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
|
|---|---|---|---|---|---|---|---|---|
thefinn93/CouchPotatoServer
|
libs/pyutil/benchmarks/bench_json.py
|
106
|
1210
|
from pyutil import randutil
import random
from decimal import Decimal
l = []
s = None
def data_strings(N):
assert isinstance(N, int), (N, type(N))
del l[:]
for i in range(N):
l.append(repr(randutil.insecurerandstr(4)))
global s
s = json.dumps(l)
def data_Decimals(N):
del l[:]
for i in range(N):
l.append(Decimal(str(random.randrange(0, 1000000000)))/random.randrange(1, 1000000000))
global s
s = jsonutil.dumps(l)
def data_floats(N):
del l[:]
for i in range(N):
l.append(float(random.randrange(0, 1000000000))/random.randrange(1, 1000000000))
global s
s = json.dumps(l)
import json
from pyutil import jsonutil
def je(N):
return json.dumps(l)
def ue(N):
return jsonutil.dumps(l)
def jd(N):
return json.loads(s)
def ud(N):
return jsonutil.loads(s)
from pyutil import benchutil
for i in (data_strings, data_floats, data_Decimals):
for e in (ud, ue, jd, je):
# for e in (ue,):
print "i: %s, e: %s" % (i, e,)
try:
benchutil.bench(e, initfunc=i, TOPXP=5, profile=False)
except TypeError, e:
print "skipping due to %s" % (e,)
benchutil.print_bench_footer()
|
gpl-3.0
|
[
504,
1134,
1974,
492,
10261,
1974,
199,
646,
2196,
199,
504,
6107,
492,
6345,
199,
199,
76,
275,
942,
199,
83,
275,
488,
199,
199,
318,
666,
63,
5465,
8,
46,
304,
272,
702,
1228,
8,
46,
12,
1109,
395,
334,
46,
12,
730,
8,
46,
430,
272,
2150,
634,
5873,
272,
367,
284,
315,
1425,
8,
46,
304,
267,
634,
14,
740,
8,
2722,
8,
3759,
1974,
14,
24824,
3759,
495,
8,
20,
1724,
272,
2288,
308,
272,
308,
275,
2022,
14,
4180,
8,
76,
9,
199,
199,
318,
666,
63,
6745,
83,
8,
46,
304,
272,
2150,
634,
5873,
272,
367,
284,
315,
1425,
8,
46,
304,
267,
634,
14,
740,
8,
6745,
8,
495,
8,
2355,
14,
20539,
8,
16,
12,
413,
25464,
1724,
15,
2355,
14,
20539,
8,
17,
12,
413,
25464,
430,
272,
2288,
308,
272,
308,
275,
2022,
1974,
14,
4180,
8,
76,
9,
199,
199,
318,
666,
63,
1609,
83,
8,
46,
304,
272,
2150,
634,
5873,
272,
367,
284,
315,
1425,
8,
46,
304,
267,
634,
14,
740,
8,
1609,
8,
2355,
14,
20539,
8,
16,
12,
413,
25464,
13342,
2355,
14,
20539,
8,
17,
12,
413,
25464,
430,
272,
2288,
308,
272,
308,
275,
2022,
14,
4180,
8,
76,
9,
199,
199,
646,
2022,
199,
504,
1134,
1974,
492,
2022,
1974,
199,
199,
318,
1335,
69,
8,
46,
304,
272,
372,
2022,
14,
4180,
8,
76,
9,
199,
199,
318,
221,
310,
8,
46,
304,
272,
372,
2022,
1974,
14,
4180,
8,
76,
9,
199,
199,
318,
1335,
68,
8,
46,
304,
272,
372,
2022,
14,
3640,
8,
83,
9,
199,
199,
318,
26759,
8,
46,
304,
272,
372,
2022,
1974,
14,
3640,
8,
83,
9,
199,
199,
504,
1134,
1974,
492,
26456,
1974,
199,
199,
509,
284,
315,
334,
576,
63,
5465,
12,
666,
63,
1609,
83,
12,
666,
63,
6745,
83,
304,
272,
367,
325,
315,
334,
1181,
12,
221,
310,
12,
1335,
68,
12,
1335,
69,
304,
272,
327,
367,
325,
315,
334,
310,
16095,
267,
870,
298,
73,
26,
450,
83,
12,
325,
26,
450,
83,
2,
450,
334,
73,
12,
325,
4258,
267,
862,
26,
288,
26456,
1974,
14,
16571,
8,
69,
12,
4205,
1532,
29,
73,
12,
32582,
20168,
29,
21,
12,
4690,
29,
797,
9,
267,
871,
3146,
12,
325,
26,
288,
870,
298,
27713,
7037,
370,
450,
83,
2,
450,
334,
69,
4258,
199,
16571,
1974,
14,
1361,
63,
16571,
63,
12781,
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
] |
[
1134,
1974,
492,
10261,
1974,
199,
646,
2196,
199,
504,
6107,
492,
6345,
199,
199,
76,
275,
942,
199,
83,
275,
488,
199,
199,
318,
666,
63,
5465,
8,
46,
304,
272,
702,
1228,
8,
46,
12,
1109,
395,
334,
46,
12,
730,
8,
46,
430,
272,
2150,
634,
5873,
272,
367,
284,
315,
1425,
8,
46,
304,
267,
634,
14,
740,
8,
2722,
8,
3759,
1974,
14,
24824,
3759,
495,
8,
20,
1724,
272,
2288,
308,
272,
308,
275,
2022,
14,
4180,
8,
76,
9,
199,
199,
318,
666,
63,
6745,
83,
8,
46,
304,
272,
2150,
634,
5873,
272,
367,
284,
315,
1425,
8,
46,
304,
267,
634,
14,
740,
8,
6745,
8,
495,
8,
2355,
14,
20539,
8,
16,
12,
413,
25464,
1724,
15,
2355,
14,
20539,
8,
17,
12,
413,
25464,
430,
272,
2288,
308,
272,
308,
275,
2022,
1974,
14,
4180,
8,
76,
9,
199,
199,
318,
666,
63,
1609,
83,
8,
46,
304,
272,
2150,
634,
5873,
272,
367,
284,
315,
1425,
8,
46,
304,
267,
634,
14,
740,
8,
1609,
8,
2355,
14,
20539,
8,
16,
12,
413,
25464,
13342,
2355,
14,
20539,
8,
17,
12,
413,
25464,
430,
272,
2288,
308,
272,
308,
275,
2022,
14,
4180,
8,
76,
9,
199,
199,
646,
2022,
199,
504,
1134,
1974,
492,
2022,
1974,
199,
199,
318,
1335,
69,
8,
46,
304,
272,
372,
2022,
14,
4180,
8,
76,
9,
199,
199,
318,
221,
310,
8,
46,
304,
272,
372,
2022,
1974,
14,
4180,
8,
76,
9,
199,
199,
318,
1335,
68,
8,
46,
304,
272,
372,
2022,
14,
3640,
8,
83,
9,
199,
199,
318,
26759,
8,
46,
304,
272,
372,
2022,
1974,
14,
3640,
8,
83,
9,
199,
199,
504,
1134,
1974,
492,
26456,
1974,
199,
199,
509,
284,
315,
334,
576,
63,
5465,
12,
666,
63,
1609,
83,
12,
666,
63,
6745,
83,
304,
272,
367,
325,
315,
334,
1181,
12,
221,
310,
12,
1335,
68,
12,
1335,
69,
304,
272,
327,
367,
325,
315,
334,
310,
16095,
267,
870,
298,
73,
26,
450,
83,
12,
325,
26,
450,
83,
2,
450,
334,
73,
12,
325,
4258,
267,
862,
26,
288,
26456,
1974,
14,
16571,
8,
69,
12,
4205,
1532,
29,
73,
12,
32582,
20168,
29,
21,
12,
4690,
29,
797,
9,
267,
871,
3146,
12,
325,
26,
288,
870,
298,
27713,
7037,
370,
450,
83,
2,
450,
334,
69,
4258,
199,
16571,
1974,
14,
1361,
63,
16571,
63,
12781,
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,
32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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
MoKee/android_kernel_nubia_nx403a
|
scripts/tracing/draw_functrace.py
|
14676
|
3560
|
#!/usr/bin/python
"""
Copyright 2008 (c) Frederic Weisbecker <fweisbec@gmail.com>
Licensed under the terms of the GNU GPL License version 2
This script parses a trace provided by the function tracer in
kernel/trace/trace_functions.c
The resulted trace is processed into a tree to produce a more human
view of the call stack by drawing textual but hierarchical tree of
calls. Only the functions's names and the the call time are provided.
Usage:
Be sure that you have CONFIG_FUNCTION_TRACER
# mount -t debugfs nodev /sys/kernel/debug
# echo function > /sys/kernel/debug/tracing/current_tracer
$ cat /sys/kernel/debug/tracing/trace_pipe > ~/raw_trace_func
Wait some times but not too much, the script is a bit slow.
Break the pipe (Ctrl + Z)
$ scripts/draw_functrace.py < raw_trace_func > draw_functrace
Then you have your drawn trace in draw_functrace
"""
import sys, re
class CallTree:
""" This class provides a tree representation of the functions
call stack. If a function has no parent in the kernel (interrupt,
syscall, kernel thread...) then it is attached to a virtual parent
called ROOT.
"""
ROOT = None
def __init__(self, func, time = None, parent = None):
self._func = func
self._time = time
if parent is None:
self._parent = CallTree.ROOT
else:
self._parent = parent
self._children = []
def calls(self, func, calltime):
""" If a function calls another one, call this method to insert it
into the tree at the appropriate place.
@return: A reference to the newly created child node.
"""
child = CallTree(func, calltime, self)
self._children.append(child)
return child
def getParent(self, func):
""" Retrieve the last parent of the current node that
has the name given by func. If this function is not
on a parent, then create it as new child of root
@return: A reference to the parent.
"""
tree = self
while tree != CallTree.ROOT and tree._func != func:
tree = tree._parent
if tree == CallTree.ROOT:
child = CallTree.ROOT.calls(func, None)
return child
return tree
def __repr__(self):
return self.__toString("", True)
def __toString(self, branch, lastChild):
if self._time is not None:
s = "%s----%s (%s)\n" % (branch, self._func, self._time)
else:
s = "%s----%s\n" % (branch, self._func)
i = 0
if lastChild:
branch = branch[:-1] + " "
while i < len(self._children):
if i != len(self._children) - 1:
s += "%s" % self._children[i].__toString(branch +\
" |", False)
else:
s += "%s" % self._children[i].__toString(branch +\
" |", True)
i += 1
return s
class BrokenLineException(Exception):
"""If the last line is not complete because of the pipe breakage,
we want to stop the processing and ignore this line.
"""
pass
class CommentLineException(Exception):
""" If the line is a comment (as in the beginning of the trace file),
just ignore it.
"""
pass
def parseLine(line):
line = line.strip()
if line.startswith("#"):
raise CommentLineException
m = re.match("[^]]+?\\] +([0-9.]+): (\\w+) <-(\\w+)", line)
if m is None:
raise BrokenLineException
return (m.group(1), m.group(2), m.group(3))
def main():
CallTree.ROOT = CallTree("Root (Nowhere)", None, None)
tree = CallTree.ROOT
for line in sys.stdin:
try:
calltime, callee, caller = parseLine(line)
except BrokenLineException:
break
except CommentLineException:
continue
tree = tree.getParent(caller)
tree = tree.calls(callee, calltime)
print CallTree.ROOT
if __name__ == "__main__":
main()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
624,
199,
7384,
9079,
334,
67,
9,
481,
21919,
1567,
2136,
374,
1235,
22043,
665,
70,
1129,
374,
24554,
32,
6799,
14,
957,
30,
199,
31661,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
199,
2765,
2884,
19953,
282,
3307,
2741,
701,
314,
805,
29140,
315,
199,
4989,
15,
3446,
15,
3446,
63,
5777,
14,
67,
199,
1918,
522,
30355,
3307,
365,
7686,
1901,
282,
3123,
370,
7389,
282,
1655,
11779,
199,
1345,
402,
314,
1240,
3464,
701,
17455,
25884,
1325,
24787,
3123,
402,
199,
5352,
14,
5972,
314,
3423,
1159,
1561,
436,
314,
314,
1240,
900,
787,
2741,
14,
199,
199,
7692,
26,
199,
198,
3655,
3238,
626,
1265,
1172,
15869,
63,
15476,
63,
1766,
1348,
540,
199,
198,
3,
10760,
446,
84,
3105,
2319,
1031,
86,
1182,
1274,
15,
4989,
15,
1757,
199,
198,
3,
11343,
805,
690,
1182,
1274,
15,
4989,
15,
1757,
15,
21635,
15,
1818,
63,
16825,
199,
198,
4,
6230,
1182,
1274,
15,
4989,
15,
1757,
15,
21635,
15,
3446,
63,
4990,
690,
6146,
15,
1773,
63,
3446,
63,
1532,
199,
198,
7536,
2005,
5431,
1325,
440,
4634,
8298,
12,
314,
2884,
365,
282,
4546,
11999,
14,
199,
198,
13948,
314,
5200,
334,
9778,
435,
3107,
9,
199,
198,
4,
10554,
15,
5485,
63,
31939,
5986,
14,
647,
665,
3066,
63,
3446,
63,
1532,
690,
5954,
63,
31939,
5986,
199,
198,
28226,
1265,
1172,
2195,
19341,
3307,
315,
5954,
63,
31939,
5986,
199,
624,
421,
199,
646,
984,
12,
295,
199,
199,
533,
23491,
26,
199,
198,
624,
961,
1021,
6571,
282,
3123,
6025,
402,
314,
3423,
507,
198,
1250,
3464,
14,
982,
282,
805,
965,
949,
1676,
315,
314,
5114,
334,
20172,
12,
507,
198,
19444,
12,
5114,
2462,
11965,
2066,
652,
365,
10102,
370,
282,
5791,
1676,
507,
198,
3527,
16547,
14,
199,
198,
624,
199,
198,
5441,
275,
488,
421,
198,
318,
636,
826,
721,
277,
12,
2562,
12,
900,
275,
488,
12,
1676,
275,
488,
304,
507,
198,
277,
423,
1532,
275,
2562,
507,
198,
277,
423,
521,
275,
900,
507,
198,
692,
1676,
365,
488,
26,
686,
198,
277,
423,
1708,
275,
23491,
14,
5441,
507,
198,
2836,
26,
686,
198,
277,
423,
1708,
275,
1676,
507,
198,
277,
423,
3223,
275,
942,
421,
198,
318,
4882,
8,
277,
12,
2562,
12,
1240,
521,
304,
507,
198,
624,
982,
282,
805,
4882,
4573,
1373,
12,
1240,
642,
1083,
370,
5518,
652,
686,
198,
9924,
314,
3123,
737,
314,
5827,
4192,
14,
686,
198,
32,
1107,
26,
437,
3659,
370,
314,
13903,
2737,
1982,
1031,
14,
507,
198,
624,
507,
198,
1739,
275,
23491,
8,
1532,
12,
1240,
521,
12,
291,
9,
507,
198,
277,
423,
3223,
14,
740,
8,
1739,
9,
507,
198,
1107,
1982,
421,
198,
318,
664,
6652,
8,
277,
12,
2562,
304,
507,
198,
624,
13939,
314,
2061,
1676,
402,
314,
1453,
1031,
626,
686,
198,
1989,
314,
536,
1627,
701,
2562,
14,
982,
642,
805,
365,
440,
686,
198,
265,
282,
1676,
12,
2066,
1218,
652,
465,
892,
1982,
402,
1738,
686,
198,
32,
1107,
26,
437,
3659,
370,
314,
1676,
14,
507,
198,
624,
507,
198,
2350,
275,
291,
507,
198,
6710,
3123,
1137,
23491,
14,
5441,
436,
3123,
423,
1532,
1137,
2562,
26,
686,
198,
2350,
275,
3123,
423,
1708,
507,
198,
692,
3123,
508,
23491,
14,
5441,
26,
686,
198,
1739,
275,
23491,
14,
5441,
14,
5352,
8,
1532,
12,
488,
9,
686,
198,
1107,
1982,
507,
198,
1107,
3123,
421,
198,
318,
636,
2722,
721,
277,
304,
507,
198,
1107,
291,
855,
16695,
12398,
715,
9,
421,
198,
318,
636,
16695,
8,
277,
12,
5246,
12,
2061,
3493,
304,
507,
198,
692,
291,
423,
521,
365,
440,
488,
26,
686,
198,
83,
275,
2071,
83,
375,
5,
83,
4366,
83,
2862,
78,
2,
450,
334,
4694,
12,
291,
423,
1532,
12,
291,
423,
521,
9,
507,
198,
2836,
26,
686,
198,
83,
275,
2071,
83,
375,
5,
83,
60,
78,
2,
450,
334,
4694,
12,
291,
423,
1532,
9,
2742,
198,
73,
275,
378,
507,
198,
692,
2061,
3493,
26,
686,
198,
4694,
275,
5246,
4439,
17,
61,
435,
298,
298,
507,
198,
6710,
284,
665,
822,
8,
277,
423,
3223,
304,
686,
198,
692,
284,
1137,
822,
8,
277,
423,
3223,
9,
446,
413,
26,
1585,
198,
83,
847,
2071,
83,
2,
450,
291,
423,
3223,
59,
73,
17979,
16695,
8,
4694,
17992,
11674,
198,
2,
259,
1204,
401,
756,
9,
686,
198,
2836,
26,
1585,
198,
83,
847,
2071,
83,
2,
450,
291,
423,
3223,
59,
73,
17979,
16695,
8,
4694,
17992,
11674,
198,
2,
259,
1204,
401,
715,
9,
686,
198,
73,
847,
413,
507,
198,
1107,
308,
199,
199,
533,
23804,
29969,
8,
1726,
304,
199,
198,
624,
3917,
314,
2061,
1004,
365,
440,
4890,
2952,
402,
314,
5200,
2059,
474,
12,
21979,
781,
2934,
370,
3631,
314,
6661,
436,
3686,
642,
1004,
14,
199,
198,
624,
199,
198,
1529,
199,
199,
533,
6819,
29969,
8,
1726,
304,
199,
198,
624,
982,
314,
1004,
365,
282,
3721,
334,
305,
315,
314,
9608,
402,
314,
3307,
570,
395,
6722,
2951,
3686,
652,
14,
199,
198,
624,
199,
198,
1529,
421,
199,
318,
2198,
3049,
8,
604,
304,
199,
198,
604,
275,
1004,
14,
1913,
342,
199,
198,
692,
1004,
14,
2460,
10064,
2349,
507,
198,
3730,
6819,
29969,
199,
198,
77,
275,
295,
14,
1431,
480,
4735,
2677,
23778,
1103,
61,
435,
779,
16,
13,
25,
32455,
304,
334,
1103,
87,
8771,
665,
15426,
1103,
87,
11,
4186,
1004,
9,
199,
198,
692,
333,
365,
488,
26,
507,
198,
3730,
23804,
29969,
199,
198,
1107,
334,
77,
14,
923,
8,
17,
395,
333,
14,
923,
8,
18,
395,
333,
14,
923,
8,
19,
430,
421,
199,
318,
2446,
837,
199,
198,
2176,
3987,
14,
5441,
275,
23491,
480,
6405,
334,
14351,
1681,
4186,
488,
12,
488,
9,
199,
198,
2350,
275,
23491,
14,
5441,
421,
198,
509,
1004,
315,
984,
14,
6626,
26,
507,
198,
893,
26,
686,
198,
1250,
521,
12,
3213,
18387,
12,
8025,
275,
2198,
3049,
8,
604
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
624,
199,
7384,
9079,
334,
67,
9,
481,
21919,
1567,
2136,
374,
1235,
22043,
665,
70,
1129,
374,
24554,
32,
6799,
14,
957,
30,
199,
31661,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
199,
2765,
2884,
19953,
282,
3307,
2741,
701,
314,
805,
29140,
315,
199,
4989,
15,
3446,
15,
3446,
63,
5777,
14,
67,
199,
1918,
522,
30355,
3307,
365,
7686,
1901,
282,
3123,
370,
7389,
282,
1655,
11779,
199,
1345,
402,
314,
1240,
3464,
701,
17455,
25884,
1325,
24787,
3123,
402,
199,
5352,
14,
5972,
314,
3423,
1159,
1561,
436,
314,
314,
1240,
900,
787,
2741,
14,
199,
199,
7692,
26,
199,
198,
3655,
3238,
626,
1265,
1172,
15869,
63,
15476,
63,
1766,
1348,
540,
199,
198,
3,
10760,
446,
84,
3105,
2319,
1031,
86,
1182,
1274,
15,
4989,
15,
1757,
199,
198,
3,
11343,
805,
690,
1182,
1274,
15,
4989,
15,
1757,
15,
21635,
15,
1818,
63,
16825,
199,
198,
4,
6230,
1182,
1274,
15,
4989,
15,
1757,
15,
21635,
15,
3446,
63,
4990,
690,
6146,
15,
1773,
63,
3446,
63,
1532,
199,
198,
7536,
2005,
5431,
1325,
440,
4634,
8298,
12,
314,
2884,
365,
282,
4546,
11999,
14,
199,
198,
13948,
314,
5200,
334,
9778,
435,
3107,
9,
199,
198,
4,
10554,
15,
5485,
63,
31939,
5986,
14,
647,
665,
3066,
63,
3446,
63,
1532,
690,
5954,
63,
31939,
5986,
199,
198,
28226,
1265,
1172,
2195,
19341,
3307,
315,
5954,
63,
31939,
5986,
199,
624,
421,
199,
646,
984,
12,
295,
199,
199,
533,
23491,
26,
199,
198,
624,
961,
1021,
6571,
282,
3123,
6025,
402,
314,
3423,
507,
198,
1250,
3464,
14,
982,
282,
805,
965,
949,
1676,
315,
314,
5114,
334,
20172,
12,
507,
198,
19444,
12,
5114,
2462,
11965,
2066,
652,
365,
10102,
370,
282,
5791,
1676,
507,
198,
3527,
16547,
14,
199,
198,
624,
199,
198,
5441,
275,
488,
421,
198,
318,
636,
826,
721,
277,
12,
2562,
12,
900,
275,
488,
12,
1676,
275,
488,
304,
507,
198,
277,
423,
1532,
275,
2562,
507,
198,
277,
423,
521,
275,
900,
507,
198,
692,
1676,
365,
488,
26,
686,
198,
277,
423,
1708,
275,
23491,
14,
5441,
507,
198,
2836,
26,
686,
198,
277,
423,
1708,
275,
1676,
507,
198,
277,
423,
3223,
275,
942,
421,
198,
318,
4882,
8,
277,
12,
2562,
12,
1240,
521,
304,
507,
198,
624,
982,
282,
805,
4882,
4573,
1373,
12,
1240,
642,
1083,
370,
5518,
652,
686,
198,
9924,
314,
3123,
737,
314,
5827,
4192,
14,
686,
198,
32,
1107,
26,
437,
3659,
370,
314,
13903,
2737,
1982,
1031,
14,
507,
198,
624,
507,
198,
1739,
275,
23491,
8,
1532,
12,
1240,
521,
12,
291,
9,
507,
198,
277,
423,
3223,
14,
740,
8,
1739,
9,
507,
198,
1107,
1982,
421,
198,
318,
664,
6652,
8,
277,
12,
2562,
304,
507,
198,
624,
13939,
314,
2061,
1676,
402,
314,
1453,
1031,
626,
686,
198,
1989,
314,
536,
1627,
701,
2562,
14,
982,
642,
805,
365,
440,
686,
198,
265,
282,
1676,
12,
2066,
1218,
652,
465,
892,
1982,
402,
1738,
686,
198,
32,
1107,
26,
437,
3659,
370,
314,
1676,
14,
507,
198,
624,
507,
198,
2350,
275,
291,
507,
198,
6710,
3123,
1137,
23491,
14,
5441,
436,
3123,
423,
1532,
1137,
2562,
26,
686,
198,
2350,
275,
3123,
423,
1708,
507,
198,
692,
3123,
508,
23491,
14,
5441,
26,
686,
198,
1739,
275,
23491,
14,
5441,
14,
5352,
8,
1532,
12,
488,
9,
686,
198,
1107,
1982,
507,
198,
1107,
3123,
421,
198,
318,
636,
2722,
721,
277,
304,
507,
198,
1107,
291,
855,
16695,
12398,
715,
9,
421,
198,
318,
636,
16695,
8,
277,
12,
5246,
12,
2061,
3493,
304,
507,
198,
692,
291,
423,
521,
365,
440,
488,
26,
686,
198,
83,
275,
2071,
83,
375,
5,
83,
4366,
83,
2862,
78,
2,
450,
334,
4694,
12,
291,
423,
1532,
12,
291,
423,
521,
9,
507,
198,
2836,
26,
686,
198,
83,
275,
2071,
83,
375,
5,
83,
60,
78,
2,
450,
334,
4694,
12,
291,
423,
1532,
9,
2742,
198,
73,
275,
378,
507,
198,
692,
2061,
3493,
26,
686,
198,
4694,
275,
5246,
4439,
17,
61,
435,
298,
298,
507,
198,
6710,
284,
665,
822,
8,
277,
423,
3223,
304,
686,
198,
692,
284,
1137,
822,
8,
277,
423,
3223,
9,
446,
413,
26,
1585,
198,
83,
847,
2071,
83,
2,
450,
291,
423,
3223,
59,
73,
17979,
16695,
8,
4694,
17992,
11674,
198,
2,
259,
1204,
401,
756,
9,
686,
198,
2836,
26,
1585,
198,
83,
847,
2071,
83,
2,
450,
291,
423,
3223,
59,
73,
17979,
16695,
8,
4694,
17992,
11674,
198,
2,
259,
1204,
401,
715,
9,
686,
198,
73,
847,
413,
507,
198,
1107,
308,
199,
199,
533,
23804,
29969,
8,
1726,
304,
199,
198,
624,
3917,
314,
2061,
1004,
365,
440,
4890,
2952,
402,
314,
5200,
2059,
474,
12,
21979,
781,
2934,
370,
3631,
314,
6661,
436,
3686,
642,
1004,
14,
199,
198,
624,
199,
198,
1529,
199,
199,
533,
6819,
29969,
8,
1726,
304,
199,
198,
624,
982,
314,
1004,
365,
282,
3721,
334,
305,
315,
314,
9608,
402,
314,
3307,
570,
395,
6722,
2951,
3686,
652,
14,
199,
198,
624,
199,
198,
1529,
421,
199,
318,
2198,
3049,
8,
604,
304,
199,
198,
604,
275,
1004,
14,
1913,
342,
199,
198,
692,
1004,
14,
2460,
10064,
2349,
507,
198,
3730,
6819,
29969,
199,
198,
77,
275,
295,
14,
1431,
480,
4735,
2677,
23778,
1103,
61,
435,
779,
16,
13,
25,
32455,
304,
334,
1103,
87,
8771,
665,
15426,
1103,
87,
11,
4186,
1004,
9,
199,
198,
692,
333,
365,
488,
26,
507,
198,
3730,
23804,
29969,
199,
198,
1107,
334,
77,
14,
923,
8,
17,
395,
333,
14,
923,
8,
18,
395,
333,
14,
923,
8,
19,
430,
421,
199,
318,
2446,
837,
199,
198,
2176,
3987,
14,
5441,
275,
23491,
480,
6405,
334,
14351,
1681,
4186,
488,
12,
488,
9,
199,
198,
2350,
275,
23491,
14,
5441,
421,
198,
509,
1004,
315,
984,
14,
6626,
26,
507,
198,
893,
26,
686,
198,
1250,
521,
12,
3213,
18387,
12,
8025,
275,
2198,
3049,
8,
604,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
markYoungH/chromium.src
|
tools/telemetry/telemetry/web_perf/metrics/timeline_based_metric.py
|
77
|
2212
|
# 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.
class TimelineBasedMetricException(Exception):
"""Exception that can be thrown from metrics that implements
TimelineBasedMetric to indicate a problem arised when computing the metric.
"""
def _TimeRangesHasOverlap(iterable_time_ranges):
""" Returns True if there is are overlapped ranges in time ranges.
iterable_time_ranges: an iterable of time ranges. Each time range is a
tuple (start time, end time).
"""
# Sort the ranges by the start time
sorted_time_ranges = sorted(iterable_time_ranges)
last_range = sorted_time_ranges[0]
for current_range in sorted_time_ranges[1:]:
start_current_range = current_range[0]
end_last_range = last_range[1]
if start_current_range < end_last_range:
return True
last_range = current_range
return False
class TimelineBasedMetric(object):
def __init__(self):
"""Computes metrics from a telemetry.timeline Model and a range
"""
super(TimelineBasedMetric, self).__init__()
def AddResults(self, model, renderer_thread, interaction_records, results):
"""Computes and adds metrics for the interaction_records' time ranges.
The override of this method should compute results on the data **only**
within the interaction_records' start and end time ranges.
Args:
model: An instance of telemetry.timeline.model.TimelineModel.
interaction_records: A list of instances of TimelineInteractionRecord. If
the override of this method doesn't support overlapped ranges, use
VerifyNonOverlappedRecords to check that no records are overlapped.
results: An instance of page.PageTestResults.
"""
raise NotImplementedError()
def VerifyNonOverlappedRecords(self, interaction_records):
"""This raises exceptions if interaction_records contain overlapped ranges.
"""
if _TimeRangesHasOverlap(((r.start, r.end) for r in interaction_records)):
raise TimelineBasedMetricException(
'This metric does not support interaction records with overlapped '
'time range.')
|
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,
421,
199,
533,
4703,
604,
20409,
11119,
1726,
8,
1726,
304,
523,
408,
1726,
626,
883,
506,
14031,
687,
7186,
626,
9031,
1362,
4703,
604,
20409,
11119,
370,
6623,
282,
5160,
14554,
939,
1380,
17226,
314,
6370,
14,
1362,
408,
421,
199,
318,
485,
1366,
23019,
6362,
28709,
8,
8147,
63,
521,
63,
8404,
304,
523,
408,
1803,
715,
340,
2337,
365,
787,
15145,
1915,
12271,
315,
900,
12271,
14,
523,
6076,
63,
521,
63,
8404,
26,
376,
6076,
402,
900,
12271,
14,
7048,
900,
1425,
365,
282,
523,
2008,
334,
928,
900,
12,
1284,
900,
680,
523,
408,
523,
327,
16722,
314,
12271,
701,
314,
1343,
900,
523,
3355,
63,
521,
63,
8404,
275,
3355,
8,
8147,
63,
521,
63,
8404,
9,
523,
2061,
63,
1842,
275,
3355,
63,
521,
63,
8404,
59,
16,
61,
523,
367,
1453,
63,
1842,
315,
3355,
63,
521,
63,
8404,
59,
17,
10688,
272,
1343,
63,
1818,
63,
1842,
275,
1453,
63,
1842,
59,
16,
61,
272,
1284,
63,
2019,
63,
1842,
275,
2061,
63,
1842,
59,
17,
61,
272,
340,
1343,
63,
1818,
63,
1842,
665,
1284,
63,
2019,
63,
1842,
26,
489,
372,
715,
272,
2061,
63,
1842,
275,
1453,
63,
1842,
523,
372,
756,
421,
199,
533,
4703,
604,
20409,
11119,
8,
785,
304,
819,
347,
636,
826,
721,
277,
304,
272,
408,
22594,
7186,
687,
282,
17298,
14,
19369,
5822,
436,
282,
1425,
339,
408,
272,
1613,
8,
27097,
20409,
11119,
12,
291,
2843,
826,
4533,
819,
347,
2654,
6579,
8,
277,
12,
1402,
12,
11889,
63,
2671,
12,
18752,
63,
6502,
12,
2058,
304,
272,
408,
22594,
436,
9584,
7186,
367,
314,
18752,
63,
6502,
7,
900,
12271,
14,
339,
710,
4278,
402,
642,
1083,
1077,
4526,
2058,
641,
314,
666,
1011,
2118,
538,
272,
4453,
314,
18752,
63,
6502,
7,
1343,
436,
1284,
900,
12271,
14,
339,
3033,
26,
489,
1402,
26,
1626,
1256,
402,
17298,
14,
19369,
14,
1238,
14,
27097,
1685,
14,
489,
18752,
63,
6502,
26,
437,
769,
402,
4454,
402,
4703,
604,
31900,
5433,
14,
982,
267,
314,
4278,
402,
642,
1083,
3181,
1133,
2291,
15145,
1915,
12271,
12,
675,
267,
7635,
6932,
28709,
1915,
14941,
370,
1104,
626,
949,
5767,
787,
15145,
1915,
14,
489,
2058,
26,
1626,
1256,
402,
2034,
14,
3276,
774,
6579,
14,
339,
408,
272,
746,
4279,
342,
819,
347,
7635,
6932,
28709,
1915,
14941,
8,
277,
12,
18752,
63,
6502,
304,
272,
408,
2765,
6534,
4967,
340,
18752,
63,
6502,
1395,
15145,
1915,
12271,
14,
272,
408,
272,
340,
485,
1366,
23019,
6362,
28709,
12925,
82,
14,
928,
12,
519,
14,
500,
9,
367,
519,
315,
18752,
63,
6502,
2298,
489,
746,
4703,
604,
20409,
11119,
1726,
8,
881,
283,
2765,
6370,
1630,
440,
2291,
18752,
5767,
543,
15145,
1915,
283,
881,
283,
521,
1425,
2659,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
421,
199,
533,
4703,
604,
20409,
11119,
1726,
8,
1726,
304,
523,
408,
1726,
626,
883,
506,
14031,
687,
7186,
626,
9031,
1362,
4703,
604,
20409,
11119,
370,
6623,
282,
5160,
14554,
939,
1380,
17226,
314,
6370,
14,
1362,
408,
421,
199,
318,
485,
1366,
23019,
6362,
28709,
8,
8147,
63,
521,
63,
8404,
304,
523,
408,
1803,
715,
340,
2337,
365,
787,
15145,
1915,
12271,
315,
900,
12271,
14,
523,
6076,
63,
521,
63,
8404,
26,
376,
6076,
402,
900,
12271,
14,
7048,
900,
1425,
365,
282,
523,
2008,
334,
928,
900,
12,
1284,
900,
680,
523,
408,
523,
327,
16722,
314,
12271,
701,
314,
1343,
900,
523,
3355,
63,
521,
63,
8404,
275,
3355,
8,
8147,
63,
521,
63,
8404,
9,
523,
2061,
63,
1842,
275,
3355,
63,
521,
63,
8404,
59,
16,
61,
523,
367,
1453,
63,
1842,
315,
3355,
63,
521,
63,
8404,
59,
17,
10688,
272,
1343,
63,
1818,
63,
1842,
275,
1453,
63,
1842,
59,
16,
61,
272,
1284,
63,
2019,
63,
1842,
275,
2061,
63,
1842,
59,
17,
61,
272,
340,
1343,
63,
1818,
63,
1842,
665,
1284,
63,
2019,
63,
1842,
26,
489,
372,
715,
272,
2061,
63,
1842,
275,
1453,
63,
1842,
523,
372,
756,
421,
199,
533,
4703,
604,
20409,
11119,
8,
785,
304,
819,
347,
636,
826,
721,
277,
304,
272,
408,
22594,
7186,
687,
282,
17298,
14,
19369,
5822,
436,
282,
1425,
339,
408,
272,
1613,
8,
27097,
20409,
11119,
12,
291,
2843,
826,
4533,
819,
347,
2654,
6579,
8,
277,
12,
1402,
12,
11889,
63,
2671,
12,
18752,
63,
6502,
12,
2058,
304,
272,
408,
22594,
436,
9584,
7186,
367,
314,
18752,
63,
6502,
7,
900,
12271,
14,
339,
710,
4278,
402,
642,
1083,
1077,
4526,
2058,
641,
314,
666,
1011,
2118,
538,
272,
4453,
314,
18752,
63,
6502,
7,
1343,
436,
1284,
900,
12271,
14,
339,
3033,
26,
489,
1402,
26,
1626,
1256,
402,
17298,
14,
19369,
14,
1238,
14,
27097,
1685,
14,
489,
18752,
63,
6502,
26,
437,
769,
402,
4454,
402,
4703,
604,
31900,
5433,
14,
982,
267,
314,
4278,
402,
642,
1083,
3181,
1133,
2291,
15145,
1915,
12271,
12,
675,
267,
7635,
6932,
28709,
1915,
14941,
370,
1104,
626,
949,
5767,
787,
15145,
1915,
14,
489,
2058,
26,
1626,
1256,
402,
2034,
14,
3276,
774,
6579,
14,
339,
408,
272,
746,
4279,
342,
819,
347,
7635,
6932,
28709,
1915,
14941,
8,
277,
12,
18752,
63,
6502,
304,
272,
408,
2765,
6534,
4967,
340,
18752,
63,
6502,
1395,
15145,
1915,
12271,
14,
272,
408,
272,
340,
485,
1366,
23019,
6362,
28709,
12925,
82,
14,
928,
12,
519,
14,
500,
9,
367,
519,
315,
18752,
63,
6502,
2298,
489,
746,
4703,
604,
20409,
11119,
1726,
8,
881,
283,
2765,
6370,
1630,
440,
2291,
18752,
5767,
543,
15145,
1915,
283,
881,
283,
521,
1425,
2659,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
JulianSchuette/android-instrumentation
|
injector/androguard/core/bytecodes/jvm_generate.py
|
10
|
3707
|
# This file is part of Androguard.
#
# Copyright (C) 2012 Anthony Desnos <desnos at t0t0.fr>
# All rights reserved.
#
# Androguard is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Androguard 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 Androguard. If not, see <http://www.gnu.org/licenses/>.
import random
from androconf import error
import jvm
class Automaton :
def __init__(self, _analysis) :
self.__analysis = _analysis
try :
from networkx import DiGraph
from networkx import draw_graphviz, write_dot
except ImportError :
error("module networkx not found")
self.__G = DiGraph()
for m in self.__analysis.get_methods() :
for bb in m.basic_blocks.get() :
for trace in bb.stack_traces.get() :
for mre in jvm.MATH_JVM_RE :
if mre[0].match( trace[2].get_name() ) :
for i in trace[3].gets() :
self._add( str(i) )
def _add(self, elem) :
l = []
x = ""
for i in elem :
if i not in jvm.MATH_JVM_OPCODES.values() :
x += i
else :
l.append( x )
l.append( i )
x = ""
if len(l) > 1 :
l.append( x )
self._add_expr( l )
def _add_expr(self, l) :
if l == [] :
return
i = 0
while i < (len(l)-1) :
self.__G.add_edge( self._transform(l[i]), self._transform(l[i+1]) )
i += 1
def _transform(self, i) :
if "VARIABLE" in i :
return "V"
return i
def new(self, loop) :
expr = []
l = list( self.__G.node )
init = l[ random.randint(0, len(l) - 1) ]
while init in jvm.MATH_JVM_OPCODES.values() :
init = l[ random.randint(0, len(l) - 1) ]
expr.append( init )
i = 0
while i <= loop :
l = list( self.__G.edge[ init ] )
if l == [] :
break
init = l[ random.randint(0, len(l) - 1) ]
expr.append( init )
i += 1
return expr
def show(self) :
print self.__G.node
print self.__G.edge
#draw_graphviz(self.__G)
#write_dot(self.__G,'file.dot')
class JVMGenerate :
def __init__(self, _vm, _analysis) :
self.__vm = _vm
self.__analysis = _analysis
self.__automaton = Automaton( self.__analysis )
self.__automaton.show()
def create_affectation(self, method_name, desc) :
l = []
if desc[0] == 0 :
l.append( [ "aload_0" ] )
l.append( [ "bipush", desc[2] ] )
l.append( [ "putfield", desc[1].get_name(), desc[1].get_descriptor() ] )
return l
def write(self, method, offset, field) :
print method, offset, field
expr = self.__automaton.new( 5 )
print field.get_name(), "EXPR ->", expr
self._transform( expr )
def _transform(self, expr) :
if len(expr) == 1 :
return
x = [ expr.pop(0), expr.pop(1), expr.pop(0) ]
# while expr != [] :
|
apache-2.0
|
[
3,
961,
570,
365,
1777,
402,
6061,
293,
15606,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
6029,
1626,
898,
89,
8055,
12712,
665,
3424,
12712,
737,
307,
16,
84,
16,
14,
4391,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
6061,
293,
15606,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
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,
6061,
293,
15606,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
6061,
293,
15606,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
2196,
199,
199,
504,
436,
293,
2190,
492,
1125,
199,
646,
1335,
2611,
199,
199,
533,
9195,
569,
265,
520,
272,
347,
636,
826,
721,
277,
12,
485,
10466,
9,
520,
267,
291,
855,
10466,
275,
485,
10466,
398,
862,
520,
288,
687,
24313,
492,
3757,
4578,
288,
687,
24313,
492,
5954,
63,
2180,
17249,
12,
2218,
63,
3287,
267,
871,
3545,
520,
288,
1125,
480,
578,
24313,
440,
1911,
531,
398,
291,
855,
39,
275,
3757,
4578,
342,
398,
367,
333,
315,
291,
855,
10466,
14,
362,
63,
2474,
342,
520,
288,
367,
14027,
315,
333,
14,
4316,
63,
4166,
14,
362,
342,
520,
355,
367,
3307,
315,
14027,
14,
2340,
63,
28388,
14,
362,
342,
520,
490,
367,
333,
264,
315,
1335,
2611,
14,
45,
11695,
63,
42,
6849,
63,
907,
520,
717,
340,
333,
264,
59,
16,
1055,
1431,
8,
3307,
59,
18,
1055,
362,
63,
354,
342,
776,
520,
1169,
367,
284,
315,
3307,
59,
19,
1055,
24894,
342,
520,
1816,
291,
423,
525,
8,
620,
8,
73,
9,
776,
339,
347,
485,
525,
8,
277,
12,
6193,
9,
520,
267,
634,
275,
942,
267,
671,
275,
3087,
267,
367,
284,
315,
6193,
520,
288,
340,
284,
440,
315,
1335,
2611,
14,
45,
11695,
63,
42,
6849,
63,
32382,
14,
1459,
342,
520,
355,
671,
847,
284,
288,
587,
520,
355,
634,
14,
740,
8,
671,
776,
355,
634,
14,
740,
8,
284,
776,
355,
671,
275,
3087,
398,
340,
822,
8,
76,
9,
690,
413,
520,
288,
634,
14,
740,
8,
671,
776,
398,
291,
423,
525,
63,
3684,
8,
634,
776,
339,
347,
485,
525,
63,
3684,
8,
277,
12,
634,
9,
520,
267,
340,
634,
508,
942,
520,
288,
372,
267,
284,
275,
378,
267,
1830,
284,
665,
334,
552,
8,
76,
7216,
17,
9,
520,
288,
291,
855,
39,
14,
525,
63,
5173,
8,
291,
423,
4711,
8,
76,
59,
73,
2522,
291,
423,
4711,
8,
76,
59,
73,
11,
17,
566,
776,
953,
284,
847,
413,
339,
347,
485,
4711,
8,
277,
12,
284,
9,
520,
267,
340,
298,
23129,
2,
315,
284,
520,
288,
372,
298,
54,
2,
267,
372,
284,
339,
347,
892,
8,
277,
12,
4438,
9,
520,
267,
5348,
275,
942,
398,
634,
275,
769,
8,
291,
855,
39,
14,
932,
776,
398,
4205,
275,
634,
59,
2196,
14,
8393,
8,
16,
12,
822,
8,
76,
9,
446,
413,
9,
1622,
267,
1830,
4205,
315,
1335,
2611,
14,
45,
11695,
63,
42,
6849,
63,
32382,
14,
1459,
342,
520,
288,
4205,
275,
634,
59,
2196,
14,
8393,
8,
16,
12,
822,
8,
76,
9,
446,
413,
9,
1622,
398,
5348,
14,
740,
8,
4205,
776,
398,
284,
275,
378,
267,
1830,
284,
2695,
4438,
520,
288,
634,
275,
769,
8,
291,
855,
39,
14,
5173,
59,
4205,
1622,
776,
288,
340,
634,
508,
942,
520,
355,
2059,
953,
4205,
275,
221,
634,
59,
2196,
14,
8393,
8,
16,
12,
822,
8,
76,
9,
446,
413,
9,
1622,
288,
5348,
14,
740,
8,
4205,
776,
953,
284,
847,
413,
398,
372,
5348,
339,
347,
2498,
8,
277,
9,
520,
267,
870,
291,
855,
39,
14,
932,
267,
870,
291,
855,
39,
14,
5173,
398,
327,
5485,
63,
2180,
17249,
8,
277,
855,
39,
9,
267,
327,
952,
63,
3287,
8,
277,
855,
39,
2584,
493,
14,
3287,
358,
199,
199,
533,
1603,
6849,
6864,
520,
272,
347,
636,
826,
721,
277,
12,
485,
2611,
12,
485,
10466,
9,
520,
267,
291,
855,
2611,
275,
485,
2611,
267,
291,
855,
10466,
275,
485,
10466,
398,
291,
855,
2495,
569,
265,
275,
9195,
569,
265,
8,
291,
855,
10466,
776,
267,
291,
855,
2495,
569,
265,
14,
2384,
342,
339,
347,
1218,
63,
65,
5551,
425,
8,
277,
12,
1083,
63,
354,
12,
4328,
9,
520,
267,
634,
275,
942,
398,
340,
4328,
59,
16,
61,
508,
378,
520,
288,
634,
14,
740,
8,
359,
298,
12201,
350,
63,
16,
2,
1622,
776,
288,
634,
14,
740,
8,
359,
298,
27566,
2084,
401,
4328,
59,
18,
61,
1622,
776,
288,
634,
14,
740,
8,
359,
298,
524,
698,
401,
4328,
59,
17,
1055,
362,
63,
354,
1062,
4328,
59,
17,
1055,
362,
63,
4120,
342,
1622,
776,
398,
372,
634,
339,
347,
2218,
8,
277,
12,
1083,
12,
3268,
12,
901,
9,
520,
267,
870,
1083,
12,
3268,
12,
901,
267,
5348,
275,
291,
855,
2495,
569,
265,
14,
1222,
8,
959,
776,
398,
870,
901,
14,
362,
63,
354,
1062,
298,
1438,
3311,
1035,
401,
5348,
398,
291,
423,
4711,
8,
5348,
776,
2378,
347,
485,
4711,
8,
277,
12,
5348,
9,
520,
267,
340,
822,
8,
3684,
9,
508,
413,
520,
288,
372,
398,
671,
275,
359,
5348,
14,
1935,
8,
16,
395,
5348,
14,
1935,
8,
17,
395,
5348,
14,
1935,
8,
16,
9,
1622,
199,
199,
3,
420,
1830,
5348,
1137,
942,
520,
199,
32768,
32768,
32768,
32768,
32768
] |
[
961,
570,
365,
1777,
402,
6061,
293,
15606,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
6029,
1626,
898,
89,
8055,
12712,
665,
3424,
12712,
737,
307,
16,
84,
16,
14,
4391,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
6061,
293,
15606,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
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,
6061,
293,
15606,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
6061,
293,
15606,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
2196,
199,
199,
504,
436,
293,
2190,
492,
1125,
199,
646,
1335,
2611,
199,
199,
533,
9195,
569,
265,
520,
272,
347,
636,
826,
721,
277,
12,
485,
10466,
9,
520,
267,
291,
855,
10466,
275,
485,
10466,
398,
862,
520,
288,
687,
24313,
492,
3757,
4578,
288,
687,
24313,
492,
5954,
63,
2180,
17249,
12,
2218,
63,
3287,
267,
871,
3545,
520,
288,
1125,
480,
578,
24313,
440,
1911,
531,
398,
291,
855,
39,
275,
3757,
4578,
342,
398,
367,
333,
315,
291,
855,
10466,
14,
362,
63,
2474,
342,
520,
288,
367,
14027,
315,
333,
14,
4316,
63,
4166,
14,
362,
342,
520,
355,
367,
3307,
315,
14027,
14,
2340,
63,
28388,
14,
362,
342,
520,
490,
367,
333,
264,
315,
1335,
2611,
14,
45,
11695,
63,
42,
6849,
63,
907,
520,
717,
340,
333,
264,
59,
16,
1055,
1431,
8,
3307,
59,
18,
1055,
362,
63,
354,
342,
776,
520,
1169,
367,
284,
315,
3307,
59,
19,
1055,
24894,
342,
520,
1816,
291,
423,
525,
8,
620,
8,
73,
9,
776,
339,
347,
485,
525,
8,
277,
12,
6193,
9,
520,
267,
634,
275,
942,
267,
671,
275,
3087,
267,
367,
284,
315,
6193,
520,
288,
340,
284,
440,
315,
1335,
2611,
14,
45,
11695,
63,
42,
6849,
63,
32382,
14,
1459,
342,
520,
355,
671,
847,
284,
288,
587,
520,
355,
634,
14,
740,
8,
671,
776,
355,
634,
14,
740,
8,
284,
776,
355,
671,
275,
3087,
398,
340,
822,
8,
76,
9,
690,
413,
520,
288,
634,
14,
740,
8,
671,
776,
398,
291,
423,
525,
63,
3684,
8,
634,
776,
339,
347,
485,
525,
63,
3684,
8,
277,
12,
634,
9,
520,
267,
340,
634,
508,
942,
520,
288,
372,
267,
284,
275,
378,
267,
1830,
284,
665,
334,
552,
8,
76,
7216,
17,
9,
520,
288,
291,
855,
39,
14,
525,
63,
5173,
8,
291,
423,
4711,
8,
76,
59,
73,
2522,
291,
423,
4711,
8,
76,
59,
73,
11,
17,
566,
776,
953,
284,
847,
413,
339,
347,
485,
4711,
8,
277,
12,
284,
9,
520,
267,
340,
298,
23129,
2,
315,
284,
520,
288,
372,
298,
54,
2,
267,
372,
284,
339,
347,
892,
8,
277,
12,
4438,
9,
520,
267,
5348,
275,
942,
398,
634,
275,
769,
8,
291,
855,
39,
14,
932,
776,
398,
4205,
275,
634,
59,
2196,
14,
8393,
8,
16,
12,
822,
8,
76,
9,
446,
413,
9,
1622,
267,
1830,
4205,
315,
1335,
2611,
14,
45,
11695,
63,
42,
6849,
63,
32382,
14,
1459,
342,
520,
288,
4205,
275,
634,
59,
2196,
14,
8393,
8,
16,
12,
822,
8,
76,
9,
446,
413,
9,
1622,
398,
5348,
14,
740,
8,
4205,
776,
398,
284,
275,
378,
267,
1830,
284,
2695,
4438,
520,
288,
634,
275,
769,
8,
291,
855,
39,
14,
5173,
59,
4205,
1622,
776,
288,
340,
634,
508,
942,
520,
355,
2059,
953,
4205,
275,
221,
634,
59,
2196,
14,
8393,
8,
16,
12,
822,
8,
76,
9,
446,
413,
9,
1622,
288,
5348,
14,
740,
8,
4205,
776,
953,
284,
847,
413,
398,
372,
5348,
339,
347,
2498,
8,
277,
9,
520,
267,
870,
291,
855,
39,
14,
932,
267,
870,
291,
855,
39,
14,
5173,
398,
327,
5485,
63,
2180,
17249,
8,
277,
855,
39,
9,
267,
327,
952,
63,
3287,
8,
277,
855,
39,
2584,
493,
14,
3287,
358,
199,
199,
533,
1603,
6849,
6864,
520,
272,
347,
636,
826,
721,
277,
12,
485,
2611,
12,
485,
10466,
9,
520,
267,
291,
855,
2611,
275,
485,
2611,
267,
291,
855,
10466,
275,
485,
10466,
398,
291,
855,
2495,
569,
265,
275,
9195,
569,
265,
8,
291,
855,
10466,
776,
267,
291,
855,
2495,
569,
265,
14,
2384,
342,
339,
347,
1218,
63,
65,
5551,
425,
8,
277,
12,
1083,
63,
354,
12,
4328,
9,
520,
267,
634,
275,
942,
398,
340,
4328,
59,
16,
61,
508,
378,
520,
288,
634,
14,
740,
8,
359,
298,
12201,
350,
63,
16,
2,
1622,
776,
288,
634,
14,
740,
8,
359,
298,
27566,
2084,
401,
4328,
59,
18,
61,
1622,
776,
288,
634,
14,
740,
8,
359,
298,
524,
698,
401,
4328,
59,
17,
1055,
362,
63,
354,
1062,
4328,
59,
17,
1055,
362,
63,
4120,
342,
1622,
776,
398,
372,
634,
339,
347,
2218,
8,
277,
12,
1083,
12,
3268,
12,
901,
9,
520,
267,
870,
1083,
12,
3268,
12,
901,
267,
5348,
275,
291,
855,
2495,
569,
265,
14,
1222,
8,
959,
776,
398,
870,
901,
14,
362,
63,
354,
1062,
298,
1438,
3311,
1035,
401,
5348,
398,
291,
423,
4711,
8,
5348,
776,
2378,
347,
485,
4711,
8,
277,
12,
5348,
9,
520,
267,
340,
822,
8,
3684,
9,
508,
413,
520,
288,
372,
398,
671,
275,
359,
5348,
14,
1935,
8,
16,
395,
5348,
14,
1935,
8,
17,
395,
5348,
14,
1935,
8,
16,
9,
1622,
199,
199,
3,
420,
1830,
5348,
1137,
942,
520,
199,
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,
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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,
0,
0,
0,
0,
0
] |
orekyuu/intellij-community
|
python/lib/Lib/atexit.py
|
104
|
1631
|
"""
atexit.py - allow programmer to define multiple exit functions to be executed
upon normal program termination.
One public function, register, is defined.
"""
__all__ = ["register"]
import sys
_exithandlers = []
def _run_exitfuncs():
"""run any registered exit functions
_exithandlers is traversed in reverse order so functions are executed
last in, first out.
"""
exc_info = None
while _exithandlers:
func, targs, kargs = _exithandlers.pop()
try:
func(*targs, **kargs)
except SystemExit:
exc_info = sys.exc_info()
except:
import traceback
print >> sys.stderr, "Error in atexit._run_exitfuncs:"
traceback.print_exc()
exc_info = sys.exc_info()
if exc_info is not None:
raise exc_info[0], exc_info[1], exc_info[2]
def register(func, *targs, **kargs):
"""register a function to be executed upon normal program termination
func - function to be called at exit
targs - optional arguments to pass to func
kargs - optional keyword arguments to pass to func
"""
_exithandlers.append((func, targs, kargs))
if hasattr(sys, "exitfunc"):
# Assume it's another registered exit function - append it to our list
register(sys.exitfunc)
sys.exitfunc = _run_exitfuncs
if __name__ == "__main__":
def x1():
print "running x1"
def x2(n):
print "running x2(%r)" % (n,)
def x3(n, kwd=None):
print "running x3(%r, kwd=%r)" % (n, kwd)
register(x1)
register(x2, 12)
register(x3, 5, "bar")
register(x3, "no kwd args")
|
apache-2.0
|
[
624,
199,
24026,
390,
14,
647,
446,
2040,
2240,
2626,
370,
5627,
3663,
4458,
3423,
370,
506,
7934,
199,
13527,
3293,
2240,
23868,
14,
199,
199,
4395,
4575,
805,
12,
2274,
12,
365,
3247,
14,
199,
624,
199,
199,
363,
452,
363,
275,
2097,
2683,
937,
199,
199,
646,
984,
199,
199,
63,
476,
448,
1221,
83,
275,
942,
199,
318,
485,
1065,
63,
2224,
9204,
837,
272,
408,
1065,
1263,
7264,
4458,
3423,
339,
485,
476,
448,
1221,
83,
365,
1468,
7460,
315,
3837,
1865,
880,
3423,
787,
7934,
272,
2061,
315,
12,
1642,
734,
14,
272,
408,
339,
3178,
63,
815,
275,
488,
272,
1830,
485,
476,
448,
1221,
83,
26,
267,
2562,
12,
307,
589,
12,
1022,
589,
275,
485,
476,
448,
1221,
83,
14,
1935,
342,
267,
862,
26,
288,
2562,
2031,
84,
589,
12,
1011,
24459,
9,
267,
871,
14838,
26,
288,
3178,
63,
815,
275,
984,
14,
2804,
63,
815,
342,
267,
871,
26,
288,
492,
5190,
288,
870,
4331,
984,
14,
3083,
12,
298,
547,
315,
19840,
423,
1065,
63,
2224,
9204,
5424,
288,
5190,
14,
1361,
63,
2804,
342,
288,
3178,
63,
815,
275,
984,
14,
2804,
63,
815,
342,
339,
340,
3178,
63,
815,
365,
440,
488,
26,
267,
746,
3178,
63,
815,
59,
16,
467,
3178,
63,
815,
59,
17,
467,
3178,
63,
815,
59,
18,
61,
421,
199,
318,
2274,
8,
1532,
12,
627,
84,
589,
12,
1011,
24459,
304,
272,
408,
2683,
282,
805,
370,
506,
7934,
12188,
3293,
2240,
23868,
339,
2562,
446,
805,
370,
506,
2797,
737,
4458,
272,
307,
589,
446,
2716,
2368,
370,
986,
370,
2562,
272,
1022,
589,
446,
2716,
4252,
2368,
370,
986,
370,
2562,
272,
408,
272,
485,
476,
448,
1221,
83,
14,
740,
1332,
1532,
12,
307,
589,
12,
1022,
589,
430,
199,
199,
692,
2688,
8,
1274,
12,
298,
2224,
1532,
2349,
272,
327,
16269,
652,
1159,
4573,
7264,
4458,
805,
446,
5666,
652,
370,
4154,
769,
272,
2274,
8,
1274,
14,
2224,
1532,
9,
199,
1274,
14,
2224,
1532,
275,
485,
1065,
63,
2224,
9204,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
347,
671,
17,
837,
267,
870,
298,
5720,
671,
17,
2,
272,
347,
671,
18,
8,
78,
304,
267,
870,
298,
5720,
671,
18,
4042,
82,
2924,
450,
334,
78,
4258,
272,
347,
671,
19,
8,
78,
12,
4775,
68,
29,
403,
304,
267,
870,
298,
5720,
671,
19,
4042,
82,
12,
4775,
68,
2458,
82,
2924,
450,
334,
78,
12,
4775,
68,
9,
339,
2274,
8,
88,
17,
9,
272,
2274,
8,
88,
18,
12,
3144,
9,
272,
2274,
8,
88,
19,
12,
959,
12,
298,
1700,
531,
272,
2274,
8,
88,
19,
12,
298,
889,
4775,
68,
1249,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
24026,
390,
14,
647,
446,
2040,
2240,
2626,
370,
5627,
3663,
4458,
3423,
370,
506,
7934,
199,
13527,
3293,
2240,
23868,
14,
199,
199,
4395,
4575,
805,
12,
2274,
12,
365,
3247,
14,
199,
624,
199,
199,
363,
452,
363,
275,
2097,
2683,
937,
199,
199,
646,
984,
199,
199,
63,
476,
448,
1221,
83,
275,
942,
199,
318,
485,
1065,
63,
2224,
9204,
837,
272,
408,
1065,
1263,
7264,
4458,
3423,
339,
485,
476,
448,
1221,
83,
365,
1468,
7460,
315,
3837,
1865,
880,
3423,
787,
7934,
272,
2061,
315,
12,
1642,
734,
14,
272,
408,
339,
3178,
63,
815,
275,
488,
272,
1830,
485,
476,
448,
1221,
83,
26,
267,
2562,
12,
307,
589,
12,
1022,
589,
275,
485,
476,
448,
1221,
83,
14,
1935,
342,
267,
862,
26,
288,
2562,
2031,
84,
589,
12,
1011,
24459,
9,
267,
871,
14838,
26,
288,
3178,
63,
815,
275,
984,
14,
2804,
63,
815,
342,
267,
871,
26,
288,
492,
5190,
288,
870,
4331,
984,
14,
3083,
12,
298,
547,
315,
19840,
423,
1065,
63,
2224,
9204,
5424,
288,
5190,
14,
1361,
63,
2804,
342,
288,
3178,
63,
815,
275,
984,
14,
2804,
63,
815,
342,
339,
340,
3178,
63,
815,
365,
440,
488,
26,
267,
746,
3178,
63,
815,
59,
16,
467,
3178,
63,
815,
59,
17,
467,
3178,
63,
815,
59,
18,
61,
421,
199,
318,
2274,
8,
1532,
12,
627,
84,
589,
12,
1011,
24459,
304,
272,
408,
2683,
282,
805,
370,
506,
7934,
12188,
3293,
2240,
23868,
339,
2562,
446,
805,
370,
506,
2797,
737,
4458,
272,
307,
589,
446,
2716,
2368,
370,
986,
370,
2562,
272,
1022,
589,
446,
2716,
4252,
2368,
370,
986,
370,
2562,
272,
408,
272,
485,
476,
448,
1221,
83,
14,
740,
1332,
1532,
12,
307,
589,
12,
1022,
589,
430,
199,
199,
692,
2688,
8,
1274,
12,
298,
2224,
1532,
2349,
272,
327,
16269,
652,
1159,
4573,
7264,
4458,
805,
446,
5666,
652,
370,
4154,
769,
272,
2274,
8,
1274,
14,
2224,
1532,
9,
199,
1274,
14,
2224,
1532,
275,
485,
1065,
63,
2224,
9204,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
347,
671,
17,
837,
267,
870,
298,
5720,
671,
17,
2,
272,
347,
671,
18,
8,
78,
304,
267,
870,
298,
5720,
671,
18,
4042,
82,
2924,
450,
334,
78,
4258,
272,
347,
671,
19,
8,
78,
12,
4775,
68,
29,
403,
304,
267,
870,
298,
5720,
671,
19,
4042,
82,
12,
4775,
68,
2458,
82,
2924,
450,
334,
78,
12,
4775,
68,
9,
339,
2274,
8,
88,
17,
9,
272,
2274,
8,
88,
18,
12,
3144,
9,
272,
2274,
8,
88,
19,
12,
959,
12,
298,
1700,
531,
272,
2274,
8,
88,
19,
12,
298,
889,
4775,
68,
1249,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
u-ra/android_kernel_htc_msm8660
|
scripts/rt-tester/rt-tester.py
|
11005
|
5307
|
#!/usr/bin/python
#
# rt-mutex tester
#
# (C) 2006 Thomas Gleixner <tglx@linutronix.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
import os
import sys
import getopt
import shutil
import string
# Globals
quiet = 0
test = 0
comments = 0
sysfsprefix = "/sys/devices/system/rttest/rttest"
statusfile = "/status"
commandfile = "/command"
# Command opcodes
cmd_opcodes = {
"schedother" : "1",
"schedfifo" : "2",
"lock" : "3",
"locknowait" : "4",
"lockint" : "5",
"lockintnowait" : "6",
"lockcont" : "7",
"unlock" : "8",
"signal" : "11",
"resetevent" : "98",
"reset" : "99",
}
test_opcodes = {
"prioeq" : ["P" , "eq" , None],
"priolt" : ["P" , "lt" , None],
"priogt" : ["P" , "gt" , None],
"nprioeq" : ["N" , "eq" , None],
"npriolt" : ["N" , "lt" , None],
"npriogt" : ["N" , "gt" , None],
"unlocked" : ["M" , "eq" , 0],
"trylock" : ["M" , "eq" , 1],
"blocked" : ["M" , "eq" , 2],
"blockedwake" : ["M" , "eq" , 3],
"locked" : ["M" , "eq" , 4],
"opcodeeq" : ["O" , "eq" , None],
"opcodelt" : ["O" , "lt" , None],
"opcodegt" : ["O" , "gt" , None],
"eventeq" : ["E" , "eq" , None],
"eventlt" : ["E" , "lt" , None],
"eventgt" : ["E" , "gt" , None],
}
# Print usage information
def usage():
print "rt-tester.py <-c -h -q -t> <testfile>"
print " -c display comments after first command"
print " -h help"
print " -q quiet mode"
print " -t test mode (syntax check)"
print " testfile: read test specification from testfile"
print " otherwise from stdin"
return
# Print progress when not in quiet mode
def progress(str):
if not quiet:
print str
# Analyse a status value
def analyse(val, top, arg):
intval = int(val)
if top[0] == "M":
intval = intval / (10 ** int(arg))
intval = intval % 10
argval = top[2]
elif top[0] == "O":
argval = int(cmd_opcodes.get(arg, arg))
else:
argval = int(arg)
# progress("%d %s %d" %(intval, top[1], argval))
if top[1] == "eq" and intval == argval:
return 1
if top[1] == "lt" and intval < argval:
return 1
if top[1] == "gt" and intval > argval:
return 1
return 0
# Parse the commandline
try:
(options, arguments) = getopt.getopt(sys.argv[1:],'chqt')
except getopt.GetoptError, ex:
usage()
sys.exit(1)
# Parse commandline options
for option, value in options:
if option == "-c":
comments = 1
elif option == "-q":
quiet = 1
elif option == "-t":
test = 1
elif option == '-h':
usage()
sys.exit(0)
# Select the input source
if arguments:
try:
fd = open(arguments[0])
except Exception,ex:
sys.stderr.write("File not found %s\n" %(arguments[0]))
sys.exit(1)
else:
fd = sys.stdin
linenr = 0
# Read the test patterns
while 1:
linenr = linenr + 1
line = fd.readline()
if not len(line):
break
line = line.strip()
parts = line.split(":")
if not parts or len(parts) < 1:
continue
if len(parts[0]) == 0:
continue
if parts[0].startswith("#"):
if comments > 1:
progress(line)
continue
if comments == 1:
comments = 2
progress(line)
cmd = parts[0].strip().lower()
opc = parts[1].strip().lower()
tid = parts[2].strip()
dat = parts[3].strip()
try:
# Test or wait for a status value
if cmd == "t" or cmd == "w":
testop = test_opcodes[opc]
fname = "%s%s%s" %(sysfsprefix, tid, statusfile)
if test:
print fname
continue
while 1:
query = 1
fsta = open(fname, 'r')
status = fsta.readline().strip()
fsta.close()
stat = status.split(",")
for s in stat:
s = s.strip()
if s.startswith(testop[0]):
# Separate status value
val = s[2:].strip()
query = analyse(val, testop, dat)
break
if query or cmd == "t":
break
progress(" " + status)
if not query:
sys.stderr.write("Test failed in line %d\n" %(linenr))
sys.exit(1)
# Issue a command to the tester
elif cmd == "c":
cmdnr = cmd_opcodes[opc]
# Build command string and sys filename
cmdstr = "%s:%s" %(cmdnr, dat)
fname = "%s%s%s" %(sysfsprefix, tid, commandfile)
if test:
print fname
continue
fcmd = open(fname, 'w')
fcmd.write(cmdstr)
fcmd.close()
except Exception,ex:
sys.stderr.write(str(ex))
sys.stderr.write("\nSyntax error in line %d\n" %(linenr))
if not test:
fd.close()
sys.exit(1)
# Normal exit pass
print "Pass"
sys.exit(0)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
14059,
13,
19078,
17570,
199,
3,
199,
3,
334,
35,
9,
8315,
27864,
598,
274,
1148,
1372,
665,
84,
18660,
32,
472,
5373,
1148,
14,
271,
30,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
1015,
499,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
646,
747,
199,
646,
984,
199,
646,
12733,
199,
646,
5145,
199,
646,
1059,
199,
199,
3,
13641,
83,
199,
10243,
275,
378,
199,
396,
275,
378,
199,
6223,
275,
378,
199,
199,
1274,
2319,
1861,
275,
3286,
1274,
15,
6410,
15,
2253,
15,
2591,
396,
15,
2591,
396,
2,
199,
1205,
493,
275,
3286,
1205,
2,
199,
1531,
493,
275,
3286,
1531,
2,
199,
199,
3,
5817,
27388,
199,
1760,
63,
22022,
275,
469,
272,
298,
10487,
1848,
2,
259,
520,
298,
17,
401,
272,
298,
10487,
22976,
2,
258,
520,
298,
18,
401,
272,
298,
831,
2,
3515,
520,
298,
19,
401,
272,
298,
831,
20870,
2,
259,
520,
298,
20,
401,
272,
298,
831,
442,
2,
755,
520,
298,
21,
401,
272,
298,
831,
442,
20870,
2,
520,
298,
22,
401,
272,
298,
831,
11096,
2,
420,
520,
298,
23,
401,
272,
298,
17966,
2,
263,
520,
298,
24,
401,
272,
298,
4653,
2,
263,
520,
298,
845,
401,
272,
298,
264,
30563,
782,
2,
259,
520,
298,
2905,
401,
272,
298,
3958,
2,
260,
520,
298,
1020,
401,
272,
789,
199,
199,
396,
63,
22022,
275,
469,
272,
298,
20572,
4077,
2,
263,
520,
2097,
48,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1359,
28934,
2,
263,
520,
2097,
48,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1359,
974,
84,
2,
263,
520,
2097,
48,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
78,
20572,
4077,
2,
755,
520,
2097,
46,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
78,
1359,
28934,
2,
755,
520,
2097,
46,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
78,
1359,
974,
84,
2,
755,
520,
2097,
46,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
32489,
2,
420,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
378,
467,
272,
298,
893,
831,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
413,
467,
272,
298,
17726,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
499,
467,
272,
298,
17726,
15181,
2,
257,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
650,
467,
272,
298,
9325,
2,
263,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
841,
467,
272,
298,
14325,
4077,
2,
420,
520,
2097,
47,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
14325,
4116,
2,
420,
520,
2097,
47,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
14325,
3308,
2,
420,
520,
2097,
47,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
12056,
266,
81,
2,
755,
520,
2097,
37,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1430,
4116,
2,
755,
520,
2097,
37,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1430,
3308,
2,
755,
520,
2097,
37,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
789,
199,
199,
3,
9101,
4503,
2556,
199,
318,
4503,
837,
272,
870,
298,
2591,
13,
8234,
14,
647,
25549,
67,
446,
72,
446,
81,
446,
84,
30,
665,
21091,
4335,
272,
870,
298,
446,
67,
259,
2929,
6786,
2410,
1642,
1414,
2,
272,
870,
298,
446,
72,
259,
1720,
2,
272,
870,
298,
446,
81,
259,
11971,
818,
2,
272,
870,
298,
446,
84,
259,
511,
818,
334,
7093,
1104,
2924,
272,
870,
298,
30530,
26,
1586,
511,
8929,
687,
30530,
2,
272,
870,
298,
4257,
687,
9009,
2,
272,
372,
199,
199,
3,
9101,
6696,
1380,
440,
315,
11971,
818,
199,
318,
6696,
8,
495,
304,
272,
340,
440,
11971,
26,
267,
870,
620,
199,
199,
3,
14279,
261,
282,
2004,
574,
199,
318,
21297,
8,
637,
12,
2746,
12,
1680,
304,
339,
26111,
275,
1109,
8,
637,
9,
339,
340,
2746,
59,
16,
61,
508,
298,
45,
582,
267,
26111,
275,
26111,
1182,
334,
709,
1011,
1109,
8,
1273,
430,
199,
198,
442,
637,
275,
26111,
450,
1616,
267,
27610,
275,
2746,
59,
18,
61,
272,
916,
2746,
59,
16,
61,
508,
298,
47,
582,
267,
27610,
275,
1109,
8,
1760,
63,
22022,
14,
362,
8,
1273,
12,
1680,
430,
272,
587,
26,
267,
27610,
275,
1109,
8,
1273,
9,
339,
327,
6696,
3647,
68,
450,
83,
450,
68,
2,
2818,
442,
637,
12,
2746,
59,
17,
467,
27610,
430,
339,
340,
2746,
59,
17,
61,
508,
298,
4077,
2,
436,
26111,
508,
27610,
26,
199,
198,
1107,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
4116,
2,
436,
26111,
665,
27610,
26,
267,
372,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
3308,
2,
436,
26111,
690,
27610,
26,
199,
198,
1107,
413,
272,
372,
378,
199,
199,
3,
6077,
314,
28279,
199,
893,
26,
272,
334,
1419,
12,
2368,
9,
275,
12733,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
7,
335,
8440,
358,
199,
2590,
12733,
14,
1002,
29368,
12,
444,
26,
272,
4503,
342,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
3,
6077,
28279,
1511,
199,
509,
945,
12,
574,
315,
1511,
26,
272,
340,
945,
508,
3905,
67,
582,
267,
6786,
275,
413,
272,
916,
945,
508,
3905,
81,
582,
267,
11971,
275,
413,
272,
916,
945,
508,
3905,
84,
582,
267,
511,
275,
413,
272,
916,
945,
508,
2475,
72,
356,
267,
4503,
342,
267,
984,
14,
2224,
8,
16,
9,
199,
199,
3,
9496,
314,
1324,
1350,
199,
692,
2368,
26,
272,
862,
26,
267,
6111,
275,
1551,
8,
4958,
59,
16,
566,
272,
871,
2186,
12,
476,
26,
267,
984,
14,
3083,
14,
952,
480,
1173,
440,
1911,
450,
83,
60,
78,
2,
2818,
4958,
59,
16,
2459,
267,
984,
14,
2224
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
14059,
13,
19078,
17570,
199,
3,
199,
3,
334,
35,
9,
8315,
27864,
598,
274,
1148,
1372,
665,
84,
18660,
32,
472,
5373,
1148,
14,
271,
30,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
1015,
499,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
646,
747,
199,
646,
984,
199,
646,
12733,
199,
646,
5145,
199,
646,
1059,
199,
199,
3,
13641,
83,
199,
10243,
275,
378,
199,
396,
275,
378,
199,
6223,
275,
378,
199,
199,
1274,
2319,
1861,
275,
3286,
1274,
15,
6410,
15,
2253,
15,
2591,
396,
15,
2591,
396,
2,
199,
1205,
493,
275,
3286,
1205,
2,
199,
1531,
493,
275,
3286,
1531,
2,
199,
199,
3,
5817,
27388,
199,
1760,
63,
22022,
275,
469,
272,
298,
10487,
1848,
2,
259,
520,
298,
17,
401,
272,
298,
10487,
22976,
2,
258,
520,
298,
18,
401,
272,
298,
831,
2,
3515,
520,
298,
19,
401,
272,
298,
831,
20870,
2,
259,
520,
298,
20,
401,
272,
298,
831,
442,
2,
755,
520,
298,
21,
401,
272,
298,
831,
442,
20870,
2,
520,
298,
22,
401,
272,
298,
831,
11096,
2,
420,
520,
298,
23,
401,
272,
298,
17966,
2,
263,
520,
298,
24,
401,
272,
298,
4653,
2,
263,
520,
298,
845,
401,
272,
298,
264,
30563,
782,
2,
259,
520,
298,
2905,
401,
272,
298,
3958,
2,
260,
520,
298,
1020,
401,
272,
789,
199,
199,
396,
63,
22022,
275,
469,
272,
298,
20572,
4077,
2,
263,
520,
2097,
48,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1359,
28934,
2,
263,
520,
2097,
48,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1359,
974,
84,
2,
263,
520,
2097,
48,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
78,
20572,
4077,
2,
755,
520,
2097,
46,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
78,
1359,
28934,
2,
755,
520,
2097,
46,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
78,
1359,
974,
84,
2,
755,
520,
2097,
46,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
32489,
2,
420,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
378,
467,
272,
298,
893,
831,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
413,
467,
272,
298,
17726,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
499,
467,
272,
298,
17726,
15181,
2,
257,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
650,
467,
272,
298,
9325,
2,
263,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
841,
467,
272,
298,
14325,
4077,
2,
420,
520,
2097,
47,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
14325,
4116,
2,
420,
520,
2097,
47,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
14325,
3308,
2,
420,
520,
2097,
47,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
12056,
266,
81,
2,
755,
520,
2097,
37,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1430,
4116,
2,
755,
520,
2097,
37,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1430,
3308,
2,
755,
520,
2097,
37,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
789,
199,
199,
3,
9101,
4503,
2556,
199,
318,
4503,
837,
272,
870,
298,
2591,
13,
8234,
14,
647,
25549,
67,
446,
72,
446,
81,
446,
84,
30,
665,
21091,
4335,
272,
870,
298,
446,
67,
259,
2929,
6786,
2410,
1642,
1414,
2,
272,
870,
298,
446,
72,
259,
1720,
2,
272,
870,
298,
446,
81,
259,
11971,
818,
2,
272,
870,
298,
446,
84,
259,
511,
818,
334,
7093,
1104,
2924,
272,
870,
298,
30530,
26,
1586,
511,
8929,
687,
30530,
2,
272,
870,
298,
4257,
687,
9009,
2,
272,
372,
199,
199,
3,
9101,
6696,
1380,
440,
315,
11971,
818,
199,
318,
6696,
8,
495,
304,
272,
340,
440,
11971,
26,
267,
870,
620,
199,
199,
3,
14279,
261,
282,
2004,
574,
199,
318,
21297,
8,
637,
12,
2746,
12,
1680,
304,
339,
26111,
275,
1109,
8,
637,
9,
339,
340,
2746,
59,
16,
61,
508,
298,
45,
582,
267,
26111,
275,
26111,
1182,
334,
709,
1011,
1109,
8,
1273,
430,
199,
198,
442,
637,
275,
26111,
450,
1616,
267,
27610,
275,
2746,
59,
18,
61,
272,
916,
2746,
59,
16,
61,
508,
298,
47,
582,
267,
27610,
275,
1109,
8,
1760,
63,
22022,
14,
362,
8,
1273,
12,
1680,
430,
272,
587,
26,
267,
27610,
275,
1109,
8,
1273,
9,
339,
327,
6696,
3647,
68,
450,
83,
450,
68,
2,
2818,
442,
637,
12,
2746,
59,
17,
467,
27610,
430,
339,
340,
2746,
59,
17,
61,
508,
298,
4077,
2,
436,
26111,
508,
27610,
26,
199,
198,
1107,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
4116,
2,
436,
26111,
665,
27610,
26,
267,
372,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
3308,
2,
436,
26111,
690,
27610,
26,
199,
198,
1107,
413,
272,
372,
378,
199,
199,
3,
6077,
314,
28279,
199,
893,
26,
272,
334,
1419,
12,
2368,
9,
275,
12733,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
7,
335,
8440,
358,
199,
2590,
12733,
14,
1002,
29368,
12,
444,
26,
272,
4503,
342,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
3,
6077,
28279,
1511,
199,
509,
945,
12,
574,
315,
1511,
26,
272,
340,
945,
508,
3905,
67,
582,
267,
6786,
275,
413,
272,
916,
945,
508,
3905,
81,
582,
267,
11971,
275,
413,
272,
916,
945,
508,
3905,
84,
582,
267,
511,
275,
413,
272,
916,
945,
508,
2475,
72,
356,
267,
4503,
342,
267,
984,
14,
2224,
8,
16,
9,
199,
199,
3,
9496,
314,
1324,
1350,
199,
692,
2368,
26,
272,
862,
26,
267,
6111,
275,
1551,
8,
4958,
59,
16,
566,
272,
871,
2186,
12,
476,
26,
267,
984,
14,
3083,
14,
952,
480,
1173,
440,
1911,
450,
83,
60,
78,
2,
2818,
4958,
59,
16,
2459,
267,
984,
14,
2224,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
kevin-f-liu/WSBAuto
|
src/finbox_master/finbox_request.py
|
1
|
1927
|
import requests
import io
import json
import csv
from math import floor
class finboxRequest:
def __init__(self):
self.url = "https://api.finbox.io/beta"
self.headers = {
'authorization': "Bearer 509e960d5d374b8958f00bd5e977d13f001925fe",
'accept': "application/json",
'content-type': "application/json"
}
def getUrl(self, extension):
return (self.url + extension)
data = {
"data": {
"finbox_id": {
}
}
}
def floored_percentage(val, digits):
val *= 10 ** (digits + 2)
return '{1:.{0}f}%'.format(digits, floor(val) / 10 ** digits)
fRequest = finboxRequest()
ticker = input("Enter a stock ticker: ")
response = requests.get(fRequest.getUrl("/fairvalues/"+ticker),headers=fRequest.headers)
response = requests.get(fRequest.getUrl("/fairvalues/"+ticker),headers=fRequest.headers)
ticker_parsed = json.loads(response.text)
fvHigh = ticker_parsed.get('data',{}).get('price',{}).get('high')
fvMid = ticker_parsed.get('data',{}).get('price',{}).get('mid')
fvLow = ticker_parsed.get('data',{}).get('price',{}).get('low')
upHigh = floored_percentage(ticker_parsed.get('data',{}).get('upside',{}).get('high'),1)
upMid = floored_percentage(ticker_parsed.get('data',{}).get('upside',{}).get('mid'),1)
upLow = floored_percentage(ticker_parsed.get('data',{}).get('upside',{}).get('low'),1)
print ('Ticker: ' + ticker_parsed.get('data',{}).get('ticker'))
print ('Finbox Fair Value Range: ' + "\n" + "High Fair Value : %.2f" % fvHigh
+ "\n" + "Mid Fair Value : %.2f" % fvMid
+ "\n" + "Low Fair Value : %.2f" % fvLow)
print ('Finbox Upside: ' + "\n" + "High Upside : " + upHigh
+ "\n" + "Mid Upside : " + upMid
+ "\n" + "Low Upside : " + upLow)
print ('Number of Estimates: ' + str(ticker_parsed.get('data',{}).get('estimates')))
print ('Confidence Level: ' + ticker_parsed.get('data',{}).get('confidence'))
|
mit
|
[
646,
4145,
199,
646,
5890,
199,
646,
2022,
199,
646,
7392,
199,
504,
3473,
492,
19841,
199,
199,
533,
2583,
1977,
2017,
26,
2286,
347,
636,
826,
721,
277,
304,
267,
291,
14,
633,
275,
298,
2859,
921,
1246,
14,
2408,
1977,
14,
2308,
15,
5683,
2,
267,
291,
14,
2139,
275,
469,
267,
283,
15846,
356,
298,
3655,
21462,
959,
1643,
69,
25,
2259,
68,
21,
68,
9880,
66,
1407,
2010,
70,
383,
3691,
21,
69,
30605,
68,
969,
70,
25018,
821,
771,
401,
267,
283,
5694,
356,
298,
3578,
15,
1001,
401,
267,
283,
1317,
13,
466,
356,
298,
3578,
15,
1001,
2,
267,
789,
339,
347,
29937,
8,
277,
12,
3329,
304,
267,
372,
334,
277,
14,
633,
435,
3329,
9,
421,
2286,
666,
275,
469,
272,
298,
576,
582,
469,
267,
298,
2408,
1977,
63,
344,
582,
469,
5493,
789,
272,
789,
272,
789,
6905,
421,
199,
318,
289,
320,
2908,
63,
14200,
8,
637,
12,
7576,
304,
272,
1139,
9000,
1616,
1011,
334,
7022,
435,
499,
9,
272,
372,
5041,
17,
14010,
91,
16,
93,
70,
22109,
1370,
908,
8,
7022,
12,
19841,
8,
637,
9,
1182,
1616,
1011,
7576,
9,
199,
199,
70,
2017,
275,
2583,
1977,
2017,
342,
199,
28572,
275,
1324,
480,
8468,
282,
10952,
32721,
26,
6099,
199,
199,
1310,
275,
4145,
14,
362,
8,
70,
2017,
14,
362,
6417,
4769,
667,
723,
1459,
25976,
28572,
395,
2139,
29,
70,
2017,
14,
2139,
9,
28154,
199,
1310,
275,
4145,
14,
362,
8,
70,
2017,
14,
362,
6417,
4769,
667,
723,
1459,
25976,
28572,
395,
2139,
29,
70,
2017,
14,
2139,
9,
199,
199,
28572,
63,
6751,
275,
2022,
14,
3640,
8,
1310,
14,
505,
9,
199,
199,
13692,
11688,
275,
32721,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
4777,
297,
2440,
680,
362,
360,
6260,
358,
199,
13692,
28735,
275,
32721,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
4777,
297,
2440,
680,
362,
360,
8523,
358,
199,
13692,
10281,
275,
32721,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
4777,
297,
2440,
680,
362,
360,
674,
358,
199,
384,
11688,
275,
289,
320,
2908,
63,
14200,
8,
28572,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
384,
2441,
297,
2440,
680,
362,
360,
6260,
659,
17,
9,
199,
384,
28735,
275,
289,
320,
2908,
63,
14200,
8,
28572,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
384,
2441,
297,
2440,
680,
362,
360,
8523,
659,
17,
9,
199,
384,
10281,
275,
289,
320,
2908,
63,
14200,
8,
28572,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
384,
2441,
297,
2440,
680,
362,
360,
674,
659,
17,
9,
199,
199,
1361,
661,
11763,
281,
26,
283,
435,
32721,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
28572,
1333,
199,
1361,
661,
8694,
1977,
481,
8387,
1594,
13114,
26,
283,
435,
1867,
78,
2,
435,
298,
11688,
481,
8387,
1594,
520,
10536,
18,
70,
2,
450,
289,
86,
11688,
199,
11,
1867,
78,
2,
435,
298,
28735,
481,
8387,
1594,
520,
10536,
18,
70,
2,
450,
289,
86,
28735,
199,
11,
1867,
78,
2,
435,
298,
10281,
481,
8387,
1594,
520,
10536,
18,
70,
2,
450,
289,
86,
10281,
9,
199,
1361,
661,
8694,
1977,
4949,
2441,
26,
283,
435,
1867,
78,
2,
435,
298,
11688,
4949,
2441,
520,
298,
435,
1536,
11688,
199,
11,
1867,
78,
2,
435,
298,
28735,
4949,
2441,
520,
298,
435,
1536,
28735,
199,
11,
1867,
78,
2,
435,
298,
10281,
4949,
2441,
520,
298,
435,
1536,
10281,
9,
199,
1361,
661,
3259,
402,
15896,
18187,
26,
283,
435,
620,
8,
28572,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
597,
18187,
7058,
199,
1361,
661,
714,
8866,
20400,
26,
283,
435,
32721,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
13969,
1333,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4145,
199,
646,
5890,
199,
646,
2022,
199,
646,
7392,
199,
504,
3473,
492,
19841,
199,
199,
533,
2583,
1977,
2017,
26,
2286,
347,
636,
826,
721,
277,
304,
267,
291,
14,
633,
275,
298,
2859,
921,
1246,
14,
2408,
1977,
14,
2308,
15,
5683,
2,
267,
291,
14,
2139,
275,
469,
267,
283,
15846,
356,
298,
3655,
21462,
959,
1643,
69,
25,
2259,
68,
21,
68,
9880,
66,
1407,
2010,
70,
383,
3691,
21,
69,
30605,
68,
969,
70,
25018,
821,
771,
401,
267,
283,
5694,
356,
298,
3578,
15,
1001,
401,
267,
283,
1317,
13,
466,
356,
298,
3578,
15,
1001,
2,
267,
789,
339,
347,
29937,
8,
277,
12,
3329,
304,
267,
372,
334,
277,
14,
633,
435,
3329,
9,
421,
2286,
666,
275,
469,
272,
298,
576,
582,
469,
267,
298,
2408,
1977,
63,
344,
582,
469,
5493,
789,
272,
789,
272,
789,
6905,
421,
199,
318,
289,
320,
2908,
63,
14200,
8,
637,
12,
7576,
304,
272,
1139,
9000,
1616,
1011,
334,
7022,
435,
499,
9,
272,
372,
5041,
17,
14010,
91,
16,
93,
70,
22109,
1370,
908,
8,
7022,
12,
19841,
8,
637,
9,
1182,
1616,
1011,
7576,
9,
199,
199,
70,
2017,
275,
2583,
1977,
2017,
342,
199,
28572,
275,
1324,
480,
8468,
282,
10952,
32721,
26,
6099,
199,
199,
1310,
275,
4145,
14,
362,
8,
70,
2017,
14,
362,
6417,
4769,
667,
723,
1459,
25976,
28572,
395,
2139,
29,
70,
2017,
14,
2139,
9,
28154,
199,
1310,
275,
4145,
14,
362,
8,
70,
2017,
14,
362,
6417,
4769,
667,
723,
1459,
25976,
28572,
395,
2139,
29,
70,
2017,
14,
2139,
9,
199,
199,
28572,
63,
6751,
275,
2022,
14,
3640,
8,
1310,
14,
505,
9,
199,
199,
13692,
11688,
275,
32721,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
4777,
297,
2440,
680,
362,
360,
6260,
358,
199,
13692,
28735,
275,
32721,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
4777,
297,
2440,
680,
362,
360,
8523,
358,
199,
13692,
10281,
275,
32721,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
4777,
297,
2440,
680,
362,
360,
674,
358,
199,
384,
11688,
275,
289,
320,
2908,
63,
14200,
8,
28572,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
384,
2441,
297,
2440,
680,
362,
360,
6260,
659,
17,
9,
199,
384,
28735,
275,
289,
320,
2908,
63,
14200,
8,
28572,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
384,
2441,
297,
2440,
680,
362,
360,
8523,
659,
17,
9,
199,
384,
10281,
275,
289,
320,
2908,
63,
14200,
8,
28572,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
384,
2441,
297,
2440,
680,
362,
360,
674,
659,
17,
9,
199,
199,
1361,
661,
11763,
281,
26,
283,
435,
32721,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
28572,
1333,
199,
1361,
661,
8694,
1977,
481,
8387,
1594,
13114,
26,
283,
435,
1867,
78,
2,
435,
298,
11688,
481,
8387,
1594,
520,
10536,
18,
70,
2,
450,
289,
86,
11688,
199,
11,
1867,
78,
2,
435,
298,
28735,
481,
8387,
1594,
520,
10536,
18,
70,
2,
450,
289,
86,
28735,
199,
11,
1867,
78,
2,
435,
298,
10281,
481,
8387,
1594,
520,
10536,
18,
70,
2,
450,
289,
86,
10281,
9,
199,
1361,
661,
8694,
1977,
4949,
2441,
26,
283,
435,
1867,
78,
2,
435,
298,
11688,
4949,
2441,
520,
298,
435,
1536,
11688,
199,
11,
1867,
78,
2,
435,
298,
28735,
4949,
2441,
520,
298,
435,
1536,
28735,
199,
11,
1867,
78,
2,
435,
298,
10281,
4949,
2441,
520,
298,
435,
1536,
10281,
9,
199,
1361,
661,
3259,
402,
15896,
18187,
26,
283,
435,
620,
8,
28572,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
597,
18187,
7058,
199,
1361,
661,
714,
8866,
20400,
26,
283,
435,
32721,
63,
6751,
14,
362,
360,
576,
297,
2440,
680,
362,
360,
13969,
1333,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1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-intro/examples/grocery_project/grocery_project/settings.py
|
3
|
5489
|
# Django settings for grocery_project project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '/Users/me/Documents/Py/PyClass/lessons/django-intro/examples/grocery_project/example.db', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = ')u-4pyjo*04q9@5)d1jyg^z3%spq^%cylw3c(heeb+i57k2&ge'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'grocery_project.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'grocery_project.wsgi.application'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'grocery_list',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
|
mit
|
[
3,
5634,
2202,
367,
486,
26786,
994,
63,
1715,
2199,
14,
199,
199,
5287,
275,
715,
199,
7433,
63,
5287,
275,
10990,
199,
199,
14288,
51,
275,
334,
272,
327,
661,
14398,
2812,
297,
283,
12695,
63,
2123,
32,
2694,
14,
957,
659,
199,
9,
199,
199,
20600,
3960,
275,
29948,
51,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
10659,
19,
297,
327,
2654,
283,
15437,
63,
20270,
18,
297,
283,
8644,
297,
283,
10659,
19,
7,
503,
283,
16404,
1370,
267,
283,
2339,
356,
1994,
12117,
15,
278,
15,
26872,
15,
2713,
15,
2713,
2543,
15,
2003,
4654,
15,
1176,
13,
18206,
15,
8589,
15,
23260,
67,
994,
63,
1715,
15,
2694,
14,
697,
297,
10473,
327,
4236,
931,
370,
3050,
570,
340,
1808,
11723,
19,
14,
267,
327,
710,
2569,
2202,
787,
440,
1202,
543,
11723,
19,
26,
267,
283,
3791,
356,
3260,
267,
283,
9032,
356,
3260,
267,
283,
5449,
356,
3260,
10473,
327,
9630,
367,
11667,
4012,
2881,
18772,
503,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
367,
11667,
4012,
13488,
14,
267,
283,
3657,
356,
3260,
10473,
327,
2494,
370,
2701,
1059,
367,
849,
14,
272,
789,
199,
93,
199,
199,
3,
10891,
83,
15,
2261,
1561,
626,
787,
1686,
367,
642,
4770,
27,
1415,
340,
10990,
365,
756,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
21,
15,
1121,
15,
1751,
12645,
6541,
13,
5146,
199,
17350,
63,
23775,
275,
942,
199,
199,
3,
10111,
900,
5718,
367,
642,
12096,
14,
8802,
2370,
883,
506,
1911,
2348,
26,
199,
3,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
1296,
63,
1618,
63,
3903,
63,
13325,
63,
991,
63,
354,
199,
3,
22160,
440,
1006,
3415,
1443,
506,
2808,
641,
1006,
17406,
10460,
14,
199,
3,
1010,
282,
5417,
3734,
642,
1471,
506,
663,
370,
2195,
2656,
900,
5718,
14,
199,
4961,
63,
15353,
275,
283,
8841,
15,
28796,
7,
199,
199,
3,
8466,
1233,
367,
642,
12096,
14,
2900,
3415,
883,
506,
1911,
2348,
26,
199,
3,
1455,
921,
1544,
14,
73,
1085,
2753,
29514,
14,
957,
15,
2975,
15,
3671,
13,
14227,
14,
1360,
199,
13947,
63,
6012,
275,
283,
287,
13,
527,
7,
199,
199,
7917,
63,
998,
275,
413,
199,
199,
3,
982,
1265,
663,
642,
370,
756,
12,
5634,
911,
1852,
2005,
5323,
12270,
880,
465,
440,
199,
3,
370,
2248,
314,
10757,
6279,
2072,
28540,
14,
199,
4701,
63,
41,
1085,
46,
275,
715,
199,
199,
3,
982,
1265,
663,
642,
370,
756,
12,
5634,
911,
440,
1475,
10831,
12,
5579,
436,
199,
3,
1704,
31276,
7182,
370,
314,
1453,
5867,
14,
199,
4701,
63,
44,
709,
46,
275,
715,
199,
199,
3,
982,
1265,
663,
642,
370,
756,
12,
5634,
911,
440,
675,
7137,
13,
14600,
29297,
14,
199,
4701,
63,
14226,
275,
715,
199,
199,
3,
24964,
10036,
931,
370,
314,
2082,
626,
911,
10266,
922,
13,
19044,
1584,
14,
199,
3,
5679,
26,
3286,
1391,
15,
1544,
15,
2694,
14,
957,
15,
4603,
6687,
199,
13669,
63,
5441,
275,
2125,
199,
199,
3,
2851,
626,
10022,
314,
5898,
19733,
687,
31460,
63,
5441,
14,
4155,
3238,
370,
675,
282,
199,
3,
8520,
14457,
14,
199,
3,
6058,
26,
298,
1014,
921,
2694,
14,
957,
15,
4603,
10665,
298,
1014,
921,
4603,
14,
2694,
14,
957,
6687,
199,
13669,
63,
2632,
275,
2125,
199,
199,
3,
24964,
931,
370,
314,
2082,
2955,
1584,
1077,
506,
13736,
370,
14,
199,
3,
7529,
1133,
5324,
7003,
315,
642,
2082,
28225,
27,
3877,
2195,
2955,
1584,
199,
3,
315,
8686,
7,
298,
1986,
6687,
24799,
436,
315,
27815,
9472,
63,
14455,
14,
199,
3,
5679,
26,
3286,
1391,
15,
1544,
15,
2694,
14,
957,
15,
1986,
6687,
199,
10449,
63,
5441,
275,
2125,
199,
199,
3,
2851,
2403,
367,
2955,
1584,
14,
199,
3,
5679,
26,
298,
1014,
921,
2694,
14,
957,
15,
1986,
10665,
298,
1014,
921,
1986,
14,
2694,
14,
957,
6687,
199,
10449,
63,
2632,
275,
1994,
1986,
4805,
199,
199,
3,
10961,
9918,
402,
2955,
1584,
199,
10449,
9472,
63,
14455,
275,
334,
272,
327,
16280,
3326,
2348,
12,
2839,
3286,
4219,
15,
1360,
15,
1986,
2,
503,
298,
35,
11254,
1544,
15,
1176,
15,
1986,
1674,
272,
327,
16763,
675,
7568,
20275,
12,
2755,
641,
5417,
14,
272,
327,
7529,
1133,
19459,
370,
675,
3679,
3792,
12,
440,
3847,
3792,
14,
199,
9,
199,
199,
3,
3820,
402,
11569,
3992,
626,
5715,
4212,
370,
2342,
2955,
1584,
315,
199,
3,
7750,
9918,
14,
199,
10449,
9472,
63,
27087,
3960,
275,
334,
272,
283,
1176,
14,
2828,
14,
18373,
14,
26677,
14,
17521,
11791,
297,
272,
283,
1176,
14,
2828,
14,
18373,
14,
26677,
14,
2640,
13752,
11791,
297,
199,
3,
259,
283,
1176,
14,
2828,
14,
18373,
14,
26677,
14,
2698,
6408,
11791,
297,
199,
9,
199,
199,
3,
4155,
642,
3747,
12,
436,
2793,
1133,
8663,
652,
543,
1263,
2030,
14,
199,
12961,
63,
3078,
275,
5320,
85,
13,
20,
647,
743,
10,
966,
81,
25,
32,
21,
9,
68,
17,
74,
5016,
62,
90,
19,
5,
681,
81,
62,
5,
1480,
20692,
19,
67,
8,
426,
2871,
11,
73,
1641,
75,
18,
6,
303,
7,
199,
199,
3,
3820,
402,
28041,
626,
5715,
4212,
370,
492,
7009,
687,
7750,
5274,
14,
199,
7433,
63,
7405,
3960,
275,
334,
272,
283,
1176,
14,
1160,
14,
16370,
14,
11381,
14,
5455,
297,
272,
283,
1176,
14,
1160,
14,
16370,
14,
571,
63,
12629,
14,
5455,
297,
199,
3,
258,
283,
1176,
14,
1160,
14,
16370,
14,
14488,
14,
5455,
297,
199,
9,
199,
199,
19987,
63,
13748,
275,
334,
272,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
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,
327,
1910,
3349
] |
[
5634,
2202,
367,
486,
26786,
994,
63,
1715,
2199,
14,
199,
199,
5287,
275,
715,
199,
7433,
63,
5287,
275,
10990,
199,
199,
14288,
51,
275,
334,
272,
327,
661,
14398,
2812,
297,
283,
12695,
63,
2123,
32,
2694,
14,
957,
659,
199,
9,
199,
199,
20600,
3960,
275,
29948,
51,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
10659,
19,
297,
327,
2654,
283,
15437,
63,
20270,
18,
297,
283,
8644,
297,
283,
10659,
19,
7,
503,
283,
16404,
1370,
267,
283,
2339,
356,
1994,
12117,
15,
278,
15,
26872,
15,
2713,
15,
2713,
2543,
15,
2003,
4654,
15,
1176,
13,
18206,
15,
8589,
15,
23260,
67,
994,
63,
1715,
15,
2694,
14,
697,
297,
10473,
327,
4236,
931,
370,
3050,
570,
340,
1808,
11723,
19,
14,
267,
327,
710,
2569,
2202,
787,
440,
1202,
543,
11723,
19,
26,
267,
283,
3791,
356,
3260,
267,
283,
9032,
356,
3260,
267,
283,
5449,
356,
3260,
10473,
327,
9630,
367,
11667,
4012,
2881,
18772,
503,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
367,
11667,
4012,
13488,
14,
267,
283,
3657,
356,
3260,
10473,
327,
2494,
370,
2701,
1059,
367,
849,
14,
272,
789,
199,
93,
199,
199,
3,
10891,
83,
15,
2261,
1561,
626,
787,
1686,
367,
642,
4770,
27,
1415,
340,
10990,
365,
756,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
21,
15,
1121,
15,
1751,
12645,
6541,
13,
5146,
199,
17350,
63,
23775,
275,
942,
199,
199,
3,
10111,
900,
5718,
367,
642,
12096,
14,
8802,
2370,
883,
506,
1911,
2348,
26,
199,
3,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
1296,
63,
1618,
63,
3903,
63,
13325,
63,
991,
63,
354,
199,
3,
22160,
440,
1006,
3415,
1443,
506,
2808,
641,
1006,
17406,
10460,
14,
199,
3,
1010,
282,
5417,
3734,
642,
1471,
506,
663,
370,
2195,
2656,
900,
5718,
14,
199,
4961,
63,
15353,
275,
283,
8841,
15,
28796,
7,
199,
199,
3,
8466,
1233,
367,
642,
12096,
14,
2900,
3415,
883,
506,
1911,
2348,
26,
199,
3,
1455,
921,
1544,
14,
73,
1085,
2753,
29514,
14,
957,
15,
2975,
15,
3671,
13,
14227,
14,
1360,
199,
13947,
63,
6012,
275,
283,
287,
13,
527,
7,
199,
199,
7917,
63,
998,
275,
413,
199,
199,
3,
982,
1265,
663,
642,
370,
756,
12,
5634,
911,
1852,
2005,
5323,
12270,
880,
465,
440,
199,
3,
370,
2248,
314,
10757,
6279,
2072,
28540,
14,
199,
4701,
63,
41,
1085,
46,
275,
715,
199,
199,
3,
982,
1265,
663,
642,
370,
756,
12,
5634,
911,
440,
1475,
10831,
12,
5579,
436,
199,
3,
1704,
31276,
7182,
370,
314,
1453,
5867,
14,
199,
4701,
63,
44,
709,
46,
275,
715,
199,
199,
3,
982,
1265,
663,
642,
370,
756,
12,
5634,
911,
440,
675,
7137,
13,
14600,
29297,
14,
199,
4701,
63,
14226,
275,
715,
199,
199,
3,
24964,
10036,
931,
370,
314,
2082,
626,
911,
10266,
922,
13,
19044,
1584,
14,
199,
3,
5679,
26,
3286,
1391,
15,
1544,
15,
2694,
14,
957,
15,
4603,
6687,
199,
13669,
63,
5441,
275,
2125,
199,
199,
3,
2851,
626,
10022,
314,
5898,
19733,
687,
31460,
63,
5441,
14,
4155,
3238,
370,
675,
282,
199,
3,
8520,
14457,
14,
199,
3,
6058,
26,
298,
1014,
921,
2694,
14,
957,
15,
4603,
10665,
298,
1014,
921,
4603,
14,
2694,
14,
957,
6687,
199,
13669,
63,
2632,
275,
2125,
199,
199,
3,
24964,
931,
370,
314,
2082,
2955,
1584,
1077,
506,
13736,
370,
14,
199,
3,
7529,
1133,
5324,
7003,
315,
642,
2082,
28225,
27,
3877,
2195,
2955,
1584,
199,
3,
315,
8686,
7,
298,
1986,
6687,
24799,
436,
315,
27815,
9472,
63,
14455,
14,
199,
3,
5679,
26,
3286,
1391,
15,
1544,
15,
2694,
14,
957,
15,
1986,
6687,
199,
10449,
63,
5441,
275,
2125,
199,
199,
3,
2851,
2403,
367,
2955,
1584,
14,
199,
3,
5679,
26,
298,
1014,
921,
2694,
14,
957,
15,
1986,
10665,
298,
1014,
921,
1986,
14,
2694,
14,
957,
6687,
199,
10449,
63,
2632,
275,
1994,
1986,
4805,
199,
199,
3,
10961,
9918,
402,
2955,
1584,
199,
10449,
9472,
63,
14455,
275,
334,
272,
327,
16280,
3326,
2348,
12,
2839,
3286,
4219,
15,
1360,
15,
1986,
2,
503,
298,
35,
11254,
1544,
15,
1176,
15,
1986,
1674,
272,
327,
16763,
675,
7568,
20275,
12,
2755,
641,
5417,
14,
272,
327,
7529,
1133,
19459,
370,
675,
3679,
3792,
12,
440,
3847,
3792,
14,
199,
9,
199,
199,
3,
3820,
402,
11569,
3992,
626,
5715,
4212,
370,
2342,
2955,
1584,
315,
199,
3,
7750,
9918,
14,
199,
10449,
9472,
63,
27087,
3960,
275,
334,
272,
283,
1176,
14,
2828,
14,
18373,
14,
26677,
14,
17521,
11791,
297,
272,
283,
1176,
14,
2828,
14,
18373,
14,
26677,
14,
2640,
13752,
11791,
297,
199,
3,
259,
283,
1176,
14,
2828,
14,
18373,
14,
26677,
14,
2698,
6408,
11791,
297,
199,
9,
199,
199,
3,
4155,
642,
3747,
12,
436,
2793,
1133,
8663,
652,
543,
1263,
2030,
14,
199,
12961,
63,
3078,
275,
5320,
85,
13,
20,
647,
743,
10,
966,
81,
25,
32,
21,
9,
68,
17,
74,
5016,
62,
90,
19,
5,
681,
81,
62,
5,
1480,
20692,
19,
67,
8,
426,
2871,
11,
73,
1641,
75,
18,
6,
303,
7,
199,
199,
3,
3820,
402,
28041,
626,
5715,
4212,
370,
492,
7009,
687,
7750,
5274,
14,
199,
7433,
63,
7405,
3960,
275,
334,
272,
283,
1176,
14,
1160,
14,
16370,
14,
11381,
14,
5455,
297,
272,
283,
1176,
14,
1160,
14,
16370,
14,
571,
63,
12629,
14,
5455,
297,
199,
3,
258,
283,
1176,
14,
1160,
14,
16370,
14,
14488,
14,
5455,
297,
199,
9,
199,
199,
19987,
63,
13748,
275,
334,
272,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
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,
327,
1910,
3349,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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9
|
5570
|
from __future__ import unicode_literals
import re
from netmiko.ssh_connection import BaseSSHConnection
class JuniperSSH(BaseSSHConnection):
"""Implement methods for interacting with Juniper Networks devices.
Subclass of SSHConnection. Disables `enable()` and `check_enable_mode()`
methods. Overrides several methods for Juniper-specific compatibility.
"""
def session_preparation(self):
"""Prepare the session after the connection has been established.
Disable paging (the '--more--' prompts).
Set the base prompt for interaction ('>').
"""
self.disable_paging(command="set cli screen-length 0\n")
self.set_base_prompt()
def config_mode(self, config_command='configure'):
'''
Enter configuration mode.
Checks to see if the session is already in configuration mode first.
Raises `ValueError` if the session was unable to enter configuration
mode.
'''
# Call parent class with specific command for entering config mode
return super(JuniperSSH, self).config_mode(config_command=config_command)
def exit_config_mode(self, exit_config='exit configuration-mode'):
"""Exit configuration mode.
Check if we're in configuration mode. If we are, exit configuration
mode. If we aren't, do nothing.
"""
output = ""
if self.check_config_mode():
output = self.send_command(exit_config, strip_prompt=False, strip_command=False)
if 'Exit with uncommitted changes?' in output:
output += self.send_command('yes', strip_prompt=False, strip_command=False)
if self.check_config_mode():
raise ValueError("Failed to exit configuration mode")
return output
def check_config_mode(self, check_string=']'):
'''
Checks if the device is in configuration mode or not
Returns a boolean
'''
# Call parent class with Juniper check_string
return super(JuniperSSH, self).check_config_mode(check_string=check_string)
def commit(self, confirm=False, confirm_delay=None, check=False, comment='',
and_quit=False, delay_factor=10):
"""
Commit the candidate configuration.
Commit the entered configuration. Raise an error and return the failure
if the commit fails.
Automatically enters configuration mode
default:
command_string = commit
check and (confirm or confirm_dely or comment):
Exception
confirm_delay and no confirm:
Exception
confirm:
confirm_delay option
comment option
command_string = commit confirmed or commit confirmed <confirm_delay>
check:
command_string = commit check
"""
if check and (confirm or confirm_delay or comment):
raise ValueError("Invalid arguments supplied with commit check")
if confirm_delay and not confirm:
raise ValueError("Invalid arguments supplied to commit method both confirm and check")
# Select proper command string based on arguments provided
command_string = 'commit'
commit_marker = 'commit complete'
if check:
command_string = 'commit check'
commit_marker = 'configuration check succeeds'
elif confirm:
if confirm_delay:
command_string = 'commit confirmed ' + str(confirm_delay)
else:
command_string = 'commit confirmed'
commit_marker = 'commit confirmed will be automatically rolled back in'
# wrap the comment in quotes
if comment:
if '"' in comment:
raise ValueError("Invalid comment contains double quote")
comment = '"{0}"'.format(comment)
command_string += ' comment ' + comment
if and_quit:
command_string += ' and-quit'
# Enter config mode (if necessary)
output = self.config_mode()
output += self.send_command(command_string, strip_prompt=False, strip_command=False,
delay_factor=delay_factor)
if not commit_marker in output:
raise ValueError("Commit failed with the following errors:\n\n{0}"
.format(output))
return output
def strip_prompt(self, *args, **kwargs):
"""Strip the trailing router prompt from the output."""
# Call the superclass strip_prompt method
a_string = super(JuniperSSH, self).strip_prompt(*args, **kwargs)
# Call additional method to strip some context items
return self.strip_context_items(a_string)
@staticmethod
def strip_context_items(a_string):
"""Strip Juniper-specific output.
Juniper will also put a configuration context:
[edit]
and various chassis contexts:
{master:0}, {backup:1}
This method removes those lines.
"""
strings_to_strip = [
r'\[edit.*\]',
r'\{master:.*\}',
r'\{backup:.*\}',
r'\{line.*\}',
r'\{primary.*\}',
r'\{secondary.*\}',
]
response_list = a_string.split('\n')
last_line = response_list[-1]
for pattern in strings_to_strip:
if re.search(pattern, last_line):
return "\n".join(response_list[:-1])
return a_string
|
mit
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
295,
199,
199,
504,
1851,
2664,
7697,
14,
5510,
63,
2105,
492,
3523,
13716,
3225,
199,
199,
533,
1603,
5411,
529,
13716,
8,
1563,
13716,
3225,
304,
272,
408,
26924,
3102,
367,
17232,
316,
543,
1603,
5411,
529,
17138,
7256,
14,
339,
30184,
402,
12027,
3225,
14,
221,
5289,
5921,
658,
4296,
11995,
436,
658,
1074,
63,
4296,
63,
632,
11995,
272,
3102,
14,
221,
31144,
9978,
3102,
367,
1603,
5411,
529,
13,
6100,
7163,
14,
272,
408,
339,
347,
2351,
63,
657,
462,
425,
8,
277,
304,
267,
408,
22281,
314,
2351,
2410,
314,
1950,
965,
2757,
23594,
14,
398,
17534,
299,
7407,
334,
1589,
2850,
6878,
306,
7,
29951,
680,
267,
2494,
314,
1300,
8457,
367,
18752,
661,
30,
1959,
267,
408,
267,
291,
14,
5993,
63,
31691,
8,
1531,
628,
409,
5053,
6426,
13,
1267,
378,
60,
78,
531,
267,
291,
14,
409,
63,
1095,
63,
7650,
342,
2378,
347,
1101,
63,
632,
8,
277,
12,
1101,
63,
1531,
534,
6472,
735,
267,
1449,
267,
16401,
2897,
818,
14,
398,
13813,
370,
1937,
340,
314,
2351,
365,
2575,
315,
2897,
818,
1642,
14,
267,
6218,
658,
3393,
64,
340,
314,
2351,
1990,
17329,
370,
9509,
2897,
267,
818,
14,
267,
1449,
398,
327,
6523,
1676,
1021,
543,
2488,
1414,
367,
9509,
316,
1101,
818,
267,
372,
1613,
8,
42,
5411,
529,
13716,
12,
291,
680,
888,
63,
632,
8,
888,
63,
1531,
29,
888,
63,
1531,
9,
2378,
347,
4458,
63,
888,
63,
632,
8,
277,
12,
4458,
63,
888,
534,
2224,
2897,
13,
632,
735,
267,
408,
6699,
2897,
818,
14,
398,
2670,
340,
781,
3984,
315,
2897,
818,
14,
221,
982,
781,
787,
12,
4458,
2897,
267,
818,
14,
221,
982,
781,
10621,
1133,
12,
886,
6548,
14,
267,
408,
398,
1072,
275,
3087,
267,
340,
291,
14,
1074,
63,
888,
63,
632,
837,
288,
1072,
275,
291,
14,
2254,
63,
1531,
8,
2224,
63,
888,
12,
6202,
63,
7650,
29,
797,
12,
6202,
63,
1531,
29,
797,
9,
288,
340,
283,
6699,
543,
625,
20300,
4493,
14069,
315,
1072,
26,
355,
1072,
847,
291,
14,
2254,
63,
1531,
360,
5066,
297,
6202,
63,
7650,
29,
797,
12,
6202,
63,
1531,
29,
797,
9,
288,
340,
291,
14,
1074,
63,
888,
63,
632,
837,
355,
746,
1722,
480,
4276,
370,
4458,
2897,
818,
531,
398,
372,
1072,
2378,
347,
1104,
63,
888,
63,
632,
8,
277,
12,
1104,
63,
875,
29,
418,
735,
267,
1449,
267,
13813,
340,
314,
2243,
365,
315,
2897,
818,
503,
440,
398,
1803,
282,
5046,
267,
1449,
398,
327,
6523,
1676,
1021,
543,
1603,
5411,
529,
1104,
63,
875,
267,
372,
1613,
8,
42,
5411,
529,
13716,
12,
291,
680,
1074,
63,
888,
63,
632,
8,
1074,
63,
875,
29,
1074,
63,
875,
9,
2378,
347,
5532,
8,
277,
12,
12679,
29,
797,
12,
12679,
63,
5814,
29,
403,
12,
1104,
29,
797,
12,
3721,
4581,
2049,
436,
63,
10589,
29,
797,
12,
7339,
63,
4778,
29,
709,
304,
267,
408,
267,
21447,
314,
7627,
2897,
14,
398,
21447,
314,
19138,
2897,
14,
14771,
376,
1125,
436,
372,
314,
5988,
267,
340,
314,
5532,
6918,
14,
398,
9195,
17174,
655,
878,
2897,
818,
398,
849,
26,
288,
1414,
63,
875,
275,
5532,
267,
1104,
436,
334,
9548,
503,
12679,
63,
271,
590,
503,
3721,
304,
288,
2186,
267,
12679,
63,
5814,
436,
949,
12679,
26,
288,
2186,
267,
12679,
26,
288,
12679,
63,
5814,
945,
288,
3721,
945,
288,
1414,
63,
875,
275,
5532,
22763,
503,
5532,
22763,
665,
9548,
63,
5814,
30,
267,
1104,
26,
288,
1414,
63,
875,
275,
5532,
1104,
398,
408,
398,
340,
1104,
436,
334,
9548,
503,
12679,
63,
5814,
503,
3721,
304,
288,
746,
1722,
480,
3364,
2368,
6841,
543,
5532,
1104,
531,
398,
340,
12679,
63,
5814,
436,
440,
12679,
26,
288,
746,
1722,
480,
3364,
2368,
6841,
370,
5532,
1083,
3865,
12679,
436,
1104,
531,
398,
327,
9496,
5576,
1414,
1059,
4079,
641,
2368,
2741,
267,
1414,
63,
875,
275,
283,
3543,
7,
267,
5532,
63,
4211,
275,
283,
3543,
4890,
7,
267,
340,
1104,
26,
288,
1414,
63,
875,
275,
283,
3543,
1104,
7,
288,
5532,
63,
4211,
275,
283,
4758,
1104,
24611,
7,
267,
916,
12679,
26,
288,
340,
12679,
63,
5814,
26,
355,
1414,
63,
875,
275,
283,
3543,
22763,
283,
435,
620,
8,
9548,
63,
5814,
9,
288,
587,
26,
355,
1414,
63,
875,
275,
283,
3543,
22763,
7,
288,
5532,
63,
4211,
275,
283,
3543,
22763,
911,
506,
5847,
20182,
1146,
1771,
315,
7,
398,
327,
4816,
314,
3721,
315,
9344,
267,
340,
3721,
26,
288,
340,
14788,
315,
3721,
26,
355,
746,
1722,
480,
3364,
3721,
3509,
4270,
6313,
531,
288,
3721,
275,
5522,
91,
16,
7063,
1370,
908,
8,
3349,
9,
953,
1414,
63,
875,
847,
283,
3721,
283,
435,
3721,
398,
340,
436,
63,
10589,
26,
288,
1414,
63,
875,
847,
283,
436,
13,
10589,
7,
398,
327,
16401,
1101,
818,
334,
692,
5784,
9,
267,
1072,
275,
291,
14,
888,
63,
632,
342,
267,
1072,
847,
291,
14,
2254,
63,
1531,
8,
1531,
63,
875,
12,
6202,
63,
7650,
29,
797,
12,
6202,
63,
1531,
29,
797,
12,
2511,
7339,
63,
4778,
29,
5814,
63,
4778,
9,
267,
340,
440,
5532,
63,
4211,
315,
1072,
26,
288,
746,
1722,
480,
11421,
3405,
543,
314,
2569,
2552,
3427,
78,
60,
78,
91,
16,
7063,
2490,
1275,
908,
8,
1199,
430,
398,
372,
1072,
2378,
347,
6202,
63,
7650,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
21332,
314,
8520,
6197,
8457,
687,
314,
1072,
1041,
398,
327,
6523,
314,
17035,
6202,
63,
7650,
1083,
267,
282,
63,
875,
275,
1613,
8,
42,
5411,
529,
13716,
12,
291,
680,
1913,
63,
7650,
2031,
589,
12,
1011,
958,
9,
398,
327,
6523,
4722,
1083,
370,
6202,
2005,
1067,
2974,
267,
372,
291,
14,
1913,
63,
1100,
63,
1744,
8,
65,
63,
875,
9,
2378,
768,
4639,
272,
347,
6202,
63,
1100,
63,
1744,
8,
65,
63,
875,
304,
267,
408,
21332,
1603,
5411,
529,
13,
6100,
1072
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
295,
199,
199,
504,
1851,
2664,
7697,
14,
5510,
63,
2105,
492,
3523,
13716,
3225,
199,
199,
533,
1603,
5411,
529,
13716,
8,
1563,
13716,
3225,
304,
272,
408,
26924,
3102,
367,
17232,
316,
543,
1603,
5411,
529,
17138,
7256,
14,
339,
30184,
402,
12027,
3225,
14,
221,
5289,
5921,
658,
4296,
11995,
436,
658,
1074,
63,
4296,
63,
632,
11995,
272,
3102,
14,
221,
31144,
9978,
3102,
367,
1603,
5411,
529,
13,
6100,
7163,
14,
272,
408,
339,
347,
2351,
63,
657,
462,
425,
8,
277,
304,
267,
408,
22281,
314,
2351,
2410,
314,
1950,
965,
2757,
23594,
14,
398,
17534,
299,
7407,
334,
1589,
2850,
6878,
306,
7,
29951,
680,
267,
2494,
314,
1300,
8457,
367,
18752,
661,
30,
1959,
267,
408,
267,
291,
14,
5993,
63,
31691,
8,
1531,
628,
409,
5053,
6426,
13,
1267,
378,
60,
78,
531,
267,
291,
14,
409,
63,
1095,
63,
7650,
342,
2378,
347,
1101,
63,
632,
8,
277,
12,
1101,
63,
1531,
534,
6472,
735,
267,
1449,
267,
16401,
2897,
818,
14,
398,
13813,
370,
1937,
340,
314,
2351,
365,
2575,
315,
2897,
818,
1642,
14,
267,
6218,
658,
3393,
64,
340,
314,
2351,
1990,
17329,
370,
9509,
2897,
267,
818,
14,
267,
1449,
398,
327,
6523,
1676,
1021,
543,
2488,
1414,
367,
9509,
316,
1101,
818,
267,
372,
1613,
8,
42,
5411,
529,
13716,
12,
291,
680,
888,
63,
632,
8,
888,
63,
1531,
29,
888,
63,
1531,
9,
2378,
347,
4458,
63,
888,
63,
632,
8,
277,
12,
4458,
63,
888,
534,
2224,
2897,
13,
632,
735,
267,
408,
6699,
2897,
818,
14,
398,
2670,
340,
781,
3984,
315,
2897,
818,
14,
221,
982,
781,
787,
12,
4458,
2897,
267,
818,
14,
221,
982,
781,
10621,
1133,
12,
886,
6548,
14,
267,
408,
398,
1072,
275,
3087,
267,
340,
291,
14,
1074,
63,
888,
63,
632,
837,
288,
1072,
275,
291,
14,
2254,
63,
1531,
8,
2224,
63,
888,
12,
6202,
63,
7650,
29,
797,
12,
6202,
63,
1531,
29,
797,
9,
288,
340,
283,
6699,
543,
625,
20300,
4493,
14069,
315,
1072,
26,
355,
1072,
847,
291,
14,
2254,
63,
1531,
360,
5066,
297,
6202,
63,
7650,
29,
797,
12,
6202,
63,
1531,
29,
797,
9,
288,
340,
291,
14,
1074,
63,
888,
63,
632,
837,
355,
746,
1722,
480,
4276,
370,
4458,
2897,
818,
531,
398,
372,
1072,
2378,
347,
1104,
63,
888,
63,
632,
8,
277,
12,
1104,
63,
875,
29,
418,
735,
267,
1449,
267,
13813,
340,
314,
2243,
365,
315,
2897,
818,
503,
440,
398,
1803,
282,
5046,
267,
1449,
398,
327,
6523,
1676,
1021,
543,
1603,
5411,
529,
1104,
63,
875,
267,
372,
1613,
8,
42,
5411,
529,
13716,
12,
291,
680,
1074,
63,
888,
63,
632,
8,
1074,
63,
875,
29,
1074,
63,
875,
9,
2378,
347,
5532,
8,
277,
12,
12679,
29,
797,
12,
12679,
63,
5814,
29,
403,
12,
1104,
29,
797,
12,
3721,
4581,
2049,
436,
63,
10589,
29,
797,
12,
7339,
63,
4778,
29,
709,
304,
267,
408,
267,
21447,
314,
7627,
2897,
14,
398,
21447,
314,
19138,
2897,
14,
14771,
376,
1125,
436,
372,
314,
5988,
267,
340,
314,
5532,
6918,
14,
398,
9195,
17174,
655,
878,
2897,
818,
398,
849,
26,
288,
1414,
63,
875,
275,
5532,
267,
1104,
436,
334,
9548,
503,
12679,
63,
271,
590,
503,
3721,
304,
288,
2186,
267,
12679,
63,
5814,
436,
949,
12679,
26,
288,
2186,
267,
12679,
26,
288,
12679,
63,
5814,
945,
288,
3721,
945,
288,
1414,
63,
875,
275,
5532,
22763,
503,
5532,
22763,
665,
9548,
63,
5814,
30,
267,
1104,
26,
288,
1414,
63,
875,
275,
5532,
1104,
398,
408,
398,
340,
1104,
436,
334,
9548,
503,
12679,
63,
5814,
503,
3721,
304,
288,
746,
1722,
480,
3364,
2368,
6841,
543,
5532,
1104,
531,
398,
340,
12679,
63,
5814,
436,
440,
12679,
26,
288,
746,
1722,
480,
3364,
2368,
6841,
370,
5532,
1083,
3865,
12679,
436,
1104,
531,
398,
327,
9496,
5576,
1414,
1059,
4079,
641,
2368,
2741,
267,
1414,
63,
875,
275,
283,
3543,
7,
267,
5532,
63,
4211,
275,
283,
3543,
4890,
7,
267,
340,
1104,
26,
288,
1414,
63,
875,
275,
283,
3543,
1104,
7,
288,
5532,
63,
4211,
275,
283,
4758,
1104,
24611,
7,
267,
916,
12679,
26,
288,
340,
12679,
63,
5814,
26,
355,
1414,
63,
875,
275,
283,
3543,
22763,
283,
435,
620,
8,
9548,
63,
5814,
9,
288,
587,
26,
355,
1414,
63,
875,
275,
283,
3543,
22763,
7,
288,
5532,
63,
4211,
275,
283,
3543,
22763,
911,
506,
5847,
20182,
1146,
1771,
315,
7,
398,
327,
4816,
314,
3721,
315,
9344,
267,
340,
3721,
26,
288,
340,
14788,
315,
3721,
26,
355,
746,
1722,
480,
3364,
3721,
3509,
4270,
6313,
531,
288,
3721,
275,
5522,
91,
16,
7063,
1370,
908,
8,
3349,
9,
953,
1414,
63,
875,
847,
283,
3721,
283,
435,
3721,
398,
340,
436,
63,
10589,
26,
288,
1414,
63,
875,
847,
283,
436,
13,
10589,
7,
398,
327,
16401,
1101,
818,
334,
692,
5784,
9,
267,
1072,
275,
291,
14,
888,
63,
632,
342,
267,
1072,
847,
291,
14,
2254,
63,
1531,
8,
1531,
63,
875,
12,
6202,
63,
7650,
29,
797,
12,
6202,
63,
1531,
29,
797,
12,
2511,
7339,
63,
4778,
29,
5814,
63,
4778,
9,
267,
340,
440,
5532,
63,
4211,
315,
1072,
26,
288,
746,
1722,
480,
11421,
3405,
543,
314,
2569,
2552,
3427,
78,
60,
78,
91,
16,
7063,
2490,
1275,
908,
8,
1199,
430,
398,
372,
1072,
2378,
347,
6202,
63,
7650,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
21332,
314,
8520,
6197,
8457,
687,
314,
1072,
1041,
398,
327,
6523,
314,
17035,
6202,
63,
7650,
1083,
267,
282,
63,
875,
275,
1613,
8,
42,
5411,
529,
13716,
12,
291,
680,
1913,
63,
7650,
2031,
589,
12,
1011,
958,
9,
398,
327,
6523,
4722,
1083,
370,
6202,
2005,
1067,
2974,
267,
372,
291,
14,
1913,
63,
1100,
63,
1744,
8,
65,
63,
875,
9,
2378,
768,
4639,
272,
347,
6202,
63,
1100,
63,
1744,
8,
65,
63,
875,
304,
267,
408,
21332,
1603,
5411,
529,
13,
6100,
1072,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
richpolis/siveinpy
|
env/lib/python2.7/site-packages/django/contrib/sessions/backends/cache.py
|
122
|
2505
|
from django.conf import settings
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.core.cache import get_cache
from django.utils.six.moves import xrange
KEY_PREFIX = "django.contrib.sessions.cache"
class SessionStore(SessionBase):
"""
A cache-based session store.
"""
def __init__(self, session_key=None):
self._cache = get_cache(settings.SESSION_CACHE_ALIAS)
super(SessionStore, self).__init__(session_key)
@property
def cache_key(self):
return KEY_PREFIX + self._get_or_create_session_key()
def load(self):
try:
session_data = self._cache.get(self.cache_key, None)
except Exception:
# Some backends (e.g. memcache) raise an exception on invalid
# cache keys. If this happens, reset the session. See #17810.
session_data = None
if session_data is not None:
return session_data
self.create()
return {}
def create(self):
# Because a cache can fail silently (e.g. memcache), we don't know if
# we are failing to create a new session because of a key collision or
# because the cache is missing. So we try for a (large) number of times
# and then raise an exception. That's the risk you shoulder if using
# cache backing.
for i in xrange(10000):
self._session_key = self._get_new_session_key()
try:
self.save(must_create=True)
except CreateError:
continue
self.modified = True
return
raise RuntimeError(
"Unable to create a new session key. "
"It is likely that the cache is unavailable.")
def save(self, must_create=False):
if must_create:
func = self._cache.add
else:
func = self._cache.set
result = func(self.cache_key,
self._get_session(no_load=must_create),
self.get_expiry_age())
if must_create and not result:
raise CreateError
def exists(self, session_key):
return (KEY_PREFIX + session_key) in self._cache
def delete(self, session_key=None):
if session_key is None:
if self.session_key is None:
return
session_key = self.session_key
self._cache.delete(KEY_PREFIX + session_key)
@classmethod
def clear_expired(cls):
pass
|
mit
|
[
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
11676,
14,
7765,
14,
1095,
492,
8596,
1563,
12,
2790,
547,
199,
504,
1639,
14,
1018,
14,
1637,
492,
664,
63,
1637,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
492,
4945,
199,
199,
3078,
63,
6351,
275,
298,
1176,
14,
2828,
14,
11676,
14,
1637,
2,
421,
199,
533,
8596,
5502,
8,
4434,
1563,
304,
272,
408,
272,
437,
2581,
13,
6788,
2351,
3877,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2351,
63,
498,
29,
403,
304,
267,
291,
423,
1637,
275,
664,
63,
1637,
8,
1751,
14,
12763,
63,
8677,
63,
12644,
9,
267,
1613,
8,
4434,
5502,
12,
291,
2843,
826,
721,
1730,
63,
498,
9,
339,
768,
1829,
272,
347,
2581,
63,
498,
8,
277,
304,
267,
372,
9301,
63,
6351,
435,
291,
423,
362,
63,
269,
63,
981,
63,
1730,
63,
498,
342,
339,
347,
2248,
8,
277,
304,
267,
862,
26,
288,
2351,
63,
576,
275,
291,
423,
1637,
14,
362,
8,
277,
14,
1637,
63,
498,
12,
488,
9,
267,
871,
2186,
26,
288,
327,
6601,
14745,
334,
69,
14,
71,
14,
21598,
9,
746,
376,
1919,
641,
3866,
288,
327,
2581,
2883,
14,
982,
642,
10986,
12,
5305,
314,
2351,
14,
1666,
327,
11175,
709,
14,
288,
2351,
63,
576,
275,
488,
267,
340,
2351,
63,
576,
365,
440,
488,
26,
288,
372,
2351,
63,
576,
267,
291,
14,
981,
342,
267,
372,
1052,
339,
347,
1218,
8,
277,
304,
267,
327,
13821,
282,
2581,
883,
2449,
18030,
334,
69,
14,
71,
14,
21598,
395,
781,
2793,
1133,
5715,
340,
267,
327,
781,
787,
18648,
370,
1218,
282,
892,
2351,
2952,
402,
282,
790,
25061,
503,
267,
327,
2952,
314,
2581,
365,
4124,
14,
2002,
781,
862,
367,
282,
334,
9629,
9,
1329,
402,
5431,
267,
327,
436,
2066,
746,
376,
1919,
14,
10314,
1159,
314,
22633,
1265,
930,
348,
424,
340,
1808,
267,
327,
2581,
21094,
14,
267,
367,
284,
315,
4945,
8,
9943,
304,
288,
291,
423,
1730,
63,
498,
275,
291,
423,
362,
63,
1222,
63,
1730,
63,
498,
342,
288,
862,
26,
355,
291,
14,
2117,
8,
7790,
63,
981,
29,
549,
9,
288,
871,
2790,
547,
26,
355,
1980,
288,
291,
14,
5540,
275,
715,
288,
372,
267,
746,
6064,
8,
288,
298,
6005,
370,
1218,
282,
892,
2351,
790,
14,
298,
288,
298,
7940,
365,
12060,
626,
314,
2581,
365,
18735,
2685,
339,
347,
3354,
8,
277,
12,
1471,
63,
981,
29,
797,
304,
267,
340,
1471,
63,
981,
26,
288,
2562,
275,
291,
423,
1637,
14,
525,
267,
587,
26,
288,
2562,
275,
291,
423,
1637,
14,
409,
267,
754,
275,
2562,
8,
277,
14,
1637,
63,
498,
12,
1993,
291,
423,
362,
63,
1730,
8,
889,
63,
912,
29,
7790,
63,
981,
395,
1993,
291,
14,
362,
63,
16844,
63,
474,
1012,
267,
340,
1471,
63,
981,
436,
440,
754,
26,
288,
746,
2790,
547,
339,
347,
3495,
8,
277,
12,
2351,
63,
498,
304,
267,
372,
334,
3078,
63,
6351,
435,
2351,
63,
498,
9,
315,
291,
423,
1637,
339,
347,
3145,
8,
277,
12,
2351,
63,
498,
29,
403,
304,
267,
340,
2351,
63,
498,
365,
488,
26,
288,
340,
291,
14,
1730,
63,
498,
365,
488,
26,
355,
372,
288,
2351,
63,
498,
275,
291,
14,
1730,
63,
498,
267,
291,
423,
1637,
14,
1807,
8,
3078,
63,
6351,
435,
2351,
63,
498,
9,
339,
768,
3744,
272,
347,
5436,
63,
16340,
8,
1886,
304,
267,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
11676,
14,
7765,
14,
1095,
492,
8596,
1563,
12,
2790,
547,
199,
504,
1639,
14,
1018,
14,
1637,
492,
664,
63,
1637,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
492,
4945,
199,
199,
3078,
63,
6351,
275,
298,
1176,
14,
2828,
14,
11676,
14,
1637,
2,
421,
199,
533,
8596,
5502,
8,
4434,
1563,
304,
272,
408,
272,
437,
2581,
13,
6788,
2351,
3877,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2351,
63,
498,
29,
403,
304,
267,
291,
423,
1637,
275,
664,
63,
1637,
8,
1751,
14,
12763,
63,
8677,
63,
12644,
9,
267,
1613,
8,
4434,
5502,
12,
291,
2843,
826,
721,
1730,
63,
498,
9,
339,
768,
1829,
272,
347,
2581,
63,
498,
8,
277,
304,
267,
372,
9301,
63,
6351,
435,
291,
423,
362,
63,
269,
63,
981,
63,
1730,
63,
498,
342,
339,
347,
2248,
8,
277,
304,
267,
862,
26,
288,
2351,
63,
576,
275,
291,
423,
1637,
14,
362,
8,
277,
14,
1637,
63,
498,
12,
488,
9,
267,
871,
2186,
26,
288,
327,
6601,
14745,
334,
69,
14,
71,
14,
21598,
9,
746,
376,
1919,
641,
3866,
288,
327,
2581,
2883,
14,
982,
642,
10986,
12,
5305,
314,
2351,
14,
1666,
327,
11175,
709,
14,
288,
2351,
63,
576,
275,
488,
267,
340,
2351,
63,
576,
365,
440,
488,
26,
288,
372,
2351,
63,
576,
267,
291,
14,
981,
342,
267,
372,
1052,
339,
347,
1218,
8,
277,
304,
267,
327,
13821,
282,
2581,
883,
2449,
18030,
334,
69,
14,
71,
14,
21598,
395,
781,
2793,
1133,
5715,
340,
267,
327,
781,
787,
18648,
370,
1218,
282,
892,
2351,
2952,
402,
282,
790,
25061,
503,
267,
327,
2952,
314,
2581,
365,
4124,
14,
2002,
781,
862,
367,
282,
334,
9629,
9,
1329,
402,
5431,
267,
327,
436,
2066,
746,
376,
1919,
14,
10314,
1159,
314,
22633,
1265,
930,
348,
424,
340,
1808,
267,
327,
2581,
21094,
14,
267,
367,
284,
315,
4945,
8,
9943,
304,
288,
291,
423,
1730,
63,
498,
275,
291,
423,
362,
63,
1222,
63,
1730,
63,
498,
342,
288,
862,
26,
355,
291,
14,
2117,
8,
7790,
63,
981,
29,
549,
9,
288,
871,
2790,
547,
26,
355,
1980,
288,
291,
14,
5540,
275,
715,
288,
372,
267,
746,
6064,
8,
288,
298,
6005,
370,
1218,
282,
892,
2351,
790,
14,
298,
288,
298,
7940,
365,
12060,
626,
314,
2581,
365,
18735,
2685,
339,
347,
3354,
8,
277,
12,
1471,
63,
981,
29,
797,
304,
267,
340,
1471,
63,
981,
26,
288,
2562,
275,
291,
423,
1637,
14,
525,
267,
587,
26,
288,
2562,
275,
291,
423,
1637,
14,
409,
267,
754,
275,
2562,
8,
277,
14,
1637,
63,
498,
12,
1993,
291,
423,
362,
63,
1730,
8,
889,
63,
912,
29,
7790,
63,
981,
395,
1993,
291,
14,
362,
63,
16844,
63,
474,
1012,
267,
340,
1471,
63,
981,
436,
440,
754,
26,
288,
746,
2790,
547,
339,
347,
3495,
8,
277,
12,
2351,
63,
498,
304,
267,
372,
334,
3078,
63,
6351,
435,
2351,
63,
498,
9,
315,
291,
423,
1637,
339,
347,
3145,
8,
277,
12,
2351,
63,
498,
29,
403,
304,
267,
340,
2351,
63,
498,
365,
488,
26,
288,
340,
291,
14,
1730,
63,
498,
365,
488,
26,
355,
372,
288,
2351,
63,
498,
275,
291,
14,
1730,
63,
498,
267,
291,
423,
1637,
14,
1807,
8,
3078,
63,
6351,
435,
2351,
63,
498,
9,
339,
768,
3744,
272,
347,
5436,
63,
16340,
8,
1886,
304,
267,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wonder-sk/QGIS
|
python/plugins/processing/algs/qgis/SetRasterStyle.py
|
3
|
2764
|
# -*- coding: utf-8 -*-
"""
***************************************************************************
SelectByLocation.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import os
from qgis.PyQt.QtXml import QDomDocument
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterFile
from processing.core.parameters import ParameterRaster
from processing.core.outputs import OutputRaster
from processing.tools import dataobjects
from qgis.utils import iface
class SetRasterStyle(GeoAlgorithm):
INPUT = 'INPUT'
STYLE = 'STYLE'
OUTPUT = 'OUTPUT'
def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Set style for raster layer')
self.group, self.i18n_group = self.trAlgorithm('Raster general tools')
self.addParameter(ParameterRaster(self.INPUT,
self.tr('Raster layer')))
self.addParameter(ParameterFile(self.STYLE,
self.tr('Style file'), False, False, 'qml'))
self.addOutput(OutputRaster(self.OUTPUT, self.tr('Styled'), True))
def processAlgorithm(self, progress):
filename = self.getParameterValue(self.INPUT)
layer = dataobjects.getObjectFromUri(filename)
style = self.getParameterValue(self.STYLE)
if layer is None:
dataobjects.load(filename, os.path.basename(filename), style=style)
self.getOutputFromName(self.OUTPUT).open = False
else:
with open(style) as f:
xml = "".join(f.readlines())
d = QDomDocument()
d.setContent(xml)
n = d.firstChild()
layer.readSymbology(n, '')
self.setOutputValue(self.OUTPUT, filename)
iface.mapCanvas().refresh()
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
9496,
2175,
6592,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
25298,
833,
6029,
272,
1898,
3322,
520,
334,
35,
9,
6029,
701,
6561,
630,
593,
817,
65,
272,
11426,
4483,
520,
5236,
1187,
2756,
737,
29712,
6308,
2414,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
2201,
630,
593,
817,
65,
7,
199,
363,
602,
363,
275,
283,
21640,
833,
6029,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
6029,
12,
6561,
630,
593,
817,
65,
7,
199,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
199,
646,
747,
199,
199,
504,
15640,
14,
24107,
14,
4238,
8672,
492,
1413,
20106,
5564,
199,
199,
504,
6661,
14,
1018,
14,
10748,
11570,
492,
8875,
11570,
199,
504,
6661,
14,
1018,
14,
3214,
492,
12009,
1173,
199,
504,
6661,
14,
1018,
14,
3214,
492,
12009,
13284,
199,
504,
6661,
14,
1018,
14,
4467,
492,
7242,
13284,
199,
504,
6661,
14,
2537,
492,
666,
1462,
199,
504,
15640,
14,
1208,
492,
13395,
421,
199,
533,
2494,
13284,
6609,
8,
10748,
11570,
304,
339,
21955,
275,
283,
7321,
7,
272,
428,
2099,
906,
275,
283,
18466,
7,
272,
18746,
275,
283,
8414,
7,
339,
347,
5627,
1610,
29867,
8,
277,
304,
267,
291,
14,
354,
12,
291,
14,
73,
1085,
78,
63,
354,
275,
291,
14,
454,
11570,
360,
1084,
3449,
367,
19775,
4045,
358,
267,
291,
14,
923,
12,
291,
14,
73,
1085,
78,
63,
923,
275,
291,
14,
454,
11570,
360,
13284,
8605,
7249,
358,
267,
291,
14,
26895,
8,
4720,
13284,
8,
277,
14,
7321,
12,
5101,
291,
14,
454,
360,
13284,
4045,
7058,
267,
291,
14,
26895,
8,
4720,
1173,
8,
277,
14,
18466,
12,
3147,
291,
14,
454,
360,
6609,
570,
659,
756,
12,
756,
12,
283,
81,
757,
1333,
267,
291,
14,
525,
2959,
8,
2959,
13284,
8,
277,
14,
8414,
12,
291,
14,
454,
360,
25033,
1146,
659,
715,
430,
339,
347,
2112,
11570,
8,
277,
12,
6696,
304,
267,
1788,
275,
291,
14,
362,
24637,
8,
277,
14,
7321,
9,
267,
4045,
275,
666,
1462,
14,
362,
1692,
2532,
14014,
8,
1501,
9,
398,
3449,
275,
291,
14,
362,
24637,
8,
277,
14,
18466,
9,
267,
340,
4045,
365,
488,
26,
288,
666,
1462,
14,
912,
8,
1501,
12,
747,
14,
515,
14,
4846,
8,
1501,
395,
3449,
29,
2487,
9,
288,
291,
14,
362,
2959,
2532,
985,
8,
277,
14,
8414,
680,
1490,
275,
756,
267,
587,
26,
288,
543,
1551,
8,
2487,
9,
465,
289,
26,
355,
2748,
275,
10587,
904,
8,
70,
14,
9684,
1012,
288,
366,
275,
1413,
20106,
5564,
342,
288,
366,
14,
28680,
8,
1652,
9,
288,
302,
275,
366,
14,
22262,
342,
288,
4045,
14,
739,
16594,
656,
4956,
8,
78,
12,
4074,
288,
291,
14,
409,
2959,
1110,
8,
277,
14,
8414,
12,
1788,
9,
288,
13395,
14,
1130,
15174,
1252,
6635,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
9496,
2175,
6592,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
25298,
833,
6029,
272,
1898,
3322,
520,
334,
35,
9,
6029,
701,
6561,
630,
593,
817,
65,
272,
11426,
4483,
520,
5236,
1187,
2756,
737,
29712,
6308,
2414,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
2201,
630,
593,
817,
65,
7,
199,
363,
602,
363,
275,
283,
21640,
833,
6029,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
6029,
12,
6561,
630,
593,
817,
65,
7,
199,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
199,
646,
747,
199,
199,
504,
15640,
14,
24107,
14,
4238,
8672,
492,
1413,
20106,
5564,
199,
199,
504,
6661,
14,
1018,
14,
10748,
11570,
492,
8875,
11570,
199,
504,
6661,
14,
1018,
14,
3214,
492,
12009,
1173,
199,
504,
6661,
14,
1018,
14,
3214,
492,
12009,
13284,
199,
504,
6661,
14,
1018,
14,
4467,
492,
7242,
13284,
199,
504,
6661,
14,
2537,
492,
666,
1462,
199,
504,
15640,
14,
1208,
492,
13395,
421,
199,
533,
2494,
13284,
6609,
8,
10748,
11570,
304,
339,
21955,
275,
283,
7321,
7,
272,
428,
2099,
906,
275,
283,
18466,
7,
272,
18746,
275,
283,
8414,
7,
339,
347,
5627,
1610,
29867,
8,
277,
304,
267,
291,
14,
354,
12,
291,
14,
73,
1085,
78,
63,
354,
275,
291,
14,
454,
11570,
360,
1084,
3449,
367,
19775,
4045,
358,
267,
291,
14,
923,
12,
291,
14,
73,
1085,
78,
63,
923,
275,
291,
14,
454,
11570,
360,
13284,
8605,
7249,
358,
267,
291,
14,
26895,
8,
4720,
13284,
8,
277,
14,
7321,
12,
5101,
291,
14,
454,
360,
13284,
4045,
7058,
267,
291,
14,
26895,
8,
4720,
1173,
8,
277,
14,
18466,
12,
3147,
291,
14,
454,
360,
6609,
570,
659,
756,
12,
756,
12,
283,
81,
757,
1333,
267,
291,
14,
525,
2959,
8,
2959,
13284,
8,
277,
14,
8414,
12,
291,
14,
454,
360,
25033,
1146,
659,
715,
430,
339,
347,
2112,
11570,
8,
277,
12,
6696,
304,
267,
1788,
275,
291,
14,
362,
24637,
8,
277,
14,
7321,
9,
267,
4045,
275,
666,
1462,
14,
362,
1692,
2532,
14014,
8,
1501,
9,
398,
3449,
275,
291,
14,
362,
24637,
8,
277,
14,
18466,
9,
267,
340,
4045,
365,
488,
26,
288,
666,
1462,
14,
912,
8,
1501,
12,
747,
14,
515,
14,
4846,
8,
1501,
395,
3449,
29,
2487,
9,
288,
291,
14,
362,
2959,
2532,
985,
8,
277,
14,
8414,
680,
1490,
275,
756,
267,
587,
26,
288,
543,
1551,
8,
2487,
9,
465,
289,
26,
355,
2748,
275,
10587,
904,
8,
70,
14,
9684,
1012,
288,
366,
275,
1413,
20106,
5564,
342,
288,
366,
14,
28680,
8,
1652,
9,
288,
302,
275,
366,
14,
22262,
342,
288,
4045,
14,
739,
16594,
656,
4956,
8,
78,
12,
4074,
288,
291,
14,
409,
2959,
1110,
8,
277,
14,
8414,
12,
1788,
9,
288,
13395,
14,
1130,
15174,
1252,
6635,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mattcontinisio/cereal-yaml
|
yaml-cpp/test/gtest-1.8.0/googletest/test/gtest_catch_exceptions_test.py
|
2139
|
9901
|
#!/usr/bin/env python
#
# Copyright 2010 Google Inc. All Rights Reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Tests Google Test's exception catching behavior.
This script invokes gtest_catch_exceptions_test_ and
gtest_catch_exceptions_ex_test_ (programs written with
Google Test) and verifies their output.
"""
__author__ = 'vladl@google.com (Vlad Losev)'
import os
import gtest_test_utils
# Constants.
FLAG_PREFIX = '--gtest_'
LIST_TESTS_FLAG = FLAG_PREFIX + 'list_tests'
NO_CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX + 'catch_exceptions=0'
FILTER_FLAG = FLAG_PREFIX + 'filter'
# Path to the gtest_catch_exceptions_ex_test_ binary, compiled with
# exceptions enabled.
EX_EXE_PATH = gtest_test_utils.GetTestExecutablePath(
'gtest_catch_exceptions_ex_test_')
# Path to the gtest_catch_exceptions_test_ binary, compiled with
# exceptions disabled.
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
'gtest_catch_exceptions_no_ex_test_')
environ = gtest_test_utils.environ
SetEnvVar = gtest_test_utils.SetEnvVar
# Tests in this file run a Google-Test-based test program and expect it
# to terminate prematurely. Therefore they are incompatible with
# the premature-exit-file protocol by design. Unset the
# premature-exit filepath to prevent Google Test from creating
# the file.
SetEnvVar(gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR, None)
TEST_LIST = gtest_test_utils.Subprocess(
[EXE_PATH, LIST_TESTS_FLAG], env=environ).output
SUPPORTS_SEH_EXCEPTIONS = 'ThrowsSehException' in TEST_LIST
if SUPPORTS_SEH_EXCEPTIONS:
BINARY_OUTPUT = gtest_test_utils.Subprocess([EXE_PATH], env=environ).output
EX_BINARY_OUTPUT = gtest_test_utils.Subprocess(
[EX_EXE_PATH], env=environ).output
# The tests.
if SUPPORTS_SEH_EXCEPTIONS:
# pylint:disable-msg=C6302
class CatchSehExceptionsTest(gtest_test_utils.TestCase):
"""Tests exception-catching behavior."""
def TestSehExceptions(self, test_output):
self.assert_('SEH exception with code 0x2a thrown '
'in the test fixture\'s constructor'
in test_output)
self.assert_('SEH exception with code 0x2a thrown '
'in the test fixture\'s destructor'
in test_output)
self.assert_('SEH exception with code 0x2a thrown in SetUpTestCase()'
in test_output)
self.assert_('SEH exception with code 0x2a thrown in TearDownTestCase()'
in test_output)
self.assert_('SEH exception with code 0x2a thrown in SetUp()'
in test_output)
self.assert_('SEH exception with code 0x2a thrown in TearDown()'
in test_output)
self.assert_('SEH exception with code 0x2a thrown in the test body'
in test_output)
def testCatchesSehExceptionsWithCxxExceptionsEnabled(self):
self.TestSehExceptions(EX_BINARY_OUTPUT)
def testCatchesSehExceptionsWithCxxExceptionsDisabled(self):
self.TestSehExceptions(BINARY_OUTPUT)
class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
"""Tests C++ exception-catching behavior.
Tests in this test case verify that:
* C++ exceptions are caught and logged as C++ (not SEH) exceptions
* Exception thrown affect the remainder of the test work flow in the
expected manner.
"""
def testCatchesCxxExceptionsInFixtureConstructor(self):
self.assert_('C++ exception with description '
'"Standard C++ exception" thrown '
'in the test fixture\'s constructor'
in EX_BINARY_OUTPUT)
self.assert_('unexpected' not in EX_BINARY_OUTPUT,
'This failure belongs in this test only if '
'"CxxExceptionInConstructorTest" (no quotes) '
'appears on the same line as words "called unexpectedly"')
if ('CxxExceptionInDestructorTest.ThrowsExceptionInDestructor' in
EX_BINARY_OUTPUT):
def testCatchesCxxExceptionsInFixtureDestructor(self):
self.assert_('C++ exception with description '
'"Standard C++ exception" thrown '
'in the test fixture\'s destructor'
in EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInDestructorTest::TearDownTestCase() '
'called as expected.'
in EX_BINARY_OUTPUT)
def testCatchesCxxExceptionsInSetUpTestCase(self):
self.assert_('C++ exception with description "Standard C++ exception"'
' thrown in SetUpTestCase()'
in EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInConstructorTest::TearDownTestCase() '
'called as expected.'
in EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInSetUpTestCaseTest constructor '
'called as expected.'
in EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInSetUpTestCaseTest destructor '
'called as expected.'
in EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInSetUpTestCaseTest::SetUp() '
'called as expected.'
in EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInSetUpTestCaseTest::TearDown() '
'called as expected.'
in EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInSetUpTestCaseTest test body '
'called as expected.'
in EX_BINARY_OUTPUT)
def testCatchesCxxExceptionsInTearDownTestCase(self):
self.assert_('C++ exception with description "Standard C++ exception"'
' thrown in TearDownTestCase()'
in EX_BINARY_OUTPUT)
def testCatchesCxxExceptionsInSetUp(self):
self.assert_('C++ exception with description "Standard C++ exception"'
' thrown in SetUp()'
in EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInSetUpTest::TearDownTestCase() '
'called as expected.'
in EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInSetUpTest destructor '
'called as expected.'
in EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInSetUpTest::TearDown() '
'called as expected.'
in EX_BINARY_OUTPUT)
self.assert_('unexpected' not in EX_BINARY_OUTPUT,
'This failure belongs in this test only if '
'"CxxExceptionInSetUpTest" (no quotes) '
'appears on the same line as words "called unexpectedly"')
def testCatchesCxxExceptionsInTearDown(self):
self.assert_('C++ exception with description "Standard C++ exception"'
' thrown in TearDown()'
in EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInTearDownTest::TearDownTestCase() '
'called as expected.'
in EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInTearDownTest destructor '
'called as expected.'
in EX_BINARY_OUTPUT)
def testCatchesCxxExceptionsInTestBody(self):
self.assert_('C++ exception with description "Standard C++ exception"'
' thrown in the test body'
in EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInTestBodyTest::TearDownTestCase() '
'called as expected.'
in EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInTestBodyTest destructor '
'called as expected.'
in EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInTestBodyTest::TearDown() '
'called as expected.'
in EX_BINARY_OUTPUT)
def testCatchesNonStdCxxExceptions(self):
self.assert_('Unknown C++ exception thrown in the test body'
in EX_BINARY_OUTPUT)
def testUnhandledCxxExceptionsAbortTheProgram(self):
# Filters out SEH exception tests on Windows. Unhandled SEH exceptions
# cause tests to show pop-up windows there.
FITLER_OUT_SEH_TESTS_FLAG = FILTER_FLAG + '=-*Seh*'
# By default, Google Test doesn't catch the exceptions.
uncaught_exceptions_ex_binary_output = gtest_test_utils.Subprocess(
[EX_EXE_PATH,
NO_CATCH_EXCEPTIONS_FLAG,
FITLER_OUT_SEH_TESTS_FLAG],
env=environ).output
self.assert_('Unhandled C++ exception terminating the program'
in uncaught_exceptions_ex_binary_output)
self.assert_('unexpected' not in uncaught_exceptions_ex_binary_output)
if __name__ == '__main__':
gtest_test_utils.Main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
7129,
4475,
3277,
14,
221,
2900,
5924,
5702,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
2925,
4475,
1379,
1159,
1919,
8579,
316,
5953,
14,
199,
199,
2765,
2884,
29761,
9088,
63,
9341,
63,
3924,
63,
396,
63,
436,
199,
8385,
63,
9341,
63,
3924,
63,
476,
63,
396,
63,
334,
28464,
5313,
543,
199,
13266,
1379,
9,
436,
22694,
3932,
1072,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
7300,
350,
76,
32,
3098,
14,
957,
334,
54,
76,
350,
491,
3362,
86,
3171,
199,
199,
646,
747,
199,
199,
646,
9088,
63,
396,
63,
1208,
199,
199,
3,
22296,
14,
199,
3719,
63,
6351,
275,
2850,
8385,
8650,
199,
4924,
63,
7569,
63,
3719,
275,
11031,
63,
6351,
435,
283,
513,
63,
2219,
7,
199,
2826,
63,
35,
8078,
63,
25054,
63,
3719,
275,
11031,
63,
6351,
435,
283,
9341,
63,
3924,
29,
16,
7,
199,
9905,
63,
3719,
275,
11031,
63,
6351,
435,
283,
1541,
7,
199,
199,
3,
6912,
370,
314,
9088,
63,
9341,
63,
3924,
63,
476,
63,
396,
63,
3366,
12,
10311,
543,
199,
3,
4967,
5223,
14,
199,
1438,
63,
23017,
63,
3243,
275,
9088,
63,
396,
63,
1208,
14,
28967,
27602,
8,
272,
283,
8385,
63,
9341,
63,
3924,
63,
476,
63,
396,
15452,
199,
199,
3,
6912,
370,
314,
9088,
63,
9341,
63,
3924,
63,
396,
63,
3366,
12,
10311,
543,
199,
3,
4967,
6980,
14,
199,
23017,
63,
3243,
275,
9088,
63,
396,
63,
1208,
14,
28967,
27602,
8,
272,
283,
8385,
63,
9341,
63,
3924,
63,
889,
63,
476,
63,
396,
15452,
199,
199,
2314,
275,
9088,
63,
396,
63,
1208,
14,
2314,
199,
1084,
19342,
275,
9088,
63,
396,
63,
1208,
14,
1084,
19342,
199,
199,
3,
6496,
315,
642,
570,
1255,
282,
4475,
13,
774,
13,
6788,
511,
2240,
436,
4282,
652,
199,
3,
370,
15095,
876,
19925,
590,
14,
221,
21039,
2985,
787,
18457,
543,
199,
3,
314,
876,
19925,
13,
2224,
13,
493,
4113,
701,
12899,
14,
221,
1910,
409,
314,
199,
3,
876,
19925,
13,
2224,
9911,
370,
7981,
4475,
1379,
687,
6425,
199,
3,
314,
570,
14,
199,
1084,
19342,
8,
8385,
63,
396,
63,
1208,
14,
4225,
45,
13214,
63,
17219,
63,
3817,
63,
9984,
63,
5568,
12,
488,
9,
199,
199,
2864,
63,
4924,
275,
9088,
63,
396,
63,
1208,
14,
22299,
8,
272,
359,
23017,
63,
3243,
12,
21716,
63,
7569,
63,
3719,
467,
2589,
29,
2314,
680,
1199,
199,
199,
10640,
51,
63,
899,
40,
63,
25054,
275,
283,
2719,
3838,
1513,
72,
1726,
7,
315,
7393,
63,
4924,
199,
199,
692,
13756,
51,
63,
899,
40,
63,
25054,
26,
523,
32698,
63,
8414,
275,
9088,
63,
396,
63,
1208,
14,
22299,
779,
23017,
63,
3243,
467,
2589,
29,
2314,
680,
1199,
199,
199,
1438,
63,
13246,
63,
8414,
275,
9088,
63,
396,
63,
1208,
14,
22299,
8,
272,
359,
1438,
63,
23017,
63,
3243,
467,
2589,
29,
2314,
680,
1199,
421,
199,
3,
710,
2295,
14,
199,
692,
13756,
51,
63,
899,
40,
63,
25054,
26,
523,
327,
4287,
26,
5993,
13,
1328,
29,
35,
2766,
996,
523,
1021,
32754,
1513,
72,
16836,
774,
8,
8385,
63,
396,
63,
1208,
14,
1746,
304,
272,
408,
2925,
1919,
13,
9341,
316,
5953,
1041,
2378,
347,
1379,
1513,
72,
16836,
8,
277,
12,
511,
63,
1199,
304,
489,
291,
14,
479,
11252,
899,
40,
1919,
543,
1233,
378,
88,
18,
65,
14031,
283,
673,
283,
262,
314,
511,
10949,
3985,
83,
3787,
7,
673,
315,
511,
63,
1199,
9,
489,
291,
14,
479,
11252,
899,
40,
1919,
543,
1233,
378,
88,
18,
65,
14031,
283,
673,
283,
262,
314,
511,
10949,
3985,
83,
32133,
7,
673,
315,
511,
63,
1199,
9,
489,
291,
14,
479,
11252,
899,
40,
1919,
543,
1233,
378,
88,
18,
65,
14031,
315,
2494,
1721,
1746,
11716,
673,
315,
511,
63,
1199,
9,
489,
291,
14,
479,
11252,
899,
40,
1919,
543,
1233,
378,
88,
18,
65,
14031,
315,
377,
25236,
1746,
11716,
673,
315,
511,
63,
1199,
9,
489,
291,
14,
479,
11252,
899,
40,
1919,
543,
1233,
378,
88,
18,
65,
14031,
315,
2494,
1721,
11716,
673,
315,
511,
63,
1199,
9,
489,
291,
14,
479,
11252,
899,
40,
1919,
543
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
7129,
4475,
3277,
14,
221,
2900,
5924,
5702,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
2925,
4475,
1379,
1159,
1919,
8579,
316,
5953,
14,
199,
199,
2765,
2884,
29761,
9088,
63,
9341,
63,
3924,
63,
396,
63,
436,
199,
8385,
63,
9341,
63,
3924,
63,
476,
63,
396,
63,
334,
28464,
5313,
543,
199,
13266,
1379,
9,
436,
22694,
3932,
1072,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
7300,
350,
76,
32,
3098,
14,
957,
334,
54,
76,
350,
491,
3362,
86,
3171,
199,
199,
646,
747,
199,
199,
646,
9088,
63,
396,
63,
1208,
199,
199,
3,
22296,
14,
199,
3719,
63,
6351,
275,
2850,
8385,
8650,
199,
4924,
63,
7569,
63,
3719,
275,
11031,
63,
6351,
435,
283,
513,
63,
2219,
7,
199,
2826,
63,
35,
8078,
63,
25054,
63,
3719,
275,
11031,
63,
6351,
435,
283,
9341,
63,
3924,
29,
16,
7,
199,
9905,
63,
3719,
275,
11031,
63,
6351,
435,
283,
1541,
7,
199,
199,
3,
6912,
370,
314,
9088,
63,
9341,
63,
3924,
63,
476,
63,
396,
63,
3366,
12,
10311,
543,
199,
3,
4967,
5223,
14,
199,
1438,
63,
23017,
63,
3243,
275,
9088,
63,
396,
63,
1208,
14,
28967,
27602,
8,
272,
283,
8385,
63,
9341,
63,
3924,
63,
476,
63,
396,
15452,
199,
199,
3,
6912,
370,
314,
9088,
63,
9341,
63,
3924,
63,
396,
63,
3366,
12,
10311,
543,
199,
3,
4967,
6980,
14,
199,
23017,
63,
3243,
275,
9088,
63,
396,
63,
1208,
14,
28967,
27602,
8,
272,
283,
8385,
63,
9341,
63,
3924,
63,
889,
63,
476,
63,
396,
15452,
199,
199,
2314,
275,
9088,
63,
396,
63,
1208,
14,
2314,
199,
1084,
19342,
275,
9088,
63,
396,
63,
1208,
14,
1084,
19342,
199,
199,
3,
6496,
315,
642,
570,
1255,
282,
4475,
13,
774,
13,
6788,
511,
2240,
436,
4282,
652,
199,
3,
370,
15095,
876,
19925,
590,
14,
221,
21039,
2985,
787,
18457,
543,
199,
3,
314,
876,
19925,
13,
2224,
13,
493,
4113,
701,
12899,
14,
221,
1910,
409,
314,
199,
3,
876,
19925,
13,
2224,
9911,
370,
7981,
4475,
1379,
687,
6425,
199,
3,
314,
570,
14,
199,
1084,
19342,
8,
8385,
63,
396,
63,
1208,
14,
4225,
45,
13214,
63,
17219,
63,
3817,
63,
9984,
63,
5568,
12,
488,
9,
199,
199,
2864,
63,
4924,
275,
9088,
63,
396,
63,
1208,
14,
22299,
8,
272,
359,
23017,
63,
3243,
12,
21716,
63,
7569,
63,
3719,
467,
2589,
29,
2314,
680,
1199,
199,
199,
10640,
51,
63,
899,
40,
63,
25054,
275,
283,
2719,
3838,
1513,
72,
1726,
7,
315,
7393,
63,
4924,
199,
199,
692,
13756,
51,
63,
899,
40,
63,
25054,
26,
523,
32698,
63,
8414,
275,
9088,
63,
396,
63,
1208,
14,
22299,
779,
23017,
63,
3243,
467,
2589,
29,
2314,
680,
1199,
199,
199,
1438,
63,
13246,
63,
8414,
275,
9088,
63,
396,
63,
1208,
14,
22299,
8,
272,
359,
1438,
63,
23017,
63,
3243,
467,
2589,
29,
2314,
680,
1199,
421,
199,
3,
710,
2295,
14,
199,
692,
13756,
51,
63,
899,
40,
63,
25054,
26,
523,
327,
4287,
26,
5993,
13,
1328,
29,
35,
2766,
996,
523,
1021,
32754,
1513,
72,
16836,
774,
8,
8385,
63,
396,
63,
1208,
14,
1746,
304,
272,
408,
2925,
1919,
13,
9341,
316,
5953,
1041,
2378,
347,
1379,
1513,
72,
16836,
8,
277,
12,
511,
63,
1199,
304,
489,
291,
14,
479,
11252,
899,
40,
1919,
543,
1233,
378,
88,
18,
65,
14031,
283,
673,
283,
262,
314,
511,
10949,
3985,
83,
3787,
7,
673,
315,
511,
63,
1199,
9,
489,
291,
14,
479,
11252,
899,
40,
1919,
543,
1233,
378,
88,
18,
65,
14031,
283,
673,
283,
262,
314,
511,
10949,
3985,
83,
32133,
7,
673,
315,
511,
63,
1199,
9,
489,
291,
14,
479,
11252,
899,
40,
1919,
543,
1233,
378,
88,
18,
65,
14031,
315,
2494,
1721,
1746,
11716,
673,
315,
511,
63,
1199,
9,
489,
291,
14,
479,
11252,
899,
40,
1919,
543,
1233,
378,
88,
18,
65,
14031,
315,
377,
25236,
1746,
11716,
673,
315,
511,
63,
1199,
9,
489,
291,
14,
479,
11252,
899,
40,
1919,
543,
1233,
378,
88,
18,
65,
14031,
315,
2494,
1721,
11716,
673,
315,
511,
63,
1199,
9,
489,
291,
14,
479,
11252,
899,
40,
1919,
543,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Tong-Chen/genomics-tools
|
mapreduce-python/cloudstorage/rest_api.py
|
106
|
8012
|
# Copyright 2012 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Base and helper classes for Google RESTful APIs."""
__all__ = ['add_sync_methods']
import httplib
import random
import time
from . import api_utils
try:
from google.appengine.api import app_identity
from google.appengine.ext import ndb
except ImportError:
from google.appengine.api import app_identity
from google.appengine.ext import ndb
def _make_sync_method(name):
"""Helper to synthesize a synchronous method from an async method name.
Used by the @add_sync_methods class decorator below.
Args:
name: The name of the synchronous method.
Returns:
A method (with first argument 'self') that retrieves and calls
self.<name>, passing its own arguments, expects it to return a
Future, and then waits for and returns that Future's result.
"""
def sync_wrapper(self, *args, **kwds):
method = getattr(self, name)
future = method(*args, **kwds)
return future.get_result()
return sync_wrapper
def add_sync_methods(cls):
"""Class decorator to add synchronous methods corresponding to async methods.
This modifies the class in place, adding additional methods to it.
If a synchronous method of a given name already exists it is not
replaced.
Args:
cls: A class.
Returns:
The same class, modified in place.
"""
for name in cls.__dict__.keys():
if name.endswith('_async'):
sync_name = name[:-6]
if not hasattr(cls, sync_name):
setattr(cls, sync_name, _make_sync_method(name))
return cls
class _AE_TokenStorage_(ndb.Model):
"""Entity to store app_identity tokens in memcache."""
token = ndb.StringProperty()
expires = ndb.FloatProperty()
@ndb.tasklet
def _make_token_async(scopes, service_account_id):
"""Get a fresh authentication token.
Args:
scopes: A list of scopes.
service_account_id: Internal-use only.
Returns:
An tuple (token, expiration_time) where expiration_time is
seconds since the epoch.
"""
rpc = app_identity.create_rpc()
app_identity.make_get_access_token_call(rpc, scopes, service_account_id)
token, expires_at = yield rpc
raise ndb.Return((token, expires_at))
class _RestApi(object):
"""Base class for REST-based API wrapper classes.
This class manages authentication tokens and request retries. All
APIs are available as synchronous and async methods; synchronous
methods are synthesized from async ones by the add_sync_methods()
function in this module.
WARNING: Do NOT directly use this api. It's an implementation detail
and is subject to change at any release.
"""
_TOKEN_EXPIRATION_HEADROOM = random.randint(60, 600)
def __init__(self, scopes, service_account_id=None, token_maker=None,
retry_params=None):
"""Constructor.
Args:
scopes: A scope or a list of scopes.
token_maker: An asynchronous function of the form
(scopes, service_account_id) -> (token, expires).
retry_params: An instance of api_utils.RetryParams. If None, the
default for current thread will be used.
service_account_id: Internal use only.
"""
if isinstance(scopes, basestring):
scopes = [scopes]
self.scopes = scopes
self.service_account_id = service_account_id
self.make_token_async = token_maker or _make_token_async
self.token = None
if not retry_params:
retry_params = api_utils._get_default_retry_params()
self.retry_params = retry_params
def __getstate__(self):
"""Store state as part of serialization/pickling."""
return {'token': self.token,
'scopes': self.scopes,
'id': self.service_account_id,
'a_maker': None if self.make_token_async == _make_token_async
else self.make_token_async,
'retry_params': self.retry_params}
def __setstate__(self, state):
"""Restore state as part of deserialization/unpickling."""
self.__init__(state['scopes'],
service_account_id=state['id'],
token_maker=state['a_maker'],
retry_params=state['retry_params'])
self.token = state['token']
@ndb.tasklet
def do_request_async(self, url, method='GET', headers=None, payload=None,
deadline=None, callback=None):
"""Issue one HTTP request.
This is an async wrapper around urlfetch(). It adds an authentication
header and retries on a 401 status code. Upon other retriable errors,
it performs blocking retries.
"""
headers = {} if headers is None else dict(headers)
if self.token is None:
self.token = yield self.get_token_async()
headers['authorization'] = 'OAuth ' + self.token
deadline = deadline or self.retry_params.urlfetch_timeout
retry = False
resp = None
try:
resp = yield self.urlfetch_async(url, payload=payload, method=method,
headers=headers, follow_redirects=False,
deadline=deadline, callback=callback)
if resp.status_code == httplib.UNAUTHORIZED:
self.token = yield self.get_token_async(refresh=True)
headers['authorization'] = 'OAuth ' + self.token
resp = yield self.urlfetch_async(
url, payload=payload, method=method, headers=headers,
follow_redirects=False, deadline=deadline, callback=callback)
except api_utils._RETRIABLE_EXCEPTIONS:
retry = True
else:
retry = api_utils._should_retry(resp)
if retry:
retry_resp = api_utils._retry_fetch(
url, retry_params=self.retry_params, payload=payload, method=method,
headers=headers, follow_redirects=False, deadline=deadline)
if retry_resp:
resp = retry_resp
elif not resp:
raise
raise ndb.Return((resp.status_code, resp.headers, resp.content))
@ndb.tasklet
def get_token_async(self, refresh=False):
"""Get an authentication token.
The token is cached in memcache, keyed by the scopes argument.
Args:
refresh: If True, ignore a cached token; default False.
Returns:
An authentication token.
"""
if self.token is not None and not refresh:
raise ndb.Return(self.token)
key = '%s,%s' % (self.service_account_id, ','.join(self.scopes))
ts = yield _AE_TokenStorage_.get_by_id_async(
key, use_cache=True, use_memcache=True,
use_datastore=self.retry_params.save_access_token)
if ts is None or ts.expires < (time.time() +
self._TOKEN_EXPIRATION_HEADROOM):
token, expires_at = yield self.make_token_async(
self.scopes, self.service_account_id)
timeout = int(expires_at - time.time())
ts = _AE_TokenStorage_(id=key, token=token, expires=expires_at)
if timeout > 0:
yield ts.put_async(memcache_timeout=timeout,
use_datastore=self.retry_params.save_access_token,
use_cache=True, use_memcache=True)
self.token = ts.token
raise ndb.Return(self.token)
def urlfetch_async(self, url, **kwds):
"""Make an async urlfetch() call.
This just passes the url and keyword arguments to NDB's async
urlfetch() wrapper in the current context.
This returns a Future despite not being decorated with @ndb.tasklet!
"""
ctx = ndb.get_context()
return ctx.urlfetch(url, **kwds)
_RestApi = add_sync_methods(_RestApi)
|
apache-2.0
|
[
3,
1898,
6029,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
199,
3,
1902,
4056,
503,
2478,
14,
1666,
314,
844,
367,
314,
2488,
199,
3,
2637,
4210,
3443,
436,
4204,
1334,
314,
844,
14,
199,
199,
624,
1563,
436,
5922,
3992,
367,
4475,
14880,
1893,
15913,
1041,
28154,
199,
363,
452,
363,
275,
788,
525,
63,
5186,
63,
2474,
418,
199,
199,
646,
8809,
199,
646,
2196,
199,
646,
900,
199,
199,
504,
1275,
492,
2986,
63,
1208,
199,
199,
893,
26,
523,
687,
6233,
14,
15358,
14,
1246,
492,
1145,
63,
5582,
523,
687,
6233,
14,
15358,
14,
832,
492,
23788,
199,
2590,
3545,
26,
523,
687,
6233,
14,
15358,
14,
1246,
492,
1145,
63,
5582,
523,
687,
6233,
14,
15358,
14,
832,
492,
23788,
421,
199,
318,
485,
1875,
63,
5186,
63,
765,
8,
354,
304,
523,
408,
4433,
370,
9560,
1589,
890,
282,
24248,
1083,
687,
376,
5316,
1083,
536,
14,
819,
8051,
701,
314,
768,
525,
63,
5186,
63,
2474,
1021,
7531,
5084,
14,
819,
3033,
26,
272,
536,
26,
710,
536,
402,
314,
24248,
1083,
14,
819,
1803,
26,
272,
437,
1083,
334,
1045,
1642,
1423,
283,
277,
358,
626,
9619,
2310,
436,
4882,
272,
291,
21455,
354,
6244,
9476,
2399,
5705,
2368,
12,
14292,
652,
370,
372,
282,
272,
20799,
12,
436,
2066,
14442,
1405,
367,
436,
2529,
626,
20799,
1159,
754,
14,
523,
408,
819,
347,
7604,
63,
5029,
8,
277,
12,
627,
589,
12,
1011,
10340,
304,
272,
1083,
275,
2519,
8,
277,
12,
536,
9,
272,
6466,
275,
1083,
2031,
589,
12,
1011,
10340,
9,
272,
372,
6466,
14,
362,
63,
1099,
342,
819,
372,
7604,
63,
5029,
421,
199,
318,
1050,
63,
5186,
63,
2474,
8,
1886,
304,
523,
408,
2543,
7531,
370,
1050,
24248,
3102,
5226,
370,
5316,
3102,
14,
819,
961,
26473,
314,
1021,
315,
4192,
12,
7791,
4722,
3102,
370,
652,
14,
523,
982,
282,
24248,
1083,
402,
282,
1627,
536,
2575,
3495,
652,
365,
440,
523,
8717,
14,
819,
3033,
26,
272,
843,
26,
437,
1021,
14,
819,
1803,
26,
272,
710,
2011,
1021,
12,
6042,
315,
4192,
14,
523,
408,
523,
367,
536,
315,
843,
855,
807,
4343,
1612,
837,
272,
340,
536,
14,
4130,
6412,
4146,
735,
489,
7604,
63,
354,
275,
536,
4439,
22,
61,
489,
340,
440,
2688,
8,
1886,
12,
7604,
63,
354,
304,
267,
5371,
8,
1886,
12,
7604,
63,
354,
12,
485,
1875,
63,
5186,
63,
765,
8,
354,
430,
523,
372,
843,
421,
199,
533,
485,
12500,
63,
3264,
6408,
2531,
78,
697,
14,
1685,
304,
523,
408,
7302,
370,
3877,
1145,
63,
5582,
4645,
315,
21598,
1041,
819,
1526,
275,
23788,
14,
31821,
342,
523,
12261,
275,
23788,
14,
5136,
3697,
342,
421,
199,
32,
78,
697,
14,
1765,
2723,
199,
318,
485,
1875,
63,
1418,
63,
4146,
8,
14129,
12,
2435,
63,
2048,
63,
344,
304,
523,
408,
1002,
282,
17480,
6299,
1526,
14,
819,
3033,
26,
272,
14570,
26,
437,
769,
402,
14570,
14,
272,
2435,
63,
2048,
63,
344,
26,
12624,
13,
1180,
1454,
14,
819,
1803,
26,
272,
1626,
2008,
334,
1418,
12,
15399,
63,
521,
9,
2382,
15399,
63,
521,
365,
272,
4696,
3967,
314,
9463,
14,
523,
408,
523,
8985,
275,
1145,
63,
5582,
14,
981,
63,
4354,
342,
523,
1145,
63,
5582,
14,
1875,
63,
362,
63,
2732,
63,
1418,
63,
1250,
8,
4354,
12,
14570,
12,
2435,
63,
2048,
63,
344,
9,
523,
1526,
12,
12261,
63,
292,
275,
1995,
8985,
523,
746,
23788,
14,
1767,
1332,
1418,
12,
12261,
63,
292,
430,
421,
199,
533,
485,
13726,
7394,
8,
785,
304,
523,
408,
1563,
1021,
367,
14880,
13,
6788,
3261,
4975,
3992,
14,
819,
961,
1021,
31965,
6299,
4645,
436,
1056,
10086,
14,
221,
2900,
523,
15913,
787,
2808,
465,
24248,
436,
5316,
3102,
27,
24248,
523,
3102,
787,
9560,
1589,
15308,
687,
5316,
7869,
701,
314,
1050,
63,
5186,
63,
2474,
342,
523,
805,
315,
642,
859,
14,
819,
14750,
26,
4226,
2845,
5370,
675,
642,
2986,
14,
2779,
1159,
376,
4514,
10093,
523,
436,
365,
5420,
370,
1570,
737,
1263,
4683,
14,
523,
408,
819,
485,
8803,
63,
25632,
23743,
63,
5211,
1092,
7474,
275,
2196,
14,
8393,
8,
2259,
12,
11624,
9,
819,
347,
636,
826,
721,
277,
12,
14570,
12,
2435,
63,
2048,
63,
344,
29,
403,
12,
1526,
63,
14367,
29,
403,
12,
2049,
7269,
63,
1162,
29,
403,
304,
272,
408,
11447,
14,
339,
3033,
26,
489,
14570,
26,
437,
4194,
503,
282,
769,
402,
14570,
14,
489,
1526,
63,
14367,
26,
1626,
15608,
805,
402,
314,
1824,
267,
334,
14129,
12,
2435,
63,
2048,
63,
344,
9,
1035,
334,
1418,
12,
12261,
680,
489,
7269,
63,
1162,
26,
1626,
1256,
402,
2986,
63,
1208,
14,
12989,
6007,
14,
982,
488,
12,
314,
267,
849,
367,
1453,
2462,
911,
506,
1202,
14,
489,
2435,
63,
2048,
63,
344,
26,
12624,
675,
1454,
14,
272,
408,
339,
340,
1228,
8,
14129,
12,
7116,
304,
489,
14570,
275,
359,
14129,
61,
272,
291,
14,
14129,
275,
14570,
272,
291,
14,
1364,
63,
2048,
63,
344,
275,
2435,
63,
2048,
63,
344,
272,
291,
14,
1875,
63,
1418,
63,
4146,
275,
1526,
63,
14367,
503,
485,
1875,
63,
1418,
63,
4146,
272,
291,
14,
1418,
275,
488,
272,
340,
440,
7269,
63,
1162,
26,
489,
7269,
63,
1162,
275,
2986,
63,
1208,
423,
362,
63,
885,
63,
7154,
63,
1162,
342,
272,
291,
14,
7154,
63,
1162,
275,
7269,
63,
1162,
819
] |
[
1898,
6029,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
199,
3,
1902,
4056,
503,
2478,
14,
1666,
314,
844,
367,
314,
2488,
199,
3,
2637,
4210,
3443,
436,
4204,
1334,
314,
844,
14,
199,
199,
624,
1563,
436,
5922,
3992,
367,
4475,
14880,
1893,
15913,
1041,
28154,
199,
363,
452,
363,
275,
788,
525,
63,
5186,
63,
2474,
418,
199,
199,
646,
8809,
199,
646,
2196,
199,
646,
900,
199,
199,
504,
1275,
492,
2986,
63,
1208,
199,
199,
893,
26,
523,
687,
6233,
14,
15358,
14,
1246,
492,
1145,
63,
5582,
523,
687,
6233,
14,
15358,
14,
832,
492,
23788,
199,
2590,
3545,
26,
523,
687,
6233,
14,
15358,
14,
1246,
492,
1145,
63,
5582,
523,
687,
6233,
14,
15358,
14,
832,
492,
23788,
421,
199,
318,
485,
1875,
63,
5186,
63,
765,
8,
354,
304,
523,
408,
4433,
370,
9560,
1589,
890,
282,
24248,
1083,
687,
376,
5316,
1083,
536,
14,
819,
8051,
701,
314,
768,
525,
63,
5186,
63,
2474,
1021,
7531,
5084,
14,
819,
3033,
26,
272,
536,
26,
710,
536,
402,
314,
24248,
1083,
14,
819,
1803,
26,
272,
437,
1083,
334,
1045,
1642,
1423,
283,
277,
358,
626,
9619,
2310,
436,
4882,
272,
291,
21455,
354,
6244,
9476,
2399,
5705,
2368,
12,
14292,
652,
370,
372,
282,
272,
20799,
12,
436,
2066,
14442,
1405,
367,
436,
2529,
626,
20799,
1159,
754,
14,
523,
408,
819,
347,
7604,
63,
5029,
8,
277,
12,
627,
589,
12,
1011,
10340,
304,
272,
1083,
275,
2519,
8,
277,
12,
536,
9,
272,
6466,
275,
1083,
2031,
589,
12,
1011,
10340,
9,
272,
372,
6466,
14,
362,
63,
1099,
342,
819,
372,
7604,
63,
5029,
421,
199,
318,
1050,
63,
5186,
63,
2474,
8,
1886,
304,
523,
408,
2543,
7531,
370,
1050,
24248,
3102,
5226,
370,
5316,
3102,
14,
819,
961,
26473,
314,
1021,
315,
4192,
12,
7791,
4722,
3102,
370,
652,
14,
523,
982,
282,
24248,
1083,
402,
282,
1627,
536,
2575,
3495,
652,
365,
440,
523,
8717,
14,
819,
3033,
26,
272,
843,
26,
437,
1021,
14,
819,
1803,
26,
272,
710,
2011,
1021,
12,
6042,
315,
4192,
14,
523,
408,
523,
367,
536,
315,
843,
855,
807,
4343,
1612,
837,
272,
340,
536,
14,
4130,
6412,
4146,
735,
489,
7604,
63,
354,
275,
536,
4439,
22,
61,
489,
340,
440,
2688,
8,
1886,
12,
7604,
63,
354,
304,
267,
5371,
8,
1886,
12,
7604,
63,
354,
12,
485,
1875,
63,
5186,
63,
765,
8,
354,
430,
523,
372,
843,
421,
199,
533,
485,
12500,
63,
3264,
6408,
2531,
78,
697,
14,
1685,
304,
523,
408,
7302,
370,
3877,
1145,
63,
5582,
4645,
315,
21598,
1041,
819,
1526,
275,
23788,
14,
31821,
342,
523,
12261,
275,
23788,
14,
5136,
3697,
342,
421,
199,
32,
78,
697,
14,
1765,
2723,
199,
318,
485,
1875,
63,
1418,
63,
4146,
8,
14129,
12,
2435,
63,
2048,
63,
344,
304,
523,
408,
1002,
282,
17480,
6299,
1526,
14,
819,
3033,
26,
272,
14570,
26,
437,
769,
402,
14570,
14,
272,
2435,
63,
2048,
63,
344,
26,
12624,
13,
1180,
1454,
14,
819,
1803,
26,
272,
1626,
2008,
334,
1418,
12,
15399,
63,
521,
9,
2382,
15399,
63,
521,
365,
272,
4696,
3967,
314,
9463,
14,
523,
408,
523,
8985,
275,
1145,
63,
5582,
14,
981,
63,
4354,
342,
523,
1145,
63,
5582,
14,
1875,
63,
362,
63,
2732,
63,
1418,
63,
1250,
8,
4354,
12,
14570,
12,
2435,
63,
2048,
63,
344,
9,
523,
1526,
12,
12261,
63,
292,
275,
1995,
8985,
523,
746,
23788,
14,
1767,
1332,
1418,
12,
12261,
63,
292,
430,
421,
199,
533,
485,
13726,
7394,
8,
785,
304,
523,
408,
1563,
1021,
367,
14880,
13,
6788,
3261,
4975,
3992,
14,
819,
961,
1021,
31965,
6299,
4645,
436,
1056,
10086,
14,
221,
2900,
523,
15913,
787,
2808,
465,
24248,
436,
5316,
3102,
27,
24248,
523,
3102,
787,
9560,
1589,
15308,
687,
5316,
7869,
701,
314,
1050,
63,
5186,
63,
2474,
342,
523,
805,
315,
642,
859,
14,
819,
14750,
26,
4226,
2845,
5370,
675,
642,
2986,
14,
2779,
1159,
376,
4514,
10093,
523,
436,
365,
5420,
370,
1570,
737,
1263,
4683,
14,
523,
408,
819,
485,
8803,
63,
25632,
23743,
63,
5211,
1092,
7474,
275,
2196,
14,
8393,
8,
2259,
12,
11624,
9,
819,
347,
636,
826,
721,
277,
12,
14570,
12,
2435,
63,
2048,
63,
344,
29,
403,
12,
1526,
63,
14367,
29,
403,
12,
2049,
7269,
63,
1162,
29,
403,
304,
272,
408,
11447,
14,
339,
3033,
26,
489,
14570,
26,
437,
4194,
503,
282,
769,
402,
14570,
14,
489,
1526,
63,
14367,
26,
1626,
15608,
805,
402,
314,
1824,
267,
334,
14129,
12,
2435,
63,
2048,
63,
344,
9,
1035,
334,
1418,
12,
12261,
680,
489,
7269,
63,
1162,
26,
1626,
1256,
402,
2986,
63,
1208,
14,
12989,
6007,
14,
982,
488,
12,
314,
267,
849,
367,
1453,
2462,
911,
506,
1202,
14,
489,
2435,
63,
2048,
63,
344,
26,
12624,
675,
1454,
14,
272,
408,
339,
340,
1228,
8,
14129,
12,
7116,
304,
489,
14570,
275,
359,
14129,
61,
272,
291,
14,
14129,
275,
14570,
272,
291,
14,
1364,
63,
2048,
63,
344,
275,
2435,
63,
2048,
63,
344,
272,
291,
14,
1875,
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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
] |
SageHack/cloud-buster
|
bust/descriptor/httpresponse.py
|
1
|
1544
|
import http.client
class HttpResponse(object):
responses = {}
def __init__(self, domain, port=None, timeout=10, ssl=False):
self.domain = domain
self.timeout = timeout
self.ssl = ssl
if port is None and ssl is False:
self.port = 80
elif port is None and ssl is True:
self.port = 443
else:
self.port = port
@property
def id(self):
return self.domain+':'+str(self.port)+(':ssl' if self.ssl else '')
def __get__(self, obj=None, objtype=None):
if self.id in self.responses:
return self.responses[self.id]
if self.ssl:
connection = http.client.HTTPSConnection(
self.domain,
port=self.port,
timeout=self.timeout
)
else:
connection = http.client.HTTPConnection(
self.domain,
port=self.port,
timeout=self.timeout
)
try:
connection.request('HEAD', '/', None, headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; rv:36.0)' +
'Gecko/200101 Firefox/36.0'
}
)
response = connection.getresponse()
except (OSError, ConnectionError, http.client.BadStatusLine):
response = None
connection.close()
self.responses[self.id] = response
return response
def __set__(self, obj=None, val=None):
raise AttributeError
|
gpl-3.0
|
[
646,
1455,
14,
1258,
421,
199,
533,
6183,
8,
785,
304,
339,
9320,
275,
1052,
339,
347,
636,
826,
721,
277,
12,
2881,
12,
1844,
29,
403,
12,
2653,
29,
709,
12,
6149,
29,
797,
304,
267,
291,
14,
2261,
275,
2881,
267,
291,
14,
2593,
275,
2653,
267,
291,
14,
4266,
275,
6149,
398,
340,
1844,
365,
488,
436,
6149,
365,
756,
26,
288,
291,
14,
719,
275,
5939,
267,
916,
1844,
365,
488,
436,
6149,
365,
715,
26,
288,
291,
14,
719,
275,
23865,
267,
587,
26,
288,
291,
14,
719,
275,
1844,
339,
768,
1829,
272,
347,
1305,
8,
277,
304,
267,
372,
291,
14,
2261,
11,
5242,
11,
495,
8,
277,
14,
719,
6393,
6176,
4266,
7,
340,
291,
14,
4266,
587,
4074,
339,
347,
636,
362,
721,
277,
12,
1559,
29,
403,
12,
1559,
466,
29,
403,
304,
267,
340,
291,
14,
344,
315,
291,
14,
10360,
26,
288,
372,
291,
14,
10360,
59,
277,
14,
344,
61,
398,
340,
291,
14,
4266,
26,
288,
1950,
275,
1455,
14,
1258,
14,
27945,
8,
355,
291,
14,
2261,
12,
355,
1844,
29,
277,
14,
719,
12,
355,
2653,
29,
277,
14,
2593,
288,
776,
267,
587,
26,
288,
1950,
275,
1455,
14,
1258,
14,
19114,
8,
355,
291,
14,
2261,
12,
355,
1844,
29,
277,
14,
719,
12,
355,
2653,
29,
277,
14,
2593,
288,
776,
398,
862,
26,
288,
1950,
14,
1069,
360,
5211,
297,
17220,
488,
12,
2323,
3126,
355,
283,
1899,
13,
7788,
356,
283,
22285,
15,
21,
14,
16,
334,
8647,
23350,
1227,
14,
19,
27,
4336,
26,
1344,
14,
16,
3171,
435,
355,
283,
4240,
21633,
15,
1840,
4893,
24584,
15,
1344,
14,
16,
7,
355,
789,
288,
776,
288,
1177,
275,
1950,
14,
25006,
342,
267,
871,
334,
16719,
12,
25417,
12,
1455,
14,
1258,
14,
5725,
3694,
3049,
304,
288,
1177,
275,
488,
398,
1950,
14,
1600,
342,
398,
291,
14,
10360,
59,
277,
14,
344,
61,
275,
1177,
267,
372,
1177,
339,
347,
636,
409,
721,
277,
12,
1559,
29,
403,
12,
1139,
29,
403,
304,
267,
746,
4281,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1455,
14,
1258,
421,
199,
533,
6183,
8,
785,
304,
339,
9320,
275,
1052,
339,
347,
636,
826,
721,
277,
12,
2881,
12,
1844,
29,
403,
12,
2653,
29,
709,
12,
6149,
29,
797,
304,
267,
291,
14,
2261,
275,
2881,
267,
291,
14,
2593,
275,
2653,
267,
291,
14,
4266,
275,
6149,
398,
340,
1844,
365,
488,
436,
6149,
365,
756,
26,
288,
291,
14,
719,
275,
5939,
267,
916,
1844,
365,
488,
436,
6149,
365,
715,
26,
288,
291,
14,
719,
275,
23865,
267,
587,
26,
288,
291,
14,
719,
275,
1844,
339,
768,
1829,
272,
347,
1305,
8,
277,
304,
267,
372,
291,
14,
2261,
11,
5242,
11,
495,
8,
277,
14,
719,
6393,
6176,
4266,
7,
340,
291,
14,
4266,
587,
4074,
339,
347,
636,
362,
721,
277,
12,
1559,
29,
403,
12,
1559,
466,
29,
403,
304,
267,
340,
291,
14,
344,
315,
291,
14,
10360,
26,
288,
372,
291,
14,
10360,
59,
277,
14,
344,
61,
398,
340,
291,
14,
4266,
26,
288,
1950,
275,
1455,
14,
1258,
14,
27945,
8,
355,
291,
14,
2261,
12,
355,
1844,
29,
277,
14,
719,
12,
355,
2653,
29,
277,
14,
2593,
288,
776,
267,
587,
26,
288,
1950,
275,
1455,
14,
1258,
14,
19114,
8,
355,
291,
14,
2261,
12,
355,
1844,
29,
277,
14,
719,
12,
355,
2653,
29,
277,
14,
2593,
288,
776,
398,
862,
26,
288,
1950,
14,
1069,
360,
5211,
297,
17220,
488,
12,
2323,
3126,
355,
283,
1899,
13,
7788,
356,
283,
22285,
15,
21,
14,
16,
334,
8647,
23350,
1227,
14,
19,
27,
4336,
26,
1344,
14,
16,
3171,
435,
355,
283,
4240,
21633,
15,
1840,
4893,
24584,
15,
1344,
14,
16,
7,
355,
789,
288,
776,
288,
1177,
275,
1950,
14,
25006,
342,
267,
871,
334,
16719,
12,
25417,
12,
1455,
14,
1258,
14,
5725,
3694,
3049,
304,
288,
1177,
275,
488,
398,
1950,
14,
1600,
342,
398,
291,
14,
10360,
59,
277,
14,
344,
61,
275,
1177,
267,
372,
1177,
339,
347,
636,
409,
721,
277,
12,
1559,
29,
403,
12,
1139,
29,
403,
304,
267,
746,
4281,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
yogiben/Sublime-AdvancedNewFile
|
advanced_new_file/anf_util.py
|
2
|
6650
|
import sublime
import re
import os
ALIAS_SETTING = "alias"
DEFAULT_INITIAL_SETTING = "default_initial"
USE_CURSOR_TEXT_SETTING = "use_cursor_text"
SHOW_FILES_SETTING = "show_files"
SHOW_PATH_SETTING = "show_path"
DEFAULT_ROOT_SETTING = "default_root"
DEFAULT_PATH_SETTING = "default_path"
DEFAULT_FOLDER_INDEX_SETTING = "default_folder_index"
OS_SPECIFIC_ALIAS_SETTING = "os_specific_alias"
IGNORE_CASE_SETTING = "ignore_case"
ALIAS_ROOT_SETTING = "alias_root"
ALIAS_PATH_SETTING = "alias_path"
ALIAS_FOLDER_INDEX_SETTING = "alias_folder_index"
DEBUG_SETTING = "debug"
AUTO_REFRESH_SIDEBAR_SETTING = "auto_refresh_sidebar"
COMPLETION_TYPE_SETTING = "completion_type"
COMPLETE_SINGLE_ENTRY_SETTING = "complete_single_entry"
USE_FOLDER_NAME_SETTING = "use_folder_name"
RELATIVE_FROM_CURRENT_SETTING = "relative_from_current"
DEFAULT_EXTENSION_SETTING = "default_extension"
FILE_PERMISSIONS_SETTING = "file_permissions"
FOLDER_PERMISSIONS_SETTING = "folder_permissions"
RENAME_DEFAULT_SETTING = "rename_default"
VCS_MANAGEMENT_SETTING = "vcs_management"
FILE_TEMPLATES_SETTING = "file_templates"
SHELL_INPUT_SETTING = "shell_input"
APPEND_EXTENSION_ON_MOVE_SETTING = "append_extension_on_move"
RELATIVE_FALLBACK_INDEX_SETTING = "relative_fallback_index"
APPEND_EXTENSION_ON_COPY_SETTING = "append_extension_on_copy"
COPY_DEFAULT_SETTING = "copy_default"
CUT_TO_FILE_DEFAULT_SETTING = "cut_to_file_default"
CURRENT_FALLBACK_TO_PROJECT_SETTING = "current_fallback_to_project"
WARN_OVERWRITE_ON_MOVE_SETTING = "warn_overwrite_on_move"
NEW_FILE_DEFAULT_ROOT_SETTING = "new_file_default_root"
RENAME_FILE_DEFAULT_ROOT_SETTING = "rename_file_default_root"
COPY_FILE_DEFAULT_ROOT_SETTING = "copy_file_default_root"
DEFAULT_NEW_FILE = "empty_filename_action"
CURSOR_BEFORE_EXTENSION_SETTING = "cursor_before_extension"
SETTINGS = [
ALIAS_SETTING,
DEFAULT_INITIAL_SETTING,
USE_CURSOR_TEXT_SETTING,
SHOW_FILES_SETTING,
SHOW_PATH_SETTING,
DEFAULT_ROOT_SETTING,
DEFAULT_PATH_SETTING,
DEFAULT_FOLDER_INDEX_SETTING,
OS_SPECIFIC_ALIAS_SETTING,
IGNORE_CASE_SETTING,
ALIAS_ROOT_SETTING,
ALIAS_PATH_SETTING,
ALIAS_FOLDER_INDEX_SETTING,
DEBUG_SETTING,
AUTO_REFRESH_SIDEBAR_SETTING,
COMPLETION_TYPE_SETTING,
COMPLETE_SINGLE_ENTRY_SETTING,
USE_FOLDER_NAME_SETTING,
RELATIVE_FROM_CURRENT_SETTING,
DEFAULT_EXTENSION_SETTING,
FILE_PERMISSIONS_SETTING,
FOLDER_PERMISSIONS_SETTING,
RENAME_DEFAULT_SETTING,
VCS_MANAGEMENT_SETTING,
FILE_TEMPLATES_SETTING,
SHELL_INPUT_SETTING,
APPEND_EXTENSION_ON_MOVE_SETTING,
RELATIVE_FALLBACK_INDEX_SETTING,
APPEND_EXTENSION_ON_COPY_SETTING,
COPY_DEFAULT_SETTING,
CUT_TO_FILE_DEFAULT_SETTING,
CURRENT_FALLBACK_TO_PROJECT_SETTING,
WARN_OVERWRITE_ON_MOVE_SETTING,
NEW_FILE_DEFAULT_ROOT_SETTING,
RENAME_FILE_DEFAULT_ROOT_SETTING,
COPY_FILE_DEFAULT_ROOT_SETTING,
DEFAULT_NEW_FILE,
CURSOR_BEFORE_EXTENSION_SETTING
]
NIX_ROOT_REGEX = r"^/"
WIN_ROOT_REGEX = r"[a-zA-Z]:(/|\\)"
HOME_REGEX = r"^~"
PLATFORM = sublime.platform()
TOP_LEVEL_SPLIT_CHAR = ":"
IS_ST3 = int(sublime.version()) > 3000
IS_X64 = sublime.arch() == "x64"
REGION_KEY = "anf_cut_to_file"
def generate_creation_path(settings, base, path, append_extension=False):
if PLATFORM == "windows":
if not re.match(WIN_ROOT_REGEX, base):
if IS_ST3:
drive, _ = os.path.splitdrive(base)
else:
drive, _ = os.path.splitunc(base)
if len(drive) == 0:
return base + TOP_LEVEL_SPLIT_CHAR + path
else:
return os.path.join(base, path)
else:
if not re.match(NIX_ROOT_REGEX, base):
return base + TOP_LEVEL_SPLIT_CHAR + path
tokens = re.split(r"[/\\]", base) + re.split(r"[/\\]", path)
if tokens[0] == "":
tokens[0] = "/"
if PLATFORM == "windows":
tokens[0] = base[0:3]
full_path = os.path.abspath(os.path.join(*tokens))
if re.search(r"[/\\]$", path) or len(path) == 0:
full_path += os.path.sep
elif re.search(r"\.", tokens[-1]):
if re.search(r"\.$", tokens[-1]):
full_path += "."
elif append_extension:
filename = os.path.basename(full_path)
if not os.path.exists(full_path):
full_path += settings.get(DEFAULT_EXTENSION_SETTING)
return full_path
def get_settings(view):
settings = sublime.load_settings("AdvancedNewFile.sublime-settings")
project_settings = {}
local_settings = {}
if view is not None:
project_settings = view.settings().get('AdvancedNewFile', {})
for setting in SETTINGS:
local_settings[setting] = settings.get(setting)
if type(project_settings) != dict:
print("Invalid type %s for project settings" % type(project_settings))
return local_settings
for key in project_settings:
if key in SETTINGS:
if key == "alias":
if IS_ST3:
local_settings[key] = dict(
local_settings[key].items() |
project_settings.get(key).items()
)
else:
local_settings[key] = dict(
local_settings[key].items() +
project_settings.get(key).items()
)
else:
local_settings[key] = project_settings[key]
else:
print("AdvancedNewFile[Warning]: Invalid key " +
"'%s' in project settings.", key)
return local_settings
def get_project_folder_data(use_folder_name):
folders = []
folder_entries = []
window = sublime.active_window()
project_folders = window.folders()
if IS_ST3:
project_data = window.project_data()
if project_data is not None:
if use_folder_name:
for folder in project_data.get("folders", []):
folder_entries.append({})
else:
folder_entries = project_data.get("folders", [])
else:
for folder in project_folders:
folder_entries.append({})
for index in range(len(folder_entries)):
folder_path = project_folders[index]
folder_entry = folder_entries[index]
if "name" in folder_entry:
folders.append((folder_entry["name"], folder_path))
else:
folders.append((os.path.basename(folder_path), folder_path))
return folders
|
mit
|
[
646,
1007,
18687,
199,
646,
295,
199,
646,
747,
199,
199,
12644,
63,
12490,
1206,
275,
298,
3620,
2,
199,
3472,
63,
13768,
63,
12490,
1206,
275,
298,
885,
63,
2747,
2,
199,
4701,
63,
31321,
63,
3876,
63,
12490,
1206,
275,
298,
1180,
63,
3937,
63,
505,
2,
199,
19085,
63,
9472,
63,
12490,
1206,
275,
298,
2384,
63,
1725,
2,
199,
19085,
63,
3243,
63,
12490,
1206,
275,
298,
2384,
63,
515,
2,
199,
3472,
63,
5441,
63,
12490,
1206,
275,
298,
885,
63,
1231,
2,
199,
3472,
63,
3243,
63,
12490,
1206,
275,
298,
885,
63,
515,
2,
199,
3472,
63,
19041,
63,
10215,
63,
12490,
1206,
275,
298,
885,
63,
3741,
63,
1080,
2,
199,
3100,
63,
22917,
23380,
63,
12644,
63,
12490,
1206,
275,
298,
736,
63,
6100,
63,
3620,
2,
199,
11209,
63,
11320,
63,
12490,
1206,
275,
298,
4247,
63,
2546,
2,
199,
12644,
63,
5441,
63,
12490,
1206,
275,
298,
3620,
63,
1231,
2,
199,
12644,
63,
3243,
63,
12490,
1206,
275,
298,
3620,
63,
515,
2,
199,
12644,
63,
19041,
63,
10215,
63,
12490,
1206,
275,
298,
3620,
63,
3741,
63,
1080,
2,
199,
5287,
63,
12490,
1206,
275,
298,
1757,
2,
199,
13883,
63,
8279,
15098,
63,
28035,
13895,
63,
12490,
1206,
275,
298,
2495,
63,
6635,
63,
27372,
2,
199,
12558,
31133,
63,
2711,
63,
12490,
1206,
275,
298,
13207,
63,
466,
2,
199,
15558,
63,
16425,
63,
7285,
63,
12490,
1206,
275,
298,
4883,
63,
4780,
63,
2373,
2,
199,
4701,
63,
19041,
63,
2339,
63,
12490,
1206,
275,
298,
1180,
63,
3741,
63,
354,
2,
199,
13604,
14277,
63,
12491,
63,
14211,
63,
12490,
1206,
275,
298,
6188,
63,
504,
63,
1818,
2,
199,
3472,
63,
15498,
63,
12490,
1206,
275,
298,
885,
63,
3435,
2,
199,
3817,
63,
4227,
31978,
63,
12490,
1206,
275,
298,
493,
63,
6060,
2,
199,
19041,
63,
4227,
31978,
63,
12490,
1206,
275,
298,
3741,
63,
6060,
2,
199,
50,
11536,
63,
3472,
63,
12490,
1206,
275,
298,
8165,
63,
885,
2,
199,
24379,
63,
20600,
9591,
63,
12490,
1206,
275,
298,
15525,
63,
8110,
2,
199,
3817,
63,
25437,
63,
12490,
1206,
275,
298,
493,
63,
5876,
2,
199,
29085,
63,
7321,
63,
12490,
1206,
275,
298,
5641,
63,
1210,
2,
199,
25248,
63,
15498,
63,
615,
63,
16207,
63,
12490,
1206,
275,
298,
740,
63,
3435,
63,
265,
63,
1185,
2,
199,
13604,
14277,
63,
38,
1761,
7111,
63,
10215,
63,
12490,
1206,
275,
298,
6188,
63,
10538,
63,
1080,
2,
199,
25248,
63,
15498,
63,
615,
63,
16188,
63,
12490,
1206,
275,
298,
740,
63,
3435,
63,
265,
63,
1574,
2,
199,
16188,
63,
3472,
63,
12490,
1206,
275,
298,
1574,
63,
885,
2,
199,
24678,
63,
2566,
63,
3817,
63,
3472,
63,
12490,
1206,
275,
298,
5919,
63,
475,
63,
493,
63,
885,
2,
199,
14211,
63,
38,
1761,
7111,
63,
2566,
63,
10797,
63,
12490,
1206,
275,
298,
1818,
63,
10538,
63,
475,
63,
1715,
2,
199,
17449,
63,
14336,
10387,
63,
615,
63,
16207,
63,
12490,
1206,
275,
298,
4050,
63,
14658,
63,
265,
63,
1185,
2,
199,
11365,
63,
3817,
63,
3472,
63,
5441,
63,
12490,
1206,
275,
298,
1222,
63,
493,
63,
885,
63,
1231,
2,
199,
50,
11536,
63,
3817,
63,
3472,
63,
5441,
63,
12490,
1206,
275,
298,
8165,
63,
493,
63,
885,
63,
1231,
2,
199,
16188,
63,
3817,
63,
3472,
63,
5441,
63,
12490,
1206,
275,
298,
1574,
63,
493,
63,
885,
63,
1231,
2,
199,
3472,
63,
11365,
63,
3817,
275,
298,
1667,
63,
1501,
63,
1287,
2,
199,
31321,
63,
31481,
63,
15498,
63,
12490,
1206,
275,
298,
3937,
63,
5182,
63,
3435,
2,
421,
199,
13931,
275,
359,
272,
437,
2673,
1179,
63,
12490,
1206,
12,
272,
6186,
63,
13768,
63,
12490,
1206,
12,
272,
4815,
63,
31321,
63,
3876,
63,
12490,
1206,
12,
272,
428,
16210,
63,
9472,
63,
12490,
1206,
12,
272,
428,
16210,
63,
3243,
63,
12490,
1206,
12,
272,
6186,
63,
5441,
63,
12490,
1206,
12,
272,
6186,
63,
3243,
63,
12490,
1206,
12,
272,
6186,
63,
19041,
63,
10215,
63,
12490,
1206,
12,
272,
4403,
63,
22917,
23380,
63,
12644,
63,
12490,
1206,
12,
272,
27499,
5788,
63,
11320,
63,
12490,
1206,
12,
272,
437,
2673,
1179,
63,
5441,
63,
12490,
1206,
12,
272,
437,
2673,
1179,
63,
3243,
63,
12490,
1206,
12,
272,
437,
2673,
1179,
63,
19041,
63,
10215,
63,
12490,
1206,
12,
272,
10990,
63,
12490,
1206,
12,
272,
25420,
63,
8279,
15098,
63,
28035,
13895,
63,
12490,
1206,
12,
272,
5099,
3950,
31133,
63,
2711,
63,
12490,
1206,
12,
272,
5099,
3950,
5248,
63,
16425,
63,
7285,
63,
12490,
1206,
12,
272,
4815,
63,
19041,
63,
2339,
63,
12490,
1206,
12,
272,
820,
2901,
14277,
63,
12491,
63,
14211,
63,
12490,
1206,
12,
272,
6186,
63,
15498,
63,
12490,
1206,
12,
272,
13024,
63,
4227,
31978,
63,
12490,
1206,
12,
272,
481,
15744,
63,
4227,
31978,
63,
12490,
1206,
12,
272,
820,
11536,
63,
3472,
63,
12490,
1206,
12,
272,
23563,
63,
20600,
9591,
63,
12490,
1206,
12,
272,
13024,
63,
25437,
63,
12490,
1206,
12,
272,
428,
1645,
4464,
63,
7321,
63,
12490,
1206,
12,
272,
19525,
3902,
63,
15498,
63,
615,
63,
16207,
63,
12490,
1206,
12,
272,
820,
2901,
14277,
63,
38,
1761,
7111,
63,
10215,
63,
12490,
1206,
12,
272,
19525,
3902,
63,
15498,
63,
615,
63,
16188,
63,
12490,
1206,
12,
272,
9357,
63,
3472,
63,
12490,
1206,
12,
272,
445,
934,
63,
2566,
63,
3817,
63,
3472,
63,
12490,
1206,
12,
272,
27946,
63,
38,
1761,
7111,
63,
2566,
63,
10797,
63,
12490,
1206,
12,
272,
13253,
46,
63,
14336,
10387,
63,
615,
63,
16207,
63,
12490,
1206,
12,
272,
18689,
63,
3817,
63,
3472,
63,
5441,
63,
12490,
1206,
12,
272,
820,
11536,
63,
3817,
63,
3472,
63,
5441,
63,
12490,
1206,
12,
272,
9357,
63,
3817,
63,
3472,
63,
5441,
63,
12490,
1206,
12,
272,
6186,
63,
11365,
63,
3817,
12,
272,
18715,
26508,
63,
31481,
63,
15498,
63,
12490,
1206,
199,
61,
199,
199,
46,
3867,
63,
5441,
63,
10710,
275,
519
] |
[
1007,
18687,
199,
646,
295,
199,
646,
747,
199,
199,
12644,
63,
12490,
1206,
275,
298,
3620,
2,
199,
3472,
63,
13768,
63,
12490,
1206,
275,
298,
885,
63,
2747,
2,
199,
4701,
63,
31321,
63,
3876,
63,
12490,
1206,
275,
298,
1180,
63,
3937,
63,
505,
2,
199,
19085,
63,
9472,
63,
12490,
1206,
275,
298,
2384,
63,
1725,
2,
199,
19085,
63,
3243,
63,
12490,
1206,
275,
298,
2384,
63,
515,
2,
199,
3472,
63,
5441,
63,
12490,
1206,
275,
298,
885,
63,
1231,
2,
199,
3472,
63,
3243,
63,
12490,
1206,
275,
298,
885,
63,
515,
2,
199,
3472,
63,
19041,
63,
10215,
63,
12490,
1206,
275,
298,
885,
63,
3741,
63,
1080,
2,
199,
3100,
63,
22917,
23380,
63,
12644,
63,
12490,
1206,
275,
298,
736,
63,
6100,
63,
3620,
2,
199,
11209,
63,
11320,
63,
12490,
1206,
275,
298,
4247,
63,
2546,
2,
199,
12644,
63,
5441,
63,
12490,
1206,
275,
298,
3620,
63,
1231,
2,
199,
12644,
63,
3243,
63,
12490,
1206,
275,
298,
3620,
63,
515,
2,
199,
12644,
63,
19041,
63,
10215,
63,
12490,
1206,
275,
298,
3620,
63,
3741,
63,
1080,
2,
199,
5287,
63,
12490,
1206,
275,
298,
1757,
2,
199,
13883,
63,
8279,
15098,
63,
28035,
13895,
63,
12490,
1206,
275,
298,
2495,
63,
6635,
63,
27372,
2,
199,
12558,
31133,
63,
2711,
63,
12490,
1206,
275,
298,
13207,
63,
466,
2,
199,
15558,
63,
16425,
63,
7285,
63,
12490,
1206,
275,
298,
4883,
63,
4780,
63,
2373,
2,
199,
4701,
63,
19041,
63,
2339,
63,
12490,
1206,
275,
298,
1180,
63,
3741,
63,
354,
2,
199,
13604,
14277,
63,
12491,
63,
14211,
63,
12490,
1206,
275,
298,
6188,
63,
504,
63,
1818,
2,
199,
3472,
63,
15498,
63,
12490,
1206,
275,
298,
885,
63,
3435,
2,
199,
3817,
63,
4227,
31978,
63,
12490,
1206,
275,
298,
493,
63,
6060,
2,
199,
19041,
63,
4227,
31978,
63,
12490,
1206,
275,
298,
3741,
63,
6060,
2,
199,
50,
11536,
63,
3472,
63,
12490,
1206,
275,
298,
8165,
63,
885,
2,
199,
24379,
63,
20600,
9591,
63,
12490,
1206,
275,
298,
15525,
63,
8110,
2,
199,
3817,
63,
25437,
63,
12490,
1206,
275,
298,
493,
63,
5876,
2,
199,
29085,
63,
7321,
63,
12490,
1206,
275,
298,
5641,
63,
1210,
2,
199,
25248,
63,
15498,
63,
615,
63,
16207,
63,
12490,
1206,
275,
298,
740,
63,
3435,
63,
265,
63,
1185,
2,
199,
13604,
14277,
63,
38,
1761,
7111,
63,
10215,
63,
12490,
1206,
275,
298,
6188,
63,
10538,
63,
1080,
2,
199,
25248,
63,
15498,
63,
615,
63,
16188,
63,
12490,
1206,
275,
298,
740,
63,
3435,
63,
265,
63,
1574,
2,
199,
16188,
63,
3472,
63,
12490,
1206,
275,
298,
1574,
63,
885,
2,
199,
24678,
63,
2566,
63,
3817,
63,
3472,
63,
12490,
1206,
275,
298,
5919,
63,
475,
63,
493,
63,
885,
2,
199,
14211,
63,
38,
1761,
7111,
63,
2566,
63,
10797,
63,
12490,
1206,
275,
298,
1818,
63,
10538,
63,
475,
63,
1715,
2,
199,
17449,
63,
14336,
10387,
63,
615,
63,
16207,
63,
12490,
1206,
275,
298,
4050,
63,
14658,
63,
265,
63,
1185,
2,
199,
11365,
63,
3817,
63,
3472,
63,
5441,
63,
12490,
1206,
275,
298,
1222,
63,
493,
63,
885,
63,
1231,
2,
199,
50,
11536,
63,
3817,
63,
3472,
63,
5441,
63,
12490,
1206,
275,
298,
8165,
63,
493,
63,
885,
63,
1231,
2,
199,
16188,
63,
3817,
63,
3472,
63,
5441,
63,
12490,
1206,
275,
298,
1574,
63,
493,
63,
885,
63,
1231,
2,
199,
3472,
63,
11365,
63,
3817,
275,
298,
1667,
63,
1501,
63,
1287,
2,
199,
31321,
63,
31481,
63,
15498,
63,
12490,
1206,
275,
298,
3937,
63,
5182,
63,
3435,
2,
421,
199,
13931,
275,
359,
272,
437,
2673,
1179,
63,
12490,
1206,
12,
272,
6186,
63,
13768,
63,
12490,
1206,
12,
272,
4815,
63,
31321,
63,
3876,
63,
12490,
1206,
12,
272,
428,
16210,
63,
9472,
63,
12490,
1206,
12,
272,
428,
16210,
63,
3243,
63,
12490,
1206,
12,
272,
6186,
63,
5441,
63,
12490,
1206,
12,
272,
6186,
63,
3243,
63,
12490,
1206,
12,
272,
6186,
63,
19041,
63,
10215,
63,
12490,
1206,
12,
272,
4403,
63,
22917,
23380,
63,
12644,
63,
12490,
1206,
12,
272,
27499,
5788,
63,
11320,
63,
12490,
1206,
12,
272,
437,
2673,
1179,
63,
5441,
63,
12490,
1206,
12,
272,
437,
2673,
1179,
63,
3243,
63,
12490,
1206,
12,
272,
437,
2673,
1179,
63,
19041,
63,
10215,
63,
12490,
1206,
12,
272,
10990,
63,
12490,
1206,
12,
272,
25420,
63,
8279,
15098,
63,
28035,
13895,
63,
12490,
1206,
12,
272,
5099,
3950,
31133,
63,
2711,
63,
12490,
1206,
12,
272,
5099,
3950,
5248,
63,
16425,
63,
7285,
63,
12490,
1206,
12,
272,
4815,
63,
19041,
63,
2339,
63,
12490,
1206,
12,
272,
820,
2901,
14277,
63,
12491,
63,
14211,
63,
12490,
1206,
12,
272,
6186,
63,
15498,
63,
12490,
1206,
12,
272,
13024,
63,
4227,
31978,
63,
12490,
1206,
12,
272,
481,
15744,
63,
4227,
31978,
63,
12490,
1206,
12,
272,
820,
11536,
63,
3472,
63,
12490,
1206,
12,
272,
23563,
63,
20600,
9591,
63,
12490,
1206,
12,
272,
13024,
63,
25437,
63,
12490,
1206,
12,
272,
428,
1645,
4464,
63,
7321,
63,
12490,
1206,
12,
272,
19525,
3902,
63,
15498,
63,
615,
63,
16207,
63,
12490,
1206,
12,
272,
820,
2901,
14277,
63,
38,
1761,
7111,
63,
10215,
63,
12490,
1206,
12,
272,
19525,
3902,
63,
15498,
63,
615,
63,
16188,
63,
12490,
1206,
12,
272,
9357,
63,
3472,
63,
12490,
1206,
12,
272,
445,
934,
63,
2566,
63,
3817,
63,
3472,
63,
12490,
1206,
12,
272,
27946,
63,
38,
1761,
7111,
63,
2566,
63,
10797,
63,
12490,
1206,
12,
272,
13253,
46,
63,
14336,
10387,
63,
615,
63,
16207,
63,
12490,
1206,
12,
272,
18689,
63,
3817,
63,
3472,
63,
5441,
63,
12490,
1206,
12,
272,
820,
11536,
63,
3817,
63,
3472,
63,
5441,
63,
12490,
1206,
12,
272,
9357,
63,
3817,
63,
3472,
63,
5441,
63,
12490,
1206,
12,
272,
6186,
63,
11365,
63,
3817,
12,
272,
18715,
26508,
63,
31481,
63,
15498,
63,
12490,
1206,
199,
61,
199,
199,
46,
3867,
63,
5441,
63,
10710,
275,
519,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
vegitron/pyodbc
|
tests3/accesstests.py
|
22
|
22390
|
#!/usr/bin/python
usage="""\
usage: %prog [options] filename
Unit tests for Microsoft Access
These run using the version from the 'build' directory, not the version
installed into the Python directories. You must run python setup.py build
before running the tests.
To run, pass the filename of an Access database on the command line:
accesstests test.accdb
An empty Access 2000 database (empty.mdb) and an empty Access 2007 database
(empty.accdb), are provided.
To run a single test, use the -t option:
accesstests test.accdb -t unicode_null
If you want to report an error, it would be helpful to include the driver information
by using the verbose flag and redirecting the output to a file:
accesstests test.accdb -v >& results.txt
You can pass the verbose flag twice for more verbose output:
accesstests test.accdb -vv
"""
# Access SQL data types: http://msdn2.microsoft.com/en-us/library/bb208866.aspx
import sys, os, re
import unittest
from decimal import Decimal
from datetime import datetime, date, time
from os.path import abspath
from testutils import *
CNXNSTRING = None
_TESTSTR = '0123456789-abcdefghijklmnopqrstuvwxyz-'
def _generate_test_string(length):
"""
Returns a string of composed of `seed` to make a string `length` characters long.
To enhance performance, there are 3 ways data is read, based on the length of the value, so most data types are
tested with 3 lengths. This function helps us generate the test data.
We use a recognizable data set instead of a single character to make it less likely that "overlap" errors will
be hidden and to help us manually identify where a break occurs.
"""
if length <= len(_TESTSTR):
return _TESTSTR[:length]
c = (length + len(_TESTSTR)-1) / len(_TESTSTR)
v = _TESTSTR * c
return v[:length]
class AccessTestCase(unittest.TestCase):
SMALL_FENCEPOST_SIZES = [ 0, 1, 254, 255 ] # text fields <= 255
LARGE_FENCEPOST_SIZES = [ 256, 270, 304, 508, 510, 511, 512, 1023, 1024, 2047, 2048, 4000, 4095, 4096, 4097, 10 * 1024, 20 * 1024 ]
ANSI_FENCEPOSTS = [ _generate_test_string(size) for size in SMALL_FENCEPOST_SIZES ]
UNICODE_FENCEPOSTS = [ unicode(s) for s in ANSI_FENCEPOSTS ]
IMAGE_FENCEPOSTS = ANSI_FENCEPOSTS + [ _generate_test_string(size) for size in LARGE_FENCEPOST_SIZES ]
def __init__(self, method_name):
unittest.TestCase.__init__(self, method_name)
def setUp(self):
self.cnxn = pyodbc.connect(CNXNSTRING)
self.cursor = self.cnxn.cursor()
for i in range(3):
try:
self.cursor.execute("drop table t%d" % i)
self.cnxn.commit()
except:
pass
self.cnxn.rollback()
def tearDown(self):
try:
self.cursor.close()
self.cnxn.close()
except:
# If we've already closed the cursor or connection, exceptions are thrown.
pass
def test_multiple_bindings(self):
"More than one bind and select on a cursor"
self.cursor.execute("create table t1(n int)")
self.cursor.execute("insert into t1 values (?)", 1)
self.cursor.execute("insert into t1 values (?)", 2)
self.cursor.execute("insert into t1 values (?)", 3)
for i in range(3):
self.cursor.execute("select n from t1 where n < ?", 10)
self.cursor.execute("select n from t1 where n < 3")
def test_different_bindings(self):
self.cursor.execute("create table t1(n int)")
self.cursor.execute("create table t2(d datetime)")
self.cursor.execute("insert into t1 values (?)", 1)
self.cursor.execute("insert into t2 values (?)", datetime.now())
def test_datasources(self):
p = pyodbc.dataSources()
self.assert_(isinstance(p, dict))
def test_getinfo_string(self):
value = self.cnxn.getinfo(pyodbc.SQL_CATALOG_NAME_SEPARATOR)
self.assert_(isinstance(value, str))
def test_getinfo_bool(self):
value = self.cnxn.getinfo(pyodbc.SQL_ACCESSIBLE_TABLES)
self.assert_(isinstance(value, bool))
def test_getinfo_int(self):
value = self.cnxn.getinfo(pyodbc.SQL_DEFAULT_TXN_ISOLATION)
self.assert_(isinstance(value, (int, long)))
def test_getinfo_smallint(self):
value = self.cnxn.getinfo(pyodbc.SQL_CONCAT_NULL_BEHAVIOR)
self.assert_(isinstance(value, int))
def _test_strtype(self, sqltype, value, colsize=None):
"""
The implementation for string, Unicode, and binary tests.
"""
assert colsize is None or (value is None or colsize >= len(value)), 'colsize=%s value=%s' % (colsize, (value is None) and 'none' or len(value))
if colsize:
sql = "create table t1(n1 int not null, s1 %s(%s), s2 %s(%s))" % (sqltype, colsize, sqltype, colsize)
else:
sql = "create table t1(n1 int not null, s1 %s, s2 %s)" % (sqltype, sqltype)
self.cursor.execute(sql)
self.cursor.execute("insert into t1 values(1, ?, ?)", (value, value))
row = self.cursor.execute("select s1, s2 from t1").fetchone()
# Access only uses Unicode, but strings might have been passed in to see if they can be written. When we read
# them back, they'll be unicode, so compare our results to a Unicode version of `value`.
if type(value) is str:
value = unicode(value)
for i in range(2):
v = row[i]
self.assertEqual(type(v), type(value))
if value is not None:
self.assertEqual(len(v), len(value))
self.assertEqual(v, value)
#
# unicode
#
def test_unicode_null(self):
self._test_strtype('varchar', None, 255)
# Generate a test for each fencepost size: test_varchar_0, etc.
def _maketest(value):
def t(self):
self._test_strtype('varchar', value, len(value))
t.__doc__ = 'unicode %s' % len(value)
return t
for value in UNICODE_FENCEPOSTS:
locals()['test_unicode_%s' % len(value)] = _maketest(value)
#
# ansi -> varchar
#
# Access only stores Unicode text but it should accept ASCII text.
# Generate a test for each fencepost size: test_varchar_0, etc.
def _maketest(value):
def t(self):
self._test_strtype('varchar', value, len(value))
t.__doc__ = 'ansi %s' % len(value)
return t
for value in ANSI_FENCEPOSTS:
locals()['test_ansivarchar_%s' % len(value)] = _maketest(value)
#
# binary
#
# Generate a test for each fencepost size: test_varchar_0, etc.
def _maketest(value):
def t(self):
self._test_strtype('varbinary', buffer(value), len(value))
t.__doc__ = 'binary %s' % len(value)
return t
for value in ANSI_FENCEPOSTS:
locals()['test_binary_%s' % len(value)] = _maketest(value)
#
# image
#
def test_null_image(self):
self._test_strtype('image', None)
# Generate a test for each fencepost size: test_varchar_0, etc.
def _maketest(value):
def t(self):
self._test_strtype('image', buffer(value))
t.__doc__ = 'image %s' % len(value)
return t
for value in IMAGE_FENCEPOSTS:
locals()['test_image_%s' % len(value)] = _maketest(value)
#
# memo
#
def test_null_memo(self):
self._test_strtype('memo', None)
# Generate a test for each fencepost size: test_varchar_0, etc.
def _maketest(value):
def t(self):
self._test_strtype('memo', unicode(value))
t.__doc__ = 'Unicode to memo %s' % len(value)
return t
for value in IMAGE_FENCEPOSTS:
locals()['test_memo_%s' % len(value)] = _maketest(value)
# ansi -> memo
def _maketest(value):
def t(self):
self._test_strtype('memo', value)
t.__doc__ = 'ANSI to memo %s' % len(value)
return t
for value in IMAGE_FENCEPOSTS:
locals()['test_ansimemo_%s' % len(value)] = _maketest(value)
def test_subquery_params(self):
"""Ensure parameter markers work in a subquery"""
self.cursor.execute("create table t1(id integer, s varchar(20))")
self.cursor.execute("insert into t1 values (?,?)", 1, 'test')
row = self.cursor.execute("""
select x.id
from (
select id
from t1
where s = ?
and id between ? and ?
) x
""", 'test', 1, 10).fetchone()
self.assertNotEqual(row, None)
self.assertEqual(row[0], 1)
def _exec(self):
self.cursor.execute(self.sql)
def test_close_cnxn(self):
"""Make sure using a Cursor after closing its connection doesn't crash."""
self.cursor.execute("create table t1(id integer, s varchar(20))")
self.cursor.execute("insert into t1 values (?,?)", 1, 'test')
self.cursor.execute("select * from t1")
self.cnxn.close()
# Now that the connection is closed, we expect an exception. (If the code attempts to use
# the HSTMT, we'll get an access violation instead.)
self.sql = "select * from t1"
self.assertRaises(pyodbc.ProgrammingError, self._exec)
def test_unicode_query(self):
self.cursor.execute(u"select 1")
def test_negative_row_index(self):
self.cursor.execute("create table t1(s varchar(20))")
self.cursor.execute("insert into t1 values(?)", "1")
row = self.cursor.execute("select * from t1").fetchone()
self.assertEquals(row[0], "1")
self.assertEquals(row[-1], "1")
def test_version(self):
self.assertEquals(3, len(pyodbc.version.split('.'))) # 1.3.1 etc.
#
# date, time, datetime
#
def test_datetime(self):
value = datetime(2007, 1, 15, 3, 4, 5)
self.cursor.execute("create table t1(dt datetime)")
self.cursor.execute("insert into t1 values (?)", value)
result = self.cursor.execute("select dt from t1").fetchone()[0]
self.assertEquals(value, result)
#
# ints and floats
#
def test_int(self):
value = 1234
self.cursor.execute("create table t1(n int)")
self.cursor.execute("insert into t1 values (?)", value)
result = self.cursor.execute("select n from t1").fetchone()[0]
self.assertEquals(result, value)
def test_negative_int(self):
value = -1
self.cursor.execute("create table t1(n int)")
self.cursor.execute("insert into t1 values (?)", value)
result = self.cursor.execute("select n from t1").fetchone()[0]
self.assertEquals(result, value)
def test_smallint(self):
value = 32767
self.cursor.execute("create table t1(n smallint)")
self.cursor.execute("insert into t1 values (?)", value)
result = self.cursor.execute("select n from t1").fetchone()[0]
self.assertEquals(result, value)
def test_real(self):
value = 1234.5
self.cursor.execute("create table t1(n real)")
self.cursor.execute("insert into t1 values (?)", value)
result = self.cursor.execute("select n from t1").fetchone()[0]
self.assertEquals(result, value)
def test_negative_real(self):
value = -200.5
self.cursor.execute("create table t1(n real)")
self.cursor.execute("insert into t1 values (?)", value)
result = self.cursor.execute("select n from t1").fetchone()[0]
self.assertEqual(value, result)
def test_float(self):
value = 1234.567
self.cursor.execute("create table t1(n float)")
self.cursor.execute("insert into t1 values (?)", value)
result = self.cursor.execute("select n from t1").fetchone()[0]
self.assertEquals(result, value)
def test_negative_float(self):
value = -200.5
self.cursor.execute("create table t1(n float)")
self.cursor.execute("insert into t1 values (?)", value)
result = self.cursor.execute("select n from t1").fetchone()[0]
self.assertEqual(value, result)
def test_tinyint(self):
self.cursor.execute("create table t1(n tinyint)")
value = 10
self.cursor.execute("insert into t1 values (?)", value)
result = self.cursor.execute("select n from t1").fetchone()[0]
self.assertEqual(type(result), type(value))
self.assertEqual(value, result)
#
# decimal & money
#
def test_decimal(self):
value = Decimal('12345.6789')
self.cursor.execute("create table t1(n numeric(10,4))")
self.cursor.execute("insert into t1 values(?)", value)
v = self.cursor.execute("select n from t1").fetchone()[0]
self.assertEqual(type(v), Decimal)
self.assertEqual(v, value)
def test_money(self):
self.cursor.execute("create table t1(n money)")
value = Decimal('1234.45')
self.cursor.execute("insert into t1 values (?)", value)
result = self.cursor.execute("select n from t1").fetchone()[0]
self.assertEqual(type(result), type(value))
self.assertEqual(value, result)
def test_negative_decimal_scale(self):
value = Decimal('-10.0010')
self.cursor.execute("create table t1(d numeric(19,4))")
self.cursor.execute("insert into t1 values(?)", value)
v = self.cursor.execute("select * from t1").fetchone()[0]
self.assertEqual(type(v), Decimal)
self.assertEqual(v, value)
#
# bit
#
def test_bit(self):
self.cursor.execute("create table t1(b bit)")
value = True
self.cursor.execute("insert into t1 values (?)", value)
result = self.cursor.execute("select b from t1").fetchone()[0]
self.assertEqual(type(result), bool)
self.assertEqual(value, result)
def test_bit_null(self):
self.cursor.execute("create table t1(b bit)")
value = None
self.cursor.execute("insert into t1 values (?)", value)
result = self.cursor.execute("select b from t1").fetchone()[0]
self.assertEqual(type(result), bool)
self.assertEqual(False, result)
def test_guid(self):
# REVIEW: Python doesn't (yet) have a UUID type so the value is returned as a string. Access, however, only
# really supports Unicode. For now, we'll have to live with this difference. All strings in Python 3.x will
# be Unicode -- pyodbc 3.x will have different defaults.
value = "de2ac9c6-8676-4b0b-b8a6-217a8580cbee"
self.cursor.execute("create table t1(g1 uniqueidentifier)")
self.cursor.execute("insert into t1 values (?)", value)
v = self.cursor.execute("select * from t1").fetchone()[0]
self.assertEqual(type(v), type(value))
self.assertEqual(len(v), len(value))
#
# rowcount
#
def test_rowcount_delete(self):
self.assertEquals(self.cursor.rowcount, -1)
self.cursor.execute("create table t1(i int)")
count = 4
for i in range(count):
self.cursor.execute("insert into t1 values (?)", i)
self.cursor.execute("delete from t1")
self.assertEquals(self.cursor.rowcount, count)
def test_rowcount_nodata(self):
"""
This represents a different code path than a delete that deleted something.
The return value is SQL_NO_DATA and code after it was causing an error. We could use SQL_NO_DATA to step over
the code that errors out and drop down to the same SQLRowCount code. On the other hand, we could hardcode a
zero return value.
"""
self.cursor.execute("create table t1(i int)")
# This is a different code path internally.
self.cursor.execute("delete from t1")
self.assertEquals(self.cursor.rowcount, 0)
def test_rowcount_select(self):
"""
Ensure Cursor.rowcount is set properly after a select statement.
pyodbc calls SQLRowCount after each execute and sets Cursor.rowcount, but SQL Server 2005 returns -1 after a
select statement, so we'll test for that behavior. This is valid behavior according to the DB API
specification, but people don't seem to like it.
"""
self.cursor.execute("create table t1(i int)")
count = 4
for i in range(count):
self.cursor.execute("insert into t1 values (?)", i)
self.cursor.execute("select * from t1")
self.assertEquals(self.cursor.rowcount, -1)
rows = self.cursor.fetchall()
self.assertEquals(len(rows), count)
self.assertEquals(self.cursor.rowcount, -1)
def test_rowcount_reset(self):
"Ensure rowcount is reset to -1"
self.cursor.execute("create table t1(i int)")
count = 4
for i in range(count):
self.cursor.execute("insert into t1 values (?)", i)
self.assertEquals(self.cursor.rowcount, 1)
self.cursor.execute("create table t2(i int)")
self.assertEquals(self.cursor.rowcount, -1)
#
# Misc
#
def test_lower_case(self):
"Ensure pyodbc.lowercase forces returned column names to lowercase."
# Has to be set before creating the cursor, so we must recreate self.cursor.
pyodbc.lowercase = True
self.cursor = self.cnxn.cursor()
self.cursor.execute("create table t1(Abc int, dEf int)")
self.cursor.execute("select * from t1")
names = [ t[0] for t in self.cursor.description ]
names.sort()
self.assertEquals(names, [ "abc", "def" ])
# Put it back so other tests don't fail.
pyodbc.lowercase = False
def test_row_description(self):
"""
Ensure Cursor.description is accessible as Row.cursor_description.
"""
self.cursor = self.cnxn.cursor()
self.cursor.execute("create table t1(a int, b char(3))")
self.cnxn.commit()
self.cursor.execute("insert into t1 values(1, 'abc')")
row = self.cursor.execute("select * from t1").fetchone()
self.assertEquals(self.cursor.description, row.cursor_description)
def test_executemany(self):
self.cursor.execute("create table t1(a int, b varchar(10))")
params = [ (i, str(i)) for i in range(1, 6) ]
self.cursor.executemany("insert into t1(a, b) values (?,?)", params)
count = self.cursor.execute("select count(*) from t1").fetchone()[0]
self.assertEqual(count, len(params))
self.cursor.execute("select a, b from t1 order by a")
rows = self.cursor.fetchall()
self.assertEqual(count, len(rows))
for param, row in zip(params, rows):
self.assertEqual(param[0], row[0])
self.assertEqual(param[1], row[1])
def test_executemany_failure(self):
"""
Ensure that an exception is raised if one query in an executemany fails.
"""
self.cursor.execute("create table t1(a int, b varchar(10))")
params = [ (1, 'good'),
('error', 'not an int'),
(3, 'good') ]
self.failUnlessRaises(pyodbc.Error, self.cursor.executemany, "insert into t1(a, b) value (?, ?)", params)
def test_row_slicing(self):
self.cursor.execute("create table t1(a int, b int, c int, d int)");
self.cursor.execute("insert into t1 values(1,2,3,4)")
row = self.cursor.execute("select * from t1").fetchone()
result = row[:]
self.failUnless(result is row)
result = row[:-1]
self.assertEqual(result, (1,2,3))
result = row[0:4]
self.failUnless(result is row)
def test_row_repr(self):
self.cursor.execute("create table t1(a int, b int, c int, d int)");
self.cursor.execute("insert into t1 values(1,2,3,4)")
row = self.cursor.execute("select * from t1").fetchone()
result = str(row)
self.assertEqual(result, "(1, 2, 3, 4)")
result = str(row[:-1])
self.assertEqual(result, "(1, 2, 3)")
result = str(row[:1])
self.assertEqual(result, "(1,)")
def test_concatenation(self):
v2 = u'0123456789' * 25
v3 = u'9876543210' * 25
value = v2 + 'x' + v3
self.cursor.execute("create table t1(c2 varchar(250), c3 varchar(250))")
self.cursor.execute("insert into t1(c2, c3) values (?,?)", v2, v3)
row = self.cursor.execute("select c2 + 'x' + c3 from t1").fetchone()
self.assertEqual(row[0], value)
def test_autocommit(self):
self.assertEqual(self.cnxn.autocommit, False)
othercnxn = pyodbc.connect(CNXNSTRING, autocommit=True)
self.assertEqual(othercnxn.autocommit, True)
othercnxn.autocommit = False
self.assertEqual(othercnxn.autocommit, False)
def main():
from optparse import OptionParser
parser = OptionParser(usage=usage)
parser.add_option("-v", "--verbose", action="count", help="Increment test verbosity (can be used multiple times)")
parser.add_option("-d", "--debug", action="store_true", default=False, help="Print debugging items")
parser.add_option("-t", "--test", help="Run only the named test")
(options, args) = parser.parse_args()
if len(args) != 1:
parser.error('dbfile argument required')
if args[0].endswith('.accdb'):
driver = 'Microsoft Access Driver (*.mdb, *.accdb)'
else:
driver = 'Microsoft Access Driver (*.mdb)'
global CNXNSTRING
CNXNSTRING = 'DRIVER={%s};DBQ=%s;ExtendedAnsiSQL=1' % (driver, abspath(args[0]))
cnxn = pyodbc.connect(CNXNSTRING)
print_library_info(cnxn)
cnxn.close()
suite = load_tests(AccessTestCase, options.test)
testRunner = unittest.TextTestRunner(verbosity=options.verbose)
result = testRunner.run(suite)
if __name__ == '__main__':
# Add the build directory to the path so we're testing the latest build, not the installed version.
add_to_path()
import pyodbc
main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3807,
11916,
60,
199,
3807,
26,
450,
6595,
359,
1419,
61,
1788,
199,
199,
5072,
2295,
367,
15332,
11003,
199,
199,
20676,
1255,
1808,
314,
1015,
687,
314,
283,
1506,
7,
2082,
12,
440,
314,
1015,
199,
7657,
1901,
314,
2018,
6602,
14,
221,
2047,
1471,
1255,
2366,
3272,
14,
647,
1900,
199,
5182,
3879,
314,
2295,
14,
199,
199,
1378,
1255,
12,
986,
314,
1788,
402,
376,
11003,
3050,
641,
314,
1414,
1004,
26,
819,
2879,
2219,
511,
14,
5470,
697,
199,
199,
2493,
2701,
11003,
12293,
3050,
334,
1667,
14,
77,
697,
9,
436,
376,
2701,
11003,
10219,
3050,
199,
8,
1667,
14,
5470,
697,
395,
787,
2741,
14,
199,
199,
1378,
1255,
282,
2849,
511,
12,
675,
314,
446,
84,
945,
26,
819,
2879,
2219,
511,
14,
5470,
697,
446,
84,
2649,
63,
2307,
199,
199,
3917,
1265,
2934,
370,
3622,
376,
1125,
12,
652,
3955,
506,
24606,
370,
2387,
314,
5253,
2556,
199,
991,
1808,
314,
3376,
3305,
436,
4660,
316,
314,
1072,
370,
282,
570,
26,
421,
2879,
2219,
511,
14,
5470,
697,
446,
86,
690,
6,
2058,
14,
2424,
199,
199,
5556,
883,
986,
314,
3376,
3305,
13373,
367,
1655,
3376,
1072,
26,
421,
2879,
2219,
511,
14,
5470,
697,
446,
8958,
199,
624,
199,
199,
3,
11003,
5385,
666,
2943,
26,
1455,
921,
706,
4272,
18,
14,
17040,
14,
957,
15,
287,
13,
527,
15,
4342,
15,
2501,
10630,
13465,
14,
26146,
199,
199,
646,
984,
12,
747,
12,
295,
199,
646,
2882,
199,
504,
6107,
492,
6345,
199,
504,
2197,
492,
2197,
12,
1434,
12,
900,
199,
504,
747,
14,
515,
492,
19529,
199,
504,
511,
1208,
492,
627,
199,
199,
12874,
56,
46,
5353,
275,
488,
199,
199,
63,
2864,
3027,
275,
283,
11371,
13,
23459,
15668,
199,
199,
318,
485,
4208,
63,
396,
63,
875,
8,
1267,
304,
272,
408,
272,
1803,
282,
1059,
402,
26356,
402,
658,
5176,
64,
370,
1852,
282,
1059,
658,
1267,
64,
4110,
1846,
14,
339,
4005,
655,
14666,
10238,
12,
2337,
787,
650,
15217,
666,
365,
1586,
12,
4079,
641,
314,
2582,
402,
314,
574,
12,
880,
4750,
666,
2943,
787,
272,
12470,
543,
650,
17464,
14,
221,
961,
805,
22577,
2739,
3550,
314,
511,
666,
14,
339,
2136,
675,
282,
17319,
14065,
666,
663,
3140,
402,
282,
2849,
4528,
370,
1852,
652,
6656,
12060,
626,
298,
16736,
2,
2552,
911,
272,
506,
8752,
436,
370,
1720,
2739,
10250,
10405,
2382,
282,
2059,
11058,
14,
272,
408,
272,
340,
2582,
2695,
822,
1547,
2864,
3027,
304,
267,
372,
485,
2864,
3027,
1491,
1267,
61,
339,
286,
275,
334,
1267,
435,
822,
1547,
2864,
3027,
7216,
17,
9,
1182,
822,
1547,
2864,
3027,
9,
272,
373,
275,
485,
2864,
3027,
627,
286,
272,
372,
373,
1491,
1267,
61,
421,
199,
533,
11003,
1746,
8,
2796,
14,
1746,
304,
339,
2516,
63,
38,
6013,
4030,
63,
2684,
58,
654,
275,
359,
378,
12,
413,
12,
22540,
12,
5450,
1622,
327,
1318,
1504,
2695,
5450,
272,
491,
689,
4962,
63,
38,
6013,
4030,
63,
2684,
58,
654,
275,
359,
7633,
12,
27632,
12,
20398,
12,
959,
2036,
12,
959,
709,
12,
959,
845,
12,
10574,
12,
12996,
19,
12,
6619,
12,
499,
12931,
12,
18427,
12,
31092,
12,
841,
19113,
12,
17125,
12,
841,
17790,
12,
1616,
627,
6619,
12,
3388,
627,
6619,
1622,
339,
25600,
63,
38,
6013,
4030,
51,
259,
275,
359,
485,
4208,
63,
396,
63,
875,
8,
890,
9,
367,
1568,
315,
2516,
63,
38,
6013,
4030,
63,
2684,
58,
654,
1622,
272,
6778,
948,
9125,
63,
38,
6013,
4030,
51,
275,
359,
2649,
8,
83,
9,
367,
308,
315,
25600,
63,
38,
6013,
4030,
51,
1622,
272,
25228,
63,
38,
6013,
4030,
51,
257,
275,
25600,
63,
38,
6013,
4030,
51,
435,
359,
485,
4208,
63,
396,
63,
875,
8,
890,
9,
367,
1568,
315,
491,
689,
4962,
63,
38,
6013,
4030,
63,
2684,
58,
654,
1622,
339,
347,
636,
826,
721,
277,
12,
1083,
63,
354,
304,
267,
2882,
14,
1746,
855,
826,
721,
277,
12,
1083,
63,
354,
9,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
6413,
5032,
257,
275,
1134,
19887,
14,
2242,
8,
12874,
56,
46,
5353,
9,
267,
291,
14,
3937,
275,
291,
14,
6413,
5032,
14,
3937,
342,
398,
367,
284,
315,
1425,
8,
19,
304,
288,
862,
26,
355,
291,
14,
3937,
14,
2526,
480,
4824,
1817,
307,
5,
68,
2,
450,
284,
9,
355,
291,
14,
6413,
5032,
14,
3543,
342,
288,
871,
26,
355,
986,
398,
291,
14,
6413,
5032,
14,
10437,
342,
339,
347,
6766,
8,
277,
304,
267,
862,
26,
288,
291,
14,
3937,
14,
1600,
342,
288,
291,
14,
6413,
5032,
14,
1600,
342,
267,
871,
26,
288,
327,
982,
781,
9064,
2575,
6876,
314,
3920,
503,
1950,
12,
4967,
787,
14031,
14,
288,
986,
339,
347,
511,
63,
6048,
63,
10880,
8,
277,
304,
267,
298,
11053,
2419,
1373,
5398,
436,
3504,
641,
282,
3920,
2,
267,
291,
14,
3937,
14,
2526,
480,
981,
1817,
307,
17,
8,
78,
1109,
6320,
267,
291,
14,
3937,
14,
2526,
480,
3176,
1901,
307,
17,
1338,
7558,
4186,
413,
9,
267,
291,
14,
3937,
14,
2526,
480,
3176,
1901,
307,
17,
1338,
7558,
4186,
499,
9,
267,
291,
14,
3937,
14,
2526,
480,
3176,
1901,
307,
17,
1338,
7558,
4186,
650,
9,
267,
367,
284,
315,
1425,
8,
19,
304,
288,
291,
14,
3937,
14,
2526,
480,
2416,
302,
687,
307,
17,
2382,
302,
665,
5805,
401,
1616,
9,
288,
291,
14,
3937,
14,
2526,
480,
2416,
302,
687,
307,
17,
2382,
302,
665,
650,
531,
268,
339,
347,
511,
63,
14020,
63,
10880,
8,
277,
304,
267,
291,
14,
3937,
14,
2526,
480,
981,
1817,
307,
17,
8,
78,
1109,
6320,
267,
291,
14,
3937,
14,
2526,
480,
981,
1817,
307,
18,
8,
68,
2197,
6320,
267,
291,
14,
3937,
14,
2526,
480,
3176,
1901,
307,
17,
1338,
7558,
4186,
413,
9,
267,
291,
14,
3937,
14,
2526,
480,
3176,
1901,
307,
18,
1338,
7558,
4186,
2197,
14,
2131,
1012,
339,
347,
511,
63,
21208
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3807,
11916,
60,
199,
3807,
26,
450,
6595,
359,
1419,
61,
1788,
199,
199,
5072,
2295,
367,
15332,
11003,
199,
199,
20676,
1255,
1808,
314,
1015,
687,
314,
283,
1506,
7,
2082,
12,
440,
314,
1015,
199,
7657,
1901,
314,
2018,
6602,
14,
221,
2047,
1471,
1255,
2366,
3272,
14,
647,
1900,
199,
5182,
3879,
314,
2295,
14,
199,
199,
1378,
1255,
12,
986,
314,
1788,
402,
376,
11003,
3050,
641,
314,
1414,
1004,
26,
819,
2879,
2219,
511,
14,
5470,
697,
199,
199,
2493,
2701,
11003,
12293,
3050,
334,
1667,
14,
77,
697,
9,
436,
376,
2701,
11003,
10219,
3050,
199,
8,
1667,
14,
5470,
697,
395,
787,
2741,
14,
199,
199,
1378,
1255,
282,
2849,
511,
12,
675,
314,
446,
84,
945,
26,
819,
2879,
2219,
511,
14,
5470,
697,
446,
84,
2649,
63,
2307,
199,
199,
3917,
1265,
2934,
370,
3622,
376,
1125,
12,
652,
3955,
506,
24606,
370,
2387,
314,
5253,
2556,
199,
991,
1808,
314,
3376,
3305,
436,
4660,
316,
314,
1072,
370,
282,
570,
26,
421,
2879,
2219,
511,
14,
5470,
697,
446,
86,
690,
6,
2058,
14,
2424,
199,
199,
5556,
883,
986,
314,
3376,
3305,
13373,
367,
1655,
3376,
1072,
26,
421,
2879,
2219,
511,
14,
5470,
697,
446,
8958,
199,
624,
199,
199,
3,
11003,
5385,
666,
2943,
26,
1455,
921,
706,
4272,
18,
14,
17040,
14,
957,
15,
287,
13,
527,
15,
4342,
15,
2501,
10630,
13465,
14,
26146,
199,
199,
646,
984,
12,
747,
12,
295,
199,
646,
2882,
199,
504,
6107,
492,
6345,
199,
504,
2197,
492,
2197,
12,
1434,
12,
900,
199,
504,
747,
14,
515,
492,
19529,
199,
504,
511,
1208,
492,
627,
199,
199,
12874,
56,
46,
5353,
275,
488,
199,
199,
63,
2864,
3027,
275,
283,
11371,
13,
23459,
15668,
199,
199,
318,
485,
4208,
63,
396,
63,
875,
8,
1267,
304,
272,
408,
272,
1803,
282,
1059,
402,
26356,
402,
658,
5176,
64,
370,
1852,
282,
1059,
658,
1267,
64,
4110,
1846,
14,
339,
4005,
655,
14666,
10238,
12,
2337,
787,
650,
15217,
666,
365,
1586,
12,
4079,
641,
314,
2582,
402,
314,
574,
12,
880,
4750,
666,
2943,
787,
272,
12470,
543,
650,
17464,
14,
221,
961,
805,
22577,
2739,
3550,
314,
511,
666,
14,
339,
2136,
675,
282,
17319,
14065,
666,
663,
3140,
402,
282,
2849,
4528,
370,
1852,
652,
6656,
12060,
626,
298,
16736,
2,
2552,
911,
272,
506,
8752,
436,
370,
1720,
2739,
10250,
10405,
2382,
282,
2059,
11058,
14,
272,
408,
272,
340,
2582,
2695,
822,
1547,
2864,
3027,
304,
267,
372,
485,
2864,
3027,
1491,
1267,
61,
339,
286,
275,
334,
1267,
435,
822,
1547,
2864,
3027,
7216,
17,
9,
1182,
822,
1547,
2864,
3027,
9,
272,
373,
275,
485,
2864,
3027,
627,
286,
272,
372,
373,
1491,
1267,
61,
421,
199,
533,
11003,
1746,
8,
2796,
14,
1746,
304,
339,
2516,
63,
38,
6013,
4030,
63,
2684,
58,
654,
275,
359,
378,
12,
413,
12,
22540,
12,
5450,
1622,
327,
1318,
1504,
2695,
5450,
272,
491,
689,
4962,
63,
38,
6013,
4030,
63,
2684,
58,
654,
275,
359,
7633,
12,
27632,
12,
20398,
12,
959,
2036,
12,
959,
709,
12,
959,
845,
12,
10574,
12,
12996,
19,
12,
6619,
12,
499,
12931,
12,
18427,
12,
31092,
12,
841,
19113,
12,
17125,
12,
841,
17790,
12,
1616,
627,
6619,
12,
3388,
627,
6619,
1622,
339,
25600,
63,
38,
6013,
4030,
51,
259,
275,
359,
485,
4208,
63,
396,
63,
875,
8,
890,
9,
367,
1568,
315,
2516,
63,
38,
6013,
4030,
63,
2684,
58,
654,
1622,
272,
6778,
948,
9125,
63,
38,
6013,
4030,
51,
275,
359,
2649,
8,
83,
9,
367,
308,
315,
25600,
63,
38,
6013,
4030,
51,
1622,
272,
25228,
63,
38,
6013,
4030,
51,
257,
275,
25600,
63,
38,
6013,
4030,
51,
435,
359,
485,
4208,
63,
396,
63,
875,
8,
890,
9,
367,
1568,
315,
491,
689,
4962,
63,
38,
6013,
4030,
63,
2684,
58,
654,
1622,
339,
347,
636,
826,
721,
277,
12,
1083,
63,
354,
304,
267,
2882,
14,
1746,
855,
826,
721,
277,
12,
1083,
63,
354,
9,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
6413,
5032,
257,
275,
1134,
19887,
14,
2242,
8,
12874,
56,
46,
5353,
9,
267,
291,
14,
3937,
275,
291,
14,
6413,
5032,
14,
3937,
342,
398,
367,
284,
315,
1425,
8,
19,
304,
288,
862,
26,
355,
291,
14,
3937,
14,
2526,
480,
4824,
1817,
307,
5,
68,
2,
450,
284,
9,
355,
291,
14,
6413,
5032,
14,
3543,
342,
288,
871,
26,
355,
986,
398,
291,
14,
6413,
5032,
14,
10437,
342,
339,
347,
6766,
8,
277,
304,
267,
862,
26,
288,
291,
14,
3937,
14,
1600,
342,
288,
291,
14,
6413,
5032,
14,
1600,
342,
267,
871,
26,
288,
327,
982,
781,
9064,
2575,
6876,
314,
3920,
503,
1950,
12,
4967,
787,
14031,
14,
288,
986,
339,
347,
511,
63,
6048,
63,
10880,
8,
277,
304,
267,
298,
11053,
2419,
1373,
5398,
436,
3504,
641,
282,
3920,
2,
267,
291,
14,
3937,
14,
2526,
480,
981,
1817,
307,
17,
8,
78,
1109,
6320,
267,
291,
14,
3937,
14,
2526,
480,
3176,
1901,
307,
17,
1338,
7558,
4186,
413,
9,
267,
291,
14,
3937,
14,
2526,
480,
3176,
1901,
307,
17,
1338,
7558,
4186,
499,
9,
267,
291,
14,
3937,
14,
2526,
480,
3176,
1901,
307,
17,
1338,
7558,
4186,
650,
9,
267,
367,
284,
315,
1425,
8,
19,
304,
288,
291,
14,
3937,
14,
2526,
480,
2416,
302,
687,
307,
17,
2382,
302,
665,
5805,
401,
1616,
9,
288,
291,
14,
3937,
14,
2526,
480,
2416,
302,
687,
307,
17,
2382,
302,
665,
650,
531,
268,
339,
347,
511,
63,
14020,
63,
10880,
8,
277,
304,
267,
291,
14,
3937,
14,
2526,
480,
981,
1817,
307,
17,
8,
78,
1109,
6320,
267,
291,
14,
3937,
14,
2526,
480,
981,
1817,
307,
18,
8,
68,
2197,
6320,
267,
291,
14,
3937,
14,
2526,
480,
3176,
1901,
307,
17,
1338,
7558,
4186,
413,
9,
267,
291,
14,
3937,
14,
2526,
480,
3176,
1901,
307,
18,
1338,
7558,
4186,
2197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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Wonjuseo/Project101
|
1/1-3. Deep Neural Network.py
|
1
|
2311
|
# tensorflow, numpy를 사용하기위해 import
import tensorflow as tf
import numpy as np
# Deep learning을 위해 데이터를 읽습니다.
data = np.loadtxt('./data.csv',delimiter=',',unpack=True,dtype='float32')
# csv자료의 0부터 2번째 까지의 feature를 x_data에 넣습니다.
# 나머지는 분류가 되는 데이터로 y_data에 넣습니다.
x_data = np.transpose(data[0:3])
y_data = np.transpose(data[3:])
# Step 1 Neural network
# x_data, y_data를 저장하기위해 X, Y를 placeholder형태로 선언해줍니다.
X = tf.placeholder(tf.float32)
Y = tf.placeholder(tf.float32)
# 3층의 weights를 선언합니다. (1 x 3) x (3 x 50) x (50 x 100) x (100 x 3) = (1 x 3)
W1 = tf.Variable(tf.random_uniform([3,50],-1.,1.))
W2 = tf.Variable(tf.random_uniform([50,100],-1.,1.))
W3 = tf.Variable(tf.random_uniform([100,3],-1.,1.))
# 3층의 layer를 선언합니다. Classification 경우로 0~1 값이 나오도록 Sigmoid 함수를 사용합니다.
L1 = tf.sigmoid(tf.matmul(X,W1))
L2 = tf.sigmoid(tf.matmul(L1,W2))
L3 = tf.matmul(L2,W3)
# 3개의 점수 A,B,C 중에서 하나를 고르는 것이므로 cost function을 softmax_cross_entropy 함수로 정한다.
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=L3,labels= Y))
# 0.001 learning_rate로 Global minimum을 찾는다.
optimizer = tf.train.AdamOptimizer(learning_rate=0.001)
train = optimizer.minimize(cost)
# Session을 선언한다.
with tf.Session() as sess:
# 변수들을 초기화 한다.
init = tf.global_variables_initializer()
sess.run(init)
# 총 20001번을 Train 한다.
for step in range(20001):
sess.run(train, feed_dict={X: x_data, Y: y_data})
# step이 1000번이 될때마다 현재 cost를 보여준다.
if step % 1000 == 0:
print (step, sess.run(cost, feed_dict={X: x_data, Y: y_data}))
# 학습 이후에 데이터를 넣었을 때에 결과가 어떻게 나오는지를 확인한다.
pred = tf.argmax(L3,1)
real = tf.argmax(Y,1)
print("Prediction:",sess.run(pred,feed_dict={X:x_data}))
print("Real:",sess.run(real, feed_dict={Y:y_data}))
#세 과목에서 80, 80, 80점을 받았을 때의 결과를 보여준다.
print("Grade: ",sess.run(pred,feed_dict={X:[[80,80,80]]}))
|
apache-2.0
|
[
3,
3228,
12,
2680,
168,
99,
121,
10148,
225,
106,
32072,
103,
17272,
247,
167,
117,
109,
169,
251,
227,
17272,
113,
492,
199,
199,
646,
3228,
465,
2833,
199,
646,
2680,
465,
980,
199,
199,
3,
577,
7840,
9328,
16439,
227,
10148,
251,
227,
17272,
113,
16002,
236,
109,
31888,
170,
227,
109,
168,
99,
121,
10148,
252,
122,
169,
233,
114,
21048,
231,
31503,
14,
199,
576,
275,
980,
14,
27992,
17371,
576,
14,
4737,
297,
15104,
4009,
297,
5301,
29,
549,
12,
2271,
534,
1609,
708,
358,
199,
199,
3,
7392,
31236,
239,
168,
97,
235,
16439,
247,
378,
168,
115,
223,
170,
227,
109,
499,
168,
111,
231,
32704,
117,
28962,
118,
235,
32704,
223,
16439,
247,
3878,
168,
99,
121,
671,
63,
576,
28739,
239,
16002,
227,
97,
169,
233,
114,
21048,
231,
31503,
14,
199,
3,
16002,
225,
247,
168,
102,
117,
32704,
223,
168,
233,
243,
16002,
115,
227,
168,
99,
247,
28733,
16002,
239,
247,
168,
233,
243,
16002,
236,
109,
31888,
170,
227,
109,
29985,
251,
612,
63,
576,
28739,
239,
16002,
227,
97,
169,
233,
114,
21048,
231,
31503,
14,
199,
88,
63,
576,
275,
980,
14,
10483,
8,
576,
59,
16,
26,
19,
566,
199,
89,
63,
576,
275,
980,
14,
10483,
8,
576,
59,
19,
5728,
199,
199,
3,
13382,
413,
5612,
4889,
2784,
199,
3,
671,
63,
576,
12,
612,
63,
576,
168,
99,
121,
10148,
255,
223,
31236,
99,
17272,
247,
167,
117,
109,
169,
251,
227,
17272,
113,
1323,
12,
1488,
168,
99,
121,
10069,
170,
247,
244,
170,
226,
251,
29985,
251,
10148,
227,
255,
169,
245,
117,
17272,
113,
169,
98,
236,
21048,
231,
31503,
14,
199,
56,
275,
2833,
14,
6199,
8,
3249,
14,
1609,
708,
9,
199,
57,
275,
2833,
14,
6199,
8,
3249,
14,
1609,
708,
9,
199,
199,
3,
650,
169,
117,
114,
16439,
247,
4931,
168,
99,
121,
10148,
227,
255,
169,
245,
117,
17272,
103,
21048,
231,
31503,
14,
334,
17,
671,
650,
9,
671,
334,
19,
671,
5238,
9,
671,
334,
1400,
671,
2948,
9,
671,
334,
1960,
671,
650,
9,
275,
334,
17,
671,
650,
9,
199,
55,
17,
275,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
8830,
779,
19,
12,
1400,
467,
13,
17,
2020,
17,
26273,
199,
55,
18,
275,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
8830,
779,
1400,
12,
1960,
467,
13,
17,
2020,
17,
26273,
199,
55,
19,
275,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
8830,
779,
1960,
12,
19,
467,
13,
17,
2020,
17,
26273,
199,
199,
3,
650,
169,
117,
114,
16439,
247,
4045,
168,
99,
121,
10148,
227,
255,
169,
245,
117,
17272,
103,
21048,
231,
31503,
14,
8465,
7789,
28962,
111,
122,
32072,
109,
29985,
251,
378,
94,
17,
221,
22247,
241,
31888,
16002,
225,
247,
169,
247,
98,
168,
238,
227,
29985,
252,
14625,
14356,
221,
17272,
102,
169,
231,
247,
168,
99,
121,
10148,
225,
106,
32072,
103,
17272,
103,
21048,
231,
31503,
14,
199,
44,
17,
275,
2833,
14,
20035,
8,
3249,
14,
14465,
8,
56,
12,
55,
17,
430,
199,
44,
18,
275,
2833,
14,
20035,
8,
3249,
14,
14465,
8,
44,
17,
12,
55,
18,
430,
199,
44,
19,
275,
2833,
14,
14465,
8,
44,
18,
12,
55,
19,
9,
199,
199,
3,
650,
22247,
251,
16439,
247,
10148,
255,
239,
169,
231,
247,
437,
12,
34,
12,
35,
10148,
98,
240,
28739,
239,
28790,
251,
221,
17272,
247,
168,
225,
247,
168,
99,
121,
28962,
112,
255,
168,
99,
113,
168,
233,
243,
28962,
111,
226,
31888,
168,
108,
223,
29985,
251,
7918,
805,
16439,
227,
28344,
63,
7925,
63,
10435,
221,
17272,
102,
169,
231,
247,
29985,
251,
10148,
255,
244,
17272,
251,
31503,
14,
199,
6336,
275,
2833,
14,
5270,
63,
3670,
8,
3249,
14,
4411,
14,
16395,
63,
7925,
63,
10435,
63,
1045,
63,
10492,
8,
10492,
29,
44,
19,
12,
3512,
29,
1488,
430,
199,
3,
378,
14,
4587,
9328,
63,
1866,
29985,
251,
13641,
7481,
16439,
227,
10148,
109,
123,
168,
233,
243,
31503,
14,
199,
12290,
275,
2833,
14,
2834,
14,
32408,
13946,
8,
10546,
63,
1866,
29,
16,
14,
4587,
9,
199,
2834,
275,
10736,
14,
19333,
8,
6336,
9,
199,
199,
3,
8596,
16439,
227,
10148,
227,
255,
169,
245,
117,
17272,
251,
31503,
14,
199,
1045,
2833,
14,
4434,
342,
465,
4043,
26,
272,
327,
16002,
112,
223,
169,
231,
247,
168,
242,
98,
16439,
227,
10148,
113,
231,
167,
117,
109,
170,
248,
243,
221,
17272,
251,
31503,
14,
272,
4205,
275,
2833,
14,
2966,
63,
3669,
63,
6498,
342,
272,
4043,
14,
1065,
8,
826,
9,
272,
327,
10148,
113,
252,
1926,
614,
168,
111,
231,
16439,
227,
16732,
221,
17272,
251,
31503,
14,
272,
367,
3650,
315,
1425,
8,
1840,
614,
304,
267,
4043,
14,
1065,
8,
2834,
12,
4733,
63,
807,
3126,
56,
26,
671,
63,
576,
12,
1488,
26,
612,
63,
576,
1552,
267,
327,
3650,
31888,
5198,
168,
111,
231,
31888,
16002,
239,
255,
168,
244,
235,
168,
101,
231,
31503,
26521,
247,
227,
31236,
106,
7918,
168,
99,
121,
16002,
112,
113,
28739,
106,
169,
98,
223,
31503,
14,
267,
340,
3650,
450,
5198,
508,
378,
26,
288,
870,
334,
2926,
12,
4043,
14,
1065,
8,
6336,
12,
4733,
63,
807,
3126,
56,
26,
671,
63,
576,
12,
1488,
26,
612,
63,
576,
12466,
5493,
327,
221,
17272,
248,
169,
233,
114,
10148,
252,
113,
170,
250,
227,
28739,
239,
16002,
236,
109,
31888,
170,
227,
109,
168,
99,
121,
16002,
227,
97,
28739,
231,
16439,
227,
16002,
244,
235,
28739,
239,
28962,
111,
109,
167,
112,
121,
28733,
10148,
245,
113,
168,
245,
120,
167,
111,
235,
16002,
225,
247,
169,
247,
98,
168,
233,
243,
32704,
223,
168,
99,
121,
26521,
248,
244,
16439,
117,
17272,
251,
31503,
14,
272,
8869,
275,
2833,
14,
16383,
8,
44,
19,
12,
17,
9,
272,
3363,
275,
2833,
14,
16383,
8,
57,
12,
17,
9,
339,
870,
480,
24261,
6783,
5480,
14,
1065,
8,
5991,
12,
3871,
63,
807,
3126,
56,
26,
88,
63,
576
] |
[
3228,
12,
2680,
168,
99,
121,
10148,
225,
106,
32072,
103,
17272,
247,
167,
117,
109,
169,
251,
227,
17272,
113,
492,
199,
199,
646,
3228,
465,
2833,
199,
646,
2680,
465,
980,
199,
199,
3,
577,
7840,
9328,
16439,
227,
10148,
251,
227,
17272,
113,
16002,
236,
109,
31888,
170,
227,
109,
168,
99,
121,
10148,
252,
122,
169,
233,
114,
21048,
231,
31503,
14,
199,
576,
275,
980,
14,
27992,
17371,
576,
14,
4737,
297,
15104,
4009,
297,
5301,
29,
549,
12,
2271,
534,
1609,
708,
358,
199,
199,
3,
7392,
31236,
239,
168,
97,
235,
16439,
247,
378,
168,
115,
223,
170,
227,
109,
499,
168,
111,
231,
32704,
117,
28962,
118,
235,
32704,
223,
16439,
247,
3878,
168,
99,
121,
671,
63,
576,
28739,
239,
16002,
227,
97,
169,
233,
114,
21048,
231,
31503,
14,
199,
3,
16002,
225,
247,
168,
102,
117,
32704,
223,
168,
233,
243,
16002,
115,
227,
168,
99,
247,
28733,
16002,
239,
247,
168,
233,
243,
16002,
236,
109,
31888,
170,
227,
109,
29985,
251,
612,
63,
576,
28739,
239,
16002,
227,
97,
169,
233,
114,
21048,
231,
31503,
14,
199,
88,
63,
576,
275,
980,
14,
10483,
8,
576,
59,
16,
26,
19,
566,
199,
89,
63,
576,
275,
980,
14,
10483,
8,
576,
59,
19,
5728,
199,
199,
3,
13382,
413,
5612,
4889,
2784,
199,
3,
671,
63,
576,
12,
612,
63,
576,
168,
99,
121,
10148,
255,
223,
31236,
99,
17272,
247,
167,
117,
109,
169,
251,
227,
17272,
113,
1323,
12,
1488,
168,
99,
121,
10069,
170,
247,
244,
170,
226,
251,
29985,
251,
10148,
227,
255,
169,
245,
117,
17272,
113,
169,
98,
236,
21048,
231,
31503,
14,
199,
56,
275,
2833,
14,
6199,
8,
3249,
14,
1609,
708,
9,
199,
57,
275,
2833,
14,
6199,
8,
3249,
14,
1609,
708,
9,
199,
199,
3,
650,
169,
117,
114,
16439,
247,
4931,
168,
99,
121,
10148,
227,
255,
169,
245,
117,
17272,
103,
21048,
231,
31503,
14,
334,
17,
671,
650,
9,
671,
334,
19,
671,
5238,
9,
671,
334,
1400,
671,
2948,
9,
671,
334,
1960,
671,
650,
9,
275,
334,
17,
671,
650,
9,
199,
55,
17,
275,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
8830,
779,
19,
12,
1400,
467,
13,
17,
2020,
17,
26273,
199,
55,
18,
275,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
8830,
779,
1400,
12,
1960,
467,
13,
17,
2020,
17,
26273,
199,
55,
19,
275,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
8830,
779,
1960,
12,
19,
467,
13,
17,
2020,
17,
26273,
199,
199,
3,
650,
169,
117,
114,
16439,
247,
4045,
168,
99,
121,
10148,
227,
255,
169,
245,
117,
17272,
103,
21048,
231,
31503,
14,
8465,
7789,
28962,
111,
122,
32072,
109,
29985,
251,
378,
94,
17,
221,
22247,
241,
31888,
16002,
225,
247,
169,
247,
98,
168,
238,
227,
29985,
252,
14625,
14356,
221,
17272,
102,
169,
231,
247,
168,
99,
121,
10148,
225,
106,
32072,
103,
17272,
103,
21048,
231,
31503,
14,
199,
44,
17,
275,
2833,
14,
20035,
8,
3249,
14,
14465,
8,
56,
12,
55,
17,
430,
199,
44,
18,
275,
2833,
14,
20035,
8,
3249,
14,
14465,
8,
44,
17,
12,
55,
18,
430,
199,
44,
19,
275,
2833,
14,
14465,
8,
44,
18,
12,
55,
19,
9,
199,
199,
3,
650,
22247,
251,
16439,
247,
10148,
255,
239,
169,
231,
247,
437,
12,
34,
12,
35,
10148,
98,
240,
28739,
239,
28790,
251,
221,
17272,
247,
168,
225,
247,
168,
99,
121,
28962,
112,
255,
168,
99,
113,
168,
233,
243,
28962,
111,
226,
31888,
168,
108,
223,
29985,
251,
7918,
805,
16439,
227,
28344,
63,
7925,
63,
10435,
221,
17272,
102,
169,
231,
247,
29985,
251,
10148,
255,
244,
17272,
251,
31503,
14,
199,
6336,
275,
2833,
14,
5270,
63,
3670,
8,
3249,
14,
4411,
14,
16395,
63,
7925,
63,
10435,
63,
1045,
63,
10492,
8,
10492,
29,
44,
19,
12,
3512,
29,
1488,
430,
199,
3,
378,
14,
4587,
9328,
63,
1866,
29985,
251,
13641,
7481,
16439,
227,
10148,
109,
123,
168,
233,
243,
31503,
14,
199,
12290,
275,
2833,
14,
2834,
14,
32408,
13946,
8,
10546,
63,
1866,
29,
16,
14,
4587,
9,
199,
2834,
275,
10736,
14,
19333,
8,
6336,
9,
199,
199,
3,
8596,
16439,
227,
10148,
227,
255,
169,
245,
117,
17272,
251,
31503,
14,
199,
1045,
2833,
14,
4434,
342,
465,
4043,
26,
272,
327,
16002,
112,
223,
169,
231,
247,
168,
242,
98,
16439,
227,
10148,
113,
231,
167,
117,
109,
170,
248,
243,
221,
17272,
251,
31503,
14,
272,
4205,
275,
2833,
14,
2966,
63,
3669,
63,
6498,
342,
272,
4043,
14,
1065,
8,
826,
9,
272,
327,
10148,
113,
252,
1926,
614,
168,
111,
231,
16439,
227,
16732,
221,
17272,
251,
31503,
14,
272,
367,
3650,
315,
1425,
8,
1840,
614,
304,
267,
4043,
14,
1065,
8,
2834,
12,
4733,
63,
807,
3126,
56,
26,
671,
63,
576,
12,
1488,
26,
612,
63,
576,
1552,
267,
327,
3650,
31888,
5198,
168,
111,
231,
31888,
16002,
239,
255,
168,
244,
235,
168,
101,
231,
31503,
26521,
247,
227,
31236,
106,
7918,
168,
99,
121,
16002,
112,
113,
28739,
106,
169,
98,
223,
31503,
14,
267,
340,
3650,
450,
5198,
508,
378,
26,
288,
870,
334,
2926,
12,
4043,
14,
1065,
8,
6336,
12,
4733,
63,
807,
3126,
56,
26,
671,
63,
576,
12,
1488,
26,
612,
63,
576,
12466,
5493,
327,
221,
17272,
248,
169,
233,
114,
10148,
252,
113,
170,
250,
227,
28739,
239,
16002,
236,
109,
31888,
170,
227,
109,
168,
99,
121,
16002,
227,
97,
28739,
231,
16439,
227,
16002,
244,
235,
28739,
239,
28962,
111,
109,
167,
112,
121,
28733,
10148,
245,
113,
168,
245,
120,
167,
111,
235,
16002,
225,
247,
169,
247,
98,
168,
233,
243,
32704,
223,
168,
99,
121,
26521,
248,
244,
16439,
117,
17272,
251,
31503,
14,
272,
8869,
275,
2833,
14,
16383,
8,
44,
19,
12,
17,
9,
272,
3363,
275,
2833,
14,
16383,
8,
57,
12,
17,
9,
339,
870,
480,
24261,
6783,
5480,
14,
1065,
8,
5991,
12,
3871,
63,
807,
3126,
56,
26,
88,
63,
576,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
akamensky/sssd
|
src/tests/intg/ent_test.py
|
1
|
15643
|
#
# ent.py module tests
#
# Copyright (c) 2015 Red Hat, Inc.
# Author: Nikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 only
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import re
import os
import io
import pytest
import ent
from util import *
@pytest.fixture(scope="module")
def passwd_path(request):
name = "NSS_WRAPPER_PASSWD"
request.addfinalizer(lambda: restore_envvar_file(name))
return backup_envvar_file(name)
@pytest.fixture(scope="module")
def group_path(request):
name = "NSS_WRAPPER_GROUP"
request.addfinalizer(lambda: restore_envvar_file(name))
return backup_envvar_file(name)
USER1 = dict(name="user1", passwd="x", uid=1001, gid=2001,
gecos="User 1", dir="/home/user1", shell="/bin/bash")
USER2 = dict(name="user2", passwd="x", uid=1002, gid=2002,
gecos="User 2", dir="/home/user2", shell="/bin/bash")
USER_LIST = [USER1, USER2]
USER_NAME_DICT = dict((u["name"], u) for u in USER_LIST)
USER_UID_DICT = dict((u["uid"], u) for u in USER_LIST)
EMPTY_GROUP = dict(name="empty_group", passwd="x", gid=2000,
mem=ent.contains_only())
GROUP1 = dict(name="group1", passwd="x", gid=2001,
mem=ent.contains_only())
GROUP2 = dict(name="group2", passwd="x", gid=2002,
mem=ent.contains_only())
ONE_USER_GROUP1 = dict(name="one_user_group1", passwd="x", gid=2011,
mem=ent.contains_only("user1"))
ONE_USER_GROUP2 = dict(name="one_user_group2", passwd="x", gid=2012,
mem=ent.contains_only("user2"))
TWO_USER_GROUP = dict(name="two_user_group", passwd="x", gid=2020,
mem=ent.contains_only("user1", "user2"))
GROUP_LIST = [EMPTY_GROUP,
GROUP1,
GROUP2,
ONE_USER_GROUP1,
ONE_USER_GROUP2,
TWO_USER_GROUP]
GROUP_NAME_DICT = dict((g["name"], g) for g in GROUP_LIST)
GROUP_GID_DICT = dict((g["gid"], g) for g in GROUP_LIST)
@pytest.fixture(scope="module")
def users_and_groups(request, passwd_path, group_path):
passwd_contents = "".join([
"{name}:{passwd}:{uid}:{gid}:{gecos}:{dir}:{shell}\n".format(**u)
for u in USER_LIST
])
group_contents = "".join([
"%s:%s:%s:%s\n" % (g["name"], g["passwd"], g["gid"],
",".join(g["mem"]))
for g in GROUP_LIST
])
with open(passwd_path, "a") as f:
f.write(passwd_contents)
with open(group_path, "a") as f:
f.write(group_contents)
def test_assert_passwd_by_name(users_and_groups):
ent.assert_passwd_by_name("user1", {})
ent.assert_passwd_by_name("user1", dict(name="user1", uid=1001))
ent.assert_passwd_by_name("user1", USER1)
try:
ent.assert_passwd_by_name("user3", {})
assert False
except AssertionError as e:
assert str(e) == "'getpwnam(): name not found: user3'"
try:
ent.assert_passwd_by_name("user2", dict(name="user1"))
assert False
except AssertionError as e:
assert str(e) == "'name' mismatch: 'user1' != 'user2'"
def test_assert_passwd_by_uid(users_and_groups):
ent.assert_passwd_by_uid(1001, {})
ent.assert_passwd_by_uid(1001, dict(name="user1", uid=1001))
ent.assert_passwd_by_uid(1001, USER1)
try:
ent.assert_passwd_by_uid(1003, {})
assert False
except AssertionError as e:
assert str(e) == "'getpwuid(): uid not found: 1003'"
try:
ent.assert_passwd_by_uid(1002, dict(name="user1"))
assert False
except AssertionError as e:
assert str(e) == "'name' mismatch: 'user1' != 'user2'"
def test_assert_passwd_list(users_and_groups):
ent.assert_passwd_list(ent.contains())
ent.assert_passwd_list(ent.contains(USER1))
ent.assert_passwd_list(ent.contains_only(*USER_LIST))
try:
ent.assert_passwd_list(ent.contains_only())
assert False
except AssertionError as e:
assert not re.search("expected users not found:", str(e))
assert re.search("unexpected users found:", str(e))
try:
ent.assert_passwd_list(ent.contains(dict(name="non_existent")))
assert False
except AssertionError as e:
assert re.search("expected users not found:", str(e))
assert not re.search("unexpected users found:", str(e))
def test_assert_each_passwd_by_name(users_and_groups):
ent.assert_each_passwd_by_name({})
ent.assert_each_passwd_by_name(dict(user1=USER1))
ent.assert_each_passwd_by_name(USER_NAME_DICT)
try:
ent.assert_each_passwd_by_name(dict(user3={}))
assert False
except AssertionError as e:
assert str(e) == "'getpwnam(): name not found: user3'"
try:
ent.assert_each_passwd_by_name(dict(user1=dict(name="user2")))
assert False
except AssertionError as e:
assert str(e) == \
"user 'user1' mismatch: 'name' mismatch: 'user2' != 'user1'"
def test_assert_each_passwd_by_uid(users_and_groups):
ent.assert_each_passwd_by_uid({})
ent.assert_each_passwd_by_uid({1001: USER1})
ent.assert_each_passwd_by_uid(USER_UID_DICT)
try:
ent.assert_each_passwd_by_uid({1003: {}})
assert False
except AssertionError as e:
assert str(e) == "'getpwuid(): uid not found: 1003'"
try:
ent.assert_each_passwd_by_uid({1001: dict(uid=1002)})
assert False
except AssertionError as e:
assert str(e) == \
"user 1001 mismatch: 'uid' mismatch: 1002 != 1001"
def test_assert_each_passwd_with_name(users_and_groups):
ent.assert_each_passwd_with_name([])
ent.assert_each_passwd_with_name([USER1])
ent.assert_each_passwd_with_name(USER_LIST)
try:
ent.assert_each_passwd_with_name([dict(name="user3")])
assert False
except AssertionError as e:
assert str(e) == "'getpwnam(): name not found: user3'"
try:
ent.assert_each_passwd_with_name([dict(name="user1", uid=1002)])
assert False
except AssertionError as e:
assert str(e) == \
"user 'user1' mismatch: 'uid' mismatch: 1002 != 1001"
def test_assert_each_passwd_with_uid(users_and_groups):
ent.assert_each_passwd_with_uid([])
ent.assert_each_passwd_with_uid([USER1])
ent.assert_each_passwd_with_uid(USER_LIST)
try:
ent.assert_each_passwd_with_uid([dict(uid=1003)])
assert False
except AssertionError as e:
assert str(e) == "'getpwuid(): uid not found: 1003'"
try:
ent.assert_each_passwd_with_uid([dict(name="user2", uid=1001)])
assert False
except AssertionError as e:
assert str(e) == \
"user 1001 mismatch: 'name' mismatch: 'user2' != 'user1'"
def test_assert_passwd(users_and_groups):
ent.assert_passwd(ent.contains())
ent.assert_passwd(ent.contains(USER1))
ent.assert_passwd(ent.contains_only(*USER_LIST))
try:
ent.assert_passwd(ent.contains(dict(name="user3", uid=1003)))
assert False
except AssertionError as e:
assert re.search("list mismatch:", str(e))
assert re.search("expected users not found:", str(e))
assert not re.search("unexpected users found:", str(e))
try:
ent.assert_passwd(ent.contains_only(USER1))
assert False
except AssertionError as e:
assert re.search("list mismatch:", str(e))
assert not re.search("expected users not found:", str(e))
assert re.search("unexpected users found:", str(e))
def test_group_member_matching(users_and_groups):
ent.assert_group_by_name("empty_group", dict(mem=ent.contains()))
ent.assert_group_by_name("empty_group", dict(mem=ent.contains_only()))
try:
ent.assert_group_by_name("empty_group",
dict(mem=ent.contains("user1")))
except AssertionError as e:
assert re.search("member list mismatch:", str(e))
assert re.search("expected members not found:", str(e))
ent.assert_group_by_name("one_user_group1", dict(mem=ent.contains()))
ent.assert_group_by_name("one_user_group1",
dict(mem=ent.contains("user1")))
ent.assert_group_by_name("one_user_group1",
dict(mem=ent.contains_only("user1")))
try:
ent.assert_group_by_name("one_user_group1",
dict(mem=ent.contains_only()))
except AssertionError as e:
assert re.search("member list mismatch:", str(e))
assert re.search("unexpected members found:", str(e))
assert not re.search("expected members not found:", str(e))
try:
ent.assert_group_by_name("one_user_group1",
dict(mem=ent.contains_only("user3")))
except AssertionError as e:
assert re.search("member list mismatch:", str(e))
assert re.search("unexpected members found:", str(e))
assert re.search("expected members not found:", str(e))
try:
ent.assert_group_by_name("one_user_group1",
dict(mem=ent.contains("user3")))
except AssertionError as e:
assert re.search("member list mismatch:", str(e))
assert not re.search("unexpected members found:", str(e))
assert re.search("expected members not found:", str(e))
ent.assert_group_by_name("two_user_group", dict(mem=ent.contains()))
ent.assert_group_by_name("two_user_group",
dict(mem=ent.contains("user1")))
ent.assert_group_by_name("two_user_group",
dict(mem=ent.contains("user1", "user2")))
ent.assert_group_by_name("two_user_group",
dict(mem=ent.contains_only("user1", "user2")))
try:
ent.assert_group_by_name("two_user_group",
dict(mem=ent.contains_only("user1")))
except AssertionError as e:
assert re.search("member list mismatch:", str(e))
assert re.search("unexpected members found:", str(e))
assert not re.search("expected members not found:", str(e))
def test_assert_group_by_name(users_and_groups):
ent.assert_group_by_name("group1", {})
ent.assert_group_by_name("group1", dict(name="group1", gid=2001))
ent.assert_group_by_name("group1", GROUP1)
try:
ent.assert_group_by_name("group3", {})
assert False
except AssertionError as e:
assert str(e) == "'getgrnam(): name not found: group3'"
try:
ent.assert_group_by_name("group2", dict(name="group1"))
assert False
except AssertionError as e:
assert str(e) == "'name' mismatch: 'group1' != 'group2'"
def test_assert_group_by_gid(users_and_groups):
ent.assert_group_by_gid(2001, {})
ent.assert_group_by_gid(2001, dict(name="group1", gid=2001))
ent.assert_group_by_gid(2001, GROUP1)
try:
ent.assert_group_by_gid(2003, {})
assert False
except AssertionError as e:
assert str(e) == "'getgrgid(): gid not found: 2003'"
try:
ent.assert_group_by_gid(2002, dict(name="group1"))
assert False
except AssertionError as e:
assert str(e) == "'name' mismatch: 'group1' != 'group2'"
def test_assert_group_list(users_and_groups):
ent.assert_group_list(ent.contains())
ent.assert_group_list(ent.contains(GROUP1))
ent.assert_group_list(ent.contains_only(*GROUP_LIST))
try:
ent.assert_group_list(ent.contains_only())
assert False
except AssertionError as e:
assert not re.search("expected groups not found:", str(e))
assert re.search("unexpected groups found:", str(e))
try:
ent.assert_group_list(ent.contains(dict(name="non_existent")))
assert False
except AssertionError as e:
assert re.search("expected groups not found:", str(e))
assert not re.search("unexpected groups found:", str(e))
def test_assert_each_group_by_name(users_and_groups):
ent.assert_each_group_by_name({})
ent.assert_each_group_by_name(dict(group1=GROUP1))
ent.assert_each_group_by_name(GROUP_NAME_DICT)
try:
ent.assert_each_group_by_name(dict(group3={}))
assert False
except AssertionError as e:
assert str(e) == "'getgrnam(): name not found: group3'"
try:
ent.assert_each_group_by_name(dict(group1=dict(name="group2")))
assert False
except AssertionError as e:
assert str(e) == "group 'group1' mismatch: " + \
"'name' mismatch: 'group2' != 'group1'"
def test_assert_each_group_by_gid(users_and_groups):
ent.assert_each_group_by_gid({})
ent.assert_each_group_by_gid({2001: GROUP1})
ent.assert_each_group_by_gid(GROUP_GID_DICT)
try:
ent.assert_each_group_by_gid({2003: {}})
assert False
except AssertionError as e:
assert str(e) == "'getgrgid(): gid not found: 2003'"
try:
ent.assert_each_group_by_gid({2001: dict(gid=2002)})
assert False
except AssertionError as e:
assert str(e) == \
"group 2001 mismatch: 'gid' mismatch: 2002 != 2001"
def test_assert_each_group_with_name(users_and_groups):
ent.assert_each_group_with_name([])
ent.assert_each_group_with_name([GROUP1])
ent.assert_each_group_with_name(GROUP_LIST)
try:
ent.assert_each_group_with_name([dict(name="group3")])
assert False
except AssertionError as e:
assert str(e) == "'getgrnam(): name not found: group3'"
try:
ent.assert_each_group_with_name([dict(name="group1", gid=2002)])
assert False
except AssertionError as e:
assert str(e) == \
"group 'group1' mismatch: 'gid' mismatch: 2002 != 2001"
def test_assert_each_group_with_gid(users_and_groups):
ent.assert_each_group_with_gid([])
ent.assert_each_group_with_gid([GROUP1])
ent.assert_each_group_with_gid(GROUP_LIST)
try:
ent.assert_each_group_with_gid([dict(gid=2003)])
assert False
except AssertionError as e:
assert str(e) == "'getgrgid(): gid not found: 2003'"
try:
ent.assert_each_group_with_gid([dict(name="group2", gid=2001)])
assert False
except AssertionError as e:
assert str(e) == \
"group 2001 mismatch: 'name' mismatch: 'group2' != 'group1'"
def test_assert_group(users_and_groups):
ent.assert_group(ent.contains())
ent.assert_group(ent.contains(GROUP1))
ent.assert_group(ent.contains_only(*GROUP_LIST))
try:
ent.assert_group(ent.contains(dict(name="group3", gid=2003)))
assert False
except AssertionError as e:
assert re.search("list mismatch:", str(e))
assert re.search("expected groups not found:", str(e))
assert not re.search("unexpected groups found:", str(e))
try:
ent.assert_group(ent.contains_only(GROUP1))
assert False
except AssertionError as e:
assert re.search("list mismatch:", str(e))
assert not re.search("expected groups not found:", str(e))
assert re.search("unexpected groups found:", str(e))
|
gpl-3.0
|
[
3,
199,
3,
15992,
14,
647,
859,
2295,
199,
3,
199,
3,
1898,
334,
67,
9,
6900,
9572,
13002,
12,
3277,
14,
199,
3,
6529,
26,
653,
3258,
393,
5789,
1804,
265,
5012,
305,
526,
86,
665,
46,
3258,
393,
5789,
14,
43,
265,
5012,
305,
526,
86,
32,
17164,
14,
957,
30,
199,
3,
199,
3,
961,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1015,
499,
1454,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
646,
295,
199,
646,
747,
199,
646,
5890,
199,
646,
4613,
199,
646,
15992,
199,
504,
4884,
492,
627,
421,
199,
32,
4462,
14,
5997,
8,
2645,
628,
578,
531,
199,
318,
15081,
63,
515,
8,
1069,
304,
272,
536,
275,
298,
46,
2300,
63,
23824,
4227,
63,
6909,
16698,
2,
272,
1056,
14,
525,
30092,
8,
2734,
26,
9066,
63,
1813,
1391,
63,
493,
8,
354,
430,
272,
372,
6902,
63,
1813,
1391,
63,
493,
8,
354,
9,
421,
199,
32,
4462,
14,
5997,
8,
2645,
628,
578,
531,
199,
318,
1572,
63,
515,
8,
1069,
304,
272,
536,
275,
298,
46,
2300,
63,
23824,
4227,
63,
7823,
2,
272,
1056,
14,
525,
30092,
8,
2734,
26,
9066,
63,
1813,
1391,
63,
493,
8,
354,
430,
272,
372,
6902,
63,
1813,
1391,
63,
493,
8,
354,
9,
421,
199,
3791,
17,
275,
1211,
8,
354,
628,
751,
17,
401,
15081,
628,
88,
401,
1747,
29,
22167,
12,
15122,
29,
8339,
12,
1467,
2312,
5197,
628,
1899,
413,
401,
2935,
9555,
4219,
15,
751,
17,
401,
5218,
9555,
1393,
15,
16408,
531,
199,
3791,
18,
275,
1211,
8,
354,
628,
751,
18,
401,
15081,
628,
88,
401,
1747,
29,
32562,
12,
15122,
29,
15135,
12,
1467,
2312,
5197,
628,
1899,
499,
401,
2935,
9555,
4219,
15,
751,
18,
401,
5218,
9555,
1393,
15,
16408,
531,
199,
3791,
63,
4924,
275,
359,
3791,
17,
12,
13044,
18,
61,
199,
3791,
63,
2339,
63,
12511,
275,
1211,
1332,
85,
905,
354,
2255,
399,
9,
367,
399,
315,
13044,
63,
4924,
9,
199,
3791,
63,
6685,
63,
12511,
275,
1211,
1332,
85,
905,
1535,
2255,
399,
9,
367,
399,
315,
13044,
63,
4924,
9,
421,
199,
13993,
63,
7823,
275,
1211,
8,
354,
628,
1667,
63,
923,
401,
15081,
628,
88,
401,
15122,
29,
8269,
12,
673,
7573,
29,
484,
14,
6134,
63,
2118,
1012,
199,
7823,
17,
275,
1211,
8,
354,
628,
923,
17,
401,
15081,
628,
88,
401,
15122,
29,
8339,
12,
1598,
7573,
29,
484,
14,
6134,
63,
2118,
1012,
199,
7823,
18,
275,
1211,
8,
354,
628,
923,
18,
401,
15081,
628,
88,
401,
15122,
29,
15135,
12,
1598,
7573,
29,
484,
14,
6134,
63,
2118,
1012,
199,
4817,
63,
3791,
63,
7823,
17,
275,
1211,
8,
354,
628,
368,
63,
751,
63,
923,
17,
401,
15081,
628,
88,
401,
15122,
29,
8128,
12,
2432,
7573,
29,
484,
14,
6134,
63,
2118,
480,
751,
17,
2237,
199,
4817,
63,
3791,
63,
7823,
18,
275,
1211,
8,
354,
628,
368,
63,
751,
63,
923,
18,
401,
15081,
628,
88,
401,
15122,
29,
7409,
12,
2432,
7573,
29,
484,
14,
6134,
63,
2118,
480,
751,
18,
2237,
199,
52,
11325,
63,
3791,
63,
7823,
275,
1211,
8,
354,
628,
5601,
63,
751,
63,
923,
401,
15081,
628,
88,
401,
15122,
29,
13934,
12,
1993,
7573,
29,
484,
14,
6134,
63,
2118,
480,
751,
17,
401,
298,
751,
18,
2237,
199,
7823,
63,
4924,
275,
359,
13993,
63,
7823,
12,
1598,
15443,
17,
12,
1598,
15443,
18,
12,
1598,
13051,
63,
3791,
63,
7823,
17,
12,
1598,
13051,
63,
3791,
63,
7823,
18,
12,
1598,
16562,
63,
3791,
63,
7823,
61,
199,
7823,
63,
2339,
63,
12511,
275,
1211,
1332,
71,
905,
354,
2255,
486,
9,
367,
486,
315,
15443,
63,
4924,
9,
199,
7823,
63,
39,
998,
63,
12511,
275,
1211,
1332,
71,
905,
8787,
2255,
486,
9,
367,
486,
315,
15443,
63,
4924,
9,
421,
199,
32,
4462,
14,
5997,
8,
2645,
628,
578,
531,
199,
318,
4390,
63,
460,
63,
2634,
8,
1069,
12,
15081,
63,
515,
12,
1572,
63,
515,
304,
272,
15081,
63,
4407,
275,
10587,
904,
779,
267,
5310,
354,
16495,
12671,
16495,
1535,
16495,
8787,
16495,
303,
5197,
16495,
694,
16495,
5641,
4988,
78,
1674,
908,
3682,
85,
9,
267,
367,
399,
315,
13044,
63,
4924,
272,
4794,
272,
1572,
63,
4407,
275,
10587,
904,
779,
267,
2071,
83,
2689,
83,
2689,
83,
2689,
83,
60,
78,
2,
450,
334,
71,
905,
354,
2255,
486,
905,
12671,
2255,
486,
905,
8787,
2255,
2574,
19089,
904,
8,
71,
905,
5286,
13045,
267,
367,
486,
315,
15443,
63,
4924,
272,
4794,
339,
543,
1551,
8,
12671,
63,
515,
12,
298,
65,
531,
465,
289,
26,
267,
289,
14,
952,
8,
12671,
63,
4407,
9,
272,
543,
1551,
8,
923,
63,
515,
12,
298,
65,
531,
465,
289,
26,
267,
289,
14,
952,
8,
923,
63,
4407,
9,
421,
199,
318,
511,
63,
479,
63,
12671,
63,
991,
63,
354,
8,
3707,
63,
460,
63,
2634,
304,
272,
15992,
14,
479,
63,
12671,
63,
991,
63,
354,
480,
751,
17,
401,
5009,
272,
15992,
14,
479,
63,
12671,
63,
991,
63,
354,
480,
751,
17,
401,
1211,
8,
354,
628,
751,
17,
401,
1747,
29,
22167,
430,
272,
15992,
14,
479,
63,
12671,
63,
991,
63,
354,
480,
751,
17,
401,
13044,
17,
9,
339,
862,
26,
267,
15992,
14,
479,
63,
12671,
63,
991,
63,
354,
480,
751,
19,
401,
5009
] |
[
199,
3,
15992,
14,
647,
859,
2295,
199,
3,
199,
3,
1898,
334,
67,
9,
6900,
9572,
13002,
12,
3277,
14,
199,
3,
6529,
26,
653,
3258,
393,
5789,
1804,
265,
5012,
305,
526,
86,
665,
46,
3258,
393,
5789,
14,
43,
265,
5012,
305,
526,
86,
32,
17164,
14,
957,
30,
199,
3,
199,
3,
961,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1015,
499,
1454,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
646,
295,
199,
646,
747,
199,
646,
5890,
199,
646,
4613,
199,
646,
15992,
199,
504,
4884,
492,
627,
421,
199,
32,
4462,
14,
5997,
8,
2645,
628,
578,
531,
199,
318,
15081,
63,
515,
8,
1069,
304,
272,
536,
275,
298,
46,
2300,
63,
23824,
4227,
63,
6909,
16698,
2,
272,
1056,
14,
525,
30092,
8,
2734,
26,
9066,
63,
1813,
1391,
63,
493,
8,
354,
430,
272,
372,
6902,
63,
1813,
1391,
63,
493,
8,
354,
9,
421,
199,
32,
4462,
14,
5997,
8,
2645,
628,
578,
531,
199,
318,
1572,
63,
515,
8,
1069,
304,
272,
536,
275,
298,
46,
2300,
63,
23824,
4227,
63,
7823,
2,
272,
1056,
14,
525,
30092,
8,
2734,
26,
9066,
63,
1813,
1391,
63,
493,
8,
354,
430,
272,
372,
6902,
63,
1813,
1391,
63,
493,
8,
354,
9,
421,
199,
3791,
17,
275,
1211,
8,
354,
628,
751,
17,
401,
15081,
628,
88,
401,
1747,
29,
22167,
12,
15122,
29,
8339,
12,
1467,
2312,
5197,
628,
1899,
413,
401,
2935,
9555,
4219,
15,
751,
17,
401,
5218,
9555,
1393,
15,
16408,
531,
199,
3791,
18,
275,
1211,
8,
354,
628,
751,
18,
401,
15081,
628,
88,
401,
1747,
29,
32562,
12,
15122,
29,
15135,
12,
1467,
2312,
5197,
628,
1899,
499,
401,
2935,
9555,
4219,
15,
751,
18,
401,
5218,
9555,
1393,
15,
16408,
531,
199,
3791,
63,
4924,
275,
359,
3791,
17,
12,
13044,
18,
61,
199,
3791,
63,
2339,
63,
12511,
275,
1211,
1332,
85,
905,
354,
2255,
399,
9,
367,
399,
315,
13044,
63,
4924,
9,
199,
3791,
63,
6685,
63,
12511,
275,
1211,
1332,
85,
905,
1535,
2255,
399,
9,
367,
399,
315,
13044,
63,
4924,
9,
421,
199,
13993,
63,
7823,
275,
1211,
8,
354,
628,
1667,
63,
923,
401,
15081,
628,
88,
401,
15122,
29,
8269,
12,
673,
7573,
29,
484,
14,
6134,
63,
2118,
1012,
199,
7823,
17,
275,
1211,
8,
354,
628,
923,
17,
401,
15081,
628,
88,
401,
15122,
29,
8339,
12,
1598,
7573,
29,
484,
14,
6134,
63,
2118,
1012,
199,
7823,
18,
275,
1211,
8,
354,
628,
923,
18,
401,
15081,
628,
88,
401,
15122,
29,
15135,
12,
1598,
7573,
29,
484,
14,
6134,
63,
2118,
1012,
199,
4817,
63,
3791,
63,
7823,
17,
275,
1211,
8,
354,
628,
368,
63,
751,
63,
923,
17,
401,
15081,
628,
88,
401,
15122,
29,
8128,
12,
2432,
7573,
29,
484,
14,
6134,
63,
2118,
480,
751,
17,
2237,
199,
4817,
63,
3791,
63,
7823,
18,
275,
1211,
8,
354,
628,
368,
63,
751,
63,
923,
18,
401,
15081,
628,
88,
401,
15122,
29,
7409,
12,
2432,
7573,
29,
484,
14,
6134,
63,
2118,
480,
751,
18,
2237,
199,
52,
11325,
63,
3791,
63,
7823,
275,
1211,
8,
354,
628,
5601,
63,
751,
63,
923,
401,
15081,
628,
88,
401,
15122,
29,
13934,
12,
1993,
7573,
29,
484,
14,
6134,
63,
2118,
480,
751,
17,
401,
298,
751,
18,
2237,
199,
7823,
63,
4924,
275,
359,
13993,
63,
7823,
12,
1598,
15443,
17,
12,
1598,
15443,
18,
12,
1598,
13051,
63,
3791,
63,
7823,
17,
12,
1598,
13051,
63,
3791,
63,
7823,
18,
12,
1598,
16562,
63,
3791,
63,
7823,
61,
199,
7823,
63,
2339,
63,
12511,
275,
1211,
1332,
71,
905,
354,
2255,
486,
9,
367,
486,
315,
15443,
63,
4924,
9,
199,
7823,
63,
39,
998,
63,
12511,
275,
1211,
1332,
71,
905,
8787,
2255,
486,
9,
367,
486,
315,
15443,
63,
4924,
9,
421,
199,
32,
4462,
14,
5997,
8,
2645,
628,
578,
531,
199,
318,
4390,
63,
460,
63,
2634,
8,
1069,
12,
15081,
63,
515,
12,
1572,
63,
515,
304,
272,
15081,
63,
4407,
275,
10587,
904,
779,
267,
5310,
354,
16495,
12671,
16495,
1535,
16495,
8787,
16495,
303,
5197,
16495,
694,
16495,
5641,
4988,
78,
1674,
908,
3682,
85,
9,
267,
367,
399,
315,
13044,
63,
4924,
272,
4794,
272,
1572,
63,
4407,
275,
10587,
904,
779,
267,
2071,
83,
2689,
83,
2689,
83,
2689,
83,
60,
78,
2,
450,
334,
71,
905,
354,
2255,
486,
905,
12671,
2255,
486,
905,
8787,
2255,
2574,
19089,
904,
8,
71,
905,
5286,
13045,
267,
367,
486,
315,
15443,
63,
4924,
272,
4794,
339,
543,
1551,
8,
12671,
63,
515,
12,
298,
65,
531,
465,
289,
26,
267,
289,
14,
952,
8,
12671,
63,
4407,
9,
272,
543,
1551,
8,
923,
63,
515,
12,
298,
65,
531,
465,
289,
26,
267,
289,
14,
952,
8,
923,
63,
4407,
9,
421,
199,
318,
511,
63,
479,
63,
12671,
63,
991,
63,
354,
8,
3707,
63,
460,
63,
2634,
304,
272,
15992,
14,
479,
63,
12671,
63,
991,
63,
354,
480,
751,
17,
401,
5009,
272,
15992,
14,
479,
63,
12671,
63,
991,
63,
354,
480,
751,
17,
401,
1211,
8,
354,
628,
751,
17,
401,
1747,
29,
22167,
430,
272,
15992,
14,
479,
63,
12671,
63,
991,
63,
354,
480,
751,
17,
401,
13044,
17,
9,
339,
862,
26,
267,
15992,
14,
479,
63,
12671,
63,
991,
63,
354,
480,
751,
19,
401,
5009,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
davidnmurray/iris
|
tools/generate_std_names.py
|
12
|
4673
|
# (C) British Crown Copyright 2010 - 2015, Met Office
#
# This file is part of Iris.
#
# Iris is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Iris is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Iris. If not, see <http://www.gnu.org/licenses/>.
"""
A script to convert the standard names information from the provided XML
file into a Python dictionary format.
Takes two arguments: the first is the XML file to process and the second
is the name of the file to write the Python dictionary file into.
By default, Iris will use the source XML file:
etc/cf-standard-name-table.xml
as obtained from:
http://cf-pcmdi.llnl.gov/documents/cf-standard-names
"""
from __future__ import (absolute_import, division, print_function)
from six.moves import (filter, input, map, range, zip) # noqa
import six
import argparse
import pprint
import xml.etree.ElementTree as ET
STD_VALUES_FILE_TEMPLATE = '''
# (C) British Crown Copyright 2010 - 2015, Met Office
#
# This file is part of Iris.
#
# Iris is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Iris is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Iris. If not, see <http://www.gnu.org/licenses/>.
"""
This file contains a dictionary of standard value names that are mapped
to another dictionary of other standard name attributes. Currently only
the `canonical_unit` exists in these attribute dictionaries.
This file is automatically generated. Do not edit this file by hand.
The file will be generated during a standard build/installation:
python setup.py build
python setup.py install
Also, the file can be re-generated in the source distribution via:
python setup.py std_names
Or for more control (e.g. to use an alternative XML file) via:
python tools/generate_std_names.py XML_FILE MODULE_FILE
"""
from __future__ import (absolute_import, division, print_function)
from six.moves import (filter, input, map, range, zip) # noqa
STD_NAMES = '''.lstrip()
def process_name_table(tree, element_name, *child_elements):
"""
Yields a series of dictionaries with the key being the id of the entry element and the value containing
another dictionary mapping other attributes of the standard name to their values, e.g. units, description, grib value etc.
"""
for elem in tree.iterfind(element_name):
sub_section = {}
for child_elem in child_elements:
found_elem = elem.find(child_elem)
sub_section[child_elem] = found_elem.text if found_elem is not None else None
yield {elem.get("id") : sub_section}
def to_dict(infile, outfile):
values = {}
aliases = {}
tree = ET.parse(infile)
for section in process_name_table(tree, 'entry', 'canonical_units'):
values.update(section)
for section in process_name_table(tree, 'alias', 'entry_id'):
aliases.update(section)
for key, valued in six.iteritems(aliases):
values.update({
key : {'canonical_units' : values.get(valued['entry_id']).get('canonical_units')}
})
outfile.write(STD_VALUES_FILE_TEMPLATE + pprint.pformat(values))
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='Create Python code from CF standard name XML.')
parser.add_argument('input', metavar='INPUT',
help='Path to CF standard name XML')
parser.add_argument('output', metavar='OUTPUT',
help='Path to resulting Python code')
args = parser.parse_args()
if six.PY2:
encoding = {}
else:
encoding = {'encoding': 'utf-8'}
with open(args.input, 'r', **encoding) as in_fh:
with open(args.output, 'w', **encoding) as out_fh:
to_dict(in_fh, out_fh)
|
gpl-3.0
|
[
3,
334,
35,
9,
699,
322,
23184,
445,
18406,
1898,
7129,
446,
6900,
12,
10072,
593,
11286,
301,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
473,
5719,
14,
199,
3,
199,
3,
473,
5719,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
199,
3,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
473,
5719,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
473,
5719,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
199,
33,
2884,
370,
3957,
314,
4465,
1561,
2556,
687,
314,
2741,
4692,
199,
493,
1901,
282,
2018,
2600,
1475,
14,
199,
199,
32488,
2877,
2368,
26,
314,
1642,
365,
314,
4692,
570,
370,
2112,
436,
314,
3499,
199,
374,
314,
536,
402,
314,
570,
370,
2218,
314,
2018,
2600,
570,
1901,
14,
199,
199,
2175,
849,
12,
473,
5719,
911,
675,
314,
1350,
4692,
570,
26,
272,
5423,
15,
2177,
13,
6807,
13,
354,
13,
1224,
14,
1652,
199,
305,
15884,
687,
26,
272,
1455,
921,
2177,
13,
2352,
20208,
14,
914,
7530,
14,
16294,
15,
12233,
15,
2177,
13,
6807,
13,
1247,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
504,
3816,
14,
4912,
492,
334,
1541,
12,
1324,
12,
2341,
12,
1425,
12,
3482,
9,
221,
327,
8151,
199,
646,
3816,
199,
199,
646,
7534,
199,
646,
10933,
199,
646,
2748,
14,
9464,
14,
15325,
465,
12265,
421,
199,
18472,
63,
15514,
63,
3817,
63,
7433,
275,
1449,
199,
3,
334,
35,
9,
699,
322,
23184,
445,
18406,
1898,
7129,
446,
6900,
12,
10072,
593,
11286,
301,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
473,
5719,
14,
199,
3,
199,
3,
473,
5719,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
199,
3,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
473,
5719,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
473,
5719,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
199,
2765,
570,
3509,
282,
2600,
402,
4465,
574,
1561,
626,
787,
9994,
199,
475,
4573,
2600,
402,
1163,
4465,
536,
3004,
14,
13550,
1454,
199,
1589,
658,
13109,
63,
3248,
64,
3495,
315,
3520,
2225,
11196,
14,
199,
199,
2765,
570,
365,
5847,
4046,
14,
4226,
440,
5283,
642,
570,
701,
4926,
14,
199,
199,
1918,
570,
911,
506,
4046,
5309,
282,
4465,
1900,
15,
23048,
26,
272,
2366,
3272,
14,
647,
1900,
272,
2366,
3272,
14,
647,
3907,
199,
199,
31892,
12,
314,
570,
883,
506,
295,
13,
10176,
315,
314,
1350,
4084,
4799,
26,
272,
2366,
3272,
14,
647,
2418,
63,
1247,
199,
199,
2844,
367,
1655,
3304,
334,
69,
14,
71,
14,
370,
675,
376,
13943,
4692,
570,
9,
4799,
26,
272,
2366,
7249,
15,
4208,
63,
1516,
63,
1247,
14,
647,
4692,
63,
3817,
30223,
63,
3817,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
504,
3816,
14,
4912,
492,
334,
1541,
12,
1324,
12,
2341,
12,
1425,
12,
3482,
9,
221,
327,
8151,
421,
199,
18472,
63,
14546,
275,
1449,
14,
10124,
342,
421,
199,
318,
2112,
63,
354,
63,
1224,
8,
2350,
12,
1819,
63,
354,
12,
627,
1739,
63,
5527,
304,
272,
408,
272,
23771,
83,
282,
6779,
402,
11196,
543,
314,
790,
3769,
314,
1305,
402,
314,
2397,
1819,
436,
314,
574,
3035,
272,
4573,
2600,
4412,
1163,
3004,
402,
314,
4465,
536,
370,
3932,
1338,
12,
325,
14,
71,
14,
6204,
12,
1369,
12,
27591,
66,
574,
5423,
14,
272,
408,
272,
367,
6193,
315,
3123,
14,
1661,
1623,
8,
2108,
63,
354,
304,
267,
1007,
63,
2792,
275,
1052,
398,
367,
1982,
63,
6086,
315,
1982,
63,
5527,
26,
288,
1911,
63,
6086,
275,
6193,
14,
1623,
8,
1739,
63,
6086,
9,
288,
1007,
63,
2792,
59,
1739,
63,
6086,
61,
275,
1911,
63,
6086,
14,
505,
340,
1911,
63,
6086,
365,
440,
488,
587,
488,
398,
1995,
469,
6086,
14,
362,
480,
344,
531,
520,
1007,
63,
2792,
93,
421,
199,
318,
370,
63,
807,
8,
13880,
12,
4386,
304,
272,
1338,
275,
1052,
272,
5481,
275,
1052,
339,
3123,
275,
12265,
14,
1122,
8,
13880,
9,
339,
367,
3420,
315,
2112,
63,
354,
63,
1224,
8,
2350,
12,
283,
2373,
297,
283,
13109,
63,
5260,
735,
267,
1338,
14,
873,
8,
2792,
9,
339,
367,
3420,
315,
2112,
63,
354,
63,
1224,
8,
2350,
12,
283,
3620,
297,
283,
2373,
63,
344,
735,
267,
5481,
14,
873,
8,
2792,
9,
339,
367,
790,
12,
574,
68,
315,
3816,
14,
4611,
8,
8602,
304,
267,
1338,
14,
873,
2561,
355,
790,
520,
791,
13109,
63,
5260,
7,
520,
1338,
14,
362,
8,
16611,
459,
2373,
63,
344,
13227,
362,
360,
13109,
63,
5260,
21004,
288,
3828,
339,
4386,
14,
952
] |
[
334,
35,
9,
699,
322,
23184,
445,
18406,
1898,
7129,
446,
6900,
12,
10072,
593,
11286,
301,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
473,
5719,
14,
199,
3,
199,
3,
473,
5719,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
199,
3,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
473,
5719,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
473,
5719,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
199,
33,
2884,
370,
3957,
314,
4465,
1561,
2556,
687,
314,
2741,
4692,
199,
493,
1901,
282,
2018,
2600,
1475,
14,
199,
199,
32488,
2877,
2368,
26,
314,
1642,
365,
314,
4692,
570,
370,
2112,
436,
314,
3499,
199,
374,
314,
536,
402,
314,
570,
370,
2218,
314,
2018,
2600,
570,
1901,
14,
199,
199,
2175,
849,
12,
473,
5719,
911,
675,
314,
1350,
4692,
570,
26,
272,
5423,
15,
2177,
13,
6807,
13,
354,
13,
1224,
14,
1652,
199,
305,
15884,
687,
26,
272,
1455,
921,
2177,
13,
2352,
20208,
14,
914,
7530,
14,
16294,
15,
12233,
15,
2177,
13,
6807,
13,
1247,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
504,
3816,
14,
4912,
492,
334,
1541,
12,
1324,
12,
2341,
12,
1425,
12,
3482,
9,
221,
327,
8151,
199,
646,
3816,
199,
199,
646,
7534,
199,
646,
10933,
199,
646,
2748,
14,
9464,
14,
15325,
465,
12265,
421,
199,
18472,
63,
15514,
63,
3817,
63,
7433,
275,
1449,
199,
3,
334,
35,
9,
699,
322,
23184,
445,
18406,
1898,
7129,
446,
6900,
12,
10072,
593,
11286,
301,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
473,
5719,
14,
199,
3,
199,
3,
473,
5719,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
199,
3,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
473,
5719,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
473,
5719,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
199,
2765,
570,
3509,
282,
2600,
402,
4465,
574,
1561,
626,
787,
9994,
199,
475,
4573,
2600,
402,
1163,
4465,
536,
3004,
14,
13550,
1454,
199,
1589,
658,
13109,
63,
3248,
64,
3495,
315,
3520,
2225,
11196,
14,
199,
199,
2765,
570,
365,
5847,
4046,
14,
4226,
440,
5283,
642,
570,
701,
4926,
14,
199,
199,
1918,
570,
911,
506,
4046,
5309,
282,
4465,
1900,
15,
23048,
26,
272,
2366,
3272,
14,
647,
1900,
272,
2366,
3272,
14,
647,
3907,
199,
199,
31892,
12,
314,
570,
883,
506,
295,
13,
10176,
315,
314,
1350,
4084,
4799,
26,
272,
2366,
3272,
14,
647,
2418,
63,
1247,
199,
199,
2844,
367,
1655,
3304,
334,
69,
14,
71,
14,
370,
675,
376,
13943,
4692,
570,
9,
4799,
26,
272,
2366,
7249,
15,
4208,
63,
1516,
63,
1247,
14,
647,
4692,
63,
3817,
30223,
63,
3817,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
504,
3816,
14,
4912,
492,
334,
1541,
12,
1324,
12,
2341,
12,
1425,
12,
3482,
9,
221,
327,
8151,
421,
199,
18472,
63,
14546,
275,
1449,
14,
10124,
342,
421,
199,
318,
2112,
63,
354,
63,
1224,
8,
2350,
12,
1819,
63,
354,
12,
627,
1739,
63,
5527,
304,
272,
408,
272,
23771,
83,
282,
6779,
402,
11196,
543,
314,
790,
3769,
314,
1305,
402,
314,
2397,
1819,
436,
314,
574,
3035,
272,
4573,
2600,
4412,
1163,
3004,
402,
314,
4465,
536,
370,
3932,
1338,
12,
325,
14,
71,
14,
6204,
12,
1369,
12,
27591,
66,
574,
5423,
14,
272,
408,
272,
367,
6193,
315,
3123,
14,
1661,
1623,
8,
2108,
63,
354,
304,
267,
1007,
63,
2792,
275,
1052,
398,
367,
1982,
63,
6086,
315,
1982,
63,
5527,
26,
288,
1911,
63,
6086,
275,
6193,
14,
1623,
8,
1739,
63,
6086,
9,
288,
1007,
63,
2792,
59,
1739,
63,
6086,
61,
275,
1911,
63,
6086,
14,
505,
340,
1911,
63,
6086,
365,
440,
488,
587,
488,
398,
1995,
469,
6086,
14,
362,
480,
344,
531,
520,
1007,
63,
2792,
93,
421,
199,
318,
370,
63,
807,
8,
13880,
12,
4386,
304,
272,
1338,
275,
1052,
272,
5481,
275,
1052,
339,
3123,
275,
12265,
14,
1122,
8,
13880,
9,
339,
367,
3420,
315,
2112,
63,
354,
63,
1224,
8,
2350,
12,
283,
2373,
297,
283,
13109,
63,
5260,
735,
267,
1338,
14,
873,
8,
2792,
9,
339,
367,
3420,
315,
2112,
63,
354,
63,
1224,
8,
2350,
12,
283,
3620,
297,
283,
2373,
63,
344,
735,
267,
5481,
14,
873,
8,
2792,
9,
339,
367,
790,
12,
574,
68,
315,
3816,
14,
4611,
8,
8602,
304,
267,
1338,
14,
873,
2561,
355,
790,
520,
791,
13109,
63,
5260,
7,
520,
1338,
14,
362,
8,
16611,
459,
2373,
63,
344,
13227,
362,
360,
13109,
63,
5260,
21004,
288,
3828,
339,
4386,
14,
952,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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
4976
|
'''
Production Configurations
'''
from .base import * # noqa
# SECRET CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
# Raises ImproperlyConfigured exception if DJANGO_SECRET_KEY not in os.environ
SECRET_KEY = env("DJANGO_SECRET_KEY")
# This ensures that Django will be able to detect a secure connection
# properly on Heroku.
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Production middleware
# ------------------------------------------------------------------------------
PRODUCTION_MIDDLEWARE = (
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
)
# set this to 60 seconds and then to 518400 when you can prove it works
SECURE_HSTS_SECONDS = 60
SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool(
"DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS", default=True)
SECURE_FRAME_DENY = env.bool("DJANGO_SECURE_FRAME_DENY", default=True)
SECURE_CONTENT_TYPE_NOSNIFF = env.bool(
"DJANGO_SECURE_CONTENT_TYPE_NOSNIFF", default=True)
SECURE_BROWSER_XSS_FILTER = True
SESSION_COOKIE_SECURE = False
SESSION_COOKIE_HTTPONLY = True
SECURE_SSL_REDIRECT = env.bool("DJANGO_SECURE_SSL_REDIRECT", default=True)
# Make sure djangosecure.middleware.SecurityMiddleware is listed first
MIDDLEWARE = PRODUCTION_MIDDLEWARE + MIDDLEWARE
# Static Assets
# ------------------------
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
# EMAIL
# ------------------------------------------------------------------------------
DEFAULT_FROM_EMAIL = env('DJANGO_DEFAULT_FROM_EMAIL',
default='The Federation <noreply@thefederation.local>')
# Set this to "django.core.mail.backends.smtp.EmailBackend" for SMTP email sending
EMAIL_BACKEND = env("DJANGO_EMAIL_BACKEND", default="django.core.mail.backends.console.EmailBackend")
# Define these as necessary if using the SMTP backend
# See https://docs.djangoproject.com/en/1.10/topics/email/#smtp-backend
EMAIL_HOST = env("DJANGO_EMAIL_HOST", default="localhost")
EMAIL_PORT = env("DJANGO_EMAIL_PORT", default=587)
EMAIL_HOST_USER = env("DJANGO_EMAIL_HOST_USER", default="")
EMAIL_HOST_PASSWORD = env("DJANGO_EMAIL_HOST_PASSWORD", default="")
EMAIL_USE_TLS = env.bool("DJANGO_EMAIL_USE_TLS", default=True)
EMAIL_USE_SSL = env.bool("DJANGO_EMAIL_USE_SSL", default=False)
EMAIL_TIMEOUT = env("DJANGO_EMAIL_TIMEOUT", default=None)
EMAIL_SSL_KEYFILE = env("DJANGO_EMAIL_SSL_KEYFILE", default=None)
EMAIL_SSL_CERTFILE = env("DJANGO_EMAIL_SSL_CERTFILE", default=None)
EMAIL_SUBJECT_PREFIX = env("DJANGO_EMAIL_SUBJECT_PREFIX", default='')
SERVER_EMAIL = env('DJANGO_SERVER_EMAIL', default=DEFAULT_FROM_EMAIL)
# TEMPLATE CONFIGURATION
# ------------------------------------------------------------------------------
# See:
# https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.loaders.cached.Loader
TEMPLATES[0]['OPTIONS']['loaders'] = [
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ]),
]
# CACHING
# ------------------------------------------------------------------------------
# Guard against old setting
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://%s:%s/%s" % (REDIS_HOST, REDIS_PORT, REDIS_DB),
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"IGNORE_EXCEPTIONS": True, # mimics memcache behavior.
# http://niwinz.github.io/django-redis/latest/#_memcached_exceptions_behavior
"PASSWORD": REDIS_PASSWORD,
}
}
}
# RQ
# --
RQ_QUEUES["default"]["USE_REDIS_CACHE"] = "default"
# SENTRY
# ------
# If you wish to configure Sentry for error reporting, first create your
# Sentry account and then place the DSN in `.env` as `SENTRY_DSN=dsnhere`.
if env('SENTRY_DSN', default=None):
INSTALLED_APPS += ('raven.contrib.django.raven_compat',)
SENTRY_DSN = env('SENTRY_DSN')
RAVEN_CONFIG = {
'dsn': SENTRY_DSN,
'site': THEFEDERATION_DOMAIN,
}
LOGGING['handlers']['sentry'] = {
'level': env('SENTRY_LEVEL', default='ERROR'),
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
}
LOGGING['loggers']['thefederation']['handlers'].append('sentry')
LOGGING['loggers']['federation']['handlers'].append('sentry')
LOGGING['loggers']['rq_scheduler.scheduler']['handlers'].append('sentry')
LOGGING['root'] = {
'level': 'WARNING',
'handlers': ['sentry', 'file'],
}
LOGGING['loggers']['raven'] = {
'level': 'DEBUG',
'handlers': ['file'],
'propagate': False,
}
LOGGING['loggers']['sentry.errors'] = {
'level': 'DEBUG',
'handlers': ['file'],
'propagate': False,
}
|
agpl-3.0
|
[
2344,
199,
26432,
4094,
6556,
199,
2344,
199,
504,
1275,
1095,
492,
627,
221,
327,
8151,
421,
199,
3,
5795,
11771,
15869,
15301,
199,
3,
5620,
10965,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
4731,
13,
498,
199,
3,
6218,
11897,
1919,
340,
577,
42,
18822,
63,
12961,
63,
3078,
440,
315,
747,
14,
2314,
199,
12961,
63,
3078,
275,
2589,
480,
22848,
63,
12961,
63,
3078,
531,
199,
199,
3,
961,
15620,
626,
5634,
911,
506,
7688,
370,
9696,
282,
11153,
1950,
199,
3,
7684,
641,
18769,
745,
85,
14,
199,
20696,
63,
20026,
63,
5413,
63,
7311,
275,
661,
2856,
63,
56,
63,
22371,
8280,
63,
7459,
297,
283,
2859,
358,
199,
199,
3,
24114,
10816,
199,
3,
5620,
10965,
199,
2514,
4980,
5430,
63,
19987,
275,
334,
272,
283,
1176,
14,
5754,
14,
4416,
14,
7676,
6608,
297,
272,
283,
2191,
25840,
79,
572,
14,
5754,
14,
19803,
21446,
6608,
297,
199,
9,
199,
199,
3,
663,
642,
370,
5212,
4696,
436,
2066,
370,
959,
1085,
5303,
1380,
1265,
883,
557,
432,
652,
5419,
199,
20696,
63,
40,
840,
51,
63,
23319,
275,
5212,
199,
20696,
63,
40,
840,
51,
63,
18171,
63,
6348,
7378,
51,
275,
2589,
14,
2245,
8,
272,
298,
22848,
63,
20696,
63,
40,
840,
51,
63,
18171,
63,
6348,
7378,
51,
401,
849,
29,
549,
9,
199,
20696,
63,
12683,
63,
23282,
57,
275,
2589,
14,
2245,
480,
22848,
63,
20696,
63,
12683,
63,
23282,
57,
401,
849,
29,
549,
9,
199,
20696,
63,
9663,
63,
2711,
63,
2826,
8199,
24150,
275,
2589,
14,
2245,
8,
272,
298,
22848,
63,
20696,
63,
9663,
63,
2711,
63,
2826,
8199,
24150,
401,
849,
29,
549,
9,
199,
20696,
63,
31956,
3279,
63,
56,
2300,
63,
9905,
275,
715,
199,
12763,
63,
13665,
63,
20696,
275,
756,
199,
12763,
63,
13665,
63,
2856,
10452,
275,
715,
199,
20696,
63,
5413,
63,
19747,
275,
2589,
14,
2245,
480,
22848,
63,
20696,
63,
5413,
63,
19747,
401,
849,
29,
549,
9,
199,
199,
3,
4155,
3238,
1639,
7817,
14,
5754,
14,
7676,
6608,
365,
10532,
1642,
199,
19987,
275,
3611,
4980,
5430,
63,
19987,
435,
30718,
199,
199,
3,
13599,
3709,
2193,
199,
3,
10652,
518,
199,
10449,
9472,
63,
17467,
275,
283,
2191,
25840,
79,
572,
14,
3494,
14,
25428,
11038,
9278,
5535,
6408,
7,
199,
199,
3,
32320,
199,
3,
5620,
10965,
199,
3472,
63,
12491,
63,
10089,
275,
2589,
360,
22848,
63,
3472,
63,
12491,
63,
10089,
297,
586,
849,
534,
1918,
7949,
32643,
665,
27400,
19786,
32,
1589,
771,
32643,
14,
1832,
5971,
199,
3,
2494,
642,
370,
298,
1176,
14,
1018,
14,
1198,
14,
7765,
14,
15592,
14,
7035,
8447,
2,
367,
19810,
3031,
10209,
199,
10089,
63,
18145,
275,
2589,
480,
22848,
63,
10089,
63,
18145,
401,
849,
628,
1176,
14,
1018,
14,
1198,
14,
7765,
14,
6614,
14,
7035,
8447,
531,
199,
3,
13930,
3520,
465,
5784,
340,
1808,
314,
19810,
4865,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
11299,
15,
2123,
12645,
15592,
13,
4620,
199,
10089,
63,
5449,
275,
2589,
480,
22848,
63,
10089,
63,
5449,
401,
849,
628,
5967,
531,
199,
10089,
63,
3657,
275,
2589,
480,
22848,
63,
10089,
63,
3657,
401,
849,
29,
29071,
9,
199,
10089,
63,
5449,
63,
3791,
275,
2589,
480,
22848,
63,
10089,
63,
5449,
63,
3791,
401,
849,
18413,
199,
10089,
63,
5449,
63,
9032,
275,
2589,
480,
22848,
63,
10089,
63,
5449,
63,
9032,
401,
849,
18413,
199,
10089,
63,
4701,
63,
10224,
275,
2589,
14,
2245,
480,
22848,
63,
10089,
63,
4701,
63,
10224,
401,
849,
29,
549,
9,
199,
10089,
63,
4701,
63,
5413,
275,
2589,
14,
2245,
480,
22848,
63,
10089,
63,
4701,
63,
5413,
401,
849,
29,
797,
9,
199,
10089,
63,
8899,
275,
2589,
480,
22848,
63,
10089,
63,
8899,
401,
849,
29,
403,
9,
199,
10089,
63,
5413,
63,
3078,
3817,
275,
2589,
480,
22848,
63,
10089,
63,
5413,
63,
3078,
3817,
401,
849,
29,
403,
9,
199,
10089,
63,
5413,
63,
11163,
3817,
275,
2589,
480,
22848,
63,
10089,
63,
5413,
63,
11163,
3817,
401,
849,
29,
403,
9,
199,
10089,
63,
6348,
5550,
63,
6351,
275,
2589,
480,
22848,
63,
10089,
63,
6348,
5550,
63,
6351,
401,
849,
13275,
199,
6613,
63,
10089,
275,
2589,
360,
22848,
63,
6613,
63,
10089,
297,
849,
29,
3472,
63,
12491,
63,
10089,
9,
421,
199,
3,
24877,
15869,
15301,
199,
3,
5620,
10965,
199,
3,
1666,
26,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
1246,
12645,
1176,
14,
1160,
14,
16370,
14,
5245,
14,
5455,
199,
25437,
59,
16,
2733,
8808,
2545,
16370,
418,
275,
359,
272,
661,
1176,
14,
1160,
14,
16370,
14,
5245,
14,
5455,
297,
359,
267,
283,
1176,
14,
1160,
14,
16370,
14,
11381,
14,
5455,
297,
283,
1176,
14,
1160,
14,
16370,
14,
571,
63,
12629,
14,
5455,
297,
17318,
199,
61,
199,
199,
3,
7240,
1244,
1206,
199,
3,
5620,
10965,
199,
3,
12436,
1005,
6169,
2269,
4260,
199,
3263,
1244,
654,
275,
469,
272,
298,
885,
582,
469,
267,
298,
18145,
582,
298,
1176,
63,
15369,
14,
1637,
14,
29605,
4437,
401,
267,
298,
16575,
582,
298,
15369,
13827,
83,
2689,
83,
3149,
83,
2,
450,
334,
907,
6178,
63,
5449,
12,
23443,
1311,
63,
3657,
12,
23443,
1311,
63,
2846,
395,
267,
298,
8808,
582,
469,
288,
298,
9901,
63,
6885,
582,
298,
1176,
63,
15369,
14,
1258,
14,
2698,
3041,
401,
288,
298,
11209,
63,
25054,
582,
715,
12,
221,
327,
24102,
2932,
21598,
5953,
14,
3147,
327,
1455,
921,
8445,
2676,
90,
14,
5031,
14,
2308,
15,
1176,
13,
15369,
15,
7410,
12645,
63,
32567,
63,
3924,
63,
17537,
288,
298,
9032,
582,
23443,
1311,
63,
9032,
12,
267,
789,
272,
789,
199,
93,
199,
199,
3,
820,
49,
199,
3,
1553,
199,
50,
49,
63,
10526,
9318,
905,
885,
6611,
4701,
63,
907,
6178,
63,
8677,
937,
275,
298,
885,
2,
199,
199
] |
[
199,
26432,
4094,
6556,
199,
2344,
199,
504,
1275,
1095,
492,
627,
221,
327,
8151,
421,
199,
3,
5795,
11771,
15869,
15301,
199,
3,
5620,
10965,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
4731,
13,
498,
199,
3,
6218,
11897,
1919,
340,
577,
42,
18822,
63,
12961,
63,
3078,
440,
315,
747,
14,
2314,
199,
12961,
63,
3078,
275,
2589,
480,
22848,
63,
12961,
63,
3078,
531,
199,
199,
3,
961,
15620,
626,
5634,
911,
506,
7688,
370,
9696,
282,
11153,
1950,
199,
3,
7684,
641,
18769,
745,
85,
14,
199,
20696,
63,
20026,
63,
5413,
63,
7311,
275,
661,
2856,
63,
56,
63,
22371,
8280,
63,
7459,
297,
283,
2859,
358,
199,
199,
3,
24114,
10816,
199,
3,
5620,
10965,
199,
2514,
4980,
5430,
63,
19987,
275,
334,
272,
283,
1176,
14,
5754,
14,
4416,
14,
7676,
6608,
297,
272,
283,
2191,
25840,
79,
572,
14,
5754,
14,
19803,
21446,
6608,
297,
199,
9,
199,
199,
3,
663,
642,
370,
5212,
4696,
436,
2066,
370,
959,
1085,
5303,
1380,
1265,
883,
557,
432,
652,
5419,
199,
20696,
63,
40,
840,
51,
63,
23319,
275,
5212,
199,
20696,
63,
40,
840,
51,
63,
18171,
63,
6348,
7378,
51,
275,
2589,
14,
2245,
8,
272,
298,
22848,
63,
20696,
63,
40,
840,
51,
63,
18171,
63,
6348,
7378,
51,
401,
849,
29,
549,
9,
199,
20696,
63,
12683,
63,
23282,
57,
275,
2589,
14,
2245,
480,
22848,
63,
20696,
63,
12683,
63,
23282,
57,
401,
849,
29,
549,
9,
199,
20696,
63,
9663,
63,
2711,
63,
2826,
8199,
24150,
275,
2589,
14,
2245,
8,
272,
298,
22848,
63,
20696,
63,
9663,
63,
2711,
63,
2826,
8199,
24150,
401,
849,
29,
549,
9,
199,
20696,
63,
31956,
3279,
63,
56,
2300,
63,
9905,
275,
715,
199,
12763,
63,
13665,
63,
20696,
275,
756,
199,
12763,
63,
13665,
63,
2856,
10452,
275,
715,
199,
20696,
63,
5413,
63,
19747,
275,
2589,
14,
2245,
480,
22848,
63,
20696,
63,
5413,
63,
19747,
401,
849,
29,
549,
9,
199,
199,
3,
4155,
3238,
1639,
7817,
14,
5754,
14,
7676,
6608,
365,
10532,
1642,
199,
19987,
275,
3611,
4980,
5430,
63,
19987,
435,
30718,
199,
199,
3,
13599,
3709,
2193,
199,
3,
10652,
518,
199,
10449,
9472,
63,
17467,
275,
283,
2191,
25840,
79,
572,
14,
3494,
14,
25428,
11038,
9278,
5535,
6408,
7,
199,
199,
3,
32320,
199,
3,
5620,
10965,
199,
3472,
63,
12491,
63,
10089,
275,
2589,
360,
22848,
63,
3472,
63,
12491,
63,
10089,
297,
586,
849,
534,
1918,
7949,
32643,
665,
27400,
19786,
32,
1589,
771,
32643,
14,
1832,
5971,
199,
3,
2494,
642,
370,
298,
1176,
14,
1018,
14,
1198,
14,
7765,
14,
15592,
14,
7035,
8447,
2,
367,
19810,
3031,
10209,
199,
10089,
63,
18145,
275,
2589,
480,
22848,
63,
10089,
63,
18145,
401,
849,
628,
1176,
14,
1018,
14,
1198,
14,
7765,
14,
6614,
14,
7035,
8447,
531,
199,
3,
13930,
3520,
465,
5784,
340,
1808,
314,
19810,
4865,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
11299,
15,
2123,
12645,
15592,
13,
4620,
199,
10089,
63,
5449,
275,
2589,
480,
22848,
63,
10089,
63,
5449,
401,
849,
628,
5967,
531,
199,
10089,
63,
3657,
275,
2589,
480,
22848,
63,
10089,
63,
3657,
401,
849,
29,
29071,
9,
199,
10089,
63,
5449,
63,
3791,
275,
2589,
480,
22848,
63,
10089,
63,
5449,
63,
3791,
401,
849,
18413,
199,
10089,
63,
5449,
63,
9032,
275,
2589,
480,
22848,
63,
10089,
63,
5449,
63,
9032,
401,
849,
18413,
199,
10089,
63,
4701,
63,
10224,
275,
2589,
14,
2245,
480,
22848,
63,
10089,
63,
4701,
63,
10224,
401,
849,
29,
549,
9,
199,
10089,
63,
4701,
63,
5413,
275,
2589,
14,
2245,
480,
22848,
63,
10089,
63,
4701,
63,
5413,
401,
849,
29,
797,
9,
199,
10089,
63,
8899,
275,
2589,
480,
22848,
63,
10089,
63,
8899,
401,
849,
29,
403,
9,
199,
10089,
63,
5413,
63,
3078,
3817,
275,
2589,
480,
22848,
63,
10089,
63,
5413,
63,
3078,
3817,
401,
849,
29,
403,
9,
199,
10089,
63,
5413,
63,
11163,
3817,
275,
2589,
480,
22848,
63,
10089,
63,
5413,
63,
11163,
3817,
401,
849,
29,
403,
9,
199,
10089,
63,
6348,
5550,
63,
6351,
275,
2589,
480,
22848,
63,
10089,
63,
6348,
5550,
63,
6351,
401,
849,
13275,
199,
6613,
63,
10089,
275,
2589,
360,
22848,
63,
6613,
63,
10089,
297,
849,
29,
3472,
63,
12491,
63,
10089,
9,
421,
199,
3,
24877,
15869,
15301,
199,
3,
5620,
10965,
199,
3,
1666,
26,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
1246,
12645,
1176,
14,
1160,
14,
16370,
14,
5245,
14,
5455,
199,
25437,
59,
16,
2733,
8808,
2545,
16370,
418,
275,
359,
272,
661,
1176,
14,
1160,
14,
16370,
14,
5245,
14,
5455,
297,
359,
267,
283,
1176,
14,
1160,
14,
16370,
14,
11381,
14,
5455,
297,
283,
1176,
14,
1160,
14,
16370,
14,
571,
63,
12629,
14,
5455,
297,
17318,
199,
61,
199,
199,
3,
7240,
1244,
1206,
199,
3,
5620,
10965,
199,
3,
12436,
1005,
6169,
2269,
4260,
199,
3263,
1244,
654,
275,
469,
272,
298,
885,
582,
469,
267,
298,
18145,
582,
298,
1176,
63,
15369,
14,
1637,
14,
29605,
4437,
401,
267,
298,
16575,
582,
298,
15369,
13827,
83,
2689,
83,
3149,
83,
2,
450,
334,
907,
6178,
63,
5449,
12,
23443,
1311,
63,
3657,
12,
23443,
1311,
63,
2846,
395,
267,
298,
8808,
582,
469,
288,
298,
9901,
63,
6885,
582,
298,
1176,
63,
15369,
14,
1258,
14,
2698,
3041,
401,
288,
298,
11209,
63,
25054,
582,
715,
12,
221,
327,
24102,
2932,
21598,
5953,
14,
3147,
327,
1455,
921,
8445,
2676,
90,
14,
5031,
14,
2308,
15,
1176,
13,
15369,
15,
7410,
12645,
63,
32567,
63,
3924,
63,
17537,
288,
298,
9032,
582,
23443,
1311,
63,
9032,
12,
267,
789,
272,
789,
199,
93,
199,
199,
3,
820,
49,
199,
3,
1553,
199,
50,
49,
63,
10526,
9318,
905,
885,
6611,
4701,
63,
907,
6178,
63,
8677,
937,
275,
298,
885,
2,
199,
199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
reubano/hdxscraper-fts
|
tests/__init__.py
|
7
|
2489
|
# -*- coding: utf-8 -*-
"""
tests
~~~~~
Provides application unit tests
"""
from flask.json import loads, dumps
from app import create_app
initialized = False
app = None
client = None
jsonx = None
endpoint = None
base = None
def setup_package():
"""database context creation"""
global initialized
global app
global client
global jsonx
global endpoint
global base
app = create_app(config_mode='Test')
endpoint = app.config['API_URL_PREFIX']
base = '%s/' % endpoint if endpoint else ''
client = app.test_client()
jsonx = app.test_request_context()
jsonx.push()
initialized = True
print('Test Package Setup\n')
def teardown_package():
"""database context removal"""
global initialized
global jsonx
jsonx.pop()
initialized = False
print('Test Package Teardown\n')
class APIHelper:
def __init__(self):
global client
self.client = client
self.json = 'application/json'
def get_data(self, table, id=None, query=None):
# returns status_code 200
if id:
url = base + table + '/' + id
else:
url = base + table
if query:
r = self.client.get(url, content_type=self.json, q=query)
else:
r = self.client.get(url, content_type=self.json)
return r
def delete_data(self, table, id):
# returns status_code 204
url = '%s/%s/%s' % (endpoint, table, id)
r = self.client.delete(url, content_type=self.json)
return r
def post_data(self, data, table):
# returns status_code 201
url = base + table
r = self.client.post(url, data=dumps(data), content_type=self.json)
return r
def patch_data(self, data, table, id=None, query=None):
# returns status_code 200 or 201
if id:
url = base + table + '/' + id
else:
url = base + table
if query:
r = self.client.patch(
url, data=dumps(data), content_type=self.json, q=query)
else:
r = self.client.patch(url, data=dumps(data), content_type=self.json)
return r
def get_num_results(self, table):
r = self.get_data(table)
loaded = loads(r.data)
return loaded['num_results']
def get_type(self, table, id=1):
r = self.get_data(table, id)
loaded = loads(r.data)
return loaded['type']['id']
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
2295,
272,
221,
2878,
94,
339,
21552,
4223,
4137,
2295,
199,
624,
199,
199,
504,
7209,
14,
1001,
492,
14404,
12,
16864,
199,
504,
1145,
492,
1218,
63,
571,
199,
199,
12486,
275,
756,
199,
571,
275,
488,
199,
1258,
275,
488,
199,
1001,
88,
275,
488,
199,
6520,
275,
488,
199,
1095,
275,
488,
421,
199,
318,
3272,
63,
2491,
837,
272,
408,
4659,
1067,
7143,
624,
272,
2288,
10038,
272,
2288,
1145,
272,
2288,
1890,
272,
2288,
2022,
88,
272,
2288,
6037,
272,
2288,
1300,
339,
1145,
275,
1218,
63,
571,
8,
888,
63,
632,
534,
774,
358,
272,
6037,
275,
1145,
14,
888,
459,
3735,
63,
2632,
63,
6351,
418,
272,
1300,
275,
1543,
83,
4805,
450,
6037,
340,
6037,
587,
2125,
272,
1890,
275,
1145,
14,
396,
63,
1258,
342,
272,
2022,
88,
275,
1145,
14,
396,
63,
1069,
63,
1100,
342,
272,
2022,
88,
14,
5335,
342,
272,
10038,
275,
715,
339,
870,
360,
774,
15665,
12439,
60,
78,
358,
421,
199,
318,
17558,
63,
2491,
837,
272,
408,
4659,
1067,
20055,
624,
272,
2288,
10038,
272,
2288,
2022,
88,
339,
2022,
88,
14,
1935,
342,
272,
10038,
275,
756,
339,
870,
360,
774,
15665,
5773,
10549,
60,
78,
358,
421,
199,
533,
3261,
4433,
26,
272,
347,
636,
826,
721,
277,
304,
267,
2288,
1890,
267,
291,
14,
1258,
275,
1890,
267,
291,
14,
1001,
275,
283,
3578,
15,
1001,
7,
339,
347,
664,
63,
576,
8,
277,
12,
1817,
12,
1305,
29,
403,
12,
1827,
29,
403,
304,
267,
327,
2529,
2004,
63,
600,
1926,
398,
340,
1305,
26,
288,
1166,
275,
1300,
435,
1817,
435,
7324,
435,
1305,
267,
587,
26,
288,
1166,
275,
1300,
435,
1817,
398,
340,
1827,
26,
288,
519,
275,
291,
14,
1258,
14,
362,
8,
633,
12,
1564,
63,
466,
29,
277,
14,
1001,
12,
1894,
29,
1131,
9,
267,
587,
26,
288,
519,
275,
291,
14,
1258,
14,
362,
8,
633,
12,
1564,
63,
466,
29,
277,
14,
1001,
9,
398,
372,
519,
339,
347,
3145,
63,
576,
8,
277,
12,
1817,
12,
1305,
304,
267,
327,
2529,
2004,
63,
600,
14785,
267,
1166,
275,
1543,
83,
3149,
83,
3149,
83,
7,
450,
334,
6520,
12,
1817,
12,
1305,
9,
267,
519,
275,
291,
14,
1258,
14,
1807,
8,
633,
12,
1564,
63,
466,
29,
277,
14,
1001,
9,
267,
372,
519,
339,
347,
2963,
63,
576,
8,
277,
12,
666,
12,
1817,
304,
267,
327,
2529,
2004,
63,
600,
1784,
267,
1166,
275,
1300,
435,
1817,
267,
519,
275,
291,
14,
1258,
14,
1932,
8,
633,
12,
666,
29,
4180,
8,
576,
395,
1564,
63,
466,
29,
277,
14,
1001,
9,
267,
372,
519,
339,
347,
3371,
63,
576,
8,
277,
12,
666,
12,
1817,
12,
1305,
29,
403,
12,
1827,
29,
403,
304,
267,
327,
2529,
2004,
63,
600,
1926,
503,
1784,
267,
340,
1305,
26,
288,
1166,
275,
1300,
435,
1817,
435,
7324,
435,
1305,
267,
587,
26,
288,
1166,
275,
1300,
435,
1817,
398,
340,
1827,
26,
288,
519,
275,
291,
14,
1258,
14,
2068,
8,
355,
1166,
12,
666,
29,
4180,
8,
576,
395,
1564,
63,
466,
29,
277,
14,
1001,
12,
1894,
29,
1131,
9,
267,
587,
26,
288,
519,
275,
291,
14,
1258,
14,
2068,
8,
633,
12,
666,
29,
4180,
8,
576,
395,
1564,
63,
466,
29,
277,
14,
1001,
9,
398,
372,
519,
339,
347,
664,
63,
1507,
63,
2604,
8,
277,
12,
1817,
304,
267,
519,
275,
291,
14,
362,
63,
576,
8,
1224,
9,
267,
6511,
275,
14404,
8,
82,
14,
576,
9,
267,
372,
6511,
459,
1507,
63,
2604,
418,
339,
347,
664,
63,
466,
8,
277,
12,
1817,
12,
1305,
29,
17,
304,
267,
519,
275,
291,
14,
362,
63,
576,
8,
1224,
12,
1305,
9,
267,
6511,
275,
14404,
8,
82,
14,
576,
9,
267,
372,
6511,
459,
466,
2545,
344,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
2295,
272,
221,
2878,
94,
339,
21552,
4223,
4137,
2295,
199,
624,
199,
199,
504,
7209,
14,
1001,
492,
14404,
12,
16864,
199,
504,
1145,
492,
1218,
63,
571,
199,
199,
12486,
275,
756,
199,
571,
275,
488,
199,
1258,
275,
488,
199,
1001,
88,
275,
488,
199,
6520,
275,
488,
199,
1095,
275,
488,
421,
199,
318,
3272,
63,
2491,
837,
272,
408,
4659,
1067,
7143,
624,
272,
2288,
10038,
272,
2288,
1145,
272,
2288,
1890,
272,
2288,
2022,
88,
272,
2288,
6037,
272,
2288,
1300,
339,
1145,
275,
1218,
63,
571,
8,
888,
63,
632,
534,
774,
358,
272,
6037,
275,
1145,
14,
888,
459,
3735,
63,
2632,
63,
6351,
418,
272,
1300,
275,
1543,
83,
4805,
450,
6037,
340,
6037,
587,
2125,
272,
1890,
275,
1145,
14,
396,
63,
1258,
342,
272,
2022,
88,
275,
1145,
14,
396,
63,
1069,
63,
1100,
342,
272,
2022,
88,
14,
5335,
342,
272,
10038,
275,
715,
339,
870,
360,
774,
15665,
12439,
60,
78,
358,
421,
199,
318,
17558,
63,
2491,
837,
272,
408,
4659,
1067,
20055,
624,
272,
2288,
10038,
272,
2288,
2022,
88,
339,
2022,
88,
14,
1935,
342,
272,
10038,
275,
756,
339,
870,
360,
774,
15665,
5773,
10549,
60,
78,
358,
421,
199,
533,
3261,
4433,
26,
272,
347,
636,
826,
721,
277,
304,
267,
2288,
1890,
267,
291,
14,
1258,
275,
1890,
267,
291,
14,
1001,
275,
283,
3578,
15,
1001,
7,
339,
347,
664,
63,
576,
8,
277,
12,
1817,
12,
1305,
29,
403,
12,
1827,
29,
403,
304,
267,
327,
2529,
2004,
63,
600,
1926,
398,
340,
1305,
26,
288,
1166,
275,
1300,
435,
1817,
435,
7324,
435,
1305,
267,
587,
26,
288,
1166,
275,
1300,
435,
1817,
398,
340,
1827,
26,
288,
519,
275,
291,
14,
1258,
14,
362,
8,
633,
12,
1564,
63,
466,
29,
277,
14,
1001,
12,
1894,
29,
1131,
9,
267,
587,
26,
288,
519,
275,
291,
14,
1258,
14,
362,
8,
633,
12,
1564,
63,
466,
29,
277,
14,
1001,
9,
398,
372,
519,
339,
347,
3145,
63,
576,
8,
277,
12,
1817,
12,
1305,
304,
267,
327,
2529,
2004,
63,
600,
14785,
267,
1166,
275,
1543,
83,
3149,
83,
3149,
83,
7,
450,
334,
6520,
12,
1817,
12,
1305,
9,
267,
519,
275,
291,
14,
1258,
14,
1807,
8,
633,
12,
1564,
63,
466,
29,
277,
14,
1001,
9,
267,
372,
519,
339,
347,
2963,
63,
576,
8,
277,
12,
666,
12,
1817,
304,
267,
327,
2529,
2004,
63,
600,
1784,
267,
1166,
275,
1300,
435,
1817,
267,
519,
275,
291,
14,
1258,
14,
1932,
8,
633,
12,
666,
29,
4180,
8,
576,
395,
1564,
63,
466,
29,
277,
14,
1001,
9,
267,
372,
519,
339,
347,
3371,
63,
576,
8,
277,
12,
666,
12,
1817,
12,
1305,
29,
403,
12,
1827,
29,
403,
304,
267,
327,
2529,
2004,
63,
600,
1926,
503,
1784,
267,
340,
1305,
26,
288,
1166,
275,
1300,
435,
1817,
435,
7324,
435,
1305,
267,
587,
26,
288,
1166,
275,
1300,
435,
1817,
398,
340,
1827,
26,
288,
519,
275,
291,
14,
1258,
14,
2068,
8,
355,
1166,
12,
666,
29,
4180,
8,
576,
395,
1564,
63,
466,
29,
277,
14,
1001,
12,
1894,
29,
1131,
9,
267,
587,
26,
288,
519,
275,
291,
14,
1258,
14,
2068,
8,
633,
12,
666,
29,
4180,
8,
576,
395,
1564,
63,
466,
29,
277,
14,
1001,
9,
398,
372,
519,
339,
347,
664,
63,
1507,
63,
2604,
8,
277,
12,
1817,
304,
267,
519,
275,
291,
14,
362,
63,
576,
8,
1224,
9,
267,
6511,
275,
14404,
8,
82,
14,
576,
9,
267,
372,
6511,
459,
1507,
63,
2604,
418,
339,
347,
664,
63,
466,
8,
277,
12,
1817,
12,
1305,
29,
17,
304,
267,
519,
275,
291,
14,
362,
63,
576,
8,
1224,
12,
1305,
9,
267,
6511,
275,
14404,
8,
82,
14,
576,
9,
267,
372,
6511,
459,
466,
2545,
344,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ubc/edx-ora2
|
openassessment/assessment/test/constants.py
|
5
|
2894
|
# -*- coding: utf-8 -*-
"""
Constants used as test data.
"""
STUDENT_ITEM = {
'student_id': u'𝓽𝓮𝓼𝓽 𝓼𝓽𝓾𝓭𝓮𝓷𝓽',
'item_id': u'𝖙𝖊𝖘𝖙 𝖎𝖙𝖊𝖒',
'course_id': u'ՇєรՇ ς๏ยгรє',
'item_type': u'openassessment'
}
ANSWER = {'text': u'ẗëṡẗ äṅṡẅëṛ'}
RUBRIC_OPTIONS = [
{
"order_num": 0,
"name": u"𝒑𝒐𝒐𝒓",
"explanation": u"𝕻𝖔𝖔𝖗 𝖏𝖔𝖇!",
"points": 0,
},
{
"order_num": 1,
"name": u"𝓰𝓸𝓸𝓭",
"explanation": u"ﻭѻѻɗ ﻝѻ๒!",
"points": 1,
},
{
"order_num": 2,
"name": u"єχ¢єℓℓєηт",
"explanation": u"乇メc乇レレ乇刀イ フo乃!",
"points": 2,
},
]
RUBRIC = {
'prompts': [{"description": u"МоъЎ-ↁіск; оѓ, ГЂэ ЩЂаlэ"}],
'criteria': [
{
"order_num": 0,
"name": u"vøȼȺƀᵾłȺɍɏ",
"prompt": u"Ħøw vȺɍɨɇđ ɨs ŧħɇ vøȼȺƀᵾłȺɍɏ?",
"options": RUBRIC_OPTIONS
},
{
"order_num": 1,
"name": u"ﻭɼค๓๓คɼ",
"prompt": u"𝕳𝖔𝖜 𝖈𝖔𝖗𝖗𝖊𝖈𝖙 𝖎𝖘 𝖙𝖍𝖊 𝖌𝖗𝖆𝖒𝖒𝖆𝖗?",
"options": RUBRIC_OPTIONS
}
]
}
EXAMPLES = [
{
'answer': (
u"𝕿𝖍𝖊𝖗𝖊 𝖆𝖗𝖊 𝖈𝖊𝖗𝖙𝖆𝖎𝖓 𝖖𝖚𝖊𝖊𝖗 𝖙𝖎𝖒𝖊𝖘 𝖆𝖓𝖉 𝖔𝖈𝖈𝖆𝖘𝖎𝖔𝖓𝖘 𝖎𝖓 𝖙𝖍𝖎𝖘 𝖘𝖙𝖗𝖆𝖓𝖌𝖊 𝖒𝖎𝖝𝖊𝖉 𝖆𝖋𝖋𝖆𝖎𝖗 𝖜𝖊 𝖈𝖆𝖑𝖑 𝖑𝖎𝖋𝖊"
u" 𝖜𝖍𝖊𝖓 𝖆 𝖒𝖆𝖓 𝖙𝖆𝖐𝖊𝖘 𝖙𝖍𝖎𝖘 𝖜𝖍𝖔𝖑𝖊 𝖚𝖓𝖎𝖛𝖊𝖗𝖘𝖊 𝖋𝖔𝖗 𝖆 𝖛𝖆𝖘𝖙 𝖕𝖗𝖆𝖈𝖙𝖎𝖈𝖆𝖑 𝖏𝖔𝖐𝖊, 𝖙𝖍𝖔𝖚𝖌𝖍 𝖙𝖍𝖊 𝖜𝖎𝖙 𝖙𝖍𝖊𝖗𝖊𝖔𝖋"
u" 𝖍𝖊 𝖇𝖚𝖙 𝖉𝖎𝖒𝖑𝖞 𝖉𝖎𝖘𝖈𝖊𝖗𝖓𝖘, 𝖆𝖓𝖉 𝖒𝖔𝖗𝖊 𝖙𝖍𝖆𝖓 𝖘𝖚𝖘𝖕𝖊𝖈𝖙𝖘 𝖙𝖍𝖆𝖙 𝖙𝖍𝖊 𝖏𝖔𝖐𝖊 𝖎𝖘 𝖆𝖙 𝖓𝖔𝖇𝖔𝖉𝖞'𝖘 𝖊𝖝𝖕𝖊𝖓𝖘𝖊 𝖇𝖚𝖙 𝖍𝖎𝖘 𝖔𝖜𝖓."
),
'options_selected': {
u"vøȼȺƀᵾłȺɍɏ": u"𝓰𝓸𝓸𝓭",
u"ﻭɼค๓๓คɼ": u"𝒑𝒐𝒐𝒓",
}
},
{
'answer': u"Tőṕ-héávӳ ẃáś thé śhíṕ áś á díńńéŕĺéśś śtúdéńt ẃíth áĺĺ Áŕíśtőtĺé íń híś héád.",
'options_selected': {
u"vøȼȺƀᵾłȺɍɏ": u"𝒑𝒐𝒐𝒓",
u"ﻭɼค๓๓คɼ": u"єχ¢єℓℓєηт",
}
},
]
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
22185,
1202,
465,
511,
666,
14,
199,
624,
199,
199,
840,
29317,
63,
10439,
275,
469,
272,
283,
5500,
63,
344,
356,
399,
7,
173,
252,
242,
122,
173,
252,
242,
107,
173,
252,
242,
121,
173,
252,
242,
122,
221,
173,
252,
242,
121,
173,
252,
242,
122,
173,
252,
242,
123,
173,
252,
242,
256,
173,
252,
242,
107,
173,
252,
242,
116,
173,
252,
242,
122,
297,
272,
283,
1053,
63,
344,
356,
399,
7,
173,
252,
245,
248,
173,
252,
245,
233,
173,
252,
245,
247,
173,
252,
245,
248,
221,
173,
252,
245,
237,
173,
252,
245,
248,
173,
252,
245,
233,
173,
252,
245,
241,
297,
272,
283,
1972,
63,
344,
356,
399,
7,
146,
230,
142,
243,
157,
117,
97,
146,
230,
221,
25128,
157,
118,
238,
157,
117,
96,
141,
112,
157,
117,
97,
142,
243,
297,
272,
283,
1053,
63,
466,
356,
399,
7,
1490,
17452,
7,
199,
93,
199,
199,
5622,
12018,
275,
791,
505,
356,
399,
7,
158,
119,
246,
128,
105,
158,
118,
95,
158,
119,
246,
13333,
98,
158,
118,
228,
158,
118,
95,
158,
119,
228,
128,
105,
158,
118,
250,
936,
199,
199,
50,
2533,
14673,
63,
8808,
275,
359,
272,
469,
267,
298,
1648,
63,
1507,
582,
378,
12,
267,
298,
354,
582,
399,
2,
173,
252,
241,
240,
173,
252,
241,
239,
173,
252,
241,
239,
173,
252,
241,
242,
401,
267,
298,
15228,
582,
399,
2,
173,
252,
244,
120,
173,
252,
245,
243,
173,
252,
245,
243,
173,
252,
245,
246,
221,
173,
252,
245,
238,
173,
252,
245,
243,
173,
252,
245,
230,
17716,
267,
298,
3438,
582,
378,
12,
272,
1660,
272,
469,
267,
298,
1648,
63,
1507,
582,
413,
12,
267,
298,
354,
582,
399,
2,
173,
252,
242,
109,
173,
252,
242,
117,
173,
252,
242,
117,
173,
252,
242,
256,
401,
267,
298,
15228,
582,
399,
2,
172,
120,
256,
142,
120,
142,
120,
134,
246,
221,
172,
120,
252,
142,
120,
157,
118,
241,
17716,
267,
298,
3438,
582,
413,
12,
272,
1660,
272,
469,
267,
298,
1648,
63,
1507,
582,
499,
12,
267,
298,
354,
582,
399,
2,
142,
243,
140,
230,
127,
96,
142,
243,
159,
227,
242,
159,
227,
242,
142,
243,
21694,
7413,
401,
267,
298,
15228,
582,
399,
2,
17837,
230,
172,
123,
241,
67,
17837,
230,
172,
123,
249,
172,
123,
249,
17837,
230,
9051,
223,
172,
122,
111,
221,
172,
123,
235,
79,
17837,
226,
17716,
267,
298,
3438,
582,
499,
12,
272,
1660,
199,
61,
199,
199,
50,
2533,
14673,
275,
469,
272,
283,
496,
311,
1086,
356,
16870,
1802,
582,
399,
2,
141,
251,
5806,
142,
233,
141,
237,
13,
159,
229,
224,
21874,
8474,
11487,
27,
221,
5806,
142,
242,
12,
7038,
242,
141,
225,
142,
236,
7038,
103,
141,
225,
5657,
76,
142,
236,
3570,
467,
272,
283,
20525,
356,
359,
267,
469,
288,
298,
1648,
63,
1507,
582,
378,
12,
288,
298,
354,
582,
399,
2,
86,
31087,
133,
121,
133,
119,
131,
223,
158,
114,
123,
130,
225,
133,
119,
134,
236,
134,
238,
401,
288,
298,
7650,
582,
399,
2,
129,
100,
31087,
87,
373,
133,
119,
134,
236,
134,
102,
134,
230,
129,
240,
221,
134,
102,
83,
221,
130,
101,
129,
101,
134,
230,
373,
31087,
133,
121,
133,
119,
131,
223,
158,
114,
123,
130,
225,
133,
119,
134,
236,
134,
238,
15583,
288,
298,
1419,
582,
820,
2533,
14673,
63,
8808,
267,
1660,
267,
469,
288,
298,
1648,
63,
1507,
582,
413,
12,
288,
298,
354,
582,
399,
2,
172,
120,
256,
134,
121,
157,
117,
227,
157,
118,
242,
157,
118,
242,
157,
117,
227,
134,
121,
401,
288,
298,
7650,
582,
399,
2,
173,
252,
244,
112,
173,
252,
245,
243,
173,
252,
245,
251,
221,
173,
252,
245,
231,
173,
252,
245,
243,
173,
252,
245,
246,
173,
252,
245,
246,
173,
252,
245,
233,
173,
252,
245,
231,
173,
252,
245,
248,
221,
173,
252,
245,
237,
173,
252,
245,
247,
221,
173,
252,
245,
248,
173,
252,
245,
236,
173,
252,
245,
233,
221,
173,
252,
245,
235,
173,
252,
245,
246,
173,
252,
245,
229,
173,
252,
245,
241,
173,
252,
245,
241,
173,
252,
245,
229,
173,
252,
245,
246,
15583,
288,
298,
1419,
582,
820,
2533,
14673,
63,
8808,
267,
789,
272,
1622,
199,
93,
199,
199,
8918,
275,
359,
272,
469,
267,
283,
5934,
356,
334,
288,
399,
2,
173,
252,
244,
124,
173,
252,
245,
236,
173,
252,
245,
233,
173,
252,
245,
246,
173,
252,
245,
233,
221,
173,
252,
245,
229,
173,
252,
245,
246,
173,
252,
245,
233,
221,
173,
252,
245,
231,
173,
252,
245,
233,
173,
252,
245,
246,
173,
252,
245,
248,
173,
252,
245,
229,
173,
252,
245,
237,
173,
252,
245,
242,
221,
173,
252,
245,
245,
173,
252,
245,
249,
173,
252,
245,
233,
173,
252,
245,
233,
173,
252,
245,
246,
221,
173,
252,
245,
248,
173,
252,
245,
237,
173,
252,
245,
241,
173,
252,
245,
233,
173,
252,
245,
247,
221,
173,
252,
245,
229,
173,
252,
245,
242,
173,
252,
245,
232,
221,
173,
252,
245,
243,
173,
252,
245,
231,
173,
252,
245,
231,
173,
252,
245,
229,
173,
252,
245,
247,
173,
252,
245,
237,
173,
252,
245,
243,
173,
252,
245,
242,
173,
252,
245,
247,
221,
173,
252,
245,
237,
173,
252,
245,
242,
221,
173,
252,
245,
248,
173,
252,
245,
236,
173,
252,
245,
237,
173,
252,
245,
247,
221,
173,
252,
245,
247,
173,
252,
245,
248,
173,
252,
245,
246,
173,
252,
245,
229,
173,
252,
245,
242,
173,
252,
245,
235,
173,
252,
245,
233,
221,
173,
252,
245,
241,
173,
252,
245,
237,
173,
252,
245,
252,
173,
252,
245,
233,
173,
252,
245,
232,
221,
173,
252,
245,
229,
173,
252,
245,
234,
173,
252,
245,
234,
173,
252,
245,
229,
173,
252,
245,
237,
173,
252,
245,
246,
221,
173,
252,
245,
251,
173,
252
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
22185,
1202,
465,
511,
666,
14,
199,
624,
199,
199,
840,
29317,
63,
10439,
275,
469,
272,
283,
5500,
63,
344,
356,
399,
7,
173,
252,
242,
122,
173,
252,
242,
107,
173,
252,
242,
121,
173,
252,
242,
122,
221,
173,
252,
242,
121,
173,
252,
242,
122,
173,
252,
242,
123,
173,
252,
242,
256,
173,
252,
242,
107,
173,
252,
242,
116,
173,
252,
242,
122,
297,
272,
283,
1053,
63,
344,
356,
399,
7,
173,
252,
245,
248,
173,
252,
245,
233,
173,
252,
245,
247,
173,
252,
245,
248,
221,
173,
252,
245,
237,
173,
252,
245,
248,
173,
252,
245,
233,
173,
252,
245,
241,
297,
272,
283,
1972,
63,
344,
356,
399,
7,
146,
230,
142,
243,
157,
117,
97,
146,
230,
221,
25128,
157,
118,
238,
157,
117,
96,
141,
112,
157,
117,
97,
142,
243,
297,
272,
283,
1053,
63,
466,
356,
399,
7,
1490,
17452,
7,
199,
93,
199,
199,
5622,
12018,
275,
791,
505,
356,
399,
7,
158,
119,
246,
128,
105,
158,
118,
95,
158,
119,
246,
13333,
98,
158,
118,
228,
158,
118,
95,
158,
119,
228,
128,
105,
158,
118,
250,
936,
199,
199,
50,
2533,
14673,
63,
8808,
275,
359,
272,
469,
267,
298,
1648,
63,
1507,
582,
378,
12,
267,
298,
354,
582,
399,
2,
173,
252,
241,
240,
173,
252,
241,
239,
173,
252,
241,
239,
173,
252,
241,
242,
401,
267,
298,
15228,
582,
399,
2,
173,
252,
244,
120,
173,
252,
245,
243,
173,
252,
245,
243,
173,
252,
245,
246,
221,
173,
252,
245,
238,
173,
252,
245,
243,
173,
252,
245,
230,
17716,
267,
298,
3438,
582,
378,
12,
272,
1660,
272,
469,
267,
298,
1648,
63,
1507,
582,
413,
12,
267,
298,
354,
582,
399,
2,
173,
252,
242,
109,
173,
252,
242,
117,
173,
252,
242,
117,
173,
252,
242,
256,
401,
267,
298,
15228,
582,
399,
2,
172,
120,
256,
142,
120,
142,
120,
134,
246,
221,
172,
120,
252,
142,
120,
157,
118,
241,
17716,
267,
298,
3438,
582,
413,
12,
272,
1660,
272,
469,
267,
298,
1648,
63,
1507,
582,
499,
12,
267,
298,
354,
582,
399,
2,
142,
243,
140,
230,
127,
96,
142,
243,
159,
227,
242,
159,
227,
242,
142,
243,
21694,
7413,
401,
267,
298,
15228,
582,
399,
2,
17837,
230,
172,
123,
241,
67,
17837,
230,
172,
123,
249,
172,
123,
249,
17837,
230,
9051,
223,
172,
122,
111,
221,
172,
123,
235,
79,
17837,
226,
17716,
267,
298,
3438,
582,
499,
12,
272,
1660,
199,
61,
199,
199,
50,
2533,
14673,
275,
469,
272,
283,
496,
311,
1086,
356,
16870,
1802,
582,
399,
2,
141,
251,
5806,
142,
233,
141,
237,
13,
159,
229,
224,
21874,
8474,
11487,
27,
221,
5806,
142,
242,
12,
7038,
242,
141,
225,
142,
236,
7038,
103,
141,
225,
5657,
76,
142,
236,
3570,
467,
272,
283,
20525,
356,
359,
267,
469,
288,
298,
1648,
63,
1507,
582,
378,
12,
288,
298,
354,
582,
399,
2,
86,
31087,
133,
121,
133,
119,
131,
223,
158,
114,
123,
130,
225,
133,
119,
134,
236,
134,
238,
401,
288,
298,
7650,
582,
399,
2,
129,
100,
31087,
87,
373,
133,
119,
134,
236,
134,
102,
134,
230,
129,
240,
221,
134,
102,
83,
221,
130,
101,
129,
101,
134,
230,
373,
31087,
133,
121,
133,
119,
131,
223,
158,
114,
123,
130,
225,
133,
119,
134,
236,
134,
238,
15583,
288,
298,
1419,
582,
820,
2533,
14673,
63,
8808,
267,
1660,
267,
469,
288,
298,
1648,
63,
1507,
582,
413,
12,
288,
298,
354,
582,
399,
2,
172,
120,
256,
134,
121,
157,
117,
227,
157,
118,
242,
157,
118,
242,
157,
117,
227,
134,
121,
401,
288,
298,
7650,
582,
399,
2,
173,
252,
244,
112,
173,
252,
245,
243,
173,
252,
245,
251,
221,
173,
252,
245,
231,
173,
252,
245,
243,
173,
252,
245,
246,
173,
252,
245,
246,
173,
252,
245,
233,
173,
252,
245,
231,
173,
252,
245,
248,
221,
173,
252,
245,
237,
173,
252,
245,
247,
221,
173,
252,
245,
248,
173,
252,
245,
236,
173,
252,
245,
233,
221,
173,
252,
245,
235,
173,
252,
245,
246,
173,
252,
245,
229,
173,
252,
245,
241,
173,
252,
245,
241,
173,
252,
245,
229,
173,
252,
245,
246,
15583,
288,
298,
1419,
582,
820,
2533,
14673,
63,
8808,
267,
789,
272,
1622,
199,
93,
199,
199,
8918,
275,
359,
272,
469,
267,
283,
5934,
356,
334,
288,
399,
2,
173,
252,
244,
124,
173,
252,
245,
236,
173,
252,
245,
233,
173,
252,
245,
246,
173,
252,
245,
233,
221,
173,
252,
245,
229,
173,
252,
245,
246,
173,
252,
245,
233,
221,
173,
252,
245,
231,
173,
252,
245,
233,
173,
252,
245,
246,
173,
252,
245,
248,
173,
252,
245,
229,
173,
252,
245,
237,
173,
252,
245,
242,
221,
173,
252,
245,
245,
173,
252,
245,
249,
173,
252,
245,
233,
173,
252,
245,
233,
173,
252,
245,
246,
221,
173,
252,
245,
248,
173,
252,
245,
237,
173,
252,
245,
241,
173,
252,
245,
233,
173,
252,
245,
247,
221,
173,
252,
245,
229,
173,
252,
245,
242,
173,
252,
245,
232,
221,
173,
252,
245,
243,
173,
252,
245,
231,
173,
252,
245,
231,
173,
252,
245,
229,
173,
252,
245,
247,
173,
252,
245,
237,
173,
252,
245,
243,
173,
252,
245,
242,
173,
252,
245,
247,
221,
173,
252,
245,
237,
173,
252,
245,
242,
221,
173,
252,
245,
248,
173,
252,
245,
236,
173,
252,
245,
237,
173,
252,
245,
247,
221,
173,
252,
245,
247,
173,
252,
245,
248,
173,
252,
245,
246,
173,
252,
245,
229,
173,
252,
245,
242,
173,
252,
245,
235,
173,
252,
245,
233,
221,
173,
252,
245,
241,
173,
252,
245,
237,
173,
252,
245,
252,
173,
252,
245,
233,
173,
252,
245,
232,
221,
173,
252,
245,
229,
173,
252,
245,
234,
173,
252,
245,
234,
173,
252,
245,
229,
173,
252,
245,
237,
173,
252,
245,
246,
221,
173,
252,
245,
251,
173,
252,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
danakj/chromium
|
third_party/libxml/src/check-xinclude-test-suite.py
|
347
|
5333
|
#!/usr/bin/python
import sys
import time
import os
import string
sys.path.insert(0, "python")
import libxml2
#
# the testsuite description
#
DIR="xinclude-test-suite"
CONF="testdescr.xml"
LOG="check-xinclude-test-suite.log"
log = open(LOG, "w")
os.chdir(DIR)
test_nr = 0
test_succeed = 0
test_failed = 0
test_error = 0
#
# Error and warning handlers
#
error_nr = 0
error_msg = ''
def errorHandler(ctx, str):
global error_nr
global error_msg
if string.find(str, "error:") >= 0:
error_nr = error_nr + 1
if len(error_msg) < 300:
if len(error_msg) == 0 or error_msg[-1] == '\n':
error_msg = error_msg + " >>" + str
else:
error_msg = error_msg + str
libxml2.registerErrorHandler(errorHandler, None)
def testXInclude(filename, id):
global error_nr
global error_msg
global log
error_nr = 0
error_msg = ''
print "testXInclude(%s, %s)" % (filename, id)
return 1
def runTest(test, basedir):
global test_nr
global test_failed
global test_error
global test_succeed
global error_msg
global log
fatal_error = 0
uri = test.prop('href')
id = test.prop('id')
type = test.prop('type')
if uri == None:
print "Test without ID:", uri
return -1
if id == None:
print "Test without URI:", id
return -1
if type == None:
print "Test without URI:", id
return -1
if basedir != None:
URI = basedir + "/" + uri
else:
URI = uri
if os.access(URI, os.R_OK) == 0:
print "Test %s missing: base %s uri %s" % (URI, basedir, uri)
return -1
expected = None
outputfile = None
diff = None
if type != 'error':
output = test.xpathEval('string(output)')
if output == 'No output file.':
output = None
if output == '':
output = None
if output != None:
if basedir != None:
output = basedir + "/" + output
if os.access(output, os.R_OK) == 0:
print "Result for %s missing: %s" % (id, output)
output = None
else:
try:
f = open(output)
expected = f.read()
outputfile = output
except:
print "Result for %s unreadable: %s" % (id, output)
try:
# print "testing %s" % (URI)
doc = libxml2.parseFile(URI)
except:
doc = None
if doc != None:
res = doc.xincludeProcess()
if res >= 0 and expected != None:
result = doc.serialize()
if result != expected:
print "Result for %s differs" % (id)
open("xinclude.res", "w").write(result)
diff = os.popen("diff %s xinclude.res" % outputfile).read()
doc.freeDoc()
else:
print "Failed to parse %s" % (URI)
res = -1
test_nr = test_nr + 1
if type == 'success':
if res > 0:
test_succeed = test_succeed + 1
elif res == 0:
test_failed = test_failed + 1
print "Test %s: no substitution done ???" % (id)
elif res < 0:
test_error = test_error + 1
print "Test %s: failed valid XInclude processing" % (id)
elif type == 'error':
if res > 0:
test_error = test_error + 1
print "Test %s: failed to detect invalid XInclude processing" % (id)
elif res == 0:
test_failed = test_failed + 1
print "Test %s: Invalid but no substitution done" % (id)
elif res < 0:
test_succeed = test_succeed + 1
elif type == 'optional':
if res > 0:
test_succeed = test_succeed + 1
else:
print "Test %s: failed optional test" % (id)
# Log the ontext
if res != 1:
log.write("Test ID %s\n" % (id))
log.write(" File: %s\n" % (URI))
content = string.strip(test.content)
while content[-1] == '\n':
content = content[0:-1]
log.write(" %s:%s\n\n" % (type, content))
if error_msg != '':
log.write(" ----\n%s ----\n" % (error_msg))
error_msg = ''
log.write("\n")
if diff != None:
log.write("diff from test %s:\n" %(id))
log.write(" -----------\n%s\n -----------\n" % (diff));
return 0
def runTestCases(case):
creator = case.prop('creator')
if creator != None:
print "=>", creator
base = case.getBase(None)
basedir = case.prop('basedir')
if basedir != None:
base = libxml2.buildURI(basedir, base)
test = case.children
while test != None:
if test.name == 'testcase':
runTest(test, base)
if test.name == 'testcases':
runTestCases(test)
test = test.next
conf = libxml2.parseFile(CONF)
if conf == None:
print "Unable to load %s" % CONF
sys.exit(1)
testsuite = conf.getRootElement()
if testsuite.name != 'testsuite':
print "Expecting TESTSUITE root element: aborting"
sys.exit(1)
profile = testsuite.prop('PROFILE')
if profile != None:
print profile
start = time.time()
case = testsuite.children
while case != None:
if case.name == 'testcases':
old_test_nr = test_nr
old_test_succeed = test_succeed
old_test_failed = test_failed
old_test_error = test_error
runTestCases(case)
print " Ran %d tests: %d suceeded, %d failed and %d generated an error" % (
test_nr - old_test_nr, test_succeed - old_test_succeed,
test_failed - old_test_failed, test_error - old_test_error)
case = case.next
conf.freeDoc()
log.close()
print "Ran %d tests: %d suceeded, %d failed and %d generated an error in %.2f s." % (
test_nr, test_succeed, test_failed, test_error, time.time() - start)
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
646,
984,
199,
646,
900,
199,
646,
747,
199,
646,
1059,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
298,
1548,
531,
199,
646,
15404,
18,
199,
199,
3,
199,
3,
314,
2295,
2577,
1369,
199,
3,
199,
3022,
628,
88,
2613,
13,
396,
13,
5768,
2,
199,
3103,
628,
396,
12113,
14,
1652,
2,
199,
4947,
628,
1074,
13,
88,
2613,
13,
396,
13,
5768,
14,
793,
2,
199,
199,
793,
275,
1551,
8,
4947,
12,
298,
87,
531,
199,
199,
736,
14,
8563,
8,
3022,
9,
199,
199,
396,
63,
7865,
275,
378,
199,
396,
63,
26622,
275,
378,
199,
396,
63,
4892,
275,
378,
199,
396,
63,
705,
275,
378,
199,
3,
199,
3,
4520,
436,
5721,
8297,
199,
3,
199,
705,
63,
7865,
275,
378,
199,
705,
63,
1328,
275,
2125,
199,
199,
318,
1125,
2461,
8,
3799,
12,
620,
304,
272,
2288,
1125,
63,
7865,
272,
2288,
1125,
63,
1328,
339,
340,
1059,
14,
1623,
8,
495,
12,
298,
705,
9107,
2356,
378,
26,
199,
198,
705,
63,
7865,
275,
1125,
63,
7865,
435,
413,
272,
340,
822,
8,
705,
63,
1328,
9,
665,
9601,
26,
267,
340,
822,
8,
705,
63,
1328,
9,
508,
378,
503,
1125,
63,
1328,
1988,
17,
61,
508,
1557,
78,
356,
6722,
1125,
63,
1328,
275,
1125,
63,
1328,
435,
298,
257,
4331,
2,
435,
620,
199,
198,
2836,
26,
6722,
1125,
63,
1328,
275,
1125,
63,
1328,
435,
620,
199,
199,
773,
1652,
18,
14,
2683,
25933,
8,
705,
2461,
12,
488,
9,
199,
199,
318,
511,
56,
7826,
8,
1501,
12,
1305,
304,
272,
2288,
1125,
63,
7865,
272,
2288,
1125,
63,
1328,
272,
2288,
943,
339,
1125,
63,
7865,
275,
378,
272,
1125,
63,
1328,
275,
2125,
339,
870,
298,
396,
56,
7826,
4042,
83,
12,
450,
83,
2924,
450,
334,
1501,
12,
1305,
9,
272,
372,
413,
199,
199,
318,
29779,
8,
396,
12,
19380,
304,
272,
2288,
511,
63,
7865,
272,
2288,
511,
63,
4892,
272,
2288,
511,
63,
705,
272,
2288,
511,
63,
26622,
272,
2288,
1125,
63,
1328,
272,
2288,
943,
339,
14294,
63,
705,
275,
378,
272,
5108,
275,
511,
14,
4469,
360,
6399,
358,
272,
1305,
275,
511,
14,
4469,
360,
344,
358,
272,
730,
275,
511,
14,
4469,
360,
466,
358,
272,
340,
5108,
508,
488,
26,
267,
870,
298,
774,
1928,
2870,
6783,
5108,
199,
198,
1107,
446,
17,
272,
340,
1305,
508,
488,
26,
267,
870,
298,
774,
1928,
9022,
6783,
1305,
199,
198,
1107,
446,
17,
272,
340,
730,
508,
488,
26,
267,
870,
298,
774,
1928,
9022,
6783,
1305,
199,
198,
1107,
446,
17,
272,
340,
19380,
1137,
488,
26,
199,
198,
7639,
275,
19380,
435,
10609,
435,
5108,
272,
587,
26,
267,
9022,
275,
5108,
272,
340,
747,
14,
2732,
8,
7639,
12,
747,
14,
50,
63,
3593,
9,
508,
378,
26,
267,
870,
298,
774,
450,
83,
4124,
26,
1300,
450,
83,
5108,
450,
83,
2,
450,
334,
7639,
12,
19380,
12,
5108,
9,
199,
198,
1107,
446,
17,
339,
1420,
275,
488,
272,
32513,
275,
488,
272,
3915,
275,
488,
272,
340,
730,
1137,
283,
705,
356,
199,
198,
1199,
275,
511,
14,
8006,
10006,
360,
875,
8,
1199,
5942,
199,
198,
692,
1072,
508,
283,
1944,
1072,
570,
10586,
6722,
1072,
275,
488,
199,
198,
692,
1072,
508,
8061,
6722,
1072,
275,
488,
199,
198,
692,
1072,
1137,
488,
26,
6722,
340,
19380,
1137,
488,
26,
507,
198,
1199,
275,
19380,
435,
10609,
435,
1072,
6722,
340,
747,
14,
2732,
8,
1199,
12,
747,
14,
50,
63,
3593,
9,
508,
378,
26,
507,
198,
1361,
298,
2889,
367,
450,
83,
4124,
26,
450,
83,
2,
450,
334,
344,
12,
1072,
9,
507,
198,
1199,
275,
488,
6722,
587,
26,
507,
198,
893,
26,
15075,
289,
275,
1551,
8,
1199,
9,
15075,
1420,
275,
289,
14,
739,
342,
15075,
32513,
275,
1072,
507,
198,
2590,
26,
15075,
870,
298,
2889,
367,
450,
83,
625,
11875,
26,
450,
83,
2,
450,
334,
344,
12,
1072,
9,
339,
862,
26,
267,
327,
870,
298,
4776,
450,
83,
2,
450,
334,
7639,
9,
199,
198,
1301,
275,
15404,
18,
14,
1122,
1173,
8,
7639,
9,
272,
871,
26,
267,
1382,
275,
488,
272,
340,
1382,
1137,
488,
26,
267,
522,
275,
1382,
14,
88,
2613,
3498,
342,
199,
198,
692,
522,
2356,
378,
436,
1420,
1137,
488,
26,
6722,
754,
275,
1382,
14,
3549,
342,
6722,
340,
754,
1137,
1420,
26,
507,
263,
870,
298,
2889,
367,
450,
83,
22754,
2,
450,
334,
344,
9,
507,
198,
1490,
480,
88,
2613,
14,
470,
401,
298,
87,
3471,
952,
8,
1099,
9,
507,
198,
3028,
275,
747,
14,
12207,
480,
3028,
450,
83,
671,
2613,
14,
470,
2,
450,
32513,
680,
739,
342,
421,
198,
1301,
14,
4624,
3768,
342,
272,
587,
26,
267,
870,
298,
4276,
370,
2198,
450,
83,
2,
450,
334,
7639,
9,
199,
198,
470,
275,
446,
17,
10813,
339,
511,
63,
7865,
275,
511,
63,
7865,
435,
413,
272,
340,
730,
508,
283,
3742,
356,
199,
198,
692,
522,
690,
378,
26,
6722,
511,
63,
26622,
275,
511,
63,
26622,
435,
413,
199,
198,
4164,
522,
508,
378,
26,
6722,
511,
63,
4892,
275,
511,
63,
4892,
435,
413,
6722,
870,
298,
774,
450,
83,
26,
949,
20584,
4224,
5805,
10674,
2,
450,
334,
344,
9,
199,
198,
4164,
522,
665,
378,
26,
6722,
511,
63,
705,
275,
511,
63,
705,
435,
413,
6722,
870,
298,
774,
450,
83,
26,
3405,
1686,
1323,
7826,
6661,
2,
450,
334,
344,
9,
272,
916,
730,
508,
283,
705,
356,
199,
198,
692,
522,
690,
378,
26,
6722,
511,
63,
705,
275,
511,
63,
705,
435,
413,
6722,
870,
298,
774,
450,
83,
26,
3405,
370,
9696,
3866,
1323,
7826,
6661,
2,
450,
334,
344,
9,
199,
198,
4164,
522,
508,
378,
26,
6722,
511,
63,
4892,
275,
511,
63,
4892,
435,
413,
6722,
870,
298,
774,
450,
83,
26,
6378,
1325,
949,
20584,
4224,
2,
450,
334,
344,
9,
199,
198,
4164,
522,
665,
378,
26,
6722,
511,
63
] |
[
2647,
15,
1393,
15,
1548,
199,
646,
984,
199,
646,
900,
199,
646,
747,
199,
646,
1059,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
298,
1548,
531,
199,
646,
15404,
18,
199,
199,
3,
199,
3,
314,
2295,
2577,
1369,
199,
3,
199,
3022,
628,
88,
2613,
13,
396,
13,
5768,
2,
199,
3103,
628,
396,
12113,
14,
1652,
2,
199,
4947,
628,
1074,
13,
88,
2613,
13,
396,
13,
5768,
14,
793,
2,
199,
199,
793,
275,
1551,
8,
4947,
12,
298,
87,
531,
199,
199,
736,
14,
8563,
8,
3022,
9,
199,
199,
396,
63,
7865,
275,
378,
199,
396,
63,
26622,
275,
378,
199,
396,
63,
4892,
275,
378,
199,
396,
63,
705,
275,
378,
199,
3,
199,
3,
4520,
436,
5721,
8297,
199,
3,
199,
705,
63,
7865,
275,
378,
199,
705,
63,
1328,
275,
2125,
199,
199,
318,
1125,
2461,
8,
3799,
12,
620,
304,
272,
2288,
1125,
63,
7865,
272,
2288,
1125,
63,
1328,
339,
340,
1059,
14,
1623,
8,
495,
12,
298,
705,
9107,
2356,
378,
26,
199,
198,
705,
63,
7865,
275,
1125,
63,
7865,
435,
413,
272,
340,
822,
8,
705,
63,
1328,
9,
665,
9601,
26,
267,
340,
822,
8,
705,
63,
1328,
9,
508,
378,
503,
1125,
63,
1328,
1988,
17,
61,
508,
1557,
78,
356,
6722,
1125,
63,
1328,
275,
1125,
63,
1328,
435,
298,
257,
4331,
2,
435,
620,
199,
198,
2836,
26,
6722,
1125,
63,
1328,
275,
1125,
63,
1328,
435,
620,
199,
199,
773,
1652,
18,
14,
2683,
25933,
8,
705,
2461,
12,
488,
9,
199,
199,
318,
511,
56,
7826,
8,
1501,
12,
1305,
304,
272,
2288,
1125,
63,
7865,
272,
2288,
1125,
63,
1328,
272,
2288,
943,
339,
1125,
63,
7865,
275,
378,
272,
1125,
63,
1328,
275,
2125,
339,
870,
298,
396,
56,
7826,
4042,
83,
12,
450,
83,
2924,
450,
334,
1501,
12,
1305,
9,
272,
372,
413,
199,
199,
318,
29779,
8,
396,
12,
19380,
304,
272,
2288,
511,
63,
7865,
272,
2288,
511,
63,
4892,
272,
2288,
511,
63,
705,
272,
2288,
511,
63,
26622,
272,
2288,
1125,
63,
1328,
272,
2288,
943,
339,
14294,
63,
705,
275,
378,
272,
5108,
275,
511,
14,
4469,
360,
6399,
358,
272,
1305,
275,
511,
14,
4469,
360,
344,
358,
272,
730,
275,
511,
14,
4469,
360,
466,
358,
272,
340,
5108,
508,
488,
26,
267,
870,
298,
774,
1928,
2870,
6783,
5108,
199,
198,
1107,
446,
17,
272,
340,
1305,
508,
488,
26,
267,
870,
298,
774,
1928,
9022,
6783,
1305,
199,
198,
1107,
446,
17,
272,
340,
730,
508,
488,
26,
267,
870,
298,
774,
1928,
9022,
6783,
1305,
199,
198,
1107,
446,
17,
272,
340,
19380,
1137,
488,
26,
199,
198,
7639,
275,
19380,
435,
10609,
435,
5108,
272,
587,
26,
267,
9022,
275,
5108,
272,
340,
747,
14,
2732,
8,
7639,
12,
747,
14,
50,
63,
3593,
9,
508,
378,
26,
267,
870,
298,
774,
450,
83,
4124,
26,
1300,
450,
83,
5108,
450,
83,
2,
450,
334,
7639,
12,
19380,
12,
5108,
9,
199,
198,
1107,
446,
17,
339,
1420,
275,
488,
272,
32513,
275,
488,
272,
3915,
275,
488,
272,
340,
730,
1137,
283,
705,
356,
199,
198,
1199,
275,
511,
14,
8006,
10006,
360,
875,
8,
1199,
5942,
199,
198,
692,
1072,
508,
283,
1944,
1072,
570,
10586,
6722,
1072,
275,
488,
199,
198,
692,
1072,
508,
8061,
6722,
1072,
275,
488,
199,
198,
692,
1072,
1137,
488,
26,
6722,
340,
19380,
1137,
488,
26,
507,
198,
1199,
275,
19380,
435,
10609,
435,
1072,
6722,
340,
747,
14,
2732,
8,
1199,
12,
747,
14,
50,
63,
3593,
9,
508,
378,
26,
507,
198,
1361,
298,
2889,
367,
450,
83,
4124,
26,
450,
83,
2,
450,
334,
344,
12,
1072,
9,
507,
198,
1199,
275,
488,
6722,
587,
26,
507,
198,
893,
26,
15075,
289,
275,
1551,
8,
1199,
9,
15075,
1420,
275,
289,
14,
739,
342,
15075,
32513,
275,
1072,
507,
198,
2590,
26,
15075,
870,
298,
2889,
367,
450,
83,
625,
11875,
26,
450,
83,
2,
450,
334,
344,
12,
1072,
9,
339,
862,
26,
267,
327,
870,
298,
4776,
450,
83,
2,
450,
334,
7639,
9,
199,
198,
1301,
275,
15404,
18,
14,
1122,
1173,
8,
7639,
9,
272,
871,
26,
267,
1382,
275,
488,
272,
340,
1382,
1137,
488,
26,
267,
522,
275,
1382,
14,
88,
2613,
3498,
342,
199,
198,
692,
522,
2356,
378,
436,
1420,
1137,
488,
26,
6722,
754,
275,
1382,
14,
3549,
342,
6722,
340,
754,
1137,
1420,
26,
507,
263,
870,
298,
2889,
367,
450,
83,
22754,
2,
450,
334,
344,
9,
507,
198,
1490,
480,
88,
2613,
14,
470,
401,
298,
87,
3471,
952,
8,
1099,
9,
507,
198,
3028,
275,
747,
14,
12207,
480,
3028,
450,
83,
671,
2613,
14,
470,
2,
450,
32513,
680,
739,
342,
421,
198,
1301,
14,
4624,
3768,
342,
272,
587,
26,
267,
870,
298,
4276,
370,
2198,
450,
83,
2,
450,
334,
7639,
9,
199,
198,
470,
275,
446,
17,
10813,
339,
511,
63,
7865,
275,
511,
63,
7865,
435,
413,
272,
340,
730,
508,
283,
3742,
356,
199,
198,
692,
522,
690,
378,
26,
6722,
511,
63,
26622,
275,
511,
63,
26622,
435,
413,
199,
198,
4164,
522,
508,
378,
26,
6722,
511,
63,
4892,
275,
511,
63,
4892,
435,
413,
6722,
870,
298,
774,
450,
83,
26,
949,
20584,
4224,
5805,
10674,
2,
450,
334,
344,
9,
199,
198,
4164,
522,
665,
378,
26,
6722,
511,
63,
705,
275,
511,
63,
705,
435,
413,
6722,
870,
298,
774,
450,
83,
26,
3405,
1686,
1323,
7826,
6661,
2,
450,
334,
344,
9,
272,
916,
730,
508,
283,
705,
356,
199,
198,
692,
522,
690,
378,
26,
6722,
511,
63,
705,
275,
511,
63,
705,
435,
413,
6722,
870,
298,
774,
450,
83,
26,
3405,
370,
9696,
3866,
1323,
7826,
6661,
2,
450,
334,
344,
9,
199,
198,
4164,
522,
508,
378,
26,
6722,
511,
63,
4892,
275,
511,
63,
4892,
435,
413,
6722,
870,
298,
774,
450,
83,
26,
6378,
1325,
949,
20584,
4224,
2,
450,
334,
344,
9,
199,
198,
4164,
522,
665,
378,
26,
6722,
511,
63,
0
] |
[
1,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BertrandBordage/cmsplugin-filer
|
cmsplugin_filer_image/models.py
|
4
|
4881
|
from django.utils.translation import ugettext_lazy as _
from django.db import models
from cms.models import CMSPlugin, Page
from cms.models.fields import PageField
from posixpath import join, basename, splitext, exists
from filer.fields.image import FilerImageField
from filer.fields.file import FilerFileField
from cms import settings as cms_settings
from django.conf import settings
from cmsplugin_filer_utils import FilerPluginManager
class FilerImage(CMSPlugin):
LEFT = "left"
RIGHT = "right"
FLOAT_CHOICES = ((LEFT, _("left")),
(RIGHT, _("right")),
)
caption_text = models.CharField(_("caption text"), null=True, blank=True, max_length=255)
image = FilerImageField(null=True, blank=True, default=None, verbose_name=_("image"))
image_url = models.URLField(_("alternative image url"), verify_exists=False, null=True, blank=True, default=None)
alt_text = models.CharField(_("alt text"), null=True, blank=True, max_length=255)
thumbnail_option = models.ForeignKey('ThumbnailOption', null=True, blank=True, verbose_name=_("thumbnail option"))
use_autoscale = models.BooleanField(_("use automatic scaling"), default=False,
help_text=_('tries to auto scale the image based on the placeholder context'))
width = models.PositiveIntegerField(_("width"), null=True, blank=True)
height = models.PositiveIntegerField(_("height"), null=True, blank=True)
crop = models.BooleanField(_("crop"), default=True)
upscale = models.BooleanField(_("upscale"), default=True)
alignment = models.CharField(_("image alignment"), max_length=10, blank=True, null=True, choices=FLOAT_CHOICES)
free_link = models.CharField(_("link"), max_length=255, blank=True, null=True,
help_text=_("if present image will be clickable"))
page_link = PageField(null=True, blank=True,
help_text=_("if present image will be clickable"),
verbose_name=_("page link"))
file_link = FilerFileField(null=True, blank=True, default=None, verbose_name=_("file link"), help_text=_("if present image will be clickable"), related_name='+')
original_link = models.BooleanField(_("link original image"), default=False, help_text=_("if present image will be clickable"))
description = models.TextField(_("description"), blank=True, null=True)
# we only add the image to select_related. page_link and file_link are FKs
# as well, but they are not used often enough to warrant the impact of two
# additional LEFT OUTER JOINs.
objects = FilerPluginManager(select_related=('image',))
class Meta:
verbose_name = _("filer image")
verbose_name_plural = _("filer images")
def clean(self):
from django.core.exceptions import ValidationError
# Make sure that either image or image_url is set
if (not self.image and not self.image_url) or (self.image and self.image_url):
raise ValidationError(_('Either an image or an image url must be selected.'))
def __unicode__(self):
if self.image:
return self.image.label
else:
return unicode( _("Image Publication %(caption)s") % {'caption': self.caption or self.alt} )
return ''
@property
def caption(self):
if self.image:
return self.caption_text or self.image.default_caption
else:
return self.caption_text
@property
def alt(self):
if self.image:
return self.alt_text or self.image.default_alt_text or self.image.label
else:
return self.alt_text
@property
def link(self):
if self.free_link:
return self.free_link
elif self.page_link:
return self.page_link.get_absolute_url()
elif self.file_link:
return self.file_link.url
elif self.original_link:
if self.image:
return self.image.url
else:
return self.image_url
else:
return ''
class ThumbnailOption(models.Model):
"""
This class defines the option use to create the thumbnail.
"""
name = models.CharField(_("name"), max_length=100)
width = models.IntegerField(_("width"), help_text=_('width in pixel.'))
height = models.IntegerField(_("height"), help_text=_('height in pixel.'))
crop = models.BooleanField(_("crop"), default=True)
upscale = models.BooleanField(_("upscale"), default=True)
class Meta:
ordering = ('width', 'height')
verbose_name = _("thumbnail option")
verbose_name_plural = _("thumbnail options")
def __unicode__(self):
return u'%s -- %s x %s' %(self.name, self.width, self.height)
|
mit
|
[
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
19240,
14,
992,
492,
29554,
5061,
12,
10331,
199,
504,
19240,
14,
992,
14,
955,
492,
10331,
792,
199,
504,
15454,
492,
4263,
12,
9593,
12,
2249,
7699,
12,
3495,
199,
504,
570,
82,
14,
955,
14,
1569,
492,
481,
3566,
21910,
199,
504,
570,
82,
14,
955,
14,
493,
492,
481,
3566,
23252,
199,
504,
19240,
492,
2202,
465,
19240,
63,
1751,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
6904,
30873,
63,
29292,
63,
1208,
492,
481,
3566,
5061,
2988,
421,
199,
533,
481,
3566,
3491,
8,
17834,
5061,
304,
272,
6578,
275,
298,
3039,
2,
272,
7052,
275,
298,
1019,
2,
272,
31241,
63,
16236,
275,
3666,
9894,
12,
3824,
3039,
8150,
2151,
334,
12811,
12,
3824,
1019,
8150,
2151,
776,
272,
19038,
63,
505,
275,
1709,
14,
2183,
6115,
13410,
1318,
1288,
2973,
29,
549,
12,
4596,
29,
549,
12,
1390,
63,
1267,
29,
2299,
9,
272,
1834,
275,
481,
3566,
21910,
8,
2307,
29,
549,
12,
4596,
29,
549,
12,
849,
29,
403,
12,
3376,
63,
354,
9384,
1569,
2237,
272,
1834,
63,
633,
275,
1709,
14,
17363,
6115,
19389,
1834,
1166,
1288,
4911,
63,
2444,
29,
797,
12,
2973,
29,
549,
12,
4596,
29,
549,
12,
849,
29,
403,
9,
272,
8791,
63,
505,
275,
1709,
14,
2183,
6115,
4478,
1318,
1288,
2973,
29,
549,
12,
4596,
29,
549,
12,
1390,
63,
1267,
29,
2299,
9,
272,
10062,
63,
1422,
275,
1709,
14,
3190,
360,
2719,
5820,
2602,
297,
2973,
29,
549,
12,
4596,
29,
549,
12,
3376,
63,
354,
9384,
8311,
945,
2237,
272,
675,
63,
29906,
275,
1709,
14,
5036,
6115,
1180,
4834,
13690,
1288,
849,
29,
797,
12,
221,
3147,
1720,
63,
505,
12397,
6264,
370,
2599,
4666,
314,
1834,
4079,
641,
314,
10069,
1067,
1333,
272,
3462,
275,
1709,
14,
8591,
6115,
2063,
1288,
2973,
29,
549,
12,
4596,
29,
549,
9,
272,
4569,
275,
1709,
14,
8591,
6115,
3333,
1288,
2973,
29,
549,
12,
4596,
29,
549,
9,
272,
18366,
275,
1709,
14,
5036,
6115,
15816,
1288,
849,
29,
549,
9,
272,
1536,
3467,
275,
1709,
14,
5036,
6115,
384,
3467,
1288,
849,
29,
549,
9,
272,
13177,
275,
1709,
14,
2183,
6115,
1569,
13177,
1288,
1390,
63,
1267,
29,
709,
12,
4596,
29,
549,
12,
2973,
29,
549,
12,
3415,
29,
11783,
63,
16236,
9,
2286,
2867,
63,
1073,
275,
1709,
14,
2183,
6115,
1073,
1288,
1390,
63,
1267,
29,
2299,
12,
4596,
29,
549,
12,
2973,
29,
549,
12,
221,
639,
1720,
63,
505,
9384,
692,
3451,
1834,
911,
506,
8968,
461,
2237,
272,
2034,
63,
1073,
275,
10331,
792,
8,
2307,
29,
549,
12,
4596,
29,
549,
12,
221,
2079,
1720,
63,
505,
9384,
692,
3451,
1834,
911,
506,
8968,
461,
1288,
2079,
3376,
63,
354,
9384,
1606,
2142,
2237,
272,
570,
63,
1073,
275,
481,
3566,
23252,
8,
2307,
29,
549,
12,
4596,
29,
549,
12,
849,
29,
403,
12,
3376,
63,
354,
9384,
493,
2142,
1288,
1720,
63,
505,
9384,
692,
3451,
1834,
911,
506,
8968,
461,
1288,
4048,
63,
354,
534,
13854,
272,
3379,
63,
1073,
275,
1709,
14,
5036,
6115,
1073,
3379,
1834,
1288,
849,
29,
797,
12,
1720,
63,
505,
9384,
692,
3451,
1834,
911,
506,
8968,
461,
2237,
272,
1369,
275,
1709,
14,
6254,
6115,
1802,
1288,
4596,
29,
549,
12,
2973,
29,
549,
9,
339,
327,
781,
1454,
1050,
314,
1834,
370,
3504,
63,
2407,
14,
2034,
63,
1073,
436,
570,
63,
1073,
787,
18821,
83,
272,
327,
465,
5521,
12,
1325,
2985,
787,
440,
1202,
14115,
8321,
370,
3429,
17633,
314,
25568,
402,
2877,
272,
327,
4722,
6578,
31682,
10593,
83,
14,
272,
2251,
275,
481,
3566,
5061,
2988,
8,
2416,
63,
2407,
7782,
1569,
16829,
2378,
1021,
6288,
26,
267,
3376,
63,
354,
275,
3824,
29292,
1834,
531,
267,
3376,
63,
354,
63,
10019,
275,
3824,
29292,
5935,
531,
2286,
347,
3633,
8,
277,
304,
267,
687,
1639,
14,
1018,
14,
3924,
492,
8505,
267,
327,
4155,
3238,
626,
1902,
1834,
503,
1834,
63,
633,
365,
663,
267,
340,
334,
1397,
291,
14,
1569,
436,
440,
291,
14,
1569,
63,
633,
9,
503,
334,
277,
14,
1569,
436,
291,
14,
1569,
63,
633,
304,
288,
746,
8505,
6723,
37,
1711,
376,
1834,
503,
376,
1834,
1166,
1471,
506,
4895,
12459,
25979,
347,
636,
2975,
721,
277,
304,
267,
340,
291,
14,
1569,
26,
288,
372,
291,
14,
1569,
14,
1302,
267,
587,
26,
288,
372,
2649,
8,
3824,
3491,
1684,
425,
2818,
13410,
9,
83,
531,
450,
791,
13410,
356,
291,
14,
13410,
503,
291,
14,
4478,
93,
776,
267,
372,
2125,
272,
768,
1829,
272,
347,
19038,
8,
277,
304,
267,
340,
291,
14,
1569,
26,
288,
372,
291,
14,
13410,
63,
505,
503,
291,
14,
1569,
14,
885,
63,
13410,
267,
587,
26,
288,
372,
291,
14,
13410,
63,
505,
272,
768,
1829,
272,
347,
8791,
8,
277,
304,
267,
340,
291,
14,
1569,
26,
288,
372,
291,
14,
4478,
63,
505,
503,
291,
14,
1569,
14,
885,
63,
4478,
63,
505,
503,
291,
14,
1569,
14,
1302,
267,
587,
26,
288,
372,
291,
14,
4478,
63,
505,
272,
768,
1829,
272,
347,
2142,
8,
277,
304,
267,
340,
291,
14,
4624,
63,
1073,
26,
288,
372,
291,
14,
4624,
63,
1073,
267,
916,
291,
14,
1606,
63,
1073,
26,
288,
372,
291,
14,
1606,
63,
1073,
14,
362,
63,
6116,
63,
633,
342,
267,
916,
291,
14,
493,
63,
1073,
26,
288,
372,
291,
14,
493,
63,
1073,
14,
633,
267,
916,
291,
14,
5043,
63,
1073,
26,
288,
340,
291,
14,
1569,
26,
355,
372,
291,
14,
1569,
14,
633,
288,
587,
26,
355,
372,
291,
14,
1569,
63,
633,
267,
587,
26,
288,
372,
2125,
268,
268,
199,
533,
3868,
5820,
2602,
8,
992,
14,
1685,
304,
272,
408,
272,
961,
1021,
7890,
314,
945,
675,
370,
1218,
314,
10062,
14,
272,
408,
272,
536,
275,
1709,
14,
2183,
6115,
354,
1288,
1390,
63,
1267,
29,
1960,
9,
272,
3462,
275,
1709,
14,
3901
] |
[
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
19240,
14,
992,
492,
29554,
5061,
12,
10331,
199,
504,
19240,
14,
992,
14,
955,
492,
10331,
792,
199,
504,
15454,
492,
4263,
12,
9593,
12,
2249,
7699,
12,
3495,
199,
504,
570,
82,
14,
955,
14,
1569,
492,
481,
3566,
21910,
199,
504,
570,
82,
14,
955,
14,
493,
492,
481,
3566,
23252,
199,
504,
19240,
492,
2202,
465,
19240,
63,
1751,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
6904,
30873,
63,
29292,
63,
1208,
492,
481,
3566,
5061,
2988,
421,
199,
533,
481,
3566,
3491,
8,
17834,
5061,
304,
272,
6578,
275,
298,
3039,
2,
272,
7052,
275,
298,
1019,
2,
272,
31241,
63,
16236,
275,
3666,
9894,
12,
3824,
3039,
8150,
2151,
334,
12811,
12,
3824,
1019,
8150,
2151,
776,
272,
19038,
63,
505,
275,
1709,
14,
2183,
6115,
13410,
1318,
1288,
2973,
29,
549,
12,
4596,
29,
549,
12,
1390,
63,
1267,
29,
2299,
9,
272,
1834,
275,
481,
3566,
21910,
8,
2307,
29,
549,
12,
4596,
29,
549,
12,
849,
29,
403,
12,
3376,
63,
354,
9384,
1569,
2237,
272,
1834,
63,
633,
275,
1709,
14,
17363,
6115,
19389,
1834,
1166,
1288,
4911,
63,
2444,
29,
797,
12,
2973,
29,
549,
12,
4596,
29,
549,
12,
849,
29,
403,
9,
272,
8791,
63,
505,
275,
1709,
14,
2183,
6115,
4478,
1318,
1288,
2973,
29,
549,
12,
4596,
29,
549,
12,
1390,
63,
1267,
29,
2299,
9,
272,
10062,
63,
1422,
275,
1709,
14,
3190,
360,
2719,
5820,
2602,
297,
2973,
29,
549,
12,
4596,
29,
549,
12,
3376,
63,
354,
9384,
8311,
945,
2237,
272,
675,
63,
29906,
275,
1709,
14,
5036,
6115,
1180,
4834,
13690,
1288,
849,
29,
797,
12,
221,
3147,
1720,
63,
505,
12397,
6264,
370,
2599,
4666,
314,
1834,
4079,
641,
314,
10069,
1067,
1333,
272,
3462,
275,
1709,
14,
8591,
6115,
2063,
1288,
2973,
29,
549,
12,
4596,
29,
549,
9,
272,
4569,
275,
1709,
14,
8591,
6115,
3333,
1288,
2973,
29,
549,
12,
4596,
29,
549,
9,
272,
18366,
275,
1709,
14,
5036,
6115,
15816,
1288,
849,
29,
549,
9,
272,
1536,
3467,
275,
1709,
14,
5036,
6115,
384,
3467,
1288,
849,
29,
549,
9,
272,
13177,
275,
1709,
14,
2183,
6115,
1569,
13177,
1288,
1390,
63,
1267,
29,
709,
12,
4596,
29,
549,
12,
2973,
29,
549,
12,
3415,
29,
11783,
63,
16236,
9,
2286,
2867,
63,
1073,
275,
1709,
14,
2183,
6115,
1073,
1288,
1390,
63,
1267,
29,
2299,
12,
4596,
29,
549,
12,
2973,
29,
549,
12,
221,
639,
1720,
63,
505,
9384,
692,
3451,
1834,
911,
506,
8968,
461,
2237,
272,
2034,
63,
1073,
275,
10331,
792,
8,
2307,
29,
549,
12,
4596,
29,
549,
12,
221,
2079,
1720,
63,
505,
9384,
692,
3451,
1834,
911,
506,
8968,
461,
1288,
2079,
3376,
63,
354,
9384,
1606,
2142,
2237,
272,
570,
63,
1073,
275,
481,
3566,
23252,
8,
2307,
29,
549,
12,
4596,
29,
549,
12,
849,
29,
403,
12,
3376,
63,
354,
9384,
493,
2142,
1288,
1720,
63,
505,
9384,
692,
3451,
1834,
911,
506,
8968,
461,
1288,
4048,
63,
354,
534,
13854,
272,
3379,
63,
1073,
275,
1709,
14,
5036,
6115,
1073,
3379,
1834,
1288,
849,
29,
797,
12,
1720,
63,
505,
9384,
692,
3451,
1834,
911,
506,
8968,
461,
2237,
272,
1369,
275,
1709,
14,
6254,
6115,
1802,
1288,
4596,
29,
549,
12,
2973,
29,
549,
9,
339,
327,
781,
1454,
1050,
314,
1834,
370,
3504,
63,
2407,
14,
2034,
63,
1073,
436,
570,
63,
1073,
787,
18821,
83,
272,
327,
465,
5521,
12,
1325,
2985,
787,
440,
1202,
14115,
8321,
370,
3429,
17633,
314,
25568,
402,
2877,
272,
327,
4722,
6578,
31682,
10593,
83,
14,
272,
2251,
275,
481,
3566,
5061,
2988,
8,
2416,
63,
2407,
7782,
1569,
16829,
2378,
1021,
6288,
26,
267,
3376,
63,
354,
275,
3824,
29292,
1834,
531,
267,
3376,
63,
354,
63,
10019,
275,
3824,
29292,
5935,
531,
2286,
347,
3633,
8,
277,
304,
267,
687,
1639,
14,
1018,
14,
3924,
492,
8505,
267,
327,
4155,
3238,
626,
1902,
1834,
503,
1834,
63,
633,
365,
663,
267,
340,
334,
1397,
291,
14,
1569,
436,
440,
291,
14,
1569,
63,
633,
9,
503,
334,
277,
14,
1569,
436,
291,
14,
1569,
63,
633,
304,
288,
746,
8505,
6723,
37,
1711,
376,
1834,
503,
376,
1834,
1166,
1471,
506,
4895,
12459,
25979,
347,
636,
2975,
721,
277,
304,
267,
340,
291,
14,
1569,
26,
288,
372,
291,
14,
1569,
14,
1302,
267,
587,
26,
288,
372,
2649,
8,
3824,
3491,
1684,
425,
2818,
13410,
9,
83,
531,
450,
791,
13410,
356,
291,
14,
13410,
503,
291,
14,
4478,
93,
776,
267,
372,
2125,
272,
768,
1829,
272,
347,
19038,
8,
277,
304,
267,
340,
291,
14,
1569,
26,
288,
372,
291,
14,
13410,
63,
505,
503,
291,
14,
1569,
14,
885,
63,
13410,
267,
587,
26,
288,
372,
291,
14,
13410,
63,
505,
272,
768,
1829,
272,
347,
8791,
8,
277,
304,
267,
340,
291,
14,
1569,
26,
288,
372,
291,
14,
4478,
63,
505,
503,
291,
14,
1569,
14,
885,
63,
4478,
63,
505,
503,
291,
14,
1569,
14,
1302,
267,
587,
26,
288,
372,
291,
14,
4478,
63,
505,
272,
768,
1829,
272,
347,
2142,
8,
277,
304,
267,
340,
291,
14,
4624,
63,
1073,
26,
288,
372,
291,
14,
4624,
63,
1073,
267,
916,
291,
14,
1606,
63,
1073,
26,
288,
372,
291,
14,
1606,
63,
1073,
14,
362,
63,
6116,
63,
633,
342,
267,
916,
291,
14,
493,
63,
1073,
26,
288,
372,
291,
14,
493,
63,
1073,
14,
633,
267,
916,
291,
14,
5043,
63,
1073,
26,
288,
340,
291,
14,
1569,
26,
355,
372,
291,
14,
1569,
14,
633,
288,
587,
26,
355,
372,
291,
14,
1569,
63,
633,
267,
587,
26,
288,
372,
2125,
268,
268,
199,
533,
3868,
5820,
2602,
8,
992,
14,
1685,
304,
272,
408,
272,
961,
1021,
7890,
314,
945,
675,
370,
1218,
314,
10062,
14,
272,
408,
272,
536,
275,
1709,
14,
2183,
6115,
354,
1288,
1390,
63,
1267,
29,
1960,
9,
272,
3462,
275,
1709,
14,
3901,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Azure/azure-sdk-for-python
|
sdk/core/azure-servicemanagement-legacy/azure/servicemanagement/_serialization.py
|
6
|
67533
|
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
import json
import sys
from datetime import datetime
from xml.dom import minidom
from ._common_models import (
Feed,
WindowsAzureData,
_Base64String,
_dict_of,
_list_of,
_scalar_list_of,
_strtype,
_unicode_type,
_xml_attribute,
)
from ._common_conversion import (
_decode_base64_to_text,
_encode_base64,
_lower,
_str,
_decode_base64_to_bytes,
)
from ._common_serialization import (
_create_entry,
_get_serialization_name,
_set_continuation_from_response_headers,
_get_readable_id,
)
from ._common_error import (
_general_error_handler,
_validate_not_none,
)
from .models import (
AvailabilityResponse,
CreateServerResponse,
LinuxConfigurationSet,
ServiceBusNamespace,
ServiceBusRegion,
WindowsConfigurationSet,
)
METADATA_NS = 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata'
class JSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime):
return obj.isoformat()
else:
return super(JSONEncoder, self).default(obj)
class _MinidomXmlToObject(object):
@staticmethod
def parse_response(response, return_type):
'''
Parse the HTTPResponse's body and fill all the data into a class of
return_type.
'''
doc = minidom.parseString(response.body)
return_obj = return_type()
xml_name = return_type._xml_name if hasattr(return_type, '_xml_name') else return_type.__name__
for node in _MinidomXmlToObject.get_child_nodes(doc, xml_name):
_MinidomXmlToObject._fill_data_to_return_object(node, return_obj)
return return_obj
@staticmethod
def parse_service_resources_response(response, return_type):
'''
Parse the HTTPResponse's body and fill all the data into a class of
return_type.
'''
doc = minidom.parseString(response.body)
return_obj = _list_of(return_type)
for node in _MinidomXmlToObject.get_children_from_path(doc, "ServiceResources", "ServiceResource"):
local_obj = return_type()
_MinidomXmlToObject._fill_data_to_return_object(node, local_obj)
return_obj.append(local_obj)
return return_obj
@staticmethod
def fill_data_member(xmldoc, element_name, data_member):
xmlelements = _MinidomXmlToObject.get_child_nodes(
xmldoc, _get_serialization_name(element_name))
if not xmlelements or not xmlelements[0].childNodes:
return None
value = xmlelements[0].firstChild.nodeValue
if data_member is None:
return value
elif isinstance(data_member, datetime):
return _to_datetime(value)
elif type(data_member) is bool:
return value.lower() != 'false'
else:
return type(data_member)(value)
@staticmethod
def convert_xml_to_azure_object(xmlstr, azure_type, include_id=True, use_title_as_id=True):
xmldoc = minidom.parseString(xmlstr)
return_obj = azure_type()
xml_name = azure_type._xml_name if hasattr(azure_type, '_xml_name') else azure_type.__name__
# Only one entry here
for xml_entry in _MinidomXmlToObject.get_children_from_path(xmldoc,
'entry'):
for node in _MinidomXmlToObject.get_children_from_path(xml_entry,
'content',
xml_name):
_MinidomXmlToObject._fill_data_to_return_object(node, return_obj)
for name, value in _MinidomXmlToObject.get_entry_properties_from_node(
xml_entry,
include_id=include_id,
use_title_as_id=use_title_as_id).items():
setattr(return_obj, name, value)
return return_obj
@staticmethod
def get_entry_properties_from_node(entry, include_id, id_prefix_to_skip=None, use_title_as_id=False):
''' get properties from entry xml '''
properties = {}
etag = entry.getAttributeNS(METADATA_NS, 'etag')
if etag:
properties['etag'] = etag
for updated in _MinidomXmlToObject.get_child_nodes(entry, 'updated'):
properties['updated'] = updated.firstChild.nodeValue
for name in _MinidomXmlToObject.get_children_from_path(entry, 'author', 'name'):
if name.firstChild is not None:
properties['author'] = name.firstChild.nodeValue
if include_id:
if use_title_as_id:
for title in _MinidomXmlToObject.get_child_nodes(entry, 'title'):
properties['name'] = title.firstChild.nodeValue
else:
# TODO: check if this is used
for id in _MinidomXmlToObject.get_child_nodes(entry, 'id'):
properties['name'] = _get_readable_id(
id.firstChild.nodeValue, id_prefix_to_skip)
return properties
@staticmethod
def convert_response_to_feeds(response, convert_func):
if response is None:
return None
feeds = _list_of(Feed)
_set_continuation_from_response_headers(feeds, response)
xmldoc = minidom.parseString(response.body)
xml_entries = _MinidomXmlToObject.get_children_from_path(xmldoc, 'feed', 'entry')
if not xml_entries:
# in some cases, response contains only entry but no feed
xml_entries = _MinidomXmlToObject.get_children_from_path(xmldoc, 'entry')
for xml_entry in xml_entries:
new_node = _MinidomXmlToObject._clone_node_with_namespaces(xml_entry, xmldoc)
feeds.append(convert_func(new_node.toxml('utf-8')))
return feeds
@staticmethod
def get_first_child_node_value(parent_node, node_name):
xml_attrs = _MinidomXmlToObject.get_child_nodes(parent_node, node_name)
if xml_attrs:
xml_attr = xml_attrs[0]
if xml_attr.firstChild:
value = xml_attr.firstChild.nodeValue
return value
@staticmethod
def get_children_from_path(node, *path):
'''descends through a hierarchy of nodes returning the list of children
at the inner most level. Only returns children who share a common parent,
not cousins.'''
cur = node
for index, child in enumerate(path):
if isinstance(child, _strtype):
next = _MinidomXmlToObject.get_child_nodes(cur, child)
else:
next = _MinidomXmlToObject._get_child_nodesNS(cur, *child)
if index == len(path) - 1:
return next
elif not next:
break
cur = next[0]
return []
@staticmethod
def get_child_nodes(node, tagName):
if ':' not in tagName:
return _MinidomXmlToObject._get_child_nodesNS(node, '*', tagName)
else:
return [childNode for childNode in node.getElementsByTagName(tagName)
if childNode.parentNode == node]
@staticmethod
def _get_child_nodesNS(node, ns, tagName):
return [childNode for childNode in node.getElementsByTagNameNS(ns, tagName)
if childNode.parentNode == node]
@staticmethod
def _parse_response_body_from_xml_node(node, return_type):
'''
parse the xml and fill all the data into a class of return_type
'''
return_obj = return_type()
_MinidomXmlToObject._fill_data_to_return_object(node, return_obj)
return return_obj
@staticmethod
def _fill_list_of(xmldoc, element_type, xml_element_name):
xmlelements = _MinidomXmlToObject.get_child_nodes(xmldoc, xml_element_name)
return [_MinidomXmlToObject._parse_response_body_from_xml_node(xmlelement, element_type) \
for xmlelement in xmlelements]
@staticmethod
def _fill_scalar_list_of(xmldoc, element_type, parent_xml_element_name,
xml_element_name):
'''Converts an xml fragment into a list of scalar types. The parent xml
element contains a flat list of xml elements which are converted into the
specified scalar type and added to the list.
Example:
xmldoc=
<Endpoints>
<Endpoint>http://{storage-service-name}.blob.core.windows.net/</Endpoint>
<Endpoint>http://{storage-service-name}.queue.core.windows.net/</Endpoint>
<Endpoint>http://{storage-service-name}.table.core.windows.net/</Endpoint>
</Endpoints>
element_type=str
parent_xml_element_name='Endpoints'
xml_element_name='Endpoint'
'''
xmlelements = _MinidomXmlToObject.get_child_nodes(xmldoc, parent_xml_element_name)
if xmlelements:
xmlelements = _MinidomXmlToObject.get_child_nodes(xmlelements[0], xml_element_name)
return [_MinidomXmlToObject._get_node_value(xmlelement, element_type) \
for xmlelement in xmlelements]
@staticmethod
def _fill_dict(xmldoc, element_name):
xmlelements = _MinidomXmlToObject.get_child_nodes(xmldoc, element_name)
if xmlelements:
return_obj = {}
for child in xmlelements[0].childNodes:
if child.firstChild:
return_obj[child.nodeName] = child.firstChild.nodeValue
return return_obj
@staticmethod
def _fill_dict_of(xmldoc, parent_xml_element_name, pair_xml_element_name,
key_xml_element_name, value_xml_element_name):
'''Converts an xml fragment into a dictionary. The parent xml element
contains a list of xml elements where each element has a child element for
the key, and another for the value.
Example:
xmldoc=
<ExtendedProperties>
<ExtendedProperty>
<Name>Ext1</Name>
<Value>Val1</Value>
</ExtendedProperty>
<ExtendedProperty>
<Name>Ext2</Name>
<Value>Val2</Value>
</ExtendedProperty>
</ExtendedProperties>
element_type=str
parent_xml_element_name='ExtendedProperties'
pair_xml_element_name='ExtendedProperty'
key_xml_element_name='Name'
value_xml_element_name='Value'
'''
return_obj = {}
xmlelements = _MinidomXmlToObject.get_child_nodes(xmldoc, parent_xml_element_name)
if xmlelements:
xmlelements = _MinidomXmlToObject.get_child_nodes(xmlelements[0], pair_xml_element_name)
for pair in xmlelements:
keys = _MinidomXmlToObject.get_child_nodes(pair, key_xml_element_name)
values = _MinidomXmlToObject.get_child_nodes(pair, value_xml_element_name)
if keys and values:
key = keys[0].firstChild.nodeValue
valueContentNode = values[0].firstChild
value = valueContentNode.nodeValue if valueContentNode else None
return_obj[key] = value
return return_obj
@staticmethod
def _fill_instance_child(xmldoc, element_name, return_type):
'''Converts a child of the current dom element to the specified type.
'''
xmlelements = _MinidomXmlToObject.get_child_nodes(
xmldoc, _get_serialization_name(element_name))
if not xmlelements:
return None
return_obj = return_type()
_MinidomXmlToObject._fill_data_to_return_object(xmlelements[0], return_obj)
return return_obj
@staticmethod
def _get_node_value(xmlelement, data_type):
value = xmlelement.firstChild.nodeValue
if data_type is datetime:
return _to_datetime(value)
elif data_type is bool:
return value.lower() != 'false'
else:
return data_type(value)
@staticmethod
def _fill_data_to_return_object(node, return_obj):
members = dict(vars(return_obj))
for name, value in members.items():
if isinstance(value, _list_of):
setattr(return_obj,
name,
_MinidomXmlToObject._fill_list_of(
node,
value.list_type,
value.xml_element_name))
elif isinstance(value, _scalar_list_of):
setattr(return_obj,
name,
_MinidomXmlToObject._fill_scalar_list_of(
node,
value.list_type,
_get_serialization_name(name),
value.xml_element_name))
elif isinstance(value, _dict_of):
setattr(return_obj,
name,
_MinidomXmlToObject._fill_dict_of(
node,
_get_serialization_name(name),
value.pair_xml_element_name,
value.key_xml_element_name,
value.value_xml_element_name))
elif isinstance(value, _xml_attribute):
real_value = None
if node.hasAttribute(value.xml_element_name):
real_value = node.getAttribute(value.xml_element_name)
if real_value is not None:
setattr(return_obj, name, real_value)
elif isinstance(value, WindowsAzureData):
setattr(return_obj,
name,
_MinidomXmlToObject._fill_instance_child(
node,
name,
value.__class__))
elif isinstance(value, dict):
setattr(return_obj,
name,
_MinidomXmlToObject._fill_dict(
node,
_get_serialization_name(name)))
elif isinstance(value, _Base64String):
value = _MinidomXmlToObject.fill_data_member(
node,
name,
'')
if value is not None:
value = _decode_base64_to_text(value)
# always set the attribute, so we don't end up returning an object
# with type _Base64String
setattr(return_obj, name, value)
else:
value = _MinidomXmlToObject.fill_data_member(
node,
name,
value)
if value is not None:
setattr(return_obj, name, value)
@staticmethod
def _find_namespaces_from_child(parent, child, namespaces):
"""Recursively searches from the parent to the child,
gathering all the applicable namespaces along the way"""
for cur_child in parent.childNodes:
if cur_child is child:
return True
if _MinidomXmlToObject._find_namespaces_from_child(cur_child, child, namespaces):
# we are the parent node
for key in cur_child.attributes.keys():
if key.startswith('xmlns:') or key == 'xmlns':
namespaces[key] = cur_child.attributes[key]
break
return False
@staticmethod
def _find_namespaces(parent, child):
res = {}
for key in parent.documentElement.attributes.keys():
if key.startswith('xmlns:') or key == 'xmlns':
res[key] = parent.documentElement.attributes[key]
_MinidomXmlToObject._find_namespaces_from_child(parent, child, res)
return res
@staticmethod
def _clone_node_with_namespaces(node_to_clone, original_doc):
clone = node_to_clone.cloneNode(True)
for key, value in _MinidomXmlToObject._find_namespaces(original_doc, node_to_clone).items():
clone.attributes[key] = value
return clone
def _data_to_xml(data):
'''Creates an xml fragment from the specified data.
data:
Array of tuples, where first: xml element name
second:
xml element text
third:
conversion function
'''
xml = ''
for element in data:
name = element[0]
val = element[1]
if len(element) > 2:
converter = element[2]
else:
converter = None
if val is not None:
if converter is not None:
text = _str(converter(_str(val)))
else:
text = _str(val)
xml += ''.join(['<', name, '>', text, '</', name, '>'])
return xml
class _XmlSerializer(object):
@staticmethod
def create_storage_service_input_to_xml(service_name, description, label,
affinity_group, location,
account_type,
extended_properties):
xml = _XmlSerializer.data_to_xml(
[('ServiceName', service_name),
('Description', description),
('Label', label, _encode_base64),
('AffinityGroup', affinity_group),
('Location', location)])
if extended_properties is not None:
xml += _XmlSerializer.extended_properties_dict_to_xml_fragment(
extended_properties)
xml += _XmlSerializer.data_to_xml([('AccountType', account_type)])
return _XmlSerializer.doc_from_xml('CreateStorageServiceInput', xml)
@staticmethod
def update_storage_service_input_to_xml(description, label,
account_type,
extended_properties):
xml = _XmlSerializer.data_to_xml(
[('Description', description),
('Label', label, _encode_base64)])
if extended_properties is not None:
xml += _XmlSerializer.extended_properties_dict_to_xml_fragment(
extended_properties)
xml += _XmlSerializer.data_to_xml([('AccountType', account_type)])
return _XmlSerializer.doc_from_xml('UpdateStorageServiceInput', xml)
@staticmethod
def regenerate_keys_to_xml(key_type):
return _XmlSerializer.doc_from_data('RegenerateKeys',
[('KeyType', key_type)])
@staticmethod
def update_hosted_service_to_xml(label, description, extended_properties):
return _XmlSerializer.doc_from_data('UpdateHostedService',
[('Label', label, _encode_base64),
('Description', description)],
extended_properties)
@staticmethod
def create_hosted_service_to_xml(service_name, label, description,
location, affinity_group,
extended_properties):
return _XmlSerializer.doc_from_data(
'CreateHostedService',
[('ServiceName', service_name),
('Label', label, _encode_base64),
('Description', description),
('Location', location),
('AffinityGroup', affinity_group)],
extended_properties)
@staticmethod
def create_deployment_to_xml(name, package_url, label, configuration,
start_deployment, treat_warnings_as_error,
extended_properties):
return _XmlSerializer.doc_from_data(
'CreateDeployment',
[('Name', name),
('PackageUrl', package_url),
('Label', label, _encode_base64),
('Configuration', configuration),
('StartDeployment',
start_deployment, _lower),
('TreatWarningsAsError', treat_warnings_as_error, _lower)],
extended_properties)
@staticmethod
def swap_deployment_to_xml(production, source_deployment):
return _XmlSerializer.doc_from_data(
'Swap',
[('Production', production),
('SourceDeployment', source_deployment)])
@staticmethod
def update_deployment_status_to_xml(status):
return _XmlSerializer.doc_from_data(
'UpdateDeploymentStatus',
[('Status', status)])
@staticmethod
def change_deployment_to_xml(configuration, treat_warnings_as_error, mode,
extended_properties):
return _XmlSerializer.doc_from_data(
'ChangeConfiguration',
[('Configuration', configuration),
('TreatWarningsAsError', treat_warnings_as_error, _lower),
('Mode', mode)],
extended_properties)
@staticmethod
def upgrade_deployment_to_xml(mode, package_url, configuration, label,
role_to_upgrade, force, extended_properties):
return _XmlSerializer.doc_from_data(
'UpgradeDeployment',
[('Mode', mode),
('PackageUrl', package_url),
('Configuration', configuration),
('Label', label, _encode_base64),
('RoleToUpgrade', role_to_upgrade),
('Force', force, _lower)],
extended_properties)
@staticmethod
def rollback_upgrade_to_xml(mode, force):
return _XmlSerializer.doc_from_data(
'RollbackUpdateOrUpgrade',
[('Mode', mode),
('Force', force, _lower)])
@staticmethod
def walk_upgrade_domain_to_xml(upgrade_domain):
return _XmlSerializer.doc_from_data(
'WalkUpgradeDomain',
[('UpgradeDomain', upgrade_domain)])
@staticmethod
def certificate_file_to_xml(data, certificate_format, password):
return _XmlSerializer.doc_from_data(
'CertificateFile',
[('Data', data),
('CertificateFormat', certificate_format),
('Password', password)])
@staticmethod
def create_affinity_group_to_xml(name, label, description, location):
return _XmlSerializer.doc_from_data(
'CreateAffinityGroup',
[('Name', name),
('Label', label, _encode_base64),
('Description', description),
('Location', location)])
@staticmethod
def update_affinity_group_to_xml(label, description):
return _XmlSerializer.doc_from_data(
'UpdateAffinityGroup',
[('Label', label, _encode_base64),
('Description', description)])
@staticmethod
def subscription_certificate_to_xml(public_key, thumbprint, data):
return _XmlSerializer.doc_from_data(
'SubscriptionCertificate',
[('SubscriptionCertificatePublicKey', public_key),
('SubscriptionCertificateThumbprint', thumbprint),
('SubscriptionCertificateData', data)])
@staticmethod
def os_image_to_xml(label, media_link, name, os):
return _XmlSerializer.doc_from_data(
'OSImage',
[('Label', label),
('MediaLink', media_link),
('Name', name),
('OS', os)])
@staticmethod
def data_virtual_hard_disk_to_xml(host_caching, disk_label, disk_name, lun,
logical_disk_size_in_gb, media_link,
source_media_link):
return _XmlSerializer.doc_from_data(
'DataVirtualHardDisk',
[('HostCaching', host_caching),
('DiskLabel', disk_label),
('DiskName', disk_name),
('Lun', lun),
('LogicalDiskSizeInGB', logical_disk_size_in_gb),
('MediaLink', media_link),
('SourceMediaLink', source_media_link)])
@staticmethod
def disk_to_xml(label, media_link, name, os):
return _XmlSerializer.doc_from_data(
'Disk',
[('OS', os),
('Label', label),
('MediaLink', media_link),
('Name', name),
])
@staticmethod
def restart_role_operation_to_xml():
return _XmlSerializer.doc_from_xml(
'RestartRoleOperation',
'<OperationType>RestartRoleOperation</OperationType>')
@staticmethod
def shutdown_role_operation_to_xml(post_shutdown_action):
xml = _XmlSerializer.data_to_xml(
[('OperationType', 'ShutdownRoleOperation'),
('PostShutdownAction', post_shutdown_action)])
return _XmlSerializer.doc_from_xml('ShutdownRoleOperation', xml)
@staticmethod
def shutdown_roles_operation_to_xml(role_names, post_shutdown_action):
xml = _XmlSerializer.data_to_xml(
[('OperationType', 'ShutdownRolesOperation')])
xml += '<Roles>'
for role_name in role_names:
xml += _XmlSerializer.data_to_xml([('Name', role_name)])
xml += '</Roles>'
xml += _XmlSerializer.data_to_xml(
[('PostShutdownAction', post_shutdown_action)])
return _XmlSerializer.doc_from_xml('ShutdownRolesOperation', xml)
@staticmethod
def start_role_operation_to_xml():
return _XmlSerializer.doc_from_xml(
'StartRoleOperation',
'<OperationType>StartRoleOperation</OperationType>')
@staticmethod
def start_roles_operation_to_xml(role_names):
xml = _XmlSerializer.data_to_xml(
[('OperationType', 'StartRolesOperation')])
xml += '<Roles>'
for role_name in role_names:
xml += _XmlSerializer.data_to_xml([('Name', role_name)])
xml += '</Roles>'
return _XmlSerializer.doc_from_xml('StartRolesOperation', xml)
@staticmethod
def windows_configuration_to_xml(configuration):
xml = _XmlSerializer.data_to_xml(
[('ConfigurationSetType', configuration.configuration_set_type),
('ComputerName', configuration.computer_name),
('AdminPassword', configuration.admin_password),
('ResetPasswordOnFirstLogon',
configuration.reset_password_on_first_logon,
_lower),
('EnableAutomaticUpdates',
configuration.enable_automatic_updates,
_lower),
('TimeZone', configuration.time_zone)])
if configuration.domain_join is not None:
xml += '<DomainJoin>'
xml += '<Credentials>'
xml += _XmlSerializer.data_to_xml(
[('Domain', configuration.domain_join.credentials.domain),
('Username', configuration.domain_join.credentials.username),
('Password', configuration.domain_join.credentials.password)])
xml += '</Credentials>'
xml += _XmlSerializer.data_to_xml(
[('JoinDomain', configuration.domain_join.join_domain),
('MachineObjectOU',
configuration.domain_join.machine_object_ou)])
xml += '</DomainJoin>'
if configuration.stored_certificate_settings is not None:
xml += '<StoredCertificateSettings>'
for cert in configuration.stored_certificate_settings:
xml += '<CertificateSetting>'
xml += _XmlSerializer.data_to_xml(
[('StoreLocation', cert.store_location),
('StoreName', cert.store_name),
('Thumbprint', cert.thumbprint)])
xml += '</CertificateSetting>'
xml += '</StoredCertificateSettings>'
if configuration.win_rm is not None:
xml += '<WinRM><Listeners>'
for listener in configuration.win_rm.listeners:
xml += '<Listener>'
xml += _XmlSerializer.data_to_xml(
[('Protocol', listener.protocol),
('CertificateThumbprint', listener.certificate_thumbprint)])
xml += '</Listener>'
xml += '</Listeners></WinRM>'
xml += _XmlSerializer.data_to_xml(
[('AdminUsername', configuration.admin_username),
('CustomData', configuration.custom_data, _encode_base64)])
if configuration.additional_unattend_content and configuration.additional_unattend_content.passes:
xml += '<AdditionalUnattendContent><Passes>'
for unattend_pass in configuration.additional_unattend_content.passes:
xml += _XmlSerializer.data_to_xml(
[('PassName', unattend_pass.pass_name)])
if unattend_pass.components:
xml += '<Components>'
for comp in unattend_pass.components:
xml += '<UnattendComponent>'
xml += _XmlSerializer.data_to_xml(
[('ComponentName', comp.component_name)])
if comp.component_settings:
xml += '<ComponentSettings>'
for setting in comp.component_settings:
xml += '<ComponentSetting>'
xml += _XmlSerializer.data_to_xml(
[('SettingName', setting.setting_name),
('Content', setting.content)])
xml += '</ComponentSetting>'
xml += '</ComponentSettings>'
xml += '</UnattendComponent>'
xml += '</Components>'
xml += '</Passes></AdditionalUnattendContent>'
return xml
@staticmethod
def linux_configuration_to_xml(configuration):
xml = _XmlSerializer.data_to_xml(
[('ConfigurationSetType', configuration.configuration_set_type),
('HostName', configuration.host_name),
('UserName', configuration.user_name),
('UserPassword', configuration.user_password),
('DisableSshPasswordAuthentication',
configuration.disable_ssh_password_authentication,
_lower)])
if configuration.ssh is not None:
xml += '<SSH>'
xml += '<PublicKeys>'
for key in configuration.ssh.public_keys:
xml += '<PublicKey>'
xml += _XmlSerializer.data_to_xml(
[('Fingerprint', key.fingerprint),
('Path', key.path)])
xml += '</PublicKey>'
xml += '</PublicKeys>'
xml += '<KeyPairs>'
for key in configuration.ssh.key_pairs:
xml += '<KeyPair>'
xml += _XmlSerializer.data_to_xml(
[('Fingerprint', key.fingerprint),
('Path', key.path)])
xml += '</KeyPair>'
xml += '</KeyPairs>'
xml += '</SSH>'
xml += _XmlSerializer.data_to_xml(
[('CustomData', configuration.custom_data, _encode_base64)])
return xml
@staticmethod
def network_configuration_to_xml(configuration):
xml = _XmlSerializer.data_to_xml(
[('ConfigurationSetType', configuration.configuration_set_type)])
xml += '<InputEndpoints>'
for endpoint in configuration.input_endpoints:
xml += '<InputEndpoint>'
xml += _XmlSerializer.data_to_xml(
[('LoadBalancedEndpointSetName',
endpoint.load_balanced_endpoint_set_name),
('LocalPort', endpoint.local_port),
('Name', endpoint.name),
('Port', endpoint.port)])
if endpoint.load_balancer_probe:
if endpoint.load_balancer_probe.path or\
endpoint.load_balancer_probe.port or\
endpoint.load_balancer_probe.protocol:
xml += '<LoadBalancerProbe>'
xml += _XmlSerializer.data_to_xml(
[('Path', endpoint.load_balancer_probe.path),
('Port', endpoint.load_balancer_probe.port),
('Protocol', endpoint.load_balancer_probe.protocol)])
xml += '</LoadBalancerProbe>'
xml += _XmlSerializer.data_to_xml(
[('Protocol', endpoint.protocol),
('EnableDirectServerReturn',
endpoint.enable_direct_server_return,
_lower),
('IdleTimeoutInMinutes', endpoint.idle_timeout_in_minutes)])
xml += '</InputEndpoint>'
xml += '</InputEndpoints>'
xml += '<SubnetNames>'
if configuration.subnet_names:
for name in configuration.subnet_names:
xml += _XmlSerializer.data_to_xml([('SubnetName', name)])
xml += '</SubnetNames>'
if configuration.static_virtual_network_ip_address:
xml += _XmlSerializer.data_to_xml(
[('StaticVirtualNetworkIPAddress',
configuration.static_virtual_network_ip_address)])
if configuration.public_ips:
xml += '<PublicIPs>'
for public_ip in configuration.public_ips:
xml += '<PublicIP>'
xml += _XmlSerializer.data_to_xml(
[('Name', public_ip.name),
('IdleTimeoutInMinutes', public_ip.idle_timeout_in_minutes)])
xml += '</PublicIP>'
xml += '</PublicIPs>'
return xml
@staticmethod
def role_to_xml(availability_set_name, data_virtual_hard_disks,
network_configuration_set, os_virtual_hard_disk, role_name,
role_size, role_type, system_configuration_set,
resource_extension_references,
provision_guest_agent, vm_image_name, media_location):
xml = _XmlSerializer.data_to_xml([('RoleName', role_name),
('RoleType', role_type)])
if system_configuration_set or network_configuration_set:
xml += '<ConfigurationSets>'
if system_configuration_set is not None:
xml += '<ConfigurationSet>'
if isinstance(system_configuration_set, WindowsConfigurationSet):
xml += _XmlSerializer.windows_configuration_to_xml(
system_configuration_set)
elif isinstance(system_configuration_set, LinuxConfigurationSet):
xml += _XmlSerializer.linux_configuration_to_xml(
system_configuration_set)
xml += '</ConfigurationSet>'
if network_configuration_set is not None:
xml += '<ConfigurationSet>'
xml += _XmlSerializer.network_configuration_to_xml(
network_configuration_set)
xml += '</ConfigurationSet>'
xml += '</ConfigurationSets>'
if resource_extension_references:
xml += '<ResourceExtensionReferences>'
for ext in resource_extension_references:
xml += '<ResourceExtensionReference>'
xml += _XmlSerializer.data_to_xml(
[('ReferenceName', ext.reference_name),
('Publisher', ext.publisher),
('Name', ext.name),
('Version', ext.version)])
if ext.resource_extension_parameter_values:
xml += '<ResourceExtensionParameterValues>'
for val in ext.resource_extension_parameter_values:
xml += '<ResourceExtensionParameterValue>'
xml += _XmlSerializer.data_to_xml(
[('Key', val.key),
('Value', val.value),
('Type', val.type)])
xml += '</ResourceExtensionParameterValue>'
xml += '</ResourceExtensionParameterValues>'
xml += '</ResourceExtensionReference>'
xml += '</ResourceExtensionReferences>'
xml += _XmlSerializer.data_to_xml(
[('VMImageName', vm_image_name),
('MediaLocation', media_location),
('AvailabilitySetName', availability_set_name)])
if data_virtual_hard_disks is not None:
xml += '<DataVirtualHardDisks>'
for hd in data_virtual_hard_disks:
xml += '<DataVirtualHardDisk>'
xml += _XmlSerializer.data_to_xml(
[('HostCaching', hd.host_caching),
('DiskLabel', hd.disk_label),
('DiskName', hd.disk_name),
('Lun', hd.lun),
('LogicalDiskSizeInGB', hd.logical_disk_size_in_gb),
('MediaLink', hd.media_link),
('SourceMediaLink', hd.source_media_link)])
xml += '</DataVirtualHardDisk>'
xml += '</DataVirtualHardDisks>'
if os_virtual_hard_disk is not None:
xml += '<OSVirtualHardDisk>'
xml += _XmlSerializer.data_to_xml(
[('HostCaching', os_virtual_hard_disk.host_caching),
('DiskLabel', os_virtual_hard_disk.disk_label),
('DiskName', os_virtual_hard_disk.disk_name),
('MediaLink', os_virtual_hard_disk.media_link),
('SourceImageName', os_virtual_hard_disk.source_image_name),
('OS', os_virtual_hard_disk.os),
('RemoteSourceImageLink', os_virtual_hard_disk.remote_source_image_link)])
xml += '</OSVirtualHardDisk>'
xml += _XmlSerializer.data_to_xml(
[('RoleSize', role_size),
('ProvisionGuestAgent', provision_guest_agent, _lower)])
return xml
@staticmethod
def add_role_to_xml(role_name, system_configuration_set,
os_virtual_hard_disk, role_type,
network_configuration_set, availability_set_name,
data_virtual_hard_disks, role_size,
resource_extension_references, provision_guest_agent,
vm_image_name, media_location):
xml = _XmlSerializer.role_to_xml(
availability_set_name,
data_virtual_hard_disks,
network_configuration_set,
os_virtual_hard_disk,
role_name,
role_size,
role_type,
system_configuration_set,
resource_extension_references,
provision_guest_agent,
vm_image_name,
media_location)
return _XmlSerializer.doc_from_xml('PersistentVMRole', xml)
@staticmethod
def update_role_to_xml(role_name, os_virtual_hard_disk, role_type,
network_configuration_set, availability_set_name,
data_virtual_hard_disks, role_size,
resource_extension_references,
provision_guest_agent):
xml = _XmlSerializer.role_to_xml(
availability_set_name,
data_virtual_hard_disks,
network_configuration_set,
os_virtual_hard_disk,
role_name,
role_size,
role_type,
None,
resource_extension_references,
provision_guest_agent,
None,
None)
return _XmlSerializer.doc_from_xml('PersistentVMRole', xml)
@staticmethod
def capture_role_to_xml(post_capture_action, target_image_name,
target_image_label, provisioning_configuration):
xml = _XmlSerializer.data_to_xml(
[('OperationType', 'CaptureRoleOperation'),
('PostCaptureAction', post_capture_action)])
if provisioning_configuration is not None:
xml += '<ProvisioningConfiguration>'
if isinstance(provisioning_configuration, WindowsConfigurationSet):
xml += _XmlSerializer.windows_configuration_to_xml(
provisioning_configuration)
elif isinstance(provisioning_configuration, LinuxConfigurationSet):
xml += _XmlSerializer.linux_configuration_to_xml(
provisioning_configuration)
xml += '</ProvisioningConfiguration>'
xml += _XmlSerializer.data_to_xml(
[('TargetImageLabel', target_image_label),
('TargetImageName', target_image_name)])
return _XmlSerializer.doc_from_xml('CaptureRoleOperation', xml)
@staticmethod
def replicate_image_to_xml(regions, offer, sku, version):
xml = '<TargetLocations>'
for region in regions:
xml += _XmlSerializer.data_to_xml([('Region', region)])
xml += '</TargetLocations>'
xml += '<ComputeImageAttributes>'
xml += _XmlSerializer.data_to_xml(
[
('Offer', offer),
('Sku', sku),
('Version', version)
]
)
xml += '</ComputeImageAttributes>'
return _XmlSerializer.doc_from_xml('ReplicationInput', xml)
@staticmethod
def virtual_machine_deployment_to_xml(deployment_name, deployment_slot,
label, role_name,
system_configuration_set,
os_virtual_hard_disk, role_type,
network_configuration_set,
availability_set_name,
data_virtual_hard_disks, role_size,
virtual_network_name,
resource_extension_references,
provision_guest_agent,
vm_image_name,
media_location,
dns_servers,
reserved_ip_name):
xml = _XmlSerializer.data_to_xml([('Name', deployment_name),
('DeploymentSlot', deployment_slot),
('Label', label)])
xml += '<RoleList>'
xml += '<Role>'
xml += _XmlSerializer.role_to_xml(
availability_set_name,
data_virtual_hard_disks,
network_configuration_set,
os_virtual_hard_disk,
role_name,
role_size,
role_type,
system_configuration_set,
resource_extension_references,
provision_guest_agent,
vm_image_name,
media_location)
xml += '</Role>'
xml += '</RoleList>'
xml += _XmlSerializer.data_to_xml(
[('VirtualNetworkName', virtual_network_name)])
if dns_servers:
xml += '<Dns><DnsServers>'
for dns_server in dns_servers:
xml += '<DnsServer>'
xml += _XmlSerializer.data_to_xml(
[('Name', dns_server.name),
('Address', dns_server.address)])
xml += '</DnsServer>'
xml += '</DnsServers></Dns>'
xml += _XmlSerializer.data_to_xml(
[('ReservedIPName', reserved_ip_name)])
return _XmlSerializer.doc_from_xml('Deployment', xml)
@staticmethod
def capture_vm_image_to_xml(options):
return _XmlSerializer.doc_from_data(
'CaptureRoleAsVMImageOperation ',
[('OperationType', 'CaptureRoleAsVMImageOperation'),
('OSState', options.os_state),
('VMImageName', options.vm_image_name),
('VMImageLabel', options.vm_image_label),
('Description', options.description),
('Language', options.language),
('ImageFamily', options.image_family),
('RecommendedVMSize', options.recommended_vm_size)])
@staticmethod
def create_vm_image_to_xml(image):
xml = _XmlSerializer.data_to_xml(
[('Name', image.name),
('Label', image.label),
('Description', image.description)])
os_disk = image.os_disk_configuration
xml += '<OSDiskConfiguration>'
xml += _XmlSerializer.data_to_xml(
[('HostCaching', os_disk.host_caching),
('OSState', os_disk.os_state),
('OS', os_disk.os),
('MediaLink', os_disk.media_link)])
xml += '</OSDiskConfiguration>'
if image.data_disk_configurations:
xml += '<DataDiskConfigurations>'
for data_disk in image.data_disk_configurations:
xml += '<DataDiskConfiguration>'
xml += _XmlSerializer.data_to_xml(
[('HostCaching', data_disk.host_caching),
('Lun', data_disk.lun),
('MediaLink', data_disk.media_link),
('LogicalDiskSizeInGB', data_disk.logical_disk_size_in_gb)])
xml += '</DataDiskConfiguration>'
xml += '</DataDiskConfigurations>'
xml += _XmlSerializer.data_to_xml(
[('Language', image.language),
('ImageFamily', image.image_family),
('RecommendedVMSize', image.recommended_vm_size),
('Eula', image.eula),
('IconUri', image.icon_uri),
('SmallIconUri', image.small_icon_uri),
('PrivacyUri', image.privacy_uri),
('PublishedDate', image.published_date),
('ShowInGui', image.show_in_gui, _lower)])
return _XmlSerializer.doc_from_xml('VMImage', xml)
@staticmethod
def update_vm_image_to_xml(image):
xml = _XmlSerializer.data_to_xml(
[('Label', image.label),
('Description', image.description)])
os_disk = image.os_disk_configuration
xml += '<OSDiskConfiguration>'
xml += _XmlSerializer.data_to_xml(
[('HostCaching', os_disk.host_caching)])
xml += '</OSDiskConfiguration>'
xml += '<DataDiskConfigurations>'
for data_disk in image.data_disk_configurations:
xml += '<DataDiskConfiguration>'
xml += _XmlSerializer.data_to_xml(
[('Name', data_disk.name),
('HostCaching', data_disk.host_caching),
('Lun', data_disk.lun)])
xml += '</DataDiskConfiguration>'
xml += '</DataDiskConfigurations>'
xml += _XmlSerializer.data_to_xml(
[('Language', image.language),
('ImageFamily', image.image_family),
('RecommendedVMSize', image.recommended_vm_size),
('Eula', image.eula),
('IconUri', image.icon_uri),
('SmallIconUri', image.small_icon_uri),
('PrivacyUri', image.privacy_uri),
('PublishedDate', image.published_date),
('ShowInGui', image.show_in_gui, _lower)])
return _XmlSerializer.doc_from_xml('VMImage', xml)
@staticmethod
def update_os_image_to_xml(image):
# Explicitly replace empty string by None to avoid serialization
# of this field, since the API answers "BadRequest" for empty string.
if not image.published_date:
image.published_date = None
xml = _XmlSerializer.data_to_xml(
[
('Label', image.label),
('Eula', image.eula),
('Description', image.description),
('ImageFamily', image.image_family),
('ShowInGui', image.show_in_gui, _lower),
('PublishedDate', image.published_date),
('IconUri', image.icon_uri),
('PrivacyUri', image.privacy_uri),
('RecommendedVMSize', image.recommended_vm_size),
('SmallIconUri', image.small_icon_uri),
('Language', image.language)
]
)
return _XmlSerializer.doc_from_xml('OSImage', xml)
@staticmethod
def create_website_to_xml(webspace_name, website_name, geo_region, plan,
host_names, compute_mode, server_farm, site_mode):
xml = '<HostNames xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">'
for host_name in host_names:
xml += '<a:string>{0}</a:string>'.format(host_name)
xml += '</HostNames>'
xml += _XmlSerializer.data_to_xml(
[('Name', website_name),
('ComputeMode', compute_mode),
('ServerFarm', server_farm),
('SiteMode', site_mode)])
xml += '<WebSpaceToCreate>'
xml += _XmlSerializer.data_to_xml(
[('GeoRegion', geo_region),
('Name', webspace_name),
('Plan', plan)])
xml += '</WebSpaceToCreate>'
return _XmlSerializer.doc_from_xml('Site', xml)
@staticmethod
def update_website_to_xml(state):
xml = _XmlSerializer.data_to_xml(
[('State', state)])
return _XmlSerializer.doc_from_xml('Site', xml)
@staticmethod
def create_reserved_ip_to_xml(name, label, location):
return _XmlSerializer.doc_from_data(
'ReservedIP',
[('Name', name),
('Label', label),
('Location', location)])
@staticmethod
def associate_reserved_ip_to_xml(
service_name, deployment_name, virtual_ip_name
):
xml = _XmlSerializer.data_to_xml([
('ServiceName', service_name),
('DeploymentName', deployment_name),
])
if virtual_ip_name:
xml += _XmlSerializer.data_to_xml(
[('VirtualIPName', virtual_ip_name)]
)
return _XmlSerializer.doc_from_xml('ReservedIPAssociation', xml)
@staticmethod
def dns_server_to_xml(name, address):
return _XmlSerializer.doc_from_data(
'DnsServer',
[('Name', name),
('Address', address)])
@staticmethod
def role_instances_to_xml(role_instances):
xml = ''
for name in role_instances:
xml += _XmlSerializer.data_to_xml([('Name', name)])
return _XmlSerializer.doc_from_xml('RoleInstances ', xml)
@staticmethod
def data_to_xml(data):
return _data_to_xml(data)
@staticmethod
def doc_from_xml(document_element_name, inner_xml):
'''Wraps the specified xml in an xml root element with default azure
namespaces'''
xml = ''.join(['<', document_element_name,
' xmlns:i="http://www.w3.org/2001/XMLSchema-instance"',
' xmlns="http://schemas.microsoft.com/windowsazure">'])
xml += inner_xml
xml += ''.join(['</', document_element_name, '>'])
return xml
@staticmethod
def doc_from_data(document_element_name, data, extended_properties=None):
xml = _XmlSerializer.data_to_xml(data)
if extended_properties is not None:
xml += _XmlSerializer.extended_properties_dict_to_xml_fragment(
extended_properties)
return _XmlSerializer.doc_from_xml(document_element_name, xml)
@staticmethod
def extended_properties_dict_to_xml_fragment(extended_properties):
xml = ''
if extended_properties is not None and len(extended_properties) > 0:
xml += '<ExtendedProperties>'
for key, val in extended_properties.items():
xml += ''.join(['<ExtendedProperty>',
'<Name>',
_str(key),
'</Name>',
'<Value>',
_str(val),
'</Value>',
'</ExtendedProperty>'])
xml += '</ExtendedProperties>'
return xml
class _SqlManagementXmlSerializer(object):
@staticmethod
def create_server_to_xml(admin_login, admin_password, location):
return _SqlManagementXmlSerializer.doc_from_data(
'Server',
[('AdministratorLogin', admin_login),
('AdministratorLoginPassword', admin_password),
('Location', location)],
'http://schemas.microsoft.com/sqlazure/2010/12/')
@staticmethod
def set_server_admin_password_to_xml(admin_password):
return _SqlManagementXmlSerializer.doc_from_xml(
'AdministratorLoginPassword', admin_password,
'http://schemas.microsoft.com/sqlazure/2010/12/')
@staticmethod
def create_firewall_rule_to_xml(name, start_ip_address, end_ip_address):
return _SqlManagementXmlSerializer.doc_from_data(
'ServiceResource',
[('Name', name),
('StartIPAddress', start_ip_address),
('EndIPAddress', end_ip_address)])
@staticmethod
def update_firewall_rule_to_xml(name, start_ip_address, end_ip_address):
return _SqlManagementXmlSerializer.doc_from_data(
'ServiceResource',
[('Name', name),
('StartIPAddress', start_ip_address),
('EndIPAddress', end_ip_address)])
@staticmethod
def create_database_to_xml(name, service_objective_id, edition, collation_name,
max_size_bytes):
return _SqlManagementXmlSerializer.doc_from_data(
'ServiceResource',
[('Name', name),
('Edition', edition),
('CollationName', collation_name),
('MaxSizeBytes', max_size_bytes),
('ServiceObjectiveId', service_objective_id)])
@staticmethod
def update_database_to_xml(name, service_objective_id, edition,
max_size_bytes):
return _SqlManagementXmlSerializer.doc_from_data(
'ServiceResource',
[('Name', name),
('Edition', edition),
('MaxSizeBytes', max_size_bytes),
('ServiceObjectiveId', service_objective_id)])
@staticmethod
def xml_to_create_server_response(xmlstr):
xmldoc = minidom.parseString(xmlstr)
element = xmldoc.documentElement
response = CreateServerResponse()
response.server_name = element.firstChild.nodeValue
response.fully_qualified_domain_name = element.getAttribute('FullyQualifiedDomainName')
return response
@staticmethod
def data_to_xml(data):
return _data_to_xml(data)
@staticmethod
def doc_from_xml(document_element_name, inner_xml,
xmlns='http://schemas.microsoft.com/windowsazure'):
'''Wraps the specified xml in an xml root element with default azure
namespaces'''
xml = ''.join(['<', document_element_name,
' xmlns="{0}">'.format(xmlns)])
xml += inner_xml
xml += ''.join(['</', document_element_name, '>'])
return xml
@staticmethod
def doc_from_data(document_element_name, data,
xmlns='http://schemas.microsoft.com/windowsazure'):
xml = _SqlManagementXmlSerializer.data_to_xml(data)
return _SqlManagementXmlSerializer.doc_from_xml(
document_element_name, xml, xmlns)
def _parse_bool(value):
if value.lower() == 'true':
return True
return False
class _ServiceBusManagementXmlSerializer(object):
@staticmethod
def namespace_to_xml(region):
'''Converts a service bus namespace description to xml
The xml format:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<NamespaceDescription
xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Region>West US</Region>
</NamespaceDescription>
</content>
</entry>
'''
body = '<NamespaceDescription xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">'
body += ''.join(['<Region>', region, '</Region>'])
body += '</NamespaceDescription>'
return _create_entry(body)
@staticmethod
def xml_to_namespace(xmlstr):
'''Converts xml response to service bus namespace
The xml format for namespace:
<entry>
<id>uuid:00000000-0000-0000-0000-000000000000;id=0000000</id>
<title type="text">myunittests</title>
<updated>2012-08-22T16:48:10Z</updated>
<content type="application/xml">
<NamespaceDescription
xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Name>myunittests</Name>
<Region>West US</Region>
<DefaultKey>0000000000000000000000000000000000000000000=</DefaultKey>
<Status>Active</Status>
<CreatedAt>2012-08-22T16:48:10.217Z</CreatedAt>
<AcsManagementEndpoint>https://myunittests-sb.accesscontrol.windows.net/</AcsManagementEndpoint>
<ServiceBusEndpoint>https://myunittests.servicebus.windows.net/</ServiceBusEndpoint>
<ConnectionString>Endpoint=sb://myunittests.servicebus.windows.net/;SharedSecretIssuer=owner;SharedSecretValue=0000000000000000000000000000000000000000000=</ConnectionString>
<SubscriptionId>00000000000000000000000000000000</SubscriptionId>
<Enabled>true</Enabled>
</NamespaceDescription>
</content>
</entry>
'''
xmldoc = minidom.parseString(xmlstr)
namespace = ServiceBusNamespace()
mappings = (
('Name', 'name', None),
('Region', 'region', None),
('DefaultKey', 'default_key', None),
('Status', 'status', None),
('CreatedAt', 'created_at', None),
('AcsManagementEndpoint', 'acs_management_endpoint', None),
('ServiceBusEndpoint', 'servicebus_endpoint', None),
('ConnectionString', 'connection_string', None),
('SubscriptionId', 'subscription_id', None),
('Enabled', 'enabled', _parse_bool),
)
for desc in _MinidomXmlToObject.get_children_from_path(
xmldoc,
'entry',
'content',
'NamespaceDescription'):
for xml_name, field_name, conversion_func in mappings:
node_value = _MinidomXmlToObject.get_first_child_node_value(desc, xml_name)
if node_value is not None:
if conversion_func is not None:
node_value = conversion_func(node_value)
setattr(namespace, field_name, node_value)
return namespace
@staticmethod
def xml_to_region(xmlstr):
'''Converts xml response to service bus region
The xml format for region:
<entry>
<id>uuid:157c311f-081f-4b4a-a0ba-a8f990ffd2a3;id=1756759</id>
<title type="text"></title>
<updated>2013-04-10T18:25:29Z</updated>
<content type="application/xml">
<RegionCodeDescription
xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Code>East Asia</Code>
<FullName>East Asia</FullName>
</RegionCodeDescription>
</content>
</entry>
'''
xmldoc = minidom.parseString(xmlstr)
region = ServiceBusRegion()
for desc in _MinidomXmlToObject.get_children_from_path(xmldoc, 'entry', 'content',
'RegionCodeDescription'):
node_value = _MinidomXmlToObject.get_first_child_node_value(desc, 'Code')
if node_value is not None:
region.code = node_value
node_value = _MinidomXmlToObject.get_first_child_node_value(desc, 'FullName')
if node_value is not None:
region.fullname = node_value
return region
@staticmethod
def xml_to_namespace_availability(xmlstr):
'''Converts xml response to service bus namespace availability
The xml format:
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<id>uuid:9fc7c652-1856-47ab-8d74-cd31502ea8e6;id=3683292</id>
<title type="text"></title>
<updated>2013-04-16T03:03:37Z</updated>
<content type="application/xml">
<NamespaceAvailability
xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Result>false</Result>
</NamespaceAvailability>
</content>
</entry>
'''
xmldoc = minidom.parseString(xmlstr)
availability = AvailabilityResponse()
for desc in _MinidomXmlToObject.get_children_from_path(xmldoc, 'entry', 'content',
'NamespaceAvailability'):
node_value = _MinidomXmlToObject.get_first_child_node_value(desc, 'Result')
if node_value is not None:
availability.result = _parse_bool(node_value)
return availability
@staticmethod
def odata_converter(data, str_type):
''' Convert odata type
http://www.odata.org/documentation/odata-version-2-0/overview#AbstractTypeSystem
To be completed
'''
if not str_type:
return _str(data)
if str_type in ["Edm.Single", "Edm.Double"]:
return float(data)
elif "Edm.Int" in str_type:
return int(data)
else:
return _str(data)
@staticmethod
def xml_to_metrics(xmlstr, object_type):
'''Converts xml response to service bus metrics objects
The xml format for MetricProperties
<entry>
<id>https://sbgm.windows.net/Metrics(\'listeners.active\')</id>
<title/>
<updated>2014-10-09T11:56:50Z</updated>
<author>
<name/>
</author>
<content type="application/xml">
<m:properties>
<d:Name>listeners.active</d:Name>
<d:PrimaryAggregation>Average</d:PrimaryAggregation>
<d:Unit>Count</d:Unit>
<d:DisplayName>Active listeners</d:DisplayName>
</m:properties>
</content>
</entry>
The xml format for MetricValues
<entry>
<id>https://sbgm.windows.net/MetricValues(datetime\'2014-10-02T00:00:00Z\')</id>
<title/>
<updated>2014-10-09T18:38:28Z</updated>
<author>
<name/>
</author>
<content type="application/xml">
<m:properties>
<d:Timestamp m:type="Edm.DateTime">2014-10-02T00:00:00Z</d:Timestamp>
<d:Min m:type="Edm.Int64">-118</d:Min>
<d:Max m:type="Edm.Int64">15</d:Max>
<d:Average m:type="Edm.Single">-78.44444</d:Average>
<d:Total m:type="Edm.Int64">0</d:Total>
</m:properties>
</content>
</entry>
'''
xmldoc = minidom.parseString(xmlstr)
return_obj = object_type()
members = dict(vars(return_obj))
# Only one entry here
for xml_entry in _MinidomXmlToObject.get_children_from_path(xmldoc,
'entry'):
for node in _MinidomXmlToObject.get_children_from_path(xml_entry,
'content',
'properties'):
for name in members:
xml_name = _get_serialization_name(name)
children = _MinidomXmlToObject.get_child_nodes(node, xml_name)
if not children:
continue
child = children[0]
node_type = child.getAttributeNS("http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", 'type')
node_value = _ServiceBusManagementXmlSerializer.odata_converter(child.firstChild.nodeValue, node_type)
setattr(return_obj, name, node_value)
for name, value in _MinidomXmlToObject.get_entry_properties_from_node(
xml_entry,
include_id=True,
use_title_as_id=False).items():
if name in members:
continue # Do not override if already members
setattr(return_obj, name, value)
return return_obj
class _SchedulerManagementXmlSerializer(object):
@staticmethod
def create_cloud_service_to_xml(label, description, geo_region):
'''
<CloudService xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windowsazure">
<Label>MyApp3</Label>
<Description>My Cloud Service for app3</Description>
<GeoRegion>South Central US</GeoRegion>
</CloudService>
'''
body = '<CloudService xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windowsazure">'
body += ''.join(['<Label>', label, '</Label>'])
body += ''.join(['<Description>', description, '</Description>'])
body += ''.join(['<GeoRegion>', geo_region, '</GeoRegion>'])
body += '</CloudService>'
return body
@staticmethod
def create_job_collection_to_xml(plan):
'''
<Resource xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windowsazure">
<IntrinsicSettings>
<Plan>Standard</Plan>
<Quota>
<MaxJobCount>10</MaxJobCount>
<MaxRecurrence>
<Frequency>Second</Frequency>
<Interval>1</Interval>
</MaxRecurrence>
</Quota>
</IntrinsicSettings>
</Resource>
'''
if plan not in ["Free", "Standard"]:
raise ValueError("Plan: Invalid option must be 'Standard' or 'Free'")
body = '<Resource xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windowsazure"><IntrinsicSettings>'
body += ''.join(['<plan>', plan, '</plan>'])
body += '</IntrinsicSettings></Resource>'
return body
|
mit
|
[
172,
120,
124,
25812,
199,
3,
1898,
334,
67,
9,
15332,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
7656,
9460,
199,
646,
2022,
199,
646,
984,
199,
504,
2197,
492,
2197,
199,
504,
2748,
14,
4556,
492,
19165,
199,
504,
13653,
2330,
63,
992,
492,
334,
272,
16261,
12,
272,
5417,
22386,
1451,
12,
272,
485,
1563,
772,
1558,
12,
272,
485,
807,
63,
1618,
12,
272,
485,
513,
63,
1618,
12,
272,
485,
7033,
63,
513,
63,
1618,
12,
272,
485,
495,
466,
12,
272,
485,
2975,
63,
466,
12,
272,
485,
1652,
63,
3215,
12,
199,
9,
199,
504,
13653,
2330,
63,
15083,
492,
334,
272,
485,
2708,
63,
1095,
772,
63,
475,
63,
505,
12,
272,
485,
2143,
63,
1095,
772,
12,
272,
485,
2325,
12,
272,
485,
495,
12,
272,
485,
2708,
63,
1095,
772,
63,
475,
63,
2394,
12,
199,
9,
199,
504,
13653,
2330,
63,
12161,
492,
334,
272,
485,
981,
63,
2373,
12,
272,
485,
362,
63,
12161,
63,
354,
12,
272,
485,
409,
63,
20305,
63,
504,
63,
1310,
63,
2139,
12,
272,
485,
362,
63,
11875,
63,
344,
12,
199,
9,
199,
504,
13653,
2330,
63,
705,
492,
334,
272,
485,
10706,
63,
705,
63,
2232,
12,
272,
485,
3502,
63,
1397,
63,
3592,
12,
199,
9,
199,
504,
1275,
992,
492,
334,
272,
16599,
7615,
2364,
12,
272,
2790,
3120,
2364,
12,
272,
10130,
5688,
1084,
12,
272,
7591,
12106,
8814,
12,
272,
7591,
12106,
10708,
12,
272,
5417,
5688,
1084,
12,
199,
9,
199,
199,
8314,
63,
2709,
275,
283,
1014,
921,
9482,
14,
17040,
14,
957,
15,
5129,
15,
9488,
15,
2036,
15,
576,
5950,
15,
2343,
7,
199,
199,
533,
4840,
6679,
8,
1001,
14,
23069,
304,
272,
347,
849,
8,
277,
12,
1559,
304,
267,
340,
1228,
8,
1113,
12,
2197,
304,
288,
372,
1559,
14,
17070,
342,
267,
587,
26,
288,
372,
1613,
8,
23069,
12,
291,
680,
885,
8,
1113,
9,
421,
199,
533,
485,
4649,
13674,
8672,
1378,
1692,
8,
785,
304,
339,
768,
4639,
272,
347,
2198,
63,
1310,
8,
1310,
12,
372,
63,
466,
304,
267,
1449,
267,
6077,
314,
29034,
1159,
2396,
436,
5554,
1006,
314,
666,
1901,
282,
1021,
402,
267,
372,
63,
466,
14,
267,
1449,
267,
1382,
275,
19165,
14,
14934,
8,
1310,
14,
2030,
9,
267,
372,
63,
1113,
275,
372,
63,
466,
342,
267,
2748,
63,
354,
275,
372,
63,
466,
423,
1652,
63,
354,
340,
2688,
8,
1107,
63,
466,
12,
2513,
1652,
63,
354,
358,
587,
372,
63,
466,
855,
354,
363,
4960,
367,
1031,
315,
485,
4649,
13674,
8672,
1378,
1692,
14,
362,
63,
1739,
63,
2415,
8,
1301,
12,
2748,
63,
354,
304,
288,
485,
4649,
13674,
8672,
1378,
1692,
423,
4498,
63,
576,
63,
475,
63,
1107,
63,
785,
8,
932,
12,
372,
63,
1113,
9,
398,
372,
372,
63,
1113,
2378,
768,
4639,
272,
347,
2198,
63,
1364,
63,
4435,
63,
1310,
8,
1310,
12,
372,
63,
466,
304,
267,
1449,
267,
6077,
314,
29034,
1159,
2396,
436,
5554,
1006,
314,
666,
1901,
282,
1021,
402,
267,
372,
63,
466,
14,
267,
1449,
267,
1382,
275,
19165,
14,
14934,
8,
1310,
14,
2030,
9,
267,
372,
63,
1113,
275,
485,
513,
63,
1618,
8,
1107,
63,
466,
9,
267,
367,
1031,
315,
485,
4649,
13674,
8672,
1378,
1692,
14,
362,
63,
3223,
63,
504,
63,
515,
8,
1301,
12,
298,
3167,
13745,
401,
298,
3167,
4031,
2349,
288,
2257,
63,
1113,
275,
372,
63,
466,
342,
288,
485,
4649,
13674,
8672,
1378,
1692,
423,
4498,
63,
576,
63,
475,
63,
1107,
63,
785,
8,
932,
12,
2257,
63,
1113,
9,
288,
372,
63,
1113,
14,
740,
8,
1832,
63,
1113,
9,
398,
372,
372,
63,
1113,
2378,
768,
4639,
272,
347,
5554,
63,
576,
63,
1114,
8,
1652,
1301,
12,
1819,
63,
354,
12,
666,
63,
1114,
304,
267,
17725,
274,
20446,
275,
485,
4649,
13674,
8672,
1378,
1692,
14,
362,
63,
1739,
63,
2415,
8,
288,
2748,
1301,
12,
485,
362,
63,
12161,
63,
354,
8,
2108,
63,
354,
430,
398,
340,
440,
17725,
274,
20446,
503,
440,
17725,
274,
20446,
59,
16,
1055,
10626,
26,
288,
372,
488,
398,
574,
275,
17725,
274,
20446,
59,
16,
1055,
22262,
14,
17240,
398,
340,
666,
63,
1114,
365,
488,
26,
288,
372,
574,
267,
916,
1228,
8,
576,
63,
1114,
12,
2197,
304,
288,
372,
485,
475,
63,
2083,
8,
585,
9,
267,
916,
730,
8,
576,
63,
1114,
9,
365,
2155,
26,
288,
372,
574,
14,
2325,
342,
1137,
283,
3910,
7,
267,
587,
26,
288,
372,
730,
8,
576,
63,
1114,
5130,
585,
9,
2378,
768,
4639,
272,
347,
3957,
63,
1652,
63,
475,
63,
9078,
63,
785,
8,
1652,
495,
12,
13601,
63,
466,
12,
2387,
63,
344,
29,
549,
12,
675,
63,
1213,
63,
305,
63,
344,
29,
549,
304,
267,
2748,
1301,
275,
19165,
14,
14934,
8,
1652,
495,
9,
267,
372,
63,
1113,
275,
13601,
63,
466,
342,
267,
2748,
63,
354,
275,
13601,
63,
466,
423,
1652,
63,
354,
340,
2688,
8,
9078,
63,
466,
12,
2513,
1652,
63,
354,
358,
587,
13601,
63,
466,
855,
354,
363,
398,
327,
5972,
1373,
2397,
2348,
267,
367,
2748,
63,
2373,
315,
485,
4649,
13674,
8672,
1378,
1692,
14,
362,
63,
3223,
63,
504,
63,
515,
8,
1652,
1301
] |
[
120,
124,
25812,
199,
3,
1898,
334,
67,
9,
15332,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
7656,
9460,
199,
646,
2022,
199,
646,
984,
199,
504,
2197,
492,
2197,
199,
504,
2748,
14,
4556,
492,
19165,
199,
504,
13653,
2330,
63,
992,
492,
334,
272,
16261,
12,
272,
5417,
22386,
1451,
12,
272,
485,
1563,
772,
1558,
12,
272,
485,
807,
63,
1618,
12,
272,
485,
513,
63,
1618,
12,
272,
485,
7033,
63,
513,
63,
1618,
12,
272,
485,
495,
466,
12,
272,
485,
2975,
63,
466,
12,
272,
485,
1652,
63,
3215,
12,
199,
9,
199,
504,
13653,
2330,
63,
15083,
492,
334,
272,
485,
2708,
63,
1095,
772,
63,
475,
63,
505,
12,
272,
485,
2143,
63,
1095,
772,
12,
272,
485,
2325,
12,
272,
485,
495,
12,
272,
485,
2708,
63,
1095,
772,
63,
475,
63,
2394,
12,
199,
9,
199,
504,
13653,
2330,
63,
12161,
492,
334,
272,
485,
981,
63,
2373,
12,
272,
485,
362,
63,
12161,
63,
354,
12,
272,
485,
409,
63,
20305,
63,
504,
63,
1310,
63,
2139,
12,
272,
485,
362,
63,
11875,
63,
344,
12,
199,
9,
199,
504,
13653,
2330,
63,
705,
492,
334,
272,
485,
10706,
63,
705,
63,
2232,
12,
272,
485,
3502,
63,
1397,
63,
3592,
12,
199,
9,
199,
504,
1275,
992,
492,
334,
272,
16599,
7615,
2364,
12,
272,
2790,
3120,
2364,
12,
272,
10130,
5688,
1084,
12,
272,
7591,
12106,
8814,
12,
272,
7591,
12106,
10708,
12,
272,
5417,
5688,
1084,
12,
199,
9,
199,
199,
8314,
63,
2709,
275,
283,
1014,
921,
9482,
14,
17040,
14,
957,
15,
5129,
15,
9488,
15,
2036,
15,
576,
5950,
15,
2343,
7,
199,
199,
533,
4840,
6679,
8,
1001,
14,
23069,
304,
272,
347,
849,
8,
277,
12,
1559,
304,
267,
340,
1228,
8,
1113,
12,
2197,
304,
288,
372,
1559,
14,
17070,
342,
267,
587,
26,
288,
372,
1613,
8,
23069,
12,
291,
680,
885,
8,
1113,
9,
421,
199,
533,
485,
4649,
13674,
8672,
1378,
1692,
8,
785,
304,
339,
768,
4639,
272,
347,
2198,
63,
1310,
8,
1310,
12,
372,
63,
466,
304,
267,
1449,
267,
6077,
314,
29034,
1159,
2396,
436,
5554,
1006,
314,
666,
1901,
282,
1021,
402,
267,
372,
63,
466,
14,
267,
1449,
267,
1382,
275,
19165,
14,
14934,
8,
1310,
14,
2030,
9,
267,
372,
63,
1113,
275,
372,
63,
466,
342,
267,
2748,
63,
354,
275,
372,
63,
466,
423,
1652,
63,
354,
340,
2688,
8,
1107,
63,
466,
12,
2513,
1652,
63,
354,
358,
587,
372,
63,
466,
855,
354,
363,
4960,
367,
1031,
315,
485,
4649,
13674,
8672,
1378,
1692,
14,
362,
63,
1739,
63,
2415,
8,
1301,
12,
2748,
63,
354,
304,
288,
485,
4649,
13674,
8672,
1378,
1692,
423,
4498,
63,
576,
63,
475,
63,
1107,
63,
785,
8,
932,
12,
372,
63,
1113,
9,
398,
372,
372,
63,
1113,
2378,
768,
4639,
272,
347,
2198,
63,
1364,
63,
4435,
63,
1310,
8,
1310,
12,
372,
63,
466,
304,
267,
1449,
267,
6077,
314,
29034,
1159,
2396,
436,
5554,
1006,
314,
666,
1901,
282,
1021,
402,
267,
372,
63,
466,
14,
267,
1449,
267,
1382,
275,
19165,
14,
14934,
8,
1310,
14,
2030,
9,
267,
372,
63,
1113,
275,
485,
513,
63,
1618,
8,
1107,
63,
466,
9,
267,
367,
1031,
315,
485,
4649,
13674,
8672,
1378,
1692,
14,
362,
63,
3223,
63,
504,
63,
515,
8,
1301,
12,
298,
3167,
13745,
401,
298,
3167,
4031,
2349,
288,
2257,
63,
1113,
275,
372,
63,
466,
342,
288,
485,
4649,
13674,
8672,
1378,
1692,
423,
4498,
63,
576,
63,
475,
63,
1107,
63,
785,
8,
932,
12,
2257,
63,
1113,
9,
288,
372,
63,
1113,
14,
740,
8,
1832,
63,
1113,
9,
398,
372,
372,
63,
1113,
2378,
768,
4639,
272,
347,
5554,
63,
576,
63,
1114,
8,
1652,
1301,
12,
1819,
63,
354,
12,
666,
63,
1114,
304,
267,
17725,
274,
20446,
275,
485,
4649,
13674,
8672,
1378,
1692,
14,
362,
63,
1739,
63,
2415,
8,
288,
2748,
1301,
12,
485,
362,
63,
12161,
63,
354,
8,
2108,
63,
354,
430,
398,
340,
440,
17725,
274,
20446,
503,
440,
17725,
274,
20446,
59,
16,
1055,
10626,
26,
288,
372,
488,
398,
574,
275,
17725,
274,
20446,
59,
16,
1055,
22262,
14,
17240,
398,
340,
666,
63,
1114,
365,
488,
26,
288,
372,
574,
267,
916,
1228,
8,
576,
63,
1114,
12,
2197,
304,
288,
372,
485,
475,
63,
2083,
8,
585,
9,
267,
916,
730,
8,
576,
63,
1114,
9,
365,
2155,
26,
288,
372,
574,
14,
2325,
342,
1137,
283,
3910,
7,
267,
587,
26,
288,
372,
730,
8,
576,
63,
1114,
5130,
585,
9,
2378,
768,
4639,
272,
347,
3957,
63,
1652,
63,
475,
63,
9078,
63,
785,
8,
1652,
495,
12,
13601,
63,
466,
12,
2387,
63,
344,
29,
549,
12,
675,
63,
1213,
63,
305,
63,
344,
29,
549,
304,
267,
2748,
1301,
275,
19165,
14,
14934,
8,
1652,
495,
9,
267,
372,
63,
1113,
275,
13601,
63,
466,
342,
267,
2748,
63,
354,
275,
13601,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
nkmk/python-snippets
|
notebook/dict_keys_values_items.py
|
1
|
1226
|
d = {'key1': 1, 'key2': 2, 'key3': 3}
for k in d:
print(k)
# key1
# key2
# key3
for k in d.keys():
print(k)
# key1
# key2
# key3
keys = d.keys()
print(keys)
print(type(keys))
# dict_keys(['key1', 'key2', 'key3'])
# <class 'dict_keys'>
k_list = list(d.keys())
print(k_list)
print(type(k_list))
# ['key1', 'key2', 'key3']
# <class 'list'>
for v in d.values():
print(v)
# 1
# 2
# 3
values = d.values()
print(values)
print(type(values))
# dict_values([1, 2, 3])
# <class 'dict_values'>
v_list = list(d.values())
print(v_list)
print(type(v_list))
# [1, 2, 3]
# <class 'list'>
for k, v in d.items():
print(k, v)
# key1 1
# key2 2
# key3 3
for t in d.items():
print(t)
print(type(t))
print(t[0])
print(t[1])
print('---')
# ('key1', 1)
# <class 'tuple'>
# key1
# 1
# ---
# ('key2', 2)
# <class 'tuple'>
# key2
# 2
# ---
# ('key3', 3)
# <class 'tuple'>
# key3
# 3
# ---
items = d.items()
print(items)
print(type(items))
# dict_items([('key1', 1), ('key2', 2), ('key3', 3)])
# <class 'dict_items'>
i_list = list(d.items())
print(i_list)
print(type(i_list))
# [('key1', 1), ('key2', 2), ('key3', 3)]
# <class 'list'>
print(i_list[0])
print(type(i_list[0]))
# ('key1', 1)
# <class 'tuple'>
|
mit
|
[
68,
275,
791,
498,
17,
356,
413,
12,
283,
498,
18,
356,
499,
12,
283,
498,
19,
356,
650,
93,
199,
199,
509,
1022,
315,
366,
26,
272,
870,
8,
75,
9,
199,
3,
790,
17,
199,
3,
790,
18,
199,
3,
790,
19,
199,
199,
509,
1022,
315,
366,
14,
1612,
837,
272,
870,
8,
75,
9,
199,
3,
790,
17,
199,
3,
790,
18,
199,
3,
790,
19,
199,
199,
1612,
275,
366,
14,
1612,
342,
199,
1361,
8,
1612,
9,
199,
1361,
8,
466,
8,
1612,
430,
199,
3,
1211,
63,
1612,
2941,
498,
17,
297,
283,
498,
18,
297,
283,
498,
19,
1105,
199,
3,
665,
533,
283,
807,
63,
1612,
8423,
199,
199,
75,
63,
513,
275,
769,
8,
68,
14,
1612,
1012,
199,
1361,
8,
75,
63,
513,
9,
199,
1361,
8,
466,
8,
75,
63,
513,
430,
199,
3,
788,
498,
17,
297,
283,
498,
18,
297,
283,
498,
19,
418,
199,
3,
665,
533,
283,
513,
8423,
199,
199,
509,
373,
315,
366,
14,
1459,
837,
272,
870,
8,
86,
9,
199,
3,
413,
199,
3,
499,
199,
3,
650,
199,
199,
1459,
275,
366,
14,
1459,
342,
199,
1361,
8,
1459,
9,
199,
1361,
8,
466,
8,
1459,
430,
199,
3,
1211,
63,
1459,
779,
17,
12,
499,
12,
650,
566,
199,
3,
665,
533,
283,
807,
63,
1459,
8423,
199,
199,
86,
63,
513,
275,
769,
8,
68,
14,
1459,
1012,
199,
1361,
8,
86,
63,
513,
9,
199,
1361,
8,
466,
8,
86,
63,
513,
430,
199,
3,
359,
17,
12,
499,
12,
650,
61,
199,
3,
665,
533,
283,
513,
8423,
199,
199,
509,
1022,
12,
373,
315,
366,
14,
1744,
837,
272,
870,
8,
75,
12,
373,
9,
199,
3,
790,
17,
413,
199,
3,
790,
18,
499,
199,
3,
790,
19,
650,
199,
199,
509,
307,
315,
366,
14,
1744,
837,
272,
870,
8,
84,
9,
272,
870,
8,
466,
8,
84,
430,
272,
870,
8,
84,
59,
16,
566,
272,
870,
8,
84,
59,
17,
566,
272,
870,
360,
2595,
358,
199,
3,
661,
498,
17,
297,
413,
9,
199,
3,
665,
533,
283,
2960,
8423,
199,
3,
790,
17,
199,
3,
413,
199,
3,
10894,
199,
3,
661,
498,
18,
297,
499,
9,
199,
3,
665,
533,
283,
2960,
8423,
199,
3,
790,
18,
199,
3,
499,
199,
3,
10894,
199,
3,
661,
498,
19,
297,
650,
9,
199,
3,
665,
533,
283,
2960,
8423,
199,
3,
790,
19,
199,
3,
650,
199,
3,
10894,
199,
199,
1744,
275,
366,
14,
1744,
342,
199,
1361,
8,
1744,
9,
199,
1361,
8,
466,
8,
1744,
430,
199,
3,
1211,
63,
1744,
8318,
498,
17,
297,
413,
395,
661,
498,
18,
297,
499,
395,
661,
498,
19,
297,
650,
3948,
199,
3,
665,
533,
283,
807,
63,
1744,
8423,
199,
199,
73,
63,
513,
275,
769,
8,
68,
14,
1744,
1012,
199,
1361,
8,
73,
63,
513,
9,
199,
1361,
8,
466,
8,
73,
63,
513,
430,
199,
3,
4274,
498,
17,
297,
413,
395,
661,
498,
18,
297,
499,
395,
661,
498,
19,
297,
650,
1874,
199,
3,
665,
533,
283,
513,
8423,
199,
199,
1361,
8,
73,
63,
513,
59,
16,
566,
199,
1361,
8,
466,
8,
73,
63,
513,
59,
16,
2459,
199,
3,
661,
498,
17,
297,
413,
9,
199,
3,
665,
533,
283,
2960,
8423,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
275,
791,
498,
17,
356,
413,
12,
283,
498,
18,
356,
499,
12,
283,
498,
19,
356,
650,
93,
199,
199,
509,
1022,
315,
366,
26,
272,
870,
8,
75,
9,
199,
3,
790,
17,
199,
3,
790,
18,
199,
3,
790,
19,
199,
199,
509,
1022,
315,
366,
14,
1612,
837,
272,
870,
8,
75,
9,
199,
3,
790,
17,
199,
3,
790,
18,
199,
3,
790,
19,
199,
199,
1612,
275,
366,
14,
1612,
342,
199,
1361,
8,
1612,
9,
199,
1361,
8,
466,
8,
1612,
430,
199,
3,
1211,
63,
1612,
2941,
498,
17,
297,
283,
498,
18,
297,
283,
498,
19,
1105,
199,
3,
665,
533,
283,
807,
63,
1612,
8423,
199,
199,
75,
63,
513,
275,
769,
8,
68,
14,
1612,
1012,
199,
1361,
8,
75,
63,
513,
9,
199,
1361,
8,
466,
8,
75,
63,
513,
430,
199,
3,
788,
498,
17,
297,
283,
498,
18,
297,
283,
498,
19,
418,
199,
3,
665,
533,
283,
513,
8423,
199,
199,
509,
373,
315,
366,
14,
1459,
837,
272,
870,
8,
86,
9,
199,
3,
413,
199,
3,
499,
199,
3,
650,
199,
199,
1459,
275,
366,
14,
1459,
342,
199,
1361,
8,
1459,
9,
199,
1361,
8,
466,
8,
1459,
430,
199,
3,
1211,
63,
1459,
779,
17,
12,
499,
12,
650,
566,
199,
3,
665,
533,
283,
807,
63,
1459,
8423,
199,
199,
86,
63,
513,
275,
769,
8,
68,
14,
1459,
1012,
199,
1361,
8,
86,
63,
513,
9,
199,
1361,
8,
466,
8,
86,
63,
513,
430,
199,
3,
359,
17,
12,
499,
12,
650,
61,
199,
3,
665,
533,
283,
513,
8423,
199,
199,
509,
1022,
12,
373,
315,
366,
14,
1744,
837,
272,
870,
8,
75,
12,
373,
9,
199,
3,
790,
17,
413,
199,
3,
790,
18,
499,
199,
3,
790,
19,
650,
199,
199,
509,
307,
315,
366,
14,
1744,
837,
272,
870,
8,
84,
9,
272,
870,
8,
466,
8,
84,
430,
272,
870,
8,
84,
59,
16,
566,
272,
870,
8,
84,
59,
17,
566,
272,
870,
360,
2595,
358,
199,
3,
661,
498,
17,
297,
413,
9,
199,
3,
665,
533,
283,
2960,
8423,
199,
3,
790,
17,
199,
3,
413,
199,
3,
10894,
199,
3,
661,
498,
18,
297,
499,
9,
199,
3,
665,
533,
283,
2960,
8423,
199,
3,
790,
18,
199,
3,
499,
199,
3,
10894,
199,
3,
661,
498,
19,
297,
650,
9,
199,
3,
665,
533,
283,
2960,
8423,
199,
3,
790,
19,
199,
3,
650,
199,
3,
10894,
199,
199,
1744,
275,
366,
14,
1744,
342,
199,
1361,
8,
1744,
9,
199,
1361,
8,
466,
8,
1744,
430,
199,
3,
1211,
63,
1744,
8318,
498,
17,
297,
413,
395,
661,
498,
18,
297,
499,
395,
661,
498,
19,
297,
650,
3948,
199,
3,
665,
533,
283,
807,
63,
1744,
8423,
199,
199,
73,
63,
513,
275,
769,
8,
68,
14,
1744,
1012,
199,
1361,
8,
73,
63,
513,
9,
199,
1361,
8,
466,
8,
73,
63,
513,
430,
199,
3,
4274,
498,
17,
297,
413,
395,
661,
498,
18,
297,
499,
395,
661,
498,
19,
297,
650,
1874,
199,
3,
665,
533,
283,
513,
8423,
199,
199,
1361,
8,
73,
63,
513,
59,
16,
566,
199,
1361,
8,
466,
8,
73,
63,
513,
59,
16,
2459,
199,
3,
661,
498,
17,
297,
413,
9,
199,
3,
665,
533,
283,
2960,
8423,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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c) 2002, 2004, 2008 David Turner <david@freetype.org>
#
# This program is a re-write of the original DocMaker took used
# to generate the API Reference of the FreeType font engine
# by converting in-source comments into structured HTML.
#
# This new version is capable of outputting XML data, as well
# as accepts more liberal formatting options.
#
# It also uses regular expression matching and substitution
# to speed things significantly.
#
from sources import *
from content import *
from utils import *
from formatter import *
from tohtml import *
import utils
import sys, os, time, string, glob, getopt
def usage():
print "\nDocMaker Usage information\n"
print " docmaker [options] file1 [file2 ...]\n"
print "using the following options:\n"
print " -h : print this page"
print " -t : set project title, as in '-t \"My Project\"'"
print " -o : set output directory, as in '-o mydir'"
print " -p : set documentation prefix, as in '-p ft2'"
print ""
print " --title : same as -t, as in '--title=\"My Project\"'"
print " --output : same as -o, as in '--output=mydir'"
print " --prefix : same as -p, as in '--prefix=ft2'"
def main( argv ):
"""main program loop"""
global output_dir
try:
opts, args = getopt.getopt( sys.argv[1:], \
"ht:o:p:", \
["help", "title=", "output=", "prefix="] )
except getopt.GetoptError:
usage()
sys.exit( 2 )
if args == []:
usage()
sys.exit( 1 )
# process options
#
project_title = "Project"
project_prefix = None
output_dir = None
for opt in opts:
if opt[0] in ( "-h", "--help" ):
usage()
sys.exit( 0 )
if opt[0] in ( "-t", "--title" ):
project_title = opt[1]
if opt[0] in ( "-o", "--output" ):
utils.output_dir = opt[1]
if opt[0] in ( "-p", "--prefix" ):
project_prefix = opt[1]
check_output()
# create context and processor
source_processor = SourceProcessor()
content_processor = ContentProcessor()
# retrieve the list of files to process
file_list = make_file_list( args )
for filename in file_list:
source_processor.parse_file( filename )
content_processor.parse_sources( source_processor )
# process sections
content_processor.finish()
formatter = HtmlFormatter( content_processor, project_title, project_prefix )
formatter.toc_dump()
formatter.index_dump()
formatter.section_dump_all()
# if called from the command line
#
if __name__ == '__main__':
main( sys.argv )
# eof
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
18,
199,
3,
199,
3,
221,
5454,
23560,
334,
67,
9,
14790,
12,
8353,
12,
9079,
20232,
16147,
281,
665,
983,
5017,
32,
4624,
466,
14,
1308,
30,
199,
3,
199,
3,
961,
2240,
365,
282,
295,
13,
952,
402,
314,
3379,
5454,
23560,
27221,
1202,
199,
3,
370,
3550,
314,
3261,
10944,
402,
314,
2868,
804,
5023,
6869,
199,
3,
701,
13806,
315,
13,
1365,
6786,
1901,
21781,
4163,
14,
199,
3,
199,
3,
961,
892,
1015,
365,
4021,
461,
402,
1072,
1337,
4692,
666,
12,
465,
5521,
199,
3,
465,
11479,
1655,
1212,
605,
279,
10803,
1511,
14,
199,
3,
199,
3,
2779,
2597,
4440,
5578,
3965,
4877,
436,
20584,
199,
3,
370,
8112,
7645,
16474,
590,
14,
199,
3,
199,
199,
504,
5274,
257,
492,
627,
199,
504,
1564,
257,
492,
627,
199,
504,
3778,
258,
492,
627,
199,
504,
9698,
492,
627,
199,
504,
370,
1360,
259,
492,
627,
199,
199,
646,
3778,
199,
199,
646,
984,
12,
747,
12,
900,
12,
1059,
12,
5739,
12,
12733,
421,
199,
318,
221,
4503,
837,
272,
870,
1867,
78,
3768,
23560,
11028,
2556,
60,
78,
2,
272,
870,
298,
221,
1382,
14367,
359,
1419,
61,
570,
17,
359,
493,
18,
2263,
7272,
78,
2,
272,
870,
298,
4941,
314,
2569,
1511,
3427,
78,
2,
272,
870,
298,
221,
446,
72,
520,
870,
642,
2034,
2,
272,
870,
298,
221,
446,
84,
520,
663,
2199,
2538,
12,
465,
315,
2475,
84,
8441,
5713,
7290,
4451,
4065,
272,
870,
298,
221,
446,
79,
520,
663,
1072,
2082,
12,
465,
315,
2475,
79,
3002,
694,
4065,
272,
870,
298,
221,
446,
80,
520,
663,
3794,
2403,
12,
465,
315,
2475,
80,
18133,
18,
4065,
272,
870,
3087,
272,
870,
298,
221,
1553,
1213,
221,
520,
2011,
465,
446,
84,
12,
465,
315,
2850,
1213,
8178,
5713,
7290,
4451,
4065,
272,
870,
298,
221,
1553,
1199,
520,
2011,
465,
446,
79,
12,
465,
315,
2850,
1199,
29,
1662,
694,
4065,
272,
870,
298,
221,
1553,
1861,
520,
2011,
465,
446,
80,
12,
465,
315,
2850,
1861,
29,
856,
18,
4065,
421,
199,
318,
221,
2446,
8,
9238,
3461,
272,
408,
973,
2240,
4438,
624,
339,
2288,
1072,
63,
694,
339,
862,
26,
267,
3999,
12,
1249,
275,
12733,
14,
18907,
8,
984,
14,
3020,
59,
17,
8429,
971,
2511,
298,
517,
26,
79,
26,
80,
6783,
259,
971,
2511,
2097,
3437,
401,
298,
1213,
11107,
298,
1199,
11107,
298,
1861,
628,
61,
776,
272,
871,
12733,
14,
1002,
29368,
26,
267,
4503,
342,
267,
984,
14,
2224,
8,
499,
776,
339,
340,
1249,
508,
18410,
267,
4503,
342,
267,
984,
14,
2224,
8,
413,
776,
339,
327,
2112,
1511,
272,
327,
272,
2199,
63,
1213,
221,
275,
298,
4761,
2,
272,
2199,
63,
1861,
275,
488,
272,
1072,
63,
694,
258,
275,
488,
339,
367,
2450,
315,
3999,
26,
267,
340,
2450,
59,
16,
61,
315,
334,
3905,
72,
401,
4320,
3437,
2,
3461,
288,
4503,
342,
288,
984,
14,
2224,
8,
378,
776,
398,
340,
2450,
59,
16,
61,
315,
334,
3905,
84,
401,
4320,
1213,
2,
3461,
288,
2199,
63,
1213,
275,
2450,
59,
17,
61,
398,
340,
2450,
59,
16,
61,
315,
334,
3905,
79,
401,
4320,
1199,
2,
3461,
288,
3778,
14,
1199,
63,
694,
275,
2450,
59,
17,
61,
398,
340,
2450,
59,
16,
61,
315,
334,
3905,
80,
401,
4320,
1861,
2,
3461,
288,
2199,
63,
1861,
275,
2450,
59,
17,
61,
339,
1104,
63,
1199,
342,
339,
327,
1218,
1067,
436,
12495,
272,
1350,
63,
6459,
221,
275,
5800,
10438,
342,
272,
1564,
63,
6459,
275,
6646,
10438,
342,
339,
327,
8044,
314,
769,
402,
1584,
370,
2112,
272,
570,
63,
513,
275,
1852,
63,
493,
63,
513,
8,
1249,
776,
272,
367,
1788,
315,
570,
63,
513,
26,
267,
1350,
63,
6459,
14,
1122,
63,
493,
8,
1788,
776,
267,
1564,
63,
6459,
14,
1122,
63,
4553,
8,
1350,
63,
6459,
776,
339,
327,
2112,
10189,
272,
1564,
63,
6459,
14,
8192,
342,
339,
9698,
275,
20880,
7772,
8,
1564,
63,
6459,
12,
2199,
63,
1213,
12,
2199,
63,
1861,
776,
339,
9698,
14,
13255,
63,
2724,
342,
272,
9698,
14,
1080,
63,
2724,
342,
272,
9698,
14,
2792,
63,
2724,
63,
452,
342,
421,
199,
3,
340,
2797,
687,
314,
1414,
1004,
199,
3,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
8,
984,
14,
3020,
776,
421,
199,
3,
29403,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
18,
199,
3,
199,
3,
221,
5454,
23560,
334,
67,
9,
14790,
12,
8353,
12,
9079,
20232,
16147,
281,
665,
983,
5017,
32,
4624,
466,
14,
1308,
30,
199,
3,
199,
3,
961,
2240,
365,
282,
295,
13,
952,
402,
314,
3379,
5454,
23560,
27221,
1202,
199,
3,
370,
3550,
314,
3261,
10944,
402,
314,
2868,
804,
5023,
6869,
199,
3,
701,
13806,
315,
13,
1365,
6786,
1901,
21781,
4163,
14,
199,
3,
199,
3,
961,
892,
1015,
365,
4021,
461,
402,
1072,
1337,
4692,
666,
12,
465,
5521,
199,
3,
465,
11479,
1655,
1212,
605,
279,
10803,
1511,
14,
199,
3,
199,
3,
2779,
2597,
4440,
5578,
3965,
4877,
436,
20584,
199,
3,
370,
8112,
7645,
16474,
590,
14,
199,
3,
199,
199,
504,
5274,
257,
492,
627,
199,
504,
1564,
257,
492,
627,
199,
504,
3778,
258,
492,
627,
199,
504,
9698,
492,
627,
199,
504,
370,
1360,
259,
492,
627,
199,
199,
646,
3778,
199,
199,
646,
984,
12,
747,
12,
900,
12,
1059,
12,
5739,
12,
12733,
421,
199,
318,
221,
4503,
837,
272,
870,
1867,
78,
3768,
23560,
11028,
2556,
60,
78,
2,
272,
870,
298,
221,
1382,
14367,
359,
1419,
61,
570,
17,
359,
493,
18,
2263,
7272,
78,
2,
272,
870,
298,
4941,
314,
2569,
1511,
3427,
78,
2,
272,
870,
298,
221,
446,
72,
520,
870,
642,
2034,
2,
272,
870,
298,
221,
446,
84,
520,
663,
2199,
2538,
12,
465,
315,
2475,
84,
8441,
5713,
7290,
4451,
4065,
272,
870,
298,
221,
446,
79,
520,
663,
1072,
2082,
12,
465,
315,
2475,
79,
3002,
694,
4065,
272,
870,
298,
221,
446,
80,
520,
663,
3794,
2403,
12,
465,
315,
2475,
80,
18133,
18,
4065,
272,
870,
3087,
272,
870,
298,
221,
1553,
1213,
221,
520,
2011,
465,
446,
84,
12,
465,
315,
2850,
1213,
8178,
5713,
7290,
4451,
4065,
272,
870,
298,
221,
1553,
1199,
520,
2011,
465,
446,
79,
12,
465,
315,
2850,
1199,
29,
1662,
694,
4065,
272,
870,
298,
221,
1553,
1861,
520,
2011,
465,
446,
80,
12,
465,
315,
2850,
1861,
29,
856,
18,
4065,
421,
199,
318,
221,
2446,
8,
9238,
3461,
272,
408,
973,
2240,
4438,
624,
339,
2288,
1072,
63,
694,
339,
862,
26,
267,
3999,
12,
1249,
275,
12733,
14,
18907,
8,
984,
14,
3020,
59,
17,
8429,
971,
2511,
298,
517,
26,
79,
26,
80,
6783,
259,
971,
2511,
2097,
3437,
401,
298,
1213,
11107,
298,
1199,
11107,
298,
1861,
628,
61,
776,
272,
871,
12733,
14,
1002,
29368,
26,
267,
4503,
342,
267,
984,
14,
2224,
8,
499,
776,
339,
340,
1249,
508,
18410,
267,
4503,
342,
267,
984,
14,
2224,
8,
413,
776,
339,
327,
2112,
1511,
272,
327,
272,
2199,
63,
1213,
221,
275,
298,
4761,
2,
272,
2199,
63,
1861,
275,
488,
272,
1072,
63,
694,
258,
275,
488,
339,
367,
2450,
315,
3999,
26,
267,
340,
2450,
59,
16,
61,
315,
334,
3905,
72,
401,
4320,
3437,
2,
3461,
288,
4503,
342,
288,
984,
14,
2224,
8,
378,
776,
398,
340,
2450,
59,
16,
61,
315,
334,
3905,
84,
401,
4320,
1213,
2,
3461,
288,
2199,
63,
1213,
275,
2450,
59,
17,
61,
398,
340,
2450,
59,
16,
61,
315,
334,
3905,
79,
401,
4320,
1199,
2,
3461,
288,
3778,
14,
1199,
63,
694,
275,
2450,
59,
17,
61,
398,
340,
2450,
59,
16,
61,
315,
334,
3905,
80,
401,
4320,
1861,
2,
3461,
288,
2199,
63,
1861,
275,
2450,
59,
17,
61,
339,
1104,
63,
1199,
342,
339,
327,
1218,
1067,
436,
12495,
272,
1350,
63,
6459,
221,
275,
5800,
10438,
342,
272,
1564,
63,
6459,
275,
6646,
10438,
342,
339,
327,
8044,
314,
769,
402,
1584,
370,
2112,
272,
570,
63,
513,
275,
1852,
63,
493,
63,
513,
8,
1249,
776,
272,
367,
1788,
315,
570,
63,
513,
26,
267,
1350,
63,
6459,
14,
1122,
63,
493,
8,
1788,
776,
267,
1564,
63,
6459,
14,
1122,
63,
4553,
8,
1350,
63,
6459,
776,
339,
327,
2112,
10189,
272,
1564,
63,
6459,
14,
8192,
342,
339,
9698,
275,
20880,
7772,
8,
1564,
63,
6459,
12,
2199,
63,
1213,
12,
2199,
63,
1861,
776,
339,
9698,
14,
13255,
63,
2724,
342,
272,
9698,
14,
1080,
63,
2724,
342,
272,
9698,
14,
2792,
63,
2724,
63,
452,
342,
421,
199,
3,
340,
2797,
687,
314,
1414,
1004,
199,
3,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
8,
984,
14,
3020,
776,
421,
199,
3,
29403,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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
from scipy import ndimage
from collections import Counter
from core.vggnet import Vgg19
from core.utils import *
import tensorflow as tf
import numpy as np
import pandas as pd
import hickle
import os
import json
def _process_caption_data(caption_file, image_dir, max_length):
with open(caption_file) as f:
caption_data = json.load(f)
# id_to_filename is a dictionary such as {image_id: filename]}
id_to_filename = {image['id']: image['file_name'] for image in caption_data['images']}
# data is a list of dictionary which contains 'captions', 'file_name' and 'image_id' as key.
data = []
for annotation in caption_data['annotations']:
image_id = annotation['image_id']
annotation['file_name'] = os.path.join(image_dir, id_to_filename[image_id])
data += [annotation]
# convert to pandas dataframe (for later visualization or debugging)
caption_data = pd.DataFrame.from_dict(data)
del caption_data['id']
caption_data.sort_values(by='image_id', inplace=True)
caption_data = caption_data.reset_index(drop=True)
del_idx = []
for i, caption in enumerate(caption_data['caption']):
caption = caption.replace('.','').replace(',','').replace("'","").replace('"','')
caption = caption.replace('&','and').replace('(','').replace(")","").replace('-',' ')
caption = " ".join(caption.split()) # replace multiple spaces
caption_data.set_value(i, 'caption', caption.lower())
if len(caption.split(" ")) > max_length:
del_idx.append(i)
# delete captions if size is larger than max_length
print "The number of captions before deletion: %d" %len(caption_data)
caption_data = caption_data.drop(caption_data.index[del_idx])
caption_data = caption_data.reset_index(drop=True)
print "The number of captions after deletion: %d" %len(caption_data)
return caption_data
def _build_vocab(annotations, threshold=1):
counter = Counter()
max_len = 0
for i, caption in enumerate(annotations['caption']):
words = caption.split(' ') # caption contrains only lower-case words
for w in words:
counter[w] +=1
if len(caption.split(" ")) > max_len:
max_len = len(caption.split(" "))
vocab = [word for word in counter if counter[word] >= threshold]
print ('Filtered %d words to %d words with word count threshold %d.' % (len(counter), len(vocab), threshold))
word_to_idx = {u'<NULL>': 0, u'<START>': 1, u'<END>': 2}
idx = 3
for word in vocab:
word_to_idx[word] = idx
idx += 1
print "Max length of caption: ", max_len
return word_to_idx
def _build_caption_vector(annotations, word_to_idx, max_length=15):
n_examples = len(annotations)
captions = np.ndarray((n_examples,max_length+2)).astype(np.int32)
for i, caption in enumerate(annotations['caption']):
words = caption.split(" ") # caption contrains only lower-case words
cap_vec = []
cap_vec.append(word_to_idx['<START>'])
for word in words:
if word in word_to_idx:
cap_vec.append(word_to_idx[word])
cap_vec.append(word_to_idx['<END>'])
# pad short caption with the special null token '<NULL>' to make it fixed-size vector
if len(cap_vec) < (max_length + 2):
for j in range(max_length + 2 - len(cap_vec)):
cap_vec.append(word_to_idx['<NULL>'])
captions[i, :] = np.asarray(cap_vec)
print "Finished building caption vectors"
return captions
def _build_file_names(annotations):
image_file_names = []
id_to_idx = {}
idx = 0
image_ids = annotations['image_id']
file_names = annotations['file_name']
for image_id, file_name in zip(image_ids, file_names):
if not image_id in id_to_idx:
id_to_idx[image_id] = idx
image_file_names.append(file_name)
idx += 1
file_names = np.asarray(image_file_names)
return file_names, id_to_idx
def _build_image_idxs(annotations, id_to_idx):
image_idxs = np.ndarray(len(annotations), dtype=np.int32)
image_ids = annotations['image_id']
for i, image_id in enumerate(image_ids):
image_idxs[i] = id_to_idx[image_id]
return image_idxs
def main():
# batch size for extracting feature vectors from vggnet.
batch_size = 100
# maximum length of caption(number of word). if caption is longer than max_length, deleted.
max_length = 15
# if word occurs less than word_count_threshold in training dataset, the word index is special unknown token.
word_count_threshold = 1
# vgg model path
vgg_model_path = './data/imagenet-vgg-verydeep-19.mat'
caption_file = 'data/annotations/captions_train2014.json'
image_dir = 'image/%2014_resized/'
# about 80000 images and 400000 captions for train dataset
train_dataset = _process_caption_data(caption_file='data/annotations/captions_train2014.json',
image_dir='image/train2014_resized/',
max_length=max_length)
# about 40000 images and 200000 captions
val_dataset = _process_caption_data(caption_file='data/annotations/captions_val2014.json',
image_dir='image/val2014_resized/',
max_length=max_length)
# about 4000 images and 20000 captions for val / test dataset
val_cutoff = int(0.1 * len(val_dataset))
test_cutoff = int(0.2 * len(val_dataset))
print 'Finished processing caption data'
save_pickle(train_dataset, 'data/train/train.annotations.pkl')
save_pickle(val_dataset[:val_cutoff], 'data/val/val.annotations.pkl')
save_pickle(val_dataset[val_cutoff:test_cutoff].reset_index(drop=True), 'data/test/test.annotations.pkl')
for split in ['train', 'val', 'test']:
annotations = load_pickle('./data/%s/%s.annotations.pkl' % (split, split))
if split == 'train':
word_to_idx = _build_vocab(annotations=annotations, threshold=word_count_threshold)
save_pickle(word_to_idx, './data/%s/word_to_idx.pkl' % split)
captions = _build_caption_vector(annotations=annotations, word_to_idx=word_to_idx, max_length=max_length)
save_pickle(captions, './data/%s/%s.captions.pkl' % (split, split))
file_names, id_to_idx = _build_file_names(annotations)
save_pickle(file_names, './data/%s/%s.file.names.pkl' % (split, split))
image_idxs = _build_image_idxs(annotations, id_to_idx)
save_pickle(image_idxs, './data/%s/%s.image.idxs.pkl' % (split, split))
# prepare reference captions to compute bleu scores later
image_ids = {}
feature_to_captions = {}
i = -1
for caption, image_id in zip(annotations['caption'], annotations['image_id']):
if not image_id in image_ids:
image_ids[image_id] = 0
i += 1
feature_to_captions[i] = []
feature_to_captions[i].append(caption.lower() + ' .')
save_pickle(feature_to_captions, './data/%s/%s.references.pkl' % (split, split))
print "Finished building %s caption dataset" %split
# extract conv5_3 feature vectors
vggnet = Vgg19(vgg_model_path)
vggnet.build()
with tf.Session() as sess:
tf.initialize_all_variables().run()
for split in ['train', 'val', 'test']:
anno_path = './data/%s/%s.annotations.pkl' % (split, split)
save_path = './data/%s/%s.features.hkl' % (split, split)
annotations = load_pickle(anno_path)
image_path = list(annotations['file_name'].unique())
n_examples = len(image_path)
all_feats = np.ndarray([n_examples, 196, 512], dtype=np.float32)
for start, end in zip(range(0, n_examples, batch_size),
range(batch_size, n_examples + batch_size, batch_size)):
image_batch_file = image_path[start:end]
image_batch = np.array(map(lambda x: ndimage.imread(x, mode='RGB'), image_batch_file)).astype(
np.float32)
feats = sess.run(vggnet.features, feed_dict={vggnet.images: image_batch})
all_feats[start:end, :] = feats
print ("Processed %d %s features.." % (end, split))
# use hickle to save huge feature vectors
hickle.dump(all_feats, save_path)
print ("Saved %s.." % (save_path))
if __name__ == "__main__":
main()
|
mit
|
[
504,
7026,
492,
302,
23335,
199,
504,
5055,
492,
14427,
199,
504,
6170,
14,
10929,
784,
386,
492,
812,
2721,
1167,
199,
504,
6170,
14,
1208,
492,
627,
199,
199,
646,
3228,
465,
2833,
199,
646,
2680,
465,
980,
199,
646,
10634,
465,
6454,
199,
646,
394,
2000,
274,
199,
646,
747,
199,
646,
2022,
421,
199,
318,
485,
1412,
63,
13410,
63,
576,
8,
13410,
63,
493,
12,
1834,
63,
694,
12,
1390,
63,
1267,
304,
272,
543,
1551,
8,
13410,
63,
493,
9,
465,
289,
26,
267,
19038,
63,
576,
275,
2022,
14,
912,
8,
70,
9,
339,
327,
1305,
63,
475,
63,
1501,
365,
282,
2600,
4066,
465,
469,
1569,
63,
344,
26,
1788,
9420,
5591,
1305,
63,
475,
63,
1501,
275,
469,
1569,
459,
344,
2565,
1834,
459,
493,
63,
354,
418,
367,
1834,
315,
19038,
63,
576,
459,
4782,
12074,
339,
327,
666,
365,
282,
769,
402,
2600,
1314,
3509,
283,
2874,
852,
297,
283,
493,
63,
354,
7,
436,
283,
1569,
63,
344,
7,
465,
790,
14,
272,
666,
275,
942,
272,
367,
11262,
315,
19038,
63,
576,
459,
11270,
2565,
267,
1834,
63,
344,
275,
11262,
459,
1569,
63,
344,
418,
267,
11262,
459,
493,
63,
354,
418,
275,
747,
14,
515,
14,
904,
8,
1569,
63,
694,
12,
1305,
63,
475,
63,
1501,
59,
1569,
63,
344,
566,
267,
666,
847,
359,
9340,
61,
2286,
327,
3957,
370,
10634,
27168,
334,
509,
2945,
13104,
2072,
503,
10201,
9,
272,
19038,
63,
576,
275,
6454,
14,
9205,
14,
504,
63,
807,
8,
576,
9,
272,
2150,
19038,
63,
576,
459,
344,
418,
272,
19038,
63,
576,
14,
3191,
63,
1459,
8,
991,
534,
1569,
63,
344,
297,
16304,
29,
549,
9,
272,
19038,
63,
576,
275,
19038,
63,
576,
14,
3958,
63,
1080,
8,
4824,
29,
549,
9,
2286,
2150,
63,
2996,
275,
942,
272,
367,
284,
12,
19038,
315,
3874,
8,
13410,
63,
576,
459,
13410,
9090,
267,
19038,
275,
19038,
14,
1814,
5175,
26516,
1814,
5102,
26516,
1814,
27769,
341,
680,
1814,
14088,
20944,
267,
19038,
275,
19038,
14,
1814,
20040,
1673,
460,
1959,
1814,
14097,
26516,
1814,
480,
4186,
341,
680,
1814,
3654,
1673,
5320,
267,
19038,
275,
298,
3680,
904,
8,
13410,
14,
1294,
1012,
221,
327,
3350,
3663,
7883,
2728,
19038,
63,
576,
14,
409,
63,
585,
8,
73,
12,
283,
13410,
297,
19038,
14,
2325,
1012,
267,
340,
822,
8,
13410,
14,
1294,
480,
26725,
690,
1390,
63,
1267,
26,
288,
2150,
63,
2996,
14,
740,
8,
73,
9,
2286,
327,
3145,
4021,
852,
340,
1568,
365,
12142,
2419,
1390,
63,
1267,
272,
870,
298,
1918,
1329,
402,
4021,
852,
2544,
14068,
26,
450,
68,
2,
450,
552,
8,
13410,
63,
576,
9,
272,
19038,
63,
576,
275,
19038,
63,
576,
14,
4824,
8,
13410,
63,
576,
14,
1080,
59,
2264,
63,
2996,
566,
272,
19038,
63,
576,
275,
19038,
63,
576,
14,
3958,
63,
1080,
8,
4824,
29,
549,
9,
272,
870,
298,
1918,
1329,
402,
4021,
852,
2410,
14068,
26,
450,
68,
2,
450,
552,
8,
13410,
63,
576,
9,
272,
372,
19038,
63,
576,
421,
199,
318,
485,
1506,
63,
9953,
8,
11270,
12,
8765,
29,
17,
304,
272,
7055,
275,
14427,
342,
272,
1390,
63,
552,
275,
378,
272,
367,
284,
12,
19038,
315,
3874,
8,
11270,
459,
13410,
9090,
267,
5932,
275,
19038,
14,
1294,
360,
5320,
327,
19038,
406,
2834,
83,
1454,
5117,
13,
2546,
5932,
267,
367,
336,
315,
5932,
26,
288,
7055,
59,
87,
61,
847,
17,
2728,
340,
822,
8,
13410,
14,
1294,
480,
26725,
690,
1390,
63,
552,
26,
288,
1390,
63,
552,
275,
822,
8,
13410,
14,
1294,
480,
26725,
339,
11181,
275,
359,
1027,
367,
4349,
315,
7055,
340,
7055,
59,
1027,
61,
2356,
8765,
61,
272,
870,
661,
13079,
3014,
450,
68,
5932,
370,
450,
68,
5932,
543,
4349,
2338,
8765,
450,
68,
3530,
450,
334,
552,
8,
5337,
395,
822,
8,
9953,
395,
8765,
430,
339,
4349,
63,
475,
63,
2996,
275,
469,
85,
7601,
8084,
30838,
378,
12,
399,
7601,
7363,
30838,
413,
12,
399,
7601,
3902,
30838,
499,
93,
272,
4280,
275,
650,
272,
367,
4349,
315,
11181,
26,
267,
4349,
63,
475,
63,
2996,
59,
1027,
61,
275,
4280,
267,
4280,
847,
413,
272,
870,
298,
4261,
2582,
402,
19038,
26,
3872,
1390,
63,
552,
272,
372,
4349,
63,
475,
63,
2996,
421,
199,
318,
485,
1506,
63,
13410,
63,
4106,
8,
11270,
12,
4349,
63,
475,
63,
2996,
12,
1390,
63,
1267,
29,
1046,
304,
272,
302,
63,
8589,
275,
822,
8,
11270,
9,
272,
4021,
852,
275,
980,
14,
8237,
1332,
78,
63,
8589,
12,
988,
63,
1267,
11,
18,
4992,
6041,
8,
1590,
14,
442,
708,
9,
259,
339,
367,
284,
12,
19038,
315,
3874,
8,
11270,
459,
13410,
9090,
267,
5932,
275,
19038,
14,
1294,
480,
6099,
327,
19038,
406,
2834,
83,
1454,
5117,
13,
2546,
5932,
267,
4021,
63,
6046,
275,
942,
267,
4021,
63,
6046,
14,
740,
8,
1027,
63,
475,
63,
2996,
459,
28,
7363,
24782,
267,
367,
4349,
315,
5932,
26,
288,
340,
4349,
315,
4349,
63,
475,
63,
2996,
26,
355,
4021,
63,
6046,
14,
740,
8,
1027,
63,
475,
63,
2996,
59,
1027,
566,
267,
4021,
63,
6046,
14,
740,
8,
1027,
63,
475,
63,
2996,
459,
28,
3902,
24782,
2728,
327,
6567,
3974,
19038,
543,
314,
4539,
2973,
1526,
2650,
8084,
3524,
370,
1852,
652,
6317,
13,
890,
5477,
267,
340,
822,
8,
2874,
63,
6046,
9,
665,
334,
988,
63,
1267,
435,
499,
304,
288,
367,
1335,
315,
1425,
8,
988,
63,
1267,
435,
499,
446,
822,
8,
2874,
63,
6046,
2298,
355,
4021,
63,
6046,
14,
740,
8,
1027,
63,
475,
63,
2996,
459,
28,
8084,
24782,
221,
2728,
4021,
852,
59,
73,
12,
12228,
275,
980,
14,
8748,
8,
2874,
63,
6046,
9,
272,
870,
298,
13430,
10015,
19038,
11102,
2,
272,
372,
4021,
852,
421,
199,
318,
485,
1506,
63,
493,
63,
1247,
8,
11270,
304,
272,
1834,
63,
493,
63,
1247,
275,
942,
272,
1305,
63,
475,
63,
2996,
275,
1052,
272,
4280,
275,
378,
272,
1834,
63
] |
[
7026,
492,
302,
23335,
199,
504,
5055,
492,
14427,
199,
504,
6170,
14,
10929,
784,
386,
492,
812,
2721,
1167,
199,
504,
6170,
14,
1208,
492,
627,
199,
199,
646,
3228,
465,
2833,
199,
646,
2680,
465,
980,
199,
646,
10634,
465,
6454,
199,
646,
394,
2000,
274,
199,
646,
747,
199,
646,
2022,
421,
199,
318,
485,
1412,
63,
13410,
63,
576,
8,
13410,
63,
493,
12,
1834,
63,
694,
12,
1390,
63,
1267,
304,
272,
543,
1551,
8,
13410,
63,
493,
9,
465,
289,
26,
267,
19038,
63,
576,
275,
2022,
14,
912,
8,
70,
9,
339,
327,
1305,
63,
475,
63,
1501,
365,
282,
2600,
4066,
465,
469,
1569,
63,
344,
26,
1788,
9420,
5591,
1305,
63,
475,
63,
1501,
275,
469,
1569,
459,
344,
2565,
1834,
459,
493,
63,
354,
418,
367,
1834,
315,
19038,
63,
576,
459,
4782,
12074,
339,
327,
666,
365,
282,
769,
402,
2600,
1314,
3509,
283,
2874,
852,
297,
283,
493,
63,
354,
7,
436,
283,
1569,
63,
344,
7,
465,
790,
14,
272,
666,
275,
942,
272,
367,
11262,
315,
19038,
63,
576,
459,
11270,
2565,
267,
1834,
63,
344,
275,
11262,
459,
1569,
63,
344,
418,
267,
11262,
459,
493,
63,
354,
418,
275,
747,
14,
515,
14,
904,
8,
1569,
63,
694,
12,
1305,
63,
475,
63,
1501,
59,
1569,
63,
344,
566,
267,
666,
847,
359,
9340,
61,
2286,
327,
3957,
370,
10634,
27168,
334,
509,
2945,
13104,
2072,
503,
10201,
9,
272,
19038,
63,
576,
275,
6454,
14,
9205,
14,
504,
63,
807,
8,
576,
9,
272,
2150,
19038,
63,
576,
459,
344,
418,
272,
19038,
63,
576,
14,
3191,
63,
1459,
8,
991,
534,
1569,
63,
344,
297,
16304,
29,
549,
9,
272,
19038,
63,
576,
275,
19038,
63,
576,
14,
3958,
63,
1080,
8,
4824,
29,
549,
9,
2286,
2150,
63,
2996,
275,
942,
272,
367,
284,
12,
19038,
315,
3874,
8,
13410,
63,
576,
459,
13410,
9090,
267,
19038,
275,
19038,
14,
1814,
5175,
26516,
1814,
5102,
26516,
1814,
27769,
341,
680,
1814,
14088,
20944,
267,
19038,
275,
19038,
14,
1814,
20040,
1673,
460,
1959,
1814,
14097,
26516,
1814,
480,
4186,
341,
680,
1814,
3654,
1673,
5320,
267,
19038,
275,
298,
3680,
904,
8,
13410,
14,
1294,
1012,
221,
327,
3350,
3663,
7883,
2728,
19038,
63,
576,
14,
409,
63,
585,
8,
73,
12,
283,
13410,
297,
19038,
14,
2325,
1012,
267,
340,
822,
8,
13410,
14,
1294,
480,
26725,
690,
1390,
63,
1267,
26,
288,
2150,
63,
2996,
14,
740,
8,
73,
9,
2286,
327,
3145,
4021,
852,
340,
1568,
365,
12142,
2419,
1390,
63,
1267,
272,
870,
298,
1918,
1329,
402,
4021,
852,
2544,
14068,
26,
450,
68,
2,
450,
552,
8,
13410,
63,
576,
9,
272,
19038,
63,
576,
275,
19038,
63,
576,
14,
4824,
8,
13410,
63,
576,
14,
1080,
59,
2264,
63,
2996,
566,
272,
19038,
63,
576,
275,
19038,
63,
576,
14,
3958,
63,
1080,
8,
4824,
29,
549,
9,
272,
870,
298,
1918,
1329,
402,
4021,
852,
2410,
14068,
26,
450,
68,
2,
450,
552,
8,
13410,
63,
576,
9,
272,
372,
19038,
63,
576,
421,
199,
318,
485,
1506,
63,
9953,
8,
11270,
12,
8765,
29,
17,
304,
272,
7055,
275,
14427,
342,
272,
1390,
63,
552,
275,
378,
272,
367,
284,
12,
19038,
315,
3874,
8,
11270,
459,
13410,
9090,
267,
5932,
275,
19038,
14,
1294,
360,
5320,
327,
19038,
406,
2834,
83,
1454,
5117,
13,
2546,
5932,
267,
367,
336,
315,
5932,
26,
288,
7055,
59,
87,
61,
847,
17,
2728,
340,
822,
8,
13410,
14,
1294,
480,
26725,
690,
1390,
63,
552,
26,
288,
1390,
63,
552,
275,
822,
8,
13410,
14,
1294,
480,
26725,
339,
11181,
275,
359,
1027,
367,
4349,
315,
7055,
340,
7055,
59,
1027,
61,
2356,
8765,
61,
272,
870,
661,
13079,
3014,
450,
68,
5932,
370,
450,
68,
5932,
543,
4349,
2338,
8765,
450,
68,
3530,
450,
334,
552,
8,
5337,
395,
822,
8,
9953,
395,
8765,
430,
339,
4349,
63,
475,
63,
2996,
275,
469,
85,
7601,
8084,
30838,
378,
12,
399,
7601,
7363,
30838,
413,
12,
399,
7601,
3902,
30838,
499,
93,
272,
4280,
275,
650,
272,
367,
4349,
315,
11181,
26,
267,
4349,
63,
475,
63,
2996,
59,
1027,
61,
275,
4280,
267,
4280,
847,
413,
272,
870,
298,
4261,
2582,
402,
19038,
26,
3872,
1390,
63,
552,
272,
372,
4349,
63,
475,
63,
2996,
421,
199,
318,
485,
1506,
63,
13410,
63,
4106,
8,
11270,
12,
4349,
63,
475,
63,
2996,
12,
1390,
63,
1267,
29,
1046,
304,
272,
302,
63,
8589,
275,
822,
8,
11270,
9,
272,
4021,
852,
275,
980,
14,
8237,
1332,
78,
63,
8589,
12,
988,
63,
1267,
11,
18,
4992,
6041,
8,
1590,
14,
442,
708,
9,
259,
339,
367,
284,
12,
19038,
315,
3874,
8,
11270,
459,
13410,
9090,
267,
5932,
275,
19038,
14,
1294,
480,
6099,
327,
19038,
406,
2834,
83,
1454,
5117,
13,
2546,
5932,
267,
4021,
63,
6046,
275,
942,
267,
4021,
63,
6046,
14,
740,
8,
1027,
63,
475,
63,
2996,
459,
28,
7363,
24782,
267,
367,
4349,
315,
5932,
26,
288,
340,
4349,
315,
4349,
63,
475,
63,
2996,
26,
355,
4021,
63,
6046,
14,
740,
8,
1027,
63,
475,
63,
2996,
59,
1027,
566,
267,
4021,
63,
6046,
14,
740,
8,
1027,
63,
475,
63,
2996,
459,
28,
3902,
24782,
2728,
327,
6567,
3974,
19038,
543,
314,
4539,
2973,
1526,
2650,
8084,
3524,
370,
1852,
652,
6317,
13,
890,
5477,
267,
340,
822,
8,
2874,
63,
6046,
9,
665,
334,
988,
63,
1267,
435,
499,
304,
288,
367,
1335,
315,
1425,
8,
988,
63,
1267,
435,
499,
446,
822,
8,
2874,
63,
6046,
2298,
355,
4021,
63,
6046,
14,
740,
8,
1027,
63,
475,
63,
2996,
459,
28,
8084,
24782,
221,
2728,
4021,
852,
59,
73,
12,
12228,
275,
980,
14,
8748,
8,
2874,
63,
6046,
9,
272,
870,
298,
13430,
10015,
19038,
11102,
2,
272,
372,
4021,
852,
421,
199,
318,
485,
1506,
63,
493,
63,
1247,
8,
11270,
304,
272,
1834,
63,
493,
63,
1247,
275,
942,
272,
1305,
63,
475,
63,
2996,
275,
1052,
272,
4280,
275,
378,
272,
1834,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
patrickhartling/maestro
|
maestro/gui/plugins/views/stanza_editor/optioneditors/OverrideEditorBase.py
|
2
|
4289
|
# Maestro is Copyright (C) 2006-2008 by Infiscape Corporation
#
# Original Author: Aron Bierbaum
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'maestro/gui/plugins/views/stanza_editor/optioneditors/OverrideEditorBase.ui'
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_OverrideEditorBase(object):
def setupUi(self, OverrideEditorBase):
OverrideEditorBase.setObjectName("OverrideEditorBase")
OverrideEditorBase.resize(QtCore.QSize(QtCore.QRect(0,0,330,143).size()).expandedTo(OverrideEditorBase.minimumSizeHint()))
self.gridlayout = QtGui.QGridLayout(OverrideEditorBase)
self.gridlayout.setMargin(9)
self.gridlayout.setSpacing(6)
self.gridlayout.setObjectName("gridlayout")
self.mOverrideLbl = QtGui.QLabel(OverrideEditorBase)
self.mOverrideLbl.setObjectName("mOverrideLbl")
self.gridlayout.addWidget(self.mOverrideLbl,0,2,1,1)
self.mPathLbl = QtGui.QLabel(OverrideEditorBase)
self.mPathLbl.setObjectName("mPathLbl")
self.gridlayout.addWidget(self.mPathLbl,0,0,1,1)
self.mMatchesList = QtGui.QListWidget(OverrideEditorBase)
self.mMatchesList.setObjectName("mMatchesList")
self.gridlayout.addWidget(self.mMatchesList,1,0,1,2)
self.mRemoveBtn = QtGui.QToolButton(OverrideEditorBase)
self.mRemoveBtn.setIcon(QtGui.QIcon(":/Maestro/images/edit_remove.png"))
self.mRemoveBtn.setObjectName("mRemoveBtn")
self.gridlayout.addWidget(self.mRemoveBtn,0,4,1,1)
self.mAddBtn = QtGui.QToolButton(OverrideEditorBase)
self.mAddBtn.setIcon(QtGui.QIcon(":/Maestro/images/edit_add.png"))
self.mAddBtn.setObjectName("mAddBtn")
self.gridlayout.addWidget(self.mAddBtn,0,3,1,1)
self.mPathCB = QtGui.QComboBox(OverrideEditorBase)
self.mPathCB.setEnabled(True)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Policy(7),QtGui.QSizePolicy.Policy(0))
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.mPathCB.sizePolicy().hasHeightForWidth())
self.mPathCB.setSizePolicy(sizePolicy)
self.mPathCB.setEditable(True)
self.mPathCB.setObjectName("mPathCB")
self.gridlayout.addWidget(self.mPathCB,0,1,1,1)
self.mOverrideTableView = QtGui.QTableView(OverrideEditorBase)
self.mOverrideTableView.setObjectName("mOverrideTableView")
self.gridlayout.addWidget(self.mOverrideTableView,1,2,1,3)
self.retranslateUi(OverrideEditorBase)
QtCore.QMetaObject.connectSlotsByName(OverrideEditorBase)
def retranslateUi(self, OverrideEditorBase):
OverrideEditorBase.setWindowTitle(QtGui.QApplication.translate("OverrideEditorBase", "Override Editor", None, QtGui.QApplication.UnicodeUTF8))
self.mOverrideLbl.setText(QtGui.QApplication.translate("OverrideEditorBase", "Overrides:", None, QtGui.QApplication.UnicodeUTF8))
self.mPathLbl.setText(QtGui.QApplication.translate("OverrideEditorBase", "Path:", None, QtGui.QApplication.UnicodeUTF8))
self.mRemoveBtn.setText(QtGui.QApplication.translate("OverrideEditorBase", "...", None, QtGui.QApplication.UnicodeUTF8))
self.mAddBtn.setText(QtGui.QApplication.translate("OverrideEditorBase", "...", None, QtGui.QApplication.UnicodeUTF8))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
OverrideEditorBase = QtGui.QWidget()
ui = Ui_OverrideEditorBase()
ui.setupUi(OverrideEditorBase)
OverrideEditorBase.show()
sys.exit(app.exec_())
|
gpl-2.0
|
[
3,
16593,
597,
293,
365,
1898,
334,
35,
9,
8315,
13,
9300,
701,
1010,
329,
3588,
11098,
199,
3,
199,
3,
12769,
6529,
26,
1952,
265,
699,
4446,
2470,
453,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
8204,
4514,
4046,
687,
7664,
8574,
570,
283,
391,
597,
293,
15,
5885,
15,
5265,
15,
4196,
15,
29455,
63,
7515,
15,
1422,
3773,
1384,
15,
11954,
10423,
1563,
14,
1907,
7,
199,
3,
199,
3,
14750,
1,
2900,
4493,
6326,
315,
642,
570,
911,
506,
14669,
1,
199,
199,
504,
14084,
20,
492,
10565,
12,
5928,
199,
199,
533,
32471,
63,
11954,
10423,
1563,
8,
785,
304,
2043,
347,
3272,
18203,
8,
277,
12,
11041,
10423,
1563,
304,
489,
11041,
10423,
1563,
14,
10376,
480,
11954,
10423,
1563,
531,
489,
11041,
10423,
1563,
14,
8709,
8,
10901,
14,
15531,
8,
10901,
14,
30197,
8,
16,
12,
16,
12,
14137,
12,
12289,
680,
890,
8801,
15645,
1378,
8,
11954,
10423,
1563,
14,
10700,
2320,
20891,
4059,
2541,
291,
14,
3825,
4209,
275,
5928,
14,
49,
7900,
4798,
8,
11954,
10423,
1563,
9,
489,
291,
14,
3825,
4209,
14,
409,
15182,
8,
25,
9,
489,
291,
14,
3825,
4209,
14,
409,
24052,
8,
22,
9,
489,
291,
14,
3825,
4209,
14,
10376,
480,
3825,
4209,
531,
2541,
291,
14,
77,
11954,
44,
3345,
275,
5928,
14,
19890,
8,
11954,
10423,
1563,
9,
489,
291,
14,
77,
11954,
44,
3345,
14,
10376,
480,
77,
11954,
44,
3345,
531,
489,
291,
14,
3825,
4209,
14,
9475,
8,
277,
14,
77,
11954,
44,
3345,
12,
16,
12,
18,
12,
17,
12,
17,
9,
2541,
291,
14,
77,
2042,
44,
3345,
275,
5928,
14,
19890,
8,
11954,
10423,
1563,
9,
489,
291,
14,
77,
2042,
44,
3345,
14,
10376,
480,
77,
2042,
44,
3345,
531,
489,
291,
14,
3825,
4209,
14,
9475,
8,
277,
14,
77,
2042,
44,
3345,
12,
16,
12,
16,
12,
17,
12,
17,
9,
2541,
291,
14,
77,
12962,
1296,
275,
5928,
14,
49,
1296,
3339,
8,
11954,
10423,
1563,
9,
489,
291,
14,
77,
12962,
1296,
14,
10376,
480,
77,
12962,
1296,
531,
489,
291,
14,
3825,
4209,
14,
9475,
8,
277,
14,
77,
12962,
1296,
12,
17,
12,
16,
12,
17,
12,
18,
9,
2541,
291,
14,
77,
5587,
22552,
275,
5928,
14,
49,
5157,
4259,
8,
11954,
10423,
1563,
9,
489,
291,
14,
77,
5587,
22552,
14,
27668,
8,
10604,
14,
26196,
480,
11254,
11903,
597,
293,
15,
4782,
15,
3773,
63,
2168,
14,
4524,
2237,
489,
291,
14,
77,
5587,
22552,
14,
10376,
480,
77,
5587,
22552,
531,
489,
291,
14,
3825,
4209,
14,
9475,
8,
277,
14,
77,
5587,
22552,
12,
16,
12,
20,
12,
17,
12,
17,
9,
2541,
291,
14,
77,
1123,
22552,
275,
5928,
14,
49,
5157,
4259,
8,
11954,
10423,
1563,
9,
489,
291,
14,
77,
1123,
22552,
14,
27668,
8,
10604,
14,
26196,
480,
11254,
11903,
597,
293,
15,
4782,
15,
3773,
63,
525,
14,
4524,
2237,
489,
291,
14,
77,
1123,
22552,
14,
10376,
480,
77,
1123,
22552,
531,
489,
291,
14,
3825,
4209,
14,
9475,
8,
277,
14,
77,
1123,
22552,
12,
16,
12,
19,
12,
17,
12,
17,
9,
2541,
291,
14,
77,
2042,
9956,
275,
5928,
14,
49,
17491,
8,
11954,
10423,
1563,
9,
489,
291,
14,
77,
2042,
9956,
14,
14329,
8,
549,
9,
2541,
22789,
275,
5928,
14,
19934,
8,
10604,
14,
19934,
14,
4845,
8,
23,
395,
10604,
14,
19934,
14,
4845,
8,
16,
430,
489,
22789,
14,
409,
19918,
21537,
8,
16,
9,
489,
22789,
14,
409,
19462,
21537,
8,
16,
9,
489,
22789,
14,
409,
8436,
1858,
6216,
8,
277,
14,
77,
2042,
9956,
14,
890,
4845,
1252,
1989,
8436,
1858,
6216,
1012,
489,
291,
14,
77,
2042,
9956,
14,
21735,
4845,
8,
890,
4845,
9,
489,
291,
14,
77,
2042,
9956,
14,
409,
20957,
1224,
8,
549,
9,
489,
291,
14,
77,
2042,
9956,
14,
10376,
480,
77,
2042,
9956,
531,
489,
291,
14,
3825,
4209,
14,
9475,
8,
277,
14,
77,
2042,
9956,
12,
16,
12,
17,
12,
17,
12,
17,
9,
2541,
291,
14,
77,
11954,
3186,
2768,
275,
5928,
14,
49,
3186,
2768,
8,
11954,
10423,
1563,
9,
489,
291,
14,
77,
11954,
3186,
2768,
14,
10376,
480,
77,
11954,
3186,
2768,
531,
489,
291,
14,
3825,
4209,
14,
9475,
8,
277,
14,
77,
11954,
3186,
2768,
12,
17,
12,
18,
12,
17,
12,
19,
9,
2541,
291,
14,
264,
5275,
18203,
8,
11954,
10423,
1563,
9,
489,
10565,
14,
49,
3396,
1692,
14,
2242,
26492,
11190,
8,
11954,
10423,
1563,
9,
8410,
347,
295,
5275,
18203,
8,
277,
12,
11041,
10423,
1563,
304,
489,
11041,
10423,
1563,
14,
30601,
8,
10604,
14,
12757,
14,
5275,
480,
11954,
10423,
1563,
401,
298,
11954,
30318,
401,
488,
12,
5928,
14,
12757,
14,
21865,
24,
430,
489,
291,
14,
77,
11954,
44,
3345,
14,
8341,
8,
10604,
14,
12757,
14,
5275,
480,
11954,
10423,
1563,
401,
298,
27586,
6783,
488,
12,
5928,
14,
12757,
14,
21865,
24,
430,
489,
291,
14,
77,
2042,
44,
3345,
14,
8341,
8,
10604,
14,
12757,
14,
5275,
480,
11954,
10423
] |
[
16593,
597,
293,
365,
1898,
334,
35,
9,
8315,
13,
9300,
701,
1010,
329,
3588,
11098,
199,
3,
199,
3,
12769,
6529,
26,
1952,
265,
699,
4446,
2470,
453,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
8204,
4514,
4046,
687,
7664,
8574,
570,
283,
391,
597,
293,
15,
5885,
15,
5265,
15,
4196,
15,
29455,
63,
7515,
15,
1422,
3773,
1384,
15,
11954,
10423,
1563,
14,
1907,
7,
199,
3,
199,
3,
14750,
1,
2900,
4493,
6326,
315,
642,
570,
911,
506,
14669,
1,
199,
199,
504,
14084,
20,
492,
10565,
12,
5928,
199,
199,
533,
32471,
63,
11954,
10423,
1563,
8,
785,
304,
2043,
347,
3272,
18203,
8,
277,
12,
11041,
10423,
1563,
304,
489,
11041,
10423,
1563,
14,
10376,
480,
11954,
10423,
1563,
531,
489,
11041,
10423,
1563,
14,
8709,
8,
10901,
14,
15531,
8,
10901,
14,
30197,
8,
16,
12,
16,
12,
14137,
12,
12289,
680,
890,
8801,
15645,
1378,
8,
11954,
10423,
1563,
14,
10700,
2320,
20891,
4059,
2541,
291,
14,
3825,
4209,
275,
5928,
14,
49,
7900,
4798,
8,
11954,
10423,
1563,
9,
489,
291,
14,
3825,
4209,
14,
409,
15182,
8,
25,
9,
489,
291,
14,
3825,
4209,
14,
409,
24052,
8,
22,
9,
489,
291,
14,
3825,
4209,
14,
10376,
480,
3825,
4209,
531,
2541,
291,
14,
77,
11954,
44,
3345,
275,
5928,
14,
19890,
8,
11954,
10423,
1563,
9,
489,
291,
14,
77,
11954,
44,
3345,
14,
10376,
480,
77,
11954,
44,
3345,
531,
489,
291,
14,
3825,
4209,
14,
9475,
8,
277,
14,
77,
11954,
44,
3345,
12,
16,
12,
18,
12,
17,
12,
17,
9,
2541,
291,
14,
77,
2042,
44,
3345,
275,
5928,
14,
19890,
8,
11954,
10423,
1563,
9,
489,
291,
14,
77,
2042,
44,
3345,
14,
10376,
480,
77,
2042,
44,
3345,
531,
489,
291,
14,
3825,
4209,
14,
9475,
8,
277,
14,
77,
2042,
44,
3345,
12,
16,
12,
16,
12,
17,
12,
17,
9,
2541,
291,
14,
77,
12962,
1296,
275,
5928,
14,
49,
1296,
3339,
8,
11954,
10423,
1563,
9,
489,
291,
14,
77,
12962,
1296,
14,
10376,
480,
77,
12962,
1296,
531,
489,
291,
14,
3825,
4209,
14,
9475,
8,
277,
14,
77,
12962,
1296,
12,
17,
12,
16,
12,
17,
12,
18,
9,
2541,
291,
14,
77,
5587,
22552,
275,
5928,
14,
49,
5157,
4259,
8,
11954,
10423,
1563,
9,
489,
291,
14,
77,
5587,
22552,
14,
27668,
8,
10604,
14,
26196,
480,
11254,
11903,
597,
293,
15,
4782,
15,
3773,
63,
2168,
14,
4524,
2237,
489,
291,
14,
77,
5587,
22552,
14,
10376,
480,
77,
5587,
22552,
531,
489,
291,
14,
3825,
4209,
14,
9475,
8,
277,
14,
77,
5587,
22552,
12,
16,
12,
20,
12,
17,
12,
17,
9,
2541,
291,
14,
77,
1123,
22552,
275,
5928,
14,
49,
5157,
4259,
8,
11954,
10423,
1563,
9,
489,
291,
14,
77,
1123,
22552,
14,
27668,
8,
10604,
14,
26196,
480,
11254,
11903,
597,
293,
15,
4782,
15,
3773,
63,
525,
14,
4524,
2237,
489,
291,
14,
77,
1123,
22552,
14,
10376,
480,
77,
1123,
22552,
531,
489,
291,
14,
3825,
4209,
14,
9475,
8,
277,
14,
77,
1123,
22552,
12,
16,
12,
19,
12,
17,
12,
17,
9,
2541,
291,
14,
77,
2042,
9956,
275,
5928,
14,
49,
17491,
8,
11954,
10423,
1563,
9,
489,
291,
14,
77,
2042,
9956,
14,
14329,
8,
549,
9,
2541,
22789,
275,
5928,
14,
19934,
8,
10604,
14,
19934,
14,
4845,
8,
23,
395,
10604,
14,
19934,
14,
4845,
8,
16,
430,
489,
22789,
14,
409,
19918,
21537,
8,
16,
9,
489,
22789,
14,
409,
19462,
21537,
8,
16,
9,
489,
22789,
14,
409,
8436,
1858,
6216,
8,
277,
14,
77,
2042,
9956,
14,
890,
4845,
1252,
1989,
8436,
1858,
6216,
1012,
489,
291,
14,
77,
2042,
9956,
14,
21735,
4845,
8,
890,
4845,
9,
489,
291,
14,
77,
2042,
9956,
14,
409,
20957,
1224,
8,
549,
9,
489,
291,
14,
77,
2042,
9956,
14,
10376,
480,
77,
2042,
9956,
531,
489,
291,
14,
3825,
4209,
14,
9475,
8,
277,
14,
77,
2042,
9956,
12,
16,
12,
17,
12,
17,
12,
17,
9,
2541,
291,
14,
77,
11954,
3186,
2768,
275,
5928,
14,
49,
3186,
2768,
8,
11954,
10423,
1563,
9,
489,
291,
14,
77,
11954,
3186,
2768,
14,
10376,
480,
77,
11954,
3186,
2768,
531,
489,
291,
14,
3825,
4209,
14,
9475,
8,
277,
14,
77,
11954,
3186,
2768,
12,
17,
12,
18,
12,
17,
12,
19,
9,
2541,
291,
14,
264,
5275,
18203,
8,
11954,
10423,
1563,
9,
489,
10565,
14,
49,
3396,
1692,
14,
2242,
26492,
11190,
8,
11954,
10423,
1563,
9,
8410,
347,
295,
5275,
18203,
8,
277,
12,
11041,
10423,
1563,
304,
489,
11041,
10423,
1563,
14,
30601,
8,
10604,
14,
12757,
14,
5275,
480,
11954,
10423,
1563,
401,
298,
11954,
30318,
401,
488,
12,
5928,
14,
12757,
14,
21865,
24,
430,
489,
291,
14,
77,
11954,
44,
3345,
14,
8341,
8,
10604,
14,
12757,
14,
5275,
480,
11954,
10423,
1563,
401,
298,
27586,
6783,
488,
12,
5928,
14,
12757,
14,
21865,
24,
430,
489,
291,
14,
77,
2042,
44,
3345,
14,
8341,
8,
10604,
14,
12757,
14,
5275,
480,
11954,
10423,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ARudiuk/mne-python
|
mne/gui/_file_traits.py
|
6
|
15746
|
"""File data sources for traits GUIs"""
# Authors: Christian Brodbeck <christianbrodbeck@nyu.edu>
#
# License: BSD (3-clause)
import os
import numpy as np
from ..externals.six.moves import map
# allow import without traits
try:
from traits.api import (Any, HasTraits, HasPrivateTraits, cached_property,
on_trait_change, Array, Bool, Button, DelegatesTo,
Directory, Enum, Event, File, Instance, Int, List,
Property, Str)
from traitsui.api import View, Item, VGroup
from pyface.api import (DirectoryDialog, OK, ProgressDialog, error,
information)
except Exception:
from ..utils import trait_wraith
HasTraits = HasPrivateTraits = object
cached_property = on_trait_change = Any = Array = Bool = Button = \
DelegatesTo = Directory = Enum = Event = File = Instance = \
Int = List = Property = Str = View = Item = VGroup = trait_wraith
from ..io.constants import FIFF
from ..io import read_info, read_fiducials
from ..surface import read_bem_surfaces
from ..coreg import (_is_mri_subject, _mri_subject_has_bem,
create_default_subject)
from ..utils import get_config, set_config
fid_wildcard = "*.fif"
trans_wildcard = "*.fif"
# for wx backend:
# fid_wildcard = "Fiducials FIFF file (*.fif)|*.fif"
# trans_wildcard = "Trans File (*.fif)|*.fif"
def _expand_path(p):
return os.path.abspath(os.path.expandvars(os.path.expanduser(p)))
def get_fs_home():
"""Get the FREESURFER_HOME directory
Returns
-------
fs_home : None | str
The FREESURFER_HOME path or None if the user cancels.
Notes
-----
If FREESURFER_HOME can't be found, the user is prompted with a file dialog.
If specified successfully, the resulting path is stored with
mne.set_config().
"""
return _get_root_home('FREESURFER_HOME', 'freesurfer', _fs_home_problem)
def get_mne_root():
"""Get the MNE_ROOT directory
Returns
-------
mne_root : None | str
The MNE_ROOT path or None if the user cancels.
Notes
-----
If MNE_ROOT can't be found, the user is prompted with a file dialog.
If specified successfully, the resulting path is stored with
mne.set_config().
"""
return _get_root_home('MNE_ROOT', 'MNE', _mne_root_problem)
def _get_root_home(cfg, name, check_fun):
root = get_config(cfg)
problem = check_fun(root)
while problem:
info = ("Please select the %s directory. This is the root "
"directory of the %s installation." % (cfg, name))
msg = '\n\n'.join((problem, info))
information(None, msg, "Select the %s Directory" % cfg)
msg = "Please select the %s Directory" % cfg
dlg = DirectoryDialog(message=msg, new_directory=False)
if dlg.open() == OK:
root = dlg.path
problem = check_fun(root)
if problem is None:
set_config(cfg, root)
else:
return None
return root
def set_fs_home():
"""Set the FREESURFER_HOME environment variable
Returns
-------
success : bool
True if the environment variable could be set, False if FREESURFER_HOME
could not be found.
Notes
-----
If FREESURFER_HOME can't be found, the user is prompted with a file dialog.
If specified successfully, the resulting path is stored with
mne.set_config().
"""
fs_home = get_fs_home()
if fs_home is None:
return False
else:
os.environ['FREESURFER_HOME'] = fs_home
return True
def _fs_home_problem(fs_home):
"""Check FREESURFER_HOME path
Return str describing problem or None if the path is okay.
"""
if fs_home is None:
return "FREESURFER_HOME is not set."
elif not os.path.exists(fs_home):
return "FREESURFER_HOME (%s) does not exist." % fs_home
else:
test_dir = os.path.join(fs_home, 'subjects', 'fsaverage')
if not os.path.exists(test_dir):
return ("FREESURFER_HOME (%s) does not contain the fsaverage "
"subject." % fs_home)
def set_mne_root(set_mne_bin=False):
"""Set the MNE_ROOT environment variable
Parameters
----------
set_mne_bin : bool
Also add the MNE binary directory to the PATH (default: False).
Returns
-------
success : bool
True if the environment variable could be set, False if MNE_ROOT
could not be found.
Notes
-----
If MNE_ROOT can't be found, the user is prompted with a file dialog.
If specified successfully, the resulting path is stored with
mne.set_config().
"""
mne_root = get_mne_root()
if mne_root is None:
return False
else:
os.environ['MNE_ROOT'] = mne_root
if set_mne_bin:
mne_bin = os.path.realpath(os.path.join(mne_root, 'bin'))
if mne_bin not in map(_expand_path, os.environ['PATH'].split(':')):
os.environ['PATH'] += ':' + mne_bin
return True
def _mne_root_problem(mne_root):
"""Check MNE_ROOT path
Return str describing problem or None if the path is okay.
"""
if mne_root is None:
return "MNE_ROOT is not set."
elif not os.path.exists(mne_root):
return "MNE_ROOT (%s) does not exist." % mne_root
else:
test_dir = os.path.join(mne_root, 'share', 'mne', 'mne_analyze')
if not os.path.exists(test_dir):
return ("MNE_ROOT (%s) is missing files. If this is your MNE "
"installation, consider reinstalling." % mne_root)
class BemSource(HasTraits):
"""Expose points and tris of a given BEM file
Parameters
----------
file : File
Path to the BEM file (*.fif).
Attributes
----------
pts : Array, shape = (n_pts, 3)
BEM file points.
tri : Array, shape = (n_tri, 3)
BEM file triangles.
Notes
-----
tri is always updated after pts, so in case downstream objects depend on
both, they should sync to a change in tri.
"""
file = File(exists=True, filter=['*.fif'])
points = Array(shape=(None, 3), value=np.empty((0, 3)))
norms = Array
tris = Array(shape=(None, 3), value=np.empty((0, 3)))
@on_trait_change('file')
def read_file(self):
if os.path.exists(self.file):
bem = read_bem_surfaces(self.file)[0]
self.points = bem['rr']
self.norms = bem['nn']
self.tris = bem['tris']
else:
self.points = np.empty((0, 3))
self.norms = np.empty((0, 3))
self.tris = np.empty((0, 3))
class FiducialsSource(HasTraits):
"""Expose points of a given fiducials fif file
Parameters
----------
file : File
Path to a fif file with fiducials (*.fif).
Attributes
----------
points : Array, shape = (n_points, 3)
Fiducials file points.
"""
file = File(filter=[fid_wildcard])
fname = Property(depends_on='file')
points = Property(depends_on='file')
@cached_property
def _get_fname(self):
fname = os.path.basename(self.file)
return fname
@cached_property
def _get_points(self):
if not os.path.exists(self.file):
return None
points = np.zeros((3, 3))
fids, _ = read_fiducials(self.file)
for fid in fids:
ident = fid['ident']
if ident == FIFF.FIFFV_POINT_LPA:
points[0] = fid['r']
elif ident == FIFF.FIFFV_POINT_NASION:
points[1] = fid['r']
elif ident == FIFF.FIFFV_POINT_RPA:
points[2] = fid['r']
return points
class InstSource(HasPrivateTraits):
"""Expose measurement information from a inst file
Parameters
----------
file : File
Path to the BEM file (*.fif).
Attributes
----------
fid : Array, shape = (3, 3)
Each row contains the coordinates for one fiducial point, in the order
Nasion, RAP, LAP. If no file is set all values are 0.
"""
file = File(exists=True, filter=['*.fif'])
inst_fname = Property(Str, depends_on='file')
inst_dir = Property(depends_on='file')
inst = Property(depends_on='file')
points_filter = Any(desc="Index to select a subset of the head shape "
"points")
n_omitted = Property(Int, depends_on=['points_filter'])
# head shape
inst_points = Property(depends_on='inst', desc="Head shape points in the "
"inst file(n x 3 array)")
points = Property(depends_on=['inst_points', 'points_filter'], desc="Head "
"shape points selected by the filter (n x 3 array)")
# fiducials
fid_dig = Property(depends_on='inst', desc="Fiducial points "
"(list of dict)")
fid_points = Property(depends_on='fid_dig', desc="Fiducial points {ident: "
"point} dict}")
lpa = Property(depends_on='fid_points', desc="LPA coordinates (1 x 3 "
"array)")
nasion = Property(depends_on='fid_points', desc="Nasion coordinates (1 x "
"3 array)")
rpa = Property(depends_on='fid_points', desc="RPA coordinates (1 x 3 "
"array)")
view = View(VGroup(Item('file'),
Item('inst_fname', show_label=False, style='readonly')))
@cached_property
def _get_n_omitted(self):
if self.points_filter is None:
return 0
else:
return np.sum(self.points_filter == False) # noqa
@cached_property
def _get_inst(self):
if self.file:
return read_info(self.file)
@cached_property
def _get_inst_dir(self):
return os.path.dirname(self.file)
@cached_property
def _get_inst_fname(self):
if self.file:
return os.path.basename(self.file)
else:
return '-'
@cached_property
def _get_inst_points(self):
if not self.inst:
return np.zeros((1, 3))
points = np.array([d['r'] for d in self.inst['dig']
if d['kind'] == FIFF.FIFFV_POINT_EXTRA])
return points
@cached_property
def _get_points(self):
if self.points_filter is None:
return self.inst_points
else:
return self.inst_points[self.points_filter]
@cached_property
def _get_fid_dig(self):
"""Fiducials for info['dig']"""
if not self.inst:
return []
dig = self.inst['dig']
dig = [d for d in dig if d['kind'] == FIFF.FIFFV_POINT_CARDINAL]
return dig
@cached_property
def _get_fid_points(self):
if not self.inst:
return {}
digs = dict((d['ident'], d) for d in self.fid_dig)
return digs
@cached_property
def _get_nasion(self):
if self.fid_points:
return self.fid_points[FIFF.FIFFV_POINT_NASION]['r'][None, :]
else:
return np.zeros((1, 3))
@cached_property
def _get_lpa(self):
if self.fid_points:
return self.fid_points[FIFF.FIFFV_POINT_LPA]['r'][None, :]
else:
return np.zeros((1, 3))
@cached_property
def _get_rpa(self):
if self.fid_points:
return self.fid_points[FIFF.FIFFV_POINT_RPA]['r'][None, :]
else:
return np.zeros((1, 3))
def _file_changed(self):
self.reset_traits(('points_filter',))
class MRISubjectSource(HasPrivateTraits):
"""Find subjects in SUBJECTS_DIR and select one
Parameters
----------
subjects_dir : directory
SUBJECTS_DIR.
subject : str
Subject, corresponding to a folder in SUBJECTS_DIR.
"""
refresh = Event(desc="Refresh the subject list based on the directory "
"structure of subjects_dir.")
# settings
subjects_dir = Directory(exists=True)
subjects = Property(List(Str), depends_on=['subjects_dir', 'refresh'])
subject = Enum(values='subjects')
# info
can_create_fsaverage = Property(Bool, depends_on=['subjects_dir',
'subjects'])
subject_has_bem = Property(Bool, depends_on=['subjects_dir', 'subject'],
desc="whether the subject has a file matching "
"the bem file name pattern")
bem_pattern = Property(depends_on='mri_dir')
@cached_property
def _get_can_create_fsaverage(self):
if not os.path.exists(self.subjects_dir):
return False
if 'fsaverage' in self.subjects:
return False
return True
@cached_property
def _get_mri_dir(self):
if not self.subject:
return
elif not self.subjects_dir:
return
else:
return os.path.join(self.subjects_dir, self.subject)
@cached_property
def _get_subjects(self):
sdir = self.subjects_dir
is_dir = sdir and os.path.isdir(sdir)
if is_dir:
dir_content = os.listdir(sdir)
subjects = [s for s in dir_content if _is_mri_subject(s, sdir)]
if len(subjects) == 0:
subjects.append('')
else:
subjects = ['']
return subjects
@cached_property
def _get_subject_has_bem(self):
if not self.subject:
return False
return _mri_subject_has_bem(self.subject, self.subjects_dir)
def create_fsaverage(self):
if not self.subjects_dir:
err = ("No subjects directory is selected. Please specify "
"subjects_dir first.")
raise RuntimeError(err)
mne_root = get_mne_root()
if mne_root is None:
err = ("MNE contains files that are needed for copying the "
"fsaverage brain. Please install MNE and try again.")
raise RuntimeError(err)
fs_home = get_fs_home()
if fs_home is None:
err = ("FreeSurfer contains files that are needed for copying the "
"fsaverage brain. Please install FreeSurfer and try again.")
raise RuntimeError(err)
create_default_subject(mne_root, fs_home,
subjects_dir=self.subjects_dir)
self.refresh = True
self.subject = 'fsaverage'
class SubjectSelectorPanel(HasPrivateTraits):
model = Instance(MRISubjectSource)
can_create_fsaverage = DelegatesTo('model')
subjects_dir = DelegatesTo('model')
subject = DelegatesTo('model')
subjects = DelegatesTo('model')
create_fsaverage = Button("Copy FsAverage to Subjects Folder",
desc="Copy the files for the fsaverage subject "
"to the subjects directory.")
view = View(VGroup(Item('subjects_dir', label='subjects_dir'),
'subject',
Item('create_fsaverage', show_label=False,
enabled_when='can_create_fsaverage')))
def _create_fsaverage_fired(self):
# progress dialog with indefinite progress bar
title = "Creating FsAverage ..."
message = "Copying fsaverage files ..."
prog = ProgressDialog(title=title, message=message)
prog.open()
prog.update(0)
try:
self.model.create_fsaverage()
except Exception as err:
msg = str(err)
error(None, msg, "Error Creating FsAverage")
raise
finally:
prog.close()
|
bsd-3-clause
|
[
624,
1173,
666,
5274,
367,
19692,
598,
53,
1831,
624,
199,
199,
3,
6642,
26,
2799,
18824,
5653,
699,
293,
31987,
346,
665,
335,
18824,
5653,
20670,
31987,
346,
32,
9745,
85,
14,
8654,
30,
199,
3,
199,
3,
844,
26,
6289,
334,
19,
13,
8501,
9,
199,
199,
646,
747,
199,
199,
646,
2680,
465,
980,
199,
504,
2508,
24688,
14,
4174,
14,
4912,
492,
2341,
199,
199,
3,
2040,
492,
1928,
19692,
199,
893,
26,
272,
687,
19692,
14,
1246,
492,
334,
9874,
12,
13481,
31116,
12,
13481,
12185,
31116,
12,
6328,
63,
1829,
12,
1169,
641,
63,
22687,
63,
1461,
12,
8725,
12,
19287,
12,
16005,
12,
1487,
4170,
2335,
1378,
12,
1169,
15191,
12,
11305,
12,
6763,
12,
3814,
12,
10066,
12,
9805,
12,
3820,
12,
1169,
16158,
12,
8303,
9,
272,
687,
19692,
1907,
14,
1246,
492,
10935,
12,
7020,
12,
812,
2448,
272,
687,
1134,
1409,
14,
1246,
492,
334,
6231,
5619,
12,
9949,
12,
21211,
5619,
12,
1125,
12,
1169,
2556,
9,
199,
2590,
2186,
26,
272,
687,
2508,
1208,
492,
30576,
63,
87,
345,
448,
272,
13481,
31116,
275,
13481,
12185,
31116,
275,
909,
272,
6328,
63,
1829,
275,
641,
63,
22687,
63,
1461,
275,
6184,
275,
8725,
275,
19287,
275,
16005,
275,
971,
267,
1487,
4170,
2335,
1378,
275,
15191,
275,
11305,
275,
6763,
275,
3814,
275,
10066,
275,
971,
267,
9805,
275,
3820,
275,
16158,
275,
8303,
275,
10935,
275,
7020,
275,
812,
2448,
275,
30576,
63,
87,
345,
448,
199,
199,
504,
2508,
2308,
14,
5559,
492,
32193,
199,
504,
2508,
2308,
492,
1586,
63,
815,
12,
1586,
63,
329,
2033,
559,
2551,
199,
504,
2508,
10992,
492,
1586,
63,
1235,
77,
63,
5105,
4309,
199,
504,
2508,
1018,
71,
492,
6110,
374,
63,
77,
322,
63,
5875,
12,
485,
77,
322,
63,
5875,
63,
1989,
63,
1235,
77,
12,
2151,
1218,
63,
885,
63,
5875,
9,
199,
504,
2508,
1208,
492,
664,
63,
888,
12,
663,
63,
888,
421,
199,
9430,
63,
16692,
275,
298,
4856,
25533,
2,
199,
1515,
63,
16692,
275,
298,
4856,
25533,
2,
199,
3,
367,
4818,
4865,
26,
199,
3,
8289,
63,
16692,
275,
298,
38,
344,
85,
559,
2551,
32193,
570,
334,
4856,
25533,
8636,
4856,
25533,
2,
199,
3,
1752,
63,
16692,
275,
298,
3188,
3814,
334,
4856,
25533,
8636,
4856,
25533,
2,
421,
199,
318,
485,
4441,
63,
515,
8,
80,
304,
272,
372,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
4441,
2936,
8,
736,
14,
515,
14,
12131,
8,
80,
1724,
421,
199,
318,
664,
63,
2319,
63,
4219,
837,
272,
408,
1002,
314,
481,
907,
654,
1230,
15849,
63,
9524,
2082,
339,
1803,
272,
5514,
272,
7449,
63,
4219,
520,
488,
1204,
620,
267,
710,
481,
907,
654,
1230,
15849,
63,
9524,
931,
503,
488,
340,
314,
922,
286,
554,
478,
14,
339,
8144,
272,
9063,
272,
982,
481,
907,
654,
1230,
15849,
63,
9524,
883,
1133,
506,
1911,
12,
314,
922,
365,
21652,
471,
543,
282,
570,
9592,
14,
272,
982,
2013,
8792,
12,
314,
9183,
931,
365,
5489,
543,
272,
18250,
14,
409,
63,
888,
1252,
272,
408,
272,
372,
485,
362,
63,
1231,
63,
4219,
360,
38,
907,
654,
1230,
15849,
63,
9524,
297,
283,
70,
5710,
300,
2412,
297,
485,
2319,
63,
4219,
63,
6462,
9,
421,
199,
318,
664,
63,
22599,
63,
1231,
837,
272,
408,
1002,
314,
603,
6388,
63,
5441,
2082,
339,
1803,
272,
5514,
272,
18250,
63,
1231,
520,
488,
1204,
620,
267,
710,
603,
6388,
63,
5441,
931,
503,
488,
340,
314,
922,
286,
554,
478,
14,
339,
8144,
272,
9063,
272,
982,
603,
6388,
63,
5441,
883,
1133,
506,
1911,
12,
314,
922,
365,
21652,
471,
543,
282,
570,
9592,
14,
272,
982,
2013,
8792,
12,
314,
9183,
931,
365,
5489,
543,
272,
18250,
14,
409,
63,
888,
1252,
272,
408,
272,
372,
485,
362,
63,
1231,
63,
4219,
360,
45,
6388,
63,
5441,
297,
283,
45,
6388,
297,
485,
22599,
63,
1231,
63,
6462,
9,
421,
199,
318,
485,
362,
63,
1231,
63,
4219,
8,
4128,
12,
536,
12,
1104,
63,
7036,
304,
272,
1738,
275,
664,
63,
888,
8,
4128,
9,
272,
5160,
275,
1104,
63,
7036,
8,
1231,
9,
272,
1830,
5160,
26,
267,
2256,
275,
1689,
8254,
3504,
314,
450,
83,
2082,
14,
961,
365,
314,
1738,
298,
355,
298,
3619,
402,
314,
450,
83,
12096,
2122,
450,
334,
4128,
12,
536,
430,
267,
1499,
275,
1557,
78,
60,
78,
1370,
904,
1332,
6462,
12,
2256,
430,
267,
2556,
8,
403,
12,
1499,
12,
298,
5446,
314,
450,
83,
15191,
2,
450,
4810,
9,
267,
1499,
275,
298,
8254,
3504,
314,
450,
83,
15191,
2,
450,
4810,
267,
19406,
275,
15191,
5619,
8,
1188,
29,
1328,
12,
892,
63,
3619,
29,
797,
9,
267,
340,
19406,
14,
1490,
342,
508,
9949,
26,
288,
1738,
275,
19406,
14,
515,
288,
5160,
275,
1104,
63,
7036,
8,
1231,
9,
288,
340,
5160,
365,
488,
26,
355,
663,
63,
888,
8,
4128,
12,
1738,
9,
267,
587,
26,
288,
372,
488,
272,
372,
1738,
421,
199,
318,
663,
63,
2319,
63,
4219,
837,
272,
408,
1084,
314,
481,
907,
654,
1230,
15849,
63,
9524,
3734,
1750,
339,
1803,
272,
5514,
272,
3182,
520,
2155,
267,
715,
340,
314,
3734,
1750,
4293,
506,
663,
12,
756,
340,
481,
907,
654,
1230,
15849,
63,
9524,
267,
4293,
440,
506,
1911,
14,
339,
8144,
272,
9063,
272,
982,
481,
907,
654,
1230,
15849,
63,
9524,
883,
1133,
506,
1911,
12,
314,
922,
365,
21652,
471,
543,
282,
570,
9592,
14,
272,
982,
2013,
8792,
12,
314,
9183,
931,
365,
5489,
543,
272,
18250,
14,
409,
63,
888,
1252,
272,
408,
272,
7449,
63,
4219,
275,
664,
63,
2319,
63,
4219,
342,
272,
340,
7449,
63,
4219,
365,
488,
26,
267,
372,
756,
272,
587,
26,
267,
747,
14,
2314,
459,
38,
907,
654,
1230,
15849,
63,
9524,
418,
275,
7449,
63,
4219,
267,
372,
715,
421,
199,
318,
485,
2319,
63,
4219,
63,
6462,
8,
2319,
63,
4219,
304,
272,
408,
1799,
481,
907,
654,
1230,
15849,
63,
9524,
931,
339
] |
[
1173,
666,
5274,
367,
19692,
598,
53,
1831,
624,
199,
199,
3,
6642,
26,
2799,
18824,
5653,
699,
293,
31987,
346,
665,
335,
18824,
5653,
20670,
31987,
346,
32,
9745,
85,
14,
8654,
30,
199,
3,
199,
3,
844,
26,
6289,
334,
19,
13,
8501,
9,
199,
199,
646,
747,
199,
199,
646,
2680,
465,
980,
199,
504,
2508,
24688,
14,
4174,
14,
4912,
492,
2341,
199,
199,
3,
2040,
492,
1928,
19692,
199,
893,
26,
272,
687,
19692,
14,
1246,
492,
334,
9874,
12,
13481,
31116,
12,
13481,
12185,
31116,
12,
6328,
63,
1829,
12,
1169,
641,
63,
22687,
63,
1461,
12,
8725,
12,
19287,
12,
16005,
12,
1487,
4170,
2335,
1378,
12,
1169,
15191,
12,
11305,
12,
6763,
12,
3814,
12,
10066,
12,
9805,
12,
3820,
12,
1169,
16158,
12,
8303,
9,
272,
687,
19692,
1907,
14,
1246,
492,
10935,
12,
7020,
12,
812,
2448,
272,
687,
1134,
1409,
14,
1246,
492,
334,
6231,
5619,
12,
9949,
12,
21211,
5619,
12,
1125,
12,
1169,
2556,
9,
199,
2590,
2186,
26,
272,
687,
2508,
1208,
492,
30576,
63,
87,
345,
448,
272,
13481,
31116,
275,
13481,
12185,
31116,
275,
909,
272,
6328,
63,
1829,
275,
641,
63,
22687,
63,
1461,
275,
6184,
275,
8725,
275,
19287,
275,
16005,
275,
971,
267,
1487,
4170,
2335,
1378,
275,
15191,
275,
11305,
275,
6763,
275,
3814,
275,
10066,
275,
971,
267,
9805,
275,
3820,
275,
16158,
275,
8303,
275,
10935,
275,
7020,
275,
812,
2448,
275,
30576,
63,
87,
345,
448,
199,
199,
504,
2508,
2308,
14,
5559,
492,
32193,
199,
504,
2508,
2308,
492,
1586,
63,
815,
12,
1586,
63,
329,
2033,
559,
2551,
199,
504,
2508,
10992,
492,
1586,
63,
1235,
77,
63,
5105,
4309,
199,
504,
2508,
1018,
71,
492,
6110,
374,
63,
77,
322,
63,
5875,
12,
485,
77,
322,
63,
5875,
63,
1989,
63,
1235,
77,
12,
2151,
1218,
63,
885,
63,
5875,
9,
199,
504,
2508,
1208,
492,
664,
63,
888,
12,
663,
63,
888,
421,
199,
9430,
63,
16692,
275,
298,
4856,
25533,
2,
199,
1515,
63,
16692,
275,
298,
4856,
25533,
2,
199,
3,
367,
4818,
4865,
26,
199,
3,
8289,
63,
16692,
275,
298,
38,
344,
85,
559,
2551,
32193,
570,
334,
4856,
25533,
8636,
4856,
25533,
2,
199,
3,
1752,
63,
16692,
275,
298,
3188,
3814,
334,
4856,
25533,
8636,
4856,
25533,
2,
421,
199,
318,
485,
4441,
63,
515,
8,
80,
304,
272,
372,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
4441,
2936,
8,
736,
14,
515,
14,
12131,
8,
80,
1724,
421,
199,
318,
664,
63,
2319,
63,
4219,
837,
272,
408,
1002,
314,
481,
907,
654,
1230,
15849,
63,
9524,
2082,
339,
1803,
272,
5514,
272,
7449,
63,
4219,
520,
488,
1204,
620,
267,
710,
481,
907,
654,
1230,
15849,
63,
9524,
931,
503,
488,
340,
314,
922,
286,
554,
478,
14,
339,
8144,
272,
9063,
272,
982,
481,
907,
654,
1230,
15849,
63,
9524,
883,
1133,
506,
1911,
12,
314,
922,
365,
21652,
471,
543,
282,
570,
9592,
14,
272,
982,
2013,
8792,
12,
314,
9183,
931,
365,
5489,
543,
272,
18250,
14,
409,
63,
888,
1252,
272,
408,
272,
372,
485,
362,
63,
1231,
63,
4219,
360,
38,
907,
654,
1230,
15849,
63,
9524,
297,
283,
70,
5710,
300,
2412,
297,
485,
2319,
63,
4219,
63,
6462,
9,
421,
199,
318,
664,
63,
22599,
63,
1231,
837,
272,
408,
1002,
314,
603,
6388,
63,
5441,
2082,
339,
1803,
272,
5514,
272,
18250,
63,
1231,
520,
488,
1204,
620,
267,
710,
603,
6388,
63,
5441,
931,
503,
488,
340,
314,
922,
286,
554,
478,
14,
339,
8144,
272,
9063,
272,
982,
603,
6388,
63,
5441,
883,
1133,
506,
1911,
12,
314,
922,
365,
21652,
471,
543,
282,
570,
9592,
14,
272,
982,
2013,
8792,
12,
314,
9183,
931,
365,
5489,
543,
272,
18250,
14,
409,
63,
888,
1252,
272,
408,
272,
372,
485,
362,
63,
1231,
63,
4219,
360,
45,
6388,
63,
5441,
297,
283,
45,
6388,
297,
485,
22599,
63,
1231,
63,
6462,
9,
421,
199,
318,
485,
362,
63,
1231,
63,
4219,
8,
4128,
12,
536,
12,
1104,
63,
7036,
304,
272,
1738,
275,
664,
63,
888,
8,
4128,
9,
272,
5160,
275,
1104,
63,
7036,
8,
1231,
9,
272,
1830,
5160,
26,
267,
2256,
275,
1689,
8254,
3504,
314,
450,
83,
2082,
14,
961,
365,
314,
1738,
298,
355,
298,
3619,
402,
314,
450,
83,
12096,
2122,
450,
334,
4128,
12,
536,
430,
267,
1499,
275,
1557,
78,
60,
78,
1370,
904,
1332,
6462,
12,
2256,
430,
267,
2556,
8,
403,
12,
1499,
12,
298,
5446,
314,
450,
83,
15191,
2,
450,
4810,
9,
267,
1499,
275,
298,
8254,
3504,
314,
450,
83,
15191,
2,
450,
4810,
267,
19406,
275,
15191,
5619,
8,
1188,
29,
1328,
12,
892,
63,
3619,
29,
797,
9,
267,
340,
19406,
14,
1490,
342,
508,
9949,
26,
288,
1738,
275,
19406,
14,
515,
288,
5160,
275,
1104,
63,
7036,
8,
1231,
9,
288,
340,
5160,
365,
488,
26,
355,
663,
63,
888,
8,
4128,
12,
1738,
9,
267,
587,
26,
288,
372,
488,
272,
372,
1738,
421,
199,
318,
663,
63,
2319,
63,
4219,
837,
272,
408,
1084,
314,
481,
907,
654,
1230,
15849,
63,
9524,
3734,
1750,
339,
1803,
272,
5514,
272,
3182,
520,
2155,
267,
715,
340,
314,
3734,
1750,
4293,
506,
663,
12,
756,
340,
481,
907,
654,
1230,
15849,
63,
9524,
267,
4293,
440,
506,
1911,
14,
339,
8144,
272,
9063,
272,
982,
481,
907,
654,
1230,
15849,
63,
9524,
883,
1133,
506,
1911,
12,
314,
922,
365,
21652,
471,
543,
282,
570,
9592,
14,
272,
982,
2013,
8792,
12,
314,
9183,
931,
365,
5489,
543,
272,
18250,
14,
409,
63,
888,
1252,
272,
408,
272,
7449,
63,
4219,
275,
664,
63,
2319,
63,
4219,
342,
272,
340,
7449,
63,
4219,
365,
488,
26,
267,
372,
756,
272,
587,
26,
267,
747,
14,
2314,
459,
38,
907,
654,
1230,
15849,
63,
9524,
418,
275,
7449,
63,
4219,
267,
372,
715,
421,
199,
318,
485,
2319,
63,
4219,
63,
6462,
8,
2319,
63,
4219,
304,
272,
408,
1799,
481,
907,
654,
1230,
15849,
63,
9524,
931,
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,
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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
] |
marcy-terui/lamvery
|
lamvery/actions/base.py
|
1
|
2145
|
# -*- coding: utf-8 -*-
from abc import ABCMeta, abstractmethod
from lamvery.config import Config
from lamvery.log import get_logger
from lamvery.clients import (
LambdaClient,
KmsClient,
EventsClient,
LogsClient,
ApiGatewayClient
)
class BaseAction:
__metaclass__ = ABCMeta
_logger = None
def __init__(self, args):
self._config = Config(args.conf_file)
self._dry_run = False
self._alias = None
if hasattr(args, 'alias'):
self._alias = args.alias
logger_name = 'lamvery'
if hasattr(args, 'dry_run'):
self._dry_run = args.dry_run
if self._dry_run:
logger_name = '(Dry run) lamvery'
self._logger = get_logger(logger_name)
@abstractmethod
def action(self):
raise NotImplementedError
def _get_client(self, cls):
return cls(
region=self._config.get_region(),
profile=self._config.get_profile(),
dry_run=self._dry_run)
def get_lambda_client(self):
return self._get_client(LambdaClient)
def get_kms_client(self):
return self._get_client(KmsClient)
def get_events_client(self):
return self._get_client(EventsClient)
def get_logs_client(self):
return self._get_client(LogsClient)
def get_apigateway_client(self):
return self._get_client(ApiGatewayClient)
def get_alias_name(self):
if self._alias is not None:
return self._alias
return self._config.get_default_alias()
def _get_diff(self, remote, local, keys):
diff = {}
for k in keys:
r = remote.get(k[0])
l = local.get(k[1])
if r == l:
diff[k[1]] = None
else:
diff[k[1]] = (r, l,)
return diff
def _print_diff(self, prefix, remote, local, keys):
diff = self._get_diff(remote, local, keys)
for k, v in diff.items():
if v is not None:
self._logger.warn(
'{p} {k}: {r} -> {l}'.format(p=prefix, k=k, r=v[0], l=v[1]))
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
13022,
492,
29565,
12,
9006,
765,
199,
504,
25917,
2588,
14,
888,
492,
4094,
199,
504,
25917,
2588,
14,
793,
492,
664,
63,
2921,
199,
504,
25917,
2588,
14,
14555,
492,
334,
272,
28650,
3041,
12,
272,
1804,
706,
3041,
12,
272,
27982,
3041,
12,
272,
3835,
458,
3041,
12,
272,
13986,
12455,
3041,
199,
9,
421,
199,
533,
3523,
3310,
26,
339,
636,
6577,
363,
275,
29565,
339,
485,
2921,
275,
488,
339,
347,
636,
826,
721,
277,
12,
1249,
304,
267,
291,
423,
888,
275,
4094,
8,
589,
14,
2190,
63,
493,
9,
267,
291,
423,
10481,
63,
1065,
275,
756,
267,
291,
423,
3620,
275,
488,
398,
340,
2688,
8,
589,
12,
283,
3620,
735,
288,
291,
423,
3620,
275,
1249,
14,
3620,
398,
2512,
63,
354,
275,
283,
17984,
2588,
7,
267,
340,
2688,
8,
589,
12,
283,
10481,
63,
1065,
735,
288,
291,
423,
10481,
63,
1065,
275,
1249,
14,
10481,
63,
1065,
288,
340,
291,
423,
10481,
63,
1065,
26,
355,
2512,
63,
354,
275,
8189,
36,
651,
1255,
9,
25917,
2588,
7,
398,
291,
423,
2921,
275,
664,
63,
2921,
8,
2921,
63,
354,
9,
339,
768,
10315,
272,
347,
1595,
8,
277,
304,
267,
746,
4279,
339,
347,
485,
362,
63,
1258,
8,
277,
12,
843,
304,
267,
372,
843,
8,
288,
4897,
29,
277,
423,
888,
14,
362,
63,
4551,
1062,
288,
4690,
29,
277,
423,
888,
14,
362,
63,
2913,
1062,
288,
9951,
63,
1065,
29,
277,
423,
10481,
63,
1065,
9,
339,
347,
664,
63,
2734,
63,
1258,
8,
277,
304,
267,
372,
291,
423,
362,
63,
1258,
8,
21350,
3041,
9,
339,
347,
664,
63,
75,
706,
63,
1258,
8,
277,
304,
267,
372,
291,
423,
362,
63,
1258,
8,
43,
706,
3041,
9,
339,
347,
664,
63,
4368,
63,
1258,
8,
277,
304,
267,
372,
291,
423,
362,
63,
1258,
8,
11770,
3041,
9,
339,
347,
664,
63,
7270,
63,
1258,
8,
277,
304,
267,
372,
291,
423,
362,
63,
1258,
8,
16333,
3041,
9,
339,
347,
664,
63,
439,
528,
6813,
63,
1258,
8,
277,
304,
267,
372,
291,
423,
362,
63,
1258,
8,
7394,
12455,
3041,
9,
339,
347,
664,
63,
3620,
63,
354,
8,
277,
304,
267,
340,
291,
423,
3620,
365,
440,
488,
26,
288,
372,
291,
423,
3620,
267,
372,
291,
423,
888,
14,
362,
63,
885,
63,
3620,
342,
339,
347,
485,
362,
63,
3028,
8,
277,
12,
3982,
12,
2257,
12,
2883,
304,
267,
3915,
275,
1052,
267,
367,
1022,
315,
2883,
26,
288,
519,
275,
3982,
14,
362,
8,
75,
59,
16,
566,
288,
634,
275,
2257,
14,
362,
8,
75,
59,
17,
566,
288,
340,
519,
508,
634,
26,
355,
3915,
59,
75,
59,
17,
2677,
275,
488,
288,
587,
26,
355,
3915,
59,
75,
59,
17,
2677,
275,
334,
82,
12,
634,
4258,
267,
372,
3915,
339,
347,
485,
1361,
63,
3028,
8,
277,
12,
2403,
12,
3982,
12,
2257,
12,
2883,
304,
267,
3915,
275,
291,
423,
362,
63,
3028,
8,
3846,
12,
2257,
12,
2883,
9,
267,
367,
1022,
12,
373,
315,
3915,
14,
1744,
837,
288,
340,
373,
365,
440,
488,
26,
355,
291,
423,
2921,
14,
4050,
8,
490,
5041,
80,
93,
469,
75,
9160,
469,
82,
93,
1035,
469,
76,
5285,
908,
8,
80,
29,
1861,
12,
1022,
29,
75,
12,
519,
29,
86,
59,
16,
467,
634,
29,
86,
59,
17,
2459,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
504,
13022,
492,
29565,
12,
9006,
765,
199,
504,
25917,
2588,
14,
888,
492,
4094,
199,
504,
25917,
2588,
14,
793,
492,
664,
63,
2921,
199,
504,
25917,
2588,
14,
14555,
492,
334,
272,
28650,
3041,
12,
272,
1804,
706,
3041,
12,
272,
27982,
3041,
12,
272,
3835,
458,
3041,
12,
272,
13986,
12455,
3041,
199,
9,
421,
199,
533,
3523,
3310,
26,
339,
636,
6577,
363,
275,
29565,
339,
485,
2921,
275,
488,
339,
347,
636,
826,
721,
277,
12,
1249,
304,
267,
291,
423,
888,
275,
4094,
8,
589,
14,
2190,
63,
493,
9,
267,
291,
423,
10481,
63,
1065,
275,
756,
267,
291,
423,
3620,
275,
488,
398,
340,
2688,
8,
589,
12,
283,
3620,
735,
288,
291,
423,
3620,
275,
1249,
14,
3620,
398,
2512,
63,
354,
275,
283,
17984,
2588,
7,
267,
340,
2688,
8,
589,
12,
283,
10481,
63,
1065,
735,
288,
291,
423,
10481,
63,
1065,
275,
1249,
14,
10481,
63,
1065,
288,
340,
291,
423,
10481,
63,
1065,
26,
355,
2512,
63,
354,
275,
8189,
36,
651,
1255,
9,
25917,
2588,
7,
398,
291,
423,
2921,
275,
664,
63,
2921,
8,
2921,
63,
354,
9,
339,
768,
10315,
272,
347,
1595,
8,
277,
304,
267,
746,
4279,
339,
347,
485,
362,
63,
1258,
8,
277,
12,
843,
304,
267,
372,
843,
8,
288,
4897,
29,
277,
423,
888,
14,
362,
63,
4551,
1062,
288,
4690,
29,
277,
423,
888,
14,
362,
63,
2913,
1062,
288,
9951,
63,
1065,
29,
277,
423,
10481,
63,
1065,
9,
339,
347,
664,
63,
2734,
63,
1258,
8,
277,
304,
267,
372,
291,
423,
362,
63,
1258,
8,
21350,
3041,
9,
339,
347,
664,
63,
75,
706,
63,
1258,
8,
277,
304,
267,
372,
291,
423,
362,
63,
1258,
8,
43,
706,
3041,
9,
339,
347,
664,
63,
4368,
63,
1258,
8,
277,
304,
267,
372,
291,
423,
362,
63,
1258,
8,
11770,
3041,
9,
339,
347,
664,
63,
7270,
63,
1258,
8,
277,
304,
267,
372,
291,
423,
362,
63,
1258,
8,
16333,
3041,
9,
339,
347,
664,
63,
439,
528,
6813,
63,
1258,
8,
277,
304,
267,
372,
291,
423,
362,
63,
1258,
8,
7394,
12455,
3041,
9,
339,
347,
664,
63,
3620,
63,
354,
8,
277,
304,
267,
340,
291,
423,
3620,
365,
440,
488,
26,
288,
372,
291,
423,
3620,
267,
372,
291,
423,
888,
14,
362,
63,
885,
63,
3620,
342,
339,
347,
485,
362,
63,
3028,
8,
277,
12,
3982,
12,
2257,
12,
2883,
304,
267,
3915,
275,
1052,
267,
367,
1022,
315,
2883,
26,
288,
519,
275,
3982,
14,
362,
8,
75,
59,
16,
566,
288,
634,
275,
2257,
14,
362,
8,
75,
59,
17,
566,
288,
340,
519,
508,
634,
26,
355,
3915,
59,
75,
59,
17,
2677,
275,
488,
288,
587,
26,
355,
3915,
59,
75,
59,
17,
2677,
275,
334,
82,
12,
634,
4258,
267,
372,
3915,
339,
347,
485,
1361,
63,
3028,
8,
277,
12,
2403,
12,
3982,
12,
2257,
12,
2883,
304,
267,
3915,
275,
291,
423,
362,
63,
3028,
8,
3846,
12,
2257,
12,
2883,
9,
267,
367,
1022,
12,
373,
315,
3915,
14,
1744,
837,
288,
340,
373,
365,
440,
488,
26,
355,
291,
423,
2921,
14,
4050,
8,
490,
5041,
80,
93,
469,
75,
9160,
469,
82,
93,
1035,
469,
76,
5285,
908,
8,
80,
29,
1861,
12,
1022,
29,
75,
12,
519,
29,
86,
59,
16,
467,
634,
29,
86,
59,
17,
2459,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
smurfix/HomEvenT
|
homevent/__init__.py
|
1
|
1392
|
# -*- coding: utf-8 -*-
##
## Copyright © 2007-2012, Matthias Urlichs <matthias@urlichs.de>
##
## 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 (included; see the file LICENSE)
## for more details.
##
"""\
This is the core of the event dispatcher.
"""
# This test is also in homevent/twist.py, for recursive-import reasons
import os
if "HOMEVENT_TEST" in os.environ:
from homevent.testreactor import install
TESTING = True
else:
from homevent.geventreactor import install
TESTING = False
install()
del install
from gevent import monkey
monkey.patch_all()
del monkey
from homevent.gevent_rpyc import patch_all
patch_all()
del patch_all
from homevent import twist # for side effects
VERSION = "0.3"
__all__ = ("Context", "Event", "Worker","SeqWorker","WorkSequence",
"collect_event","process_event","register_worker", "mainloop",
"main_words","global_words", "register_condition")
# Do not export "log" by default; it's too generic.
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
309,
221,
199,
309,
221,
1898,
22405,
103,
10219,
13,
7409,
12,
18619,
273,
2241,
738,
82,
317,
32556,
665,
569,
273,
2241,
32,
300,
317,
32556,
14,
271,
30,
199,
309,
199,
309,
221,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
309,
221,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
309,
221,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
309,
221,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
221,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
309,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
309,
221,
1664,
1696,
1684,
844,
334,
12409,
27,
1937,
314,
570,
5113,
9,
199,
309,
221,
367,
1655,
2436,
14,
199,
309,
199,
199,
19659,
199,
2765,
365,
314,
6170,
402,
314,
1566,
17475,
14,
199,
624,
199,
199,
3,
961,
511,
365,
2597,
315,
5629,
782,
15,
8122,
631,
14,
647,
12,
367,
9133,
13,
646,
14872,
199,
646,
747,
199,
692,
298,
9524,
4554,
63,
2864,
2,
315,
747,
14,
2314,
26,
199,
198,
504,
5629,
782,
14,
396,
13544,
492,
3907,
199,
198,
2864,
1206,
275,
715,
199,
2836,
26,
199,
198,
504,
5629,
782,
14,
303,
782,
13544,
492,
3907,
199,
198,
2864,
1206,
275,
756,
199,
3174,
342,
199,
2264,
3907,
199,
199,
504,
23386,
492,
14198,
199,
20372,
14,
2068,
63,
452,
342,
199,
2264,
14198,
199,
199,
504,
5629,
782,
14,
303,
782,
63,
82,
11357,
492,
3371,
63,
452,
199,
2068,
63,
452,
342,
199,
2264,
3371,
63,
452,
199,
199,
504,
5629,
782,
492,
8900,
631,
327,
367,
5366,
22414,
199,
199,
4612,
275,
298,
16,
14,
19,
2,
199,
199,
363,
452,
363,
275,
1689,
2998,
401,
298,
2390,
401,
298,
12678,
2266,
11205,
12678,
2266,
6517,
5826,
401,
199,
198,
2,
7112,
63,
1430,
2266,
1412,
63,
1430,
2266,
2683,
63,
6599,
401,
298,
22644,
401,
199,
198,
2,
973,
63,
3148,
2266,
2966,
63,
3148,
401,
298,
2683,
63,
5394,
531,
199,
3,
4226,
440,
4843,
298,
793,
2,
701,
849,
27,
652,
1159,
4634,
7809,
14,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
309,
221,
199,
309,
221,
1898,
22405,
103,
10219,
13,
7409,
12,
18619,
273,
2241,
738,
82,
317,
32556,
665,
569,
273,
2241,
32,
300,
317,
32556,
14,
271,
30,
199,
309,
199,
309,
221,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
309,
221,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
309,
221,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
309,
221,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
221,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
309,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
309,
221,
1664,
1696,
1684,
844,
334,
12409,
27,
1937,
314,
570,
5113,
9,
199,
309,
221,
367,
1655,
2436,
14,
199,
309,
199,
199,
19659,
199,
2765,
365,
314,
6170,
402,
314,
1566,
17475,
14,
199,
624,
199,
199,
3,
961,
511,
365,
2597,
315,
5629,
782,
15,
8122,
631,
14,
647,
12,
367,
9133,
13,
646,
14872,
199,
646,
747,
199,
692,
298,
9524,
4554,
63,
2864,
2,
315,
747,
14,
2314,
26,
199,
198,
504,
5629,
782,
14,
396,
13544,
492,
3907,
199,
198,
2864,
1206,
275,
715,
199,
2836,
26,
199,
198,
504,
5629,
782,
14,
303,
782,
13544,
492,
3907,
199,
198,
2864,
1206,
275,
756,
199,
3174,
342,
199,
2264,
3907,
199,
199,
504,
23386,
492,
14198,
199,
20372,
14,
2068,
63,
452,
342,
199,
2264,
14198,
199,
199,
504,
5629,
782,
14,
303,
782,
63,
82,
11357,
492,
3371,
63,
452,
199,
2068,
63,
452,
342,
199,
2264,
3371,
63,
452,
199,
199,
504,
5629,
782,
492,
8900,
631,
327,
367,
5366,
22414,
199,
199,
4612,
275,
298,
16,
14,
19,
2,
199,
199,
363,
452,
363,
275,
1689,
2998,
401,
298,
2390,
401,
298,
12678,
2266,
11205,
12678,
2266,
6517,
5826,
401,
199,
198,
2,
7112,
63,
1430,
2266,
1412,
63,
1430,
2266,
2683,
63,
6599,
401,
298,
22644,
401,
199,
198,
2,
973,
63,
3148,
2266,
2966,
63,
3148,
401,
298,
2683,
63,
5394,
531,
199,
3,
4226,
440,
4843,
298,
793,
2,
701,
849,
27,
652,
1159,
4634,
7809,
14,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
TalShor/SciLMM
|
scilmm/Tests/test_IBDCompute.py
|
1
|
2451
|
import os
from os.path import join
from unittest import TestCase
import numpy as np
from scilmm import IBDCompute
class TestIBDCompute(TestCase):
def setUp(self):
self.ibd_compute = IBDCompute()
def test_compute_relationships(self):
pedigree, entries_list = self.ibd_compute.compute_relationships(
join(os.path.abspath(os.path.dirname(__file__)), 'Examples', 'relationship_example.csv'))
self.assertEqual(len(entries_list), 10)
self.assertEqual(pedigree.family.shape[0], 10)
def test_simulate_relationship(self):
pedigree, entries_list = self.ibd_compute.simulate_relationship(sample_size=1000, sparsity_factor=0.01)
self.assertEqual(pedigree.family.shape[0], 1000)
# Testing a family with no connections
self.assertRaises(Exception, self.ibd_compute.simulate_relationship, sample_size=100, sparsity_factor=0.0001)
def test_compute_ibd(self):
_, _ = self.ibd_compute.simulate_relationship(sample_size=1000, sparsity_factor=0.01)
ibd, _, _ = self.ibd_compute.compute_ibd()
self.assertEqual(ibd.max(), 1)
self.assertEqual((ibd == ibd.max()).sum(), 1000)
self.assertGreaterEqual((ibd == 0.5).sum(), 10)
self.assertLessEqual((ibd == 0.5).sum(), 1000)
def test_circular_rel(self):
pedigree, entries_list = self.ibd_compute.compute_relationships(
join(os.path.abspath(os.path.dirname(__file__)), 'Examples', 'circular_rel.fam'))
self.assertEqual(pedigree.relationship.sum(), 3)
self.assertLess(pedigree.relationship.sum(), pedigree.family.shape[0])
def test_half_and_full_brothers(self):
pedigree, entries_list = self.ibd_compute.compute_relationships(
join(os.path.abspath(os.path.dirname(__file__)), 'Examples', 'half_and_full_brothers.fam'))
ibd, _, _ = self.ibd_compute.compute_ibd()
self.assertEqual(ibd[(np.argwhere(entries_list == '0_9')[0][0], np.argwhere(entries_list == '0_8')[0][0])],
0.25)
self.assertEqual(ibd[(np.argwhere(entries_list == '0_3')[0][0], np.argwhere(entries_list == '0_4')[0][0])], 0.5)
def test_too_many_parents(self):
pedigree, entries_list = self.ibd_compute.compute_relationships(
join(os.path.abspath(os.path.dirname(__file__)), 'Examples', 'too_many_parents.fam'))
self.assertEqual(set(entries_list), {'0_10', '0_11', '0_12'})
|
gpl-3.0
|
[
646,
747,
199,
504,
747,
14,
515,
492,
4263,
199,
504,
2882,
492,
7640,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
4061,
382,
596,
492,
473,
11156,
8564,
421,
199,
533,
1379,
2100,
36,
8564,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
1892,
68,
63,
3357,
275,
473,
11156,
8564,
342,
339,
347,
511,
63,
3357,
63,
24034,
8,
277,
304,
267,
4837,
18367,
850,
12,
4811,
63,
513,
275,
291,
14,
1892,
68,
63,
3357,
14,
3357,
63,
24034,
8,
288,
4263,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
22159,
283,
22787,
297,
283,
11704,
63,
2694,
14,
4737,
1333,
267,
291,
14,
629,
8,
552,
8,
3189,
63,
513,
395,
1616,
9,
267,
291,
14,
629,
8,
321,
18367,
850,
14,
6606,
14,
1392,
59,
16,
467,
1616,
9,
339,
347,
511,
63,
28689,
63,
11704,
8,
277,
304,
267,
4837,
18367,
850,
12,
4811,
63,
513,
275,
291,
14,
1892,
68,
63,
3357,
14,
28689,
63,
11704,
8,
3271,
63,
890,
29,
5279,
12,
28668,
3677,
63,
4778,
29,
16,
14,
614,
9,
267,
291,
14,
629,
8,
321,
18367,
850,
14,
6606,
14,
1392,
59,
16,
467,
5198,
9,
398,
327,
11940,
282,
9614,
543,
949,
6947,
267,
291,
14,
1855,
8,
1726,
12,
291,
14,
1892,
68,
63,
3357,
14,
28689,
63,
11704,
12,
2690,
63,
890,
29,
1960,
12,
28668,
3677,
63,
4778,
29,
16,
14,
4183,
9,
339,
347,
511,
63,
3357,
63,
1892,
68,
8,
277,
304,
267,
5501,
485,
275,
291,
14,
1892,
68,
63,
3357,
14,
28689,
63,
11704,
8,
3271,
63,
890,
29,
5279,
12,
28668,
3677,
63,
4778,
29,
16,
14,
614,
9,
267,
284,
3691,
12,
5501,
485,
275,
291,
14,
1892,
68,
63,
3357,
14,
3357,
63,
1892,
68,
342,
267,
291,
14,
629,
8,
1892,
68,
14,
988,
1062,
413,
9,
267,
291,
14,
629,
1332,
1892,
68,
508,
284,
3691,
14,
988,
8801,
1838,
1062,
5198,
9,
267,
291,
14,
26875,
1332,
1892,
68,
508,
378,
14,
21,
680,
1838,
1062,
1616,
9,
267,
291,
14,
15625,
591,
1332,
1892,
68,
508,
378,
14,
21,
680,
1838,
1062,
5198,
9,
339,
347,
511,
63,
23022,
63,
3369,
8,
277,
304,
267,
4837,
18367,
850,
12,
4811,
63,
513,
275,
291,
14,
1892,
68,
63,
3357,
14,
3357,
63,
24034,
8,
288,
4263,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
22159,
283,
22787,
297,
283,
23022,
63,
3369,
14,
18493,
1333,
267,
291,
14,
629,
8,
321,
18367,
850,
14,
11704,
14,
1838,
1062,
650,
9,
267,
291,
14,
15625,
8,
321,
18367,
850,
14,
11704,
14,
1838,
1062,
4837,
18367,
850,
14,
6606,
14,
1392,
59,
16,
566,
339,
347,
511,
63,
10220,
63,
460,
63,
2861,
63,
20670,
728,
83,
8,
277,
304,
267,
4837,
18367,
850,
12,
4811,
63,
513,
275,
291,
14,
1892,
68,
63,
3357,
14,
3357,
63,
24034,
8,
288,
4263,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
22159,
283,
22787,
297,
283,
10220,
63,
460,
63,
2861,
63,
20670,
728,
83,
14,
18493,
1333,
267,
284,
3691,
12,
5501,
485,
275,
291,
14,
1892,
68,
63,
3357,
14,
3357,
63,
1892,
68,
342,
267,
291,
14,
629,
8,
1892,
68,
7528,
1590,
14,
1273,
4509,
8,
3189,
63,
513,
508,
283,
16,
63,
25,
5832,
16,
1527,
16,
467,
980,
14,
1273,
4509,
8,
3189,
63,
513,
508,
283,
16,
63,
24,
5832,
16,
1527,
16,
27520,
586,
378,
14,
821,
9,
267,
291,
14,
629,
8,
1892,
68,
7528,
1590,
14,
1273,
4509,
8,
3189,
63,
513,
508,
283,
16,
63,
19,
5832,
16,
1527,
16,
467,
980,
14,
1273,
4509,
8,
3189,
63,
513,
508,
283,
16,
63,
20,
5832,
16,
1527,
16,
27520,
378,
14,
21,
9,
339,
347,
511,
63,
7354,
63,
3479,
63,
8859,
8,
277,
304,
267,
4837,
18367,
850,
12,
4811,
63,
513,
275,
291,
14,
1892,
68,
63,
3357,
14,
3357,
63,
24034,
8,
288,
4263,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
22159,
283,
22787,
297,
283,
7354,
63,
3479,
63,
8859,
14,
18493,
1333,
267,
291,
14,
629,
8,
409,
8,
3189,
63,
513,
395,
791,
16,
63,
709,
297,
283,
16,
63,
845,
297,
283,
16,
63,
713,
3071,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
199,
504,
747,
14,
515,
492,
4263,
199,
504,
2882,
492,
7640,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
4061,
382,
596,
492,
473,
11156,
8564,
421,
199,
533,
1379,
2100,
36,
8564,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
1892,
68,
63,
3357,
275,
473,
11156,
8564,
342,
339,
347,
511,
63,
3357,
63,
24034,
8,
277,
304,
267,
4837,
18367,
850,
12,
4811,
63,
513,
275,
291,
14,
1892,
68,
63,
3357,
14,
3357,
63,
24034,
8,
288,
4263,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
22159,
283,
22787,
297,
283,
11704,
63,
2694,
14,
4737,
1333,
267,
291,
14,
629,
8,
552,
8,
3189,
63,
513,
395,
1616,
9,
267,
291,
14,
629,
8,
321,
18367,
850,
14,
6606,
14,
1392,
59,
16,
467,
1616,
9,
339,
347,
511,
63,
28689,
63,
11704,
8,
277,
304,
267,
4837,
18367,
850,
12,
4811,
63,
513,
275,
291,
14,
1892,
68,
63,
3357,
14,
28689,
63,
11704,
8,
3271,
63,
890,
29,
5279,
12,
28668,
3677,
63,
4778,
29,
16,
14,
614,
9,
267,
291,
14,
629,
8,
321,
18367,
850,
14,
6606,
14,
1392,
59,
16,
467,
5198,
9,
398,
327,
11940,
282,
9614,
543,
949,
6947,
267,
291,
14,
1855,
8,
1726,
12,
291,
14,
1892,
68,
63,
3357,
14,
28689,
63,
11704,
12,
2690,
63,
890,
29,
1960,
12,
28668,
3677,
63,
4778,
29,
16,
14,
4183,
9,
339,
347,
511,
63,
3357,
63,
1892,
68,
8,
277,
304,
267,
5501,
485,
275,
291,
14,
1892,
68,
63,
3357,
14,
28689,
63,
11704,
8,
3271,
63,
890,
29,
5279,
12,
28668,
3677,
63,
4778,
29,
16,
14,
614,
9,
267,
284,
3691,
12,
5501,
485,
275,
291,
14,
1892,
68,
63,
3357,
14,
3357,
63,
1892,
68,
342,
267,
291,
14,
629,
8,
1892,
68,
14,
988,
1062,
413,
9,
267,
291,
14,
629,
1332,
1892,
68,
508,
284,
3691,
14,
988,
8801,
1838,
1062,
5198,
9,
267,
291,
14,
26875,
1332,
1892,
68,
508,
378,
14,
21,
680,
1838,
1062,
1616,
9,
267,
291,
14,
15625,
591,
1332,
1892,
68,
508,
378,
14,
21,
680,
1838,
1062,
5198,
9,
339,
347,
511,
63,
23022,
63,
3369,
8,
277,
304,
267,
4837,
18367,
850,
12,
4811,
63,
513,
275,
291,
14,
1892,
68,
63,
3357,
14,
3357,
63,
24034,
8,
288,
4263,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
22159,
283,
22787,
297,
283,
23022,
63,
3369,
14,
18493,
1333,
267,
291,
14,
629,
8,
321,
18367,
850,
14,
11704,
14,
1838,
1062,
650,
9,
267,
291,
14,
15625,
8,
321,
18367,
850,
14,
11704,
14,
1838,
1062,
4837,
18367,
850,
14,
6606,
14,
1392,
59,
16,
566,
339,
347,
511,
63,
10220,
63,
460,
63,
2861,
63,
20670,
728,
83,
8,
277,
304,
267,
4837,
18367,
850,
12,
4811,
63,
513,
275,
291,
14,
1892,
68,
63,
3357,
14,
3357,
63,
24034,
8,
288,
4263,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
22159,
283,
22787,
297,
283,
10220,
63,
460,
63,
2861,
63,
20670,
728,
83,
14,
18493,
1333,
267,
284,
3691,
12,
5501,
485,
275,
291,
14,
1892,
68,
63,
3357,
14,
3357,
63,
1892,
68,
342,
267,
291,
14,
629,
8,
1892,
68,
7528,
1590,
14,
1273,
4509,
8,
3189,
63,
513,
508,
283,
16,
63,
25,
5832,
16,
1527,
16,
467,
980,
14,
1273,
4509,
8,
3189,
63,
513,
508,
283,
16,
63,
24,
5832,
16,
1527,
16,
27520,
586,
378,
14,
821,
9,
267,
291,
14,
629,
8,
1892,
68,
7528,
1590,
14,
1273,
4509,
8,
3189,
63,
513,
508,
283,
16,
63,
19,
5832,
16,
1527,
16,
467,
980,
14,
1273,
4509,
8,
3189,
63,
513,
508,
283,
16,
63,
20,
5832,
16,
1527,
16,
27520,
378,
14,
21,
9,
339,
347,
511,
63,
7354,
63,
3479,
63,
8859,
8,
277,
304,
267,
4837,
18367,
850,
12,
4811,
63,
513,
275,
291,
14,
1892,
68,
63,
3357,
14,
3357,
63,
24034,
8,
288,
4263,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
22159,
283,
22787,
297,
283,
7354,
63,
3479,
63,
8859,
14,
18493,
1333,
267,
291,
14,
629,
8,
409,
8,
3189,
63,
513,
395,
791,
16,
63,
709,
297,
283,
16,
63,
845,
297,
283,
16,
63,
713,
3071,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Mercador/python-keystoneclient
|
keystoneclient/baseclient.py
|
10
|
1313
|
# 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.
class Client(object):
def __init__(self, session):
self.session = session
def request(self, url, method, **kwargs):
kwargs.setdefault('authenticated', True)
return self.session.request(url, method, **kwargs)
def get(self, url, **kwargs):
return self.request(url, 'GET', **kwargs)
def head(self, url, **kwargs):
return self.request(url, 'HEAD', **kwargs)
def post(self, url, **kwargs):
return self.request(url, 'POST', **kwargs)
def put(self, url, **kwargs):
return self.request(url, 'PUT', **kwargs)
def patch(self, url, **kwargs):
return self.request(url, 'PATCH', **kwargs)
def delete(self, url, **kwargs):
return self.request(url, 'DELETE', **kwargs)
|
apache-2.0
|
[
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
421,
199,
533,
6810,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
2351,
304,
267,
291,
14,
1730,
275,
2351,
339,
347,
1056,
8,
277,
12,
1166,
12,
1083,
12,
1011,
958,
304,
267,
2074,
14,
5486,
360,
12177,
297,
715,
9,
267,
372,
291,
14,
1730,
14,
1069,
8,
633,
12,
1083,
12,
1011,
958,
9,
339,
347,
664,
8,
277,
12,
1166,
12,
1011,
958,
304,
267,
372,
291,
14,
1069,
8,
633,
12,
283,
2970,
297,
1011,
958,
9,
339,
347,
4854,
8,
277,
12,
1166,
12,
1011,
958,
304,
267,
372,
291,
14,
1069,
8,
633,
12,
283,
5211,
297,
1011,
958,
9,
339,
347,
2963,
8,
277,
12,
1166,
12,
1011,
958,
304,
267,
372,
291,
14,
1069,
8,
633,
12,
283,
4030,
297,
1011,
958,
9,
339,
347,
5324,
8,
277,
12,
1166,
12,
1011,
958,
304,
267,
372,
291,
14,
1069,
8,
633,
12,
283,
4013,
297,
1011,
958,
9,
339,
347,
3371,
8,
277,
12,
1166,
12,
1011,
958,
304,
267,
372,
291,
14,
1069,
8,
633,
12,
283,
17073,
297,
1011,
958,
9,
339,
347,
3145,
8,
277,
12,
1166,
12,
1011,
958,
304,
267,
372,
291,
14,
1069,
8,
633,
12,
283,
7014,
297,
1011,
958,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
421,
199,
533,
6810,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
2351,
304,
267,
291,
14,
1730,
275,
2351,
339,
347,
1056,
8,
277,
12,
1166,
12,
1083,
12,
1011,
958,
304,
267,
2074,
14,
5486,
360,
12177,
297,
715,
9,
267,
372,
291,
14,
1730,
14,
1069,
8,
633,
12,
1083,
12,
1011,
958,
9,
339,
347,
664,
8,
277,
12,
1166,
12,
1011,
958,
304,
267,
372,
291,
14,
1069,
8,
633,
12,
283,
2970,
297,
1011,
958,
9,
339,
347,
4854,
8,
277,
12,
1166,
12,
1011,
958,
304,
267,
372,
291,
14,
1069,
8,
633,
12,
283,
5211,
297,
1011,
958,
9,
339,
347,
2963,
8,
277,
12,
1166,
12,
1011,
958,
304,
267,
372,
291,
14,
1069,
8,
633,
12,
283,
4030,
297,
1011,
958,
9,
339,
347,
5324,
8,
277,
12,
1166,
12,
1011,
958,
304,
267,
372,
291,
14,
1069,
8,
633,
12,
283,
4013,
297,
1011,
958,
9,
339,
347,
3371,
8,
277,
12,
1166,
12,
1011,
958,
304,
267,
372,
291,
14,
1069,
8,
633,
12,
283,
17073,
297,
1011,
958,
9,
339,
347,
3145,
8,
277,
12,
1166,
12,
1011,
958,
304,
267,
372,
291,
14,
1069,
8,
633,
12,
283,
7014,
297,
1011,
958,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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from __future__ import unicode_literals
from django.core.exceptions import ImproperlyConfigured
from django import forms
from django.forms.extras import SelectDateWidget
from django.utils.translation import ugettext_lazy as _
from mezzanine.conf import settings
from mezzanine.core.forms import SplitSelectDateTimeWidget
from mezzanine.utils.importing import import_dotted_path
# Constants for all available field types.
TEXT = 1
TEXTAREA = 2
EMAIL = 3
CHECKBOX = 4
CHECKBOX_MULTIPLE = 5
SELECT = 6
SELECT_MULTIPLE = 7
RADIO_MULTIPLE = 8
FILE = 9
DATE = 10
DATE_TIME = 11
HIDDEN = 12
NUMBER = 13
URL = 14
DOB = 15
# Names for all available field types.
NAMES = (
(TEXT, _("Single line text")),
(TEXTAREA, _("Multi line text")),
(EMAIL, _("Email")),
(NUMBER, _("Number")),
(URL, _("URL")),
(CHECKBOX, _("Check box")),
(CHECKBOX_MULTIPLE, _("Check boxes")),
(SELECT, _("Drop down")),
(SELECT_MULTIPLE, _("Multi select")),
(RADIO_MULTIPLE, _("Radio buttons")),
(FILE, _("File upload")),
(DATE, _("Date")),
(DATE_TIME, _("Date/time")),
(DOB, _("Date of birth")),
(HIDDEN, _("Hidden")),
)
# Field classes for all available field types.
CLASSES = {
TEXT: forms.CharField,
TEXTAREA: forms.CharField,
EMAIL: forms.EmailField,
CHECKBOX: forms.BooleanField,
CHECKBOX_MULTIPLE: forms.MultipleChoiceField,
SELECT: forms.ChoiceField,
SELECT_MULTIPLE: forms.MultipleChoiceField,
RADIO_MULTIPLE: forms.ChoiceField,
FILE: forms.FileField,
DATE: forms.DateField,
DATE_TIME: forms.DateTimeField,
DOB: forms.DateField,
HIDDEN: forms.CharField,
NUMBER: forms.FloatField,
URL: forms.URLField,
}
# Widgets for field types where a specialised widget is required.
WIDGETS = {
TEXTAREA: forms.Textarea,
CHECKBOX_MULTIPLE: forms.CheckboxSelectMultiple,
RADIO_MULTIPLE: forms.RadioSelect,
DATE: SelectDateWidget,
DATE_TIME: SplitSelectDateTimeWidget,
DOB: SelectDateWidget,
HIDDEN: forms.HiddenInput,
}
# Some helper groupings of field types.
CHOICES = (CHECKBOX, SELECT, RADIO_MULTIPLE)
DATES = (DATE, DATE_TIME, DOB)
MULTIPLE = (CHECKBOX_MULTIPLE, SELECT_MULTIPLE)
# HTML5 Widgets
html5_field = lambda name, base: type(str(""), (base,), {"input_type": name})
if getattr(settings, "FORMS_USE_HTML5", False):
WIDGETS.update({
DATE: html5_field("date", forms.DateInput),
DATE_TIME: html5_field("datetime", forms.DateTimeInput),
DOB: html5_field("date", forms.DateInput),
EMAIL: html5_field("email", forms.TextInput),
NUMBER: html5_field("number", forms.TextInput),
URL: html5_field("url", forms.TextInput),
})
# Allow extra fields types to be defined via the FORMS_EXTRA_FIELDS
# setting, which should contain a sequence of three-item sequences,
# each containing the ID, dotted import path for the field class,
# and field name, for each custom field type.
extra_fields = getattr(settings, "FORMS_EXTRA_FIELDS", [])
for field_id, field_path, field_name in extra_fields:
if field_id in CLASSES:
err = "ID %s for field %s in FORMS_EXTRA_FIELDS already exists"
raise ImproperlyConfigured(err % (field_id, field_name))
CLASSES[field_id] = import_dotted_path(field_path)
NAMES += ((field_id, _(field_name)),)
# Similar to above but for widgets - expects a sequence of pairs,
# each with a field ID as per above, and a dotted path to the custom
# widget class to use for the corresponding form field.
extra_widgets = getattr(settings, "FORMS_EXTRA_WIDGETS", [])
for field_id, widget_path in extra_widgets:
if field_id not in CLASSES:
err = "ID %s in FORMS_EXTRA_WIDGETS does not match a field"
raise ImproperlyConfigured(err % field_id)
WIDGETS[field_id] = import_dotted_path(widget_path)
|
bsd-2-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
3351,
14,
9975,
492,
9496,
2506,
3339,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
562,
4348,
290,
1132,
14,
2190,
492,
2202,
199,
504,
562,
4348,
290,
1132,
14,
1018,
14,
3351,
492,
11740,
5446,
3926,
3339,
199,
504,
562,
4348,
290,
1132,
14,
1208,
14,
646,
316,
492,
492,
63,
19404,
63,
515,
421,
199,
3,
22296,
367,
1006,
2808,
901,
2943,
14,
199,
3876,
275,
413,
199,
3876,
28591,
275,
499,
199,
10089,
275,
650,
199,
8936,
15694,
275,
841,
199,
8936,
15694,
63,
21894,
906,
275,
959,
199,
4859,
275,
1227,
199,
4859,
63,
21894,
906,
275,
1520,
199,
19662,
2090,
63,
21894,
906,
275,
1695,
199,
3817,
275,
1749,
199,
5390,
275,
1616,
199,
5390,
63,
4961,
275,
4119,
199,
40,
22436,
275,
3144,
199,
9190,
275,
4944,
199,
2632,
275,
4329,
199,
1649,
34,
275,
4114,
199,
199,
3,
23923,
367,
1006,
2808,
901,
2943,
14,
199,
14546,
275,
334,
272,
334,
3876,
12,
3824,
7200,
1004,
1318,
8150,
272,
334,
3876,
28591,
12,
3824,
3947,
1004,
1318,
8150,
272,
334,
10089,
12,
3824,
7035,
8150,
272,
334,
9190,
12,
3824,
3259,
8150,
272,
334,
2632,
12,
3824,
2632,
8150,
272,
334,
8936,
15694,
12,
3824,
1799,
5689,
8150,
272,
334,
8936,
15694,
63,
21894,
906,
12,
3824,
1799,
17193,
8150,
272,
334,
4859,
12,
3824,
11070,
3224,
8150,
272,
334,
4859,
63,
21894,
906,
12,
3824,
3947,
3504,
8150,
272,
334,
19662,
2090,
63,
21894,
906,
12,
3824,
16065,
15766,
8150,
272,
334,
3817,
12,
3824,
1173,
5802,
8150,
272,
334,
5390,
12,
3824,
2506,
8150,
272,
334,
5390,
63,
4961,
12,
3824,
2506,
15,
521,
8150,
272,
334,
1649,
34,
12,
3824,
2506,
402,
21036,
8150,
272,
334,
40,
22436,
12,
3824,
14983,
8150,
199,
9,
199,
199,
3,
5024,
3992,
367,
1006,
2808,
901,
2943,
14,
199,
13748,
275,
469,
272,
11951,
26,
4513,
14,
2183,
12,
272,
11951,
28591,
26,
4513,
14,
2183,
12,
272,
32320,
26,
4513,
14,
16577,
12,
272,
17654,
15694,
26,
4513,
14,
5036,
12,
272,
17654,
15694,
63,
21894,
906,
26,
4513,
14,
8433,
15792,
12,
272,
10468,
26,
4513,
14,
15792,
12,
272,
10468,
63,
21894,
906,
26,
4513,
14,
8433,
15792,
12,
272,
820,
1554,
2090,
63,
21894,
906,
26,
4513,
14,
15792,
12,
272,
13024,
26,
4513,
14,
23252,
12,
272,
30131,
26,
4513,
14,
14071,
12,
272,
30131,
63,
4961,
26,
4513,
14,
4626,
12,
272,
3506,
34,
26,
4513,
14,
14071,
12,
272,
869,
22436,
26,
4513,
14,
2183,
12,
272,
18122,
26,
4513,
14,
13019,
12,
272,
2851,
26,
4513,
14,
17363,
12,
199,
93,
199,
199,
3,
16905,
83,
367,
901,
2943,
2382,
282,
4539,
9096,
3938,
365,
1415,
14,
199,
9845,
2970,
51,
275,
469,
272,
11951,
28591,
26,
4513,
14,
1872,
6789,
12,
272,
17654,
15694,
63,
21894,
906,
26,
4513,
14,
26366,
32331,
12,
272,
820,
1554,
2090,
63,
21894,
906,
26,
4513,
14,
16065,
5446,
12,
272,
30131,
26,
9496,
2506,
3339,
12,
272,
30131,
63,
4961,
26,
11740,
5446,
3926,
3339,
12,
272,
3506,
34,
26,
9496,
2506,
3339,
12,
272,
869,
22436,
26,
4513,
14,
25419,
12,
199,
93,
199,
199,
3,
6601,
5922,
1572,
780,
402,
901,
2943,
14,
199,
16236,
275,
334,
8936,
15694,
12,
10468,
12,
820,
1554,
2090,
63,
21894,
906,
9,
199,
6521,
654,
275,
334,
5390,
12,
30131,
63,
4961,
12,
3506,
34,
9,
199,
21894,
906,
275,
334,
8936,
15694,
63,
21894,
906,
12,
10468,
63,
21894,
906,
9,
199,
199,
3,
4163,
21,
16905,
83,
199,
1360,
21,
63,
698,
275,
2400,
536,
12,
1300,
26,
730,
8,
495,
11986,
395,
334,
1095,
4706,
2420,
1210,
63,
466,
582,
536,
1552,
199,
692,
2519,
8,
1751,
12,
298,
11518,
63,
4701,
63,
4943,
21,
401,
756,
304,
272,
644,
998,
2970,
51,
14,
873,
2561,
267,
30131,
26,
3517,
21,
63,
698,
480,
602,
401,
4513,
14,
2506,
3205,
395,
267,
30131,
63,
4961,
26,
3517,
21,
63,
698,
480,
2083,
401,
4513,
14,
3926,
3205,
395,
267,
3506,
34,
26,
3517,
21,
63,
698,
480,
602,
401,
4513,
14,
2506,
3205,
395,
267,
32320,
26,
3517,
21,
63,
698,
480,
2123,
401,
4513,
14,
18362,
395,
267,
18122,
26,
3517,
21,
63,
698,
480,
1955,
401,
4513,
14,
18362,
395,
267,
2851,
26,
3517,
21,
63,
698,
480,
633,
401,
4513,
14,
18362,
395,
272,
3828,
199,
199,
3,
9812,
2402,
1504,
2943,
370,
506,
3247,
4799,
314,
2381,
3053,
63,
18555,
63,
12767,
199,
3,
4260,
12,
1314,
1077,
1395,
282,
3414,
402,
7795,
13,
1053,
8013,
12,
199,
3,
1924,
3035,
314,
2870,
12,
18947,
492,
931,
367,
314,
901,
1021,
12,
199,
3,
436,
901,
536,
12,
367,
1924,
3537,
901,
730,
14,
199,
2911,
63,
955,
275,
2519,
8,
1751,
12,
298,
11518,
63,
18555,
63,
12767,
401,
3073,
199,
509,
901,
63,
344,
12,
901,
63,
515,
12,
901,
63,
354,
315,
2402,
63,
955,
26,
272,
340,
901,
63,
344,
315,
24221,
654,
26,
267,
2329,
275,
298,
998,
450,
83,
367,
901,
450,
83,
315,
2381,
3053,
63,
18555,
63,
12767,
2575,
3495,
2,
267,
746,
11897,
8,
1508,
450,
334,
698,
63,
344,
12,
901,
63,
354,
430,
272,
24221,
654,
59,
698,
63,
344,
61,
275,
492,
63,
19404,
63,
515,
8,
698,
63,
515,
9,
272,
26149,
654,
847,
3666,
698,
63,
344,
12,
12561,
698,
63,
354,
1826,
9,
199,
199,
3,
20046,
370,
3432,
1325,
367,
11114,
446,
14292,
282,
3414,
402,
6342,
12,
199,
3,
1924,
543,
282,
901,
2870,
465,
1126,
3432,
12,
436,
282,
18947,
931,
370,
314,
3537,
199,
3,
3938,
1021,
370,
675,
367,
314,
5226,
1824,
901,
14,
199,
2911,
63,
8583,
275,
2519,
8,
1751,
12,
298,
11518,
63,
18555,
63,
9845,
2970,
51,
401,
3073,
199,
509,
901,
63,
344,
12,
3938,
63,
515,
315,
2402,
63,
8583,
26,
272,
340,
901
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
3351,
14,
9975,
492,
9496,
2506,
3339,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
562,
4348,
290,
1132,
14,
2190,
492,
2202,
199,
504,
562,
4348,
290,
1132,
14,
1018,
14,
3351,
492,
11740,
5446,
3926,
3339,
199,
504,
562,
4348,
290,
1132,
14,
1208,
14,
646,
316,
492,
492,
63,
19404,
63,
515,
421,
199,
3,
22296,
367,
1006,
2808,
901,
2943,
14,
199,
3876,
275,
413,
199,
3876,
28591,
275,
499,
199,
10089,
275,
650,
199,
8936,
15694,
275,
841,
199,
8936,
15694,
63,
21894,
906,
275,
959,
199,
4859,
275,
1227,
199,
4859,
63,
21894,
906,
275,
1520,
199,
19662,
2090,
63,
21894,
906,
275,
1695,
199,
3817,
275,
1749,
199,
5390,
275,
1616,
199,
5390,
63,
4961,
275,
4119,
199,
40,
22436,
275,
3144,
199,
9190,
275,
4944,
199,
2632,
275,
4329,
199,
1649,
34,
275,
4114,
199,
199,
3,
23923,
367,
1006,
2808,
901,
2943,
14,
199,
14546,
275,
334,
272,
334,
3876,
12,
3824,
7200,
1004,
1318,
8150,
272,
334,
3876,
28591,
12,
3824,
3947,
1004,
1318,
8150,
272,
334,
10089,
12,
3824,
7035,
8150,
272,
334,
9190,
12,
3824,
3259,
8150,
272,
334,
2632,
12,
3824,
2632,
8150,
272,
334,
8936,
15694,
12,
3824,
1799,
5689,
8150,
272,
334,
8936,
15694,
63,
21894,
906,
12,
3824,
1799,
17193,
8150,
272,
334,
4859,
12,
3824,
11070,
3224,
8150,
272,
334,
4859,
63,
21894,
906,
12,
3824,
3947,
3504,
8150,
272,
334,
19662,
2090,
63,
21894,
906,
12,
3824,
16065,
15766,
8150,
272,
334,
3817,
12,
3824,
1173,
5802,
8150,
272,
334,
5390,
12,
3824,
2506,
8150,
272,
334,
5390,
63,
4961,
12,
3824,
2506,
15,
521,
8150,
272,
334,
1649,
34,
12,
3824,
2506,
402,
21036,
8150,
272,
334,
40,
22436,
12,
3824,
14983,
8150,
199,
9,
199,
199,
3,
5024,
3992,
367,
1006,
2808,
901,
2943,
14,
199,
13748,
275,
469,
272,
11951,
26,
4513,
14,
2183,
12,
272,
11951,
28591,
26,
4513,
14,
2183,
12,
272,
32320,
26,
4513,
14,
16577,
12,
272,
17654,
15694,
26,
4513,
14,
5036,
12,
272,
17654,
15694,
63,
21894,
906,
26,
4513,
14,
8433,
15792,
12,
272,
10468,
26,
4513,
14,
15792,
12,
272,
10468,
63,
21894,
906,
26,
4513,
14,
8433,
15792,
12,
272,
820,
1554,
2090,
63,
21894,
906,
26,
4513,
14,
15792,
12,
272,
13024,
26,
4513,
14,
23252,
12,
272,
30131,
26,
4513,
14,
14071,
12,
272,
30131,
63,
4961,
26,
4513,
14,
4626,
12,
272,
3506,
34,
26,
4513,
14,
14071,
12,
272,
869,
22436,
26,
4513,
14,
2183,
12,
272,
18122,
26,
4513,
14,
13019,
12,
272,
2851,
26,
4513,
14,
17363,
12,
199,
93,
199,
199,
3,
16905,
83,
367,
901,
2943,
2382,
282,
4539,
9096,
3938,
365,
1415,
14,
199,
9845,
2970,
51,
275,
469,
272,
11951,
28591,
26,
4513,
14,
1872,
6789,
12,
272,
17654,
15694,
63,
21894,
906,
26,
4513,
14,
26366,
32331,
12,
272,
820,
1554,
2090,
63,
21894,
906,
26,
4513,
14,
16065,
5446,
12,
272,
30131,
26,
9496,
2506,
3339,
12,
272,
30131,
63,
4961,
26,
11740,
5446,
3926,
3339,
12,
272,
3506,
34,
26,
9496,
2506,
3339,
12,
272,
869,
22436,
26,
4513,
14,
25419,
12,
199,
93,
199,
199,
3,
6601,
5922,
1572,
780,
402,
901,
2943,
14,
199,
16236,
275,
334,
8936,
15694,
12,
10468,
12,
820,
1554,
2090,
63,
21894,
906,
9,
199,
6521,
654,
275,
334,
5390,
12,
30131,
63,
4961,
12,
3506,
34,
9,
199,
21894,
906,
275,
334,
8936,
15694,
63,
21894,
906,
12,
10468,
63,
21894,
906,
9,
199,
199,
3,
4163,
21,
16905,
83,
199,
1360,
21,
63,
698,
275,
2400,
536,
12,
1300,
26,
730,
8,
495,
11986,
395,
334,
1095,
4706,
2420,
1210,
63,
466,
582,
536,
1552,
199,
692,
2519,
8,
1751,
12,
298,
11518,
63,
4701,
63,
4943,
21,
401,
756,
304,
272,
644,
998,
2970,
51,
14,
873,
2561,
267,
30131,
26,
3517,
21,
63,
698,
480,
602,
401,
4513,
14,
2506,
3205,
395,
267,
30131,
63,
4961,
26,
3517,
21,
63,
698,
480,
2083,
401,
4513,
14,
3926,
3205,
395,
267,
3506,
34,
26,
3517,
21,
63,
698,
480,
602,
401,
4513,
14,
2506,
3205,
395,
267,
32320,
26,
3517,
21,
63,
698,
480,
2123,
401,
4513,
14,
18362,
395,
267,
18122,
26,
3517,
21,
63,
698,
480,
1955,
401,
4513,
14,
18362,
395,
267,
2851,
26,
3517,
21,
63,
698,
480,
633,
401,
4513,
14,
18362,
395,
272,
3828,
199,
199,
3,
9812,
2402,
1504,
2943,
370,
506,
3247,
4799,
314,
2381,
3053,
63,
18555,
63,
12767,
199,
3,
4260,
12,
1314,
1077,
1395,
282,
3414,
402,
7795,
13,
1053,
8013,
12,
199,
3,
1924,
3035,
314,
2870,
12,
18947,
492,
931,
367,
314,
901,
1021,
12,
199,
3,
436,
901,
536,
12,
367,
1924,
3537,
901,
730,
14,
199,
2911,
63,
955,
275,
2519,
8,
1751,
12,
298,
11518,
63,
18555,
63,
12767,
401,
3073,
199,
509,
901,
63,
344,
12,
901,
63,
515,
12,
901,
63,
354,
315,
2402,
63,
955,
26,
272,
340,
901,
63,
344,
315,
24221,
654,
26,
267,
2329,
275,
298,
998,
450,
83,
367,
901,
450,
83,
315,
2381,
3053,
63,
18555,
63,
12767,
2575,
3495,
2,
267,
746,
11897,
8,
1508,
450,
334,
698,
63,
344,
12,
901,
63,
354,
430,
272,
24221,
654,
59,
698,
63,
344,
61,
275,
492,
63,
19404,
63,
515,
8,
698,
63,
515,
9,
272,
26149,
654,
847,
3666,
698,
63,
344,
12,
12561,
698,
63,
354,
1826,
9,
199,
199,
3,
20046,
370,
3432,
1325,
367,
11114,
446,
14292,
282,
3414,
402,
6342,
12,
199,
3,
1924,
543,
282,
901,
2870,
465,
1126,
3432,
12,
436,
282,
18947,
931,
370,
314,
3537,
199,
3,
3938,
1021,
370,
675,
367,
314,
5226,
1824,
901,
14,
199,
2911,
63,
8583,
275,
2519,
8,
1751,
12,
298,
11518,
63,
18555,
63,
9845,
2970,
51,
401,
3073,
199,
509,
901,
63,
344,
12,
3938,
63,
515,
315,
2402,
63,
8583,
26,
272,
340,
901,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
MonamAgarwal/final
|
GTG/backends/generictomboy.py
|
1
|
24956
|
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Getting Things GNOME! - a personal organizer for the GNOME desktop
# Copyright (c) 2008-2013 - Lionel Dricot & Bertrand Rousseau
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
'''
Contains the Backend class for both Tomboy and Gnote
'''
# Note: To introspect tomboy, execute:
# qdbus org.gnome.Tomboy /org/gnome/Tomboy/RemoteControl
import os
import threading
import uuid
import dbus
import datetime
import unicodedata
from GTG.tools.testingmode import TestingMode
from GTG.tools.borg import Borg
from GTG.backends.genericbackend import GenericBackend
from GTG.backends.backendsignals import BackendSignals
from GTG.backends.syncengine import SyncEngine, SyncMeme
from GTG.tools.logger import Log
from GTG.tools.watchdog import Watchdog
from GTG.tools.interruptible import interruptible
from GTG.tools.tags import extract_tags_from_text
class GenericTomboy(GenericBackend):
'''Backend class for Tomboy/Gnote'''
###############################################################################
### Backend standard methods ##################################################
###############################################################################
def __init__(self, parameters):
"""
See GenericBackend for an explanation of this function.
"""
super(GenericTomboy, self).__init__(parameters)
# loading the saved state of the synchronization, if any
self.data_path = os.path.join('backends/tomboy/',
"sync_engine-" + self.get_id())
self.sync_engine = self._load_pickled_file(self.data_path,
SyncEngine())
# if the backend is being tested, we connect to a different DBus
# interface to avoid clashing with a running instance of Tomboy
if TestingMode().get_testing_mode():
# just used for testing purposes
self.BUS_ADDRESS = \
self._parameters["use this fake connection instead"]
else:
self.BUS_ADDRESS = self._BUS_ADDRESS
# we let some time pass before considering a tomboy task for importing,
# as the user may still be editing it. Here, we store the Timer objects
# that will execute after some time after each tomboy signal.
# NOTE: I'm not sure if this is the case anymore (but it shouldn't hurt
# anyway). (invernizzi)
self._tomboy_setting_timers = {}
def initialize(self):
'''
See GenericBackend for an explanation of this function.
Connects to the session bus and sets the callbacks for bus signals
'''
super(GenericTomboy, self).initialize()
with self.DbusWatchdog(self):
bus = dbus.SessionBus()
bus.add_signal_receiver(self.on_note_saved,
dbus_interface=self.BUS_ADDRESS[2],
signal_name="NoteSaved")
bus.add_signal_receiver(self.on_note_deleted,
dbus_interface=self.BUS_ADDRESS[2],
signal_name="NoteDeleted")
@interruptible
def start_get_tasks(self):
'''
See GenericBackend for an explanation of this function.
Gets all the notes from Tomboy and sees if they must be added in GTG
(and, if so, it adds them).
'''
tomboy_notes = []
with self.TomboyConnection(self, *self.BUS_ADDRESS) as tomboy:
with self.DbusWatchdog(self):
tomboy_notes = [note_id for note_id in
tomboy.ListAllNotes()]
# adding the new ones
for note in tomboy_notes:
self.cancellation_point()
self._process_tomboy_note(note)
# checking if some notes have been deleted while GTG was not running
stored_notes_ids = self.sync_engine.get_all_remote()
for note in set(stored_notes_ids).difference(set(tomboy_notes)):
self.on_note_deleted(note, None)
def save_state(self):
'''Saves the state of the synchronization'''
self._store_pickled_file(self.data_path, self.sync_engine)
def quit(self, disable=False):
'''
See GenericBackend for an explanation of this function.
'''
def quit_thread():
while True:
try:
[key, timer] = \
next(iter(self._tomboy_setting_timers.items()))
except StopIteration:
break
timer.cancel()
del self._tomboy_setting_timers[key]
threading.Thread(target=quit_thread).start()
super(GenericTomboy, self).quit(disable)
###############################################################################
### Something got removed #####################################################
###############################################################################
@interruptible
def on_note_deleted(self, note, something):
'''
Callback, executed when a tomboy note is deleted.
Deletes the related GTG task.
@param note: the id of the Tomboy note
@param something: not used, here for signal callback compatibility
'''
with self.datastore.get_backend_mutex():
self.cancellation_point()
try:
tid = self.sync_engine.get_local_id(note)
except KeyError:
return
if self.datastore.has_task(tid):
self.datastore.request_task_deletion(tid)
self.break_relationship(remote_id=note)
@interruptible
def remove_task(self, tid):
'''
See GenericBackend for an explanation of this function.
'''
with self.datastore.get_backend_mutex():
self.cancellation_point()
try:
note = self.sync_engine.get_remote_id(tid)
except KeyError:
return
with self.TomboyConnection(self, *self.BUS_ADDRESS) as tomboy:
with self.DbusWatchdog(self):
if tomboy.NoteExists(note):
tomboy.DeleteNote(note)
self.break_relationship(local_id=tid)
def _exec_lost_syncability(self, tid, note):
'''
Executed when a relationship between tasks loses its syncability
property. See SyncEngine for an explanation of that.
This function finds out which object (task/note) is the original one
and which is the copy, and deletes the copy.
@param tid: a GTG task tid
@param note: a tomboy note id
'''
self.cancellation_point()
meme = self.sync_engine.get_meme_from_remote_id(note)
# First of all, the relationship is lost
self.sync_engine.break_relationship(remote_id=note)
if meme.get_origin() == "GTG":
with self.TomboyConnection(self, *self.BUS_ADDRESS) as tomboy:
with self.DbusWatchdog(self):
tomboy.DeleteNote(note)
else:
self.datastore.request_task_deletion(tid)
###############################################################################
### Process tasks #############################################################
###############################################################################
def _process_tomboy_note(self, note):
'''
Given a tomboy note, finds out if it must be synced to a GTG note and,
if so, it carries out the synchronization (by creating or updating a
GTG task, or deleting itself if the related task has been deleted)
@param note: a Tomboy note id
'''
with self.datastore.get_backend_mutex():
self.cancellation_point()
is_syncable = self._tomboy_note_is_syncable(note)
has_task = self.datastore.has_task
note_exists = self._tomboy_note_exists
with self.DbusWatchdog(self):
action, tid = self.sync_engine.analyze_remote_id(note,
has_task,
note_exists,
is_syncable)
Log.debug("processing tomboy (%s, %s)" % (action, is_syncable))
if action == SyncEngine.ADD:
tid = str(uuid.uuid4())
task = self.datastore.task_factory(tid)
self._populate_task(task, note)
modified_for = self.get_modified_for_note(note)
self.record_relationship(local_id=tid,
remote_id=note,
meme=SyncMeme(task.get_modified(),
modified_for,
self.get_id()))
self.datastore.push_task(task)
elif action == SyncEngine.UPDATE:
task = self.datastore.get_task(tid)
meme = self.sync_engine.get_meme_from_remote_id(note)
newest = meme.which_is_newest(task.get_modified(),
self.get_modified_for_note(note))
if newest == "remote":
self._populate_task(task, note)
meme.set_local_last_modified(task.get_modified())
meme.set_remote_last_modified(
self.get_modified_for_note(note))
self.save_state()
elif action == SyncEngine.REMOVE:
with self.TomboyConnection(self, *self.BUS_ADDRESS) as tomboy:
with self.DbusWatchdog(self):
tomboy.DeleteNote(note)
try:
self.sync_engine.break_relationship(remote_id=note)
except KeyError:
pass
elif action == SyncEngine.LOST_SYNCABILITY:
self._exec_lost_syncability(tid, note)
@interruptible
def set_task(self, task):
'''
See GenericBackend for an explanation of this function.
'''
self.cancellation_point()
is_syncable = self._gtg_task_is_syncable_per_attached_tags(task)
tid = task.get_id()
with self.datastore.get_backend_mutex():
with self.TomboyConnection(self, *self.BUS_ADDRESS) as tomboy:
has_task = self.datastore.has_task
has_note = tomboy.NoteExists
can_sync = is_syncable
with self.DbusWatchdog(self):
action, note = self.sync_engine.analyze_local_id(tid,
has_task,
has_note,
can_sync)
Log.debug("processing gtg (%s, %d)" % (action, is_syncable))
if action == SyncEngine.ADD:
# GTG allows multiple tasks with the same name,
# Tomboy doesn't. we need to handle the renaming
# manually
title = task.get_title()
duplicate_counter = 1
with self.DbusWatchdog(self):
note = tomboy.CreateNamedNote(title)
while note == "":
duplicate_counter += 1
note = tomboy.CreateNamedNote(title + "(%d)" %
duplicate_counter)
if duplicate_counter != 1:
# if we needed to rename, we have to rename also
# the gtg task
task.set_title(title + " (%d)" % duplicate_counter)
self._populate_note(note, task)
self.record_relationship(
local_id=tid, remote_id=note,
meme=SyncMeme(task.get_modified(),
self.get_modified_for_note(note),
"GTG"))
elif action == SyncEngine.UPDATE:
meme = self.sync_engine.get_meme_from_local_id(
task.get_id())
modified_for = self.get_modified_for_note(note)
newest = meme.which_is_newest(task.get_modified(),
modified_for)
if newest == "local":
self._populate_note(note, task)
meme.set_local_last_modified(task.get_modified())
meme.set_remote_last_modified(
self.get_modified_for_note(note))
self.save_state()
elif action == SyncEngine.REMOVE:
self.datastore.request_task_deletion(tid)
try:
self.sync_engine.break_relationship(local_id=tid)
self.save_state()
except KeyError:
pass
elif action == SyncEngine.LOST_SYNCABILITY:
self._exec_lost_syncability(tid, note)
###############################################################################
### Helper methods ############################################################
###############################################################################
@interruptible
def on_note_saved(self, note):
'''
Callback, executed when a tomboy note is saved by Tomboy itself.
Updates the related GTG task (or creates one, if necessary).
@param note: the id of the Tomboy note
'''
self.cancellation_point()
# NOTE: we let some seconds pass before executing the real callback, as
# the editing of the Tomboy note may still be in progress
@interruptible
def _execute_on_note_saved(self, note):
self.cancellation_point()
try:
del self._tomboy_setting_timers[note]
except:
pass
self._process_tomboy_note(note)
self.save_state()
try:
self._tomboy_setting_timers[note].cancel()
except KeyError:
pass
finally:
timer = threading.Timer(5, _execute_on_note_saved,
args=(self, note))
self._tomboy_setting_timers[note] = timer
timer.start()
def _tomboy_note_is_syncable(self, note):
'''
Returns True if this tomboy note should be synced into GTG tasks.
@param note: the note id
@returns Boolean
'''
attached_tags = self.get_attached_tags()
if GenericBackend.ALLTASKS_TAG in attached_tags:
return True
with self.TomboyConnection(self, *self.BUS_ADDRESS) as tomboy:
with self.DbusWatchdog(self):
content = tomboy.GetNoteContents(note)
syncable = False
for tag in attached_tags:
try:
content.index(tag)
syncable = True
break
except ValueError:
pass
return syncable
def _tomboy_note_exists(self, note):
'''
Returns True if a tomboy note exists with the given id.
@param note: the note id
@returns Boolean
'''
with self.TomboyConnection(self, *self.BUS_ADDRESS) as tomboy:
with self.DbusWatchdog(self):
return tomboy.NoteExists(note)
def get_modified_for_note(self, note):
'''
Returns the modification time for the given note id.
@param note: the note id
@returns datetime.datetime
'''
with self.TomboyConnection(self, *self.BUS_ADDRESS) as tomboy:
with self.DbusWatchdog(self):
return datetime.datetime.fromtimestamp(
tomboy.GetNoteChangeDate(note))
def _tomboy_split_title_and_text(self, content):
'''
Tomboy does not have a "getTitle" and "getText" functions to get the
title and the text of a note separately. Instead, it has a getContent
function, that returns both of them.
This function splits up the output of getContent into a title string
and a text string.
@param content: a string, the result of a getContent call
@returns list: a list composed by [title, text]
'''
try:
end_of_title = content.index('\n')
except ValueError:
return content, str("")
title = content[: end_of_title]
if len(content) > end_of_title:
return title, content[end_of_title + 1:]
else:
return title, str("")
def _populate_task(self, task, note):
'''
Copies the content of a Tomboy note into a task.
@param task: a GTG Task
@param note: a Tomboy note
'''
# add tags objects (it's not enough to have @tag in the text to add a
# tag
with self.TomboyConnection(self, *self.BUS_ADDRESS) as tomboy:
with self.DbusWatchdog(self):
content = tomboy.GetNoteContents(note)
# update the tags list
task.set_only_these_tags(extract_tags_from_text(content))
# extract title and text
[title, text] = self._tomboy_split_title_and_text(str(content))
# Tomboy speaks unicode, we don't
title = unicodedata.normalize('NFKD', title)
text = unicodedata.normalize('NFKD', text)
task.set_title(title)
task.set_text(text)
task.add_remote_id(self.get_id(), note)
def _populate_note(self, note, task):
'''
Copies the content of a task into a Tomboy note.
@param note: a Tomboy note
@param task: a GTG Task
'''
title = task.get_title()
with self.TomboyConnection(self, *self.BUS_ADDRESS) as tomboy:
with self.DbusWatchdog(self):
tomboy.SetNoteContents(note, title + '\n' +
task.get_excerpt(strip_tags=False))
def break_relationship(self, *args, **kwargs):
'''
Proxy method for SyncEngine.break_relationship, which also saves the
state of the synchronization.
'''
# tomboy passes Dbus.String objects, which are not pickable. We convert
# those to unicode
if "remote_id" in kwargs:
kwargs["remote_id"] = str(kwargs["remote_id"])
try:
self.sync_engine.break_relationship(*args, **kwargs)
# we try to save the state at each change in the sync_engine:
# it's slower, but it should avoid widespread task
# duplication
self.save_state()
except KeyError:
pass
def record_relationship(self, *args, **kwargs):
'''
Proxy method for SyncEngine.break_relationship, which also saves the
state of the synchronization.
'''
# tomboy passes Dbus.String objects, which are not pickable. We convert
# those to unicode
if "remote_id" in kwargs:
kwargs["remote_id"] = str(kwargs["remote_id"])
self.sync_engine.record_relationship(*args, **kwargs)
# we try to save the state at each change in the sync_engine:
# it's slower, but it should avoid widespread task
# duplication
self.save_state()
###############################################################################
### Connection handling #######################################################
###############################################################################
class TomboyConnection(Borg):
'''
TomboyConnection creates a connection to TOMBOY via DBus and
handles all the possible exceptions.
It is a class that can be used with a with statement.
Example::
with self.TomboyConnection(self, *self.BUS_ADDRESS) as tomboy:
#do something
'''
def __init__(self, backend, bus_name, bus_path, bus_interface):
'''
Sees if a TomboyConnection object already exists. If so, since we
are inheriting from a Borg object, the initialization already took
place.
If not, it tries to connect to Tomboy via Dbus. If the connection
is not possible, the user is notified about it.
@param backend: a reference to a Backend
@param bus_name: the DBus address of Tomboy
@param bus_path: the DBus path of Tomboy RemoteControl
@param bus_interface: the DBus address of Tomboy RemoteControl
'''
super(GenericTomboy.TomboyConnection, self).__init__()
if hasattr(self, "tomboy_connection_is_ok") and \
self.tomboy_connection_is_ok:
return
self.backend = backend
self.tomboy_connection_is_ok = True
with GenericTomboy.DbusWatchdog(backend):
bus = dbus.SessionBus()
try:
obj = bus.get_object(bus_name, bus_path)
self.tomboy = dbus.Interface(obj, bus_interface)
except dbus.DBusException:
self.tomboy_failed()
self.tomboy = None
def __enter__(self):
'''
Returns the Tomboy connection
@returns: dbus.Interface
'''
return self.tomboy
def __exit__(self, exception_type, value, traceback):
'''
Checks the state of the connection.
If something went wrong for the connection, notifies the user.
@param exception_type: the type of exception that occurred, or
None
@param value: the instance of the exception occurred, or None
@param traceback: the traceback of the error
@returns: False if some exception must be re-raised.
'''
if isinstance(value, dbus.DBusException) or \
not self.tomboy_connection_is_ok:
self.tomboy_failed()
return True
else:
return False
def tomboy_failed(self):
""" Handle failed tomboy connection.
Disable backend and show error in notification bar """
self.tomboy_connection_is_ok = False
BackendSignals().backend_failed(self.backend.get_id(),
BackendSignals.ERRNO_DBUS)
self.backend.quit(disable=True)
class DbusWatchdog(Watchdog):
'''
A simple watchdog to detect stale dbus connections
'''
def __init__(self, backend):
'''
Simple constructor, which sets _when_taking_too_long as the
function to run when the connection is taking too long.
@param backend: a Backend object
'''
self.backend = backend
super(GenericTomboy.DbusWatchdog, self).__init__(
3, self._when_taking_too_long)
def _when_taking_too_long(self):
'''
Function that is executed when the Dbus connection seems to be
hanging. It disables the backend and signals the error to the user.
'''
Log.error("Dbus connection is taking too long for the Tomboy/Gnote"
"backend!")
BackendSignals().backend_failed(self.backend.get_id(),
BackendSignals.ERRNO_DBUS)
self.backend.quit(disable=True)
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
13722,
199,
3,
20703,
3868,
780,
598,
2826,
3635,
1,
446,
282,
25994,
20765,
1793,
367,
314,
598,
2826,
3635,
19763,
199,
3,
1898,
334,
67,
9,
9079,
13,
6965,
446,
491,
1636,
352,
577,
322,
331,
84,
1253,
23207,
454,
460,
820,
1785,
261,
3844,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
199,
3,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
199,
3,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
199,
3,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
13722,
199,
199,
2344,
199,
6906,
314,
25674,
1021,
367,
3865,
21644,
656,
89,
436,
598,
4610,
199,
2344,
199,
3,
3390,
26,
4005,
1109,
21302,
370,
77,
656,
89,
12,
5341,
26,
199,
3,
259,
1894,
17066,
5981,
14,
784,
1377,
14,
52,
676,
656,
89,
1182,
1308,
15,
784,
1377,
15,
52,
676,
656,
89,
15,
6713,
3717,
199,
199,
646,
747,
199,
646,
5796,
199,
646,
5377,
199,
646,
21140,
199,
646,
2197,
199,
646,
23128,
199,
199,
504,
598,
6332,
14,
2537,
14,
4776,
632,
492,
11940,
1385,
199,
504,
598,
6332,
14,
2537,
14,
66,
1308,
492,
699,
1308,
199,
504,
598,
6332,
14,
7765,
14,
6767,
4620,
492,
8307,
8447,
199,
504,
598,
6332,
14,
7765,
14,
4620,
10458,
492,
25674,
28536,
199,
504,
598,
6332,
14,
7765,
14,
5186,
3908,
492,
22407,
8524,
12,
22407,
1352,
278,
199,
504,
598,
6332,
14,
2537,
14,
2921,
492,
5297,
199,
504,
598,
6332,
14,
2537,
14,
6821,
13889,
492,
29075,
13889,
199,
504,
598,
6332,
14,
2537,
14,
1058,
5505,
21602,
492,
1640,
5505,
21602,
199,
504,
598,
6332,
14,
2537,
14,
2969,
492,
5536,
63,
2969,
63,
504,
63,
505,
421,
199,
533,
8307,
52,
676,
656,
89,
8,
9417,
8447,
304,
272,
1449,
8447,
1021,
367,
21644,
656,
89,
15,
39,
4610,
2344,
199,
199,
11490,
199,
5680,
25674,
4465,
3102,
20286,
309,
199,
11490,
272,
347,
636,
826,
721,
277,
12,
2633,
304,
267,
408,
267,
1666,
8307,
8447,
367,
376,
17531,
402,
642,
805,
14,
267,
408,
267,
1613,
8,
9417,
52,
676,
656,
89,
12,
291,
2843,
826,
721,
3214,
9,
267,
327,
8697,
314,
6290,
1174,
402,
314,
29509,
12,
340,
1263,
267,
291,
14,
576,
63,
515,
275,
747,
14,
515,
14,
904,
360,
7765,
15,
3151,
656,
89,
3678,
4228,
298,
5186,
63,
3908,
23245,
435,
291,
14,
362,
63,
344,
1012,
267,
291,
14,
5186,
63,
3908,
275,
291,
423,
912,
63,
20428,
63,
493,
8,
277,
14,
576,
63,
515,
12,
8962,
22407,
8524,
1012,
267,
327,
340,
314,
4865,
365,
3769,
12470,
12,
781,
4907,
370,
282,
3365,
6249,
527,
267,
327,
3217,
370,
5126,
30109,
316,
543,
282,
3879,
1256,
402,
21644,
656,
89,
267,
340,
11940,
1385,
1252,
362,
63,
4776,
63,
632,
837,
288,
327,
2951,
1202,
367,
5343,
12901,
288,
291,
14,
24753,
63,
12368,
275,
971,
355,
291,
423,
3214,
905,
1180,
642,
4026,
1950,
3140,
937,
267,
587,
26,
288,
291,
14,
24753,
63,
12368,
275,
291,
423,
24753,
63,
12368,
267,
327,
781,
4691,
2005,
900,
986,
2544,
11201,
316,
282,
370,
77,
656,
89,
2120,
367,
16306,
12,
267,
327,
465,
314,
922,
1443,
5139,
506,
20401,
652,
14,
11842,
12,
781,
3877,
314,
22287,
2251,
267,
327,
626,
911,
5341,
2410,
2005,
900,
2410,
1924,
370,
77,
656,
89,
4673,
14,
267,
327,
6944,
26,
473,
6704,
440,
3238,
340,
642,
365,
314,
1930,
20827,
334,
7911,
652,
9296,
1133,
394,
20471,
267,
327,
420,
15988,
680,
334,
262,
422,
78,
565,
16079,
9,
267,
291,
423,
3151,
656,
89,
63,
6031,
63,
27386,
275,
1052,
339,
347,
8265,
8,
277,
304,
267,
1449,
267,
1666,
8307,
8447,
367,
376,
17531,
402,
642,
805,
14,
267,
15175,
83,
370,
314,
2351,
10414,
436,
5951,
314,
13484,
367,
10414,
10166,
267,
1449,
267,
1613,
8,
9417,
52,
676,
656,
89,
12,
291,
680,
8489,
342,
267,
543,
291,
14,
36,
5610,
13978,
13889,
8,
277,
304,
288,
10414,
275,
21140,
14,
4434,
12106,
342,
288,
10414,
14,
525,
63,
4653,
63,
10244,
8,
277,
14,
265,
63,
4610,
63,
8420,
12,
2511,
21140,
63,
3266,
29,
277,
14,
24753,
63,
12368,
59,
18,
467,
2511,
4673,
63,
354,
628,
7443,
21969,
531,
288,
10414,
14,
525,
63,
4653,
63,
10244,
8,
277,
14,
265,
63,
4610,
63,
6062,
12,
2511,
21140,
63,
3266,
29,
277,
14,
24753,
63,
12368,
59,
18,
467,
2511,
4673,
63,
354,
628,
7443,
17735,
531,
339,
768,
1058,
5505,
21602,
272,
347,
1343,
63,
362,
63,
5054,
8,
277,
304,
267,
1449,
267,
1666,
8307,
8447,
367,
376,
17531,
402,
642,
805,
14,
267,
14509,
1006,
314,
12681,
687,
21644,
656,
89,
436,
542,
397,
340,
2985,
1471,
506,
3483,
315,
598,
6332,
267,
334,
460,
12,
340,
880,
12,
652,
9584,
3062,
680,
267,
1449,
267,
370,
77,
656,
89,
63,
5983,
275,
942,
267,
543,
291,
14,
52,
676,
656,
89,
3225,
8,
277,
12,
627,
277,
14,
24753,
63,
12368,
9,
465,
370,
77,
656,
89,
26,
288,
543,
291,
14,
36,
5610,
13978,
13889,
8,
277,
304,
355,
370,
77,
656,
89,
63,
5983,
275,
359,
4610,
63,
344,
367,
5317,
63,
344,
315,
1816,
370,
77,
656,
89,
14,
1296,
2422,
18685,
5106,
267,
327,
7791,
314,
892,
7869,
267,
367,
5317,
315,
370,
77,
656,
89,
63,
5983,
26,
288,
291
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
13722,
199,
3,
20703,
3868,
780,
598,
2826,
3635,
1,
446,
282,
25994,
20765,
1793,
367,
314,
598,
2826,
3635,
19763,
199,
3,
1898,
334,
67,
9,
9079,
13,
6965,
446,
491,
1636,
352,
577,
322,
331,
84,
1253,
23207,
454,
460,
820,
1785,
261,
3844,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
199,
3,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
199,
3,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
199,
3,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
13722,
199,
199,
2344,
199,
6906,
314,
25674,
1021,
367,
3865,
21644,
656,
89,
436,
598,
4610,
199,
2344,
199,
3,
3390,
26,
4005,
1109,
21302,
370,
77,
656,
89,
12,
5341,
26,
199,
3,
259,
1894,
17066,
5981,
14,
784,
1377,
14,
52,
676,
656,
89,
1182,
1308,
15,
784,
1377,
15,
52,
676,
656,
89,
15,
6713,
3717,
199,
199,
646,
747,
199,
646,
5796,
199,
646,
5377,
199,
646,
21140,
199,
646,
2197,
199,
646,
23128,
199,
199,
504,
598,
6332,
14,
2537,
14,
4776,
632,
492,
11940,
1385,
199,
504,
598,
6332,
14,
2537,
14,
66,
1308,
492,
699,
1308,
199,
504,
598,
6332,
14,
7765,
14,
6767,
4620,
492,
8307,
8447,
199,
504,
598,
6332,
14,
7765,
14,
4620,
10458,
492,
25674,
28536,
199,
504,
598,
6332,
14,
7765,
14,
5186,
3908,
492,
22407,
8524,
12,
22407,
1352,
278,
199,
504,
598,
6332,
14,
2537,
14,
2921,
492,
5297,
199,
504,
598,
6332,
14,
2537,
14,
6821,
13889,
492,
29075,
13889,
199,
504,
598,
6332,
14,
2537,
14,
1058,
5505,
21602,
492,
1640,
5505,
21602,
199,
504,
598,
6332,
14,
2537,
14,
2969,
492,
5536,
63,
2969,
63,
504,
63,
505,
421,
199,
533,
8307,
52,
676,
656,
89,
8,
9417,
8447,
304,
272,
1449,
8447,
1021,
367,
21644,
656,
89,
15,
39,
4610,
2344,
199,
199,
11490,
199,
5680,
25674,
4465,
3102,
20286,
309,
199,
11490,
272,
347,
636,
826,
721,
277,
12,
2633,
304,
267,
408,
267,
1666,
8307,
8447,
367,
376,
17531,
402,
642,
805,
14,
267,
408,
267,
1613,
8,
9417,
52,
676,
656,
89,
12,
291,
2843,
826,
721,
3214,
9,
267,
327,
8697,
314,
6290,
1174,
402,
314,
29509,
12,
340,
1263,
267,
291,
14,
576,
63,
515,
275,
747,
14,
515,
14,
904,
360,
7765,
15,
3151,
656,
89,
3678,
4228,
298,
5186,
63,
3908,
23245,
435,
291,
14,
362,
63,
344,
1012,
267,
291,
14,
5186,
63,
3908,
275,
291,
423,
912,
63,
20428,
63,
493,
8,
277,
14,
576,
63,
515,
12,
8962,
22407,
8524,
1012,
267,
327,
340,
314,
4865,
365,
3769,
12470,
12,
781,
4907,
370,
282,
3365,
6249,
527,
267,
327,
3217,
370,
5126,
30109,
316,
543,
282,
3879,
1256,
402,
21644,
656,
89,
267,
340,
11940,
1385,
1252,
362,
63,
4776,
63,
632,
837,
288,
327,
2951,
1202,
367,
5343,
12901,
288,
291,
14,
24753,
63,
12368,
275,
971,
355,
291,
423,
3214,
905,
1180,
642,
4026,
1950,
3140,
937,
267,
587,
26,
288,
291,
14,
24753,
63,
12368,
275,
291,
423,
24753,
63,
12368,
267,
327,
781,
4691,
2005,
900,
986,
2544,
11201,
316,
282,
370,
77,
656,
89,
2120,
367,
16306,
12,
267,
327,
465,
314,
922,
1443,
5139,
506,
20401,
652,
14,
11842,
12,
781,
3877,
314,
22287,
2251,
267,
327,
626,
911,
5341,
2410,
2005,
900,
2410,
1924,
370,
77,
656,
89,
4673,
14,
267,
327,
6944,
26,
473,
6704,
440,
3238,
340,
642,
365,
314,
1930,
20827,
334,
7911,
652,
9296,
1133,
394,
20471,
267,
327,
420,
15988,
680,
334,
262,
422,
78,
565,
16079,
9,
267,
291,
423,
3151,
656,
89,
63,
6031,
63,
27386,
275,
1052,
339,
347,
8265,
8,
277,
304,
267,
1449,
267,
1666,
8307,
8447,
367,
376,
17531,
402,
642,
805,
14,
267,
15175,
83,
370,
314,
2351,
10414,
436,
5951,
314,
13484,
367,
10414,
10166,
267,
1449,
267,
1613,
8,
9417,
52,
676,
656,
89,
12,
291,
680,
8489,
342,
267,
543,
291,
14,
36,
5610,
13978,
13889,
8,
277,
304,
288,
10414,
275,
21140,
14,
4434,
12106,
342,
288,
10414,
14,
525,
63,
4653,
63,
10244,
8,
277,
14,
265,
63,
4610,
63,
8420,
12,
2511,
21140,
63,
3266,
29,
277,
14,
24753,
63,
12368,
59,
18,
467,
2511,
4673,
63,
354,
628,
7443,
21969,
531,
288,
10414,
14,
525,
63,
4653,
63,
10244,
8,
277,
14,
265,
63,
4610,
63,
6062,
12,
2511,
21140,
63,
3266,
29,
277,
14,
24753,
63,
12368,
59,
18,
467,
2511,
4673,
63,
354,
628,
7443,
17735,
531,
339,
768,
1058,
5505,
21602,
272,
347,
1343,
63,
362,
63,
5054,
8,
277,
304,
267,
1449,
267,
1666,
8307,
8447,
367,
376,
17531,
402,
642,
805,
14,
267,
14509,
1006,
314,
12681,
687,
21644,
656,
89,
436,
542,
397,
340,
2985,
1471,
506,
3483,
315,
598,
6332,
267,
334,
460,
12,
340,
880,
12,
652,
9584,
3062,
680,
267,
1449,
267,
370,
77,
656,
89,
63,
5983,
275,
942,
267,
543,
291,
14,
52,
676,
656,
89,
3225,
8,
277,
12,
627,
277,
14,
24753,
63,
12368,
9,
465,
370,
77,
656,
89,
26,
288,
543,
291,
14,
36,
5610,
13978,
13889,
8,
277,
304,
355,
370,
77,
656,
89,
63,
5983,
275,
359,
4610,
63,
344,
367,
5317,
63,
344,
315,
1816,
370,
77,
656,
89,
14,
1296,
2422,
18685,
5106,
267,
327,
7791,
314,
892,
7869,
267,
367,
5317,
315,
370,
77,
656,
89,
63,
5983,
26,
288,
291,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
facetoe/i3pystatus
|
i3pystatus/pagerduty.py
|
3
|
2349
|
from i3pystatus import IntervalModule
from i3pystatus.core.util import internet, require, formatp
import pypd
__author__ = 'chestm007'
class PagerDuty(IntervalModule):
"""
Module to get the current incidents in PD
Requires `pypd`
Formatters:
* `{num_incidents}` - current number of incidents unresolved
* `{num_acknowledged_incidents}` - as it sounds
* `{num_triggered_incidents}` - number of unacknowledged incidents
Example:
.. code-block:: python
status.register(
'pagerduty',
api_key='mah_api_key',
user_id='LKJ19QW'
)
"""
settings = (
'format',
('api_key', 'pagerduty api key'),
('color', 'module text color'),
('interval', 'refresh interval'),
('user_id', 'your pagerduty user id, shows up in the url when viewing your profile '
'`https://subdomain.pagerduty.com/users/<user_id>`')
)
required = ['api_key']
format = '{num_triggered_incidents} triggered {num_acknowledged_incidents} acknowledged'
api_key = None
color = '#AA0000'
interval = 60
user_id = None
api_search_dict = dict(statuses=['triggered', 'acknowledged'])
num_acknowledged_incidents = None
num_triggered_incidents = None
num_incidents = None
def init(self):
pypd.api_key = self.api_key
if self.user_id:
self.api_search_dict['user_ids'] = [self.user_id]
@require(internet)
def run(self):
pd_incidents = pypd.Incident.find(**self.api_search_dict)
incidents = {
'acknowledged': [],
'triggered': [],
'all': []
}
for incident in pd_incidents:
incidents['all'].append(incident)
status = incident.get('status')
if status == 'acknowledged':
incidents['acknowledged'].append(incident)
elif status == 'triggered':
incidents['triggered'].append(incident)
self.num_acknowledged_incidents = len(incidents.get('acknowledged'))
self.num_triggered_incidents = len(incidents.get('triggered'))
self.num_incidents = len(incidents.get('all'))
self.output = dict(
full_text=formatp(self.format, **vars(self)),
color=self.color
)
|
mit
|
[
504,
284,
19,
647,
1205,
492,
18766,
2377,
199,
504,
284,
19,
647,
1205,
14,
1018,
14,
1974,
492,
21408,
12,
4409,
12,
1475,
80,
199,
199,
646,
1134,
8961,
199,
199,
363,
2502,
363,
275,
283,
595,
270,
77,
8255,
7,
421,
199,
533,
510,
1456,
36,
19974,
8,
8227,
2377,
304,
272,
408,
272,
5673,
370,
664,
314,
1453,
315,
12689,
83,
315,
510,
36,
272,
15127,
658,
647,
8961,
64,
339,
9701,
878,
26,
339,
627,
658,
91,
1507,
63,
29811,
83,
23485,
446,
1453,
1329,
402,
315,
12689,
83,
625,
13697,
272,
627,
658,
91,
1507,
63,
564,
28609,
3046,
63,
29811,
83,
23485,
446,
465,
652,
20453,
83,
272,
627,
658,
91,
1507,
63,
21142,
63,
29811,
83,
23485,
446,
1329,
402,
625,
564,
28609,
3046,
315,
12689,
83,
339,
5679,
26,
339,
2508,
1233,
13,
1457,
447,
2366,
398,
2004,
14,
2683,
8,
288,
283,
21219,
68,
19974,
297,
288,
2986,
63,
498,
534,
391,
72,
63,
1246,
63,
498,
297,
288,
922,
63,
344,
534,
44,
43,
42,
1167,
49,
55,
7,
267,
776,
272,
408,
339,
2202,
275,
334,
267,
283,
908,
297,
267,
661,
1246,
63,
498,
297,
283,
21219,
68,
19974,
2986,
790,
659,
267,
661,
2326,
297,
283,
578,
1318,
3164,
659,
267,
661,
4284,
297,
283,
6635,
6252,
659,
267,
661,
751,
63,
344,
297,
283,
12695,
26581,
68,
19974,
922,
1305,
12,
13703,
1536,
315,
314,
1166,
1380,
2455,
316,
2195,
4690,
283,
490,
26144,
2859,
921,
22806,
14,
21219,
68,
19974,
14,
957,
15,
3707,
8316,
751,
63,
344,
8637,
358,
272,
776,
339,
1415,
275,
788,
1246,
63,
498,
418,
339,
1475,
275,
5041,
1507,
63,
21142,
63,
29811,
83,
93,
15572,
221,
469,
1507,
63,
564,
28609,
3046,
63,
29811,
83,
93,
19807,
28609,
3046,
7,
272,
2986,
63,
498,
275,
488,
272,
3164,
275,
3943,
2276,
993,
7,
272,
6252,
275,
5212,
272,
922,
63,
344,
275,
488,
272,
2986,
63,
1733,
63,
807,
275,
1211,
8,
17084,
2968,
21142,
297,
283,
564,
28609,
3046,
1105,
339,
1967,
63,
564,
28609,
3046,
63,
29811,
83,
275,
488,
272,
1967,
63,
21142,
63,
29811,
83,
275,
488,
272,
1967,
63,
29811,
83,
275,
488,
339,
347,
4205,
8,
277,
304,
267,
1134,
8961,
14,
1246,
63,
498,
275,
291,
14,
1246,
63,
498,
267,
340,
291,
14,
751,
63,
344,
26,
288,
291,
14,
1246,
63,
1733,
63,
807,
459,
751,
63,
1580,
418,
275,
359,
277,
14,
751,
63,
344,
61,
339,
768,
4365,
8,
4901,
9,
272,
347,
1255,
8,
277,
304,
267,
6454,
63,
29811,
83,
275,
1134,
8961,
14,
607,
12689,
14,
1623,
3682,
277,
14,
1246,
63,
1733,
63,
807,
9,
398,
315,
12689,
83,
275,
469,
288,
283,
564,
28609,
3046,
356,
990,
288,
283,
21142,
356,
990,
288,
283,
452,
356,
942,
267,
789,
267,
367,
315,
12689,
315,
6454,
63,
29811,
83,
26,
288,
315,
12689,
83,
459,
452,
2278,
740,
8,
29811,
9,
288,
2004,
275,
315,
12689,
14,
362,
360,
1205,
358,
288,
340,
2004,
508,
283,
564,
28609,
3046,
356,
355,
315,
12689,
83,
459,
564,
28609,
3046,
2278,
740,
8,
29811,
9,
288,
916,
2004,
508,
283,
21142,
356,
355,
315,
12689,
83,
459,
21142,
2278,
740,
8,
29811,
9,
267,
291,
14,
1507,
63,
564,
28609,
3046,
63,
29811,
83,
275,
822,
8,
29811,
83,
14,
362,
360,
564,
28609,
3046,
1333,
267,
291,
14,
1507,
63,
21142,
63,
29811,
83,
275,
822,
8,
29811,
83,
14,
362,
360,
21142,
1333,
267,
291,
14,
1507,
63,
29811,
83,
275,
822,
8,
29811,
83,
14,
362,
360,
452,
1333,
398,
291,
14,
1199,
275,
1211,
8,
288,
2615,
63,
505,
29,
908,
80,
8,
277,
14,
908,
12,
1011,
2936,
8,
277,
1826,
288,
3164,
29,
277,
14,
2326,
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
] |
[
284,
19,
647,
1205,
492,
18766,
2377,
199,
504,
284,
19,
647,
1205,
14,
1018,
14,
1974,
492,
21408,
12,
4409,
12,
1475,
80,
199,
199,
646,
1134,
8961,
199,
199,
363,
2502,
363,
275,
283,
595,
270,
77,
8255,
7,
421,
199,
533,
510,
1456,
36,
19974,
8,
8227,
2377,
304,
272,
408,
272,
5673,
370,
664,
314,
1453,
315,
12689,
83,
315,
510,
36,
272,
15127,
658,
647,
8961,
64,
339,
9701,
878,
26,
339,
627,
658,
91,
1507,
63,
29811,
83,
23485,
446,
1453,
1329,
402,
315,
12689,
83,
625,
13697,
272,
627,
658,
91,
1507,
63,
564,
28609,
3046,
63,
29811,
83,
23485,
446,
465,
652,
20453,
83,
272,
627,
658,
91,
1507,
63,
21142,
63,
29811,
83,
23485,
446,
1329,
402,
625,
564,
28609,
3046,
315,
12689,
83,
339,
5679,
26,
339,
2508,
1233,
13,
1457,
447,
2366,
398,
2004,
14,
2683,
8,
288,
283,
21219,
68,
19974,
297,
288,
2986,
63,
498,
534,
391,
72,
63,
1246,
63,
498,
297,
288,
922,
63,
344,
534,
44,
43,
42,
1167,
49,
55,
7,
267,
776,
272,
408,
339,
2202,
275,
334,
267,
283,
908,
297,
267,
661,
1246,
63,
498,
297,
283,
21219,
68,
19974,
2986,
790,
659,
267,
661,
2326,
297,
283,
578,
1318,
3164,
659,
267,
661,
4284,
297,
283,
6635,
6252,
659,
267,
661,
751,
63,
344,
297,
283,
12695,
26581,
68,
19974,
922,
1305,
12,
13703,
1536,
315,
314,
1166,
1380,
2455,
316,
2195,
4690,
283,
490,
26144,
2859,
921,
22806,
14,
21219,
68,
19974,
14,
957,
15,
3707,
8316,
751,
63,
344,
8637,
358,
272,
776,
339,
1415,
275,
788,
1246,
63,
498,
418,
339,
1475,
275,
5041,
1507,
63,
21142,
63,
29811,
83,
93,
15572,
221,
469,
1507,
63,
564,
28609,
3046,
63,
29811,
83,
93,
19807,
28609,
3046,
7,
272,
2986,
63,
498,
275,
488,
272,
3164,
275,
3943,
2276,
993,
7,
272,
6252,
275,
5212,
272,
922,
63,
344,
275,
488,
272,
2986,
63,
1733,
63,
807,
275,
1211,
8,
17084,
2968,
21142,
297,
283,
564,
28609,
3046,
1105,
339,
1967,
63,
564,
28609,
3046,
63,
29811,
83,
275,
488,
272,
1967,
63,
21142,
63,
29811,
83,
275,
488,
272,
1967,
63,
29811,
83,
275,
488,
339,
347,
4205,
8,
277,
304,
267,
1134,
8961,
14,
1246,
63,
498,
275,
291,
14,
1246,
63,
498,
267,
340,
291,
14,
751,
63,
344,
26,
288,
291,
14,
1246,
63,
1733,
63,
807,
459,
751,
63,
1580,
418,
275,
359,
277,
14,
751,
63,
344,
61,
339,
768,
4365,
8,
4901,
9,
272,
347,
1255,
8,
277,
304,
267,
6454,
63,
29811,
83,
275,
1134,
8961,
14,
607,
12689,
14,
1623,
3682,
277,
14,
1246,
63,
1733,
63,
807,
9,
398,
315,
12689,
83,
275,
469,
288,
283,
564,
28609,
3046,
356,
990,
288,
283,
21142,
356,
990,
288,
283,
452,
356,
942,
267,
789,
267,
367,
315,
12689,
315,
6454,
63,
29811,
83,
26,
288,
315,
12689,
83,
459,
452,
2278,
740,
8,
29811,
9,
288,
2004,
275,
315,
12689,
14,
362,
360,
1205,
358,
288,
340,
2004,
508,
283,
564,
28609,
3046,
356,
355,
315,
12689,
83,
459,
564,
28609,
3046,
2278,
740,
8,
29811,
9,
288,
916,
2004,
508,
283,
21142,
356,
355,
315,
12689,
83,
459,
21142,
2278,
740,
8,
29811,
9,
267,
291,
14,
1507,
63,
564,
28609,
3046,
63,
29811,
83,
275,
822,
8,
29811,
83,
14,
362,
360,
564,
28609,
3046,
1333,
267,
291,
14,
1507,
63,
21142,
63,
29811,
83,
275,
822,
8,
29811,
83,
14,
362,
360,
21142,
1333,
267,
291,
14,
1507,
63,
29811,
83,
275,
822,
8,
29811,
83,
14,
362,
360,
452,
1333,
398,
291,
14,
1199,
275,
1211,
8,
288,
2615,
63,
505,
29,
908,
80,
8,
277,
14,
908,
12,
1011,
2936,
8,
277,
1826,
288,
3164,
29,
277,
14,
2326,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
labcodes/django
|
tests/serializers/test_yaml.py
|
74
|
5567
|
import importlib
import unittest
from io import StringIO
from django.core import management, serializers
from django.core.serializers.base import DeserializationError
from django.test import SimpleTestCase, TestCase, TransactionTestCase
from .models import Author
from .tests import SerializersTestBase, SerializersTransactionTestBase
try:
import yaml
HAS_YAML = True
except ImportError:
HAS_YAML = False
YAML_IMPORT_ERROR_MESSAGE = r'No module named yaml'
class YamlImportModuleMock:
"""Provides a wrapped import_module function to simulate yaml ImportError
In order to run tests that verify the behavior of the YAML serializer
when run on a system that has yaml installed (like the django CI server),
mock import_module, so that it raises an ImportError when the yaml
serializer is being imported. The importlib.import_module() call is
being made in the serializers.register_serializer().
Refs: #12756
"""
def __init__(self):
self._import_module = importlib.import_module
def import_module(self, module_path):
if module_path == serializers.BUILTIN_SERIALIZERS['yaml']:
raise ImportError(YAML_IMPORT_ERROR_MESSAGE)
return self._import_module(module_path)
class NoYamlSerializerTestCase(SimpleTestCase):
"""Not having pyyaml installed provides a misleading error
Refs: #12756
"""
@classmethod
def setUpClass(cls):
"""Removes imported yaml and stubs importlib.import_module"""
super().setUpClass()
cls._import_module_mock = YamlImportModuleMock()
importlib.import_module = cls._import_module_mock.import_module
# clear out cached serializers to emulate yaml missing
serializers._serializers = {}
@classmethod
def tearDownClass(cls):
"""Puts yaml back if necessary"""
super().tearDownClass()
importlib.import_module = cls._import_module_mock._import_module
# clear out cached serializers to clean out BadSerializer instances
serializers._serializers = {}
def test_serializer_pyyaml_error_message(self):
"""Using yaml serializer without pyyaml raises ImportError"""
jane = Author(name="Jane")
with self.assertRaises(ImportError):
serializers.serialize("yaml", [jane])
def test_deserializer_pyyaml_error_message(self):
"""Using yaml deserializer without pyyaml raises ImportError"""
with self.assertRaises(ImportError):
serializers.deserialize("yaml", "")
def test_dumpdata_pyyaml_error_message(self):
"""Calling dumpdata produces an error when yaml package missing"""
with self.assertRaisesMessage(management.CommandError, YAML_IMPORT_ERROR_MESSAGE):
management.call_command('dumpdata', format='yaml')
@unittest.skipUnless(HAS_YAML, "No yaml library detected")
class YamlSerializerTestCase(SerializersTestBase, TestCase):
serializer_name = "yaml"
fwd_ref_str = """- fields:
headline: Forward references pose no problem
pub_date: 2006-06-16 15:00:00
categories: [1]
author: 1
pk: 1
model: serializers.article
- fields:
name: Reference
pk: 1
model: serializers.category
- fields:
name: Agnes
pk: 1
model: serializers.author"""
pkless_str = """- fields:
name: Reference
pk: null
model: serializers.category
- fields:
name: Non-fiction
model: serializers.category"""
mapping_ordering_str = """- model: serializers.article
pk: %(article_pk)s
fields:
author: %(author_pk)s
headline: Poker has no place on ESPN
pub_date: 2006-06-16 11:00:00
categories: [%(first_category_pk)s, %(second_category_pk)s]
meta_data: []
"""
@staticmethod
def _validate_output(serial_str):
try:
yaml.safe_load(StringIO(serial_str))
except Exception:
return False
else:
return True
@staticmethod
def _get_pk_values(serial_str):
ret_list = []
stream = StringIO(serial_str)
for obj_dict in yaml.safe_load(stream):
ret_list.append(obj_dict["pk"])
return ret_list
@staticmethod
def _get_field_values(serial_str, field_name):
ret_list = []
stream = StringIO(serial_str)
for obj_dict in yaml.safe_load(stream):
if "fields" in obj_dict and field_name in obj_dict["fields"]:
field_value = obj_dict["fields"][field_name]
# yaml.safe_load will return non-string objects for some
# of the fields we are interested in, this ensures that
# everything comes back as a string
if isinstance(field_value, str):
ret_list.append(field_value)
else:
ret_list.append(str(field_value))
return ret_list
def test_yaml_deserializer_exception(self):
with self.assertRaises(DeserializationError):
for obj in serializers.deserialize("yaml", "{"):
pass
@unittest.skipUnless(HAS_YAML, "No yaml library detected")
class YamlSerializerTransactionTestCase(SerializersTransactionTestBase, TransactionTestCase):
serializer_name = "yaml"
fwd_ref_str = """- fields:
headline: Forward references pose no problem
pub_date: 2006-06-16 15:00:00
categories: [1]
author: 1
pk: 1
model: serializers.article
- fields:
name: Reference
pk: 1
model: serializers.category
- fields:
name: Agnes
pk: 1
model: serializers.author"""
|
bsd-3-clause
|
[
646,
14802,
199,
646,
2882,
199,
504,
5890,
492,
5228,
199,
199,
504,
1639,
14,
1018,
492,
10041,
12,
12506,
199,
504,
1639,
14,
1018,
14,
12844,
14,
1095,
492,
1487,
12161,
547,
199,
504,
1639,
14,
396,
492,
24424,
12,
7640,
12,
18244,
1746,
199,
199,
504,
1275,
992,
492,
6529,
199,
504,
1275,
2219,
492,
11973,
6315,
14440,
12,
11973,
6315,
10161,
14440,
199,
199,
893,
26,
272,
492,
8864,
272,
7509,
63,
23103,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
23103,
275,
756,
199,
199,
23103,
63,
17576,
63,
3170,
63,
8272,
275,
519,
7,
1944,
859,
4310,
8864,
7,
421,
199,
533,
1488,
3935,
6295,
2377,
3346,
26,
272,
408,
17473,
282,
8072,
492,
63,
578,
805,
370,
20577,
8864,
3545,
339,
1010,
1865,
370,
1255,
2295,
626,
4911,
314,
5953,
402,
314,
18916,
9146,
272,
1380,
1255,
641,
282,
2656,
626,
965,
8864,
4903,
334,
2930,
314,
1639,
445,
41,
1654,
395,
272,
1683,
492,
63,
578,
12,
880,
626,
652,
6534,
376,
3545,
1380,
314,
8864,
272,
9146,
365,
3769,
8439,
14,
221,
710,
14802,
14,
646,
63,
578,
342,
1240,
365,
272,
3769,
6326,
315,
314,
12506,
14,
2683,
63,
8349,
1252,
339,
22165,
26,
327,
4195,
1367,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
646,
63,
578,
275,
14802,
14,
646,
63,
578,
339,
347,
492,
63,
578,
8,
277,
12,
859,
63,
515,
304,
267,
340,
859,
63,
515,
508,
12506,
14,
18637,
20012,
63,
19637,
5357,
3960,
459,
5963,
2565,
288,
746,
3545,
8,
23103,
63,
17576,
63,
3170,
63,
8272,
9,
398,
372,
291,
423,
646,
63,
578,
8,
578,
63,
515,
9,
421,
199,
533,
3091,
57,
3935,
7299,
1746,
8,
17968,
304,
272,
408,
1763,
9445,
1134,
5963,
4903,
6571,
282,
3201,
16812,
1125,
339,
22165,
26,
327,
4195,
1367,
272,
408,
272,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
408,
22948,
8439,
8864,
436,
22312,
14802,
14,
646,
63,
578,
624,
267,
1613,
1252,
27777,
342,
398,
843,
423,
646,
63,
578,
63,
1805,
275,
1488,
3935,
6295,
2377,
3346,
342,
267,
14802,
14,
646,
63,
578,
275,
843,
423,
646,
63,
578,
63,
1805,
14,
646,
63,
578,
398,
327,
5436,
734,
6328,
12506,
370,
31102,
8864,
4124,
267,
12506,
423,
12844,
275,
1052,
339,
768,
3744,
272,
347,
24468,
8,
1886,
304,
267,
408,
48,
14608,
8864,
1771,
340,
5784,
624,
267,
1613,
1252,
12336,
2543,
342,
398,
14802,
14,
646,
63,
578,
275,
843,
423,
646,
63,
578,
63,
1805,
423,
646,
63,
578,
398,
327,
5436,
734,
6328,
12506,
370,
3633,
734,
8857,
7299,
4454,
267,
12506,
423,
12844,
275,
1052,
339,
347,
511,
63,
8349,
63,
647,
5963,
63,
705,
63,
1188,
8,
277,
304,
267,
408,
10369,
8864,
9146,
1928,
1134,
5963,
6534,
3545,
624,
267,
1335,
5865,
275,
6529,
8,
354,
628,
42,
5865,
531,
267,
543,
291,
14,
1855,
8,
17825,
304,
288,
12506,
14,
3549,
480,
5963,
401,
359,
74,
5865,
566,
339,
347,
511,
63,
27470,
63,
647,
5963,
63,
705,
63,
1188,
8,
277,
304,
267,
408,
10369,
8864,
30237,
1928,
1134,
5963,
6534,
3545,
624,
267,
543,
291,
14,
1855,
8,
17825,
304,
288,
12506,
14,
11143,
480,
5963,
401,
6899,
339,
347,
511,
63,
2724,
576,
63,
647,
5963,
63,
705,
63,
1188,
8,
277,
304,
267,
408,
23796,
5461,
576,
16904,
376,
1125,
1380,
8864,
2559,
4124,
624,
267,
543,
291,
14,
14638,
8,
8110,
14,
31542,
12,
18916,
63,
17576,
63,
3170,
63,
8272,
304,
288,
10041,
14,
1250,
63,
1531,
360,
2724,
576,
297,
1475,
534,
5963,
358,
421,
199,
32,
2796,
14,
11278,
8,
13533,
63,
23103,
12,
298,
1944,
8864,
3555,
10501,
531,
199,
533,
1488,
3935,
7299,
1746,
8,
3571,
6315,
14440,
12,
7640,
304,
272,
9146,
63,
354,
275,
298,
5963,
2,
272,
31336,
63,
1121,
63,
495,
275,
408,
13,
1504,
26,
272,
21250,
26,
22536,
6941,
1115,
261,
949,
5160,
272,
7974,
63,
602,
26,
8315,
13,
1690,
13,
975,
4114,
26,
383,
26,
383,
272,
9695,
26,
359,
17,
61,
272,
4132,
26,
413,
523,
3803,
26,
413,
523,
1402,
26,
12506,
14,
6934,
199,
13,
1504,
26,
272,
536,
26,
10944,
523,
3803,
26,
413,
523,
1402,
26,
12506,
14,
3710,
199,
13,
1504,
26,
272,
536,
26,
437,
784,
397,
523,
3803,
26,
413,
523,
1402,
26,
12506,
14,
2502,
624,
339,
3803,
2003,
63,
495,
275,
408,
13,
1504,
26,
272,
536,
26,
10944,
523,
3803,
26,
2973,
523,
1402,
26,
12506,
14,
3710,
199,
13,
1504,
26,
272,
536,
26,
10172,
13,
329,
414,
523,
1402,
26,
12506,
14,
3710,
624,
339,
4412,
63,
7128,
63,
495,
275,
408,
13,
1402,
26,
12506,
14,
6934,
523,
3803,
26,
2818,
6934,
63,
2051,
9,
83,
523,
1504,
26,
272,
4132,
26,
2818,
2502,
63,
2051,
9,
83,
272,
21250,
26,
510,
26790,
965,
949,
4192,
641,
31334,
46,
272,
7974,
63,
602,
26,
8315,
13,
1690,
13,
975,
4119,
26,
383,
26,
383,
272,
9695,
26,
359,
2840,
2246,
63,
3710,
63,
2051,
9,
83,
12,
2818,
4375,
63,
3710,
63,
2051,
9,
83,
61,
272,
3404,
63,
576,
26,
942,
199,
624,
339,
768,
4639,
272,
347,
485,
3502,
63,
1199,
8,
2171,
63,
495,
304,
267,
862,
26,
288,
8864,
14,
3489,
63,
912,
8,
6424,
8,
2171,
63,
495,
430,
267,
871,
2186,
26,
288,
372,
756,
267,
587,
26,
288,
372,
715,
339,
768,
4639,
272,
347,
485,
362,
63,
2051,
63,
1459,
8,
2171,
63,
495,
304,
267,
2203,
63,
513,
275,
942,
267,
2547,
275,
5228,
8,
2171,
63,
495,
9,
267,
367,
1559,
63,
807,
315,
8864,
14,
3489,
63,
912,
8,
1745,
304,
288,
2203,
63,
513,
14,
740,
8,
1113,
63,
807,
905,
2051,
3135,
267,
372,
2203,
63,
513,
339,
768,
4639,
272,
347,
485,
362,
63,
698,
63,
1459,
8,
2171,
63,
495,
12,
901,
63,
354,
304,
267,
2203,
63,
513,
275,
942,
267,
2547,
275,
5228,
8,
2171,
63,
495,
9,
267,
367,
1559,
63,
807,
315,
8864,
14,
3489,
63,
912
] |
[
14802,
199,
646,
2882,
199,
504,
5890,
492,
5228,
199,
199,
504,
1639,
14,
1018,
492,
10041,
12,
12506,
199,
504,
1639,
14,
1018,
14,
12844,
14,
1095,
492,
1487,
12161,
547,
199,
504,
1639,
14,
396,
492,
24424,
12,
7640,
12,
18244,
1746,
199,
199,
504,
1275,
992,
492,
6529,
199,
504,
1275,
2219,
492,
11973,
6315,
14440,
12,
11973,
6315,
10161,
14440,
199,
199,
893,
26,
272,
492,
8864,
272,
7509,
63,
23103,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
23103,
275,
756,
199,
199,
23103,
63,
17576,
63,
3170,
63,
8272,
275,
519,
7,
1944,
859,
4310,
8864,
7,
421,
199,
533,
1488,
3935,
6295,
2377,
3346,
26,
272,
408,
17473,
282,
8072,
492,
63,
578,
805,
370,
20577,
8864,
3545,
339,
1010,
1865,
370,
1255,
2295,
626,
4911,
314,
5953,
402,
314,
18916,
9146,
272,
1380,
1255,
641,
282,
2656,
626,
965,
8864,
4903,
334,
2930,
314,
1639,
445,
41,
1654,
395,
272,
1683,
492,
63,
578,
12,
880,
626,
652,
6534,
376,
3545,
1380,
314,
8864,
272,
9146,
365,
3769,
8439,
14,
221,
710,
14802,
14,
646,
63,
578,
342,
1240,
365,
272,
3769,
6326,
315,
314,
12506,
14,
2683,
63,
8349,
1252,
339,
22165,
26,
327,
4195,
1367,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
646,
63,
578,
275,
14802,
14,
646,
63,
578,
339,
347,
492,
63,
578,
8,
277,
12,
859,
63,
515,
304,
267,
340,
859,
63,
515,
508,
12506,
14,
18637,
20012,
63,
19637,
5357,
3960,
459,
5963,
2565,
288,
746,
3545,
8,
23103,
63,
17576,
63,
3170,
63,
8272,
9,
398,
372,
291,
423,
646,
63,
578,
8,
578,
63,
515,
9,
421,
199,
533,
3091,
57,
3935,
7299,
1746,
8,
17968,
304,
272,
408,
1763,
9445,
1134,
5963,
4903,
6571,
282,
3201,
16812,
1125,
339,
22165,
26,
327,
4195,
1367,
272,
408,
272,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
408,
22948,
8439,
8864,
436,
22312,
14802,
14,
646,
63,
578,
624,
267,
1613,
1252,
27777,
342,
398,
843,
423,
646,
63,
578,
63,
1805,
275,
1488,
3935,
6295,
2377,
3346,
342,
267,
14802,
14,
646,
63,
578,
275,
843,
423,
646,
63,
578,
63,
1805,
14,
646,
63,
578,
398,
327,
5436,
734,
6328,
12506,
370,
31102,
8864,
4124,
267,
12506,
423,
12844,
275,
1052,
339,
768,
3744,
272,
347,
24468,
8,
1886,
304,
267,
408,
48,
14608,
8864,
1771,
340,
5784,
624,
267,
1613,
1252,
12336,
2543,
342,
398,
14802,
14,
646,
63,
578,
275,
843,
423,
646,
63,
578,
63,
1805,
423,
646,
63,
578,
398,
327,
5436,
734,
6328,
12506,
370,
3633,
734,
8857,
7299,
4454,
267,
12506,
423,
12844,
275,
1052,
339,
347,
511,
63,
8349,
63,
647,
5963,
63,
705,
63,
1188,
8,
277,
304,
267,
408,
10369,
8864,
9146,
1928,
1134,
5963,
6534,
3545,
624,
267,
1335,
5865,
275,
6529,
8,
354,
628,
42,
5865,
531,
267,
543,
291,
14,
1855,
8,
17825,
304,
288,
12506,
14,
3549,
480,
5963,
401,
359,
74,
5865,
566,
339,
347,
511,
63,
27470,
63,
647,
5963,
63,
705,
63,
1188,
8,
277,
304,
267,
408,
10369,
8864,
30237,
1928,
1134,
5963,
6534,
3545,
624,
267,
543,
291,
14,
1855,
8,
17825,
304,
288,
12506,
14,
11143,
480,
5963,
401,
6899,
339,
347,
511,
63,
2724,
576,
63,
647,
5963,
63,
705,
63,
1188,
8,
277,
304,
267,
408,
23796,
5461,
576,
16904,
376,
1125,
1380,
8864,
2559,
4124,
624,
267,
543,
291,
14,
14638,
8,
8110,
14,
31542,
12,
18916,
63,
17576,
63,
3170,
63,
8272,
304,
288,
10041,
14,
1250,
63,
1531,
360,
2724,
576,
297,
1475,
534,
5963,
358,
421,
199,
32,
2796,
14,
11278,
8,
13533,
63,
23103,
12,
298,
1944,
8864,
3555,
10501,
531,
199,
533,
1488,
3935,
7299,
1746,
8,
3571,
6315,
14440,
12,
7640,
304,
272,
9146,
63,
354,
275,
298,
5963,
2,
272,
31336,
63,
1121,
63,
495,
275,
408,
13,
1504,
26,
272,
21250,
26,
22536,
6941,
1115,
261,
949,
5160,
272,
7974,
63,
602,
26,
8315,
13,
1690,
13,
975,
4114,
26,
383,
26,
383,
272,
9695,
26,
359,
17,
61,
272,
4132,
26,
413,
523,
3803,
26,
413,
523,
1402,
26,
12506,
14,
6934,
199,
13,
1504,
26,
272,
536,
26,
10944,
523,
3803,
26,
413,
523,
1402,
26,
12506,
14,
3710,
199,
13,
1504,
26,
272,
536,
26,
437,
784,
397,
523,
3803,
26,
413,
523,
1402,
26,
12506,
14,
2502,
624,
339,
3803,
2003,
63,
495,
275,
408,
13,
1504,
26,
272,
536,
26,
10944,
523,
3803,
26,
2973,
523,
1402,
26,
12506,
14,
3710,
199,
13,
1504,
26,
272,
536,
26,
10172,
13,
329,
414,
523,
1402,
26,
12506,
14,
3710,
624,
339,
4412,
63,
7128,
63,
495,
275,
408,
13,
1402,
26,
12506,
14,
6934,
523,
3803,
26,
2818,
6934,
63,
2051,
9,
83,
523,
1504,
26,
272,
4132,
26,
2818,
2502,
63,
2051,
9,
83,
272,
21250,
26,
510,
26790,
965,
949,
4192,
641,
31334,
46,
272,
7974,
63,
602,
26,
8315,
13,
1690,
13,
975,
4119,
26,
383,
26,
383,
272,
9695,
26,
359,
2840,
2246,
63,
3710,
63,
2051,
9,
83,
12,
2818,
4375,
63,
3710,
63,
2051,
9,
83,
61,
272,
3404,
63,
576,
26,
942,
199,
624,
339,
768,
4639,
272,
347,
485,
3502,
63,
1199,
8,
2171,
63,
495,
304,
267,
862,
26,
288,
8864,
14,
3489,
63,
912,
8,
6424,
8,
2171,
63,
495,
430,
267,
871,
2186,
26,
288,
372,
756,
267,
587,
26,
288,
372,
715,
339,
768,
4639,
272,
347,
485,
362,
63,
2051,
63,
1459,
8,
2171,
63,
495,
304,
267,
2203,
63,
513,
275,
942,
267,
2547,
275,
5228,
8,
2171,
63,
495,
9,
267,
367,
1559,
63,
807,
315,
8864,
14,
3489,
63,
912,
8,
1745,
304,
288,
2203,
63,
513,
14,
740,
8,
1113,
63,
807,
905,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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
] |
henriquemiranda/yambopy
|
scripts/realtime/break-symm.py
|
6
|
2275
|
##############################################################################
#
# Author: Alejandro Molina-Sanchez
# Run real-time simulations with yambo
#
# Warning: Real-time simulations requires several data folders for running
# properly. Before using this scripts compulsively is recommended
# to understand the different run levels.
#
# This script breaks the symmetries of a given nscf run and
# prepares the rt-folder for the RT simulations
#
##############################################################################
from __future__ import print_function
from yambopy import *
import argparse
print('This script breaks the symmetries of a given nscf run and')
print('prepares the rt-folder for the RT simulations')
print('Any previous "database" folder will be erased')
print('arg1: folder with nscf data')
print('arg2: folder for RT simulation')
print('arg3: prefix')
print('arg4: symmetry')
print('Example: python break-symm.py -i nscf -o rt-100 -p si -s 100')
parser = argparse.ArgumentParser(description='Map of a double-grid')
parser.add_argument('-i' ,'--input' , help='Folder with nscf data')
parser.add_argument('-o' ,'--output' , help='Folder for RT simulation')
parser.add_argument('-p' ,'--prefix' ,help='Prefix of nscf calculation')
parser.add_argument('-s' ,'--symmetry' ,help='Choice symmetry: 100 010 110')
args = parser.parse_args()
print('Folder of nscf data ===>>> ' ,args.input)
print('Folder of RT simulation ===>>> ' ,args.output)
print('Prefix ===>>> ' ,args.prefix)
print('Symmetry ===>>> ' ,args.symmetry)
nscf_folder = args.input
rt_folder = args.output
prefix = args.prefix
symm = args.symmetry
# Check rt_folder
if os.path.isdir(rt_folder):
print('Real-time folder already exists')
raise SystemExit
# Generation of the database folder
if os.path.isdir('database'):
os.system('rm -rf database')
os.system('cd %s/%s.save ; p2y -O ../../database' % (nscf_folder, prefix))
os.system('cd database; yambo')
# Breaking of symmetries
if symm == '100':
breaking_symmetries([1,0,0], [0,0,0], rt_folder)
elif symm == '010':
breaking_symmetries([0,1,0], [0,0,0], rt_folder)
elif symm == '110':
breaking_symmetries([1,0,0], [0,1,0], rt_folder)
|
bsd-3-clause
|
[
4605,
199,
3,
199,
3,
6529,
26,
6832,
74,
460,
293,
603,
393,
13765,
13,
23906,
595,
90,
199,
3,
3378,
3363,
13,
521,
4389,
21429,
543,
612,
455,
656,
199,
3,
221,
199,
3,
15902,
26,
14849,
13,
521,
4389,
21429,
5074,
9978,
666,
16533,
367,
3879,
199,
3,
7684,
14,
21467,
1808,
642,
10554,
1013,
348,
9840,
365,
14318,
199,
3,
370,
20647,
314,
3365,
1255,
11106,
14,
199,
3,
199,
3,
961,
2884,
18277,
314,
4678,
3318,
397,
402,
282,
1627,
302,
27441,
1255,
436,
199,
3,
876,
27749,
314,
14059,
13,
3741,
367,
314,
24090,
4389,
21429,
199,
3,
199,
4605,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
612,
11020,
927,
258,
492,
627,
199,
646,
7534,
199,
199,
1361,
360,
2765,
2884,
18277,
314,
4678,
3318,
397,
402,
282,
1627,
302,
27441,
1255,
436,
358,
199,
1361,
360,
657,
27749,
314,
14059,
13,
3741,
367,
314,
24090,
4389,
21429,
358,
199,
1361,
360,
9874,
4136,
298,
4659,
2,
4922,
911,
506,
9266,
11185,
358,
199,
1361,
360,
1273,
17,
26,
4922,
543,
302,
27441,
666,
358,
199,
1361,
360,
1273,
18,
26,
4922,
367,
24090,
17625,
358,
199,
1361,
360,
1273,
19,
26,
2403,
358,
199,
1361,
360,
1273,
20,
26,
30246,
358,
199,
1361,
360,
9846,
26,
2366,
2059,
13,
1786,
596,
14,
647,
446,
73,
302,
27441,
446,
79,
14059,
13,
1960,
446,
80,
13877,
446,
83,
2948,
358,
199,
199,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
2956,
402,
282,
4270,
13,
3825,
358,
199,
2087,
14,
525,
63,
2094,
3654,
73,
7,
20606,
306,
1210,
7,
259,
2360,
1720,
534,
7850,
543,
302,
27441,
666,
358,
199,
2087,
14,
525,
63,
2094,
3654,
79,
7,
20606,
306,
1199,
7,
257,
2360,
1720,
534,
7850,
367,
24090,
17625,
358,
199,
2087,
14,
525,
63,
2094,
3654,
80,
7,
20606,
306,
1861,
7,
257,
2360,
3437,
534,
4793,
402,
302,
27441,
15232,
358,
199,
2087,
14,
525,
63,
2094,
3654,
83,
7,
20606,
306,
3840,
10987,
7,
2360,
3437,
534,
9054,
30246,
26,
2948,
378,
709,
16814,
358,
199,
589,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
1361,
360,
7850,
402,
302,
27441,
666,
258,
24768,
6071,
221,
283,
2360,
589,
14,
1210,
9,
199,
1361,
360,
7850,
402,
24090,
17625,
24768,
6071,
221,
283,
2360,
589,
14,
1199,
9,
199,
1361,
360,
4793,
8295,
24768,
6071,
221,
283,
2360,
589,
14,
1861,
9,
199,
1361,
360,
16594,
10987,
4483,
24768,
6071,
221,
283,
2360,
589,
14,
3840,
10987,
9,
199,
199,
78,
27441,
63,
3741,
275,
1249,
14,
1210,
199,
2591,
63,
3741,
257,
275,
1249,
14,
1199,
199,
1861,
420,
275,
1249,
14,
1861,
199,
1786,
596,
263,
275,
1249,
14,
3840,
10987,
2043,
199,
3,
2670,
14059,
63,
3741,
199,
692,
747,
14,
515,
14,
6027,
8,
2591,
63,
3741,
304,
272,
870,
360,
10099,
13,
521,
4922,
2575,
3495,
358,
272,
746,
14838,
199,
3,
1464,
425,
402,
314,
3050,
4922,
199,
692,
747,
14,
515,
14,
6027,
360,
4659,
735,
272,
747,
14,
2253,
360,
5682,
446,
3941,
3050,
358,
199,
736,
14,
2253,
360,
2866,
450,
83,
3149,
83,
14,
2117,
8700,
299,
18,
89,
446,
47,
24272,
5093,
4659,
7,
450,
334,
78,
27441,
63,
3741,
12,
2403,
430,
199,
736,
14,
2253,
360,
2866,
3050,
27,
612,
455,
656,
358,
2043,
199,
3,
22535,
316,
402,
4678,
3318,
397,
199,
199,
692,
1847,
596,
257,
508,
283,
1960,
356,
272,
27485,
63,
3840,
3318,
397,
779,
17,
12,
16,
12,
16,
467,
359,
16,
12,
16,
12,
16,
467,
14059,
63,
3741,
9,
199,
4164,
1847,
596,
508,
283,
9523,
356,
272,
27485,
63,
3840,
3318,
397,
779,
16,
12,
17,
12,
16,
467,
359,
16,
12,
16,
12,
16,
467,
14059,
63,
3741,
9,
199,
4164,
1847,
596,
508,
283,
6019,
356,
272,
27485,
63,
3840,
3318,
397,
779,
17,
12,
16,
12,
16,
467,
359,
16,
12,
17,
12,
16,
467,
14059,
63,
3741,
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
] |
[
199,
3,
199,
3,
6529,
26,
6832,
74,
460,
293,
603,
393,
13765,
13,
23906,
595,
90,
199,
3,
3378,
3363,
13,
521,
4389,
21429,
543,
612,
455,
656,
199,
3,
221,
199,
3,
15902,
26,
14849,
13,
521,
4389,
21429,
5074,
9978,
666,
16533,
367,
3879,
199,
3,
7684,
14,
21467,
1808,
642,
10554,
1013,
348,
9840,
365,
14318,
199,
3,
370,
20647,
314,
3365,
1255,
11106,
14,
199,
3,
199,
3,
961,
2884,
18277,
314,
4678,
3318,
397,
402,
282,
1627,
302,
27441,
1255,
436,
199,
3,
876,
27749,
314,
14059,
13,
3741,
367,
314,
24090,
4389,
21429,
199,
3,
199,
4605,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
612,
11020,
927,
258,
492,
627,
199,
646,
7534,
199,
199,
1361,
360,
2765,
2884,
18277,
314,
4678,
3318,
397,
402,
282,
1627,
302,
27441,
1255,
436,
358,
199,
1361,
360,
657,
27749,
314,
14059,
13,
3741,
367,
314,
24090,
4389,
21429,
358,
199,
1361,
360,
9874,
4136,
298,
4659,
2,
4922,
911,
506,
9266,
11185,
358,
199,
1361,
360,
1273,
17,
26,
4922,
543,
302,
27441,
666,
358,
199,
1361,
360,
1273,
18,
26,
4922,
367,
24090,
17625,
358,
199,
1361,
360,
1273,
19,
26,
2403,
358,
199,
1361,
360,
1273,
20,
26,
30246,
358,
199,
1361,
360,
9846,
26,
2366,
2059,
13,
1786,
596,
14,
647,
446,
73,
302,
27441,
446,
79,
14059,
13,
1960,
446,
80,
13877,
446,
83,
2948,
358,
199,
199,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
2956,
402,
282,
4270,
13,
3825,
358,
199,
2087,
14,
525,
63,
2094,
3654,
73,
7,
20606,
306,
1210,
7,
259,
2360,
1720,
534,
7850,
543,
302,
27441,
666,
358,
199,
2087,
14,
525,
63,
2094,
3654,
79,
7,
20606,
306,
1199,
7,
257,
2360,
1720,
534,
7850,
367,
24090,
17625,
358,
199,
2087,
14,
525,
63,
2094,
3654,
80,
7,
20606,
306,
1861,
7,
257,
2360,
3437,
534,
4793,
402,
302,
27441,
15232,
358,
199,
2087,
14,
525,
63,
2094,
3654,
83,
7,
20606,
306,
3840,
10987,
7,
2360,
3437,
534,
9054,
30246,
26,
2948,
378,
709,
16814,
358,
199,
589,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
1361,
360,
7850,
402,
302,
27441,
666,
258,
24768,
6071,
221,
283,
2360,
589,
14,
1210,
9,
199,
1361,
360,
7850,
402,
24090,
17625,
24768,
6071,
221,
283,
2360,
589,
14,
1199,
9,
199,
1361,
360,
4793,
8295,
24768,
6071,
221,
283,
2360,
589,
14,
1861,
9,
199,
1361,
360,
16594,
10987,
4483,
24768,
6071,
221,
283,
2360,
589,
14,
3840,
10987,
9,
199,
199,
78,
27441,
63,
3741,
275,
1249,
14,
1210,
199,
2591,
63,
3741,
257,
275,
1249,
14,
1199,
199,
1861,
420,
275,
1249,
14,
1861,
199,
1786,
596,
263,
275,
1249,
14,
3840,
10987,
2043,
199,
3,
2670,
14059,
63,
3741,
199,
692,
747,
14,
515,
14,
6027,
8,
2591,
63,
3741,
304,
272,
870,
360,
10099,
13,
521,
4922,
2575,
3495,
358,
272,
746,
14838,
199,
3,
1464,
425,
402,
314,
3050,
4922,
199,
692,
747,
14,
515,
14,
6027,
360,
4659,
735,
272,
747,
14,
2253,
360,
5682,
446,
3941,
3050,
358,
199,
736,
14,
2253,
360,
2866,
450,
83,
3149,
83,
14,
2117,
8700,
299,
18,
89,
446,
47,
24272,
5093,
4659,
7,
450,
334,
78,
27441,
63,
3741,
12,
2403,
430,
199,
736,
14,
2253,
360,
2866,
3050,
27,
612,
455,
656,
358,
2043,
199,
3,
22535,
316,
402,
4678,
3318,
397,
199,
199,
692,
1847,
596,
257,
508,
283,
1960,
356,
272,
27485,
63,
3840,
3318,
397,
779,
17,
12,
16,
12,
16,
467,
359,
16,
12,
16,
12,
16,
467,
14059,
63,
3741,
9,
199,
4164,
1847,
596,
508,
283,
9523,
356,
272,
27485,
63,
3840,
3318,
397,
779,
16,
12,
17,
12,
16,
467,
359,
16,
12,
16,
12,
16,
467,
14059,
63,
3741,
9,
199,
4164,
1847,
596,
508,
283,
6019,
356,
272,
27485,
63,
3840,
3318,
397,
779,
17,
12,
16,
12,
16,
467,
359,
16,
12,
17,
12,
16,
467,
14059,
63,
3741,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Varbin/EEH
|
_vendor/ldap3/extend/microsoft/modifyPassword.py
|
1
|
2949
|
"""
"""
# Created on 2015.11.27
#
# Author: Giovanni Cannata
#
# Copyright 2015, 2016, 2017 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ldap3 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 ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.
from ... import MODIFY_REPLACE, MODIFY_DELETE, MODIFY_ADD
from ...utils.log import log, log_enabled, PROTOCOL
from ...core.results import RESULT_SUCCESS
from ...utils.dn import safe_dn
def ad_modify_password(connection, user_dn, new_password, old_password, controls=None):
# old password must be None to reset password with sufficient privileges
if connection.check_names:
user_dn = safe_dn(user_dn)
if str is bytes: # python2, converts to unicode
new_password = unicode(new_password)
if old_password:
old_password = unicode(old_password)
encoded_new_password = ('"%s"' % new_password).encode('utf-16-le')
if old_password: # normal users must specify old and new password
encoded_old_password = ('"%s"' % old_password).encode('utf-16-le')
result = connection.modify(user_dn,
{'unicodePwd': [(MODIFY_DELETE, [encoded_old_password]),
(MODIFY_ADD, [encoded_new_password])]},
controls)
else: # admin users can reset password without sending the old one
result = connection.modify(user_dn,
{'unicodePwd': [(MODIFY_REPLACE, [encoded_new_password])]},
controls)
if not connection.strategy.sync:
_, result = connection.get_response(result)
else:
result = connection.result
# change successful, returns True
if result['result'] == RESULT_SUCCESS:
return True
# change was not successful, raises exception if raise_exception = True in connection or returns the operation result, error code is in result['result']
if connection.raise_exceptions:
from ...core.exceptions import LDAPOperationResult
if log_enabled(PROTOCOL):
log(PROTOCOL, 'operation result <%s> for <%s>', result, connection)
raise LDAPOperationResult(result=result['result'], description=result['description'], dn=result['dn'], message=result['message'], response_type=result['type'])
return result
|
bsd-2-clause
|
[
624,
199,
624,
199,
199,
3,
18208,
641,
6900,
14,
845,
14,
1465,
199,
3,
199,
3,
6529,
26,
598,
2308,
86,
1189,
73,
445,
1189,
419,
199,
3,
199,
3,
1898,
6900,
12,
7800,
12,
9708,
598,
2308,
86,
1189,
73,
445,
1189,
419,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
13727,
19,
14,
199,
3,
199,
3,
13727,
19,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
199,
3,
701,
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,
13727,
19,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
13727,
19,
315,
314,
9685,
436,
9685,
14,
30928,
540,
1584,
14,
199,
3,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
504,
2263,
492,
10362,
1914,
18114,
63,
27010,
12,
10362,
1914,
18114,
63,
7014,
12,
10362,
1914,
18114,
63,
9732,
199,
504,
2263,
1208,
14,
793,
492,
943,
12,
943,
63,
3827,
12,
3611,
2566,
3978,
199,
504,
2263,
1018,
14,
2604,
492,
20668,
63,
12779,
199,
504,
2263,
1208,
14,
4272,
492,
5048,
63,
4272,
421,
199,
318,
1503,
63,
8951,
63,
2060,
8,
2105,
12,
922,
63,
4272,
12,
892,
63,
2060,
12,
2269,
63,
2060,
12,
13467,
29,
403,
304,
272,
327,
2269,
2505,
1471,
506,
488,
370,
5305,
2505,
543,
19258,
20001,
272,
340,
1950,
14,
1074,
63,
1247,
26,
267,
922,
63,
4272,
275,
5048,
63,
4272,
8,
751,
63,
4272,
9,
272,
340,
620,
365,
2783,
26,
221,
327,
2366,
18,
12,
15373,
370,
2649,
267,
892,
63,
2060,
275,
2649,
8,
1222,
63,
2060,
9,
267,
340,
2269,
63,
2060,
26,
288,
2269,
63,
2060,
275,
2649,
8,
1753,
63,
2060,
9,
339,
5737,
63,
1222,
63,
2060,
275,
661,
6808,
83,
4507,
450,
892,
63,
2060,
680,
2143,
360,
1624,
13,
975,
13,
274,
358,
339,
340,
2269,
63,
2060,
26,
221,
327,
3293,
4390,
1471,
4165,
2269,
436,
892,
2505,
267,
5737,
63,
1753,
63,
2060,
275,
661,
6808,
83,
4507,
450,
2269,
63,
2060,
680,
2143,
360,
1624,
13,
975,
13,
274,
358,
267,
754,
275,
1950,
14,
8951,
8,
751,
63,
4272,
12,
3521,
791,
2975,
32701,
356,
3842,
31225,
63,
7014,
12,
359,
8167,
63,
1753,
63,
2060,
2522,
8962,
334,
31225,
63,
9732,
12,
359,
8167,
63,
1222,
63,
2060,
12457,
1386,
3521,
13467,
9,
272,
587,
26,
221,
327,
4628,
4390,
883,
5305,
2505,
1928,
10209,
314,
2269,
1373,
267,
754,
275,
1950,
14,
8951,
8,
751,
63,
4272,
12,
3521,
791,
2975,
32701,
356,
3842,
31225,
63,
27010,
12,
359,
8167,
63,
1222,
63,
2060,
12457,
1386,
3521,
13467,
9,
339,
340,
440,
1950,
14,
8590,
14,
5186,
26,
267,
5501,
754,
275,
1950,
14,
362,
63,
1310,
8,
1099,
9,
272,
587,
26,
267,
754,
275,
1950,
14,
1099,
339,
327,
1570,
9512,
12,
2529,
715,
272,
340,
754,
459,
1099,
418,
508,
20668,
63,
12779,
26,
267,
372,
715,
339,
327,
1570,
1990,
440,
9512,
12,
6534,
1919,
340,
746,
63,
1971,
275,
715,
315,
1950,
503,
2529,
314,
3439,
754,
12,
1125,
1233,
365,
315,
754,
459,
1099,
418,
272,
340,
1950,
14,
3730,
63,
3924,
26,
267,
687,
2263,
1018,
14,
3924,
492,
20717,
6044,
2889,
267,
340,
943,
63,
3827,
8,
9583,
304,
288,
943,
8,
9583,
12,
283,
5735,
754,
21808,
83,
30,
367,
21808,
83,
4206,
754,
12,
1950,
9,
267,
746,
20717,
6044,
2889,
8,
1099,
29,
1099,
459,
1099,
995,
1369,
29,
1099,
459,
1802,
995,
14052,
29,
1099,
459,
4272,
995,
1245,
29,
1099,
459,
1188,
995,
1177,
63,
466,
29,
1099,
459,
466,
1105,
339,
372,
754,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
624,
199,
199,
3,
18208,
641,
6900,
14,
845,
14,
1465,
199,
3,
199,
3,
6529,
26,
598,
2308,
86,
1189,
73,
445,
1189,
419,
199,
3,
199,
3,
1898,
6900,
12,
7800,
12,
9708,
598,
2308,
86,
1189,
73,
445,
1189,
419,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
13727,
19,
14,
199,
3,
199,
3,
13727,
19,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
199,
3,
701,
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,
13727,
19,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
13727,
19,
315,
314,
9685,
436,
9685,
14,
30928,
540,
1584,
14,
199,
3,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
504,
2263,
492,
10362,
1914,
18114,
63,
27010,
12,
10362,
1914,
18114,
63,
7014,
12,
10362,
1914,
18114,
63,
9732,
199,
504,
2263,
1208,
14,
793,
492,
943,
12,
943,
63,
3827,
12,
3611,
2566,
3978,
199,
504,
2263,
1018,
14,
2604,
492,
20668,
63,
12779,
199,
504,
2263,
1208,
14,
4272,
492,
5048,
63,
4272,
421,
199,
318,
1503,
63,
8951,
63,
2060,
8,
2105,
12,
922,
63,
4272,
12,
892,
63,
2060,
12,
2269,
63,
2060,
12,
13467,
29,
403,
304,
272,
327,
2269,
2505,
1471,
506,
488,
370,
5305,
2505,
543,
19258,
20001,
272,
340,
1950,
14,
1074,
63,
1247,
26,
267,
922,
63,
4272,
275,
5048,
63,
4272,
8,
751,
63,
4272,
9,
272,
340,
620,
365,
2783,
26,
221,
327,
2366,
18,
12,
15373,
370,
2649,
267,
892,
63,
2060,
275,
2649,
8,
1222,
63,
2060,
9,
267,
340,
2269,
63,
2060,
26,
288,
2269,
63,
2060,
275,
2649,
8,
1753,
63,
2060,
9,
339,
5737,
63,
1222,
63,
2060,
275,
661,
6808,
83,
4507,
450,
892,
63,
2060,
680,
2143,
360,
1624,
13,
975,
13,
274,
358,
339,
340,
2269,
63,
2060,
26,
221,
327,
3293,
4390,
1471,
4165,
2269,
436,
892,
2505,
267,
5737,
63,
1753,
63,
2060,
275,
661,
6808,
83,
4507,
450,
2269,
63,
2060,
680,
2143,
360,
1624,
13,
975,
13,
274,
358,
267,
754,
275,
1950,
14,
8951,
8,
751,
63,
4272,
12,
3521,
791,
2975,
32701,
356,
3842,
31225,
63,
7014,
12,
359,
8167,
63,
1753,
63,
2060,
2522,
8962,
334,
31225,
63,
9732,
12,
359,
8167,
63,
1222,
63,
2060,
12457,
1386,
3521,
13467,
9,
272,
587,
26,
221,
327,
4628,
4390,
883,
5305,
2505,
1928,
10209,
314,
2269,
1373,
267,
754,
275,
1950,
14,
8951,
8,
751,
63,
4272,
12,
3521,
791,
2975,
32701,
356,
3842,
31225,
63,
27010,
12,
359,
8167,
63,
1222,
63,
2060,
12457,
1386,
3521,
13467,
9,
339,
340,
440,
1950,
14,
8590,
14,
5186,
26,
267,
5501,
754,
275,
1950,
14,
362,
63,
1310,
8,
1099,
9,
272,
587,
26,
267,
754,
275,
1950,
14,
1099,
339,
327,
1570,
9512,
12,
2529,
715,
272,
340,
754,
459,
1099,
418,
508,
20668,
63,
12779,
26,
267,
372,
715,
339,
327,
1570,
1990,
440,
9512,
12,
6534,
1919,
340,
746,
63,
1971,
275,
715,
315,
1950,
503,
2529,
314,
3439,
754,
12,
1125,
1233,
365,
315,
754,
459,
1099,
418,
272,
340,
1950,
14,
3730,
63,
3924,
26,
267,
687,
2263,
1018,
14,
3924,
492,
20717,
6044,
2889,
267,
340,
943,
63,
3827,
8,
9583,
304,
288,
943,
8,
9583,
12,
283,
5735,
754,
21808,
83,
30,
367,
21808,
83,
4206,
754,
12,
1950,
9,
267,
746,
20717,
6044,
2889,
8,
1099,
29,
1099,
459,
1099,
995,
1369,
29,
1099,
459,
1802,
995,
14052,
29,
1099,
459,
4272,
995,
1245,
29,
1099,
459,
1188,
995,
1177,
63,
466,
29,
1099,
459,
466,
1105,
339,
372,
754,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Gurdil/pywo
|
pywo/core/windows.py
|
5
|
34855
|
#
# PyWO - Python Window Organizer
# Copyright 2010, Wojciech 'KosciaK' Pietrzok
#
# This file is part of PyWO.
#
# PyWO 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.
#
# PyWO 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 PyWO. If not, see <http://www.gnu.org/licenses/>.
#
"""Classes and functions related to windows and window managers.
.. seealso::
* :doc:`/definitions` for reference of used terms.
* :doc:`xlib` for methods common to both :class:`Window`
and :class:`WindowManager`
"""
import logging
import time
from Xlib import X, Xutil, Xatom
from pywo.core.basic import CustomTuple
from pywo.core.basic import Gravity, Position, Size, Geometry, Extents
from pywo.core.basic import Layout, Strut
from pywo.core.xlib import XObject
__author__ = "Wojciech 'KosciaK' Pietrzok, Antti Kaihola"
log = logging.getLogger(__name__)
class Type(object):
"""Enum of windows, and window managers types."""
# Window Types
DESKTOP = XObject.atom('_NET_WM_WINDOW_TYPE_DESKTOP')
"""Desktop."""
DOCK = XObject.atom('_NET_WM_WINDOW_TYPE_DOCK')
"""Dock window (for example panels)."""
TOOLBAR = XObject.atom('_NET_WM_WINDOW_TYPE_TOOLBAR')
"""Toolbar window."""
MENU = XObject.atom('_NET_WM_WINDOW_TYPE_MENU')
"""Menu window."""
UTILITY = XObject.atom('_NET_WM_WINDOW_TYPE_UTILITY')
"""Utility window."""
SPLASH = XObject.atom('_NET_WM_WINDOW_TYPE_SPLASH')
"""Splash dialog."""
DIALOG = XObject.atom('_NET_WM_WINDOW_TYPE_DIALOG')
"""Modal dialog."""
NORMAL = XObject.atom('_NET_WM_WINDOW_TYPE_NORMAL')
"""Normal window."""
NONE = -1
"""No `Type` specified."""
# Window manager Types
COMPIZ = 1
METACITY = 2
KWIN = 3
XFWM = 4
OPENBOX = 5
FLUXBOX = 6
BLACKBOX = 7
ICEWM = 8
ENLIGHTMENT = 9
WINDOW_MAKER = 10
SAWFISH = 11
PEKWM = 12
UNKNOWN = -1
class Hacks(object):
"""List of hacks caused by EWMH, ICCCM implementation inconsistencies."""
DONT_TRANSLATE_COORDS = CustomTuple([Type.COMPIZ,
Type.FLUXBOX,
Type.WINDOW_MAKER])
"""Don't translate coordinates of the window."""
ADJUST_GEOMETRY = CustomTuple([Type.COMPIZ,
Type.KWIN,
Type.ENLIGHTMENT,
Type.ICEWM,
Type.BLACKBOX])
"""Adjust `Geometry`."""
PARENT_XY = CustomTuple([Type.FLUXBOX,
Type.WINDOW_MAKER])
"""Use coordinates from window's parent."""
CALCULATE_EXTENTS = CustomTuple([Type.BLACKBOX,
Type.ICEWM,
Type.SAWFISH,
Type.WINDOW_MAKER,
Type.UNKNOWN])
"""Calculate `Extents` values if not provided by window manager."""
class State(object):
"""Enum of window states."""
# States described by EWMH
MODAL = XObject.atom('_NET_WM_STATE_MODAL')
"""Modal dialog."""
STICKY = XObject.atom('_NET_WM_STATE_STICKY')
"""Sticky - show on all :ref:`desktops <desktop>`
/ :ref:`viewports <viewport>`."""
MAXIMIZED_VERT = XObject.atom('_NET_WM_STATE_MAXIMIZED_VERT')
"""Maximized vertically."""
MAXIMIZED_HORZ = XObject.atom('_NET_WM_STATE_MAXIMIZED_HORZ')
"""Maximized horizontally."""
MAXIMIZED = (MAXIMIZED_VERT, MAXIMIZED_HORZ)
"""Maximized both vertically and horizontally."""
SHADED = XObject.atom('_NET_WM_STATE_SHADED')
"""Shaded (only title bar is visible)."""
SKIP_TASKBAR = XObject.atom('_NET_WM_STATE_SKIP_TASKBAR')
"""Don't show window in the taskbar."""
SKIP_PAGER = XObject.atom('_NET_WM_STATE_SKIP_PAGER')
"""Don't show window in the pager."""
HIDDEN = XObject.atom('_NET_WM_STATE_HIDDEN')
"""Hidden window (for example when iconified)."""
FULLSCREEN = XObject.atom('_NET_WM_STATE_FULLSCREEN')
"""Fullscreen."""
ABOVE = XObject.atom('_NET_WM_STATE_ABOVE')
"""Above all other windows."""
BELOW = XObject.atom('_NET_WM_STATE_BELOW')
"""Below all other windows."""
DEMANDS_ATTENTION = XObject.atom('_NET_WM_STATE_DEMANDS_ATTENTION')
"""Demands attention."""
# Window managers specific states
OB_UNDECORATED = XObject.atom('_OB_WM_STATE_UNDECORATED')
"""Borderless (only in Openbox)."""
class Mode(object):
"""Enum of mode values.
Used while changing window's states.
"""
UNSET = 0
"""Unset state."""
SET = 1
"""Set state."""
TOGGLE = 2
"""Toggle state."""
class Window(XObject):
"""Window object."""
# _NET_WM_DESKTOP returns this value when in STATE_STICKY
ALL_DESKTOPS = 0xFFFFFFFF
"""Visible on all :ref:`desktops <desktop>`."""
def __init__(self, win_id):
XObject.__init__(self, win_id)
@property
def type(self):
"""Return tuple of window's :class:`Type`(s)."""
# _NET_WM_WINDOW_TYPE, ATOM[]/32
type = self.get_property('_NET_WM_WINDOW_TYPE')
if not type:
return CustomTuple([Type.NONE])
return CustomTuple(type.value)
@property
def state(self):
"""Return tuple of window's state(s)."""
# _NET_WM_STATE, ATOM[]
state = self.get_property('_NET_WM_STATE')
if not state:
return CustomTuple()
return CustomTuple(state.value)
@property
def parent_id(self):
"""Return window's parent id."""
parent = self._win.get_wm_transient_for()
if parent:
return parent.id
else:
return None
@property
def parent(self):
"""Return window's parent."""
parent_id = self.parent_id
if parent_id:
return Window(parent_id)
else:
return None
@property
def name(self):
"""Return window's name."""
# _NET_WM_NAME, UTF8_STRING
name = self.get_property('_NET_WM_NAME')
if not name:
name = self._win.get_full_property(Xatom.WM_NAME, 0)
if not name:
return ''
return name.value
@property
def class_name(self):
"""Return window's class name."""
class_name = self._win.get_wm_class()
if class_name:
return '.'.join(class_name)
return ''
@property
def client_machine(self):
"""Return name of window's client machine."""
client = self._win.get_wm_client_machine()
return client
@property
def desktop(self):
"""Return :ref:`desktop` number the window is on.
Returns :const:`ALL_DESKTOPS` if window is sticky.
"""
# _NET_WM_DESKTOP desktop, CARDINAL/32
desktop = self.get_property('_NET_WM_DESKTOP')
if not desktop:
return 0
return desktop.value[0]
def set_desktop(self, desktop_id):
"""Move window to given :ref:`desktop`."""
desktop_id = int(desktop_id)
if desktop_id < 0:
desktop_id = 0
event_type = self.atom('_NET_WM_DESKTOP')
data = [desktop_id,
0, 0, 0, 0]
mask = X.PropertyChangeMask
self.send_event(data, event_type, mask)
# TODO: viewport_position, viewport, set_viewport
def __strut(self):
"""Return raw strut info."""
# _NET_WM_STRUT, left, right, top, bottom, CARDINAL[4]/32
strut = self.get_property('_NET_WM_STRUT')
if strut:
return strut.value
else:
return ()
def __strut_partial(self):
"""Return raw strut partial info."""
# _NET_WM_STRUT_PARTIAL, left, right, top, bottom,
# left_start_y, left_end_y,
# right_start_y, right_end_y,
# top_start_x, top_end_x,
# bottom_start_x, bottom_end_x,
# CARDINAL[12]/32
strut_partial = self.get_property('_NET_WM_STRUT_PARTIAL')
if strut_partial:
return strut_partial.value
else:
return ()
@property
def strut(self):
"""Return :class:`~pywo.core.basic.Strut`."""
strut_partial = self.__strut_partial()
if strut_partial:
# Try strut_partial first, with full info about reserved area
return Strut(*strut_partial)
strut = self.__strut()
if strut:
# Fallback to strut - only info about width/height
return Strut(strut[0], strut[1], strut[2], strut[3],
0, 0, 0, 0, 0, 0, 0, 0)
return None
def __extents(self):
"""Return raw extents info."""
# _NET_FRAME_EXTENTS, left, right, top, bottom, CARDINAL[4]/32
extents = self.get_property('_NET_FRAME_EXTENTS')
if extents:
return extents.value
else:
return ()
@property
def extents(self):
"""Return window's :class:`~pywo.core.basic.Extents`."""
extents = self.__extents()
if not extents and self.wm_type in Hacks.CALCULATE_EXTENTS:
# Hack for Blackbox, IceWM, Sawfish, Window Maker
win = self._win
parent = win.query_tree().parent
if parent.id == self._root_id:
return Extents(None, None, None, None)
if win.get_geometry().width == parent.get_geometry().width and \
win.get_geometry().height == parent.get_geometry().height:
win, parent = parent, parent.query_tree().parent
if parent.id == self._root_id:
return Extents(None, None, None, None)
win_geo = win.get_geometry()
parent_geo = parent.get_geometry()
border_widths = win_geo.border_width + parent_geo.border_width
parent_border = parent_geo.border_width*2
left = win_geo.x + border_widths
top = win_geo.y + border_widths
right = parent_geo.width - win_geo.width - left + parent_border
bottom = parent_geo.height - win_geo.height - top + parent_border
extents = (left, right, top, bottom)
elif not extents:
extents = (None, None, None, None)
elif Type.OPENBOX in self.wm_type and \
State.OB_UNDECORATED in self.state:
# TODO: recognize 'retain border when undecorated' setting
extents = (1, 1, 1, 1) # works for retain border
#extents = (0, 0, 0, 0) # if border is not retained
return Extents(*extents)
def __geometry(self):
"""Return raw geometry info (translated if needed)."""
geometry = self._win.get_geometry()
if self.wm_type in Hacks.PARENT_XY:
# Hack for Fluxbox, Window Maker
parent_geo = self._win.query_tree().parent.get_geometry()
geometry.x = parent_geo.x
geometry.y = parent_geo.y
return (geometry.x, geometry.y,
geometry.width, geometry.height)
@property
def geometry(self):
"""Return window's :class:`~pywo.core.basic.Geometry`.
(x, y) coordinates are the top-left corner of the window.
Window position is relative to the left-top corner of
current :ref:`viewport`.
Position and size *includes* window's extents!
Position is translated if needed.
"""
x, y, width, height = self.__geometry()
#print x, y, width, height
extents = self.extents
if self.wm_type not in Hacks.DONT_TRANSLATE_COORDS and \
not (Type.METACITY in self.wm_type and not extents):
# NOTE: in Metacity for windows with no extents
# returned translated coords were invalid (0, 0)
# if neeeded translate coords and multiply them by -1
translated = self._translate_coords(x, y)
x = -translated.x
y = -translated.y
if self.wm_type in Hacks.ADJUST_GEOMETRY:
# Used in Compiz, KWin, E16, IceWM, Blackbox
x -= extents.left
y -= extents.top
# FIXME: invalid geometry if border_width > 0 in raw_geometry
return Geometry(x, y,
width + extents.horizontal,
height + extents.vertical)
def set_geometry(self, geometry, on_resize=Gravity(0, 0)):
"""Move or resize window.
Use provided :class:`~pywo.core.basic.Geometry`, in case of resize
adjust position using :class:`~pywo.core.basic.Gravity`.
Postion (relative to current :ref:`viewport`) and size must include
window's extents.
"""
# FIXME: probabely doesn't work correctly with windows with border_width
extents = self.extents
x = geometry.x
y = geometry.y
width = geometry.width - extents.horizontal
height = geometry.height - extents.vertical
geometry_size = (width, height)
current = self.__geometry()
hints = self._win.get_wm_normal_hints()
# This is a fix for WINE, OpenOffice and KeePassX windows
if hints and hints.win_gravity == X.StaticGravity:
x += extents.left
y += extents.top
# Reduce size to maximal allowed value
if hints and hints.max_width:
width = min([width, hints.max_width])
if hints and hints.max_height:
height = min([height, hints.max_height])
# Don't try to set size lower then minimal
if hints and hints.min_width:
width = max([width, hints.min_width])
if hints and hints.min_height:
height = max([height, hints.min_height])
# Set correct size if it is incremental, take base in account
if hints and hints.width_inc:
if hints.base_width:
base = hints.base_width
else:
base = current[2] % hints.width_inc
width = ((width - base) / hints.width_inc) * hints.width_inc
width += base
if hints.min_width and width < hints.min_width:
width += hints.width_inc
if hints and hints.height_inc:
if hints.base_height:
base = hints.base_height
else:
base = current[3] % hints.height_inc
height = ((height - base) / hints.height_inc) * hints.height_inc
height += base
if hints.height_inc and height < hints.min_height:
height += hints.height_inc
# Adjust position after size change
if (width, height) != geometry_size:
x = x + (geometry_size[0] - width) * on_resize.x
y = y + (geometry_size[1] - height) * on_resize.y
self._win.configure(x=x, y=y, width=width, height=height)
def moveresize(self, geometry):
"""Works like :meth:`set_geometry`, but using ``_NET_MOVERESIZE_WINDOW``
This gives finer control:
* it allows to use gravity, so there are no problems with static windows
* x, y coordinates includes window's extents
* allow to move part of the window outside the workarea, while
configure will resize window to fit workarea
.. warning::
It seems that x,y coords must be unsigned ints!!!
So it is not possible to move window to the left :ref:`viewport`!
Not sure it it is EWMH, Xlib, or python-xlib fault...
But it makes _NET_MOVERESIZE_WINDOW rather useless...
"""
# TODO: check the border_width issue
# TODO: what about max/min/incremental size?
event_type = self.atom('_NET_MOVERESIZE_WINDOW')
mask = X.SubstructureRedirectMask
flags = 1 << 8 | 1 << 9 | 1 << 10 | 1 << 11 | 1 << 13
data = [X.NorthWestGravity | flags,
max([0, geometry.x]),
max([0, geometry.y]),
geometry.width,
geometry.height]
self.send_event(data, event_type, mask)
def activate(self):
"""Make this window active (and unshade, unminimize)."""
# NOTE: In Metacity this WON'T change desktop to window's desktop!
event_type = self.atom('_NET_ACTIVE_WINDOW')
mask = X.SubstructureRedirectMask
data = [0, 0, 0, 0, 0]
self.send_event(data, event_type, mask)
# NOTE: Previously used for activating (didn't unshade/unminimize)
# Need to test if setting X.Above is needed in various WMs
#self._win.set_input_focus(X.RevertToNone, X.CurrentTime)
#self._win.configure(stack_mode=X.Above)
def iconify(self, mode):
"""Iconify (minimize) window."""
state = self._win.get_wm_state().state
if mode == 1 or \
mode == 2 and state == Xutil.NormalState:
set_state = Xutil.IconicState
if mode == 0 or \
mode == 2 and state == Xutil.IconicState:
set_state = Xutil.NormalState
event_type = self.atom('WM_CHANGE_STATE')
mask = X.SubstructureRedirectMask
data = [set_state,
0, 0, 0, 0]
self.send_event(data, event_type, mask)
def maximize(self, mode,
vert=State.MAXIMIZED_VERT,
horz=State.MAXIMIZED_HORZ):
"""Maximize window.
If you want to maximize only horizontally use ``vert=False``
If you want to maximize only vertically use ``horz=False``
"""
data = [mode,
horz,
vert,
0, 0]
self.__change_state(data)
def shade(self, mode):
"""Shade window (if supported by window manager)."""
data = [mode,
State.SHADED,
0, 0, 0]
self.__change_state(data)
def fullscreen(self, mode):
"""Make window fullscreen (if supported by window manager)."""
data = [mode,
State.FULLSCREEN,
0, 0, 0]
self.__change_state(data)
def sticky(self, mode):
"""Make window sticky (if supported by window manager)."""
data = [mode,
State.STICKY,
0, 0, 0]
self.__change_state(data)
def always_above(self, mode):
"""Make window always above others (if supported by window manager)."""
data = [mode,
State.ABOVE,
0, 0, 0]
self.__change_state(data)
def always_below(self, mode):
"""Make window always below others (if supported by window manager)."""
data = [mode,
State.BELOW,
0, 0, 0]
self.__change_state(data)
def reset(self, full=False):
"""Reset window's state.
Uniconify, unset fullscreen, unmaximize, unshade.
If ``full == True`` unset sticky, always above / below.
"""
self.iconify(Mode.UNSET)
self.fullscreen(Mode.UNSET)
self.maximize(Mode.UNSET)
self.shade(Mode.UNSET)
if full:
self.sticky(Mode.UNSET)
self.always_above(Mode.UNSET)
self.always_below(Mode.UNSET)
def close(self):
"""Close window."""
event_type = self.atom('_NET_CLOSE_WINDOW')
mask = X.SubstructureRedirectMask
data = [0, 0, 0, 0, 0]
self.send_event(data, event_type, mask)
def destroy(self):
"""Unmap and destroy window."""
self._win.unmap()
self._win.destroy()
def __change_state(self, data):
"""Send ``_NET_WM_STATE`` event to the root window."""
event_type = self.atom('_NET_WM_STATE')
mask = X.SubstructureRedirectMask
self.send_event(data, event_type, mask)
def visual_bell(self, color_name="red", line_width=4, duration=0.125):
"""Show border around window."""
#geo = self.geometry
#self.draw_rectangle(geo.x+2, geo.y+2, geo.width-4, geo.height-4, 4)
#self.flush()
#time.sleep(duration)
#self.draw_rectangle(geo.x+2, geo.y+2, geo.width-4, geo.height-4, 4)
#osd.close()
#self.flush()
osd = self.osd_rectangle(self.geometry, color_name, line_width)
osd.blink(duration)
def __eq__(self, other):
return self.id == other.id
def __ne__(self, other):
return not self.id == other.id
def __repr__(self):
return '<Window id=%s>' % (self.id,)
def debug_info(self, logger=log):
"""Print full window's info, for debug use only."""
logger.info('-= Current Window =-')
win = self._win
logger.info('ID=%s' % self.id)
logger.info('Client_machine="%s"' % self.client_machine)
logger.info('Name="%s"' % self.name)
logger.info('Class="%s"' % self.class_name)
logger.info('Type=%s' % [self.atom_name(e) for e in self.type])
logger.info('State=%s' % [self.atom_name(e) for e in self.state])
logger.info('WM State=%s' % win.get_wm_state())
logger.info('Desktop=%s' % self.desktop)
logger.info('Extents=%s' % self.extents)
logger.info('Extents_raw=%s' % [str(e) for e in self.__extents()])
logger.info('Geometry=%s' % self.geometry)
logger.info('Geometry_raw=%s' % getattr(win.get_geometry(), '_data'))
geometry = self._win.get_geometry()
translated = self._translate_coords(geometry.x, geometry.y)
logger.info('Geometry_translated=%s' % getattr(translated, '_data'))
logger.info('Strut=%s' % self.strut)
logger.info('Parent=%s %s' % (self.parent_id, self.parent))
logger.info('Normal_hints=%s' % getattr(win.get_wm_normal_hints(),
'_data'))
#log.info('Hints=%s' % self._win.get_wm_hints())
logger.info('Attributes=%s' % getattr(win.get_attributes(), '_data'))
logger.info('Query_tree=%s' % getattr(win.query_tree(), '_data'))
class WindowManager(XObject):
"""Window Manager (or root window in X programming terms).
WindowManager's :attr:`_win` refers to the root window.
`WindowManager` is a Singleton.
"""
# Instance of the WindowManager class, make it Singleton.
__INSTANCE = None
def __new__(cls):
if cls.__INSTANCE:
return cls.__INSTANCE
manager = object.__new__(cls)
XObject.__init__(manager)
cls.__INSTANCE = manager
manager.update_type()
return manager
# def __init__(self):
# XObject.__init__(self)
# self.update_type()
@property
def name(self):
"""Return window manager's name.
``''`` is returned if window manager doesn't support EWMH.
"""
# _NET_SUPPORTING_WM_CHECK, WINDOW/32
win_id = self.get_property('_NET_SUPPORTING_WM_CHECK')
if not win_id:
return ''
win = XObject(win_id.value[0])
name = win.get_property('_NET_WM_NAME')
if name:
return name.value
else:
return ''
@property
def type(self):
"""Return tuple of window manager's type(s)."""
return self.wm_type
def update_type(self):
"""Update window manager's type."""
recognize = {'compiz': Type.COMPIZ, 'metacity': Type.METACITY,
'kwin': Type.KWIN, 'xfwm': Type.XFWM,
'openbox': Type.OPENBOX, 'fluxbox': Type.FLUXBOX,
'blackbox': Type.BLACKBOX, 'icewm': Type.ICEWM,
'e1': Type.ENLIGHTMENT, 'sawfish': Type.SAWFISH,
'window maker': Type.WINDOW_MAKER, 'pekwm': Type.PEKWM,
}
name = self.name.lower()
XObject.set_wm_type(Type.UNKNOWN)
for name_part, wm_type in recognize.items():
if name_part in name:
XObject.set_wm_type(wm_type)
@property
def desktops(self):
"""Return number of :ref:`desktops <desktop>`.
Number of desktops may differ from ``desktop_layout.cols*rows``
"""
# _NET_NUMBER_OF_DESKTOPS, CARDINAL/32
number = self.get_property('_NET_NUMBER_OF_DESKTOPS')
if not number:
return 1
return number.value[0]
@property
def desktop_names(self):
"""Return list of :ref:`desktop` names.
Not all Window Managers support desktop names, in this case
empty list is returned.
Length of list of names may differ from number of desktops!
"""
# _NET_DESKTOP_NAMES, UTF8_STRING[]
names = self.get_property('_NET_DESKTOP_NAMES')
if not names:
return []
return names.value.decode('utf-8').split('\x00')[:-1]
# TODO: set_desktop_name ???
# TODO: add_desktop, remove_desktop
@property
def desktop(self):
"""Return current :ref:`desktop` number."""
# _NET_CURRENT_DESKTOP desktop, CARDINAL/32
desktop = self.get_property('_NET_CURRENT_DESKTOP')
return desktop.value[0]
def set_desktop(self, num):
"""Change current :ref:`desktop`."""
num = int(num)
if num < 0:
num = 0
event_type = self.atom('_NET_CURRENT_DESKTOP')
data = [num,
0, 0, 0, 0]
mask = X.PropertyChangeMask
self.send_event(data, event_type, mask)
@property
def desktop_size(self):
"""Return Size of current :ref:`desktop`."""
# _NET_DESKTOP_GEOMETRY width, height, CARDINAL[2]/32
geometry = self.get_property('_NET_DESKTOP_GEOMETRY').value
return Size(geometry[0], geometry[1])
# TODO: set_desktop_size?!?, or set_viewports(columns, rows)
@property
def desktop_layout(self):
"""Return :ref:`desktops <desktop>` :class:`~pywo.core.basic.Layout`,
as set by pager."""
# _NET_DESKTOP_LAYOUT, orientation, columns, rows, starting_corner
# CARDINAL[4]/32
layout = self.get_property('_NET_DESKTOP_LAYOUT')
if not layout:
return None
orientation, cols, rows, corner = layout.value
desktops = self.desktops
# NOTE: needs more testing...
cols = cols or (desktops / rows + min([1, desktops % rows]))
rows = rows or (desktops / cols + min([1, desktops % cols]))
return Layout(cols, rows, orientation, corner)
@property
def viewport_position(self):
"""Return position of current :ref:`viewport`.
Position is relative to :ref:`desktop`.
"""
# _NET_DESKTOP_VIEWPORT x, y, CARDINAL[][2]/32
viewport = self.get_property('_NET_DESKTOP_VIEWPORT').value
# TODO: Might not work correctly on all WMs
return Position(viewport[0], viewport[1])
def set_viewport_position(self, x, y):
"""Change current :ref:`viewport` position."""
event_type = self.atom('_NET_DESKTOP_VIEWPORT')
data = [x,
y,
0, 0, 0]
mask = X.PropertyChangeMask
self.send_event(data, event_type, mask)
def set_viewport(self, viewport):
"""Change current :ref:`viewport` (similar to :meth:`set_desktop`)."""
if viewport < 0:
viewport = 0
desktop_size = self.desktop_size
layout = self.viewport_layout
x = desktop_size.width / layout.cols * (viewport % layout.cols)
y = desktop_size.height / layout.rows * (viewport / layout.cols)
self.set_viewport_position(x, y)
@property
def viewport_layout(self):
"""Return :ref:`viewports <viewport>` :class:`~pywo.core.basic.Layout`,
as set by pager.
Some Window Managers use scrolling instead of pagination,
so it is possible to set viewport to any position inside :ref:`desktop`.
"""
desktop_size = self.desktop_size
workarea_size = self.workarea_geometry
cols = desktop_size.width / workarea_size.width
rows = desktop_size.height / workarea_size.height
return Layout(cols, rows)
@property
def workarea_geometry(self):
"""Return geometry of current :ref:`workarea`.
Position is relative to current :ref:`viewport`.
"""
# _NET_WORKAREA, x, y, width, height CARDINAL[][4]/32
workarea = self.get_property('_NET_WORKAREA').value
# NOTE: this will return geometry for first, not current!
# what about all workareas, not only the current one?
# TODO: multi monitor support by returning workarea for current monitor?
return Geometry(workarea[0], workarea[1],
workarea[2], workarea[3])
# TODO: Maybe add Window.current_screen()?
def nearest_screen_geometry(self, geometry):
"""Return :class:`~pywo.core.basic.Geometry` of the :ref:`screen`
best matching the given rectangle.
Position is relative to current :ref:`viewport`.
"""
screens_by_intersection = ((screen & geometry, screen)
for screen in self.screen_geometries())
screens_by_area = ((intersection.area, screen)
for intersection, screen in screens_by_intersection
if intersection)
largest_area, screen = sorted(screens_by_area)[-1]
return screen & self.workarea_geometry
def active_window_id(self):
"""Return id of active window."""
# _NET_ACTIVE_WINDOW, WINDOW/32
win_id = self.get_property('_NET_ACTIVE_WINDOW')
if win_id:
return win_id.value[0]
return None
def active_window(self):
"""Return active window."""
window_id = self.active_window_id()
if window_id:
return Window(window_id)
return None
@staticmethod
def get_window(window_id):
"""Return Window with given id."""
window = Window(window_id)
return window
def windows_ids(self, stacking=True):
"""Return list of all windows' ids (newest/on top first)."""
if stacking:
windows_ids = self.get_property('_NET_CLIENT_LIST_STACKING').value
else:
windows_ids = self.get_property('_NET_CLIENT_LIST').value
windows_ids.reverse()
return windows_ids
def windows(self, filter=None, match='', stacking=True):
"""Return list of all windows (newest/on top first)."""
# TODO: regexp matching?
windows_ids = self.windows_ids(stacking)
windows = [Window(win_id) for win_id in windows_ids]
if filter:
windows = [window for window in windows if filter(window)]
if match:
windows = self.__name_matcher(windows, match)
return windows
def visual_bell(self, color_name="red", line_width=4, duration=0.125):
"""Show border around :ref:`workarea` on current :ref:`screen`."""
active = self.active_window()
nearest_geometry = self.nearest_screen_geometry(active.geometry)
osd = self.osd_rectangle(nearest_geometry, color_name, line_width)
osd.blink(duration)
def __name_matcher(self, windows, match):
"""Filter and sort windows with matching name or class name."""
match = match.strip().lower()
# TODO: match.decode('utf-8') if not unicode
desktop = self.desktop
workarea = self.workarea_geometry
def mapper(window, points=0):
name = window.name.lower().decode('utf-8')
if name == match:
points += 200
elif match in name:
left = name.find(match)
right = (name.rfind(match) - len(name) + len(match)) * -1
points += 150 - min(left, right)
if match in window.class_name.lower():
points += 100
try:
geometry = window.geometry
except:
return (window, 0)
if points and \
(window.desktop == desktop or \
window.desktop == Window.ALL_DESKTOPS):
points += 50
if geometry.x < workarea.x2 and \
geometry.x2 > workarea.x and \
geometry.y < workarea.y2 and \
geometry.y2 > workarea.y:
points += 100
return (window, points)
windows = map(mapper, windows)
windows.sort(key=lambda win: win[1], reverse=True)
windows = [win for win, points in windows if points]
return windows
def unregister_all(self):
"""Unregister all event handlers for all windows."""
self._unregister_all()
def __repr__(self):
return '<WindowManager id=%s>' % (self.id,)
def debug_info(self, logger=log):
"""Print full windows manager's info, for debug use only."""
logger.info('-= Window Manager =-')
logger.info('Name=%s' % self.name)
#logger.info('Supported=%s' % \
# [self.atom_name(atom)
# for atom in self.get_property('_NET_SUPPORTED').value])
logger.info('-= Desktops =-')
logger.info('Layout=%s' % self.desktop_layout)
logger.info('Names=%s' % self.desktop_names)
logger.info('Total=%s' % self.desktops)
logger.info('Current=%s' % self.desktop)
logger.info('Size=%s' % self.desktop_size)
logger.info('-= Viewports =-')
logger.info('Layout=%s' % self.viewport_layout)
logger.info('Position=%s' % self.viewport_position)
logger.info('-= Workarea =-')
logger.info('Geometry=%s' % self.workarea_geometry)
logger.info('-= Strut =-')
struts = [win.strut for win in self.windows()]
logger.info('[%s]' % \
', '.join([str(strut) for strut in struts if strut]))
logger.info('-= Screens =-')
screens = self.screen_geometries()
logger.info('Total=%s' % len(screens))
logger.info('Geometries=[%s]' % \
', '.join([str(geo) for geo in screens]))
|
gpl-3.0
|
[
3,
199,
3,
1611,
11325,
446,
2018,
15689,
13125,
290,
1793,
199,
3,
1898,
7129,
12,
644,
79,
74,
559,
12736,
283,
43,
26737,
4674,
43,
7,
510,
14077,
30841,
745,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1611,
11325,
14,
199,
3,
199,
3,
1611,
11325,
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,
1611,
11325,
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,
1611,
11325,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
624,
15711,
436,
3423,
4048,
370,
10061,
436,
4353,
19680,
14,
199,
199,
703,
19352,
447,
339,
627,
520,
1301,
1705,
15,
15388,
64,
367,
3659,
402,
1202,
2895,
14,
272,
627,
520,
1301,
1705,
88,
773,
64,
367,
3102,
2863,
370,
3865,
520,
533,
1705,
4301,
64,
15166,
436,
520,
533,
1705,
4301,
2988,
64,
199,
199,
624,
421,
199,
646,
2050,
199,
646,
900,
199,
199,
504,
1323,
773,
492,
1323,
12,
1323,
1974,
12,
1323,
4188,
199,
199,
504,
1134,
2027,
14,
1018,
14,
4316,
492,
8388,
7075,
199,
504,
1134,
2027,
14,
1018,
14,
4316,
492,
10268,
18936,
12,
15483,
12,
14579,
12,
10579,
12,
1316,
767,
83,
221,
199,
504,
1134,
2027,
14,
1018,
14,
4316,
492,
25604,
12,
8303,
337,
199,
504,
1134,
2027,
14,
1018,
14,
88,
773,
492,
1323,
1692,
421,
199,
363,
2502,
363,
275,
298,
26724,
74,
559,
12736,
283,
43,
26737,
4674,
43,
7,
510,
14077,
30841,
745,
12,
437,
343,
280,
1804,
5789,
72,
22205,
2,
421,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
2434,
8,
785,
304,
339,
408,
5081,
402,
10061,
12,
436,
4353,
19680,
2943,
1041,
339,
327,
15689,
18851,
272,
11758,
43,
11422,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
15480,
63,
2711,
63,
4448,
43,
11422,
358,
272,
408,
20436,
1041,
272,
3506,
2504,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
15480,
63,
2711,
63,
25190,
358,
272,
408,
28804,
4353,
334,
509,
2893,
12748,
83,
10477,
272,
2296,
2228,
13895,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
15480,
63,
2711,
63,
9731,
13895,
358,
272,
408,
29630,
4353,
1041,
272,
603,
742,
53,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
15480,
63,
2711,
63,
18223,
358,
272,
408,
5977,
4353,
1041,
272,
738,
52,
2273,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
15480,
63,
2711,
63,
934,
2273,
358,
272,
408,
17505,
4353,
1041,
272,
428,
2749,
8100,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
15480,
63,
2711,
63,
24933,
8100,
358,
272,
408,
51,
1168,
1119,
9592,
1041,
272,
30132,
14008,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
15480,
63,
2711,
63,
1914,
23622,
358,
272,
408,
23689,
9592,
1041,
272,
653,
9623,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
15480,
63,
2711,
63,
10765,
358,
272,
408,
6241,
4353,
1041,
272,
653,
4817,
275,
446,
17,
272,
408,
1944,
658,
804,
64,
2013,
1041,
339,
327,
15689,
5256,
18851,
272,
16503,
5357,
275,
413,
272,
19357,
1348,
1922,
275,
499,
272,
1804,
7941,
275,
650,
272,
1323,
38,
13073,
275,
841,
272,
24164,
15694,
275,
959,
272,
9821,
14272,
15694,
275,
1227,
272,
26774,
15694,
275,
1520,
272,
473,
2089,
13073,
275,
1695,
272,
5070,
21613,
4479,
275,
1749,
272,
20896,
1649,
55,
63,
2054,
19972,
275,
1616,
272,
13950,
29046,
13898,
275,
4119,
272,
510,
11959,
13073,
275,
3144,
272,
24740,
275,
446,
17,
421,
199,
533,
30802,
83,
8,
785,
304,
339,
408,
1296,
402,
11176,
83,
18104,
701,
662,
13073,
40,
12,
473,
2571,
9249,
4514,
315,
388,
2316,
724,
2578,
1041,
339,
577,
5994,
63,
26376,
1951,
63,
1439,
726,
3177,
275,
8388,
7075,
779,
804,
14,
6790,
5357,
12,
221,
1460,
2434,
14,
3143,
14272,
15694,
12,
221,
1460,
2434,
14,
15480,
63,
2054,
19972,
566,
272,
408,
16932,
1133,
9028,
8983,
402,
314,
4353,
1041,
272,
16271,
42,
7698,
63,
28472,
275,
8388,
7075,
779,
804,
14,
6790,
5357,
12,
221,
3521,
2434,
14,
43,
7941,
12,
221,
3521,
2434,
14,
742,
21613,
4479,
12,
221,
3521,
2434,
14,
4047,
13073,
12,
221,
3521,
2434,
14,
23113,
15694,
566,
272,
408,
17977,
658,
6831,
17105,
272,
19499,
63,
8195,
275,
8388,
7075,
779,
804,
14,
3143,
14272,
15694,
12,
221,
2490,
2434,
14,
15480,
63,
2054,
19972,
566,
272,
408,
6119,
8983,
687,
4353,
1159,
1676,
1041,
272,
445,
748,
35,
1293,
1951,
63,
2472,
1309,
51,
275,
8388,
7075,
779,
804,
14,
23113,
15694,
12,
221,
3660,
2434,
14,
4047,
13073,
12,
3660,
2434,
14,
4251,
29046,
13898,
12,
3660,
2434,
14,
15480,
63,
2054,
19972,
12,
3660,
2434,
14,
11588,
566,
272,
408,
14860,
658,
19808,
83,
64,
1338,
340,
440,
2741,
701,
4353,
5256,
1041,
421,
199,
533,
8511,
8,
785,
304,
339,
408,
5081,
402,
4353,
6363,
1041,
339,
327,
24230,
11736,
701,
662,
13073,
40,
272,
10362,
10741,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
6689,
63,
8816,
748,
358,
272,
408,
23689,
9592,
1041,
272,
4384,
13884,
57,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
6689,
63,
840,
13884,
57,
358,
272,
408,
51,
8284,
89,
446,
2498,
641,
1006,
520,
1121,
1705,
10368,
84,
1483,
665,
14487,
8637,
5591,
1182,
520,
1121,
1705,
1345,
5203,
665,
25484,
8637,
1041,
272,
9141,
1469,
18732,
63,
8851,
275,
1323,
1692
] |
[
199,
3,
1611,
11325,
446,
2018,
15689,
13125,
290,
1793,
199,
3,
1898,
7129,
12,
644,
79,
74,
559,
12736,
283,
43,
26737,
4674,
43,
7,
510,
14077,
30841,
745,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1611,
11325,
14,
199,
3,
199,
3,
1611,
11325,
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,
1611,
11325,
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,
1611,
11325,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
624,
15711,
436,
3423,
4048,
370,
10061,
436,
4353,
19680,
14,
199,
199,
703,
19352,
447,
339,
627,
520,
1301,
1705,
15,
15388,
64,
367,
3659,
402,
1202,
2895,
14,
272,
627,
520,
1301,
1705,
88,
773,
64,
367,
3102,
2863,
370,
3865,
520,
533,
1705,
4301,
64,
15166,
436,
520,
533,
1705,
4301,
2988,
64,
199,
199,
624,
421,
199,
646,
2050,
199,
646,
900,
199,
199,
504,
1323,
773,
492,
1323,
12,
1323,
1974,
12,
1323,
4188,
199,
199,
504,
1134,
2027,
14,
1018,
14,
4316,
492,
8388,
7075,
199,
504,
1134,
2027,
14,
1018,
14,
4316,
492,
10268,
18936,
12,
15483,
12,
14579,
12,
10579,
12,
1316,
767,
83,
221,
199,
504,
1134,
2027,
14,
1018,
14,
4316,
492,
25604,
12,
8303,
337,
199,
504,
1134,
2027,
14,
1018,
14,
88,
773,
492,
1323,
1692,
421,
199,
363,
2502,
363,
275,
298,
26724,
74,
559,
12736,
283,
43,
26737,
4674,
43,
7,
510,
14077,
30841,
745,
12,
437,
343,
280,
1804,
5789,
72,
22205,
2,
421,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
2434,
8,
785,
304,
339,
408,
5081,
402,
10061,
12,
436,
4353,
19680,
2943,
1041,
339,
327,
15689,
18851,
272,
11758,
43,
11422,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
15480,
63,
2711,
63,
4448,
43,
11422,
358,
272,
408,
20436,
1041,
272,
3506,
2504,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
15480,
63,
2711,
63,
25190,
358,
272,
408,
28804,
4353,
334,
509,
2893,
12748,
83,
10477,
272,
2296,
2228,
13895,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
15480,
63,
2711,
63,
9731,
13895,
358,
272,
408,
29630,
4353,
1041,
272,
603,
742,
53,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
15480,
63,
2711,
63,
18223,
358,
272,
408,
5977,
4353,
1041,
272,
738,
52,
2273,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
15480,
63,
2711,
63,
934,
2273,
358,
272,
408,
17505,
4353,
1041,
272,
428,
2749,
8100,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
15480,
63,
2711,
63,
24933,
8100,
358,
272,
408,
51,
1168,
1119,
9592,
1041,
272,
30132,
14008,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
15480,
63,
2711,
63,
1914,
23622,
358,
272,
408,
23689,
9592,
1041,
272,
653,
9623,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
15480,
63,
2711,
63,
10765,
358,
272,
408,
6241,
4353,
1041,
272,
653,
4817,
275,
446,
17,
272,
408,
1944,
658,
804,
64,
2013,
1041,
339,
327,
15689,
5256,
18851,
272,
16503,
5357,
275,
413,
272,
19357,
1348,
1922,
275,
499,
272,
1804,
7941,
275,
650,
272,
1323,
38,
13073,
275,
841,
272,
24164,
15694,
275,
959,
272,
9821,
14272,
15694,
275,
1227,
272,
26774,
15694,
275,
1520,
272,
473,
2089,
13073,
275,
1695,
272,
5070,
21613,
4479,
275,
1749,
272,
20896,
1649,
55,
63,
2054,
19972,
275,
1616,
272,
13950,
29046,
13898,
275,
4119,
272,
510,
11959,
13073,
275,
3144,
272,
24740,
275,
446,
17,
421,
199,
533,
30802,
83,
8,
785,
304,
339,
408,
1296,
402,
11176,
83,
18104,
701,
662,
13073,
40,
12,
473,
2571,
9249,
4514,
315,
388,
2316,
724,
2578,
1041,
339,
577,
5994,
63,
26376,
1951,
63,
1439,
726,
3177,
275,
8388,
7075,
779,
804,
14,
6790,
5357,
12,
221,
1460,
2434,
14,
3143,
14272,
15694,
12,
221,
1460,
2434,
14,
15480,
63,
2054,
19972,
566,
272,
408,
16932,
1133,
9028,
8983,
402,
314,
4353,
1041,
272,
16271,
42,
7698,
63,
28472,
275,
8388,
7075,
779,
804,
14,
6790,
5357,
12,
221,
3521,
2434,
14,
43,
7941,
12,
221,
3521,
2434,
14,
742,
21613,
4479,
12,
221,
3521,
2434,
14,
4047,
13073,
12,
221,
3521,
2434,
14,
23113,
15694,
566,
272,
408,
17977,
658,
6831,
17105,
272,
19499,
63,
8195,
275,
8388,
7075,
779,
804,
14,
3143,
14272,
15694,
12,
221,
2490,
2434,
14,
15480,
63,
2054,
19972,
566,
272,
408,
6119,
8983,
687,
4353,
1159,
1676,
1041,
272,
445,
748,
35,
1293,
1951,
63,
2472,
1309,
51,
275,
8388,
7075,
779,
804,
14,
23113,
15694,
12,
221,
3660,
2434,
14,
4047,
13073,
12,
3660,
2434,
14,
4251,
29046,
13898,
12,
3660,
2434,
14,
15480,
63,
2054,
19972,
12,
3660,
2434,
14,
11588,
566,
272,
408,
14860,
658,
19808,
83,
64,
1338,
340,
440,
2741,
701,
4353,
5256,
1041,
421,
199,
533,
8511,
8,
785,
304,
339,
408,
5081,
402,
4353,
6363,
1041,
339,
327,
24230,
11736,
701,
662,
13073,
40,
272,
10362,
10741,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
6689,
63,
8816,
748,
358,
272,
408,
23689,
9592,
1041,
272,
4384,
13884,
57,
275,
1323,
1692,
14,
4188,
6412,
7278,
63,
13073,
63,
6689,
63,
840,
13884,
57,
358,
272,
408,
51,
8284,
89,
446,
2498,
641,
1006,
520,
1121,
1705,
10368,
84,
1483,
665,
14487,
8637,
5591,
1182,
520,
1121,
1705,
1345,
5203,
665,
25484,
8637,
1041,
272,
9141,
1469,
18732,
63,
8851,
275,
1323,
1692,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
RaoUmer/django
|
django/core/serializers/base.py
|
4
|
5766
|
"""
Module for abstract serializer/unserializer base classes.
"""
from django.db import models
from django.utils.encoding import smart_text
from django.utils import six
class SerializerDoesNotExist(KeyError):
"""The requested serializer was not found."""
pass
class SerializationError(Exception):
"""Something bad happened during serialization."""
pass
class DeserializationError(Exception):
"""Something bad happened during deserialization."""
pass
class Serializer(object):
"""
Abstract serializer base class.
"""
# Indicates if the implemented serializer is only available for
# internal Django use.
internal_use_only = False
def serialize(self, queryset, **options):
"""
Serialize a queryset.
"""
self.options = options
self.stream = options.pop("stream", six.StringIO())
self.selected_fields = options.pop("fields", None)
self.use_natural_keys = options.pop("use_natural_keys", False)
self.start_serialization()
self.first = True
for obj in queryset:
self.start_object(obj)
# Use the concrete parent class' _meta instead of the object's _meta
# This is to avoid local_fields problems for proxy models. Refs #17717.
concrete_model = obj._meta.concrete_model
for field in concrete_model._meta.local_fields:
if field.serialize:
if field.rel is None:
if self.selected_fields is None or field.attname in self.selected_fields:
self.handle_field(obj, field)
else:
if self.selected_fields is None or field.attname[:-3] in self.selected_fields:
self.handle_fk_field(obj, field)
for field in concrete_model._meta.many_to_many:
if field.serialize:
if self.selected_fields is None or field.attname in self.selected_fields:
self.handle_m2m_field(obj, field)
self.end_object(obj)
if self.first:
self.first = False
self.end_serialization()
return self.getvalue()
def start_serialization(self):
"""
Called when serializing of the queryset starts.
"""
raise NotImplementedError
def end_serialization(self):
"""
Called when serializing of the queryset ends.
"""
pass
def start_object(self, obj):
"""
Called when serializing of an object starts.
"""
raise NotImplementedError
def end_object(self, obj):
"""
Called when serializing of an object ends.
"""
pass
def handle_field(self, obj, field):
"""
Called to handle each individual (non-relational) field on an object.
"""
raise NotImplementedError
def handle_fk_field(self, obj, field):
"""
Called to handle a ForeignKey field.
"""
raise NotImplementedError
def handle_m2m_field(self, obj, field):
"""
Called to handle a ManyToManyField.
"""
raise NotImplementedError
def getvalue(self):
"""
Return the fully serialized queryset (or None if the output stream is
not seekable).
"""
if callable(getattr(self.stream, 'getvalue', None)):
return self.stream.getvalue()
class Deserializer(object):
"""
Abstract base deserializer class.
"""
def __init__(self, stream_or_string, **options):
"""
Init this serializer given a stream or a string
"""
self.options = options
if isinstance(stream_or_string, six.string_types):
self.stream = six.StringIO(stream_or_string)
else:
self.stream = stream_or_string
# hack to make sure that the models have all been loaded before
# deserialization starts (otherwise subclass calls to get_model()
# and friends might fail...)
models.get_apps()
def __iter__(self):
return self
def __next__(self):
"""Iteration iterface -- return the next item in the stream"""
raise NotImplementedError
next = __next__ # Python 2 compatibility
class DeserializedObject(object):
"""
A deserialized model.
Basically a container for holding the pre-saved deserialized data along
with the many-to-many data saved with the object.
Call ``save()`` to save the object (with the many-to-many data) to the
database; call ``save(save_m2m=False)`` to save just the object fields
(and not touch the many-to-many stuff.)
"""
def __init__(self, obj, m2m_data=None):
self.object = obj
self.m2m_data = m2m_data
def __repr__(self):
return "<DeserializedObject: %s.%s(pk=%s)>" % (
self.object._meta.app_label, self.object._meta.object_name, self.object.pk)
def save(self, save_m2m=True, using=None):
# Call save on the Model baseclass directly. This bypasses any
# model-defined save. The save is also forced to be raw.
# This ensures that the data that is deserialized is literally
# what came from the file, not post-processed by pre_save/save
# methods.
models.Model.save_base(self.object, using=using, raw=True)
if self.m2m_data and save_m2m:
for accessor_name, object_list in self.m2m_data.items():
setattr(self.object, accessor_name, object_list)
# prevent a second (possibly accidental) call to save() from saving
# the m2m data twice.
self.m2m_data = None
|
bsd-3-clause
|
[
624,
199,
2377,
367,
9006,
9146,
15,
324,
8349,
1300,
3992,
14,
199,
624,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
505,
199,
504,
1639,
14,
1208,
492,
3816,
199,
199,
533,
25555,
7400,
8,
10230,
304,
272,
408,
1918,
5839,
9146,
1990,
440,
1911,
1041,
272,
986,
199,
199,
533,
11973,
2072,
547,
8,
1726,
304,
272,
408,
20641,
4875,
21056,
5309,
16953,
1041,
272,
986,
199,
199,
533,
1487,
12161,
547,
8,
1726,
304,
272,
408,
20641,
4875,
21056,
5309,
477,
12161,
1041,
272,
986,
199,
199,
533,
25555,
8,
785,
304,
272,
408,
272,
11836,
9146,
1300,
1021,
14,
272,
408,
339,
327,
19334,
340,
314,
6366,
9146,
365,
1454,
2808,
367,
272,
327,
5007,
5634,
675,
14,
272,
5007,
63,
1180,
63,
2118,
275,
756,
339,
347,
8437,
8,
277,
12,
7594,
12,
1011,
1419,
304,
267,
408,
267,
11973,
794,
282,
7594,
14,
267,
408,
267,
291,
14,
1419,
275,
1511,
398,
291,
14,
1745,
275,
1511,
14,
1935,
480,
1745,
401,
3816,
14,
6424,
1012,
267,
291,
14,
5511,
63,
955,
275,
1511,
14,
1935,
480,
955,
401,
488,
9,
267,
291,
14,
1180,
63,
15759,
63,
1612,
275,
1511,
14,
1935,
480,
1180,
63,
15759,
63,
1612,
401,
756,
9,
398,
291,
14,
928,
63,
12161,
342,
267,
291,
14,
2246,
275,
715,
267,
367,
1559,
315,
7594,
26,
288,
291,
14,
928,
63,
785,
8,
1113,
9,
288,
327,
3645,
314,
13801,
1676,
1021,
7,
485,
2024,
3140,
402,
314,
909,
1159,
485,
2024,
288,
327,
961,
365,
370,
5126,
2257,
63,
955,
8826,
367,
4566,
1709,
14,
22165,
327,
8881,
1196,
14,
288,
13801,
63,
1238,
275,
1559,
423,
2024,
14,
13455,
63,
1238,
288,
367,
901,
315,
13801,
63,
1238,
423,
2024,
14,
1832,
63,
955,
26,
355,
340,
901,
14,
3549,
26,
490,
340,
901,
14,
3369,
365,
488,
26,
717,
340,
291,
14,
5511,
63,
955,
365,
488,
503,
901,
14,
13651,
315,
291,
14,
5511,
63,
955,
26,
1169,
291,
14,
2479,
63,
698,
8,
1113,
12,
901,
9,
490,
587,
26,
717,
340,
291,
14,
5511,
63,
955,
365,
488,
503,
901,
14,
13651,
4439,
19,
61,
315,
291,
14,
5511,
63,
955,
26,
1169,
291,
14,
2479,
63,
9010,
63,
698,
8,
1113,
12,
901,
9,
288,
367,
901,
315,
13801,
63,
1238,
423,
2024,
14,
3479,
63,
475,
63,
3479,
26,
355,
340,
901,
14,
3549,
26,
490,
340,
291,
14,
5511,
63,
955,
365,
488,
503,
901,
14,
13651,
315,
291,
14,
5511,
63,
955,
26,
717,
291,
14,
2479,
63,
77,
18,
77,
63,
698,
8,
1113,
12,
901,
9,
288,
291,
14,
500,
63,
785,
8,
1113,
9,
288,
340,
291,
14,
2246,
26,
355,
291,
14,
2246,
275,
756,
267,
291,
14,
500,
63,
12161,
342,
267,
372,
291,
14,
7150,
342,
339,
347,
1343,
63,
12161,
8,
277,
304,
267,
408,
267,
12295,
1380,
3012,
9147,
402,
314,
7594,
9174,
14,
267,
408,
267,
746,
4279,
339,
347,
1284,
63,
12161,
8,
277,
304,
267,
408,
267,
12295,
1380,
3012,
9147,
402,
314,
7594,
11187,
14,
267,
408,
267,
986,
339,
347,
1343,
63,
785,
8,
277,
12,
1559,
304,
267,
408,
267,
12295,
1380,
3012,
9147,
402,
376,
909,
9174,
14,
267,
408,
267,
746,
4279,
339,
347,
1284,
63,
785,
8,
277,
12,
1559,
304,
267,
408,
267,
12295,
1380,
3012,
9147,
402,
376,
909,
11187,
14,
267,
408,
267,
986,
339,
347,
2429,
63,
698,
8,
277,
12,
1559,
12,
901,
304,
267,
408,
267,
12295,
370,
2429,
1924,
8212,
334,
2865,
13,
5690,
279,
9,
901,
641,
376,
909,
14,
267,
408,
267,
746,
4279,
339,
347,
2429,
63,
9010,
63,
698,
8,
277,
12,
1559,
12,
901,
304,
267,
408,
267,
12295,
370,
2429,
282,
12718,
901,
14,
267,
408,
267,
746,
4279,
339,
347,
2429,
63,
77,
18,
77,
63,
698,
8,
277,
12,
1559,
12,
901,
304,
267,
408,
267,
12295,
370,
2429,
282,
28409,
14,
267,
408,
267,
746,
4279,
339,
347,
664,
585,
8,
277,
304,
267,
408,
267,
1432,
314,
9999,
6380,
7594,
334,
269,
488,
340,
314,
1072,
2547,
365,
267,
440,
12005,
461,
680,
267,
408,
267,
340,
4550,
8,
5675,
8,
277,
14,
1745,
12,
283,
7150,
297,
488,
2298,
288,
372,
291,
14,
1745,
14,
7150,
342,
199,
199,
533,
1487,
8349,
8,
785,
304,
272,
408,
272,
11836,
1300,
30237,
1021,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2547,
63,
269,
63,
875,
12,
1011,
1419,
304,
267,
408,
267,
21026,
642,
9146,
1627,
282,
2547,
503,
282,
1059,
267,
408,
267,
291,
14,
1419,
275,
1511,
267,
340,
1228,
8,
1745,
63,
269,
63,
875,
12,
3816,
14,
875,
63,
1313,
304,
288,
291,
14,
1745,
275,
3816,
14,
6424,
8,
1745,
63,
269,
63,
875,
9,
267,
587,
26,
288,
291,
14,
1745,
275,
2547,
63,
269,
63,
875,
267,
327,
11176,
370,
1852,
3238,
626,
314,
1709,
1172,
1006,
2757,
6511,
2544,
267,
327,
477,
12161,
9174,
334,
26617,
5516,
4882,
370,
664,
63,
1238,
342,
267,
327,
436,
26157,
5594,
2449,
11965,
267,
1709,
14,
362,
63,
5181,
342,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
291,
339,
347,
636,
2184,
721,
277,
304,
267,
408,
8666,
2740,
1409,
1553,
372,
314,
2163,
1242,
315,
314,
2547,
624,
267,
746,
4279,
339,
2163,
275,
636,
2184,
363,
3777,
327,
2018,
499,
7163,
199,
199,
533,
1487,
8397,
1692,
8,
785,
304,
272,
408,
272,
437,
13256,
1402,
14,
339,
10082,
1183,
282,
3970,
367,
17573,
314,
876,
13,
8420,
13256,
666,
3180,
272,
543,
314,
5002,
13,
475,
13,
3479,
666,
6290,
543,
314,
909,
14,
339,
6523,
1124,
2117,
8497,
370,
3354,
314,
909,
334,
1045,
314,
5002,
13,
475,
13,
3479,
666,
9,
370,
314,
272,
3050,
27,
1240,
1124,
2117,
8,
2117,
63,
77,
18,
77,
29,
797,
9719,
370,
3354,
2951,
314,
909,
1504,
272,
334,
460,
440,
12943,
314,
5002,
13,
475,
13,
3479,
8292,
4959,
272,
408,
339,
347,
636,
826,
721
] |
[
199,
2377,
367,
9006,
9146,
15,
324,
8349,
1300,
3992,
14,
199,
624,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
505,
199,
504,
1639,
14,
1208,
492,
3816,
199,
199,
533,
25555,
7400,
8,
10230,
304,
272,
408,
1918,
5839,
9146,
1990,
440,
1911,
1041,
272,
986,
199,
199,
533,
11973,
2072,
547,
8,
1726,
304,
272,
408,
20641,
4875,
21056,
5309,
16953,
1041,
272,
986,
199,
199,
533,
1487,
12161,
547,
8,
1726,
304,
272,
408,
20641,
4875,
21056,
5309,
477,
12161,
1041,
272,
986,
199,
199,
533,
25555,
8,
785,
304,
272,
408,
272,
11836,
9146,
1300,
1021,
14,
272,
408,
339,
327,
19334,
340,
314,
6366,
9146,
365,
1454,
2808,
367,
272,
327,
5007,
5634,
675,
14,
272,
5007,
63,
1180,
63,
2118,
275,
756,
339,
347,
8437,
8,
277,
12,
7594,
12,
1011,
1419,
304,
267,
408,
267,
11973,
794,
282,
7594,
14,
267,
408,
267,
291,
14,
1419,
275,
1511,
398,
291,
14,
1745,
275,
1511,
14,
1935,
480,
1745,
401,
3816,
14,
6424,
1012,
267,
291,
14,
5511,
63,
955,
275,
1511,
14,
1935,
480,
955,
401,
488,
9,
267,
291,
14,
1180,
63,
15759,
63,
1612,
275,
1511,
14,
1935,
480,
1180,
63,
15759,
63,
1612,
401,
756,
9,
398,
291,
14,
928,
63,
12161,
342,
267,
291,
14,
2246,
275,
715,
267,
367,
1559,
315,
7594,
26,
288,
291,
14,
928,
63,
785,
8,
1113,
9,
288,
327,
3645,
314,
13801,
1676,
1021,
7,
485,
2024,
3140,
402,
314,
909,
1159,
485,
2024,
288,
327,
961,
365,
370,
5126,
2257,
63,
955,
8826,
367,
4566,
1709,
14,
22165,
327,
8881,
1196,
14,
288,
13801,
63,
1238,
275,
1559,
423,
2024,
14,
13455,
63,
1238,
288,
367,
901,
315,
13801,
63,
1238,
423,
2024,
14,
1832,
63,
955,
26,
355,
340,
901,
14,
3549,
26,
490,
340,
901,
14,
3369,
365,
488,
26,
717,
340,
291,
14,
5511,
63,
955,
365,
488,
503,
901,
14,
13651,
315,
291,
14,
5511,
63,
955,
26,
1169,
291,
14,
2479,
63,
698,
8,
1113,
12,
901,
9,
490,
587,
26,
717,
340,
291,
14,
5511,
63,
955,
365,
488,
503,
901,
14,
13651,
4439,
19,
61,
315,
291,
14,
5511,
63,
955,
26,
1169,
291,
14,
2479,
63,
9010,
63,
698,
8,
1113,
12,
901,
9,
288,
367,
901,
315,
13801,
63,
1238,
423,
2024,
14,
3479,
63,
475,
63,
3479,
26,
355,
340,
901,
14,
3549,
26,
490,
340,
291,
14,
5511,
63,
955,
365,
488,
503,
901,
14,
13651,
315,
291,
14,
5511,
63,
955,
26,
717,
291,
14,
2479,
63,
77,
18,
77,
63,
698,
8,
1113,
12,
901,
9,
288,
291,
14,
500,
63,
785,
8,
1113,
9,
288,
340,
291,
14,
2246,
26,
355,
291,
14,
2246,
275,
756,
267,
291,
14,
500,
63,
12161,
342,
267,
372,
291,
14,
7150,
342,
339,
347,
1343,
63,
12161,
8,
277,
304,
267,
408,
267,
12295,
1380,
3012,
9147,
402,
314,
7594,
9174,
14,
267,
408,
267,
746,
4279,
339,
347,
1284,
63,
12161,
8,
277,
304,
267,
408,
267,
12295,
1380,
3012,
9147,
402,
314,
7594,
11187,
14,
267,
408,
267,
986,
339,
347,
1343,
63,
785,
8,
277,
12,
1559,
304,
267,
408,
267,
12295,
1380,
3012,
9147,
402,
376,
909,
9174,
14,
267,
408,
267,
746,
4279,
339,
347,
1284,
63,
785,
8,
277,
12,
1559,
304,
267,
408,
267,
12295,
1380,
3012,
9147,
402,
376,
909,
11187,
14,
267,
408,
267,
986,
339,
347,
2429,
63,
698,
8,
277,
12,
1559,
12,
901,
304,
267,
408,
267,
12295,
370,
2429,
1924,
8212,
334,
2865,
13,
5690,
279,
9,
901,
641,
376,
909,
14,
267,
408,
267,
746,
4279,
339,
347,
2429,
63,
9010,
63,
698,
8,
277,
12,
1559,
12,
901,
304,
267,
408,
267,
12295,
370,
2429,
282,
12718,
901,
14,
267,
408,
267,
746,
4279,
339,
347,
2429,
63,
77,
18,
77,
63,
698,
8,
277,
12,
1559,
12,
901,
304,
267,
408,
267,
12295,
370,
2429,
282,
28409,
14,
267,
408,
267,
746,
4279,
339,
347,
664,
585,
8,
277,
304,
267,
408,
267,
1432,
314,
9999,
6380,
7594,
334,
269,
488,
340,
314,
1072,
2547,
365,
267,
440,
12005,
461,
680,
267,
408,
267,
340,
4550,
8,
5675,
8,
277,
14,
1745,
12,
283,
7150,
297,
488,
2298,
288,
372,
291,
14,
1745,
14,
7150,
342,
199,
199,
533,
1487,
8349,
8,
785,
304,
272,
408,
272,
11836,
1300,
30237,
1021,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2547,
63,
269,
63,
875,
12,
1011,
1419,
304,
267,
408,
267,
21026,
642,
9146,
1627,
282,
2547,
503,
282,
1059,
267,
408,
267,
291,
14,
1419,
275,
1511,
267,
340,
1228,
8,
1745,
63,
269,
63,
875,
12,
3816,
14,
875,
63,
1313,
304,
288,
291,
14,
1745,
275,
3816,
14,
6424,
8,
1745,
63,
269,
63,
875,
9,
267,
587,
26,
288,
291,
14,
1745,
275,
2547,
63,
269,
63,
875,
267,
327,
11176,
370,
1852,
3238,
626,
314,
1709,
1172,
1006,
2757,
6511,
2544,
267,
327,
477,
12161,
9174,
334,
26617,
5516,
4882,
370,
664,
63,
1238,
342,
267,
327,
436,
26157,
5594,
2449,
11965,
267,
1709,
14,
362,
63,
5181,
342,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
291,
339,
347,
636,
2184,
721,
277,
304,
267,
408,
8666,
2740,
1409,
1553,
372,
314,
2163,
1242,
315,
314,
2547,
624,
267,
746,
4279,
339,
2163,
275,
636,
2184,
363,
3777,
327,
2018,
499,
7163,
199,
199,
533,
1487,
8397,
1692,
8,
785,
304,
272,
408,
272,
437,
13256,
1402,
14,
339,
10082,
1183,
282,
3970,
367,
17573,
314,
876,
13,
8420,
13256,
666,
3180,
272,
543,
314,
5002,
13,
475,
13,
3479,
666,
6290,
543,
314,
909,
14,
339,
6523,
1124,
2117,
8497,
370,
3354,
314,
909,
334,
1045,
314,
5002,
13,
475,
13,
3479,
666,
9,
370,
314,
272,
3050,
27,
1240,
1124,
2117,
8,
2117,
63,
77,
18,
77,
29,
797,
9719,
370,
3354,
2951,
314,
909,
1504,
272,
334,
460,
440,
12943,
314,
5002,
13,
475,
13,
3479,
8292,
4959,
272,
408,
339,
347,
636,
826,
721,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
BryanCutler/spark
|
examples/src/main/python/mllib/recommendation_example.py
|
27
|
2015
|
#
# 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.
#
"""
Collaborative Filtering Classification Example.
"""
from pyspark import SparkContext
# $example on$
from pyspark.mllib.recommendation import ALS, MatrixFactorizationModel, Rating
# $example off$
if __name__ == "__main__":
sc = SparkContext(appName="PythonCollaborativeFilteringExample")
# $example on$
# Load and parse the data
data = sc.textFile("data/mllib/als/test.data")
ratings = data.map(lambda l: l.split(','))\
.map(lambda l: Rating(int(l[0]), int(l[1]), float(l[2])))
# Build the recommendation model using Alternating Least Squares
rank = 10
numIterations = 10
model = ALS.train(ratings, rank, numIterations)
# Evaluate the model on training data
testdata = ratings.map(lambda p: (p[0], p[1]))
predictions = model.predictAll(testdata).map(lambda r: ((r[0], r[1]), r[2]))
ratesAndPreds = ratings.map(lambda r: ((r[0], r[1]), r[2])).join(predictions)
MSE = ratesAndPreds.map(lambda r: (r[1][0] - r[1][1])**2).mean()
print("Mean Squared Error = " + str(MSE))
# Save and load model
model.save(sc, "target/tmp/myCollaborativeFilter")
sameModel = MatrixFactorizationModel.load(sc, "target/tmp/myCollaborativeFilter")
# $example off$
|
apache-2.0
|
[
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
624,
199,
2001,
5561,
269,
1905,
9388,
316,
8465,
7789,
5679,
14,
199,
624,
199,
504,
15847,
492,
21769,
199,
199,
3,
2672,
2694,
641,
4,
199,
504,
15847,
14,
25598,
14,
264,
22105,
492,
437,
5296,
12,
8449,
12666,
2072,
1685,
12,
820,
1958,
199,
3,
2672,
2694,
2331,
4,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
4061,
275,
21769,
8,
571,
985,
628,
4718,
2001,
5561,
269,
1905,
4131,
316,
9846,
531,
272,
327,
2672,
2694,
641,
4,
272,
327,
7190,
436,
2198,
314,
666,
272,
666,
275,
4061,
14,
505,
1173,
480,
576,
15,
25598,
15,
2551,
15,
396,
14,
576,
531,
272,
32026,
780,
275,
666,
14,
1130,
8,
2734,
634,
26,
634,
14,
1294,
5102,
1333,
60,
267,
1275,
1130,
8,
2734,
634,
26,
820,
1958,
8,
442,
8,
76,
59,
16,
2522,
1109,
8,
76,
59,
17,
2522,
2069,
8,
76,
59,
18,
11845,
339,
327,
6516,
314,
295,
22105,
1402,
1808,
17669,
1958,
7005,
1810,
428,
392,
11044,
272,
6915,
275,
1616,
272,
1967,
26292,
275,
1616,
272,
1402,
275,
437,
5296,
14,
2834,
8,
17565,
780,
12,
6915,
12,
1967,
26292,
9,
339,
327,
27450,
314,
1402,
641,
6093,
666,
272,
511,
576,
275,
32026,
780,
14,
1130,
8,
2734,
299,
26,
334,
80,
59,
16,
467,
299,
59,
17,
2459,
272,
7914,
275,
1402,
14,
6892,
2422,
8,
18481,
680,
1130,
8,
2734,
519,
26,
3666,
82,
59,
16,
467,
519,
59,
17,
2522,
519,
59,
18,
2459,
272,
24434,
3325,
48,
10428,
275,
32026,
780,
14,
1130,
8,
2734,
519,
26,
3666,
82,
59,
16,
467,
519,
59,
17,
2522,
519,
59,
18,
2459,
14,
904,
8,
9869,
9,
272,
603,
899,
275,
24434,
3325,
48,
10428,
14,
1130,
8,
2734,
519,
26,
334,
82,
59,
17,
1527,
16,
61,
446,
519,
59,
17,
1527,
17,
566,
538,
18,
680,
3670,
342,
272,
870,
480,
14825,
428,
30458,
4520,
275,
298,
435,
620,
8,
45,
899,
430,
339,
327,
11063,
436,
2248,
1402,
272,
1402,
14,
2117,
8,
551,
12,
298,
1375,
15,
2791,
15,
1662,
2001,
5561,
269,
1905,
4131,
531,
272,
2011,
1685,
275,
8449,
12666,
2072,
1685,
14,
912,
8,
551,
12,
298,
1375,
15,
2791,
15,
1662,
2001,
5561,
269,
1905,
4131,
531,
272,
327,
2672,
2694,
2331,
4,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
624,
199,
2001,
5561,
269,
1905,
9388,
316,
8465,
7789,
5679,
14,
199,
624,
199,
504,
15847,
492,
21769,
199,
199,
3,
2672,
2694,
641,
4,
199,
504,
15847,
14,
25598,
14,
264,
22105,
492,
437,
5296,
12,
8449,
12666,
2072,
1685,
12,
820,
1958,
199,
3,
2672,
2694,
2331,
4,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
4061,
275,
21769,
8,
571,
985,
628,
4718,
2001,
5561,
269,
1905,
4131,
316,
9846,
531,
272,
327,
2672,
2694,
641,
4,
272,
327,
7190,
436,
2198,
314,
666,
272,
666,
275,
4061,
14,
505,
1173,
480,
576,
15,
25598,
15,
2551,
15,
396,
14,
576,
531,
272,
32026,
780,
275,
666,
14,
1130,
8,
2734,
634,
26,
634,
14,
1294,
5102,
1333,
60,
267,
1275,
1130,
8,
2734,
634,
26,
820,
1958,
8,
442,
8,
76,
59,
16,
2522,
1109,
8,
76,
59,
17,
2522,
2069,
8,
76,
59,
18,
11845,
339,
327,
6516,
314,
295,
22105,
1402,
1808,
17669,
1958,
7005,
1810,
428,
392,
11044,
272,
6915,
275,
1616,
272,
1967,
26292,
275,
1616,
272,
1402,
275,
437,
5296,
14,
2834,
8,
17565,
780,
12,
6915,
12,
1967,
26292,
9,
339,
327,
27450,
314,
1402,
641,
6093,
666,
272,
511,
576,
275,
32026,
780,
14,
1130,
8,
2734,
299,
26,
334,
80,
59,
16,
467,
299,
59,
17,
2459,
272,
7914,
275,
1402,
14,
6892,
2422,
8,
18481,
680,
1130,
8,
2734,
519,
26,
3666,
82,
59,
16,
467,
519,
59,
17,
2522,
519,
59,
18,
2459,
272,
24434,
3325,
48,
10428,
275,
32026,
780,
14,
1130,
8,
2734,
519,
26,
3666,
82,
59,
16,
467,
519,
59,
17,
2522,
519,
59,
18,
2459,
14,
904,
8,
9869,
9,
272,
603,
899,
275,
24434,
3325,
48,
10428,
14,
1130,
8,
2734,
519,
26,
334,
82,
59,
17,
1527,
16,
61,
446,
519,
59,
17,
1527,
17,
566,
538,
18,
680,
3670,
342,
272,
870,
480,
14825,
428,
30458,
4520,
275,
298,
435,
620,
8,
45,
899,
430,
339,
327,
11063,
436,
2248,
1402,
272,
1402,
14,
2117,
8,
551,
12,
298,
1375,
15,
2791,
15,
1662,
2001,
5561,
269,
1905,
4131,
531,
272,
2011,
1685,
275,
8449,
12666,
2072,
1685,
14,
912,
8,
551,
12,
298,
1375,
15,
2791,
15,
1662,
2001,
5561,
269,
1905,
4131,
531,
272,
327,
2672,
2694,
2331,
4,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
adalke/rdkit
|
rdkit/ML/Descriptors/UnitTestDescriptors.py
|
4
|
1337
|
#
# Copyright (C) 2001,2002 greg Landrum and Rational Discovery LLC
#
""" unit testing code for descriptors
"""
import unittest
from rdkit.ML.Descriptors import CompoundDescriptors
from rdkit.six.moves import xrange
class TestCase(unittest.TestCase):
def setUp(self):
d = [('DED',['NonZero','Mean','Dev']),
('M_B_electroneg',['NonZero']),
('Cov_rad',['Max','Min'])]
self.desc = CompoundDescriptors.CompoundDescriptorCalculator(d)
self.desc.BuildAtomDict()
self.tol = 0.0001
def testAtomDict(self):
" testing the atom dict "
assert len(self.desc.atomDict.keys())==48,'BuildAtomDict failed'
def testSimpleDescriptorCalc(self):
" testing simple descriptor calculation "
composList = ['Nb','Nb3','NbPt','Nb2Pt']
compare = [[2.32224798203, 0.0, 1.34000003338, 1.34000003338],
[2.32224798203, 0.0, 1.34000003338, 1.34000003338],
[1.51555249095, 0.806695491076, 1.34000003338, 1.29999995232],
[1.78445098797, 0.717062658734, 1.34000003338, 1.29999995232]]
for i in xrange(len(composList)):
assert max(map(lambda x,y:abs(x-y),compare[i],
self.desc.CalcSimpleDescriptorsForComposition(composList[i]))) < self.tol,\
'Descriptor calculation failed'
if __name__ == '__main__':
unittest.main()
|
bsd-3-clause
|
[
3,
199,
3,
221,
1898,
334,
35,
9,
12521,
12,
15135,
221,
486,
1135,
491,
460,
28430,
436,
20164,
5289,
6913,
20376,
199,
3,
199,
199,
624,
4137,
5343,
1233,
367,
15428,
199,
199,
624,
199,
646,
2882,
199,
504,
11517,
6065,
14,
1698,
14,
2586,
30547,
492,
3599,
1034,
2586,
30547,
199,
504,
11517,
6065,
14,
4174,
14,
4912,
492,
4945,
16872,
199,
533,
7640,
8,
2796,
14,
1746,
304,
523,
347,
3613,
8,
277,
304,
272,
366,
275,
4274,
8280,
297,
459,
6932,
8681,
1673,
14825,
1673,
12680,
3815,
268,
661,
45,
63,
34,
63,
26334,
82,
368,
71,
297,
459,
6932,
8681,
3815,
268,
661,
967,
86,
63,
9525,
297,
459,
4261,
1673,
4649,
24437,
272,
291,
14,
3257,
275,
3599,
1034,
2586,
30547,
14,
26552,
4311,
20000,
8,
68,
9,
272,
291,
14,
3257,
14,
3425,
12097,
2141,
342,
272,
291,
14,
6896,
275,
378,
14,
4183,
819,
347,
511,
12097,
2141,
8,
277,
304,
272,
298,
5343,
314,
6222,
1211,
298,
2286,
702,
822,
8,
277,
14,
3257,
14,
4188,
2141,
14,
1612,
1012,
389,
2006,
2584,
3425,
12097,
2141,
3405,
7,
523,
347,
511,
3184,
4311,
19511,
8,
277,
304,
272,
298,
5343,
3486,
5872,
15232,
298,
272,
1013,
736,
1296,
275,
788,
26183,
1673,
26183,
19,
1673,
26183,
19886,
1673,
26183,
18,
19886,
418,
272,
6540,
275,
3474,
18,
14,
708,
8731,
16564,
11341,
12,
378,
14,
16,
12,
413,
14,
1082,
5345,
1153,
1703,
12,
413,
14,
1082,
5345,
1153,
1703,
467,
1779,
359,
18,
14,
708,
8731,
16564,
11341,
12,
378,
14,
16,
12,
413,
14,
1082,
5345,
1153,
1703,
12,
413,
14,
1082,
5345,
1153,
1703,
467,
1779,
359,
17,
14,
28082,
1229,
11032,
19113,
12,
378,
14,
1257,
15014,
15419,
709,
2114,
12,
413,
14,
1082,
5345,
1153,
1703,
12,
413,
14,
18,
20036,
2528,
708,
467,
1779,
359,
17,
14,
23,
16042,
6576,
1555,
2576,
12,
378,
14,
31462,
1690,
13730,
1555,
1082,
12,
413,
14,
1082,
5345,
1153,
1703,
12,
413,
14,
18,
20036,
2528,
708,
2677,
272,
367,
284,
315,
4945,
8,
552,
8,
863,
736,
1296,
2298,
489,
702,
1390,
8,
1130,
8,
2734,
671,
12,
89,
26,
2101,
8,
88,
13,
89,
395,
5785,
59,
73,
467,
2151,
291,
14,
3257,
14,
19511,
3184,
2586,
30547,
1858,
30099,
8,
863,
736,
1296,
59,
73,
11845,
665,
291,
14,
6896,
4202,
489,
283,
4311,
15232,
3405,
7,
2126,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
221,
1898,
334,
35,
9,
12521,
12,
15135,
221,
486,
1135,
491,
460,
28430,
436,
20164,
5289,
6913,
20376,
199,
3,
199,
199,
624,
4137,
5343,
1233,
367,
15428,
199,
199,
624,
199,
646,
2882,
199,
504,
11517,
6065,
14,
1698,
14,
2586,
30547,
492,
3599,
1034,
2586,
30547,
199,
504,
11517,
6065,
14,
4174,
14,
4912,
492,
4945,
16872,
199,
533,
7640,
8,
2796,
14,
1746,
304,
523,
347,
3613,
8,
277,
304,
272,
366,
275,
4274,
8280,
297,
459,
6932,
8681,
1673,
14825,
1673,
12680,
3815,
268,
661,
45,
63,
34,
63,
26334,
82,
368,
71,
297,
459,
6932,
8681,
3815,
268,
661,
967,
86,
63,
9525,
297,
459,
4261,
1673,
4649,
24437,
272,
291,
14,
3257,
275,
3599,
1034,
2586,
30547,
14,
26552,
4311,
20000,
8,
68,
9,
272,
291,
14,
3257,
14,
3425,
12097,
2141,
342,
272,
291,
14,
6896,
275,
378,
14,
4183,
819,
347,
511,
12097,
2141,
8,
277,
304,
272,
298,
5343,
314,
6222,
1211,
298,
2286,
702,
822,
8,
277,
14,
3257,
14,
4188,
2141,
14,
1612,
1012,
389,
2006,
2584,
3425,
12097,
2141,
3405,
7,
523,
347,
511,
3184,
4311,
19511,
8,
277,
304,
272,
298,
5343,
3486,
5872,
15232,
298,
272,
1013,
736,
1296,
275,
788,
26183,
1673,
26183,
19,
1673,
26183,
19886,
1673,
26183,
18,
19886,
418,
272,
6540,
275,
3474,
18,
14,
708,
8731,
16564,
11341,
12,
378,
14,
16,
12,
413,
14,
1082,
5345,
1153,
1703,
12,
413,
14,
1082,
5345,
1153,
1703,
467,
1779,
359,
18,
14,
708,
8731,
16564,
11341,
12,
378,
14,
16,
12,
413,
14,
1082,
5345,
1153,
1703,
12,
413,
14,
1082,
5345,
1153,
1703,
467,
1779,
359,
17,
14,
28082,
1229,
11032,
19113,
12,
378,
14,
1257,
15014,
15419,
709,
2114,
12,
413,
14,
1082,
5345,
1153,
1703,
12,
413,
14,
18,
20036,
2528,
708,
467,
1779,
359,
17,
14,
23,
16042,
6576,
1555,
2576,
12,
378,
14,
31462,
1690,
13730,
1555,
1082,
12,
413,
14,
1082,
5345,
1153,
1703,
12,
413,
14,
18,
20036,
2528,
708,
2677,
272,
367,
284,
315,
4945,
8,
552,
8,
863,
736,
1296,
2298,
489,
702,
1390,
8,
1130,
8,
2734,
671,
12,
89,
26,
2101,
8,
88,
13,
89,
395,
5785,
59,
73,
467,
2151,
291,
14,
3257,
14,
19511,
3184,
2586,
30547,
1858,
30099,
8,
863,
736,
1296,
59,
73,
11845,
665,
291,
14,
6896,
4202,
489,
283,
4311,
15232,
3405,
7,
2126,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
benpatterson/edx-platform
|
lms/djangoapps/instructor/management/commands/openended_post.py
|
86
|
4626
|
"""
Command to manually re-post open ended submissions to the grader.
"""
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand
from optparse import make_option
from xmodule.modulestore.django import modulestore
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xmodule.open_ended_grading_classes.openendedchild import OpenEndedChild
from xmodule.open_ended_grading_classes.open_ended_module import OpenEndedModule
from courseware.courses import get_course
from instructor.utils import get_module_for_student
class Command(BaseCommand):
"""
Command to manually re-post open ended submissions to the grader.
"""
help = ("Usage: openended_post <course_id> <problem_location> <student_ids.txt> <hostname> --dry-run --task-number=<task_number>\n"
"The text file should contain a User.id in each line.")
option_list = BaseCommand.option_list + (
make_option('-n', '--dry-run',
action='store_true', dest='dry_run', default=False,
help="Do everything except send the submission to the grader. "),
make_option('--task-number',
type='int', default=0,
help="Task number that needs to be submitted."),
)
def handle(self, *args, **options):
dry_run = options['dry_run']
task_number = options['task_number']
if len(args) == 4:
course_id = SlashSeparatedCourseKey.from_deprecated_string(args[0])
location = course_id.make_usage_key_from_deprecated_string(args[1])
students_ids = [line.strip() for line in open(args[2])]
hostname = args[3]
else:
print self.help
return
try:
course = get_course(course_id)
except ValueError as err:
print err
return
descriptor = modulestore().get_item(location, depth=0)
if descriptor is None:
print "Location not found in course"
return
if dry_run:
print "Doing a dry run."
students = User.objects.filter(id__in=students_ids).order_by('username')
print "Number of students: {0}".format(students.count())
for student in students:
post_submission_for_student(student, course, location, task_number, dry_run=dry_run, hostname=hostname)
def post_submission_for_student(student, course, location, task_number, dry_run=True, hostname=None):
"""If the student's task child_state is ASSESSING post submission to grader."""
print "{0}:{1}".format(student.id, student.username)
request = DummyRequest()
request.user = student
request.host = hostname
try:
module = get_module_for_student(student, location, request=request, course=course)
if module is None:
print " WARNING: No state found."
return False
latest_task = module.child_module.get_task_number(task_number)
if latest_task is None:
print " WARNING: No task state found."
return False
if not isinstance(latest_task, OpenEndedModule):
print " ERROR: Not an OpenEndedModule task."
return False
latest_task_state = latest_task.child_state
if latest_task_state == OpenEndedChild.INITIAL:
print " WARNING: No submission."
elif latest_task_state == OpenEndedChild.POST_ASSESSMENT or latest_task_state == OpenEndedChild.DONE:
print " WARNING: Submission already graded."
elif latest_task_state == OpenEndedChild.ASSESSING:
latest_answer = latest_task.latest_answer()
if dry_run:
print " Skipped sending submission to grader: {0!r}".format(latest_answer[:100].encode('utf-8'))
else:
latest_task.send_to_grader(latest_answer, latest_task.system)
print " Sent submission to grader: {0!r}".format(latest_answer[:100].encode('utf-8'))
return True
else:
print "WARNING: Invalid task_state: {0}".format(latest_task_state)
except Exception as err: # pylint: disable=broad-except
print err
return False
class DummyRequest(object):
"""Dummy request"""
META = {}
def __init__(self):
self.session = {}
self.user = None
self.host = None
self.secure = True
def get_host(self):
"""Return a default host."""
return self.host
def is_secure(self):
"""Always secure."""
return self.secure
|
agpl-3.0
|
[
624,
199,
3110,
370,
10250,
295,
13,
1932,
1551,
22480,
30399,
370,
314,
27741,
14,
199,
624,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
199,
504,
8691,
492,
1852,
63,
1422,
199,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
30687,
199,
504,
9872,
14,
1490,
63,
8960,
63,
16050,
63,
2888,
14,
1490,
8960,
1739,
492,
3232,
32615,
3493,
199,
504,
9872,
14,
1490,
63,
8960,
63,
16050,
63,
2888,
14,
1490,
63,
8960,
63,
578,
492,
3232,
32615,
2377,
199,
199,
504,
20736,
14,
11653,
492,
664,
63,
1972,
199,
199,
504,
17724,
14,
1208,
492,
664,
63,
578,
63,
509,
63,
5500,
421,
199,
533,
5817,
8,
25150,
304,
272,
408,
272,
5817,
370,
10250,
295,
13,
1932,
1551,
22480,
30399,
370,
314,
27741,
14,
272,
408,
339,
1720,
275,
1689,
7692,
26,
1551,
8960,
63,
1932,
665,
1972,
63,
344,
30,
665,
6462,
63,
1985,
30,
665,
5500,
63,
1580,
14,
2424,
30,
665,
4269,
30,
1553,
10481,
13,
1065,
1553,
1765,
13,
1955,
18987,
1765,
63,
1955,
3072,
78,
2,
288,
298,
1918,
1318,
570,
1077,
1395,
282,
2876,
14,
344,
315,
1924,
1004,
2685,
339,
945,
63,
513,
275,
22239,
14,
1422,
63,
513,
435,
334,
267,
1852,
63,
1422,
3654,
78,
297,
2850,
10481,
13,
1065,
297,
490,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
10481,
63,
1065,
297,
849,
29,
797,
12,
490,
1720,
628,
2585,
8137,
871,
3222,
314,
13071,
370,
314,
27741,
14,
26261,
267,
1852,
63,
1422,
4517,
1765,
13,
1955,
297,
490,
730,
534,
442,
297,
849,
29,
16,
12,
490,
1720,
628,
4476,
1329,
626,
4839,
370,
506,
16930,
7651,
272,
776,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
398,
9951,
63,
1065,
275,
1511,
459,
10481,
63,
1065,
418,
267,
2120,
63,
1955,
275,
1511,
459,
1765,
63,
1955,
418,
398,
340,
822,
8,
589,
9,
508,
841,
26,
288,
2518,
63,
344,
275,
30687,
14,
504,
63,
6667,
63,
875,
8,
589,
59,
16,
566,
288,
2909,
275,
2518,
63,
344,
14,
1875,
63,
3807,
63,
498,
63,
504,
63,
6667,
63,
875,
8,
589,
59,
17,
566,
288,
18557,
63,
1580,
275,
359,
604,
14,
1913,
342,
367,
1004,
315,
1551,
8,
589,
59,
18,
12457,
288,
6246,
275,
1249,
59,
19,
61,
267,
587,
26,
288,
870,
291,
14,
3437,
288,
372,
398,
862,
26,
288,
2518,
275,
664,
63,
1972,
8,
1972,
63,
344,
9,
267,
871,
1722,
465,
2329,
26,
288,
870,
2329,
288,
372,
398,
5872,
275,
10996,
1252,
362,
63,
1053,
8,
1985,
12,
5818,
29,
16,
9,
267,
340,
5872,
365,
488,
26,
288,
870,
298,
6592,
440,
1911,
315,
2518,
2,
288,
372,
398,
340,
9951,
63,
1065,
26,
288,
870,
298,
2585,
316,
282,
9951,
1255,
2122,
398,
18557,
275,
2876,
14,
1462,
14,
1541,
8,
344,
363,
262,
29,
17921,
63,
1580,
680,
1648,
63,
991,
360,
2473,
358,
267,
870,
298,
3259,
402,
18557,
26,
469,
16,
5469,
908,
8,
17921,
14,
835,
1012,
398,
367,
6474,
315,
18557,
26,
288,
2963,
63,
12542,
63,
509,
63,
5500,
8,
5500,
12,
2518,
12,
2909,
12,
2120,
63,
1955,
12,
9951,
63,
1065,
29,
10481,
63,
1065,
12,
6246,
29,
4269,
9,
421,
199,
318,
2963,
63,
12542,
63,
509,
63,
5500,
8,
5500,
12,
2518,
12,
2909,
12,
2120,
63,
1955,
12,
9951,
63,
1065,
29,
549,
12,
6246,
29,
403,
304,
272,
408,
3917,
314,
6474,
1159,
2120,
1982,
63,
929,
365,
17567,
1608,
1206,
2963,
13071,
370,
27741,
1041,
339,
870,
5310,
16,
16495,
17,
5469,
908,
8,
5500,
14,
344,
12,
6474,
14,
2473,
9,
339,
1056,
275,
9762,
2017,
342,
272,
1056,
14,
751,
275,
6474,
272,
1056,
14,
1102,
275,
6246,
339,
862,
26,
267,
859,
275,
664,
63,
578,
63,
509,
63,
5500,
8,
5500,
12,
2909,
12,
1056,
29,
1069,
12,
2518,
29,
1972,
9,
267,
340,
859,
365,
488,
26,
288,
870,
298,
221,
14750,
26,
3091,
1174,
1911,
2122,
288,
372,
756,
398,
8839,
63,
1765,
275,
859,
14,
1739,
63,
578,
14,
362,
63,
1765,
63,
1955,
8,
1765,
63,
1955,
9,
267,
340,
8839,
63,
1765,
365,
488,
26,
288,
870,
298,
221,
14750,
26,
3091,
2120,
1174,
1911,
2122,
288,
372,
756,
398,
340,
440,
1228,
8,
7410,
63,
1765,
12,
3232,
32615,
2377,
304,
288,
870,
298,
12539,
26,
2832,
376,
3232,
32615,
2377,
2120,
2122,
288,
372,
756,
398,
8839,
63,
1765,
63,
929,
275,
8839,
63,
1765,
14,
1739,
63,
929,
398,
340,
8839,
63,
1765,
63,
929,
508,
3232,
32615,
3493,
14,
13768,
26,
288,
870,
298,
221,
14750,
26,
3091,
13071,
2122,
267,
916,
8839,
63,
1765,
63,
929,
508,
3232,
32615,
3493,
14,
4030,
63,
3755,
1608,
4479,
503,
8839,
63,
1765,
63,
929,
508,
3232,
32615,
3493,
14,
22162,
26,
288,
870,
298,
221,
14750,
26,
4804,
2250,
2575,
1999,
770,
2122,
267,
916,
8839,
63,
1765,
63,
929,
508,
3232,
32615,
3493,
14,
3755,
1608,
1206,
26,
288,
8839,
63,
5934,
275,
8839,
63,
1765,
14,
7410,
63,
5934,
342,
288,
340,
9951,
63,
1065,
26,
355,
870,
298,
221,
8232,
1915,
10209,
13071,
370,
27741,
26,
469,
16,
1,
82,
5469,
908,
8,
7410,
63,
5934,
1491,
1960,
1055,
2143,
360,
1624,
13,
24,
1333,
288,
587,
26,
355,
8839,
63,
1765,
14,
2254,
63,
475,
63,
17556,
8,
7410,
63,
5934,
12,
8839,
63,
1765,
14,
2253,
9,
355,
870,
298,
221,
428,
484,
13071,
370,
27741,
26,
469,
16,
1,
82,
5469,
908,
8,
7410,
63,
5934,
1491,
1960,
1055,
2143,
360,
1624,
13,
24,
1333,
355,
372,
715,
267,
587,
26,
288,
870,
298,
9171,
26,
6378,
2120,
63,
929,
26,
469,
16,
5469,
908,
8,
7410,
63,
1765,
63,
929,
9,
272,
871,
2186,
465,
2329,
26,
221,
327,
4287,
26,
3507,
29,
29047,
13,
2590,
267,
870,
2329,
339,
372,
756,
421,
199,
533,
9762,
2017,
8,
785,
304,
272
] |
[
199,
3110,
370,
10250,
295,
13,
1932,
1551,
22480,
30399,
370,
314,
27741,
14,
199,
624,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
199,
504,
8691,
492,
1852,
63,
1422,
199,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
30687,
199,
504,
9872,
14,
1490,
63,
8960,
63,
16050,
63,
2888,
14,
1490,
8960,
1739,
492,
3232,
32615,
3493,
199,
504,
9872,
14,
1490,
63,
8960,
63,
16050,
63,
2888,
14,
1490,
63,
8960,
63,
578,
492,
3232,
32615,
2377,
199,
199,
504,
20736,
14,
11653,
492,
664,
63,
1972,
199,
199,
504,
17724,
14,
1208,
492,
664,
63,
578,
63,
509,
63,
5500,
421,
199,
533,
5817,
8,
25150,
304,
272,
408,
272,
5817,
370,
10250,
295,
13,
1932,
1551,
22480,
30399,
370,
314,
27741,
14,
272,
408,
339,
1720,
275,
1689,
7692,
26,
1551,
8960,
63,
1932,
665,
1972,
63,
344,
30,
665,
6462,
63,
1985,
30,
665,
5500,
63,
1580,
14,
2424,
30,
665,
4269,
30,
1553,
10481,
13,
1065,
1553,
1765,
13,
1955,
18987,
1765,
63,
1955,
3072,
78,
2,
288,
298,
1918,
1318,
570,
1077,
1395,
282,
2876,
14,
344,
315,
1924,
1004,
2685,
339,
945,
63,
513,
275,
22239,
14,
1422,
63,
513,
435,
334,
267,
1852,
63,
1422,
3654,
78,
297,
2850,
10481,
13,
1065,
297,
490,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
10481,
63,
1065,
297,
849,
29,
797,
12,
490,
1720,
628,
2585,
8137,
871,
3222,
314,
13071,
370,
314,
27741,
14,
26261,
267,
1852,
63,
1422,
4517,
1765,
13,
1955,
297,
490,
730,
534,
442,
297,
849,
29,
16,
12,
490,
1720,
628,
4476,
1329,
626,
4839,
370,
506,
16930,
7651,
272,
776,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
398,
9951,
63,
1065,
275,
1511,
459,
10481,
63,
1065,
418,
267,
2120,
63,
1955,
275,
1511,
459,
1765,
63,
1955,
418,
398,
340,
822,
8,
589,
9,
508,
841,
26,
288,
2518,
63,
344,
275,
30687,
14,
504,
63,
6667,
63,
875,
8,
589,
59,
16,
566,
288,
2909,
275,
2518,
63,
344,
14,
1875,
63,
3807,
63,
498,
63,
504,
63,
6667,
63,
875,
8,
589,
59,
17,
566,
288,
18557,
63,
1580,
275,
359,
604,
14,
1913,
342,
367,
1004,
315,
1551,
8,
589,
59,
18,
12457,
288,
6246,
275,
1249,
59,
19,
61,
267,
587,
26,
288,
870,
291,
14,
3437,
288,
372,
398,
862,
26,
288,
2518,
275,
664,
63,
1972,
8,
1972,
63,
344,
9,
267,
871,
1722,
465,
2329,
26,
288,
870,
2329,
288,
372,
398,
5872,
275,
10996,
1252,
362,
63,
1053,
8,
1985,
12,
5818,
29,
16,
9,
267,
340,
5872,
365,
488,
26,
288,
870,
298,
6592,
440,
1911,
315,
2518,
2,
288,
372,
398,
340,
9951,
63,
1065,
26,
288,
870,
298,
2585,
316,
282,
9951,
1255,
2122,
398,
18557,
275,
2876,
14,
1462,
14,
1541,
8,
344,
363,
262,
29,
17921,
63,
1580,
680,
1648,
63,
991,
360,
2473,
358,
267,
870,
298,
3259,
402,
18557,
26,
469,
16,
5469,
908,
8,
17921,
14,
835,
1012,
398,
367,
6474,
315,
18557,
26,
288,
2963,
63,
12542,
63,
509,
63,
5500,
8,
5500,
12,
2518,
12,
2909,
12,
2120,
63,
1955,
12,
9951,
63,
1065,
29,
10481,
63,
1065,
12,
6246,
29,
4269,
9,
421,
199,
318,
2963,
63,
12542,
63,
509,
63,
5500,
8,
5500,
12,
2518,
12,
2909,
12,
2120,
63,
1955,
12,
9951,
63,
1065,
29,
549,
12,
6246,
29,
403,
304,
272,
408,
3917,
314,
6474,
1159,
2120,
1982,
63,
929,
365,
17567,
1608,
1206,
2963,
13071,
370,
27741,
1041,
339,
870,
5310,
16,
16495,
17,
5469,
908,
8,
5500,
14,
344,
12,
6474,
14,
2473,
9,
339,
1056,
275,
9762,
2017,
342,
272,
1056,
14,
751,
275,
6474,
272,
1056,
14,
1102,
275,
6246,
339,
862,
26,
267,
859,
275,
664,
63,
578,
63,
509,
63,
5500,
8,
5500,
12,
2909,
12,
1056,
29,
1069,
12,
2518,
29,
1972,
9,
267,
340,
859,
365,
488,
26,
288,
870,
298,
221,
14750,
26,
3091,
1174,
1911,
2122,
288,
372,
756,
398,
8839,
63,
1765,
275,
859,
14,
1739,
63,
578,
14,
362,
63,
1765,
63,
1955,
8,
1765,
63,
1955,
9,
267,
340,
8839,
63,
1765,
365,
488,
26,
288,
870,
298,
221,
14750,
26,
3091,
2120,
1174,
1911,
2122,
288,
372,
756,
398,
340,
440,
1228,
8,
7410,
63,
1765,
12,
3232,
32615,
2377,
304,
288,
870,
298,
12539,
26,
2832,
376,
3232,
32615,
2377,
2120,
2122,
288,
372,
756,
398,
8839,
63,
1765,
63,
929,
275,
8839,
63,
1765,
14,
1739,
63,
929,
398,
340,
8839,
63,
1765,
63,
929,
508,
3232,
32615,
3493,
14,
13768,
26,
288,
870,
298,
221,
14750,
26,
3091,
13071,
2122,
267,
916,
8839,
63,
1765,
63,
929,
508,
3232,
32615,
3493,
14,
4030,
63,
3755,
1608,
4479,
503,
8839,
63,
1765,
63,
929,
508,
3232,
32615,
3493,
14,
22162,
26,
288,
870,
298,
221,
14750,
26,
4804,
2250,
2575,
1999,
770,
2122,
267,
916,
8839,
63,
1765,
63,
929,
508,
3232,
32615,
3493,
14,
3755,
1608,
1206,
26,
288,
8839,
63,
5934,
275,
8839,
63,
1765,
14,
7410,
63,
5934,
342,
288,
340,
9951,
63,
1065,
26,
355,
870,
298,
221,
8232,
1915,
10209,
13071,
370,
27741,
26,
469,
16,
1,
82,
5469,
908,
8,
7410,
63,
5934,
1491,
1960,
1055,
2143,
360,
1624,
13,
24,
1333,
288,
587,
26,
355,
8839,
63,
1765,
14,
2254,
63,
475,
63,
17556,
8,
7410,
63,
5934,
12,
8839,
63,
1765,
14,
2253,
9,
355,
870,
298,
221,
428,
484,
13071,
370,
27741,
26,
469,
16,
1,
82,
5469,
908,
8,
7410,
63,
5934,
1491,
1960,
1055,
2143,
360,
1624,
13,
24,
1333,
355,
372,
715,
267,
587,
26,
288,
870,
298,
9171,
26,
6378,
2120,
63,
929,
26,
469,
16,
5469,
908,
8,
7410,
63,
1765,
63,
929,
9,
272,
871,
2186,
465,
2329,
26,
221,
327,
4287,
26,
3507,
29,
29047,
13,
2590,
267,
870,
2329,
339,
372,
756,
421,
199,
533,
9762,
2017,
8,
785,
304,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
eltonkevani/tempest_el_env
|
tempest/cli/simple_read_only/test_nova.py
|
3
|
5477
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 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.
import subprocess
from oslo.config import cfg
import testtools
import tempest.cli
from tempest.openstack.common import log as logging
import tempest.test
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
class SimpleReadOnlyNovaClientTest(tempest.cli.ClientTestBase):
"""
This is a first pass at a simple read only python-novaclient test. This
only exercises client commands that are read only.
This should test commands:
* as a regular user
* as a admin user
* with and without optional parameters
* initially just check return codes, and later test command outputs
"""
def test_admin_fake_action(self):
self.assertRaises(subprocess.CalledProcessError,
self.nova,
'this-does-nova-exist')
# NOTE(jogo): Commands in order listed in 'nova help'
# Positional arguments:
def test_admin_absolute_limites(self):
self.nova('absolute-limits')
self.nova('absolute-limits', params='--reserved')
def test_admin_aggregate_list(self):
self.nova('aggregate-list')
def test_admin_availability_zone_list(self):
self.assertIn("internal", self.nova('availability-zone-list'))
def test_admin_cloudpipe_list(self):
self.nova('cloudpipe-list')
def test_admin_credentials(self):
self.nova('credentials')
@testtools.skipIf(CONF.service_available.neutron,
"Neutron does not provide this feature")
def test_admin_dns_domains(self):
self.nova('dns-domains')
@tempest.test.skip_because(bug="1157349")
def test_admin_dns_list(self):
self.nova('dns-list')
def test_admin_endpoints(self):
self.nova('endpoints')
def test_admin_flavor_acces_list(self):
self.assertRaises(subprocess.CalledProcessError,
self.nova,
'flavor-access-list')
# Failed to get access list for public flavor type
self.assertRaises(subprocess.CalledProcessError,
self.nova,
'flavor-access-list',
params='--flavor m1.tiny')
def test_admin_flavor_list(self):
self.assertIn("Memory_MB", self.nova('flavor-list'))
def test_admin_floating_ip_bulk_list(self):
self.nova('floating-ip-bulk-list')
def test_admin_floating_ip_list(self):
self.nova('floating-ip-list')
def test_admin_floating_ip_pool_list(self):
self.nova('floating-ip-pool-list')
def test_admin_host_list(self):
self.nova('host-list')
def test_admin_hypervisor_list(self):
self.nova('hypervisor-list')
def test_admin_image_list(self):
self.nova('image-list')
@tempest.test.skip_because(bug="1157349")
def test_admin_interface_list(self):
self.nova('interface-list')
def test_admin_keypair_list(self):
self.nova('keypair-list')
def test_admin_list(self):
self.nova('list')
self.nova('list', params='--all-tenants 1')
self.nova('list', params='--all-tenants 0')
self.assertRaises(subprocess.CalledProcessError,
self.nova,
'list',
params='--all-tenants bad')
def test_admin_network_list(self):
self.nova('network-list')
def test_admin_rate_limits(self):
self.nova('rate-limits')
def test_admin_secgroup_list(self):
self.nova('secgroup-list')
@tempest.test.skip_because(bug="1157349")
def test_admin_secgroup_list_rules(self):
self.nova('secgroup-list-rules')
def test_admin_servce_list(self):
self.nova('service-list')
def test_admin_usage(self):
self.nova('usage')
def test_admin_usage_list(self):
self.nova('usage-list')
def test_admin_volume_list(self):
self.nova('volume-list')
def test_admin_volume_snapshot_list(self):
self.nova('volume-snapshot-list')
def test_admin_volume_type_list(self):
self.nova('volume-type-list')
def test_admin_help(self):
self.nova('help')
def test_admin_list_extensions(self):
self.nova('list-extensions')
def test_admin_net_list(self):
self.nova('net-list')
def test_agent_list(self):
self.nova('agent-list')
self.nova('agent-list', flags='--debug')
# Optional arguments:
def test_admin_version(self):
self.nova('', flags='--version')
def test_admin_debug_list(self):
self.nova('list', flags='--debug')
def test_admin_timeout(self):
self.nova('list', flags='--timeout %d' % CONF.cli.timeout)
def test_admin_timing(self):
self.nova('list', flags='--timing')
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
6171,
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,
646,
3873,
199,
199,
504,
11258,
14,
888,
492,
4810,
199,
646,
30741,
199,
199,
646,
24076,
14,
2764,
199,
504,
24076,
14,
8512,
14,
2330,
492,
943,
465,
2050,
199,
646,
24076,
14,
396,
199,
199,
3103,
275,
4810,
14,
3103,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
5870,
22210,
19884,
3041,
774,
8,
808,
597,
14,
2764,
14,
3041,
14440,
304,
339,
408,
272,
961,
365,
282,
1642,
986,
737,
282,
3486,
1586,
1454,
2366,
13,
889,
15367,
864,
511,
14,
961,
272,
1454,
444,
281,
559,
874,
1890,
3718,
626,
787,
1586,
1454,
14,
339,
961,
1077,
511,
3718,
26,
272,
627,
465,
282,
5578,
922,
272,
627,
465,
282,
4628,
922,
272,
627,
543,
436,
1928,
2716,
2633,
272,
627,
22801,
2951,
1104,
372,
9479,
12,
436,
2945,
511,
1414,
4704,
339,
408,
339,
347,
511,
63,
2113,
63,
3183,
63,
1287,
8,
277,
304,
267,
291,
14,
1855,
8,
5781,
14,
24691,
12,
2079,
291,
14,
6765,
12,
2079,
283,
3749,
13,
9105,
13,
6765,
13,
4494,
358,
339,
327,
6944,
8,
743,
1939,
304,
5817,
83,
315,
1865,
10532,
315,
283,
6765,
1720,
7,
339,
327,
15483,
279,
2368,
26,
339,
347,
511,
63,
2113,
63,
6116,
63,
317,
2664,
744,
8,
277,
304,
267,
291,
14,
6765,
360,
6116,
13,
9368,
358,
267,
291,
14,
6765,
360,
6116,
13,
9368,
297,
1862,
23791,
10421,
358,
339,
347,
511,
63,
2113,
63,
7516,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
7516,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
11856,
63,
2619,
63,
513,
8,
277,
304,
267,
291,
14,
4080,
480,
4672,
401,
291,
14,
6765,
360,
11856,
13,
2619,
13,
513,
1333,
339,
347,
511,
63,
2113,
63,
4091,
4990,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
4091,
4990,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
6942,
8,
277,
304,
267,
291,
14,
6765,
360,
6942,
358,
339,
768,
396,
2537,
14,
15118,
8,
3103,
14,
1364,
63,
4561,
14,
10271,
12,
1993,
298,
20915,
1630,
440,
5647,
642,
3878,
531,
272,
347,
511,
63,
2113,
63,
5797,
63,
9756,
8,
277,
304,
267,
291,
14,
6765,
360,
5797,
13,
9756,
358,
339,
768,
808,
597,
14,
396,
14,
2759,
63,
20684,
8,
1266,
628,
845,
1641,
11991,
531,
272,
347,
511,
63,
2113,
63,
5797,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
5797,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
14461,
8,
277,
304,
267,
291,
14,
6765,
360,
14461,
358,
339,
347,
511,
63,
2113,
63,
6081,
63,
645,
823,
63,
513,
8,
277,
304,
267,
291,
14,
1855,
8,
5781,
14,
24691,
12,
2079,
291,
14,
6765,
12,
2079,
283,
6081,
13,
2732,
13,
513,
358,
267,
327,
16277,
370,
664,
2879,
769,
367,
4575,
8541,
730,
267,
291,
14,
1855,
8,
5781,
14,
24691,
12,
2079,
291,
14,
6765,
12,
2079,
283,
6081,
13,
2732,
13,
513,
297,
2079,
1862,
23791,
6081,
333,
17,
14,
9864,
358,
339,
347,
511,
63,
2113,
63,
6081,
63,
513,
8,
277,
304,
267,
291,
14,
4080,
480,
8628,
63,
4567,
401,
291,
14,
6765,
360,
6081,
13,
513,
1333,
339,
347,
511,
63,
2113,
63,
7774,
63,
711,
63,
9377,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
7774,
13,
711,
13,
9377,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
7774,
63,
711,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
7774,
13,
711,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
7774,
63,
711,
63,
2293,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
7774,
13,
711,
13,
2293,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
1102,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
1102,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
18237,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
18237,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
1569,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
1569,
13,
513,
358,
339,
768,
808,
597,
14,
396,
14,
2759,
63,
20684,
8,
1266,
628,
845,
1641,
11991,
531,
272,
347,
511,
63,
2113,
63,
3266,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
3266,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
19263,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
19263,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
513,
358,
267,
291,
14,
6765,
360,
513,
297,
1862,
23791,
452,
13,
25021,
413,
358,
267,
291,
14,
6765,
360,
513,
297,
1862,
23791,
452,
13,
25021,
378,
358,
267,
291,
14,
1855,
8,
5781,
14,
24691,
12,
2079,
291,
14,
6765,
12,
2079,
283,
513,
297,
2079,
1862,
23791,
452,
13,
25021,
4875,
358,
339,
347,
511,
63,
2113,
63,
1200,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
1200,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
1866,
63,
9368,
8,
277,
304,
267,
291,
14,
6765,
360,
1866,
13,
9368,
358,
339,
347
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
6171,
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,
646,
3873,
199,
199,
504,
11258,
14,
888,
492,
4810,
199,
646,
30741,
199,
199,
646,
24076,
14,
2764,
199,
504,
24076,
14,
8512,
14,
2330,
492,
943,
465,
2050,
199,
646,
24076,
14,
396,
199,
199,
3103,
275,
4810,
14,
3103,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
5870,
22210,
19884,
3041,
774,
8,
808,
597,
14,
2764,
14,
3041,
14440,
304,
339,
408,
272,
961,
365,
282,
1642,
986,
737,
282,
3486,
1586,
1454,
2366,
13,
889,
15367,
864,
511,
14,
961,
272,
1454,
444,
281,
559,
874,
1890,
3718,
626,
787,
1586,
1454,
14,
339,
961,
1077,
511,
3718,
26,
272,
627,
465,
282,
5578,
922,
272,
627,
465,
282,
4628,
922,
272,
627,
543,
436,
1928,
2716,
2633,
272,
627,
22801,
2951,
1104,
372,
9479,
12,
436,
2945,
511,
1414,
4704,
339,
408,
339,
347,
511,
63,
2113,
63,
3183,
63,
1287,
8,
277,
304,
267,
291,
14,
1855,
8,
5781,
14,
24691,
12,
2079,
291,
14,
6765,
12,
2079,
283,
3749,
13,
9105,
13,
6765,
13,
4494,
358,
339,
327,
6944,
8,
743,
1939,
304,
5817,
83,
315,
1865,
10532,
315,
283,
6765,
1720,
7,
339,
327,
15483,
279,
2368,
26,
339,
347,
511,
63,
2113,
63,
6116,
63,
317,
2664,
744,
8,
277,
304,
267,
291,
14,
6765,
360,
6116,
13,
9368,
358,
267,
291,
14,
6765,
360,
6116,
13,
9368,
297,
1862,
23791,
10421,
358,
339,
347,
511,
63,
2113,
63,
7516,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
7516,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
11856,
63,
2619,
63,
513,
8,
277,
304,
267,
291,
14,
4080,
480,
4672,
401,
291,
14,
6765,
360,
11856,
13,
2619,
13,
513,
1333,
339,
347,
511,
63,
2113,
63,
4091,
4990,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
4091,
4990,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
6942,
8,
277,
304,
267,
291,
14,
6765,
360,
6942,
358,
339,
768,
396,
2537,
14,
15118,
8,
3103,
14,
1364,
63,
4561,
14,
10271,
12,
1993,
298,
20915,
1630,
440,
5647,
642,
3878,
531,
272,
347,
511,
63,
2113,
63,
5797,
63,
9756,
8,
277,
304,
267,
291,
14,
6765,
360,
5797,
13,
9756,
358,
339,
768,
808,
597,
14,
396,
14,
2759,
63,
20684,
8,
1266,
628,
845,
1641,
11991,
531,
272,
347,
511,
63,
2113,
63,
5797,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
5797,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
14461,
8,
277,
304,
267,
291,
14,
6765,
360,
14461,
358,
339,
347,
511,
63,
2113,
63,
6081,
63,
645,
823,
63,
513,
8,
277,
304,
267,
291,
14,
1855,
8,
5781,
14,
24691,
12,
2079,
291,
14,
6765,
12,
2079,
283,
6081,
13,
2732,
13,
513,
358,
267,
327,
16277,
370,
664,
2879,
769,
367,
4575,
8541,
730,
267,
291,
14,
1855,
8,
5781,
14,
24691,
12,
2079,
291,
14,
6765,
12,
2079,
283,
6081,
13,
2732,
13,
513,
297,
2079,
1862,
23791,
6081,
333,
17,
14,
9864,
358,
339,
347,
511,
63,
2113,
63,
6081,
63,
513,
8,
277,
304,
267,
291,
14,
4080,
480,
8628,
63,
4567,
401,
291,
14,
6765,
360,
6081,
13,
513,
1333,
339,
347,
511,
63,
2113,
63,
7774,
63,
711,
63,
9377,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
7774,
13,
711,
13,
9377,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
7774,
63,
711,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
7774,
13,
711,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
7774,
63,
711,
63,
2293,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
7774,
13,
711,
13,
2293,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
1102,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
1102,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
18237,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
18237,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
1569,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
1569,
13,
513,
358,
339,
768,
808,
597,
14,
396,
14,
2759,
63,
20684,
8,
1266,
628,
845,
1641,
11991,
531,
272,
347,
511,
63,
2113,
63,
3266,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
3266,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
19263,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
19263,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
513,
358,
267,
291,
14,
6765,
360,
513,
297,
1862,
23791,
452,
13,
25021,
413,
358,
267,
291,
14,
6765,
360,
513,
297,
1862,
23791,
452,
13,
25021,
378,
358,
267,
291,
14,
1855,
8,
5781,
14,
24691,
12,
2079,
291,
14,
6765,
12,
2079,
283,
513,
297,
2079,
1862,
23791,
452,
13,
25021,
4875,
358,
339,
347,
511,
63,
2113,
63,
1200,
63,
513,
8,
277,
304,
267,
291,
14,
6765,
360,
1200,
13,
513,
358,
339,
347,
511,
63,
2113,
63,
1866,
63,
9368,
8,
277,
304,
267,
291,
14,
6765,
360,
1866,
13,
9368,
358,
339,
347,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
janarthananfit/Nightlies-4.4
|
Documentation/target/tcm_mod_builder.py
|
4981
|
41422
|
#!/usr/bin/python
# The TCM v4 multi-protocol fabric module generation script for drivers/target/$NEW_MOD
#
# Copyright (c) 2010 Rising Tide Systems
# Copyright (c) 2010 Linux-iSCSI.org
#
# Author: nab@kernel.org
#
import os, sys
import subprocess as sub
import string
import re
import optparse
tcm_dir = ""
fabric_ops = []
fabric_mod_dir = ""
fabric_mod_port = ""
fabric_mod_init_port = ""
def tcm_mod_err(msg):
print msg
sys.exit(1)
def tcm_mod_create_module_subdir(fabric_mod_dir_var):
if os.path.isdir(fabric_mod_dir_var) == True:
return 1
print "Creating fabric_mod_dir: " + fabric_mod_dir_var
ret = os.mkdir(fabric_mod_dir_var)
if ret:
tcm_mod_err("Unable to mkdir " + fabric_mod_dir_var)
return
def tcm_mod_build_FC_include(fabric_mod_dir_var, fabric_mod_name):
global fabric_mod_port
global fabric_mod_init_port
buf = ""
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
print "Writing file: " + f
p = open(f, 'w');
if not p:
tcm_mod_err("Unable to open file: " + f)
buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
buf += "\n"
buf += "struct " + fabric_mod_name + "_nacl {\n"
buf += " /* Binary World Wide unique Port Name for FC Initiator Nport */\n"
buf += " u64 nport_wwpn;\n"
buf += " /* ASCII formatted WWPN for FC Initiator Nport */\n"
buf += " char nport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_nodeacl() */\n"
buf += " struct se_node_acl se_node_acl;\n"
buf += "};\n"
buf += "\n"
buf += "struct " + fabric_mod_name + "_tpg {\n"
buf += " /* FC lport target portal group tag for TCM */\n"
buf += " u16 lport_tpgt;\n"
buf += " /* Pointer back to " + fabric_mod_name + "_lport */\n"
buf += " struct " + fabric_mod_name + "_lport *lport;\n"
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
buf += " struct se_portal_group se_tpg;\n"
buf += "};\n"
buf += "\n"
buf += "struct " + fabric_mod_name + "_lport {\n"
buf += " /* SCSI protocol the lport is providing */\n"
buf += " u8 lport_proto_id;\n"
buf += " /* Binary World Wide unique Port Name for FC Target Lport */\n"
buf += " u64 lport_wwpn;\n"
buf += " /* ASCII formatted WWPN for FC Target Lport */\n"
buf += " char lport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_lport() */\n"
buf += " struct se_wwn lport_wwn;\n"
buf += "};\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
fabric_mod_port = "lport"
fabric_mod_init_port = "nport"
return
def tcm_mod_build_SAS_include(fabric_mod_dir_var, fabric_mod_name):
global fabric_mod_port
global fabric_mod_init_port
buf = ""
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
print "Writing file: " + f
p = open(f, 'w');
if not p:
tcm_mod_err("Unable to open file: " + f)
buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
buf += "\n"
buf += "struct " + fabric_mod_name + "_nacl {\n"
buf += " /* Binary World Wide unique Port Name for SAS Initiator port */\n"
buf += " u64 iport_wwpn;\n"
buf += " /* ASCII formatted WWPN for Sas Initiator port */\n"
buf += " char iport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_nodeacl() */\n"
buf += " struct se_node_acl se_node_acl;\n"
buf += "};\n\n"
buf += "struct " + fabric_mod_name + "_tpg {\n"
buf += " /* SAS port target portal group tag for TCM */\n"
buf += " u16 tport_tpgt;\n"
buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n"
buf += " struct " + fabric_mod_name + "_tport *tport;\n"
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
buf += " struct se_portal_group se_tpg;\n"
buf += "};\n\n"
buf += "struct " + fabric_mod_name + "_tport {\n"
buf += " /* SCSI protocol the tport is providing */\n"
buf += " u8 tport_proto_id;\n"
buf += " /* Binary World Wide unique Port Name for SAS Target port */\n"
buf += " u64 tport_wwpn;\n"
buf += " /* ASCII formatted WWPN for SAS Target port */\n"
buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n"
buf += " struct se_wwn tport_wwn;\n"
buf += "};\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
fabric_mod_port = "tport"
fabric_mod_init_port = "iport"
return
def tcm_mod_build_iSCSI_include(fabric_mod_dir_var, fabric_mod_name):
global fabric_mod_port
global fabric_mod_init_port
buf = ""
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
print "Writing file: " + f
p = open(f, 'w');
if not p:
tcm_mod_err("Unable to open file: " + f)
buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
buf += "\n"
buf += "struct " + fabric_mod_name + "_nacl {\n"
buf += " /* ASCII formatted InitiatorName */\n"
buf += " char iport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_nodeacl() */\n"
buf += " struct se_node_acl se_node_acl;\n"
buf += "};\n\n"
buf += "struct " + fabric_mod_name + "_tpg {\n"
buf += " /* iSCSI target portal group tag for TCM */\n"
buf += " u16 tport_tpgt;\n"
buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n"
buf += " struct " + fabric_mod_name + "_tport *tport;\n"
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
buf += " struct se_portal_group se_tpg;\n"
buf += "};\n\n"
buf += "struct " + fabric_mod_name + "_tport {\n"
buf += " /* SCSI protocol the tport is providing */\n"
buf += " u8 tport_proto_id;\n"
buf += " /* ASCII formatted TargetName for IQN */\n"
buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n"
buf += " struct se_wwn tport_wwn;\n"
buf += "};\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
fabric_mod_port = "tport"
fabric_mod_init_port = "iport"
return
def tcm_mod_build_base_includes(proto_ident, fabric_mod_dir_val, fabric_mod_name):
if proto_ident == "FC":
tcm_mod_build_FC_include(fabric_mod_dir_val, fabric_mod_name)
elif proto_ident == "SAS":
tcm_mod_build_SAS_include(fabric_mod_dir_val, fabric_mod_name)
elif proto_ident == "iSCSI":
tcm_mod_build_iSCSI_include(fabric_mod_dir_val, fabric_mod_name)
else:
print "Unsupported proto_ident: " + proto_ident
sys.exit(1)
return
def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
buf = ""
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_configfs.c"
print "Writing file: " + f
p = open(f, 'w');
if not p:
tcm_mod_err("Unable to open file: " + f)
buf = "#include <linux/module.h>\n"
buf += "#include <linux/moduleparam.h>\n"
buf += "#include <linux/version.h>\n"
buf += "#include <generated/utsrelease.h>\n"
buf += "#include <linux/utsname.h>\n"
buf += "#include <linux/init.h>\n"
buf += "#include <linux/slab.h>\n"
buf += "#include <linux/kthread.h>\n"
buf += "#include <linux/types.h>\n"
buf += "#include <linux/string.h>\n"
buf += "#include <linux/configfs.h>\n"
buf += "#include <linux/ctype.h>\n"
buf += "#include <asm/unaligned.h>\n\n"
buf += "#include <target/target_core_base.h>\n"
buf += "#include <target/target_core_fabric.h>\n"
buf += "#include <target/target_core_fabric_configfs.h>\n"
buf += "#include <target/target_core_configfs.h>\n"
buf += "#include <target/configfs_macros.h>\n\n"
buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
buf += "/* Local pointer to allocated TCM configfs fabric module */\n"
buf += "struct target_fabric_configfs *" + fabric_mod_name + "_fabric_configfs;\n\n"
buf += "static struct se_node_acl *" + fabric_mod_name + "_make_nodeacl(\n"
buf += " struct se_portal_group *se_tpg,\n"
buf += " struct config_group *group,\n"
buf += " const char *name)\n"
buf += "{\n"
buf += " struct se_node_acl *se_nacl, *se_nacl_new;\n"
buf += " struct " + fabric_mod_name + "_nacl *nacl;\n"
if proto_ident == "FC" or proto_ident == "SAS":
buf += " u64 wwpn = 0;\n"
buf += " u32 nexus_depth;\n\n"
buf += " /* " + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n"
buf += " return ERR_PTR(-EINVAL); */\n"
buf += " se_nacl_new = " + fabric_mod_name + "_alloc_fabric_acl(se_tpg);\n"
buf += " if (!se_nacl_new)\n"
buf += " return ERR_PTR(-ENOMEM);\n"
buf += "//#warning FIXME: Hardcoded nexus depth in " + fabric_mod_name + "_make_nodeacl()\n"
buf += " nexus_depth = 1;\n"
buf += " /*\n"
buf += " * se_nacl_new may be released by core_tpg_add_initiator_node_acl()\n"
buf += " * when converting a NodeACL from demo mode -> explict\n"
buf += " */\n"
buf += " se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,\n"
buf += " name, nexus_depth);\n"
buf += " if (IS_ERR(se_nacl)) {\n"
buf += " " + fabric_mod_name + "_release_fabric_acl(se_tpg, se_nacl_new);\n"
buf += " return se_nacl;\n"
buf += " }\n"
buf += " /*\n"
buf += " * Locate our struct " + fabric_mod_name + "_nacl and set the FC Nport WWPN\n"
buf += " */\n"
buf += " nacl = container_of(se_nacl, struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
if proto_ident == "FC" or proto_ident == "SAS":
buf += " nacl->" + fabric_mod_init_port + "_wwpn = wwpn;\n"
buf += " /* " + fabric_mod_name + "_format_wwn(&nacl->" + fabric_mod_init_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n"
buf += " return se_nacl;\n"
buf += "}\n\n"
buf += "static void " + fabric_mod_name + "_drop_nodeacl(struct se_node_acl *se_acl)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_nacl *nacl = container_of(se_acl,\n"
buf += " struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
buf += " core_tpg_del_initiator_node_acl(se_acl->se_tpg, se_acl, 1);\n"
buf += " kfree(nacl);\n"
buf += "}\n\n"
buf += "static struct se_portal_group *" + fabric_mod_name + "_make_tpg(\n"
buf += " struct se_wwn *wwn,\n"
buf += " struct config_group *group,\n"
buf += " const char *name)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + "*" + fabric_mod_port + " = container_of(wwn,\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg;\n"
buf += " unsigned long tpgt;\n"
buf += " int ret;\n\n"
buf += " if (strstr(name, \"tpgt_\") != name)\n"
buf += " return ERR_PTR(-EINVAL);\n"
buf += " if (strict_strtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)\n"
buf += " return ERR_PTR(-EINVAL);\n\n"
buf += " tpg = kzalloc(sizeof(struct " + fabric_mod_name + "_tpg), GFP_KERNEL);\n"
buf += " if (!tpg) {\n"
buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_tpg\");\n"
buf += " return ERR_PTR(-ENOMEM);\n"
buf += " }\n"
buf += " tpg->" + fabric_mod_port + " = " + fabric_mod_port + ";\n"
buf += " tpg->" + fabric_mod_port + "_tpgt = tpgt;\n\n"
buf += " ret = core_tpg_register(&" + fabric_mod_name + "_fabric_configfs->tf_ops, wwn,\n"
buf += " &tpg->se_tpg, (void *)tpg,\n"
buf += " TRANSPORT_TPG_TYPE_NORMAL);\n"
buf += " if (ret < 0) {\n"
buf += " kfree(tpg);\n"
buf += " return NULL;\n"
buf += " }\n"
buf += " return &tpg->se_tpg;\n"
buf += "}\n\n"
buf += "static void " + fabric_mod_name + "_drop_tpg(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n\n"
buf += " core_tpg_deregister(se_tpg);\n"
buf += " kfree(tpg);\n"
buf += "}\n\n"
buf += "static struct se_wwn *" + fabric_mod_name + "_make_" + fabric_mod_port + "(\n"
buf += " struct target_fabric_configfs *tf,\n"
buf += " struct config_group *group,\n"
buf += " const char *name)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + ";\n"
if proto_ident == "FC" or proto_ident == "SAS":
buf += " u64 wwpn = 0;\n\n"
buf += " /* if (" + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n"
buf += " return ERR_PTR(-EINVAL); */\n\n"
buf += " " + fabric_mod_port + " = kzalloc(sizeof(struct " + fabric_mod_name + "_" + fabric_mod_port + "), GFP_KERNEL);\n"
buf += " if (!" + fabric_mod_port + ") {\n"
buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_" + fabric_mod_port + "\");\n"
buf += " return ERR_PTR(-ENOMEM);\n"
buf += " }\n"
if proto_ident == "FC" or proto_ident == "SAS":
buf += " " + fabric_mod_port + "->" + fabric_mod_port + "_wwpn = wwpn;\n"
buf += " /* " + fabric_mod_name + "_format_wwn(&" + fabric_mod_port + "->" + fabric_mod_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n"
buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_wwn;\n"
buf += "}\n\n"
buf += "static void " + fabric_mod_name + "_drop_" + fabric_mod_port + "(struct se_wwn *wwn)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = container_of(wwn,\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n"
buf += " kfree(" + fabric_mod_port + ");\n"
buf += "}\n\n"
buf += "static ssize_t " + fabric_mod_name + "_wwn_show_attr_version(\n"
buf += " struct target_fabric_configfs *tf,\n"
buf += " char *page)\n"
buf += "{\n"
buf += " return sprintf(page, \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n"
buf += " \"on \"UTS_RELEASE\"\\n\", " + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n"
buf += " utsname()->machine);\n"
buf += "}\n\n"
buf += "TF_WWN_ATTR_RO(" + fabric_mod_name + ", version);\n\n"
buf += "static struct configfs_attribute *" + fabric_mod_name + "_wwn_attrs[] = {\n"
buf += " &" + fabric_mod_name + "_wwn_version.attr,\n"
buf += " NULL,\n"
buf += "};\n\n"
buf += "static struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n"
buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n"
buf += " .get_fabric_proto_ident = " + fabric_mod_name + "_get_fabric_proto_ident,\n"
buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n"
buf += " .tpg_get_tag = " + fabric_mod_name + "_get_tag,\n"
buf += " .tpg_get_default_depth = " + fabric_mod_name + "_get_default_depth,\n"
buf += " .tpg_get_pr_transport_id = " + fabric_mod_name + "_get_pr_transport_id,\n"
buf += " .tpg_get_pr_transport_id_len = " + fabric_mod_name + "_get_pr_transport_id_len,\n"
buf += " .tpg_parse_pr_out_transport_id = " + fabric_mod_name + "_parse_pr_out_transport_id,\n"
buf += " .tpg_check_demo_mode = " + fabric_mod_name + "_check_false,\n"
buf += " .tpg_check_demo_mode_cache = " + fabric_mod_name + "_check_true,\n"
buf += " .tpg_check_demo_mode_write_protect = " + fabric_mod_name + "_check_true,\n"
buf += " .tpg_check_prod_mode_write_protect = " + fabric_mod_name + "_check_false,\n"
buf += " .tpg_alloc_fabric_acl = " + fabric_mod_name + "_alloc_fabric_acl,\n"
buf += " .tpg_release_fabric_acl = " + fabric_mod_name + "_release_fabric_acl,\n"
buf += " .tpg_get_inst_index = " + fabric_mod_name + "_tpg_get_inst_index,\n"
buf += " .release_cmd = " + fabric_mod_name + "_release_cmd,\n"
buf += " .shutdown_session = " + fabric_mod_name + "_shutdown_session,\n"
buf += " .close_session = " + fabric_mod_name + "_close_session,\n"
buf += " .stop_session = " + fabric_mod_name + "_stop_session,\n"
buf += " .fall_back_to_erl0 = " + fabric_mod_name + "_reset_nexus,\n"
buf += " .sess_logged_in = " + fabric_mod_name + "_sess_logged_in,\n"
buf += " .sess_get_index = " + fabric_mod_name + "_sess_get_index,\n"
buf += " .sess_get_initiator_sid = NULL,\n"
buf += " .write_pending = " + fabric_mod_name + "_write_pending,\n"
buf += " .write_pending_status = " + fabric_mod_name + "_write_pending_status,\n"
buf += " .set_default_node_attributes = " + fabric_mod_name + "_set_default_node_attrs,\n"
buf += " .get_task_tag = " + fabric_mod_name + "_get_task_tag,\n"
buf += " .get_cmd_state = " + fabric_mod_name + "_get_cmd_state,\n"
buf += " .queue_data_in = " + fabric_mod_name + "_queue_data_in,\n"
buf += " .queue_status = " + fabric_mod_name + "_queue_status,\n"
buf += " .queue_tm_rsp = " + fabric_mod_name + "_queue_tm_rsp,\n"
buf += " .get_fabric_sense_len = " + fabric_mod_name + "_get_fabric_sense_len,\n"
buf += " .set_fabric_sense_len = " + fabric_mod_name + "_set_fabric_sense_len,\n"
buf += " .is_state_remove = " + fabric_mod_name + "_is_state_remove,\n"
buf += " /*\n"
buf += " * Setup function pointers for generic logic in target_core_fabric_configfs.c\n"
buf += " */\n"
buf += " .fabric_make_wwn = " + fabric_mod_name + "_make_" + fabric_mod_port + ",\n"
buf += " .fabric_drop_wwn = " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n"
buf += " .fabric_make_tpg = " + fabric_mod_name + "_make_tpg,\n"
buf += " .fabric_drop_tpg = " + fabric_mod_name + "_drop_tpg,\n"
buf += " .fabric_post_link = NULL,\n"
buf += " .fabric_pre_unlink = NULL,\n"
buf += " .fabric_make_np = NULL,\n"
buf += " .fabric_drop_np = NULL,\n"
buf += " .fabric_make_nodeacl = " + fabric_mod_name + "_make_nodeacl,\n"
buf += " .fabric_drop_nodeacl = " + fabric_mod_name + "_drop_nodeacl,\n"
buf += "};\n\n"
buf += "static int " + fabric_mod_name + "_register_configfs(void)\n"
buf += "{\n"
buf += " struct target_fabric_configfs *fabric;\n"
buf += " int ret;\n\n"
buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n"
buf += " \" on \"UTS_RELEASE\"\\n\"," + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n"
buf += " utsname()->machine);\n"
buf += " /*\n"
buf += " * Register the top level struct config_item_type with TCM core\n"
buf += " */\n"
buf += " fabric = target_fabric_configfs_init(THIS_MODULE, \"" + fabric_mod_name[4:] + "\");\n"
buf += " if (IS_ERR(fabric)) {\n"
buf += " printk(KERN_ERR \"target_fabric_configfs_init() failed\\n\");\n"
buf += " return PTR_ERR(fabric);\n"
buf += " }\n"
buf += " /*\n"
buf += " * Setup fabric->tf_ops from our local " + fabric_mod_name + "_ops\n"
buf += " */\n"
buf += " fabric->tf_ops = " + fabric_mod_name + "_ops;\n"
buf += " /*\n"
buf += " * Setup default attribute lists for various fabric->tf_cit_tmpl\n"
buf += " */\n"
buf += " TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = " + fabric_mod_name + "_wwn_attrs;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_base_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_auth_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_param_cit.ct_attrs = NULL;\n"
buf += " /*\n"
buf += " * Register the fabric for use within TCM\n"
buf += " */\n"
buf += " ret = target_fabric_configfs_register(fabric);\n"
buf += " if (ret < 0) {\n"
buf += " printk(KERN_ERR \"target_fabric_configfs_register() failed\"\n"
buf += " \" for " + fabric_mod_name.upper() + "\\n\");\n"
buf += " return ret;\n"
buf += " }\n"
buf += " /*\n"
buf += " * Setup our local pointer to *fabric\n"
buf += " */\n"
buf += " " + fabric_mod_name + "_fabric_configfs = fabric;\n"
buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + "[0] - Set fabric -> " + fabric_mod_name + "_fabric_configfs\\n\");\n"
buf += " return 0;\n"
buf += "};\n\n"
buf += "static void __exit " + fabric_mod_name + "_deregister_configfs(void)\n"
buf += "{\n"
buf += " if (!" + fabric_mod_name + "_fabric_configfs)\n"
buf += " return;\n\n"
buf += " target_fabric_configfs_deregister(" + fabric_mod_name + "_fabric_configfs);\n"
buf += " " + fabric_mod_name + "_fabric_configfs = NULL;\n"
buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + "[0] - Cleared " + fabric_mod_name + "_fabric_configfs\\n\");\n"
buf += "};\n\n"
buf += "static int __init " + fabric_mod_name + "_init(void)\n"
buf += "{\n"
buf += " int ret;\n\n"
buf += " ret = " + fabric_mod_name + "_register_configfs();\n"
buf += " if (ret < 0)\n"
buf += " return ret;\n\n"
buf += " return 0;\n"
buf += "};\n\n"
buf += "static void __exit " + fabric_mod_name + "_exit(void)\n"
buf += "{\n"
buf += " " + fabric_mod_name + "_deregister_configfs();\n"
buf += "};\n\n"
buf += "MODULE_DESCRIPTION(\"" + fabric_mod_name.upper() + " series fabric driver\");\n"
buf += "MODULE_LICENSE(\"GPL\");\n"
buf += "module_init(" + fabric_mod_name + "_init);\n"
buf += "module_exit(" + fabric_mod_name + "_exit);\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
return
def tcm_mod_scan_fabric_ops(tcm_dir):
fabric_ops_api = tcm_dir + "include/target/target_core_fabric.h"
print "Using tcm_mod_scan_fabric_ops: " + fabric_ops_api
process_fo = 0;
p = open(fabric_ops_api, 'r')
line = p.readline()
while line:
if process_fo == 0 and re.search('struct target_core_fabric_ops {', line):
line = p.readline()
continue
if process_fo == 0:
process_fo = 1;
line = p.readline()
# Search for function pointer
if not re.search('\(\*', line):
continue
fabric_ops.append(line.rstrip())
continue
line = p.readline()
# Search for function pointer
if not re.search('\(\*', line):
continue
fabric_ops.append(line.rstrip())
p.close()
return
def tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir_var, fabric_mod_name):
buf = ""
bufi = ""
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.c"
print "Writing file: " + f
p = open(f, 'w')
if not p:
tcm_mod_err("Unable to open file: " + f)
fi = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.h"
print "Writing file: " + fi
pi = open(fi, 'w')
if not pi:
tcm_mod_err("Unable to open file: " + fi)
buf = "#include <linux/slab.h>\n"
buf += "#include <linux/kthread.h>\n"
buf += "#include <linux/types.h>\n"
buf += "#include <linux/list.h>\n"
buf += "#include <linux/types.h>\n"
buf += "#include <linux/string.h>\n"
buf += "#include <linux/ctype.h>\n"
buf += "#include <asm/unaligned.h>\n"
buf += "#include <scsi/scsi.h>\n"
buf += "#include <scsi/scsi_host.h>\n"
buf += "#include <scsi/scsi_device.h>\n"
buf += "#include <scsi/scsi_cmnd.h>\n"
buf += "#include <scsi/libfc.h>\n\n"
buf += "#include <target/target_core_base.h>\n"
buf += "#include <target/target_core_fabric.h>\n"
buf += "#include <target/target_core_configfs.h>\n\n"
buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
buf += "int " + fabric_mod_name + "_check_true(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " return 1;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_check_true(struct se_portal_group *);\n"
buf += "int " + fabric_mod_name + "_check_false(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_check_false(struct se_portal_group *);\n"
total_fabric_ops = len(fabric_ops)
i = 0
while i < total_fabric_ops:
fo = fabric_ops[i]
i += 1
# print "fabric_ops: " + fo
if re.search('get_fabric_name', fo):
buf += "char *" + fabric_mod_name + "_get_fabric_name(void)\n"
buf += "{\n"
buf += " return \"" + fabric_mod_name[4:] + "\";\n"
buf += "}\n\n"
bufi += "char *" + fabric_mod_name + "_get_fabric_name(void);\n"
continue
if re.search('get_fabric_proto_ident', fo):
buf += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
buf += " u8 proto_id;\n\n"
buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
if proto_ident == "FC":
buf += " case SCSI_PROTOCOL_FCP:\n"
buf += " default:\n"
buf += " proto_id = fc_get_fabric_proto_ident(se_tpg);\n"
buf += " break;\n"
elif proto_ident == "SAS":
buf += " case SCSI_PROTOCOL_SAS:\n"
buf += " default:\n"
buf += " proto_id = sas_get_fabric_proto_ident(se_tpg);\n"
buf += " break;\n"
elif proto_ident == "iSCSI":
buf += " case SCSI_PROTOCOL_ISCSI:\n"
buf += " default:\n"
buf += " proto_id = iscsi_get_fabric_proto_ident(se_tpg);\n"
buf += " break;\n"
buf += " }\n\n"
buf += " return proto_id;\n"
buf += "}\n\n"
bufi += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *);\n"
if re.search('get_wwn', fo):
buf += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n\n"
buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_name[0];\n"
buf += "}\n\n"
bufi += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *);\n"
if re.search('get_tag', fo):
buf += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " return tpg->" + fabric_mod_port + "_tpgt;\n"
buf += "}\n\n"
bufi += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *);\n"
if re.search('get_default_depth', fo):
buf += "u32 " + fabric_mod_name + "_get_default_depth(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " return 1;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_get_default_depth(struct se_portal_group *);\n"
if re.search('get_pr_transport_id\)\(', fo):
buf += "u32 " + fabric_mod_name + "_get_pr_transport_id(\n"
buf += " struct se_portal_group *se_tpg,\n"
buf += " struct se_node_acl *se_nacl,\n"
buf += " struct t10_pr_registration *pr_reg,\n"
buf += " int *format_code,\n"
buf += " unsigned char *buf)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
buf += " int ret = 0;\n\n"
buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
if proto_ident == "FC":
buf += " case SCSI_PROTOCOL_FCP:\n"
buf += " default:\n"
buf += " ret = fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code, buf);\n"
buf += " break;\n"
elif proto_ident == "SAS":
buf += " case SCSI_PROTOCOL_SAS:\n"
buf += " default:\n"
buf += " ret = sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code, buf);\n"
buf += " break;\n"
elif proto_ident == "iSCSI":
buf += " case SCSI_PROTOCOL_ISCSI:\n"
buf += " default:\n"
buf += " ret = iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code, buf);\n"
buf += " break;\n"
buf += " }\n\n"
buf += " return ret;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id(struct se_portal_group *,\n"
bufi += " struct se_node_acl *, struct t10_pr_registration *,\n"
bufi += " int *, unsigned char *);\n"
if re.search('get_pr_transport_id_len\)\(', fo):
buf += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(\n"
buf += " struct se_portal_group *se_tpg,\n"
buf += " struct se_node_acl *se_nacl,\n"
buf += " struct t10_pr_registration *pr_reg,\n"
buf += " int *format_code)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
buf += " int ret = 0;\n\n"
buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
if proto_ident == "FC":
buf += " case SCSI_PROTOCOL_FCP:\n"
buf += " default:\n"
buf += " ret = fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code);\n"
buf += " break;\n"
elif proto_ident == "SAS":
buf += " case SCSI_PROTOCOL_SAS:\n"
buf += " default:\n"
buf += " ret = sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code);\n"
buf += " break;\n"
elif proto_ident == "iSCSI":
buf += " case SCSI_PROTOCOL_ISCSI:\n"
buf += " default:\n"
buf += " ret = iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code);\n"
buf += " break;\n"
buf += " }\n\n"
buf += " return ret;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(struct se_portal_group *,\n"
bufi += " struct se_node_acl *, struct t10_pr_registration *,\n"
bufi += " int *);\n"
if re.search('parse_pr_out_transport_id\)\(', fo):
buf += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(\n"
buf += " struct se_portal_group *se_tpg,\n"
buf += " const char *buf,\n"
buf += " u32 *out_tid_len,\n"
buf += " char **port_nexus_ptr)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
buf += " char *tid = NULL;\n\n"
buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
if proto_ident == "FC":
buf += " case SCSI_PROTOCOL_FCP:\n"
buf += " default:\n"
buf += " tid = fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
buf += " port_nexus_ptr);\n"
elif proto_ident == "SAS":
buf += " case SCSI_PROTOCOL_SAS:\n"
buf += " default:\n"
buf += " tid = sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
buf += " port_nexus_ptr);\n"
elif proto_ident == "iSCSI":
buf += " case SCSI_PROTOCOL_ISCSI:\n"
buf += " default:\n"
buf += " tid = iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
buf += " port_nexus_ptr);\n"
buf += " }\n\n"
buf += " return tid;\n"
buf += "}\n\n"
bufi += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(struct se_portal_group *,\n"
bufi += " const char *, u32 *, char **);\n"
if re.search('alloc_fabric_acl\)\(', fo):
buf += "struct se_node_acl *" + fabric_mod_name + "_alloc_fabric_acl(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_nacl *nacl;\n\n"
buf += " nacl = kzalloc(sizeof(struct " + fabric_mod_name + "_nacl), GFP_KERNEL);\n"
buf += " if (!nacl) {\n"
buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_nacl\\n\");\n"
buf += " return NULL;\n"
buf += " }\n\n"
buf += " return &nacl->se_node_acl;\n"
buf += "}\n\n"
bufi += "struct se_node_acl *" + fabric_mod_name + "_alloc_fabric_acl(struct se_portal_group *);\n"
if re.search('release_fabric_acl\)\(', fo):
buf += "void " + fabric_mod_name + "_release_fabric_acl(\n"
buf += " struct se_portal_group *se_tpg,\n"
buf += " struct se_node_acl *se_nacl)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_nacl *nacl = container_of(se_nacl,\n"
buf += " struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
buf += " kfree(nacl);\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_release_fabric_acl(struct se_portal_group *,\n"
bufi += " struct se_node_acl *);\n"
if re.search('tpg_get_inst_index\)\(', fo):
buf += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " return 1;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *);\n"
if re.search('\*release_cmd\)\(', fo):
buf += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return;\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *);\n"
if re.search('shutdown_session\)\(', fo):
buf += "int " + fabric_mod_name + "_shutdown_session(struct se_session *se_sess)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_shutdown_session(struct se_session *);\n"
if re.search('close_session\)\(', fo):
buf += "void " + fabric_mod_name + "_close_session(struct se_session *se_sess)\n"
buf += "{\n"
buf += " return;\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_close_session(struct se_session *);\n"
if re.search('stop_session\)\(', fo):
buf += "void " + fabric_mod_name + "_stop_session(struct se_session *se_sess, int sess_sleep , int conn_sleep)\n"
buf += "{\n"
buf += " return;\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_stop_session(struct se_session *, int, int);\n"
if re.search('fall_back_to_erl0\)\(', fo):
buf += "void " + fabric_mod_name + "_reset_nexus(struct se_session *se_sess)\n"
buf += "{\n"
buf += " return;\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_reset_nexus(struct se_session *);\n"
if re.search('sess_logged_in\)\(', fo):
buf += "int " + fabric_mod_name + "_sess_logged_in(struct se_session *se_sess)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_sess_logged_in(struct se_session *);\n"
if re.search('sess_get_index\)\(', fo):
buf += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *se_sess)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *);\n"
if re.search('write_pending\)\(', fo):
buf += "int " + fabric_mod_name + "_write_pending(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_write_pending(struct se_cmd *);\n"
if re.search('write_pending_status\)\(', fo):
buf += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *);\n"
if re.search('set_default_node_attributes\)\(', fo):
buf += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *nacl)\n"
buf += "{\n"
buf += " return;\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *);\n"
if re.search('get_task_tag\)\(', fo):
buf += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *);\n"
if re.search('get_cmd_state\)\(', fo):
buf += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *);\n"
if re.search('queue_data_in\)\(', fo):
buf += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *);\n"
if re.search('queue_status\)\(', fo):
buf += "int " + fabric_mod_name + "_queue_status(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_queue_status(struct se_cmd *);\n"
if re.search('queue_tm_rsp\)\(', fo):
buf += "int " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *);\n"
if re.search('get_fabric_sense_len\)\(', fo):
buf += "u16 " + fabric_mod_name + "_get_fabric_sense_len(void)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "u16 " + fabric_mod_name + "_get_fabric_sense_len(void);\n"
if re.search('set_fabric_sense_len\)\(', fo):
buf += "u16 " + fabric_mod_name + "_set_fabric_sense_len(struct se_cmd *se_cmd, u32 sense_length)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "u16 " + fabric_mod_name + "_set_fabric_sense_len(struct se_cmd *, u32);\n"
if re.search('is_state_remove\)\(', fo):
buf += "int " + fabric_mod_name + "_is_state_remove(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_is_state_remove(struct se_cmd *);\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
ret = pi.write(bufi)
if ret:
tcm_mod_err("Unable to write fi: " + fi)
pi.close()
return
def tcm_mod_build_kbuild(fabric_mod_dir_var, fabric_mod_name):
buf = ""
f = fabric_mod_dir_var + "/Makefile"
print "Writing file: " + f
p = open(f, 'w')
if not p:
tcm_mod_err("Unable to open file: " + f)
buf += fabric_mod_name + "-objs := " + fabric_mod_name + "_fabric.o \\\n"
buf += " " + fabric_mod_name + "_configfs.o\n"
buf += "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name + ".o\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
return
def tcm_mod_build_kconfig(fabric_mod_dir_var, fabric_mod_name):
buf = ""
f = fabric_mod_dir_var + "/Kconfig"
print "Writing file: " + f
p = open(f, 'w')
if not p:
tcm_mod_err("Unable to open file: " + f)
buf = "config " + fabric_mod_name.upper() + "\n"
buf += " tristate \"" + fabric_mod_name.upper() + " fabric module\"\n"
buf += " depends on TARGET_CORE && CONFIGFS_FS\n"
buf += " default n\n"
buf += " ---help---\n"
buf += " Say Y here to enable the " + fabric_mod_name.upper() + " fabric module\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
return
def tcm_mod_add_kbuild(tcm_dir, fabric_mod_name):
buf = "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name.lower() + "/\n"
kbuild = tcm_dir + "/drivers/target/Makefile"
f = open(kbuild, 'a')
f.write(buf)
f.close()
return
def tcm_mod_add_kconfig(tcm_dir, fabric_mod_name):
buf = "source \"drivers/target/" + fabric_mod_name.lower() + "/Kconfig\"\n"
kconfig = tcm_dir + "/drivers/target/Kconfig"
f = open(kconfig, 'a')
f.write(buf)
f.close()
return
def main(modname, proto_ident):
# proto_ident = "FC"
# proto_ident = "SAS"
# proto_ident = "iSCSI"
tcm_dir = os.getcwd();
tcm_dir += "/../../"
print "tcm_dir: " + tcm_dir
fabric_mod_name = modname
fabric_mod_dir = tcm_dir + "drivers/target/" + fabric_mod_name
print "Set fabric_mod_name: " + fabric_mod_name
print "Set fabric_mod_dir: " + fabric_mod_dir
print "Using proto_ident: " + proto_ident
if proto_ident != "FC" and proto_ident != "SAS" and proto_ident != "iSCSI":
print "Unsupported proto_ident: " + proto_ident
sys.exit(1)
ret = tcm_mod_create_module_subdir(fabric_mod_dir)
if ret:
print "tcm_mod_create_module_subdir() failed because module already exists!"
sys.exit(1)
tcm_mod_build_base_includes(proto_ident, fabric_mod_dir, fabric_mod_name)
tcm_mod_scan_fabric_ops(tcm_dir)
tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir, fabric_mod_name)
tcm_mod_build_configfs(proto_ident, fabric_mod_dir, fabric_mod_name)
tcm_mod_build_kbuild(fabric_mod_dir, fabric_mod_name)
tcm_mod_build_kconfig(fabric_mod_dir, fabric_mod_name)
input = raw_input("Would you like to add " + fabric_mod_name + "to drivers/target/Makefile..? [yes,no]: ")
if input == "yes" or input == "y":
tcm_mod_add_kbuild(tcm_dir, fabric_mod_name)
input = raw_input("Would you like to add " + fabric_mod_name + "to drivers/target/Kconfig..? [yes,no]: ")
if input == "yes" or input == "y":
tcm_mod_add_kconfig(tcm_dir, fabric_mod_name)
return
parser = optparse.OptionParser()
parser.add_option('-m', '--modulename', help='Module name', dest='modname',
action='store', nargs=1, type='string')
parser.add_option('-p', '--protoident', help='Protocol Ident', dest='protoident',
action='store', nargs=1, type='string')
(opts, args) = parser.parse_args()
mandatories = ['modname', 'protoident']
for m in mandatories:
if not opts.__dict__[m]:
print "mandatory option is missing\n"
parser.print_help()
exit(-1)
if __name__ == "__main__":
main(str(opts.modname), opts.protoident)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
710,
28526,
373,
20,
3510,
13,
3922,
2630,
859,
10152,
2884,
367,
19016,
15,
1375,
21792,
11365,
63,
8816,
199,
3,
199,
3,
1898,
334,
67,
9,
7129,
820,
11136,
377,
2655,
15285,
199,
3,
1898,
334,
67,
9,
7129,
10130,
13,
21534,
14,
1308,
199,
3,
199,
3,
6529,
26,
302,
371,
32,
4989,
14,
1308,
199,
3,
199,
646,
747,
12,
984,
199,
646,
3873,
465,
1007,
199,
646,
1059,
199,
646,
295,
199,
646,
8691,
199,
199,
10606,
63,
694,
275,
3087,
199,
199,
4991,
63,
1483,
275,
942,
199,
4991,
63,
1494,
63,
694,
275,
3087,
199,
4991,
63,
1494,
63,
719,
275,
3087,
199,
4991,
63,
1494,
63,
826,
63,
719,
275,
3087,
199,
199,
318,
15288,
63,
1494,
63,
1508,
8,
1328,
304,
199,
198,
1361,
1499,
199,
198,
1274,
14,
2224,
8,
17,
9,
199,
199,
318,
15288,
63,
1494,
63,
981,
63,
578,
63,
10622,
8,
4991,
63,
1494,
63,
694,
63,
1391,
304,
421,
198,
692,
747,
14,
515,
14,
6027,
8,
4991,
63,
1494,
63,
694,
63,
1391,
9,
508,
715,
26,
507,
198,
1107,
413,
421,
198,
1361,
298,
14380,
2630,
63,
1494,
63,
694,
26,
298,
435,
2630,
63,
1494,
63,
694,
63,
1391,
199,
198,
3292,
275,
747,
14,
8215,
8,
4991,
63,
1494,
63,
694,
63,
1391,
9,
199,
198,
692,
2203,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
20366,
298,
435,
2630,
63,
1494,
63,
694,
63,
1391,
9,
421,
198,
1107,
199,
199,
318,
15288,
63,
1494,
63,
1506,
63,
4161,
63,
2613,
8,
4991,
63,
1494,
63,
694,
63,
1391,
12,
2630,
63,
1494,
63,
354,
304,
199,
198,
2966,
2630,
63,
1494,
63,
719,
199,
198,
2966,
2630,
63,
1494,
63,
826,
63,
719,
199,
198,
1436,
275,
3087,
421,
198,
70,
275,
2630,
63,
1494,
63,
694,
63,
1391,
435,
10609,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1095,
14,
72,
2,
199,
198,
1361,
298,
16646,
570,
26,
298,
435,
289,
421,
198,
80,
275,
1551,
8,
70,
12,
283,
87,
11339,
199,
198,
692,
440,
299,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
1551,
570,
26,
298,
435,
289,
9,
421,
198,
1436,
275,
5426,
4640,
298,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
4612,
198,
4451,
86,
16,
14,
17,
13356,
78,
2,
199,
198,
1436,
847,
5426,
4640,
298,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
198,
708,
60,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
7745,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
14161,
13064,
32612,
3747,
10977,
2812,
367,
20934,
21412,
707,
653,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
772,
302,
719,
63,
25944,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
10485,
7871,
30415,
9060,
367,
20934,
21412,
707,
653,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1560,
302,
719,
63,
354,
905,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
22842,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
23964,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
932,
63,
5853,
542,
63,
932,
63,
5853,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
5249,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
20934,
27167,
1347,
18428,
1572,
1947,
367,
28526,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
975,
27167,
63,
28552,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
28833,
1771,
370,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
627,
25623,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
5249,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
8707,
63,
923,
542,
63,
5249,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
17822,
4113,
314,
27167,
365,
13070,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
24,
27167,
63,
2625,
63,
344,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
14161,
13064,
32612,
3747,
10977,
2812,
367,
20934,
10256,
491,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
772,
27167,
63,
25944,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
10485,
7871,
30415,
9060,
367,
20934,
10256,
491,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1560,
27167,
63,
354,
905,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
22842,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
25623,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
10988,
27167,
63,
10988,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
421,
198,
3292,
275,
299,
14,
952,
8,
1436,
9,
199,
198,
692,
2203,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
2218,
289,
26,
298,
435,
289,
9,
421,
198,
80,
14,
1600,
342,
421,
198,
4991,
63,
1494,
63,
719,
275,
298,
25623,
2,
199,
198,
4991,
63,
1494,
63,
826,
63,
719,
275,
298,
78,
719,
2,
421,
198,
1107,
199,
199,
318,
15288,
63,
1494,
63,
1506,
63,
15319,
63,
2613,
8,
4991,
63,
1494,
63,
694,
63,
1391,
12,
2630,
63,
1494,
63,
354,
304
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
710,
28526,
373,
20,
3510,
13,
3922,
2630,
859,
10152,
2884,
367,
19016,
15,
1375,
21792,
11365,
63,
8816,
199,
3,
199,
3,
1898,
334,
67,
9,
7129,
820,
11136,
377,
2655,
15285,
199,
3,
1898,
334,
67,
9,
7129,
10130,
13,
21534,
14,
1308,
199,
3,
199,
3,
6529,
26,
302,
371,
32,
4989,
14,
1308,
199,
3,
199,
646,
747,
12,
984,
199,
646,
3873,
465,
1007,
199,
646,
1059,
199,
646,
295,
199,
646,
8691,
199,
199,
10606,
63,
694,
275,
3087,
199,
199,
4991,
63,
1483,
275,
942,
199,
4991,
63,
1494,
63,
694,
275,
3087,
199,
4991,
63,
1494,
63,
719,
275,
3087,
199,
4991,
63,
1494,
63,
826,
63,
719,
275,
3087,
199,
199,
318,
15288,
63,
1494,
63,
1508,
8,
1328,
304,
199,
198,
1361,
1499,
199,
198,
1274,
14,
2224,
8,
17,
9,
199,
199,
318,
15288,
63,
1494,
63,
981,
63,
578,
63,
10622,
8,
4991,
63,
1494,
63,
694,
63,
1391,
304,
421,
198,
692,
747,
14,
515,
14,
6027,
8,
4991,
63,
1494,
63,
694,
63,
1391,
9,
508,
715,
26,
507,
198,
1107,
413,
421,
198,
1361,
298,
14380,
2630,
63,
1494,
63,
694,
26,
298,
435,
2630,
63,
1494,
63,
694,
63,
1391,
199,
198,
3292,
275,
747,
14,
8215,
8,
4991,
63,
1494,
63,
694,
63,
1391,
9,
199,
198,
692,
2203,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
20366,
298,
435,
2630,
63,
1494,
63,
694,
63,
1391,
9,
421,
198,
1107,
199,
199,
318,
15288,
63,
1494,
63,
1506,
63,
4161,
63,
2613,
8,
4991,
63,
1494,
63,
694,
63,
1391,
12,
2630,
63,
1494,
63,
354,
304,
199,
198,
2966,
2630,
63,
1494,
63,
719,
199,
198,
2966,
2630,
63,
1494,
63,
826,
63,
719,
199,
198,
1436,
275,
3087,
421,
198,
70,
275,
2630,
63,
1494,
63,
694,
63,
1391,
435,
10609,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1095,
14,
72,
2,
199,
198,
1361,
298,
16646,
570,
26,
298,
435,
289,
421,
198,
80,
275,
1551,
8,
70,
12,
283,
87,
11339,
199,
198,
692,
440,
299,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
1551,
570,
26,
298,
435,
289,
9,
421,
198,
1436,
275,
5426,
4640,
298,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
4612,
198,
4451,
86,
16,
14,
17,
13356,
78,
2,
199,
198,
1436,
847,
5426,
4640,
298,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
198,
708,
60,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
7745,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
14161,
13064,
32612,
3747,
10977,
2812,
367,
20934,
21412,
707,
653,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
772,
302,
719,
63,
25944,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
10485,
7871,
30415,
9060,
367,
20934,
21412,
707,
653,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1560,
302,
719,
63,
354,
905,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
22842,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
23964,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
932,
63,
5853,
542,
63,
932,
63,
5853,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
5249,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
20934,
27167,
1347,
18428,
1572,
1947,
367,
28526,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
975,
27167,
63,
28552,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
28833,
1771,
370,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
627,
25623,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
5249,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
8707,
63,
923,
542,
63,
5249,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
17822,
4113,
314,
27167,
365,
13070,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
24,
27167,
63,
2625,
63,
344,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
14161,
13064,
32612,
3747,
10977,
2812,
367,
20934,
10256,
491,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
772,
27167,
63,
25944,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
10485,
7871,
30415,
9060,
367,
20934,
10256,
491,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1560,
27167,
63,
354,
905,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
22842,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
25623,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
10988,
27167,
63,
10988,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
421,
198,
3292,
275,
299,
14,
952,
8,
1436,
9,
199,
198,
692,
2203,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
2218,
289,
26,
298,
435,
289,
9,
421,
198,
80,
14,
1600,
342,
421,
198,
4991,
63,
1494,
63,
719,
275,
298,
25623,
2,
199,
198,
4991,
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
] |
cobbler/cobbler
|
cobbler/cobbler_collections/mgmtclasses.py
|
1
|
2621
|
"""
Copyright 2010, Kelsey Hightower
Kelsey Hightower <kelsey.hightower@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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
"""
from cobbler.cobbler_collections import collection
from cobbler.items import mgmtclass as mgmtclass
from cobbler import utils
from cobbler.cexceptions import CX
class Mgmtclasses(collection.Collection):
"""
A mgmtclass provides a container for management resources.
"""
@staticmethod
def collection_type() -> str:
return "mgmtclass"
@staticmethod
def collection_types() -> str:
return "mgmtclasses"
def factory_produce(self, api, item_dict):
"""
Return a mgmtclass forged from item_dict
:param api: TODO
:param item_dict: TODO
:returns: TODO
"""
new_mgmtclass = mgmtclass.Mgmtclass(api)
new_mgmtclass.from_dict(item_dict)
return new_mgmtclass
def remove(self, name, with_delete: bool = True, with_sync: bool = True, with_triggers: bool = True,
recursive: bool = False):
"""
Remove element named 'name' from the collection
:raises CX
"""
name = name.lower()
obj = self.find(name=name)
if obj is not None:
if with_delete:
if with_triggers:
utils.run_triggers(self.api, obj, "/var/lib/cobbler/triggers/delete/mgmtclass/pre/*", [])
self.lock.acquire()
try:
del self.listing[name]
finally:
self.lock.release()
self.collection_mgr.serialize_delete(self, obj)
if with_delete:
if with_triggers:
utils.run_triggers(self.api, obj, "/var/lib/cobbler/triggers/delete/mgmtclass/post/*", [])
utils.run_triggers(self.api, obj, "/var/lib/cobbler/triggers/change/*", [])
return
raise CX("cannot delete an object that does not exist: %s" % name)
|
gpl-2.0
|
[
624,
199,
7384,
7129,
12,
1804,
2836,
89,
16332,
21651,
199,
43,
2836,
89,
16332,
21651,
665,
75,
2836,
89,
14,
6260,
21651,
32,
6799,
14,
957,
30,
199,
199,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
30216,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
996,
6019,
13,
10067,
221,
8217,
199,
624,
199,
199,
504,
512,
26722,
14,
331,
26722,
63,
7882,
492,
3245,
199,
504,
512,
26722,
14,
1744,
492,
333,
22489,
533,
465,
333,
22489,
533,
199,
504,
512,
26722,
492,
3778,
199,
504,
512,
26722,
14,
301,
16010,
83,
492,
445,
56,
421,
199,
533,
603,
22489,
2888,
8,
3627,
14,
7768,
304,
272,
408,
272,
437,
333,
22489,
533,
6571,
282,
3970,
367,
10041,
5944,
14,
272,
408,
339,
768,
4639,
272,
347,
3245,
63,
466,
342,
1035,
620,
26,
267,
372,
298,
9752,
533,
2,
339,
768,
4639,
272,
347,
3245,
63,
1313,
342,
1035,
620,
26,
267,
372,
298,
9752,
2888,
2,
339,
347,
6434,
63,
7832,
8,
277,
12,
2986,
12,
1242,
63,
807,
304,
267,
408,
267,
1432,
282,
333,
22489,
533,
367,
3046,
687,
1242,
63,
807,
398,
520,
635,
2986,
26,
3254,
267,
520,
635,
1242,
63,
807,
26,
3254,
267,
520,
5808,
26,
3254,
267,
408,
267,
892,
63,
9752,
533,
275,
333,
22489,
533,
14,
45,
22489,
533,
8,
1246,
9,
267,
892,
63,
9752,
533,
14,
504,
63,
807,
8,
1053,
63,
807,
9,
267,
372,
892,
63,
9752,
533,
339,
347,
2813,
8,
277,
12,
536,
12,
543,
63,
1807,
26,
2155,
275,
715,
12,
543,
63,
5186,
26,
2155,
275,
715,
12,
543,
63,
26328,
26,
2155,
275,
715,
12,
2049,
9133,
26,
2155,
275,
756,
304,
267,
408,
267,
5852,
1819,
4310,
283,
354,
7,
687,
314,
3245,
398,
520,
3536,
445,
56,
267,
408,
398,
536,
275,
536,
14,
2325,
342,
267,
1559,
275,
291,
14,
1623,
8,
354,
29,
354,
9,
267,
340,
1559,
365,
440,
488,
26,
288,
340,
543,
63,
1807,
26,
355,
340,
543,
63,
26328,
26,
490,
3778,
14,
1065,
63,
26328,
8,
277,
14,
1246,
12,
1559,
12,
3286,
1391,
15,
773,
15,
331,
26722,
15,
26328,
15,
1807,
15,
9752,
533,
15,
657,
6331,
401,
3073,
953,
291,
14,
831,
14,
8174,
342,
288,
862,
26,
355,
2150,
291,
14,
16115,
59,
354,
61,
288,
3753,
26,
355,
291,
14,
831,
14,
3221,
342,
288,
291,
14,
3627,
63,
7755,
14,
3549,
63,
1807,
8,
277,
12,
1559,
9,
953,
340,
543,
63,
1807,
26,
355,
340,
543,
63,
26328,
26,
490,
3778,
14,
1065,
63,
26328,
8,
277,
14,
1246,
12,
1559,
12,
3286,
1391,
15,
773,
15,
331,
26722,
15,
26328,
15,
1807,
15,
9752,
533,
15,
1932,
6331,
401,
3073,
490,
3778,
14,
1065,
63,
26328,
8,
277,
14,
1246,
12,
1559,
12,
3286,
1391,
15,
773,
15,
331,
26722,
15,
26328,
15,
1461,
6331,
401,
3073,
953,
372,
398,
746,
445,
56,
480,
11250,
3145,
376,
909,
626,
1630,
440,
2187,
26,
450,
83,
2,
450,
536,
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
] |
[
199,
7384,
7129,
12,
1804,
2836,
89,
16332,
21651,
199,
43,
2836,
89,
16332,
21651,
665,
75,
2836,
89,
14,
6260,
21651,
32,
6799,
14,
957,
30,
199,
199,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
30216,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
996,
6019,
13,
10067,
221,
8217,
199,
624,
199,
199,
504,
512,
26722,
14,
331,
26722,
63,
7882,
492,
3245,
199,
504,
512,
26722,
14,
1744,
492,
333,
22489,
533,
465,
333,
22489,
533,
199,
504,
512,
26722,
492,
3778,
199,
504,
512,
26722,
14,
301,
16010,
83,
492,
445,
56,
421,
199,
533,
603,
22489,
2888,
8,
3627,
14,
7768,
304,
272,
408,
272,
437,
333,
22489,
533,
6571,
282,
3970,
367,
10041,
5944,
14,
272,
408,
339,
768,
4639,
272,
347,
3245,
63,
466,
342,
1035,
620,
26,
267,
372,
298,
9752,
533,
2,
339,
768,
4639,
272,
347,
3245,
63,
1313,
342,
1035,
620,
26,
267,
372,
298,
9752,
2888,
2,
339,
347,
6434,
63,
7832,
8,
277,
12,
2986,
12,
1242,
63,
807,
304,
267,
408,
267,
1432,
282,
333,
22489,
533,
367,
3046,
687,
1242,
63,
807,
398,
520,
635,
2986,
26,
3254,
267,
520,
635,
1242,
63,
807,
26,
3254,
267,
520,
5808,
26,
3254,
267,
408,
267,
892,
63,
9752,
533,
275,
333,
22489,
533,
14,
45,
22489,
533,
8,
1246,
9,
267,
892,
63,
9752,
533,
14,
504,
63,
807,
8,
1053,
63,
807,
9,
267,
372,
892,
63,
9752,
533,
339,
347,
2813,
8,
277,
12,
536,
12,
543,
63,
1807,
26,
2155,
275,
715,
12,
543,
63,
5186,
26,
2155,
275,
715,
12,
543,
63,
26328,
26,
2155,
275,
715,
12,
2049,
9133,
26,
2155,
275,
756,
304,
267,
408,
267,
5852,
1819,
4310,
283,
354,
7,
687,
314,
3245,
398,
520,
3536,
445,
56,
267,
408,
398,
536,
275,
536,
14,
2325,
342,
267,
1559,
275,
291,
14,
1623,
8,
354,
29,
354,
9,
267,
340,
1559,
365,
440,
488,
26,
288,
340,
543,
63,
1807,
26,
355,
340,
543,
63,
26328,
26,
490,
3778,
14,
1065,
63,
26328,
8,
277,
14,
1246,
12,
1559,
12,
3286,
1391,
15,
773,
15,
331,
26722,
15,
26328,
15,
1807,
15,
9752,
533,
15,
657,
6331,
401,
3073,
953,
291,
14,
831,
14,
8174,
342,
288,
862,
26,
355,
2150,
291,
14,
16115,
59,
354,
61,
288,
3753,
26,
355,
291,
14,
831,
14,
3221,
342,
288,
291,
14,
3627,
63,
7755,
14,
3549,
63,
1807,
8,
277,
12,
1559,
9,
953,
340,
543,
63,
1807,
26,
355,
340,
543,
63,
26328,
26,
490,
3778,
14,
1065,
63,
26328,
8,
277,
14,
1246,
12,
1559,
12,
3286,
1391,
15,
773,
15,
331,
26722,
15,
26328,
15,
1807,
15,
9752,
533,
15,
1932,
6331,
401,
3073,
490,
3778,
14,
1065,
63,
26328,
8,
277,
14,
1246,
12,
1559,
12,
3286,
1391,
15,
773,
15,
331,
26722,
15,
26328,
15,
1461,
6331,
401,
3073,
953,
372,
398,
746,
445,
56,
480,
11250,
3145,
376,
909,
626,
1630,
440,
2187,
26,
450,
83,
2,
450,
536,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dunkhong/grr
|
grr/client/grr_response_client/client_actions/osquery.py
|
1
|
8557
|
#!/usr/bin/env python
"""A module with client action for talking with osquery."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import collections
import os
from future.builtins import map
from future.utils import iterkeys
from typing import Any
from typing import Iterator
from typing import List
from typing import NamedTuple
from typing import Text
from grr_response_client import actions
from grr_response_core import config
from grr_response_core.lib.rdfvalues import osquery as rdf_osquery
from grr_response_core.lib.util import precondition
from grr_response_core.lib.util.compat import json
# pylint: disable=g-import-not-at-top
try:
# TODO: `subprocess32` is a backport of Python 3.2+ `subprocess`
# API. Once support for older versions of Python is dropped, this import can
# be removed.
import subprocess32 as subprocess
except ImportError:
import subprocess
# pylint: enable=g-import-not-at-top
class Error(Exception):
"""A class for all osquery-related exceptions."""
def __init__(self, message, cause = None):
if cause is not None:
message = "{message}: {cause}".format(message=message, cause=cause)
super(Error, self).__init__(message)
self.cause = cause
class QueryError(Error):
"""A class of exceptions indicating invalid queries (e.g. syntax errors)."""
def __init__(self, output, cause = None):
message = "invalid query: {}".format(output)
super(QueryError, self).__init__(message, cause=cause)
class TimeoutError(Error):
"""A class of exceptions raised when a call to osquery timeouts."""
def __init__(self, cause = None):
super(TimeoutError, self).__init__("osquery timeout", cause=cause)
class Osquery(actions.ActionPlugin):
"""An action plugin class for talking with osquery."""
in_rdfvalue = rdf_osquery.OsqueryArgs
out_rdfvalues = [rdf_osquery.OsqueryResult]
def Run(self, args):
for result in self.Process(args):
self.SendReply(result)
# TODO(hanuszczak): This does not need to be a class method. It should be
# refactored to a separate function and tested as such.
def Process(self, args):
if not config.CONFIG["Osquery.path"]:
raise RuntimeError("The `Osquery` action invoked on a client without "
"osquery path specified.")
if not os.path.exists(config.CONFIG["Osquery.path"]):
raise RuntimeError("The `Osquery` action invoked on a client where "
"osquery executable is not available.")
if not args.query:
raise ValueError("The `Osquery` was invoked with an empty query.")
output = Query(args)
# For syntax errors, osquery does not fail (exits with 0) but prints stuff
# to the standard error.
if output.stderr and not args.ignore_stderr_errors:
raise QueryError(output.stderr)
json_decoder = json.Decoder(object_pairs_hook=collections.OrderedDict)
table = ParseTable(json_decoder.decode(output.stdout))
table.query = args.query
for chunk in ChunkTable(table, config.CONFIG["Osquery.max_chunk_size"]):
yield rdf_osquery.OsqueryResult(table=chunk, stderr=output.stderr)
def ChunkTable(table,
max_chunk_size):
"""Chunks given table into multiple smaller ones.
Tables that osquery yields can be arbitrarily large. Because GRR's messages
cannot be arbitrarily large, it might happen that the table has to be split
into multiple smaller ones.
Note that that serialized response protos are going to be slightly bigger than
the specified limit. For regular values the additional payload should be
negligible.
Args:
table: A table to split into multiple smaller ones.
max_chunk_size: A maximum size of the returned table in bytes.
Yields:
Tables with the same query and headers as the input table and a subset of
rows.
"""
def ByteLength(string):
return len(string.encode("utf-8"))
def Chunk():
result = rdf_osquery.OsqueryTable()
result.query = table.query
result.header = table.header
return result
chunk = Chunk()
chunk_size = 0
for row in table.rows:
row_size = sum(map(ByteLength, row.values))
if chunk_size + row_size > max_chunk_size:
yield chunk
chunk = Chunk()
chunk_size = 0
chunk.rows.append(row)
chunk_size += row_size
# We want to yield extra chunk in two cases:
# * there are some rows that did not cause the chunk to overflow so it has not
# been yielded as part of the loop.
# * the initial table has no rows but we still need to yield some table even
# if it is empty.
if chunk.rows or not table.rows:
yield chunk
def ParseTable(table):
"""Parses table of osquery output.
Args:
table: A table in a "parsed JSON" representation.
Returns:
A parsed `rdf_osquery.OsqueryTable` instance.
"""
precondition.AssertIterableType(table, dict)
result = rdf_osquery.OsqueryTable()
result.header = ParseHeader(table)
for row in table:
result.rows.append(ParseRow(result.header, row))
return result
# TODO: Parse type information.
def ParseHeader(table):
"""Parses header of osquery output.
Args:
table: A table in a "parsed JSON" representation.
Returns:
A parsed `rdf_osquery.OsqueryHeader` instance.
"""
precondition.AssertIterableType(table, dict)
prototype = None # type: List[Text]
for row in table:
columns = list(iterkeys(row))
if prototype is None:
prototype = columns
elif prototype != columns:
message = "Expected columns '{expected}', got '{actual}' for table {json}"
message = message.format(expected=prototype, actual=columns, json=table)
raise ValueError(message)
result = rdf_osquery.OsqueryHeader()
for name in prototype or []:
result.columns.append(rdf_osquery.OsqueryColumn(name=name))
return result
def ParseRow(header,
row):
"""Parses a single row of osquery output.
Args:
header: A parsed header describing the row format.
row: A row in a "parsed JSON" representation.
Returns:
A parsed `rdf_osquery.OsqueryRow` instance.
"""
precondition.AssertDictType(row, Text, Text)
result = rdf_osquery.OsqueryRow()
for column in header.columns:
result.values.append(row[column.name])
return result
# TODO(hanuszczak): https://github.com/python/typeshed/issues/2761
ProcOutput = NamedTuple("ProcOutput", [("stdout", Text), ("stderr", Text)]) # pytype: disable=wrong-arg-types
def Query(args):
"""Calls osquery with given query and returns its output.
Args:
args: A query to call osquery with.
Returns:
A "parsed JSON" representation of the osquery output.
Raises:
QueryError: If the query is incorrect.
TimeoutError: If a call to the osquery executable times out.
Error: If anything else goes wrong with the subprocess call.
"""
timeout = args.timeout_millis / 1000 # `subprocess.run` uses seconds.
# TODO: pytype is not aware of the backport.
# pytype: disable=module-attr
try:
# We use `--S` to enforce shell execution. This is because on Windows there
# is only `osqueryd` and `osqueryi` is not available. However, by passing
# `--S` we can make `osqueryd` behave like `osqueryi`. Since this flag also
# works with `osqueryi`, by passing it we simply expand number of supported
# executable types.
command = [
config.CONFIG["Osquery.path"],
"--S", # Enforce shell execution.
"--logger_stderr=false", # Only allow errors to be written to stderr.
"--logger_min_status=3", # Disable status logs.
"--logger_min_stderr=2", # Only ERROR-level logs to stderr.
"--json", # Set output format to JSON.
args.query,
]
proc = subprocess.run(
command,
timeout=timeout,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
# TODO: Since we use a backported API, `SubprocessError` is hard
# to work with. Until support for Python 2 is dropped we re-raise with simpler
# exception type because we don't really care that much (the exception message
# should be detailed enough anyway).
except subprocess.TimeoutExpired as error:
raise TimeoutError(cause=error)
except subprocess.CalledProcessError as error:
raise Error("osquery invocation error", cause=error)
# pytype: enable=module-attr
stdout = proc.stdout.decode("utf-8")
stderr = proc.stderr.decode("utf-8").strip()
return ProcOutput(stdout=stdout, stderr=stderr)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
33,
859,
543,
1890,
1595,
367,
22811,
316,
543,
747,
1131,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
5055,
199,
646,
747,
199,
199,
504,
6466,
14,
10372,
492,
2341,
199,
504,
6466,
14,
1208,
492,
25706,
199,
504,
14090,
492,
6184,
199,
504,
14090,
492,
25769,
199,
504,
14090,
492,
3820,
199,
504,
14090,
492,
16198,
7075,
199,
504,
14090,
492,
4516,
199,
199,
504,
31118,
63,
1310,
63,
1258,
492,
5445,
199,
504,
31118,
63,
1310,
63,
1018,
492,
1101,
199,
504,
31118,
63,
1310,
63,
1018,
14,
773,
14,
17120,
1459,
492,
747,
1131,
465,
18148,
63,
736,
1131,
199,
504,
31118,
63,
1310,
63,
1018,
14,
773,
14,
1974,
492,
876,
5394,
199,
504,
31118,
63,
1310,
63,
1018,
14,
773,
14,
1974,
14,
5819,
492,
2022,
199,
199,
3,
4287,
26,
3507,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
199,
893,
26,
523,
327,
3254,
26,
658,
5781,
708,
64,
365,
282,
1771,
719,
402,
2018,
650,
14,
18,
11,
658,
5781,
64,
523,
327,
3261,
14,
19468,
2291,
367,
12731,
5459,
402,
2018,
365,
17481,
12,
642,
492,
883,
523,
327,
506,
4829,
14,
523,
492,
3873,
708,
465,
3873,
199,
2590,
3545,
26,
523,
492,
3873,
199,
3,
4287,
26,
4756,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
421,
199,
533,
4520,
8,
1726,
304,
523,
408,
33,
1021,
367,
1006,
747,
1131,
13,
2407,
4967,
1041,
819,
347,
636,
826,
721,
277,
12,
1245,
12,
7675,
275,
488,
304,
272,
340,
7675,
365,
440,
488,
26,
489,
1245,
275,
5310,
1188,
9160,
469,
2651,
5469,
908,
8,
1188,
29,
1188,
12,
7675,
29,
2651,
9,
339,
1613,
8,
547,
12,
291,
2843,
826,
721,
1188,
9,
272,
291,
14,
2651,
275,
7675,
421,
199,
533,
8133,
547,
8,
547,
304,
523,
408,
33,
1021,
402,
4967,
9297,
3866,
9212,
334,
69,
14,
71,
14,
6302,
2552,
10477,
819,
347,
636,
826,
721,
277,
12,
1072,
12,
7675,
275,
488,
304,
272,
1245,
275,
298,
3197,
1827,
26,
8352,
908,
8,
1199,
9,
272,
1613,
8,
3227,
547,
12,
291,
2843,
826,
721,
1188,
12,
7675,
29,
2651,
9,
421,
199,
533,
31886,
8,
547,
304,
523,
408,
33,
1021,
402,
4967,
4915,
1380,
282,
1240,
370,
747,
1131,
25870,
1041,
819,
347,
636,
826,
721,
277,
12,
7675,
275,
488,
304,
272,
1613,
8,
19382,
12,
291,
2843,
826,
29093,
736,
1131,
2653,
401,
7675,
29,
2651,
9,
421,
199,
533,
593,
83,
1131,
8,
3723,
14,
3310,
5061,
304,
523,
408,
2493,
1595,
3589,
1021,
367,
22811,
316,
543,
747,
1131,
1041,
819,
315,
63,
17120,
585,
275,
18148,
63,
736,
1131,
14,
24351,
1131,
6213,
523,
734,
63,
17120,
1459,
275,
359,
17120,
63,
736,
1131,
14,
24351,
1131,
2889,
61,
819,
347,
3378,
8,
277,
12,
1249,
304,
272,
367,
754,
315,
291,
14,
3498,
8,
589,
304,
489,
291,
14,
6795,
14166,
8,
1099,
9,
819,
327,
3254,
8,
19262,
527,
90,
16823,
1151,
304,
961,
1630,
440,
1929,
370,
506,
282,
1021,
1083,
14,
2779,
1077,
506,
523,
327,
295,
7783,
2908,
370,
282,
7396,
805,
436,
12470,
465,
4066,
14,
523,
347,
7132,
8,
277,
12,
1249,
304,
272,
340,
440,
1101,
14,
5569,
905,
24351,
1131,
14,
515,
6229,
489,
746,
6064,
480,
1918,
658,
24351,
1131,
64,
1595,
10302,
641,
282,
1890,
1928,
298,
586,
298,
736,
1131,
931,
2013,
2685,
339,
340,
440,
747,
14,
515,
14,
2444,
8,
888,
14,
5569,
905,
24351,
1131,
14,
515,
21473,
489,
746,
6064,
480,
1918,
658,
24351,
1131,
64,
1595,
10302,
641,
282,
1890,
2382,
298,
586,
298,
736,
1131,
7286,
365,
440,
2808,
2685,
339,
340,
440,
1249,
14,
1131,
26,
489,
746,
1722,
480,
1918,
658,
24351,
1131,
64,
1990,
10302,
543,
376,
2701,
1827,
2685,
339,
1072,
275,
8133,
8,
589,
9,
339,
327,
2104,
6302,
2552,
12,
747,
1131,
1630,
440,
2449,
334,
476,
1405,
543,
378,
9,
1325,
14767,
8292,
272,
327,
370,
314,
4465,
1125,
14,
272,
340,
1072,
14,
3083,
436,
440,
1249,
14,
4247,
63,
3083,
63,
2550,
26,
489,
746,
8133,
547,
8,
1199,
14,
3083,
9,
339,
2022,
63,
8813,
275,
2022,
14,
8326,
8,
785,
63,
7322,
63,
3664,
29,
7882,
14,
16882,
9,
339,
1817,
275,
6077,
3186,
8,
1001,
63,
8813,
14,
2708,
8,
1199,
14,
2703,
430,
272,
1817,
14,
1131,
275,
1249,
14,
1131,
339,
367,
3728,
315,
25246,
3186,
8,
1224,
12,
1101,
14,
5569,
905,
24351,
1131,
14,
988,
63,
4604,
63,
890,
21473,
489,
1995,
18148,
63,
736,
1131,
14,
24351,
1131,
2889,
8,
1224,
29,
4604,
12,
4635,
29,
1199,
14,
3083,
9,
421,
199,
318,
25246,
3186,
8,
1224,
12,
2049,
1390,
63,
4604,
63,
890,
304,
523,
408,
9856,
83,
1627,
1817,
1901,
3663,
12700,
7869,
14,
819,
377,
5921,
626,
747,
1131,
14801,
883,
506,
601,
2075,
82,
11406,
7031,
14,
13821,
598,
13381,
1159,
3788,
523,
3913,
506,
601,
2075,
82,
11406,
7031,
12,
652,
5594,
5992,
626,
314,
1817,
965,
370,
506,
3715,
523,
1901,
3663,
12700,
7869,
14,
819,
3390,
626,
626,
6380,
1177,
4104,
83,
787,
9995,
370,
506,
18023,
29416,
2419,
523,
314,
2013,
2304,
14,
2104,
5578,
1338,
314,
4722,
4886,
1077,
506,
523,
14158,
317,
28297,
14,
819,
3033,
26,
272,
1817,
26,
437,
1817,
370,
3715,
1901,
3663,
12700,
7869,
14,
272,
1390,
63,
4604,
63,
890,
26,
437,
5696,
1568,
402,
314,
2138,
1817,
315,
2783,
14,
819,
23771,
83,
26,
272,
377,
5921,
543,
314,
2011,
1827,
436,
2323,
465,
314,
1324,
1817,
436,
282,
10026,
402,
272,
4730,
14,
523,
408,
819,
347,
20301,
4625,
8,
875,
304,
272,
372,
822,
8,
875,
14,
2143,
480,
1624,
13,
24,
2237,
819,
347,
25246,
837,
272,
754,
275,
18148,
63,
736,
1131,
14,
24351,
1131,
3186,
342,
272,
754,
14,
1131,
275,
1817,
14,
1131,
272,
754,
14,
1291
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
33,
859,
543,
1890,
1595,
367,
22811,
316,
543,
747,
1131,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
5055,
199,
646,
747,
199,
199,
504,
6466,
14,
10372,
492,
2341,
199,
504,
6466,
14,
1208,
492,
25706,
199,
504,
14090,
492,
6184,
199,
504,
14090,
492,
25769,
199,
504,
14090,
492,
3820,
199,
504,
14090,
492,
16198,
7075,
199,
504,
14090,
492,
4516,
199,
199,
504,
31118,
63,
1310,
63,
1258,
492,
5445,
199,
504,
31118,
63,
1310,
63,
1018,
492,
1101,
199,
504,
31118,
63,
1310,
63,
1018,
14,
773,
14,
17120,
1459,
492,
747,
1131,
465,
18148,
63,
736,
1131,
199,
504,
31118,
63,
1310,
63,
1018,
14,
773,
14,
1974,
492,
876,
5394,
199,
504,
31118,
63,
1310,
63,
1018,
14,
773,
14,
1974,
14,
5819,
492,
2022,
199,
199,
3,
4287,
26,
3507,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
199,
893,
26,
523,
327,
3254,
26,
658,
5781,
708,
64,
365,
282,
1771,
719,
402,
2018,
650,
14,
18,
11,
658,
5781,
64,
523,
327,
3261,
14,
19468,
2291,
367,
12731,
5459,
402,
2018,
365,
17481,
12,
642,
492,
883,
523,
327,
506,
4829,
14,
523,
492,
3873,
708,
465,
3873,
199,
2590,
3545,
26,
523,
492,
3873,
199,
3,
4287,
26,
4756,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
421,
199,
533,
4520,
8,
1726,
304,
523,
408,
33,
1021,
367,
1006,
747,
1131,
13,
2407,
4967,
1041,
819,
347,
636,
826,
721,
277,
12,
1245,
12,
7675,
275,
488,
304,
272,
340,
7675,
365,
440,
488,
26,
489,
1245,
275,
5310,
1188,
9160,
469,
2651,
5469,
908,
8,
1188,
29,
1188,
12,
7675,
29,
2651,
9,
339,
1613,
8,
547,
12,
291,
2843,
826,
721,
1188,
9,
272,
291,
14,
2651,
275,
7675,
421,
199,
533,
8133,
547,
8,
547,
304,
523,
408,
33,
1021,
402,
4967,
9297,
3866,
9212,
334,
69,
14,
71,
14,
6302,
2552,
10477,
819,
347,
636,
826,
721,
277,
12,
1072,
12,
7675,
275,
488,
304,
272,
1245,
275,
298,
3197,
1827,
26,
8352,
908,
8,
1199,
9,
272,
1613,
8,
3227,
547,
12,
291,
2843,
826,
721,
1188,
12,
7675,
29,
2651,
9,
421,
199,
533,
31886,
8,
547,
304,
523,
408,
33,
1021,
402,
4967,
4915,
1380,
282,
1240,
370,
747,
1131,
25870,
1041,
819,
347,
636,
826,
721,
277,
12,
7675,
275,
488,
304,
272,
1613,
8,
19382,
12,
291,
2843,
826,
29093,
736,
1131,
2653,
401,
7675,
29,
2651,
9,
421,
199,
533,
593,
83,
1131,
8,
3723,
14,
3310,
5061,
304,
523,
408,
2493,
1595,
3589,
1021,
367,
22811,
316,
543,
747,
1131,
1041,
819,
315,
63,
17120,
585,
275,
18148,
63,
736,
1131,
14,
24351,
1131,
6213,
523,
734,
63,
17120,
1459,
275,
359,
17120,
63,
736,
1131,
14,
24351,
1131,
2889,
61,
819,
347,
3378,
8,
277,
12,
1249,
304,
272,
367,
754,
315,
291,
14,
3498,
8,
589,
304,
489,
291,
14,
6795,
14166,
8,
1099,
9,
819,
327,
3254,
8,
19262,
527,
90,
16823,
1151,
304,
961,
1630,
440,
1929,
370,
506,
282,
1021,
1083,
14,
2779,
1077,
506,
523,
327,
295,
7783,
2908,
370,
282,
7396,
805,
436,
12470,
465,
4066,
14,
523,
347,
7132,
8,
277,
12,
1249,
304,
272,
340,
440,
1101,
14,
5569,
905,
24351,
1131,
14,
515,
6229,
489,
746,
6064,
480,
1918,
658,
24351,
1131,
64,
1595,
10302,
641,
282,
1890,
1928,
298,
586,
298,
736,
1131,
931,
2013,
2685,
339,
340,
440,
747,
14,
515,
14,
2444,
8,
888,
14,
5569,
905,
24351,
1131,
14,
515,
21473,
489,
746,
6064,
480,
1918,
658,
24351,
1131,
64,
1595,
10302,
641,
282,
1890,
2382,
298,
586,
298,
736,
1131,
7286,
365,
440,
2808,
2685,
339,
340,
440,
1249,
14,
1131,
26,
489,
746,
1722,
480,
1918,
658,
24351,
1131,
64,
1990,
10302,
543,
376,
2701,
1827,
2685,
339,
1072,
275,
8133,
8,
589,
9,
339,
327,
2104,
6302,
2552,
12,
747,
1131,
1630,
440,
2449,
334,
476,
1405,
543,
378,
9,
1325,
14767,
8292,
272,
327,
370,
314,
4465,
1125,
14,
272,
340,
1072,
14,
3083,
436,
440,
1249,
14,
4247,
63,
3083,
63,
2550,
26,
489,
746,
8133,
547,
8,
1199,
14,
3083,
9,
339,
2022,
63,
8813,
275,
2022,
14,
8326,
8,
785,
63,
7322,
63,
3664,
29,
7882,
14,
16882,
9,
339,
1817,
275,
6077,
3186,
8,
1001,
63,
8813,
14,
2708,
8,
1199,
14,
2703,
430,
272,
1817,
14,
1131,
275,
1249,
14,
1131,
339,
367,
3728,
315,
25246,
3186,
8,
1224,
12,
1101,
14,
5569,
905,
24351,
1131,
14,
988,
63,
4604,
63,
890,
21473,
489,
1995,
18148,
63,
736,
1131,
14,
24351,
1131,
2889,
8,
1224,
29,
4604,
12,
4635,
29,
1199,
14,
3083,
9,
421,
199,
318,
25246,
3186,
8,
1224,
12,
2049,
1390,
63,
4604,
63,
890,
304,
523,
408,
9856,
83,
1627,
1817,
1901,
3663,
12700,
7869,
14,
819,
377,
5921,
626,
747,
1131,
14801,
883,
506,
601,
2075,
82,
11406,
7031,
14,
13821,
598,
13381,
1159,
3788,
523,
3913,
506,
601,
2075,
82,
11406,
7031,
12,
652,
5594,
5992,
626,
314,
1817,
965,
370,
506,
3715,
523,
1901,
3663,
12700,
7869,
14,
819,
3390,
626,
626,
6380,
1177,
4104,
83,
787,
9995,
370,
506,
18023,
29416,
2419,
523,
314,
2013,
2304,
14,
2104,
5578,
1338,
314,
4722,
4886,
1077,
506,
523,
14158,
317,
28297,
14,
819,
3033,
26,
272,
1817,
26,
437,
1817,
370,
3715,
1901,
3663,
12700,
7869,
14,
272,
1390,
63,
4604,
63,
890,
26,
437,
5696,
1568,
402,
314,
2138,
1817,
315,
2783,
14,
819,
23771,
83,
26,
272,
377,
5921,
543,
314,
2011,
1827,
436,
2323,
465,
314,
1324,
1817,
436,
282,
10026,
402,
272,
4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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
] |
virtualopensystems/neutron
|
neutron/db/migration/alembic_migrations/versions/4692d074d587_agent_scheduler.py
|
8
|
3255
|
# 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.
#
"""agent scheduler
Revision ID: 4692d074d587
Revises: 3b54bf9e29f7
Create Date: 2013-02-21 23:01:50.370306
"""
# revision identifiers, used by Alembic.
revision = '4692d074d587'
down_revision = '3b54bf9e29f7'
# Change to ['*'] if this migration applies to all plugins
migration_for_plugins = [
'neutron.plugins.brocade.NeutronPlugin.BrocadePluginV2',
'neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2',
'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2',
'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2',
'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin',
'neutron.plugins.nec.nec_plugin.NECPluginV2',
'neutron.plugins.vmware.plugin.NsxPlugin',
'neutron.plugins.vmware.plugin.NsxServicePlugin',
'neutron.plugins.oneconvergence.plugin.OneConvergencePluginV2',
'neutron.plugins.ml2.plugin.Ml2Plugin',
'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2'
]
from alembic import op
import sqlalchemy as sa
from neutron.db import migration
def upgrade(active_plugins=None, options=None):
if not migration.should_run(active_plugins, migration_for_plugins):
return
### commands auto generated by Alembic - please adjust! ###
op.create_table(
'networkdhcpagentbindings',
sa.Column('network_id', sa.String(length=36), nullable=False),
sa.Column('dhcp_agent_id', sa.String(length=36), nullable=False),
sa.ForeignKeyConstraint(['dhcp_agent_id'], ['agents.id'],
ondelete='CASCADE'),
sa.ForeignKeyConstraint(['network_id'], ['networks.id'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('network_id', 'dhcp_agent_id')
)
op.create_table(
'routerl3agentbindings',
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('router_id', sa.String(length=36), nullable=True),
sa.Column('l3_agent_id', sa.String(length=36), nullable=True),
sa.ForeignKeyConstraint(['l3_agent_id'], ['agents.id'],
ondelete='CASCADE'),
sa.ForeignKeyConstraint(['router_id'], ['routers.id'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
### end Alembic commands ###
def downgrade(active_plugins=None, options=None):
if not migration.should_run(active_plugins, migration_for_plugins):
return
### commands auto generated by Alembic - please adjust! ###
op.drop_table('routerl3agentbindings')
op.drop_table('networkdhcpagentbindings')
### end Alembic commands ###
|
apache-2.0
|
[
3,
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,
3,
199,
199,
624,
4054,
11899,
199,
199,
12714,
2870,
26,
841,
27041,
68,
24888,
68,
29071,
199,
497,
433,
874,
26,
650,
66,
1477,
4361,
25,
69,
1398,
70,
23,
199,
2499,
6148,
26,
6171,
13,
996,
13,
2025,
6546,
26,
614,
26,
1400,
14,
13812,
11363,
199,
199,
624,
199,
199,
3,
6974,
14154,
12,
1202,
701,
6832,
20596,
14,
199,
5792,
275,
283,
16112,
18,
68,
24888,
68,
29071,
7,
199,
2110,
63,
5792,
275,
283,
19,
66,
1477,
4361,
25,
69,
1398,
70,
23,
7,
199,
199,
3,
7743,
370,
788,
10,
418,
340,
642,
8367,
12966,
370,
1006,
8963,
199,
199,
8998,
63,
509,
63,
5265,
275,
359,
272,
283,
10271,
14,
5265,
14,
20670,
9490,
14,
20915,
5061,
14,
34,
293,
9490,
5061,
54,
18,
297,
272,
283,
10271,
14,
5265,
14,
472,
85,
1774,
5562,
14,
6374,
63,
10271,
63,
2718,
14,
14091,
14491,
5061,
54,
18,
297,
272,
283,
10271,
14,
5265,
14,
1490,
23201,
14,
22409,
63,
10271,
63,
2718,
14,
47,
7428,
20915,
5061,
54,
18,
297,
272,
283,
10271,
14,
5265,
14,
12165,
20936,
14,
20915,
5061,
14,
46,
11702,
5061,
54,
18,
297,
272,
283,
10271,
14,
5265,
14,
12165,
20936,
14,
20915,
3167,
5061,
14,
46,
11702,
23613,
5061,
297,
272,
283,
10271,
14,
5265,
14,
12453,
14,
12453,
63,
2718,
14,
6388,
2890,
76,
1632,
54,
18,
297,
272,
283,
10271,
14,
5265,
14,
18970,
14,
2718,
14,
2438,
88,
5061,
297,
272,
283,
10271,
14,
5265,
14,
18970,
14,
2718,
14,
2438,
88,
3167,
5061,
297,
272,
283,
10271,
14,
5265,
14,
368,
6435,
10925,
14,
2718,
14,
4395,
7619,
10925,
5061,
54,
18,
297,
272,
283,
10271,
14,
5265,
14,
757,
18,
14,
2718,
14,
45,
76,
18,
5061,
297,
272,
283,
10271,
14,
5265,
14,
4492,
458,
3111,
14,
2718,
14,
20915,
13726,
4936,
54,
18,
7,
199,
61,
199,
199,
504,
30960,
20596,
492,
1687,
199,
646,
8335,
465,
2937,
421,
199,
504,
8224,
14,
697,
492,
8367,
421,
199,
318,
10754,
8,
2682,
63,
5265,
29,
403,
12,
1511,
29,
403,
304,
272,
340,
440,
8367,
14,
5626,
63,
1065,
8,
2682,
63,
5265,
12,
8367,
63,
509,
63,
5265,
304,
267,
372,
339,
6754,
3718,
2599,
4046,
701,
6832,
20596,
446,
8749,
11311,
1,
6754,
272,
1687,
14,
981,
63,
1224,
8,
267,
283,
1200,
7821,
67,
387,
12069,
10880,
297,
267,
2937,
14,
4547,
360,
1200,
63,
344,
297,
2937,
14,
1558,
8,
1267,
29,
1344,
395,
7854,
29,
797,
395,
267,
2937,
14,
4547,
360,
10801,
63,
4054,
63,
344,
297,
2937,
14,
1558,
8,
1267,
29,
1344,
395,
7854,
29,
797,
395,
267,
2937,
14,
3190,
8463,
2941,
10801,
63,
4054,
63,
344,
995,
788,
14250,
14,
344,
995,
1816,
16549,
534,
10855,
659,
267,
2937,
14,
3190,
8463,
2941,
1200,
63,
344,
995,
788,
7642,
14,
344,
995,
1816,
16549,
534,
10855,
659,
267,
2937,
14,
29457,
8463,
360,
1200,
63,
344,
297,
283,
10801,
63,
4054,
63,
344,
358,
272,
776,
272,
1687,
14,
981,
63,
1224,
8,
267,
283,
4995,
76,
19,
4054,
10880,
297,
267,
2937,
14,
4547,
360,
344,
297,
2937,
14,
1558,
8,
1267,
29,
1344,
395,
7854,
29,
797,
395,
267,
2937,
14,
4547,
360,
4995,
63,
344,
297,
2937,
14,
1558,
8,
1267,
29,
1344,
395,
7854,
29,
549,
395,
267,
2937,
14,
4547,
360,
76,
19,
63,
4054,
63,
344,
297,
2937,
14,
1558,
8,
1267,
29,
1344,
395,
7854,
29,
549,
395,
267,
2937,
14,
3190,
8463,
2941,
76,
19,
63,
4054,
63,
344,
995,
788,
14250,
14,
344,
995,
1816,
16549,
534,
10855,
659,
267,
2937,
14,
3190,
8463,
2941,
4995,
63,
344,
995,
788,
17292,
14,
344,
995,
1816,
16549,
534,
10855,
659,
267,
2937,
14,
29457,
8463,
360,
344,
358,
272,
776,
272,
6754,
1284,
6832,
20596,
3718,
6754,
421,
199,
318,
32498,
8,
2682,
63,
5265,
29,
403,
12,
1511,
29,
403,
304,
272,
340,
440,
8367,
14,
5626,
63,
1065,
8,
2682,
63,
5265,
12,
8367,
63,
509,
63,
5265,
304,
267,
372,
339,
6754,
3718,
2599,
4046,
701,
6832,
20596,
446,
8749,
11311,
1,
6754,
272,
1687,
14,
4824,
63,
1224,
360,
4995,
76,
19,
4054,
10880,
358,
272,
1687,
14,
4824,
63,
1224,
360,
1200,
7821,
67,
387,
12069,
10880,
358,
272,
6754,
1284,
6832,
20596,
3718,
6754,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6171,
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,
3,
199,
199,
624,
4054,
11899,
199,
199,
12714,
2870,
26,
841,
27041,
68,
24888,
68,
29071,
199,
497,
433,
874,
26,
650,
66,
1477,
4361,
25,
69,
1398,
70,
23,
199,
2499,
6148,
26,
6171,
13,
996,
13,
2025,
6546,
26,
614,
26,
1400,
14,
13812,
11363,
199,
199,
624,
199,
199,
3,
6974,
14154,
12,
1202,
701,
6832,
20596,
14,
199,
5792,
275,
283,
16112,
18,
68,
24888,
68,
29071,
7,
199,
2110,
63,
5792,
275,
283,
19,
66,
1477,
4361,
25,
69,
1398,
70,
23,
7,
199,
199,
3,
7743,
370,
788,
10,
418,
340,
642,
8367,
12966,
370,
1006,
8963,
199,
199,
8998,
63,
509,
63,
5265,
275,
359,
272,
283,
10271,
14,
5265,
14,
20670,
9490,
14,
20915,
5061,
14,
34,
293,
9490,
5061,
54,
18,
297,
272,
283,
10271,
14,
5265,
14,
472,
85,
1774,
5562,
14,
6374,
63,
10271,
63,
2718,
14,
14091,
14491,
5061,
54,
18,
297,
272,
283,
10271,
14,
5265,
14,
1490,
23201,
14,
22409,
63,
10271,
63,
2718,
14,
47,
7428,
20915,
5061,
54,
18,
297,
272,
283,
10271,
14,
5265,
14,
12165,
20936,
14,
20915,
5061,
14,
46,
11702,
5061,
54,
18,
297,
272,
283,
10271,
14,
5265,
14,
12165,
20936,
14,
20915,
3167,
5061,
14,
46,
11702,
23613,
5061,
297,
272,
283,
10271,
14,
5265,
14,
12453,
14,
12453,
63,
2718,
14,
6388,
2890,
76,
1632,
54,
18,
297,
272,
283,
10271,
14,
5265,
14,
18970,
14,
2718,
14,
2438,
88,
5061,
297,
272,
283,
10271,
14,
5265,
14,
18970,
14,
2718,
14,
2438,
88,
3167,
5061,
297,
272,
283,
10271,
14,
5265,
14,
368,
6435,
10925,
14,
2718,
14,
4395,
7619,
10925,
5061,
54,
18,
297,
272,
283,
10271,
14,
5265,
14,
757,
18,
14,
2718,
14,
45,
76,
18,
5061,
297,
272,
283,
10271,
14,
5265,
14,
4492,
458,
3111,
14,
2718,
14,
20915,
13726,
4936,
54,
18,
7,
199,
61,
199,
199,
504,
30960,
20596,
492,
1687,
199,
646,
8335,
465,
2937,
421,
199,
504,
8224,
14,
697,
492,
8367,
421,
199,
318,
10754,
8,
2682,
63,
5265,
29,
403,
12,
1511,
29,
403,
304,
272,
340,
440,
8367,
14,
5626,
63,
1065,
8,
2682,
63,
5265,
12,
8367,
63,
509,
63,
5265,
304,
267,
372,
339,
6754,
3718,
2599,
4046,
701,
6832,
20596,
446,
8749,
11311,
1,
6754,
272,
1687,
14,
981,
63,
1224,
8,
267,
283,
1200,
7821,
67,
387,
12069,
10880,
297,
267,
2937,
14,
4547,
360,
1200,
63,
344,
297,
2937,
14,
1558,
8,
1267,
29,
1344,
395,
7854,
29,
797,
395,
267,
2937,
14,
4547,
360,
10801,
63,
4054,
63,
344,
297,
2937,
14,
1558,
8,
1267,
29,
1344,
395,
7854,
29,
797,
395,
267,
2937,
14,
3190,
8463,
2941,
10801,
63,
4054,
63,
344,
995,
788,
14250,
14,
344,
995,
1816,
16549,
534,
10855,
659,
267,
2937,
14,
3190,
8463,
2941,
1200,
63,
344,
995,
788,
7642,
14,
344,
995,
1816,
16549,
534,
10855,
659,
267,
2937,
14,
29457,
8463,
360,
1200,
63,
344,
297,
283,
10801,
63,
4054,
63,
344,
358,
272,
776,
272,
1687,
14,
981,
63,
1224,
8,
267,
283,
4995,
76,
19,
4054,
10880,
297,
267,
2937,
14,
4547,
360,
344,
297,
2937,
14,
1558,
8,
1267,
29,
1344,
395,
7854,
29,
797,
395,
267,
2937,
14,
4547,
360,
4995,
63,
344,
297,
2937,
14,
1558,
8,
1267,
29,
1344,
395,
7854,
29,
549,
395,
267,
2937,
14,
4547,
360,
76,
19,
63,
4054,
63,
344,
297,
2937,
14,
1558,
8,
1267,
29,
1344,
395,
7854,
29,
549,
395,
267,
2937,
14,
3190,
8463,
2941,
76,
19,
63,
4054,
63,
344,
995,
788,
14250,
14,
344,
995,
1816,
16549,
534,
10855,
659,
267,
2937,
14,
3190,
8463,
2941,
4995,
63,
344,
995,
788,
17292,
14,
344,
995,
1816,
16549,
534,
10855,
659,
267,
2937,
14,
29457,
8463,
360,
344,
358,
272,
776,
272,
6754,
1284,
6832,
20596,
3718,
6754,
421,
199,
318,
32498,
8,
2682,
63,
5265,
29,
403,
12,
1511,
29,
403,
304,
272,
340,
440,
8367,
14,
5626,
63,
1065,
8,
2682,
63,
5265,
12,
8367,
63,
509,
63,
5265,
304,
267,
372,
339,
6754,
3718,
2599,
4046,
701,
6832,
20596,
446,
8749,
11311,
1,
6754,
272,
1687,
14,
4824,
63,
1224,
360,
4995,
76,
19,
4054,
10880,
358,
272,
1687,
14,
4824,
63,
1224,
360,
1200,
7821,
67,
387,
12069,
10880,
358,
272,
6754,
1284,
6832,
20596,
3718,
6754,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
yb-kim/gemV
|
src/arch/x86/isa/insts/x87/arithmetic/square_root.py
|
91
|
2150
|
# Copyright (c) 2007 The Hewlett-Packard Development Company
# All rights reserved.
#
# The license below extends only to copyright in the software and shall
# not be construed as granting a license to any other intellectual
# property including but not limited to intellectual property relating
# to a hardware implementation of the functionality of the software
# licensed hereunder. You may use the software subject to the license
# terms below provided that you ensure that this notice is replicated
# unmodified and in its entirety in all distributions of the software,
# modified or unmodified, in source code or in binary form.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors: Gabe Black
microcode = '''
# FSQRT
'''
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
10219,
710,
27849,
13,
29471,
15290,
15878,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
710,
4190,
5084,
16879,
1454,
370,
4248,
315,
314,
2032,
436,
10989,
199,
3,
440,
506,
950,
431,
68,
465,
16085,
316,
282,
4190,
370,
1263,
1163,
27925,
1264,
1061,
199,
3,
3324,
5893,
1325,
440,
13988,
370,
27925,
1264,
1061,
3324,
4668,
1958,
199,
3,
370,
282,
14991,
4514,
402,
314,
9330,
402,
314,
2032,
199,
3,
18233,
2348,
7138,
14,
221,
2047,
1443,
675,
314,
2032,
5420,
370,
314,
4190,
199,
3,
2895,
5084,
2741,
626,
1265,
4868,
626,
642,
4245,
365,
32436,
199,
3,
24214,
436,
315,
2399,
8039,
369,
315,
1006,
10208,
402,
314,
2032,
12,
199,
3,
6042,
503,
24214,
12,
315,
1350,
1233,
503,
315,
3366,
1824,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
598,
7570,
30593,
199,
199,
6453,
600,
275,
1449,
199,
3,
481,
18445,
11876,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
10219,
710,
27849,
13,
29471,
15290,
15878,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
710,
4190,
5084,
16879,
1454,
370,
4248,
315,
314,
2032,
436,
10989,
199,
3,
440,
506,
950,
431,
68,
465,
16085,
316,
282,
4190,
370,
1263,
1163,
27925,
1264,
1061,
199,
3,
3324,
5893,
1325,
440,
13988,
370,
27925,
1264,
1061,
3324,
4668,
1958,
199,
3,
370,
282,
14991,
4514,
402,
314,
9330,
402,
314,
2032,
199,
3,
18233,
2348,
7138,
14,
221,
2047,
1443,
675,
314,
2032,
5420,
370,
314,
4190,
199,
3,
2895,
5084,
2741,
626,
1265,
4868,
626,
642,
4245,
365,
32436,
199,
3,
24214,
436,
315,
2399,
8039,
369,
315,
1006,
10208,
402,
314,
2032,
12,
199,
3,
6042,
503,
24214,
12,
315,
1350,
1233,
503,
315,
3366,
1824,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
598,
7570,
30593,
199,
199,
6453,
600,
275,
1449,
199,
3,
481,
18445,
11876,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
karibou/sosreport
|
tests/policy_tests.py
|
15
|
1831
|
import unittest
from sos.policies import Policy, PackageManager, import_policy
from sos.plugins import Plugin, IndependentPlugin, RedHatPlugin, DebianPlugin
class FauxPolicy(Policy):
distro = "Faux"
class FauxPlugin(Plugin, IndependentPlugin):
pass
class FauxRedHatPlugin(Plugin, RedHatPlugin):
pass
class FauxDebianPlugin(Plugin, DebianPlugin):
pass
class PolicyTests(unittest.TestCase):
def test_independent_only(self):
p = FauxPolicy()
p.valid_subclasses = []
self.assertTrue(p.validate_plugin(FauxPlugin))
def test_redhat(self):
p = FauxPolicy()
p.valid_subclasses = [RedHatPlugin]
self.assertTrue(p.validate_plugin(FauxRedHatPlugin))
def test_debian(self):
p = FauxPolicy()
p.valid_subclasses = [DebianPlugin]
self.assertTrue(p.validate_plugin(FauxDebianPlugin))
def test_fails(self):
p = FauxPolicy()
p.valid_subclasses = []
self.assertFalse(p.validate_plugin(FauxDebianPlugin))
def test_can_import(self):
self.assertTrue(import_policy('redhat') is not None)
def test_cant_import(self):
self.assertTrue(import_policy('notreal') is None)
class PackageManagerTests(unittest.TestCase):
def setUp(self):
self.pm = PackageManager()
def test_default_all_pkgs(self):
self.assertEquals(self.pm.all_pkgs(), {})
def test_default_all_pkgs_by_name(self):
self.assertEquals(self.pm.all_pkgs_by_name('doesntmatter'), [])
def test_default_all_pkgs_by_name_regex(self):
self.assertEquals(self.pm.all_pkgs_by_name_regex('.*doesntmatter$'), [])
def test_default_pkg_by_name(self):
self.assertEquals(self.pm.pkg_by_name('foo'), None)
if __name__ == "__main__":
unittest.main()
# vim: set et ts=4 sw=4 :
|
gpl-2.0
|
[
646,
2882,
199,
199,
504,
308,
736,
14,
11767,
492,
18141,
12,
15665,
2988,
12,
492,
63,
3185,
199,
504,
308,
736,
14,
5265,
492,
11349,
12,
1010,
7106,
5061,
12,
9572,
40,
292,
5061,
12,
30445,
5061,
199,
199,
533,
10859,
2521,
4845,
8,
4845,
304,
272,
20499,
275,
298,
1906,
2521,
2,
199,
199,
533,
10859,
2521,
5061,
8,
5061,
12,
1010,
7106,
5061,
304,
272,
986,
199,
199,
533,
10859,
2521,
10858,
40,
292,
5061,
8,
5061,
12,
9572,
40,
292,
5061,
304,
272,
986,
199,
199,
533,
10859,
2521,
872,
9662,
5061,
8,
5061,
12,
30445,
5061,
304,
272,
986,
199,
199,
533,
18141,
2925,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
26083,
63,
2118,
8,
277,
304,
267,
299,
275,
10859,
2521,
4845,
342,
267,
299,
14,
1078,
63,
19094,
275,
942,
398,
291,
14,
1815,
8,
80,
14,
3502,
63,
2718,
8,
1906,
2521,
5061,
430,
339,
347,
511,
63,
17164,
8,
277,
304,
267,
299,
275,
10859,
2521,
4845,
342,
267,
299,
14,
1078,
63,
19094,
275,
359,
10858,
40,
292,
5061,
61,
398,
291,
14,
1815,
8,
80,
14,
3502,
63,
2718,
8,
1906,
2521,
10858,
40,
292,
5061,
430,
339,
347,
511,
63,
23204,
8,
277,
304,
267,
299,
275,
10859,
2521,
4845,
342,
267,
299,
14,
1078,
63,
19094,
275,
359,
872,
9662,
5061,
61,
398,
291,
14,
1815,
8,
80,
14,
3502,
63,
2718,
8,
1906,
2521,
872,
9662,
5061,
430,
339,
347,
511,
63,
15762,
8,
277,
304,
267,
299,
275,
10859,
2521,
4845,
342,
267,
299,
14,
1078,
63,
19094,
275,
942,
398,
291,
14,
3334,
8,
80,
14,
3502,
63,
2718,
8,
1906,
2521,
872,
9662,
5061,
430,
339,
347,
511,
63,
2425,
63,
646,
8,
277,
304,
267,
291,
14,
1815,
8,
646,
63,
3185,
360,
17164,
358,
365,
440,
488,
9,
339,
347,
511,
63,
67,
867,
63,
646,
8,
277,
304,
267,
291,
14,
1815,
8,
646,
63,
3185,
360,
1397,
3093,
358,
365,
488,
9,
421,
199,
533,
15665,
2988,
2925,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
7073,
275,
15665,
2988,
342,
339,
347,
511,
63,
885,
63,
452,
63,
16624,
8,
277,
304,
267,
291,
14,
2947,
8,
277,
14,
7073,
14,
452,
63,
16624,
1062,
5009,
339,
347,
511,
63,
885,
63,
452,
63,
16624,
63,
991,
63,
354,
8,
277,
304,
267,
291,
14,
2947,
8,
277,
14,
7073,
14,
452,
63,
16624,
63,
991,
63,
354,
360,
26664,
569,
351,
659,
3073,
339,
347,
511,
63,
885,
63,
452,
63,
16624,
63,
991,
63,
354,
63,
3821,
8,
277,
304,
267,
291,
14,
2947,
8,
277,
14,
7073,
14,
452,
63,
16624,
63,
991,
63,
354,
63,
3821,
360,
2795,
26664,
569,
351,
26712,
3073,
339,
347,
511,
63,
885,
63,
4600,
63,
991,
63,
354,
8,
277,
304,
267,
291,
14,
2947,
8,
277,
14,
7073,
14,
4600,
63,
991,
63,
354,
360,
1421,
659,
488,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
199,
3,
6695,
26,
663,
10844,
6714,
29,
20,
5584,
29,
20,
520,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
308,
736,
14,
11767,
492,
18141,
12,
15665,
2988,
12,
492,
63,
3185,
199,
504,
308,
736,
14,
5265,
492,
11349,
12,
1010,
7106,
5061,
12,
9572,
40,
292,
5061,
12,
30445,
5061,
199,
199,
533,
10859,
2521,
4845,
8,
4845,
304,
272,
20499,
275,
298,
1906,
2521,
2,
199,
199,
533,
10859,
2521,
5061,
8,
5061,
12,
1010,
7106,
5061,
304,
272,
986,
199,
199,
533,
10859,
2521,
10858,
40,
292,
5061,
8,
5061,
12,
9572,
40,
292,
5061,
304,
272,
986,
199,
199,
533,
10859,
2521,
872,
9662,
5061,
8,
5061,
12,
30445,
5061,
304,
272,
986,
199,
199,
533,
18141,
2925,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
26083,
63,
2118,
8,
277,
304,
267,
299,
275,
10859,
2521,
4845,
342,
267,
299,
14,
1078,
63,
19094,
275,
942,
398,
291,
14,
1815,
8,
80,
14,
3502,
63,
2718,
8,
1906,
2521,
5061,
430,
339,
347,
511,
63,
17164,
8,
277,
304,
267,
299,
275,
10859,
2521,
4845,
342,
267,
299,
14,
1078,
63,
19094,
275,
359,
10858,
40,
292,
5061,
61,
398,
291,
14,
1815,
8,
80,
14,
3502,
63,
2718,
8,
1906,
2521,
10858,
40,
292,
5061,
430,
339,
347,
511,
63,
23204,
8,
277,
304,
267,
299,
275,
10859,
2521,
4845,
342,
267,
299,
14,
1078,
63,
19094,
275,
359,
872,
9662,
5061,
61,
398,
291,
14,
1815,
8,
80,
14,
3502,
63,
2718,
8,
1906,
2521,
872,
9662,
5061,
430,
339,
347,
511,
63,
15762,
8,
277,
304,
267,
299,
275,
10859,
2521,
4845,
342,
267,
299,
14,
1078,
63,
19094,
275,
942,
398,
291,
14,
3334,
8,
80,
14,
3502,
63,
2718,
8,
1906,
2521,
872,
9662,
5061,
430,
339,
347,
511,
63,
2425,
63,
646,
8,
277,
304,
267,
291,
14,
1815,
8,
646,
63,
3185,
360,
17164,
358,
365,
440,
488,
9,
339,
347,
511,
63,
67,
867,
63,
646,
8,
277,
304,
267,
291,
14,
1815,
8,
646,
63,
3185,
360,
1397,
3093,
358,
365,
488,
9,
421,
199,
533,
15665,
2988,
2925,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
7073,
275,
15665,
2988,
342,
339,
347,
511,
63,
885,
63,
452,
63,
16624,
8,
277,
304,
267,
291,
14,
2947,
8,
277,
14,
7073,
14,
452,
63,
16624,
1062,
5009,
339,
347,
511,
63,
885,
63,
452,
63,
16624,
63,
991,
63,
354,
8,
277,
304,
267,
291,
14,
2947,
8,
277,
14,
7073,
14,
452,
63,
16624,
63,
991,
63,
354,
360,
26664,
569,
351,
659,
3073,
339,
347,
511,
63,
885,
63,
452,
63,
16624,
63,
991,
63,
354,
63,
3821,
8,
277,
304,
267,
291,
14,
2947,
8,
277,
14,
7073,
14,
452,
63,
16624,
63,
991,
63,
354,
63,
3821,
360,
2795,
26664,
569,
351,
26712,
3073,
339,
347,
511,
63,
885,
63,
4600,
63,
991,
63,
354,
8,
277,
304,
267,
291,
14,
2947,
8,
277,
14,
7073,
14,
4600,
63,
991,
63,
354,
360,
1421,
659,
488,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
199,
3,
6695,
26,
663,
10844,
6714,
29,
20,
5584,
29,
20,
520,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Leoniela/nipype
|
nipype/interfaces/spm/tests/test_auto_CreateWarped.py
|
12
|
1298
|
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from nipype.testing import assert_equal
from nipype.interfaces.spm.preprocess import CreateWarped
def test_CreateWarped_inputs():
input_map = dict(flowfield_files=dict(copyfile=False,
field='crt_warped.flowfields',
mandatory=True,
),
ignore_exception=dict(nohash=True,
usedefault=True,
),
image_files=dict(copyfile=False,
field='crt_warped.images',
mandatory=True,
),
interp=dict(field='crt_warped.interp',
),
iterations=dict(field='crt_warped.K',
),
matlab_cmd=dict(),
mfile=dict(usedefault=True,
),
modulate=dict(field='crt_warped.jactransf',
),
paths=dict(),
use_mcr=dict(),
use_v8struct=dict(min_ver='8',
usedefault=True,
),
)
inputs = CreateWarped.input_spec()
for key, metadata in input_map.items():
for metakey, value in metadata.items():
yield assert_equal, getattr(inputs.traits()[key], metakey), value
def test_CreateWarped_outputs():
output_map = dict(warped_files=dict(),
)
outputs = CreateWarped.output_spec()
for key, metadata in output_map.items():
for metakey, value in metadata.items():
yield assert_equal, getattr(outputs.traits()[key], metakey), value
|
bsd-3-clause
|
[
3,
25420,
13,
12795,
6989,
701,
7249,
15,
1074,
7273,
14,
647,
446,
3506,
2845,
24981,
199,
504,
302,
711,
514,
14,
4776,
492,
702,
63,
1452,
199,
504,
302,
711,
514,
14,
7436,
14,
681,
77,
14,
17677,
492,
2790,
55,
285,
1915,
199,
199,
318,
511,
63,
2499,
55,
285,
1915,
63,
3711,
837,
272,
1324,
63,
1130,
275,
1211,
8,
1659,
698,
63,
1725,
29,
807,
8,
21997,
29,
797,
12,
272,
901,
534,
16617,
63,
3281,
1915,
14,
1659,
955,
297,
272,
15230,
29,
549,
12,
272,
2318,
272,
3686,
63,
1971,
29,
807,
8,
889,
2227,
29,
549,
12,
272,
675,
885,
29,
549,
12,
272,
2318,
272,
1834,
63,
1725,
29,
807,
8,
21997,
29,
797,
12,
272,
901,
534,
16617,
63,
3281,
1915,
14,
4782,
297,
272,
15230,
29,
549,
12,
272,
2318,
272,
23716,
29,
807,
8,
698,
534,
16617,
63,
3281,
1915,
14,
14252,
297,
272,
2318,
272,
10615,
29,
807,
8,
698,
534,
16617,
63,
3281,
1915,
14,
43,
297,
272,
2318,
272,
2530,
5561,
63,
1760,
29,
807,
1062,
272,
333,
493,
29,
807,
8,
1180,
885,
29,
549,
12,
272,
2318,
272,
3413,
5434,
29,
807,
8,
698,
534,
16617,
63,
3281,
1915,
14,
74,
2442,
1320,
70,
297,
272,
2318,
272,
3792,
29,
807,
1062,
272,
675,
63,
77,
1556,
29,
807,
1062,
272,
675,
63,
86,
24,
1820,
29,
807,
8,
827,
63,
422,
534,
24,
297,
272,
675,
885,
29,
549,
12,
272,
2318,
272,
776,
272,
4153,
275,
2790,
55,
285,
1915,
14,
1210,
63,
1650,
342,
339,
367,
790,
12,
3341,
315,
1324,
63,
1130,
14,
1744,
837,
267,
367,
3404,
498,
12,
574,
315,
3341,
14,
1744,
837,
288,
1995,
702,
63,
1452,
12,
2519,
8,
3711,
14,
17668,
3430,
498,
467,
3404,
498,
395,
574,
199,
199,
318,
511,
63,
2499,
55,
285,
1915,
63,
4467,
837,
272,
1072,
63,
1130,
275,
1211,
8,
3281,
1915,
63,
1725,
29,
807,
1062,
272,
776,
272,
4704,
275,
2790,
55,
285,
1915,
14,
1199,
63,
1650,
342,
339,
367,
790,
12,
3341,
315,
1072,
63,
1130,
14,
1744,
837,
267,
367,
3404,
498,
12,
574,
315,
3341,
14,
1744,
837,
288,
1995,
702,
63,
1452,
12,
2519,
8,
4467,
14,
17668,
3430,
498,
467,
3404,
498,
395,
574,
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
] |
[
25420,
13,
12795,
6989,
701,
7249,
15,
1074,
7273,
14,
647,
446,
3506,
2845,
24981,
199,
504,
302,
711,
514,
14,
4776,
492,
702,
63,
1452,
199,
504,
302,
711,
514,
14,
7436,
14,
681,
77,
14,
17677,
492,
2790,
55,
285,
1915,
199,
199,
318,
511,
63,
2499,
55,
285,
1915,
63,
3711,
837,
272,
1324,
63,
1130,
275,
1211,
8,
1659,
698,
63,
1725,
29,
807,
8,
21997,
29,
797,
12,
272,
901,
534,
16617,
63,
3281,
1915,
14,
1659,
955,
297,
272,
15230,
29,
549,
12,
272,
2318,
272,
3686,
63,
1971,
29,
807,
8,
889,
2227,
29,
549,
12,
272,
675,
885,
29,
549,
12,
272,
2318,
272,
1834,
63,
1725,
29,
807,
8,
21997,
29,
797,
12,
272,
901,
534,
16617,
63,
3281,
1915,
14,
4782,
297,
272,
15230,
29,
549,
12,
272,
2318,
272,
23716,
29,
807,
8,
698,
534,
16617,
63,
3281,
1915,
14,
14252,
297,
272,
2318,
272,
10615,
29,
807,
8,
698,
534,
16617,
63,
3281,
1915,
14,
43,
297,
272,
2318,
272,
2530,
5561,
63,
1760,
29,
807,
1062,
272,
333,
493,
29,
807,
8,
1180,
885,
29,
549,
12,
272,
2318,
272,
3413,
5434,
29,
807,
8,
698,
534,
16617,
63,
3281,
1915,
14,
74,
2442,
1320,
70,
297,
272,
2318,
272,
3792,
29,
807,
1062,
272,
675,
63,
77,
1556,
29,
807,
1062,
272,
675,
63,
86,
24,
1820,
29,
807,
8,
827,
63,
422,
534,
24,
297,
272,
675,
885,
29,
549,
12,
272,
2318,
272,
776,
272,
4153,
275,
2790,
55,
285,
1915,
14,
1210,
63,
1650,
342,
339,
367,
790,
12,
3341,
315,
1324,
63,
1130,
14,
1744,
837,
267,
367,
3404,
498,
12,
574,
315,
3341,
14,
1744,
837,
288,
1995,
702,
63,
1452,
12,
2519,
8,
3711,
14,
17668,
3430,
498,
467,
3404,
498,
395,
574,
199,
199,
318,
511,
63,
2499,
55,
285,
1915,
63,
4467,
837,
272,
1072,
63,
1130,
275,
1211,
8,
3281,
1915,
63,
1725,
29,
807,
1062,
272,
776,
272,
4704,
275,
2790,
55,
285,
1915,
14,
1199,
63,
1650,
342,
339,
367,
790,
12,
3341,
315,
1072,
63,
1130,
14,
1744,
837,
267,
367,
3404,
498,
12,
574,
315,
3341,
14,
1744,
837,
288,
1995,
702,
63,
1452,
12,
2519,
8,
4467,
14,
17668,
3430,
498,
467,
3404,
498,
395,
574,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
HiroIshikawa/21playground
|
microblog/flask/lib/python3.5/site-packages/sqlalchemy/util/queue.py
|
81
|
6548
|
# util/queue.py
# Copyright (C) 2005-2015 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""An adaptation of Py2.3/2.4's Queue module which supports reentrant
behavior, using RLock instead of Lock for its mutex object. The
Queue object is used exclusively by the sqlalchemy.pool.QueuePool
class.
This is to support the connection pool's usage of weakref callbacks to return
connections to the underlying Queue, which can in extremely
rare cases be invoked within the ``get()`` method of the Queue itself,
producing a ``put()`` inside the ``get()`` and therefore a reentrant
condition.
"""
from collections import deque
from time import time as _time
from .compat import threading
__all__ = ['Empty', 'Full', 'Queue']
class Empty(Exception):
"Exception raised by Queue.get(block=0)/get_nowait()."
pass
class Full(Exception):
"Exception raised by Queue.put(block=0)/put_nowait()."
pass
class Queue:
def __init__(self, maxsize=0):
"""Initialize a queue object with a given maximum size.
If `maxsize` is <= 0, the queue size is infinite.
"""
self._init(maxsize)
# mutex must be held whenever the queue is mutating. All methods
# that acquire mutex must release it before returning. mutex
# is shared between the two conditions, so acquiring and
# releasing the conditions also acquires and releases mutex.
self.mutex = threading.RLock()
# Notify not_empty whenever an item is added to the queue; a
# thread waiting to get is notified then.
self.not_empty = threading.Condition(self.mutex)
# Notify not_full whenever an item is removed from the queue;
# a thread waiting to put is notified then.
self.not_full = threading.Condition(self.mutex)
def qsize(self):
"""Return the approximate size of the queue (not reliable!)."""
self.mutex.acquire()
n = self._qsize()
self.mutex.release()
return n
def empty(self):
"""Return True if the queue is empty, False otherwise (not
reliable!)."""
self.mutex.acquire()
n = self._empty()
self.mutex.release()
return n
def full(self):
"""Return True if the queue is full, False otherwise (not
reliable!)."""
self.mutex.acquire()
n = self._full()
self.mutex.release()
return n
def put(self, item, block=True, timeout=None):
"""Put an item into the queue.
If optional args `block` is True and `timeout` is None (the
default), block if necessary until a free slot is
available. If `timeout` is a positive number, it blocks at
most `timeout` seconds and raises the ``Full`` exception if no
free slot was available within that time. Otherwise (`block`
is false), put an item on the queue if a free slot is
immediately available, else raise the ``Full`` exception
(`timeout` is ignored in that case).
"""
self.not_full.acquire()
try:
if not block:
if self._full():
raise Full
elif timeout is None:
while self._full():
self.not_full.wait()
else:
if timeout < 0:
raise ValueError("'timeout' must be a positive number")
endtime = _time() + timeout
while self._full():
remaining = endtime - _time()
if remaining <= 0.0:
raise Full
self.not_full.wait(remaining)
self._put(item)
self.not_empty.notify()
finally:
self.not_full.release()
def put_nowait(self, item):
"""Put an item into the queue without blocking.
Only enqueue the item if a free slot is immediately available.
Otherwise raise the ``Full`` exception.
"""
return self.put(item, False)
def get(self, block=True, timeout=None):
"""Remove and return an item from the queue.
If optional args `block` is True and `timeout` is None (the
default), block if necessary until an item is available. If
`timeout` is a positive number, it blocks at most `timeout`
seconds and raises the ``Empty`` exception if no item was
available within that time. Otherwise (`block` is false),
return an item if one is immediately available, else raise the
``Empty`` exception (`timeout` is ignored in that case).
"""
self.not_empty.acquire()
try:
if not block:
if self._empty():
raise Empty
elif timeout is None:
while self._empty():
self.not_empty.wait()
else:
if timeout < 0:
raise ValueError("'timeout' must be a positive number")
endtime = _time() + timeout
while self._empty():
remaining = endtime - _time()
if remaining <= 0.0:
raise Empty
self.not_empty.wait(remaining)
item = self._get()
self.not_full.notify()
return item
finally:
self.not_empty.release()
def get_nowait(self):
"""Remove and return an item from the queue without blocking.
Only get an item if one is immediately available. Otherwise
raise the ``Empty`` exception.
"""
return self.get(False)
# Override these methods to implement other queue organizations
# (e.g. stack or priority queue).
# These will only be called with appropriate locks held
# Initialize the queue representation
def _init(self, maxsize):
self.maxsize = maxsize
self.queue = deque()
def _qsize(self):
return len(self.queue)
# Check whether the queue is empty
def _empty(self):
return not self.queue
# Check whether the queue is full
def _full(self):
return self.maxsize > 0 and len(self.queue) == self.maxsize
# Put a new item in the queue
def _put(self, item):
self.queue.append(item)
# Get an item from the queue
def _get(self):
return self.queue.popleft()
|
mit
|
[
3,
4884,
15,
1825,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
7806,
314,
14303,
11462,
436,
8417,
199,
3,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
2493,
19520,
425,
402,
1611,
18,
14,
19,
15,
18,
14,
20,
1159,
10703,
859,
1314,
5171,
295,
18626,
867,
199,
17537,
12,
1808,
820,
6432,
3140,
402,
15536,
367,
2399,
333,
18173,
909,
14,
221,
710,
199,
3737,
909,
365,
1202,
444,
1016,
9840,
701,
314,
8335,
14,
2293,
14,
3737,
5453,
199,
533,
14,
199,
199,
2765,
365,
370,
2291,
314,
1950,
4203,
1159,
4503,
402,
13852,
13484,
370,
372,
199,
7995,
370,
314,
8793,
10703,
12,
1314,
883,
315,
30503,
590,
199,
345,
264,
5560,
506,
10302,
4453,
314,
1124,
362,
8497,
1083,
402,
314,
10703,
6337,
12,
199,
496,
14713,
282,
1124,
524,
8497,
6272,
314,
1124,
362,
8497,
436,
16119,
282,
295,
18626,
867,
199,
5394,
14,
199,
199,
624,
199,
199,
504,
5055,
492,
15782,
199,
504,
900,
492,
900,
465,
485,
521,
199,
504,
1275,
5819,
492,
5796,
421,
199,
363,
452,
363,
275,
788,
4699,
297,
283,
9042,
297,
283,
3737,
418,
421,
199,
533,
9630,
8,
1726,
304,
272,
298,
1726,
4915,
701,
10703,
14,
362,
8,
1457,
29,
16,
2447,
362,
63,
20870,
1252,
2,
339,
986,
421,
199,
533,
16579,
8,
1726,
304,
272,
298,
1726,
4915,
701,
10703,
14,
524,
8,
1457,
29,
16,
2447,
524,
63,
20870,
1252,
2,
339,
986,
421,
199,
533,
10703,
26,
272,
347,
636,
826,
721,
277,
12,
19791,
29,
16,
304,
267,
408,
9345,
282,
4126,
909,
543,
282,
1627,
5696,
1568,
14,
398,
982,
658,
13634,
64,
365,
2695,
378,
12,
314,
4126,
1568,
365,
15258,
14,
267,
408,
398,
291,
423,
826,
8,
13634,
9,
267,
327,
333,
18173,
1471,
506,
23608,
18119,
314,
4126,
365,
8567,
1958,
14,
221,
2900,
3102,
267,
327,
626,
16919,
333,
18173,
1471,
4683,
652,
2544,
8152,
14,
221,
333,
18173,
267,
327,
365,
5709,
3382,
314,
2877,
3704,
12,
880,
1066,
23729,
436,
267,
327,
295,
274,
11571,
314,
3704,
2597,
1066,
3340,
436,
19015,
333,
18173,
14,
267,
291,
14,
19078,
275,
5796,
14,
30550,
342,
267,
327,
31949,
440,
63,
1667,
18119,
376,
1242,
365,
3483,
370,
314,
4126,
27,
282,
267,
327,
2462,
10923,
370,
664,
365,
29535,
2066,
14,
267,
291,
14,
1397,
63,
1667,
275,
5796,
14,
9558,
8,
277,
14,
19078,
9,
267,
327,
31949,
440,
63,
2861,
18119,
376,
1242,
365,
4829,
687,
314,
4126,
27,
267,
327,
282,
2462,
10923,
370,
5324,
365,
29535,
2066,
14,
267,
291,
14,
1397,
63,
2861,
275,
5796,
14,
9558,
8,
277,
14,
19078,
9,
339,
347,
1894,
890,
8,
277,
304,
267,
408,
1767,
314,
19917,
1568,
402,
314,
4126,
334,
1397,
32150,
1,
10477,
398,
291,
14,
19078,
14,
8174,
342,
267,
302,
275,
291,
423,
81,
890,
342,
267,
291,
14,
19078,
14,
3221,
342,
267,
372,
302,
339,
347,
2701,
8,
277,
304,
267,
408,
1767,
715,
340,
314,
4126,
365,
2701,
12,
756,
4257,
334,
1397,
267,
32150,
1,
10477,
398,
291,
14,
19078,
14,
8174,
342,
267,
302,
275,
291,
423,
1667,
342,
267,
291,
14,
19078,
14,
3221,
342,
267,
372,
302,
339,
347,
2615,
8,
277,
304,
267,
408,
1767,
715,
340,
314,
4126,
365,
2615,
12,
756,
4257,
334,
1397,
267,
32150,
1,
10477,
398,
291,
14,
19078,
14,
8174,
342,
267,
302,
275,
291,
423,
2861,
342,
267,
291,
14,
19078,
14,
3221,
342,
267,
372,
302,
339,
347,
5324,
8,
277,
12,
1242,
12,
1853,
29,
549,
12,
2653,
29,
403,
304,
267,
408,
18989,
376,
1242,
1901,
314,
4126,
14,
398,
982,
2716,
1249,
658,
1457,
64,
365,
715,
436,
658,
2593,
64,
365,
488,
334,
1589,
267,
849,
395,
1853,
340,
5784,
5133,
282,
2867,
9348,
365,
267,
2808,
14,
982,
658,
2593,
64,
365,
282,
7317,
1329,
12,
652,
5664,
737,
267,
4750,
658,
2593,
64,
4696,
436,
6534,
314,
1124,
9042,
1040,
1919,
340,
949,
267,
2867,
9348,
1990,
2808,
4453,
626,
900,
14,
221,
6630,
13493,
1457,
64,
267,
365,
3055,
395,
5324,
376,
1242,
641,
314,
4126,
340,
282,
2867,
9348,
365,
267,
9939,
2808,
12,
587,
746,
314,
1124,
9042,
1040,
1919,
267,
13493,
2593,
64,
365,
5525,
315,
626,
1930,
680,
267,
408,
398,
291,
14,
1397,
63,
2861,
14,
8174,
342,
267,
862,
26,
288,
340,
440,
1853,
26,
355,
340,
291,
423,
2861,
837,
490,
746,
16579,
288,
916,
2653,
365,
488,
26,
355,
1830,
291,
423,
2861,
837,
490,
291,
14,
1397,
63,
2861,
14,
2573,
342,
288,
587,
26,
355,
340,
2653,
665,
378,
26,
490,
746,
1722,
15587,
2593,
7,
1471,
506,
282,
7317,
1329,
531,
355,
1284,
521,
275,
485,
521,
342,
435,
2653,
355,
1830,
291,
423,
2861,
837,
490,
7971,
275,
1284,
521,
446,
485,
521,
342,
490,
340,
7971,
2695,
378,
14,
16,
26,
717,
746,
16579,
490,
291,
14,
1397,
63,
2861,
14,
2573,
8,
11266,
9,
288,
291,
423,
524,
8,
1053,
9,
288,
291,
14,
1397,
63,
1667,
14,
6814,
342,
267,
3753,
26,
288,
291,
14,
1397,
63,
2861,
14,
3221,
342,
339,
347,
5324,
63,
20870,
8,
277,
12,
1242,
304,
267,
408,
18989,
376,
1242,
1901,
314,
4126,
1928,
14592,
14,
398,
5972,
14892,
314,
1242,
340,
282,
2867,
9348,
365,
9939,
2808,
14,
267,
6630,
746,
314,
1124,
9042,
1040,
1919,
14,
267,
408,
267,
372,
291,
14,
524,
8,
1053,
12,
756,
9,
339,
347,
664,
8,
277,
12,
1853,
29,
549,
12,
2653,
29,
403,
304,
267,
408,
5587,
436,
372,
376,
1242,
687,
314,
4126,
14,
398,
982,
2716,
1249,
658,
1457,
64,
365,
715,
436,
658,
2593,
64,
365,
488,
334,
1589,
267,
849,
395,
1853,
340,
5784,
5133,
376,
1242,
365,
2808,
14,
982,
267,
658,
2593,
64,
365,
282,
7317,
1329,
12,
652,
5664,
737,
4750
] |
[
4884,
15,
1825,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
7806,
314,
14303,
11462,
436,
8417,
199,
3,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
2493,
19520,
425,
402,
1611,
18,
14,
19,
15,
18,
14,
20,
1159,
10703,
859,
1314,
5171,
295,
18626,
867,
199,
17537,
12,
1808,
820,
6432,
3140,
402,
15536,
367,
2399,
333,
18173,
909,
14,
221,
710,
199,
3737,
909,
365,
1202,
444,
1016,
9840,
701,
314,
8335,
14,
2293,
14,
3737,
5453,
199,
533,
14,
199,
199,
2765,
365,
370,
2291,
314,
1950,
4203,
1159,
4503,
402,
13852,
13484,
370,
372,
199,
7995,
370,
314,
8793,
10703,
12,
1314,
883,
315,
30503,
590,
199,
345,
264,
5560,
506,
10302,
4453,
314,
1124,
362,
8497,
1083,
402,
314,
10703,
6337,
12,
199,
496,
14713,
282,
1124,
524,
8497,
6272,
314,
1124,
362,
8497,
436,
16119,
282,
295,
18626,
867,
199,
5394,
14,
199,
199,
624,
199,
199,
504,
5055,
492,
15782,
199,
504,
900,
492,
900,
465,
485,
521,
199,
504,
1275,
5819,
492,
5796,
421,
199,
363,
452,
363,
275,
788,
4699,
297,
283,
9042,
297,
283,
3737,
418,
421,
199,
533,
9630,
8,
1726,
304,
272,
298,
1726,
4915,
701,
10703,
14,
362,
8,
1457,
29,
16,
2447,
362,
63,
20870,
1252,
2,
339,
986,
421,
199,
533,
16579,
8,
1726,
304,
272,
298,
1726,
4915,
701,
10703,
14,
524,
8,
1457,
29,
16,
2447,
524,
63,
20870,
1252,
2,
339,
986,
421,
199,
533,
10703,
26,
272,
347,
636,
826,
721,
277,
12,
19791,
29,
16,
304,
267,
408,
9345,
282,
4126,
909,
543,
282,
1627,
5696,
1568,
14,
398,
982,
658,
13634,
64,
365,
2695,
378,
12,
314,
4126,
1568,
365,
15258,
14,
267,
408,
398,
291,
423,
826,
8,
13634,
9,
267,
327,
333,
18173,
1471,
506,
23608,
18119,
314,
4126,
365,
8567,
1958,
14,
221,
2900,
3102,
267,
327,
626,
16919,
333,
18173,
1471,
4683,
652,
2544,
8152,
14,
221,
333,
18173,
267,
327,
365,
5709,
3382,
314,
2877,
3704,
12,
880,
1066,
23729,
436,
267,
327,
295,
274,
11571,
314,
3704,
2597,
1066,
3340,
436,
19015,
333,
18173,
14,
267,
291,
14,
19078,
275,
5796,
14,
30550,
342,
267,
327,
31949,
440,
63,
1667,
18119,
376,
1242,
365,
3483,
370,
314,
4126,
27,
282,
267,
327,
2462,
10923,
370,
664,
365,
29535,
2066,
14,
267,
291,
14,
1397,
63,
1667,
275,
5796,
14,
9558,
8,
277,
14,
19078,
9,
267,
327,
31949,
440,
63,
2861,
18119,
376,
1242,
365,
4829,
687,
314,
4126,
27,
267,
327,
282,
2462,
10923,
370,
5324,
365,
29535,
2066,
14,
267,
291,
14,
1397,
63,
2861,
275,
5796,
14,
9558,
8,
277,
14,
19078,
9,
339,
347,
1894,
890,
8,
277,
304,
267,
408,
1767,
314,
19917,
1568,
402,
314,
4126,
334,
1397,
32150,
1,
10477,
398,
291,
14,
19078,
14,
8174,
342,
267,
302,
275,
291,
423,
81,
890,
342,
267,
291,
14,
19078,
14,
3221,
342,
267,
372,
302,
339,
347,
2701,
8,
277,
304,
267,
408,
1767,
715,
340,
314,
4126,
365,
2701,
12,
756,
4257,
334,
1397,
267,
32150,
1,
10477,
398,
291,
14,
19078,
14,
8174,
342,
267,
302,
275,
291,
423,
1667,
342,
267,
291,
14,
19078,
14,
3221,
342,
267,
372,
302,
339,
347,
2615,
8,
277,
304,
267,
408,
1767,
715,
340,
314,
4126,
365,
2615,
12,
756,
4257,
334,
1397,
267,
32150,
1,
10477,
398,
291,
14,
19078,
14,
8174,
342,
267,
302,
275,
291,
423,
2861,
342,
267,
291,
14,
19078,
14,
3221,
342,
267,
372,
302,
339,
347,
5324,
8,
277,
12,
1242,
12,
1853,
29,
549,
12,
2653,
29,
403,
304,
267,
408,
18989,
376,
1242,
1901,
314,
4126,
14,
398,
982,
2716,
1249,
658,
1457,
64,
365,
715,
436,
658,
2593,
64,
365,
488,
334,
1589,
267,
849,
395,
1853,
340,
5784,
5133,
282,
2867,
9348,
365,
267,
2808,
14,
982,
658,
2593,
64,
365,
282,
7317,
1329,
12,
652,
5664,
737,
267,
4750,
658,
2593,
64,
4696,
436,
6534,
314,
1124,
9042,
1040,
1919,
340,
949,
267,
2867,
9348,
1990,
2808,
4453,
626,
900,
14,
221,
6630,
13493,
1457,
64,
267,
365,
3055,
395,
5324,
376,
1242,
641,
314,
4126,
340,
282,
2867,
9348,
365,
267,
9939,
2808,
12,
587,
746,
314,
1124,
9042,
1040,
1919,
267,
13493,
2593,
64,
365,
5525,
315,
626,
1930,
680,
267,
408,
398,
291,
14,
1397,
63,
2861,
14,
8174,
342,
267,
862,
26,
288,
340,
440,
1853,
26,
355,
340,
291,
423,
2861,
837,
490,
746,
16579,
288,
916,
2653,
365,
488,
26,
355,
1830,
291,
423,
2861,
837,
490,
291,
14,
1397,
63,
2861,
14,
2573,
342,
288,
587,
26,
355,
340,
2653,
665,
378,
26,
490,
746,
1722,
15587,
2593,
7,
1471,
506,
282,
7317,
1329,
531,
355,
1284,
521,
275,
485,
521,
342,
435,
2653,
355,
1830,
291,
423,
2861,
837,
490,
7971,
275,
1284,
521,
446,
485,
521,
342,
490,
340,
7971,
2695,
378,
14,
16,
26,
717,
746,
16579,
490,
291,
14,
1397,
63,
2861,
14,
2573,
8,
11266,
9,
288,
291,
423,
524,
8,
1053,
9,
288,
291,
14,
1397,
63,
1667,
14,
6814,
342,
267,
3753,
26,
288,
291,
14,
1397,
63,
2861,
14,
3221,
342,
339,
347,
5324,
63,
20870,
8,
277,
12,
1242,
304,
267,
408,
18989,
376,
1242,
1901,
314,
4126,
1928,
14592,
14,
398,
5972,
14892,
314,
1242,
340,
282,
2867,
9348,
365,
9939,
2808,
14,
267,
6630,
746,
314,
1124,
9042,
1040,
1919,
14,
267,
408,
267,
372,
291,
14,
524,
8,
1053,
12,
756,
9,
339,
347,
664,
8,
277,
12,
1853,
29,
549,
12,
2653,
29,
403,
304,
267,
408,
5587,
436,
372,
376,
1242,
687,
314,
4126,
14,
398,
982,
2716,
1249,
658,
1457,
64,
365,
715,
436,
658,
2593,
64,
365,
488,
334,
1589,
267,
849,
395,
1853,
340,
5784,
5133,
376,
1242,
365,
2808,
14,
982,
267,
658,
2593,
64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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
jchodera/pymbar
|
pymbar/tests/test_utils.py
|
3
|
1027
|
import numpy as np
import pymbar
from pymbar.utils_for_testing import eq
import scipy.misc
from nose import SkipTest
def test_logsumexp():
a = np.random.normal(size=(200, 500, 5))
for axis in range(a.ndim):
ans_ne = pymbar.utils.logsumexp(a, axis=axis)
ans_no_ne = pymbar.utils.logsumexp(a, axis=axis, use_numexpr=False)
ans_scipy = scipy.misc.logsumexp(a, axis=axis)
eq(ans_ne, ans_no_ne)
eq(ans_ne, ans_scipy)
def test_logsumexp_b():
a = np.random.normal(size=(200, 500, 5))
b = np.random.normal(size=(200, 500, 5)) ** 2.
for axis in range(a.ndim):
ans_ne = pymbar.utils.logsumexp(a, b=b, axis=axis)
ans_no_ne = pymbar.utils.logsumexp(a, b=b, axis=axis, use_numexpr=False)
ans_scipy = scipy.misc.logsumexp(a, b=b, axis=axis)
eq(ans_ne, ans_no_ne)
eq(ans_ne, ans_scipy)
def test_logsum():
u = np.random.normal(size=(200))
y1 = pymbar.utils.logsumexp(u)
y2 = pymbar.utils._logsum(u)
eq(y1, y2, decimal=12)
|
lgpl-2.1
|
[
646,
2680,
465,
980,
199,
646,
1134,
887,
285,
199,
504,
1134,
887,
285,
14,
1208,
63,
509,
63,
4776,
492,
3850,
199,
646,
7026,
14,
9923,
199,
504,
11354,
492,
18795,
199,
199,
318,
511,
63,
7270,
940,
9290,
837,
272,
282,
275,
980,
14,
2355,
14,
3302,
8,
890,
2687,
1840,
12,
6891,
12,
959,
430,
339,
367,
3114,
315,
1425,
8,
65,
14,
8322,
304,
267,
4987,
63,
685,
275,
1134,
887,
285,
14,
1208,
14,
7270,
940,
9290,
8,
65,
12,
3114,
29,
3127,
9,
267,
4987,
63,
889,
63,
685,
275,
1134,
887,
285,
14,
1208,
14,
7270,
940,
9290,
8,
65,
12,
3114,
29,
3127,
12,
675,
63,
10563,
31149,
29,
797,
9,
267,
4987,
63,
14248,
275,
7026,
14,
9923,
14,
7270,
940,
9290,
8,
65,
12,
3114,
29,
3127,
9,
267,
3850,
8,
796,
63,
685,
12,
4987,
63,
889,
63,
685,
9,
267,
3850,
8,
796,
63,
685,
12,
4987,
63,
14248,
9,
199,
199,
318,
511,
63,
7270,
940,
9290,
63,
66,
837,
272,
282,
275,
980,
14,
2355,
14,
3302,
8,
890,
2687,
1840,
12,
6891,
12,
959,
430,
272,
330,
275,
980,
14,
2355,
14,
3302,
8,
890,
2687,
1840,
12,
6891,
12,
959,
430,
1011,
499,
14,
339,
367,
3114,
315,
1425,
8,
65,
14,
8322,
304,
267,
4987,
63,
685,
275,
1134,
887,
285,
14,
1208,
14,
7270,
940,
9290,
8,
65,
12,
330,
29,
66,
12,
3114,
29,
3127,
9,
267,
4987,
63,
889,
63,
685,
275,
1134,
887,
285,
14,
1208,
14,
7270,
940,
9290,
8,
65,
12,
330,
29,
66,
12,
3114,
29,
3127,
12,
675,
63,
10563,
31149,
29,
797,
9,
267,
4987,
63,
14248,
275,
7026,
14,
9923,
14,
7270,
940,
9290,
8,
65,
12,
330,
29,
66,
12,
3114,
29,
3127,
9,
267,
3850,
8,
796,
63,
685,
12,
4987,
63,
889,
63,
685,
9,
267,
3850,
8,
796,
63,
685,
12,
4987,
63,
14248,
9,
199,
199,
318,
511,
63,
7270,
453,
837,
272,
399,
275,
980,
14,
2355,
14,
3302,
8,
890,
2687,
1840,
430,
272,
612,
17,
275,
1134,
887,
285,
14,
1208,
14,
7270,
940,
9290,
8,
85,
9,
272,
612,
18,
275,
1134,
887,
285,
14,
1208,
423,
7270,
453,
8,
85,
9,
272,
3850,
8,
89,
17,
12,
612,
18,
12,
6107,
29,
713,
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
] |
[
2680,
465,
980,
199,
646,
1134,
887,
285,
199,
504,
1134,
887,
285,
14,
1208,
63,
509,
63,
4776,
492,
3850,
199,
646,
7026,
14,
9923,
199,
504,
11354,
492,
18795,
199,
199,
318,
511,
63,
7270,
940,
9290,
837,
272,
282,
275,
980,
14,
2355,
14,
3302,
8,
890,
2687,
1840,
12,
6891,
12,
959,
430,
339,
367,
3114,
315,
1425,
8,
65,
14,
8322,
304,
267,
4987,
63,
685,
275,
1134,
887,
285,
14,
1208,
14,
7270,
940,
9290,
8,
65,
12,
3114,
29,
3127,
9,
267,
4987,
63,
889,
63,
685,
275,
1134,
887,
285,
14,
1208,
14,
7270,
940,
9290,
8,
65,
12,
3114,
29,
3127,
12,
675,
63,
10563,
31149,
29,
797,
9,
267,
4987,
63,
14248,
275,
7026,
14,
9923,
14,
7270,
940,
9290,
8,
65,
12,
3114,
29,
3127,
9,
267,
3850,
8,
796,
63,
685,
12,
4987,
63,
889,
63,
685,
9,
267,
3850,
8,
796,
63,
685,
12,
4987,
63,
14248,
9,
199,
199,
318,
511,
63,
7270,
940,
9290,
63,
66,
837,
272,
282,
275,
980,
14,
2355,
14,
3302,
8,
890,
2687,
1840,
12,
6891,
12,
959,
430,
272,
330,
275,
980,
14,
2355,
14,
3302,
8,
890,
2687,
1840,
12,
6891,
12,
959,
430,
1011,
499,
14,
339,
367,
3114,
315,
1425,
8,
65,
14,
8322,
304,
267,
4987,
63,
685,
275,
1134,
887,
285,
14,
1208,
14,
7270,
940,
9290,
8,
65,
12,
330,
29,
66,
12,
3114,
29,
3127,
9,
267,
4987,
63,
889,
63,
685,
275,
1134,
887,
285,
14,
1208,
14,
7270,
940,
9290,
8,
65,
12,
330,
29,
66,
12,
3114,
29,
3127,
12,
675,
63,
10563,
31149,
29,
797,
9,
267,
4987,
63,
14248,
275,
7026,
14,
9923,
14,
7270,
940,
9290,
8,
65,
12,
330,
29,
66,
12,
3114,
29,
3127,
9,
267,
3850,
8,
796,
63,
685,
12,
4987,
63,
889,
63,
685,
9,
267,
3850,
8,
796,
63,
685,
12,
4987,
63,
14248,
9,
199,
199,
318,
511,
63,
7270,
453,
837,
272,
399,
275,
980,
14,
2355,
14,
3302,
8,
890,
2687,
1840,
430,
272,
612,
17,
275,
1134,
887,
285,
14,
1208,
14,
7270,
940,
9290,
8,
85,
9,
272,
612,
18,
275,
1134,
887,
285,
14,
1208,
423,
7270,
453,
8,
85,
9,
272,
3850,
8,
89,
17,
12,
612,
18,
12,
6107,
29,
713,
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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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
bschuon/django-oscar
|
tests/integration/offer/percentage_benefit_tests.py
|
40
|
8517
|
from decimal import Decimal as D
from django.test import TestCase
import mock
from oscar.apps.offer import models
from oscar.test import factories
from oscar.test.basket import add_product, add_products
class TestAPercentageDiscountAppliedWithCountCondition(TestCase):
def setUp(self):
range = models.Range.objects.create(
name="All products", includes_all_products=True)
self.condition = models.CountCondition(
range=range,
type=models.Condition.COUNT,
value=2)
self.benefit = models.PercentageDiscountBenefit(
range=range,
type=models.Benefit.PERCENTAGE,
value=20)
self.offer = mock.Mock()
self.basket = factories.create_basket(empty=True)
def test_applies_correctly_to_empty_basket(self):
result = self.benefit.apply(self.basket, self.condition, self.offer)
self.assertEqual(D('0.00'), result.discount)
self.assertEqual(0, self.basket.num_items_with_discount)
self.assertEqual(0, self.basket.num_items_without_discount)
def test_applies_correctly_to_basket_with_no_discountable_products(self):
product = factories.create_product(is_discountable=False)
add_product(self.basket, D('12.00'), 2, product=product)
result = self.benefit.apply(self.basket, self.condition, self.offer)
self.assertEqual(D('0.00'), result.discount)
self.assertEqual(0, self.basket.num_items_with_discount)
self.assertEqual(2, self.basket.num_items_without_discount)
def test_applies_correctly_to_basket_which_matches_condition(self):
add_product(self.basket, D('12.00'), 2)
result = self.benefit.apply(self.basket, self.condition, self.offer)
self.assertEqual(2 * D('12.00') * D('0.2'), result.discount)
self.assertEqual(2, self.basket.num_items_with_discount)
self.assertEqual(0, self.basket.num_items_without_discount)
def test_applies_correctly_to_basket_which_exceeds_condition(self):
add_product(self.basket, D('12.00'), 3)
result = self.benefit.apply(self.basket, self.condition, self.offer)
self.assertEqual(3 * D('12.00') * D('0.2'), result.discount)
self.assertEqual(3, self.basket.num_items_with_discount)
self.assertEqual(0, self.basket.num_items_without_discount)
class TestAPercentageDiscountWithMaxItemsSetAppliedWithCountCondition(TestCase):
def setUp(self):
range = models.Range.objects.create(
name="All products", includes_all_products=True)
self.condition = models.CountCondition(
range=range,
type=models.Condition.COUNT,
value=2)
self.benefit = models.PercentageDiscountBenefit(
range=range,
type=models.Benefit.PERCENTAGE,
value=20,
max_affected_items=1)
self.offer = mock.Mock()
self.basket = factories.create_basket(empty=True)
def test_applies_correctly_to_empty_basket(self):
result = self.benefit.apply(self.basket, self.condition, self.offer)
self.assertEqual(D('0.00'), result.discount)
self.assertEqual(0, self.basket.num_items_with_discount)
self.assertEqual(0, self.basket.num_items_without_discount)
def test_applies_correctly_to_basket_which_matches_condition(self):
add_product(self.basket, D('12.00'), 2)
result = self.benefit.apply(self.basket, self.condition, self.offer)
self.assertEqual(1 * D('12.00') * D('0.2'), result.discount)
self.assertEqual(2, self.basket.num_items_with_discount)
self.assertEqual(0, self.basket.num_items_without_discount)
def test_applies_correctly_to_basket_which_exceeds_condition(self):
add_products(self.basket, [(D('12.00'), 2), (D('20.00'), 2)])
result = self.benefit.apply(self.basket, self.condition, self.offer)
self.assertEqual(1 * D('12.00') * D('0.2'), result.discount)
# Should only consume the condition products
self.assertEqual(2, self.basket.num_items_with_discount)
self.assertEqual(2, self.basket.num_items_without_discount)
class TestAPercentageDiscountAppliedWithValueCondition(TestCase):
def setUp(self):
range = models.Range.objects.create(
name="All products", includes_all_products=True)
self.condition = models.ValueCondition.objects.create(
range=range,
type=models.Condition.VALUE,
value=D('10.00'))
self.benefit = models.PercentageDiscountBenefit.objects.create(
range=range,
type=models.Benefit.PERCENTAGE,
value=20)
self.offer = mock.Mock()
self.basket = factories.create_basket(empty=True)
def test_applies_correctly_to_empty_basket(self):
result = self.benefit.apply(self.basket, self.condition, self.offer)
self.assertEqual(D('0.00'), result.discount)
self.assertEqual(0, self.basket.num_items_with_discount)
self.assertEqual(0, self.basket.num_items_without_discount)
def test_applies_correctly_to_basket_which_matches_condition(self):
add_product(self.basket, D('5.00'), 2)
result = self.benefit.apply(self.basket, self.condition, self.offer)
self.assertEqual(2 * D('5.00') * D('0.2'), result.discount)
self.assertEqual(2, self.basket.num_items_with_discount)
self.assertEqual(0, self.basket.num_items_without_discount)
def test_applies_correctly_to_basket_which_exceeds_condition_but_matches_on_boundary(self):
add_product(self.basket, D('5.00'), 3)
result = self.benefit.apply(self.basket, self.condition, self.offer)
self.assertEqual(3 * D('5.00') * D('0.2'), result.discount)
self.assertEqual(3, self.basket.num_items_with_discount)
self.assertEqual(0, self.basket.num_items_without_discount)
def test_applies_correctly_to_basket_which_exceeds_condition(self):
add_product(self.basket, D('4.00'), 3)
result = self.benefit.apply(self.basket, self.condition, self.offer)
self.assertEqual(3 * D('4.00') * D('0.2'), result.discount)
self.assertEqual(3, self.basket.num_items_with_discount)
self.assertEqual(0, self.basket.num_items_without_discount)
class TestAPercentageDiscountWithMaxItemsSetAppliedWithValueCondition(TestCase):
def setUp(self):
range = models.Range.objects.create(
name="All products", includes_all_products=True)
self.condition = models.ValueCondition.objects.create(
range=range,
type=models.Condition.VALUE,
value=D('10.00'))
self.benefit = models.PercentageDiscountBenefit.objects.create(
range=range,
type=models.Benefit.PERCENTAGE,
value=20,
max_affected_items=1)
self.offer = mock.Mock()
self.basket = factories.create_basket(empty=True)
def test_applies_correctly_to_empty_basket(self):
result = self.benefit.apply(self.basket, self.condition, self.offer)
self.assertEqual(D('0.00'), result.discount)
self.assertEqual(0, self.basket.num_items_with_discount)
self.assertEqual(0, self.basket.num_items_without_discount)
def test_applies_correctly_to_basket_which_matches_condition(self):
add_product(self.basket, D('5.00'), 2)
result = self.benefit.apply(self.basket, self.condition, self.offer)
self.assertEqual(1 * D('5.00') * D('0.2'), result.discount)
self.assertEqual(2, self.basket.num_items_with_discount)
self.assertEqual(0, self.basket.num_items_without_discount)
def test_applies_correctly_to_basket_which_exceeds_condition_but_matches_on_boundary(self):
add_product(self.basket, D('5.00'), 3)
result = self.benefit.apply(self.basket, self.condition, self.offer)
self.assertEqual(1 * D('5.00') * D('0.2'), result.discount)
self.assertEqual(2, self.basket.num_items_with_discount)
self.assertEqual(1, self.basket.num_items_without_discount)
def test_applies_correctly_to_basket_which_exceeds_condition(self):
add_product(self.basket, D('4.00'), 3)
result = self.benefit.apply(self.basket, self.condition, self.offer)
self.assertEqual(1 * D('4.00') * D('0.2'), result.discount)
self.assertEqual(3, self.basket.num_items_with_discount)
self.assertEqual(0, self.basket.num_items_without_discount)
|
bsd-3-clause
|
[
504,
6107,
492,
6345,
465,
577,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
646,
1683,
199,
199,
504,
312,
22707,
14,
5181,
14,
12786,
492,
1709,
199,
504,
312,
22707,
14,
396,
492,
22115,
199,
504,
312,
22707,
14,
396,
14,
18136,
492,
1050,
63,
2558,
12,
1050,
63,
13336,
421,
199,
533,
1379,
1282,
281,
2946,
474,
2825,
835,
2640,
1857,
3007,
2353,
9558,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1425,
275,
1709,
14,
4709,
14,
1462,
14,
981,
8,
288,
536,
628,
2422,
7585,
401,
6952,
63,
452,
63,
13336,
29,
549,
9,
267,
291,
14,
5394,
275,
1709,
14,
2353,
9558,
8,
288,
1425,
29,
1842,
12,
288,
730,
29,
992,
14,
9558,
14,
8760,
12,
288,
574,
29,
18,
9,
267,
291,
14,
66,
6349,
3269,
275,
1709,
14,
17931,
474,
2825,
835,
34,
6349,
3269,
8,
288,
1425,
29,
1842,
12,
288,
730,
29,
992,
14,
34,
6349,
3269,
14,
4227,
17349,
2962,
12,
288,
574,
29,
1165,
9,
267,
291,
14,
12786,
275,
1683,
14,
3346,
342,
267,
291,
14,
18136,
275,
22115,
14,
981,
63,
18136,
8,
1667,
29,
549,
9,
339,
347,
511,
63,
571,
6528,
63,
4525,
590,
63,
475,
63,
1667,
63,
18136,
8,
277,
304,
267,
754,
275,
291,
14,
66,
6349,
3269,
14,
4998,
8,
277,
14,
18136,
12,
291,
14,
5394,
12,
291,
14,
12786,
9,
267,
291,
14,
629,
8,
36,
360,
16,
14,
383,
659,
754,
14,
15446,
9,
267,
291,
14,
629,
8,
16,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
1045,
63,
15446,
9,
267,
291,
14,
629,
8,
16,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
7395,
63,
15446,
9,
339,
347,
511,
63,
571,
6528,
63,
4525,
590,
63,
475,
63,
18136,
63,
1045,
63,
889,
63,
15446,
461,
63,
13336,
8,
277,
304,
267,
3336,
275,
22115,
14,
981,
63,
2558,
8,
374,
63,
15446,
461,
29,
797,
9,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
577,
360,
713,
14,
383,
659,
499,
12,
3336,
29,
2558,
9,
267,
754,
275,
291,
14,
66,
6349,
3269,
14,
4998,
8,
277,
14,
18136,
12,
291,
14,
5394,
12,
291,
14,
12786,
9,
267,
291,
14,
629,
8,
36,
360,
16,
14,
383,
659,
754,
14,
15446,
9,
267,
291,
14,
629,
8,
16,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
1045,
63,
15446,
9,
267,
291,
14,
629,
8,
18,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
7395,
63,
15446,
9,
339,
347,
511,
63,
571,
6528,
63,
4525,
590,
63,
475,
63,
18136,
63,
6777,
63,
6742,
63,
5394,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
577,
360,
713,
14,
383,
659,
499,
9,
267,
754,
275,
291,
14,
66,
6349,
3269,
14,
4998,
8,
277,
14,
18136,
12,
291,
14,
5394,
12,
291,
14,
12786,
9,
267,
291,
14,
629,
8,
18,
627,
577,
360,
713,
14,
383,
358,
627,
577,
360,
16,
14,
18,
659,
754,
14,
15446,
9,
267,
291,
14,
629,
8,
18,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
1045,
63,
15446,
9,
267,
291,
14,
629,
8,
16,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
7395,
63,
15446,
9,
339,
347,
511,
63,
571,
6528,
63,
4525,
590,
63,
475,
63,
18136,
63,
6777,
63,
476,
301,
5923,
63,
5394,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
577,
360,
713,
14,
383,
659,
650,
9,
267,
754,
275,
291,
14,
66,
6349,
3269,
14,
4998,
8,
277,
14,
18136,
12,
291,
14,
5394,
12,
291,
14,
12786,
9,
267,
291,
14,
629,
8,
19,
627,
577,
360,
713,
14,
383,
358,
627,
577,
360,
16,
14,
18,
659,
754,
14,
15446,
9,
267,
291,
14,
629,
8,
19,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
1045,
63,
15446,
9,
267,
291,
14,
629,
8,
16,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
7395,
63,
15446,
9,
421,
199,
533,
1379,
1282,
281,
2946,
474,
2825,
835,
3007,
4261,
7412,
1084,
2640,
1857,
3007,
2353,
9558,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1425,
275,
1709,
14,
4709,
14,
1462,
14,
981,
8,
288,
536,
628,
2422,
7585,
401,
6952,
63,
452,
63,
13336,
29,
549,
9,
267,
291,
14,
5394,
275,
1709,
14,
2353,
9558,
8,
288,
1425,
29,
1842,
12,
288,
730,
29,
992,
14,
9558,
14,
8760,
12,
288,
574,
29,
18,
9,
267,
291,
14,
66,
6349,
3269,
275,
1709,
14,
17931,
474,
2825,
835,
34,
6349,
3269,
8,
288,
1425,
29,
1842,
12,
288,
730,
29,
992,
14,
34,
6349,
3269,
14,
4227,
17349,
2962,
12,
288,
574,
29,
1165,
12,
288,
1390,
63,
26653,
63,
1744,
29,
17,
9,
267,
291,
14,
12786,
275,
1683,
14,
3346,
342,
267,
291,
14,
18136,
275,
22115,
14,
981,
63,
18136,
8,
1667,
29,
549,
9,
339,
347,
511,
63,
571,
6528,
63,
4525,
590,
63,
475,
63,
1667,
63,
18136,
8,
277,
304,
267,
754,
275,
291,
14,
66,
6349,
3269,
14,
4998,
8,
277,
14,
18136,
12,
291,
14,
5394,
12,
291,
14,
12786,
9,
267,
291,
14,
629,
8,
36,
360,
16,
14,
383,
659,
754,
14,
15446,
9,
267,
291,
14,
629,
8,
16,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
1045,
63,
15446,
9,
267,
291,
14,
629,
8,
16,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
7395,
63,
15446,
9,
339,
347,
511,
63,
571,
6528,
63,
4525,
590,
63,
475,
63,
18136,
63,
6777,
63,
6742,
63,
5394,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
577,
360,
713,
14,
383,
659,
499,
9,
267,
754,
275,
291,
14,
66,
6349,
3269,
14,
4998,
8,
277,
14,
18136,
12,
291,
14,
5394,
12,
291,
14,
12786,
9,
267,
291,
14,
629,
8,
17,
627,
577,
360,
713,
14,
383,
358,
627,
577,
360,
16,
14,
18,
659,
754,
14,
15446,
9,
267,
291,
14,
629,
8,
18,
12,
291,
14,
18136,
14,
1507,
63
] |
[
6107,
492,
6345,
465,
577,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
646,
1683,
199,
199,
504,
312,
22707,
14,
5181,
14,
12786,
492,
1709,
199,
504,
312,
22707,
14,
396,
492,
22115,
199,
504,
312,
22707,
14,
396,
14,
18136,
492,
1050,
63,
2558,
12,
1050,
63,
13336,
421,
199,
533,
1379,
1282,
281,
2946,
474,
2825,
835,
2640,
1857,
3007,
2353,
9558,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1425,
275,
1709,
14,
4709,
14,
1462,
14,
981,
8,
288,
536,
628,
2422,
7585,
401,
6952,
63,
452,
63,
13336,
29,
549,
9,
267,
291,
14,
5394,
275,
1709,
14,
2353,
9558,
8,
288,
1425,
29,
1842,
12,
288,
730,
29,
992,
14,
9558,
14,
8760,
12,
288,
574,
29,
18,
9,
267,
291,
14,
66,
6349,
3269,
275,
1709,
14,
17931,
474,
2825,
835,
34,
6349,
3269,
8,
288,
1425,
29,
1842,
12,
288,
730,
29,
992,
14,
34,
6349,
3269,
14,
4227,
17349,
2962,
12,
288,
574,
29,
1165,
9,
267,
291,
14,
12786,
275,
1683,
14,
3346,
342,
267,
291,
14,
18136,
275,
22115,
14,
981,
63,
18136,
8,
1667,
29,
549,
9,
339,
347,
511,
63,
571,
6528,
63,
4525,
590,
63,
475,
63,
1667,
63,
18136,
8,
277,
304,
267,
754,
275,
291,
14,
66,
6349,
3269,
14,
4998,
8,
277,
14,
18136,
12,
291,
14,
5394,
12,
291,
14,
12786,
9,
267,
291,
14,
629,
8,
36,
360,
16,
14,
383,
659,
754,
14,
15446,
9,
267,
291,
14,
629,
8,
16,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
1045,
63,
15446,
9,
267,
291,
14,
629,
8,
16,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
7395,
63,
15446,
9,
339,
347,
511,
63,
571,
6528,
63,
4525,
590,
63,
475,
63,
18136,
63,
1045,
63,
889,
63,
15446,
461,
63,
13336,
8,
277,
304,
267,
3336,
275,
22115,
14,
981,
63,
2558,
8,
374,
63,
15446,
461,
29,
797,
9,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
577,
360,
713,
14,
383,
659,
499,
12,
3336,
29,
2558,
9,
267,
754,
275,
291,
14,
66,
6349,
3269,
14,
4998,
8,
277,
14,
18136,
12,
291,
14,
5394,
12,
291,
14,
12786,
9,
267,
291,
14,
629,
8,
36,
360,
16,
14,
383,
659,
754,
14,
15446,
9,
267,
291,
14,
629,
8,
16,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
1045,
63,
15446,
9,
267,
291,
14,
629,
8,
18,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
7395,
63,
15446,
9,
339,
347,
511,
63,
571,
6528,
63,
4525,
590,
63,
475,
63,
18136,
63,
6777,
63,
6742,
63,
5394,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
577,
360,
713,
14,
383,
659,
499,
9,
267,
754,
275,
291,
14,
66,
6349,
3269,
14,
4998,
8,
277,
14,
18136,
12,
291,
14,
5394,
12,
291,
14,
12786,
9,
267,
291,
14,
629,
8,
18,
627,
577,
360,
713,
14,
383,
358,
627,
577,
360,
16,
14,
18,
659,
754,
14,
15446,
9,
267,
291,
14,
629,
8,
18,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
1045,
63,
15446,
9,
267,
291,
14,
629,
8,
16,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
7395,
63,
15446,
9,
339,
347,
511,
63,
571,
6528,
63,
4525,
590,
63,
475,
63,
18136,
63,
6777,
63,
476,
301,
5923,
63,
5394,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
577,
360,
713,
14,
383,
659,
650,
9,
267,
754,
275,
291,
14,
66,
6349,
3269,
14,
4998,
8,
277,
14,
18136,
12,
291,
14,
5394,
12,
291,
14,
12786,
9,
267,
291,
14,
629,
8,
19,
627,
577,
360,
713,
14,
383,
358,
627,
577,
360,
16,
14,
18,
659,
754,
14,
15446,
9,
267,
291,
14,
629,
8,
19,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
1045,
63,
15446,
9,
267,
291,
14,
629,
8,
16,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
7395,
63,
15446,
9,
421,
199,
533,
1379,
1282,
281,
2946,
474,
2825,
835,
3007,
4261,
7412,
1084,
2640,
1857,
3007,
2353,
9558,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1425,
275,
1709,
14,
4709,
14,
1462,
14,
981,
8,
288,
536,
628,
2422,
7585,
401,
6952,
63,
452,
63,
13336,
29,
549,
9,
267,
291,
14,
5394,
275,
1709,
14,
2353,
9558,
8,
288,
1425,
29,
1842,
12,
288,
730,
29,
992,
14,
9558,
14,
8760,
12,
288,
574,
29,
18,
9,
267,
291,
14,
66,
6349,
3269,
275,
1709,
14,
17931,
474,
2825,
835,
34,
6349,
3269,
8,
288,
1425,
29,
1842,
12,
288,
730,
29,
992,
14,
34,
6349,
3269,
14,
4227,
17349,
2962,
12,
288,
574,
29,
1165,
12,
288,
1390,
63,
26653,
63,
1744,
29,
17,
9,
267,
291,
14,
12786,
275,
1683,
14,
3346,
342,
267,
291,
14,
18136,
275,
22115,
14,
981,
63,
18136,
8,
1667,
29,
549,
9,
339,
347,
511,
63,
571,
6528,
63,
4525,
590,
63,
475,
63,
1667,
63,
18136,
8,
277,
304,
267,
754,
275,
291,
14,
66,
6349,
3269,
14,
4998,
8,
277,
14,
18136,
12,
291,
14,
5394,
12,
291,
14,
12786,
9,
267,
291,
14,
629,
8,
36,
360,
16,
14,
383,
659,
754,
14,
15446,
9,
267,
291,
14,
629,
8,
16,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
1045,
63,
15446,
9,
267,
291,
14,
629,
8,
16,
12,
291,
14,
18136,
14,
1507,
63,
1744,
63,
7395,
63,
15446,
9,
339,
347,
511,
63,
571,
6528,
63,
4525,
590,
63,
475,
63,
18136,
63,
6777,
63,
6742,
63,
5394,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
577,
360,
713,
14,
383,
659,
499,
9,
267,
754,
275,
291,
14,
66,
6349,
3269,
14,
4998,
8,
277,
14,
18136,
12,
291,
14,
5394,
12,
291,
14,
12786,
9,
267,
291,
14,
629,
8,
17,
627,
577,
360,
713,
14,
383,
358,
627,
577,
360,
16,
14,
18,
659,
754,
14,
15446,
9,
267,
291,
14,
629,
8,
18,
12,
291,
14,
18136,
14,
1507,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
aetilley/scikit-learn
|
sklearn/metrics/cluster/bicluster.py
|
359
|
2797
|
from __future__ import division
import numpy as np
from sklearn.utils.linear_assignment_ import linear_assignment
from sklearn.utils.validation import check_consistent_length, check_array
__all__ = ["consensus_score"]
def _check_rows_and_columns(a, b):
"""Unpacks the row and column arrays and checks their shape."""
check_consistent_length(*a)
check_consistent_length(*b)
checks = lambda x: check_array(x, ensure_2d=False)
a_rows, a_cols = map(checks, a)
b_rows, b_cols = map(checks, b)
return a_rows, a_cols, b_rows, b_cols
def _jaccard(a_rows, a_cols, b_rows, b_cols):
"""Jaccard coefficient on the elements of the two biclusters."""
intersection = ((a_rows * b_rows).sum() *
(a_cols * b_cols).sum())
a_size = a_rows.sum() * a_cols.sum()
b_size = b_rows.sum() * b_cols.sum()
return intersection / (a_size + b_size - intersection)
def _pairwise_similarity(a, b, similarity):
"""Computes pairwise similarity matrix.
result[i, j] is the Jaccard coefficient of a's bicluster i and b's
bicluster j.
"""
a_rows, a_cols, b_rows, b_cols = _check_rows_and_columns(a, b)
n_a = a_rows.shape[0]
n_b = b_rows.shape[0]
result = np.array(list(list(similarity(a_rows[i], a_cols[i],
b_rows[j], b_cols[j])
for j in range(n_b))
for i in range(n_a)))
return result
def consensus_score(a, b, similarity="jaccard"):
"""The similarity of two sets of biclusters.
Similarity between individual biclusters is computed. Then the
best matching between sets is found using the Hungarian algorithm.
The final score is the sum of similarities divided by the size of
the larger set.
Read more in the :ref:`User Guide <biclustering>`.
Parameters
----------
a : (rows, columns)
Tuple of row and column indicators for a set of biclusters.
b : (rows, columns)
Another set of biclusters like ``a``.
similarity : string or function, optional, default: "jaccard"
May be the string "jaccard" to use the Jaccard coefficient, or
any function that takes four arguments, each of which is a 1d
indicator vector: (a_rows, a_columns, b_rows, b_columns).
References
----------
* Hochreiter, Bodenhofer, et. al., 2010. `FABIA: factor analysis
for bicluster acquisition
<https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2881408/>`__.
"""
if similarity == "jaccard":
similarity = _jaccard
matrix = _pairwise_similarity(a, b, similarity)
indices = linear_assignment(1. - matrix)
n_a = len(a[0])
n_b = len(b[0])
return matrix[indices[:, 0], indices[:, 1]].sum() / max(n_a, n_b)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
6357,
14,
1208,
14,
6676,
63,
10861,
63,
492,
7798,
63,
10861,
199,
504,
6357,
14,
1208,
14,
6136,
492,
1104,
63,
15478,
63,
1267,
12,
1104,
63,
1144,
199,
199,
363,
452,
363,
275,
2097,
388,
31664,
63,
3397,
937,
421,
199,
318,
485,
1074,
63,
3838,
63,
460,
63,
3406,
8,
65,
12,
330,
304,
272,
408,
26472,
83,
314,
1962,
436,
2763,
6572,
436,
5920,
3932,
2215,
1041,
272,
1104,
63,
15478,
63,
1267,
2031,
65,
9,
272,
1104,
63,
15478,
63,
1267,
2031,
66,
9,
272,
5920,
275,
2400,
671,
26,
1104,
63,
1144,
8,
88,
12,
4868,
63,
18,
68,
29,
797,
9,
272,
282,
63,
3838,
12,
282,
63,
4574,
275,
2341,
8,
8625,
12,
282,
9,
272,
330,
63,
3838,
12,
330,
63,
4574,
275,
2341,
8,
8625,
12,
330,
9,
272,
372,
282,
63,
3838,
12,
282,
63,
4574,
12,
330,
63,
3838,
12,
330,
63,
4574,
421,
199,
318,
485,
74,
5470,
1005,
8,
65,
63,
3838,
12,
282,
63,
4574,
12,
330,
63,
3838,
12,
330,
63,
4574,
304,
272,
408,
42,
5470,
1005,
9421,
641,
314,
4008,
402,
314,
2877,
12111,
9170,
1041,
272,
16223,
275,
3666,
65,
63,
3838,
627,
330,
63,
3838,
680,
1838,
342,
627,
490,
334,
65,
63,
4574,
627,
330,
63,
4574,
680,
1838,
1012,
339,
282,
63,
890,
275,
282,
63,
3838,
14,
1838,
342,
627,
282,
63,
4574,
14,
1838,
342,
272,
330,
63,
890,
275,
330,
63,
3838,
14,
1838,
342,
627,
330,
63,
4574,
14,
1838,
342,
339,
372,
16223,
1182,
334,
65,
63,
890,
435,
330,
63,
890,
446,
16223,
9,
421,
199,
318,
485,
25069,
63,
21965,
8,
65,
12,
330,
12,
22838,
304,
272,
408,
22594,
24859,
22838,
3634,
14,
339,
754,
59,
73,
12,
1335,
61,
365,
314,
1603,
5470,
1005,
9421,
402,
282,
1159,
12111,
4201,
284,
436,
330,
1159,
272,
12111,
4201,
1335,
14,
339,
408,
272,
282,
63,
3838,
12,
282,
63,
4574,
12,
330,
63,
3838,
12,
330,
63,
4574,
275,
485,
1074,
63,
3838,
63,
460,
63,
3406,
8,
65,
12,
330,
9,
272,
302,
63,
65,
275,
282,
63,
3838,
14,
1392,
59,
16,
61,
272,
302,
63,
66,
275,
330,
63,
3838,
14,
1392,
59,
16,
61,
272,
754,
275,
980,
14,
1144,
8,
513,
8,
513,
8,
21965,
8,
65,
63,
3838,
59,
73,
467,
282,
63,
4574,
59,
73,
467,
5644,
330,
63,
3838,
59,
74,
467,
330,
63,
4574,
59,
74,
566,
1816,
367,
1335,
315,
1425,
8,
78,
63,
66,
430,
2574,
367,
284,
315,
1425,
8,
78,
63,
65,
1724,
272,
372,
754,
421,
199,
318,
406,
31664,
63,
3397,
8,
65,
12,
330,
12,
22838,
628,
74,
5470,
1005,
2349,
272,
408,
1918,
22838,
402,
2877,
5951,
402,
12111,
9170,
14,
339,
10751,
13093,
3382,
8212,
12111,
9170,
365,
9235,
14,
9442,
314,
272,
5526,
4877,
3382,
5951,
365,
1911,
1808,
314,
869,
25364,
5563,
14,
272,
710,
4242,
5396,
365,
314,
3089,
402,
4389,
382,
27894,
29378,
701,
314,
1568,
402,
272,
314,
12142,
663,
14,
339,
5574,
1655,
315,
314,
520,
1121,
1705,
1899,
15423,
665,
4492,
25802,
14943,
339,
3897,
272,
4143,
272,
282,
520,
334,
3838,
12,
4362,
9,
267,
11634,
402,
1962,
436,
2763,
7262,
2750,
367,
282,
663,
402,
12111,
9170,
14,
339,
330,
520,
334,
3838,
12,
4362,
9,
267,
22604,
663,
402,
12111,
9170,
2839,
1124,
65,
4345,
339,
22838,
520,
1059,
503,
805,
12,
2716,
12,
849,
26,
298,
74,
5470,
1005,
2,
267,
10162,
506,
314,
1059,
298,
74,
5470,
1005,
2,
370,
675,
314,
1603,
5470,
1005,
9421,
12,
503,
267,
1263,
805,
626,
6181,
11648,
2368,
12,
1924,
402,
1314,
365,
282,
413,
68,
267,
16385,
5477,
26,
334,
65,
63,
3838,
12,
282,
63,
3406,
12,
330,
63,
3838,
12,
330,
63,
3406,
680,
339,
14504,
272,
4143,
339,
627,
28673,
335,
264,
1661,
12,
699,
380,
78,
526,
2412,
12,
10844,
14,
741,
2020,
7129,
14,
658,
38,
1217,
13033,
26,
6535,
11284,
489,
367,
12111,
4201,
1066,
21523,
489,
665,
2859,
921,
1544,
14,
78,
2894,
73,
14,
7530,
77,
14,
8445,
72,
14,
16294,
15,
80,
5466,
15,
19813,
15,
48,
7608,
10740,
1079,
2036,
3133,
64,
4343,
339,
408,
272,
340,
22838,
508,
298,
74,
5470,
1005,
582,
267,
22838,
275,
485,
74,
5470,
1005,
272,
3634,
275,
485,
25069,
63,
21965,
8,
65,
12,
330,
12,
22838,
9,
272,
4918,
275,
7798,
63,
10861,
8,
17,
14,
446,
3634,
9,
272,
302,
63,
65,
275,
822,
8,
65,
59,
16,
566,
272,
302,
63,
66,
275,
822,
8,
66,
59,
16,
566,
272,
372,
3634,
59,
4108,
3981,
378,
467,
4918,
3981,
413,
20230,
1838,
342,
1182,
1390,
8,
78,
63,
65,
12,
302,
63,
66,
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
] |
[
636,
2443,
363,
492,
4629,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
6357,
14,
1208,
14,
6676,
63,
10861,
63,
492,
7798,
63,
10861,
199,
504,
6357,
14,
1208,
14,
6136,
492,
1104,
63,
15478,
63,
1267,
12,
1104,
63,
1144,
199,
199,
363,
452,
363,
275,
2097,
388,
31664,
63,
3397,
937,
421,
199,
318,
485,
1074,
63,
3838,
63,
460,
63,
3406,
8,
65,
12,
330,
304,
272,
408,
26472,
83,
314,
1962,
436,
2763,
6572,
436,
5920,
3932,
2215,
1041,
272,
1104,
63,
15478,
63,
1267,
2031,
65,
9,
272,
1104,
63,
15478,
63,
1267,
2031,
66,
9,
272,
5920,
275,
2400,
671,
26,
1104,
63,
1144,
8,
88,
12,
4868,
63,
18,
68,
29,
797,
9,
272,
282,
63,
3838,
12,
282,
63,
4574,
275,
2341,
8,
8625,
12,
282,
9,
272,
330,
63,
3838,
12,
330,
63,
4574,
275,
2341,
8,
8625,
12,
330,
9,
272,
372,
282,
63,
3838,
12,
282,
63,
4574,
12,
330,
63,
3838,
12,
330,
63,
4574,
421,
199,
318,
485,
74,
5470,
1005,
8,
65,
63,
3838,
12,
282,
63,
4574,
12,
330,
63,
3838,
12,
330,
63,
4574,
304,
272,
408,
42,
5470,
1005,
9421,
641,
314,
4008,
402,
314,
2877,
12111,
9170,
1041,
272,
16223,
275,
3666,
65,
63,
3838,
627,
330,
63,
3838,
680,
1838,
342,
627,
490,
334,
65,
63,
4574,
627,
330,
63,
4574,
680,
1838,
1012,
339,
282,
63,
890,
275,
282,
63,
3838,
14,
1838,
342,
627,
282,
63,
4574,
14,
1838,
342,
272,
330,
63,
890,
275,
330,
63,
3838,
14,
1838,
342,
627,
330,
63,
4574,
14,
1838,
342,
339,
372,
16223,
1182,
334,
65,
63,
890,
435,
330,
63,
890,
446,
16223,
9,
421,
199,
318,
485,
25069,
63,
21965,
8,
65,
12,
330,
12,
22838,
304,
272,
408,
22594,
24859,
22838,
3634,
14,
339,
754,
59,
73,
12,
1335,
61,
365,
314,
1603,
5470,
1005,
9421,
402,
282,
1159,
12111,
4201,
284,
436,
330,
1159,
272,
12111,
4201,
1335,
14,
339,
408,
272,
282,
63,
3838,
12,
282,
63,
4574,
12,
330,
63,
3838,
12,
330,
63,
4574,
275,
485,
1074,
63,
3838,
63,
460,
63,
3406,
8,
65,
12,
330,
9,
272,
302,
63,
65,
275,
282,
63,
3838,
14,
1392,
59,
16,
61,
272,
302,
63,
66,
275,
330,
63,
3838,
14,
1392,
59,
16,
61,
272,
754,
275,
980,
14,
1144,
8,
513,
8,
513,
8,
21965,
8,
65,
63,
3838,
59,
73,
467,
282,
63,
4574,
59,
73,
467,
5644,
330,
63,
3838,
59,
74,
467,
330,
63,
4574,
59,
74,
566,
1816,
367,
1335,
315,
1425,
8,
78,
63,
66,
430,
2574,
367,
284,
315,
1425,
8,
78,
63,
65,
1724,
272,
372,
754,
421,
199,
318,
406,
31664,
63,
3397,
8,
65,
12,
330,
12,
22838,
628,
74,
5470,
1005,
2349,
272,
408,
1918,
22838,
402,
2877,
5951,
402,
12111,
9170,
14,
339,
10751,
13093,
3382,
8212,
12111,
9170,
365,
9235,
14,
9442,
314,
272,
5526,
4877,
3382,
5951,
365,
1911,
1808,
314,
869,
25364,
5563,
14,
272,
710,
4242,
5396,
365,
314,
3089,
402,
4389,
382,
27894,
29378,
701,
314,
1568,
402,
272,
314,
12142,
663,
14,
339,
5574,
1655,
315,
314,
520,
1121,
1705,
1899,
15423,
665,
4492,
25802,
14943,
339,
3897,
272,
4143,
272,
282,
520,
334,
3838,
12,
4362,
9,
267,
11634,
402,
1962,
436,
2763,
7262,
2750,
367,
282,
663,
402,
12111,
9170,
14,
339,
330,
520,
334,
3838,
12,
4362,
9,
267,
22604,
663,
402,
12111,
9170,
2839,
1124,
65,
4345,
339,
22838,
520,
1059,
503,
805,
12,
2716,
12,
849,
26,
298,
74,
5470,
1005,
2,
267,
10162,
506,
314,
1059,
298,
74,
5470,
1005,
2,
370,
675,
314,
1603,
5470,
1005,
9421,
12,
503,
267,
1263,
805,
626,
6181,
11648,
2368,
12,
1924,
402,
1314,
365,
282,
413,
68,
267,
16385,
5477,
26,
334,
65,
63,
3838,
12,
282,
63,
3406,
12,
330,
63,
3838,
12,
330,
63,
3406,
680,
339,
14504,
272,
4143,
339,
627,
28673,
335,
264,
1661,
12,
699,
380,
78,
526,
2412,
12,
10844,
14,
741,
2020,
7129,
14,
658,
38,
1217,
13033,
26,
6535,
11284,
489,
367,
12111,
4201,
1066,
21523,
489,
665,
2859,
921,
1544,
14,
78,
2894,
73,
14,
7530,
77,
14,
8445,
72,
14,
16294,
15,
80,
5466,
15,
19813,
15,
48,
7608,
10740,
1079,
2036,
3133,
64,
4343,
339,
408,
272,
340,
22838,
508,
298,
74,
5470,
1005,
582,
267,
22838,
275,
485,
74,
5470,
1005,
272,
3634,
275,
485,
25069,
63,
21965,
8,
65,
12,
330,
12,
22838,
9,
272,
4918,
275,
7798,
63,
10861,
8,
17,
14,
446,
3634,
9,
272,
302,
63,
65,
275,
822,
8,
65,
59,
16,
566,
272,
302,
63,
66,
275,
822,
8,
66,
59,
16,
566,
272,
372,
3634,
59,
4108,
3981,
378,
467,
4918,
3981,
413,
20230,
1838,
342,
1182,
1390,
8,
78,
63,
65,
12,
302,
63,
66,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
xuerenlv/scrapy
|
scrapy/http/request/form.py
|
23
|
6564
|
"""
This module implements the FormRequest class which is a more convenient class
(than Request) to generate Requests based on form data.
See documentation in docs/topics/request-response.rst
"""
from six.moves.urllib.parse import urljoin, urlencode
import lxml.html
from parsel.selector import create_root_node
import six
from scrapy.http.request import Request
from scrapy.utils.python import to_bytes, is_listlike
class FormRequest(Request):
def __init__(self, *args, **kwargs):
formdata = kwargs.pop('formdata', None)
if formdata and kwargs.get('method') is None:
kwargs['method'] = 'POST'
super(FormRequest, self).__init__(*args, **kwargs)
if formdata:
items = formdata.items() if isinstance(formdata, dict) else formdata
querystr = _urlencode(items, self.encoding)
if self.method == 'POST':
self.headers.setdefault(b'Content-Type', b'application/x-www-form-urlencoded')
self._set_body(querystr)
else:
self._set_url(self.url + ('&' if '?' in self.url else '?') + querystr)
@classmethod
def from_response(cls, response, formname=None, formid=None, formnumber=0, formdata=None,
clickdata=None, dont_click=False, formxpath=None, **kwargs):
kwargs.setdefault('encoding', response.encoding)
form = _get_form(response, formname, formid, formnumber, formxpath)
formdata = _get_inputs(form, formdata, dont_click, clickdata, response)
url = _get_form_url(form, kwargs.pop('url', None))
method = kwargs.pop('method', form.method)
return cls(url=url, method=method, formdata=formdata, **kwargs)
def _get_form_url(form, url):
if url is None:
return form.action or form.base_url
return urljoin(form.base_url, url)
def _urlencode(seq, enc):
values = [(to_bytes(k, enc), to_bytes(v, enc))
for k, vs in seq
for v in (vs if is_listlike(vs) else [vs])]
return urlencode(values, doseq=1)
def _get_form(response, formname, formid, formnumber, formxpath):
"""Find the form element """
text = response.body_as_unicode()
root = create_root_node(text, lxml.html.HTMLParser, base_url=response.url)
forms = root.xpath('//form')
if not forms:
raise ValueError("No <form> element found in %s" % response)
if formname is not None:
f = root.xpath('//form[@name="%s"]' % formname)
if f:
return f[0]
if formid is not None:
f = root.xpath('//form[@id="%s"]' % formid)
if f:
return f[0]
# Get form element from xpath, if not found, go up
if formxpath is not None:
nodes = root.xpath(formxpath)
if nodes:
el = nodes[0]
while True:
if el.tag == 'form':
return el
el = el.getparent()
if el is None:
break
raise ValueError('No <form> element found with %s' % formxpath)
# If we get here, it means that either formname was None
# or invalid
if formnumber is not None:
try:
form = forms[formnumber]
except IndexError:
raise IndexError("Form number %d not found in %s" %
(formnumber, response))
else:
return form
def _get_inputs(form, formdata, dont_click, clickdata, response):
try:
formdata = dict(formdata or ())
except (ValueError, TypeError):
raise ValueError('formdata should be a dict or iterable of tuples')
inputs = form.xpath('descendant::textarea'
'|descendant::select'
'|descendant::input[@type!="submit" and @type!="image" and @type!="reset"'
'and ((@type!="checkbox" and @type!="radio") or @checked)]')
values = [(k, u'' if v is None else v)
for k, v in (_value(e) for e in inputs)
if k and k not in formdata]
if not dont_click:
clickable = _get_clickable(clickdata, form)
if clickable and clickable[0] not in formdata and not clickable[0] is None:
values.append(clickable)
values.extend(formdata.items())
return values
def _value(ele):
n = ele.name
v = ele.value
if ele.tag == 'select':
return _select_value(ele, n, v)
return n, v
def _select_value(ele, n, v):
multiple = ele.multiple
if v is None and not multiple:
# Match browser behaviour on simple select tag without options selected
# And for select tags wihout options
o = ele.value_options
return (n, o[0]) if o else (None, None)
elif v is not None and multiple:
# This is a workround to bug in lxml fixed 2.3.1
# fix https://github.com/lxml/lxml/commit/57f49eed82068a20da3db8f1b18ae00c1bab8b12#L1L1139
selected_options = ele.xpath('.//option[@selected]')
v = [(o.get('value') or o.text or u'').strip() for o in selected_options]
return n, v
def _get_clickable(clickdata, form):
"""
Returns the clickable element specified in clickdata,
if the latter is given. If not, it returns the first
clickable element found
"""
clickables = [el for el in form.xpath('.//input[@type="submit"]')]
if not clickables:
return
# If we don't have clickdata, we just use the first clickable element
if clickdata is None:
el = clickables[0]
return (el.name, el.value)
# If clickdata is given, we compare it to the clickable elements to find a
# match. We first look to see if the number is specified in clickdata,
# because that uniquely identifies the element
nr = clickdata.get('nr', None)
if nr is not None:
try:
el = list(form.inputs)[nr]
except IndexError:
pass
else:
return (el.name, el.value)
# We didn't find it, so now we build an XPath expression out of the other
# arguments, because they can be used as such
xpath = u'.//*' + \
u''.join(u'[@%s="%s"]' % c for c in six.iteritems(clickdata))
el = form.xpath(xpath)
if len(el) == 1:
return (el[0].name, el[0].value)
elif len(el) > 1:
raise ValueError("Multiple elements found (%r) matching the criteria "
"in clickdata: %r" % (el, clickdata))
else:
raise ValueError('No clickable element matching clickdata: %r' % (clickdata,))
|
bsd-3-clause
|
[
624,
199,
2765,
859,
9031,
314,
8204,
2017,
1021,
1314,
365,
282,
1655,
22700,
1021,
199,
8,
13797,
4784,
9,
370,
3550,
20260,
4079,
641,
1824,
666,
14,
199,
199,
9295,
3794,
315,
9149,
15,
11299,
15,
1069,
13,
1310,
14,
8332,
199,
624,
199,
199,
504,
3816,
14,
4912,
14,
4078,
14,
1122,
492,
20818,
12,
16511,
199,
646,
14490,
14,
1360,
199,
504,
2198,
76,
14,
6662,
492,
1218,
63,
1231,
63,
932,
199,
646,
3816,
199,
504,
18918,
14,
1014,
14,
1069,
492,
4784,
199,
504,
18918,
14,
1208,
14,
1548,
492,
370,
63,
2394,
12,
365,
63,
513,
2930,
421,
199,
533,
8204,
2017,
8,
2017,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1824,
576,
275,
2074,
14,
1935,
360,
30942,
297,
488,
9,
267,
340,
1824,
576,
436,
2074,
14,
362,
360,
765,
358,
365,
488,
26,
288,
2074,
459,
765,
418,
275,
283,
4030,
7,
398,
1613,
8,
2821,
2017,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
398,
340,
1824,
576,
26,
288,
2974,
275,
1824,
576,
14,
1744,
342,
340,
1228,
8,
30942,
12,
1211,
9,
587,
1824,
576,
288,
1827,
495,
275,
485,
10738,
8,
1744,
12,
291,
14,
2991,
9,
288,
340,
291,
14,
765,
508,
283,
4030,
356,
355,
291,
14,
2139,
14,
5486,
8,
66,
7,
2714,
13,
804,
297,
330,
7,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
358,
355,
291,
423,
409,
63,
2030,
8,
1131,
495,
9,
288,
587,
26,
355,
291,
423,
409,
63,
633,
8,
277,
14,
633,
435,
661,
6,
7,
340,
15539,
315,
291,
14,
633,
587,
8720,
358,
435,
1827,
495,
9,
339,
768,
3744,
272,
347,
687,
63,
1310,
8,
1886,
12,
1177,
12,
1824,
354,
29,
403,
12,
1824,
344,
29,
403,
12,
1824,
1955,
29,
16,
12,
1824,
576,
29,
403,
12,
1993,
8968,
576,
29,
403,
12,
21542,
63,
4891,
29,
797,
12,
1824,
8006,
29,
403,
12,
1011,
958,
304,
267,
2074,
14,
5486,
360,
2991,
297,
1177,
14,
2991,
9,
267,
1824,
275,
485,
362,
63,
964,
8,
1310,
12,
1824,
354,
12,
1824,
344,
12,
1824,
1955,
12,
1824,
8006,
9,
267,
1824,
576,
275,
485,
362,
63,
3711,
8,
964,
12,
1824,
576,
12,
21542,
63,
4891,
12,
8968,
576,
12,
1177,
9,
267,
1166,
275,
485,
362,
63,
964,
63,
633,
8,
964,
12,
2074,
14,
1935,
360,
633,
297,
488,
430,
267,
1083,
275,
2074,
14,
1935,
360,
765,
297,
1824,
14,
765,
9,
267,
372,
843,
8,
633,
29,
633,
12,
1083,
29,
765,
12,
1824,
576,
29,
30942,
12,
1011,
958,
9,
421,
199,
318,
485,
362,
63,
964,
63,
633,
8,
964,
12,
1166,
304,
272,
340,
1166,
365,
488,
26,
267,
372,
1824,
14,
1287,
503,
1824,
14,
1095,
63,
633,
272,
372,
20818,
8,
964,
14,
1095,
63,
633,
12,
1166,
9,
421,
199,
318,
485,
10738,
8,
3610,
12,
12011,
304,
272,
1338,
275,
3842,
475,
63,
2394,
8,
75,
12,
12011,
395,
370,
63,
2394,
8,
86,
12,
12011,
430,
1598,
367,
1022,
12,
8118,
315,
5412,
1598,
367,
373,
315,
334,
3122,
340,
365,
63,
513,
2930,
8,
3122,
9,
587,
359,
3122,
12457,
272,
372,
16511,
8,
1459,
12,
886,
3610,
29,
17,
9,
421,
199,
318,
485,
362,
63,
964,
8,
1310,
12,
1824,
354,
12,
1824,
344,
12,
1824,
1955,
12,
1824,
8006,
304,
272,
408,
6591,
314,
1824,
1819,
408,
272,
1318,
275,
1177,
14,
2030,
63,
305,
63,
2975,
342,
272,
1738,
275,
1218,
63,
1231,
63,
932,
8,
505,
12,
14490,
14,
1360,
14,
27375,
12,
1300,
63,
633,
29,
1310,
14,
633,
9,
272,
4513,
275,
1738,
14,
8006,
15079,
964,
358,
272,
340,
440,
4513,
26,
267,
746,
1722,
480,
1944,
665,
964,
30,
1819,
1911,
315,
450,
83,
2,
450,
1177,
9,
339,
340,
1824,
354,
365,
440,
488,
26,
267,
289,
275,
1738,
14,
8006,
15079,
964,
14251,
354,
5961,
83,
937,
7,
450,
1824,
354,
9,
267,
340,
289,
26,
288,
372,
289,
59,
16,
61,
339,
340,
1824,
344,
365,
440,
488,
26,
267,
289,
275,
1738,
14,
8006,
15079,
964,
14251,
344,
5961,
83,
937,
7,
450,
1824,
344,
9,
267,
340,
289,
26,
288,
372,
289,
59,
16,
61,
15567,
327,
2372,
1824,
1819,
687,
14462,
12,
340,
440,
1911,
12,
2621,
1536,
272,
340,
1824,
8006,
365,
440,
488,
26,
267,
3380,
275,
1738,
14,
8006,
8,
964,
8006,
9,
267,
340,
3380,
26,
288,
579,
275,
3380,
59,
16,
61,
288,
1830,
715,
26,
355,
340,
579,
14,
1450,
508,
283,
964,
356,
490,
372,
579,
355,
579,
275,
579,
14,
362,
1708,
342,
355,
340,
579,
365,
488,
26,
490,
2059,
267,
746,
1722,
360,
1944,
665,
964,
30,
1819,
1911,
543,
450,
83,
7,
450,
1824,
8006,
9,
339,
327,
982,
781,
664,
2348,
12,
652,
4910,
626,
1902,
1824,
354,
1990,
488,
272,
327,
503,
3866,
272,
340,
1824,
1955,
365,
440,
488,
26,
267,
862,
26,
288,
1824,
275,
4513,
59,
964,
1955,
61,
267,
871,
7888,
26,
288,
746,
7888,
480,
2821,
1329,
450,
68,
440,
1911,
315,
450,
83,
2,
450,
2490,
334,
964,
1955,
12,
1177,
430,
267,
587,
26,
288,
372,
1824,
421,
199,
318,
485,
362,
63,
3711,
8,
964,
12,
1824,
576,
12,
21542,
63,
4891,
12,
8968,
576,
12,
1177,
304,
272,
862,
26,
267,
1824,
576,
275,
1211,
8,
30942,
503,
14515,
272,
871,
334,
3393,
12,
3146,
304,
267,
746,
1722,
360,
30942,
1077,
506,
282,
1211,
503,
6076,
402,
6346,
358,
339,
4153,
275,
1824,
14,
8006,
360,
31759,
447,
20895,
7,
717,
11280,
31759,
447,
2416,
7,
717,
11280,
31759,
447,
1210,
14251,
466,
1,
628,
7275,
2,
436,
768,
466,
1,
628,
1569,
2,
436,
768,
466,
1,
628,
3958,
4507,
717,
283,
460,
3666,
32,
466,
1,
628,
13456,
2,
436,
768,
466,
1,
628,
11905,
531,
503,
768,
10718,
1874,
358,
272,
1338,
275,
3842,
75,
12,
399,
891,
340,
373,
365,
488,
587,
373,
9,
1598,
367,
1022,
12
] |
[
199,
2765,
859,
9031,
314,
8204,
2017,
1021,
1314,
365,
282,
1655,
22700,
1021,
199,
8,
13797,
4784,
9,
370,
3550,
20260,
4079,
641,
1824,
666,
14,
199,
199,
9295,
3794,
315,
9149,
15,
11299,
15,
1069,
13,
1310,
14,
8332,
199,
624,
199,
199,
504,
3816,
14,
4912,
14,
4078,
14,
1122,
492,
20818,
12,
16511,
199,
646,
14490,
14,
1360,
199,
504,
2198,
76,
14,
6662,
492,
1218,
63,
1231,
63,
932,
199,
646,
3816,
199,
504,
18918,
14,
1014,
14,
1069,
492,
4784,
199,
504,
18918,
14,
1208,
14,
1548,
492,
370,
63,
2394,
12,
365,
63,
513,
2930,
421,
199,
533,
8204,
2017,
8,
2017,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1824,
576,
275,
2074,
14,
1935,
360,
30942,
297,
488,
9,
267,
340,
1824,
576,
436,
2074,
14,
362,
360,
765,
358,
365,
488,
26,
288,
2074,
459,
765,
418,
275,
283,
4030,
7,
398,
1613,
8,
2821,
2017,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
398,
340,
1824,
576,
26,
288,
2974,
275,
1824,
576,
14,
1744,
342,
340,
1228,
8,
30942,
12,
1211,
9,
587,
1824,
576,
288,
1827,
495,
275,
485,
10738,
8,
1744,
12,
291,
14,
2991,
9,
288,
340,
291,
14,
765,
508,
283,
4030,
356,
355,
291,
14,
2139,
14,
5486,
8,
66,
7,
2714,
13,
804,
297,
330,
7,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
358,
355,
291,
423,
409,
63,
2030,
8,
1131,
495,
9,
288,
587,
26,
355,
291,
423,
409,
63,
633,
8,
277,
14,
633,
435,
661,
6,
7,
340,
15539,
315,
291,
14,
633,
587,
8720,
358,
435,
1827,
495,
9,
339,
768,
3744,
272,
347,
687,
63,
1310,
8,
1886,
12,
1177,
12,
1824,
354,
29,
403,
12,
1824,
344,
29,
403,
12,
1824,
1955,
29,
16,
12,
1824,
576,
29,
403,
12,
1993,
8968,
576,
29,
403,
12,
21542,
63,
4891,
29,
797,
12,
1824,
8006,
29,
403,
12,
1011,
958,
304,
267,
2074,
14,
5486,
360,
2991,
297,
1177,
14,
2991,
9,
267,
1824,
275,
485,
362,
63,
964,
8,
1310,
12,
1824,
354,
12,
1824,
344,
12,
1824,
1955,
12,
1824,
8006,
9,
267,
1824,
576,
275,
485,
362,
63,
3711,
8,
964,
12,
1824,
576,
12,
21542,
63,
4891,
12,
8968,
576,
12,
1177,
9,
267,
1166,
275,
485,
362,
63,
964,
63,
633,
8,
964,
12,
2074,
14,
1935,
360,
633,
297,
488,
430,
267,
1083,
275,
2074,
14,
1935,
360,
765,
297,
1824,
14,
765,
9,
267,
372,
843,
8,
633,
29,
633,
12,
1083,
29,
765,
12,
1824,
576,
29,
30942,
12,
1011,
958,
9,
421,
199,
318,
485,
362,
63,
964,
63,
633,
8,
964,
12,
1166,
304,
272,
340,
1166,
365,
488,
26,
267,
372,
1824,
14,
1287,
503,
1824,
14,
1095,
63,
633,
272,
372,
20818,
8,
964,
14,
1095,
63,
633,
12,
1166,
9,
421,
199,
318,
485,
10738,
8,
3610,
12,
12011,
304,
272,
1338,
275,
3842,
475,
63,
2394,
8,
75,
12,
12011,
395,
370,
63,
2394,
8,
86,
12,
12011,
430,
1598,
367,
1022,
12,
8118,
315,
5412,
1598,
367,
373,
315,
334,
3122,
340,
365,
63,
513,
2930,
8,
3122,
9,
587,
359,
3122,
12457,
272,
372,
16511,
8,
1459,
12,
886,
3610,
29,
17,
9,
421,
199,
318,
485,
362,
63,
964,
8,
1310,
12,
1824,
354,
12,
1824,
344,
12,
1824,
1955,
12,
1824,
8006,
304,
272,
408,
6591,
314,
1824,
1819,
408,
272,
1318,
275,
1177,
14,
2030,
63,
305,
63,
2975,
342,
272,
1738,
275,
1218,
63,
1231,
63,
932,
8,
505,
12,
14490,
14,
1360,
14,
27375,
12,
1300,
63,
633,
29,
1310,
14,
633,
9,
272,
4513,
275,
1738,
14,
8006,
15079,
964,
358,
272,
340,
440,
4513,
26,
267,
746,
1722,
480,
1944,
665,
964,
30,
1819,
1911,
315,
450,
83,
2,
450,
1177,
9,
339,
340,
1824,
354,
365,
440,
488,
26,
267,
289,
275,
1738,
14,
8006,
15079,
964,
14251,
354,
5961,
83,
937,
7,
450,
1824,
354,
9,
267,
340,
289,
26,
288,
372,
289,
59,
16,
61,
339,
340,
1824,
344,
365,
440,
488,
26,
267,
289,
275,
1738,
14,
8006,
15079,
964,
14251,
344,
5961,
83,
937,
7,
450,
1824,
344,
9,
267,
340,
289,
26,
288,
372,
289,
59,
16,
61,
15567,
327,
2372,
1824,
1819,
687,
14462,
12,
340,
440,
1911,
12,
2621,
1536,
272,
340,
1824,
8006,
365,
440,
488,
26,
267,
3380,
275,
1738,
14,
8006,
8,
964,
8006,
9,
267,
340,
3380,
26,
288,
579,
275,
3380,
59,
16,
61,
288,
1830,
715,
26,
355,
340,
579,
14,
1450,
508,
283,
964,
356,
490,
372,
579,
355,
579,
275,
579,
14,
362,
1708,
342,
355,
340,
579,
365,
488,
26,
490,
2059,
267,
746,
1722,
360,
1944,
665,
964,
30,
1819,
1911,
543,
450,
83,
7,
450,
1824,
8006,
9,
339,
327,
982,
781,
664,
2348,
12,
652,
4910,
626,
1902,
1824,
354,
1990,
488,
272,
327,
503,
3866,
272,
340,
1824,
1955,
365,
440,
488,
26,
267,
862,
26,
288,
1824,
275,
4513,
59,
964,
1955,
61,
267,
871,
7888,
26,
288,
746,
7888,
480,
2821,
1329,
450,
68,
440,
1911,
315,
450,
83,
2,
450,
2490,
334,
964,
1955,
12,
1177,
430,
267,
587,
26,
288,
372,
1824,
421,
199,
318,
485,
362,
63,
3711,
8,
964,
12,
1824,
576,
12,
21542,
63,
4891,
12,
8968,
576,
12,
1177,
304,
272,
862,
26,
267,
1824,
576,
275,
1211,
8,
30942,
503,
14515,
272,
871,
334,
3393,
12,
3146,
304,
267,
746,
1722,
360,
30942,
1077,
506,
282,
1211,
503,
6076,
402,
6346,
358,
339,
4153,
275,
1824,
14,
8006,
360,
31759,
447,
20895,
7,
717,
11280,
31759,
447,
2416,
7,
717,
11280,
31759,
447,
1210,
14251,
466,
1,
628,
7275,
2,
436,
768,
466,
1,
628,
1569,
2,
436,
768,
466,
1,
628,
3958,
4507,
717,
283,
460,
3666,
32,
466,
1,
628,
13456,
2,
436,
768,
466,
1,
628,
11905,
531,
503,
768,
10718,
1874,
358,
272,
1338,
275,
3842,
75,
12,
399,
891,
340,
373,
365,
488,
587,
373,
9,
1598,
367,
1022,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
InakiZabala/odoomrp-wip
|
procurement_orderpoint_no_confirm/__openerp__.py
|
27
|
1348
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
##############################################################################
{
"name": "Procurement Orderpoint No Confirm",
"version": "1.0",
"depends": ["stock"],
"author": "OdooMRP team,"
"AvanzOSC,"
"Serv. Tecnol. Avanzados - Pedro M. Baeza",
"contributors": [
"Ainara Galdona <ainaragaldona@avanzosc.es>",
"Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>",
"Ana Juaristi <anajuaristi@avanzosc.es>",
],
"category": "Procurement",
'installable': True,
'auto_install': False,
}
|
agpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
199,
3,
259,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
8083,
199,
3,
199,
4605,
199,
199,
91,
272,
298,
354,
582,
298,
15019,
10984,
9240,
1403,
3091,
32112,
401,
272,
298,
1023,
582,
298,
17,
14,
16,
401,
272,
298,
8912,
582,
2097,
6088,
2255,
272,
298,
2502,
582,
298,
47,
16766,
45,
18612,
8099,
4589,
1598,
298,
6651,
290,
90,
31799,
4589,
1598,
298,
1505,
86,
14,
377,
825,
78,
393,
14,
16599,
290,
90,
20257,
446,
510,
379,
293,
603,
14,
699,
3624,
8076,
401,
272,
298,
21630,
582,
359,
267,
298,
33,
262,
17956,
598,
279,
13196,
65,
665,
1581,
285,
643,
279,
13196,
65,
32,
1214,
290,
18070,
551,
14,
397,
7166,
267,
298,
48,
379,
293,
603,
14,
699,
3624,
8076,
665,
1915,
293,
14,
28363,
8076,
32,
332,
433,
559,
736,
28363,
8076,
14,
957,
7166,
267,
298,
2493,
65,
1603,
85,
285,
631,
73,
665,
6738,
27764,
285,
631,
73,
32,
1214,
290,
18070,
551,
14,
397,
7166,
272,
2156,
272,
298,
3710,
582,
298,
15019,
10984,
401,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
199,
3,
259,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
8083,
199,
3,
199,
4605,
199,
199,
91,
272,
298,
354,
582,
298,
15019,
10984,
9240,
1403,
3091,
32112,
401,
272,
298,
1023,
582,
298,
17,
14,
16,
401,
272,
298,
8912,
582,
2097,
6088,
2255,
272,
298,
2502,
582,
298,
47,
16766,
45,
18612,
8099,
4589,
1598,
298,
6651,
290,
90,
31799,
4589,
1598,
298,
1505,
86,
14,
377,
825,
78,
393,
14,
16599,
290,
90,
20257,
446,
510,
379,
293,
603,
14,
699,
3624,
8076,
401,
272,
298,
21630,
582,
359,
267,
298,
33,
262,
17956,
598,
279,
13196,
65,
665,
1581,
285,
643,
279,
13196,
65,
32,
1214,
290,
18070,
551,
14,
397,
7166,
267,
298,
48,
379,
293,
603,
14,
699,
3624,
8076,
665,
1915,
293,
14,
28363,
8076,
32,
332,
433,
559,
736,
28363,
8076,
14,
957,
7166,
267,
298,
2493,
65,
1603,
85,
285,
631,
73,
665,
6738,
27764,
285,
631,
73,
32,
1214,
290,
18070,
551,
14,
397,
7166,
272,
2156,
272,
298,
3710,
582,
298,
15019,
10984,
401,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
axinging/chromium-crosswalk
|
third_party/WebKit/LayoutTests/PRESUBMIT.py
|
3
|
2808
|
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""LayoutTests/ presubmit script for Blink.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into gcl.
"""
import filecmp
def _CheckTestharnessResults(input_api, output_api):
expected_files = [f.AbsoluteLocalPath() for f in input_api.AffectedFiles() if f.LocalPath().endswith('-expected.txt') and f.Action() != 'D']
if len(expected_files) == 0:
return []
checker_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
'..', 'Tools', 'Scripts', 'check-testharness-expected-pass')
args = [input_api.python_executable, checker_path]
args.extend(expected_files)
_, errs = input_api.subprocess.Popen(args,
stdout=input_api.subprocess.PIPE,
stderr=input_api.subprocess.PIPE).communicate()
if errs:
return [output_api.PresubmitError(errs)]
return []
def _CheckIdenticalFiles(input_api, output_api):
"""Verifies that certain files are identical in various locations.
These files should always be updated together."""
dirty_files = set(input_api.LocalPaths())
groups = [[
'imported/web-platform-tests/resources/testharness.js',
'resources/testharness.js',
], [
'imported/web-platform-tests/resources/testharnessreport.js',
'resources/testharnessreport.js',
], [
'imported/web-platform-tests/resources/idlharness.js',
'resources/idlharness.js',
]]
def _absolute_path(s):
return input_api.os_path.join(input_api.PresubmitLocalPath(), *s.split('/'))
def _local_path(s):
return input_api.os_path.join('third_party', 'WebKit', 'LayoutTests', *s.split('/'))
errors = []
for group in groups:
if any(_local_path(p) in dirty_files for p in group):
a = group[0]
for b in group[1:]:
if not filecmp.cmp(_absolute_path(a), _absolute_path(b), shallow=False):
errors.append(output_api.PresubmitError(
'Files that should match differ: (see https://crbug.com/362788)\n' +
' %s <=> %s' % (_local_path(a), _local_path(b))))
return errors
def CheckChangeOnUpload(input_api, output_api):
results = []
results.extend(_CheckTestharnessResults(input_api, output_api))
results.extend(_CheckIdenticalFiles(input_api, output_api))
return results
def CheckChangeOnCommit(input_api, output_api):
results = []
results.extend(_CheckTestharnessResults(input_api, output_api))
results.extend(_CheckIdenticalFiles(input_api, output_api))
return results
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
4798,
2925,
15,
23895,
2884,
367,
699,
1073,
14,
199,
199,
9295,
1455,
921,
2374,
14,
13211,
14,
1308,
15,
23826,
15,
1917,
13,
14543,
15,
27834,
2537,
15,
80,
15527,
13,
6429,
199,
509,
1655,
2436,
3595,
314,
23895,
3261,
6137,
1901,
486,
429,
14,
199,
624,
199,
199,
646,
570,
5730,
421,
199,
318,
485,
1799,
774,
23569,
6579,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
272,
1420,
63,
1725,
275,
359,
70,
14,
24677,
26453,
342,
367,
289,
315,
1324,
63,
1246,
14,
19256,
6201,
5535,
342,
340,
289,
14,
26453,
1252,
4130,
3654,
2062,
14,
2424,
358,
436,
289,
14,
3310,
342,
1137,
283,
36,
418,
272,
340,
822,
8,
2062,
63,
1725,
9,
508,
378,
26,
267,
372,
942,
339,
7739,
63,
515,
275,
1324,
63,
1246,
14,
736,
63,
515,
14,
904,
8,
1210,
63,
1246,
14,
30607,
26453,
1062,
267,
19155,
283,
11654,
297,
283,
25681,
297,
283,
1074,
13,
396,
23569,
13,
2062,
13,
1529,
358,
339,
1249,
275,
359,
1210,
63,
1246,
14,
1548,
63,
5904,
12,
7739,
63,
515,
61,
272,
1249,
14,
2880,
8,
2062,
63,
1725,
9,
272,
5501,
2329,
83,
275,
1324,
63,
1246,
14,
5781,
14,
7942,
8,
589,
12,
267,
3839,
29,
1210,
63,
1246,
14,
5781,
14,
6089,
12,
267,
4635,
29,
1210,
63,
1246,
14,
5781,
14,
6089,
680,
10664,
342,
272,
340,
2329,
83,
26,
267,
372,
359,
1199,
63,
1246,
14,
30607,
547,
8,
1508,
83,
1874,
272,
372,
942,
421,
199,
318,
485,
1799,
22469,
5535,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
272,
408,
21168,
626,
9842,
1584,
787,
13130,
315,
7750,
9918,
14,
272,
5723,
1584,
1077,
3544,
506,
4588,
10451,
1041,
339,
14650,
63,
1725,
275,
663,
8,
1210,
63,
1246,
14,
5339,
11804,
1012,
339,
4652,
275,
3474,
267,
283,
17932,
15,
2520,
13,
3246,
13,
2219,
15,
4435,
15,
396,
23569,
14,
3596,
297,
267,
283,
4435,
15,
396,
23569,
14,
3596,
297,
272,
2156,
359,
267,
283,
17932,
15,
2520,
13,
3246,
13,
2219,
15,
4435,
15,
396,
23569,
3070,
14,
3596,
297,
267,
283,
4435,
15,
396,
23569,
3070,
14,
3596,
297,
272,
2156,
359,
267,
283,
17932,
15,
2520,
13,
3246,
13,
2219,
15,
4435,
15,
13398,
23569,
14,
3596,
297,
267,
283,
4435,
15,
13398,
23569,
14,
3596,
297,
272,
1622,
61,
339,
347,
485,
6116,
63,
515,
8,
83,
304,
267,
372,
1324,
63,
1246,
14,
736,
63,
515,
14,
904,
8,
1210,
63,
1246,
14,
30607,
26453,
1062,
627,
83,
14,
1294,
28684,
339,
347,
485,
1832,
63,
515,
8,
83,
304,
267,
372,
1324,
63,
1246,
14,
736,
63,
515,
14,
904,
360,
11470,
63,
7522,
297,
283,
21666,
297,
283,
4798,
2925,
297,
627,
83,
14,
1294,
28684,
339,
2552,
275,
942,
272,
367,
1572,
315,
4652,
26,
267,
340,
1263,
1547,
1832,
63,
515,
8,
80,
9,
315,
14650,
63,
1725,
367,
299,
315,
1572,
304,
288,
282,
275,
1572,
59,
16,
61,
288,
367,
330,
315,
1572,
59,
17,
10688,
355,
340,
440,
570,
5730,
14,
5730,
1547,
6116,
63,
515,
8,
65,
395,
485,
6116,
63,
515,
8,
66,
395,
23834,
29,
797,
304,
490,
2552,
14,
740,
8,
1199,
63,
1246,
14,
30607,
547,
8,
717,
283,
5535,
626,
1077,
1336,
14460,
26,
334,
3239,
4178,
921,
1556,
1266,
14,
957,
15,
1344,
1465,
1299,
2862,
78,
7,
435,
717,
283,
221,
450,
83,
2695,
30,
450,
83,
7,
450,
6110,
1832,
63,
515,
8,
65,
395,
485,
1832,
63,
515,
8,
66,
7845,
272,
372,
2552,
421,
199,
318,
2670,
4001,
3314,
10301,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
272,
2058,
275,
942,
272,
2058,
14,
2880,
1547,
1799,
774,
23569,
6579,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
430,
272,
2058,
14,
2880,
1547,
1799,
22469,
5535,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
430,
272,
372,
2058,
421,
199,
318,
2670,
4001,
3314,
11421,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
272,
2058,
275,
942,
272,
2058,
14,
2880,
1547,
1799,
774,
23569,
6579,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
430,
272,
2058,
14,
2880,
1547,
1799,
22469,
5535,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
430,
272,
372,
2058,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
4798,
2925,
15,
23895,
2884,
367,
699,
1073,
14,
199,
199,
9295,
1455,
921,
2374,
14,
13211,
14,
1308,
15,
23826,
15,
1917,
13,
14543,
15,
27834,
2537,
15,
80,
15527,
13,
6429,
199,
509,
1655,
2436,
3595,
314,
23895,
3261,
6137,
1901,
486,
429,
14,
199,
624,
199,
199,
646,
570,
5730,
421,
199,
318,
485,
1799,
774,
23569,
6579,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
272,
1420,
63,
1725,
275,
359,
70,
14,
24677,
26453,
342,
367,
289,
315,
1324,
63,
1246,
14,
19256,
6201,
5535,
342,
340,
289,
14,
26453,
1252,
4130,
3654,
2062,
14,
2424,
358,
436,
289,
14,
3310,
342,
1137,
283,
36,
418,
272,
340,
822,
8,
2062,
63,
1725,
9,
508,
378,
26,
267,
372,
942,
339,
7739,
63,
515,
275,
1324,
63,
1246,
14,
736,
63,
515,
14,
904,
8,
1210,
63,
1246,
14,
30607,
26453,
1062,
267,
19155,
283,
11654,
297,
283,
25681,
297,
283,
1074,
13,
396,
23569,
13,
2062,
13,
1529,
358,
339,
1249,
275,
359,
1210,
63,
1246,
14,
1548,
63,
5904,
12,
7739,
63,
515,
61,
272,
1249,
14,
2880,
8,
2062,
63,
1725,
9,
272,
5501,
2329,
83,
275,
1324,
63,
1246,
14,
5781,
14,
7942,
8,
589,
12,
267,
3839,
29,
1210,
63,
1246,
14,
5781,
14,
6089,
12,
267,
4635,
29,
1210,
63,
1246,
14,
5781,
14,
6089,
680,
10664,
342,
272,
340,
2329,
83,
26,
267,
372,
359,
1199,
63,
1246,
14,
30607,
547,
8,
1508,
83,
1874,
272,
372,
942,
421,
199,
318,
485,
1799,
22469,
5535,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
272,
408,
21168,
626,
9842,
1584,
787,
13130,
315,
7750,
9918,
14,
272,
5723,
1584,
1077,
3544,
506,
4588,
10451,
1041,
339,
14650,
63,
1725,
275,
663,
8,
1210,
63,
1246,
14,
5339,
11804,
1012,
339,
4652,
275,
3474,
267,
283,
17932,
15,
2520,
13,
3246,
13,
2219,
15,
4435,
15,
396,
23569,
14,
3596,
297,
267,
283,
4435,
15,
396,
23569,
14,
3596,
297,
272,
2156,
359,
267,
283,
17932,
15,
2520,
13,
3246,
13,
2219,
15,
4435,
15,
396,
23569,
3070,
14,
3596,
297,
267,
283,
4435,
15,
396,
23569,
3070,
14,
3596,
297,
272,
2156,
359,
267,
283,
17932,
15,
2520,
13,
3246,
13,
2219,
15,
4435,
15,
13398,
23569,
14,
3596,
297,
267,
283,
4435,
15,
13398,
23569,
14,
3596,
297,
272,
1622,
61,
339,
347,
485,
6116,
63,
515,
8,
83,
304,
267,
372,
1324,
63,
1246,
14,
736,
63,
515,
14,
904,
8,
1210,
63,
1246,
14,
30607,
26453,
1062,
627,
83,
14,
1294,
28684,
339,
347,
485,
1832,
63,
515,
8,
83,
304,
267,
372,
1324,
63,
1246,
14,
736,
63,
515,
14,
904,
360,
11470,
63,
7522,
297,
283,
21666,
297,
283,
4798,
2925,
297,
627,
83,
14,
1294,
28684,
339,
2552,
275,
942,
272,
367,
1572,
315,
4652,
26,
267,
340,
1263,
1547,
1832,
63,
515,
8,
80,
9,
315,
14650,
63,
1725,
367,
299,
315,
1572,
304,
288,
282,
275,
1572,
59,
16,
61,
288,
367,
330,
315,
1572,
59,
17,
10688,
355,
340,
440,
570,
5730,
14,
5730,
1547,
6116,
63,
515,
8,
65,
395,
485,
6116,
63,
515,
8,
66,
395,
23834,
29,
797,
304,
490,
2552,
14,
740,
8,
1199,
63,
1246,
14,
30607,
547,
8,
717,
283,
5535,
626,
1077,
1336,
14460,
26,
334,
3239,
4178,
921,
1556,
1266,
14,
957,
15,
1344,
1465,
1299,
2862,
78,
7,
435,
717,
283,
221,
450,
83,
2695,
30,
450,
83,
7,
450,
6110,
1832,
63,
515,
8,
65,
395,
485,
1832,
63,
515,
8,
66,
7845,
272,
372,
2552,
421,
199,
318,
2670,
4001,
3314,
10301,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
272,
2058,
275,
942,
272,
2058,
14,
2880,
1547,
1799,
774,
23569,
6579,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
430,
272,
2058,
14,
2880,
1547,
1799,
22469,
5535,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
430,
272,
372,
2058,
421,
199,
318,
2670,
4001,
3314,
11421,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
272,
2058,
275,
942,
272,
2058,
14,
2880,
1547,
1799,
774,
23569,
6579,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
430,
272,
2058,
14,
2880,
1547,
1799,
22469,
5535,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
430,
272,
372,
2058,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Shouqun/node-gn
|
tools/depot_tools/third_party/mock/__init__.py
|
1
|
75516
|
# Test tools for mocking and patching.
# Copyright (C) 2007-2012 Michael Foord & the mock team
# E-mail: fuzzyman AT voidspace DOT org DOT uk
# mock 1.0
# http://www.voidspace.org.uk/python/mock/
# Released subject to the BSD License
# Please see http://www.voidspace.org.uk/python/license.shtml
# Scripts maintained at http://www.voidspace.org.uk/python/index.shtml
# Comments, suggestions and bug reports welcome.
__all__ = (
'Mock',
'MagicMock',
'patch',
'sentinel',
'DEFAULT',
'ANY',
'call',
'create_autospec',
'FILTER_DIR',
'NonCallableMock',
'NonCallableMagicMock',
'mock_open',
'PropertyMock',
)
__version__ = '1.0.1'
import pprint
import sys
try:
import inspect
except ImportError:
# for alternative platforms that
# may not have inspect
inspect = None
try:
from functools import wraps as original_wraps
except ImportError:
# Python 2.4 compatibility
def wraps(original):
def inner(f):
f.__name__ = original.__name__
f.__doc__ = original.__doc__
f.__module__ = original.__module__
f.__wrapped__ = original
return f
return inner
else:
if sys.version_info[:2] >= (3, 3):
wraps = original_wraps
else:
def wraps(func):
def inner(f):
f = original_wraps(func)(f)
f.__wrapped__ = func
return f
return inner
try:
unicode
except NameError:
# Python 3
basestring = unicode = str
try:
long
except NameError:
# Python 3
long = int
try:
BaseException
except NameError:
# Python 2.4 compatibility
BaseException = Exception
try:
next
except NameError:
def next(obj):
return obj.next()
BaseExceptions = (BaseException,)
if 'java' in sys.platform:
# jython
import java
BaseExceptions = (BaseException, java.lang.Throwable)
try:
_isidentifier = str.isidentifier
except AttributeError:
# Python 2.X
import keyword
import re
regex = re.compile(r'^[a-z_][a-z0-9_]*$', re.I)
def _isidentifier(string):
if string in keyword.kwlist:
return False
return regex.match(string)
inPy3k = sys.version_info[0] == 3
# Needed to work around Python 3 bug where use of "super" interferes with
# defining __class__ as a descriptor
_super = super
self = 'im_self'
builtin = '__builtin__'
if inPy3k:
self = '__self__'
builtin = 'builtins'
FILTER_DIR = True
def _is_instance_mock(obj):
# can't use isinstance on Mock objects because they override __class__
# The base class for all mocks is NonCallableMock
return issubclass(type(obj), NonCallableMock)
def _is_exception(obj):
return (
isinstance(obj, BaseExceptions) or
isinstance(obj, ClassTypes) and issubclass(obj, BaseExceptions)
)
class _slotted(object):
__slots__ = ['a']
DescriptorTypes = (
type(_slotted.a),
property,
)
def _getsignature(func, skipfirst, instance=False):
if inspect is None:
raise ImportError('inspect module not available')
if isinstance(func, ClassTypes) and not instance:
try:
func = func.__init__
except AttributeError:
return
skipfirst = True
elif not isinstance(func, FunctionTypes):
# for classes where instance is True we end up here too
try:
func = func.__call__
except AttributeError:
return
if inPy3k:
try:
argspec = inspect.getfullargspec(func)
except TypeError:
# C function / method, possibly inherited object().__init__
return
regargs, varargs, varkw, defaults, kwonly, kwonlydef, ann = argspec
else:
try:
regargs, varargs, varkwargs, defaults = inspect.getargspec(func)
except TypeError:
# C function / method, possibly inherited object().__init__
return
# instance methods and classmethods need to lose the self argument
if getattr(func, self, None) is not None:
regargs = regargs[1:]
if skipfirst:
# this condition and the above one are never both True - why?
regargs = regargs[1:]
if inPy3k:
signature = inspect.formatargspec(
regargs, varargs, varkw, defaults,
kwonly, kwonlydef, ann, formatvalue=lambda value: "")
else:
signature = inspect.formatargspec(
regargs, varargs, varkwargs, defaults,
formatvalue=lambda value: "")
return signature[1:-1], func
def _check_signature(func, mock, skipfirst, instance=False):
if not _callable(func):
return
result = _getsignature(func, skipfirst, instance)
if result is None:
return
signature, func = result
# can't use self because "self" is common as an argument name
# unfortunately even not in the first place
src = "lambda _mock_self, %s: None" % signature
checksig = eval(src, {})
_copy_func_details(func, checksig)
type(mock)._mock_check_sig = checksig
def _copy_func_details(func, funcopy):
funcopy.__name__ = func.__name__
funcopy.__doc__ = func.__doc__
#funcopy.__dict__.update(func.__dict__)
funcopy.__module__ = func.__module__
if not inPy3k:
funcopy.func_defaults = func.func_defaults
return
funcopy.__defaults__ = func.__defaults__
funcopy.__kwdefaults__ = func.__kwdefaults__
def _callable(obj):
if isinstance(obj, ClassTypes):
return True
if getattr(obj, '__call__', None) is not None:
return True
return False
def _is_list(obj):
# checks for list or tuples
# XXXX badly named!
return type(obj) in (list, tuple)
def _instance_callable(obj):
"""Given an object, return True if the object is callable.
For classes, return True if instances would be callable."""
if not isinstance(obj, ClassTypes):
# already an instance
return getattr(obj, '__call__', None) is not None
klass = obj
# uses __bases__ instead of __mro__ so that we work with old style classes
if klass.__dict__.get('__call__') is not None:
return True
for base in klass.__bases__:
if _instance_callable(base):
return True
return False
def _set_signature(mock, original, instance=False):
# creates a function with signature (*args, **kwargs) that delegates to a
# mock. It still does signature checking by calling a lambda with the same
# signature as the original.
if not _callable(original):
return
skipfirst = isinstance(original, ClassTypes)
result = _getsignature(original, skipfirst, instance)
if result is None:
# was a C function (e.g. object().__init__ ) that can't be mocked
return
signature, func = result
src = "lambda %s: None" % signature
checksig = eval(src, {})
_copy_func_details(func, checksig)
name = original.__name__
if not _isidentifier(name):
name = 'funcopy'
context = {'_checksig_': checksig, 'mock': mock}
src = """def %s(*args, **kwargs):
_checksig_(*args, **kwargs)
return mock(*args, **kwargs)""" % name
exec (src, context)
funcopy = context[name]
_setup_func(funcopy, mock)
return funcopy
def _setup_func(funcopy, mock):
funcopy.mock = mock
# can't use isinstance with mocks
if not _is_instance_mock(mock):
return
def assert_called_with(*args, **kwargs):
return mock.assert_called_with(*args, **kwargs)
def assert_called_once_with(*args, **kwargs):
return mock.assert_called_once_with(*args, **kwargs)
def assert_has_calls(*args, **kwargs):
return mock.assert_has_calls(*args, **kwargs)
def assert_any_call(*args, **kwargs):
return mock.assert_any_call(*args, **kwargs)
def reset_mock():
funcopy.method_calls = _CallList()
funcopy.mock_calls = _CallList()
mock.reset_mock()
ret = funcopy.return_value
if _is_instance_mock(ret) and not ret is mock:
ret.reset_mock()
funcopy.called = False
funcopy.call_count = 0
funcopy.call_args = None
funcopy.call_args_list = _CallList()
funcopy.method_calls = _CallList()
funcopy.mock_calls = _CallList()
funcopy.return_value = mock.return_value
funcopy.side_effect = mock.side_effect
funcopy._mock_children = mock._mock_children
funcopy.assert_called_with = assert_called_with
funcopy.assert_called_once_with = assert_called_once_with
funcopy.assert_has_calls = assert_has_calls
funcopy.assert_any_call = assert_any_call
funcopy.reset_mock = reset_mock
mock._mock_delegate = funcopy
def _is_magic(name):
return '__%s__' % name[2:-2] == name
class _SentinelObject(object):
"A unique, named, sentinel object."
def __init__(self, name):
self.name = name
def __repr__(self):
return 'sentinel.%s' % self.name
class _Sentinel(object):
"""Access attributes to return a named object, usable as a sentinel."""
def __init__(self):
self._sentinels = {}
def __getattr__(self, name):
if name == '__bases__':
# Without this help(mock) raises an exception
raise AttributeError
return self._sentinels.setdefault(name, _SentinelObject(name))
sentinel = _Sentinel()
DEFAULT = sentinel.DEFAULT
_missing = sentinel.MISSING
_deleted = sentinel.DELETED
class OldStyleClass:
pass
ClassType = type(OldStyleClass)
def _copy(value):
if type(value) in (dict, list, tuple, set):
return type(value)(value)
return value
ClassTypes = (type,)
if not inPy3k:
ClassTypes = (type, ClassType)
_allowed_names = set(
[
'return_value', '_mock_return_value', 'side_effect',
'_mock_side_effect', '_mock_parent', '_mock_new_parent',
'_mock_name', '_mock_new_name'
]
)
def _delegating_property(name):
_allowed_names.add(name)
_the_name = '_mock_' + name
def _get(self, name=name, _the_name=_the_name):
sig = self._mock_delegate
if sig is None:
return getattr(self, _the_name)
return getattr(sig, name)
def _set(self, value, name=name, _the_name=_the_name):
sig = self._mock_delegate
if sig is None:
self.__dict__[_the_name] = value
else:
setattr(sig, name, value)
return property(_get, _set)
class _CallList(list):
def __contains__(self, value):
if not isinstance(value, list):
return list.__contains__(self, value)
len_value = len(value)
len_self = len(self)
if len_value > len_self:
return False
for i in range(0, len_self - len_value + 1):
sub_list = self[i:i+len_value]
if sub_list == value:
return True
return False
def __repr__(self):
return pprint.pformat(list(self))
def _check_and_set_parent(parent, value, name, new_name):
if not _is_instance_mock(value):
return False
if ((value._mock_name or value._mock_new_name) or
(value._mock_parent is not None) or
(value._mock_new_parent is not None)):
return False
_parent = parent
while _parent is not None:
# setting a mock (value) as a child or return value of itself
# should not modify the mock
if _parent is value:
return False
_parent = _parent._mock_new_parent
if new_name:
value._mock_new_parent = parent
value._mock_new_name = new_name
if name:
value._mock_parent = parent
value._mock_name = name
return True
class Base(object):
_mock_return_value = DEFAULT
_mock_side_effect = None
def __init__(self, *args, **kwargs):
pass
class NonCallableMock(Base):
"""A non-callable version of `Mock`"""
def __new__(cls, *args, **kw):
# every instance has its own class
# so we can create magic methods on the
# class without stomping on other mocks
new = type(cls.__name__, (cls,), {'__doc__': cls.__doc__})
instance = object.__new__(new)
return instance
def __init__(
self, spec=None, wraps=None, name=None, spec_set=None,
parent=None, _spec_state=None, _new_name='', _new_parent=None,
**kwargs
):
if _new_parent is None:
_new_parent = parent
__dict__ = self.__dict__
__dict__['_mock_parent'] = parent
__dict__['_mock_name'] = name
__dict__['_mock_new_name'] = _new_name
__dict__['_mock_new_parent'] = _new_parent
if spec_set is not None:
spec = spec_set
spec_set = True
self._mock_add_spec(spec, spec_set)
__dict__['_mock_children'] = {}
__dict__['_mock_wraps'] = wraps
__dict__['_mock_delegate'] = None
__dict__['_mock_called'] = False
__dict__['_mock_call_args'] = None
__dict__['_mock_call_count'] = 0
__dict__['_mock_call_args_list'] = _CallList()
__dict__['_mock_mock_calls'] = _CallList()
__dict__['method_calls'] = _CallList()
if kwargs:
self.configure_mock(**kwargs)
_super(NonCallableMock, self).__init__(
spec, wraps, name, spec_set, parent,
_spec_state
)
def attach_mock(self, mock, attribute):
"""
Attach a mock as an attribute of this one, replacing its name and
parent. Calls to the attached mock will be recorded in the
`method_calls` and `mock_calls` attributes of this one."""
mock._mock_parent = None
mock._mock_new_parent = None
mock._mock_name = ''
mock._mock_new_name = None
setattr(self, attribute, mock)
def mock_add_spec(self, spec, spec_set=False):
"""Add a spec to a mock. `spec` can either be an object or a
list of strings. Only attributes on the `spec` can be fetched as
attributes from the mock.
If `spec_set` is True then only attributes on the spec can be set."""
self._mock_add_spec(spec, spec_set)
def _mock_add_spec(self, spec, spec_set):
_spec_class = None
if spec is not None and not _is_list(spec):
if isinstance(spec, ClassTypes):
_spec_class = spec
else:
_spec_class = _get_class(spec)
spec = dir(spec)
__dict__ = self.__dict__
__dict__['_spec_class'] = _spec_class
__dict__['_spec_set'] = spec_set
__dict__['_mock_methods'] = spec
def __get_return_value(self):
ret = self._mock_return_value
if self._mock_delegate is not None:
ret = self._mock_delegate.return_value
if ret is DEFAULT:
ret = self._get_child_mock(
_new_parent=self, _new_name='()'
)
self.return_value = ret
return ret
def __set_return_value(self, value):
if self._mock_delegate is not None:
self._mock_delegate.return_value = value
else:
self._mock_return_value = value
_check_and_set_parent(self, value, None, '()')
__return_value_doc = "The value to be returned when the mock is called."
return_value = property(__get_return_value, __set_return_value,
__return_value_doc)
@property
def __class__(self):
if self._spec_class is None:
return type(self)
return self._spec_class
called = _delegating_property('called')
call_count = _delegating_property('call_count')
call_args = _delegating_property('call_args')
call_args_list = _delegating_property('call_args_list')
mock_calls = _delegating_property('mock_calls')
def __get_side_effect(self):
sig = self._mock_delegate
if sig is None:
return self._mock_side_effect
return sig.side_effect
def __set_side_effect(self, value):
value = _try_iter(value)
sig = self._mock_delegate
if sig is None:
self._mock_side_effect = value
else:
sig.side_effect = value
side_effect = property(__get_side_effect, __set_side_effect)
def reset_mock(self):
"Restore the mock object to its initial state."
self.called = False
self.call_args = None
self.call_count = 0
self.mock_calls = _CallList()
self.call_args_list = _CallList()
self.method_calls = _CallList()
for child in self._mock_children.values():
if isinstance(child, _SpecState):
continue
child.reset_mock()
ret = self._mock_return_value
if _is_instance_mock(ret) and ret is not self:
ret.reset_mock()
def configure_mock(self, **kwargs):
"""Set attributes on the mock through keyword arguments.
Attributes plus return values and side effects can be set on child
mocks using standard dot notation and unpacking a dictionary in the
method call:
>>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
>>> mock.configure_mock(**attrs)"""
for arg, val in sorted(kwargs.items(),
# we sort on the number of dots so that
# attributes are set before we set attributes on
# attributes
key=lambda entry: entry[0].count('.')):
args = arg.split('.')
final = args.pop()
obj = self
for entry in args:
obj = getattr(obj, entry)
setattr(obj, final, val)
def __getattr__(self, name):
if name == '_mock_methods':
raise AttributeError(name)
elif self._mock_methods is not None:
if name not in self._mock_methods or name in _all_magics:
raise AttributeError("Mock object has no attribute %r" % name)
elif _is_magic(name):
raise AttributeError(name)
result = self._mock_children.get(name)
if result is _deleted:
raise AttributeError(name)
elif result is None:
wraps = None
if self._mock_wraps is not None:
# XXXX should we get the attribute without triggering code
# execution?
wraps = getattr(self._mock_wraps, name)
result = self._get_child_mock(
parent=self, name=name, wraps=wraps, _new_name=name,
_new_parent=self
)
self._mock_children[name] = result
elif isinstance(result, _SpecState):
result = create_autospec(
result.spec, result.spec_set, result.instance,
result.parent, result.name
)
self._mock_children[name] = result
return result
def __repr__(self):
_name_list = [self._mock_new_name]
_parent = self._mock_new_parent
last = self
dot = '.'
if _name_list == ['()']:
dot = ''
seen = set()
while _parent is not None:
last = _parent
_name_list.append(_parent._mock_new_name + dot)
dot = '.'
if _parent._mock_new_name == '()':
dot = ''
_parent = _parent._mock_new_parent
# use ids here so as not to call __hash__ on the mocks
if id(_parent) in seen:
break
seen.add(id(_parent))
_name_list = list(reversed(_name_list))
_first = last._mock_name or 'mock'
if len(_name_list) > 1:
if _name_list[1] not in ('()', '().'):
_first += '.'
_name_list[0] = _first
name = ''.join(_name_list)
name_string = ''
if name not in ('mock', 'mock.'):
name_string = ' name=%r' % name
spec_string = ''
if self._spec_class is not None:
spec_string = ' spec=%r'
if self._spec_set:
spec_string = ' spec_set=%r'
spec_string = spec_string % self._spec_class.__name__
return "<%s%s%s id='%s'>" % (
type(self).__name__,
name_string,
spec_string,
id(self)
)
def __dir__(self):
"""Filter the output of `dir(mock)` to only useful members.
XXXX
"""
extras = self._mock_methods or []
from_type = dir(type(self))
from_dict = list(self.__dict__)
if FILTER_DIR:
from_type = [e for e in from_type if not e.startswith('_')]
from_dict = [e for e in from_dict if not e.startswith('_') or
_is_magic(e)]
return sorted(set(extras + from_type + from_dict +
list(self._mock_children)))
def __setattr__(self, name, value):
if name in _allowed_names:
# property setters go through here
return object.__setattr__(self, name, value)
elif (self._spec_set and self._mock_methods is not None and
name not in self._mock_methods and
name not in self.__dict__):
raise AttributeError("Mock object has no attribute '%s'" % name)
elif name in _unsupported_magics:
msg = 'Attempting to set unsupported magic method %r.' % name
raise AttributeError(msg)
elif name in _all_magics:
if self._mock_methods is not None and name not in self._mock_methods:
raise AttributeError("Mock object has no attribute '%s'" % name)
if not _is_instance_mock(value):
setattr(type(self), name, _get_method(name, value))
original = value
value = lambda *args, **kw: original(self, *args, **kw)
else:
# only set _new_name and not name so that mock_calls is tracked
# but not method calls
_check_and_set_parent(self, value, None, name)
setattr(type(self), name, value)
self._mock_children[name] = value
elif name == '__class__':
self._spec_class = value
return
else:
if _check_and_set_parent(self, value, name, name):
self._mock_children[name] = value
return object.__setattr__(self, name, value)
def __delattr__(self, name):
if name in _all_magics and name in type(self).__dict__:
delattr(type(self), name)
if name not in self.__dict__:
# for magic methods that are still MagicProxy objects and
# not set on the instance itself
return
if name in self.__dict__:
object.__delattr__(self, name)
obj = self._mock_children.get(name, _missing)
if obj is _deleted:
raise AttributeError(name)
if obj is not _missing:
del self._mock_children[name]
self._mock_children[name] = _deleted
def _format_mock_call_signature(self, args, kwargs):
name = self._mock_name or 'mock'
return _format_call_signature(name, args, kwargs)
def _format_mock_failure_message(self, args, kwargs):
message = 'Expected call: %s\nActual call: %s'
expected_string = self._format_mock_call_signature(args, kwargs)
call_args = self.call_args
if len(call_args) == 3:
call_args = call_args[1:]
actual_string = self._format_mock_call_signature(*call_args)
return message % (expected_string, actual_string)
def assert_called_with(_mock_self, *args, **kwargs):
"""assert that the mock was called with the specified arguments.
Raises an AssertionError if the args and keyword args passed in are
different to the last call to the mock."""
self = _mock_self
if self.call_args is None:
expected = self._format_mock_call_signature(args, kwargs)
raise AssertionError('Expected call: %s\nNot called' % (expected,))
if self.call_args != (args, kwargs):
msg = self._format_mock_failure_message(args, kwargs)
raise AssertionError(msg)
def assert_called_once_with(_mock_self, *args, **kwargs):
"""assert that the mock was called exactly once and with the specified
arguments."""
self = _mock_self
if not self.call_count == 1:
msg = ("Expected to be called once. Called %s times." %
self.call_count)
raise AssertionError(msg)
return self.assert_called_with(*args, **kwargs)
def assert_has_calls(self, calls, any_order=False):
"""assert the mock has been called with the specified calls.
The `mock_calls` list is checked for the calls.
If `any_order` is False (the default) then the calls must be
sequential. There can be extra calls before or after the
specified calls.
If `any_order` is True then the calls can be in any order, but
they must all appear in `mock_calls`."""
if not any_order:
if calls not in self.mock_calls:
raise AssertionError(
'Calls not found.\nExpected: %r\n'
'Actual: %r' % (calls, self.mock_calls)
)
return
all_calls = list(self.mock_calls)
not_found = []
for kall in calls:
try:
all_calls.remove(kall)
except ValueError:
not_found.append(kall)
if not_found:
raise AssertionError(
'%r not all found in call list' % (tuple(not_found),)
)
def assert_any_call(self, *args, **kwargs):
"""assert the mock has been called with the specified arguments.
The assert passes if the mock has *ever* been called, unlike
`assert_called_with` and `assert_called_once_with` that only pass if
the call is the most recent one."""
kall = call(*args, **kwargs)
if kall not in self.call_args_list:
expected_string = self._format_mock_call_signature(args, kwargs)
raise AssertionError(
'%s call not found' % expected_string
)
def _get_child_mock(self, **kw):
"""Create the child mocks for attributes and return value.
By default child mocks will be the same type as the parent.
Subclasses of Mock may want to override this to customize the way
child mocks are made.
For non-callable mocks the callable variant will be used (rather than
any custom subclass)."""
_type = type(self)
if not issubclass(_type, CallableMixin):
if issubclass(_type, NonCallableMagicMock):
klass = MagicMock
elif issubclass(_type, NonCallableMock) :
klass = Mock
else:
klass = _type.__mro__[1]
return klass(**kw)
def _try_iter(obj):
if obj is None:
return obj
if _is_exception(obj):
return obj
if _callable(obj):
return obj
try:
return iter(obj)
except TypeError:
# XXXX backwards compatibility
# but this will blow up on first call - so maybe we should fail early?
return obj
class CallableMixin(Base):
def __init__(self, spec=None, side_effect=None, return_value=DEFAULT,
wraps=None, name=None, spec_set=None, parent=None,
_spec_state=None, _new_name='', _new_parent=None, **kwargs):
self.__dict__['_mock_return_value'] = return_value
_super(CallableMixin, self).__init__(
spec, wraps, name, spec_set, parent,
_spec_state, _new_name, _new_parent, **kwargs
)
self.side_effect = side_effect
def _mock_check_sig(self, *args, **kwargs):
# stub method that can be replaced with one with a specific signature
pass
def __call__(_mock_self, *args, **kwargs):
# can't use self in-case a function / method we are mocking uses self
# in the signature
_mock_self._mock_check_sig(*args, **kwargs)
return _mock_self._mock_call(*args, **kwargs)
def _mock_call(_mock_self, *args, **kwargs):
self = _mock_self
self.called = True
self.call_count += 1
self.call_args = _Call((args, kwargs), two=True)
self.call_args_list.append(_Call((args, kwargs), two=True))
_new_name = self._mock_new_name
_new_parent = self._mock_new_parent
self.mock_calls.append(_Call(('', args, kwargs)))
seen = set()
skip_next_dot = _new_name == '()'
do_method_calls = self._mock_parent is not None
name = self._mock_name
while _new_parent is not None:
this_mock_call = _Call((_new_name, args, kwargs))
if _new_parent._mock_new_name:
dot = '.'
if skip_next_dot:
dot = ''
skip_next_dot = False
if _new_parent._mock_new_name == '()':
skip_next_dot = True
_new_name = _new_parent._mock_new_name + dot + _new_name
if do_method_calls:
if _new_name == name:
this_method_call = this_mock_call
else:
this_method_call = _Call((name, args, kwargs))
_new_parent.method_calls.append(this_method_call)
do_method_calls = _new_parent._mock_parent is not None
if do_method_calls:
name = _new_parent._mock_name + '.' + name
_new_parent.mock_calls.append(this_mock_call)
_new_parent = _new_parent._mock_new_parent
# use ids here so as not to call __hash__ on the mocks
_new_parent_id = id(_new_parent)
if _new_parent_id in seen:
break
seen.add(_new_parent_id)
ret_val = DEFAULT
effect = self.side_effect
if effect is not None:
if _is_exception(effect):
raise effect
if not _callable(effect):
result = next(effect)
if _is_exception(result):
raise result
return result
ret_val = effect(*args, **kwargs)
if ret_val is DEFAULT:
ret_val = self.return_value
if (self._mock_wraps is not None and
self._mock_return_value is DEFAULT):
return self._mock_wraps(*args, **kwargs)
if ret_val is DEFAULT:
ret_val = self.return_value
return ret_val
class Mock(CallableMixin, NonCallableMock):
"""
Create a new `Mock` object. `Mock` takes several optional arguments
that specify the behaviour of the Mock object:
* `spec`: This can be either a list of strings or an existing object (a
class or instance) that acts as the specification for the mock object. If
you pass in an object then a list of strings is formed by calling dir on
the object (excluding unsupported magic attributes and methods). Accessing
any attribute not in this list will raise an `AttributeError`.
If `spec` is an object (rather than a list of strings) then
`mock.__class__` returns the class of the spec object. This allows mocks
to pass `isinstance` tests.
* `spec_set`: A stricter variant of `spec`. If used, attempting to *set*
or get an attribute on the mock that isn't on the object passed as
`spec_set` will raise an `AttributeError`.
* `side_effect`: A function to be called whenever the Mock is called. See
the `side_effect` attribute. Useful for raising exceptions or
dynamically changing return values. The function is called with the same
arguments as the mock, and unless it returns `DEFAULT`, the return
value of this function is used as the return value.
Alternatively `side_effect` can be an exception class or instance. In
this case the exception will be raised when the mock is called.
If `side_effect` is an iterable then each call to the mock will return
the next value from the iterable. If any of the members of the iterable
are exceptions they will be raised instead of returned.
* `return_value`: The value returned when the mock is called. By default
this is a new Mock (created on first access). See the
`return_value` attribute.
* `wraps`: Item for the mock object to wrap. If `wraps` is not None then
calling the Mock will pass the call through to the wrapped object
(returning the real result). Attribute access on the mock will return a
Mock object that wraps the corresponding attribute of the wrapped object
(so attempting to access an attribute that doesn't exist will raise an
`AttributeError`).
If the mock has an explicit `return_value` set then calls are not passed
to the wrapped object and the `return_value` is returned instead.
* `name`: If the mock has a name then it will be used in the repr of the
mock. This can be useful for debugging. The name is propagated to child
mocks.
Mocks can also be called with arbitrary keyword arguments. These will be
used to set attributes on the mock after it is created.
"""
def _dot_lookup(thing, comp, import_path):
try:
return getattr(thing, comp)
except AttributeError:
__import__(import_path)
return getattr(thing, comp)
def _importer(target):
components = target.split('.')
import_path = components.pop(0)
thing = __import__(import_path)
for comp in components:
import_path += ".%s" % comp
thing = _dot_lookup(thing, comp, import_path)
return thing
def _is_started(patcher):
# XXXX horrible
return hasattr(patcher, 'is_local')
class _patch(object):
attribute_name = None
_active_patches = set()
def __init__(
self, getter, attribute, new, spec, create,
spec_set, autospec, new_callable, kwargs
):
if new_callable is not None:
if new is not DEFAULT:
raise ValueError(
"Cannot use 'new' and 'new_callable' together"
)
if autospec is not None:
raise ValueError(
"Cannot use 'autospec' and 'new_callable' together"
)
self.getter = getter
self.attribute = attribute
self.new = new
self.new_callable = new_callable
self.spec = spec
self.create = create
self.has_local = False
self.spec_set = spec_set
self.autospec = autospec
self.kwargs = kwargs
self.additional_patchers = []
def copy(self):
patcher = _patch(
self.getter, self.attribute, self.new, self.spec,
self.create, self.spec_set,
self.autospec, self.new_callable, self.kwargs
)
patcher.attribute_name = self.attribute_name
patcher.additional_patchers = [
p.copy() for p in self.additional_patchers
]
return patcher
def __call__(self, func):
if isinstance(func, ClassTypes):
return self.decorate_class(func)
return self.decorate_callable(func)
def decorate_class(self, klass):
for attr in dir(klass):
if not attr.startswith(patch.TEST_PREFIX):
continue
attr_value = getattr(klass, attr)
if not hasattr(attr_value, "__call__"):
continue
patcher = self.copy()
setattr(klass, attr, patcher(attr_value))
return klass
def decorate_callable(self, func):
if hasattr(func, 'patchings'):
func.patchings.append(self)
return func
@wraps(func)
def patched(*args, **keywargs):
# don't use a with here (backwards compatability with Python 2.4)
extra_args = []
entered_patchers = []
# can't use try...except...finally because of Python 2.4
# compatibility
exc_info = tuple()
try:
try:
for patching in patched.patchings:
arg = patching.__enter__()
entered_patchers.append(patching)
if patching.attribute_name is not None:
keywargs.update(arg)
elif patching.new is DEFAULT:
extra_args.append(arg)
args += tuple(extra_args)
return func(*args, **keywargs)
except:
if (patching not in entered_patchers and
_is_started(patching)):
# the patcher may have been started, but an exception
# raised whilst entering one of its additional_patchers
entered_patchers.append(patching)
# Pass the exception to __exit__
exc_info = sys.exc_info()
# re-raise the exception
raise
finally:
for patching in reversed(entered_patchers):
patching.__exit__(*exc_info)
patched.patchings = [self]
if hasattr(func, 'func_code'):
# not in Python 3
patched.compat_co_firstlineno = getattr(
func, "compat_co_firstlineno",
func.func_code.co_firstlineno
)
return patched
def get_original(self):
target = self.getter()
name = self.attribute
original = DEFAULT
local = False
try:
original = target.__dict__[name]
except (AttributeError, KeyError):
original = getattr(target, name, DEFAULT)
else:
local = True
if not self.create and original is DEFAULT:
raise AttributeError(
"%s does not have the attribute %r" % (target, name)
)
return original, local
def __enter__(self):
"""Perform the patch."""
new, spec, spec_set = self.new, self.spec, self.spec_set
autospec, kwargs = self.autospec, self.kwargs
new_callable = self.new_callable
self.target = self.getter()
# normalise False to None
if spec is False:
spec = None
if spec_set is False:
spec_set = None
if autospec is False:
autospec = None
if spec is not None and autospec is not None:
raise TypeError("Can't specify spec and autospec")
if ((spec is not None or autospec is not None) and
spec_set not in (True, None)):
raise TypeError("Can't provide explicit spec_set *and* spec or autospec")
original, local = self.get_original()
if new is DEFAULT and autospec is None:
inherit = False
if spec is True:
# set spec to the object we are replacing
spec = original
if spec_set is True:
spec_set = original
spec = None
elif spec is not None:
if spec_set is True:
spec_set = spec
spec = None
elif spec_set is True:
spec_set = original
if spec is not None or spec_set is not None:
if original is DEFAULT:
raise TypeError("Can't use 'spec' with create=True")
if isinstance(original, ClassTypes):
# If we're patching out a class and there is a spec
inherit = True
Klass = MagicMock
_kwargs = {}
if new_callable is not None:
Klass = new_callable
elif spec is not None or spec_set is not None:
this_spec = spec
if spec_set is not None:
this_spec = spec_set
if _is_list(this_spec):
not_callable = '__call__' not in this_spec
else:
not_callable = not _callable(this_spec)
if not_callable:
Klass = NonCallableMagicMock
if spec is not None:
_kwargs['spec'] = spec
if spec_set is not None:
_kwargs['spec_set'] = spec_set
# add a name to mocks
if (isinstance(Klass, type) and
issubclass(Klass, NonCallableMock) and self.attribute):
_kwargs['name'] = self.attribute
_kwargs.update(kwargs)
new = Klass(**_kwargs)
if inherit and _is_instance_mock(new):
# we can only tell if the instance should be callable if the
# spec is not a list
this_spec = spec
if spec_set is not None:
this_spec = spec_set
if (not _is_list(this_spec) and not
_instance_callable(this_spec)):
Klass = NonCallableMagicMock
_kwargs.pop('name')
new.return_value = Klass(_new_parent=new, _new_name='()',
**_kwargs)
elif autospec is not None:
# spec is ignored, new *must* be default, spec_set is treated
# as a boolean. Should we check spec is not None and that spec_set
# is a bool?
if new is not DEFAULT:
raise TypeError(
"autospec creates the mock for you. Can't specify "
"autospec and new."
)
if original is DEFAULT:
raise TypeError("Can't use 'autospec' with create=True")
spec_set = bool(spec_set)
if autospec is True:
autospec = original
new = create_autospec(autospec, spec_set=spec_set,
_name=self.attribute, **kwargs)
elif kwargs:
# can't set keyword args when we aren't creating the mock
# XXXX If new is a Mock we could call new.configure_mock(**kwargs)
raise TypeError("Can't pass kwargs to a mock we aren't creating")
new_attr = new
self.temp_original = original
self.is_local = local
setattr(self.target, self.attribute, new_attr)
if self.attribute_name is not None:
extra_args = {}
if self.new is DEFAULT:
extra_args[self.attribute_name] = new
for patching in self.additional_patchers:
arg = patching.__enter__()
if patching.new is DEFAULT:
extra_args.update(arg)
return extra_args
return new
def __exit__(self, *exc_info):
"""Undo the patch."""
if not _is_started(self):
raise RuntimeError('stop called on unstarted patcher')
if self.is_local and self.temp_original is not DEFAULT:
setattr(self.target, self.attribute, self.temp_original)
else:
delattr(self.target, self.attribute)
if not self.create and not hasattr(self.target, self.attribute):
# needed for proxy objects like django settings
setattr(self.target, self.attribute, self.temp_original)
del self.temp_original
del self.is_local
del self.target
for patcher in reversed(self.additional_patchers):
if _is_started(patcher):
patcher.__exit__(*exc_info)
def start(self):
"""Activate a patch, returning any created mock."""
result = self.__enter__()
self._active_patches.add(self)
return result
def stop(self):
"""Stop an active patch."""
self._active_patches.discard(self)
return self.__exit__()
def _get_target(target):
try:
target, attribute = target.rsplit('.', 1)
except (TypeError, ValueError):
raise TypeError("Need a valid target to patch. You supplied: %r" %
(target,))
getter = lambda: _importer(target)
return getter, attribute
def _patch_object(
target, attribute, new=DEFAULT, spec=None,
create=False, spec_set=None, autospec=None,
new_callable=None, **kwargs
):
"""
patch.object(target, attribute, new=DEFAULT, spec=None, create=False,
spec_set=None, autospec=None, new_callable=None, **kwargs)
patch the named member (`attribute`) on an object (`target`) with a mock
object.
`patch.object` can be used as a decorator, class decorator or a context
manager. Arguments `new`, `spec`, `create`, `spec_set`,
`autospec` and `new_callable` have the same meaning as for `patch`. Like
`patch`, `patch.object` takes arbitrary keyword arguments for configuring
the mock object it creates.
When used as a class decorator `patch.object` honours `patch.TEST_PREFIX`
for choosing which methods to wrap.
"""
getter = lambda: target
return _patch(
getter, attribute, new, spec, create,
spec_set, autospec, new_callable, kwargs
)
def _patch_multiple(target, spec=None, create=False, spec_set=None,
autospec=None, new_callable=None, **kwargs):
"""Perform multiple patches in a single call. It takes the object to be
patched (either as an object or a string to fetch the object by importing)
and keyword arguments for the patches::
with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'):
...
Use `DEFAULT` as the value if you want `patch.multiple` to create
mocks for you. In this case the created mocks are passed into a decorated
function by keyword, and a dictionary is returned when `patch.multiple` is
used as a context manager.
`patch.multiple` can be used as a decorator, class decorator or a context
manager. The arguments `spec`, `spec_set`, `create`,
`autospec` and `new_callable` have the same meaning as for `patch`. These
arguments will be applied to *all* patches done by `patch.multiple`.
When used as a class decorator `patch.multiple` honours `patch.TEST_PREFIX`
for choosing which methods to wrap.
"""
if type(target) in (unicode, str):
getter = lambda: _importer(target)
else:
getter = lambda: target
if not kwargs:
raise ValueError(
'Must supply at least one keyword argument with patch.multiple'
)
# need to wrap in a list for python 3, where items is a view
items = list(kwargs.items())
attribute, new = items[0]
patcher = _patch(
getter, attribute, new, spec, create, spec_set,
autospec, new_callable, {}
)
patcher.attribute_name = attribute
for attribute, new in items[1:]:
this_patcher = _patch(
getter, attribute, new, spec, create, spec_set,
autospec, new_callable, {}
)
this_patcher.attribute_name = attribute
patcher.additional_patchers.append(this_patcher)
return patcher
def patch(
target, new=DEFAULT, spec=None, create=False,
spec_set=None, autospec=None, new_callable=None, **kwargs
):
"""
`patch` acts as a function decorator, class decorator or a context
manager. Inside the body of the function or with statement, the `target`
is patched with a `new` object. When the function/with statement exits
the patch is undone.
If `new` is omitted, then the target is replaced with a
`MagicMock`. If `patch` is used as a decorator and `new` is
omitted, the created mock is passed in as an extra argument to the
decorated function. If `patch` is used as a context manager the created
mock is returned by the context manager.
`target` should be a string in the form `'package.module.ClassName'`. The
`target` is imported and the specified object replaced with the `new`
object, so the `target` must be importable from the environment you are
calling `patch` from. The target is imported when the decorated function
is executed, not at decoration time.
The `spec` and `spec_set` keyword arguments are passed to the `MagicMock`
if patch is creating one for you.
In addition you can pass `spec=True` or `spec_set=True`, which causes
patch to pass in the object being mocked as the spec/spec_set object.
`new_callable` allows you to specify a different class, or callable object,
that will be called to create the `new` object. By default `MagicMock` is
used.
A more powerful form of `spec` is `autospec`. If you set `autospec=True`
then the mock with be created with a spec from the object being replaced.
All attributes of the mock will also have the spec of the corresponding
attribute of the object being replaced. Methods and functions being
mocked will have their arguments checked and will raise a `TypeError` if
they are called with the wrong signature. For mocks replacing a class,
their return value (the 'instance') will have the same spec as the class.
Instead of `autospec=True` you can pass `autospec=some_object` to use an
arbitrary object as the spec instead of the one being replaced.
By default `patch` will fail to replace attributes that don't exist. If
you pass in `create=True`, and the attribute doesn't exist, patch will
create the attribute for you when the patched function is called, and
delete it again afterwards. This is useful for writing tests against
attributes that your production code creates at runtime. It is off by by
default because it can be dangerous. With it switched on you can write
passing tests against APIs that don't actually exist!
Patch can be used as a `TestCase` class decorator. It works by
decorating each test method in the class. This reduces the boilerplate
code when your test methods share a common patchings set. `patch` finds
tests by looking for method names that start with `patch.TEST_PREFIX`.
By default this is `test`, which matches the way `unittest` finds tests.
You can specify an alternative prefix by setting `patch.TEST_PREFIX`.
Patch can be used as a context manager, with the with statement. Here the
patching applies to the indented block after the with statement. If you
use "as" then the patched object will be bound to the name after the
"as"; very useful if `patch` is creating a mock object for you.
`patch` takes arbitrary keyword arguments. These will be passed to
the `Mock` (or `new_callable`) on construction.
`patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are
available for alternate use-cases.
"""
getter, attribute = _get_target(target)
return _patch(
getter, attribute, new, spec, create,
spec_set, autospec, new_callable, kwargs
)
class _patch_dict(object):
"""
Patch a dictionary, or dictionary like object, and restore the dictionary
to its original state after the test.
`in_dict` can be a dictionary or a mapping like container. If it is a
mapping then it must at least support getting, setting and deleting items
plus iterating over keys.
`in_dict` can also be a string specifying the name of the dictionary, which
will then be fetched by importing it.
`values` can be a dictionary of values to set in the dictionary. `values`
can also be an iterable of `(key, value)` pairs.
If `clear` is True then the dictionary will be cleared before the new
values are set.
`patch.dict` can also be called with arbitrary keyword arguments to set
values in the dictionary::
with patch.dict('sys.modules', mymodule=Mock(), other_module=Mock()):
...
`patch.dict` can be used as a context manager, decorator or class
decorator. When used as a class decorator `patch.dict` honours
`patch.TEST_PREFIX` for choosing which methods to wrap.
"""
def __init__(self, in_dict, values=(), clear=False, **kwargs):
if isinstance(in_dict, basestring):
in_dict = _importer(in_dict)
self.in_dict = in_dict
# support any argument supported by dict(...) constructor
self.values = dict(values)
self.values.update(kwargs)
self.clear = clear
self._original = None
def __call__(self, f):
if isinstance(f, ClassTypes):
return self.decorate_class(f)
@wraps(f)
def _inner(*args, **kw):
self._patch_dict()
try:
return f(*args, **kw)
finally:
self._unpatch_dict()
return _inner
def decorate_class(self, klass):
for attr in dir(klass):
attr_value = getattr(klass, attr)
if (attr.startswith(patch.TEST_PREFIX) and
hasattr(attr_value, "__call__")):
decorator = _patch_dict(self.in_dict, self.values, self.clear)
decorated = decorator(attr_value)
setattr(klass, attr, decorated)
return klass
def __enter__(self):
"""Patch the dict."""
self._patch_dict()
def _patch_dict(self):
values = self.values
in_dict = self.in_dict
clear = self.clear
try:
original = in_dict.copy()
except AttributeError:
# dict like object with no copy method
# must support iteration over keys
original = {}
for key in in_dict:
original[key] = in_dict[key]
self._original = original
if clear:
_clear_dict(in_dict)
try:
in_dict.update(values)
except AttributeError:
# dict like object with no update method
for key in values:
in_dict[key] = values[key]
def _unpatch_dict(self):
in_dict = self.in_dict
original = self._original
_clear_dict(in_dict)
try:
in_dict.update(original)
except AttributeError:
for key in original:
in_dict[key] = original[key]
def __exit__(self, *args):
"""Unpatch the dict."""
self._unpatch_dict()
return False
start = __enter__
stop = __exit__
def _clear_dict(in_dict):
try:
in_dict.clear()
except AttributeError:
keys = list(in_dict)
for key in keys:
del in_dict[key]
def _patch_stopall():
"""Stop all active patches."""
for patch in list(_patch._active_patches):
patch.stop()
patch.object = _patch_object
patch.dict = _patch_dict
patch.multiple = _patch_multiple
patch.stopall = _patch_stopall
patch.TEST_PREFIX = 'test'
magic_methods = (
"lt le gt ge eq ne "
"getitem setitem delitem "
"len contains iter "
"hash str sizeof "
"enter exit "
"divmod neg pos abs invert "
"complex int float index "
"trunc floor ceil "
)
numerics = "add sub mul div floordiv mod lshift rshift and xor or pow "
inplace = ' '.join('i%s' % n for n in numerics.split())
right = ' '.join('r%s' % n for n in numerics.split())
extra = ''
if inPy3k:
extra = 'bool next '
else:
extra = 'unicode long nonzero oct hex truediv rtruediv '
# not including __prepare__, __instancecheck__, __subclasscheck__
# (as they are metaclass methods)
# __del__ is not supported at all as it causes problems if it exists
_non_defaults = set('__%s__' % method for method in [
'cmp', 'getslice', 'setslice', 'coerce', 'subclasses',
'format', 'get', 'set', 'delete', 'reversed',
'missing', 'reduce', 'reduce_ex', 'getinitargs',
'getnewargs', 'getstate', 'setstate', 'getformat',
'setformat', 'repr', 'dir'
])
def _get_method(name, func):
"Turns a callable object (like a mock) into a real function"
def method(self, *args, **kw):
return func(self, *args, **kw)
method.__name__ = name
return method
_magics = set(
'__%s__' % method for method in
' '.join([magic_methods, numerics, inplace, right, extra]).split()
)
_all_magics = _magics | _non_defaults
_unsupported_magics = set([
'__getattr__', '__setattr__',
'__init__', '__new__', '__prepare__'
'__instancecheck__', '__subclasscheck__',
'__del__'
])
_calculate_return_value = {
'__hash__': lambda self: object.__hash__(self),
'__str__': lambda self: object.__str__(self),
'__sizeof__': lambda self: object.__sizeof__(self),
'__unicode__': lambda self: unicode(object.__str__(self)),
}
_return_values = {
'__lt__': NotImplemented,
'__gt__': NotImplemented,
'__le__': NotImplemented,
'__ge__': NotImplemented,
'__int__': 1,
'__contains__': False,
'__len__': 0,
'__exit__': False,
'__complex__': 1j,
'__float__': 1.0,
'__bool__': True,
'__nonzero__': True,
'__oct__': '1',
'__hex__': '0x1',
'__long__': long(1),
'__index__': 1,
}
def _get_eq(self):
def __eq__(other):
ret_val = self.__eq__._mock_return_value
if ret_val is not DEFAULT:
return ret_val
return self is other
return __eq__
def _get_ne(self):
def __ne__(other):
if self.__ne__._mock_return_value is not DEFAULT:
return DEFAULT
return self is not other
return __ne__
def _get_iter(self):
def __iter__():
ret_val = self.__iter__._mock_return_value
if ret_val is DEFAULT:
return iter([])
# if ret_val was already an iterator, then calling iter on it should
# return the iterator unchanged
return iter(ret_val)
return __iter__
_side_effect_methods = {
'__eq__': _get_eq,
'__ne__': _get_ne,
'__iter__': _get_iter,
}
def _set_return_value(mock, method, name):
fixed = _return_values.get(name, DEFAULT)
if fixed is not DEFAULT:
method.return_value = fixed
return
return_calulator = _calculate_return_value.get(name)
if return_calulator is not None:
try:
return_value = return_calulator(mock)
except AttributeError:
# XXXX why do we return AttributeError here?
# set it as a side_effect instead?
return_value = AttributeError(name)
method.return_value = return_value
return
side_effector = _side_effect_methods.get(name)
if side_effector is not None:
method.side_effect = side_effector(mock)
class MagicMixin(object):
def __init__(self, *args, **kw):
_super(MagicMixin, self).__init__(*args, **kw)
self._mock_set_magics()
def _mock_set_magics(self):
these_magics = _magics
if self._mock_methods is not None:
these_magics = _magics.intersection(self._mock_methods)
remove_magics = set()
remove_magics = _magics - these_magics
for entry in remove_magics:
if entry in type(self).__dict__:
# remove unneeded magic methods
delattr(self, entry)
# don't overwrite existing attributes if called a second time
these_magics = these_magics - set(type(self).__dict__)
_type = type(self)
for entry in these_magics:
setattr(_type, entry, MagicProxy(entry, self))
class NonCallableMagicMock(MagicMixin, NonCallableMock):
"""A version of `MagicMock` that isn't callable."""
def mock_add_spec(self, spec, spec_set=False):
"""Add a spec to a mock. `spec` can either be an object or a
list of strings. Only attributes on the `spec` can be fetched as
attributes from the mock.
If `spec_set` is True then only attributes on the spec can be set."""
self._mock_add_spec(spec, spec_set)
self._mock_set_magics()
class MagicMock(MagicMixin, Mock):
"""
MagicMock is a subclass of Mock with default implementations
of most of the magic methods. You can use MagicMock without having to
configure the magic methods yourself.
If you use the `spec` or `spec_set` arguments then *only* magic
methods that exist in the spec will be created.
Attributes and the return value of a `MagicMock` will also be `MagicMocks`.
"""
def mock_add_spec(self, spec, spec_set=False):
"""Add a spec to a mock. `spec` can either be an object or a
list of strings. Only attributes on the `spec` can be fetched as
attributes from the mock.
If `spec_set` is True then only attributes on the spec can be set."""
self._mock_add_spec(spec, spec_set)
self._mock_set_magics()
class MagicProxy(object):
def __init__(self, name, parent):
self.name = name
self.parent = parent
def __call__(self, *args, **kwargs):
m = self.create_mock()
return m(*args, **kwargs)
def create_mock(self):
entry = self.name
parent = self.parent
m = parent._get_child_mock(name=entry, _new_name=entry,
_new_parent=parent)
setattr(parent, entry, m)
_set_return_value(parent, m, entry)
return m
def __get__(self, obj, _type=None):
return self.create_mock()
class _ANY(object):
"A helper object that compares equal to everything."
def __eq__(self, other):
return True
def __ne__(self, other):
return False
def __repr__(self):
return '<ANY>'
ANY = _ANY()
def _format_call_signature(name, args, kwargs):
message = '%s(%%s)' % name
formatted_args = ''
args_string = ', '.join([repr(arg) for arg in args])
kwargs_string = ', '.join([
'%s=%r' % (key, value) for key, value in kwargs.items()
])
if args_string:
formatted_args = args_string
if kwargs_string:
if formatted_args:
formatted_args += ', '
formatted_args += kwargs_string
return message % formatted_args
class _Call(tuple):
"""
A tuple for holding the results of a call to a mock, either in the form
`(args, kwargs)` or `(name, args, kwargs)`.
If args or kwargs are empty then a call tuple will compare equal to
a tuple without those values. This makes comparisons less verbose::
_Call(('name', (), {})) == ('name',)
_Call(('name', (1,), {})) == ('name', (1,))
_Call(((), {'a': 'b'})) == ({'a': 'b'},)
The `_Call` object provides a useful shortcut for comparing with call::
_Call(((1, 2), {'a': 3})) == call(1, 2, a=3)
_Call(('foo', (1, 2), {'a': 3})) == call.foo(1, 2, a=3)
If the _Call has no name then it will match any name.
"""
def __new__(cls, value=(), name=None, parent=None, two=False,
from_kall=True):
name = ''
args = ()
kwargs = {}
_len = len(value)
if _len == 3:
name, args, kwargs = value
elif _len == 2:
first, second = value
if isinstance(first, basestring):
name = first
if isinstance(second, tuple):
args = second
else:
kwargs = second
else:
args, kwargs = first, second
elif _len == 1:
value, = value
if isinstance(value, basestring):
name = value
elif isinstance(value, tuple):
args = value
else:
kwargs = value
if two:
return tuple.__new__(cls, (args, kwargs))
return tuple.__new__(cls, (name, args, kwargs))
def __init__(self, value=(), name=None, parent=None, two=False,
from_kall=True):
self.name = name
self.parent = parent
self.from_kall = from_kall
def __eq__(self, other):
if other is ANY:
return True
try:
len_other = len(other)
except TypeError:
return False
self_name = ''
if len(self) == 2:
self_args, self_kwargs = self
else:
self_name, self_args, self_kwargs = self
other_name = ''
if len_other == 0:
other_args, other_kwargs = (), {}
elif len_other == 3:
other_name, other_args, other_kwargs = other
elif len_other == 1:
value, = other
if isinstance(value, tuple):
other_args = value
other_kwargs = {}
elif isinstance(value, basestring):
other_name = value
other_args, other_kwargs = (), {}
else:
other_args = ()
other_kwargs = value
else:
# len 2
# could be (name, args) or (name, kwargs) or (args, kwargs)
first, second = other
if isinstance(first, basestring):
other_name = first
if isinstance(second, tuple):
other_args, other_kwargs = second, {}
else:
other_args, other_kwargs = (), second
else:
other_args, other_kwargs = first, second
if self_name and other_name != self_name:
return False
# this order is important for ANY to work!
return (other_args, other_kwargs) == (self_args, self_kwargs)
def __ne__(self, other):
return not self.__eq__(other)
def __call__(self, *args, **kwargs):
if self.name is None:
return _Call(('', args, kwargs), name='()')
name = self.name + '()'
return _Call((self.name, args, kwargs), name=name, parent=self)
def __getattr__(self, attr):
if self.name is None:
return _Call(name=attr, from_kall=False)
name = '%s.%s' % (self.name, attr)
return _Call(name=name, parent=self, from_kall=False)
def __repr__(self):
if not self.from_kall:
name = self.name or 'call'
if name.startswith('()'):
name = 'call%s' % name
return name
if len(self) == 2:
name = 'call'
args, kwargs = self
else:
name, args, kwargs = self
if not name:
name = 'call'
elif not name.startswith('()'):
name = 'call.%s' % name
else:
name = 'call%s' % name
return _format_call_signature(name, args, kwargs)
def call_list(self):
"""For a call object that represents multiple calls, `call_list`
returns a list of all the intermediate calls as well as the
final call."""
vals = []
thing = self
while thing is not None:
if thing.from_kall:
vals.append(thing)
thing = thing.parent
return _CallList(reversed(vals))
call = _Call(from_kall=False)
def create_autospec(spec, spec_set=False, instance=False, _parent=None,
_name=None, **kwargs):
"""Create a mock object using another object as a spec. Attributes on the
mock will use the corresponding attribute on the `spec` object as their
spec.
Functions or methods being mocked will have their arguments checked
to check that they are called with the correct signature.
If `spec_set` is True then attempting to set attributes that don't exist
on the spec object will raise an `AttributeError`.
If a class is used as a spec then the return value of the mock (the
instance of the class) will have the same spec. You can use a class as the
spec for an instance object by passing `instance=True`. The returned mock
will only be callable if instances of the mock are callable.
`create_autospec` also takes arbitrary keyword arguments that are passed to
the constructor of the created mock."""
if _is_list(spec):
# can't pass a list instance to the mock constructor as it will be
# interpreted as a list of strings
spec = type(spec)
is_type = isinstance(spec, ClassTypes)
_kwargs = {'spec': spec}
if spec_set:
_kwargs = {'spec_set': spec}
elif spec is None:
# None we mock with a normal mock without a spec
_kwargs = {}
_kwargs.update(kwargs)
Klass = MagicMock
if type(spec) in DescriptorTypes:
# descriptors don't have a spec
# because we don't know what type they return
_kwargs = {}
elif not _callable(spec):
Klass = NonCallableMagicMock
elif is_type and instance and not _instance_callable(spec):
Klass = NonCallableMagicMock
_new_name = _name
if _parent is None:
# for a top level object no _new_name should be set
_new_name = ''
mock = Klass(parent=_parent, _new_parent=_parent, _new_name=_new_name,
name=_name, **_kwargs)
if isinstance(spec, FunctionTypes):
# should only happen at the top level because we don't
# recurse for functions
mock = _set_signature(mock, spec)
else:
_check_signature(spec, mock, is_type, instance)
if _parent is not None and not instance:
_parent._mock_children[_name] = mock
if is_type and not instance and 'return_value' not in kwargs:
mock.return_value = create_autospec(spec, spec_set, instance=True,
_name='()', _parent=mock)
for entry in dir(spec):
if _is_magic(entry):
# MagicMock already does the useful magic methods for us
continue
if isinstance(spec, FunctionTypes) and entry in FunctionAttributes:
# allow a mock to actually be a function
continue
# XXXX do we need a better way of getting attributes without
# triggering code execution (?) Probably not - we need the actual
# object to mock it so we would rather trigger a property than mock
# the property descriptor. Likewise we want to mock out dynamically
# provided attributes.
# XXXX what about attributes that raise exceptions other than
# AttributeError on being fetched?
# we could be resilient against it, or catch and propagate the
# exception when the attribute is fetched from the mock
try:
original = getattr(spec, entry)
except AttributeError:
continue
kwargs = {'spec': original}
if spec_set:
kwargs = {'spec_set': original}
if not isinstance(original, FunctionTypes):
new = _SpecState(original, spec_set, mock, entry, instance)
mock._mock_children[entry] = new
else:
parent = mock
if isinstance(spec, FunctionTypes):
parent = mock.mock
new = MagicMock(parent=parent, name=entry, _new_name=entry,
_new_parent=parent, **kwargs)
mock._mock_children[entry] = new
skipfirst = _must_skip(spec, entry, is_type)
_check_signature(original, new, skipfirst=skipfirst)
# so functions created with _set_signature become instance attributes,
# *plus* their underlying mock exists in _mock_children of the parent
# mock. Adding to _mock_children may be unnecessary where we are also
# setting as an instance attribute?
if isinstance(new, FunctionTypes):
setattr(mock, entry, new)
return mock
def _must_skip(spec, entry, is_type):
if not isinstance(spec, ClassTypes):
if entry in getattr(spec, '__dict__', {}):
# instance attribute - shouldn't skip
return False
spec = spec.__class__
if not hasattr(spec, '__mro__'):
# old style class: can't have descriptors anyway
return is_type
for klass in spec.__mro__:
result = klass.__dict__.get(entry, DEFAULT)
if result is DEFAULT:
continue
if isinstance(result, (staticmethod, classmethod)):
return False
return is_type
# shouldn't get here unless function is a dynamically provided attribute
# XXXX untested behaviour
return is_type
def _get_class(obj):
try:
return obj.__class__
except AttributeError:
# in Python 2, _sre.SRE_Pattern objects have no __class__
return type(obj)
class _SpecState(object):
def __init__(self, spec, spec_set=False, parent=None,
name=None, ids=None, instance=False):
self.spec = spec
self.ids = ids
self.spec_set = spec_set
self.parent = parent
self.instance = instance
self.name = name
FunctionTypes = (
# python function
type(create_autospec),
# instance method
type(ANY.__eq__),
# unbound method
type(_ANY.__eq__),
)
FunctionAttributes = set([
'func_closure',
'func_code',
'func_defaults',
'func_dict',
'func_doc',
'func_globals',
'func_name',
])
file_spec = None
def mock_open(mock=None, read_data=''):
"""
A helper function to create a mock to replace the use of `open`. It works
for `open` called directly or used as a context manager.
The `mock` argument is the mock object to configure. If `None` (the
default) then a `MagicMock` will be created for you, with the API limited
to methods or attributes available on standard file handles.
`read_data` is a string for the `read` method of the file handle to return.
This is an empty string by default.
"""
global file_spec
if file_spec is None:
# set on first use
if inPy3k:
import _io
file_spec = list(set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO))))
else:
file_spec = file
if mock is None:
mock = MagicMock(name='open', spec=open)
handle = MagicMock(spec=file_spec)
handle.write.return_value = None
handle.__enter__.return_value = handle
handle.read.return_value = read_data
mock.return_value = handle
return mock
class PropertyMock(Mock):
"""
A mock intended to be used as a property, or other descriptor, on a class.
`PropertyMock` provides `__get__` and `__set__` methods so you can specify
a return value when it is fetched.
Fetching a `PropertyMock` instance from an object calls the mock, with
no args. Setting it calls the mock with the value being set.
"""
def _get_child_mock(self, **kwargs):
return MagicMock(**kwargs)
def __get__(self, obj, obj_type):
return self()
def __set__(self, obj, val):
self(val)
|
mit
|
[
3,
1379,
7249,
367,
1683,
316,
436,
3371,
316,
14,
199,
3,
1898,
334,
35,
9,
10219,
13,
7409,
16922,
481,
79,
2181,
1253,
314,
1683,
8099,
199,
3,
662,
13,
1198,
26,
24101,
1237,
15059,
2309,
2638,
15854,
5981,
15854,
399,
75,
199,
199,
3,
1683,
413,
14,
16,
199,
3,
1455,
921,
1544,
14,
1647,
2638,
14,
1308,
14,
3210,
15,
1548,
15,
1805,
15,
199,
199,
3,
17646,
68,
5420,
370,
314,
6289,
844,
199,
3,
7754,
1937,
1455,
921,
1544,
14,
1647,
2638,
14,
1308,
14,
3210,
15,
1548,
15,
1682,
14,
83,
1360,
199,
199,
3,
14914,
83,
26391,
737,
1455,
921,
1544,
14,
1647,
2638,
14,
1308,
14,
3210,
15,
1548,
15,
1080,
14,
83,
1360,
199,
3,
5429,
1470,
12,
18453,
15293,
436,
6519,
13924,
336,
14628,
14,
421,
199,
363,
452,
363,
275,
334,
272,
283,
3346,
297,
272,
283,
11988,
297,
272,
283,
2068,
297,
272,
283,
13400,
297,
272,
283,
3472,
297,
272,
283,
8974,
297,
272,
283,
1250,
297,
272,
283,
981,
63,
22303,
297,
272,
283,
9905,
63,
3022,
297,
272,
283,
6932,
16410,
3346,
297,
272,
283,
6932,
16410,
11988,
297,
272,
283,
1805,
63,
1490,
297,
272,
283,
3697,
3346,
297,
199,
9,
421,
199,
363,
1023,
363,
275,
283,
17,
14,
16,
14,
17,
7,
421,
199,
646,
10933,
199,
646,
984,
199,
199,
893,
26,
272,
492,
6485,
199,
2590,
3545,
26,
272,
327,
367,
13943,
10677,
626,
272,
327,
1443,
440,
1172,
6485,
272,
6485,
275,
488,
199,
199,
893,
26,
272,
687,
9143,
492,
14018,
465,
3379,
63,
13582,
199,
2590,
3545,
26,
272,
327,
2018,
499,
14,
20,
7163,
272,
347,
14018,
8,
5043,
304,
267,
347,
6506,
8,
70,
304,
288,
289,
855,
354,
363,
275,
3379,
855,
354,
363,
288,
289,
855,
1301,
363,
275,
3379,
855,
1301,
363,
288,
289,
855,
578,
363,
275,
3379,
855,
578,
363,
288,
289,
855,
9130,
363,
275,
3379,
288,
372,
289,
267,
372,
6506,
199,
2836,
26,
272,
340,
984,
14,
1023,
63,
815,
1491,
18,
61,
2356,
334,
19,
12,
650,
304,
267,
14018,
275,
3379,
63,
13582,
272,
587,
26,
267,
347,
14018,
8,
1532,
304,
288,
347,
6506,
8,
70,
304,
355,
289,
275,
3379,
63,
13582,
8,
1532,
5130,
70,
9,
355,
289,
855,
9130,
363,
275,
2562,
355,
372,
289,
288,
372,
6506,
199,
199,
893,
26,
272,
2649,
199,
2590,
12746,
26,
272,
327,
2018,
650,
272,
7116,
275,
2649,
275,
620,
199,
199,
893,
26,
272,
1846,
199,
2590,
12746,
26,
272,
327,
2018,
650,
272,
1846,
275,
1109,
199,
199,
893,
26,
272,
25416,
199,
2590,
12746,
26,
272,
327,
2018,
499,
14,
20,
7163,
272,
25416,
275,
2186,
199,
199,
893,
26,
272,
2163,
199,
2590,
12746,
26,
272,
347,
2163,
8,
1113,
304,
267,
372,
1559,
14,
2184,
342,
421,
199,
1563,
16836,
275,
334,
29900,
4258,
199,
692,
283,
6138,
7,
315,
984,
14,
3246,
26,
272,
327,
1335,
11361,
272,
492,
12120,
272,
3523,
16836,
275,
334,
29900,
12,
12120,
14,
4159,
14,
2719,
1143,
461,
9,
199,
199,
893,
26,
272,
485,
29022,
2841,
275,
620,
14,
29022,
2841,
199,
2590,
4281,
26,
272,
327,
2018,
499,
14,
56,
272,
492,
4252,
272,
492,
295,
272,
5163,
275,
295,
14,
2014,
8,
82,
23811,
65,
13,
90,
17900,
65,
13,
90,
16,
13,
25,
15555,
4268,
295,
14,
41,
9,
272,
347,
485,
29022,
2841,
8,
875,
304,
267,
340,
1059,
315,
4252,
14,
829,
513,
26,
288,
372,
756,
267,
372,
5163,
14,
1431,
8,
875,
9,
421,
199,
262,
2713,
19,
75,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
650,
199,
199,
3,
28196,
370,
1736,
6818,
2018,
650,
6519,
2382,
675,
402,
298,
4792,
2,
1640,
771,
470,
543,
199,
3,
12669,
636,
533,
363,
465,
282,
5872,
199,
63,
4792,
275,
1613,
199,
199,
277,
275,
283,
1017,
63,
277,
7,
199,
5351,
275,
2560,
5351,
12217,
199,
692,
315,
2713,
19,
75,
26,
272,
291,
275,
2560,
277,
12217,
272,
6762,
275,
283,
10372,
7,
199,
199,
9905,
63,
3022,
275,
715,
421,
199,
318,
485,
374,
63,
842,
63,
1805,
8,
1113,
304,
272,
327,
883,
1133,
675,
1228,
641,
4420,
2251,
2952,
2985,
4278,
636,
533,
363,
272,
327,
710,
1300,
1021,
367,
1006,
26500,
365,
10172,
16410,
3346,
272,
372,
11602,
8,
466,
8,
1113,
395,
10172,
16410,
3346,
9,
421,
199,
318,
485,
374,
63,
1971,
8,
1113,
304,
272,
372,
334,
267,
1228,
8,
1113,
12,
3523,
16836,
9,
503,
267,
1228,
8,
1113,
12,
8089,
4100,
9,
436,
11602,
8,
1113,
12,
3523,
16836,
9,
272,
776,
421,
199,
533,
485,
7998,
471,
8,
785,
304,
272,
636,
7257,
363,
275,
788,
65,
418,
421,
199,
4311,
4100,
275,
334,
272,
730,
1547,
7998,
471,
14,
65,
395,
272,
3324,
12,
199,
9,
421,
199,
318,
485,
362,
5233,
8,
1532,
12,
3372,
2246,
12,
1256,
29,
797,
304,
272,
340,
6485,
365,
488,
26,
267,
746,
3545,
360,
10955,
859,
440,
2808,
358,
339,
340,
1228,
8,
1532,
12,
8089,
4100,
9,
436,
440,
1256,
26,
267,
862,
26,
288,
2562,
275,
2562,
855,
826,
363,
267,
871,
4281,
26,
288,
372,
267,
3372,
2246,
275,
715,
272,
916,
440,
1228,
8,
1532,
12,
6801,
4100,
304,
267,
327,
367,
3992,
2382,
1256,
365,
715,
781,
1284,
1536,
2348,
4634,
267,
862,
26,
288,
2562,
275,
2562,
855,
1250,
363,
267,
871,
4281,
26,
288,
372,
339,
340,
315,
2713,
19,
75,
26,
267,
862,
26,
288,
26632,
275,
6485,
14,
362,
2861,
15644,
8,
1532,
9,
267,
871,
3146,
26,
288,
327,
445,
805,
1182,
1083,
12,
12570,
12623,
909,
11027,
826,
363,
288,
372,
267,
1295,
589,
12,
23377,
12,
27835,
12,
4243,
12,
32635,
12,
32635,
318,
12,
21172,
275,
26632,
272,
587,
26,
267,
862,
26,
288,
1295,
589,
12,
23377,
12,
2729,
958,
12,
4243,
275,
6485,
14,
29836,
8,
1532,
9,
267,
871,
3146,
26,
288,
327,
445,
805,
1182,
1083,
12,
12570,
12623,
909,
11027,
826,
363,
288,
372,
339
] |
[
1379,
7249,
367,
1683,
316,
436,
3371,
316,
14,
199,
3,
1898,
334,
35,
9,
10219,
13,
7409,
16922,
481,
79,
2181,
1253,
314,
1683,
8099,
199,
3,
662,
13,
1198,
26,
24101,
1237,
15059,
2309,
2638,
15854,
5981,
15854,
399,
75,
199,
199,
3,
1683,
413,
14,
16,
199,
3,
1455,
921,
1544,
14,
1647,
2638,
14,
1308,
14,
3210,
15,
1548,
15,
1805,
15,
199,
199,
3,
17646,
68,
5420,
370,
314,
6289,
844,
199,
3,
7754,
1937,
1455,
921,
1544,
14,
1647,
2638,
14,
1308,
14,
3210,
15,
1548,
15,
1682,
14,
83,
1360,
199,
199,
3,
14914,
83,
26391,
737,
1455,
921,
1544,
14,
1647,
2638,
14,
1308,
14,
3210,
15,
1548,
15,
1080,
14,
83,
1360,
199,
3,
5429,
1470,
12,
18453,
15293,
436,
6519,
13924,
336,
14628,
14,
421,
199,
363,
452,
363,
275,
334,
272,
283,
3346,
297,
272,
283,
11988,
297,
272,
283,
2068,
297,
272,
283,
13400,
297,
272,
283,
3472,
297,
272,
283,
8974,
297,
272,
283,
1250,
297,
272,
283,
981,
63,
22303,
297,
272,
283,
9905,
63,
3022,
297,
272,
283,
6932,
16410,
3346,
297,
272,
283,
6932,
16410,
11988,
297,
272,
283,
1805,
63,
1490,
297,
272,
283,
3697,
3346,
297,
199,
9,
421,
199,
363,
1023,
363,
275,
283,
17,
14,
16,
14,
17,
7,
421,
199,
646,
10933,
199,
646,
984,
199,
199,
893,
26,
272,
492,
6485,
199,
2590,
3545,
26,
272,
327,
367,
13943,
10677,
626,
272,
327,
1443,
440,
1172,
6485,
272,
6485,
275,
488,
199,
199,
893,
26,
272,
687,
9143,
492,
14018,
465,
3379,
63,
13582,
199,
2590,
3545,
26,
272,
327,
2018,
499,
14,
20,
7163,
272,
347,
14018,
8,
5043,
304,
267,
347,
6506,
8,
70,
304,
288,
289,
855,
354,
363,
275,
3379,
855,
354,
363,
288,
289,
855,
1301,
363,
275,
3379,
855,
1301,
363,
288,
289,
855,
578,
363,
275,
3379,
855,
578,
363,
288,
289,
855,
9130,
363,
275,
3379,
288,
372,
289,
267,
372,
6506,
199,
2836,
26,
272,
340,
984,
14,
1023,
63,
815,
1491,
18,
61,
2356,
334,
19,
12,
650,
304,
267,
14018,
275,
3379,
63,
13582,
272,
587,
26,
267,
347,
14018,
8,
1532,
304,
288,
347,
6506,
8,
70,
304,
355,
289,
275,
3379,
63,
13582,
8,
1532,
5130,
70,
9,
355,
289,
855,
9130,
363,
275,
2562,
355,
372,
289,
288,
372,
6506,
199,
199,
893,
26,
272,
2649,
199,
2590,
12746,
26,
272,
327,
2018,
650,
272,
7116,
275,
2649,
275,
620,
199,
199,
893,
26,
272,
1846,
199,
2590,
12746,
26,
272,
327,
2018,
650,
272,
1846,
275,
1109,
199,
199,
893,
26,
272,
25416,
199,
2590,
12746,
26,
272,
327,
2018,
499,
14,
20,
7163,
272,
25416,
275,
2186,
199,
199,
893,
26,
272,
2163,
199,
2590,
12746,
26,
272,
347,
2163,
8,
1113,
304,
267,
372,
1559,
14,
2184,
342,
421,
199,
1563,
16836,
275,
334,
29900,
4258,
199,
692,
283,
6138,
7,
315,
984,
14,
3246,
26,
272,
327,
1335,
11361,
272,
492,
12120,
272,
3523,
16836,
275,
334,
29900,
12,
12120,
14,
4159,
14,
2719,
1143,
461,
9,
199,
199,
893,
26,
272,
485,
29022,
2841,
275,
620,
14,
29022,
2841,
199,
2590,
4281,
26,
272,
327,
2018,
499,
14,
56,
272,
492,
4252,
272,
492,
295,
272,
5163,
275,
295,
14,
2014,
8,
82,
23811,
65,
13,
90,
17900,
65,
13,
90,
16,
13,
25,
15555,
4268,
295,
14,
41,
9,
272,
347,
485,
29022,
2841,
8,
875,
304,
267,
340,
1059,
315,
4252,
14,
829,
513,
26,
288,
372,
756,
267,
372,
5163,
14,
1431,
8,
875,
9,
421,
199,
262,
2713,
19,
75,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
650,
199,
199,
3,
28196,
370,
1736,
6818,
2018,
650,
6519,
2382,
675,
402,
298,
4792,
2,
1640,
771,
470,
543,
199,
3,
12669,
636,
533,
363,
465,
282,
5872,
199,
63,
4792,
275,
1613,
199,
199,
277,
275,
283,
1017,
63,
277,
7,
199,
5351,
275,
2560,
5351,
12217,
199,
692,
315,
2713,
19,
75,
26,
272,
291,
275,
2560,
277,
12217,
272,
6762,
275,
283,
10372,
7,
199,
199,
9905,
63,
3022,
275,
715,
421,
199,
318,
485,
374,
63,
842,
63,
1805,
8,
1113,
304,
272,
327,
883,
1133,
675,
1228,
641,
4420,
2251,
2952,
2985,
4278,
636,
533,
363,
272,
327,
710,
1300,
1021,
367,
1006,
26500,
365,
10172,
16410,
3346,
272,
372,
11602,
8,
466,
8,
1113,
395,
10172,
16410,
3346,
9,
421,
199,
318,
485,
374,
63,
1971,
8,
1113,
304,
272,
372,
334,
267,
1228,
8,
1113,
12,
3523,
16836,
9,
503,
267,
1228,
8,
1113,
12,
8089,
4100,
9,
436,
11602,
8,
1113,
12,
3523,
16836,
9,
272,
776,
421,
199,
533,
485,
7998,
471,
8,
785,
304,
272,
636,
7257,
363,
275,
788,
65,
418,
421,
199,
4311,
4100,
275,
334,
272,
730,
1547,
7998,
471,
14,
65,
395,
272,
3324,
12,
199,
9,
421,
199,
318,
485,
362,
5233,
8,
1532,
12,
3372,
2246,
12,
1256,
29,
797,
304,
272,
340,
6485,
365,
488,
26,
267,
746,
3545,
360,
10955,
859,
440,
2808,
358,
339,
340,
1228,
8,
1532,
12,
8089,
4100,
9,
436,
440,
1256,
26,
267,
862,
26,
288,
2562,
275,
2562,
855,
826,
363,
267,
871,
4281,
26,
288,
372,
267,
3372,
2246,
275,
715,
272,
916,
440,
1228,
8,
1532,
12,
6801,
4100,
304,
267,
327,
367,
3992,
2382,
1256,
365,
715,
781,
1284,
1536,
2348,
4634,
267,
862,
26,
288,
2562,
275,
2562,
855,
1250,
363,
267,
871,
4281,
26,
288,
372,
339,
340,
315,
2713,
19,
75,
26,
267,
862,
26,
288,
26632,
275,
6485,
14,
362,
2861,
15644,
8,
1532,
9,
267,
871,
3146,
26,
288,
327,
445,
805,
1182,
1083,
12,
12570,
12623,
909,
11027,
826,
363,
288,
372,
267,
1295,
589,
12,
23377,
12,
27835,
12,
4243,
12,
32635,
12,
32635,
318,
12,
21172,
275,
26632,
272,
587,
26,
267,
862,
26,
288,
1295,
589,
12,
23377,
12,
2729,
958,
12,
4243,
275,
6485,
14,
29836,
8,
1532,
9,
267,
871,
3146,
26,
288,
327,
445,
805,
1182,
1083,
12,
12570,
12623,
909,
11027,
826,
363,
288,
372,
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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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
] |
ucloud/uai-sdk
|
uai/api/get_uai_srv_bill_unitprice.py
|
1
|
1616
|
# Copyright 2017 The UAI-SDK 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.
# ==============================================================================
from uai.api.base_api import BaseUaiServiceApiOp
class GetUAISrvBillUnitPriceApiOp(BaseUaiServiceApiOp):
ACTION_NAME = "GetUAISrvBillUnitPrice"
def __init__(self, public_key, private_key, service_type, bill_prod, project_id='', region='', zone=''):
super(GetUAISrvBillUnitPriceApiOp, self).__init__(self.ACTION_NAME, public_key, private_key, project_id, region, zone)
self.cmd_params['Region'] = region if region != '' else super(GetUAISrvBillUnitPriceApiOp, self).PARAMS_DEFAULT_REGION
self.cmd_params['BillProdId'] = bill_prod
self.cmd_params['ServiceTypeId'] = service_type
def _check_args(self, params):
if params['BillProdId'] == '':
return False
if params['ServiceTypeId'] == '':
return False
return True
def call_api(self):
succ, rsp = super(GetUAISrvBillUnitPriceApiOp, self).call_api()
return succ, rsp
|
apache-2.0
|
[
3,
1898,
9708,
710,
738,
7730,
13,
14939,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
504,
399,
5789,
14,
1246,
14,
1095,
63,
1246,
492,
3523,
53,
5789,
3167,
7394,
4619,
199,
199,
533,
2372,
21659,
1311,
6310,
34,
778,
5072,
11826,
7394,
4619,
8,
1563,
53,
5789,
3167,
7394,
4619,
304,
339,
9612,
63,
2339,
275,
298,
1002,
21659,
1311,
6310,
34,
778,
5072,
11826,
2,
339,
347,
636,
826,
721,
277,
12,
4575,
63,
498,
12,
5726,
63,
498,
12,
2435,
63,
466,
12,
330,
778,
63,
8788,
12,
2199,
63,
344,
4581,
4897,
4581,
5718,
9280,
267,
1613,
8,
1002,
21659,
1311,
6310,
34,
778,
5072,
11826,
7394,
4619,
12,
291,
2843,
826,
721,
277,
14,
10052,
63,
2339,
12,
4575,
63,
498,
12,
5726,
63,
498,
12,
2199,
63,
344,
12,
4897,
12,
5718,
9,
267,
291,
14,
1760,
63,
1162,
459,
10708,
418,
275,
4897,
340,
4897,
1137,
2125,
587,
1613,
8,
1002,
21659,
1311,
6310,
34,
778,
5072,
11826,
7394,
4619,
12,
291,
680,
17978,
63,
3472,
63,
23030,
267,
291,
14,
1760,
63,
1162,
459,
34,
778,
30966,
1304,
418,
275,
330,
778,
63,
8788,
267,
291,
14,
1760,
63,
1162,
459,
3167,
2568,
418,
275,
2435,
63,
466,
339,
347,
485,
1074,
63,
589,
8,
277,
12,
1862,
304,
267,
340,
1862,
459,
34,
778,
30966,
1304,
418,
508,
8061,
288,
372,
756,
267,
340,
1862,
459,
3167,
2568,
418,
508,
8061,
288,
372,
756,
267,
372,
715,
339,
347,
1240,
63,
1246,
8,
277,
304,
267,
308,
8451,
12,
13684,
275,
1613,
8,
1002,
21659,
1311,
6310,
34,
778,
5072,
11826,
7394,
4619,
12,
291,
680,
1250,
63,
1246,
342,
267,
372,
308,
8451,
12,
13684,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
738,
7730,
13,
14939,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
504,
399,
5789,
14,
1246,
14,
1095,
63,
1246,
492,
3523,
53,
5789,
3167,
7394,
4619,
199,
199,
533,
2372,
21659,
1311,
6310,
34,
778,
5072,
11826,
7394,
4619,
8,
1563,
53,
5789,
3167,
7394,
4619,
304,
339,
9612,
63,
2339,
275,
298,
1002,
21659,
1311,
6310,
34,
778,
5072,
11826,
2,
339,
347,
636,
826,
721,
277,
12,
4575,
63,
498,
12,
5726,
63,
498,
12,
2435,
63,
466,
12,
330,
778,
63,
8788,
12,
2199,
63,
344,
4581,
4897,
4581,
5718,
9280,
267,
1613,
8,
1002,
21659,
1311,
6310,
34,
778,
5072,
11826,
7394,
4619,
12,
291,
2843,
826,
721,
277,
14,
10052,
63,
2339,
12,
4575,
63,
498,
12,
5726,
63,
498,
12,
2199,
63,
344,
12,
4897,
12,
5718,
9,
267,
291,
14,
1760,
63,
1162,
459,
10708,
418,
275,
4897,
340,
4897,
1137,
2125,
587,
1613,
8,
1002,
21659,
1311,
6310,
34,
778,
5072,
11826,
7394,
4619,
12,
291,
680,
17978,
63,
3472,
63,
23030,
267,
291,
14,
1760,
63,
1162,
459,
34,
778,
30966,
1304,
418,
275,
330,
778,
63,
8788,
267,
291,
14,
1760,
63,
1162,
459,
3167,
2568,
418,
275,
2435,
63,
466,
339,
347,
485,
1074,
63,
589,
8,
277,
12,
1862,
304,
267,
340,
1862,
459,
34,
778,
30966,
1304,
418,
508,
8061,
288,
372,
756,
267,
340,
1862,
459,
3167,
2568,
418,
508,
8061,
288,
372,
756,
267,
372,
715,
339,
347,
1240,
63,
1246,
8,
277,
304,
267,
308,
8451,
12,
13684,
275,
1613,
8,
1002,
21659,
1311,
6310,
34,
778,
5072,
11826,
7394,
4619,
12,
291,
680,
1250,
63,
1246,
342,
267,
372,
308,
8451,
12,
13684,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
imsut/commons
|
tests/python/twitter/common/python/test_nested.py
|
2
|
1942
|
# ==================================================================================================
# Copyright 2011 Twitter, Inc.
# --------------------------------------------------------------------------------------------------
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this work except in compliance with the License.
# You may obtain a copy of the License in the LICENSE file, or at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==================================================================================================
import os
import tempfile
import zipfile
from twitter.common.dirutil import safe_mkdir, safe_rmtree
from twitter.common.python.importer import Nested
class TestNested(object):
def test_generate_prefixes(self):
a, b, sep = 'a', 'b', os.sep
assert list(Nested._generate_prefixes(sep)) == []
assert list(Nested._generate_prefixes('')) == []
assert list(Nested._generate_prefixes('.')) == []
a_sep_b = a + sep + b
assert list(Nested._generate_prefixes(a_sep_b)) == [a_sep_b, a]
sep_a_sep_b = sep + a + sep + b
assert list(Nested._generate_prefixes(sep_a_sep_b)) == [sep_a_sep_b, sep + a]
def test_split_existing(self):
td = tempfile.mkdtemp()
try:
assert Nested._split_existing(td) == (td, '.')
assert Nested._split_existing(td + os.sep) == (td, '.')
assert Nested._split_existing(os.path.join(td, 'a', 'b', 'c')) == (
td, os.path.join('a', 'b', 'c'))
assert Nested._split_existing(os.path.join(td, 'a', '..', 'c')) == (td, 'c')
finally:
safe_rmtree(td)
|
apache-2.0
|
[
3,
7819,
2486,
29,
199,
3,
1898,
7760,
19259,
12,
3277,
14,
199,
3,
5620,
1444,
306,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
1736,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
315,
314,
5113,
570,
12,
503,
737,
26,
199,
3,
199,
3,
221,
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,
7819,
2486,
29,
199,
199,
646,
747,
199,
646,
5549,
199,
646,
10392,
199,
199,
504,
15811,
14,
2330,
14,
694,
1974,
492,
5048,
63,
8215,
12,
5048,
63,
9242,
199,
504,
15811,
14,
2330,
14,
1548,
14,
12138,
492,
23137,
199,
199,
533,
1379,
13029,
8,
785,
304,
523,
347,
511,
63,
4208,
63,
14124,
8,
277,
304,
272,
282,
12,
330,
12,
7375,
275,
283,
65,
297,
283,
66,
297,
747,
14,
4127,
272,
702,
769,
8,
13029,
423,
4208,
63,
14124,
8,
4127,
430,
508,
942,
272,
702,
769,
8,
13029,
423,
4208,
63,
14124,
30991,
508,
942,
272,
702,
769,
8,
13029,
423,
4208,
63,
14124,
24535,
508,
942,
339,
282,
63,
4127,
63,
66,
275,
282,
435,
7375,
435,
330,
272,
702,
769,
8,
13029,
423,
4208,
63,
14124,
8,
65,
63,
4127,
63,
66,
430,
508,
359,
65,
63,
4127,
63,
66,
12,
282,
61,
339,
7375,
63,
65,
63,
4127,
63,
66,
275,
7375,
435,
282,
435,
7375,
435,
330,
272,
702,
769,
8,
13029,
423,
4208,
63,
14124,
8,
4127,
63,
65,
63,
4127,
63,
66,
430,
508,
359,
4127,
63,
65,
63,
4127,
63,
66,
12,
7375,
435,
282,
61,
819,
347,
511,
63,
1294,
63,
5952,
8,
277,
304,
272,
12749,
275,
5549,
14,
11983,
342,
272,
862,
26,
489,
702,
23137,
423,
1294,
63,
5952,
8,
2076,
9,
508,
334,
2076,
12,
20093,
489,
702,
23137,
423,
1294,
63,
5952,
8,
2076,
435,
747,
14,
4127,
9,
508,
334,
2076,
12,
20093,
489,
702,
23137,
423,
1294,
63,
5952,
8,
736,
14,
515,
14,
904,
8,
2076,
12,
283,
65,
297,
283,
66,
297,
283,
67,
1333,
508,
334,
267,
12749,
12,
747,
14,
515,
14,
904,
360,
65,
297,
283,
66,
297,
283,
67,
1333,
489,
702,
23137,
423,
1294,
63,
5952,
8,
736,
14,
515,
14,
904,
8,
2076,
12,
283,
65,
297,
19155,
283,
67,
1333,
508,
334,
2076,
12,
283,
67,
358,
272,
3753,
26,
489,
5048,
63,
9242,
8,
2076,
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
] |
[
7819,
2486,
29,
199,
3,
1898,
7760,
19259,
12,
3277,
14,
199,
3,
5620,
1444,
306,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
1736,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
315,
314,
5113,
570,
12,
503,
737,
26,
199,
3,
199,
3,
221,
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,
7819,
2486,
29,
199,
199,
646,
747,
199,
646,
5549,
199,
646,
10392,
199,
199,
504,
15811,
14,
2330,
14,
694,
1974,
492,
5048,
63,
8215,
12,
5048,
63,
9242,
199,
504,
15811,
14,
2330,
14,
1548,
14,
12138,
492,
23137,
199,
199,
533,
1379,
13029,
8,
785,
304,
523,
347,
511,
63,
4208,
63,
14124,
8,
277,
304,
272,
282,
12,
330,
12,
7375,
275,
283,
65,
297,
283,
66,
297,
747,
14,
4127,
272,
702,
769,
8,
13029,
423,
4208,
63,
14124,
8,
4127,
430,
508,
942,
272,
702,
769,
8,
13029,
423,
4208,
63,
14124,
30991,
508,
942,
272,
702,
769,
8,
13029,
423,
4208,
63,
14124,
24535,
508,
942,
339,
282,
63,
4127,
63,
66,
275,
282,
435,
7375,
435,
330,
272,
702,
769,
8,
13029,
423,
4208,
63,
14124,
8,
65,
63,
4127,
63,
66,
430,
508,
359,
65,
63,
4127,
63,
66,
12,
282,
61,
339,
7375,
63,
65,
63,
4127,
63,
66,
275,
7375,
435,
282,
435,
7375,
435,
330,
272,
702,
769,
8,
13029,
423,
4208,
63,
14124,
8,
4127,
63,
65,
63,
4127,
63,
66,
430,
508,
359,
4127,
63,
65,
63,
4127,
63,
66,
12,
7375,
435,
282,
61,
819,
347,
511,
63,
1294,
63,
5952,
8,
277,
304,
272,
12749,
275,
5549,
14,
11983,
342,
272,
862,
26,
489,
702,
23137,
423,
1294,
63,
5952,
8,
2076,
9,
508,
334,
2076,
12,
20093,
489,
702,
23137,
423,
1294,
63,
5952,
8,
2076,
435,
747,
14,
4127,
9,
508,
334,
2076,
12,
20093,
489,
702,
23137,
423,
1294,
63,
5952,
8,
736,
14,
515,
14,
904,
8,
2076,
12,
283,
65,
297,
283,
66,
297,
283,
67,
1333,
508,
334,
267,
12749,
12,
747,
14,
515,
14,
904,
360,
65,
297,
283,
66,
297,
283,
67,
1333,
489,
702,
23137,
423,
1294,
63,
5952,
8,
736,
14,
515,
14,
904,
8,
2076,
12,
283,
65,
297,
19155,
283,
67,
1333,
508,
334,
2076,
12,
283,
67,
358,
272,
3753,
26,
489,
5048,
63,
9242,
8,
2076,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Nihn/Diamond-1
|
src/collectors/http/http.py
|
28
|
3120
|
# coding=utf-8
"""
Collect statistics from a HTTP or HTTPS connexion
#### Dependencies
* urllib2
#### Usage
Add the collector config as :
enabled = True
ttl_multiplier = 2
path_suffix = ""
measure_collector_time = False
byte_unit = byte,
req_vhost = www.my_server.com
req_url = https://www.my_server.com/, https://www.my_server.com/assets/jquery.js
Metrics are collected as :
- servers.<hostname>.http.<url>.size (size of the page received in bytes)
- servers.<hostname>.http.<url>.time (time to download the page in microsec)
'.' and '/' chars are replaced by __, url looking like
http://www.site.com/admin/page.html are replaced by
http:__www_site_com_admin_page_html
"""
import urllib2
import diamond.collector
import datetime
class HttpCollector(diamond.collector.Collector):
def get_default_config_help(self):
config_help = super(HttpCollector, self).get_default_config_help()
config_help.update({
'req_port': 'Port',
'req_url':
'array of full URL to get (ex : https://www.ici.net/mypage.html)',
'req_vhost':
'Host header variable if needed. Will be added to every request',
})
return config_help
def get_default_config(self):
default_config = super(HttpCollector, self).get_default_config()
default_config['path'] = 'http'
default_config['req_vhost'] = ''
default_config['req_url'] = ['http://localhost/']
default_config['headers'] = {'User-Agent': 'Diamond HTTP collector', }
return default_config
def collect(self):
# create urllib2 vars
if self.config['req_vhost'] != "":
self.config['headers']['Host'] = self.config['req_vhost']
# time the request
for url in self.config['req_url']:
self.log.debug("collecting %s", str(url))
req_start = datetime.datetime.now()
req = urllib2.Request(url, headers=self.config['headers'])
try:
handle = urllib2.urlopen(req)
the_page = handle.read()
req_end = datetime.datetime.now()
req_time = req_end - req_start
# build a compatible name : no '.' and no'/' in the name
metric_name = url.replace(
'/', '_').replace(
'.', '_').replace(
'\\', '').replace(
':', '')
# metric_name = url.split("/")[-1].replace(".", "_")
if metric_name == '':
metric_name = "root"
self.publish_gauge(
metric_name + '.time',
req_time.seconds * 1000000 + req_time.microseconds)
self.publish_gauge(
metric_name + '.size',
len(the_page))
except IOError, e:
self.log.error("Unable to open %s",
self.config['req_url'])
except Exception, e:
self.log.error("Unknown error opening url: %s", e)
|
mit
|
[
3,
2803,
29,
1624,
13,
24,
199,
199,
624,
199,
25023,
11076,
687,
282,
3101,
503,
14147,
2557,
476,
1636,
199,
199,
381,
1487,
3209,
421,
627,
4011,
18,
199,
199,
381,
11028,
199,
1123,
314,
14910,
1101,
465,
520,
199,
199,
3827,
275,
715,
199,
12130,
63,
15812,
275,
499,
199,
515,
63,
4511,
275,
3087,
199,
9580,
63,
10946,
63,
521,
275,
756,
199,
4414,
63,
3248,
275,
3696,
12,
199,
2103,
63,
32071,
275,
20732,
14,
1662,
63,
1000,
14,
957,
199,
2103,
63,
633,
275,
4178,
921,
1544,
14,
1662,
63,
1000,
14,
957,
15,
12,
4178,
921,
1544,
14,
1662,
63,
1000,
14,
957,
15,
12186,
15,
22324,
14,
3596,
199,
199,
17213,
787,
13736,
465,
520,
272,
446,
8037,
21455,
4269,
10827,
1014,
21455,
633,
10827,
890,
334,
890,
402,
314,
2034,
3086,
315,
2783,
9,
272,
446,
8037,
21455,
4269,
10827,
1014,
21455,
633,
10827,
521,
334,
521,
370,
5235,
314,
2034,
315,
9967,
3321,
9,
339,
7815,
436,
7324,
8365,
787,
8717,
701,
636,
12,
1166,
10023,
2839,
2126,
1455,
921,
1544,
14,
2124,
14,
957,
15,
2113,
15,
1606,
14,
1360,
787,
8717,
701,
2126,
1455,
21363,
1544,
63,
2124,
63,
957,
63,
2113,
63,
1606,
63,
1360,
199,
624,
199,
199,
646,
4011,
18,
199,
646,
487,
24940,
14,
10946,
199,
646,
2197,
421,
199,
533,
4760,
12852,
8,
328,
24940,
14,
10946,
14,
12852,
304,
339,
347,
664,
63,
885,
63,
888,
63,
3437,
8,
277,
304,
267,
1101,
63,
3437,
275,
1613,
8,
5779,
12852,
12,
291,
680,
362,
63,
885,
63,
888,
63,
3437,
342,
267,
1101,
63,
3437,
14,
873,
2561,
288,
283,
2103,
63,
719,
356,
283,
4313,
297,
288,
283,
2103,
63,
633,
356,
288,
283,
1144,
402,
2615,
2851,
370,
664,
334,
476,
520,
4178,
921,
1544,
14,
530,
73,
14,
846,
15,
1662,
1606,
14,
1360,
3196,
288,
283,
2103,
63,
32071,
356,
288,
283,
4965,
1406,
1750,
340,
4346,
14,
12823,
506,
3483,
370,
4036,
1056,
297,
267,
3828,
267,
372,
1101,
63,
3437,
339,
347,
664,
63,
885,
63,
888,
8,
277,
304,
267,
849,
63,
888,
275,
1613,
8,
5779,
12852,
12,
291,
680,
362,
63,
885,
63,
888,
342,
267,
849,
63,
888,
459,
515,
418,
275,
283,
1014,
7,
267,
849,
63,
888,
459,
2103,
63,
32071,
418,
275,
2125,
267,
849,
63,
888,
459,
2103,
63,
633,
418,
275,
788,
1014,
921,
5967,
15,
418,
398,
849,
63,
888,
459,
2139,
418,
275,
791,
1899,
13,
7788,
356,
283,
1341,
24940,
3101,
14910,
297,
789,
267,
372,
849,
63,
888,
339,
347,
8775,
8,
277,
304,
267,
327,
1218,
4011,
18,
6802,
267,
340,
291,
14,
888,
459,
2103,
63,
32071,
418,
1137,
10812,
288,
291,
14,
888,
459,
2139,
2545,
4965,
418,
275,
291,
14,
888,
459,
2103,
63,
32071,
418,
398,
327,
900,
314,
1056,
267,
367,
1166,
315,
291,
14,
888,
459,
2103,
63,
633,
2565,
288,
291,
14,
793,
14,
1757,
480,
7112,
316,
450,
83,
401,
620,
8,
633,
430,
288,
2648,
63,
928,
275,
2197,
14,
2083,
14,
2131,
342,
288,
2648,
275,
4011,
18,
14,
2017,
8,
633,
12,
2323,
29,
277,
14,
888,
459,
2139,
1105,
288,
862,
26,
355,
2429,
275,
4011,
18,
14,
10890,
8,
2103,
9,
355,
314,
63,
1606,
275,
2429,
14,
739,
342,
355,
2648,
63,
500,
275,
2197,
14,
2083,
14,
2131,
342,
355,
2648,
63,
521,
275,
2648,
63,
500,
446,
2648,
63,
928,
2234,
327,
1900,
282,
9025,
536,
520,
949,
7815,
436,
949,
29957,
315,
314,
536,
355,
6370,
63,
354,
275,
1166,
14,
1814,
8,
490,
17220,
2513,
1959,
1814,
8,
490,
22608,
2513,
1959,
1814,
8,
490,
6468,
297,
12548,
1814,
8,
490,
25475,
4074,
355,
327,
6370,
63,
354,
275,
1166,
14,
1294,
19031,
1988,
17,
1055,
1814,
30381,
2668,
531,
355,
340,
6370,
63,
354,
508,
8061,
490,
6370,
63,
354,
275,
298,
1231,
2,
355,
291,
14,
4763,
63,
26775,
8,
490,
6370,
63,
354,
435,
1987,
521,
297,
490,
2648,
63,
521,
14,
4515,
627,
19492,
435,
2648,
63,
521,
14,
18144,
9,
355,
291,
14,
4763,
63,
26775,
8,
490,
6370,
63,
354,
435,
1987,
890,
297,
490,
822,
8,
1589,
63,
1606,
430,
953,
871,
5925,
12,
325,
26,
355,
291,
14,
793,
14,
705,
480,
6005,
370,
1551,
450,
83,
401,
3044,
291,
14,
888,
459,
2103,
63,
633,
1105,
288,
871,
2186,
12,
325,
26,
355,
291,
14,
793,
14,
705,
480,
5912,
1125,
13618,
1166,
26,
450,
83,
401,
325,
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
] |
[
2803,
29,
1624,
13,
24,
199,
199,
624,
199,
25023,
11076,
687,
282,
3101,
503,
14147,
2557,
476,
1636,
199,
199,
381,
1487,
3209,
421,
627,
4011,
18,
199,
199,
381,
11028,
199,
1123,
314,
14910,
1101,
465,
520,
199,
199,
3827,
275,
715,
199,
12130,
63,
15812,
275,
499,
199,
515,
63,
4511,
275,
3087,
199,
9580,
63,
10946,
63,
521,
275,
756,
199,
4414,
63,
3248,
275,
3696,
12,
199,
2103,
63,
32071,
275,
20732,
14,
1662,
63,
1000,
14,
957,
199,
2103,
63,
633,
275,
4178,
921,
1544,
14,
1662,
63,
1000,
14,
957,
15,
12,
4178,
921,
1544,
14,
1662,
63,
1000,
14,
957,
15,
12186,
15,
22324,
14,
3596,
199,
199,
17213,
787,
13736,
465,
520,
272,
446,
8037,
21455,
4269,
10827,
1014,
21455,
633,
10827,
890,
334,
890,
402,
314,
2034,
3086,
315,
2783,
9,
272,
446,
8037,
21455,
4269,
10827,
1014,
21455,
633,
10827,
521,
334,
521,
370,
5235,
314,
2034,
315,
9967,
3321,
9,
339,
7815,
436,
7324,
8365,
787,
8717,
701,
636,
12,
1166,
10023,
2839,
2126,
1455,
921,
1544,
14,
2124,
14,
957,
15,
2113,
15,
1606,
14,
1360,
787,
8717,
701,
2126,
1455,
21363,
1544,
63,
2124,
63,
957,
63,
2113,
63,
1606,
63,
1360,
199,
624,
199,
199,
646,
4011,
18,
199,
646,
487,
24940,
14,
10946,
199,
646,
2197,
421,
199,
533,
4760,
12852,
8,
328,
24940,
14,
10946,
14,
12852,
304,
339,
347,
664,
63,
885,
63,
888,
63,
3437,
8,
277,
304,
267,
1101,
63,
3437,
275,
1613,
8,
5779,
12852,
12,
291,
680,
362,
63,
885,
63,
888,
63,
3437,
342,
267,
1101,
63,
3437,
14,
873,
2561,
288,
283,
2103,
63,
719,
356,
283,
4313,
297,
288,
283,
2103,
63,
633,
356,
288,
283,
1144,
402,
2615,
2851,
370,
664,
334,
476,
520,
4178,
921,
1544,
14,
530,
73,
14,
846,
15,
1662,
1606,
14,
1360,
3196,
288,
283,
2103,
63,
32071,
356,
288,
283,
4965,
1406,
1750,
340,
4346,
14,
12823,
506,
3483,
370,
4036,
1056,
297,
267,
3828,
267,
372,
1101,
63,
3437,
339,
347,
664,
63,
885,
63,
888,
8,
277,
304,
267,
849,
63,
888,
275,
1613,
8,
5779,
12852,
12,
291,
680,
362,
63,
885,
63,
888,
342,
267,
849,
63,
888,
459,
515,
418,
275,
283,
1014,
7,
267,
849,
63,
888,
459,
2103,
63,
32071,
418,
275,
2125,
267,
849,
63,
888,
459,
2103,
63,
633,
418,
275,
788,
1014,
921,
5967,
15,
418,
398,
849,
63,
888,
459,
2139,
418,
275,
791,
1899,
13,
7788,
356,
283,
1341,
24940,
3101,
14910,
297,
789,
267,
372,
849,
63,
888,
339,
347,
8775,
8,
277,
304,
267,
327,
1218,
4011,
18,
6802,
267,
340,
291,
14,
888,
459,
2103,
63,
32071,
418,
1137,
10812,
288,
291,
14,
888,
459,
2139,
2545,
4965,
418,
275,
291,
14,
888,
459,
2103,
63,
32071,
418,
398,
327,
900,
314,
1056,
267,
367,
1166,
315,
291,
14,
888,
459,
2103,
63,
633,
2565,
288,
291,
14,
793,
14,
1757,
480,
7112,
316,
450,
83,
401,
620,
8,
633,
430,
288,
2648,
63,
928,
275,
2197,
14,
2083,
14,
2131,
342,
288,
2648,
275,
4011,
18,
14,
2017,
8,
633,
12,
2323,
29,
277,
14,
888,
459,
2139,
1105,
288,
862,
26,
355,
2429,
275,
4011,
18,
14,
10890,
8,
2103,
9,
355,
314,
63,
1606,
275,
2429,
14,
739,
342,
355,
2648,
63,
500,
275,
2197,
14,
2083,
14,
2131,
342,
355,
2648,
63,
521,
275,
2648,
63,
500,
446,
2648,
63,
928,
2234,
327,
1900,
282,
9025,
536,
520,
949,
7815,
436,
949,
29957,
315,
314,
536,
355,
6370,
63,
354,
275,
1166,
14,
1814,
8,
490,
17220,
2513,
1959,
1814,
8,
490,
22608,
2513,
1959,
1814,
8,
490,
6468,
297,
12548,
1814,
8,
490,
25475,
4074,
355,
327,
6370,
63,
354,
275,
1166,
14,
1294,
19031,
1988,
17,
1055,
1814,
30381,
2668,
531,
355,
340,
6370,
63,
354,
508,
8061,
490,
6370,
63,
354,
275,
298,
1231,
2,
355,
291,
14,
4763,
63,
26775,
8,
490,
6370,
63,
354,
435,
1987,
521,
297,
490,
2648,
63,
521,
14,
4515,
627,
19492,
435,
2648,
63,
521,
14,
18144,
9,
355,
291,
14,
4763,
63,
26775,
8,
490,
6370,
63,
354,
435,
1987,
890,
297,
490,
822,
8,
1589,
63,
1606,
430,
953,
871,
5925,
12,
325,
26,
355,
291,
14,
793,
14,
705,
480,
6005,
370,
1551,
450,
83,
401,
3044,
291,
14,
888,
459,
2103,
63,
633,
1105,
288,
871,
2186,
12,
325,
26,
355,
291,
14,
793,
14,
705,
480,
5912,
1125,
13618,
1166,
26,
450,
83,
401,
325,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
EasonYi/flask
|
tests/test_signals.py
|
149
|
5418
|
# -*- coding: utf-8 -*-
"""
tests.signals
~~~~~~~~~~~~~~~~~~~~~~~
Signalling.
:copyright: (c) 2015 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""
import pytest
try:
import blinker
except ImportError:
blinker = None
import flask
pytestmark = pytest.mark.skipif(
blinker is None,
reason='Signals require the blinker library.'
)
def test_template_rendered():
app = flask.Flask(__name__)
@app.route('/')
def index():
return flask.render_template('simple_template.html', whiskey=42)
recorded = []
def record(sender, template, context):
recorded.append((template, context))
flask.template_rendered.connect(record, app)
try:
app.test_client().get('/')
assert len(recorded) == 1
template, context = recorded[0]
assert template.name == 'simple_template.html'
assert context['whiskey'] == 42
finally:
flask.template_rendered.disconnect(record, app)
def test_before_render_template():
app = flask.Flask(__name__)
@app.route('/')
def index():
return flask.render_template('simple_template.html', whiskey=42)
recorded = []
def record(sender, template, context):
context['whiskey'] = 43
recorded.append((template, context))
flask.before_render_template.connect(record, app)
try:
rv = app.test_client().get('/')
assert len(recorded) == 1
template, context = recorded[0]
assert template.name == 'simple_template.html'
assert context['whiskey'] == 43
assert rv.data == b'<h1>43</h1>'
finally:
flask.before_render_template.disconnect(record, app)
def test_request_signals():
app = flask.Flask(__name__)
calls = []
def before_request_signal(sender):
calls.append('before-signal')
def after_request_signal(sender, response):
assert response.data == b'stuff'
calls.append('after-signal')
@app.before_request
def before_request_handler():
calls.append('before-handler')
@app.after_request
def after_request_handler(response):
calls.append('after-handler')
response.data = 'stuff'
return response
@app.route('/')
def index():
calls.append('handler')
return 'ignored anyway'
flask.request_started.connect(before_request_signal, app)
flask.request_finished.connect(after_request_signal, app)
try:
rv = app.test_client().get('/')
assert rv.data == b'stuff'
assert calls == ['before-signal', 'before-handler', 'handler',
'after-handler', 'after-signal']
finally:
flask.request_started.disconnect(before_request_signal, app)
flask.request_finished.disconnect(after_request_signal, app)
def test_request_exception_signal():
app = flask.Flask(__name__)
recorded = []
@app.route('/')
def index():
1 // 0
def record(sender, exception):
recorded.append(exception)
flask.got_request_exception.connect(record, app)
try:
assert app.test_client().get('/').status_code == 500
assert len(recorded) == 1
assert isinstance(recorded[0], ZeroDivisionError)
finally:
flask.got_request_exception.disconnect(record, app)
def test_appcontext_signals():
app = flask.Flask(__name__)
recorded = []
def record_push(sender, **kwargs):
recorded.append('push')
def record_pop(sender, **kwargs):
recorded.append('pop')
@app.route('/')
def index():
return 'Hello'
flask.appcontext_pushed.connect(record_push, app)
flask.appcontext_popped.connect(record_pop, app)
try:
with app.test_client() as c:
rv = c.get('/')
assert rv.data == b'Hello'
assert recorded == ['push']
assert recorded == ['push', 'pop']
finally:
flask.appcontext_pushed.disconnect(record_push, app)
flask.appcontext_popped.disconnect(record_pop, app)
def test_flash_signal():
app = flask.Flask(__name__)
app.config['SECRET_KEY'] = 'secret'
@app.route('/')
def index():
flask.flash('This is a flash message', category='notice')
return flask.redirect('/other')
recorded = []
def record(sender, message, category):
recorded.append((message, category))
flask.message_flashed.connect(record, app)
try:
client = app.test_client()
with client.session_transaction():
client.get('/')
assert len(recorded) == 1
message, category = recorded[0]
assert message == 'This is a flash message'
assert category == 'notice'
finally:
flask.message_flashed.disconnect(record, app)
def test_appcontext_tearing_down_signal():
app = flask.Flask(__name__)
recorded = []
def record_teardown(sender, **kwargs):
recorded.append(('tear_down', kwargs))
@app.route('/')
def index():
1 // 0
flask.appcontext_tearing_down.connect(record_teardown, app)
try:
with app.test_client() as c:
rv = c.get('/')
assert rv.status_code == 500
assert recorded == []
assert recorded == [('tear_down', {'exc': None})]
finally:
flask.appcontext_tearing_down.disconnect(record_teardown, app)
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
2295,
14,
10458,
272,
18294,
2878,
23597,
339,
6632,
26039,
14,
339,
520,
7307,
26,
334,
67,
9,
6900,
701,
1952,
827,
32472,
19728,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
199,
646,
4613,
199,
199,
893,
26,
272,
492,
330,
20311,
199,
2590,
3545,
26,
272,
330,
20311,
275,
488,
199,
199,
646,
7209,
421,
199,
4462,
1657,
275,
4613,
14,
1657,
14,
22696,
8,
272,
330,
20311,
365,
488,
12,
272,
4499,
534,
28536,
4409,
314,
330,
20311,
3555,
3530,
199,
9,
199,
199,
318,
511,
63,
1160,
63,
16841,
837,
272,
1145,
275,
7209,
14,
14182,
3460,
354,
3368,
339,
768,
571,
14,
4449,
7825,
272,
347,
1478,
837,
267,
372,
7209,
14,
3352,
63,
1160,
360,
4129,
63,
1160,
14,
1360,
297,
704,
374,
498,
29,
2260,
9,
339,
18894,
275,
942,
339,
347,
2777,
8,
8114,
12,
1978,
12,
1067,
304,
267,
18894,
14,
740,
1332,
1160,
12,
1067,
430,
339,
7209,
14,
1160,
63,
16841,
14,
2242,
8,
3059,
12,
1145,
9,
272,
862,
26,
267,
1145,
14,
396,
63,
1258,
1252,
362,
7825,
267,
702,
822,
8,
264,
15402,
9,
508,
413,
267,
1978,
12,
1067,
275,
18894,
59,
16,
61,
267,
702,
1978,
14,
354,
508,
283,
4129,
63,
1160,
14,
1360,
7,
267,
702,
1067,
459,
87,
866,
498,
418,
508,
5685,
272,
3753,
26,
267,
7209,
14,
1160,
63,
16841,
14,
10673,
8,
3059,
12,
1145,
9,
199,
199,
318,
511,
63,
5182,
63,
3352,
63,
1160,
837,
272,
1145,
275,
7209,
14,
14182,
3460,
354,
3368,
339,
768,
571,
14,
4449,
7825,
272,
347,
1478,
837,
267,
372,
7209,
14,
3352,
63,
1160,
360,
4129,
63,
1160,
14,
1360,
297,
704,
374,
498,
29,
2260,
9,
339,
18894,
275,
942,
339,
347,
2777,
8,
8114,
12,
1978,
12,
1067,
304,
267,
1067,
459,
87,
866,
498,
418,
275,
11851,
267,
18894,
14,
740,
1332,
1160,
12,
1067,
430,
339,
7209,
14,
5182,
63,
3352,
63,
1160,
14,
2242,
8,
3059,
12,
1145,
9,
272,
862,
26,
267,
4336,
275,
1145,
14,
396,
63,
1258,
1252,
362,
7825,
267,
702,
822,
8,
264,
15402,
9,
508,
413,
267,
1978,
12,
1067,
275,
18894,
59,
16,
61,
267,
702,
1978,
14,
354,
508,
283,
4129,
63,
1160,
14,
1360,
7,
267,
702,
1067,
459,
87,
866,
498,
418,
508,
11851,
267,
702,
4336,
14,
576,
508,
330,
7601,
72,
17,
30,
2824,
1108,
72,
17,
3524,
272,
3753,
26,
267,
7209,
14,
5182,
63,
3352,
63,
1160,
14,
10673,
8,
3059,
12,
1145,
9,
199,
199,
318,
511,
63,
1069,
63,
10458,
837,
272,
1145,
275,
7209,
14,
14182,
3460,
354,
3368,
272,
4882,
275,
942,
339,
347,
2544,
63,
1069,
63,
4653,
8,
8114,
304,
267,
4882,
14,
740,
360,
5182,
13,
4653,
358,
339,
347,
2410,
63,
1069,
63,
4653,
8,
8114,
12,
1177,
304,
267,
702,
1177,
14,
576,
508,
330,
1159,
84,
3043,
7,
267,
4882,
14,
740,
360,
4399,
13,
4653,
358,
339,
768,
571,
14,
5182,
63,
1069,
272,
347,
2544,
63,
1069,
63,
2232,
837,
267,
4882,
14,
740,
360,
5182,
13,
2232,
358,
339,
768,
571,
14,
4399,
63,
1069,
272,
347,
2410,
63,
1069,
63,
2232,
8,
1310,
304,
267,
4882,
14,
740,
360,
4399,
13,
2232,
358,
267,
1177,
14,
576,
275,
283,
14573,
7,
267,
372,
1177,
339,
768,
571,
14,
4449,
7825,
272,
347,
1478,
837,
267,
4882,
14,
740,
360,
2232,
358,
267,
372,
283,
11996,
15988,
7,
339,
7209,
14,
1069,
63,
8924,
14,
2242,
8,
5182,
63,
1069,
63,
4653,
12,
1145,
9,
272,
7209,
14,
1069,
63,
8669,
14,
2242,
8,
4399,
63,
1069,
63,
4653,
12,
1145,
9,
339,
862,
26,
267,
4336,
275,
1145,
14,
396,
63,
1258,
1252,
362,
7825,
267,
702,
4336,
14,
576,
508,
330,
1159,
84,
3043,
7,
398,
702,
4882,
508,
788,
5182,
13,
4653,
297,
283,
5182,
13,
2232,
297,
283,
2232,
297,
586,
283,
4399,
13,
2232,
297,
283,
4399,
13,
4653,
418,
272,
3753,
26,
267,
7209,
14,
1069,
63,
8924,
14,
10673,
8,
5182,
63,
1069,
63,
4653,
12,
1145,
9,
267,
7209,
14,
1069,
63,
8669,
14,
10673,
8,
4399,
63,
1069,
63,
4653,
12,
1145,
9,
199,
199,
318,
511,
63,
1069,
63,
1971,
63,
4653,
837,
272,
1145,
275,
7209,
14,
14182,
3460,
354,
3368,
272,
18894,
275,
942,
339,
768,
571,
14,
4449,
7825,
272,
347,
1478,
837,
267,
413,
5001,
378,
339,
347,
2777,
8,
8114,
12,
1919,
304,
267,
18894,
14,
740,
8,
1971,
9,
339,
7209,
14,
7808,
63,
1069,
63,
1971,
14,
2242,
8,
3059,
12,
1145,
9,
272,
862,
26,
267,
702,
1145,
14,
396,
63,
1258,
1252,
362,
2336,
1959,
1205,
63,
600,
508,
6891,
267,
702,
822,
8,
264,
15402,
9,
508,
413,
267,
702,
1228,
8,
264,
15402,
59,
16,
467,
25838,
9,
272,
3753,
26,
267,
7209,
14,
7808,
63,
1069,
63,
1971,
14,
10673,
8,
3059,
12,
1145,
9,
199,
199,
318,
511,
63,
571,
1100,
63,
10458,
837,
272,
1145,
275,
7209,
14,
14182,
3460,
354,
3368,
272,
18894,
275,
942,
339,
347,
2777,
63,
5335,
8,
8114,
12,
1011,
958,
304,
267,
18894,
14,
740,
360,
5335,
358,
339,
347,
2777,
63,
1935,
8,
8114,
12,
1011,
958,
304,
267,
18894,
14,
740,
360,
1935,
358,
339,
768,
571,
14,
4449,
7825,
272,
347,
1478,
837,
267,
372,
283,
6257,
7,
339,
7209,
14,
571,
1100,
63,
5335,
379,
14,
2242,
8,
3059,
63,
5335,
12,
1145,
9,
272,
7209,
14,
571,
1100,
63,
1935,
1915,
14,
2242,
8,
3059,
63,
1935,
12,
1145,
9,
272,
862,
26,
267,
543,
1145,
14,
396,
63,
1258,
342,
465,
286,
26,
288,
4336,
275,
286,
14,
362,
7825,
288,
702,
4336,
14,
576,
508,
330,
7,
6257,
7,
288,
702,
18894,
508,
788,
5335,
418,
267,
702,
18894,
508,
788,
5335,
297,
283,
1935,
418,
272,
3753,
26,
267,
7209,
14,
571,
1100,
63,
5335,
379,
14,
10673,
8,
3059,
63,
5335,
12,
1145
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
2295,
14,
10458,
272,
18294,
2878,
23597,
339,
6632,
26039,
14,
339,
520,
7307,
26,
334,
67,
9,
6900,
701,
1952,
827,
32472,
19728,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
199,
646,
4613,
199,
199,
893,
26,
272,
492,
330,
20311,
199,
2590,
3545,
26,
272,
330,
20311,
275,
488,
199,
199,
646,
7209,
421,
199,
4462,
1657,
275,
4613,
14,
1657,
14,
22696,
8,
272,
330,
20311,
365,
488,
12,
272,
4499,
534,
28536,
4409,
314,
330,
20311,
3555,
3530,
199,
9,
199,
199,
318,
511,
63,
1160,
63,
16841,
837,
272,
1145,
275,
7209,
14,
14182,
3460,
354,
3368,
339,
768,
571,
14,
4449,
7825,
272,
347,
1478,
837,
267,
372,
7209,
14,
3352,
63,
1160,
360,
4129,
63,
1160,
14,
1360,
297,
704,
374,
498,
29,
2260,
9,
339,
18894,
275,
942,
339,
347,
2777,
8,
8114,
12,
1978,
12,
1067,
304,
267,
18894,
14,
740,
1332,
1160,
12,
1067,
430,
339,
7209,
14,
1160,
63,
16841,
14,
2242,
8,
3059,
12,
1145,
9,
272,
862,
26,
267,
1145,
14,
396,
63,
1258,
1252,
362,
7825,
267,
702,
822,
8,
264,
15402,
9,
508,
413,
267,
1978,
12,
1067,
275,
18894,
59,
16,
61,
267,
702,
1978,
14,
354,
508,
283,
4129,
63,
1160,
14,
1360,
7,
267,
702,
1067,
459,
87,
866,
498,
418,
508,
5685,
272,
3753,
26,
267,
7209,
14,
1160,
63,
16841,
14,
10673,
8,
3059,
12,
1145,
9,
199,
199,
318,
511,
63,
5182,
63,
3352,
63,
1160,
837,
272,
1145,
275,
7209,
14,
14182,
3460,
354,
3368,
339,
768,
571,
14,
4449,
7825,
272,
347,
1478,
837,
267,
372,
7209,
14,
3352,
63,
1160,
360,
4129,
63,
1160,
14,
1360,
297,
704,
374,
498,
29,
2260,
9,
339,
18894,
275,
942,
339,
347,
2777,
8,
8114,
12,
1978,
12,
1067,
304,
267,
1067,
459,
87,
866,
498,
418,
275,
11851,
267,
18894,
14,
740,
1332,
1160,
12,
1067,
430,
339,
7209,
14,
5182,
63,
3352,
63,
1160,
14,
2242,
8,
3059,
12,
1145,
9,
272,
862,
26,
267,
4336,
275,
1145,
14,
396,
63,
1258,
1252,
362,
7825,
267,
702,
822,
8,
264,
15402,
9,
508,
413,
267,
1978,
12,
1067,
275,
18894,
59,
16,
61,
267,
702,
1978,
14,
354,
508,
283,
4129,
63,
1160,
14,
1360,
7,
267,
702,
1067,
459,
87,
866,
498,
418,
508,
11851,
267,
702,
4336,
14,
576,
508,
330,
7601,
72,
17,
30,
2824,
1108,
72,
17,
3524,
272,
3753,
26,
267,
7209,
14,
5182,
63,
3352,
63,
1160,
14,
10673,
8,
3059,
12,
1145,
9,
199,
199,
318,
511,
63,
1069,
63,
10458,
837,
272,
1145,
275,
7209,
14,
14182,
3460,
354,
3368,
272,
4882,
275,
942,
339,
347,
2544,
63,
1069,
63,
4653,
8,
8114,
304,
267,
4882,
14,
740,
360,
5182,
13,
4653,
358,
339,
347,
2410,
63,
1069,
63,
4653,
8,
8114,
12,
1177,
304,
267,
702,
1177,
14,
576,
508,
330,
1159,
84,
3043,
7,
267,
4882,
14,
740,
360,
4399,
13,
4653,
358,
339,
768,
571,
14,
5182,
63,
1069,
272,
347,
2544,
63,
1069,
63,
2232,
837,
267,
4882,
14,
740,
360,
5182,
13,
2232,
358,
339,
768,
571,
14,
4399,
63,
1069,
272,
347,
2410,
63,
1069,
63,
2232,
8,
1310,
304,
267,
4882,
14,
740,
360,
4399,
13,
2232,
358,
267,
1177,
14,
576,
275,
283,
14573,
7,
267,
372,
1177,
339,
768,
571,
14,
4449,
7825,
272,
347,
1478,
837,
267,
4882,
14,
740,
360,
2232,
358,
267,
372,
283,
11996,
15988,
7,
339,
7209,
14,
1069,
63,
8924,
14,
2242,
8,
5182,
63,
1069,
63,
4653,
12,
1145,
9,
272,
7209,
14,
1069,
63,
8669,
14,
2242,
8,
4399,
63,
1069,
63,
4653,
12,
1145,
9,
339,
862,
26,
267,
4336,
275,
1145,
14,
396,
63,
1258,
1252,
362,
7825,
267,
702,
4336,
14,
576,
508,
330,
1159,
84,
3043,
7,
398,
702,
4882,
508,
788,
5182,
13,
4653,
297,
283,
5182,
13,
2232,
297,
283,
2232,
297,
586,
283,
4399,
13,
2232,
297,
283,
4399,
13,
4653,
418,
272,
3753,
26,
267,
7209,
14,
1069,
63,
8924,
14,
10673,
8,
5182,
63,
1069,
63,
4653,
12,
1145,
9,
267,
7209,
14,
1069,
63,
8669,
14,
10673,
8,
4399,
63,
1069,
63,
4653,
12,
1145,
9,
199,
199,
318,
511,
63,
1069,
63,
1971,
63,
4653,
837,
272,
1145,
275,
7209,
14,
14182,
3460,
354,
3368,
272,
18894,
275,
942,
339,
768,
571,
14,
4449,
7825,
272,
347,
1478,
837,
267,
413,
5001,
378,
339,
347,
2777,
8,
8114,
12,
1919,
304,
267,
18894,
14,
740,
8,
1971,
9,
339,
7209,
14,
7808,
63,
1069,
63,
1971,
14,
2242,
8,
3059,
12,
1145,
9,
272,
862,
26,
267,
702,
1145,
14,
396,
63,
1258,
1252,
362,
2336,
1959,
1205,
63,
600,
508,
6891,
267,
702,
822,
8,
264,
15402,
9,
508,
413,
267,
702,
1228,
8,
264,
15402,
59,
16,
467,
25838,
9,
272,
3753,
26,
267,
7209,
14,
7808,
63,
1069,
63,
1971,
14,
10673,
8,
3059,
12,
1145,
9,
199,
199,
318,
511,
63,
571,
1100,
63,
10458,
837,
272,
1145,
275,
7209,
14,
14182,
3460,
354,
3368,
272,
18894,
275,
942,
339,
347,
2777,
63,
5335,
8,
8114,
12,
1011,
958,
304,
267,
18894,
14,
740,
360,
5335,
358,
339,
347,
2777,
63,
1935,
8,
8114,
12,
1011,
958,
304,
267,
18894,
14,
740,
360,
1935,
358,
339,
768,
571,
14,
4449,
7825,
272,
347,
1478,
837,
267,
372,
283,
6257,
7,
339,
7209,
14,
571,
1100,
63,
5335,
379,
14,
2242,
8,
3059,
63,
5335,
12,
1145,
9,
272,
7209,
14,
571,
1100,
63,
1935,
1915,
14,
2242,
8,
3059,
63,
1935,
12,
1145,
9,
272,
862,
26,
267,
543,
1145,
14,
396,
63,
1258,
342,
465,
286,
26,
288,
4336,
275,
286,
14,
362,
7825,
288,
702,
4336,
14,
576,
508,
330,
7,
6257,
7,
288,
702,
18894,
508,
788,
5335,
418,
267,
702,
18894,
508,
788,
5335,
297,
283,
1935,
418,
272,
3753,
26,
267,
7209,
14,
571,
1100,
63,
5335,
379,
14,
10673,
8,
3059,
63,
5335,
12,
1145,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
CGATOxford/Optic
|
scripts/species_map2species_map.py
|
1
|
2392
|
'''
species_map2species_map.py
=============================================
:Author: Nick Ilott
:Release: $Id$
:Date: |today|
:Tags: Python
Purpose
-------
Convert species ids from a species_map file to names provided from
genome files.
Usage
-----
Example::
python species_map2species_map.py --help
Type::
python species_map2species_map.py --help
for command line help.
Documentation
-------------
This is a script with a very specific purpose. Read names that are sampled from
many genomes using GemReads.py are by default converted into substrings of the
original strings. For sampling contigs using contigs2random_sample.py we require
a species map file with names that correspond to the genomes being simulated.
Therefore this script converts names back to original genome style names using
gi number as the common identifier.
Reads from stdin and outputs to stdout.
Command line options
--------------------
'''
import os
import sys
import re
import optparse
import CGAT.FastaIterator as FastaIterator
import glob
import CGAT.Experiment as E
import CGAT.IOTools as IOTools
def main(argv=None):
"""script main.
parses command line options in sys.argv, unless *argv* is given.
"""
if not argv:
argv = sys.argv
# setup command line parser
parser = optparse.OptionParser(version="%prog version: $Id: script_template.py 2871 2010-03-03 10:20:44Z andreas $",
usage=globals()["__doc__"])
parser.add_option("-g", "--genome-dir", dest="genome_dir", type="string",
help="supply help")
# add common options (-h/--help, ...) and parse command line
(options, args) = E.Start(parser, argv=argv)
contigs_map = {}
for genome in glob.glob(os.path.join(options.genome_dir, "*")):
for fasta in FastaIterator.iterate(IOTools.openFile(genome)):
identifier = fasta.title.split("|")
gi = identifier[1]
contigs_map[gi] = fasta.title
for line in options.stdin.readlines():
data = line[:-1].split("\t")
gi = data[1]
assert gi in contigs_map, "cannot find genome with id gi|%s in genomes directory" % gi
options.stdout.write("%s\t%s\n" % (data[0], contigs_map[gi]))
# write footer and output benchmark information.
E.Stop()
if __name__ == "__main__":
sys.exit(main(sys.argv))
|
mit
|
[
2344,
199,
17168,
63,
1130,
18,
17168,
63,
1130,
14,
647,
199,
2486,
9152,
199,
199,
26,
5949,
26,
653,
2000,
473,
1653,
84,
199,
26,
9625,
26,
2672,
1304,
4,
199,
26,
2506,
26,
1204,
8136,
92,
199,
26,
9440,
26,
2018,
199,
199,
14959,
4070,
199,
12797,
199,
199,
7306,
20340,
2762,
687,
282,
20340,
63,
1130,
570,
370,
1561,
2741,
687,
221,
199,
27776,
1584,
14,
199,
199,
7692,
199,
9858,
199,
199,
9846,
447,
8410,
2366,
20340,
63,
1130,
18,
17168,
63,
1130,
14,
647,
1553,
3437,
199,
199,
804,
447,
8410,
2366,
20340,
63,
1130,
18,
17168,
63,
1130,
14,
647,
1553,
3437,
199,
199,
509,
1414,
1004,
1720,
14,
199,
199,
17763,
199,
8684,
199,
199,
2765,
365,
282,
2884,
543,
282,
7437,
2488,
12016,
14,
5574,
1561,
626,
787,
24914,
687,
199,
3479,
29924,
83,
1808,
5346,
77,
23614,
14,
647,
787,
701,
849,
6702,
1901,
1007,
5465,
402,
314,
221,
199,
5043,
3326,
14,
2104,
15877,
406,
280,
458,
1808,
406,
280,
458,
18,
2355,
63,
3271,
14,
647,
781,
4409,
199,
65,
20340,
2341,
570,
543,
1561,
626,
17118,
370,
314,
29924,
83,
3769,
4389,
8097,
14,
199,
10924,
1707,
642,
2884,
15373,
1561,
1771,
370,
3379,
29924,
3449,
1561,
1808,
199,
6153,
1329,
465,
314,
2863,
5148,
14,
199,
199,
23614,
687,
9009,
436,
4704,
370,
3839,
14,
199,
199,
3110,
1004,
1511,
199,
777,
375,
199,
199,
2344,
199,
199,
646,
747,
199,
646,
984,
199,
646,
295,
199,
646,
8691,
199,
646,
18657,
619,
14,
1906,
1207,
3585,
465,
10859,
1207,
3585,
199,
646,
5739,
199,
646,
18657,
619,
14,
20781,
465,
662,
199,
646,
18657,
619,
14,
2090,
11654,
465,
5004,
11654,
421,
199,
318,
2446,
8,
3020,
29,
403,
304,
272,
408,
1579,
2446,
14,
339,
19953,
1414,
1004,
1511,
315,
984,
14,
3020,
12,
7444,
627,
3020,
10,
365,
1627,
14,
272,
408,
339,
340,
440,
9238,
26,
267,
9238,
275,
984,
14,
3020,
339,
327,
3272,
1414,
1004,
1798,
272,
1798,
275,
8691,
14,
14553,
8,
1023,
5961,
6595,
1015,
26,
2672,
1304,
26,
2884,
63,
1160,
14,
647,
499,
17369,
7129,
13,
1644,
13,
1644,
1616,
26,
1165,
26,
1602,
58,
436,
264,
305,
2672,
401,
3521,
4503,
29,
8473,
22957,
363,
1301,
363,
3135,
339,
1798,
14,
525,
63,
1422,
6096,
71,
401,
4320,
27776,
13,
694,
401,
2053,
628,
27776,
63,
694,
401,
730,
628,
875,
401,
1993,
1720,
628,
8621,
590,
1720,
531,
339,
327,
1050,
2863,
1511,
5868,
72,
25695,
3437,
12,
19172,
436,
2198,
1414,
1004,
272,
334,
1419,
12,
1249,
9,
275,
662,
14,
3162,
8,
2087,
12,
9238,
29,
3020,
9,
339,
406,
280,
458,
63,
1130,
275,
1052,
272,
367,
29924,
315,
5739,
14,
6463,
8,
736,
14,
515,
14,
904,
8,
1419,
14,
27776,
63,
694,
12,
8969,
14150,
267,
367,
30544,
315,
10859,
1207,
3585,
14,
20627,
8,
2090,
11654,
14,
1490,
1173,
8,
27776,
2298,
288,
5148,
275,
30544,
14,
1213,
14,
1294,
25795,
531,
288,
18895,
275,
5148,
59,
17,
61,
288,
406,
280,
458,
63,
1130,
59,
6153,
61,
275,
30544,
14,
1213,
339,
367,
1004,
315,
1511,
14,
6626,
14,
9684,
837,
267,
666,
275,
1004,
4439,
17,
1055,
1294,
4582,
84,
531,
267,
18895,
275,
666,
59,
17,
61,
267,
702,
18895,
315,
406,
280,
458,
63,
1130,
12,
298,
11250,
2342,
29924,
543,
1305,
18895,
15287,
83,
315,
29924,
83,
2082,
2,
450,
18895,
398,
1511,
14,
2703,
14,
952,
3647,
83,
60,
84,
5,
83,
60,
78,
2,
450,
334,
576,
59,
16,
467,
406,
280,
458,
63,
1130,
59,
6153,
2459,
339,
327,
2218,
14178,
436,
1072,
12338,
2556,
14,
272,
662,
14,
6293,
342,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
984,
14,
2224,
8,
973,
8,
1274,
14,
3020,
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
] |
[
199,
17168,
63,
1130,
18,
17168,
63,
1130,
14,
647,
199,
2486,
9152,
199,
199,
26,
5949,
26,
653,
2000,
473,
1653,
84,
199,
26,
9625,
26,
2672,
1304,
4,
199,
26,
2506,
26,
1204,
8136,
92,
199,
26,
9440,
26,
2018,
199,
199,
14959,
4070,
199,
12797,
199,
199,
7306,
20340,
2762,
687,
282,
20340,
63,
1130,
570,
370,
1561,
2741,
687,
221,
199,
27776,
1584,
14,
199,
199,
7692,
199,
9858,
199,
199,
9846,
447,
8410,
2366,
20340,
63,
1130,
18,
17168,
63,
1130,
14,
647,
1553,
3437,
199,
199,
804,
447,
8410,
2366,
20340,
63,
1130,
18,
17168,
63,
1130,
14,
647,
1553,
3437,
199,
199,
509,
1414,
1004,
1720,
14,
199,
199,
17763,
199,
8684,
199,
199,
2765,
365,
282,
2884,
543,
282,
7437,
2488,
12016,
14,
5574,
1561,
626,
787,
24914,
687,
199,
3479,
29924,
83,
1808,
5346,
77,
23614,
14,
647,
787,
701,
849,
6702,
1901,
1007,
5465,
402,
314,
221,
199,
5043,
3326,
14,
2104,
15877,
406,
280,
458,
1808,
406,
280,
458,
18,
2355,
63,
3271,
14,
647,
781,
4409,
199,
65,
20340,
2341,
570,
543,
1561,
626,
17118,
370,
314,
29924,
83,
3769,
4389,
8097,
14,
199,
10924,
1707,
642,
2884,
15373,
1561,
1771,
370,
3379,
29924,
3449,
1561,
1808,
199,
6153,
1329,
465,
314,
2863,
5148,
14,
199,
199,
23614,
687,
9009,
436,
4704,
370,
3839,
14,
199,
199,
3110,
1004,
1511,
199,
777,
375,
199,
199,
2344,
199,
199,
646,
747,
199,
646,
984,
199,
646,
295,
199,
646,
8691,
199,
646,
18657,
619,
14,
1906,
1207,
3585,
465,
10859,
1207,
3585,
199,
646,
5739,
199,
646,
18657,
619,
14,
20781,
465,
662,
199,
646,
18657,
619,
14,
2090,
11654,
465,
5004,
11654,
421,
199,
318,
2446,
8,
3020,
29,
403,
304,
272,
408,
1579,
2446,
14,
339,
19953,
1414,
1004,
1511,
315,
984,
14,
3020,
12,
7444,
627,
3020,
10,
365,
1627,
14,
272,
408,
339,
340,
440,
9238,
26,
267,
9238,
275,
984,
14,
3020,
339,
327,
3272,
1414,
1004,
1798,
272,
1798,
275,
8691,
14,
14553,
8,
1023,
5961,
6595,
1015,
26,
2672,
1304,
26,
2884,
63,
1160,
14,
647,
499,
17369,
7129,
13,
1644,
13,
1644,
1616,
26,
1165,
26,
1602,
58,
436,
264,
305,
2672,
401,
3521,
4503,
29,
8473,
22957,
363,
1301,
363,
3135,
339,
1798,
14,
525,
63,
1422,
6096,
71,
401,
4320,
27776,
13,
694,
401,
2053,
628,
27776,
63,
694,
401,
730,
628,
875,
401,
1993,
1720,
628,
8621,
590,
1720,
531,
339,
327,
1050,
2863,
1511,
5868,
72,
25695,
3437,
12,
19172,
436,
2198,
1414,
1004,
272,
334,
1419,
12,
1249,
9,
275,
662,
14,
3162,
8,
2087,
12,
9238,
29,
3020,
9,
339,
406,
280,
458,
63,
1130,
275,
1052,
272,
367,
29924,
315,
5739,
14,
6463,
8,
736,
14,
515,
14,
904,
8,
1419,
14,
27776,
63,
694,
12,
8969,
14150,
267,
367,
30544,
315,
10859,
1207,
3585,
14,
20627,
8,
2090,
11654,
14,
1490,
1173,
8,
27776,
2298,
288,
5148,
275,
30544,
14,
1213,
14,
1294,
25795,
531,
288,
18895,
275,
5148,
59,
17,
61,
288,
406,
280,
458,
63,
1130,
59,
6153,
61,
275,
30544,
14,
1213,
339,
367,
1004,
315,
1511,
14,
6626,
14,
9684,
837,
267,
666,
275,
1004,
4439,
17,
1055,
1294,
4582,
84,
531,
267,
18895,
275,
666,
59,
17,
61,
267,
702,
18895,
315,
406,
280,
458,
63,
1130,
12,
298,
11250,
2342,
29924,
543,
1305,
18895,
15287,
83,
315,
29924,
83,
2082,
2,
450,
18895,
398,
1511,
14,
2703,
14,
952,
3647,
83,
60,
84,
5,
83,
60,
78,
2,
450,
334,
576,
59,
16,
467,
406,
280,
458,
63,
1130,
59,
6153,
2459,
339,
327,
2218,
14178,
436,
1072,
12338,
2556,
14,
272,
662,
14,
6293,
342,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
984,
14,
2224,
8,
973,
8,
1274,
14,
3020,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
potato/searx
|
searx/engines/digbt.py
|
5
|
1777
|
"""
DigBT (Videos, Music, Files)
@website https://digbt.org
@provide-api no
@using-api no
@results HTML (using search portal)
@stable no (HTML can change)
@parse url, title, content, magnetlink
"""
from sys import version_info
from lxml import html
from searx.engines.xpath import extract_text
from searx.utils import get_torrent_size
from searx.url_utils import urljoin
if version_info[0] == 3:
unicode = str
categories = ['videos', 'music', 'files']
paging = True
URL = 'https://digbt.org'
SEARCH_URL = URL + '/search/{query}-time-{pageno}'
FILESIZE = 3
FILESIZE_MULTIPLIER = 4
def request(query, params):
params['url'] = SEARCH_URL.format(query=query, pageno=params['pageno'])
return params
def response(resp):
dom = html.fromstring(resp.text)
search_res = dom.xpath('.//td[@class="x-item"]')
if not search_res:
return list()
results = list()
for result in search_res:
url = urljoin(URL, result.xpath('.//a[@title]/@href')[0])
title = extract_text(result.xpath('.//a[@title]'))
content = extract_text(result.xpath('.//div[@class="files"]'))
files_data = extract_text(result.xpath('.//div[@class="tail"]')).split()
filesize = get_torrent_size(files_data[FILESIZE], files_data[FILESIZE_MULTIPLIER])
magnetlink = result.xpath('.//div[@class="tail"]//a[@class="title"]/@href')[0]
results.append({'url': url,
'title': title,
'content': content,
'filesize': filesize,
'magnetlink': magnetlink,
'seed': 'N/A',
'leech': 'N/A',
'template': 'torrent.html'})
return results
|
agpl-3.0
|
[
624,
199,
22442,
19162,
334,
2201,
18808,
12,
28919,
9916,
12,
16920,
9,
421,
768,
7360,
258,
4178,
921,
328,
4908,
84,
14,
1308,
199,
768,
20824,
13,
1246,
949,
421,
768,
4941,
13,
1246,
257,
949,
199,
768,
2604,
258,
4163,
334,
4941,
2754,
18428,
9,
199,
768,
11989,
420,
949,
334,
4943,
883,
1570,
9,
199,
768,
1122,
755,
1166,
12,
2538,
12,
1564,
12,
15916,
386,
1073,
199,
624,
199,
199,
504,
984,
492,
1015,
63,
815,
199,
504,
14490,
492,
3517,
199,
504,
542,
285,
88,
14,
30378,
14,
8006,
492,
5536,
63,
505,
199,
504,
542,
285,
88,
14,
1208,
492,
664,
63,
14101,
63,
890,
199,
504,
542,
285,
88,
14,
633,
63,
1208,
492,
20818,
199,
199,
692,
1015,
63,
815,
59,
16,
61,
508,
650,
26,
272,
2649,
275,
620,
199,
199,
8906,
275,
788,
11418,
297,
283,
20544,
297,
283,
1725,
418,
199,
31691,
275,
715,
199,
199,
2632,
275,
283,
2859,
921,
328,
4908,
84,
14,
1308,
7,
199,
15962,
63,
2632,
275,
2851,
435,
1994,
1733,
5321,
1131,
17063,
521,
24185,
387,
2268,
79,
6834,
199,
9472,
11025,
275,
650,
199,
9472,
11025,
63,
21894,
2673,
540,
275,
841,
421,
199,
318,
1056,
8,
1131,
12,
1862,
304,
272,
1862,
459,
633,
418,
275,
5795,
7762,
63,
2632,
14,
908,
8,
1131,
29,
1131,
12,
9881,
287,
79,
29,
1162,
459,
387,
2268,
79,
1105,
339,
372,
1862,
421,
199,
318,
1177,
8,
4518,
304,
272,
8266,
275,
3517,
14,
13521,
8,
4518,
14,
505,
9,
272,
2754,
63,
470,
275,
8266,
14,
8006,
29995,
2076,
14251,
533,
628,
88,
13,
1053,
937,
358,
339,
340,
440,
2754,
63,
470,
26,
267,
372,
769,
342,
339,
2058,
275,
769,
342,
272,
367,
754,
315,
2754,
63,
470,
26,
267,
1166,
275,
20818,
8,
2632,
12,
754,
14,
8006,
29995,
65,
14251,
1213,
12978,
32,
6399,
5832,
16,
566,
267,
2538,
275,
5536,
63,
505,
8,
1099,
14,
8006,
29995,
65,
14251,
1213,
28869,
267,
1564,
275,
5536,
63,
505,
8,
1099,
14,
8006,
29995,
3015,
14251,
533,
628,
1725,
937,
1333,
267,
1584,
63,
576,
275,
5536,
63,
505,
8,
1099,
14,
8006,
29995,
3015,
14251,
533,
628,
1521,
937,
11103,
1294,
342,
267,
23858,
275,
664,
63,
14101,
63,
890,
8,
1725,
63,
576,
59,
9472,
11025,
467,
1584,
63,
576,
59,
9472,
11025,
63,
21894,
2673,
540,
566,
267,
15916,
386,
1073,
275,
754,
14,
8006,
29995,
3015,
14251,
533,
628,
1521,
937,
501,
65,
14251,
533,
628,
1213,
937,
15,
32,
6399,
5832,
16,
61,
398,
2058,
14,
740,
3252,
633,
356,
1166,
12,
717,
283,
1213,
356,
2538,
12,
717,
283,
1317,
356,
1564,
12,
717,
283,
19233,
356,
23858,
12,
717,
283,
19902,
386,
1073,
356,
15916,
386,
1073,
12,
717,
283,
5176,
356,
283,
46,
15,
33,
297,
717,
283,
274,
12736,
356,
283,
46,
15,
33,
297,
717,
283,
1160,
356,
283,
14101,
14,
1360,
3071,
339,
372,
2058,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
22442,
19162,
334,
2201,
18808,
12,
28919,
9916,
12,
16920,
9,
421,
768,
7360,
258,
4178,
921,
328,
4908,
84,
14,
1308,
199,
768,
20824,
13,
1246,
949,
421,
768,
4941,
13,
1246,
257,
949,
199,
768,
2604,
258,
4163,
334,
4941,
2754,
18428,
9,
199,
768,
11989,
420,
949,
334,
4943,
883,
1570,
9,
199,
768,
1122,
755,
1166,
12,
2538,
12,
1564,
12,
15916,
386,
1073,
199,
624,
199,
199,
504,
984,
492,
1015,
63,
815,
199,
504,
14490,
492,
3517,
199,
504,
542,
285,
88,
14,
30378,
14,
8006,
492,
5536,
63,
505,
199,
504,
542,
285,
88,
14,
1208,
492,
664,
63,
14101,
63,
890,
199,
504,
542,
285,
88,
14,
633,
63,
1208,
492,
20818,
199,
199,
692,
1015,
63,
815,
59,
16,
61,
508,
650,
26,
272,
2649,
275,
620,
199,
199,
8906,
275,
788,
11418,
297,
283,
20544,
297,
283,
1725,
418,
199,
31691,
275,
715,
199,
199,
2632,
275,
283,
2859,
921,
328,
4908,
84,
14,
1308,
7,
199,
15962,
63,
2632,
275,
2851,
435,
1994,
1733,
5321,
1131,
17063,
521,
24185,
387,
2268,
79,
6834,
199,
9472,
11025,
275,
650,
199,
9472,
11025,
63,
21894,
2673,
540,
275,
841,
421,
199,
318,
1056,
8,
1131,
12,
1862,
304,
272,
1862,
459,
633,
418,
275,
5795,
7762,
63,
2632,
14,
908,
8,
1131,
29,
1131,
12,
9881,
287,
79,
29,
1162,
459,
387,
2268,
79,
1105,
339,
372,
1862,
421,
199,
318,
1177,
8,
4518,
304,
272,
8266,
275,
3517,
14,
13521,
8,
4518,
14,
505,
9,
272,
2754,
63,
470,
275,
8266,
14,
8006,
29995,
2076,
14251,
533,
628,
88,
13,
1053,
937,
358,
339,
340,
440,
2754,
63,
470,
26,
267,
372,
769,
342,
339,
2058,
275,
769,
342,
272,
367,
754,
315,
2754,
63,
470,
26,
267,
1166,
275,
20818,
8,
2632,
12,
754,
14,
8006,
29995,
65,
14251,
1213,
12978,
32,
6399,
5832,
16,
566,
267,
2538,
275,
5536,
63,
505,
8,
1099,
14,
8006,
29995,
65,
14251,
1213,
28869,
267,
1564,
275,
5536,
63,
505,
8,
1099,
14,
8006,
29995,
3015,
14251,
533,
628,
1725,
937,
1333,
267,
1584,
63,
576,
275,
5536,
63,
505,
8,
1099,
14,
8006,
29995,
3015,
14251,
533,
628,
1521,
937,
11103,
1294,
342,
267,
23858,
275,
664,
63,
14101,
63,
890,
8,
1725,
63,
576,
59,
9472,
11025,
467,
1584,
63,
576,
59,
9472,
11025,
63,
21894,
2673,
540,
566,
267,
15916,
386,
1073,
275,
754,
14,
8006,
29995,
3015,
14251,
533,
628,
1521,
937,
501,
65,
14251,
533,
628,
1213,
937,
15,
32,
6399,
5832,
16,
61,
398,
2058,
14,
740,
3252,
633,
356,
1166,
12,
717,
283,
1213,
356,
2538,
12,
717,
283,
1317,
356,
1564,
12,
717,
283,
19233,
356,
23858,
12,
717,
283,
19902,
386,
1073,
356,
15916,
386,
1073,
12,
717,
283,
5176,
356,
283,
46,
15,
33,
297,
717,
283,
274,
12736,
356,
283,
46,
15,
33,
297,
717,
283,
1160,
356,
283,
14101,
14,
1360,
3071,
339,
372,
2058,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
aricchen/openHR
|
openerp/addons/stock_location/__openerp__.py
|
59
|
5005
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Advanced Routes',
'version': '1.0',
'category': 'Manufacturing',
'description': """
This module supplements the Warehouse application by effectively implementing Push and Pull inventory flows.
============================================================================================================
Typically this could be used to:
--------------------------------
* Manage product manufacturing chains
* Manage default locations per product
* Define routes within your warehouse according to business needs, such as:
- Quality Control
- After Sales Services
- Supplier Returns
* Help rental management, by generating automated return moves for rented products
Once this module is installed, an additional tab appear on the product form,
where you can add Push and Pull flow specifications. The demo data of CPU1
product for that push/pull :
Push flows:
-----------
Push flows are useful when the arrival of certain products in a given location
should always be followed by a corresponding move to another location, optionally
after a certain delay. The original Warehouse application already supports such
Push flow specifications on the Locations themselves, but these cannot be
refined per-product.
A push flow specification indicates which location is chained with which location,
and with what parameters. As soon as a given quantity of products is moved in the
source location, a chained move is automatically foreseen according to the
parameters set on the flow specification (destination location, delay, type of
move, journal). The new move can be automatically processed, or require a manual
confirmation, depending on the parameters.
Pull flows:
-----------
Pull flows are a bit different from Push flows, in the sense that they are not
related to the processing of product moves, but rather to the processing of
procurement orders. What is being pulled is a need, not directly products. A
classical example of Pull flow is when you have an Outlet company, with a parent
Company that is responsible for the supplies of the Outlet.
[ Customer ] <- A - [ Outlet ] <- B - [ Holding ] <~ C ~ [ Supplier ]
When a new procurement order (A, coming from the confirmation of a Sale Order
for example) arrives in the Outlet, it is converted into another procurement
(B, via a Pull flow of type 'move') requested from the Holding. When procurement
order B is processed by the Holding company, and if the product is out of stock,
it can be converted into a Purchase Order (C) from the Supplier (Pull flow of
type Purchase). The result is that the procurement order, the need, is pushed
all the way between the Customer and Supplier.
Technically, Pull flows allow to process procurement orders differently, not
only depending on the product being considered, but also depending on which
location holds the 'need' for that product (i.e. the destination location of
that procurement order).
Use-Case:
---------
You can use the demo data as follow:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**CPU1:** Sell some CPU1 from Chicago Shop and run the scheduler
- Warehouse: delivery order, Chicago Shop: reception
**CPU3:**
- When receiving the product, it goes to Quality Control location then
stored to shelf 2.
- When delivering the customer: Pick List -> Packing -> Delivery Order from Gate A
""",
'author': 'OpenERP SA',
'images': ['images/pulled_flow.jpeg','images/pushed_flow.jpeg'],
'depends': ['procurement','stock','sale'],
'data': ['stock_location_view.xml', 'security/stock_location_security.xml', 'security/ir.model.access.csv', 'procurement_pull_workflow.xml'],
'demo': [
'stock_location_demo_cpu1.xml',
'stock_location_demo_cpu3.yml',
],
'installable': True,
'test': [
'test/stock_location_pull_flow.yml',
'test/stock_location_push_flow.yml',
],
'auto_install': False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
421,
199,
91,
272,
283,
354,
356,
283,
23613,
19776,
744,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
2395,
7415,
319,
4039,
297,
272,
283,
1802,
356,
408,
199,
2765,
859,
4973,
20446,
314,
644,
11499,
4223,
701,
27881,
18234,
22643,
436,
27705,
8200,
30708,
14,
199,
5695,
2486,
5769,
199,
199,
21718,
7288,
642,
4293,
506,
1202,
370,
26,
199,
1444,
272,
627,
14944,
3336,
2169,
7415,
319,
4039,
30640,
272,
627,
14944,
849,
9918,
1126,
3336,
272,
627,
13930,
15777,
4453,
2195,
13782,
7182,
370,
26440,
4839,
12,
4066,
465,
26,
267,
446,
24108,
8612,
267,
446,
12836,
428,
7098,
21813,
267,
446,
29083,
5697,
1803,
339,
627,
15456,
295,
343,
279,
10041,
12,
701,
12999,
6384,
23513,
372,
14569,
367,
2903,
471,
7585,
199,
199,
25690,
642,
859,
365,
4903,
12,
376,
4722,
5174,
7468,
641,
314,
3336,
1824,
12,
199,
4509,
1265,
883,
1050,
22643,
436,
27705,
6369,
28754,
14,
710,
14779,
666,
402,
11952,
17,
199,
2558,
367,
626,
6675,
15,
9302,
520,
199,
199,
10731,
30708,
26,
199,
13715,
199,
10731,
30708,
787,
2997,
1380,
314,
601,
26976,
402,
9842,
7585,
315,
282,
1627,
2909,
199,
5626,
3544,
506,
9437,
701,
282,
5226,
4057,
370,
4573,
2909,
12,
14190,
199,
4399,
282,
9842,
7339,
14,
710,
3379,
644,
11499,
4223,
2575,
5171,
4066,
199,
10731,
6369,
28754,
641,
314,
6263,
1298,
17279,
12,
1325,
3520,
3913,
506,
199,
1121,
1942,
1126,
13,
2558,
14,
199,
199,
33,
6675,
6369,
8929,
9126,
1314,
2909,
365,
6036,
379,
543,
1314,
2909,
12,
199,
460,
543,
4052,
2633,
14,
3709,
18930,
465,
282,
1627,
12524,
402,
7585,
365,
12155,
315,
314,
199,
1365,
2909,
12,
282,
6036,
379,
4057,
365,
5847,
11257,
8606,
7182,
370,
314,
199,
3214,
663,
641,
314,
6369,
8929,
334,
6881,
2909,
12,
7339,
12,
730,
402,
199,
1185,
12,
9605,
680,
710,
892,
4057,
883,
506,
5847,
7686,
12,
503,
4409,
282,
8722,
199,
20903,
12,
10298,
641,
314,
2633,
14,
199,
199,
27318,
30708,
26,
199,
13715,
199,
27318,
30708,
787,
282,
4546,
3365,
687,
22643,
30708,
12,
315,
314,
12249,
626,
2985,
787,
440,
199,
2407,
370,
314,
6661,
402,
3336,
14569,
12,
1325,
7830,
370,
314,
6661,
402,
199,
18546,
15460,
14,
14791,
365,
3769,
25239,
1146,
365,
282,
1929,
12,
440,
5370,
7585,
14,
437,
199,
12334,
915,
2893,
402,
27705,
6369,
365,
1380,
1265,
1172,
376,
6219,
2723,
7233,
12,
543,
282,
1676,
199,
16063,
626,
365,
17845,
367,
314,
4973,
6528,
402,
314,
6219,
2723,
14,
819,
359,
22397,
1622,
25549,
437,
446,
359,
6219,
2723,
1622,
221,
25549,
699,
446,
221,
359,
869,
13122,
1622,
665,
94,
445,
6146,
359,
29083,
5697,
1622,
199,
199,
11423,
282,
892,
16214,
1865,
334,
33,
12,
17262,
687,
314,
18791,
402,
282,
428,
1895,
9240,
199,
509,
2893,
9,
601,
322,
2310,
315,
314,
6219,
2723,
12,
652,
365,
6702,
1901,
4573,
16214,
199,
8,
34,
12,
4799,
282,
27705,
6369,
402,
730,
283,
1185,
358,
5839,
687,
314,
869,
13122,
14,
3979,
16214,
199,
1648,
699,
365,
7686,
701,
314,
869,
13122,
7233,
12,
436,
340,
314,
3336,
365,
734,
402,
10952,
12,
199,
390,
883,
506,
6702,
1901,
282,
23177,
6703,
9240,
334,
35,
9,
687,
314,
29083,
5697,
334,
27318,
6369,
402,
199,
466,
23177,
6703,
680,
710,
754,
365,
626,
314,
16214,
1865,
12,
314,
1929,
12,
365,
22319,
199,
452,
314,
4340,
3382,
314,
22397,
436,
29083,
5697,
14,
199,
199,
6301,
11019,
7288,
12,
27705,
30708,
2040,
370,
2112,
16214,
15460,
23142,
12,
440,
199,
2118,
10298,
641,
314,
3336,
3769,
8652,
12,
1325,
2597,
10298,
641,
1314,
199,
1985,
15164,
314,
283,
9321,
7,
367,
626,
3336,
334,
73,
14,
69,
14,
314,
5724,
2909,
402,
199,
9099,
16214,
1865,
680,
199,
199,
6119,
13,
1538,
26,
199,
9960,
199,
199,
5556,
883,
675,
314,
14779,
666,
465,
2035,
26,
199,
30642,
2878,
523,
1011,
11011,
17,
19003,
428,
1697,
2005,
11952,
17,
687,
2799,
25751,
5244,
411,
436,
1255,
314,
11899,
1362,
446,
644,
11499,
26,
18719,
1865,
12,
2799,
25751,
5244,
411,
26,
295,
814,
523,
1011,
11011,
19,
19003,
1362,
446,
3979,
18390,
314,
3336,
12,
652,
13538,
370,
24108,
8612,
2909,
2066,
2126,
5489,
370,
21920,
276,
499,
14,
1362,
446,
3979,
28503,
316,
314,
15229,
26,
16568,
3820,
1035,
9954,
316,
1035,
1487,
317,
2588,
9240,
687,
598,
323,
437,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
4782,
356,
788,
4782,
15,
80,
348,
1146,
63,
1659,
14,
14230,
1673,
4782,
15,
5335,
379,
63,
1659,
14,
14230,
995,
272,
283,
8912,
356,
788,
18546,
1673,
6088,
1673,
8515,
995,
272,
283,
576,
356,
788,
6088,
63,
1985,
63,
1345,
14,
1652,
297,
283,
4416,
15,
6088,
63,
1985,
63,
4416,
14,
1652,
297,
283,
4416,
15,
723,
14
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
421,
199,
91,
272,
283,
354,
356,
283,
23613,
19776,
744,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
2395,
7415,
319,
4039,
297,
272,
283,
1802,
356,
408,
199,
2765,
859,
4973,
20446,
314,
644,
11499,
4223,
701,
27881,
18234,
22643,
436,
27705,
8200,
30708,
14,
199,
5695,
2486,
5769,
199,
199,
21718,
7288,
642,
4293,
506,
1202,
370,
26,
199,
1444,
272,
627,
14944,
3336,
2169,
7415,
319,
4039,
30640,
272,
627,
14944,
849,
9918,
1126,
3336,
272,
627,
13930,
15777,
4453,
2195,
13782,
7182,
370,
26440,
4839,
12,
4066,
465,
26,
267,
446,
24108,
8612,
267,
446,
12836,
428,
7098,
21813,
267,
446,
29083,
5697,
1803,
339,
627,
15456,
295,
343,
279,
10041,
12,
701,
12999,
6384,
23513,
372,
14569,
367,
2903,
471,
7585,
199,
199,
25690,
642,
859,
365,
4903,
12,
376,
4722,
5174,
7468,
641,
314,
3336,
1824,
12,
199,
4509,
1265,
883,
1050,
22643,
436,
27705,
6369,
28754,
14,
710,
14779,
666,
402,
11952,
17,
199,
2558,
367,
626,
6675,
15,
9302,
520,
199,
199,
10731,
30708,
26,
199,
13715,
199,
10731,
30708,
787,
2997,
1380,
314,
601,
26976,
402,
9842,
7585,
315,
282,
1627,
2909,
199,
5626,
3544,
506,
9437,
701,
282,
5226,
4057,
370,
4573,
2909,
12,
14190,
199,
4399,
282,
9842,
7339,
14,
710,
3379,
644,
11499,
4223,
2575,
5171,
4066,
199,
10731,
6369,
28754,
641,
314,
6263,
1298,
17279,
12,
1325,
3520,
3913,
506,
199,
1121,
1942,
1126,
13,
2558,
14,
199,
199,
33,
6675,
6369,
8929,
9126,
1314,
2909,
365,
6036,
379,
543,
1314,
2909,
12,
199,
460,
543,
4052,
2633,
14,
3709,
18930,
465,
282,
1627,
12524,
402,
7585,
365,
12155,
315,
314,
199,
1365,
2909,
12,
282,
6036,
379,
4057,
365,
5847,
11257,
8606,
7182,
370,
314,
199,
3214,
663,
641,
314,
6369,
8929,
334,
6881,
2909,
12,
7339,
12,
730,
402,
199,
1185,
12,
9605,
680,
710,
892,
4057,
883,
506,
5847,
7686,
12,
503,
4409,
282,
8722,
199,
20903,
12,
10298,
641,
314,
2633,
14,
199,
199,
27318,
30708,
26,
199,
13715,
199,
27318,
30708,
787,
282,
4546,
3365,
687,
22643,
30708,
12,
315,
314,
12249,
626,
2985,
787,
440,
199,
2407,
370,
314,
6661,
402,
3336,
14569,
12,
1325,
7830,
370,
314,
6661,
402,
199,
18546,
15460,
14,
14791,
365,
3769,
25239,
1146,
365,
282,
1929,
12,
440,
5370,
7585,
14,
437,
199,
12334,
915,
2893,
402,
27705,
6369,
365,
1380,
1265,
1172,
376,
6219,
2723,
7233,
12,
543,
282,
1676,
199,
16063,
626,
365,
17845,
367,
314,
4973,
6528,
402,
314,
6219,
2723,
14,
819,
359,
22397,
1622,
25549,
437,
446,
359,
6219,
2723,
1622,
221,
25549,
699,
446,
221,
359,
869,
13122,
1622,
665,
94,
445,
6146,
359,
29083,
5697,
1622,
199,
199,
11423,
282,
892,
16214,
1865,
334,
33,
12,
17262,
687,
314,
18791,
402,
282,
428,
1895,
9240,
199,
509,
2893,
9,
601,
322,
2310,
315,
314,
6219,
2723,
12,
652,
365,
6702,
1901,
4573,
16214,
199,
8,
34,
12,
4799,
282,
27705,
6369,
402,
730,
283,
1185,
358,
5839,
687,
314,
869,
13122,
14,
3979,
16214,
199,
1648,
699,
365,
7686,
701,
314,
869,
13122,
7233,
12,
436,
340,
314,
3336,
365,
734,
402,
10952,
12,
199,
390,
883,
506,
6702,
1901,
282,
23177,
6703,
9240,
334,
35,
9,
687,
314,
29083,
5697,
334,
27318,
6369,
402,
199,
466,
23177,
6703,
680,
710,
754,
365,
626,
314,
16214,
1865,
12,
314,
1929,
12,
365,
22319,
199,
452,
314,
4340,
3382,
314,
22397,
436,
29083,
5697,
14,
199,
199,
6301,
11019,
7288,
12,
27705,
30708,
2040,
370,
2112,
16214,
15460,
23142,
12,
440,
199,
2118,
10298,
641,
314,
3336,
3769,
8652,
12,
1325,
2597,
10298,
641,
1314,
199,
1985,
15164,
314,
283,
9321,
7,
367,
626,
3336,
334,
73,
14,
69,
14,
314,
5724,
2909,
402,
199,
9099,
16214,
1865,
680,
199,
199,
6119,
13,
1538,
26,
199,
9960,
199,
199,
5556,
883,
675,
314,
14779,
666,
465,
2035,
26,
199,
30642,
2878,
523,
1011,
11011,
17,
19003,
428,
1697,
2005,
11952,
17,
687,
2799,
25751,
5244,
411,
436,
1255,
314,
11899,
1362,
446,
644,
11499,
26,
18719,
1865,
12,
2799,
25751,
5244,
411,
26,
295,
814,
523,
1011,
11011,
19,
19003,
1362,
446,
3979,
18390,
314,
3336,
12,
652,
13538,
370,
24108,
8612,
2909,
2066,
2126,
5489,
370,
21920,
276,
499,
14,
1362,
446,
3979,
28503,
316,
314,
15229,
26,
16568,
3820,
1035,
9954,
316,
1035,
1487,
317,
2588,
9240,
687,
598,
323,
437,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
4782,
356,
788,
4782,
15,
80,
348,
1146,
63,
1659,
14,
14230,
1673,
4782,
15,
5335,
379,
63,
1659,
14,
14230,
995,
272,
283,
8912,
356,
788,
18546,
1673,
6088,
1673,
8515,
995,
272,
283,
576,
356,
788,
6088,
63,
1985,
63,
1345,
14,
1652,
297,
283,
4416,
15,
6088,
63,
1985,
63,
4416,
14,
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1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
brandond/ansible
|
lib/ansible/modules/crypto/openssh_cert.py
|
6
|
21127
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2018, David Kainz <dkainz@mgit.at> <dave.jokain@gmx.at>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {
'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'
}
DOCUMENTATION = '''
---
module: openssh_cert
author: "David Kainz (@lolcube)"
version_added: "2.8"
short_description: Generate OpenSSH host or user certificates.
description:
- Generate and regenerate OpenSSH host or user certificates.
requirements:
- "ssh-keygen"
options:
state:
description:
- Whether the host or user certificate should exist or not, taking action if the state is different from what is stated.
type: str
default: "present"
choices: [ 'present', 'absent' ]
type:
description:
- Whether the module should generate a host or a user certificate.
type: str
required: true
choices: ['host', 'user']
force:
description:
- Should the certificate be regenerated even if it already exists and is valid.
type: bool
default: false
path:
description:
- Path of the file containing the certificate.
type: path
required: true
signing_key:
description:
- The path to the private openssh key that is used for signing the public key in order to generate the certificate.
type: path
required: true
public_key:
description:
- The path to the public key that will be signed with the signing key in order to generate the certificate.
type: path
required: true
valid_from:
description:
- "The point in time the certificate is valid from. Time can be specified either as relative time or as absolute timestamp.
Time will always be interpreted as UTC. Valid formats are: C([+-]timespec | YYYY-MM-DD | YYYY-MM-DDTHH:MM:SS | YYYY-MM-DD HH:MM:SS | always)
where timespec can be an integer + C([w | d | h | m | s]) (e.g. C(+32w1d2h).
Note that if using relative time this module is NOT idempotent."
type: str
required: true
valid_to:
description:
- "The point in time the certificate is valid to. Time can be specified either as relative time or as absolute timestamp.
Time will always be interpreted as UTC. Valid formats are: C([+-]timespec | YYYY-MM-DD | YYYY-MM-DDTHH:MM:SS | YYYY-MM-DD HH:MM:SS | forever)
where timespec can be an integer + C([w | d | h | m | s]) (e.g. C(+32w1d2h).
Note that if using relative time this module is NOT idempotent."
type: str
required: true
valid_at:
description:
- "Check if the certificate is valid at a certain point in time. If it is not the certificate will be regenerated.
Time will always be interpreted as UTC. Mainly to be used with relative timespec for I(valid_from) and / or I(valid_to).
Note that if using relative time this module is NOT idempotent."
type: str
principals:
description:
- "Certificates may be limited to be valid for a set of principal (user/host) names.
By default, generated certificates are valid for all users or hosts."
type: list
options:
description:
- "Specify certificate options when signing a key. The option that are valid for user certificates are:"
- "C(clear): Clear all enabled permissions. This is useful for clearing the default set of permissions so permissions may be added individually."
- "C(force-command=command): Forces the execution of command instead of any shell or
command specified by the user when the certificate is used for authentication."
- "C(no-agent-forwarding): Disable ssh-agent forwarding (permitted by default)."
- "C(no-port-forwarding): Disable port forwarding (permitted by default)."
- "C(no-pty Disable): PTY allocation (permitted by default)."
- "C(no-user-rc): Disable execution of C(~/.ssh/rc) by sshd (permitted by default)."
- "C(no-x11-forwarding): Disable X11 forwarding (permitted by default)"
- "C(permit-agent-forwarding): Allows ssh-agent forwarding."
- "C(permit-port-forwarding): Allows port forwarding."
- "C(permit-pty): Allows PTY allocation."
- "C(permit-user-rc): Allows execution of C(~/.ssh/rc) by sshd."
- "C(permit-x11-forwarding): Allows X11 forwarding."
- "C(source-address=address_list): Restrict the source addresses from which the certificate is considered valid.
The C(address_list) is a comma-separated list of one or more address/netmask pairs in CIDR format."
- "At present, no options are valid for host keys."
type: list
identifier:
description:
- Specify the key identity when signing a public key. The identifier that is logged by the server when the certificate is used for authentication.
type: str
extends_documentation_fragment: files
'''
EXAMPLES = '''
# Generate an OpenSSH user certificate that is valid forever and for all users
- openssh_cert:
type: user
signing_key: /path/to/private_key
public_key: /path/to/public_key.pub
path: /path/to/certificate
valid_from: always
valid_to: forever
# Generate an OpenSSH host certificate that is valid for 32 weeks from now and will be regenerated
# if it is valid for less than 2 weeks from the time the module is being run
- openssh_cert:
type: host
signing_key: /path/to/private_key
public_key: /path/to/public_key.pub
path: /path/to/certificate
valid_from: +0s
valid_to: +32w
valid_at: +2w
# Generate an OpenSSH host certificate that is valid forever and only for example.com and examplehost
- openssh_cert:
type: host
signing_key: /path/to/private_key
public_key: /path/to/public_key.pub
path: /path/to/certificate
valid_from: always
valid_to: forever
principals:
- example.com
- examplehost
# Generate an OpenSSH host Certificate that is valid from 21.1.2001 to 21.1.2019
- openssh_cert:
type: host
signing_key: /path/to/private_key
public_key: /path/to/public_key.pub
path: /path/to/certificate
valid_from: "2001-01-21"
valid_to: "2019-01-21"
# Generate an OpenSSH user Certificate with clear and force-command option:
- openssh_cert:
type: user
signing_key: /path/to/private_key
public_key: /path/to/public_key.pub
path: /path/to/certificate
valid_from: always
valid_to: forever
options:
- "clear"
- "force-command=/tmp/bla/foo"
'''
RETURN = '''
type:
description: type of the certificate (host or user)
returned: changed or success
type: str
sample: host
filename:
description: path to the certificate
returned: changed or success
type: str
sample: /tmp/certifivate-cert.pub
info:
description: Information about the certificate. Output of C(ssh-keygen -L -f).
returned: change or success
type: list
'''
import os
import errno
import random
import re
import tempfile
from datetime import datetime
from datetime import MINYEAR, MAXYEAR
from datetime import timedelta
from shutil import copy2
from shutil import rmtree
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.crypto import convert_relative_to_datetime
from ansible.module_utils._text import to_native
class CertificateError(Exception):
pass
class Certificate(object):
def __init__(self, module):
self.state = module.params['state']
self.force = module.params['force']
self.type = module.params['type']
self.signing_key = module.params['signing_key']
self.public_key = module.params['public_key']
self.path = module.params['path']
self.identifier = module.params['identifier']
self.valid_from = module.params['valid_from']
self.valid_to = module.params['valid_to']
self.valid_at = module.params['valid_at']
self.principals = module.params['principals']
self.options = module.params['options']
self.changed = False
self.check_mode = module.check_mode
self.cert_info = {}
if self.state == 'present':
if self.options and self.type == "host":
module.fail_json(msg="Options can only be used with user certificates.")
if self.valid_at:
self.valid_at = self.valid_at.lstrip()
self.valid_from = self.valid_from.lstrip()
self.valid_to = self.valid_to.lstrip()
self.ssh_keygen = module.get_bin_path('ssh-keygen', True)
def generate(self, module):
if not self.is_valid(module, perms_required=False) or self.force:
args = [
self.ssh_keygen,
'-s', self.signing_key
]
validity = ""
if not (self.valid_from == "always" and self.valid_to == "forever"):
if not self.valid_from == "always":
timeobj = self.convert_to_datetime(module, self.valid_from)
validity += (
str(timeobj.year).zfill(4) +
str(timeobj.month).zfill(2) +
str(timeobj.day).zfill(2) +
str(timeobj.hour).zfill(2) +
str(timeobj.minute).zfill(2) +
str(timeobj.second).zfill(2)
)
else:
validity += "19700101010101"
validity += ":"
if self.valid_to == "forever":
# on ssh-keygen versions that have the year 2038 bug this will cause the datetime to be 2038-01-19T04:14:07
timeobj = datetime(MAXYEAR, 12, 31)
else:
timeobj = self.convert_to_datetime(module, self.valid_to)
validity += (
str(timeobj.year).zfill(4) +
str(timeobj.month).zfill(2) +
str(timeobj.day).zfill(2) +
str(timeobj.hour).zfill(2) +
str(timeobj.minute).zfill(2) +
str(timeobj.second).zfill(2)
)
args.extend(["-V", validity])
if self.type == 'host':
args.extend(['-h'])
if self.identifier:
args.extend(['-I', self.identifier])
else:
args.extend(['-I', ""])
if self.principals:
args.extend(['-n', ','.join(self.principals)])
if self.options:
for option in self.options:
args.extend(['-O'])
args.extend([option])
args.extend(['-P', ''])
try:
temp_directory = tempfile.mkdtemp()
copy2(self.public_key, temp_directory)
args.extend([temp_directory + "/" + os.path.basename(self.public_key)])
module.run_command(args, environ_update=dict(TZ="UTC"), check_rc=True)
copy2(temp_directory + "/" + os.path.splitext(os.path.basename(self.public_key))[0] + "-cert.pub", self.path)
rmtree(temp_directory, ignore_errors=True)
proc = module.run_command([self.ssh_keygen, '-L', '-f', self.path])
self.cert_info = proc[1].split()
self.changed = True
except Exception as e:
try:
self.remove()
rmtree(temp_directory, ignore_errors=True)
except OSError as exc:
if exc.errno != errno.ENOENT:
raise CertificateError(exc)
else:
pass
module.fail_json(msg="%s" % to_native(e))
file_args = module.load_file_common_arguments(module.params)
if module.set_fs_attributes_if_different(file_args, False):
self.changed = True
def convert_to_datetime(self, module, timestring):
if self.is_relative(timestring):
result = convert_relative_to_datetime(timestring)
if result is None:
module.fail_json(
msg="'%s' is not a valid time format." % timestring)
else:
return result
else:
formats = ["%Y-%m-%d",
"%Y-%m-%d %H:%M:%S",
"%Y-%m-%dT%H:%M:%S",
]
for fmt in formats:
try:
return datetime.strptime(timestring, fmt)
except ValueError:
pass
module.fail_json(msg="'%s' is not a valid time format" % timestring)
def is_relative(self, timestr):
if timestr.startswith("+") or timestr.startswith("-"):
return True
return False
def is_same_datetime(self, datetime_one, datetime_two):
# This function is for backwards compatability only because .total_seconds() is new in python2.7
def timedelta_total_seconds(timedelta):
return ((timedelta.microseconds + 0.0 + (timedelta.seconds + timedelta.days * 24 * 3600) * 10 ** 6) / 10 ** 6)
# try to use .total_ seconds() from python2.7
try:
return (datetime_one - datetime_two).total_seconds() == 0.0
except AttributeError:
return timedelta_total_seconds(datetime_one - datetime_two) == 0.0
def is_valid(self, module, perms_required=True):
def _check_state():
return os.path.exists(self.path)
if _check_state():
proc = module.run_command([self.ssh_keygen, '-L', '-f', self.path], environ_update=dict(TZ="UTC"), check_rc=False)
if proc[0] != 0:
return False
self.cert_info = proc[1].split()
principals = re.findall("(?<=Principals:)(.*)(?=Critical)", proc[1], re.S)[0].split()
principals = list(map(str.strip, principals))
if principals == ["(none)"]:
principals = None
cert_type = re.findall("( user | host )", proc[1])[0].strip()
validity = re.findall("(from (\\d{4}-\\d{2}-\\d{2}T\\d{2}(:\\d{2}){2}) to (\\d{4}-\\d{2}-\\d{2}T\\d{2}(:\\d{2}){2}))", proc[1])
if validity:
if validity[0][1]:
cert_valid_from = self.convert_to_datetime(module, validity[0][1])
if self.is_same_datetime(cert_valid_from, self.convert_to_datetime(module, "1970-01-01 01:01:01")):
cert_valid_from = datetime(MINYEAR, 1, 1)
else:
cert_valid_from = datetime(MINYEAR, 1, 1)
if validity[0][3]:
cert_valid_to = self.convert_to_datetime(module, validity[0][3])
if self.is_same_datetime(cert_valid_to, self.convert_to_datetime(module, "2038-01-19 03:14:07")):
cert_valid_to = datetime(MAXYEAR, 12, 31)
else:
cert_valid_to = datetime(MAXYEAR, 12, 31)
else:
cert_valid_from = datetime(MINYEAR, 1, 1)
cert_valid_to = datetime(MAXYEAR, 12, 31)
else:
return False
def _check_perms(module):
file_args = module.load_file_common_arguments(module.params)
return not module.set_fs_attributes_if_different(file_args, False)
def _check_type():
return self.type == cert_type
def _check_principals():
if not principals or not self.principals:
return self.principals == principals
return set(self.principals) == set(principals)
def _check_validity(module):
if self.valid_from == "always":
earliest_time = datetime(MINYEAR, 1, 1)
elif self.is_relative(self.valid_from):
earliest_time = None
else:
earliest_time = self.convert_to_datetime(module, self.valid_from)
if self.valid_to == "forever":
last_time = datetime(MAXYEAR, 12, 31)
elif self.is_relative(self.valid_to):
last_time = None
else:
last_time = self.convert_to_datetime(module, self.valid_to)
if earliest_time:
if not self.is_same_datetime(earliest_time, cert_valid_from):
return False
if last_time:
if not self.is_same_datetime(last_time, cert_valid_to):
return False
if self.valid_at:
if cert_valid_from <= self.convert_to_datetime(module, self.valid_at) <= cert_valid_to:
return True
if earliest_time and last_time:
return True
return False
if not perms_required:
return _check_type() and _check_principals() and _check_validity(module)
return _check_perms(module) and _check_type() and _check_principals() and _check_validity(module)
def dump(self):
"""Serialize the object into a dictionary."""
def filter_keywords(arr, keywords):
concated = []
string = ""
for word in arr:
if word in keywords:
concated.append(string)
string = ""
string += " " + word
concated.append(string)
return concated
def format_cert_info():
return filter_keywords(self.cert_info, [
"Type:",
"Public",
"Signing",
"Key",
"Serial:",
"Valid:",
"Principals:",
"Critical",
"Extensions:"])
if self.state == 'present':
result = {
'changed': self.changed,
'type': self.type,
'filename': self.path,
'info': format_cert_info(),
}
else:
result = {
'changed': self.changed,
}
return result
def remove(self):
"""Remove the resource from the filesystem."""
try:
os.remove(self.path)
self.changed = True
except OSError as exc:
if exc.errno != errno.ENOENT:
raise CertificateError(exc)
else:
pass
return
def main():
module = AnsibleModule(
argument_spec=dict(
state=dict(type='str', default='present', choices=['absent', 'present']),
force=dict(type='bool', default=False),
type=dict(type='str', choices=['host', 'user']),
signing_key=dict(type='path'),
public_key=dict(type='path'),
path=dict(type='path', required=True),
identifier=dict(type='str'),
valid_from=dict(type='str'),
valid_to=dict(type='str'),
valid_at=dict(type='str'),
principals=dict(type='list'),
options=dict(type='list'),
),
supports_check_mode=True,
add_file_common_args=True,
required_if=[('state', 'present', ['type', 'signing_key', 'public_key', 'valid_from', 'valid_to'])],
)
def isBaseDir(path):
base_dir = os.path.dirname(path) or '.'
if not os.path.isdir(base_dir):
module.fail_json(
name=base_dir,
msg='The directory %s does not exist or the file is not a directory' % base_dir
)
if module.params['state'] == "present":
isBaseDir(module.params['signing_key'])
isBaseDir(module.params['public_key'])
isBaseDir(module.params['path'])
certificate = Certificate(module)
if certificate.state == 'present':
if module.check_mode:
certificate.changed = module.params['force'] or not certificate.is_valid(module)
else:
try:
certificate.generate(module)
except Exception as exc:
module.fail_json(msg=to_native(exc))
else:
if module.check_mode:
certificate.changed = os.path.exists(module.params['path'])
if certificate.changed:
certificate.cert_info = {}
else:
try:
certificate.remove()
except Exception as exc:
module.fail_json(msg=to_native(exc))
result = certificate.dump()
module.exit_json(**result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
14894,
12,
20232,
1804,
1581,
90,
665,
6341,
1581,
90,
32,
77,
3187,
14,
292,
30,
665,
68,
811,
14,
743,
75,
1581,
32,
71,
9457,
14,
292,
30,
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,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
469,
272,
283,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
272,
283,
1205,
356,
788,
7780,
995,
272,
283,
4946,
63,
991,
356,
283,
9387,
7,
199,
93,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
1551,
5510,
63,
4736,
199,
2502,
26,
298,
36,
17204,
1804,
1581,
90,
8593,
320,
10181,
3375,
2924,
199,
1023,
63,
3270,
26,
298,
18,
14,
24,
2,
199,
3612,
63,
1802,
26,
7958,
3232,
13716,
1591,
503,
922,
14512,
14,
199,
1802,
26,
272,
446,
7958,
436,
30943,
3232,
13716,
1591,
503,
922,
14512,
14,
199,
7538,
26,
272,
446,
298,
5510,
13,
498,
2268,
2,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
288,
446,
7480,
314,
1591,
503,
922,
5897,
1077,
2187,
503,
440,
12,
16466,
1595,
340,
314,
1174,
365,
3365,
687,
4052,
365,
410,
972,
14,
267,
730,
26,
620,
267,
849,
26,
298,
1881,
2,
267,
3415,
26,
359,
283,
1881,
297,
283,
5575,
7,
1622,
272,
730,
26,
267,
1369,
26,
288,
446,
7480,
314,
859,
1077,
3550,
282,
1591,
503,
282,
922,
5897,
14,
267,
730,
26,
620,
267,
1415,
26,
2549,
267,
3415,
26,
788,
1102,
297,
283,
751,
418,
272,
3542,
26,
267,
1369,
26,
288,
446,
7719,
314,
5897,
506,
31904,
2755,
340,
652,
2575,
3495,
436,
365,
1686,
14,
267,
730,
26,
2155,
267,
849,
26,
3055,
272,
931,
26,
267,
1369,
26,
288,
446,
6912,
402,
314,
570,
3035,
314,
5897,
14,
267,
730,
26,
931,
267,
1415,
26,
2549,
272,
18057,
63,
498,
26,
267,
1369,
26,
288,
446,
710,
931,
370,
314,
5726,
1551,
5510,
790,
626,
365,
1202,
367,
18057,
314,
4575,
790,
315,
1865,
370,
3550,
314,
5897,
14,
267,
730,
26,
931,
267,
1415,
26,
2549,
272,
4575,
63,
498,
26,
267,
1369,
26,
288,
446,
710,
931,
370,
314,
4575,
790,
626,
911,
506,
10514,
543,
314,
18057,
790,
315,
1865,
370,
3550,
314,
5897,
14,
267,
730,
26,
931,
267,
1415,
26,
2549,
272,
1686,
63,
504,
26,
267,
1369,
26,
288,
446,
298,
1918,
2376,
315,
900,
314,
5897,
365,
1686,
687,
14,
4703,
883,
506,
2013,
1902,
465,
3847,
900,
503,
465,
3679,
4913,
14,
2049,
4703,
911,
3544,
506,
11922,
465,
12174,
14,
4821,
6752,
787,
26,
445,
779,
16341,
61,
521,
1650,
1204,
31946,
13,
3218,
13,
5745,
1204,
31946,
13,
3218,
13,
5745,
2080,
40,
26,
3218,
26,
2300,
1204,
31946,
13,
3218,
13,
5745,
26922,
26,
3218,
26,
2300,
1204,
3544,
9,
2049,
2382,
900,
1650,
883,
506,
376,
3000,
435,
445,
779,
87,
1204,
366,
1204,
394,
1204,
333,
1204,
308,
566,
334,
69,
14,
71,
14,
445,
24303,
708,
87,
17,
68,
18,
72,
680,
2049,
3390,
626,
340,
1808,
3847,
900,
642,
859,
365,
2845,
32122,
2122,
267,
730,
26,
620,
267,
1415,
26,
2549,
272,
1686,
63,
475,
26,
267,
1369,
26,
288,
446,
298,
1918,
2376,
315,
900,
314,
5897,
365,
1686,
370,
14,
4703,
883,
506,
2013,
1902,
465,
3847,
900,
503,
465,
3679,
4913,
14,
2049,
4703,
911,
3544,
506,
11922,
465,
12174,
14,
4821,
6752,
787,
26,
445,
779,
16341,
61,
521,
1650,
1204,
31946,
13,
3218,
13,
5745,
1204,
31946,
13,
3218,
13,
5745,
2080,
40,
26,
3218,
26,
2300,
1204,
31946,
13,
3218,
13,
5745,
26922,
26,
3218,
26,
2300,
1204,
28688,
9,
2049,
2382,
900,
1650,
883,
506,
376,
3000,
435,
445,
779,
87,
1204,
366,
1204,
394,
1204,
333,
1204,
308,
566,
334,
69,
14,
71,
14,
445,
24303,
708,
87,
17,
68,
18,
72,
680,
2049,
3390,
626,
340,
1808,
3847,
900,
642,
859,
365,
2845,
32122,
2122,
267,
730,
26,
620,
267,
1415,
26,
2549,
272,
1686,
63,
292,
26,
267,
1369,
26,
288,
446,
298,
1799,
340,
314,
5897,
365,
1686,
737,
282,
9842,
2376,
315,
900,
14,
982,
652,
365,
440,
314,
5897,
911,
506,
31904,
14,
2049,
4703,
911,
3544,
506,
11922,
465,
12174,
14,
11298,
590,
370,
506,
1202,
543,
3847,
900,
1650,
367,
473,
8,
1078,
63,
504,
9,
436,
1182,
503,
473,
8,
1078,
63,
475,
680,
2049,
3390,
626,
340,
1808,
3847,
900,
642,
859,
365,
2845,
32122,
2122,
267,
730,
26,
620,
272,
5448,
10352,
2551,
26,
267,
1369,
26,
288,
446,
298,
11414,
83,
1443,
506,
13988,
370,
506,
1686,
367,
282,
663,
402,
21646,
334,
751,
15,
1102,
9,
1561,
14,
1598,
4885,
849,
12,
4046,
14512,
787,
1686,
367,
1006,
4390,
503,
7057,
2122,
267,
730,
26,
769,
272,
1511,
26,
267,
1369,
26,
288,
446,
298,
17768,
5897,
1511,
1380,
18057,
282,
790,
14,
710,
945,
626,
787,
1686,
367,
922,
14512,
787,
5424,
288,
446,
298,
35,
8,
3584,
304,
14836,
1006,
5223,
3443,
14,
221,
961,
365,
2997,
367,
5436,
316,
314,
849,
663,
402,
3443,
880,
3443,
1443,
506,
3483,
7814,
3163,
2122,
288,
446,
298,
35,
8,
3990,
13,
1531,
29,
1531,
304,
2104,
823,
314,
6451,
402,
1414,
3140,
402,
1263,
5218,
503,
2049,
1414,
2013,
701,
314,
922,
1380,
314,
5897,
365,
1202,
367,
6299,
2122,
288,
446,
298,
35,
8,
889,
13,
4054,
13,
21513,
304,
17534,
8635,
13,
4054,
24119,
334,
28843,
701,
849,
17617,
288,
446,
298,
35,
8,
889,
13,
719,
13,
21513,
304,
17534,
1844,
24119,
334,
28843,
701,
849,
17617,
288,
446,
298,
35,
8,
889,
13,
28563,
17534,
304,
510,
2099,
18723,
334,
28843,
701,
849,
17617,
288,
446,
298,
35,
8,
889,
13,
751,
13,
1195
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
14894,
12,
20232,
1804,
1581,
90,
665,
6341,
1581,
90,
32,
77,
3187,
14,
292,
30,
665,
68,
811,
14,
743,
75,
1581,
32,
71,
9457,
14,
292,
30,
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,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
469,
272,
283,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
272,
283,
1205,
356,
788,
7780,
995,
272,
283,
4946,
63,
991,
356,
283,
9387,
7,
199,
93,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
1551,
5510,
63,
4736,
199,
2502,
26,
298,
36,
17204,
1804,
1581,
90,
8593,
320,
10181,
3375,
2924,
199,
1023,
63,
3270,
26,
298,
18,
14,
24,
2,
199,
3612,
63,
1802,
26,
7958,
3232,
13716,
1591,
503,
922,
14512,
14,
199,
1802,
26,
272,
446,
7958,
436,
30943,
3232,
13716,
1591,
503,
922,
14512,
14,
199,
7538,
26,
272,
446,
298,
5510,
13,
498,
2268,
2,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
288,
446,
7480,
314,
1591,
503,
922,
5897,
1077,
2187,
503,
440,
12,
16466,
1595,
340,
314,
1174,
365,
3365,
687,
4052,
365,
410,
972,
14,
267,
730,
26,
620,
267,
849,
26,
298,
1881,
2,
267,
3415,
26,
359,
283,
1881,
297,
283,
5575,
7,
1622,
272,
730,
26,
267,
1369,
26,
288,
446,
7480,
314,
859,
1077,
3550,
282,
1591,
503,
282,
922,
5897,
14,
267,
730,
26,
620,
267,
1415,
26,
2549,
267,
3415,
26,
788,
1102,
297,
283,
751,
418,
272,
3542,
26,
267,
1369,
26,
288,
446,
7719,
314,
5897,
506,
31904,
2755,
340,
652,
2575,
3495,
436,
365,
1686,
14,
267,
730,
26,
2155,
267,
849,
26,
3055,
272,
931,
26,
267,
1369,
26,
288,
446,
6912,
402,
314,
570,
3035,
314,
5897,
14,
267,
730,
26,
931,
267,
1415,
26,
2549,
272,
18057,
63,
498,
26,
267,
1369,
26,
288,
446,
710,
931,
370,
314,
5726,
1551,
5510,
790,
626,
365,
1202,
367,
18057,
314,
4575,
790,
315,
1865,
370,
3550,
314,
5897,
14,
267,
730,
26,
931,
267,
1415,
26,
2549,
272,
4575,
63,
498,
26,
267,
1369,
26,
288,
446,
710,
931,
370,
314,
4575,
790,
626,
911,
506,
10514,
543,
314,
18057,
790,
315,
1865,
370,
3550,
314,
5897,
14,
267,
730,
26,
931,
267,
1415,
26,
2549,
272,
1686,
63,
504,
26,
267,
1369,
26,
288,
446,
298,
1918,
2376,
315,
900,
314,
5897,
365,
1686,
687,
14,
4703,
883,
506,
2013,
1902,
465,
3847,
900,
503,
465,
3679,
4913,
14,
2049,
4703,
911,
3544,
506,
11922,
465,
12174,
14,
4821,
6752,
787,
26,
445,
779,
16341,
61,
521,
1650,
1204,
31946,
13,
3218,
13,
5745,
1204,
31946,
13,
3218,
13,
5745,
2080,
40,
26,
3218,
26,
2300,
1204,
31946,
13,
3218,
13,
5745,
26922,
26,
3218,
26,
2300,
1204,
3544,
9,
2049,
2382,
900,
1650,
883,
506,
376,
3000,
435,
445,
779,
87,
1204,
366,
1204,
394,
1204,
333,
1204,
308,
566,
334,
69,
14,
71,
14,
445,
24303,
708,
87,
17,
68,
18,
72,
680,
2049,
3390,
626,
340,
1808,
3847,
900,
642,
859,
365,
2845,
32122,
2122,
267,
730,
26,
620,
267,
1415,
26,
2549,
272,
1686,
63,
475,
26,
267,
1369,
26,
288,
446,
298,
1918,
2376,
315,
900,
314,
5897,
365,
1686,
370,
14,
4703,
883,
506,
2013,
1902,
465,
3847,
900,
503,
465,
3679,
4913,
14,
2049,
4703,
911,
3544,
506,
11922,
465,
12174,
14,
4821,
6752,
787,
26,
445,
779,
16341,
61,
521,
1650,
1204,
31946,
13,
3218,
13,
5745,
1204,
31946,
13,
3218,
13,
5745,
2080,
40,
26,
3218,
26,
2300,
1204,
31946,
13,
3218,
13,
5745,
26922,
26,
3218,
26,
2300,
1204,
28688,
9,
2049,
2382,
900,
1650,
883,
506,
376,
3000,
435,
445,
779,
87,
1204,
366,
1204,
394,
1204,
333,
1204,
308,
566,
334,
69,
14,
71,
14,
445,
24303,
708,
87,
17,
68,
18,
72,
680,
2049,
3390,
626,
340,
1808,
3847,
900,
642,
859,
365,
2845,
32122,
2122,
267,
730,
26,
620,
267,
1415,
26,
2549,
272,
1686,
63,
292,
26,
267,
1369,
26,
288,
446,
298,
1799,
340,
314,
5897,
365,
1686,
737,
282,
9842,
2376,
315,
900,
14,
982,
652,
365,
440,
314,
5897,
911,
506,
31904,
14,
2049,
4703,
911,
3544,
506,
11922,
465,
12174,
14,
11298,
590,
370,
506,
1202,
543,
3847,
900,
1650,
367,
473,
8,
1078,
63,
504,
9,
436,
1182,
503,
473,
8,
1078,
63,
475,
680,
2049,
3390,
626,
340,
1808,
3847,
900,
642,
859,
365,
2845,
32122,
2122,
267,
730,
26,
620,
272,
5448,
10352,
2551,
26,
267,
1369,
26,
288,
446,
298,
11414,
83,
1443,
506,
13988,
370,
506,
1686,
367,
282,
663,
402,
21646,
334,
751,
15,
1102,
9,
1561,
14,
1598,
4885,
849,
12,
4046,
14512,
787,
1686,
367,
1006,
4390,
503,
7057,
2122,
267,
730,
26,
769,
272,
1511,
26,
267,
1369,
26,
288,
446,
298,
17768,
5897,
1511,
1380,
18057,
282,
790,
14,
710,
945,
626,
787,
1686,
367,
922,
14512,
787,
5424,
288,
446,
298,
35,
8,
3584,
304,
14836,
1006,
5223,
3443,
14,
221,
961,
365,
2997,
367,
5436,
316,
314,
849,
663,
402,
3443,
880,
3443,
1443,
506,
3483,
7814,
3163,
2122,
288,
446,
298,
35,
8,
3990,
13,
1531,
29,
1531,
304,
2104,
823,
314,
6451,
402,
1414,
3140,
402,
1263,
5218,
503,
2049,
1414,
2013,
701,
314,
922,
1380,
314,
5897,
365,
1202,
367,
6299,
2122,
288,
446,
298,
35,
8,
889,
13,
4054,
13,
21513,
304,
17534,
8635,
13,
4054,
24119,
334,
28843,
701,
849,
17617,
288,
446,
298,
35,
8,
889,
13,
719,
13,
21513,
304,
17534,
1844,
24119,
334,
28843,
701,
849,
17617,
288,
446,
298,
35,
8,
889,
13,
28563,
17534,
304,
510,
2099,
18723,
334,
28843,
701,
849,
17617,
288,
446,
298,
35,
8,
889,
13,
751,
13,
1195,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ArcherSys/ArcherSys
|
Lib/site-packages/django/forms/models.py
|
37
|
55467
|
"""
Helper functions for creating Form classes from Django models
and database field objects.
"""
from __future__ import unicode_literals
import warnings
from collections import OrderedDict
from itertools import chain
from django.core.exceptions import (
NON_FIELD_ERRORS, FieldError, ImproperlyConfigured, ValidationError,
)
from django.forms.fields import ChoiceField, Field
from django.forms.forms import BaseForm, DeclarativeFieldsMetaclass
from django.forms.formsets import BaseFormSet, formset_factory
from django.forms.utils import ErrorList
from django.forms.widgets import (
HiddenInput, MultipleHiddenInput, SelectMultiple,
)
from django.utils import six
from django.utils.deprecation import RemovedInDjango19Warning
from django.utils.encoding import force_text, smart_text
from django.utils.text import capfirst, get_text_list
from django.utils.translation import ugettext, ugettext_lazy as _
__all__ = (
'ModelForm', 'BaseModelForm', 'model_to_dict', 'fields_for_model',
'save_instance', 'ModelChoiceField', 'ModelMultipleChoiceField',
'ALL_FIELDS', 'BaseModelFormSet', 'modelformset_factory',
'BaseInlineFormSet', 'inlineformset_factory', 'modelform_factory',
)
ALL_FIELDS = '__all__'
def construct_instance(form, instance, fields=None, exclude=None):
"""
Constructs and returns a model instance from the bound ``form``'s
``cleaned_data``, but does not save the returned instance to the
database.
"""
from django.db import models
opts = instance._meta
cleaned_data = form.cleaned_data
file_field_list = []
for f in opts.fields:
if not f.editable or isinstance(f, models.AutoField) \
or f.name not in cleaned_data:
continue
if fields is not None and f.name not in fields:
continue
if exclude and f.name in exclude:
continue
# Defer saving file-type fields until after the other fields, so a
# callable upload_to can use the values from other fields.
if isinstance(f, models.FileField):
file_field_list.append(f)
else:
f.save_form_data(instance, cleaned_data[f.name])
for f in file_field_list:
f.save_form_data(instance, cleaned_data[f.name])
return instance
def save_instance(form, instance, fields=None, fail_message='saved',
commit=True, exclude=None, construct=True):
"""
Saves bound Form ``form``'s cleaned_data into model instance ``instance``.
If commit=True, then the changes to ``instance`` will be saved to the
database. Returns ``instance``.
If construct=False, assume ``instance`` has already been constructed and
just needs to be saved.
"""
if construct:
instance = construct_instance(form, instance, fields, exclude)
opts = instance._meta
if form.errors:
raise ValueError("The %s could not be %s because the data didn't"
" validate." % (opts.object_name, fail_message))
# Wrap up the saving of m2m data as a function.
def save_m2m():
cleaned_data = form.cleaned_data
# Note that for historical reasons we want to include also
# virtual_fields here. (GenericRelation was previously a fake
# m2m field).
for f in chain(opts.many_to_many, opts.virtual_fields):
if not hasattr(f, 'save_form_data'):
continue
if fields and f.name not in fields:
continue
if exclude and f.name in exclude:
continue
if f.name in cleaned_data:
f.save_form_data(instance, cleaned_data[f.name])
if commit:
# If we are committing, save the instance and the m2m data immediately.
instance.save()
save_m2m()
else:
# We're not committing. Add a method to the form to allow deferred
# saving of m2m data.
form.save_m2m = save_m2m
return instance
# ModelForms #################################################################
def model_to_dict(instance, fields=None, exclude=None):
"""
Returns a dict containing the data in ``instance`` suitable for passing as
a Form's ``initial`` keyword argument.
``fields`` is an optional list of field names. If provided, only the named
fields will be included in the returned dict.
``exclude`` is an optional list of field names. If provided, the named
fields will be excluded from the returned dict, even if they are listed in
the ``fields`` argument.
"""
# avoid a circular import
from django.db.models.fields.related import ManyToManyField
opts = instance._meta
data = {}
for f in chain(opts.concrete_fields, opts.virtual_fields, opts.many_to_many):
if not getattr(f, 'editable', False):
continue
if fields and f.name not in fields:
continue
if exclude and f.name in exclude:
continue
if isinstance(f, ManyToManyField):
# If the object doesn't have a primary key yet, just use an empty
# list for its m2m fields. Calling f.value_from_object will raise
# an exception.
if instance.pk is None:
data[f.name] = []
else:
# MultipleChoiceWidget needs a list of pks, not object instances.
qs = f.value_from_object(instance)
if qs._result_cache is not None:
data[f.name] = [item.pk for item in qs]
else:
data[f.name] = list(qs.values_list('pk', flat=True))
else:
data[f.name] = f.value_from_object(instance)
return data
def fields_for_model(model, fields=None, exclude=None, widgets=None,
formfield_callback=None, localized_fields=None,
labels=None, help_texts=None, error_messages=None):
"""
Returns a ``OrderedDict`` containing form fields for the given model.
``fields`` is an optional list of field names. If provided, only the named
fields will be included in the returned fields.
``exclude`` is an optional list of field names. If provided, the named
fields will be excluded from the returned fields, even if they are listed
in the ``fields`` argument.
``widgets`` is a dictionary of model field names mapped to a widget.
``localized_fields`` is a list of names of fields which should be localized.
``labels`` is a dictionary of model field names mapped to a label.
``help_texts`` is a dictionary of model field names mapped to a help text.
``error_messages`` is a dictionary of model field names mapped to a
dictionary of error messages.
``formfield_callback`` is a callable that takes a model field and returns
a form field.
"""
field_list = []
ignored = []
opts = model._meta
# Avoid circular import
from django.db.models.fields import Field as ModelField
sortable_virtual_fields = [f for f in opts.virtual_fields
if isinstance(f, ModelField)]
for f in sorted(chain(opts.concrete_fields, sortable_virtual_fields, opts.many_to_many)):
if not getattr(f, 'editable', False):
continue
if fields is not None and f.name not in fields:
continue
if exclude and f.name in exclude:
continue
kwargs = {}
if widgets and f.name in widgets:
kwargs['widget'] = widgets[f.name]
if localized_fields == ALL_FIELDS or (localized_fields and f.name in localized_fields):
kwargs['localize'] = True
if labels and f.name in labels:
kwargs['label'] = labels[f.name]
if help_texts and f.name in help_texts:
kwargs['help_text'] = help_texts[f.name]
if error_messages and f.name in error_messages:
kwargs['error_messages'] = error_messages[f.name]
if formfield_callback is None:
formfield = f.formfield(**kwargs)
elif not callable(formfield_callback):
raise TypeError('formfield_callback must be a function or callable')
else:
formfield = formfield_callback(f, **kwargs)
if formfield:
field_list.append((f.name, formfield))
else:
ignored.append(f.name)
field_dict = OrderedDict(field_list)
if fields:
field_dict = OrderedDict(
[(f, field_dict.get(f)) for f in fields
if ((not exclude) or (exclude and f not in exclude)) and (f not in ignored)]
)
return field_dict
class ModelFormOptions(object):
def __init__(self, options=None):
self.model = getattr(options, 'model', None)
self.fields = getattr(options, 'fields', None)
self.exclude = getattr(options, 'exclude', None)
self.widgets = getattr(options, 'widgets', None)
self.localized_fields = getattr(options, 'localized_fields', None)
self.labels = getattr(options, 'labels', None)
self.help_texts = getattr(options, 'help_texts', None)
self.error_messages = getattr(options, 'error_messages', None)
class ModelFormMetaclass(DeclarativeFieldsMetaclass):
def __new__(mcs, name, bases, attrs):
formfield_callback = attrs.pop('formfield_callback', None)
new_class = super(ModelFormMetaclass, mcs).__new__(mcs, name, bases, attrs)
if bases == (BaseModelForm,):
return new_class
opts = new_class._meta = ModelFormOptions(getattr(new_class, 'Meta', None))
# We check if a string was passed to `fields` or `exclude`,
# which is likely to be a mistake where the user typed ('foo') instead
# of ('foo',)
for opt in ['fields', 'exclude', 'localized_fields']:
value = getattr(opts, opt)
if isinstance(value, six.string_types) and value != ALL_FIELDS:
msg = ("%(model)s.Meta.%(opt)s cannot be a string. "
"Did you mean to type: ('%(value)s',)?" % {
'model': new_class.__name__,
'opt': opt,
'value': value,
})
raise TypeError(msg)
if opts.model:
# If a model is defined, extract form fields from it.
if opts.fields is None and opts.exclude is None:
raise ImproperlyConfigured(
"Creating a ModelForm without either the 'fields' attribute "
"or the 'exclude' attribute is prohibited; form %s "
"needs updating." % name
)
if opts.fields == ALL_FIELDS:
# Sentinel for fields_for_model to indicate "get the list of
# fields from the model"
opts.fields = None
fields = fields_for_model(opts.model, opts.fields, opts.exclude,
opts.widgets, formfield_callback,
opts.localized_fields, opts.labels,
opts.help_texts, opts.error_messages)
# make sure opts.fields doesn't specify an invalid field
none_model_fields = [k for k, v in six.iteritems(fields) if not v]
missing_fields = (set(none_model_fields) -
set(new_class.declared_fields.keys()))
if missing_fields:
message = 'Unknown field(s) (%s) specified for %s'
message = message % (', '.join(missing_fields),
opts.model.__name__)
raise FieldError(message)
# Override default model fields with any custom declared ones
# (plus, include all the other declared fields).
fields.update(new_class.declared_fields)
else:
fields = new_class.declared_fields
new_class.base_fields = fields
return new_class
class BaseModelForm(BaseForm):
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
initial=None, error_class=ErrorList, label_suffix=None,
empty_permitted=False, instance=None):
opts = self._meta
if opts.model is None:
raise ValueError('ModelForm has no model class specified.')
if instance is None:
# if we didn't get an instance, instantiate a new one
self.instance = opts.model()
object_data = {}
else:
self.instance = instance
object_data = model_to_dict(instance, opts.fields, opts.exclude)
# if initial was provided, it should override the values from instance
if initial is not None:
object_data.update(initial)
# self._validate_unique will be set to True by BaseModelForm.clean().
# It is False by default so overriding self.clean() and failing to call
# super will stop validate_unique from being called.
self._validate_unique = False
super(BaseModelForm, self).__init__(data, files, auto_id, prefix, object_data,
error_class, label_suffix, empty_permitted)
# Apply ``limit_choices_to`` to each field.
for field_name in self.fields:
formfield = self.fields[field_name]
if hasattr(formfield, 'queryset') and hasattr(formfield, 'get_limit_choices_to'):
limit_choices_to = formfield.get_limit_choices_to()
if limit_choices_to is not None:
formfield.queryset = formfield.queryset.complex_filter(limit_choices_to)
def _get_validation_exclusions(self):
"""
For backwards-compatibility, several types of fields need to be
excluded from model validation. See the following tickets for
details: #12507, #12521, #12553
"""
exclude = []
# Build up a list of fields that should be excluded from model field
# validation and unique checks.
for f in self.instance._meta.fields:
field = f.name
# Exclude fields that aren't on the form. The developer may be
# adding these values to the model after form validation.
if field not in self.fields:
exclude.append(f.name)
# Don't perform model validation on fields that were defined
# manually on the form and excluded via the ModelForm's Meta
# class. See #12901.
elif self._meta.fields and field not in self._meta.fields:
exclude.append(f.name)
elif self._meta.exclude and field in self._meta.exclude:
exclude.append(f.name)
# Exclude fields that failed form validation. There's no need for
# the model fields to validate them as well.
elif field in self._errors.keys():
exclude.append(f.name)
# Exclude empty fields that are not required by the form, if the
# underlying model field is required. This keeps the model field
# from raising a required error. Note: don't exclude the field from
# validation if the model field allows blanks. If it does, the blank
# value may be included in a unique check, so cannot be excluded
# from validation.
else:
form_field = self.fields[field]
field_value = self.cleaned_data.get(field, None)
if not f.blank and not form_field.required and field_value in form_field.empty_values:
exclude.append(f.name)
return exclude
def clean(self):
self._validate_unique = True
return self.cleaned_data
def _update_errors(self, errors):
# Override any validation error messages defined at the model level
# with those defined at the form level.
opts = self._meta
for field, messages in errors.error_dict.items():
if (field == NON_FIELD_ERRORS and opts.error_messages and
NON_FIELD_ERRORS in opts.error_messages):
error_messages = opts.error_messages[NON_FIELD_ERRORS]
elif field in self.fields:
error_messages = self.fields[field].error_messages
else:
continue
for message in messages:
if (isinstance(message, ValidationError) and
message.code in error_messages):
message.message = error_messages[message.code]
self.add_error(None, errors)
def _post_clean(self):
opts = self._meta
exclude = self._get_validation_exclusions()
# a subset of `exclude` which won't have the InlineForeignKeyField
# if we're adding a new object since that value doesn't exist
# until after the new instance is saved to the database.
construct_instance_exclude = list(exclude)
# Foreign Keys being used to represent inline relationships
# are excluded from basic field value validation. This is for two
# reasons: firstly, the value may not be supplied (#12507; the
# case of providing new values to the admin); secondly the
# object being referred to may not yet fully exist (#12749).
# However, these fields *must* be included in uniqueness checks,
# so this can't be part of _get_validation_exclusions().
for name, field in self.fields.items():
if isinstance(field, InlineForeignKeyField):
if self.cleaned_data.get(name) is not None and self.cleaned_data[name]._state.adding:
construct_instance_exclude.append(name)
exclude.append(name)
# Update the model instance with self.cleaned_data.
self.instance = construct_instance(self, self.instance, opts.fields, construct_instance_exclude)
try:
self.instance.full_clean(exclude=exclude, validate_unique=False)
except ValidationError as e:
self._update_errors(e)
# Validate uniqueness if needed.
if self._validate_unique:
self.validate_unique()
def validate_unique(self):
"""
Calls the instance's validate_unique() method and updates the form's
validation errors if any were raised.
"""
exclude = self._get_validation_exclusions()
try:
self.instance.validate_unique(exclude=exclude)
except ValidationError as e:
self._update_errors(e)
def save(self, commit=True):
"""
Saves this ``form``'s cleaned_data into model instance
``self.instance``.
If commit=True, then the changes to ``instance`` will be saved to the
database. Returns ``instance``.
"""
if self.instance.pk is None:
fail_message = 'created'
else:
fail_message = 'changed'
return save_instance(self, self.instance, self._meta.fields,
fail_message, commit, self._meta.exclude,
construct=False)
save.alters_data = True
class ModelForm(six.with_metaclass(ModelFormMetaclass, BaseModelForm)):
pass
def modelform_factory(model, form=ModelForm, fields=None, exclude=None,
formfield_callback=None, widgets=None, localized_fields=None,
labels=None, help_texts=None, error_messages=None):
"""
Returns a ModelForm containing form fields for the given model.
``fields`` is an optional list of field names. If provided, only the named
fields will be included in the returned fields. If omitted or '__all__',
all fields will be used.
``exclude`` is an optional list of field names. If provided, the named
fields will be excluded from the returned fields, even if they are listed
in the ``fields`` argument.
``widgets`` is a dictionary of model field names mapped to a widget.
``localized_fields`` is a list of names of fields which should be localized.
``formfield_callback`` is a callable that takes a model field and returns
a form field.
``labels`` is a dictionary of model field names mapped to a label.
``help_texts`` is a dictionary of model field names mapped to a help text.
``error_messages`` is a dictionary of model field names mapped to a
dictionary of error messages.
"""
# Create the inner Meta class. FIXME: ideally, we should be able to
# construct a ModelForm without creating and passing in a temporary
# inner class.
# Build up a list of attributes that the Meta object will have.
attrs = {'model': model}
if fields is not None:
attrs['fields'] = fields
if exclude is not None:
attrs['exclude'] = exclude
if widgets is not None:
attrs['widgets'] = widgets
if localized_fields is not None:
attrs['localized_fields'] = localized_fields
if labels is not None:
attrs['labels'] = labels
if help_texts is not None:
attrs['help_texts'] = help_texts
if error_messages is not None:
attrs['error_messages'] = error_messages
# If parent form class already has an inner Meta, the Meta we're
# creating needs to inherit from the parent's inner meta.
parent = (object,)
if hasattr(form, 'Meta'):
parent = (form.Meta, object)
Meta = type(str('Meta'), parent, attrs)
# Give this new form class a reasonable name.
class_name = model.__name__ + str('Form')
# Class attributes for the new form class.
form_class_attrs = {
'Meta': Meta,
'formfield_callback': formfield_callback
}
if (getattr(Meta, 'fields', None) is None and
getattr(Meta, 'exclude', None) is None):
raise ImproperlyConfigured(
"Calling modelform_factory without defining 'fields' or "
"'exclude' explicitly is prohibited."
)
# Instantiate type(form) in order to use the same metaclass as form.
return type(form)(class_name, (form,), form_class_attrs)
# ModelFormSets ##############################################################
class BaseModelFormSet(BaseFormSet):
"""
A ``FormSet`` for editing a queryset and/or adding new objects to it.
"""
model = None
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
queryset=None, **kwargs):
self.queryset = queryset
self.initial_extra = kwargs.pop('initial', None)
defaults = {'data': data, 'files': files, 'auto_id': auto_id, 'prefix': prefix}
defaults.update(kwargs)
super(BaseModelFormSet, self).__init__(**defaults)
def initial_form_count(self):
"""Returns the number of forms that are required in this FormSet."""
if not (self.data or self.files):
return len(self.get_queryset())
return super(BaseModelFormSet, self).initial_form_count()
def _existing_object(self, pk):
if not hasattr(self, '_object_dict'):
self._object_dict = {o.pk: o for o in self.get_queryset()}
return self._object_dict.get(pk)
def _get_to_python(self, field):
"""
If the field is a related field, fetch the concrete field's (that
is, the ultimate pointed-to field's) to_python.
"""
while field.rel is not None:
field = field.rel.get_related_field()
return field.to_python
def _construct_form(self, i, **kwargs):
if self.is_bound and i < self.initial_form_count():
pk_key = "%s-%s" % (self.add_prefix(i), self.model._meta.pk.name)
pk = self.data[pk_key]
pk_field = self.model._meta.pk
to_python = self._get_to_python(pk_field)
pk = to_python(pk)
kwargs['instance'] = self._existing_object(pk)
if i < self.initial_form_count() and 'instance' not in kwargs:
kwargs['instance'] = self.get_queryset()[i]
if i >= self.initial_form_count() and self.initial_extra:
# Set initial values for extra forms
try:
kwargs['initial'] = self.initial_extra[i - self.initial_form_count()]
except IndexError:
pass
return super(BaseModelFormSet, self)._construct_form(i, **kwargs)
def get_queryset(self):
if not hasattr(self, '_queryset'):
if self.queryset is not None:
qs = self.queryset
else:
qs = self.model._default_manager.get_queryset()
# If the queryset isn't already ordered we need to add an
# artificial ordering here to make sure that all formsets
# constructed from this queryset have the same form order.
if not qs.ordered:
qs = qs.order_by(self.model._meta.pk.name)
# Removed queryset limiting here. As per discussion re: #13023
# on django-dev, max_num should not prevent existing
# related objects/inlines from being displayed.
self._queryset = qs
return self._queryset
def save_new(self, form, commit=True):
"""Saves and returns a new model instance for the given form."""
return form.save(commit=commit)
def save_existing(self, form, instance, commit=True):
"""Saves and returns an existing model instance for the given form."""
return form.save(commit=commit)
def save(self, commit=True):
"""Saves model instances for every form, adding and changing instances
as necessary, and returns the list of instances.
"""
if not commit:
self.saved_forms = []
def save_m2m():
for form in self.saved_forms:
form.save_m2m()
self.save_m2m = save_m2m
return self.save_existing_objects(commit) + self.save_new_objects(commit)
save.alters_data = True
def clean(self):
self.validate_unique()
def validate_unique(self):
# Collect unique_checks and date_checks to run from all the forms.
all_unique_checks = set()
all_date_checks = set()
forms_to_delete = self.deleted_forms
valid_forms = [form for form in self.forms if form.is_valid() and form not in forms_to_delete]
for form in valid_forms:
exclude = form._get_validation_exclusions()
unique_checks, date_checks = form.instance._get_unique_checks(exclude=exclude)
all_unique_checks = all_unique_checks.union(set(unique_checks))
all_date_checks = all_date_checks.union(set(date_checks))
errors = []
# Do each of the unique checks (unique and unique_together)
for uclass, unique_check in all_unique_checks:
seen_data = set()
for form in valid_forms:
# get data for each field of each of unique_check
row_data = (form.cleaned_data[field]
for field in unique_check if field in form.cleaned_data)
# Reduce Model instances to their primary key values
row_data = tuple(d._get_pk_val() if hasattr(d, '_get_pk_val') else d
for d in row_data)
if row_data and None not in row_data:
# if we've already seen it then we have a uniqueness failure
if row_data in seen_data:
# poke error messages into the right places and mark
# the form as invalid
errors.append(self.get_unique_error_message(unique_check))
form._errors[NON_FIELD_ERRORS] = self.error_class([self.get_form_error()])
# remove the data from the cleaned_data dict since it was invalid
for field in unique_check:
if field in form.cleaned_data:
del form.cleaned_data[field]
# mark the data as seen
seen_data.add(row_data)
# iterate over each of the date checks now
for date_check in all_date_checks:
seen_data = set()
uclass, lookup, field, unique_for = date_check
for form in valid_forms:
# see if we have data for both fields
if (form.cleaned_data and form.cleaned_data[field] is not None
and form.cleaned_data[unique_for] is not None):
# if it's a date lookup we need to get the data for all the fields
if lookup == 'date':
date = form.cleaned_data[unique_for]
date_data = (date.year, date.month, date.day)
# otherwise it's just the attribute on the date/datetime
# object
else:
date_data = (getattr(form.cleaned_data[unique_for], lookup),)
data = (form.cleaned_data[field],) + date_data
# if we've already seen it then we have a uniqueness failure
if data in seen_data:
# poke error messages into the right places and mark
# the form as invalid
errors.append(self.get_date_error_message(date_check))
form._errors[NON_FIELD_ERRORS] = self.error_class([self.get_form_error()])
# remove the data from the cleaned_data dict since it was invalid
del form.cleaned_data[field]
# mark the data as seen
seen_data.add(data)
if errors:
raise ValidationError(errors)
def get_unique_error_message(self, unique_check):
if len(unique_check) == 1:
return ugettext("Please correct the duplicate data for %(field)s.") % {
"field": unique_check[0],
}
else:
return ugettext("Please correct the duplicate data for %(field)s, "
"which must be unique.") % {
"field": get_text_list(unique_check, six.text_type(_("and"))),
}
def get_date_error_message(self, date_check):
return ugettext("Please correct the duplicate data for %(field_name)s "
"which must be unique for the %(lookup)s in %(date_field)s.") % {
'field_name': date_check[2],
'date_field': date_check[3],
'lookup': six.text_type(date_check[1]),
}
def get_form_error(self):
return ugettext("Please correct the duplicate values below.")
def save_existing_objects(self, commit=True):
self.changed_objects = []
self.deleted_objects = []
if not self.initial_forms:
return []
saved_instances = []
forms_to_delete = self.deleted_forms
for form in self.initial_forms:
obj = form.instance
if form in forms_to_delete:
# If the pk is None, it means that the object can't be
# deleted again. Possible reason for this is that the
# object was already deleted from the DB. Refs #14877.
if obj.pk is None:
continue
self.deleted_objects.append(obj)
if commit:
obj.delete()
elif form.has_changed():
self.changed_objects.append((obj, form.changed_data))
saved_instances.append(self.save_existing(form, obj, commit=commit))
if not commit:
self.saved_forms.append(form)
return saved_instances
def save_new_objects(self, commit=True):
self.new_objects = []
for form in self.extra_forms:
if not form.has_changed():
continue
# If someone has marked an add form for deletion, don't save the
# object.
if self.can_delete and self._should_delete_form(form):
continue
self.new_objects.append(self.save_new(form, commit=commit))
if not commit:
self.saved_forms.append(form)
return self.new_objects
def add_fields(self, form, index):
"""Add a hidden field for the object's primary key."""
from django.db.models import AutoField, OneToOneField, ForeignKey
self._pk_field = pk = self.model._meta.pk
# If a pk isn't editable, then it won't be on the form, so we need to
# add it here so we can tell which object is which when we get the
# data back. Generally, pk.editable should be false, but for some
# reason, auto_created pk fields and AutoField's editable attribute is
# True, so check for that as well.
def pk_is_not_editable(pk):
return ((not pk.editable) or (pk.auto_created or isinstance(pk, AutoField))
or (pk.rel and pk.rel.parent_link and pk_is_not_editable(pk.rel.to._meta.pk)))
if pk_is_not_editable(pk) or pk.name not in form.fields:
if form.is_bound:
# If we're adding the related instance, ignore its primary key
# as it could be an auto-generated default which isn't actually
# in the database.
pk_value = None if form.instance._state.adding else form.instance.pk
else:
try:
if index is not None:
pk_value = self.get_queryset()[index].pk
else:
pk_value = None
except IndexError:
pk_value = None
if isinstance(pk, OneToOneField) or isinstance(pk, ForeignKey):
qs = pk.rel.to._default_manager.get_queryset()
else:
qs = self.model._default_manager.get_queryset()
qs = qs.using(form.instance._state.db)
if form._meta.widgets:
widget = form._meta.widgets.get(self._pk_field.name, HiddenInput)
else:
widget = HiddenInput
form.fields[self._pk_field.name] = ModelChoiceField(qs, initial=pk_value, required=False, widget=widget)
super(BaseModelFormSet, self).add_fields(form, index)
def modelformset_factory(model, form=ModelForm, formfield_callback=None,
formset=BaseModelFormSet, extra=1, can_delete=False,
can_order=False, max_num=None, fields=None, exclude=None,
widgets=None, validate_max=False, localized_fields=None,
labels=None, help_texts=None, error_messages=None,
min_num=None, validate_min=False):
"""
Returns a FormSet class for the given Django model class.
"""
meta = getattr(form, 'Meta', None)
if meta is None:
meta = type(str('Meta'), (object,), {})
if (getattr(meta, 'fields', fields) is None and
getattr(meta, 'exclude', exclude) is None):
raise ImproperlyConfigured(
"Calling modelformset_factory without defining 'fields' or "
"'exclude' explicitly is prohibited."
)
form = modelform_factory(model, form=form, fields=fields, exclude=exclude,
formfield_callback=formfield_callback,
widgets=widgets, localized_fields=localized_fields,
labels=labels, help_texts=help_texts, error_messages=error_messages)
FormSet = formset_factory(form, formset, extra=extra, min_num=min_num, max_num=max_num,
can_order=can_order, can_delete=can_delete,
validate_min=validate_min, validate_max=validate_max)
FormSet.model = model
return FormSet
# InlineFormSets #############################################################
class BaseInlineFormSet(BaseModelFormSet):
"""A formset for child objects related to a parent."""
def __init__(self, data=None, files=None, instance=None,
save_as_new=False, prefix=None, queryset=None, **kwargs):
if instance is None:
self.instance = self.fk.rel.to()
else:
self.instance = instance
self.save_as_new = save_as_new
if queryset is None:
queryset = self.model._default_manager
if self.instance.pk is not None:
qs = queryset.filter(**{self.fk.name: self.instance})
else:
qs = queryset.none()
super(BaseInlineFormSet, self).__init__(data, files, prefix=prefix,
queryset=qs, **kwargs)
def initial_form_count(self):
if self.save_as_new:
return 0
return super(BaseInlineFormSet, self).initial_form_count()
def _construct_form(self, i, **kwargs):
form = super(BaseInlineFormSet, self)._construct_form(i, **kwargs)
if self.save_as_new:
# Remove the primary key from the form's data, we are only
# creating new instances
form.data[form.add_prefix(self._pk_field.name)] = None
# Remove the foreign key from the form's data
form.data[form.add_prefix(self.fk.name)] = None
# Set the fk value here so that the form can do its validation.
fk_value = self.instance.pk
if self.fk.rel.field_name != self.fk.rel.to._meta.pk.name:
fk_value = getattr(self.instance, self.fk.rel.field_name)
fk_value = getattr(fk_value, 'pk', fk_value)
setattr(form.instance, self.fk.get_attname(), fk_value)
return form
@classmethod
def get_default_prefix(cls):
return cls.fk.rel.get_accessor_name(model=cls.model).replace('+', '')
def save_new(self, form, commit=True):
# Ensure the latest copy of the related instance is present on each
# form (it may have been saved after the formset was originally
# instantiated).
setattr(form.instance, self.fk.name, self.instance)
# Use commit=False so we can assign the parent key afterwards, then
# save the object.
obj = form.save(commit=False)
pk_value = getattr(self.instance, self.fk.rel.field_name)
setattr(obj, self.fk.get_attname(), getattr(pk_value, 'pk', pk_value))
if commit:
obj.save()
# form.save_m2m() can be called via the formset later on if commit=False
if commit and hasattr(form, 'save_m2m'):
form.save_m2m()
return obj
def add_fields(self, form, index):
super(BaseInlineFormSet, self).add_fields(form, index)
if self._pk_field == self.fk:
name = self._pk_field.name
kwargs = {'pk_field': True}
else:
# The foreign key field might not be on the form, so we poke at the
# Model field to get the label, since we need that for error messages.
name = self.fk.name
kwargs = {
'label': getattr(form.fields.get(name), 'label', capfirst(self.fk.verbose_name))
}
if self.fk.rel.field_name != self.fk.rel.to._meta.pk.name:
kwargs['to_field'] = self.fk.rel.field_name
# If we're adding a new object, ignore a parent's auto-generated pk
# as it will be regenerated on the save request.
if self.instance._state.adding and form._meta.model._meta.pk.has_default():
self.instance.pk = None
form.fields[name] = InlineForeignKeyField(self.instance, **kwargs)
# Add the generated field to form._meta.fields if it's defined to make
# sure validation isn't skipped on that field.
if form._meta.fields:
if isinstance(form._meta.fields, tuple):
form._meta.fields = list(form._meta.fields)
form._meta.fields.append(self.fk.name)
def get_unique_error_message(self, unique_check):
unique_check = [field for field in unique_check if field != self.fk.name]
return super(BaseInlineFormSet, self).get_unique_error_message(unique_check)
def _get_foreign_key(parent_model, model, fk_name=None, can_fail=False):
"""
Finds and returns the ForeignKey from model to parent if there is one
(returns None if can_fail is True and no such field exists). If fk_name is
provided, assume it is the name of the ForeignKey field. Unless can_fail is
True, an exception is raised if there is no ForeignKey from model to
parent_model.
"""
# avoid circular import
from django.db.models import ForeignKey
opts = model._meta
if fk_name:
fks_to_parent = [f for f in opts.fields if f.name == fk_name]
if len(fks_to_parent) == 1:
fk = fks_to_parent[0]
if not isinstance(fk, ForeignKey) or \
(fk.rel.to != parent_model and
fk.rel.to not in parent_model._meta.get_parent_list()):
raise ValueError(
"fk_name '%s' is not a ForeignKey to '%s.%s'."
% (fk_name, parent_model._meta.app_label, parent_model._meta.object_name))
elif len(fks_to_parent) == 0:
raise ValueError(
"'%s.%s' has no field named '%s'."
% (model._meta.app_label, model._meta.object_name, fk_name))
else:
# Try to discover what the ForeignKey from model to parent_model is
fks_to_parent = [
f for f in opts.fields
if isinstance(f, ForeignKey)
and (f.rel.to == parent_model
or f.rel.to in parent_model._meta.get_parent_list())
]
if len(fks_to_parent) == 1:
fk = fks_to_parent[0]
elif len(fks_to_parent) == 0:
if can_fail:
return
raise ValueError(
"'%s.%s' has no ForeignKey to '%s.%s'." % (
model._meta.app_label,
model._meta.object_name,
parent_model._meta.app_label,
parent_model._meta.object_name,
)
)
else:
raise ValueError(
"'%s.%s' has more than one ForeignKey to '%s.%s'." % (
model._meta.app_label,
model._meta.object_name,
parent_model._meta.app_label,
parent_model._meta.object_name,
)
)
return fk
def inlineformset_factory(parent_model, model, form=ModelForm,
formset=BaseInlineFormSet, fk_name=None,
fields=None, exclude=None, extra=3, can_order=False,
can_delete=True, max_num=None, formfield_callback=None,
widgets=None, validate_max=False, localized_fields=None,
labels=None, help_texts=None, error_messages=None,
min_num=None, validate_min=False):
"""
Returns an ``InlineFormSet`` for the given kwargs.
You must provide ``fk_name`` if ``model`` has more than one ``ForeignKey``
to ``parent_model``.
"""
fk = _get_foreign_key(parent_model, model, fk_name=fk_name)
# enforce a max_num=1 when the foreign key to the parent model is unique.
if fk.unique:
max_num = 1
kwargs = {
'form': form,
'formfield_callback': formfield_callback,
'formset': formset,
'extra': extra,
'can_delete': can_delete,
'can_order': can_order,
'fields': fields,
'exclude': exclude,
'min_num': min_num,
'max_num': max_num,
'widgets': widgets,
'validate_min': validate_min,
'validate_max': validate_max,
'localized_fields': localized_fields,
'labels': labels,
'help_texts': help_texts,
'error_messages': error_messages,
}
FormSet = modelformset_factory(model, **kwargs)
FormSet.fk = fk
return FormSet
# Fields #####################################################################
class InlineForeignKeyField(Field):
"""
A basic integer field that deals with validating the given value to a
given parent instance in an inline.
"""
widget = HiddenInput
default_error_messages = {
'invalid_choice': _('The inline foreign key did not match the parent instance primary key.'),
}
def __init__(self, parent_instance, *args, **kwargs):
self.parent_instance = parent_instance
self.pk_field = kwargs.pop("pk_field", False)
self.to_field = kwargs.pop("to_field", None)
if self.parent_instance is not None:
if self.to_field:
kwargs["initial"] = getattr(self.parent_instance, self.to_field)
else:
kwargs["initial"] = self.parent_instance.pk
kwargs["required"] = False
super(InlineForeignKeyField, self).__init__(*args, **kwargs)
def clean(self, value):
if value in self.empty_values:
if self.pk_field:
return None
# if there is no value act as we did before.
return self.parent_instance
# ensure the we compare the values as equal types.
if self.to_field:
orig = getattr(self.parent_instance, self.to_field)
else:
orig = self.parent_instance.pk
if force_text(value) != force_text(orig):
raise ValidationError(self.error_messages['invalid_choice'], code='invalid_choice')
return self.parent_instance
def has_changed(self, initial, data):
return False
class ModelChoiceIterator(object):
def __init__(self, field):
self.field = field
self.queryset = field.queryset
def __iter__(self):
if self.field.empty_label is not None:
yield ("", self.field.empty_label)
if self.field.cache_choices:
if self.field.choice_cache is None:
self.field.choice_cache = [
self.choice(obj) for obj in self.queryset.iterator()
]
for choice in self.field.choice_cache:
yield choice
else:
for obj in self.queryset.iterator():
yield self.choice(obj)
def __len__(self):
return (len(self.queryset) +
(1 if self.field.empty_label is not None else 0))
def choice(self, obj):
return (self.field.prepare_value(obj), self.field.label_from_instance(obj))
class ModelChoiceField(ChoiceField):
"""A ChoiceField whose choices are a model QuerySet."""
# This class is a subclass of ChoiceField for purity, but it doesn't
# actually use any of ChoiceField's implementation.
default_error_messages = {
'invalid_choice': _('Select a valid choice. That choice is not one of'
' the available choices.'),
}
def __init__(self, queryset, empty_label="---------", cache_choices=None,
required=True, widget=None, label=None, initial=None,
help_text='', to_field_name=None, limit_choices_to=None,
*args, **kwargs):
if required and (initial is not None):
self.empty_label = None
else:
self.empty_label = empty_label
if cache_choices is not None:
warnings.warn("cache_choices has been deprecated and will be "
"removed in Django 1.9.",
RemovedInDjango19Warning, stacklevel=2)
else:
cache_choices = False
self.cache_choices = cache_choices
# Call Field instead of ChoiceField __init__() because we don't need
# ChoiceField.__init__().
Field.__init__(self, required, widget, label, initial, help_text,
*args, **kwargs)
self.queryset = queryset
self.limit_choices_to = limit_choices_to # limit the queryset later.
self.choice_cache = None
self.to_field_name = to_field_name
def get_limit_choices_to(self):
"""
Returns ``limit_choices_to`` for this form field.
If it is a callable, it will be invoked and the result will be
returned.
"""
if callable(self.limit_choices_to):
return self.limit_choices_to()
return self.limit_choices_to
def __deepcopy__(self, memo):
result = super(ChoiceField, self).__deepcopy__(memo)
# Need to force a new ModelChoiceIterator to be created, bug #11183
result.queryset = result.queryset
return result
def _get_queryset(self):
return self._queryset
def _set_queryset(self, queryset):
self._queryset = queryset
self.widget.choices = self.choices
queryset = property(_get_queryset, _set_queryset)
# this method will be used to create object labels by the QuerySetIterator.
# Override it to customize the label.
def label_from_instance(self, obj):
"""
This method is used to convert objects into strings; it's used to
generate the labels for the choices presented by this object. Subclasses
can override this method to customize the display of the choices.
"""
return smart_text(obj)
def _get_choices(self):
# If self._choices is set, then somebody must have manually set
# the property self.choices. In this case, just return self._choices.
if hasattr(self, '_choices'):
return self._choices
# Otherwise, execute the QuerySet in self.queryset to determine the
# choices dynamically. Return a fresh ModelChoiceIterator that has not been
# consumed. Note that we're instantiating a new ModelChoiceIterator *each*
# time _get_choices() is called (and, thus, each time self.choices is
# accessed) so that we can ensure the QuerySet has not been consumed. This
# construct might look complicated but it allows for lazy evaluation of
# the queryset.
return ModelChoiceIterator(self)
choices = property(_get_choices, ChoiceField._set_choices)
def prepare_value(self, value):
if hasattr(value, '_meta'):
if self.to_field_name:
return value.serializable_value(self.to_field_name)
else:
return value.pk
return super(ModelChoiceField, self).prepare_value(value)
def to_python(self, value):
if value in self.empty_values:
return None
try:
key = self.to_field_name or 'pk'
value = self.queryset.get(**{key: value})
except (ValueError, TypeError, self.queryset.model.DoesNotExist):
raise ValidationError(self.error_messages['invalid_choice'], code='invalid_choice')
return value
def validate(self, value):
return Field.validate(self, value)
def has_changed(self, initial, data):
initial_value = initial if initial is not None else ''
data_value = data if data is not None else ''
return force_text(self.prepare_value(initial_value)) != force_text(data_value)
class ModelMultipleChoiceField(ModelChoiceField):
"""A MultipleChoiceField whose choices are a model QuerySet."""
widget = SelectMultiple
hidden_widget = MultipleHiddenInput
default_error_messages = {
'list': _('Enter a list of values.'),
'invalid_choice': _('Select a valid choice. %(value)s is not one of the'
' available choices.'),
'invalid_pk_value': _('"%(pk)s" is not a valid value for a primary key.')
}
def __init__(self, queryset, cache_choices=None, required=True,
widget=None, label=None, initial=None,
help_text='', *args, **kwargs):
super(ModelMultipleChoiceField, self).__init__(queryset, None,
cache_choices, required, widget, label, initial, help_text,
*args, **kwargs)
def to_python(self, value):
if not value:
return []
return list(self._check_values(value))
def clean(self, value):
if self.required and not value:
raise ValidationError(self.error_messages['required'], code='required')
elif not self.required and not value:
return self.queryset.none()
if not isinstance(value, (list, tuple)):
raise ValidationError(self.error_messages['list'], code='list')
qs = self._check_values(value)
# Since this overrides the inherited ModelChoiceField.clean
# we run custom validators here
self.run_validators(value)
return qs
def _check_values(self, value):
"""
Given a list of possible PK values, returns a QuerySet of the
corresponding objects. Raises a ValidationError if a given value is
invalid (not a valid PK, not in the queryset, etc.)
"""
key = self.to_field_name or 'pk'
# deduplicate given values to avoid creating many querysets or
# requiring the database backend deduplicate efficiently.
try:
value = frozenset(value)
except TypeError:
# list of lists isn't hashable, for example
raise ValidationError(
self.error_messages['list'],
code='list',
)
for pk in value:
try:
self.queryset.filter(**{key: pk})
except (ValueError, TypeError):
raise ValidationError(
self.error_messages['invalid_pk_value'],
code='invalid_pk_value',
params={'pk': pk},
)
qs = self.queryset.filter(**{'%s__in' % key: value})
pks = set(force_text(getattr(o, key)) for o in qs)
for val in value:
if force_text(val) not in pks:
raise ValidationError(
self.error_messages['invalid_choice'],
code='invalid_choice',
params={'value': val},
)
return qs
def prepare_value(self, value):
if (hasattr(value, '__iter__') and
not isinstance(value, six.text_type) and
not hasattr(value, '_meta')):
return [super(ModelMultipleChoiceField, self).prepare_value(v) for v in value]
return super(ModelMultipleChoiceField, self).prepare_value(value)
def has_changed(self, initial, data):
if initial is None:
initial = []
if data is None:
data = []
if len(initial) != len(data):
return True
initial_set = set(force_text(value) for value in self.prepare_value(initial))
data_set = set(force_text(value) for value in data)
return data_set != initial_set
def modelform_defines_fields(form_class):
return (form_class is not None and (
hasattr(form_class, '_meta') and
(form_class._meta.fields is not None or
form_class._meta.exclude is not None)
))
|
mit
|
[
624,
199,
4433,
3423,
367,
6425,
8204,
3992,
687,
5634,
1709,
199,
460,
3050,
901,
2251,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
3598,
199,
504,
5055,
492,
8773,
199,
504,
7975,
492,
6036,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
334,
272,
11214,
63,
8609,
63,
21477,
12,
27691,
12,
11897,
12,
8505,
12,
199,
9,
199,
504,
1639,
14,
3351,
14,
955,
492,
16053,
792,
12,
5024,
199,
504,
1639,
14,
3351,
14,
3351,
492,
3523,
2821,
12,
1487,
4925,
1905,
7304,
29387,
199,
504,
1639,
14,
3351,
14,
31033,
492,
3523,
14736,
12,
11068,
63,
3702,
199,
504,
1639,
14,
3351,
14,
1208,
492,
4520,
1296,
199,
504,
1639,
14,
3351,
14,
8583,
492,
334,
272,
26401,
3205,
12,
14326,
25419,
12,
9496,
8433,
12,
199,
9,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
1167,
3849,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
12,
11179,
63,
505,
199,
504,
1639,
14,
1208,
14,
505,
492,
4021,
2246,
12,
664,
63,
505,
63,
513,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
12,
10366,
63,
6395,
465,
485,
199,
199,
363,
452,
363,
275,
334,
272,
283,
15937,
297,
283,
1563,
15937,
297,
283,
1238,
63,
475,
63,
807,
297,
283,
955,
63,
509,
63,
1238,
297,
272,
283,
2117,
63,
842,
297,
283,
1685,
15792,
297,
283,
1685,
8433,
15792,
297,
272,
283,
1761,
63,
12767,
297,
283,
27687,
14736,
297,
283,
632,
24849,
409,
63,
3702,
297,
272,
283,
1563,
10307,
14736,
297,
283,
6460,
10724,
63,
3702,
297,
283,
632,
24849,
63,
3702,
297,
199,
9,
199,
199,
1761,
63,
12767,
275,
2560,
452,
12217,
421,
199,
318,
6982,
63,
842,
8,
964,
12,
1256,
12,
1504,
29,
403,
12,
5760,
29,
403,
304,
272,
408,
272,
9215,
83,
436,
2529,
282,
1402,
1256,
687,
314,
3914,
1124,
964,
1040,
7,
83,
272,
1124,
8275,
63,
576,
4542,
1325,
1630,
440,
3354,
314,
2138,
1256,
370,
314,
272,
3050,
14,
272,
408,
272,
687,
1639,
14,
697,
492,
1709,
272,
3999,
275,
1256,
423,
2024,
339,
12364,
63,
576,
275,
1824,
14,
8275,
63,
576,
272,
570,
63,
698,
63,
513,
275,
942,
272,
367,
289,
315,
3999,
14,
955,
26,
267,
340,
440,
289,
14,
10820,
503,
1228,
8,
70,
12,
1709,
14,
4378,
9,
971,
355,
503,
289,
14,
354,
440,
315,
12364,
63,
576,
26,
288,
1980,
267,
340,
1504,
365,
440,
488,
436,
289,
14,
354,
440,
315,
1504,
26,
288,
1980,
267,
340,
5760,
436,
289,
14,
354,
315,
5760,
26,
288,
1980,
267,
327,
1487,
2412,
13369,
570,
13,
466,
1504,
5133,
2410,
314,
1163,
1504,
12,
880,
282,
267,
327,
4550,
5802,
63,
475,
883,
675,
314,
1338,
687,
1163,
1504,
14,
267,
340,
1228,
8,
70,
12,
1709,
14,
23252,
304,
288,
570,
63,
698,
63,
513,
14,
740,
8,
70,
9,
267,
587,
26,
288,
289,
14,
2117,
63,
964,
63,
576,
8,
842,
12,
12364,
63,
576,
59,
70,
14,
354,
566,
339,
367,
289,
315,
570,
63,
698,
63,
513,
26,
267,
289,
14,
2117,
63,
964,
63,
576,
8,
842,
12,
12364,
63,
576,
59,
70,
14,
354,
566,
339,
372,
1256,
421,
199,
318,
3354,
63,
842,
8,
964,
12,
1256,
12,
1504,
29,
403,
12,
2449,
63,
1188,
534,
8420,
297,
2116,
5532,
29,
549,
12,
5760,
29,
403,
12,
6982,
29,
549,
304,
272,
408,
272,
428,
7047,
3914,
8204,
1124,
964,
1040,
7,
83,
12364,
63,
576,
1901,
1402,
1256,
1124,
842,
4345,
339,
982,
5532,
29,
549,
12,
2066,
314,
4493,
370,
1124,
842,
1040,
911,
506,
6290,
370,
314,
272,
3050,
14,
1803,
1124,
842,
4345,
339,
982,
6982,
29,
797,
12,
5534,
1124,
842,
1040,
965,
2575,
2757,
14701,
436,
272,
2951,
4839,
370,
506,
6290,
14,
272,
408,
272,
340,
6982,
26,
267,
1256,
275,
6982,
63,
842,
8,
964,
12,
1256,
12,
1504,
12,
5760,
9,
272,
3999,
275,
1256,
423,
2024,
272,
340,
1824,
14,
2550,
26,
267,
746,
1722,
480,
1918,
450,
83,
4293,
440,
506,
450,
83,
2952,
314,
666,
9980,
1133,
2,
586,
298,
4107,
2122,
450,
334,
3291,
14,
785,
63,
354,
12,
2449,
63,
1188,
430,
339,
327,
20322,
1536,
314,
13369,
402,
333,
18,
77,
666,
465,
282,
805,
14,
272,
347,
3354,
63,
77,
18,
77,
837,
267,
12364,
63,
576,
275,
1824,
14,
8275,
63,
576,
267,
327,
3390,
626,
367,
32530,
14872,
781,
2934,
370,
2387,
2597,
267,
327,
5791,
63,
955,
2348,
14,
334,
9417,
12617,
1990,
10889,
282,
4026,
267,
327,
333,
18,
77,
901,
680,
267,
367,
289,
315,
6036,
8,
3291,
14,
3479,
63,
475,
63,
3479,
12,
3999,
14,
2065,
63,
955,
304,
288,
340,
440,
2688,
8,
70,
12,
283,
2117,
63,
964,
63,
576,
735,
355,
1980,
288,
340,
1504,
436,
289,
14,
354,
440,
315,
1504,
26,
355,
1980,
288,
340,
5760,
436,
289,
14,
354,
315,
5760,
26,
355,
1980,
288,
340,
289,
14,
354,
315,
12364,
63,
576,
26,
355,
289,
14,
2117,
63,
964,
63,
576,
8,
842,
12,
12364,
63,
576,
59,
70,
14,
354,
566,
272,
340,
5532,
26,
267,
327,
982,
781,
787,
5532,
1337,
12,
3354,
314,
1256,
436,
314,
333,
18,
77,
666,
9939,
14,
267,
1256,
14,
2117,
342,
267,
3354,
63,
77,
18,
77,
342,
272,
587,
26,
267,
327,
2136,
3984,
440,
5532,
1337,
14,
2654,
282,
1083,
370,
314,
1824,
370,
2040,
12309,
267,
327,
13369,
402,
333,
18,
77,
666,
14,
267,
1824,
14,
2117,
63,
77,
18,
77,
275,
3354,
63,
77,
18,
77,
272,
372,
1256,
421,
199,
3,
5822,
26028,
15779,
3,
199,
199,
318,
1402,
63,
475,
63,
807,
8,
842,
12,
1504,
29,
403,
12,
5760,
29,
403,
304,
272,
408,
272,
1803,
282,
1211,
3035,
314,
666,
315,
1124,
842,
1040,
11233,
367,
9476,
465,
272,
282,
8204,
1159,
1124,
2747,
1040,
4252,
1423,
14,
339,
1124,
955,
1040,
365,
376,
2716,
769,
402,
901,
1561
] |
[
199,
4433,
3423,
367,
6425,
8204,
3992,
687,
5634,
1709,
199,
460,
3050,
901,
2251,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
3598,
199,
504,
5055,
492,
8773,
199,
504,
7975,
492,
6036,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
334,
272,
11214,
63,
8609,
63,
21477,
12,
27691,
12,
11897,
12,
8505,
12,
199,
9,
199,
504,
1639,
14,
3351,
14,
955,
492,
16053,
792,
12,
5024,
199,
504,
1639,
14,
3351,
14,
3351,
492,
3523,
2821,
12,
1487,
4925,
1905,
7304,
29387,
199,
504,
1639,
14,
3351,
14,
31033,
492,
3523,
14736,
12,
11068,
63,
3702,
199,
504,
1639,
14,
3351,
14,
1208,
492,
4520,
1296,
199,
504,
1639,
14,
3351,
14,
8583,
492,
334,
272,
26401,
3205,
12,
14326,
25419,
12,
9496,
8433,
12,
199,
9,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
1167,
3849,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
12,
11179,
63,
505,
199,
504,
1639,
14,
1208,
14,
505,
492,
4021,
2246,
12,
664,
63,
505,
63,
513,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
12,
10366,
63,
6395,
465,
485,
199,
199,
363,
452,
363,
275,
334,
272,
283,
15937,
297,
283,
1563,
15937,
297,
283,
1238,
63,
475,
63,
807,
297,
283,
955,
63,
509,
63,
1238,
297,
272,
283,
2117,
63,
842,
297,
283,
1685,
15792,
297,
283,
1685,
8433,
15792,
297,
272,
283,
1761,
63,
12767,
297,
283,
27687,
14736,
297,
283,
632,
24849,
409,
63,
3702,
297,
272,
283,
1563,
10307,
14736,
297,
283,
6460,
10724,
63,
3702,
297,
283,
632,
24849,
63,
3702,
297,
199,
9,
199,
199,
1761,
63,
12767,
275,
2560,
452,
12217,
421,
199,
318,
6982,
63,
842,
8,
964,
12,
1256,
12,
1504,
29,
403,
12,
5760,
29,
403,
304,
272,
408,
272,
9215,
83,
436,
2529,
282,
1402,
1256,
687,
314,
3914,
1124,
964,
1040,
7,
83,
272,
1124,
8275,
63,
576,
4542,
1325,
1630,
440,
3354,
314,
2138,
1256,
370,
314,
272,
3050,
14,
272,
408,
272,
687,
1639,
14,
697,
492,
1709,
272,
3999,
275,
1256,
423,
2024,
339,
12364,
63,
576,
275,
1824,
14,
8275,
63,
576,
272,
570,
63,
698,
63,
513,
275,
942,
272,
367,
289,
315,
3999,
14,
955,
26,
267,
340,
440,
289,
14,
10820,
503,
1228,
8,
70,
12,
1709,
14,
4378,
9,
971,
355,
503,
289,
14,
354,
440,
315,
12364,
63,
576,
26,
288,
1980,
267,
340,
1504,
365,
440,
488,
436,
289,
14,
354,
440,
315,
1504,
26,
288,
1980,
267,
340,
5760,
436,
289,
14,
354,
315,
5760,
26,
288,
1980,
267,
327,
1487,
2412,
13369,
570,
13,
466,
1504,
5133,
2410,
314,
1163,
1504,
12,
880,
282,
267,
327,
4550,
5802,
63,
475,
883,
675,
314,
1338,
687,
1163,
1504,
14,
267,
340,
1228,
8,
70,
12,
1709,
14,
23252,
304,
288,
570,
63,
698,
63,
513,
14,
740,
8,
70,
9,
267,
587,
26,
288,
289,
14,
2117,
63,
964,
63,
576,
8,
842,
12,
12364,
63,
576,
59,
70,
14,
354,
566,
339,
367,
289,
315,
570,
63,
698,
63,
513,
26,
267,
289,
14,
2117,
63,
964,
63,
576,
8,
842,
12,
12364,
63,
576,
59,
70,
14,
354,
566,
339,
372,
1256,
421,
199,
318,
3354,
63,
842,
8,
964,
12,
1256,
12,
1504,
29,
403,
12,
2449,
63,
1188,
534,
8420,
297,
2116,
5532,
29,
549,
12,
5760,
29,
403,
12,
6982,
29,
549,
304,
272,
408,
272,
428,
7047,
3914,
8204,
1124,
964,
1040,
7,
83,
12364,
63,
576,
1901,
1402,
1256,
1124,
842,
4345,
339,
982,
5532,
29,
549,
12,
2066,
314,
4493,
370,
1124,
842,
1040,
911,
506,
6290,
370,
314,
272,
3050,
14,
1803,
1124,
842,
4345,
339,
982,
6982,
29,
797,
12,
5534,
1124,
842,
1040,
965,
2575,
2757,
14701,
436,
272,
2951,
4839,
370,
506,
6290,
14,
272,
408,
272,
340,
6982,
26,
267,
1256,
275,
6982,
63,
842,
8,
964,
12,
1256,
12,
1504,
12,
5760,
9,
272,
3999,
275,
1256,
423,
2024,
272,
340,
1824,
14,
2550,
26,
267,
746,
1722,
480,
1918,
450,
83,
4293,
440,
506,
450,
83,
2952,
314,
666,
9980,
1133,
2,
586,
298,
4107,
2122,
450,
334,
3291,
14,
785,
63,
354,
12,
2449,
63,
1188,
430,
339,
327,
20322,
1536,
314,
13369,
402,
333,
18,
77,
666,
465,
282,
805,
14,
272,
347,
3354,
63,
77,
18,
77,
837,
267,
12364,
63,
576,
275,
1824,
14,
8275,
63,
576,
267,
327,
3390,
626,
367,
32530,
14872,
781,
2934,
370,
2387,
2597,
267,
327,
5791,
63,
955,
2348,
14,
334,
9417,
12617,
1990,
10889,
282,
4026,
267,
327,
333,
18,
77,
901,
680,
267,
367,
289,
315,
6036,
8,
3291,
14,
3479,
63,
475,
63,
3479,
12,
3999,
14,
2065,
63,
955,
304,
288,
340,
440,
2688,
8,
70,
12,
283,
2117,
63,
964,
63,
576,
735,
355,
1980,
288,
340,
1504,
436,
289,
14,
354,
440,
315,
1504,
26,
355,
1980,
288,
340,
5760,
436,
289,
14,
354,
315,
5760,
26,
355,
1980,
288,
340,
289,
14,
354,
315,
12364,
63,
576,
26,
355,
289,
14,
2117,
63,
964,
63,
576,
8,
842,
12,
12364,
63,
576,
59,
70,
14,
354,
566,
272,
340,
5532,
26,
267,
327,
982,
781,
787,
5532,
1337,
12,
3354,
314,
1256,
436,
314,
333,
18,
77,
666,
9939,
14,
267,
1256,
14,
2117,
342,
267,
3354,
63,
77,
18,
77,
342,
272,
587,
26,
267,
327,
2136,
3984,
440,
5532,
1337,
14,
2654,
282,
1083,
370,
314,
1824,
370,
2040,
12309,
267,
327,
13369,
402,
333,
18,
77,
666,
14,
267,
1824,
14,
2117,
63,
77,
18,
77,
275,
3354,
63,
77,
18,
77,
272,
372,
1256,
421,
199,
3,
5822,
26028,
15779,
3,
199,
199,
318,
1402,
63,
475,
63,
807,
8,
842,
12,
1504,
29,
403,
12,
5760,
29,
403,
304,
272,
408,
272,
1803,
282,
1211,
3035,
314,
666,
315,
1124,
842,
1040,
11233,
367,
9476,
465,
272,
282,
8204,
1159,
1124,
2747,
1040,
4252,
1423,
14,
339,
1124,
955,
1040,
365,
376,
2716,
769,
402,
901,
1561,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
nttks/jenkins-test
|
common/lib/xmodule/xmodule/tests/test_imageannotation.py
|
25
|
3487
|
# -*- coding: utf-8 -*-
"""Test for Image Annotation Xmodule functional logic."""
import unittest
from mock import Mock
from lxml import etree
from xblock.field_data import DictFieldData
from xblock.fields import ScopeIds
from xmodule.imageannotation_module import ImageAnnotationModule
from . import get_test_system
class ImageAnnotationModuleTestCase(unittest.TestCase):
''' Image Annotation Module Test Case '''
sample_xml = '''
<annotatable>
<instructions><p>Image Test Instructions.</p></instructions>
<json>
navigatorSizeRatio: 0.25,
wrapHorizontal: false,
showNavigator: true,
navigatorPosition: "BOTTOM_LEFT",
showNavigationControl: true,
tileSources: [{
Image: {
xmlns: "http://schemas.microsoft.com/deepzoom/2009",
Url: "http://static.seadragon.com/content/misc/milwaukee_files/",
TileSize: "254",
Overlap: "1",
Format: "jpg",
ServerFormat: "Default",
Size: {
Width: "15497",
Height: "5378"
}
}
},],
</json>
</annotatable>
'''
def setUp(self):
"""
Makes sure that the Module is declared and mocked with the sample xml above.
"""
# return anything except None to test LMS
def test_real_user(useless):
useless_user = Mock(email='fake@fake.com', id=useless)
return useless_user
# test to make sure that role is checked in LMS
def test_user_role():
return 'staff'
self.system = get_test_system()
self.system.get_real_user = test_real_user
self.system.get_user_role = test_user_role
self.system.anonymous_student_id = None
self.mod = ImageAnnotationModule(
Mock(),
self.system,
DictFieldData({'data': self.sample_xml}),
ScopeIds(None, None, None, None)
)
def test_extract_instructions(self):
"""
Tests to make sure that the instructions are correctly pulled from the sample xml above.
It also makes sure that if no instructions exist, that it does in fact return nothing.
"""
xmltree = etree.fromstring(self.sample_xml)
expected_xml = u"<div><p>Image Test Instructions.</p></div>"
actual_xml = self.mod._extract_instructions(xmltree) # pylint: disable=protected-access
self.assertIsNotNone(actual_xml)
self.assertEqual(expected_xml.strip(), actual_xml.strip())
xmltree = etree.fromstring('<annotatable>foo</annotatable>')
actual = self.mod._extract_instructions(xmltree) # pylint: disable=protected-access
self.assertIsNone(actual)
def test_student_view(self):
"""
Tests the function that passes in all the information in the context that will be used in templates/textannotation.html
"""
context = self.mod.student_view({}).content
for key in ['display_name', 'instructions_html', 'annotation_storage', 'token', 'tag', 'openseadragonjson', 'default_tab', 'instructor_email', 'annotation_mode', 'is_course_staff']:
self.assertIn(key, context)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
774,
367,
6047,
30793,
1323,
578,
22380,
9661,
1041,
199,
199,
646,
2882,
199,
504,
1683,
492,
4420,
199,
504,
14490,
492,
7559,
199,
199,
504,
12971,
14,
698,
63,
576,
492,
7448,
792,
1451,
199,
504,
12971,
14,
955,
492,
20488,
11506,
199,
199,
504,
9872,
14,
1569,
9340,
63,
578,
492,
6047,
16768,
2377,
199,
199,
504,
1275,
492,
664,
63,
396,
63,
2253,
421,
199,
533,
6047,
16768,
2377,
1746,
8,
2796,
14,
1746,
304,
272,
1449,
6047,
30793,
5673,
1379,
12425,
1449,
272,
2690,
63,
1652,
275,
1449,
267,
665,
3226,
15511,
30,
288,
665,
20718,
2535,
80,
30,
3491,
1379,
1010,
10583,
9758,
80,
2957,
20718,
30,
288,
665,
1001,
30,
355,
12670,
24934,
2320,
13971,
26,
378,
14,
821,
12,
355,
4816,
19918,
26,
258,
3055,
12,
355,
2498,
19617,
24934,
26,
2549,
12,
355,
12670,
24934,
5625,
26,
298,
27838,
63,
9894,
401,
355,
2498,
19617,
5360,
3717,
26,
2549,
12,
355,
12835,
13959,
26,
257,
8910,
490,
6047,
26,
221,
469,
717,
9604,
26,
298,
1014,
921,
9482,
14,
17040,
14,
957,
15,
16131,
10598,
15,
8664,
401,
717,
20503,
26,
298,
1014,
921,
1986,
14,
261,
350,
2527,
265,
14,
957,
15,
1317,
15,
9923,
15,
77,
382,
758,
85,
415,
69,
63,
1725,
10665,
717,
377,
441,
2320,
26,
298,
8306,
401,
717,
7259,
4762,
26,
298,
17,
401,
717,
9701,
26,
298,
8476,
401,
717,
7146,
3484,
26,
298,
2698,
401,
717,
14579,
26,
469,
1169,
644,
1466,
26,
298,
1046,
19180,
401,
1169,
5311,
1070,
26,
298,
21,
12046,
2,
717,
789,
490,
789,
355,
1660,
467,
288,
3068,
1001,
30,
267,
3068,
3226,
15511,
30,
272,
1449,
339,
347,
3613,
8,
277,
304,
267,
408,
288,
23365,
3238,
626,
314,
5673,
365,
14290,
436,
16991,
543,
314,
2690,
2748,
3432,
14,
267,
408,
267,
327,
372,
7003,
871,
488,
370,
511,
27540,
267,
347,
511,
63,
3093,
63,
751,
8,
1180,
2003,
304,
288,
31291,
63,
751,
275,
4420,
8,
2123,
534,
3183,
32,
3183,
14,
957,
297,
1305,
29,
1180,
2003,
9,
288,
372,
31291,
63,
751,
398,
327,
511,
370,
1852,
3238,
626,
4719,
365,
7923,
315,
27540,
267,
347,
511,
63,
751,
63,
3756,
837,
288,
372,
283,
7018,
7,
398,
291,
14,
2253,
275,
664,
63,
396,
63,
2253,
342,
267,
291,
14,
2253,
14,
362,
63,
3093,
63,
751,
275,
511,
63,
3093,
63,
751,
267,
291,
14,
2253,
14,
362,
63,
751,
63,
3756,
275,
511,
63,
751,
63,
3756,
267,
291,
14,
2253,
14,
12628,
63,
5500,
63,
344,
275,
488,
398,
291,
14,
1494,
275,
6047,
16768,
2377,
8,
288,
4420,
1062,
288,
291,
14,
2253,
12,
288,
7448,
792,
1451,
3252,
576,
356,
291,
14,
3271,
63,
1652,
8688,
288,
20488,
11506,
8,
403,
12,
488,
12,
488,
12,
488,
9,
267,
776,
339,
347,
511,
63,
5005,
63,
20718,
8,
277,
304,
267,
408,
267,
6496,
370,
1852,
3238,
626,
314,
15794,
787,
6657,
25239,
1146,
687,
314,
2690,
2748,
3432,
14,
267,
2779,
2597,
7704,
3238,
626,
340,
949,
15794,
2187,
12,
626,
652,
1630,
315,
10572,
372,
6548,
14,
267,
408,
267,
2748,
2350,
275,
7559,
14,
13521,
8,
277,
14,
3271,
63,
1652,
9,
398,
1420,
63,
1652,
275,
399,
17030,
3015,
2535,
80,
30,
3491,
1379,
1010,
10583,
9758,
80,
2957,
3015,
4335,
267,
3503,
63,
1652,
275,
291,
14,
1494,
423,
5005,
63,
20718,
8,
1652,
2350,
9,
221,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
267,
291,
14,
10389,
8,
6514,
63,
1652,
9,
267,
291,
14,
629,
8,
2062,
63,
1652,
14,
1913,
1062,
3503,
63,
1652,
14,
1913,
1012,
398,
2748,
2350,
275,
7559,
14,
13521,
4827,
3226,
15511,
30,
1421,
1108,
3226,
15511,
5971,
267,
3503,
275,
291,
14,
1494,
423,
5005,
63,
20718,
8,
1652,
2350,
9,
221,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
267,
291,
14,
7702,
8,
6514,
9,
339,
347,
511,
63,
5500,
63,
1345,
8,
277,
304,
267,
408,
267,
6496,
314,
805,
626,
14933,
315,
1006,
314,
2556,
315,
314,
1067,
626,
911,
506,
1202,
315,
7009,
15,
505,
9340,
14,
1360,
267,
408,
267,
1067,
275,
291,
14,
1494,
14,
5500,
63,
1345,
24692,
680,
1317,
267,
367,
790,
315,
788,
2918,
63,
354,
297,
283,
20718,
63,
1360,
297,
283,
9340,
63,
3494,
297,
283,
1418,
297,
283,
1450,
297,
283,
26158,
350,
2527,
265,
1001,
297,
283,
885,
63,
2902,
297,
283,
14891,
63,
2123,
297,
283,
9340,
63,
632,
297,
283,
374,
63,
1972,
63,
7018,
2565,
288,
291,
14,
4080,
8,
498,
12,
1067,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
774,
367,
6047,
30793,
1323,
578,
22380,
9661,
1041,
199,
199,
646,
2882,
199,
504,
1683,
492,
4420,
199,
504,
14490,
492,
7559,
199,
199,
504,
12971,
14,
698,
63,
576,
492,
7448,
792,
1451,
199,
504,
12971,
14,
955,
492,
20488,
11506,
199,
199,
504,
9872,
14,
1569,
9340,
63,
578,
492,
6047,
16768,
2377,
199,
199,
504,
1275,
492,
664,
63,
396,
63,
2253,
421,
199,
533,
6047,
16768,
2377,
1746,
8,
2796,
14,
1746,
304,
272,
1449,
6047,
30793,
5673,
1379,
12425,
1449,
272,
2690,
63,
1652,
275,
1449,
267,
665,
3226,
15511,
30,
288,
665,
20718,
2535,
80,
30,
3491,
1379,
1010,
10583,
9758,
80,
2957,
20718,
30,
288,
665,
1001,
30,
355,
12670,
24934,
2320,
13971,
26,
378,
14,
821,
12,
355,
4816,
19918,
26,
258,
3055,
12,
355,
2498,
19617,
24934,
26,
2549,
12,
355,
12670,
24934,
5625,
26,
298,
27838,
63,
9894,
401,
355,
2498,
19617,
5360,
3717,
26,
2549,
12,
355,
12835,
13959,
26,
257,
8910,
490,
6047,
26,
221,
469,
717,
9604,
26,
298,
1014,
921,
9482,
14,
17040,
14,
957,
15,
16131,
10598,
15,
8664,
401,
717,
20503,
26,
298,
1014,
921,
1986,
14,
261,
350,
2527,
265,
14,
957,
15,
1317,
15,
9923,
15,
77,
382,
758,
85,
415,
69,
63,
1725,
10665,
717,
377,
441,
2320,
26,
298,
8306,
401,
717,
7259,
4762,
26,
298,
17,
401,
717,
9701,
26,
298,
8476,
401,
717,
7146,
3484,
26,
298,
2698,
401,
717,
14579,
26,
469,
1169,
644,
1466,
26,
298,
1046,
19180,
401,
1169,
5311,
1070,
26,
298,
21,
12046,
2,
717,
789,
490,
789,
355,
1660,
467,
288,
3068,
1001,
30,
267,
3068,
3226,
15511,
30,
272,
1449,
339,
347,
3613,
8,
277,
304,
267,
408,
288,
23365,
3238,
626,
314,
5673,
365,
14290,
436,
16991,
543,
314,
2690,
2748,
3432,
14,
267,
408,
267,
327,
372,
7003,
871,
488,
370,
511,
27540,
267,
347,
511,
63,
3093,
63,
751,
8,
1180,
2003,
304,
288,
31291,
63,
751,
275,
4420,
8,
2123,
534,
3183,
32,
3183,
14,
957,
297,
1305,
29,
1180,
2003,
9,
288,
372,
31291,
63,
751,
398,
327,
511,
370,
1852,
3238,
626,
4719,
365,
7923,
315,
27540,
267,
347,
511,
63,
751,
63,
3756,
837,
288,
372,
283,
7018,
7,
398,
291,
14,
2253,
275,
664,
63,
396,
63,
2253,
342,
267,
291,
14,
2253,
14,
362,
63,
3093,
63,
751,
275,
511,
63,
3093,
63,
751,
267,
291,
14,
2253,
14,
362,
63,
751,
63,
3756,
275,
511,
63,
751,
63,
3756,
267,
291,
14,
2253,
14,
12628,
63,
5500,
63,
344,
275,
488,
398,
291,
14,
1494,
275,
6047,
16768,
2377,
8,
288,
4420,
1062,
288,
291,
14,
2253,
12,
288,
7448,
792,
1451,
3252,
576,
356,
291,
14,
3271,
63,
1652,
8688,
288,
20488,
11506,
8,
403,
12,
488,
12,
488,
12,
488,
9,
267,
776,
339,
347,
511,
63,
5005,
63,
20718,
8,
277,
304,
267,
408,
267,
6496,
370,
1852,
3238,
626,
314,
15794,
787,
6657,
25239,
1146,
687,
314,
2690,
2748,
3432,
14,
267,
2779,
2597,
7704,
3238,
626,
340,
949,
15794,
2187,
12,
626,
652,
1630,
315,
10572,
372,
6548,
14,
267,
408,
267,
2748,
2350,
275,
7559,
14,
13521,
8,
277,
14,
3271,
63,
1652,
9,
398,
1420,
63,
1652,
275,
399,
17030,
3015,
2535,
80,
30,
3491,
1379,
1010,
10583,
9758,
80,
2957,
3015,
4335,
267,
3503,
63,
1652,
275,
291,
14,
1494,
423,
5005,
63,
20718,
8,
1652,
2350,
9,
221,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
267,
291,
14,
10389,
8,
6514,
63,
1652,
9,
267,
291,
14,
629,
8,
2062,
63,
1652,
14,
1913,
1062,
3503,
63,
1652,
14,
1913,
1012,
398,
2748,
2350,
275,
7559,
14,
13521,
4827,
3226,
15511,
30,
1421,
1108,
3226,
15511,
5971,
267,
3503,
275,
291,
14,
1494,
423,
5005,
63,
20718,
8,
1652,
2350,
9,
221,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
267,
291,
14,
7702,
8,
6514,
9,
339,
347,
511,
63,
5500,
63,
1345,
8,
277,
304,
267,
408,
267,
6496,
314,
805,
626,
14933,
315,
1006,
314,
2556,
315,
314,
1067,
626,
911,
506,
1202,
315,
7009,
15,
505,
9340,
14,
1360,
267,
408,
267,
1067,
275,
291,
14,
1494,
14,
5500,
63,
1345,
24692,
680,
1317,
267,
367,
790,
315,
788,
2918,
63,
354,
297,
283,
20718,
63,
1360,
297,
283,
9340,
63,
3494,
297,
283,
1418,
297,
283,
1450,
297,
283,
26158,
350,
2527,
265,
1001,
297,
283,
885,
63,
2902,
297,
283,
14891,
63,
2123,
297,
283,
9340,
63,
632,
297,
283,
374,
63,
1972,
63,
7018,
2565,
288,
291,
14,
4080,
8,
498,
12,
1067,
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,
32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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
warped-rudi/xbmc
|
tools/EventClients/lib/python/zeroconf.py
|
181
|
4874
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2008-2013 Team XBMC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""
Simple wrapper around Avahi
"""
__author__ = "d4rk@xbmc.org"
__version__ = "0.1"
try:
import time
import dbus, gobject, avahi
from dbus import DBusException
from dbus.mainloop.glib import DBusGMainLoop
except Exception, e:
print "Zeroconf support disabled. To enable, install the following Python modules:"
print " dbus, gobject, avahi"
pass
SERVICE_FOUND = 1
SERVICE_LOST = 2
class Browser:
""" Simple Zeroconf Browser """
def __init__( self, service_types = {} ):
"""
service_types - dictionary of services => handlers
"""
self._stop = False
self.loop = DBusGMainLoop()
self.bus = dbus.SystemBus( mainloop=self.loop )
self.server = dbus.Interface( self.bus.get_object( avahi.DBUS_NAME, '/' ),
'org.freedesktop.Avahi.Server')
self.handlers = {}
for type in service_types.keys():
self.add_service( type, service_types[ type ] )
def add_service( self, type, handler = None ):
"""
Add a service that the browser should watch for
"""
self.sbrowser = dbus.Interface(
self.bus.get_object(
avahi.DBUS_NAME,
self.server.ServiceBrowserNew(
avahi.IF_UNSPEC,
avahi.PROTO_UNSPEC,
type,
'local',
dbus.UInt32(0)
)
),
avahi.DBUS_INTERFACE_SERVICE_BROWSER)
self.handlers[ type ] = handler
self.sbrowser.connect_to_signal("ItemNew", self._new_item_handler)
self.sbrowser.connect_to_signal("ItemRemove", self._remove_item_handler)
def run(self):
"""
Run the gobject event loop
"""
# Don't use loop.run() because Python's GIL will block all threads
loop = gobject.MainLoop()
context = loop.get_context()
while not self._stop:
if context.pending():
context.iteration( True )
else:
time.sleep(1)
def stop(self):
"""
Stop the gobject event loop
"""
self._stop = True
def _new_item_handler(self, interface, protocol, name, stype, domain, flags):
if flags & avahi.LOOKUP_RESULT_LOCAL:
# local service, skip
pass
self.server.ResolveService(
interface,
protocol,
name,
stype,
domain,
avahi.PROTO_UNSPEC,
dbus.UInt32(0),
reply_handler = self._service_resolved_handler,
error_handler = self._error_handler
)
return
def _remove_item_handler(self, interface, protocol, name, stype, domain, flags):
if self.handlers[ stype ]:
# FIXME: more details needed here
try:
self.handlers[ stype ]( SERVICE_LOST, { 'type' : stype, 'name' : name } )
except:
pass
def _service_resolved_handler( self, *args ):
service = {}
service['type'] = str( args[3] )
service['name'] = str( args[2] )
service['address'] = str( args[7] )
service['hostname'] = str( args[5] )
service['port'] = int( args[8] )
# if the service type has a handler call it
try:
if self.handlers[ args[3] ]:
self.handlers[ args[3] ]( SERVICE_FOUND, service )
except:
pass
def _error_handler( self, *args ):
print 'ERROR: %s ' % str( args[0] )
if __name__ == "__main__":
def service_handler( found, service ):
print "---------------------"
print ['Found Service', 'Lost Service'][found-1]
for key in service.keys():
print key+" : "+str( service[key] )
browser = Browser( {
'_xbmc-events._udp' : service_handler,
'_xbmc-web._tcp' : service_handler
} )
browser.run()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
257,
1898,
334,
35,
9,
9079,
13,
6965,
11682,
1323,
28994,
199,
3,
199,
3,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
257,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
257,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
199,
3,
257,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
257,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
199,
624,
199,
3184,
4975,
6818,
437,
3042,
5812,
199,
624,
199,
199,
363,
2502,
363,
221,
275,
298,
68,
20,
23992,
32,
21382,
14,
1308,
2,
199,
363,
1023,
363,
275,
298,
16,
14,
17,
2,
199,
199,
893,
26,
272,
492,
900,
272,
492,
21140,
12,
25595,
12,
2289,
65,
5812,
272,
687,
21140,
492,
6249,
527,
1726,
272,
687,
21140,
14,
22644,
14,
30816,
492,
6249,
527,
39,
6756,
7382,
199,
2590,
2186,
12,
325,
26,
272,
870,
298,
8681,
2190,
2291,
6980,
14,
4005,
4756,
12,
3907,
314,
2569,
2018,
4621,
5424,
272,
870,
298,
259,
21140,
12,
25595,
12,
2289,
65,
5812,
2,
272,
986,
199,
199,
10486,
63,
13945,
221,
275,
413,
199,
10486,
63,
1484,
840,
257,
275,
499,
199,
199,
533,
27620,
26,
272,
408,
5870,
15708,
2190,
27620,
408,
339,
347,
636,
826,
721,
291,
12,
2435,
63,
1313,
275,
1052,
3461,
267,
408,
267,
2435,
63,
1313,
446,
2600,
402,
8500,
9265,
8297,
267,
408,
267,
291,
423,
2379,
275,
756,
267,
291,
14,
3813,
275,
6249,
527,
39,
6756,
7382,
342,
267,
291,
14,
5610,
275,
21140,
14,
3989,
12106,
8,
2446,
3813,
29,
277,
14,
3813,
776,
267,
291,
14,
1000,
275,
21140,
14,
4267,
8,
291,
14,
5610,
14,
362,
63,
785,
8,
2289,
65,
5812,
14,
2846,
1668,
63,
2339,
12,
7324,
2318,
639,
283,
1308,
14,
4624,
14487,
14,
33,
3042,
5812,
14,
3120,
358,
267,
291,
14,
5586,
275,
1052,
398,
367,
730,
315,
2435,
63,
1313,
14,
1612,
837,
288,
291,
14,
525,
63,
1364,
8,
730,
12,
2435,
63,
1313,
59,
730,
1622,
776,
2378,
347,
1050,
63,
1364,
8,
291,
12,
730,
12,
3016,
275,
488,
3461,
267,
408,
267,
2654,
282,
2435,
626,
314,
7042,
1077,
9626,
367,
267,
408,
267,
291,
14,
83,
5750,
275,
21140,
14,
4267,
8,
288,
291,
14,
5610,
14,
362,
63,
785,
8,
355,
2289,
65,
5812,
14,
2846,
1668,
63,
2339,
12,
355,
291,
14,
1000,
14,
3167,
11930,
4665,
8,
490,
2289,
65,
5812,
14,
4656,
63,
1734,
24147,
12,
490,
2289,
65,
5812,
14,
7459,
63,
1734,
24147,
12,
490,
730,
12,
490,
283,
1832,
297,
490,
21140,
14,
13304,
708,
8,
16,
9,
490,
776,
355,
2318,
288,
2289,
65,
5812,
14,
2846,
1668,
63,
17598,
63,
10486,
63,
31956,
3279,
9,
267,
291,
14,
5586,
59,
730,
1622,
275,
3016,
267,
291,
14,
83,
5750,
14,
2242,
63,
475,
63,
4653,
480,
2081,
4665,
401,
291,
423,
1222,
63,
1053,
63,
2232,
9,
267,
291,
14,
83,
5750,
14,
2242,
63,
475,
63,
4653,
480,
2081,
5587,
401,
291,
423,
2168,
63,
1053,
63,
2232,
9,
2378,
347,
1255,
8,
277,
304,
267,
408,
267,
3378,
314,
25595,
1566,
4438,
267,
408,
267,
327,
7529,
1133,
675,
4438,
14,
1065,
342,
2952,
2018,
1159,
598,
1193,
911,
1853,
1006,
7183,
267,
4438,
275,
25595,
14,
6756,
7382,
342,
267,
1067,
275,
4438,
14,
362,
63,
1100,
342,
267,
1830,
440,
291,
423,
2379,
26,
288,
340,
1067,
14,
6455,
837,
355,
1067,
14,
12575,
8,
715,
776,
288,
587,
26,
355,
900,
14,
4532,
8,
17,
9,
339,
347,
3631,
8,
277,
304,
267,
408,
267,
8015,
314,
25595,
1566,
4438,
267,
408,
267,
291,
423,
2379,
275,
715,
2378,
347,
485,
1222,
63,
1053,
63,
2232,
8,
277,
12,
3217,
12,
4113,
12,
536,
12,
410,
514,
12,
2881,
12,
3285,
304,
267,
340,
3285,
1253,
2289,
65,
5812,
14,
29149,
63,
9517,
63,
7486,
26,
288,
327,
2257,
2435,
12,
3372,
288,
986,
398,
291,
14,
1000,
14,
27459,
3167,
8,
288,
3217,
12,
288,
4113,
12,
288,
536,
12,
288,
410,
514,
12,
288,
2881,
12,
288,
2289,
65,
5812,
14,
7459,
63,
1734,
24147,
12,
288,
21140,
14,
13304,
708,
8,
16,
395,
288,
9351,
63,
2232,
275,
291,
423,
1364,
63,
13697,
63,
2232,
12,
288,
1125,
63,
2232,
275,
291,
423,
705,
63,
2232,
288,
776,
267,
372,
2378,
347,
485,
2168,
63,
1053,
63,
2232,
8,
277,
12,
3217,
12,
4113,
12,
536,
12,
410,
514,
12,
2881,
12,
3285,
304,
267,
340,
291,
14,
5586,
59,
410,
514,
16246,
288,
327,
7600,
26,
1655,
2436,
4346,
2348,
288,
862,
26,
355,
291,
14,
5586,
59,
410,
514,
1622,
8,
16655,
63,
1484,
840,
12,
469,
283,
466,
7,
520,
410,
514,
12,
283,
354,
7,
520,
536,
789,
776,
288,
871,
26,
355,
986,
2378,
347,
485,
1364,
63,
13697,
63,
2232,
8,
291,
12,
627,
589,
3461,
267,
2435,
275,
1052,
267,
2435,
459,
466,
418,
258,
275,
620,
8,
1249,
59,
19,
61,
776,
267,
2435,
459,
354,
418,
258,
275,
620,
8,
1249,
59,
18,
61,
776,
267,
2435,
459,
1562,
418,
221,
275,
620,
8,
1249,
59,
23,
61,
776,
267,
2435,
459,
4269,
418,
275,
620,
8,
1249,
59,
21,
61,
776,
267,
2435
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
257,
1898,
334,
35,
9,
9079,
13,
6965,
11682,
1323,
28994,
199,
3,
199,
3,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
257,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
257,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
199,
3,
257,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
257,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
199,
624,
199,
3184,
4975,
6818,
437,
3042,
5812,
199,
624,
199,
199,
363,
2502,
363,
221,
275,
298,
68,
20,
23992,
32,
21382,
14,
1308,
2,
199,
363,
1023,
363,
275,
298,
16,
14,
17,
2,
199,
199,
893,
26,
272,
492,
900,
272,
492,
21140,
12,
25595,
12,
2289,
65,
5812,
272,
687,
21140,
492,
6249,
527,
1726,
272,
687,
21140,
14,
22644,
14,
30816,
492,
6249,
527,
39,
6756,
7382,
199,
2590,
2186,
12,
325,
26,
272,
870,
298,
8681,
2190,
2291,
6980,
14,
4005,
4756,
12,
3907,
314,
2569,
2018,
4621,
5424,
272,
870,
298,
259,
21140,
12,
25595,
12,
2289,
65,
5812,
2,
272,
986,
199,
199,
10486,
63,
13945,
221,
275,
413,
199,
10486,
63,
1484,
840,
257,
275,
499,
199,
199,
533,
27620,
26,
272,
408,
5870,
15708,
2190,
27620,
408,
339,
347,
636,
826,
721,
291,
12,
2435,
63,
1313,
275,
1052,
3461,
267,
408,
267,
2435,
63,
1313,
446,
2600,
402,
8500,
9265,
8297,
267,
408,
267,
291,
423,
2379,
275,
756,
267,
291,
14,
3813,
275,
6249,
527,
39,
6756,
7382,
342,
267,
291,
14,
5610,
275,
21140,
14,
3989,
12106,
8,
2446,
3813,
29,
277,
14,
3813,
776,
267,
291,
14,
1000,
275,
21140,
14,
4267,
8,
291,
14,
5610,
14,
362,
63,
785,
8,
2289,
65,
5812,
14,
2846,
1668,
63,
2339,
12,
7324,
2318,
639,
283,
1308,
14,
4624,
14487,
14,
33,
3042,
5812,
14,
3120,
358,
267,
291,
14,
5586,
275,
1052,
398,
367,
730,
315,
2435,
63,
1313,
14,
1612,
837,
288,
291,
14,
525,
63,
1364,
8,
730,
12,
2435,
63,
1313,
59,
730,
1622,
776,
2378,
347,
1050,
63,
1364,
8,
291,
12,
730,
12,
3016,
275,
488,
3461,
267,
408,
267,
2654,
282,
2435,
626,
314,
7042,
1077,
9626,
367,
267,
408,
267,
291,
14,
83,
5750,
275,
21140,
14,
4267,
8,
288,
291,
14,
5610,
14,
362,
63,
785,
8,
355,
2289,
65,
5812,
14,
2846,
1668,
63,
2339,
12,
355,
291,
14,
1000,
14,
3167,
11930,
4665,
8,
490,
2289,
65,
5812,
14,
4656,
63,
1734,
24147,
12,
490,
2289,
65,
5812,
14,
7459,
63,
1734,
24147,
12,
490,
730,
12,
490,
283,
1832,
297,
490,
21140,
14,
13304,
708,
8,
16,
9,
490,
776,
355,
2318,
288,
2289,
65,
5812,
14,
2846,
1668,
63,
17598,
63,
10486,
63,
31956,
3279,
9,
267,
291,
14,
5586,
59,
730,
1622,
275,
3016,
267,
291,
14,
83,
5750,
14,
2242,
63,
475,
63,
4653,
480,
2081,
4665,
401,
291,
423,
1222,
63,
1053,
63,
2232,
9,
267,
291,
14,
83,
5750,
14,
2242,
63,
475,
63,
4653,
480,
2081,
5587,
401,
291,
423,
2168,
63,
1053,
63,
2232,
9,
2378,
347,
1255,
8,
277,
304,
267,
408,
267,
3378,
314,
25595,
1566,
4438,
267,
408,
267,
327,
7529,
1133,
675,
4438,
14,
1065,
342,
2952,
2018,
1159,
598,
1193,
911,
1853,
1006,
7183,
267,
4438,
275,
25595,
14,
6756,
7382,
342,
267,
1067,
275,
4438,
14,
362,
63,
1100,
342,
267,
1830,
440,
291,
423,
2379,
26,
288,
340,
1067,
14,
6455,
837,
355,
1067,
14,
12575,
8,
715,
776,
288,
587,
26,
355,
900,
14,
4532,
8,
17,
9,
339,
347,
3631,
8,
277,
304,
267,
408,
267,
8015,
314,
25595,
1566,
4438,
267,
408,
267,
291,
423,
2379,
275,
715,
2378,
347,
485,
1222,
63,
1053,
63,
2232,
8,
277,
12,
3217,
12,
4113,
12,
536,
12,
410,
514,
12,
2881,
12,
3285,
304,
267,
340,
3285,
1253,
2289,
65,
5812,
14,
29149,
63,
9517,
63,
7486,
26,
288,
327,
2257,
2435,
12,
3372,
288,
986,
398,
291,
14,
1000,
14,
27459,
3167,
8,
288,
3217,
12,
288,
4113,
12,
288,
536,
12,
288,
410,
514,
12,
288,
2881,
12,
288,
2289,
65,
5812,
14,
7459,
63,
1734,
24147,
12,
288,
21140,
14,
13304,
708,
8,
16,
395,
288,
9351,
63,
2232,
275,
291,
423,
1364,
63,
13697,
63,
2232,
12,
288,
1125,
63,
2232,
275,
291,
423,
705,
63,
2232,
288,
776,
267,
372,
2378,
347,
485,
2168,
63,
1053,
63,
2232,
8,
277,
12,
3217,
12,
4113,
12,
536,
12,
410,
514,
12,
2881,
12,
3285,
304,
267,
340,
291,
14,
5586,
59,
410,
514,
16246,
288,
327,
7600,
26,
1655,
2436,
4346,
2348,
288,
862,
26,
355,
291,
14,
5586,
59,
410,
514,
1622,
8,
16655,
63,
1484,
840,
12,
469,
283,
466,
7,
520,
410,
514,
12,
283,
354,
7,
520,
536,
789,
776,
288,
871,
26,
355,
986,
2378,
347,
485,
1364,
63,
13697,
63,
2232,
8,
291,
12,
627,
589,
3461,
267,
2435,
275,
1052,
267,
2435,
459,
466,
418,
258,
275,
620,
8,
1249,
59,
19,
61,
776,
267,
2435,
459,
354,
418,
258,
275,
620,
8,
1249,
59,
18,
61,
776,
267,
2435,
459,
1562,
418,
221,
275,
620,
8,
1249,
59,
23,
61,
776,
267,
2435,
459,
4269,
418,
275,
620,
8,
1249,
59,
21,
61,
776,
267,
2435,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
HaroldMills/Vesper
|
vesper/signal/tests/test_wave_file_signal.py
|
1
|
1904
|
from pathlib import Path
from vesper.signal.signal_error import SignalError
from vesper.signal.tests.test_signal import SignalTests
from vesper.signal.time_axis import TimeAxis
from vesper.signal.wave_file_signal import WaveFileSignal
from vesper.tests.test_case import TestCase
import vesper.signal.tests.utils as utils
import vesper.tests.test_utils as test_utils
_DATA_DIR_PATH = Path(test_utils.get_test_data_dir_path(__file__))
class WaveFileSignalTests(TestCase):
def test_init(self):
cases = [
('Header Only.wav', 0, 1, 24000, '<i2'),
('One Channel.wav', 10, 1, 22050, '<i2'),
('Two Channels.wav', 10, 2, 24000, '<i2')
]
for file_name, frame_count, channel_count, frame_rate, dtype in cases:
file_path = _DATA_DIR_PATH / file_name
time_axis = TimeAxis(frame_count, frame_rate)
shape = (channel_count, frame_count)
samples = utils.create_samples(shape, dtype='<i2')
signal = WaveFileSignal(file_path, name=file_name)
SignalTests.assert_signal(
signal, file_name, time_axis, channel_count, (), dtype,
samples)
signal = WaveFileSignal(file_path)
SignalTests.assert_signal(
signal, 'Signal', time_axis, channel_count, (), dtype, samples)
def test_empty_file(self):
file_path = _DATA_DIR_PATH / 'Empty.wav'
self._assert_raises(Exception, WaveFileSignal, file_path)
def test_truncated_file(self):
file_path = _DATA_DIR_PATH / 'Truncated.wav'
signal = WaveFileSignal(file_path)
time_axis = TimeAxis(10, 22050)
SignalTests.assert_signal(signal, 'Signal', time_axis, 1, (), '<i2')
self._assert_raises(SignalError, lambda s: s.as_channels[0], signal)
|
mit
|
[
504,
32212,
492,
6912,
199,
199,
504,
373,
397,
529,
14,
4653,
14,
4653,
63,
705,
492,
18288,
547,
199,
504,
373,
397,
529,
14,
4653,
14,
2219,
14,
396,
63,
4653,
492,
18288,
2925,
199,
504,
373,
397,
529,
14,
4653,
14,
521,
63,
3127,
492,
4703,
11220,
199,
504,
373,
397,
529,
14,
4653,
14,
10024,
63,
493,
63,
4653,
492,
644,
811,
1173,
11274,
199,
504,
373,
397,
529,
14,
2219,
14,
396,
63,
2546,
492,
7640,
199,
646,
373,
397,
529,
14,
4653,
14,
2219,
14,
1208,
465,
3778,
199,
646,
373,
397,
529,
14,
2219,
14,
396,
63,
1208,
465,
511,
63,
1208,
421,
199,
63,
3998,
63,
3022,
63,
3243,
275,
6912,
8,
396,
63,
1208,
14,
362,
63,
396,
63,
576,
63,
694,
63,
515,
3460,
493,
8964,
421,
199,
533,
644,
811,
1173,
11274,
2925,
8,
1746,
304,
2378,
347,
511,
63,
826,
8,
277,
304,
2728,
5560,
275,
359,
288,
661,
2567,
5972,
14,
19118,
297,
378,
12,
413,
12,
5504,
1493,
12,
2650,
73,
18,
659,
288,
661,
4395,
17270,
14,
19118,
297,
1616,
12,
413,
12,
25647,
1400,
12,
2650,
73,
18,
659,
288,
661,
11467,
17270,
83,
14,
19118,
297,
1616,
12,
499,
12,
5504,
1493,
12,
2650,
73,
18,
358,
267,
1622,
2728,
367,
570,
63,
354,
12,
2787,
63,
835,
12,
3623,
63,
835,
12,
2787,
63,
1866,
12,
2152,
315,
5560,
26,
7846,
570,
63,
515,
275,
485,
3998,
63,
3022,
63,
3243,
1182,
570,
63,
354,
288,
900,
63,
3127,
275,
4703,
11220,
8,
1943,
63,
835,
12,
2787,
63,
1866,
9,
288,
2215,
275,
334,
2775,
63,
835,
12,
2787,
63,
835,
9,
288,
5845,
275,
3778,
14,
981,
63,
3356,
8,
1392,
12,
2152,
15829,
73,
18,
358,
7846,
4673,
275,
644,
811,
1173,
11274,
8,
493,
63,
515,
12,
536,
29,
493,
63,
354,
9,
288,
18288,
2925,
14,
479,
63,
4653,
8,
355,
4673,
12,
570,
63,
354,
12,
900,
63,
3127,
12,
3623,
63,
835,
12,
11969,
2152,
12,
355,
5845,
9,
7846,
4673,
275,
644,
811,
1173,
11274,
8,
493,
63,
515,
9,
288,
18288,
2925,
14,
479,
63,
4653,
8,
355,
4673,
12,
283,
11274,
297,
900,
63,
3127,
12,
3623,
63,
835,
12,
11969,
2152,
12,
5845,
9,
2378,
347,
511,
63,
1667,
63,
493,
8,
277,
304,
267,
570,
63,
515,
275,
485,
3998,
63,
3022,
63,
3243,
1182,
283,
4699,
14,
19118,
7,
267,
291,
423,
479,
63,
3536,
8,
1726,
12,
644,
811,
1173,
11274,
12,
570,
63,
515,
9,
268,
5493,
347,
511,
63,
19347,
63,
493,
8,
277,
304,
267,
570,
63,
515,
275,
485,
3998,
63,
3022,
63,
3243,
1182,
283,
20460,
3153,
14,
19118,
7,
267,
4673,
275,
644,
811,
1173,
11274,
8,
493,
63,
515,
9,
267,
900,
63,
3127,
275,
4703,
11220,
8,
709,
12,
25647,
1400,
9,
267,
18288,
2925,
14,
479,
63,
4653,
8,
4653,
12,
283,
11274,
297,
900,
63,
3127,
12,
413,
12,
11969,
2650,
73,
18,
358,
267,
291,
423,
479,
63,
3536,
8,
11274,
547,
12,
2400,
308,
26,
308,
14,
305,
63,
6324,
59,
16,
467,
4673,
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
] |
[
32212,
492,
6912,
199,
199,
504,
373,
397,
529,
14,
4653,
14,
4653,
63,
705,
492,
18288,
547,
199,
504,
373,
397,
529,
14,
4653,
14,
2219,
14,
396,
63,
4653,
492,
18288,
2925,
199,
504,
373,
397,
529,
14,
4653,
14,
521,
63,
3127,
492,
4703,
11220,
199,
504,
373,
397,
529,
14,
4653,
14,
10024,
63,
493,
63,
4653,
492,
644,
811,
1173,
11274,
199,
504,
373,
397,
529,
14,
2219,
14,
396,
63,
2546,
492,
7640,
199,
646,
373,
397,
529,
14,
4653,
14,
2219,
14,
1208,
465,
3778,
199,
646,
373,
397,
529,
14,
2219,
14,
396,
63,
1208,
465,
511,
63,
1208,
421,
199,
63,
3998,
63,
3022,
63,
3243,
275,
6912,
8,
396,
63,
1208,
14,
362,
63,
396,
63,
576,
63,
694,
63,
515,
3460,
493,
8964,
421,
199,
533,
644,
811,
1173,
11274,
2925,
8,
1746,
304,
2378,
347,
511,
63,
826,
8,
277,
304,
2728,
5560,
275,
359,
288,
661,
2567,
5972,
14,
19118,
297,
378,
12,
413,
12,
5504,
1493,
12,
2650,
73,
18,
659,
288,
661,
4395,
17270,
14,
19118,
297,
1616,
12,
413,
12,
25647,
1400,
12,
2650,
73,
18,
659,
288,
661,
11467,
17270,
83,
14,
19118,
297,
1616,
12,
499,
12,
5504,
1493,
12,
2650,
73,
18,
358,
267,
1622,
2728,
367,
570,
63,
354,
12,
2787,
63,
835,
12,
3623,
63,
835,
12,
2787,
63,
1866,
12,
2152,
315,
5560,
26,
7846,
570,
63,
515,
275,
485,
3998,
63,
3022,
63,
3243,
1182,
570,
63,
354,
288,
900,
63,
3127,
275,
4703,
11220,
8,
1943,
63,
835,
12,
2787,
63,
1866,
9,
288,
2215,
275,
334,
2775,
63,
835,
12,
2787,
63,
835,
9,
288,
5845,
275,
3778,
14,
981,
63,
3356,
8,
1392,
12,
2152,
15829,
73,
18,
358,
7846,
4673,
275,
644,
811,
1173,
11274,
8,
493,
63,
515,
12,
536,
29,
493,
63,
354,
9,
288,
18288,
2925,
14,
479,
63,
4653,
8,
355,
4673,
12,
570,
63,
354,
12,
900,
63,
3127,
12,
3623,
63,
835,
12,
11969,
2152,
12,
355,
5845,
9,
7846,
4673,
275,
644,
811,
1173,
11274,
8,
493,
63,
515,
9,
288,
18288,
2925,
14,
479,
63,
4653,
8,
355,
4673,
12,
283,
11274,
297,
900,
63,
3127,
12,
3623,
63,
835,
12,
11969,
2152,
12,
5845,
9,
2378,
347,
511,
63,
1667,
63,
493,
8,
277,
304,
267,
570,
63,
515,
275,
485,
3998,
63,
3022,
63,
3243,
1182,
283,
4699,
14,
19118,
7,
267,
291,
423,
479,
63,
3536,
8,
1726,
12,
644,
811,
1173,
11274,
12,
570,
63,
515,
9,
268,
5493,
347,
511,
63,
19347,
63,
493,
8,
277,
304,
267,
570,
63,
515,
275,
485,
3998,
63,
3022,
63,
3243,
1182,
283,
20460,
3153,
14,
19118,
7,
267,
4673,
275,
644,
811,
1173,
11274,
8,
493,
63,
515,
9,
267,
900,
63,
3127,
275,
4703,
11220,
8,
709,
12,
25647,
1400,
9,
267,
18288,
2925,
14,
479,
63,
4653,
8,
4653,
12,
283,
11274,
297,
900,
63,
3127,
12,
413,
12,
11969,
2650,
73,
18,
358,
267,
291,
423,
479,
63,
3536,
8,
11274,
547,
12,
2400,
308,
26,
308,
14,
305,
63,
6324,
59,
16,
467,
4673,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kevinkle/semantic
|
app/SuperPhy/models/response.py
|
2
|
4112
|
"""
models.py
"""
#pylint: disable=C0103, W0406
from collections import defaultdict
from flask import Flask, abort, request, jsonify, g, url_for, current_app
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.httpauth import HTTPBasicAuth
from passlib.apps import custom_app_context as pwd_context
from itsdangerous import (TimedJSONWebSignatureSerializer
as Serializer, BadSignature, SignatureExpired)
class Response():
"""
This is a helper for formatting the sparql responses for the user.
"""
@classmethod
def default(cls, results, extra=None):
"""
This is a template. Copy this over to another function if you are
making a different response object.
"""
response = {}
response = results
if extra is not None:
response.update(extra)
return jsonify(response)
@classmethod
def bulk_download(cls, results, extra=None):
"""
"""
response = {}
response['headers'] = results['head']['vars']
response['rows'] = []
bindings = results['results']['bindings']
for binding in bindings:
row = {}
for item in response['headers']:
if binding.has_key(item):
row[item] = binding[item]['value']
else:
row[item] = ""
response['rows'].append(row)
if extra is not None:
response.update(extra)
return jsonify(response)
@classmethod
def shorten(cls, results, extra=None):
"""
This is the default response from sparql. This turns the layered
response into a shorter dictionary object
Example
input:
{'head': {'vars': ['s', 'p', 'o']}, 'results': {'bindings': [{'p': {'value': 'FOOP'}, 's': {'value': 'FOOS'}, 'o': {'value': 'FOOO'}}, {'p': {'value': 'FOOP2'}, 's': {'value': 'FOOS2'}, 'o': {'value': 'FOOO2'}}]}}
output:
{'vars': ['s', 'p', 'o'], 'results': [{'p': 'FOOP', 's': 'FOOS', 'o': 'FOOO'}, {'p': 'FOOP2', 's': 'FOOS2', 'o': 'FOOO2'}]}
"""
response = {}
response['vars'] = results.get('head').get('vars')
bindings = results['results']['bindings']
response['rows'] = []
for key in bindings:
row = {}
for item in response['vars']:
row[item] = key[item]['value']
response['rows'].append(row)
if extra is not None:
response.update(extra)
return jsonify(response)
@classmethod
def format_gene_search(cls, results, genomeDict, extra=None):
"""
Formats the response from the gene search query for the front-end in the form of a dictionary:
{genome1: {gene1: count, gene2: count}, genome2: {gene1: count...} ...}
Extra arguments:
genomeDict: a preformed dictionary based on selected genes and genomes.
"""
response = {}
response = results
bindings = results['results']['bindings']
for binding in bindings:
accession = binding['Genome']['value'].split("#")[1]
gene_name = binding['Gene_Name']['value']
try:
genomeDict[accession][gene_name] += 1
except KeyError:
"Genome or gene doesn't exist in dictionary"
if extra is not None:
response.update(extra)
return jsonify(genomeDict)
@classmethod
def format_categories(cls, results, extra=None):
"""
Formats the response for categories to use for the front-end.
"""
response = {}
response = results
categoryDict = defaultdict(list)
bindings = results['results']['bindings']
for binding in bindings:
category = binding["Category"]['value']
subcategory = binding["Subcategory"]['value']
if subcategory not in categoryDict[category]:
categoryDict[category].append(subcategory)
return jsonify(categoryDict)
|
apache-2.0
|
[
624,
199,
992,
14,
647,
199,
624,
199,
3,
26324,
26,
3507,
29,
35,
28399,
12,
644,
966,
1690,
199,
199,
504,
5055,
492,
10018,
199,
504,
7209,
492,
16704,
12,
12004,
12,
1056,
12,
23819,
12,
486,
12,
1166,
63,
509,
12,
1453,
63,
571,
199,
504,
7209,
14,
832,
14,
14536,
492,
14303,
199,
504,
7209,
14,
832,
14,
16916,
387,
762,
492,
3101,
6845,
2817,
199,
504,
986,
773,
14,
5181,
492,
3537,
63,
571,
63,
1100,
465,
14374,
63,
1100,
199,
504,
2399,
31444,
492,
334,
28682,
6243,
5926,
10014,
7299,
2079,
465,
25555,
12,
8857,
10014,
12,
18603,
20898,
9,
199,
199,
533,
7232,
837,
272,
408,
272,
961,
365,
282,
5922,
367,
10803,
314,
28668,
1710,
9320,
367,
314,
922,
14,
339,
408,
272,
768,
3744,
272,
347,
849,
8,
1886,
12,
2058,
12,
2402,
29,
403,
304,
267,
408,
267,
961,
365,
282,
1978,
14,
11247,
642,
1806,
370,
4573,
805,
340,
1265,
787,
267,
10663,
282,
3365,
1177,
909,
14,
267,
408,
267,
1177,
275,
1052,
398,
1177,
275,
2058,
398,
340,
2402,
365,
440,
488,
26,
288,
1177,
14,
873,
8,
2911,
9,
267,
372,
23819,
8,
1310,
9,
339,
768,
3744,
272,
347,
13137,
63,
4249,
8,
1886,
12,
2058,
12,
2402,
29,
403,
304,
267,
408,
267,
408,
267,
1177,
275,
1052,
267,
1177,
459,
2139,
418,
275,
2058,
459,
2993,
2545,
2936,
418,
267,
1177,
459,
3838,
418,
275,
942,
267,
17792,
275,
2058,
459,
2604,
2545,
10880,
418,
267,
367,
11696,
315,
17792,
26,
288,
1962,
275,
1052,
288,
367,
1242,
315,
1177,
459,
2139,
2565,
355,
340,
11696,
14,
1989,
63,
498,
8,
1053,
304,
490,
1962,
59,
1053,
61,
275,
11696,
59,
1053,
2733,
585,
418,
355,
587,
26,
490,
1962,
59,
1053,
61,
275,
3087,
288,
1177,
459,
3838,
2278,
740,
8,
1143,
9,
398,
340,
2402,
365,
440,
488,
26,
288,
1177,
14,
873,
8,
2911,
9,
267,
372,
23819,
8,
1310,
9,
339,
768,
3744,
272,
347,
25123,
8,
1886,
12,
2058,
12,
2402,
29,
403,
304,
267,
408,
267,
961,
365,
314,
849,
1177,
687,
28668,
1710,
14,
961,
25449,
314,
27305,
16179,
267,
1177,
1901,
282,
18299,
2600,
909,
267,
5679,
398,
1324,
26,
288,
791,
2993,
356,
791,
2936,
356,
788,
83,
297,
283,
80,
297,
283,
79,
14949,
283,
2604,
356,
791,
10880,
356,
9016,
80,
356,
791,
585,
356,
283,
3230,
1938,
2267,
283,
83,
356,
791,
585,
356,
283,
3230,
3100,
2267,
283,
79,
356,
791,
585,
356,
283,
3230,
5757,
28400,
791,
80,
356,
791,
585,
356,
283,
3230,
1938,
18,
2267,
283,
83,
356,
791,
585,
356,
283,
3230,
3100,
18,
2267,
283,
79,
356,
791,
585,
356,
283,
3230,
5757,
18,
936,
11049,
4863,
267,
1072,
26,
267,
791,
2936,
356,
788,
83,
297,
283,
80,
297,
283,
79,
995,
283,
2604,
356,
9016,
80,
356,
283,
3230,
1938,
297,
283,
83,
356,
283,
3230,
3100,
297,
283,
79,
356,
283,
3230,
5757,
2267,
791,
80,
356,
283,
3230,
1938,
18,
297,
283,
83,
356,
283,
3230,
3100,
18,
297,
283,
79,
356,
283,
3230,
5757,
18,
936,
9420,
267,
408,
267,
1177,
275,
1052,
398,
1177,
459,
2936,
418,
275,
2058,
14,
362,
360,
2993,
1959,
362,
360,
2936,
358,
267,
17792,
275,
2058,
459,
2604,
2545,
10880,
418,
267,
1177,
459,
3838,
418,
275,
942,
267,
367,
790,
315,
17792,
26,
288,
1962,
275,
1052,
288,
367,
1242,
315,
1177,
459,
2936,
2565,
355,
1962,
59,
1053,
61,
275,
790,
59,
1053,
2733,
585,
418,
288,
1177,
459,
3838,
2278,
740,
8,
1143,
9,
398,
340,
2402,
365,
440,
488,
26,
288,
1177,
14,
873,
8,
2911,
9,
267,
372,
23819,
8,
1310,
9,
339,
768,
3744,
272,
347,
1475,
63,
10654,
63,
1733,
8,
1886,
12,
2058,
12,
29924,
2141,
12,
2402,
29,
403,
304,
267,
408,
267,
9701,
83,
314,
1177,
687,
314,
15599,
2754,
1827,
367,
314,
13738,
13,
500,
315,
314,
1824,
402,
282,
2600,
26,
267,
469,
27776,
17,
26,
469,
10654,
17,
26,
2338,
12,
15599,
18,
26,
2338,
1386,
29924,
18,
26,
469,
10654,
17,
26,
2338,
1396,
93,
2263,
93,
398,
11177,
2368,
26,
288,
29924,
2141,
26,
282,
876,
6194,
2600,
4079,
641,
4895,
3805,
397,
436,
29924,
83,
14,
267,
408,
267,
1177,
275,
1052,
267,
1177,
275,
2058,
398,
17792,
275,
2058,
459,
2604,
2545,
10880,
418,
267,
367,
11696,
315,
17792,
26,
288,
1066,
823,
438,
275,
11696,
459,
8168,
1377,
2545,
585,
2278,
1294,
10064,
9981,
17,
61,
288,
15599,
63,
354,
275,
11696,
459,
39,
6349,
63,
985,
2545,
585,
418,
288,
862,
26,
355,
29924,
2141,
59,
645,
823,
438,
1527,
10654,
63,
354,
61,
847,
413,
288,
871,
4067,
26,
355,
298,
8168,
1377,
503,
15599,
3181,
1133,
2187,
315,
2600,
2,
398,
340,
2402,
365,
440,
488,
26,
288,
1177,
14,
873,
8,
2911,
9,
398,
372,
23819,
8,
27776,
2141,
9,
339,
768,
3744,
272,
347,
1475,
63,
8906,
8,
1886,
12,
2058,
12,
2402,
29,
403,
304,
267,
408,
267,
9701,
83,
314,
1177,
367,
9695,
370,
675,
367,
314,
13738,
13,
500,
14,
267,
408,
267,
1177,
275,
1052,
267,
1177,
275,
2058,
398,
4637,
2141,
275,
10018,
8,
513,
9,
398,
17792,
275,
2058,
459,
2604,
2545,
10880,
418,
267,
367,
11696,
315,
17792,
26,
288,
4637,
275,
11696,
905,
7841,
937,
459,
585,
418,
288,
1007,
3710,
275,
11696,
905,
2610,
3710,
937,
459,
585,
418,
288,
340,
1007,
3710,
440,
315,
4637,
2141,
59,
3710,
2189,
355,
4637,
2141,
59,
3710,
1055,
740,
8,
954,
3710,
9,
4960,
372,
23819,
8,
3710,
2141,
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
] |
[
199,
992,
14,
647,
199,
624,
199,
3,
26324,
26,
3507,
29,
35,
28399,
12,
644,
966,
1690,
199,
199,
504,
5055,
492,
10018,
199,
504,
7209,
492,
16704,
12,
12004,
12,
1056,
12,
23819,
12,
486,
12,
1166,
63,
509,
12,
1453,
63,
571,
199,
504,
7209,
14,
832,
14,
14536,
492,
14303,
199,
504,
7209,
14,
832,
14,
16916,
387,
762,
492,
3101,
6845,
2817,
199,
504,
986,
773,
14,
5181,
492,
3537,
63,
571,
63,
1100,
465,
14374,
63,
1100,
199,
504,
2399,
31444,
492,
334,
28682,
6243,
5926,
10014,
7299,
2079,
465,
25555,
12,
8857,
10014,
12,
18603,
20898,
9,
199,
199,
533,
7232,
837,
272,
408,
272,
961,
365,
282,
5922,
367,
10803,
314,
28668,
1710,
9320,
367,
314,
922,
14,
339,
408,
272,
768,
3744,
272,
347,
849,
8,
1886,
12,
2058,
12,
2402,
29,
403,
304,
267,
408,
267,
961,
365,
282,
1978,
14,
11247,
642,
1806,
370,
4573,
805,
340,
1265,
787,
267,
10663,
282,
3365,
1177,
909,
14,
267,
408,
267,
1177,
275,
1052,
398,
1177,
275,
2058,
398,
340,
2402,
365,
440,
488,
26,
288,
1177,
14,
873,
8,
2911,
9,
267,
372,
23819,
8,
1310,
9,
339,
768,
3744,
272,
347,
13137,
63,
4249,
8,
1886,
12,
2058,
12,
2402,
29,
403,
304,
267,
408,
267,
408,
267,
1177,
275,
1052,
267,
1177,
459,
2139,
418,
275,
2058,
459,
2993,
2545,
2936,
418,
267,
1177,
459,
3838,
418,
275,
942,
267,
17792,
275,
2058,
459,
2604,
2545,
10880,
418,
267,
367,
11696,
315,
17792,
26,
288,
1962,
275,
1052,
288,
367,
1242,
315,
1177,
459,
2139,
2565,
355,
340,
11696,
14,
1989,
63,
498,
8,
1053,
304,
490,
1962,
59,
1053,
61,
275,
11696,
59,
1053,
2733,
585,
418,
355,
587,
26,
490,
1962,
59,
1053,
61,
275,
3087,
288,
1177,
459,
3838,
2278,
740,
8,
1143,
9,
398,
340,
2402,
365,
440,
488,
26,
288,
1177,
14,
873,
8,
2911,
9,
267,
372,
23819,
8,
1310,
9,
339,
768,
3744,
272,
347,
25123,
8,
1886,
12,
2058,
12,
2402,
29,
403,
304,
267,
408,
267,
961,
365,
314,
849,
1177,
687,
28668,
1710,
14,
961,
25449,
314,
27305,
16179,
267,
1177,
1901,
282,
18299,
2600,
909,
267,
5679,
398,
1324,
26,
288,
791,
2993,
356,
791,
2936,
356,
788,
83,
297,
283,
80,
297,
283,
79,
14949,
283,
2604,
356,
791,
10880,
356,
9016,
80,
356,
791,
585,
356,
283,
3230,
1938,
2267,
283,
83,
356,
791,
585,
356,
283,
3230,
3100,
2267,
283,
79,
356,
791,
585,
356,
283,
3230,
5757,
28400,
791,
80,
356,
791,
585,
356,
283,
3230,
1938,
18,
2267,
283,
83,
356,
791,
585,
356,
283,
3230,
3100,
18,
2267,
283,
79,
356,
791,
585,
356,
283,
3230,
5757,
18,
936,
11049,
4863,
267,
1072,
26,
267,
791,
2936,
356,
788,
83,
297,
283,
80,
297,
283,
79,
995,
283,
2604,
356,
9016,
80,
356,
283,
3230,
1938,
297,
283,
83,
356,
283,
3230,
3100,
297,
283,
79,
356,
283,
3230,
5757,
2267,
791,
80,
356,
283,
3230,
1938,
18,
297,
283,
83,
356,
283,
3230,
3100,
18,
297,
283,
79,
356,
283,
3230,
5757,
18,
936,
9420,
267,
408,
267,
1177,
275,
1052,
398,
1177,
459,
2936,
418,
275,
2058,
14,
362,
360,
2993,
1959,
362,
360,
2936,
358,
267,
17792,
275,
2058,
459,
2604,
2545,
10880,
418,
267,
1177,
459,
3838,
418,
275,
942,
267,
367,
790,
315,
17792,
26,
288,
1962,
275,
1052,
288,
367,
1242,
315,
1177,
459,
2936,
2565,
355,
1962,
59,
1053,
61,
275,
790,
59,
1053,
2733,
585,
418,
288,
1177,
459,
3838,
2278,
740,
8,
1143,
9,
398,
340,
2402,
365,
440,
488,
26,
288,
1177,
14,
873,
8,
2911,
9,
267,
372,
23819,
8,
1310,
9,
339,
768,
3744,
272,
347,
1475,
63,
10654,
63,
1733,
8,
1886,
12,
2058,
12,
29924,
2141,
12,
2402,
29,
403,
304,
267,
408,
267,
9701,
83,
314,
1177,
687,
314,
15599,
2754,
1827,
367,
314,
13738,
13,
500,
315,
314,
1824,
402,
282,
2600,
26,
267,
469,
27776,
17,
26,
469,
10654,
17,
26,
2338,
12,
15599,
18,
26,
2338,
1386,
29924,
18,
26,
469,
10654,
17,
26,
2338,
1396,
93,
2263,
93,
398,
11177,
2368,
26,
288,
29924,
2141,
26,
282,
876,
6194,
2600,
4079,
641,
4895,
3805,
397,
436,
29924,
83,
14,
267,
408,
267,
1177,
275,
1052,
267,
1177,
275,
2058,
398,
17792,
275,
2058,
459,
2604,
2545,
10880,
418,
267,
367,
11696,
315,
17792,
26,
288,
1066,
823,
438,
275,
11696,
459,
8168,
1377,
2545,
585,
2278,
1294,
10064,
9981,
17,
61,
288,
15599,
63,
354,
275,
11696,
459,
39,
6349,
63,
985,
2545,
585,
418,
288,
862,
26,
355,
29924,
2141,
59,
645,
823,
438,
1527,
10654,
63,
354,
61,
847,
413,
288,
871,
4067,
26,
355,
298,
8168,
1377,
503,
15599,
3181,
1133,
2187,
315,
2600,
2,
398,
340,
2402,
365,
440,
488,
26,
288,
1177,
14,
873,
8,
2911,
9,
398,
372,
23819,
8,
27776,
2141,
9,
339,
768,
3744,
272,
347,
1475,
63,
8906,
8,
1886,
12,
2058,
12,
2402,
29,
403,
304,
267,
408,
267,
9701,
83,
314,
1177,
367,
9695,
370,
675,
367,
314,
13738,
13,
500,
14,
267,
408,
267,
1177,
275,
1052,
267,
1177,
275,
2058,
398,
4637,
2141,
275,
10018,
8,
513,
9,
398,
17792,
275,
2058,
459,
2604,
2545,
10880,
418,
267,
367,
11696,
315,
17792,
26,
288,
4637,
275,
11696,
905,
7841,
937,
459,
585,
418,
288,
1007,
3710,
275,
11696,
905,
2610,
3710,
937,
459,
585,
418,
288,
340,
1007,
3710,
440,
315,
4637,
2141,
59,
3710,
2189,
355,
4637,
2141,
59,
3710,
1055,
740,
8,
954,
3710,
9,
4960,
372,
23819,
8,
3710,
2141,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
BallCity/PokemonGo-Map
|
pogom/models.py
|
2
|
12947
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
import logging
import os
import time
from peewee import Model, SqliteDatabase, InsertQuery,\
IntegerField, CharField, DoubleField, BooleanField,\
DateTimeField, OperationalError, create_model_tables
from playhouse.flask_utils import FlaskDB
from playhouse.pool import PooledMySQLDatabase
from playhouse.shortcuts import RetryOperationalError
from datetime import datetime, timedelta
from base64 import b64encode
from . import config
from .utils import get_pokemon_name, get_pokemon_rarity, get_pokemon_types, get_args, send_to_webhook
from .transform import transform_from_wgs_to_gcj
from .customLog import printPokemon
log = logging.getLogger(__name__)
args = get_args()
flaskDb = FlaskDB()
class MyRetryDB(RetryOperationalError, PooledMySQLDatabase):
pass
def init_database(app):
if args.db_type == 'mysql':
db = MyRetryDB(
args.db_name,
user=args.db_user,
password=args.db_pass,
host=args.db_host,
max_connections=args.db_max_connections,
stale_timeout=300)
log.info('Connecting to MySQL database on {}.'.format(args.db_host))
else:
db = SqliteDatabase(args.db)
log.info('Connecting to local SQLLite database.')
app.config['DATABASE'] = db
flaskDb.init_app(app)
return db
class BaseModel(flaskDb.Model):
@classmethod
def get_all(cls):
results = [m for m in cls.select().dicts()]
if args.china:
for result in results:
result['latitude'], result['longitude'] = \
transform_from_wgs_to_gcj(
result['latitude'], result['longitude'])
return results
class Pokemon(BaseModel):
# We are base64 encoding the ids delivered by the api
# because they are too big for sqlite to handle
encounter_id = CharField(primary_key=True, max_length=50)
spawnpoint_id = CharField(index=True)
pokemon_id = IntegerField(index=True)
latitude = DoubleField()
longitude = DoubleField()
disappear_time = DateTimeField(index=True)
class Meta:
indexes = ((('latitude', 'longitude'), False),)
@classmethod
def get_active(cls, swLat, swLng, neLat, neLng):
if swLat is None or swLng is None or neLat is None or neLng is None:
query = (Pokemon
.select()
.where(Pokemon.disappear_time > datetime.utcnow())
.dicts())
else:
query = (Pokemon
.select()
.where((Pokemon.disappear_time > datetime.utcnow()) &
(Pokemon.latitude >= swLat) &
(Pokemon.longitude >= swLng) &
(Pokemon.latitude <= neLat) &
(Pokemon.longitude <= neLng))
.dicts())
pokemons = []
for p in query:
p['pokemon_name'] = get_pokemon_name(p['pokemon_id'])
p['pokemon_rarity'] = get_pokemon_rarity(p['pokemon_id'])
p['pokemon_types'] = get_pokemon_types(p['pokemon_id'])
if args.china:
p['latitude'], p['longitude'] = \
transform_from_wgs_to_gcj(p['latitude'], p['longitude'])
pokemons.append(p)
return pokemons
@classmethod
def get_active_by_id(cls, ids, swLat, swLng, neLat, neLng):
if swLat is None or swLng is None or neLat is None or neLng is None:
query = (Pokemon
.select()
.where((Pokemon.pokemon_id << ids) &
(Pokemon.disappear_time > datetime.utcnow()))
.dicts())
else:
query = (Pokemon
.select()
.where((Pokemon.pokemon_id << ids) &
(Pokemon.disappear_time > datetime.utcnow()) &
(Pokemon.latitude >= swLat) &
(Pokemon.longitude >= swLng) &
(Pokemon.latitude <= neLat) &
(Pokemon.longitude <= neLng))
.dicts())
pokemons = []
for p in query:
p['pokemon_name'] = get_pokemon_name(p['pokemon_id'])
p['pokemon_rarity'] = get_pokemon_rarity(p['pokemon_id'])
p['pokemon_types'] = get_pokemon_types(p['pokemon_id'])
if args.china:
p['latitude'], p['longitude'] = \
transform_from_wgs_to_gcj(p['latitude'], p['longitude'])
pokemons.append(p)
return pokemons
class Pokestop(BaseModel):
pokestop_id = CharField(primary_key=True, max_length=50)
enabled = BooleanField()
latitude = DoubleField()
longitude = DoubleField()
last_modified = DateTimeField(index=True)
lure_expiration = DateTimeField(null=True, index=True)
active_pokemon_id = IntegerField(null=True)
class Meta:
indexes = ((('latitude', 'longitude'), False),)
@classmethod
def get_stops(cls, swLat, swLng, neLat, neLng):
if swLat is None or swLng is None or neLat is None or neLng is None:
query = (Pokestop
.select()
.dicts())
else:
query = (Pokestop
.select()
.where((Pokestop.latitude >= swLat) &
(Pokestop.longitude >= swLng) &
(Pokestop.latitude <= neLat) &
(Pokestop.longitude <= neLng))
.dicts())
pokestops = []
for p in query:
if args.china:
p['latitude'], p['longitude'] = \
transform_from_wgs_to_gcj(p['latitude'], p['longitude'])
pokestops.append(p)
return pokestops
class Gym(BaseModel):
UNCONTESTED = 0
TEAM_MYSTIC = 1
TEAM_VALOR = 2
TEAM_INSTINCT = 3
gym_id = CharField(primary_key=True, max_length=50)
team_id = IntegerField()
guard_pokemon_id = IntegerField()
gym_points = IntegerField()
enabled = BooleanField()
latitude = DoubleField()
longitude = DoubleField()
last_modified = DateTimeField(index=True)
class Meta:
indexes = ((('latitude', 'longitude'), False),)
@classmethod
def get_gyms(cls, swLat, swLng, neLat, neLng):
if swLat is None or swLng is None or neLat is None or neLng is None:
query = (Gym
.select()
.dicts())
else:
query = (Gym
.select()
.where((Gym.latitude >= swLat) &
(Gym.longitude >= swLng) &
(Gym.latitude <= neLat) &
(Gym.longitude <= neLng))
.dicts())
gyms = []
for g in query:
gyms.append(g)
return gyms
class ScannedLocation(BaseModel):
scanned_id = CharField(primary_key=True, max_length=50)
latitude = DoubleField()
longitude = DoubleField()
last_modified = DateTimeField(index=True)
class Meta:
indexes = ((('latitude', 'longitude'), False),)
@classmethod
def get_recent(cls, swLat, swLng, neLat, neLng):
query = (ScannedLocation
.select()
.where((ScannedLocation.last_modified >=
(datetime.utcnow() - timedelta(minutes=15))) &
(ScannedLocation.latitude >= swLat) &
(ScannedLocation.longitude >= swLng) &
(ScannedLocation.latitude <= neLat) &
(ScannedLocation.longitude <= neLng))
.dicts())
scans = []
for s in query:
scans.append(s)
return scans
def parse_map(map_dict, iteration_num, step, step_location):
pokemons = {}
pokestops = {}
gyms = {}
scanned = {}
cells = map_dict['responses']['GET_MAP_OBJECTS']['map_cells']
for cell in cells:
if config['parse_pokemon']:
for p in cell.get('wild_pokemons', []):
d_t = datetime.utcfromtimestamp(
(p['last_modified_timestamp_ms'] +
p['time_till_hidden_ms']) / 1000.0)
printPokemon(p['pokemon_data']['pokemon_id'], p['latitude'],
p['longitude'], d_t)
pokemons[p['encounter_id']] = {
'encounter_id': b64encode(str(p['encounter_id'])),
'spawnpoint_id': p['spawnpoint_id'],
'pokemon_id': p['pokemon_data']['pokemon_id'],
'latitude': p['latitude'],
'longitude': p['longitude'],
'disappear_time': d_t
}
webhook_data = {
'encounter_id': b64encode(str(p['encounter_id'])),
'spawnpoint_id': p['spawnpoint_id'],
'pokemon_id': p['pokemon_data']['pokemon_id'],
'latitude': p['latitude'],
'longitude': p['longitude'],
'disappear_time': time.mktime(d_t.timetuple())
}
send_to_webhook('pokemon', webhook_data)
for f in cell.get('forts', []):
if config['parse_pokestops'] and f.get('type') == 1: # Pokestops
if 'lure_info' in f:
lure_expiration = datetime.utcfromtimestamp(
f['lure_info']['lure_expires_timestamp_ms'] / 1000.0)
active_pokemon_id = f['lure_info']['active_pokemon_id']
else:
lure_expiration, active_pokemon_id = None, None
pokestops[f['id']] = {
'pokestop_id': f['id'],
'enabled': f['enabled'],
'latitude': f['latitude'],
'longitude': f['longitude'],
'last_modified': datetime.utcfromtimestamp(
f['last_modified_timestamp_ms'] / 1000.0),
'lure_expiration': lure_expiration,
'active_pokemon_id': active_pokemon_id
}
elif config['parse_gyms'] and f.get('type') is None: # Currently, there are only stops and gyms
gyms[f['id']] = {
'gym_id': f['id'],
'team_id': f.get('owned_by_team', 0),
'guard_pokemon_id': f.get('guard_pokemon_id', 0),
'gym_points': f.get('gym_points', 0),
'enabled': f['enabled'],
'latitude': f['latitude'],
'longitude': f['longitude'],
'last_modified': datetime.utcfromtimestamp(
f['last_modified_timestamp_ms'] / 1000.0),
}
pokemons_upserted = 0
pokestops_upserted = 0
gyms_upserted = 0
if pokemons and config['parse_pokemon']:
pokemons_upserted = len(pokemons)
log.debug("Upserting {} pokemon".format(len(pokemons)))
bulk_upsert(Pokemon, pokemons)
if pokestops and config['parse_pokestops']:
pokestops_upserted = len(pokestops)
log.debug("Upserting {} pokestops".format(len(pokestops)))
bulk_upsert(Pokestop, pokestops)
if gyms and config['parse_gyms']:
gyms_upserted = len(gyms)
log.debug("Upserting {} gyms".format(len(gyms)))
bulk_upsert(Gym, gyms)
log.info("Upserted {} pokemon, {} pokestops, and {} gyms".format(
pokemons_upserted,
pokestops_upserted,
gyms_upserted))
scanned[0] = {
'scanned_id': str(step_location[0])+','+str(step_location[1]),
'latitude': step_location[0],
'longitude': step_location[1],
'last_modified': datetime.utcnow(),
}
bulk_upsert(ScannedLocation, scanned)
def bulk_upsert(cls, data):
num_rows = len(data.values())
i = 0
step = 120
flaskDb.connect_db()
while i < num_rows:
log.debug("Inserting items {} to {}".format(i, min(i+step, num_rows)))
try:
InsertQuery(cls, rows=data.values()[i:min(i+step, num_rows)]).upsert().execute()
except OperationalError as e:
log.warning("%s... Retrying", e)
continue
i+=step
flaskDb.close_db(None)
def create_tables(db):
db.connect()
db.create_tables([Pokemon, Pokestop, Gym, ScannedLocation], safe=True)
db.close()
def drop_tables(db):
db.connect()
db.drop_tables([Pokemon, Pokestop, Gym, ScannedLocation], safe=True)
db.close()
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
900,
199,
504,
4837,
546,
1024,
492,
5822,
12,
428,
29498,
7243,
12,
15496,
3227,
4202,
673,
26141,
12,
12064,
12,
22945,
792,
12,
9411,
792,
4202,
673,
31637,
12,
6654,
6279,
547,
12,
1218,
63,
1238,
63,
5987,
199,
504,
5232,
6740,
14,
15720,
63,
1208,
492,
16704,
2846,
199,
504,
5232,
6740,
14,
2293,
492,
510,
1534,
1146,
20784,
7243,
199,
504,
5232,
6740,
14,
17469,
492,
20506,
31998,
547,
199,
504,
2197,
492,
2197,
12,
6871,
199,
504,
1300,
772,
492,
330,
772,
2143,
199,
199,
504,
1275,
492,
1101,
199,
504,
1275,
1208,
492,
664,
63,
28331,
63,
354,
12,
664,
63,
28331,
63,
82,
7945,
12,
664,
63,
28331,
63,
1313,
12,
664,
63,
589,
12,
3222,
63,
475,
63,
22944,
199,
504,
1275,
4711,
492,
5793,
63,
504,
63,
87,
458,
63,
475,
63,
9493,
74,
199,
504,
1275,
4229,
2445,
492,
870,
1575,
17180,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
589,
275,
664,
63,
589,
342,
199,
15720,
8882,
275,
16704,
2846,
342,
421,
199,
533,
4932,
12989,
2846,
8,
12989,
31998,
547,
12,
510,
1534,
1146,
20784,
7243,
304,
272,
986,
421,
199,
318,
4205,
63,
4659,
8,
571,
304,
272,
340,
1249,
14,
697,
63,
466,
508,
283,
8644,
356,
267,
1592,
275,
4932,
12989,
2846,
8,
288,
1249,
14,
697,
63,
354,
12,
288,
922,
29,
589,
14,
697,
63,
751,
12,
288,
2505,
29,
589,
14,
697,
63,
1529,
12,
288,
1591,
29,
589,
14,
697,
63,
1102,
12,
288,
1390,
63,
7995,
29,
589,
14,
697,
63,
988,
63,
7995,
12,
288,
20149,
63,
2593,
29,
5863,
9,
267,
943,
14,
815,
360,
32000,
370,
11200,
3050,
641,
1052,
17374,
908,
8,
589,
14,
697,
63,
1102,
430,
272,
587,
26,
267,
1592,
275,
428,
29498,
7243,
8,
589,
14,
697,
9,
267,
943,
14,
815,
360,
32000,
370,
2257,
5385,
19375,
3050,
2659,
339,
1145,
14,
888,
459,
17873,
418,
275,
1592,
272,
7209,
8882,
14,
826,
63,
571,
8,
571,
9,
339,
372,
1592,
421,
199,
533,
3523,
1685,
8,
15720,
8882,
14,
1685,
304,
339,
768,
3744,
272,
347,
664,
63,
452,
8,
1886,
304,
267,
2058,
275,
359,
77,
367,
333,
315,
843,
14,
2416,
1252,
7892,
5106,
267,
340,
1249,
14,
335,
13765,
26,
288,
367,
754,
315,
2058,
26,
355,
754,
459,
13331,
995,
754,
459,
13803,
418,
275,
971,
490,
5793,
63,
504,
63,
87,
458,
63,
475,
63,
9493,
74,
8,
717,
754,
459,
13331,
995,
754,
459,
13803,
1105,
267,
372,
2058,
421,
199,
533,
4376,
17180,
8,
27687,
304,
272,
327,
2136,
787,
1300,
772,
2644,
314,
2762,
28218,
701,
314,
2986,
272,
327,
2952,
2985,
787,
4634,
7282,
367,
11723,
370,
2429,
272,
655,
5337,
63,
344,
275,
12064,
8,
3327,
63,
498,
29,
549,
12,
1390,
63,
1267,
29,
1400,
9,
272,
15187,
1403,
63,
344,
275,
12064,
8,
1080,
29,
549,
9,
272,
1115,
17180,
63,
344,
275,
26141,
8,
1080,
29,
549,
9,
272,
18896,
275,
22945,
792,
342,
272,
18154,
275,
22945,
792,
342,
272,
2153,
27307,
63,
521,
275,
31637,
8,
1080,
29,
549,
9,
339,
1021,
6288,
26,
267,
10507,
275,
3666,
360,
13331,
297,
283,
13803,
659,
756,
16945,
339,
768,
3744,
272,
347,
664,
63,
2682,
8,
1886,
12,
5584,
22510,
12,
5584,
44,
2753,
12,
1279,
22510,
12,
1279,
44,
2753,
304,
267,
340,
5584,
22510,
365,
488,
503,
5584,
44,
2753,
365,
488,
503,
1279,
22510,
365,
488,
503,
1279,
44,
2753,
365,
488,
26,
288,
1827,
275,
334,
1575,
17180,
2151,
1275,
2416,
342,
2151,
1275,
4509,
8,
1575,
17180,
14,
2297,
27307,
63,
521,
690,
2197,
14,
10779,
1012,
2151,
1275,
7892,
1012,
267,
587,
26,
288,
1827,
275,
334,
1575,
17180,
2151,
1275,
2416,
342,
2151,
1275,
4509,
1332,
1575,
17180,
14,
2297,
27307,
63,
521,
690,
2197,
14,
10779,
1012,
1253,
1169,
334,
1575,
17180,
14,
13331,
2356,
5584,
22510,
9,
1253,
1169,
334,
1575,
17180,
14,
13803,
2356,
5584,
44,
2753,
9,
1253,
1169,
334,
1575,
17180,
14,
13331,
2695,
1279,
22510,
9,
1253,
1169,
334,
1575,
17180,
14,
13803,
2695,
1279,
44,
2753,
430,
2151,
1275,
7892,
1012,
398,
1115,
17180,
83,
275,
942,
267,
367,
299,
315,
1827,
26,
288,
299,
459,
28331,
63,
354,
418,
275,
664,
63,
28331,
63,
354,
8,
80,
459,
28331,
63,
344,
1105,
288,
299,
459,
28331,
63,
82,
7945,
418,
275,
664,
63,
28331,
63,
82,
7945,
8,
80,
459,
28331,
63,
344,
1105,
288,
299,
459,
28331,
63,
1313,
418,
275,
664,
63,
28331,
63,
1313,
8,
80,
459,
28331,
63,
344,
1105,
288,
340,
1249,
14,
335,
13765,
26,
355,
299,
459,
13331,
995,
299,
459,
13803,
418,
275,
971,
490,
5793,
63,
504,
63,
87,
458,
63,
475,
63,
9493,
74,
8,
80,
459,
13331,
995,
299,
459,
13803,
1105,
288,
1115,
17180,
83,
14,
740,
8,
80,
9,
398,
372,
1115,
17180,
83,
339,
768,
3744,
272,
347,
664,
63,
2682,
63,
991,
63,
344,
8,
1886,
12,
2762,
12,
5584,
22510,
12,
5584,
44,
2753,
12,
1279,
22510,
12,
1279,
44,
2753,
304,
267,
340,
5584,
22510,
365,
488,
503,
5584,
44,
2753,
365,
488,
503,
1279,
22510,
365,
488,
503,
1279,
44,
2753,
365,
488,
26,
288,
1827,
275,
334,
1575,
17180,
2151,
1275,
2416,
342,
2151,
1275,
4509,
1332,
1575,
17180,
14,
28331,
63,
344,
5213,
2762,
9,
1253,
1169,
334,
1575,
17180,
14,
2297,
27307,
63,
521,
690,
2197,
14,
10779,
4059,
2151,
1275,
7892,
1012,
267,
587,
26,
288,
1827,
275,
334,
1575,
17180,
2151,
1275,
2416,
342,
2151,
1275,
4509,
1332,
1575,
17180,
14,
28331,
63,
344,
5213,
2762,
9,
1253,
1169,
334,
1575,
17180,
14,
2297,
27307,
63,
521,
690,
2197,
14,
10779,
1012,
1253,
1169,
334,
1575,
17180,
14,
13331,
2356,
5584,
22510,
9,
1253,
1169,
334,
1575,
17180,
14,
13803,
2356,
5584,
44,
2753,
9,
1253,
1169,
334,
1575,
17180,
14,
13331,
2695,
1279
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
900,
199,
504,
4837,
546,
1024,
492,
5822,
12,
428,
29498,
7243,
12,
15496,
3227,
4202,
673,
26141,
12,
12064,
12,
22945,
792,
12,
9411,
792,
4202,
673,
31637,
12,
6654,
6279,
547,
12,
1218,
63,
1238,
63,
5987,
199,
504,
5232,
6740,
14,
15720,
63,
1208,
492,
16704,
2846,
199,
504,
5232,
6740,
14,
2293,
492,
510,
1534,
1146,
20784,
7243,
199,
504,
5232,
6740,
14,
17469,
492,
20506,
31998,
547,
199,
504,
2197,
492,
2197,
12,
6871,
199,
504,
1300,
772,
492,
330,
772,
2143,
199,
199,
504,
1275,
492,
1101,
199,
504,
1275,
1208,
492,
664,
63,
28331,
63,
354,
12,
664,
63,
28331,
63,
82,
7945,
12,
664,
63,
28331,
63,
1313,
12,
664,
63,
589,
12,
3222,
63,
475,
63,
22944,
199,
504,
1275,
4711,
492,
5793,
63,
504,
63,
87,
458,
63,
475,
63,
9493,
74,
199,
504,
1275,
4229,
2445,
492,
870,
1575,
17180,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
589,
275,
664,
63,
589,
342,
199,
15720,
8882,
275,
16704,
2846,
342,
421,
199,
533,
4932,
12989,
2846,
8,
12989,
31998,
547,
12,
510,
1534,
1146,
20784,
7243,
304,
272,
986,
421,
199,
318,
4205,
63,
4659,
8,
571,
304,
272,
340,
1249,
14,
697,
63,
466,
508,
283,
8644,
356,
267,
1592,
275,
4932,
12989,
2846,
8,
288,
1249,
14,
697,
63,
354,
12,
288,
922,
29,
589,
14,
697,
63,
751,
12,
288,
2505,
29,
589,
14,
697,
63,
1529,
12,
288,
1591,
29,
589,
14,
697,
63,
1102,
12,
288,
1390,
63,
7995,
29,
589,
14,
697,
63,
988,
63,
7995,
12,
288,
20149,
63,
2593,
29,
5863,
9,
267,
943,
14,
815,
360,
32000,
370,
11200,
3050,
641,
1052,
17374,
908,
8,
589,
14,
697,
63,
1102,
430,
272,
587,
26,
267,
1592,
275,
428,
29498,
7243,
8,
589,
14,
697,
9,
267,
943,
14,
815,
360,
32000,
370,
2257,
5385,
19375,
3050,
2659,
339,
1145,
14,
888,
459,
17873,
418,
275,
1592,
272,
7209,
8882,
14,
826,
63,
571,
8,
571,
9,
339,
372,
1592,
421,
199,
533,
3523,
1685,
8,
15720,
8882,
14,
1685,
304,
339,
768,
3744,
272,
347,
664,
63,
452,
8,
1886,
304,
267,
2058,
275,
359,
77,
367,
333,
315,
843,
14,
2416,
1252,
7892,
5106,
267,
340,
1249,
14,
335,
13765,
26,
288,
367,
754,
315,
2058,
26,
355,
754,
459,
13331,
995,
754,
459,
13803,
418,
275,
971,
490,
5793,
63,
504,
63,
87,
458,
63,
475,
63,
9493,
74,
8,
717,
754,
459,
13331,
995,
754,
459,
13803,
1105,
267,
372,
2058,
421,
199,
533,
4376,
17180,
8,
27687,
304,
272,
327,
2136,
787,
1300,
772,
2644,
314,
2762,
28218,
701,
314,
2986,
272,
327,
2952,
2985,
787,
4634,
7282,
367,
11723,
370,
2429,
272,
655,
5337,
63,
344,
275,
12064,
8,
3327,
63,
498,
29,
549,
12,
1390,
63,
1267,
29,
1400,
9,
272,
15187,
1403,
63,
344,
275,
12064,
8,
1080,
29,
549,
9,
272,
1115,
17180,
63,
344,
275,
26141,
8,
1080,
29,
549,
9,
272,
18896,
275,
22945,
792,
342,
272,
18154,
275,
22945,
792,
342,
272,
2153,
27307,
63,
521,
275,
31637,
8,
1080,
29,
549,
9,
339,
1021,
6288,
26,
267,
10507,
275,
3666,
360,
13331,
297,
283,
13803,
659,
756,
16945,
339,
768,
3744,
272,
347,
664,
63,
2682,
8,
1886,
12,
5584,
22510,
12,
5584,
44,
2753,
12,
1279,
22510,
12,
1279,
44,
2753,
304,
267,
340,
5584,
22510,
365,
488,
503,
5584,
44,
2753,
365,
488,
503,
1279,
22510,
365,
488,
503,
1279,
44,
2753,
365,
488,
26,
288,
1827,
275,
334,
1575,
17180,
2151,
1275,
2416,
342,
2151,
1275,
4509,
8,
1575,
17180,
14,
2297,
27307,
63,
521,
690,
2197,
14,
10779,
1012,
2151,
1275,
7892,
1012,
267,
587,
26,
288,
1827,
275,
334,
1575,
17180,
2151,
1275,
2416,
342,
2151,
1275,
4509,
1332,
1575,
17180,
14,
2297,
27307,
63,
521,
690,
2197,
14,
10779,
1012,
1253,
1169,
334,
1575,
17180,
14,
13331,
2356,
5584,
22510,
9,
1253,
1169,
334,
1575,
17180,
14,
13803,
2356,
5584,
44,
2753,
9,
1253,
1169,
334,
1575,
17180,
14,
13331,
2695,
1279,
22510,
9,
1253,
1169,
334,
1575,
17180,
14,
13803,
2695,
1279,
44,
2753,
430,
2151,
1275,
7892,
1012,
398,
1115,
17180,
83,
275,
942,
267,
367,
299,
315,
1827,
26,
288,
299,
459,
28331,
63,
354,
418,
275,
664,
63,
28331,
63,
354,
8,
80,
459,
28331,
63,
344,
1105,
288,
299,
459,
28331,
63,
82,
7945,
418,
275,
664,
63,
28331,
63,
82,
7945,
8,
80,
459,
28331,
63,
344,
1105,
288,
299,
459,
28331,
63,
1313,
418,
275,
664,
63,
28331,
63,
1313,
8,
80,
459,
28331,
63,
344,
1105,
288,
340,
1249,
14,
335,
13765,
26,
355,
299,
459,
13331,
995,
299,
459,
13803,
418,
275,
971,
490,
5793,
63,
504,
63,
87,
458,
63,
475,
63,
9493,
74,
8,
80,
459,
13331,
995,
299,
459,
13803,
1105,
288,
1115,
17180,
83,
14,
740,
8,
80,
9,
398,
372,
1115,
17180,
83,
339,
768,
3744,
272,
347,
664,
63,
2682,
63,
991,
63,
344,
8,
1886,
12,
2762,
12,
5584,
22510,
12,
5584,
44,
2753,
12,
1279,
22510,
12,
1279,
44,
2753,
304,
267,
340,
5584,
22510,
365,
488,
503,
5584,
44,
2753,
365,
488,
503,
1279,
22510,
365,
488,
503,
1279,
44,
2753,
365,
488,
26,
288,
1827,
275,
334,
1575,
17180,
2151,
1275,
2416,
342,
2151,
1275,
4509,
1332,
1575,
17180,
14,
28331,
63,
344,
5213,
2762,
9,
1253,
1169,
334,
1575,
17180,
14,
2297,
27307,
63,
521,
690,
2197,
14,
10779,
4059,
2151,
1275,
7892,
1012,
267,
587,
26,
288,
1827,
275,
334,
1575,
17180,
2151,
1275,
2416,
342,
2151,
1275,
4509,
1332,
1575,
17180,
14,
28331,
63,
344,
5213,
2762,
9,
1253,
1169,
334,
1575,
17180,
14,
2297,
27307,
63,
521,
690,
2197,
14,
10779,
1012,
1253,
1169,
334,
1575,
17180,
14,
13331,
2356,
5584,
22510,
9,
1253,
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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
] |
dmilith/SublimeText3-dmilith
|
Packages/pygments/all/pygments/lexers/r.py
|
47
|
23755
|
# -*- coding: utf-8 -*-
"""
pygments.lexers.r
~~~~~~~~~~~~~~~~~
Lexers for the R/S languages.
:copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
from pygments.lexer import Lexer, RegexLexer, include, words, do_insertions
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
Number, Punctuation, Generic
__all__ = ['RConsoleLexer', 'SLexer', 'RdLexer']
line_re = re.compile('.*?\n')
class RConsoleLexer(Lexer):
"""
For R console transcripts or R CMD BATCH output files.
"""
name = 'RConsole'
aliases = ['rconsole', 'rout']
filenames = ['*.Rout']
def get_tokens_unprocessed(self, text):
slexer = SLexer(**self.options)
current_code_block = ''
insertions = []
for match in line_re.finditer(text):
line = match.group()
if line.startswith('>') or line.startswith('+'):
# Colorize the prompt as such,
# then put rest of line into current_code_block
insertions.append((len(current_code_block),
[(0, Generic.Prompt, line[:2])]))
current_code_block += line[2:]
else:
# We have reached a non-prompt line!
# If we have stored prompt lines, need to process them first.
if current_code_block:
# Weave together the prompts and highlight code.
for item in do_insertions(
insertions, slexer.get_tokens_unprocessed(current_code_block)):
yield item
# Reset vars for next code block.
current_code_block = ''
insertions = []
# Now process the actual line itself, this is output from R.
yield match.start(), Generic.Output, line
# If we happen to end on a code block with nothing after it, need to
# process the last code block. This is neither elegant nor DRY so
# should be changed.
if current_code_block:
for item in do_insertions(
insertions, slexer.get_tokens_unprocessed(current_code_block)):
yield item
class SLexer(RegexLexer):
"""
For S, S-plus, and R source code.
.. versionadded:: 0.10
"""
name = 'S'
aliases = ['splus', 's', 'r']
filenames = ['*.S', '*.R', '.Rhistory', '.Rprofile', '.Renviron']
mimetypes = ['text/S-plus', 'text/S', 'text/x-r-source', 'text/x-r',
'text/x-R', 'text/x-r-history', 'text/x-r-profile']
builtins_base = (
'Arg', 'Conj', 'Cstack_info', 'Encoding', 'FALSE',
'Filter', 'Find', 'I', 'ISOdate', 'ISOdatetime', 'Im', 'Inf',
'La.svd', 'Map', 'Math.Date', 'Math.POSIXt', 'Math.data.frame',
'Math.difftime', 'Math.factor', 'Mod', 'NA_character_',
'NA_complex_', 'NA_real_', 'NCOL', 'NROW', 'NULLNA_integer_', 'NaN',
'Negate', 'NextMethod', 'Ops.Date', 'Ops.POSIXt', 'Ops.data.frame',
'Ops.difftime', 'Ops.factor', 'Ops.numeric_version', 'Ops.ordered',
'Position', 'R.Version', 'R.home', 'R.version', 'R.version.string',
'RNGkind', 'RNGversion', 'R_system_version', 'Re', 'Recall',
'Reduce', 'Summary.Date', 'Summary.POSIXct', 'Summary.POSIXlt',
'Summary.data.frame', 'Summary.difftime', 'Summary.factor',
'Summary.numeric_version', 'Summary.ordered', 'Sys.Date',
'Sys.chmod', 'Sys.getenv', 'Sys.getlocale', 'Sys.getpid',
'Sys.glob', 'Sys.info', 'Sys.localeconv', 'Sys.readlink',
'Sys.setFileTime', 'Sys.setenv', 'Sys.setlocale', 'Sys.sleep',
'Sys.time', 'Sys.timezone', 'Sys.umask', 'Sys.unsetenv',
'Sys.which', 'TRUE', 'UseMethod', 'Vectorize', 'abbreviate', 'abs',
'acos', 'acosh', 'addNA', 'addTaskCallback', 'agrep', 'alist',
'all', 'all.equal', 'all.equal.POSIXct', 'all.equal.character',
'all.equal.default', 'all.equal.factor', 'all.equal.formula',
'all.equal.language', 'all.equal.list', 'all.equal.numeric',
'all.equal.raw', 'all.names', 'all.vars', 'any', 'anyDuplicated',
'anyDuplicated.array', 'anyDuplicated.data.frame',
'anyDuplicated.default', 'anyDuplicated.matrix', 'aperm',
'aperm.default', 'aperm.table', 'append', 'apply', 'args',
'arrayInd', 'as.Date', 'as.Date.POSIXct', 'as.Date.POSIXlt',
'as.Date.character', 'as.Date.date', 'as.Date.dates',
'as.Date.default', 'as.Date.factor', 'as.Date.numeric',
'as.POSIXct', 'as.POSIXct.Date', 'as.POSIXct.POSIXlt',
'as.POSIXct.date', 'as.POSIXct.dates', 'as.POSIXct.default',
'as.POSIXct.numeric', 'as.POSIXlt', 'as.POSIXlt.Date',
'as.POSIXlt.POSIXct', 'as.POSIXlt.character', 'as.POSIXlt.date',
'as.POSIXlt.dates', 'as.POSIXlt.default', 'as.POSIXlt.factor',
'as.POSIXlt.numeric', 'as.array', 'as.array.default', 'as.call',
'as.character', 'as.character.Date', 'as.character.POSIXt',
'as.character.condition', 'as.character.default',
'as.character.error', 'as.character.factor', 'as.character.hexmode',
'as.character.numeric_version', 'as.character.octmode',
'as.character.srcref', 'as.complex', 'as.data.frame',
'as.data.frame.AsIs', 'as.data.frame.Date', 'as.data.frame.POSIXct',
'as.data.frame.POSIXlt', 'as.data.frame.array',
'as.data.frame.character', 'as.data.frame.complex',
'as.data.frame.data.frame', 'as.data.frame.default',
'as.data.frame.difftime', 'as.data.frame.factor',
'as.data.frame.integer', 'as.data.frame.list',
'as.data.frame.logical', 'as.data.frame.matrix',
'as.data.frame.model.matrix', 'as.data.frame.numeric',
'as.data.frame.numeric_version', 'as.data.frame.ordered',
'as.data.frame.raw', 'as.data.frame.table', 'as.data.frame.ts',
'as.data.frame.vector', 'as.difftime', 'as.double',
'as.double.POSIXlt', 'as.double.difftime', 'as.environment',
'as.expression', 'as.expression.default', 'as.factor',
'as.function', 'as.function.default', 'as.hexmode', 'as.integer',
'as.list', 'as.list.Date', 'as.list.POSIXct', 'as.list.data.frame',
'as.list.default', 'as.list.environment', 'as.list.factor',
'as.list.function', 'as.list.numeric_version', 'as.logical',
'as.logical.factor', 'as.matrix', 'as.matrix.POSIXlt',
'as.matrix.data.frame', 'as.matrix.default', 'as.matrix.noquote',
'as.name', 'as.null', 'as.null.default', 'as.numeric',
'as.numeric_version', 'as.octmode', 'as.ordered',
'as.package_version', 'as.pairlist', 'as.qr', 'as.raw', 'as.single',
'as.single.default', 'as.symbol', 'as.table', 'as.table.default',
'as.vector', 'as.vector.factor', 'asNamespace', 'asS3', 'asS4',
'asin', 'asinh', 'assign', 'atan', 'atan2', 'atanh',
'attachNamespace', 'attr', 'attr.all.equal', 'attributes',
'autoload', 'autoloader', 'backsolve', 'baseenv', 'basename',
'besselI', 'besselJ', 'besselK', 'besselY', 'beta',
'bindingIsActive', 'bindingIsLocked', 'bindtextdomain', 'bitwAnd',
'bitwNot', 'bitwOr', 'bitwShiftL', 'bitwShiftR', 'bitwXor', 'body',
'bquote', 'browser', 'browserCondition', 'browserSetDebug',
'browserText', 'builtins', 'by', 'by.data.frame', 'by.default',
'bzfile', 'c.Date', 'c.POSIXct', 'c.POSIXlt', 'c.noquote',
'c.numeric_version', 'call', 'callCC', 'capabilities', 'casefold',
'cat', 'category', 'cbind', 'cbind.data.frame', 'ceiling',
'char.expand', 'charToRaw', 'charmatch', 'chartr', 'check_tzones',
'chol', 'chol.default', 'chol2inv', 'choose', 'class',
'clearPushBack', 'close', 'close.connection', 'close.srcfile',
'close.srcfilealias', 'closeAllConnections', 'col', 'colMeans',
'colSums', 'colnames', 'commandArgs', 'comment', 'computeRestarts',
'conditionCall', 'conditionCall.condition', 'conditionMessage',
'conditionMessage.condition', 'conflicts', 'contributors', 'cos',
'cosh', 'crossprod', 'cummax', 'cummin', 'cumprod', 'cumsum', 'cut',
'cut.Date', 'cut.POSIXt', 'cut.default', 'dQuote', 'data.class',
'data.matrix', 'date', 'debug', 'debugonce',
'default.stringsAsFactors', 'delayedAssign', 'deparse', 'det',
'determinant', 'determinant.matrix', 'dget', 'diag', 'diff',
'diff.Date', 'diff.POSIXt', 'diff.default', 'difftime', 'digamma',
'dim', 'dim.data.frame', 'dimnames', 'dimnames.data.frame', 'dir',
'dir.create', 'dirname', 'do.call', 'dput', 'drop', 'droplevels',
'droplevels.data.frame', 'droplevels.factor', 'dump', 'duplicated',
'duplicated.POSIXlt', 'duplicated.array', 'duplicated.data.frame',
'duplicated.default', 'duplicated.matrix',
'duplicated.numeric_version', 'dyn.load', 'dyn.unload', 'eapply',
'eigen', 'else', 'emptyenv', 'enc2native', 'enc2utf8',
'encodeString', 'enquote', 'env.profile', 'environment',
'environmentIsLocked', 'environmentName', 'eval', 'eval.parent',
'evalq', 'exists', 'exp', 'expand.grid', 'expm1', 'expression',
'factor', 'factorial', 'fifo', 'file', 'file.access', 'file.append',
'file.choose', 'file.copy', 'file.create', 'file.exists',
'file.info', 'file.link', 'file.path', 'file.remove', 'file.rename',
'file.show', 'file.symlink', 'find.package', 'findInterval',
'findPackageEnv', 'findRestart', 'floor', 'flush',
'flush.connection', 'force', 'formals', 'format',
'format.AsIs', 'format.Date', 'format.POSIXct', 'format.POSIXlt',
'format.data.frame', 'format.default', 'format.difftime',
'format.factor', 'format.hexmode', 'format.info',
'format.libraryIQR', 'format.numeric_version', 'format.octmode',
'format.packageInfo', 'format.pval', 'format.summaryDefault',
'formatC', 'formatDL', 'forwardsolve', 'gamma', 'gc', 'gc.time',
'gcinfo', 'gctorture', 'gctorture2', 'get', 'getAllConnections',
'getCallingDLL', 'getCallingDLLe', 'getConnection',
'getDLLRegisteredRoutines', 'getDLLRegisteredRoutines.DLLInfo',
'getDLLRegisteredRoutines.character', 'getElement',
'getExportedValue', 'getHook', 'getLoadedDLLs', 'getNamespace',
'getNamespaceExports', 'getNamespaceImports', 'getNamespaceInfo',
'getNamespaceName', 'getNamespaceUsers', 'getNamespaceVersion',
'getNativeSymbolInfo', 'getOption', 'getRversion', 'getSrcLines',
'getTaskCallbackNames', 'geterrmessage', 'gettext', 'gettextf',
'getwd', 'gl', 'globalenv', 'gregexpr', 'grep', 'grepRaw', 'grepl',
'gsub', 'gzcon', 'gzfile', 'head', 'iconv', 'iconvlist',
'icuSetCollate', 'identical', 'identity', 'ifelse', 'importIntoEnv',
'in', 'inherits', 'intToBits', 'intToUtf8', 'interaction', 'interactive',
'intersect', 'inverse.rle', 'invisible', 'invokeRestart',
'invokeRestartInteractively', 'is.R', 'is.array', 'is.atomic',
'is.call', 'is.character', 'is.complex', 'is.data.frame',
'is.double', 'is.element', 'is.environment', 'is.expression',
'is.factor', 'is.finite', 'is.function', 'is.infinite',
'is.integer', 'is.language', 'is.list', 'is.loaded', 'is.logical',
'is.matrix', 'is.na', 'is.na.POSIXlt', 'is.na.data.frame',
'is.na.numeric_version', 'is.name', 'is.nan', 'is.null',
'is.numeric', 'is.numeric.Date', 'is.numeric.POSIXt',
'is.numeric.difftime', 'is.numeric_version', 'is.object',
'is.ordered', 'is.package_version', 'is.pairlist', 'is.primitive',
'is.qr', 'is.raw', 'is.recursive', 'is.single', 'is.symbol',
'is.table', 'is.unsorted', 'is.vector', 'isBaseNamespace',
'isIncomplete', 'isNamespace', 'isOpen', 'isRestart', 'isS4',
'isSeekable', 'isSymmetric', 'isSymmetric.matrix', 'isTRUE',
'isatty', 'isdebugged', 'jitter', 'julian', 'julian.Date',
'julian.POSIXt', 'kappa', 'kappa.default', 'kappa.lm', 'kappa.qr',
'kronecker', 'l10n_info', 'labels', 'labels.default', 'lapply',
'lazyLoad', 'lazyLoadDBexec', 'lazyLoadDBfetch', 'lbeta', 'lchoose',
'length', 'length.POSIXlt', 'letters', 'levels', 'levels.default',
'lfactorial', 'lgamma', 'library.dynam', 'library.dynam.unload',
'licence', 'license', 'list.dirs', 'list.files', 'list2env', 'load',
'loadNamespace', 'loadedNamespaces', 'loadingNamespaceInfo',
'local', 'lockBinding', 'lockEnvironment', 'log', 'log10', 'log1p',
'log2', 'logb', 'lower.tri', 'ls', 'make.names', 'make.unique',
'makeActiveBinding', 'mapply', 'margin.table', 'mat.or.vec',
'match', 'match.arg', 'match.call', 'match.fun', 'max', 'max.col',
'mean', 'mean.Date', 'mean.POSIXct', 'mean.POSIXlt', 'mean.default',
'mean.difftime', 'mem.limits', 'memCompress', 'memDecompress',
'memory.profile', 'merge', 'merge.data.frame', 'merge.default',
'message', 'mget', 'min', 'missing', 'mode', 'month.abb',
'month.name', 'months', 'months.Date', 'months.POSIXt',
'months.abb', 'months.nameletters', 'names', 'names.POSIXlt',
'namespaceExport', 'namespaceImport', 'namespaceImportClasses',
'namespaceImportFrom', 'namespaceImportMethods', 'nargs', 'nchar',
'ncol', 'new.env', 'ngettext', 'nlevels', 'noquote', 'norm',
'normalizePath', 'nrow', 'numeric_version', 'nzchar', 'objects',
'oldClass', 'on.exit', 'open', 'open.connection', 'open.srcfile',
'open.srcfilealias', 'open.srcfilecopy', 'options', 'order',
'ordered', 'outer', 'packBits', 'packageEvent',
'packageHasNamespace', 'packageStartupMessage', 'package_version',
'pairlist', 'parent.env', 'parent.frame', 'parse',
'parseNamespaceFile', 'paste', 'paste0', 'path.expand',
'path.package', 'pipe', 'pmatch', 'pmax', 'pmax.int', 'pmin',
'pmin.int', 'polyroot', 'pos.to.env', 'pretty', 'pretty.default',
'prettyNum', 'print', 'print.AsIs', 'print.DLLInfo',
'print.DLLInfoList', 'print.DLLRegisteredRoutines', 'print.Date',
'print.NativeRoutineList', 'print.POSIXct', 'print.POSIXlt',
'print.by', 'print.condition', 'print.connection',
'print.data.frame', 'print.default', 'print.difftime',
'print.factor', 'print.function', 'print.hexmode',
'print.libraryIQR', 'print.listof', 'print.noquote',
'print.numeric_version', 'print.octmode', 'print.packageInfo',
'print.proc_time', 'print.restart', 'print.rle',
'print.simple.list', 'print.srcfile', 'print.srcref',
'print.summary.table', 'print.summaryDefault', 'print.table',
'print.warnings', 'prmatrix', 'proc.time', 'prod', 'prop.table',
'provideDimnames', 'psigamma', 'pushBack', 'pushBackLength', 'q',
'qr', 'qr.Q', 'qr.R', 'qr.X', 'qr.coef', 'qr.default', 'qr.fitted',
'qr.qty', 'qr.qy', 'qr.resid', 'qr.solve', 'quarters',
'quarters.Date', 'quarters.POSIXt', 'quit', 'quote', 'range',
'range.default', 'rank', 'rapply', 'raw', 'rawConnection',
'rawConnectionValue', 'rawShift', 'rawToBits', 'rawToChar', 'rbind',
'rbind.data.frame', 'rcond', 'read.dcf', 'readBin', 'readChar',
'readLines', 'readRDS', 'readRenviron', 'readline', 'reg.finalizer',
'regexec', 'regexpr', 'registerS3method', 'registerS3methods',
'regmatches', 'remove', 'removeTaskCallback', 'rep', 'rep.Date',
'rep.POSIXct', 'rep.POSIXlt', 'rep.factor', 'rep.int',
'rep.numeric_version', 'rep_len', 'replace', 'replicate',
'requireNamespace', 'restartDescription', 'restartFormals',
'retracemem', 'rev', 'rev.default', 'rle', 'rm', 'round',
'round.Date', 'round.POSIXt', 'row', 'row.names',
'row.names.data.frame', 'row.names.default', 'rowMeans', 'rowSums',
'rownames', 'rowsum', 'rowsum.data.frame', 'rowsum.default',
'sQuote', 'sample', 'sample.int', 'sapply', 'save', 'save.image',
'saveRDS', 'scale', 'scale.default', 'scan', 'search',
'searchpaths', 'seek', 'seek.connection', 'seq', 'seq.Date',
'seq.POSIXt', 'seq.default', 'seq.int', 'seq_along', 'seq_len',
'sequence', 'serialize', 'set.seed', 'setHook', 'setNamespaceInfo',
'setSessionTimeLimit', 'setTimeLimit', 'setdiff', 'setequal',
'setwd', 'shQuote', 'showConnections', 'sign', 'signalCondition',
'signif', 'simpleCondition', 'simpleError', 'simpleMessage',
'simpleWarning', 'simplify2array', 'sin', 'single',
'sinh', 'sink', 'sink.number', 'slice.index', 'socketConnection',
'socketSelect', 'solve', 'solve.default', 'solve.qr', 'sort',
'sort.POSIXlt', 'sort.default', 'sort.int', 'sort.list', 'split',
'split.Date', 'split.POSIXct', 'split.data.frame', 'split.default',
'sprintf', 'sqrt', 'srcfile', 'srcfilealias', 'srcfilecopy',
'srcref', 'standardGeneric', 'stderr', 'stdin', 'stdout', 'stop',
'stopifnot', 'storage.mode', 'strftime', 'strptime', 'strsplit',
'strtoi', 'strtrim', 'structure', 'strwrap', 'sub', 'subset',
'subset.data.frame', 'subset.default', 'subset.matrix',
'substitute', 'substr', 'substring', 'sum', 'summary',
'summary.Date', 'summary.POSIXct', 'summary.POSIXlt',
'summary.connection', 'summary.data.frame', 'summary.default',
'summary.factor', 'summary.matrix', 'summary.proc_time',
'summary.srcfile', 'summary.srcref', 'summary.table',
'suppressMessages', 'suppressPackageStartupMessages',
'suppressWarnings', 'svd', 'sweep', 'sys.call', 'sys.calls',
'sys.frame', 'sys.frames', 'sys.function', 'sys.load.image',
'sys.nframe', 'sys.on.exit', 'sys.parent', 'sys.parents',
'sys.save.image', 'sys.source', 'sys.status', 'system',
'system.file', 'system.time', 'system2', 't', 't.data.frame',
't.default', 'table', 'tabulate', 'tail', 'tan', 'tanh', 'tapply',
'taskCallbackManager', 'tcrossprod', 'tempdir', 'tempfile',
'testPlatformEquivalence', 'textConnection', 'textConnectionValue',
'toString', 'toString.default', 'tolower', 'topenv', 'toupper',
'trace', 'traceback', 'tracemem', 'tracingState', 'transform',
'transform.data.frame', 'transform.default', 'trigamma', 'trunc',
'trunc.Date', 'trunc.POSIXt', 'truncate', 'truncate.connection',
'try', 'tryCatch', 'typeof', 'unclass', 'undebug', 'union',
'unique', 'unique.POSIXlt', 'unique.array', 'unique.data.frame',
'unique.default', 'unique.matrix', 'unique.numeric_version',
'units', 'units.difftime', 'unix.time', 'unlink', 'unlist',
'unloadNamespace', 'unlockBinding', 'unname', 'unserialize',
'unsplit', 'untrace', 'untracemem', 'unz', 'upper.tri', 'url',
'utf8ToInt', 'vapply', 'version', 'warning', 'warnings', 'weekdays',
'weekdays.Date', 'weekdays.POSIXt', 'which', 'which.max',
'which.min', 'with', 'with.default', 'withCallingHandlers',
'withRestarts', 'withVisible', 'within', 'within.data.frame',
'within.list', 'write', 'write.dcf', 'writeBin', 'writeChar',
'writeLines', 'xor', 'xor.hexmode', 'xor.octmode',
'xpdrows.data.frame', 'xtfrm', 'xtfrm.AsIs', 'xtfrm.Date',
'xtfrm.POSIXct', 'xtfrm.POSIXlt', 'xtfrm.Surv', 'xtfrm.default',
'xtfrm.difftime', 'xtfrm.factor', 'xtfrm.numeric_version', 'xzfile',
'zapsmall'
)
tokens = {
'comments': [
(r'#.*$', Comment.Single),
],
'valid_name': [
(r'[a-zA-Z][\w.]*', Text),
# can begin with ., but not if that is followed by a digit
(r'\.[a-zA-Z_][\w.]*', Text),
],
'punctuation': [
(r'\[{1,2}|\]{1,2}|\(|\)|;|,', Punctuation),
],
'keywords': [
(words(builtins_base, suffix=r'(?![\w. =])'),
Keyword.Pseudo),
(r'(if|else|for|while|repeat|in|next|break|return|switch|function)'
r'(?![\w.])',
Keyword.Reserved),
(r'(array|category|character|complex|double|function|integer|list|'
r'logical|matrix|numeric|vector|data.frame|c)'
r'(?![\w.])',
Keyword.Type),
(r'(library|require|attach|detach|source)'
r'(?![\w.])',
Keyword.Namespace)
],
'operators': [
(r'<<?-|->>?|-|==|<=|>=|<|>|&&?|!=|\|\|?|\?', Operator),
(r'\*|\+|\^|/|!|%[^%]*%|=|~|\$|@|:{1,3}', Operator)
],
'builtin_symbols': [
(r'(NULL|NA(_(integer|real|complex|character)_)?|'
r'letters|LETTERS|Inf|TRUE|FALSE|NaN|pi|\.\.(\.|[0-9]+))'
r'(?![\w.])',
Keyword.Constant),
(r'(T|F)\b', Name.Builtin.Pseudo),
],
'numbers': [
# hex number
(r'0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?', Number.Hex),
# decimal number
(r'[+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+|\.)([eE][+-]?[0-9]+)?[Li]?',
Number),
],
'statements': [
include('comments'),
# whitespaces
(r'\s+', Text),
(r'`.*?`', String.Backtick),
(r'\'', String, 'string_squote'),
(r'\"', String, 'string_dquote'),
include('builtin_symbols'),
include('numbers'),
include('keywords'),
include('punctuation'),
include('operators'),
include('valid_name'),
],
'root': [
include('statements'),
# blocks:
(r'\{|\}', Punctuation),
# (r'\{', Punctuation, 'block'),
(r'.', Text),
],
# 'block': [
# include('statements'),
# ('\{', Punctuation, '#push'),
# ('\}', Punctuation, '#pop')
# ],
'string_squote': [
(r'([^\'\\]|\\.)*\'', String, '#pop'),
],
'string_dquote': [
(r'([^"\\]|\\.)*"', String, '#pop'),
],
}
def analyse_text(text):
if re.search(r'[a-z0-9_\])\s]<-(?!-)', text):
return 0.11
class RdLexer(RegexLexer):
"""
Pygments Lexer for R documentation (Rd) files
This is a very minimal implementation, highlighting little more
than the macros. A description of Rd syntax is found in `Writing R
Extensions <http://cran.r-project.org/doc/manuals/R-exts.html>`_
and `Parsing Rd files <developer.r-project.org/parseRd.pdf>`_.
.. versionadded:: 1.6
"""
name = 'Rd'
aliases = ['rd']
filenames = ['*.Rd']
mimetypes = ['text/x-r-doc']
# To account for verbatim / LaTeX-like / and R-like areas
# would require parsing.
tokens = {
'root': [
# catch escaped brackets and percent sign
(r'\\[\\{}%]', String.Escape),
# comments
(r'%.*$', Comment),
# special macros with no arguments
(r'\\(?:cr|l?dots|R|tab)\b', Keyword.Constant),
# macros
(r'\\[a-zA-Z]+\b', Keyword),
# special preprocessor macros
(r'^\s*#(?:ifn?def|endif).*\b', Comment.Preproc),
# non-escaped brackets
(r'[{}]', Name.Builtin),
# everything else
(r'[^\\%\n{}]+', Text),
(r'.', Text),
]
}
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
82,
272,
18294,
94,
339,
491,
476,
1192,
367,
314,
820,
15,
51,
10815,
14,
339,
520,
7307,
26,
1898,
8315,
13,
7806,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
199,
504,
13277,
14,
11729,
492,
21125,
12,
12939,
5838,
12,
2387,
12,
5932,
12,
886,
63,
262,
13049,
199,
504,
13277,
14,
1418,
492,
4516,
12,
6819,
12,
11013,
12,
6431,
12,
2812,
12,
2624,
12,
971,
272,
4860,
12,
10357,
12,
8307,
199,
199,
363,
452,
363,
275,
788,
50,
9270,
5838,
297,
283,
4929,
5273,
297,
283,
50,
68,
5838,
418,
421,
199,
604,
63,
264,
221,
275,
295,
14,
2014,
360,
21040,
78,
358,
421,
199,
533,
820,
9270,
5838,
8,
5838,
304,
272,
408,
272,
2104,
820,
8559,
7115,
6429,
503,
820,
25548,
699,
8078,
1072,
1584,
14,
272,
408,
339,
536,
275,
283,
50,
9270,
7,
272,
5481,
275,
788,
82,
6614,
297,
283,
12791,
418,
272,
6203,
275,
17855,
7595,
418,
339,
347,
664,
63,
4504,
63,
24088,
8,
277,
12,
1318,
304,
267,
308,
11729,
275,
428,
5838,
3682,
277,
14,
1419,
9,
398,
1453,
63,
600,
63,
1457,
275,
2125,
267,
32465,
275,
942,
398,
367,
1336,
315,
1004,
63,
264,
14,
19373,
8,
505,
304,
288,
1004,
275,
1336,
14,
923,
342,
288,
340,
1004,
14,
2460,
28781,
503,
1004,
14,
2460,
19975,
735,
355,
327,
11581,
794,
314,
8457,
465,
4066,
12,
355,
327,
2066,
5324,
4618,
402,
1004,
1901,
1453,
63,
600,
63,
1457,
355,
32465,
14,
740,
1332,
552,
8,
1818,
63,
600,
63,
1457,
395,
3521,
3842,
16,
12,
8307,
14,
20430,
12,
1004,
1491,
18,
566,
2459,
355,
1453,
63,
600,
63,
1457,
847,
1004,
59,
18,
2938,
288,
587,
26,
355,
327,
2136,
1172,
13075,
282,
2222,
13,
7650,
1004,
1,
355,
327,
982,
781,
1172,
5489,
8457,
2385,
12,
1929,
370,
2112,
3062,
1642,
14,
355,
340,
1453,
63,
600,
63,
1457,
26,
490,
327,
2136,
811,
10451,
314,
29951,
436,
11850,
1233,
14,
490,
367,
1242,
315,
886,
63,
262,
13049,
8,
1169,
32465,
12,
308,
11729,
14,
362,
63,
4504,
63,
24088,
8,
1818,
63,
600,
63,
1457,
2298,
717,
1995,
1242,
490,
327,
15510,
6802,
367,
2163,
1233,
1853,
14,
490,
1453,
63,
600,
63,
1457,
275,
2125,
490,
32465,
275,
942,
355,
327,
7356,
2112,
314,
3503,
1004,
6337,
12,
642,
365,
1072,
687,
820,
14,
355,
1995,
1336,
14,
928,
1062,
8307,
14,
2959,
12,
1004,
398,
327,
982,
781,
5992,
370,
1284,
641,
282,
1233,
1853,
543,
6548,
2410,
652,
12,
1929,
370,
267,
327,
2112,
314,
2061,
1233,
1853,
14,
961,
365,
15564,
325,
4170,
867,
6590,
577,
5782,
880,
267,
327,
1077,
506,
2896,
14,
267,
340,
1453,
63,
600,
63,
1457,
26,
288,
367,
1242,
315,
886,
63,
262,
13049,
8,
490,
32465,
12,
308,
11729,
14,
362,
63,
4504,
63,
24088,
8,
1818,
63,
600,
63,
1457,
2298,
355,
1995,
1242,
421,
199,
533,
428,
5838,
8,
19856,
304,
272,
408,
272,
2104,
428,
12,
428,
13,
6666,
12,
436,
820,
1350,
1233,
14,
339,
2508,
7445,
447,
378,
14,
709,
272,
408,
339,
536,
275,
283,
51,
7,
272,
5481,
275,
788,
15276,
527,
297,
283,
83,
297,
283,
82,
418,
272,
6203,
275,
17855,
51,
297,
11937,
50,
297,
1987,
50,
5570,
297,
1987,
50,
2913,
297,
1987,
50,
2314,
418,
272,
13290,
275,
788,
505,
15,
51,
13,
6666,
297,
283,
505,
15,
51,
297,
283,
505,
15,
88,
13,
82,
13,
1365,
297,
283,
505,
15,
88,
13,
82,
297,
326,
283,
505,
15,
88,
13,
50,
297,
283,
505,
15,
88,
13,
82,
13,
5570,
297,
283,
505,
15,
88,
13,
82,
13,
2913,
418,
339,
12963,
63,
1095,
275,
334,
267,
283,
6373,
297,
283,
714,
74,
297,
283,
35,
2340,
63,
815,
297,
283,
7630,
297,
283,
19823,
297,
267,
283,
4131,
297,
283,
6591,
297,
283,
41,
297,
283,
7336,
602,
297,
283,
7336,
2083,
297,
283,
16221,
297,
283,
17354,
297,
267,
283,
7833,
14,
18675,
297,
283,
2956,
297,
283,
18568,
14,
2506,
297,
283,
18568,
14,
16399,
84,
297,
283,
18568,
14,
576,
14,
1943,
297,
267,
283,
18568,
14,
3028,
521,
297,
283,
18568,
14,
4778,
297,
283,
9871,
297,
283,
7170,
63,
10856,
14474,
267,
283,
7170,
63,
5254,
14474,
283,
7170,
63,
3093,
14474,
283,
46,
3978,
297,
283,
46,
11415,
297,
283,
8084,
7170,
63,
4115,
14474,
283,
14300,
297,
267,
283,
4698,
3237,
297,
283,
5765,
3767,
297,
283,
16452,
14,
2506,
297,
283,
16452,
14,
16399,
84,
297,
283,
16452,
14,
576,
14,
1943,
297,
267,
283,
16452,
14,
3028,
521,
297,
283,
16452,
14,
4778,
297,
283,
16452,
14,
6677,
63,
1023,
297,
283,
16452,
14,
8235,
297,
267,
283,
5625,
297,
283,
50,
14,
3353,
297,
283,
50,
14,
4219,
297,
283,
50,
14,
1023,
297,
283,
50,
14,
1023,
14,
875,
297,
267,
283,
50,
12259,
5091,
297,
283,
50,
12259,
1023,
297,
283,
50,
63,
2253,
63,
1023,
297,
283,
497,
297,
283,
497,
1250,
297,
267,
283,
21822,
297,
283,
10407,
14,
2506,
297,
283,
10407,
14,
16399,
319,
297,
283,
10407,
14,
16399,
4116,
297,
267,
283,
10407,
14,
576,
14,
1943,
297,
283,
10407,
14,
3028,
521,
297,
283,
10407,
14,
4778,
297,
267,
283,
10407,
14,
6677,
63,
1023,
297,
283,
10407,
14,
8235,
297,
283,
11319,
14,
2506,
297,
267,
283,
11319,
14,
11693,
297,
283,
11319,
14,
12959,
297,
283,
11319,
14,
362,
5508,
297,
283,
11319,
14,
17829,
297,
267,
283,
11319,
14,
6463,
297,
283,
11319,
14,
815,
297,
283,
11319,
14,
5508,
5598,
297,
283,
11319,
14,
31654,
297,
267,
283,
11319,
14,
409,
1173,
1366,
297,
283,
11319,
14,
261,
9072,
297,
283,
11319,
14,
409,
5508,
297,
283,
11319,
14,
4532,
297,
267,
283,
11319,
14,
521,
297,
283,
11319,
14,
7145,
297,
283,
11319,
14,
18315,
297,
283,
11319,
14
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
82,
272,
18294,
94,
339,
491,
476,
1192,
367,
314,
820,
15,
51,
10815,
14,
339,
520,
7307,
26,
1898,
8315,
13,
7806,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
199,
504,
13277,
14,
11729,
492,
21125,
12,
12939,
5838,
12,
2387,
12,
5932,
12,
886,
63,
262,
13049,
199,
504,
13277,
14,
1418,
492,
4516,
12,
6819,
12,
11013,
12,
6431,
12,
2812,
12,
2624,
12,
971,
272,
4860,
12,
10357,
12,
8307,
199,
199,
363,
452,
363,
275,
788,
50,
9270,
5838,
297,
283,
4929,
5273,
297,
283,
50,
68,
5838,
418,
421,
199,
604,
63,
264,
221,
275,
295,
14,
2014,
360,
21040,
78,
358,
421,
199,
533,
820,
9270,
5838,
8,
5838,
304,
272,
408,
272,
2104,
820,
8559,
7115,
6429,
503,
820,
25548,
699,
8078,
1072,
1584,
14,
272,
408,
339,
536,
275,
283,
50,
9270,
7,
272,
5481,
275,
788,
82,
6614,
297,
283,
12791,
418,
272,
6203,
275,
17855,
7595,
418,
339,
347,
664,
63,
4504,
63,
24088,
8,
277,
12,
1318,
304,
267,
308,
11729,
275,
428,
5838,
3682,
277,
14,
1419,
9,
398,
1453,
63,
600,
63,
1457,
275,
2125,
267,
32465,
275,
942,
398,
367,
1336,
315,
1004,
63,
264,
14,
19373,
8,
505,
304,
288,
1004,
275,
1336,
14,
923,
342,
288,
340,
1004,
14,
2460,
28781,
503,
1004,
14,
2460,
19975,
735,
355,
327,
11581,
794,
314,
8457,
465,
4066,
12,
355,
327,
2066,
5324,
4618,
402,
1004,
1901,
1453,
63,
600,
63,
1457,
355,
32465,
14,
740,
1332,
552,
8,
1818,
63,
600,
63,
1457,
395,
3521,
3842,
16,
12,
8307,
14,
20430,
12,
1004,
1491,
18,
566,
2459,
355,
1453,
63,
600,
63,
1457,
847,
1004,
59,
18,
2938,
288,
587,
26,
355,
327,
2136,
1172,
13075,
282,
2222,
13,
7650,
1004,
1,
355,
327,
982,
781,
1172,
5489,
8457,
2385,
12,
1929,
370,
2112,
3062,
1642,
14,
355,
340,
1453,
63,
600,
63,
1457,
26,
490,
327,
2136,
811,
10451,
314,
29951,
436,
11850,
1233,
14,
490,
367,
1242,
315,
886,
63,
262,
13049,
8,
1169,
32465,
12,
308,
11729,
14,
362,
63,
4504,
63,
24088,
8,
1818,
63,
600,
63,
1457,
2298,
717,
1995,
1242,
490,
327,
15510,
6802,
367,
2163,
1233,
1853,
14,
490,
1453,
63,
600,
63,
1457,
275,
2125,
490,
32465,
275,
942,
355,
327,
7356,
2112,
314,
3503,
1004,
6337,
12,
642,
365,
1072,
687,
820,
14,
355,
1995,
1336,
14,
928,
1062,
8307,
14,
2959,
12,
1004,
398,
327,
982,
781,
5992,
370,
1284,
641,
282,
1233,
1853,
543,
6548,
2410,
652,
12,
1929,
370,
267,
327,
2112,
314,
2061,
1233,
1853,
14,
961,
365,
15564,
325,
4170,
867,
6590,
577,
5782,
880,
267,
327,
1077,
506,
2896,
14,
267,
340,
1453,
63,
600,
63,
1457,
26,
288,
367,
1242,
315,
886,
63,
262,
13049,
8,
490,
32465,
12,
308,
11729,
14,
362,
63,
4504,
63,
24088,
8,
1818,
63,
600,
63,
1457,
2298,
355,
1995,
1242,
421,
199,
533,
428,
5838,
8,
19856,
304,
272,
408,
272,
2104,
428,
12,
428,
13,
6666,
12,
436,
820,
1350,
1233,
14,
339,
2508,
7445,
447,
378,
14,
709,
272,
408,
339,
536,
275,
283,
51,
7,
272,
5481,
275,
788,
15276,
527,
297,
283,
83,
297,
283,
82,
418,
272,
6203,
275,
17855,
51,
297,
11937,
50,
297,
1987,
50,
5570,
297,
1987,
50,
2913,
297,
1987,
50,
2314,
418,
272,
13290,
275,
788,
505,
15,
51,
13,
6666,
297,
283,
505,
15,
51,
297,
283,
505,
15,
88,
13,
82,
13,
1365,
297,
283,
505,
15,
88,
13,
82,
297,
326,
283,
505,
15,
88,
13,
50,
297,
283,
505,
15,
88,
13,
82,
13,
5570,
297,
283,
505,
15,
88,
13,
82,
13,
2913,
418,
339,
12963,
63,
1095,
275,
334,
267,
283,
6373,
297,
283,
714,
74,
297,
283,
35,
2340,
63,
815,
297,
283,
7630,
297,
283,
19823,
297,
267,
283,
4131,
297,
283,
6591,
297,
283,
41,
297,
283,
7336,
602,
297,
283,
7336,
2083,
297,
283,
16221,
297,
283,
17354,
297,
267,
283,
7833,
14,
18675,
297,
283,
2956,
297,
283,
18568,
14,
2506,
297,
283,
18568,
14,
16399,
84,
297,
283,
18568,
14,
576,
14,
1943,
297,
267,
283,
18568,
14,
3028,
521,
297,
283,
18568,
14,
4778,
297,
283,
9871,
297,
283,
7170,
63,
10856,
14474,
267,
283,
7170,
63,
5254,
14474,
283,
7170,
63,
3093,
14474,
283,
46,
3978,
297,
283,
46,
11415,
297,
283,
8084,
7170,
63,
4115,
14474,
283,
14300,
297,
267,
283,
4698,
3237,
297,
283,
5765,
3767,
297,
283,
16452,
14,
2506,
297,
283,
16452,
14,
16399,
84,
297,
283,
16452,
14,
576,
14,
1943,
297,
267,
283,
16452,
14,
3028,
521,
297,
283,
16452,
14,
4778,
297,
283,
16452,
14,
6677,
63,
1023,
297,
283,
16452,
14,
8235,
297,
267,
283,
5625,
297,
283,
50,
14,
3353,
297,
283,
50,
14,
4219,
297,
283,
50,
14,
1023,
297,
283,
50,
14,
1023,
14,
875,
297,
267,
283,
50,
12259,
5091,
297,
283,
50,
12259,
1023,
297,
283,
50,
63,
2253,
63,
1023,
297,
283,
497,
297,
283,
497,
1250,
297,
267,
283,
21822,
297,
283,
10407,
14,
2506,
297,
283,
10407,
14,
16399,
319,
297,
283,
10407,
14,
16399,
4116,
297,
267,
283,
10407,
14,
576,
14,
1943,
297,
283,
10407,
14,
3028,
521,
297,
283,
10407,
14,
4778,
297,
267,
283,
10407,
14,
6677,
63,
1023,
297,
283,
10407,
14,
8235,
297,
283,
11319,
14,
2506,
297,
267,
283,
11319,
14,
11693,
297,
283,
11319,
14,
12959,
297,
283,
11319,
14,
362,
5508,
297,
283,
11319,
14,
17829,
297,
267,
283,
11319,
14,
6463,
297,
283,
11319,
14,
815,
297,
283,
11319,
14,
5508,
5598,
297,
283,
11319,
14,
31654,
297,
267,
283,
11319,
14,
409,
1173,
1366,
297,
283,
11319,
14,
261,
9072,
297,
283,
11319,
14,
409,
5508,
297,
283,
11319,
14,
4532,
297,
267,
283,
11319,
14,
521,
297,
283,
11319,
14,
7145,
297,
283,
11319,
14,
18315,
297,
283,
11319,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hmen89/odoo
|
addons/stock/report/report_stock.py
|
376
|
2486
|
# -*- 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/>.
#
##############################################################################
from openerp.osv import fields, osv
from openerp.tools.sql import drop_view_if_exists
class report_stock_lines_date(osv.osv):
_name = "report.stock.lines.date"
_description = "Dates of Inventories and latest Moves"
_auto = False
_order = "date"
_columns = {
'id': fields.integer('Product Id', readonly=True),
'product_id': fields.many2one('product.product', 'Product', readonly=True, select=True),
'date': fields.datetime('Date of latest Inventory', readonly=True),
'move_date': fields.datetime('Date of latest Stock Move', readonly=True),
"active": fields.boolean("Active", readonly=True),
}
def init(self, cr):
drop_view_if_exists(cr, 'report_stock_lines_date')
cr.execute("""
create or replace view report_stock_lines_date as (
select
p.id as id,
p.id as product_id,
max(s.date) as date,
max(m.date) as move_date,
p.active as active
from
product_product p
left join (
stock_inventory_line l
inner join stock_inventory s on (l.inventory_id=s.id and s.state = 'done')
) on (p.id=l.product_id)
left join stock_move m on (m.product_id=p.id and m.state = 'done')
group by p.id
)""")
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
504,
5166,
14,
2537,
14,
3009,
492,
5978,
63,
1345,
63,
692,
63,
2444,
199,
199,
533,
3622,
63,
6088,
63,
1278,
63,
602,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
298,
3070,
14,
6088,
14,
1278,
14,
602,
2,
272,
485,
1802,
275,
298,
36,
2335,
402,
1010,
782,
6112,
436,
8839,
3930,
2310,
2,
272,
485,
2495,
275,
756,
272,
485,
1648,
275,
298,
602,
2,
272,
485,
3406,
275,
469,
267,
283,
344,
356,
1504,
14,
4115,
360,
5884,
15418,
297,
6863,
29,
549,
395,
267,
283,
2558,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
2558,
14,
2558,
297,
283,
5884,
297,
6863,
29,
549,
12,
3504,
29,
549,
395,
267,
283,
602,
356,
1504,
14,
2083,
360,
2506,
402,
8839,
19337,
297,
6863,
29,
549,
395,
267,
283,
1185,
63,
602,
356,
1504,
14,
2083,
360,
2506,
402,
8839,
28406,
14171,
297,
6863,
29,
549,
395,
267,
298,
2682,
582,
1504,
14,
4871,
480,
7472,
401,
6863,
29,
549,
395,
272,
789,
339,
347,
4205,
8,
277,
12,
2467,
304,
267,
5978,
63,
1345,
63,
692,
63,
2444,
8,
1556,
12,
283,
3070,
63,
6088,
63,
1278,
63,
602,
358,
267,
2467,
14,
2526,
4852,
288,
1218,
503,
3350,
2455,
3622,
63,
6088,
63,
1278,
63,
602,
465,
334,
355,
3504,
355,
299,
14,
344,
465,
1305,
12,
355,
299,
14,
344,
465,
3336,
63,
344,
12,
355,
1390,
8,
83,
14,
602,
9,
465,
1434,
12,
355,
1390,
8,
77,
14,
602,
9,
465,
4057,
63,
602,
12,
355,
299,
14,
2682,
465,
4702,
288,
687,
355,
3336,
63,
2558,
299,
490,
3602,
4263,
334,
717,
10952,
63,
7212,
63,
604,
634,
717,
6506,
4263,
10952,
63,
7212,
308,
641,
334,
76,
14,
7212,
63,
344,
29,
83,
14,
344,
436,
308,
14,
929,
275,
283,
4456,
358,
490,
776,
641,
334,
80,
14,
344,
29,
76,
14,
2558,
63,
344,
9,
490,
3602,
4263,
10952,
63,
1185,
333,
641,
334,
77,
14,
2558,
63,
344,
29,
80,
14,
344,
436,
333,
14,
929,
275,
283,
4456,
358,
355,
1572,
701,
299,
14,
344,
288,
776,
6141,
421,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
504,
5166,
14,
2537,
14,
3009,
492,
5978,
63,
1345,
63,
692,
63,
2444,
199,
199,
533,
3622,
63,
6088,
63,
1278,
63,
602,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
298,
3070,
14,
6088,
14,
1278,
14,
602,
2,
272,
485,
1802,
275,
298,
36,
2335,
402,
1010,
782,
6112,
436,
8839,
3930,
2310,
2,
272,
485,
2495,
275,
756,
272,
485,
1648,
275,
298,
602,
2,
272,
485,
3406,
275,
469,
267,
283,
344,
356,
1504,
14,
4115,
360,
5884,
15418,
297,
6863,
29,
549,
395,
267,
283,
2558,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
2558,
14,
2558,
297,
283,
5884,
297,
6863,
29,
549,
12,
3504,
29,
549,
395,
267,
283,
602,
356,
1504,
14,
2083,
360,
2506,
402,
8839,
19337,
297,
6863,
29,
549,
395,
267,
283,
1185,
63,
602,
356,
1504,
14,
2083,
360,
2506,
402,
8839,
28406,
14171,
297,
6863,
29,
549,
395,
267,
298,
2682,
582,
1504,
14,
4871,
480,
7472,
401,
6863,
29,
549,
395,
272,
789,
339,
347,
4205,
8,
277,
12,
2467,
304,
267,
5978,
63,
1345,
63,
692,
63,
2444,
8,
1556,
12,
283,
3070,
63,
6088,
63,
1278,
63,
602,
358,
267,
2467,
14,
2526,
4852,
288,
1218,
503,
3350,
2455,
3622,
63,
6088,
63,
1278,
63,
602,
465,
334,
355,
3504,
355,
299,
14,
344,
465,
1305,
12,
355,
299,
14,
344,
465,
3336,
63,
344,
12,
355,
1390,
8,
83,
14,
602,
9,
465,
1434,
12,
355,
1390,
8,
77,
14,
602,
9,
465,
4057,
63,
602,
12,
355,
299,
14,
2682,
465,
4702,
288,
687,
355,
3336,
63,
2558,
299,
490,
3602,
4263,
334,
717,
10952,
63,
7212,
63,
604,
634,
717,
6506,
4263,
10952,
63,
7212,
308,
641,
334,
76,
14,
7212,
63,
344,
29,
83,
14,
344,
436,
308,
14,
929,
275,
283,
4456,
358,
490,
776,
641,
334,
80,
14,
344,
29,
76,
14,
2558,
63,
344,
9,
490,
3602,
4263,
10952,
63,
1185,
333,
641,
334,
77,
14,
2558,
63,
344,
29,
80,
14,
344,
436,
333,
14,
929,
275,
283,
4456,
358,
355,
1572,
701,
299,
14,
344,
288,
776,
6141,
421,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pyblish/pyblish-win
|
lib/Python27/Lib/encodings/euc_jis_2004.py
|
816
|
1051
|
#
# euc_jis_2004.py: Python Unicode Codec for EUC_JIS_2004
#
# Written by Hye-Shik Chang <perky@FreeBSD.org>
#
import _codecs_jp, codecs
import _multibytecodec as mbc
codec = _codecs_jp.getcodec('euc_jis_2004')
class Codec(codecs.Codec):
encode = codec.encode
decode = codec.decode
class IncrementalEncoder(mbc.MultibyteIncrementalEncoder,
codecs.IncrementalEncoder):
codec = codec
class IncrementalDecoder(mbc.MultibyteIncrementalDecoder,
codecs.IncrementalDecoder):
codec = codec
class StreamReader(Codec, mbc.MultibyteStreamReader, codecs.StreamReader):
codec = codec
class StreamWriter(Codec, mbc.MultibyteStreamWriter, codecs.StreamWriter):
codec = codec
def getregentry():
return codecs.CodecInfo(
name='euc_jis_2004',
encode=Codec().encode,
decode=Codec().decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
|
lgpl-3.0
|
[
3,
199,
3,
325,
947,
63,
18941,
63,
15431,
14,
647,
26,
2018,
6140,
13732,
367,
662,
13371,
63,
22290,
63,
15431,
199,
3,
199,
3,
27694,
701,
869,
8048,
13,
2662,
3258,
2799,
621,
665,
529,
10562,
32,
10146,
15400,
14,
1308,
30,
199,
3,
199,
199,
646,
485,
8933,
63,
11538,
12,
6010,
199,
646,
485,
3029,
4414,
9276,
465,
333,
3776,
199,
199,
9276,
275,
485,
8933,
63,
11538,
14,
362,
9276,
360,
15149,
63,
18941,
63,
15431,
358,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
272,
3752,
275,
9076,
14,
2143,
272,
4849,
275,
9076,
14,
2708,
199,
199,
533,
24350,
8,
887,
67,
14,
3947,
4414,
17016,
12,
586,
6010,
14,
17016,
304,
272,
9076,
275,
9076,
199,
199,
533,
24385,
8,
887,
67,
14,
3947,
4414,
16703,
12,
586,
6010,
14,
16703,
304,
272,
9076,
275,
9076,
199,
199,
533,
22970,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16132,
12,
6010,
14,
16132,
304,
272,
9076,
275,
9076,
199,
199,
533,
24163,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16551,
12,
6010,
14,
16551,
304,
272,
9076,
275,
9076,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
15149,
63,
18941,
63,
15431,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
325,
947,
63,
18941,
63,
15431,
14,
647,
26,
2018,
6140,
13732,
367,
662,
13371,
63,
22290,
63,
15431,
199,
3,
199,
3,
27694,
701,
869,
8048,
13,
2662,
3258,
2799,
621,
665,
529,
10562,
32,
10146,
15400,
14,
1308,
30,
199,
3,
199,
199,
646,
485,
8933,
63,
11538,
12,
6010,
199,
646,
485,
3029,
4414,
9276,
465,
333,
3776,
199,
199,
9276,
275,
485,
8933,
63,
11538,
14,
362,
9276,
360,
15149,
63,
18941,
63,
15431,
358,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
272,
3752,
275,
9076,
14,
2143,
272,
4849,
275,
9076,
14,
2708,
199,
199,
533,
24350,
8,
887,
67,
14,
3947,
4414,
17016,
12,
586,
6010,
14,
17016,
304,
272,
9076,
275,
9076,
199,
199,
533,
24385,
8,
887,
67,
14,
3947,
4414,
16703,
12,
586,
6010,
14,
16703,
304,
272,
9076,
275,
9076,
199,
199,
533,
22970,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16132,
12,
6010,
14,
16132,
304,
272,
9076,
275,
9076,
199,
199,
533,
24163,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16551,
12,
6010,
14,
16551,
304,
272,
9076,
275,
9076,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
15149,
63,
18941,
63,
15431,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Changaco/oh-mainline
|
mysite/profile/migrations/0007_tag_type_remove_s.py
|
17
|
5292
|
# This file is part of OpenHatch.
# Copyright (C) 2009 OpenHatch, Inc.
#
# 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 south.db import db
from django.db import models
from mysite.profile.models import *
class Migration:
def forwards(self, orm):
# Adding model 'TagType'
db.create_table('profile_tagtype', (
('id', models.AutoField(primary_key=True)),
('prefix', models.CharField(max_length=20)),
))
db.send_create_signal('profile', ['TagType'])
# Deleting model 'tagtypes'
db.delete_table('profile_tagtypes')
# Changing field 'Person.time_record_was_created'
db.alter_column('profile_person', 'time_record_was_created', models.DateTimeField(default=datetime.datetime(2009, 6, 19, 12, 12, 52, 616983)))
# Changing field 'Link_ProjectExp_Tag.time_record_was_created'
db.alter_column('profile_link_projectexp_tag', 'time_record_was_created', models.DateTimeField(default=datetime.datetime(2009, 6, 19, 12, 12, 53, 45500)))
def backwards(self, orm):
# Deleting model 'TagType'
db.delete_table('profile_tagtype')
# Adding model 'tagtypes'
db.create_table('profile_tagtypes', (
('prefix', models.CharField(max_length=20)),
('id', models.AutoField(primary_key=True)),
))
db.send_create_signal('profile', ['tagtypes'])
# Changing field 'Person.time_record_was_created'
db.alter_column('profile_person', 'time_record_was_created', models.DateTimeField(default=datetime.datetime(2009, 6, 19, 12, 9, 5, 403945)))
# Changing field 'Link_ProjectExp_Tag.time_record_was_created'
db.alter_column('profile_link_projectexp_tag', 'time_record_was_created', models.DateTimeField(default=datetime.datetime(2009, 6, 19, 12, 9, 5, 292717)))
models = {
'profile.person': {
'id': ('models.AutoField', [], {'primary_key': 'True'}),
'last_polled': ('models.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'last_touched': ('models.DateTimeField', [], {}),
'name': ('models.CharField', [], {'max_length': '200'}),
'password_hash_md5': ('models.CharField', [], {'max_length': '200'}),
'poll_on_next_web_view': ('models.BooleanField', [], {'default': 'True'}),
'time_record_was_created': ('models.DateTimeField', [], {'default': 'datetime.datetime(2009, 6, 19, 12, 12, 53, 486535)'}),
'username': ('models.CharField', [], {'max_length': '200'})
},
'profile.tag': {
'id': ('models.AutoField', [], {'primary_key': 'True'}),
'text': ('models.CharField', [], {'max_length': '50'}),
'type': ('models.CharField', [], {'max_length': '50'})
},
'profile.link_projectexp_tag': {
'id': ('models.AutoField', [], {'primary_key': 'True'}),
'project_exp': ('models.ForeignKey', ["orm['profile.ProjectExp']"], {}),
'source': ('models.CharField', [], {'max_length': '200'}),
'tag': ('models.ForeignKey', ["orm['profile.Tag']"], {}),
'time_record_was_created': ('models.DateTimeField', [], {'default': 'datetime.datetime(2009, 6, 19, 12, 12, 54, 25865)'})
},
'search.project': {
'_stub': True,
'id': ('models.AutoField', [], {'primary_key': 'True'})
},
'profile.tagtype': {
'id': ('models.AutoField', [], {'primary_key': 'True'}),
'prefix': ('models.CharField', [], {'max_length': '20'})
},
'profile.projectexp': {
'description': ('models.TextField', [], {}),
'id': ('models.AutoField', [], {'primary_key': 'True'}),
'man_months': ('models.PositiveIntegerField', [], {}),
'person': ('models.ForeignKey', ["orm['profile.Person']"], {}),
'person_role': ('models.CharField', [], {'max_length': '200'}),
'primary_language': ('models.CharField', [], {'max_length': '200'}),
'project': ('models.ForeignKey', ["orm['search.Project']"], {}),
'source': ('models.CharField', [], {'max_length': '100'}),
'tags': ('models.TextField', [], {}),
'time_finish': ('models.DateTimeField', [], {}),
'time_record_was_created': ('models.DateTimeField', [], {}),
'time_start': ('models.DateTimeField', [], {}),
'url': ('models.URLField', [], {'max_length': '200'})
}
}
complete_apps = ['profile']
|
agpl-3.0
|
[
3,
961,
570,
365,
1777,
402,
3232,
40,
693,
14,
199,
3,
1898,
334,
35,
9,
8937,
3232,
40,
693,
12,
3277,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
3002,
2124,
14,
2913,
14,
992,
492,
627,
199,
199,
533,
12090,
26,
2286,
347,
17465,
8,
277,
12,
9813,
304,
2728,
327,
12934,
1402,
283,
1931,
804,
7,
267,
1592,
14,
981,
63,
1224,
360,
2913,
63,
1450,
466,
297,
334,
288,
661,
344,
297,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
1826,
288,
661,
1861,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1165,
1826,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
360,
2913,
297,
788,
1931,
804,
1105,
2728,
327,
15920,
1402,
283,
1450,
1313,
7,
267,
1592,
14,
1807,
63,
1224,
360,
2913,
63,
1450,
1313,
358,
2728,
327,
27854,
901,
283,
7344,
14,
521,
63,
3059,
63,
10274,
63,
3966,
7,
267,
1592,
14,
11858,
63,
2301,
360,
2913,
63,
5484,
297,
283,
521,
63,
3059,
63,
10274,
63,
3966,
297,
1709,
14,
4626,
8,
885,
29,
2083,
14,
2083,
8,
8664,
12,
1227,
12,
5851,
12,
3144,
12,
3144,
12,
14589,
12,
1227,
10143,
2658,
1724,
2728,
327,
27854,
901,
283,
3834,
63,
4761,
4527,
63,
1931,
14,
521,
63,
3059,
63,
10274,
63,
3966,
7,
267,
1592,
14,
11858,
63,
2301,
360,
2913,
63,
1073,
63,
5468,
825,
3858,
80,
63,
1450,
297,
283,
521,
63,
3059,
63,
10274,
63,
3966,
297,
1709,
14,
4626,
8,
885,
29,
2083,
14,
2083,
8,
8664,
12,
1227,
12,
5851,
12,
3144,
12,
3144,
12,
13564,
12,
841,
1229,
383,
1724,
268,
17635,
347,
8552,
8,
277,
12,
9813,
304,
2728,
327,
15920,
1402,
283,
1931,
804,
7,
267,
1592,
14,
1807,
63,
1224,
360,
2913,
63,
1450,
466,
358,
2728,
327,
12934,
1402,
283,
1450,
1313,
7,
267,
1592,
14,
981,
63,
1224,
360,
2913,
63,
1450,
1313,
297,
334,
288,
661,
1861,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1165,
1826,
288,
661,
344,
297,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
1826,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
360,
2913,
297,
788,
1450,
1313,
1105,
2728,
327,
27854,
901,
283,
7344,
14,
521,
63,
3059,
63,
10274,
63,
3966,
7,
267,
1592,
14,
11858,
63,
2301,
360,
2913,
63,
5484,
297,
283,
521,
63,
3059,
63,
10274,
63,
3966,
297,
1709,
14,
4626,
8,
885,
29,
2083,
14,
2083,
8,
8664,
12,
1227,
12,
5851,
12,
3144,
12,
1749,
12,
959,
12,
6335,
1355,
2322,
1724,
2728,
327,
27854,
901,
283,
3834,
63,
4761,
4527,
63,
1931,
14,
521,
63,
3059,
63,
10274,
63,
3966,
7,
267,
1592,
14,
11858,
63,
2301,
360,
2913,
63,
1073,
63,
5468,
825,
3858,
80,
63,
1450,
297,
283,
521,
63,
3059,
63,
10274,
63,
3966,
297,
1709,
14,
4626,
8,
885,
29,
2083,
14,
2083,
8,
8664,
12,
1227,
12,
5851,
12,
3144,
12,
1749,
12,
959,
12,
7349,
1465,
1196,
1724,
268,
17635,
1709,
275,
469,
267,
283,
2913,
14,
5484,
356,
469,
288,
283,
344,
356,
661,
992,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
2019,
63,
2515,
1146,
356,
661,
992,
14,
4626,
297,
990,
791,
2307,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2019,
63,
31854,
356,
661,
992,
14,
4626,
297,
990,
8613,
288,
283,
354,
356,
661,
992,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1840,
1604,
288,
283,
2060,
63,
2227,
63,
1064,
21,
356,
661,
992,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1840,
1604,
288,
283,
6843,
63,
265,
63,
2184,
63,
2520,
63,
1345,
356,
661,
992,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
521,
63,
3059,
63,
10274,
63,
3966,
356,
661,
992,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
8,
8664,
12,
1227,
12,
5851,
12,
3144,
12,
3144,
12,
13564,
12,
841,
1184,
7920,
9,
1604,
288,
283,
2473,
356,
661,
992,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1840,
3071,
267,
1660,
267,
283,
2913,
14,
1450,
356,
469,
288,
283,
344,
356,
661,
992,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
505,
356,
661,
992,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
1604,
288,
283,
466,
356,
661,
992,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
283,
2913,
14,
1073,
63,
5468,
825,
3858,
80,
63,
1450,
356,
469,
288,
283,
344,
356,
661,
992,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
1715,
63,
1474,
356,
661,
992,
14,
3190,
297,
2097,
1025,
459,
2913,
14,
4761,
4527,
418,
2255,
8613,
288,
283,
1365,
356,
661,
992,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1840,
1604,
288,
283,
1450,
356,
661,
992,
14,
3190,
297,
2097,
1025,
459,
2913,
14,
1931,
418,
2255,
8613,
288,
283,
521,
63,
3059,
63,
10274,
63,
3966,
356,
661,
992,
14,
4626
] |
[
961,
570,
365,
1777,
402,
3232,
40,
693,
14,
199,
3,
1898,
334,
35,
9,
8937,
3232,
40,
693,
12,
3277,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
3002,
2124,
14,
2913,
14,
992,
492,
627,
199,
199,
533,
12090,
26,
2286,
347,
17465,
8,
277,
12,
9813,
304,
2728,
327,
12934,
1402,
283,
1931,
804,
7,
267,
1592,
14,
981,
63,
1224,
360,
2913,
63,
1450,
466,
297,
334,
288,
661,
344,
297,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
1826,
288,
661,
1861,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1165,
1826,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
360,
2913,
297,
788,
1931,
804,
1105,
2728,
327,
15920,
1402,
283,
1450,
1313,
7,
267,
1592,
14,
1807,
63,
1224,
360,
2913,
63,
1450,
1313,
358,
2728,
327,
27854,
901,
283,
7344,
14,
521,
63,
3059,
63,
10274,
63,
3966,
7,
267,
1592,
14,
11858,
63,
2301,
360,
2913,
63,
5484,
297,
283,
521,
63,
3059,
63,
10274,
63,
3966,
297,
1709,
14,
4626,
8,
885,
29,
2083,
14,
2083,
8,
8664,
12,
1227,
12,
5851,
12,
3144,
12,
3144,
12,
14589,
12,
1227,
10143,
2658,
1724,
2728,
327,
27854,
901,
283,
3834,
63,
4761,
4527,
63,
1931,
14,
521,
63,
3059,
63,
10274,
63,
3966,
7,
267,
1592,
14,
11858,
63,
2301,
360,
2913,
63,
1073,
63,
5468,
825,
3858,
80,
63,
1450,
297,
283,
521,
63,
3059,
63,
10274,
63,
3966,
297,
1709,
14,
4626,
8,
885,
29,
2083,
14,
2083,
8,
8664,
12,
1227,
12,
5851,
12,
3144,
12,
3144,
12,
13564,
12,
841,
1229,
383,
1724,
268,
17635,
347,
8552,
8,
277,
12,
9813,
304,
2728,
327,
15920,
1402,
283,
1931,
804,
7,
267,
1592,
14,
1807,
63,
1224,
360,
2913,
63,
1450,
466,
358,
2728,
327,
12934,
1402,
283,
1450,
1313,
7,
267,
1592,
14,
981,
63,
1224,
360,
2913,
63,
1450,
1313,
297,
334,
288,
661,
1861,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1165,
1826,
288,
661,
344,
297,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
1826,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
360,
2913,
297,
788,
1450,
1313,
1105,
2728,
327,
27854,
901,
283,
7344,
14,
521,
63,
3059,
63,
10274,
63,
3966,
7,
267,
1592,
14,
11858,
63,
2301,
360,
2913,
63,
5484,
297,
283,
521,
63,
3059,
63,
10274,
63,
3966,
297,
1709,
14,
4626,
8,
885,
29,
2083,
14,
2083,
8,
8664,
12,
1227,
12,
5851,
12,
3144,
12,
1749,
12,
959,
12,
6335,
1355,
2322,
1724,
2728,
327,
27854,
901,
283,
3834,
63,
4761,
4527,
63,
1931,
14,
521,
63,
3059,
63,
10274,
63,
3966,
7,
267,
1592,
14,
11858,
63,
2301,
360,
2913,
63,
1073,
63,
5468,
825,
3858,
80,
63,
1450,
297,
283,
521,
63,
3059,
63,
10274,
63,
3966,
297,
1709,
14,
4626,
8,
885,
29,
2083,
14,
2083,
8,
8664,
12,
1227,
12,
5851,
12,
3144,
12,
1749,
12,
959,
12,
7349,
1465,
1196,
1724,
268,
17635,
1709,
275,
469,
267,
283,
2913,
14,
5484,
356,
469,
288,
283,
344,
356,
661,
992,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
2019,
63,
2515,
1146,
356,
661,
992,
14,
4626,
297,
990,
791,
2307,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2019,
63,
31854,
356,
661,
992,
14,
4626,
297,
990,
8613,
288,
283,
354,
356,
661,
992,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1840,
1604,
288,
283,
2060,
63,
2227,
63,
1064,
21,
356,
661,
992,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1840,
1604,
288,
283,
6843,
63,
265,
63,
2184,
63,
2520,
63,
1345,
356,
661,
992,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
521,
63,
3059,
63,
10274,
63,
3966,
356,
661,
992,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
8,
8664,
12,
1227,
12,
5851,
12,
3144,
12,
3144,
12,
13564,
12,
841,
1184,
7920,
9,
1604,
288,
283,
2473,
356,
661,
992,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1840,
3071,
267,
1660,
267,
283,
2913,
14,
1450,
356,
469,
288,
283,
344,
356,
661,
992,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
505,
356,
661,
992,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
1604,
288,
283,
466,
356,
661,
992,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
283,
2913,
14,
1073,
63,
5468,
825,
3858,
80,
63,
1450,
356,
469,
288,
283,
344,
356,
661,
992,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
1715,
63,
1474,
356,
661,
992,
14,
3190,
297,
2097,
1025,
459,
2913,
14,
4761,
4527,
418,
2255,
8613,
288,
283,
1365,
356,
661,
992,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1840,
1604,
288,
283,
1450,
356,
661,
992,
14,
3190,
297,
2097,
1025,
459,
2913,
14,
1931,
418,
2255,
8613,
288,
283,
521,
63,
3059,
63,
10274,
63,
3966,
356,
661,
992,
14,
4626,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
endlessm/chromium-browser
|
third_party/catapult/third_party/gsutil/gslib/tests/test_tabcomplete.py
|
5
|
14512
|
# -*- coding: utf-8 -*-
# Copyright 2014 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Integration tests for tab completion."""
from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
from __future__ import unicode_literals
import os
import time
from gslib.command import CreateOrGetGsutilLogger
from gslib.tab_complete import CloudObjectCompleter
from gslib.tab_complete import TAB_COMPLETE_CACHE_TTL
from gslib.tab_complete import TabCompletionCache
import gslib.tests.testcase as testcase
from gslib.tests.util import ARGCOMPLETE_AVAILABLE
from gslib.tests.util import SetBotoConfigForTest
from gslib.tests.util import unittest
from gslib.tests.util import WorkingDirectory
from gslib.utils.boto_util import GetTabCompletionCacheFilename
@unittest.skipUnless(ARGCOMPLETE_AVAILABLE,
'Tab completion requires argcomplete')
class TestTabComplete(testcase.GsUtilIntegrationTestCase):
"""Integration tests for tab completion."""
def setUp(self):
super(TestTabComplete, self).setUp()
self.logger = CreateOrGetGsutilLogger('tab_complete')
def test_single_bucket(self):
"""Tests tab completion matching a single bucket."""
# Prefix is a workaround for XML API limitation, see PR 766 for details
bucket_name = self.MakeTempName('bucket', prefix='aaa-')
self.CreateBucket(bucket_name)
request = '%s://%s' % (self.default_provider, bucket_name[:-2])
expected_result = '//%s/' % bucket_name
self.RunGsUtilTabCompletion(['ls', request],
expected_results=[expected_result])
def test_bucket_only_single_bucket(self):
"""Tests bucket-only tab completion matching a single bucket."""
bucket_name = self.MakeTempName('bucket', prefix='aaa-')
# Workaround for XML API limitation, see PR 766 for details
self.CreateBucket(bucket_name)
request = '%s://%s' % (self.default_provider, bucket_name[:-2])
expected_result = '//%s ' % bucket_name
self.RunGsUtilTabCompletion(['rb', request],
expected_results=[expected_result])
def test_bucket_only_no_objects(self):
"""Tests that bucket-only tab completion doesn't match objects."""
object_name = self.MakeTempName('obj')
object_uri = self.CreateObject(object_name=object_name, contents=b'data')
request = '%s://%s/%s' % (self.default_provider, object_uri.bucket_name,
object_name[:-2])
self.RunGsUtilTabCompletion(['rb', request], expected_results=[])
def test_single_subdirectory(self):
"""Tests tab completion matching a single subdirectory."""
object_base_name = self.MakeTempName('obj')
object_name = object_base_name + '/subobj'
object_uri = self.CreateObject(object_name=object_name, contents=b'data')
request = '%s://%s/' % (self.default_provider, object_uri.bucket_name)
expected_result = '//%s/%s/' % (object_uri.bucket_name, object_base_name)
self.RunGsUtilTabCompletion(['ls', request],
expected_results=[expected_result])
def test_multiple_buckets(self):
"""Tests tab completion matching multiple buckets."""
base_name = self.MakeTempName('bucket')
# Workaround for XML API limitation, see PR 766 for details
prefix = 'aaa-'
self.CreateBucket(base_name,
bucket_name_prefix=prefix,
bucket_name_suffix='1')
self.CreateBucket(base_name,
bucket_name_prefix=prefix,
bucket_name_suffix='2')
request = '%s://%s' % (self.default_provider, ''.join([prefix, base_name]))
expected_result1 = '//%s/' % ''.join([prefix, base_name, '1'])
expected_result2 = '//%s/' % ''.join([prefix, base_name, '2'])
self.RunGsUtilTabCompletion(
['ls', request], expected_results=[expected_result1, expected_result2])
def test_single_object(self):
"""Tests tab completion matching a single object."""
object_name = self.MakeTempName('obj')
object_uri = self.CreateObject(object_name=object_name, contents=b'data')
request = '%s://%s/%s' % (self.default_provider, object_uri.bucket_name,
object_name[:-2])
expected_result = '//%s/%s ' % (object_uri.bucket_name, object_name)
self.RunGsUtilTabCompletion(['ls', request],
expected_results=[expected_result])
def test_multiple_objects(self):
"""Tests tab completion matching multiple objects."""
bucket_uri = self.CreateBucket()
object_base_name = self.MakeTempName('obj')
object1_name = object_base_name + '-suffix1'
self.CreateObject(bucket_uri=bucket_uri,
object_name=object1_name,
contents=b'data')
object2_name = object_base_name + '-suffix2'
self.CreateObject(bucket_uri=bucket_uri,
object_name=object2_name,
contents=b'data')
request = '%s://%s/%s' % (self.default_provider, bucket_uri.bucket_name,
object_base_name)
expected_result1 = '//%s/%s' % (bucket_uri.bucket_name, object1_name)
expected_result2 = '//%s/%s' % (bucket_uri.bucket_name, object2_name)
self.RunGsUtilTabCompletion(
['ls', request], expected_results=[expected_result1, expected_result2])
def test_subcommands(self):
"""Tests tab completion for commands with subcommands."""
bucket_name = self.MakeTempName('bucket', prefix='aaa-')
self.CreateBucket(bucket_name)
bucket_request = '%s://%s' % (self.default_provider, bucket_name[:-2])
expected_bucket_result = '//%s ' % bucket_name
local_file = 'a_local_file'
local_dir = self.CreateTempDir(test_files=[local_file])
local_file_request = '%s%s' % (local_dir, os.sep)
expected_local_file_result = '%s ' % os.path.join(local_dir, local_file)
# Should invoke Cloud bucket URL completer.
self.RunGsUtilTabCompletion(['cors', 'get', bucket_request],
expected_results=[expected_bucket_result])
# Should invoke File URL completer which should match the local file.
self.RunGsUtilTabCompletion(['cors', 'set', local_file_request],
expected_results=[expected_local_file_result])
# Should invoke Cloud bucket URL completer.
self.RunGsUtilTabCompletion(['cors', 'set', 'some_file', bucket_request],
expected_results=[expected_bucket_result])
def test_invalid_partial_bucket_name(self):
"""Tests tab completion with a partial URL that by itself is not valid.
The bucket name in a Cloud URL cannot end in a dash, but a partial URL
during tab completion may end in a dash and completion should still work.
"""
bucket_base_name = self.MakeTempName('bucket', prefix='aaa-')
bucket_name = bucket_base_name + '-s'
self.CreateBucket(bucket_name)
request = '%s://%s-' % (self.default_provider, bucket_base_name)
expected_result = '//%s/' % bucket_name
self.RunGsUtilTabCompletion(['ls', request],
expected_results=[expected_result])
def test_acl_argument(self):
"""Tests tab completion for ACL arguments."""
local_file = 'a_local_file'
local_dir = self.CreateTempDir(test_files=[local_file])
local_file_request = '%s%s' % (local_dir, os.sep)
expected_local_file_result = '%s ' % os.path.join(local_dir, local_file)
# Should invoke File URL completer which should match the local file.
self.RunGsUtilTabCompletion(['acl', 'set', local_file_request],
expected_results=[expected_local_file_result])
# Should match canned ACL name.
self.RunGsUtilTabCompletion(['acl', 'set', 'priv'],
expected_results=['private '])
local_file = 'priv_file'
local_dir = self.CreateTempDir(test_files=[local_file])
with WorkingDirectory(local_dir):
# Should match both a file and a canned ACL since argument takes
# either one.
self.RunGsUtilTabCompletion(['acl', 'set', 'priv'],
expected_results=[local_file, 'private'])
def _WriteTabCompletionCache(prefix,
results,
timestamp=None,
partial_results=False):
if timestamp is None:
timestamp = time.time()
cache = TabCompletionCache(prefix, results, timestamp, partial_results)
cache.WriteToFile(GetTabCompletionCacheFilename())
@unittest.skipUnless(ARGCOMPLETE_AVAILABLE,
'Tab completion requires argcomplete')
class TestTabCompleteUnitTests(testcase.unit_testcase.GsUtilUnitTestCase):
"""Unit tests for tab completion."""
def test_cached_results(self):
"""Tests tab completion results returned from cache."""
with SetBotoConfigForTest([('GSUtil', 'state_dir', self.CreateTempDir())]):
request = 'gs://prefix'
cached_results = ['gs://prefix1', 'gs://prefix2']
_WriteTabCompletionCache(request, cached_results)
completer = CloudObjectCompleter(self.MakeGsUtilApi())
results = completer(request)
self.assertEqual(cached_results, results)
def test_expired_cached_results(self):
"""Tests tab completion results not returned from cache when too old."""
with SetBotoConfigForTest([('GSUtil', 'state_dir', self.CreateTempDir())]):
bucket_base_name = self.MakeTempName('bucket')
bucket_name = bucket_base_name + '-suffix'
self.CreateBucket(bucket_name)
request = '%s://%s' % (self.default_provider, bucket_base_name)
expected_result = '%s://%s/' % (self.default_provider, bucket_name)
cached_results = ['//%s1' % bucket_name, '//%s2' % bucket_name]
_WriteTabCompletionCache(request, cached_results,
time.time() - TAB_COMPLETE_CACHE_TTL)
completer = CloudObjectCompleter(self.MakeGsUtilApi())
results = completer(request)
self.assertEqual([expected_result], results)
def test_prefix_caching(self):
"""Tests tab completion results returned from cache with prefix match.
If the tab completion prefix is an extension of the cached prefix, tab
completion should return results from the cache that start with the prefix.
"""
with SetBotoConfigForTest([('GSUtil', 'state_dir', self.CreateTempDir())]):
cached_prefix = 'gs://prefix'
cached_results = ['gs://prefix-first', 'gs://prefix-second']
_WriteTabCompletionCache(cached_prefix, cached_results)
request = 'gs://prefix-f'
completer = CloudObjectCompleter(self.MakeGsUtilApi())
results = completer(request)
self.assertEqual(['gs://prefix-first'], results)
def test_prefix_caching_boundary(self):
"""Tests tab completion prefix caching not spanning directory boundaries.
If the tab completion prefix is an extension of the cached prefix, but is
not within the same bucket/sub-directory then the cached results should not
be used.
"""
with SetBotoConfigForTest([('GSUtil', 'state_dir', self.CreateTempDir())]):
object_uri = self.CreateObject(object_name='subdir/subobj',
contents=b'test data')
cached_prefix = '%s://%s/' % (self.default_provider,
object_uri.bucket_name)
cached_results = [
'%s://%s/subdir' % (self.default_provider, object_uri.bucket_name)
]
_WriteTabCompletionCache(cached_prefix, cached_results)
request = '%s://%s/subdir/' % (self.default_provider,
object_uri.bucket_name)
expected_result = '%s://%s/subdir/subobj' % (self.default_provider,
object_uri.bucket_name)
completer = CloudObjectCompleter(self.MakeGsUtilApi())
results = completer(request)
self.assertEqual([expected_result], results)
def test_prefix_caching_no_results(self):
"""Tests tab completion returning empty result set using cached prefix.
If the tab completion prefix is an extension of the cached prefix, but does
not match any of the cached results then no remote request should be made
and an empty result set should be returned.
"""
with SetBotoConfigForTest([('GSUtil', 'state_dir', self.CreateTempDir())]):
object_uri = self.CreateObject(object_name='obj', contents=b'test data')
cached_prefix = '%s://%s/' % (self.default_provider,
object_uri.bucket_name)
cached_results = []
_WriteTabCompletionCache(cached_prefix, cached_results)
request = '%s://%s/o' % (self.default_provider, object_uri.bucket_name)
completer = CloudObjectCompleter(self.MakeGsUtilApi())
results = completer(request)
self.assertEqual([], results)
def test_prefix_caching_partial_results(self):
"""Tests tab completion prefix matching ignoring partial cached results.
If the tab completion prefix is an extension of the cached prefix, but the
cached result set is partial, the cached results should not be used because
the matching results for the prefix may be incomplete.
"""
with SetBotoConfigForTest([('GSUtil', 'state_dir', self.CreateTempDir())]):
object_uri = self.CreateObject(object_name='obj', contents=b'test data')
cached_prefix = '%s://%s/' % (self.default_provider,
object_uri.bucket_name)
cached_results = []
_WriteTabCompletionCache(cached_prefix,
cached_results,
partial_results=True)
request = '%s://%s/o' % (self.default_provider, object_uri.bucket_name)
completer = CloudObjectCompleter(self.MakeGsUtilApi())
results = completer(request)
self.assertEqual([str(object_uri)], results)
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
6927,
4475,
3277,
14,
221,
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,
624,
20405,
2295,
367,
5174,
13659,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
747,
199,
646,
900,
199,
199,
504,
29563,
14,
1531,
492,
2790,
2844,
1002,
32394,
1974,
4455,
199,
504,
29563,
14,
2902,
63,
4883,
492,
8142,
1692,
6600,
351,
199,
504,
29563,
14,
2902,
63,
4883,
492,
17916,
63,
15558,
63,
8677,
63,
25567,
199,
504,
29563,
14,
2902,
63,
4883,
492,
23159,
19741,
4437,
199,
646,
29563,
14,
2219,
14,
10847,
465,
16228,
199,
504,
29563,
14,
2219,
14,
1974,
492,
4160,
39,
15558,
63,
17377,
199,
504,
29563,
14,
2219,
14,
1974,
492,
2494,
20380,
2028,
1858,
774,
199,
504,
29563,
14,
2219,
14,
1974,
492,
2882,
199,
504,
29563,
14,
2219,
14,
1974,
492,
9361,
316,
6231,
199,
504,
29563,
14,
1208,
14,
10914,
63,
1974,
492,
2372,
7690,
19741,
4437,
8117,
421,
199,
32,
2796,
14,
11278,
8,
11611,
15558,
63,
17377,
12,
2151,
283,
7690,
13659,
5074,
1680,
4883,
358,
199,
533,
1379,
7690,
14175,
8,
10847,
14,
32394,
9562,
20405,
1746,
304,
523,
408,
20405,
2295,
367,
5174,
13659,
1041,
819,
347,
3613,
8,
277,
304,
272,
1613,
8,
774,
7690,
14175,
12,
291,
680,
5996,
342,
272,
291,
14,
2921,
275,
2790,
2844,
1002,
32394,
1974,
4455,
360,
2902,
63,
4883,
358,
819,
347,
511,
63,
4780,
63,
4623,
8,
277,
304,
272,
408,
2925,
5174,
13659,
4877,
282,
2849,
5315,
1041,
339,
327,
25110,
365,
282,
18092,
367,
4692,
3261,
12305,
12,
1937,
12218,
1520,
1272,
367,
2436,
272,
5315,
63,
354,
275,
291,
14,
5483,
6530,
985,
360,
4623,
297,
2403,
534,
11629,
25815,
272,
291,
14,
2499,
12311,
8,
4623,
63,
354,
9,
339,
1056,
275,
1543,
83,
13827,
83,
7,
450,
334,
277,
14,
885,
63,
3780,
12,
5315,
63,
354,
4439,
18,
566,
272,
1420,
63,
1099,
275,
18290,
5,
83,
4805,
450,
5315,
63,
354,
339,
291,
14,
2540,
32394,
9562,
7690,
19741,
2941,
478,
297,
1056,
467,
1816,
1420,
63,
2604,
1524,
2062,
63,
1099,
566,
819,
347,
511,
63,
4623,
63,
2118,
63,
4780,
63,
4623,
8,
277,
304,
272,
408,
2925,
5315,
13,
2118,
5174,
13659,
4877,
282,
2849,
5315,
1041,
339,
5315,
63,
354,
275,
291,
14,
5483,
6530,
985,
360,
4623,
297,
2403,
534,
11629,
25815,
272,
327,
9361,
11659,
367,
4692,
3261,
12305,
12,
1937,
12218,
1520,
1272,
367,
2436,
272,
291,
14,
2499,
12311,
8,
4623,
63,
354,
9,
339,
1056,
275,
1543,
83,
13827,
83,
7,
450,
334,
277,
14,
885,
63,
3780,
12,
5315,
63,
354,
4439,
18,
566,
272,
1420,
63,
1099,
275,
18290,
5,
83,
283,
450,
5315,
63,
354,
339,
291,
14,
2540,
32394,
9562,
7690,
19741,
2941,
4848,
297,
1056,
467,
1816,
1420,
63,
2604,
1524,
2062,
63,
1099,
566,
819,
347,
511,
63,
4623,
63,
2118,
63,
889,
63,
1462,
8,
277,
304,
272,
408,
2925,
626,
5315,
13,
2118,
5174,
13659,
3181,
1133,
1336,
2251,
1041,
339,
909,
63,
354,
275,
291,
14,
5483,
6530,
985,
360,
1113,
358,
272,
909,
63,
2302,
275,
291,
14,
2499,
1692,
8,
785,
63,
354,
29,
785,
63,
354,
12,
4072,
29,
66,
5121,
419,
358,
339,
1056,
275,
1543,
83,
13827,
83,
3149,
83,
7,
450,
334,
277,
14,
885,
63,
3780,
12,
909,
63,
2302,
14,
4623,
63,
354,
12,
2892,
909,
63,
354,
4439,
18,
566,
339,
291,
14,
2540,
32394,
9562,
7690,
19741,
2941,
4848,
297,
1056,
467,
1420,
63,
2604,
14285,
819,
347,
511,
63,
4780,
63,
954,
3619,
8,
277,
304,
272,
408,
2925,
5174,
13659,
4877,
282,
2849,
25094,
1041,
339,
909,
63,
1095,
63,
354,
275,
291,
14,
5483,
6530,
985,
360,
1113,
358,
272,
909,
63,
354,
275,
909,
63,
1095,
63,
354,
435,
1994,
954,
1113,
7,
272,
909,
63,
2302,
275,
291,
14,
2499,
1692,
8,
785,
63,
354,
29,
785,
63,
354,
12,
4072,
29,
66,
5121,
419,
358,
339,
1056,
275,
1543,
83,
13827,
83,
4805,
450,
334,
277,
14,
885,
63,
3780,
12,
909,
63,
2302,
14,
4623,
63,
354,
9,
272,
1420,
63,
1099,
275,
18290,
5,
83,
3149,
83,
4805,
450,
334,
785,
63,
2302,
14,
4623,
63,
354,
12,
909,
63,
1095,
63,
354,
9,
339,
291,
14,
2540,
32394,
9562,
7690,
19741,
2941,
478,
297,
1056,
467,
1816,
1420,
63,
2604,
1524,
2062,
63,
1099,
566,
819,
347,
511,
63,
6048,
63,
15065,
8,
277,
304,
272,
408,
2925,
5174,
13659,
4877,
3663,
18655,
1041,
339,
1300,
63,
354,
275,
291,
14,
5483,
6530,
985,
360,
4623,
358,
272,
327,
9361,
11659,
367,
4692,
3261,
12305,
12,
1937,
12218,
1520,
1272,
367,
2436,
272,
2403,
275,
283,
11629,
15668,
272,
291,
14,
2499,
12311,
8,
1095,
63,
354,
12,
1993,
5315,
63,
354,
63,
1861,
29,
1861,
12,
1993,
5315,
63,
354,
63,
4511,
534,
17,
358,
272,
291,
14,
2499,
12311,
8,
1095,
63,
354,
12,
1993,
5315,
63,
354,
63,
1861,
29,
1861,
12,
1993,
5315,
63,
354,
63,
4511,
534,
18,
358,
339,
1056,
275,
1543,
83,
13827,
83,
7,
450
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
6927,
4475,
3277,
14,
221,
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,
624,
20405,
2295,
367,
5174,
13659,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
747,
199,
646,
900,
199,
199,
504,
29563,
14,
1531,
492,
2790,
2844,
1002,
32394,
1974,
4455,
199,
504,
29563,
14,
2902,
63,
4883,
492,
8142,
1692,
6600,
351,
199,
504,
29563,
14,
2902,
63,
4883,
492,
17916,
63,
15558,
63,
8677,
63,
25567,
199,
504,
29563,
14,
2902,
63,
4883,
492,
23159,
19741,
4437,
199,
646,
29563,
14,
2219,
14,
10847,
465,
16228,
199,
504,
29563,
14,
2219,
14,
1974,
492,
4160,
39,
15558,
63,
17377,
199,
504,
29563,
14,
2219,
14,
1974,
492,
2494,
20380,
2028,
1858,
774,
199,
504,
29563,
14,
2219,
14,
1974,
492,
2882,
199,
504,
29563,
14,
2219,
14,
1974,
492,
9361,
316,
6231,
199,
504,
29563,
14,
1208,
14,
10914,
63,
1974,
492,
2372,
7690,
19741,
4437,
8117,
421,
199,
32,
2796,
14,
11278,
8,
11611,
15558,
63,
17377,
12,
2151,
283,
7690,
13659,
5074,
1680,
4883,
358,
199,
533,
1379,
7690,
14175,
8,
10847,
14,
32394,
9562,
20405,
1746,
304,
523,
408,
20405,
2295,
367,
5174,
13659,
1041,
819,
347,
3613,
8,
277,
304,
272,
1613,
8,
774,
7690,
14175,
12,
291,
680,
5996,
342,
272,
291,
14,
2921,
275,
2790,
2844,
1002,
32394,
1974,
4455,
360,
2902,
63,
4883,
358,
819,
347,
511,
63,
4780,
63,
4623,
8,
277,
304,
272,
408,
2925,
5174,
13659,
4877,
282,
2849,
5315,
1041,
339,
327,
25110,
365,
282,
18092,
367,
4692,
3261,
12305,
12,
1937,
12218,
1520,
1272,
367,
2436,
272,
5315,
63,
354,
275,
291,
14,
5483,
6530,
985,
360,
4623,
297,
2403,
534,
11629,
25815,
272,
291,
14,
2499,
12311,
8,
4623,
63,
354,
9,
339,
1056,
275,
1543,
83,
13827,
83,
7,
450,
334,
277,
14,
885,
63,
3780,
12,
5315,
63,
354,
4439,
18,
566,
272,
1420,
63,
1099,
275,
18290,
5,
83,
4805,
450,
5315,
63,
354,
339,
291,
14,
2540,
32394,
9562,
7690,
19741,
2941,
478,
297,
1056,
467,
1816,
1420,
63,
2604,
1524,
2062,
63,
1099,
566,
819,
347,
511,
63,
4623,
63,
2118,
63,
4780,
63,
4623,
8,
277,
304,
272,
408,
2925,
5315,
13,
2118,
5174,
13659,
4877,
282,
2849,
5315,
1041,
339,
5315,
63,
354,
275,
291,
14,
5483,
6530,
985,
360,
4623,
297,
2403,
534,
11629,
25815,
272,
327,
9361,
11659,
367,
4692,
3261,
12305,
12,
1937,
12218,
1520,
1272,
367,
2436,
272,
291,
14,
2499,
12311,
8,
4623,
63,
354,
9,
339,
1056,
275,
1543,
83,
13827,
83,
7,
450,
334,
277,
14,
885,
63,
3780,
12,
5315,
63,
354,
4439,
18,
566,
272,
1420,
63,
1099,
275,
18290,
5,
83,
283,
450,
5315,
63,
354,
339,
291,
14,
2540,
32394,
9562,
7690,
19741,
2941,
4848,
297,
1056,
467,
1816,
1420,
63,
2604,
1524,
2062,
63,
1099,
566,
819,
347,
511,
63,
4623,
63,
2118,
63,
889,
63,
1462,
8,
277,
304,
272,
408,
2925,
626,
5315,
13,
2118,
5174,
13659,
3181,
1133,
1336,
2251,
1041,
339,
909,
63,
354,
275,
291,
14,
5483,
6530,
985,
360,
1113,
358,
272,
909,
63,
2302,
275,
291,
14,
2499,
1692,
8,
785,
63,
354,
29,
785,
63,
354,
12,
4072,
29,
66,
5121,
419,
358,
339,
1056,
275,
1543,
83,
13827,
83,
3149,
83,
7,
450,
334,
277,
14,
885,
63,
3780,
12,
909,
63,
2302,
14,
4623,
63,
354,
12,
2892,
909,
63,
354,
4439,
18,
566,
339,
291,
14,
2540,
32394,
9562,
7690,
19741,
2941,
4848,
297,
1056,
467,
1420,
63,
2604,
14285,
819,
347,
511,
63,
4780,
63,
954,
3619,
8,
277,
304,
272,
408,
2925,
5174,
13659,
4877,
282,
2849,
25094,
1041,
339,
909,
63,
1095,
63,
354,
275,
291,
14,
5483,
6530,
985,
360,
1113,
358,
272,
909,
63,
354,
275,
909,
63,
1095,
63,
354,
435,
1994,
954,
1113,
7,
272,
909,
63,
2302,
275,
291,
14,
2499,
1692,
8,
785,
63,
354,
29,
785,
63,
354,
12,
4072,
29,
66,
5121,
419,
358,
339,
1056,
275,
1543,
83,
13827,
83,
4805,
450,
334,
277,
14,
885,
63,
3780,
12,
909,
63,
2302,
14,
4623,
63,
354,
9,
272,
1420,
63,
1099,
275,
18290,
5,
83,
3149,
83,
4805,
450,
334,
785,
63,
2302,
14,
4623,
63,
354,
12,
909,
63,
1095,
63,
354,
9,
339,
291,
14,
2540,
32394,
9562,
7690,
19741,
2941,
478,
297,
1056,
467,
1816,
1420,
63,
2604,
1524,
2062,
63,
1099,
566,
819,
347,
511,
63,
6048,
63,
15065,
8,
277,
304,
272,
408,
2925,
5174,
13659,
4877,
3663,
18655,
1041,
339,
1300,
63,
354,
275,
291,
14,
5483,
6530,
985,
360,
4623,
358,
272,
327,
9361,
11659,
367,
4692,
3261,
12305,
12,
1937,
12218,
1520,
1272,
367,
2436,
272,
2403,
275,
283,
11629,
15668,
272,
291,
14,
2499,
12311,
8,
1095,
63,
354,
12,
1993,
5315,
63,
354,
63,
1861,
29,
1861,
12,
1993,
5315,
63,
354,
63,
4511,
534,
17,
358,
272,
291,
14,
2499,
12311,
8,
1095,
63,
354,
12,
1993,
5315,
63,
354,
63,
1861,
29,
1861,
12,
1993,
5315,
63,
354,
63,
4511,
534,
18,
358,
339,
1056,
275,
1543,
83,
13827,
83,
7,
450,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
olsonanl/transform
|
plugins/scripts/taskrunners/trns_upload_Transform.Pair.py
|
15
|
2910
|
#!/usr/bin/env python
import argparse
import sys
import os
import time
import traceback
import sys
import ctypes
import subprocess
from subprocess import Popen, PIPE
import shutil
from optparse import OptionParser
from biokbase.workspace.client import Workspace
import urllib
import urllib2
import json
from biokbase import log
from biokbase.userandjobstate.client import UserAndJobState
from biokbase.Transform.util import Uploader
import datetime
desc1 = '''
NAME
trns_upload_Transform.Pair -- upload the input data into WS
SYNOPSIS
'''
desc2 = '''
DESCRIPTION
trns_upload_Transform.Pair upload the input data into WS
'''
desc3 = '''
EXAMPLES
CSV test case
> trns_upload_Transform.Pair --ws_url 'https://kbase.us/services/ws' --ws_id kbasetest:home --in_id '' --out_id 'my_tst_out'
SEE ALSO
trns_validate_hndlr, trns_import_hndlr
AUTHORS
First Last.
'''
if __name__ == "__main__":
# Parse options.
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, prog='trns_upload_Transform.Pair', epilog=desc3)
parser.add_argument('-u', '--ws_url', help='Workspace url', action='store', dest='ws_url', default='https://kbase.us/services/ws', required=True)
parser.add_argument('-w', '--dst_ws_name', help='Destination workspace name', action='store', dest='ws_id', default=None, required=True)
parser.add_argument('-o', '--out_id', help='Output workspace object name', action='store', dest='outobj_id', default=None, required=True)
parser.add_argument('-l', '--support_dir', help='Support directory', action='store', dest='sdir', default='lib', required=True)
parser.add_argument('-g', '--out_file', help='Output prefix or file name', action='store', dest='otmp', default='outfile', required=True)
# for meta data
parser.add_argument('-i', '--in_id', help='Input Shock node id for meta', action='store', dest='inobj_id', default='NotProvided', required=True)
parser.add_argument('-e', '--ext_type', help='External object type', action='store', dest='etype', default=None, required=True)
parser.add_argument('-j', '--job_id', help='UJS job id', action='store', dest='jid', default='NoJodID', required=False)
usage = parser.format_usage()
parser.description = desc1 + ' ' + usage + desc2
parser.usage = argparse.SUPPRESS
args = parser.parse_args()
kb_token = os.environ.get('KB_AUTH_TOKEN')
## main loop
jif = open("{}/{}".format(args.sdir,args.otmp, 'r'))
data = json.loads(jif.read())
jif.close()
wsd = Workspace(url=args.ws_url, token=kb_token)
wsd.save_objects({'workspace':args.ws_id, 'objects' : [ {
'type' : 'Transform.Pair', 'data' : data, 'name' : args.outobj_id,
'meta' : { 'source_id' : args.inobj_id, 'source_type' : args.etype,
'ujs_job_id' : args.jid} } ]})
exit(0);
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
7534,
199,
646,
984,
199,
646,
747,
199,
646,
900,
199,
646,
5190,
199,
646,
984,
199,
646,
5577,
199,
646,
3873,
199,
504,
3873,
492,
13995,
12,
22773,
199,
646,
5145,
199,
504,
8691,
492,
13491,
199,
504,
12111,
745,
1095,
14,
13249,
14,
1258,
492,
9361,
2638,
199,
646,
4011,
199,
646,
4011,
18,
199,
646,
2022,
199,
504,
12111,
745,
1095,
492,
943,
199,
504,
12111,
745,
1095,
14,
751,
460,
2423,
929,
14,
1258,
492,
2876,
3325,
6694,
2223,
199,
504,
12111,
745,
1095,
14,
6939,
14,
1974,
492,
4949,
3422,
199,
646,
2197,
199,
199,
3257,
17,
275,
1449,
199,
2339,
489,
5651,
561,
63,
5064,
63,
6939,
14,
12882,
1553,
5802,
314,
1324,
666,
1901,
644,
51,
199,
199,
31802,
21665,
1311,
755,
2126,
199,
2344,
199,
199,
3257,
18,
275,
1449,
199,
17705,
523,
5651,
561,
63,
5064,
63,
6939,
14,
12882,
5802,
314,
1324,
666,
1901,
644,
51,
2043,
199,
2344,
199,
199,
3257,
19,
275,
1449,
199,
8918,
489,
14689,
511,
1930,
489,
690,
5651,
561,
63,
5064,
63,
6939,
14,
12882,
1553,
3569,
63,
633,
283,
2859,
921,
75,
1095,
14,
527,
15,
5950,
15,
3569,
7,
1553,
3569,
63,
344,
1022,
1095,
396,
26,
4219,
221,
1553,
262,
63,
344,
2125,
1553,
548,
63,
344,
283,
1662,
63,
84,
270,
63,
548,
7,
2126,
199,
199,
899,
37,
12112,
4118,
489,
5651,
561,
63,
3502,
63,
72,
977,
7493,
12,
5651,
561,
63,
646,
63,
72,
977,
7493,
199,
199,
5580,
4149,
199,
7147,
15237,
14,
199,
2344,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
327,
6077,
1511,
14,
272,
1798,
275,
7534,
14,
10730,
8,
8911,
63,
533,
29,
18978,
14,
7963,
5831,
22779,
12,
13205,
534,
454,
561,
63,
5064,
63,
6939,
14,
12882,
297,
29850,
29,
3257,
19,
9,
272,
1798,
14,
525,
63,
2094,
3654,
85,
297,
2850,
3569,
63,
633,
297,
1720,
534,
21058,
1166,
297,
1595,
534,
1617,
297,
2053,
534,
3569,
63,
633,
297,
849,
534,
2859,
921,
75,
1095,
14,
527,
15,
5950,
15,
3569,
297,
1415,
29,
549,
9,
339,
1798,
14,
525,
63,
2094,
3654,
87,
297,
2850,
5119,
63,
3569,
63,
354,
297,
1720,
534,
13151,
14466,
536,
297,
1595,
534,
1617,
297,
2053,
534,
3569,
63,
344,
297,
849,
29,
403,
12,
1415,
29,
549,
9,
272,
1798,
14,
525,
63,
2094,
3654,
79,
297,
2850,
548,
63,
344,
297,
1720,
534,
2959,
14466,
909,
536,
297,
1595,
534,
1617,
297,
2053,
534,
548,
1113,
63,
344,
297,
849,
29,
403,
12,
1415,
29,
549,
9,
339,
1798,
14,
525,
63,
2094,
3654,
76,
297,
2850,
4058,
63,
694,
297,
1720,
534,
11532,
2082,
297,
1595,
534,
1617,
297,
2053,
534,
83,
694,
297,
849,
534,
773,
297,
1415,
29,
549,
9,
272,
1798,
14,
525,
63,
2094,
3654,
71,
297,
2850,
548,
63,
493,
297,
1720,
534,
2959,
2403,
503,
570,
536,
297,
1595,
534,
1617,
297,
2053,
534,
357,
311,
297,
849,
534,
4984,
297,
1415,
29,
549,
9,
272,
327,
367,
3404,
666,
272,
1798,
14,
525,
63,
2094,
3654,
73,
297,
2850,
262,
63,
344,
297,
1720,
534,
3205,
428,
526,
346,
1031,
1305,
367,
3404,
297,
1595,
534,
1617,
297,
2053,
534,
262,
1113,
63,
344,
297,
849,
534,
1763,
919,
11923,
297,
1415,
29,
549,
9,
272,
1798,
14,
525,
63,
2094,
3654,
69,
297,
2850,
832,
63,
466,
297,
1720,
534,
11389,
909,
730,
297,
1595,
534,
1617,
297,
2053,
534,
29232,
297,
849,
29,
403,
12,
1415,
29,
549,
9,
272,
1798,
14,
525,
63,
2094,
3654,
74,
297,
2850,
2423,
63,
344,
297,
1720,
534,
53,
11378,
3906,
1305,
297,
1595,
534,
1617,
297,
2053,
534,
14203,
297,
849,
534,
1944,
42,
364,
998,
297,
1415,
29,
797,
9,
339,
4503,
275,
1798,
14,
908,
63,
3807,
342,
272,
1798,
14,
1802,
275,
4328,
17,
435,
283,
420,
283,
435,
4503,
435,
4328,
18,
272,
1798,
14,
3807,
275,
7534,
14,
24023,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
25979,
19932,
63,
1418,
275,
747,
14,
2314,
14,
362,
360,
12780,
63,
5580,
63,
8803,
358,
339,
925,
2446,
4438,
272,
1335,
692,
275,
1551,
20794,
15,
13536,
908,
8,
589,
14,
83,
694,
12,
589,
14,
357,
311,
12,
283,
82,
1333,
272,
666,
275,
2022,
14,
3640,
8,
74,
692,
14,
739,
1012,
272,
1335,
692,
14,
1600,
342,
2286,
336,
3893,
275,
9361,
2638,
8,
633,
29,
589,
14,
3569,
63,
633,
12,
1526,
29,
7862,
63,
1418,
9,
272,
336,
3893,
14,
2117,
63,
1462,
3252,
13249,
356,
589,
14,
3569,
63,
344,
12,
283,
1462,
7,
520,
359,
469,
489,
283,
466,
7,
520,
283,
6939,
14,
12882,
297,
283,
576,
7,
520,
666,
12,
283,
354,
7,
520,
1249,
14,
548,
1113,
63,
344,
12,
15166,
283,
2024,
7,
520,
469,
283,
1365,
63,
344,
7,
520,
1249,
14,
262,
1113,
63,
344,
12,
283,
1365,
63,
466,
7,
520,
1249,
14,
29232,
12,
326,
283,
85,
3596,
63,
2423,
63,
344,
7,
520,
1249,
14,
14203,
93,
789,
1622,
1552,
1362,
339,
4458,
8,
16,
2736,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
7534,
199,
646,
984,
199,
646,
747,
199,
646,
900,
199,
646,
5190,
199,
646,
984,
199,
646,
5577,
199,
646,
3873,
199,
504,
3873,
492,
13995,
12,
22773,
199,
646,
5145,
199,
504,
8691,
492,
13491,
199,
504,
12111,
745,
1095,
14,
13249,
14,
1258,
492,
9361,
2638,
199,
646,
4011,
199,
646,
4011,
18,
199,
646,
2022,
199,
504,
12111,
745,
1095,
492,
943,
199,
504,
12111,
745,
1095,
14,
751,
460,
2423,
929,
14,
1258,
492,
2876,
3325,
6694,
2223,
199,
504,
12111,
745,
1095,
14,
6939,
14,
1974,
492,
4949,
3422,
199,
646,
2197,
199,
199,
3257,
17,
275,
1449,
199,
2339,
489,
5651,
561,
63,
5064,
63,
6939,
14,
12882,
1553,
5802,
314,
1324,
666,
1901,
644,
51,
199,
199,
31802,
21665,
1311,
755,
2126,
199,
2344,
199,
199,
3257,
18,
275,
1449,
199,
17705,
523,
5651,
561,
63,
5064,
63,
6939,
14,
12882,
5802,
314,
1324,
666,
1901,
644,
51,
2043,
199,
2344,
199,
199,
3257,
19,
275,
1449,
199,
8918,
489,
14689,
511,
1930,
489,
690,
5651,
561,
63,
5064,
63,
6939,
14,
12882,
1553,
3569,
63,
633,
283,
2859,
921,
75,
1095,
14,
527,
15,
5950,
15,
3569,
7,
1553,
3569,
63,
344,
1022,
1095,
396,
26,
4219,
221,
1553,
262,
63,
344,
2125,
1553,
548,
63,
344,
283,
1662,
63,
84,
270,
63,
548,
7,
2126,
199,
199,
899,
37,
12112,
4118,
489,
5651,
561,
63,
3502,
63,
72,
977,
7493,
12,
5651,
561,
63,
646,
63,
72,
977,
7493,
199,
199,
5580,
4149,
199,
7147,
15237,
14,
199,
2344,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
327,
6077,
1511,
14,
272,
1798,
275,
7534,
14,
10730,
8,
8911,
63,
533,
29,
18978,
14,
7963,
5831,
22779,
12,
13205,
534,
454,
561,
63,
5064,
63,
6939,
14,
12882,
297,
29850,
29,
3257,
19,
9,
272,
1798,
14,
525,
63,
2094,
3654,
85,
297,
2850,
3569,
63,
633,
297,
1720,
534,
21058,
1166,
297,
1595,
534,
1617,
297,
2053,
534,
3569,
63,
633,
297,
849,
534,
2859,
921,
75,
1095,
14,
527,
15,
5950,
15,
3569,
297,
1415,
29,
549,
9,
339,
1798,
14,
525,
63,
2094,
3654,
87,
297,
2850,
5119,
63,
3569,
63,
354,
297,
1720,
534,
13151,
14466,
536,
297,
1595,
534,
1617,
297,
2053,
534,
3569,
63,
344,
297,
849,
29,
403,
12,
1415,
29,
549,
9,
272,
1798,
14,
525,
63,
2094,
3654,
79,
297,
2850,
548,
63,
344,
297,
1720,
534,
2959,
14466,
909,
536,
297,
1595,
534,
1617,
297,
2053,
534,
548,
1113,
63,
344,
297,
849,
29,
403,
12,
1415,
29,
549,
9,
339,
1798,
14,
525,
63,
2094,
3654,
76,
297,
2850,
4058,
63,
694,
297,
1720,
534,
11532,
2082,
297,
1595,
534,
1617,
297,
2053,
534,
83,
694,
297,
849,
534,
773,
297,
1415,
29,
549,
9,
272,
1798,
14,
525,
63,
2094,
3654,
71,
297,
2850,
548,
63,
493,
297,
1720,
534,
2959,
2403,
503,
570,
536,
297,
1595,
534,
1617,
297,
2053,
534,
357,
311,
297,
849,
534,
4984,
297,
1415,
29,
549,
9,
272,
327,
367,
3404,
666,
272,
1798,
14,
525,
63,
2094,
3654,
73,
297,
2850,
262,
63,
344,
297,
1720,
534,
3205,
428,
526,
346,
1031,
1305,
367,
3404,
297,
1595,
534,
1617,
297,
2053,
534,
262,
1113,
63,
344,
297,
849,
534,
1763,
919,
11923,
297,
1415,
29,
549,
9,
272,
1798,
14,
525,
63,
2094,
3654,
69,
297,
2850,
832,
63,
466,
297,
1720,
534,
11389,
909,
730,
297,
1595,
534,
1617,
297,
2053,
534,
29232,
297,
849,
29,
403,
12,
1415,
29,
549,
9,
272,
1798,
14,
525,
63,
2094,
3654,
74,
297,
2850,
2423,
63,
344,
297,
1720,
534,
53,
11378,
3906,
1305,
297,
1595,
534,
1617,
297,
2053,
534,
14203,
297,
849,
534,
1944,
42,
364,
998,
297,
1415,
29,
797,
9,
339,
4503,
275,
1798,
14,
908,
63,
3807,
342,
272,
1798,
14,
1802,
275,
4328,
17,
435,
283,
420,
283,
435,
4503,
435,
4328,
18,
272,
1798,
14,
3807,
275,
7534,
14,
24023,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
25979,
19932,
63,
1418,
275,
747,
14,
2314,
14,
362,
360,
12780,
63,
5580,
63,
8803,
358,
339,
925,
2446,
4438,
272,
1335,
692,
275,
1551,
20794,
15,
13536,
908,
8,
589,
14,
83,
694,
12,
589,
14,
357,
311,
12,
283,
82,
1333,
272,
666,
275,
2022,
14,
3640,
8,
74,
692,
14,
739,
1012,
272,
1335,
692,
14,
1600,
342,
2286,
336,
3893,
275,
9361,
2638,
8,
633,
29,
589,
14,
3569,
63,
633,
12,
1526,
29,
7862,
63,
1418,
9,
272,
336,
3893,
14,
2117,
63,
1462,
3252,
13249,
356,
589,
14,
3569,
63,
344,
12,
283,
1462,
7,
520,
359,
469,
489,
283,
466,
7,
520,
283,
6939,
14,
12882,
297,
283,
576,
7,
520,
666,
12,
283,
354,
7,
520,
1249,
14,
548,
1113,
63,
344,
12,
15166,
283,
2024,
7,
520,
469,
283,
1365,
63,
344,
7,
520,
1249,
14,
262,
1113,
63,
344,
12,
283,
1365,
63,
466,
7,
520,
1249,
14,
29232,
12,
326,
283,
85,
3596,
63,
2423,
63,
344,
7,
520,
1249,
14,
14203,
93,
789,
1622,
1552,
1362,
339,
4458,
8,
16,
2736,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
Jigsaw-Code/net-analysis
|
netanalysis/ooni/data/fetch_measurements.py
|
1
|
4198
|
#!/usr/bin/python
#
# Copyright 2021 Jigsaw Operations LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import datetime as dt
from functools import singledispatch
import gzip
import logging
from multiprocessing.pool import ThreadPool
import os
import pathlib
import sys
from typing import List
import ujson
from . import ooni_client
@singledispatch
def trim_measurement(json_obj, max_string_size: int):
return json_obj
@trim_measurement.register(dict)
def _(json_dict: dict, max_string_size: int):
keys_to_delete: List[str] = []
for key, value in json_dict.items():
if type(value) == str and len(value) > max_string_size:
keys_to_delete.append(key)
else:
trim_measurement(value, max_string_size)
for key in keys_to_delete:
del json_dict[key]
return json_dict
@trim_measurement.register(list)
def _(json_list: list, max_string_size: int):
for item in json_list:
trim_measurement(item, max_string_size)
return json_list
class CostLimitError(Exception):
def __init__(self, message: str) -> None:
super().__init__(message)
def main(args):
logging.basicConfig(level=logging.INFO)
if args.debug:
logging.basicConfig(level=logging.DEBUG)
ooni = ooni_client.OoniClient()
num_measurements = 0
file_entries = ooni.list_files(
args.first_date, args.last_date, args.test_type, args.country)
def fetch_file(entry: ooni_client.FileEntry):
nonlocal num_measurements
basename = pathlib.PurePosixPath(entry.url.path).name
# Fix .json.lz4 and .tar.lz4 filenames.
if not basename.endswith('.jsonl.gz'):
basename = basename.rsplit('.', 2)[0] + '.jsonl.gz'
target_filename = args.output_dir / entry.country / \
f'{entry.date:%Y-%m-%d}' / basename
os.makedirs(target_filename.parent, exist_ok=True)
if ooni.cost_usd > args.cost_limit_usd:
raise CostLimitError(
f'Downloaded {ooni.bytes_downloaded / 2**20} MiB')
with gzip.open(target_filename, mode='wt', encoding='utf-8', newline='\n') as target_file:
for measurement in entry.get_measurements():
num_measurements += 1
m = trim_measurement(measurement, args.max_string_size)
ujson.dump(m, target_file)
target_file.write('\n')
return f'Downloaded {entry.url.geturl()} [{entry.size:,} bytes]'
with ThreadPool(processes=5 * os.cpu_count()) as sync_pool:
for msg in sync_pool.imap_unordered(fetch_file, file_entries):
logging.info(msg)
logging.info(f'Measurements: {num_measurements}, Downloaded {ooni.bytes_downloaded/2**20:0.3f} MiB, Estimated Cost: ${ooni.cost_usd:02f}')
def _parse_date_flag(date_str: str) -> dt.date:
return dt.datetime.strptime(date_str, "%Y-%m-%d").date()
if __name__ == "__main__":
parser = argparse.ArgumentParser("Fetch OONI measurements")
parser.add_argument("--country", type=str, required=True)
parser.add_argument("--first_date", type=_parse_date_flag,
default=dt.date.today() - dt.timedelta(days=14))
parser.add_argument("--last_date", type=_parse_date_flag,
default=dt.date.today())
parser.add_argument("--test_type", type=str, default='webconnectivity')
parser.add_argument("--max_string_size", type=int, default=1000)
parser.add_argument("--cost_limit_usd", type=float, default=1.00)
parser.add_argument("--output_dir", type=pathlib.Path, required=True)
parser.add_argument("--debug", action="store_true")
sys.exit(main(parser.parse_args()))
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
499,
15385,
1603,
73,
458,
10084,
29474,
20376,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
7534,
199,
646,
2197,
465,
4487,
199,
504,
9143,
492,
2849,
6052,
199,
646,
11756,
199,
646,
2050,
199,
504,
12866,
14,
2293,
492,
11086,
5453,
199,
646,
747,
199,
646,
32212,
199,
646,
984,
199,
504,
14090,
492,
3820,
199,
199,
646,
399,
1001,
199,
199,
504,
1275,
492,
312,
265,
73,
63,
1258,
421,
199,
32,
4780,
6052,
199,
318,
11639,
63,
17912,
8,
1001,
63,
1113,
12,
1390,
63,
875,
63,
890,
26,
1109,
304,
272,
372,
2022,
63,
1113,
421,
199,
32,
12263,
63,
17912,
14,
2683,
8,
807,
9,
199,
318,
12561,
1001,
63,
807,
26,
1211,
12,
1390,
63,
875,
63,
890,
26,
1109,
304,
272,
2883,
63,
475,
63,
1807,
26,
3820,
59,
495,
61,
275,
942,
272,
367,
790,
12,
574,
315,
2022,
63,
807,
14,
1744,
837,
267,
340,
730,
8,
585,
9,
508,
620,
436,
822,
8,
585,
9,
690,
1390,
63,
875,
63,
890,
26,
288,
2883,
63,
475,
63,
1807,
14,
740,
8,
498,
9,
267,
587,
26,
288,
11639,
63,
17912,
8,
585,
12,
1390,
63,
875,
63,
890,
9,
272,
367,
790,
315,
2883,
63,
475,
63,
1807,
26,
267,
2150,
2022,
63,
807,
59,
498,
61,
272,
372,
2022,
63,
807,
421,
199,
32,
12263,
63,
17912,
14,
2683,
8,
513,
9,
199,
318,
12561,
1001,
63,
513,
26,
769,
12,
1390,
63,
875,
63,
890,
26,
1109,
304,
272,
367,
1242,
315,
2022,
63,
513,
26,
267,
11639,
63,
17912,
8,
1053,
12,
1390,
63,
875,
63,
890,
9,
272,
372,
2022,
63,
513,
421,
199,
533,
24681,
8407,
547,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
1245,
26,
620,
9,
1035,
488,
26,
267,
1613,
11027,
826,
721,
1188,
9,
421,
199,
318,
2446,
8,
589,
304,
272,
2050,
14,
19602,
8,
1896,
29,
4806,
14,
4531,
9,
272,
340,
1249,
14,
1757,
26,
267,
2050,
14,
19602,
8,
1896,
29,
4806,
14,
5287,
9,
339,
312,
265,
73,
275,
312,
265,
73,
63,
1258,
14,
47,
265,
73,
3041,
342,
272,
1967,
63,
30264,
275,
378,
272,
570,
63,
3189,
275,
312,
265,
73,
14,
513,
63,
1725,
8,
267,
1249,
14,
2246,
63,
602,
12,
1249,
14,
2019,
63,
602,
12,
1249,
14,
396,
63,
466,
12,
1249,
14,
6063,
9,
339,
347,
5267,
63,
493,
8,
2373,
26,
312,
265,
73,
63,
1258,
14,
1173,
3900,
304,
267,
2222,
1832,
1967,
63,
30264,
267,
9593,
275,
32212,
14,
28928,
1575,
4174,
2042,
8,
2373,
14,
633,
14,
515,
680,
354,
267,
327,
14811,
1275,
1001,
14,
28997,
20,
436,
1275,
5369,
14,
28997,
20,
6203,
14,
267,
340,
440,
9593,
14,
4130,
5175,
1001,
76,
14,
6838,
735,
288,
9593,
275,
9593,
14,
13490,
14078,
499,
2788,
16,
61,
435,
1987,
1001,
76,
14,
6838,
7,
398,
1347,
63,
1501,
275,
1249,
14,
1199,
63,
694,
1182,
2397,
14,
6063,
1182,
971,
288,
289,
16019,
2373,
14,
602,
2689,
57,
3295,
77,
3295,
68,
6834,
1182,
9593,
267,
747,
14,
8347,
8,
1375,
63,
1501,
14,
1708,
12,
2187,
63,
745,
29,
549,
9,
267,
340,
312,
265,
73,
14,
6336,
63,
31597,
690,
1249,
14,
6336,
63,
3097,
63,
31597,
26,
288,
746,
24681,
8407,
547,
8,
355,
289,
7,
3514,
4591,
469,
79,
265,
73,
14,
2394,
63,
19385,
1182,
499,
538,
1165,
93,
603,
17587,
358,
267,
543,
11756,
14,
1490,
8,
1375,
63,
1501,
12,
818,
534,
9115,
297,
2644,
534,
1624,
13,
24,
297,
8057,
17115,
78,
358,
465,
1347,
63,
493,
26,
288,
367,
18216,
315,
2397,
14,
362,
63,
30264,
837,
355,
1967,
63,
30264,
847,
413,
355,
333,
275,
11639,
63,
17912,
8,
17912,
12,
1249,
14,
988,
63,
875,
63,
890,
9,
355,
399,
1001,
14,
2724,
8,
77,
12,
1347,
63,
493,
9,
355,
1347,
63,
493,
14,
952,
2258,
78,
358,
267,
372,
289,
7,
3514,
4591,
469,
2373,
14,
633,
14,
32130,
12737,
8910,
2373,
14,
890,
11941,
93,
2783,
6616,
339,
543,
11086,
5453,
8,
11816,
29,
21,
627,
747,
14,
3541,
63,
835,
1012,
465,
7604,
63,
2293,
26,
267,
367,
1499,
315,
7604,
63,
2293,
14,
15311,
63,
24182,
8,
3535,
63,
493,
12,
570,
63,
3189,
304,
288,
2050,
14,
815,
8,
1328,
9,
339,
2050,
14,
815,
8,
70,
7,
18611,
1470,
26,
469,
1507,
63,
30264,
1386,
13392,
4591,
469,
79,
265,
73,
14,
2394,
63,
19385,
15,
18,
538,
1165,
26,
16,
14,
19,
70,
93,
603,
17587,
12,
15896,
12754,
24681,
26,
10839,
79,
265,
73,
14,
6336,
63,
31597,
26,
996,
70,
12216,
421,
199,
318,
485,
1122,
63,
602,
63,
4173,
8,
602,
63,
495,
26,
620,
9,
1035,
4487,
14,
602,
26,
272,
372,
4487,
14,
2083,
14,
9866,
8,
602,
63,
495,
12,
2071,
57,
3295,
77,
3295,
68,
3471,
602,
342,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1798,
275,
7534,
14,
10730,
480,
11135,
593,
615,
41,
32619,
531,
272,
1798,
14,
525,
63,
2094,
6739,
6063,
401,
730,
29,
495,
12,
1415,
29,
549,
9,
272,
1798,
14,
525,
63,
2094,
6739,
2246,
63,
602,
401,
730,
3699,
1122,
63,
602,
63,
4173,
12,
717,
849,
29
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
499,
15385,
1603,
73,
458,
10084,
29474,
20376,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
7534,
199,
646,
2197,
465,
4487,
199,
504,
9143,
492,
2849,
6052,
199,
646,
11756,
199,
646,
2050,
199,
504,
12866,
14,
2293,
492,
11086,
5453,
199,
646,
747,
199,
646,
32212,
199,
646,
984,
199,
504,
14090,
492,
3820,
199,
199,
646,
399,
1001,
199,
199,
504,
1275,
492,
312,
265,
73,
63,
1258,
421,
199,
32,
4780,
6052,
199,
318,
11639,
63,
17912,
8,
1001,
63,
1113,
12,
1390,
63,
875,
63,
890,
26,
1109,
304,
272,
372,
2022,
63,
1113,
421,
199,
32,
12263,
63,
17912,
14,
2683,
8,
807,
9,
199,
318,
12561,
1001,
63,
807,
26,
1211,
12,
1390,
63,
875,
63,
890,
26,
1109,
304,
272,
2883,
63,
475,
63,
1807,
26,
3820,
59,
495,
61,
275,
942,
272,
367,
790,
12,
574,
315,
2022,
63,
807,
14,
1744,
837,
267,
340,
730,
8,
585,
9,
508,
620,
436,
822,
8,
585,
9,
690,
1390,
63,
875,
63,
890,
26,
288,
2883,
63,
475,
63,
1807,
14,
740,
8,
498,
9,
267,
587,
26,
288,
11639,
63,
17912,
8,
585,
12,
1390,
63,
875,
63,
890,
9,
272,
367,
790,
315,
2883,
63,
475,
63,
1807,
26,
267,
2150,
2022,
63,
807,
59,
498,
61,
272,
372,
2022,
63,
807,
421,
199,
32,
12263,
63,
17912,
14,
2683,
8,
513,
9,
199,
318,
12561,
1001,
63,
513,
26,
769,
12,
1390,
63,
875,
63,
890,
26,
1109,
304,
272,
367,
1242,
315,
2022,
63,
513,
26,
267,
11639,
63,
17912,
8,
1053,
12,
1390,
63,
875,
63,
890,
9,
272,
372,
2022,
63,
513,
421,
199,
533,
24681,
8407,
547,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
1245,
26,
620,
9,
1035,
488,
26,
267,
1613,
11027,
826,
721,
1188,
9,
421,
199,
318,
2446,
8,
589,
304,
272,
2050,
14,
19602,
8,
1896,
29,
4806,
14,
4531,
9,
272,
340,
1249,
14,
1757,
26,
267,
2050,
14,
19602,
8,
1896,
29,
4806,
14,
5287,
9,
339,
312,
265,
73,
275,
312,
265,
73,
63,
1258,
14,
47,
265,
73,
3041,
342,
272,
1967,
63,
30264,
275,
378,
272,
570,
63,
3189,
275,
312,
265,
73,
14,
513,
63,
1725,
8,
267,
1249,
14,
2246,
63,
602,
12,
1249,
14,
2019,
63,
602,
12,
1249,
14,
396,
63,
466,
12,
1249,
14,
6063,
9,
339,
347,
5267,
63,
493,
8,
2373,
26,
312,
265,
73,
63,
1258,
14,
1173,
3900,
304,
267,
2222,
1832,
1967,
63,
30264,
267,
9593,
275,
32212,
14,
28928,
1575,
4174,
2042,
8,
2373,
14,
633,
14,
515,
680,
354,
267,
327,
14811,
1275,
1001,
14,
28997,
20,
436,
1275,
5369,
14,
28997,
20,
6203,
14,
267,
340,
440,
9593,
14,
4130,
5175,
1001,
76,
14,
6838,
735,
288,
9593,
275,
9593,
14,
13490,
14078,
499,
2788,
16,
61,
435,
1987,
1001,
76,
14,
6838,
7,
398,
1347,
63,
1501,
275,
1249,
14,
1199,
63,
694,
1182,
2397,
14,
6063,
1182,
971,
288,
289,
16019,
2373,
14,
602,
2689,
57,
3295,
77,
3295,
68,
6834,
1182,
9593,
267,
747,
14,
8347,
8,
1375,
63,
1501,
14,
1708,
12,
2187,
63,
745,
29,
549,
9,
267,
340,
312,
265,
73,
14,
6336,
63,
31597,
690,
1249,
14,
6336,
63,
3097,
63,
31597,
26,
288,
746,
24681,
8407,
547,
8,
355,
289,
7,
3514,
4591,
469,
79,
265,
73,
14,
2394,
63,
19385,
1182,
499,
538,
1165,
93,
603,
17587,
358,
267,
543,
11756,
14,
1490,
8,
1375,
63,
1501,
12,
818,
534,
9115,
297,
2644,
534,
1624,
13,
24,
297,
8057,
17115,
78,
358,
465,
1347,
63,
493,
26,
288,
367,
18216,
315,
2397,
14,
362,
63,
30264,
837,
355,
1967,
63,
30264,
847,
413,
355,
333,
275,
11639,
63,
17912,
8,
17912,
12,
1249,
14,
988,
63,
875,
63,
890,
9,
355,
399,
1001,
14,
2724,
8,
77,
12,
1347,
63,
493,
9,
355,
1347,
63,
493,
14,
952,
2258,
78,
358,
267,
372,
289,
7,
3514,
4591,
469,
2373,
14,
633,
14,
32130,
12737,
8910,
2373,
14,
890,
11941,
93,
2783,
6616,
339,
543,
11086,
5453,
8,
11816,
29,
21,
627,
747,
14,
3541,
63,
835,
1012,
465,
7604,
63,
2293,
26,
267,
367,
1499,
315,
7604,
63,
2293,
14,
15311,
63,
24182,
8,
3535,
63,
493,
12,
570,
63,
3189,
304,
288,
2050,
14,
815,
8,
1328,
9,
339,
2050,
14,
815,
8,
70,
7,
18611,
1470,
26,
469,
1507,
63,
30264,
1386,
13392,
4591,
469,
79,
265,
73,
14,
2394,
63,
19385,
15,
18,
538,
1165,
26,
16,
14,
19,
70,
93,
603,
17587,
12,
15896,
12754,
24681,
26,
10839,
79,
265,
73,
14,
6336,
63,
31597,
26,
996,
70,
12216,
421,
199,
318,
485,
1122,
63,
602,
63,
4173,
8,
602,
63,
495,
26,
620,
9,
1035,
4487,
14,
602,
26,
272,
372,
4487,
14,
2083,
14,
9866,
8,
602,
63,
495,
12,
2071,
57,
3295,
77,
3295,
68,
3471,
602,
342,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1798,
275,
7534,
14,
10730,
480,
11135,
593,
615,
41,
32619,
531,
272,
1798,
14,
525,
63,
2094,
6739,
6063,
401,
730,
29,
495,
12,
1415,
29,
549,
9,
272,
1798,
14,
525,
63,
2094,
6739,
2246,
63,
602,
401,
730,
3699,
1122,
63,
602,
63,
4173,
12,
717,
849,
29,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mozman/ezdxf
|
examples/text_layout_engine_usage.py
|
1
|
12087
|
# Copyright (c) 2021, Manfred Moitzi
# License: MIT License
import sys
from typing import Iterable
import pathlib
import random
import ezdxf
from ezdxf import zoom, print_config
from ezdxf.math import Matrix44
from ezdxf.tools import fonts
from ezdxf.tools import text_layout as tl
"""
This example shows the usage of the internal text_layout module to render
complex text layouts. The module is designed to render MText like entities,
but could be used for other tasks too. The layout engine supports a multi
column setup, each column contains paragraphs, and these paragraphs can
automatically flow across the columns. All locations are relative to each other,
absolute locations are not supported - tabulators are not supported.
The layout engine knows nothing about the content itself, it just manages
content boxes of a fixed given width and height and "glue" spaces in between.
The engine does not alter the size of the content boxes, but resizes the glue
if necessary. The actual rendering is done by a rendering object associated to
each content box.
The only text styling manged by the layout engine is underline, overline and
strike through multiple content boxes.
Features:
- layout alignment like MText: top-middle-bottom combined with left-center-right
- paragraph alignments: left, right, center, justified
- paragraph indentation: left, right, special first line
- cell alignments: top, center, bottom
- fraction cells: over, slanted, tolerance style
- columns have a fixed height or grows automatically, paragraphs which do not
fit "flow" into the following column.
- pass through of transformation matrix to the rendering object
TODO:
- bullet- and numbered lists
- refinements to replicate MText features as good as possible
Used for:
- drawing add-on to render MTEXT with columns
- explode MTEXT into DXF primitives (TEXT, LINE)
"""
if not ezdxf.options.use_matplotlib:
print("The Matplotlib package is required.")
sys.exit(1)
# Type alias:
Content = Iterable[tl.Cell]
DIR = pathlib.Path("~/Desktop/Outbox").expanduser()
STYLE = "Style0"
FONT = "OpenSans-Regular.ttf"
COLUMN_HEIGHT: float = 12
print_config()
doc = ezdxf.new()
msp = doc.modelspace()
style = doc.styles.new(STYLE, dxfattribs={"font": FONT})
def measure_space(font):
return font.text_width(" X") - font.text_width("X")
class SizedFont:
def __init__(self, height: float):
self.height = float(height)
self.font = fonts.make_font(FONT, self.height)
self.space = measure_space(self.font)
def text_width(self, text: str):
return self.font.text_width(text)
fix_sized_fonts = [
SizedFont(0.18),
SizedFont(0.35),
SizedFont(0.50),
SizedFont(0.70),
SizedFont(1.00),
]
class FrameRenderer(tl.ContentRenderer):
"""Render object to render a frame around a content collection.
This renderer can be used by collections which just manages content
but do not represent a content by itself (Layout, Column, Paragraph).
"""
def __init__(self, color):
self.color = color
def render(
self,
left: float,
bottom: float,
right: float,
top: float,
m: Matrix44 = None,
) -> None:
"""Render a frame as LWPOLYLINE."""
pline = msp.add_lwpolyline(
[(left, top), (right, top), (right, bottom), (left, bottom)],
close=True,
dxfattribs={"color": self.color},
)
if m:
pline.transform(m)
def line(
self, x1: float, y1: float, x2: float, y2: float, m: Matrix44 = None
) -> None:
"""Line renderer used to create underline, overline, strike through
and fraction dividers.
"""
line = msp.add_line(
(x1, y1), (x2, y2), dxfattribs={"color": self.color}
)
if m:
line.transform(m)
class TextRenderer(tl.ContentRenderer):
"""Text content renderer."""
def __init__(self, text, attribs):
self.text = text
self.attribs = attribs
self.line_attribs = {"color": attribs["color"]}
def render(
self,
left: float,
bottom: float,
right: float,
top: float,
m: Matrix44 = None,
):
"""Create/render the text content"""
text = msp.add_text(self.text, dxfattribs=self.attribs)
text.set_pos((left, bottom), align="LEFT")
if m:
text.transform(m)
def line(
self, x1: float, y1: float, x2: float, y2: float, m: Matrix44 = None
) -> None:
"""Line renderer used to create underline, overline, strike through
and fraction dividers.
"""
line = msp.add_line((x1, y1), (x2, y2), dxfattribs=self.line_attribs)
if m:
line.transform(m)
class Word(tl.Text):
"""Represent a word as content box for the layout engine."""
def __init__(self, text: str, font: SizedFont, stroke: int = 0):
# Each content box can have individual properties:
attribs = {
"color": random.choice((1, 2, 3, 4, 6, 7, 7)),
"height": font.height,
"style": STYLE,
}
super().__init__(
# Width and height of the content are fixed given values and will
# not be changed by the layout engine:
width=font.text_width(text),
height=font.height,
stroke=stroke,
# Each content box can have it's own rendering object:
renderer=TextRenderer(text, attribs),
)
def uniform_content(count: int, size: int = 1) -> Content:
"""Create content with one text size."""
font = fix_sized_fonts[size]
for word in tl.lorem_ipsum(count):
yield Word(word, font)
yield tl.Space(font.space)
def random_sized_content(count: int) -> Content:
"""Create content with randomized text size."""
def size():
return random.choice([0, 1, 1, 1, 1, 1, 2, 3])
for word in tl.lorem_ipsum(count):
font = fix_sized_fonts[size()]
yield Word(word, font)
yield tl.Space(font.space)
def stroke_groups(words: Iterable[str]):
group = []
count = 0
stroke = 0
for word in words:
if count == 0:
if group:
yield group, stroke
count = random.randint(1, 4)
group = [word]
stroke = random.choice([0, 0, 0, 0, 1, 1, 1, 2, 2, 4])
else:
count -= 1
group.append(word)
if group:
yield group, stroke
def stroked_content(count: int, size: int = 1) -> Content:
"""Create content with one text size and groups of words with or without
strokes.
"""
font = fix_sized_fonts[size]
groups = stroke_groups(tl.lorem_ipsum(count))
for group, stroke in groups:
# strokes should span across spaces in between words:
# Spaces between words are bound to the preceding content box renderer,
# MText is more flexible, but this implementation is easy and good
# enough, otherwise spaces would need a distinct height and a rendering
# object, both are not implemented for glue objects.
continue_stroke = stroke + 8 if stroke else 0
for word in group[:-1]:
yield Word(word, font=font, stroke=continue_stroke)
yield tl.Space(font.space)
# strokes end at the last word, without continue stroke:
yield Word(group[-1], font=font, stroke=stroke)
yield tl.Space(font.space)
class Fraction(tl.Fraction):
"""Represents a fraction for the layout engine, which consist of a top-
and bottom content box, divided by horizontal or slanted line.
The "tolerance style" has no line between the stacked content boxes.
This implementation is more flexible than MText, the content boxes can be
words but also fractions or cell groups.
"""
def __init__(
self, t1: str, t2: str, stacking: tl.Stacking, font: SizedFont
):
top = Word(t1, font)
bottom = Word(t2, font)
super().__init__(
top=top,
bottom=bottom,
stacking=stacking,
# Uses only the generic line renderer to render the divider line,
# the top- and bottom content boxes use their own render objects.
renderer=FrameRenderer(color=7),
)
def fraction_content() -> Content:
"""Create content with one text size and place random fractions between
words.
"""
words = list(uniform_content(120))
for word in words:
word.valign = tl.CellAlignment.BOTTOM
stacking_options = list(tl.Stacking)
font = SizedFont(0.25) # fraction font
for _ in range(10):
stacking = random.choice(stacking_options)
top = str(random.randint(1, 1000))
bottom = str(random.randint(1, 1000))
pos = random.randint(0, len(words) - 1)
if isinstance(words[pos], tl.Space):
pos += 1
words.insert(pos, Fraction(top, bottom, stacking, font))
words.insert(pos + 1, tl.Space(font.space))
return words
def create_layout(align: tl.ParagraphAlignment, content: Content) -> tl.Layout:
# Create a flow text paragraph for the content:
paragraph = tl.Paragraph(align=align)
paragraph.append_content(content)
# Start the layout engine and set default column width:
layout = tl.Layout(
width=8, # default column width for columns without define width
margins=(0.5,), # space around the layout
# The render object of collections like Layout, Column or Paragraph is
# called before the render objects of the content managed by the
# collection.
# This could be used to render a frame or a background:
renderer=FrameRenderer(color=2),
)
# Append the first column with default width and a content height of 12 drawing
# units. At least the first column has to be created by the client.
layout.append_column(height=COLUMN_HEIGHT, gutter=1)
# Append the content. The content will be distributed across the available
# columns and automatically overflow into adjacent columns if necessary.
# The layout engine creates new columns automatically if required by
# cloning the last column.
layout.append_paragraphs([paragraph])
# Content- and total size is always up to date, only the final location
# has to be updated by calling Layout.place().
print()
print(f"Layout has {len(layout)} columns.")
print(f"Layout total width: {layout.total_width}")
print(f"Layout total height: {layout.total_height}")
for n, column in enumerate(layout, start=1):
print()
print(f" {n}. column has {len(column)} paragraph(s)")
print(f" Column total width: {column.total_width}")
print(f" Column total height: {column.total_height}")
# It is recommended to place the layout at origin (0, 0) and use a
# transformation matrix to move the layout to the final location in
# the DXF target layout - the model space in this example.
# Set final layout location in the xy-plane with alignment:
layout.place(align=tl.LayoutAlignment.BOTTOM_LEFT)
# It is possible to add content after calling place(), but place has to be
# called again before calling the render() method of the layout.
return layout
def create(content: Content, y: float) -> None:
x: float = 0
for align in list(tl.ParagraphAlignment):
# Build and place the layout at (0, 0):
layout = create_layout(align, content)
# Render and move the layout to the final location:
m = Matrix44.translate(x, y, 0)
layout.render(m)
x += layout.total_width + 2
dy: float = COLUMN_HEIGHT + 3
create(list(uniform_content(200)), 0)
create(list(random_sized_content(200)), dy)
create(list(stroked_content(200)), 2 * dy)
create(fraction_content(), 3 * dy)
# zooming needs the longest time:
zoom.extents(msp, factor=1.1)
doc.saveas(str(DIR / "text_layout.dxf"))
|
mit
|
[
3,
221,
1898,
334,
67,
9,
499,
15385,
12,
4688,
22980,
3930,
390,
16079,
199,
3,
221,
844,
26,
10697,
844,
199,
646,
984,
199,
504,
14090,
492,
19937,
199,
646,
32212,
199,
646,
2196,
199,
646,
325,
23670,
1949,
199,
504,
325,
23670,
1949,
492,
16935,
12,
870,
63,
888,
199,
504,
325,
23670,
1949,
14,
3442,
492,
8449,
1602,
199,
504,
325,
23670,
1949,
14,
2537,
492,
26219,
199,
504,
325,
23670,
1949,
14,
2537,
492,
1318,
63,
4209,
465,
25168,
199,
199,
624,
221,
199,
2765,
2893,
13703,
314,
4503,
402,
314,
5007,
1318,
63,
4209,
859,
370,
3795,
221,
199,
5254,
1318,
7054,
83,
14,
710,
859,
365,
19829,
370,
3795,
603,
1872,
2839,
9045,
12,
199,
7911,
4293,
506,
1202,
367,
1163,
6527,
4634,
14,
710,
7054,
6869,
5171,
282,
3510,
221,
199,
2301,
3272,
12,
1924,
2763,
3509,
26603,
12,
436,
3520,
26603,
883,
221,
199,
2495,
17174,
6369,
9371,
314,
4362,
14,
2900,
9918,
787,
3847,
370,
1924,
1163,
12,
221,
199,
6116,
9918,
787,
440,
3748,
446,
5174,
26609,
787,
440,
3748,
14,
199,
199,
1918,
7054,
6869,
19428,
6548,
3595,
314,
1564,
6337,
12,
652,
2951,
31965,
221,
199,
1317,
17193,
402,
282,
6317,
1627,
3462,
436,
4569,
436,
298,
3528,
310,
2,
7883,
315,
3382,
14,
221,
199,
1918,
6869,
1630,
440,
17355,
314,
1568,
402,
314,
1564,
17193,
12,
1325,
295,
7723,
314,
6482,
310,
221,
199,
692,
5784,
14,
710,
3503,
14066,
365,
4224,
701,
282,
14066,
909,
4568,
370,
221,
199,
10885,
1564,
5689,
14,
9948,
199,
1918,
1454,
1318,
32468,
2983,
333,
618,
68,
701,
314,
7054,
6869,
365,
25735,
12,
1806,
604,
436,
221,
199,
26845,
4012,
3663,
1564,
17193,
14,
199,
199,
10807,
26,
199,
199,
13,
7054,
13177,
2839,
603,
1872,
26,
2746,
13,
14885,
13,
8305,
12149,
543,
3602,
13,
4218,
13,
1019,
199,
13,
13168,
6998,
1470,
26,
3602,
12,
2451,
12,
8126,
12,
2951,
4541,
199,
13,
13168,
14311,
26,
3602,
12,
2451,
12,
4539,
1642,
1004,
199,
13,
4917,
6998,
1470,
26,
2746,
12,
8126,
12,
9048,
199,
13,
12347,
10106,
26,
1806,
12,
308,
1502,
471,
12,
13464,
3449,
199,
13,
4362,
1172,
282,
6317,
4569,
503,
486,
3838,
5847,
12,
26603,
1314,
886,
440,
16421,
5542,
298,
1659,
2,
1901,
314,
2569,
2763,
14,
199,
13,
986,
4012,
402,
13315,
3634,
370,
314,
14066,
909,
199,
199,
11768,
26,
9948,
199,
13,
330,
15007,
13,
436,
1967,
18897,
5548,
199,
13,
2984,
1132,
1470,
370,
29738,
603,
1872,
4534,
465,
6954,
465,
3962,
199,
199,
9167,
367,
26,
199,
199,
13,
17455,
1050,
13,
265,
370,
3795,
603,
3876,
543,
4362,
199,
13,
15868,
271,
603,
3876,
1901,
577,
25145,
1979,
22337,
334,
3876,
12,
13587,
9,
199,
199,
624,
199,
692,
440,
325,
23670,
1949,
14,
1419,
14,
1180,
63,
16440,
26,
272,
870,
480,
1918,
18619,
6711,
2559,
365,
1415,
2685,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
3,
2434,
5162,
26,
199,
2714,
275,
19937,
59,
5019,
14,
8108,
61,
199,
199,
3022,
275,
32212,
14,
2042,
20793,
15,
20436,
15,
2204,
1977,
3471,
12131,
342,
199,
18466,
275,
298,
6609,
16,
2,
199,
18398,
275,
298,
4299,
51,
796,
13,
16038,
14,
32264,
2,
199,
21436,
63,
13509,
26,
2069,
275,
3144,
199,
199,
1361,
63,
888,
342,
199,
199,
1301,
275,
325,
23670,
1949,
14,
1222,
342,
199,
77,
681,
275,
1382,
14,
992,
1142,
342,
199,
2487,
275,
1382,
14,
12955,
14,
1222,
8,
18466,
12,
366,
1949,
30674,
8871,
4246,
582,
481,
5994,
1552,
421,
199,
318,
9775,
63,
2638,
8,
4246,
304,
272,
372,
5023,
14,
505,
63,
2063,
480,
1323,
531,
446,
5023,
14,
505,
63,
2063,
480,
56,
531,
421,
199,
533,
428,
1759,
6986,
26,
272,
347,
636,
826,
721,
277,
12,
4569,
26,
2069,
304,
267,
291,
14,
3333,
275,
2069,
8,
3333,
9,
267,
291,
14,
4246,
275,
26219,
14,
1875,
63,
4246,
8,
18398,
12,
291,
14,
3333,
9,
267,
291,
14,
2638,
275,
9775,
63,
2638,
8,
277,
14,
4246,
9,
339,
347,
1318,
63,
2063,
8,
277,
12,
1318,
26,
620,
304,
267,
372,
291,
14,
4246,
14,
505,
63,
2063,
8,
505,
9,
421,
199,
970,
63,
15308,
63,
19864,
275,
359,
272,
428,
1759,
6986,
8,
16,
14,
1085,
395,
272,
428,
1759,
6986,
8,
16,
14,
1276,
395,
272,
428,
1759,
6986,
8,
16,
14,
1400,
395,
272,
428,
1759,
6986,
8,
16,
14,
2760,
395,
272,
428,
1759,
6986,
8,
17,
14,
383,
395,
199,
61,
421,
199,
533,
11726,
11355,
8,
5019,
14,
2714,
11355,
304,
272,
408,
9216,
909,
370,
3795,
282,
2787,
6818,
282,
1564,
3245,
14,
339,
961,
11889,
883,
506,
1202,
701,
5055,
1314,
2951,
31965,
1564,
272,
1325,
886,
440,
2954,
282,
1564,
701,
6337,
334,
4798,
12,
4996,
12,
2235,
7109,
680,
339,
408,
339,
347,
636,
826,
721,
277,
12,
3164,
304,
267,
291,
14,
2326,
275,
3164,
339,
347,
3795,
8,
267,
291,
12,
267,
3602,
26,
2069,
12,
267,
9048,
26,
2069,
12,
267,
2451,
26,
2069,
12,
267,
2746,
26,
2069,
12,
267,
333,
26,
8449,
1602,
275,
488,
12,
272,
776,
1035,
488,
26,
267,
408,
9216,
282,
2787,
465,
491,
55,
19869,
6174,
1041,
267,
299,
604,
275,
333,
681,
14,
525,
63,
20692,
6023,
604,
8,
288,
3842,
3039,
12,
2746,
395,
334,
1019,
12,
2746,
395,
334,
1019,
12,
9048,
395,
334,
3039,
12,
9048,
4360,
288,
4002,
29,
549,
12,
288,
366,
1949,
30674,
8871,
2326,
582,
291,
14,
2326,
1386,
267,
776,
267,
340,
333,
26,
288,
299,
604,
14,
4711,
8,
77,
9,
339,
347,
1004,
8,
267,
291,
12,
671,
17,
26,
2069,
12,
612,
17,
26,
2069,
12,
671,
18,
26,
2069,
12,
612,
18,
26,
2069,
12,
333,
26,
8449,
1602,
275,
488,
272,
776,
1035,
488,
26,
267,
408,
3049,
11889,
1202,
370,
1218,
25735,
12,
1806,
604,
12,
4024,
415,
4012,
267,
436,
12347,
487,
2922,
83,
14,
398,
408,
267,
1004,
275,
333,
681,
14,
525,
63,
604,
8,
288,
334,
88,
17,
12,
612
] |
[
221,
1898,
334,
67,
9,
499,
15385,
12,
4688,
22980,
3930,
390,
16079,
199,
3,
221,
844,
26,
10697,
844,
199,
646,
984,
199,
504,
14090,
492,
19937,
199,
646,
32212,
199,
646,
2196,
199,
646,
325,
23670,
1949,
199,
504,
325,
23670,
1949,
492,
16935,
12,
870,
63,
888,
199,
504,
325,
23670,
1949,
14,
3442,
492,
8449,
1602,
199,
504,
325,
23670,
1949,
14,
2537,
492,
26219,
199,
504,
325,
23670,
1949,
14,
2537,
492,
1318,
63,
4209,
465,
25168,
199,
199,
624,
221,
199,
2765,
2893,
13703,
314,
4503,
402,
314,
5007,
1318,
63,
4209,
859,
370,
3795,
221,
199,
5254,
1318,
7054,
83,
14,
710,
859,
365,
19829,
370,
3795,
603,
1872,
2839,
9045,
12,
199,
7911,
4293,
506,
1202,
367,
1163,
6527,
4634,
14,
710,
7054,
6869,
5171,
282,
3510,
221,
199,
2301,
3272,
12,
1924,
2763,
3509,
26603,
12,
436,
3520,
26603,
883,
221,
199,
2495,
17174,
6369,
9371,
314,
4362,
14,
2900,
9918,
787,
3847,
370,
1924,
1163,
12,
221,
199,
6116,
9918,
787,
440,
3748,
446,
5174,
26609,
787,
440,
3748,
14,
199,
199,
1918,
7054,
6869,
19428,
6548,
3595,
314,
1564,
6337,
12,
652,
2951,
31965,
221,
199,
1317,
17193,
402,
282,
6317,
1627,
3462,
436,
4569,
436,
298,
3528,
310,
2,
7883,
315,
3382,
14,
221,
199,
1918,
6869,
1630,
440,
17355,
314,
1568,
402,
314,
1564,
17193,
12,
1325,
295,
7723,
314,
6482,
310,
221,
199,
692,
5784,
14,
710,
3503,
14066,
365,
4224,
701,
282,
14066,
909,
4568,
370,
221,
199,
10885,
1564,
5689,
14,
9948,
199,
1918,
1454,
1318,
32468,
2983,
333,
618,
68,
701,
314,
7054,
6869,
365,
25735,
12,
1806,
604,
436,
221,
199,
26845,
4012,
3663,
1564,
17193,
14,
199,
199,
10807,
26,
199,
199,
13,
7054,
13177,
2839,
603,
1872,
26,
2746,
13,
14885,
13,
8305,
12149,
543,
3602,
13,
4218,
13,
1019,
199,
13,
13168,
6998,
1470,
26,
3602,
12,
2451,
12,
8126,
12,
2951,
4541,
199,
13,
13168,
14311,
26,
3602,
12,
2451,
12,
4539,
1642,
1004,
199,
13,
4917,
6998,
1470,
26,
2746,
12,
8126,
12,
9048,
199,
13,
12347,
10106,
26,
1806,
12,
308,
1502,
471,
12,
13464,
3449,
199,
13,
4362,
1172,
282,
6317,
4569,
503,
486,
3838,
5847,
12,
26603,
1314,
886,
440,
16421,
5542,
298,
1659,
2,
1901,
314,
2569,
2763,
14,
199,
13,
986,
4012,
402,
13315,
3634,
370,
314,
14066,
909,
199,
199,
11768,
26,
9948,
199,
13,
330,
15007,
13,
436,
1967,
18897,
5548,
199,
13,
2984,
1132,
1470,
370,
29738,
603,
1872,
4534,
465,
6954,
465,
3962,
199,
199,
9167,
367,
26,
199,
199,
13,
17455,
1050,
13,
265,
370,
3795,
603,
3876,
543,
4362,
199,
13,
15868,
271,
603,
3876,
1901,
577,
25145,
1979,
22337,
334,
3876,
12,
13587,
9,
199,
199,
624,
199,
692,
440,
325,
23670,
1949,
14,
1419,
14,
1180,
63,
16440,
26,
272,
870,
480,
1918,
18619,
6711,
2559,
365,
1415,
2685,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
3,
2434,
5162,
26,
199,
2714,
275,
19937,
59,
5019,
14,
8108,
61,
199,
199,
3022,
275,
32212,
14,
2042,
20793,
15,
20436,
15,
2204,
1977,
3471,
12131,
342,
199,
18466,
275,
298,
6609,
16,
2,
199,
18398,
275,
298,
4299,
51,
796,
13,
16038,
14,
32264,
2,
199,
21436,
63,
13509,
26,
2069,
275,
3144,
199,
199,
1361,
63,
888,
342,
199,
199,
1301,
275,
325,
23670,
1949,
14,
1222,
342,
199,
77,
681,
275,
1382,
14,
992,
1142,
342,
199,
2487,
275,
1382,
14,
12955,
14,
1222,
8,
18466,
12,
366,
1949,
30674,
8871,
4246,
582,
481,
5994,
1552,
421,
199,
318,
9775,
63,
2638,
8,
4246,
304,
272,
372,
5023,
14,
505,
63,
2063,
480,
1323,
531,
446,
5023,
14,
505,
63,
2063,
480,
56,
531,
421,
199,
533,
428,
1759,
6986,
26,
272,
347,
636,
826,
721,
277,
12,
4569,
26,
2069,
304,
267,
291,
14,
3333,
275,
2069,
8,
3333,
9,
267,
291,
14,
4246,
275,
26219,
14,
1875,
63,
4246,
8,
18398,
12,
291,
14,
3333,
9,
267,
291,
14,
2638,
275,
9775,
63,
2638,
8,
277,
14,
4246,
9,
339,
347,
1318,
63,
2063,
8,
277,
12,
1318,
26,
620,
304,
267,
372,
291,
14,
4246,
14,
505,
63,
2063,
8,
505,
9,
421,
199,
970,
63,
15308,
63,
19864,
275,
359,
272,
428,
1759,
6986,
8,
16,
14,
1085,
395,
272,
428,
1759,
6986,
8,
16,
14,
1276,
395,
272,
428,
1759,
6986,
8,
16,
14,
1400,
395,
272,
428,
1759,
6986,
8,
16,
14,
2760,
395,
272,
428,
1759,
6986,
8,
17,
14,
383,
395,
199,
61,
421,
199,
533,
11726,
11355,
8,
5019,
14,
2714,
11355,
304,
272,
408,
9216,
909,
370,
3795,
282,
2787,
6818,
282,
1564,
3245,
14,
339,
961,
11889,
883,
506,
1202,
701,
5055,
1314,
2951,
31965,
1564,
272,
1325,
886,
440,
2954,
282,
1564,
701,
6337,
334,
4798,
12,
4996,
12,
2235,
7109,
680,
339,
408,
339,
347,
636,
826,
721,
277,
12,
3164,
304,
267,
291,
14,
2326,
275,
3164,
339,
347,
3795,
8,
267,
291,
12,
267,
3602,
26,
2069,
12,
267,
9048,
26,
2069,
12,
267,
2451,
26,
2069,
12,
267,
2746,
26,
2069,
12,
267,
333,
26,
8449,
1602,
275,
488,
12,
272,
776,
1035,
488,
26,
267,
408,
9216,
282,
2787,
465,
491,
55,
19869,
6174,
1041,
267,
299,
604,
275,
333,
681,
14,
525,
63,
20692,
6023,
604,
8,
288,
3842,
3039,
12,
2746,
395,
334,
1019,
12,
2746,
395,
334,
1019,
12,
9048,
395,
334,
3039,
12,
9048,
4360,
288,
4002,
29,
549,
12,
288,
366,
1949,
30674,
8871,
2326,
582,
291,
14,
2326,
1386,
267,
776,
267,
340,
333,
26,
288,
299,
604,
14,
4711,
8,
77,
9,
339,
347,
1004,
8,
267,
291,
12,
671,
17,
26,
2069,
12,
612,
17,
26,
2069,
12,
671,
18,
26,
2069,
12,
612,
18,
26,
2069,
12,
333,
26,
8449,
1602,
275,
488,
272,
776,
1035,
488,
26,
267,
408,
3049,
11889,
1202,
370,
1218,
25735,
12,
1806,
604,
12,
4024,
415,
4012,
267,
436,
12347,
487,
2922,
83,
14,
398,
408,
267,
1004,
275,
333,
681,
14,
525,
63,
604,
8,
288,
334,
88,
17,
12,
612,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
garthomp/ruby_blog
|
node_modules/grunt-docker/node_modules/docker/node_modules/pygmentize-bundled/vendor/pygments/build-3.3/pygments/styles/murphy.py
|
364
|
2751
|
# -*- coding: utf-8 -*-
"""
pygments.styles.murphy
~~~~~~~~~~~~~~~~~~~~~~
Murphy's style from CodeRay.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from pygments.style import Style
from pygments.token import Keyword, Name, Comment, String, Error, \
Number, Operator, Generic, Whitespace
class MurphyStyle(Style):
"""
Murphy's style from CodeRay.
"""
default_style = ""
styles = {
Whitespace: "#bbbbbb",
Comment: "#666 italic",
Comment.Preproc: "#579 noitalic",
Comment.Special: "#c00 bold",
Keyword: "bold #289",
Keyword.Pseudo: "#08f",
Keyword.Type: "#66f",
Operator: "#333",
Operator.Word: "bold #000",
Name.Builtin: "#072",
Name.Function: "bold #5ed",
Name.Class: "bold #e9e",
Name.Namespace: "bold #0e84b5",
Name.Exception: "bold #F00",
Name.Variable: "#036",
Name.Variable.Instance: "#aaf",
Name.Variable.Class: "#ccf",
Name.Variable.Global: "#f84",
Name.Constant: "bold #5ed",
Name.Label: "bold #970",
Name.Entity: "#800",
Name.Attribute: "#007",
Name.Tag: "#070",
Name.Decorator: "bold #555",
String: "bg:#e0e0ff",
String.Char: "#88F bg:",
String.Doc: "#D42 bg:",
String.Interpol: "bg:#eee",
String.Escape: "bold #666",
String.Regex: "bg:#e0e0ff #000",
String.Symbol: "#fc8 bg:",
String.Other: "#f88",
Number: "bold #60E",
Number.Integer: "bold #66f",
Number.Float: "bold #60E",
Number.Hex: "bold #058",
Number.Oct: "bold #40E",
Generic.Heading: "bold #000080",
Generic.Subheading: "bold #800080",
Generic.Deleted: "#A00000",
Generic.Inserted: "#00A000",
Generic.Error: "#FF0000",
Generic.Emph: "italic",
Generic.Strong: "bold",
Generic.Prompt: "bold #c65d09",
Generic.Output: "#888",
Generic.Traceback: "#04D",
Error: "#F00 bg:#FAA"
}
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12955,
14,
77,
300,
6581,
272,
18294,
2878,
1714,
339,
603,
300,
6581,
1159,
3449,
687,
5495,
25474,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
504,
13277,
14,
2487,
492,
19442,
199,
504,
13277,
14,
1418,
492,
6431,
12,
2812,
12,
6819,
12,
2624,
12,
4520,
12,
971,
1362,
4860,
12,
11013,
12,
8307,
12,
24403,
421,
199,
533,
603,
300,
6581,
6609,
8,
6609,
304,
272,
408,
272,
603,
300,
6581,
1159,
3449,
687,
5495,
25474,
14,
272,
408,
339,
849,
63,
2487,
275,
3087,
339,
15725,
275,
469,
267,
24403,
26,
4483,
5426,
14923,
2501,
401,
267,
6819,
26,
7861,
5426,
11829,
652,
17999,
401,
267,
6819,
14,
19285,
26,
3698,
5426,
14003,
949,
21843,
401,
267,
6819,
14,
12246,
26,
3698,
5426,
67,
383,
17268,
401,
398,
6431,
26,
7861,
298,
9771,
327,
20919,
401,
267,
6431,
14,
23414,
26,
3322,
5426,
2036,
70,
401,
267,
6431,
14,
804,
26,
4519,
5426,
1272,
70,
401,
398,
11013,
26,
8295,
5426,
11769,
401,
267,
11013,
14,
10155,
26,
3777,
298,
9771,
327,
1493,
401,
398,
2812,
14,
12306,
26,
4519,
5426,
20281,
401,
267,
2812,
14,
3481,
26,
3777,
298,
9771,
327,
21,
379,
401,
267,
2812,
14,
2543,
26,
4483,
298,
9771,
327,
69,
25,
69,
401,
267,
2812,
14,
8814,
26,
3322,
298,
9771,
327,
16,
69,
1349,
66,
21,
401,
267,
2812,
14,
1726,
26,
3322,
298,
9771,
327,
38,
383,
401,
267,
2812,
14,
2773,
26,
3777,
5426,
25368,
401,
267,
2812,
14,
2773,
14,
3244,
26,
259,
5426,
31498,
401,
267,
2812,
14,
2773,
14,
2543,
26,
755,
5426,
31427,
401,
267,
2812,
14,
2773,
14,
7025,
26,
420,
5426,
70,
1349,
401,
267,
2812,
14,
9737,
26,
3777,
298,
9771,
327,
21,
379,
401,
267,
2812,
14,
4314,
26,
4483,
298,
9771,
327,
20598,
401,
267,
2812,
14,
7302,
26,
5185,
5426,
6718,
401,
267,
2812,
14,
1646,
26,
3322,
5426,
8255,
401,
267,
2812,
14,
1931,
26,
8295,
5426,
19235,
401,
267,
2812,
14,
14946,
26,
3322,
298,
9771,
327,
15722,
401,
398,
2624,
26,
8540,
298,
6856,
15596,
69,
16,
69,
16,
556,
401,
267,
2624,
14,
1610,
26,
5185,
5426,
1299,
38,
12994,
6783,
267,
2624,
14,
3768,
26,
4483,
5426,
36,
2260,
12994,
6783,
267,
2624,
14,
22713,
26,
3698,
298,
6856,
15596,
18777,
401,
267,
2624,
14,
10260,
26,
3777,
298,
9771,
327,
11829,
401,
267,
2624,
14,
5103,
26,
4519,
298,
6856,
15596,
69,
16,
69,
16,
556,
327,
1493,
401,
267,
2624,
14,
8169,
26,
3777,
5426,
3003,
24,
12994,
6783,
267,
2624,
14,
8632,
26,
4519,
5426,
70,
1299,
401,
398,
4860,
26,
8540,
298,
9771,
327,
2259,
37,
401,
267,
4860,
14,
2674,
26,
3322,
298,
9771,
327,
1272,
70,
401,
267,
4860,
14,
5136,
26,
4519,
298,
9771,
327,
2259,
37,
401,
267,
4860,
14,
10373,
26,
4483,
298,
9771,
327,
18009,
401,
267,
4860,
14,
17584,
26,
4483,
298,
9771,
327,
2167,
37,
401,
398,
8307,
14,
23818,
26,
3698,
298,
9771,
327,
993,
1257,
401,
267,
8307,
14,
2610,
13983,
26,
263,
298,
9771,
327,
15214,
1257,
401,
267,
8307,
14,
17735,
26,
3698,
5426,
33,
5345,
401,
267,
8307,
14,
607,
9449,
26,
3515,
5426,
383,
33,
1493,
401,
267,
8307,
14,
547,
26,
3777,
5426,
1665,
993,
401,
267,
8307,
14,
37,
311,
72,
26,
4519,
298,
21843,
401,
267,
8307,
14,
2848,
951,
26,
3322,
298,
9771,
401,
267,
8307,
14,
20430,
26,
3322,
298,
9771,
327,
67,
2182,
68,
1643,
401,
267,
8307,
14,
2959,
26,
3322,
5426,
13997,
401,
267,
8307,
14,
15905,
26,
260,
5426,
966,
36,
401,
398,
4520,
26,
9326,
5426,
38,
383,
12994,
15596,
2078,
33,
2,
272,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12955,
14,
77,
300,
6581,
272,
18294,
2878,
1714,
339,
603,
300,
6581,
1159,
3449,
687,
5495,
25474,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
504,
13277,
14,
2487,
492,
19442,
199,
504,
13277,
14,
1418,
492,
6431,
12,
2812,
12,
6819,
12,
2624,
12,
4520,
12,
971,
1362,
4860,
12,
11013,
12,
8307,
12,
24403,
421,
199,
533,
603,
300,
6581,
6609,
8,
6609,
304,
272,
408,
272,
603,
300,
6581,
1159,
3449,
687,
5495,
25474,
14,
272,
408,
339,
849,
63,
2487,
275,
3087,
339,
15725,
275,
469,
267,
24403,
26,
4483,
5426,
14923,
2501,
401,
267,
6819,
26,
7861,
5426,
11829,
652,
17999,
401,
267,
6819,
14,
19285,
26,
3698,
5426,
14003,
949,
21843,
401,
267,
6819,
14,
12246,
26,
3698,
5426,
67,
383,
17268,
401,
398,
6431,
26,
7861,
298,
9771,
327,
20919,
401,
267,
6431,
14,
23414,
26,
3322,
5426,
2036,
70,
401,
267,
6431,
14,
804,
26,
4519,
5426,
1272,
70,
401,
398,
11013,
26,
8295,
5426,
11769,
401,
267,
11013,
14,
10155,
26,
3777,
298,
9771,
327,
1493,
401,
398,
2812,
14,
12306,
26,
4519,
5426,
20281,
401,
267,
2812,
14,
3481,
26,
3777,
298,
9771,
327,
21,
379,
401,
267,
2812,
14,
2543,
26,
4483,
298,
9771,
327,
69,
25,
69,
401,
267,
2812,
14,
8814,
26,
3322,
298,
9771,
327,
16,
69,
1349,
66,
21,
401,
267,
2812,
14,
1726,
26,
3322,
298,
9771,
327,
38,
383,
401,
267,
2812,
14,
2773,
26,
3777,
5426,
25368,
401,
267,
2812,
14,
2773,
14,
3244,
26,
259,
5426,
31498,
401,
267,
2812,
14,
2773,
14,
2543,
26,
755,
5426,
31427,
401,
267,
2812,
14,
2773,
14,
7025,
26,
420,
5426,
70,
1349,
401,
267,
2812,
14,
9737,
26,
3777,
298,
9771,
327,
21,
379,
401,
267,
2812,
14,
4314,
26,
4483,
298,
9771,
327,
20598,
401,
267,
2812,
14,
7302,
26,
5185,
5426,
6718,
401,
267,
2812,
14,
1646,
26,
3322,
5426,
8255,
401,
267,
2812,
14,
1931,
26,
8295,
5426,
19235,
401,
267,
2812,
14,
14946,
26,
3322,
298,
9771,
327,
15722,
401,
398,
2624,
26,
8540,
298,
6856,
15596,
69,
16,
69,
16,
556,
401,
267,
2624,
14,
1610,
26,
5185,
5426,
1299,
38,
12994,
6783,
267,
2624,
14,
3768,
26,
4483,
5426,
36,
2260,
12994,
6783,
267,
2624,
14,
22713,
26,
3698,
298,
6856,
15596,
18777,
401,
267,
2624,
14,
10260,
26,
3777,
298,
9771,
327,
11829,
401,
267,
2624,
14,
5103,
26,
4519,
298,
6856,
15596,
69,
16,
69,
16,
556,
327,
1493,
401,
267,
2624,
14,
8169,
26,
3777,
5426,
3003,
24,
12994,
6783,
267,
2624,
14,
8632,
26,
4519,
5426,
70,
1299,
401,
398,
4860,
26,
8540,
298,
9771,
327,
2259,
37,
401,
267,
4860,
14,
2674,
26,
3322,
298,
9771,
327,
1272,
70,
401,
267,
4860,
14,
5136,
26,
4519,
298,
9771,
327,
2259,
37,
401,
267,
4860,
14,
10373,
26,
4483,
298,
9771,
327,
18009,
401,
267,
4860,
14,
17584,
26,
4483,
298,
9771,
327,
2167,
37,
401,
398,
8307,
14,
23818,
26,
3698,
298,
9771,
327,
993,
1257,
401,
267,
8307,
14,
2610,
13983,
26,
263,
298,
9771,
327,
15214,
1257,
401,
267,
8307,
14,
17735,
26,
3698,
5426,
33,
5345,
401,
267,
8307,
14,
607,
9449,
26,
3515,
5426,
383,
33,
1493,
401,
267,
8307,
14,
547,
26,
3777,
5426,
1665,
993,
401,
267,
8307,
14,
37,
311,
72,
26,
4519,
298,
21843,
401,
267,
8307,
14,
2848,
951,
26,
3322,
298,
9771,
401,
267,
8307,
14,
20430,
26,
3322,
298,
9771,
327,
67,
2182,
68,
1643,
401,
267,
8307,
14,
2959,
26,
3322,
5426,
13997,
401,
267,
8307,
14,
15905,
26,
260,
5426,
966,
36,
401,
398,
4520,
26,
9326,
5426,
38,
383,
12994,
15596,
2078,
33,
2,
272,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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
|
11148
|
#########################################################################
#
# Copyright (c) 2003-2004 Danny Brewer d29583@groovegarden.com
# Copyright (C) 2004-2010 OpenERP SA (<http://openerp.com>).
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (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 Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# See: http://www.gnu.org/licenses/lgpl.html
#
#############################################################################
import os
import uno
import unohelper
import xmlrpclib
import base64
from com.sun.star.task import XJobExecutor
if __name__<>"package":
from lib.gui import *
from lib.error import ErrorDialog
from lib.tools import *
from LoginTest import *
from lib.rpc import *
database="test"
uid = 3
class AddAttachment(unohelper.Base, XJobExecutor ):
Kind = {
'PDF' : 'pdf',
'OpenOffice': 'sxw',
}
def __init__(self, ctx):
self.ctx = ctx
self.module = "openerp_report"
self.version = "0.1"
LoginTest()
if not loginstatus and __name__=="package":
exit(1)
self.aSearchResult = []
desktop=getDesktop()
oDoc2 = desktop.getCurrentComponent()
docinfo=oDoc2.getDocumentInfo()
global passwd
self.password = passwd
global url
self.sock=RPCSession(url)
if docinfo.getUserFieldValue(2) <> "" and docinfo.getUserFieldValue(3) <> "":
self.win = DBModalDialog(60, 50, 180, 70, "Add Attachment to Server")
self.win.addFixedText("lblResourceType", 2 , 5, 100, 10, "Select Appropriate Resource Type:")
self.win.addComboListBox("lstResourceType", -2, 25, 176, 15,True)
self.win.addButton('btnOkWithoutInformation', -2 , -5, 25 , 15,'OK' ,actionListenerProc = self.btnOkWithoutInformation_clicked )
else:
self.win = DBModalDialog(60, 50, 180, 190, "Add Attachment to Server")
self.win.addFixedText("lblModuleName",2 , 9, 42, 20, "Select Module:")
self.win.addComboListBox("lstmodel", -2, 5, 134, 15,True)
self.lstModel = self.win.getControl( "lstmodel" )
self.dModel = {}
# Open a new connexion to the server
ids = self.sock.execute(database, uid, self.password, 'ir.module.module', 'search', [('name','=','base_report_model'),('state', '=', 'installed')])
if not len(ids):
# If the module 'base_report_model' is not installed, use the default model
self.dModel = {
"Partner":'res.partner',
}
else:
ids =self.sock.execute(database, uid, self.password, 'base.report.model' , 'search', [])
res = self.sock.execute(database, uid, self.password, 'base.report.model' , 'read', ids, ['name','model_id'])
models = self.sock.execute(database, uid, self.password, 'ir.model' , 'read', map(lambda x:x['model_id'][0], res), ['model'])
models = dict(map(lambda x:(x['id'],x['model']), models))
self.dModel = dict(map(lambda x: (x['name'],models[x['model_id'][0]]), res))
for item in self.dModel.keys():
self.lstModel.addItem(item, self.lstModel.getItemCount())
self.win.addFixedText("lblSearchName",2 , 25, 60, 10, "Enter Search String:")
self.win.addEdit("txtSearchName", 2, 35, 149, 15,)
self.win.addButton('btnSearch', -2 , 35, 25 , 15,'Search' ,actionListenerProc = self.btnSearch_clicked )
self.win.addFixedText("lblSearchRecord", 2 , 55, 60, 10, "Search Result:")
self.win.addComboListBox("lstResource", -2, 65, 176, 70, False )
self.lstResource = self.win.getControl( "lstResource" )
self.win.addFixedText("lblResourceType", 2 , 137, 100, 20, "Select Appropriate Resource Type:")
self.win.addComboListBox("lstResourceType", -2, 147, 176, 15,True )
self.win.addButton('btnOkWithInformation', -2 , -5, 25 , 15,'OK' ,actionListenerProc = self.btnOkWithInformation_clicked )
self.lstResourceType = self.win.getControl( "lstResourceType" )
for kind in self.Kind.keys():
self.lstResourceType.addItem( kind, self.lstResourceType.getItemCount() )
self.win.addButton('btnCancel', -2 - 27 , -5 , 30 , 15, 'Cancel' ,actionListenerProc = self.btnCancel_clicked )
self.win.doModalDialog("lstResourceType", self.Kind.keys()[0])
def btnSearch_clicked(self, oActionEvent):
modelSelectedItem = self.win.getListBoxSelectedItem("lstmodel")
if modelSelectedItem == "":
return
desktop=getDesktop()
oDoc2 = desktop.getCurrentComponent()
docinfo=oDoc2.getDocumentInfo()
self.aSearchResult =self.sock.execute( database, uid, self.password, self.dModel[modelSelectedItem], 'name_search', self.win.getEditText("txtSearchName"))
self.win.removeListBoxItems("lstResource", 0, self.win.getListBoxItemCount("lstResource"))
if self.aSearchResult == []:
ErrorDialog("No search result found.", "", "Search Error.")
return
for result in self.aSearchResult:
self.lstResource.addItem(result[1],result[0])
def _send_attachment(self, name, data, res_model, res_id):
desktop = getDesktop()
oDoc2 = desktop.getCurrentComponent()
docinfo = oDoc2.getDocumentInfo()
params = {
'name': name,
'datas': base64.encodestring( data ),
'datas_fname': name,
'res_model' : res_model,
'res_id' : int(res_id),
}
return self.sock.execute( database, uid, self.password, 'ir.attachment', 'create', params )
def send_attachment(self, model, resource_id):
desktop = getDesktop()
oDoc2 = desktop.getCurrentComponent()
docinfo = oDoc2.getDocumentInfo()
if oDoc2.getURL() == "":
ErrorDialog("You should save your file.", "", "Saving Error.")
return None
url = oDoc2.getURL()
if self.Kind[self.win.getListBoxSelectedItem("lstResourceType")] == "pdf":
url = self.doc2pdf(url[7:])
if url == None:
ErrorDialog( "Problem in creating PDF.", "", "PDF Error.")
return None
url = url[7:]
data = read_data_from_file( get_absolute_file_path( url ) )
return self._send_attachment( os.path.basename( url ), data, model, resource_id )
def btnOkWithoutInformation_clicked(self, oActionEvent):
desktop = getDesktop()
oDoc2 = desktop.getCurrentComponent()
docinfo = oDoc2.getDocumentInfo()
if self.win.getListBoxSelectedItem("lstResourceType") == "":
ErrorDialog("You have to select a resource type.", "", "Selection Error." )
return
res = self.send_attachment( docinfo.getUserFieldValue(3), docinfo.getUserFieldValue(2) )
self.win.endExecute()
def btnOkWithInformation_clicked(self, oActionEvent):
if self.win.getListBoxSelectedItem("lstResourceType") == "":
ErrorDialog( "You have to select a resource type.", "", "Selection Error." )
return
if self.win.getListBoxSelectedItem("lstResource") == "" or self.win.getListBoxSelectedItem("lstmodel") == "":
ErrorDialog("You have to select Model and Resource.", "", "Selection Error.")
return
resourceid = None
for s in self.aSearchResult:
if s[1] == self.win.getListBoxSelectedItem("lstResource"):
resourceid = s[0]
break
if resourceid == None:
ErrorDialog("No resource is selected.", "", "Resource Error." )
return
res = self.send_attachment( self.dModel[self.win.getListBoxSelectedItem('lstmodel')], resourceid )
self.win.endExecute()
def btnCancel_clicked(self, oActionEvent):
self.win.endExecute()
def doc2pdf(self, strFile):
oDoc = None
strFilterSubName = ''
strUrl = convertToURL( strFile )
desktop = getDesktop()
oDoc = desktop.loadComponentFromURL( strUrl, "_blank", 0, Array(self._MakePropertyValue("Hidden",True)))
if oDoc:
strFilterSubName = ""
# select appropriate filter
if oDoc.supportsService("com.sun.star.presentation.PresentationDocument"):
strFilterSubName = "impress_pdf_Export"
elif oDoc.supportsService("com.sun.star.sheet.SpreadsheetDocument"):
strFilterSubName = "calc_pdf_Export"
elif oDoc.supportsService("com.sun.star.text.WebDocument"):
strFilterSubName = "writer_web_pdf_Export"
elif oDoc.supportsService("com.sun.star.text.GlobalDocument"):
strFilterSubName = "writer_globaldocument_pdf_Export"
elif oDoc.supportsService("com.sun.star.text.TextDocument"):
strFilterSubName = "writer_pdf_Export"
elif oDoc.supportsService("com.sun.star.drawing.DrawingDocument"):
strFilterSubName = "draw_pdf_Export"
elif oDoc.supportsService("com.sun.star.formula.FormulaProperties"):
strFilterSubName = "math_pdf_Export"
elif oDoc.supportsService("com.sun.star.chart.ChartDocument"):
strFilterSubName = "chart_pdf_Export"
else:
pass
filename = len(strFilterSubName) > 0 and convertToURL( os.path.splitext( strFile )[0] + ".pdf" ) or None
if len(strFilterSubName) > 0:
oDoc.storeToURL( filename, Array(self._MakePropertyValue("FilterName", strFilterSubName ),self._MakePropertyValue("CompressMode", "1" )))
oDoc.close(True)
# Can be None if len(strFilterSubName) <= 0
return filename
def _MakePropertyValue(self, cName="", uValue=u""):
oPropertyValue = createUnoStruct( "com.sun.star.beans.PropertyValue" )
if cName:
oPropertyValue.Name = cName
if uValue:
oPropertyValue.Value = uValue
return oPropertyValue
if __name__<>"package" and __name__=="__main__":
AddAttachment(None)
elif __name__=="package":
g_ImplementationHelper.addImplementation( AddAttachment, "org.openoffice.openerp.report.addattachment", ("com.sun.star.task.Job",),)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3949,
3,
199,
3,
199,
3,
221,
1898,
334,
67,
9,
13004,
13,
15431,
577,
1189,
89,
699,
264,
2135,
366,
1398,
16793,
32,
23260,
79,
432,
23909,
848,
14,
957,
199,
3,
221,
1898,
334,
35,
9,
8353,
13,
6542,
7653,
13950,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
221,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
221,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
221,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
221,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
221,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
221,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
221,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
221,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
3,
199,
3,
221,
1666,
26,
221,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
9783,
1168,
14,
1360,
199,
3,
199,
31635,
199,
199,
646,
747,
199,
646,
625,
79,
199,
646,
625,
79,
3676,
199,
646,
19122,
199,
646,
1300,
772,
199,
504,
2414,
14,
11846,
14,
7848,
14,
1765,
492,
1323,
6694,
16752,
199,
692,
636,
354,
363,
28,
4335,
2491,
582,
272,
687,
1973,
14,
5885,
492,
627,
272,
687,
1973,
14,
705,
492,
4520,
5619,
272,
687,
1973,
14,
2537,
492,
627,
272,
687,
16430,
774,
492,
627,
272,
687,
1973,
14,
4354,
492,
627,
272,
3050,
628,
396,
2,
272,
1747,
275,
650,
199,
199,
533,
2654,
22662,
8,
324,
79,
3676,
14,
1563,
12,
1323,
6694,
16752,
3461,
272,
1804,
688,
275,
469,
267,
283,
7638,
7,
520,
283,
5607,
297,
267,
283,
4299,
31166,
356,
283,
20851,
297,
272,
789,
272,
347,
636,
826,
721,
277,
12,
4027,
304,
267,
291,
14,
3799,
258,
275,
4027,
267,
291,
14,
578,
221,
275,
298,
11267,
63,
3070,
2,
267,
291,
14,
1023,
275,
298,
16,
14,
17,
2,
267,
16430,
774,
342,
267,
340,
440,
4676,
1205,
436,
636,
354,
363,
11800,
2491,
582,
288,
4458,
8,
17,
9,
398,
291,
14,
65,
5278,
2889,
275,
942,
267,
19763,
29,
362,
20436,
342,
267,
312,
3768,
18,
275,
19763,
14,
16662,
7004,
342,
267,
1382,
815,
29,
79,
3768,
18,
14,
362,
5564,
2354,
342,
398,
2288,
15081,
267,
291,
14,
2060,
275,
15081,
267,
2288,
1166,
267,
291,
14,
5096,
29,
18612,
3298,
3552,
8,
633,
9,
267,
340,
1382,
815,
14,
32627,
792,
1110,
8,
18,
9,
20941,
3087,
436,
1382,
815,
14,
32627,
792,
1110,
8,
19,
9,
20941,
10812,
288,
291,
14,
2676,
275,
6249,
23689,
5619,
8,
2259,
12,
5238,
12,
13576,
12,
10045,
12,
298,
1123,
21328,
434,
370,
7146,
531,
288,
291,
14,
2676,
14,
525,
9515,
1872,
480,
18842,
4031,
804,
401,
499,
2360,
959,
12,
2948,
12,
1616,
12,
298,
5446,
19615,
5655,
7337,
2434,
9107,
288,
291,
14,
2676,
14,
525,
12413,
26764,
480,
6916,
4031,
804,
401,
446,
18,
12,
5661,
12,
27827,
12,
4114,
12,
549,
9,
288,
291,
14,
2676,
14,
525,
4259,
360,
9633,
11622,
12450,
4935,
297,
446,
18,
2360,
446,
21,
12,
5661,
2360,
4114,
2584,
3593,
7,
2360,
1287,
10464,
15019,
275,
291,
14,
9633,
11622,
12450,
4935,
63,
11276,
776,
267,
587,
26,
288,
291,
14,
2676,
275,
6249,
23689,
5619,
8,
2259,
12,
5238,
12,
13576,
12,
29682,
12,
298,
1123,
21328,
434,
370,
7146,
531,
288,
291,
14,
2676,
14,
525,
9515,
1872,
480,
18842,
2377,
985,
401,
18,
2360,
1749,
12,
5685,
12,
3388,
12,
298,
5446,
5673,
9107,
288,
291,
14,
2676,
14,
525,
12413,
26764,
480,
6916,
1238,
401,
446,
18,
12,
959,
12,
25956,
12,
4114,
12,
549,
9,
288,
291,
14,
6916,
1685,
275,
291,
14,
2676,
14,
25117,
8,
298,
6916,
1238,
2,
776,
288,
291,
14,
68,
1685,
275,
1052,
953,
327,
3232,
282,
892,
2557,
476,
1636,
370,
314,
1654,
953,
2762,
275,
291,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
723,
14,
578,
14,
578,
297,
283,
1733,
297,
4274,
354,
1673,
29511,
1095,
63,
3070,
63,
1238,
8157,
929,
297,
6291,
283,
7657,
2023,
288,
340,
440,
822,
8,
1580,
304,
355,
327,
982,
314,
859,
283,
1095,
63,
3070,
63,
1238,
7,
365,
440,
4903,
12,
675,
314,
849,
1402,
355,
291,
14,
68,
1685,
275,
469,
490,
298,
24120,
582,
7,
470,
14,
3899,
297,
355,
789,
288,
587,
26,
2234,
2762,
275,
277,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
1095,
14,
3070,
14,
1238,
7,
2360,
283,
1733,
297,
3073,
355,
522,
275,
291,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
1095,
14,
3070,
14,
1238,
7,
2360,
283,
739,
297,
2762,
12,
788,
354,
1673,
1238,
63,
344,
1105,
355,
1709,
275,
291,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
723,
14,
1238,
7,
2360,
283,
739,
297,
2341,
8,
2734,
671,
26,
88,
459,
1238,
63,
344,
3488,
16,
467,
522,
395,
788,
1238,
1105,
355,
1709,
275,
1211,
8,
1130,
8,
2734,
671,
20334,
88,
459,
344,
995,
88,
459,
1238,
3815,
1709,
430,
355,
291,
14,
68,
1685,
275,
1211,
8,
1130,
8,
2734,
671,
26,
334,
88,
459,
354,
995,
992,
59,
88,
459,
1238,
63,
344,
3488,
16,
13925,
522,
430,
953,
367,
1242,
315,
291,
14,
68,
1685,
14,
1612,
837,
355,
291,
14,
6916,
1685,
14,
19798,
8,
1053,
12,
291,
14,
6916
] |
[
3,
199,
3,
199,
3,
221,
1898,
334,
67,
9,
13004,
13,
15431,
577,
1189,
89,
699,
264,
2135,
366,
1398,
16793,
32,
23260,
79,
432,
23909,
848,
14,
957,
199,
3,
221,
1898,
334,
35,
9,
8353,
13,
6542,
7653,
13950,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
221,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
221,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
221,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
221,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
221,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
221,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
221,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
221,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
3,
199,
3,
221,
1666,
26,
221,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
9783,
1168,
14,
1360,
199,
3,
199,
31635,
199,
199,
646,
747,
199,
646,
625,
79,
199,
646,
625,
79,
3676,
199,
646,
19122,
199,
646,
1300,
772,
199,
504,
2414,
14,
11846,
14,
7848,
14,
1765,
492,
1323,
6694,
16752,
199,
692,
636,
354,
363,
28,
4335,
2491,
582,
272,
687,
1973,
14,
5885,
492,
627,
272,
687,
1973,
14,
705,
492,
4520,
5619,
272,
687,
1973,
14,
2537,
492,
627,
272,
687,
16430,
774,
492,
627,
272,
687,
1973,
14,
4354,
492,
627,
272,
3050,
628,
396,
2,
272,
1747,
275,
650,
199,
199,
533,
2654,
22662,
8,
324,
79,
3676,
14,
1563,
12,
1323,
6694,
16752,
3461,
272,
1804,
688,
275,
469,
267,
283,
7638,
7,
520,
283,
5607,
297,
267,
283,
4299,
31166,
356,
283,
20851,
297,
272,
789,
272,
347,
636,
826,
721,
277,
12,
4027,
304,
267,
291,
14,
3799,
258,
275,
4027,
267,
291,
14,
578,
221,
275,
298,
11267,
63,
3070,
2,
267,
291,
14,
1023,
275,
298,
16,
14,
17,
2,
267,
16430,
774,
342,
267,
340,
440,
4676,
1205,
436,
636,
354,
363,
11800,
2491,
582,
288,
4458,
8,
17,
9,
398,
291,
14,
65,
5278,
2889,
275,
942,
267,
19763,
29,
362,
20436,
342,
267,
312,
3768,
18,
275,
19763,
14,
16662,
7004,
342,
267,
1382,
815,
29,
79,
3768,
18,
14,
362,
5564,
2354,
342,
398,
2288,
15081,
267,
291,
14,
2060,
275,
15081,
267,
2288,
1166,
267,
291,
14,
5096,
29,
18612,
3298,
3552,
8,
633,
9,
267,
340,
1382,
815,
14,
32627,
792,
1110,
8,
18,
9,
20941,
3087,
436,
1382,
815,
14,
32627,
792,
1110,
8,
19,
9,
20941,
10812,
288,
291,
14,
2676,
275,
6249,
23689,
5619,
8,
2259,
12,
5238,
12,
13576,
12,
10045,
12,
298,
1123,
21328,
434,
370,
7146,
531,
288,
291,
14,
2676,
14,
525,
9515,
1872,
480,
18842,
4031,
804,
401,
499,
2360,
959,
12,
2948,
12,
1616,
12,
298,
5446,
19615,
5655,
7337,
2434,
9107,
288,
291,
14,
2676,
14,
525,
12413,
26764,
480,
6916,
4031,
804,
401,
446,
18,
12,
5661,
12,
27827,
12,
4114,
12,
549,
9,
288,
291,
14,
2676,
14,
525,
4259,
360,
9633,
11622,
12450,
4935,
297,
446,
18,
2360,
446,
21,
12,
5661,
2360,
4114,
2584,
3593,
7,
2360,
1287,
10464,
15019,
275,
291,
14,
9633,
11622,
12450,
4935,
63,
11276,
776,
267,
587,
26,
288,
291,
14,
2676,
275,
6249,
23689,
5619,
8,
2259,
12,
5238,
12,
13576,
12,
29682,
12,
298,
1123,
21328,
434,
370,
7146,
531,
288,
291,
14,
2676,
14,
525,
9515,
1872,
480,
18842,
2377,
985,
401,
18,
2360,
1749,
12,
5685,
12,
3388,
12,
298,
5446,
5673,
9107,
288,
291,
14,
2676,
14,
525,
12413,
26764,
480,
6916,
1238,
401,
446,
18,
12,
959,
12,
25956,
12,
4114,
12,
549,
9,
288,
291,
14,
6916,
1685,
275,
291,
14,
2676,
14,
25117,
8,
298,
6916,
1238,
2,
776,
288,
291,
14,
68,
1685,
275,
1052,
953,
327,
3232,
282,
892,
2557,
476,
1636,
370,
314,
1654,
953,
2762,
275,
291,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
723,
14,
578,
14,
578,
297,
283,
1733,
297,
4274,
354,
1673,
29511,
1095,
63,
3070,
63,
1238,
8157,
929,
297,
6291,
283,
7657,
2023,
288,
340,
440,
822,
8,
1580,
304,
355,
327,
982,
314,
859,
283,
1095,
63,
3070,
63,
1238,
7,
365,
440,
4903,
12,
675,
314,
849,
1402,
355,
291,
14,
68,
1685,
275,
469,
490,
298,
24120,
582,
7,
470,
14,
3899,
297,
355,
789,
288,
587,
26,
2234,
2762,
275,
277,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
1095,
14,
3070,
14,
1238,
7,
2360,
283,
1733,
297,
3073,
355,
522,
275,
291,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
1095,
14,
3070,
14,
1238,
7,
2360,
283,
739,
297,
2762,
12,
788,
354,
1673,
1238,
63,
344,
1105,
355,
1709,
275,
291,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
723,
14,
1238,
7,
2360,
283,
739,
297,
2341,
8,
2734,
671,
26,
88,
459,
1238,
63,
344,
3488,
16,
467,
522,
395,
788,
1238,
1105,
355,
1709,
275,
1211,
8,
1130,
8,
2734,
671,
20334,
88,
459,
344,
995,
88,
459,
1238,
3815,
1709,
430,
355,
291,
14,
68,
1685,
275,
1211,
8,
1130,
8,
2734,
671,
26,
334,
88,
459,
354,
995,
992,
59,
88,
459,
1238,
63,
344,
3488,
16,
13925,
522,
430,
953,
367,
1242,
315,
291,
14,
68,
1685,
14,
1612,
837,
355,
291,
14,
6916,
1685,
14,
19798,
8,
1053,
12,
291,
14,
6916,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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or
from ..utils import (
js_to_json,
determine_ext,
)
class BpbIE(InfoExtractor):
IE_DESC = 'Bundeszentrale für politische Bildung'
_VALID_URL = r'https?://(?:www\.)?bpb\.de/mediathek/(?P<id>[0-9]+)/'
_TEST = {
'url': 'http://www.bpb.de/mediathek/297/joachim-gauck-zu-1989-und-die-erinnerung-an-die-ddr',
# md5 fails in Python 2.6 due to buggy server response and wrong handling of urllib2
'md5': 'c4f84c8a8044ca9ff68bb8441d300b3f',
'info_dict': {
'id': '297',
'ext': 'mp4',
'title': 'Joachim Gauck zu 1989 und die Erinnerung an die DDR',
'description': 'Joachim Gauck, erster Beauftragter für die Stasi-Unterlagen, spricht auf dem Geschichtsforum über die friedliche Revolution 1989 und eine "gewisse Traurigkeit" im Umgang mit der DDR-Vergangenheit.'
}
}
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
title = self._html_search_regex(
r'<h2 class="white">(.*?)</h2>', webpage, 'title')
video_info_dicts = re.findall(
r"({\s*src:\s*'http://film\.bpb\.de/[^}]+})", webpage)
formats = []
for video_info in video_info_dicts:
video_info = self._parse_json(video_info, video_id, transform_source=js_to_json)
quality = video_info['quality']
video_url = video_info['src']
formats.append({
'url': video_url,
'preference': 10 if quality == 'high' else 0,
'format_note': quality,
'format_id': '%s-%s' % (quality, determine_ext(video_url)),
})
self._sort_formats(formats)
return {
'id': video_id,
'formats': formats,
'title': title,
'description': self._og_search_description(webpage),
}
|
gpl-3.0
|
[
3,
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
8586,
63,
475,
63,
1001,
12,
272,
6705,
63,
832,
12,
199,
9,
421,
199,
533,
699,
3317,
4332,
8,
18283,
304,
272,
15292,
63,
15119,
275,
283,
34,
324,
3424,
90,
484,
345,
274,
289,
17709,
82,
1115,
317,
16753,
595,
699,
668,
10335,
7,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
66,
3317,
4537,
271,
15,
4603,
1589,
75,
9448,
48,
28,
344,
9514,
16,
13,
25,
24598,
7,
339,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
66,
3317,
14,
271,
15,
4603,
1589,
75,
15,
12615,
15,
743,
1225,
1017,
13,
16750,
346,
13,
90,
85,
13,
1167,
1407,
13,
725,
13,
15130,
13,
281,
5216,
10335,
13,
290,
13,
15130,
13,
617,
82,
297,
267,
327,
6128,
21,
6918,
315,
2018,
499,
14,
22,
7037,
370,
1032,
26435,
1654,
1177,
436,
6835,
7252,
402,
4011,
18,
267,
283,
1064,
21,
356,
283,
67,
20,
70,
1349,
67,
24,
65,
24,
9111,
696,
25,
556,
2333,
2501,
1349,
2953,
68,
5863,
66,
19,
70,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
12615,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
5691,
1225,
1017,
598,
3844,
346,
1315,
85,
5851,
1407,
625,
68,
18833,
221,
539,
5216,
10335,
376,
18833,
577,
4564,
297,
288,
283,
1802,
356,
283,
5691,
1225,
1017,
598,
3844,
346,
12,
221,
1192,
351,
6423,
3844,
856,
2527,
351,
289,
17709,
82,
18833,
1933,
24950,
13,
1358,
351,
1823,
287,
12,
308,
1359,
335,
84,
282,
1286,
28548,
598,
397,
335,
1158,
1086,
10044,
13333,
121,
605,
18833,
289,
18906,
317,
595,
799,
86,
3347,
5851,
1407,
625,
68,
325,
1132,
298,
303,
87,
374,
261,
12643,
300,
528,
415,
390,
2,
3416,
738,
6649,
621,
30714,
16921,
577,
4564,
13,
3673,
71,
621,
287,
426,
390,
3530,
267,
789,
272,
789,
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,
398,
2538,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7601,
72,
18,
1021,
628,
7510,
1743,
17140,
15939,
72,
18,
4206,
9248,
12,
283,
1213,
358,
267,
3991,
63,
815,
63,
7892,
275,
295,
14,
6452,
8,
288,
519,
2,
2561,
60,
83,
10,
2164,
3427,
83,
10223,
1014,
921,
1289,
77,
4537,
66,
3317,
4537,
271,
15,
4735,
93,
2807,
1552,
401,
9248,
9,
398,
6752,
275,
942,
267,
367,
3991,
63,
815,
315,
3991,
63,
815,
63,
7892,
26,
288,
3991,
63,
815,
275,
291,
423,
1122,
63,
1001,
8,
3722,
63,
815,
12,
3991,
63,
344,
12,
5793,
63,
1365,
29,
3596,
63,
475,
63,
1001,
9,
288,
11030,
275,
3991,
63,
815,
459,
9161,
418,
288,
3991,
63,
633,
275,
3991,
63,
815,
459,
2164,
418,
288,
6752,
14,
740,
2561,
355,
283,
633,
356,
3991,
63,
633,
12,
355,
283,
14994,
356,
1616,
340,
11030,
508,
283,
6260,
7,
587,
378,
12,
355,
283,
908,
63,
4610,
356,
11030,
12,
355,
283,
908,
63,
344,
356,
1543,
83,
3295,
83,
7,
450,
334,
9161,
12,
6705,
63,
832,
8,
3722,
63,
633,
1826,
288,
3828,
398,
291,
423,
3191,
63,
6321,
8,
6321,
9,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
6321,
356,
6752,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
1802,
356,
291,
423,
974,
63,
1733,
63,
1802,
8,
12022,
395,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
8586,
63,
475,
63,
1001,
12,
272,
6705,
63,
832,
12,
199,
9,
421,
199,
533,
699,
3317,
4332,
8,
18283,
304,
272,
15292,
63,
15119,
275,
283,
34,
324,
3424,
90,
484,
345,
274,
289,
17709,
82,
1115,
317,
16753,
595,
699,
668,
10335,
7,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
66,
3317,
4537,
271,
15,
4603,
1589,
75,
9448,
48,
28,
344,
9514,
16,
13,
25,
24598,
7,
339,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
66,
3317,
14,
271,
15,
4603,
1589,
75,
15,
12615,
15,
743,
1225,
1017,
13,
16750,
346,
13,
90,
85,
13,
1167,
1407,
13,
725,
13,
15130,
13,
281,
5216,
10335,
13,
290,
13,
15130,
13,
617,
82,
297,
267,
327,
6128,
21,
6918,
315,
2018,
499,
14,
22,
7037,
370,
1032,
26435,
1654,
1177,
436,
6835,
7252,
402,
4011,
18,
267,
283,
1064,
21,
356,
283,
67,
20,
70,
1349,
67,
24,
65,
24,
9111,
696,
25,
556,
2333,
2501,
1349,
2953,
68,
5863,
66,
19,
70,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
12615,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
5691,
1225,
1017,
598,
3844,
346,
1315,
85,
5851,
1407,
625,
68,
18833,
221,
539,
5216,
10335,
376,
18833,
577,
4564,
297,
288,
283,
1802,
356,
283,
5691,
1225,
1017,
598,
3844,
346,
12,
221,
1192,
351,
6423,
3844,
856,
2527,
351,
289,
17709,
82,
18833,
1933,
24950,
13,
1358,
351,
1823,
287,
12,
308,
1359,
335,
84,
282,
1286,
28548,
598,
397,
335,
1158,
1086,
10044,
13333,
121,
605,
18833,
289,
18906,
317,
595,
799,
86,
3347,
5851,
1407,
625,
68,
325,
1132,
298,
303,
87,
374,
261,
12643,
300,
528,
415,
390,
2,
3416,
738,
6649,
621,
30714,
16921,
577,
4564,
13,
3673,
71,
621,
287,
426,
390,
3530,
267,
789,
272,
789,
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,
398,
2538,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7601,
72,
18,
1021,
628,
7510,
1743,
17140,
15939,
72,
18,
4206,
9248,
12,
283,
1213,
358,
267,
3991,
63,
815,
63,
7892,
275,
295,
14,
6452,
8,
288,
519,
2,
2561,
60,
83,
10,
2164,
3427,
83,
10223,
1014,
921,
1289,
77,
4537,
66,
3317,
4537,
271,
15,
4735,
93,
2807,
1552,
401,
9248,
9,
398,
6752,
275,
942,
267,
367,
3991,
63,
815,
315,
3991,
63,
815,
63,
7892,
26,
288,
3991,
63,
815,
275,
291,
423,
1122,
63,
1001,
8,
3722,
63,
815,
12,
3991,
63,
344,
12,
5793,
63,
1365,
29,
3596,
63,
475,
63,
1001,
9,
288,
11030,
275,
3991,
63,
815,
459,
9161,
418,
288,
3991,
63,
633,
275,
3991,
63,
815,
459,
2164,
418,
288,
6752,
14,
740,
2561,
355,
283,
633,
356,
3991,
63,
633,
12,
355,
283,
14994,
356,
1616,
340,
11030,
508,
283,
6260,
7,
587,
378,
12,
355,
283,
908,
63,
4610,
356,
11030,
12,
355,
283,
908,
63,
344,
356,
1543,
83,
3295,
83,
7,
450,
334,
9161,
12,
6705,
63,
832,
8,
3722,
63,
633,
1826,
288,
3828,
398,
291,
423,
3191,
63,
6321,
8,
6321,
9,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
6321,
356,
6752,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
1802,
356,
291,
423,
974,
63,
1733,
63,
1802,
8,
12022,
395,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
divio/django
|
tests/migrations/test_optimizer.py
|
50
|
22478
|
# -*- coding: utf-8 -*-
from django.db import migrations, models
from django.db.migrations.optimizer import MigrationOptimizer
from django.test import SimpleTestCase
from .models import CustomModelBase, EmptyManager
class OptimizerTests(SimpleTestCase):
"""
Tests the migration autodetector.
"""
def optimize(self, operations):
"""
Handy shortcut for getting results + number of loops
"""
optimizer = MigrationOptimizer()
return optimizer.optimize(operations), optimizer._iterations
def assertOptimizesTo(self, operations, expected, exact=None, less_than=None):
result, iterations = self.optimize(operations)
result = [repr(f.deconstruct()) for f in result]
expected = [repr(f.deconstruct()) for f in expected]
self.assertEqual(expected, result)
if exact is not None and iterations != exact:
raise self.failureException("Optimization did not take exactly %s iterations (it took %s)" % (exact, iterations))
if less_than is not None and iterations >= less_than:
raise self.failureException("Optimization did not take less than %s iterations (it took %s)" % (less_than, iterations))
def assertDoesNotOptimize(self, operations):
self.assertOptimizesTo(operations, operations)
def test_single(self):
"""
Tests that the optimizer does nothing on a single operation,
and that it does it in just one pass.
"""
self.assertOptimizesTo(
[migrations.DeleteModel("Foo")],
[migrations.DeleteModel("Foo")],
exact=1,
)
def test_create_delete_model(self):
"""
CreateModel and DeleteModel should collapse into nothing.
"""
self.assertOptimizesTo(
[
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
migrations.DeleteModel("Foo"),
],
[],
)
def test_create_rename_model(self):
"""
CreateModel should absorb RenameModels.
"""
managers = [('objects', EmptyManager())]
self.assertOptimizesTo(
[
migrations.CreateModel(
name="Foo",
fields=[("name", models.CharField(max_length=255))],
options={'verbose_name': 'Foo'},
bases=(CustomModelBase),
managers=managers,
),
migrations.RenameModel("Foo", "Bar"),
],
[
migrations.CreateModel(
"Bar",
[("name", models.CharField(max_length=255))],
options={'verbose_name': 'Foo'},
bases=(CustomModelBase),
managers=managers,
)
],
)
def test_rename_model_self(self):
"""
RenameModels should absorb themselves.
"""
self.assertOptimizesTo(
[
migrations.RenameModel("Foo", "Baa"),
migrations.RenameModel("Baa", "Bar"),
],
[
migrations.RenameModel("Foo", "Bar"),
],
)
def _test_create_alter_foo_delete_model(self, alter_foo):
"""
CreateModel, AlterModelTable, AlterUniqueTogether/AlterIndexTogether/
AlterOrderWithRespectTo, and DeleteModel should collapse into nothing.
"""
self.assertOptimizesTo(
[
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
migrations.AlterModelTable("Foo", "woohoo"),
alter_foo,
migrations.DeleteModel("Foo"),
],
[],
)
def test_create_alter_unique_delete_model(self):
self._test_create_alter_foo_delete_model(migrations.AlterUniqueTogether("Foo", [["a", "b"]]))
def test_create_alter_index_delete_model(self):
self._test_create_alter_foo_delete_model(migrations.AlterIndexTogether("Foo", [["a", "b"]]))
def test_create_alter_owrt_delete_model(self):
self._test_create_alter_foo_delete_model(migrations.AlterOrderWithRespectTo("Foo", "a"))
def _test_alter_alter_model(self, alter_foo, alter_bar):
"""
Two AlterUniqueTogether/AlterIndexTogether/AlterOrderWithRespectTo
should collapse into the second.
"""
self.assertOptimizesTo(
[
alter_foo,
alter_bar,
],
[
alter_bar,
],
)
def test_alter_alter_table_model(self):
self._test_alter_alter_model(
migrations.AlterModelTable("Foo", "a"),
migrations.AlterModelTable("Foo", "b"),
)
def test_alter_alter_unique_model(self):
self._test_alter_alter_model(
migrations.AlterUniqueTogether("Foo", [["a", "b"]]),
migrations.AlterUniqueTogether("Foo", [["a", "c"]]),
)
def test_alter_alter_index_model(self):
self._test_alter_alter_model(
migrations.AlterIndexTogether("Foo", [["a", "b"]]),
migrations.AlterIndexTogether("Foo", [["a", "c"]]),
)
def test_alter_alter_owrt_model(self):
self._test_alter_alter_model(
migrations.AlterOrderWithRespectTo("Foo", "a"),
migrations.AlterOrderWithRespectTo("Foo", "b"),
)
def test_optimize_through_create(self):
"""
We should be able to optimize away create/delete through a create or delete
of a different model, but only if the create operation does not mention the model
at all.
"""
# These should work
self.assertOptimizesTo(
[
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
migrations.CreateModel("Bar", [("size", models.IntegerField())]),
migrations.DeleteModel("Foo"),
],
[
migrations.CreateModel("Bar", [("size", models.IntegerField())]),
],
)
self.assertOptimizesTo(
[
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
migrations.CreateModel("Bar", [("size", models.IntegerField())]),
migrations.DeleteModel("Bar"),
migrations.DeleteModel("Foo"),
],
[],
)
self.assertOptimizesTo(
[
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
migrations.CreateModel("Bar", [("size", models.IntegerField())]),
migrations.DeleteModel("Foo"),
migrations.DeleteModel("Bar"),
],
[],
)
# This should not work - FK should block it
self.assertOptimizesTo(
[
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
migrations.CreateModel("Bar", [("other", models.ForeignKey("testapp.Foo"))]),
migrations.DeleteModel("Foo"),
],
[
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
migrations.CreateModel("Bar", [("other", models.ForeignKey("testapp.Foo"))]),
migrations.DeleteModel("Foo"),
],
)
# This should not work - bases should block it
self.assertOptimizesTo(
[
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
migrations.CreateModel("Bar", [("size", models.IntegerField())], bases=("testapp.Foo", )),
migrations.DeleteModel("Foo"),
],
[
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
migrations.CreateModel("Bar", [("size", models.IntegerField())], bases=("testapp.Foo", )),
migrations.DeleteModel("Foo"),
],
)
def test_create_model_add_field(self):
"""
AddField should optimize into CreateModel.
"""
managers = [('objects', EmptyManager())]
self.assertOptimizesTo(
[
migrations.CreateModel(
name="Foo",
fields=[("name", models.CharField(max_length=255))],
options={'verbose_name': 'Foo'},
bases=(CustomModelBase),
managers=managers,
),
migrations.AddField("Foo", "age", models.IntegerField()),
],
[
migrations.CreateModel(
name="Foo",
fields=[
("name", models.CharField(max_length=255)),
("age", models.IntegerField()),
],
options={'verbose_name': 'Foo'},
bases=(CustomModelBase),
managers=managers,
),
],
)
def test_create_model_add_field_not_through_fk(self):
"""
AddField should NOT optimize into CreateModel if it's an FK to a model
that's between them.
"""
self.assertOptimizesTo(
[
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
migrations.CreateModel("Link", [("url", models.TextField())]),
migrations.AddField("Foo", "link", models.ForeignKey("migrations.Link")),
],
[
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
migrations.CreateModel("Link", [("url", models.TextField())]),
migrations.AddField("Foo", "link", models.ForeignKey("migrations.Link")),
],
)
def test_create_model_add_field_not_through_m2m_through(self):
"""
AddField should NOT optimize into CreateModel if it's an M2M using a
through that's created between them.
"""
# Note: The middle model is not actually a valid through model,
# but that doesn't matter, as we never render it.
self.assertOptimizesTo(
[
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
migrations.CreateModel("LinkThrough", []),
migrations.AddField("Foo", "link", models.ManyToManyField("migrations.Link", through="migrations.LinkThrough")),
],
[
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
migrations.CreateModel("LinkThrough", []),
migrations.AddField("Foo", "link", models.ManyToManyField("migrations.Link", through="migrations.LinkThrough")),
],
)
def test_create_model_alter_field(self):
"""
AlterField should optimize into CreateModel.
"""
managers = [('objects', EmptyManager())]
self.assertOptimizesTo(
[
migrations.CreateModel(
name="Foo",
fields=[("name", models.CharField(max_length=255))],
options={'verbose_name': 'Foo'},
bases=(CustomModelBase),
managers=managers,
),
migrations.AlterField("Foo", "name", models.IntegerField()),
],
[
migrations.CreateModel(
name="Foo",
fields=[
("name", models.IntegerField()),
],
options={'verbose_name': 'Foo'},
bases=(CustomModelBase),
managers=managers,
),
],
)
def test_create_model_rename_field(self):
"""
RenameField should optimize into CreateModel.
"""
managers = [('objects', EmptyManager())]
self.assertOptimizesTo(
[
migrations.CreateModel(
name="Foo",
fields=[("name", models.CharField(max_length=255))],
options={'verbose_name': 'Foo'},
bases=(CustomModelBase),
managers=managers,
),
migrations.RenameField("Foo", "name", "title"),
],
[
migrations.CreateModel(
name="Foo",
fields=[
("title", models.CharField(max_length=255)),
],
options={'verbose_name': 'Foo'},
bases=(CustomModelBase),
managers=managers,
),
],
)
def test_add_field_rename_field(self):
"""
RenameField should optimize into AddField
"""
self.assertOptimizesTo(
[
migrations.AddField("Foo", "name", models.CharField(max_length=255)),
migrations.RenameField("Foo", "name", "title"),
],
[
migrations.AddField("Foo", "title", models.CharField(max_length=255)),
],
)
def test_alter_field_rename_field(self):
"""
RenameField should optimize to the other side of AlterField,
and into itself.
"""
self.assertOptimizesTo(
[
migrations.AlterField("Foo", "name", models.CharField(max_length=255)),
migrations.RenameField("Foo", "name", "title"),
migrations.RenameField("Foo", "title", "nom"),
],
[
migrations.RenameField("Foo", "name", "nom"),
migrations.AlterField("Foo", "nom", models.CharField(max_length=255)),
],
)
def test_create_model_remove_field(self):
"""
RemoveField should optimize into CreateModel.
"""
managers = [('objects', EmptyManager())]
self.assertOptimizesTo(
[
migrations.CreateModel(
name="Foo",
fields=[
("name", models.CharField(max_length=255)),
("age", models.IntegerField()),
],
options={'verbose_name': 'Foo'},
bases=(CustomModelBase),
managers=managers,
),
migrations.RemoveField("Foo", "age"),
],
[
migrations.CreateModel(
name="Foo",
fields=[
("name", models.CharField(max_length=255)),
],
options={'verbose_name': 'Foo'},
bases=(CustomModelBase),
managers=managers,
),
],
)
def test_add_field_alter_field(self):
"""
AlterField should optimize into AddField.
"""
self.assertOptimizesTo(
[
migrations.AddField("Foo", "age", models.IntegerField()),
migrations.AlterField("Foo", "age", models.FloatField(default=2.4)),
],
[
migrations.AddField("Foo", name="age", field=models.FloatField(default=2.4)),
],
)
def test_add_field_delete_field(self):
"""
RemoveField should cancel AddField
"""
self.assertOptimizesTo(
[
migrations.AddField("Foo", "age", models.IntegerField()),
migrations.RemoveField("Foo", "age"),
],
[],
)
def test_alter_field_delete_field(self):
"""
RemoveField should absorb AlterField
"""
self.assertOptimizesTo(
[
migrations.AlterField("Foo", "age", models.IntegerField()),
migrations.RemoveField("Foo", "age"),
],
[
migrations.RemoveField("Foo", "age"),
],
)
def _test_create_alter_foo_field(self, alter):
"""
CreateModel, AlterFooTogether/AlterOrderWithRespectTo followed by an
add/alter/rename field should optimize to CreateModel and the Alter*
"""
# AddField
self.assertOptimizesTo(
[
migrations.CreateModel("Foo", [
("a", models.IntegerField()),
("b", models.IntegerField()),
]),
alter,
migrations.AddField("Foo", "c", models.IntegerField()),
],
[
migrations.CreateModel("Foo", [
("a", models.IntegerField()),
("b", models.IntegerField()),
("c", models.IntegerField()),
]),
alter,
],
)
# AlterField
self.assertDoesNotOptimize(
[
migrations.CreateModel("Foo", [
("a", models.IntegerField()),
("b", models.IntegerField()),
]),
alter,
migrations.AlterField("Foo", "b", models.CharField(max_length=255)),
],
)
self.assertOptimizesTo(
[
migrations.CreateModel("Foo", [
("a", models.IntegerField()),
("b", models.IntegerField()),
("c", models.IntegerField()),
]),
alter,
migrations.AlterField("Foo", "c", models.CharField(max_length=255)),
],
[
migrations.CreateModel("Foo", [
("a", models.IntegerField()),
("b", models.IntegerField()),
("c", models.CharField(max_length=255)),
]),
alter,
],
)
# RenameField
self.assertDoesNotOptimize(
[
migrations.CreateModel("Foo", [
("a", models.IntegerField()),
("b", models.IntegerField()),
]),
alter,
migrations.RenameField("Foo", "b", "c"),
],
)
self.assertOptimizesTo(
[
migrations.CreateModel("Foo", [
("a", models.IntegerField()),
("b", models.IntegerField()),
]),
alter,
migrations.RenameField("Foo", "b", "x"),
migrations.RenameField("Foo", "x", "c"),
],
[
migrations.CreateModel("Foo", [
("a", models.IntegerField()),
("b", models.IntegerField()),
]),
alter,
migrations.RenameField("Foo", "b", "c"),
],
)
self.assertOptimizesTo(
[
migrations.CreateModel("Foo", [
("a", models.IntegerField()),
("b", models.IntegerField()),
("c", models.IntegerField()),
]),
alter,
migrations.RenameField("Foo", "c", "d"),
],
[
migrations.CreateModel("Foo", [
("a", models.IntegerField()),
("b", models.IntegerField()),
("d", models.IntegerField()),
]),
alter,
],
)
# RemoveField
self.assertDoesNotOptimize(
[
migrations.CreateModel("Foo", [
("a", models.IntegerField()),
("b", models.IntegerField()),
]),
alter,
migrations.RemoveField("Foo", "b"),
],
)
self.assertOptimizesTo(
[
migrations.CreateModel("Foo", [
("a", models.IntegerField()),
("b", models.IntegerField()),
("c", models.IntegerField()),
]),
alter,
migrations.RemoveField("Foo", "c"),
],
[
migrations.CreateModel("Foo", [
("a", models.IntegerField()),
("b", models.IntegerField()),
]),
alter,
],
)
def test_create_alter_unique_field(self):
self._test_create_alter_foo_field(migrations.AlterUniqueTogether("Foo", [["a", "b"]]))
def test_create_alter_index_field(self):
self._test_create_alter_foo_field(migrations.AlterIndexTogether("Foo", [["a", "b"]]))
def test_create_alter_owrt_field(self):
self._test_create_alter_foo_field(migrations.AlterOrderWithRespectTo("Foo", "b"))
def test_optimize_through_fields(self):
"""
Checks that field-level through checking is working.
This should manage to collapse model Foo to nonexistence,
and model Bar to a single IntegerField called "width".
"""
self.assertOptimizesTo(
[
migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
migrations.CreateModel("Bar", [("size", models.IntegerField())]),
migrations.AddField("Foo", "age", models.IntegerField()),
migrations.AddField("Bar", "width", models.IntegerField()),
migrations.AlterField("Foo", "age", models.IntegerField()),
migrations.RenameField("Bar", "size", "dimensions"),
migrations.RemoveField("Foo", "age"),
migrations.RenameModel("Foo", "Phou"),
migrations.RemoveField("Bar", "dimensions"),
migrations.RenameModel("Phou", "Fou"),
migrations.DeleteModel("Fou"),
],
[
migrations.CreateModel("Bar", [("width", models.IntegerField())]),
],
)
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
504,
1639,
14,
697,
14,
7685,
14,
12290,
492,
12090,
13946,
199,
504,
1639,
14,
396,
492,
24424,
199,
199,
504,
1275,
992,
492,
8388,
1685,
1563,
12,
9630,
2988,
421,
199,
533,
19246,
1793,
2925,
8,
17968,
304,
272,
408,
272,
6496,
314,
8367,
28537,
9119,
14,
272,
408,
339,
347,
13497,
8,
277,
12,
5331,
304,
267,
408,
267,
18405,
89,
17522,
367,
10232,
2058,
435,
1329,
402,
17222,
267,
408,
267,
10736,
275,
12090,
13946,
342,
267,
372,
10736,
14,
13416,
8,
8170,
395,
10736,
423,
13570,
339,
347,
702,
9867,
6491,
1378,
8,
277,
12,
5331,
12,
1420,
12,
5835,
29,
403,
12,
6656,
63,
13797,
29,
403,
304,
267,
754,
12,
10615,
275,
291,
14,
13416,
8,
8170,
9,
267,
754,
275,
359,
2722,
8,
70,
14,
23693,
1012,
367,
289,
315,
754,
61,
267,
1420,
275,
359,
2722,
8,
70,
14,
23693,
1012,
367,
289,
315,
1420,
61,
267,
291,
14,
629,
8,
2062,
12,
754,
9,
267,
340,
5835,
365,
440,
488,
436,
10615,
1137,
5835,
26,
288,
746,
291,
14,
15935,
480,
30661,
8103,
440,
5452,
8840,
450,
83,
10615,
334,
390,
27221,
450,
83,
2924,
450,
334,
7327,
12,
10615,
430,
267,
340,
6656,
63,
13797,
365,
440,
488,
436,
10615,
2356,
6656,
63,
13797,
26,
288,
746,
291,
14,
15935,
480,
30661,
8103,
440,
5452,
6656,
2419,
450,
83,
10615,
334,
390,
27221,
450,
83,
2924,
450,
334,
2003,
63,
13797,
12,
10615,
430,
339,
347,
702,
7193,
30474,
8,
277,
12,
5331,
304,
267,
291,
14,
479,
9867,
6491,
1378,
8,
8170,
12,
5331,
9,
339,
347,
511,
63,
4780,
8,
277,
304,
267,
408,
267,
6496,
626,
314,
10736,
1630,
6548,
641,
282,
2849,
3439,
12,
267,
436,
626,
652,
1630,
652,
315,
2951,
1373,
986,
14,
267,
408,
267,
291,
14,
479,
9867,
6491,
1378,
8,
288,
359,
7685,
14,
5392,
1685,
480,
5686,
17857,
288,
359,
7685,
14,
5392,
1685,
480,
5686,
17857,
288,
5835,
29,
17,
12,
267,
776,
339,
347,
511,
63,
981,
63,
1807,
63,
1238,
8,
277,
304,
267,
408,
267,
2790,
1685,
436,
8496,
1685,
1077,
24311,
1901,
6548,
14,
267,
408,
267,
291,
14,
479,
9867,
6491,
1378,
8,
288,
359,
355,
6180,
14,
14907,
480,
5686,
401,
10003,
354,
401,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
430,
2522,
355,
6180,
14,
5392,
1685,
480,
5686,
1288,
288,
2156,
288,
990,
267,
776,
339,
347,
511,
63,
981,
63,
8165,
63,
1238,
8,
277,
304,
267,
408,
267,
2790,
1685,
1077,
2236,
1509,
66,
22756,
20474,
14,
267,
408,
267,
19680,
275,
4274,
1462,
297,
9630,
2988,
24821,
267,
291,
14,
479,
9867,
6491,
1378,
8,
288,
359,
355,
6180,
14,
14907,
8,
490,
536,
628,
5686,
401,
490,
1504,
1524,
480,
354,
401,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
25106,
490,
1511,
3713,
3832,
63,
354,
356,
283,
5686,
2267,
490,
9768,
2687,
7223,
1685,
1563,
395,
490,
19680,
29,
16259,
12,
355,
2318,
355,
6180,
14,
16843,
1685,
480,
5686,
401,
298,
5281,
1288,
288,
2156,
288,
359,
355,
6180,
14,
14907,
8,
490,
298,
5281,
401,
490,
10003,
354,
401,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
25106,
490,
1511,
3713,
3832,
63,
354,
356,
283,
5686,
2267,
490,
9768,
2687,
7223,
1685,
1563,
395,
490,
19680,
29,
16259,
12,
355,
776,
288,
2156,
267,
776,
339,
347,
511,
63,
8165,
63,
1238,
63,
277,
8,
277,
304,
267,
408,
267,
22756,
20474,
1077,
2236,
1509,
66,
17279,
14,
267,
408,
267,
291,
14,
479,
9867,
6491,
1378,
8,
288,
359,
355,
6180,
14,
16843,
1685,
480,
5686,
401,
298,
34,
2158,
1288,
355,
6180,
14,
16843,
1685,
480,
34,
2158,
401,
298,
5281,
1288,
288,
2156,
288,
359,
355,
6180,
14,
16843,
1685,
480,
5686,
401,
298,
5281,
1288,
288,
2156,
267,
776,
339,
347,
485,
396,
63,
981,
63,
11858,
63,
1421,
63,
1807,
63,
1238,
8,
277,
12,
17355,
63,
1421,
304,
267,
408,
267,
2790,
1685,
12,
4580,
351,
1685,
3186,
12,
4580,
351,
11427,
1378,
4920,
15,
14364,
2681,
1378,
4920,
15,
267,
4580,
351,
4738,
3007,
1322,
1764,
1378,
12,
436,
8496,
1685,
1077,
24311,
1901,
6548,
14,
267,
408,
267,
291,
14,
479,
9867,
6491,
1378,
8,
288,
359,
355,
6180,
14,
14907,
480,
5686,
401,
10003,
354,
401,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
430,
2522,
355,
6180,
14,
14364,
1685,
3186,
480,
5686,
401,
298,
87,
1534,
19112,
1288,
355,
17355,
63,
1421,
12,
355,
6180,
14,
5392,
1685,
480,
5686,
1288,
288,
2156,
288,
990,
267,
776,
339,
347,
511,
63,
981,
63,
11858,
63,
3235,
63,
1807,
63,
1238,
8,
277,
304,
267,
291,
423,
396,
63,
981,
63,
11858,
63,
1421,
63,
1807,
63,
1238,
8,
7685,
14,
14364,
11427,
1378,
4920,
480,
5686,
401,
24212,
65,
401,
298,
66,
937,
2459,
339,
347,
511,
63,
981,
63,
11858,
63,
1080,
63,
1807,
63,
1238,
8,
277,
304,
267,
291,
423,
396,
63,
981,
63,
11858,
63,
1421,
63,
1807,
63,
1238,
8,
7685,
14,
14364,
2681,
1378,
4920,
480,
5686,
401,
24212,
65,
401,
298,
66,
937,
2459,
339,
347,
511,
63,
981,
63,
11858,
63,
583,
2591,
63,
1807,
63,
1238,
8,
277,
304,
267,
291,
423,
396,
63,
981,
63,
11858,
63,
1421,
63,
1807,
63,
1238,
8,
7685,
14,
14364,
4738,
3007,
1322,
1764,
1378,
480,
5686,
401,
298,
65,
2237,
339,
347,
485,
396,
63,
11858,
63,
11858,
63,
1238,
8,
277,
12,
17355,
63,
1421,
12,
17355,
63,
1700,
304,
267,
408,
267,
16853,
4580,
351,
11427,
1378,
4920,
15,
14364,
2681,
1378,
4920,
15,
14364,
4738,
3007,
1322,
1764,
1378,
267,
1077,
24311,
1901,
314,
3499,
14,
267,
408,
267,
291,
14,
479,
9867,
6491,
1378,
8,
288,
359,
355,
17355,
63,
1421,
12,
355,
17355,
63,
1700,
12,
288,
2156,
288,
359,
355,
17355,
63,
1700,
12,
288,
2156,
267,
776,
339,
347,
511,
63,
11858,
63,
11858,
63,
1224,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
504,
1639,
14,
697,
14,
7685,
14,
12290,
492,
12090,
13946,
199,
504,
1639,
14,
396,
492,
24424,
199,
199,
504,
1275,
992,
492,
8388,
1685,
1563,
12,
9630,
2988,
421,
199,
533,
19246,
1793,
2925,
8,
17968,
304,
272,
408,
272,
6496,
314,
8367,
28537,
9119,
14,
272,
408,
339,
347,
13497,
8,
277,
12,
5331,
304,
267,
408,
267,
18405,
89,
17522,
367,
10232,
2058,
435,
1329,
402,
17222,
267,
408,
267,
10736,
275,
12090,
13946,
342,
267,
372,
10736,
14,
13416,
8,
8170,
395,
10736,
423,
13570,
339,
347,
702,
9867,
6491,
1378,
8,
277,
12,
5331,
12,
1420,
12,
5835,
29,
403,
12,
6656,
63,
13797,
29,
403,
304,
267,
754,
12,
10615,
275,
291,
14,
13416,
8,
8170,
9,
267,
754,
275,
359,
2722,
8,
70,
14,
23693,
1012,
367,
289,
315,
754,
61,
267,
1420,
275,
359,
2722,
8,
70,
14,
23693,
1012,
367,
289,
315,
1420,
61,
267,
291,
14,
629,
8,
2062,
12,
754,
9,
267,
340,
5835,
365,
440,
488,
436,
10615,
1137,
5835,
26,
288,
746,
291,
14,
15935,
480,
30661,
8103,
440,
5452,
8840,
450,
83,
10615,
334,
390,
27221,
450,
83,
2924,
450,
334,
7327,
12,
10615,
430,
267,
340,
6656,
63,
13797,
365,
440,
488,
436,
10615,
2356,
6656,
63,
13797,
26,
288,
746,
291,
14,
15935,
480,
30661,
8103,
440,
5452,
6656,
2419,
450,
83,
10615,
334,
390,
27221,
450,
83,
2924,
450,
334,
2003,
63,
13797,
12,
10615,
430,
339,
347,
702,
7193,
30474,
8,
277,
12,
5331,
304,
267,
291,
14,
479,
9867,
6491,
1378,
8,
8170,
12,
5331,
9,
339,
347,
511,
63,
4780,
8,
277,
304,
267,
408,
267,
6496,
626,
314,
10736,
1630,
6548,
641,
282,
2849,
3439,
12,
267,
436,
626,
652,
1630,
652,
315,
2951,
1373,
986,
14,
267,
408,
267,
291,
14,
479,
9867,
6491,
1378,
8,
288,
359,
7685,
14,
5392,
1685,
480,
5686,
17857,
288,
359,
7685,
14,
5392,
1685,
480,
5686,
17857,
288,
5835,
29,
17,
12,
267,
776,
339,
347,
511,
63,
981,
63,
1807,
63,
1238,
8,
277,
304,
267,
408,
267,
2790,
1685,
436,
8496,
1685,
1077,
24311,
1901,
6548,
14,
267,
408,
267,
291,
14,
479,
9867,
6491,
1378,
8,
288,
359,
355,
6180,
14,
14907,
480,
5686,
401,
10003,
354,
401,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
430,
2522,
355,
6180,
14,
5392,
1685,
480,
5686,
1288,
288,
2156,
288,
990,
267,
776,
339,
347,
511,
63,
981,
63,
8165,
63,
1238,
8,
277,
304,
267,
408,
267,
2790,
1685,
1077,
2236,
1509,
66,
22756,
20474,
14,
267,
408,
267,
19680,
275,
4274,
1462,
297,
9630,
2988,
24821,
267,
291,
14,
479,
9867,
6491,
1378,
8,
288,
359,
355,
6180,
14,
14907,
8,
490,
536,
628,
5686,
401,
490,
1504,
1524,
480,
354,
401,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
25106,
490,
1511,
3713,
3832,
63,
354,
356,
283,
5686,
2267,
490,
9768,
2687,
7223,
1685,
1563,
395,
490,
19680,
29,
16259,
12,
355,
2318,
355,
6180,
14,
16843,
1685,
480,
5686,
401,
298,
5281,
1288,
288,
2156,
288,
359,
355,
6180,
14,
14907,
8,
490,
298,
5281,
401,
490,
10003,
354,
401,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
25106,
490,
1511,
3713,
3832,
63,
354,
356,
283,
5686,
2267,
490,
9768,
2687,
7223,
1685,
1563,
395,
490,
19680,
29,
16259,
12,
355,
776,
288,
2156,
267,
776,
339,
347,
511,
63,
8165,
63,
1238,
63,
277,
8,
277,
304,
267,
408,
267,
22756,
20474,
1077,
2236,
1509,
66,
17279,
14,
267,
408,
267,
291,
14,
479,
9867,
6491,
1378,
8,
288,
359,
355,
6180,
14,
16843,
1685,
480,
5686,
401,
298,
34,
2158,
1288,
355,
6180,
14,
16843,
1685,
480,
34,
2158,
401,
298,
5281,
1288,
288,
2156,
288,
359,
355,
6180,
14,
16843,
1685,
480,
5686,
401,
298,
5281,
1288,
288,
2156,
267,
776,
339,
347,
485,
396,
63,
981,
63,
11858,
63,
1421,
63,
1807,
63,
1238,
8,
277,
12,
17355,
63,
1421,
304,
267,
408,
267,
2790,
1685,
12,
4580,
351,
1685,
3186,
12,
4580,
351,
11427,
1378,
4920,
15,
14364,
2681,
1378,
4920,
15,
267,
4580,
351,
4738,
3007,
1322,
1764,
1378,
12,
436,
8496,
1685,
1077,
24311,
1901,
6548,
14,
267,
408,
267,
291,
14,
479,
9867,
6491,
1378,
8,
288,
359,
355,
6180,
14,
14907,
480,
5686,
401,
10003,
354,
401,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
430,
2522,
355,
6180,
14,
14364,
1685,
3186,
480,
5686,
401,
298,
87,
1534,
19112,
1288,
355,
17355,
63,
1421,
12,
355,
6180,
14,
5392,
1685,
480,
5686,
1288,
288,
2156,
288,
990,
267,
776,
339,
347,
511,
63,
981,
63,
11858,
63,
3235,
63,
1807,
63,
1238,
8,
277,
304,
267,
291,
423,
396,
63,
981,
63,
11858,
63,
1421,
63,
1807,
63,
1238,
8,
7685,
14,
14364,
11427,
1378,
4920,
480,
5686,
401,
24212,
65,
401,
298,
66,
937,
2459,
339,
347,
511,
63,
981,
63,
11858,
63,
1080,
63,
1807,
63,
1238,
8,
277,
304,
267,
291,
423,
396,
63,
981,
63,
11858,
63,
1421,
63,
1807,
63,
1238,
8,
7685,
14,
14364,
2681,
1378,
4920,
480,
5686,
401,
24212,
65,
401,
298,
66,
937,
2459,
339,
347,
511,
63,
981,
63,
11858,
63,
583,
2591,
63,
1807,
63,
1238,
8,
277,
304,
267,
291,
423,
396,
63,
981,
63,
11858,
63,
1421,
63,
1807,
63,
1238,
8,
7685,
14,
14364,
4738,
3007,
1322,
1764,
1378,
480,
5686,
401,
298,
65,
2237,
339,
347,
485,
396,
63,
11858,
63,
11858,
63,
1238,
8,
277,
12,
17355,
63,
1421,
12,
17355,
63,
1700,
304,
267,
408,
267,
16853,
4580,
351,
11427,
1378,
4920,
15,
14364,
2681,
1378,
4920,
15,
14364,
4738,
3007,
1322,
1764,
1378,
267,
1077,
24311,
1901,
314,
3499,
14,
267,
408,
267,
291,
14,
479,
9867,
6491,
1378,
8,
288,
359,
355,
17355,
63,
1421,
12,
355,
17355,
63,
1700,
12,
288,
2156,
288,
359,
355,
17355,
63,
1700,
12,
288,
2156,
267,
776,
339,
347,
511,
63,
11858,
63,
11858,
63,
1224,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
ludobox/ludobox-ui
|
server/setup.py
|
2
|
2226
|
# ludobox setup.py
"""Setup script for Ludobox."""
# Copyright (C) 2016 Pierre-Yves Martin for DCALK
#
# 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 os
import sys
try:
from setuptools import setup, find_packages
from setuptools.command.install import install
except ImportError:
from distutils.core import setup, find_packages, install
# Leave the following line to match the regexp [0-9]*\.[0-9]*\.[0-9]*
version = "0.9.26" # [major].[minor].[release]
# parse README
with open('../README.md') as readme_file:
long_description = readme_file.read()
# parse requirements
with open('requirements.txt') as f:
required = [x for x in f.read().splitlines()]
setup(
name="ludobox",
packages=find_packages(exclude=['client','tests', 'model', 'data', 'docs', 'templates']),
version=version,
description="Ludobox",
long_description=long_description,
author="DCALK",
author_email="info@ludobox.net",
url="http://ludobox.net",
download_url="http://github.com/ludobox/ludobox-ui",
include_package_data=True,
keywords=["game", "public domain"],
entry_points={
'console_scripts': [
'ludobox = ludobox.main:main'
],
},
license='GPL',
classifiers=[
"Programming Language :: Python",
"Environment :: Other Environment",
"Development Status :: 2 - Pre-Alpha",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Python Modules",
],
install_requires=required,
test_suite='tests'
)
|
agpl-3.0
|
[
3,
634,
5916,
1977,
3272,
14,
647,
199,
199,
624,
8555,
2884,
367,
491,
5916,
1977,
1041,
199,
199,
3,
1898,
334,
35,
9,
7800,
221,
510,
4446,
264,
13,
57,
2310,
603,
26788,
367,
577,
13329,
43,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
199,
3,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
747,
199,
646,
984,
199,
199,
893,
26,
272,
687,
9116,
492,
3272,
12,
2342,
63,
5154,
272,
687,
9116,
14,
1531,
14,
3174,
492,
3907,
199,
2590,
3545,
26,
272,
687,
7065,
14,
1018,
492,
3272,
12,
2342,
63,
5154,
12,
3907,
199,
199,
3,
28015,
314,
2569,
1004,
370,
1336,
314,
13156,
359,
16,
13,
25,
3672,
27658,
16,
13,
25,
3672,
27658,
16,
13,
25,
3672,
199,
1023,
275,
298,
16,
14,
25,
14,
1479,
2,
221,
327,
359,
8452,
1055,
59,
11067,
1055,
59,
3221,
61,
199,
199,
3,
2198,
27781,
199,
1045,
1551,
24592,
18195,
14,
1064,
358,
465,
1586,
278,
63,
493,
26,
272,
1846,
63,
1802,
275,
1586,
278,
63,
493,
14,
739,
342,
199,
199,
3,
2198,
9760,
199,
1045,
1551,
360,
7538,
14,
2424,
358,
465,
289,
26,
272,
1415,
275,
359,
88,
367,
671,
315,
289,
14,
739,
1252,
7644,
5106,
199,
199,
2758,
8,
272,
536,
628,
76,
5916,
1977,
401,
272,
6117,
29,
1623,
63,
5154,
8,
5473,
2968,
1258,
1673,
2219,
297,
283,
1238,
297,
283,
576,
297,
283,
4757,
297,
283,
5876,
3815,
272,
1015,
29,
1023,
12,
272,
1369,
628,
44,
5916,
1977,
401,
272,
1846,
63,
1802,
29,
2809,
63,
1802,
12,
272,
4132,
628,
5196,
748,
43,
401,
272,
4132,
63,
2123,
628,
815,
32,
76,
5916,
1977,
14,
846,
401,
272,
1166,
628,
1014,
921,
76,
5916,
1977,
14,
846,
401,
272,
5235,
63,
633,
628,
1014,
921,
5031,
14,
957,
15,
76,
5916,
1977,
15,
76,
5916,
1977,
13,
1907,
401,
272,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
7681,
6270,
5097,
401,
298,
3455,
2881,
2255,
272,
2397,
63,
3438,
3126,
267,
283,
6614,
63,
6429,
356,
359,
288,
283,
76,
5916,
1977,
275,
634,
5916,
1977,
14,
973,
26,
973,
7,
267,
2156,
272,
1660,
272,
4190,
534,
12006,
297,
272,
19137,
1524,
267,
298,
11411,
8466,
3800,
2018,
401,
267,
298,
8263,
3800,
5439,
9711,
401,
267,
298,
23753,
9795,
3800,
499,
446,
5543,
13,
16192,
401,
267,
298,
23910,
23975,
3800,
23493,
401,
267,
298,
23699,
6187,
3800,
4403,
1010,
7106,
401,
267,
298,
12157,
3800,
2290,
15290,
3800,
31454,
3800,
2018,
18167,
401,
272,
2156,
272,
3907,
63,
6537,
29,
2427,
12,
272,
511,
63,
5768,
534,
2219,
7,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
634,
5916,
1977,
3272,
14,
647,
199,
199,
624,
8555,
2884,
367,
491,
5916,
1977,
1041,
199,
199,
3,
1898,
334,
35,
9,
7800,
221,
510,
4446,
264,
13,
57,
2310,
603,
26788,
367,
577,
13329,
43,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
199,
3,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
747,
199,
646,
984,
199,
199,
893,
26,
272,
687,
9116,
492,
3272,
12,
2342,
63,
5154,
272,
687,
9116,
14,
1531,
14,
3174,
492,
3907,
199,
2590,
3545,
26,
272,
687,
7065,
14,
1018,
492,
3272,
12,
2342,
63,
5154,
12,
3907,
199,
199,
3,
28015,
314,
2569,
1004,
370,
1336,
314,
13156,
359,
16,
13,
25,
3672,
27658,
16,
13,
25,
3672,
27658,
16,
13,
25,
3672,
199,
1023,
275,
298,
16,
14,
25,
14,
1479,
2,
221,
327,
359,
8452,
1055,
59,
11067,
1055,
59,
3221,
61,
199,
199,
3,
2198,
27781,
199,
1045,
1551,
24592,
18195,
14,
1064,
358,
465,
1586,
278,
63,
493,
26,
272,
1846,
63,
1802,
275,
1586,
278,
63,
493,
14,
739,
342,
199,
199,
3,
2198,
9760,
199,
1045,
1551,
360,
7538,
14,
2424,
358,
465,
289,
26,
272,
1415,
275,
359,
88,
367,
671,
315,
289,
14,
739,
1252,
7644,
5106,
199,
199,
2758,
8,
272,
536,
628,
76,
5916,
1977,
401,
272,
6117,
29,
1623,
63,
5154,
8,
5473,
2968,
1258,
1673,
2219,
297,
283,
1238,
297,
283,
576,
297,
283,
4757,
297,
283,
5876,
3815,
272,
1015,
29,
1023,
12,
272,
1369,
628,
44,
5916,
1977,
401,
272,
1846,
63,
1802,
29,
2809,
63,
1802,
12,
272,
4132,
628,
5196,
748,
43,
401,
272,
4132,
63,
2123,
628,
815,
32,
76,
5916,
1977,
14,
846,
401,
272,
1166,
628,
1014,
921,
76,
5916,
1977,
14,
846,
401,
272,
5235,
63,
633,
628,
1014,
921,
5031,
14,
957,
15,
76,
5916,
1977,
15,
76,
5916,
1977,
13,
1907,
401,
272,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
7681,
6270,
5097,
401,
298,
3455,
2881,
2255,
272,
2397,
63,
3438,
3126,
267,
283,
6614,
63,
6429,
356,
359,
288,
283,
76,
5916,
1977,
275,
634,
5916,
1977,
14,
973,
26,
973,
7,
267,
2156,
272,
1660,
272,
4190,
534,
12006,
297,
272,
19137,
1524,
267,
298,
11411,
8466,
3800,
2018,
401,
267,
298,
8263,
3800,
5439,
9711,
401,
267,
298,
23753,
9795,
3800,
499,
446,
5543,
13,
16192,
401,
267,
298,
23910,
23975,
3800,
23493,
401,
267,
298,
23699,
6187,
3800,
4403,
1010,
7106,
401,
267,
298,
12157,
3800,
2290,
15290,
3800,
31454,
3800,
2018,
18167,
401,
272,
2156,
272,
3907,
63,
6537,
29,
2427,
12,
272,
511,
63,
5768,
534,
2219,
7,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
BT-ojossen/odoo
|
addons/payment_ogone/controllers/main.py
|
389
|
1179
|
# -*- coding: utf-8 -*-
import logging
import pprint
import werkzeug
from openerp import http, SUPERUSER_ID
from openerp.http import request
_logger = logging.getLogger(__name__)
class OgoneController(http.Controller):
_accept_url = '/payment/ogone/test/accept'
_decline_url = '/payment/ogone/test/decline'
_exception_url = '/payment/ogone/test/exception'
_cancel_url = '/payment/ogone/test/cancel'
@http.route([
'/payment/ogone/accept', '/payment/ogone/test/accept',
'/payment/ogone/decline', '/payment/ogone/test/decline',
'/payment/ogone/exception', '/payment/ogone/test/exception',
'/payment/ogone/cancel', '/payment/ogone/test/cancel',
], type='http', auth='none')
def ogone_form_feedback(self, **post):
""" Ogone contacts using GET, at least for accept """
_logger.info('Ogone: entering form_feedback with post data %s', pprint.pformat(post)) # debug
cr, uid, context = request.cr, SUPERUSER_ID, request.context
request.registry['payment.transaction'].form_feedback(cr, uid, post, 'ogone', context=context)
return werkzeug.utils.redirect(post.pop('return_url', '/'))
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2050,
199,
646,
10933,
199,
646,
10380,
199,
199,
504,
5166,
492,
1455,
12,
12824,
63,
998,
199,
504,
5166,
14,
1014,
492,
1056,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
593,
32227,
7506,
8,
1014,
14,
7506,
304,
272,
485,
5694,
63,
633,
275,
1994,
7948,
15,
29163,
15,
396,
15,
5694,
7,
272,
485,
9427,
1132,
63,
633,
275,
1994,
7948,
15,
29163,
15,
396,
15,
9427,
1132,
7,
272,
485,
1971,
63,
633,
275,
1994,
7948,
15,
29163,
15,
396,
15,
1971,
7,
272,
485,
6406,
63,
633,
275,
1994,
7948,
15,
29163,
15,
396,
15,
6406,
7,
339,
768,
1014,
14,
4449,
779,
267,
1994,
7948,
15,
29163,
15,
5694,
297,
1994,
7948,
15,
29163,
15,
396,
15,
5694,
297,
267,
1994,
7948,
15,
29163,
15,
9427,
1132,
297,
1994,
7948,
15,
29163,
15,
396,
15,
9427,
1132,
297,
267,
1994,
7948,
15,
29163,
15,
1971,
297,
1994,
7948,
15,
29163,
15,
396,
15,
1971,
297,
267,
1994,
7948,
15,
29163,
15,
6406,
297,
1994,
7948,
15,
29163,
15,
396,
15,
6406,
297,
272,
2156,
730,
534,
1014,
297,
1790,
534,
3592,
358,
272,
347,
312,
32227,
63,
964,
63,
13485,
8,
277,
12,
1011,
1932,
304,
267,
408,
593,
32227,
27989,
1808,
9576,
12,
737,
5210,
367,
4729,
408,
267,
485,
2921,
14,
815,
360,
47,
32227,
26,
9509,
316,
1824,
63,
13485,
543,
2963,
666,
450,
83,
297,
10933,
14,
24225,
8,
1932,
430,
221,
327,
3105,
267,
2467,
12,
1747,
12,
1067,
275,
1056,
14,
1556,
12,
12824,
63,
998,
12,
1056,
14,
1100,
267,
1056,
14,
5189,
459,
7948,
14,
5945,
2278,
964,
63,
13485,
8,
1556,
12,
1747,
12,
2963,
12,
283,
29163,
297,
1067,
29,
1100,
9,
267,
372,
10380,
14,
1208,
14,
4876,
8,
1932,
14,
1935,
360,
1107,
63,
633,
297,
1994,
1333,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2050,
199,
646,
10933,
199,
646,
10380,
199,
199,
504,
5166,
492,
1455,
12,
12824,
63,
998,
199,
504,
5166,
14,
1014,
492,
1056,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
593,
32227,
7506,
8,
1014,
14,
7506,
304,
272,
485,
5694,
63,
633,
275,
1994,
7948,
15,
29163,
15,
396,
15,
5694,
7,
272,
485,
9427,
1132,
63,
633,
275,
1994,
7948,
15,
29163,
15,
396,
15,
9427,
1132,
7,
272,
485,
1971,
63,
633,
275,
1994,
7948,
15,
29163,
15,
396,
15,
1971,
7,
272,
485,
6406,
63,
633,
275,
1994,
7948,
15,
29163,
15,
396,
15,
6406,
7,
339,
768,
1014,
14,
4449,
779,
267,
1994,
7948,
15,
29163,
15,
5694,
297,
1994,
7948,
15,
29163,
15,
396,
15,
5694,
297,
267,
1994,
7948,
15,
29163,
15,
9427,
1132,
297,
1994,
7948,
15,
29163,
15,
396,
15,
9427,
1132,
297,
267,
1994,
7948,
15,
29163,
15,
1971,
297,
1994,
7948,
15,
29163,
15,
396,
15,
1971,
297,
267,
1994,
7948,
15,
29163,
15,
6406,
297,
1994,
7948,
15,
29163,
15,
396,
15,
6406,
297,
272,
2156,
730,
534,
1014,
297,
1790,
534,
3592,
358,
272,
347,
312,
32227,
63,
964,
63,
13485,
8,
277,
12,
1011,
1932,
304,
267,
408,
593,
32227,
27989,
1808,
9576,
12,
737,
5210,
367,
4729,
408,
267,
485,
2921,
14,
815,
360,
47,
32227,
26,
9509,
316,
1824,
63,
13485,
543,
2963,
666,
450,
83,
297,
10933,
14,
24225,
8,
1932,
430,
221,
327,
3105,
267,
2467,
12,
1747,
12,
1067,
275,
1056,
14,
1556,
12,
12824,
63,
998,
12,
1056,
14,
1100,
267,
1056,
14,
5189,
459,
7948,
14,
5945,
2278,
964,
63,
13485,
8,
1556,
12,
1747,
12,
2963,
12,
283,
29163,
297,
1067,
29,
1100,
9,
267,
372,
10380,
14,
1208,
14,
4876,
8,
1932,
14,
1935,
360,
1107,
63,
633,
297,
1994,
1333,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
orekyuu/intellij-community
|
python/helpers/docutils/parsers/rst/languages/it.py
|
57
|
3093
|
# $Id: it.py 4564 2006-05-21 20:44:42Z wiemann $
# Authors: Nicola Larosa <docutils@tekNico.net>;
# Lele Gaifax <lele@seldati.it>
# Copyright: This module has been placed in the public domain.
# Beware: the italian translation of the reStructuredText documentation
# at http://docit.bice.dyndns.org/static/ReST, in particular
# http://docit.bice.dyndns.org/static/ReST/ref/rst/directives.html, needs
# to be synced with the content of this file.
"""
Italian-language mappings for language-dependent features of
reStructuredText.
"""
__docformat__ = 'reStructuredText'
directives = {
'attenzione': 'attention',
'cautela': 'caution',
'pericolo': 'danger',
'errore': 'error',
'suggerimento': 'hint',
'importante': 'important',
'nota': 'note',
'consiglio': 'tip',
'avvertenza': 'warning',
'ammonizione': 'admonition',
'riquadro': 'sidebar',
'argomento': 'topic',
'blocco-di-righe': 'line-block',
'blocco-interpretato': 'parsed-literal',
'rubrica': 'rubric',
'epigrafe': 'epigraph',
'punti-salienti': 'highlights',
'estratto-evidenziato': 'pull-quote',
'composito': 'compound',
u'container (translation required)': 'container',
#'questions': 'questions',
#'qa': 'questions',
#'faq': 'questions',
'tabella': 'table',
'tabella-csv': 'csv-table',
'tabella-elenco': 'list-table',
'meta': 'meta',
#'imagemap': 'imagemap',
'immagine': 'image',
'figura': 'figure',
'includi': 'include',
'grezzo': 'raw',
'sostituisci': 'replace',
'unicode': 'unicode',
'data': 'date',
'classe': 'class',
'ruolo': 'role',
'ruolo-predefinito': 'default-role',
'titolo': 'title',
'indice': 'contents',
'contenuti': 'contents',
'seznum': 'sectnum',
'sezioni-autonumerate': 'sectnum',
'annota-riferimenti-esterni': 'target-notes',
'intestazione': 'header',
'piede-pagina': 'footer',
#'footnotes': 'footnotes',
#'citations': 'citations',
'restructuredtext-test-directive': 'restructuredtext-test-directive'}
"""Italian name to registered (in directives/__init__.py) directive name
mapping."""
roles = {
'abbreviazione': 'abbreviation',
'acronimo': 'acronym',
'indice': 'index',
'deponente': 'subscript',
'esponente': 'superscript',
'riferimento-titolo': 'title-reference',
'riferimento-pep': 'pep-reference',
'riferimento-rfc': 'rfc-reference',
'enfasi': 'emphasis',
'forte': 'strong',
'letterale': 'literal',
'riferimento-con-nome': 'named-reference',
'riferimento-anonimo': 'anonymous-reference',
'riferimento-nota': 'footnote-reference',
'riferimento-citazione': 'citation-reference',
'riferimento-sostituzione': 'substitution-reference',
'destinazione': 'target',
'riferimento-uri': 'uri-reference',
'grezzo': 'raw',}
"""Mapping of Italian role names to canonical role names for interpreted text.
"""
|
apache-2.0
|
[
3,
2672,
1304,
26,
652,
14,
647,
10416,
772,
8315,
13,
1717,
13,
2025,
3388,
26,
1602,
26,
2260,
58,
336,
1873,
20059,
2672,
199,
3,
6642,
26,
653,
12802,
416,
491,
285,
29295,
665,
27114,
32,
266,
75,
46,
12802,
14,
846,
30,
27,
199,
3,
3515,
7005,
274,
598,
5789,
667,
88,
665,
274,
274,
32,
5891,
983,
280,
14,
390,
30,
199,
3,
1898,
26,
961,
859,
965,
2757,
15090,
315,
314,
4575,
2881,
14,
199,
199,
3,
699,
546,
1530,
26,
314,
652,
25861,
7761,
402,
314,
295,
27486,
1872,
3794,
199,
3,
737,
1455,
921,
1301,
390,
14,
66,
1885,
14,
8161,
977,
561,
14,
1308,
15,
1986,
15,
497,
840,
12,
315,
6770,
199,
3,
1455,
921,
1301,
390,
14,
66,
1885,
14,
8161,
977,
561,
14,
1308,
15,
1986,
15,
497,
840,
15,
1121,
15,
8332,
15,
23216,
14,
1360,
12,
4839,
199,
3,
370,
506,
9560,
6867,
543,
314,
1564,
402,
642,
570,
14,
199,
199,
624,
199,
7940,
25861,
13,
3671,
13546,
367,
2637,
13,
7106,
4534,
402,
199,
264,
27486,
1872,
14,
199,
624,
199,
199,
363,
21841,
363,
275,
283,
264,
27486,
1872,
7,
421,
199,
23216,
275,
469,
489,
283,
4867,
16079,
368,
356,
283,
22393,
297,
489,
283,
696,
938,
416,
356,
283,
696,
2206,
297,
489,
283,
5490,
331,
320,
356,
283,
68,
12974,
297,
489,
283,
281,
293,
264,
356,
283,
705,
297,
489,
283,
83,
1518,
836,
73,
434,
79,
356,
283,
6479,
297,
489,
283,
646,
8949,
356,
283,
19559,
297,
489,
283,
1397,
65,
356,
283,
4610,
297,
489,
283,
388,
4093,
14437,
356,
283,
8996,
297,
489,
283,
1214,
422,
724,
8076,
356,
283,
3764,
297,
489,
283,
455,
2106,
565,
26277,
356,
283,
350,
31722,
297,
489,
283,
322,
14567,
293,
356,
283,
27372,
297,
489,
283,
16308,
434,
79,
356,
283,
5746,
297,
489,
283,
66,
2102,
331,
13,
328,
13,
322,
71,
426,
356,
283,
604,
13,
1457,
297,
489,
283,
66,
2102,
331,
13,
21533,
11318,
356,
283,
6751,
13,
8939,
297,
489,
283,
82,
456,
7127,
356,
283,
21586,
297,
489,
283,
1545,
528,
345,
771,
356,
283,
1545,
528,
3255,
297,
489,
283,
80,
324,
280,
13,
6327,
24555,
280,
356,
283,
14337,
83,
297,
489,
283,
69,
495,
292,
475,
13,
69,
433,
848,
16079,
11318,
356,
283,
9302,
13,
3513,
297,
489,
283,
7784,
338,
475,
356,
283,
15278,
297,
489,
399,
7,
3600,
334,
6893,
1415,
11862,
283,
3600,
297,
489,
17384,
16069,
356,
283,
16069,
297,
489,
17384,
7096,
356,
283,
16069,
297,
489,
17384,
667,
81,
356,
283,
16069,
297,
489,
283,
84,
902,
416,
356,
283,
1224,
297,
489,
283,
84,
902,
416,
13,
4737,
356,
283,
4737,
13,
1224,
297,
489,
283,
84,
902,
416,
13,
69,
552,
331,
356,
283,
513,
13,
1224,
297,
489,
283,
2024,
356,
283,
2024,
297,
489,
17384,
1569,
1130,
356,
283,
1569,
1130,
297,
489,
283,
1017,
391,
2598,
356,
283,
1569,
297,
489,
283,
592,
12417,
356,
283,
8941,
297,
489,
283,
262,
1016,
328,
356,
283,
2613,
297,
489,
283,
9157,
4348,
79,
356,
283,
1773,
297,
489,
283,
83,
941,
390,
85,
374,
559,
356,
283,
1814,
297,
489,
283,
2975,
356,
283,
2975,
297,
489,
283,
576,
356,
283,
602,
297,
489,
283,
429,
305,
261,
356,
283,
533,
297,
489,
283,
6558,
79,
320,
356,
283,
3756,
297,
489,
283,
6558,
79,
320,
13,
657,
318,
826,
79,
356,
283,
885,
13,
3756,
297,
489,
283,
280,
475,
320,
356,
283,
1213,
297,
489,
283,
3558,
301,
356,
283,
4407,
297,
489,
283,
388,
724,
935,
356,
283,
4407,
297,
489,
283,
261,
90,
1507,
356,
283,
8519,
1507,
297,
489,
283,
261,
90,
1636,
73,
13,
6898,
265,
940,
1866,
356,
283,
8519,
1507,
297,
489,
283,
3226,
65,
13,
322,
2412,
9001,
280,
13,
397,
1203,
73,
356,
283,
1375,
13,
5983,
297,
489,
283,
262,
396,
30834,
356,
283,
1291,
297,
489,
283,
9890,
271,
13,
11069,
65,
356,
283,
12781,
297,
489,
17384,
11407,
5983,
356,
283,
11407,
5983,
297,
489,
17384,
14422,
1298,
356,
283,
14422,
1298,
297,
489,
283,
26854,
13,
396,
13,
15047,
356,
283,
26854,
13,
396,
13,
15047,
936,
199,
624,
7940,
25861,
536,
370,
7264,
334,
262,
13502,
22128,
826,
4343,
647,
9,
13613,
536,
199,
4745,
1041,
199,
199,
8050,
275,
469,
489,
283,
371,
23988,
30834,
356,
283,
371,
30369,
297,
489,
283,
645,
2641,
73,
573,
356,
283,
645,
2641,
12828,
297,
489,
283,
3558,
301,
356,
283,
1080,
297,
489,
283,
271,
10995,
266,
356,
283,
30907,
297,
489,
283,
397,
10995,
266,
356,
283,
4792,
1579,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
280,
475,
320,
356,
283,
1213,
13,
4443,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
12636,
356,
283,
12636,
13,
4443,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
8973,
356,
283,
8973,
13,
4443,
297,
489,
283,
287,
70,
24950,
356,
283,
28907,
297,
489,
283,
509,
266,
356,
283,
9370,
297,
489,
283,
2723,
2967,
274,
356,
283,
8939,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
388,
13,
29897,
356,
283,
4579,
13,
4443,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
21009,
73,
573,
356,
283,
12628,
13,
4443,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
1397,
65,
356,
283,
19589,
13,
4443,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
14422,
30834,
356,
283,
6210,
13,
4443,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
83,
941,
390,
9494,
26277,
356,
283,
30809,
13,
4443,
297,
489,
283,
2614,
262,
30834,
356,
283,
1375,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
2302,
356,
283,
2302,
13,
4443,
297,
489,
283,
9157,
4348,
79,
356,
283,
1773,
297,
93,
199,
624,
7674,
402,
2779,
25861,
4719,
1561,
370,
11358,
4719,
1561,
367,
11922,
1318,
14,
199,
624,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2672,
1304,
26,
652,
14,
647,
10416,
772,
8315,
13,
1717,
13,
2025,
3388,
26,
1602,
26,
2260,
58,
336,
1873,
20059,
2672,
199,
3,
6642,
26,
653,
12802,
416,
491,
285,
29295,
665,
27114,
32,
266,
75,
46,
12802,
14,
846,
30,
27,
199,
3,
3515,
7005,
274,
598,
5789,
667,
88,
665,
274,
274,
32,
5891,
983,
280,
14,
390,
30,
199,
3,
1898,
26,
961,
859,
965,
2757,
15090,
315,
314,
4575,
2881,
14,
199,
199,
3,
699,
546,
1530,
26,
314,
652,
25861,
7761,
402,
314,
295,
27486,
1872,
3794,
199,
3,
737,
1455,
921,
1301,
390,
14,
66,
1885,
14,
8161,
977,
561,
14,
1308,
15,
1986,
15,
497,
840,
12,
315,
6770,
199,
3,
1455,
921,
1301,
390,
14,
66,
1885,
14,
8161,
977,
561,
14,
1308,
15,
1986,
15,
497,
840,
15,
1121,
15,
8332,
15,
23216,
14,
1360,
12,
4839,
199,
3,
370,
506,
9560,
6867,
543,
314,
1564,
402,
642,
570,
14,
199,
199,
624,
199,
7940,
25861,
13,
3671,
13546,
367,
2637,
13,
7106,
4534,
402,
199,
264,
27486,
1872,
14,
199,
624,
199,
199,
363,
21841,
363,
275,
283,
264,
27486,
1872,
7,
421,
199,
23216,
275,
469,
489,
283,
4867,
16079,
368,
356,
283,
22393,
297,
489,
283,
696,
938,
416,
356,
283,
696,
2206,
297,
489,
283,
5490,
331,
320,
356,
283,
68,
12974,
297,
489,
283,
281,
293,
264,
356,
283,
705,
297,
489,
283,
83,
1518,
836,
73,
434,
79,
356,
283,
6479,
297,
489,
283,
646,
8949,
356,
283,
19559,
297,
489,
283,
1397,
65,
356,
283,
4610,
297,
489,
283,
388,
4093,
14437,
356,
283,
8996,
297,
489,
283,
1214,
422,
724,
8076,
356,
283,
3764,
297,
489,
283,
455,
2106,
565,
26277,
356,
283,
350,
31722,
297,
489,
283,
322,
14567,
293,
356,
283,
27372,
297,
489,
283,
16308,
434,
79,
356,
283,
5746,
297,
489,
283,
66,
2102,
331,
13,
328,
13,
322,
71,
426,
356,
283,
604,
13,
1457,
297,
489,
283,
66,
2102,
331,
13,
21533,
11318,
356,
283,
6751,
13,
8939,
297,
489,
283,
82,
456,
7127,
356,
283,
21586,
297,
489,
283,
1545,
528,
345,
771,
356,
283,
1545,
528,
3255,
297,
489,
283,
80,
324,
280,
13,
6327,
24555,
280,
356,
283,
14337,
83,
297,
489,
283,
69,
495,
292,
475,
13,
69,
433,
848,
16079,
11318,
356,
283,
9302,
13,
3513,
297,
489,
283,
7784,
338,
475,
356,
283,
15278,
297,
489,
399,
7,
3600,
334,
6893,
1415,
11862,
283,
3600,
297,
489,
17384,
16069,
356,
283,
16069,
297,
489,
17384,
7096,
356,
283,
16069,
297,
489,
17384,
667,
81,
356,
283,
16069,
297,
489,
283,
84,
902,
416,
356,
283,
1224,
297,
489,
283,
84,
902,
416,
13,
4737,
356,
283,
4737,
13,
1224,
297,
489,
283,
84,
902,
416,
13,
69,
552,
331,
356,
283,
513,
13,
1224,
297,
489,
283,
2024,
356,
283,
2024,
297,
489,
17384,
1569,
1130,
356,
283,
1569,
1130,
297,
489,
283,
1017,
391,
2598,
356,
283,
1569,
297,
489,
283,
592,
12417,
356,
283,
8941,
297,
489,
283,
262,
1016,
328,
356,
283,
2613,
297,
489,
283,
9157,
4348,
79,
356,
283,
1773,
297,
489,
283,
83,
941,
390,
85,
374,
559,
356,
283,
1814,
297,
489,
283,
2975,
356,
283,
2975,
297,
489,
283,
576,
356,
283,
602,
297,
489,
283,
429,
305,
261,
356,
283,
533,
297,
489,
283,
6558,
79,
320,
356,
283,
3756,
297,
489,
283,
6558,
79,
320,
13,
657,
318,
826,
79,
356,
283,
885,
13,
3756,
297,
489,
283,
280,
475,
320,
356,
283,
1213,
297,
489,
283,
3558,
301,
356,
283,
4407,
297,
489,
283,
388,
724,
935,
356,
283,
4407,
297,
489,
283,
261,
90,
1507,
356,
283,
8519,
1507,
297,
489,
283,
261,
90,
1636,
73,
13,
6898,
265,
940,
1866,
356,
283,
8519,
1507,
297,
489,
283,
3226,
65,
13,
322,
2412,
9001,
280,
13,
397,
1203,
73,
356,
283,
1375,
13,
5983,
297,
489,
283,
262,
396,
30834,
356,
283,
1291,
297,
489,
283,
9890,
271,
13,
11069,
65,
356,
283,
12781,
297,
489,
17384,
11407,
5983,
356,
283,
11407,
5983,
297,
489,
17384,
14422,
1298,
356,
283,
14422,
1298,
297,
489,
283,
26854,
13,
396,
13,
15047,
356,
283,
26854,
13,
396,
13,
15047,
936,
199,
624,
7940,
25861,
536,
370,
7264,
334,
262,
13502,
22128,
826,
4343,
647,
9,
13613,
536,
199,
4745,
1041,
199,
199,
8050,
275,
469,
489,
283,
371,
23988,
30834,
356,
283,
371,
30369,
297,
489,
283,
645,
2641,
73,
573,
356,
283,
645,
2641,
12828,
297,
489,
283,
3558,
301,
356,
283,
1080,
297,
489,
283,
271,
10995,
266,
356,
283,
30907,
297,
489,
283,
397,
10995,
266,
356,
283,
4792,
1579,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
280,
475,
320,
356,
283,
1213,
13,
4443,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
12636,
356,
283,
12636,
13,
4443,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
8973,
356,
283,
8973,
13,
4443,
297,
489,
283,
287,
70,
24950,
356,
283,
28907,
297,
489,
283,
509,
266,
356,
283,
9370,
297,
489,
283,
2723,
2967,
274,
356,
283,
8939,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
388,
13,
29897,
356,
283,
4579,
13,
4443,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
21009,
73,
573,
356,
283,
12628,
13,
4443,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
1397,
65,
356,
283,
19589,
13,
4443,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
14422,
30834,
356,
283,
6210,
13,
4443,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
83,
941,
390,
9494,
26277,
356,
283,
30809,
13,
4443,
297,
489,
283,
2614,
262,
30834,
356,
283,
1375,
297,
489,
283,
322,
2412,
73,
434,
79,
13,
2302,
356,
283,
2302,
13,
4443,
297,
489,
283,
9157,
4348,
79,
356,
283,
1773,
297,
93,
199,
624,
7674,
402,
2779,
25861,
4719,
1561,
370,
11358,
4719,
1561,
367,
11922,
1318,
14,
199,
624,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Intel-Corporation/tensorflow
|
tensorflow/contrib/losses/python/losses/loss_ops_test.py
|
23
|
55152
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for contrib.losses.python.losses.loss_ops."""
# pylint: disable=unused-import,g-bad-import-order
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
# pylint: enable=unused-import
import numpy as np
from tensorflow.contrib.framework.python.ops import arg_scope
from tensorflow.contrib.losses.python.losses import loss_ops
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.framework import random_seed
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import init_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import random_ops
from tensorflow.python.ops import variable_scope
from tensorflow.python.ops import variables
from tensorflow.python.platform import test
from tensorflow.python.training import momentum as momentum_lib
class AbsoluteDifferenceLossTest(test.TestCase):
def setUp(self):
self._predictions = constant_op.constant([4, 8, 12, 8, 1, 3], shape=(2, 3))
self._labels = constant_op.constant([1, 9, 2, -5, -2, 6], shape=(2, 3))
def testValueErrorThrownWhenWeightIsNone(self):
with self.cached_session():
with self.assertRaises(ValueError):
loss_ops.absolute_difference(
self._predictions, self._predictions, weights=None)
def testAllCorrectNoLossWeight(self):
loss = loss_ops.absolute_difference(self._predictions, self._predictions)
with self.cached_session():
self.assertAlmostEqual(0.0, loss.eval(), 3)
def testNonZeroLoss(self):
loss = loss_ops.absolute_difference(self._predictions, self._labels)
with self.cached_session():
self.assertAlmostEqual(5.5, loss.eval(), 3)
def testNonZeroLossWithPythonScalarWeight(self):
weights = 2.3
loss = loss_ops.absolute_difference(self._predictions, self._labels,
weights)
with self.cached_session():
self.assertAlmostEqual(5.5 * weights, loss.eval(), 3)
def testNonZeroLossWithScalarTensorWeight(self):
weights = 2.3
loss = loss_ops.absolute_difference(self._predictions, self._labels,
constant_op.constant(weights))
with self.cached_session():
self.assertAlmostEqual(5.5 * weights, loss.eval(), 3)
def testNonZeroLossWithOneDimBatchSpecificWeights(self):
weights = constant_op.constant([1.2, 0.0], shape=[2,])
loss = loss_ops.absolute_difference(self._predictions, self._labels,
weights)
with self.cached_session():
self.assertAlmostEqual(5.6, loss.eval(), 3)
def testNonZeroLossWithTwoDimBatchSpecificWeights(self):
weights = constant_op.constant([1.2, 0.0], shape=[2, 1])
loss = loss_ops.absolute_difference(self._predictions, self._labels,
weights)
with self.cached_session():
self.assertAlmostEqual(5.6, loss.eval(), 3)
def testNonZeroLossWithSampleSpecificWeights(self):
weights = constant_op.constant([3, 6, 5, 0, 4, 2], shape=[2, 3])
loss = loss_ops.absolute_difference(self._predictions, self._labels,
weights)
with self.cached_session():
self.assertAlmostEqual(16.6, loss.eval(), 3)
def testNonZeroLossWithSampleSpecificWeightsMostZero(self):
weights = constant_op.constant([0, 0, 0, 0, 0, 2], shape=[2, 3])
loss = loss_ops.absolute_difference(self._predictions, self._labels,
weights)
with self.cached_session():
self.assertAlmostEqual(6.0, loss.eval(), 3)
def testLossWithSampleSpecificWeightsAllZero(self):
weights = array_ops.zeros((2, 3))
loss = loss_ops.absolute_difference(self._predictions, self._labels,
weights)
with self.cached_session():
self.assertAlmostEqual(0.0, loss.eval(), 3)
class SoftmaxCrossEntropyLossTest(test.TestCase):
def testNoneWeightRaisesValueError(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]])
with self.cached_session():
with self.assertRaises(ValueError):
loss_ops.softmax_cross_entropy(logits, labels, weights=None)
def testAllCorrect(self):
with self.cached_session():
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]])
loss = loss_ops.softmax_cross_entropy(logits, labels)
self.assertEquals('softmax_cross_entropy_loss/value', loss.op.name)
self.assertAlmostEqual(loss.eval(), 0.0, 3)
def testAllWrong(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[0, 0, 1],
[1, 0, 0],
[0, 1, 0]])
with self.cached_session():
loss = loss_ops.softmax_cross_entropy(logits, labels)
self.assertEquals(loss.op.name, 'softmax_cross_entropy_loss/value')
self.assertAlmostEqual(loss.eval(), 10.0, 3)
def testNonZeroLossWithPythonScalarWeight(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[0, 0, 1],
[1, 0, 0],
[0, 1, 0]])
weights = 2.3
with self.cached_session():
loss = loss_ops.softmax_cross_entropy(logits, labels, weights)
self.assertAlmostEqual(weights * 10.0, loss.eval(), 3)
def testNonZeroLossWithScalarTensorWeight(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[0, 0, 1],
[1, 0, 0],
[0, 1, 0]])
weights = 2.3
with self.cached_session():
loss = loss_ops.softmax_cross_entropy(logits, labels,
constant_op.constant(weights))
self.assertAlmostEqual(weights * 10.0, loss.eval(), 3)
def testNonZeroLossWithOneDimBatchSpecificWeights(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[0, 0, 1],
[1, 0, 0],
[0, 1, 0]])
weights = constant_op.constant([1.2, 3.4, 5.6], shape=[3])
with self.cached_session():
loss = loss_ops.softmax_cross_entropy(logits, labels, weights)
self.assertAlmostEqual((1.2 + 3.4 + 5.6) * 10.0 / 3.0, loss.eval(), 3)
def testAllWrongAllWeightsMissing(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[0, 0, 1],
[1, 0, 0],
[0, 1, 0]])
weights = constant_op.constant([0, 0, 0], shape=[3])
with self.cached_session():
loss = loss_ops.softmax_cross_entropy(logits, labels, weights)
self.assertAlmostEqual(0.0, loss.eval(), 3)
def testSomeWeightsMissing(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[0, 0, 1],
[1, 0, 0],
[0, 1, 0]])
weights = constant_op.constant([1.2, 0, 0], shape=[3])
with self.cached_session():
loss = loss_ops.softmax_cross_entropy(logits, labels, weights)
self.assertAlmostEqual(12.0, loss.eval(), 3)
def testSoftmaxWithMeasurementSpecificWeightsRaisesException(self):
with self.cached_session():
logits = constant_op.constant([[100.0, -100.0, -100.0],
[-100.0, 100.0, -100.0],
[-100.0, -100.0, 100.0]])
labels = constant_op.constant([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]])
weights = constant_op.constant([[3, 4, 5],
[2, 6, 0],
[8, 0, 1]])
with self.assertRaises(ValueError):
loss_ops.softmax_cross_entropy(logits, labels, weights=weights).eval()
def testSoftmaxLabelSmoothing(self):
with self.cached_session():
# Softmax Cross Entropy Loss is:
# -\sum_i p_i \log q_i
# where for a softmax activation
# \log q_i = x_i - \log \sum_j \exp x_j
# = x_i - x_max - \log \sum_j \exp (x_j - x_max)
# For our activations, [100, -100, -100] the log partion function becomes
# \log ( exp(0) + exp(-200) + exp(-200) ) = 0
# so our log softmaxes become: [0, -200, -200]
# so our cross entropy loss is:
# -(1 - L + L/n) * 0 + 400 * L/n = 400 L/n
logits = constant_op.constant([[100.0, -100.0, -100.0]])
labels = constant_op.constant([[1, 0, 0]])
label_smoothing = 0.1
loss = loss_ops.softmax_cross_entropy(
logits, labels, label_smoothing=label_smoothing)
self.assertEquals(loss.op.name, 'softmax_cross_entropy_loss/value')
expected_value = 400.0 * label_smoothing / 3.0
self.assertAlmostEqual(loss.eval(), expected_value, 3)
def testLossWithDynamicallyShapedWeights1D(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[0, 0, 1],
[1, 0, 0],
[0, 1, 0]])
weights = [2.3, 2.4, 2.5]
weights_placeholder = array_ops.placeholder(dtypes.float32, shape=[None])
loss = loss_ops.softmax_cross_entropy(logits, labels, weights_placeholder)
with self.cached_session() as sess:
loss = sess.run(loss, {weights_placeholder: weights})
self.assertAlmostEqual(np.average(weights) * 10.0, loss, 3)
def testLossWithDynamicallyShapedWeights2D(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[0, 0, 1],
[1, 0, 0],
[0, 1, 0]])
weights = [[2.3], [2.4], [2.5]]
weights_placeholder = array_ops.placeholder(
dtypes.float32, shape=[None, None])
loss = loss_ops.softmax_cross_entropy(logits, labels, weights_placeholder)
with self.cached_session() as sess:
loss = sess.run(loss, {weights_placeholder: weights})
self.assertAlmostEqual(np.average(weights) * 10.0, loss, 3)
class SparseSoftmaxCrossEntropyLossTest(test.TestCase):
def testNoneWeightRaisesValueError(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[0], [1], [2]])
with self.cached_session():
with self.assertRaises(ValueError):
loss_ops.sparse_softmax_cross_entropy(logits, labels, weights=None)
def testAllCorrectInt32Labels(self):
with self.cached_session():
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[0], [1], [2]], dtype=dtypes.int32)
loss = loss_ops.sparse_softmax_cross_entropy(logits, labels)
self.assertEquals(loss.op.name, 'sparse_softmax_cross_entropy_loss/value')
self.assertAlmostEqual(loss.eval(), 0.0, 3)
def testAllCorrectInt64Labels(self):
with self.cached_session():
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[0], [1], [2]], dtype=dtypes.int64)
loss = loss_ops.sparse_softmax_cross_entropy(logits, labels)
self.assertEquals(loss.op.name, 'sparse_softmax_cross_entropy_loss/value')
self.assertAlmostEqual(loss.eval(), 0.0, 3)
def testAllCorrectNonColumnLabels(self):
with self.cached_session():
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([0, 1, 2])
loss = loss_ops.sparse_softmax_cross_entropy(logits, labels)
self.assertEquals(loss.op.name, 'sparse_softmax_cross_entropy_loss/value')
self.assertAlmostEqual(loss.eval(), 0.0, 3)
def testAllWrongInt32Labels(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[2], [0], [1]], dtype=dtypes.int32)
with self.cached_session():
loss = loss_ops.sparse_softmax_cross_entropy(logits, labels)
self.assertEquals(loss.op.name, 'sparse_softmax_cross_entropy_loss/value')
self.assertAlmostEqual(loss.eval(), 10.0, 3)
def testAllWrongInt64Labels(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[2], [0], [1]], dtype=dtypes.int64)
with self.cached_session():
loss = loss_ops.sparse_softmax_cross_entropy(logits, labels)
self.assertEquals(loss.op.name, 'sparse_softmax_cross_entropy_loss/value')
self.assertAlmostEqual(loss.eval(), 10.0, 3)
def testAllWrongNonColumnLabels(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([2, 0, 1])
with self.cached_session():
loss = loss_ops.sparse_softmax_cross_entropy(logits, labels)
self.assertEquals(loss.op.name, 'sparse_softmax_cross_entropy_loss/value')
self.assertAlmostEqual(loss.eval(), 10.0, 3)
def testNonZeroLossWithPythonScalarWeight(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[2], [0], [1]])
weights = 2.3
with self.cached_session():
loss = loss_ops.sparse_softmax_cross_entropy(logits, labels, weights)
self.assertAlmostEqual(weights * 10.0, loss.eval(), 3)
def testNonZeroLossWithScalarTensorWeight(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[2], [0], [1]])
weights = 2.3
with self.cached_session():
loss = loss_ops.sparse_softmax_cross_entropy(
logits, labels, constant_op.constant(weights))
self.assertAlmostEqual(weights * 10.0, loss.eval(), 3)
def testNonZeroLossWithOneDimBatchSpecificWeights(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[2], [0], [1]])
weights = constant_op.constant([1.2, 3.4, 5.6], shape=[3])
with self.cached_session():
loss = loss_ops.sparse_softmax_cross_entropy(logits, labels, weights)
self.assertAlmostEqual((1.2 + 3.4 + 5.6) * 10.0 / 3.0, loss.eval(), 3)
def testNonZeroLossWithColumnWeights(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[2], [0], [1]])
weights = constant_op.constant([[1.2], [3.4], [5.6]])
with self.cached_session():
loss = loss_ops.sparse_softmax_cross_entropy(logits, labels, weights)
self.assertAlmostEqual((1.2 + 3.4 + 5.6) * 10.0 / 3.0, loss.eval(), 3)
def testAllWrongAllWeightsMissing(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[2], [0], [1]])
weights = constant_op.constant([0, 0, 0], shape=[3])
with self.cached_session():
loss = loss_ops.sparse_softmax_cross_entropy(logits, labels, weights)
self.assertAlmostEqual(0.0, loss.eval(), 3)
def testSomeWeightsMissing(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([[2], [0], [1]])
weights = constant_op.constant([1.2, 0, 0], shape=[3])
with self.cached_session():
loss = loss_ops.sparse_softmax_cross_entropy(logits, labels, weights)
self.assertAlmostEqual(12.0, loss.eval(), 3)
def testMeasurementSpecificWeightsRaisesException(self):
with self.cached_session():
logits = constant_op.constant([[100.0, -100.0, -100.0],
[-100.0, 100.0, -100.0],
[-100.0, -100.0, 100.0]])
labels = constant_op.constant([[0], [1], [2]])
weights = constant_op.constant([[3, 4, 5], [2, 6, 0], [8, 0, 1]])
with self.assertRaises(ValueError):
loss_ops.sparse_softmax_cross_entropy(
logits, labels, weights=weights).eval()
def testInconsistentWeightSizeRaisesException(self):
"""The weight tensor has incorrect number of elements."""
with self.cached_session():
logits = constant_op.constant([[100.0, -100.0, -100.0],
[-100.0, 100.0, -100.0],
[-100.0, -100.0, 100.0]])
labels = constant_op.constant([[0], [1], [2]])
weights = constant_op.constant([1.2, 3.4, 5.6, 7.8])
with self.assertRaises(ValueError):
loss_ops.sparse_softmax_cross_entropy(
logits, labels, weights=weights).eval()
def testInconsistentLabelSizeRaisesException(self):
"""The label tensor has incorrect number of elements."""
with self.cached_session():
logits = constant_op.constant([[100.0, -100.0, -100.0],
[-100.0, 100.0, -100.0],
[-100.0, -100.0, 100.0]])
labels = constant_op.constant([[0], [1], [2], [3]])
weights = constant_op.constant([1.2, 3.4, 5.6])
with self.assertRaises(ValueError):
loss_ops.sparse_softmax_cross_entropy(
logits, labels, weights=weights).eval()
def testInconsistentWeightShapeRaisesException(self):
"""The weight tensor has incorrect shape."""
with self.cached_session():
logits = constant_op.constant([[100.0, -100.0, -100.0, -100.0],
[-100.0, 100.0, -100.0, -100.0],
[-100.0, -100.0, 100.0, -100.0],
[-100.0, -100.0, -100.0, 100.0]])
labels = constant_op.constant([[0], [1], [2], [3]])
weights = constant_op.constant([[1.2, 3.4], [5.6, 7.8]])
with self.assertRaises(ValueError):
loss_ops.sparse_softmax_cross_entropy(
logits, labels, weights=weights).eval()
def testInconsistentLabelShapeRaisesException(self):
"""The label tensor has incorrect shape."""
with self.cached_session():
logits = constant_op.constant([[100.0, -100.0, -100.0, -100.0],
[-100.0, 100.0, -100.0, -100.0],
[-100.0, -100.0, 100.0, -100.0],
[-100.0, -100.0, -100.0, 100.0]])
labels = constant_op.constant([[0, 1], [2, 3]])
weights = constant_op.constant([1.2, 3.4, 5.6, 7.8])
with self.assertRaises(ValueError):
loss_ops.sparse_softmax_cross_entropy(
logits, labels, weights=weights).eval()
def testLossWithDynamicallyShapedWeights1D(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([2, 0, 1])
weights = [2.3, 2.4, 2.5]
weights_placeholder = array_ops.placeholder(
dtypes.float32, shape=[None])
loss = loss_ops.sparse_softmax_cross_entropy(
logits, labels, weights_placeholder)
with self.cached_session() as sess:
loss = sess.run(loss, {weights_placeholder: weights})
self.assertAlmostEqual(np.average(weights) * 10.0, loss, 3)
def testLossWithDynamicallyShapedWeights2D(self):
logits = constant_op.constant([[10.0, 0.0, 0.0],
[0.0, 10.0, 0.0],
[0.0, 0.0, 10.0]])
labels = constant_op.constant([2, 0, 1])
weights = [[2.3], [2.4], [2.5]]
weights_placeholder = array_ops.placeholder(
dtypes.float32, shape=[None, None])
loss = loss_ops.sparse_softmax_cross_entropy(
logits, labels, weights_placeholder)
with self.cached_session() as sess:
loss = sess.run(loss, {weights_placeholder: weights})
self.assertAlmostEqual(np.average(weights) * 10.0, loss, 3)
class SigmoidCrossEntropyLossTest(test.TestCase):
def testAllCorrectSigmoid(self):
with self.cached_session():
logits = constant_op.constant([[100.0, -100.0, -100.0],
[-100.0, 100.0, -100.0],
[-100.0, -100.0, 100.0]])
labels = constant_op.constant([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
loss = loss_ops.sigmoid_cross_entropy(logits, labels)
self.assertEquals(loss.op.name, 'sigmoid_cross_entropy_loss/value')
self.assertAlmostEqual(0.0, loss.eval(), 3)
def testLossWithSingleDimPlaceholderForLogitsAndWeights1(self):
logits = array_ops.placeholder(dtypes.float32, shape=(None, 1))
labels = array_ops.placeholder(dtypes.float32, shape=(None, 1))
weights = array_ops.ones_like(logits, dtype=dtypes.float32)
loss = loss_ops.sigmoid_cross_entropy(logits, labels, weights)
with self.cached_session() as sess:
loss = sess.run(loss,
feed_dict={
logits: np.ones((32, 1)),
labels: np.ones((32, 1)),
})
self.assertAlmostEqual(0.313, loss, 3)
def testLossWithSingleDimPlaceholderForLogitsAndWeights2(self):
logits = array_ops.placeholder(dtypes.float32, shape=(None, 2))
labels = array_ops.placeholder(dtypes.float32, shape=(None, 2))
weights = array_ops.ones_like(logits, dtype=dtypes.float32)
loss = loss_ops.sigmoid_cross_entropy(logits, labels, weights)
with self.cached_session() as sess:
loss = sess.run(loss,
feed_dict={
logits: np.ones((32, 2)),
labels: np.ones((32, 2)),
})
self.assertAlmostEqual(0.313, loss, 3)
def testAllWrongSigmoid(self):
with self.cached_session():
logits = constant_op.constant([[100.0, -100.0, -100.0],
[-100.0, 100.0, -100.0],
[-100.0, -100.0, 100.0]])
labels = constant_op.constant([[0, 0, 1],
[1, 0, 0],
[0, 1, 0]])
loss = loss_ops.sigmoid_cross_entropy(logits, labels)
self.assertEquals(loss.op.name, 'sigmoid_cross_entropy_loss/value')
self.assertAlmostEqual(loss.eval(), 600.0 / 9.0, 3)
def testAllWrongSigmoidWithMeasurementSpecificWeights(self):
with self.cached_session():
logits = constant_op.constant([[100.0, -100.0, -100.0],
[-100.0, 100.0, -100.0],
[-100.0, -100.0, 100.0]])
labels = constant_op.constant([[0, 0, 1],
[1, 0, 0],
[0, 1, 0]])
weights = constant_op.constant([[3, 4, 5],
[2, 6, 0],
[8, 0, 1]])
loss = loss_ops.sigmoid_cross_entropy(logits, labels, weights)
self.assertEquals(loss.op.name, 'sigmoid_cross_entropy_loss/value')
self.assertAlmostEqual(1700.0 / 7.0, loss.eval(), 3)
def testMultiCorrectSigmoid(self):
logits = constant_op.constant([[100.0, -100.0, 100.0],
[100.0, 100.0, -100.0],
[-100.0, 100.0, 100.0]])
labels = constant_op.constant([[1, 0, 1],
[1, 1, 0],
[0, 1, 1]])
loss = loss_ops.sigmoid_cross_entropy(logits, labels)
self.assertEquals(loss.op.name, 'sigmoid_cross_entropy_loss/value')
with self.cached_session():
self.assertAlmostEqual(loss.eval(), 0.0, 3)
def testSigmoidLabelSmoothingCorrect(self):
with self.cached_session():
logits = constant_op.constant([[100.0, -100.0, -100.0]])
labels = constant_op.constant([[1, 0, 1]])
# Sigmoid cross entropy loss is:
# max(x,0) - x*z + log(1 + exp(-abs(x)))
# The new labels are:
# z' = z * (1 - L) + 0.5 L
# 1 -> 1 - 0.5 L
# 0 -> 0.5 L
# here we expect:
# 1/3 * (100 - 100 * (1 - 0.5 L) + 0
# + 0 + 100 * (0.5 L) + 0
# + 0 + 100 * (1 - 0.5 L) + 0)
# = 1/3 * (100 + 50 L)
label_smoothing = 0.1
loss = loss_ops.sigmoid_cross_entropy(
logits, labels, label_smoothing=label_smoothing)
self.assertEquals(loss.op.name, 'sigmoid_cross_entropy_loss/value')
expected_value = (100.0 + 50.0 * label_smoothing) / 3.0
self.assertAlmostEqual(loss.eval(), expected_value, 3)
def testSigmoidLabelSmoothingEqualsSoftmaxTwoLabel(self):
with self.cached_session():
label_smoothing = 0.1
sigmoid_logits = constant_op.constant([[100.0, -100.0, -100.0]])
sigmoid_labels = constant_op.constant([[1, 0, 1]])
sigmoid_loss = loss_ops.sigmoid_cross_entropy(
sigmoid_logits, sigmoid_labels, label_smoothing=label_smoothing)
softmax_logits = constant_op.constant(
[[0.0, 100.0], [100.0, 0.0], [100.0, 0.0]])
softmax_labels = constant_op.constant([[0, 1], [1, 0], [0, 1]])
softmax_loss = loss_ops.softmax_cross_entropy(
softmax_logits, softmax_labels, label_smoothing=label_smoothing)
self.assertAlmostEqual(sigmoid_loss.eval(), softmax_loss.eval(), 3)
class LogLossTest(test.TestCase):
def setUp(self):
predictions = np.asarray([.9, .2, .2, .8, .4, .6]).reshape((2, 3))
labels = np.asarray([1.0, 0.0, 1.0, 1.0, 0.0, 0.0]).reshape((2, 3))
self._np_predictions = predictions
self._np_labels = labels
epsilon = 1e-7
self._expected_losses = np.multiply(
labels, np.log(predictions + epsilon)) + np.multiply(
1 - labels, np.log(1 - predictions + epsilon))
self._predictions = constant_op.constant(predictions)
self._labels = constant_op.constant(labels)
def testValueErrorThrownWhenWeightIsNone(self):
with self.cached_session():
with self.assertRaises(ValueError):
loss_ops.log_loss(self._labels, self._labels, weights=None)
def testAllCorrectNoLossWeight(self):
loss = loss_ops.log_loss(self._labels, self._labels)
with self.cached_session():
self.assertAlmostEqual(0.0, loss.eval(), 3)
def testAllCorrectNoLossWeightWithPlaceholder(self):
tf_predictions = array_ops.placeholder(
dtypes.float32, shape=self._np_labels.shape)
loss = loss_ops.log_loss(tf_predictions, self._labels)
with self.cached_session():
self.assertAlmostEqual(
0.0, loss.eval(feed_dict={tf_predictions: self._np_labels}), 3)
def testNonZeroLoss(self):
loss = loss_ops.log_loss(self._predictions, self._labels)
with self.cached_session():
self.assertAlmostEqual(-np.sum(self._expected_losses) / 6.0,
loss.eval(), 3)
def testNonZeroLossWithPythonScalarWeight(self):
weights = 2.3
loss = loss_ops.log_loss(self._predictions, self._labels, weights)
with self.cached_session():
self.assertAlmostEqual(weights * -np.sum(self._expected_losses) / 6.0,
loss.eval(), 3)
def testNonZeroLossWithScalarTensorWeight(self):
weights = 2.3
loss = loss_ops.log_loss(self._predictions, self._labels,
constant_op.constant(weights))
with self.cached_session():
self.assertAlmostEqual(weights * -np.sum(self._expected_losses) / 6.0,
loss.eval(), 3)
def testNonZeroLossWithScalarTensorWeightAndPlaceholder(self):
tf_predictions = array_ops.placeholder(
dtypes.float32, shape=self._np_predictions.shape)
weights = 2.3
loss = loss_ops.log_loss(tf_predictions, self._labels,
constant_op.constant(weights))
with self.cached_session() as sess:
loss = sess.run(loss, feed_dict={tf_predictions: self._np_predictions})
self.assertAlmostEqual(weights * -np.sum(self._expected_losses) / 6.0,
loss, 3)
def testNonZeroLossWithScalarTensorWeightAndPlaceholderWithRankOnly(self):
tf_predictions = array_ops.placeholder(dtypes.float32, shape=[None, None])
weights = 2.3
loss = loss_ops.log_loss(tf_predictions, self._labels,
constant_op.constant(weights))
with self.cached_session() as sess:
loss = sess.run(loss, feed_dict={tf_predictions: self._np_predictions})
self.assertAlmostEqual(weights * -np.sum(self._expected_losses) / 6.0,
loss, 3)
def testNonZeroLossWithOneDimBatchSpecificWeights(self):
weights = constant_op.constant([1.2, 3.4], shape=[2])
expected_losses = np.multiply(
self._expected_losses,
np.asarray([1.2, 1.2, 1.2, 3.4, 3.4, 3.4]).reshape((2, 3)))
loss = loss_ops.log_loss(self._predictions, self._labels, weights)
with self.cached_session():
self.assertAlmostEqual(-np.sum(expected_losses) / 6.0, loss.eval(), 3)
def testNonZeroLossWithOneDimBatchSpecificWeightsSomeZero(self):
weights = constant_op.constant([1.2, 0], shape=[2])
expected_losses = np.multiply(self._expected_losses,
np.asarray([1.2, 1.2, 1.2, 0, 0, 0]).reshape(
(2, 3)))
loss = loss_ops.log_loss(self._predictions, self._labels, weights)
with self.cached_session():
self.assertAlmostEqual(-np.sum(expected_losses) / 3.0, loss.eval(), 3)
def testNonZeroLossWithTwoDimBatchSpecificWeightsSomeZero(self):
weights = constant_op.constant([1.2, 0], shape=[2, 1])
expected_losses = np.multiply(self._expected_losses,
np.asarray([1.2, 1.2, 1.2, 0, 0, 0]).reshape(
(2, 3)))
loss = loss_ops.log_loss(self._predictions, self._labels, weights)
with self.cached_session():
self.assertAlmostEqual(-np.sum(expected_losses) / 3.0, loss.eval(), 3)
def testWeightsWithSameNumDimsButWrongShapeThrowsException(self):
weights = constant_op.constant(np.random.normal(size=(2, 4)), shape=[2, 4])
with self.cached_session():
with self.assertRaises(ValueError):
loss_ops.log_loss(self._predictions, self._labels, weights)
def testNonZeroLossWithMeasurementSpecificWeights(self):
weights = np.array([3, 6, 5, 0, 4, 2]).reshape((2, 3))
expected_losses = np.multiply(self._expected_losses, weights)
loss = loss_ops.log_loss(
self._predictions,
self._labels,
constant_op.constant(
weights, shape=(2, 3)))
with self.cached_session():
self.assertAlmostEqual(-np.sum(expected_losses) / 5.0, loss.eval(), 3)
def testNonZeroLossWithMeasurementSpecificWeightsWithPlaceholder(self):
weights = np.array([3, 6, 5, 0, 4, 2]).reshape((2, 3))
expected_losses = np.multiply(self._expected_losses, weights)
tf_predictions = array_ops.placeholder(dtypes.float32, shape=[2, 3])
loss = loss_ops.log_loss(
tf_predictions,
self._labels,
constant_op.constant(
weights, shape=(2, 3)))
with self.cached_session() as sess:
loss = sess.run(loss, feed_dict={tf_predictions: self._np_predictions})
self.assertAlmostEqual(-np.sum(expected_losses) / 5.0, loss, 3)
def testNonZeroLossWithSampleSpecificWeightsMostZero(self):
weights = np.array([0, 0, 0, 0, 0, 2]).reshape((2, 3))
expected_losses = np.multiply(self._expected_losses, weights)
loss = loss_ops.log_loss(
self._predictions,
self._labels,
constant_op.constant(
weights, shape=(2, 3)))
with self.cached_session():
self.assertAlmostEqual(-np.sum(expected_losses), loss.eval(), 3)
def testNonZeroLossWithSampleSpecificWeightsMostZeroWithPlaceholder(self):
weights = np.array([0, 0, 0, 0, 0, 2]).reshape((2, 3))
expected_losses = np.multiply(self._expected_losses, weights)
tf_predictions = array_ops.placeholder(dtypes.float32, shape=[2, 3])
tf_weights = constant_op.constant(weights, shape=(2, 3))
loss = loss_ops.log_loss(tf_predictions, self._labels, tf_weights)
with self.cached_session() as sess:
loss = sess.run(loss, feed_dict={tf_predictions: self._np_predictions})
self.assertAlmostEqual(-np.sum(expected_losses), loss, 3)
def testLossWithSampleSpecificWeightsAllZero(self):
tf_weights = array_ops.zeros(shape=(2, 3))
loss = loss_ops.log_loss(self._predictions, self._labels, tf_weights)
with self.cached_session():
self.assertAlmostEqual(0.0, loss.eval(), 3)
class HingeLossTest(test.TestCase):
def testIncompatibleShapes(self):
with self.cached_session():
logits = constant_op.constant([[-1.0], [2.1]])
labels = constant_op.constant([0.0, 1.0])
with self.assertRaises(ValueError):
_ = loss_ops.hinge_loss(logits, labels).eval()
def testAllOutsideMargin(self):
with self.cached_session():
logits = constant_op.constant([1.2, -1.4, -1.0, 2.1])
labels = constant_op.constant([1.0, 0.0, 0.0, 1.0])
loss = loss_ops.hinge_loss(logits, labels)
self.assertAllClose(loss.eval(), [0.0, 0.0, 0.0, 0.0], atol=1e-3)
def testSomeInsideMargin(self):
with self.cached_session():
logits = constant_op.constant([[-0.7], [-1.4], [1.4], [0.6]])
labels = constant_op.constant([[0.0], [0.0], [1.0], [1.0]])
loss = loss_ops.hinge_loss(logits, labels)
# Examples 1 and 4 are on the correct side of the hyperplane but within
# the margin so they incur some (small) loss.
self.assertAllClose(loss.eval(), [[0.3], [0.0], [0.0], [0.4]], atol=1e-3)
def testSomeMisclassified(self):
with self.cached_session():
logits = constant_op.constant([[[1.2], [0.4], [-1.0], [-1.1]]])
labels = constant_op.constant([[[1.0], [0.0], [0.0], [1.0]]])
loss = loss_ops.hinge_loss(logits, labels)
# Examples 2 and 4 are on the wrong side of the hyperplane so they incur
# some (fairly large) loss.
self.assertAllClose(
loss.eval(), [[[0.0], [1.4], [0.0], [2.1]]], atol=1e-3)
class MeanSquaredErrorTest(test.TestCase):
def setUp(self):
self._predictions = constant_op.constant([4, 8, 12, 8, 1, 3], shape=(2, 3))
self._labels = constant_op.constant([1, 9, 2, -5, -2, 6], shape=(2, 3))
def testValueErrorThrownWhenWeightIsNone(self):
with self.cached_session():
with self.assertRaises(ValueError):
loss_ops.mean_squared_error(
self._predictions, self._predictions, weights=None)
def testAllCorrectNoLossWeight(self):
loss = loss_ops.mean_squared_error(self._predictions, self._predictions)
with self.cached_session():
self.assertAlmostEqual(0.0, loss.eval(), 3)
def testNonZeroLoss(self):
loss = loss_ops.mean_squared_error(self._predictions, self._labels)
with self.cached_session():
self.assertAlmostEqual(49.5, loss.eval(), 3)
def testNonZeroLossWithPythonScalarWeight(self):
weights = 2.3
loss = loss_ops.mean_squared_error(self._predictions, self._labels, weights)
with self.cached_session():
self.assertAlmostEqual(49.5 * weights, loss.eval(), 3)
def testNonZeroLossWithScalarTensorWeight(self):
weights = 2.3
loss = loss_ops.mean_squared_error(self._predictions, self._labels,
constant_op.constant(weights))
with self.cached_session():
self.assertAlmostEqual(49.5 * weights, loss.eval(), 3)
def testNonZeroLossWithOneDimBatchSpecificWeights(self):
weights = constant_op.constant([1.2, 3.4], shape=[2,])
loss = loss_ops.mean_squared_error(self._predictions, self._labels, weights)
with self.cached_session():
self.assertAlmostEqual(767.8 / 6.0, loss.eval(), 3)
def testNonZeroLossWithTwoDimBatchSpecificWeights(self):
weights = constant_op.constant([1.2, 3.4], shape=[2, 1])
loss = loss_ops.mean_squared_error(self._predictions, self._labels, weights)
with self.cached_session():
self.assertAlmostEqual(767.8 / 6.0, loss.eval(), 3)
def testNonZeroLossWithSampleSpecificWeights(self):
weights = constant_op.constant([3, 6, 5, 0, 4, 2], shape=[2, 3])
loss = loss_ops.mean_squared_error(self._predictions, self._labels, weights)
with self.cached_session():
self.assertAlmostEqual(587 / 5.0, loss.eval(), 3)
def testNonZeroLossWithSampleSpecificWeightsMostZero(self):
weights = constant_op.constant([0, 0, 0, 0, 0, 2], shape=[2, 3])
loss = loss_ops.mean_squared_error(self._predictions, self._labels, weights)
with self.cached_session():
self.assertAlmostEqual(18.0, loss.eval(), 3)
def testLossWithSampleSpecificWeightsAllZero(self):
weights = array_ops.zeros((2, 3))
loss = loss_ops.mean_squared_error(self._predictions, self._labels, weights)
with self.cached_session():
self.assertAlmostEqual(0.0, loss.eval(), 3)
class MeanPairwiseSquaresErrorTest(test.TestCase):
def setUp(self):
self._predictions = np.array([[4, 8, 12], [8, 1, 3]])
self._labels = np.array([[1, 9, 2], [-5, -5, 7]])
batch_size, dims = self._labels.shape
# Compute the expected loss 'manually'.
total = np.zeros((batch_size, 1))
for b in range(batch_size):
for i in range(dims):
for j in range(dims):
x = self._predictions[b, i].item() - self._predictions[b, j].item()
y = self._labels[b, i].item() - self._labels[b, j].item()
tmp = (x - y) * (x - y)
total[b] += tmp
self._expected_losses = np.divide(total, 9.0)
def testValueErrorThrownWhenWeightIsNone(self):
with self.cached_session():
with self.assertRaises(ValueError):
loss_ops.mean_pairwise_squared_error(
predictions=constant_op.constant(self._labels),
labels=constant_op.constant(self._labels),
weights=None)
def testAllCorrectNoLossWeight(self):
loss = loss_ops.mean_pairwise_squared_error(
predictions=constant_op.constant(self._labels),
labels=constant_op.constant(self._labels))
with self.cached_session():
self.assertAlmostEqual(0.0, loss.eval(), 3)
def testNonZeroLoss(self):
loss = loss_ops.mean_pairwise_squared_error(
predictions=constant_op.constant(self._predictions),
labels=constant_op.constant(self._labels))
with self.cached_session():
self.assertAlmostEqual(np.sum(self._expected_losses), loss.eval(), 3)
def testGradientWithZeroWeight(self):
with ops.Graph().as_default():
random_seed.set_random_seed(0)
inputs = array_ops.ones((2, 3))
weights = variable_scope.get_variable(
'weights',
shape=[3, 4],
initializer=init_ops.truncated_normal_initializer())
predictions = math_ops.matmul(inputs, weights)
optimizer = momentum_lib.MomentumOptimizer(
learning_rate=0.001, momentum=0.9)
loss = loss_ops.mean_pairwise_squared_error(predictions, predictions, 0)
gradients_to_variables = optimizer.compute_gradients(loss)
init_op = variables.global_variables_initializer()
with self.cached_session() as sess:
sess.run(init_op)
for grad, _ in gradients_to_variables:
np_grad = sess.run(grad)
self.assertFalse(np.isnan(np_grad).any())
def testNonZeroLossWithPythonScalarWeight(self):
weights = 2.3
loss = loss_ops.mean_pairwise_squared_error(
predictions=constant_op.constant(self._predictions),
labels=constant_op.constant(self._labels),
weights=weights)
with self.cached_session():
self.assertAlmostEqual(weights * np.sum(self._expected_losses),
loss.eval(), 3)
def testNonZeroLossWithScalarTensorWeight(self):
weights = 2.3
loss = loss_ops.mean_pairwise_squared_error(
predictions=constant_op.constant(self._predictions),
labels=constant_op.constant(self._labels),
weights=constant_op.constant(weights))
with self.cached_session():
self.assertAlmostEqual(weights * np.sum(self._expected_losses),
loss.eval(), 3)
def testNonZeroLossWithScalarZeroWeight(self):
weights = 0
loss = loss_ops.mean_pairwise_squared_error(
predictions=constant_op.constant(self._predictions),
labels=constant_op.constant(self._labels),
weights=constant_op.constant(weights))
with self.cached_session():
self.assertAlmostEqual(0, loss.eval(), 3)
def testNonZeroLossWithScalarTensorWeightWithPlaceholder(self):
weights = 2.3
tf_predictions = array_ops.placeholder(
dtypes.float32, shape=self._predictions.shape)
tf_labels = array_ops.placeholder(dtypes.float32, shape=self._labels.shape)
loss = loss_ops.mean_pairwise_squared_error(
predictions=tf_predictions,
labels=tf_labels,
weights=constant_op.constant(weights))
with self.cached_session() as sess:
loss = sess.run(loss,
feed_dict={
tf_predictions: self._predictions,
tf_labels: self._labels,
})
self.assertAlmostEqual(weights * np.sum(self._expected_losses), loss, 3)
def testNonZeroLossWithOneDimBatchSpecificWeights(self):
weights = np.asarray([2.0, 1.0]).reshape((2, 1))
expected_losses = np.multiply(weights, self._expected_losses)
loss = loss_ops.mean_pairwise_squared_error(
predictions=constant_op.constant(self._predictions),
labels=constant_op.constant(self._labels),
weights=constant_op.constant(
weights, shape=[2]))
with self.cached_session():
self.assertAlmostEqual(np.sum(expected_losses), loss.eval(), 3)
def testZeroLossWithOneDimBatchZeroWeights(self):
weights = np.asarray([0.0, 0.0]).reshape((2, 1))
loss = loss_ops.mean_pairwise_squared_error(
predictions=constant_op.constant(self._predictions),
labels=constant_op.constant(self._labels),
weights=constant_op.constant(
weights, shape=[2]))
with self.cached_session():
self.assertAlmostEqual(0, loss.eval(), 3)
def testNonZeroLossWithOneDimBatchSpecificWeightsAndPlaceholders(self):
weights = np.asarray([1.2, 3.4]).reshape((2, 1))
expected_losses = np.multiply(weights, self._expected_losses)
tf_predictions = array_ops.placeholder(
dtypes.float32, shape=self._predictions.shape)
tf_labels = array_ops.placeholder(dtypes.int32, shape=self._labels.shape)
loss = loss_ops.mean_pairwise_squared_error(
predictions=tf_predictions,
labels=tf_labels,
weights=constant_op.constant(
weights, shape=[2]))
with self.cached_session() as sess:
loss = sess.run(loss,
feed_dict={
tf_predictions: self._predictions,
tf_labels: self._labels,
})
self.assertAlmostEqual(np.sum(expected_losses), loss, 3)
def testLossWithAllZeroBatchSpecificWeights(self):
weights = np.zeros((2, 1))
loss = loss_ops.mean_pairwise_squared_error(
predictions=constant_op.constant(self._predictions),
labels=constant_op.constant(self._labels),
weights=constant_op.constant(
weights, shape=[2]))
with self.cached_session():
self.assertAlmostEqual(0.0, loss.eval(), 3)
def testLossIsAssociativeAcrossBatchElements(self):
with ops.Graph().as_default():
random_seed.set_random_seed(0)
height = 3
width = 4
shape = (1, height, width, 1)
labels0 = random_ops.random_uniform(
shape, minval=0, maxval=1, dtype=dtypes.float32)
predictions0 = random_ops.random_uniform(
shape, minval=0, maxval=1, dtype=dtypes.float32)
labels1 = random_ops.random_uniform(
shape, minval=0, maxval=1, dtype=dtypes.float32)
predictions1 = random_ops.random_uniform(
shape, minval=0, maxval=1, dtype=dtypes.float32)
loss0 = loss_ops.mean_pairwise_squared_error(
predictions=predictions0,
labels=labels0)
loss1 = loss_ops.mean_pairwise_squared_error(
predictions=predictions1,
labels=labels1)
loss0_1 = loss_ops.mean_pairwise_squared_error(
predictions=array_ops.concat([predictions0, predictions1], 0),
labels=array_ops.concat([labels0, labels1], 0))
with self.cached_session() as session:
loss0, loss1, loss0_1 = session.run([loss0, loss1, loss0_1])
self.assertTrue(loss0 > 0)
self.assertTrue(loss1 > 0)
self.assertAlmostEqual(loss0 + loss1, loss0_1, 5)
class CosineDistanceLossTest(test.TestCase):
def setUp(self):
self._predictions = np.asarray([
[1, 0, 0], # Batch 1
[0, 0, -1],
[1, 0, 0], # Batch 2
[1, 0, 0],
[0, 0, -1], # Batch 3
[1, 0, 0]
]).reshape((3, 2, 3))
self._labels = np.asarray([[1, 0, 0],
[0, 0, 1],
[0, 1, 0],
[1, 0, 0],
[0, 0, 1],
[0, 1, 0]]).reshape((3, 2, 3))
def testValueErrorThrownWhenWeightIsNone(self):
with self.cached_session():
with self.assertRaises(ValueError):
loss_ops.cosine_distance(
predictions=constant_op.constant(self._labels),
labels=constant_op.constant(self._labels),
dim=2,
weights=None)
def testAllCorrectNoWeights(self):
loss = loss_ops.cosine_distance(
predictions=constant_op.constant(self._labels),
labels=constant_op.constant(self._labels),
dim=2)
with self.cached_session():
self.assertAlmostEqual(0, loss.eval(), 5)
def testPartiallyCorrectWithIntegerValues(self):
loss = loss_ops.cosine_distance(
predictions=constant_op.constant(self._predictions),
labels=constant_op.constant(self._labels),
dim=2)
with self.cached_session():
self.assertAlmostEqual(1, loss.eval(), 5)
def testPartiallyCorrectFloatingPointValues(self):
predictions = np.matrix(
('0.819031913261206 0.567041924552012 0.087465312324590;'
'-0.665139432070255 -0.739487441769973 -0.103671883216994;'
'0.707106781186548 -0.707106781186548 0'))
labels = np.matrix(('0.819031913261206 0.567041924552012 0.087465312324590;'
'0.665139432070255 0.739487441769973 0.103671883216994;'
'0.707106781186548 0.707106781186548 0'))
tf_preds = constant_op.constant(
predictions, shape=(3, 1, 3), dtype=dtypes.float32)
tf_labels = constant_op.constant(
labels, shape=(3, 1, 3), dtype=dtypes.float32)
loss = loss_ops.cosine_distance(tf_preds, tf_labels, dim=2)
with self.cached_session():
self.assertAlmostEqual(1.0, loss.eval(), 5)
def testSampleSpecificWeights(self):
loss = loss_ops.cosine_distance(
predictions=constant_op.constant(self._predictions),
labels=constant_op.constant(self._labels),
dim=2,
weights=constant_op.constant([1, 0, 0]))
with self.cached_session():
self.assertEqual(1.0, loss.eval())
def testMeasurementSpecificWeights(self):
loss = loss_ops.cosine_distance(
predictions=constant_op.constant(self._predictions),
labels=constant_op.constant(self._labels),
dim=2,
weights=constant_op.constant(
[1, 0, 0, 1, 1, 1], shape=(3, 2)))
with self.cached_session():
self.assertEqual(3.0 / 4.0, loss.eval())
def testValueErrorThrownWithShapelessPlaceholder(self):
tf_predictions = array_ops.placeholder(dtypes.float32)
with self.cached_session():
with self.assertRaises(ValueError):
loss_ops.cosine_distance(
predictions=tf_predictions,
labels=constant_op.constant(self._labels),
dim=2,
weights=constant_op.constant(
[1, 0, 0, 1, 1, 1], shape=(3, 2)))
def testMeasurementSpecificWeightsWithPlaceholderWithShape(self):
tf_predictions = array_ops.placeholder(
dtypes.float32, shape=self._labels.shape)
loss = loss_ops.cosine_distance(
predictions=tf_predictions,
labels=constant_op.constant(self._labels),
dim=2,
weights=constant_op.constant(
[1, 0, 0, 1, 1, 1], shape=(3, 2)))
with self.cached_session() as sess:
loss = sess.run(loss, feed_dict={tf_predictions: self._predictions})
self.assertEqual(3.0 / 4.0, loss)
def testZeroLossWhenAllSampleSpecificWeightsAreZero(self):
loss = loss_ops.cosine_distance(
predictions=constant_op.constant(self._predictions),
labels=constant_op.constant(self._labels),
dim=2,
weights=array_ops.zeros((3,)))
with self.cached_session():
self.assertEqual(0, loss.eval())
def testZeroLossWhenAllMeasurementSpecificWeightsAreZero(self):
loss = loss_ops.cosine_distance(
predictions=constant_op.constant(self._predictions),
labels=constant_op.constant(self._labels),
dim=2,
weights=array_ops.zeros((3, 2)))
with self.cached_session():
self.assertEqual(0, loss.eval())
class ComputeWeightedLossTest(test.TestCase):
def testHingeLoss(self):
logits = constant_op.constant([1.2, 0.4, -1.0, -1.1])
labels = constant_op.constant([1.0, 0.0, 0.0, 1.0])
losses = loss_ops.hinge_loss(logits, labels)
self.assertFalse(loss_ops.get_losses())
loss = loss_ops.compute_weighted_loss(losses)
self.assertTrue(loss_ops.get_losses())
with self.cached_session():
self.assertAllClose(losses.eval(), [0.0, 1.4, 0.0, 2.1], atol=1e-3)
self.assertAllClose(loss.eval(), 3.5 / 4.0, atol=1e-3)
class AddLossTest(test.TestCase):
def testAddExternalLoss(self):
logits = constant_op.constant([[1.2, 0.4, -1.0, -1.1]])
labels = constant_op.constant([[1.0, 0.0, 0.0, 1.0]])
losses = loss_ops.hinge_loss(logits, labels)
self.assertFalse(loss_ops.get_losses())
loss_ops.add_loss(math_ops.reduce_mean(losses))
self.assertTrue(loss_ops.get_losses())
total_loss = loss_ops.get_total_loss()
with self.cached_session():
self.assertAllClose(losses.eval(), [[0.0, 1.4, 0.0, 2.1]], atol=1e-3)
self.assertAllClose(total_loss.eval(), 3.5 / 4.0, atol=1e-3)
def testNoneLossCollection(self):
logits = constant_op.constant([[1.2, 0.4, -1.0, -1.1]])
labels = constant_op.constant([[1.0, 0.0, 0.0, 1.0]])
losses = loss_ops.hinge_loss(logits, labels)
self.assertFalse(loss_ops.get_losses())
loss_ops.add_loss(math_ops.reduce_mean(losses), loss_collection=None)
self.assertFalse(loss_ops.get_losses())
with self.cached_session():
self.assertAllClose(losses.eval(), [[0.0, 1.4, 0.0, 2.1]], atol=1e-3)
def testNoCollectLosses(self):
logits = constant_op.constant([[1.2, 0.4, -1.0, -1.1]])
labels = constant_op.constant([[1.0, 0.0, 0.0, 1.0]])
self.assertFalse(loss_ops.get_losses())
with arg_scope([loss_ops.add_loss], loss_collection=None):
loss_ops.absolute_difference(logits, labels)
loss_ops.log_loss(logits, labels)
loss_ops.mean_squared_error(logits, labels)
loss_ops.sigmoid_cross_entropy(logits, labels)
loss_ops.softmax_cross_entropy(logits, labels)
self.assertFalse(loss_ops.get_losses())
def testNoCollectLossesBatch2(self):
logits = constant_op.constant([[1.2, 0.4, -1.0, -1.1]] * 2)
labels = constant_op.constant([[1.0, 0.0, 0.0, 1.0]] * 2)
self.assertFalse(loss_ops.get_losses())
with arg_scope([loss_ops.add_loss], loss_collection=None):
loss_ops.absolute_difference(logits, labels)
loss_ops.log_loss(logits, labels)
loss_ops.mean_squared_error(logits, labels)
loss_ops.sigmoid_cross_entropy(logits, labels)
loss_ops.softmax_cross_entropy(logits, labels)
self.assertFalse(loss_ops.get_losses())
if __name__ == '__main__':
test.main()
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
5914,
14,
17865,
14,
1548,
14,
17865,
14,
4358,
63,
1483,
1041,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
12,
71,
13,
4087,
13,
646,
13,
1648,
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,
3,
4287,
26,
4756,
29,
8618,
13,
646,
199,
199,
646,
2680,
465,
980,
199,
504,
3228,
14,
2828,
14,
4857,
14,
1548,
14,
1483,
492,
1680,
63,
2645,
199,
504,
3228,
14,
2828,
14,
17865,
14,
1548,
14,
17865,
492,
5621,
63,
1483,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2196,
63,
5176,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
4205,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1750,
63,
2645,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
7588,
492,
23887,
465,
23887,
63,
773,
421,
199,
533,
24964,
32279,
8610,
774,
8,
396,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
423,
9869,
275,
4413,
63,
411,
14,
4083,
779,
20,
12,
1695,
12,
3144,
12,
1695,
12,
413,
12,
650,
467,
2215,
2687,
18,
12,
650,
430,
272,
291,
423,
3512,
275,
4413,
63,
411,
14,
4083,
779,
17,
12,
1749,
12,
499,
12,
446,
21,
12,
446,
18,
12,
1227,
467,
2215,
2687,
18,
12,
650,
430,
819,
347,
511,
3393,
2719,
18406,
11423,
16359,
1831,
403,
8,
277,
304,
272,
543,
291,
14,
5245,
63,
1730,
837,
489,
543,
291,
14,
1855,
8,
3393,
304,
267,
5621,
63,
1483,
14,
6116,
63,
9196,
8,
288,
291,
423,
9869,
12,
291,
423,
9869,
12,
4931,
29,
403,
9,
819,
347,
511,
2422,
19993,
1944,
8610,
16359,
8,
277,
304,
272,
5621,
275,
5621,
63,
1483,
14,
6116,
63,
9196,
8,
277,
423,
9869,
12,
291,
423,
9869,
9,
272,
543,
291,
14,
5245,
63,
1730,
837,
489,
291,
14,
7904,
8,
16,
14,
16,
12,
5621,
14,
2579,
1062,
650,
9,
819,
347,
511,
6932,
8681,
8610,
8,
277,
304,
272,
5621,
275,
5621,
63,
1483,
14,
6116,
63,
9196,
8,
277,
423,
9869,
12,
291,
423,
3512,
9,
272,
543,
291,
14,
5245,
63,
1730,
837,
489,
291,
14,
7904,
8,
21,
14,
21,
12,
5621,
14,
2579,
1062,
650,
9,
819,
347,
511,
6932,
8681,
8610,
3007,
4718,
13090,
16359,
8,
277,
304,
272,
4931,
275,
499,
14,
19,
272,
5621,
275,
5621,
63,
1483,
14,
6116,
63,
9196,
8,
277,
423,
9869,
12,
291,
423,
3512,
12,
3147,
4931,
9,
272,
543,
291,
14,
5245,
63,
1730,
837,
489,
291,
14,
7904,
8,
21,
14,
21,
627,
4931,
12,
5621,
14,
2579,
1062,
650,
9,
819,
347,
511,
6932,
8681,
8610,
3007,
13090,
3861,
16359,
8,
277,
304,
272,
4931,
275,
499,
14,
19,
272,
5621,
275,
5621,
63,
1483,
14,
6116,
63,
9196,
8,
277,
423,
9869,
12,
291,
423,
3512,
12,
3147,
4413,
63,
411,
14,
4083,
8,
4916,
430,
272,
543,
291,
14,
5245,
63,
1730,
837,
489,
291,
14,
7904,
8,
21,
14,
21,
627,
4931,
12,
5621,
14,
2579,
1062,
650,
9,
819,
347,
511,
6932,
8681,
8610,
3007,
4395,
19156,
8842,
16786,
23885,
8,
277,
304,
272,
4931,
275,
4413,
63,
411,
14,
4083,
779,
17,
14,
18,
12,
378,
14,
16,
467,
2215,
1524,
18,
30453,
272,
5621,
275,
5621,
63,
1483,
14,
6116,
63,
9196,
8,
277,
423,
9869,
12,
291,
423,
3512,
12,
3147,
4931,
9,
272,
543,
291,
14,
5245,
63,
1730,
837,
489,
291,
14,
7904,
8,
21,
14,
22,
12,
5621,
14,
2579,
1062,
650,
9,
819,
347,
511,
6932,
8681,
8610,
3007,
11467,
19156,
8842,
16786,
23885,
8,
277,
304,
272,
4931,
275,
4413,
63,
411,
14,
4083,
779,
17,
14,
18,
12,
378,
14,
16,
467,
2215,
1524,
18,
12,
413,
566,
272,
5621,
275,
5621,
63,
1483,
14,
6116,
63,
9196,
8,
277,
423,
9869,
12,
291,
423,
3512,
12,
3147,
4931,
9,
272,
543,
291,
14,
5245,
63,
1730,
837,
489,
291,
14,
7904,
8,
21,
14,
22,
12,
5621,
14,
2579,
1062,
650,
9,
819,
347,
511,
6932,
8681,
8610,
3007,
8176,
16786,
23885,
8,
277,
304,
272,
4931,
275,
4413,
63,
411,
14,
4083,
779,
19,
12,
1227,
12,
959,
12,
378,
12,
841,
12,
499,
467,
2215,
1524,
18,
12,
650,
566,
272,
5621,
275,
5621,
63,
1483,
14,
6116,
63,
9196,
8,
277,
423,
9869,
12,
291,
423,
3512,
12,
3147,
4931,
9,
272,
543,
291,
14,
5245,
63,
1730,
837,
489,
291,
14,
7904,
8,
975,
14,
22,
12,
5621,
14,
2579,
1062,
650,
9,
819,
347,
511,
6932,
8681,
8610,
3007,
8176,
16786,
23885,
24625,
8681,
8,
277,
304,
272,
4931,
275,
4413,
63,
411,
14,
4083,
779,
16,
12,
378,
12,
378,
12
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
5914,
14,
17865,
14,
1548,
14,
17865,
14,
4358,
63,
1483,
1041,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
12,
71,
13,
4087,
13,
646,
13,
1648,
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,
3,
4287,
26,
4756,
29,
8618,
13,
646,
199,
199,
646,
2680,
465,
980,
199,
504,
3228,
14,
2828,
14,
4857,
14,
1548,
14,
1483,
492,
1680,
63,
2645,
199,
504,
3228,
14,
2828,
14,
17865,
14,
1548,
14,
17865,
492,
5621,
63,
1483,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2196,
63,
5176,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
4205,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1750,
63,
2645,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
7588,
492,
23887,
465,
23887,
63,
773,
421,
199,
533,
24964,
32279,
8610,
774,
8,
396,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
423,
9869,
275,
4413,
63,
411,
14,
4083,
779,
20,
12,
1695,
12,
3144,
12,
1695,
12,
413,
12,
650,
467,
2215,
2687,
18,
12,
650,
430,
272,
291,
423,
3512,
275,
4413,
63,
411,
14,
4083,
779,
17,
12,
1749,
12,
499,
12,
446,
21,
12,
446,
18,
12,
1227,
467,
2215,
2687,
18,
12,
650,
430,
819,
347,
511,
3393,
2719,
18406,
11423,
16359,
1831,
403,
8,
277,
304,
272,
543,
291,
14,
5245,
63,
1730,
837,
489,
543,
291,
14,
1855,
8,
3393,
304,
267,
5621,
63,
1483,
14,
6116,
63,
9196,
8,
288,
291,
423,
9869,
12,
291,
423,
9869,
12,
4931,
29,
403,
9,
819,
347,
511,
2422,
19993,
1944,
8610,
16359,
8,
277,
304,
272,
5621,
275,
5621,
63,
1483,
14,
6116,
63,
9196,
8,
277,
423,
9869,
12,
291,
423,
9869,
9,
272,
543,
291,
14,
5245,
63,
1730,
837,
489,
291,
14,
7904,
8,
16,
14,
16,
12,
5621,
14,
2579,
1062,
650,
9,
819,
347,
511,
6932,
8681,
8610,
8,
277,
304,
272,
5621,
275,
5621,
63,
1483,
14,
6116,
63,
9196,
8,
277,
423,
9869,
12,
291,
423,
3512,
9,
272,
543,
291,
14,
5245,
63,
1730,
837,
489,
291,
14,
7904,
8,
21,
14,
21,
12,
5621,
14,
2579,
1062,
650,
9,
819,
347,
511,
6932,
8681,
8610,
3007,
4718,
13090,
16359,
8,
277,
304,
272,
4931,
275,
499,
14,
19,
272,
5621,
275,
5621,
63,
1483,
14,
6116,
63,
9196,
8,
277,
423,
9869,
12,
291,
423,
3512,
12,
3147,
4931,
9,
272,
543,
291,
14,
5245,
63,
1730,
837,
489,
291,
14,
7904,
8,
21,
14,
21,
627,
4931,
12,
5621,
14,
2579,
1062,
650,
9,
819,
347,
511,
6932,
8681,
8610,
3007,
13090,
3861,
16359,
8,
277,
304,
272,
4931,
275,
499,
14,
19,
272,
5621,
275,
5621,
63,
1483,
14,
6116,
63,
9196,
8,
277,
423,
9869,
12,
291,
423,
3512,
12,
3147,
4413,
63,
411,
14,
4083,
8,
4916,
430,
272,
543,
291,
14,
5245,
63,
1730,
837,
489,
291,
14,
7904,
8,
21,
14,
21,
627,
4931,
12,
5621,
14,
2579,
1062,
650,
9,
819,
347,
511,
6932,
8681,
8610,
3007,
4395,
19156,
8842,
16786,
23885,
8,
277,
304,
272,
4931,
275,
4413,
63,
411,
14,
4083,
779,
17,
14,
18,
12,
378,
14,
16,
467,
2215,
1524,
18,
30453,
272,
5621,
275,
5621,
63,
1483,
14,
6116,
63,
9196,
8,
277,
423,
9869,
12,
291,
423,
3512,
12,
3147,
4931,
9,
272,
543,
291,
14,
5245,
63,
1730,
837,
489,
291,
14,
7904,
8,
21,
14,
22,
12,
5621,
14,
2579,
1062,
650,
9,
819,
347,
511,
6932,
8681,
8610,
3007,
11467,
19156,
8842,
16786,
23885,
8,
277,
304,
272,
4931,
275,
4413,
63,
411,
14,
4083,
779,
17,
14,
18,
12,
378,
14,
16,
467,
2215,
1524,
18,
12,
413,
566,
272,
5621,
275,
5621,
63,
1483,
14,
6116,
63,
9196,
8,
277,
423,
9869,
12,
291,
423,
3512,
12,
3147,
4931,
9,
272,
543,
291,
14,
5245,
63,
1730,
837,
489,
291,
14,
7904,
8,
21,
14,
22,
12,
5621,
14,
2579,
1062,
650,
9,
819,
347,
511,
6932,
8681,
8610,
3007,
8176,
16786,
23885,
8,
277,
304,
272,
4931,
275,
4413,
63,
411,
14,
4083,
779,
19,
12,
1227,
12,
959,
12,
378,
12,
841,
12,
499,
467,
2215,
1524,
18,
12,
650,
566,
272,
5621,
275,
5621,
63,
1483,
14,
6116,
63,
9196,
8,
277,
423,
9869,
12,
291,
423,
3512,
12,
3147,
4931,
9,
272,
543,
291,
14,
5245,
63,
1730,
837,
489,
291,
14,
7904,
8,
975,
14,
22,
12,
5621,
14,
2579,
1062,
650,
9,
819,
347,
511,
6932,
8681,
8610,
3007,
8176,
16786,
23885,
24625,
8681,
8,
277,
304,
272,
4931,
275,
4413,
63,
411,
14,
4083,
779,
16,
12,
378,
12,
378,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
lugensa/sqlalchemy-migrate
|
migrate/changeset/schema.py
|
60
|
22855
|
"""
Schema module providing common schema operations.
"""
import warnings
from UserDict import DictMixin
import sqlalchemy
from sqlalchemy.schema import ForeignKeyConstraint
from sqlalchemy.schema import UniqueConstraint
from migrate.exceptions import *
from migrate.changeset import SQLA_07
from migrate.changeset.databases.visitor import (get_engine_visitor,
run_single_visitor)
__all__ = [
'create_column',
'drop_column',
'alter_column',
'rename_table',
'rename_index',
'ChangesetTable',
'ChangesetColumn',
'ChangesetIndex',
'ChangesetDefaultClause',
'ColumnDelta',
]
def create_column(column, table=None, *p, **kw):
"""Create a column, given the table.
API to :meth:`ChangesetColumn.create`.
"""
if table is not None:
return table.create_column(column, *p, **kw)
return column.create(*p, **kw)
def drop_column(column, table=None, *p, **kw):
"""Drop a column, given the table.
API to :meth:`ChangesetColumn.drop`.
"""
if table is not None:
return table.drop_column(column, *p, **kw)
return column.drop(*p, **kw)
def rename_table(table, name, engine=None, **kw):
"""Rename a table.
If Table instance is given, engine is not used.
API to :meth:`ChangesetTable.rename`.
:param table: Table to be renamed.
:param name: New name for Table.
:param engine: Engine instance.
:type table: string or Table instance
:type name: string
:type engine: obj
"""
table = _to_table(table, engine)
table.rename(name, **kw)
def rename_index(index, name, table=None, engine=None, **kw):
"""Rename an index.
If Index instance is given,
table and engine are not used.
API to :meth:`ChangesetIndex.rename`.
:param index: Index to be renamed.
:param name: New name for index.
:param table: Table to which Index is reffered.
:param engine: Engine instance.
:type index: string or Index instance
:type name: string
:type table: string or Table instance
:type engine: obj
"""
index = _to_index(index, table, engine)
index.rename(name, **kw)
def alter_column(*p, **k):
"""Alter a column.
This is a helper function that creates a :class:`ColumnDelta` and
runs it.
:argument column:
The name of the column to be altered or a
:class:`ChangesetColumn` column representing it.
:param table:
A :class:`~sqlalchemy.schema.Table` or table name to
for the table where the column will be changed.
:param engine:
The :class:`~sqlalchemy.engine.base.Engine` to use for table
reflection and schema alterations.
:returns: A :class:`ColumnDelta` instance representing the change.
"""
if 'table' not in k and isinstance(p[0], sqlalchemy.Column):
k['table'] = p[0].table
if 'engine' not in k:
k['engine'] = k['table'].bind
# deprecation
if len(p) >= 2 and isinstance(p[1], sqlalchemy.Column):
warnings.warn(
"Passing a Column object to alter_column is deprecated."
" Just pass in keyword parameters instead.",
MigrateDeprecationWarning
)
engine = k['engine']
# enough tests seem to break when metadata is always altered
# that this crutch has to be left in until they can be sorted
# out
k['alter_metadata']=True
delta = ColumnDelta(*p, **k)
visitorcallable = get_engine_visitor(engine, 'schemachanger')
engine._run_visitor(visitorcallable, delta)
return delta
def _to_table(table, engine=None):
"""Return if instance of Table, else construct new with metadata"""
if isinstance(table, sqlalchemy.Table):
return table
# Given: table name, maybe an engine
meta = sqlalchemy.MetaData()
if engine is not None:
meta.bind = engine
return sqlalchemy.Table(table, meta)
def _to_index(index, table=None, engine=None):
"""Return if instance of Index, else construct new with metadata"""
if isinstance(index, sqlalchemy.Index):
return index
# Given: index name; table name required
table = _to_table(table, engine)
ret = sqlalchemy.Index(index)
ret.table = table
return ret
class ColumnDelta(DictMixin, sqlalchemy.schema.SchemaItem):
"""Extracts the differences between two columns/column-parameters
May receive parameters arranged in several different ways:
* **current_column, new_column, \*p, \*\*kw**
Additional parameters can be specified to override column
differences.
* **current_column, \*p, \*\*kw**
Additional parameters alter current_column. Table name is extracted
from current_column object.
Name is changed to current_column.name from current_name,
if current_name is specified.
* **current_col_name, \*p, \*\*kw**
Table kw must specified.
:param table: Table at which current Column should be bound to.\
If table name is given, reflection will be used.
:type table: string or Table instance
:param metadata: A :class:`MetaData` instance to store
reflected table names
:param engine: When reflecting tables, either engine or metadata must \
be specified to acquire engine object.
:type engine: :class:`Engine` instance
:returns: :class:`ColumnDelta` instance provides interface for altered attributes to \
`result_column` through :func:`dict` alike object.
* :class:`ColumnDelta`.result_column is altered column with new attributes
* :class:`ColumnDelta`.current_name is current name of column in db
"""
# Column attributes that can be altered
diff_keys = ('name', 'type', 'primary_key', 'nullable',
'server_onupdate', 'server_default', 'autoincrement')
diffs = dict()
__visit_name__ = 'column'
def __init__(self, *p, **kw):
# 'alter_metadata' is not a public api. It exists purely
# as a crutch until the tests that fail when 'alter_metadata'
# behaviour always happens can be sorted out
self.alter_metadata = kw.pop("alter_metadata", False)
self.meta = kw.pop("metadata", None)
self.engine = kw.pop("engine", None)
# Things are initialized differently depending on how many column
# parameters are given. Figure out how many and call the appropriate
# method.
if len(p) >= 1 and isinstance(p[0], sqlalchemy.Column):
# At least one column specified
if len(p) >= 2 and isinstance(p[1], sqlalchemy.Column):
# Two columns specified
diffs = self.compare_2_columns(*p, **kw)
else:
# Exactly one column specified
diffs = self.compare_1_column(*p, **kw)
else:
# Zero columns specified
if not len(p) or not isinstance(p[0], basestring):
raise ValueError("First argument must be column name")
diffs = self.compare_parameters(*p, **kw)
self.apply_diffs(diffs)
def __repr__(self):
return '<ColumnDelta altermetadata=%r, %s>' % (
self.alter_metadata,
super(ColumnDelta, self).__repr__()
)
def __getitem__(self, key):
if key not in self.keys():
raise KeyError("No such diff key, available: %s" % self.diffs )
return getattr(self.result_column, key)
def __setitem__(self, key, value):
if key not in self.keys():
raise KeyError("No such diff key, available: %s" % self.diffs )
setattr(self.result_column, key, value)
def __delitem__(self, key):
raise NotImplementedError
def keys(self):
return self.diffs.keys()
def compare_parameters(self, current_name, *p, **k):
"""Compares Column objects with reflection"""
self.table = k.pop('table')
self.result_column = self._table.c.get(current_name)
if len(p):
k = self._extract_parameters(p, k, self.result_column)
return k
def compare_1_column(self, col, *p, **k):
"""Compares one Column object"""
self.table = k.pop('table', None)
if self.table is None:
self.table = col.table
self.result_column = col
if len(p):
k = self._extract_parameters(p, k, self.result_column)
return k
def compare_2_columns(self, old_col, new_col, *p, **k):
"""Compares two Column objects"""
self.process_column(new_col)
self.table = k.pop('table', None)
# we cannot use bool() on table in SA06
if self.table is None:
self.table = old_col.table
if self.table is None:
new_col.table
self.result_column = old_col
# set differences
# leave out some stuff for later comp
for key in (set(self.diff_keys) - set(('type',))):
val = getattr(new_col, key, None)
if getattr(self.result_column, key, None) != val:
k.setdefault(key, val)
# inspect types
if not self.are_column_types_eq(self.result_column.type, new_col.type):
k.setdefault('type', new_col.type)
if len(p):
k = self._extract_parameters(p, k, self.result_column)
return k
def apply_diffs(self, diffs):
"""Populate dict and column object with new values"""
self.diffs = diffs
for key in self.diff_keys:
if key in diffs:
setattr(self.result_column, key, diffs[key])
self.process_column(self.result_column)
# create an instance of class type if not yet
if 'type' in diffs and callable(self.result_column.type):
self.result_column.type = self.result_column.type()
# add column to the table
if self.table is not None and self.alter_metadata:
self.result_column.add_to_table(self.table)
def are_column_types_eq(self, old_type, new_type):
"""Compares two types to be equal"""
ret = old_type.__class__ == new_type.__class__
# String length is a special case
if ret and isinstance(new_type, sqlalchemy.types.String):
ret = (getattr(old_type, 'length', None) == \
getattr(new_type, 'length', None))
return ret
def _extract_parameters(self, p, k, column):
"""Extracts data from p and modifies diffs"""
p = list(p)
while len(p):
if isinstance(p[0], basestring):
k.setdefault('name', p.pop(0))
elif isinstance(p[0], sqlalchemy.types.AbstractType):
k.setdefault('type', p.pop(0))
elif callable(p[0]):
p[0] = p[0]()
else:
break
if len(p):
new_col = column.copy_fixed()
new_col._init_items(*p)
k = self.compare_2_columns(column, new_col, **k)
return k
def process_column(self, column):
"""Processes default values for column"""
# XXX: this is a snippet from SA processing of positional parameters
toinit = list()
if column.server_default is not None:
if isinstance(column.server_default, sqlalchemy.FetchedValue):
toinit.append(column.server_default)
else:
toinit.append(sqlalchemy.DefaultClause(column.server_default))
if column.server_onupdate is not None:
if isinstance(column.server_onupdate, FetchedValue):
toinit.append(column.server_default)
else:
toinit.append(sqlalchemy.DefaultClause(column.server_onupdate,
for_update=True))
if toinit:
column._init_items(*toinit)
def _get_table(self):
return getattr(self, '_table', None)
def _set_table(self, table):
if isinstance(table, basestring):
if self.alter_metadata:
if not self.meta:
raise ValueError("metadata must be specified for table"
" reflection when using alter_metadata")
meta = self.meta
if self.engine:
meta.bind = self.engine
else:
if not self.engine and not self.meta:
raise ValueError("engine or metadata must be specified"
" to reflect tables")
if not self.engine:
self.engine = self.meta.bind
meta = sqlalchemy.MetaData(bind=self.engine)
self._table = sqlalchemy.Table(table, meta, autoload=True)
elif isinstance(table, sqlalchemy.Table):
self._table = table
if not self.alter_metadata:
self._table.meta = sqlalchemy.MetaData(bind=self._table.bind)
def _get_result_column(self):
return getattr(self, '_result_column', None)
def _set_result_column(self, column):
"""Set Column to Table based on alter_metadata evaluation."""
self.process_column(column)
if not hasattr(self, 'current_name'):
self.current_name = column.name
if self.alter_metadata:
self._result_column = column
else:
self._result_column = column.copy_fixed()
table = property(_get_table, _set_table)
result_column = property(_get_result_column, _set_result_column)
class ChangesetTable(object):
"""Changeset extensions to SQLAlchemy tables."""
def create_column(self, column, *p, **kw):
"""Creates a column.
The column parameter may be a column definition or the name of
a column in this table.
API to :meth:`ChangesetColumn.create`
:param column: Column to be created
:type column: Column instance or string
"""
if not isinstance(column, sqlalchemy.Column):
# It's a column name
column = getattr(self.c, str(column))
column.create(table=self, *p, **kw)
def drop_column(self, column, *p, **kw):
"""Drop a column, given its name or definition.
API to :meth:`ChangesetColumn.drop`
:param column: Column to be droped
:type column: Column instance or string
"""
if not isinstance(column, sqlalchemy.Column):
# It's a column name
try:
column = getattr(self.c, str(column))
except AttributeError:
# That column isn't part of the table. We don't need
# its entire definition to drop the column, just its
# name, so create a dummy column with the same name.
column = sqlalchemy.Column(str(column), sqlalchemy.Integer())
column.drop(table=self, *p, **kw)
def rename(self, name, connection=None, **kwargs):
"""Rename this table.
:param name: New name of the table.
:type name: string
:param connection: reuse connection istead of creating new one.
:type connection: :class:`sqlalchemy.engine.base.Connection` instance
"""
engine = self.bind
self.new_name = name
visitorcallable = get_engine_visitor(engine, 'schemachanger')
run_single_visitor(engine, visitorcallable, self, connection, **kwargs)
# Fix metadata registration
self.name = name
self.deregister()
self._set_parent(self.metadata)
def _meta_key(self):
"""Get the meta key for this table."""
return sqlalchemy.schema._get_table_key(self.name, self.schema)
def deregister(self):
"""Remove this table from its metadata"""
if SQLA_07:
self.metadata._remove_table(self.name, self.schema)
else:
key = self._meta_key()
meta = self.metadata
if key in meta.tables:
del meta.tables[key]
class ChangesetColumn(object):
"""Changeset extensions to SQLAlchemy columns."""
def alter(self, *p, **k):
"""Makes a call to :func:`alter_column` for the column this
method is called on.
"""
if 'table' not in k:
k['table'] = self.table
if 'engine' not in k:
k['engine'] = k['table'].bind
return alter_column(self, *p, **k)
def create(self, table=None, index_name=None, unique_name=None,
primary_key_name=None, populate_default=True, connection=None, **kwargs):
"""Create this column in the database.
Assumes the given table exists. ``ALTER TABLE ADD COLUMN``,
for most databases.
:param table: Table instance to create on.
:param index_name: Creates :class:`ChangesetIndex` on this column.
:param unique_name: Creates :class:\
`~migrate.changeset.constraint.UniqueConstraint` on this column.
:param primary_key_name: Creates :class:\
`~migrate.changeset.constraint.PrimaryKeyConstraint` on this column.
:param populate_default: If True, created column will be \
populated with defaults
:param connection: reuse connection istead of creating new one.
:type table: Table instance
:type index_name: string
:type unique_name: string
:type primary_key_name: string
:type populate_default: bool
:type connection: :class:`sqlalchemy.engine.base.Connection` instance
:returns: self
"""
self.populate_default = populate_default
self.index_name = index_name
self.unique_name = unique_name
self.primary_key_name = primary_key_name
for cons in ('index_name', 'unique_name', 'primary_key_name'):
self._check_sanity_constraints(cons)
self.add_to_table(table)
engine = self.table.bind
visitorcallable = get_engine_visitor(engine, 'columngenerator')
engine._run_visitor(visitorcallable, self, connection, **kwargs)
# TODO: reuse existing connection
if self.populate_default and self.default is not None:
stmt = table.update().values({self: engine._execute_default(self.default)})
engine.execute(stmt)
return self
def drop(self, table=None, connection=None, **kwargs):
"""Drop this column from the database, leaving its table intact.
``ALTER TABLE DROP COLUMN``, for most databases.
:param connection: reuse connection istead of creating new one.
:type connection: :class:`sqlalchemy.engine.base.Connection` instance
"""
if table is not None:
self.table = table
engine = self.table.bind
visitorcallable = get_engine_visitor(engine, 'columndropper')
engine._run_visitor(visitorcallable, self, connection, **kwargs)
self.remove_from_table(self.table, unset_table=False)
self.table = None
return self
def add_to_table(self, table):
if table is not None and self.table is None:
if SQLA_07:
table.append_column(self)
else:
self._set_parent(table)
def _col_name_in_constraint(self,cons,name):
return False
def remove_from_table(self, table, unset_table=True):
# TODO: remove primary keys, constraints, etc
if unset_table:
self.table = None
to_drop = set()
for index in table.indexes:
columns = []
for col in index.columns:
if col.name!=self.name:
columns.append(col)
if columns:
index.columns=columns
else:
to_drop.add(index)
table.indexes = table.indexes - to_drop
to_drop = set()
for cons in table.constraints:
# TODO: deal with other types of constraint
if isinstance(cons,(ForeignKeyConstraint,
UniqueConstraint)):
for col_name in cons.columns:
if not isinstance(col_name,basestring):
col_name = col_name.name
if self.name==col_name:
to_drop.add(cons)
table.constraints = table.constraints - to_drop
if table.c.contains_column(self):
if SQLA_07:
table._columns.remove(self)
else:
table.c.remove(self)
# TODO: this is fixed in 0.6
def copy_fixed(self, **kw):
"""Create a copy of this ``Column``, with all attributes."""
return sqlalchemy.Column(self.name, self.type, self.default,
key=self.key,
primary_key=self.primary_key,
nullable=self.nullable,
quote=self.quote,
index=self.index,
unique=self.unique,
onupdate=self.onupdate,
autoincrement=self.autoincrement,
server_default=self.server_default,
server_onupdate=self.server_onupdate,
*[c.copy(**kw) for c in self.constraints])
def _check_sanity_constraints(self, name):
"""Check if constraints names are correct"""
obj = getattr(self, name)
if (getattr(self, name[:-5]) and not obj):
raise InvalidConstraintError("Column.create() accepts index_name,"
" primary_key_name and unique_name to generate constraints")
if not isinstance(obj, basestring) and obj is not None:
raise InvalidConstraintError(
"%s argument for column must be constraint name" % name)
class ChangesetIndex(object):
"""Changeset extensions to SQLAlchemy Indexes."""
__visit_name__ = 'index'
def rename(self, name, connection=None, **kwargs):
"""Change the name of an index.
:param name: New name of the Index.
:type name: string
:param connection: reuse connection istead of creating new one.
:type connection: :class:`sqlalchemy.engine.base.Connection` instance
"""
engine = self.table.bind
self.new_name = name
visitorcallable = get_engine_visitor(engine, 'schemachanger')
engine._run_visitor(visitorcallable, self, connection, **kwargs)
self.name = name
class ChangesetDefaultClause(object):
"""Implements comparison between :class:`DefaultClause` instances"""
def __eq__(self, other):
if isinstance(other, self.__class__):
if self.arg == other.arg:
return True
def __ne__(self, other):
return not self.__eq__(other)
|
mit
|
[
624,
2043,
13268,
859,
13070,
2863,
4177,
5331,
14,
199,
624,
199,
646,
3598,
199,
199,
504,
32241,
492,
7448,
4256,
199,
199,
646,
8335,
199,
199,
504,
8335,
14,
3629,
492,
12718,
8463,
199,
504,
8335,
14,
3629,
492,
18276,
8463,
199,
199,
504,
12810,
14,
3924,
492,
627,
199,
504,
12810,
14,
26027,
492,
5385,
33,
63,
1780,
199,
504,
12810,
14,
26027,
14,
17439,
14,
19863,
492,
334,
362,
63,
3908,
63,
19863,
12,
1740,
1255,
63,
4780,
63,
19863,
9,
421,
199,
363,
452,
363,
275,
359,
272,
283,
981,
63,
2301,
297,
272,
283,
4824,
63,
2301,
297,
272,
283,
11858,
63,
2301,
297,
272,
283,
8165,
63,
1224,
297,
272,
283,
8165,
63,
1080,
297,
272,
283,
4001,
409,
3186,
297,
272,
283,
4001,
409,
4547,
297,
272,
283,
4001,
409,
2681,
297,
272,
283,
4001,
409,
2698,
16009,
297,
272,
283,
4547,
13411,
297,
199,
61,
199,
199,
318,
1218,
63,
2301,
8,
2301,
12,
1817,
29,
403,
12,
627,
80,
12,
1011,
829,
304,
272,
408,
2499,
282,
2763,
12,
1627,
314,
1817,
14,
2286,
3261,
370,
520,
5247,
1705,
4001,
409,
4547,
14,
981,
2313,
272,
408,
272,
340,
1817,
365,
440,
488,
26,
267,
372,
1817,
14,
981,
63,
2301,
8,
2301,
12,
627,
80,
12,
1011,
829,
9,
272,
372,
2763,
14,
981,
2031,
80,
12,
1011,
829,
9,
421,
199,
318,
5978,
63,
2301,
8,
2301,
12,
1817,
29,
403,
12,
627,
80,
12,
1011,
829,
304,
272,
408,
11070,
282,
2763,
12,
1627,
314,
1817,
14,
2286,
3261,
370,
520,
5247,
1705,
4001,
409,
4547,
14,
4824,
2313,
272,
408,
272,
340,
1817,
365,
440,
488,
26,
267,
372,
1817,
14,
4824,
63,
2301,
8,
2301,
12,
627,
80,
12,
1011,
829,
9,
272,
372,
2763,
14,
4824,
2031,
80,
12,
1011,
829,
9,
421,
199,
318,
11441,
63,
1224,
8,
1224,
12,
536,
12,
6869,
29,
403,
12,
1011,
829,
304,
272,
408,
16843,
282,
1817,
14,
339,
982,
6957,
1256,
365,
1627,
12,
6869,
365,
440,
1202,
14,
339,
3261,
370,
520,
5247,
1705,
4001,
409,
3186,
14,
8165,
2313,
339,
520,
635,
1817,
26,
6957,
370,
506,
17864,
14,
272,
520,
635,
536,
26,
7053,
536,
367,
6957,
14,
272,
520,
635,
6869,
26,
12580,
1256,
14,
272,
520,
466,
1817,
26,
1059,
503,
6957,
1256,
272,
520,
466,
536,
26,
1059,
272,
520,
466,
6869,
26,
1559,
272,
408,
272,
1817,
275,
485,
475,
63,
1224,
8,
1224,
12,
6869,
9,
272,
1817,
14,
8165,
8,
354,
12,
1011,
829,
9,
421,
199,
318,
11441,
63,
1080,
8,
1080,
12,
536,
12,
1817,
29,
403,
12,
6869,
29,
403,
12,
1011,
829,
304,
272,
408,
16843,
376,
1478,
14,
339,
982,
5499,
1256,
365,
1627,
12,
272,
1817,
436,
6869,
787,
440,
1202,
14,
339,
3261,
370,
520,
5247,
1705,
4001,
409,
2681,
14,
8165,
2313,
339,
520,
635,
1478,
26,
5499,
370,
506,
17864,
14,
272,
520,
635,
536,
26,
7053,
536,
367,
1478,
14,
272,
520,
635,
1817,
26,
6957,
370,
1314,
5499,
365,
295,
9224,
14,
272,
520,
635,
6869,
26,
12580,
1256,
14,
272,
520,
466,
1478,
26,
1059,
503,
5499,
1256,
272,
520,
466,
536,
26,
1059,
272,
520,
466,
1817,
26,
1059,
503,
6957,
1256,
272,
520,
466,
6869,
26,
1559,
272,
408,
272,
1478,
275,
485,
475,
63,
1080,
8,
1080,
12,
1817,
12,
6869,
9,
272,
1478,
14,
8165,
8,
354,
12,
1011,
829,
9,
421,
199,
318,
17355,
63,
2301,
2031,
80,
12,
1011,
75,
304,
272,
408,
14364,
282,
2763,
14,
339,
961,
365,
282,
5922,
805,
626,
8491,
282,
520,
533,
1705,
4547,
13411,
64,
436,
272,
7858,
652,
14,
339,
520,
2094,
2763,
26,
489,
710,
536,
402,
314,
2763,
370,
506,
29815,
503,
282,
489,
520,
533,
1705,
4001,
409,
4547,
64,
2763,
6144,
652,
14,
339,
520,
635,
1817,
26,
489,
437,
520,
533,
6054,
14536,
14,
3629,
14,
3186,
64,
503,
1817,
536,
370,
489,
367,
314,
1817,
2382,
314,
2763,
911,
506,
2896,
14,
339,
520,
635,
6869,
26,
489,
710,
520,
533,
6054,
14536,
14,
3908,
14,
1095,
14,
8524,
64,
370,
675,
367,
1817,
489,
25572,
436,
4177,
741,
23029,
14,
2286,
520,
5808,
26,
437,
520,
533,
1705,
4547,
13411,
64,
1256,
6144,
314,
1570,
14,
25979,
408,
2286,
340,
283,
1224,
7,
440,
315,
1022,
436,
1228,
8,
80,
59,
16,
467,
8335,
14,
4547,
304,
267,
1022,
459,
1224,
418,
275,
299,
59,
16,
1055,
1224,
272,
340,
283,
3908,
7,
440,
315,
1022,
26,
267,
1022,
459,
3908,
418,
275,
1022,
459,
1224,
2278,
3409,
339,
327,
17831,
272,
340,
822,
8,
80,
9,
2356,
499,
436,
1228,
8,
80,
59,
17,
467,
8335,
14,
4547,
304,
267,
3598,
14,
4050,
8,
288,
298,
4986,
316,
282,
4996,
909,
370,
17355,
63,
2301,
365,
5906,
2122,
288,
298,
13870,
986,
315,
4252,
2633,
3140,
4765,
288,
28195,
1866,
15561,
288,
776,
272,
6869,
275,
1022,
459,
3908,
418,
339,
327,
8321,
2295,
17021,
370,
2059,
1380,
3341,
365,
3544,
29815,
272,
327,
626,
642,
2467,
337,
335,
965,
370,
506,
3602,
315,
5133,
2985,
883,
506,
3355,
272,
327,
734,
272,
1022,
459,
11858,
63,
2343,
13784,
549,
2286,
5762,
275,
4996,
13411,
2031,
80,
12,
1011,
75,
9,
339,
18040,
8296,
275,
664,
63,
3908,
63,
19863,
8,
3908,
12,
283,
3629,
335,
12974,
358,
272,
6869,
423,
1065,
63,
19863,
8,
19863,
8296,
12,
5762,
9,
339,
372,
5762,
421,
199,
318,
485,
475,
63,
1224,
8,
1224,
12,
6869,
29,
403,
304,
272,
408,
1767,
340,
1256,
402,
6957,
12,
587,
6982,
892,
543,
3341,
624,
272,
340,
1228,
8,
1224,
12,
8335,
14,
3186,
304,
267,
372,
1817,
339,
327,
9138,
26,
1817,
536,
12,
11703,
376,
6869,
272,
3404,
275,
8335,
14,
25285,
342,
272,
340,
6869,
365,
440,
488,
26,
267,
3404,
14,
3409,
275,
6869,
272,
372,
8335,
14,
3186,
8,
1224,
12,
3404,
9,
421,
199,
318,
485,
475,
63,
1080,
8,
1080,
12,
1817,
29,
403,
12,
6869,
29,
403,
304,
272,
408,
1767,
340,
1256
] |
[
2043,
13268,
859,
13070,
2863,
4177,
5331,
14,
199,
624,
199,
646,
3598,
199,
199,
504,
32241,
492,
7448,
4256,
199,
199,
646,
8335,
199,
199,
504,
8335,
14,
3629,
492,
12718,
8463,
199,
504,
8335,
14,
3629,
492,
18276,
8463,
199,
199,
504,
12810,
14,
3924,
492,
627,
199,
504,
12810,
14,
26027,
492,
5385,
33,
63,
1780,
199,
504,
12810,
14,
26027,
14,
17439,
14,
19863,
492,
334,
362,
63,
3908,
63,
19863,
12,
1740,
1255,
63,
4780,
63,
19863,
9,
421,
199,
363,
452,
363,
275,
359,
272,
283,
981,
63,
2301,
297,
272,
283,
4824,
63,
2301,
297,
272,
283,
11858,
63,
2301,
297,
272,
283,
8165,
63,
1224,
297,
272,
283,
8165,
63,
1080,
297,
272,
283,
4001,
409,
3186,
297,
272,
283,
4001,
409,
4547,
297,
272,
283,
4001,
409,
2681,
297,
272,
283,
4001,
409,
2698,
16009,
297,
272,
283,
4547,
13411,
297,
199,
61,
199,
199,
318,
1218,
63,
2301,
8,
2301,
12,
1817,
29,
403,
12,
627,
80,
12,
1011,
829,
304,
272,
408,
2499,
282,
2763,
12,
1627,
314,
1817,
14,
2286,
3261,
370,
520,
5247,
1705,
4001,
409,
4547,
14,
981,
2313,
272,
408,
272,
340,
1817,
365,
440,
488,
26,
267,
372,
1817,
14,
981,
63,
2301,
8,
2301,
12,
627,
80,
12,
1011,
829,
9,
272,
372,
2763,
14,
981,
2031,
80,
12,
1011,
829,
9,
421,
199,
318,
5978,
63,
2301,
8,
2301,
12,
1817,
29,
403,
12,
627,
80,
12,
1011,
829,
304,
272,
408,
11070,
282,
2763,
12,
1627,
314,
1817,
14,
2286,
3261,
370,
520,
5247,
1705,
4001,
409,
4547,
14,
4824,
2313,
272,
408,
272,
340,
1817,
365,
440,
488,
26,
267,
372,
1817,
14,
4824,
63,
2301,
8,
2301,
12,
627,
80,
12,
1011,
829,
9,
272,
372,
2763,
14,
4824,
2031,
80,
12,
1011,
829,
9,
421,
199,
318,
11441,
63,
1224,
8,
1224,
12,
536,
12,
6869,
29,
403,
12,
1011,
829,
304,
272,
408,
16843,
282,
1817,
14,
339,
982,
6957,
1256,
365,
1627,
12,
6869,
365,
440,
1202,
14,
339,
3261,
370,
520,
5247,
1705,
4001,
409,
3186,
14,
8165,
2313,
339,
520,
635,
1817,
26,
6957,
370,
506,
17864,
14,
272,
520,
635,
536,
26,
7053,
536,
367,
6957,
14,
272,
520,
635,
6869,
26,
12580,
1256,
14,
272,
520,
466,
1817,
26,
1059,
503,
6957,
1256,
272,
520,
466,
536,
26,
1059,
272,
520,
466,
6869,
26,
1559,
272,
408,
272,
1817,
275,
485,
475,
63,
1224,
8,
1224,
12,
6869,
9,
272,
1817,
14,
8165,
8,
354,
12,
1011,
829,
9,
421,
199,
318,
11441,
63,
1080,
8,
1080,
12,
536,
12,
1817,
29,
403,
12,
6869,
29,
403,
12,
1011,
829,
304,
272,
408,
16843,
376,
1478,
14,
339,
982,
5499,
1256,
365,
1627,
12,
272,
1817,
436,
6869,
787,
440,
1202,
14,
339,
3261,
370,
520,
5247,
1705,
4001,
409,
2681,
14,
8165,
2313,
339,
520,
635,
1478,
26,
5499,
370,
506,
17864,
14,
272,
520,
635,
536,
26,
7053,
536,
367,
1478,
14,
272,
520,
635,
1817,
26,
6957,
370,
1314,
5499,
365,
295,
9224,
14,
272,
520,
635,
6869,
26,
12580,
1256,
14,
272,
520,
466,
1478,
26,
1059,
503,
5499,
1256,
272,
520,
466,
536,
26,
1059,
272,
520,
466,
1817,
26,
1059,
503,
6957,
1256,
272,
520,
466,
6869,
26,
1559,
272,
408,
272,
1478,
275,
485,
475,
63,
1080,
8,
1080,
12,
1817,
12,
6869,
9,
272,
1478,
14,
8165,
8,
354,
12,
1011,
829,
9,
421,
199,
318,
17355,
63,
2301,
2031,
80,
12,
1011,
75,
304,
272,
408,
14364,
282,
2763,
14,
339,
961,
365,
282,
5922,
805,
626,
8491,
282,
520,
533,
1705,
4547,
13411,
64,
436,
272,
7858,
652,
14,
339,
520,
2094,
2763,
26,
489,
710,
536,
402,
314,
2763,
370,
506,
29815,
503,
282,
489,
520,
533,
1705,
4001,
409,
4547,
64,
2763,
6144,
652,
14,
339,
520,
635,
1817,
26,
489,
437,
520,
533,
6054,
14536,
14,
3629,
14,
3186,
64,
503,
1817,
536,
370,
489,
367,
314,
1817,
2382,
314,
2763,
911,
506,
2896,
14,
339,
520,
635,
6869,
26,
489,
710,
520,
533,
6054,
14536,
14,
3908,
14,
1095,
14,
8524,
64,
370,
675,
367,
1817,
489,
25572,
436,
4177,
741,
23029,
14,
2286,
520,
5808,
26,
437,
520,
533,
1705,
4547,
13411,
64,
1256,
6144,
314,
1570,
14,
25979,
408,
2286,
340,
283,
1224,
7,
440,
315,
1022,
436,
1228,
8,
80,
59,
16,
467,
8335,
14,
4547,
304,
267,
1022,
459,
1224,
418,
275,
299,
59,
16,
1055,
1224,
272,
340,
283,
3908,
7,
440,
315,
1022,
26,
267,
1022,
459,
3908,
418,
275,
1022,
459,
1224,
2278,
3409,
339,
327,
17831,
272,
340,
822,
8,
80,
9,
2356,
499,
436,
1228,
8,
80,
59,
17,
467,
8335,
14,
4547,
304,
267,
3598,
14,
4050,
8,
288,
298,
4986,
316,
282,
4996,
909,
370,
17355,
63,
2301,
365,
5906,
2122,
288,
298,
13870,
986,
315,
4252,
2633,
3140,
4765,
288,
28195,
1866,
15561,
288,
776,
272,
6869,
275,
1022,
459,
3908,
418,
339,
327,
8321,
2295,
17021,
370,
2059,
1380,
3341,
365,
3544,
29815,
272,
327,
626,
642,
2467,
337,
335,
965,
370,
506,
3602,
315,
5133,
2985,
883,
506,
3355,
272,
327,
734,
272,
1022,
459,
11858,
63,
2343,
13784,
549,
2286,
5762,
275,
4996,
13411,
2031,
80,
12,
1011,
75,
9,
339,
18040,
8296,
275,
664,
63,
3908,
63,
19863,
8,
3908,
12,
283,
3629,
335,
12974,
358,
272,
6869,
423,
1065,
63,
19863,
8,
19863,
8296,
12,
5762,
9,
339,
372,
5762,
421,
199,
318,
485,
475,
63,
1224,
8,
1224,
12,
6869,
29,
403,
304,
272,
408,
1767,
340,
1256,
402,
6957,
12,
587,
6982,
892,
543,
3341,
624,
272,
340,
1228,
8,
1224,
12,
8335,
14,
3186,
304,
267,
372,
1817,
339,
327,
9138,
26,
1817,
536,
12,
11703,
376,
6869,
272,
3404,
275,
8335,
14,
25285,
342,
272,
340,
6869,
365,
440,
488,
26,
267,
3404,
14,
3409,
275,
6869,
272,
372,
8335,
14,
3186,
8,
1224,
12,
3404,
9,
421,
199,
318,
485,
475,
63,
1080,
8,
1080,
12,
1817,
29,
403,
12,
6869,
29,
403,
304,
272,
408,
1767,
340,
1256,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
levic/django-extensions
|
django_extensions/management/commands/mail_debug.py
|
27
|
2924
|
import asyncore
import sys
from logging import getLogger
from optparse import make_option
from smtpd import SMTPServer
from django.core.management.base import BaseCommand, CommandError
from django_extensions.management.utils import setup_logger, signalcommand
logger = getLogger(__name__)
class ExtensionDebuggingServer(SMTPServer):
"""Duplication of smtpd.DebuggingServer, but using logging instead of print."""
# Do something with the gathered message
def process_message(self, peer, mailfrom, rcpttos, data):
"""Output will be sent to the module logger at INFO level."""
inheaders = 1
lines = data.split('\n')
logger.info('---------- MESSAGE FOLLOWS ----------')
for line in lines:
# headers first
if inheaders and not line:
logger.info('X-Peer: %s' % peer[0])
inheaders = 0
logger.info(line)
logger.info('------------ END MESSAGE ------------')
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option('--output', dest='output_file', default=None,
help='Specifies an output file to send a copy of all messages (not flushed immediately).'),
make_option('--use-settings', dest='use_settings',
action='store_true', default=False,
help='Uses EMAIL_HOST and HOST_PORT from Django settings.'),
)
help = "Starts a test mail server for development."
args = '[optional port number or ippaddr:port]'
requires_system_checks = False
@signalcommand
def handle(self, addrport='', *args, **options):
if args:
raise CommandError('Usage is mail_debug %s' % self.args)
if not addrport:
if options.get('use_settings', False):
from django.conf import settings
addr = getattr(settings, 'EMAIL_HOST', '')
port = str(getattr(settings, 'EMAIL_PORT', '1025'))
else:
addr = ''
port = '1025'
else:
try:
addr, port = addrport.split(':')
except ValueError:
addr, port = '', addrport
if not addr:
addr = '127.0.0.1'
if not port.isdigit():
raise CommandError("%r is not a valid port number." % port)
else:
port = int(port)
# Add console handler
setup_logger(logger, stream=self.stdout, filename=options.get('output_file', None))
def inner_run():
quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'
print("Now accepting mail at %s:%s -- use %s to quit" % (addr, port, quit_command))
ExtensionDebuggingServer((addr, port), None)
asyncore.loop()
try:
inner_run()
except KeyboardInterrupt:
pass
|
mit
|
[
646,
30328,
199,
646,
984,
199,
504,
2050,
492,
28138,
199,
504,
8691,
492,
1852,
63,
1422,
199,
504,
14400,
68,
492,
19810,
3120,
199,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
199,
504,
1639,
63,
5359,
14,
8110,
14,
1208,
492,
3272,
63,
2921,
12,
4673,
1531,
199,
199,
2921,
275,
28138,
3460,
354,
3368,
421,
199,
533,
13282,
7084,
1540,
3120,
8,
20927,
3120,
304,
272,
408,
36,
384,
1863,
402,
14400,
68,
14,
7084,
1540,
3120,
12,
1325,
1808,
2050,
3140,
402,
870,
1041,
272,
327,
4226,
6020,
543,
314,
16072,
31051,
1245,
272,
347,
2112,
63,
1188,
8,
277,
12,
9104,
12,
610,
17588,
417,
12,
4819,
541,
14543,
12,
666,
304,
267,
408,
2959,
911,
506,
4847,
370,
314,
859,
2512,
737,
24008,
2166,
1041,
267,
315,
2139,
275,
413,
267,
2385,
275,
666,
14,
1294,
2258,
78,
358,
267,
2512,
14,
815,
360,
9460,
603,
1608,
2962,
481,
2228,
1484,
5035,
4143,
358,
267,
367,
1004,
315,
2385,
26,
288,
327,
2323,
1642,
288,
340,
315,
2139,
436,
440,
1004,
26,
355,
2512,
14,
815,
360,
56,
13,
12566,
26,
450,
83,
7,
450,
9104,
59,
16,
566,
355,
315,
2139,
275,
378,
288,
2512,
14,
815,
8,
604,
9,
267,
2512,
14,
815,
360,
4559,
7729,
603,
1608,
2962,
3001,
375,
358,
421,
199,
533,
5817,
8,
25150,
304,
272,
945,
63,
513,
275,
22239,
14,
1422,
63,
513,
435,
334,
267,
1852,
63,
1422,
4517,
1199,
297,
2053,
534,
1199,
63,
493,
297,
849,
29,
403,
12,
490,
1720,
534,
6154,
5604,
376,
1072,
570,
370,
3222,
282,
1331,
402,
1006,
3788,
334,
1397,
8976,
379,
9939,
680,
659,
267,
1852,
63,
1422,
4517,
1180,
13,
1751,
297,
2053,
534,
1180,
63,
1751,
297,
490,
1595,
534,
1617,
63,
2052,
297,
849,
29,
797,
12,
490,
1720,
534,
21896,
32320,
63,
5449,
436,
25741,
63,
3657,
687,
5634,
2202,
8038,
272,
776,
272,
1720,
275,
298,
32142,
282,
511,
6016,
1654,
367,
16367,
2122,
272,
1249,
275,
6730,
4144,
1844,
1329,
503,
284,
802,
2697,
26,
719,
6616,
339,
5074,
63,
2253,
63,
8625,
275,
756,
339,
768,
4653,
1531,
272,
347,
2429,
8,
277,
12,
5552,
719,
4581,
627,
589,
12,
1011,
1419,
304,
267,
340,
1249,
26,
288,
746,
14393,
360,
7692,
365,
6016,
63,
1757,
450,
83,
7,
450,
291,
14,
589,
9,
267,
340,
440,
5552,
719,
26,
288,
340,
1511,
14,
362,
360,
1180,
63,
1751,
297,
756,
304,
355,
687,
1639,
14,
2190,
492,
2202,
355,
5552,
275,
2519,
8,
1751,
12,
283,
10089,
63,
5449,
297,
4074,
355,
1844,
275,
620,
8,
5675,
8,
1751,
12,
283,
10089,
63,
3657,
297,
283,
32105,
1333,
288,
587,
26,
355,
5552,
275,
2125,
355,
1844,
275,
283,
32105,
7,
267,
587,
26,
288,
862,
26,
355,
5552,
12,
1844,
275,
5552,
719,
14,
1294,
11633,
288,
871,
1722,
26,
355,
5552,
12,
1844,
275,
3260,
5552,
719,
267,
340,
440,
5552,
26,
288,
5552,
275,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
398,
340,
440,
1844,
14,
13896,
837,
288,
746,
14393,
3647,
82,
365,
440,
282,
1686,
1844,
1329,
2122,
450,
1844,
9,
267,
587,
26,
288,
1844,
275,
1109,
8,
719,
9,
398,
327,
2654,
8559,
3016,
267,
3272,
63,
2921,
8,
2921,
12,
2547,
29,
277,
14,
2703,
12,
1788,
29,
1419,
14,
362,
360,
1199,
63,
493,
297,
488,
430,
398,
347,
6506,
63,
1065,
837,
288,
17242,
63,
1531,
275,
334,
1274,
14,
3246,
508,
283,
2676,
708,
358,
436,
283,
22584,
13,
14731,
7,
503,
283,
13060,
13,
35,
7,
288,
870,
480,
14351,
32163,
6016,
737,
450,
83,
2689,
83,
1553,
675,
450,
83,
370,
17242,
2,
450,
334,
2697,
12,
1844,
12,
17242,
63,
1531,
430,
953,
13282,
7084,
1540,
3120,
1332,
2697,
12,
1844,
395,
488,
9,
288,
30328,
14,
3813,
342,
398,
862,
26,
288,
6506,
63,
1065,
342,
267,
871,
13483,
26,
288,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
30328,
199,
646,
984,
199,
504,
2050,
492,
28138,
199,
504,
8691,
492,
1852,
63,
1422,
199,
504,
14400,
68,
492,
19810,
3120,
199,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
199,
504,
1639,
63,
5359,
14,
8110,
14,
1208,
492,
3272,
63,
2921,
12,
4673,
1531,
199,
199,
2921,
275,
28138,
3460,
354,
3368,
421,
199,
533,
13282,
7084,
1540,
3120,
8,
20927,
3120,
304,
272,
408,
36,
384,
1863,
402,
14400,
68,
14,
7084,
1540,
3120,
12,
1325,
1808,
2050,
3140,
402,
870,
1041,
272,
327,
4226,
6020,
543,
314,
16072,
31051,
1245,
272,
347,
2112,
63,
1188,
8,
277,
12,
9104,
12,
610,
17588,
417,
12,
4819,
541,
14543,
12,
666,
304,
267,
408,
2959,
911,
506,
4847,
370,
314,
859,
2512,
737,
24008,
2166,
1041,
267,
315,
2139,
275,
413,
267,
2385,
275,
666,
14,
1294,
2258,
78,
358,
267,
2512,
14,
815,
360,
9460,
603,
1608,
2962,
481,
2228,
1484,
5035,
4143,
358,
267,
367,
1004,
315,
2385,
26,
288,
327,
2323,
1642,
288,
340,
315,
2139,
436,
440,
1004,
26,
355,
2512,
14,
815,
360,
56,
13,
12566,
26,
450,
83,
7,
450,
9104,
59,
16,
566,
355,
315,
2139,
275,
378,
288,
2512,
14,
815,
8,
604,
9,
267,
2512,
14,
815,
360,
4559,
7729,
603,
1608,
2962,
3001,
375,
358,
421,
199,
533,
5817,
8,
25150,
304,
272,
945,
63,
513,
275,
22239,
14,
1422,
63,
513,
435,
334,
267,
1852,
63,
1422,
4517,
1199,
297,
2053,
534,
1199,
63,
493,
297,
849,
29,
403,
12,
490,
1720,
534,
6154,
5604,
376,
1072,
570,
370,
3222,
282,
1331,
402,
1006,
3788,
334,
1397,
8976,
379,
9939,
680,
659,
267,
1852,
63,
1422,
4517,
1180,
13,
1751,
297,
2053,
534,
1180,
63,
1751,
297,
490,
1595,
534,
1617,
63,
2052,
297,
849,
29,
797,
12,
490,
1720,
534,
21896,
32320,
63,
5449,
436,
25741,
63,
3657,
687,
5634,
2202,
8038,
272,
776,
272,
1720,
275,
298,
32142,
282,
511,
6016,
1654,
367,
16367,
2122,
272,
1249,
275,
6730,
4144,
1844,
1329,
503,
284,
802,
2697,
26,
719,
6616,
339,
5074,
63,
2253,
63,
8625,
275,
756,
339,
768,
4653,
1531,
272,
347,
2429,
8,
277,
12,
5552,
719,
4581,
627,
589,
12,
1011,
1419,
304,
267,
340,
1249,
26,
288,
746,
14393,
360,
7692,
365,
6016,
63,
1757,
450,
83,
7,
450,
291,
14,
589,
9,
267,
340,
440,
5552,
719,
26,
288,
340,
1511,
14,
362,
360,
1180,
63,
1751,
297,
756,
304,
355,
687,
1639,
14,
2190,
492,
2202,
355,
5552,
275,
2519,
8,
1751,
12,
283,
10089,
63,
5449,
297,
4074,
355,
1844,
275,
620,
8,
5675,
8,
1751,
12,
283,
10089,
63,
3657,
297,
283,
32105,
1333,
288,
587,
26,
355,
5552,
275,
2125,
355,
1844,
275,
283,
32105,
7,
267,
587,
26,
288,
862,
26,
355,
5552,
12,
1844,
275,
5552,
719,
14,
1294,
11633,
288,
871,
1722,
26,
355,
5552,
12,
1844,
275,
3260,
5552,
719,
267,
340,
440,
5552,
26,
288,
5552,
275,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
398,
340,
440,
1844,
14,
13896,
837,
288,
746,
14393,
3647,
82,
365,
440,
282,
1686,
1844,
1329,
2122,
450,
1844,
9,
267,
587,
26,
288,
1844,
275,
1109,
8,
719,
9,
398,
327,
2654,
8559,
3016,
267,
3272,
63,
2921,
8,
2921,
12,
2547,
29,
277,
14,
2703,
12,
1788,
29,
1419,
14,
362,
360,
1199,
63,
493,
297,
488,
430,
398,
347,
6506,
63,
1065,
837,
288,
17242,
63,
1531,
275,
334,
1274,
14,
3246,
508,
283,
2676,
708,
358,
436,
283,
22584,
13,
14731,
7,
503,
283,
13060,
13,
35,
7,
288,
870,
480,
14351,
32163,
6016,
737,
450,
83,
2689,
83,
1553,
675,
450,
83,
370,
17242,
2,
450,
334,
2697,
12,
1844,
12,
17242,
63,
1531,
430,
953,
13282,
7084,
1540,
3120,
1332,
2697,
12,
1844,
395,
488,
9,
288,
30328,
14,
3813,
342,
398,
862,
26,
288,
6506,
63,
1065,
342,
267,
871,
13483,
26,
288,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
orcasgit/django-flatcontent
|
flatcontent/models.py
|
1
|
2578
|
from django.contrib.sites.models import Site
from django.core.cache import cache
from django.db import models
from django.utils import translation
from templatefield.fields import TemplateTextField
from templatefield.managers import RenderTemplateManager
class FlatContent(models.Model):
slug = models.SlugField(max_length=255, unique=False,
help_text='The name by which the template author '
'retrieves this content.')
site = models.ForeignKey(Site, blank=True, null=True)
content = TemplateTextField()
default = models.Manager()
objects = RenderTemplateManager()
class Meta:
unique_together = ('slug', 'site',)
verbose_name_plural = 'flat content'
def __unicode__(self):
return self.slug
def save(self, *args, **kwargs):
super(FlatContent, self).save(*args, **kwargs)
cache.delete(self.key_from_slug(
self.slug, site_id=self.site.id if self.site else None))
def delete(self):
cache.delete(self.key_from_slug(
self.slug, site_id=self.site.id if self.site else None))
super(FlatContent, self).delete()
# Helper method to get key for caching
def key_from_slug(slug, site_id=None):
lang = translation.get_language()
return 'flatcontent_%s_%s_%s' % (site_id, slug, lang)
key_from_slug = staticmethod(key_from_slug)
# Class method with caching
@classmethod
def get(cls, slug, site_id=None, context=None):
"""
Checks if key is in cache, otherwise performs database lookup and
inserts into cache.
"""
key, cache_value = cls._get_cached(slug, site_id, context)
if cache_value:
return cache_value
manager = cls.objects.with_context(context or {})
try:
fc = manager.get(slug=slug, site=site_id)
except cls.DoesNotExist:
try:
# Fallback to the non-site specific flatcontent
key, cache_value = cls._get_cached(slug, context=context)
if cache_value:
return cache_value
fc = manager.get(slug=slug, site=None)
except:
return ''
if not context:
cache.set(key, fc.content)
return fc.content
@classmethod
def _get_cached(cls, slug, site_id=None, context=None):
key = cls.key_from_slug(slug, site_id=site_id)
cache_value = None if context else cache.get(key)
return key, cache_value
|
bsd-3-clause
|
[
504,
1639,
14,
2828,
14,
8619,
14,
992,
492,
11666,
199,
504,
1639,
14,
1018,
14,
1637,
492,
2581,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
492,
7761,
199,
504,
1978,
698,
14,
955,
492,
5458,
6254,
199,
504,
1978,
698,
14,
16259,
492,
17769,
4231,
2988,
421,
199,
533,
19005,
2714,
8,
992,
14,
1685,
304,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
2299,
12,
3747,
29,
797,
12,
1169,
1720,
63,
505,
534,
1918,
536,
701,
1314,
314,
1978,
4132,
283,
4228,
283,
11235,
69,
2310,
642,
1564,
2659,
272,
4770,
275,
1709,
14,
3190,
8,
8972,
12,
4596,
29,
549,
12,
2973,
29,
549,
9,
272,
1564,
275,
5458,
6254,
342,
339,
849,
275,
1709,
14,
2988,
342,
272,
2251,
275,
17769,
4231,
2988,
342,
339,
1021,
6288,
26,
267,
3747,
63,
6314,
275,
661,
5464,
297,
283,
2124,
9538,
267,
3376,
63,
354,
63,
10019,
275,
283,
7088,
1564,
7,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
291,
14,
5464,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
17271,
2714,
12,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
267,
2581,
14,
1807,
8,
277,
14,
498,
63,
504,
63,
5464,
8,
288,
291,
14,
5464,
12,
4770,
63,
344,
29,
277,
14,
2124,
14,
344,
340,
291,
14,
2124,
587,
488,
430,
339,
347,
3145,
8,
277,
304,
267,
2581,
14,
1807,
8,
277,
14,
498,
63,
504,
63,
5464,
8,
288,
291,
14,
5464,
12,
4770,
63,
344,
29,
277,
14,
2124,
14,
344,
340,
291,
14,
2124,
587,
488,
430,
267,
1613,
8,
17271,
2714,
12,
291,
680,
1807,
342,
339,
327,
11642,
1083,
370,
664,
790,
367,
13627,
272,
347,
790,
63,
504,
63,
5464,
8,
5464,
12,
4770,
63,
344,
29,
403,
304,
267,
6339,
275,
7761,
14,
362,
63,
3671,
342,
267,
372,
283,
7088,
1317,
4970,
83,
4970,
83,
4970,
83,
7,
450,
334,
2124,
63,
344,
12,
8889,
12,
6339,
9,
272,
790,
63,
504,
63,
5464,
275,
12822,
8,
498,
63,
504,
63,
5464,
9,
339,
327,
8089,
1083,
543,
13627,
272,
768,
3744,
272,
347,
664,
8,
1886,
12,
8889,
12,
4770,
63,
344,
29,
403,
12,
1067,
29,
403,
304,
267,
408,
267,
13813,
340,
790,
365,
315,
2581,
12,
4257,
18628,
3050,
4237,
436,
267,
28203,
1901,
2581,
14,
267,
408,
267,
790,
12,
2581,
63,
585,
275,
843,
423,
362,
63,
5245,
8,
5464,
12,
4770,
63,
344,
12,
1067,
9,
267,
340,
2581,
63,
585,
26,
288,
372,
2581,
63,
585,
398,
5256,
275,
843,
14,
1462,
14,
1045,
63,
1100,
8,
1100,
503,
5009,
267,
862,
26,
288,
10821,
275,
5256,
14,
362,
8,
5464,
29,
5464,
12,
4770,
29,
2124,
63,
344,
9,
267,
871,
843,
14,
7400,
26,
288,
862,
26,
355,
327,
481,
5421,
370,
314,
2222,
13,
2124,
2488,
6829,
1317,
355,
790,
12,
2581,
63,
585,
275,
843,
423,
362,
63,
5245,
8,
5464,
12,
1067,
29,
1100,
9,
355,
340,
2581,
63,
585,
26,
490,
372,
2581,
63,
585,
355,
10821,
275,
5256,
14,
362,
8,
5464,
29,
5464,
12,
4770,
29,
403,
9,
288,
871,
26,
355,
372,
2125,
267,
340,
440,
1067,
26,
288,
2581,
14,
409,
8,
498,
12,
10821,
14,
1317,
9,
267,
372,
10821,
14,
1317,
339,
768,
3744,
272,
347,
485,
362,
63,
5245,
8,
1886,
12,
8889,
12,
4770,
63,
344,
29,
403,
12,
1067,
29,
403,
304,
267,
790,
275,
843,
14,
498,
63,
504,
63,
5464,
8,
5464,
12,
4770,
63,
344,
29,
2124,
63,
344,
9,
267,
2581,
63,
585,
275,
488,
340,
1067,
587,
2581,
14,
362,
8,
498,
9,
267,
372,
790,
12,
2581,
63,
585,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
2828,
14,
8619,
14,
992,
492,
11666,
199,
504,
1639,
14,
1018,
14,
1637,
492,
2581,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
492,
7761,
199,
504,
1978,
698,
14,
955,
492,
5458,
6254,
199,
504,
1978,
698,
14,
16259,
492,
17769,
4231,
2988,
421,
199,
533,
19005,
2714,
8,
992,
14,
1685,
304,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
2299,
12,
3747,
29,
797,
12,
1169,
1720,
63,
505,
534,
1918,
536,
701,
1314,
314,
1978,
4132,
283,
4228,
283,
11235,
69,
2310,
642,
1564,
2659,
272,
4770,
275,
1709,
14,
3190,
8,
8972,
12,
4596,
29,
549,
12,
2973,
29,
549,
9,
272,
1564,
275,
5458,
6254,
342,
339,
849,
275,
1709,
14,
2988,
342,
272,
2251,
275,
17769,
4231,
2988,
342,
339,
1021,
6288,
26,
267,
3747,
63,
6314,
275,
661,
5464,
297,
283,
2124,
9538,
267,
3376,
63,
354,
63,
10019,
275,
283,
7088,
1564,
7,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
291,
14,
5464,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
17271,
2714,
12,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
267,
2581,
14,
1807,
8,
277,
14,
498,
63,
504,
63,
5464,
8,
288,
291,
14,
5464,
12,
4770,
63,
344,
29,
277,
14,
2124,
14,
344,
340,
291,
14,
2124,
587,
488,
430,
339,
347,
3145,
8,
277,
304,
267,
2581,
14,
1807,
8,
277,
14,
498,
63,
504,
63,
5464,
8,
288,
291,
14,
5464,
12,
4770,
63,
344,
29,
277,
14,
2124,
14,
344,
340,
291,
14,
2124,
587,
488,
430,
267,
1613,
8,
17271,
2714,
12,
291,
680,
1807,
342,
339,
327,
11642,
1083,
370,
664,
790,
367,
13627,
272,
347,
790,
63,
504,
63,
5464,
8,
5464,
12,
4770,
63,
344,
29,
403,
304,
267,
6339,
275,
7761,
14,
362,
63,
3671,
342,
267,
372,
283,
7088,
1317,
4970,
83,
4970,
83,
4970,
83,
7,
450,
334,
2124,
63,
344,
12,
8889,
12,
6339,
9,
272,
790,
63,
504,
63,
5464,
275,
12822,
8,
498,
63,
504,
63,
5464,
9,
339,
327,
8089,
1083,
543,
13627,
272,
768,
3744,
272,
347,
664,
8,
1886,
12,
8889,
12,
4770,
63,
344,
29,
403,
12,
1067,
29,
403,
304,
267,
408,
267,
13813,
340,
790,
365,
315,
2581,
12,
4257,
18628,
3050,
4237,
436,
267,
28203,
1901,
2581,
14,
267,
408,
267,
790,
12,
2581,
63,
585,
275,
843,
423,
362,
63,
5245,
8,
5464,
12,
4770,
63,
344,
12,
1067,
9,
267,
340,
2581,
63,
585,
26,
288,
372,
2581,
63,
585,
398,
5256,
275,
843,
14,
1462,
14,
1045,
63,
1100,
8,
1100,
503,
5009,
267,
862,
26,
288,
10821,
275,
5256,
14,
362,
8,
5464,
29,
5464,
12,
4770,
29,
2124,
63,
344,
9,
267,
871,
843,
14,
7400,
26,
288,
862,
26,
355,
327,
481,
5421,
370,
314,
2222,
13,
2124,
2488,
6829,
1317,
355,
790,
12,
2581,
63,
585,
275,
843,
423,
362,
63,
5245,
8,
5464,
12,
1067,
29,
1100,
9,
355,
340,
2581,
63,
585,
26,
490,
372,
2581,
63,
585,
355,
10821,
275,
5256,
14,
362,
8,
5464,
29,
5464,
12,
4770,
29,
403,
9,
288,
871,
26,
355,
372,
2125,
267,
340,
440,
1067,
26,
288,
2581,
14,
409,
8,
498,
12,
10821,
14,
1317,
9,
267,
372,
10821,
14,
1317,
339,
768,
3744,
272,
347,
485,
362,
63,
5245,
8,
1886,
12,
8889,
12,
4770,
63,
344,
29,
403,
12,
1067,
29,
403,
304,
267,
790,
275,
843,
14,
498,
63,
504,
63,
5464,
8,
5464,
12,
4770,
63,
344,
29,
2124,
63,
344,
9,
267,
2581,
63,
585,
275,
488,
340,
1067,
587,
2581,
14,
362,
8,
498,
9,
267,
372,
790,
12,
2581,
63,
585,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
BraydenYates/school
|
jenningsextracredit.py
|
1
|
2032
|
import os, sys
def congrats():
print(" ,jf")
print(" _am, ,_am, ,_g_oam, _am, _g_ag, _am, koewkovg _mm_")
print(" ,gF @._-gF @-' jf @ ,gF @ ^ NX #_,gF @ jf qK '")
print(" 8Y 8Y d j# jF .8Y ,d dY 8Y d jf *b,")
print("jK , jK ,N jN jF :K ,Z ,jF jK ,Z' ,jfk, dN.")
print(" NbpP NbpP dP dFk_o8NbpP'V^dF NbpY'V^'dF 'dYo-'*h,W'")
print(" ,gF',@'")
print(" :8K j8")
print(" '*w*'")
print("Algebra Extra Credit \n ")
print("When answering, please format it as: \n x=number \n No spaces, please. \n")
ans = raw_input("Solve. \n 5x+2x=21 \n")
if ans == "x=3":
print ("Correct. Continuing. \n")
ans = raw_input("Simplify. \n 15x+7y+2x \n")
if ans == "17x+7y":
print( "Correct. Continuing. \n")
ans = raw_input("Simplify. \n 4k-3l-2k \n")
if ans == "2k-31":
print("Correct. Continuing. \n")
ans = raw_input("Solve the following. \n 38=2a+54 \n")
if ans == "a=-8":
print("Correct.")
ans = raw_input("You payed $600 for a new guitar. Your guitar \n costs $40 more than twice the cost of your friend's \n guitar. How much did your friend's guitar cost? \n")
if ans == "$280":
print("Correct. Continuing.")
ans = raw_input("Solve. \n t+18.1=23.9 \n")
if ans == "t=5.8":
print("Correct. Continuing. ")
congrats()
|
gpl-2.0
|
[
646,
747,
12,
984,
199,
199,
318,
406,
2587,
1956,
837,
267,
870,
480,
2476,
12788,
2360,
32008,
531,
267,
870,
480,
257,
485,
455,
12,
259,
2360,
63,
455,
12,
221,
2360,
63,
71,
63,
79,
455,
12,
259,
485,
455,
12,
257,
485,
71,
63,
643,
12,
257,
485,
455,
12,
257,
20817,
546,
7697,
10929,
257,
485,
596,
29443,
267,
870,
480,
2360,
71,
38,
221,
768,
423,
13,
71,
38,
257,
768,
15668,
221,
1335,
70,
257,
768,
221,
2360,
71,
38,
221,
768,
221,
7167,
653,
56,
221,
327,
3131,
71,
38,
221,
768,
258,
1335,
70,
420,
1894,
43,
221,
283,
531,
267,
870,
480,
1695,
57,
420,
1695,
57,
259,
366,
257,
1335,
3,
257,
1335,
38,
1275,
24,
57,
221,
2360,
68,
257,
366,
57,
258,
1695,
57,
257,
366,
259,
1335,
70,
755,
627,
66,
12,
531,
267,
870,
480,
74,
43,
257,
2360,
221,
1335,
43,
257,
2360,
46,
257,
1335,
46,
257,
1335,
38,
221,
520,
43,
221,
2360,
58,
221,
2360,
74,
38,
258,
1335,
43,
221,
2360,
58,
7,
221,
2360,
74,
9010,
12,
755,
366,
46,
2685,
267,
870,
480,
653,
10913,
48,
259,
653,
10913,
48,
259,
366,
48,
257,
366,
38,
75,
63,
79,
24,
46,
10913,
48,
7,
54,
62,
68,
38,
755,
653,
10913,
57,
7,
54,
62,
7,
68,
38,
283,
68,
32154,
15668,
10,
72,
12,
55,
9859,
267,
870,
480,
12793,
2360,
71,
38,
297,
32,
9859,
267,
870,
480,
12788,
520,
24,
43,
221,
1335,
24,
531,
267,
870,
480,
12793,
6438,
87,
10,
9859,
421,
199,
1361,
480,
2439,
19355,
11177,
30473,
971,
78,
6099,
199,
199,
1361,
480,
11423,
6385,
316,
12,
8749,
1475,
652,
465,
26,
971,
78,
671,
29,
1955,
971,
78,
3091,
7883,
12,
8749,
14,
971,
78,
531,
199,
796,
275,
3066,
63,
1210,
480,
51,
3344,
14,
971,
78,
959,
88,
11,
18,
88,
29,
2025,
971,
78,
531,
199,
692,
4987,
508,
298,
88,
29,
19,
582,
2728,
870,
1689,
19993,
14,
1448,
1346,
23221,
14,
971,
78,
531,
267,
4987,
275,
3066,
63,
1210,
480,
51,
3236,
8209,
14,
971,
78,
4114,
88,
11,
23,
89,
11,
18,
88,
971,
78,
531,
2728,
340,
4987,
508,
298,
1196,
88,
11,
23,
89,
582,
355,
870,
8,
298,
19993,
14,
1448,
1346,
23221,
14,
971,
78,
531,
14977,
4987,
275,
3066,
63,
1210,
480,
51,
3236,
8209,
14,
971,
78,
841,
75,
13,
19,
76,
13,
18,
75,
971,
78,
531,
355,
340,
4987,
508,
298,
18,
75,
13,
2192,
582,
717,
870,
480,
19993,
14,
1448,
1346,
23221,
14,
971,
78,
531,
717,
4987,
275,
3066,
63,
1210,
480,
51,
3344,
314,
2569,
14,
971,
78,
10448,
29,
18,
65,
11,
1477,
971,
78,
531,
717,
340,
4987,
508,
298,
65,
4022,
24,
582,
1816,
870,
480,
19993,
2685,
1816,
4987,
275,
3066,
63,
1210,
480,
5556,
8633,
379,
2672,
6683,
367,
282,
892,
486,
4993,
285,
14,
221,
19519,
486,
4993,
285,
971,
78,
26819,
2672,
2167,
1655,
221,
2419,
13373,
314,
7918,
221,
402,
2195,
32506,
1159,
971,
78,
486,
4993,
285,
14,
7494,
8298,
8103,
2195,
32506,
1159,
486,
4993,
285,
7918,
31,
971,
78,
531,
1816,
340,
4987,
508,
7880,
18520,
582,
3147,
870,
480,
19993,
14,
1448,
1346,
23221,
2685,
3147,
4987,
275,
3066,
63,
1210,
480,
51,
3344,
14,
971,
78,
307,
11,
1085,
14,
17,
29,
1789,
14,
25,
971,
78,
531,
3147,
340,
4987,
508,
298,
84,
29,
21,
14,
24,
582,
6059,
870,
480,
19993,
14,
1448,
1346,
23221,
14,
6099,
6059,
406,
2587,
1956,
342,
639,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
12,
984,
199,
199,
318,
406,
2587,
1956,
837,
267,
870,
480,
2476,
12788,
2360,
32008,
531,
267,
870,
480,
257,
485,
455,
12,
259,
2360,
63,
455,
12,
221,
2360,
63,
71,
63,
79,
455,
12,
259,
485,
455,
12,
257,
485,
71,
63,
643,
12,
257,
485,
455,
12,
257,
20817,
546,
7697,
10929,
257,
485,
596,
29443,
267,
870,
480,
2360,
71,
38,
221,
768,
423,
13,
71,
38,
257,
768,
15668,
221,
1335,
70,
257,
768,
221,
2360,
71,
38,
221,
768,
221,
7167,
653,
56,
221,
327,
3131,
71,
38,
221,
768,
258,
1335,
70,
420,
1894,
43,
221,
283,
531,
267,
870,
480,
1695,
57,
420,
1695,
57,
259,
366,
257,
1335,
3,
257,
1335,
38,
1275,
24,
57,
221,
2360,
68,
257,
366,
57,
258,
1695,
57,
257,
366,
259,
1335,
70,
755,
627,
66,
12,
531,
267,
870,
480,
74,
43,
257,
2360,
221,
1335,
43,
257,
2360,
46,
257,
1335,
46,
257,
1335,
38,
221,
520,
43,
221,
2360,
58,
221,
2360,
74,
38,
258,
1335,
43,
221,
2360,
58,
7,
221,
2360,
74,
9010,
12,
755,
366,
46,
2685,
267,
870,
480,
653,
10913,
48,
259,
653,
10913,
48,
259,
366,
48,
257,
366,
38,
75,
63,
79,
24,
46,
10913,
48,
7,
54,
62,
68,
38,
755,
653,
10913,
57,
7,
54,
62,
7,
68,
38,
283,
68,
32154,
15668,
10,
72,
12,
55,
9859,
267,
870,
480,
12793,
2360,
71,
38,
297,
32,
9859,
267,
870,
480,
12788,
520,
24,
43,
221,
1335,
24,
531,
267,
870,
480,
12793,
6438,
87,
10,
9859,
421,
199,
1361,
480,
2439,
19355,
11177,
30473,
971,
78,
6099,
199,
199,
1361,
480,
11423,
6385,
316,
12,
8749,
1475,
652,
465,
26,
971,
78,
671,
29,
1955,
971,
78,
3091,
7883,
12,
8749,
14,
971,
78,
531,
199,
796,
275,
3066,
63,
1210,
480,
51,
3344,
14,
971,
78,
959,
88,
11,
18,
88,
29,
2025,
971,
78,
531,
199,
692,
4987,
508,
298,
88,
29,
19,
582,
2728,
870,
1689,
19993,
14,
1448,
1346,
23221,
14,
971,
78,
531,
267,
4987,
275,
3066,
63,
1210,
480,
51,
3236,
8209,
14,
971,
78,
4114,
88,
11,
23,
89,
11,
18,
88,
971,
78,
531,
2728,
340,
4987,
508,
298,
1196,
88,
11,
23,
89,
582,
355,
870,
8,
298,
19993,
14,
1448,
1346,
23221,
14,
971,
78,
531,
14977,
4987,
275,
3066,
63,
1210,
480,
51,
3236,
8209,
14,
971,
78,
841,
75,
13,
19,
76,
13,
18,
75,
971,
78,
531,
355,
340,
4987,
508,
298,
18,
75,
13,
2192,
582,
717,
870,
480,
19993,
14,
1448,
1346,
23221,
14,
971,
78,
531,
717,
4987,
275,
3066,
63,
1210,
480,
51,
3344,
314,
2569,
14,
971,
78,
10448,
29,
18,
65,
11,
1477,
971,
78,
531,
717,
340,
4987,
508,
298,
65,
4022,
24,
582,
1816,
870,
480,
19993,
2685,
1816,
4987,
275,
3066,
63,
1210,
480,
5556,
8633,
379,
2672,
6683,
367,
282,
892,
486,
4993,
285,
14,
221,
19519,
486,
4993,
285,
971,
78,
26819,
2672,
2167,
1655,
221,
2419,
13373,
314,
7918,
221,
402,
2195,
32506,
1159,
971,
78,
486,
4993,
285,
14,
7494,
8298,
8103,
2195,
32506,
1159,
486,
4993,
285,
7918,
31,
971,
78,
531,
1816,
340,
4987,
508,
7880,
18520,
582,
3147,
870,
480,
19993,
14,
1448,
1346,
23221,
2685,
3147,
4987,
275,
3066,
63,
1210,
480,
51,
3344,
14,
971,
78,
307,
11,
1085,
14,
17,
29,
1789,
14,
25,
971,
78,
531,
3147,
340,
4987,
508,
298,
84,
29,
21,
14,
24,
582,
6059,
870,
480,
19993,
14,
1448,
1346,
23221,
14,
6099,
6059,
406,
2587,
1956,
342,
639,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
gdimitris/ChessPuzzler
|
Virtual_Environment/lib/python2.7/site-packages/sqlparse/formatter.py
|
118
|
5113
|
# Copyright (C) 2008 Andi Albrecht, albrecht.andi@gmail.com
#
# This module is part of python-sqlparse and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php.
"""SQL formatter"""
from sqlparse import filters
from sqlparse.exceptions import SQLParseError
def validate_options(options):
"""Validates options."""
kwcase = options.get('keyword_case', None)
if kwcase not in [None, 'upper', 'lower', 'capitalize']:
raise SQLParseError('Invalid value for keyword_case: %r' % kwcase)
idcase = options.get('identifier_case', None)
if idcase not in [None, 'upper', 'lower', 'capitalize']:
raise SQLParseError('Invalid value for identifier_case: %r' % idcase)
ofrmt = options.get('output_format', None)
if ofrmt not in [None, 'sql', 'python', 'php']:
raise SQLParseError('Unknown output format: %r' % ofrmt)
strip_comments = options.get('strip_comments', False)
if strip_comments not in [True, False]:
raise SQLParseError('Invalid value for strip_comments: %r'
% strip_comments)
strip_ws = options.get('strip_whitespace', False)
if strip_ws not in [True, False]:
raise SQLParseError('Invalid value for strip_whitespace: %r'
% strip_ws)
truncate_strings = options.get('truncate_strings', None)
if truncate_strings is not None:
try:
truncate_strings = int(truncate_strings)
except (ValueError, TypeError):
raise SQLParseError('Invalid value for truncate_strings: %r'
% truncate_strings)
if truncate_strings <= 1:
raise SQLParseError('Invalid value for truncate_strings: %r'
% truncate_strings)
options['truncate_strings'] = truncate_strings
options['truncate_char'] = options.get('truncate_char', '[...]')
reindent = options.get('reindent', False)
if reindent not in [True, False]:
raise SQLParseError('Invalid value for reindent: %r'
% reindent)
elif reindent:
options['strip_whitespace'] = True
indent_tabs = options.get('indent_tabs', False)
if indent_tabs not in [True, False]:
raise SQLParseError('Invalid value for indent_tabs: %r' % indent_tabs)
elif indent_tabs:
options['indent_char'] = '\t'
else:
options['indent_char'] = ' '
indent_width = options.get('indent_width', 2)
try:
indent_width = int(indent_width)
except (TypeError, ValueError):
raise SQLParseError('indent_width requires an integer')
if indent_width < 1:
raise SQLParseError('indent_width requires an positive integer')
options['indent_width'] = indent_width
right_margin = options.get('right_margin', None)
if right_margin is not None:
try:
right_margin = int(right_margin)
except (TypeError, ValueError):
raise SQLParseError('right_margin requires an integer')
if right_margin < 10:
raise SQLParseError('right_margin requires an integer > 10')
options['right_margin'] = right_margin
return options
def build_filter_stack(stack, options):
"""Setup and return a filter stack.
Args:
stack: :class:`~sqlparse.filters.FilterStack` instance
options: Dictionary with options validated by validate_options.
"""
# Token filter
if options.get('keyword_case', None):
stack.preprocess.append(
filters.KeywordCaseFilter(options['keyword_case']))
if options.get('identifier_case', None):
stack.preprocess.append(
filters.IdentifierCaseFilter(options['identifier_case']))
if options.get('truncate_strings', None) is not None:
stack.preprocess.append(filters.TruncateStringFilter(
width=options['truncate_strings'], char=options['truncate_char']))
# After grouping
if options.get('strip_comments', False):
stack.enable_grouping()
stack.stmtprocess.append(filters.StripCommentsFilter())
if (options.get('strip_whitespace', False)
or options.get('reindent', False)):
stack.enable_grouping()
stack.stmtprocess.append(filters.StripWhitespaceFilter())
if options.get('reindent', False):
stack.enable_grouping()
stack.stmtprocess.append(
filters.ReindentFilter(char=options['indent_char'],
width=options['indent_width']))
if options.get('right_margin', False):
stack.enable_grouping()
stack.stmtprocess.append(
filters.RightMarginFilter(width=options['right_margin']))
# Serializer
if options.get('output_format'):
frmt = options['output_format']
if frmt.lower() == 'php':
fltr = filters.OutputPHPFilter()
elif frmt.lower() == 'python':
fltr = filters.OutputPythonFilter()
else:
fltr = None
if fltr is not None:
stack.postprocess.append(fltr)
return stack
|
mit
|
[
3,
1898,
334,
35,
9,
9079,
1626,
328,
4580,
10205,
335,
84,
12,
741,
10205,
335,
84,
14,
290,
328,
32,
6799,
14,
957,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
2366,
13,
3009,
1122,
436,
365,
14286,
1334,
199,
3,
314,
6289,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
15746,
13,
1682,
14,
8624,
14,
199,
199,
624,
4657,
9698,
624,
199,
199,
504,
3875,
1122,
492,
4766,
199,
504,
3875,
1122,
14,
3924,
492,
5385,
9123,
421,
199,
318,
4107,
63,
1419,
8,
1419,
304,
272,
408,
3490,
2335,
1511,
1041,
272,
4775,
2546,
275,
1511,
14,
362,
360,
6691,
63,
2546,
297,
488,
9,
272,
340,
4775,
2546,
440,
315,
359,
403,
12,
283,
4142,
297,
283,
2325,
297,
283,
18351,
2565,
267,
746,
5385,
9123,
360,
3364,
574,
367,
4252,
63,
2546,
26,
450,
82,
7,
450,
4775,
2546,
9,
339,
1305,
2546,
275,
1511,
14,
362,
360,
5364,
63,
2546,
297,
488,
9,
272,
340,
1305,
2546,
440,
315,
359,
403,
12,
283,
4142,
297,
283,
2325,
297,
283,
18351,
2565,
267,
746,
5385,
9123,
360,
3364,
574,
367,
5148,
63,
2546,
26,
450,
82,
7,
450,
1305,
2546,
9,
339,
402,
82,
2037,
275,
1511,
14,
362,
360,
1199,
63,
908,
297,
488,
9,
272,
340,
402,
82,
2037,
440,
315,
359,
403,
12,
283,
3009,
297,
283,
1548,
297,
283,
8624,
2565,
267,
746,
5385,
9123,
360,
5912,
1072,
1475,
26,
450,
82,
7,
450,
402,
82,
2037,
9,
339,
6202,
63,
6223,
275,
1511,
14,
362,
360,
1913,
63,
6223,
297,
756,
9,
272,
340,
6202,
63,
6223,
440,
315,
359,
549,
12,
756,
2189,
267,
746,
5385,
9123,
360,
3364,
574,
367,
6202,
63,
6223,
26,
450,
82,
7,
1169,
450,
6202,
63,
6223,
9,
339,
6202,
63,
3569,
275,
1511,
14,
362,
360,
1913,
63,
8506,
297,
756,
9,
272,
340,
6202,
63,
3569,
440,
315,
359,
549,
12,
756,
2189,
267,
746,
5385,
9123,
360,
3364,
574,
367,
6202,
63,
8506,
26,
450,
82,
7,
1169,
450,
6202,
63,
3569,
9,
339,
14547,
63,
5465,
275,
1511,
14,
362,
360,
12517,
63,
5465,
297,
488,
9,
272,
340,
14547,
63,
5465,
365,
440,
488,
26,
267,
862,
26,
288,
14547,
63,
5465,
275,
1109,
8,
12517,
63,
5465,
9,
267,
871,
334,
3393,
12,
3146,
304,
288,
746,
5385,
9123,
360,
3364,
574,
367,
14547,
63,
5465,
26,
450,
82,
7,
1816,
450,
14547,
63,
5465,
9,
267,
340,
14547,
63,
5465,
2695,
413,
26,
288,
746,
5385,
9123,
360,
3364,
574,
367,
14547,
63,
5465,
26,
450,
82,
7,
1816,
450,
14547,
63,
5465,
9,
267,
1511,
459,
12517,
63,
5465,
418,
275,
14547,
63,
5465,
267,
1511,
459,
12517,
63,
1560,
418,
275,
1511,
14,
362,
360,
12517,
63,
1560,
297,
6730,
1396,
10374,
339,
295,
3724,
275,
1511,
14,
362,
360,
264,
3724,
297,
756,
9,
272,
340,
295,
3724,
440,
315,
359,
549,
12,
756,
2189,
267,
746,
5385,
9123,
360,
3364,
574,
367,
295,
3724,
26,
450,
82,
7,
1169,
450,
295,
3724,
9,
272,
916,
295,
3724,
26,
267,
1511,
459,
1913,
63,
8506,
418,
275,
715,
272,
4363,
63,
8741,
275,
1511,
14,
362,
360,
3724,
63,
8741,
297,
756,
9,
272,
340,
4363,
63,
8741,
440,
315,
359,
549,
12,
756,
2189,
267,
746,
5385,
9123,
360,
3364,
574,
367,
4363,
63,
8741,
26,
450,
82,
7,
450,
4363,
63,
8741,
9,
272,
916,
4363,
63,
8741,
26,
267,
1511,
459,
3724,
63,
1560,
418,
275,
1557,
84,
7,
272,
587,
26,
267,
1511,
459,
3724,
63,
1560,
418,
275,
283,
283,
272,
4363,
63,
2063,
275,
1511,
14,
362,
360,
3724,
63,
2063,
297,
499,
9,
272,
862,
26,
267,
4363,
63,
2063,
275,
1109,
8,
3724,
63,
2063,
9,
272,
871,
334,
4333,
12,
1722,
304,
267,
746,
5385,
9123,
360,
3724,
63,
2063,
5074,
376,
3000,
358,
272,
340,
4363,
63,
2063,
665,
413,
26,
267,
746,
5385,
9123,
360,
3724,
63,
2063,
5074,
376,
7317,
3000,
358,
272,
1511,
459,
3724,
63,
2063,
418,
275,
4363,
63,
2063,
339,
2451,
63,
9650,
275,
1511,
14,
362,
360,
1019,
63,
9650,
297,
488,
9,
272,
340,
2451,
63,
9650,
365,
440,
488,
26,
267,
862,
26,
288,
2451,
63,
9650,
275,
1109,
8,
1019,
63,
9650,
9,
267,
871,
334,
4333,
12,
1722,
304,
288,
746,
5385,
9123,
360,
1019,
63,
9650,
5074,
376,
3000,
358,
267,
340,
2451,
63,
9650,
665,
1616,
26,
288,
746,
5385,
9123,
360,
1019,
63,
9650,
5074,
376,
3000,
690,
1616,
358,
272,
1511,
459,
1019,
63,
9650,
418,
275,
2451,
63,
9650,
339,
372,
1511,
421,
199,
318,
1900,
63,
1541,
63,
2340,
8,
2340,
12,
1511,
304,
272,
408,
8555,
436,
372,
282,
2457,
3464,
14,
339,
3033,
26,
489,
3464,
26,
520,
533,
6054,
3009,
1122,
14,
4273,
14,
4131,
4851,
64,
1256,
489,
1511,
26,
11932,
543,
1511,
16468,
701,
4107,
63,
1419,
14,
272,
408,
272,
327,
8767,
2457,
272,
340,
1511,
14,
362,
360,
6691,
63,
2546,
297,
488,
304,
267,
3464,
14,
17677,
14,
740,
8,
288,
4766,
14,
10650,
1538,
4131,
8,
1419,
459,
6691,
63,
2546,
5156,
339,
340,
1511,
14,
362,
360,
5364,
63,
2546,
297,
488,
304,
267,
3464,
14,
17677,
14,
740,
8,
288,
4766,
14,
7544,
1538,
4131,
8,
1419,
459,
5364,
63,
2546,
5156,
339,
340,
1511,
14,
362,
360,
12517,
63,
5465,
297,
488,
9,
365,
440,
488,
26,
267,
3464,
14,
17677,
14,
740,
8,
4273,
14,
20460,
1411,
1558,
4131,
8,
288,
3462,
29,
1419,
459,
12517,
63,
5465,
995,
1495,
29,
1419,
459,
12517,
63,
1560,
5156,
339,
327,
12836,
17786,
272,
340,
1511,
14,
362,
360,
1913,
63,
6223,
297,
756,
304,
267,
3464,
14,
4296,
63,
22390,
342,
267,
3464,
14,
9649,
1412,
14,
740,
8,
4273,
14,
21332,
18929,
4131,
1012,
339,
340,
334,
1419,
14,
362,
360,
1913,
63,
8506,
297,
756,
9,
267,
503,
1511,
14,
362,
360,
264,
3724,
297,
756,
2298,
267,
3464,
14,
4296,
63,
22390,
342,
267,
3464,
14,
9649,
1412,
14
] |
[
1898,
334,
35,
9,
9079,
1626,
328,
4580,
10205,
335,
84,
12,
741,
10205,
335,
84,
14,
290,
328,
32,
6799,
14,
957,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
2366,
13,
3009,
1122,
436,
365,
14286,
1334,
199,
3,
314,
6289,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
15746,
13,
1682,
14,
8624,
14,
199,
199,
624,
4657,
9698,
624,
199,
199,
504,
3875,
1122,
492,
4766,
199,
504,
3875,
1122,
14,
3924,
492,
5385,
9123,
421,
199,
318,
4107,
63,
1419,
8,
1419,
304,
272,
408,
3490,
2335,
1511,
1041,
272,
4775,
2546,
275,
1511,
14,
362,
360,
6691,
63,
2546,
297,
488,
9,
272,
340,
4775,
2546,
440,
315,
359,
403,
12,
283,
4142,
297,
283,
2325,
297,
283,
18351,
2565,
267,
746,
5385,
9123,
360,
3364,
574,
367,
4252,
63,
2546,
26,
450,
82,
7,
450,
4775,
2546,
9,
339,
1305,
2546,
275,
1511,
14,
362,
360,
5364,
63,
2546,
297,
488,
9,
272,
340,
1305,
2546,
440,
315,
359,
403,
12,
283,
4142,
297,
283,
2325,
297,
283,
18351,
2565,
267,
746,
5385,
9123,
360,
3364,
574,
367,
5148,
63,
2546,
26,
450,
82,
7,
450,
1305,
2546,
9,
339,
402,
82,
2037,
275,
1511,
14,
362,
360,
1199,
63,
908,
297,
488,
9,
272,
340,
402,
82,
2037,
440,
315,
359,
403,
12,
283,
3009,
297,
283,
1548,
297,
283,
8624,
2565,
267,
746,
5385,
9123,
360,
5912,
1072,
1475,
26,
450,
82,
7,
450,
402,
82,
2037,
9,
339,
6202,
63,
6223,
275,
1511,
14,
362,
360,
1913,
63,
6223,
297,
756,
9,
272,
340,
6202,
63,
6223,
440,
315,
359,
549,
12,
756,
2189,
267,
746,
5385,
9123,
360,
3364,
574,
367,
6202,
63,
6223,
26,
450,
82,
7,
1169,
450,
6202,
63,
6223,
9,
339,
6202,
63,
3569,
275,
1511,
14,
362,
360,
1913,
63,
8506,
297,
756,
9,
272,
340,
6202,
63,
3569,
440,
315,
359,
549,
12,
756,
2189,
267,
746,
5385,
9123,
360,
3364,
574,
367,
6202,
63,
8506,
26,
450,
82,
7,
1169,
450,
6202,
63,
3569,
9,
339,
14547,
63,
5465,
275,
1511,
14,
362,
360,
12517,
63,
5465,
297,
488,
9,
272,
340,
14547,
63,
5465,
365,
440,
488,
26,
267,
862,
26,
288,
14547,
63,
5465,
275,
1109,
8,
12517,
63,
5465,
9,
267,
871,
334,
3393,
12,
3146,
304,
288,
746,
5385,
9123,
360,
3364,
574,
367,
14547,
63,
5465,
26,
450,
82,
7,
1816,
450,
14547,
63,
5465,
9,
267,
340,
14547,
63,
5465,
2695,
413,
26,
288,
746,
5385,
9123,
360,
3364,
574,
367,
14547,
63,
5465,
26,
450,
82,
7,
1816,
450,
14547,
63,
5465,
9,
267,
1511,
459,
12517,
63,
5465,
418,
275,
14547,
63,
5465,
267,
1511,
459,
12517,
63,
1560,
418,
275,
1511,
14,
362,
360,
12517,
63,
1560,
297,
6730,
1396,
10374,
339,
295,
3724,
275,
1511,
14,
362,
360,
264,
3724,
297,
756,
9,
272,
340,
295,
3724,
440,
315,
359,
549,
12,
756,
2189,
267,
746,
5385,
9123,
360,
3364,
574,
367,
295,
3724,
26,
450,
82,
7,
1169,
450,
295,
3724,
9,
272,
916,
295,
3724,
26,
267,
1511,
459,
1913,
63,
8506,
418,
275,
715,
272,
4363,
63,
8741,
275,
1511,
14,
362,
360,
3724,
63,
8741,
297,
756,
9,
272,
340,
4363,
63,
8741,
440,
315,
359,
549,
12,
756,
2189,
267,
746,
5385,
9123,
360,
3364,
574,
367,
4363,
63,
8741,
26,
450,
82,
7,
450,
4363,
63,
8741,
9,
272,
916,
4363,
63,
8741,
26,
267,
1511,
459,
3724,
63,
1560,
418,
275,
1557,
84,
7,
272,
587,
26,
267,
1511,
459,
3724,
63,
1560,
418,
275,
283,
283,
272,
4363,
63,
2063,
275,
1511,
14,
362,
360,
3724,
63,
2063,
297,
499,
9,
272,
862,
26,
267,
4363,
63,
2063,
275,
1109,
8,
3724,
63,
2063,
9,
272,
871,
334,
4333,
12,
1722,
304,
267,
746,
5385,
9123,
360,
3724,
63,
2063,
5074,
376,
3000,
358,
272,
340,
4363,
63,
2063,
665,
413,
26,
267,
746,
5385,
9123,
360,
3724,
63,
2063,
5074,
376,
7317,
3000,
358,
272,
1511,
459,
3724,
63,
2063,
418,
275,
4363,
63,
2063,
339,
2451,
63,
9650,
275,
1511,
14,
362,
360,
1019,
63,
9650,
297,
488,
9,
272,
340,
2451,
63,
9650,
365,
440,
488,
26,
267,
862,
26,
288,
2451,
63,
9650,
275,
1109,
8,
1019,
63,
9650,
9,
267,
871,
334,
4333,
12,
1722,
304,
288,
746,
5385,
9123,
360,
1019,
63,
9650,
5074,
376,
3000,
358,
267,
340,
2451,
63,
9650,
665,
1616,
26,
288,
746,
5385,
9123,
360,
1019,
63,
9650,
5074,
376,
3000,
690,
1616,
358,
272,
1511,
459,
1019,
63,
9650,
418,
275,
2451,
63,
9650,
339,
372,
1511,
421,
199,
318,
1900,
63,
1541,
63,
2340,
8,
2340,
12,
1511,
304,
272,
408,
8555,
436,
372,
282,
2457,
3464,
14,
339,
3033,
26,
489,
3464,
26,
520,
533,
6054,
3009,
1122,
14,
4273,
14,
4131,
4851,
64,
1256,
489,
1511,
26,
11932,
543,
1511,
16468,
701,
4107,
63,
1419,
14,
272,
408,
272,
327,
8767,
2457,
272,
340,
1511,
14,
362,
360,
6691,
63,
2546,
297,
488,
304,
267,
3464,
14,
17677,
14,
740,
8,
288,
4766,
14,
10650,
1538,
4131,
8,
1419,
459,
6691,
63,
2546,
5156,
339,
340,
1511,
14,
362,
360,
5364,
63,
2546,
297,
488,
304,
267,
3464,
14,
17677,
14,
740,
8,
288,
4766,
14,
7544,
1538,
4131,
8,
1419,
459,
5364,
63,
2546,
5156,
339,
340,
1511,
14,
362,
360,
12517,
63,
5465,
297,
488,
9,
365,
440,
488,
26,
267,
3464,
14,
17677,
14,
740,
8,
4273,
14,
20460,
1411,
1558,
4131,
8,
288,
3462,
29,
1419,
459,
12517,
63,
5465,
995,
1495,
29,
1419,
459,
12517,
63,
1560,
5156,
339,
327,
12836,
17786,
272,
340,
1511,
14,
362,
360,
1913,
63,
6223,
297,
756,
304,
267,
3464,
14,
4296,
63,
22390,
342,
267,
3464,
14,
9649,
1412,
14,
740,
8,
4273,
14,
21332,
18929,
4131,
1012,
339,
340,
334,
1419,
14,
362,
360,
1913,
63,
8506,
297,
756,
9,
267,
503,
1511,
14,
362,
360,
264,
3724,
297,
756,
2298,
267,
3464,
14,
4296,
63,
22390,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
bhairavmehta95/flashcard-helper-alexa-skill
|
venv/lib/python2.7/site-packages/pip/vcs/mercurial.py
|
514
|
3472
|
from __future__ import absolute_import
import logging
import os
import tempfile
from pip.utils import display_path, rmtree
from pip.vcs import vcs, VersionControl
from pip.download import path_to_url
from pip._vendor.six.moves import configparser
logger = logging.getLogger(__name__)
class Mercurial(VersionControl):
name = 'hg'
dirname = '.hg'
repo_name = 'clone'
schemes = ('hg', 'hg+http', 'hg+https', 'hg+ssh', 'hg+static-http')
def export(self, location):
"""Export the Hg repository at the url to the destination location"""
temp_dir = tempfile.mkdtemp('-export', 'pip-')
self.unpack(temp_dir)
try:
self.run_command(
['archive', location], show_stdout=False, cwd=temp_dir)
finally:
rmtree(temp_dir)
def switch(self, dest, url, rev_options):
repo_config = os.path.join(dest, self.dirname, 'hgrc')
config = configparser.SafeConfigParser()
try:
config.read(repo_config)
config.set('paths', 'default', url)
with open(repo_config, 'w') as config_file:
config.write(config_file)
except (OSError, configparser.NoSectionError) as exc:
logger.warning(
'Could not switch Mercurial repository to %s: %s', url, exc,
)
else:
self.run_command(['update', '-q'] + rev_options, cwd=dest)
def update(self, dest, rev_options):
self.run_command(['pull', '-q'], cwd=dest)
self.run_command(['update', '-q'] + rev_options, cwd=dest)
def obtain(self, dest):
url, rev = self.get_url_rev()
if rev:
rev_options = [rev]
rev_display = ' (to revision %s)' % rev
else:
rev_options = []
rev_display = ''
if self.check_destination(dest, url, rev_options, rev_display):
logger.info(
'Cloning hg %s%s to %s',
url,
rev_display,
display_path(dest),
)
self.run_command(['clone', '--noupdate', '-q', url, dest])
self.run_command(['update', '-q'] + rev_options, cwd=dest)
def get_url(self, location):
url = self.run_command(
['showconfig', 'paths.default'],
show_stdout=False, cwd=location).strip()
if self._is_local_repository(url):
url = path_to_url(url)
return url.strip()
def get_revision(self, location):
current_revision = self.run_command(
['parents', '--template={rev}'],
show_stdout=False, cwd=location).strip()
return current_revision
def get_revision_hash(self, location):
current_rev_hash = self.run_command(
['parents', '--template={node}'],
show_stdout=False, cwd=location).strip()
return current_rev_hash
def get_src_requirement(self, dist, location):
repo = self.get_url(location)
if not repo.lower().startswith('hg:'):
repo = 'hg+' + repo
egg_project_name = dist.egg_name().split('-', 1)[0]
if not repo:
return None
current_rev_hash = self.get_revision_hash(location)
return '%s@%s#egg=%s' % (repo, current_rev_hash, egg_project_name)
def check_version(self, dest, rev_options):
"""Always assume the versions don't match"""
return False
vcs.register(Mercurial)
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
5549,
199,
199,
504,
7305,
14,
1208,
492,
2929,
63,
515,
12,
20978,
199,
504,
7305,
14,
15525,
492,
19827,
12,
3394,
3717,
199,
504,
7305,
14,
4249,
492,
931,
63,
475,
63,
633,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
492,
21230,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
30522,
8,
3353,
3717,
304,
272,
536,
275,
283,
9208,
7,
272,
9017,
275,
1987,
9208,
7,
272,
3831,
63,
354,
275,
283,
6311,
7,
272,
21149,
275,
661,
9208,
297,
283,
9208,
11,
1014,
297,
283,
9208,
11,
2859,
297,
283,
9208,
11,
5510,
297,
283,
9208,
11,
1986,
13,
1014,
358,
339,
347,
4843,
8,
277,
12,
2909,
304,
267,
408,
11399,
314,
869,
71,
7611,
737,
314,
1166,
370,
314,
5724,
2909,
624,
267,
2388,
63,
694,
275,
5549,
14,
11983,
3654,
3790,
297,
283,
9983,
25815,
267,
291,
14,
5301,
8,
808,
63,
694,
9,
267,
862,
26,
288,
291,
14,
1065,
63,
1531,
8,
355,
788,
6404,
297,
2909,
467,
2498,
63,
2703,
29,
797,
12,
8288,
29,
808,
63,
694,
9,
267,
3753,
26,
288,
20978,
8,
808,
63,
694,
9,
339,
347,
6258,
8,
277,
12,
2053,
12,
1166,
12,
6822,
63,
1419,
304,
267,
3831,
63,
888,
275,
747,
14,
515,
14,
904,
8,
2614,
12,
291,
14,
3475,
12,
283,
9208,
1195,
358,
267,
1101,
275,
21230,
14,
11090,
15218,
342,
267,
862,
26,
288,
1101,
14,
739,
8,
3417,
63,
888,
9,
288,
1101,
14,
409,
360,
3771,
297,
283,
885,
297,
1166,
9,
288,
543,
1551,
8,
3417,
63,
888,
12,
283,
87,
358,
465,
1101,
63,
493,
26,
355,
1101,
14,
952,
8,
888,
63,
493,
9,
267,
871,
334,
16719,
12,
21230,
14,
1944,
8660,
547,
9,
465,
3178,
26,
288,
2512,
14,
3764,
8,
355,
283,
6531,
440,
6258,
30522,
7611,
370,
450,
83,
26,
450,
83,
297,
1166,
12,
3178,
12,
288,
776,
267,
587,
26,
288,
291,
14,
1065,
63,
1531,
2941,
873,
297,
2475,
81,
418,
435,
6822,
63,
1419,
12,
8288,
29,
2614,
9,
339,
347,
1678,
8,
277,
12,
2053,
12,
6822,
63,
1419,
304,
267,
291,
14,
1065,
63,
1531,
2941,
9302,
297,
2475,
81,
995,
8288,
29,
2614,
9,
267,
291,
14,
1065,
63,
1531,
2941,
873,
297,
2475,
81,
418,
435,
6822,
63,
1419,
12,
8288,
29,
2614,
9,
339,
347,
3332,
8,
277,
12,
2053,
304,
267,
1166,
12,
6822,
275,
291,
14,
362,
63,
633,
63,
4964,
342,
267,
340,
6822,
26,
288,
6822,
63,
1419,
275,
359,
4964,
61,
288,
6822,
63,
2918,
275,
283,
334,
475,
6974,
450,
83,
3171,
450,
6822,
267,
587,
26,
288,
6822,
63,
1419,
275,
942,
288,
6822,
63,
2918,
275,
2125,
267,
340,
291,
14,
1074,
63,
6881,
8,
2614,
12,
1166,
12,
6822,
63,
1419,
12,
6822,
63,
2918,
304,
288,
2512,
14,
815,
8,
355,
283,
1968,
19718,
18016,
450,
83,
5,
83,
370,
450,
83,
297,
355,
1166,
12,
355,
6822,
63,
2918,
12,
355,
2929,
63,
515,
8,
2614,
395,
288,
776,
288,
291,
14,
1065,
63,
1531,
2941,
6311,
297,
2850,
889,
873,
297,
2475,
81,
297,
1166,
12,
2053,
566,
288,
291,
14,
1065,
63,
1531,
2941,
873,
297,
2475,
81,
418,
435,
6822,
63,
1419,
12,
8288,
29,
2614,
9,
339,
347,
664,
63,
633,
8,
277,
12,
2909,
304,
267,
1166,
275,
291,
14,
1065,
63,
1531,
8,
288,
788,
2384,
888,
297,
283,
3771,
14,
885,
995,
288,
2498,
63,
2703,
29,
797,
12,
8288,
29,
1985,
680,
1913,
342,
267,
340,
291,
423,
374,
63,
1832,
63,
8421,
8,
633,
304,
288,
1166,
275,
931,
63,
475,
63,
633,
8,
633,
9,
267,
372,
1166,
14,
1913,
342,
339,
347,
664,
63,
5792,
8,
277,
12,
2909,
304,
267,
1453,
63,
5792,
275,
291,
14,
1065,
63,
1531,
8,
288,
788,
8859,
297,
2850,
1160,
3126,
4964,
93,
995,
288,
2498,
63,
2703,
29,
797,
12,
8288,
29,
1985,
680,
1913,
342,
267,
372,
1453,
63,
5792,
339,
347,
664,
63,
5792,
63,
2227,
8,
277,
12,
2909,
304,
267,
1453,
63,
4964,
63,
2227,
275,
291,
14,
1065,
63,
1531,
8,
288,
788,
8859,
297,
2850,
1160,
3126,
932,
93,
995,
288,
2498,
63,
2703,
29,
797,
12,
8288,
29,
1985,
680,
1913,
342,
267,
372,
1453,
63,
4964,
63,
2227,
339,
347,
664,
63,
2164,
63,
12434,
8,
277,
12,
2917,
12,
2909,
304,
267,
3831,
275,
291,
14,
362,
63,
633,
8,
1985,
9,
267,
340,
440,
3831,
14,
2325,
1252,
2460,
360,
9208,
23117,
288,
3831,
275,
283,
9208,
4786,
435,
3831,
267,
11393,
63,
1715,
63,
354,
275,
2917,
14,
5799,
63,
354,
1252,
1294,
13858,
413,
2788,
16,
61,
267,
340,
440,
3831,
26,
288,
372,
488,
267,
1453,
63,
4964,
63,
2227,
275,
291,
14,
362,
63,
5792,
63,
2227,
8,
1985,
9,
267,
372,
1543,
83,
19437,
83,
3,
5799,
2458,
83,
7,
450,
334,
3417,
12,
1453,
63,
4964,
63,
2227,
12,
11393,
63,
1715,
63,
354,
9,
339,
347,
1104,
63,
1023,
8,
277,
12,
2053,
12,
6822,
63,
1419,
304,
267,
408,
2439,
2885,
5534,
314,
5459,
2793,
1133,
1336,
624,
267,
372,
756,
199,
199,
15525,
14,
2683,
8,
16797,
18977,
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
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
5549,
199,
199,
504,
7305,
14,
1208,
492,
2929,
63,
515,
12,
20978,
199,
504,
7305,
14,
15525,
492,
19827,
12,
3394,
3717,
199,
504,
7305,
14,
4249,
492,
931,
63,
475,
63,
633,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
492,
21230,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
30522,
8,
3353,
3717,
304,
272,
536,
275,
283,
9208,
7,
272,
9017,
275,
1987,
9208,
7,
272,
3831,
63,
354,
275,
283,
6311,
7,
272,
21149,
275,
661,
9208,
297,
283,
9208,
11,
1014,
297,
283,
9208,
11,
2859,
297,
283,
9208,
11,
5510,
297,
283,
9208,
11,
1986,
13,
1014,
358,
339,
347,
4843,
8,
277,
12,
2909,
304,
267,
408,
11399,
314,
869,
71,
7611,
737,
314,
1166,
370,
314,
5724,
2909,
624,
267,
2388,
63,
694,
275,
5549,
14,
11983,
3654,
3790,
297,
283,
9983,
25815,
267,
291,
14,
5301,
8,
808,
63,
694,
9,
267,
862,
26,
288,
291,
14,
1065,
63,
1531,
8,
355,
788,
6404,
297,
2909,
467,
2498,
63,
2703,
29,
797,
12,
8288,
29,
808,
63,
694,
9,
267,
3753,
26,
288,
20978,
8,
808,
63,
694,
9,
339,
347,
6258,
8,
277,
12,
2053,
12,
1166,
12,
6822,
63,
1419,
304,
267,
3831,
63,
888,
275,
747,
14,
515,
14,
904,
8,
2614,
12,
291,
14,
3475,
12,
283,
9208,
1195,
358,
267,
1101,
275,
21230,
14,
11090,
15218,
342,
267,
862,
26,
288,
1101,
14,
739,
8,
3417,
63,
888,
9,
288,
1101,
14,
409,
360,
3771,
297,
283,
885,
297,
1166,
9,
288,
543,
1551,
8,
3417,
63,
888,
12,
283,
87,
358,
465,
1101,
63,
493,
26,
355,
1101,
14,
952,
8,
888,
63,
493,
9,
267,
871,
334,
16719,
12,
21230,
14,
1944,
8660,
547,
9,
465,
3178,
26,
288,
2512,
14,
3764,
8,
355,
283,
6531,
440,
6258,
30522,
7611,
370,
450,
83,
26,
450,
83,
297,
1166,
12,
3178,
12,
288,
776,
267,
587,
26,
288,
291,
14,
1065,
63,
1531,
2941,
873,
297,
2475,
81,
418,
435,
6822,
63,
1419,
12,
8288,
29,
2614,
9,
339,
347,
1678,
8,
277,
12,
2053,
12,
6822,
63,
1419,
304,
267,
291,
14,
1065,
63,
1531,
2941,
9302,
297,
2475,
81,
995,
8288,
29,
2614,
9,
267,
291,
14,
1065,
63,
1531,
2941,
873,
297,
2475,
81,
418,
435,
6822,
63,
1419,
12,
8288,
29,
2614,
9,
339,
347,
3332,
8,
277,
12,
2053,
304,
267,
1166,
12,
6822,
275,
291,
14,
362,
63,
633,
63,
4964,
342,
267,
340,
6822,
26,
288,
6822,
63,
1419,
275,
359,
4964,
61,
288,
6822,
63,
2918,
275,
283,
334,
475,
6974,
450,
83,
3171,
450,
6822,
267,
587,
26,
288,
6822,
63,
1419,
275,
942,
288,
6822,
63,
2918,
275,
2125,
267,
340,
291,
14,
1074,
63,
6881,
8,
2614,
12,
1166,
12,
6822,
63,
1419,
12,
6822,
63,
2918,
304,
288,
2512,
14,
815,
8,
355,
283,
1968,
19718,
18016,
450,
83,
5,
83,
370,
450,
83,
297,
355,
1166,
12,
355,
6822,
63,
2918,
12,
355,
2929,
63,
515,
8,
2614,
395,
288,
776,
288,
291,
14,
1065,
63,
1531,
2941,
6311,
297,
2850,
889,
873,
297,
2475,
81,
297,
1166,
12,
2053,
566,
288,
291,
14,
1065,
63,
1531,
2941,
873,
297,
2475,
81,
418,
435,
6822,
63,
1419,
12,
8288,
29,
2614,
9,
339,
347,
664,
63,
633,
8,
277,
12,
2909,
304,
267,
1166,
275,
291,
14,
1065,
63,
1531,
8,
288,
788,
2384,
888,
297,
283,
3771,
14,
885,
995,
288,
2498,
63,
2703,
29,
797,
12,
8288,
29,
1985,
680,
1913,
342,
267,
340,
291,
423,
374,
63,
1832,
63,
8421,
8,
633,
304,
288,
1166,
275,
931,
63,
475,
63,
633,
8,
633,
9,
267,
372,
1166,
14,
1913,
342,
339,
347,
664,
63,
5792,
8,
277,
12,
2909,
304,
267,
1453,
63,
5792,
275,
291,
14,
1065,
63,
1531,
8,
288,
788,
8859,
297,
2850,
1160,
3126,
4964,
93,
995,
288,
2498,
63,
2703,
29,
797,
12,
8288,
29,
1985,
680,
1913,
342,
267,
372,
1453,
63,
5792,
339,
347,
664,
63,
5792,
63,
2227,
8,
277,
12,
2909,
304,
267,
1453,
63,
4964,
63,
2227,
275,
291,
14,
1065,
63,
1531,
8,
288,
788,
8859,
297,
2850,
1160,
3126,
932,
93,
995,
288,
2498,
63,
2703,
29,
797,
12,
8288,
29,
1985,
680,
1913,
342,
267,
372,
1453,
63,
4964,
63,
2227,
339,
347,
664,
63,
2164,
63,
12434,
8,
277,
12,
2917,
12,
2909,
304,
267,
3831,
275,
291,
14,
362,
63,
633,
8,
1985,
9,
267,
340,
440,
3831,
14,
2325,
1252,
2460,
360,
9208,
23117,
288,
3831,
275,
283,
9208,
4786,
435,
3831,
267,
11393,
63,
1715,
63,
354,
275,
2917,
14,
5799,
63,
354,
1252,
1294,
13858,
413,
2788,
16,
61,
267,
340,
440,
3831,
26,
288,
372,
488,
267,
1453,
63,
4964,
63,
2227,
275,
291,
14,
362,
63,
5792,
63,
2227,
8,
1985,
9,
267,
372,
1543,
83,
19437,
83,
3,
5799,
2458,
83,
7,
450,
334,
3417,
12,
1453,
63,
4964,
63,
2227,
12,
11393,
63,
1715,
63,
354,
9,
339,
347,
1104,
63,
1023,
8,
277,
12,
2053,
12,
6822,
63,
1419,
304,
267,
408,
2439,
2885,
5534,
314,
5459,
2793,
1133,
1336,
624,
267,
372,
756,
199,
199,
15525,
14,
2683,
8,
16797,
18977,
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,
32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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Aorjoa/aiyara-ceph-dash
|
.tox/py27/lib/python2.7/site-packages/nose/plugins/cover.py
|
48
|
11673
|
"""If you have Ned Batchelder's coverage_ module installed, you may activate a
coverage report with the ``--with-coverage`` switch or NOSE_WITH_COVERAGE
environment variable. The coverage report will cover any python source module
imported after the start of the test run, excluding modules that match
testMatch. If you want to include those modules too, use the ``--cover-tests``
switch, or set the NOSE_COVER_TESTS environment variable to a true value. To
restrict the coverage report to modules from a particular package or packages,
use the ``--cover-package`` switch or the NOSE_COVER_PACKAGE environment
variable.
.. _coverage: http://www.nedbatchelder.com/code/modules/coverage.html
"""
import logging
import re
import sys
import StringIO
from nose.plugins.base import Plugin
from nose.util import src, tolist
log = logging.getLogger(__name__)
class Coverage(Plugin):
"""
Activate a coverage report using Ned Batchelder's coverage module.
"""
coverTests = False
coverPackages = None
coverInstance = None
coverErase = False
coverMinPercentage = None
score = 200
status = {}
def options(self, parser, env):
"""
Add options to command line.
"""
super(Coverage, self).options(parser, env)
parser.add_option("--cover-package", action="append",
default=env.get('NOSE_COVER_PACKAGE'),
metavar="PACKAGE",
dest="cover_packages",
help="Restrict coverage output to selected packages "
"[NOSE_COVER_PACKAGE]")
parser.add_option("--cover-erase", action="store_true",
default=env.get('NOSE_COVER_ERASE'),
dest="cover_erase",
help="Erase previously collected coverage "
"statistics before run")
parser.add_option("--cover-tests", action="store_true",
dest="cover_tests",
default=env.get('NOSE_COVER_TESTS'),
help="Include test modules in coverage report "
"[NOSE_COVER_TESTS]")
parser.add_option("--cover-min-percentage", action="store",
dest="cover_min_percentage",
default=env.get('NOSE_COVER_MIN_PERCENTAGE'),
help="Minimum percentage of coverage for tests "
"to pass [NOSE_COVER_MIN_PERCENTAGE]")
parser.add_option("--cover-inclusive", action="store_true",
dest="cover_inclusive",
default=env.get('NOSE_COVER_INCLUSIVE'),
help="Include all python files under working "
"directory in coverage report. Useful for "
"discovering holes in test coverage if not all "
"files are imported by the test suite. "
"[NOSE_COVER_INCLUSIVE]")
parser.add_option("--cover-html", action="store_true",
default=env.get('NOSE_COVER_HTML'),
dest='cover_html',
help="Produce HTML coverage information")
parser.add_option('--cover-html-dir', action='store',
default=env.get('NOSE_COVER_HTML_DIR', 'cover'),
dest='cover_html_dir',
metavar='DIR',
help='Produce HTML coverage information in dir')
parser.add_option("--cover-branches", action="store_true",
default=env.get('NOSE_COVER_BRANCHES'),
dest="cover_branches",
help="Include branch coverage in coverage report "
"[NOSE_COVER_BRANCHES]")
parser.add_option("--cover-xml", action="store_true",
default=env.get('NOSE_COVER_XML'),
dest="cover_xml",
help="Produce XML coverage information")
parser.add_option("--cover-xml-file", action="store",
default=env.get('NOSE_COVER_XML_FILE', 'coverage.xml'),
dest="cover_xml_file",
metavar="FILE",
help="Produce XML coverage information in file")
def configure(self, options, conf):
"""
Configure plugin.
"""
try:
self.status.pop('active')
except KeyError:
pass
super(Coverage, self).configure(options, conf)
if self.enabled:
try:
import coverage
if not hasattr(coverage, 'coverage'):
raise ImportError("Unable to import coverage module")
except ImportError:
log.error("Coverage not available: "
"unable to import coverage module")
self.enabled = False
return
self.conf = conf
self.coverErase = options.cover_erase
self.coverTests = options.cover_tests
self.coverPackages = []
if options.cover_packages:
if isinstance(options.cover_packages, (list, tuple)):
cover_packages = options.cover_packages
else:
cover_packages = [options.cover_packages]
for pkgs in [tolist(x) for x in cover_packages]:
self.coverPackages.extend(pkgs)
self.coverInclusive = options.cover_inclusive
if self.coverPackages:
log.info("Coverage report will include only packages: %s",
self.coverPackages)
self.coverHtmlDir = None
if options.cover_html:
self.coverHtmlDir = options.cover_html_dir
log.debug('Will put HTML coverage report in %s', self.coverHtmlDir)
self.coverBranches = options.cover_branches
self.coverXmlFile = None
if options.cover_min_percentage:
self.coverMinPercentage = int(options.cover_min_percentage.rstrip('%'))
if options.cover_xml:
self.coverXmlFile = options.cover_xml_file
log.debug('Will put XML coverage report in %s', self.coverXmlFile)
if self.enabled:
self.status['active'] = True
self.coverInstance = coverage.coverage(auto_data=False,
branch=self.coverBranches, data_suffix=conf.worker,
source=self.coverPackages)
self.coverInstance._warn_no_data = False
self.coverInstance.is_worker = conf.worker
self.coverInstance.exclude('#pragma[: ]+[nN][oO] [cC][oO][vV][eE][rR]')
log.debug("Coverage begin")
self.skipModules = sys.modules.keys()[:]
if self.coverErase:
log.debug("Clearing previously collected coverage statistics")
self.coverInstance.combine()
self.coverInstance.erase()
if not self.coverInstance.is_worker:
self.coverInstance.load()
self.coverInstance.start()
def beforeTest(self, *args, **kwargs):
"""
Begin recording coverage information.
"""
if self.coverInstance.is_worker:
self.coverInstance.load()
self.coverInstance.start()
def afterTest(self, *args, **kwargs):
"""
Stop recording coverage information.
"""
if self.coverInstance.is_worker:
self.coverInstance.stop()
self.coverInstance.save()
def report(self, stream):
"""
Output code coverage report.
"""
log.debug("Coverage report")
self.coverInstance.stop()
self.coverInstance.combine()
self.coverInstance.save()
modules = [module
for name, module in sys.modules.items()
if self.wantModuleCoverage(name, module)]
log.debug("Coverage report will cover modules: %s", modules)
self.coverInstance.report(modules, file=stream)
import coverage
if self.coverHtmlDir:
log.debug("Generating HTML coverage report")
try:
self.coverInstance.html_report(modules, self.coverHtmlDir)
except coverage.misc.CoverageException, e:
log.warning("Failed to generate HTML report: %s" % str(e))
if self.coverXmlFile:
log.debug("Generating XML coverage report")
try:
self.coverInstance.xml_report(modules, self.coverXmlFile)
except coverage.misc.CoverageException, e:
log.warning("Failed to generate XML report: %s" % str(e))
# make sure we have minimum required coverage
if self.coverMinPercentage:
f = StringIO.StringIO()
self.coverInstance.report(modules, file=f)
multiPackageRe = (r'-------\s\w+\s+\d+\s+\d+(?:\s+\d+\s+\d+)?'
r'\s+(\d+)%\s+\d*\s{0,1}$')
singlePackageRe = (r'-------\s[\w./]+\s+\d+\s+\d+(?:\s+\d+\s+\d+)?'
r'\s+(\d+)%(?:\s+[-\d, ]+)\s{0,1}$')
m = re.search(multiPackageRe, f.getvalue())
if m is None:
m = re.search(singlePackageRe, f.getvalue())
if m:
percentage = int(m.groups()[0])
if percentage < self.coverMinPercentage:
log.error('TOTAL Coverage did not reach minimum '
'required: %d%%' % self.coverMinPercentage)
sys.exit(1)
else:
log.error("No total percentage was found in coverage output, "
"something went wrong.")
def wantModuleCoverage(self, name, module):
if not hasattr(module, '__file__'):
log.debug("no coverage of %s: no __file__", name)
return False
module_file = src(module.__file__)
if not module_file or not module_file.endswith('.py'):
log.debug("no coverage of %s: not a python file", name)
return False
if self.coverPackages:
for package in self.coverPackages:
if (re.findall(r'^%s\b' % re.escape(package), name)
and (self.coverTests
or not self.conf.testMatch.search(name))):
log.debug("coverage for %s", name)
return True
if name in self.skipModules:
log.debug("no coverage for %s: loaded before coverage start",
name)
return False
if self.conf.testMatch.search(name) and not self.coverTests:
log.debug("no coverage for %s: is a test", name)
return False
# accept any package that passed the previous tests, unless
# coverPackages is on -- in that case, if we wanted this
# module, we would have already returned True
return not self.coverPackages
def wantFile(self, file, package=None):
"""If inclusive coverage enabled, return true for all source files
in wanted packages.
"""
if self.coverInclusive:
if file.endswith(".py"):
if package and self.coverPackages:
for want in self.coverPackages:
if package.startswith(want):
return True
else:
return True
return None
|
bsd-2-clause
|
[
624,
3917,
1265,
1172,
653,
379,
17206,
352,
424,
1159,
11745,
63,
859,
4903,
12,
1265,
1443,
15422,
282,
199,
10828,
3622,
543,
314,
1124,
306,
1045,
13,
10828,
1040,
6258,
503,
4825,
899,
63,
9139,
63,
19052,
2962,
199,
5418,
1750,
14,
710,
11745,
3622,
911,
8486,
1263,
2366,
1350,
859,
199,
17932,
2410,
314,
1343,
402,
314,
511,
1255,
12,
28529,
4621,
626,
1336,
199,
396,
4486,
14,
982,
1265,
2934,
370,
2387,
5204,
4621,
4634,
12,
675,
314,
1124,
306,
5899,
13,
2219,
1040,
199,
5656,
12,
503,
663,
314,
4825,
899,
63,
19052,
63,
7569,
3734,
1750,
370,
282,
2549,
574,
14,
4005,
199,
22188,
314,
11745,
3622,
370,
4621,
687,
282,
6770,
2559,
503,
6117,
12,
199,
1180,
314,
1124,
306,
5899,
13,
2491,
1040,
6258,
503,
314,
4825,
899,
63,
19052,
63,
19265,
3734,
199,
1975,
14,
199,
199,
703,
485,
10828,
26,
1455,
921,
1544,
14,
7439,
2912,
352,
424,
14,
957,
15,
600,
15,
3112,
15,
10828,
14,
1360,
199,
624,
199,
646,
2050,
199,
646,
295,
199,
646,
984,
199,
646,
5228,
199,
504,
11354,
14,
5265,
14,
1095,
492,
11349,
199,
504,
11354,
14,
1974,
492,
2928,
12,
370,
513,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
1849,
3652,
8,
5061,
304,
272,
408,
272,
21904,
2409,
282,
11745,
3622,
1808,
653,
379,
17206,
352,
424,
1159,
11745,
859,
14,
272,
408,
272,
8486,
2925,
275,
756,
272,
8486,
25135,
275,
488,
272,
8486,
3244,
275,
488,
272,
8486,
29960,
275,
756,
272,
8486,
4649,
17931,
474,
275,
488,
272,
5396,
275,
1926,
272,
2004,
275,
1052,
339,
347,
1511,
8,
277,
12,
1798,
12,
2589,
304,
267,
408,
267,
2654,
1511,
370,
1414,
1004,
14,
267,
408,
267,
1613,
8,
27444,
12,
291,
680,
1419,
8,
2087,
12,
2589,
9,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
2491,
401,
1595,
628,
740,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
19265,
659,
2079,
8214,
628,
19265,
401,
2079,
2053,
628,
5899,
63,
5154,
401,
2079,
1720,
628,
497,
4768,
11745,
1072,
370,
4895,
6117,
298,
2079,
7369,
2826,
899,
63,
19052,
63,
19265,
12523,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
22087,
401,
1595,
628,
1617,
63,
2052,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
540,
8162,
659,
2079,
2053,
628,
5899,
63,
22087,
401,
2079,
1720,
628,
29960,
10889,
13736,
11745,
298,
2079,
298,
13724,
2544,
1255,
531,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
2219,
401,
1595,
628,
1617,
63,
2052,
401,
2079,
2053,
628,
5899,
63,
2219,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
7569,
659,
2079,
1720,
628,
7826,
511,
4621,
315,
11745,
3622,
298,
2079,
7369,
2826,
899,
63,
19052,
63,
7569,
12523,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
827,
13,
14200,
401,
1595,
628,
1617,
401,
2079,
2053,
628,
5899,
63,
827,
63,
14200,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
4896,
63,
4227,
17349,
2962,
659,
2079,
1720,
628,
12092,
16327,
402,
11745,
367,
2295,
298,
2079,
298,
475,
986,
359,
2826,
899,
63,
19052,
63,
4896,
63,
4227,
17349,
2962,
12523,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
26062,
401,
1595,
628,
1617,
63,
2052,
401,
2079,
2053,
628,
5899,
63,
26062,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
568,
1981,
1668,
5399,
659,
2079,
1720,
628,
7826,
1006,
2366,
1584,
1334,
6449,
298,
2079,
298,
3619,
315,
11745,
3622,
14,
221,
18491,
367,
298,
2079,
298,
18861,
316,
2636,
2978,
315,
511,
11745,
340,
440,
1006,
298,
2079,
298,
1725,
787,
8439,
701,
314,
511,
5241,
14,
298,
2079,
7369,
2826,
899,
63,
19052,
63,
568,
1981,
1668,
5399,
12523,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
1360,
401,
1595,
628,
1617,
63,
2052,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
4943,
659,
2079,
2053,
534,
5899,
63,
1360,
297,
2079,
1720,
628,
24391,
4163,
11745,
2556,
531,
267,
1798,
14,
525,
63,
1422,
4517,
5899,
13,
1360,
13,
694,
297,
1595,
534,
1617,
297,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
4943,
63,
3022,
297,
283,
5899,
659,
2079,
2053,
534,
5899,
63,
1360,
63,
694,
297,
2079,
8214,
534,
3022,
297,
2079,
1720,
534,
24391,
4163,
11745,
2556,
315,
2935,
358,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
16896,
401,
1595,
628,
1617,
63,
2052,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
24776,
654,
659,
2079,
2053,
628,
5899,
63,
16896,
401,
2079,
1720,
628,
7826,
5246,
11745,
315,
11745,
3622,
298,
2079,
7369,
2826,
899,
63,
19052,
63,
24776,
654,
12523,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
1652,
401,
1595,
628,
1617,
63,
2052,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
4317,
659,
2079,
2053,
628,
5899,
63,
1652,
401,
2079,
1720,
628,
24391,
4692,
11745,
2556,
531,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
1652,
13,
493,
401,
1595,
628,
1617,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
4317,
63,
3817,
297,
283,
10828,
14,
1652,
659,
2079,
2053,
628,
5899,
63,
1652,
63,
493,
401,
2079,
8214,
628,
3817,
401,
2079,
1720,
628,
24391,
4692,
11745,
2556,
315,
570,
531,
339,
347,
7908,
8,
277,
12,
1511,
12,
3743,
304,
267,
408,
267,
15453,
3589,
14,
267,
408,
267,
862,
26,
288,
291,
14,
1205,
14,
1935,
360,
2682,
358,
267,
871,
4067,
26,
288,
986,
267,
1613,
8,
27444,
12,
291,
680,
6472,
8,
1419,
12,
3743,
9,
267,
340,
291,
14,
3827,
26,
288,
862,
26,
355,
492,
11745,
355,
340,
440,
2688,
8,
10828,
12,
283,
10828,
735,
490,
746,
3545,
480,
6005,
370,
492,
11745,
859,
531,
288,
871,
3545,
26,
355,
943,
14,
705,
480,
27444,
440,
2808,
26,
298,
2079,
298,
17200,
370,
492,
11745,
859,
531,
355,
291
] |
[
3917,
1265,
1172,
653,
379,
17206,
352,
424,
1159,
11745,
63,
859,
4903,
12,
1265,
1443,
15422,
282,
199,
10828,
3622,
543,
314,
1124,
306,
1045,
13,
10828,
1040,
6258,
503,
4825,
899,
63,
9139,
63,
19052,
2962,
199,
5418,
1750,
14,
710,
11745,
3622,
911,
8486,
1263,
2366,
1350,
859,
199,
17932,
2410,
314,
1343,
402,
314,
511,
1255,
12,
28529,
4621,
626,
1336,
199,
396,
4486,
14,
982,
1265,
2934,
370,
2387,
5204,
4621,
4634,
12,
675,
314,
1124,
306,
5899,
13,
2219,
1040,
199,
5656,
12,
503,
663,
314,
4825,
899,
63,
19052,
63,
7569,
3734,
1750,
370,
282,
2549,
574,
14,
4005,
199,
22188,
314,
11745,
3622,
370,
4621,
687,
282,
6770,
2559,
503,
6117,
12,
199,
1180,
314,
1124,
306,
5899,
13,
2491,
1040,
6258,
503,
314,
4825,
899,
63,
19052,
63,
19265,
3734,
199,
1975,
14,
199,
199,
703,
485,
10828,
26,
1455,
921,
1544,
14,
7439,
2912,
352,
424,
14,
957,
15,
600,
15,
3112,
15,
10828,
14,
1360,
199,
624,
199,
646,
2050,
199,
646,
295,
199,
646,
984,
199,
646,
5228,
199,
504,
11354,
14,
5265,
14,
1095,
492,
11349,
199,
504,
11354,
14,
1974,
492,
2928,
12,
370,
513,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
1849,
3652,
8,
5061,
304,
272,
408,
272,
21904,
2409,
282,
11745,
3622,
1808,
653,
379,
17206,
352,
424,
1159,
11745,
859,
14,
272,
408,
272,
8486,
2925,
275,
756,
272,
8486,
25135,
275,
488,
272,
8486,
3244,
275,
488,
272,
8486,
29960,
275,
756,
272,
8486,
4649,
17931,
474,
275,
488,
272,
5396,
275,
1926,
272,
2004,
275,
1052,
339,
347,
1511,
8,
277,
12,
1798,
12,
2589,
304,
267,
408,
267,
2654,
1511,
370,
1414,
1004,
14,
267,
408,
267,
1613,
8,
27444,
12,
291,
680,
1419,
8,
2087,
12,
2589,
9,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
2491,
401,
1595,
628,
740,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
19265,
659,
2079,
8214,
628,
19265,
401,
2079,
2053,
628,
5899,
63,
5154,
401,
2079,
1720,
628,
497,
4768,
11745,
1072,
370,
4895,
6117,
298,
2079,
7369,
2826,
899,
63,
19052,
63,
19265,
12523,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
22087,
401,
1595,
628,
1617,
63,
2052,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
540,
8162,
659,
2079,
2053,
628,
5899,
63,
22087,
401,
2079,
1720,
628,
29960,
10889,
13736,
11745,
298,
2079,
298,
13724,
2544,
1255,
531,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
2219,
401,
1595,
628,
1617,
63,
2052,
401,
2079,
2053,
628,
5899,
63,
2219,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
7569,
659,
2079,
1720,
628,
7826,
511,
4621,
315,
11745,
3622,
298,
2079,
7369,
2826,
899,
63,
19052,
63,
7569,
12523,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
827,
13,
14200,
401,
1595,
628,
1617,
401,
2079,
2053,
628,
5899,
63,
827,
63,
14200,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
4896,
63,
4227,
17349,
2962,
659,
2079,
1720,
628,
12092,
16327,
402,
11745,
367,
2295,
298,
2079,
298,
475,
986,
359,
2826,
899,
63,
19052,
63,
4896,
63,
4227,
17349,
2962,
12523,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
26062,
401,
1595,
628,
1617,
63,
2052,
401,
2079,
2053,
628,
5899,
63,
26062,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
568,
1981,
1668,
5399,
659,
2079,
1720,
628,
7826,
1006,
2366,
1584,
1334,
6449,
298,
2079,
298,
3619,
315,
11745,
3622,
14,
221,
18491,
367,
298,
2079,
298,
18861,
316,
2636,
2978,
315,
511,
11745,
340,
440,
1006,
298,
2079,
298,
1725,
787,
8439,
701,
314,
511,
5241,
14,
298,
2079,
7369,
2826,
899,
63,
19052,
63,
568,
1981,
1668,
5399,
12523,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
1360,
401,
1595,
628,
1617,
63,
2052,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
4943,
659,
2079,
2053,
534,
5899,
63,
1360,
297,
2079,
1720,
628,
24391,
4163,
11745,
2556,
531,
267,
1798,
14,
525,
63,
1422,
4517,
5899,
13,
1360,
13,
694,
297,
1595,
534,
1617,
297,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
4943,
63,
3022,
297,
283,
5899,
659,
2079,
2053,
534,
5899,
63,
1360,
63,
694,
297,
2079,
8214,
534,
3022,
297,
2079,
1720,
534,
24391,
4163,
11745,
2556,
315,
2935,
358,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
16896,
401,
1595,
628,
1617,
63,
2052,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
24776,
654,
659,
2079,
2053,
628,
5899,
63,
16896,
401,
2079,
1720,
628,
7826,
5246,
11745,
315,
11745,
3622,
298,
2079,
7369,
2826,
899,
63,
19052,
63,
24776,
654,
12523,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
1652,
401,
1595,
628,
1617,
63,
2052,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
4317,
659,
2079,
2053,
628,
5899,
63,
1652,
401,
2079,
1720,
628,
24391,
4692,
11745,
2556,
531,
267,
1798,
14,
525,
63,
1422,
6739,
5899,
13,
1652,
13,
493,
401,
1595,
628,
1617,
401,
2079,
849,
29,
1813,
14,
362,
360,
2826,
899,
63,
19052,
63,
4317,
63,
3817,
297,
283,
10828,
14,
1652,
659,
2079,
2053,
628,
5899,
63,
1652,
63,
493,
401,
2079,
8214,
628,
3817,
401,
2079,
1720,
628,
24391,
4692,
11745,
2556,
315,
570,
531,
339,
347,
7908,
8,
277,
12,
1511,
12,
3743,
304,
267,
408,
267,
15453,
3589,
14,
267,
408,
267,
862,
26,
288,
291,
14,
1205,
14,
1935,
360,
2682,
358,
267,
871,
4067,
26,
288,
986,
267,
1613,
8,
27444,
12,
291,
680,
6472,
8,
1419,
12,
3743,
9,
267,
340,
291,
14,
3827,
26,
288,
862,
26,
355,
492,
11745,
355,
340,
440,
2688,
8,
10828,
12,
283,
10828,
735,
490,
746,
3545,
480,
6005,
370,
492,
11745,
859,
531,
288,
871,
3545,
26,
355,
943,
14,
705,
480,
27444,
440,
2808,
26,
298,
2079,
298,
17200,
370,
492,
11745,
859,
531,
355,
291,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
inovtec-solutions/OpenERP
|
openerp/addons/point_of_sale/report/pos_details_summary.py
|
22
|
5615
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
from openerp.report import report_sxw
class pos_details_summary(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(pos_details_summary, self).__init__(cr, uid, name, context=context)
self.total = 0.0
self.localcontext.update({
'time': time,
'strip_name': self._strip_name,
'getpayments': self._get_payments,
'getqtytotal': self._get_qty_total,
'getsumdisc': self._get_sum_discount,
'getpaidtotal': self._paid_total,
'gettotalofthaday': self._total_of_the_day,
'getsuminvoice': self._sum_invoice,
'gettaxamount': self._get_tax_amount,
'getsalestotal': self._get_sales_total,
'getstartperiod': self._get_start_period,
'getendperiod': self._get_end_period,
'getcompany':self.get_company
})
def get_company(self, objects):
comp=[obj.company_id.name for obj in objects]
return '%s' % (comp[0])
def _get_qty_total(self, objects):
#code for the sum of qty_total
return reduce(lambda acc, object:
acc + reduce(
lambda sum_qty, line:
sum_qty + line.qty,
object.lines,
0 ),
objects,
0)
def _get_sum_discount(self, objects):
#code for the sum of discount value
return reduce(lambda acc, object:
acc + reduce(
lambda sum_dis, line:
sum_dis + ((line.price_unit * line.qty ) * (line.discount / 100)),
object.lines,
0.0),
objects,
0.0 )
def _get_payments(self, objects):
result = {}
for obj in objects:
for statement in obj.statement_ids:
if statement.journal_id:
result[statement.journal_id] = result.get(statement.journal_id, 0.0) + statement.amount
return result
def _paid_total(self, objects):
return sum(self._get_payments(objects).values(), 0.0)
def _total_of_the_day(self, objects):
total_paid = self._paid_total(objects)
total_invoiced = self._sum_invoice(objects)
return total_paid - total_invoiced
def _sum_invoice(self, objects):
return reduce(lambda acc, obj:
acc + obj.invoice_id.amount_total,
[o for o in objects if o.invoice_id and o.invoice_id.number],
0.0)
def _ellipsis(self, string, maxlen=100, ellipsis = '...'):
ellipsis = ellipsis or ''
return string[:maxlen - len(ellipsis) ] + (ellipsis, '')[len(string) < maxlen]
def _strip_name(self, name, maxlen=50):
return self._ellipsis(name, maxlen, ' ...')
def _get_tax_amount(self, objects):
res = {}
list_ids = []
for order in objects:
for line in order.lines:
if len(line.product_id.taxes_id):
tax = line.product_id.taxes_id[0]
res[tax.name] = (line.price_unit * line.qty * (1-(line.discount or 0.0) / 100.0)) + (tax.id in list_ids and res[tax.name] or 0)
list_ids.append(tax.id)
return res
def _get_sales_total(self, objects):
return reduce(lambda x, o: x + len(o.lines), objects, 0)
def _get_start_period(self, objects):
date_orders = sorted([obj.date_order for obj in objects])
min_date = date_orders[0]
return '%s' % min_date
def _get_end_period(self, objects):
date_orders = sorted([obj.date_order for obj in objects])
max_date = date_orders[-1]
return '%s' % max_date
report_sxw.report_sxw('report.pos.details_summary',
'pos.order',
'addons/point_of_sale/report/pos_details_summary.rml',
parser=pos_details_summary,
header='internal')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
504,
5166,
14,
3070,
492,
3622,
63,
20851,
199,
199,
533,
2086,
63,
5087,
63,
4705,
8,
3070,
63,
20851,
14,
16300,
63,
1122,
304,
272,
347,
636,
826,
721,
277,
12,
2467,
12,
1747,
12,
536,
12,
1067,
304,
267,
1613,
8,
1712,
63,
5087,
63,
4705,
12,
291,
2843,
826,
721,
1556,
12,
1747,
12,
536,
12,
1067,
29,
1100,
9,
267,
291,
14,
2923,
275,
378,
14,
16,
267,
291,
14,
17886,
14,
873,
2561,
288,
283,
521,
356,
900,
12,
288,
283,
1913,
63,
354,
356,
291,
423,
1913,
63,
354,
12,
288,
283,
362,
31432,
356,
291,
423,
362,
63,
31432,
12,
288,
283,
362,
5643,
2923,
356,
291,
423,
362,
63,
5643,
63,
2923,
12,
288,
283,
362,
1838,
6409,
356,
291,
423,
362,
63,
1838,
63,
15446,
12,
288,
283,
362,
16555,
2923,
356,
291,
423,
16555,
63,
2923,
12,
288,
283,
362,
2923,
1618,
273,
350,
1187,
356,
291,
423,
2923,
63,
1618,
63,
1589,
63,
2977,
12,
288,
283,
362,
1838,
5404,
356,
291,
423,
1838,
63,
5404,
12,
288,
283,
362,
5530,
4606,
356,
291,
423,
362,
63,
5530,
63,
4606,
12,
288,
283,
362,
8515,
270,
1735,
356,
291,
423,
362,
63,
16175,
63,
2923,
12,
288,
283,
362,
928,
5191,
356,
291,
423,
362,
63,
928,
63,
5191,
12,
288,
283,
303,
7169,
5191,
356,
291,
423,
362,
63,
500,
63,
5191,
12,
288,
283,
362,
4627,
356,
277,
14,
362,
63,
4627,
267,
3828,
339,
347,
664,
63,
4627,
8,
277,
12,
2251,
304,
267,
1013,
1524,
1113,
14,
4627,
63,
344,
14,
354,
367,
1559,
315,
2251,
61,
267,
372,
1543,
83,
7,
450,
334,
863,
59,
16,
566,
339,
347,
485,
362,
63,
5643,
63,
2923,
8,
277,
12,
2251,
304,
267,
327,
600,
367,
314,
3089,
402,
13556,
63,
2923,
267,
372,
7114,
8,
2734,
6907,
12,
909,
26,
3147,
6907,
435,
7114,
8,
6059,
2400,
3089,
63,
5643,
12,
1004,
26,
9144,
3089,
63,
5643,
435,
1004,
14,
5643,
12,
6059,
909,
14,
1278,
12,
6059,
378,
2318,
2511,
2251,
12,
2511,
378,
9,
339,
347,
485,
362,
63,
1838,
63,
15446,
8,
277,
12,
2251,
304,
267,
327,
600,
367,
314,
3089,
402,
25309,
574,
267,
372,
7114,
8,
2734,
6907,
12,
909,
26,
3147,
6907,
435,
7114,
8,
6059,
2400,
3089,
63,
2297,
12,
1004,
26,
9144,
3089,
63,
2297,
435,
3666,
604,
14,
4777,
63,
3248,
627,
1004,
14,
5643,
776,
627,
334,
604,
14,
15446,
1182,
2948,
1826,
6059,
909,
14,
1278,
12,
6059,
378,
14,
16,
395,
2511,
2251,
12,
2511,
378,
14,
16,
776,
339,
347,
485,
362,
63,
31432,
8,
277,
12,
2251,
304,
267,
754,
275,
1052,
267,
367,
1559,
315,
2251,
26,
288,
367,
5164,
315,
1559,
14,
6242,
63,
1580,
26,
355,
340,
5164,
14,
7067,
63,
344,
26,
490,
754,
59,
6242,
14,
7067,
63,
344,
61,
275,
754,
14,
362,
8,
6242,
14,
7067,
63,
344,
12,
378,
14,
16,
9,
435,
5164,
14,
4606,
267,
372,
754,
339,
347,
485,
16555,
63,
2923,
8,
277,
12,
2251,
304,
267,
372,
3089,
8,
277,
423,
362,
63,
31432,
8,
1462,
680,
1459,
1062,
378,
14,
16,
9,
339,
347,
485,
2923,
63,
1618,
63,
1589,
63,
2977,
8,
277,
12,
2251,
304,
267,
3141,
63,
16555,
275,
291,
423,
16555,
63,
2923,
8,
1462,
9,
267,
3141,
63,
25614,
275,
291,
423,
1838,
63,
5404,
8,
1462,
9,
267,
372,
3141,
63,
16555,
446,
3141,
63,
25614,
339,
347,
485,
1838,
63,
5404,
8,
277,
12,
2251,
304,
267,
372,
7114,
8,
2734,
6907,
12,
1559,
26,
6059,
6907,
435,
1559,
14,
5404,
63,
344,
14,
4606,
63,
2923,
12,
2511,
359,
79,
367,
312,
315,
2251,
340,
312,
14,
5404,
63,
344,
436,
312,
14,
5404,
63,
344,
14,
1955,
467,
2511,
378,
14,
16,
9,
339,
347,
485,
16514,
2316,
8,
277,
12,
1059,
12,
21037,
29,
1960,
12,
32696,
275,
24352,
735,
267,
32696,
275,
32696,
503,
2125,
267,
372,
1059,
1491,
29078,
446,
822,
8,
16514,
2316,
9,
1622,
435,
334,
16514,
2316,
12,
4074,
59,
552,
8,
875,
9,
665,
21037,
61,
339,
347,
485,
1913,
63,
354,
8,
277,
12,
536,
12,
21037,
29,
1400,
304,
267,
372,
291,
423,
16514,
2316,
8,
354,
12,
21037,
12,
283,
2263,
358,
339,
347,
485,
362,
63,
5530,
63,
4606,
8,
277,
12,
2251,
304,
267,
522,
275,
1052,
267,
769,
63,
1580,
275,
942,
267,
367,
1865,
315,
2251,
26,
288,
367,
1004,
315,
1865,
14,
1278,
26,
355,
340,
822,
8,
604,
14,
2558,
63,
344,
14,
22272,
63,
344,
304,
490,
9067,
275,
1004,
14,
2558,
63,
344,
14,
22272,
63,
344,
59,
16,
61,
490,
522,
59,
5530,
14,
354,
61,
275,
334,
604,
14,
4777,
63,
3248,
627,
1004,
14,
5643,
627,
334
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
504,
5166,
14,
3070,
492,
3622,
63,
20851,
199,
199,
533,
2086,
63,
5087,
63,
4705,
8,
3070,
63,
20851,
14,
16300,
63,
1122,
304,
272,
347,
636,
826,
721,
277,
12,
2467,
12,
1747,
12,
536,
12,
1067,
304,
267,
1613,
8,
1712,
63,
5087,
63,
4705,
12,
291,
2843,
826,
721,
1556,
12,
1747,
12,
536,
12,
1067,
29,
1100,
9,
267,
291,
14,
2923,
275,
378,
14,
16,
267,
291,
14,
17886,
14,
873,
2561,
288,
283,
521,
356,
900,
12,
288,
283,
1913,
63,
354,
356,
291,
423,
1913,
63,
354,
12,
288,
283,
362,
31432,
356,
291,
423,
362,
63,
31432,
12,
288,
283,
362,
5643,
2923,
356,
291,
423,
362,
63,
5643,
63,
2923,
12,
288,
283,
362,
1838,
6409,
356,
291,
423,
362,
63,
1838,
63,
15446,
12,
288,
283,
362,
16555,
2923,
356,
291,
423,
16555,
63,
2923,
12,
288,
283,
362,
2923,
1618,
273,
350,
1187,
356,
291,
423,
2923,
63,
1618,
63,
1589,
63,
2977,
12,
288,
283,
362,
1838,
5404,
356,
291,
423,
1838,
63,
5404,
12,
288,
283,
362,
5530,
4606,
356,
291,
423,
362,
63,
5530,
63,
4606,
12,
288,
283,
362,
8515,
270,
1735,
356,
291,
423,
362,
63,
16175,
63,
2923,
12,
288,
283,
362,
928,
5191,
356,
291,
423,
362,
63,
928,
63,
5191,
12,
288,
283,
303,
7169,
5191,
356,
291,
423,
362,
63,
500,
63,
5191,
12,
288,
283,
362,
4627,
356,
277,
14,
362,
63,
4627,
267,
3828,
339,
347,
664,
63,
4627,
8,
277,
12,
2251,
304,
267,
1013,
1524,
1113,
14,
4627,
63,
344,
14,
354,
367,
1559,
315,
2251,
61,
267,
372,
1543,
83,
7,
450,
334,
863,
59,
16,
566,
339,
347,
485,
362,
63,
5643,
63,
2923,
8,
277,
12,
2251,
304,
267,
327,
600,
367,
314,
3089,
402,
13556,
63,
2923,
267,
372,
7114,
8,
2734,
6907,
12,
909,
26,
3147,
6907,
435,
7114,
8,
6059,
2400,
3089,
63,
5643,
12,
1004,
26,
9144,
3089,
63,
5643,
435,
1004,
14,
5643,
12,
6059,
909,
14,
1278,
12,
6059,
378,
2318,
2511,
2251,
12,
2511,
378,
9,
339,
347,
485,
362,
63,
1838,
63,
15446,
8,
277,
12,
2251,
304,
267,
327,
600,
367,
314,
3089,
402,
25309,
574,
267,
372,
7114,
8,
2734,
6907,
12,
909,
26,
3147,
6907,
435,
7114,
8,
6059,
2400,
3089,
63,
2297,
12,
1004,
26,
9144,
3089,
63,
2297,
435,
3666,
604,
14,
4777,
63,
3248,
627,
1004,
14,
5643,
776,
627,
334,
604,
14,
15446,
1182,
2948,
1826,
6059,
909,
14,
1278,
12,
6059,
378,
14,
16,
395,
2511,
2251,
12,
2511,
378,
14,
16,
776,
339,
347,
485,
362,
63,
31432,
8,
277,
12,
2251,
304,
267,
754,
275,
1052,
267,
367,
1559,
315,
2251,
26,
288,
367,
5164,
315,
1559,
14,
6242,
63,
1580,
26,
355,
340,
5164,
14,
7067,
63,
344,
26,
490,
754,
59,
6242,
14,
7067,
63,
344,
61,
275,
754,
14,
362,
8,
6242,
14,
7067,
63,
344,
12,
378,
14,
16,
9,
435,
5164,
14,
4606,
267,
372,
754,
339,
347,
485,
16555,
63,
2923,
8,
277,
12,
2251,
304,
267,
372,
3089,
8,
277,
423,
362,
63,
31432,
8,
1462,
680,
1459,
1062,
378,
14,
16,
9,
339,
347,
485,
2923,
63,
1618,
63,
1589,
63,
2977,
8,
277,
12,
2251,
304,
267,
3141,
63,
16555,
275,
291,
423,
16555,
63,
2923,
8,
1462,
9,
267,
3141,
63,
25614,
275,
291,
423,
1838,
63,
5404,
8,
1462,
9,
267,
372,
3141,
63,
16555,
446,
3141,
63,
25614,
339,
347,
485,
1838,
63,
5404,
8,
277,
12,
2251,
304,
267,
372,
7114,
8,
2734,
6907,
12,
1559,
26,
6059,
6907,
435,
1559,
14,
5404,
63,
344,
14,
4606,
63,
2923,
12,
2511,
359,
79,
367,
312,
315,
2251,
340,
312,
14,
5404,
63,
344,
436,
312,
14,
5404,
63,
344,
14,
1955,
467,
2511,
378,
14,
16,
9,
339,
347,
485,
16514,
2316,
8,
277,
12,
1059,
12,
21037,
29,
1960,
12,
32696,
275,
24352,
735,
267,
32696,
275,
32696,
503,
2125,
267,
372,
1059,
1491,
29078,
446,
822,
8,
16514,
2316,
9,
1622,
435,
334,
16514,
2316,
12,
4074,
59,
552,
8,
875,
9,
665,
21037,
61,
339,
347,
485,
1913,
63,
354,
8,
277,
12,
536,
12,
21037,
29,
1400,
304,
267,
372,
291,
423,
16514,
2316,
8,
354,
12,
21037,
12,
283,
2263,
358,
339,
347,
485,
362,
63,
5530,
63,
4606,
8,
277,
12,
2251,
304,
267,
522,
275,
1052,
267,
769,
63,
1580,
275,
942,
267,
367,
1865,
315,
2251,
26,
288,
367,
1004,
315,
1865,
14,
1278,
26,
355,
340,
822,
8,
604,
14,
2558,
63,
344,
14,
22272,
63,
344,
304,
490,
9067,
275,
1004,
14,
2558,
63,
344,
14,
22272,
63,
344,
59,
16,
61,
490,
522,
59,
5530,
14,
354,
61,
275,
334,
604,
14,
4777,
63,
3248,
627,
1004,
14,
5643,
627,
334,
0
] |
[
1,
1,
1,
1,
1,
1,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loaders/CANON/stellas_loadsep2013.py
|
5
|
2830
|
#!/usr/bin/env python
__author__ = 'Mike McCann,Duane Edgington,Reiko Michisaki'
__copyright__ = '2013'
__license__ = 'GPL v3'
__contact__ = 'duane at mbari.org'
__doc__ = '''
Stella loader for all CANON activities in September 2013
Mike McCann; Modified by Duane Edgington and Reiko Michisaki
MBARI 02 September 2013
@var __date__: Date of last svn commit
@undocumented: __doc__ parser
@status: production
@license: GPL
'''
import os
import sys
import datetime # needed for glider data
import time # for startdate, enddate args
os.environ['DJANGO_SETTINGS_MODULE']='settings'
project_dir = os.path.dirname(__file__)
# the next line makes it possible to find CANON
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../")) # this makes it possible to find CANON, one directory up
from CANON import CANONLoader
# building input data sources object
from socket import gethostname
hostname=gethostname()
print hostname
if hostname=='odss-test.shore.mbari.org':
cl = CANONLoader('stoqs_september2011', 'CANON - September 2011')
else:
cl = CANONLoader('stoqs_september2013', 'CANON - September 2013')
# default location of thredds and dods data:
cl.tdsBase = 'http://odss.mbari.org/thredds/'
cl.dodsBase = cl.tdsBase + 'dodsC/'
######################################################################
# GLIDERS
######################################################################
# Set start and end dates for all glider loads
# startdate is 24hours from now
ts=time.time()-(2.2*60*60)
st=datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M')
t=time.strptime(st,"%Y-%m-%d %H:%M")
#t =time.strptime("2013-09-05 0:01", "%Y-%m-%d %H:%M")
startdate=t[:6]
t =time.strptime("2013-10-15 0:01", "%Y-%m-%d %H:%M")
enddate=t[:6]
#######################################################################################
# DRIFTERS
#######################################################################################
# Stella 203
cl.stella203_base = cl.dodsBase + 'CANON_september2013/Platforms/Drifters/Stella_1/'
cl.stella203_parms = [ 'TEMP', 'pH' ]
cl.stella203_files = [
'stella203_data.nc',
]
# Stella 204
cl.stella204_base = cl.dodsBase + 'CANON_september2013/Platforms/Drifters/Stella_1/'
cl.stella204_parms = [ 'TEMP', 'pH' ]
cl.stella204_files = [
'stella204_data.nc',
]
###################################################################################################################
# Execute the load
cl.process_command_line()
if cl.args.test:
cl.loadStella203(stride=1)
cl.loadStella204(stride=1)
elif cl.args.optimal_stride:
cl.loadStella203(stride=1)
cl.loadStella204(stride=1)
else:
cl.loadStella203(stride=1)
cl.loadStella204(stride=1)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
363,
2502,
363,
259,
275,
283,
45,
7455,
22895,
35,
1189,
12,
36,
85,
5865,
17379,
1540,
1860,
12,
497,
16625,
603,
1158,
374,
27387,
7,
199,
363,
7307,
363,
275,
283,
6965,
7,
199,
363,
1682,
363,
257,
275,
283,
12006,
373,
19,
7,
199,
363,
7811,
363,
257,
275,
283,
2033,
5865,
737,
21187,
759,
14,
1308,
7,
199,
199,
363,
1301,
363,
275,
1449,
199,
199,
51,
14146,
416,
5077,
367,
1006,
29661,
615,
30744,
315,
428,
1545,
31575,
6171,
199,
199,
45,
7455,
22895,
35,
1189,
27,
22016,
701,
577,
85,
5865,
17379,
1540,
1860,
436,
799,
16625,
603,
1158,
374,
27387,
199,
4567,
689,
41,
12497,
428,
1545,
31575,
6171,
199,
199,
32,
1391,
636,
602,
10651,
6148,
402,
2061,
11327,
5532,
199,
32,
30107,
12546,
26,
636,
1301,
363,
1798,
199,
32,
1205,
26,
9920,
199,
32,
1682,
26,
14629,
199,
2344,
199,
199,
646,
747,
199,
646,
984,
199,
646,
2197,
221,
327,
4346,
367,
486,
11306,
666,
199,
646,
900,
420,
327,
367,
1343,
602,
12,
1284,
602,
1249,
199,
736,
14,
2314,
459,
22848,
63,
13931,
63,
10001,
32373,
1751,
7,
199,
1715,
63,
694,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
199,
3,
314,
2163,
1004,
7704,
652,
3962,
370,
2342,
29661,
615,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
29024,
2237,
221,
327,
642,
7704,
652,
3962,
370,
2342,
29661,
615,
12,
1373,
2082,
1536,
199,
199,
504,
29661,
615,
492,
29661,
615,
5455,
267,
199,
3,
10015,
1324,
666,
5274,
909,
199,
504,
2838,
492,
2312,
15157,
354,
199,
4269,
29,
29789,
342,
199,
1361,
6246,
199,
692,
6246,
6803,
364,
385,
13,
396,
14,
13927,
264,
14,
887,
759,
14,
1308,
356,
272,
824,
275,
29661,
615,
5455,
360,
14308,
6177,
63,
4127,
31575,
8128,
297,
283,
18988,
615,
446,
428,
1545,
31575,
7760,
358,
199,
2836,
26,
272,
824,
275,
29661,
615,
5455,
360,
14308,
6177,
63,
4127,
31575,
6965,
297,
283,
18988,
615,
446,
428,
1545,
31575,
6171,
358,
199,
199,
3,
849,
2909,
402,
294,
581,
795,
436,
366,
364,
83,
666,
26,
199,
429,
14,
84,
795,
1563,
275,
283,
1014,
921,
364,
385,
14,
887,
759,
14,
1308,
15,
273,
581,
795,
4805,
199,
429,
14,
68,
364,
83,
1563,
275,
824,
14,
84,
795,
1563,
435,
283,
68,
364,
83,
35,
4805,
421,
199,
18022,
199,
3,
221,
3563,
998,
3960,
199,
18022,
199,
3,
2494,
1343,
436,
1284,
10831,
367,
1006,
486,
11306,
14404,
199,
3,
1343,
602,
365,
5504,
8419,
687,
3063,
199,
1086,
29,
521,
14,
521,
342,
15426,
18,
14,
18,
10,
2259,
10,
2259,
9,
257,
199,
270,
29,
2083,
14,
2083,
14,
18531,
8,
1086,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
358,
199,
84,
29,
521,
14,
9866,
8,
270,
4589,
5,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
531,
199,
3,
84,
275,
521,
14,
9866,
480,
6965,
13,
1643,
13,
1717,
378,
26,
614,
401,
2071,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
531,
199,
928,
602,
29,
84,
1491,
22,
61,
199,
84,
275,
521,
14,
9866,
480,
6965,
13,
709,
13,
1046,
378,
26,
614,
401,
2071,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
531,
199,
500,
602,
29,
84,
1491,
22,
61,
819,
199,
13289,
14776,
199,
3,
577,
50,
4656,
1157,
51,
199,
13289,
14776,
199,
199,
3,
428,
14146,
416,
29202,
199,
429,
14,
30721,
416,
11341,
63,
1095,
275,
824,
14,
68,
364,
83,
1563,
435,
283,
18988,
615,
63,
4127,
31575,
6965,
15,
3714,
8560,
15,
36,
20546,
878,
15,
51,
14146,
416,
63,
17,
4805,
199,
429,
14,
30721,
416,
11341,
63,
28899,
275,
359,
283,
12510,
297,
283,
80,
40,
7,
1622,
199,
429,
14,
30721,
416,
11341,
63,
1725,
275,
359,
12723,
283,
30721,
416,
11341,
63,
576,
14,
7966,
297,
1993,
1622,
199,
199,
3,
428,
14146,
416,
14785,
199,
429,
14,
30721,
416,
6686,
63,
1095,
275,
824,
14,
68,
364,
83,
1563,
435,
283,
18988,
615,
63,
4127,
31575,
6965,
15,
3714,
8560,
15,
36,
20546,
878,
15,
51,
14146,
416,
63,
17,
4805,
199,
429,
14,
30721,
416,
6686,
63,
28899,
275,
359,
283,
12510,
297,
283,
80,
40,
7,
1622,
199,
429,
14,
30721,
416,
6686,
63,
1725,
275,
359,
12723,
283,
30721,
416,
6686,
63,
576,
14,
7966,
297,
1993,
1622,
421,
199,
3060,
22529,
5680,
199,
3,
17009,
314,
2248,
199,
429,
14,
1412,
63,
1531,
63,
604,
342,
199,
199,
692,
824,
14,
589,
14,
396,
26,
272,
824,
14,
912,
51,
14146,
416,
11341,
8,
12318,
29,
17,
9,
272,
824,
14,
912,
51,
14146,
416,
6686,
8,
12318,
29,
17,
9,
199,
199,
4164,
824,
14,
589,
14,
411,
16757,
63,
12318,
26,
272,
824,
14,
912,
51,
14146,
416,
11341,
8,
12318,
29,
17,
9,
272,
824,
14,
912,
51,
14146,
416,
6686,
8,
12318,
29,
17,
9,
199,
199,
2836,
26,
272,
824,
14,
912,
51,
14146,
416,
11341,
8,
12318,
29,
17,
9,
272,
824,
14,
912,
51,
14146,
416,
6686,
8,
12318,
29,
17,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
363,
2502,
363,
259,
275,
283,
45,
7455,
22895,
35,
1189,
12,
36,
85,
5865,
17379,
1540,
1860,
12,
497,
16625,
603,
1158,
374,
27387,
7,
199,
363,
7307,
363,
275,
283,
6965,
7,
199,
363,
1682,
363,
257,
275,
283,
12006,
373,
19,
7,
199,
363,
7811,
363,
257,
275,
283,
2033,
5865,
737,
21187,
759,
14,
1308,
7,
199,
199,
363,
1301,
363,
275,
1449,
199,
199,
51,
14146,
416,
5077,
367,
1006,
29661,
615,
30744,
315,
428,
1545,
31575,
6171,
199,
199,
45,
7455,
22895,
35,
1189,
27,
22016,
701,
577,
85,
5865,
17379,
1540,
1860,
436,
799,
16625,
603,
1158,
374,
27387,
199,
4567,
689,
41,
12497,
428,
1545,
31575,
6171,
199,
199,
32,
1391,
636,
602,
10651,
6148,
402,
2061,
11327,
5532,
199,
32,
30107,
12546,
26,
636,
1301,
363,
1798,
199,
32,
1205,
26,
9920,
199,
32,
1682,
26,
14629,
199,
2344,
199,
199,
646,
747,
199,
646,
984,
199,
646,
2197,
221,
327,
4346,
367,
486,
11306,
666,
199,
646,
900,
420,
327,
367,
1343,
602,
12,
1284,
602,
1249,
199,
736,
14,
2314,
459,
22848,
63,
13931,
63,
10001,
32373,
1751,
7,
199,
1715,
63,
694,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
199,
3,
314,
2163,
1004,
7704,
652,
3962,
370,
2342,
29661,
615,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
29024,
2237,
221,
327,
642,
7704,
652,
3962,
370,
2342,
29661,
615,
12,
1373,
2082,
1536,
199,
199,
504,
29661,
615,
492,
29661,
615,
5455,
267,
199,
3,
10015,
1324,
666,
5274,
909,
199,
504,
2838,
492,
2312,
15157,
354,
199,
4269,
29,
29789,
342,
199,
1361,
6246,
199,
692,
6246,
6803,
364,
385,
13,
396,
14,
13927,
264,
14,
887,
759,
14,
1308,
356,
272,
824,
275,
29661,
615,
5455,
360,
14308,
6177,
63,
4127,
31575,
8128,
297,
283,
18988,
615,
446,
428,
1545,
31575,
7760,
358,
199,
2836,
26,
272,
824,
275,
29661,
615,
5455,
360,
14308,
6177,
63,
4127,
31575,
6965,
297,
283,
18988,
615,
446,
428,
1545,
31575,
6171,
358,
199,
199,
3,
849,
2909,
402,
294,
581,
795,
436,
366,
364,
83,
666,
26,
199,
429,
14,
84,
795,
1563,
275,
283,
1014,
921,
364,
385,
14,
887,
759,
14,
1308,
15,
273,
581,
795,
4805,
199,
429,
14,
68,
364,
83,
1563,
275,
824,
14,
84,
795,
1563,
435,
283,
68,
364,
83,
35,
4805,
421,
199,
18022,
199,
3,
221,
3563,
998,
3960,
199,
18022,
199,
3,
2494,
1343,
436,
1284,
10831,
367,
1006,
486,
11306,
14404,
199,
3,
1343,
602,
365,
5504,
8419,
687,
3063,
199,
1086,
29,
521,
14,
521,
342,
15426,
18,
14,
18,
10,
2259,
10,
2259,
9,
257,
199,
270,
29,
2083,
14,
2083,
14,
18531,
8,
1086,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
358,
199,
84,
29,
521,
14,
9866,
8,
270,
4589,
5,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
531,
199,
3,
84,
275,
521,
14,
9866,
480,
6965,
13,
1643,
13,
1717,
378,
26,
614,
401,
2071,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
531,
199,
928,
602,
29,
84,
1491,
22,
61,
199,
84,
275,
521,
14,
9866,
480,
6965,
13,
709,
13,
1046,
378,
26,
614,
401,
2071,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
531,
199,
500,
602,
29,
84,
1491,
22,
61,
819,
199,
13289,
14776,
199,
3,
577,
50,
4656,
1157,
51,
199,
13289,
14776,
199,
199,
3,
428,
14146,
416,
29202,
199,
429,
14,
30721,
416,
11341,
63,
1095,
275,
824,
14,
68,
364,
83,
1563,
435,
283,
18988,
615,
63,
4127,
31575,
6965,
15,
3714,
8560,
15,
36,
20546,
878,
15,
51,
14146,
416,
63,
17,
4805,
199,
429,
14,
30721,
416,
11341,
63,
28899,
275,
359,
283,
12510,
297,
283,
80,
40,
7,
1622,
199,
429,
14,
30721,
416,
11341,
63,
1725,
275,
359,
12723,
283,
30721,
416,
11341,
63,
576,
14,
7966,
297,
1993,
1622,
199,
199,
3,
428,
14146,
416,
14785,
199,
429,
14,
30721,
416,
6686,
63,
1095,
275,
824,
14,
68,
364,
83,
1563,
435,
283,
18988,
615,
63,
4127,
31575,
6965,
15,
3714,
8560,
15,
36,
20546,
878,
15,
51,
14146,
416,
63,
17,
4805,
199,
429,
14,
30721,
416,
6686,
63,
28899,
275,
359,
283,
12510,
297,
283,
80,
40,
7,
1622,
199,
429,
14,
30721,
416,
6686,
63,
1725,
275,
359,
12723,
283,
30721,
416,
6686,
63,
576,
14,
7966,
297,
1993,
1622,
421,
199,
3060,
22529,
5680,
199,
3,
17009,
314,
2248,
199,
429,
14,
1412,
63,
1531,
63,
604,
342,
199,
199,
692,
824,
14,
589,
14,
396,
26,
272,
824,
14,
912,
51,
14146,
416,
11341,
8,
12318,
29,
17,
9,
272,
824,
14,
912,
51,
14146,
416,
6686,
8,
12318,
29,
17,
9,
199,
199,
4164,
824,
14,
589,
14,
411,
16757,
63,
12318,
26,
272,
824,
14,
912,
51,
14146,
416,
11341,
8,
12318,
29,
17,
9,
272,
824,
14,
912,
51,
14146,
416,
6686,
8,
12318,
29,
17,
9,
199,
199,
2836,
26,
272,
824,
14,
912,
51,
14146,
416,
11341,
8,
12318,
29,
17,
9,
272,
824,
14,
912,
51,
14146,
416,
6686,
8,
12318,
29,
17,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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