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
|
|---|---|---|---|---|---|---|---|---|
pax2you4now/wesnoth
|
scons/python_devel.py
|
49
|
1381
|
# vi: syntax=python:et:ts=4
import sys, os
from config_check_utils import backup_env, restore_env
import distutils.sysconfig
def exists():
return True
def PythonExtension(env, target, source, **kv):
return env.SharedLibrary(target, source, SHLIBPREFIX='', SHLIBSUFFIX=distutils.sysconfig.get_config_var("SO"), **kv)
def generate(env):
env.AddMethod(PythonExtension)
def CheckPython(context):
env = context.env
backup = backup_env(env, ["CPPPATH", "LIBPATH", "LIBS"])
context.Message("Checking for Python... ")
env.AppendUnique(CPPPATH = distutils.sysconfig.get_python_inc())
version = distutils.sysconfig.get_config_var("VERSION")
if not version:
version = sys.version[:3]
if env["PLATFORM"] == "win32":
version = version.replace('.', '')
env.AppendUnique(LIBPATH = distutils.sysconfig.get_config_var("LIBDIR") or \
os.path.join(distutils.sysconfig.get_config_var("prefix"), "libs") )
env.AppendUnique(LIBS = "python" + version)
test_program = """
#include <Python.h>
int main()
{
Py_Initialize();
}
\n"""
if context.TryLink(test_program, ".c"):
context.Result("yes")
return True
else:
context.Result("no")
restore_env(context.env, backup)
return False
config_checks = { "CheckPython" : CheckPython }
|
gpl-2.0
|
[
3,
1321,
26,
6302,
29,
1548,
26,
386,
26,
1086,
29,
20,
199,
646,
984,
12,
747,
199,
504,
1101,
63,
1074,
63,
1208,
492,
6902,
63,
1813,
12,
9066,
63,
1813,
199,
646,
7065,
14,
24030,
199,
199,
318,
3495,
837,
272,
372,
715,
199,
199,
318,
2018,
6382,
8,
1813,
12,
1347,
12,
1350,
12,
1011,
11475,
304,
272,
372,
2589,
14,
12197,
7424,
8,
1375,
12,
1350,
12,
4410,
5617,
6351,
4581,
4410,
5617,
12273,
29,
13350,
14,
24030,
14,
362,
63,
888,
63,
1391,
480,
4118,
1288,
1011,
11475,
9,
199,
199,
318,
3550,
8,
1813,
304,
272,
2589,
14,
1123,
3767,
8,
4718,
6382,
9,
199,
199,
318,
2670,
4718,
8,
1100,
304,
272,
2589,
275,
1067,
14,
1813,
272,
6902,
275,
6902,
63,
1813,
8,
1813,
12,
2097,
14533,
3243,
401,
298,
32119,
401,
298,
25161,
3135,
272,
1067,
14,
2209,
480,
14740,
367,
2018,
1396,
6099,
272,
2589,
14,
8310,
11427,
8,
14533,
3243,
275,
7065,
14,
24030,
14,
362,
63,
1548,
63,
6559,
1012,
272,
1015,
275,
7065,
14,
24030,
14,
362,
63,
888,
63,
1391,
480,
4612,
531,
272,
340,
440,
1015,
26,
267,
1015,
275,
984,
14,
1023,
1491,
19,
61,
272,
340,
2589,
905,
17805,
937,
508,
298,
2676,
708,
582,
267,
1015,
275,
1015,
14,
1814,
14078,
4074,
272,
2589,
14,
8310,
11427,
8,
32119,
275,
7065,
14,
24030,
14,
362,
63,
888,
63,
1391,
480,
5617,
3022,
531,
503,
971,
3044,
747,
14,
515,
14,
904,
8,
13350,
14,
24030,
14,
362,
63,
888,
63,
1391,
480,
1861,
1288,
298,
8450,
531,
776,
272,
2589,
14,
8310,
11427,
8,
25161,
275,
298,
1548,
2,
435,
1015,
9,
272,
511,
63,
6815,
275,
408,
272,
327,
2613,
665,
4718,
14,
72,
30,
272,
1109,
2446,
342,
272,
469,
267,
1611,
63,
9345,
7303,
272,
789,
272,
971,
78,
624,
272,
340,
1067,
14,
12357,
3834,
8,
396,
63,
6815,
12,
3680,
67,
2349,
267,
1067,
14,
2889,
480,
5066,
531,
267,
372,
715,
272,
587,
26,
267,
1067,
14,
2889,
480,
889,
531,
267,
9066,
63,
1813,
8,
1100,
14,
1813,
12,
6902,
9,
267,
372,
756,
199,
199,
888,
63,
8625,
275,
469,
298,
1799,
4718,
2,
520,
2670,
4718,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1321,
26,
6302,
29,
1548,
26,
386,
26,
1086,
29,
20,
199,
646,
984,
12,
747,
199,
504,
1101,
63,
1074,
63,
1208,
492,
6902,
63,
1813,
12,
9066,
63,
1813,
199,
646,
7065,
14,
24030,
199,
199,
318,
3495,
837,
272,
372,
715,
199,
199,
318,
2018,
6382,
8,
1813,
12,
1347,
12,
1350,
12,
1011,
11475,
304,
272,
372,
2589,
14,
12197,
7424,
8,
1375,
12,
1350,
12,
4410,
5617,
6351,
4581,
4410,
5617,
12273,
29,
13350,
14,
24030,
14,
362,
63,
888,
63,
1391,
480,
4118,
1288,
1011,
11475,
9,
199,
199,
318,
3550,
8,
1813,
304,
272,
2589,
14,
1123,
3767,
8,
4718,
6382,
9,
199,
199,
318,
2670,
4718,
8,
1100,
304,
272,
2589,
275,
1067,
14,
1813,
272,
6902,
275,
6902,
63,
1813,
8,
1813,
12,
2097,
14533,
3243,
401,
298,
32119,
401,
298,
25161,
3135,
272,
1067,
14,
2209,
480,
14740,
367,
2018,
1396,
6099,
272,
2589,
14,
8310,
11427,
8,
14533,
3243,
275,
7065,
14,
24030,
14,
362,
63,
1548,
63,
6559,
1012,
272,
1015,
275,
7065,
14,
24030,
14,
362,
63,
888,
63,
1391,
480,
4612,
531,
272,
340,
440,
1015,
26,
267,
1015,
275,
984,
14,
1023,
1491,
19,
61,
272,
340,
2589,
905,
17805,
937,
508,
298,
2676,
708,
582,
267,
1015,
275,
1015,
14,
1814,
14078,
4074,
272,
2589,
14,
8310,
11427,
8,
32119,
275,
7065,
14,
24030,
14,
362,
63,
888,
63,
1391,
480,
5617,
3022,
531,
503,
971,
3044,
747,
14,
515,
14,
904,
8,
13350,
14,
24030,
14,
362,
63,
888,
63,
1391,
480,
1861,
1288,
298,
8450,
531,
776,
272,
2589,
14,
8310,
11427,
8,
25161,
275,
298,
1548,
2,
435,
1015,
9,
272,
511,
63,
6815,
275,
408,
272,
327,
2613,
665,
4718,
14,
72,
30,
272,
1109,
2446,
342,
272,
469,
267,
1611,
63,
9345,
7303,
272,
789,
272,
971,
78,
624,
272,
340,
1067,
14,
12357,
3834,
8,
396,
63,
6815,
12,
3680,
67,
2349,
267,
1067,
14,
2889,
480,
5066,
531,
267,
372,
715,
272,
587,
26,
267,
1067,
14,
2889,
480,
889,
531,
267,
9066,
63,
1813,
8,
1100,
14,
1813,
12,
6902,
9,
267,
372,
756,
199,
199,
888,
63,
8625,
275,
469,
298,
1799,
4718,
2,
520,
2670,
4718,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
Tocknicsu/nctuoj
|
backend/web/user.py
|
1
|
2943
|
from req import WebRequestHandler
from req import Service
import tornado
import math
class WebUsersHandler(WebRequestHandler):
@tornado.gen.coroutine
def get(self):
if self.map_power['user_manage'] not in self.account['power']:
self.write_error(403)
return
args = ["page"]
meta = self.get_args(args)
meta['count'] = 10
### default page is 1
if not meta['page']:
meta['page'] = 1
### if get page is not int then redirect to page 1
try:
meta["page"] = int(meta["page"])
except:
self.redirect('/users/')
return
### modify page in range (1, page_count)
err, count = yield from Service.User.get_user_list_count()
print(count, type(count))
page_count = max(math.ceil(count / meta['count']), 1)
if int(meta['page']) < 1:
self.redirect('/users/')
return
if int(meta['page']) > page_count:
self.redirect('/users/?page=%s'%str(page_count))
return
err, data = yield from Service.User.get_user_list(meta)
### about pagination
page = {}
page['total'] = page_count
page['current'] = meta['page']
page['url'] = '/users/'
page['get'] = {}
self.render('./users/users.html', data=data, page=page)
class WebUserHandler(WebRequestHandler):
""" single user data """
@tornado.gen.coroutine
def get(self, id=None, action=None):
if not id: id = self.account["id"]
###err, meta = yield from Service.User.get_user_advanced_info(id)
err, meta = yield from Service.User.get_user_basic_info({'id': id})
err, meta['group'] = yield from Service.User.get_user_group_info({'id': id})
if err:
self.write_error(err)
return
self.render('./users/user.html', data=meta)
class WebUserEditHandler(WebRequestHandler):
@tornado.gen.coroutine
def get(self, id):
if int(id) != self.account['id']:
self.write_error(403)
return
data = {}
err, data['schools'] = yield from Service.School.get_school_list()
self.render('./users/user_edit.html', data=data)
class WebUserSignHandler(WebRequestHandler):
@tornado.gen.coroutine
def get(self, action):
if action == "signin":
if self.account['id'] != 0:
self.redirect('/')
self.render('./users/user_signin.html')
elif action == "signout":
Service.User.signout(self)
self.redirect('/users/signin/')
elif action == "signup":
if self.account['id'] != 0:
self.redirect('/')
err, school = yield from Service.School.get_school_list()
self.render('./users/user_signup.html', school=school)
else:
self.write_error(404)
|
mit
|
[
504,
2648,
492,
6001,
11149,
199,
504,
2648,
492,
7591,
199,
646,
12148,
199,
646,
3473,
421,
199,
533,
6001,
12117,
2461,
8,
5926,
11149,
304,
272,
768,
18443,
14,
2268,
14,
16675,
272,
347,
664,
8,
277,
304,
267,
340,
291,
14,
1130,
63,
5652,
459,
751,
63,
9053,
418,
440,
315,
291,
14,
2048,
459,
5652,
2565,
288,
291,
14,
952,
63,
705,
8,
13353,
9,
288,
372,
267,
1249,
275,
2097,
1606,
937,
267,
3404,
275,
291,
14,
362,
63,
589,
8,
589,
9,
267,
3404,
459,
835,
418,
275,
1616,
267,
6754,
849,
2034,
365,
413,
267,
340,
440,
3404,
459,
1606,
2565,
288,
3404,
459,
1606,
418,
275,
413,
267,
6754,
340,
664,
2034,
365,
440,
1109,
2066,
4660,
370,
2034,
413,
4960,
862,
26,
288,
3404,
905,
1606,
937,
275,
1109,
8,
2024,
905,
1606,
3135,
267,
871,
26,
288,
291,
14,
4876,
2336,
3707,
6217,
288,
372,
267,
6754,
2811,
2034,
315,
1425,
334,
17,
12,
2034,
63,
835,
9,
267,
2329,
12,
2338,
275,
1995,
687,
7591,
14,
1899,
14,
362,
63,
751,
63,
513,
63,
835,
342,
267,
870,
8,
835,
12,
730,
8,
835,
430,
267,
2034,
63,
835,
275,
1390,
8,
3442,
14,
14085,
8,
835,
1182,
3404,
459,
835,
3815,
413,
9,
267,
340,
1109,
8,
2024,
459,
1606,
1105,
665,
413,
26,
288,
291,
14,
4876,
2336,
3707,
6217,
288,
372,
267,
340,
1109,
8,
2024,
459,
1606,
1105,
690,
2034,
63,
835,
26,
288,
291,
14,
4876,
2336,
3707,
10197,
1606,
2458,
83,
5956,
495,
8,
1606,
63,
835,
430,
288,
372,
267,
2329,
12,
666,
275,
1995,
687,
7591,
14,
1899,
14,
362,
63,
751,
63,
513,
8,
2024,
9,
267,
6754,
3595,
21192,
267,
2034,
275,
1052,
267,
2034,
459,
2923,
418,
275,
2034,
63,
835,
267,
2034,
459,
1818,
418,
275,
3404,
459,
1606,
418,
267,
2034,
459,
633,
418,
275,
1994,
3707,
4805,
267,
2034,
459,
362,
418,
275,
1052,
267,
291,
14,
3352,
17371,
3707,
15,
3707,
14,
1360,
297,
666,
29,
576,
12,
2034,
29,
1606,
9,
421,
199,
533,
6001,
1899,
2461,
8,
5926,
11149,
304,
272,
408,
2849,
922,
666,
408,
272,
768,
18443,
14,
2268,
14,
16675,
272,
347,
664,
8,
277,
12,
1305,
29,
403,
12,
1595,
29,
403,
304,
267,
340,
440,
1305,
26,
1305,
275,
291,
14,
2048,
905,
344,
937,
267,
6754,
1508,
12,
3404,
275,
1995,
687,
7591,
14,
1899,
14,
362,
63,
751,
63,
14652,
63,
815,
8,
344,
9,
267,
2329,
12,
3404,
275,
1995,
687,
7591,
14,
1899,
14,
362,
63,
751,
63,
4316,
63,
815,
3252,
344,
356,
1305,
1552,
267,
2329,
12,
3404,
459,
923,
418,
275,
1995,
687,
7591,
14,
1899,
14,
362,
63,
751,
63,
923,
63,
815,
3252,
344,
356,
1305,
1552,
267,
340,
2329,
26,
288,
291,
14,
952,
63,
705,
8,
1508,
9,
288,
372,
267,
291,
14,
3352,
17371,
3707,
15,
751,
14,
1360,
297,
666,
29,
2024,
9,
199,
199,
533,
6001,
1899,
4685,
2461,
8,
5926,
11149,
304,
272,
768,
18443,
14,
2268,
14,
16675,
272,
347,
664,
8,
277,
12,
1305,
304,
267,
340,
1109,
8,
344,
9,
1137,
291,
14,
2048,
459,
344,
2565,
288,
291,
14,
952,
63,
705,
8,
13353,
9,
288,
372,
267,
666,
275,
1052,
267,
2329,
12,
666,
459,
83,
2239,
1446,
418,
275,
1995,
687,
7591,
14,
51,
15089,
14,
362,
63,
23194,
63,
513,
342,
267,
291,
14,
3352,
17371,
3707,
15,
751,
63,
3773,
14,
1360,
297,
666,
29,
576,
9,
199,
199,
533,
6001,
1899,
4940,
2461,
8,
5926,
11149,
304,
272,
768,
18443,
14,
2268,
14,
16675,
272,
347,
664,
8,
277,
12,
1595,
304,
267,
340,
1595,
508,
298,
1037,
262,
582,
288,
340,
291,
14,
2048,
459,
344,
418,
1137,
378,
26,
355,
291,
14,
4876,
7825,
288,
291,
14,
3352,
17371,
3707,
15,
751,
63,
1037,
262,
14,
1360,
358,
267,
916,
1595,
508,
298,
1037,
548,
582,
288,
7591,
14,
1899,
14,
1037,
548,
8,
277,
9,
288,
291,
14,
4876,
2336,
3707,
15,
1037,
262,
6217,
267,
916,
1595,
508,
298,
19799,
582,
288,
340,
291,
14,
2048,
459,
344,
418,
1137,
378,
26,
355,
291,
14,
4876,
7825,
288,
2329,
12,
308,
15089,
275,
1995,
687,
7591,
14,
51,
15089,
14,
362,
63,
23194,
63,
513,
342,
288,
291,
14,
3352,
17371,
3707,
15,
751,
63,
19799,
14,
1360,
297,
308,
15089,
29,
23194,
9,
267,
587,
26,
288,
291,
14,
952,
63,
705,
8,
5188,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2648,
492,
6001,
11149,
199,
504,
2648,
492,
7591,
199,
646,
12148,
199,
646,
3473,
421,
199,
533,
6001,
12117,
2461,
8,
5926,
11149,
304,
272,
768,
18443,
14,
2268,
14,
16675,
272,
347,
664,
8,
277,
304,
267,
340,
291,
14,
1130,
63,
5652,
459,
751,
63,
9053,
418,
440,
315,
291,
14,
2048,
459,
5652,
2565,
288,
291,
14,
952,
63,
705,
8,
13353,
9,
288,
372,
267,
1249,
275,
2097,
1606,
937,
267,
3404,
275,
291,
14,
362,
63,
589,
8,
589,
9,
267,
3404,
459,
835,
418,
275,
1616,
267,
6754,
849,
2034,
365,
413,
267,
340,
440,
3404,
459,
1606,
2565,
288,
3404,
459,
1606,
418,
275,
413,
267,
6754,
340,
664,
2034,
365,
440,
1109,
2066,
4660,
370,
2034,
413,
4960,
862,
26,
288,
3404,
905,
1606,
937,
275,
1109,
8,
2024,
905,
1606,
3135,
267,
871,
26,
288,
291,
14,
4876,
2336,
3707,
6217,
288,
372,
267,
6754,
2811,
2034,
315,
1425,
334,
17,
12,
2034,
63,
835,
9,
267,
2329,
12,
2338,
275,
1995,
687,
7591,
14,
1899,
14,
362,
63,
751,
63,
513,
63,
835,
342,
267,
870,
8,
835,
12,
730,
8,
835,
430,
267,
2034,
63,
835,
275,
1390,
8,
3442,
14,
14085,
8,
835,
1182,
3404,
459,
835,
3815,
413,
9,
267,
340,
1109,
8,
2024,
459,
1606,
1105,
665,
413,
26,
288,
291,
14,
4876,
2336,
3707,
6217,
288,
372,
267,
340,
1109,
8,
2024,
459,
1606,
1105,
690,
2034,
63,
835,
26,
288,
291,
14,
4876,
2336,
3707,
10197,
1606,
2458,
83,
5956,
495,
8,
1606,
63,
835,
430,
288,
372,
267,
2329,
12,
666,
275,
1995,
687,
7591,
14,
1899,
14,
362,
63,
751,
63,
513,
8,
2024,
9,
267,
6754,
3595,
21192,
267,
2034,
275,
1052,
267,
2034,
459,
2923,
418,
275,
2034,
63,
835,
267,
2034,
459,
1818,
418,
275,
3404,
459,
1606,
418,
267,
2034,
459,
633,
418,
275,
1994,
3707,
4805,
267,
2034,
459,
362,
418,
275,
1052,
267,
291,
14,
3352,
17371,
3707,
15,
3707,
14,
1360,
297,
666,
29,
576,
12,
2034,
29,
1606,
9,
421,
199,
533,
6001,
1899,
2461,
8,
5926,
11149,
304,
272,
408,
2849,
922,
666,
408,
272,
768,
18443,
14,
2268,
14,
16675,
272,
347,
664,
8,
277,
12,
1305,
29,
403,
12,
1595,
29,
403,
304,
267,
340,
440,
1305,
26,
1305,
275,
291,
14,
2048,
905,
344,
937,
267,
6754,
1508,
12,
3404,
275,
1995,
687,
7591,
14,
1899,
14,
362,
63,
751,
63,
14652,
63,
815,
8,
344,
9,
267,
2329,
12,
3404,
275,
1995,
687,
7591,
14,
1899,
14,
362,
63,
751,
63,
4316,
63,
815,
3252,
344,
356,
1305,
1552,
267,
2329,
12,
3404,
459,
923,
418,
275,
1995,
687,
7591,
14,
1899,
14,
362,
63,
751,
63,
923,
63,
815,
3252,
344,
356,
1305,
1552,
267,
340,
2329,
26,
288,
291,
14,
952,
63,
705,
8,
1508,
9,
288,
372,
267,
291,
14,
3352,
17371,
3707,
15,
751,
14,
1360,
297,
666,
29,
2024,
9,
199,
199,
533,
6001,
1899,
4685,
2461,
8,
5926,
11149,
304,
272,
768,
18443,
14,
2268,
14,
16675,
272,
347,
664,
8,
277,
12,
1305,
304,
267,
340,
1109,
8,
344,
9,
1137,
291,
14,
2048,
459,
344,
2565,
288,
291,
14,
952,
63,
705,
8,
13353,
9,
288,
372,
267,
666,
275,
1052,
267,
2329,
12,
666,
459,
83,
2239,
1446,
418,
275,
1995,
687,
7591,
14,
51,
15089,
14,
362,
63,
23194,
63,
513,
342,
267,
291,
14,
3352,
17371,
3707,
15,
751,
63,
3773,
14,
1360,
297,
666,
29,
576,
9,
199,
199,
533,
6001,
1899,
4940,
2461,
8,
5926,
11149,
304,
272,
768,
18443,
14,
2268,
14,
16675,
272,
347,
664,
8,
277,
12,
1595,
304,
267,
340,
1595,
508,
298,
1037,
262,
582,
288,
340,
291,
14,
2048,
459,
344,
418,
1137,
378,
26,
355,
291,
14,
4876,
7825,
288,
291,
14,
3352,
17371,
3707,
15,
751,
63,
1037,
262,
14,
1360,
358,
267,
916,
1595,
508,
298,
1037,
548,
582,
288,
7591,
14,
1899,
14,
1037,
548,
8,
277,
9,
288,
291,
14,
4876,
2336,
3707,
15,
1037,
262,
6217,
267,
916,
1595,
508,
298,
19799,
582,
288,
340,
291,
14,
2048,
459,
344,
418,
1137,
378,
26,
355,
291,
14,
4876,
7825,
288,
2329,
12,
308,
15089,
275,
1995,
687,
7591,
14,
51,
15089,
14,
362,
63,
23194,
63,
513,
342,
288,
291,
14,
3352,
17371,
3707,
15,
751,
63,
19799,
14,
1360,
297,
308,
15089,
29,
23194,
9,
267,
587,
26,
288,
291,
14,
952,
63,
705,
8,
5188,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
DarkRebel/myrobotlab
|
src/resource/Python/examples/AdafruitMotoShield.Stepper.py
|
5
|
1115
|
// create a 200 step stepper on adafruitsheild port 1
Stepper stepper1 = fruity.createStepper(200, 1);
// step 100 in one direction
stepper1.step(100);
// step 100 in the other
stepper1.step(-100);
// FIXME - needs to be cleaned up - tear down
fruity.releaseStepper(stepper1.getName());
# Arduino and motor details can be changed here
# Here is an example of creating a Adafruit Motor Shield service.
# Moving motor 1 forward at speed 200 for 1 second,
# moving it backward at speed 100, then stopping.
fruity.setSpeed(200)
fruity.run(1, AdafruitMotorShield.FORWARD)
sleep(1)
fruity.setSpeed(100)
fruity.run(1, AdafruitMotorShield.BACKWARD)
sleep(1)
fruity.run(1, AdafruitMotorShield.RELEASE)
# Additional methods were added in the spirit of Python's minimal code for maximum effect
# The following script does the same thing as the previous.
fruity.runForward(1, 200)
sleep(1)
fruity.runBackward(1, 100)
sleep(1)
fruity.stop()
# The shield supports the standard MRL Motor API too.
fruity_m1.move(0.5) # move CW at 1/2 power
fruity_m1.move(0.0) # stop
fruity_m1.move(-0.5) # move CCw at 1/2 power
|
apache-2.0
|
[
199,
501,
1218,
282,
1926,
3650,
17871,
641,
282,
983,
4391,
85,
1405,
426,
668,
1844,
413,
199,
31843,
17871,
17,
275,
289,
6558,
1209,
14,
981,
31843,
8,
1840,
12,
413,
2736,
9948,
199,
501,
3650,
2948,
315,
1373,
7581,
199,
2926,
529,
17,
14,
2926,
8,
1960,
2736,
199,
501,
3650,
2948,
315,
314,
1163,
199,
2926,
529,
17,
14,
2926,
2801,
1960,
2736,
199,
199,
501,
7600,
446,
4839,
370,
506,
12364,
1536,
446,
1565,
285,
3224,
199,
4391,
24180,
14,
3221,
31843,
8,
2926,
529,
17,
14,
16405,
30910,
421,
199,
3,
1952,
2033,
10175,
436,
28496,
2436,
883,
506,
2896,
2348,
199,
199,
3,
11842,
365,
376,
2893,
402,
6425,
282,
437,
983,
4391,
4993,
603,
13147,
5244,
553,
2435,
14,
221,
199,
3,
3930,
4007,
28496,
413,
7568,
737,
8112,
1926,
367,
413,
3499,
12,
221,
199,
3,
12876,
652,
13388,
737,
8112,
2948,
12,
2066,
23599,
14,
199,
199,
4391,
24180,
14,
409,
15146,
8,
1840,
9,
199,
4391,
24180,
14,
1065,
8,
17,
12,
437,
983,
4391,
4993,
31642,
2662,
553,
14,
29700,
9,
199,
4532,
8,
17,
9,
199,
4391,
24180,
14,
409,
15146,
8,
1960,
9,
199,
4391,
24180,
14,
1065,
8,
17,
12,
437,
983,
4391,
4993,
31642,
2662,
553,
14,
7111,
2982,
36,
9,
199,
4532,
8,
17,
9,
199,
4391,
24180,
14,
1065,
8,
17,
12,
437,
983,
4391,
4993,
31642,
2662,
553,
14,
19736,
9,
523,
199,
199,
3,
10961,
3102,
4898,
3483,
315,
314,
19441,
11133,
402,
2018,
1159,
13460,
1233,
367,
5696,
7763,
221,
199,
3,
710,
2569,
2884,
1630,
314,
2011,
8377,
465,
314,
4136,
14,
9948,
199,
4391,
24180,
14,
1065,
12984,
8,
17,
12,
1926,
9,
199,
4532,
8,
17,
9,
199,
4391,
24180,
14,
1065,
4540,
3079,
8,
17,
12,
2948,
9,
199,
4532,
8,
17,
9,
199,
4391,
24180,
14,
2379,
342,
523,
199,
3,
710,
1033,
553,
5171,
314,
4465,
603,
2431,
603,
13147,
3261,
4634,
14,
199,
199,
4391,
24180,
63,
77,
17,
14,
1185,
8,
16,
14,
21,
9,
327,
4057,
445,
55,
737,
413,
15,
18,
7074,
199,
4391,
24180,
63,
77,
17,
14,
1185,
8,
16,
14,
16,
9,
327,
3631,
199,
4391,
24180,
63,
77,
17,
14,
1185,
2801,
16,
14,
21,
9,
327,
4057,
17586,
87,
737,
413,
15,
18,
7074,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
501,
1218,
282,
1926,
3650,
17871,
641,
282,
983,
4391,
85,
1405,
426,
668,
1844,
413,
199,
31843,
17871,
17,
275,
289,
6558,
1209,
14,
981,
31843,
8,
1840,
12,
413,
2736,
9948,
199,
501,
3650,
2948,
315,
1373,
7581,
199,
2926,
529,
17,
14,
2926,
8,
1960,
2736,
199,
501,
3650,
2948,
315,
314,
1163,
199,
2926,
529,
17,
14,
2926,
2801,
1960,
2736,
199,
199,
501,
7600,
446,
4839,
370,
506,
12364,
1536,
446,
1565,
285,
3224,
199,
4391,
24180,
14,
3221,
31843,
8,
2926,
529,
17,
14,
16405,
30910,
421,
199,
3,
1952,
2033,
10175,
436,
28496,
2436,
883,
506,
2896,
2348,
199,
199,
3,
11842,
365,
376,
2893,
402,
6425,
282,
437,
983,
4391,
4993,
603,
13147,
5244,
553,
2435,
14,
221,
199,
3,
3930,
4007,
28496,
413,
7568,
737,
8112,
1926,
367,
413,
3499,
12,
221,
199,
3,
12876,
652,
13388,
737,
8112,
2948,
12,
2066,
23599,
14,
199,
199,
4391,
24180,
14,
409,
15146,
8,
1840,
9,
199,
4391,
24180,
14,
1065,
8,
17,
12,
437,
983,
4391,
4993,
31642,
2662,
553,
14,
29700,
9,
199,
4532,
8,
17,
9,
199,
4391,
24180,
14,
409,
15146,
8,
1960,
9,
199,
4391,
24180,
14,
1065,
8,
17,
12,
437,
983,
4391,
4993,
31642,
2662,
553,
14,
7111,
2982,
36,
9,
199,
4532,
8,
17,
9,
199,
4391,
24180,
14,
1065,
8,
17,
12,
437,
983,
4391,
4993,
31642,
2662,
553,
14,
19736,
9,
523,
199,
199,
3,
10961,
3102,
4898,
3483,
315,
314,
19441,
11133,
402,
2018,
1159,
13460,
1233,
367,
5696,
7763,
221,
199,
3,
710,
2569,
2884,
1630,
314,
2011,
8377,
465,
314,
4136,
14,
9948,
199,
4391,
24180,
14,
1065,
12984,
8,
17,
12,
1926,
9,
199,
4532,
8,
17,
9,
199,
4391,
24180,
14,
1065,
4540,
3079,
8,
17,
12,
2948,
9,
199,
4532,
8,
17,
9,
199,
4391,
24180,
14,
2379,
342,
523,
199,
3,
710,
1033,
553,
5171,
314,
4465,
603,
2431,
603,
13147,
3261,
4634,
14,
199,
199,
4391,
24180,
63,
77,
17,
14,
1185,
8,
16,
14,
21,
9,
327,
4057,
445,
55,
737,
413,
15,
18,
7074,
199,
4391,
24180,
63,
77,
17,
14,
1185,
8,
16,
14,
16,
9,
327,
3631,
199,
4391,
24180,
63,
77,
17,
14,
1185,
2801,
16,
14,
21,
9,
327,
4057,
17586,
87,
737,
413,
15,
18,
7074,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
Dark-Hacker/horizon
|
openstack_dashboard/dashboards/admin/volumes/volumes/views.py
|
13
|
6688
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse_lazy
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import forms
from horizon.utils import memoized
from openstack_dashboard.api import cinder
from openstack_dashboard.dashboards.admin.volumes.volumes \
import forms as volumes_forms
from openstack_dashboard.dashboards.admin.volumes.volumes \
import tables as volumes_tables
from openstack_dashboard.dashboards.project.volumes.volumes \
import views as volumes_views
class DetailView(volumes_views.DetailView):
template_name = "admin/volumes/volumes/detail.html"
def get_context_data(self, **kwargs):
context = super(DetailView, self).get_context_data(**kwargs)
table = volumes_tables.VolumesTable(self.request)
context["url"] = self.get_redirect_url()
context["actions"] = table.render_row_actions(context["volume"])
return context
def get_redirect_url(self):
return reverse('horizon:admin:volumes:index')
class ManageVolumeView(forms.ModalFormView):
form_class = volumes_forms.ManageVolume
template_name = 'admin/volumes/volumes/manage_volume.html'
modal_header = _("Manage Volume")
form_id = "manage_volume_modal"
submit_label = _("Manage")
success_url = reverse_lazy('horizon:admin:volumes:volumes_tab')
submit_url = reverse_lazy('horizon:admin:volumes:volumes:manage')
cancel_url = reverse_lazy("horizon:admin:volumes:index")
page_title = _("Manage a Volume")
def get_context_data(self, **kwargs):
context = super(ManageVolumeView, self).get_context_data(**kwargs)
return context
class UnmanageVolumeView(forms.ModalFormView):
form_class = volumes_forms.UnmanageVolume
template_name = 'admin/volumes/volumes/unmanage_volume.html'
modal_header = _("Confirm Unmanage Volume")
form_id = "unmanage_volume_modal"
submit_label = _("Unmanage")
success_url = reverse_lazy('horizon:admin:volumes:volumes_tab')
submit_url = 'horizon:admin:volumes:volumes:unmanage'
cancel_url = reverse_lazy("horizon:admin:volumes:index")
page_title = _("Unmanage a Volume")
def get_context_data(self, **kwargs):
context = super(UnmanageVolumeView, self).get_context_data(**kwargs)
args = (self.kwargs['volume_id'],)
context['submit_url'] = reverse(self.submit_url, args=args)
return context
@memoized.memoized_method
def get_data(self):
try:
volume_id = self.kwargs['volume_id']
volume = cinder.volume_get(self.request, volume_id)
except Exception:
exceptions.handle(self.request,
_('Unable to retrieve volume details.'),
redirect=self.success_url)
return volume
def get_initial(self):
volume = self.get_data()
return {'volume_id': self.kwargs["volume_id"],
'name': volume.name,
'host': getattr(volume, "os-vol-host-attr:host")}
class MigrateVolumeView(forms.ModalFormView):
form_class = volumes_forms.MigrateVolume
template_name = 'admin/volumes/volumes/migrate_volume.html'
modal_header = _("Migrate Volume")
form_id = "migrate_volume_modal"
submit_label = _("Migrate")
success_url = reverse_lazy('horizon:admin:volumes:volumes_tab')
submit_url = 'horizon:admin:volumes:volumes:migrate'
cancel_url = reverse_lazy("horizon:admin:volumes:index")
page_title = _("Migrate Volume")
def get_context_data(self, **kwargs):
context = super(MigrateVolumeView, self).get_context_data(**kwargs)
args = (self.kwargs['volume_id'],)
context['submit_url'] = reverse(self.submit_url, args=args)
return context
@memoized.memoized_method
def get_data(self):
try:
volume_id = self.kwargs['volume_id']
volume = cinder.volume_get(self.request, volume_id)
except Exception:
exceptions.handle(self.request,
_('Unable to retrieve volume details.'),
redirect=self.success_url)
return volume
@memoized.memoized_method
def get_hosts(self):
try:
return cinder.pool_list(self.request)
except Exception:
exceptions.handle(self.request,
_('Unable to retrieve pools information.'),
redirect=self.success_url)
def get_initial(self):
volume = self.get_data()
return {'volume_id': self.kwargs["volume_id"],
'name': volume.name,
'current_host': getattr(volume, "os-vol-host-attr:host"),
'hosts': self.get_hosts()}
class UpdateStatusView(forms.ModalFormView):
form_class = volumes_forms.UpdateStatus
modal_header = _("Update Volume Status")
modal_id = "update_volume_status_modal"
template_name = 'admin/volumes/volumes/update_status.html'
submit_label = _("Update Status")
submit_url = "horizon:admin:volumes:volumes:update_status"
success_url = reverse_lazy('horizon:admin:volumes:index')
page_title = _("Update Volume Status")
def get_context_data(self, **kwargs):
context = super(UpdateStatusView, self).get_context_data(**kwargs)
context["volume_id"] = self.kwargs['volume_id']
args = (self.kwargs['volume_id'],)
context['submit_url'] = reverse(self.submit_url, args=args)
return context
@memoized.memoized_method
def get_data(self):
try:
volume_id = self.kwargs['volume_id']
volume = cinder.volume_get(self.request, volume_id)
except Exception:
exceptions.handle(self.request,
_('Unable to retrieve volume details.'),
redirect=self.success_url)
return volume
def get_initial(self):
volume = self.get_data()
return {'volume_id': self.kwargs["volume_id"],
'status': volume.status}
|
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,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
63,
6395,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
4513,
199,
504,
21726,
14,
1208,
492,
11955,
1759,
199,
199,
504,
13869,
63,
9743,
14,
1246,
492,
13069,
199,
504,
13869,
63,
9743,
14,
30424,
14,
2113,
14,
8838,
14,
8838,
971,
272,
492,
4513,
465,
12158,
63,
3351,
199,
504,
13869,
63,
9743,
14,
30424,
14,
2113,
14,
8838,
14,
8838,
971,
272,
492,
6716,
465,
12158,
63,
5987,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
8838,
14,
8838,
971,
272,
492,
6858,
465,
12158,
63,
4196,
421,
199,
533,
13302,
2768,
8,
8838,
63,
4196,
14,
28539,
304,
272,
1978,
63,
354,
275,
298,
2113,
15,
8838,
15,
8838,
15,
5506,
14,
1360,
2,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
1067,
275,
1613,
8,
28539,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
1817,
275,
12158,
63,
5987,
14,
32480,
3186,
8,
277,
14,
1069,
9,
267,
1067,
905,
633,
937,
275,
291,
14,
362,
63,
4876,
63,
633,
342,
267,
1067,
905,
3723,
937,
275,
1817,
14,
3352,
63,
1143,
63,
3723,
8,
1100,
905,
2405,
3135,
267,
372,
1067,
339,
347,
664,
63,
4876,
63,
633,
8,
277,
304,
267,
372,
3837,
360,
16561,
26,
2113,
26,
8838,
26,
1080,
358,
421,
199,
533,
14944,
6464,
2768,
8,
3351,
14,
23689,
2821,
2768,
304,
272,
1824,
63,
533,
275,
12158,
63,
3351,
14,
20588,
6464,
272,
1978,
63,
354,
275,
283,
2113,
15,
8838,
15,
8838,
15,
9053,
63,
2405,
14,
1360,
7,
272,
21698,
63,
1291,
275,
3824,
20588,
15018,
531,
272,
1824,
63,
344,
275,
298,
9053,
63,
2405,
63,
17713,
2,
272,
11482,
63,
1302,
275,
3824,
20588,
531,
272,
3182,
63,
633,
275,
3837,
63,
6395,
360,
16561,
26,
2113,
26,
8838,
26,
8838,
63,
2902,
358,
272,
11482,
63,
633,
275,
3837,
63,
6395,
360,
16561,
26,
2113,
26,
8838,
26,
8838,
26,
9053,
358,
272,
9311,
63,
633,
275,
3837,
63,
6395,
480,
16561,
26,
2113,
26,
8838,
26,
1080,
531,
272,
2034,
63,
1213,
275,
3824,
20588,
282,
15018,
531,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
1067,
275,
1613,
8,
20588,
6464,
2768,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
372,
1067,
421,
199,
533,
1910,
9053,
6464,
2768,
8,
3351,
14,
23689,
2821,
2768,
304,
272,
1824,
63,
533,
275,
12158,
63,
3351,
14,
1358,
9053,
6464,
272,
1978,
63,
354,
275,
283,
2113,
15,
8838,
15,
8838,
15,
324,
9053,
63,
2405,
14,
1360,
7,
272,
21698,
63,
1291,
275,
3824,
26857,
1910,
9053,
15018,
531,
272,
1824,
63,
344,
275,
298,
324,
9053,
63,
2405,
63,
17713,
2,
272,
11482,
63,
1302,
275,
3824,
1358,
9053,
531,
272,
3182,
63,
633,
275,
3837,
63,
6395,
360,
16561,
26,
2113,
26,
8838,
26,
8838,
63,
2902,
358,
272,
11482,
63,
633,
275,
283,
16561,
26,
2113,
26,
8838,
26,
8838,
26,
324,
9053,
7,
272,
9311,
63,
633,
275,
3837,
63,
6395,
480,
16561,
26,
2113,
26,
8838,
26,
1080,
531,
272,
2034,
63,
1213,
275,
3824,
1358,
9053,
282,
15018,
531,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
1067,
275,
1613,
8,
1358,
9053,
6464,
2768,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
1249,
275,
334,
277,
14,
958,
459,
2405,
63,
344,
995,
9,
267,
1067,
459,
7275,
63,
633,
418,
275,
3837,
8,
277,
14,
7275,
63,
633,
12,
1249,
29,
589,
9,
267,
372,
1067,
339,
768,
20457,
14,
20457,
63,
765,
272,
347,
664,
63,
576,
8,
277,
304,
267,
862,
26,
288,
3301,
63,
344,
275,
291,
14,
958,
459,
2405,
63,
344,
418,
288,
3301,
275,
13069,
14,
2405,
63,
362,
8,
277,
14,
1069,
12,
3301,
63,
344,
9,
267,
871,
2186,
26,
288,
4967,
14,
2479,
8,
277,
14,
1069,
12,
2892,
4018,
6005,
370,
8044,
3301,
2436,
8038,
2892,
4660,
29,
277,
14,
3742,
63,
633,
9,
267,
372,
3301,
339,
347,
664,
63,
2747,
8,
277,
304,
267,
3301,
275,
291,
14,
362,
63,
576,
342,
267,
372,
791,
2405,
63,
344,
356,
291,
14,
958,
905,
2405,
63,
344,
2255,
355,
283,
354,
356,
3301,
14,
354,
12,
355,
283,
1102,
356,
2519,
8,
2405,
12,
298,
736,
13,
5650,
13,
1102,
13,
962,
26,
1102,
531,
93,
421,
199,
533,
28195,
1866,
6464,
2768,
8,
3351,
14,
23689,
2821,
2768,
304,
272,
1824,
63,
533,
275,
12158,
63,
3351,
14,
26641,
6464,
272,
1978,
63,
354,
275,
283,
2113,
15,
8838,
15,
8838,
15,
8462,
63,
2405,
14,
1360,
7,
272,
21698,
63,
1291,
275,
3824,
26641,
15018,
531,
272,
1824,
63,
344,
275,
298,
8462,
63,
2405,
63,
17713,
2,
272,
11482,
63,
1302,
275,
3824,
26641,
531,
272,
3182,
63,
633,
275,
3837,
63,
6395,
360,
16561,
26,
2113,
26,
8838,
26,
8838,
63,
2902,
358,
272,
11482,
63,
633,
275,
283,
16561,
26,
2113,
26,
8838,
26,
8838,
26,
8462,
7,
272,
9311,
63,
633,
275,
3837,
63,
6395,
480,
16561,
26
] |
[
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
63,
6395,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
4513,
199,
504,
21726,
14,
1208,
492,
11955,
1759,
199,
199,
504,
13869,
63,
9743,
14,
1246,
492,
13069,
199,
504,
13869,
63,
9743,
14,
30424,
14,
2113,
14,
8838,
14,
8838,
971,
272,
492,
4513,
465,
12158,
63,
3351,
199,
504,
13869,
63,
9743,
14,
30424,
14,
2113,
14,
8838,
14,
8838,
971,
272,
492,
6716,
465,
12158,
63,
5987,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
8838,
14,
8838,
971,
272,
492,
6858,
465,
12158,
63,
4196,
421,
199,
533,
13302,
2768,
8,
8838,
63,
4196,
14,
28539,
304,
272,
1978,
63,
354,
275,
298,
2113,
15,
8838,
15,
8838,
15,
5506,
14,
1360,
2,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
1067,
275,
1613,
8,
28539,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
1817,
275,
12158,
63,
5987,
14,
32480,
3186,
8,
277,
14,
1069,
9,
267,
1067,
905,
633,
937,
275,
291,
14,
362,
63,
4876,
63,
633,
342,
267,
1067,
905,
3723,
937,
275,
1817,
14,
3352,
63,
1143,
63,
3723,
8,
1100,
905,
2405,
3135,
267,
372,
1067,
339,
347,
664,
63,
4876,
63,
633,
8,
277,
304,
267,
372,
3837,
360,
16561,
26,
2113,
26,
8838,
26,
1080,
358,
421,
199,
533,
14944,
6464,
2768,
8,
3351,
14,
23689,
2821,
2768,
304,
272,
1824,
63,
533,
275,
12158,
63,
3351,
14,
20588,
6464,
272,
1978,
63,
354,
275,
283,
2113,
15,
8838,
15,
8838,
15,
9053,
63,
2405,
14,
1360,
7,
272,
21698,
63,
1291,
275,
3824,
20588,
15018,
531,
272,
1824,
63,
344,
275,
298,
9053,
63,
2405,
63,
17713,
2,
272,
11482,
63,
1302,
275,
3824,
20588,
531,
272,
3182,
63,
633,
275,
3837,
63,
6395,
360,
16561,
26,
2113,
26,
8838,
26,
8838,
63,
2902,
358,
272,
11482,
63,
633,
275,
3837,
63,
6395,
360,
16561,
26,
2113,
26,
8838,
26,
8838,
26,
9053,
358,
272,
9311,
63,
633,
275,
3837,
63,
6395,
480,
16561,
26,
2113,
26,
8838,
26,
1080,
531,
272,
2034,
63,
1213,
275,
3824,
20588,
282,
15018,
531,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
1067,
275,
1613,
8,
20588,
6464,
2768,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
372,
1067,
421,
199,
533,
1910,
9053,
6464,
2768,
8,
3351,
14,
23689,
2821,
2768,
304,
272,
1824,
63,
533,
275,
12158,
63,
3351,
14,
1358,
9053,
6464,
272,
1978,
63,
354,
275,
283,
2113,
15,
8838,
15,
8838,
15,
324,
9053,
63,
2405,
14,
1360,
7,
272,
21698,
63,
1291,
275,
3824,
26857,
1910,
9053,
15018,
531,
272,
1824,
63,
344,
275,
298,
324,
9053,
63,
2405,
63,
17713,
2,
272,
11482,
63,
1302,
275,
3824,
1358,
9053,
531,
272,
3182,
63,
633,
275,
3837,
63,
6395,
360,
16561,
26,
2113,
26,
8838,
26,
8838,
63,
2902,
358,
272,
11482,
63,
633,
275,
283,
16561,
26,
2113,
26,
8838,
26,
8838,
26,
324,
9053,
7,
272,
9311,
63,
633,
275,
3837,
63,
6395,
480,
16561,
26,
2113,
26,
8838,
26,
1080,
531,
272,
2034,
63,
1213,
275,
3824,
1358,
9053,
282,
15018,
531,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
1067,
275,
1613,
8,
1358,
9053,
6464,
2768,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
1249,
275,
334,
277,
14,
958,
459,
2405,
63,
344,
995,
9,
267,
1067,
459,
7275,
63,
633,
418,
275,
3837,
8,
277,
14,
7275,
63,
633,
12,
1249,
29,
589,
9,
267,
372,
1067,
339,
768,
20457,
14,
20457,
63,
765,
272,
347,
664,
63,
576,
8,
277,
304,
267,
862,
26,
288,
3301,
63,
344,
275,
291,
14,
958,
459,
2405,
63,
344,
418,
288,
3301,
275,
13069,
14,
2405,
63,
362,
8,
277,
14,
1069,
12,
3301,
63,
344,
9,
267,
871,
2186,
26,
288,
4967,
14,
2479,
8,
277,
14,
1069,
12,
2892,
4018,
6005,
370,
8044,
3301,
2436,
8038,
2892,
4660,
29,
277,
14,
3742,
63,
633,
9,
267,
372,
3301,
339,
347,
664,
63,
2747,
8,
277,
304,
267,
3301,
275,
291,
14,
362,
63,
576,
342,
267,
372,
791,
2405,
63,
344,
356,
291,
14,
958,
905,
2405,
63,
344,
2255,
355,
283,
354,
356,
3301,
14,
354,
12,
355,
283,
1102,
356,
2519,
8,
2405,
12,
298,
736,
13,
5650,
13,
1102,
13,
962,
26,
1102,
531,
93,
421,
199,
533,
28195,
1866,
6464,
2768,
8,
3351,
14,
23689,
2821,
2768,
304,
272,
1824,
63,
533,
275,
12158,
63,
3351,
14,
26641,
6464,
272,
1978,
63,
354,
275,
283,
2113,
15,
8838,
15,
8838,
15,
8462,
63,
2405,
14,
1360,
7,
272,
21698,
63,
1291,
275,
3824,
26641,
15018,
531,
272,
1824,
63,
344,
275,
298,
8462,
63,
2405,
63,
17713,
2,
272,
11482,
63,
1302,
275,
3824,
26641,
531,
272,
3182,
63,
633,
275,
3837,
63,
6395,
360,
16561,
26,
2113,
26,
8838,
26,
8838,
63,
2902,
358,
272,
11482,
63,
633,
275,
283,
16561,
26,
2113,
26,
8838,
26,
8838,
26,
8462,
7,
272,
9311,
63,
633,
275,
3837,
63,
6395,
480,
16561,
26,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
eric-stanley/selenium
|
py/selenium/webdriver/common/keys.py
|
71
|
2748
|
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC 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.
"""
The Keys implementation.
"""
from __future__ import unicode_literals
class Keys(object):
"""
Set of special keys codes.
"""
NULL = '\ue000'
CANCEL = '\ue001' # ^break
HELP = '\ue002'
BACKSPACE = '\ue003'
BACK_SPACE = BACKSPACE
TAB = '\ue004'
CLEAR = '\ue005'
RETURN = '\ue006'
ENTER = '\ue007'
SHIFT = '\ue008'
LEFT_SHIFT = SHIFT
CONTROL = '\ue009'
LEFT_CONTROL = CONTROL
ALT = '\ue00a'
LEFT_ALT = ALT
PAUSE = '\ue00b'
ESCAPE = '\ue00c'
SPACE = '\ue00d'
PAGE_UP = '\ue00e'
PAGE_DOWN = '\ue00f'
END = '\ue010'
HOME = '\ue011'
LEFT = '\ue012'
ARROW_LEFT = LEFT
UP = '\ue013'
ARROW_UP = UP
RIGHT = '\ue014'
ARROW_RIGHT = RIGHT
DOWN = '\ue015'
ARROW_DOWN = DOWN
INSERT = '\ue016'
DELETE = '\ue017'
SEMICOLON = '\ue018'
EQUALS = '\ue019'
NUMPAD0 = '\ue01a' # number pad keys
NUMPAD1 = '\ue01b'
NUMPAD2 = '\ue01c'
NUMPAD3 = '\ue01d'
NUMPAD4 = '\ue01e'
NUMPAD5 = '\ue01f'
NUMPAD6 = '\ue020'
NUMPAD7 = '\ue021'
NUMPAD8 = '\ue022'
NUMPAD9 = '\ue023'
MULTIPLY = '\ue024'
ADD = '\ue025'
SEPARATOR = '\ue026'
SUBTRACT = '\ue027'
DECIMAL = '\ue028'
DIVIDE = '\ue029'
F1 = '\ue031' # function keys
F2 = '\ue032'
F3 = '\ue033'
F4 = '\ue034'
F5 = '\ue035'
F6 = '\ue036'
F7 = '\ue037'
F8 = '\ue038'
F9 = '\ue039'
F10 = '\ue03a'
F11 = '\ue03b'
F12 = '\ue03c'
META = '\ue03d'
COMMAND = '\ue03d'
|
apache-2.0
|
[
3,
3909,
370,
314,
2290,
481,
3798,
676,
1448,
7297,
9844,
334,
51,
4161,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
428,
4161,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
624,
199,
1918,
17276,
4514,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
533,
17276,
8,
785,
304,
272,
408,
272,
2494,
402,
4539,
2883,
9479,
14,
272,
408,
339,
5962,
260,
275,
1557,
310,
1493,
7,
272,
27385,
755,
275,
1557,
310,
4587,
7,
327,
221,
7167,
4785,
272,
29269,
260,
275,
1557,
310,
7432,
7,
272,
22658,
11658,
259,
275,
1557,
310,
8262,
7,
272,
22658,
63,
11658,
257,
275,
22658,
11658,
272,
17916,
3515,
275,
1557,
310,
7979,
7,
272,
445,
906,
689,
263,
275,
1557,
310,
7972,
7,
272,
24646,
755,
275,
1557,
310,
8010,
7,
272,
5070,
1157,
263,
275,
1557,
310,
8255,
7,
272,
20754,
263,
275,
1557,
310,
8662,
7,
272,
6578,
63,
18013,
257,
275,
20754,
272,
8098,
420,
275,
1557,
310,
8581,
7,
272,
6578,
63,
13060,
275,
8098,
272,
12112,
52,
3515,
275,
1557,
310,
383,
65,
7,
272,
6578,
63,
19600,
258,
275,
12112,
52,
272,
510,
33,
4701,
263,
275,
1557,
310,
383,
66,
7,
272,
17682,
755,
275,
1557,
310,
383,
67,
7,
272,
16796,
263,
275,
1557,
310,
383,
68,
7,
272,
510,
2962,
63,
2160,
420,
275,
1557,
310,
383,
69,
7,
272,
510,
2962,
63,
8819,
259,
275,
1557,
310,
383,
70,
7,
272,
7729,
3515,
275,
1557,
310,
9523,
7,
272,
7781,
3635,
260,
275,
1557,
310,
13059,
7,
272,
6578,
260,
275,
1557,
310,
11533,
7,
272,
4160,
11415,
63,
9894,
257,
275,
6578,
272,
7215,
3698,
275,
1557,
310,
13264,
7,
272,
4160,
11415,
63,
2160,
258,
275,
7215,
272,
7052,
263,
275,
1557,
310,
10752,
7,
272,
4160,
11415,
63,
12811,
221,
275,
7052,
272,
10163,
260,
275,
1557,
310,
11164,
7,
272,
4160,
11415,
63,
8819,
257,
275,
10163,
272,
22542,
755,
275,
1557,
310,
10882,
7,
272,
15137,
755,
275,
1557,
310,
9570,
7,
272,
26955,
259,
275,
1557,
310,
12549,
7,
272,
27249,
755,
275,
1557,
310,
12512,
7,
339,
653,
22759,
1554,
16,
420,
275,
1557,
310,
614,
65,
7,
327,
221,
1329,
6567,
2883,
272,
653,
22759,
1554,
17,
420,
275,
1557,
310,
614,
66,
7,
272,
653,
22759,
1554,
18,
420,
275,
1557,
310,
614,
67,
7,
272,
653,
22759,
1554,
19,
420,
275,
1557,
310,
614,
68,
7,
272,
653,
22759,
1554,
20,
420,
275,
1557,
310,
614,
69,
7,
272,
653,
22759,
1554,
21,
420,
275,
1557,
310,
614,
70,
7,
272,
653,
22759,
1554,
22,
420,
275,
1557,
310,
10173,
7,
272,
653,
22759,
1554,
23,
420,
275,
1557,
310,
15385,
7,
272,
653,
22759,
1554,
24,
420,
275,
1557,
310,
16348,
7,
272,
653,
22759,
1554,
25,
420,
275,
1557,
310,
16771,
7,
272,
24895,
1772,
6084,
258,
275,
1557,
310,
5284,
7,
272,
21380,
3515,
275,
1557,
310,
18823,
7,
272,
14782,
259,
275,
1557,
310,
14842,
7,
272,
7605,
22280,
258,
275,
1557,
310,
14218,
7,
272,
31371,
16980,
420,
275,
1557,
310,
15501,
7,
272,
5266,
5437,
37,
755,
275,
1557,
310,
13996,
7,
339,
481,
17,
3698,
275,
1557,
310,
19225,
7,
327,
221,
805,
221,
2883,
272,
481,
18,
3698,
275,
1557,
310,
21683,
7,
272,
481,
19,
3698,
275,
1557,
310,
8762,
7,
272,
481,
20,
3698,
275,
1557,
310,
21756,
7,
272,
481,
21,
3698,
275,
1557,
310,
21088,
7,
272,
481,
22,
3698,
275,
1557,
310,
25368,
7,
272,
481,
23,
3698,
275,
1557,
310,
18325,
7,
272,
481,
24,
3698,
275,
1557,
310,
14273,
7,
272,
481,
25,
3698,
275,
1557,
310,
10005,
7,
272,
481,
709,
3515,
275,
1557,
310,
1644,
65,
7,
272,
481,
845,
3515,
275,
1557,
310,
1644,
66,
7,
272,
481,
713,
3515,
275,
1557,
310,
1644,
67,
7,
339,
603,
15808,
260,
275,
1557,
310,
1644,
68,
7,
272,
25965,
420,
275,
1557,
310,
1644,
68,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3909,
370,
314,
2290,
481,
3798,
676,
1448,
7297,
9844,
334,
51,
4161,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
428,
4161,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
624,
199,
1918,
17276,
4514,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
533,
17276,
8,
785,
304,
272,
408,
272,
2494,
402,
4539,
2883,
9479,
14,
272,
408,
339,
5962,
260,
275,
1557,
310,
1493,
7,
272,
27385,
755,
275,
1557,
310,
4587,
7,
327,
221,
7167,
4785,
272,
29269,
260,
275,
1557,
310,
7432,
7,
272,
22658,
11658,
259,
275,
1557,
310,
8262,
7,
272,
22658,
63,
11658,
257,
275,
22658,
11658,
272,
17916,
3515,
275,
1557,
310,
7979,
7,
272,
445,
906,
689,
263,
275,
1557,
310,
7972,
7,
272,
24646,
755,
275,
1557,
310,
8010,
7,
272,
5070,
1157,
263,
275,
1557,
310,
8255,
7,
272,
20754,
263,
275,
1557,
310,
8662,
7,
272,
6578,
63,
18013,
257,
275,
20754,
272,
8098,
420,
275,
1557,
310,
8581,
7,
272,
6578,
63,
13060,
275,
8098,
272,
12112,
52,
3515,
275,
1557,
310,
383,
65,
7,
272,
6578,
63,
19600,
258,
275,
12112,
52,
272,
510,
33,
4701,
263,
275,
1557,
310,
383,
66,
7,
272,
17682,
755,
275,
1557,
310,
383,
67,
7,
272,
16796,
263,
275,
1557,
310,
383,
68,
7,
272,
510,
2962,
63,
2160,
420,
275,
1557,
310,
383,
69,
7,
272,
510,
2962,
63,
8819,
259,
275,
1557,
310,
383,
70,
7,
272,
7729,
3515,
275,
1557,
310,
9523,
7,
272,
7781,
3635,
260,
275,
1557,
310,
13059,
7,
272,
6578,
260,
275,
1557,
310,
11533,
7,
272,
4160,
11415,
63,
9894,
257,
275,
6578,
272,
7215,
3698,
275,
1557,
310,
13264,
7,
272,
4160,
11415,
63,
2160,
258,
275,
7215,
272,
7052,
263,
275,
1557,
310,
10752,
7,
272,
4160,
11415,
63,
12811,
221,
275,
7052,
272,
10163,
260,
275,
1557,
310,
11164,
7,
272,
4160,
11415,
63,
8819,
257,
275,
10163,
272,
22542,
755,
275,
1557,
310,
10882,
7,
272,
15137,
755,
275,
1557,
310,
9570,
7,
272,
26955,
259,
275,
1557,
310,
12549,
7,
272,
27249,
755,
275,
1557,
310,
12512,
7,
339,
653,
22759,
1554,
16,
420,
275,
1557,
310,
614,
65,
7,
327,
221,
1329,
6567,
2883,
272,
653,
22759,
1554,
17,
420,
275,
1557,
310,
614,
66,
7,
272,
653,
22759,
1554,
18,
420,
275,
1557,
310,
614,
67,
7,
272,
653,
22759,
1554,
19,
420,
275,
1557,
310,
614,
68,
7,
272,
653,
22759,
1554,
20,
420,
275,
1557,
310,
614,
69,
7,
272,
653,
22759,
1554,
21,
420,
275,
1557,
310,
614,
70,
7,
272,
653,
22759,
1554,
22,
420,
275,
1557,
310,
10173,
7,
272,
653,
22759,
1554,
23,
420,
275,
1557,
310,
15385,
7,
272,
653,
22759,
1554,
24,
420,
275,
1557,
310,
16348,
7,
272,
653,
22759,
1554,
25,
420,
275,
1557,
310,
16771,
7,
272,
24895,
1772,
6084,
258,
275,
1557,
310,
5284,
7,
272,
21380,
3515,
275,
1557,
310,
18823,
7,
272,
14782,
259,
275,
1557,
310,
14842,
7,
272,
7605,
22280,
258,
275,
1557,
310,
14218,
7,
272,
31371,
16980,
420,
275,
1557,
310,
15501,
7,
272,
5266,
5437,
37,
755,
275,
1557,
310,
13996,
7,
339,
481,
17,
3698,
275,
1557,
310,
19225,
7,
327,
221,
805,
221,
2883,
272,
481,
18,
3698,
275,
1557,
310,
21683,
7,
272,
481,
19,
3698,
275,
1557,
310,
8762,
7,
272,
481,
20,
3698,
275,
1557,
310,
21756,
7,
272,
481,
21,
3698,
275,
1557,
310,
21088,
7,
272,
481,
22,
3698,
275,
1557,
310,
25368,
7,
272,
481,
23,
3698,
275,
1557,
310,
18325,
7,
272,
481,
24,
3698,
275,
1557,
310,
14273,
7,
272,
481,
25,
3698,
275,
1557,
310,
10005,
7,
272,
481,
709,
3515,
275,
1557,
310,
1644,
65,
7,
272,
481,
845,
3515,
275,
1557,
310,
1644,
66,
7,
272,
481,
713,
3515,
275,
1557,
310,
1644,
67,
7,
339,
603,
15808,
260,
275,
1557,
310,
1644,
68,
7,
272,
25965,
420,
275,
1557,
310,
1644,
68,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
lthurlow/Network-Grapher
|
proj/external/numpy-1.7.0/build/lib.linux-i686-2.7/numpy/distutils/exec_command.py
|
2
|
18578
|
#!/usr/bin/env python
"""
exec_command
Implements exec_command function that is (almost) equivalent to
commands.getstatusoutput function but on NT, DOS systems the
returned status is actually correct (though, the returned status
values may be different by a factor). In addition, exec_command
takes keyword arguments for (re-)defining environment variables.
Provides functions:
exec_command --- execute command in a specified directory and
in the modified environment.
find_executable --- locate a command using info from environment
variable PATH. Equivalent to posix `which`
command.
Author: Pearu Peterson <pearu@cens.ioc.ee>
Created: 11 January 2003
Requires: Python 2.x
Succesfully tested on:
os.name | sys.platform | comments
--------+--------------+----------
posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3
PyCrust 0.9.3, Idle 1.0.2
posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2
posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2
posix | darwin | Darwin 7.2.0, Python 2.3
nt | win32 | Windows Me
Python 2.3(EE), Idle 1.0, PyCrust 0.7.2
Python 2.1.1 Idle 0.8
nt | win32 | Windows 98, Python 2.1.1. Idle 0.8
nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests
fail i.e. redefining environment variables may
not work. FIXED: don't use cygwin echo!
Comment: also `cmd /c echo` will not work
but redefining environment variables do work.
posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)
nt | win32 | Windows XP, Python 2.3.3
Known bugs:
- Tests, that send messages to stderr, fail when executed from MSYS prompt
because the messages are lost at some point.
"""
__all__ = ['exec_command','find_executable']
import os
import sys
import shlex
from numpy.distutils.misc_util import is_sequence, make_temp_file
from numpy.distutils import log
from numpy.distutils.compat import get_exception
from numpy.compat import open_latin1
def temp_file_name():
fo, name = make_temp_file()
fo.close()
return name
def get_pythonexe():
pythonexe = sys.executable
if os.name in ['nt','dos']:
fdir,fn = os.path.split(pythonexe)
fn = fn.upper().replace('PYTHONW','PYTHON')
pythonexe = os.path.join(fdir,fn)
assert os.path.isfile(pythonexe), '%r is not a file' % (pythonexe,)
return pythonexe
def splitcmdline(line):
import warnings
warnings.warn('splitcmdline is deprecated; use shlex.split',
DeprecationWarning)
return shlex.split(line)
def find_executable(exe, path=None, _cache={}):
"""Return full path of a executable or None.
Symbolic links are not followed.
"""
key = exe, path
try:
return _cache[key]
except KeyError:
pass
log.debug('find_executable(%r)' % exe)
orig_exe = exe
if path is None:
path = os.environ.get('PATH',os.defpath)
if os.name=='posix':
realpath = os.path.realpath
else:
realpath = lambda a:a
if exe.startswith('"'):
exe = exe[1:-1]
suffixes = ['']
if os.name in ['nt','dos','os2']:
fn,ext = os.path.splitext(exe)
extra_suffixes = ['.exe','.com','.bat']
if ext.lower() not in extra_suffixes:
suffixes = extra_suffixes
if os.path.isabs(exe):
paths = ['']
else:
paths = [ os.path.abspath(p) for p in path.split(os.pathsep) ]
for path in paths:
fn = os.path.join(path, exe)
for s in suffixes:
f_ext = fn+s
if not os.path.islink(f_ext):
f_ext = realpath(f_ext)
if os.path.isfile(f_ext) and os.access(f_ext, os.X_OK):
log.good('Found executable %s' % f_ext)
_cache[key] = f_ext
return f_ext
log.warn('Could not locate executable %s' % orig_exe)
return None
############################################################
def _preserve_environment( names ):
log.debug('_preserve_environment(%r)' % (names))
env = {}
for name in names:
env[name] = os.environ.get(name)
return env
def _update_environment( **env ):
log.debug('_update_environment(...)')
for name,value in env.items():
os.environ[name] = value or ''
def exec_command( command,
execute_in='', use_shell=None, use_tee = None,
_with_python = 1,
**env ):
""" Return (status,output) of executed command.
command is a concatenated string of executable and arguments.
The output contains both stdout and stderr messages.
The following special keyword arguments can be used:
use_shell - execute `sh -c command`
use_tee - pipe the output of command through tee
execute_in - before run command `cd execute_in` and after `cd -`.
On NT, DOS systems the returned status is correct for external commands.
Wild cards will not work for non-posix systems or when use_shell=0.
"""
log.debug('exec_command(%r,%s)' % (command,\
','.join(['%s=%r'%kv for kv in env.items()])))
if use_tee is None:
use_tee = os.name=='posix'
if use_shell is None:
use_shell = os.name=='posix'
execute_in = os.path.abspath(execute_in)
oldcwd = os.path.abspath(os.getcwd())
if __name__[-12:] == 'exec_command':
exec_dir = os.path.dirname(os.path.abspath(__file__))
elif os.path.isfile('exec_command.py'):
exec_dir = os.path.abspath('.')
else:
exec_dir = os.path.abspath(sys.argv[0])
if os.path.isfile(exec_dir):
exec_dir = os.path.dirname(exec_dir)
if oldcwd!=execute_in:
os.chdir(execute_in)
log.debug('New cwd: %s' % execute_in)
else:
log.debug('Retaining cwd: %s' % oldcwd)
oldenv = _preserve_environment( env.keys() )
_update_environment( **env )
try:
# _exec_command is robust but slow, it relies on
# usable sys.std*.fileno() descriptors. If they
# are bad (like in win32 Idle, PyCrust environments)
# then _exec_command_python (even slower)
# will be used as a last resort.
#
# _exec_command_posix uses os.system and is faster
# but not on all platforms os.system will return
# a correct status.
if _with_python and (0 or sys.stdout.fileno()==-1):
st = _exec_command_python(command,
exec_command_dir = exec_dir,
**env)
elif os.name=='posix':
st = _exec_command_posix(command,
use_shell=use_shell,
use_tee=use_tee,
**env)
else:
st = _exec_command(command, use_shell=use_shell,
use_tee=use_tee,**env)
finally:
if oldcwd!=execute_in:
os.chdir(oldcwd)
log.debug('Restored cwd to %s' % oldcwd)
_update_environment(**oldenv)
return st
def _exec_command_posix( command,
use_shell = None,
use_tee = None,
**env ):
log.debug('_exec_command_posix(...)')
if is_sequence(command):
command_str = ' '.join(list(command))
else:
command_str = command
tmpfile = temp_file_name()
stsfile = None
if use_tee:
stsfile = temp_file_name()
filter = ''
if use_tee == 2:
filter = r'| tr -cd "\n" | tr "\n" "."; echo'
command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\
% (command_str,stsfile,tmpfile,filter)
else:
stsfile = temp_file_name()
command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\
% (command_str,stsfile,tmpfile)
#command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)
log.debug('Running os.system(%r)' % (command_posix))
status = os.system(command_posix)
if use_tee:
if status:
# if command_tee fails then fall back to robust exec_command
log.warn('_exec_command_posix failed (status=%s)' % status)
return _exec_command(command, use_shell=use_shell, **env)
if stsfile is not None:
f = open_latin1(stsfile,'r')
status_text = f.read()
status = int(status_text)
f.close()
os.remove(stsfile)
f = open_latin1(tmpfile,'r')
text = f.read()
f.close()
os.remove(tmpfile)
if text[-1:]=='\n':
text = text[:-1]
return status, text
def _exec_command_python(command,
exec_command_dir='', **env):
log.debug('_exec_command_python(...)')
python_exe = get_pythonexe()
cmdfile = temp_file_name()
stsfile = temp_file_name()
outfile = temp_file_name()
f = open(cmdfile,'w')
f.write('import os\n')
f.write('import sys\n')
f.write('sys.path.insert(0,%r)\n' % (exec_command_dir))
f.write('from exec_command import exec_command\n')
f.write('del sys.path[0]\n')
f.write('cmd = %r\n' % command)
f.write('os.environ = %r\n' % (os.environ))
f.write('s,o = exec_command(cmd, _with_python=0, **%r)\n' % (env))
f.write('f=open(%r,"w")\nf.write(str(s))\nf.close()\n' % (stsfile))
f.write('f=open(%r,"w")\nf.write(o)\nf.close()\n' % (outfile))
f.close()
cmd = '%s %s' % (python_exe, cmdfile)
status = os.system(cmd)
if status:
raise RuntimeError("%r failed" % (cmd,))
os.remove(cmdfile)
f = open_latin1(stsfile,'r')
status = int(f.read())
f.close()
os.remove(stsfile)
f = open_latin1(outfile,'r')
text = f.read()
f.close()
os.remove(outfile)
return status, text
def quote_arg(arg):
if arg[0]!='"' and ' ' in arg:
return '"%s"' % arg
return arg
def _exec_command( command, use_shell=None, use_tee = None, **env ):
log.debug('_exec_command(...)')
if use_shell is None:
use_shell = os.name=='posix'
if use_tee is None:
use_tee = os.name=='posix'
using_command = 0
if use_shell:
# We use shell (unless use_shell==0) so that wildcards can be
# used.
sh = os.environ.get('SHELL','/bin/sh')
if is_sequence(command):
argv = [sh,'-c',' '.join(list(command))]
else:
argv = [sh,'-c',command]
else:
# On NT, DOS we avoid using command.com as it's exit status is
# not related to the exit status of a command.
if is_sequence(command):
argv = command[:]
else:
argv = shlex.split(command)
if hasattr(os,'spawnvpe'):
spawn_command = os.spawnvpe
else:
spawn_command = os.spawnve
argv[0] = find_executable(argv[0]) or argv[0]
if not os.path.isfile(argv[0]):
log.warn('Executable %s does not exist' % (argv[0]))
if os.name in ['nt','dos']:
# argv[0] might be internal command
argv = [os.environ['COMSPEC'],'/C'] + argv
using_command = 1
so_fileno = sys.stdout.fileno()
se_fileno = sys.stderr.fileno()
so_flush = sys.stdout.flush
se_flush = sys.stderr.flush
so_dup = os.dup(so_fileno)
se_dup = os.dup(se_fileno)
outfile = temp_file_name()
fout = open(outfile,'w')
if using_command:
errfile = temp_file_name()
ferr = open(errfile,'w')
log.debug('Running %s(%s,%r,%r,os.environ)' \
% (spawn_command.__name__,os.P_WAIT,argv[0],argv))
argv0 = argv[0]
if not using_command:
argv[0] = quote_arg(argv0)
so_flush()
se_flush()
os.dup2(fout.fileno(),so_fileno)
if using_command:
#XXX: disabled for now as it does not work from cmd under win32.
# Tests fail on msys
os.dup2(ferr.fileno(),se_fileno)
else:
os.dup2(fout.fileno(),se_fileno)
try:
status = spawn_command(os.P_WAIT,argv0,argv,os.environ)
except OSError:
errmess = str(get_exception())
status = 999
sys.stderr.write('%s: %s'%(errmess,argv[0]))
so_flush()
se_flush()
os.dup2(so_dup,so_fileno)
os.dup2(se_dup,se_fileno)
fout.close()
fout = open_latin1(outfile,'r')
text = fout.read()
fout.close()
os.remove(outfile)
if using_command:
ferr.close()
ferr = open_latin1(errfile,'r')
errmess = ferr.read()
ferr.close()
os.remove(errfile)
if errmess and not status:
# Not sure how to handle the case where errmess
# contains only warning messages and that should
# not be treated as errors.
#status = 998
if text:
text = text + '\n'
#text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)
text = text + errmess
print (errmess)
if text[-1:]=='\n':
text = text[:-1]
if status is None:
status = 0
if use_tee:
print (text)
return status, text
def test_nt(**kws):
pythonexe = get_pythonexe()
echo = find_executable('echo')
using_cygwin_echo = echo != 'echo'
if using_cygwin_echo:
log.warn('Using cygwin echo in win32 environment is not supported')
s,o=exec_command(pythonexe\
+' -c "import os;print os.environ.get(\'AAA\',\'\')"')
assert s==0 and o=='',(s,o)
s,o=exec_command(pythonexe\
+' -c "import os;print os.environ.get(\'AAA\')"',
AAA='Tere')
assert s==0 and o=='Tere',(s,o)
os.environ['BBB'] = 'Hi'
s,o=exec_command(pythonexe\
+' -c "import os;print os.environ.get(\'BBB\',\'\')"')
assert s==0 and o=='Hi',(s,o)
s,o=exec_command(pythonexe\
+' -c "import os;print os.environ.get(\'BBB\',\'\')"',
BBB='Hey')
assert s==0 and o=='Hey',(s,o)
s,o=exec_command(pythonexe\
+' -c "import os;print os.environ.get(\'BBB\',\'\')"')
assert s==0 and o=='Hi',(s,o)
elif 0:
s,o=exec_command('echo Hello')
assert s==0 and o=='Hello',(s,o)
s,o=exec_command('echo a%AAA%')
assert s==0 and o=='a',(s,o)
s,o=exec_command('echo a%AAA%',AAA='Tere')
assert s==0 and o=='aTere',(s,o)
os.environ['BBB'] = 'Hi'
s,o=exec_command('echo a%BBB%')
assert s==0 and o=='aHi',(s,o)
s,o=exec_command('echo a%BBB%',BBB='Hey')
assert s==0 and o=='aHey', (s,o)
s,o=exec_command('echo a%BBB%')
assert s==0 and o=='aHi',(s,o)
s,o=exec_command('this_is_not_a_command')
assert s and o!='',(s,o)
s,o=exec_command('type not_existing_file')
assert s and o!='',(s,o)
s,o=exec_command('echo path=%path%')
assert s==0 and o!='',(s,o)
s,o=exec_command('%s -c "import sys;sys.stderr.write(sys.platform)"' \
% pythonexe)
assert s==0 and o=='win32',(s,o)
s,o=exec_command('%s -c "raise \'Ignore me.\'"' % pythonexe)
assert s==1 and o,(s,o)
s,o=exec_command('%s -c "import sys;sys.stderr.write(\'0\');sys.stderr.write(\'1\');sys.stderr.write(\'2\')"'\
% pythonexe)
assert s==0 and o=='012',(s,o)
s,o=exec_command('%s -c "import sys;sys.exit(15)"' % pythonexe)
assert s==15 and o=='',(s,o)
s,o=exec_command('%s -c "print \'Heipa\'"' % pythonexe)
assert s==0 and o=='Heipa',(s,o)
print ('ok')
def test_posix(**kws):
s,o=exec_command("echo Hello",**kws)
assert s==0 and o=='Hello',(s,o)
s,o=exec_command('echo $AAA',**kws)
assert s==0 and o=='',(s,o)
s,o=exec_command('echo "$AAA"',AAA='Tere',**kws)
assert s==0 and o=='Tere',(s,o)
s,o=exec_command('echo "$AAA"',**kws)
assert s==0 and o=='',(s,o)
os.environ['BBB'] = 'Hi'
s,o=exec_command('echo "$BBB"',**kws)
assert s==0 and o=='Hi',(s,o)
s,o=exec_command('echo "$BBB"',BBB='Hey',**kws)
assert s==0 and o=='Hey',(s,o)
s,o=exec_command('echo "$BBB"',**kws)
assert s==0 and o=='Hi',(s,o)
s,o=exec_command('this_is_not_a_command',**kws)
assert s!=0 and o!='',(s,o)
s,o=exec_command('echo path=$PATH',**kws)
assert s==0 and o!='',(s,o)
s,o=exec_command('python -c "import sys,os;sys.stderr.write(os.name)"',**kws)
assert s==0 and o=='posix',(s,o)
s,o=exec_command('python -c "raise \'Ignore me.\'"',**kws)
assert s==1 and o,(s,o)
s,o=exec_command('python -c "import sys;sys.stderr.write(\'0\');sys.stderr.write(\'1\');sys.stderr.write(\'2\')"',**kws)
assert s==0 and o=='012',(s,o)
s,o=exec_command('python -c "import sys;sys.exit(15)"',**kws)
assert s==15 and o=='',(s,o)
s,o=exec_command('python -c "print \'Heipa\'"',**kws)
assert s==0 and o=='Heipa',(s,o)
print ('ok')
def test_execute_in(**kws):
pythonexe = get_pythonexe()
tmpfile = temp_file_name()
fn = os.path.basename(tmpfile)
tmpdir = os.path.dirname(tmpfile)
f = open(tmpfile,'w')
f.write('Hello')
f.close()
s,o = exec_command('%s -c "print \'Ignore the following IOError:\','\
'open(%r,\'r\')"' % (pythonexe,fn),**kws)
assert s and o!='',(s,o)
s,o = exec_command('%s -c "print open(%r,\'r\').read()"' % (pythonexe,fn),
execute_in = tmpdir,**kws)
assert s==0 and o=='Hello',(s,o)
os.remove(tmpfile)
print ('ok')
def test_svn(**kws):
s,o = exec_command(['svn','status'],**kws)
assert s,(s,o)
print ('svn ok')
def test_cl(**kws):
if os.name=='nt':
s,o = exec_command(['cl','/V'],**kws)
assert s,(s,o)
print ('cl ok')
if os.name=='posix':
test = test_posix
elif os.name in ['nt','dos']:
test = test_nt
else:
raise NotImplementedError('exec_command tests for ', os.name)
############################################################
if __name__ == "__main__":
test(use_tee=0)
test(use_tee=1)
test_execute_in(use_tee=0)
test_execute_in(use_tee=1)
test_svn(use_tee=1)
test_cl(use_tee=1)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
1628,
63,
1531,
199,
199,
29452,
2146,
63,
1531,
805,
626,
365,
334,
4398,
9,
7353,
370,
199,
4405,
14,
362,
1205,
1199,
805,
1325,
641,
23350,
12,
577,
3100,
10460,
314,
199,
19065,
2004,
365,
5965,
3211,
334,
15401,
12,
314,
2138,
2004,
199,
1459,
1443,
506,
3365,
701,
282,
6535,
680,
1010,
10234,
12,
2146,
63,
1531,
199,
31613,
4252,
2368,
367,
334,
264,
13,
9,
318,
7969,
3734,
2860,
14,
199,
199,
17473,
3423,
26,
523,
2146,
63,
1531,
221,
10894,
5341,
1414,
315,
282,
2013,
2082,
436,
490,
315,
314,
6042,
3734,
14,
523,
2342,
63,
5904,
10894,
16592,
282,
1414,
1808,
2256,
687,
3734,
490,
1750,
15097,
14,
24228,
370,
10694,
658,
6777,
64,
490,
1414,
14,
199,
199,
5949,
26,
510,
2210,
85,
22912,
834,
665,
16343,
85,
32,
2497,
83,
14,
73,
679,
14,
1024,
30,
199,
10502,
26,
4119,
17474,
20527,
13004,
199,
199,
18153,
26,
2018,
499,
14,
88,
199,
199,
51,
947,
823,
5836,
12470,
641,
26,
523,
747,
14,
354,
1204,
984,
14,
3246,
1204,
6786,
523,
3001,
11,
10965,
11,
9460,
523,
10694,
257,
1204,
18369,
18,
755,
1204,
30445,
334,
4148,
9,
10130,
12,
2018,
499,
14,
17,
14,
19,
28061,
499,
14,
18,
14,
19,
28061,
499,
14,
19,
14,
19,
2574,
1611,
17345,
833,
378,
14,
25,
14,
19,
12,
473,
3011,
413,
14,
16,
14,
18,
523,
10694,
257,
1204,
18369,
18,
755,
1204,
9572,
13002,
1749,
10130,
12,
2018,
499,
14,
17,
14,
19,
12,
499,
14,
18,
14,
18,
12,
499,
14,
19,
14,
18,
523,
10694,
257,
1204,
308,
21003,
21,
755,
1204,
25625,
3100,
959,
14,
25,
12,
2018,
499,
14,
18,
12,
499,
14,
19,
14,
18,
523,
10694,
257,
1204,
366,
22822,
755,
1204,
577,
22822,
1520,
14,
18,
14,
16,
12,
2018,
499,
14,
19,
523,
13377,
420,
1204,
4747,
708,
263,
1204,
5417,
3194,
2574,
2018,
499,
14,
19,
8,
8699,
395,
473,
3011,
413,
14,
16,
12,
1611,
17345,
833,
378,
14,
23,
14,
18,
2574,
2018,
499,
14,
17,
14,
17,
473,
3011,
378,
14,
24,
523,
13377,
420,
1204,
4747,
708,
263,
1204,
5417,
16096,
12,
2018,
499,
14,
17,
14,
17,
14,
473,
3011,
378,
14,
24,
523,
13377,
420,
1204,
4747,
708,
263,
1204,
445,
18313,
16096,
13,
20,
14,
709,
12,
2018,
499,
14,
17,
14,
17,
8,
3053,
35,
9,
446,
11343,
2295,
2574,
2449,
284,
14,
69,
14,
295,
318,
7969,
3734,
2860,
1443,
2574,
440,
1736,
14,
7333,
1149,
26,
2793,
1133,
675,
23941,
11343,
1,
2574,
6819,
26,
2597,
658,
1760,
1182,
67,
11343,
64,
911,
440,
1736,
2574,
1325,
295,
318,
7969,
3734,
2860,
886,
1736,
14,
523,
10694,
257,
1204,
23941,
755,
1204,
445,
18313,
16096,
13,
20,
14,
709,
12,
2018,
499,
14,
19,
14,
19,
8,
1480,
13844,
316,
4539,
9,
523,
13377,
420,
1204,
4747,
708,
263,
1204,
5417,
1323,
48,
12,
2018,
499,
14,
19,
14,
19,
199,
199,
24574,
18227,
26,
199,
13,
6496,
12,
626,
3222,
3788,
370,
4635,
12,
2449,
1380,
7934,
687,
603,
13326,
8457,
523,
2952,
314,
3788,
787,
14669,
737,
2005,
2376,
14,
199,
624,
199,
199,
363,
452,
363,
275,
788,
1628,
63,
1531,
1673,
1623,
63,
5904,
418,
199,
199,
646,
747,
199,
646,
984,
199,
646,
16701,
199,
199,
504,
2680,
14,
13350,
14,
9923,
63,
1974,
492,
365,
63,
4041,
12,
1852,
63,
808,
63,
493,
199,
504,
2680,
14,
13350,
492,
943,
199,
504,
2680,
14,
13350,
14,
5819,
492,
664,
63,
1971,
199,
199,
504,
2680,
14,
5819,
492,
1551,
63,
10378,
17,
199,
199,
318,
2388,
63,
493,
63,
354,
837,
272,
7090,
12,
536,
275,
1852,
63,
808,
63,
493,
342,
272,
7090,
14,
1600,
342,
272,
372,
536,
199,
199,
318,
664,
63,
647,
273,
368,
1845,
837,
272,
1134,
273,
368,
1845,
275,
984,
14,
5904,
272,
340,
747,
14,
354,
315,
788,
343,
1673,
18339,
2565,
267,
289,
694,
12,
2324,
275,
747,
14,
515,
14,
1294,
8,
647,
273,
368,
1845,
9,
267,
4325,
275,
4325,
14,
4142,
1252,
1814,
360,
11720,
55,
1673,
11720,
358,
267,
1134,
273,
368,
1845,
275,
747,
14,
515,
14,
904,
8,
70,
694,
12,
2324,
9,
267,
702,
747,
14,
515,
14,
6292,
8,
647,
273,
368,
1845,
395,
1543,
82,
365,
440,
282,
570,
7,
450,
334,
647,
273,
368,
1845,
4258,
272,
372,
1134,
273,
368,
1845,
199,
199,
318,
3715,
15612,
8,
604,
304,
272,
492,
3598,
272,
3598,
14,
4050,
360,
1294,
15612,
365,
5906,
27,
675,
16701,
14,
1294,
297,
2116,
13413,
9,
272,
372,
16701,
14,
1294,
8,
604,
9,
199,
199,
318,
2342,
63,
5904,
8,
5803,
12,
931,
29,
403,
12,
485,
1637,
16420,
272,
408,
1767,
2615,
931,
402,
282,
7286,
503,
488,
14,
339,
21478,
9670,
6220,
787,
440,
9437,
14,
272,
408,
272,
790,
275,
14778,
12,
931,
272,
862,
26,
267,
372,
485,
1637,
59,
498,
61,
272,
871,
4067,
26,
267,
986,
272,
943,
14,
1757,
360,
1623,
63,
5904,
4042,
82,
3171,
450,
14778,
9,
272,
2306,
63,
5803,
275,
14778,
339,
340,
931,
365,
488,
26,
267,
931,
275,
747,
14,
2314,
14,
362,
360,
3243,
297,
736,
14,
318,
515,
9,
272,
340,
747,
14,
354,
6803,
9228,
356,
267,
3363,
515,
275,
747,
14,
515,
14,
11091,
272,
587,
26,
267,
3363,
515,
275,
2400,
282,
26,
65,
339,
340,
14778,
14,
2460,
14088,
735,
267,
14778,
275,
14778,
59,
17,
6809,
17,
61,
339,
19475,
275,
24506,
272,
340,
747,
14,
354,
315,
788,
343,
1673,
18339,
1673,
736,
18,
2565,
267,
4325,
12,
832,
275,
747,
14,
515,
14,
7973,
8,
5803,
9,
267,
2402,
63,
16097,
275,
18953,
5803,
26409,
957,
26409,
13475,
418,
267,
340,
1599,
14,
2325,
342,
440,
315,
2402,
63,
16097,
26,
288,
19475,
275,
2402,
63,
16097,
339,
340,
747,
14,
515,
14,
17896,
8,
5803,
304,
267,
3792,
275,
24506,
272,
587,
26,
267,
3792,
275,
359,
747,
14,
515,
14,
4832,
8
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
1628,
63,
1531,
199,
199,
29452,
2146,
63,
1531,
805,
626,
365,
334,
4398,
9,
7353,
370,
199,
4405,
14,
362,
1205,
1199,
805,
1325,
641,
23350,
12,
577,
3100,
10460,
314,
199,
19065,
2004,
365,
5965,
3211,
334,
15401,
12,
314,
2138,
2004,
199,
1459,
1443,
506,
3365,
701,
282,
6535,
680,
1010,
10234,
12,
2146,
63,
1531,
199,
31613,
4252,
2368,
367,
334,
264,
13,
9,
318,
7969,
3734,
2860,
14,
199,
199,
17473,
3423,
26,
523,
2146,
63,
1531,
221,
10894,
5341,
1414,
315,
282,
2013,
2082,
436,
490,
315,
314,
6042,
3734,
14,
523,
2342,
63,
5904,
10894,
16592,
282,
1414,
1808,
2256,
687,
3734,
490,
1750,
15097,
14,
24228,
370,
10694,
658,
6777,
64,
490,
1414,
14,
199,
199,
5949,
26,
510,
2210,
85,
22912,
834,
665,
16343,
85,
32,
2497,
83,
14,
73,
679,
14,
1024,
30,
199,
10502,
26,
4119,
17474,
20527,
13004,
199,
199,
18153,
26,
2018,
499,
14,
88,
199,
199,
51,
947,
823,
5836,
12470,
641,
26,
523,
747,
14,
354,
1204,
984,
14,
3246,
1204,
6786,
523,
3001,
11,
10965,
11,
9460,
523,
10694,
257,
1204,
18369,
18,
755,
1204,
30445,
334,
4148,
9,
10130,
12,
2018,
499,
14,
17,
14,
19,
28061,
499,
14,
18,
14,
19,
28061,
499,
14,
19,
14,
19,
2574,
1611,
17345,
833,
378,
14,
25,
14,
19,
12,
473,
3011,
413,
14,
16,
14,
18,
523,
10694,
257,
1204,
18369,
18,
755,
1204,
9572,
13002,
1749,
10130,
12,
2018,
499,
14,
17,
14,
19,
12,
499,
14,
18,
14,
18,
12,
499,
14,
19,
14,
18,
523,
10694,
257,
1204,
308,
21003,
21,
755,
1204,
25625,
3100,
959,
14,
25,
12,
2018,
499,
14,
18,
12,
499,
14,
19,
14,
18,
523,
10694,
257,
1204,
366,
22822,
755,
1204,
577,
22822,
1520,
14,
18,
14,
16,
12,
2018,
499,
14,
19,
523,
13377,
420,
1204,
4747,
708,
263,
1204,
5417,
3194,
2574,
2018,
499,
14,
19,
8,
8699,
395,
473,
3011,
413,
14,
16,
12,
1611,
17345,
833,
378,
14,
23,
14,
18,
2574,
2018,
499,
14,
17,
14,
17,
473,
3011,
378,
14,
24,
523,
13377,
420,
1204,
4747,
708,
263,
1204,
5417,
16096,
12,
2018,
499,
14,
17,
14,
17,
14,
473,
3011,
378,
14,
24,
523,
13377,
420,
1204,
4747,
708,
263,
1204,
445,
18313,
16096,
13,
20,
14,
709,
12,
2018,
499,
14,
17,
14,
17,
8,
3053,
35,
9,
446,
11343,
2295,
2574,
2449,
284,
14,
69,
14,
295,
318,
7969,
3734,
2860,
1443,
2574,
440,
1736,
14,
7333,
1149,
26,
2793,
1133,
675,
23941,
11343,
1,
2574,
6819,
26,
2597,
658,
1760,
1182,
67,
11343,
64,
911,
440,
1736,
2574,
1325,
295,
318,
7969,
3734,
2860,
886,
1736,
14,
523,
10694,
257,
1204,
23941,
755,
1204,
445,
18313,
16096,
13,
20,
14,
709,
12,
2018,
499,
14,
19,
14,
19,
8,
1480,
13844,
316,
4539,
9,
523,
13377,
420,
1204,
4747,
708,
263,
1204,
5417,
1323,
48,
12,
2018,
499,
14,
19,
14,
19,
199,
199,
24574,
18227,
26,
199,
13,
6496,
12,
626,
3222,
3788,
370,
4635,
12,
2449,
1380,
7934,
687,
603,
13326,
8457,
523,
2952,
314,
3788,
787,
14669,
737,
2005,
2376,
14,
199,
624,
199,
199,
363,
452,
363,
275,
788,
1628,
63,
1531,
1673,
1623,
63,
5904,
418,
199,
199,
646,
747,
199,
646,
984,
199,
646,
16701,
199,
199,
504,
2680,
14,
13350,
14,
9923,
63,
1974,
492,
365,
63,
4041,
12,
1852,
63,
808,
63,
493,
199,
504,
2680,
14,
13350,
492,
943,
199,
504,
2680,
14,
13350,
14,
5819,
492,
664,
63,
1971,
199,
199,
504,
2680,
14,
5819,
492,
1551,
63,
10378,
17,
199,
199,
318,
2388,
63,
493,
63,
354,
837,
272,
7090,
12,
536,
275,
1852,
63,
808,
63,
493,
342,
272,
7090,
14,
1600,
342,
272,
372,
536,
199,
199,
318,
664,
63,
647,
273,
368,
1845,
837,
272,
1134,
273,
368,
1845,
275,
984,
14,
5904,
272,
340,
747,
14,
354,
315,
788,
343,
1673,
18339,
2565,
267,
289,
694,
12,
2324,
275,
747,
14,
515,
14,
1294,
8,
647,
273,
368,
1845,
9,
267,
4325,
275,
4325,
14,
4142,
1252,
1814,
360,
11720,
55,
1673,
11720,
358,
267,
1134,
273,
368,
1845,
275,
747,
14,
515,
14,
904,
8,
70,
694,
12,
2324,
9,
267,
702,
747,
14,
515,
14,
6292,
8,
647,
273,
368,
1845,
395,
1543,
82,
365,
440,
282,
570,
7,
450,
334,
647,
273,
368,
1845,
4258,
272,
372,
1134,
273,
368,
1845,
199,
199,
318,
3715,
15612,
8,
604,
304,
272,
492,
3598,
272,
3598,
14,
4050,
360,
1294,
15612,
365,
5906,
27,
675,
16701,
14,
1294,
297,
2116,
13413,
9,
272,
372,
16701,
14,
1294,
8,
604,
9,
199,
199,
318,
2342,
63,
5904,
8,
5803,
12,
931,
29,
403,
12,
485,
1637,
16420,
272,
408,
1767,
2615,
931,
402,
282,
7286,
503,
488,
14,
339,
21478,
9670,
6220,
787,
440,
9437,
14,
272,
408,
272,
790,
275,
14778,
12,
931,
272,
862,
26,
267,
372,
485,
1637,
59,
498,
61,
272,
871,
4067,
26,
267,
986,
272,
943,
14,
1757,
360,
1623,
63,
5904,
4042,
82,
3171,
450,
14778,
9,
272,
2306,
63,
5803,
275,
14778,
339,
340,
931,
365,
488,
26,
267,
931,
275,
747,
14,
2314,
14,
362,
360,
3243,
297,
736,
14,
318,
515,
9,
272,
340,
747,
14,
354,
6803,
9228,
356,
267,
3363,
515,
275,
747,
14,
515,
14,
11091,
272,
587,
26,
267,
3363,
515,
275,
2400,
282,
26,
65,
339,
340,
14778,
14,
2460,
14088,
735,
267,
14778,
275,
14778,
59,
17,
6809,
17,
61,
339,
19475,
275,
24506,
272,
340,
747,
14,
354,
315,
788,
343,
1673,
18339,
1673,
736,
18,
2565,
267,
4325,
12,
832,
275,
747,
14,
515,
14,
7973,
8,
5803,
9,
267,
2402,
63,
16097,
275,
18953,
5803,
26409,
957,
26409,
13475,
418,
267,
340,
1599,
14,
2325,
342,
440,
315,
2402,
63,
16097,
26,
288,
19475,
275,
2402,
63,
16097,
339,
340,
747,
14,
515,
14,
17896,
8,
5803,
304,
267,
3792,
275,
24506,
272,
587,
26,
267,
3792,
275,
359,
747,
14,
515,
14,
4832,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
andersinno/django-analog
|
analog/define.py
|
1
|
2981
|
from django.db import models
from .models import BaseLogEntry
all_known_log_models = {}
def define_log_model(
model_class,
base_class=BaseLogEntry,
on_delete=models.CASCADE,
allow_null_target=False,
):
"""
Define a log model for a given Django model class ("parent model").
The log entry model class is returned, and it must be assigned to
a variable in a `models.py` file to allow Django to pick it up
for migrations.
For all intents and purposes, the log entry model is owned by your
app after this function creates it.
The parent model is anointed with two new attributes:
* ``add_log_entry``, a function to add a log entry. (See
:func:`BaseLogEntry.add_log_entry` for details,
but heed the fact that the ``target`` argument will be
implicitly passed.)
* ``log_model``, a reference to the log entry model.
:param model_class: The model class this log entry model is for.
:param base_class: Replacement base class for the model. Should
be compatible with :class:`BaseLogEntry` never-
theless.
:param on_delete: The `on_delete` clause for the log entry class's
foreign key. Defaults to `CASCADE`, i.e. that
log entries are deleted when the logged model
instance is. `PROTECT` would be another sane
option.
:param allow_null_target: Whether to allow null values as target.
This lets you have "generic" model log
entries in the same table as instance
specific ones.
:type allow_null_target: bool
:return: The log entry model.
"""
log_model_name = "%sLogEntry" % model_class.__name__
allow_null_target = bool(allow_null_target)
class Meta:
app_label = model_class._meta.app_label
abstract = False
class_dict = {
"target": models.ForeignKey(
to=model_class,
related_name="log_entries",
on_delete=on_delete,
blank=allow_null_target,
null=allow_null_target,
),
"__module__": model_class.__module__,
"Meta": Meta,
"logged_model": model_class,
}
log_entry_class = type(str(log_model_name), (base_class,), class_dict)
def add_log_entry(
self, message, identifier=None, kind="other",
user=None, extra=None, save=True, **kwargs
):
return log_entry_class.add_log_entry(
target=self,
message=message,
identifier=identifier,
kind=kind,
user=user,
extra=extra,
save=save,
**kwargs
)
setattr(model_class, "add_log_entry", add_log_entry)
setattr(model_class, "log_model", log_entry_class)
all_known_log_models[model_class] = log_entry_class
return log_entry_class
|
mit
|
[
504,
1639,
14,
697,
492,
1709,
199,
199,
504,
1275,
992,
492,
3523,
2445,
3900,
199,
199,
452,
63,
3159,
63,
793,
63,
992,
275,
1052,
421,
199,
318,
5627,
63,
793,
63,
1238,
8,
272,
1402,
63,
533,
12,
272,
1300,
63,
533,
29,
1563,
2445,
3900,
12,
272,
641,
63,
1807,
29,
992,
14,
10855,
12,
272,
2040,
63,
2307,
63,
1375,
29,
797,
12,
199,
304,
272,
408,
272,
13930,
282,
943,
1402,
367,
282,
1627,
5634,
1402,
1021,
1689,
1708,
1402,
3471,
339,
710,
943,
2397,
1402,
1021,
365,
2138,
12,
436,
652,
1471,
506,
7943,
370,
272,
282,
1750,
315,
282,
658,
992,
14,
647,
64,
570,
370,
2040,
5634,
370,
3732,
652,
1536,
272,
367,
6180,
14,
339,
2104,
1006,
21020,
83,
436,
12901,
12,
314,
943,
2397,
1402,
365,
23191,
701,
2195,
272,
1145,
2410,
642,
805,
8491,
652,
14,
339,
710,
1676,
1402,
365,
376,
79,
9082,
543,
2877,
892,
3004,
26,
339,
627,
1124,
525,
63,
793,
63,
2373,
4542,
282,
805,
370,
1050,
282,
943,
2397,
14,
334,
9295,
489,
520,
1532,
1705,
1563,
2445,
3900,
14,
525,
63,
793,
63,
2373,
64,
367,
2436,
12,
489,
1325,
946,
379,
314,
10572,
626,
314,
1124,
1375,
1040,
1423,
911,
506,
489,
19796,
3032,
4959,
272,
627,
1124,
793,
63,
1238,
4542,
282,
3659,
370,
314,
943,
2397,
1402,
14,
339,
520,
635,
1402,
63,
533,
26,
710,
1402,
1021,
642,
943,
2397,
1402,
365,
367,
14,
272,
520,
635,
1300,
63,
533,
26,
14402,
434,
1300,
1021,
367,
314,
1402,
14,
7719,
2432,
506,
9025,
543,
520,
533,
1705,
1563,
2445,
3900,
64,
7078,
13,
2432,
314,
2003,
14,
272,
520,
635,
641,
63,
1807,
26,
710,
658,
265,
63,
1807,
64,
8502,
367,
314,
943,
2397,
1021,
1159,
1993,
11608,
790,
14,
7827,
370,
658,
10855,
3559,
284,
14,
69,
14,
626,
1993,
943,
4811,
787,
5463,
1380,
314,
10367,
1402,
1993,
1256,
365,
14,
221,
658,
29148,
64,
3955,
506,
4573,
31648,
1993,
945,
14,
272,
520,
635,
2040,
63,
2307,
63,
1375,
26,
7480,
370,
2040,
2973,
1338,
465,
1347,
14,
2892,
961,
19083,
1265,
1172,
298,
6767,
2,
1402,
943,
2892,
4811,
315,
314,
2011,
1817,
465,
1256,
2892,
2488,
7869,
14,
272,
520,
466,
2040,
63,
2307,
63,
1375,
26,
2155,
272,
520,
1107,
26,
710,
943,
2397,
1402,
14,
272,
408,
272,
943,
63,
1238,
63,
354,
275,
2071,
83,
2445,
3900,
2,
450,
1402,
63,
533,
855,
354,
363,
272,
2040,
63,
2307,
63,
1375,
275,
2155,
8,
3306,
63,
2307,
63,
1375,
9,
339,
1021,
6288,
26,
267,
1145,
63,
1302,
275,
1402,
63,
533,
423,
2024,
14,
571,
63,
1302,
267,
9006,
275,
756,
339,
1021,
63,
807,
275,
469,
267,
298,
1375,
582,
1709,
14,
3190,
8,
288,
370,
29,
1238,
63,
533,
12,
288,
4048,
63,
354,
628,
793,
63,
3189,
401,
288,
641,
63,
1807,
29,
265,
63,
1807,
12,
288,
4596,
29,
3306,
63,
2307,
63,
1375,
12,
288,
2973,
29,
3306,
63,
2307,
63,
1375,
12,
267,
2318,
267,
4396,
578,
5727,
1402,
63,
533,
855,
578,
3108,
267,
298,
3396,
582,
6288,
12,
267,
298,
12419,
63,
1238,
582,
1402,
63,
533,
12,
272,
789,
339,
943,
63,
2373,
63,
533,
275,
730,
8,
495,
8,
793,
63,
1238,
63,
354,
395,
334,
1095,
63,
533,
4706,
1021,
63,
807,
9,
339,
347,
1050,
63,
793,
63,
2373,
8,
267,
291,
12,
1245,
12,
5148,
29,
403,
12,
4928,
628,
1848,
401,
267,
922,
29,
403,
12,
2402,
29,
403,
12,
3354,
29,
549,
12,
1011,
958,
272,
3461,
267,
372,
943,
63,
2373,
63,
533,
14,
525,
63,
793,
63,
2373,
8,
288,
1347,
29,
277,
12,
288,
1245,
29,
1188,
12,
288,
5148,
29,
5364,
12,
288,
4928,
29,
5091,
12,
288,
922,
29,
751,
12,
288,
2402,
29,
2911,
12,
288,
3354,
29,
2117,
12,
288,
1011,
958,
267,
776,
339,
5371,
8,
1238,
63,
533,
12,
298,
525,
63,
793,
63,
2373,
401,
1050,
63,
793,
63,
2373,
9,
272,
5371,
8,
1238,
63,
533,
12,
298,
793,
63,
1238,
401,
943,
63,
2373,
63,
533,
9,
272,
1006,
63,
3159,
63,
793,
63,
992,
59,
1238,
63,
533,
61,
275,
943,
63,
2373,
63,
533,
272,
372,
943,
63,
2373,
63,
533,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
697,
492,
1709,
199,
199,
504,
1275,
992,
492,
3523,
2445,
3900,
199,
199,
452,
63,
3159,
63,
793,
63,
992,
275,
1052,
421,
199,
318,
5627,
63,
793,
63,
1238,
8,
272,
1402,
63,
533,
12,
272,
1300,
63,
533,
29,
1563,
2445,
3900,
12,
272,
641,
63,
1807,
29,
992,
14,
10855,
12,
272,
2040,
63,
2307,
63,
1375,
29,
797,
12,
199,
304,
272,
408,
272,
13930,
282,
943,
1402,
367,
282,
1627,
5634,
1402,
1021,
1689,
1708,
1402,
3471,
339,
710,
943,
2397,
1402,
1021,
365,
2138,
12,
436,
652,
1471,
506,
7943,
370,
272,
282,
1750,
315,
282,
658,
992,
14,
647,
64,
570,
370,
2040,
5634,
370,
3732,
652,
1536,
272,
367,
6180,
14,
339,
2104,
1006,
21020,
83,
436,
12901,
12,
314,
943,
2397,
1402,
365,
23191,
701,
2195,
272,
1145,
2410,
642,
805,
8491,
652,
14,
339,
710,
1676,
1402,
365,
376,
79,
9082,
543,
2877,
892,
3004,
26,
339,
627,
1124,
525,
63,
793,
63,
2373,
4542,
282,
805,
370,
1050,
282,
943,
2397,
14,
334,
9295,
489,
520,
1532,
1705,
1563,
2445,
3900,
14,
525,
63,
793,
63,
2373,
64,
367,
2436,
12,
489,
1325,
946,
379,
314,
10572,
626,
314,
1124,
1375,
1040,
1423,
911,
506,
489,
19796,
3032,
4959,
272,
627,
1124,
793,
63,
1238,
4542,
282,
3659,
370,
314,
943,
2397,
1402,
14,
339,
520,
635,
1402,
63,
533,
26,
710,
1402,
1021,
642,
943,
2397,
1402,
365,
367,
14,
272,
520,
635,
1300,
63,
533,
26,
14402,
434,
1300,
1021,
367,
314,
1402,
14,
7719,
2432,
506,
9025,
543,
520,
533,
1705,
1563,
2445,
3900,
64,
7078,
13,
2432,
314,
2003,
14,
272,
520,
635,
641,
63,
1807,
26,
710,
658,
265,
63,
1807,
64,
8502,
367,
314,
943,
2397,
1021,
1159,
1993,
11608,
790,
14,
7827,
370,
658,
10855,
3559,
284,
14,
69,
14,
626,
1993,
943,
4811,
787,
5463,
1380,
314,
10367,
1402,
1993,
1256,
365,
14,
221,
658,
29148,
64,
3955,
506,
4573,
31648,
1993,
945,
14,
272,
520,
635,
2040,
63,
2307,
63,
1375,
26,
7480,
370,
2040,
2973,
1338,
465,
1347,
14,
2892,
961,
19083,
1265,
1172,
298,
6767,
2,
1402,
943,
2892,
4811,
315,
314,
2011,
1817,
465,
1256,
2892,
2488,
7869,
14,
272,
520,
466,
2040,
63,
2307,
63,
1375,
26,
2155,
272,
520,
1107,
26,
710,
943,
2397,
1402,
14,
272,
408,
272,
943,
63,
1238,
63,
354,
275,
2071,
83,
2445,
3900,
2,
450,
1402,
63,
533,
855,
354,
363,
272,
2040,
63,
2307,
63,
1375,
275,
2155,
8,
3306,
63,
2307,
63,
1375,
9,
339,
1021,
6288,
26,
267,
1145,
63,
1302,
275,
1402,
63,
533,
423,
2024,
14,
571,
63,
1302,
267,
9006,
275,
756,
339,
1021,
63,
807,
275,
469,
267,
298,
1375,
582,
1709,
14,
3190,
8,
288,
370,
29,
1238,
63,
533,
12,
288,
4048,
63,
354,
628,
793,
63,
3189,
401,
288,
641,
63,
1807,
29,
265,
63,
1807,
12,
288,
4596,
29,
3306,
63,
2307,
63,
1375,
12,
288,
2973,
29,
3306,
63,
2307,
63,
1375,
12,
267,
2318,
267,
4396,
578,
5727,
1402,
63,
533,
855,
578,
3108,
267,
298,
3396,
582,
6288,
12,
267,
298,
12419,
63,
1238,
582,
1402,
63,
533,
12,
272,
789,
339,
943,
63,
2373,
63,
533,
275,
730,
8,
495,
8,
793,
63,
1238,
63,
354,
395,
334,
1095,
63,
533,
4706,
1021,
63,
807,
9,
339,
347,
1050,
63,
793,
63,
2373,
8,
267,
291,
12,
1245,
12,
5148,
29,
403,
12,
4928,
628,
1848,
401,
267,
922,
29,
403,
12,
2402,
29,
403,
12,
3354,
29,
549,
12,
1011,
958,
272,
3461,
267,
372,
943,
63,
2373,
63,
533,
14,
525,
63,
793,
63,
2373,
8,
288,
1347,
29,
277,
12,
288,
1245,
29,
1188,
12,
288,
5148,
29,
5364,
12,
288,
4928,
29,
5091,
12,
288,
922,
29,
751,
12,
288,
2402,
29,
2911,
12,
288,
3354,
29,
2117,
12,
288,
1011,
958,
267,
776,
339,
5371,
8,
1238,
63,
533,
12,
298,
525,
63,
793,
63,
2373,
401,
1050,
63,
793,
63,
2373,
9,
272,
5371,
8,
1238,
63,
533,
12,
298,
793,
63,
1238,
401,
943,
63,
2373,
63,
533,
9,
272,
1006,
63,
3159,
63,
793,
63,
992,
59,
1238,
63,
533,
61,
275,
943,
63,
2373,
63,
533,
272,
372,
943,
63,
2373,
63,
533,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mlperf/training_results_v0.6
|
Google/benchmarks/mask/implementations/tpu-v3-256-mask/mask_rcnn/object_detection/shape_utils.py
|
22
|
2359
|
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Utils used to manipulate tensor shapes."""
import tensorflow as tf
def assert_shape_equal(shape_a, shape_b):
"""Asserts that shape_a and shape_b are equal.
If the shapes are static, raises a ValueError when the shapes
mismatch.
If the shapes are dynamic, raises a tf InvalidArgumentError when the shapes
mismatch.
Args:
shape_a: a list containing shape of the first tensor.
shape_b: a list containing shape of the second tensor.
Returns:
Either a tf.no_op() when shapes are all static and a tf.assert_equal() op
when the shapes are dynamic.
Raises:
ValueError: When shapes are both static and unequal.
"""
if (all(isinstance(dim, int) for dim in shape_a) and
all(isinstance(dim, int) for dim in shape_b)):
if shape_a != shape_b:
raise ValueError('Unequal shapes {}, {}'.format(shape_a, shape_b))
else: return tf.no_op()
else:
return tf.assert_equal(shape_a, shape_b)
def combined_static_and_dynamic_shape(tensor):
"""Returns a list containing static and dynamic values for the dimensions.
Returns a list of static and dynamic values for shape dimensions. This is
useful to preserve static shapes when available in reshape operation.
Args:
tensor: A tensor of any type.
Returns:
A list of size tensor.shape.ndims containing integers or a scalar tensor.
"""
static_tensor_shape = tensor.shape.as_list()
dynamic_tensor_shape = tf.shape(tensor)
combined_shape = []
for index, dim in enumerate(static_tensor_shape):
if dim is not None:
combined_shape.append(dim)
else:
combined_shape.append(dynamic_tensor_shape[index])
return combined_shape
|
apache-2.0
|
[
3,
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
624,
7535,
1202,
370,
27232,
2345,
11751,
1041,
199,
199,
646,
3228,
465,
2833,
421,
199,
318,
702,
63,
1392,
63,
1452,
8,
1392,
63,
65,
12,
2215,
63,
66,
304,
523,
408,
9699,
83,
626,
2215,
63,
65,
436,
2215,
63,
66,
787,
4472,
14,
819,
982,
314,
11751,
787,
2955,
12,
6534,
282,
1722,
1380,
314,
11751,
523,
15015,
14,
819,
982,
314,
11751,
787,
8336,
12,
6534,
282,
2833,
6378,
17042,
1380,
314,
11751,
523,
15015,
14,
819,
3033,
26,
272,
2215,
63,
65,
26,
282,
769,
3035,
2215,
402,
314,
1642,
2345,
14,
272,
2215,
63,
66,
26,
282,
769,
3035,
2215,
402,
314,
3499,
2345,
14,
819,
1803,
26,
272,
13083,
282,
2833,
14,
889,
63,
411,
342,
1380,
11751,
787,
1006,
2955,
436,
282,
2833,
14,
479,
63,
1452,
342,
1687,
272,
1380,
314,
11751,
787,
8336,
14,
819,
6218,
26,
272,
1722,
26,
3979,
11751,
787,
3865,
2955,
436,
625,
1452,
14,
523,
408,
523,
340,
334,
452,
8,
6074,
8,
3572,
12,
1109,
9,
367,
8134,
315,
2215,
63,
65,
9,
436,
489,
1006,
8,
6074,
8,
3572,
12,
1109,
9,
367,
8134,
315,
2215,
63,
66,
2298,
272,
340,
2215,
63,
65,
1137,
2215,
63,
66,
26,
489,
746,
1722,
360,
53,
685,
537,
11751,
5479,
9499,
908,
8,
1392,
63,
65,
12,
2215,
63,
66,
430,
272,
587,
26,
372,
2833,
14,
889,
63,
411,
342,
523,
587,
26,
272,
372,
2833,
14,
479,
63,
1452,
8,
1392,
63,
65,
12,
2215,
63,
66,
9,
421,
199,
318,
12149,
63,
1986,
63,
460,
63,
7764,
63,
1392,
8,
3128,
304,
523,
408,
3407,
282,
769,
3035,
2955,
436,
8336,
1338,
367,
314,
7365,
14,
819,
1803,
282,
769,
402,
2955,
436,
8336,
1338,
367,
2215,
7365,
14,
961,
365,
523,
2997,
370,
11211,
2955,
11751,
1380,
2808,
315,
21460,
3439,
14,
819,
3033,
26,
272,
2345,
26,
437,
2345,
402,
1263,
730,
14,
819,
1803,
26,
272,
437,
769,
402,
1568,
2345,
14,
1392,
14,
13575,
3035,
9446,
503,
282,
6917,
2345,
14,
523,
408,
523,
2955,
63,
3128,
63,
1392,
275,
2345,
14,
1392,
14,
305,
63,
513,
342,
523,
8336,
63,
3128,
63,
1392,
275,
2833,
14,
1392,
8,
3128,
9,
523,
12149,
63,
1392,
275,
942,
523,
367,
1478,
12,
8134,
315,
3874,
8,
1986,
63,
3128,
63,
1392,
304,
272,
340,
8134,
365,
440,
488,
26,
489,
12149,
63,
1392,
14,
740,
8,
3572,
9,
272,
587,
26,
489,
12149,
63,
1392,
14,
740,
8,
7764,
63,
3128,
63,
1392,
59,
1080,
566,
523,
372,
12149,
63,
1392,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
624,
7535,
1202,
370,
27232,
2345,
11751,
1041,
199,
199,
646,
3228,
465,
2833,
421,
199,
318,
702,
63,
1392,
63,
1452,
8,
1392,
63,
65,
12,
2215,
63,
66,
304,
523,
408,
9699,
83,
626,
2215,
63,
65,
436,
2215,
63,
66,
787,
4472,
14,
819,
982,
314,
11751,
787,
2955,
12,
6534,
282,
1722,
1380,
314,
11751,
523,
15015,
14,
819,
982,
314,
11751,
787,
8336,
12,
6534,
282,
2833,
6378,
17042,
1380,
314,
11751,
523,
15015,
14,
819,
3033,
26,
272,
2215,
63,
65,
26,
282,
769,
3035,
2215,
402,
314,
1642,
2345,
14,
272,
2215,
63,
66,
26,
282,
769,
3035,
2215,
402,
314,
3499,
2345,
14,
819,
1803,
26,
272,
13083,
282,
2833,
14,
889,
63,
411,
342,
1380,
11751,
787,
1006,
2955,
436,
282,
2833,
14,
479,
63,
1452,
342,
1687,
272,
1380,
314,
11751,
787,
8336,
14,
819,
6218,
26,
272,
1722,
26,
3979,
11751,
787,
3865,
2955,
436,
625,
1452,
14,
523,
408,
523,
340,
334,
452,
8,
6074,
8,
3572,
12,
1109,
9,
367,
8134,
315,
2215,
63,
65,
9,
436,
489,
1006,
8,
6074,
8,
3572,
12,
1109,
9,
367,
8134,
315,
2215,
63,
66,
2298,
272,
340,
2215,
63,
65,
1137,
2215,
63,
66,
26,
489,
746,
1722,
360,
53,
685,
537,
11751,
5479,
9499,
908,
8,
1392,
63,
65,
12,
2215,
63,
66,
430,
272,
587,
26,
372,
2833,
14,
889,
63,
411,
342,
523,
587,
26,
272,
372,
2833,
14,
479,
63,
1452,
8,
1392,
63,
65,
12,
2215,
63,
66,
9,
421,
199,
318,
12149,
63,
1986,
63,
460,
63,
7764,
63,
1392,
8,
3128,
304,
523,
408,
3407,
282,
769,
3035,
2955,
436,
8336,
1338,
367,
314,
7365,
14,
819,
1803,
282,
769,
402,
2955,
436,
8336,
1338,
367,
2215,
7365,
14,
961,
365,
523,
2997,
370,
11211,
2955,
11751,
1380,
2808,
315,
21460,
3439,
14,
819,
3033,
26,
272,
2345,
26,
437,
2345,
402,
1263,
730,
14,
819,
1803,
26,
272,
437,
769,
402,
1568,
2345,
14,
1392,
14,
13575,
3035,
9446,
503,
282,
6917,
2345,
14,
523,
408,
523,
2955,
63,
3128,
63,
1392,
275,
2345,
14,
1392,
14,
305,
63,
513,
342,
523,
8336,
63,
3128,
63,
1392,
275,
2833,
14,
1392,
8,
3128,
9,
523,
12149,
63,
1392,
275,
942,
523,
367,
1478,
12,
8134,
315,
3874,
8,
1986,
63,
3128,
63,
1392,
304,
272,
340,
8134,
365,
440,
488,
26,
489,
12149,
63,
1392,
14,
740,
8,
3572,
9,
272,
587,
26,
489,
12149,
63,
1392,
14,
740,
8,
7764,
63,
3128,
63,
1392,
59,
1080,
566,
523,
372,
12149,
63,
1392,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
HyperionROM/android_external_chromium
|
net/tools/testserver/backoff_server.py
|
64
|
1382
|
#!/usr/bin/python2.4
# Copyright (c) 2011 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.
"""This is a simple HTTP server for manually testing exponential
back-off functionality in Chrome.
"""
import BaseHTTPServer
import sys
import urlparse
class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
keep_running = True
def do_GET(self):
if self.path == '/quitquitquit':
self.send_response(200)
self.send_header('Content-Type', 'text/plain')
self.end_headers()
self.wfile.write('QUITTING')
RequestHandler.keep_running = False
return
params = urlparse.parse_qs(urlparse.urlparse(self.path).query)
if not params or not 'code' in params or params['code'][0] == '200':
self.send_response(200)
self.send_header('Content-Type', 'text/plain')
self.end_headers()
self.wfile.write('OK')
else:
self.send_error(int(params['code'][0]))
def main():
if len(sys.argv) != 2:
print "Usage: %s PORT" % sys.argv[0]
sys.exit(1)
port = int(sys.argv[1])
print "To stop the server, go to http://localhost:%d/quitquitquit" % port
httpd = BaseHTTPServer.HTTPServer(('', port), RequestHandler)
while RequestHandler.keep_running:
httpd.handle_request()
if __name__ == '__main__':
main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
18,
14,
20,
199,
3,
1898,
334,
67,
9,
7760,
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,
2765,
365,
282,
3486,
3101,
1654,
367,
10250,
5343,
23160,
199,
894,
13,
1997,
9330,
315,
16776,
14,
199,
624,
421,
199,
646,
3523,
14938,
199,
646,
984,
199,
646,
7097,
421,
199,
533,
4784,
2461,
8,
1563,
14938,
14,
1563,
23518,
304,
523,
4215,
63,
5720,
275,
715,
819,
347,
886,
63,
2970,
8,
277,
304,
272,
340,
291,
14,
515,
508,
1994,
10589,
10589,
10589,
356,
489,
291,
14,
2254,
63,
1310,
8,
1840,
9,
489,
291,
14,
2254,
63,
1291,
360,
2714,
13,
804,
297,
283,
505,
15,
6104,
358,
489,
291,
14,
500,
63,
2139,
342,
489,
291,
14,
18076,
14,
952,
360,
2328,
20779,
1206,
358,
489,
4784,
2461,
14,
3250,
63,
5720,
275,
756,
489,
372,
339,
1862,
275,
7097,
14,
1122,
63,
6177,
8,
10290,
14,
10290,
8,
277,
14,
515,
680,
1131,
9,
339,
340,
440,
1862,
503,
440,
283,
600,
7,
315,
1862,
503,
1862,
459,
600,
3488,
16,
61,
508,
283,
1840,
356,
489,
291,
14,
2254,
63,
1310,
8,
1840,
9,
489,
291,
14,
2254,
63,
1291,
360,
2714,
13,
804,
297,
283,
505,
15,
6104,
358,
489,
291,
14,
500,
63,
2139,
342,
489,
291,
14,
18076,
14,
952,
360,
3593,
358,
272,
587,
26,
489,
291,
14,
2254,
63,
705,
8,
442,
8,
1162,
459,
600,
3488,
16,
2459,
421,
199,
318,
2446,
837,
523,
340,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
272,
870,
298,
7692,
26,
450,
83,
25562,
2,
450,
984,
14,
3020,
59,
16,
61,
272,
984,
14,
2224,
8,
17,
9,
523,
1844,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
523,
870,
298,
1378,
3631,
314,
1654,
12,
2621,
370,
1455,
921,
5967,
2689,
68,
15,
10589,
10589,
10589,
2,
450,
1844,
523,
23913,
275,
3523,
14938,
14,
14938,
4725,
297,
1844,
395,
4784,
2461,
9,
523,
1830,
4784,
2461,
14,
3250,
63,
5720,
26,
272,
23913,
14,
2479,
63,
1069,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
18,
14,
20,
199,
3,
1898,
334,
67,
9,
7760,
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,
2765,
365,
282,
3486,
3101,
1654,
367,
10250,
5343,
23160,
199,
894,
13,
1997,
9330,
315,
16776,
14,
199,
624,
421,
199,
646,
3523,
14938,
199,
646,
984,
199,
646,
7097,
421,
199,
533,
4784,
2461,
8,
1563,
14938,
14,
1563,
23518,
304,
523,
4215,
63,
5720,
275,
715,
819,
347,
886,
63,
2970,
8,
277,
304,
272,
340,
291,
14,
515,
508,
1994,
10589,
10589,
10589,
356,
489,
291,
14,
2254,
63,
1310,
8,
1840,
9,
489,
291,
14,
2254,
63,
1291,
360,
2714,
13,
804,
297,
283,
505,
15,
6104,
358,
489,
291,
14,
500,
63,
2139,
342,
489,
291,
14,
18076,
14,
952,
360,
2328,
20779,
1206,
358,
489,
4784,
2461,
14,
3250,
63,
5720,
275,
756,
489,
372,
339,
1862,
275,
7097,
14,
1122,
63,
6177,
8,
10290,
14,
10290,
8,
277,
14,
515,
680,
1131,
9,
339,
340,
440,
1862,
503,
440,
283,
600,
7,
315,
1862,
503,
1862,
459,
600,
3488,
16,
61,
508,
283,
1840,
356,
489,
291,
14,
2254,
63,
1310,
8,
1840,
9,
489,
291,
14,
2254,
63,
1291,
360,
2714,
13,
804,
297,
283,
505,
15,
6104,
358,
489,
291,
14,
500,
63,
2139,
342,
489,
291,
14,
18076,
14,
952,
360,
3593,
358,
272,
587,
26,
489,
291,
14,
2254,
63,
705,
8,
442,
8,
1162,
459,
600,
3488,
16,
2459,
421,
199,
318,
2446,
837,
523,
340,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
272,
870,
298,
7692,
26,
450,
83,
25562,
2,
450,
984,
14,
3020,
59,
16,
61,
272,
984,
14,
2224,
8,
17,
9,
523,
1844,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
523,
870,
298,
1378,
3631,
314,
1654,
12,
2621,
370,
1455,
921,
5967,
2689,
68,
15,
10589,
10589,
10589,
2,
450,
1844,
523,
23913,
275,
3523,
14938,
14,
14938,
4725,
297,
1844,
395,
4784,
2461,
9,
523,
1830,
4784,
2461,
14,
3250,
63,
5720,
26,
272,
23913,
14,
2479,
63,
1069,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768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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
] |
RedRightHand/llvm-analyses
|
cse231-proj1/llvm/src/utils/lint/cpp_lint.py
|
147
|
3031
|
#!/usr/bin/python
#
# Checks C++ files to make sure they conform to LLVM standards, as specified in
# http://llvm.org/docs/CodingStandards.html .
#
# TODO: add unittests for the verifier functions:
# http://docs.python.org/library/unittest.html .
import common_lint
import re
import sys
def VerifyIncludes(filename, lines):
"""Makes sure the #includes are in proper order and no disallows files are
#included.
Args:
filename: the file under consideration as string
lines: contents of the file as string array
"""
lint = []
include_gtest_re = re.compile(r'^#include "gtest/(.*)"')
include_llvm_re = re.compile(r'^#include "llvm/(.*)"')
include_support_re = re.compile(r'^#include "(Support/.*)"')
include_config_re = re.compile(r'^#include "(Config/.*)"')
include_system_re = re.compile(r'^#include <(.*)>')
DISALLOWED_SYSTEM_HEADERS = ['iostream']
line_num = 1
prev_config_header = None
prev_system_header = None
for line in lines:
# TODO: implement private headers
# TODO: implement gtest headers
# TODO: implement top-level llvm/* headers
# TODO: implement llvm/Support/* headers
# Process Config/* headers
config_header = include_config_re.match(line)
if config_header:
curr_config_header = config_header.group(1)
if prev_config_header:
if prev_config_header > curr_config_header:
lint.append((filename, line_num,
'Config headers not in order: "%s" before "%s"' % (
prev_config_header, curr_config_header)))
# Process system headers
system_header = include_system_re.match(line)
if system_header:
curr_system_header = system_header.group(1)
# Is it blacklisted?
if curr_system_header in DISALLOWED_SYSTEM_HEADERS:
lint.append((filename, line_num,
'Disallowed system header: <%s>' % curr_system_header))
elif prev_system_header:
# Make sure system headers are alphabetized amongst themselves
if prev_system_header > curr_system_header:
lint.append((filename, line_num,
'System headers not in order: <%s> before <%s>' % (
prev_system_header, curr_system_header)))
prev_system_header = curr_system_header
line_num += 1
return lint
class CppLint(common_lint.BaseLint):
MAX_LINE_LENGTH = 80
def RunOnFile(self, filename, lines):
lint = []
lint.extend(VerifyIncludes(filename, lines))
lint.extend(common_lint.VerifyLineLength(filename, lines,
CppLint.MAX_LINE_LENGTH))
lint.extend(common_lint.VerifyTabs(filename, lines))
lint.extend(common_lint.VerifyTrailingWhitespace(filename, lines))
return lint
def CppLintMain(filenames):
all_lint = common_lint.RunLintOverAllFiles(CppLint(), filenames)
for lint in all_lint:
print '%s:%d:%s' % (lint[0], lint[1], lint[2])
return 0
if __name__ == '__main__':
sys.exit(CppLintMain(sys.argv[1:]))
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
13813,
445,
4176,
1584,
370,
1852,
3238,
2985,
26449,
370,
491,
28631,
10584,
5596,
12,
465,
2013,
315,
199,
3,
1455,
921,
29257,
14,
1308,
15,
4757,
15,
35,
2691,
18736,
5596,
14,
1360,
1275,
199,
3,
199,
3,
3254,
26,
1050,
2882,
83,
367,
314,
25581,
3423,
26,
199,
3,
1455,
921,
4757,
14,
1548,
14,
1308,
15,
4342,
15,
2796,
14,
1360,
1275,
199,
199,
646,
2863,
63,
3854,
199,
646,
295,
199,
646,
984,
199,
199,
318,
7635,
22792,
8,
1501,
12,
2385,
304,
523,
408,
27142,
3238,
314,
327,
9441,
787,
315,
5576,
1865,
436,
949,
2153,
24077,
1584,
787,
523,
327,
12409,
14,
819,
3033,
26,
272,
1788,
26,
314,
570,
1334,
8219,
1754,
465,
1059,
272,
2385,
26,
4072,
402,
314,
570,
465,
1059,
1625,
523,
408,
523,
24620,
275,
942,
819,
2387,
63,
8385,
63,
264,
275,
295,
14,
2014,
8,
82,
4289,
3,
2613,
298,
8385,
7985,
2795,
2924,
358,
523,
2387,
63,
29257,
63,
264,
275,
295,
14,
2014,
8,
82,
4289,
3,
2613,
298,
29257,
7985,
2795,
2924,
358,
523,
2387,
63,
4058,
63,
264,
275,
295,
14,
2014,
8,
82,
4289,
3,
2613,
7340,
11532,
15,
2795,
2924,
358,
523,
2387,
63,
888,
63,
264,
275,
295,
14,
2014,
8,
82,
4289,
3,
2613,
7340,
2028,
15,
2795,
2924,
358,
523,
2387,
63,
2253,
63,
264,
275,
295,
14,
2014,
8,
82,
4289,
3,
2613,
665,
8,
12432,
5971,
819,
7587,
17350,
63,
12711,
63,
21178,
275,
788,
73,
9015,
418,
819,
1004,
63,
1507,
275,
413,
523,
5071,
63,
888,
63,
1291,
275,
488,
523,
5071,
63,
2253,
63,
1291,
275,
488,
523,
367,
1004,
315,
2385,
26,
272,
327,
3254,
26,
5669,
5726,
2323,
272,
327,
3254,
26,
5669,
9088,
2323,
272,
327,
3254,
26,
5669,
2746,
13,
1896,
18338,
2611,
6331,
2323,
272,
327,
3254,
26,
5669,
18338,
2611,
15,
11532,
6331,
2323,
339,
327,
7132,
4094,
6331,
2323,
272,
1101,
63,
1291,
275,
2387,
63,
888,
63,
264,
14,
1431,
8,
604,
9,
272,
340,
1101,
63,
1291,
26,
489,
8230,
63,
888,
63,
1291,
275,
1101,
63,
1291,
14,
923,
8,
17,
9,
489,
340,
5071,
63,
888,
63,
1291,
26,
267,
340,
5071,
63,
888,
63,
1291,
690,
8230,
63,
888,
63,
1291,
26,
881,
24620,
14,
740,
1332,
1501,
12,
1004,
63,
1507,
12,
2432,
283,
2028,
2323,
440,
315,
1865,
26,
2071,
83,
2,
2544,
2071,
83,
4507,
450,
334,
586,
5071,
63,
888,
63,
1291,
12,
8230,
63,
888,
63,
1291,
1724,
339,
327,
7132,
2656,
2323,
272,
2656,
63,
1291,
275,
2387,
63,
2253,
63,
264,
14,
1431,
8,
604,
9,
272,
340,
2656,
63,
1291,
26,
489,
8230,
63,
2253,
63,
1291,
275,
2656,
63,
1291,
14,
923,
8,
17,
9,
2541,
327,
6596,
652,
12136,
15023,
31,
489,
340,
8230,
63,
2253,
63,
1291,
315,
7587,
17350,
63,
12711,
63,
21178,
26,
267,
24620,
14,
740,
1332,
1501,
12,
1004,
63,
1507,
12,
2151,
283,
2825,
6541,
2656,
1406,
26,
21808,
83,
3524,
450,
8230,
63,
2253,
63,
1291,
430,
489,
916,
5071,
63,
2253,
63,
1291,
26,
267,
327,
4155,
3238,
2656,
2323,
787,
23331,
22927,
16885,
270,
17279,
267,
340,
5071,
63,
2253,
63,
1291,
690,
8230,
63,
2253,
63,
1291,
26,
881,
24620,
14,
740,
1332,
1501,
12,
1004,
63,
1507,
12,
2432,
283,
3989,
2323,
440,
315,
1865,
26,
21808,
83,
30,
2544,
21808,
83,
3524,
450,
334,
586,
5071,
63,
2253,
63,
1291,
12,
8230,
63,
2253,
63,
1291,
1724,
2541,
5071,
63,
2253,
63,
1291,
275,
8230,
63,
2253,
63,
1291,
339,
1004,
63,
1507,
847,
413,
819,
372,
24620,
421,
199,
533,
445,
802,
44,
442,
8,
2330,
63,
3854,
14,
1563,
44,
442,
304,
523,
9141,
63,
6174,
63,
9127,
275,
5939,
819,
347,
3378,
3314,
1173,
8,
277,
12,
1788,
12,
2385,
304,
272,
24620,
275,
942,
272,
24620,
14,
2880,
8,
7496,
22792,
8,
1501,
12,
2385,
430,
272,
24620,
14,
2880,
8,
2330,
63,
3854,
14,
7496,
3049,
4625,
8,
1501,
12,
2385,
12,
6163,
445,
802,
44,
442,
14,
4283,
63,
6174,
63,
9127,
430,
272,
24620,
14,
2880,
8,
2330,
63,
3854,
14,
7496,
23085,
8,
1501,
12,
2385,
430,
272,
24620,
14,
2880,
8,
2330,
63,
3854,
14,
7496,
2437,
5662,
16552,
8,
1501,
12,
2385,
430,
272,
372,
24620,
421,
199,
318,
445,
802,
44,
442,
6756,
8,
10309,
304,
523,
1006,
63,
3854,
275,
2863,
63,
3854,
14,
2540,
44,
442,
5674,
2422,
5535,
8,
19705,
44,
442,
1062,
6203,
9,
523,
367,
24620,
315,
1006,
63,
3854,
26,
272,
870,
1543,
83,
2689,
68,
2689,
83,
7,
450,
334,
3854,
59,
16,
467,
24620,
59,
17,
467,
24620,
59,
18,
566,
523,
372,
378,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
984,
14,
2224,
8,
19705,
44,
442,
6756,
8,
1274,
14,
3020,
59,
17,
16720,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
13813,
445,
4176,
1584,
370,
1852,
3238,
2985,
26449,
370,
491,
28631,
10584,
5596,
12,
465,
2013,
315,
199,
3,
1455,
921,
29257,
14,
1308,
15,
4757,
15,
35,
2691,
18736,
5596,
14,
1360,
1275,
199,
3,
199,
3,
3254,
26,
1050,
2882,
83,
367,
314,
25581,
3423,
26,
199,
3,
1455,
921,
4757,
14,
1548,
14,
1308,
15,
4342,
15,
2796,
14,
1360,
1275,
199,
199,
646,
2863,
63,
3854,
199,
646,
295,
199,
646,
984,
199,
199,
318,
7635,
22792,
8,
1501,
12,
2385,
304,
523,
408,
27142,
3238,
314,
327,
9441,
787,
315,
5576,
1865,
436,
949,
2153,
24077,
1584,
787,
523,
327,
12409,
14,
819,
3033,
26,
272,
1788,
26,
314,
570,
1334,
8219,
1754,
465,
1059,
272,
2385,
26,
4072,
402,
314,
570,
465,
1059,
1625,
523,
408,
523,
24620,
275,
942,
819,
2387,
63,
8385,
63,
264,
275,
295,
14,
2014,
8,
82,
4289,
3,
2613,
298,
8385,
7985,
2795,
2924,
358,
523,
2387,
63,
29257,
63,
264,
275,
295,
14,
2014,
8,
82,
4289,
3,
2613,
298,
29257,
7985,
2795,
2924,
358,
523,
2387,
63,
4058,
63,
264,
275,
295,
14,
2014,
8,
82,
4289,
3,
2613,
7340,
11532,
15,
2795,
2924,
358,
523,
2387,
63,
888,
63,
264,
275,
295,
14,
2014,
8,
82,
4289,
3,
2613,
7340,
2028,
15,
2795,
2924,
358,
523,
2387,
63,
2253,
63,
264,
275,
295,
14,
2014,
8,
82,
4289,
3,
2613,
665,
8,
12432,
5971,
819,
7587,
17350,
63,
12711,
63,
21178,
275,
788,
73,
9015,
418,
819,
1004,
63,
1507,
275,
413,
523,
5071,
63,
888,
63,
1291,
275,
488,
523,
5071,
63,
2253,
63,
1291,
275,
488,
523,
367,
1004,
315,
2385,
26,
272,
327,
3254,
26,
5669,
5726,
2323,
272,
327,
3254,
26,
5669,
9088,
2323,
272,
327,
3254,
26,
5669,
2746,
13,
1896,
18338,
2611,
6331,
2323,
272,
327,
3254,
26,
5669,
18338,
2611,
15,
11532,
6331,
2323,
339,
327,
7132,
4094,
6331,
2323,
272,
1101,
63,
1291,
275,
2387,
63,
888,
63,
264,
14,
1431,
8,
604,
9,
272,
340,
1101,
63,
1291,
26,
489,
8230,
63,
888,
63,
1291,
275,
1101,
63,
1291,
14,
923,
8,
17,
9,
489,
340,
5071,
63,
888,
63,
1291,
26,
267,
340,
5071,
63,
888,
63,
1291,
690,
8230,
63,
888,
63,
1291,
26,
881,
24620,
14,
740,
1332,
1501,
12,
1004,
63,
1507,
12,
2432,
283,
2028,
2323,
440,
315,
1865,
26,
2071,
83,
2,
2544,
2071,
83,
4507,
450,
334,
586,
5071,
63,
888,
63,
1291,
12,
8230,
63,
888,
63,
1291,
1724,
339,
327,
7132,
2656,
2323,
272,
2656,
63,
1291,
275,
2387,
63,
2253,
63,
264,
14,
1431,
8,
604,
9,
272,
340,
2656,
63,
1291,
26,
489,
8230,
63,
2253,
63,
1291,
275,
2656,
63,
1291,
14,
923,
8,
17,
9,
2541,
327,
6596,
652,
12136,
15023,
31,
489,
340,
8230,
63,
2253,
63,
1291,
315,
7587,
17350,
63,
12711,
63,
21178,
26,
267,
24620,
14,
740,
1332,
1501,
12,
1004,
63,
1507,
12,
2151,
283,
2825,
6541,
2656,
1406,
26,
21808,
83,
3524,
450,
8230,
63,
2253,
63,
1291,
430,
489,
916,
5071,
63,
2253,
63,
1291,
26,
267,
327,
4155,
3238,
2656,
2323,
787,
23331,
22927,
16885,
270,
17279,
267,
340,
5071,
63,
2253,
63,
1291,
690,
8230,
63,
2253,
63,
1291,
26,
881,
24620,
14,
740,
1332,
1501,
12,
1004,
63,
1507,
12,
2432,
283,
3989,
2323,
440,
315,
1865,
26,
21808,
83,
30,
2544,
21808,
83,
3524,
450,
334,
586,
5071,
63,
2253,
63,
1291,
12,
8230,
63,
2253,
63,
1291,
1724,
2541,
5071,
63,
2253,
63,
1291,
275,
8230,
63,
2253,
63,
1291,
339,
1004,
63,
1507,
847,
413,
819,
372,
24620,
421,
199,
533,
445,
802,
44,
442,
8,
2330,
63,
3854,
14,
1563,
44,
442,
304,
523,
9141,
63,
6174,
63,
9127,
275,
5939,
819,
347,
3378,
3314,
1173,
8,
277,
12,
1788,
12,
2385,
304,
272,
24620,
275,
942,
272,
24620,
14,
2880,
8,
7496,
22792,
8,
1501,
12,
2385,
430,
272,
24620,
14,
2880,
8,
2330,
63,
3854,
14,
7496,
3049,
4625,
8,
1501,
12,
2385,
12,
6163,
445,
802,
44,
442,
14,
4283,
63,
6174,
63,
9127,
430,
272,
24620,
14,
2880,
8,
2330,
63,
3854,
14,
7496,
23085,
8,
1501,
12,
2385,
430,
272,
24620,
14,
2880,
8,
2330,
63,
3854,
14,
7496,
2437,
5662,
16552,
8,
1501,
12,
2385,
430,
272,
372,
24620,
421,
199,
318,
445,
802,
44,
442,
6756,
8,
10309,
304,
523,
1006,
63,
3854,
275,
2863,
63,
3854,
14,
2540,
44,
442,
5674,
2422,
5535,
8,
19705,
44,
442,
1062,
6203,
9,
523,
367,
24620,
315,
1006,
63,
3854,
26,
272,
870,
1543,
83,
2689,
68,
2689,
83,
7,
450,
334,
3854,
59,
16,
467,
24620,
59,
17,
467,
24620,
59,
18,
566,
523,
372,
378,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
984,
14,
2224,
8,
19705,
44,
442,
6756,
8,
1274,
14,
3020,
59,
17,
16720,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
gaoxiaofeng/troubleShooting
|
src/troubleshooting/framework/template/Keyword.py
|
1
|
1763
|
from troubleshooting.framework.modules.configuration import ConfigManagerInstance
from troubleshooting.framework.remote.client import client
from troubleshooting.framework.libraries.bash import ExecuteCommond
try:
#import project config.variable
from config.variable import *
except:
print "WARN: failed to import config.variable"
class Keyword(object):
def __init__(self):
super(Keyword,self).__init__()
self.remote = True if ConfigManagerInstance.config["Host"] else False
self.host = ConfigManagerInstance.config["Host"]
self.port = int(ConfigManagerInstance.config["Port"])
self.user = ConfigManagerInstance.config["User"]
self.password = ConfigManagerInstance.config["Password"]
self.ssh = None
self.local = None
def _open_connection(self):
self.ssh = client().open_connection(host=self.host,port=self.port,user=self.user,password=self.password)
def _remote_execute_command(self,command,checkerr = False):
if self.ssh is None:
self._open_connection()
stdout = self.ssh._execute_command(command,checkerr=checkerr)
return stdout
def _local_execute_command(self,command,checkerr = True):
if self.local is None:
self.local = ExecuteCommond()
stdout = self.local.shell_command(command,checkerr=checkerr)
return stdout
def execute_command(self,command,checkerr = False):
if self.remote:
stdout = self._remote_execute_command(command,checkerr=checkerr)
return stdout
else:
stdout = self._local_execute_command(command)
return stdout
def download(self,remoteFile,localFile):
self.ssh.get(remoteFile,localFile)
|
apache-2.0
|
[
504,
29616,
13927,
15866,
14,
4857,
14,
3112,
14,
4758,
492,
4094,
2988,
3244,
199,
504,
29616,
13927,
15866,
14,
4857,
14,
3846,
14,
1258,
492,
1890,
199,
504,
29616,
13927,
15866,
14,
4857,
14,
10159,
14,
16408,
492,
17009,
5150,
7835,
199,
893,
26,
272,
327,
646,
2199,
1101,
14,
1975,
272,
687,
1101,
14,
1975,
492,
627,
199,
2590,
26,
272,
870,
298,
17449,
26,
3405,
370,
492,
1101,
14,
1975,
2,
199,
533,
6431,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
10650,
12,
277,
2843,
826,
4533,
267,
291,
14,
3846,
275,
715,
340,
4094,
2988,
3244,
14,
888,
905,
4965,
937,
587,
756,
267,
291,
14,
1102,
275,
4094,
2988,
3244,
14,
888,
905,
4965,
937,
267,
291,
14,
719,
275,
1109,
8,
2028,
2988,
3244,
14,
888,
905,
4313,
3135,
267,
291,
14,
751,
275,
4094,
2988,
3244,
14,
888,
905,
1899,
937,
267,
291,
14,
2060,
275,
4094,
2988,
3244,
14,
888,
905,
6139,
937,
267,
291,
14,
5510,
275,
488,
267,
291,
14,
1832,
275,
488,
272,
347,
485,
1490,
63,
2105,
8,
277,
304,
267,
291,
14,
5510,
275,
1890,
1252,
1490,
63,
2105,
8,
1102,
29,
277,
14,
1102,
12,
719,
29,
277,
14,
719,
12,
751,
29,
277,
14,
751,
12,
2060,
29,
277,
14,
2060,
9,
272,
347,
485,
3846,
63,
2526,
63,
1531,
8,
277,
12,
1531,
12,
1074,
1508,
275,
756,
304,
267,
340,
291,
14,
5510,
365,
488,
26,
288,
291,
423,
1490,
63,
2105,
342,
267,
3839,
275,
291,
14,
5510,
423,
2526,
63,
1531,
8,
1531,
12,
1074,
1508,
29,
1074,
1508,
9,
267,
372,
3839,
339,
347,
485,
1832,
63,
2526,
63,
1531,
8,
277,
12,
1531,
12,
1074,
1508,
275,
715,
304,
267,
340,
291,
14,
1832,
365,
488,
26,
288,
291,
14,
1832,
275,
221,
17009,
5150,
7835,
342,
267,
3839,
275,
291,
14,
1832,
14,
5641,
63,
1531,
8,
1531,
12,
1074,
1508,
29,
1074,
1508,
9,
267,
372,
3839,
272,
347,
5341,
63,
1531,
8,
277,
12,
1531,
12,
1074,
1508,
275,
756,
304,
267,
340,
291,
14,
3846,
26,
288,
3839,
275,
291,
423,
3846,
63,
2526,
63,
1531,
8,
1531,
12,
1074,
1508,
29,
1074,
1508,
9,
288,
372,
3839,
267,
587,
26,
288,
3839,
275,
291,
423,
1832,
63,
2526,
63,
1531,
8,
1531,
9,
288,
372,
221,
3839,
339,
347,
5235,
8,
277,
12,
3846,
1173,
12,
1832,
1173,
304,
267,
291,
14,
5510,
14,
362,
8,
3846,
1173,
12,
1832,
1173,
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
] |
[
29616,
13927,
15866,
14,
4857,
14,
3112,
14,
4758,
492,
4094,
2988,
3244,
199,
504,
29616,
13927,
15866,
14,
4857,
14,
3846,
14,
1258,
492,
1890,
199,
504,
29616,
13927,
15866,
14,
4857,
14,
10159,
14,
16408,
492,
17009,
5150,
7835,
199,
893,
26,
272,
327,
646,
2199,
1101,
14,
1975,
272,
687,
1101,
14,
1975,
492,
627,
199,
2590,
26,
272,
870,
298,
17449,
26,
3405,
370,
492,
1101,
14,
1975,
2,
199,
533,
6431,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
10650,
12,
277,
2843,
826,
4533,
267,
291,
14,
3846,
275,
715,
340,
4094,
2988,
3244,
14,
888,
905,
4965,
937,
587,
756,
267,
291,
14,
1102,
275,
4094,
2988,
3244,
14,
888,
905,
4965,
937,
267,
291,
14,
719,
275,
1109,
8,
2028,
2988,
3244,
14,
888,
905,
4313,
3135,
267,
291,
14,
751,
275,
4094,
2988,
3244,
14,
888,
905,
1899,
937,
267,
291,
14,
2060,
275,
4094,
2988,
3244,
14,
888,
905,
6139,
937,
267,
291,
14,
5510,
275,
488,
267,
291,
14,
1832,
275,
488,
272,
347,
485,
1490,
63,
2105,
8,
277,
304,
267,
291,
14,
5510,
275,
1890,
1252,
1490,
63,
2105,
8,
1102,
29,
277,
14,
1102,
12,
719,
29,
277,
14,
719,
12,
751,
29,
277,
14,
751,
12,
2060,
29,
277,
14,
2060,
9,
272,
347,
485,
3846,
63,
2526,
63,
1531,
8,
277,
12,
1531,
12,
1074,
1508,
275,
756,
304,
267,
340,
291,
14,
5510,
365,
488,
26,
288,
291,
423,
1490,
63,
2105,
342,
267,
3839,
275,
291,
14,
5510,
423,
2526,
63,
1531,
8,
1531,
12,
1074,
1508,
29,
1074,
1508,
9,
267,
372,
3839,
339,
347,
485,
1832,
63,
2526,
63,
1531,
8,
277,
12,
1531,
12,
1074,
1508,
275,
715,
304,
267,
340,
291,
14,
1832,
365,
488,
26,
288,
291,
14,
1832,
275,
221,
17009,
5150,
7835,
342,
267,
3839,
275,
291,
14,
1832,
14,
5641,
63,
1531,
8,
1531,
12,
1074,
1508,
29,
1074,
1508,
9,
267,
372,
3839,
272,
347,
5341,
63,
1531,
8,
277,
12,
1531,
12,
1074,
1508,
275,
756,
304,
267,
340,
291,
14,
3846,
26,
288,
3839,
275,
291,
423,
3846,
63,
2526,
63,
1531,
8,
1531,
12,
1074,
1508,
29,
1074,
1508,
9,
288,
372,
3839,
267,
587,
26,
288,
3839,
275,
291,
423,
1832,
63,
2526,
63,
1531,
8,
1531,
9,
288,
372,
221,
3839,
339,
347,
5235,
8,
277,
12,
3846,
1173,
12,
1832,
1173,
304,
267,
291,
14,
5510,
14,
362,
8,
3846,
1173,
12,
1832,
1173,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
palaniyappanBala/thug
|
src/Analysis/peepdf/jsbeautifier/unpackers/myobfuscate.py
|
175
|
2832
|
#
# deobfuscator for scripts messed up with myobfuscate.com
# by Einar Lielmanis <einar@jsbeautifier.org>
#
# written by Stefano Sanfilippo <a.little.coder@gmail.com>
#
# usage:
#
# if detect(some_string):
# unpacked = unpack(some_string)
#
# CAVEAT by Einar Lielmanis
#
# You really don't want to obfuscate your scripts there: they're tracking
# your unpackings, your script gets turned into something like this,
# as of 2011-08-26:
#
# var _escape = 'your_script_escaped';
# var _111 = document.createElement('script');
# _111.src = 'http://api.www.myobfuscate.com/?getsrc=ok' +
# '&ref=' + encodeURIComponent(document.referrer) +
# '&url=' + encodeURIComponent(document.URL);
# var 000 = document.getElementsByTagName('head')[0];
# 000.appendChild(_111);
# document.write(unescape(_escape));
#
"""Deobfuscator for scripts messed up with MyObfuscate.com"""
import re
import base64
# Python 2 retrocompatibility
# pylint: disable=F0401
# pylint: disable=E0611
try:
from urllib import unquote
except ImportError:
from urllib.parse import unquote
from jsbeautifier.unpackers import UnpackingError
PRIORITY = 1
CAVEAT = """//
// Unpacker warning: be careful when using myobfuscate.com for your projects:
// scripts obfuscated by the free online version call back home.
//
"""
SIGNATURE = (r'["\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F'
r'\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x61\x62\x63\x64\x65'
r'\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75'
r'\x76\x77\x78\x79\x7A\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x2B'
r'\x2F\x3D","","\x63\x68\x61\x72\x41\x74","\x69\x6E\x64\x65\x78'
r'\x4F\x66","\x66\x72\x6F\x6D\x43\x68\x61\x72\x43\x6F\x64\x65","'
r'\x6C\x65\x6E\x67\x74\x68"]')
def detect(source):
"""Detects MyObfuscate.com packer."""
return SIGNATURE in source
def unpack(source):
"""Unpacks js code packed with MyObfuscate.com"""
if not detect(source):
return source
payload = unquote(_filter(source))
match = re.search(r"^var _escape\='<script>(.*)<\/script>'",
payload, re.DOTALL)
polished = match.group(1) if match else source
return CAVEAT + polished
def _filter(source):
"""Extracts and decode payload (original file) from `source`"""
try:
varname = re.search(r'eval\(\w+\(\w+\((\w+)\)\)\);', source).group(1)
reverse = re.search(r"var +%s *\= *'(.*)';" % varname, source).group(1)
except AttributeError:
raise UnpackingError('Malformed MyObfuscate data.')
try:
return base64.b64decode(reverse[::-1].encode('utf8')).decode('utf8')
except TypeError:
raise UnpackingError('MyObfuscate payload is not base64-encoded.')
|
gpl-2.0
|
[
3,
199,
3,
477,
2873,
31958,
67,
707,
367,
10554,
26560,
939,
1536,
543,
3002,
2873,
31958,
1411,
14,
957,
199,
3,
701,
662,
262,
285,
491,
14769,
1237,
374,
665,
69,
262,
285,
32,
3596,
30745,
935,
3895,
14,
1308,
30,
199,
3,
199,
3,
258,
5313,
701,
17854,
70,
8143,
29359,
329,
3587,
555,
665,
65,
14,
10182,
14,
2693,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
4503,
26,
199,
3,
199,
3,
340,
9696,
8,
3972,
63,
875,
304,
199,
3,
258,
23389,
275,
7787,
8,
3972,
63,
875,
9,
199,
3,
199,
199,
3,
7240,
2524,
619,
701,
662,
262,
285,
491,
14769,
1237,
374,
199,
199,
3,
199,
3,
2047,
7710,
2793,
1133,
2934,
370,
2607,
31958,
1411,
2195,
10554,
2337,
26,
2985,
3984,
15161,
199,
3,
2195,
7787,
780,
12,
2195,
2884,
7545,
19136,
1901,
6020,
2839,
642,
12,
199,
3,
465,
402,
7760,
13,
2036,
13,
1479,
26,
199,
3,
199,
3,
257,
2729,
485,
3765,
275,
283,
12695,
63,
1579,
63,
13572,
13619,
199,
3,
257,
2729,
485,
6673,
275,
2213,
14,
20296,
360,
1579,
11339,
199,
3,
257,
485,
6673,
14,
2164,
275,
283,
1014,
921,
1246,
14,
1544,
14,
1662,
2873,
31958,
1411,
14,
957,
10197,
362,
2164,
29,
745,
7,
435,
199,
3,
4519,
7673,
1121,
534,
435,
3752,
1230,
948,
22527,
1946,
8,
3554,
14,
21928,
3859,
9,
435,
199,
3,
4519,
7673,
633,
534,
435,
3752,
1230,
948,
22527,
1946,
8,
3554,
14,
2632,
2736,
199,
3,
257,
2729,
21551,
275,
2213,
14,
15045,
360,
2993,
5832,
16,
11566,
199,
3,
257,
21551,
14,
14988,
1547,
6673,
2736,
199,
3,
257,
2213,
14,
952,
8,
22726,
1547,
3765,
16674,
199,
3,
199,
199,
624,
872,
2873,
31958,
67,
707,
367,
10554,
26560,
939,
1536,
543,
4932,
47,
4361,
527,
1411,
14,
957,
624,
199,
199,
646,
295,
199,
646,
1300,
772,
199,
199,
3,
2018,
499,
295,
1374,
15390,
199,
3,
4287,
26,
3507,
29,
38,
28025,
199,
3,
4287,
26,
3507,
29,
37,
1690,
845,
199,
893,
26,
272,
687,
4011,
492,
14342,
199,
2590,
3545,
26,
272,
687,
4011,
14,
1122,
492,
14342,
199,
199,
504,
8586,
30745,
935,
3895,
14,
5301,
1192,
492,
31017,
316,
547,
199,
199,
25144,
275,
413,
199,
199,
3263,
2524,
619,
275,
408,
501,
199,
501,
31017,
281,
5721,
26,
506,
25082,
1380,
1808,
3002,
2873,
31958,
1411,
14,
957,
367,
2195,
11336,
26,
199,
501,
10554,
2607,
31958,
3153,
701,
314,
2867,
18470,
1015,
1240,
1771,
5629,
14,
199,
501,
199,
199,
624,
199,
199,
26588,
275,
334,
82,
7,
905,
60,
88,
2953,
60,
88,
2260,
60,
88,
2824,
60,
88,
1602,
60,
88,
2322,
60,
88,
2466,
60,
88,
2417,
60,
88,
2006,
60,
88,
1887,
60,
88,
20,
33,
60,
88,
20,
34,
60,
88,
20,
35,
60,
88,
20,
36,
60,
88,
20,
37,
60,
88,
20,
38,
7,
1467,
519,
1154,
88,
1400,
60,
88,
2869,
60,
88,
2528,
60,
88,
2481,
60,
88,
1477,
60,
88,
1229,
60,
88,
1367,
60,
88,
1641,
60,
88,
2010,
60,
88,
1427,
60,
88,
21,
33,
60,
88,
2976,
60,
88,
2789,
60,
88,
2766,
60,
88,
772,
60,
88,
2182,
7,
1467,
519,
1154,
88,
1272,
60,
88,
1822,
60,
88,
2333,
60,
88,
1876,
60,
88,
22,
33,
60,
88,
22,
34,
60,
88,
22,
35,
60,
88,
22,
36,
60,
88,
22,
37,
60,
88,
22,
38,
60,
88,
2760,
60,
88,
3172,
60,
88,
2819,
60,
88,
2898,
60,
88,
1342,
60,
88,
2194,
7,
1467,
519,
1154,
88,
2114,
60,
88,
1138,
60,
88,
2277,
60,
88,
1965,
60,
88,
23,
33,
60,
88,
1216,
60,
88,
2192,
60,
88,
708,
60,
88,
1153,
60,
88,
1082,
60,
88,
1276,
60,
88,
1344,
60,
88,
1401,
60,
88,
1703,
60,
88,
1355,
60,
88,
18,
34,
7,
1467,
519,
1154,
88,
18,
38,
60,
88,
19,
36,
401,
5151,
3212,
88,
2766,
60,
88,
2333,
60,
88,
2976,
60,
88,
2819,
60,
88,
2953,
60,
88,
1342,
2266,
60,
88,
1876,
60,
88,
22,
37,
60,
88,
772,
60,
88,
2182,
60,
88,
2277,
7,
1467,
519,
1154,
88,
20,
38,
60,
88,
1272,
2266,
60,
88,
1272,
60,
88,
2819,
60,
88,
22,
38,
60,
88,
22,
36,
60,
88,
2824,
60,
88,
2333,
60,
88,
2976,
60,
88,
2819,
60,
88,
2824,
60,
88,
22,
38,
60,
88,
772,
60,
88,
2182,
2266,
7,
1467,
519,
1154,
88,
22,
35,
60,
88,
2182,
60,
88,
22,
37,
60,
88,
1822,
60,
88,
1342,
60,
88,
2333,
937,
358,
199,
199,
318,
9696,
8,
1365,
304,
272,
408,
872,
28853,
4932,
47,
4361,
527,
1411,
14,
957,
1706,
281,
1041,
272,
372,
5056,
13214,
315,
1350,
199,
199,
318,
7787,
8,
1365,
304,
272,
408,
26472,
83,
8586,
1233,
13170,
543,
4932,
47,
4361,
527,
1411,
14,
957,
624,
272,
340,
440,
9696,
8,
1365,
304,
267,
372,
1350,
272,
4886,
275,
14342,
1547,
1541,
8,
1365,
430,
272,
1336,
275,
295,
14,
1733,
8,
82,
16136,
1391,
485,
3765,
60,
15829,
1579,
13661,
12432,
28,
19814,
1579,
3524,
401,
1993,
4886,
12,
295,
14,
16504,
9,
272,
1115,
1891,
379,
275,
1336,
14,
923,
8,
17,
9,
340,
1336,
587,
1350,
272,
372,
7240,
2524,
619,
435,
1115,
1891,
379,
199,
199,
318,
485,
1541,
8,
1365,
304,
272,
408,
12147,
83,
436,
4849,
4886,
334,
5043,
570,
9,
687,
658,
1365,
64,
624,
272,
862,
26,
267,
22071,
275,
295,
14,
1733,
8,
82,
7,
2579,
29323,
87,
7896,
2961,
87,
7896,
1332,
60,
87,
13439,
2862,
2862,
27853,
1350,
680,
923,
8,
17,
9,
267,
3837,
275,
295,
14,
1733,
8,
82,
2,
1391,
435,
5,
83,
30940,
29,
627,
6774,
2795,
3171,
9426,
450,
22071,
12,
1350,
680,
923,
8,
17,
9,
272,
871,
4281,
26,
267,
746,
31017,
316,
547,
360,
29513,
4932,
47,
4361,
527,
1411,
666,
2659,
272,
862,
26,
267,
372,
1300,
772,
14,
66,
772,
2708,
8,
4471,
14172,
17,
1055,
2143,
360,
1624,
24,
11103,
2708,
360,
1624,
24,
358,
272
] |
[
199,
3,
477,
2873,
31958,
67,
707,
367,
10554,
26560,
939,
1536,
543,
3002,
2873,
31958,
1411,
14,
957,
199,
3,
701,
662,
262,
285,
491,
14769,
1237,
374,
665,
69,
262,
285,
32,
3596,
30745,
935,
3895,
14,
1308,
30,
199,
3,
199,
3,
258,
5313,
701,
17854,
70,
8143,
29359,
329,
3587,
555,
665,
65,
14,
10182,
14,
2693,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
4503,
26,
199,
3,
199,
3,
340,
9696,
8,
3972,
63,
875,
304,
199,
3,
258,
23389,
275,
7787,
8,
3972,
63,
875,
9,
199,
3,
199,
199,
3,
7240,
2524,
619,
701,
662,
262,
285,
491,
14769,
1237,
374,
199,
199,
3,
199,
3,
2047,
7710,
2793,
1133,
2934,
370,
2607,
31958,
1411,
2195,
10554,
2337,
26,
2985,
3984,
15161,
199,
3,
2195,
7787,
780,
12,
2195,
2884,
7545,
19136,
1901,
6020,
2839,
642,
12,
199,
3,
465,
402,
7760,
13,
2036,
13,
1479,
26,
199,
3,
199,
3,
257,
2729,
485,
3765,
275,
283,
12695,
63,
1579,
63,
13572,
13619,
199,
3,
257,
2729,
485,
6673,
275,
2213,
14,
20296,
360,
1579,
11339,
199,
3,
257,
485,
6673,
14,
2164,
275,
283,
1014,
921,
1246,
14,
1544,
14,
1662,
2873,
31958,
1411,
14,
957,
10197,
362,
2164,
29,
745,
7,
435,
199,
3,
4519,
7673,
1121,
534,
435,
3752,
1230,
948,
22527,
1946,
8,
3554,
14,
21928,
3859,
9,
435,
199,
3,
4519,
7673,
633,
534,
435,
3752,
1230,
948,
22527,
1946,
8,
3554,
14,
2632,
2736,
199,
3,
257,
2729,
21551,
275,
2213,
14,
15045,
360,
2993,
5832,
16,
11566,
199,
3,
257,
21551,
14,
14988,
1547,
6673,
2736,
199,
3,
257,
2213,
14,
952,
8,
22726,
1547,
3765,
16674,
199,
3,
199,
199,
624,
872,
2873,
31958,
67,
707,
367,
10554,
26560,
939,
1536,
543,
4932,
47,
4361,
527,
1411,
14,
957,
624,
199,
199,
646,
295,
199,
646,
1300,
772,
199,
199,
3,
2018,
499,
295,
1374,
15390,
199,
3,
4287,
26,
3507,
29,
38,
28025,
199,
3,
4287,
26,
3507,
29,
37,
1690,
845,
199,
893,
26,
272,
687,
4011,
492,
14342,
199,
2590,
3545,
26,
272,
687,
4011,
14,
1122,
492,
14342,
199,
199,
504,
8586,
30745,
935,
3895,
14,
5301,
1192,
492,
31017,
316,
547,
199,
199,
25144,
275,
413,
199,
199,
3263,
2524,
619,
275,
408,
501,
199,
501,
31017,
281,
5721,
26,
506,
25082,
1380,
1808,
3002,
2873,
31958,
1411,
14,
957,
367,
2195,
11336,
26,
199,
501,
10554,
2607,
31958,
3153,
701,
314,
2867,
18470,
1015,
1240,
1771,
5629,
14,
199,
501,
199,
199,
624,
199,
199,
26588,
275,
334,
82,
7,
905,
60,
88,
2953,
60,
88,
2260,
60,
88,
2824,
60,
88,
1602,
60,
88,
2322,
60,
88,
2466,
60,
88,
2417,
60,
88,
2006,
60,
88,
1887,
60,
88,
20,
33,
60,
88,
20,
34,
60,
88,
20,
35,
60,
88,
20,
36,
60,
88,
20,
37,
60,
88,
20,
38,
7,
1467,
519,
1154,
88,
1400,
60,
88,
2869,
60,
88,
2528,
60,
88,
2481,
60,
88,
1477,
60,
88,
1229,
60,
88,
1367,
60,
88,
1641,
60,
88,
2010,
60,
88,
1427,
60,
88,
21,
33,
60,
88,
2976,
60,
88,
2789,
60,
88,
2766,
60,
88,
772,
60,
88,
2182,
7,
1467,
519,
1154,
88,
1272,
60,
88,
1822,
60,
88,
2333,
60,
88,
1876,
60,
88,
22,
33,
60,
88,
22,
34,
60,
88,
22,
35,
60,
88,
22,
36,
60,
88,
22,
37,
60,
88,
22,
38,
60,
88,
2760,
60,
88,
3172,
60,
88,
2819,
60,
88,
2898,
60,
88,
1342,
60,
88,
2194,
7,
1467,
519,
1154,
88,
2114,
60,
88,
1138,
60,
88,
2277,
60,
88,
1965,
60,
88,
23,
33,
60,
88,
1216,
60,
88,
2192,
60,
88,
708,
60,
88,
1153,
60,
88,
1082,
60,
88,
1276,
60,
88,
1344,
60,
88,
1401,
60,
88,
1703,
60,
88,
1355,
60,
88,
18,
34,
7,
1467,
519,
1154,
88,
18,
38,
60,
88,
19,
36,
401,
5151,
3212,
88,
2766,
60,
88,
2333,
60,
88,
2976,
60,
88,
2819,
60,
88,
2953,
60,
88,
1342,
2266,
60,
88,
1876,
60,
88,
22,
37,
60,
88,
772,
60,
88,
2182,
60,
88,
2277,
7,
1467,
519,
1154,
88,
20,
38,
60,
88,
1272,
2266,
60,
88,
1272,
60,
88,
2819,
60,
88,
22,
38,
60,
88,
22,
36,
60,
88,
2824,
60,
88,
2333,
60,
88,
2976,
60,
88,
2819,
60,
88,
2824,
60,
88,
22,
38,
60,
88,
772,
60,
88,
2182,
2266,
7,
1467,
519,
1154,
88,
22,
35,
60,
88,
2182,
60,
88,
22,
37,
60,
88,
1822,
60,
88,
1342,
60,
88,
2333,
937,
358,
199,
199,
318,
9696,
8,
1365,
304,
272,
408,
872,
28853,
4932,
47,
4361,
527,
1411,
14,
957,
1706,
281,
1041,
272,
372,
5056,
13214,
315,
1350,
199,
199,
318,
7787,
8,
1365,
304,
272,
408,
26472,
83,
8586,
1233,
13170,
543,
4932,
47,
4361,
527,
1411,
14,
957,
624,
272,
340,
440,
9696,
8,
1365,
304,
267,
372,
1350,
272,
4886,
275,
14342,
1547,
1541,
8,
1365,
430,
272,
1336,
275,
295,
14,
1733,
8,
82,
16136,
1391,
485,
3765,
60,
15829,
1579,
13661,
12432,
28,
19814,
1579,
3524,
401,
1993,
4886,
12,
295,
14,
16504,
9,
272,
1115,
1891,
379,
275,
1336,
14,
923,
8,
17,
9,
340,
1336,
587,
1350,
272,
372,
7240,
2524,
619,
435,
1115,
1891,
379,
199,
199,
318,
485,
1541,
8,
1365,
304,
272,
408,
12147,
83,
436,
4849,
4886,
334,
5043,
570,
9,
687,
658,
1365,
64,
624,
272,
862,
26,
267,
22071,
275,
295,
14,
1733,
8,
82,
7,
2579,
29323,
87,
7896,
2961,
87,
7896,
1332,
60,
87,
13439,
2862,
2862,
27853,
1350,
680,
923,
8,
17,
9,
267,
3837,
275,
295,
14,
1733,
8,
82,
2,
1391,
435,
5,
83,
30940,
29,
627,
6774,
2795,
3171,
9426,
450,
22071,
12,
1350,
680,
923,
8,
17,
9,
272,
871,
4281,
26,
267,
746,
31017,
316,
547,
360,
29513,
4932,
47,
4361,
527,
1411,
666,
2659,
272,
862,
26,
267,
372,
1300,
772,
14,
66,
772,
2708,
8,
4471,
14172,
17,
1055,
2143,
360,
1624,
24,
11103,
2708,
360,
1624,
24,
358,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Hastwell/baconbot
|
nbt/chunk.py
|
6
|
7930
|
"""
Handles a single chunk of data (16x16x128 blocks) from a Minecraft save.
Chunk is currently McRegion only.
"""
from io import BytesIO
from struct import pack, unpack
import array, math
class Chunk(object):
"""Class for representing a single chunk."""
def __init__(self, nbt):
chunk_data = nbt['Level']
self.coords = chunk_data['xPos'],chunk_data['zPos']
self.blocks = BlockArray(chunk_data['Blocks'].value, chunk_data['Data'].value)
def get_coords(self):
"""Return the coordinates of this chunk."""
return (self.coords[0].value,self.coords[1].value)
def __repr__(self):
"""Return a representation of this Chunk."""
return "Chunk("+str(self.coords[0])+","+str(self.coords[1])+")"
class BlockArray(object):
"""Convenience class for dealing with a Block/data byte array."""
def __init__(self, blocksBytes=None, dataBytes=None):
"""Create a new BlockArray, defaulting to no block or data bytes."""
if isinstance(blocksBytes, (bytearray, array.array)):
self.blocksList = list(blocksBytes)
else:
self.blocksList = [0]*32768 # Create an empty block list (32768 entries of zero (air))
if isinstance(dataBytes, (bytearray, array.array)):
self.dataList = list(dataBytes)
else:
self.dataList = [0]*16384 # Create an empty data list (32768 4-bit entries of zero make 16384 byte entries)
# Get all block entries
def get_all_blocks(self):
"""Return the blocks that are in this BlockArray."""
return self.blocksList
# Get all data entries
def get_all_data(self):
"""Return the data of all the blocks in this BlockArray."""
bits = []
for b in self.dataList:
# The first byte of the Blocks arrays correspond
# to the LEAST significant bits of the first byte of the Data.
# NOT to the MOST significant bits, as you might expected.
bits.append(b & 15) # Little end of the byte
bits.append((b >> 4) & 15) # Big end of the byte
return bits
# Get all block entries and data entries as tuples
def get_all_blocks_and_data(self):
"""Return both blocks and data, packed together as tuples."""
return list(zip(self.get_all_blocks(), self.get_all_data()))
def get_blocks_struct(self):
"""Return a dictionary with block ids keyed to (x, y, z)."""
cur_x = 0
cur_y = 0
cur_z = 0
blocks = {}
for block_id in self.blocksList:
blocks[(cur_x,cur_y,cur_z)] = block_id
cur_y += 1
if (cur_y > 127):
cur_y = 0
cur_z += 1
if (cur_z > 15):
cur_z = 0
cur_x += 1
return blocks
# Give blockList back as a byte array
def get_blocks_byte_array(self, buffer=False):
"""Return a list of all blocks in this chunk."""
if buffer:
length = len(self.blocksList)
return BytesIO(pack(">i", length)+self.get_blocks_byte_array())
else:
return array.array('B', self.blocksList).tostring()
def get_data_byte_array(self, buffer=False):
"""Return a list of data for all blocks in this chunk."""
if buffer:
length = len(self.dataList)
return BytesIO(pack(">i", length)+self.get_data_byte_array())
else:
return array.array('B', self.dataList).tostring()
def generate_heightmap(self, buffer=False, as_array=False):
"""Return a heightmap, representing the highest solid blocks in this chunk."""
non_solids = [0, 8, 9, 10, 11, 38, 37, 32, 31]
if buffer:
return BytesIO(pack(">i", 256)+self.generate_heightmap()) # Length + Heightmap, ready for insertion into Chunk NBT
else:
bytes = []
for z in range(16):
for x in range(16):
for y in range(127, -1, -1):
offset = y + z*128 + x*128*16
if (self.blocksList[offset] not in non_solids or y == 0):
bytes.append(y+1)
break
if (as_array):
return bytes
else:
return array.array('B', bytes).tostring()
def set_blocks(self, list=None, dict=None, fill_air=False):
"""
Sets all blocks in this chunk, using either a list or dictionary.
Blocks not explicitly set can be filled to air by setting fill_air to True.
"""
if list:
# Inputting a list like self.blocksList
self.blocksList = list
elif dict:
# Inputting a dictionary like result of self.get_blocks_struct()
list = []
for x in range(16):
for z in range(16):
for y in range(128):
coord = x,y,z
offset = y + z*128 + x*128*16
if (coord in dict):
list.append(dict[coord])
else:
if (self.blocksList[offset] and not fill_air):
list.append(self.blocksList[offset])
else:
list.append(0) # Air
self.blocksList = list
else:
# None of the above...
return False
return True
def set_block(self, x,y,z, id, data=0):
"""Sets the block a x, y, z to the specified id, and optionally data."""
offset = y + z*128 + x*128*16
self.blocksList[offset] = id
if (offset % 2 == 1):
# offset is odd
index = (offset-1)//2
b = self.dataList[index]
self.dataList[index] = (b & 240) + (data & 15) # modify lower bits, leaving higher bits in place
else:
# offset is even
index = offset//2
b = self.dataList[index]
self.dataList[index] = (b & 15) + (data << 4 & 240) # modify ligher bits, leaving lower bits in place
# Get a given X,Y,Z or a tuple of three coordinates
def get_block(self, x,y,z, coord=False):
"""Return the id of the block at x, y, z."""
"""
Laid out like:
(0,0,0), (0,1,0), (0,2,0) ... (0,127,0), (0,0,1), (0,1,1), (0,2,1) ... (0,127,1), (0,0,2) ... (0,127,15), (1,0,0), (1,1,0) ... (15,127,15)
::
blocks = []
for x in range(15):
for z in range(15):
for y in range(127):
blocks.append(Block(x,y,z))
"""
offset = y + z*128 + x*128*16 if (coord == False) else coord[1] + coord[2]*128 + coord[0]*128*16
return self.blocksList[offset]
# Get a given X,Y,Z or a tuple of three coordinates
def get_data(self, x,y,z, coord=False):
"""Return the data of the block at x, y, z."""
offset = y + z*128 + x*128*16 if (coord == False) else coord[1] + coord[2]*128 + coord[0]*128*16
# The first byte of the Blocks arrays correspond
# to the LEAST significant bits of the first byte of the Data.
# NOT to the MOST significant bits, as you might expected.
if (offset % 2 == 1):
# offset is odd
index = (offset-1)//2
b = self.dataList[index]
return b & 15 # Get little (last 4 bits) end of byte
else:
# offset is even
index = offset//2
b = self.dataList[index]
return (b >> 4) & 15 # Get big end (first 4 bits) of byte
def get_block_and_data(self, x,y,z, coord=False):
"""Return the tuple of (id, data) for the block at x, y, z"""
return (self.get_block(x,y,z,coord),self.get_data(x,y,z,coord))
|
gpl-2.0
|
[
624,
199,
23555,
282,
2849,
3728,
402,
666,
334,
975,
88,
975,
88,
3933,
5664,
9,
687,
282,
10195,
825,
4800,
3354,
14,
199,
9856,
365,
5544,
22895,
10708,
1454,
14,
199,
624,
199,
504,
5890,
492,
11808,
199,
504,
2702,
492,
1706,
12,
7787,
199,
646,
1625,
12,
3473,
199,
199,
533,
25246,
8,
785,
304,
272,
408,
2543,
367,
6144,
282,
2849,
3728,
1041,
272,
347,
636,
826,
721,
277,
12,
8526,
84,
304,
267,
3728,
63,
576,
275,
8526,
84,
459,
4670,
418,
267,
291,
14,
8032,
275,
3728,
63,
576,
459,
88,
6981,
995,
4604,
63,
576,
459,
90,
6981,
418,
267,
291,
14,
4166,
275,
8651,
3836,
8,
4604,
63,
576,
459,
24996,
2278,
585,
12,
3728,
63,
576,
459,
1451,
2278,
585,
9,
339,
347,
664,
63,
8032,
8,
277,
304,
267,
408,
1767,
314,
8983,
402,
642,
3728,
1041,
267,
372,
334,
277,
14,
8032,
59,
16,
1055,
585,
12,
277,
14,
8032,
59,
17,
1055,
585,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
408,
1767,
282,
6025,
402,
642,
25246,
1041,
267,
372,
298,
9856,
28819,
495,
8,
277,
14,
8032,
59,
16,
29030,
2266,
11,
495,
8,
277,
14,
8032,
59,
17,
566,
21425,
2,
421,
199,
533,
8651,
3836,
8,
785,
304,
272,
408,
714,
23329,
1021,
367,
23654,
543,
282,
8651,
15,
576,
3696,
1625,
1041,
272,
347,
636,
826,
721,
277,
12,
5664,
5571,
29,
403,
12,
666,
5571,
29,
403,
304,
267,
408,
2499,
282,
892,
8651,
3836,
12,
849,
316,
370,
949,
1853,
503,
666,
2783,
1041,
267,
340,
1228,
8,
4166,
5571,
12,
334,
20108,
12,
1625,
14,
1144,
2298,
288,
291,
14,
4166,
1296,
275,
769,
8,
4166,
5571,
9,
267,
587,
26,
288,
291,
14,
4166,
1296,
275,
359,
16,
3672,
708,
14408,
327,
2790,
376,
2701,
1853,
769,
334,
708,
14408,
4811,
402,
4697,
334,
8387,
430,
398,
340,
1228,
8,
576,
5571,
12,
334,
20108,
12,
1625,
14,
1144,
2298,
288,
291,
14,
576,
1296,
275,
769,
8,
576,
5571,
9,
267,
587,
26,
288,
291,
14,
576,
1296,
275,
359,
16,
3672,
975,
8188,
327,
2790,
376,
2701,
666,
769,
334,
708,
14408,
841,
13,
2075,
4811,
402,
4697,
1852,
24619,
1349,
3696,
4811,
9,
339,
327,
2372,
1006,
1853,
4811,
272,
347,
664,
63,
452,
63,
4166,
8,
277,
304,
267,
408,
1767,
314,
5664,
626,
787,
315,
642,
8651,
3836,
1041,
267,
372,
291,
14,
4166,
1296,
339,
327,
2372,
1006,
666,
4811,
272,
347,
664,
63,
452,
63,
576,
8,
277,
304,
267,
408,
1767,
314,
666,
402,
1006,
314,
5664,
315,
642,
8651,
3836,
1041,
267,
5821,
275,
942,
267,
367,
330,
315,
291,
14,
576,
1296,
26,
288,
327,
710,
1642,
3696,
402,
314,
8651,
83,
6572,
17118,
288,
327,
370,
314,
6124,
11307,
16474,
5821,
402,
314,
1642,
3696,
402,
314,
3918,
14,
288,
327,
2845,
370,
314,
10362,
840,
16474,
5821,
12,
465,
1265,
5594,
1420,
14,
288,
5821,
14,
740,
8,
66,
1253,
4114,
9,
327,
491,
390,
1118,
1284,
402,
314,
3696,
288,
5821,
14,
740,
1332,
66,
4331,
841,
9,
1253,
4114,
9,
327,
13123,
1284,
402,
314,
3696,
267,
372,
5821,
339,
327,
2372,
1006,
1853,
4811,
436,
666,
4811,
465,
6346,
272,
347,
664,
63,
452,
63,
4166,
63,
460,
63,
576,
8,
277,
304,
267,
408,
1767,
3865,
5664,
436,
666,
12,
13170,
10451,
465,
6346,
1041,
267,
372,
769,
8,
3065,
8,
277,
14,
362,
63,
452,
63,
4166,
1062,
291,
14,
362,
63,
452,
63,
576,
4059,
339,
347,
664,
63,
4166,
63,
1820,
8,
277,
304,
267,
408,
1767,
282,
2600,
543,
1853,
2762,
19272,
370,
334,
88,
12,
612,
12,
1315,
10477,
267,
1094,
63,
88,
275,
378,
267,
1094,
63,
89,
275,
378,
267,
1094,
63,
90,
275,
378,
267,
5664,
275,
1052,
267,
367,
1853,
63,
344,
315,
291,
14,
4166,
1296,
26,
288,
5664,
7528,
895,
63,
88,
12,
895,
63,
89,
12,
895,
63,
90,
1874,
275,
1853,
63,
344,
288,
1094,
63,
89,
847,
413,
288,
340,
334,
895,
63,
89,
690,
12792,
304,
355,
1094,
63,
89,
275,
378,
355,
1094,
63,
90,
847,
413,
355,
340,
334,
895,
63,
90,
690,
4114,
304,
490,
1094,
63,
90,
275,
378,
490,
1094,
63,
88,
847,
413,
267,
372,
5664,
339,
327,
25495,
1853,
1296,
1771,
465,
282,
3696,
1625,
272,
347,
664,
63,
4166,
63,
4414,
63,
1144,
8,
277,
12,
3335,
29,
797,
304,
267,
408,
1767,
282,
769,
402,
1006,
5664,
315,
642,
3728,
1041,
267,
340,
3335,
26,
288,
2582,
275,
822,
8,
277,
14,
4166,
1296,
9,
288,
372,
11808,
8,
1389,
19651,
73,
401,
2582,
6393,
277,
14,
362,
63,
4166,
63,
4414,
63,
1144,
1012,
267,
587,
26,
288,
372,
1625,
14,
1144,
360,
34,
297,
291,
14,
4166,
1296,
680,
14028,
342,
339,
347,
664,
63,
576,
63,
4414,
63,
1144,
8,
277,
12,
3335,
29,
797,
304,
267,
408,
1767,
282,
769,
402,
666,
367,
1006,
5664,
315,
642,
3728,
1041,
267,
340,
3335,
26,
288,
2582,
275,
822,
8,
277,
14,
576,
1296,
9,
288,
372,
11808,
8,
1389,
19651,
73,
401,
2582,
6393,
277,
14,
362,
63,
576,
63,
4414,
63,
1144,
1012,
267,
587,
26,
288,
372,
1625,
14,
1144,
360,
34,
297,
291,
14,
576,
1296,
680,
14028,
342,
339,
347,
3550,
63,
3333,
1130,
8,
277,
12,
3335,
29,
797,
12,
465,
63,
1144,
29,
797,
304,
267,
408,
1767,
282,
4569,
1130,
12,
6144,
314,
15356,
18609,
5664,
315,
642,
3728,
1041,
267,
2222,
63,
28335,
795,
275,
359,
16,
12,
1695,
12,
1749,
12,
1616,
12,
4119,
12,
10448,
12,
6877,
12,
4337,
12,
7105,
61,
267,
340,
3335,
26,
288,
372,
11808,
8,
1389,
19651,
73,
401,
7633,
6393,
277,
14,
4208,
63,
3333,
1130,
1012,
327,
19893,
435,
5311,
1070,
1130,
12,
10144,
367,
22470,
1901,
25246,
653,
19162,
267,
587,
26,
288,
2783,
275,
942,
288,
367,
1315,
315,
1425,
8,
975,
304,
355,
367,
671,
315,
1425,
8,
975,
304,
490,
367,
612,
315,
1425,
8,
4195,
12,
446,
17
] |
[
199,
23555,
282,
2849,
3728,
402,
666,
334,
975,
88,
975,
88,
3933,
5664,
9,
687,
282,
10195,
825,
4800,
3354,
14,
199,
9856,
365,
5544,
22895,
10708,
1454,
14,
199,
624,
199,
504,
5890,
492,
11808,
199,
504,
2702,
492,
1706,
12,
7787,
199,
646,
1625,
12,
3473,
199,
199,
533,
25246,
8,
785,
304,
272,
408,
2543,
367,
6144,
282,
2849,
3728,
1041,
272,
347,
636,
826,
721,
277,
12,
8526,
84,
304,
267,
3728,
63,
576,
275,
8526,
84,
459,
4670,
418,
267,
291,
14,
8032,
275,
3728,
63,
576,
459,
88,
6981,
995,
4604,
63,
576,
459,
90,
6981,
418,
267,
291,
14,
4166,
275,
8651,
3836,
8,
4604,
63,
576,
459,
24996,
2278,
585,
12,
3728,
63,
576,
459,
1451,
2278,
585,
9,
339,
347,
664,
63,
8032,
8,
277,
304,
267,
408,
1767,
314,
8983,
402,
642,
3728,
1041,
267,
372,
334,
277,
14,
8032,
59,
16,
1055,
585,
12,
277,
14,
8032,
59,
17,
1055,
585,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
408,
1767,
282,
6025,
402,
642,
25246,
1041,
267,
372,
298,
9856,
28819,
495,
8,
277,
14,
8032,
59,
16,
29030,
2266,
11,
495,
8,
277,
14,
8032,
59,
17,
566,
21425,
2,
421,
199,
533,
8651,
3836,
8,
785,
304,
272,
408,
714,
23329,
1021,
367,
23654,
543,
282,
8651,
15,
576,
3696,
1625,
1041,
272,
347,
636,
826,
721,
277,
12,
5664,
5571,
29,
403,
12,
666,
5571,
29,
403,
304,
267,
408,
2499,
282,
892,
8651,
3836,
12,
849,
316,
370,
949,
1853,
503,
666,
2783,
1041,
267,
340,
1228,
8,
4166,
5571,
12,
334,
20108,
12,
1625,
14,
1144,
2298,
288,
291,
14,
4166,
1296,
275,
769,
8,
4166,
5571,
9,
267,
587,
26,
288,
291,
14,
4166,
1296,
275,
359,
16,
3672,
708,
14408,
327,
2790,
376,
2701,
1853,
769,
334,
708,
14408,
4811,
402,
4697,
334,
8387,
430,
398,
340,
1228,
8,
576,
5571,
12,
334,
20108,
12,
1625,
14,
1144,
2298,
288,
291,
14,
576,
1296,
275,
769,
8,
576,
5571,
9,
267,
587,
26,
288,
291,
14,
576,
1296,
275,
359,
16,
3672,
975,
8188,
327,
2790,
376,
2701,
666,
769,
334,
708,
14408,
841,
13,
2075,
4811,
402,
4697,
1852,
24619,
1349,
3696,
4811,
9,
339,
327,
2372,
1006,
1853,
4811,
272,
347,
664,
63,
452,
63,
4166,
8,
277,
304,
267,
408,
1767,
314,
5664,
626,
787,
315,
642,
8651,
3836,
1041,
267,
372,
291,
14,
4166,
1296,
339,
327,
2372,
1006,
666,
4811,
272,
347,
664,
63,
452,
63,
576,
8,
277,
304,
267,
408,
1767,
314,
666,
402,
1006,
314,
5664,
315,
642,
8651,
3836,
1041,
267,
5821,
275,
942,
267,
367,
330,
315,
291,
14,
576,
1296,
26,
288,
327,
710,
1642,
3696,
402,
314,
8651,
83,
6572,
17118,
288,
327,
370,
314,
6124,
11307,
16474,
5821,
402,
314,
1642,
3696,
402,
314,
3918,
14,
288,
327,
2845,
370,
314,
10362,
840,
16474,
5821,
12,
465,
1265,
5594,
1420,
14,
288,
5821,
14,
740,
8,
66,
1253,
4114,
9,
327,
491,
390,
1118,
1284,
402,
314,
3696,
288,
5821,
14,
740,
1332,
66,
4331,
841,
9,
1253,
4114,
9,
327,
13123,
1284,
402,
314,
3696,
267,
372,
5821,
339,
327,
2372,
1006,
1853,
4811,
436,
666,
4811,
465,
6346,
272,
347,
664,
63,
452,
63,
4166,
63,
460,
63,
576,
8,
277,
304,
267,
408,
1767,
3865,
5664,
436,
666,
12,
13170,
10451,
465,
6346,
1041,
267,
372,
769,
8,
3065,
8,
277,
14,
362,
63,
452,
63,
4166,
1062,
291,
14,
362,
63,
452,
63,
576,
4059,
339,
347,
664,
63,
4166,
63,
1820,
8,
277,
304,
267,
408,
1767,
282,
2600,
543,
1853,
2762,
19272,
370,
334,
88,
12,
612,
12,
1315,
10477,
267,
1094,
63,
88,
275,
378,
267,
1094,
63,
89,
275,
378,
267,
1094,
63,
90,
275,
378,
267,
5664,
275,
1052,
267,
367,
1853,
63,
344,
315,
291,
14,
4166,
1296,
26,
288,
5664,
7528,
895,
63,
88,
12,
895,
63,
89,
12,
895,
63,
90,
1874,
275,
1853,
63,
344,
288,
1094,
63,
89,
847,
413,
288,
340,
334,
895,
63,
89,
690,
12792,
304,
355,
1094,
63,
89,
275,
378,
355,
1094,
63,
90,
847,
413,
355,
340,
334,
895,
63,
90,
690,
4114,
304,
490,
1094,
63,
90,
275,
378,
490,
1094,
63,
88,
847,
413,
267,
372,
5664,
339,
327,
25495,
1853,
1296,
1771,
465,
282,
3696,
1625,
272,
347,
664,
63,
4166,
63,
4414,
63,
1144,
8,
277,
12,
3335,
29,
797,
304,
267,
408,
1767,
282,
769,
402,
1006,
5664,
315,
642,
3728,
1041,
267,
340,
3335,
26,
288,
2582,
275,
822,
8,
277,
14,
4166,
1296,
9,
288,
372,
11808,
8,
1389,
19651,
73,
401,
2582,
6393,
277,
14,
362,
63,
4166,
63,
4414,
63,
1144,
1012,
267,
587,
26,
288,
372,
1625,
14,
1144,
360,
34,
297,
291,
14,
4166,
1296,
680,
14028,
342,
339,
347,
664,
63,
576,
63,
4414,
63,
1144,
8,
277,
12,
3335,
29,
797,
304,
267,
408,
1767,
282,
769,
402,
666,
367,
1006,
5664,
315,
642,
3728,
1041,
267,
340,
3335,
26,
288,
2582,
275,
822,
8,
277,
14,
576,
1296,
9,
288,
372,
11808,
8,
1389,
19651,
73,
401,
2582,
6393,
277,
14,
362,
63,
576,
63,
4414,
63,
1144,
1012,
267,
587,
26,
288,
372,
1625,
14,
1144,
360,
34,
297,
291,
14,
576,
1296,
680,
14028,
342,
339,
347,
3550,
63,
3333,
1130,
8,
277,
12,
3335,
29,
797,
12,
465,
63,
1144,
29,
797,
304,
267,
408,
1767,
282,
4569,
1130,
12,
6144,
314,
15356,
18609,
5664,
315,
642,
3728,
1041,
267,
2222,
63,
28335,
795,
275,
359,
16,
12,
1695,
12,
1749,
12,
1616,
12,
4119,
12,
10448,
12,
6877,
12,
4337,
12,
7105,
61,
267,
340,
3335,
26,
288,
372,
11808,
8,
1389,
19651,
73,
401,
7633,
6393,
277,
14,
4208,
63,
3333,
1130,
1012,
327,
19893,
435,
5311,
1070,
1130,
12,
10144,
367,
22470,
1901,
25246,
653,
19162,
267,
587,
26,
288,
2783,
275,
942,
288,
367,
1315,
315,
1425,
8,
975,
304,
355,
367,
671,
315,
1425,
8,
975,
304,
490,
367,
612,
315,
1425,
8,
4195,
12,
446,
17,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
scionoftech/PushyNotification
|
pushy_server/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/engine.io-parser/node_modules/utf8/tests/generate-test-data.py
|
1788
|
1435
|
#!/usr/bin/env python
import re
import json
# https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
# http://stackoverflow.com/a/13436167/96656
def unisymbol(codePoint):
if codePoint >= 0x0000 and codePoint <= 0xFFFF:
return unichr(codePoint)
elif codePoint >= 0x010000 and codePoint <= 0x10FFFF:
highSurrogate = int((codePoint - 0x10000) / 0x400) + 0xD800
lowSurrogate = int((codePoint - 0x10000) % 0x400) + 0xDC00
return unichr(highSurrogate) + unichr(lowSurrogate)
else:
return 'Error'
def hexify(codePoint):
return 'U+' + hex(codePoint)[2:].upper().zfill(6)
def writeFile(filename, contents):
print filename
with open(filename, 'w') as f:
f.write(contents.strip() + '\n')
data = []
for codePoint in range(0x000000, 0x10FFFF + 1):
# Skip non-scalar values.
if codePoint >= 0xD800 and codePoint <= 0xDFFF:
continue
symbol = unisymbol(codePoint)
# http://stackoverflow.com/a/17199950/96656
bytes = symbol.encode('utf8').decode('latin1')
data.append({
'codePoint': codePoint,
'decoded': symbol,
'encoded': bytes
});
jsonData = json.dumps(data, sort_keys=False, indent=2, separators=(',', ': '))
# Use tabs instead of double spaces for indentation
jsonData = jsonData.replace(' ', '\t')
# Escape hexadecimal digits in escape sequences
jsonData = re.sub(
r'\\u([a-fA-F0-9]{4})',
lambda match: r'\u{}'.format(match.group(1).upper()),
jsonData
)
writeFile('data.json', jsonData)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
295,
199,
646,
2022,
199,
199,
3,
4178,
921,
3442,
2241,
991,
78,
8764,
14,
1235,
15,
5983,
15,
9554,
13,
2991,
3,
16380,
13,
964,
348,
3624,
199,
3,
1455,
921,
23153,
14,
957,
15,
65,
15,
7582,
1344,
10806,
15,
30689,
1367,
199,
318,
625,
19765,
2705,
8,
600,
3428,
304,
199,
198,
692,
1233,
3428,
2356,
378,
88,
993,
436,
1233,
3428,
2695,
378,
23973,
26,
507,
198,
1107,
17742,
8,
600,
3428,
9,
199,
198,
4164,
1233,
3428,
2356,
378,
88,
614,
993,
436,
1233,
3428,
2695,
378,
88,
709,
6968,
26,
507,
198,
6260,
11762,
13095,
275,
1109,
1332,
600,
3428,
446,
378,
88,
9943,
9,
1182,
378,
88,
5303,
9,
435,
378,
8313,
6718,
507,
198,
674,
11762,
13095,
275,
1109,
1332,
600,
3428,
446,
378,
88,
9943,
9,
450,
378,
88,
5303,
9,
435,
378,
88,
5196,
383,
507,
198,
1107,
17742,
8,
6260,
11762,
13095,
9,
435,
17742,
8,
674,
11762,
13095,
9,
199,
198,
2836,
26,
507,
198,
1107,
283,
547,
7,
199,
199,
318,
6318,
2021,
8,
600,
3428,
304,
199,
198,
1107,
283,
53,
4786,
435,
6318,
8,
600,
3428,
2788,
18,
11455,
4142,
1252,
26626,
8,
22,
9,
199,
199,
318,
2218,
1173,
8,
1501,
12,
4072,
304,
199,
198,
1361,
1788,
199,
198,
1045,
1551,
8,
1501,
12,
283,
87,
358,
465,
289,
26,
507,
198,
70,
14,
952,
8,
4407,
14,
1913,
342,
435,
1557,
78,
358,
199,
199,
576,
275,
942,
199,
509,
1233,
3428,
315,
1425,
8,
16,
88,
3273,
12,
378,
88,
709,
6968,
435,
413,
304,
199,
198,
3,
8232,
2222,
13,
7033,
1338,
14,
199,
198,
692,
1233,
3428,
2356,
378,
8313,
6718,
436,
1233,
3428,
2695,
378,
8313,
24254,
26,
507,
198,
6958,
199,
198,
5155,
275,
625,
19765,
2705,
8,
600,
3428,
9,
199,
198,
3,
1455,
921,
23153,
14,
957,
15,
65,
15,
13593,
5637,
1400,
15,
30689,
1367,
199,
198,
2394,
275,
5272,
14,
2143,
360,
1624,
24,
1959,
2708,
360,
10378,
17,
358,
199,
198,
576,
14,
740,
2561,
507,
198,
7,
600,
3428,
356,
1233,
3428,
12,
507,
198,
5121,
69,
15282,
356,
5272,
12,
507,
198,
7,
8167,
356,
2783,
199,
198,
32056,
199,
199,
1001,
1451,
275,
2022,
14,
4180,
8,
576,
12,
4069,
63,
1612,
29,
797,
12,
4363,
29,
18,
12,
17658,
2687,
23324,
7596,
20005,
199,
3,
3645,
12187,
3140,
402,
4270,
7883,
367,
14311,
199,
1001,
1451,
275,
2022,
1451,
14,
1814,
360,
221,
1656,
1557,
84,
358,
199,
3,
21067,
20379,
7576,
315,
4772,
8013,
199,
1001,
1451,
275,
295,
14,
954,
8,
199,
198,
82,
8124,
85,
779,
65,
13,
13753,
13,
38,
16,
13,
25,
8194,
20,
25583,
199,
198,
2734,
1336,
26,
519,
1154,
85,
11123,
908,
8,
1431,
14,
923,
8,
17,
680,
4142,
4000,
199,
198,
1001,
1451,
199,
9,
199,
199,
952,
1173,
360,
576,
14,
1001,
297,
2022,
1451,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
295,
199,
646,
2022,
199,
199,
3,
4178,
921,
3442,
2241,
991,
78,
8764,
14,
1235,
15,
5983,
15,
9554,
13,
2991,
3,
16380,
13,
964,
348,
3624,
199,
3,
1455,
921,
23153,
14,
957,
15,
65,
15,
7582,
1344,
10806,
15,
30689,
1367,
199,
318,
625,
19765,
2705,
8,
600,
3428,
304,
199,
198,
692,
1233,
3428,
2356,
378,
88,
993,
436,
1233,
3428,
2695,
378,
23973,
26,
507,
198,
1107,
17742,
8,
600,
3428,
9,
199,
198,
4164,
1233,
3428,
2356,
378,
88,
614,
993,
436,
1233,
3428,
2695,
378,
88,
709,
6968,
26,
507,
198,
6260,
11762,
13095,
275,
1109,
1332,
600,
3428,
446,
378,
88,
9943,
9,
1182,
378,
88,
5303,
9,
435,
378,
8313,
6718,
507,
198,
674,
11762,
13095,
275,
1109,
1332,
600,
3428,
446,
378,
88,
9943,
9,
450,
378,
88,
5303,
9,
435,
378,
88,
5196,
383,
507,
198,
1107,
17742,
8,
6260,
11762,
13095,
9,
435,
17742,
8,
674,
11762,
13095,
9,
199,
198,
2836,
26,
507,
198,
1107,
283,
547,
7,
199,
199,
318,
6318,
2021,
8,
600,
3428,
304,
199,
198,
1107,
283,
53,
4786,
435,
6318,
8,
600,
3428,
2788,
18,
11455,
4142,
1252,
26626,
8,
22,
9,
199,
199,
318,
2218,
1173,
8,
1501,
12,
4072,
304,
199,
198,
1361,
1788,
199,
198,
1045,
1551,
8,
1501,
12,
283,
87,
358,
465,
289,
26,
507,
198,
70,
14,
952,
8,
4407,
14,
1913,
342,
435,
1557,
78,
358,
199,
199,
576,
275,
942,
199,
509,
1233,
3428,
315,
1425,
8,
16,
88,
3273,
12,
378,
88,
709,
6968,
435,
413,
304,
199,
198,
3,
8232,
2222,
13,
7033,
1338,
14,
199,
198,
692,
1233,
3428,
2356,
378,
8313,
6718,
436,
1233,
3428,
2695,
378,
8313,
24254,
26,
507,
198,
6958,
199,
198,
5155,
275,
625,
19765,
2705,
8,
600,
3428,
9,
199,
198,
3,
1455,
921,
23153,
14,
957,
15,
65,
15,
13593,
5637,
1400,
15,
30689,
1367,
199,
198,
2394,
275,
5272,
14,
2143,
360,
1624,
24,
1959,
2708,
360,
10378,
17,
358,
199,
198,
576,
14,
740,
2561,
507,
198,
7,
600,
3428,
356,
1233,
3428,
12,
507,
198,
5121,
69,
15282,
356,
5272,
12,
507,
198,
7,
8167,
356,
2783,
199,
198,
32056,
199,
199,
1001,
1451,
275,
2022,
14,
4180,
8,
576,
12,
4069,
63,
1612,
29,
797,
12,
4363,
29,
18,
12,
17658,
2687,
23324,
7596,
20005,
199,
3,
3645,
12187,
3140,
402,
4270,
7883,
367,
14311,
199,
1001,
1451,
275,
2022,
1451,
14,
1814,
360,
221,
1656,
1557,
84,
358,
199,
3,
21067,
20379,
7576,
315,
4772,
8013,
199,
1001,
1451,
275,
295,
14,
954,
8,
199,
198,
82,
8124,
85,
779,
65,
13,
13753,
13,
38,
16,
13,
25,
8194,
20,
25583,
199,
198,
2734,
1336,
26,
519,
1154,
85,
11123,
908,
8,
1431,
14,
923,
8,
17,
680,
4142,
4000,
199,
198,
1001,
1451,
199,
9,
199,
199,
952,
1173,
360,
576,
14,
1001,
297,
2022,
1451,
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,
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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
] |
marratj/ansible
|
lib/ansible/modules/network/nxos/nxos_portchannel.py
|
10
|
15668
|
#!/usr/bin/python
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'network'}
DOCUMENTATION = '''
---
module: nxos_portchannel
extends_documentation_fragment: nxos
version_added: "2.2"
short_description: Manages port-channel interfaces.
description:
- Manages port-channel specific configuration parameters.
author:
- Jason Edelman (@jedelman8)
- Gabriele Gerbino (@GGabriele)
notes:
- Tested against NXOSv 7.3.(0)D1(1) on VIRL
- C(state=absent) removes the portchannel config and interface if it
already exists. If members to be removed are not explicitly
passed, all existing members (if any), are removed.
- Members must be a list.
- LACP needs to be enabled first if active/passive modes are used.
options:
group:
description:
- Channel-group number for the port-channel.
required: true
mode:
description:
- Mode for the port-channel, i.e. on, active, passive.
required: false
default: on
choices: ['active','passive','on']
min_links:
description:
- Min links required to keep portchannel up.
required: false
default: null
members:
description:
- List of interfaces that will be managed in a given portchannel.
required: false
default: null
force:
description:
- When true it forces port-channel members to match what is
declared in the members param. This can be used to remove
members.
required: false
choices: ['true', 'false']
default: false
state:
description:
- Manage the state of the resource.
required: false
default: present
choices: ['present','absent']
'''
EXAMPLES = '''
# Ensure port-channel99 is created, add two members, and set to mode on
- nxos_portchannel:
group: 99
members: ['Ethernet1/1','Ethernet1/2']
mode: 'active'
state: present
'''
RETURN = '''
commands:
description: command sent to the device
returned: always
type: list
sample: ["interface Ethernet2/6", "no channel-group 12",
"interface Ethernet2/5", "no channel-group 12",
"interface Ethernet2/6", "channel-group 12 mode on",
"interface Ethernet2/5", "channel-group 12 mode on"]
'''
import collections
import re
from ansible.module_utils.nxos import get_config, load_config, run_commands
from ansible.module_utils.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netcfg import CustomNetworkConfig
def get_value(arg, config, module):
param_to_command_keymap = {
'min_links': 'lacp min-links'
}
REGEX = re.compile(r'(?:{0}\s)(?P<value>.*)$'.format(param_to_command_keymap[arg]), re.M)
value = ''
if param_to_command_keymap[arg] in config:
value = REGEX.search(config).group('value')
return value
def check_interface(module, netcfg):
config = str(netcfg)
REGEX = re.compile(r'\s+interface port-channel{0}$'.format(module.params['group']), re.M)
value = False
try:
if REGEX.search(config):
value = True
except TypeError:
value = False
return value
def get_custom_value(arg, config, module):
REGEX = re.compile(r'\s+member vni {0} associate-vrf\s*$'.format(
module.params['vni']), re.M)
value = False
try:
if REGEX.search(config):
value = True
except TypeError:
value = False
return value
def execute_show_command(command, module):
provider = module.params['provider']
if provider['transport'] == 'cli':
if 'show port-channel summary' in command:
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
elif provider['transport'] == 'nxapi':
cmds = [command]
body = run_commands(module, cmds)
return body
def get_portchannel_members(pchannel):
try:
members = pchannel['TABLE_member']['ROW_member']
except KeyError:
members = []
return members
def get_portchannel_mode(interface, protocol, module, netcfg):
if protocol != 'LACP':
mode = 'on'
else:
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
parents = ['interface {0}'.format(interface.capitalize())]
body = netcfg.get_section(parents)
mode_list = body.split('\n')
for line in mode_list:
this_line = line.strip()
if this_line.startswith('channel-group'):
find = this_line
if 'mode' in find:
if 'passive' in find:
mode = 'passive'
elif 'active' in find:
mode = 'active'
return mode
def get_portchannel(module, netcfg=None):
command = 'show port-channel summary'
portchannel = {}
portchannel_table = {}
members = []
try:
body = execute_show_command(command, module)[0]
pc_table = body['TABLE_channel']['ROW_channel']
if isinstance(pc_table, dict):
pc_table = [pc_table]
for pc in pc_table:
if pc['group'] == module.params['group']:
portchannel_table = pc
except (KeyError, AttributeError, TypeError, IndexError):
return {}
if portchannel_table:
portchannel['group'] = portchannel_table['group']
protocol = portchannel_table['prtcl']
members_list = get_portchannel_members(portchannel_table)
if isinstance(members_list, dict):
members_list = [members_list]
member_dictionary = {}
for each_member in members_list:
interface = each_member['port']
members.append(interface)
pc_member = {}
pc_member['status'] = str(each_member['port-status'])
pc_member['mode'] = get_portchannel_mode(interface,
protocol, module, netcfg)
member_dictionary[interface] = pc_member
portchannel['members'] = members
portchannel['members_detail'] = member_dictionary
# Ensure each member have the same mode.
modes = set()
for each, value in member_dictionary.items():
modes.update([value['mode']])
if len(modes) == 1:
portchannel['mode'] = value['mode']
else:
portchannel['mode'] = 'unknown'
return portchannel
def get_existing(module, args):
existing = {}
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
interface_exist = check_interface(module, netcfg)
if interface_exist:
parents = ['interface port-channel{0}'.format(module.params['group'])]
config = netcfg.get_section(parents)
if config:
existing['min_links'] = get_value('min_links', config, module)
existing.update(get_portchannel(module, netcfg=netcfg))
return existing, interface_exist
def config_portchannel(proposed, mode, group, force):
commands = []
# NOTE: Leading whitespace for force option is important
force = ' force' if force else ''
config_args = {
'mode': 'channel-group {group}{force} mode {mode}',
'min_links': 'lacp min-links {min_links}',
}
for member in proposed.get('members', []):
commands.append('interface {0}'.format(member))
commands.append(config_args.get('mode').format(group=group, force=force, mode=mode))
min_links = proposed.get('min_links', None)
if min_links:
command = 'interface port-channel {0}'.format(group)
commands.append(command)
commands.append(config_args.get('min_links').format(
min_links=min_links))
return commands
def get_commands_to_add_members(proposed, existing, force, module):
try:
proposed_members = proposed['members']
except KeyError:
proposed_members = []
try:
existing_members = existing['members']
except KeyError:
existing_members = []
members_to_add = list(set(proposed_members).difference(existing_members))
commands = []
# NOTE: Leading whitespace for force option is important
force = ' force' if force else ''
if members_to_add:
for member in members_to_add:
commands.append('interface {0}'.format(member))
commands.append('channel-group {0}{1} mode {2}'.format(
existing['group'], force, proposed['mode']))
return commands
def get_commands_to_remove_members(proposed, existing, module):
try:
proposed_members = proposed['members']
except KeyError:
proposed_members = []
try:
existing_members = existing['members']
except KeyError:
existing_members = []
members_to_remove = list(set(existing_members).difference(proposed_members))
commands = []
if members_to_remove:
for member in members_to_remove:
commands.append('interface {0}'.format(member))
commands.append('no channel-group {0}'.format(existing['group']))
return commands
def get_commands_if_mode_change(proposed, existing, group, mode, force, module):
try:
proposed_members = proposed['members']
except KeyError:
proposed_members = []
try:
existing_members = existing['members']
except KeyError:
existing_members = []
try:
members_dict = existing['members_detail']
except KeyError:
members_dict = {}
members_to_remove = set(existing_members).difference(proposed_members)
members_with_mode_change = []
if members_dict:
for interface, values in members_dict.items():
if (interface in proposed_members and
(interface not in members_to_remove)):
if values['mode'] != mode:
members_with_mode_change.append(interface)
commands = []
# NOTE: Leading whitespace for force option is important
force = ' force' if force else ''
if members_with_mode_change:
for member in members_with_mode_change:
commands.append('interface {0}'.format(member))
commands.append('no channel-group {0}'.format(group))
for member in members_with_mode_change:
commands.append('interface {0}'.format(member))
commands.append('channel-group {0}{1} mode {2}'.format(group, force, mode))
return commands
def get_commands_min_links(existing, proposed, group, min_links, module):
commands = []
try:
if (existing['min_links'] is None or
(existing['min_links'] != proposed['min_links'])):
commands.append('interface port-channel{0}'.format(group))
commands.append('lacp min-link {0}'.format(min_links))
except KeyError:
commands.append('interface port-channel{0}'.format(group))
commands.append('lacp min-link {0}'.format(min_links))
return commands
def flatten_list(command_lists):
flat_command_list = []
for command in command_lists:
if isinstance(command, list):
flat_command_list.extend(command)
else:
flat_command_list.append(command)
return flat_command_list
def state_present(module, existing, proposed, interface_exist, force, warnings):
commands = []
group = str(module.params['group'])
mode = module.params['mode']
min_links = module.params['min_links']
if not interface_exist:
command = config_portchannel(proposed, mode, group, force)
commands.append(command)
commands.insert(0, 'interface port-channel{0}'.format(group))
warnings.append("The proposed port-channel interface did not "
"exist. It's recommended to use nxos_interface to "
"create all logical interfaces.")
elif existing and interface_exist:
if force:
command = get_commands_to_remove_members(proposed, existing, module)
commands.append(command)
command = get_commands_to_add_members(proposed, existing, force, module)
commands.append(command)
mode_command = get_commands_if_mode_change(proposed, existing, group, mode, force, module)
commands.insert(0, mode_command)
if min_links:
command = get_commands_min_links(existing, proposed, group, min_links, module)
commands.append(command)
return commands
def state_absent(module, existing, proposed):
commands = []
group = str(module.params['group'])
commands.append(['no interface port-channel{0}'.format(group)])
return commands
def main():
argument_spec = dict(
group=dict(required=True, type='str'),
mode=dict(required=False, choices=['on', 'active', 'passive'], default='on', type='str'),
min_links=dict(required=False, default=None, type='str'),
members=dict(required=False, default=None, type='list'),
force=dict(required=False, default='false', type='str', choices=['true', 'false']),
state=dict(required=False, choices=['absent', 'present'], default='present'),
include_defaults=dict(default=False),
config=dict(),
save=dict(type='bool', default=False)
)
argument_spec.update(nxos_argument_spec)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
warnings = list()
check_args(module, warnings)
results = dict(changed=False, warnings=warnings)
group = str(module.params['group'])
mode = module.params['mode']
min_links = module.params['min_links']
members = module.params['members']
state = module.params['state']
if str(module.params['force']).lower() == 'true':
force = True
elif module.params['force'] == 'false':
force = False
if ((min_links or mode) and
(not members and state == 'present')):
module.fail_json(msg='"members" is required when state=present and '
'"min_links" or "mode" are provided')
args = [
'group',
'members',
'min_links',
'mode'
]
existing, interface_exist = get_existing(module, args)
proposed = dict((k, v) for k, v in module.params.items()
if v is not None and k in args)
commands = []
if state == 'absent' and existing:
commands = state_absent(module, existing, proposed)
elif state == 'present':
commands = state_present(module, existing, proposed, interface_exist, force, warnings)
cmds = flatten_list(commands)
if cmds:
if module.check_mode:
module.exit_json(**results)
else:
load_config(module, cmds)
results['changed'] = True
if 'configure' in cmds:
cmds.pop(0)
results['commands'] = cmds
module.exit_json(**results)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
1200,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
22072,
63,
719,
2775,
199,
11036,
63,
9970,
63,
7677,
26,
22072,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
21612,
1844,
13,
2775,
8386,
14,
199,
1802,
26,
523,
446,
21612,
1844,
13,
2775,
2488,
2897,
2633,
14,
199,
2502,
26,
523,
446,
1603,
2660,
662,
2264,
1237,
8593,
6532,
2264,
1237,
24,
9,
523,
446,
598,
371,
322,
8081,
22261,
1393,
79,
8593,
2916,
371,
322,
8081,
9,
199,
5983,
26,
523,
446,
30568,
6169,
653,
56,
3100,
86,
1520,
14,
19,
14,
8,
16,
9,
36,
17,
8,
17,
9,
641,
812,
41,
2431,
523,
446,
445,
8,
929,
29,
5575,
9,
14185,
314,
1844,
2775,
1101,
436,
3217,
340,
652,
272,
2575,
3495,
14,
982,
7556,
370,
506,
4829,
787,
440,
7662,
272,
3032,
12,
1006,
3411,
7556,
334,
692,
1263,
395,
787,
4829,
14,
523,
446,
14409,
83,
1471,
506,
282,
769,
14,
523,
446,
491,
1348,
48,
4839,
370,
506,
5223,
1642,
340,
4702,
15,
25166,
12404,
787,
1202,
14,
199,
1419,
26,
523,
1572,
26,
272,
1369,
26,
489,
446,
17270,
13,
923,
1329,
367,
314,
1844,
13,
2775,
14,
272,
1415,
26,
2549,
523,
818,
26,
272,
1369,
26,
489,
446,
4900,
367,
314,
1844,
13,
2775,
12,
284,
14,
69,
14,
641,
12,
4702,
12,
21010,
14,
272,
1415,
26,
3055,
272,
849,
26,
641,
272,
3415,
26,
788,
2682,
1673,
25166,
1673,
265,
418,
523,
1748,
63,
4614,
26,
272,
1369,
26,
489,
446,
10195,
6220,
1415,
370,
4215,
1844,
2775,
1536,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
7556,
26,
272,
1369,
26,
489,
446,
3820,
402,
8386,
626,
911,
506,
12883,
315,
282,
1627,
1844,
2775,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
3542,
26,
272,
1369,
26,
489,
446,
3979,
2549,
652,
25983,
1844,
13,
2775,
7556,
370,
1336,
4052,
365,
267,
14290,
315,
314,
7556,
1215,
14,
961,
883,
506,
1202,
370,
2813,
267,
7556,
14,
272,
1415,
26,
3055,
272,
3415,
26,
788,
2052,
297,
283,
3910,
418,
272,
849,
26,
3055,
523,
1174,
26,
272,
1369,
26,
489,
446,
14944,
314,
1174,
402,
314,
2073,
14,
272,
1415,
26,
3055,
272,
849,
26,
3451,
272,
3415,
26,
788,
1881,
1673,
5575,
418,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
7523,
1844,
13,
2775,
1020,
365,
2737,
12,
1050,
2877,
7556,
12,
436,
663,
370,
818,
641,
199,
13,
22072,
63,
719,
2775,
26,
272,
1572,
26,
8806,
272,
7556,
26,
788,
22056,
17,
15,
17,
1673,
22056,
17,
15,
18,
418,
272,
818,
26,
283,
2682,
7,
272,
1174,
26,
3451,
199,
2344,
199,
199,
9677,
275,
1449,
199,
4405,
26,
272,
1369,
26,
1414,
4847,
370,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
769,
272,
2690,
26,
2097,
3266,
26125,
18,
15,
22,
401,
298,
889,
3623,
13,
923,
3144,
401,
1467,
298,
3266,
26125,
18,
15,
21,
401,
298,
889,
3623,
13,
923,
3144,
401,
1467,
298,
3266,
26125,
18,
15,
22,
401,
298,
2775,
13,
923,
3144,
818,
641,
401,
1467,
298,
3266,
26125,
18,
15,
21,
401,
298,
2775,
13,
923,
3144,
818,
641,
937,
199,
2344,
199,
199,
646,
5055,
199,
646,
295,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
17982,
492,
664,
63,
888,
12,
2248,
63,
888,
12,
1255,
63,
4405,
199,
504,
3242,
14,
578,
63,
1208,
14,
17982,
492,
22072,
63,
2094,
63,
1650,
12,
1104,
63,
589,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
846,
4128,
492,
8388,
4491,
2028,
421,
199,
318,
664,
63,
585,
8,
1273,
12,
1101,
12,
859,
304,
272,
1215,
63,
475,
63,
1531,
63,
19624,
275,
469,
267,
283,
827,
63,
4614,
356,
283,
416,
1850,
1748,
13,
4614,
7,
272,
789,
339,
14142,
1438,
275,
295,
14,
2014,
8,
82,
20459,
91,
16,
4988,
83,
18168,
48,
28,
585,
26343,
4,
1370,
908,
8,
635,
63,
475,
63,
1531,
63,
19624,
59,
1273,
2522,
295,
14,
45,
9,
272,
574,
275,
2125,
272,
340,
1215,
63,
475,
63,
1531,
63,
19624,
59,
1273,
61,
315,
1101,
26,
267,
574,
275,
14142,
1438,
14,
1733,
8,
888,
680,
923,
360,
585,
358,
272,
372,
574,
421,
199,
318,
1104,
63,
3266,
8,
578,
12,
1851,
4128,
304,
272,
1101,
275,
620,
8,
846,
4128,
9,
272,
14142,
1438,
275,
295,
14,
2014,
8,
82,
1154,
83,
11,
3266,
1844,
13,
2775,
91,
16,
93,
4,
1370,
908,
8,
578,
14,
1162,
459,
923,
3815,
295,
14,
45,
9,
272,
574,
275,
756,
272,
862,
26,
267,
340,
14142,
1438,
14,
1733,
8,
888,
304,
288,
574,
275,
715,
272,
871,
3146,
26,
267,
574,
275,
756,
339,
372,
574,
421,
199,
318,
664,
63,
4229,
63,
585,
8,
1273,
12,
1101,
12,
859
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
1200,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
22072,
63,
719,
2775,
199,
11036,
63,
9970,
63,
7677,
26,
22072,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
21612,
1844,
13,
2775,
8386,
14,
199,
1802,
26,
523,
446,
21612,
1844,
13,
2775,
2488,
2897,
2633,
14,
199,
2502,
26,
523,
446,
1603,
2660,
662,
2264,
1237,
8593,
6532,
2264,
1237,
24,
9,
523,
446,
598,
371,
322,
8081,
22261,
1393,
79,
8593,
2916,
371,
322,
8081,
9,
199,
5983,
26,
523,
446,
30568,
6169,
653,
56,
3100,
86,
1520,
14,
19,
14,
8,
16,
9,
36,
17,
8,
17,
9,
641,
812,
41,
2431,
523,
446,
445,
8,
929,
29,
5575,
9,
14185,
314,
1844,
2775,
1101,
436,
3217,
340,
652,
272,
2575,
3495,
14,
982,
7556,
370,
506,
4829,
787,
440,
7662,
272,
3032,
12,
1006,
3411,
7556,
334,
692,
1263,
395,
787,
4829,
14,
523,
446,
14409,
83,
1471,
506,
282,
769,
14,
523,
446,
491,
1348,
48,
4839,
370,
506,
5223,
1642,
340,
4702,
15,
25166,
12404,
787,
1202,
14,
199,
1419,
26,
523,
1572,
26,
272,
1369,
26,
489,
446,
17270,
13,
923,
1329,
367,
314,
1844,
13,
2775,
14,
272,
1415,
26,
2549,
523,
818,
26,
272,
1369,
26,
489,
446,
4900,
367,
314,
1844,
13,
2775,
12,
284,
14,
69,
14,
641,
12,
4702,
12,
21010,
14,
272,
1415,
26,
3055,
272,
849,
26,
641,
272,
3415,
26,
788,
2682,
1673,
25166,
1673,
265,
418,
523,
1748,
63,
4614,
26,
272,
1369,
26,
489,
446,
10195,
6220,
1415,
370,
4215,
1844,
2775,
1536,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
7556,
26,
272,
1369,
26,
489,
446,
3820,
402,
8386,
626,
911,
506,
12883,
315,
282,
1627,
1844,
2775,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
3542,
26,
272,
1369,
26,
489,
446,
3979,
2549,
652,
25983,
1844,
13,
2775,
7556,
370,
1336,
4052,
365,
267,
14290,
315,
314,
7556,
1215,
14,
961,
883,
506,
1202,
370,
2813,
267,
7556,
14,
272,
1415,
26,
3055,
272,
3415,
26,
788,
2052,
297,
283,
3910,
418,
272,
849,
26,
3055,
523,
1174,
26,
272,
1369,
26,
489,
446,
14944,
314,
1174,
402,
314,
2073,
14,
272,
1415,
26,
3055,
272,
849,
26,
3451,
272,
3415,
26,
788,
1881,
1673,
5575,
418,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
7523,
1844,
13,
2775,
1020,
365,
2737,
12,
1050,
2877,
7556,
12,
436,
663,
370,
818,
641,
199,
13,
22072,
63,
719,
2775,
26,
272,
1572,
26,
8806,
272,
7556,
26,
788,
22056,
17,
15,
17,
1673,
22056,
17,
15,
18,
418,
272,
818,
26,
283,
2682,
7,
272,
1174,
26,
3451,
199,
2344,
199,
199,
9677,
275,
1449,
199,
4405,
26,
272,
1369,
26,
1414,
4847,
370,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
769,
272,
2690,
26,
2097,
3266,
26125,
18,
15,
22,
401,
298,
889,
3623,
13,
923,
3144,
401,
1467,
298,
3266,
26125,
18,
15,
21,
401,
298,
889,
3623,
13,
923,
3144,
401,
1467,
298,
3266,
26125,
18,
15,
22,
401,
298,
2775,
13,
923,
3144,
818,
641,
401,
1467,
298,
3266,
26125,
18,
15,
21,
401,
298,
2775,
13,
923,
3144,
818,
641,
937,
199,
2344,
199,
199,
646,
5055,
199,
646,
295,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
17982,
492,
664,
63,
888,
12,
2248,
63,
888,
12,
1255,
63,
4405,
199,
504,
3242,
14,
578,
63,
1208,
14,
17982,
492,
22072,
63,
2094,
63,
1650,
12,
1104,
63,
589,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
846,
4128,
492,
8388,
4491,
2028,
421,
199,
318,
664,
63,
585,
8,
1273,
12,
1101,
12,
859,
304,
272,
1215,
63,
475,
63,
1531,
63,
19624,
275,
469,
267,
283,
827,
63,
4614,
356,
283,
416,
1850,
1748,
13,
4614,
7,
272,
789,
339,
14142,
1438,
275,
295,
14,
2014,
8,
82,
20459,
91,
16,
4988,
83,
18168,
48,
28,
585,
26343,
4,
1370,
908,
8,
635,
63,
475,
63,
1531,
63,
19624,
59,
1273,
2522,
295,
14,
45,
9,
272,
574,
275,
2125,
272,
340,
1215,
63,
475,
63,
1531,
63,
19624,
59,
1273,
61,
315,
1101,
26,
267,
574,
275,
14142,
1438,
14,
1733,
8,
888,
680,
923,
360,
585,
358,
272,
372,
574,
421,
199,
318,
1104,
63,
3266,
8,
578,
12,
1851,
4128,
304,
272,
1101,
275,
620,
8,
846,
4128,
9,
272,
14142,
1438,
275,
295,
14,
2014,
8,
82,
1154,
83,
11,
3266,
1844,
13,
2775,
91,
16,
93,
4,
1370,
908,
8,
578,
14,
1162,
459,
923,
3815,
295,
14,
45,
9,
272,
574,
275,
756,
272,
862,
26,
267,
340,
14142,
1438,
14,
1733,
8,
888,
304,
288,
574,
275,
715,
272,
871,
3146,
26,
267,
574,
275,
756,
339,
372,
574,
421,
199,
318,
664,
63,
4229,
63,
585,
8,
1273,
12,
1101,
12,
859,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
georgemarshall/django
|
django/db/backends/sqlite3/operations.py
|
5
|
14006
|
import datetime
import decimal
import uuid
from functools import lru_cache
from itertools import chain
from django.conf import settings
from django.core.exceptions import FieldError
from django.db import utils
from django.db.backends.base.operations import BaseDatabaseOperations
from django.db.models import aggregates, fields
from django.db.models.expressions import Col
from django.utils import timezone
from django.utils.dateparse import parse_date, parse_datetime, parse_time
from django.utils.duration import duration_microseconds
from django.utils.functional import cached_property
class DatabaseOperations(BaseDatabaseOperations):
cast_char_field_without_max_length = 'text'
cast_data_types = {
'DateField': 'TEXT',
'DateTimeField': 'TEXT',
}
explain_prefix = 'EXPLAIN QUERY PLAN'
def bulk_batch_size(self, fields, objs):
"""
SQLite has a compile-time default (SQLITE_LIMIT_VARIABLE_NUMBER) of
999 variables per query.
If there's only a single field to insert, the limit is 500
(SQLITE_MAX_COMPOUND_SELECT).
"""
if len(fields) == 1:
return 500
elif len(fields) > 1:
return self.connection.features.max_query_params // len(fields)
else:
return len(objs)
def check_expression_support(self, expression):
bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
if isinstance(expression, bad_aggregates):
for expr in expression.get_source_expressions():
try:
output_field = expr.output_field
except (AttributeError, FieldError):
# Not every subexpression has an output_field which is fine
# to ignore.
pass
else:
if isinstance(output_field, bad_fields):
raise utils.NotSupportedError(
'You cannot use Sum, Avg, StdDev, and Variance '
'aggregations on date/time fields in sqlite3 '
'since date/time is saved as text.'
)
if isinstance(expression, aggregates.Aggregate) and len(expression.source_expressions) > 1:
raise utils.NotSupportedError(
"SQLite doesn't support DISTINCT on aggregate functions "
"accepting multiple arguments."
)
def date_extract_sql(self, lookup_type, field_name):
"""
Support EXTRACT with a user-defined function django_date_extract()
that's registered in connect(). Use single quotes because this is a
string and could otherwise cause a collision with a field name.
"""
return "django_date_extract('%s', %s)" % (lookup_type.lower(), field_name)
def date_interval_sql(self, timedelta):
return str(duration_microseconds(timedelta))
def format_for_duration_arithmetic(self, sql):
"""Do nothing since formatting is handled in the custom function."""
return sql
def date_trunc_sql(self, lookup_type, field_name):
return "django_date_trunc('%s', %s)" % (lookup_type.lower(), field_name)
def time_trunc_sql(self, lookup_type, field_name):
return "django_time_trunc('%s', %s)" % (lookup_type.lower(), field_name)
def _convert_tznames_to_sql(self, tzname):
if settings.USE_TZ:
return "'%s'" % tzname, "'%s'" % self.connection.timezone_name
return 'NULL', 'NULL'
def datetime_cast_date_sql(self, field_name, tzname):
return 'django_datetime_cast_date(%s, %s, %s)' % (
field_name, *self._convert_tznames_to_sql(tzname),
)
def datetime_cast_time_sql(self, field_name, tzname):
return 'django_datetime_cast_time(%s, %s, %s)' % (
field_name, *self._convert_tznames_to_sql(tzname),
)
def datetime_extract_sql(self, lookup_type, field_name, tzname):
return "django_datetime_extract('%s', %s, %s, %s)" % (
lookup_type.lower(), field_name, *self._convert_tznames_to_sql(tzname),
)
def datetime_trunc_sql(self, lookup_type, field_name, tzname):
return "django_datetime_trunc('%s', %s, %s, %s)" % (
lookup_type.lower(), field_name, *self._convert_tznames_to_sql(tzname),
)
def time_extract_sql(self, lookup_type, field_name):
return "django_time_extract('%s', %s)" % (lookup_type.lower(), field_name)
def pk_default_value(self):
return "NULL"
def _quote_params_for_last_executed_query(self, params):
"""
Only for last_executed_query! Don't use this to execute SQL queries!
"""
# This function is limited both by SQLITE_LIMIT_VARIABLE_NUMBER (the
# number of parameters, default = 999) and SQLITE_MAX_COLUMN (the
# number of return values, default = 2000). Since Python's sqlite3
# module doesn't expose the get_limit() C API, assume the default
# limits are in effect and split the work in batches if needed.
BATCH_SIZE = 999
if len(params) > BATCH_SIZE:
results = ()
for index in range(0, len(params), BATCH_SIZE):
chunk = params[index:index + BATCH_SIZE]
results += self._quote_params_for_last_executed_query(chunk)
return results
sql = 'SELECT ' + ', '.join(['QUOTE(?)'] * len(params))
# Bypass Django's wrappers and use the underlying sqlite3 connection
# to avoid logging this query - it would trigger infinite recursion.
cursor = self.connection.connection.cursor()
# Native sqlite3 cursors cannot be used as context managers.
try:
return cursor.execute(sql, params).fetchone()
finally:
cursor.close()
def last_executed_query(self, cursor, sql, params):
# Python substitutes parameters in Modules/_sqlite/cursor.c with:
# pysqlite_statement_bind_parameters(self->statement, parameters, allow_8bit_chars);
# Unfortunately there is no way to reach self->statement from Python,
# so we quote and substitute parameters manually.
if params:
if isinstance(params, (list, tuple)):
params = self._quote_params_for_last_executed_query(params)
else:
values = tuple(params.values())
values = self._quote_params_for_last_executed_query(values)
params = dict(zip(params, values))
return sql % params
# For consistency with SQLiteCursorWrapper.execute(), just return sql
# when there are no parameters. See #13648 and #17158.
else:
return sql
def quote_name(self, name):
if name.startswith('"') and name.endswith('"'):
return name # Quoting once is enough.
return '"%s"' % name
def no_limit_value(self):
return -1
def __references_graph(self, table_name):
query = """
WITH tables AS (
SELECT %s name
UNION
SELECT sqlite_master.name
FROM sqlite_master
JOIN tables ON (sql REGEXP %s || tables.name || %s)
) SELECT name FROM tables;
"""
params = (
table_name,
r'(?i)\s+references\s+("|\')?',
r'("|\')?\s*\(',
)
with self.connection.cursor() as cursor:
results = cursor.execute(query, params)
return [row[0] for row in results.fetchall()]
@cached_property
def _references_graph(self):
# 512 is large enough to fit the ~330 tables (as of this writing) in
# Django's test suite.
return lru_cache(maxsize=512)(self.__references_graph)
def sql_flush(self, style, tables, sequences, allow_cascade=False):
if tables and allow_cascade:
# Simulate TRUNCATE CASCADE by recursively collecting the tables
# referencing the tables to be flushed.
tables = set(chain.from_iterable(self._references_graph(table) for table in tables))
# Note: No requirement for reset of auto-incremented indices (cf. other
# sql_flush() implementations). Just return SQL at this point
return ['%s %s %s;' % (
style.SQL_KEYWORD('DELETE'),
style.SQL_KEYWORD('FROM'),
style.SQL_FIELD(self.quote_name(table))
) for table in tables]
def adapt_datetimefield_value(self, value):
if value is None:
return None
# Expression values are adapted by the database.
if hasattr(value, 'resolve_expression'):
return value
# SQLite doesn't support tz-aware datetimes
if timezone.is_aware(value):
if settings.USE_TZ:
value = timezone.make_naive(value, self.connection.timezone)
else:
raise ValueError("SQLite backend does not support timezone-aware datetimes when USE_TZ is False.")
return str(value)
def adapt_timefield_value(self, value):
if value is None:
return None
# Expression values are adapted by the database.
if hasattr(value, 'resolve_expression'):
return value
# SQLite doesn't support tz-aware datetimes
if timezone.is_aware(value):
raise ValueError("SQLite backend does not support timezone-aware times.")
return str(value)
def get_db_converters(self, expression):
converters = super().get_db_converters(expression)
internal_type = expression.output_field.get_internal_type()
if internal_type == 'DateTimeField':
converters.append(self.convert_datetimefield_value)
elif internal_type == 'DateField':
converters.append(self.convert_datefield_value)
elif internal_type == 'TimeField':
converters.append(self.convert_timefield_value)
elif internal_type == 'DecimalField':
converters.append(self.get_decimalfield_converter(expression))
elif internal_type == 'UUIDField':
converters.append(self.convert_uuidfield_value)
elif internal_type in ('NullBooleanField', 'BooleanField'):
converters.append(self.convert_booleanfield_value)
return converters
def convert_datetimefield_value(self, value, expression, connection):
if value is not None:
if not isinstance(value, datetime.datetime):
value = parse_datetime(value)
if settings.USE_TZ and not timezone.is_aware(value):
value = timezone.make_aware(value, self.connection.timezone)
return value
def convert_datefield_value(self, value, expression, connection):
if value is not None:
if not isinstance(value, datetime.date):
value = parse_date(value)
return value
def convert_timefield_value(self, value, expression, connection):
if value is not None:
if not isinstance(value, datetime.time):
value = parse_time(value)
return value
def get_decimalfield_converter(self, expression):
# SQLite stores only 15 significant digits. Digits coming from
# float inaccuracy must be removed.
create_decimal = decimal.Context(prec=15).create_decimal_from_float
if isinstance(expression, Col):
quantize_value = decimal.Decimal(1).scaleb(-expression.output_field.decimal_places)
def converter(value, expression, connection):
if value is not None:
return create_decimal(value).quantize(quantize_value, context=expression.output_field.context)
else:
def converter(value, expression, connection):
if value is not None:
return create_decimal(value)
return converter
def convert_uuidfield_value(self, value, expression, connection):
if value is not None:
value = uuid.UUID(value)
return value
def convert_booleanfield_value(self, value, expression, connection):
return bool(value) if value in (1, 0) else value
def bulk_insert_sql(self, fields, placeholder_rows):
return " UNION ALL ".join(
"SELECT %s" % ", ".join(row)
for row in placeholder_rows
)
def combine_expression(self, connector, sub_expressions):
# SQLite doesn't have a ^ operator, so use the user-defined POWER
# function that's registered in connect().
if connector == '^':
return 'POWER(%s)' % ','.join(sub_expressions)
return super().combine_expression(connector, sub_expressions)
def combine_duration_expression(self, connector, sub_expressions):
if connector not in ['+', '-']:
raise utils.DatabaseError('Invalid connector for timedelta: %s.' % connector)
fn_params = ["'%s'" % connector] + sub_expressions
if len(fn_params) > 3:
raise ValueError('Too many params for timedelta operations.')
return "django_format_dtdelta(%s)" % ', '.join(fn_params)
def integer_field_range(self, internal_type):
# SQLite doesn't enforce any integer constraints
return (None, None)
def subtract_temporals(self, internal_type, lhs, rhs):
lhs_sql, lhs_params = lhs
rhs_sql, rhs_params = rhs
if internal_type == 'TimeField':
return "django_time_diff(%s, %s)" % (lhs_sql, rhs_sql), lhs_params + rhs_params
return "django_timestamp_diff(%s, %s)" % (lhs_sql, rhs_sql), lhs_params + rhs_params
def insert_statement(self, ignore_conflicts=False):
return 'INSERT OR IGNORE INTO' if ignore_conflicts else super().insert_statement(ignore_conflicts)
|
bsd-3-clause
|
[
646,
2197,
199,
646,
6107,
199,
646,
5377,
199,
504,
9143,
492,
634,
6558,
63,
1637,
199,
504,
7975,
492,
6036,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
27691,
199,
504,
1639,
14,
697,
492,
3778,
199,
504,
1639,
14,
697,
14,
7765,
14,
1095,
14,
8170,
492,
29103,
12929,
199,
504,
1639,
14,
697,
14,
992,
492,
27535,
12,
1504,
199,
504,
1639,
14,
697,
14,
992,
14,
15264,
492,
3626,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
1208,
14,
602,
1122,
492,
2198,
63,
602,
12,
2198,
63,
2083,
12,
2198,
63,
521,
199,
504,
1639,
14,
1208,
14,
5553,
492,
7373,
63,
18144,
199,
504,
1639,
14,
1208,
14,
15481,
492,
6328,
63,
1829,
421,
199,
533,
8692,
12929,
8,
1563,
7243,
12929,
304,
272,
9106,
63,
1560,
63,
698,
63,
7395,
63,
988,
63,
1267,
275,
283,
505,
7,
272,
9106,
63,
576,
63,
1313,
275,
469,
267,
283,
14071,
356,
283,
3876,
297,
267,
283,
4626,
356,
283,
3876,
297,
272,
789,
272,
27797,
63,
1861,
275,
283,
1438,
2749,
9021,
7813,
9418,
10092,
879,
7,
339,
347,
13137,
63,
2912,
63,
890,
8,
277,
12,
1504,
12,
13474,
304,
267,
408,
267,
19245,
965,
282,
6555,
13,
521,
849,
334,
4657,
4427,
63,
13387,
63,
23129,
63,
9190,
9,
402,
267,
22291,
2860,
1126,
1827,
14,
398,
982,
2337,
1159,
1454,
282,
2849,
901,
370,
5518,
12,
314,
2304,
365,
6891,
267,
334,
4657,
4427,
63,
4283,
63,
11265,
1512,
6131,
63,
4859,
680,
267,
408,
267,
340,
822,
8,
955,
9,
508,
413,
26,
288,
372,
6891,
267,
916,
822,
8,
955,
9,
690,
413,
26,
288,
372,
291,
14,
2105,
14,
3179,
14,
988,
63,
1131,
63,
1162,
5001,
822,
8,
955,
9,
267,
587,
26,
288,
372,
822,
8,
8718,
9,
339,
347,
1104,
63,
5599,
63,
4058,
8,
277,
12,
3965,
304,
267,
4875,
63,
955,
275,
334,
955,
14,
14071,
12,
1504,
14,
4626,
12,
1504,
14,
27115,
9,
267,
4875,
63,
21622,
275,
334,
21622,
14,
6959,
12,
27535,
14,
16650,
12,
27535,
14,
31805,
12,
27535,
14,
11976,
12680,
9,
267,
340,
1228,
8,
5599,
12,
4875,
63,
21622,
304,
288,
367,
5348,
315,
3965,
14,
362,
63,
1365,
63,
15264,
837,
355,
862,
26,
490,
1072,
63,
698,
275,
5348,
14,
1199,
63,
698,
355,
871,
334,
10227,
12,
27691,
304,
490,
327,
2832,
4036,
1007,
5599,
965,
376,
1072,
63,
698,
1314,
365,
15701,
490,
327,
370,
3686,
14,
490,
986,
355,
587,
26,
490,
340,
1228,
8,
1199,
63,
698,
12,
4875,
63,
955,
304,
717,
746,
3778,
14,
26077,
547,
8,
1169,
283,
5556,
3913,
675,
12094,
12,
437,
10929,
12,
20992,
12680,
12,
436,
21107,
554,
283,
1169,
283,
10978,
1298,
641,
1434,
15,
521,
1504,
315,
11723,
19,
283,
1169,
283,
8585,
1434,
15,
521,
365,
6290,
465,
1318,
3530,
717,
776,
267,
340,
1228,
8,
5599,
12,
27535,
14,
10170,
9,
436,
822,
8,
5599,
14,
1365,
63,
15264,
9,
690,
413,
26,
288,
746,
3778,
14,
26077,
547,
8,
355,
298,
4657,
1175,
3181,
1133,
2291,
28424,
28437,
641,
9531,
3423,
298,
355,
298,
5694,
316,
3663,
2368,
2122,
288,
776,
339,
347,
1434,
63,
5005,
63,
3009,
8,
277,
12,
4237,
63,
466,
12,
901,
63,
354,
304,
267,
408,
267,
12502,
3651,
22280,
543,
282,
922,
13,
4037,
805,
1639,
63,
602,
63,
5005,
342,
267,
626,
1159,
7264,
315,
4907,
1252,
3645,
2849,
9344,
2952,
642,
365,
282,
267,
1059,
436,
4293,
4257,
7675,
282,
25061,
543,
282,
901,
536,
14,
267,
408,
267,
372,
298,
1176,
63,
602,
63,
5005,
3508,
83,
297,
450,
83,
2924,
450,
334,
3892,
63,
466,
14,
2325,
1062,
901,
63,
354,
9,
339,
347,
1434,
63,
4284,
63,
3009,
8,
277,
12,
6871,
304,
267,
372,
620,
8,
5553,
63,
18144,
8,
7473,
430,
339,
347,
1475,
63,
509,
63,
5553,
63,
18327,
15307,
8,
277,
12,
3875,
304,
267,
408,
2585,
6548,
3967,
10803,
365,
8860,
315,
314,
3537,
805,
1041,
267,
372,
3875,
339,
347,
1434,
63,
8208,
63,
3009,
8,
277,
12,
4237,
63,
466,
12,
901,
63,
354,
304,
267,
372,
298,
1176,
63,
602,
63,
8208,
3508,
83,
297,
450,
83,
2924,
450,
334,
3892,
63,
466,
14,
2325,
1062,
901,
63,
354,
9,
339,
347,
900,
63,
8208,
63,
3009,
8,
277,
12,
4237,
63,
466,
12,
901,
63,
354,
304,
267,
372,
298,
1176,
63,
521,
63,
8208,
3508,
83,
297,
450,
83,
2924,
450,
334,
3892,
63,
466,
14,
2325,
1062,
901,
63,
354,
9,
339,
347,
485,
3916,
63,
3903,
1247,
63,
475,
63,
3009,
8,
277,
12,
28054,
304,
267,
340,
2202,
14,
4701,
63,
14226,
26,
288,
372,
17648,
83,
4065,
450,
28054,
12,
17648,
83,
4065,
450,
291,
14,
2105,
14,
7145,
63,
354,
267,
372,
283,
8084,
297,
283,
8084,
7,
339,
347,
2197,
63,
2931,
63,
602,
63,
3009,
8,
277,
12,
901,
63,
354,
12,
28054,
304,
267,
372,
283,
1176,
63,
2083,
63,
2931,
63,
602,
4042,
83,
12,
450,
83,
12,
450,
83,
3171,
450,
334,
288,
901,
63,
354,
12,
627,
277,
423,
3916,
63,
3903,
1247,
63,
475,
63,
3009,
8,
20027,
395,
267,
776,
339,
347,
2197,
63,
2931,
63,
521,
63,
3009,
8,
277,
12,
901,
63,
354,
12,
28054,
304,
267,
372,
283,
1176,
63,
2083,
63,
2931,
63,
521,
4042,
83,
12,
450,
83,
12,
450,
83,
3171,
450,
334,
288,
901,
63,
354,
12,
627,
277,
423,
3916,
63,
3903,
1247,
63,
475,
63,
3009,
8,
20027,
395,
267,
776,
339,
347,
2197,
63,
5005,
63,
3009,
8,
277,
12,
4237,
63,
466,
12,
901,
63,
354,
12,
28054,
304,
267,
372,
298,
1176,
63,
2083,
63,
5005,
3508,
83,
297,
450,
83,
12,
450,
83,
12,
450,
83,
2924,
450,
334,
288,
4237,
63,
466,
14,
2325,
1062,
901,
63,
354,
12,
627,
277,
423,
3916,
63,
3903,
1247,
63,
475,
63,
3009,
8,
20027,
395,
267,
776,
339,
347,
2197,
63,
8208,
63,
3009
] |
[
2197,
199,
646,
6107,
199,
646,
5377,
199,
504,
9143,
492,
634,
6558,
63,
1637,
199,
504,
7975,
492,
6036,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
27691,
199,
504,
1639,
14,
697,
492,
3778,
199,
504,
1639,
14,
697,
14,
7765,
14,
1095,
14,
8170,
492,
29103,
12929,
199,
504,
1639,
14,
697,
14,
992,
492,
27535,
12,
1504,
199,
504,
1639,
14,
697,
14,
992,
14,
15264,
492,
3626,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
1208,
14,
602,
1122,
492,
2198,
63,
602,
12,
2198,
63,
2083,
12,
2198,
63,
521,
199,
504,
1639,
14,
1208,
14,
5553,
492,
7373,
63,
18144,
199,
504,
1639,
14,
1208,
14,
15481,
492,
6328,
63,
1829,
421,
199,
533,
8692,
12929,
8,
1563,
7243,
12929,
304,
272,
9106,
63,
1560,
63,
698,
63,
7395,
63,
988,
63,
1267,
275,
283,
505,
7,
272,
9106,
63,
576,
63,
1313,
275,
469,
267,
283,
14071,
356,
283,
3876,
297,
267,
283,
4626,
356,
283,
3876,
297,
272,
789,
272,
27797,
63,
1861,
275,
283,
1438,
2749,
9021,
7813,
9418,
10092,
879,
7,
339,
347,
13137,
63,
2912,
63,
890,
8,
277,
12,
1504,
12,
13474,
304,
267,
408,
267,
19245,
965,
282,
6555,
13,
521,
849,
334,
4657,
4427,
63,
13387,
63,
23129,
63,
9190,
9,
402,
267,
22291,
2860,
1126,
1827,
14,
398,
982,
2337,
1159,
1454,
282,
2849,
901,
370,
5518,
12,
314,
2304,
365,
6891,
267,
334,
4657,
4427,
63,
4283,
63,
11265,
1512,
6131,
63,
4859,
680,
267,
408,
267,
340,
822,
8,
955,
9,
508,
413,
26,
288,
372,
6891,
267,
916,
822,
8,
955,
9,
690,
413,
26,
288,
372,
291,
14,
2105,
14,
3179,
14,
988,
63,
1131,
63,
1162,
5001,
822,
8,
955,
9,
267,
587,
26,
288,
372,
822,
8,
8718,
9,
339,
347,
1104,
63,
5599,
63,
4058,
8,
277,
12,
3965,
304,
267,
4875,
63,
955,
275,
334,
955,
14,
14071,
12,
1504,
14,
4626,
12,
1504,
14,
27115,
9,
267,
4875,
63,
21622,
275,
334,
21622,
14,
6959,
12,
27535,
14,
16650,
12,
27535,
14,
31805,
12,
27535,
14,
11976,
12680,
9,
267,
340,
1228,
8,
5599,
12,
4875,
63,
21622,
304,
288,
367,
5348,
315,
3965,
14,
362,
63,
1365,
63,
15264,
837,
355,
862,
26,
490,
1072,
63,
698,
275,
5348,
14,
1199,
63,
698,
355,
871,
334,
10227,
12,
27691,
304,
490,
327,
2832,
4036,
1007,
5599,
965,
376,
1072,
63,
698,
1314,
365,
15701,
490,
327,
370,
3686,
14,
490,
986,
355,
587,
26,
490,
340,
1228,
8,
1199,
63,
698,
12,
4875,
63,
955,
304,
717,
746,
3778,
14,
26077,
547,
8,
1169,
283,
5556,
3913,
675,
12094,
12,
437,
10929,
12,
20992,
12680,
12,
436,
21107,
554,
283,
1169,
283,
10978,
1298,
641,
1434,
15,
521,
1504,
315,
11723,
19,
283,
1169,
283,
8585,
1434,
15,
521,
365,
6290,
465,
1318,
3530,
717,
776,
267,
340,
1228,
8,
5599,
12,
27535,
14,
10170,
9,
436,
822,
8,
5599,
14,
1365,
63,
15264,
9,
690,
413,
26,
288,
746,
3778,
14,
26077,
547,
8,
355,
298,
4657,
1175,
3181,
1133,
2291,
28424,
28437,
641,
9531,
3423,
298,
355,
298,
5694,
316,
3663,
2368,
2122,
288,
776,
339,
347,
1434,
63,
5005,
63,
3009,
8,
277,
12,
4237,
63,
466,
12,
901,
63,
354,
304,
267,
408,
267,
12502,
3651,
22280,
543,
282,
922,
13,
4037,
805,
1639,
63,
602,
63,
5005,
342,
267,
626,
1159,
7264,
315,
4907,
1252,
3645,
2849,
9344,
2952,
642,
365,
282,
267,
1059,
436,
4293,
4257,
7675,
282,
25061,
543,
282,
901,
536,
14,
267,
408,
267,
372,
298,
1176,
63,
602,
63,
5005,
3508,
83,
297,
450,
83,
2924,
450,
334,
3892,
63,
466,
14,
2325,
1062,
901,
63,
354,
9,
339,
347,
1434,
63,
4284,
63,
3009,
8,
277,
12,
6871,
304,
267,
372,
620,
8,
5553,
63,
18144,
8,
7473,
430,
339,
347,
1475,
63,
509,
63,
5553,
63,
18327,
15307,
8,
277,
12,
3875,
304,
267,
408,
2585,
6548,
3967,
10803,
365,
8860,
315,
314,
3537,
805,
1041,
267,
372,
3875,
339,
347,
1434,
63,
8208,
63,
3009,
8,
277,
12,
4237,
63,
466,
12,
901,
63,
354,
304,
267,
372,
298,
1176,
63,
602,
63,
8208,
3508,
83,
297,
450,
83,
2924,
450,
334,
3892,
63,
466,
14,
2325,
1062,
901,
63,
354,
9,
339,
347,
900,
63,
8208,
63,
3009,
8,
277,
12,
4237,
63,
466,
12,
901,
63,
354,
304,
267,
372,
298,
1176,
63,
521,
63,
8208,
3508,
83,
297,
450,
83,
2924,
450,
334,
3892,
63,
466,
14,
2325,
1062,
901,
63,
354,
9,
339,
347,
485,
3916,
63,
3903,
1247,
63,
475,
63,
3009,
8,
277,
12,
28054,
304,
267,
340,
2202,
14,
4701,
63,
14226,
26,
288,
372,
17648,
83,
4065,
450,
28054,
12,
17648,
83,
4065,
450,
291,
14,
2105,
14,
7145,
63,
354,
267,
372,
283,
8084,
297,
283,
8084,
7,
339,
347,
2197,
63,
2931,
63,
602,
63,
3009,
8,
277,
12,
901,
63,
354,
12,
28054,
304,
267,
372,
283,
1176,
63,
2083,
63,
2931,
63,
602,
4042,
83,
12,
450,
83,
12,
450,
83,
3171,
450,
334,
288,
901,
63,
354,
12,
627,
277,
423,
3916,
63,
3903,
1247,
63,
475,
63,
3009,
8,
20027,
395,
267,
776,
339,
347,
2197,
63,
2931,
63,
521,
63,
3009,
8,
277,
12,
901,
63,
354,
12,
28054,
304,
267,
372,
283,
1176,
63,
2083,
63,
2931,
63,
521,
4042,
83,
12,
450,
83,
12,
450,
83,
3171,
450,
334,
288,
901,
63,
354,
12,
627,
277,
423,
3916,
63,
3903,
1247,
63,
475,
63,
3009,
8,
20027,
395,
267,
776,
339,
347,
2197,
63,
5005,
63,
3009,
8,
277,
12,
4237,
63,
466,
12,
901,
63,
354,
12,
28054,
304,
267,
372,
298,
1176,
63,
2083,
63,
5005,
3508,
83,
297,
450,
83,
12,
450,
83,
12,
450,
83,
2924,
450,
334,
288,
4237,
63,
466,
14,
2325,
1062,
901,
63,
354,
12,
627,
277,
423,
3916,
63,
3903,
1247,
63,
475,
63,
3009,
8,
20027,
395,
267,
776,
339,
347,
2197,
63,
8208,
63,
3009,
0
] |
[
1,
1,
1,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/VTK
|
Utilities/Maintenance/VisualizeModuleDependencies.py
|
12
|
11003
|
#!/usr/bin/env python
'''
This program takes a list of module files and creates a (possibly disjoint)
directed graph of the modules and their dependencies. Arrows on the
directed graph point to the dependent module.
Typical usage would be as follows:
VisualizeModuleDependencies.py VTKSourceDir vtkFiltersSources,vtkInteractionStyle,vtkRenderingOpenGL
'''
import os, sys
from collections import defaultdict
import vtk
def GetProgramParameters():
import argparse
description = 'Creates a directed graph of the modules and their dependencies.'
epilogue = '''
This program takes a list of module files and creates a
(possibly disjoint) directed graph of the modules and their
dependencies. Arrows on the directed graph point to the dependent module.
By default, dependencies of a given module are followed to their maximum
depth. However you can restrict the depth by specifying the depth to
which dependent modules are searched.
The moduleList is a comma-separated list of module names with no
spaces between the names.
The treeDepth defaults to 0, this means that for a given module all
dependent modules will be found. If non-zero, then trees will be only
searched to that depth.
'''
parser = argparse.ArgumentParser(description=description, epilog=epilogue)
parser.add_argument('vtkSourceDir', help='The path to the vtk Source Directory.')
parser.add_argument('moduleList', help='The list of modules.')
parser.add_argument('moduleTreeDepth', help='The depth of the module trees', nargs='?', default=0, type=int)
args = parser.parse_args()
vtkSourceDir = args.vtkSourceDir
moduleList = [x.strip() for x in args.moduleList.split(',')]
moduleTreeDepth = args.moduleTreeDepth
return (vtkSourceDir, moduleList, moduleTreeDepth)
def GetProgramParametersOld():
'''
Used for Python versions < 2.7
'''
if len(sys.argv) < 3:
s = 'Usage: ' + sys.argv[0] + ' vtkSourceDir moduleList [moduleTreeDepth]'
print(s)
exit(0)
args = dict()
args['vtkSourceDir'] = sys.argv[1]
args['moduleList'] = sys.argv[2]
args['moduleTreeDepth'] = 0
if len(sys.argv) > 3:
args['moduleTreeDepth'] = int(sys.argv[3])
vtkSourceDir = args['vtkSourceDir']
moduleList = [x.strip() for x in args['moduleList'].split(',')]
moduleTreeDepth = args['moduleTreeDepth']
return (vtkSourceDir, moduleList, moduleTreeDepth)
def FindModuleFiles(path):
'''
Get a list of module files in the VTK directory.
'''
moduleFiles = [os.path.join(root, name)
for root, dirs, files in os.walk(path)
for name in files
if name == ("module.cmake")]
return moduleFiles
def ParseModuleFile(fileName):
'''
Read each module file returning the module name and what
it depends on or implements.
'''
fh = open(fileName, 'rb')
lines = []
for line in fh:
line = line.strip()
if line.startswith('$'): # Skip CMake variable names
continue
if line.startswith('#'):
continue
line = line.split('#')[0].strip() # inline comments
if line == "":
continue
line = line.split(')')[0].strip() # closing brace with no space
if line == "":
continue
for l in line.split(" "):
lines.append(l)
languages = ['PYTHON', 'TCL', 'JAVA']
keywords = ['BACKEND', 'COMPILE_DEPENDS', 'DEPENDS', 'EXCLUDE_FROM_ALL',
'EXCLUDE_FROM_WRAPPING', 'GROUPS', 'IMPLEMENTS', 'KIT',
'PRIVATE_DEPENDS', 'TEST_DEPENDS'] + \
map(lambda l: 'EXCLUDE_FROM_%s_WRAPPING' % l, languages)
moduleName = ""
depends = []
implements = []
state = "START";
for item in lines:
if state == "START" and item.startswith("vtk_module("):
moduleName = item.split("(")[1]
continue
if item in keywords:
state = item
continue
if state == 'DEPENDS' and item != ')':
depends.append(item)
continue
if state == 'IMPLEMENTS' and item != ')':
implements.append(item)
continue
return [moduleName, depends + implements]
def FindAllNeededModules(modules, foundModules, moduleDepencencies):
'''
Recursively search moduleDependencies finding all modules.
'''
if modules != None and len(modules) > 0:
for m in modules:
foundModules.add(m)
foundModules = foundModules | set(moduleDepencencies[m]) # Set union
foundModules = FindAllNeededModules(moduleDepencencies[m],
foundModules, moduleDepencencies)
return foundModules
def MakeModuleTree(module, index, tree, moduleDependencies, treeDepth, level=0):
'''
For a given module make a tree with the module as the root and the
dependent modules as children.
'''
if module:
index = index + [module]
if treeDepth == 0 or level < treeDepth:
for m in moduleDependencies[module]:
level += 1
MakeModuleTree(m, index, tree, moduleDependencies, treeDepth, level)
level -= 1
Add(tree, index)
# One-line Tree in Python
# See: https:gist.github.com/hrldcpr/2012250
def Tree(): return defaultdict(Tree)
def Add(tree, keys):
for key in keys:
tree = tree[key]
def PrettyPrint(tree, level=0):
'''
Useful to visualize the tree.
'''
result = ''
for k, v in tree.iteritems():
s = ' ' * level + k + '\n'
result += s
level += 1
result += PrettyPrint(v, level)
level -= 1
return result
def GetAllKeys(tree):
'''
Return all the modules in the tree as a set.
'''
modules = set()
for key in tree:
modules = set(list(modules) + [key] + list(GetAllKeys(tree[key])))
return modules
def MakeEdgeList(t):
'''
Return a set that represents the edges in the tree.
'''
edgeList = set()
for k, v in t.iteritems():
subKeys = v.keys()
if subKeys:
for kk in subKeys:
edgeList.add((k, kk))
edg = MakeEdgeList(v)
if edg:
edgeList.update(edg)
return edgeList
def MakeGraph(t, parent='', level=0):
'''
Returns a list that has two elements, the vertices and the edge list.
'''
return [GetAllKeys(t), MakeEdgeList(t)]
def GenerateGraph(moduleList, moduleDepencencies, moduleTreeDepth):
'''
Generate a graph from the module list.
The resultant graph is a list consisting of two sets, the first set
is the set of vertices and the second set is the edge list.
'''
graph = [set(), set()]
for m in moduleList:
t = Tree()
MakeModuleTree(m, [], t, moduleDepencencies, moduleTreeDepth)
g = MakeGraph(t)
graph[0].update(g[0])
if g[1]:
graph[1].update(g[1])
return graph
def GenerateVTKGraph(graph):
'''
Take the vertices and edge list in the graph parameter
and return a VTK graph.
'''
g = vtk.vtkMutableDirectedGraph()
# Label the vertices
labels = vtk.vtkStringArray()
labels.SetNumberOfComponents(1)
labels.SetName("Labels")
index = dict()
l = list(graph[0])
# Make the vertex labels and create a dictionary with the
# keys as labels and the vertex ids as the values.
for i in range(0, len(l)):
# Set the vertex labels
labels.InsertNextValue(l[i])
index[l[i]] = g.AddVertex()
g.GetVertexData().AddArray(labels)
# Add edges
l = list(graph[1])
for i in range(0, len(l)):
ll = list(l[i])
g.AddGraphEdge(index[ll[0]], index[ll[1]])
# g.Dump()
return g
def DisplayGraph(graph):
'''
Display the graph.
'''
theme = vtk.vtkViewTheme()
theme.SetBackgroundColor(0, 0, .1)
theme.SetBackgroundColor2(0, 0, .5)
# Layout the graph
# Pick a strategy you like.
# strategy = vtk.vtkCircularLayoutStrategy()
strategy = vtk.vtkSimple2DLayoutStrategy()
# strategy = vtk.vtkRandomLayoutStrategy()
layout = vtk.vtkGraphLayout()
layout.SetLayoutStrategy(strategy)
layout.SetInputData(graph)
view = vtk.vtkGraphLayoutView()
view.AddRepresentationFromInputConnection(layout.GetOutputPort())
# Tell the view to use the vertex layout we provide.
view.SetLayoutStrategyToPassThrough()
view.SetEdgeLabelVisibility(True)
view.SetVertexLabelArrayName("Labels")
view.SetVertexLabelVisibility(True)
view.ApplyViewTheme(theme)
# Manually create an actor containing the glyphed arrows.
# Get the edge geometry
edgeGeom = vtk.vtkGraphToPolyData()
edgeGeom.SetInputConnection(layout.GetOutputPort())
edgeGeom.EdgeGlyphOutputOn()
# Set the position (0: edge start, 1: edge end) where
# the edge arrows should go.
# edgeGeom.SetEdgeGlyphPosition(0.8)
edgeGeom.SetEdgeGlyphPosition(0.85)
# Make a simple edge arrow for glyphing.
# arrowSource = vtk.vtkGlyphSource2D()
# arrowSource.SetGlyphTypeToEdgeArrow()
# arrowSource.SetScale(0.075)
# Or use a cone.
coneSource = vtk.vtkConeSource()
coneSource.SetRadius(0.025)
coneSource.SetHeight(0.1)
coneSource.SetResolution(12)
# Use Glyph3D to repeat the glyph on all edges.
arrowGlyph = vtk.vtkGlyph3D()
arrowGlyph.SetInputConnection(0, edgeGeom.GetOutputPort(1))
# arrowGlyph.SetInputConnection(1, arrowSource.GetOutputPort())
arrowGlyph.SetInputConnection(1, coneSource.GetOutputPort())
# Add the edge arrow actor to the view.
arrowMapper = vtk.vtkPolyDataMapper()
arrowMapper.SetInputConnection(arrowGlyph.GetOutputPort())
arrowActor = vtk.vtkActor()
arrowActor.SetMapper(arrowMapper)
view.GetRenderer().AddActor(arrowActor)
view.ResetCamera()
view.Render()
view.SetInteractionModeTo3D()
view.GetInteractor().Initialize()
view.GetInteractor().Start()
def main():
ver = list(sys.version_info[0:2])
ver = ver[0] + ver[1] / 10.0
if ver >= 2.7:
vtkSourceDir, moduleList, moduleTreeDepth = GetProgramParameters()
else:
vtkSourceDir, moduleList, moduleTreeDepth = GetProgramParametersOld()
# Parse the module files making a dictionary of each module and its
# dependencies or what it implements.
moduleDepencencies = dict()
moduleFiles = FindModuleFiles(vtkSourceDir + "/")
for fname in moduleFiles:
m = ParseModuleFile(fname)
moduleDepencencies[m[0]] = m[1]
# Generate a graph from the module list.
graph = GenerateGraph(moduleList, moduleDepencencies, moduleTreeDepth)
# Now build a vtk graph.
g = GenerateVTKGraph(graph)
# Display it.
DisplayGraph(g)
if __name__ == '__main__':
main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
2344,
199,
2765,
2240,
6181,
282,
769,
402,
859,
1584,
436,
8491,
282,
334,
19614,
2153,
10153,
9,
199,
12080,
3343,
402,
314,
4621,
436,
3932,
5124,
14,
1952,
3838,
641,
314,
199,
12080,
3343,
2376,
370,
314,
11410,
859,
14,
199,
199,
26876,
4503,
3955,
506,
465,
11924,
26,
199,
14702,
794,
2377,
11927,
14,
647,
812,
15263,
2980,
3567,
11144,
18053,
13959,
12,
11919,
31900,
6609,
12,
11919,
9216,
316,
4299,
2226,
199,
199,
2344,
199,
199,
646,
747,
12,
984,
199,
504,
5055,
492,
10018,
199,
646,
11144,
199,
199,
318,
2372,
9184,
5976,
837,
272,
492,
7534,
272,
1369,
275,
283,
10607,
282,
23667,
3343,
402,
314,
4621,
436,
3932,
5124,
3530,
272,
29850,
310,
275,
1449,
267,
961,
2240,
6181,
282,
769,
402,
859,
1584,
436,
8491,
282,
267,
334,
19614,
2153,
10153,
9,
23667,
3343,
402,
314,
4621,
436,
3932,
267,
5124,
14,
1952,
3838,
641,
314,
23667,
3343,
2376,
370,
314,
11410,
859,
14,
267,
4885,
849,
12,
5124,
402,
282,
1627,
859,
787,
9437,
370,
3932,
5696,
267,
5818,
14,
9738,
1265,
883,
18152,
314,
5818,
701,
9176,
314,
5818,
370,
267,
1314,
11410,
4621,
787,
17543,
14,
267,
710,
859,
1296,
365,
282,
10029,
13,
12794,
769,
402,
859,
1561,
543,
949,
267,
7883,
3382,
314,
1561,
14,
267,
710,
3123,
14125,
4243,
370,
378,
12,
642,
4910,
626,
367,
282,
1627,
859,
1006,
267,
11410,
4621,
911,
506,
1911,
14,
982,
2222,
13,
4262,
12,
2066,
14416,
911,
506,
1454,
267,
17543,
370,
626,
5818,
14,
272,
1449,
272,
1798,
275,
7534,
14,
10730,
8,
1802,
29,
1802,
12,
29850,
29,
28349,
310,
9,
272,
1798,
14,
525,
63,
2094,
360,
11919,
2980,
3567,
297,
1720,
534,
1918,
931,
370,
314,
11144,
5800,
15191,
2659,
272,
1798,
14,
525,
63,
2094,
360,
578,
1296,
297,
1720,
534,
1918,
769,
402,
4621,
2659,
272,
1798,
14,
525,
63,
2094,
360,
578,
3987,
14125,
297,
1720,
534,
1918,
5818,
402,
314,
859,
14416,
297,
9237,
31468,
849,
29,
16,
12,
730,
29,
442,
9,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
272,
11144,
2980,
3567,
275,
1249,
14,
11919,
2980,
3567,
272,
859,
1296,
275,
359,
88,
14,
1913,
342,
367,
671,
315,
1249,
14,
578,
1296,
14,
1294,
29972,
272,
859,
3987,
14125,
275,
1249,
14,
578,
3987,
14125,
272,
372,
334,
11919,
2980,
3567,
12,
859,
1296,
12,
859,
3987,
14125,
9,
199,
199,
318,
2372,
9184,
5976,
16411,
837,
272,
1449,
272,
8051,
367,
2018,
5459,
665,
499,
14,
23,
272,
1449,
272,
340,
822,
8,
1274,
14,
3020,
9,
665,
650,
26,
267,
308,
275,
283,
7692,
26,
283,
435,
984,
14,
3020,
59,
16,
61,
435,
283,
11144,
2980,
3567,
859,
1296,
359,
578,
3987,
14125,
6616,
267,
870,
8,
83,
9,
267,
4458,
8,
16,
9,
272,
1249,
275,
1211,
342,
272,
1249,
459,
11919,
2980,
3567,
418,
275,
984,
14,
3020,
59,
17,
61,
272,
1249,
459,
578,
1296,
418,
275,
984,
14,
3020,
59,
18,
61,
272,
1249,
459,
578,
3987,
14125,
418,
275,
378,
272,
340,
822,
8,
1274,
14,
3020,
9,
690,
650,
26,
267,
1249,
459,
578,
3987,
14125,
418,
275,
1109,
8,
1274,
14,
3020,
59,
19,
566,
272,
11144,
2980,
3567,
275,
1249,
459,
11919,
2980,
3567,
418,
272,
859,
1296,
275,
359,
88,
14,
1913,
342,
367,
671,
315,
1249,
459,
578,
1296,
2278,
1294,
29972,
272,
859,
3987,
14125,
275,
1249,
459,
578,
3987,
14125,
418,
272,
372,
334,
11919,
2980,
3567,
12,
859,
1296,
12,
859,
3987,
14125,
9,
199,
199,
318,
6668,
2377,
5535,
8,
515,
304,
272,
1449,
272,
2372,
282,
769,
402,
859,
1584,
315,
314,
812,
15263,
2082,
14,
272,
1449,
272,
859,
5535,
275,
359,
736,
14,
515,
14,
904,
8,
1231,
12,
536,
9,
326,
367,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
515,
9,
326,
367,
536,
315,
1584,
326,
340,
536,
508,
1689,
578,
14,
16472,
11323,
272,
372,
859,
5535,
199,
199,
318,
6077,
2377,
1173,
8,
15450,
304,
272,
1449,
272,
5574,
1924,
859,
570,
8152,
314,
859,
536,
436,
4052,
272,
652,
8350,
641,
503,
9031,
14,
272,
1449,
272,
11155,
275,
1551,
8,
15450,
12,
283,
4848,
358,
272,
2385,
275,
942,
272,
367,
1004,
315,
11155,
26,
267,
1004,
275,
1004,
14,
1913,
342,
267,
340,
1004,
14,
2460,
14676,
735,
221,
327,
8232,
21355,
1750,
1561,
288,
1980,
267,
340,
1004,
14,
2460,
7863,
735,
288,
1980,
267,
1004,
275,
1004,
14,
1294,
7863,
5832,
16,
1055,
1913,
342,
221,
327,
8308,
6786,
267,
340,
1004,
508,
10812,
288,
1980,
267,
1004,
275,
1004,
14,
1294,
15938,
5832,
16,
1055,
1913,
342,
221,
327,
11261,
23549,
543,
949,
4601,
267,
340,
1004,
508,
10812,
288,
1980,
267,
367,
634,
315,
1004,
14,
1294,
480,
26699,
288,
2385,
14,
740,
8,
76,
9,
272,
10815,
275,
788,
11720,
297,
283,
52,
1981,
297,
283,
42,
28520,
418,
272,
7681,
275,
788,
18145,
297,
283,
29911,
63,
10814,
20853,
297,
283,
10814,
20853,
297,
283,
1438,
13958,
63,
12491,
63,
1761,
297,
355,
283,
1438,
13958,
63,
12491,
63,
6524,
7121,
1206,
297,
283,
27544,
297,
283,
8947,
10320,
51,
297,
283,
43,
649,
297,
355,
283,
18748,
63,
10814,
20853,
297,
283,
2864,
63,
10814,
20853,
418,
435,
971,
2049,
2341,
8,
2734,
634,
26,
283,
1438,
13958,
63,
12491,
4970,
83,
63,
6524,
7121,
1206,
7,
450,
634,
12,
10815,
9,
272,
859,
985,
275,
3087,
272,
8350,
275,
942,
272,
9031,
275,
942,
272,
1174,
275,
298,
7363,
11436,
272,
367,
1242,
315,
2385,
26,
267,
340,
1174,
508,
298,
7363,
2,
436,
1242,
14,
2460,
480,
11919,
63,
578,
480,
304,
288,
859,
985,
275,
1242,
14,
1294,
480,
480,
2788,
17,
61,
288,
1980,
267,
340,
1242,
315,
7681,
26,
288,
1174,
275,
1242,
288,
1980,
267,
340,
1174,
508,
283,
10814,
20853,
7,
436,
1242,
1137,
5320,
356,
288,
8350,
14,
740,
8,
1053,
9,
288,
1980,
267,
340,
1174,
508,
283,
8947,
10320,
51,
7,
436,
1242
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
2344,
199,
2765,
2240,
6181,
282,
769,
402,
859,
1584,
436,
8491,
282,
334,
19614,
2153,
10153,
9,
199,
12080,
3343,
402,
314,
4621,
436,
3932,
5124,
14,
1952,
3838,
641,
314,
199,
12080,
3343,
2376,
370,
314,
11410,
859,
14,
199,
199,
26876,
4503,
3955,
506,
465,
11924,
26,
199,
14702,
794,
2377,
11927,
14,
647,
812,
15263,
2980,
3567,
11144,
18053,
13959,
12,
11919,
31900,
6609,
12,
11919,
9216,
316,
4299,
2226,
199,
199,
2344,
199,
199,
646,
747,
12,
984,
199,
504,
5055,
492,
10018,
199,
646,
11144,
199,
199,
318,
2372,
9184,
5976,
837,
272,
492,
7534,
272,
1369,
275,
283,
10607,
282,
23667,
3343,
402,
314,
4621,
436,
3932,
5124,
3530,
272,
29850,
310,
275,
1449,
267,
961,
2240,
6181,
282,
769,
402,
859,
1584,
436,
8491,
282,
267,
334,
19614,
2153,
10153,
9,
23667,
3343,
402,
314,
4621,
436,
3932,
267,
5124,
14,
1952,
3838,
641,
314,
23667,
3343,
2376,
370,
314,
11410,
859,
14,
267,
4885,
849,
12,
5124,
402,
282,
1627,
859,
787,
9437,
370,
3932,
5696,
267,
5818,
14,
9738,
1265,
883,
18152,
314,
5818,
701,
9176,
314,
5818,
370,
267,
1314,
11410,
4621,
787,
17543,
14,
267,
710,
859,
1296,
365,
282,
10029,
13,
12794,
769,
402,
859,
1561,
543,
949,
267,
7883,
3382,
314,
1561,
14,
267,
710,
3123,
14125,
4243,
370,
378,
12,
642,
4910,
626,
367,
282,
1627,
859,
1006,
267,
11410,
4621,
911,
506,
1911,
14,
982,
2222,
13,
4262,
12,
2066,
14416,
911,
506,
1454,
267,
17543,
370,
626,
5818,
14,
272,
1449,
272,
1798,
275,
7534,
14,
10730,
8,
1802,
29,
1802,
12,
29850,
29,
28349,
310,
9,
272,
1798,
14,
525,
63,
2094,
360,
11919,
2980,
3567,
297,
1720,
534,
1918,
931,
370,
314,
11144,
5800,
15191,
2659,
272,
1798,
14,
525,
63,
2094,
360,
578,
1296,
297,
1720,
534,
1918,
769,
402,
4621,
2659,
272,
1798,
14,
525,
63,
2094,
360,
578,
3987,
14125,
297,
1720,
534,
1918,
5818,
402,
314,
859,
14416,
297,
9237,
31468,
849,
29,
16,
12,
730,
29,
442,
9,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
272,
11144,
2980,
3567,
275,
1249,
14,
11919,
2980,
3567,
272,
859,
1296,
275,
359,
88,
14,
1913,
342,
367,
671,
315,
1249,
14,
578,
1296,
14,
1294,
29972,
272,
859,
3987,
14125,
275,
1249,
14,
578,
3987,
14125,
272,
372,
334,
11919,
2980,
3567,
12,
859,
1296,
12,
859,
3987,
14125,
9,
199,
199,
318,
2372,
9184,
5976,
16411,
837,
272,
1449,
272,
8051,
367,
2018,
5459,
665,
499,
14,
23,
272,
1449,
272,
340,
822,
8,
1274,
14,
3020,
9,
665,
650,
26,
267,
308,
275,
283,
7692,
26,
283,
435,
984,
14,
3020,
59,
16,
61,
435,
283,
11144,
2980,
3567,
859,
1296,
359,
578,
3987,
14125,
6616,
267,
870,
8,
83,
9,
267,
4458,
8,
16,
9,
272,
1249,
275,
1211,
342,
272,
1249,
459,
11919,
2980,
3567,
418,
275,
984,
14,
3020,
59,
17,
61,
272,
1249,
459,
578,
1296,
418,
275,
984,
14,
3020,
59,
18,
61,
272,
1249,
459,
578,
3987,
14125,
418,
275,
378,
272,
340,
822,
8,
1274,
14,
3020,
9,
690,
650,
26,
267,
1249,
459,
578,
3987,
14125,
418,
275,
1109,
8,
1274,
14,
3020,
59,
19,
566,
272,
11144,
2980,
3567,
275,
1249,
459,
11919,
2980,
3567,
418,
272,
859,
1296,
275,
359,
88,
14,
1913,
342,
367,
671,
315,
1249,
459,
578,
1296,
2278,
1294,
29972,
272,
859,
3987,
14125,
275,
1249,
459,
578,
3987,
14125,
418,
272,
372,
334,
11919,
2980,
3567,
12,
859,
1296,
12,
859,
3987,
14125,
9,
199,
199,
318,
6668,
2377,
5535,
8,
515,
304,
272,
1449,
272,
2372,
282,
769,
402,
859,
1584,
315,
314,
812,
15263,
2082,
14,
272,
1449,
272,
859,
5535,
275,
359,
736,
14,
515,
14,
904,
8,
1231,
12,
536,
9,
326,
367,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
515,
9,
326,
367,
536,
315,
1584,
326,
340,
536,
508,
1689,
578,
14,
16472,
11323,
272,
372,
859,
5535,
199,
199,
318,
6077,
2377,
1173,
8,
15450,
304,
272,
1449,
272,
5574,
1924,
859,
570,
8152,
314,
859,
536,
436,
4052,
272,
652,
8350,
641,
503,
9031,
14,
272,
1449,
272,
11155,
275,
1551,
8,
15450,
12,
283,
4848,
358,
272,
2385,
275,
942,
272,
367,
1004,
315,
11155,
26,
267,
1004,
275,
1004,
14,
1913,
342,
267,
340,
1004,
14,
2460,
14676,
735,
221,
327,
8232,
21355,
1750,
1561,
288,
1980,
267,
340,
1004,
14,
2460,
7863,
735,
288,
1980,
267,
1004,
275,
1004,
14,
1294,
7863,
5832,
16,
1055,
1913,
342,
221,
327,
8308,
6786,
267,
340,
1004,
508,
10812,
288,
1980,
267,
1004,
275,
1004,
14,
1294,
15938,
5832,
16,
1055,
1913,
342,
221,
327,
11261,
23549,
543,
949,
4601,
267,
340,
1004,
508,
10812,
288,
1980,
267,
367,
634,
315,
1004,
14,
1294,
480,
26699,
288,
2385,
14,
740,
8,
76,
9,
272,
10815,
275,
788,
11720,
297,
283,
52,
1981,
297,
283,
42,
28520,
418,
272,
7681,
275,
788,
18145,
297,
283,
29911,
63,
10814,
20853,
297,
283,
10814,
20853,
297,
283,
1438,
13958,
63,
12491,
63,
1761,
297,
355,
283,
1438,
13958,
63,
12491,
63,
6524,
7121,
1206,
297,
283,
27544,
297,
283,
8947,
10320,
51,
297,
283,
43,
649,
297,
355,
283,
18748,
63,
10814,
20853,
297,
283,
2864,
63,
10814,
20853,
418,
435,
971,
2049,
2341,
8,
2734,
634,
26,
283,
1438,
13958,
63,
12491,
4970,
83,
63,
6524,
7121,
1206,
7,
450,
634,
12,
10815,
9,
272,
859,
985,
275,
3087,
272,
8350,
275,
942,
272,
9031,
275,
942,
272,
1174,
275,
298,
7363,
11436,
272,
367,
1242,
315,
2385,
26,
267,
340,
1174,
508,
298,
7363,
2,
436,
1242,
14,
2460,
480,
11919,
63,
578,
480,
304,
288,
859,
985,
275,
1242,
14,
1294,
480,
480,
2788,
17,
61,
288,
1980,
267,
340,
1242,
315,
7681,
26,
288,
1174,
275,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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
] |
adityacs/ansible
|
lib/ansible/modules/network/junos/junos_package.py
|
50
|
5163
|
#!/usr/bin/python
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
ANSIBLE_METADATA = {'status': ['preview'],
'supported_by': 'community',
'version': '1.0'}
DOCUMENTATION = """
---
module: junos_package
version_added: "2.1"
author: "Peter Sprygada (@privateip)"
short_description: Installs packages on remote devices running Junos
description:
- This module can install new and updated packages on remote
devices running Junos. The module will compare the specified
package with the one running on the remote device and install
the specified version if there is a mismatch
extends_documentation_fragment: junos
options:
src:
description:
- The I(src) argument specifies the path to the source package to be
installed on the remote device in the advent of a version mismatch.
The I(src) argument can be either a localized path or a full
path to the package file to install.
required: true
default: null
aliases: ['package']
version:
description:
- The I(version) argument can be used to explicitly specify the
version of the package that should be installed on the remote
device. If the I(version) argument is not specified, then
the version is extracts from the I(src) filename.
required: false
default: null
reboot:
description:
- In order for a package to take effect, the remote device must be
restarted. When enabled, this argument will instruct the module
to reboot the device once the updated package has been installed.
If disabled or the remote package does not need to be changed,
the device will not be started.
required: true
default: true
choices: ['true', 'false']
no_copy:
description:
- The I(no_copy) argument is responsible for instructing the remote
device on where to install the package from. When enabled, the
package is transferred to the remote device prior to installing.
required: false
default: false
choices: ['true', 'false']
force:
description:
- The I(force) argument instructs the module to bypass the package
version check and install the packaged identified in I(src) on
the remote device.
required: true
default: false
choices: ['true', 'false']
requirements:
- junos-eznc
notes:
- This module requires the netconf system service be enabled on
the remote device being managed
"""
EXAMPLES = """
# the required set of connection arguments have been purposely left off
# the examples for brevity
- name: install local package on remote device
junos_package:
src: junos-vsrx-12.1X46-D10.2-domestic.tgz
- name: install local package on remote device without rebooting
junos_package:
src: junos-vsrx-12.1X46-D10.2-domestic.tgz
reboot: no
"""
import ansible.module_utils.junos
from ansible.module_utils.network import NetworkModule
try:
from jnpr.junos.utils.sw import SW
HAS_SW = True
except ImportError:
HAS_SW = False
def install_package(module):
junos = SW(module.connection.device)
package = module.params['src']
no_copy = module.params['no_copy']
progress_log = lambda x, y: module.log(y)
module.log('installing package')
result = junos.install(package, progress=progress_log, no_copy=no_copy)
if not result:
module.fail_json(msg='Unable to install package on device')
if module.params['reboot']:
module.log('rebooting system')
junos.reboot()
def main():
spec = dict(
src=dict(type='path', required=True, aliases=['package']),
version=dict(),
reboot=dict(type='bool', default=True),
no_copy=dict(default=False, type='bool'),
force=dict(type='bool', default=False),
transport=dict(default='netconf', choices=['netconf'])
)
module = NetworkModule(argument_spec=spec,
supports_check_mode=True)
if not HAS_SW:
module.fail_json(msg='Missing jnpr.junos.utils.sw module')
result = dict(changed=False)
do_upgrade = module.params['force'] or False
if not module.params['force']:
has_ver = module.connection.get_facts().get('version')
wants_ver = module.params['version']
do_upgrade = has_ver != wants_ver
if do_upgrade:
if not module.check_mode:
install_package(module)
result['changed'] = True
module.exit_json(**result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
1023,
356,
283,
17,
14,
16,
936,
199,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
1335,
21003,
63,
2491,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
2502,
26,
298,
8070,
351,
8360,
651,
71,
10641,
8593,
4239,
711,
2924,
199,
3612,
63,
1802,
26,
13276,
83,
6117,
641,
3982,
7256,
3879,
1603,
21003,
199,
1802,
26,
523,
446,
961,
859,
883,
3907,
892,
436,
4588,
6117,
641,
3982,
272,
7256,
3879,
1603,
21003,
14,
221,
710,
859,
911,
6540,
314,
2013,
272,
2559,
543,
314,
1373,
3879,
641,
314,
3982,
2243,
436,
3907,
272,
314,
2013,
1015,
340,
2337,
365,
282,
15015,
199,
11036,
63,
9970,
63,
7677,
26,
1335,
21003,
199,
1419,
26,
523,
2928,
26,
272,
1369,
26,
489,
446,
710,
473,
8,
2164,
9,
1423,
9314,
314,
931,
370,
314,
1350,
2559,
370,
506,
267,
4903,
641,
314,
3982,
2243,
315,
314,
1503,
782,
402,
282,
1015,
15015,
14,
267,
710,
473,
8,
2164,
9,
1423,
883,
506,
1902,
282,
25460,
931,
503,
282,
2615,
267,
931,
370,
314,
2559,
570,
370,
3907,
14,
272,
1415,
26,
2549,
272,
849,
26,
2973,
272,
5481,
26,
788,
2491,
418,
523,
1015,
26,
272,
1369,
26,
489,
446,
710,
473,
8,
1023,
9,
1423,
883,
506,
1202,
370,
7662,
4165,
314,
267,
1015,
402,
314,
2559,
626,
1077,
506,
4903,
641,
314,
3982,
267,
2243,
14,
221,
982,
314,
473,
8,
1023,
9,
1423,
365,
440,
2013,
12,
2066,
267,
314,
1015,
365,
5536,
83,
687,
314,
473,
8,
2164,
9,
1788,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
19457,
26,
272,
1369,
26,
489,
446,
1010,
1865,
367,
282,
2559,
370,
5452,
7763,
12,
314,
3982,
2243,
1471,
506,
267,
32277,
14,
221,
3979,
5223,
12,
642,
1423,
911,
315,
1820,
314,
859,
267,
370,
19457,
314,
2243,
5403,
314,
4588,
2559,
965,
2757,
4903,
14,
267,
982,
6980,
503,
314,
3982,
2559,
1630,
440,
1929,
370,
506,
2896,
12,
267,
314,
2243,
911,
440,
506,
8239,
14,
272,
1415,
26,
2549,
272,
849,
26,
2549,
272,
3415,
26,
788,
2052,
297,
283,
3910,
418,
523,
949,
63,
1574,
26,
272,
1369,
26,
489,
446,
710,
473,
8,
889,
63,
1574,
9,
1423,
365,
17845,
367,
315,
1820,
316,
314,
3982,
267,
2243,
641,
2382,
370,
3907,
314,
2559,
687,
14,
221,
3979,
5223,
12,
314,
267,
2559,
365,
1752,
5057,
370,
314,
3982,
2243,
6791,
370,
22200,
14,
272,
1415,
26,
3055,
272,
849,
26,
3055,
272,
3415,
26,
788,
2052,
297,
283,
3910,
418,
523,
3542,
26,
272,
1369,
26,
489,
446,
710,
473,
8,
3990,
9,
1423,
315,
23253,
314,
859,
370,
21115,
314,
2559,
267,
1015,
1104,
436,
3907,
314,
2559,
68,
15836,
315,
473,
8,
2164,
9,
641,
267,
314,
3982,
2243,
14,
272,
1415,
26,
2549,
272,
849,
26,
3055,
272,
3415,
26,
788,
2052,
297,
283,
3910,
418,
199,
7538,
26,
523,
446,
1335,
21003,
13,
27263,
7966,
199,
5983,
26,
523,
446,
961,
859,
5074,
314,
1851,
2190,
2656,
2435,
506,
5223,
641,
272,
314,
3982,
2243,
3769,
12883,
199,
624,
199,
199,
8918,
275,
408,
199,
3,
314,
1415,
663,
402,
1950,
2368,
1172,
2757,
12016,
590,
3602,
2331,
199,
3,
314,
7251,
367,
330,
264,
18936,
199,
199,
13,
536,
26,
3907,
2257,
2559,
641,
3982,
2243,
523,
1335,
21003,
63,
2491,
26,
272,
2928,
26,
1335,
21003,
13,
3122,
6872,
13,
713,
14,
17,
56,
2466,
13,
36,
709,
14,
18,
13,
1117,
278,
11108,
14,
27220,
199,
199,
13,
536,
26,
3907,
2257,
2559,
641,
3982,
2243,
1928,
19457,
316,
523,
1335,
21003,
63,
2491,
26,
272,
2928,
26,
1335,
21003,
13,
3122,
6872,
13,
713,
14,
17,
56,
2466,
13,
36,
709,
14,
18,
13,
1117,
278,
11108,
14,
27220,
272,
19457,
26,
949,
199,
624,
199,
646,
3242,
14,
578,
63,
1208,
14,
31959,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
492,
7220,
2377,
199,
199,
893,
26,
272,
687,
1335,
1590,
82,
14,
31959,
14,
1208,
14,
3519,
492,
17548,
272,
7509,
63,
8745,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
8745,
275,
756,
199,
199,
318,
3907,
63,
2491,
8,
578,
304,
272,
1335,
21003,
275,
17548,
8,
578,
14,
2105,
14,
1782,
9,
272,
2559,
275,
859,
14,
1162,
459,
2164,
418,
272,
949,
63,
1574,
275,
859,
14,
1162,
459,
889,
63,
1574,
418,
339,
6696,
63,
793,
275,
2400,
671,
12,
612,
26,
859,
14,
793,
8,
89,
9,
339,
859,
14,
793,
360,
3174,
316,
2559,
358,
272,
754,
275,
1335,
21003,
14,
3174,
8,
2491,
12,
6696,
29,
5734,
63,
793,
12,
949,
63,
1574,
29,
889,
63,
1574,
9,
339,
340,
440,
754,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
6005,
370,
3907,
2559,
641,
2243,
358,
339,
340,
859,
14,
1162,
459,
15051,
2565,
267,
859,
14,
793,
360,
15051,
316,
2656,
358,
267,
1335,
21003,
14,
15051,
342,
421,
199,
318,
2446
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
1023,
356,
283,
17,
14,
16,
936,
199,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
1335,
21003,
63,
2491,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
2502,
26,
298,
8070,
351,
8360,
651,
71,
10641,
8593,
4239,
711,
2924,
199,
3612,
63,
1802,
26,
13276,
83,
6117,
641,
3982,
7256,
3879,
1603,
21003,
199,
1802,
26,
523,
446,
961,
859,
883,
3907,
892,
436,
4588,
6117,
641,
3982,
272,
7256,
3879,
1603,
21003,
14,
221,
710,
859,
911,
6540,
314,
2013,
272,
2559,
543,
314,
1373,
3879,
641,
314,
3982,
2243,
436,
3907,
272,
314,
2013,
1015,
340,
2337,
365,
282,
15015,
199,
11036,
63,
9970,
63,
7677,
26,
1335,
21003,
199,
1419,
26,
523,
2928,
26,
272,
1369,
26,
489,
446,
710,
473,
8,
2164,
9,
1423,
9314,
314,
931,
370,
314,
1350,
2559,
370,
506,
267,
4903,
641,
314,
3982,
2243,
315,
314,
1503,
782,
402,
282,
1015,
15015,
14,
267,
710,
473,
8,
2164,
9,
1423,
883,
506,
1902,
282,
25460,
931,
503,
282,
2615,
267,
931,
370,
314,
2559,
570,
370,
3907,
14,
272,
1415,
26,
2549,
272,
849,
26,
2973,
272,
5481,
26,
788,
2491,
418,
523,
1015,
26,
272,
1369,
26,
489,
446,
710,
473,
8,
1023,
9,
1423,
883,
506,
1202,
370,
7662,
4165,
314,
267,
1015,
402,
314,
2559,
626,
1077,
506,
4903,
641,
314,
3982,
267,
2243,
14,
221,
982,
314,
473,
8,
1023,
9,
1423,
365,
440,
2013,
12,
2066,
267,
314,
1015,
365,
5536,
83,
687,
314,
473,
8,
2164,
9,
1788,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
19457,
26,
272,
1369,
26,
489,
446,
1010,
1865,
367,
282,
2559,
370,
5452,
7763,
12,
314,
3982,
2243,
1471,
506,
267,
32277,
14,
221,
3979,
5223,
12,
642,
1423,
911,
315,
1820,
314,
859,
267,
370,
19457,
314,
2243,
5403,
314,
4588,
2559,
965,
2757,
4903,
14,
267,
982,
6980,
503,
314,
3982,
2559,
1630,
440,
1929,
370,
506,
2896,
12,
267,
314,
2243,
911,
440,
506,
8239,
14,
272,
1415,
26,
2549,
272,
849,
26,
2549,
272,
3415,
26,
788,
2052,
297,
283,
3910,
418,
523,
949,
63,
1574,
26,
272,
1369,
26,
489,
446,
710,
473,
8,
889,
63,
1574,
9,
1423,
365,
17845,
367,
315,
1820,
316,
314,
3982,
267,
2243,
641,
2382,
370,
3907,
314,
2559,
687,
14,
221,
3979,
5223,
12,
314,
267,
2559,
365,
1752,
5057,
370,
314,
3982,
2243,
6791,
370,
22200,
14,
272,
1415,
26,
3055,
272,
849,
26,
3055,
272,
3415,
26,
788,
2052,
297,
283,
3910,
418,
523,
3542,
26,
272,
1369,
26,
489,
446,
710,
473,
8,
3990,
9,
1423,
315,
23253,
314,
859,
370,
21115,
314,
2559,
267,
1015,
1104,
436,
3907,
314,
2559,
68,
15836,
315,
473,
8,
2164,
9,
641,
267,
314,
3982,
2243,
14,
272,
1415,
26,
2549,
272,
849,
26,
3055,
272,
3415,
26,
788,
2052,
297,
283,
3910,
418,
199,
7538,
26,
523,
446,
1335,
21003,
13,
27263,
7966,
199,
5983,
26,
523,
446,
961,
859,
5074,
314,
1851,
2190,
2656,
2435,
506,
5223,
641,
272,
314,
3982,
2243,
3769,
12883,
199,
624,
199,
199,
8918,
275,
408,
199,
3,
314,
1415,
663,
402,
1950,
2368,
1172,
2757,
12016,
590,
3602,
2331,
199,
3,
314,
7251,
367,
330,
264,
18936,
199,
199,
13,
536,
26,
3907,
2257,
2559,
641,
3982,
2243,
523,
1335,
21003,
63,
2491,
26,
272,
2928,
26,
1335,
21003,
13,
3122,
6872,
13,
713,
14,
17,
56,
2466,
13,
36,
709,
14,
18,
13,
1117,
278,
11108,
14,
27220,
199,
199,
13,
536,
26,
3907,
2257,
2559,
641,
3982,
2243,
1928,
19457,
316,
523,
1335,
21003,
63,
2491,
26,
272,
2928,
26,
1335,
21003,
13,
3122,
6872,
13,
713,
14,
17,
56,
2466,
13,
36,
709,
14,
18,
13,
1117,
278,
11108,
14,
27220,
272,
19457,
26,
949,
199,
624,
199,
646,
3242,
14,
578,
63,
1208,
14,
31959,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
492,
7220,
2377,
199,
199,
893,
26,
272,
687,
1335,
1590,
82,
14,
31959,
14,
1208,
14,
3519,
492,
17548,
272,
7509,
63,
8745,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
8745,
275,
756,
199,
199,
318,
3907,
63,
2491,
8,
578,
304,
272,
1335,
21003,
275,
17548,
8,
578,
14,
2105,
14,
1782,
9,
272,
2559,
275,
859,
14,
1162,
459,
2164,
418,
272,
949,
63,
1574,
275,
859,
14,
1162,
459,
889,
63,
1574,
418,
339,
6696,
63,
793,
275,
2400,
671,
12,
612,
26,
859,
14,
793,
8,
89,
9,
339,
859,
14,
793,
360,
3174,
316,
2559,
358,
272,
754,
275,
1335,
21003,
14,
3174,
8,
2491,
12,
6696,
29,
5734,
63,
793,
12,
949,
63,
1574,
29,
889,
63,
1574,
9,
339,
340,
440,
754,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
6005,
370,
3907,
2559,
641,
2243,
358,
339,
340,
859,
14,
1162,
459,
15051,
2565,
267,
859,
14,
793,
360,
15051,
316,
2656,
358,
267,
1335,
21003,
14,
15051,
342,
421,
199,
318,
2446,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Maistho/CouchPotatoServer
|
libs/requests/packages/urllib3/_collections.py
|
484
|
10454
|
from collections import Mapping, MutableMapping
try:
from threading import RLock
except ImportError: # Platform-specific: No threads available
class RLock:
def __enter__(self):
pass
def __exit__(self, exc_type, exc_value, traceback):
pass
try: # Python 2.7+
from collections import OrderedDict
except ImportError:
from .packages.ordered_dict import OrderedDict
from .packages.six import iterkeys, itervalues, PY3
__all__ = ['RecentlyUsedContainer', 'HTTPHeaderDict']
_Null = object()
class RecentlyUsedContainer(MutableMapping):
"""
Provides a thread-safe dict-like container which maintains up to
``maxsize`` keys while throwing away the least-recently-used keys beyond
``maxsize``.
:param maxsize:
Maximum number of recent elements to retain.
:param dispose_func:
Every time an item is evicted from the container,
``dispose_func(value)`` is called. Callback which will get called
"""
ContainerCls = OrderedDict
def __init__(self, maxsize=10, dispose_func=None):
self._maxsize = maxsize
self.dispose_func = dispose_func
self._container = self.ContainerCls()
self.lock = RLock()
def __getitem__(self, key):
# Re-insert the item, moving it to the end of the eviction line.
with self.lock:
item = self._container.pop(key)
self._container[key] = item
return item
def __setitem__(self, key, value):
evicted_value = _Null
with self.lock:
# Possibly evict the existing value of 'key'
evicted_value = self._container.get(key, _Null)
self._container[key] = value
# If we didn't evict an existing value, we might have to evict the
# least recently used item from the beginning of the container.
if len(self._container) > self._maxsize:
_key, evicted_value = self._container.popitem(last=False)
if self.dispose_func and evicted_value is not _Null:
self.dispose_func(evicted_value)
def __delitem__(self, key):
with self.lock:
value = self._container.pop(key)
if self.dispose_func:
self.dispose_func(value)
def __len__(self):
with self.lock:
return len(self._container)
def __iter__(self):
raise NotImplementedError('Iteration over this class is unlikely to be threadsafe.')
def clear(self):
with self.lock:
# Copy pointers to all values, then wipe the mapping
values = list(itervalues(self._container))
self._container.clear()
if self.dispose_func:
for value in values:
self.dispose_func(value)
def keys(self):
with self.lock:
return list(iterkeys(self._container))
_dict_setitem = dict.__setitem__
_dict_getitem = dict.__getitem__
_dict_delitem = dict.__delitem__
_dict_contains = dict.__contains__
_dict_setdefault = dict.setdefault
class HTTPHeaderDict(dict):
"""
:param headers:
An iterable of field-value pairs. Must not contain multiple field names
when compared case-insensitively.
:param kwargs:
Additional field-value pairs to pass in to ``dict.update``.
A ``dict`` like container for storing HTTP Headers.
Field names are stored and compared case-insensitively in compliance with
RFC 7230. Iteration provides the first case-sensitive key seen for each
case-insensitive pair.
Using ``__setitem__`` syntax overwrites fields that compare equal
case-insensitively in order to maintain ``dict``'s api. For fields that
compare equal, instead create a new ``HTTPHeaderDict`` and use ``.add``
in a loop.
If multiple fields that are equal case-insensitively are passed to the
constructor or ``.update``, the behavior is undefined and some will be
lost.
>>> headers = HTTPHeaderDict()
>>> headers.add('Set-Cookie', 'foo=bar')
>>> headers.add('set-cookie', 'baz=quxx')
>>> headers['content-length'] = '7'
>>> headers['SET-cookie']
'foo=bar, baz=quxx'
>>> headers['Content-Length']
'7'
"""
def __init__(self, headers=None, **kwargs):
dict.__init__(self)
if headers is not None:
if isinstance(headers, HTTPHeaderDict):
self._copy_from(headers)
else:
self.extend(headers)
if kwargs:
self.extend(kwargs)
def __setitem__(self, key, val):
return _dict_setitem(self, key.lower(), (key, val))
def __getitem__(self, key):
val = _dict_getitem(self, key.lower())
return ', '.join(val[1:])
def __delitem__(self, key):
return _dict_delitem(self, key.lower())
def __contains__(self, key):
return _dict_contains(self, key.lower())
def __eq__(self, other):
if not isinstance(other, Mapping) and not hasattr(other, 'keys'):
return False
if not isinstance(other, type(self)):
other = type(self)(other)
return dict((k1, self[k1]) for k1 in self) == dict((k2, other[k2]) for k2 in other)
def __ne__(self, other):
return not self.__eq__(other)
values = MutableMapping.values
get = MutableMapping.get
update = MutableMapping.update
if not PY3: # Python 2
iterkeys = MutableMapping.iterkeys
itervalues = MutableMapping.itervalues
__marker = object()
def pop(self, key, default=__marker):
'''D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised.
'''
# Using the MutableMapping function directly fails due to the private marker.
# Using ordinary dict.pop would expose the internal structures.
# So let's reinvent the wheel.
try:
value = self[key]
except KeyError:
if default is self.__marker:
raise
return default
else:
del self[key]
return value
def discard(self, key):
try:
del self[key]
except KeyError:
pass
def add(self, key, val):
"""Adds a (name, value) pair, doesn't overwrite the value if it already
exists.
>>> headers = HTTPHeaderDict(foo='bar')
>>> headers.add('Foo', 'baz')
>>> headers['foo']
'bar, baz'
"""
key_lower = key.lower()
new_vals = key, val
# Keep the common case aka no item present as fast as possible
vals = _dict_setdefault(self, key_lower, new_vals)
if new_vals is not vals:
# new_vals was not inserted, as there was a previous one
if isinstance(vals, list):
# If already several items got inserted, we have a list
vals.append(val)
else:
# vals should be a tuple then, i.e. only one item so far
# Need to convert the tuple to list for further extension
_dict_setitem(self, key_lower, [vals[0], vals[1], val])
def extend(self, *args, **kwargs):
"""Generic import function for any type of header-like object.
Adapted version of MutableMapping.update in order to insert items
with self.add instead of self.__setitem__
"""
if len(args) > 1:
raise TypeError("extend() takes at most 1 positional "
"arguments ({} given)".format(len(args)))
other = args[0] if len(args) >= 1 else ()
if isinstance(other, HTTPHeaderDict):
for key, val in other.iteritems():
self.add(key, val)
elif isinstance(other, Mapping):
for key in other:
self.add(key, other[key])
elif hasattr(other, "keys"):
for key in other.keys():
self.add(key, other[key])
else:
for key, value in other:
self.add(key, value)
for key, value in kwargs.items():
self.add(key, value)
def getlist(self, key):
"""Returns a list of all the values for the named field. Returns an
empty list if the key doesn't exist."""
try:
vals = _dict_getitem(self, key.lower())
except KeyError:
return []
else:
if isinstance(vals, tuple):
return [vals[1]]
else:
return vals[1:]
# Backwards compatibility for httplib
getheaders = getlist
getallmatchingheaders = getlist
iget = getlist
def __repr__(self):
return "%s(%s)" % (type(self).__name__, dict(self.itermerged()))
def _copy_from(self, other):
for key in other:
val = _dict_getitem(other, key)
if isinstance(val, list):
# Don't need to convert tuples
val = list(val)
_dict_setitem(self, key, val)
def copy(self):
clone = type(self)()
clone._copy_from(self)
return clone
def iteritems(self):
"""Iterate over all header lines, including duplicate ones."""
for key in self:
vals = _dict_getitem(self, key)
for val in vals[1:]:
yield vals[0], val
def itermerged(self):
"""Iterate over all headers, merging duplicate ones together."""
for key in self:
val = _dict_getitem(self, key)
yield val[0], ', '.join(val[1:])
def items(self):
return list(self.iteritems())
@classmethod
def from_httplib(cls, message): # Python 2
"""Read headers from a Python 2 httplib message object."""
# python2.7 does not expose a proper API for exporting multiheaders
# efficiently. This function re-reads raw lines from the message
# object and extracts the multiheaders properly.
headers = []
for line in message.headers:
if line.startswith((' ', '\t')):
key, value = headers[-1]
headers[-1] = (key, value + '\r\n' + line.rstrip())
continue
key, value = line.split(':', 1)
headers.append((key, value.strip()))
return cls(headers)
|
gpl-3.0
|
[
504,
5055,
492,
12340,
12,
29396,
199,
893,
26,
272,
687,
5796,
492,
820,
6432,
199,
2590,
3545,
26,
221,
327,
16078,
13,
6100,
26,
3091,
7183,
2808,
272,
1021,
820,
6432,
26,
267,
347,
636,
4200,
721,
277,
304,
288,
986,
398,
347,
636,
2224,
721,
277,
12,
3178,
63,
466,
12,
3178,
63,
585,
12,
5190,
304,
288,
986,
421,
199,
893,
26,
221,
327,
2018,
499,
14,
23,
11,
272,
687,
5055,
492,
8773,
199,
2590,
3545,
26,
272,
687,
1275,
5154,
14,
8235,
63,
807,
492,
8773,
199,
504,
1275,
5154,
14,
4174,
492,
25706,
12,
24451,
12,
7843,
19,
421,
199,
363,
452,
363,
275,
788,
29574,
590,
9167,
4076,
297,
283,
2856,
2567,
2141,
418,
421,
199,
63,
8849,
275,
909,
342,
421,
199,
533,
799,
2946,
590,
9167,
4076,
8,
17707,
7674,
304,
272,
408,
272,
21552,
282,
2462,
13,
3489,
1211,
13,
2930,
3970,
1314,
11075,
83,
1536,
370,
272,
1124,
13634,
1040,
2883,
1830,
7978,
316,
13437,
314,
5210,
13,
14951,
590,
13,
2972,
2883,
20561,
272,
1124,
13634,
4345,
339,
520,
635,
19791,
26,
267,
14212,
1329,
402,
8058,
4008,
370,
8074,
14,
339,
520,
635,
2153,
4070,
63,
1532,
26,
267,
18414,
900,
376,
1242,
365,
24656,
1522,
687,
314,
3970,
12,
267,
1124,
29842,
63,
1532,
8,
585,
9719,
365,
2797,
14,
221,
17555,
1314,
911,
664,
2797,
272,
408,
339,
15395,
24342,
275,
8773,
339,
347,
636,
826,
721,
277,
12,
19791,
29,
709,
12,
2153,
4070,
63,
1532,
29,
403,
304,
267,
291,
423,
13634,
275,
19791,
267,
291,
14,
29842,
63,
1532,
275,
2153,
4070,
63,
1532,
398,
291,
423,
3600,
275,
291,
14,
4076,
24342,
342,
267,
291,
14,
831,
275,
820,
6432,
342,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
327,
799,
13,
3176,
314,
1242,
12,
12876,
652,
370,
314,
1284,
402,
314,
24656,
414,
1004,
14,
267,
543,
291,
14,
831,
26,
288,
1242,
275,
291,
423,
3600,
14,
1935,
8,
498,
9,
288,
291,
423,
3600,
59,
498,
61,
275,
1242,
288,
372,
1242,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
24656,
1522,
63,
585,
275,
485,
8849,
267,
543,
291,
14,
831,
26,
288,
327,
25987,
9312,
24656,
319,
314,
3411,
574,
402,
283,
498,
7,
288,
24656,
1522,
63,
585,
275,
291,
423,
3600,
14,
362,
8,
498,
12,
485,
8849,
9,
288,
291,
423,
3600,
59,
498,
61,
275,
574,
953,
327,
982,
781,
9980,
1133,
24656,
319,
376,
3411,
574,
12,
781,
5594,
1172,
370,
24656,
319,
314,
288,
327,
5210,
23568,
1202,
1242,
687,
314,
9608,
402,
314,
3970,
14,
288,
340,
822,
8,
277,
423,
3600,
9,
690,
291,
423,
13634,
26,
355,
485,
498,
12,
24656,
1522,
63,
585,
275,
291,
423,
3600,
14,
24882,
8,
2019,
29,
797,
9,
398,
340,
291,
14,
29842,
63,
1532,
436,
24656,
1522,
63,
585,
365,
440,
485,
8849,
26,
288,
291,
14,
29842,
63,
1532,
8,
69,
433,
1522,
63,
585,
9,
339,
347,
636,
13228,
721,
277,
12,
790,
304,
267,
543,
291,
14,
831,
26,
288,
574,
275,
291,
423,
3600,
14,
1935,
8,
498,
9,
398,
340,
291,
14,
29842,
63,
1532,
26,
288,
291,
14,
29842,
63,
1532,
8,
585,
9,
339,
347,
636,
552,
721,
277,
304,
267,
543,
291,
14,
831,
26,
288,
372,
822,
8,
277,
423,
3600,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
746,
4279,
360,
8666,
1806,
642,
1021,
365,
625,
24227,
370,
506,
2462,
3489,
2659,
339,
347,
5436,
8,
277,
304,
267,
543,
291,
14,
831,
26,
288,
327,
11247,
21116,
370,
1006,
1338,
12,
2066,
336,
3662,
314,
4412,
288,
1338,
275,
769,
8,
13012,
8,
277,
423,
3600,
430,
288,
291,
423,
3600,
14,
3584,
342,
398,
340,
291,
14,
29842,
63,
1532,
26,
288,
367,
574,
315,
1338,
26,
355,
291,
14,
29842,
63,
1532,
8,
585,
9,
339,
347,
2883,
8,
277,
304,
267,
543,
291,
14,
831,
26,
288,
372,
769,
8,
16007,
8,
277,
423,
3600,
430,
421,
199,
63,
807,
63,
8617,
275,
1211,
855,
8617,
363,
199,
63,
807,
63,
6095,
275,
1211,
855,
6095,
363,
199,
63,
807,
63,
13228,
275,
1211,
855,
13228,
363,
199,
63,
807,
63,
6134,
275,
1211,
855,
6134,
363,
199,
63,
807,
63,
5486,
275,
1211,
14,
5486,
421,
199,
533,
3101,
2567,
2141,
8,
807,
304,
272,
408,
272,
520,
635,
2323,
26,
267,
1626,
6076,
402,
901,
13,
585,
6342,
14,
9498,
440,
1395,
3663,
901,
1561,
267,
1380,
13524,
1930,
13,
262,
2464,
338,
9462,
14,
339,
520,
635,
2074,
26,
267,
10961,
901,
13,
585,
6342,
370,
986,
315,
370,
1124,
807,
14,
873,
4345,
339,
437,
1124,
807,
1040,
2839,
3970,
367,
16915,
3101,
21391,
14,
339,
5024,
1561,
787,
5489,
436,
13524,
1930,
13,
262,
2464,
338,
9462,
315,
4151,
543,
272,
7329,
1520,
9687,
14,
473,
5388,
6571,
314,
1642,
1930,
13,
7361,
790,
6775,
367,
1924,
272,
1930,
13,
15851,
4092,
14,
339,
11719,
9035,
8617,
18762,
6302,
1806,
16334,
1504,
626,
6540,
4472,
272,
1930,
13,
262,
2464,
338,
9462,
315,
1865,
370,
11075,
1124,
807,
1040,
7,
83,
2986,
14,
2104,
1504,
626,
272,
6540,
4472,
12,
3140,
1218,
282,
892,
1124,
2856,
2567,
2141,
1040,
436,
675,
21502,
525,
1040,
272,
315,
282,
4438,
14,
339,
982,
3663,
1504,
626,
787,
4472,
1930,
13,
262,
2464,
338,
9462,
787,
3032,
370,
314,
272,
3787,
503,
21502,
873,
4542,
314,
5953,
365,
10942,
436,
2005,
911,
506,
272,
14669,
14,
339,
1306,
2323,
275,
3101,
2567,
2141,
342,
272,
1306,
2323,
14,
525,
360,
1084,
13,
7810,
297,
283,
1421,
29,
1700,
358,
272,
1306,
2323,
14,
525,
360,
409,
13,
5306,
297,
283,
6185,
29,
392,
2154,
358,
272,
1306,
2323,
459,
1317,
13,
1267,
418,
275,
283,
23,
7,
272,
1306,
2323,
459,
3597,
13,
5306,
418,
272,
283,
1421,
29,
1700,
12,
15507,
29,
392,
2154,
7,
272,
1306,
2323,
459,
2714,
13,
4625,
418,
272,
283,
23,
7,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2323
] |
[
5055,
492,
12340,
12,
29396,
199,
893,
26,
272,
687,
5796,
492,
820,
6432,
199,
2590,
3545,
26,
221,
327,
16078,
13,
6100,
26,
3091,
7183,
2808,
272,
1021,
820,
6432,
26,
267,
347,
636,
4200,
721,
277,
304,
288,
986,
398,
347,
636,
2224,
721,
277,
12,
3178,
63,
466,
12,
3178,
63,
585,
12,
5190,
304,
288,
986,
421,
199,
893,
26,
221,
327,
2018,
499,
14,
23,
11,
272,
687,
5055,
492,
8773,
199,
2590,
3545,
26,
272,
687,
1275,
5154,
14,
8235,
63,
807,
492,
8773,
199,
504,
1275,
5154,
14,
4174,
492,
25706,
12,
24451,
12,
7843,
19,
421,
199,
363,
452,
363,
275,
788,
29574,
590,
9167,
4076,
297,
283,
2856,
2567,
2141,
418,
421,
199,
63,
8849,
275,
909,
342,
421,
199,
533,
799,
2946,
590,
9167,
4076,
8,
17707,
7674,
304,
272,
408,
272,
21552,
282,
2462,
13,
3489,
1211,
13,
2930,
3970,
1314,
11075,
83,
1536,
370,
272,
1124,
13634,
1040,
2883,
1830,
7978,
316,
13437,
314,
5210,
13,
14951,
590,
13,
2972,
2883,
20561,
272,
1124,
13634,
4345,
339,
520,
635,
19791,
26,
267,
14212,
1329,
402,
8058,
4008,
370,
8074,
14,
339,
520,
635,
2153,
4070,
63,
1532,
26,
267,
18414,
900,
376,
1242,
365,
24656,
1522,
687,
314,
3970,
12,
267,
1124,
29842,
63,
1532,
8,
585,
9719,
365,
2797,
14,
221,
17555,
1314,
911,
664,
2797,
272,
408,
339,
15395,
24342,
275,
8773,
339,
347,
636,
826,
721,
277,
12,
19791,
29,
709,
12,
2153,
4070,
63,
1532,
29,
403,
304,
267,
291,
423,
13634,
275,
19791,
267,
291,
14,
29842,
63,
1532,
275,
2153,
4070,
63,
1532,
398,
291,
423,
3600,
275,
291,
14,
4076,
24342,
342,
267,
291,
14,
831,
275,
820,
6432,
342,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
327,
799,
13,
3176,
314,
1242,
12,
12876,
652,
370,
314,
1284,
402,
314,
24656,
414,
1004,
14,
267,
543,
291,
14,
831,
26,
288,
1242,
275,
291,
423,
3600,
14,
1935,
8,
498,
9,
288,
291,
423,
3600,
59,
498,
61,
275,
1242,
288,
372,
1242,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
24656,
1522,
63,
585,
275,
485,
8849,
267,
543,
291,
14,
831,
26,
288,
327,
25987,
9312,
24656,
319,
314,
3411,
574,
402,
283,
498,
7,
288,
24656,
1522,
63,
585,
275,
291,
423,
3600,
14,
362,
8,
498,
12,
485,
8849,
9,
288,
291,
423,
3600,
59,
498,
61,
275,
574,
953,
327,
982,
781,
9980,
1133,
24656,
319,
376,
3411,
574,
12,
781,
5594,
1172,
370,
24656,
319,
314,
288,
327,
5210,
23568,
1202,
1242,
687,
314,
9608,
402,
314,
3970,
14,
288,
340,
822,
8,
277,
423,
3600,
9,
690,
291,
423,
13634,
26,
355,
485,
498,
12,
24656,
1522,
63,
585,
275,
291,
423,
3600,
14,
24882,
8,
2019,
29,
797,
9,
398,
340,
291,
14,
29842,
63,
1532,
436,
24656,
1522,
63,
585,
365,
440,
485,
8849,
26,
288,
291,
14,
29842,
63,
1532,
8,
69,
433,
1522,
63,
585,
9,
339,
347,
636,
13228,
721,
277,
12,
790,
304,
267,
543,
291,
14,
831,
26,
288,
574,
275,
291,
423,
3600,
14,
1935,
8,
498,
9,
398,
340,
291,
14,
29842,
63,
1532,
26,
288,
291,
14,
29842,
63,
1532,
8,
585,
9,
339,
347,
636,
552,
721,
277,
304,
267,
543,
291,
14,
831,
26,
288,
372,
822,
8,
277,
423,
3600,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
746,
4279,
360,
8666,
1806,
642,
1021,
365,
625,
24227,
370,
506,
2462,
3489,
2659,
339,
347,
5436,
8,
277,
304,
267,
543,
291,
14,
831,
26,
288,
327,
11247,
21116,
370,
1006,
1338,
12,
2066,
336,
3662,
314,
4412,
288,
1338,
275,
769,
8,
13012,
8,
277,
423,
3600,
430,
288,
291,
423,
3600,
14,
3584,
342,
398,
340,
291,
14,
29842,
63,
1532,
26,
288,
367,
574,
315,
1338,
26,
355,
291,
14,
29842,
63,
1532,
8,
585,
9,
339,
347,
2883,
8,
277,
304,
267,
543,
291,
14,
831,
26,
288,
372,
769,
8,
16007,
8,
277,
423,
3600,
430,
421,
199,
63,
807,
63,
8617,
275,
1211,
855,
8617,
363,
199,
63,
807,
63,
6095,
275,
1211,
855,
6095,
363,
199,
63,
807,
63,
13228,
275,
1211,
855,
13228,
363,
199,
63,
807,
63,
6134,
275,
1211,
855,
6134,
363,
199,
63,
807,
63,
5486,
275,
1211,
14,
5486,
421,
199,
533,
3101,
2567,
2141,
8,
807,
304,
272,
408,
272,
520,
635,
2323,
26,
267,
1626,
6076,
402,
901,
13,
585,
6342,
14,
9498,
440,
1395,
3663,
901,
1561,
267,
1380,
13524,
1930,
13,
262,
2464,
338,
9462,
14,
339,
520,
635,
2074,
26,
267,
10961,
901,
13,
585,
6342,
370,
986,
315,
370,
1124,
807,
14,
873,
4345,
339,
437,
1124,
807,
1040,
2839,
3970,
367,
16915,
3101,
21391,
14,
339,
5024,
1561,
787,
5489,
436,
13524,
1930,
13,
262,
2464,
338,
9462,
315,
4151,
543,
272,
7329,
1520,
9687,
14,
473,
5388,
6571,
314,
1642,
1930,
13,
7361,
790,
6775,
367,
1924,
272,
1930,
13,
15851,
4092,
14,
339,
11719,
9035,
8617,
18762,
6302,
1806,
16334,
1504,
626,
6540,
4472,
272,
1930,
13,
262,
2464,
338,
9462,
315,
1865,
370,
11075,
1124,
807,
1040,
7,
83,
2986,
14,
2104,
1504,
626,
272,
6540,
4472,
12,
3140,
1218,
282,
892,
1124,
2856,
2567,
2141,
1040,
436,
675,
21502,
525,
1040,
272,
315,
282,
4438,
14,
339,
982,
3663,
1504,
626,
787,
4472,
1930,
13,
262,
2464,
338,
9462,
787,
3032,
370,
314,
272,
3787,
503,
21502,
873,
4542,
314,
5953,
365,
10942,
436,
2005,
911,
506,
272,
14669,
14,
339,
1306,
2323,
275,
3101,
2567,
2141,
342,
272,
1306,
2323,
14,
525,
360,
1084,
13,
7810,
297,
283,
1421,
29,
1700,
358,
272,
1306,
2323,
14,
525,
360,
409,
13,
5306,
297,
283,
6185,
29,
392,
2154,
358,
272,
1306,
2323,
459,
1317,
13,
1267,
418,
275,
283,
23,
7,
272,
1306,
2323,
459,
3597,
13,
5306,
418,
272,
283,
1421,
29,
1700,
12,
15507,
29,
392,
2154,
7,
272,
1306,
2323,
459,
2714,
13,
4625,
418,
272,
283,
23,
7,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2323,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pombredanne/django-linkcheck
|
linkcheck/tests/__init__.py
|
4
|
6017
|
import urllib2
import socket
import re
import os
#MOCK addinfurl
class addinfoUrl():
"""class to add info() and getUrl(url=) methods to an open file."""
def __init__(self, url, code, msg):
self.headers = None
self.url = url
self.code = code
self.msg = msg
def info(self):
return self.headers
def getcode(self):
return self.code
def getUrl(self):
return self.url
#
# Mock Method so test can run independently
#
# Fix for Python<2.6
try:
timeout = socket._GLOBAL_DEFAULT_TIMEOUT
except AttributeError:
timeout = 1000
def mock_urlopen(url, data=None, timeout=timeout):
msg_dict = {'301': "Moved Permanently", '404': 'Not Found', '200': 'OK'}
code = '404'
msg = msg_dict.get(code)
m = re.search("([0-9]*)$", url)
if m:
code = m.group(0)
msg = msg_dict.get(code, 'Something Happened')
if code == "200":
return addinfoUrl(url, code, msg)
raise urllib2.HTTPError(url, code, msg, None, None)
from django.conf import settings
from django.core.urlresolvers import reverse
from django.test import TestCase
from linkcheck.models import Url
class InternalCheckTestCase(TestCase):
urls = 'linkcheck.tests.test_urls'
def setUp(self):
#replace urllib2.urlopen with mock method
urllib2.urlopen = mock_urlopen
def test_internal_check_mailto(self):
uv = Url(url="mailto:nobody", still_exists=True)
uv.check()
self.assertEquals(uv.status, None)
self.assertEquals(uv.message, 'Email link (not automatically checked)')
def test_internal_check_blank(self):
uv = Url(url="", still_exists=True)
uv.check()
self.assertEquals(uv.status, False)
self.assertEquals(uv.message, 'Empty link')
def test_internal_check_anchor(self):
uv = Url(url="#some_anchor", still_exists=True)
uv.check()
self.assertEquals(uv.status, None)
self.assertEquals(uv.message, 'Link to within the same page (not automatically checked)')
# TODO: This now fails, because with follow=True, redirects are automatically followed
# def test_internal_check_view_302(self):
# uv = Url(url="/admin/linkcheck", still_exists=True)
# uv.check()
# self.assertEquals(uv.status, None)
# self.assertEquals(uv.message, 'This link redirects: code 302 (not automatically checked)')
def test_internal_check_admin_found(self):
uv = Url(url="/admin/", still_exists=True)
uv.check()
self.assertEquals(uv.status, True)
self.assertEquals(uv.message, 'Working internal link')
def test_internal_check_broken_internal_link(self):
uv = Url(url="/broken/internal/link", still_exists=True)
uv.check()
self.assertEquals(uv.status, False)
self.assertEquals(uv.message, 'Broken internal link')
def test_internal_check_invalid_url(self):
uv = Url(url="invalid/url", still_exists=True)
uv.check()
self.assertEquals(uv.status, False)
self.assertEquals(uv.message, 'Invalid URL')
def test_same_page_anchor(self):
# TODO Make this test
pass
#uv = Url(url="#anchor", still_exists=True)
#uv.check()
#self.assertEquals(uv.status, None)
#self.assertEquals(uv.message, "")
class InternalMediaCheckTestCase(TestCase):
def setUp(self):
self.old_media_root = settings.MEDIA_ROOT
settings.MEDIA_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'media')
def tearDown(self):
settings.MEDIA_ROOT = self.old_media_root
def test_internal_check_media_missing(self):
uv = Url(url="/media/not_found", still_exists=True)
uv.check()
self.assertEquals(uv.status, False)
self.assertEquals(uv.message, 'Missing Document')
def test_internal_check_media_found(self):
uv = Url(url="/media/found", still_exists=True)
uv.check()
self.assertEquals(uv.status, True)
self.assertEquals(uv.message, 'Working file link')
def test_internal_check_media_utf8(self):
uv = Url(url="/media/r%C3%BCckmeldung", still_exists=True)
uv.check()
self.assertEquals(uv.status, True)
self.assertEquals(uv.message, 'Working file link')
class ExternalCheckTestCase(TestCase):
def test_external_check_200(self):
uv = Url(url="http://qa-dev.w3.org/link-testsuite/http.php?code=200", still_exists=True)
uv.check()
self.assertEquals(uv.status, True)
self.assertEquals(uv.message, '200 OK')
def test_external_check_301(self):
uv = Url(url="http://qa-dev.w3.org/link-testsuite/http.php?code=301", still_exists=True)
uv.check()
self.assertEquals(uv.status, False)
self.assertEquals(uv.message, '301 Moved Permanently')
def test_external_check_404(self):
uv = Url(url="http://qa-dev.w3.org/link-testsuite/http.php?code=404", still_exists=True)
uv.check()
self.assertEquals(uv.status, False)
self.assertEquals(uv.message, '404 Not Found')
class FindingLinksTestCase(TestCase):
def test_found_links(self):
from linkcheck.tests.sampleapp.models import Book
self.assertEqual(Url.objects.all().count(), 0)
Book.objects.create(title='My Title', description="""Here's a link: <a href="http://www.example.org">Example</a>""")
self.assertEqual(Url.objects.all().count(), 1)
self.assertEqual(Url.objects.all()[0].url, "http://www.example.org")
class ReportViewTestCase(TestCase):
def setUp(self):
from django.contrib.auth.models import User
User.objects.create_superuser('admin', 'admin@example.org', 'password')
def test_report_view(self):
self.client.login(username='admin', password='password')
response = self.client.get(reverse('linkcheck.views.report'))
self.assertContains(response, "<h1>Link Checker</h1>")
|
bsd-3-clause
|
[
646,
4011,
18,
199,
646,
2838,
199,
646,
295,
199,
646,
747,
199,
199,
3,
17749,
1050,
4904,
633,
199,
533,
1050,
815,
6417,
837,
272,
408,
533,
370,
1050,
2256,
342,
436,
29937,
8,
633,
29,
9,
3102,
370,
376,
1551,
570,
1041,
339,
347,
636,
826,
721,
277,
12,
1166,
12,
1233,
12,
1499,
304,
267,
291,
14,
2139,
275,
488,
267,
291,
14,
633,
275,
1166,
267,
291,
14,
600,
275,
1233,
267,
291,
14,
1328,
221,
275,
1499,
339,
347,
2256,
8,
277,
304,
267,
372,
291,
14,
2139,
339,
347,
664,
600,
8,
277,
304,
267,
372,
291,
14,
600,
339,
347,
29937,
8,
277,
304,
267,
372,
291,
14,
633,
199,
199,
3,
199,
3,
4420,
9075,
880,
511,
883,
1255,
30426,
199,
3,
199,
199,
3,
14811,
367,
2018,
28,
18,
14,
22,
199,
893,
26,
272,
2653,
275,
2838,
423,
13808,
63,
3472,
63,
8899,
199,
2590,
4281,
26,
272,
2653,
275,
5198,
199,
199,
318,
1683,
63,
10890,
8,
633,
12,
666,
29,
403,
12,
2653,
29,
2593,
304,
272,
1499,
63,
807,
275,
791,
8507,
356,
298,
20774,
3492,
11433,
590,
401,
283,
5188,
356,
283,
1763,
2643,
297,
283,
1840,
356,
283,
3593,
936,
339,
1233,
275,
283,
5188,
7,
272,
1499,
221,
275,
1499,
63,
807,
14,
362,
8,
600,
9,
339,
333,
275,
295,
14,
1733,
480,
779,
16,
13,
25,
23849,
11918,
1166,
9,
272,
340,
333,
26,
267,
1233,
275,
333,
14,
923,
8,
16,
9,
267,
1499,
221,
275,
1499,
63,
807,
14,
362,
8,
600,
12,
283,
20641,
869,
5435,
379,
358,
267,
340,
1233,
508,
298,
1840,
582,
288,
372,
1050,
815,
6417,
8,
633,
12,
1233,
12,
1499,
9,
339,
746,
4011,
18,
14,
12815,
8,
633,
12,
1233,
12,
1499,
12,
488,
12,
488,
9,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
2142,
1074,
14,
992,
492,
20503,
199,
199,
533,
12624,
1799,
1746,
8,
1746,
304,
272,
8187,
275,
283,
1073,
1074,
14,
2219,
14,
396,
63,
3603,
7,
339,
347,
3613,
8,
277,
304,
267,
327,
1814,
4011,
18,
14,
10890,
543,
1683,
1083,
267,
4011,
18,
14,
10890,
275,
1683,
63,
10890,
339,
347,
511,
63,
4672,
63,
1074,
63,
26206,
8,
277,
304,
267,
20879,
275,
20503,
8,
633,
628,
26206,
26,
889,
2030,
401,
5139,
63,
2444,
29,
549,
9,
267,
20879,
14,
1074,
342,
267,
291,
14,
2947,
8,
9154,
14,
1205,
12,
488,
9,
267,
291,
14,
2947,
8,
9154,
14,
1188,
12,
283,
7035,
2142,
334,
1397,
5847,
7923,
5942,
339,
347,
511,
63,
4672,
63,
1074,
63,
2500,
8,
277,
304,
267,
20879,
275,
20503,
8,
633,
8772,
5139,
63,
2444,
29,
549,
9,
267,
20879,
14,
1074,
342,
267,
291,
14,
2947,
8,
9154,
14,
1205,
12,
756,
9,
267,
291,
14,
2947,
8,
9154,
14,
1188,
12,
283,
4699,
2142,
358,
339,
347,
511,
63,
4672,
63,
1074,
63,
11498,
8,
277,
304,
267,
20879,
275,
20503,
8,
633,
13476,
3972,
63,
11498,
401,
5139,
63,
2444,
29,
549,
9,
267,
20879,
14,
1074,
342,
267,
291,
14,
2947,
8,
9154,
14,
1205,
12,
488,
9,
267,
291,
14,
2947,
8,
9154,
14,
1188,
12,
283,
3834,
370,
4453,
314,
2011,
2034,
334,
1397,
5847,
7923,
5942,
199,
199,
3,
259,
3254,
26,
961,
3063,
6918,
12,
2952,
543,
2035,
29,
549,
12,
17784,
787,
5847,
9437,
199,
3,
259,
347,
511,
63,
4672,
63,
1074,
63,
1345,
63,
8551,
8,
277,
304,
199,
3,
263,
20879,
275,
20503,
8,
633,
9555,
2113,
15,
1073,
1074,
401,
5139,
63,
2444,
29,
549,
9,
199,
3,
263,
20879,
14,
1074,
342,
199,
3,
263,
291,
14,
2947,
8,
9154,
14,
1205,
12,
488,
9,
199,
3,
263,
291,
14,
2947,
8,
9154,
14,
1188,
12,
283,
2765,
2142,
17784,
26,
1233,
11485,
334,
1397,
5847,
7923,
5942,
339,
347,
511,
63,
4672,
63,
1074,
63,
2113,
63,
4214,
8,
277,
304,
267,
20879,
275,
20503,
8,
633,
9555,
2113,
10665,
5139,
63,
2444,
29,
549,
9,
267,
20879,
14,
1074,
342,
267,
291,
14,
2947,
8,
9154,
14,
1205,
12,
715,
9,
267,
291,
14,
2947,
8,
9154,
14,
1188,
12,
283,
18356,
5007,
2142,
358,
339,
347,
511,
63,
4672,
63,
1074,
63,
15697,
63,
4672,
63,
1073,
8,
277,
304,
267,
20879,
275,
20503,
8,
633,
9555,
15697,
15,
4672,
15,
1073,
401,
5139,
63,
2444,
29,
549,
9,
267,
20879,
14,
1074,
342,
267,
291,
14,
2947,
8,
9154,
14,
1205,
12,
756,
9,
267,
291,
14,
2947,
8,
9154,
14,
1188,
12,
283,
30509,
5007,
2142,
358,
339,
347,
511,
63,
4672,
63,
1074,
63,
3197,
63,
633,
8,
277,
304,
267,
20879,
275,
20503,
8,
633,
628,
3197,
15,
633,
401,
5139,
63,
2444,
29,
549,
9,
267,
20879,
14,
1074,
342,
267,
291,
14,
2947,
8,
9154,
14,
1205,
12,
756,
9,
267,
291,
14,
2947,
8,
9154,
14,
1188,
12,
283,
3364,
2851,
358,
339,
347,
511,
63,
7191,
63,
1606,
63,
11498,
8,
277,
304,
267,
327,
3254,
4155,
642,
511,
267,
986,
267,
327,
9154,
275,
20503,
8,
633,
13476,
11498,
401,
5139,
63,
2444,
29,
549,
9,
267,
327,
9154,
14,
1074,
342,
267,
327,
277,
14,
2947,
8,
9154,
14,
1205,
12,
488,
9,
267,
327,
277,
14,
2947,
8,
9154,
14,
1188,
12,
6899,
421,
199,
533,
12624,
11398,
1799,
1746,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
1753,
63,
4603,
63,
1231,
275,
2202,
14,
13669,
63,
5441,
267,
2202,
14,
13669,
63,
5441,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
22159,
283,
4603,
358,
339,
347,
6766,
8,
277,
304,
267,
2202,
14,
13669,
63,
5441,
275,
291,
14,
1753,
63,
4603,
63,
1231,
339,
347,
511,
63,
4672,
63,
1074,
63,
4603,
63,
4752,
8,
277,
304,
267,
20879,
275,
20503,
8,
633,
9555,
4603,
15,
1397,
63,
4214,
401,
5139,
63
] |
[
4011,
18,
199,
646,
2838,
199,
646,
295,
199,
646,
747,
199,
199,
3,
17749,
1050,
4904,
633,
199,
533,
1050,
815,
6417,
837,
272,
408,
533,
370,
1050,
2256,
342,
436,
29937,
8,
633,
29,
9,
3102,
370,
376,
1551,
570,
1041,
339,
347,
636,
826,
721,
277,
12,
1166,
12,
1233,
12,
1499,
304,
267,
291,
14,
2139,
275,
488,
267,
291,
14,
633,
275,
1166,
267,
291,
14,
600,
275,
1233,
267,
291,
14,
1328,
221,
275,
1499,
339,
347,
2256,
8,
277,
304,
267,
372,
291,
14,
2139,
339,
347,
664,
600,
8,
277,
304,
267,
372,
291,
14,
600,
339,
347,
29937,
8,
277,
304,
267,
372,
291,
14,
633,
199,
199,
3,
199,
3,
4420,
9075,
880,
511,
883,
1255,
30426,
199,
3,
199,
199,
3,
14811,
367,
2018,
28,
18,
14,
22,
199,
893,
26,
272,
2653,
275,
2838,
423,
13808,
63,
3472,
63,
8899,
199,
2590,
4281,
26,
272,
2653,
275,
5198,
199,
199,
318,
1683,
63,
10890,
8,
633,
12,
666,
29,
403,
12,
2653,
29,
2593,
304,
272,
1499,
63,
807,
275,
791,
8507,
356,
298,
20774,
3492,
11433,
590,
401,
283,
5188,
356,
283,
1763,
2643,
297,
283,
1840,
356,
283,
3593,
936,
339,
1233,
275,
283,
5188,
7,
272,
1499,
221,
275,
1499,
63,
807,
14,
362,
8,
600,
9,
339,
333,
275,
295,
14,
1733,
480,
779,
16,
13,
25,
23849,
11918,
1166,
9,
272,
340,
333,
26,
267,
1233,
275,
333,
14,
923,
8,
16,
9,
267,
1499,
221,
275,
1499,
63,
807,
14,
362,
8,
600,
12,
283,
20641,
869,
5435,
379,
358,
267,
340,
1233,
508,
298,
1840,
582,
288,
372,
1050,
815,
6417,
8,
633,
12,
1233,
12,
1499,
9,
339,
746,
4011,
18,
14,
12815,
8,
633,
12,
1233,
12,
1499,
12,
488,
12,
488,
9,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
2142,
1074,
14,
992,
492,
20503,
199,
199,
533,
12624,
1799,
1746,
8,
1746,
304,
272,
8187,
275,
283,
1073,
1074,
14,
2219,
14,
396,
63,
3603,
7,
339,
347,
3613,
8,
277,
304,
267,
327,
1814,
4011,
18,
14,
10890,
543,
1683,
1083,
267,
4011,
18,
14,
10890,
275,
1683,
63,
10890,
339,
347,
511,
63,
4672,
63,
1074,
63,
26206,
8,
277,
304,
267,
20879,
275,
20503,
8,
633,
628,
26206,
26,
889,
2030,
401,
5139,
63,
2444,
29,
549,
9,
267,
20879,
14,
1074,
342,
267,
291,
14,
2947,
8,
9154,
14,
1205,
12,
488,
9,
267,
291,
14,
2947,
8,
9154,
14,
1188,
12,
283,
7035,
2142,
334,
1397,
5847,
7923,
5942,
339,
347,
511,
63,
4672,
63,
1074,
63,
2500,
8,
277,
304,
267,
20879,
275,
20503,
8,
633,
8772,
5139,
63,
2444,
29,
549,
9,
267,
20879,
14,
1074,
342,
267,
291,
14,
2947,
8,
9154,
14,
1205,
12,
756,
9,
267,
291,
14,
2947,
8,
9154,
14,
1188,
12,
283,
4699,
2142,
358,
339,
347,
511,
63,
4672,
63,
1074,
63,
11498,
8,
277,
304,
267,
20879,
275,
20503,
8,
633,
13476,
3972,
63,
11498,
401,
5139,
63,
2444,
29,
549,
9,
267,
20879,
14,
1074,
342,
267,
291,
14,
2947,
8,
9154,
14,
1205,
12,
488,
9,
267,
291,
14,
2947,
8,
9154,
14,
1188,
12,
283,
3834,
370,
4453,
314,
2011,
2034,
334,
1397,
5847,
7923,
5942,
199,
199,
3,
259,
3254,
26,
961,
3063,
6918,
12,
2952,
543,
2035,
29,
549,
12,
17784,
787,
5847,
9437,
199,
3,
259,
347,
511,
63,
4672,
63,
1074,
63,
1345,
63,
8551,
8,
277,
304,
199,
3,
263,
20879,
275,
20503,
8,
633,
9555,
2113,
15,
1073,
1074,
401,
5139,
63,
2444,
29,
549,
9,
199,
3,
263,
20879,
14,
1074,
342,
199,
3,
263,
291,
14,
2947,
8,
9154,
14,
1205,
12,
488,
9,
199,
3,
263,
291,
14,
2947,
8,
9154,
14,
1188,
12,
283,
2765,
2142,
17784,
26,
1233,
11485,
334,
1397,
5847,
7923,
5942,
339,
347,
511,
63,
4672,
63,
1074,
63,
2113,
63,
4214,
8,
277,
304,
267,
20879,
275,
20503,
8,
633,
9555,
2113,
10665,
5139,
63,
2444,
29,
549,
9,
267,
20879,
14,
1074,
342,
267,
291,
14,
2947,
8,
9154,
14,
1205,
12,
715,
9,
267,
291,
14,
2947,
8,
9154,
14,
1188,
12,
283,
18356,
5007,
2142,
358,
339,
347,
511,
63,
4672,
63,
1074,
63,
15697,
63,
4672,
63,
1073,
8,
277,
304,
267,
20879,
275,
20503,
8,
633,
9555,
15697,
15,
4672,
15,
1073,
401,
5139,
63,
2444,
29,
549,
9,
267,
20879,
14,
1074,
342,
267,
291,
14,
2947,
8,
9154,
14,
1205,
12,
756,
9,
267,
291,
14,
2947,
8,
9154,
14,
1188,
12,
283,
30509,
5007,
2142,
358,
339,
347,
511,
63,
4672,
63,
1074,
63,
3197,
63,
633,
8,
277,
304,
267,
20879,
275,
20503,
8,
633,
628,
3197,
15,
633,
401,
5139,
63,
2444,
29,
549,
9,
267,
20879,
14,
1074,
342,
267,
291,
14,
2947,
8,
9154,
14,
1205,
12,
756,
9,
267,
291,
14,
2947,
8,
9154,
14,
1188,
12,
283,
3364,
2851,
358,
339,
347,
511,
63,
7191,
63,
1606,
63,
11498,
8,
277,
304,
267,
327,
3254,
4155,
642,
511,
267,
986,
267,
327,
9154,
275,
20503,
8,
633,
13476,
11498,
401,
5139,
63,
2444,
29,
549,
9,
267,
327,
9154,
14,
1074,
342,
267,
327,
277,
14,
2947,
8,
9154,
14,
1205,
12,
488,
9,
267,
327,
277,
14,
2947,
8,
9154,
14,
1188,
12,
6899,
421,
199,
533,
12624,
11398,
1799,
1746,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
1753,
63,
4603,
63,
1231,
275,
2202,
14,
13669,
63,
5441,
267,
2202,
14,
13669,
63,
5441,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
22159,
283,
4603,
358,
339,
347,
6766,
8,
277,
304,
267,
2202,
14,
13669,
63,
5441,
275,
291,
14,
1753,
63,
4603,
63,
1231,
339,
347,
511,
63,
4672,
63,
1074,
63,
4603,
63,
4752,
8,
277,
304,
267,
20879,
275,
20503,
8,
633,
9555,
4603,
15,
1397,
63,
4214,
401,
5139,
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,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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
] |
wscullin/spack
|
var/spack/repos/builtin/packages/r-permute/package.py
|
3
|
1978
|
##############################################################################
# Copyright (c) 2013-2017, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/llnl/spack
# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License (as
# published by the Free Software Foundation) version 2.1, February 1999.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
# conditions of the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
from spack import *
class RPermute(RPackage):
"""A set of restricted permutation designs for freely exchangeable, line
transects (time series), and spatial grid designs plus permutation of
blocks (groups of samples) is provided. 'permute' also allows split-plot
designs, in which the whole-plots or split-plots or both can be
freely-exchangeable or one of the restricted designs. The 'permute'
package is modelled after the permutation schemes of 'Canoco 3.1'
(and later) by Cajo ter Braak."""
homepage = "https://github.com/gavinsimpson/permute"
url = "https://cran.r-project.org/src/contrib/permute_0.9-4.tar.gz"
version('0.9-4', '569fc2442d72a1e3b7e2d456019674c9')
depends_on('r@2.14:')
|
lgpl-2.1
|
[
4605,
199,
3,
1898,
334,
67,
9,
6171,
13,
10680,
12,
7964,
29590,
491,
4380,
6878,
20548,
13863,
12,
20376,
14,
199,
3,
2165,
16584,
737,
314,
7964,
29590,
491,
4380,
6878,
20548,
16871,
31671,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
428,
1389,
14,
199,
3,
18208,
701,
377,
16216,
598,
11020,
472,
12,
22387,
11020,
472,
32,
914,
7530,
14,
16294,
12,
2900,
4481,
4644,
14,
199,
3,
491,
44,
14176,
13,
6012,
13,
8557,
11501,
199,
3,
199,
3,
2104,
2436,
12,
1937,
4178,
921,
5031,
14,
957,
15,
914,
7530,
15,
83,
1389,
199,
3,
7754,
2597,
1937,
314,
12840,
436,
5113,
1584,
367,
4154,
4245,
436,
314,
32426,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
305,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
9,
1015,
499,
14,
17,
12,
21141,
26709,
21300,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
5292,
3408,
1634,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
2895,
436,
199,
3,
3704,
402,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
8217,
199,
4605,
199,
504,
308,
1389,
492,
627,
421,
199,
533,
820,
2623,
12423,
8,
50,
8599,
304,
272,
408,
33,
663,
402,
15297,
22966,
477,
20440,
367,
20673,
7742,
15343,
461,
12,
1004,
272,
7115,
25353,
334,
521,
6779,
395,
436,
11469,
6068,
477,
20440,
12254,
22966,
402,
272,
5664,
334,
2634,
402,
5845,
9,
365,
2741,
14,
283,
8220,
938,
7,
2597,
6127,
3715,
13,
2798,
272,
477,
20440,
12,
315,
1314,
314,
8852,
13,
13701,
503,
3715,
13,
13701,
503,
3865,
883,
506,
272,
20673,
7742,
13,
14197,
461,
503,
1373,
402,
314,
15297,
477,
20440,
14,
710,
283,
8220,
938,
7,
272,
2559,
365,
1402,
1146,
2410,
314,
22966,
21149,
402,
283,
6049,
79,
331,
650,
14,
17,
7,
272,
334,
460,
2945,
9,
701,
8790,
743,
2044,
32377,
1151,
1041,
339,
26586,
275,
298,
2859,
921,
5031,
14,
957,
15,
71,
1214,
262,
11184,
834,
15,
8220,
938,
2,
272,
1166,
420,
275,
298,
2859,
921,
67,
1312,
14,
82,
13,
1715,
14,
1308,
15,
2164,
15,
2828,
15,
8220,
938,
63,
16,
14,
25,
13,
20,
14,
5369,
14,
6838,
2,
339,
1015,
360,
16,
14,
25,
13,
20,
297,
283,
15143,
3003,
1194,
2260,
68,
2819,
65,
17,
69,
19,
66,
23,
69,
18,
68,
11419,
26978,
1342,
67,
25,
358,
339,
8350,
63,
265,
360,
82,
32,
18,
14,
1079,
10993,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
1898,
334,
67,
9,
6171,
13,
10680,
12,
7964,
29590,
491,
4380,
6878,
20548,
13863,
12,
20376,
14,
199,
3,
2165,
16584,
737,
314,
7964,
29590,
491,
4380,
6878,
20548,
16871,
31671,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
428,
1389,
14,
199,
3,
18208,
701,
377,
16216,
598,
11020,
472,
12,
22387,
11020,
472,
32,
914,
7530,
14,
16294,
12,
2900,
4481,
4644,
14,
199,
3,
491,
44,
14176,
13,
6012,
13,
8557,
11501,
199,
3,
199,
3,
2104,
2436,
12,
1937,
4178,
921,
5031,
14,
957,
15,
914,
7530,
15,
83,
1389,
199,
3,
7754,
2597,
1937,
314,
12840,
436,
5113,
1584,
367,
4154,
4245,
436,
314,
32426,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
305,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
9,
1015,
499,
14,
17,
12,
21141,
26709,
21300,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
5292,
3408,
1634,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
2895,
436,
199,
3,
3704,
402,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
8217,
199,
4605,
199,
504,
308,
1389,
492,
627,
421,
199,
533,
820,
2623,
12423,
8,
50,
8599,
304,
272,
408,
33,
663,
402,
15297,
22966,
477,
20440,
367,
20673,
7742,
15343,
461,
12,
1004,
272,
7115,
25353,
334,
521,
6779,
395,
436,
11469,
6068,
477,
20440,
12254,
22966,
402,
272,
5664,
334,
2634,
402,
5845,
9,
365,
2741,
14,
283,
8220,
938,
7,
2597,
6127,
3715,
13,
2798,
272,
477,
20440,
12,
315,
1314,
314,
8852,
13,
13701,
503,
3715,
13,
13701,
503,
3865,
883,
506,
272,
20673,
7742,
13,
14197,
461,
503,
1373,
402,
314,
15297,
477,
20440,
14,
710,
283,
8220,
938,
7,
272,
2559,
365,
1402,
1146,
2410,
314,
22966,
21149,
402,
283,
6049,
79,
331,
650,
14,
17,
7,
272,
334,
460,
2945,
9,
701,
8790,
743,
2044,
32377,
1151,
1041,
339,
26586,
275,
298,
2859,
921,
5031,
14,
957,
15,
71,
1214,
262,
11184,
834,
15,
8220,
938,
2,
272,
1166,
420,
275,
298,
2859,
921,
67,
1312,
14,
82,
13,
1715,
14,
1308,
15,
2164,
15,
2828,
15,
8220,
938,
63,
16,
14,
25,
13,
20,
14,
5369,
14,
6838,
2,
339,
1015,
360,
16,
14,
25,
13,
20,
297,
283,
15143,
3003,
1194,
2260,
68,
2819,
65,
17,
69,
19,
66,
23,
69,
18,
68,
11419,
26978,
1342,
67,
25,
358,
339,
8350,
63,
265,
360,
82,
32,
18,
14,
1079,
10993,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
tqchen/tvm
|
tests/python/unittest/test_runtime_heterogeneous.py
|
2
|
15150
|
# 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.
# pylint: disable=too-many-locals
"""Unit tests for heterogeneous runtime"""
import json
import numpy as np
import tvm
from tvm import te
from tvm.contrib import graph_runtime, util
from tvm import topi
def get_simplex_graph(host_dev_type, device_dev_type):
r""" Return the hand-crafted json object where only one copy node is
inserted. This node copies data from the target device to cpu.
The network is constructed as following:
A B
\ /
elemwise_add (gpu)
\
copy C
\ /
elemwise_sub (cpu)
Parameters
----------
host_dev_type : int
The device type of the host processor, e.g. cpu.
device_dev_type : int
The device type of the device processor, e.g. gpu, opencl, etc.
Returns
-------
json : json
A json encoded object.
"""
# Construct each node in the graph.
var_a = {"op": "null", "name": "A", "inputs": []}
var_b = {"op": "null", "name": "B", "inputs": []}
elemwise_add = {
"op": "tvm_op",
"name": "elemwise_add",
"attrs": {
"flatten_data": "1",
"func_name": "elemwise_add",
"num_inputs": "2",
"num_outputs": "1",
},
"inputs": [[0, 0, 0], [1, 0, 0]],
}
copy = {
"op": "tvm_op",
"name": "__copy_add_to_sub",
"attrs": {
"flatten_data": "0",
"func_name": "__copy",
"num_inputs": "1",
"num_outputs": "1",
},
"inputs": [[2, 0, 0]],
}
var_c = {"op": "null", "name": "C", "inputs": []}
elemwise_sub = {
"op": "tvm_op",
"name": "elemwise_sub",
"attrs": {
"flatten_data": "0",
"func_name": "elemwise_sub",
"num_inputs": "2",
"num_outputs": "1",
},
"inputs": [[3, 0, 0], [4, 0, 0]],
}
# Group the nodes.
nodes = [var_a, var_b, elemwise_add, copy, var_c, elemwise_sub]
arg_nodes = [0, 1, 4]
node_row_ptr = [0, 1, 2, 3, 4, 5, 6]
heads = [[5, 0, 0]]
shape = (4,)
attrs = {
"storage_id": ["list_int", [3, 4, 0, 1, 5, 2]],
"shape": ["list_shape", [shape, shape, shape, shape, shape, shape]],
"device_index": [
"list_int",
[
device_dev_type,
device_dev_type,
device_dev_type,
host_dev_type,
host_dev_type,
host_dev_type,
],
],
"dtype": ["list_int", [0, 0, 0, 0, 0, 0]],
"dltype": ["list_str", ["float32", "float32", "float32", "float32", "float32", "float32"]],
}
# Construct the graph.
graph = {
"nodes": nodes,
"arg_nodes": arg_nodes,
"node_row_ptr": node_row_ptr,
"heads": heads,
"attrs": attrs,
}
return json.dumps(graph)
def test_simplex_data_transferring():
r"""
Test the heterogeneous execution of a simple network where data
transferring is from the target device to the host processor at runtime.
The host processor is always assumed to be cpu, and the device varies.
"""
host = "cpu"
target_host = "llvm"
host_ctx = tvm.context(host)
if not tvm.runtime.enabled(target_host):
print("Skip test because llvm is not enabled.")
return
def check_device(device, target_device):
if not tvm.runtime.enabled(target_device):
print("Skip test because {} is not enabled.".format(target_device))
return
device_ctx = tvm.context(device)
graph = get_simplex_graph(host_ctx.device_type, device_ctx.device_type)
shape = (4,)
# Create module for add whose target is the device.
tensor_a = te.placeholder(shape, name="A")
tensor_b = te.placeholder(shape, name="B")
elemwise_add = te.compute(
shape, lambda *i: tensor_a(*i) + tensor_b(*i), name="elemwise_add"
)
target = topi.cpp.TEST_create_target(device)
schedule_add = topi.cpp.cuda.schedule_injective(target, [elemwise_add])
lower_add = tvm.lower(schedule_add, [tensor_a, tensor_b, elemwise_add], name="elemwise_add")
# Insert copy. Neither compute nor schedule is required for the copy
# node. The compute will be performed at runtime which is just data
# copy from the input to the output.
tensor_copy = te.placeholder(shape, name="__copy")
# Create module for sub whose target is the host.
tensor_c = te.placeholder(shape, name="C")
elemwise_sub = te.compute(
shape, lambda *i: tensor_copy(*i) - tensor_c(*i), name="elemwise_sub"
)
schedule_sub = te.create_schedule(elemwise_sub.op)
lower_sub = tvm.lower(
schedule_sub, [tensor_copy, tensor_c, elemwise_sub], name="elemwise_sub"
)
target_flist = {target_device: lower_add, target_host: lower_sub}
mhost = tvm.build(target_flist, target_host=target_host)
ctx = [host_ctx, device_ctx]
mod = graph_runtime.create(graph, mhost, ctx)
params = {}
params["A"] = tensor_a = np.random.uniform(size=shape).astype(tensor_a.dtype)
params["B"] = tensor_b = np.random.uniform(size=shape).astype(tensor_b.dtype)
params["C"] = tensor_c = np.random.uniform(size=shape).astype(tensor_c.dtype)
mod.set_input(**params)
mod.run()
out = mod.get_output(0, tvm.nd.empty(shape))
np.testing.assert_equal(out.asnumpy(), (tensor_a + tensor_b) - tensor_c)
dev_tar = {"cuda": "cuda", "opencl": "opencl"}
for device, target in dev_tar.items():
with tvm.target.Target(device):
check_device(device, target)
def get_duplex_graph(host_dev_type, device_dev_type):
r""" Return the hand-crafted json object where two copy nodes are inserted.
Data transferring happens back-and-forth between the target device and CPU.
The network is constructed as following:
A B
\ /
elemwise_add (gpu)
\
copy C
\ /
elemwise_sub (cpu)
\
copy D
\ /
elemwise_add (gpu)
Parameters
----------
host_dev_type : int
The device type of the host processor, e.g. cpu.
device_dev_type : int
The device type of the device processor, e.g. gpu, opencl, etc.
Returns
-------
json : json
A json encoded object.
"""
# Construct each node in the graph.
var_a = {"op": "null", "name": "A", "inputs": []}
var_b = {"op": "null", "name": "B", "inputs": []}
elemwise_add0 = {
"op": "tvm_op",
"name": "elemwise_add0",
"attrs": {
"flatten_data": "1",
"func_name": "elemwise_add0",
"num_inputs": "2",
"num_outputs": "1",
},
"inputs": [[0, 0, 0], [1, 0, 0]],
}
copy_add_sub = {
"op": "tvm_op",
"name": "__copy_add_to_sub",
"attrs": {
"flatten_data": "0",
"func_name": "__copy",
"num_inputs": "1",
"num_outputs": "1",
},
"inputs": [[2, 0, 0]],
}
var_c = {"op": "null", "name": "C", "inputs": []}
elemwise_sub = {
"op": "tvm_op",
"name": "elemwise_sub",
"attrs": {
"flatten_data": "0",
"func_name": "elemwise_sub",
"num_inputs": "2",
"num_outputs": "1",
},
"inputs": [[3, 0, 0], [4, 0, 0]],
}
copy_sub_add = {
"op": "tvm_op",
"name": "__copy_sub_to_add",
"attrs": {
"flatten_data": "0",
"func_name": "__copy",
"num_inputs": "1",
"num_outputs": "1",
},
"inputs": [[5, 0, 0]],
}
var_d = {"op": "null", "name": "D", "inputs": []}
elemwise_add1 = {
"op": "tvm_op",
"name": "elemwise_add1",
"attrs": {
"flatten_data": "0",
"func_name": "elemwise_add1",
"num_inputs": "2",
"num_outputs": "1",
},
"inputs": [[6, 0, 0], [7, 0, 0]],
}
# Group the nodes.
nodes = [
var_a,
var_b,
elemwise_add0,
copy_add_sub,
var_c,
elemwise_sub,
copy_sub_add,
var_d,
elemwise_add1,
]
arg_nodes = [0, 1, 4, 7]
node_row_ptr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
heads = [[8, 0, 0]]
shape = (4,)
attrs = {
"storage_id": ["list_int", [4, 5, 0, 1, 6, 2, 0, 7, 3]],
"shape": ["list_shape", [shape, shape, shape, shape, shape, shape, shape, shape, shape]],
"device_index": [
"list_int",
[
device_dev_type,
device_dev_type,
device_dev_type,
host_dev_type,
host_dev_type,
host_dev_type,
device_dev_type,
device_dev_type,
device_dev_type,
],
],
"dtype": ["list_int", [0, 0, 0, 0, 0, 0, 0, 0, 0]],
"dltype": [
"list_str",
[
"float32",
"float32",
"float32",
"float32",
"float32",
"float32",
"float32",
"float32",
"float32",
],
],
}
# Construct the graph.
graph = {
"nodes": nodes,
"arg_nodes": arg_nodes,
"node_row_ptr": node_row_ptr,
"heads": heads,
"attrs": attrs,
}
return json.dumps(graph)
def test_duplex_data_transferring():
r"""
Test the heterogeneous execution of a simple network where data
transferring occurs back-and-forth between the target device and host
processor.
The host processor is always assumed to be cpu, and the target device
varies.
"""
host = "cpu"
target_host = "llvm"
host_ctx = tvm.context(host)
if not tvm.runtime.enabled(target_host):
print("Skip test because llvm is not enabled.")
return
def check_device(device, target_device):
if not tvm.runtime.enabled(target_device):
print("Skip test because {} is not enabled.".format(target_device))
return
device_ctx = tvm.context(device)
graph = get_duplex_graph(host_ctx.device_type, device_ctx.device_type)
shape = (4,)
# Insert copy nodes for data transferring between add and sub nodes.
# Transfers data from gpu to cpu.
copy_add_sub = te.placeholder(shape, name="__copy0")
# Transfers data from cpu to gpu.
copy_sub_add = te.placeholder(shape, name="__copy1")
# Create a module containing adds on the device.
tensor_a = te.placeholder(shape, name="A")
tensor_b = te.placeholder(shape, name="B")
tensor_d = te.placeholder(shape, name="D")
elemwise_add0 = te.compute(
shape, lambda *i: tensor_a(*i) + tensor_b(*i), name="elemwise_add0"
)
elemwise_add1 = te.compute(
shape, lambda *i: copy_sub_add(*i) + tensor_d(*i), name="elemwise_add1"
)
target = topi.cpp.TEST_create_target(device)
add_schedule0 = topi.cpp.cuda.schedule_injective(target, [elemwise_add0])
lower_add0 = tvm.lower(
add_schedule0, [tensor_a, tensor_b, elemwise_add0], name="elemwise_add0"
)
add_schedule1 = topi.cpp.cuda.schedule_injective(target, [elemwise_add1])
lower_add1 = tvm.lower(
add_schedule1, [tensor_d, copy_sub_add, elemwise_add1], name="elemwise_add1"
)
# Create module for sub whose target is the host.
tensor_c = te.placeholder(shape, name="C")
elemwise_sub = te.compute(
shape, lambda *i: copy_add_sub(*i) - tensor_c(*i), name="elemwise_sub"
)
sub_schedule = te.create_schedule(elemwise_sub.op)
lower_sub = tvm.lower(
sub_schedule, [copy_add_sub, tensor_c, elemwise_sub], name="elemwise_sub"
)
lower_add0.update(lower_add1)
target_flist = {target_device: lower_add0, target_host: lower_sub}
mhost = tvm.build(target_flist, target_host=target_host)
ctx = [host_ctx, device_ctx]
params = {}
params["A"] = tensor_a = np.random.uniform(size=shape).astype(tensor_a.dtype)
params["B"] = tensor_b = np.random.uniform(size=shape).astype(tensor_b.dtype)
params["C"] = tensor_c = np.random.uniform(size=shape).astype(tensor_c.dtype)
params["D"] = tensor_d = np.random.uniform(size=shape).astype(tensor_d.dtype)
def check_verify():
mod = graph_runtime.create(graph, mhost, ctx)
mod.set_input(**params)
mod.run()
out = mod.get_output(0, tvm.nd.empty(shape))
np.testing.assert_equal(out.asnumpy(), tensor_a + tensor_b - tensor_c + tensor_d)
def check_load_module():
temp = util.tempdir()
path_lib = temp.relpath("deploy.so")
mhost.export_library(path_lib)
with open(temp.relpath("deploy.json"), "w") as out_file:
out_file.write(graph)
loaded_lib = tvm.runtime.load_module(path_lib)
loaded_graph = open(temp.relpath("deploy.json")).read()
mod = graph_runtime.create(loaded_graph, loaded_lib, ctx)
mod.set_input(**params)
mod.run()
out = mod.get_output(0, tvm.nd.empty(shape))
np.testing.assert_equal(out.asnumpy(), tensor_a + tensor_b - tensor_c + tensor_d)
check_verify()
check_load_module()
dev_tar = {"cuda": "cuda", "opencl": "opencl"}
for device, target in dev_tar.items():
with tvm.target.Target(device):
check_device(device, target)
if __name__ == "__main__":
test_simplex_data_transferring()
test_duplex_data_transferring()
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
4287,
26,
3507,
29,
7354,
13,
3479,
13,
9350,
199,
624,
5072,
2295,
367,
946,
24208,
10654,
1785,
8836,
624,
199,
646,
2022,
199,
646,
2680,
465,
980,
199,
199,
646,
31385,
199,
504,
31385,
492,
1565,
199,
504,
31385,
14,
2828,
492,
3343,
63,
7726,
12,
4884,
199,
504,
31385,
492,
370,
1038,
421,
199,
318,
664,
63,
4129,
88,
63,
2180,
8,
1102,
63,
2374,
63,
466,
12,
2243,
63,
2374,
63,
466,
304,
272,
519,
624,
1432,
314,
4926,
13,
67,
345,
70,
471,
2022,
909,
2382,
1454,
1373,
1331,
1031,
365,
272,
11788,
14,
961,
1031,
6866,
666,
687,
314,
1347,
2243,
370,
5033,
14,
272,
710,
2784,
365,
14701,
465,
2569,
26,
326,
437,
259,
699,
2116,
971,
221,
1182,
1467,
6193,
2605,
63,
525,
221,
334,
6477,
9,
2151,
971,
2151,
1331,
420,
445,
2432,
971,
420,
1182,
2151,
6193,
2605,
63,
954,
221,
334,
3541,
9,
339,
3897,
272,
4143,
272,
1591,
63,
2374,
63,
466,
520,
1109,
267,
710,
2243,
730,
402,
314,
1591,
12495,
12,
325,
14,
71,
14,
5033,
14,
272,
2243,
63,
2374,
63,
466,
520,
1109,
267,
710,
2243,
730,
402,
314,
2243,
12495,
12,
325,
14,
71,
14,
21758,
12,
1551,
429,
12,
5423,
14,
339,
1803,
272,
5514,
272,
2022,
520,
2022,
267,
437,
2022,
5737,
909,
14,
272,
408,
272,
327,
9215,
1924,
1031,
315,
314,
3343,
14,
272,
2729,
63,
65,
275,
2420,
411,
582,
298,
2307,
401,
298,
354,
582,
298,
33,
401,
298,
3711,
582,
23455,
272,
2729,
63,
66,
275,
2420,
411,
582,
298,
2307,
401,
298,
354,
582,
298,
34,
401,
298,
3711,
582,
23455,
272,
6193,
2605,
63,
525,
275,
469,
267,
298,
411,
582,
298,
84,
2611,
63,
411,
401,
267,
298,
354,
582,
298,
6086,
2605,
63,
525,
401,
267,
298,
3288,
582,
469,
288,
298,
8487,
63,
576,
582,
298,
17,
401,
288,
298,
1532,
63,
354,
582,
298,
6086,
2605,
63,
525,
401,
288,
298,
1507,
63,
3711,
582,
298,
18,
401,
288,
298,
1507,
63,
4467,
582,
298,
17,
401,
267,
1660,
267,
298,
3711,
582,
3474,
16,
12,
378,
12,
378,
467,
359,
17,
12,
378,
12,
378,
2365,
272,
789,
272,
1331,
275,
469,
267,
298,
411,
582,
298,
84,
2611,
63,
411,
401,
267,
298,
354,
582,
4396,
1574,
63,
525,
63,
475,
63,
954,
401,
267,
298,
3288,
582,
469,
288,
298,
8487,
63,
576,
582,
298,
16,
401,
288,
298,
1532,
63,
354,
582,
4396,
1574,
401,
288,
298,
1507,
63,
3711,
582,
298,
17,
401,
288,
298,
1507,
63,
4467,
582,
298,
17,
401,
267,
1660,
267,
298,
3711,
582,
3474,
18,
12,
378,
12,
378,
2365,
272,
789,
272,
2729,
63,
67,
275,
2420,
411,
582,
298,
2307,
401,
298,
354,
582,
298,
35,
401,
298,
3711,
582,
23455,
272,
6193,
2605,
63,
954,
275,
469,
267,
298,
411,
582,
298,
84,
2611,
63,
411,
401,
267,
298,
354,
582,
298,
6086,
2605,
63,
954,
401,
267,
298,
3288,
582,
469,
288,
298,
8487,
63,
576,
582,
298,
16,
401,
288,
298,
1532,
63,
354,
582,
298,
6086,
2605,
63,
954,
401,
288,
298,
1507,
63,
3711,
582,
298,
18,
401,
288,
298,
1507,
63,
4467,
582,
298,
17,
401,
267,
1660,
267,
298,
3711,
582,
3474,
19,
12,
378,
12,
378,
467,
359,
20,
12,
378,
12,
378,
2365,
272,
789,
339,
327,
5611,
314,
3380,
14,
272,
3380,
275,
359,
1391,
63,
65,
12,
2729,
63,
66,
12,
6193,
2605,
63,
525,
12,
1331,
12,
2729,
63,
67,
12,
6193,
2605,
63,
954,
61,
272,
1680,
63,
2415,
275,
359,
16,
12,
413,
12,
841,
61,
272,
1031,
63,
1143,
63,
4695,
275,
359,
16,
12,
413,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
61,
272,
25362,
275,
3474,
21,
12,
378,
12,
378,
2677,
272,
2215,
275,
334,
20,
4258,
272,
3290,
275,
469,
267,
298,
3494,
63,
344,
582,
2097,
513,
63,
442,
401,
359,
19,
12,
841,
12,
378,
12,
413,
12,
959,
12,
499,
2365,
267,
298,
1392,
582,
2097,
513,
63,
1392,
401,
359,
1392,
12,
2215,
12,
2215,
12,
2215,
12,
2215,
12,
2215,
2365,
267,
298,
1782,
63,
1080,
582,
359,
288,
298,
513,
63,
442,
401,
288,
359,
355,
2243,
63,
2374,
63,
466,
12,
355,
2243,
63,
2374,
63,
466,
12,
355,
2243,
63,
2374,
63,
466,
12,
355,
1591,
63,
2374,
63,
466,
12,
355,
1591,
63,
2374,
63,
466,
12,
355,
1591,
63,
2374,
63,
466,
12,
288,
2156,
267,
2156,
267,
298,
2271,
582,
2097,
513,
63,
442,
401,
359,
16,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
2365,
267,
298,
5030,
466,
582,
2097,
513,
63,
495,
401,
2097,
1609,
708,
401,
298,
1609,
708,
401,
298,
1609,
708,
401,
298,
1609,
708,
401,
298,
1609,
708,
401,
298,
1609,
708,
18396,
272,
789,
339,
327,
9215,
314,
3343,
14,
272,
3343,
275,
469,
267,
298,
2415,
582,
3380,
12,
267,
298,
1273,
63,
2415,
582,
1680,
63
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
4287,
26,
3507,
29,
7354,
13,
3479,
13,
9350,
199,
624,
5072,
2295,
367,
946,
24208,
10654,
1785,
8836,
624,
199,
646,
2022,
199,
646,
2680,
465,
980,
199,
199,
646,
31385,
199,
504,
31385,
492,
1565,
199,
504,
31385,
14,
2828,
492,
3343,
63,
7726,
12,
4884,
199,
504,
31385,
492,
370,
1038,
421,
199,
318,
664,
63,
4129,
88,
63,
2180,
8,
1102,
63,
2374,
63,
466,
12,
2243,
63,
2374,
63,
466,
304,
272,
519,
624,
1432,
314,
4926,
13,
67,
345,
70,
471,
2022,
909,
2382,
1454,
1373,
1331,
1031,
365,
272,
11788,
14,
961,
1031,
6866,
666,
687,
314,
1347,
2243,
370,
5033,
14,
272,
710,
2784,
365,
14701,
465,
2569,
26,
326,
437,
259,
699,
2116,
971,
221,
1182,
1467,
6193,
2605,
63,
525,
221,
334,
6477,
9,
2151,
971,
2151,
1331,
420,
445,
2432,
971,
420,
1182,
2151,
6193,
2605,
63,
954,
221,
334,
3541,
9,
339,
3897,
272,
4143,
272,
1591,
63,
2374,
63,
466,
520,
1109,
267,
710,
2243,
730,
402,
314,
1591,
12495,
12,
325,
14,
71,
14,
5033,
14,
272,
2243,
63,
2374,
63,
466,
520,
1109,
267,
710,
2243,
730,
402,
314,
2243,
12495,
12,
325,
14,
71,
14,
21758,
12,
1551,
429,
12,
5423,
14,
339,
1803,
272,
5514,
272,
2022,
520,
2022,
267,
437,
2022,
5737,
909,
14,
272,
408,
272,
327,
9215,
1924,
1031,
315,
314,
3343,
14,
272,
2729,
63,
65,
275,
2420,
411,
582,
298,
2307,
401,
298,
354,
582,
298,
33,
401,
298,
3711,
582,
23455,
272,
2729,
63,
66,
275,
2420,
411,
582,
298,
2307,
401,
298,
354,
582,
298,
34,
401,
298,
3711,
582,
23455,
272,
6193,
2605,
63,
525,
275,
469,
267,
298,
411,
582,
298,
84,
2611,
63,
411,
401,
267,
298,
354,
582,
298,
6086,
2605,
63,
525,
401,
267,
298,
3288,
582,
469,
288,
298,
8487,
63,
576,
582,
298,
17,
401,
288,
298,
1532,
63,
354,
582,
298,
6086,
2605,
63,
525,
401,
288,
298,
1507,
63,
3711,
582,
298,
18,
401,
288,
298,
1507,
63,
4467,
582,
298,
17,
401,
267,
1660,
267,
298,
3711,
582,
3474,
16,
12,
378,
12,
378,
467,
359,
17,
12,
378,
12,
378,
2365,
272,
789,
272,
1331,
275,
469,
267,
298,
411,
582,
298,
84,
2611,
63,
411,
401,
267,
298,
354,
582,
4396,
1574,
63,
525,
63,
475,
63,
954,
401,
267,
298,
3288,
582,
469,
288,
298,
8487,
63,
576,
582,
298,
16,
401,
288,
298,
1532,
63,
354,
582,
4396,
1574,
401,
288,
298,
1507,
63,
3711,
582,
298,
17,
401,
288,
298,
1507,
63,
4467,
582,
298,
17,
401,
267,
1660,
267,
298,
3711,
582,
3474,
18,
12,
378,
12,
378,
2365,
272,
789,
272,
2729,
63,
67,
275,
2420,
411,
582,
298,
2307,
401,
298,
354,
582,
298,
35,
401,
298,
3711,
582,
23455,
272,
6193,
2605,
63,
954,
275,
469,
267,
298,
411,
582,
298,
84,
2611,
63,
411,
401,
267,
298,
354,
582,
298,
6086,
2605,
63,
954,
401,
267,
298,
3288,
582,
469,
288,
298,
8487,
63,
576,
582,
298,
16,
401,
288,
298,
1532,
63,
354,
582,
298,
6086,
2605,
63,
954,
401,
288,
298,
1507,
63,
3711,
582,
298,
18,
401,
288,
298,
1507,
63,
4467,
582,
298,
17,
401,
267,
1660,
267,
298,
3711,
582,
3474,
19,
12,
378,
12,
378,
467,
359,
20,
12,
378,
12,
378,
2365,
272,
789,
339,
327,
5611,
314,
3380,
14,
272,
3380,
275,
359,
1391,
63,
65,
12,
2729,
63,
66,
12,
6193,
2605,
63,
525,
12,
1331,
12,
2729,
63,
67,
12,
6193,
2605,
63,
954,
61,
272,
1680,
63,
2415,
275,
359,
16,
12,
413,
12,
841,
61,
272,
1031,
63,
1143,
63,
4695,
275,
359,
16,
12,
413,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
61,
272,
25362,
275,
3474,
21,
12,
378,
12,
378,
2677,
272,
2215,
275,
334,
20,
4258,
272,
3290,
275,
469,
267,
298,
3494,
63,
344,
582,
2097,
513,
63,
442,
401,
359,
19,
12,
841,
12,
378,
12,
413,
12,
959,
12,
499,
2365,
267,
298,
1392,
582,
2097,
513,
63,
1392,
401,
359,
1392,
12,
2215,
12,
2215,
12,
2215,
12,
2215,
12,
2215,
2365,
267,
298,
1782,
63,
1080,
582,
359,
288,
298,
513,
63,
442,
401,
288,
359,
355,
2243,
63,
2374,
63,
466,
12,
355,
2243,
63,
2374,
63,
466,
12,
355,
2243,
63,
2374,
63,
466,
12,
355,
1591,
63,
2374,
63,
466,
12,
355,
1591,
63,
2374,
63,
466,
12,
355,
1591,
63,
2374,
63,
466,
12,
288,
2156,
267,
2156,
267,
298,
2271,
582,
2097,
513,
63,
442,
401,
359,
16,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
2365,
267,
298,
5030,
466,
582,
2097,
513,
63,
495,
401,
2097,
1609,
708,
401,
298,
1609,
708,
401,
298,
1609,
708,
401,
298,
1609,
708,
401,
298,
1609,
708,
401,
298,
1609,
708,
18396,
272,
789,
339,
327,
9215,
314,
3343,
14,
272,
3343,
275,
469,
267,
298,
2415,
582,
3380,
12,
267,
298,
1273,
63,
2415,
582,
1680,
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,
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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
] |
stephenlienharrell/roster-dns-management
|
test/dnslshost_test.py
|
1
|
21050
|
#!/usr/bin/python
# Copyright (c) 2009, Purdue University
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# Neither the name of the Purdue University nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Regression test for dnslshost
Make sure you are running this against a database that can be destroyed.
DO NOT EVER RUN THIS TEST AGAINST A PRODUCTION DATABASE.
"""
__copyright__ = 'Copyright (C) 2009, Purdue University'
__license__ = 'BSD'
__version__ = '#TRUNK#'
import os
import sys
import socket
import threading
import time
import getpass
import unittest
import roster_core
import roster_server
from roster_user_tools import roster_client_lib
USER_CONFIG = 'test_data/roster_user_tools.conf'
CONFIG_FILE = 'test_data/roster.conf' # Example in test_data
SCHEMA_FILE = '../roster-core/data/database_schema.sql'
DATA_FILE = 'test_data/test_data.sql'
HOST = u'localhost'
USERNAME = u'sharrell'
PASSWORD = u'test'
KEYFILE=('test_data/dnsmgmt.key.pem')
CERTFILE=('test_data/dnsmgmt.cert.pem')
CREDFILE='%s/.dnscred' % os.getcwd()
EXEC='../roster-user-tools/scripts/dnslshost'
class options(object):
password = u'test'
username = u'sharrell'
server = None
ldap = u'ldaps://ldap.cs.university.edu:636'
credfile = CREDFILE
view_name = None
ip_address = None
target = u'machine1'
ttl = 64
class DaemonThread(threading.Thread):
def __init__(self, config_instance, port):
threading.Thread.__init__(self)
self.config_instance = config_instance
self.port = port
self.daemon_instance = None
def run(self):
self.daemon_instance = roster_server.Server(self.config_instance, KEYFILE,
CERTFILE)
self.daemon_instance.Serve(port=self.port)
class Testdnslshost(unittest.TestCase):
def setUp(self):
def PickUnusedPort():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, 0))
addr, port = s.getsockname()
s.close()
return port
self.config_instance = roster_core.Config(file_name=CONFIG_FILE)
db_instance = self.config_instance.GetDb()
db_instance.CreateRosterDatabase()
data = open(DATA_FILE, 'r').read()
db_instance.StartTransaction()
db_instance.cursor.execute(data)
db_instance.EndTransaction()
db_instance.close()
self.port = PickUnusedPort()
self.server_name = 'https://%s:%s' % (HOST, self.port)
self.daemon_thread = DaemonThread(self.config_instance, self.port)
self.daemon_thread.daemon = True
self.daemon_thread.start()
self.core_instance = roster_core.Core(USERNAME, self.config_instance)
self.password = 'test'
time.sleep(1)
roster_client_lib.GetCredentials(USERNAME, u'test', credfile=CREDFILE,
server_name=self.server_name)
self.core_instance.MakeView(u'test_view')
self.core_instance.MakeView(u'test_view2')
self.core_instance.MakeView(u'test_view3')
self.core_instance.MakeZone(u'reverse_zone', u'master',
u'1.168.192.in-addr.arpa.',
view_name=u'test_view')
self.core_instance.MakeZone(u'forward_zone', u'master',
u'university.edu.',
view_name=u'test_view')
self.core_instance.MakeZone(u'forward_zone', u'master',
u'university.edu.',
view_name=u'test_view3')
self.core_instance.MakeZone(u'reverse_zone', u'master',
u'1.168.192.in-addr.arpa.',
view_name=u'test_view2')
self.core_instance.MakeZone(u'ipv6zone', u'master',
u'8.0.e.f.f.3.ip6.arpa.',
view_name=u'test_view')
self.core_instance.MakeRecord(
u'soa', u'soa1', u'forward_zone',
{u'name_server': u'ns1.university.edu.',
u'admin_email': u'admin.university.edu.',
u'serial_number': 1, u'refresh_seconds': 5,
u'retry_seconds': 5, u'expiry_seconds': 5,
u'minimum_seconds': 5}, view_name=u'test_view')
self.core_instance.MakeRecord(
u'soa', u'soa1', u'forward_zone',
{u'name_server': u'ns1.university.edu.',
u'admin_email': u'admin.university.edu.',
u'serial_number': 1, u'refresh_seconds': 5,
u'retry_seconds': 5, u'expiry_seconds': 5,
u'minimum_seconds': 5}, view_name=u'test_view3')
self.core_instance.MakeRecord(
u'soa', u'soa1', u'reverse_zone',
{u'name_server': u'ns1.university.edu.',
u'admin_email': u'admin.university.edu.',
u'serial_number': 1, u'refresh_seconds': 5,
u'retry_seconds': 5, u'expiry_seconds': 5,
u'minimum_seconds': 5}, view_name=u'test_view')
self.core_instance.MakeRecord(
u'soa', u'soa1', u'reverse_zone',
{u'name_server': u'ns1.university.edu.',
u'admin_email': u'admin.university.edu.',
u'serial_number': 1, u'refresh_seconds': 5,
u'retry_seconds': 5, u'expiry_seconds': 5,
u'minimum_seconds': 5}, view_name=u'test_view2')
self.core_instance.MakeRecord(
u'aaaa', u'host2', u'forward_zone', {u'assignment_ip':
u'4321:0000:0001:0002:0003:0004:0567:89ab'}, view_name=u'test_view')
self.core_instance.MakeRecord(u'a', u'host1', u'forward_zone',
{u'assignment_ip': u'192.168.0.1'},
view_name=u'test_view')
self.core_instance.MakeRecord(u'a', u'host2', u'forward_zone',
{u'assignment_ip': u'192.168.1.11'},
view_name=u'test_view3')
self.core_instance.MakeRecord(u'a', u'host3', u'forward_zone',
{u'assignment_ip': u'192.168.1.5'},
view_name=u'test_view')
self.core_instance.MakeRecord(u'a', u'host4', u'forward_zone',
{u'assignment_ip': u'192.168.1.10'},
view_name=u'test_view')
self.core_instance.MakeRecord(u'a', u'host5', u'forward_zone',
{u'assignment_ip': u'192.168.1.17'},
view_name=u'test_view3')
self.core_instance.MakeRecord(u'a', u'host6', u'forward_zone',
{u'assignment_ip': u'192.168.1.8'},
view_name=u'test_view')
self.core_instance.MakeRecord(u'ptr', u'8',
u'reverse_zone',
{u'assignment_host':
u'host6.university.edu.'},
view_name=u'test_view')
self.core_instance.MakeRecord(u'ptr', u'4',
u'reverse_zone',
{u'assignment_host':
u'host2.university.edu.'},
view_name=u'test_view2')
self.core_instance.MakeRecord(u'ptr', u'5',
u'reverse_zone',
{u'assignment_host':
u'host3.university.edu.'},
view_name=u'test_view')
self.core_instance.MakeRecord(u'ptr', u'10',
u'reverse_zone',
{u'assignment_host':
u'host4.university.edu.'},
view_name=u'test_view2')
self.core_instance.MakeRecord(u'ptr', u'7',
u'reverse_zone',
{u'assignment_host':
u'host5.university.edu.'},
view_name=u'test_view2')
def tearDown(self):
if( os.path.exists(CREDFILE) ):
os.remove(CREDFILE)
def testListSingleIP(self):
self.core_instance.MakeReverseRangeZoneAssignment(u'reverse_zone',
u'192.168.1.0/24')
output = os.popen('python %s cidr --cidr-block 192.168.1.5 --no-header '
'-s %s -u %s -p %s --config-file %s' % (
EXEC, self.server_name,
USERNAME, PASSWORD, USER_CONFIG))
lines = output.read()
self.assertEqual(len(lines), 129)
self.assertTrue(
'192.168.1.5 Reverse host3.university.edu reverse_zone test_view\n'
in lines)
self.assertTrue(
'192.168.1.5 Forward host3.university.edu forward_zone test_view\n'
in lines)
output.close()
output = os.popen('python %s cidr --cidr-block 192.168.1.4 '
'-s %s -u %s -p %s --config-file %s --no-header' % (
EXEC, self.server_name,
USERNAME, PASSWORD, USER_CONFIG))
self.assertEqual(output.read(),
'192.168.1.4 Reverse host2.university.edu reverse_zone test_view2\n\n')
output.close()
def testListZone(self):
self.core_instance.MakeReverseRangeZoneAssignment(u'reverse_zone',
u'192.168.1.0/24')
output = os.popen('python %s zone -z forward_zone --no-header '
'-s %s -u %s -p %s --config-file %s' % (
EXEC, self.server_name, USERNAME,
PASSWORD, USER_CONFIG))
lines = output.read()
self.assertEquals(len(lines), 647)
self.assertTrue(
'4321:0000:0001:0002:0003:0004:0567:89ab Forward host2.university.edu '
'forward_zone test_view\n'
in lines)
self.assertTrue(
'192.168.0.1 Forward host1.university.edu '
'forward_zone test_view\n'
in lines)
self.assertTrue(
'192.168.1.11 Forward host2.university.edu '
'forward_zone test_view3\n'
in lines)
self.assertTrue(
'192.168.1.5 Forward host3.university.edu '
'forward_zone test_view\n'
in lines)
self.assertTrue(
'192.168.1.10 Forward host4.university.edu '
'forward_zone test_view\n'
in lines)
self.assertTrue(
'192.168.1.17 Forward host5.university.edu '
'forward_zone test_view3\n'
in lines)
self.assertTrue(
'192.168.1.8 Forward host6.university.edu '
'forward_zone test_view\n'
in lines)
output.close()
output = os.popen('python %s zone -z forward_zone --no-header '
'-v test_view -s %s -u %s -p %s --config-file %s' % (
EXEC, self.server_name, USERNAME,
PASSWORD, USER_CONFIG))
lines = output.read()
self.assertEquals( len(lines), 461)
self.assertTrue(
'192.168.1.5 Forward host3.university.edu '
'forward_zone test_view\n'
in lines)
self.assertTrue(
'192.168.1.8 Forward host6.university.edu '
'forward_zone test_view\n'
in lines)
self.assertTrue(
'192.168.1.10 Forward host4.university.edu '
'forward_zone test_view\n'
in lines)
self.assertTrue(
'192.168.0.1 Forward host1.university.edu '
'forward_zone test_view\n'
'4321:0000:0001:0002:0003:0004:0567:89ab Forward host2.university.edu '
'forward_zone test_view\n'
'192.168.1.5 Forward host3.university.edu '
'forward_zone test_view\n'
in lines)
output.close()
output = os.popen('python %s zone -z forward_zone --no-header '
'-v test_view3 -s %s -u %s -p %s --config-file %s' % (
EXEC, self.server_name, USERNAME,
PASSWORD, USER_CONFIG))
self.assertEqual( output.read(),
'192.168.1.11 Forward host2.university.edu forward_zone test_view3\n'
'192.168.1.17 Forward host5.university.edu forward_zone test_view3\n\n')
output.close()
output = os.popen('python %s zone -z forward_zone --no-header '
'-v test_view -s %s -u %s -p %s --config-file %s' % (
EXEC, self.server_name, USERNAME,
PASSWORD, USER_CONFIG))
self.assertEqual(output.read(),
'192.168.0.1 Forward host1.university.edu forward_zone test_view\n'
'4321:0000:0001:0002:0003:0004:0567:89ab Forward host2.university.edu forward_zone test_view\n'
'192.168.1.5 Forward host3.university.edu forward_zone test_view\n'
'192.168.1.10 Forward host4.university.edu forward_zone test_view\n'
'192.168.1.8 Forward host6.university.edu forward_zone test_view\n\n')
output.close()
output = os.popen('python %s zone -z forward_zone --no-header '
'--cidr-block 192.168.56.0/29 -s %s -u %s -p %s '
'--config-file %s' % (EXEC, self.server_name,
USERNAME, PASSWORD, USER_CONFIG))
self.assertEqual(output.read(),
'CLIENT ERROR: The --cidr-block flag cannot be used with '
'the zone command.\n')
output.close()
output = os.popen('python %s -z forward_zone --no-header '
'--cidr-block 192.168.56.0/29 -s %s -u %s -p %s '
'--config-file %s' % (EXEC, self.server_name,
USERNAME, PASSWORD, USER_CONFIG))
self.assertEqual(output.read(),
'CLIENT ERROR: A command must be specified.\n')
output.close()
def testListCIDR(self):
self.core_instance.MakeReverseRangeZoneAssignment(u'reverse_zone',
u'192.168.1.4/30')
output = os.popen('python %s cidr --cidr-block 192.168.1.4/30 --no-header '
'-v test_view -s %s -u %s -p %s --config-file %s' % (
EXEC, self.server_name, USERNAME,
PASSWORD, USER_CONFIG))
lines = output.read()
self.assertEquals(len(lines), 321 )
self.assertEqual(lines,
'192.168.1.4 -- -- -- test_view\n'
'192.168.1.5 Reverse host3.university.edu reverse_zone test_view\n'
'192.168.1.5 Forward host3.university.edu forward_zone test_view\n'
'192.168.1.6 -- -- -- test_view\n'
'192.168.1.7 -- -- -- test_view\n\n')
output.close()
output = os.popen('python %s cidr --cidr-block 192.168.1.4/30 '
'-s %s -u %s -p %s --config-file %s' % (
EXEC, self.server_name, USERNAME,
PASSWORD, USER_CONFIG))
lines = output.read()
self.assertEqual(len(lines), 653)
self.assertTrue(
'View: test_view2\n'
in lines)
self.assertTrue(
'192.168.1.4 Reverse host2.university.edu reverse_zone test_view2\n'
in lines)
self.assertTrue(
'192.168.1.5 -- -- -- test_view2\n'
in lines)
self.assertTrue(
'192.168.1.6 -- -- -- test_view2\n'
in lines)
self.assertTrue(
'192.168.1.7 Reverse host5.university.edu reverse_zone test_view2\n'
in lines)
self.assertTrue(
'View: test_view\n'
in lines)
self.assertTrue(
'192.168.1.4 -- -- -- test_view\n'
in lines)
self.assertTrue(
'192.168.1.5 Reverse host3.university.edu reverse_zone test_view\n'
in lines)
self.assertTrue(
'192.168.1.5 Forward host3.university.edu forward_zone test_view\n'
in lines)
self.assertTrue(
'192.168.1.6 -- -- -- test_view\n'
in lines)
self.assertTrue(
'192.168.1.7 -- -- -- test_view\n'
in lines)
output.close()
output = os.popen('python %s cidr --cidr-block 192.168.1.4/30 --no-header '
'-v test_view -s %s -u %s -p %s --config-file %s' % (
EXEC, self.server_name, USERNAME,
PASSWORD, USER_CONFIG))
self.assertEqual(output.read(),
'192.168.1.4 -- -- -- test_view\n'
'192.168.1.5 Reverse host3.university.edu reverse_zone test_view\n'
'192.168.1.5 Forward host3.university.edu forward_zone test_view\n'
'192.168.1.6 -- -- -- test_view\n'
'192.168.1.7 -- -- -- test_view\n\n')
output.close()
output = os.popen('python %s cidr --cidr-block 10.0.0.4/30 --no-header '
'-s %s -u %s -p %s --config-file %s' % (
EXEC, self.server_name, USERNAME,
PASSWORD, USER_CONFIG))
self.assertEqual(output.read(),
'10.0.0.4 -- -- -- --\n'
'10.0.0.5 -- -- -- --\n'
'10.0.0.6 -- -- -- --\n'
'10.0.0.7 -- -- -- --\n\n')
output.close()
output = os.popen('python %s cidr --cidr-block 192.168.1.4/32 --no-header '
'-s %s -u %s -p %s --config-file %s' % (
EXEC, self.server_name, USERNAME,
PASSWORD, USER_CONFIG))
self.assertEqual(output.read(),
'192.168.1.4 Reverse host2.university.edu reverse_zone test_view2\n\n')
output.close()
output = os.popen('python %s cidr --cidr-block 192.168.1.4/30 --no-header '
'-z forward_zone -s %s -u %s -p %s --config-file %s '
'-v test_view' % (EXEC, self.server_name, USERNAME,
PASSWORD, USER_CONFIG))
self.assertEqual(output.read(),
'192.168.1.4 -- -- -- test_view\n'
'192.168.1.5 Forward host3.university.edu forward_zone test_view\n'
'192.168.1.6 -- -- -- test_view\n'
'192.168.1.7 -- -- -- test_view\n\n')
output.close()
output = os.popen('python %s cidr --cidr-block 192.168.1.4/30 --no-header '
'-z reverse_zone -s %s -u %s -p %s --config-file %s '
'-v test_view' % (EXEC, self.server_name, USERNAME,
PASSWORD, USER_CONFIG))
self.assertEqual(output.read(),
'192.168.1.4 -- -- -- test_view\n'
'192.168.1.5 Reverse host3.university.edu reverse_zone test_view\n'
'192.168.1.6 -- -- -- test_view\n'
'192.168.1.7 -- -- -- test_view\n\n')
output.close()
output = os.popen('python %s cidr -z forward_zone --no-header '
' -s %s -u %s -p %s --config-file %s' %
(EXEC, self.server_name, USERNAME, PASSWORD, USER_CONFIG))
self.assertEqual(output.read(),
'CLIENT ERROR: The --cidr-block flag is required.\n')
output.close()
if( __name__ == '__main__' ):
unittest.main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
334,
67,
9,
8937,
12,
23177,
11933,
15904,
199,
3,
2900,
4481,
4644,
14,
199,
3,
221,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
221,
199,
3,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
199,
3,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
642,
199,
3,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
436,
15,
269,
199,
3,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
221,
199,
3,
11443,
314,
536,
402,
314,
23177,
11933,
15904,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
1928,
199,
3,
2488,
6791,
5313,
4983,
14,
199,
3,
221,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
199,
3,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
199,
3,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
199,
3,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
199,
3,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
199,
3,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
13013,
511,
367,
6715,
478,
1102,
199,
199,
5483,
3238,
1265,
787,
3879,
642,
6169,
282,
3050,
626,
883,
506,
28924,
14,
199,
199,
1649,
2845,
662,
2111,
21277,
5749,
7393,
437,
9741,
7834,
437,
3611,
4980,
5430,
31705,
14,
199,
624,
199,
199,
363,
7307,
363,
275,
283,
7384,
334,
35,
9,
8937,
12,
23177,
11933,
15904,
7,
199,
363,
1682,
363,
275,
283,
15400,
7,
199,
363,
1023,
363,
275,
3943,
1766,
8019,
19367,
421,
199,
646,
747,
199,
646,
984,
199,
646,
2838,
199,
646,
5796,
199,
646,
900,
199,
646,
18354,
199,
646,
2882,
421,
199,
646,
882,
11652,
63,
1018,
199,
646,
882,
11652,
63,
1000,
199,
504,
882,
11652,
63,
751,
63,
2537,
221,
492,
882,
11652,
63,
1258,
63,
773,
199,
199,
3791,
63,
5569,
275,
283,
396,
63,
576,
15,
4796,
351,
63,
751,
63,
2537,
14,
2190,
7,
199,
5569,
63,
3817,
275,
283,
396,
63,
576,
15,
4796,
351,
14,
2190,
7,
327,
5679,
315,
511,
63,
576,
199,
10926,
63,
3817,
275,
20644,
4796,
351,
13,
1018,
15,
576,
15,
4659,
63,
3629,
14,
3009,
7,
199,
3998,
63,
3817,
275,
283,
396,
63,
576,
15,
396,
63,
576,
14,
3009,
7,
199,
5449,
275,
399,
7,
5967,
7,
199,
11958,
275,
399,
1159,
8210,
264,
914,
7,
199,
9032,
275,
399,
1133,
597,
7,
199,
3078,
3817,
7782,
396,
63,
576,
15,
5797,
9752,
14,
498,
14,
13102,
358,
199,
11163,
3817,
7782,
396,
63,
576,
15,
5797,
9752,
14,
4736,
14,
13102,
358,
199,
30553,
3817,
9569,
83,
8083,
4272,
551,
581,
7,
450,
747,
14,
9458,
342,
199,
10276,
534,
5093,
4796,
351,
13,
751,
13,
2537,
15,
6429,
15,
5797,
478,
1102,
7,
199,
199,
533,
1511,
8,
785,
304,
523,
2505,
275,
399,
1133,
597,
7,
523,
3434,
275,
399,
1159,
8210,
264,
914,
7,
523,
1654,
275,
488,
523,
13727,
275,
399,
7,
1447,
7461,
921,
9642,
14,
1259,
14,
324,
14111,
14,
8654,
26,
26654,
7,
523,
22314,
493,
275,
445,
7387,
3817,
523,
2455,
63,
354,
275,
488,
523,
3384,
63,
1562,
275,
488,
523,
1347,
275,
399,
6704,
7176,
17,
7,
523,
14856,
275,
5049,
199,
199,
533,
577,
8770,
4436,
8,
12562,
14,
4436,
304,
523,
347,
636,
826,
721,
277,
12,
1101,
63,
842,
12,
1844,
304,
272,
5796,
14,
4436,
855,
826,
721,
277,
9,
272,
291,
14,
888,
63,
842,
275,
1101,
63,
842,
272,
291,
14,
719,
275,
1844,
272,
291,
14,
10824,
63,
842,
275,
488,
819,
347,
1255,
8,
277,
304,
272,
291,
14,
10824,
63,
842,
275,
882,
11652,
63,
1000,
14,
3120,
8,
277,
14,
888,
63,
842,
12,
9301,
3817,
12,
6059,
28313,
3817,
9,
272,
291,
14,
10824,
63,
842,
14,
1505,
432,
8,
719,
29,
277,
14,
719,
9,
199,
199,
533,
1379,
5797,
478,
1102,
8,
2796,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
339,
347,
16568,
20782,
4313,
837,
489,
308,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
9484,
9,
489,
308,
14,
3409,
1332,
5449,
12,
378,
430,
489,
5552,
12,
1844,
275,
308,
14,
27886,
342,
489,
308,
14,
1600,
342,
489,
372,
1844,
339,
291,
14,
888,
63,
842,
275,
882,
11652,
63,
1018,
14,
2028,
8,
493,
63,
354,
29,
5569,
63,
3817,
9,
339,
1592,
63,
842,
275,
291,
14,
888,
63,
842,
14,
1002,
8882,
342,
339,
1592,
63,
842,
14,
2499,
50,
29895,
7243,
342,
339,
666,
275,
1551,
8,
3998,
63,
3817,
12,
283,
82,
1959,
739,
342,
272,
1592,
63,
842,
14,
3162,
10161,
342,
272,
1592,
63,
842,
14,
3937,
14,
2526,
8,
576,
9,
272,
1592,
63,
842,
14,
3005,
10161,
342,
272,
1592,
63,
842,
14,
1600,
342,
339,
291,
14,
719,
275,
16568,
20782,
4313,
342,
272,
291,
14,
1000,
63,
354,
275,
283,
2859,
13827,
83,
2689,
83,
7,
450,
334,
5449,
12,
291,
14,
719,
9,
272,
291,
14,
10824,
63,
2671,
275,
577,
8770,
4436,
8,
277,
14,
888,
63,
842,
12,
291,
14,
719,
9,
272,
291,
14,
10824,
63,
2671,
14
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
334,
67,
9,
8937,
12,
23177,
11933,
15904,
199,
3,
2900,
4481,
4644,
14,
199,
3,
221,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
221,
199,
3,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
199,
3,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
642,
199,
3,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
436,
15,
269,
199,
3,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
221,
199,
3,
11443,
314,
536,
402,
314,
23177,
11933,
15904,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
1928,
199,
3,
2488,
6791,
5313,
4983,
14,
199,
3,
221,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
199,
3,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
199,
3,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
199,
3,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
199,
3,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
199,
3,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
13013,
511,
367,
6715,
478,
1102,
199,
199,
5483,
3238,
1265,
787,
3879,
642,
6169,
282,
3050,
626,
883,
506,
28924,
14,
199,
199,
1649,
2845,
662,
2111,
21277,
5749,
7393,
437,
9741,
7834,
437,
3611,
4980,
5430,
31705,
14,
199,
624,
199,
199,
363,
7307,
363,
275,
283,
7384,
334,
35,
9,
8937,
12,
23177,
11933,
15904,
7,
199,
363,
1682,
363,
275,
283,
15400,
7,
199,
363,
1023,
363,
275,
3943,
1766,
8019,
19367,
421,
199,
646,
747,
199,
646,
984,
199,
646,
2838,
199,
646,
5796,
199,
646,
900,
199,
646,
18354,
199,
646,
2882,
421,
199,
646,
882,
11652,
63,
1018,
199,
646,
882,
11652,
63,
1000,
199,
504,
882,
11652,
63,
751,
63,
2537,
221,
492,
882,
11652,
63,
1258,
63,
773,
199,
199,
3791,
63,
5569,
275,
283,
396,
63,
576,
15,
4796,
351,
63,
751,
63,
2537,
14,
2190,
7,
199,
5569,
63,
3817,
275,
283,
396,
63,
576,
15,
4796,
351,
14,
2190,
7,
327,
5679,
315,
511,
63,
576,
199,
10926,
63,
3817,
275,
20644,
4796,
351,
13,
1018,
15,
576,
15,
4659,
63,
3629,
14,
3009,
7,
199,
3998,
63,
3817,
275,
283,
396,
63,
576,
15,
396,
63,
576,
14,
3009,
7,
199,
5449,
275,
399,
7,
5967,
7,
199,
11958,
275,
399,
1159,
8210,
264,
914,
7,
199,
9032,
275,
399,
1133,
597,
7,
199,
3078,
3817,
7782,
396,
63,
576,
15,
5797,
9752,
14,
498,
14,
13102,
358,
199,
11163,
3817,
7782,
396,
63,
576,
15,
5797,
9752,
14,
4736,
14,
13102,
358,
199,
30553,
3817,
9569,
83,
8083,
4272,
551,
581,
7,
450,
747,
14,
9458,
342,
199,
10276,
534,
5093,
4796,
351,
13,
751,
13,
2537,
15,
6429,
15,
5797,
478,
1102,
7,
199,
199,
533,
1511,
8,
785,
304,
523,
2505,
275,
399,
1133,
597,
7,
523,
3434,
275,
399,
1159,
8210,
264,
914,
7,
523,
1654,
275,
488,
523,
13727,
275,
399,
7,
1447,
7461,
921,
9642,
14,
1259,
14,
324,
14111,
14,
8654,
26,
26654,
7,
523,
22314,
493,
275,
445,
7387,
3817,
523,
2455,
63,
354,
275,
488,
523,
3384,
63,
1562,
275,
488,
523,
1347,
275,
399,
6704,
7176,
17,
7,
523,
14856,
275,
5049,
199,
199,
533,
577,
8770,
4436,
8,
12562,
14,
4436,
304,
523,
347,
636,
826,
721,
277,
12,
1101,
63,
842,
12,
1844,
304,
272,
5796,
14,
4436,
855,
826,
721,
277,
9,
272,
291,
14,
888,
63,
842,
275,
1101,
63,
842,
272,
291,
14,
719,
275,
1844,
272,
291,
14,
10824,
63,
842,
275,
488,
819,
347,
1255,
8,
277,
304,
272,
291,
14,
10824,
63,
842,
275,
882,
11652,
63,
1000,
14,
3120,
8,
277,
14,
888,
63,
842,
12,
9301,
3817,
12,
6059,
28313,
3817,
9,
272,
291,
14,
10824,
63,
842,
14,
1505,
432,
8,
719,
29,
277,
14,
719,
9,
199,
199,
533,
1379,
5797,
478,
1102,
8,
2796,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
339,
347,
16568,
20782,
4313,
837,
489,
308,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
9484,
9,
489,
308,
14,
3409,
1332,
5449,
12,
378,
430,
489,
5552,
12,
1844,
275,
308,
14,
27886,
342,
489,
308,
14,
1600,
342,
489,
372,
1844,
339,
291,
14,
888,
63,
842,
275,
882,
11652,
63,
1018,
14,
2028,
8,
493,
63,
354,
29,
5569,
63,
3817,
9,
339,
1592,
63,
842,
275,
291,
14,
888,
63,
842,
14,
1002,
8882,
342,
339,
1592,
63,
842,
14,
2499,
50,
29895,
7243,
342,
339,
666,
275,
1551,
8,
3998,
63,
3817,
12,
283,
82,
1959,
739,
342,
272,
1592,
63,
842,
14,
3162,
10161,
342,
272,
1592,
63,
842,
14,
3937,
14,
2526,
8,
576,
9,
272,
1592,
63,
842,
14,
3005,
10161,
342,
272,
1592,
63,
842,
14,
1600,
342,
339,
291,
14,
719,
275,
16568,
20782,
4313,
342,
272,
291,
14,
1000,
63,
354,
275,
283,
2859,
13827,
83,
2689,
83,
7,
450,
334,
5449,
12,
291,
14,
719,
9,
272,
291,
14,
10824,
63,
2671,
275,
577,
8770,
4436,
8,
277,
14,
888,
63,
842,
12,
291,
14,
719,
9,
272,
291,
14,
10824,
63,
2671,
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,
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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
] |
kawasaki2013/getting-started-python
|
optional-container-engine/tests/test_crud.py
|
17
|
3024
|
# Copyright 2015 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import re
from conftest import flaky_filter
from flaky import flaky
import pytest
# Mark all test cases in this class as flaky, so that if errors occur they
# can be retried. This is useful when databases are temporarily unavailable.
@flaky(rerun_filter=flaky_filter)
# Tell pytest to use both the app and model fixtures for all test cases.
# This ensures that configuration is properly applied and that all database
# resources created during tests are cleaned up. These fixtures are defined
# in conftest.py
@pytest.mark.usefixtures('app', 'model')
class TestCrudActions(object):
def test_list(self, app, model):
for i in range(1, 12):
model.create({'title': u'Book {0}'.format(i)})
with app.test_client() as c:
rv = c.get('/books/')
assert rv.status == '200 OK'
body = rv.data.decode('utf-8')
assert 'Book 1' in body, "Should show books"
assert len(re.findall('<h4>Book', body)) == 10, (
"Should not show more than 10 books")
assert 'More' in body, "Should have more than one page"
def test_add(self, app):
data = {
'title': 'Test Book',
'author': 'Test Author',
'publishedDate': 'Test Date Published',
'description': 'Test Description'
}
with app.test_client() as c:
rv = c.post('/books/add', data=data, follow_redirects=True)
assert rv.status == '200 OK'
body = rv.data.decode('utf-8')
assert 'Test Book' in body
assert 'Test Author' in body
assert 'Test Date Published' in body
assert 'Test Description' in body
def test_edit(self, app, model):
existing = model.create({'title': "Temp Title"})
with app.test_client() as c:
rv = c.post(
'/books/%s/edit' % existing['id'],
data={'title': 'Updated Title'},
follow_redirects=True)
assert rv.status == '200 OK'
body = rv.data.decode('utf-8')
assert 'Updated Title' in body
assert 'Temp Title' not in body
def test_delete(self, app, model):
existing = model.create({'title': "Temp Title"})
with app.test_client() as c:
rv = c.get(
'/books/%s/delete' % existing['id'],
follow_redirects=True)
assert rv.status == '200 OK'
assert not model.read(existing['id'])
|
apache-2.0
|
[
3,
1898,
6900,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
295,
199,
199,
504,
3743,
396,
492,
17566,
10562,
63,
1541,
199,
504,
17566,
10562,
492,
17566,
10562,
199,
646,
4613,
421,
199,
3,
7173,
1006,
511,
5560,
315,
642,
1021,
465,
17566,
10562,
12,
880,
626,
340,
2552,
4781,
2985,
199,
3,
883,
506,
4444,
379,
14,
961,
365,
2997,
1380,
16219,
787,
22256,
18735,
14,
199,
32,
14163,
10562,
8,
264,
1065,
63,
1541,
29,
14163,
10562,
63,
1541,
9,
199,
3,
30528,
4613,
370,
675,
3865,
314,
1145,
436,
1402,
15188,
367,
1006,
511,
5560,
14,
199,
3,
961,
15620,
626,
2897,
365,
7684,
6781,
436,
626,
1006,
3050,
199,
3,
5944,
2737,
5309,
2295,
787,
12364,
1536,
14,
5723,
15188,
787,
3247,
199,
3,
315,
3743,
396,
14,
647,
199,
32,
4462,
14,
1657,
14,
1180,
8769,
360,
571,
297,
283,
1238,
358,
199,
533,
1379,
17345,
1181,
9303,
8,
785,
304,
339,
347,
511,
63,
513,
8,
277,
12,
1145,
12,
1402,
304,
267,
367,
284,
315,
1425,
8,
17,
12,
3144,
304,
288,
1402,
14,
981,
3252,
1213,
356,
399,
7,
8696,
469,
16,
5285,
908,
8,
73,
11466,
398,
543,
1145,
14,
396,
63,
1258,
342,
465,
286,
26,
288,
4336,
275,
286,
14,
362,
2336,
8858,
6217,
398,
702,
4336,
14,
1205,
508,
283,
1840,
9949,
7,
398,
2396,
275,
4336,
14,
576,
14,
2708,
360,
1624,
13,
24,
358,
267,
702,
283,
8696,
413,
7,
315,
2396,
12,
298,
11408,
2498,
19040,
2,
267,
702,
822,
8,
264,
14,
6452,
4827,
72,
20,
30,
8696,
297,
2396,
430,
508,
1616,
12,
334,
288,
298,
11408,
440,
2498,
1655,
2419,
1616,
19040,
531,
267,
702,
283,
11053,
7,
315,
2396,
12,
298,
11408,
1172,
1655,
2419,
1373,
2034,
2,
339,
347,
511,
63,
525,
8,
277,
12,
1145,
304,
267,
666,
275,
469,
288,
283,
1213,
356,
283,
774,
8944,
297,
288,
283,
2502,
356,
283,
774,
6529,
297,
288,
283,
8987,
2506,
356,
283,
774,
6148,
19952,
379,
297,
288,
283,
1802,
356,
283,
774,
11994,
7,
267,
789,
398,
543,
1145,
14,
396,
63,
1258,
342,
465,
286,
26,
288,
4336,
275,
286,
14,
1932,
2336,
8858,
15,
525,
297,
666,
29,
576,
12,
2035,
63,
13607,
29,
549,
9,
398,
702,
4336,
14,
1205,
508,
283,
1840,
9949,
7,
267,
2396,
275,
4336,
14,
576,
14,
2708,
360,
1624,
13,
24,
358,
267,
702,
283,
774,
8944,
7,
315,
2396,
267,
702,
283,
774,
6529,
7,
315,
2396,
267,
702,
283,
774,
6148,
19952,
379,
7,
315,
2396,
267,
702,
283,
774,
11994,
7,
315,
2396,
339,
347,
511,
63,
3773,
8,
277,
12,
1145,
12,
1402,
304,
267,
3411,
275,
1402,
14,
981,
3252,
1213,
356,
298,
6530,
16881,
5984,
398,
543,
1145,
14,
396,
63,
1258,
342,
465,
286,
26,
288,
4336,
275,
286,
14,
1932,
8,
355,
1994,
8858,
3149,
83,
15,
3773,
7,
450,
3411,
459,
344,
995,
355,
666,
3713,
1213,
356,
283,
19920,
16881,
2267,
355,
2035,
63,
13607,
29,
549,
9,
398,
702,
4336,
14,
1205,
508,
283,
1840,
9949,
7,
267,
2396,
275,
4336,
14,
576,
14,
2708,
360,
1624,
13,
24,
358,
267,
702,
283,
19920,
16881,
7,
315,
2396,
267,
702,
283,
6530,
16881,
7,
440,
315,
2396,
339,
347,
511,
63,
1807,
8,
277,
12,
1145,
12,
1402,
304,
267,
3411,
275,
1402,
14,
981,
3252,
1213,
356,
298,
6530,
16881,
5984,
398,
543,
1145,
14,
396,
63,
1258,
342,
465,
286,
26,
288,
4336,
275,
286,
14,
362,
8,
355,
1994,
8858,
3149,
83,
15,
1807,
7,
450,
3411,
459,
344,
995,
355,
2035,
63,
13607,
29,
549,
9,
398,
702,
4336,
14,
1205,
508,
283,
1840,
9949,
7,
267,
702,
440,
1402,
14,
739,
8,
5952,
459,
344,
1105,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6900,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
295,
199,
199,
504,
3743,
396,
492,
17566,
10562,
63,
1541,
199,
504,
17566,
10562,
492,
17566,
10562,
199,
646,
4613,
421,
199,
3,
7173,
1006,
511,
5560,
315,
642,
1021,
465,
17566,
10562,
12,
880,
626,
340,
2552,
4781,
2985,
199,
3,
883,
506,
4444,
379,
14,
961,
365,
2997,
1380,
16219,
787,
22256,
18735,
14,
199,
32,
14163,
10562,
8,
264,
1065,
63,
1541,
29,
14163,
10562,
63,
1541,
9,
199,
3,
30528,
4613,
370,
675,
3865,
314,
1145,
436,
1402,
15188,
367,
1006,
511,
5560,
14,
199,
3,
961,
15620,
626,
2897,
365,
7684,
6781,
436,
626,
1006,
3050,
199,
3,
5944,
2737,
5309,
2295,
787,
12364,
1536,
14,
5723,
15188,
787,
3247,
199,
3,
315,
3743,
396,
14,
647,
199,
32,
4462,
14,
1657,
14,
1180,
8769,
360,
571,
297,
283,
1238,
358,
199,
533,
1379,
17345,
1181,
9303,
8,
785,
304,
339,
347,
511,
63,
513,
8,
277,
12,
1145,
12,
1402,
304,
267,
367,
284,
315,
1425,
8,
17,
12,
3144,
304,
288,
1402,
14,
981,
3252,
1213,
356,
399,
7,
8696,
469,
16,
5285,
908,
8,
73,
11466,
398,
543,
1145,
14,
396,
63,
1258,
342,
465,
286,
26,
288,
4336,
275,
286,
14,
362,
2336,
8858,
6217,
398,
702,
4336,
14,
1205,
508,
283,
1840,
9949,
7,
398,
2396,
275,
4336,
14,
576,
14,
2708,
360,
1624,
13,
24,
358,
267,
702,
283,
8696,
413,
7,
315,
2396,
12,
298,
11408,
2498,
19040,
2,
267,
702,
822,
8,
264,
14,
6452,
4827,
72,
20,
30,
8696,
297,
2396,
430,
508,
1616,
12,
334,
288,
298,
11408,
440,
2498,
1655,
2419,
1616,
19040,
531,
267,
702,
283,
11053,
7,
315,
2396,
12,
298,
11408,
1172,
1655,
2419,
1373,
2034,
2,
339,
347,
511,
63,
525,
8,
277,
12,
1145,
304,
267,
666,
275,
469,
288,
283,
1213,
356,
283,
774,
8944,
297,
288,
283,
2502,
356,
283,
774,
6529,
297,
288,
283,
8987,
2506,
356,
283,
774,
6148,
19952,
379,
297,
288,
283,
1802,
356,
283,
774,
11994,
7,
267,
789,
398,
543,
1145,
14,
396,
63,
1258,
342,
465,
286,
26,
288,
4336,
275,
286,
14,
1932,
2336,
8858,
15,
525,
297,
666,
29,
576,
12,
2035,
63,
13607,
29,
549,
9,
398,
702,
4336,
14,
1205,
508,
283,
1840,
9949,
7,
267,
2396,
275,
4336,
14,
576,
14,
2708,
360,
1624,
13,
24,
358,
267,
702,
283,
774,
8944,
7,
315,
2396,
267,
702,
283,
774,
6529,
7,
315,
2396,
267,
702,
283,
774,
6148,
19952,
379,
7,
315,
2396,
267,
702,
283,
774,
11994,
7,
315,
2396,
339,
347,
511,
63,
3773,
8,
277,
12,
1145,
12,
1402,
304,
267,
3411,
275,
1402,
14,
981,
3252,
1213,
356,
298,
6530,
16881,
5984,
398,
543,
1145,
14,
396,
63,
1258,
342,
465,
286,
26,
288,
4336,
275,
286,
14,
1932,
8,
355,
1994,
8858,
3149,
83,
15,
3773,
7,
450,
3411,
459,
344,
995,
355,
666,
3713,
1213,
356,
283,
19920,
16881,
2267,
355,
2035,
63,
13607,
29,
549,
9,
398,
702,
4336,
14,
1205,
508,
283,
1840,
9949,
7,
267,
2396,
275,
4336,
14,
576,
14,
2708,
360,
1624,
13,
24,
358,
267,
702,
283,
19920,
16881,
7,
315,
2396,
267,
702,
283,
6530,
16881,
7,
440,
315,
2396,
339,
347,
511,
63,
1807,
8,
277,
12,
1145,
12,
1402,
304,
267,
3411,
275,
1402,
14,
981,
3252,
1213,
356,
298,
6530,
16881,
5984,
398,
543,
1145,
14,
396,
63,
1258,
342,
465,
286,
26,
288,
4336,
275,
286,
14,
362,
8,
355,
1994,
8858,
3149,
83,
15,
1807,
7,
450,
3411,
459,
344,
995,
355,
2035,
63,
13607,
29,
549,
9,
398,
702,
4336,
14,
1205,
508,
283,
1840,
9949,
7,
267,
702,
440,
1402,
14,
739,
8,
5952,
459,
344,
1105,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
gigglesninja/senior-design
|
MissionPlanner/Lib/lib2to3/pgen2/conv.py
|
325
|
9627
|
# Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Convert graminit.[ch] spit out by pgen to Python code.
Pgen is the Python parser generator. It is useful to quickly create a
parser from a grammar file in Python's grammar notation. But I don't
want my parsers to be written in C (yet), so I'm translating the
parsing tables to Python data structures and writing a Python parse
engine.
Note that the token numbers are constants determined by the standard
Python tokenizer. The standard token module defines these numbers and
their names (the names are not used much). The token numbers are
hardcoded into the Python tokenizer and into pgen. A Python
implementation of the Python tokenizer is also available, in the
standard tokenize module.
On the other hand, symbol numbers (representing the grammar's
non-terminals) are assigned by pgen based on the actual grammar
input.
Note: this module is pretty much obsolete; the pgen module generates
equivalent grammar tables directly from the Grammar.txt input file
without having to invoke the Python pgen C program.
"""
# Python imports
import re
# Local imports
from pgen2 import grammar, token
class Converter(grammar.Grammar):
"""Grammar subclass that reads classic pgen output files.
The run() method reads the tables as produced by the pgen parser
generator, typically contained in two C files, graminit.h and
graminit.c. The other methods are for internal use only.
See the base class for more documentation.
"""
def run(self, graminit_h, graminit_c):
"""Load the grammar tables from the text files written by pgen."""
self.parse_graminit_h(graminit_h)
self.parse_graminit_c(graminit_c)
self.finish_off()
def parse_graminit_h(self, filename):
"""Parse the .h file written by pgen. (Internal)
This file is a sequence of #define statements defining the
nonterminals of the grammar as numbers. We build two tables
mapping the numbers to names and back.
"""
try:
f = open(filename)
except IOError, err:
print "Can't open %s: %s" % (filename, err)
return False
self.symbol2number = {}
self.number2symbol = {}
lineno = 0
for line in f:
lineno += 1
mo = re.match(r"^#define\s+(\w+)\s+(\d+)$", line)
if not mo and line.strip():
print "%s(%s): can't parse %s" % (filename, lineno,
line.strip())
else:
symbol, number = mo.groups()
number = int(number)
assert symbol not in self.symbol2number
assert number not in self.number2symbol
self.symbol2number[symbol] = number
self.number2symbol[number] = symbol
return True
def parse_graminit_c(self, filename):
"""Parse the .c file written by pgen. (Internal)
The file looks as follows. The first two lines are always this:
#include "pgenheaders.h"
#include "grammar.h"
After that come four blocks:
1) one or more state definitions
2) a table defining dfas
3) a table defining labels
4) a struct defining the grammar
A state definition has the following form:
- one or more arc arrays, each of the form:
static arc arcs_<n>_<m>[<k>] = {
{<i>, <j>},
...
};
- followed by a state array, of the form:
static state states_<s>[<t>] = {
{<k>, arcs_<n>_<m>},
...
};
"""
try:
f = open(filename)
except IOError, err:
print "Can't open %s: %s" % (filename, err)
return False
# The code below essentially uses f's iterator-ness!
lineno = 0
# Expect the two #include lines
lineno, line = lineno+1, f.next()
assert line == '#include "pgenheaders.h"\n', (lineno, line)
lineno, line = lineno+1, f.next()
assert line == '#include "grammar.h"\n', (lineno, line)
# Parse the state definitions
lineno, line = lineno+1, f.next()
allarcs = {}
states = []
while line.startswith("static arc "):
while line.startswith("static arc "):
mo = re.match(r"static arc arcs_(\d+)_(\d+)\[(\d+)\] = {$",
line)
assert mo, (lineno, line)
n, m, k = map(int, mo.groups())
arcs = []
for _ in range(k):
lineno, line = lineno+1, f.next()
mo = re.match(r"\s+{(\d+), (\d+)},$", line)
assert mo, (lineno, line)
i, j = map(int, mo.groups())
arcs.append((i, j))
lineno, line = lineno+1, f.next()
assert line == "};\n", (lineno, line)
allarcs[(n, m)] = arcs
lineno, line = lineno+1, f.next()
mo = re.match(r"static state states_(\d+)\[(\d+)\] = {$", line)
assert mo, (lineno, line)
s, t = map(int, mo.groups())
assert s == len(states), (lineno, line)
state = []
for _ in range(t):
lineno, line = lineno+1, f.next()
mo = re.match(r"\s+{(\d+), arcs_(\d+)_(\d+)},$", line)
assert mo, (lineno, line)
k, n, m = map(int, mo.groups())
arcs = allarcs[n, m]
assert k == len(arcs), (lineno, line)
state.append(arcs)
states.append(state)
lineno, line = lineno+1, f.next()
assert line == "};\n", (lineno, line)
lineno, line = lineno+1, f.next()
self.states = states
# Parse the dfas
dfas = {}
mo = re.match(r"static dfa dfas\[(\d+)\] = {$", line)
assert mo, (lineno, line)
ndfas = int(mo.group(1))
for i in range(ndfas):
lineno, line = lineno+1, f.next()
mo = re.match(r'\s+{(\d+), "(\w+)", (\d+), (\d+), states_(\d+),$',
line)
assert mo, (lineno, line)
symbol = mo.group(2)
number, x, y, z = map(int, mo.group(1, 3, 4, 5))
assert self.symbol2number[symbol] == number, (lineno, line)
assert self.number2symbol[number] == symbol, (lineno, line)
assert x == 0, (lineno, line)
state = states[z]
assert y == len(state), (lineno, line)
lineno, line = lineno+1, f.next()
mo = re.match(r'\s+("(?:\\\d\d\d)*")},$', line)
assert mo, (lineno, line)
first = {}
rawbitset = eval(mo.group(1))
for i, c in enumerate(rawbitset):
byte = ord(c)
for j in range(8):
if byte & (1<<j):
first[i*8 + j] = 1
dfas[number] = (state, first)
lineno, line = lineno+1, f.next()
assert line == "};\n", (lineno, line)
self.dfas = dfas
# Parse the labels
labels = []
lineno, line = lineno+1, f.next()
mo = re.match(r"static label labels\[(\d+)\] = {$", line)
assert mo, (lineno, line)
nlabels = int(mo.group(1))
for i in range(nlabels):
lineno, line = lineno+1, f.next()
mo = re.match(r'\s+{(\d+), (0|"\w+")},$', line)
assert mo, (lineno, line)
x, y = mo.groups()
x = int(x)
if y == "0":
y = None
else:
y = eval(y)
labels.append((x, y))
lineno, line = lineno+1, f.next()
assert line == "};\n", (lineno, line)
self.labels = labels
# Parse the grammar struct
lineno, line = lineno+1, f.next()
assert line == "grammar _PyParser_Grammar = {\n", (lineno, line)
lineno, line = lineno+1, f.next()
mo = re.match(r"\s+(\d+),$", line)
assert mo, (lineno, line)
ndfas = int(mo.group(1))
assert ndfas == len(self.dfas)
lineno, line = lineno+1, f.next()
assert line == "\tdfas,\n", (lineno, line)
lineno, line = lineno+1, f.next()
mo = re.match(r"\s+{(\d+), labels},$", line)
assert mo, (lineno, line)
nlabels = int(mo.group(1))
assert nlabels == len(self.labels), (lineno, line)
lineno, line = lineno+1, f.next()
mo = re.match(r"\s+(\d+)$", line)
assert mo, (lineno, line)
start = int(mo.group(1))
assert start in self.number2symbol, (lineno, line)
self.start = start
lineno, line = lineno+1, f.next()
assert line == "};\n", (lineno, line)
try:
lineno, line = lineno+1, f.next()
except StopIteration:
pass
else:
assert 0, (lineno, line)
def finish_off(self):
"""Create additional useful structures. (Internal)."""
self.keywords = {} # map from keyword strings to arc labels
self.tokens = {} # map from numeric token values to arc labels
for ilabel, (type, value) in enumerate(self.labels):
if type == token.NAME and value is not None:
self.keywords[value] = ilabel
elif value is None:
self.tokens[type] = ilabel
|
gpl-2.0
|
[
3,
1898,
8353,
13,
9397,
6566,
279,
13863,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
624,
7306,
1999,
77,
826,
24097,
335,
61,
2249,
390,
734,
701,
299,
2268,
370,
2018,
1233,
14,
199,
199,
48,
2268,
365,
314,
2018,
1798,
4306,
14,
221,
2779,
365,
2997,
370,
23661,
1218,
282,
199,
2087,
687,
282,
12528,
570,
315,
2018,
1159,
12528,
15843,
14,
221,
11017,
473,
2793,
1133,
199,
7051,
3002,
21295,
370,
506,
5313,
315,
445,
334,
28064,
395,
880,
473,
6704,
1752,
24615,
314,
199,
11059,
6716,
370,
2018,
666,
13955,
436,
3575,
282,
2018,
2198,
199,
3908,
14,
199,
199,
7443,
626,
314,
1526,
5579,
787,
5262,
12037,
701,
314,
4465,
199,
4718,
14803,
14,
221,
710,
4465,
1526,
859,
7890,
3520,
5579,
436,
199,
1589,
723,
1561,
334,
1589,
1561,
787,
440,
1202,
8298,
680,
221,
710,
1526,
5579,
787,
199,
8726,
15282,
1901,
314,
2018,
14803,
436,
1901,
299,
2268,
14,
221,
437,
2018,
199,
12236,
402,
314,
2018,
14803,
365,
2597,
2808,
12,
315,
314,
199,
6807,
13343,
859,
14,
199,
199,
3314,
314,
1163,
4926,
12,
5272,
5579,
334,
13063,
316,
314,
12528,
1159,
199,
2865,
13,
24322,
9,
787,
7943,
701,
299,
2268,
4079,
641,
314,
3503,
12528,
199,
1210,
14,
199,
199,
7443,
26,
642,
859,
365,
7268,
8298,
24985,
27,
314,
299,
2268,
859,
12821,
199,
24179,
12528,
6716,
5370,
687,
314,
10268,
9992,
14,
2424,
1324,
570,
199,
7395,
9445,
370,
12677,
314,
2018,
299,
2268,
445,
2240,
14,
199,
199,
624,
199,
199,
3,
2018,
8925,
199,
646,
295,
199,
199,
3,
10111,
8925,
199,
504,
299,
2268,
18,
492,
12528,
12,
1526,
421,
199,
533,
11801,
351,
8,
15239,
14,
27119,
304,
272,
408,
27119,
5516,
626,
11597,
31205,
299,
2268,
1072,
1584,
14,
339,
710,
1255,
342,
1083,
11597,
314,
6716,
465,
13584,
701,
314,
299,
2268,
1798,
272,
4306,
12,
13609,
10470,
315,
2877,
445,
1584,
12,
1999,
77,
826,
14,
72,
436,
272,
1999,
77,
826,
14,
67,
14,
221,
710,
1163,
3102,
787,
367,
5007,
675,
1454,
14,
339,
1666,
314,
1300,
1021,
367,
1655,
3794,
14,
339,
408,
339,
347,
1255,
8,
277,
12,
1999,
77,
826,
63,
72,
12,
1999,
77,
826,
63,
67,
304,
267,
408,
6200,
314,
12528,
6716,
687,
314,
1318,
1584,
5313,
701,
299,
2268,
1041,
267,
291,
14,
1122,
63,
1679,
826,
63,
72,
8,
1679,
826,
63,
72,
9,
267,
291,
14,
1122,
63,
1679,
826,
63,
67,
8,
1679,
826,
63,
67,
9,
267,
291,
14,
8192,
63,
1997,
342,
339,
347,
2198,
63,
1679,
826,
63,
72,
8,
277,
12,
1788,
304,
267,
408,
4003,
314,
1275,
72,
570,
5313,
701,
299,
2268,
14,
221,
334,
8405,
9,
398,
961,
570,
365,
282,
3414,
402,
327,
4640,
9834,
12669,
314,
267,
2222,
24322,
402,
314,
12528,
465,
5579,
14,
221,
2136,
1900,
2877,
6716,
267,
4412,
314,
5579,
370,
1561,
436,
1771,
14,
398,
408,
267,
862,
26,
288,
289,
275,
1551,
8,
1501,
9,
267,
871,
5925,
12,
2329,
26,
288,
870,
298,
6049,
1133,
1551,
450,
83,
26,
450,
83,
2,
450,
334,
1501,
12,
2329,
9,
288,
372,
756,
267,
291,
14,
5155,
18,
1955,
275,
1052,
267,
291,
14,
1955,
18,
5155,
275,
1052,
267,
5874,
275,
378,
267,
367,
1004,
315,
289,
26,
288,
5874,
847,
413,
288,
1303,
275,
295,
14,
1431,
8,
82,
16136,
3,
4640,
60,
83,
20900,
87,
13439,
83,
20900,
68,
8771,
11918,
1004,
9,
288,
340,
440,
1303,
436,
1004,
14,
1913,
837,
355,
870,
2071,
83,
4042,
83,
304,
883,
1133,
2198,
450,
83,
2,
450,
334,
1501,
12,
5874,
12,
8179,
1004,
14,
1913,
1012,
288,
587,
26,
355,
5272,
12,
1329,
275,
1303,
14,
2634,
342,
355,
1329,
275,
1109,
8,
1955,
9,
355,
702,
5272,
440,
315,
291,
14,
5155,
18,
1955,
355,
702,
1329,
440,
315,
291,
14,
1955,
18,
5155,
355,
291,
14,
5155,
18,
1955,
59,
5155,
61,
275,
1329,
355,
291,
14,
1955,
18,
5155,
59,
1955,
61,
275,
5272,
267,
372,
715,
339,
347,
2198,
63,
1679,
826,
63,
67,
8,
277,
12,
1788,
304,
267,
408,
4003,
314,
1275,
67,
570,
5313,
701,
299,
2268,
14,
221,
334,
8405,
9,
398,
710,
570,
10734,
465,
11924,
14,
221,
710,
1642,
2877,
2385,
787,
3544,
642,
26,
398,
327,
2613,
298,
80,
2268,
2139,
14,
72,
2,
267,
327,
2613,
298,
15239,
14,
72,
2,
398,
12836,
626,
11492,
11648,
5664,
26,
398,
413,
9,
1373,
503,
1655,
1174,
10269,
267,
499,
9,
282,
1817,
12669,
4051,
305,
267,
650,
9,
282,
1817,
12669,
3628,
267,
841,
9,
282,
2702,
12669,
314,
12528,
398,
437,
1174,
5492,
965,
314,
2569,
1824,
26,
267,
446,
1373,
503,
1655,
14972,
6572,
12,
1924,
402,
314,
1824,
26,
881,
2955,
14972,
601,
1259,
27718,
78,
30,
27718,
77,
9514,
28,
75,
19109,
275,
469,
2116,
469,
28,
73,
6244,
665,
74,
30,
1386,
2116,
2263,
881,
16735,
267,
446,
9437,
701,
282,
1174,
1625,
12,
402,
314,
1824,
26,
881,
2955,
1174,
6363,
27718,
83,
9514,
28,
84,
19109,
275,
469,
2116,
469,
28,
75,
6244,
601,
1259,
27718,
78,
30,
27718,
77,
30,
1386,
2116,
2263,
881,
16735,
398,
408,
267,
862,
26,
288,
289,
275,
1551,
8,
1501,
9,
267,
871,
5925,
12,
2329,
26,
288,
870,
298,
6049,
1133,
1551,
450,
83,
26,
450,
83,
2,
450,
334,
1501,
12,
2329,
9,
288,
372,
756,
267,
327,
710,
1233,
5084,
28891,
4440,
289,
1159,
6122,
13,
4171,
1,
267,
5874,
275,
378,
398,
327,
15100,
314,
2877,
327,
2613,
2385,
267,
5874,
12,
1004,
275,
5874,
11,
17,
12,
289,
14,
2184,
342,
267,
702,
1004,
508,
3943,
2613,
298,
80,
2268,
2139,
14,
72,
3212,
78,
297,
334,
3469,
12,
1004,
9,
267,
5874,
12,
1004,
275,
5874,
11,
17,
12,
289,
14,
2184,
342,
267,
702,
1004,
508,
3943,
2613,
298,
15239,
14,
72,
3212,
78,
297,
334,
3469,
12,
1004,
9,
398,
327,
6077,
314,
1174,
10269,
267,
5874,
12,
1004,
275
] |
[
1898,
8353,
13,
9397,
6566,
279,
13863,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
624,
7306,
1999,
77,
826,
24097,
335,
61,
2249,
390,
734,
701,
299,
2268,
370,
2018,
1233,
14,
199,
199,
48,
2268,
365,
314,
2018,
1798,
4306,
14,
221,
2779,
365,
2997,
370,
23661,
1218,
282,
199,
2087,
687,
282,
12528,
570,
315,
2018,
1159,
12528,
15843,
14,
221,
11017,
473,
2793,
1133,
199,
7051,
3002,
21295,
370,
506,
5313,
315,
445,
334,
28064,
395,
880,
473,
6704,
1752,
24615,
314,
199,
11059,
6716,
370,
2018,
666,
13955,
436,
3575,
282,
2018,
2198,
199,
3908,
14,
199,
199,
7443,
626,
314,
1526,
5579,
787,
5262,
12037,
701,
314,
4465,
199,
4718,
14803,
14,
221,
710,
4465,
1526,
859,
7890,
3520,
5579,
436,
199,
1589,
723,
1561,
334,
1589,
1561,
787,
440,
1202,
8298,
680,
221,
710,
1526,
5579,
787,
199,
8726,
15282,
1901,
314,
2018,
14803,
436,
1901,
299,
2268,
14,
221,
437,
2018,
199,
12236,
402,
314,
2018,
14803,
365,
2597,
2808,
12,
315,
314,
199,
6807,
13343,
859,
14,
199,
199,
3314,
314,
1163,
4926,
12,
5272,
5579,
334,
13063,
316,
314,
12528,
1159,
199,
2865,
13,
24322,
9,
787,
7943,
701,
299,
2268,
4079,
641,
314,
3503,
12528,
199,
1210,
14,
199,
199,
7443,
26,
642,
859,
365,
7268,
8298,
24985,
27,
314,
299,
2268,
859,
12821,
199,
24179,
12528,
6716,
5370,
687,
314,
10268,
9992,
14,
2424,
1324,
570,
199,
7395,
9445,
370,
12677,
314,
2018,
299,
2268,
445,
2240,
14,
199,
199,
624,
199,
199,
3,
2018,
8925,
199,
646,
295,
199,
199,
3,
10111,
8925,
199,
504,
299,
2268,
18,
492,
12528,
12,
1526,
421,
199,
533,
11801,
351,
8,
15239,
14,
27119,
304,
272,
408,
27119,
5516,
626,
11597,
31205,
299,
2268,
1072,
1584,
14,
339,
710,
1255,
342,
1083,
11597,
314,
6716,
465,
13584,
701,
314,
299,
2268,
1798,
272,
4306,
12,
13609,
10470,
315,
2877,
445,
1584,
12,
1999,
77,
826,
14,
72,
436,
272,
1999,
77,
826,
14,
67,
14,
221,
710,
1163,
3102,
787,
367,
5007,
675,
1454,
14,
339,
1666,
314,
1300,
1021,
367,
1655,
3794,
14,
339,
408,
339,
347,
1255,
8,
277,
12,
1999,
77,
826,
63,
72,
12,
1999,
77,
826,
63,
67,
304,
267,
408,
6200,
314,
12528,
6716,
687,
314,
1318,
1584,
5313,
701,
299,
2268,
1041,
267,
291,
14,
1122,
63,
1679,
826,
63,
72,
8,
1679,
826,
63,
72,
9,
267,
291,
14,
1122,
63,
1679,
826,
63,
67,
8,
1679,
826,
63,
67,
9,
267,
291,
14,
8192,
63,
1997,
342,
339,
347,
2198,
63,
1679,
826,
63,
72,
8,
277,
12,
1788,
304,
267,
408,
4003,
314,
1275,
72,
570,
5313,
701,
299,
2268,
14,
221,
334,
8405,
9,
398,
961,
570,
365,
282,
3414,
402,
327,
4640,
9834,
12669,
314,
267,
2222,
24322,
402,
314,
12528,
465,
5579,
14,
221,
2136,
1900,
2877,
6716,
267,
4412,
314,
5579,
370,
1561,
436,
1771,
14,
398,
408,
267,
862,
26,
288,
289,
275,
1551,
8,
1501,
9,
267,
871,
5925,
12,
2329,
26,
288,
870,
298,
6049,
1133,
1551,
450,
83,
26,
450,
83,
2,
450,
334,
1501,
12,
2329,
9,
288,
372,
756,
267,
291,
14,
5155,
18,
1955,
275,
1052,
267,
291,
14,
1955,
18,
5155,
275,
1052,
267,
5874,
275,
378,
267,
367,
1004,
315,
289,
26,
288,
5874,
847,
413,
288,
1303,
275,
295,
14,
1431,
8,
82,
16136,
3,
4640,
60,
83,
20900,
87,
13439,
83,
20900,
68,
8771,
11918,
1004,
9,
288,
340,
440,
1303,
436,
1004,
14,
1913,
837,
355,
870,
2071,
83,
4042,
83,
304,
883,
1133,
2198,
450,
83,
2,
450,
334,
1501,
12,
5874,
12,
8179,
1004,
14,
1913,
1012,
288,
587,
26,
355,
5272,
12,
1329,
275,
1303,
14,
2634,
342,
355,
1329,
275,
1109,
8,
1955,
9,
355,
702,
5272,
440,
315,
291,
14,
5155,
18,
1955,
355,
702,
1329,
440,
315,
291,
14,
1955,
18,
5155,
355,
291,
14,
5155,
18,
1955,
59,
5155,
61,
275,
1329,
355,
291,
14,
1955,
18,
5155,
59,
1955,
61,
275,
5272,
267,
372,
715,
339,
347,
2198,
63,
1679,
826,
63,
67,
8,
277,
12,
1788,
304,
267,
408,
4003,
314,
1275,
67,
570,
5313,
701,
299,
2268,
14,
221,
334,
8405,
9,
398,
710,
570,
10734,
465,
11924,
14,
221,
710,
1642,
2877,
2385,
787,
3544,
642,
26,
398,
327,
2613,
298,
80,
2268,
2139,
14,
72,
2,
267,
327,
2613,
298,
15239,
14,
72,
2,
398,
12836,
626,
11492,
11648,
5664,
26,
398,
413,
9,
1373,
503,
1655,
1174,
10269,
267,
499,
9,
282,
1817,
12669,
4051,
305,
267,
650,
9,
282,
1817,
12669,
3628,
267,
841,
9,
282,
2702,
12669,
314,
12528,
398,
437,
1174,
5492,
965,
314,
2569,
1824,
26,
267,
446,
1373,
503,
1655,
14972,
6572,
12,
1924,
402,
314,
1824,
26,
881,
2955,
14972,
601,
1259,
27718,
78,
30,
27718,
77,
9514,
28,
75,
19109,
275,
469,
2116,
469,
28,
73,
6244,
665,
74,
30,
1386,
2116,
2263,
881,
16735,
267,
446,
9437,
701,
282,
1174,
1625,
12,
402,
314,
1824,
26,
881,
2955,
1174,
6363,
27718,
83,
9514,
28,
84,
19109,
275,
469,
2116,
469,
28,
75,
6244,
601,
1259,
27718,
78,
30,
27718,
77,
30,
1386,
2116,
2263,
881,
16735,
398,
408,
267,
862,
26,
288,
289,
275,
1551,
8,
1501,
9,
267,
871,
5925,
12,
2329,
26,
288,
870,
298,
6049,
1133,
1551,
450,
83,
26,
450,
83,
2,
450,
334,
1501,
12,
2329,
9,
288,
372,
756,
267,
327,
710,
1233,
5084,
28891,
4440,
289,
1159,
6122,
13,
4171,
1,
267,
5874,
275,
378,
398,
327,
15100,
314,
2877,
327,
2613,
2385,
267,
5874,
12,
1004,
275,
5874,
11,
17,
12,
289,
14,
2184,
342,
267,
702,
1004,
508,
3943,
2613,
298,
80,
2268,
2139,
14,
72,
3212,
78,
297,
334,
3469,
12,
1004,
9,
267,
5874,
12,
1004,
275,
5874,
11,
17,
12,
289,
14,
2184,
342,
267,
702,
1004,
508,
3943,
2613,
298,
15239,
14,
72,
3212,
78,
297,
334,
3469,
12,
1004,
9,
398,
327,
6077,
314,
1174,
10269,
267,
5874,
12,
1004,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
julienvey/solum
|
solum/tests/api/v1/test_plan.py
|
1
|
6136
|
# -*- coding: utf-8 -*-
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import json
import mock
import testscenarios
from solum.api.controllers.v1.datamodel import plan as planmodel
from solum.api.controllers.v1 import plan
from solum.common import exception
from solum import objects
from solum.tests import base
from solum.tests import fakes
load_tests = testscenarios.load_tests_apply_scenarios
@mock.patch('pecan.request', new_callable=fakes.FakePecanRequest)
@mock.patch('pecan.response', new_callable=fakes.FakePecanResponse)
@mock.patch('solum.api.handlers.plan_handler.PlanHandler')
class TestPlanController(base.BaseTestCase):
def setUp(self):
super(TestPlanController, self).setUp()
objects.load()
def test_plan_get(self, PlanHandler, resp_mock, request_mock):
hand_get = PlanHandler.return_value.get
hand_get.return_value = fakes.FakePlan()
cont = plan.PlanController('test_id')
cont.get()
hand_get.assert_called_with('test_id')
self.assertEqual(200, resp_mock.status)
def test_plan_get_not_found(self, PlanHandler, resp_mock, request_mock):
hand_get = PlanHandler.return_value.get
hand_get.side_effect = exception.NotFound(name='plan',
plan_id='test_id')
cont = plan.PlanController('test_id')
cont.get()
hand_get.assert_called_with('test_id')
self.assertEqual(404, resp_mock.status)
def test_plan_put_none(self, PlanHandler, resp_mock, request_mock):
request_mock.body = None
request_mock.content_type = 'application/json'
hand_put = PlanHandler.return_value.put
hand_put.return_value = fakes.FakePlan()
plan.PlanController('test_id').put()
self.assertEqual(400, resp_mock.status)
def test_plan_put_not_found(self, PlanHandler, resp_mock, request_mock):
json_update = {'name': 'foo'}
request_mock.body = json.dumps(json_update)
request_mock.content_type = 'application/json'
hand_update = PlanHandler.return_value.update
hand_update.side_effect = exception.NotFound(name='plan',
plan_id='test_id')
plan.PlanController('test_id').put()
hand_update.assert_called_with('test_id', json_update)
self.assertEqual(404, resp_mock.status)
def test_plan_put_ok(self, PlanHandler, resp_mock, request_mock):
json_update = {'name': 'foo'}
request_mock.body = json.dumps(json_update)
request_mock.content_type = 'application/json'
hand_update = PlanHandler.return_value.update
hand_update.return_value = fakes.FakePlan()
plan.PlanController('test_id').put()
hand_update.assert_called_with('test_id', json_update)
self.assertEqual(200, resp_mock.status)
def test_plan_delete_not_found(self, PlanHandler, resp_mock, request_mock):
hand_delete = PlanHandler.return_value.delete
hand_delete.side_effect = exception.NotFound(name='plan',
plan_id='test_id')
obj = plan.PlanController('test_id')
obj.delete()
hand_delete.assert_called_with('test_id')
self.assertEqual(404, resp_mock.status)
def test_plan_delete_ok(self, PlanHandler, resp_mock, request_mock):
hand_delete = PlanHandler.return_value.delete
hand_delete.return_value = None
obj = plan.PlanController('test_id')
obj.delete()
hand_delete.assert_called_with('test_id')
self.assertEqual(204, resp_mock.status)
@mock.patch('pecan.request', new_callable=fakes.FakePecanRequest)
@mock.patch('pecan.response', new_callable=fakes.FakePecanResponse)
@mock.patch('solum.api.handlers.plan_handler.PlanHandler')
class TestPlansController(base.BaseTestCase):
def setUp(self):
super(TestPlansController, self).setUp()
objects.load()
def test_plans_get_all(self, PlanHandler, resp_mock, request_mock):
hand_get = PlanHandler.return_value.get_all
hand_get.return_value = []
resp = plan.PlansController().get_all()
self.assertIsNotNone(resp)
self.assertEqual(200, resp_mock.status)
hand_get.assert_called_with()
def test_plans_post(self, PlanHandler, resp_mock, request_mock):
json_update = {'name': 'foo'}
request_mock.body = json.dumps(json_update)
request_mock.content_type = 'application/json'
hand_create = PlanHandler.return_value.create
hand_create.return_value = fakes.FakePlan()
plan.PlansController().post()
hand_create.assert_called_with(json_update)
self.assertEqual(201, resp_mock.status)
class TestPlanAsDict(base.BaseTestCase):
scenarios = [
('none', dict(data=None)),
('one', dict(data={'name': 'foo'})),
('full', dict(data={'uri': 'http://example.com/v1/plans/x1',
'name': 'Example plan',
'type': 'plan',
'project_id': '1dae5a09ef2b4d8cbf3594b0eb4f6b94',
'user_id': '55f41cf46df74320b9486a35f5d28a11'}))
]
def test_as_dict(self):
objects.load()
if self.data is None:
s = planmodel.Plan()
self.data = {}
else:
s = planmodel.Plan(**self.data)
if 'uri' in self.data:
del self.data['uri']
if 'type' in self.data:
del self.data['type']
self.assertEqual(self.data, s.as_dict(objects.registry.Plan))
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
646,
2022,
199,
646,
1683,
199,
646,
511,
32225,
199,
199,
504,
8597,
453,
14,
1246,
14,
20531,
14,
86,
17,
14,
576,
1238,
492,
8683,
465,
8683,
1238,
199,
504,
8597,
453,
14,
1246,
14,
20531,
14,
86,
17,
492,
8683,
199,
504,
8597,
453,
14,
2330,
492,
1919,
199,
504,
8597,
453,
492,
2251,
199,
504,
8597,
453,
14,
2219,
492,
1300,
199,
504,
8597,
453,
14,
2219,
492,
14063,
421,
199,
912,
63,
2219,
275,
511,
32225,
14,
912,
63,
2219,
63,
4998,
63,
32225,
421,
199,
32,
1805,
14,
2068,
360,
733,
290,
14,
1069,
297,
892,
63,
8296,
29,
27443,
14,
8249,
48,
825,
290,
2017,
9,
199,
32,
1805,
14,
2068,
360,
733,
290,
14,
1310,
297,
892,
63,
8296,
29,
27443,
14,
8249,
48,
825,
290,
2364,
9,
199,
32,
1805,
14,
2068,
360,
7873,
453,
14,
1246,
14,
5586,
14,
5140,
63,
2232,
14,
13375,
2461,
358,
199,
533,
1379,
13375,
7506,
8,
1095,
14,
20760,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
13375,
7506,
12,
291,
680,
5996,
342,
267,
2251,
14,
912,
342,
339,
347,
511,
63,
5140,
63,
362,
8,
277,
12,
32427,
2461,
12,
3085,
63,
1805,
12,
1056,
63,
1805,
304,
267,
4926,
63,
362,
275,
32427,
2461,
14,
1107,
63,
585,
14,
362,
267,
4926,
63,
362,
14,
1107,
63,
585,
275,
14063,
14,
8249,
13375,
342,
267,
13770,
275,
8683,
14,
13375,
7506,
360,
396,
63,
344,
358,
267,
13770,
14,
362,
342,
267,
4926,
63,
362,
14,
479,
63,
3527,
63,
1045,
360,
396,
63,
344,
358,
267,
291,
14,
629,
8,
1840,
12,
3085,
63,
1805,
14,
1205,
9,
339,
347,
511,
63,
5140,
63,
362,
63,
1397,
63,
4214,
8,
277,
12,
32427,
2461,
12,
3085,
63,
1805,
12,
1056,
63,
1805,
304,
267,
4926,
63,
362,
275,
32427,
2461,
14,
1107,
63,
585,
14,
362,
267,
4926,
63,
362,
14,
2441,
63,
5881,
275,
1919,
14,
4667,
8,
354,
534,
5140,
297,
8179,
8683,
63,
344,
534,
396,
63,
344,
358,
267,
13770,
275,
8683,
14,
13375,
7506,
360,
396,
63,
344,
358,
267,
13770,
14,
362,
342,
267,
4926,
63,
362,
14,
479,
63,
3527,
63,
1045,
360,
396,
63,
344,
358,
267,
291,
14,
629,
8,
5188,
12,
3085,
63,
1805,
14,
1205,
9,
339,
347,
511,
63,
5140,
63,
524,
63,
3592,
8,
277,
12,
32427,
2461,
12,
3085,
63,
1805,
12,
1056,
63,
1805,
304,
267,
1056,
63,
1805,
14,
2030,
275,
488,
267,
1056,
63,
1805,
14,
1317,
63,
466,
275,
283,
3578,
15,
1001,
7,
267,
4926,
63,
524,
275,
32427,
2461,
14,
1107,
63,
585,
14,
524,
267,
4926,
63,
524,
14,
1107,
63,
585,
275,
14063,
14,
8249,
13375,
342,
267,
8683,
14,
13375,
7506,
360,
396,
63,
344,
1959,
524,
342,
267,
291,
14,
629,
8,
5303,
12,
3085,
63,
1805,
14,
1205,
9,
339,
347,
511,
63,
5140,
63,
524,
63,
1397,
63,
4214,
8,
277,
12,
32427,
2461,
12,
3085,
63,
1805,
12,
1056,
63,
1805,
304,
267,
2022,
63,
873,
275,
791,
354,
356,
283,
1421,
936,
267,
1056,
63,
1805,
14,
2030,
275,
2022,
14,
4180,
8,
1001,
63,
873,
9,
267,
1056,
63,
1805,
14,
1317,
63,
466,
275,
283,
3578,
15,
1001,
7,
267,
4926,
63,
873,
275,
32427,
2461,
14,
1107,
63,
585,
14,
873,
267,
4926,
63,
873,
14,
2441,
63,
5881,
275,
1919,
14,
4667,
8,
354,
534,
5140,
297,
9349,
8683,
63,
344,
534,
396,
63,
344,
358,
267,
8683,
14,
13375,
7506,
360,
396,
63,
344,
1959,
524,
342,
267,
4926,
63,
873,
14,
479,
63,
3527,
63,
1045,
360,
396,
63,
344,
297,
2022,
63,
873,
9,
267,
291,
14,
629,
8,
5188,
12,
3085,
63,
1805,
14,
1205,
9,
339,
347,
511,
63,
5140,
63,
524,
63,
745,
8,
277,
12,
32427,
2461,
12,
3085,
63,
1805,
12,
1056,
63,
1805,
304,
267,
2022,
63,
873,
275,
791,
354,
356,
283,
1421,
936,
267,
1056,
63,
1805,
14,
2030,
275,
2022,
14,
4180,
8,
1001,
63,
873,
9,
267,
1056,
63,
1805,
14,
1317,
63,
466,
275,
283,
3578,
15,
1001,
7,
267,
4926,
63,
873,
275,
32427,
2461,
14,
1107,
63,
585,
14,
873,
267,
4926,
63,
873,
14,
1107,
63,
585,
275,
14063,
14,
8249,
13375,
342,
267,
8683,
14,
13375,
7506,
360,
396,
63,
344,
1959,
524,
342,
267,
4926,
63,
873,
14,
479,
63,
3527,
63,
1045,
360,
396,
63,
344,
297,
2022,
63,
873,
9,
267,
291,
14,
629,
8,
1840,
12,
3085,
63,
1805,
14,
1205,
9,
339,
347,
511,
63,
5140,
63,
1807,
63,
1397,
63,
4214,
8,
277,
12,
32427,
2461,
12,
3085,
63,
1805,
12,
1056,
63,
1805,
304,
267,
4926,
63,
1807,
275,
32427,
2461,
14,
1107,
63,
585,
14,
1807,
267,
4926,
63,
1807,
14,
2441,
63,
5881,
275,
1919,
14,
4667,
8,
354,
534,
5140,
297,
9349,
8683,
63,
344,
534,
396,
63,
344,
358,
267,
1559,
275,
8683,
14,
13375,
7506,
360,
396,
63,
344,
358,
267,
1559,
14,
1807,
342,
267,
4926,
63,
1807,
14,
479,
63,
3527,
63,
1045,
360,
396,
63,
344,
358,
267,
291,
14,
629,
8,
5188,
12,
3085,
63,
1805,
14,
1205,
9,
339,
347,
511,
63,
5140,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
646,
2022,
199,
646,
1683,
199,
646,
511,
32225,
199,
199,
504,
8597,
453,
14,
1246,
14,
20531,
14,
86,
17,
14,
576,
1238,
492,
8683,
465,
8683,
1238,
199,
504,
8597,
453,
14,
1246,
14,
20531,
14,
86,
17,
492,
8683,
199,
504,
8597,
453,
14,
2330,
492,
1919,
199,
504,
8597,
453,
492,
2251,
199,
504,
8597,
453,
14,
2219,
492,
1300,
199,
504,
8597,
453,
14,
2219,
492,
14063,
421,
199,
912,
63,
2219,
275,
511,
32225,
14,
912,
63,
2219,
63,
4998,
63,
32225,
421,
199,
32,
1805,
14,
2068,
360,
733,
290,
14,
1069,
297,
892,
63,
8296,
29,
27443,
14,
8249,
48,
825,
290,
2017,
9,
199,
32,
1805,
14,
2068,
360,
733,
290,
14,
1310,
297,
892,
63,
8296,
29,
27443,
14,
8249,
48,
825,
290,
2364,
9,
199,
32,
1805,
14,
2068,
360,
7873,
453,
14,
1246,
14,
5586,
14,
5140,
63,
2232,
14,
13375,
2461,
358,
199,
533,
1379,
13375,
7506,
8,
1095,
14,
20760,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
13375,
7506,
12,
291,
680,
5996,
342,
267,
2251,
14,
912,
342,
339,
347,
511,
63,
5140,
63,
362,
8,
277,
12,
32427,
2461,
12,
3085,
63,
1805,
12,
1056,
63,
1805,
304,
267,
4926,
63,
362,
275,
32427,
2461,
14,
1107,
63,
585,
14,
362,
267,
4926,
63,
362,
14,
1107,
63,
585,
275,
14063,
14,
8249,
13375,
342,
267,
13770,
275,
8683,
14,
13375,
7506,
360,
396,
63,
344,
358,
267,
13770,
14,
362,
342,
267,
4926,
63,
362,
14,
479,
63,
3527,
63,
1045,
360,
396,
63,
344,
358,
267,
291,
14,
629,
8,
1840,
12,
3085,
63,
1805,
14,
1205,
9,
339,
347,
511,
63,
5140,
63,
362,
63,
1397,
63,
4214,
8,
277,
12,
32427,
2461,
12,
3085,
63,
1805,
12,
1056,
63,
1805,
304,
267,
4926,
63,
362,
275,
32427,
2461,
14,
1107,
63,
585,
14,
362,
267,
4926,
63,
362,
14,
2441,
63,
5881,
275,
1919,
14,
4667,
8,
354,
534,
5140,
297,
8179,
8683,
63,
344,
534,
396,
63,
344,
358,
267,
13770,
275,
8683,
14,
13375,
7506,
360,
396,
63,
344,
358,
267,
13770,
14,
362,
342,
267,
4926,
63,
362,
14,
479,
63,
3527,
63,
1045,
360,
396,
63,
344,
358,
267,
291,
14,
629,
8,
5188,
12,
3085,
63,
1805,
14,
1205,
9,
339,
347,
511,
63,
5140,
63,
524,
63,
3592,
8,
277,
12,
32427,
2461,
12,
3085,
63,
1805,
12,
1056,
63,
1805,
304,
267,
1056,
63,
1805,
14,
2030,
275,
488,
267,
1056,
63,
1805,
14,
1317,
63,
466,
275,
283,
3578,
15,
1001,
7,
267,
4926,
63,
524,
275,
32427,
2461,
14,
1107,
63,
585,
14,
524,
267,
4926,
63,
524,
14,
1107,
63,
585,
275,
14063,
14,
8249,
13375,
342,
267,
8683,
14,
13375,
7506,
360,
396,
63,
344,
1959,
524,
342,
267,
291,
14,
629,
8,
5303,
12,
3085,
63,
1805,
14,
1205,
9,
339,
347,
511,
63,
5140,
63,
524,
63,
1397,
63,
4214,
8,
277,
12,
32427,
2461,
12,
3085,
63,
1805,
12,
1056,
63,
1805,
304,
267,
2022,
63,
873,
275,
791,
354,
356,
283,
1421,
936,
267,
1056,
63,
1805,
14,
2030,
275,
2022,
14,
4180,
8,
1001,
63,
873,
9,
267,
1056,
63,
1805,
14,
1317,
63,
466,
275,
283,
3578,
15,
1001,
7,
267,
4926,
63,
873,
275,
32427,
2461,
14,
1107,
63,
585,
14,
873,
267,
4926,
63,
873,
14,
2441,
63,
5881,
275,
1919,
14,
4667,
8,
354,
534,
5140,
297,
9349,
8683,
63,
344,
534,
396,
63,
344,
358,
267,
8683,
14,
13375,
7506,
360,
396,
63,
344,
1959,
524,
342,
267,
4926,
63,
873,
14,
479,
63,
3527,
63,
1045,
360,
396,
63,
344,
297,
2022,
63,
873,
9,
267,
291,
14,
629,
8,
5188,
12,
3085,
63,
1805,
14,
1205,
9,
339,
347,
511,
63,
5140,
63,
524,
63,
745,
8,
277,
12,
32427,
2461,
12,
3085,
63,
1805,
12,
1056,
63,
1805,
304,
267,
2022,
63,
873,
275,
791,
354,
356,
283,
1421,
936,
267,
1056,
63,
1805,
14,
2030,
275,
2022,
14,
4180,
8,
1001,
63,
873,
9,
267,
1056,
63,
1805,
14,
1317,
63,
466,
275,
283,
3578,
15,
1001,
7,
267,
4926,
63,
873,
275,
32427,
2461,
14,
1107,
63,
585,
14,
873,
267,
4926,
63,
873,
14,
1107,
63,
585,
275,
14063,
14,
8249,
13375,
342,
267,
8683,
14,
13375,
7506,
360,
396,
63,
344,
1959,
524,
342,
267,
4926,
63,
873,
14,
479,
63,
3527,
63,
1045,
360,
396,
63,
344,
297,
2022,
63,
873,
9,
267,
291,
14,
629,
8,
1840,
12,
3085,
63,
1805,
14,
1205,
9,
339,
347,
511,
63,
5140,
63,
1807,
63,
1397,
63,
4214,
8,
277,
12,
32427,
2461,
12,
3085,
63,
1805,
12,
1056,
63,
1805,
304,
267,
4926,
63,
1807,
275,
32427,
2461,
14,
1107,
63,
585,
14,
1807,
267,
4926,
63,
1807,
14,
2441,
63,
5881,
275,
1919,
14,
4667,
8,
354,
534,
5140,
297,
9349,
8683,
63,
344,
534,
396,
63,
344,
358,
267,
1559,
275,
8683,
14,
13375,
7506,
360,
396,
63,
344,
358,
267,
1559,
14,
1807,
342,
267,
4926,
63,
1807,
14,
479,
63,
3527,
63,
1045,
360,
396,
63,
344,
358,
267,
291,
14,
629,
8,
5188,
12,
3085,
63,
1805,
14,
1205,
9,
339,
347,
511,
63,
5140,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
gmimano/commcaretest
|
corehq/apps/domain/utils.py
|
1
|
1991
|
import json
import re
from couchdbkit import ResourceNotFound
from django.conf import settings
from dimagi.utils.couch.cache import cache_core
from corehq.apps.domain.models import Domain
from dimagi.utils.couch.database import get_db
from django.core.cache import cache
DOMAIN_MODULE_KEY = 'DOMAIN_MODULE_CONFIG'
ADM_DOMAIN_KEY = 'ADM_ENABLED_DOMAINS'
new_domain_re = r"(?:[a-z0-9]+\-)*[a-z0-9]+" # lowercase letters, numbers, and '-' (at most one between "words")
new_org_re = r"(?:[a-z0-9]+\-)*[a-zA-Z0-9]+" # lowercase and uppercase letters, numbers, and '-' (at most one between "words")
grandfathered_domain_re = r"[a-z0-9\-\.:]+"
legacy_domain_re = r"[\w\.:-]+"
commcare_public_domain_url = '/a/public/'
website_re = '(http(s?)\:\/\/|~/|/)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?/?(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?'
def normalize_domain_name(domain):
normalized = domain.replace('_', '-').lower()
if settings.DEBUG:
assert(re.match('^%s$' % grandfathered_domain_re, normalized))
return normalized
def get_domained_url(domain, path):
return '/a/%s/%s' % (domain, path)
def get_domain_from_url(path):
try:
domain, = re.compile(r'^/a/(?P<domain>%s)/' % legacy_domain_re).search(path).groups()
except Exception:
domain = None
return domain
def get_domain_module_map():
hardcoded = getattr(settings, 'DOMAIN_MODULE_MAP', {})
try:
dynamic = cache_core.cached_open_doc(get_db(), 'DOMAIN_MODULE_CONFIG').get('module_map', {})
except ResourceNotFound:
dynamic = {}
hardcoded.update(dynamic)
return hardcoded
def get_adm_enabled_domains():
try:
domains = cache_core.cached_open_doc(get_db(), 'ADM_ENABLED_DOMAINS').get('domains', {})
except ResourceNotFound:
domains = []
return domains
def domain_restricts_superusers(domain):
domain = Domain.get_by_name(domain)
if not domain:
return False
return domain.restrict_superusers
|
bsd-3-clause
|
[
646,
2022,
199,
646,
295,
199,
504,
28877,
697,
6065,
492,
7337,
4667,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
487,
5615,
73,
14,
1208,
14,
331,
2133,
14,
1637,
492,
2581,
63,
1018,
199,
504,
6170,
21550,
14,
5181,
14,
2261,
14,
992,
492,
14061,
199,
504,
487,
5615,
73,
14,
1208,
14,
331,
2133,
14,
4659,
492,
664,
63,
697,
199,
504,
1639,
14,
1018,
14,
1637,
492,
2581,
199,
199,
7378,
63,
10001,
63,
3078,
275,
283,
7378,
63,
10001,
63,
5569,
7,
199,
1554,
45,
63,
7378,
63,
3078,
275,
283,
1554,
45,
63,
15704,
63,
7378,
51,
7,
199,
199,
1222,
63,
2261,
63,
264,
275,
519,
2,
25060,
65,
13,
90,
16,
13,
25,
2807,
16185,
3342,
59,
65,
13,
90,
16,
13,
25,
2807,
2,
327,
12141,
14435,
12,
5579,
12,
436,
10791,
334,
292,
4750,
1373,
3382,
298,
3148,
531,
199,
1222,
63,
1308,
63,
264,
275,
519,
2,
25060,
65,
13,
90,
16,
13,
25,
2807,
16185,
3342,
59,
65,
13,
6353,
13,
58,
16,
13,
25,
2807,
2,
327,
12141,
436,
22681,
14435,
12,
5579,
12,
436,
10791,
334,
292,
4750,
1373,
3382,
298,
3148,
531,
199,
22655,
667,
31051,
63,
2261,
63,
264,
275,
519,
22774,
65,
13,
90,
16,
13,
25,
60,
2696,
16781,
2807,
2,
199,
10000,
63,
2261,
63,
264,
275,
519,
29354,
87,
4537,
6809,
2807,
2,
199,
1404,
28654,
63,
3455,
63,
2261,
63,
633,
275,
1994,
65,
15,
3455,
4805,
199,
7360,
63,
264,
275,
8189,
1014,
8,
83,
31,
2862,
3427,
6307,
15,
92,
94,
15,
92,
15,
5547,
779,
65,
13,
6353,
13,
58,
8194,
17,
93,
16510,
87,
16185,
2807,
4537,
6393,
16510,
87,
8194,
18,
12,
21,
12466,
8,
26,
7023,
68,
8194,
17,
12,
21,
1552,
31,
10197,
2961,
87,
11,
4537,
7023,
87,
8194,
19,
12,
20,
1552,
31,
1332,
60,
8995,
87,
11,
9529,
87,
19544,
24168,
60,
87,
11,
9529,
87,
11,
3342,
5547,
7,
199,
199,
318,
7666,
63,
2261,
63,
354,
8,
2261,
304,
272,
9657,
275,
2881,
14,
1814,
20928,
2475,
1959,
2325,
342,
272,
340,
2202,
14,
5287,
26,
267,
702,
8,
264,
14,
1431,
9097,
5,
83,
12913,
450,
26881,
667,
31051,
63,
2261,
63,
264,
12,
9657,
430,
272,
372,
9657,
199,
199,
318,
664,
63,
2261,
379,
63,
633,
8,
2261,
12,
931,
304,
272,
372,
1994,
65,
3149,
83,
3149,
83,
7,
450,
334,
2261,
12,
931,
9,
199,
199,
318,
664,
63,
2261,
63,
504,
63,
633,
8,
515,
304,
272,
862,
26,
267,
2881,
12,
275,
295,
14,
2014,
8,
82,
4289,
15,
65,
9448,
48,
28,
2261,
6598,
83,
2447,
7,
450,
12139,
63,
2261,
63,
264,
680,
1733,
8,
515,
680,
2634,
342,
272,
871,
2186,
26,
267,
2881,
275,
488,
272,
372,
2881,
421,
199,
318,
664,
63,
2261,
63,
578,
63,
1130,
837,
272,
7508,
15282,
275,
2519,
8,
1751,
12,
283,
7378,
63,
10001,
63,
5443,
297,
5009,
272,
862,
26,
267,
8336,
275,
2581,
63,
1018,
14,
5245,
63,
1490,
63,
1301,
8,
362,
63,
697,
1062,
283,
7378,
63,
10001,
63,
5569,
1959,
362,
360,
578,
63,
1130,
297,
5009,
272,
871,
7337,
4667,
26,
267,
8336,
275,
1052,
339,
7508,
15282,
14,
873,
8,
7764,
9,
272,
372,
7508,
15282,
421,
199,
318,
664,
63,
14464,
63,
3827,
63,
9756,
837,
272,
862,
26,
267,
14006,
275,
2581,
63,
1018,
14,
5245,
63,
1490,
63,
1301,
8,
362,
63,
697,
1062,
283,
1554,
45,
63,
15704,
63,
7378,
51,
1959,
362,
360,
9756,
297,
5009,
272,
871,
7337,
4667,
26,
267,
14006,
275,
942,
272,
372,
14006,
421,
199,
318,
2881,
63,
12099,
3021,
63,
4792,
3707,
8,
2261,
304,
272,
2881,
275,
14061,
14,
362,
63,
991,
63,
354,
8,
2261,
9,
272,
340,
440,
2881,
26,
267,
372,
756,
272,
372,
2881,
14,
22188,
63,
4792,
3707,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2022,
199,
646,
295,
199,
504,
28877,
697,
6065,
492,
7337,
4667,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
487,
5615,
73,
14,
1208,
14,
331,
2133,
14,
1637,
492,
2581,
63,
1018,
199,
504,
6170,
21550,
14,
5181,
14,
2261,
14,
992,
492,
14061,
199,
504,
487,
5615,
73,
14,
1208,
14,
331,
2133,
14,
4659,
492,
664,
63,
697,
199,
504,
1639,
14,
1018,
14,
1637,
492,
2581,
199,
199,
7378,
63,
10001,
63,
3078,
275,
283,
7378,
63,
10001,
63,
5569,
7,
199,
1554,
45,
63,
7378,
63,
3078,
275,
283,
1554,
45,
63,
15704,
63,
7378,
51,
7,
199,
199,
1222,
63,
2261,
63,
264,
275,
519,
2,
25060,
65,
13,
90,
16,
13,
25,
2807,
16185,
3342,
59,
65,
13,
90,
16,
13,
25,
2807,
2,
327,
12141,
14435,
12,
5579,
12,
436,
10791,
334,
292,
4750,
1373,
3382,
298,
3148,
531,
199,
1222,
63,
1308,
63,
264,
275,
519,
2,
25060,
65,
13,
90,
16,
13,
25,
2807,
16185,
3342,
59,
65,
13,
6353,
13,
58,
16,
13,
25,
2807,
2,
327,
12141,
436,
22681,
14435,
12,
5579,
12,
436,
10791,
334,
292,
4750,
1373,
3382,
298,
3148,
531,
199,
22655,
667,
31051,
63,
2261,
63,
264,
275,
519,
22774,
65,
13,
90,
16,
13,
25,
60,
2696,
16781,
2807,
2,
199,
10000,
63,
2261,
63,
264,
275,
519,
29354,
87,
4537,
6809,
2807,
2,
199,
1404,
28654,
63,
3455,
63,
2261,
63,
633,
275,
1994,
65,
15,
3455,
4805,
199,
7360,
63,
264,
275,
8189,
1014,
8,
83,
31,
2862,
3427,
6307,
15,
92,
94,
15,
92,
15,
5547,
779,
65,
13,
6353,
13,
58,
8194,
17,
93,
16510,
87,
16185,
2807,
4537,
6393,
16510,
87,
8194,
18,
12,
21,
12466,
8,
26,
7023,
68,
8194,
17,
12,
21,
1552,
31,
10197,
2961,
87,
11,
4537,
7023,
87,
8194,
19,
12,
20,
1552,
31,
1332,
60,
8995,
87,
11,
9529,
87,
19544,
24168,
60,
87,
11,
9529,
87,
11,
3342,
5547,
7,
199,
199,
318,
7666,
63,
2261,
63,
354,
8,
2261,
304,
272,
9657,
275,
2881,
14,
1814,
20928,
2475,
1959,
2325,
342,
272,
340,
2202,
14,
5287,
26,
267,
702,
8,
264,
14,
1431,
9097,
5,
83,
12913,
450,
26881,
667,
31051,
63,
2261,
63,
264,
12,
9657,
430,
272,
372,
9657,
199,
199,
318,
664,
63,
2261,
379,
63,
633,
8,
2261,
12,
931,
304,
272,
372,
1994,
65,
3149,
83,
3149,
83,
7,
450,
334,
2261,
12,
931,
9,
199,
199,
318,
664,
63,
2261,
63,
504,
63,
633,
8,
515,
304,
272,
862,
26,
267,
2881,
12,
275,
295,
14,
2014,
8,
82,
4289,
15,
65,
9448,
48,
28,
2261,
6598,
83,
2447,
7,
450,
12139,
63,
2261,
63,
264,
680,
1733,
8,
515,
680,
2634,
342,
272,
871,
2186,
26,
267,
2881,
275,
488,
272,
372,
2881,
421,
199,
318,
664,
63,
2261,
63,
578,
63,
1130,
837,
272,
7508,
15282,
275,
2519,
8,
1751,
12,
283,
7378,
63,
10001,
63,
5443,
297,
5009,
272,
862,
26,
267,
8336,
275,
2581,
63,
1018,
14,
5245,
63,
1490,
63,
1301,
8,
362,
63,
697,
1062,
283,
7378,
63,
10001,
63,
5569,
1959,
362,
360,
578,
63,
1130,
297,
5009,
272,
871,
7337,
4667,
26,
267,
8336,
275,
1052,
339,
7508,
15282,
14,
873,
8,
7764,
9,
272,
372,
7508,
15282,
421,
199,
318,
664,
63,
14464,
63,
3827,
63,
9756,
837,
272,
862,
26,
267,
14006,
275,
2581,
63,
1018,
14,
5245,
63,
1490,
63,
1301,
8,
362,
63,
697,
1062,
283,
1554,
45,
63,
15704,
63,
7378,
51,
1959,
362,
360,
9756,
297,
5009,
272,
871,
7337,
4667,
26,
267,
14006,
275,
942,
272,
372,
14006,
421,
199,
318,
2881,
63,
12099,
3021,
63,
4792,
3707,
8,
2261,
304,
272,
2881,
275,
14061,
14,
362,
63,
991,
63,
354,
8,
2261,
9,
272,
340,
440,
2881,
26,
267,
372,
756,
272,
372,
2881,
14,
22188,
63,
4792,
3707,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
janusnic/youtube-dl-GUI
|
youtube_dl/extractor/daum.py
|
118
|
2755
|
# encoding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..compat import (
compat_urllib_parse,
)
class DaumIE(InfoExtractor):
_VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/(?:v/|.*?clipid=)(?P<id>[^?#&]+)'
IE_NAME = 'daum.net'
_TESTS = [{
'url': 'http://tvpot.daum.net/clip/ClipView.do?clipid=52554690',
'info_dict': {
'id': '52554690',
'ext': 'mp4',
'title': 'DOTA 2GETHER 시즌2 6회 - 2부',
'description': 'DOTA 2GETHER 시즌2 6회 - 2부',
'upload_date': '20130831',
'duration': 3868,
},
}, {
'url': 'http://tvpot.daum.net/v/vab4dyeDBysyBssyukBUjBz',
'only_matching': True,
}, {
'url': 'http://tvpot.daum.net/v/07dXWRka62Y%24',
'only_matching': True,
}]
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
canonical_url = 'http://tvpot.daum.net/v/%s' % video_id
webpage = self._download_webpage(canonical_url, video_id)
full_id = self._search_regex(
r'src=["\']http://videofarm\.daum\.net/controller/video/viewer/Video\.html\?.*?vid=(.+?)[&"\']',
webpage, 'full id')
query = compat_urllib_parse.urlencode({'vid': full_id})
info = self._download_xml(
'http://tvpot.daum.net/clip/ClipInfoXml.do?' + query, video_id,
'Downloading video info')
urls = self._download_xml(
'http://videofarm.daum.net/controller/api/open/v1_2/MovieData.apixml?' + query,
video_id, 'Downloading video formats info')
formats = []
for format_el in urls.findall('result/output_list/output_list'):
profile = format_el.attrib['profile']
format_query = compat_urllib_parse.urlencode({
'vid': full_id,
'profile': profile,
})
url_doc = self._download_xml(
'http://videofarm.daum.net/controller/api/open/v1_2/MovieLocation.apixml?' + format_query,
video_id, note='Downloading video data for %s format' % profile)
format_url = url_doc.find('result/url').text
formats.append({
'url': format_url,
'format_id': profile,
})
return {
'id': video_id,
'title': info.find('TITLE').text,
'formats': formats,
'thumbnail': self._og_search_thumbnail(webpage),
'description': info.find('CONTENTS').text,
'duration': int(info.find('DURATION').text),
'upload_date': info.find('REGDTTM').text[:8],
}
|
mit
|
[
3,
2644,
26,
2774,
13,
24,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
4078,
63,
1122,
12,
199,
9,
421,
199,
533,
577,
65,
453,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
77,
20316,
6993,
14173,
4537,
983,
453,
4537,
846,
32576,
86,
15,
92,
6697,
2764,
3150,
29,
18168,
48,
28,
344,
13489,
31,
3,
6,
29716,
272,
15292,
63,
2339,
275,
283,
983,
453,
14,
846,
7,
339,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
7548,
15,
17492,
2768,
14,
1117,
31,
2764,
3150,
29,
24334,
1477,
24495,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
24334,
1477,
24495,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
13203,
33,
499,
2970,
3452,
10148,
234,
251,
169,
100,
235,
18,
1227,
170,
249,
235,
446,
499,
168,
115,
223,
297,
288,
283,
1802,
356,
283,
13203,
33,
499,
2970,
3452,
10148,
234,
251,
169,
100,
235,
18,
1227,
170,
249,
235,
446,
499,
168,
115,
223,
297,
288,
283,
5064,
63,
602,
356,
283,
1797,
12127,
2192,
297,
288,
283,
5553,
356,
650,
15430,
12,
267,
1660,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
86,
15,
86,
371,
20,
68,
8048,
2846,
588,
89,
34,
385,
89,
3210,
2910,
74,
34,
90,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
86,
15,
1780,
31282,
6524,
7351,
2789,
57,
5,
1194,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
14877,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
3991,
63,
344,
275,
14208,
14,
923,
360,
344,
358,
267,
11358,
63,
633,
275,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
86,
3149,
83,
7,
450,
3991,
63,
344,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
13109,
63,
633,
12,
3991,
63,
344,
9,
267,
2615,
63,
344,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
1159,
1195,
6270,
26889,
1014,
921,
5624,
1618,
5362,
4537,
983,
453,
4537,
846,
15,
5538,
15,
3722,
15,
16645,
15,
9166,
4537,
1360,
29635,
6697,
5017,
2687,
11198,
2788,
6,
3212,
418,
297,
288,
9248,
12,
283,
2861,
1305,
358,
267,
1827,
275,
8434,
63,
4078,
63,
1122,
14,
10738,
3252,
5017,
356,
2615,
63,
344,
1552,
267,
2256,
275,
291,
423,
4249,
63,
1652,
8,
288,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
7548,
15,
17492,
2354,
8672,
14,
1117,
14069,
435,
1827,
12,
3991,
63,
344,
12,
288,
283,
18085,
3991,
2256,
358,
267,
8187,
275,
291,
423,
4249,
63,
1652,
8,
288,
283,
1014,
921,
5624,
1618,
5362,
14,
983,
453,
14,
846,
15,
5538,
15,
1246,
15,
1490,
15,
86,
17,
63,
18,
15,
19088,
1451,
14,
439,
1148,
757,
14069,
435,
1827,
12,
288,
3991,
63,
344,
12,
283,
18085,
3991,
6752,
2256,
358,
398,
6752,
275,
942,
267,
367,
1475,
63,
352,
315,
8187,
14,
6452,
360,
1099,
15,
1199,
63,
513,
15,
1199,
63,
513,
735,
288,
4690,
275,
1475,
63,
352,
14,
6640,
459,
2913,
418,
288,
1475,
63,
1131,
275,
8434,
63,
4078,
63,
1122,
14,
10738,
2561,
355,
283,
5017,
356,
2615,
63,
344,
12,
355,
283,
2913,
356,
4690,
12,
288,
3828,
288,
1166,
63,
1301,
275,
291,
423,
4249,
63,
1652,
8,
355,
283,
1014,
921,
5624,
1618,
5362,
14,
983,
453,
14,
846,
15,
5538,
15,
1246,
15,
1490,
15,
86,
17,
63,
18,
15,
19088,
6592,
14,
439,
1148,
757,
14069,
435,
1475,
63,
1131,
12,
355,
3991,
63,
344,
12,
5317,
534,
18085,
3991,
666,
367,
450,
83,
1475,
7,
450,
4690,
9,
288,
1475,
63,
633,
275,
1166,
63,
1301,
14,
1623,
360,
1099,
15,
633,
1959,
505,
288,
6752,
14,
740,
2561,
355,
283,
633,
356,
1475,
63,
633,
12,
355,
283,
908,
63,
344,
356,
4690,
12,
288,
3828,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
2256,
14,
1623,
360,
19091,
1959,
505,
12,
288,
283,
6321,
356,
6752,
12,
288,
283,
8311,
356,
291,
423,
974,
63,
1733,
63,
8311,
8,
12022,
395,
288,
283,
1802,
356,
2256,
14,
1623,
360,
9663,
51,
1959,
505,
12,
288,
283,
5553,
356,
1109,
8,
815,
14,
1623,
360,
36,
15301,
1959,
505,
395,
288,
283,
5064,
63,
602,
356,
2256,
14,
1623,
360,
5616,
36,
1481,
45,
1959,
505,
1491,
24,
467,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2644,
26,
2774,
13,
24,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
4078,
63,
1122,
12,
199,
9,
421,
199,
533,
577,
65,
453,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
77,
20316,
6993,
14173,
4537,
983,
453,
4537,
846,
32576,
86,
15,
92,
6697,
2764,
3150,
29,
18168,
48,
28,
344,
13489,
31,
3,
6,
29716,
272,
15292,
63,
2339,
275,
283,
983,
453,
14,
846,
7,
339,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
7548,
15,
17492,
2768,
14,
1117,
31,
2764,
3150,
29,
24334,
1477,
24495,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
24334,
1477,
24495,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
13203,
33,
499,
2970,
3452,
10148,
234,
251,
169,
100,
235,
18,
1227,
170,
249,
235,
446,
499,
168,
115,
223,
297,
288,
283,
1802,
356,
283,
13203,
33,
499,
2970,
3452,
10148,
234,
251,
169,
100,
235,
18,
1227,
170,
249,
235,
446,
499,
168,
115,
223,
297,
288,
283,
5064,
63,
602,
356,
283,
1797,
12127,
2192,
297,
288,
283,
5553,
356,
650,
15430,
12,
267,
1660,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
86,
15,
86,
371,
20,
68,
8048,
2846,
588,
89,
34,
385,
89,
3210,
2910,
74,
34,
90,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
86,
15,
1780,
31282,
6524,
7351,
2789,
57,
5,
1194,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
14877,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
3991,
63,
344,
275,
14208,
14,
923,
360,
344,
358,
267,
11358,
63,
633,
275,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
86,
3149,
83,
7,
450,
3991,
63,
344,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
13109,
63,
633,
12,
3991,
63,
344,
9,
267,
2615,
63,
344,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
1159,
1195,
6270,
26889,
1014,
921,
5624,
1618,
5362,
4537,
983,
453,
4537,
846,
15,
5538,
15,
3722,
15,
16645,
15,
9166,
4537,
1360,
29635,
6697,
5017,
2687,
11198,
2788,
6,
3212,
418,
297,
288,
9248,
12,
283,
2861,
1305,
358,
267,
1827,
275,
8434,
63,
4078,
63,
1122,
14,
10738,
3252,
5017,
356,
2615,
63,
344,
1552,
267,
2256,
275,
291,
423,
4249,
63,
1652,
8,
288,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
7548,
15,
17492,
2354,
8672,
14,
1117,
14069,
435,
1827,
12,
3991,
63,
344,
12,
288,
283,
18085,
3991,
2256,
358,
267,
8187,
275,
291,
423,
4249,
63,
1652,
8,
288,
283,
1014,
921,
5624,
1618,
5362,
14,
983,
453,
14,
846,
15,
5538,
15,
1246,
15,
1490,
15,
86,
17,
63,
18,
15,
19088,
1451,
14,
439,
1148,
757,
14069,
435,
1827,
12,
288,
3991,
63,
344,
12,
283,
18085,
3991,
6752,
2256,
358,
398,
6752,
275,
942,
267,
367,
1475,
63,
352,
315,
8187,
14,
6452,
360,
1099,
15,
1199,
63,
513,
15,
1199,
63,
513,
735,
288,
4690,
275,
1475,
63,
352,
14,
6640,
459,
2913,
418,
288,
1475,
63,
1131,
275,
8434,
63,
4078,
63,
1122,
14,
10738,
2561,
355,
283,
5017,
356,
2615,
63,
344,
12,
355,
283,
2913,
356,
4690,
12,
288,
3828,
288,
1166,
63,
1301,
275,
291,
423,
4249,
63,
1652,
8,
355,
283,
1014,
921,
5624,
1618,
5362,
14,
983,
453,
14,
846,
15,
5538,
15,
1246,
15,
1490,
15,
86,
17,
63,
18,
15,
19088,
6592,
14,
439,
1148,
757,
14069,
435,
1475,
63,
1131,
12,
355,
3991,
63,
344,
12,
5317,
534,
18085,
3991,
666,
367,
450,
83,
1475,
7,
450,
4690,
9,
288,
1475,
63,
633,
275,
1166,
63,
1301,
14,
1623,
360,
1099,
15,
633,
1959,
505,
288,
6752,
14,
740,
2561,
355,
283,
633,
356,
1475,
63,
633,
12,
355,
283,
908,
63,
344,
356,
4690,
12,
288,
3828,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
2256,
14,
1623,
360,
19091,
1959,
505,
12,
288,
283,
6321,
356,
6752,
12,
288,
283,
8311,
356,
291,
423,
974,
63,
1733,
63,
8311,
8,
12022,
395,
288,
283,
1802,
356,
2256,
14,
1623,
360,
9663,
51,
1959,
505,
12,
288,
283,
5553,
356,
1109,
8,
815,
14,
1623,
360,
36,
15301,
1959,
505,
395,
288,
283,
5064,
63,
602,
356,
2256,
14,
1623,
360,
5616,
36,
1481,
45,
1959,
505,
1491,
24,
467,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
bigfatpaulyj/py-airfoil
|
scons-local-2.2.0/SCons/Variables/EnumVariable.py
|
14
|
3872
|
"""engine.SCons.Variables.EnumVariable
This file defines the option type for SCons allowing only specified
input-values.
Usage example:
opts = Variables()
opts.Add(EnumVariable('debug', 'debug output and symbols', 'no',
allowed_values=('yes', 'no', 'full'),
map={}, ignorecase=2))
...
if env['debug'] == 'full':
...
"""
#
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
__revision__ = "src/engine/SCons/Variables/EnumVariable.py issue-2856:2676:d23b7a2f45e8 2012/08/05 15:38:28 garyo"
__all__ = ['EnumVariable',]
import SCons.Errors
def _validator(key, val, env, vals):
if not val in vals:
raise SCons.Errors.UserError(
'Invalid value for option %s: %s. Valid values are: %s' % (key, val, vals))
def EnumVariable(key, help, default, allowed_values, map={}, ignorecase=0):
"""
The input parameters describe a option with only certain values
allowed. They are returned with an appropriate converter and
validator appended. The result is usable for input to
Variables.Add().
'key' and 'default' are the values to be passed on to Variables.Add().
'help' will be appended by the allowed values automatically
'allowed_values' is a list of strings, which are allowed as values
for this option.
The 'map'-dictionary may be used for converting the input value
into canonical values (eg. for aliases).
'ignorecase' defines the behaviour of the validator:
If ignorecase == 0, the validator/converter are case-sensitive.
If ignorecase == 1, the validator/converter are case-insensitive.
If ignorecase == 2, the validator/converter is case-insensitive and
the converted value will always be lower-case.
The 'validator' tests whether the value is in the list of allowed
values. The 'converter' converts input values according to the
given 'map'-dictionary (unmapped input values are returned
unchanged).
"""
help = '%s (%s)' % (help, '|'.join(allowed_values))
# define validator
if ignorecase >= 1:
validator = lambda key, val, env: \
_validator(key, val.lower(), env, allowed_values)
else:
validator = lambda key, val, env: \
_validator(key, val, env, allowed_values)
# define converter
if ignorecase == 2:
converter = lambda val: map.get(val.lower(), val).lower()
elif ignorecase == 1:
converter = lambda val: map.get(val.lower(), val)
else:
converter = lambda val: map.get(val, val)
return (key, help, default, validator, converter)
# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
|
gpl-3.0
|
[
624,
3908,
14,
18521,
14,
11458,
14,
5081,
2773,
199,
199,
2765,
570,
7890,
314,
945,
730,
367,
8218,
17266,
1454,
2013,
199,
1210,
13,
1459,
14,
199,
199,
7692,
2893,
26,
819,
3999,
275,
17198,
342,
523,
3999,
14,
1123,
8,
5081,
2773,
360,
1757,
297,
283,
1757,
1072,
436,
6698,
297,
283,
889,
297,
1993,
4370,
63,
1459,
7782,
5066,
297,
283,
889,
297,
283,
2861,
659,
1993,
2341,
10324,
3686,
2546,
29,
18,
430,
523,
2263,
523,
340,
2589,
459,
1757,
418,
508,
283,
2861,
356,
272,
2263,
199,
624,
199,
199,
3,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
12,
6029,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
11458,
15,
5081,
2773,
14,
647,
4976,
13,
1651,
1367,
26,
1479,
2114,
26,
68,
1789,
66,
23,
65,
18,
70,
2322,
69,
24,
6029,
15,
2036,
15,
1717,
4114,
26,
1703,
26,
1651,
486,
695,
79,
2,
199,
199,
363,
452,
363,
275,
788,
5081,
2773,
297,
61,
421,
199,
646,
8218,
14,
9298,
199,
199,
318,
485,
11034,
8,
498,
12,
1139,
12,
2589,
12,
5322,
304,
272,
340,
440,
1139,
315,
5322,
26,
267,
746,
8218,
14,
9298,
14,
1899,
547,
8,
288,
283,
3364,
574,
367,
945,
450,
83,
26,
450,
83,
14,
221,
4821,
1338,
787,
26,
450,
83,
7,
450,
334,
498,
12,
1139,
12,
5322,
430,
421,
199,
318,
11305,
2773,
8,
498,
12,
1720,
12,
849,
12,
4370,
63,
1459,
12,
2341,
10324,
3686,
2546,
29,
16,
304,
272,
408,
272,
710,
1324,
2633,
13743,
282,
945,
543,
1454,
9842,
1338,
272,
4370,
14,
9322,
787,
2138,
543,
376,
5827,
11109,
436,
272,
11822,
11544,
14,
710,
754,
365,
18025,
367,
1324,
370,
272,
17198,
14,
1123,
1252,
339,
283,
498,
7,
436,
283,
885,
7,
787,
314,
1338,
370,
506,
3032,
641,
370,
17198,
14,
1123,
1252,
339,
283,
3437,
7,
911,
506,
11544,
701,
314,
4370,
1338,
5847,
339,
283,
6541,
63,
1459,
7,
365,
282,
769,
402,
3326,
12,
1314,
787,
4370,
465,
1338,
272,
367,
642,
945,
14,
339,
710,
283,
1130,
12418,
9086,
1443,
506,
1202,
367,
13806,
314,
1324,
574,
272,
1901,
11358,
1338,
334,
5902,
14,
367,
5481,
680,
339,
283,
4247,
2546,
7,
7890,
314,
13942,
402,
314,
11822,
26,
339,
982,
3686,
2546,
508,
378,
12,
314,
11822,
15,
11256,
787,
1930,
13,
7361,
14,
272,
982,
3686,
2546,
508,
413,
12,
314,
11822,
15,
11256,
787,
1930,
13,
15851,
14,
272,
982,
3686,
2546,
508,
499,
12,
314,
11822,
15,
11256,
365,
1930,
13,
15851,
436,
717,
314,
6702,
574,
911,
3544,
506,
5117,
13,
2546,
14,
339,
710,
283,
11034,
7,
2295,
3775,
314,
574,
365,
315,
314,
769,
402,
4370,
272,
1338,
14,
710,
283,
11256,
7,
15373,
1324,
1338,
7182,
370,
314,
272,
1627,
283,
1130,
12418,
9086,
334,
324,
11663,
1324,
1338,
787,
2138,
272,
14874,
680,
5591,
408,
272,
1720,
275,
1543,
83,
4366,
83,
3171,
450,
334,
3437,
12,
21590,
904,
8,
6541,
63,
1459,
430,
272,
327,
5627,
11822,
272,
340,
3686,
2546,
2356,
413,
26,
267,
11822,
275,
2400,
790,
12,
1139,
12,
2589,
26,
971,
490,
485,
11034,
8,
498,
12,
1139,
14,
2325,
1062,
2589,
12,
4370,
63,
1459,
9,
272,
587,
26,
267,
11822,
275,
2400,
790,
12,
1139,
12,
2589,
26,
971,
490,
485,
11034,
8,
498,
12,
1139,
12,
2589,
12,
4370,
63,
1459,
9,
272,
327,
5627,
11109,
272,
340,
3686,
2546,
508,
499,
26,
267,
11109,
275,
2400,
1139,
26,
2341,
14,
362,
8,
637,
14,
2325,
1062,
1139,
680,
2325,
342,
272,
916,
3686,
2546,
508,
413,
26,
267,
11109,
275,
2400,
1139,
26,
2341,
14,
362,
8,
637,
14,
2325,
1062,
1139,
9,
272,
587,
26,
267,
11109,
275,
2400,
1139,
26,
2341,
14,
362,
8,
637,
12,
1139,
9,
272,
372,
334,
498,
12,
1720,
12,
849,
12,
11822,
12,
11109,
9,
199,
199,
3,
10111,
17198,
26,
199,
3,
5174,
13,
2063,
26,
20,
199,
3,
4363,
13,
8741,
13,
632,
26,
20613,
199,
3,
9599,
26,
199,
3,
6695,
26,
663,
26414,
20849,
29,
20,
20105,
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
] |
[
3908,
14,
18521,
14,
11458,
14,
5081,
2773,
199,
199,
2765,
570,
7890,
314,
945,
730,
367,
8218,
17266,
1454,
2013,
199,
1210,
13,
1459,
14,
199,
199,
7692,
2893,
26,
819,
3999,
275,
17198,
342,
523,
3999,
14,
1123,
8,
5081,
2773,
360,
1757,
297,
283,
1757,
1072,
436,
6698,
297,
283,
889,
297,
1993,
4370,
63,
1459,
7782,
5066,
297,
283,
889,
297,
283,
2861,
659,
1993,
2341,
10324,
3686,
2546,
29,
18,
430,
523,
2263,
523,
340,
2589,
459,
1757,
418,
508,
283,
2861,
356,
272,
2263,
199,
624,
199,
199,
3,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
12,
6029,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
11458,
15,
5081,
2773,
14,
647,
4976,
13,
1651,
1367,
26,
1479,
2114,
26,
68,
1789,
66,
23,
65,
18,
70,
2322,
69,
24,
6029,
15,
2036,
15,
1717,
4114,
26,
1703,
26,
1651,
486,
695,
79,
2,
199,
199,
363,
452,
363,
275,
788,
5081,
2773,
297,
61,
421,
199,
646,
8218,
14,
9298,
199,
199,
318,
485,
11034,
8,
498,
12,
1139,
12,
2589,
12,
5322,
304,
272,
340,
440,
1139,
315,
5322,
26,
267,
746,
8218,
14,
9298,
14,
1899,
547,
8,
288,
283,
3364,
574,
367,
945,
450,
83,
26,
450,
83,
14,
221,
4821,
1338,
787,
26,
450,
83,
7,
450,
334,
498,
12,
1139,
12,
5322,
430,
421,
199,
318,
11305,
2773,
8,
498,
12,
1720,
12,
849,
12,
4370,
63,
1459,
12,
2341,
10324,
3686,
2546,
29,
16,
304,
272,
408,
272,
710,
1324,
2633,
13743,
282,
945,
543,
1454,
9842,
1338,
272,
4370,
14,
9322,
787,
2138,
543,
376,
5827,
11109,
436,
272,
11822,
11544,
14,
710,
754,
365,
18025,
367,
1324,
370,
272,
17198,
14,
1123,
1252,
339,
283,
498,
7,
436,
283,
885,
7,
787,
314,
1338,
370,
506,
3032,
641,
370,
17198,
14,
1123,
1252,
339,
283,
3437,
7,
911,
506,
11544,
701,
314,
4370,
1338,
5847,
339,
283,
6541,
63,
1459,
7,
365,
282,
769,
402,
3326,
12,
1314,
787,
4370,
465,
1338,
272,
367,
642,
945,
14,
339,
710,
283,
1130,
12418,
9086,
1443,
506,
1202,
367,
13806,
314,
1324,
574,
272,
1901,
11358,
1338,
334,
5902,
14,
367,
5481,
680,
339,
283,
4247,
2546,
7,
7890,
314,
13942,
402,
314,
11822,
26,
339,
982,
3686,
2546,
508,
378,
12,
314,
11822,
15,
11256,
787,
1930,
13,
7361,
14,
272,
982,
3686,
2546,
508,
413,
12,
314,
11822,
15,
11256,
787,
1930,
13,
15851,
14,
272,
982,
3686,
2546,
508,
499,
12,
314,
11822,
15,
11256,
365,
1930,
13,
15851,
436,
717,
314,
6702,
574,
911,
3544,
506,
5117,
13,
2546,
14,
339,
710,
283,
11034,
7,
2295,
3775,
314,
574,
365,
315,
314,
769,
402,
4370,
272,
1338,
14,
710,
283,
11256,
7,
15373,
1324,
1338,
7182,
370,
314,
272,
1627,
283,
1130,
12418,
9086,
334,
324,
11663,
1324,
1338,
787,
2138,
272,
14874,
680,
5591,
408,
272,
1720,
275,
1543,
83,
4366,
83,
3171,
450,
334,
3437,
12,
21590,
904,
8,
6541,
63,
1459,
430,
272,
327,
5627,
11822,
272,
340,
3686,
2546,
2356,
413,
26,
267,
11822,
275,
2400,
790,
12,
1139,
12,
2589,
26,
971,
490,
485,
11034,
8,
498,
12,
1139,
14,
2325,
1062,
2589,
12,
4370,
63,
1459,
9,
272,
587,
26,
267,
11822,
275,
2400,
790,
12,
1139,
12,
2589,
26,
971,
490,
485,
11034,
8,
498,
12,
1139,
12,
2589,
12,
4370,
63,
1459,
9,
272,
327,
5627,
11109,
272,
340,
3686,
2546,
508,
499,
26,
267,
11109,
275,
2400,
1139,
26,
2341,
14,
362,
8,
637,
14,
2325,
1062,
1139,
680,
2325,
342,
272,
916,
3686,
2546,
508,
413,
26,
267,
11109,
275,
2400,
1139,
26,
2341,
14,
362,
8,
637,
14,
2325,
1062,
1139,
9,
272,
587,
26,
267,
11109,
275,
2400,
1139,
26,
2341,
14,
362,
8,
637,
12,
1139,
9,
272,
372,
334,
498,
12,
1720,
12,
849,
12,
11822,
12,
11109,
9,
199,
199,
3,
10111,
17198,
26,
199,
3,
5174,
13,
2063,
26,
20,
199,
3,
4363,
13,
8741,
13,
632,
26,
20613,
199,
3,
9599,
26,
199,
3,
6695,
26,
663,
26414,
20849,
29,
20,
20105,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bwasti/caffe2
|
caffe2/python/layers/layers.py
|
1
|
10652
|
## @package layers
# Module caffe2.python.layers.layers
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from caffe2.python import core, schema, scope
from caffe2.python.layers.tags import TagContext
from collections import namedtuple
import numpy as np
# Some types to simplify descriptions of things traveling between ops
IdList = schema.List(np.int64)
IdScoreList = schema.Map(np.int64, np.float32)
def get_categorical_limit(record):
if schema.equal_schemas(record, IdList):
key = 'values'
elif schema.equal_schemas(record, IdScoreList, check_field_types=False):
key = 'values:keys'
else:
raise NotImplementedError()
assert record[key].metadata is not None, (
"Blob {} doesn't have metadata".format(str(record[key]())))
return record[key].metadata.categorical_limit
def set_request_only(field):
for f in field.all_scalars():
categorical_limit, expected_value = None, None
if not f.metadata:
feature_specs = schema.FeatureSpec(
feature_is_request_only=True,
)
elif not f.metadata.feature_specs:
categorical_limit = f.metadata.categorical_limit
expected_value = f.metadata.expected_value
feature_specs = schema.FeatureSpec(
feature_is_request_only=True,
)
else:
categorical_limit = f.metadata.categorical_limit
expected_value = f.metadata.expected_value
feature_specs = schema.FeatureSpec(
feature_type=f.metadata.feature_specs.feature_type,
feature_names=f.metadata.feature_specs.feature_names,
feature_ids=f.metadata.feature_specs.feature_ids,
feature_is_request_only=True,
desired_hash_size=f.metadata.feature_specs.desired_hash_size,
)
# make sure not to set categorical_limit for a non-integer field
if not np.issubdtype(f.field_type(), np.integer):
assert categorical_limit is None, \
"categorical_limit shouldn't be set for no-integer field"
f.set_metadata(
schema.Metadata(
categorical_limit=categorical_limit,
expected_value=expected_value,
feature_specs=feature_specs,
)
)
class InstantiationContext(object):
"""
List of contexts where layer could be instantitated
"""
# The layers support this context will accumulate predictions, labels,
# weights. The accumulated data can later be used to compute
# calibration or for other
# purpose.
ACCUMULATE_PRED = 'accumulate_pred'
EVAL = 'eval'
PREDICTION = 'prediction'
TRAINING = 'training'
_LAYER_REGISTRY = {}
def register_layer(name, layer):
assert name not in _LAYER_REGISTRY, "{0} already exists".format(name)
_LAYER_REGISTRY[name] = layer
def layer_exists(name):
return name in _LAYER_REGISTRY
def get_layer_class(name):
return _LAYER_REGISTRY[name]
def create_layer(layer_name, *args, **kwargs):
return _LAYER_REGISTRY[layer_name](*args, **kwargs)
LayerPsParam = namedtuple('LayerPsParam', ['sparse_key', 'average_length'])
class LayerParameter(object):
def __init__(self, parameter=None, optimizer=None, initializer=None,
ps_param=None):
assert isinstance(parameter, core.BlobReference), \
"expect {0} to be a blob reference".format(str(parameter))
self.parameter = parameter
self.optimizer = optimizer
self.initializer = initializer
self.ps_param = ps_param
def is_request_only_scalar(scalar):
if len(scalar.field_metadata()) == 0:
return False
for metadata in scalar.field_metadata():
if not (metadata and metadata.feature_specs and getattr(
metadata.feature_specs, 'feature_is_request_only', False)):
return False
return True
class ModelLayer(object):
def __init__(self, model, prefix, input_record,
predict_input_record_fields=None, tags=None, **kwargs):
"""
Base class for model layers. Layer is an abstraction that allows to
provide model description in terms of meta-operators, where each of the
meta-operators can have different implementations for training,
evaluation and prediction, that are instantiated later. As an example
SampledSoftmax can do something related to sampling depending on
supervision during the training and just apply softmax if it's used for
prediction/evaluation.
All inputs/outputs from layers are represented as a record (instance of
schema bounded to blobs) and are accessible through input_record and
output_schema. If Layer needs to have only a subset of inputs/provides
subset of outputs during the inference - it should provide
predict_input_record and predict_output_schema correspondingly (those
records are expected to be a subset of input_record/output_schema).
Each layer has a list of Tags associated with it, that depends on
current context and arguments. It's possible to use those tags during
the instantiation time.
"""
self.name = model.next_layer_name(prefix)
self.model = model
self.kwargs = kwargs
self._input_record = input_record
if predict_input_record_fields:
if not isinstance(predict_input_record_fields, list):
predict_input_record_fields = [predict_input_record_fields]
self._predict_input_record = self._input_record[
predict_input_record_fields]
else:
self._predict_input_record = None
self.request_only = True
if len(input_record.all_scalars()) == 0:
self.request_only = False
for scalar in input_record.all_scalars():
if not is_request_only_scalar(scalar):
self.request_only = False
break
self._output_schema = None
self._predict_output_schema = None
self.eval_output_schema = None
self.tags = set(tags or [])
self.tags.update(TagContext.current().tags)
self.params = []
def get_type(self):
return self.__class__.__name__
def _check_output_schema(self):
assert self._output_schema is not None, "Schema is not initialized"
assert (self._predict_output_schema is None or
schema.is_schema_subset(self._predict_output_schema,
self._output_schema)), (
"predict_output_schema is not a subset of the output_schema")
@property
def predict_input_record(self):
return self._predict_input_record or self._input_record
@property
def input_record(self):
return self._input_record
@property
def predict_output_schema(self):
self._check_output_schema()
return self._predict_output_schema or self._output_schema
@predict_output_schema.setter
def predict_output_schema(self, output_schema):
assert self._predict_output_schema is None
self._predict_output_schema = output_schema
@property
def output_schema(self):
if self.request_only:
set_request_only(self._output_schema)
self._check_output_schema()
return self._output_schema
@output_schema.setter
def output_schema(self, output_schema):
assert self._output_schema is None
self._output_schema = output_schema
def get_parameters(self):
return self.params
def get_fp16_compatible_parameters(self):
"""Return a subset of parameters which can be converted to fp16"""
return []
def get_memory_usage(self):
return 0
def add_init_params(self, init_net):
'''
Adds layer initialization operators to passed net.
'''
for param in self.params:
# TODO(amalevich): Either return back to lambdas, that add
# all params (looks a bit safer and breaking less
# abstractions) or extend Net interface to this type of
# operations better
# TODO(xlwang) init_net._net.op has type google.protobuf.\
# internal.containers.RepeatedCompositeFieldContainer, but
# the version of protobuf in fbcode does not support append
# so extend is used
if param.initializer:
init_net._net.op.extend([param.initializer])
def add_operators(self, net, init_net=None,
context=InstantiationContext.TRAINING):
'''
Adds layer trainig or initialization operators to the passed in net.
init_net can be None and can be called independently from add_init_params
'''
# Namescope below should warranty that all intermediate blobs will be
# assiciated with the layer that produces them
with scope.NameScope(self.name):
if context not in {InstantiationContext.PREDICTION,
InstantiationContext.EVAL,
InstantiationContext.ACCUMULATE_PRED}:
assert init_net, (
"Only prediction and eval context don't need init_net")
if init_net:
self.add_init_params(init_net)
if context == InstantiationContext.TRAINING:
self.add_train_ops(net)
elif context == InstantiationContext.EVAL:
self.add_eval_ops(net)
elif context == InstantiationContext.ACCUMULATE_PRED:
self.add_ops_to_accumulate_pred(net)
else:
self.add_ops(net)
def add_ops(self, net):
raise NotImplementedError
def add_eval_ops(self, net):
# Default train layer implementation is completely matching predict
# layer implementation.
self.add_ops(net)
def add_train_ops(self, net):
# Default eval layer implementation is completely matching eval
# layer implementation.
self.add_eval_ops(net)
def add_ops_to_accumulate_pred(self, net):
# This adds operators to accumulate predictions/labels/weights. The
# accumulated data can later be used to compute calibration or for other
# purpose. Default layer implementation is completely matching eval
# layer implementation.
self.add_eval_ops(net)
|
apache-2.0
|
[
309,
768,
2491,
9393,
199,
3,
5673,
1704,
2026,
18,
14,
1548,
14,
4359,
14,
4359,
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,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1704,
2026,
18,
14,
1548,
492,
6170,
12,
4177,
12,
4194,
199,
504,
1704,
2026,
18,
14,
1548,
14,
4359,
14,
2969,
492,
8053,
2998,
199,
199,
504,
5055,
492,
12863,
199,
646,
2680,
465,
980,
199,
199,
3,
6601,
2943,
370,
15037,
18714,
402,
7645,
1468,
1090,
316,
3382,
4156,
199,
1304,
1296,
275,
4177,
14,
1296,
8,
1590,
14,
442,
772,
9,
199,
1304,
12642,
1296,
275,
4177,
14,
2956,
8,
1590,
14,
442,
772,
12,
980,
14,
1609,
708,
9,
421,
199,
318,
664,
63,
16810,
63,
3097,
8,
3059,
304,
272,
340,
4177,
14,
1452,
63,
9482,
8,
3059,
12,
15418,
1296,
304,
267,
790,
275,
283,
1459,
7,
272,
916,
4177,
14,
1452,
63,
9482,
8,
3059,
12,
15418,
12642,
1296,
12,
1104,
63,
698,
63,
1313,
29,
797,
304,
267,
790,
275,
283,
1459,
26,
1612,
7,
272,
587,
26,
267,
746,
4279,
342,
272,
702,
2777,
59,
498,
1055,
2343,
365,
440,
488,
12,
334,
267,
298,
16799,
1052,
3181,
1133,
1172,
3341,
1674,
908,
8,
495,
8,
3059,
59,
498,
61,
16890,
272,
372,
2777,
59,
498,
1055,
2343,
14,
16810,
63,
3097,
421,
199,
318,
663,
63,
1069,
63,
2118,
8,
698,
304,
272,
367,
289,
315,
901,
14,
452,
63,
4732,
4291,
837,
267,
22138,
63,
3097,
12,
1420,
63,
585,
275,
488,
12,
488,
267,
340,
440,
289,
14,
2343,
26,
288,
3878,
63,
7273,
275,
4177,
14,
5968,
5307,
8,
355,
3878,
63,
374,
63,
1069,
63,
2118,
29,
549,
12,
288,
776,
267,
916,
440,
289,
14,
2343,
14,
4445,
63,
7273,
26,
288,
22138,
63,
3097,
275,
289,
14,
2343,
14,
16810,
63,
3097,
288,
1420,
63,
585,
275,
289,
14,
2343,
14,
2062,
63,
585,
288,
3878,
63,
7273,
275,
4177,
14,
5968,
5307,
8,
355,
3878,
63,
374,
63,
1069,
63,
2118,
29,
549,
12,
288,
776,
267,
587,
26,
288,
22138,
63,
3097,
275,
289,
14,
2343,
14,
16810,
63,
3097,
288,
1420,
63,
585,
275,
289,
14,
2343,
14,
2062,
63,
585,
288,
3878,
63,
7273,
275,
4177,
14,
5968,
5307,
8,
355,
3878,
63,
466,
29,
70,
14,
2343,
14,
4445,
63,
7273,
14,
4445,
63,
466,
12,
355,
3878,
63,
1247,
29,
70,
14,
2343,
14,
4445,
63,
7273,
14,
4445,
63,
1247,
12,
355,
3878,
63,
1580,
29,
70,
14,
2343,
14,
4445,
63,
7273,
14,
4445,
63,
1580,
12,
355,
3878,
63,
374,
63,
1069,
63,
2118,
29,
549,
12,
355,
6387,
63,
2227,
63,
890,
29,
70,
14,
2343,
14,
4445,
63,
7273,
14,
16035,
63,
2227,
63,
890,
12,
288,
776,
398,
327,
1852,
3238,
440,
370,
663,
22138,
63,
3097,
367,
282,
2222,
13,
4115,
901,
267,
340,
440,
980,
14,
374,
954,
2271,
8,
70,
14,
698,
63,
466,
1062,
980,
14,
4115,
304,
288,
702,
22138,
63,
3097,
365,
488,
12,
971,
355,
298,
16810,
63,
3097,
9296,
1133,
506,
663,
367,
949,
13,
4115,
901,
2,
398,
289,
14,
409,
63,
2343,
8,
288,
4177,
14,
5142,
8,
355,
22138,
63,
3097,
29,
16810,
63,
3097,
12,
355,
1420,
63,
585,
29,
2062,
63,
585,
12,
355,
3878,
63,
7273,
29,
4445,
63,
7273,
12,
288,
776,
267,
776,
421,
199,
533,
14089,
4466,
425,
2998,
8,
785,
304,
272,
408,
272,
3820,
402,
18191,
2382,
4045,
4293,
506,
9034,
84,
972,
272,
408,
272,
327,
710,
9393,
2291,
642,
1067,
911,
30535,
7914,
12,
3628,
12,
272,
327,
4931,
14,
710,
29845,
666,
883,
2945,
506,
1202,
370,
4526,
272,
327,
25365,
503,
367,
1163,
272,
327,
12016,
14,
272,
16362,
2639,
1293,
1951,
63,
22973,
275,
283,
13223,
5434,
63,
5991,
7,
272,
662,
3204,
275,
283,
2579,
7,
272,
510,
7387,
6196,
1075,
275,
283,
14845,
7,
272,
377,
21715,
1206,
275,
283,
7588,
7,
421,
199,
63,
24167,
63,
25304,
57,
275,
1052,
421,
199,
318,
2274,
63,
1897,
8,
354,
12,
4045,
304,
272,
702,
536,
440,
315,
485,
24167,
63,
25304,
57,
12,
5310,
16,
93,
2575,
3495,
1674,
908,
8,
354,
9,
272,
485,
24167,
63,
25304,
57,
59,
354,
61,
275,
4045,
421,
199,
318,
4045,
63,
2444,
8,
354,
304,
272,
372,
536,
315,
485,
24167,
63,
25304,
57,
421,
199,
318,
664,
63,
1897,
63,
533,
8,
354,
304,
272,
372,
485,
24167,
63,
25304,
57,
59,
354,
61,
421,
199,
318,
1218,
63,
1897,
8,
1897,
63,
354,
12,
627,
589,
12,
1011,
958,
304,
272,
372,
485,
24167,
63,
25304,
57,
59,
1897,
63,
354,
61,
2031,
589,
12,
1011,
958,
9,
421,
199,
5003,
25512,
4098,
275,
12863,
360,
5003,
25512,
4098,
297,
788,
4421,
63,
498,
297,
283,
8536,
63,
1267,
1105,
421,
199,
533,
11915,
4720,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
2725,
29,
403,
12,
10736,
29,
403,
12,
11130,
29,
403,
12,
326,
7347,
63,
635,
29,
403,
304,
267,
702,
1228,
8,
5329,
12,
6170,
14,
16799,
5083,
395,
971,
288,
298,
4921,
469,
16,
93,
370,
506,
282,
9182,
3659,
1674,
908,
8,
495,
8,
5329,
430,
267,
291,
14,
5329,
275,
2725,
267,
291,
14,
12290,
275,
10736,
267,
291,
14,
6498,
275,
11130,
267,
291,
14,
1190,
63,
635,
275,
7347,
63,
635,
421,
199,
318,
365,
63,
1069,
63,
2118,
63,
7033,
8,
7033,
304,
272,
340,
822,
8,
7033,
14,
698,
63,
2343,
1012,
508,
378,
26,
267,
372,
756,
272,
367,
3341,
315,
6917,
14,
698,
63,
2343,
837,
267,
340,
440,
334,
2343,
436,
3341,
14,
4445,
63,
7273,
436,
2519,
8,
355,
3341,
14,
4445,
63,
7273,
12,
283,
4445,
63,
374,
63,
1069,
63,
2118,
297,
756,
2298,
288,
372,
756,
272,
372,
715,
421,
199,
533,
5822,
5003,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1402,
12,
2403
] |
[
768,
2491,
9393,
199,
3,
5673,
1704,
2026,
18,
14,
1548,
14,
4359,
14,
4359,
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,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1704,
2026,
18,
14,
1548,
492,
6170,
12,
4177,
12,
4194,
199,
504,
1704,
2026,
18,
14,
1548,
14,
4359,
14,
2969,
492,
8053,
2998,
199,
199,
504,
5055,
492,
12863,
199,
646,
2680,
465,
980,
199,
199,
3,
6601,
2943,
370,
15037,
18714,
402,
7645,
1468,
1090,
316,
3382,
4156,
199,
1304,
1296,
275,
4177,
14,
1296,
8,
1590,
14,
442,
772,
9,
199,
1304,
12642,
1296,
275,
4177,
14,
2956,
8,
1590,
14,
442,
772,
12,
980,
14,
1609,
708,
9,
421,
199,
318,
664,
63,
16810,
63,
3097,
8,
3059,
304,
272,
340,
4177,
14,
1452,
63,
9482,
8,
3059,
12,
15418,
1296,
304,
267,
790,
275,
283,
1459,
7,
272,
916,
4177,
14,
1452,
63,
9482,
8,
3059,
12,
15418,
12642,
1296,
12,
1104,
63,
698,
63,
1313,
29,
797,
304,
267,
790,
275,
283,
1459,
26,
1612,
7,
272,
587,
26,
267,
746,
4279,
342,
272,
702,
2777,
59,
498,
1055,
2343,
365,
440,
488,
12,
334,
267,
298,
16799,
1052,
3181,
1133,
1172,
3341,
1674,
908,
8,
495,
8,
3059,
59,
498,
61,
16890,
272,
372,
2777,
59,
498,
1055,
2343,
14,
16810,
63,
3097,
421,
199,
318,
663,
63,
1069,
63,
2118,
8,
698,
304,
272,
367,
289,
315,
901,
14,
452,
63,
4732,
4291,
837,
267,
22138,
63,
3097,
12,
1420,
63,
585,
275,
488,
12,
488,
267,
340,
440,
289,
14,
2343,
26,
288,
3878,
63,
7273,
275,
4177,
14,
5968,
5307,
8,
355,
3878,
63,
374,
63,
1069,
63,
2118,
29,
549,
12,
288,
776,
267,
916,
440,
289,
14,
2343,
14,
4445,
63,
7273,
26,
288,
22138,
63,
3097,
275,
289,
14,
2343,
14,
16810,
63,
3097,
288,
1420,
63,
585,
275,
289,
14,
2343,
14,
2062,
63,
585,
288,
3878,
63,
7273,
275,
4177,
14,
5968,
5307,
8,
355,
3878,
63,
374,
63,
1069,
63,
2118,
29,
549,
12,
288,
776,
267,
587,
26,
288,
22138,
63,
3097,
275,
289,
14,
2343,
14,
16810,
63,
3097,
288,
1420,
63,
585,
275,
289,
14,
2343,
14,
2062,
63,
585,
288,
3878,
63,
7273,
275,
4177,
14,
5968,
5307,
8,
355,
3878,
63,
466,
29,
70,
14,
2343,
14,
4445,
63,
7273,
14,
4445,
63,
466,
12,
355,
3878,
63,
1247,
29,
70,
14,
2343,
14,
4445,
63,
7273,
14,
4445,
63,
1247,
12,
355,
3878,
63,
1580,
29,
70,
14,
2343,
14,
4445,
63,
7273,
14,
4445,
63,
1580,
12,
355,
3878,
63,
374,
63,
1069,
63,
2118,
29,
549,
12,
355,
6387,
63,
2227,
63,
890,
29,
70,
14,
2343,
14,
4445,
63,
7273,
14,
16035,
63,
2227,
63,
890,
12,
288,
776,
398,
327,
1852,
3238,
440,
370,
663,
22138,
63,
3097,
367,
282,
2222,
13,
4115,
901,
267,
340,
440,
980,
14,
374,
954,
2271,
8,
70,
14,
698,
63,
466,
1062,
980,
14,
4115,
304,
288,
702,
22138,
63,
3097,
365,
488,
12,
971,
355,
298,
16810,
63,
3097,
9296,
1133,
506,
663,
367,
949,
13,
4115,
901,
2,
398,
289,
14,
409,
63,
2343,
8,
288,
4177,
14,
5142,
8,
355,
22138,
63,
3097,
29,
16810,
63,
3097,
12,
355,
1420,
63,
585,
29,
2062,
63,
585,
12,
355,
3878,
63,
7273,
29,
4445,
63,
7273,
12,
288,
776,
267,
776,
421,
199,
533,
14089,
4466,
425,
2998,
8,
785,
304,
272,
408,
272,
3820,
402,
18191,
2382,
4045,
4293,
506,
9034,
84,
972,
272,
408,
272,
327,
710,
9393,
2291,
642,
1067,
911,
30535,
7914,
12,
3628,
12,
272,
327,
4931,
14,
710,
29845,
666,
883,
2945,
506,
1202,
370,
4526,
272,
327,
25365,
503,
367,
1163,
272,
327,
12016,
14,
272,
16362,
2639,
1293,
1951,
63,
22973,
275,
283,
13223,
5434,
63,
5991,
7,
272,
662,
3204,
275,
283,
2579,
7,
272,
510,
7387,
6196,
1075,
275,
283,
14845,
7,
272,
377,
21715,
1206,
275,
283,
7588,
7,
421,
199,
63,
24167,
63,
25304,
57,
275,
1052,
421,
199,
318,
2274,
63,
1897,
8,
354,
12,
4045,
304,
272,
702,
536,
440,
315,
485,
24167,
63,
25304,
57,
12,
5310,
16,
93,
2575,
3495,
1674,
908,
8,
354,
9,
272,
485,
24167,
63,
25304,
57,
59,
354,
61,
275,
4045,
421,
199,
318,
4045,
63,
2444,
8,
354,
304,
272,
372,
536,
315,
485,
24167,
63,
25304,
57,
421,
199,
318,
664,
63,
1897,
63,
533,
8,
354,
304,
272,
372,
485,
24167,
63,
25304,
57,
59,
354,
61,
421,
199,
318,
1218,
63,
1897,
8,
1897,
63,
354,
12,
627,
589,
12,
1011,
958,
304,
272,
372,
485,
24167,
63,
25304,
57,
59,
1897,
63,
354,
61,
2031,
589,
12,
1011,
958,
9,
421,
199,
5003,
25512,
4098,
275,
12863,
360,
5003,
25512,
4098,
297,
788,
4421,
63,
498,
297,
283,
8536,
63,
1267,
1105,
421,
199,
533,
11915,
4720,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
2725,
29,
403,
12,
10736,
29,
403,
12,
11130,
29,
403,
12,
326,
7347,
63,
635,
29,
403,
304,
267,
702,
1228,
8,
5329,
12,
6170,
14,
16799,
5083,
395,
971,
288,
298,
4921,
469,
16,
93,
370,
506,
282,
9182,
3659,
1674,
908,
8,
495,
8,
5329,
430,
267,
291,
14,
5329,
275,
2725,
267,
291,
14,
12290,
275,
10736,
267,
291,
14,
6498,
275,
11130,
267,
291,
14,
1190,
63,
635,
275,
7347,
63,
635,
421,
199,
318,
365,
63,
1069,
63,
2118,
63,
7033,
8,
7033,
304,
272,
340,
822,
8,
7033,
14,
698,
63,
2343,
1012,
508,
378,
26,
267,
372,
756,
272,
367,
3341,
315,
6917,
14,
698,
63,
2343,
837,
267,
340,
440,
334,
2343,
436,
3341,
14,
4445,
63,
7273,
436,
2519,
8,
355,
3341,
14,
4445,
63,
7273,
12,
283,
4445,
63,
374,
63,
1069,
63,
2118,
297,
756,
2298,
288,
372,
756,
272,
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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
] |
ciaa/linux
|
tools/perf/python/twatch.py
|
1565
|
1316
|
#! /usr/bin/python
# -*- python -*-
# -*- coding: utf-8 -*-
# twatch - Experimental use of the perf python interface
# Copyright (C) 2011 Arnaldo Carvalho de Melo <acme@redhat.com>
#
# This application 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.
#
# This application is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
import perf
def main():
cpus = perf.cpu_map()
threads = perf.thread_map()
evsel = perf.evsel(task = 1, comm = 1, mmap = 0,
wakeup_events = 1, watermark = 1,
sample_id_all = 1,
sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU)
evsel.open(cpus = cpus, threads = threads);
evlist = perf.evlist(cpus, threads)
evlist.add(evsel)
evlist.mmap()
while True:
evlist.poll(timeout = -1)
for cpu in cpus:
event = evlist.read_on_cpu(cpu)
if not event:
continue
print "cpu: %2d, pid: %4d, tid: %4d" % (event.sample_cpu,
event.sample_pid,
event.sample_tid),
print event
if __name__ == '__main__':
main()
|
gpl-2.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2366,
1882,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
257,
307,
6821,
446,
23997,
279,
675,
402,
314,
8582,
2366,
3217,
199,
3,
257,
1898,
334,
35,
9,
7760,
1952,
78,
279,
1117,
14243,
637,
526,
477,
3194,
320,
665,
18107,
32,
17164,
14,
957,
30,
199,
3,
199,
3,
257,
961,
4223,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
257,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
257,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1015,
499,
14,
199,
3,
199,
3,
257,
961,
4223,
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,
1664,
199,
3,
257,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
646,
8582,
199,
199,
318,
2446,
837,
199,
198,
8896,
275,
8582,
14,
3541,
63,
1130,
342,
199,
198,
6962,
275,
8582,
14,
2671,
63,
1130,
342,
199,
198,
6857,
5891,
275,
8582,
14,
6857,
5891,
8,
1765,
275,
413,
12,
1923,
275,
413,
12,
21991,
275,
378,
12,
1585,
257,
21560,
384,
63,
4368,
275,
413,
12,
22834,
1657,
275,
413,
12,
1585,
257,
2690,
63,
344,
63,
452,
275,
413,
12,
1585,
257,
2690,
63,
466,
275,
8582,
14,
15827,
63,
27081,
1204,
8582,
14,
15827,
63,
52,
998,
1204,
8582,
14,
15827,
63,
11011,
9,
199,
198,
6857,
5891,
14,
1490,
8,
8896,
275,
24174,
12,
7183,
275,
7183,
2736,
199,
198,
6857,
513,
275,
8582,
14,
6857,
513,
8,
8896,
12,
7183,
9,
199,
198,
6857,
513,
14,
525,
8,
6857,
5891,
9,
199,
198,
6857,
513,
14,
20671,
342,
199,
198,
6710,
715,
26,
507,
198,
6857,
513,
14,
6843,
8,
2593,
275,
446,
17,
9,
507,
198,
509,
5033,
315,
24174,
26,
686,
198,
1430,
275,
8145,
513,
14,
739,
63,
265,
63,
3541,
8,
3541,
9,
686,
198,
692,
440,
1566,
26,
1585,
198,
6958,
686,
198,
1361,
298,
3541,
26,
450,
18,
68,
12,
4422,
26,
450,
20,
68,
12,
11559,
26,
450,
20,
68,
2,
450,
334,
1430,
14,
3271,
63,
3541,
12,
11674,
198,
1430,
14,
3271,
63,
3150,
12,
11674,
198,
1430,
14,
3271,
63,
5700,
395,
686,
198,
1361,
1566,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1182,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2366,
1882,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
257,
307,
6821,
446,
23997,
279,
675,
402,
314,
8582,
2366,
3217,
199,
3,
257,
1898,
334,
35,
9,
7760,
1952,
78,
279,
1117,
14243,
637,
526,
477,
3194,
320,
665,
18107,
32,
17164,
14,
957,
30,
199,
3,
199,
3,
257,
961,
4223,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
257,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
257,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1015,
499,
14,
199,
3,
199,
3,
257,
961,
4223,
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,
1664,
199,
3,
257,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
646,
8582,
199,
199,
318,
2446,
837,
199,
198,
8896,
275,
8582,
14,
3541,
63,
1130,
342,
199,
198,
6962,
275,
8582,
14,
2671,
63,
1130,
342,
199,
198,
6857,
5891,
275,
8582,
14,
6857,
5891,
8,
1765,
275,
413,
12,
1923,
275,
413,
12,
21991,
275,
378,
12,
1585,
257,
21560,
384,
63,
4368,
275,
413,
12,
22834,
1657,
275,
413,
12,
1585,
257,
2690,
63,
344,
63,
452,
275,
413,
12,
1585,
257,
2690,
63,
466,
275,
8582,
14,
15827,
63,
27081,
1204,
8582,
14,
15827,
63,
52,
998,
1204,
8582,
14,
15827,
63,
11011,
9,
199,
198,
6857,
5891,
14,
1490,
8,
8896,
275,
24174,
12,
7183,
275,
7183,
2736,
199,
198,
6857,
513,
275,
8582,
14,
6857,
513,
8,
8896,
12,
7183,
9,
199,
198,
6857,
513,
14,
525,
8,
6857,
5891,
9,
199,
198,
6857,
513,
14,
20671,
342,
199,
198,
6710,
715,
26,
507,
198,
6857,
513,
14,
6843,
8,
2593,
275,
446,
17,
9,
507,
198,
509,
5033,
315,
24174,
26,
686,
198,
1430,
275,
8145,
513,
14,
739,
63,
265,
63,
3541,
8,
3541,
9,
686,
198,
692,
440,
1566,
26,
1585,
198,
6958,
686,
198,
1361,
298,
3541,
26,
450,
18,
68,
12,
4422,
26,
450,
20,
68,
12,
11559,
26,
450,
20,
68,
2,
450,
334,
1430,
14,
3271,
63,
3541,
12,
11674,
198,
1430,
14,
3271,
63,
3150,
12,
11674,
198,
1430,
14,
3271,
63,
5700,
395,
686,
198,
1361,
1566,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pyjs/pyjs
|
examples/asteroids/Space.py
|
6
|
4946
|
# Copyright 2009 Joe Rumsey (joe@rumsey.org)
# Copyright 2012 Charles Law (charles.law@gmail.com)
#
# 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 pyjd # this is dummy in pyjs.
from pyjamas import DOM
from pyjamas.ui import Event
from pyjamas.ui import KeyboardListener
from pyjamas.ui.Button import Button
from pyjamas.ui.ClickListener import ClickHandler
from pyjamas.ui.FocusPanel import FocusPanel
from pyjamas.ui.HTML import HTML
from pyjamas.ui.Image import Image
from pyjamas.ui.KeyboardListener import KeyboardHandler
from pyjamas.ui.RootPanel import RootPanel, RootPanelCls
from pyjamas.Canvas import Color
from pyjamas.Canvas.GWTCanvas import GWTCanvas
from pyjamas.Canvas.ImageLoader import loadImages
from game_model import Model, ASTEROID_SIZE
from game_controller import Controller
SHOT_COLOR = Color.Color('#fff')
class GameCanvas(GWTCanvas):
def __init__(self, w, h):
GWTCanvas.__init__(self, w, h)
self.width = w
self.height = h
self.model = Model(w, h)
self.controller = Controller(self.model)
images = ['./images/ship1.png',
'./images/ship2.png',
'./images/asteroid.png']
loadImages(images, self)
self.sinkEvents(Event.KEYEVENTS)
def onImagesLoaded(self, imagesHandles):
self.ship = imagesHandles[0]
self.ship_thrust = imagesHandles[1]
self.asteroid = imagesHandles[2]
self.resize(self.width, self.height)
self.controller.start_game(self)
def addTo(self, panel):
panel.add(self)
self.top = DOM.getAbsoluteTop(self.getElement())
self.left = DOM.getAbsoluteLeft(self.getElement())
def setKey(self, k, set):
DOM.eventPreventDefault(DOM.eventGetCurrentEvent())
if k == 38:
self.controller.key_up = set
elif k == 40:
self.controller.key_down = set
elif k == 37:
self.controller.key_left = set
elif k == 39:
self.controller.key_right = set
elif k == 32:
self.controller.key_fire = set
def onKeyDown(self, sender, keyCode, modifiers = None):
self.setKey(keyCode, True)
def onKeyUp(self, sender, keyCode, modifiers = None):
self.setKey(keyCode, False)
def draw_asteroid(self, asteroid):
self.saveContext()
self.translate(asteroid.x, asteroid.y)
self.rotate(asteroid.rot)
self.scale(asteroid.scale,asteroid.scale)
self.drawImage(self.asteroid, -(ASTEROID_SIZE/2), -(ASTEROID_SIZE/2))
self.restoreContext()
def draw_shot(self, shot):
self.setFillStyle(SHOT_COLOR)
self.fillRect(int(shot.x - 1), int(shot.y - 1), 3, 3)
def draw_ship(self, ship):
self.saveContext()
self.translate(ship.x, ship.y)
self.rotate(ship.rot)
if self.controller.key_up:
img = self.ship_thrust
else:
img = self.ship
self.drawImage(img, -15, -12)
self.restoreContext()
def draw(self):
self.setFillStyle(Color.Color('#000'))
self.fillRect(0,0,self.width,self.height)
for a in self.model.asteroids:
self.draw_asteroid(a)
for s in self.model.shots:
self.draw_shot(s)
self.draw_ship(self.model.ship)
class RootPanelListener(RootPanelCls, KeyboardHandler, ClickHandler):
def __init__(self, Parent, *args, **kwargs):
self.Parent = Parent
self.focussed = False
RootPanelCls.__init__(self, *args, **kwargs)
ClickHandler.__init__(self)
KeyboardHandler.__init__(self)
self.addClickListener(self)
def onClick(self, Sender):
self.focussed = not self.focussed
self.Parent.setFocus(self.focussed)
if __name__ == '__main__':
pyjd.setup("public/Space.html")
c = GameCanvas(800, 600)
panel = FocusPanel(Widget=c)
RootPanel().add(panel)
panel.addKeyboardListener(c)
panel.setFocus(True)
RootPanel().add(HTML("""
<hr/>
Left/Right arrows turn, Up key thrusts, Space bar fires<br/>
<a href="http://rumsey.org/blog/?p=215">About Space Game</a> by <a href="http://rumsey.org/blog/">Ogre</a><br/>
Written entirely in Python, using <a href="http://pyjs.org/">Pyjamas</a></br>
Copyright © 2009 Joe Rumsey
"""))
#c.getElement().focus()
pyjd.run()
|
apache-2.0
|
[
3,
257,
1898,
8937,
7135,
69,
820,
453,
261,
89,
334,
20241,
32,
28430,
261,
89,
14,
1308,
9,
199,
3,
257,
1898,
6029,
6659,
2978,
7964,
87,
334,
1560,
2978,
14,
22277,
32,
6799,
14,
957,
9,
199,
3,
199,
3,
257,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
257,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
257,
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,
257,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
257,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
257,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
257,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
257,
4204,
1334,
314,
844,
14,
199,
3,
199,
646,
1134,
17694,
327,
642,
365,
7283,
315,
1134,
3596,
14,
199,
504,
1134,
16997,
305,
492,
14316,
199,
199,
504,
1134,
16997,
305,
14,
1907,
492,
6763,
199,
504,
1134,
16997,
305,
14,
1907,
492,
2606,
3576,
10464,
199,
199,
504,
1134,
16997,
305,
14,
1907,
14,
4259,
492,
16005,
199,
504,
1134,
16997,
305,
14,
1907,
14,
12040,
10464,
492,
26147,
2461,
199,
504,
1134,
16997,
305,
14,
1907,
14,
17310,
10185,
492,
481,
10763,
10185,
199,
504,
1134,
16997,
305,
14,
1907,
14,
4943,
492,
4163,
199,
504,
1134,
16997,
305,
14,
1907,
14,
3491,
492,
6047,
199,
504,
1134,
16997,
305,
14,
1907,
14,
28377,
10464,
492,
2606,
3576,
2461,
199,
504,
1134,
16997,
305,
14,
1907,
14,
6405,
10185,
492,
12826,
10185,
12,
12826,
10185,
24342,
199,
199,
504,
1134,
16997,
305,
14,
15174,
492,
11581,
199,
504,
1134,
16997,
305,
14,
15174,
14,
19674,
5708,
290,
4755,
492,
598,
55,
5708,
290,
4755,
199,
504,
1134,
16997,
305,
14,
15174,
14,
3491,
5455,
492,
2248,
18882,
421,
199,
504,
9219,
63,
1238,
492,
5822,
12,
20788,
12960,
998,
63,
4305,
199,
504,
9219,
63,
5538,
492,
16282,
421,
199,
25041,
63,
7134,
275,
11581,
14,
4117,
7863,
18190,
358,
421,
199,
533,
25132,
15174,
8,
19674,
5708,
290,
4755,
304,
272,
347,
636,
826,
721,
277,
12,
336,
12,
394,
304,
267,
598,
55,
5708,
290,
4755,
855,
826,
721,
277,
12,
336,
12,
394,
9,
267,
291,
14,
2063,
275,
336,
267,
291,
14,
3333,
275,
394,
2728,
291,
14,
1238,
275,
5822,
8,
87,
12,
394,
9,
267,
291,
14,
5538,
275,
16282,
8,
277,
14,
1238,
9,
398,
5935,
275,
788,
13186,
4782,
15,
3319,
17,
14,
4524,
297,
2116,
21526,
4782,
15,
3319,
18,
14,
4524,
297,
2116,
21526,
4782,
15,
9209,
3977,
14,
4524,
418,
267,
2248,
18882,
8,
4782,
12,
291,
9,
398,
291,
14,
11279,
11770,
8,
2390,
14,
3078,
8193,
51,
9,
339,
347,
641,
18882,
19757,
8,
277,
12,
5935,
23555,
304,
267,
291,
14,
3319,
275,
5935,
23555,
59,
16,
61,
267,
291,
14,
3319,
63,
273,
19622,
275,
5935,
23555,
59,
17,
61,
267,
291,
14,
9209,
3977,
275,
5935,
23555,
59,
18,
61,
398,
291,
14,
8709,
8,
277,
14,
2063,
12,
291,
14,
3333,
9,
398,
291,
14,
5538,
14,
928,
63,
5097,
8,
277,
9,
339,
347,
1050,
1378,
8,
277,
12,
12748,
304,
267,
12748,
14,
525,
8,
277,
9,
267,
291,
14,
2119,
275,
14316,
14,
362,
24677,
6105,
8,
277,
14,
21720,
1012,
267,
291,
14,
3039,
275,
14316,
14,
362,
24677,
8185,
8,
277,
14,
21720,
1012,
2378,
347,
663,
1197,
8,
277,
12,
1022,
12,
663,
304,
267,
14316,
14,
1430,
2398,
782,
2698,
8,
10462,
14,
1430,
29058,
2390,
1012,
267,
340,
1022,
508,
10448,
26,
288,
291,
14,
5538,
14,
498,
63,
384,
275,
663,
267,
916,
1022,
508,
6335,
26,
288,
291,
14,
5538,
14,
498,
63,
2110,
275,
663,
267,
916,
1022,
508,
6877,
26,
288,
291,
14,
5538,
14,
498,
63,
3039,
275,
663,
267,
916,
1022,
508,
10551,
26,
288,
291,
14,
5538,
14,
498,
63,
1019,
275,
663,
267,
916,
1022,
508,
4337,
26,
288,
291,
14,
5538,
14,
498,
63,
8935,
275,
663,
339,
347,
641,
1197,
3514,
8,
277,
12,
8904,
12,
790,
3034,
12,
9933,
275,
488,
304,
267,
291,
14,
409,
1197,
8,
498,
3034,
12,
715,
9,
339,
347,
641,
1197,
1721,
8,
277,
12,
8904,
12,
790,
3034,
12,
9933,
275,
488,
304,
267,
291,
14,
409,
1197,
8,
498,
3034,
12,
756,
9,
2378,
347,
5954,
63,
9209,
3977,
8,
277,
12,
465,
266,
3977,
304,
267,
291,
14,
2117,
2998,
342,
267,
291,
14,
5275,
8,
9209,
3977,
14,
88,
12,
465,
266,
3977,
14,
89,
9,
267,
291,
14,
12873,
8,
9209,
3977,
14,
4571,
9,
267,
291,
14,
3467,
8,
9209,
3977,
14,
3467,
12,
9209,
3977,
14,
3467,
9,
267,
291,
14,
5485,
3491,
8,
277,
14,
9209,
3977,
12,
24953,
11307,
12960,
998,
63,
4305,
15,
18,
395,
24953,
11307,
12960,
998,
63,
4305,
15,
18,
430,
267,
291,
14,
8011,
2998,
342,
339,
347,
5954,
63,
2782,
8,
277,
12,
1033,
357,
304,
267,
291,
14,
409,
12914,
6609,
8,
25041,
63,
7134,
9,
267,
291,
14,
4498,
8252,
8,
442,
8,
2782,
14,
88,
446,
413,
395,
1109,
8,
2782,
14,
89,
446,
413,
395,
650,
12,
650,
9,
5493,
347,
5954,
63,
3319,
8,
277,
12,
15924,
304,
267,
291,
14,
2117,
2998,
342,
267,
291,
14,
5275,
8,
3319,
14,
88,
12,
15924,
14,
89,
9,
267,
291,
14,
12873,
8,
3319,
14,
4571,
9,
267,
340,
291,
14,
5538,
14,
498,
63,
384,
26,
288,
6050,
275,
291,
14,
3319,
63,
273,
19622,
267,
587,
26,
288,
6050,
275,
291,
14,
3319,
267,
291,
14,
5485,
3491,
8,
4060,
12,
446,
1046,
12,
446,
713,
9,
267,
291,
14,
8011,
2998,
342,
199,
5493,
347,
5954,
8,
277,
304,
267,
291,
14,
409,
12914,
6609
] |
[
257,
1898,
8937,
7135,
69,
820,
453,
261,
89,
334,
20241,
32,
28430,
261,
89,
14,
1308,
9,
199,
3,
257,
1898,
6029,
6659,
2978,
7964,
87,
334,
1560,
2978,
14,
22277,
32,
6799,
14,
957,
9,
199,
3,
199,
3,
257,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
257,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
257,
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,
257,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
257,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
257,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
257,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
257,
4204,
1334,
314,
844,
14,
199,
3,
199,
646,
1134,
17694,
327,
642,
365,
7283,
315,
1134,
3596,
14,
199,
504,
1134,
16997,
305,
492,
14316,
199,
199,
504,
1134,
16997,
305,
14,
1907,
492,
6763,
199,
504,
1134,
16997,
305,
14,
1907,
492,
2606,
3576,
10464,
199,
199,
504,
1134,
16997,
305,
14,
1907,
14,
4259,
492,
16005,
199,
504,
1134,
16997,
305,
14,
1907,
14,
12040,
10464,
492,
26147,
2461,
199,
504,
1134,
16997,
305,
14,
1907,
14,
17310,
10185,
492,
481,
10763,
10185,
199,
504,
1134,
16997,
305,
14,
1907,
14,
4943,
492,
4163,
199,
504,
1134,
16997,
305,
14,
1907,
14,
3491,
492,
6047,
199,
504,
1134,
16997,
305,
14,
1907,
14,
28377,
10464,
492,
2606,
3576,
2461,
199,
504,
1134,
16997,
305,
14,
1907,
14,
6405,
10185,
492,
12826,
10185,
12,
12826,
10185,
24342,
199,
199,
504,
1134,
16997,
305,
14,
15174,
492,
11581,
199,
504,
1134,
16997,
305,
14,
15174,
14,
19674,
5708,
290,
4755,
492,
598,
55,
5708,
290,
4755,
199,
504,
1134,
16997,
305,
14,
15174,
14,
3491,
5455,
492,
2248,
18882,
421,
199,
504,
9219,
63,
1238,
492,
5822,
12,
20788,
12960,
998,
63,
4305,
199,
504,
9219,
63,
5538,
492,
16282,
421,
199,
25041,
63,
7134,
275,
11581,
14,
4117,
7863,
18190,
358,
421,
199,
533,
25132,
15174,
8,
19674,
5708,
290,
4755,
304,
272,
347,
636,
826,
721,
277,
12,
336,
12,
394,
304,
267,
598,
55,
5708,
290,
4755,
855,
826,
721,
277,
12,
336,
12,
394,
9,
267,
291,
14,
2063,
275,
336,
267,
291,
14,
3333,
275,
394,
2728,
291,
14,
1238,
275,
5822,
8,
87,
12,
394,
9,
267,
291,
14,
5538,
275,
16282,
8,
277,
14,
1238,
9,
398,
5935,
275,
788,
13186,
4782,
15,
3319,
17,
14,
4524,
297,
2116,
21526,
4782,
15,
3319,
18,
14,
4524,
297,
2116,
21526,
4782,
15,
9209,
3977,
14,
4524,
418,
267,
2248,
18882,
8,
4782,
12,
291,
9,
398,
291,
14,
11279,
11770,
8,
2390,
14,
3078,
8193,
51,
9,
339,
347,
641,
18882,
19757,
8,
277,
12,
5935,
23555,
304,
267,
291,
14,
3319,
275,
5935,
23555,
59,
16,
61,
267,
291,
14,
3319,
63,
273,
19622,
275,
5935,
23555,
59,
17,
61,
267,
291,
14,
9209,
3977,
275,
5935,
23555,
59,
18,
61,
398,
291,
14,
8709,
8,
277,
14,
2063,
12,
291,
14,
3333,
9,
398,
291,
14,
5538,
14,
928,
63,
5097,
8,
277,
9,
339,
347,
1050,
1378,
8,
277,
12,
12748,
304,
267,
12748,
14,
525,
8,
277,
9,
267,
291,
14,
2119,
275,
14316,
14,
362,
24677,
6105,
8,
277,
14,
21720,
1012,
267,
291,
14,
3039,
275,
14316,
14,
362,
24677,
8185,
8,
277,
14,
21720,
1012,
2378,
347,
663,
1197,
8,
277,
12,
1022,
12,
663,
304,
267,
14316,
14,
1430,
2398,
782,
2698,
8,
10462,
14,
1430,
29058,
2390,
1012,
267,
340,
1022,
508,
10448,
26,
288,
291,
14,
5538,
14,
498,
63,
384,
275,
663,
267,
916,
1022,
508,
6335,
26,
288,
291,
14,
5538,
14,
498,
63,
2110,
275,
663,
267,
916,
1022,
508,
6877,
26,
288,
291,
14,
5538,
14,
498,
63,
3039,
275,
663,
267,
916,
1022,
508,
10551,
26,
288,
291,
14,
5538,
14,
498,
63,
1019,
275,
663,
267,
916,
1022,
508,
4337,
26,
288,
291,
14,
5538,
14,
498,
63,
8935,
275,
663,
339,
347,
641,
1197,
3514,
8,
277,
12,
8904,
12,
790,
3034,
12,
9933,
275,
488,
304,
267,
291,
14,
409,
1197,
8,
498,
3034,
12,
715,
9,
339,
347,
641,
1197,
1721,
8,
277,
12,
8904,
12,
790,
3034,
12,
9933,
275,
488,
304,
267,
291,
14,
409,
1197,
8,
498,
3034,
12,
756,
9,
2378,
347,
5954,
63,
9209,
3977,
8,
277,
12,
465,
266,
3977,
304,
267,
291,
14,
2117,
2998,
342,
267,
291,
14,
5275,
8,
9209,
3977,
14,
88,
12,
465,
266,
3977,
14,
89,
9,
267,
291,
14,
12873,
8,
9209,
3977,
14,
4571,
9,
267,
291,
14,
3467,
8,
9209,
3977,
14,
3467,
12,
9209,
3977,
14,
3467,
9,
267,
291,
14,
5485,
3491,
8,
277,
14,
9209,
3977,
12,
24953,
11307,
12960,
998,
63,
4305,
15,
18,
395,
24953,
11307,
12960,
998,
63,
4305,
15,
18,
430,
267,
291,
14,
8011,
2998,
342,
339,
347,
5954,
63,
2782,
8,
277,
12,
1033,
357,
304,
267,
291,
14,
409,
12914,
6609,
8,
25041,
63,
7134,
9,
267,
291,
14,
4498,
8252,
8,
442,
8,
2782,
14,
88,
446,
413,
395,
1109,
8,
2782,
14,
89,
446,
413,
395,
650,
12,
650,
9,
5493,
347,
5954,
63,
3319,
8,
277,
12,
15924,
304,
267,
291,
14,
2117,
2998,
342,
267,
291,
14,
5275,
8,
3319,
14,
88,
12,
15924,
14,
89,
9,
267,
291,
14,
12873,
8,
3319,
14,
4571,
9,
267,
340,
291,
14,
5538,
14,
498,
63,
384,
26,
288,
6050,
275,
291,
14,
3319,
63,
273,
19622,
267,
587,
26,
288,
6050,
275,
291,
14,
3319,
267,
291,
14,
5485,
3491,
8,
4060,
12,
446,
1046,
12,
446,
713,
9,
267,
291,
14,
8011,
2998,
342,
199,
5493,
347,
5954,
8,
277,
304,
267,
291,
14,
409,
12914,
6609,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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except NameError:
pass
from collections import deque
from .constants import spaceCharacters
from .constants import entities
from .constants import asciiLetters, asciiUpper2Lower
from .constants import digits, hexDigits, EOF
from .constants import tokenTypes, tagTokenTypes
from .constants import replacementCharacters
from .inputstream import HTMLInputStream
from .trie import Trie
entitiesTrie = Trie(entities)
class HTMLTokenizer(object):
""" This class takes care of tokenizing HTML.
* self.currentToken
Holds the token that is currently being processed.
* self.state
Holds a reference to the method to be invoked... XXX
* self.stream
Points to HTMLInputStream object.
"""
def __init__(self, stream, encoding=None, parseMeta=True, useChardet=True,
lowercaseElementName=True, lowercaseAttrName=True, parser=None):
self.stream = HTMLInputStream(stream, encoding, parseMeta, useChardet)
self.parser = parser
# Perform case conversions?
self.lowercaseElementName = lowercaseElementName
self.lowercaseAttrName = lowercaseAttrName
# Setup the initial tokenizer state
self.escapeFlag = False
self.lastFourChars = []
self.state = self.dataState
self.escape = False
# The current token being created
self.currentToken = None
super(HTMLTokenizer, self).__init__()
def __iter__(self):
""" This is where the magic happens.
We do our usually processing through the states and when we have a token
to return we yield the token which pauses processing until the next token
is requested.
"""
self.tokenQueue = deque([])
# Start processing. When EOF is reached self.state will return False
# instead of True and the loop will terminate.
while self.state():
while self.stream.errors:
yield {"type": tokenTypes["ParseError"], "data": self.stream.errors.pop(0)}
while self.tokenQueue:
yield self.tokenQueue.popleft()
def consumeNumberEntity(self, isHex):
"""This function returns either U+FFFD or the character based on the
decimal or hexadecimal representation. It also discards ";" if present.
If not present self.tokenQueue.append({"type": tokenTypes["ParseError"]}) is invoked.
"""
allowed = digits
radix = 10
if isHex:
allowed = hexDigits
radix = 16
charStack = []
# Consume all the characters that are in range while making sure we
# don't hit an EOF.
c = self.stream.char()
while c in allowed and c is not EOF:
charStack.append(c)
c = self.stream.char()
# Convert the set of characters consumed to an int.
charAsInt = int("".join(charStack), radix)
# Certain characters get replaced with others
if charAsInt in replacementCharacters:
char = replacementCharacters[charAsInt]
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"illegal-codepoint-for-numeric-entity",
"datavars": {"charAsInt": charAsInt}})
elif ((0xD800 <= charAsInt <= 0xDFFF) or
(charAsInt > 0x10FFFF)):
char = "\uFFFD"
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"illegal-codepoint-for-numeric-entity",
"datavars": {"charAsInt": charAsInt}})
else:
# Should speed up this check somehow (e.g. move the set to a constant)
if ((0x0001 <= charAsInt <= 0x0008) or
(0x000E <= charAsInt <= 0x001F) or
(0x007F <= charAsInt <= 0x009F) or
(0xFDD0 <= charAsInt <= 0xFDEF) or
charAsInt in frozenset([0x000B, 0xFFFE, 0xFFFF, 0x1FFFE,
0x1FFFF, 0x2FFFE, 0x2FFFF, 0x3FFFE,
0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE,
0x5FFFF, 0x6FFFE, 0x6FFFF, 0x7FFFE,
0x7FFFF, 0x8FFFE, 0x8FFFF, 0x9FFFE,
0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE,
0xBFFFF, 0xCFFFE, 0xCFFFF, 0xDFFFE,
0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE,
0xFFFFF, 0x10FFFE, 0x10FFFF])):
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data":
"illegal-codepoint-for-numeric-entity",
"datavars": {"charAsInt": charAsInt}})
try:
# Try/except needed as UCS-2 Python builds' unichar only works
# within the BMP.
char = chr(charAsInt)
except ValueError:
v = charAsInt - 0x10000
char = chr(0xD800 | (v >> 10)) + chr(0xDC00 | (v & 0x3FF))
# Discard the ; if present. Otherwise, put it back on the queue and
# invoke parseError on parser.
if c != ";":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"numeric-entity-without-semicolon"})
self.stream.unget(c)
return char
def consumeEntity(self, allowedChar=None, fromAttribute=False):
# Initialise to the default output for when no entity is matched
output = "&"
charStack = [self.stream.char()]
if (charStack[0] in spaceCharacters or charStack[0] in (EOF, "<", "&")
or (allowedChar is not None and allowedChar == charStack[0])):
self.stream.unget(charStack[0])
elif charStack[0] == "#":
# Read the next character to see if it's hex or decimal
hex = False
charStack.append(self.stream.char())
if charStack[-1] in ("x", "X"):
hex = True
charStack.append(self.stream.char())
# charStack[-1] should be the first digit
if (hex and charStack[-1] in hexDigits) \
or (not hex and charStack[-1] in digits):
# At least one digit found, so consume the whole number
self.stream.unget(charStack[-1])
output = self.consumeNumberEntity(hex)
else:
# No digits found
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "expected-numeric-entity"})
self.stream.unget(charStack.pop())
output = "&" + "".join(charStack)
else:
# At this point in the process might have named entity. Entities
# are stored in the global variable "entities".
#
# Consume characters and compare to these to a substring of the
# entity names in the list until the substring no longer matches.
while (charStack[-1] is not EOF):
if not entitiesTrie.has_keys_with_prefix("".join(charStack)):
break
charStack.append(self.stream.char())
# At this point we have a string that starts with some characters
# that may match an entity
# Try to find the longest entity the string will match to take care
# of ¬i for instance.
try:
entityName = entitiesTrie.longest_prefix("".join(charStack[:-1]))
entityLength = len(entityName)
except KeyError:
entityName = None
if entityName is not None:
if entityName[-1] != ";":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"named-entity-without-semicolon"})
if (entityName[-1] != ";" and fromAttribute and
(charStack[entityLength] in asciiLetters or
charStack[entityLength] in digits or
charStack[entityLength] == "=")):
self.stream.unget(charStack.pop())
output = "&" + "".join(charStack)
else:
output = entities[entityName]
self.stream.unget(charStack.pop())
output += "".join(charStack[entityLength:])
else:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"expected-named-entity"})
self.stream.unget(charStack.pop())
output = "&" + "".join(charStack)
if fromAttribute:
self.currentToken["data"][-1][1] += output
else:
if output in spaceCharacters:
tokenType = "SpaceCharacters"
else:
tokenType = "Characters"
self.tokenQueue.append({"type": tokenTypes[tokenType], "data": output})
def processEntityInAttribute(self, allowedChar):
"""This method replaces the need for "entityInAttributeValueState".
"""
self.consumeEntity(allowedChar=allowedChar, fromAttribute=True)
def emitCurrentToken(self):
"""This method is a generic handler for emitting the tags. It also sets
the state to "data" because that's what's needed after a token has been
emitted.
"""
token = self.currentToken
# Add token to the queue to be yielded
if (token["type"] in tagTokenTypes):
if self.lowercaseElementName:
token["name"] = token["name"].translate(asciiUpper2Lower)
if token["type"] == tokenTypes["EndTag"]:
if token["data"]:
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "attributes-in-end-tag"})
if token["selfClosing"]:
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "self-closing-flag-on-end-tag"})
self.tokenQueue.append(token)
self.state = self.dataState
# Below are the various tokenizer states worked out.
def dataState(self):
data = self.stream.char()
if data == "&":
self.state = self.entityDataState
elif data == "<":
self.state = self.tagOpenState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.tokenQueue.append({"type": tokenTypes["Characters"],
"data": "\u0000"})
elif data is EOF:
# Tokenization ends.
return False
elif data in spaceCharacters:
# Directly after emitting a token you switch back to the "data
# state". At that point spaceCharacters are important so they are
# emitted separately.
self.tokenQueue.append({"type": tokenTypes["SpaceCharacters"], "data":
data + self.stream.charsUntil(spaceCharacters, True)})
# No need to update lastFourChars here, since the first space will
# have already been appended to lastFourChars and will have broken
# any <!-- or --> sequences
else:
chars = self.stream.charsUntil(("&", "<", "\u0000"))
self.tokenQueue.append({"type": tokenTypes["Characters"], "data":
data + chars})
return True
def entityDataState(self):
self.consumeEntity()
self.state = self.dataState
return True
def rcdataState(self):
data = self.stream.char()
if data == "&":
self.state = self.characterReferenceInRcdata
elif data == "<":
self.state = self.rcdataLessThanSignState
elif data == EOF:
# Tokenization ends.
return False
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.tokenQueue.append({"type": tokenTypes["Characters"],
"data": "\uFFFD"})
elif data in spaceCharacters:
# Directly after emitting a token you switch back to the "data
# state". At that point spaceCharacters are important so they are
# emitted separately.
self.tokenQueue.append({"type": tokenTypes["SpaceCharacters"], "data":
data + self.stream.charsUntil(spaceCharacters, True)})
# No need to update lastFourChars here, since the first space will
# have already been appended to lastFourChars and will have broken
# any <!-- or --> sequences
else:
chars = self.stream.charsUntil(("&", "<", "\u0000"))
self.tokenQueue.append({"type": tokenTypes["Characters"], "data":
data + chars})
return True
def characterReferenceInRcdata(self):
self.consumeEntity()
self.state = self.rcdataState
return True
def rawtextState(self):
data = self.stream.char()
if data == "<":
self.state = self.rawtextLessThanSignState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.tokenQueue.append({"type": tokenTypes["Characters"],
"data": "\uFFFD"})
elif data == EOF:
# Tokenization ends.
return False
else:
chars = self.stream.charsUntil(("<", "\u0000"))
self.tokenQueue.append({"type": tokenTypes["Characters"], "data":
data + chars})
return True
def scriptDataState(self):
data = self.stream.char()
if data == "<":
self.state = self.scriptDataLessThanSignState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.tokenQueue.append({"type": tokenTypes["Characters"],
"data": "\uFFFD"})
elif data == EOF:
# Tokenization ends.
return False
else:
chars = self.stream.charsUntil(("<", "\u0000"))
self.tokenQueue.append({"type": tokenTypes["Characters"], "data":
data + chars})
return True
def plaintextState(self):
data = self.stream.char()
if data == EOF:
# Tokenization ends.
return False
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.tokenQueue.append({"type": tokenTypes["Characters"],
"data": "\uFFFD"})
else:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data":
data + self.stream.charsUntil("\u0000")})
return True
def tagOpenState(self):
data = self.stream.char()
if data == "!":
self.state = self.markupDeclarationOpenState
elif data == "/":
self.state = self.closeTagOpenState
elif data in asciiLetters:
self.currentToken = {"type": tokenTypes["StartTag"],
"name": data, "data": [],
"selfClosing": False,
"selfClosingAcknowledged": False}
self.state = self.tagNameState
elif data == ">":
# XXX In theory it could be something besides a tag name. But
# do we really care?
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"expected-tag-name-but-got-right-bracket"})
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "<>"})
self.state = self.dataState
elif data == "?":
# XXX In theory it could be something besides a tag name. But
# do we really care?
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"expected-tag-name-but-got-question-mark"})
self.stream.unget(data)
self.state = self.bogusCommentState
else:
# XXX
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"expected-tag-name"})
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "<"})
self.stream.unget(data)
self.state = self.dataState
return True
def closeTagOpenState(self):
data = self.stream.char()
if data in asciiLetters:
self.currentToken = {"type": tokenTypes["EndTag"], "name": data,
"data": [], "selfClosing": False}
self.state = self.tagNameState
elif data == ">":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"expected-closing-tag-but-got-right-bracket"})
self.state = self.dataState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"expected-closing-tag-but-got-eof"})
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "</"})
self.state = self.dataState
else:
# XXX data can be _'_...
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"expected-closing-tag-but-got-char",
"datavars": {"data": data}})
self.stream.unget(data)
self.state = self.bogusCommentState
return True
def tagNameState(self):
data = self.stream.char()
if data in spaceCharacters:
self.state = self.beforeAttributeNameState
elif data == ">":
self.emitCurrentToken()
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-tag-name"})
self.state = self.dataState
elif data == "/":
self.state = self.selfClosingStartTagState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["name"] += "\uFFFD"
else:
self.currentToken["name"] += data
# (Don't use charsUntil here, because tag names are
# very short and it's faster to not do anything fancy)
return True
def rcdataLessThanSignState(self):
data = self.stream.char()
if data == "/":
self.temporaryBuffer = ""
self.state = self.rcdataEndTagOpenState
else:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "<"})
self.stream.unget(data)
self.state = self.rcdataState
return True
def rcdataEndTagOpenState(self):
data = self.stream.char()
if data in asciiLetters:
self.temporaryBuffer += data
self.state = self.rcdataEndTagNameState
else:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "</"})
self.stream.unget(data)
self.state = self.rcdataState
return True
def rcdataEndTagNameState(self):
appropriate = self.currentToken and self.currentToken["name"].lower() == self.temporaryBuffer.lower()
data = self.stream.char()
if data in spaceCharacters and appropriate:
self.currentToken = {"type": tokenTypes["EndTag"],
"name": self.temporaryBuffer,
"data": [], "selfClosing": False}
self.state = self.beforeAttributeNameState
elif data == "/" and appropriate:
self.currentToken = {"type": tokenTypes["EndTag"],
"name": self.temporaryBuffer,
"data": [], "selfClosing": False}
self.state = self.selfClosingStartTagState
elif data == ">" and appropriate:
self.currentToken = {"type": tokenTypes["EndTag"],
"name": self.temporaryBuffer,
"data": [], "selfClosing": False}
self.emitCurrentToken()
self.state = self.dataState
elif data in asciiLetters:
self.temporaryBuffer += data
else:
self.tokenQueue.append({"type": tokenTypes["Characters"],
"data": "</" + self.temporaryBuffer})
self.stream.unget(data)
self.state = self.rcdataState
return True
def rawtextLessThanSignState(self):
data = self.stream.char()
if data == "/":
self.temporaryBuffer = ""
self.state = self.rawtextEndTagOpenState
else:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "<"})
self.stream.unget(data)
self.state = self.rawtextState
return True
def rawtextEndTagOpenState(self):
data = self.stream.char()
if data in asciiLetters:
self.temporaryBuffer += data
self.state = self.rawtextEndTagNameState
else:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "</"})
self.stream.unget(data)
self.state = self.rawtextState
return True
def rawtextEndTagNameState(self):
appropriate = self.currentToken and self.currentToken["name"].lower() == self.temporaryBuffer.lower()
data = self.stream.char()
if data in spaceCharacters and appropriate:
self.currentToken = {"type": tokenTypes["EndTag"],
"name": self.temporaryBuffer,
"data": [], "selfClosing": False}
self.state = self.beforeAttributeNameState
elif data == "/" and appropriate:
self.currentToken = {"type": tokenTypes["EndTag"],
"name": self.temporaryBuffer,
"data": [], "selfClosing": False}
self.state = self.selfClosingStartTagState
elif data == ">" and appropriate:
self.currentToken = {"type": tokenTypes["EndTag"],
"name": self.temporaryBuffer,
"data": [], "selfClosing": False}
self.emitCurrentToken()
self.state = self.dataState
elif data in asciiLetters:
self.temporaryBuffer += data
else:
self.tokenQueue.append({"type": tokenTypes["Characters"],
"data": "</" + self.temporaryBuffer})
self.stream.unget(data)
self.state = self.rawtextState
return True
def scriptDataLessThanSignState(self):
data = self.stream.char()
if data == "/":
self.temporaryBuffer = ""
self.state = self.scriptDataEndTagOpenState
elif data == "!":
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "<!"})
self.state = self.scriptDataEscapeStartState
else:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "<"})
self.stream.unget(data)
self.state = self.scriptDataState
return True
def scriptDataEndTagOpenState(self):
data = self.stream.char()
if data in asciiLetters:
self.temporaryBuffer += data
self.state = self.scriptDataEndTagNameState
else:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "</"})
self.stream.unget(data)
self.state = self.scriptDataState
return True
def scriptDataEndTagNameState(self):
appropriate = self.currentToken and self.currentToken["name"].lower() == self.temporaryBuffer.lower()
data = self.stream.char()
if data in spaceCharacters and appropriate:
self.currentToken = {"type": tokenTypes["EndTag"],
"name": self.temporaryBuffer,
"data": [], "selfClosing": False}
self.state = self.beforeAttributeNameState
elif data == "/" and appropriate:
self.currentToken = {"type": tokenTypes["EndTag"],
"name": self.temporaryBuffer,
"data": [], "selfClosing": False}
self.state = self.selfClosingStartTagState
elif data == ">" and appropriate:
self.currentToken = {"type": tokenTypes["EndTag"],
"name": self.temporaryBuffer,
"data": [], "selfClosing": False}
self.emitCurrentToken()
self.state = self.dataState
elif data in asciiLetters:
self.temporaryBuffer += data
else:
self.tokenQueue.append({"type": tokenTypes["Characters"],
"data": "</" + self.temporaryBuffer})
self.stream.unget(data)
self.state = self.scriptDataState
return True
def scriptDataEscapeStartState(self):
data = self.stream.char()
if data == "-":
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "-"})
self.state = self.scriptDataEscapeStartDashState
else:
self.stream.unget(data)
self.state = self.scriptDataState
return True
def scriptDataEscapeStartDashState(self):
data = self.stream.char()
if data == "-":
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "-"})
self.state = self.scriptDataEscapedDashDashState
else:
self.stream.unget(data)
self.state = self.scriptDataState
return True
def scriptDataEscapedState(self):
data = self.stream.char()
if data == "-":
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "-"})
self.state = self.scriptDataEscapedDashState
elif data == "<":
self.state = self.scriptDataEscapedLessThanSignState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.tokenQueue.append({"type": tokenTypes["Characters"],
"data": "\uFFFD"})
elif data == EOF:
self.state = self.dataState
else:
chars = self.stream.charsUntil(("<", "-", "\u0000"))
self.tokenQueue.append({"type": tokenTypes["Characters"], "data":
data + chars})
return True
def scriptDataEscapedDashState(self):
data = self.stream.char()
if data == "-":
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "-"})
self.state = self.scriptDataEscapedDashDashState
elif data == "<":
self.state = self.scriptDataEscapedLessThanSignState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.tokenQueue.append({"type": tokenTypes["Characters"],
"data": "\uFFFD"})
self.state = self.scriptDataEscapedState
elif data == EOF:
self.state = self.dataState
else:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": data})
self.state = self.scriptDataEscapedState
return True
def scriptDataEscapedDashDashState(self):
data = self.stream.char()
if data == "-":
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "-"})
elif data == "<":
self.state = self.scriptDataEscapedLessThanSignState
elif data == ">":
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": ">"})
self.state = self.scriptDataState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.tokenQueue.append({"type": tokenTypes["Characters"],
"data": "\uFFFD"})
self.state = self.scriptDataEscapedState
elif data == EOF:
self.state = self.dataState
else:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": data})
self.state = self.scriptDataEscapedState
return True
def scriptDataEscapedLessThanSignState(self):
data = self.stream.char()
if data == "/":
self.temporaryBuffer = ""
self.state = self.scriptDataEscapedEndTagOpenState
elif data in asciiLetters:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "<" + data})
self.temporaryBuffer = data
self.state = self.scriptDataDoubleEscapeStartState
else:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "<"})
self.stream.unget(data)
self.state = self.scriptDataEscapedState
return True
def scriptDataEscapedEndTagOpenState(self):
data = self.stream.char()
if data in asciiLetters:
self.temporaryBuffer = data
self.state = self.scriptDataEscapedEndTagNameState
else:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "</"})
self.stream.unget(data)
self.state = self.scriptDataEscapedState
return True
def scriptDataEscapedEndTagNameState(self):
appropriate = self.currentToken and self.currentToken["name"].lower() == self.temporaryBuffer.lower()
data = self.stream.char()
if data in spaceCharacters and appropriate:
self.currentToken = {"type": tokenTypes["EndTag"],
"name": self.temporaryBuffer,
"data": [], "selfClosing": False}
self.state = self.beforeAttributeNameState
elif data == "/" and appropriate:
self.currentToken = {"type": tokenTypes["EndTag"],
"name": self.temporaryBuffer,
"data": [], "selfClosing": False}
self.state = self.selfClosingStartTagState
elif data == ">" and appropriate:
self.currentToken = {"type": tokenTypes["EndTag"],
"name": self.temporaryBuffer,
"data": [], "selfClosing": False}
self.emitCurrentToken()
self.state = self.dataState
elif data in asciiLetters:
self.temporaryBuffer += data
else:
self.tokenQueue.append({"type": tokenTypes["Characters"],
"data": "</" + self.temporaryBuffer})
self.stream.unget(data)
self.state = self.scriptDataEscapedState
return True
def scriptDataDoubleEscapeStartState(self):
data = self.stream.char()
if data in (spaceCharacters | frozenset(("/", ">"))):
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": data})
if self.temporaryBuffer.lower() == "script":
self.state = self.scriptDataDoubleEscapedState
else:
self.state = self.scriptDataEscapedState
elif data in asciiLetters:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": data})
self.temporaryBuffer += data
else:
self.stream.unget(data)
self.state = self.scriptDataEscapedState
return True
def scriptDataDoubleEscapedState(self):
data = self.stream.char()
if data == "-":
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "-"})
self.state = self.scriptDataDoubleEscapedDashState
elif data == "<":
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "<"})
self.state = self.scriptDataDoubleEscapedLessThanSignState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.tokenQueue.append({"type": tokenTypes["Characters"],
"data": "\uFFFD"})
elif data == EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-script-in-script"})
self.state = self.dataState
else:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": data})
return True
def scriptDataDoubleEscapedDashState(self):
data = self.stream.char()
if data == "-":
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "-"})
self.state = self.scriptDataDoubleEscapedDashDashState
elif data == "<":
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "<"})
self.state = self.scriptDataDoubleEscapedLessThanSignState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.tokenQueue.append({"type": tokenTypes["Characters"],
"data": "\uFFFD"})
self.state = self.scriptDataDoubleEscapedState
elif data == EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-script-in-script"})
self.state = self.dataState
else:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": data})
self.state = self.scriptDataDoubleEscapedState
return True
def scriptDataDoubleEscapedDashDashState(self):
data = self.stream.char()
if data == "-":
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "-"})
elif data == "<":
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "<"})
self.state = self.scriptDataDoubleEscapedLessThanSignState
elif data == ">":
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": ">"})
self.state = self.scriptDataState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.tokenQueue.append({"type": tokenTypes["Characters"],
"data": "\uFFFD"})
self.state = self.scriptDataDoubleEscapedState
elif data == EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-script-in-script"})
self.state = self.dataState
else:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": data})
self.state = self.scriptDataDoubleEscapedState
return True
def scriptDataDoubleEscapedLessThanSignState(self):
data = self.stream.char()
if data == "/":
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": "/"})
self.temporaryBuffer = ""
self.state = self.scriptDataDoubleEscapeEndState
else:
self.stream.unget(data)
self.state = self.scriptDataDoubleEscapedState
return True
def scriptDataDoubleEscapeEndState(self):
data = self.stream.char()
if data in (spaceCharacters | frozenset(("/", ">"))):
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": data})
if self.temporaryBuffer.lower() == "script":
self.state = self.scriptDataEscapedState
else:
self.state = self.scriptDataDoubleEscapedState
elif data in asciiLetters:
self.tokenQueue.append({"type": tokenTypes["Characters"], "data": data})
self.temporaryBuffer += data
else:
self.stream.unget(data)
self.state = self.scriptDataDoubleEscapedState
return True
def beforeAttributeNameState(self):
data = self.stream.char()
if data in spaceCharacters:
self.stream.charsUntil(spaceCharacters, True)
elif data in asciiLetters:
self.currentToken["data"].append([data, ""])
self.state = self.attributeNameState
elif data == ">":
self.emitCurrentToken()
elif data == "/":
self.state = self.selfClosingStartTagState
elif data in ("'", '"', "=", "<"):
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"invalid-character-in-attribute-name"})
self.currentToken["data"].append([data, ""])
self.state = self.attributeNameState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["data"].append(["\uFFFD", ""])
self.state = self.attributeNameState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"expected-attribute-name-but-got-eof"})
self.state = self.dataState
else:
self.currentToken["data"].append([data, ""])
self.state = self.attributeNameState
return True
def attributeNameState(self):
data = self.stream.char()
leavingThisState = True
emitToken = False
if data == "=":
self.state = self.beforeAttributeValueState
elif data in asciiLetters:
self.currentToken["data"][-1][0] += data +\
self.stream.charsUntil(asciiLetters, True)
leavingThisState = False
elif data == ">":
# XXX If we emit here the attributes are converted to a dict
# without being checked and when the code below runs we error
# because data is a dict not a list
emitToken = True
elif data in spaceCharacters:
self.state = self.afterAttributeNameState
elif data == "/":
self.state = self.selfClosingStartTagState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["data"][-1][0] += "\uFFFD"
leavingThisState = False
elif data in ("'", '"', "<"):
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data":
"invalid-character-in-attribute-name"})
self.currentToken["data"][-1][0] += data
leavingThisState = False
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "eof-in-attribute-name"})
self.state = self.dataState
else:
self.currentToken["data"][-1][0] += data
leavingThisState = False
if leavingThisState:
# Attributes are not dropped at this stage. That happens when the
# start tag token is emitted so values can still be safely appended
# to attributes, but we do want to report the parse error in time.
if self.lowercaseAttrName:
self.currentToken["data"][-1][0] = (
self.currentToken["data"][-1][0].translate(asciiUpper2Lower))
for name, value in self.currentToken["data"][:-1]:
if self.currentToken["data"][-1][0] == name:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"duplicate-attribute"})
break
# XXX Fix for above XXX
if emitToken:
self.emitCurrentToken()
return True
def afterAttributeNameState(self):
data = self.stream.char()
if data in spaceCharacters:
self.stream.charsUntil(spaceCharacters, True)
elif data == "=":
self.state = self.beforeAttributeValueState
elif data == ">":
self.emitCurrentToken()
elif data in asciiLetters:
self.currentToken["data"].append([data, ""])
self.state = self.attributeNameState
elif data == "/":
self.state = self.selfClosingStartTagState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["data"].append(["\uFFFD", ""])
self.state = self.attributeNameState
elif data in ("'", '"', "<"):
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"invalid-character-after-attribute-name"})
self.currentToken["data"].append([data, ""])
self.state = self.attributeNameState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"expected-end-of-tag-but-got-eof"})
self.state = self.dataState
else:
self.currentToken["data"].append([data, ""])
self.state = self.attributeNameState
return True
def beforeAttributeValueState(self):
data = self.stream.char()
if data in spaceCharacters:
self.stream.charsUntil(spaceCharacters, True)
elif data == "\"":
self.state = self.attributeValueDoubleQuotedState
elif data == "&":
self.state = self.attributeValueUnQuotedState
self.stream.unget(data)
elif data == "'":
self.state = self.attributeValueSingleQuotedState
elif data == ">":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"expected-attribute-value-but-got-right-bracket"})
self.emitCurrentToken()
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["data"][-1][1] += "\uFFFD"
self.state = self.attributeValueUnQuotedState
elif data in ("=", "<", "`"):
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"equals-in-unquoted-attribute-value"})
self.currentToken["data"][-1][1] += data
self.state = self.attributeValueUnQuotedState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"expected-attribute-value-but-got-eof"})
self.state = self.dataState
else:
self.currentToken["data"][-1][1] += data
self.state = self.attributeValueUnQuotedState
return True
def attributeValueDoubleQuotedState(self):
data = self.stream.char()
if data == "\"":
self.state = self.afterAttributeValueState
elif data == "&":
self.processEntityInAttribute('"')
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["data"][-1][1] += "\uFFFD"
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-attribute-value-double-quote"})
self.state = self.dataState
else:
self.currentToken["data"][-1][1] += data +\
self.stream.charsUntil(("\"", "&", "\u0000"))
return True
def attributeValueSingleQuotedState(self):
data = self.stream.char()
if data == "'":
self.state = self.afterAttributeValueState
elif data == "&":
self.processEntityInAttribute("'")
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["data"][-1][1] += "\uFFFD"
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-attribute-value-single-quote"})
self.state = self.dataState
else:
self.currentToken["data"][-1][1] += data +\
self.stream.charsUntil(("'", "&", "\u0000"))
return True
def attributeValueUnQuotedState(self):
data = self.stream.char()
if data in spaceCharacters:
self.state = self.beforeAttributeNameState
elif data == "&":
self.processEntityInAttribute(">")
elif data == ">":
self.emitCurrentToken()
elif data in ('"', "'", "=", "<", "`"):
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-character-in-unquoted-attribute-value"})
self.currentToken["data"][-1][1] += data
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["data"][-1][1] += "\uFFFD"
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-attribute-value-no-quotes"})
self.state = self.dataState
else:
self.currentToken["data"][-1][1] += data + self.stream.charsUntil(
frozenset(("&", ">", '"', "'", "=", "<", "`", "\u0000")) | spaceCharacters)
return True
def afterAttributeValueState(self):
data = self.stream.char()
if data in spaceCharacters:
self.state = self.beforeAttributeNameState
elif data == ">":
self.emitCurrentToken()
elif data == "/":
self.state = self.selfClosingStartTagState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-EOF-after-attribute-value"})
self.stream.unget(data)
self.state = self.dataState
else:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-character-after-attribute-value"})
self.stream.unget(data)
self.state = self.beforeAttributeNameState
return True
def selfClosingStartTagState(self):
data = self.stream.char()
if data == ">":
self.currentToken["selfClosing"] = True
self.emitCurrentToken()
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data":
"unexpected-EOF-after-solidus-in-tag"})
self.stream.unget(data)
self.state = self.dataState
else:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-character-after-solidus-in-tag"})
self.stream.unget(data)
self.state = self.beforeAttributeNameState
return True
def bogusCommentState(self):
# Make a new comment token and give it as value all the characters
# until the first > or EOF (charsUntil checks for EOF automatically)
# and emit it.
data = self.stream.charsUntil(">")
data = data.replace("\u0000", "\uFFFD")
self.tokenQueue.append(
{"type": tokenTypes["Comment"], "data": data})
# Eat the character directly after the bogus comment which is either a
# ">" or an EOF.
self.stream.char()
self.state = self.dataState
return True
def markupDeclarationOpenState(self):
charStack = [self.stream.char()]
if charStack[-1] == "-":
charStack.append(self.stream.char())
if charStack[-1] == "-":
self.currentToken = {"type": tokenTypes["Comment"], "data": ""}
self.state = self.commentStartState
return True
elif charStack[-1] in ('d', 'D'):
matched = True
for expected in (('o', 'O'), ('c', 'C'), ('t', 'T'),
('y', 'Y'), ('p', 'P'), ('e', 'E')):
charStack.append(self.stream.char())
if charStack[-1] not in expected:
matched = False
break
if matched:
self.currentToken = {"type": tokenTypes["Doctype"],
"name": "",
"publicId": None, "systemId": None,
"correct": True}
self.state = self.doctypeState
return True
elif (charStack[-1] == "[" and
self.parser is not None and
self.parser.tree.openElements and
self.parser.tree.openElements[-1].namespace != self.parser.tree.defaultNamespace):
matched = True
for expected in ["C", "D", "A", "T", "A", "["]:
charStack.append(self.stream.char())
if charStack[-1] != expected:
matched = False
break
if matched:
self.state = self.cdataSectionState
return True
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"expected-dashes-or-doctype"})
while charStack:
self.stream.unget(charStack.pop())
self.state = self.bogusCommentState
return True
def commentStartState(self):
data = self.stream.char()
if data == "-":
self.state = self.commentStartDashState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["data"] += "\uFFFD"
elif data == ">":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"incorrect-comment"})
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-comment"})
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.currentToken["data"] += data
self.state = self.commentState
return True
def commentStartDashState(self):
data = self.stream.char()
if data == "-":
self.state = self.commentEndState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["data"] += "-\uFFFD"
elif data == ">":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"incorrect-comment"})
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-comment"})
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.currentToken["data"] += "-" + data
self.state = self.commentState
return True
def commentState(self):
data = self.stream.char()
if data == "-":
self.state = self.commentEndDashState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["data"] += "\uFFFD"
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "eof-in-comment"})
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.currentToken["data"] += data + \
self.stream.charsUntil(("-", "\u0000"))
return True
def commentEndDashState(self):
data = self.stream.char()
if data == "-":
self.state = self.commentEndState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["data"] += "-\uFFFD"
self.state = self.commentState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-comment-end-dash"})
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.currentToken["data"] += "-" + data
self.state = self.commentState
return True
def commentEndState(self):
data = self.stream.char()
if data == ">":
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["data"] += "--\uFFFD"
self.state = self.commentState
elif data == "!":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-bang-after-double-dash-in-comment"})
self.state = self.commentEndBangState
elif data == "-":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-dash-after-double-dash-in-comment"})
self.currentToken["data"] += data
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-comment-double-dash"})
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
# XXX
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-char-in-comment"})
self.currentToken["data"] += "--" + data
self.state = self.commentState
return True
def commentEndBangState(self):
data = self.stream.char()
if data == ">":
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data == "-":
self.currentToken["data"] += "--!"
self.state = self.commentEndDashState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["data"] += "--!\uFFFD"
self.state = self.commentState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-comment-end-bang-state"})
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.currentToken["data"] += "--!" + data
self.state = self.commentState
return True
def doctypeState(self):
data = self.stream.char()
if data in spaceCharacters:
self.state = self.beforeDoctypeNameState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"expected-doctype-name-but-got-eof"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"need-space-after-doctype"})
self.stream.unget(data)
self.state = self.beforeDoctypeNameState
return True
def beforeDoctypeNameState(self):
data = self.stream.char()
if data in spaceCharacters:
pass
elif data == ">":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"expected-doctype-name-but-got-right-bracket"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["name"] = "\uFFFD"
self.state = self.doctypeNameState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"expected-doctype-name-but-got-eof"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.currentToken["name"] = data
self.state = self.doctypeNameState
return True
def doctypeNameState(self):
data = self.stream.char()
if data in spaceCharacters:
self.currentToken["name"] = self.currentToken["name"].translate(asciiUpper2Lower)
self.state = self.afterDoctypeNameState
elif data == ">":
self.currentToken["name"] = self.currentToken["name"].translate(asciiUpper2Lower)
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["name"] += "\uFFFD"
self.state = self.doctypeNameState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-doctype-name"})
self.currentToken["correct"] = False
self.currentToken["name"] = self.currentToken["name"].translate(asciiUpper2Lower)
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.currentToken["name"] += data
return True
def afterDoctypeNameState(self):
data = self.stream.char()
if data in spaceCharacters:
pass
elif data == ">":
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data is EOF:
self.currentToken["correct"] = False
self.stream.unget(data)
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-doctype"})
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
if data in ("p", "P"):
matched = True
for expected in (("u", "U"), ("b", "B"), ("l", "L"),
("i", "I"), ("c", "C")):
data = self.stream.char()
if data not in expected:
matched = False
break
if matched:
self.state = self.afterDoctypePublicKeywordState
return True
elif data in ("s", "S"):
matched = True
for expected in (("y", "Y"), ("s", "S"), ("t", "T"),
("e", "E"), ("m", "M")):
data = self.stream.char()
if data not in expected:
matched = False
break
if matched:
self.state = self.afterDoctypeSystemKeywordState
return True
# All the characters read before the current 'data' will be
# [a-zA-Z], so they're garbage in the bogus doctype and can be
# discarded; only the latest character might be '>' or EOF
# and needs to be ungetted
self.stream.unget(data)
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"expected-space-or-right-bracket-in-doctype", "datavars":
{"data": data}})
self.currentToken["correct"] = False
self.state = self.bogusDoctypeState
return True
def afterDoctypePublicKeywordState(self):
data = self.stream.char()
if data in spaceCharacters:
self.state = self.beforeDoctypePublicIdentifierState
elif data in ("'", '"'):
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-char-in-doctype"})
self.stream.unget(data)
self.state = self.beforeDoctypePublicIdentifierState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.stream.unget(data)
self.state = self.beforeDoctypePublicIdentifierState
return True
def beforeDoctypePublicIdentifierState(self):
data = self.stream.char()
if data in spaceCharacters:
pass
elif data == "\"":
self.currentToken["publicId"] = ""
self.state = self.doctypePublicIdentifierDoubleQuotedState
elif data == "'":
self.currentToken["publicId"] = ""
self.state = self.doctypePublicIdentifierSingleQuotedState
elif data == ">":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-end-of-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-char-in-doctype"})
self.currentToken["correct"] = False
self.state = self.bogusDoctypeState
return True
def doctypePublicIdentifierDoubleQuotedState(self):
data = self.stream.char()
if data == "\"":
self.state = self.afterDoctypePublicIdentifierState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["publicId"] += "\uFFFD"
elif data == ">":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-end-of-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.currentToken["publicId"] += data
return True
def doctypePublicIdentifierSingleQuotedState(self):
data = self.stream.char()
if data == "'":
self.state = self.afterDoctypePublicIdentifierState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["publicId"] += "\uFFFD"
elif data == ">":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-end-of-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.currentToken["publicId"] += data
return True
def afterDoctypePublicIdentifierState(self):
data = self.stream.char()
if data in spaceCharacters:
self.state = self.betweenDoctypePublicAndSystemIdentifiersState
elif data == ">":
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data == '"':
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-char-in-doctype"})
self.currentToken["systemId"] = ""
self.state = self.doctypeSystemIdentifierDoubleQuotedState
elif data == "'":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-char-in-doctype"})
self.currentToken["systemId"] = ""
self.state = self.doctypeSystemIdentifierSingleQuotedState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-char-in-doctype"})
self.currentToken["correct"] = False
self.state = self.bogusDoctypeState
return True
def betweenDoctypePublicAndSystemIdentifiersState(self):
data = self.stream.char()
if data in spaceCharacters:
pass
elif data == ">":
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data == '"':
self.currentToken["systemId"] = ""
self.state = self.doctypeSystemIdentifierDoubleQuotedState
elif data == "'":
self.currentToken["systemId"] = ""
self.state = self.doctypeSystemIdentifierSingleQuotedState
elif data == EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-char-in-doctype"})
self.currentToken["correct"] = False
self.state = self.bogusDoctypeState
return True
def afterDoctypeSystemKeywordState(self):
data = self.stream.char()
if data in spaceCharacters:
self.state = self.beforeDoctypeSystemIdentifierState
elif data in ("'", '"'):
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-char-in-doctype"})
self.stream.unget(data)
self.state = self.beforeDoctypeSystemIdentifierState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.stream.unget(data)
self.state = self.beforeDoctypeSystemIdentifierState
return True
def beforeDoctypeSystemIdentifierState(self):
data = self.stream.char()
if data in spaceCharacters:
pass
elif data == "\"":
self.currentToken["systemId"] = ""
self.state = self.doctypeSystemIdentifierDoubleQuotedState
elif data == "'":
self.currentToken["systemId"] = ""
self.state = self.doctypeSystemIdentifierSingleQuotedState
elif data == ">":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-char-in-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-char-in-doctype"})
self.currentToken["correct"] = False
self.state = self.bogusDoctypeState
return True
def doctypeSystemIdentifierDoubleQuotedState(self):
data = self.stream.char()
if data == "\"":
self.state = self.afterDoctypeSystemIdentifierState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["systemId"] += "\uFFFD"
elif data == ">":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-end-of-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.currentToken["systemId"] += data
return True
def doctypeSystemIdentifierSingleQuotedState(self):
data = self.stream.char()
if data == "'":
self.state = self.afterDoctypeSystemIdentifierState
elif data == "\u0000":
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
self.currentToken["systemId"] += "\uFFFD"
elif data == ">":
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-end-of-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.currentToken["systemId"] += data
return True
def afterDoctypeSystemIdentifierState(self):
data = self.stream.char()
if data in spaceCharacters:
pass
elif data == ">":
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data is EOF:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"eof-in-doctype"})
self.currentToken["correct"] = False
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
self.tokenQueue.append({"type": tokenTypes["ParseError"], "data":
"unexpected-char-in-doctype"})
self.state = self.bogusDoctypeState
return True
def bogusDoctypeState(self):
data = self.stream.char()
if data == ">":
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
elif data is EOF:
# XXX EMIT
self.stream.unget(data)
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
pass
return True
def cdataSectionState(self):
data = []
while True:
data.append(self.stream.charsUntil("]"))
data.append(self.stream.charsUntil(">"))
char = self.stream.char()
if char == EOF:
break
else:
assert char == ">"
if data[-1][-2:] == "]]":
data[-1] = data[-1][:-2]
break
else:
data.append(char)
data = "".join(data)
# Deal with null here rather than in the parser
nullCount = data.count("\u0000")
if nullCount > 0:
for i in range(nullCount):
self.tokenQueue.append({"type": tokenTypes["ParseError"],
"data": "invalid-codepoint"})
data = data.replace("\u0000", "\uFFFD")
if data:
self.tokenQueue.append({"type": tokenTypes["Characters"],
"data": data})
self.state = self.dataState
return True
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
893,
26,
272,
8678,
275,
17742,
327,
27510,
24,
26,
8151,
199,
2590,
12746,
26,
272,
986,
199,
199,
504,
5055,
492,
15782,
199,
199,
504,
1275,
5559,
492,
25431,
199,
504,
1275,
5559,
492,
9045,
199,
504,
1275,
5559,
492,
13294,
28760,
12,
13294,
19316,
18,
17846,
199,
504,
1275,
5559,
492,
7576,
12,
6318,
29371,
12,
9027,
199,
504,
1275,
5559,
492,
10042,
12,
1947,
3264,
4100,
199,
504,
1275,
5559,
492,
8343,
9272,
199,
199,
504,
1275,
1210,
1745,
492,
4163,
27611,
199,
199,
504,
1275,
599,
69,
492,
377,
11317,
199,
199,
8327,
6948,
69,
275,
377,
11317,
8,
8327,
9,
421,
199,
533,
4163,
21782,
8,
785,
304,
272,
408,
961,
1021,
6181,
10296,
402,
1526,
9147,
4163,
14,
339,
627,
291,
14,
11631,
489,
869,
8250,
314,
1526,
626,
365,
5544,
3769,
7686,
14,
339,
627,
291,
14,
929,
489,
869,
8250,
282,
3659,
370,
314,
1083,
370,
506,
10302,
1396,
5787,
339,
627,
291,
14,
1745,
489,
32598,
370,
4163,
27611,
909,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2547,
12,
2644,
29,
403,
12,
2198,
3396,
29,
549,
12,
675,
1610,
9886,
29,
549,
12,
326,
12141,
2162,
985,
29,
549,
12,
12141,
7144,
985,
29,
549,
12,
1798,
29,
403,
304,
398,
291,
14,
1745,
275,
4163,
27611,
8,
1745,
12,
2644,
12,
2198,
3396,
12,
675,
1610,
9886,
9,
267,
291,
14,
2087,
275,
1798,
398,
327,
14795,
1930,
24796,
31,
267,
291,
14,
21636,
2162,
985,
275,
12141,
2162,
985,
267,
291,
14,
21636,
7144,
985,
275,
12141,
7144,
985,
398,
327,
12439,
314,
2536,
14803,
1174,
267,
291,
14,
3765,
5318,
275,
756,
267,
291,
14,
2019,
24766,
11229,
275,
942,
267,
291,
14,
929,
275,
291,
14,
18694,
267,
291,
14,
3765,
275,
756,
398,
327,
710,
1453,
1526,
3769,
2737,
267,
291,
14,
11631,
275,
488,
267,
1613,
8,
4943,
21782,
12,
291,
2843,
826,
4533,
339,
347,
636,
1661,
721,
277,
304,
267,
408,
961,
365,
2382,
314,
10628,
10986,
14,
398,
2136,
886,
4154,
9987,
6661,
4012,
314,
6363,
436,
1380,
781,
1172,
282,
1526,
267,
370,
372,
781,
1995,
314,
1526,
1314,
691,
5589,
6661,
5133,
314,
2163,
1526,
267,
365,
5839,
14,
267,
408,
267,
291,
14,
9690,
275,
15782,
4157,
267,
327,
7707,
6661,
14,
3979,
9027,
365,
13075,
291,
14,
929,
911,
372,
756,
267,
327,
3140,
402,
715,
436,
314,
4438,
911,
15095,
14,
267,
1830,
291,
14,
929,
837,
288,
1830,
291,
14,
1745,
14,
2550,
26,
355,
1995,
2420,
466,
582,
10042,
905,
9123,
2255,
298,
576,
582,
291,
14,
1745,
14,
2550,
14,
1935,
8,
16,
6769,
288,
1830,
291,
14,
9690,
26,
355,
1995,
291,
14,
9690,
14,
25704,
342,
339,
347,
9451,
3259,
7302,
8,
277,
12,
365,
10373,
304,
267,
408,
2765,
805,
2529,
1902,
738,
11,
28050,
503,
314,
4528,
4079,
641,
314,
267,
6107,
503,
20379,
6025,
14,
2779,
2597,
4339,
5596,
28045,
340,
3451,
14,
267,
982,
440,
3451,
291,
14,
9690,
14,
740,
6333,
466,
582,
10042,
905,
9123,
21900,
365,
10302,
14,
267,
408,
398,
4370,
275,
7576,
267,
14070,
88,
275,
1616,
267,
340,
365,
10373,
26,
288,
4370,
275,
6318,
29371,
288,
14070,
88,
275,
3193,
398,
1495,
4851,
275,
942,
398,
327,
1448,
3639,
1006,
314,
4110,
626,
787,
315,
1425,
1830,
10663,
3238,
781,
267,
327,
2793,
1133,
9793,
376,
9027,
14,
267,
286,
275,
291,
14,
1745,
14,
1560,
342,
267,
1830,
286,
315,
4370,
436,
286,
365,
440,
9027,
26,
288,
1495,
4851,
14,
740,
8,
67,
9,
288,
286,
275,
291,
14,
1745,
14,
1560,
342,
398,
327,
7905,
314,
663,
402,
4110,
16949,
370,
376,
1109,
14,
267,
1495,
2822,
3241,
275,
1109,
31059,
904,
8,
1560,
4851,
395,
14070,
88,
9,
398,
327,
11002,
877,
4110,
664,
8717,
543,
11789,
267,
340,
1495,
2822,
3241,
315,
8343,
9272,
26,
288,
1495,
275,
8343,
9272,
59,
1560,
2822,
3241,
61,
288,
291,
14,
9690,
14,
740,
6333,
466,
582,
10042,
905,
9123,
2255,
298,
576,
582,
2511,
298,
23375,
13,
19300,
13,
509,
13,
6677,
13,
4502,
401,
2511,
298,
576,
2936,
582,
2420,
1560,
2822,
3241,
582,
1495,
2822,
3241,
19575,
267,
916,
3666,
16,
8313,
6718,
2695,
1495,
2822,
3241,
2695,
378,
8313,
24254,
9,
503,
1598,
334,
1560,
2822,
3241,
690,
378,
88,
709,
6968,
2298,
288,
1495,
275,
1867,
24815,
2,
288,
291,
14,
9690,
14,
740,
6333,
466,
582,
10042,
905,
9123,
2255,
298,
576,
582,
2511,
298,
23375,
13,
19300,
13,
509,
13,
6677,
13,
4502,
401,
2511,
298,
576,
2936,
582,
2420,
1560,
2822,
3241,
582,
1495,
2822,
3241,
19575,
267,
587,
26,
288,
327,
7719,
8112,
1536,
642,
1104,
29437,
334,
69,
14,
71,
14,
4057,
314,
663,
370,
282,
4413,
9,
288,
340,
3666,
16,
88,
4183,
2695,
1495,
2822,
3241,
2695,
378,
88,
19141,
9,
503,
355,
334,
16,
88,
1493,
37,
2695,
1495,
2822,
3241,
2695,
378,
88,
4587,
38,
9,
503,
355,
334,
16,
88,
8255,
38,
2695,
1495,
2822,
3241,
2695,
378,
88,
8581,
38,
9,
503,
355,
334,
16,
6287,
5745,
16,
2695,
1495,
2822,
3241,
2695,
378,
6287,
5638,
9,
503,
355,
1495,
2822,
3241,
315,
9522,
779,
16,
88,
1493,
34,
12,
378,
9039,
5100,
12,
378,
23973,
12,
378,
88,
17,
27897,
12,
3147,
378,
88,
17,
6968,
12,
378,
88,
18,
27897,
12,
378,
88,
18,
6968,
12,
378,
88,
19,
27897,
12,
3147,
378,
88,
19,
6968,
12,
378,
88,
20,
27897,
12,
378,
88,
20,
6968,
12,
378,
88,
21,
27897,
12,
3147,
378,
88,
21,
6968,
12,
378,
88,
22,
27897,
12,
378,
88,
22,
6968,
12,
378,
88,
23,
27897,
12,
3147,
378,
88,
23,
6968,
12,
378,
88,
24,
27897,
12,
378,
88,
24,
6968,
12,
378,
88,
25,
27897,
12,
3147,
378,
88,
25,
6968,
12,
378,
7471,
27897,
12,
378,
7471,
6968,
12,
378,
8094,
27897,
12,
3147,
378,
8094,
6968,
12,
378,
8163,
27897,
12,
378,
8163,
6968,
12
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
893,
26,
272,
8678,
275,
17742,
327,
27510,
24,
26,
8151,
199,
2590,
12746,
26,
272,
986,
199,
199,
504,
5055,
492,
15782,
199,
199,
504,
1275,
5559,
492,
25431,
199,
504,
1275,
5559,
492,
9045,
199,
504,
1275,
5559,
492,
13294,
28760,
12,
13294,
19316,
18,
17846,
199,
504,
1275,
5559,
492,
7576,
12,
6318,
29371,
12,
9027,
199,
504,
1275,
5559,
492,
10042,
12,
1947,
3264,
4100,
199,
504,
1275,
5559,
492,
8343,
9272,
199,
199,
504,
1275,
1210,
1745,
492,
4163,
27611,
199,
199,
504,
1275,
599,
69,
492,
377,
11317,
199,
199,
8327,
6948,
69,
275,
377,
11317,
8,
8327,
9,
421,
199,
533,
4163,
21782,
8,
785,
304,
272,
408,
961,
1021,
6181,
10296,
402,
1526,
9147,
4163,
14,
339,
627,
291,
14,
11631,
489,
869,
8250,
314,
1526,
626,
365,
5544,
3769,
7686,
14,
339,
627,
291,
14,
929,
489,
869,
8250,
282,
3659,
370,
314,
1083,
370,
506,
10302,
1396,
5787,
339,
627,
291,
14,
1745,
489,
32598,
370,
4163,
27611,
909,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2547,
12,
2644,
29,
403,
12,
2198,
3396,
29,
549,
12,
675,
1610,
9886,
29,
549,
12,
326,
12141,
2162,
985,
29,
549,
12,
12141,
7144,
985,
29,
549,
12,
1798,
29,
403,
304,
398,
291,
14,
1745,
275,
4163,
27611,
8,
1745,
12,
2644,
12,
2198,
3396,
12,
675,
1610,
9886,
9,
267,
291,
14,
2087,
275,
1798,
398,
327,
14795,
1930,
24796,
31,
267,
291,
14,
21636,
2162,
985,
275,
12141,
2162,
985,
267,
291,
14,
21636,
7144,
985,
275,
12141,
7144,
985,
398,
327,
12439,
314,
2536,
14803,
1174,
267,
291,
14,
3765,
5318,
275,
756,
267,
291,
14,
2019,
24766,
11229,
275,
942,
267,
291,
14,
929,
275,
291,
14,
18694,
267,
291,
14,
3765,
275,
756,
398,
327,
710,
1453,
1526,
3769,
2737,
267,
291,
14,
11631,
275,
488,
267,
1613,
8,
4943,
21782,
12,
291,
2843,
826,
4533,
339,
347,
636,
1661,
721,
277,
304,
267,
408,
961,
365,
2382,
314,
10628,
10986,
14,
398,
2136,
886,
4154,
9987,
6661,
4012,
314,
6363,
436,
1380,
781,
1172,
282,
1526,
267,
370,
372,
781,
1995,
314,
1526,
1314,
691,
5589,
6661,
5133,
314,
2163,
1526,
267,
365,
5839,
14,
267,
408,
267,
291,
14,
9690,
275,
15782,
4157,
267,
327,
7707,
6661,
14,
3979,
9027,
365,
13075,
291,
14,
929,
911,
372,
756,
267,
327,
3140,
402,
715,
436,
314,
4438,
911,
15095,
14,
267,
1830,
291,
14,
929,
837,
288,
1830,
291,
14,
1745,
14,
2550,
26,
355,
1995,
2420,
466,
582,
10042,
905,
9123,
2255,
298,
576,
582,
291,
14,
1745,
14,
2550,
14,
1935,
8,
16,
6769,
288,
1830,
291,
14,
9690,
26,
355,
1995,
291,
14,
9690,
14,
25704,
342,
339,
347,
9451,
3259,
7302,
8,
277,
12,
365,
10373,
304,
267,
408,
2765,
805,
2529,
1902,
738,
11,
28050,
503,
314,
4528,
4079,
641,
314,
267,
6107,
503,
20379,
6025,
14,
2779,
2597,
4339,
5596,
28045,
340,
3451,
14,
267,
982,
440,
3451,
291,
14,
9690,
14,
740,
6333,
466,
582,
10042,
905,
9123,
21900,
365,
10302,
14,
267,
408,
398,
4370,
275,
7576,
267,
14070,
88,
275,
1616,
267,
340,
365,
10373,
26,
288,
4370,
275,
6318,
29371,
288,
14070,
88,
275,
3193,
398,
1495,
4851,
275,
942,
398,
327,
1448,
3639,
1006,
314,
4110,
626,
787,
315,
1425,
1830,
10663,
3238,
781,
267,
327,
2793,
1133,
9793,
376,
9027,
14,
267,
286,
275,
291,
14,
1745,
14,
1560,
342,
267,
1830,
286,
315,
4370,
436,
286,
365,
440,
9027,
26,
288,
1495,
4851,
14,
740,
8,
67,
9,
288,
286,
275,
291,
14,
1745,
14,
1560,
342,
398,
327,
7905,
314,
663,
402,
4110,
16949,
370,
376,
1109,
14,
267,
1495,
2822,
3241,
275,
1109,
31059,
904,
8,
1560,
4851,
395,
14070,
88,
9,
398,
327,
11002,
877,
4110,
664,
8717,
543,
11789,
267,
340,
1495,
2822,
3241,
315,
8343,
9272,
26,
288,
1495,
275,
8343,
9272,
59,
1560,
2822,
3241,
61,
288,
291,
14,
9690,
14,
740,
6333,
466,
582,
10042,
905,
9123,
2255,
298,
576,
582,
2511,
298,
23375,
13,
19300,
13,
509,
13,
6677,
13,
4502,
401,
2511,
298,
576,
2936,
582,
2420,
1560,
2822,
3241,
582,
1495,
2822,
3241,
19575,
267,
916,
3666,
16,
8313,
6718,
2695,
1495,
2822,
3241,
2695,
378,
8313,
24254,
9,
503,
1598,
334,
1560,
2822,
3241,
690,
378,
88,
709,
6968,
2298,
288,
1495,
275,
1867,
24815,
2,
288,
291,
14,
9690,
14,
740,
6333,
466,
582,
10042,
905,
9123,
2255,
298,
576,
582,
2511,
298,
23375,
13,
19300,
13,
509,
13,
6677,
13,
4502,
401,
2511,
298,
576,
2936,
582,
2420,
1560,
2822,
3241,
582,
1495,
2822,
3241,
19575,
267,
587,
26,
288,
327,
7719,
8112,
1536,
642,
1104,
29437,
334,
69,
14,
71,
14,
4057,
314,
663,
370,
282,
4413,
9,
288,
340,
3666,
16,
88,
4183,
2695,
1495,
2822,
3241,
2695,
378,
88,
19141,
9,
503,
355,
334,
16,
88,
1493,
37,
2695,
1495,
2822,
3241,
2695,
378,
88,
4587,
38,
9,
503,
355,
334,
16,
88,
8255,
38,
2695,
1495,
2822,
3241,
2695,
378,
88,
8581,
38,
9,
503,
355,
334,
16,
6287,
5745,
16,
2695,
1495,
2822,
3241,
2695,
378,
6287,
5638,
9,
503,
355,
1495,
2822,
3241,
315,
9522,
779,
16,
88,
1493,
34,
12,
378,
9039,
5100,
12,
378,
23973,
12,
378,
88,
17,
27897,
12,
3147,
378,
88,
17,
6968,
12,
378,
88,
18,
27897,
12,
378,
88,
18,
6968,
12,
378,
88,
19,
27897,
12,
3147,
378,
88,
19,
6968,
12,
378,
88,
20,
27897,
12,
378,
88,
20,
6968,
12,
378,
88,
21,
27897,
12,
3147,
378,
88,
21,
6968,
12,
378,
88,
22,
27897,
12,
378,
88,
22,
6968,
12,
378,
88,
23,
27897,
12,
3147,
378,
88,
23,
6968,
12,
378,
88,
24,
27897,
12,
378,
88,
24,
6968,
12,
378,
88,
25,
27897,
12,
3147,
378,
88,
25,
6968,
12,
378,
7471,
27897,
12,
378,
7471,
6968,
12,
378,
8094,
27897,
12,
3147,
378,
8094,
6968,
12,
378,
8163,
27897,
12,
378,
8163,
6968,
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,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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
] |
hiuwo/acq4
|
acq4/analysis/tools/Fitting.py
|
1
|
36006
|
#!/usr/bin/env python
"""
Python class wrapper for data fitting.
Includes the following external methods:
getFunctions returns the list of function names (dictionary keys)
FitRegion performs the fitting
Note that FitRegion will plot on top of the current data using MPlots routines
if the current curve and the current plot instance are passed.
"""
# January, 2009
# Paul B. Manis, Ph.D.
# UNC Chapel Hill
# Department of Otolaryngology/Head and Neck Surgery
# Supported by NIH Grants DC000425-22 and DC004551-07 to PBM.
# Copyright Paul Manis, 2009
#
"""
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/>.
"""
"""
Additional Terms:
The author(s) would appreciate that any modifications to this program, or
corrections of erros, be reported to the principal author, Paul Manis, at
pmanis@med.unc.edu, with the subject line "PySounds Modifications".
Note: This program also relies on the TrollTech Qt libraries for the GUI.
You must obtain these libraries from TrollTech directly, under their license
to use the program.
"""
import sys
import numpy
import scipy
try:
import openopt
HAVE_OPENOPT = True
except ImportError:
HAVE_OPENOPT = False
print "There was an error importing openopt. Continuing...."
import ctypes
import numpy.random
#from numba import autojit
usingMPlot = False
if usingMPlot:
import MPlot # we include plotting as part of the fitting
def debug_trace():
'''Set a tracepoint in the Python debugger that works with Qt'''
if pyqt:
from PyQt4.QtCore import pyqtRemoveInputHook
from pdb import set_trace
if pyqt:
pyqtRemoveInputHook()
set_trace()
class Fitting():
# dictionary contains:
# name of function: function call, initial parameters, iterations, plot color, then x and y for testing
# target valutes, names of parameters, contant values, and derivative function if needed.
#
def __init__(self):
self.fitfuncmap = {
'exp0' : (self.exp0eval, [0.0, 20.0], 2000, 'k', [0, 100, 1.],
[1.0, 5.0], ['A0', 'tau'], None, None),
'exp1' : (self.expeval, [0.0, 0.0, 20.0], 2000, 'k', [0, 100, 1.],
[0.5, 1.0, 5.0], ['DC', 'A0', 'tau'], None, self.expevalprime),
'expsum' : (self.expsumeval, [0.0, -0.5, 200.0, -0.25, 450.0], 500000, 'k', [0, 1000, 1.],
[0.0, -1.0, 150.0, -0.25, 350.0], ['DC', 'A0', 'tau0', 'A1', 'tau1'], None, None),
'expsum2' : (self.expsumeval2, [0., -0.5, -0.250], 50000, 'k', [0, 1000, 1.],
[0., -0.5, -0.25], ['A0', 'A1'], [5., 20.], None),
'exp2' : (self.exp2eval, [0.0, -0.5, 200.0, -0.25, 450.0], 500000, 'k', [0, 1000, 1.],
[0.0, -1.0, 150.0, -0.25, 350.0], ['DC', 'A0', 'tau0', 'A1', 'tau1'], None, None),
'exppow' : (self.exppoweval, [0.0, 1.0, 100, ], 2000, 'k', [0, 100, 0.1],
[0.0, 1.0, 100.0], ['DC', 'A0', 'tau'], None, None),
'exppulse' : (self.expPulse, [3.0, 2.5, 0.2, 2.5, 2.0, 0.5], 2000, 'k', [0, 10, 0.3],
[0.0, 0., 0.75, 4., 1.5, 1.], ['DC', 't0', 'tau1', 'tau2', 'amp', 'width'], None, None),
'boltz' : (self.boltzeval, [0.0, 1.0, -50.0, -5.0], 5000, 'r', [-130., -30., 1.],
[0.00, 0.010, -100.0, 7.0], ['DC', 'A0', 'x0', 'k'], None, None),
'gauss' : (self.gausseval, [1.0, 0.0, 0.5], 2000, 'y', [-10., 10., 0.2],
[1.0, 1.0, 2.0], ['A', 'mu', 'sigma'], None, None),
'line' : (self.lineeval, [1.0, 0.0], 500, 'r', [-10., 10., 0.5],
[0.0, 2.0], ['m', 'b'], None, None),
'poly2' : (self.poly2eval, [1.0, 1.0, 0.0], 500, 'r', [0, 100, 1.],
[0.5, 1.0, 5.0], ['a', 'b', 'c'], None, None),
'poly3' : (self.poly3eval, [1.0, 1.0, 1.0, 0.0], 1000, 'r', [0., 100., 1.],
[0.5, 1.0, 5.0, 2.0], ['a', 'b', 'c', 'd'], None, None),
'poly4' : (self.poly4eval, [1.0, 1.0, 1.0, 1.0, 0.0], 1000, 'r', [0., 100., 1.],
[0.1, 0.5, 1.0, 5.0, 2.0], ['a', 'b', 'c', 'd', 'e'], None, None),
'sin' : (self.sineeval, [-1., 1.0, 4.0, 0.0], 1000, 'r', [0., 100., 0.2],
[0.0, 1.0, 9.0, 0.0], ['DC', 'A', 'f', 'phi'], None, None),
'boltz2' : (self.boltzeval2, [0.0, 0.5, -50.0, 5.0, 0.5, -20.0, 3.0], 1200, 'r',
[-100., 50., 1.], [0.0, 0.3, -45.0, 4.0, 0.7, 10.0, 12.0],
['DC', 'A1', 'x1', 'k1', 'A2', 'x2', 'k2'], None, None),
'taucurve' : (self.taucurve, [50., 300.0, 60.0, 10.0, 8.0, 65.0, 10.0], 50000, 'r',
[-150., 50., 1.], [0.0, 237.0, 60.0, 12.0, 17.0, 60.0, 14.0],
['DC', 'a1', 'v1', 'k1', 'a2', 'v2', 'k2'], None, self.taucurveder),
}
self.fitSum2Err = 0
def getFunctions(self):
return(self.fitfuncmap.keys())
def exp0eval(self, p, x, y=None, C = None, sumsq = False):
"""
Exponential function with an amplitude and 0 offset
"""
yd = p[0] * numpy.exp(-x/p[1])
if y is None:
return yd
else:
if sumsq is True:
return numpy.sum((y - yd)**2)
else:
return y - yd
def expsumeval(self, p, x, y=None, C = None, sumsq = False, weights=None):
"""
Sum of two exponentials with independent time constants and amplitudes,
and a DC offset
"""
yd = p[0] + (p[1]* numpy.exp(-x/p[2])) + (p[3]*numpy.exp(-x/p[4]))
if y is None:
return yd
else:
yerr = y - yd
if weights is not None:
yerr = yerr * weights
if sumsq is True:
return numpy.sum(yerr**2)
else:
return yerr
def expsumeval2(self, p, x, y=None, C = None, sumsq = False, weights=None):
"""
Sum of two exponentials, with predefined time constants , allowing
only the amplitudes and DC offset to vary
"""
yd = p[0] + (p[1]* numpy.exp(-x/C[0])) + (p[2]*numpy.exp(-x/C[1]))
if y is None:
return yd
else:
if sumsq is True:
return numpy.sum((y - yd)**2)
else:
return y - yd
def expeval(self, p, x, y=None, C = None, sumsq = False, weights=None):
"""
Exponential with offset
"""
yd = p[0] + p[1] * numpy.exp(-x/p[2])
# print yd.shape
# print y.shape
if y is None:
return yd
else:
if sumsq is True:
return numpy.sum((y - yd)**2)
else:
return y - yd
def expevalprime(self, p, x, y=None, C = None, sumsq = False, weights=None):
"""
Derivative for exponential with offset
"""
ydp = p[1] * numpy.exp(-x/p[2])/(p[2]*p[2])
yd = p[0] + p[1] * numpy.exp(-x/p[2])
print y
if y is None:
return (yd, ydp)
else:
if sumsq is True:
return numpy.sum((y - yd)**2)
else:
return y - yd
def exppoweval(self, p, x, y=None, C = None, sumsq = False, weights=None):
"""
Single exponential function, rising to a ppower
"""
if C is None:
cx = 1.0
else:
cx = C[0]
yd = p[0] + p[1] * (1.0-numpy.exp(-x/p[2]))**cx
if y is None:
return yd
else:
if sumsq is True:
return numpy.sum((y - yd)**2)
else:
return y - yd
def exp2eval(self, p, x, y=None, C = None, sumsq = False, weights=None):
"""
For fit to activation currents...
"""
yd = p[0] + (p[1] * (1.0 - numpy.exp(-x/p[2]))**2.0 ) + (p[3] * (1.0 - numpy.exp(-x/p[4])))
if y == None:
return yd
else:
if sumsq is True:
ss = numpy.sqrt(numpy.sum((y - yd)**2.0))
# if p[4] < 3.0*p[2]:
# ss = ss*1e6 # penalize them being too close
return ss
else:
return y - yd
# @autojit
def expPulse(self, p, x, y=None, C=None, sumsq = False, weights = None):
"""Exponential pulse function (rising exponential with optional variable-length
plateau followed by falling exponential)
Parameter p is [yOffset, t0, tau1, tau2, amp, width]
"""
yOffset, t0, tau1, tau2, amp, width = p
yd = numpy.empty(x.shape)
yd[x<t0] = yOffset
m1 = (x>=t0)&(x<(t0+width))
m2 = (x>=(t0+width))
x1 = x[m1]
x2 = x[m2]
yd[m1] = amp*(1-numpy.exp(-(x1-t0)/tau1))+yOffset
amp2 = amp*(1-numpy.exp(-width/tau1)) ## y-value at start of decay
yd[m2] = ((amp2)*numpy.exp(-(x2-(width+t0))/tau2))+yOffset
if y == None:
return yd
else:
if sumsq is True:
ss = numpy.sqrt(numpy.sum((y-yd)**2.0))
return ss
else:
return y-yd
def boltzeval(self,p, x, y=None, C = None, sumsq = False, weights=None):
yd = p[0] + (p[1]-p[0])/(1.0 + numpy.exp((x-p[2])/p[3]))
if y == None:
return yd
else:
if sumsq is True:
return numpy.sqrt(numpy.sum((y - yd)**2.0))
else:
return y - yd
def boltzeval2(self,p, x, y=None, C = None, sumsq = False, weights=None):
yd = p[0] + p[1]/(1 + numpy.exp((x-p[2])/p[3])) + p[4]/(1 + numpy.exp((x-p[5])/p[6]))
if y == None:
return yd
else:
if sumsq is True:
return numpy.sum((y - yd)**2)
else:
return y - yd
def gausseval(self,p, x, y=None, C = None, sumsq = False, weights=None):
yd = (p[0]/(p[2]*numpy.sqrt(2.0*numpy.pi)))*numpy.exp(-((x - p[1])**2.0)/(2.0*(p[2]**2.0)))
if y == None:
return yd
else:
if sumsq is True:
return numpy.sum((y - yd)**2)
else:
return y - yd
def lineeval(self, p, x, y=None, C = None, sumsq = False, weights=None):
yd = p[0]*x + p[1]
if y == None:
return yd
else:
if sumsq is True:
return numpy.sum((y - yd)**2)
else:
return y - yd
def poly2eval(self, p, x, y=None, C = None, sumsq = False, weights=None):
yd = p[0]*x**2.0 + p[1]*x + p[2]
if y == None:
return yd
else:
if sumsq is True:
return numpy.sum((y - yd)**2)
else:
return y - yd
def poly3eval(self, p, x, y=None, C = None, sumsq = False, weights=None):
yd = p[0]*x**3.0 + p[1]*x**2.0 + p[2]*x +p[3]
if y == None:
return yd
else:
if sumsq is True:
return numpy.sum((y - yd)**2)
else:
return y - yd
def poly4eval(self, p, x, y=None, C = None, sumsq = False, weights=None):
yd = p[0]*x**4.0 + p[1]*x**3.0 + p[2]*x**2.0 + p[3]*x +p[4]
if y == None:
return yd
else:
if sumsq is True:
return numpy.sum((y - yd)**2)
else:
return y - yd
def sineeval(self, p, x, y=None, C = None, sumsq = False, weights=None):
yd = p[0] + p[1]*numpy.sin((x*2.0*numpy.pi/p[2])+p[3])
if y == None:
return yd
else:
if sumsq is True:
return numpy.sum((y - yd)**2)
else:
return y - yd
def taucurve(self, p, x, y=None, C = None, sumsq=True, weights=None):
"""
HH-like description of activation/inactivation function
'DC', 'a1', 'v1', 'k1', 'a2', 'v2', 'k2'
"""
yd = p[0] + 1.0/(p[1]*numpy.exp((x+p[2])/p[3]) +p[4]*numpy.exp(-(x+p[5])/p[6]))
if y == None:
return yd
else:
if sumsq is True:
return numpy.sqrt(numpy.sum((y - yd)**2))
else:
return y - yd
def taucurveder(self, p, x):
"""
Derivative for taucurve
'DC', 'a1', 'v1', 'k1', 'a2', 'v2', 'k2'
"""
y = -(p[1]*numpy.exp((p[2] + x)/p[3])/p[3] - p[4]*numpy.exp(-(p[5] + x)/p[6])/p[6])/(p[1]*numpy.exp((p[2] + x)/p[3]) +
p[4]*numpy.exp(-(p[5] + x)/p[6]))**2.0
# print 'dy: ', y
return y
def getClipData(self, x, y, t0, t1):
"""
Return the values in y that match the x range in tx from
t0 to t1. x must be monotonic increasing or decreasing.
Allow for reverse ordering. """
it0 = (numpy.abs(x-t0)).argmin()
it1 = (numpy.abs(x-t1)).argmin()
if it0 > it1:
t = it1
it1 = it0
it0 = t
return(x[it0:it1], y[it0:it1])
def FitRegion(self, whichdata, thisaxis, tdat, ydat, t0 = None, t1 = None,
fitFunc = 'exp1', fitFuncDer = None, fitPars = None, fixedPars = None,
fitPlot = None, plotInstance = None, dataType= 'xy', method = None,
bounds=None, weights=None, constraints=()):
"""
**Arguments**
============= ===================================================
whichdata
thisaxis
tdat
ydat
t0 (optional) Minimum of time data - determined from tdat if left unspecified
t1 (optional) Maximum of time data - determined from tdat if left unspecified
fitFunc (optional) The function to fit the data to (as defined in __init__). Default is 'exp1'.
fitFuncDer (optional) default=None
fitPars (optional) Initial fit parameters. Use the values defined in self.fitfuncmap if unspecified.
fixedPars (optional) Fixed parameters to pass to the function. Default=None
fitPlot (optional) default=None
plotInstance (optional) default=None
dataType (optional) Options are ['xy', 'blocks']. Default='xy'
method (optional) Options are ['curve_fit', 'fmin', 'simplex', 'Nelder-Mead', 'bfgs', 'TNC', 'SLSQP', 'COBYLA', 'L-BFGS-B', 'openopt']. Default='leastsq'
bounds (optional) default=None
weights (optional) default=None
constraints (optional) default=()
============= ===================================================
To call with tdat and ydat as simple arrays:
FitRegion(1, 0, tdat, ydat, FitFunc = 'exp1')
e.g., the first argument should be 1, but this axis is ignored if datatype is 'xy'
"""
self.fitSum2Err = 0.0
if t0 == t1:
if plotInstance is not None and usingMPlot:
(x, y) = plotInstance.getCoordinates()
t0 = x[0]
t1 = x[1]
if t1 is None:
t1 = numpy.max(tdat)
if t0 is None:
t0 = numpy.min(tdat)
func = self.fitfuncmap[fitFunc]
if func is None:
print "FitRegion: unknown function %s" % (fitFunc)
return
xp = []
xf = []
yf = []
yn = []
tx = []
names = func[6]
if fitPars is None:
fpars = func[1]
else:
fpars = fitPars
if method == 'simplex': # remap calls if needed for newer versions of scipy (>= 0.11)
method = 'Nelder-Mead'
if ydat.ndim == 1 or dataType == 'xy' or dataType == '2d': # check if 1-d, then "pretend" its only a 1-element block
nblock = 1
else:
nblock = ydat.shape[0] # otherwise, this is the number of traces in the block
# print 'datatype: ', dataType
# print 'nblock: ', nblock
# print 'whichdata: ', whichdata
# for block in range(nblock):
for record in whichdata:
if dataType == 'blocks':
(tx, dy) = self.getClipData(tdat[block], ydat[block][record, thisaxis, :], t0, t1)
else:
(tx, dy) = self.getClipData(tdat, ydat[record,:], t0, t1)
# print 'Fitting.py: block, type, Fit data: ', block, dataType
# print tx.shape
# print dy.shape
yn.append(names)
if not any(tx):
continue # no data in the window...
ier = 0
#
# Different optimization methods are included here. Not all have been tested fully with
# this wrapper.
#
if method is None or method == 'leastsq': # use standard leastsq, no bounds
plsq, cov, infodict, mesg, ier = scipy.optimize.leastsq(func[0], fpars,
args=(tx.astype('float64'), dy.astype('float64'), fixedPars),
full_output = 1, maxfev = func[2])
if ier > 4:
print "optimize.leastsq error flag is: %d" % (ier)
print mesg
elif method == 'curve_fit':
print fpars
print fixedPars
plsq, cov = scipy.optimize.curve_fit(func[0], tx.astype('float64'), dy.astype('float64'), p0=fpars)
ier = 0
elif method in ['fmin', 'simplex', 'Nelder-Mead', 'bfgs', 'TNC', 'SLSQP', 'COBYLA', 'L-BFGS-B']: # use standard wrapper from scipy for those routintes
res = scipy.optimize.minimize(func[0], fpars, args=(tx.astype('float64'), dy.astype('float64'), fixedPars, True),
method=method, jac=None, hess=None, hessp=None, bounds=bounds, constraints=constraints, tol=None, callback=None,
options={'maxiter': func[2], 'disp': False })
plsq = res.x
#print " method:", method
#print " bounds:", bounds
#print " result:", plsq
# next section is replaced by the code above - kept here for reference if needed...
# elif method == 'fmin' or method == 'simplex':
# plsq = scipy.optimize.fmin(func[0], fpars, args=(tx.astype('float64'), dy.astype('float64'), fixedPars, True),
# maxfun = func[2]) # , iprint=0)
# ier = 0
# elif method == 'bfgs':
# plsq, cov, infodict = scipy.optimize.fmin_l_bfgs_b(func[0], fpars, fprime=func[8],
# args=(tx.astype('float64'), dy.astype('float64'), fixedPars, True, weights),
# maxfun = func[2], bounds = bounds,
# approx_grad = True) # , disp=0, iprint=-1)
elif method == 'openopt': # use OpenOpt's routines - usually slower, but sometimes they converge better
if not HAVE_OPENOPT:
raise Exception("Requested openopt fitting method but openopt is not installed.")
if bounds is not None:
# unpack bounds
lb = [y[0] for y in bounds]
ub = [y[1] for y in bounds]
fopt = openopt.DFP(func[0], fpars, tx, dy, df = fitFuncDer, lb=lb, ub=ub)
# fopt.df = func[8]
r = fopt.solve('nlp:ralg', plot=0, iprint = 10)
plsq = r.xf
ier = 0
else:
fopt = openopt.DFP(func[0], fpars, tx, dy, df = fitFuncDer)
print func[8]
# fopt.df = func[7]
fopt.checkdf()
r = fopt.solve('nlp:ralg', plot=0, iprint = 10)
plsq = r.xf
ier = 0
else:
print 'method %s not recognized, please check Fitting.py' % (method)
return
xfit = numpy.arange(min(tx), max(tx), (max(tx)-min(tx))/100.0)
yfit = func[0](plsq, xfit, C=fixedPars)
yy = func[0](plsq, tx, C=fixedPars) # calculate function
self.fitSum2Err = numpy.sum((dy - yy)**2)
if usingMPlot and FitPlot != None and plotInstance != None:
self.FitPlot(xFit = xfit, yFit = yfit, fitFunc = fund[0],
fitPars = plsq, plot = fitPlot, plotInstance = plotInstance)
xp.append(plsq) # parameter list
xf.append(xfit) # x plot point list
yf.append(yfit) # y fit point list
# print xp
# print len(xp)
return(xp, xf, yf, yn) # includes names with yn and range of tx
def FitPlot(self, xFit = None, yFit = None, fitFunc = 'exp1',
fitPars = None, fixedPars = None, fitPlot=None, plotInstance = None,
color=None):
""" Plot the fit data onto the fitPlot with the specified "plot Instance".
if there is no xFit, or some parameters are missing, we just return.
if there is xFit, but no yFit, then we try to compute the fit with
what we have. The plot is superimposed on the specified "fitPlot" and
the color is specified by the function color in the fitPars list.
"""
if xFit is None or fitPars is None:
return
func = self.fitfuncmap[fitFunc]
if color is None:
fcolor = func[3]
else:
fcolor = color
if yFit is None:
yFit = numpy.array([])
for k in range(0, len(fitPars)):
yFit[k] = func[0](fitPars[k], xFit[k], C=fixedPars)
if plotInstance is None or fitPlot is None:
return(yfit)
for k in range(0, len(fitPars)):
plotInstance.PlotLine(fitPlot, xFit[k], yFit[k], color = fcolor)
return(yfit)
def getFitErr(self):
""" Return the fit error for the most recent fit
"""
return(self.fitSum2Err)
def expfit(self, x, y):
""" find best fit of a single exponential function to x and y
using the chebyshev polynomial approximation.
returns (DC, A, tau) for fit.
Perform a single exponential fit to data using Chebyshev polynomial method.
Equation fit: y = a1 * exp(-x/tau) + a0
Call: [a0 a1 tau] = expfit(x,y);
Calling parameter x is the time base, y is the data to be fit.
Returned values: a0 is the offset, a1 is the amplitude, tau is the time
constant (scaled in units of x).
Relies on routines chebftd to generate polynomial coeffs, and chebint to compute the
coefficients for the integral of the data. These are now included in this
.py file source.
This version is based on the one in the pClamp manual: HOWEVER, since
I use the bounded [-1 1] form for the Chebyshev polynomials, the coefficients are different,
and the resulting equation for tau is different. I manually optimized the tau
estimate based on fits to some simulated noisy data. (Its ok to use the whole range of d1 and d0
when the data is clean, but only the first few coeffs really hold the info when
the data is noisy.)
NOTE: The user is responsible for making sure that the passed data is appropriate,
e.g., no large noise or electronic transients, and that the time constants in the
data are adequately sampled.
To do a double exp fit with this method is possible, but more complex.
It would be computationally simpler to try breaking the data into two regions where
the fast and slow components are dominant, and fit each separately; then use that to
seed a non-linear fit (e.g., L-M) algorithm.
Final working version 4/13/99 Paul B. Manis
converted to Python 7/9/2009 Paul B. Manis. Seems functional.
"""
n = 30; # default number of polynomials coeffs to use in fit
a = numpy.amin(x)
b = numpy.amax(x)
d0 = self.chebftd(a, b, n, x, y) # coeffs for data trace...
d1 = self.chebint(a, b, d0, n) # coeffs of integral...
tau = -numpy.mean(d1[2:3]/d0[2:3])
try:
g = numpy.exp(-x/tau)
except:
g = 0.0
dg = self.chebftd(a, b, n, x, g) # generate chebyshev polynomial for unit exponential function
# now estimate the amplitude from the ratios of the coeffs.
a1 = self.estimate(d0, dg, 1)
a0 = (d0[0]-a1*dg[0])/2.0 # get the offset here
return(a0, a1, tau)#
def estimate(self, c, d, m):
""" compute optimal estimate of parameter from arrays of data """
n = len(c)
a = sum(c[m:n]*d[m:n])/sum(d[m:n]**2.0)
return(a)
# note : the following routine is a bottleneck. It should be coded in C.
def chebftd(self, a, b, n, t, d):
""" Chebyshev fit; from Press et al, p 192.
matlab code P. Manis 21 Mar 1999
"Given a function func, lower and upper limits of the interval [a,b], and
a maximum degree, n, this routine computes the n coefficients c[1..n] such that
func(x) sum(k=1, n) of ck*Tk(y) - c0/2, where y = (x -0.5*(b+a))/(0.5*(b-a))
This routine is to be used with moderately large n (30-50) the array of c's is
subsequently truncated at the smaller value m such that cm and subsequent
terms are negligible."
This routine is modified so that we find close points in x (data array) - i.e., we find
the best Chebyshev terms to describe the data as if it is an arbitrary function.
t is the x data, d is the y data...
"""
bma = 0.5*(b-a)
bpa = 0.5*(b+a)
inc = t[1]-t[0]
f = numpy.zeros(n)
for k in range(0, n):
y = numpy.cos(numpy.pi*(k+0.5)/n)
pos = int(0.5+(y*bma+bpa)/inc)
if pos < 0:
pos = 0
if pos >= len(d)-2:
pos = len(d)-2
try:
f[k]= d[pos+1]
except:
print "error in chebftd: k = %d (len f = %d) pos = %d, len(d) = %d\n" % (k, len(f), pos, len(d))
print "you should probably make sure this doesn't happen"
fac = 2.0/n
c=numpy.zeros(n)
for j in range(0, n):
sum=0.0
for k in range(0, n):
sum = sum + f[k]*numpy.cos(numpy.pi*j*(k+0.5)/n)
c[j]=fac*sum
return(c)
def chebint(self, a, b, c, n):
""" Given a, b, and c[1..n] as output from chebft or chebftd, and given n,
the desired degree of approximation (length of c to be used),
this routine computes cint, the Chebyshev coefficients of the
integral of the function whose coeffs are in c. The constant of
integration is set so that the integral vanishes at a.
Coded from Press et al, 3/21/99 P. Manis (Matlab)
Python translation 7/8/2009 P. Manis
"""
sum = 0.0
fac = 1.0
con = 0.25*(b-a) # factor that normalizes the interval
cint = numpy.zeros(n)
for j in range(1,n-2):
cint[j]=con*(c[j-1]-c[j+1])/j
sum = sum + fac * cint[j]
fac = - fac
cint[n-1] = con*c[n-2]/(n-1)
sum = sum + fac*cint[n-1]
cint[0] = 2.0*sum # set constant of integration.
return(cint)
# routine to flatten an array/list.
#
def flatten(self, l, ltypes=(list, tuple)):
i = 0
while i < len(l):
while isinstance(l[i], ltypes):
if not l[i]:
l.pop(i)
if not len(l):
break
else:
l[i:i+1] = list(l[i])
i += 1
return l
# flatten()
# run tests if we are "main"
if __name__ == "__main__":
# import matplotlib.pyplot as pyplot
import timeit
import Fitting
import matplotlib as MP
MP.use('Qt4Agg')
################## Do not modify the following code
# sets up matplotlib with sans-serif plotting...
import matplotlib.gridspec as GS
# import mpl_toolkits.axes_grid1.inset_locator as INSETS
# #import inset_axes, zoomed_inset_axes
# import mpl_toolkits.axes_grid1.anchored_artists as ANCHOR
# # import AnchoredSizeBar
stdFont = 'Arial'
import matplotlib.pyplot as pylab
pylab.rcParams['text.usetex'] = True
pylab.rcParams['interactive'] = False
pylab.rcParams['font.family'] = 'sans-serif'
pylab.rcParams['font.sans-serif'] = 'Arial'
pylab.rcParams['mathtext.default'] = 'sf'
pylab.rcParams['figure.facecolor'] = 'white'
# next setting allows pdf font to be readable in Adobe Illustrator
pylab.rcParams['pdf.fonttype'] = 42
pylab.rcParams['text.dvipnghack'] = True
##################### to here (matplotlib stuff - touchy!
Fits = Fitting.Fitting()
# x = numpy.arange(0, 100.0, 0.1)
# y = 5.0-2.5*numpy.exp(-x/5.0)+0.5*numpy.random.randn(len(x))
# (dc, aFit,tauFit) = Fits.expfit(x,y)
# yf = dc + aFit*numpy.exp(-x/tauFit)
# pyplot.figure(1)
# pyplot.plot(x,y,'k')
# pyplot.hold(True)
# pyplot.plot(x, yf, 'r')
# pyplot.show()
exploreError = False
if exploreError is True:
# explore the error surface for a function:
func = 'exppulse'
f = Fits.fitfuncmap[func]
p1range = numpy.arange(0.1, 5.0, 0.1)
p2range = numpy.arange(0.1, 5.0, 0.1)
err = numpy.zeros((len(p1range), len(p2range)))
x = numpy.array(numpy.arange(f[4][0], f[4][1], f[4][2]))
C = None
if func == 'expsum2':
C = f[7]
# check exchange of tau1 ([1]) and width[4]
C = None
yOffset, t0, tau1, tau2, amp, width = f[1] # get inital parameters
y0 = f[0](f[1], x, C=C)
noise = numpy.random.random(y0.shape) - 0.5
y0 += 0.0* noise
sh = err.shape
yp = numpy.zeros((sh[0], sh[1], len(y0)))
for i, p1 in enumerate(p1range):
tau1t = tau1*p1
for j, p2 in enumerate(p2range):
ampt = amp*p2
pars = (yOffset, t0, tau1t, tau2, ampt, width) # repackage
err[i,j] = f[0](pars, x, y0, C=C, sumsq = True)
yp[i,j] = f[0](pars, x, C=C, sumsq = False)
pylab.figure()
CS=pylab.contour(p1range*tau1, p2range*width, err, 25)
CB = pylab.colorbar(CS, shrink=0.8, extend='both')
pylab.figure()
for i, p1 in enumerate(p1range):
for j, p2 in enumerate(p2range):
pylab.plot(x, yp[i,j])
pylab.plot(x, y0, 'r-', linewidth=2.0)
# run tests for each type of fit, return results to compare parameters
cons = None
bnds = None
signal_to_noise = 100000.
for func in Fits.fitfuncmap:
if func != 'exppulse':
continue
print "\nFunction: %s\nTarget: " % (func),
f = Fits.fitfuncmap[func]
for k in range(0,len(f[1])):
print "%f " % (f[1][k]),
print "\nStarting: ",
for k in range(0,len(f[5])):
print "%f " % (f[5][k]),
# nstep = 500.0
# if func == 'sin':
# nstep = 100.0
x = numpy.array(numpy.arange(f[4][0], f[4][1], f[4][2]))
C = None
if func == 'expsum2':
C = f[7]
if func == 'exppulse':
C = f[7]
y = f[0](f[1], x, C=C)
yd = numpy.array(y)
noise = numpy.random.normal(0, 0.1, yd.shape)
my = numpy.amax(yd)
#yd = yd + sigmax*0.05*my*(numpy.random.random_sample(shape(yd))-0.5)
yd += noise*my/signal_to_noise
testMethod = 'SLSQP'
if func == 'taucurve':
continue
bounds=[(0., 100.), (0., 1000.), (0.0, 500.0), (0.1, 50.0),
(0., 1000), (0.0, 500.0), (0.1, 50.0)]
(fpar, xf, yf, names) = Fits.FitRegion(numpy.array([1]), 0, x, yd, fitFunc = func, bounds=bounds, method=testMethod)
elif func == 'boltz':
continue
bounds = [(-0.5,0.5), (0.0, 20.0), (-120., 0.), (-20., 0.)]
(fpar, xf, yf, names) = Fits.FitRegion(numpy.array([1]), 0, x, yd, fitFunc = func, bounds=bounds, method=testMethod)
elif func == 'exp2':
bounds=[(-0.001, 0.001), (-5.0, 0.), (1.0, 500.0), (-5.0, 0.0),
(1., 10000.)]
(fpar, xf, yf, names) = Fits.FitRegion(numpy.array([1]), 0, x, yd, fitFunc = func, bounds=bounds, method=testMethod)
elif func == 'exppulse':
# set some constraints to the fitting
# yOffset, tau1, tau2, amp, width = f[1] # order of constraings
dt = numpy.mean(numpy.diff(x))
bounds = [(-5, 5), (-15., 15.), (-2, 2.0), (2-10, 10.), (-5, 5.), (0., 5.)]
# cxample for constraints:
# cons = ({'type': 'ineq', 'fun': lambda x: x[4] - 3.0*x[2]},
# {'type': 'ineq', 'fun': lambda x: - x[4] + 12*x[2]},
# {'type': 'ineq', 'fun': lambda x: x[2]},
# {'type': 'ineq', 'fun': lambda x: - x[4] + 2000},
# )
cons = ({'type': 'ineq', 'fun': lambda x: x[3] - x[2] }, # tau1 < tau2
)
C = None
tv = f[5]
initialgr = f[0](f[5], x, None )
(fpar, xf, yf, names) = Fits.FitRegion(
numpy.array([1]), 0, x, yd, fitFunc = func, fixedPars = C, constraints = cons, bounds = bounds, method=testMethod)
# print xf
# print yf
# print fpar
# print names
else:
(fpar, xf, yf, names) = Fits.FitRegion(
numpy.array([1]), 0, x, yd, fitFunc = func, fixedPars = C, constraints = cons, bounds = bnds, method=testMethod)
#print fpar
s = numpy.shape(fpar)
j = 0
outstr = ""
initstr = ""
truestr = ""
for i in range(0, len(names[j])):
# print "%f " % fpar[j][i],
outstr = outstr + ('%s = %f, ' % (names[j][i], fpar[j][i]))
initstr = initstr + '%s = %f, ' % (names[j][i], tv[i])
truestr = truestr + '%s = %f, ' % (names[j][i], f[1][i])
print( "\nTrue(%d) : %s" % (j, truestr) )
print( "FIT(%d) : %s" % (j, outstr) )
print( "init(%d) : %s" % (j, initstr) )
print( "Error: : %f" % (Fits.fitSum2Err))
if func is 'exppulse':
pylab.figure()
pylab.plot(numpy.array(x), yd, 'ro-')
pylab.hold(True)
pylab.plot(numpy.array(x), initialgr, 'k--')
pylab.plot(xf[0], yf[0], 'b-') # fit
pylab.show()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
4718,
1021,
4975,
367,
666,
21774,
14,
199,
22792,
314,
2569,
5957,
3102,
26,
199,
362,
13967,
2529,
314,
769,
402,
805,
1561,
334,
9086,
2883,
9,
199,
13776,
10708,
18628,
314,
21774,
199,
7443,
626,
25971,
10708,
911,
5137,
641,
2746,
402,
314,
1453,
666,
1808,
27365,
4555,
14975,
199,
692,
314,
1453,
15318,
436,
314,
1453,
5137,
1256,
787,
3032,
14,
199,
199,
624,
199,
3,
17474,
20527,
12,
8937,
199,
3,
28574,
699,
14,
4688,
374,
12,
11308,
14,
36,
14,
199,
3,
738,
6389,
2799,
924,
76,
869,
778,
199,
3,
1487,
12493,
402,
593,
6896,
695,
78,
1939,
4956,
15,
11664,
436,
5612,
346,
17079,
836,
89,
199,
3,
26167,
701,
653,
19824,
598,
82,
2285,
30592,
16643,
821,
13,
1081,
436,
30592,
7979,
23327,
13,
1780,
370,
510,
15225,
14,
199,
3,
1898,
28574,
4688,
374,
12,
8937,
199,
3,
199,
624,
272,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
199,
624,
272,
10961,
13861,
706,
26,
272,
710,
4132,
8,
83,
9,
3955,
2771,
20940,
323,
626,
1263,
23070,
370,
642,
2240,
12,
503,
272,
1970,
14998,
402,
9266,
4796,
12,
506,
14581,
370,
314,
21646,
4132,
12,
28574,
4688,
374,
12,
737,
272,
299,
1237,
374,
32,
3594,
14,
1097,
14,
8654,
12,
543,
314,
5420,
1004,
298,
2713,
18670,
83,
12972,
3477,
83,
1674,
339,
3390,
26,
961,
2240,
2597,
25749,
641,
314,
377,
2827,
6301,
335,
3959,
8363,
367,
314,
17160,
14,
272,
2047,
1471,
3332,
3520,
8363,
687,
377,
2827,
6301,
335,
5370,
12,
1334,
3932,
4190,
272,
370,
675,
314,
2240,
14,
199,
624,
199,
199,
646,
984,
199,
646,
2680,
199,
646,
7026,
199,
199,
893,
26,
272,
492,
1551,
2992,
272,
25227,
63,
9935,
5123,
275,
715,
199,
2590,
3545,
26,
272,
25227,
63,
9935,
5123,
275,
756,
272,
870,
298,
10924,
1990,
376,
1125,
16306,
1551,
2992,
14,
1448,
1346,
23221,
4496,
2,
199,
199,
646,
5577,
199,
646,
2680,
14,
2355,
421,
199,
3,
504,
1967,
2470,
492,
2599,
17676,
199,
199,
4941,
1658,
1653,
275,
756,
199,
692,
1808,
1658,
1653,
26,
272,
492,
603,
10711,
327,
781,
2387,
25174,
465,
1777,
402,
314,
21774,
199,
199,
318,
3105,
63,
3446,
837,
523,
1449,
1084,
282,
3307,
1403,
315,
314,
2018,
14958,
626,
5419,
543,
3959,
2344,
523,
340,
27149,
26,
489,
687,
14084,
20,
14,
10901,
492,
27149,
5587,
3205,
8481,
523,
687,
10543,
492,
663,
63,
3446,
523,
340,
27149,
26,
489,
27149,
5587,
3205,
8481,
342,
523,
663,
63,
3446,
342,
2126,
199,
533,
25971,
1337,
837,
272,
327,
2600,
3509,
26,
272,
327,
536,
402,
805,
26,
805,
1240,
12,
2536,
2633,
12,
10615,
12,
5137,
3164,
12,
2066,
671,
436,
612,
367,
5343,
272,
327,
1347,
1139,
3862,
12,
1561,
402,
2633,
12,
13770,
867,
1338,
12,
436,
18883,
805,
340,
4346,
14,
272,
327,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
3269,
1532,
1130,
275,
469,
267,
283,
1474,
16,
7,
221,
520,
334,
277,
14,
1474,
16,
2579,
12,
359,
16,
14,
16,
12,
3388,
14,
16,
467,
12293,
12,
283,
75,
297,
359,
16,
12,
2948,
12,
413,
8333,
673,
359,
17,
14,
16,
12,
959,
14,
16,
467,
788,
33,
16,
297,
283,
16656,
995,
488,
12,
488,
395,
267,
283,
1474,
17,
7,
221,
520,
334,
277,
14,
476,
321,
637,
12,
359,
16,
14,
16,
12,
378,
14,
16,
12,
3388,
14,
16,
467,
12293,
12,
283,
75,
297,
359,
16,
12,
2948,
12,
413,
8333,
673,
359,
16,
14,
21,
12,
413,
14,
16,
12,
959,
14,
16,
467,
788,
5196,
297,
283,
33,
16,
297,
283,
16656,
995,
488,
12,
291,
14,
476,
321,
637,
12446,
395,
267,
283,
476,
1190,
453,
7,
221,
520,
334,
277,
14,
476,
1190,
940,
637,
12,
221,
359,
16,
14,
16,
12,
446,
16,
14,
21,
12,
1926,
14,
16,
12,
446,
16,
14,
821,
12,
841,
1400,
14,
16,
467,
959,
5345,
12,
283,
75,
297,
221,
359,
16,
12,
5198,
12,
413,
8333,
673,
359,
16,
14,
16,
12,
446,
17,
14,
16,
12,
14711,
14,
16,
12,
446,
16,
14,
821,
12,
31921,
14,
16,
467,
788,
5196,
297,
283,
33,
16,
297,
283,
16656,
16,
297,
283,
33,
17,
297,
283,
16656,
17,
995,
488,
12,
488,
395,
267,
283,
476,
1190,
453,
18,
7,
221,
520,
334,
277,
14,
476,
1190,
940,
637,
18,
12,
221,
359,
16,
2020,
446,
16,
14,
21,
12,
446,
16,
14,
7991,
467,
959,
993,
12,
283,
75,
297,
221,
359,
16,
12,
5198,
12,
413,
8333,
673,
359,
16,
2020,
446,
16,
14,
21,
12,
446,
16,
14,
821,
467,
788,
33,
16,
297,
283,
33,
17,
995,
359,
21,
2020,
3388,
8333,
488,
395,
267,
283,
1474,
18,
7,
221,
520,
334,
277,
14,
1474,
18,
2579,
12,
221,
359,
16,
14,
16,
12,
446,
16,
14,
21,
12,
1926,
14,
16,
12,
446,
16,
14,
821,
12,
841,
1400,
14,
16,
467,
959,
5345,
12,
283,
75,
297,
221,
359,
16,
12,
5198,
12,
413,
8333,
673,
359,
16,
14,
16,
12,
446,
17,
14,
16,
12,
14711,
14,
16,
12,
446,
16,
14,
821,
12,
31921,
14,
16,
467,
788,
5196,
297,
283,
33,
16,
297,
283,
16656,
16
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
4718,
1021,
4975,
367,
666,
21774,
14,
199,
22792,
314,
2569,
5957,
3102,
26,
199,
362,
13967,
2529,
314,
769,
402,
805,
1561,
334,
9086,
2883,
9,
199,
13776,
10708,
18628,
314,
21774,
199,
7443,
626,
25971,
10708,
911,
5137,
641,
2746,
402,
314,
1453,
666,
1808,
27365,
4555,
14975,
199,
692,
314,
1453,
15318,
436,
314,
1453,
5137,
1256,
787,
3032,
14,
199,
199,
624,
199,
3,
17474,
20527,
12,
8937,
199,
3,
28574,
699,
14,
4688,
374,
12,
11308,
14,
36,
14,
199,
3,
738,
6389,
2799,
924,
76,
869,
778,
199,
3,
1487,
12493,
402,
593,
6896,
695,
78,
1939,
4956,
15,
11664,
436,
5612,
346,
17079,
836,
89,
199,
3,
26167,
701,
653,
19824,
598,
82,
2285,
30592,
16643,
821,
13,
1081,
436,
30592,
7979,
23327,
13,
1780,
370,
510,
15225,
14,
199,
3,
1898,
28574,
4688,
374,
12,
8937,
199,
3,
199,
624,
272,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
199,
624,
272,
10961,
13861,
706,
26,
272,
710,
4132,
8,
83,
9,
3955,
2771,
20940,
323,
626,
1263,
23070,
370,
642,
2240,
12,
503,
272,
1970,
14998,
402,
9266,
4796,
12,
506,
14581,
370,
314,
21646,
4132,
12,
28574,
4688,
374,
12,
737,
272,
299,
1237,
374,
32,
3594,
14,
1097,
14,
8654,
12,
543,
314,
5420,
1004,
298,
2713,
18670,
83,
12972,
3477,
83,
1674,
339,
3390,
26,
961,
2240,
2597,
25749,
641,
314,
377,
2827,
6301,
335,
3959,
8363,
367,
314,
17160,
14,
272,
2047,
1471,
3332,
3520,
8363,
687,
377,
2827,
6301,
335,
5370,
12,
1334,
3932,
4190,
272,
370,
675,
314,
2240,
14,
199,
624,
199,
199,
646,
984,
199,
646,
2680,
199,
646,
7026,
199,
199,
893,
26,
272,
492,
1551,
2992,
272,
25227,
63,
9935,
5123,
275,
715,
199,
2590,
3545,
26,
272,
25227,
63,
9935,
5123,
275,
756,
272,
870,
298,
10924,
1990,
376,
1125,
16306,
1551,
2992,
14,
1448,
1346,
23221,
4496,
2,
199,
199,
646,
5577,
199,
646,
2680,
14,
2355,
421,
199,
3,
504,
1967,
2470,
492,
2599,
17676,
199,
199,
4941,
1658,
1653,
275,
756,
199,
692,
1808,
1658,
1653,
26,
272,
492,
603,
10711,
327,
781,
2387,
25174,
465,
1777,
402,
314,
21774,
199,
199,
318,
3105,
63,
3446,
837,
523,
1449,
1084,
282,
3307,
1403,
315,
314,
2018,
14958,
626,
5419,
543,
3959,
2344,
523,
340,
27149,
26,
489,
687,
14084,
20,
14,
10901,
492,
27149,
5587,
3205,
8481,
523,
687,
10543,
492,
663,
63,
3446,
523,
340,
27149,
26,
489,
27149,
5587,
3205,
8481,
342,
523,
663,
63,
3446,
342,
2126,
199,
533,
25971,
1337,
837,
272,
327,
2600,
3509,
26,
272,
327,
536,
402,
805,
26,
805,
1240,
12,
2536,
2633,
12,
10615,
12,
5137,
3164,
12,
2066,
671,
436,
612,
367,
5343,
272,
327,
1347,
1139,
3862,
12,
1561,
402,
2633,
12,
13770,
867,
1338,
12,
436,
18883,
805,
340,
4346,
14,
272,
327,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
3269,
1532,
1130,
275,
469,
267,
283,
1474,
16,
7,
221,
520,
334,
277,
14,
1474,
16,
2579,
12,
359,
16,
14,
16,
12,
3388,
14,
16,
467,
12293,
12,
283,
75,
297,
359,
16,
12,
2948,
12,
413,
8333,
673,
359,
17,
14,
16,
12,
959,
14,
16,
467,
788,
33,
16,
297,
283,
16656,
995,
488,
12,
488,
395,
267,
283,
1474,
17,
7,
221,
520,
334,
277,
14,
476,
321,
637,
12,
359,
16,
14,
16,
12,
378,
14,
16,
12,
3388,
14,
16,
467,
12293,
12,
283,
75,
297,
359,
16,
12,
2948,
12,
413,
8333,
673,
359,
16,
14,
21,
12,
413,
14,
16,
12,
959,
14,
16,
467,
788,
5196,
297,
283,
33,
16,
297,
283,
16656,
995,
488,
12,
291,
14,
476,
321,
637,
12446,
395,
267,
283,
476,
1190,
453,
7,
221,
520,
334,
277,
14,
476,
1190,
940,
637,
12,
221,
359,
16,
14,
16,
12,
446,
16,
14,
21,
12,
1926,
14,
16,
12,
446,
16,
14,
821,
12,
841,
1400,
14,
16,
467,
959,
5345,
12,
283,
75,
297,
221,
359,
16,
12,
5198,
12,
413,
8333,
673,
359,
16,
14,
16,
12,
446,
17,
14,
16,
12,
14711,
14,
16,
12,
446,
16,
14,
821,
12,
31921,
14,
16,
467,
788,
5196,
297,
283,
33,
16,
297,
283,
16656,
16,
297,
283,
33,
17,
297,
283,
16656,
17,
995,
488,
12,
488,
395,
267,
283,
476,
1190,
453,
18,
7,
221,
520,
334,
277,
14,
476,
1190,
940,
637,
18,
12,
221,
359,
16,
2020,
446,
16,
14,
21,
12,
446,
16,
14,
7991,
467,
959,
993,
12,
283,
75,
297,
221,
359,
16,
12,
5198,
12,
413,
8333,
673,
359,
16,
2020,
446,
16,
14,
21,
12,
446,
16,
14,
821,
467,
788,
33,
16,
297,
283,
33,
17,
995,
359,
21,
2020,
3388,
8333,
488,
395,
267,
283,
1474,
18,
7,
221,
520,
334,
277,
14,
1474,
18,
2579,
12,
221,
359,
16,
14,
16,
12,
446,
16,
14,
21,
12,
1926,
14,
16,
12,
446,
16,
14,
821,
12,
841,
1400,
14,
16,
467,
959,
5345,
12,
283,
75,
297,
221,
359,
16,
12,
5198,
12,
413,
8333,
673,
359,
16,
14,
16,
12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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
] |
wangxin39/xstat
|
ManageSystem/WebContent/fckeditor/editor/filemanager/connectors/py/connector.py
|
55
|
4026
|
#!/usr/bin/env python
"""
FCKeditor - The text editor for Internet - http://www.fckeditor.net
Copyright (C) 2003-2008 Frederico Caldeira Knabben
== BEGIN LICENSE ==
Licensed under the terms of any of the following licenses at your
choice:
- GNU General Public License Version 2 or later (the "GPL")
http://www.gnu.org/licenses/gpl.html
- GNU Lesser General Public License Version 2.1 or later (the "LGPL")
http://www.gnu.org/licenses/lgpl.html
- Mozilla Public License Version 1.1 or later (the "MPL")
http://www.mozilla.org/MPL/MPL-1.1.html
== END LICENSE ==
Connector for Python (CGI and WSGI).
See config.py for configuration settings
"""
import os
from fckutil import *
from fckcommands import * # default command's implementation
from fckoutput import * # base http, xml and html output mixins
from fckconnector import FCKeditorConnectorBase # import base connector
import config as Config
class FCKeditorConnector( FCKeditorConnectorBase,
GetFoldersCommandMixin,
GetFoldersAndFilesCommandMixin,
CreateFolderCommandMixin,
UploadFileCommandMixin,
BaseHttpMixin, BaseXmlMixin, BaseHtmlMixin ):
"The Standard connector class."
def doResponse(self):
"Main function. Process the request, set headers and return a string as response."
s = ""
# Check if this connector is disabled
if not(Config.Enabled):
return self.sendError(1, "This connector is disabled. Please check the connector configurations in \"editor/filemanager/connectors/py/config.py\" and try again.")
# Make sure we have valid inputs
for key in ("Command","Type","CurrentFolder"):
if not self.request.has_key (key):
return
# Get command, resource type and current folder
command = self.request.get("Command")
resourceType = self.request.get("Type")
currentFolder = getCurrentFolder(self.request.get("CurrentFolder"))
# Check for invalid paths
if currentFolder is None:
return self.sendError(102, "")
# Check if it is an allowed command
if ( not command in Config.ConfigAllowedCommands ):
return self.sendError( 1, 'The %s command isn\'t allowed' % command )
if ( not resourceType in Config.ConfigAllowedTypes ):
return self.sendError( 1, 'Invalid type specified' )
# Setup paths
if command == "QuickUpload":
self.userFilesFolder = Config.QuickUploadAbsolutePath[resourceType]
self.webUserFilesFolder = Config.QuickUploadPath[resourceType]
else:
self.userFilesFolder = Config.FileTypesAbsolutePath[resourceType]
self.webUserFilesFolder = Config.FileTypesPath[resourceType]
if not self.userFilesFolder: # no absolute path given (dangerous...)
self.userFilesFolder = mapServerPath(self.environ,
self.webUserFilesFolder)
# Ensure that the directory exists.
if not os.path.exists(self.userFilesFolder):
try:
self.createServerFoldercreateServerFolder( self.userFilesFolder )
except:
return self.sendError(1, "This connector couldn\'t access to local user\'s files directories. Please check the UserFilesAbsolutePath in \"editor/filemanager/connectors/py/config.py\" and try again. ")
# File upload doesn't have to return XML, so intercept here
if (command == "FileUpload"):
return self.uploadFile(resourceType, currentFolder)
# Create Url
url = combinePaths( self.webUserFilesFolder, currentFolder )
# Begin XML
s += self.createXmlHeader(command, resourceType, currentFolder, url)
# Execute the command
selector = {"GetFolders": self.getFolders,
"GetFoldersAndFiles": self.getFoldersAndFiles,
"CreateFolder": self.createFolder,
}
s += selector[command](resourceType, currentFolder)
s += self.createXmlFooter()
return s
# Running from command line (plain old CGI)
if __name__ == '__main__':
try:
# Create a Connector Instance
conn = FCKeditorConnector()
data = conn.doResponse()
for header in conn.headers:
print '%s: %s' % header
print
print data
except:
print "Content-Type: text/plain"
print
import cgi
cgi.print_exception()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
4161,
1136,
27050,
446,
710,
1318,
8823,
367,
22026,
446,
1455,
921,
1544,
14,
70,
346,
7515,
14,
846,
199,
7384,
334,
35,
9,
13004,
13,
9300,
481,
264,
9910,
331,
8256,
271,
20936,
1804,
78,
12198,
287,
199,
199,
389,
16427,
5113,
508,
199,
199,
31661,
1334,
314,
2895,
402,
1263,
402,
314,
2569,
12378,
737,
2195,
199,
5095,
26,
421,
446,
1664,
1696,
1684,
844,
3394,
499,
503,
2945,
334,
1589,
298,
12006,
531,
2043,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
14,
1360,
421,
446,
1664,
6401,
1696,
1684,
844,
3394,
499,
14,
17,
503,
2945,
334,
1589,
298,
44,
12006,
531,
2043,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
9783,
1168,
14,
1360,
421,
446,
17728,
1684,
844,
3394,
413,
14,
17,
503,
2945,
334,
1589,
298,
3950,
531,
2043,
1455,
921,
1544,
14,
12102,
14,
1308,
15,
3950,
15,
3950,
13,
17,
14,
17,
14,
1360,
199,
199,
389,
7729,
5113,
508,
199,
199,
20476,
367,
2018,
334,
21337,
436,
9279,
680,
199,
199,
9295,
1101,
14,
647,
367,
2897,
2202,
199,
199,
624,
199,
646,
747,
199,
199,
504,
289,
346,
1974,
492,
627,
199,
504,
289,
346,
4405,
492,
627,
221,
198,
3,
849,
1414,
1159,
4514,
199,
504,
289,
346,
1199,
492,
627,
221,
198,
3,
1300,
1455,
12,
2748,
436,
3517,
1072,
13667,
3617,
199,
504,
289,
346,
11815,
492,
20934,
1136,
27050,
20476,
1563,
327,
492,
1300,
13252,
199,
646,
1101,
465,
4094,
199,
199,
533,
20934,
1136,
27050,
20476,
8,
198,
4161,
1136,
27050,
20476,
1563,
12,
5264,
198,
1002,
7850,
83,
3110,
4256,
12,
5264,
198,
1002,
7850,
83,
3325,
5535,
3110,
4256,
12,
5264,
198,
2499,
7850,
3110,
4256,
12,
5264,
198,
10301,
1173,
3110,
4256,
12,
5264,
198,
1563,
5779,
4256,
12,
3523,
8672,
4256,
12,
3523,
12957,
4256,
221,
3461,
199,
198,
2,
1918,
9739,
13252,
1021,
2122,
199,
198,
318,
886,
2364,
8,
277,
304,
507,
198,
2,
6756,
805,
14,
7132,
314,
1056,
12,
663,
2323,
436,
372,
282,
1059,
465,
1177,
2122,
507,
198,
83,
275,
3087,
507,
198,
3,
2670,
340,
642,
13252,
365,
6980,
507,
198,
692,
440,
8,
2028,
14,
6589,
304,
686,
198,
1107,
291,
14,
2254,
547,
8,
17,
12,
298,
2765,
13252,
365,
6980,
14,
221,
7754,
1104,
314,
13252,
13422,
315,
8441,
7515,
15,
493,
2609,
15,
2242,
1384,
15,
647,
15,
888,
14,
647,
4451,
436,
862,
4020,
2685,
507,
198,
3,
4155,
3238,
781,
1172,
1686,
4153,
507,
198,
509,
790,
315,
1689,
3110,
2266,
804,
2266,
5639,
7850,
2349,
686,
198,
692,
440,
291,
14,
1069,
14,
1989,
63,
498,
334,
498,
304,
1585,
198,
1107,
507,
198,
3,
2372,
1414,
12,
2073,
730,
436,
1453,
4922,
507,
198,
1531,
275,
291,
14,
1069,
14,
362,
480,
3110,
531,
507,
198,
1927,
804,
275,
291,
14,
1069,
14,
362,
480,
804,
531,
507,
198,
1818,
7850,
275,
664,
5639,
7850,
8,
277,
14,
1069,
14,
362,
480,
5639,
7850,
2237,
507,
198,
3,
2670,
367,
3866,
3792,
507,
198,
692,
1453,
7850,
365,
488,
26,
686,
198,
1107,
291,
14,
2254,
547,
8,
7759,
12,
6899,
2742,
198,
3,
2670,
340,
652,
365,
376,
4370,
1414,
507,
198,
692,
334,
440,
1414,
315,
4094,
14,
2028,
16070,
14680,
3461,
686,
198,
1107,
291,
14,
2254,
547,
8,
413,
12,
283,
1918,
450,
83,
1414,
5712,
3985,
84,
4370,
7,
450,
1414,
776,
2742,
198,
692,
334,
440,
2073,
804,
315,
4094,
14,
2028,
16070,
4100,
221,
3461,
686,
198,
1107,
291,
14,
2254,
547,
8,
413,
12,
283,
3364,
730,
2013,
7,
776,
2742,
198,
3,
12439,
3792,
507,
198,
692,
1414,
508,
298,
19684,
10301,
582,
686,
198,
277,
14,
751,
5535,
7850,
275,
4094,
14,
19684,
10301,
24677,
2042,
59,
1927,
804,
61,
686,
198,
277,
14,
2520,
1899,
5535,
7850,
275,
221,
4094,
14,
19684,
10301,
2042,
59,
1927,
804,
61,
507,
198,
2836,
26,
686,
198,
277,
14,
751,
5535,
7850,
275,
4094,
14,
1173,
4100,
24677,
2042,
59,
1927,
804,
61,
686,
198,
277,
14,
2520,
1899,
5535,
7850,
275,
4094,
14,
1173,
4100,
2042,
59,
1927,
804,
61,
2742,
198,
692,
440,
291,
14,
751,
5535,
7850,
26,
327,
949,
3679,
931,
1627,
334,
31444,
11965,
686,
198,
277,
14,
751,
5535,
7850,
275,
2341,
3120,
2042,
8,
277,
14,
2314,
12,
22680,
198,
277,
14,
2520,
1899,
5535,
7850,
9,
507,
198,
3,
7523,
626,
314,
2082,
3495,
14,
507,
198,
692,
440,
747,
14,
515,
14,
2444,
8,
277,
14,
751,
5535,
7850,
304,
686,
198,
893,
26,
1585,
198,
277,
14,
981,
3120,
7850,
981,
3120,
7850,
8,
291,
14,
751,
5535,
7850,
776,
686,
198,
2590,
26,
1585,
198,
1107,
291,
14,
2254,
547,
8,
17,
12,
298,
2765,
13252,
21554,
3985,
84,
2879,
370,
2257,
922,
3985,
83,
1584,
6602,
14,
221,
7754,
1104,
314,
2876,
5535,
24677,
2042,
315,
8441,
7515,
15,
493,
2609,
15,
2242,
1384,
15,
647,
15,
888,
14,
647,
4451,
436,
862,
4020,
14,
6099,
2742,
198,
3,
3814,
5802,
3181,
1133,
1172,
370,
372,
4692,
12,
880,
13926,
2348,
507,
198,
692,
334,
1531,
508,
298,
1173,
10301,
2349,
686,
198,
1107,
291,
14,
5064,
1173,
8,
1927,
804,
12,
1453,
7850,
9,
2742,
198,
3,
2790,
20503,
507,
198,
633,
275,
13323,
11804,
8,
291,
14,
2520,
1899,
5535,
7850,
12,
1453,
7850,
776,
2742,
198,
3,
25754,
4692,
507,
198,
83,
847,
291,
14,
981,
8672,
2567,
8,
1531,
12,
2073,
804,
12,
1453,
7850,
12,
1166,
9,
507,
198,
3,
17009,
314,
1414,
507,
198,
6662,
275,
2420,
1002,
7850,
83,
582,
291,
14,
362,
7850,
83,
12,
1871,
198,
2,
1002,
7850,
83,
3325,
5535,
582,
291,
14,
362,
7850,
83,
3325,
5535,
12,
1871,
198,
2,
2499,
7850,
582,
291,
14,
981,
7850,
12,
1871,
198,
93,
507,
198,
83,
847,
9759,
59,
1531,
8738,
1927,
804,
12,
1453,
7850,
9,
507,
198,
83,
847,
291,
14,
981,
8672,
5686,
351,
342,
507,
198,
1107,
308
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
4161,
1136,
27050,
446,
710,
1318,
8823,
367,
22026,
446,
1455,
921,
1544,
14,
70,
346,
7515,
14,
846,
199,
7384,
334,
35,
9,
13004,
13,
9300,
481,
264,
9910,
331,
8256,
271,
20936,
1804,
78,
12198,
287,
199,
199,
389,
16427,
5113,
508,
199,
199,
31661,
1334,
314,
2895,
402,
1263,
402,
314,
2569,
12378,
737,
2195,
199,
5095,
26,
421,
446,
1664,
1696,
1684,
844,
3394,
499,
503,
2945,
334,
1589,
298,
12006,
531,
2043,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
14,
1360,
421,
446,
1664,
6401,
1696,
1684,
844,
3394,
499,
14,
17,
503,
2945,
334,
1589,
298,
44,
12006,
531,
2043,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
9783,
1168,
14,
1360,
421,
446,
17728,
1684,
844,
3394,
413,
14,
17,
503,
2945,
334,
1589,
298,
3950,
531,
2043,
1455,
921,
1544,
14,
12102,
14,
1308,
15,
3950,
15,
3950,
13,
17,
14,
17,
14,
1360,
199,
199,
389,
7729,
5113,
508,
199,
199,
20476,
367,
2018,
334,
21337,
436,
9279,
680,
199,
199,
9295,
1101,
14,
647,
367,
2897,
2202,
199,
199,
624,
199,
646,
747,
199,
199,
504,
289,
346,
1974,
492,
627,
199,
504,
289,
346,
4405,
492,
627,
221,
198,
3,
849,
1414,
1159,
4514,
199,
504,
289,
346,
1199,
492,
627,
221,
198,
3,
1300,
1455,
12,
2748,
436,
3517,
1072,
13667,
3617,
199,
504,
289,
346,
11815,
492,
20934,
1136,
27050,
20476,
1563,
327,
492,
1300,
13252,
199,
646,
1101,
465,
4094,
199,
199,
533,
20934,
1136,
27050,
20476,
8,
198,
4161,
1136,
27050,
20476,
1563,
12,
5264,
198,
1002,
7850,
83,
3110,
4256,
12,
5264,
198,
1002,
7850,
83,
3325,
5535,
3110,
4256,
12,
5264,
198,
2499,
7850,
3110,
4256,
12,
5264,
198,
10301,
1173,
3110,
4256,
12,
5264,
198,
1563,
5779,
4256,
12,
3523,
8672,
4256,
12,
3523,
12957,
4256,
221,
3461,
199,
198,
2,
1918,
9739,
13252,
1021,
2122,
199,
198,
318,
886,
2364,
8,
277,
304,
507,
198,
2,
6756,
805,
14,
7132,
314,
1056,
12,
663,
2323,
436,
372,
282,
1059,
465,
1177,
2122,
507,
198,
83,
275,
3087,
507,
198,
3,
2670,
340,
642,
13252,
365,
6980,
507,
198,
692,
440,
8,
2028,
14,
6589,
304,
686,
198,
1107,
291,
14,
2254,
547,
8,
17,
12,
298,
2765,
13252,
365,
6980,
14,
221,
7754,
1104,
314,
13252,
13422,
315,
8441,
7515,
15,
493,
2609,
15,
2242,
1384,
15,
647,
15,
888,
14,
647,
4451,
436,
862,
4020,
2685,
507,
198,
3,
4155,
3238,
781,
1172,
1686,
4153,
507,
198,
509,
790,
315,
1689,
3110,
2266,
804,
2266,
5639,
7850,
2349,
686,
198,
692,
440,
291,
14,
1069,
14,
1989,
63,
498,
334,
498,
304,
1585,
198,
1107,
507,
198,
3,
2372,
1414,
12,
2073,
730,
436,
1453,
4922,
507,
198,
1531,
275,
291,
14,
1069,
14,
362,
480,
3110,
531,
507,
198,
1927,
804,
275,
291,
14,
1069,
14,
362,
480,
804,
531,
507,
198,
1818,
7850,
275,
664,
5639,
7850,
8,
277,
14,
1069,
14,
362,
480,
5639,
7850,
2237,
507,
198,
3,
2670,
367,
3866,
3792,
507,
198,
692,
1453,
7850,
365,
488,
26,
686,
198,
1107,
291,
14,
2254,
547,
8,
7759,
12,
6899,
2742,
198,
3,
2670,
340,
652,
365,
376,
4370,
1414,
507,
198,
692,
334,
440,
1414,
315,
4094,
14,
2028,
16070,
14680,
3461,
686,
198,
1107,
291,
14,
2254,
547,
8,
413,
12,
283,
1918,
450,
83,
1414,
5712,
3985,
84,
4370,
7,
450,
1414,
776,
2742,
198,
692,
334,
440,
2073,
804,
315,
4094,
14,
2028,
16070,
4100,
221,
3461,
686,
198,
1107,
291,
14,
2254,
547,
8,
413,
12,
283,
3364,
730,
2013,
7,
776,
2742,
198,
3,
12439,
3792,
507,
198,
692,
1414,
508,
298,
19684,
10301,
582,
686,
198,
277,
14,
751,
5535,
7850,
275,
4094,
14,
19684,
10301,
24677,
2042,
59,
1927,
804,
61,
686,
198,
277,
14,
2520,
1899,
5535,
7850,
275,
221,
4094,
14,
19684,
10301,
2042,
59,
1927,
804,
61,
507,
198,
2836,
26,
686,
198,
277,
14,
751,
5535,
7850,
275,
4094,
14,
1173,
4100,
24677,
2042,
59,
1927,
804,
61,
686,
198,
277,
14,
2520,
1899,
5535,
7850,
275,
4094,
14,
1173,
4100,
2042,
59,
1927,
804,
61,
2742,
198,
692,
440,
291,
14,
751,
5535,
7850,
26,
327,
949,
3679,
931,
1627,
334,
31444,
11965,
686,
198,
277,
14,
751,
5535,
7850,
275,
2341,
3120,
2042,
8,
277,
14,
2314,
12,
22680,
198,
277,
14,
2520,
1899,
5535,
7850,
9,
507,
198,
3,
7523,
626,
314,
2082,
3495,
14,
507,
198,
692,
440,
747,
14,
515,
14,
2444,
8,
277,
14,
751,
5535,
7850,
304,
686,
198,
893,
26,
1585,
198,
277,
14,
981,
3120,
7850,
981,
3120,
7850,
8,
291,
14,
751,
5535,
7850,
776,
686,
198,
2590,
26,
1585,
198,
1107,
291,
14,
2254,
547,
8,
17,
12,
298,
2765,
13252,
21554,
3985,
84,
2879,
370,
2257,
922,
3985,
83,
1584,
6602,
14,
221,
7754,
1104,
314,
2876,
5535,
24677,
2042,
315,
8441,
7515,
15,
493,
2609,
15,
2242,
1384,
15,
647,
15,
888,
14,
647,
4451,
436,
862,
4020,
14,
6099,
2742,
198,
3,
3814,
5802,
3181,
1133,
1172,
370,
372,
4692,
12,
880,
13926,
2348,
507,
198,
692,
334,
1531,
508,
298,
1173,
10301,
2349,
686,
198,
1107,
291,
14,
5064,
1173,
8,
1927,
804,
12,
1453,
7850,
9,
2742,
198,
3,
2790,
20503,
507,
198,
633,
275,
13323,
11804,
8,
291,
14,
2520,
1899,
5535,
7850,
12,
1453,
7850,
776,
2742,
198,
3,
25754,
4692,
507,
198,
83,
847,
291,
14,
981,
8672,
2567,
8,
1531,
12,
2073,
804,
12,
1453,
7850,
12,
1166,
9,
507,
198,
3,
17009,
314,
1414,
507,
198,
6662,
275,
2420,
1002,
7850,
83,
582,
291,
14,
362,
7850,
83,
12,
1871,
198,
2,
1002,
7850,
83,
3325,
5535,
582,
291,
14,
362,
7850,
83,
3325,
5535,
12,
1871,
198,
2,
2499,
7850,
582,
291,
14,
981,
7850,
12,
1871,
198,
93,
507,
198,
83,
847,
9759,
59,
1531,
8738,
1927,
804,
12,
1453,
7850,
9,
507,
198,
83,
847,
291,
14,
981,
8672,
5686,
351,
342,
507,
198,
1107,
308,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
cloudera/hue
|
desktop/core/ext-py/repoze.who-2.3/docs/examples/standalone_login_no_who.py
|
2
|
3146
|
# Standalone login application for demo SSO:
# N.B.: this version does *not* use repoze.who at all, but should produce
# a cookie which repoze.who.plugin.authtkt can use.
import datetime
from paste.auth import auth_tkt
from webob import Request
LOGIN_FORM_TEMPLATE = """\
<html>
<head>
<title> Demo SSO Login </title>
</head>
<body>
<h1> Demo SSO Login </h1>
<p style="color: Red">%(message)s</p>
<form action="#" method="post">
<input type="hidden" name="came_from" value="%(came_from)s" />
<fieldset id="login_name_fs">
<label for="login_name">Login Name</label>
<input type="text" id="login_name" name="login_name" value="%(login_name)s" />
</fieldset>
<fieldset id="password_fs">
<label for="password">Login Name</label>
<input type="password" id="password" name="password" />
</fieldset>
<input type="submit" name="form.submitted" value="Log In" />
</form>
</body>
</html>
"""
# oh emacs python-mode, you disappoint me """
# Clients have to know about these values out-of-band
SECRET = 's33kr1t'
COOKIE_NAME = 'auth_cookie'
MAX_AGE = '3600' # seconds
AUTH = {
'phred': 'y4bb3d4bb4d00',
'bharney': 'b3dr0ck',
}
def _validate(login_name, password):
# Your application's logic goes here
return AUTH.get(login_name) == password
def _get_cookies(environ, value):
later = (datetime.datetime.now() +
datetime.timedelta(seconds=int(MAX_AGE)))
# Wdy, DD-Mon-YY HH:MM:SS GMT
expires = later.strftime('%a, %d %b %Y %H:%M:%S')
# the Expires header is *required* at least for IE7 (IE7 does
# not respect Max-Age)
tail = "; Max-Age=%s; Expires=%s" % (MAX_AGE, expires)
cur_domain = environ.get('HTTP_HOST', environ.get('SERVER_NAME'))
wild_domain = '.' + cur_domain
return [('Set-Cookie', '%s="%s"; Path=/; Domain=%s%s'
% (COOKIE_NAME, value, wild_domain, tail)),
]
def login(environ, start_response):
request = Request(environ)
message = ''
if 'form.submitted' in request.POST:
came_from = request.POST['came_from']
login_name = request.POST['login_name']
password = request.POST['password']
remote_addr = environ['REMOTE_ADDR']
if _validate(login_name, password):
headers = [('Location', came_from)]
ticket = auth_tkt.AuthTicket(SECRET, login_name, remote_addr,
cookie_name=COOKIE_NAME, secure=True,
digest_algo="sha512")
headers = _get_cookies(environ, ticket.cookie_value())
headers.append(('Location', came_from))
start_response('302 Found', headers)
return []
message = 'Authentication failed'
else:
came_from = request.GET.get('came_from', '')
login_name = ''
body = LOGIN_FORM_TEMPLATE % {'message': message,
'came_from': came_from,
'login_name': login_name,
}
start_response('200 OK', [])
return [body]
def main(global_config, **local_config):
return login
|
apache-2.0
|
[
3,
1933,
460,
10636,
4676,
4223,
367,
14779,
428,
4118,
26,
199,
3,
653,
14,
34,
16781,
642,
1015,
1630,
627,
1397,
10,
675,
3831,
806,
14,
11345,
737,
1006,
12,
1325,
1077,
7389,
199,
3,
755,
282,
5494,
1314,
3831,
806,
14,
11345,
14,
2718,
14,
1178,
2663,
84,
883,
675,
14,
199,
646,
2197,
199,
199,
504,
20901,
14,
1178,
492,
1790,
63,
2663,
84,
199,
504,
14568,
492,
4784,
199,
199,
17208,
63,
3516,
63,
7433,
275,
9638,
199,
28,
1360,
30,
199,
28,
2993,
30,
199,
28,
1213,
30,
28939,
428,
4118,
16430,
3068,
1213,
30,
199,
1108,
2993,
30,
199,
28,
2030,
30,
199,
28,
72,
17,
30,
28939,
428,
4118,
16430,
3068,
72,
17,
30,
199,
28,
80,
3449,
628,
2326,
26,
9572,
1743,
2840,
1188,
9,
83,
1108,
80,
30,
199,
28,
964,
1595,
13476,
2,
1083,
628,
1932,
1743,
199,
665,
1210,
730,
628,
5642,
2,
536,
628,
27467,
63,
504,
2,
574,
17662,
27467,
63,
504,
9,
83,
2,
7082,
199,
665,
698,
409,
1305,
628,
2886,
63,
354,
63,
2319,
1743,
523,
665,
1302,
367,
628,
2886,
63,
354,
1743,
8880,
2812,
1108,
1302,
30,
523,
665,
1210,
730,
628,
505,
2,
1305,
628,
2886,
63,
354,
2,
536,
628,
2886,
63,
354,
2,
574,
17662,
2886,
63,
354,
9,
83,
2,
7082,
199,
3068,
698,
409,
30,
199,
665,
698,
409,
1305,
628,
2060,
63,
2319,
1743,
523,
665,
1302,
367,
628,
2060,
1743,
8880,
2812,
1108,
1302,
30,
523,
665,
1210,
730,
628,
2060,
2,
1305,
628,
2060,
2,
536,
628,
2060,
2,
7082,
199,
3068,
698,
409,
30,
199,
665,
1210,
730,
628,
7275,
2,
536,
628,
964,
14,
23736,
2,
574,
628,
2445,
1010,
2,
7082,
199,
1108,
964,
30,
199,
1108,
2030,
30,
199,
1108,
1360,
30,
199,
624,
199,
199,
3,
312,
72,
325,
19309,
2366,
13,
632,
12,
1265,
2153,
439,
1403,
562,
408,
199,
199,
3,
6810,
83,
1172,
370,
5715,
3595,
3520,
1338,
734,
13,
1618,
13,
7877,
199,
12961,
275,
283,
83,
1153,
16779,
17,
84,
7,
199,
13665,
63,
2339,
275,
283,
1178,
63,
5306,
7,
199,
199,
4283,
63,
2962,
275,
283,
11035,
7,
327,
4696,
199,
199,
5580,
275,
469,
272,
283,
838,
581,
356,
283,
89,
20,
2501,
19,
68,
20,
2501,
20,
68,
383,
297,
272,
283,
66,
8210,
23263,
356,
283,
66,
19,
5012,
16,
346,
297,
199,
93,
199,
199,
318,
485,
3502,
8,
2886,
63,
354,
12,
2505,
304,
272,
327,
19519,
4223,
1159,
9661,
13538,
2348,
272,
372,
7560,
14,
362,
8,
2886,
63,
354,
9,
508,
2505,
199,
199,
318,
485,
362,
63,
7792,
8,
2314,
12,
574,
304,
339,
2945,
275,
334,
2083,
14,
2083,
14,
2131,
342,
435,
355,
2197,
14,
7473,
8,
4515,
29,
442,
8,
4283,
63,
2962,
1724,
272,
327,
644,
8161,
12,
29662,
13,
6671,
13,
7080,
26922,
26,
3218,
26,
2300,
19152,
272,
12261,
275,
2945,
14,
6205,
3508,
65,
12,
450,
68,
450,
66,
450,
57,
450,
40,
2689,
45,
2689,
51,
358,
272,
327,
314,
1316,
1038,
470,
1406,
365,
627,
2427,
10,
737,
5210,
367,
15292,
23,
334,
4332,
23,
1630,
272,
327,
440,
14021,
8228,
13,
20480,
9,
272,
9483,
275,
28036,
8228,
13,
20480,
2458,
83,
27,
1316,
1038,
470,
2458,
83,
2,
450,
334,
4283,
63,
2962,
12,
12261,
9,
339,
1094,
63,
2261,
275,
6160,
14,
362,
360,
2856,
63,
5449,
297,
6160,
14,
362,
360,
6613,
63,
2339,
1333,
272,
336,
668,
63,
2261,
275,
7815,
435,
1094,
63,
2261,
339,
372,
4274,
1084,
13,
7810,
297,
1543,
83,
5961,
83,
11436,
6912,
13043,
27,
14061,
2458,
83,
5,
83,
7,
717,
450,
334,
13665,
63,
2339,
12,
574,
12,
336,
668,
63,
2261,
12,
9483,
1826,
1779,
1622,
199,
199,
318,
4676,
8,
2314,
12,
1343,
63,
1310,
304,
272,
1056,
275,
4784,
8,
2314,
9,
272,
1245,
275,
2125,
272,
340,
283,
964,
14,
23736,
7,
315,
1056,
14,
4030,
26,
267,
20382,
63,
504,
275,
1056,
14,
4030,
459,
27467,
63,
504,
418,
267,
4676,
63,
354,
275,
1056,
14,
4030,
459,
2886,
63,
354,
418,
267,
2505,
275,
1056,
14,
4030,
459,
2060,
418,
267,
3982,
63,
2697,
275,
6160,
459,
16058,
63,
7803,
418,
267,
340,
485,
3502,
8,
2886,
63,
354,
12,
2505,
304,
288,
2323,
275,
4274,
6592,
297,
20382,
63,
504,
1874,
288,
12052,
275,
1790,
63,
2663,
84,
14,
2817,
25813,
8,
12961,
12,
4676,
63,
354,
12,
3982,
63,
2697,
12,
1460,
5494,
63,
354,
29,
13665,
63,
2339,
12,
11153,
29,
549,
12,
1460,
10017,
63,
21734,
628,
4835,
7736,
531,
288,
2323,
275,
485,
362,
63,
7792,
8,
2314,
12,
12052,
14,
5306,
63,
585,
1012,
288,
2323,
14,
740,
4725,
6592,
297,
20382,
63,
504,
430,
288,
1343,
63,
1310,
360,
8551,
2643,
297,
2323,
9,
288,
372,
942,
267,
1245,
275,
283,
10348,
3405,
7,
272,
587,
26,
267,
20382,
63,
504,
275,
1056,
14,
2970,
14,
362,
360,
27467,
63,
504,
297,
4074,
267,
4676,
63,
354,
275,
2125,
339,
2396,
275,
5051,
568,
63,
3516,
63,
7433,
450,
791,
1188,
356,
1245,
12,
3303,
283,
27467,
63,
504,
356,
20382,
63,
504,
12,
3303,
283,
2886,
63,
354,
356,
4676,
63,
354,
12,
639,
789,
272,
1343,
63,
1310,
360,
1840,
9949,
297,
3073,
272,
372,
359,
2030,
61,
421,
199,
318,
2446,
8,
2966,
63,
888,
12,
1011,
1832,
63,
888,
304,
272,
372,
4676,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1933,
460,
10636,
4676,
4223,
367,
14779,
428,
4118,
26,
199,
3,
653,
14,
34,
16781,
642,
1015,
1630,
627,
1397,
10,
675,
3831,
806,
14,
11345,
737,
1006,
12,
1325,
1077,
7389,
199,
3,
755,
282,
5494,
1314,
3831,
806,
14,
11345,
14,
2718,
14,
1178,
2663,
84,
883,
675,
14,
199,
646,
2197,
199,
199,
504,
20901,
14,
1178,
492,
1790,
63,
2663,
84,
199,
504,
14568,
492,
4784,
199,
199,
17208,
63,
3516,
63,
7433,
275,
9638,
199,
28,
1360,
30,
199,
28,
2993,
30,
199,
28,
1213,
30,
28939,
428,
4118,
16430,
3068,
1213,
30,
199,
1108,
2993,
30,
199,
28,
2030,
30,
199,
28,
72,
17,
30,
28939,
428,
4118,
16430,
3068,
72,
17,
30,
199,
28,
80,
3449,
628,
2326,
26,
9572,
1743,
2840,
1188,
9,
83,
1108,
80,
30,
199,
28,
964,
1595,
13476,
2,
1083,
628,
1932,
1743,
199,
665,
1210,
730,
628,
5642,
2,
536,
628,
27467,
63,
504,
2,
574,
17662,
27467,
63,
504,
9,
83,
2,
7082,
199,
665,
698,
409,
1305,
628,
2886,
63,
354,
63,
2319,
1743,
523,
665,
1302,
367,
628,
2886,
63,
354,
1743,
8880,
2812,
1108,
1302,
30,
523,
665,
1210,
730,
628,
505,
2,
1305,
628,
2886,
63,
354,
2,
536,
628,
2886,
63,
354,
2,
574,
17662,
2886,
63,
354,
9,
83,
2,
7082,
199,
3068,
698,
409,
30,
199,
665,
698,
409,
1305,
628,
2060,
63,
2319,
1743,
523,
665,
1302,
367,
628,
2060,
1743,
8880,
2812,
1108,
1302,
30,
523,
665,
1210,
730,
628,
2060,
2,
1305,
628,
2060,
2,
536,
628,
2060,
2,
7082,
199,
3068,
698,
409,
30,
199,
665,
1210,
730,
628,
7275,
2,
536,
628,
964,
14,
23736,
2,
574,
628,
2445,
1010,
2,
7082,
199,
1108,
964,
30,
199,
1108,
2030,
30,
199,
1108,
1360,
30,
199,
624,
199,
199,
3,
312,
72,
325,
19309,
2366,
13,
632,
12,
1265,
2153,
439,
1403,
562,
408,
199,
199,
3,
6810,
83,
1172,
370,
5715,
3595,
3520,
1338,
734,
13,
1618,
13,
7877,
199,
12961,
275,
283,
83,
1153,
16779,
17,
84,
7,
199,
13665,
63,
2339,
275,
283,
1178,
63,
5306,
7,
199,
199,
4283,
63,
2962,
275,
283,
11035,
7,
327,
4696,
199,
199,
5580,
275,
469,
272,
283,
838,
581,
356,
283,
89,
20,
2501,
19,
68,
20,
2501,
20,
68,
383,
297,
272,
283,
66,
8210,
23263,
356,
283,
66,
19,
5012,
16,
346,
297,
199,
93,
199,
199,
318,
485,
3502,
8,
2886,
63,
354,
12,
2505,
304,
272,
327,
19519,
4223,
1159,
9661,
13538,
2348,
272,
372,
7560,
14,
362,
8,
2886,
63,
354,
9,
508,
2505,
199,
199,
318,
485,
362,
63,
7792,
8,
2314,
12,
574,
304,
339,
2945,
275,
334,
2083,
14,
2083,
14,
2131,
342,
435,
355,
2197,
14,
7473,
8,
4515,
29,
442,
8,
4283,
63,
2962,
1724,
272,
327,
644,
8161,
12,
29662,
13,
6671,
13,
7080,
26922,
26,
3218,
26,
2300,
19152,
272,
12261,
275,
2945,
14,
6205,
3508,
65,
12,
450,
68,
450,
66,
450,
57,
450,
40,
2689,
45,
2689,
51,
358,
272,
327,
314,
1316,
1038,
470,
1406,
365,
627,
2427,
10,
737,
5210,
367,
15292,
23,
334,
4332,
23,
1630,
272,
327,
440,
14021,
8228,
13,
20480,
9,
272,
9483,
275,
28036,
8228,
13,
20480,
2458,
83,
27,
1316,
1038,
470,
2458,
83,
2,
450,
334,
4283,
63,
2962,
12,
12261,
9,
339,
1094,
63,
2261,
275,
6160,
14,
362,
360,
2856,
63,
5449,
297,
6160,
14,
362,
360,
6613,
63,
2339,
1333,
272,
336,
668,
63,
2261,
275,
7815,
435,
1094,
63,
2261,
339,
372,
4274,
1084,
13,
7810,
297,
1543,
83,
5961,
83,
11436,
6912,
13043,
27,
14061,
2458,
83,
5,
83,
7,
717,
450,
334,
13665,
63,
2339,
12,
574,
12,
336,
668,
63,
2261,
12,
9483,
1826,
1779,
1622,
199,
199,
318,
4676,
8,
2314,
12,
1343,
63,
1310,
304,
272,
1056,
275,
4784,
8,
2314,
9,
272,
1245,
275,
2125,
272,
340,
283,
964,
14,
23736,
7,
315,
1056,
14,
4030,
26,
267,
20382,
63,
504,
275,
1056,
14,
4030,
459,
27467,
63,
504,
418,
267,
4676,
63,
354,
275,
1056,
14,
4030,
459,
2886,
63,
354,
418,
267,
2505,
275,
1056,
14,
4030,
459,
2060,
418,
267,
3982,
63,
2697,
275,
6160,
459,
16058,
63,
7803,
418,
267,
340,
485,
3502,
8,
2886,
63,
354,
12,
2505,
304,
288,
2323,
275,
4274,
6592,
297,
20382,
63,
504,
1874,
288,
12052,
275,
1790,
63,
2663,
84,
14,
2817,
25813,
8,
12961,
12,
4676,
63,
354,
12,
3982,
63,
2697,
12,
1460,
5494,
63,
354,
29,
13665,
63,
2339,
12,
11153,
29,
549,
12,
1460,
10017,
63,
21734,
628,
4835,
7736,
531,
288,
2323,
275,
485,
362,
63,
7792,
8,
2314,
12,
12052,
14,
5306,
63,
585,
1012,
288,
2323,
14,
740,
4725,
6592,
297,
20382,
63,
504,
430,
288,
1343,
63,
1310,
360,
8551,
2643,
297,
2323,
9,
288,
372,
942,
267,
1245,
275,
283,
10348,
3405,
7,
272,
587,
26,
267,
20382,
63,
504,
275,
1056,
14,
2970,
14,
362,
360,
27467,
63,
504,
297,
4074,
267,
4676,
63,
354,
275,
2125,
339,
2396,
275,
5051,
568,
63,
3516,
63,
7433,
450,
791,
1188,
356,
1245,
12,
3303,
283,
27467,
63,
504,
356,
20382,
63,
504,
12,
3303,
283,
2886,
63,
354,
356,
4676,
63,
354,
12,
639,
789,
272,
1343,
63,
1310,
360,
1840,
9949,
297,
3073,
272,
372,
359,
2030,
61,
421,
199,
318,
2446,
8,
2966,
63,
888,
12,
1011,
1832,
63,
888,
304,
272,
372,
4676,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
abought/osf.io
|
scripts/migrate_unregistered.py
|
61
|
4757
|
#!/usr/bin/env
# -*- coding: utf-8 -*-
"""Migrates old-style unregistered users (dictionaries in Node#contributor_list)
to actual User records.
"""
import logging
from modularodm.exceptions import ValidationValueError
from website import app, models
from framework import auth
from framework.auth import Auth
from tests.base import OsfTestCase
from tests.factories import DeprecatedUnregUserFactory, ProjectFactory, UserFactory
logging.getLogger('factory.generate:BaseFactory').setLevel(logging.WARNING)
logger = logging.getLogger(__name__)
def main():
app.init_app()
for node in models.Node.find():
migrate_contributors(node)
def make_user(user_dict):
if 'id' in user_dict:
user = models.User.load(user_dict['id'])
else:
name, email = user_dict['nr_name'], user_dict['nr_email']
try:
user = models.User.create_unregistered(fullname=name,
email=email)
user.save()
except ValidationValueError:
user = auth.get_user(email=email)
if user is None:
logger.error('Could not load user {0}'.format(user_dict))
return user
def migrate_user(user_dict, node):
user = make_user(user_dict)
if user is None:
logger.error('Could not load user {0}'.format(user_dict))
return
# Add unclaimed_record to unregistered users for a given node
if not user.is_registered:
# First contributor (usually the creator) will be recorded as the referrer
# of unregistered users
try:
referrer = node.contributors[0]
except IndexError:
if node.creator:
referrer = node.creator
else: # meh
return
user.add_unclaimed_record(node=node, referrer=referrer,
given_name=user_dict['nr_name'], email=user_dict['nr_email'])
logger.info(u'Migrated unregistered user {0}'.format(user.username))
try:
user.save()
except Exception as error:
logging.error(user_dict)
raise error
return user
def migrate_contributors(node):
node.contributors = [
migrate_user(user_dict, node) for user_dict in node.contributor_list
]
logger.info(u'Finished migrating unregistered '
'contributors for node {0}'.format(node._primary_key))
return node.save()
# To run tests: pytest scripts/migrate_unregistered.py
# or nosetests scripts/migrate_unregistered.py
class TestMigratingUnreg(OsfTestCase):
def test_make_user_from_reg_user(self):
reg_user = UserFactory(is_registered=True)
user = make_user({'id': reg_user._primary_key})
assert user == reg_user
def test_make_user_from_old_unreg_user(self):
old_style = DeprecatedUnregUserFactory()
user = make_user(old_style)
user.save()
assert isinstance(user, models.User)
assert user.is_registered is False
assert user.fullname == old_style['nr_name']
assert user.username == old_style['nr_email']
assert old_style['nr_email'] in user.emails
def test_migrate_contributors(self):
creator = UserFactory(is_registered=True)
project = ProjectFactory(creator=creator)
auth = Auth(project.creator)
contrib1 = UserFactory()
project.add_contributor(contrib1, auth=auth)
project.save()
# sanity checks
assert len(project.contributor_list) == 2
nr_contrib = DeprecatedUnregUserFactory()
project.contributor_list.append(nr_contrib)
project.save()
assert len(project.contributors) == 2
assert len(project.contributor_list) == 3
old_length = len(project.contributor_list)
migrate_contributors(project)
project.save()
assert len(project.contributor_list) == old_length
assert len(project.contributors) == old_length
migrated_user = project.contributors[-1]
assert migrated_user.fullname == nr_contrib['nr_name']
assert migrated_user.is_registered is False
# has an unclaimed record
assert project._primary_key in migrated_user.unclaimed_records
rec = migrated_user.get_unclaimed_record(project._primary_key)
assert rec['name'] == nr_contrib['nr_name']
assert rec['referrer_id'] == creator._primary_key
assert rec['token']
assert rec['email'] == nr_contrib['nr_email']
def test_migrate_nr_user_with_same_email_as_registered_user(self):
reg_user = UserFactory(is_registered=True)
unreg_user = DeprecatedUnregUserFactory(nr_email=reg_user.username)
assert make_user(unreg_user) == reg_user
if __name__ == '__main__':
main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
19322,
17153,
2269,
13,
2487,
625,
11616,
4390,
334,
328,
10150,
315,
5013,
3,
16833,
63,
513,
9,
199,
475,
3503,
2876,
5767,
14,
199,
624,
199,
646,
2050,
199,
199,
504,
3413,
2238,
364,
77,
14,
3924,
492,
19381,
3393,
199,
504,
10691,
492,
1145,
12,
1709,
199,
504,
10059,
492,
1790,
199,
504,
10059,
14,
1178,
492,
3590,
199,
504,
2295,
14,
1095,
492,
593,
7646,
1746,
199,
504,
2295,
14,
15406,
492,
17993,
1358,
1135,
24594,
12,
32249,
12,
16047,
421,
199,
4806,
14,
5572,
360,
3702,
14,
4208,
26,
1563,
2927,
1959,
13548,
8,
4806,
14,
9171,
9,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
2446,
837,
272,
1145,
14,
826,
63,
571,
342,
272,
367,
1031,
315,
1709,
14,
1716,
14,
1623,
837,
267,
12810,
63,
21630,
8,
932,
9,
421,
199,
318,
1852,
63,
751,
8,
751,
63,
807,
304,
272,
340,
283,
344,
7,
315,
922,
63,
807,
26,
267,
922,
275,
1709,
14,
1899,
14,
912,
8,
751,
63,
807,
459,
344,
1105,
272,
587,
26,
267,
536,
12,
3031,
275,
922,
63,
807,
459,
7865,
63,
354,
995,
922,
63,
807,
459,
7865,
63,
2123,
418,
267,
862,
26,
288,
922,
275,
1709,
14,
1899,
14,
981,
63,
324,
11616,
8,
9930,
29,
354,
12,
355,
3031,
29,
2123,
9,
288,
922,
14,
2117,
342,
267,
871,
19381,
3393,
26,
288,
922,
275,
1790,
14,
362,
63,
751,
8,
2123,
29,
2123,
9,
288,
340,
922,
365,
488,
26,
355,
2512,
14,
705,
360,
6531,
440,
2248,
922,
469,
16,
5285,
908,
8,
751,
63,
807,
430,
272,
372,
922,
421,
199,
318,
12810,
63,
751,
8,
751,
63,
807,
12,
1031,
304,
272,
922,
275,
1852,
63,
751,
8,
751,
63,
807,
9,
272,
340,
922,
365,
488,
26,
267,
2512,
14,
705,
360,
6531,
440,
2248,
922,
469,
16,
5285,
908,
8,
751,
63,
807,
430,
267,
372,
272,
327,
2654,
625,
31563,
63,
3059,
370,
625,
11616,
4390,
367,
282,
1627,
1031,
272,
340,
440,
922,
14,
374,
63,
11616,
26,
267,
327,
7758,
11615,
334,
25118,
314,
14875,
9,
911,
506,
18894,
465,
314,
10618,
3859,
267,
327,
402,
625,
11616,
4390,
267,
862,
26,
288,
10618,
3859,
275,
1031,
14,
21630,
59,
16,
61,
267,
871,
7888,
26,
288,
340,
1031,
14,
9986,
26,
355,
10618,
3859,
275,
1031,
14,
9986,
288,
587,
26,
221,
327,
562,
72,
355,
372,
267,
922,
14,
525,
63,
1097,
416,
21538,
63,
3059,
8,
932,
29,
932,
12,
10618,
3859,
29,
21928,
3859,
12,
288,
1627,
63,
354,
29,
751,
63,
807,
459,
7865,
63,
354,
995,
3031,
29,
751,
63,
807,
459,
7865,
63,
2123,
1105,
267,
2512,
14,
815,
8,
85,
7,
19322,
12601,
625,
11616,
922,
469,
16,
5285,
908,
8,
751,
14,
2473,
430,
267,
862,
26,
288,
922,
14,
2117,
342,
267,
871,
2186,
465,
1125,
26,
288,
2050,
14,
705,
8,
751,
63,
807,
9,
288,
746,
1125,
272,
372,
922,
421,
199,
318,
12810,
63,
21630,
8,
932,
304,
272,
1031,
14,
21630,
275,
359,
267,
12810,
63,
751,
8,
751,
63,
807,
12,
1031,
9,
367,
922,
63,
807,
315,
1031,
14,
16833,
63,
513,
339,
1622,
272,
2512,
14,
815,
8,
85,
7,
13430,
3952,
10417,
625,
11616,
283,
267,
283,
21630,
367,
1031,
469,
16,
5285,
908,
8,
932,
423,
3327,
63,
498,
430,
272,
372,
1031,
14,
2117,
342,
199,
199,
3,
4005,
1255,
2295,
26,
4613,
10554,
15,
8462,
63,
324,
11616,
14,
647,
199,
3,
503,
11354,
2219,
10554,
15,
8462,
63,
324,
11616,
14,
647,
199,
533,
1379,
19322,
10417,
1358,
1135,
8,
47,
7646,
1746,
304,
339,
347,
511,
63,
1875,
63,
751,
63,
504,
63,
1135,
63,
751,
8,
277,
304,
267,
1295,
63,
751,
275,
16047,
8,
374,
63,
11616,
29,
549,
9,
267,
922,
275,
1852,
63,
751,
3252,
344,
356,
1295,
63,
751,
423,
3327,
63,
498,
1552,
267,
702,
922,
508,
1295,
63,
751,
339,
347,
511,
63,
1875,
63,
751,
63,
504,
63,
1753,
63,
324,
1135,
63,
751,
8,
277,
304,
267,
2269,
63,
2487,
275,
17993,
1358,
1135,
24594,
342,
267,
922,
275,
1852,
63,
751,
8,
1753,
63,
2487,
9,
267,
922,
14,
2117,
342,
267,
702,
1228,
8,
751,
12,
1709,
14,
1899,
9,
267,
702,
922,
14,
374,
63,
11616,
365,
756,
267,
702,
922,
14,
9930,
508,
2269,
63,
2487,
459,
7865,
63,
354,
418,
267,
702,
922,
14,
2473,
508,
2269,
63,
2487,
459,
7865,
63,
2123,
418,
267,
702,
2269,
63,
2487,
459,
7865,
63,
2123,
418,
315,
922,
14,
14170,
339,
347,
511,
63,
8462,
63,
21630,
8,
277,
304,
267,
14875,
275,
16047,
8,
374,
63,
11616,
29,
549,
9,
267,
2199,
275,
32249,
8,
9986,
29,
9986,
9,
267,
1790,
275,
3590,
8,
1715,
14,
9986,
9,
398,
5914,
17,
275,
16047,
342,
267,
2199,
14,
525,
63,
16833,
8,
2828,
17,
12,
1790,
29,
1178,
9,
267,
2199,
14,
2117,
342,
267,
327,
16740,
5920,
267,
702,
822,
8,
1715,
14,
16833,
63,
513,
9,
508,
499,
398,
14762,
63,
2828,
275,
17993,
1358,
1135,
24594,
342,
267,
2199,
14,
16833,
63,
513,
14,
740,
8,
7865,
63,
2828,
9,
267,
2199,
14,
2117,
342,
267,
702,
822,
8,
1715,
14,
21630,
9,
508,
499,
267,
702,
822,
8,
1715,
14,
16833,
63,
513,
9,
508,
650,
267,
2269,
63,
1267,
275,
822,
8,
1715,
14,
16833,
63,
513,
9,
398,
12810,
63,
21630,
8,
1715,
9,
267,
2199,
14,
2117,
342,
398,
702,
822,
8,
1715,
14,
16833,
63,
513,
9,
508,
2269,
63,
1267,
267,
702,
822,
8,
1715,
14,
21630,
9,
508,
2269,
63,
1267,
398,
28322,
63,
751,
275,
2199,
14,
21630,
1988,
17,
61,
267,
702,
28322,
63,
751,
14,
9930,
508,
14762,
63,
2828,
459,
7865,
63,
354,
418,
267,
702,
28322,
63,
751,
14,
374,
63,
11616,
365,
756,
398,
327,
965,
376,
625,
31563,
2777,
267,
702,
2199,
423,
3327
] |
[
2647,
15,
1393,
15,
1813,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
19322,
17153,
2269,
13,
2487,
625,
11616,
4390,
334,
328,
10150,
315,
5013,
3,
16833,
63,
513,
9,
199,
475,
3503,
2876,
5767,
14,
199,
624,
199,
646,
2050,
199,
199,
504,
3413,
2238,
364,
77,
14,
3924,
492,
19381,
3393,
199,
504,
10691,
492,
1145,
12,
1709,
199,
504,
10059,
492,
1790,
199,
504,
10059,
14,
1178,
492,
3590,
199,
504,
2295,
14,
1095,
492,
593,
7646,
1746,
199,
504,
2295,
14,
15406,
492,
17993,
1358,
1135,
24594,
12,
32249,
12,
16047,
421,
199,
4806,
14,
5572,
360,
3702,
14,
4208,
26,
1563,
2927,
1959,
13548,
8,
4806,
14,
9171,
9,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
2446,
837,
272,
1145,
14,
826,
63,
571,
342,
272,
367,
1031,
315,
1709,
14,
1716,
14,
1623,
837,
267,
12810,
63,
21630,
8,
932,
9,
421,
199,
318,
1852,
63,
751,
8,
751,
63,
807,
304,
272,
340,
283,
344,
7,
315,
922,
63,
807,
26,
267,
922,
275,
1709,
14,
1899,
14,
912,
8,
751,
63,
807,
459,
344,
1105,
272,
587,
26,
267,
536,
12,
3031,
275,
922,
63,
807,
459,
7865,
63,
354,
995,
922,
63,
807,
459,
7865,
63,
2123,
418,
267,
862,
26,
288,
922,
275,
1709,
14,
1899,
14,
981,
63,
324,
11616,
8,
9930,
29,
354,
12,
355,
3031,
29,
2123,
9,
288,
922,
14,
2117,
342,
267,
871,
19381,
3393,
26,
288,
922,
275,
1790,
14,
362,
63,
751,
8,
2123,
29,
2123,
9,
288,
340,
922,
365,
488,
26,
355,
2512,
14,
705,
360,
6531,
440,
2248,
922,
469,
16,
5285,
908,
8,
751,
63,
807,
430,
272,
372,
922,
421,
199,
318,
12810,
63,
751,
8,
751,
63,
807,
12,
1031,
304,
272,
922,
275,
1852,
63,
751,
8,
751,
63,
807,
9,
272,
340,
922,
365,
488,
26,
267,
2512,
14,
705,
360,
6531,
440,
2248,
922,
469,
16,
5285,
908,
8,
751,
63,
807,
430,
267,
372,
272,
327,
2654,
625,
31563,
63,
3059,
370,
625,
11616,
4390,
367,
282,
1627,
1031,
272,
340,
440,
922,
14,
374,
63,
11616,
26,
267,
327,
7758,
11615,
334,
25118,
314,
14875,
9,
911,
506,
18894,
465,
314,
10618,
3859,
267,
327,
402,
625,
11616,
4390,
267,
862,
26,
288,
10618,
3859,
275,
1031,
14,
21630,
59,
16,
61,
267,
871,
7888,
26,
288,
340,
1031,
14,
9986,
26,
355,
10618,
3859,
275,
1031,
14,
9986,
288,
587,
26,
221,
327,
562,
72,
355,
372,
267,
922,
14,
525,
63,
1097,
416,
21538,
63,
3059,
8,
932,
29,
932,
12,
10618,
3859,
29,
21928,
3859,
12,
288,
1627,
63,
354,
29,
751,
63,
807,
459,
7865,
63,
354,
995,
3031,
29,
751,
63,
807,
459,
7865,
63,
2123,
1105,
267,
2512,
14,
815,
8,
85,
7,
19322,
12601,
625,
11616,
922,
469,
16,
5285,
908,
8,
751,
14,
2473,
430,
267,
862,
26,
288,
922,
14,
2117,
342,
267,
871,
2186,
465,
1125,
26,
288,
2050,
14,
705,
8,
751,
63,
807,
9,
288,
746,
1125,
272,
372,
922,
421,
199,
318,
12810,
63,
21630,
8,
932,
304,
272,
1031,
14,
21630,
275,
359,
267,
12810,
63,
751,
8,
751,
63,
807,
12,
1031,
9,
367,
922,
63,
807,
315,
1031,
14,
16833,
63,
513,
339,
1622,
272,
2512,
14,
815,
8,
85,
7,
13430,
3952,
10417,
625,
11616,
283,
267,
283,
21630,
367,
1031,
469,
16,
5285,
908,
8,
932,
423,
3327,
63,
498,
430,
272,
372,
1031,
14,
2117,
342,
199,
199,
3,
4005,
1255,
2295,
26,
4613,
10554,
15,
8462,
63,
324,
11616,
14,
647,
199,
3,
503,
11354,
2219,
10554,
15,
8462,
63,
324,
11616,
14,
647,
199,
533,
1379,
19322,
10417,
1358,
1135,
8,
47,
7646,
1746,
304,
339,
347,
511,
63,
1875,
63,
751,
63,
504,
63,
1135,
63,
751,
8,
277,
304,
267,
1295,
63,
751,
275,
16047,
8,
374,
63,
11616,
29,
549,
9,
267,
922,
275,
1852,
63,
751,
3252,
344,
356,
1295,
63,
751,
423,
3327,
63,
498,
1552,
267,
702,
922,
508,
1295,
63,
751,
339,
347,
511,
63,
1875,
63,
751,
63,
504,
63,
1753,
63,
324,
1135,
63,
751,
8,
277,
304,
267,
2269,
63,
2487,
275,
17993,
1358,
1135,
24594,
342,
267,
922,
275,
1852,
63,
751,
8,
1753,
63,
2487,
9,
267,
922,
14,
2117,
342,
267,
702,
1228,
8,
751,
12,
1709,
14,
1899,
9,
267,
702,
922,
14,
374,
63,
11616,
365,
756,
267,
702,
922,
14,
9930,
508,
2269,
63,
2487,
459,
7865,
63,
354,
418,
267,
702,
922,
14,
2473,
508,
2269,
63,
2487,
459,
7865,
63,
2123,
418,
267,
702,
2269,
63,
2487,
459,
7865,
63,
2123,
418,
315,
922,
14,
14170,
339,
347,
511,
63,
8462,
63,
21630,
8,
277,
304,
267,
14875,
275,
16047,
8,
374,
63,
11616,
29,
549,
9,
267,
2199,
275,
32249,
8,
9986,
29,
9986,
9,
267,
1790,
275,
3590,
8,
1715,
14,
9986,
9,
398,
5914,
17,
275,
16047,
342,
267,
2199,
14,
525,
63,
16833,
8,
2828,
17,
12,
1790,
29,
1178,
9,
267,
2199,
14,
2117,
342,
267,
327,
16740,
5920,
267,
702,
822,
8,
1715,
14,
16833,
63,
513,
9,
508,
499,
398,
14762,
63,
2828,
275,
17993,
1358,
1135,
24594,
342,
267,
2199,
14,
16833,
63,
513,
14,
740,
8,
7865,
63,
2828,
9,
267,
2199,
14,
2117,
342,
267,
702,
822,
8,
1715,
14,
21630,
9,
508,
499,
267,
702,
822,
8,
1715,
14,
16833,
63,
513,
9,
508,
650,
267,
2269,
63,
1267,
275,
822,
8,
1715,
14,
16833,
63,
513,
9,
398,
12810,
63,
21630,
8,
1715,
9,
267,
2199,
14,
2117,
342,
398,
702,
822,
8,
1715,
14,
16833,
63,
513,
9,
508,
2269,
63,
1267,
267,
702,
822,
8,
1715,
14,
21630,
9,
508,
2269,
63,
1267,
398,
28322,
63,
751,
275,
2199,
14,
21630,
1988,
17,
61,
267,
702,
28322,
63,
751,
14,
9930,
508,
14762,
63,
2828,
459,
7865,
63,
354,
418,
267,
702,
28322,
63,
751,
14,
374,
63,
11616,
365,
756,
398,
327,
965,
376,
625,
31563,
2777,
267,
702,
2199,
423,
3327,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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ises
from numpy.testing import assert_array_almost_equal, assert_array_equal
from os import path as op
import warnings
from expyfun._utils import _TempDir, _has_scipy_version
from expyfun.io import read_wav, write_wav
warnings.simplefilter('always')
tempdir = _TempDir()
def test_read_write_wav():
"""Test reading and writing WAV files
"""
fname = op.join(tempdir, 'temp.wav')
data = np.r_[np.random.rand(1000), 1, -1]
fs = 44100
# Use normal 16-bit precision: not great
write_wav(fname, data, fs)
data_read, fs_read = read_wav(fname)
assert_equal(fs_read, fs)
assert_array_almost_equal(data[np.newaxis, :], data_read, 4)
# test our overwrite check
assert_raises(IOError, write_wav, fname, data, fs)
# test forcing fs dtype to int
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
write_wav(fname, data, float(fs), overwrite=True)
assert_equal(len(w), 1)
# Use 64-bit int: not supported
assert_raises(RuntimeError, write_wav, fname, data, fs, dtype=np.int64,
overwrite=True)
# Use 32-bit int: better
write_wav(fname, data, fs, dtype=np.int32, overwrite=True)
data_read, fs_read = read_wav(fname)
assert_equal(fs_read, fs)
assert_array_almost_equal(data[np.newaxis, :], data_read, 7)
if _has_scipy_version('0.13'):
# Use 32-bit float: better
write_wav(fname, data, fs, dtype=np.float32, overwrite=True)
data_read, fs_read = read_wav(fname)
assert_equal(fs_read, fs)
assert_array_almost_equal(data[np.newaxis, :], data_read, 7)
# Use 64-bit float: perfect
write_wav(fname, data, fs, dtype=np.float64, overwrite=True)
data_read, fs_read = read_wav(fname)
assert_equal(fs_read, fs)
assert_array_equal(data[np.newaxis, :], data_read)
else:
assert_raises(RuntimeError, write_wav, fname, data, fs,
dtype=np.float32, overwrite=True)
# Now try multi-dimensional data
data = np.tile(data[np.newaxis, :], (2, 1))
write_wav(fname, data[np.newaxis, :], fs, overwrite=True)
data_read, fs_read = read_wav(fname)
assert_equal(fs_read, fs)
assert_array_almost_equal(data, data_read, 4)
# Make sure our bound check works
assert_raises(ValueError, write_wav, fname, data * 2, fs, overwrite=True)
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2680,
465,
980,
199,
504,
11354,
14,
2537,
492,
702,
63,
1452,
12,
702,
63,
3536,
199,
504,
2680,
14,
4776,
492,
702,
63,
1144,
63,
4398,
63,
1452,
12,
702,
63,
1144,
63,
1452,
199,
504,
747,
492,
931,
465,
1687,
199,
646,
3598,
199,
199,
504,
444,
647,
7036,
423,
1208,
492,
485,
29008,
12,
485,
1989,
63,
14248,
63,
1023,
199,
504,
444,
647,
7036,
14,
2308,
492,
1586,
63,
19118,
12,
2218,
63,
19118,
199,
199,
5451,
14,
18815,
360,
9223,
358,
199,
11567,
275,
485,
29008,
342,
421,
199,
318,
511,
63,
739,
63,
952,
63,
19118,
837,
272,
408,
774,
7664,
436,
3575,
644,
6087,
1584,
272,
408,
272,
6748,
275,
1687,
14,
904,
8,
11567,
12,
283,
808,
14,
19118,
358,
272,
666,
275,
980,
14,
82,
9925,
1590,
14,
2355,
14,
3759,
8,
5279,
395,
413,
12,
446,
17,
61,
272,
7449,
275,
10868,
1960,
339,
327,
3645,
3293,
3193,
13,
2075,
7151,
26,
440,
27254,
272,
2218,
63,
19118,
8,
5252,
12,
666,
12,
7449,
9,
272,
666,
63,
739,
12,
7449,
63,
739,
275,
1586,
63,
19118,
8,
5252,
9,
272,
702,
63,
1452,
8,
2319,
63,
739,
12,
7449,
9,
272,
702,
63,
1144,
63,
4398,
63,
1452,
8,
576,
59,
1590,
14,
14483,
12,
26450,
666,
63,
739,
12,
841,
9,
339,
327,
511,
4154,
8970,
1104,
272,
702,
63,
3536,
8,
13760,
12,
2218,
63,
19118,
12,
6748,
12,
666,
12,
7449,
9,
339,
327,
511,
31070,
7449,
2152,
370,
1109,
272,
543,
3598,
14,
9341,
63,
5451,
8,
3059,
29,
549,
9,
465,
336,
26,
267,
3598,
14,
18815,
360,
9223,
358,
267,
2218,
63,
19118,
8,
5252,
12,
666,
12,
2069,
8,
2319,
395,
8970,
29,
549,
9,
267,
702,
63,
1452,
8,
552,
8,
87,
395,
413,
9,
339,
327,
3645,
5049,
13,
2075,
1109,
26,
440,
3748,
272,
702,
63,
3536,
8,
13281,
12,
2218,
63,
19118,
12,
6748,
12,
666,
12,
7449,
12,
2152,
29,
1590,
14,
442,
772,
12,
2116,
8970,
29,
549,
9,
339,
327,
3645,
4337,
13,
2075,
1109,
26,
8034,
272,
2218,
63,
19118,
8,
5252,
12,
666,
12,
7449,
12,
2152,
29,
1590,
14,
442,
708,
12,
8970,
29,
549,
9,
272,
666,
63,
739,
12,
7449,
63,
739,
275,
1586,
63,
19118,
8,
5252,
9,
272,
702,
63,
1452,
8,
2319,
63,
739,
12,
7449,
9,
272,
702,
63,
1144,
63,
4398,
63,
1452,
8,
576,
59,
1590,
14,
14483,
12,
26450,
666,
63,
739,
12,
1520,
9,
339,
340,
485,
1989,
63,
14248,
63,
1023,
360,
16,
14,
969,
735,
267,
327,
3645,
4337,
13,
2075,
2069,
26,
8034,
267,
2218,
63,
19118,
8,
5252,
12,
666,
12,
7449,
12,
2152,
29,
1590,
14,
1609,
708,
12,
8970,
29,
549,
9,
267,
666,
63,
739,
12,
7449,
63,
739,
275,
1586,
63,
19118,
8,
5252,
9,
267,
702,
63,
1452,
8,
2319,
63,
739,
12,
7449,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
576,
59,
1590,
14,
14483,
12,
26450,
666,
63,
739,
12,
1520,
9,
398,
327,
3645,
5049,
13,
2075,
2069,
26,
23668,
267,
2218,
63,
19118,
8,
5252,
12,
666,
12,
7449,
12,
2152,
29,
1590,
14,
1609,
772,
12,
8970,
29,
549,
9,
267,
666,
63,
739,
12,
7449,
63,
739,
275,
1586,
63,
19118,
8,
5252,
9,
267,
702,
63,
1452,
8,
2319,
63,
739,
12,
7449,
9,
267,
702,
63,
1144,
63,
1452,
8,
576,
59,
1590,
14,
14483,
12,
26450,
666,
63,
739,
9,
272,
587,
26,
267,
702,
63,
3536,
8,
13281,
12,
2218,
63,
19118,
12,
6748,
12,
666,
12,
7449,
12,
1993,
2152,
29,
1590,
14,
1609,
708,
12,
8970,
29,
549,
9,
339,
327,
7356,
862,
3510,
13,
13014,
666,
272,
666,
275,
980,
14,
7172,
8,
576,
59,
1590,
14,
14483,
12,
26450,
334,
18,
12,
413,
430,
272,
2218,
63,
19118,
8,
5252,
12,
666,
59,
1590,
14,
14483,
12,
26450,
7449,
12,
8970,
29,
549,
9,
272,
666,
63,
739,
12,
7449,
63,
739,
275,
1586,
63,
19118,
8,
5252,
9,
272,
702,
63,
1452,
8,
2319,
63,
739,
12,
7449,
9,
272,
702,
63,
1144,
63,
4398,
63,
1452,
8,
576,
12,
666,
63,
739,
12,
841,
9,
339,
327,
4155,
3238,
4154,
3914,
1104,
5419,
272,
702,
63,
3536,
8,
3393,
12,
2218,
63,
19118,
12,
6748,
12,
666,
627,
499,
12,
7449,
12,
8970,
29,
549,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2680,
465,
980,
199,
504,
11354,
14,
2537,
492,
702,
63,
1452,
12,
702,
63,
3536,
199,
504,
2680,
14,
4776,
492,
702,
63,
1144,
63,
4398,
63,
1452,
12,
702,
63,
1144,
63,
1452,
199,
504,
747,
492,
931,
465,
1687,
199,
646,
3598,
199,
199,
504,
444,
647,
7036,
423,
1208,
492,
485,
29008,
12,
485,
1989,
63,
14248,
63,
1023,
199,
504,
444,
647,
7036,
14,
2308,
492,
1586,
63,
19118,
12,
2218,
63,
19118,
199,
199,
5451,
14,
18815,
360,
9223,
358,
199,
11567,
275,
485,
29008,
342,
421,
199,
318,
511,
63,
739,
63,
952,
63,
19118,
837,
272,
408,
774,
7664,
436,
3575,
644,
6087,
1584,
272,
408,
272,
6748,
275,
1687,
14,
904,
8,
11567,
12,
283,
808,
14,
19118,
358,
272,
666,
275,
980,
14,
82,
9925,
1590,
14,
2355,
14,
3759,
8,
5279,
395,
413,
12,
446,
17,
61,
272,
7449,
275,
10868,
1960,
339,
327,
3645,
3293,
3193,
13,
2075,
7151,
26,
440,
27254,
272,
2218,
63,
19118,
8,
5252,
12,
666,
12,
7449,
9,
272,
666,
63,
739,
12,
7449,
63,
739,
275,
1586,
63,
19118,
8,
5252,
9,
272,
702,
63,
1452,
8,
2319,
63,
739,
12,
7449,
9,
272,
702,
63,
1144,
63,
4398,
63,
1452,
8,
576,
59,
1590,
14,
14483,
12,
26450,
666,
63,
739,
12,
841,
9,
339,
327,
511,
4154,
8970,
1104,
272,
702,
63,
3536,
8,
13760,
12,
2218,
63,
19118,
12,
6748,
12,
666,
12,
7449,
9,
339,
327,
511,
31070,
7449,
2152,
370,
1109,
272,
543,
3598,
14,
9341,
63,
5451,
8,
3059,
29,
549,
9,
465,
336,
26,
267,
3598,
14,
18815,
360,
9223,
358,
267,
2218,
63,
19118,
8,
5252,
12,
666,
12,
2069,
8,
2319,
395,
8970,
29,
549,
9,
267,
702,
63,
1452,
8,
552,
8,
87,
395,
413,
9,
339,
327,
3645,
5049,
13,
2075,
1109,
26,
440,
3748,
272,
702,
63,
3536,
8,
13281,
12,
2218,
63,
19118,
12,
6748,
12,
666,
12,
7449,
12,
2152,
29,
1590,
14,
442,
772,
12,
2116,
8970,
29,
549,
9,
339,
327,
3645,
4337,
13,
2075,
1109,
26,
8034,
272,
2218,
63,
19118,
8,
5252,
12,
666,
12,
7449,
12,
2152,
29,
1590,
14,
442,
708,
12,
8970,
29,
549,
9,
272,
666,
63,
739,
12,
7449,
63,
739,
275,
1586,
63,
19118,
8,
5252,
9,
272,
702,
63,
1452,
8,
2319,
63,
739,
12,
7449,
9,
272,
702,
63,
1144,
63,
4398,
63,
1452,
8,
576,
59,
1590,
14,
14483,
12,
26450,
666,
63,
739,
12,
1520,
9,
339,
340,
485,
1989,
63,
14248,
63,
1023,
360,
16,
14,
969,
735,
267,
327,
3645,
4337,
13,
2075,
2069,
26,
8034,
267,
2218,
63,
19118,
8,
5252,
12,
666,
12,
7449,
12,
2152,
29,
1590,
14,
1609,
708,
12,
8970,
29,
549,
9,
267,
666,
63,
739,
12,
7449,
63,
739,
275,
1586,
63,
19118,
8,
5252,
9,
267,
702,
63,
1452,
8,
2319,
63,
739,
12,
7449,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
576,
59,
1590,
14,
14483,
12,
26450,
666,
63,
739,
12,
1520,
9,
398,
327,
3645,
5049,
13,
2075,
2069,
26,
23668,
267,
2218,
63,
19118,
8,
5252,
12,
666,
12,
7449,
12,
2152,
29,
1590,
14,
1609,
772,
12,
8970,
29,
549,
9,
267,
666,
63,
739,
12,
7449,
63,
739,
275,
1586,
63,
19118,
8,
5252,
9,
267,
702,
63,
1452,
8,
2319,
63,
739,
12,
7449,
9,
267,
702,
63,
1144,
63,
1452,
8,
576,
59,
1590,
14,
14483,
12,
26450,
666,
63,
739,
9,
272,
587,
26,
267,
702,
63,
3536,
8,
13281,
12,
2218,
63,
19118,
12,
6748,
12,
666,
12,
7449,
12,
1993,
2152,
29,
1590,
14,
1609,
708,
12,
8970,
29,
549,
9,
339,
327,
7356,
862,
3510,
13,
13014,
666,
272,
666,
275,
980,
14,
7172,
8,
576,
59,
1590,
14,
14483,
12,
26450,
334,
18,
12,
413,
430,
272,
2218,
63,
19118,
8,
5252,
12,
666,
59,
1590,
14,
14483,
12,
26450,
7449,
12,
8970,
29,
549,
9,
272,
666,
63,
739,
12,
7449,
63,
739,
275,
1586,
63,
19118,
8,
5252,
9,
272,
702,
63,
1452,
8,
2319,
63,
739,
12,
7449,
9,
272,
702,
63,
1144,
63,
4398,
63,
1452,
8,
576,
12,
666,
63,
739,
12,
841,
9,
339,
327,
4155,
3238,
4154,
3914,
1104,
5419,
272,
702,
63,
3536,
8,
3393,
12,
2218,
63,
19118,
12,
6748,
12,
666,
627,
499,
12,
7449,
12,
8970,
29,
549,
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,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,
0,
0
] |
JoelEager/pyTanks.Player
|
clientLogic/clock.py
|
1
|
5148
|
"""
The asyncio code that maintains a consistent frame rate and runs the on-frame logic
"""
import math
import json
from datetime import datetime
import asyncio
import config
from aiLogic import tankAI
from . import clientData
from .logging import logPrint
running = True # The asyncio event loop will end when this is set to False
def __moveObj(obj, distance):
"""
Moves a game object the given distance along its current heading
:param obj: An object with x, y, and heading properties
:param distance: The distance to move in pixels
"""
obj.x += math.cos(obj.heading) * distance
obj.y -= math.sin(obj.heading) * distance
def __dictToObj(dictIn):
"""
Turns a dictionary into a matching object
"""
class objFromDict:
def __init__(self):
for key, value in dictIn.items():
setattr(self, key, value)
return objFromDict()
def __onTick(frameDelta):
"""
On tick logic that updates the gameState and runs AI the functions
:param frameDelta: The time, in seconds, since the last call to this function
"""
gameStateWasNone = clientData.gameState is None
wasAlive = None
if not gameStateWasNone:
wasAlive = clientData.gameState.myTank.alive
if len(clientData.incoming) != 0:
# Message received from server, try to decode it
message = clientData.incoming.pop(0)
try:
clientData.gameState = json.loads(message, object_hook=__dictToObj)
clientData.lastUpdate = datetime.now()
except json.decoder.JSONDecodeError:
# Message isn't JSON so print it
# (This is usually used to handle error messages)
logPrint("Message from server: " + message, 1)
elif clientData.gameState is not None:
# Extrapolate the gameState
totalDistance = config.game.tank.speed * frameDelta
if clientData.gameState.myTank.moving:
__moveObj(clientData.gameState.myTank, totalDistance)
for tank in clientData.gameState.tanks:
if tank.moving:
__moveObj(tank, totalDistance)
totalDistance = config.game.shell.speed * frameDelta
for shell in clientData.gameState.shells:
__moveObj(shell, totalDistance)
# Check clientData.lastUpdate for connection timeout
if (datetime.now() - clientData.lastUpdate).total_seconds() > config.client.timeout:
logPrint("Connection to server timed out - attempting 'nice' disconnect...", 1)
global running
running = False
return
# Call the AI functions
if clientData.gameState is not None:
if gameStateWasNone:
logPrint("Received command of the " + clientData.gameState.myTank.name, 1)
tankAI.onConnect()
if clientData.gameState.ongoingGame:
if clientData.gameState.myTank.alive:
if not wasAlive:
logPrint("Tank spawned", 2)
tankAI.onSpawn()
tankAI.onTick(frameDelta)
if not clientData.gameState.myTank.alive and wasAlive:
logPrint("Tank killed", 2)
async def clientClock():
"""
Maintains a consistent frame rate as set in config.py and calls onTick() every frame
"""
# For frame rate targeting
lastFrameTime = datetime.now()
baseDelay = 1 / config.client.framesPerSecond
delay = baseDelay
deltas = list()
minFPS = config.client.framesPerSecond
# For calculating the FPS for logging
lastFPSLog = datetime.now()
frameCount = 0
while running:
# Calculate the time passed in seconds and adds it to the list of deltas
frameDelta = (datetime.now() - lastFrameTime).total_seconds()
lastFrameTime = datetime.now()
deltas.append(frameDelta)
if len(deltas) > 15:
deltas.pop(0)
# Adjust delay to try to keep the actual frame rate within 5% of the target
avgDelta = sum(deltas) / float(len(deltas))
if avgDelta * config.client.framesPerSecond < 0.95: # Too fast
delay += baseDelay * 0.01
elif avgDelta * config.client.framesPerSecond > 1.05: # Too slow
delay -= baseDelay * 0.01
if delay < 1 / 250:
delay = 1 / 250
# Log FPS if server logging is enabled
if config.client.logLevel >= 3:
if avgDelta != 0:
if 1 / avgDelta < minFPS:
minFPS = 1 / avgDelta
frameCount += 1
if (datetime.now() - lastFPSLog).total_seconds() >= config.client.fpsLogRate:
logPrint("FPS: avg=" + str(frameCount / config.client.fpsLogRate) + ", min=" +
str(round(minFPS, 1)), 3)
frameCount = 0
minFPS = config.client.framesPerSecond
lastFPSLog = datetime.now()
# Now do the logic for this frame
__onTick(frameDelta)
# Sleep until the next frame
await asyncio.sleep(delay) # (If this doesn't sleep then the other tasks can never be completed.)
|
mit
|
[
624,
199,
1918,
16195,
1233,
626,
11075,
83,
282,
12137,
2787,
6634,
436,
7858,
314,
641,
13,
1943,
9661,
199,
624,
199,
199,
646,
3473,
199,
646,
2022,
199,
504,
2197,
492,
2197,
199,
646,
16195,
199,
199,
646,
1101,
199,
504,
15933,
32140,
492,
307,
3580,
7730,
199,
504,
1275,
492,
1890,
1451,
199,
504,
1275,
4806,
492,
943,
5375,
199,
199,
5720,
275,
715,
3515,
327,
710,
16195,
1566,
4438,
911,
1284,
1380,
642,
365,
663,
370,
756,
199,
199,
318,
636,
1185,
5665,
8,
1113,
12,
6033,
304,
272,
408,
272,
3930,
2310,
282,
9219,
909,
314,
1627,
6033,
3180,
2399,
1453,
16631,
272,
520,
635,
1559,
26,
1626,
909,
543,
671,
12,
612,
12,
436,
16631,
4382,
272,
520,
635,
6033,
26,
710,
6033,
370,
4057,
315,
11094,
272,
408,
272,
1559,
14,
88,
847,
3473,
14,
5197,
8,
1113,
14,
13983,
9,
627,
6033,
272,
1559,
14,
89,
4862,
3473,
14,
5911,
8,
1113,
14,
13983,
9,
627,
6033,
199,
199,
318,
636,
807,
1378,
5665,
8,
807,
607,
304,
272,
408,
272,
16147,
83,
282,
2600,
1901,
282,
4877,
909,
272,
408,
272,
1021,
1559,
2532,
2141,
26,
267,
347,
636,
826,
721,
277,
304,
288,
367,
790,
12,
574,
315,
1211,
607,
14,
1744,
837,
355,
5371,
8,
277,
12,
790,
12,
574,
9,
339,
372,
1559,
2532,
2141,
342,
199,
199,
318,
636,
265,
11763,
8,
1943,
13411,
304,
272,
408,
272,
4068,
11748,
9661,
626,
7029,
314,
9219,
2223,
436,
7858,
437,
41,
314,
3423,
272,
520,
635,
2787,
13411,
26,
710,
900,
12,
315,
4696,
12,
3967,
314,
2061,
1240,
370,
642,
805,
272,
408,
272,
9219,
2223,
55,
305,
403,
275,
1890,
1451,
14,
5097,
2223,
365,
488,
272,
1990,
23692,
275,
488,
272,
340,
440,
9219,
2223,
55,
305,
403,
26,
267,
1990,
23692,
275,
1890,
1451,
14,
5097,
2223,
14,
1662,
52,
3580,
14,
9631,
272,
340,
822,
8,
1258,
1451,
14,
15994,
9,
1137,
378,
26,
267,
327,
6430,
3086,
687,
1654,
12,
862,
370,
4849,
652,
267,
1245,
275,
1890,
1451,
14,
15994,
14,
1935,
8,
16,
9,
267,
862,
26,
288,
1890,
1451,
14,
5097,
2223,
275,
2022,
14,
3640,
8,
1188,
12,
909,
63,
3664,
18971,
807,
1378,
5665,
9,
288,
1890,
1451,
14,
2019,
4152,
275,
2197,
14,
2131,
342,
267,
871,
2022,
14,
8813,
14,
6243,
12620,
26,
288,
327,
6430,
5712,
1133,
4840,
880,
870,
652,
288,
327,
334,
2765,
365,
9987,
1202,
370,
2429,
1125,
3788,
9,
288,
943,
5375,
480,
2209,
687,
1654,
26,
298,
435,
1245,
12,
413,
9,
272,
916,
1890,
1451,
14,
5097,
2223,
365,
440,
488,
26,
267,
327,
7255,
1330,
16288,
314,
9219,
2223,
267,
3141,
10076,
275,
1101,
14,
5097,
14,
84,
3580,
14,
7625,
627,
2787,
13411,
398,
340,
1890,
1451,
14,
5097,
2223,
14,
1662,
52,
3580,
14,
7665,
26,
288,
636,
1185,
5665,
8,
1258,
1451,
14,
5097,
2223,
14,
1662,
52,
3580,
12,
3141,
10076,
9,
398,
367,
307,
3580,
315,
1890,
1451,
14,
5097,
2223,
14,
84,
25088,
26,
288,
340,
307,
3580,
14,
7665,
26,
355,
636,
1185,
5665,
8,
84,
3580,
12,
3141,
10076,
9,
398,
3141,
10076,
275,
1101,
14,
5097,
14,
5641,
14,
7625,
627,
2787,
13411,
267,
367,
5218,
315,
1890,
1451,
14,
5097,
2223,
14,
609,
6840,
26,
288,
636,
1185,
5665,
8,
5641,
12,
3141,
10076,
9,
398,
327,
2670,
1890,
1451,
14,
2019,
4152,
367,
1950,
2653,
267,
340,
334,
2083,
14,
2131,
342,
446,
1890,
1451,
14,
2019,
4152,
680,
2923,
63,
4515,
342,
690,
1101,
14,
1258,
14,
2593,
26,
288,
943,
5375,
480,
3225,
370,
1654,
18590,
734,
446,
19595,
283,
22746,
7,
17639,
23966,
413,
9,
288,
2288,
3879,
288,
3879,
275,
756,
288,
372,
339,
327,
6523,
314,
437,
41,
3423,
272,
340,
1890,
1451,
14,
5097,
2223,
365,
440,
488,
26,
267,
340,
9219,
2223,
55,
305,
403,
26,
288,
943,
5375,
480,
9392,
1414,
402,
314,
298,
435,
1890,
1451,
14,
5097,
2223,
14,
1662,
52,
3580,
14,
354,
12,
413,
9,
288,
307,
3580,
7730,
14,
265,
8631,
342,
398,
340,
1890,
1451,
14,
5097,
2223,
14,
5774,
316,
11454,
26,
288,
340,
1890,
1451,
14,
5097,
2223,
14,
1662,
52,
3580,
14,
9631,
26,
355,
340,
440,
1990,
23692,
26,
490,
943,
5375,
480,
52,
3580,
15187,
379,
401,
499,
9,
490,
307,
3580,
7730,
14,
265,
12739,
3501,
342,
2234,
307,
3580,
7730,
14,
265,
11763,
8,
1943,
13411,
9,
398,
340,
440,
1890,
1451,
14,
5097,
2223,
14,
1662,
52,
3580,
14,
9631,
436,
1990,
23692,
26,
288,
943,
5375,
480,
52,
3580,
26659,
401,
499,
9,
199,
199,
4146,
347,
1890,
17387,
837,
272,
408,
272,
16593,
8368,
83,
282,
12137,
2787,
6634,
465,
663,
315,
1101,
14,
647,
436,
4882,
641,
11763,
342,
4036,
2787,
272,
408,
272,
327,
2104,
2787,
6634,
1347,
316,
272,
2061,
3160,
1366,
275,
2197,
14,
2131,
342,
272,
1300,
10796,
275,
413,
1182,
1101,
14,
1258,
14,
8444,
2623,
11906,
272,
7339,
275,
1300,
10796,
272,
27446,
275,
769,
342,
272,
1748,
38,
5067,
275,
1101,
14,
1258,
14,
8444,
2623,
11906,
339,
327,
2104,
26079,
314,
481,
5067,
367,
2050,
272,
2061,
38,
5067,
2445,
275,
2197,
14,
2131,
342,
272,
2787,
2353,
275,
378,
339,
1830,
3879,
26,
267,
327,
12707,
314,
900,
3032,
315,
4696,
436,
9584,
652,
370,
314,
769,
402,
27446,
267,
2787,
13411,
275,
334,
2083,
14,
2131,
342,
446,
2061,
3160,
1366,
680,
2923,
63,
4515,
342,
267,
2061,
3160,
1366,
275,
2197,
14,
2131,
342,
267,
27446,
14,
740,
8,
1943,
13411,
9,
267,
340,
822,
8,
25446,
9,
690,
4114,
26,
288,
27446,
14,
1935,
8,
16,
9,
398,
327,
26412,
7339,
370,
862,
370,
4215,
314,
3503,
2787,
6634,
4453,
959,
5,
402,
314,
1347,
267,
12402,
13411,
275,
3089,
8,
25446,
9,
1182,
2069,
8,
552,
8,
25446,
430,
267,
340,
12402,
13411,
627,
1101,
14,
1258,
14,
8444,
2623,
11906,
665,
378,
14,
2720,
26,
221,
327,
22893,
7377,
288,
7339,
847,
1300,
10796,
627,
378,
14,
614,
267,
916,
12402,
13411
] |
[
199,
1918,
16195,
1233,
626,
11075,
83,
282,
12137,
2787,
6634,
436,
7858,
314,
641,
13,
1943,
9661,
199,
624,
199,
199,
646,
3473,
199,
646,
2022,
199,
504,
2197,
492,
2197,
199,
646,
16195,
199,
199,
646,
1101,
199,
504,
15933,
32140,
492,
307,
3580,
7730,
199,
504,
1275,
492,
1890,
1451,
199,
504,
1275,
4806,
492,
943,
5375,
199,
199,
5720,
275,
715,
3515,
327,
710,
16195,
1566,
4438,
911,
1284,
1380,
642,
365,
663,
370,
756,
199,
199,
318,
636,
1185,
5665,
8,
1113,
12,
6033,
304,
272,
408,
272,
3930,
2310,
282,
9219,
909,
314,
1627,
6033,
3180,
2399,
1453,
16631,
272,
520,
635,
1559,
26,
1626,
909,
543,
671,
12,
612,
12,
436,
16631,
4382,
272,
520,
635,
6033,
26,
710,
6033,
370,
4057,
315,
11094,
272,
408,
272,
1559,
14,
88,
847,
3473,
14,
5197,
8,
1113,
14,
13983,
9,
627,
6033,
272,
1559,
14,
89,
4862,
3473,
14,
5911,
8,
1113,
14,
13983,
9,
627,
6033,
199,
199,
318,
636,
807,
1378,
5665,
8,
807,
607,
304,
272,
408,
272,
16147,
83,
282,
2600,
1901,
282,
4877,
909,
272,
408,
272,
1021,
1559,
2532,
2141,
26,
267,
347,
636,
826,
721,
277,
304,
288,
367,
790,
12,
574,
315,
1211,
607,
14,
1744,
837,
355,
5371,
8,
277,
12,
790,
12,
574,
9,
339,
372,
1559,
2532,
2141,
342,
199,
199,
318,
636,
265,
11763,
8,
1943,
13411,
304,
272,
408,
272,
4068,
11748,
9661,
626,
7029,
314,
9219,
2223,
436,
7858,
437,
41,
314,
3423,
272,
520,
635,
2787,
13411,
26,
710,
900,
12,
315,
4696,
12,
3967,
314,
2061,
1240,
370,
642,
805,
272,
408,
272,
9219,
2223,
55,
305,
403,
275,
1890,
1451,
14,
5097,
2223,
365,
488,
272,
1990,
23692,
275,
488,
272,
340,
440,
9219,
2223,
55,
305,
403,
26,
267,
1990,
23692,
275,
1890,
1451,
14,
5097,
2223,
14,
1662,
52,
3580,
14,
9631,
272,
340,
822,
8,
1258,
1451,
14,
15994,
9,
1137,
378,
26,
267,
327,
6430,
3086,
687,
1654,
12,
862,
370,
4849,
652,
267,
1245,
275,
1890,
1451,
14,
15994,
14,
1935,
8,
16,
9,
267,
862,
26,
288,
1890,
1451,
14,
5097,
2223,
275,
2022,
14,
3640,
8,
1188,
12,
909,
63,
3664,
18971,
807,
1378,
5665,
9,
288,
1890,
1451,
14,
2019,
4152,
275,
2197,
14,
2131,
342,
267,
871,
2022,
14,
8813,
14,
6243,
12620,
26,
288,
327,
6430,
5712,
1133,
4840,
880,
870,
652,
288,
327,
334,
2765,
365,
9987,
1202,
370,
2429,
1125,
3788,
9,
288,
943,
5375,
480,
2209,
687,
1654,
26,
298,
435,
1245,
12,
413,
9,
272,
916,
1890,
1451,
14,
5097,
2223,
365,
440,
488,
26,
267,
327,
7255,
1330,
16288,
314,
9219,
2223,
267,
3141,
10076,
275,
1101,
14,
5097,
14,
84,
3580,
14,
7625,
627,
2787,
13411,
398,
340,
1890,
1451,
14,
5097,
2223,
14,
1662,
52,
3580,
14,
7665,
26,
288,
636,
1185,
5665,
8,
1258,
1451,
14,
5097,
2223,
14,
1662,
52,
3580,
12,
3141,
10076,
9,
398,
367,
307,
3580,
315,
1890,
1451,
14,
5097,
2223,
14,
84,
25088,
26,
288,
340,
307,
3580,
14,
7665,
26,
355,
636,
1185,
5665,
8,
84,
3580,
12,
3141,
10076,
9,
398,
3141,
10076,
275,
1101,
14,
5097,
14,
5641,
14,
7625,
627,
2787,
13411,
267,
367,
5218,
315,
1890,
1451,
14,
5097,
2223,
14,
609,
6840,
26,
288,
636,
1185,
5665,
8,
5641,
12,
3141,
10076,
9,
398,
327,
2670,
1890,
1451,
14,
2019,
4152,
367,
1950,
2653,
267,
340,
334,
2083,
14,
2131,
342,
446,
1890,
1451,
14,
2019,
4152,
680,
2923,
63,
4515,
342,
690,
1101,
14,
1258,
14,
2593,
26,
288,
943,
5375,
480,
3225,
370,
1654,
18590,
734,
446,
19595,
283,
22746,
7,
17639,
23966,
413,
9,
288,
2288,
3879,
288,
3879,
275,
756,
288,
372,
339,
327,
6523,
314,
437,
41,
3423,
272,
340,
1890,
1451,
14,
5097,
2223,
365,
440,
488,
26,
267,
340,
9219,
2223,
55,
305,
403,
26,
288,
943,
5375,
480,
9392,
1414,
402,
314,
298,
435,
1890,
1451,
14,
5097,
2223,
14,
1662,
52,
3580,
14,
354,
12,
413,
9,
288,
307,
3580,
7730,
14,
265,
8631,
342,
398,
340,
1890,
1451,
14,
5097,
2223,
14,
5774,
316,
11454,
26,
288,
340,
1890,
1451,
14,
5097,
2223,
14,
1662,
52,
3580,
14,
9631,
26,
355,
340,
440,
1990,
23692,
26,
490,
943,
5375,
480,
52,
3580,
15187,
379,
401,
499,
9,
490,
307,
3580,
7730,
14,
265,
12739,
3501,
342,
2234,
307,
3580,
7730,
14,
265,
11763,
8,
1943,
13411,
9,
398,
340,
440,
1890,
1451,
14,
5097,
2223,
14,
1662,
52,
3580,
14,
9631,
436,
1990,
23692,
26,
288,
943,
5375,
480,
52,
3580,
26659,
401,
499,
9,
199,
199,
4146,
347,
1890,
17387,
837,
272,
408,
272,
16593,
8368,
83,
282,
12137,
2787,
6634,
465,
663,
315,
1101,
14,
647,
436,
4882,
641,
11763,
342,
4036,
2787,
272,
408,
272,
327,
2104,
2787,
6634,
1347,
316,
272,
2061,
3160,
1366,
275,
2197,
14,
2131,
342,
272,
1300,
10796,
275,
413,
1182,
1101,
14,
1258,
14,
8444,
2623,
11906,
272,
7339,
275,
1300,
10796,
272,
27446,
275,
769,
342,
272,
1748,
38,
5067,
275,
1101,
14,
1258,
14,
8444,
2623,
11906,
339,
327,
2104,
26079,
314,
481,
5067,
367,
2050,
272,
2061,
38,
5067,
2445,
275,
2197,
14,
2131,
342,
272,
2787,
2353,
275,
378,
339,
1830,
3879,
26,
267,
327,
12707,
314,
900,
3032,
315,
4696,
436,
9584,
652,
370,
314,
769,
402,
27446,
267,
2787,
13411,
275,
334,
2083,
14,
2131,
342,
446,
2061,
3160,
1366,
680,
2923,
63,
4515,
342,
267,
2061,
3160,
1366,
275,
2197,
14,
2131,
342,
267,
27446,
14,
740,
8,
1943,
13411,
9,
267,
340,
822,
8,
25446,
9,
690,
4114,
26,
288,
27446,
14,
1935,
8,
16,
9,
398,
327,
26412,
7339,
370,
862,
370,
4215,
314,
3503,
2787,
6634,
4453,
959,
5,
402,
314,
1347,
267,
12402,
13411,
275,
3089,
8,
25446,
9,
1182,
2069,
8,
552,
8,
25446,
430,
267,
340,
12402,
13411,
627,
1101,
14,
1258,
14,
8444,
2623,
11906,
665,
378,
14,
2720,
26,
221,
327,
22893,
7377,
288,
7339,
847,
1300,
10796,
627,
378,
14,
614,
267,
916,
12402,
13411,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
codevlabs/ZeroNet
|
plugins/Trayicon/TrayiconPlugin.py
|
10
|
4312
|
import time
import os
import sys
import atexit
from Plugin import PluginManager
from Config import config
allow_reload = False # No source reload supported in this plugin
@PluginManager.registerTo("Actions")
class ActionsPlugin(object):
def main(self):
global notificationicon, winfolders
from lib import notificationicon, winfolders
import gevent.threadpool
self.main = sys.modules["main"]
icon = notificationicon.NotificationIcon(
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'trayicon.ico'),
"ZeroNet %s" % config.version
)
self.icon = icon
if not config.debug: # Hide console if not in debug mode
notificationicon.hideConsole()
self.console = False
else:
self.console = True
@atexit.register
def hideIcon():
icon.die()
icon.items = (
(self.titleIp, False),
(self.titleConnections, False),
(self.titleTransfer, False),
(self.titleConsole, self.toggleConsole),
(self.titleAutorun, self.toggleAutorun),
"--",
("ZeroNet Twitter", lambda: self.opensite("https://twitter.com/HelloZeroNet")),
("ZeroNet Reddit", lambda: self.opensite("http://www.reddit.com/r/zeronet/")),
("ZeroNet Github", lambda: self.opensite("https://github.com/HelloZeroNet/ZeroNet")),
("Report bug/request feature", lambda: self.opensite("https://github.com/HelloZeroNet/ZeroNet/issues")),
"--",
("!Open ZeroNet", lambda: self.opensite("http://%s:%s" % (config.ui_ip, config.ui_port))),
"--",
("Quit", self.quit),
)
icon.clicked = lambda: self.opensite("http://%s:%s" % (config.ui_ip, config.ui_port))
gevent.threadpool.start_new_thread(icon._run, ()) # Start in real thread (not gevent compatible)
super(ActionsPlugin, self).main()
icon._die = True
def quit(self):
self.icon.die()
time.sleep(0.1)
self.main.ui_server.stop()
self.main.file_server.stop()
# sys.exit()
def opensite(self, url):
import webbrowser
webbrowser.open(url, new=0)
def titleIp(self):
title = "!IP: %s" % config.ip_external
if self.main.file_server.port_opened:
title += " (active)"
else:
title += " (passive)"
return title
def titleConnections(self):
title = "Connections: %s" % len(self.main.file_server.connections)
return title
def titleTransfer(self):
title = "Received: %.2f MB | Sent: %.2f MB" % (
float(self.main.file_server.bytes_recv) / 1024 / 1024,
float(self.main.file_server.bytes_sent) / 1024 / 1024
)
return title
def titleConsole(self):
if self.console:
return "+Show console window"
else:
return "Show console window"
def toggleConsole(self):
if self.console:
notificationicon.hideConsole()
self.console = False
else:
notificationicon.showConsole()
self.console = True
def getAutorunPath(self):
return "%s\\zeronet.cmd" % winfolders.get(winfolders.STARTUP)
def formatAutorun(self):
args = sys.argv[:]
args.insert(0, sys.executable)
if sys.platform == 'win32':
args = ['"%s"' % arg for arg in args]
cmd = " ".join(args)
# Dont open browser on autorun
cmd = cmd.replace("start.py", "zeronet.py").replace('"--open_browser"', "").replace('"default_browser"', "")
return "cd /D %s \n%s" % (os.getcwd(), cmd)
def isAutorunEnabled(self):
path = self.getAutorunPath()
return os.path.isfile(path) and open(path).read() == self.formatAutorun()
def titleAutorun(self):
if self.isAutorunEnabled():
return "+Start ZeroNet when Windows starts"
else:
return "Start ZeroNet when Windows starts"
def toggleAutorun(self):
if self.isAutorunEnabled():
os.unlink(self.getAutorunPath())
else:
open(self.getAutorunPath(), "w").write(self.formatAutorun())
|
gpl-2.0
|
[
646,
900,
199,
646,
747,
199,
646,
984,
199,
646,
19840,
199,
199,
504,
11349,
492,
11349,
2988,
199,
504,
4094,
492,
1101,
199,
199,
3306,
63,
9233,
275,
756,
221,
327,
3091,
1350,
13101,
3748,
315,
642,
3589,
421,
199,
32,
5061,
2988,
14,
2683,
1378,
480,
9303,
531,
199,
533,
24367,
5061,
8,
785,
304,
339,
347,
2446,
8,
277,
304,
267,
2288,
6955,
4677,
12,
4747,
15171,
267,
687,
1973,
492,
6955,
4677,
12,
4747,
15171,
267,
492,
23386,
14,
2671,
2293,
398,
291,
14,
973,
275,
984,
14,
3112,
905,
973,
937,
398,
7016,
275,
6955,
4677,
14,
11598,
8954,
8,
288,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
22159,
283,
84,
803,
4677,
14,
12802,
659,
288,
298,
8681,
2480,
450,
83,
2,
450,
1101,
14,
1023,
267,
776,
267,
291,
14,
4677,
275,
7016,
398,
340,
440,
1101,
14,
1757,
26,
221,
327,
869,
2655,
8559,
340,
440,
315,
3105,
818,
288,
6955,
4677,
14,
8191,
9270,
342,
288,
291,
14,
6614,
275,
756,
267,
587,
26,
288,
291,
14,
6614,
275,
715,
398,
768,
24026,
390,
14,
2683,
267,
347,
13714,
8954,
837,
288,
7016,
14,
15130,
342,
398,
7016,
14,
1744,
275,
334,
288,
334,
277,
14,
1213,
6583,
12,
756,
395,
288,
334,
277,
14,
1213,
22122,
12,
756,
395,
288,
334,
277,
14,
1213,
11761,
12,
756,
395,
288,
334,
277,
14,
1213,
9270,
12,
291,
14,
13396,
9270,
395,
288,
334,
277,
14,
1213,
33,
4139,
324,
12,
291,
14,
13396,
33,
4139,
324,
395,
288,
4320,
401,
288,
1689,
8681,
2480,
19259,
401,
2400,
26,
291,
14,
1490,
2124,
480,
2859,
921,
13746,
14,
957,
15,
6257,
8681,
2480,
8150,
288,
1689,
8681,
2480,
9572,
1741,
401,
2400,
26,
291,
14,
1490,
2124,
480,
1014,
921,
1544,
14,
18374,
14,
957,
15,
82,
15,
2282,
25759,
15,
8150,
288,
1689,
8681,
2480,
598,
4049,
401,
2400,
26,
291,
14,
1490,
2124,
480,
2859,
921,
5031,
14,
957,
15,
6257,
8681,
2480,
15,
8681,
2480,
8150,
288,
1689,
7457,
6519,
15,
1069,
3878,
401,
2400,
26,
291,
14,
1490,
2124,
480,
2859,
921,
5031,
14,
957,
15,
6257,
8681,
2480,
15,
8681,
2480,
15,
10115,
8150,
288,
4320,
401,
288,
1689,
1,
4299,
15708,
2480,
401,
2400,
26,
291,
14,
1490,
2124,
480,
1014,
13827,
83,
2689,
83,
2,
450,
334,
888,
14,
1907,
63,
711,
12,
1101,
14,
1907,
63,
719,
11508,
288,
4320,
401,
288,
1689,
24145,
401,
291,
14,
10589,
395,
398,
776,
398,
7016,
14,
11276,
275,
2400,
26,
291,
14,
1490,
2124,
480,
1014,
13827,
83,
2689,
83,
2,
450,
334,
888,
14,
1907,
63,
711,
12,
1101,
14,
1907,
63,
719,
430,
267,
23386,
14,
2671,
2293,
14,
928,
63,
1222,
63,
2671,
8,
4677,
423,
1065,
12,
14515,
221,
327,
7707,
315,
3363,
2462,
334,
1397,
23386,
9025,
9,
267,
1613,
8,
9303,
5061,
12,
291,
680,
973,
342,
267,
7016,
423,
15130,
275,
715,
339,
347,
17242,
8,
277,
304,
267,
291,
14,
4677,
14,
15130,
342,
267,
900,
14,
4532,
8,
16,
14,
17,
9,
267,
291,
14,
973,
14,
1907,
63,
1000,
14,
2379,
342,
267,
291,
14,
973,
14,
493,
63,
1000,
14,
2379,
342,
267,
327,
984,
14,
2224,
342,
339,
347,
1551,
2124,
8,
277,
12,
1166,
304,
267,
492,
781,
29063,
267,
781,
29063,
14,
1490,
8,
633,
12,
892,
29,
16,
9,
339,
347,
2538,
6583,
8,
277,
304,
267,
2538,
275,
19724,
1772,
26,
450,
83,
2,
450,
1101,
14,
711,
63,
5159,
267,
340,
291,
14,
973,
14,
493,
63,
1000,
14,
719,
63,
19234,
26,
288,
2538,
847,
298,
334,
2682,
2924,
267,
587,
26,
288,
2538,
847,
298,
334,
25166,
2924,
267,
372,
2538,
339,
347,
2538,
22122,
8,
277,
304,
267,
2538,
275,
298,
22122,
26,
450,
83,
2,
450,
822,
8,
277,
14,
973,
14,
493,
63,
1000,
14,
7995,
9,
267,
372,
2538,
339,
347,
2538,
11761,
8,
277,
304,
267,
2538,
275,
298,
9392,
26,
10536,
18,
70,
19487,
1204,
428,
484,
26,
10536,
18,
70,
19487,
2,
450,
334,
288,
2069,
8,
277,
14,
973,
14,
493,
63,
1000,
14,
2394,
63,
7637,
9,
1182,
6619,
1182,
6619,
12,
288,
2069,
8,
277,
14,
973,
14,
493,
63,
1000,
14,
2394,
63,
1150,
9,
1182,
6619,
1182,
6619,
267,
776,
267,
372,
2538,
339,
347,
2538,
9270,
8,
277,
304,
267,
340,
291,
14,
6614,
26,
288,
372,
7210,
6824,
8559,
4353,
2,
267,
587,
26,
288,
372,
298,
6824,
8559,
4353,
2,
339,
347,
19420,
9270,
8,
277,
304,
267,
340,
291,
14,
6614,
26,
288,
6955,
4677,
14,
8191,
9270,
342,
288,
291,
14,
6614,
275,
756,
267,
587,
26,
288,
6955,
4677,
14,
2384,
9270,
342,
288,
291,
14,
6614,
275,
715,
339,
347,
664,
33,
4139,
324,
2042,
8,
277,
304,
267,
372,
2071,
83,
1103,
2282,
25759,
14,
1760,
2,
450,
4747,
15171,
14,
362,
8,
2676,
15171,
14,
7363,
2160,
9,
339,
347,
1475,
33,
4139,
324,
8,
277,
304,
267,
1249,
275,
984,
14,
3020,
5873,
267,
1249,
14,
3176,
8,
16,
12,
984,
14,
5904,
9,
267,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
288,
1249,
275,
788,
6808,
83,
4507,
450,
1680,
367,
1680,
315,
1249,
61,
267,
2088,
275,
298,
3680,
904,
8,
589,
9,
398,
327,
577,
1888,
1551,
7042,
641,
282,
4139,
324,
267,
2088,
275,
2088,
14,
1814,
480,
928,
14,
647,
401,
298,
2282,
25759,
14,
647,
3471,
1814,
14088,
306,
1490,
63,
5750,
6949,
25354,
1814,
14088,
885,
63,
5750,
6949,
6899,
398,
372,
298,
2866,
1182,
36,
450,
83,
971,
78,
5,
83,
2,
450,
334,
736,
14,
9458,
1062,
2088,
9,
339,
347,
365,
33,
4139,
324,
6589,
8,
277,
304,
267,
931,
275,
291,
14,
362,
33,
4139,
324,
2042,
342,
267,
372,
747,
14,
515,
14,
6292,
8,
515,
9,
436,
1551,
8,
515,
680,
739,
342,
508,
291,
14,
908,
33,
4139,
324,
342,
339,
347,
2538,
33,
4139,
324,
8,
277,
304,
267,
340
] |
[
900,
199,
646,
747,
199,
646,
984,
199,
646,
19840,
199,
199,
504,
11349,
492,
11349,
2988,
199,
504,
4094,
492,
1101,
199,
199,
3306,
63,
9233,
275,
756,
221,
327,
3091,
1350,
13101,
3748,
315,
642,
3589,
421,
199,
32,
5061,
2988,
14,
2683,
1378,
480,
9303,
531,
199,
533,
24367,
5061,
8,
785,
304,
339,
347,
2446,
8,
277,
304,
267,
2288,
6955,
4677,
12,
4747,
15171,
267,
687,
1973,
492,
6955,
4677,
12,
4747,
15171,
267,
492,
23386,
14,
2671,
2293,
398,
291,
14,
973,
275,
984,
14,
3112,
905,
973,
937,
398,
7016,
275,
6955,
4677,
14,
11598,
8954,
8,
288,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
22159,
283,
84,
803,
4677,
14,
12802,
659,
288,
298,
8681,
2480,
450,
83,
2,
450,
1101,
14,
1023,
267,
776,
267,
291,
14,
4677,
275,
7016,
398,
340,
440,
1101,
14,
1757,
26,
221,
327,
869,
2655,
8559,
340,
440,
315,
3105,
818,
288,
6955,
4677,
14,
8191,
9270,
342,
288,
291,
14,
6614,
275,
756,
267,
587,
26,
288,
291,
14,
6614,
275,
715,
398,
768,
24026,
390,
14,
2683,
267,
347,
13714,
8954,
837,
288,
7016,
14,
15130,
342,
398,
7016,
14,
1744,
275,
334,
288,
334,
277,
14,
1213,
6583,
12,
756,
395,
288,
334,
277,
14,
1213,
22122,
12,
756,
395,
288,
334,
277,
14,
1213,
11761,
12,
756,
395,
288,
334,
277,
14,
1213,
9270,
12,
291,
14,
13396,
9270,
395,
288,
334,
277,
14,
1213,
33,
4139,
324,
12,
291,
14,
13396,
33,
4139,
324,
395,
288,
4320,
401,
288,
1689,
8681,
2480,
19259,
401,
2400,
26,
291,
14,
1490,
2124,
480,
2859,
921,
13746,
14,
957,
15,
6257,
8681,
2480,
8150,
288,
1689,
8681,
2480,
9572,
1741,
401,
2400,
26,
291,
14,
1490,
2124,
480,
1014,
921,
1544,
14,
18374,
14,
957,
15,
82,
15,
2282,
25759,
15,
8150,
288,
1689,
8681,
2480,
598,
4049,
401,
2400,
26,
291,
14,
1490,
2124,
480,
2859,
921,
5031,
14,
957,
15,
6257,
8681,
2480,
15,
8681,
2480,
8150,
288,
1689,
7457,
6519,
15,
1069,
3878,
401,
2400,
26,
291,
14,
1490,
2124,
480,
2859,
921,
5031,
14,
957,
15,
6257,
8681,
2480,
15,
8681,
2480,
15,
10115,
8150,
288,
4320,
401,
288,
1689,
1,
4299,
15708,
2480,
401,
2400,
26,
291,
14,
1490,
2124,
480,
1014,
13827,
83,
2689,
83,
2,
450,
334,
888,
14,
1907,
63,
711,
12,
1101,
14,
1907,
63,
719,
11508,
288,
4320,
401,
288,
1689,
24145,
401,
291,
14,
10589,
395,
398,
776,
398,
7016,
14,
11276,
275,
2400,
26,
291,
14,
1490,
2124,
480,
1014,
13827,
83,
2689,
83,
2,
450,
334,
888,
14,
1907,
63,
711,
12,
1101,
14,
1907,
63,
719,
430,
267,
23386,
14,
2671,
2293,
14,
928,
63,
1222,
63,
2671,
8,
4677,
423,
1065,
12,
14515,
221,
327,
7707,
315,
3363,
2462,
334,
1397,
23386,
9025,
9,
267,
1613,
8,
9303,
5061,
12,
291,
680,
973,
342,
267,
7016,
423,
15130,
275,
715,
339,
347,
17242,
8,
277,
304,
267,
291,
14,
4677,
14,
15130,
342,
267,
900,
14,
4532,
8,
16,
14,
17,
9,
267,
291,
14,
973,
14,
1907,
63,
1000,
14,
2379,
342,
267,
291,
14,
973,
14,
493,
63,
1000,
14,
2379,
342,
267,
327,
984,
14,
2224,
342,
339,
347,
1551,
2124,
8,
277,
12,
1166,
304,
267,
492,
781,
29063,
267,
781,
29063,
14,
1490,
8,
633,
12,
892,
29,
16,
9,
339,
347,
2538,
6583,
8,
277,
304,
267,
2538,
275,
19724,
1772,
26,
450,
83,
2,
450,
1101,
14,
711,
63,
5159,
267,
340,
291,
14,
973,
14,
493,
63,
1000,
14,
719,
63,
19234,
26,
288,
2538,
847,
298,
334,
2682,
2924,
267,
587,
26,
288,
2538,
847,
298,
334,
25166,
2924,
267,
372,
2538,
339,
347,
2538,
22122,
8,
277,
304,
267,
2538,
275,
298,
22122,
26,
450,
83,
2,
450,
822,
8,
277,
14,
973,
14,
493,
63,
1000,
14,
7995,
9,
267,
372,
2538,
339,
347,
2538,
11761,
8,
277,
304,
267,
2538,
275,
298,
9392,
26,
10536,
18,
70,
19487,
1204,
428,
484,
26,
10536,
18,
70,
19487,
2,
450,
334,
288,
2069,
8,
277,
14,
973,
14,
493,
63,
1000,
14,
2394,
63,
7637,
9,
1182,
6619,
1182,
6619,
12,
288,
2069,
8,
277,
14,
973,
14,
493,
63,
1000,
14,
2394,
63,
1150,
9,
1182,
6619,
1182,
6619,
267,
776,
267,
372,
2538,
339,
347,
2538,
9270,
8,
277,
304,
267,
340,
291,
14,
6614,
26,
288,
372,
7210,
6824,
8559,
4353,
2,
267,
587,
26,
288,
372,
298,
6824,
8559,
4353,
2,
339,
347,
19420,
9270,
8,
277,
304,
267,
340,
291,
14,
6614,
26,
288,
6955,
4677,
14,
8191,
9270,
342,
288,
291,
14,
6614,
275,
756,
267,
587,
26,
288,
6955,
4677,
14,
2384,
9270,
342,
288,
291,
14,
6614,
275,
715,
339,
347,
664,
33,
4139,
324,
2042,
8,
277,
304,
267,
372,
2071,
83,
1103,
2282,
25759,
14,
1760,
2,
450,
4747,
15171,
14,
362,
8,
2676,
15171,
14,
7363,
2160,
9,
339,
347,
1475,
33,
4139,
324,
8,
277,
304,
267,
1249,
275,
984,
14,
3020,
5873,
267,
1249,
14,
3176,
8,
16,
12,
984,
14,
5904,
9,
267,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
288,
1249,
275,
788,
6808,
83,
4507,
450,
1680,
367,
1680,
315,
1249,
61,
267,
2088,
275,
298,
3680,
904,
8,
589,
9,
398,
327,
577,
1888,
1551,
7042,
641,
282,
4139,
324,
267,
2088,
275,
2088,
14,
1814,
480,
928,
14,
647,
401,
298,
2282,
25759,
14,
647,
3471,
1814,
14088,
306,
1490,
63,
5750,
6949,
25354,
1814,
14088,
885,
63,
5750,
6949,
6899,
398,
372,
298,
2866,
1182,
36,
450,
83,
971,
78,
5,
83,
2,
450,
334,
736,
14,
9458,
1062,
2088,
9,
339,
347,
365,
33,
4139,
324,
6589,
8,
277,
304,
267,
931,
275,
291,
14,
362,
33,
4139,
324,
2042,
342,
267,
372,
747,
14,
515,
14,
6292,
8,
515,
9,
436,
1551,
8,
515,
680,
739,
342,
508,
291,
14,
908,
33,
4139,
324,
342,
339,
347,
2538,
33,
4139,
324,
8,
277,
304,
267,
340,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
"""
Represents an EC2 Object
"""
from boto.ec2.tag import TagSet
class EC2Object(object):
def __init__(self, connection=None):
self.connection = connection
if self.connection and hasattr(self.connection, 'region'):
self.region = connection.region
else:
self.region = None
def startElement(self, name, attrs, connection):
return None
def endElement(self, name, value, connection):
setattr(self, name, value)
class TaggedEC2Object(EC2Object):
"""
Any EC2 resource that can be tagged should be represented
by a Python object that subclasses this class. This class
has the mechanism in place to handle the tagSet element in
the Describe* responses. If tags are found, it will create
a TagSet object and allow it to parse and collect the tags
into a dict that is stored in the "tags" attribute of the
object.
"""
def __init__(self, connection=None):
super(TaggedEC2Object, self).__init__(connection)
self.tags = TagSet()
def startElement(self, name, attrs, connection):
if name == 'tagSet':
return self.tags
else:
return None
def add_tag(self, key, value='', dry_run=False):
"""
Add a tag to this object. Tags are stored by AWS and can be used
to organize and filter resources. Adding a tag involves a round-trip
to the EC2 service.
:type key: str
:param key: The key or name of the tag being stored.
:type value: str
:param value: An optional value that can be stored with the tag.
If you want only the tag name and no value, the
value should be the empty string.
"""
self.add_tags({key: value}, dry_run)
def add_tags(self, tags, dry_run=False):
"""
Add tags to this object. Tags are stored by AWS and can be used
to organize and filter resources. Adding tags involves a round-trip
to the EC2 service.
:type tags: dict
:param tags: A dictionary of key-value pairs for the tags being stored.
If for some tags you want only the name and no value, the
corresponding value for that tag name should be an empty
string.
"""
status = self.connection.create_tags(
[self.id],
tags,
dry_run=dry_run
)
if self.tags is None:
self.tags = TagSet()
self.tags.update(tags)
def remove_tag(self, key, value=None, dry_run=False):
"""
Remove a tag from this object. Removing a tag involves a round-trip
to the EC2 service.
:type key: str
:param key: The key or name of the tag being stored.
:type value: str
:param value: An optional value that can be stored with the tag.
If a value is provided, it must match the value currently
stored in EC2. If not, the tag will not be removed. If
a value of None is provided, the tag will be
unconditionally deleted.
NOTE: There is an important distinction between a value
of '' and a value of None.
"""
self.remove_tags({key: value}, dry_run)
def remove_tags(self, tags, dry_run=False):
"""
Removes tags from this object. Removing tags involves a round-trip
to the EC2 service.
:type tags: dict
:param tags: A dictionary of key-value pairs for the tags being removed.
For each key, the provided value must match the value
currently stored in EC2. If not, that particular tag will
not be removed. However, if a value of None is provided,
the tag will be unconditionally deleted.
NOTE: There is an important distinction between a value of
'' and a value of None.
"""
status = self.connection.delete_tags(
[self.id],
tags,
dry_run=dry_run
)
for key, value in tags.items():
if key in self.tags:
if value is None or value == self.tags[key]:
del self.tags[key]
|
mit
|
[
3,
1898,
334,
67,
9,
8315,
13,
6542,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
1898,
334,
67,
9,
7129,
12,
662,
85,
915,
89,
541,
527,
15285,
12,
3277,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
624,
199,
18089,
376,
15352,
18,
6935,
199,
624,
199,
504,
6055,
14,
825,
18,
14,
1450,
492,
8053,
1084,
421,
199,
533,
15352,
18,
1692,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1950,
29,
403,
304,
267,
291,
14,
2105,
275,
1950,
267,
340,
291,
14,
2105,
436,
2688,
8,
277,
14,
2105,
12,
283,
4551,
735,
288,
291,
14,
4551,
275,
1950,
14,
4551,
267,
587,
26,
288,
291,
14,
4551,
275,
488,
339,
347,
26325,
8,
277,
12,
536,
12,
3290,
12,
1950,
304,
267,
372,
488,
339,
347,
28920,
8,
277,
12,
536,
12,
574,
12,
1950,
304,
267,
5371,
8,
277,
12,
536,
12,
574,
9,
421,
199,
533,
32121,
4220,
18,
1692,
8,
4220,
18,
1692,
304,
272,
408,
272,
6184,
15352,
18,
2073,
626,
883,
506,
20018,
1077,
506,
11159,
272,
701,
282,
2018,
909,
626,
9180,
642,
1021,
14,
221,
961,
1021,
272,
965,
314,
14729,
315,
4192,
370,
2429,
314,
30050,
1819,
315,
272,
314,
28571,
1235,
10,
9320,
14,
221,
982,
3762,
787,
1911,
12,
652,
911,
1218,
272,
282,
8053,
1084,
909,
436,
2040,
652,
370,
2198,
436,
8775,
314,
3762,
272,
1901,
282,
1211,
626,
365,
5489,
315,
314,
298,
2969,
2,
2225,
402,
314,
272,
909,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1950,
29,
403,
304,
267,
1613,
8,
26403,
4220,
18,
1692,
12,
291,
2843,
826,
721,
2105,
9,
267,
291,
14,
2969,
275,
8053,
1084,
342,
339,
347,
26325,
8,
277,
12,
536,
12,
3290,
12,
1950,
304,
267,
340,
536,
508,
283,
27420,
356,
288,
372,
291,
14,
2969,
267,
587,
26,
288,
372,
488,
339,
347,
1050,
63,
1450,
8,
277,
12,
790,
12,
574,
4581,
9951,
63,
1065,
29,
797,
304,
267,
408,
267,
2654,
282,
1947,
370,
642,
909,
14,
221,
25204,
787,
5489,
701,
10168,
436,
883,
506,
1202,
267,
370,
20765,
794,
436,
2457,
5944,
14,
221,
12934,
282,
1947,
25613,
2310,
282,
6168,
13,
7254,
267,
370,
314,
15352,
18,
2435,
14,
398,
520,
466,
790,
26,
620,
267,
520,
635,
790,
26,
710,
790,
503,
536,
402,
314,
1947,
3769,
5489,
14,
398,
520,
466,
574,
26,
620,
267,
520,
635,
574,
26,
1626,
2716,
574,
626,
883,
506,
5489,
543,
314,
1947,
14,
1993,
982,
1265,
2934,
1454,
314,
1947,
536,
436,
949,
574,
12,
314,
1993,
574,
1077,
506,
314,
2701,
1059,
14,
267,
408,
267,
291,
14,
525,
63,
2969,
2561,
498,
26,
574,
1386,
9951,
63,
1065,
9,
339,
347,
1050,
63,
2969,
8,
277,
12,
3762,
12,
9951,
63,
1065,
29,
797,
304,
267,
408,
267,
2654,
3762,
370,
642,
909,
14,
221,
25204,
787,
5489,
701,
10168,
436,
883,
506,
1202,
267,
370,
20765,
794,
436,
2457,
5944,
14,
221,
12934,
3762,
25613,
2310,
282,
6168,
13,
7254,
267,
370,
314,
15352,
18,
2435,
14,
398,
520,
466,
3762,
26,
1211,
267,
520,
635,
3762,
26,
437,
2600,
402,
790,
13,
585,
6342,
367,
314,
3762,
3769,
5489,
14,
2151,
982,
367,
2005,
3762,
1265,
2934,
1454,
314,
536,
436,
949,
574,
12,
314,
2151,
5226,
574,
367,
626,
1947,
536,
1077,
506,
376,
2701,
2151,
1059,
14,
267,
408,
267,
2004,
275,
291,
14,
2105,
14,
981,
63,
2969,
8,
288,
359,
277,
14,
344,
467,
288,
3762,
12,
288,
9951,
63,
1065,
29,
10481,
63,
1065,
267,
776,
267,
340,
291,
14,
2969,
365,
488,
26,
288,
291,
14,
2969,
275,
8053,
1084,
342,
267,
291,
14,
2969,
14,
873,
8,
2969,
9,
339,
347,
2813,
63,
1450,
8,
277,
12,
790,
12,
574,
29,
403,
12,
9951,
63,
1065,
29,
797,
304,
267,
408,
267,
5852,
282,
1947,
687,
642,
909,
14,
221,
29343,
282,
1947,
25613,
2310,
282,
6168,
13,
7254,
267,
370,
314,
15352,
18,
2435,
14,
398,
520,
466,
790,
26,
620,
267,
520,
635,
790,
26,
710,
790,
503,
536,
402,
314,
1947,
3769,
5489,
14,
398,
520,
466,
574,
26,
620,
267,
520,
635,
574,
26,
1626,
2716,
574,
626,
883,
506,
5489,
543,
314,
1947,
14,
1993,
982,
282,
574,
365,
2741,
12,
652,
1471,
1336,
314,
574,
5544,
1993,
5489,
315,
15352,
18,
14,
221,
982,
440,
12,
314,
1947,
911,
440,
506,
4829,
14,
221,
982,
1993,
282,
574,
402,
488,
365,
2741,
12,
314,
1947,
911,
506,
1993,
625,
31565,
5463,
14,
1993,
6944,
26,
6006,
365,
376,
11012,
2917,
262,
414,
3382,
282,
574,
1993,
402,
2125,
436,
282,
574,
402,
488
] |
[
1898,
334,
67,
9,
8315,
13,
6542,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
1898,
334,
67,
9,
7129,
12,
662,
85,
915,
89,
541,
527,
15285,
12,
3277,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
624,
199,
18089,
376,
15352,
18,
6935,
199,
624,
199,
504,
6055,
14,
825,
18,
14,
1450,
492,
8053,
1084,
421,
199,
533,
15352,
18,
1692,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1950,
29,
403,
304,
267,
291,
14,
2105,
275,
1950,
267,
340,
291,
14,
2105,
436,
2688,
8,
277,
14,
2105,
12,
283,
4551,
735,
288,
291,
14,
4551,
275,
1950,
14,
4551,
267,
587,
26,
288,
291,
14,
4551,
275,
488,
339,
347,
26325,
8,
277,
12,
536,
12,
3290,
12,
1950,
304,
267,
372,
488,
339,
347,
28920,
8,
277,
12,
536,
12,
574,
12,
1950,
304,
267,
5371,
8,
277,
12,
536,
12,
574,
9,
421,
199,
533,
32121,
4220,
18,
1692,
8,
4220,
18,
1692,
304,
272,
408,
272,
6184,
15352,
18,
2073,
626,
883,
506,
20018,
1077,
506,
11159,
272,
701,
282,
2018,
909,
626,
9180,
642,
1021,
14,
221,
961,
1021,
272,
965,
314,
14729,
315,
4192,
370,
2429,
314,
30050,
1819,
315,
272,
314,
28571,
1235,
10,
9320,
14,
221,
982,
3762,
787,
1911,
12,
652,
911,
1218,
272,
282,
8053,
1084,
909,
436,
2040,
652,
370,
2198,
436,
8775,
314,
3762,
272,
1901,
282,
1211,
626,
365,
5489,
315,
314,
298,
2969,
2,
2225,
402,
314,
272,
909,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1950,
29,
403,
304,
267,
1613,
8,
26403,
4220,
18,
1692,
12,
291,
2843,
826,
721,
2105,
9,
267,
291,
14,
2969,
275,
8053,
1084,
342,
339,
347,
26325,
8,
277,
12,
536,
12,
3290,
12,
1950,
304,
267,
340,
536,
508,
283,
27420,
356,
288,
372,
291,
14,
2969,
267,
587,
26,
288,
372,
488,
339,
347,
1050,
63,
1450,
8,
277,
12,
790,
12,
574,
4581,
9951,
63,
1065,
29,
797,
304,
267,
408,
267,
2654,
282,
1947,
370,
642,
909,
14,
221,
25204,
787,
5489,
701,
10168,
436,
883,
506,
1202,
267,
370,
20765,
794,
436,
2457,
5944,
14,
221,
12934,
282,
1947,
25613,
2310,
282,
6168,
13,
7254,
267,
370,
314,
15352,
18,
2435,
14,
398,
520,
466,
790,
26,
620,
267,
520,
635,
790,
26,
710,
790,
503,
536,
402,
314,
1947,
3769,
5489,
14,
398,
520,
466,
574,
26,
620,
267,
520,
635,
574,
26,
1626,
2716,
574,
626,
883,
506,
5489,
543,
314,
1947,
14,
1993,
982,
1265,
2934,
1454,
314,
1947,
536,
436,
949,
574,
12,
314,
1993,
574,
1077,
506,
314,
2701,
1059,
14,
267,
408,
267,
291,
14,
525,
63,
2969,
2561,
498,
26,
574,
1386,
9951,
63,
1065,
9,
339,
347,
1050,
63,
2969,
8,
277,
12,
3762,
12,
9951,
63,
1065,
29,
797,
304,
267,
408,
267,
2654,
3762,
370,
642,
909,
14,
221,
25204,
787,
5489,
701,
10168,
436,
883,
506,
1202,
267,
370,
20765,
794,
436,
2457,
5944,
14,
221,
12934,
3762,
25613,
2310,
282,
6168,
13,
7254,
267,
370,
314,
15352,
18,
2435,
14,
398,
520,
466,
3762,
26,
1211,
267,
520,
635,
3762,
26,
437,
2600,
402,
790,
13,
585,
6342,
367,
314,
3762,
3769,
5489,
14,
2151,
982,
367,
2005,
3762,
1265,
2934,
1454,
314,
536,
436,
949,
574,
12,
314,
2151,
5226,
574,
367,
626,
1947,
536,
1077,
506,
376,
2701,
2151,
1059,
14,
267,
408,
267,
2004,
275,
291,
14,
2105,
14,
981,
63,
2969,
8,
288,
359,
277,
14,
344,
467,
288,
3762,
12,
288,
9951,
63,
1065,
29,
10481,
63,
1065,
267,
776,
267,
340,
291,
14,
2969,
365,
488,
26,
288,
291,
14,
2969,
275,
8053,
1084,
342,
267,
291,
14,
2969,
14,
873,
8,
2969,
9,
339,
347,
2813,
63,
1450,
8,
277,
12,
790,
12,
574,
29,
403,
12,
9951,
63,
1065,
29,
797,
304,
267,
408,
267,
5852,
282,
1947,
687,
642,
909,
14,
221,
29343,
282,
1947,
25613,
2310,
282,
6168,
13,
7254,
267,
370,
314,
15352,
18,
2435,
14,
398,
520,
466,
790,
26,
620,
267,
520,
635,
790,
26,
710,
790,
503,
536,
402,
314,
1947,
3769,
5489,
14,
398,
520,
466,
574,
26,
620,
267,
520,
635,
574,
26,
1626,
2716,
574,
626,
883,
506,
5489,
543,
314,
1947,
14,
1993,
982,
282,
574,
365,
2741,
12,
652,
1471,
1336,
314,
574,
5544,
1993,
5489,
315,
15352,
18,
14,
221,
982,
440,
12,
314,
1947,
911,
440,
506,
4829,
14,
221,
982,
1993,
282,
574,
402,
488,
365,
2741,
12,
314,
1947,
911,
506,
1993,
625,
31565,
5463,
14,
1993,
6944,
26,
6006,
365,
376,
11012,
2917,
262,
414,
3382,
282,
574,
1993,
402,
2125,
436,
282,
574,
402,
488,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
alxgu/ansible
|
lib/ansible/plugins/doc_fragments/default_callback.py
|
45
|
2283
|
# -*- coding: utf-8 -*-
# Copyright: (c) 2017, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
class ModuleDocFragment(object):
DOCUMENTATION = r'''
options:
display_skipped_hosts:
name: Show skipped hosts
description: "Toggle to control displaying skipped task/host results in a task"
type: bool
default: yes
env:
- name: DISPLAY_SKIPPED_HOSTS
deprecated:
why: environment variables without "ANSIBLE_" prefix are deprecated
version: "2.12"
alternatives: the "ANSIBLE_DISPLAY_SKIPPED_HOSTS" environment variable
- name: ANSIBLE_DISPLAY_SKIPPED_HOSTS
ini:
- key: display_skipped_hosts
section: defaults
display_ok_hosts:
name: Show 'ok' hosts
description: "Toggle to control displaying 'ok' task/host results in a task"
type: bool
default: yes
env:
- name: ANSIBLE_DISPLAY_OK_HOSTS
ini:
- key: display_ok_hosts
section: defaults
version_added: '2.7'
display_failed_stderr:
name: Use STDERR for failed and unreachable tasks
description: "Toggle to control whether failed and unreachable tasks are displayed to STDERR (vs. STDOUT)"
type: bool
default: no
env:
- name: ANSIBLE_DISPLAY_FAILED_STDERR
ini:
- key: display_failed_stderr
section: defaults
version_added: '2.7'
show_custom_stats:
name: Show custom stats
description: 'This adds the custom stats set via the set_stats plugin to the play recap'
type: bool
default: no
env:
- name: ANSIBLE_SHOW_CUSTOM_STATS
ini:
- key: show_custom_stats
section: defaults
show_per_host_start:
name: Show per host task start
description: 'This adds output that shows when a task is started to execute for each host'
type: bool
default: no
env:
- name: ANSIBLE_SHOW_PER_HOST_START
ini:
- key: show_per_host_start
section: defaults
version_added: '2.9'
'''
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
26,
334,
67,
9,
9708,
12,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
421,
199,
533,
5673,
3768,
11080,
8,
785,
304,
339,
29970,
2594,
275,
519,
2344,
272,
1511,
26,
489,
2929,
63,
11962,
63,
5146,
26,
267,
536,
26,
12968,
9645,
7057,
267,
1369,
26,
298,
24743,
370,
3304,
20589,
9645,
2120,
15,
1102,
2058,
315,
282,
2120,
2,
267,
730,
26,
2155,
267,
849,
26,
9456,
267,
2589,
26,
881,
446,
536,
26,
7587,
11625,
63,
13525,
19359,
63,
23775,
288,
5906,
26,
1598,
10842,
26,
3734,
2860,
1928,
298,
8490,
12172,
2403,
787,
5906,
1598,
1015,
26,
298,
18,
14,
713,
2,
1598,
8679,
10661,
26,
314,
298,
8490,
63,
20993,
63,
13525,
19359,
63,
23775,
2,
3734,
1750,
881,
446,
536,
26,
32271,
7187,
63,
20993,
63,
13525,
19359,
63,
23775,
267,
20364,
26,
881,
446,
790,
26,
2929,
63,
11962,
63,
5146,
288,
3420,
26,
4243,
489,
2929,
63,
745,
63,
5146,
26,
267,
536,
26,
12968,
283,
745,
7,
7057,
267,
1369,
26,
298,
24743,
370,
3304,
20589,
283,
745,
7,
2120,
15,
1102,
2058,
315,
282,
2120,
2,
267,
730,
26,
2155,
267,
849,
26,
9456,
267,
2589,
26,
881,
446,
536,
26,
32271,
7187,
63,
20993,
63,
3593,
63,
23775,
267,
20364,
26,
881,
446,
790,
26,
2929,
63,
745,
63,
5146,
288,
3420,
26,
4243,
267,
1015,
63,
3270,
26,
283,
18,
14,
23,
7,
489,
2929,
63,
4892,
63,
3083,
26,
267,
536,
26,
3645,
30118,
2666,
367,
3405,
436,
625,
15837,
6527,
267,
1369,
26,
298,
24743,
370,
3304,
3775,
3405,
436,
625,
15837,
6527,
787,
9080,
370,
30118,
2666,
334,
3122,
14,
4384,
12619,
2924,
267,
730,
26,
2155,
267,
849,
26,
949,
267,
2589,
26,
881,
446,
536,
26,
32271,
7187,
63,
20993,
63,
12299,
63,
18472,
2666,
267,
20364,
26,
881,
446,
790,
26,
2929,
63,
4892,
63,
3083,
288,
3420,
26,
4243,
267,
1015,
63,
3270,
26,
283,
18,
14,
23,
7,
489,
2498,
63,
4229,
63,
3200,
26,
267,
536,
26,
12968,
3537,
5020,
267,
1369,
26,
283,
2765,
9584,
314,
3537,
5020,
663,
4799,
314,
663,
63,
3200,
3589,
370,
314,
5232,
295,
2874,
7,
267,
730,
26,
2155,
267,
849,
26,
949,
267,
2589,
26,
881,
446,
536,
26,
32271,
7187,
63,
19085,
63,
20519,
63,
19202,
267,
20364,
26,
881,
446,
790,
26,
2498,
63,
4229,
63,
3200,
288,
3420,
26,
4243,
489,
2498,
63,
529,
63,
1102,
63,
928,
26,
267,
536,
26,
12968,
1126,
1591,
2120,
1343,
267,
1369,
26,
283,
2765,
9584,
1072,
626,
13703,
1380,
282,
2120,
365,
8239,
370,
5341,
367,
1924,
1591,
7,
267,
730,
26,
2155,
267,
849,
26,
949,
267,
2589,
26,
881,
446,
536,
26,
32271,
7187,
63,
19085,
63,
4227,
63,
5449,
63,
7363,
267,
20364,
26,
881,
446,
790,
26,
2498,
63,
529,
63,
1102,
63,
928,
288,
3420,
26,
4243,
267,
1015,
63,
3270,
26,
283,
18,
14,
25,
7,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
26,
334,
67,
9,
9708,
12,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
421,
199,
533,
5673,
3768,
11080,
8,
785,
304,
339,
29970,
2594,
275,
519,
2344,
272,
1511,
26,
489,
2929,
63,
11962,
63,
5146,
26,
267,
536,
26,
12968,
9645,
7057,
267,
1369,
26,
298,
24743,
370,
3304,
20589,
9645,
2120,
15,
1102,
2058,
315,
282,
2120,
2,
267,
730,
26,
2155,
267,
849,
26,
9456,
267,
2589,
26,
881,
446,
536,
26,
7587,
11625,
63,
13525,
19359,
63,
23775,
288,
5906,
26,
1598,
10842,
26,
3734,
2860,
1928,
298,
8490,
12172,
2403,
787,
5906,
1598,
1015,
26,
298,
18,
14,
713,
2,
1598,
8679,
10661,
26,
314,
298,
8490,
63,
20993,
63,
13525,
19359,
63,
23775,
2,
3734,
1750,
881,
446,
536,
26,
32271,
7187,
63,
20993,
63,
13525,
19359,
63,
23775,
267,
20364,
26,
881,
446,
790,
26,
2929,
63,
11962,
63,
5146,
288,
3420,
26,
4243,
489,
2929,
63,
745,
63,
5146,
26,
267,
536,
26,
12968,
283,
745,
7,
7057,
267,
1369,
26,
298,
24743,
370,
3304,
20589,
283,
745,
7,
2120,
15,
1102,
2058,
315,
282,
2120,
2,
267,
730,
26,
2155,
267,
849,
26,
9456,
267,
2589,
26,
881,
446,
536,
26,
32271,
7187,
63,
20993,
63,
3593,
63,
23775,
267,
20364,
26,
881,
446,
790,
26,
2929,
63,
745,
63,
5146,
288,
3420,
26,
4243,
267,
1015,
63,
3270,
26,
283,
18,
14,
23,
7,
489,
2929,
63,
4892,
63,
3083,
26,
267,
536,
26,
3645,
30118,
2666,
367,
3405,
436,
625,
15837,
6527,
267,
1369,
26,
298,
24743,
370,
3304,
3775,
3405,
436,
625,
15837,
6527,
787,
9080,
370,
30118,
2666,
334,
3122,
14,
4384,
12619,
2924,
267,
730,
26,
2155,
267,
849,
26,
949,
267,
2589,
26,
881,
446,
536,
26,
32271,
7187,
63,
20993,
63,
12299,
63,
18472,
2666,
267,
20364,
26,
881,
446,
790,
26,
2929,
63,
4892,
63,
3083,
288,
3420,
26,
4243,
267,
1015,
63,
3270,
26,
283,
18,
14,
23,
7,
489,
2498,
63,
4229,
63,
3200,
26,
267,
536,
26,
12968,
3537,
5020,
267,
1369,
26,
283,
2765,
9584,
314,
3537,
5020,
663,
4799,
314,
663,
63,
3200,
3589,
370,
314,
5232,
295,
2874,
7,
267,
730,
26,
2155,
267,
849,
26,
949,
267,
2589,
26,
881,
446,
536,
26,
32271,
7187,
63,
19085,
63,
20519,
63,
19202,
267,
20364,
26,
881,
446,
790,
26,
2498,
63,
4229,
63,
3200,
288,
3420,
26,
4243,
489,
2498,
63,
529,
63,
1102,
63,
928,
26,
267,
536,
26,
12968,
1126,
1591,
2120,
1343,
267,
1369,
26,
283,
2765,
9584,
1072,
626,
13703,
1380,
282,
2120,
365,
8239,
370,
5341,
367,
1924,
1591,
7,
267,
730,
26,
2155,
267,
849,
26,
949,
267,
2589,
26,
881,
446,
536,
26,
32271,
7187,
63,
19085,
63,
4227,
63,
5449,
63,
7363,
267,
20364,
26,
881,
446,
790,
26,
2498,
63,
529,
63,
1102,
63,
928,
288,
3420,
26,
4243,
267,
1015,
63,
3270,
26,
283,
18,
14,
25,
7,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sahiljain/catapult
|
telemetry/telemetry/timeline/trace_data.py
|
6
|
11161
|
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import copy
import json
import logging
import os
import shutil
import subprocess
import tempfile
from telemetry.core import util
_TRACE2HTML_PATH = os.path.join(
util.GetCatapultDir(), 'tracing', 'bin', 'trace2html')
class NonSerializableTraceData(Exception):
"""Raised when raw trace data cannot be serialized to TraceData."""
pass
class TraceDataPart(object):
"""TraceData can have a variety of events.
These are called "parts" and are accessed by the following fixed field names.
"""
def __init__(self, raw_field_name):
self._raw_field_name = raw_field_name
def __repr__(self):
return 'TraceDataPart("%s")' % self._raw_field_name
@property
def raw_field_name(self):
return self._raw_field_name
def __eq__(self, other):
return self.raw_field_name == other.raw_field_name
def __hash__(self):
return hash(self.raw_field_name)
ATRACE_PART = TraceDataPart('systemTraceEvents')
BATTOR_TRACE_PART = TraceDataPart('powerTraceAsString')
CHROME_TRACE_PART = TraceDataPart('traceEvents')
CPU_TRACE_DATA = TraceDataPart('cpuSnapshots')
INSPECTOR_TRACE_PART = TraceDataPart('inspectorTimelineEvents')
SURFACE_FLINGER_PART = TraceDataPart('surfaceFlinger')
TAB_ID_PART = TraceDataPart('tabIds')
TELEMETRY_PART = TraceDataPart('telemetry')
ALL_TRACE_PARTS = {ATRACE_PART,
BATTOR_TRACE_PART,
CHROME_TRACE_PART,
CPU_TRACE_DATA,
INSPECTOR_TRACE_PART,
SURFACE_FLINGER_PART,
TAB_ID_PART,
TELEMETRY_PART}
ALL_TRACE_PARTS_RAW_NAMES = set(k.raw_field_name for k in ALL_TRACE_PARTS)
def _HasTraceFor(part, raw):
assert isinstance(part, TraceDataPart)
if part.raw_field_name not in raw:
return False
return len(raw[part.raw_field_name]) > 0
def _GetFilePathForTrace(trace, dir_path):
""" Return path to a file that contains |trace|.
Note: if |trace| is an instance of TraceFileHandle, this reuses the trace path
that the trace file handle holds. Otherwise, it creates a new trace file
in |dir_path| directory.
"""
if isinstance(trace, TraceFileHandle):
return trace.file_path
with tempfile.NamedTemporaryFile(mode='w', dir=dir_path, delete=False) as fp:
if isinstance(trace, basestring):
fp.write(trace)
elif isinstance(trace, dict) or isinstance(trace, list):
json.dump(trace, fp)
else:
raise TypeError('Trace is of unknown type.')
return fp.name
class TraceData(object):
""" TraceData holds a collection of traces from multiple sources.
A TraceData can have multiple active parts. Each part represents traces
collected from a different trace agent.
"""
def __init__(self):
"""Creates TraceData from the given data."""
self._raw_data = {}
self._events_are_safely_mutable = False
def _SetFromBuilder(self, d):
self._raw_data = d
self._events_are_safely_mutable = True
@property
def events_are_safely_mutable(self):
"""Returns true if the events in this value are completely sealed.
Some importers want to take complex fields out of the TraceData and add
them to the model, changing them subtly as they do so. If the TraceData
was constructed with data that is shared with something outside the trace
data, for instance a test harness, then this mutation is unexpected. But,
if the values are sealed, then mutating the events is a lot faster.
We know if events are sealed if the value came from a string, or if the
value came from a TraceDataBuilder.
"""
return self._events_are_safely_mutable
@property
def active_parts(self):
return {p for p in ALL_TRACE_PARTS if p.raw_field_name in self._raw_data}
def HasTracesFor(self, part):
return _HasTraceFor(part, self._raw_data)
def GetTracesFor(self, part):
""" Return the list of traces for |part| in string or dictionary forms.
Note: since this API return the traces that can be directly accessed in
memory, it may require lots of memory usage as some of the trace can be
very big.
For references, we have cases where Telemetry is OOM'ed because the memory
required for processing the trace in Python is too big (crbug.com/672097).
"""
assert isinstance(part, TraceDataPart)
if not self.HasTracesFor(part):
return []
traces_list = self._raw_data[part.raw_field_name]
# Since this API return the traces in memory form, and since the memory
# bottleneck of Telemetry is for keeping trace in memory, there is no uses
# in keeping the on-disk form of tracing beyond this point. Hence we convert
# all traces for part of form TraceFileHandle to the JSON form.
for i, data in enumerate(traces_list):
if isinstance(data, TraceFileHandle):
traces_list[i] = data.AsTraceData()
return traces_list
def GetTraceFor(self, part):
assert isinstance(part, TraceDataPart)
traces = self.GetTracesFor(part)
assert len(traces) == 1
return traces[0]
def CleanUpAllTraces(self):
""" Remove all the traces that this has handles to.
Those include traces stored in memory & on disk. After invoking this,
one can no longer uses this object for collecting the traces.
"""
for traces_list in self._raw_data.itervalues():
for trace in traces_list:
if isinstance(trace, TraceFileHandle):
trace.Clean()
self._raw_data = {}
def Serialize(self, file_path, trace_title=''):
"""Serializes the trace result to |file_path|.
"""
if not self._raw_data:
logging.warning('No traces to convert to html.')
return
temp_dir = tempfile.mkdtemp()
trace_files = []
try:
trace_size_data = {}
for part, traces_list in self._raw_data.iteritems():
for trace in traces_list:
path = _GetFilePathForTrace(trace, temp_dir)
trace_size_data.setdefault(part, 0)
trace_size_data[part] += os.path.getsize(path)
trace_files.append(path)
logging.info('Trace sizes in bytes: %s', trace_size_data)
cmd = (['python', _TRACE2HTML_PATH] + trace_files +
['--output', file_path] + ['--title', trace_title])
subprocess.check_output(cmd)
finally:
shutil.rmtree(temp_dir)
class TraceFileHandle(object):
"""A trace file handle object allows storing trace data on disk.
TraceFileHandle API allows one to collect traces from Chrome into disk instead
of keeping them in memory. This is important for keeping memory usage of
Telemetry low to avoid OOM (see:
https://github.com/catapult-project/catapult/issues/3119).
The fact that this uses a file underneath to store tracing data means the
callsite is repsonsible for discarding the file when they no longer need the
tracing data. Call TraceFileHandle.Clean when you done using this object.
"""
def __init__(self):
self._backing_file = None
self._file_path = None
self._trace_data = None
def Open(self):
assert not self._backing_file and not self._file_path
self._backing_file = tempfile.NamedTemporaryFile(delete=False, mode='a')
def AppendTraceData(self, partial_trace_data):
assert isinstance(partial_trace_data, basestring)
self._backing_file.write(partial_trace_data)
@property
def file_path(self):
assert self._file_path, (
'Either the handle need to be closed first or this handle is cleaned')
return self._file_path
def Close(self):
assert self._backing_file
self._backing_file.close()
self._file_path = self._backing_file.name
self._backing_file = None
def AsTraceData(self):
"""Get the object form of trace data that this handle manages.
*Warning: this can have large memory footprint if the trace data is big.
Since this requires the in-memory form of the trace, it is no longer useful
to still keep the backing file underneath, invoking this will also discard
the file to avoid the risk of leaking the backing trace file.
"""
if self._trace_data:
return self._trace_data
assert self._file_path
with open(self._file_path) as f:
self._trace_data = json.load(f)
self.Clean()
return self._trace_data
def Clean(self):
"""Remove the backing file used for storing trace on disk.
This should be called when and only when you no longer need to use
TraceFileHandle.
"""
assert self._file_path
os.remove(self._file_path)
self._file_path = None
class TraceDataBuilder(object):
"""TraceDataBuilder helps build up a trace from multiple trace agents.
TraceData is supposed to be immutable, but it is useful during recording to
have a mutable version. That is TraceDataBuilder.
"""
def __init__(self):
self._raw_data = {}
def AsData(self):
if self._raw_data == None:
raise Exception('Can only AsData once')
data = TraceData()
data._SetFromBuilder(self._raw_data)
self._raw_data = None
return data
def AddTraceFor(self, part, trace):
assert isinstance(part, TraceDataPart)
if part == CHROME_TRACE_PART:
assert (isinstance(trace, dict) or
isinstance(trace, TraceFileHandle))
else:
assert (isinstance(trace, basestring) or
isinstance(trace, dict) or
isinstance(trace, list))
if self._raw_data == None:
raise Exception('Already called AsData() on this builder.')
self._raw_data.setdefault(part.raw_field_name, [])
self._raw_data[part.raw_field_name].append(trace)
def HasTracesFor(self, part):
return _HasTraceFor(part, self._raw_data)
def CreateTraceDataFromRawData(raw_data):
"""Convenient method for creating a TraceData object from |raw_data|.
This is mostly used for testing.
Args:
raw_data can be:
+ A dictionary that repsents multiple trace parts. Keys of the
dictionary must always contain 'traceEvents', as chrome trace
must always present.
+ A list that represents Chrome trace events.
+ JSON string of either above.
"""
raw_data = copy.deepcopy(raw_data)
if isinstance(raw_data, basestring):
json_data = json.loads(raw_data)
else:
json_data = raw_data
b = TraceDataBuilder()
if not json_data:
return b.AsData()
if isinstance(json_data, dict):
assert 'traceEvents' in json_data, 'Only raw chrome trace is supported'
trace_parts_keys = []
for k in json_data:
if k != 'traceEvents' and k in ALL_TRACE_PARTS_RAW_NAMES:
trace_parts_keys.append(k)
b.AddTraceFor(TraceDataPart(k), json_data[k])
# Delete the data for extra keys to form trace data for Chrome part only.
for k in trace_parts_keys:
del json_data[k]
b.AddTraceFor(CHROME_TRACE_PART, json_data)
elif isinstance(json_data, list):
b.AddTraceFor(CHROME_TRACE_PART, {'traceEvents': json_data})
else:
raise NonSerializableTraceData('Unrecognized data format.')
return b.AsData()
|
bsd-3-clause
|
[
3,
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
1331,
199,
646,
2022,
199,
646,
2050,
199,
646,
747,
199,
646,
5145,
199,
646,
3873,
199,
646,
5549,
199,
199,
504,
17298,
14,
1018,
492,
4884,
421,
199,
63,
20112,
18,
4943,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
272,
4884,
14,
1002,
35,
419,
80,
427,
3567,
1062,
283,
21635,
297,
283,
1393,
297,
283,
3446,
18,
1360,
358,
421,
199,
533,
10172,
3571,
14065,
3921,
1451,
8,
1726,
304,
523,
408,
16894,
1380,
3066,
3307,
666,
3913,
506,
6380,
370,
11680,
1451,
1041,
523,
986,
421,
199,
533,
11680,
1451,
8416,
8,
785,
304,
523,
408,
3921,
1451,
883,
1172,
282,
32246,
402,
4474,
14,
819,
5723,
787,
2797,
298,
4181,
2,
436,
787,
13810,
701,
314,
2569,
6317,
901,
1561,
14,
523,
408,
523,
347,
636,
826,
721,
277,
12,
3066,
63,
698,
63,
354,
304,
272,
291,
423,
1773,
63,
698,
63,
354,
275,
3066,
63,
698,
63,
354,
819,
347,
636,
2722,
721,
277,
304,
272,
372,
283,
3921,
1451,
8416,
3647,
83,
32292,
450,
291,
423,
1773,
63,
698,
63,
354,
819,
768,
1829,
523,
347,
3066,
63,
698,
63,
354,
8,
277,
304,
272,
372,
291,
423,
1773,
63,
698,
63,
354,
819,
347,
636,
4077,
721,
277,
12,
1163,
304,
272,
372,
291,
14,
1773,
63,
698,
63,
354,
508,
1163,
14,
1773,
63,
698,
63,
354,
819,
347,
636,
2227,
721,
277,
304,
272,
372,
2631,
8,
277,
14,
1773,
63,
698,
63,
354,
9,
421,
199,
619,
50,
4121,
63,
14848,
275,
11680,
1451,
8416,
360,
2253,
3921,
11770,
358,
199,
34,
11712,
726,
63,
20112,
63,
14848,
275,
11680,
1451,
8416,
360,
5652,
3921,
2822,
1558,
358,
199,
1244,
31364,
63,
20112,
63,
14848,
275,
11680,
1451,
8416,
360,
3446,
11770,
358,
199,
11011,
63,
20112,
63,
3998,
275,
11680,
1451,
8416,
360,
3541,
12038,
83,
358,
199,
10789,
11401,
726,
63,
20112,
63,
14848,
275,
11680,
1451,
8416,
360,
26047,
27097,
11770,
358,
199,
51,
1230,
13199,
63,
3143,
1206,
540,
63,
14848,
275,
11680,
1451,
8416,
360,
10992,
38,
2983,
281,
358,
199,
10129,
63,
998,
63,
14848,
275,
11680,
1451,
8416,
360,
2902,
11506,
358,
199,
3727,
906,
25922,
63,
14848,
275,
11680,
1451,
8416,
360,
15253,
10987,
358,
199,
199,
1761,
63,
20112,
63,
14848,
51,
275,
469,
619,
50,
4121,
63,
14848,
12,
673,
699,
11712,
726,
63,
20112,
63,
14848,
12,
673,
6624,
31364,
63,
20112,
63,
14848,
12,
673,
11952,
63,
20112,
63,
3998,
12,
673,
1621,
51,
11401,
726,
63,
20112,
63,
14848,
12,
673,
428,
1230,
13199,
63,
3143,
1206,
540,
63,
14848,
12,
673,
17916,
63,
998,
63,
14848,
12,
673,
10686,
906,
25922,
63,
14848,
93,
199,
199,
1761,
63,
20112,
63,
14848,
51,
63,
4307,
63,
14546,
275,
663,
8,
75,
14,
1773,
63,
698,
63,
354,
367,
1022,
315,
11727,
63,
20112,
63,
14848,
51,
9,
199,
199,
318,
485,
6362,
3921,
1858,
8,
2064,
12,
3066,
304,
523,
702,
1228,
8,
2064,
12,
11680,
1451,
8416,
9,
523,
340,
1777,
14,
1773,
63,
698,
63,
354,
440,
315,
3066,
26,
272,
372,
756,
523,
372,
822,
8,
1773,
59,
2064,
14,
1773,
63,
698,
63,
354,
566,
690,
378,
421,
199,
318,
485,
1002,
14225,
1858,
3921,
8,
3446,
12,
2935,
63,
515,
304,
523,
408,
1432,
931,
370,
282,
570,
626,
3509,
1204,
3446,
18257,
819,
3390,
26,
340,
1204,
3446,
92,
365,
376,
1256,
402,
11680,
1173,
5940,
12,
642,
295,
5589,
314,
3307,
931,
523,
626,
314,
3307,
570,
2429,
15164,
14,
6630,
12,
652,
8491,
282,
892,
3307,
570,
523,
315,
1204,
694,
63,
515,
92,
2082,
14,
523,
408,
523,
340,
1228,
8,
3446,
12,
11680,
1173,
5940,
304,
272,
372,
3307,
14,
493,
63,
515,
523,
543,
5549,
14,
19320,
8,
632,
534,
87,
297,
2935,
29,
694,
63,
515,
12,
3145,
29,
797,
9,
465,
4090,
26,
272,
340,
1228,
8,
3446,
12,
7116,
304,
489,
4090,
14,
952,
8,
3446,
9,
272,
916,
1228,
8,
3446,
12,
1211,
9,
503,
1228,
8,
3446,
12,
769,
304,
489,
2022,
14,
2724,
8,
3446,
12,
4090,
9,
272,
587,
26,
489,
746,
3146,
360,
3921,
365,
402,
5809,
730,
2659,
272,
372,
4090,
14,
354,
421,
199,
533,
11680,
1451,
8,
785,
304,
523,
408,
11680,
1451,
15164,
282,
3245,
402,
26365,
687,
3663,
5274,
14,
819,
437,
11680,
1451,
883,
1172,
3663,
4702,
4184,
14,
7048,
1777,
8469,
26365,
523,
13736,
687,
282,
3365,
3307,
6631,
14,
523,
408,
523,
347,
636,
826,
721,
277,
304,
272,
408,
10607,
11680,
1451,
687,
314,
1627,
666,
1041,
272,
291,
423,
1773,
63,
576,
275,
1052,
272,
291,
423,
4368,
63,
1530,
63,
2231,
70,
7742,
63,
17404,
275,
756,
819,
347,
485,
1084,
2532,
6437,
8,
277,
12,
366,
304,
272,
291,
423,
1773,
63,
576,
275,
366,
272,
291,
423,
4368,
63,
1530,
63,
2231,
70,
7742,
63,
17404,
275,
715,
819,
768,
1829,
523,
347,
4474,
63,
1530,
63,
2231,
70,
7742,
63,
17404,
8,
277,
304,
272,
408,
3407,
2549,
340,
314,
4474,
315,
642,
574,
787,
14793,
29894,
1146,
14,
339,
6601,
1742,
27568,
2934,
370,
5452,
6114,
1504,
734,
402,
314,
11680,
1451,
436,
1050,
272,
3062,
370,
314,
1402,
12,
13729,
3062,
1007,
84,
590,
465,
2985,
886,
880,
14,
982,
314,
11680,
1451,
272,
1990,
14701,
543,
666,
626,
365,
5709,
543,
6020,
9682,
314,
3307,
272,
666,
12,
367,
1256,
282,
511,
20458,
12,
2066,
642,
31083,
365,
10537,
14,
11017,
12,
272,
340,
314,
1338,
787,
29894,
1146,
12,
2066,
8567,
1958,
314,
4474,
365,
282,
13918,
12930,
14,
339,
2136,
5715,
340,
4474,
787,
29894,
1146,
340,
314,
574,
20382,
687,
282,
1059,
12,
503,
340,
314,
272,
574,
20382,
687,
282,
11680,
1451,
6437,
14,
272,
408,
272,
372,
291,
423,
4368,
63,
1530,
63,
2231,
70,
7742,
63
] |
[
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
1331,
199,
646,
2022,
199,
646,
2050,
199,
646,
747,
199,
646,
5145,
199,
646,
3873,
199,
646,
5549,
199,
199,
504,
17298,
14,
1018,
492,
4884,
421,
199,
63,
20112,
18,
4943,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
272,
4884,
14,
1002,
35,
419,
80,
427,
3567,
1062,
283,
21635,
297,
283,
1393,
297,
283,
3446,
18,
1360,
358,
421,
199,
533,
10172,
3571,
14065,
3921,
1451,
8,
1726,
304,
523,
408,
16894,
1380,
3066,
3307,
666,
3913,
506,
6380,
370,
11680,
1451,
1041,
523,
986,
421,
199,
533,
11680,
1451,
8416,
8,
785,
304,
523,
408,
3921,
1451,
883,
1172,
282,
32246,
402,
4474,
14,
819,
5723,
787,
2797,
298,
4181,
2,
436,
787,
13810,
701,
314,
2569,
6317,
901,
1561,
14,
523,
408,
523,
347,
636,
826,
721,
277,
12,
3066,
63,
698,
63,
354,
304,
272,
291,
423,
1773,
63,
698,
63,
354,
275,
3066,
63,
698,
63,
354,
819,
347,
636,
2722,
721,
277,
304,
272,
372,
283,
3921,
1451,
8416,
3647,
83,
32292,
450,
291,
423,
1773,
63,
698,
63,
354,
819,
768,
1829,
523,
347,
3066,
63,
698,
63,
354,
8,
277,
304,
272,
372,
291,
423,
1773,
63,
698,
63,
354,
819,
347,
636,
4077,
721,
277,
12,
1163,
304,
272,
372,
291,
14,
1773,
63,
698,
63,
354,
508,
1163,
14,
1773,
63,
698,
63,
354,
819,
347,
636,
2227,
721,
277,
304,
272,
372,
2631,
8,
277,
14,
1773,
63,
698,
63,
354,
9,
421,
199,
619,
50,
4121,
63,
14848,
275,
11680,
1451,
8416,
360,
2253,
3921,
11770,
358,
199,
34,
11712,
726,
63,
20112,
63,
14848,
275,
11680,
1451,
8416,
360,
5652,
3921,
2822,
1558,
358,
199,
1244,
31364,
63,
20112,
63,
14848,
275,
11680,
1451,
8416,
360,
3446,
11770,
358,
199,
11011,
63,
20112,
63,
3998,
275,
11680,
1451,
8416,
360,
3541,
12038,
83,
358,
199,
10789,
11401,
726,
63,
20112,
63,
14848,
275,
11680,
1451,
8416,
360,
26047,
27097,
11770,
358,
199,
51,
1230,
13199,
63,
3143,
1206,
540,
63,
14848,
275,
11680,
1451,
8416,
360,
10992,
38,
2983,
281,
358,
199,
10129,
63,
998,
63,
14848,
275,
11680,
1451,
8416,
360,
2902,
11506,
358,
199,
3727,
906,
25922,
63,
14848,
275,
11680,
1451,
8416,
360,
15253,
10987,
358,
199,
199,
1761,
63,
20112,
63,
14848,
51,
275,
469,
619,
50,
4121,
63,
14848,
12,
673,
699,
11712,
726,
63,
20112,
63,
14848,
12,
673,
6624,
31364,
63,
20112,
63,
14848,
12,
673,
11952,
63,
20112,
63,
3998,
12,
673,
1621,
51,
11401,
726,
63,
20112,
63,
14848,
12,
673,
428,
1230,
13199,
63,
3143,
1206,
540,
63,
14848,
12,
673,
17916,
63,
998,
63,
14848,
12,
673,
10686,
906,
25922,
63,
14848,
93,
199,
199,
1761,
63,
20112,
63,
14848,
51,
63,
4307,
63,
14546,
275,
663,
8,
75,
14,
1773,
63,
698,
63,
354,
367,
1022,
315,
11727,
63,
20112,
63,
14848,
51,
9,
199,
199,
318,
485,
6362,
3921,
1858,
8,
2064,
12,
3066,
304,
523,
702,
1228,
8,
2064,
12,
11680,
1451,
8416,
9,
523,
340,
1777,
14,
1773,
63,
698,
63,
354,
440,
315,
3066,
26,
272,
372,
756,
523,
372,
822,
8,
1773,
59,
2064,
14,
1773,
63,
698,
63,
354,
566,
690,
378,
421,
199,
318,
485,
1002,
14225,
1858,
3921,
8,
3446,
12,
2935,
63,
515,
304,
523,
408,
1432,
931,
370,
282,
570,
626,
3509,
1204,
3446,
18257,
819,
3390,
26,
340,
1204,
3446,
92,
365,
376,
1256,
402,
11680,
1173,
5940,
12,
642,
295,
5589,
314,
3307,
931,
523,
626,
314,
3307,
570,
2429,
15164,
14,
6630,
12,
652,
8491,
282,
892,
3307,
570,
523,
315,
1204,
694,
63,
515,
92,
2082,
14,
523,
408,
523,
340,
1228,
8,
3446,
12,
11680,
1173,
5940,
304,
272,
372,
3307,
14,
493,
63,
515,
523,
543,
5549,
14,
19320,
8,
632,
534,
87,
297,
2935,
29,
694,
63,
515,
12,
3145,
29,
797,
9,
465,
4090,
26,
272,
340,
1228,
8,
3446,
12,
7116,
304,
489,
4090,
14,
952,
8,
3446,
9,
272,
916,
1228,
8,
3446,
12,
1211,
9,
503,
1228,
8,
3446,
12,
769,
304,
489,
2022,
14,
2724,
8,
3446,
12,
4090,
9,
272,
587,
26,
489,
746,
3146,
360,
3921,
365,
402,
5809,
730,
2659,
272,
372,
4090,
14,
354,
421,
199,
533,
11680,
1451,
8,
785,
304,
523,
408,
11680,
1451,
15164,
282,
3245,
402,
26365,
687,
3663,
5274,
14,
819,
437,
11680,
1451,
883,
1172,
3663,
4702,
4184,
14,
7048,
1777,
8469,
26365,
523,
13736,
687,
282,
3365,
3307,
6631,
14,
523,
408,
523,
347,
636,
826,
721,
277,
304,
272,
408,
10607,
11680,
1451,
687,
314,
1627,
666,
1041,
272,
291,
423,
1773,
63,
576,
275,
1052,
272,
291,
423,
4368,
63,
1530,
63,
2231,
70,
7742,
63,
17404,
275,
756,
819,
347,
485,
1084,
2532,
6437,
8,
277,
12,
366,
304,
272,
291,
423,
1773,
63,
576,
275,
366,
272,
291,
423,
4368,
63,
1530,
63,
2231,
70,
7742,
63,
17404,
275,
715,
819,
768,
1829,
523,
347,
4474,
63,
1530,
63,
2231,
70,
7742,
63,
17404,
8,
277,
304,
272,
408,
3407,
2549,
340,
314,
4474,
315,
642,
574,
787,
14793,
29894,
1146,
14,
339,
6601,
1742,
27568,
2934,
370,
5452,
6114,
1504,
734,
402,
314,
11680,
1451,
436,
1050,
272,
3062,
370,
314,
1402,
12,
13729,
3062,
1007,
84,
590,
465,
2985,
886,
880,
14,
982,
314,
11680,
1451,
272,
1990,
14701,
543,
666,
626,
365,
5709,
543,
6020,
9682,
314,
3307,
272,
666,
12,
367,
1256,
282,
511,
20458,
12,
2066,
642,
31083,
365,
10537,
14,
11017,
12,
272,
340,
314,
1338,
787,
29894,
1146,
12,
2066,
8567,
1958,
314,
4474,
365,
282,
13918,
12930,
14,
339,
2136,
5715,
340,
4474,
787,
29894,
1146,
340,
314,
574,
20382,
687,
282,
1059,
12,
503,
340,
314,
272,
574,
20382,
687,
282,
11680,
1451,
6437,
14,
272,
408,
272,
372,
291,
423,
4368,
63,
1530,
63,
2231,
70,
7742,
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,
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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
] |
rchicoli/samba
|
selftest/selftest.py
|
4
|
16699
|
#!/usr/bin/python -u
# Bootstrap Samba and run a number of tests against it.
# Copyright (C) 2005-2012 Jelmer Vernooij <jelmer@samba.org>
# Copyright (C) 2007-2009 Stefan Metzmacher <metze@samba.org>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import atexit
from cStringIO import StringIO
import os
import sys
import signal
import subprocess
import subunit
import traceback
import warnings
import optparse
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
from selftest import (
socket_wrapper,
subunithelper,
testlist,
)
from selftest.client import write_clientconf
from selftest.run import (
expand_command_list,
expand_command_run,
exported_envvars_str,
now,
run_testsuite_command,
)
from selftest.target import (
EnvironmentManager,
NoneTarget,
UnsupportedEnvironment,
)
includes = ()
excludes = ()
def read_excludes(fn):
excludes.extend(testlist.read_test_regexes(fn))
def read_includes(fn):
includes.extend(testlist.read_test_regexes(fn))
parser = optparse.OptionParser("TEST-REGEXES")
parser.add_option("--target", type="choice", choices=["samba", "samba3", "none"], default="samba", help="Samba version to target")
parser.add_option("--quick", help="run quick overall test", action="store_true", default=False)
parser.add_option("--list", help="list available tests", action="store_true", default=False)
parser.add_option("--socket-wrapper", help="enable socket wrapper", action="store_true", default=False)
parser.add_option("--socket-wrapper-pcap", help="save traffic to pcap directories", type="str")
parser.add_option("--socket-wrapper-keep-pcap", help="keep all pcap files, not just those for tests that failed", action="store_true", default=False)
parser.add_option("--one", help="abort when the first test fails", action="store_true", default=False)
parser.add_option("--exclude", action="callback", help="Add file to exclude files", callback=read_excludes)
parser.add_option("--include", action="callback", help="Add file to include files", callback=read_includes)
parser.add_option("--testenv", help="run a shell in the requested test environment", action="store_true", default=False)
parser.add_option("--resetup-environment", help="Re-setup environment", action="store_true", default=False)
parser.add_option("--binary-mapping", help="Map binaries to use", type=str)
parser.add_option("--load-list", help="Load list of tests to load from a file", type=str)
parser.add_option("--prefix", help="prefix to run tests in", type=str, default="./st")
parser.add_option("--srcdir", type=str, default=".", help="source directory")
parser.add_option("--bindir", type=str, default="./bin", help="binaries directory")
parser.add_option("--testlist", type=str, action="append", help="file to read available tests from")
parser.add_option("--ldap", help="back samba onto specified ldap server", choices=["openldap", "fedora-ds"], type="choice")
opts, args = parser.parse_args()
subunit_ops = subunithelper.SubunitOps(sys.stdout)
def handle_signal(sig, frame):
sys.stderr.write("Exiting early because of signal %s.\n" % sig)
sys.exit(1)
for sig in (signal.SIGINT, signal.SIGQUIT, signal.SIGTERm, signal.SIGPIPE):
signal.signal(sig, handle_signal)
def skip(name):
return testlist.find_in_list(excludes, name)
def setup_pcap(name):
if (not opts.socket_wrapper_pcap or
not os.environ.get("SOCKET_WRAPPER_PCAP_DIR")):
return
fname = "".join([x for x in name if x.isalnum() or x == '-'])
pcap_file = os.path.join(
os.environ["SOCKET_WRAPPER_PCAP_DIR"], "%s.pcap" % fname)
socket_wrapper.setup_pcap(pcap_file)
return pcap_file
def cleanup_pcap(pcap_file, exit_code):
if not opts.socket_wrapper_pcap:
return
if opts.socket_wrapper_keep_pcap:
return
if exitcode == 0:
return
if pcap_file is None:
return
os.unlink(pcap_file)
def run_testsuite(name, cmd, subunit_ops, env=None):
"""Run a single testsuite.
:param env: Environment to run in
:param name: Name of the testsuite
:param cmd: Name of the (fully expanded) command to run
:return: exitcode of the command
"""
pcap_file = setup_pcap(name)
exitcode = run_testsuite_command(name, cmd, subunit_ops, env)
if exitcode is None:
sys.exit(1)
cleanup_pcap(pcap_file, exitcode)
if not opts.socket_wrapper_keep_pcap and pcap_file is not None:
sys.stdout.write("PCAP FILE: %s\n" % pcap_file)
if exitcode != 0 and opts.one:
sys.exit(1)
return exitcode
if opts.list and opts.testenv:
sys.stderr.write("--list and --testenv are mutually exclusive\n")
sys.exit(1)
tests = args
# quick hack to disable rpc validation when using valgrind - it is way too slow
if not os.environ.get("VALGRIND"):
os.environ["VALIDATE"] = "validate"
os.environ["MALLOC_CHECK_"] = "2"
# make all our python scripts unbuffered
os.environ["PYTHONUNBUFFERED"] = "1"
bindir_abs = os.path.abspath(opts.bindir)
# Backwards compatibility:
if os.environ.get("TEST_LDAP") == "yes":
if os.environ.get("FEDORA_DS_ROOT"):
ldap = "fedora-ds"
else:
ldap = "openldap"
torture_maxtime = int(os.getenv("TORTURE_MAXTIME", "1200"))
if opts.ldap:
# LDAP is slow
torture_maxtime *= 2
prefix = os.path.normpath(opts.prefix)
# Ensure we have the test prefix around.
#
# We need restrictive permissions on this as some subdirectories in this tree
# will have wider permissions (ie 0777) and this would allow other users on the
# host to subvert the test process.
if not os.path.isdir(prefix):
os.mkdir(prefix, 0700)
else:
os.chmod(prefix, 0700)
prefix_abs = os.path.abspath(prefix)
tmpdir_abs = os.path.abspath(os.path.join(prefix_abs, "tmp"))
if not os.path.isdir(tmpdir_abs):
os.mkdir(tmpdir_abs, 0777)
srcdir_abs = os.path.abspath(opts.srcdir)
if prefix_abs == "/":
raise Exception("using '/' as absolute prefix is a bad idea")
os.environ["PREFIX"] = prefix
os.environ["KRB5CCNAME"] = os.path.join(prefix, "krb5ticket")
os.environ["PREFIX_ABS"] = prefix_abs
os.environ["SRCDIR"] = opts.srcdir
os.environ["SRCDIR_ABS"] = srcdir_abs
os.environ["BINDIR"] = bindir_abs
tls_enabled = not opts.quick
if tls_enabled:
os.environ["TLS_ENABLED"] = "yes"
else:
os.environ["TLS_ENABLED"] = "no"
def prefix_pathvar(name, newpath):
if name in os.environ:
os.environ[name] = "%s:%s" % (newpath, os.environ[name])
else:
os.environ[name] = newpath
prefix_pathvar("PKG_CONFIG_PATH", os.path.join(bindir_abs, "pkgconfig"))
prefix_pathvar("PYTHONPATH", os.path.join(bindir_abs, "python"))
if opts.socket_wrapper_keep_pcap:
# Socket wrapper keep pcap implies socket wrapper pcap
opts.socket_wrapper_pcap = True
if opts.socket_wrapper_pcap:
# Socket wrapper pcap implies socket wrapper
opts.socket_wrapper = True
if opts.socket_wrapper:
socket_wrapper_dir = socket_wrapper.setup_dir(os.path.join(prefix_abs, "w"), opts.socket_wrapper_pcap)
sys.stdout.write("SOCKET_WRAPPER_DIR=%s\n" % socket_wrapper_dir)
elif not opts.list:
if os.getuid() != 0:
warnings.warn("not using socket wrapper, but also not running as root. Will not be able to listen on proper ports")
testenv_default = "none"
if opts.binary_mapping:
binary_mapping = dict([l.split(":") for l in opts.binary_mapping.split(",")])
os.environ["BINARY_MAPPING"] = opts.binary_mapping
else:
binary_mapping = {}
os.environ["BINARY_MAPPING"] = ""
# After this many seconds, the server will self-terminate. All tests
# must terminate in this time, and testenv will only stay alive this
# long
if os.environ.get("SMBD_MAXTIME", ""):
server_maxtime = int(os.environ["SMBD_MAXTIME"])
else:
server_maxtime = 7500
def has_socket_wrapper(bindir):
"""Check if Samba has been built with socket wrapper support.
"""
f = StringIO()
subprocess.check_call([os.path.join(bindir, "smbd"), "-b"], stdout=f)
for l in f.readlines():
if "SOCKET_WRAPPER" in l:
return True
return False
if not opts.list:
if opts.target == "samba":
if opts.socket_wrapper and not has_socket_wrapper(opts.bindir):
sys.stderr.write("You must include --enable-socket-wrapper when compiling Samba in order to execute 'make test'. Exiting....\n")
sys.exit(1)
testenv_default = "dc"
from selftest.target.samba import Samba
target = Samba(opts.bindir, binary_mapping, ldap, opts.srcdir, server_maxtime)
elif opts.target == "samba3":
if opts.socket_wrapper and not has_socket_wrapper(opts.bindir):
sys.stderr.write("You must include --enable-socket-wrapper when compiling Samba in order to execute 'make test'. Exiting....\n")
sys.exit(1)
testenv_default = "member"
from selftest.target.samba3 import Samba3
target = Samba3(opts.bindir, binary_mapping, srcdir_abs, server_maxtime)
elif opts.target == "none":
testenv_default = "none"
target = NoneTarget()
env_manager = EnvironmentManager(target)
atexit.register(env_manager.teardown_all)
interfaces = ",".join([
"127.0.0.11/8",
"127.0.0.12/8",
"127.0.0.13/8",
"127.0.0.14/8",
"127.0.0.15/8",
"127.0.0.16/8"])
clientdir = os.path.join(prefix_abs, "client")
conffile = os.path.join(clientdir, "client.conf")
os.environ["SMB_CONF_PATH"] = conffile
todo = []
if not opts.testlist:
sys.stderr.write("No testlists specified\n")
sys.exit(1)
os.environ["SELFTEST_PREFIX"] = prefix_abs
os.environ["SELFTEST_TMPDIR"] = tmpdir_abs
os.environ["TEST_DATA_PREFIX"] = tmpdir_abs
if opts.socket_wrapper:
os.environ["SELFTEST_INTERFACES"] = interfaces
else:
os.environ["SELFTEST_INTERFACES"] = ""
if opts.quick:
os.environ["SELFTEST_QUICK"] = "1"
else:
os.environ["SELFTEST_QUICK"] = ""
os.environ["SELFTEST_MAXTIME"] = str(torture_maxtime)
available = []
for fn in opts.testlist:
for testsuite in testlist.read_testlist_file(fn):
if not testlist.should_run_test(tests, testsuite):
continue
name = testsuite[0]
if (includes is not None and
testlist.find_in_list(includes, name) is not None):
continue
available.append(testsuite)
if opts.load_list:
restricted_mgr = testlist.RestrictedTestManager.from_path(opts.load_list)
else:
restricted_mgr = None
for testsuite in available:
name = testsuite[0]
skipreason = skip(name)
if restricted_mgr is not None:
match = restricted_mgr.should_run_testsuite(name)
if match == []:
continue
else:
match = None
if skipreason is not None:
if not opts.list:
subunit_ops.skip_testsuite(name, skipreason)
else:
todo.append(testsuite + (match,))
if restricted_mgr is not None:
for name in restricted_mgr.iter_unused():
sys.stdout.write("No test or testsuite found matching %s\n" % name)
if todo == []:
sys.stderr.write("No tests to run\n")
sys.exit(1)
suitestotal = len(todo)
if not opts.list:
subunit_ops.progress(suitestotal, subunit.PROGRESS_SET)
subunit_ops.time(now())
exported_envvars = [
# domain stuff
"DOMAIN",
"REALM",
# domain controller stuff
"DC_SERVER",
"DC_SERVER_IP",
"DC_NETBIOSNAME",
"DC_NETBIOSALIAS",
# domain member
"MEMBER_SERVER",
"MEMBER_SERVER_IP",
"MEMBER_NETBIOSNAME",
"MEMBER_NETBIOSALIAS",
# rpc proxy controller stuff
"RPC_PROXY_SERVER",
"RPC_PROXY_SERVER_IP",
"RPC_PROXY_NETBIOSNAME",
"RPC_PROXY_NETBIOSALIAS",
# domain controller stuff for Vampired DC
"VAMPIRE_DC_SERVER",
"VAMPIRE_DC_SERVER_IP",
"VAMPIRE_DC_NETBIOSNAME",
"VAMPIRE_DC_NETBIOSALIAS",
# domain controller stuff for Vampired DC
"PROMOTED_DC_SERVER",
"PROMOTED_DC_SERVER_IP",
"PROMOTED_DC_NETBIOSNAME",
"PROMOTED_DC_NETBIOSALIAS",
# server stuff
"SERVER",
"SERVER_IP",
"NETBIOSNAME",
"NETBIOSALIAS",
# user stuff
"USERNAME",
"USERID",
"PASSWORD",
"DC_USERNAME",
"DC_PASSWORD",
# misc stuff
"KRB5_CONFIG",
"WINBINDD_SOCKET_DIR",
"WINBINDD_PRIV_PIPE_DIR",
"NMBD_SOCKET_DIR",
"LOCAL_PATH"
]
def switch_env(name, prefix):
if ":" in name:
(envname, option) = name.split(":", 1)
else:
envname = name
option = "client"
env = env_manager.setup_env(envname, prefix)
testenv_vars = env.get_vars()
if option == "local":
socket_wrapper.set_default_iface(testenv_vars["SOCKET_WRAPPER_DEFAULT_IFACE"])
os.environ["SMB_CONF_PATH"] = testenv_vars["SERVERCONFFILE"]
elif option == "client":
socket_wrapper.set_default_iface(11)
write_clientconf(conffile, clientdir, testenv_vars)
os.environ["SMB_CONF_PATH"] = conffile
else:
raise Exception("Unknown option[%s] for envname[%s]" % (option,
envname))
for name in exported_envvars:
if name in testenv_vars:
os.environ[name] = testenv_vars[name]
elif name in os.environ:
del os.environ[name]
return env
# This 'global' file needs to be empty when we start
dns_host_file_path = os.path.join(prefix_abs, "dns_host_file")
if os.path.exists(dns_host_file_path):
os.unlink(dns_host_file_path)
if opts.testenv:
testenv_name = os.environ.get("SELFTEST_TESTENV", testenv_default)
env = switch_env(testenv_name, prefix)
testenv_vars = env.get_vars()
os.environ["PIDDIR"] = testenv_vars["PIDDIR"]
os.environ["ENVNAME"] = testenv_name
envvarstr = exported_envvars_str(testenv_vars, exported_envvars)
term = os.environ.get("TERMINAL", "xterm -e")
cmd = """'echo -e "
Welcome to the Samba4 Test environment '%(testenv_name)'
This matches the client environment used in make test
server is pid `cat \$PIDDIR/samba.pid`
Some useful environment variables:
TORTURE_OPTIONS=\$TORTURE_OPTIONS
SMB_CONF_PATH=\$SMB_CONF_PATH
$envvarstr
\" && LD_LIBRARY_PATH=%(LD_LIBRARY_PATH)s $(SHELL)'""" % {
"testenv_name": testenv_name,
"LD_LIBRARY_PATH": os.environ["LD_LIBRARY_PATH"]}
subprocess.call(term + ' ' + cmd, shell=True)
env_manager.teardown_env(testenv_name)
elif opts.list:
for (name, envname, cmd, supports_loadfile, supports_idlist, subtests) in todo:
cmd = expand_command_list(cmd)
if cmd is None:
warnings.warn("Unable to list tests in %s" % name)
continue
exitcode = subprocess.call(cmd, shell=True)
if exitcode != 0:
sys.stderr.write("%s exited with exit code %s\n" % (cmd, exitcode))
sys.exit(1)
else:
for (name, envname, cmd, supports_loadfile, supports_idlist, subtests) in todo:
try:
env = switch_env(envname, prefix)
except UnsupportedEnvironment:
subunit_ops.start_testsuite(name)
subunit_ops.end_testsuite(name, "skip",
"environment %s is unknown in this test backend - skipping" % envname)
continue
except Exception, e:
subunit_ops.start_testsuite(name)
traceback.print_exc()
subunit_ops.end_testsuite(name, "error",
"unable to set up environment %s: %s" % (envname, e))
continue
cmd, tmpf = expand_command_run(cmd, supports_loadfile, supports_idlist,
subtests)
run_testsuite(name, cmd, subunit_ops, env=env)
if tmpf is not None:
os.remove(tmpf)
if opts.resetup_environment:
env_manager.teardown_env(envname)
env_manager.teardown_all()
sys.stdout.write("\n")
# if there were any valgrind failures, show them
for fn in os.listdir(prefix):
if fn.startswith("valgrind.log"):
sys.stdout.write("VALGRIND FAILURE\n")
f = open(os.path.join(prefix, fn), 'r')
try:
sys.stdout.write(f.read())
finally:
f.close()
sys.exit(0)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
446,
85,
199,
3,
27324,
7868,
428,
14310,
436,
1255,
282,
1329,
402,
2295,
6169,
652,
14,
199,
3,
1898,
334,
35,
9,
11811,
13,
7409,
1603,
352,
2626,
5444,
889,
79,
7879,
665,
74,
352,
2626,
32,
21693,
14,
1308,
30,
199,
3,
1898,
334,
35,
9,
10219,
13,
8664,
17854,
12269,
10072,
90,
391,
7641,
665,
10207,
806,
32,
21693,
14,
1308,
30,
199,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
19840,
199,
504,
15073,
492,
5228,
199,
646,
747,
199,
646,
984,
199,
646,
4673,
199,
646,
3873,
199,
646,
1007,
3248,
199,
646,
5190,
199,
646,
3598,
199,
199,
646,
8691,
199,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
3460,
493,
29658,
199,
199,
504,
291,
396,
492,
334,
272,
2838,
63,
5029,
12,
272,
1007,
324,
448,
2096,
12,
272,
511,
513,
12,
272,
776,
199,
504,
291,
396,
14,
1258,
492,
2218,
63,
1258,
2190,
199,
504,
291,
396,
14,
1065,
492,
334,
272,
6544,
63,
1531,
63,
513,
12,
272,
6544,
63,
1531,
63,
1065,
12,
272,
16629,
63,
1813,
2936,
63,
495,
12,
272,
3063,
12,
272,
1255,
63,
14239,
63,
1531,
12,
272,
776,
199,
504,
291,
396,
14,
1375,
492,
334,
272,
9711,
2988,
12,
272,
488,
4277,
12,
272,
19022,
8263,
12,
272,
776,
199,
199,
9441,
275,
6248,
199,
26984,
275,
6248,
199,
199,
318,
1586,
63,
26984,
8,
2324,
304,
272,
23388,
14,
2880,
8,
396,
513,
14,
739,
63,
396,
63,
29283,
8,
2324,
430,
199,
199,
318,
1586,
63,
9441,
8,
2324,
304,
272,
6952,
14,
2880,
8,
396,
513,
14,
739,
63,
396,
63,
29283,
8,
2324,
430,
199,
199,
2087,
275,
8691,
14,
14553,
480,
2864,
13,
10710,
654,
531,
199,
2087,
14,
525,
63,
1422,
6739,
1375,
401,
730,
628,
5095,
401,
3415,
6270,
21693,
401,
298,
21693,
19,
401,
298,
3592,
2255,
849,
628,
21693,
401,
1720,
628,
51,
14310,
1015,
370,
1347,
531,
199,
2087,
14,
525,
63,
1422,
6739,
13239,
401,
1720,
628,
1065,
12530,
20347,
511,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
199,
2087,
14,
525,
63,
1422,
6739,
513,
401,
1720,
628,
513,
2808,
2295,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
199,
2087,
14,
525,
63,
1422,
6739,
3450,
13,
5029,
401,
1720,
628,
4296,
2838,
4975,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
199,
2087,
14,
525,
63,
1422,
6739,
3450,
13,
5029,
13,
2352,
439,
401,
1720,
628,
2117,
15602,
370,
18606,
6602,
401,
730,
628,
495,
531,
199,
2087,
14,
525,
63,
1422,
6739,
3450,
13,
5029,
13,
3250,
13,
2352,
439,
401,
1720,
628,
3250,
1006,
18606,
1584,
12,
440,
2951,
5204,
367,
2295,
626,
3405,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
199,
2087,
14,
525,
63,
1422,
6739,
368,
401,
1720,
628,
13845,
1380,
314,
1642,
511,
6918,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
199,
2087,
14,
525,
63,
1422,
6739,
5473,
401,
1595,
628,
3058,
401,
1720,
628,
1123,
570,
370,
5760,
1584,
401,
3233,
29,
739,
63,
26984,
9,
199,
2087,
14,
525,
63,
1422,
6739,
2613,
401,
1595,
628,
3058,
401,
1720,
628,
1123,
570,
370,
2387,
1584,
401,
3233,
29,
739,
63,
9441,
9,
199,
2087,
14,
525,
63,
1422,
6739,
744,
9072,
401,
1720,
628,
1065,
282,
5218,
315,
314,
5839,
511,
3734,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
199,
2087,
14,
525,
63,
1422,
6739,
264,
2758,
13,
5418,
401,
1720,
628,
497,
13,
2758,
3734,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
199,
2087,
14,
525,
63,
1422,
6739,
3008,
13,
4745,
401,
1720,
628,
2956,
21984,
370,
675,
401,
730,
29,
495,
9,
199,
2087,
14,
525,
63,
1422,
6739,
912,
13,
513,
401,
1720,
628,
6200,
769,
402,
2295,
370,
2248,
687,
282,
570,
401,
730,
29,
495,
9,
199,
2087,
14,
525,
63,
1422,
6739,
1861,
401,
1720,
628,
1861,
370,
1255,
2295,
315,
401,
730,
29,
495,
12,
849,
628,
13186,
270,
531,
199,
2087,
14,
525,
63,
1422,
6739,
17878,
401,
730,
29,
495,
12,
849,
628,
4765,
1720,
628,
1365,
2082,
531,
199,
2087,
14,
525,
63,
1422,
6739,
1393,
694,
401,
730,
29,
495,
12,
849,
628,
13186,
1393,
401,
1720,
628,
27542,
2082,
531,
199,
2087,
14,
525,
63,
1422,
6739,
396,
513,
401,
730,
29,
495,
12,
1595,
628,
740,
401,
1720,
628,
493,
370,
1586,
2808,
2295,
687,
531,
199,
2087,
14,
525,
63,
1422,
6739,
9642,
401,
1720,
628,
894,
31710,
14602,
2013,
13727,
1654,
401,
3415,
6270,
1490,
9642,
401,
298,
28803,
13,
795,
2255,
730,
628,
5095,
531,
199,
199,
3291,
12,
1249,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
954,
3248,
63,
1483,
275,
1007,
324,
448,
2096,
14,
2610,
3248,
16452,
8,
1274,
14,
2703,
9,
199,
199,
318,
2429,
63,
4653,
8,
4093,
12,
2787,
304,
272,
984,
14,
3083,
14,
952,
480,
6699,
316,
14670,
2952,
402,
4673,
450,
83,
3134,
78,
2,
450,
5259,
9,
272,
984,
14,
2224,
8,
17,
9,
199,
199
] |
[
2647,
15,
1393,
15,
1548,
446,
85,
199,
3,
27324,
7868,
428,
14310,
436,
1255,
282,
1329,
402,
2295,
6169,
652,
14,
199,
3,
1898,
334,
35,
9,
11811,
13,
7409,
1603,
352,
2626,
5444,
889,
79,
7879,
665,
74,
352,
2626,
32,
21693,
14,
1308,
30,
199,
3,
1898,
334,
35,
9,
10219,
13,
8664,
17854,
12269,
10072,
90,
391,
7641,
665,
10207,
806,
32,
21693,
14,
1308,
30,
199,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
19840,
199,
504,
15073,
492,
5228,
199,
646,
747,
199,
646,
984,
199,
646,
4673,
199,
646,
3873,
199,
646,
1007,
3248,
199,
646,
5190,
199,
646,
3598,
199,
199,
646,
8691,
199,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
3460,
493,
29658,
199,
199,
504,
291,
396,
492,
334,
272,
2838,
63,
5029,
12,
272,
1007,
324,
448,
2096,
12,
272,
511,
513,
12,
272,
776,
199,
504,
291,
396,
14,
1258,
492,
2218,
63,
1258,
2190,
199,
504,
291,
396,
14,
1065,
492,
334,
272,
6544,
63,
1531,
63,
513,
12,
272,
6544,
63,
1531,
63,
1065,
12,
272,
16629,
63,
1813,
2936,
63,
495,
12,
272,
3063,
12,
272,
1255,
63,
14239,
63,
1531,
12,
272,
776,
199,
504,
291,
396,
14,
1375,
492,
334,
272,
9711,
2988,
12,
272,
488,
4277,
12,
272,
19022,
8263,
12,
272,
776,
199,
199,
9441,
275,
6248,
199,
26984,
275,
6248,
199,
199,
318,
1586,
63,
26984,
8,
2324,
304,
272,
23388,
14,
2880,
8,
396,
513,
14,
739,
63,
396,
63,
29283,
8,
2324,
430,
199,
199,
318,
1586,
63,
9441,
8,
2324,
304,
272,
6952,
14,
2880,
8,
396,
513,
14,
739,
63,
396,
63,
29283,
8,
2324,
430,
199,
199,
2087,
275,
8691,
14,
14553,
480,
2864,
13,
10710,
654,
531,
199,
2087,
14,
525,
63,
1422,
6739,
1375,
401,
730,
628,
5095,
401,
3415,
6270,
21693,
401,
298,
21693,
19,
401,
298,
3592,
2255,
849,
628,
21693,
401,
1720,
628,
51,
14310,
1015,
370,
1347,
531,
199,
2087,
14,
525,
63,
1422,
6739,
13239,
401,
1720,
628,
1065,
12530,
20347,
511,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
199,
2087,
14,
525,
63,
1422,
6739,
513,
401,
1720,
628,
513,
2808,
2295,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
199,
2087,
14,
525,
63,
1422,
6739,
3450,
13,
5029,
401,
1720,
628,
4296,
2838,
4975,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
199,
2087,
14,
525,
63,
1422,
6739,
3450,
13,
5029,
13,
2352,
439,
401,
1720,
628,
2117,
15602,
370,
18606,
6602,
401,
730,
628,
495,
531,
199,
2087,
14,
525,
63,
1422,
6739,
3450,
13,
5029,
13,
3250,
13,
2352,
439,
401,
1720,
628,
3250,
1006,
18606,
1584,
12,
440,
2951,
5204,
367,
2295,
626,
3405,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
199,
2087,
14,
525,
63,
1422,
6739,
368,
401,
1720,
628,
13845,
1380,
314,
1642,
511,
6918,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
199,
2087,
14,
525,
63,
1422,
6739,
5473,
401,
1595,
628,
3058,
401,
1720,
628,
1123,
570,
370,
5760,
1584,
401,
3233,
29,
739,
63,
26984,
9,
199,
2087,
14,
525,
63,
1422,
6739,
2613,
401,
1595,
628,
3058,
401,
1720,
628,
1123,
570,
370,
2387,
1584,
401,
3233,
29,
739,
63,
9441,
9,
199,
2087,
14,
525,
63,
1422,
6739,
744,
9072,
401,
1720,
628,
1065,
282,
5218,
315,
314,
5839,
511,
3734,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
199,
2087,
14,
525,
63,
1422,
6739,
264,
2758,
13,
5418,
401,
1720,
628,
497,
13,
2758,
3734,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
199,
2087,
14,
525,
63,
1422,
6739,
3008,
13,
4745,
401,
1720,
628,
2956,
21984,
370,
675,
401,
730,
29,
495,
9,
199,
2087,
14,
525,
63,
1422,
6739,
912,
13,
513,
401,
1720,
628,
6200,
769,
402,
2295,
370,
2248,
687,
282,
570,
401,
730,
29,
495,
9,
199,
2087,
14,
525,
63,
1422,
6739,
1861,
401,
1720,
628,
1861,
370,
1255,
2295,
315,
401,
730,
29,
495,
12,
849,
628,
13186,
270,
531,
199,
2087,
14,
525,
63,
1422,
6739,
17878,
401,
730,
29,
495,
12,
849,
628,
4765,
1720,
628,
1365,
2082,
531,
199,
2087,
14,
525,
63,
1422,
6739,
1393,
694,
401,
730,
29,
495,
12,
849,
628,
13186,
1393,
401,
1720,
628,
27542,
2082,
531,
199,
2087,
14,
525,
63,
1422,
6739,
396,
513,
401,
730,
29,
495,
12,
1595,
628,
740,
401,
1720,
628,
493,
370,
1586,
2808,
2295,
687,
531,
199,
2087,
14,
525,
63,
1422,
6739,
9642,
401,
1720,
628,
894,
31710,
14602,
2013,
13727,
1654,
401,
3415,
6270,
1490,
9642,
401,
298,
28803,
13,
795,
2255,
730,
628,
5095,
531,
199,
199,
3291,
12,
1249,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
954,
3248,
63,
1483,
275,
1007,
324,
448,
2096,
14,
2610,
3248,
16452,
8,
1274,
14,
2703,
9,
199,
199,
318,
2429,
63,
4653,
8,
4093,
12,
2787,
304,
272,
984,
14,
3083,
14,
952,
480,
6699,
316,
14670,
2952,
402,
4673,
450,
83,
3134,
78,
2,
450,
5259,
9,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
bacontext/mopidy
|
tests/test_httpclient.py
|
13
|
1421
|
from __future__ import unicode_literals
import re
import pytest
from mopidy import httpclient
@pytest.mark.parametrize("config,expected", [
({}, None),
({'hostname': 'proxy.lan'}, 'http://proxy.lan:80'),
({'scheme': None, 'hostname': 'proxy.lan'}, 'http://proxy.lan:80'),
({'scheme': 'https', 'hostname': 'proxy.lan'}, 'https://proxy.lan:80'),
({'username': 'user', 'hostname': 'proxy.lan'}, 'http://proxy.lan:80'),
({'password': 'pass', 'hostname': 'proxy.lan'}, 'http://proxy.lan:80'),
({'hostname': 'proxy.lan', 'port': 8080}, 'http://proxy.lan:8080'),
({'hostname': 'proxy.lan', 'port': -1}, 'http://proxy.lan:80'),
({'username': 'user', 'password': 'pass', 'hostname': 'proxy.lan'},
'http://user:pass@proxy.lan:80'),
])
def test_format_proxy(config, expected):
assert httpclient.format_proxy(config) == expected
def test_format_proxy_without_auth():
config = {'username': 'user', 'password': 'pass', 'hostname': 'proxy.lan'}
formated_proxy = httpclient.format_proxy(config, auth=False)
assert formated_proxy == 'http://proxy.lan:80'
@pytest.mark.parametrize("name,expected", [
(None, r'^Mopidy/[^ ]+ CPython|/[^ ]+$'),
('Foo', r'^Foo Mopidy/[^ ]+ CPython|/[^ ]+$'),
('Foo/1.2.3', r'^Foo/1.2.3 Mopidy/[^ ]+ CPython|/[^ ]+$'),
])
def test_format_user_agent(name, expected):
assert re.match(expected, httpclient.format_user_agent(name))
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
646,
4613,
199,
199,
504,
333,
411,
344,
89,
492,
1455,
1258,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
888,
12,
2062,
401,
359,
272,
11459,
1386,
488,
395,
272,
26227,
4269,
356,
283,
3280,
14,
1502,
2267,
283,
1014,
921,
3280,
14,
1502,
26,
1257,
659,
272,
26227,
5512,
356,
488,
12,
283,
4269,
356,
283,
3280,
14,
1502,
2267,
283,
1014,
921,
3280,
14,
1502,
26,
1257,
659,
272,
26227,
5512,
356,
283,
2859,
297,
283,
4269,
356,
283,
3280,
14,
1502,
2267,
283,
2859,
921,
3280,
14,
1502,
26,
1257,
659,
272,
26227,
2473,
356,
283,
751,
297,
283,
4269,
356,
283,
3280,
14,
1502,
2267,
283,
1014,
921,
3280,
14,
1502,
26,
1257,
659,
272,
26227,
2060,
356,
283,
1529,
297,
283,
4269,
356,
283,
3280,
14,
1502,
2267,
283,
1014,
921,
3280,
14,
1502,
26,
1257,
659,
272,
26227,
4269,
356,
283,
3280,
14,
1502,
297,
283,
719,
356,
30220,
1386,
283,
1014,
921,
3280,
14,
1502,
26,
15844,
659,
272,
26227,
4269,
356,
283,
3280,
14,
1502,
297,
283,
719,
356,
446,
17,
1386,
283,
1014,
921,
3280,
14,
1502,
26,
1257,
659,
272,
26227,
2473,
356,
283,
751,
297,
283,
2060,
356,
283,
1529,
297,
283,
4269,
356,
283,
3280,
14,
1502,
2267,
1362,
283,
1014,
921,
751,
26,
1529,
32,
3280,
14,
1502,
26,
1257,
659,
199,
566,
199,
318,
511,
63,
908,
63,
3280,
8,
888,
12,
1420,
304,
272,
702,
1455,
1258,
14,
908,
63,
3280,
8,
888,
9,
508,
1420,
421,
199,
318,
511,
63,
908,
63,
3280,
63,
7395,
63,
1178,
837,
272,
1101,
275,
791,
2473,
356,
283,
751,
297,
283,
2060,
356,
283,
1529,
297,
283,
4269,
356,
283,
3280,
14,
1502,
936,
272,
1824,
972,
63,
3280,
275,
1455,
1258,
14,
908,
63,
3280,
8,
888,
12,
1790,
29,
797,
9,
272,
702,
1824,
972,
63,
3280,
508,
283,
1014,
921,
3280,
14,
1502,
26,
1257,
7,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
354,
12,
2062,
401,
359,
272,
334,
403,
12,
519,
4289,
45,
411,
344,
89,
15,
4735,
1622,
11,
25654,
92,
15,
4735,
1622,
11,
26712,
272,
661,
5686,
297,
519,
4289,
5686,
603,
411,
344,
89,
15,
4735,
1622,
11,
25654,
92,
15,
4735,
1622,
11,
26712,
272,
661,
5686,
15,
17,
14,
18,
14,
19,
297,
519,
4289,
5686,
15,
17,
14,
18,
14,
19,
603,
411,
344,
89,
15,
4735,
1622,
11,
25654,
92,
15,
4735,
1622,
11,
26712,
199,
566,
199,
318,
511,
63,
908,
63,
751,
63,
4054,
8,
354,
12,
1420,
304,
272,
702,
295,
14,
1431,
8,
2062,
12,
1455,
1258,
14,
908,
63,
751,
63,
4054,
8,
354,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
646,
4613,
199,
199,
504,
333,
411,
344,
89,
492,
1455,
1258,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
888,
12,
2062,
401,
359,
272,
11459,
1386,
488,
395,
272,
26227,
4269,
356,
283,
3280,
14,
1502,
2267,
283,
1014,
921,
3280,
14,
1502,
26,
1257,
659,
272,
26227,
5512,
356,
488,
12,
283,
4269,
356,
283,
3280,
14,
1502,
2267,
283,
1014,
921,
3280,
14,
1502,
26,
1257,
659,
272,
26227,
5512,
356,
283,
2859,
297,
283,
4269,
356,
283,
3280,
14,
1502,
2267,
283,
2859,
921,
3280,
14,
1502,
26,
1257,
659,
272,
26227,
2473,
356,
283,
751,
297,
283,
4269,
356,
283,
3280,
14,
1502,
2267,
283,
1014,
921,
3280,
14,
1502,
26,
1257,
659,
272,
26227,
2060,
356,
283,
1529,
297,
283,
4269,
356,
283,
3280,
14,
1502,
2267,
283,
1014,
921,
3280,
14,
1502,
26,
1257,
659,
272,
26227,
4269,
356,
283,
3280,
14,
1502,
297,
283,
719,
356,
30220,
1386,
283,
1014,
921,
3280,
14,
1502,
26,
15844,
659,
272,
26227,
4269,
356,
283,
3280,
14,
1502,
297,
283,
719,
356,
446,
17,
1386,
283,
1014,
921,
3280,
14,
1502,
26,
1257,
659,
272,
26227,
2473,
356,
283,
751,
297,
283,
2060,
356,
283,
1529,
297,
283,
4269,
356,
283,
3280,
14,
1502,
2267,
1362,
283,
1014,
921,
751,
26,
1529,
32,
3280,
14,
1502,
26,
1257,
659,
199,
566,
199,
318,
511,
63,
908,
63,
3280,
8,
888,
12,
1420,
304,
272,
702,
1455,
1258,
14,
908,
63,
3280,
8,
888,
9,
508,
1420,
421,
199,
318,
511,
63,
908,
63,
3280,
63,
7395,
63,
1178,
837,
272,
1101,
275,
791,
2473,
356,
283,
751,
297,
283,
2060,
356,
283,
1529,
297,
283,
4269,
356,
283,
3280,
14,
1502,
936,
272,
1824,
972,
63,
3280,
275,
1455,
1258,
14,
908,
63,
3280,
8,
888,
12,
1790,
29,
797,
9,
272,
702,
1824,
972,
63,
3280,
508,
283,
1014,
921,
3280,
14,
1502,
26,
1257,
7,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
354,
12,
2062,
401,
359,
272,
334,
403,
12,
519,
4289,
45,
411,
344,
89,
15,
4735,
1622,
11,
25654,
92,
15,
4735,
1622,
11,
26712,
272,
661,
5686,
297,
519,
4289,
5686,
603,
411,
344,
89,
15,
4735,
1622,
11,
25654,
92,
15,
4735,
1622,
11,
26712,
272,
661,
5686,
15,
17,
14,
18,
14,
19,
297,
519,
4289,
5686,
15,
17,
14,
18,
14,
19,
603,
411,
344,
89,
15,
4735,
1622,
11,
25654,
92,
15,
4735,
1622,
11,
26712,
199,
566,
199,
318,
511,
63,
908,
63,
751,
63,
4054,
8,
354,
12,
1420,
304,
272,
702,
295,
14,
1431,
8,
2062,
12,
1455,
1258,
14,
908,
63,
751,
63,
4054,
8,
354,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
maciekcc/tensorflow
|
tensorflow/python/debug/cli/curses_ui_test.py
|
57
|
59063
|
# 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 of the curses-based CLI."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import curses
import tempfile
import threading
import numpy as np
from six.moves import queue
from tensorflow.python.debug.cli import curses_ui
from tensorflow.python.debug.cli import debugger_cli_common
from tensorflow.python.debug.cli import tensor_format
from tensorflow.python.framework import test_util
from tensorflow.python.platform import gfile
from tensorflow.python.platform import googletest
def string_to_codes(cmd):
return [ord(c) for c in cmd]
def codes_to_string(cmd_code):
# Omit non-ASCII key codes.
return "".join([chr(code) for code in cmd_code if code < 256])
class MockCursesUI(curses_ui.CursesUI):
"""Mock subclass of CursesUI that bypasses actual terminal manipulations."""
def __init__(self,
height,
width,
command_sequence=None):
self._height = height
self._width = width
self._command_sequence = command_sequence
self._command_counter = 0
# The mock class has no actual textbox. So use this variable to keep
# track of what's entered in the textbox on creation.
self._curr_existing_command = ""
# Observers for test.
# Observers of screen output.
self.unwrapped_outputs = []
self.wrapped_outputs = []
self.scroll_messages = []
self.output_array_pointer_indices = []
self.output_pad_rows = []
# Observers of command textbox.
self.existing_commands = []
# Observer for tab-completion candidates.
self.candidates_lists = []
# Observer for the main menu.
self.main_menu_list = []
# Observer for toast messages.
self.toasts = []
curses_ui.CursesUI.__init__(self)
# Override the default path to the command history file to avoid test
# concurrency issues.
self._command_history_store = debugger_cli_common.CommandHistory(
history_file_path=tempfile.mktemp())
# Below, override the _screen_ prefixed member methods that interact with the
# actual terminal, so that the mock can run in a terminal-less environment.
# TODO(cais): Search for a way to have a mock terminal object that behaves
# like the actual terminal, so that we can test the terminal interaction
# parts of the CursesUI class.
def _screen_init(self):
pass
def _screen_refresh_size(self):
self._max_y = self._height
self._max_x = self._width
def _screen_launch(self, enable_mouse_on_start):
self._mouse_enabled = enable_mouse_on_start
def _screen_terminate(self):
pass
def _screen_refresh(self):
pass
def _screen_create_command_window(self):
pass
def _screen_create_command_textbox(self, existing_command=None):
"""Override to insert observer of existing commands.
Used in testing of history navigation and tab completion.
Args:
existing_command: Command string entered to the textbox at textbox
creation time. Note that the textbox does not actually exist in this
mock subclass. This method only keeps track of and records the state.
"""
self.existing_commands.append(existing_command)
self._curr_existing_command = existing_command
def _screen_new_output_pad(self, rows, cols):
return "mock_pad"
def _screen_add_line_to_output_pad(self, pad, row, txt, color_segments=None):
pass
def _screen_draw_text_line(self, row, line, attr=curses.A_NORMAL, color=None):
pass
def _screen_scroll_output_pad(self, pad, viewport_top, viewport_left,
screen_location_top, screen_location_left,
screen_location_bottom, screen_location_right):
pass
def _screen_get_user_command(self):
command = self._command_sequence[self._command_counter]
self._command_key_counter = 0
for c in command:
if c == curses.KEY_RESIZE:
# Special case for simulating a terminal resize event in curses.
self._height = command[1]
self._width = command[2]
self._on_textbox_keypress(c)
self._command_counter += 1
return ""
elif c == curses.KEY_MOUSE:
mouse_x = command[1]
mouse_y = command[2]
self._command_counter += 1
self._textbox_curr_terminator = c
return self._fetch_hyperlink_command(mouse_x, mouse_y)
else:
y = self._on_textbox_keypress(c)
self._command_key_counter += 1
if y == curses_ui.CursesUI.CLI_TERMINATOR_KEY:
break
self._command_counter += 1
# Take into account pre-existing string automatically entered on textbox
# creation.
return self._curr_existing_command + codes_to_string(command)
def _screen_getmouse(self):
output = (0, self._mouse_xy_sequence[self._mouse_counter][0],
self._mouse_xy_sequence[self._mouse_counter][1], 0,
curses.BUTTON1_CLICKED)
self._mouse_counter += 1
return output
def _screen_gather_textbox_str(self):
return codes_to_string(self._command_sequence[self._command_counter]
[:self._command_key_counter])
def _scroll_output(self, direction, line_index=None):
"""Override to observe screen output.
This method is invoked after every command that generates a new screen
output and after every keyboard triggered screen scrolling. Therefore
it is a good place to insert the observer.
Args:
direction: which direction to scroll.
line_index: (int or None) Optional line index to scroll to. See doc string
of the overridden method for more information.
"""
curses_ui.CursesUI._scroll_output(self, direction, line_index=line_index)
self.unwrapped_outputs.append(self._curr_unwrapped_output)
self.wrapped_outputs.append(self._curr_wrapped_output)
self.scroll_messages.append(self._scroll_info)
self.output_array_pointer_indices.append(self._output_array_pointer_indices)
self.output_pad_rows.append(self._output_pad_row)
def _display_main_menu(self, output):
curses_ui.CursesUI._display_main_menu(self, output)
self.main_menu_list.append(self._main_menu)
def _screen_render_nav_bar(self):
pass
def _screen_render_menu_pad(self):
pass
def _display_candidates(self, candidates):
curses_ui.CursesUI._display_candidates(self, candidates)
self.candidates_lists.append(candidates)
def _toast(self, message, color=None, line_index=None):
curses_ui.CursesUI._toast(self, message, color=color, line_index=line_index)
self.toasts.append(message)
class CursesTest(test_util.TensorFlowTestCase):
_EXIT = string_to_codes("exit\n")
def _babble(self, args, screen_info=None):
ap = argparse.ArgumentParser(
description="Do babble.", usage=argparse.SUPPRESS)
ap.add_argument(
"-n",
"--num_times",
dest="num_times",
type=int,
default=60,
help="How many times to babble")
ap.add_argument(
"-l",
"--line",
dest="line",
type=str,
default="bar",
help="The content of each line")
ap.add_argument(
"-k",
"--link",
dest="link",
action="store_true",
help="Create a command link on each line")
ap.add_argument(
"-m",
"--menu",
dest="menu",
action="store_true",
help="Create a menu for testing")
parsed = ap.parse_args(args)
lines = [parsed.line] * parsed.num_times
font_attr_segs = {}
if parsed.link:
for i in range(len(lines)):
font_attr_segs[i] = [(
0,
len(lines[i]),
debugger_cli_common.MenuItem("", "babble"),)]
annotations = {}
if parsed.menu:
menu = debugger_cli_common.Menu()
menu.append(
debugger_cli_common.MenuItem("babble again", "babble"))
menu.append(
debugger_cli_common.MenuItem("ahoy", "ahoy", enabled=False))
annotations[debugger_cli_common.MAIN_MENU_KEY] = menu
output = debugger_cli_common.RichTextLines(
lines, font_attr_segs=font_attr_segs, annotations=annotations)
return output
def _print_ones(self, args, screen_info=None):
ap = argparse.ArgumentParser(
description="Print all-one matrix.", usage=argparse.SUPPRESS)
ap.add_argument(
"-s",
"--size",
dest="size",
type=int,
default=3,
help="Size of the matrix. For example, of the value is 3, "
"the matrix will have shape (3, 3)")
parsed = ap.parse_args(args)
m = np.ones([parsed.size, parsed.size])
return tensor_format.format_tensor(m, "m")
def testInitialization(self):
ui = MockCursesUI(40, 80)
self.assertEqual(0, ui._command_pointer)
self.assertEqual([], ui._active_command_history)
self.assertEqual("", ui._pending_command)
def testCursesUiInChildThreadStartsWithoutException(self):
result = queue.Queue()
def child_thread():
try:
MockCursesUI(40, 80)
except ValueError as e:
result.put(e)
t = threading.Thread(target=child_thread)
t.start()
t.join()
self.assertTrue(result.empty())
def testRunUIExitImmediately(self):
"""Make sure that the UI can exit properly after launch."""
ui = MockCursesUI(40, 80, command_sequence=[self._EXIT])
ui.run_ui()
# No screen output should have happened.
self.assertEqual(0, len(ui.unwrapped_outputs))
def testRunUIEmptyCommand(self):
"""Issue an empty command then exit."""
ui = MockCursesUI(40, 80, command_sequence=[[], self._EXIT])
ui.run_ui()
# Empty command should not lead to any screen output.
self.assertEqual(0, len(ui.unwrapped_outputs))
def testRunUIInvalidCommandPrefix(self):
"""Handle an unregistered command prefix."""
ui = MockCursesUI(
40,
80,
command_sequence=[string_to_codes("foo\n"), self._EXIT])
ui.run_ui()
# Screen output/scrolling should have happened exactly once.
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual(1, len(ui.wrapped_outputs))
self.assertEqual(1, len(ui.scroll_messages))
self.assertEqual(["ERROR: Invalid command prefix \"foo\""],
ui.unwrapped_outputs[0].lines)
# TODO(cais): Add explanation for the 35 extra lines.
self.assertEqual(["ERROR: Invalid command prefix \"foo\""],
ui.wrapped_outputs[0].lines[:1])
# A single line of output should not have caused scrolling.
self.assertNotIn("Scroll", ui.scroll_messages[0])
self.assertIn("Mouse:", ui.scroll_messages[0])
def testRunUIInvalidCommandSyntax(self):
"""Handle a command with invalid syntax."""
ui = MockCursesUI(
40,
80,
command_sequence=[string_to_codes("babble -z\n"), self._EXIT])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
# Screen output/scrolling should have happened exactly once.
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual(1, len(ui.wrapped_outputs))
self.assertEqual(1, len(ui.scroll_messages))
self.assertIn("Mouse:", ui.scroll_messages[0])
self.assertEqual(
["Syntax error for command: babble", "For help, do \"help babble\""],
ui.unwrapped_outputs[0].lines)
def testRunUIScrollTallOutputPageDownUp(self):
"""Scroll tall output with PageDown and PageUp."""
# Use PageDown and PageUp to scroll back and forth a little before exiting.
ui = MockCursesUI(
40,
80,
command_sequence=[string_to_codes("babble\n"), [curses.KEY_NPAGE] * 2 +
[curses.KEY_PPAGE] + self._EXIT])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
# Screen output/scrolling should have happened exactly once.
self.assertEqual(4, len(ui.unwrapped_outputs))
self.assertEqual(4, len(ui.wrapped_outputs))
self.assertEqual(4, len(ui.scroll_messages))
# Before scrolling.
self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[0].lines)
self.assertEqual(["bar"] * 60, ui.wrapped_outputs[0].lines[:60])
# Initial scroll: At the top.
self.assertIn("Scroll (PgDn): 0.00%", ui.scroll_messages[0])
self.assertIn("Mouse:", ui.scroll_messages[0])
# After 1st scrolling (PageDown).
# The screen output shouldn't have changed. Only the viewport should.
self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[0].lines)
self.assertEqual(["bar"] * 60, ui.wrapped_outputs[0].lines[:60])
self.assertIn("Scroll (PgDn/PgUp): 1.69%", ui.scroll_messages[1])
self.assertIn("Mouse:", ui.scroll_messages[1])
# After 2nd scrolling (PageDown).
self.assertIn("Scroll (PgDn/PgUp): 3.39%", ui.scroll_messages[2])
self.assertIn("Mouse:", ui.scroll_messages[2])
# After 3rd scrolling (PageUp).
self.assertIn("Scroll (PgDn/PgUp): 1.69%", ui.scroll_messages[3])
self.assertIn("Mouse:", ui.scroll_messages[3])
def testCutOffTooManyOutputLines(self):
ui = MockCursesUI(
40,
80,
command_sequence=[string_to_codes("babble -n 20\n"), self._EXIT])
# Modify max_output_lines so that this test doesn't use too much time or
# memory.
ui.max_output_lines = 10
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertEqual(["bar"] * 10 + ["Output cut off at 10 lines!"],
ui.wrapped_outputs[0].lines[:11])
def testRunUIScrollTallOutputEndHome(self):
"""Scroll tall output with PageDown and PageUp."""
# Use End and Home to scroll a little before exiting to test scrolling.
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble\n"),
[curses.KEY_END] * 2 + [curses.KEY_HOME] + self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
# Screen output/scrolling should have happened exactly once.
self.assertEqual(4, len(ui.unwrapped_outputs))
self.assertEqual(4, len(ui.wrapped_outputs))
self.assertEqual(4, len(ui.scroll_messages))
# Before scrolling.
self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[0].lines)
self.assertEqual(["bar"] * 60, ui.wrapped_outputs[0].lines[:60])
# Initial scroll: At the top.
self.assertIn("Scroll (PgDn): 0.00%", ui.scroll_messages[0])
# After 1st scrolling (End).
self.assertIn("Scroll (PgUp): 100.00%", ui.scroll_messages[1])
# After 2nd scrolling (End).
self.assertIn("Scroll (PgUp): 100.00%", ui.scroll_messages[2])
# After 3rd scrolling (Hhome).
self.assertIn("Scroll (PgDn): 0.00%", ui.scroll_messages[3])
def testRunUIWithInitCmd(self):
"""Run UI with an initial command specified."""
ui = MockCursesUI(40, 80, command_sequence=[self._EXIT])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui(init_command="babble")
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[0].lines)
self.assertEqual(["bar"] * 60, ui.wrapped_outputs[0].lines[:60])
self.assertIn("Scroll (PgDn): 0.00%", ui.scroll_messages[0])
def testCompileHelpWithoutHelpIntro(self):
ui = MockCursesUI(
40,
80,
command_sequence=[string_to_codes("help\n"), self._EXIT])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["b"])
ui.run_ui()
self.assertEqual(["babble", " Aliases: b", "", " babble some"],
ui.unwrapped_outputs[0].lines[:4])
def testCompileHelpWithHelpIntro(self):
ui = MockCursesUI(
40,
80,
command_sequence=[string_to_codes("help\n"), self._EXIT])
help_intro = debugger_cli_common.RichTextLines(
["This is a curses UI.", "All it can do is 'babble'.", ""])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["b"])
ui.set_help_intro(help_intro)
ui.run_ui()
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual(
help_intro.lines + ["babble", " Aliases: b", "", " babble some"],
ui.unwrapped_outputs[0].lines[:7])
def testCommandHistoryNavBackwardOnce(self):
ui = MockCursesUI(
40,
80,
command_sequence=[string_to_codes("help\n"),
[curses.KEY_UP], # Hit Up and Enter.
string_to_codes("\n"),
self._EXIT])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["b"])
ui.run_ui()
self.assertEqual(2, len(ui.unwrapped_outputs))
for i in [0, 1]:
self.assertEqual(["babble", " Aliases: b", "", " babble some"],
ui.unwrapped_outputs[i].lines[:4])
def testCommandHistoryNavBackwardTwice(self):
ui = MockCursesUI(
40,
80,
command_sequence=[string_to_codes("help\n"),
string_to_codes("babble\n"),
[curses.KEY_UP],
[curses.KEY_UP], # Hit Up twice and Enter.
string_to_codes("\n"),
self._EXIT])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["b"])
ui.run_ui()
self.assertEqual(3, len(ui.unwrapped_outputs))
# The 1st and 3rd outputs are for command "help".
for i in [0, 2]:
self.assertEqual(["babble", " Aliases: b", "", " babble some"],
ui.unwrapped_outputs[i].lines[:4])
# The 2nd output is for command "babble".
self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[1].lines)
def testCommandHistoryNavBackwardOverLimit(self):
ui = MockCursesUI(
40,
80,
command_sequence=[string_to_codes("help\n"),
string_to_codes("babble\n"),
[curses.KEY_UP],
[curses.KEY_UP],
[curses.KEY_UP], # Hit Up three times and Enter.
string_to_codes("\n"),
self._EXIT])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["b"])
ui.run_ui()
self.assertEqual(3, len(ui.unwrapped_outputs))
# The 1st and 3rd outputs are for command "help".
for i in [0, 2]:
self.assertEqual(["babble", " Aliases: b", "", " babble some"],
ui.unwrapped_outputs[i].lines[:4])
# The 2nd output is for command "babble".
self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[1].lines)
def testCommandHistoryNavBackwardThenForward(self):
ui = MockCursesUI(
40,
80,
command_sequence=[string_to_codes("help\n"),
string_to_codes("babble\n"),
[curses.KEY_UP],
[curses.KEY_UP],
[curses.KEY_DOWN], # Hit Up twice and Down once.
string_to_codes("\n"),
self._EXIT])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["b"])
ui.run_ui()
self.assertEqual(3, len(ui.unwrapped_outputs))
# The 1st output is for command "help".
self.assertEqual(["babble", " Aliases: b", "", " babble some"],
ui.unwrapped_outputs[0].lines[:4])
# The 2nd and 3rd outputs are for command "babble".
for i in [1, 2]:
self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[i].lines)
def testCommandHistoryPrefixNavBackwardOnce(self):
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 1\n"),
string_to_codes("babble -n 10\n"),
string_to_codes("help\n"),
string_to_codes("b") + [curses.KEY_UP], # Navigate with prefix.
string_to_codes("\n"),
self._EXIT
])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["b"])
ui.run_ui()
self.assertEqual(["bar"], ui.unwrapped_outputs[0].lines)
self.assertEqual(["bar"] * 10, ui.unwrapped_outputs[1].lines)
self.assertEqual(["babble", " Aliases: b", "", " babble some"],
ui.unwrapped_outputs[2].lines[:4])
self.assertEqual(["bar"] * 10, ui.unwrapped_outputs[3].lines)
def testTerminalResize(self):
ui = MockCursesUI(
40,
80,
command_sequence=[string_to_codes("babble\n"),
[curses.KEY_RESIZE, 100, 85], # Resize to [100, 85]
self._EXIT])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["b"])
ui.run_ui()
# The resize event should have caused a second screen output event.
self.assertEqual(2, len(ui.unwrapped_outputs))
self.assertEqual(2, len(ui.wrapped_outputs))
self.assertEqual(2, len(ui.scroll_messages))
# The 1st and 2nd screen outputs should be identical (unwrapped).
self.assertEqual(ui.unwrapped_outputs[0], ui.unwrapped_outputs[1])
# The 1st scroll info should contain scrolling, because the screen size
# is less than the number of lines in the output.
self.assertIn("Scroll (PgDn): 0.00%", ui.scroll_messages[0])
def testTabCompletionWithCommonPrefix(self):
# Type "b" and trigger tab completion.
ui = MockCursesUI(
40,
80,
command_sequence=[string_to_codes("b\t"), string_to_codes("\n"),
self._EXIT])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["ba"])
ui.run_ui()
# The automatically registered exit commands "exit" and "quit" should not
# appear in the tab completion candidates because they don't start with
# "b".
self.assertEqual([["ba", "babble"]], ui.candidates_lists)
# "ba" is a common prefix of the two candidates. So the "ba" command should
# have been issued after the Enter.
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual(1, len(ui.wrapped_outputs))
self.assertEqual(1, len(ui.scroll_messages))
self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[0].lines)
self.assertEqual(["bar"] * 60, ui.wrapped_outputs[0].lines[:60])
def testTabCompletionEmptyTriggerWithoutCommonPrefix(self):
ui = MockCursesUI(
40,
80,
command_sequence=[string_to_codes("\t"), # Trigger tab completion.
string_to_codes("\n"),
self._EXIT])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["a"])
# Use a different alias "a" instead.
ui.run_ui()
# The manually registered command, along with the automatically registered
# exit commands should appear in the candidates.
self.assertEqual(
[["a", "babble", "exit", "h", "help", "m", "mouse", "quit"]],
ui.candidates_lists)
# The two candidates have no common prefix. So no command should have been
# issued.
self.assertEqual(0, len(ui.unwrapped_outputs))
self.assertEqual(0, len(ui.wrapped_outputs))
self.assertEqual(0, len(ui.scroll_messages))
def testTabCompletionNonemptyTriggerSingleCandidate(self):
ui = MockCursesUI(
40,
80,
command_sequence=[string_to_codes("b\t"), # Trigger tab completion.
string_to_codes("\n"),
self._EXIT])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["a"])
ui.run_ui()
# There is only one candidate, so no candidates should have been displayed.
# Instead, the completion should have been automatically keyed in, leading
# to the "babble" command being issue.
self.assertEqual([[]], ui.candidates_lists)
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual(1, len(ui.wrapped_outputs))
self.assertEqual(1, len(ui.scroll_messages))
self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[0].lines)
self.assertEqual(["bar"] * 60, ui.wrapped_outputs[0].lines[:60])
def testTabCompletionNoMatch(self):
ui = MockCursesUI(
40,
80,
command_sequence=[string_to_codes("c\t"), # Trigger tab completion.
string_to_codes("\n"),
self._EXIT])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["a"])
ui.run_ui()
# Only the invalid command "c" should have been issued.
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual(1, len(ui.wrapped_outputs))
self.assertEqual(1, len(ui.scroll_messages))
self.assertEqual(["ERROR: Invalid command prefix \"c\""],
ui.unwrapped_outputs[0].lines)
self.assertEqual(["ERROR: Invalid command prefix \"c\""],
ui.wrapped_outputs[0].lines[:1])
def testTabCompletionOneWordContext(self):
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 3\t"), # Trigger tab completion.
string_to_codes("\n"),
self._EXIT
])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["b"])
ui.register_tab_comp_context(["babble", "b"], ["10", "20", "30", "300"])
ui.run_ui()
self.assertEqual([["30", "300"]], ui.candidates_lists)
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual(1, len(ui.wrapped_outputs))
self.assertEqual(1, len(ui.scroll_messages))
self.assertEqual(["bar"] * 30, ui.unwrapped_outputs[0].lines)
self.assertEqual(["bar"] * 30, ui.wrapped_outputs[0].lines[:30])
def testTabCompletionTwice(self):
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 1\t"), # Trigger tab completion.
string_to_codes("2\t"), # With more prefix, tab again.
string_to_codes("3\n"),
self._EXIT
])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["b"])
ui.register_tab_comp_context(["babble", "b"], ["10", "120", "123"])
ui.run_ui()
# There should have been two different lists of candidates.
self.assertEqual([["10", "120", "123"], ["120", "123"]],
ui.candidates_lists)
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual(1, len(ui.wrapped_outputs))
self.assertEqual(1, len(ui.scroll_messages))
self.assertEqual(["bar"] * 123, ui.unwrapped_outputs[0].lines)
self.assertEqual(["bar"] * 123, ui.wrapped_outputs[0].lines[:123])
def testRegexSearch(self):
"""Test regex search."""
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 3\n"),
string_to_codes("/(b|r)\n"), # Regex search and highlight.
string_to_codes("/a\n"), # Regex search and highlight.
self._EXIT
])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["b"])
ui.run_ui()
# The unwrapped (original) output should never have any highlighting.
self.assertEqual(3, len(ui.unwrapped_outputs))
for i in range(3):
self.assertEqual(["bar"] * 3, ui.unwrapped_outputs[i].lines)
self.assertEqual({}, ui.unwrapped_outputs[i].font_attr_segs)
# The wrapped outputs should show highlighting depending on the regex.
self.assertEqual(3, len(ui.wrapped_outputs))
# The first output should have no highlighting.
self.assertEqual(["bar"] * 3, ui.wrapped_outputs[0].lines[:3])
self.assertEqual({}, ui.wrapped_outputs[0].font_attr_segs)
# The second output should have highlighting for "b" and "r".
self.assertEqual(["bar"] * 3, ui.wrapped_outputs[1].lines[:3])
for i in range(3):
self.assertEqual([(0, 1, "black_on_white"), (2, 3, "black_on_white")],
ui.wrapped_outputs[1].font_attr_segs[i])
# The third output should have highlighting for "a" only.
self.assertEqual(["bar"] * 3, ui.wrapped_outputs[1].lines[:3])
for i in range(3):
self.assertEqual([(1, 2, "black_on_white")],
ui.wrapped_outputs[2].font_attr_segs[i])
def testRegexSearchContinuation(self):
"""Test continuing scrolling down to next regex match."""
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 3\n"),
string_to_codes("/(b|r)\n"), # Regex search and highlight.
string_to_codes("/\n"), # Continue scrolling down: 1st time.
string_to_codes("/\n"), # Continue scrolling down: 2nd time.
string_to_codes("/\n"), # Continue scrolling down: 3rd time.
string_to_codes("/\n"), # Continue scrolling down: 4th time.
self._EXIT
])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["b"])
ui.run_ui()
# The 1st output is for the non-searched output. The other three are for
# the searched output. Even though continuation search "/" is performed
# four times, there should be only three searched outputs, because the
# last one has exceeded the end.
self.assertEqual(4, len(ui.unwrapped_outputs))
for i in range(4):
self.assertEqual(["bar"] * 3, ui.unwrapped_outputs[i].lines)
self.assertEqual({}, ui.unwrapped_outputs[i].font_attr_segs)
self.assertEqual(["bar"] * 3, ui.wrapped_outputs[0].lines[:3])
self.assertEqual({}, ui.wrapped_outputs[0].font_attr_segs)
for j in range(1, 4):
self.assertEqual(["bar"] * 3, ui.wrapped_outputs[j].lines[:3])
self.assertEqual({
0: [(0, 1, "black_on_white"), (2, 3, "black_on_white")],
1: [(0, 1, "black_on_white"), (2, 3, "black_on_white")],
2: [(0, 1, "black_on_white"), (2, 3, "black_on_white")]
}, ui.wrapped_outputs[j].font_attr_segs)
self.assertEqual([0, 0, 1, 2], ui.output_pad_rows)
def testRegexSearchUnderLineWrapping(self):
ui = MockCursesUI(
40,
6, # Use a narrow window to trigger line wrapping
command_sequence=[
string_to_codes("babble -n 3 -l foo-bar-baz-qux\n"),
string_to_codes("/foo\n"), # Regex search and highlight.
string_to_codes("/\n"), # Continue scrolling down: 1st time.
string_to_codes("/\n"), # Continue scrolling down: 2nd time.
string_to_codes("/\n"), # Continue scrolling down: 3rd time.
string_to_codes("/\n"), # Continue scrolling down: 4th time.
self._EXIT
])
ui.register_command_handler(
"babble", self._babble, "babble some")
ui.run_ui()
self.assertEqual(4, len(ui.wrapped_outputs))
for wrapped_output in ui.wrapped_outputs:
self.assertEqual(["foo-", "bar-", "baz-", "qux"] * 3,
wrapped_output.lines[0 : 12])
# The scroll location should reflect the line wrapping.
self.assertEqual([0, 0, 4, 8], ui.output_pad_rows)
def testRegexSearchNoMatchContinuation(self):
"""Test continuing scrolling when there is no regex match."""
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 3\n"),
string_to_codes("/foo\n"), # Regex search and highlight.
string_to_codes("/\n"), # Continue scrolling down.
self._EXIT
])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["b"])
ui.run_ui()
# The regex search and continuation search in the 3rd command should not
# have produced any output.
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual([0], ui.output_pad_rows)
def testRegexSearchContinuationWithoutSearch(self):
"""Test continuation scrolling when no regex search has been performed."""
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 3\n"),
string_to_codes("/\n"), # Continue scrolling without search first.
self._EXIT
])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["b"])
ui.run_ui()
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual([0], ui.output_pad_rows)
def testRegexSearchWithInvalidRegex(self):
"""Test using invalid regex to search."""
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 3\n"),
string_to_codes("/[\n"), # Continue scrolling without search first.
self._EXIT
])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["b"])
ui.run_ui()
# Invalid regex should not have led to a new screen of output.
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual([0], ui.output_pad_rows)
# Invalid regex should have led to a toast error message.
self.assertEqual(
[MockCursesUI._UI_WAIT_MESSAGE,
"ERROR: Invalid regular expression: \"[\"",
MockCursesUI._UI_WAIT_MESSAGE],
ui.toasts)
def testRegexSearchFromCommandHistory(self):
"""Test regex search commands are recorded in command history."""
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 3\n"),
string_to_codes("/(b|r)\n"), # Regex search and highlight.
string_to_codes("babble -n 4\n"),
[curses.KEY_UP],
[curses.KEY_UP],
string_to_codes("\n"), # Hit Up twice and Enter.
self._EXIT
])
ui.register_command_handler(
"babble", self._babble, "babble some", prefix_aliases=["b"])
ui.run_ui()
self.assertEqual(4, len(ui.wrapped_outputs))
self.assertEqual(["bar"] * 3, ui.wrapped_outputs[0].lines[:3])
self.assertEqual({}, ui.wrapped_outputs[0].font_attr_segs)
self.assertEqual(["bar"] * 3, ui.wrapped_outputs[1].lines[:3])
for i in range(3):
self.assertEqual([(0, 1, "black_on_white"), (2, 3, "black_on_white")],
ui.wrapped_outputs[1].font_attr_segs[i])
self.assertEqual(["bar"] * 4, ui.wrapped_outputs[2].lines[:4])
self.assertEqual({}, ui.wrapped_outputs[2].font_attr_segs)
# The regex search command loaded from history should have worked on the
# new screen output.
self.assertEqual(["bar"] * 4, ui.wrapped_outputs[3].lines[:4])
for i in range(4):
self.assertEqual([(0, 1, "black_on_white"), (2, 3, "black_on_white")],
ui.wrapped_outputs[3].font_attr_segs[i])
def testDisplayTensorWithIndices(self):
"""Test displaying tensor with indices."""
ui = MockCursesUI(
9, # Use a small screen height to cause scrolling.
80,
command_sequence=[
string_to_codes("print_ones --size 5\n"),
[curses.KEY_NPAGE],
[curses.KEY_NPAGE],
[curses.KEY_NPAGE],
[curses.KEY_END],
[curses.KEY_NPAGE], # This PageDown goes over the bottom limit.
[curses.KEY_PPAGE],
[curses.KEY_PPAGE],
[curses.KEY_PPAGE],
[curses.KEY_HOME],
[curses.KEY_PPAGE], # This PageDown goes over the top limit.
self._EXIT
])
ui.register_command_handler("print_ones", self._print_ones,
"print an all-one matrix of specified size")
ui.run_ui()
self.assertEqual(11, len(ui.unwrapped_outputs))
self.assertEqual(11, len(ui.output_array_pointer_indices))
self.assertEqual(11, len(ui.scroll_messages))
for i in range(11):
self.assertEqual([
"Tensor \"m\":", "", "array([[ 1., 1., 1., 1., 1.],",
" [ 1., 1., 1., 1., 1.],",
" [ 1., 1., 1., 1., 1.],",
" [ 1., 1., 1., 1., 1.],",
" [ 1., 1., 1., 1., 1.]])"
], ui.unwrapped_outputs[i].lines)
self.assertEqual({
0: None,
-1: [1, 0]
}, ui.output_array_pointer_indices[0])
self.assertIn(" Scroll (PgDn): 0.00% -[1,0] ", ui.scroll_messages[0])
# Scrolled down one line.
self.assertEqual({
0: None,
-1: [2, 0]
}, ui.output_array_pointer_indices[1])
self.assertIn(" Scroll (PgDn/PgUp): 16.67% -[2,0] ", ui.scroll_messages[1])
# Scrolled down one line.
self.assertEqual({
0: [0, 0],
-1: [3, 0]
}, ui.output_array_pointer_indices[2])
self.assertIn(" Scroll (PgDn/PgUp): 33.33% [0,0]-[3,0] ",
ui.scroll_messages[2])
# Scrolled down one line.
self.assertEqual({
0: [1, 0],
-1: [4, 0]
}, ui.output_array_pointer_indices[3])
self.assertIn(" Scroll (PgDn/PgUp): 50.00% [1,0]-[4,0] ",
ui.scroll_messages[3])
# Scroll to the bottom.
self.assertEqual({
0: [4, 0],
-1: None
}, ui.output_array_pointer_indices[4])
self.assertIn(" Scroll (PgUp): 100.00% [4,0]- ", ui.scroll_messages[4])
# Attempt to scroll beyond the bottom should lead to no change.
self.assertEqual({
0: [4, 0],
-1: None
}, ui.output_array_pointer_indices[5])
self.assertIn(" Scroll (PgUp): 100.00% [4,0]- ", ui.scroll_messages[5])
# Scrolled up one line.
self.assertEqual({
0: [3, 0],
-1: None
}, ui.output_array_pointer_indices[6])
self.assertIn(" Scroll (PgDn/PgUp): 83.33% [3,0]- ", ui.scroll_messages[6])
# Scrolled up one line.
self.assertEqual({
0: [2, 0],
-1: None
}, ui.output_array_pointer_indices[7])
self.assertIn(" Scroll (PgDn/PgUp): 66.67% [2,0]- ", ui.scroll_messages[7])
# Scrolled up one line.
self.assertEqual({
0: [1, 0],
-1: [4, 0]
}, ui.output_array_pointer_indices[8])
self.assertIn(" Scroll (PgDn/PgUp): 50.00% [1,0]-[4,0] ",
ui.scroll_messages[8])
# Scroll to the top.
self.assertEqual({
0: None,
-1: [1, 0]
}, ui.output_array_pointer_indices[9])
self.assertIn(" Scroll (PgDn): 0.00% -[1,0] ", ui.scroll_messages[9])
# Attempt to scroll pass the top limit should lead to no change.
self.assertEqual({
0: None,
-1: [1, 0]
}, ui.output_array_pointer_indices[10])
self.assertIn(" Scroll (PgDn): 0.00% -[1,0] ", ui.scroll_messages[10])
def testScrollTensorByValidIndices(self):
"""Test scrolling to specified (valid) indices in a tensor."""
ui = MockCursesUI(
8, # Use a small screen height to cause scrolling.
80,
command_sequence=[
string_to_codes("print_ones --size 5\n"),
string_to_codes("@[0, 0]\n"), # Scroll to element [0, 0].
string_to_codes("@1,0\n"), # Scroll to element [3, 0].
string_to_codes("@[0,2]\n"), # Scroll back to line 0.
self._EXIT
])
ui.register_command_handler("print_ones", self._print_ones,
"print an all-one matrix of specified size")
ui.run_ui()
self.assertEqual(4, len(ui.unwrapped_outputs))
self.assertEqual(4, len(ui.output_array_pointer_indices))
for i in range(4):
self.assertEqual([
"Tensor \"m\":", "", "array([[ 1., 1., 1., 1., 1.],",
" [ 1., 1., 1., 1., 1.],",
" [ 1., 1., 1., 1., 1.],",
" [ 1., 1., 1., 1., 1.],",
" [ 1., 1., 1., 1., 1.]])"
], ui.unwrapped_outputs[i].lines)
self.assertEqual({
0: None,
-1: [0, 0]
}, ui.output_array_pointer_indices[0])
self.assertEqual({
0: [0, 0],
-1: [2, 0]
}, ui.output_array_pointer_indices[1])
self.assertEqual({
0: [1, 0],
-1: [3, 0]
}, ui.output_array_pointer_indices[2])
self.assertEqual({
0: [0, 0],
-1: [2, 0]
}, ui.output_array_pointer_indices[3])
def testScrollTensorByInvalidIndices(self):
"""Test scrolling to specified invalid indices in a tensor."""
ui = MockCursesUI(
8, # Use a small screen height to cause scrolling.
80,
command_sequence=[
string_to_codes("print_ones --size 5\n"),
string_to_codes("@[10, 0]\n"), # Scroll to invalid indices.
string_to_codes("@[]\n"), # Scroll to invalid indices.
string_to_codes("@\n"), # Scroll to invalid indices.
self._EXIT
])
ui.register_command_handler("print_ones", self._print_ones,
"print an all-one matrix of specified size")
ui.run_ui()
# Because all scroll-by-indices commands are invalid, there should be only
# one output event.
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual(1, len(ui.output_array_pointer_indices))
# Check error messages.
self.assertEqual("ERROR: Indices exceed tensor dimensions.", ui.toasts[2])
self.assertEqual("ERROR: invalid literal for int() with base 10: ''",
ui.toasts[4])
self.assertEqual("ERROR: Empty indices.", ui.toasts[6])
def testWriteScreenOutputToFileWorks(self):
output_path = tempfile.mktemp()
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 2>%s\n" % output_path),
self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertEqual(1, len(ui.unwrapped_outputs))
with gfile.Open(output_path, "r") as f:
self.assertEqual("bar\nbar\n", f.read())
# Clean up output file.
gfile.Remove(output_path)
def testIncompleteRedirectErrors(self):
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 2 >\n"),
self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertEqual(["ERROR: Redirect file path is empty"], ui.toasts)
self.assertEqual(0, len(ui.unwrapped_outputs))
def testAppendingRedirectErrors(self):
output_path = tempfile.mktemp()
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 2 >> %s\n" % output_path),
self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual(
["Syntax error for command: babble", "For help, do \"help babble\""],
ui.unwrapped_outputs[0].lines)
# Clean up output file.
gfile.Remove(output_path)
def testMouseOffTakesEffect(self):
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("mouse off\n"), string_to_codes("babble\n"),
self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertFalse(ui._mouse_enabled)
self.assertIn("Mouse: OFF", ui.scroll_messages[-1])
def testMouseOffAndOnTakeEffect(self):
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("mouse off\n"), string_to_codes("mouse on\n"),
string_to_codes("babble\n"), self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertTrue(ui._mouse_enabled)
self.assertIn("Mouse: ON", ui.scroll_messages[-1])
def testMouseClickOnLinkTriggersCommand(self):
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 10 -k\n"),
[curses.KEY_MOUSE, 1, 4], # A click on a hyperlink.
self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertEqual(2, len(ui.unwrapped_outputs))
self.assertEqual(["bar"] * 10, ui.unwrapped_outputs[0].lines)
self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[1].lines)
def testMouseClickOnLinkWithExistingTextTriggersCommand(self):
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 10 -k\n"),
string_to_codes("foo"), # Enter some existing code in the textbox.
[curses.KEY_MOUSE, 1, 4], # A click on a hyperlink.
self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertEqual(2, len(ui.unwrapped_outputs))
self.assertEqual(["bar"] * 10, ui.unwrapped_outputs[0].lines)
self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[1].lines)
def testMouseClickOffLinkDoesNotTriggersCommand(self):
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 10 -k\n"),
# A click off a hyperlink (too much to the right).
[curses.KEY_MOUSE, 8, 4],
self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
# The mouse click event should not triggered no command.
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual(["bar"] * 10, ui.unwrapped_outputs[0].lines)
# This command should have generated no main menus.
self.assertEqual([None], ui.main_menu_list)
def testMouseClickOnEnabledMenuItemWorks(self):
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 10 -m\n"),
# A click on the enabled menu item.
[curses.KEY_MOUSE, 3, 2],
self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertEqual(2, len(ui.unwrapped_outputs))
self.assertEqual(["bar"] * 10, ui.unwrapped_outputs[0].lines)
self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[1].lines)
# Check the content of the menu.
self.assertEqual(["| babble again | ahoy | "], ui.main_menu_list[0].lines)
self.assertEqual(1, len(ui.main_menu_list[0].font_attr_segs))
self.assertEqual(1, len(ui.main_menu_list[0].font_attr_segs[0]))
item_annot = ui.main_menu_list[0].font_attr_segs[0][0]
self.assertEqual(2, item_annot[0])
self.assertEqual(14, item_annot[1])
self.assertEqual("babble", item_annot[2][0].content)
self.assertEqual("underline", item_annot[2][1])
# The output from the menu-triggered command does not have a menu.
self.assertIsNone(ui.main_menu_list[1])
def testMouseClickOnDisabledMenuItemTriggersNoCommand(self):
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 10 -m\n"),
# A click on the disabled menu item.
[curses.KEY_MOUSE, 18, 1],
self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertEqual(1, len(ui.unwrapped_outputs))
self.assertEqual(["bar"] * 10, ui.unwrapped_outputs[0].lines)
def testNavigationUsingCommandLineWorks(self):
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 2\n"),
string_to_codes("babble -n 4\n"),
string_to_codes("prev\n"),
string_to_codes("next\n"),
self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertEqual(4, len(ui.unwrapped_outputs))
self.assertEqual(["bar"] * 2, ui.unwrapped_outputs[0].lines)
self.assertEqual(["bar"] * 4, ui.unwrapped_outputs[1].lines)
self.assertEqual(["bar"] * 2, ui.unwrapped_outputs[2].lines)
self.assertEqual(["bar"] * 4, ui.unwrapped_outputs[3].lines)
def testNavigationOverOldestLimitUsingCommandLineGivesCorrectWarning(self):
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 2\n"),
string_to_codes("babble -n 4\n"),
string_to_codes("prev\n"),
string_to_codes("prev\n"), # Navigate over oldest limit.
self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertEqual(3, len(ui.unwrapped_outputs))
self.assertEqual(["bar"] * 2, ui.unwrapped_outputs[0].lines)
self.assertEqual(["bar"] * 4, ui.unwrapped_outputs[1].lines)
self.assertEqual(["bar"] * 2, ui.unwrapped_outputs[2].lines)
self.assertEqual("At the OLDEST in navigation history!", ui.toasts[-2])
def testNavigationOverLatestLimitUsingCommandLineGivesCorrectWarning(self):
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 2\n"),
string_to_codes("babble -n 4\n"),
string_to_codes("prev\n"),
string_to_codes("next\n"),
string_to_codes("next\n"), # Navigate over latest limit.
self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertEqual(4, len(ui.unwrapped_outputs))
self.assertEqual(["bar"] * 2, ui.unwrapped_outputs[0].lines)
self.assertEqual(["bar"] * 4, ui.unwrapped_outputs[1].lines)
self.assertEqual(["bar"] * 2, ui.unwrapped_outputs[2].lines)
self.assertEqual(["bar"] * 4, ui.unwrapped_outputs[3].lines)
self.assertEqual("At the LATEST in navigation history!", ui.toasts[-2])
def testMouseClicksOnNavBarWorks(self):
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 2\n"),
string_to_codes("babble -n 4\n"),
# A click on the back (prev) button of the nav bar.
[curses.KEY_MOUSE, 3, 1],
# A click on the forward (prev) button of the nav bar.
[curses.KEY_MOUSE, 7, 1],
self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertEqual(4, len(ui.unwrapped_outputs))
self.assertEqual(["bar"] * 2, ui.unwrapped_outputs[0].lines)
self.assertEqual(["bar"] * 4, ui.unwrapped_outputs[1].lines)
self.assertEqual(["bar"] * 2, ui.unwrapped_outputs[2].lines)
self.assertEqual(["bar"] * 4, ui.unwrapped_outputs[3].lines)
def testMouseClicksOnNavBarAfterPreviousScrollingWorks(self):
ui = MockCursesUI(
40,
80,
command_sequence=[
string_to_codes("babble -n 2\n"),
[curses.KEY_NPAGE], # Scroll down one line.
string_to_codes("babble -n 4\n"),
# A click on the back (prev) button of the nav bar.
[curses.KEY_MOUSE, 3, 1],
# A click on the forward (prev) button of the nav bar.
[curses.KEY_MOUSE, 7, 1],
self._EXIT
])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
self.assertEqual(6, len(ui.unwrapped_outputs))
self.assertEqual(["bar"] * 2, ui.unwrapped_outputs[0].lines)
# From manual scroll.
self.assertEqual(["bar"] * 2, ui.unwrapped_outputs[1].lines)
self.assertEqual(["bar"] * 4, ui.unwrapped_outputs[2].lines)
# From history navigation.
self.assertEqual(["bar"] * 2, ui.unwrapped_outputs[3].lines)
# From history navigation's auto-scroll to history scroll position.
self.assertEqual(["bar"] * 2, ui.unwrapped_outputs[4].lines)
self.assertEqual(["bar"] * 4, ui.unwrapped_outputs[5].lines)
self.assertEqual(6, len(ui.scroll_messages))
self.assertIn("Scroll (PgDn): 0.00%", ui.scroll_messages[0])
self.assertIn("Scroll (PgUp): 100.00%", ui.scroll_messages[1])
self.assertIn("Scroll (PgDn): 0.00%", ui.scroll_messages[2])
self.assertIn("Scroll (PgDn): 0.00%", ui.scroll_messages[3])
self.assertIn("Scroll (PgUp): 100.00%", ui.scroll_messages[4])
self.assertIn("Scroll (PgDn): 0.00%", ui.scroll_messages[5])
class ScrollBarTest(test_util.TensorFlowTestCase):
def testConstructorRaisesExceptionForNotEnoughHeight(self):
with self.assertRaisesRegexp(
ValueError, r"Insufficient height for ScrollBar \(2\)"):
curses_ui.ScrollBar(0, 0, 1, 1, 0, 0)
def testLayoutIsEmptyForZeroRow(self):
scroll_bar = curses_ui.ScrollBar(0, 0, 1, 7, 0, 0)
layout = scroll_bar.layout()
self.assertEqual([" "] * 8, layout.lines)
self.assertEqual({}, layout.font_attr_segs)
def testLayoutIsEmptyFoOneRow(self):
scroll_bar = curses_ui.ScrollBar(0, 0, 1, 7, 0, 1)
layout = scroll_bar.layout()
self.assertEqual([" "] * 8, layout.lines)
self.assertEqual({}, layout.font_attr_segs)
def testClickCommandForOneRowIsNone(self):
scroll_bar = curses_ui.ScrollBar(0, 0, 1, 7, 0, 1)
self.assertIsNone(scroll_bar.get_click_command(0))
self.assertIsNone(scroll_bar.get_click_command(3))
self.assertIsNone(scroll_bar.get_click_command(7))
self.assertIsNone(scroll_bar.get_click_command(8))
def testLayoutIsCorrectForTopPosition(self):
scroll_bar = curses_ui.ScrollBar(0, 0, 1, 7, 0, 20)
layout = scroll_bar.layout()
self.assertEqual(["UP"] + [" "] * 6 + ["DN"], layout.lines)
self.assertEqual(
{0: [(0, 2, curses_ui.ScrollBar.BASE_ATTR)],
1: [(0, 2, curses_ui.ScrollBar.BASE_ATTR)],
7: [(0, 2, curses_ui.ScrollBar.BASE_ATTR)]},
layout.font_attr_segs)
def testWidth1LayoutIsCorrectForTopPosition(self):
scroll_bar = curses_ui.ScrollBar(0, 0, 0, 7, 0, 20)
layout = scroll_bar.layout()
self.assertEqual(["U"] + [" "] * 6 + ["D"], layout.lines)
self.assertEqual(
{0: [(0, 1, curses_ui.ScrollBar.BASE_ATTR)],
1: [(0, 1, curses_ui.ScrollBar.BASE_ATTR)],
7: [(0, 1, curses_ui.ScrollBar.BASE_ATTR)]},
layout.font_attr_segs)
def testWidth3LayoutIsCorrectForTopPosition(self):
scroll_bar = curses_ui.ScrollBar(0, 0, 2, 7, 0, 20)
layout = scroll_bar.layout()
self.assertEqual(["UP "] + [" "] * 6 + ["DN "], layout.lines)
self.assertEqual(
{0: [(0, 3, curses_ui.ScrollBar.BASE_ATTR)],
1: [(0, 3, curses_ui.ScrollBar.BASE_ATTR)],
7: [(0, 3, curses_ui.ScrollBar.BASE_ATTR)]},
layout.font_attr_segs)
def testWidth4LayoutIsCorrectForTopPosition(self):
scroll_bar = curses_ui.ScrollBar(0, 0, 3, 7, 0, 20)
layout = scroll_bar.layout()
self.assertEqual([" UP "] + [" "] * 6 + ["DOWN"], layout.lines)
self.assertEqual(
{0: [(0, 4, curses_ui.ScrollBar.BASE_ATTR)],
1: [(0, 4, curses_ui.ScrollBar.BASE_ATTR)],
7: [(0, 4, curses_ui.ScrollBar.BASE_ATTR)]},
layout.font_attr_segs)
def testLayoutIsCorrectForBottomPosition(self):
scroll_bar = curses_ui.ScrollBar(0, 0, 1, 7, 19, 20)
layout = scroll_bar.layout()
self.assertEqual(["UP"] + [" "] * 6 + ["DN"], layout.lines)
self.assertEqual(
{0: [(0, 2, curses_ui.ScrollBar.BASE_ATTR)],
6: [(0, 2, curses_ui.ScrollBar.BASE_ATTR)],
7: [(0, 2, curses_ui.ScrollBar.BASE_ATTR)]},
layout.font_attr_segs)
def testLayoutIsCorrectForMiddlePosition(self):
scroll_bar = curses_ui.ScrollBar(0, 0, 1, 7, 10, 20)
layout = scroll_bar.layout()
self.assertEqual(["UP"] + [" "] * 6 + ["DN"], layout.lines)
self.assertEqual(
{0: [(0, 2, curses_ui.ScrollBar.BASE_ATTR)],
3: [(0, 2, curses_ui.ScrollBar.BASE_ATTR)],
7: [(0, 2, curses_ui.ScrollBar.BASE_ATTR)]},
layout.font_attr_segs)
def testClickCommandsAreCorrectForMiddlePosition(self):
scroll_bar = curses_ui.ScrollBar(0, 0, 1, 7, 10, 20)
self.assertIsNone(scroll_bar.get_click_command(-1))
self.assertEqual(curses_ui._SCROLL_UP_A_LINE,
scroll_bar.get_click_command(0))
self.assertEqual(curses_ui._SCROLL_UP,
scroll_bar.get_click_command(1))
self.assertEqual(curses_ui._SCROLL_UP,
scroll_bar.get_click_command(2))
self.assertIsNone(scroll_bar.get_click_command(3))
self.assertEqual(curses_ui._SCROLL_DOWN,
scroll_bar.get_click_command(5))
self.assertEqual(curses_ui._SCROLL_DOWN,
scroll_bar.get_click_command(6))
self.assertEqual(curses_ui._SCROLL_DOWN_A_LINE,
scroll_bar.get_click_command(7))
self.assertIsNone(scroll_bar.get_click_command(8))
def testClickCommandsAreCorrectForBottomPosition(self):
scroll_bar = curses_ui.ScrollBar(0, 0, 1, 7, 19, 20)
self.assertIsNone(scroll_bar.get_click_command(-1))
self.assertEqual(curses_ui._SCROLL_UP_A_LINE,
scroll_bar.get_click_command(0))
for i in range(1, 6):
self.assertEqual(curses_ui._SCROLL_UP,
scroll_bar.get_click_command(i))
self.assertIsNone(scroll_bar.get_click_command(6))
self.assertEqual(curses_ui._SCROLL_DOWN_A_LINE,
scroll_bar.get_click_command(7))
self.assertIsNone(scroll_bar.get_click_command(8))
def testClickCommandsAreCorrectForScrollBarNotAtZeroMinY(self):
scroll_bar = curses_ui.ScrollBar(0, 5, 1, 12, 10, 20)
self.assertIsNone(scroll_bar.get_click_command(0))
self.assertIsNone(scroll_bar.get_click_command(4))
self.assertEqual(curses_ui._SCROLL_UP_A_LINE,
scroll_bar.get_click_command(5))
self.assertEqual(curses_ui._SCROLL_UP,
scroll_bar.get_click_command(6))
self.assertEqual(curses_ui._SCROLL_UP,
scroll_bar.get_click_command(7))
self.assertIsNone(scroll_bar.get_click_command(8))
self.assertEqual(curses_ui._SCROLL_DOWN,
scroll_bar.get_click_command(10))
self.assertEqual(curses_ui._SCROLL_DOWN,
scroll_bar.get_click_command(11))
self.assertEqual(curses_ui._SCROLL_DOWN_A_LINE,
scroll_bar.get_click_command(12))
self.assertIsNone(scroll_bar.get_click_command(13))
if __name__ == "__main__":
googletest.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,
402,
314,
15429,
13,
6788,
14214,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
7534,
199,
646,
15429,
199,
646,
5549,
199,
646,
5796,
199,
199,
646,
2680,
465,
980,
199,
504,
3816,
14,
4912,
492,
4126,
199,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
15429,
63,
1907,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
14958,
63,
2764,
63,
2330,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
2345,
63,
908,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
3246,
492,
26532,
199,
504,
3228,
14,
1548,
14,
3246,
492,
31141,
421,
199,
318,
1059,
63,
475,
63,
6021,
8,
1760,
304,
523,
372,
359,
2181,
8,
67,
9,
367,
286,
315,
2088,
61,
421,
199,
318,
9479,
63,
475,
63,
875,
8,
1760,
63,
600,
304,
523,
327,
593,
1147,
2222,
13,
12292,
790,
9479,
14,
523,
372,
10587,
904,
779,
10194,
8,
600,
9,
367,
1233,
315,
2088,
63,
600,
340,
1233,
665,
7633,
566,
421,
199,
533,
4420,
3864,
874,
6379,
8,
12026,
63,
1907,
14,
3864,
874,
6379,
304,
523,
408,
3346,
5516,
402,
7319,
874,
6379,
626,
701,
16027,
3503,
11167,
13335,
21429,
1041,
819,
347,
636,
826,
721,
277,
12,
2049,
4569,
12,
2049,
3462,
12,
2049,
1414,
63,
4041,
29,
403,
304,
272,
291,
423,
3333,
275,
4569,
272,
291,
423,
2063,
275,
3462,
339,
291,
423,
1531,
63,
4041,
275,
1414,
63,
4041,
272,
291,
423,
1531,
63,
5337,
275,
378,
339,
327,
710,
1683,
1021,
965,
949,
3503,
1318,
1977,
14,
2002,
675,
642,
1750,
370,
4215,
272,
327,
4426,
402,
4052,
1159,
19138,
315,
314,
1318,
1977,
641,
7143,
14,
272,
291,
423,
9808,
63,
5952,
63,
1531,
275,
3087,
339,
327,
17985,
5871,
367,
511,
14,
272,
327,
17985,
5871,
402,
6426,
1072,
14,
272,
291,
14,
324,
9130,
63,
4467,
275,
942,
272,
291,
14,
9130,
63,
4467,
275,
942,
272,
291,
14,
6755,
63,
3431,
275,
942,
272,
291,
14,
1199,
63,
1144,
63,
3929,
63,
4108,
275,
942,
339,
291,
14,
1199,
63,
6226,
63,
3838,
275,
942,
339,
327,
17985,
5871,
402,
1414,
1318,
1977,
14,
272,
291,
14,
5952,
63,
4405,
275,
942,
339,
327,
17985,
1000,
367,
5174,
13,
13207,
15101,
14,
272,
291,
14,
16389,
63,
6717,
275,
942,
339,
327,
17985,
1000,
367,
314,
2446,
6269,
14,
272,
291,
14,
973,
63,
4470,
63,
513,
275,
942,
339,
327,
17985,
1000,
367,
370,
1810,
3788,
14,
272,
291,
14,
475,
1810,
83,
275,
942,
339,
15429,
63,
1907,
14,
3864,
874,
6379,
855,
826,
721,
277,
9,
339,
327,
11041,
314,
849,
931,
370,
314,
1414,
7994,
570,
370,
5126,
511,
272,
327,
406,
4968,
10876,
14,
272,
291,
423,
1531,
63,
5570,
63,
1617,
275,
14958,
63,
2764,
63,
2330,
14,
3110,
12114,
8,
267,
7994,
63,
493,
63,
515,
29,
17336,
14,
22136,
1012,
819,
327,
6423,
674,
12,
4278,
314,
485,
5410,
63,
18239,
3653,
3102,
626,
17232,
543,
314,
523,
327,
3503,
11167,
12,
880,
626,
314,
1683,
883,
1255,
315,
282,
11167,
13,
2003,
3734,
14,
819,
327,
3254,
8,
696,
374,
304,
8730,
367,
282,
4340,
370,
1172,
282,
1683,
11167,
909,
626,
25113,
523,
327,
2839,
314,
3503,
11167,
12,
880,
626,
781,
883,
511,
314,
11167,
18752,
523,
327,
4184,
402,
314,
7319,
874,
6379,
1021,
14,
819,
347,
485,
5410,
63,
826,
8,
277,
304,
272,
986,
819,
347,
485,
5410,
63,
6635,
63,
890,
8,
277,
304,
272,
291,
423,
988,
63,
89,
275,
291,
423,
3333,
272,
291,
423,
988,
63,
88,
275,
291,
423,
2063,
819,
347,
485,
5410,
63,
9850,
8,
277,
12,
4756,
63,
10544,
63,
265,
63,
928,
304,
272,
291,
423,
10544,
63,
3827,
275,
4756,
63,
10544,
63,
265,
63,
928,
819,
347,
485,
5410,
63,
14478,
8,
277,
304,
272,
986,
819,
347,
485,
5410,
63,
6635,
8,
277,
304,
272,
986,
819,
347,
485,
5410,
63,
981,
63,
1531,
63,
3806,
8,
277,
304,
272,
986,
819,
347,
485,
5410,
63,
981,
63,
1531,
63,
505,
1977,
8,
277,
12,
3411,
63,
1531,
29,
403,
304,
272,
408,
11954,
370,
5518,
27336,
402,
3411,
3718,
14,
339,
8051,
315,
5343,
402,
7994,
19191,
436,
5174,
13659,
14,
339,
3033,
26,
489,
3411,
63,
1531,
26,
5817,
1059,
19138,
370,
314,
1318,
1977,
737,
1318,
1977,
267,
7143,
900,
14,
3390,
626,
314,
1318,
1977,
1630,
440,
5965,
2187,
315,
642,
267,
1683,
5516,
14,
961,
1083,
1454,
18578,
4426,
402,
436,
5767,
314,
1174,
14,
272,
408,
339,
291,
14,
5952,
63,
4405,
14,
740,
8,
5952,
63,
1531,
9,
272,
291,
423,
9808,
63,
5952,
63,
1531,
275,
3411,
63,
1531,
819,
347,
485,
5410,
63,
1222,
63,
1199,
63,
6226,
8,
277,
12,
4730,
12,
8850,
304,
272,
372,
298,
1805,
63,
6226,
2,
819,
347,
485,
5410,
63,
525,
63,
604,
63,
475,
63,
1199,
63,
6226,
8,
277,
12,
6567,
12,
1962,
12,
9444,
12,
3164,
63,
13879,
29,
403,
304,
272,
986,
819,
347,
485
] |
[
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,
402,
314,
15429,
13,
6788,
14214,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
7534,
199,
646,
15429,
199,
646,
5549,
199,
646,
5796,
199,
199,
646,
2680,
465,
980,
199,
504,
3816,
14,
4912,
492,
4126,
199,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
15429,
63,
1907,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
14958,
63,
2764,
63,
2330,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
2345,
63,
908,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
3246,
492,
26532,
199,
504,
3228,
14,
1548,
14,
3246,
492,
31141,
421,
199,
318,
1059,
63,
475,
63,
6021,
8,
1760,
304,
523,
372,
359,
2181,
8,
67,
9,
367,
286,
315,
2088,
61,
421,
199,
318,
9479,
63,
475,
63,
875,
8,
1760,
63,
600,
304,
523,
327,
593,
1147,
2222,
13,
12292,
790,
9479,
14,
523,
372,
10587,
904,
779,
10194,
8,
600,
9,
367,
1233,
315,
2088,
63,
600,
340,
1233,
665,
7633,
566,
421,
199,
533,
4420,
3864,
874,
6379,
8,
12026,
63,
1907,
14,
3864,
874,
6379,
304,
523,
408,
3346,
5516,
402,
7319,
874,
6379,
626,
701,
16027,
3503,
11167,
13335,
21429,
1041,
819,
347,
636,
826,
721,
277,
12,
2049,
4569,
12,
2049,
3462,
12,
2049,
1414,
63,
4041,
29,
403,
304,
272,
291,
423,
3333,
275,
4569,
272,
291,
423,
2063,
275,
3462,
339,
291,
423,
1531,
63,
4041,
275,
1414,
63,
4041,
272,
291,
423,
1531,
63,
5337,
275,
378,
339,
327,
710,
1683,
1021,
965,
949,
3503,
1318,
1977,
14,
2002,
675,
642,
1750,
370,
4215,
272,
327,
4426,
402,
4052,
1159,
19138,
315,
314,
1318,
1977,
641,
7143,
14,
272,
291,
423,
9808,
63,
5952,
63,
1531,
275,
3087,
339,
327,
17985,
5871,
367,
511,
14,
272,
327,
17985,
5871,
402,
6426,
1072,
14,
272,
291,
14,
324,
9130,
63,
4467,
275,
942,
272,
291,
14,
9130,
63,
4467,
275,
942,
272,
291,
14,
6755,
63,
3431,
275,
942,
272,
291,
14,
1199,
63,
1144,
63,
3929,
63,
4108,
275,
942,
339,
291,
14,
1199,
63,
6226,
63,
3838,
275,
942,
339,
327,
17985,
5871,
402,
1414,
1318,
1977,
14,
272,
291,
14,
5952,
63,
4405,
275,
942,
339,
327,
17985,
1000,
367,
5174,
13,
13207,
15101,
14,
272,
291,
14,
16389,
63,
6717,
275,
942,
339,
327,
17985,
1000,
367,
314,
2446,
6269,
14,
272,
291,
14,
973,
63,
4470,
63,
513,
275,
942,
339,
327,
17985,
1000,
367,
370,
1810,
3788,
14,
272,
291,
14,
475,
1810,
83,
275,
942,
339,
15429,
63,
1907,
14,
3864,
874,
6379,
855,
826,
721,
277,
9,
339,
327,
11041,
314,
849,
931,
370,
314,
1414,
7994,
570,
370,
5126,
511,
272,
327,
406,
4968,
10876,
14,
272,
291,
423,
1531,
63,
5570,
63,
1617,
275,
14958,
63,
2764,
63,
2330,
14,
3110,
12114,
8,
267,
7994,
63,
493,
63,
515,
29,
17336,
14,
22136,
1012,
819,
327,
6423,
674,
12,
4278,
314,
485,
5410,
63,
18239,
3653,
3102,
626,
17232,
543,
314,
523,
327,
3503,
11167,
12,
880,
626,
314,
1683,
883,
1255,
315,
282,
11167,
13,
2003,
3734,
14,
819,
327,
3254,
8,
696,
374,
304,
8730,
367,
282,
4340,
370,
1172,
282,
1683,
11167,
909,
626,
25113,
523,
327,
2839,
314,
3503,
11167,
12,
880,
626,
781,
883,
511,
314,
11167,
18752,
523,
327,
4184,
402,
314,
7319,
874,
6379,
1021,
14,
819,
347,
485,
5410,
63,
826,
8,
277,
304,
272,
986,
819,
347,
485,
5410,
63,
6635,
63,
890,
8,
277,
304,
272,
291,
423,
988,
63,
89,
275,
291,
423,
3333,
272,
291,
423,
988,
63,
88,
275,
291,
423,
2063,
819,
347,
485,
5410,
63,
9850,
8,
277,
12,
4756,
63,
10544,
63,
265,
63,
928,
304,
272,
291,
423,
10544,
63,
3827,
275,
4756,
63,
10544,
63,
265,
63,
928,
819,
347,
485,
5410,
63,
14478,
8,
277,
304,
272,
986,
819,
347,
485,
5410,
63,
6635,
8,
277,
304,
272,
986,
819,
347,
485,
5410,
63,
981,
63,
1531,
63,
3806,
8,
277,
304,
272,
986,
819,
347,
485,
5410,
63,
981,
63,
1531,
63,
505,
1977,
8,
277,
12,
3411,
63,
1531,
29,
403,
304,
272,
408,
11954,
370,
5518,
27336,
402,
3411,
3718,
14,
339,
8051,
315,
5343,
402,
7994,
19191,
436,
5174,
13659,
14,
339,
3033,
26,
489,
3411,
63,
1531,
26,
5817,
1059,
19138,
370,
314,
1318,
1977,
737,
1318,
1977,
267,
7143,
900,
14,
3390,
626,
314,
1318,
1977,
1630,
440,
5965,
2187,
315,
642,
267,
1683,
5516,
14,
961,
1083,
1454,
18578,
4426,
402,
436,
5767,
314,
1174,
14,
272,
408,
339,
291,
14,
5952,
63,
4405,
14,
740,
8,
5952,
63,
1531,
9,
272,
291,
423,
9808,
63,
5952,
63,
1531,
275,
3411,
63,
1531,
819,
347,
485,
5410,
63,
1222,
63,
1199,
63,
6226,
8,
277,
12,
4730,
12,
8850,
304,
272,
372,
298,
1805,
63,
6226,
2,
819,
347,
485,
5410,
63,
525,
63,
604,
63,
475,
63,
1199,
63,
6226,
8,
277,
12,
6567,
12,
1962,
12,
9444,
12,
3164,
63,
13879,
29,
403,
304,
272,
986,
819,
347,
485,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
TreesLab/NCLscan
|
bin/create_reference.py
|
1
|
3080
|
#! /usr/bin/env python2
import argparse
import re
import os
import sys
from collections import OrderedDict
def create_reference_and_index(config):
'''
Create the reference and index for NCLscan.
1. Repeat_ChrM
2. AllRef.fa
3. Bwa index
4. Novoalign index
'''
config_options = config.options.copy()
Run_with_args = Run_cmd(config_options)
Run_with_args("mkdir -p {NCLscan_ref_dir}")
# Generate the "Repeat_ChrM"
Run_with_args("echo 'chrM' > {NCLscan_ref_dir}/chrM.list")
Run_with_args("cat {Reference_genome} | {SeqOut_bin} {NCLscan_ref_dir}/chrM.list 1 > {NCLscan_ref_dir}/chrM.fa")
Run_with_args("cat {NCLscan_ref_dir}/chrM.fa | sed '1d' > {NCLscan_ref_dir}/chrM.seq")
Run_with_args("head -n 1 {NCLscan_ref_dir}/chrM.fa > {NCLscan_ref_dir}/chrM.title")
Run_with_args("cat {NCLscan_ref_dir}/chrM.title {NCLscan_ref_dir}/chrM.seq {NCLscan_ref_dir}/chrM.seq > {NCLscan_ref_dir}/RepChrM.fa")
# Generate the "AllRef.fa"
Run_with_args("cat {Reference_genome} | grep '^>' | sed -r 's/>([^ ]*).*/\\1/g' | grep -v 'chrM' > {NCLscan_ref_dir}/non_chrM.list")
Run_with_args("cat {Reference_genome} | {SeqOut_bin} {NCLscan_ref_dir}/non_chrM.list 1 > {NCLscan_ref_dir}/ref_non_chrM.fa")
Run_with_args("cat {NCLscan_ref_dir}/ref_non_chrM.fa {Protein_coding_transcripts} {lncRNA_transcripts} {NCLscan_ref_dir}/RepChrM.fa > {NCLscan_ref_dir}/AllRef.fa")
# Generate the index for bwa
Run_with_args("{bwa_bin} index {NCLscan_ref_dir}/AllRef.fa")
# Generate the index for novoalign
Run_with_args("{novoindex_bin} {NCLscan_ref_dir}/AllRef.ndx {NCLscan_ref_dir}/AllRef.fa")
# Remove tmp files
Run_with_args("rm -f {NCLscan_ref_dir}/chrM.list {NCLscan_ref_dir}/chrM.fa {NCLscan_ref_dir}/chrM.seq {NCLscan_ref_dir}/chrM.title {NCLscan_ref_dir}/non_chrM.list {NCLscan_ref_dir}/ref_non_chrM.fa")
def Run_cmd(args):
def Run(cmd_str):
os.system(cmd_str.format(**args))
return Run
class NCLscanConfig(object):
def __init__(self, config_text):
self.parse_config(config_text)
def parse_config(self, config_text):
format_options = re.sub("^ *(.*?)/? *$", "\g<1>", config_text, flags=re.M)
all_options = OrderedDict(re.findall("(^[^#\n][\w-]*) *= *(.*)", format_options, flags=re.M))
for key, value in all_options.items():
if value == "":
print >> sys.stderr, "Error: There is a key with empty value: {}".format(key)
exit(1)
all_options[key] = value.format(**all_options)
self.options = all_options
def get(self, key):
return self.options[key]
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--config", help="The config file of NCLscan.")
args = parser.parse_args()
if len(sys.argv) == 1:
parser.print_help()
sys.exit()
with open(args.config) as config_file:
config = NCLscanConfig(config_file.read())
create_reference_and_index(config)
|
mit
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
18,
199,
199,
646,
7534,
199,
646,
295,
199,
646,
747,
199,
646,
984,
199,
504,
5055,
492,
8773,
199,
199,
318,
1218,
63,
4443,
63,
460,
63,
1080,
8,
888,
304,
272,
1449,
267,
2790,
314,
3659,
436,
1478,
367,
653,
1981,
6282,
14,
267,
413,
14,
21973,
292,
63,
1049,
82,
45,
267,
499,
14,
2900,
2891,
14,
667,
267,
650,
14,
699,
758,
1478,
267,
841,
14,
3091,
2392,
5743,
1478,
272,
1449,
339,
1101,
63,
1419,
275,
1101,
14,
1419,
14,
1574,
342,
272,
3378,
63,
1045,
63,
589,
275,
3378,
63,
1760,
8,
888,
63,
1419,
9,
339,
3378,
63,
1045,
63,
589,
480,
8215,
446,
80,
469,
46,
1981,
6282,
63,
1121,
63,
694,
15412,
339,
327,
7958,
314,
298,
27600,
63,
1049,
82,
45,
2,
272,
3378,
63,
1045,
63,
589,
480,
7878,
283,
10194,
45,
7,
690,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
513,
531,
272,
3378,
63,
1045,
63,
589,
480,
3385,
469,
5083,
63,
27776,
93,
1204,
469,
11205,
2204,
63,
1393,
93,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
513,
413,
690,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
667,
531,
272,
3378,
63,
1045,
63,
589,
480,
3385,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
667,
1204,
542,
68,
283,
17,
68,
7,
690,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
3610,
531,
272,
3378,
63,
1045,
63,
589,
480,
2993,
446,
78,
413,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
667,
690,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
1213,
531,
272,
3378,
63,
1045,
63,
589,
480,
3385,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
1213,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
3610,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
3610,
690,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
6875,
1049,
82,
45,
14,
667,
531,
339,
327,
7958,
314,
298,
2422,
2891,
14,
667,
2,
272,
3378,
63,
1045,
63,
589,
480,
3385,
469,
5083,
63,
27776,
93,
1204,
20595,
14452,
3524,
1204,
542,
68,
446,
82,
283,
83,
3133,
7059,
1622,
10,
680,
15870,
1103,
17,
15,
71,
7,
1204,
20595,
446,
86,
283,
10194,
45,
7,
690,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
2865,
63,
10194,
45,
14,
513,
531,
272,
3378,
63,
1045,
63,
589,
480,
3385,
469,
5083,
63,
27776,
93,
1204,
469,
11205,
2204,
63,
1393,
93,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
2865,
63,
10194,
45,
14,
513,
413,
690,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
1121,
63,
2865,
63,
10194,
45,
14,
667,
531,
272,
3378,
63,
1045,
63,
589,
480,
3385,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
1121,
63,
2865,
63,
10194,
45,
14,
667,
469,
919,
15859,
63,
1523,
63,
27800,
93,
469,
6066,
67,
25179,
63,
27800,
93,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
6875,
1049,
82,
45,
14,
667,
690,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
2422,
2891,
14,
667,
531,
339,
327,
7958,
314,
1478,
367,
330,
758,
272,
3378,
63,
1045,
63,
589,
13076,
66,
758,
63,
1393,
93,
1478,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
2422,
2891,
14,
667,
531,
2286,
327,
7958,
314,
1478,
367,
949,
2392,
5743,
272,
3378,
63,
1045,
63,
589,
13076,
889,
2392,
1080,
63,
1393,
93,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
2422,
2891,
14,
31818,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
2422,
2891,
14,
667,
531,
339,
327,
5852,
3529,
1584,
272,
3378,
63,
1045,
63,
589,
480,
5682,
446,
70,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
513,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
667,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
3610,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
1213,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
2865,
63,
10194,
45,
14,
513,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
1121,
63,
2865,
63,
10194,
45,
14,
667,
531,
421,
199,
318,
3378,
63,
1760,
8,
589,
304,
272,
347,
3378,
8,
1760,
63,
495,
304,
267,
747,
14,
2253,
8,
1760,
63,
495,
14,
908,
3682,
589,
430,
272,
372,
3378,
421,
199,
533,
653,
1981,
6282,
2028,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1101,
63,
505,
304,
267,
291,
14,
1122,
63,
888,
8,
888,
63,
505,
9,
339,
347,
2198,
63,
888,
8,
277,
12,
1101,
63,
505,
304,
267,
1475,
63,
1419,
275,
295,
14,
954,
18523,
627,
17140,
2447,
31,
627,
11918,
1867,
71,
28,
17,
7166,
1101,
63,
505,
12,
3285,
29,
264,
14,
45,
9,
267,
1006,
63,
1419,
275,
8773,
8,
264,
14,
6452,
18353,
62,
4735,
20262,
78,
30679,
87,
13,
23849,
9000,
627,
19276,
4186,
1475,
63,
1419,
12,
3285,
29,
264,
14,
45,
430,
267,
367,
790,
12,
574,
315,
1006,
63,
1419,
14,
1744,
837,
953,
340,
574,
508,
10812,
355,
870,
4331,
984,
14,
3083,
12,
298,
547,
26,
6006,
365,
282,
790,
543,
2701,
574,
26,
8352,
908,
8,
498,
9,
355,
4458,
8,
17,
9,
953,
1006,
63,
1419,
59,
498,
61,
275,
574,
14,
908,
3682,
452,
63,
1419,
9,
267,
291,
14,
1419,
275,
1006,
63,
1419,
339,
347,
664,
8,
277,
12,
790,
304,
267,
372,
291,
14,
1419,
59,
498,
61,
4388,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1798,
275,
7534,
14,
10730,
342,
272,
1798,
14,
525,
63,
2094,
6096,
67,
401,
4320,
888,
401,
1720,
628,
1918,
1101,
570,
402,
653,
1981,
6282,
2685,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
340,
822,
8,
1274,
14,
3020,
9,
508,
413
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
18,
199,
199,
646,
7534,
199,
646,
295,
199,
646,
747,
199,
646,
984,
199,
504,
5055,
492,
8773,
199,
199,
318,
1218,
63,
4443,
63,
460,
63,
1080,
8,
888,
304,
272,
1449,
267,
2790,
314,
3659,
436,
1478,
367,
653,
1981,
6282,
14,
267,
413,
14,
21973,
292,
63,
1049,
82,
45,
267,
499,
14,
2900,
2891,
14,
667,
267,
650,
14,
699,
758,
1478,
267,
841,
14,
3091,
2392,
5743,
1478,
272,
1449,
339,
1101,
63,
1419,
275,
1101,
14,
1419,
14,
1574,
342,
272,
3378,
63,
1045,
63,
589,
275,
3378,
63,
1760,
8,
888,
63,
1419,
9,
339,
3378,
63,
1045,
63,
589,
480,
8215,
446,
80,
469,
46,
1981,
6282,
63,
1121,
63,
694,
15412,
339,
327,
7958,
314,
298,
27600,
63,
1049,
82,
45,
2,
272,
3378,
63,
1045,
63,
589,
480,
7878,
283,
10194,
45,
7,
690,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
513,
531,
272,
3378,
63,
1045,
63,
589,
480,
3385,
469,
5083,
63,
27776,
93,
1204,
469,
11205,
2204,
63,
1393,
93,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
513,
413,
690,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
667,
531,
272,
3378,
63,
1045,
63,
589,
480,
3385,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
667,
1204,
542,
68,
283,
17,
68,
7,
690,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
3610,
531,
272,
3378,
63,
1045,
63,
589,
480,
2993,
446,
78,
413,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
667,
690,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
1213,
531,
272,
3378,
63,
1045,
63,
589,
480,
3385,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
1213,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
3610,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
3610,
690,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
6875,
1049,
82,
45,
14,
667,
531,
339,
327,
7958,
314,
298,
2422,
2891,
14,
667,
2,
272,
3378,
63,
1045,
63,
589,
480,
3385,
469,
5083,
63,
27776,
93,
1204,
20595,
14452,
3524,
1204,
542,
68,
446,
82,
283,
83,
3133,
7059,
1622,
10,
680,
15870,
1103,
17,
15,
71,
7,
1204,
20595,
446,
86,
283,
10194,
45,
7,
690,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
2865,
63,
10194,
45,
14,
513,
531,
272,
3378,
63,
1045,
63,
589,
480,
3385,
469,
5083,
63,
27776,
93,
1204,
469,
11205,
2204,
63,
1393,
93,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
2865,
63,
10194,
45,
14,
513,
413,
690,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
1121,
63,
2865,
63,
10194,
45,
14,
667,
531,
272,
3378,
63,
1045,
63,
589,
480,
3385,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
1121,
63,
2865,
63,
10194,
45,
14,
667,
469,
919,
15859,
63,
1523,
63,
27800,
93,
469,
6066,
67,
25179,
63,
27800,
93,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
6875,
1049,
82,
45,
14,
667,
690,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
2422,
2891,
14,
667,
531,
339,
327,
7958,
314,
1478,
367,
330,
758,
272,
3378,
63,
1045,
63,
589,
13076,
66,
758,
63,
1393,
93,
1478,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
2422,
2891,
14,
667,
531,
2286,
327,
7958,
314,
1478,
367,
949,
2392,
5743,
272,
3378,
63,
1045,
63,
589,
13076,
889,
2392,
1080,
63,
1393,
93,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
2422,
2891,
14,
31818,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
2422,
2891,
14,
667,
531,
339,
327,
5852,
3529,
1584,
272,
3378,
63,
1045,
63,
589,
480,
5682,
446,
70,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
513,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
667,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
3610,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
10194,
45,
14,
1213,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
2865,
63,
10194,
45,
14,
513,
469,
46,
1981,
6282,
63,
1121,
63,
694,
5995,
1121,
63,
2865,
63,
10194,
45,
14,
667,
531,
421,
199,
318,
3378,
63,
1760,
8,
589,
304,
272,
347,
3378,
8,
1760,
63,
495,
304,
267,
747,
14,
2253,
8,
1760,
63,
495,
14,
908,
3682,
589,
430,
272,
372,
3378,
421,
199,
533,
653,
1981,
6282,
2028,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1101,
63,
505,
304,
267,
291,
14,
1122,
63,
888,
8,
888,
63,
505,
9,
339,
347,
2198,
63,
888,
8,
277,
12,
1101,
63,
505,
304,
267,
1475,
63,
1419,
275,
295,
14,
954,
18523,
627,
17140,
2447,
31,
627,
11918,
1867,
71,
28,
17,
7166,
1101,
63,
505,
12,
3285,
29,
264,
14,
45,
9,
267,
1006,
63,
1419,
275,
8773,
8,
264,
14,
6452,
18353,
62,
4735,
20262,
78,
30679,
87,
13,
23849,
9000,
627,
19276,
4186,
1475,
63,
1419,
12,
3285,
29,
264,
14,
45,
430,
267,
367,
790,
12,
574,
315,
1006,
63,
1419,
14,
1744,
837,
953,
340,
574,
508,
10812,
355,
870,
4331,
984,
14,
3083,
12,
298,
547,
26,
6006,
365,
282,
790,
543,
2701,
574,
26,
8352,
908,
8,
498,
9,
355,
4458,
8,
17,
9,
953,
1006,
63,
1419,
59,
498,
61,
275,
574,
14,
908,
3682,
452,
63,
1419,
9,
267,
291,
14,
1419,
275,
1006,
63,
1419,
339,
347,
664,
8,
277,
12,
790,
304,
267,
372,
291,
14,
1419,
59,
498,
61,
4388,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1798,
275,
7534,
14,
10730,
342,
272,
1798,
14,
525,
63,
2094,
6096,
67,
401,
4320,
888,
401,
1720,
628,
1918,
1101,
570,
402,
653,
1981,
6282,
2685,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
340,
822,
8,
1274,
14,
3020,
9,
508,
413,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nilearn/nilearn_sandbox
|
examples/rpbi/plot_localizer_rpbi.py
|
1
|
4435
|
"""
Massively univariate analysis of a computation task from the Localizer dataset
==============================================================================
A permuted Ordinary Least Squares algorithm is run at each voxel in
order to determine which voxels are specifically active when a healthy subject
performs a computation task as opposed to a sentence reading task.
Randomized Parcellation Based Inference [1] is also used so as to illustrate
that it conveys more sensitivity.
"""
# Author: Virgile Fritsch, <virgile.fritsch@inria.fr>, Mar. 2014
import numpy as np
from nilearn import datasets
from scipy import linalg
from nilearn.input_data import NiftiMasker
from nilearn.mass_univariate import permuted_ols
from nilearn_sandbox.mass_univariate.rpbi import randomized_parcellation_based_inference
### Load Localizer motor contrast #############################################
n_samples = 20
# localizer_dataset = datasets.fetch_localizer_calculation_task(
# n_subjects=n_samples)
localizer_dataset = datasets.fetch_localizer_contrasts(
["calculation vs sentences"],
n_subjects=n_samples)
### Mask data #################################################################
nifti_masker = NiftiMasker(
memory='nilearn_cache', memory_level=1) # cache options
fmri_masked = nifti_masker.fit_transform(localizer_dataset.cmaps)
### Perform massively univariate analysis with permuted OLS ###################
tested_var = np.ones((n_samples, 1), dtype=float) # intercept
neg_log_pvals, all_scores, h0 = permuted_ols(
tested_var, fmri_masked, model_intercept=False,
n_perm=5000, # 5,000 for the sake of time. 10,000 is recommended
two_sided_test=False, # RPBI does not perform a two-sided test
n_jobs=1) # can be changed to use more CPUs
neg_log_pvals_unmasked = nifti_masker.inverse_transform(
np.ravel(neg_log_pvals))
### Randomized Parcellation Based Inference ###################################
neg_log_pvals_rpbi, _, _ = randomized_parcellation_based_inference(
tested_var, fmri_masked,
np.asarray(nifti_masker.mask_img_.get_data()).astype(bool),
n_parcellations=30, # 30 for the sake of time, 100 is recommended
n_parcels=1000,
threshold='auto',
n_perm=5000, # 5,000 for the sake of time. 10,000 is recommended
random_state=0, memory='nilearn_cache', n_jobs=1, verbose=True)
neg_log_pvals_rpbi_unmasked = nifti_masker.inverse_transform(
neg_log_pvals_rpbi)
### Visualization #############################################################
import matplotlib.pyplot as plt
from nilearn.plotting import plot_stat_map
# Here, we should use a structural image as a background, when available.
# Various plotting parameters
z_slice = 39 # plotted slice
from nilearn.image.resampling import coord_transform
affine = neg_log_pvals_unmasked.get_affine()
_, _, k_slice = coord_transform(0, 0, z_slice,
linalg.inv(affine))
k_slice = round(k_slice)
threshold = - np.log10(0.1) # 10% corrected
vmax = min(np.amax(neg_log_pvals),
np.amax(neg_log_pvals_rpbi))
# Plot permutation p-values map
fig = plt.figure(figsize=(5, 7), facecolor='k')
display = plot_stat_map(neg_log_pvals_unmasked,
threshold=threshold, cmap=plt.cm.autumn,
display_mode='z', cut_coords=[z_slice],
figure=fig, vmax=vmax, black_bg=True)
neg_log_pvals_data = neg_log_pvals_unmasked.get_data()
neg_log_pvals_slice_data = \
neg_log_pvals_data[..., k_slice]
n_detections = (neg_log_pvals_slice_data > threshold).sum()
title = ('Negative $\log_{10}$ p-values'
'\n(Non-parametric + '
'\nmax-type correction)'
'\n%d detections') % n_detections
display.title(title, y=1.2)
# Plot RPBI p-values map
fig = plt.figure(figsize=(5, 7), facecolor='k')
display = plot_stat_map(neg_log_pvals_rpbi_unmasked,
threshold=threshold, cmap=plt.cm.autumn,
display_mode='z', cut_coords=[z_slice],
figure=fig, vmax=vmax, black_bg=True)
neg_log_pvals_rpbi_data = \
neg_log_pvals_rpbi_unmasked.get_data()
neg_log_pvals_rpbi_slice_data = \
neg_log_pvals_rpbi_data[..., k_slice]
n_detections = (neg_log_pvals_rpbi_slice_data > threshold).sum()
title = ('Negative $\log_{10}$ p-values' + '\n(RPBI)'
'\n%d detections') % n_detections
display.title(title, y=1.2)
plt.show()
|
bsd-3-clause
|
[
624,
199,
45,
2608,
5636,
17225,
18449,
11284,
402,
282,
14009,
2120,
687,
314,
10111,
1793,
4789,
199,
5695,
17224,
199,
199,
33,
10869,
4241,
4236,
68,
5354,
7005,
1810,
428,
392,
11044,
5563,
365,
1255,
737,
1924,
14164,
31418,
315,
199,
1648,
370,
6705,
1314,
14164,
88,
18099,
787,
22543,
4702,
1380,
282,
13822,
89,
5420,
199,
529,
3351,
282,
14009,
2120,
465,
25068,
370,
282,
14537,
7664,
2120,
14,
199,
199,
3883,
1759,
2235,
6067,
2212,
21311,
1010,
1769,
359,
17,
61,
365,
2597,
1202,
880,
465,
370,
22907,
11409,
323,
199,
9099,
652,
406,
432,
588,
1655,
4334,
20635,
14,
199,
199,
624,
199,
3,
6529,
26,
812,
723,
71,
441,
31712,
1086,
335,
12,
665,
1042,
71,
441,
14,
25876,
1086,
335,
32,
262,
23714,
14,
4391,
6244,
16794,
14,
6927,
199,
646,
2680,
465,
980,
199,
504,
302,
441,
1060,
492,
13148,
199,
504,
7026,
492,
16727,
199,
504,
302,
441,
1060,
14,
1210,
63,
576,
492,
653,
692,
280,
5144,
281,
199,
504,
302,
441,
1060,
14,
11535,
63,
324,
23225,
492,
10869,
4241,
63,
1446,
199,
504,
302,
441,
1060,
63,
16647,
14,
11535,
63,
324,
23225,
14,
82,
3317,
73,
492,
2196,
1759,
63,
462,
6067,
2212,
63,
6788,
63,
20580,
199,
199,
5680,
7190,
10111,
1793,
28496,
30347,
26316,
8776,
199,
78,
63,
3356,
275,
3388,
199,
3,
2257,
1793,
63,
5214,
275,
13148,
14,
3535,
63,
1832,
1793,
63,
31458,
63,
1765,
8,
199,
3,
258,
302,
63,
25660,
29,
78,
63,
3356,
9,
199,
1832,
1793,
63,
5214,
275,
13148,
14,
3535,
63,
1832,
1793,
63,
17926,
10329,
8,
272,
2097,
31458,
8118,
24256,
2255,
272,
302,
63,
25660,
29,
78,
63,
3356,
9,
199,
199,
5680,
17581,
666,
15779,
3,
199,
78,
692,
280,
63,
2629,
281,
275,
653,
692,
280,
5144,
281,
8,
272,
4402,
534,
78,
441,
1060,
63,
1637,
297,
4402,
63,
1896,
29,
17,
9,
221,
327,
2581,
1511,
199,
10886,
322,
63,
11018,
275,
302,
692,
280,
63,
2629,
281,
14,
3269,
63,
4711,
8,
1832,
1793,
63,
5214,
14,
67,
8919,
9,
199,
199,
5680,
14795,
333,
2608,
5636,
17225,
18449,
11284,
543,
10869,
4241,
593,
5296,
21905,
5680,
199,
10453,
63,
1391,
275,
980,
14,
4548,
1332,
78,
63,
3356,
12,
413,
395,
2152,
29,
1609,
9,
221,
327,
13926,
199,
8705,
63,
793,
63,
80,
3643,
12,
1006,
63,
7107,
12,
394,
16,
275,
10869,
4241,
63,
1446,
8,
272,
12470,
63,
1391,
12,
20831,
322,
63,
11018,
12,
1402,
63,
10863,
29,
797,
12,
272,
302,
63,
8220,
29,
13128,
12,
221,
327,
959,
12,
1493,
367,
314,
308,
1728,
402,
900,
14,
1616,
12,
1493,
365,
14318,
272,
2877,
63,
31851,
63,
396,
29,
797,
12,
221,
327,
820,
13167,
41,
1630,
440,
5147,
282,
2877,
13,
31851,
511,
272,
302,
63,
6920,
29,
17,
9,
221,
327,
883,
506,
2896,
370,
675,
1655,
28504,
199,
8705,
63,
793,
63,
80,
3643,
63,
324,
11018,
275,
302,
692,
280,
63,
2629,
281,
14,
11668,
63,
4711,
8,
272,
980,
14,
11186,
8,
8705,
63,
793,
63,
80,
3643,
430,
199,
199,
5680,
9571,
1759,
2235,
6067,
2212,
21311,
1010,
1769,
10371,
5680,
199,
8705,
63,
793,
63,
80,
3643,
63,
82,
3317,
73,
12,
5501,
485,
275,
2196,
1759,
63,
462,
6067,
2212,
63,
6788,
63,
20580,
8,
272,
12470,
63,
1391,
12,
20831,
322,
63,
11018,
12,
272,
980,
14,
8748,
8,
78,
692,
280,
63,
2629,
281,
14,
2629,
63,
4060,
3754,
362,
63,
576,
8801,
6041,
8,
2245,
395,
272,
302,
63,
462,
6067,
6011,
29,
1216,
12,
221,
327,
4233,
367,
314,
308,
1728,
402,
900,
12,
2948,
365,
14318,
272,
302,
63,
462,
301,
478,
29,
5279,
12,
272,
8765,
534,
2495,
297,
272,
302,
63,
8220,
29,
13128,
12,
221,
327,
959,
12,
1493,
367,
314,
308,
1728,
402,
900,
14,
1616,
12,
1493,
365,
14318,
272,
2196,
63,
929,
29,
16,
12,
4402,
534,
78,
441,
1060,
63,
1637,
297,
302,
63,
6920,
29,
17,
12,
3376,
29,
549,
9,
199,
8705,
63,
793,
63,
80,
3643,
63,
82,
3317,
73,
63,
324,
11018,
275,
302,
692,
280,
63,
2629,
281,
14,
11668,
63,
4711,
8,
272,
14158,
63,
793,
63,
80,
3643,
63,
82,
3317,
73,
9,
199,
199,
5680,
14702,
2072,
24515,
8776,
199,
646,
8027,
14,
13563,
465,
4488,
199,
504,
302,
441,
1060,
14,
2798,
1337,
492,
5137,
63,
3736,
63,
1130,
199,
199,
3,
11842,
12,
781,
1077,
675,
282,
2702,
4889,
1834,
465,
282,
8020,
12,
1380,
2808,
14,
199,
199,
3,
21107,
1785,
25174,
2633,
199,
90,
63,
5224,
275,
10551,
221,
327,
5137,
471,
6014,
199,
504,
302,
441,
1060,
14,
1569,
14,
470,
23144,
492,
11021,
63,
4711,
199,
9181,
1132,
275,
14158,
63,
793,
63,
80,
3643,
63,
324,
11018,
14,
362,
63,
9181,
1132,
342,
199,
3131,
5501,
1022,
63,
5224,
275,
11021,
63,
4711,
8,
16,
12,
378,
12,
1315,
63,
5224,
12,
1816,
16727,
14,
5350,
8,
9181,
1132,
430,
199,
75,
63,
5224,
275,
6168,
8,
75,
63,
5224,
9,
199,
199,
7227,
275,
446,
980,
14,
793,
709,
8,
16,
14,
17,
9,
221,
327,
1616,
5,
30156,
199,
30609,
275,
1748,
8,
1590,
14,
65,
988,
8,
8705,
63,
793,
63,
80,
3643,
395,
1779,
980,
14,
65,
988,
8,
8705,
63,
793,
63,
80,
3643,
63,
82,
3317,
73,
430,
199,
199,
3,
14794,
22966,
299,
13,
1459,
2341,
199,
592,
275,
4488,
14,
8941,
8,
23899,
2687,
21,
12,
1520,
395,
8870,
2326,
534,
75,
358,
199,
199,
2918,
275,
5137,
63,
3736,
63,
1130,
8,
8705,
63,
793,
63,
80,
3643,
63,
324,
11018,
12,
717,
8765,
29,
7227,
12,
14920,
29,
6003,
14,
4400,
14,
6898,
1307,
12,
717,
2929,
63,
632,
534,
90,
297,
10415,
63,
8032,
1524,
90,
63,
5224,
467,
717,
9658,
29,
592,
12,
23349,
29,
30609,
12,
12136,
63,
6856,
29,
549,
9,
199,
199,
8705,
63,
793,
63,
80,
3643,
63,
576,
275,
14158,
63,
793,
63,
80,
3643,
63,
324,
11018,
14,
362,
63,
576,
342,
199,
8705
] |
[
199,
45,
2608,
5636,
17225,
18449,
11284,
402,
282,
14009,
2120,
687,
314,
10111,
1793,
4789,
199,
5695,
17224,
199,
199,
33,
10869,
4241,
4236,
68,
5354,
7005,
1810,
428,
392,
11044,
5563,
365,
1255,
737,
1924,
14164,
31418,
315,
199,
1648,
370,
6705,
1314,
14164,
88,
18099,
787,
22543,
4702,
1380,
282,
13822,
89,
5420,
199,
529,
3351,
282,
14009,
2120,
465,
25068,
370,
282,
14537,
7664,
2120,
14,
199,
199,
3883,
1759,
2235,
6067,
2212,
21311,
1010,
1769,
359,
17,
61,
365,
2597,
1202,
880,
465,
370,
22907,
11409,
323,
199,
9099,
652,
406,
432,
588,
1655,
4334,
20635,
14,
199,
199,
624,
199,
3,
6529,
26,
812,
723,
71,
441,
31712,
1086,
335,
12,
665,
1042,
71,
441,
14,
25876,
1086,
335,
32,
262,
23714,
14,
4391,
6244,
16794,
14,
6927,
199,
646,
2680,
465,
980,
199,
504,
302,
441,
1060,
492,
13148,
199,
504,
7026,
492,
16727,
199,
504,
302,
441,
1060,
14,
1210,
63,
576,
492,
653,
692,
280,
5144,
281,
199,
504,
302,
441,
1060,
14,
11535,
63,
324,
23225,
492,
10869,
4241,
63,
1446,
199,
504,
302,
441,
1060,
63,
16647,
14,
11535,
63,
324,
23225,
14,
82,
3317,
73,
492,
2196,
1759,
63,
462,
6067,
2212,
63,
6788,
63,
20580,
199,
199,
5680,
7190,
10111,
1793,
28496,
30347,
26316,
8776,
199,
78,
63,
3356,
275,
3388,
199,
3,
2257,
1793,
63,
5214,
275,
13148,
14,
3535,
63,
1832,
1793,
63,
31458,
63,
1765,
8,
199,
3,
258,
302,
63,
25660,
29,
78,
63,
3356,
9,
199,
1832,
1793,
63,
5214,
275,
13148,
14,
3535,
63,
1832,
1793,
63,
17926,
10329,
8,
272,
2097,
31458,
8118,
24256,
2255,
272,
302,
63,
25660,
29,
78,
63,
3356,
9,
199,
199,
5680,
17581,
666,
15779,
3,
199,
78,
692,
280,
63,
2629,
281,
275,
653,
692,
280,
5144,
281,
8,
272,
4402,
534,
78,
441,
1060,
63,
1637,
297,
4402,
63,
1896,
29,
17,
9,
221,
327,
2581,
1511,
199,
10886,
322,
63,
11018,
275,
302,
692,
280,
63,
2629,
281,
14,
3269,
63,
4711,
8,
1832,
1793,
63,
5214,
14,
67,
8919,
9,
199,
199,
5680,
14795,
333,
2608,
5636,
17225,
18449,
11284,
543,
10869,
4241,
593,
5296,
21905,
5680,
199,
10453,
63,
1391,
275,
980,
14,
4548,
1332,
78,
63,
3356,
12,
413,
395,
2152,
29,
1609,
9,
221,
327,
13926,
199,
8705,
63,
793,
63,
80,
3643,
12,
1006,
63,
7107,
12,
394,
16,
275,
10869,
4241,
63,
1446,
8,
272,
12470,
63,
1391,
12,
20831,
322,
63,
11018,
12,
1402,
63,
10863,
29,
797,
12,
272,
302,
63,
8220,
29,
13128,
12,
221,
327,
959,
12,
1493,
367,
314,
308,
1728,
402,
900,
14,
1616,
12,
1493,
365,
14318,
272,
2877,
63,
31851,
63,
396,
29,
797,
12,
221,
327,
820,
13167,
41,
1630,
440,
5147,
282,
2877,
13,
31851,
511,
272,
302,
63,
6920,
29,
17,
9,
221,
327,
883,
506,
2896,
370,
675,
1655,
28504,
199,
8705,
63,
793,
63,
80,
3643,
63,
324,
11018,
275,
302,
692,
280,
63,
2629,
281,
14,
11668,
63,
4711,
8,
272,
980,
14,
11186,
8,
8705,
63,
793,
63,
80,
3643,
430,
199,
199,
5680,
9571,
1759,
2235,
6067,
2212,
21311,
1010,
1769,
10371,
5680,
199,
8705,
63,
793,
63,
80,
3643,
63,
82,
3317,
73,
12,
5501,
485,
275,
2196,
1759,
63,
462,
6067,
2212,
63,
6788,
63,
20580,
8,
272,
12470,
63,
1391,
12,
20831,
322,
63,
11018,
12,
272,
980,
14,
8748,
8,
78,
692,
280,
63,
2629,
281,
14,
2629,
63,
4060,
3754,
362,
63,
576,
8801,
6041,
8,
2245,
395,
272,
302,
63,
462,
6067,
6011,
29,
1216,
12,
221,
327,
4233,
367,
314,
308,
1728,
402,
900,
12,
2948,
365,
14318,
272,
302,
63,
462,
301,
478,
29,
5279,
12,
272,
8765,
534,
2495,
297,
272,
302,
63,
8220,
29,
13128,
12,
221,
327,
959,
12,
1493,
367,
314,
308,
1728,
402,
900,
14,
1616,
12,
1493,
365,
14318,
272,
2196,
63,
929,
29,
16,
12,
4402,
534,
78,
441,
1060,
63,
1637,
297,
302,
63,
6920,
29,
17,
12,
3376,
29,
549,
9,
199,
8705,
63,
793,
63,
80,
3643,
63,
82,
3317,
73,
63,
324,
11018,
275,
302,
692,
280,
63,
2629,
281,
14,
11668,
63,
4711,
8,
272,
14158,
63,
793,
63,
80,
3643,
63,
82,
3317,
73,
9,
199,
199,
5680,
14702,
2072,
24515,
8776,
199,
646,
8027,
14,
13563,
465,
4488,
199,
504,
302,
441,
1060,
14,
2798,
1337,
492,
5137,
63,
3736,
63,
1130,
199,
199,
3,
11842,
12,
781,
1077,
675,
282,
2702,
4889,
1834,
465,
282,
8020,
12,
1380,
2808,
14,
199,
199,
3,
21107,
1785,
25174,
2633,
199,
90,
63,
5224,
275,
10551,
221,
327,
5137,
471,
6014,
199,
504,
302,
441,
1060,
14,
1569,
14,
470,
23144,
492,
11021,
63,
4711,
199,
9181,
1132,
275,
14158,
63,
793,
63,
80,
3643,
63,
324,
11018,
14,
362,
63,
9181,
1132,
342,
199,
3131,
5501,
1022,
63,
5224,
275,
11021,
63,
4711,
8,
16,
12,
378,
12,
1315,
63,
5224,
12,
1816,
16727,
14,
5350,
8,
9181,
1132,
430,
199,
75,
63,
5224,
275,
6168,
8,
75,
63,
5224,
9,
199,
199,
7227,
275,
446,
980,
14,
793,
709,
8,
16,
14,
17,
9,
221,
327,
1616,
5,
30156,
199,
30609,
275,
1748,
8,
1590,
14,
65,
988,
8,
8705,
63,
793,
63,
80,
3643,
395,
1779,
980,
14,
65,
988,
8,
8705,
63,
793,
63,
80,
3643,
63,
82,
3317,
73,
430,
199,
199,
3,
14794,
22966,
299,
13,
1459,
2341,
199,
592,
275,
4488,
14,
8941,
8,
23899,
2687,
21,
12,
1520,
395,
8870,
2326,
534,
75,
358,
199,
199,
2918,
275,
5137,
63,
3736,
63,
1130,
8,
8705,
63,
793,
63,
80,
3643,
63,
324,
11018,
12,
717,
8765,
29,
7227,
12,
14920,
29,
6003,
14,
4400,
14,
6898,
1307,
12,
717,
2929,
63,
632,
534,
90,
297,
10415,
63,
8032,
1524,
90,
63,
5224,
467,
717,
9658,
29,
592,
12,
23349,
29,
30609,
12,
12136,
63,
6856,
29,
549,
9,
199,
199,
8705,
63,
793,
63,
80,
3643,
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
] |
hyundukkim/WATT
|
tools/WebIDLBinder/third_party/ply/test/lex_optimize3.py
|
164
|
1062
|
# -----------------------------------------------------------------------------
# lex_optimize3.py
#
# Writes table in a subdirectory structure.
# -----------------------------------------------------------------------------
import sys
if ".." not in sys.path: sys.path.insert(0,"..")
import ply.lex as lex
tokens = (
'NAME','NUMBER',
'PLUS','MINUS','TIMES','DIVIDE','EQUALS',
'LPAREN','RPAREN',
)
# Tokens
t_PLUS = r'\+'
t_MINUS = r'-'
t_TIMES = r'\*'
t_DIVIDE = r'/'
t_EQUALS = r'='
t_LPAREN = r'\('
t_RPAREN = r'\)'
t_NAME = r'[a-zA-Z_][a-zA-Z0-9_]*'
def t_NUMBER(t):
r'\d+'
try:
t.value = int(t.value)
except ValueError:
print("Integer value too large %s" % t.value)
t.value = 0
return t
t_ignore = " \t"
def t_newline(t):
r'\n+'
t.lineno += t.value.count("\n")
def t_error(t):
print("Illegal character '%s'" % t.value[0])
t.lexer.skip(1)
# Build the lexer
lex.lex(optimize=1,lextab="lexdir.sub.calctab",outputdir="lexdir/sub")
lex.runmain(data="3+4")
|
apache-2.0
|
[
3,
13722,
199,
3,
7103,
63,
13416,
19,
14,
647,
199,
3,
199,
3,
30753,
1817,
315,
282,
25094,
5523,
14,
199,
3,
13722,
199,
646,
984,
199,
199,
692,
21777,
2,
440,
315,
984,
14,
515,
26,
984,
14,
515,
14,
3176,
8,
16,
4589,
703,
531,
199,
646,
299,
590,
14,
3113,
465,
7103,
199,
199,
4504,
275,
334,
272,
283,
2339,
1673,
9190,
297,
272,
283,
27280,
1673,
18004,
1673,
11342,
654,
1673,
1914,
5437,
37,
1673,
16352,
51,
297,
272,
283,
44,
22169,
1673,
50,
22169,
297,
272,
776,
199,
199,
3,
8767,
83,
199,
199,
84,
63,
27280,
259,
275,
519,
1154,
4786,
199,
84,
63,
18004,
257,
275,
519,
12418,
7,
199,
84,
63,
11342,
654,
257,
275,
519,
1154,
10223,
199,
84,
63,
1914,
5437,
37,
221,
275,
519,
29957,
199,
84,
63,
16352,
51,
221,
275,
519,
7,
534,
199,
84,
63,
44,
22169,
221,
275,
519,
1154,
360,
199,
84,
63,
50,
22169,
221,
275,
519,
1154,
3171,
199,
84,
63,
2339,
259,
275,
519,
3894,
65,
13,
6353,
13,
58,
17900,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
7,
199,
199,
318,
307,
63,
9190,
8,
84,
304,
272,
519,
1154,
68,
4786,
272,
862,
26,
267,
307,
14,
585,
275,
1109,
8,
84,
14,
585,
9,
272,
871,
1722,
26,
267,
870,
480,
2674,
574,
4634,
7031,
450,
83,
2,
450,
307,
14,
585,
9,
267,
307,
14,
585,
275,
378,
272,
372,
307,
199,
199,
84,
63,
4247,
275,
298,
971,
84,
2,
199,
199,
318,
307,
63,
12210,
8,
84,
304,
272,
519,
1154,
78,
4786,
272,
307,
14,
3469,
847,
307,
14,
585,
14,
835,
4582,
78,
531,
1362,
199,
318,
307,
63,
705,
8,
84,
304,
272,
870,
480,
25501,
4528,
1543,
83,
4065,
450,
307,
14,
585,
59,
16,
566,
272,
307,
14,
11729,
14,
2759,
8,
17,
9,
1362,
199,
3,
6516,
314,
10426,
199,
3113,
14,
3113,
8,
13416,
29,
17,
12,
274,
400,
371,
628,
3113,
694,
14,
954,
14,
915,
319,
371,
401,
1199,
694,
628,
3113,
694,
15,
954,
531,
199,
3113,
14,
1065,
973,
8,
576,
628,
19,
11,
20,
531,
6905,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
13722,
199,
3,
7103,
63,
13416,
19,
14,
647,
199,
3,
199,
3,
30753,
1817,
315,
282,
25094,
5523,
14,
199,
3,
13722,
199,
646,
984,
199,
199,
692,
21777,
2,
440,
315,
984,
14,
515,
26,
984,
14,
515,
14,
3176,
8,
16,
4589,
703,
531,
199,
646,
299,
590,
14,
3113,
465,
7103,
199,
199,
4504,
275,
334,
272,
283,
2339,
1673,
9190,
297,
272,
283,
27280,
1673,
18004,
1673,
11342,
654,
1673,
1914,
5437,
37,
1673,
16352,
51,
297,
272,
283,
44,
22169,
1673,
50,
22169,
297,
272,
776,
199,
199,
3,
8767,
83,
199,
199,
84,
63,
27280,
259,
275,
519,
1154,
4786,
199,
84,
63,
18004,
257,
275,
519,
12418,
7,
199,
84,
63,
11342,
654,
257,
275,
519,
1154,
10223,
199,
84,
63,
1914,
5437,
37,
221,
275,
519,
29957,
199,
84,
63,
16352,
51,
221,
275,
519,
7,
534,
199,
84,
63,
44,
22169,
221,
275,
519,
1154,
360,
199,
84,
63,
50,
22169,
221,
275,
519,
1154,
3171,
199,
84,
63,
2339,
259,
275,
519,
3894,
65,
13,
6353,
13,
58,
17900,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
7,
199,
199,
318,
307,
63,
9190,
8,
84,
304,
272,
519,
1154,
68,
4786,
272,
862,
26,
267,
307,
14,
585,
275,
1109,
8,
84,
14,
585,
9,
272,
871,
1722,
26,
267,
870,
480,
2674,
574,
4634,
7031,
450,
83,
2,
450,
307,
14,
585,
9,
267,
307,
14,
585,
275,
378,
272,
372,
307,
199,
199,
84,
63,
4247,
275,
298,
971,
84,
2,
199,
199,
318,
307,
63,
12210,
8,
84,
304,
272,
519,
1154,
78,
4786,
272,
307,
14,
3469,
847,
307,
14,
585,
14,
835,
4582,
78,
531,
1362,
199,
318,
307,
63,
705,
8,
84,
304,
272,
870,
480,
25501,
4528,
1543,
83,
4065,
450,
307,
14,
585,
59,
16,
566,
272,
307,
14,
11729,
14,
2759,
8,
17,
9,
1362,
199,
3,
6516,
314,
10426,
199,
3113,
14,
3113,
8,
13416,
29,
17,
12,
274,
400,
371,
628,
3113,
694,
14,
954,
14,
915,
319,
371,
401,
1199,
694,
628,
3113,
694,
15,
954,
531,
199,
3113,
14,
1065,
973,
8,
576,
628,
19,
11,
20,
531,
6905,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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
] |
luca76/QGIS
|
python/ext-libs/jinja2/bccache.py
|
116
|
11902
|
# -*- coding: utf-8 -*-
"""
jinja2.bccache
~~~~~~~~~~~~~~
This module implements the bytecode cache system Jinja is optionally
using. This is useful if you have very complex template situations and
the compiliation of all those templates slow down your application too
much.
Situations where this is useful are often forking web applications that
are initialized on the first request.
:copyright: (c) 2010 by the Jinja Team.
:license: BSD.
"""
from os import path, listdir
import os
import sys
import errno
import marshal
import tempfile
import fnmatch
from hashlib import sha1
from jinja2.utils import open_if_exists
from jinja2._compat import BytesIO, pickle, PY2, text_type
# marshal works better on 3.x, one hack less required
if not PY2:
marshal_dump = marshal.dump
marshal_load = marshal.load
else:
def marshal_dump(code, f):
if isinstance(f, file):
marshal.dump(code, f)
else:
f.write(marshal.dumps(code))
def marshal_load(f):
if isinstance(f, file):
return marshal.load(f)
return marshal.loads(f.read())
bc_version = 2
# magic version used to only change with new jinja versions. With 2.6
# we change this to also take Python version changes into account. The
# reason for this is that Python tends to segfault if fed earlier bytecode
# versions because someone thought it would be a good idea to reuse opcodes
# or make Python incompatible with earlier versions.
bc_magic = 'j2'.encode('ascii') + \
pickle.dumps(bc_version, 2) + \
pickle.dumps((sys.version_info[0] << 24) | sys.version_info[1])
class Bucket(object):
"""Buckets are used to store the bytecode for one template. It's created
and initialized by the bytecode cache and passed to the loading functions.
The buckets get an internal checksum from the cache assigned and use this
to automatically reject outdated cache material. Individual bytecode
cache subclasses don't have to care about cache invalidation.
"""
def __init__(self, environment, key, checksum):
self.environment = environment
self.key = key
self.checksum = checksum
self.reset()
def reset(self):
"""Resets the bucket (unloads the bytecode)."""
self.code = None
def load_bytecode(self, f):
"""Loads bytecode from a file or file like object."""
# make sure the magic header is correct
magic = f.read(len(bc_magic))
if magic != bc_magic:
self.reset()
return
# the source code of the file changed, we need to reload
checksum = pickle.load(f)
if self.checksum != checksum:
self.reset()
return
self.code = marshal_load(f)
def write_bytecode(self, f):
"""Dump the bytecode into the file or file like object passed."""
if self.code is None:
raise TypeError('can\'t write empty bucket')
f.write(bc_magic)
pickle.dump(self.checksum, f, 2)
marshal_dump(self.code, f)
def bytecode_from_string(self, string):
"""Load bytecode from a string."""
self.load_bytecode(BytesIO(string))
def bytecode_to_string(self):
"""Return the bytecode as string."""
out = BytesIO()
self.write_bytecode(out)
return out.getvalue()
class BytecodeCache(object):
"""To implement your own bytecode cache you have to subclass this class
and override :meth:`load_bytecode` and :meth:`dump_bytecode`. Both of
these methods are passed a :class:`~jinja2.bccache.Bucket`.
A very basic bytecode cache that saves the bytecode on the file system::
from os import path
class MyCache(BytecodeCache):
def __init__(self, directory):
self.directory = directory
def load_bytecode(self, bucket):
filename = path.join(self.directory, bucket.key)
if path.exists(filename):
with open(filename, 'rb') as f:
bucket.load_bytecode(f)
def dump_bytecode(self, bucket):
filename = path.join(self.directory, bucket.key)
with open(filename, 'wb') as f:
bucket.write_bytecode(f)
A more advanced version of a filesystem based bytecode cache is part of
Jinja2.
"""
def load_bytecode(self, bucket):
"""Subclasses have to override this method to load bytecode into a
bucket. If they are not able to find code in the cache for the
bucket, it must not do anything.
"""
raise NotImplementedError()
def dump_bytecode(self, bucket):
"""Subclasses have to override this method to write the bytecode
from a bucket back to the cache. If it unable to do so it must not
fail silently but raise an exception.
"""
raise NotImplementedError()
def clear(self):
"""Clears the cache. This method is not used by Jinja2 but should be
implemented to allow applications to clear the bytecode cache used
by a particular environment.
"""
def get_cache_key(self, name, filename=None):
"""Returns the unique hash key for this template name."""
hash = sha1(name.encode('utf-8'))
if filename is not None:
filename = '|' + filename
if isinstance(filename, text_type):
filename = filename.encode('utf-8')
hash.update(filename)
return hash.hexdigest()
def get_source_checksum(self, source):
"""Returns a checksum for the source."""
return sha1(source.encode('utf-8')).hexdigest()
def get_bucket(self, environment, name, filename, source):
"""Return a cache bucket for the given template. All arguments are
mandatory but filename may be `None`.
"""
key = self.get_cache_key(name, filename)
checksum = self.get_source_checksum(source)
bucket = Bucket(environment, key, checksum)
self.load_bytecode(bucket)
return bucket
def set_bucket(self, bucket):
"""Put the bucket into the cache."""
self.dump_bytecode(bucket)
class FileSystemBytecodeCache(BytecodeCache):
"""A bytecode cache that stores bytecode on the filesystem. It accepts
two arguments: The directory where the cache items are stored and a
pattern string that is used to build the filename.
If no directory is specified a default cache directory is selected. On
Windows the user's temp directory is used, on UNIX systems a directory
is created for the user in the system temp directory.
The pattern can be used to have multiple separate caches operate on the
same directory. The default pattern is ``'__jinja2_%s.cache'``. ``%s``
is replaced with the cache key.
>>> bcc = FileSystemBytecodeCache('/tmp/jinja_cache', '%s.cache')
This bytecode cache supports clearing of the cache using the clear method.
"""
def __init__(self, directory=None, pattern='__jinja2_%s.cache'):
if directory is None:
directory = self._get_default_cache_dir()
self.directory = directory
self.pattern = pattern
def _get_default_cache_dir(self):
tmpdir = tempfile.gettempdir()
# On windows the temporary directory is used specific unless
# explicitly forced otherwise. We can just use that.
if os.name == 'n':
return tmpdir
if not hasattr(os, 'getuid'):
raise RuntimeError('Cannot determine safe temp directory. You '
'need to explicitly provide one.')
dirname = '_jinja2-cache-%d' % os.getuid()
actual_dir = os.path.join(tmpdir, dirname)
try:
# 448 == 0700
os.mkdir(actual_dir, 448)
except OSError as e:
if e.errno != errno.EEXIST:
raise
return actual_dir
def _get_cache_filename(self, bucket):
return path.join(self.directory, self.pattern % bucket.key)
def load_bytecode(self, bucket):
f = open_if_exists(self._get_cache_filename(bucket), 'rb')
if f is not None:
try:
bucket.load_bytecode(f)
finally:
f.close()
def dump_bytecode(self, bucket):
f = open(self._get_cache_filename(bucket), 'wb')
try:
bucket.write_bytecode(f)
finally:
f.close()
def clear(self):
# imported lazily here because google app-engine doesn't support
# write access on the file system and the function does not exist
# normally.
from os import remove
files = fnmatch.filter(listdir(self.directory), self.pattern % '*')
for filename in files:
try:
remove(path.join(self.directory, filename))
except OSError:
pass
class MemcachedBytecodeCache(BytecodeCache):
"""This class implements a bytecode cache that uses a memcache cache for
storing the information. It does not enforce a specific memcache library
(tummy's memcache or cmemcache) but will accept any class that provides
the minimal interface required.
Libraries compatible with this class:
- `werkzeug <http://werkzeug.pocoo.org/>`_.contrib.cache
- `python-memcached <http://www.tummy.com/Community/software/python-memcached/>`_
- `cmemcache <http://gijsbert.org/cmemcache/>`_
(Unfortunately the django cache interface is not compatible because it
does not support storing binary data, only unicode. You can however pass
the underlying cache client to the bytecode cache which is available
as `django.core.cache.cache._client`.)
The minimal interface for the client passed to the constructor is this:
.. class:: MinimalClientInterface
.. method:: set(key, value[, timeout])
Stores the bytecode in the cache. `value` is a string and
`timeout` the timeout of the key. If timeout is not provided
a default timeout or no timeout should be assumed, if it's
provided it's an integer with the number of seconds the cache
item should exist.
.. method:: get(key)
Returns the value for the cache key. If the item does not
exist in the cache the return value must be `None`.
The other arguments to the constructor are the prefix for all keys that
is added before the actual cache key and the timeout for the bytecode in
the cache system. We recommend a high (or no) timeout.
This bytecode cache does not support clearing of used items in the cache.
The clear method is a no-operation function.
.. versionadded:: 2.7
Added support for ignoring memcache errors through the
`ignore_memcache_errors` parameter.
"""
def __init__(self, client, prefix='jinja2/bytecode/', timeout=None,
ignore_memcache_errors=True):
self.client = client
self.prefix = prefix
self.timeout = timeout
self.ignore_memcache_errors = ignore_memcache_errors
def load_bytecode(self, bucket):
try:
code = self.client.get(self.prefix + bucket.key)
except Exception:
if not self.ignore_memcache_errors:
raise
code = None
if code is not None:
bucket.bytecode_from_string(code)
def dump_bytecode(self, bucket):
args = (self.prefix + bucket.key, bucket.bytecode_to_string())
if self.timeout is not None:
args += (self.timeout,)
try:
self.client.set(*args)
except Exception:
if not self.ignore_memcache_errors:
raise
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10321,
18,
14,
3776,
1637,
272,
32202,
1714,
339,
961,
859,
9031,
314,
16855,
2581,
2656,
17300,
365,
14190,
272,
1808,
14,
221,
961,
365,
2997,
340,
1265,
1172,
7437,
6114,
1978,
24325,
436,
272,
314,
1013,
1638,
425,
402,
1006,
5204,
7009,
11999,
3224,
2195,
4223,
4634,
272,
8298,
14,
339,
428,
390,
18012,
2382,
642,
365,
2997,
787,
14115,
14926,
316,
3330,
13103,
626,
272,
787,
10038,
641,
314,
1642,
1056,
14,
339,
520,
7307,
26,
334,
67,
9,
7129,
701,
314,
17300,
11682,
14,
272,
520,
1682,
26,
6289,
14,
199,
624,
199,
504,
747,
492,
931,
12,
27483,
199,
646,
747,
199,
646,
984,
199,
646,
7554,
199,
646,
21985,
199,
646,
5549,
199,
646,
15951,
199,
504,
8337,
492,
7793,
17,
199,
504,
10321,
18,
14,
1208,
492,
1551,
63,
692,
63,
2444,
199,
504,
10321,
18,
423,
5819,
492,
11808,
12,
5927,
12,
7843,
18,
12,
1318,
63,
466,
421,
199,
3,
21985,
5419,
8034,
641,
650,
14,
88,
12,
1373,
11176,
6656,
1415,
199,
692,
440,
7843,
18,
26,
272,
21985,
63,
2724,
275,
21985,
14,
2724,
272,
21985,
63,
912,
275,
21985,
14,
912,
199,
2836,
26,
339,
347,
21985,
63,
2724,
8,
600,
12,
289,
304,
267,
340,
1228,
8,
70,
12,
570,
304,
288,
21985,
14,
2724,
8,
600,
12,
289,
9,
267,
587,
26,
288,
289,
14,
952,
8,
18376,
14,
4180,
8,
600,
430,
339,
347,
21985,
63,
912,
8,
70,
304,
267,
340,
1228,
8,
70,
12,
570,
304,
288,
372,
21985,
14,
912,
8,
70,
9,
267,
372,
21985,
14,
3640,
8,
70,
14,
739,
1012,
421,
199,
3776,
63,
1023,
275,
499,
199,
199,
3,
10628,
1015,
1202,
370,
1454,
1570,
543,
892,
10321,
5459,
14,
221,
8777,
499,
14,
22,
199,
3,
781,
1570,
642,
370,
2597,
5452,
2018,
1015,
4493,
1901,
2933,
14,
221,
710,
199,
3,
4499,
367,
642,
365,
626,
2018,
16685,
795,
370,
8812,
1879,
340,
23036,
14119,
16855,
199,
3,
5459,
2952,
17122,
32463,
652,
3955,
506,
282,
6954,
16819,
370,
12598,
27388,
199,
3,
503,
1852,
2018,
18457,
543,
14119,
5459,
14,
199,
3776,
63,
11523,
275,
283,
74,
18,
1370,
2143,
360,
4371,
358,
435,
971,
272,
5927,
14,
4180,
8,
3776,
63,
1023,
12,
499,
9,
435,
971,
272,
5927,
14,
4180,
1332,
1274,
14,
1023,
63,
815,
59,
16,
61,
5213,
5504,
9,
1204,
984,
14,
1023,
63,
815,
59,
17,
566,
421,
199,
533,
31479,
8,
785,
304,
272,
408,
12311,
83,
787,
1202,
370,
3877,
314,
16855,
367,
1373,
1978,
14,
221,
2779,
1159,
2737,
272,
436,
10038,
701,
314,
16855,
2581,
436,
3032,
370,
314,
8697,
3423,
14,
339,
710,
18655,
664,
376,
5007,
9040,
687,
314,
2581,
7943,
436,
675,
642,
272,
370,
5847,
17100,
734,
19074,
2581,
6285,
14,
221,
1010,
15067,
16855,
272,
2581,
9180,
2793,
1133,
1172,
370,
10296,
3595,
2581,
3866,
425,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3734,
12,
790,
12,
9040,
304,
267,
291,
14,
5418,
275,
3734,
267,
291,
14,
498,
275,
790,
267,
291,
14,
8928,
275,
9040,
267,
291,
14,
3958,
342,
339,
347,
5305,
8,
277,
304,
267,
408,
497,
2193,
314,
5315,
334,
324,
3640,
314,
16855,
10477,
267,
291,
14,
600,
275,
488,
339,
347,
2248,
63,
19812,
8,
277,
12,
289,
304,
267,
408,
30777,
16855,
687,
282,
570,
503,
570,
2839,
909,
1041,
267,
327,
1852,
3238,
314,
10628,
1406,
365,
3211,
267,
10628,
275,
289,
14,
739,
8,
552,
8,
3776,
63,
11523,
430,
267,
340,
10628,
1137,
16604,
63,
11523,
26,
288,
291,
14,
3958,
342,
288,
372,
267,
327,
314,
1350,
1233,
402,
314,
570,
2896,
12,
781,
1929,
370,
13101,
267,
9040,
275,
5927,
14,
912,
8,
70,
9,
267,
340,
291,
14,
8928,
1137,
9040,
26,
288,
291,
14,
3958,
342,
288,
372,
267,
291,
14,
600,
275,
21985,
63,
912,
8,
70,
9,
339,
347,
2218,
63,
19812,
8,
277,
12,
289,
304,
267,
408,
11772,
314,
16855,
1901,
314,
570,
503,
570,
2839,
909,
3032,
1041,
267,
340,
291,
14,
600,
365,
488,
26,
288,
746,
3146,
360,
2425,
3985,
84,
2218,
2701,
5315,
358,
267,
289,
14,
952,
8,
3776,
63,
11523,
9,
267,
5927,
14,
2724,
8,
277,
14,
8928,
12,
289,
12,
499,
9,
267,
21985,
63,
2724,
8,
277,
14,
600,
12,
289,
9,
339,
347,
16855,
63,
504,
63,
875,
8,
277,
12,
1059,
304,
267,
408,
6200,
16855,
687,
282,
1059,
1041,
267,
291,
14,
912,
63,
19812,
8,
15466,
8,
875,
430,
339,
347,
16855,
63,
475,
63,
875,
8,
277,
304,
267,
408,
1767,
314,
16855,
465,
1059,
1041,
267,
734,
275,
11808,
342,
267,
291,
14,
952,
63,
19812,
8,
548,
9,
267,
372,
734,
14,
7150,
342,
421,
199,
533,
20301,
600,
4437,
8,
785,
304,
272,
408,
1378,
5669,
2195,
5705,
16855,
2581,
1265,
1172,
370,
5516,
642,
1021,
272,
436,
4278,
520,
5247,
1705,
912,
63,
19812,
64,
436,
520,
5247,
1705,
2724,
63,
19812,
2313,
221,
17650,
402,
272,
3520,
3102,
787,
3032,
282,
520,
533,
6054,
12264,
18,
14,
3776,
1637,
14,
12311,
2313,
339,
437,
7437,
5678,
16855,
2581,
626,
23050,
314,
16855,
641,
314,
570,
2656,
447,
398,
687,
747,
492,
931,
398,
1021,
4932,
4437,
8,
4861,
600,
4437,
304,
953,
347,
636,
826,
721,
277,
12,
2082,
304,
355,
291,
14,
3619,
275,
2082,
953,
347,
2248,
63,
19812,
8,
277,
12,
5315,
304,
355,
1788,
275,
931,
14,
904,
8,
277,
14,
3619,
12,
5315,
14,
498,
9,
355,
340,
931,
14,
2444,
8,
1501,
304,
490,
543,
1551,
8,
1501,
12,
283,
4848,
358,
465,
289,
26,
717,
5315,
14,
912,
63,
19812,
8,
70,
9,
953,
347,
5461,
63,
19812,
8,
277,
12,
5315,
304,
355,
1788,
275,
931,
14,
904,
8,
277,
14,
3619,
12,
5315,
14,
498,
9,
355,
543,
1551,
8,
1501,
12,
283,
6603,
358,
465,
289,
26,
490,
5315,
14,
952,
63,
19812,
8,
70,
9,
339,
437,
1655,
19472,
1015,
402,
282
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10321,
18,
14,
3776,
1637,
272,
32202,
1714,
339,
961,
859,
9031,
314,
16855,
2581,
2656,
17300,
365,
14190,
272,
1808,
14,
221,
961,
365,
2997,
340,
1265,
1172,
7437,
6114,
1978,
24325,
436,
272,
314,
1013,
1638,
425,
402,
1006,
5204,
7009,
11999,
3224,
2195,
4223,
4634,
272,
8298,
14,
339,
428,
390,
18012,
2382,
642,
365,
2997,
787,
14115,
14926,
316,
3330,
13103,
626,
272,
787,
10038,
641,
314,
1642,
1056,
14,
339,
520,
7307,
26,
334,
67,
9,
7129,
701,
314,
17300,
11682,
14,
272,
520,
1682,
26,
6289,
14,
199,
624,
199,
504,
747,
492,
931,
12,
27483,
199,
646,
747,
199,
646,
984,
199,
646,
7554,
199,
646,
21985,
199,
646,
5549,
199,
646,
15951,
199,
504,
8337,
492,
7793,
17,
199,
504,
10321,
18,
14,
1208,
492,
1551,
63,
692,
63,
2444,
199,
504,
10321,
18,
423,
5819,
492,
11808,
12,
5927,
12,
7843,
18,
12,
1318,
63,
466,
421,
199,
3,
21985,
5419,
8034,
641,
650,
14,
88,
12,
1373,
11176,
6656,
1415,
199,
692,
440,
7843,
18,
26,
272,
21985,
63,
2724,
275,
21985,
14,
2724,
272,
21985,
63,
912,
275,
21985,
14,
912,
199,
2836,
26,
339,
347,
21985,
63,
2724,
8,
600,
12,
289,
304,
267,
340,
1228,
8,
70,
12,
570,
304,
288,
21985,
14,
2724,
8,
600,
12,
289,
9,
267,
587,
26,
288,
289,
14,
952,
8,
18376,
14,
4180,
8,
600,
430,
339,
347,
21985,
63,
912,
8,
70,
304,
267,
340,
1228,
8,
70,
12,
570,
304,
288,
372,
21985,
14,
912,
8,
70,
9,
267,
372,
21985,
14,
3640,
8,
70,
14,
739,
1012,
421,
199,
3776,
63,
1023,
275,
499,
199,
199,
3,
10628,
1015,
1202,
370,
1454,
1570,
543,
892,
10321,
5459,
14,
221,
8777,
499,
14,
22,
199,
3,
781,
1570,
642,
370,
2597,
5452,
2018,
1015,
4493,
1901,
2933,
14,
221,
710,
199,
3,
4499,
367,
642,
365,
626,
2018,
16685,
795,
370,
8812,
1879,
340,
23036,
14119,
16855,
199,
3,
5459,
2952,
17122,
32463,
652,
3955,
506,
282,
6954,
16819,
370,
12598,
27388,
199,
3,
503,
1852,
2018,
18457,
543,
14119,
5459,
14,
199,
3776,
63,
11523,
275,
283,
74,
18,
1370,
2143,
360,
4371,
358,
435,
971,
272,
5927,
14,
4180,
8,
3776,
63,
1023,
12,
499,
9,
435,
971,
272,
5927,
14,
4180,
1332,
1274,
14,
1023,
63,
815,
59,
16,
61,
5213,
5504,
9,
1204,
984,
14,
1023,
63,
815,
59,
17,
566,
421,
199,
533,
31479,
8,
785,
304,
272,
408,
12311,
83,
787,
1202,
370,
3877,
314,
16855,
367,
1373,
1978,
14,
221,
2779,
1159,
2737,
272,
436,
10038,
701,
314,
16855,
2581,
436,
3032,
370,
314,
8697,
3423,
14,
339,
710,
18655,
664,
376,
5007,
9040,
687,
314,
2581,
7943,
436,
675,
642,
272,
370,
5847,
17100,
734,
19074,
2581,
6285,
14,
221,
1010,
15067,
16855,
272,
2581,
9180,
2793,
1133,
1172,
370,
10296,
3595,
2581,
3866,
425,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3734,
12,
790,
12,
9040,
304,
267,
291,
14,
5418,
275,
3734,
267,
291,
14,
498,
275,
790,
267,
291,
14,
8928,
275,
9040,
267,
291,
14,
3958,
342,
339,
347,
5305,
8,
277,
304,
267,
408,
497,
2193,
314,
5315,
334,
324,
3640,
314,
16855,
10477,
267,
291,
14,
600,
275,
488,
339,
347,
2248,
63,
19812,
8,
277,
12,
289,
304,
267,
408,
30777,
16855,
687,
282,
570,
503,
570,
2839,
909,
1041,
267,
327,
1852,
3238,
314,
10628,
1406,
365,
3211,
267,
10628,
275,
289,
14,
739,
8,
552,
8,
3776,
63,
11523,
430,
267,
340,
10628,
1137,
16604,
63,
11523,
26,
288,
291,
14,
3958,
342,
288,
372,
267,
327,
314,
1350,
1233,
402,
314,
570,
2896,
12,
781,
1929,
370,
13101,
267,
9040,
275,
5927,
14,
912,
8,
70,
9,
267,
340,
291,
14,
8928,
1137,
9040,
26,
288,
291,
14,
3958,
342,
288,
372,
267,
291,
14,
600,
275,
21985,
63,
912,
8,
70,
9,
339,
347,
2218,
63,
19812,
8,
277,
12,
289,
304,
267,
408,
11772,
314,
16855,
1901,
314,
570,
503,
570,
2839,
909,
3032,
1041,
267,
340,
291,
14,
600,
365,
488,
26,
288,
746,
3146,
360,
2425,
3985,
84,
2218,
2701,
5315,
358,
267,
289,
14,
952,
8,
3776,
63,
11523,
9,
267,
5927,
14,
2724,
8,
277,
14,
8928,
12,
289,
12,
499,
9,
267,
21985,
63,
2724,
8,
277,
14,
600,
12,
289,
9,
339,
347,
16855,
63,
504,
63,
875,
8,
277,
12,
1059,
304,
267,
408,
6200,
16855,
687,
282,
1059,
1041,
267,
291,
14,
912,
63,
19812,
8,
15466,
8,
875,
430,
339,
347,
16855,
63,
475,
63,
875,
8,
277,
304,
267,
408,
1767,
314,
16855,
465,
1059,
1041,
267,
734,
275,
11808,
342,
267,
291,
14,
952,
63,
19812,
8,
548,
9,
267,
372,
734,
14,
7150,
342,
421,
199,
533,
20301,
600,
4437,
8,
785,
304,
272,
408,
1378,
5669,
2195,
5705,
16855,
2581,
1265,
1172,
370,
5516,
642,
1021,
272,
436,
4278,
520,
5247,
1705,
912,
63,
19812,
64,
436,
520,
5247,
1705,
2724,
63,
19812,
2313,
221,
17650,
402,
272,
3520,
3102,
787,
3032,
282,
520,
533,
6054,
12264,
18,
14,
3776,
1637,
14,
12311,
2313,
339,
437,
7437,
5678,
16855,
2581,
626,
23050,
314,
16855,
641,
314,
570,
2656,
447,
398,
687,
747,
492,
931,
398,
1021,
4932,
4437,
8,
4861,
600,
4437,
304,
953,
347,
636,
826,
721,
277,
12,
2082,
304,
355,
291,
14,
3619,
275,
2082,
953,
347,
2248,
63,
19812,
8,
277,
12,
5315,
304,
355,
1788,
275,
931,
14,
904,
8,
277,
14,
3619,
12,
5315,
14,
498,
9,
355,
340,
931,
14,
2444,
8,
1501,
304,
490,
543,
1551,
8,
1501,
12,
283,
4848,
358,
465,
289,
26,
717,
5315,
14,
912,
63,
19812,
8,
70,
9,
953,
347,
5461,
63,
19812,
8,
277,
12,
5315,
304,
355,
1788,
275,
931,
14,
904,
8,
277,
14,
3619,
12,
5315,
14,
498,
9,
355,
543,
1551,
8,
1501,
12,
283,
6603,
358,
465,
289,
26,
490,
5315,
14,
952,
63,
19812,
8,
70,
9,
339,
437,
1655,
19472,
1015,
402,
282,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
shakamunyi/tensorflow
|
tensorflow/contrib/image/__init__.py
|
19
|
2181
|
# 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.
# ==============================================================================
"""Ops for image manipulation.
### API
This module provides functions for image manipulation; currently, chrominance
transformas (including changing saturation and hue) in YIQ space and
projective transforms (including rotation) are supported.
@@angles_to_projective_transforms
@@compose_transforms
@@adjust_yiq_hsv
@@random_yiq_hsv
@@rotate
@@transform
@@translate
@@translations_to_projective_transforms
@@bipartite_match
@@single_image_random_dot_stereograms
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
# pylint: disable=line-too-long
from tensorflow.contrib.image.python.ops.distort_image_ops import adjust_hsv_in_yiq
from tensorflow.contrib.image.python.ops.distort_image_ops import random_hsv_in_yiq
from tensorflow.contrib.image.python.ops.image_ops import angles_to_projective_transforms
from tensorflow.contrib.image.python.ops.image_ops import compose_transforms
from tensorflow.contrib.image.python.ops.image_ops import rotate
from tensorflow.contrib.image.python.ops.image_ops import transform
from tensorflow.contrib.image.python.ops.image_ops import translate
from tensorflow.contrib.image.python.ops.image_ops import translations_to_projective_transforms
from tensorflow.contrib.image.python.ops.single_image_random_dot_stereograms import single_image_random_dot_stereograms
from tensorflow.python.util.all_util import remove_undocumented
# pylint: enable=line-too-long
remove_undocumented(__name__)
|
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,
16452,
367,
1834,
26212,
14,
199,
199,
5680,
3261,
199,
199,
2765,
859,
6571,
3423,
367,
1834,
26212,
27,
5544,
12,
20074,
262,
554,
199,
4711,
305,
334,
15768,
13729,
21845,
1542,
436,
28679,
9,
315,
1488,
23559,
4601,
436,
199,
5468,
6850,
18501,
334,
15768,
13038,
9,
787,
3748,
14,
199,
199,
7492,
13162,
63,
475,
63,
5468,
6850,
63,
15133,
199,
7492,
12607,
63,
15133,
199,
7492,
10917,
63,
89,
9962,
63,
72,
2772,
199,
7492,
2355,
63,
89,
9962,
63,
72,
2772,
199,
7492,
12873,
199,
7492,
4711,
199,
7492,
5275,
199,
7492,
13982,
63,
475,
63,
5468,
6850,
63,
15133,
199,
7492,
4492,
30623,
63,
1431,
199,
7492,
4780,
63,
1569,
63,
2355,
63,
3287,
63,
1597,
13322,
9292,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
3,
4287,
26,
3507,
29,
604,
13,
7354,
13,
2809,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
2686,
361,
63,
1569,
63,
1483,
492,
11311,
63,
72,
2772,
63,
262,
63,
89,
9962,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
2686,
361,
63,
1569,
63,
1483,
492,
2196,
63,
72,
2772,
63,
262,
63,
89,
9962,
199,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
1569,
63,
1483,
492,
22597,
63,
475,
63,
5468,
6850,
63,
15133,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
1569,
63,
1483,
492,
23366,
63,
15133,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
1569,
63,
1483,
492,
20071,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
1569,
63,
1483,
492,
5793,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
1569,
63,
1483,
492,
9028,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
1569,
63,
1483,
492,
15547,
63,
475,
63,
5468,
6850,
63,
15133,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
4780,
63,
1569,
63,
2355,
63,
3287,
63,
1597,
13322,
9292,
492,
2849,
63,
1569,
63,
2355,
63,
3287,
63,
1597,
13322,
9292,
199,
199,
504,
3228,
14,
1548,
14,
1974,
14,
452,
63,
1974,
492,
2813,
63,
30107,
12546,
199,
199,
3,
4287,
26,
4756,
29,
604,
13,
7354,
13,
2809,
199,
199,
2168,
63,
30107,
12546,
3460,
354,
3368,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
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,
16452,
367,
1834,
26212,
14,
199,
199,
5680,
3261,
199,
199,
2765,
859,
6571,
3423,
367,
1834,
26212,
27,
5544,
12,
20074,
262,
554,
199,
4711,
305,
334,
15768,
13729,
21845,
1542,
436,
28679,
9,
315,
1488,
23559,
4601,
436,
199,
5468,
6850,
18501,
334,
15768,
13038,
9,
787,
3748,
14,
199,
199,
7492,
13162,
63,
475,
63,
5468,
6850,
63,
15133,
199,
7492,
12607,
63,
15133,
199,
7492,
10917,
63,
89,
9962,
63,
72,
2772,
199,
7492,
2355,
63,
89,
9962,
63,
72,
2772,
199,
7492,
12873,
199,
7492,
4711,
199,
7492,
5275,
199,
7492,
13982,
63,
475,
63,
5468,
6850,
63,
15133,
199,
7492,
4492,
30623,
63,
1431,
199,
7492,
4780,
63,
1569,
63,
2355,
63,
3287,
63,
1597,
13322,
9292,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
3,
4287,
26,
3507,
29,
604,
13,
7354,
13,
2809,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
2686,
361,
63,
1569,
63,
1483,
492,
11311,
63,
72,
2772,
63,
262,
63,
89,
9962,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
2686,
361,
63,
1569,
63,
1483,
492,
2196,
63,
72,
2772,
63,
262,
63,
89,
9962,
199,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
1569,
63,
1483,
492,
22597,
63,
475,
63,
5468,
6850,
63,
15133,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
1569,
63,
1483,
492,
23366,
63,
15133,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
1569,
63,
1483,
492,
20071,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
1569,
63,
1483,
492,
5793,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
1569,
63,
1483,
492,
9028,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
1569,
63,
1483,
492,
15547,
63,
475,
63,
5468,
6850,
63,
15133,
199,
504,
3228,
14,
2828,
14,
1569,
14,
1548,
14,
1483,
14,
4780,
63,
1569,
63,
2355,
63,
3287,
63,
1597,
13322,
9292,
492,
2849,
63,
1569,
63,
2355,
63,
3287,
63,
1597,
13322,
9292,
199,
199,
504,
3228,
14,
1548,
14,
1974,
14,
452,
63,
1974,
492,
2813,
63,
30107,
12546,
199,
199,
3,
4287,
26,
4756,
29,
604,
13,
7354,
13,
2809,
199,
199,
2168,
63,
30107,
12546,
3460,
354,
3368,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mantidproject/mantid
|
scripts/Diffraction/isis_powder/routines/yaml_sanity.py
|
3
|
2383
|
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
def calibration_file_sanity_check(yaml_dict, file_path):
# Check that the dictionary has data
if not yaml_dict:
raise ValueError("YAML files appears to be empty at:\n" + str(file_path))
# Check that we only have one unbounded range at maximum
unbound_key_exists = _does_single_unbound_key_exist(yaml_dict)
if unbound_key_exists:
_is_unbound_key_sane(yaml_dict)
def _does_single_unbound_key_exist(keys):
seen_unbounded_key = None
for key in keys:
key_string = str(key)
# The user can have multiple ranges but the last one is the only one which can be unbounded
if _is_run_range_key_unbounded(key_string):
if not seen_unbounded_key:
seen_unbounded_key = key_string
else:
raise ValueError("Seen multiple unbounded keys in mapping file: " + key_string + " and "
+ seen_unbounded_key)
return True if seen_unbounded_key else False
def _is_unbound_key_sane(keys):
unbounded_lower_value = 0
largest_seen_bound_value = 0
for key in keys:
split_key = str(key).split('-')
if _is_run_range_key_unbounded(key):
unbounded_lower_value = int(split_key[-2]) # Get the second to last element which is the lower bounds
else:
# This isn't perfect but it avoid us generating loads of lists of ints.
for value in split_key:
if value.isdigit() and int(value) > largest_seen_bound_value:
largest_seen_bound_value = int(value)
if unbounded_lower_value < largest_seen_bound_value:
# We have a bounded value in an unbounded range
raise ValueError("Found a run range in calibration mapping overlaps an unbounded run range."
+ "\nThe value " + str(largest_seen_bound_value) + " was found and is greater than "
+ str(unbounded_lower_value))
def _is_run_range_key_unbounded(key):
split_key = str(key).split('-')
return split_key[-1] == ''
|
gpl-3.0
|
[
3,
603,
4466,
68,
24426,
520,
4178,
921,
5031,
14,
957,
15,
1237,
5700,
1715,
15,
1237,
5700,
199,
3,
199,
3,
1898,
1253,
1574,
27,
14894,
2281,
1311,
820,
85,
728,
18090,
4693,
17589,
16871,
31671,
738,
43,
6129,
12,
199,
3,
257,
653,
7181,
36,
593,
1151,
31196,
20548,
16871,
31671,
12,
31615,
290,
8360,
8408,
5800,
12,
199,
3,
257,
1010,
6329,
337,
7964,
310,
446,
491,
618,
11908,
1253,
17447,
2709,
12,
1010,
25585,
402,
16332,
662,
1372,
4312,
24309,
17378,
12,
27751,
199,
3,
6988,
19596,
446,
844,
446,
23285,
26,
14629,
446,
650,
14,
16,
435,
421,
199,
318,
25365,
63,
493,
63,
21614,
63,
1074,
8,
5963,
63,
807,
12,
570,
63,
515,
304,
272,
327,
2670,
626,
314,
2600,
965,
666,
272,
340,
440,
8864,
63,
807,
26,
267,
746,
1722,
480,
23103,
1584,
11337,
370,
506,
2701,
737,
3427,
78,
2,
435,
620,
8,
493,
63,
515,
430,
339,
327,
2670,
626,
781,
1454,
1172,
1373,
625,
7547,
1425,
737,
5696,
272,
22334,
63,
498,
63,
2444,
275,
485,
9105,
63,
4780,
63,
18124,
63,
498,
63,
4494,
8,
5963,
63,
807,
9,
272,
340,
22334,
63,
498,
63,
2444,
26,
267,
485,
374,
63,
18124,
63,
498,
63,
83,
5865,
8,
5963,
63,
807,
9,
421,
199,
318,
485,
9105,
63,
4780,
63,
18124,
63,
498,
63,
4494,
8,
1612,
304,
272,
6775,
63,
324,
7547,
63,
498,
275,
488,
339,
367,
790,
315,
2883,
26,
267,
790,
63,
875,
275,
620,
8,
498,
9,
267,
327,
710,
922,
883,
1172,
3663,
12271,
1325,
314,
2061,
1373,
365,
314,
1454,
1373,
1314,
883,
506,
625,
7547,
267,
340,
485,
374,
63,
1065,
63,
1842,
63,
498,
63,
324,
7547,
8,
498,
63,
875,
304,
288,
340,
440,
6775,
63,
324,
7547,
63,
498,
26,
355,
6775,
63,
324,
7547,
63,
498,
275,
790,
63,
875,
288,
587,
26,
355,
746,
1722,
480,
1513,
287,
3663,
625,
7547,
2883,
315,
4412,
570,
26,
298,
435,
790,
63,
875,
435,
298,
436,
298,
639,
435,
6775,
63,
324,
7547,
63,
498,
9,
272,
372,
715,
340,
6775,
63,
324,
7547,
63,
498,
587,
756,
421,
199,
318,
485,
374,
63,
18124,
63,
498,
63,
83,
5865,
8,
1612,
304,
272,
625,
7547,
63,
2325,
63,
585,
275,
378,
272,
17451,
63,
8606,
63,
3556,
63,
585,
275,
378,
272,
367,
790,
315,
2883,
26,
267,
3715,
63,
498,
275,
620,
8,
498,
680,
1294,
21950,
267,
340,
485,
374,
63,
1065,
63,
1842,
63,
498,
63,
324,
7547,
8,
498,
304,
288,
625,
7547,
63,
2325,
63,
585,
275,
1109,
8,
1294,
63,
498,
1988,
18,
566,
221,
327,
2372,
314,
3499,
370,
2061,
1819,
1314,
365,
314,
5117,
10461,
267,
587,
26,
288,
327,
961,
5712,
1133,
23668,
1325,
652,
5126,
2739,
12999,
14404,
402,
5548,
402,
14526,
14,
288,
367,
574,
315,
3715,
63,
498,
26,
355,
340,
574,
14,
13896,
342,
436,
1109,
8,
585,
9,
690,
17451,
63,
8606,
63,
3556,
63,
585,
26,
490,
17451,
63,
8606,
63,
3556,
63,
585,
275,
1109,
8,
585,
9,
339,
340,
625,
7547,
63,
2325,
63,
585,
665,
17451,
63,
8606,
63,
3556,
63,
585,
26,
267,
327,
2136,
1172,
282,
1234,
4585,
574,
315,
376,
625,
7547,
1425,
267,
746,
1722,
480,
3601,
282,
1255,
1425,
315,
25365,
4412,
29755,
376,
625,
7547,
1255,
1425,
2122,
586,
435,
1867,
13705,
574,
298,
435,
620,
8,
9828,
3199,
63,
8606,
63,
3556,
63,
585,
9,
435,
298,
1990,
1911,
436,
365,
8932,
2419,
298,
586,
435,
620,
8,
324,
7547,
63,
2325,
63,
585,
430,
421,
199,
318,
485,
374,
63,
1065,
63,
1842,
63,
498,
63,
324,
7547,
8,
498,
304,
272,
3715,
63,
498,
275,
620,
8,
498,
680,
1294,
21950,
272,
372,
3715,
63,
498,
1988,
17,
61,
508,
2125,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
603,
4466,
68,
24426,
520,
4178,
921,
5031,
14,
957,
15,
1237,
5700,
1715,
15,
1237,
5700,
199,
3,
199,
3,
1898,
1253,
1574,
27,
14894,
2281,
1311,
820,
85,
728,
18090,
4693,
17589,
16871,
31671,
738,
43,
6129,
12,
199,
3,
257,
653,
7181,
36,
593,
1151,
31196,
20548,
16871,
31671,
12,
31615,
290,
8360,
8408,
5800,
12,
199,
3,
257,
1010,
6329,
337,
7964,
310,
446,
491,
618,
11908,
1253,
17447,
2709,
12,
1010,
25585,
402,
16332,
662,
1372,
4312,
24309,
17378,
12,
27751,
199,
3,
6988,
19596,
446,
844,
446,
23285,
26,
14629,
446,
650,
14,
16,
435,
421,
199,
318,
25365,
63,
493,
63,
21614,
63,
1074,
8,
5963,
63,
807,
12,
570,
63,
515,
304,
272,
327,
2670,
626,
314,
2600,
965,
666,
272,
340,
440,
8864,
63,
807,
26,
267,
746,
1722,
480,
23103,
1584,
11337,
370,
506,
2701,
737,
3427,
78,
2,
435,
620,
8,
493,
63,
515,
430,
339,
327,
2670,
626,
781,
1454,
1172,
1373,
625,
7547,
1425,
737,
5696,
272,
22334,
63,
498,
63,
2444,
275,
485,
9105,
63,
4780,
63,
18124,
63,
498,
63,
4494,
8,
5963,
63,
807,
9,
272,
340,
22334,
63,
498,
63,
2444,
26,
267,
485,
374,
63,
18124,
63,
498,
63,
83,
5865,
8,
5963,
63,
807,
9,
421,
199,
318,
485,
9105,
63,
4780,
63,
18124,
63,
498,
63,
4494,
8,
1612,
304,
272,
6775,
63,
324,
7547,
63,
498,
275,
488,
339,
367,
790,
315,
2883,
26,
267,
790,
63,
875,
275,
620,
8,
498,
9,
267,
327,
710,
922,
883,
1172,
3663,
12271,
1325,
314,
2061,
1373,
365,
314,
1454,
1373,
1314,
883,
506,
625,
7547,
267,
340,
485,
374,
63,
1065,
63,
1842,
63,
498,
63,
324,
7547,
8,
498,
63,
875,
304,
288,
340,
440,
6775,
63,
324,
7547,
63,
498,
26,
355,
6775,
63,
324,
7547,
63,
498,
275,
790,
63,
875,
288,
587,
26,
355,
746,
1722,
480,
1513,
287,
3663,
625,
7547,
2883,
315,
4412,
570,
26,
298,
435,
790,
63,
875,
435,
298,
436,
298,
639,
435,
6775,
63,
324,
7547,
63,
498,
9,
272,
372,
715,
340,
6775,
63,
324,
7547,
63,
498,
587,
756,
421,
199,
318,
485,
374,
63,
18124,
63,
498,
63,
83,
5865,
8,
1612,
304,
272,
625,
7547,
63,
2325,
63,
585,
275,
378,
272,
17451,
63,
8606,
63,
3556,
63,
585,
275,
378,
272,
367,
790,
315,
2883,
26,
267,
3715,
63,
498,
275,
620,
8,
498,
680,
1294,
21950,
267,
340,
485,
374,
63,
1065,
63,
1842,
63,
498,
63,
324,
7547,
8,
498,
304,
288,
625,
7547,
63,
2325,
63,
585,
275,
1109,
8,
1294,
63,
498,
1988,
18,
566,
221,
327,
2372,
314,
3499,
370,
2061,
1819,
1314,
365,
314,
5117,
10461,
267,
587,
26,
288,
327,
961,
5712,
1133,
23668,
1325,
652,
5126,
2739,
12999,
14404,
402,
5548,
402,
14526,
14,
288,
367,
574,
315,
3715,
63,
498,
26,
355,
340,
574,
14,
13896,
342,
436,
1109,
8,
585,
9,
690,
17451,
63,
8606,
63,
3556,
63,
585,
26,
490,
17451,
63,
8606,
63,
3556,
63,
585,
275,
1109,
8,
585,
9,
339,
340,
625,
7547,
63,
2325,
63,
585,
665,
17451,
63,
8606,
63,
3556,
63,
585,
26,
267,
327,
2136,
1172,
282,
1234,
4585,
574,
315,
376,
625,
7547,
1425,
267,
746,
1722,
480,
3601,
282,
1255,
1425,
315,
25365,
4412,
29755,
376,
625,
7547,
1255,
1425,
2122,
586,
435,
1867,
13705,
574,
298,
435,
620,
8,
9828,
3199,
63,
8606,
63,
3556,
63,
585,
9,
435,
298,
1990,
1911,
436,
365,
8932,
2419,
298,
586,
435,
620,
8,
324,
7547,
63,
2325,
63,
585,
430,
421,
199,
318,
485,
374,
63,
1065,
63,
1842,
63,
498,
63,
324,
7547,
8,
498,
304,
272,
3715,
63,
498,
275,
620,
8,
498,
680,
1294,
21950,
272,
372,
3715,
63,
498,
1988,
17,
61,
508,
2125,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
edxnercel/edx-platform
|
lms/djangoapps/verify_student/migrations/0001_initial.py
|
114
|
7568
|
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model 'SoftwareSecurePhotoVerification'
db.create_table('verify_student_softwaresecurephotoverification', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('status', self.gf('model_utils.fields.StatusField')(default='created', max_length=100, no_check_for_status=True)),
('status_changed', self.gf('model_utils.fields.MonitorField')(default=datetime.datetime.now, monitor=u'status')),
('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
('name', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
('face_image_url', self.gf('django.db.models.fields.URLField')(max_length=255, blank=True)),
('photo_id_image_url', self.gf('django.db.models.fields.URLField')(max_length=255, blank=True)),
('receipt_id', self.gf('django.db.models.fields.CharField')(max_length=255, db_index=True)),
('created_at', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, db_index=True, blank=True)),
('updated_at', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, db_index=True, blank=True)),
('submitted_at', self.gf('django.db.models.fields.DateTimeField')(null=True, db_index=True)),
('reviewing_user', self.gf('django.db.models.fields.related.ForeignKey')(default=None, related_name='photo_verifications_reviewed', null=True, to=orm['auth.User'])),
('reviewing_service', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
('error_msg', self.gf('django.db.models.fields.TextField')(blank=True)),
('error_code', self.gf('django.db.models.fields.CharField')(max_length=50, blank=True)),
('photo_id_key', self.gf('django.db.models.fields.TextField')(max_length=1024)),
))
db.send_create_signal('verify_student', ['SoftwareSecurePhotoVerification'])
def backwards(self, orm):
# Deleting model 'SoftwareSecurePhotoVerification'
db.delete_table('verify_student_softwaresecurephotoverification')
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'verify_student.softwaresecurephotoverification': {
'Meta': {'ordering': "['-created_at']", 'object_name': 'SoftwareSecurePhotoVerification'},
'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}),
'error_code': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}),
'error_msg': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'face_image_url': ('django.db.models.fields.URLField', [], {'max_length': '255', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'photo_id_image_url': ('django.db.models.fields.URLField', [], {'max_length': '255', 'blank': 'True'}),
'photo_id_key': ('django.db.models.fields.TextField', [], {'max_length': '1024'}),
'receipt_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'reviewing_service': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'reviewing_user': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'related_name': "'photo_verifications_reviewed'", 'null': 'True', 'to': "orm['auth.User']"}),
'status': ('model_utils.fields.StatusField', [], {'default': "'created'", 'max_length': '100', u'no_check_for_status': 'True'}),
'status_changed': ('model_utils.fields.MonitorField', [], {'default': 'datetime.datetime.now', u'monitor': "u'status'"}),
'submitted_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'db_index': 'True'}),
'updated_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
}
}
complete_apps = ['verify_student']
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
1402,
283,
10337,
24117,
21258,
22595,
7,
267,
1592,
14,
981,
63,
1224,
360,
4712,
63,
5500,
63,
15619,
7817,
838,
357,
1883,
7313,
297,
334,
288,
661,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
7533,
3327,
63,
498,
29,
549,
1826,
288,
661,
1205,
297,
291,
14,
7102,
360,
1238,
63,
1208,
14,
955,
14,
3694,
792,
7533,
885,
534,
3966,
297,
1390,
63,
1267,
29,
1960,
12,
949,
63,
1074,
63,
509,
63,
1205,
29,
549,
1826,
288,
661,
1205,
63,
2489,
297,
291,
14,
7102,
360,
1238,
63,
1208,
14,
955,
14,
13189,
792,
7533,
885,
29,
2083,
14,
2083,
14,
2131,
12,
8372,
29,
85,
1159,
84,
896,
3855,
288,
661,
751,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
475,
29,
1025,
459,
1178,
14,
1899,
16607,
288,
661,
354,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
2299,
12,
4596,
29,
549,
1826,
288,
661,
1409,
63,
1569,
63,
633,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
17363,
7533,
988,
63,
1267,
29,
2299,
12,
4596,
29,
549,
1826,
288,
661,
13834,
63,
344,
63,
1569,
63,
633,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
17363,
7533,
988,
63,
1267,
29,
2299,
12,
4596,
29,
549,
1826,
288,
661,
18905,
63,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
2299,
12,
1592,
63,
1080,
29,
549,
1826,
288,
661,
3966,
63,
292,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2495,
63,
2131,
63,
525,
29,
549,
12,
1592,
63,
1080,
29,
549,
12,
4596,
29,
549,
1826,
288,
661,
5334,
63,
292,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2495,
63,
2131,
29,
549,
12,
1592,
63,
1080,
29,
549,
12,
4596,
29,
549,
1826,
288,
661,
23736,
63,
292,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2307,
29,
549,
12,
1592,
63,
1080,
29,
549,
1826,
288,
661,
8578,
316,
63,
751,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
885,
29,
403,
12,
4048,
63,
354,
534,
13834,
63,
16257,
83,
63,
8578,
379,
297,
2973,
29,
549,
12,
370,
29,
1025,
459,
1178,
14,
1899,
16607,
288,
661,
8578,
316,
63,
1364,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
2299,
12,
4596,
29,
549,
1826,
288,
661,
705,
63,
1328,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
7533,
2500,
29,
549,
1826,
288,
661,
705,
63,
600,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
1400,
12,
4596,
29,
549,
1826,
288,
661,
13834,
63,
344,
63,
498,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
7533,
988,
63,
1267,
29,
7727,
1826,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
360,
4712,
63,
5500,
297,
788,
10337,
24117,
21258,
22595,
1105,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
15920,
1402,
283,
10337,
24117,
21258,
22595,
7,
267,
1592,
14,
1807,
63,
1224,
360,
4712,
63,
5500,
63,
15619,
7817,
838,
357,
1883,
7313,
358,
2378,
1709,
275,
469,
267,
283,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
1317,
63,
466,
363,
571,
63,
1302,
297,
283,
1317,
63,
466,
363,
1238,
297,
283,
11879,
18106,
283,
3235,
63,
6314,
356,
9510,
1317,
63,
466,
297,
283,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
10778,
14,
11282,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
283,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
1402,
283,
10337,
24117,
21258,
22595,
7,
267,
1592,
14,
981,
63,
1224,
360,
4712,
63,
5500,
63,
15619,
7817,
838,
357,
1883,
7313,
297,
334,
288,
661,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
7533,
3327,
63,
498,
29,
549,
1826,
288,
661,
1205,
297,
291,
14,
7102,
360,
1238,
63,
1208,
14,
955,
14,
3694,
792,
7533,
885,
534,
3966,
297,
1390,
63,
1267,
29,
1960,
12,
949,
63,
1074,
63,
509,
63,
1205,
29,
549,
1826,
288,
661,
1205,
63,
2489,
297,
291,
14,
7102,
360,
1238,
63,
1208,
14,
955,
14,
13189,
792,
7533,
885,
29,
2083,
14,
2083,
14,
2131,
12,
8372,
29,
85,
1159,
84,
896,
3855,
288,
661,
751,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
475,
29,
1025,
459,
1178,
14,
1899,
16607,
288,
661,
354,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
2299,
12,
4596,
29,
549,
1826,
288,
661,
1409,
63,
1569,
63,
633,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
17363,
7533,
988,
63,
1267,
29,
2299,
12,
4596,
29,
549,
1826,
288,
661,
13834,
63,
344,
63,
1569,
63,
633,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
17363,
7533,
988,
63,
1267,
29,
2299,
12,
4596,
29,
549,
1826,
288,
661,
18905,
63,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
2299,
12,
1592,
63,
1080,
29,
549,
1826,
288,
661,
3966,
63,
292,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2495,
63,
2131,
63,
525,
29,
549,
12,
1592,
63,
1080,
29,
549,
12,
4596,
29,
549,
1826,
288,
661,
5334,
63,
292,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2495,
63,
2131,
29,
549,
12,
1592,
63,
1080,
29,
549,
12,
4596,
29,
549,
1826,
288,
661,
23736,
63,
292,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2307,
29,
549,
12,
1592,
63,
1080,
29,
549,
1826,
288,
661,
8578,
316,
63,
751,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
885,
29,
403,
12,
4048,
63,
354,
534,
13834,
63,
16257,
83,
63,
8578,
379,
297,
2973,
29,
549,
12,
370,
29,
1025,
459,
1178,
14,
1899,
16607,
288,
661,
8578,
316,
63,
1364,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
2299,
12,
4596,
29,
549,
1826,
288,
661,
705,
63,
1328,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
7533,
2500,
29,
549,
1826,
288,
661,
705,
63,
600,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
1400,
12,
4596,
29,
549,
1826,
288,
661,
13834,
63,
344,
63,
498,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
7533,
988,
63,
1267,
29,
7727,
1826,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
360,
4712,
63,
5500,
297,
788,
10337,
24117,
21258,
22595,
1105,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
15920,
1402,
283,
10337,
24117,
21258,
22595,
7,
267,
1592,
14,
1807,
63,
1224,
360,
4712,
63,
5500,
63,
15619,
7817,
838,
357,
1883,
7313,
358,
2378,
1709,
275,
469,
267,
283,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
1317,
63,
466,
363,
571,
63,
1302,
297,
283,
1317,
63,
466,
363,
1238,
297,
283,
11879,
18106,
283,
3235,
63,
6314,
356,
9510,
1317,
63,
466,
297,
283,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
10778,
14,
11282,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
283,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ShinySide/HispAsian_Kernel_NH7
|
build-all.py
|
75
|
10510
|
#! /usr/bin/env python
# Copyright (c) 2009-2011, The Linux Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of The Linux Foundation 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, FITNESS FOR A PARTICULAR PURPOSE AND
# NON-INFRINGEMENT 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.
# Build the kernel for all targets using the Android build environment.
#
# TODO: Accept arguments to indicate what to build.
#
# Modify for supporting of the Samsung JF targets.
#
import glob
from optparse import OptionParser
import subprocess
import os
import os.path
import shutil
import sys
import tarfile
version = 'build-all.py, version 0.01'
build_dir = '../../output/all-kernels'
make_command = ["zImage", "modules"]
make_env = os.environ
pwd = os.environ.get("PWD")
make_env.update({
'ARCH': 'arm',
'CROSS_COMPILE': pwd + '/../prebuilts/gcc/linux-x86/arm/arm-eabi-4.7/bin/arm-eabi-',
'KCONFIG_NOTIMESTAMP': 'true' })
all_options = {}
def error(msg):
sys.stderr.write("error: %s\n" % msg)
def fail(msg):
"""Fail with a user-printed message"""
error(msg)
sys.exit(1)
def check_kernel():
"""Ensure that PWD is a kernel directory"""
if (not os.path.isfile('MAINTAINERS') or
not os.path.isfile('arch/arm/mach-msm/Kconfig')):
fail("This doesn't seem to be an MSM kernel dir")
def check_build():
"""Ensure that the build directory is present."""
if not os.path.isdir(build_dir):
try:
os.makedirs(build_dir)
except OSError as exc:
if exc.errno == errno.EEXIST:
pass
else:
raise
def update_config(file, str):
print 'Updating %s with \'%s\'\n' % (file, str)
defconfig = open(file, 'a')
defconfig.write(str + '\n')
defconfig.close()
def scan_configs():
"""Get the full list of defconfigs appropriate for this tree."""
names = {}
for n in glob.glob('arch/arm/configs/jf_???_defconfig'):
names[os.path.basename(n)[:-10]] = n
return names
class Builder:
def __init__(self, logname):
self.logname = logname
self.fd = open(logname, 'w')
def run(self, args):
devnull = open('/dev/null', 'r')
proc = subprocess.Popen(args, stdin=devnull,
env=make_env,
bufsize=0,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
count = 0
# for line in proc.stdout:
rawfd = proc.stdout.fileno()
while True:
line = os.read(rawfd, 1024)
if not line:
break
self.fd.write(line)
self.fd.flush()
if all_options.verbose:
sys.stdout.write(line)
sys.stdout.flush()
else:
for i in range(line.count('\n')):
count += 1
if count == 64:
count = 0
print
sys.stdout.write('.')
sys.stdout.flush()
print
result = proc.wait()
self.fd.close()
return result
failed_targets = []
def build(target):
dest_dir = os.path.join(build_dir, target)
log_name = '%s/log-%s.log' % (build_dir, target)
zImage_name = '%s/arch/arm/boot/zImage' % (dest_dir)
bootImage_name = '%s/arch/arm/boot/boot.img' % (dest_dir)
signedImage_name = '%s/arch/arm/boot/signed_boot.img' % (dest_dir)
tarball_name = '%s/%s.tar' % (build_dir, target)
if target == 'jf_att':
signing = "SGH-I337_NA_ATT_C"
elif target == 'jactive_att':
signing = "SGH-I537_NA_ATT_C"
elif target == 'jf_tmo':
signing = "SGH-M919_NA_TMB_C"
elif target == 'jf_vzw':
signing = "SCH-I545_NA_VZW_C"
elif target == 'jf_spr':
signing = "SPH-L720_NA_SPR_C"
elif target == 'jf_cri':
signing = "SCH-R970C_NA_CRI_C"
elif target == 'jf_usc':
signing = "SCH-R970_NA_USC_C"
elif target == 'jf_eur':
signing = "GT-I9505_EUR_XX_C"
print 'Building %s in %s log %s' % (target, dest_dir, log_name)
if not os.path.isdir(dest_dir):
os.mkdir(dest_dir)
defconfig = 'arch/arm/configs/%s_defconfig' % target[:-4]
dotconfig = '%s/.config' % dest_dir
savedefconfig = '%s/defconfig' % dest_dir
shutil.copyfile(defconfig, dotconfig)
devnull = open('/dev/null', 'r')
subprocess.check_call(['make', 'O=%s' % dest_dir,
'VARIANT_DEFCONFIG=%s_defconfig' % target,
'DEBUG_DEFCONFIG=%seng_defconfig' % target[:-4],
# 'SELINUX_DEFCONFIG=%sselinux_defconfig' % target[:-4],
# 'SELINUX_LOG_DEFCONFIG=%sselinux_log_defconfig' % target[:-4],
'%s_defconfig' % target[:-4]], env=make_env, stdin=devnull)
devnull.close()
if not all_options.updateconfigs:
build = Builder(log_name)
result = build.run(['make', 'O=%s' % dest_dir] + make_command)
if result != 0:
if all_options.keep_going:
failed_targets.append(target)
fail_or_error = error
else:
fail_or_error = fail
fail_or_error("Failed to build %s, see %s" % (target, build.logname))
if result == 0:
os.rename(zImage_name, bootImage_name)
os.system('java -jar ../../buildscript/tools/signclient.jar -runtype ss_openssl_all -model %s -input %s -output %s' %(signing,bootImage_name,signedImage_name))
tar = tarfile.open(tarball_name, "w")
tar.add(signedImage_name, arcname='boot.img')
tar.close()
# Copy the defconfig back.
if all_options.configs or all_options.updateconfigs:
devnull = open('/dev/null', 'r')
subprocess.check_call(['make', 'O=%s' % dest_dir,
'savedefconfig'], env=make_env, stdin=devnull)
devnull.close()
shutil.copyfile(savedefconfig, defconfig)
def build_many(allconf, targets):
print "Building %d target(s)" % len(targets)
for target in targets:
if all_options.updateconfigs:
update_config(allconf[target], all_options.updateconfigs)
build(target)
if failed_targets:
fail('\n '.join(["Failed targets:"] +
[target for target in failed_targets]))
def main():
global make_command
check_kernel()
check_build()
configs = scan_configs()
usage = ("""
%prog [options] all -- Build all targets
%prog [options] jf_att jf_vzw jf_tmo jf_spr ... -- List specific targets""")
parser = OptionParser(usage=usage, version=version)
parser.add_option('--configs', action='store_true',
dest='configs',
help="Copy configs back into tree")
parser.add_option('--list', action='store_true',
dest='list',
help='List available targets')
parser.add_option('-v', '--verbose', action='store_true',
dest='verbose',
help='Output to stdout in addition to log file')
parser.add_option('--oldconfig', action='store_true',
dest='oldconfig',
help='Only process "make oldconfig"')
parser.add_option('--updateconfigs',
dest='updateconfigs',
help="Update defconfigs with provided option setting, "
"e.g. --updateconfigs=\'CONFIG_USE_THING=y\'")
parser.add_option('-j', '--jobs', type='int', dest="jobs",
help="Number of simultaneous jobs")
parser.add_option('-l', '--load-average', type='int',
dest='load_average',
help="Don't start multiple jobs unless load is below LOAD_AVERAGE")
parser.add_option('-k', '--keep-going', action='store_true',
dest='keep_going', default=False,
help="Keep building other targets if a target fails")
parser.add_option('-m', '--make-target', action='append',
help='Build the indicated make target (default: %s)' %
' '.join(make_command))
parser.add_option('-i', '--ignore-errors', action='store_true',
dest="ignore",
help="Ignore errors from commands")
(options, args) = parser.parse_args()
global all_options
all_options = options
if options.list:
print "Available targets:"
for target in configs.keys():
print " %s" % target
sys.exit(0)
if options.oldconfig:
make_command = ["oldconfig"]
elif options.make_target:
make_command = options.make_target
if options.jobs:
make_command.append("-j%d" % options.jobs)
if options.load_average:
make_command.append("-l%d" % options.load_average)
if options.ignore:
make_command.append("-i")
make_command.append("-k")
if args == ['all']:
build_many(configs, configs.keys())
elif len(args) > 0:
targets = []
for t in args:
if t not in configs.keys():
parser.error("Target '%s' not one of %s" % (t, configs.keys()))
targets.append(t)
build_many(configs, targets)
else:
parser.error("Must specify a target to build, or 'all'")
if __name__ == "__main__":
main()
|
gpl-2.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
8937,
13,
8128,
12,
710,
10130,
2752,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
755,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
710,
10130,
2752,
6590,
199,
3,
755,
314,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
199,
3,
755,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
199,
3,
755,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
11214,
13,
12799,
9315,
9706,
14,
221,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
199,
3,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
199,
3,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
199,
3,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
199,
3,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
199,
3,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
3,
6516,
314,
5114,
367,
1006,
4545,
1808,
314,
14694,
1900,
3734,
14,
199,
3,
199,
3,
3254,
26,
15506,
2368,
370,
6623,
4052,
370,
1900,
14,
199,
199,
3,
199,
3,
22520,
367,
21038,
402,
314,
428,
19470,
10335,
1603,
38,
4545,
14,
199,
3,
199,
199,
646,
5739,
199,
504,
8691,
492,
13491,
199,
646,
3873,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
5145,
199,
646,
984,
199,
646,
13608,
199,
199,
1023,
275,
283,
1506,
13,
452,
14,
647,
12,
1015,
378,
14,
614,
7,
199,
199,
1506,
63,
694,
275,
283,
9707,
1199,
15,
452,
13,
29824,
7,
199,
1875,
63,
1531,
275,
2097,
90,
3491,
401,
298,
3112,
937,
199,
1875,
63,
1813,
275,
747,
14,
2314,
199,
14258,
275,
747,
14,
2314,
14,
362,
480,
10780,
36,
531,
199,
1875,
63,
1813,
14,
873,
2561,
267,
283,
7762,
356,
283,
5362,
297,
267,
283,
28368,
63,
29911,
356,
14374,
435,
1994,
5093,
657,
464,
382,
1086,
15,
13112,
15,
5135,
13,
88,
1184,
15,
5362,
15,
5362,
13,
69,
14677,
13,
20,
14,
23,
15,
1393,
15,
5362,
13,
69,
14677,
14382,
267,
283,
43,
5569,
63,
4609,
1469,
16260,
356,
283,
2052,
7,
3828,
199,
452,
63,
1419,
275,
1052,
199,
199,
318,
1125,
8,
1328,
304,
272,
984,
14,
3083,
14,
952,
480,
705,
26,
450,
83,
60,
78,
2,
450,
1499,
9,
199,
199,
318,
2449,
8,
1328,
304,
272,
408,
4874,
543,
282,
922,
13,
27131,
1245,
624,
272,
1125,
8,
1328,
9,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
318,
1104,
63,
4989,
837,
272,
408,
13913,
626,
510,
16698,
365,
282,
5114,
2082,
624,
272,
340,
334,
1397,
747,
14,
515,
14,
6292,
360,
2054,
2919,
9021,
3960,
358,
503,
267,
440,
747,
14,
515,
14,
6292,
360,
1047,
15,
5362,
15,
14121,
13,
706,
77,
15,
28033,
8109,
267,
2449,
480,
2765,
3181,
1133,
17021,
370,
506,
376,
603,
4029,
5114,
2935,
531,
199,
199,
318,
1104,
63,
1506,
837,
272,
408,
13913,
626,
314,
1900,
2082,
365,
3451,
1041,
272,
340,
440,
747,
14,
515,
14,
6027,
8,
1506,
63,
694,
304,
267,
862,
26,
288,
747,
14,
8347,
8,
1506,
63,
694,
9,
267,
871,
6440,
465,
3178,
26,
288,
340,
3178,
14,
7931,
508,
7554,
14,
28596,
26,
355,
986,
288,
587,
26,
355,
746,
199,
199,
318,
1678,
63,
888,
8,
493,
12,
620,
304,
272,
870,
283,
24993,
450,
83,
543,
19095,
83,
24908,
78,
7,
450,
334,
493,
12,
620,
9,
272,
347,
888,
275,
1551,
8,
493,
12,
283,
65,
358,
272,
347,
888,
14,
952,
8,
495,
435,
1557,
78,
358,
272,
347,
888,
14,
1600,
342,
199,
199,
318,
8000,
63,
7532,
837,
272,
408,
1002,
314,
2615,
769,
402,
347,
7532,
5827,
367,
642,
3123,
1041,
272,
1561,
275,
1052,
272,
367,
302,
315,
5739,
14,
6463,
360,
1047,
15,
5362,
15,
7532,
15,
32008,
63,
10674,
31,
63,
26022,
735,
267,
1561,
59,
736,
14,
515,
14,
4846,
8,
78,
31280,
709,
2677,
275,
302,
272,
372,
1561,
199,
199,
533,
19286,
26,
272,
347,
636,
826,
721,
277,
12,
943,
354,
304,
267,
291,
14,
793,
354,
275,
943,
354,
267,
291,
14,
2592,
275,
1551,
8,
793,
354,
12,
283,
87,
358,
339,
347,
1255,
8,
277,
12,
1249,
304,
267,
4866,
2307,
275,
1551,
2336,
2374,
15,
2307,
297,
283,
82,
358,
267,
6499,
275,
3873,
14,
7942,
8,
589,
12,
9009,
29,
19778,
12,
355,
2589,
29,
1875,
63,
1813,
12,
355,
17080,
29,
16,
12,
355,
3839,
29,
5781,
14,
6089,
12,
355,
4635,
29,
5781,
14,
13850,
9,
267,
2338,
275,
378,
267,
327,
367,
1004,
315,
6499,
14,
2703,
26,
267,
3066,
2592,
275,
6499,
14,
2703,
14,
9843,
342,
267,
1830,
715,
26,
288,
1004,
275,
747,
14,
739,
8,
1773,
2592,
12,
6619,
9,
288,
340,
440,
1004,
26,
355,
2059,
288,
291,
14,
2592,
14,
952,
8,
604,
9,
288,
291,
14,
2592,
14,
4939,
342,
288,
340,
1006,
63,
1419,
14
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
8937,
13,
8128,
12,
710,
10130,
2752,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
755,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
710,
10130,
2752,
6590,
199,
3,
755,
314,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
199,
3,
755,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
199,
3,
755,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
11214,
13,
12799,
9315,
9706,
14,
221,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
199,
3,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
199,
3,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
199,
3,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
199,
3,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
199,
3,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
3,
6516,
314,
5114,
367,
1006,
4545,
1808,
314,
14694,
1900,
3734,
14,
199,
3,
199,
3,
3254,
26,
15506,
2368,
370,
6623,
4052,
370,
1900,
14,
199,
199,
3,
199,
3,
22520,
367,
21038,
402,
314,
428,
19470,
10335,
1603,
38,
4545,
14,
199,
3,
199,
199,
646,
5739,
199,
504,
8691,
492,
13491,
199,
646,
3873,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
5145,
199,
646,
984,
199,
646,
13608,
199,
199,
1023,
275,
283,
1506,
13,
452,
14,
647,
12,
1015,
378,
14,
614,
7,
199,
199,
1506,
63,
694,
275,
283,
9707,
1199,
15,
452,
13,
29824,
7,
199,
1875,
63,
1531,
275,
2097,
90,
3491,
401,
298,
3112,
937,
199,
1875,
63,
1813,
275,
747,
14,
2314,
199,
14258,
275,
747,
14,
2314,
14,
362,
480,
10780,
36,
531,
199,
1875,
63,
1813,
14,
873,
2561,
267,
283,
7762,
356,
283,
5362,
297,
267,
283,
28368,
63,
29911,
356,
14374,
435,
1994,
5093,
657,
464,
382,
1086,
15,
13112,
15,
5135,
13,
88,
1184,
15,
5362,
15,
5362,
13,
69,
14677,
13,
20,
14,
23,
15,
1393,
15,
5362,
13,
69,
14677,
14382,
267,
283,
43,
5569,
63,
4609,
1469,
16260,
356,
283,
2052,
7,
3828,
199,
452,
63,
1419,
275,
1052,
199,
199,
318,
1125,
8,
1328,
304,
272,
984,
14,
3083,
14,
952,
480,
705,
26,
450,
83,
60,
78,
2,
450,
1499,
9,
199,
199,
318,
2449,
8,
1328,
304,
272,
408,
4874,
543,
282,
922,
13,
27131,
1245,
624,
272,
1125,
8,
1328,
9,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
318,
1104,
63,
4989,
837,
272,
408,
13913,
626,
510,
16698,
365,
282,
5114,
2082,
624,
272,
340,
334,
1397,
747,
14,
515,
14,
6292,
360,
2054,
2919,
9021,
3960,
358,
503,
267,
440,
747,
14,
515,
14,
6292,
360,
1047,
15,
5362,
15,
14121,
13,
706,
77,
15,
28033,
8109,
267,
2449,
480,
2765,
3181,
1133,
17021,
370,
506,
376,
603,
4029,
5114,
2935,
531,
199,
199,
318,
1104,
63,
1506,
837,
272,
408,
13913,
626,
314,
1900,
2082,
365,
3451,
1041,
272,
340,
440,
747,
14,
515,
14,
6027,
8,
1506,
63,
694,
304,
267,
862,
26,
288,
747,
14,
8347,
8,
1506,
63,
694,
9,
267,
871,
6440,
465,
3178,
26,
288,
340,
3178,
14,
7931,
508,
7554,
14,
28596,
26,
355,
986,
288,
587,
26,
355,
746,
199,
199,
318,
1678,
63,
888,
8,
493,
12,
620,
304,
272,
870,
283,
24993,
450,
83,
543,
19095,
83,
24908,
78,
7,
450,
334,
493,
12,
620,
9,
272,
347,
888,
275,
1551,
8,
493,
12,
283,
65,
358,
272,
347,
888,
14,
952,
8,
495,
435,
1557,
78,
358,
272,
347,
888,
14,
1600,
342,
199,
199,
318,
8000,
63,
7532,
837,
272,
408,
1002,
314,
2615,
769,
402,
347,
7532,
5827,
367,
642,
3123,
1041,
272,
1561,
275,
1052,
272,
367,
302,
315,
5739,
14,
6463,
360,
1047,
15,
5362,
15,
7532,
15,
32008,
63,
10674,
31,
63,
26022,
735,
267,
1561,
59,
736,
14,
515,
14,
4846,
8,
78,
31280,
709,
2677,
275,
302,
272,
372,
1561,
199,
199,
533,
19286,
26,
272,
347,
636,
826,
721,
277,
12,
943,
354,
304,
267,
291,
14,
793,
354,
275,
943,
354,
267,
291,
14,
2592,
275,
1551,
8,
793,
354,
12,
283,
87,
358,
339,
347,
1255,
8,
277,
12,
1249,
304,
267,
4866,
2307,
275,
1551,
2336,
2374,
15,
2307,
297,
283,
82,
358,
267,
6499,
275,
3873,
14,
7942,
8,
589,
12,
9009,
29,
19778,
12,
355,
2589,
29,
1875,
63,
1813,
12,
355,
17080,
29,
16,
12,
355,
3839,
29,
5781,
14,
6089,
12,
355,
4635,
29,
5781,
14,
13850,
9,
267,
2338,
275,
378,
267,
327,
367,
1004,
315,
6499,
14,
2703,
26,
267,
3066,
2592,
275,
6499,
14,
2703,
14,
9843,
342,
267,
1830,
715,
26,
288,
1004,
275,
747,
14,
739,
8,
1773,
2592,
12,
6619,
9,
288,
340,
440,
1004,
26,
355,
2059,
288,
291,
14,
2592,
14,
952,
8,
604,
9,
288,
291,
14,
2592,
14,
4939,
342,
288,
340,
1006,
63,
1419,
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,
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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
] |
yasoob/PythonRSSReader
|
venv/lib/python2.7/site-packages/pip/index.py
|
237
|
47847
|
"""Routines related to PyPI, indexes"""
from __future__ import absolute_import
import logging
import cgi
from collections import namedtuple
import itertools
import sys
import os
import re
import mimetypes
import posixpath
import warnings
from pip._vendor.six.moves.urllib import parse as urllib_parse
from pip._vendor.six.moves.urllib import request as urllib_request
from pip.compat import ipaddress
from pip.utils import (
Inf, cached_property, normalize_name, splitext, normalize_path,
ARCHIVE_EXTENSIONS, SUPPORTED_EXTENSIONS)
from pip.utils.deprecation import RemovedInPip8Warning
from pip.utils.logging import indent_log
from pip.exceptions import (
DistributionNotFound, BestVersionAlreadyInstalled, InvalidWheelFilename,
UnsupportedWheel,
)
from pip.download import HAS_TLS, url_to_path, path_to_url
from pip.models import PyPI
from pip.wheel import Wheel, wheel_ext
from pip.pep425tags import supported_tags, supported_tags_noarch, get_platform
from pip._vendor import html5lib, requests, pkg_resources, six
from pip._vendor.packaging.version import parse as parse_version
from pip._vendor.requests.exceptions import SSLError
__all__ = ['FormatControl', 'fmt_ctl_handle_mutual_exclude', 'PackageFinder']
# Taken from Chrome's list of secure origins (See: http://bit.ly/1qrySKC)
SECURE_ORIGINS = [
# protocol, hostname, port
("https", "*", "*"),
("*", "localhost", "*"),
("*", "127.0.0.0/8", "*"),
("*", "::1/128", "*"),
("file", "*", None),
]
logger = logging.getLogger(__name__)
class InstallationCandidate(object):
def __init__(self, project, version, location):
self.project = project
self.version = parse_version(version)
self.location = location
self._key = (self.project, self.version, self.location)
def __repr__(self):
return "<InstallationCandidate({0!r}, {1!r}, {2!r})>".format(
self.project, self.version, self.location,
)
def __hash__(self):
return hash(self._key)
def __lt__(self, other):
return self._compare(other, lambda s, o: s < o)
def __le__(self, other):
return self._compare(other, lambda s, o: s <= o)
def __eq__(self, other):
return self._compare(other, lambda s, o: s == o)
def __ge__(self, other):
return self._compare(other, lambda s, o: s >= o)
def __gt__(self, other):
return self._compare(other, lambda s, o: s > o)
def __ne__(self, other):
return self._compare(other, lambda s, o: s != o)
def _compare(self, other, method):
if not isinstance(other, InstallationCandidate):
return NotImplemented
return method(self._key, other._key)
class PackageFinder(object):
"""This finds packages.
This is meant to match easy_install's technique for looking for
packages, by reading pages and looking for appropriate links.
"""
def __init__(self, find_links, index_urls,
allow_external=(), allow_unverified=(),
allow_all_external=False, allow_all_prereleases=False,
trusted_hosts=None, process_dependency_links=False,
session=None, format_control=None):
"""Create a PackageFinder.
:param format_control: A FormatControl object or None. Used to control
the selection of source packages / binary packages when consulting
the index and links.
"""
if session is None:
raise TypeError(
"PackageFinder() missing 1 required keyword argument: "
"'session'"
)
# Build find_links. If an argument starts with ~, it may be
# a local file relative to a home directory. So try normalizing
# it and if it exists, use the normalized version.
# This is deliberately conservative - it might be fine just to
# blindly normalize anything starting with a ~...
self.find_links = []
for link in find_links:
if link.startswith('~'):
new_link = normalize_path(link)
if os.path.exists(new_link):
link = new_link
self.find_links.append(link)
self.index_urls = index_urls
self.dependency_links = []
# These are boring links that have already been logged somehow:
self.logged_links = set()
self.format_control = format_control or FormatControl(set(), set())
# Do we allow (safe and verifiable) externally hosted files?
self.allow_external = set(normalize_name(n) for n in allow_external)
# Which names are allowed to install insecure and unverifiable files?
self.allow_unverified = set(
normalize_name(n) for n in allow_unverified
)
# Anything that is allowed unverified is also allowed external
self.allow_external |= self.allow_unverified
# Do we allow all (safe and verifiable) externally hosted files?
self.allow_all_external = allow_all_external
# Domains that we won't emit warnings for when not using HTTPS
self.secure_origins = [
("*", host, "*")
for host in (trusted_hosts if trusted_hosts else [])
]
# Stores if we ignored any external links so that we can instruct
# end users how to install them if no distributions are available
self.need_warn_external = False
# Stores if we ignored any unsafe links so that we can instruct
# end users how to install them if no distributions are available
self.need_warn_unverified = False
# Do we want to allow _all_ pre-releases?
self.allow_all_prereleases = allow_all_prereleases
# Do we process dependency links?
self.process_dependency_links = process_dependency_links
# The Session we'll use to make requests
self.session = session
# If we don't have TLS enabled, then WARN if anyplace we're looking
# relies on TLS.
if not HAS_TLS:
for link in itertools.chain(self.index_urls, self.find_links):
parsed = urllib_parse.urlparse(link)
if parsed.scheme == "https":
logger.warning(
"pip is configured with locations that require "
"TLS/SSL, however the ssl module in Python is not "
"available."
)
break
def add_dependency_links(self, links):
# # FIXME: this shouldn't be global list this, it should only
# # apply to requirements of the package that specifies the
# # dependency_links value
# # FIXME: also, we should track comes_from (i.e., use Link)
if self.process_dependency_links:
warnings.warn(
"Dependency Links processing has been deprecated and will be "
"removed in a future release.",
RemovedInPip8Warning,
)
self.dependency_links.extend(links)
@staticmethod
def _sort_locations(locations, expand_dir=False):
"""
Sort locations into "files" (archives) and "urls", and return
a pair of lists (files,urls)
"""
files = []
urls = []
# puts the url for the given file path into the appropriate list
def sort_path(path):
url = path_to_url(path)
if mimetypes.guess_type(url, strict=False)[0] == 'text/html':
urls.append(url)
else:
files.append(url)
for url in locations:
is_local_path = os.path.exists(url)
is_file_url = url.startswith('file:')
if is_local_path or is_file_url:
if is_local_path:
path = url
else:
path = url_to_path(url)
if os.path.isdir(path):
if expand_dir:
path = os.path.realpath(path)
for item in os.listdir(path):
sort_path(os.path.join(path, item))
elif is_file_url:
urls.append(url)
elif os.path.isfile(path):
sort_path(path)
else:
urls.append(url)
return files, urls
def _candidate_sort_key(self, candidate):
"""
Function used to generate link sort key for link tuples.
The greater the return value, the more preferred it is.
If not finding wheels, then sorted by version only.
If finding wheels, then the sort order is by version, then:
1. existing installs
2. wheels ordered via Wheel.support_index_min()
3. source archives
Note: it was considered to embed this logic into the Link
comparison operators, but then different sdist links
with the same version, would have to be considered equal
"""
support_num = len(supported_tags)
if candidate.location == INSTALLED_VERSION:
pri = 1
elif candidate.location.is_wheel:
# can raise InvalidWheelFilename
wheel = Wheel(candidate.location.filename)
if not wheel.supported():
raise UnsupportedWheel(
"%s is not a supported wheel for this platform. It "
"can't be sorted." % wheel.filename
)
pri = -(wheel.support_index_min())
else: # sdist
pri = -(support_num)
return (candidate.version, pri)
def _sort_versions(self, applicable_versions):
"""
Bring the latest version (and wheels) to the front, but maintain the
existing ordering as secondary. See the docstring for `_link_sort_key`
for details. This function is isolated for easier unit testing.
"""
return sorted(
applicable_versions,
key=self._candidate_sort_key,
reverse=True
)
def _validate_secure_origin(self, logger, location):
# Determine if this url used a secure transport mechanism
parsed = urllib_parse.urlparse(str(location))
origin = (parsed.scheme, parsed.hostname, parsed.port)
# Determine if our origin is a secure origin by looking through our
# hardcoded list of secure origins, as well as any additional ones
# configured on this PackageFinder instance.
for secure_origin in (SECURE_ORIGINS + self.secure_origins):
# Check to see if the protocol matches
if origin[0] != secure_origin[0] and secure_origin[0] != "*":
continue
try:
# We need to do this decode dance to ensure that we have a
# unicode object, even on Python 2.x.
addr = ipaddress.ip_address(
origin[1]
if (
isinstance(origin[1], six.text_type) or
origin[1] is None
)
else origin[1].decode("utf8")
)
network = ipaddress.ip_network(
secure_origin[1]
if isinstance(secure_origin[1], six.text_type)
else secure_origin[1].decode("utf8")
)
except ValueError:
# We don't have both a valid address or a valid network, so
# we'll check this origin against hostnames.
if origin[1] != secure_origin[1] and secure_origin[1] != "*":
continue
else:
# We have a valid address and network, so see if the address
# is contained within the network.
if addr not in network:
continue
# Check to see if the port patches
if (origin[2] != secure_origin[2] and
secure_origin[2] != "*" and
secure_origin[2] is not None):
continue
# If we've gotten here, then this origin matches the current
# secure origin and we should return True
return True
# If we've gotten to this point, then the origin isn't secure and we
# will not accept it as a valid location to search. We will however
# log a warning that we are ignoring it.
logger.warning(
"The repository located at %s is not a trusted or secure host and "
"is being ignored. If this repository is available via HTTPS it "
"is recommended to use HTTPS instead, otherwise you may silence "
"this warning and allow it anyways with '--trusted-host %s'.",
parsed.hostname,
parsed.hostname,
)
return False
def _get_index_urls_locations(self, project_name):
"""Returns the locations found via self.index_urls
Checks the url_name on the main (first in the list) index and
use this url_name to produce all locations
"""
def mkurl_pypi_url(url):
loc = posixpath.join(url, project_url_name)
# For maximum compatibility with easy_install, ensure the path
# ends in a trailing slash. Although this isn't in the spec
# (and PyPI can handle it without the slash) some other index
# implementations might break if they relied on easy_install's
# behavior.
if not loc.endswith('/'):
loc = loc + '/'
return loc
project_url_name = urllib_parse.quote(project_name.lower())
if self.index_urls:
# Check that we have the url_name correctly spelled:
# Only check main index if index URL is given
main_index_url = Link(
mkurl_pypi_url(self.index_urls[0]),
trusted=True,
)
page = self._get_page(main_index_url)
if page is None and PyPI.netloc not in str(main_index_url):
warnings.warn(
"Failed to find %r at %s. It is suggested to upgrade "
"your index to support normalized names as the name in "
"/simple/{name}." % (project_name, main_index_url),
RemovedInPip8Warning,
)
project_url_name = self._find_url_name(
Link(self.index_urls[0], trusted=True),
project_url_name,
) or project_url_name
if project_url_name is not None:
return [mkurl_pypi_url(url) for url in self.index_urls]
return []
def _find_all_versions(self, project_name):
"""Find all available versions for project_name
This checks index_urls, find_links and dependency_links
All versions found are returned
See _link_package_versions for details on which files are accepted
"""
index_locations = self._get_index_urls_locations(project_name)
index_file_loc, index_url_loc = self._sort_locations(index_locations)
fl_file_loc, fl_url_loc = self._sort_locations(
self.find_links, expand_dir=True)
dep_file_loc, dep_url_loc = self._sort_locations(self.dependency_links)
file_locations = (
Link(url) for url in itertools.chain(
index_file_loc, fl_file_loc, dep_file_loc)
)
# We trust every url that the user has given us whether it was given
# via --index-url or --find-links
# We explicitly do not trust links that came from dependency_links
# We want to filter out any thing which does not have a secure origin.
url_locations = [
link for link in itertools.chain(
(Link(url, trusted=True) for url in index_url_loc),
(Link(url, trusted=True) for url in fl_url_loc),
(Link(url) for url in dep_url_loc),
)
if self._validate_secure_origin(logger, link)
]
logger.debug('%d location(s) to search for versions of %s:',
len(url_locations), project_name)
for location in url_locations:
logger.debug('* %s', location)
canonical_name = pkg_resources.safe_name(project_name).lower()
formats = fmt_ctl_formats(self.format_control, canonical_name)
search = Search(project_name.lower(), canonical_name, formats)
find_links_versions = self._package_versions(
# We trust every directly linked archive in find_links
(Link(url, '-f', trusted=True) for url in self.find_links),
search
)
page_versions = []
for page in self._get_pages(url_locations, project_name):
logger.debug('Analyzing links from page %s', page.url)
with indent_log():
page_versions.extend(
self._package_versions(page.links, search)
)
dependency_versions = self._package_versions(
(Link(url) for url in self.dependency_links), search
)
if dependency_versions:
logger.debug(
'dependency_links found: %s',
', '.join([
version.location.url for version in dependency_versions
])
)
file_versions = self._package_versions(file_locations, search)
if file_versions:
file_versions.sort(reverse=True)
logger.debug(
'Local files found: %s',
', '.join([
url_to_path(candidate.location.url)
for candidate in file_versions
])
)
# This is an intentional priority ordering
return (
file_versions + find_links_versions + page_versions +
dependency_versions
)
def find_requirement(self, req, upgrade):
"""Try to find an InstallationCandidate for req
Expects req, an InstallRequirement and upgrade, a boolean
Returns an InstallationCandidate or None
May raise DistributionNotFound or BestVersionAlreadyInstalled
"""
all_versions = self._find_all_versions(req.name)
# Filter out anything which doesn't match our specifier
_versions = set(
req.specifier.filter(
# We turn the version object into a str here because otherwise
# when we're debundled but setuptools isn't, Python will see
# packaging.version.Version and
# pkg_resources._vendor.packaging.version.Version as different
# types. This way we'll use a str as a common data interchange
# format. If we stop using the pkg_resources provided specifier
# and start using our own, we can drop the cast to str().
[str(x.version) for x in all_versions],
prereleases=(
self.allow_all_prereleases
if self.allow_all_prereleases else None
),
)
)
applicable_versions = [
# Again, converting to str to deal with debundling.
x for x in all_versions if str(x.version) in _versions
]
if req.satisfied_by is not None:
# Finally add our existing versions to the front of our versions.
applicable_versions.insert(
0,
InstallationCandidate(
req.name,
req.satisfied_by.version,
INSTALLED_VERSION,
)
)
existing_applicable = True
else:
existing_applicable = False
applicable_versions = self._sort_versions(applicable_versions)
if not upgrade and existing_applicable:
if applicable_versions[0].location is INSTALLED_VERSION:
logger.debug(
'Existing installed version (%s) is most up-to-date and '
'satisfies requirement',
req.satisfied_by.version,
)
else:
logger.debug(
'Existing installed version (%s) satisfies requirement '
'(most up-to-date version is %s)',
req.satisfied_by.version,
applicable_versions[0][2],
)
return None
if not applicable_versions:
logger.critical(
'Could not find a version that satisfies the requirement %s '
'(from versions: %s)',
req,
', '.join(
sorted(
set(str(i.version) for i in all_versions),
key=parse_version,
)
)
)
if self.need_warn_external:
logger.warning(
"Some externally hosted files were ignored as access to "
"them may be unreliable (use --allow-external %s to "
"allow).",
req.name,
)
if self.need_warn_unverified:
logger.warning(
"Some insecure and unverifiable files were ignored"
" (use --allow-unverified %s to allow).",
req.name,
)
raise DistributionNotFound(
'No matching distribution found for %s' % req
)
if applicable_versions[0].location is INSTALLED_VERSION:
# We have an existing version, and its the best version
logger.debug(
'Installed version (%s) is most up-to-date (past versions: '
'%s)',
req.satisfied_by.version,
', '.join(str(i.version) for i in applicable_versions[1:]) or
"none",
)
raise BestVersionAlreadyInstalled
if len(applicable_versions) > 1:
logger.debug(
'Using version %s (newest of versions: %s)',
applicable_versions[0].version,
', '.join(str(i.version) for i in applicable_versions)
)
selected_version = applicable_versions[0].location
if (selected_version.verifiable is not None and not
selected_version.verifiable):
logger.warning(
"%s is potentially insecure and unverifiable.", req.name,
)
return selected_version
def _find_url_name(self, index_url, url_name):
"""
Finds the true URL name of a package, when the given name isn't quite
correct.
This is usually used to implement case-insensitivity.
"""
if not index_url.url.endswith('/'):
# Vaguely part of the PyPI API... weird but true.
# FIXME: bad to modify this?
index_url.url += '/'
page = self._get_page(index_url)
if page is None:
logger.critical('Cannot fetch index base URL %s', index_url)
return
norm_name = normalize_name(url_name)
for link in page.links:
base = posixpath.basename(link.path.rstrip('/'))
if norm_name == normalize_name(base):
logger.debug(
'Real name of requirement %s is %s', url_name, base,
)
return base
return None
def _get_pages(self, locations, project_name):
"""
Yields (page, page_url) from the given locations, skipping
locations that have errors, and adding download/homepage links
"""
all_locations = list(locations)
seen = set()
normalized = normalize_name(project_name)
while all_locations:
location = all_locations.pop(0)
if location in seen:
continue
seen.add(location)
page = self._get_page(location)
if page is None:
continue
yield page
for link in page.rel_links():
if (normalized not in self.allow_external and not
self.allow_all_external):
self.need_warn_external = True
logger.debug(
"Not searching %s for files because external "
"urls are disallowed.",
link,
)
continue
if (link.trusted is not None and not
link.trusted and
normalized not in self.allow_unverified):
logger.debug(
"Not searching %s for urls, it is an "
"untrusted link and cannot produce safe or "
"verifiable files.",
link,
)
self.need_warn_unverified = True
continue
all_locations.append(link)
_py_version_re = re.compile(r'-py([123]\.?[0-9]?)$')
def _sort_links(self, links):
"""
Returns elements of links in order, non-egg links first, egg links
second, while eliminating duplicates
"""
eggs, no_eggs = [], []
seen = set()
for link in links:
if link not in seen:
seen.add(link)
if link.egg_fragment:
eggs.append(link)
else:
no_eggs.append(link)
return no_eggs + eggs
def _package_versions(self, links, search):
result = []
for link in self._sort_links(links):
v = self._link_package_versions(link, search)
if v is not None:
result.append(v)
return result
def _log_skipped_link(self, link, reason):
if link not in self.logged_links:
logger.debug('Skipping link %s; %s', link, reason)
self.logged_links.add(link)
def _link_package_versions(self, link, search):
"""Return an InstallationCandidate or None"""
platform = get_platform()
version = None
if link.egg_fragment:
egg_info = link.egg_fragment
ext = link.ext
else:
egg_info, ext = link.splitext()
if not ext:
self._log_skipped_link(link, 'not a file')
return
if ext not in SUPPORTED_EXTENSIONS:
self._log_skipped_link(
link, 'unsupported archive format: %s' % ext)
return
if "binary" not in search.formats and ext == wheel_ext:
self._log_skipped_link(
link, 'No binaries permitted for %s' % search.supplied)
return
if "macosx10" in link.path and ext == '.zip':
self._log_skipped_link(link, 'macosx10 one')
return
if ext == wheel_ext:
try:
wheel = Wheel(link.filename)
except InvalidWheelFilename:
self._log_skipped_link(link, 'invalid wheel filename')
return
if (pkg_resources.safe_name(wheel.name).lower() !=
search.canonical):
self._log_skipped_link(
link, 'wrong project name (not %s)' % search.supplied)
return
if not wheel.supported():
self._log_skipped_link(
link, 'it is not compatible with this Python')
return
# This is a dirty hack to prevent installing Binary Wheels from
# PyPI unless it is a Windows or Mac Binary Wheel. This is
# paired with a change to PyPI disabling uploads for the
# same. Once we have a mechanism for enabling support for
# binary wheels on linux that deals with the inherent problems
# of binary distribution this can be removed.
comes_from = getattr(link, "comes_from", None)
if (
(
not platform.startswith('win') and not
platform.startswith('macosx') and not
platform == 'cli'
) and
comes_from is not None and
urllib_parse.urlparse(
comes_from.url
).netloc.endswith(PyPI.netloc)):
if not wheel.supported(tags=supported_tags_noarch):
self._log_skipped_link(
link,
"it is a pypi-hosted binary "
"Wheel on an unsupported platform",
)
return
version = wheel.version
# This should be up by the search.ok_binary check, but see issue 2700.
if "source" not in search.formats and ext != wheel_ext:
self._log_skipped_link(
link, 'No sources permitted for %s' % search.supplied)
return
if not version:
version = egg_info_matches(egg_info, search.supplied, link)
if version is None:
self._log_skipped_link(
link, 'wrong project name (not %s)' % search.supplied)
return
if (link.internal is not None and not
link.internal and not
normalize_name(search.supplied).lower()
in self.allow_external and not
self.allow_all_external):
# We have a link that we are sure is external, so we should skip
# it unless we are allowing externals
self._log_skipped_link(link, 'it is externally hosted')
self.need_warn_external = True
return
if (link.verifiable is not None and not
link.verifiable and not
(normalize_name(search.supplied).lower()
in self.allow_unverified)):
# We have a link that we are sure we cannot verify its integrity,
# so we should skip it unless we are allowing unsafe installs
# for this requirement.
self._log_skipped_link(
link, 'it is an insecure and unverifiable file')
self.need_warn_unverified = True
return
match = self._py_version_re.search(version)
if match:
version = version[:match.start()]
py_version = match.group(1)
if py_version != sys.version[:3]:
self._log_skipped_link(
link, 'Python version is incorrect')
return
logger.debug('Found link %s, version: %s', link, version)
return InstallationCandidate(search.supplied, version, link)
def _get_page(self, link):
return HTMLPage.get_page(link, session=self.session)
def egg_info_matches(
egg_info, search_name, link,
_egg_info_re=re.compile(r'([a-z0-9_.]+)-([a-z0-9_.!+-]+)', re.I)):
"""Pull the version part out of a string.
:param egg_info: The string to parse. E.g. foo-2.1
:param search_name: The name of the package this belongs to. None to
infer the name. Note that this cannot unambiguously parse strings
like foo-2-2 which might be foo, 2-2 or foo-2, 2.
:param link: The link the string came from, for logging on failure.
"""
match = _egg_info_re.search(egg_info)
if not match:
logger.debug('Could not parse version from link: %s', link)
return None
if search_name is None:
full_match = match.group(0)
return full_match[full_match.index('-'):]
name = match.group(0).lower()
# To match the "safe" name that pkg_resources creates:
name = name.replace('_', '-')
# project name and version must be separated by a dash
look_for = search_name.lower() + "-"
if name.startswith(look_for):
return match.group(0)[len(look_for):]
else:
return None
class HTMLPage(object):
"""Represents one page, along with its URL"""
def __init__(self, content, url, headers=None, trusted=None):
# Determine if we have any encoding information in our headers
encoding = None
if headers and "Content-Type" in headers:
content_type, params = cgi.parse_header(headers["Content-Type"])
if "charset" in params:
encoding = params['charset']
self.content = content
self.parsed = html5lib.parse(
self.content,
encoding=encoding,
namespaceHTMLElements=False,
)
self.url = url
self.headers = headers
self.trusted = trusted
def __str__(self):
return self.url
@classmethod
def get_page(cls, link, skip_archives=True, session=None):
if session is None:
raise TypeError(
"get_page() missing 1 required keyword argument: 'session'"
)
url = link.url
url = url.split('#', 1)[0]
# Check for VCS schemes that do not support lookup as web pages.
from pip.vcs import VcsSupport
for scheme in VcsSupport.schemes:
if url.lower().startswith(scheme) and url[len(scheme)] in '+:':
logger.debug('Cannot look at %s URL %s', scheme, link)
return None
try:
if skip_archives:
filename = link.filename
for bad_ext in ARCHIVE_EXTENSIONS:
if filename.endswith(bad_ext):
content_type = cls._get_content_type(
url, session=session,
)
if content_type.lower().startswith('text/html'):
break
else:
logger.debug(
'Skipping page %s because of Content-Type: %s',
link,
content_type,
)
return
logger.debug('Getting page %s', url)
# Tack index.html onto file:// URLs that point to directories
(scheme, netloc, path, params, query, fragment) = \
urllib_parse.urlparse(url)
if (scheme == 'file' and
os.path.isdir(urllib_request.url2pathname(path))):
# add trailing slash if not present so urljoin doesn't trim
# final segment
if not url.endswith('/'):
url += '/'
url = urllib_parse.urljoin(url, 'index.html')
logger.debug(' file: URL is directory, getting %s', url)
resp = session.get(
url,
headers={
"Accept": "text/html",
"Cache-Control": "max-age=600",
},
)
resp.raise_for_status()
# The check for archives above only works if the url ends with
# something that looks like an archive. However that is not a
# requirement of an url. Unless we issue a HEAD request on every
# url we cannot know ahead of time for sure if something is HTML
# or not. However we can check after we've downloaded it.
content_type = resp.headers.get('Content-Type', 'unknown')
if not content_type.lower().startswith("text/html"):
logger.debug(
'Skipping page %s because of Content-Type: %s',
link,
content_type,
)
return
inst = cls(
resp.content, resp.url, resp.headers,
trusted=link.trusted,
)
except requests.HTTPError as exc:
level = 2 if exc.response.status_code == 404 else 1
cls._handle_fail(link, exc, url, level=level)
except requests.ConnectionError as exc:
cls._handle_fail(link, "connection error: %s" % exc, url)
except requests.Timeout:
cls._handle_fail(link, "timed out", url)
except SSLError as exc:
reason = ("There was a problem confirming the ssl certificate: "
"%s" % exc)
cls._handle_fail(link, reason, url, level=2, meth=logger.info)
else:
return inst
@staticmethod
def _handle_fail(link, reason, url, level=1, meth=None):
if meth is None:
meth = logger.debug
meth("Could not fetch URL %s: %s - skipping", link, reason)
@staticmethod
def _get_content_type(url, session):
"""Get the Content-Type of the given url, using a HEAD request"""
scheme, netloc, path, query, fragment = urllib_parse.urlsplit(url)
if scheme not in ('http', 'https'):
# FIXME: some warning or something?
# assertion error?
return ''
resp = session.head(url, allow_redirects=True)
resp.raise_for_status()
return resp.headers.get("Content-Type", "")
@cached_property
def api_version(self):
metas = [
x for x in self.parsed.findall(".//meta")
if x.get("name", "").lower() == "api-version"
]
if metas:
try:
return int(metas[0].get("value", None))
except (TypeError, ValueError):
pass
return None
@cached_property
def base_url(self):
bases = [
x for x in self.parsed.findall(".//base")
if x.get("href") is not None
]
if bases and bases[0].get("href"):
return bases[0].get("href")
else:
return self.url
@property
def links(self):
"""Yields all links in the page"""
for anchor in self.parsed.findall(".//a"):
if anchor.get("href"):
href = anchor.get("href")
url = self.clean_link(
urllib_parse.urljoin(self.base_url, href)
)
# Determine if this link is internal. If that distinction
# doesn't make sense in this context, then we don't make
# any distinction.
internal = None
if self.api_version and self.api_version >= 2:
# Only api_versions >= 2 have a distinction between
# external and internal links
internal = bool(
anchor.get("rel") and
"internal" in anchor.get("rel").split()
)
yield Link(url, self, internal=internal)
def rel_links(self, rels=('homepage', 'download')):
"""Yields all links with the given relations"""
rels = set(rels)
for anchor in self.parsed.findall(".//a"):
if anchor.get("rel") and anchor.get("href"):
found_rels = set(anchor.get("rel").split())
# Determine the intersection between what rels were found and
# what rels were being looked for
if found_rels & rels:
href = anchor.get("href")
url = self.clean_link(
urllib_parse.urljoin(self.base_url, href)
)
yield Link(url, self, trusted=False)
_clean_re = re.compile(r'[^a-z0-9$&+,/:;=?@.#%_\\|-]', re.I)
def clean_link(self, url):
"""Makes sure a link is fully encoded. That is, if a ' ' shows up in
the link, it will be rewritten to %20 (while not over-quoting
% or other characters)."""
return self._clean_re.sub(
lambda match: '%%%2x' % ord(match.group(0)), url)
class Link(object):
def __init__(self, url, comes_from=None, internal=None, trusted=None):
# url can be a UNC windows share
if url != Inf and url.startswith('\\\\'):
url = path_to_url(url)
self.url = url
self.comes_from = comes_from
self.internal = internal
self.trusted = trusted
def __str__(self):
if self.comes_from:
return '%s (from %s)' % (self.url, self.comes_from)
else:
return str(self.url)
def __repr__(self):
return '<Link %s>' % self
def __eq__(self, other):
if not isinstance(other, Link):
return NotImplemented
return self.url == other.url
def __ne__(self, other):
if not isinstance(other, Link):
return NotImplemented
return self.url != other.url
def __lt__(self, other):
if not isinstance(other, Link):
return NotImplemented
return self.url < other.url
def __le__(self, other):
if not isinstance(other, Link):
return NotImplemented
return self.url <= other.url
def __gt__(self, other):
if not isinstance(other, Link):
return NotImplemented
return self.url > other.url
def __ge__(self, other):
if not isinstance(other, Link):
return NotImplemented
return self.url >= other.url
def __hash__(self):
return hash(self.url)
@property
def filename(self):
_, netloc, path, _, _ = urllib_parse.urlsplit(self.url)
name = posixpath.basename(path.rstrip('/')) or netloc
name = urllib_parse.unquote(name)
assert name, ('URL %r produced no filename' % self.url)
return name
@property
def scheme(self):
return urllib_parse.urlsplit(self.url)[0]
@property
def netloc(self):
return urllib_parse.urlsplit(self.url)[1]
@property
def path(self):
return urllib_parse.unquote(urllib_parse.urlsplit(self.url)[2])
def splitext(self):
return splitext(posixpath.basename(self.path.rstrip('/')))
@property
def ext(self):
return self.splitext()[1]
@property
def url_without_fragment(self):
scheme, netloc, path, query, fragment = urllib_parse.urlsplit(self.url)
return urllib_parse.urlunsplit((scheme, netloc, path, query, None))
_egg_fragment_re = re.compile(r'#egg=([^&]*)')
@property
def egg_fragment(self):
match = self._egg_fragment_re.search(self.url)
if not match:
return None
return match.group(1)
_hash_re = re.compile(
r'(sha1|sha224|sha384|sha256|sha512|md5)=([a-f0-9]+)'
)
@property
def hash(self):
match = self._hash_re.search(self.url)
if match:
return match.group(2)
return None
@property
def hash_name(self):
match = self._hash_re.search(self.url)
if match:
return match.group(1)
return None
@property
def show_url(self):
return posixpath.basename(self.url.split('#', 1)[0].split('?', 1)[0])
@property
def verifiable(self):
"""
Returns True if this link can be verified after download, False if it
cannot, and None if we cannot determine.
"""
trusted = self.trusted or getattr(self.comes_from, "trusted", None)
if trusted is not None and trusted:
# This link came from a trusted source. It *may* be verifiable but
# first we need to see if this page is operating under the new
# API version.
try:
api_version = getattr(self.comes_from, "api_version", None)
api_version = int(api_version)
except (ValueError, TypeError):
api_version = None
if api_version is None or api_version <= 1:
# This link is either trusted, or it came from a trusted,
# however it is not operating under the API version 2 so
# we can't make any claims about if it's safe or not
return
if self.hash:
# This link came from a trusted source and it has a hash, so we
# can consider it safe.
return True
else:
# This link came from a trusted source, using the new API
# version, and it does not have a hash. It is NOT verifiable
return False
elif trusted is not None:
# This link came from an untrusted source and we cannot trust it
return False
@property
def is_wheel(self):
return self.ext == wheel_ext
@property
def is_artifact(self):
"""
Determines if this points to an actual artifact (e.g. a tarball) or if
it points to an "abstract" thing like a path or a VCS location.
"""
from pip.vcs import vcs
if self.scheme in vcs.all_schemes:
return False
return True
# An object to represent the "link" for the installed version of a requirement.
# Using Inf as the url makes it sort higher.
INSTALLED_VERSION = Link(Inf)
FormatControl = namedtuple('FormatControl', 'no_binary only_binary')
"""This object has two fields, no_binary and only_binary.
If a field is falsy, it isn't set. If it is {':all:'}, it should match all
packages except those listed in the other field. Only one field can be set
to {':all:'} at a time. The rest of the time exact package name matches
are listed, with any given package only showing up in one field at a time.
"""
def fmt_ctl_handle_mutual_exclude(value, target, other):
new = value.split(',')
while ':all:' in new:
other.clear()
target.clear()
target.add(':all:')
del new[:new.index(':all:') + 1]
if ':none:' not in new:
# Without a none, we want to discard everything as :all: covers it
return
for name in new:
if name == ':none:':
target.clear()
continue
name = pkg_resources.safe_name(name).lower()
other.discard(name)
target.add(name)
def fmt_ctl_formats(fmt_ctl, canonical_name):
result = set(["binary", "source"])
if canonical_name in fmt_ctl.only_binary:
result.discard('source')
elif canonical_name in fmt_ctl.no_binary:
result.discard('binary')
elif ':all:' in fmt_ctl.only_binary:
result.discard('source')
elif ':all:' in fmt_ctl.no_binary:
result.discard('binary')
return frozenset(result)
def fmt_ctl_no_binary(fmt_ctl):
fmt_ctl_handle_mutual_exclude(
':all:', fmt_ctl.no_binary, fmt_ctl.only_binary)
def fmt_ctl_no_use_wheel(fmt_ctl):
fmt_ctl_no_binary(fmt_ctl)
warnings.warn(
'--no-use-wheel is deprecated and will be removed in the future. '
' Please use --no-binary :all: instead.', DeprecationWarning,
stacklevel=2)
Search = namedtuple('Search', 'supplied canonical formats')
"""Capture key aspects of a search.
:attribute supplied: The user supplied package.
:attribute canonical: The canonical package name.
:attribute formats: The formats allowed for this package. Should be a set
with 'binary' or 'source' or both in it.
"""
|
mit
|
[
624,
7595,
3746,
4048,
370,
24330,
12,
10507,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2050,
199,
646,
16004,
199,
504,
5055,
492,
12863,
199,
646,
7975,
199,
646,
984,
199,
646,
747,
199,
646,
295,
199,
646,
13290,
199,
646,
15454,
199,
646,
3598,
199,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
14,
4078,
492,
2198,
465,
4011,
63,
1122,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
14,
4078,
492,
1056,
465,
4011,
63,
1069,
199,
199,
504,
7305,
14,
5819,
492,
20617,
199,
504,
7305,
14,
1208,
492,
334,
272,
1010,
70,
12,
6328,
63,
1829,
12,
7666,
63,
354,
12,
2249,
7699,
12,
7666,
63,
515,
12,
272,
4160,
1244,
5399,
63,
18451,
12,
32501,
63,
18451,
9,
199,
504,
7305,
14,
1208,
14,
15383,
492,
799,
17920,
32457,
24,
3849,
199,
504,
7305,
14,
1208,
14,
4806,
492,
4363,
63,
793,
199,
504,
7305,
14,
3924,
492,
334,
272,
11839,
4667,
12,
699,
597,
3353,
16760,
21268,
12,
6378,
25663,
8117,
12,
272,
19022,
25663,
12,
199,
9,
199,
504,
7305,
14,
4249,
492,
7509,
63,
10224,
12,
1166,
63,
475,
63,
515,
12,
931,
63,
475,
63,
633,
199,
504,
7305,
14,
992,
492,
24330,
199,
504,
7305,
14,
11798,
492,
26161,
12,
9989,
63,
832,
199,
504,
7305,
14,
12636,
24398,
2969,
492,
3748,
63,
2969,
12,
3748,
63,
2969,
63,
889,
1047,
12,
664,
63,
3246,
199,
504,
7305,
423,
9884,
492,
3517,
21,
773,
12,
4145,
12,
5496,
63,
4435,
12,
3816,
199,
504,
7305,
423,
9884,
14,
27796,
14,
1023,
492,
2198,
465,
2198,
63,
1023,
199,
504,
7305,
423,
9884,
14,
6615,
14,
3924,
492,
7799,
547,
421,
199,
363,
452,
363,
275,
788,
3484,
3717,
297,
283,
5045,
63,
8077,
63,
2479,
63,
6552,
1061,
63,
5473,
297,
283,
8599,
11791,
418,
421,
199,
3,
32316,
917,
687,
16776,
1159,
769,
402,
11153,
2306,
3617,
334,
9295,
26,
1455,
921,
2075,
14,
590,
15,
17,
81,
651,
8656,
35,
9,
199,
20696,
63,
20332,
10789,
275,
359,
272,
327,
4113,
12,
6246,
12,
1844,
272,
1689,
2859,
401,
8969,
401,
8969,
1288,
272,
1689,
14421,
298,
5967,
401,
8969,
1288,
272,
1689,
14421,
298,
4195,
14,
16,
14,
16,
14,
16,
15,
24,
401,
8969,
1288,
272,
1689,
14421,
27472,
17,
15,
3933,
401,
8969,
1288,
272,
1689,
493,
401,
8969,
401,
488,
395,
199,
61,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
26866,
26925,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
2199,
12,
1015,
12,
2909,
304,
267,
291,
14,
1715,
275,
2199,
267,
291,
14,
1023,
275,
2198,
63,
1023,
8,
1023,
9,
267,
291,
14,
1985,
275,
2909,
267,
291,
423,
498,
275,
334,
277,
14,
1715,
12,
291,
14,
1023,
12,
291,
14,
1985,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3886,
31456,
26925,
2561,
16,
1,
82,
1386,
469,
17,
1,
82,
1386,
469,
18,
1,
82,
1552,
23167,
908,
8,
288,
291,
14,
1715,
12,
291,
14,
1023,
12,
291,
14,
1985,
12,
267,
776,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
277,
423,
498,
9,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
665,
312,
9,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
2695,
312,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
508,
312,
9,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
2356,
312,
9,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
690,
312,
9,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
1137,
312,
9,
339,
347,
485,
5785,
8,
277,
12,
1163,
12,
1083,
304,
267,
340,
440,
1228,
8,
1848,
12,
26866,
26925,
304,
288,
372,
3784,
398,
372,
1083,
8,
277,
423,
498,
12,
1163,
423,
498,
9,
421,
199,
533,
15665,
11791,
8,
785,
304,
272,
408,
2765,
17651,
6117,
14,
339,
961,
365,
18329,
370,
1336,
8837,
63,
3174,
1159,
32414,
367,
10023,
367,
272,
6117,
12,
701,
7664,
6497,
436,
10023,
367,
5827,
6220,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2342,
63,
4614,
12,
1478,
63,
3603,
12,
326,
2040,
63,
5159,
16729,
2040,
63,
324,
12949,
16729,
326,
2040,
63,
452,
63,
5159,
29,
797,
12,
2040,
63,
452,
63,
25648,
29,
797,
12,
326,
19427,
63,
5146,
29,
403,
12,
2112,
63,
8575,
63,
4614,
29,
797,
12,
326,
2351,
29,
403,
12,
1475,
63,
2785,
29,
403,
304,
267,
408,
2499,
282,
15665,
11791,
14,
398,
520,
635,
1475,
63,
2785,
26,
437,
9701,
3717,
909,
503,
488,
14,
8051,
370,
3304,
288,
314,
7267,
402,
1350,
6117,
1182,
3366,
6117,
1380,
13447,
427,
316,
288,
314,
1478,
436,
6220,
14,
267,
408,
267,
340,
2351,
365,
488,
26,
288,
746,
3146,
8,
355,
298,
8599,
11791,
342,
4124,
413,
1415,
4252,
1423,
26,
298,
355,
3546,
1730,
4065,
288,
776,
398,
327,
6516,
2342,
63,
4614,
14,
982,
376,
1423,
9174,
543,
6146,
12,
652,
1443,
506,
267,
327,
282,
2257,
570,
3847,
370,
282,
5629,
2082,
14,
2002,
862,
3293,
9147,
267,
327,
652,
436,
340,
652,
3495,
12,
675,
314,
9657,
1015,
14,
267,
327,
961,
365,
9122,
605,
13824,
406,
7297,
1905,
446,
652,
5594,
506,
15701,
2951,
370,
267,
327,
330,
24491,
590,
7666,
7003,
6617,
543,
282,
6146,
1396,
267,
291,
14,
1623,
63,
4614,
275,
942,
267,
367,
2142,
315,
2342,
63,
4614,
26,
288,
340,
2142,
14,
2460,
21114,
735,
355,
892,
63,
1073,
275,
7666,
63,
515,
8,
1073,
9,
355,
340
] |
[
7595,
3746,
4048,
370,
24330,
12,
10507,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2050,
199,
646,
16004,
199,
504,
5055,
492,
12863,
199,
646,
7975,
199,
646,
984,
199,
646,
747,
199,
646,
295,
199,
646,
13290,
199,
646,
15454,
199,
646,
3598,
199,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
14,
4078,
492,
2198,
465,
4011,
63,
1122,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
14,
4078,
492,
1056,
465,
4011,
63,
1069,
199,
199,
504,
7305,
14,
5819,
492,
20617,
199,
504,
7305,
14,
1208,
492,
334,
272,
1010,
70,
12,
6328,
63,
1829,
12,
7666,
63,
354,
12,
2249,
7699,
12,
7666,
63,
515,
12,
272,
4160,
1244,
5399,
63,
18451,
12,
32501,
63,
18451,
9,
199,
504,
7305,
14,
1208,
14,
15383,
492,
799,
17920,
32457,
24,
3849,
199,
504,
7305,
14,
1208,
14,
4806,
492,
4363,
63,
793,
199,
504,
7305,
14,
3924,
492,
334,
272,
11839,
4667,
12,
699,
597,
3353,
16760,
21268,
12,
6378,
25663,
8117,
12,
272,
19022,
25663,
12,
199,
9,
199,
504,
7305,
14,
4249,
492,
7509,
63,
10224,
12,
1166,
63,
475,
63,
515,
12,
931,
63,
475,
63,
633,
199,
504,
7305,
14,
992,
492,
24330,
199,
504,
7305,
14,
11798,
492,
26161,
12,
9989,
63,
832,
199,
504,
7305,
14,
12636,
24398,
2969,
492,
3748,
63,
2969,
12,
3748,
63,
2969,
63,
889,
1047,
12,
664,
63,
3246,
199,
504,
7305,
423,
9884,
492,
3517,
21,
773,
12,
4145,
12,
5496,
63,
4435,
12,
3816,
199,
504,
7305,
423,
9884,
14,
27796,
14,
1023,
492,
2198,
465,
2198,
63,
1023,
199,
504,
7305,
423,
9884,
14,
6615,
14,
3924,
492,
7799,
547,
421,
199,
363,
452,
363,
275,
788,
3484,
3717,
297,
283,
5045,
63,
8077,
63,
2479,
63,
6552,
1061,
63,
5473,
297,
283,
8599,
11791,
418,
421,
199,
3,
32316,
917,
687,
16776,
1159,
769,
402,
11153,
2306,
3617,
334,
9295,
26,
1455,
921,
2075,
14,
590,
15,
17,
81,
651,
8656,
35,
9,
199,
20696,
63,
20332,
10789,
275,
359,
272,
327,
4113,
12,
6246,
12,
1844,
272,
1689,
2859,
401,
8969,
401,
8969,
1288,
272,
1689,
14421,
298,
5967,
401,
8969,
1288,
272,
1689,
14421,
298,
4195,
14,
16,
14,
16,
14,
16,
15,
24,
401,
8969,
1288,
272,
1689,
14421,
27472,
17,
15,
3933,
401,
8969,
1288,
272,
1689,
493,
401,
8969,
401,
488,
395,
199,
61,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
26866,
26925,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
2199,
12,
1015,
12,
2909,
304,
267,
291,
14,
1715,
275,
2199,
267,
291,
14,
1023,
275,
2198,
63,
1023,
8,
1023,
9,
267,
291,
14,
1985,
275,
2909,
267,
291,
423,
498,
275,
334,
277,
14,
1715,
12,
291,
14,
1023,
12,
291,
14,
1985,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3886,
31456,
26925,
2561,
16,
1,
82,
1386,
469,
17,
1,
82,
1386,
469,
18,
1,
82,
1552,
23167,
908,
8,
288,
291,
14,
1715,
12,
291,
14,
1023,
12,
291,
14,
1985,
12,
267,
776,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
277,
423,
498,
9,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
665,
312,
9,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
2695,
312,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
508,
312,
9,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
2356,
312,
9,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
690,
312,
9,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
1137,
312,
9,
339,
347,
485,
5785,
8,
277,
12,
1163,
12,
1083,
304,
267,
340,
440,
1228,
8,
1848,
12,
26866,
26925,
304,
288,
372,
3784,
398,
372,
1083,
8,
277,
423,
498,
12,
1163,
423,
498,
9,
421,
199,
533,
15665,
11791,
8,
785,
304,
272,
408,
2765,
17651,
6117,
14,
339,
961,
365,
18329,
370,
1336,
8837,
63,
3174,
1159,
32414,
367,
10023,
367,
272,
6117,
12,
701,
7664,
6497,
436,
10023,
367,
5827,
6220,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2342,
63,
4614,
12,
1478,
63,
3603,
12,
326,
2040,
63,
5159,
16729,
2040,
63,
324,
12949,
16729,
326,
2040,
63,
452,
63,
5159,
29,
797,
12,
2040,
63,
452,
63,
25648,
29,
797,
12,
326,
19427,
63,
5146,
29,
403,
12,
2112,
63,
8575,
63,
4614,
29,
797,
12,
326,
2351,
29,
403,
12,
1475,
63,
2785,
29,
403,
304,
267,
408,
2499,
282,
15665,
11791,
14,
398,
520,
635,
1475,
63,
2785,
26,
437,
9701,
3717,
909,
503,
488,
14,
8051,
370,
3304,
288,
314,
7267,
402,
1350,
6117,
1182,
3366,
6117,
1380,
13447,
427,
316,
288,
314,
1478,
436,
6220,
14,
267,
408,
267,
340,
2351,
365,
488,
26,
288,
746,
3146,
8,
355,
298,
8599,
11791,
342,
4124,
413,
1415,
4252,
1423,
26,
298,
355,
3546,
1730,
4065,
288,
776,
398,
327,
6516,
2342,
63,
4614,
14,
982,
376,
1423,
9174,
543,
6146,
12,
652,
1443,
506,
267,
327,
282,
2257,
570,
3847,
370,
282,
5629,
2082,
14,
2002,
862,
3293,
9147,
267,
327,
652,
436,
340,
652,
3495,
12,
675,
314,
9657,
1015,
14,
267,
327,
961,
365,
9122,
605,
13824,
406,
7297,
1905,
446,
652,
5594,
506,
15701,
2951,
370,
267,
327,
330,
24491,
590,
7666,
7003,
6617,
543,
282,
6146,
1396,
267,
291,
14,
1623,
63,
4614,
275,
942,
267,
367,
2142,
315,
2342,
63,
4614,
26,
288,
340,
2142,
14,
2460,
21114,
735,
355,
892,
63,
1073,
275,
7666,
63,
515,
8,
1073,
9,
355,
340,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
badock/nova
|
nova/api/openstack/compute/contrib/quota_classes.py
|
13
|
4976
|
# Copyright 2012 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 webob
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
import nova.context
from nova import db
from nova import exception
from nova.i18n import _
from nova import quota
from nova import utils
QUOTAS = quota.QUOTAS
# Quotas that are only enabled by specific extensions
EXTENDED_QUOTAS = {'server_groups': 'os-server-group-quotas',
'server_group_members': 'os-server-group-quotas'}
authorize = extensions.extension_authorizer('compute', 'quota_classes')
class QuotaClassTemplate(xmlutil.TemplateBuilder):
def construct(self):
root = xmlutil.TemplateElement('quota_class_set',
selector='quota_class_set')
root.set('id')
for resource in QUOTAS.resources:
if resource not in EXTENDED_QUOTAS:
elem = xmlutil.SubTemplateElement(root, resource)
elem.text = resource
return xmlutil.MasterTemplate(root, 1)
class QuotaClassSetsController(wsgi.Controller):
supported_quotas = []
def __init__(self, ext_mgr):
self.ext_mgr = ext_mgr
self.supported_quotas = QUOTAS.resources
for resource, extension in EXTENDED_QUOTAS.items():
if not self.ext_mgr.is_loaded(extension):
self.supported_quotas.remove(resource)
def _format_quota_set(self, quota_class, quota_set):
"""Convert the quota object to a result dict."""
if quota_class:
result = dict(id=str(quota_class))
else:
result = {}
for resource in self.supported_quotas:
if resource in quota_set:
result[resource] = quota_set[resource]
return dict(quota_class_set=result)
@wsgi.serializers(xml=QuotaClassTemplate)
def show(self, req, id):
context = req.environ['nova.context']
authorize(context)
try:
nova.context.authorize_quota_class_context(context, id)
values = QUOTAS.get_class_quotas(context, id)
return self._format_quota_set(id, values)
except exception.Forbidden:
raise webob.exc.HTTPForbidden()
@wsgi.serializers(xml=QuotaClassTemplate)
def update(self, req, id, body):
context = req.environ['nova.context']
authorize(context)
quota_class = id
bad_keys = []
if not self.is_valid_body(body, 'quota_class_set'):
msg = _("quota_class_set not specified")
raise webob.exc.HTTPBadRequest(explanation=msg)
quota_class_set = body['quota_class_set']
for key in quota_class_set.keys():
if key not in self.supported_quotas:
bad_keys.append(key)
continue
try:
value = utils.validate_integer(
body['quota_class_set'][key], key)
except exception.InvalidInput as e:
raise webob.exc.HTTPBadRequest(
explanation=e.format_message())
if bad_keys:
msg = _("Bad key(s) %s in quota_set") % ",".join(bad_keys)
raise webob.exc.HTTPBadRequest(explanation=msg)
for key in quota_class_set.keys():
value = utils.validate_integer(
body['quota_class_set'][key], key)
try:
db.quota_class_update(context, quota_class, key, value)
except exception.QuotaClassNotFound:
db.quota_class_create(context, quota_class, key, value)
except exception.AdminRequired:
raise webob.exc.HTTPForbidden()
values = QUOTAS.get_class_quotas(context, quota_class)
return self._format_quota_set(None, values)
class Quota_classes(extensions.ExtensionDescriptor):
"""Quota classes management support."""
name = "QuotaClasses"
alias = "os-quota-class-sets"
namespace = ("http://docs.openstack.org/compute/ext/"
"quota-classes-sets/api/v1.1")
updated = "2012-03-12T00:00:00Z"
def get_resources(self):
resources = []
res = extensions.ResourceExtension('os-quota-class-sets',
QuotaClassSetsController(self.ext_mgr))
resources.append(res)
return resources
|
apache-2.0
|
[
3,
1898,
6029,
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,
14568,
199,
199,
504,
5913,
14,
1246,
14,
8512,
492,
5478,
199,
504,
5913,
14,
1246,
14,
8512,
492,
12464,
199,
504,
5913,
14,
1246,
14,
8512,
492,
2748,
1974,
199,
646,
5913,
14,
1100,
199,
504,
5913,
492,
1592,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
199,
504,
5913,
492,
12132,
199,
504,
5913,
492,
3778,
421,
199,
18654,
1179,
275,
12132,
14,
18654,
1179,
199,
3,
5843,
357,
305,
626,
787,
1454,
5223,
701,
2488,
5478,
199,
27059,
63,
18654,
1179,
275,
791,
1000,
63,
2634,
356,
283,
736,
13,
1000,
13,
923,
13,
17056,
297,
673,
283,
1000,
63,
923,
63,
6334,
356,
283,
736,
13,
1000,
13,
923,
13,
17056,
936,
421,
199,
14204,
275,
5478,
14,
3435,
63,
2502,
1793,
360,
3357,
297,
283,
8848,
63,
2888,
358,
421,
199,
533,
5843,
12041,
2543,
4231,
8,
1652,
1974,
14,
4231,
6437,
304,
272,
347,
6982,
8,
277,
304,
267,
1738,
275,
2748,
1974,
14,
4231,
2162,
360,
8848,
63,
533,
63,
409,
297,
4318,
9759,
534,
8848,
63,
533,
63,
409,
358,
267,
1738,
14,
409,
360,
344,
358,
398,
367,
2073,
315,
11364,
1179,
14,
4435,
26,
288,
340,
2073,
440,
315,
20203,
25518,
63,
18654,
1179,
26,
355,
6193,
275,
2748,
1974,
14,
2610,
4231,
2162,
8,
1231,
12,
2073,
9,
355,
6193,
14,
505,
275,
2073,
398,
372,
2748,
1974,
14,
12288,
4231,
8,
1231,
12,
413,
9,
421,
199,
533,
5843,
12041,
2543,
9899,
7506,
8,
6508,
14,
7506,
304,
339,
3748,
63,
17056,
275,
942,
339,
347,
636,
826,
721,
277,
12,
1599,
63,
7755,
304,
267,
291,
14,
832,
63,
7755,
275,
1599,
63,
7755,
267,
291,
14,
4946,
63,
17056,
275,
11364,
1179,
14,
4435,
267,
367,
2073,
12,
3329,
315,
20203,
25518,
63,
18654,
1179,
14,
1744,
837,
288,
340,
440,
291,
14,
832,
63,
7755,
14,
374,
63,
4591,
8,
3435,
304,
355,
291,
14,
4946,
63,
17056,
14,
2168,
8,
1927,
9,
339,
347,
485,
908,
63,
8848,
63,
409,
8,
277,
12,
12132,
63,
533,
12,
12132,
63,
409,
304,
267,
408,
7306,
314,
12132,
909,
370,
282,
754,
1211,
1041,
398,
340,
12132,
63,
533,
26,
288,
754,
275,
1211,
8,
344,
29,
495,
8,
8848,
63,
533,
430,
267,
587,
26,
288,
754,
275,
1052,
398,
367,
2073,
315,
291,
14,
4946,
63,
17056,
26,
288,
340,
2073,
315,
12132,
63,
409,
26,
355,
754,
59,
1927,
61,
275,
12132,
63,
409,
59,
1927,
61,
398,
372,
1211,
8,
8848,
63,
533,
63,
409,
29,
1099,
9,
339,
768,
6508,
14,
12844,
8,
1652,
29,
17610,
2543,
4231,
9,
272,
347,
2498,
8,
277,
12,
2648,
12,
1305,
304,
267,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
267,
20210,
8,
1100,
9,
267,
862,
26,
288,
5913,
14,
1100,
14,
14204,
63,
8848,
63,
533,
63,
1100,
8,
1100,
12,
1305,
9,
288,
1338,
275,
11364,
1179,
14,
362,
63,
533,
63,
17056,
8,
1100,
12,
1305,
9,
288,
372,
291,
423,
908,
63,
8848,
63,
409,
8,
344,
12,
1338,
9,
267,
871,
1919,
14,
17454,
26,
288,
746,
14568,
14,
2804,
14,
2856,
17454,
342,
339,
768,
6508,
14,
12844,
8,
1652,
29,
17610,
2543,
4231,
9,
272,
347,
1678,
8,
277,
12,
2648,
12,
1305,
12,
2396,
304,
267,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
267,
20210,
8,
1100,
9,
267,
12132,
63,
533,
275,
1305,
267,
4875,
63,
1612,
275,
942,
398,
340,
440,
291,
14,
374,
63,
1078,
63,
2030,
8,
2030,
12,
283,
8848,
63,
533,
63,
409,
735,
288,
1499,
275,
3824,
8848,
63,
533,
63,
409,
440,
2013,
531,
288,
746,
14568,
14,
2804,
14,
21070,
8,
15228,
29,
1328,
9,
267,
12132,
63,
533,
63,
409,
275,
2396,
459,
8848,
63,
533,
63,
409,
418,
267,
367,
790,
315,
12132,
63,
533,
63,
409,
14,
1612,
837,
288,
340,
790,
440,
315,
291,
14,
4946,
63,
17056,
26,
355,
4875,
63,
1612,
14,
740,
8,
498,
9,
355,
1980,
288,
862,
26,
355,
574,
275,
3778,
14,
3502,
63,
4115,
8,
717,
2396,
459,
8848,
63,
533,
63,
409,
3488,
498,
467,
790,
9,
288,
871,
1919,
14,
3364,
3205,
465,
325,
26,
355,
746,
14568,
14,
2804,
14,
21070,
8,
490,
17531,
29,
69,
14,
908,
63,
1188,
1012,
398,
340,
4875,
63,
1612,
26,
288,
1499,
275,
3824,
5725,
790,
8,
83,
9,
450,
83,
315,
12132,
63,
409,
531,
450,
19089,
904,
8,
4087,
63,
1612,
9,
288,
746,
14568,
14,
2804,
14,
21070,
8,
15228,
29,
1328,
9,
398,
367,
790,
315,
12132,
63,
533,
63,
409,
14,
1612,
837,
288,
574,
275,
3778,
14,
3502,
63,
4115,
8,
717,
2396,
459,
8848,
63,
533,
63,
409,
3488,
498,
467,
790,
9,
288,
862,
26,
355,
1592,
14,
8848,
63,
533,
63,
873,
8,
1100,
12,
12132,
63,
533,
12,
790,
12,
574,
9,
288,
871,
1919,
14,
17610,
2543,
4667,
26,
355,
1592,
14,
8848,
63,
533,
63,
981,
8,
1100,
12,
12132,
63,
533,
12,
790,
12,
574,
9,
288,
871,
1919,
14,
4880,
8030,
26,
355,
746,
14568,
14,
2804,
14,
2856,
17454
] |
[
1898,
6029,
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,
14568,
199,
199,
504,
5913,
14,
1246,
14,
8512,
492,
5478,
199,
504,
5913,
14,
1246,
14,
8512,
492,
12464,
199,
504,
5913,
14,
1246,
14,
8512,
492,
2748,
1974,
199,
646,
5913,
14,
1100,
199,
504,
5913,
492,
1592,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
199,
504,
5913,
492,
12132,
199,
504,
5913,
492,
3778,
421,
199,
18654,
1179,
275,
12132,
14,
18654,
1179,
199,
3,
5843,
357,
305,
626,
787,
1454,
5223,
701,
2488,
5478,
199,
27059,
63,
18654,
1179,
275,
791,
1000,
63,
2634,
356,
283,
736,
13,
1000,
13,
923,
13,
17056,
297,
673,
283,
1000,
63,
923,
63,
6334,
356,
283,
736,
13,
1000,
13,
923,
13,
17056,
936,
421,
199,
14204,
275,
5478,
14,
3435,
63,
2502,
1793,
360,
3357,
297,
283,
8848,
63,
2888,
358,
421,
199,
533,
5843,
12041,
2543,
4231,
8,
1652,
1974,
14,
4231,
6437,
304,
272,
347,
6982,
8,
277,
304,
267,
1738,
275,
2748,
1974,
14,
4231,
2162,
360,
8848,
63,
533,
63,
409,
297,
4318,
9759,
534,
8848,
63,
533,
63,
409,
358,
267,
1738,
14,
409,
360,
344,
358,
398,
367,
2073,
315,
11364,
1179,
14,
4435,
26,
288,
340,
2073,
440,
315,
20203,
25518,
63,
18654,
1179,
26,
355,
6193,
275,
2748,
1974,
14,
2610,
4231,
2162,
8,
1231,
12,
2073,
9,
355,
6193,
14,
505,
275,
2073,
398,
372,
2748,
1974,
14,
12288,
4231,
8,
1231,
12,
413,
9,
421,
199,
533,
5843,
12041,
2543,
9899,
7506,
8,
6508,
14,
7506,
304,
339,
3748,
63,
17056,
275,
942,
339,
347,
636,
826,
721,
277,
12,
1599,
63,
7755,
304,
267,
291,
14,
832,
63,
7755,
275,
1599,
63,
7755,
267,
291,
14,
4946,
63,
17056,
275,
11364,
1179,
14,
4435,
267,
367,
2073,
12,
3329,
315,
20203,
25518,
63,
18654,
1179,
14,
1744,
837,
288,
340,
440,
291,
14,
832,
63,
7755,
14,
374,
63,
4591,
8,
3435,
304,
355,
291,
14,
4946,
63,
17056,
14,
2168,
8,
1927,
9,
339,
347,
485,
908,
63,
8848,
63,
409,
8,
277,
12,
12132,
63,
533,
12,
12132,
63,
409,
304,
267,
408,
7306,
314,
12132,
909,
370,
282,
754,
1211,
1041,
398,
340,
12132,
63,
533,
26,
288,
754,
275,
1211,
8,
344,
29,
495,
8,
8848,
63,
533,
430,
267,
587,
26,
288,
754,
275,
1052,
398,
367,
2073,
315,
291,
14,
4946,
63,
17056,
26,
288,
340,
2073,
315,
12132,
63,
409,
26,
355,
754,
59,
1927,
61,
275,
12132,
63,
409,
59,
1927,
61,
398,
372,
1211,
8,
8848,
63,
533,
63,
409,
29,
1099,
9,
339,
768,
6508,
14,
12844,
8,
1652,
29,
17610,
2543,
4231,
9,
272,
347,
2498,
8,
277,
12,
2648,
12,
1305,
304,
267,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
267,
20210,
8,
1100,
9,
267,
862,
26,
288,
5913,
14,
1100,
14,
14204,
63,
8848,
63,
533,
63,
1100,
8,
1100,
12,
1305,
9,
288,
1338,
275,
11364,
1179,
14,
362,
63,
533,
63,
17056,
8,
1100,
12,
1305,
9,
288,
372,
291,
423,
908,
63,
8848,
63,
409,
8,
344,
12,
1338,
9,
267,
871,
1919,
14,
17454,
26,
288,
746,
14568,
14,
2804,
14,
2856,
17454,
342,
339,
768,
6508,
14,
12844,
8,
1652,
29,
17610,
2543,
4231,
9,
272,
347,
1678,
8,
277,
12,
2648,
12,
1305,
12,
2396,
304,
267,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
267,
20210,
8,
1100,
9,
267,
12132,
63,
533,
275,
1305,
267,
4875,
63,
1612,
275,
942,
398,
340,
440,
291,
14,
374,
63,
1078,
63,
2030,
8,
2030,
12,
283,
8848,
63,
533,
63,
409,
735,
288,
1499,
275,
3824,
8848,
63,
533,
63,
409,
440,
2013,
531,
288,
746,
14568,
14,
2804,
14,
21070,
8,
15228,
29,
1328,
9,
267,
12132,
63,
533,
63,
409,
275,
2396,
459,
8848,
63,
533,
63,
409,
418,
267,
367,
790,
315,
12132,
63,
533,
63,
409,
14,
1612,
837,
288,
340,
790,
440,
315,
291,
14,
4946,
63,
17056,
26,
355,
4875,
63,
1612,
14,
740,
8,
498,
9,
355,
1980,
288,
862,
26,
355,
574,
275,
3778,
14,
3502,
63,
4115,
8,
717,
2396,
459,
8848,
63,
533,
63,
409,
3488,
498,
467,
790,
9,
288,
871,
1919,
14,
3364,
3205,
465,
325,
26,
355,
746,
14568,
14,
2804,
14,
21070,
8,
490,
17531,
29,
69,
14,
908,
63,
1188,
1012,
398,
340,
4875,
63,
1612,
26,
288,
1499,
275,
3824,
5725,
790,
8,
83,
9,
450,
83,
315,
12132,
63,
409,
531,
450,
19089,
904,
8,
4087,
63,
1612,
9,
288,
746,
14568,
14,
2804,
14,
21070,
8,
15228,
29,
1328,
9,
398,
367,
790,
315,
12132,
63,
533,
63,
409,
14,
1612,
837,
288,
574,
275,
3778,
14,
3502,
63,
4115,
8,
717,
2396,
459,
8848,
63,
533,
63,
409,
3488,
498,
467,
790,
9,
288,
862,
26,
355,
1592,
14,
8848,
63,
533,
63,
873,
8,
1100,
12,
12132,
63,
533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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
] |
meyburgh/googletest
|
scripts/gen_gtest_pred_impl.py
|
2538
|
21986
|
#!/usr/bin/env python
#
# Copyright 2006, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""gen_gtest_pred_impl.py v0.1
Generates the implementation of Google Test predicate assertions and
accompanying tests.
Usage:
gen_gtest_pred_impl.py MAX_ARITY
where MAX_ARITY is a positive integer.
The command generates the implementation of up-to MAX_ARITY-ary
predicate assertions, and writes it to file gtest_pred_impl.h in the
directory where the script is. It also generates the accompanying
unit test in file gtest_pred_impl_unittest.cc.
"""
__author__ = 'wan@google.com (Zhanyong Wan)'
import os
import sys
import time
# Where this script is.
SCRIPT_DIR = os.path.dirname(sys.argv[0])
# Where to store the generated header.
HEADER = os.path.join(SCRIPT_DIR, '../include/gtest/gtest_pred_impl.h')
# Where to store the generated unit test.
UNIT_TEST = os.path.join(SCRIPT_DIR, '../test/gtest_pred_impl_unittest.cc')
def HeaderPreamble(n):
"""Returns the preamble for the header file.
Args:
n: the maximum arity of the predicate macros to be generated.
"""
# A map that defines the values used in the preamble template.
DEFS = {
'today' : time.strftime('%m/%d/%Y'),
'year' : time.strftime('%Y'),
'command' : '%s %s' % (os.path.basename(sys.argv[0]), n),
'n' : n
}
return (
"""// Copyright 2006, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This file is AUTOMATICALLY GENERATED on %(today)s by command
// '%(command)s'. DO NOT EDIT BY HAND!
//
// Implements a family of generic predicate assertion macros.
#ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
#define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
// Makes sure this header is not included before gtest.h.
#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
# error Do not include gtest_pred_impl.h directly. Include gtest.h instead.
#endif // GTEST_INCLUDE_GTEST_GTEST_H_
// This header implements a family of generic predicate assertion
// macros:
//
// ASSERT_PRED_FORMAT1(pred_format, v1)
// ASSERT_PRED_FORMAT2(pred_format, v1, v2)
// ...
//
// where pred_format is a function or functor that takes n (in the
// case of ASSERT_PRED_FORMATn) values and their source expression
// text, and returns a testing::AssertionResult. See the definition
// of ASSERT_EQ in gtest.h for an example.
//
// If you don't care about formatting, you can use the more
// restrictive version:
//
// ASSERT_PRED1(pred, v1)
// ASSERT_PRED2(pred, v1, v2)
// ...
//
// where pred is an n-ary function or functor that returns bool,
// and the values v1, v2, ..., must support the << operator for
// streaming to std::ostream.
//
// We also define the EXPECT_* variations.
//
// For now we only support predicates whose arity is at most %(n)s.
// Please email googletestframework@googlegroups.com if you need
// support for higher arities.
// GTEST_ASSERT_ is the basic statement to which all of the assertions
// in this file reduce. Don't use this in your code.
#define GTEST_ASSERT_(expression, on_failure) \\
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \\
if (const ::testing::AssertionResult gtest_ar = (expression)) \\
; \\
else \\
on_failure(gtest_ar.failure_message())
""" % DEFS)
def Arity(n):
"""Returns the English name of the given arity."""
if n < 0:
return None
elif n <= 3:
return ['nullary', 'unary', 'binary', 'ternary'][n]
else:
return '%s-ary' % n
def Title(word):
"""Returns the given word in title case. The difference between
this and string's title() method is that Title('4-ary') is '4-ary'
while '4-ary'.title() is '4-Ary'."""
return word[0].upper() + word[1:]
def OneTo(n):
"""Returns the list [1, 2, 3, ..., n]."""
return range(1, n + 1)
def Iter(n, format, sep=''):
"""Given a positive integer n, a format string that contains 0 or
more '%s' format specs, and optionally a separator string, returns
the join of n strings, each formatted with the format string on an
iterator ranged from 1 to n.
Example:
Iter(3, 'v%s', sep=', ') returns 'v1, v2, v3'.
"""
# How many '%s' specs are in format?
spec_count = len(format.split('%s')) - 1
return sep.join([format % (spec_count * (i,)) for i in OneTo(n)])
def ImplementationForArity(n):
"""Returns the implementation of n-ary predicate assertions."""
# A map the defines the values used in the implementation template.
DEFS = {
'n' : str(n),
'vs' : Iter(n, 'v%s', sep=', '),
'vts' : Iter(n, '#v%s', sep=', '),
'arity' : Arity(n),
'Arity' : Title(Arity(n))
}
impl = """
// Helper function for implementing {EXPECT|ASSERT}_PRED%(n)s. Don't use
// this in your code.
template <typename Pred""" % DEFS
impl += Iter(n, """,
typename T%s""")
impl += """>
AssertionResult AssertPred%(n)sHelper(const char* pred_text""" % DEFS
impl += Iter(n, """,
const char* e%s""")
impl += """,
Pred pred"""
impl += Iter(n, """,
const T%s& v%s""")
impl += """) {
if (pred(%(vs)s)) return AssertionSuccess();
""" % DEFS
impl += ' return AssertionFailure() << pred_text << "("'
impl += Iter(n, """
<< e%s""", sep=' << ", "')
impl += ' << ") evaluates to false, where"'
impl += Iter(n, """
<< "\\n" << e%s << " evaluates to " << v%s""")
impl += """;
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT%(n)s.
// Don't use this in your code.
#define GTEST_PRED_FORMAT%(n)s_(pred_format, %(vs)s, on_failure)\\
GTEST_ASSERT_(pred_format(%(vts)s, %(vs)s), \\
on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED%(n)s. Don't use
// this in your code.
#define GTEST_PRED%(n)s_(pred, %(vs)s, on_failure)\\
GTEST_ASSERT_(::testing::AssertPred%(n)sHelper(#pred""" % DEFS
impl += Iter(n, """, \\
#v%s""")
impl += """, \\
pred"""
impl += Iter(n, """, \\
v%s""")
impl += """), on_failure)
// %(Arity)s predicate assertion macros.
#define EXPECT_PRED_FORMAT%(n)s(pred_format, %(vs)s) \\
GTEST_PRED_FORMAT%(n)s_(pred_format, %(vs)s, GTEST_NONFATAL_FAILURE_)
#define EXPECT_PRED%(n)s(pred, %(vs)s) \\
GTEST_PRED%(n)s_(pred, %(vs)s, GTEST_NONFATAL_FAILURE_)
#define ASSERT_PRED_FORMAT%(n)s(pred_format, %(vs)s) \\
GTEST_PRED_FORMAT%(n)s_(pred_format, %(vs)s, GTEST_FATAL_FAILURE_)
#define ASSERT_PRED%(n)s(pred, %(vs)s) \\
GTEST_PRED%(n)s_(pred, %(vs)s, GTEST_FATAL_FAILURE_)
""" % DEFS
return impl
def HeaderPostamble():
"""Returns the postamble for the header file."""
return """
#endif // GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
"""
def GenerateFile(path, content):
"""Given a file path and a content string, overwrites it with the
given content."""
print 'Updating file %s . . .' % path
f = file(path, 'w+')
print >>f, content,
f.close()
print 'File %s has been updated.' % path
def GenerateHeader(n):
"""Given the maximum arity n, updates the header file that implements
the predicate assertions."""
GenerateFile(HEADER,
HeaderPreamble(n)
+ ''.join([ImplementationForArity(i) for i in OneTo(n)])
+ HeaderPostamble())
def UnitTestPreamble():
"""Returns the preamble for the unit test file."""
# A map that defines the values used in the preamble template.
DEFS = {
'today' : time.strftime('%m/%d/%Y'),
'year' : time.strftime('%Y'),
'command' : '%s %s' % (os.path.basename(sys.argv[0]), sys.argv[1]),
}
return (
"""// Copyright 2006, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This file is AUTOMATICALLY GENERATED on %(today)s by command
// '%(command)s'. DO NOT EDIT BY HAND!
// Regression test for gtest_pred_impl.h
//
// This file is generated by a script and quite long. If you intend to
// learn how Google Test works by reading its unit tests, read
// gtest_unittest.cc instead.
//
// This is intended as a regression test for the Google Test predicate
// assertions. We compile it as part of the gtest_unittest target
// only to keep the implementation tidy and compact, as it is quite
// involved to set up the stage for testing Google Test using Google
// Test itself.
//
// Currently, gtest_unittest takes ~11 seconds to run in the testing
// daemon. In the future, if it grows too large and needs much more
// time to finish, we should consider separating this file into a
// stand-alone regression test.
#include <iostream>
#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
// A user-defined data type.
struct Bool {
explicit Bool(int val) : value(val != 0) {}
bool operator>(int n) const { return value > Bool(n).value; }
Bool operator+(const Bool& rhs) const { return Bool(value + rhs.value); }
bool operator==(const Bool& rhs) const { return value == rhs.value; }
bool value;
};
// Enables Bool to be used in assertions.
std::ostream& operator<<(std::ostream& os, const Bool& x) {
return os << (x.value ? "true" : "false");
}
""" % DEFS)
def TestsForArity(n):
"""Returns the tests for n-ary predicate assertions."""
# A map that defines the values used in the template for the tests.
DEFS = {
'n' : n,
'es' : Iter(n, 'e%s', sep=', '),
'vs' : Iter(n, 'v%s', sep=', '),
'vts' : Iter(n, '#v%s', sep=', '),
'tvs' : Iter(n, 'T%s v%s', sep=', '),
'int_vs' : Iter(n, 'int v%s', sep=', '),
'Bool_vs' : Iter(n, 'Bool v%s', sep=', '),
'types' : Iter(n, 'typename T%s', sep=', '),
'v_sum' : Iter(n, 'v%s', sep=' + '),
'arity' : Arity(n),
'Arity' : Title(Arity(n)),
}
tests = (
"""// Sample functions/functors for testing %(arity)s predicate assertions.
// A %(arity)s predicate function.
template <%(types)s>
bool PredFunction%(n)s(%(tvs)s) {
return %(v_sum)s > 0;
}
// The following two functions are needed to circumvent a bug in
// gcc 2.95.3, which sometimes has problem with the above template
// function.
bool PredFunction%(n)sInt(%(int_vs)s) {
return %(v_sum)s > 0;
}
bool PredFunction%(n)sBool(%(Bool_vs)s) {
return %(v_sum)s > 0;
}
""" % DEFS)
tests += """
// A %(arity)s predicate functor.
struct PredFunctor%(n)s {
template <%(types)s>
bool operator()(""" % DEFS
tests += Iter(n, 'const T%s& v%s', sep=""",
""")
tests += """) {
return %(v_sum)s > 0;
}
};
""" % DEFS
tests += """
// A %(arity)s predicate-formatter function.
template <%(types)s>
testing::AssertionResult PredFormatFunction%(n)s(""" % DEFS
tests += Iter(n, 'const char* e%s', sep=""",
""")
tests += Iter(n, """,
const T%s& v%s""")
tests += """) {
if (PredFunction%(n)s(%(vs)s))
return testing::AssertionSuccess();
return testing::AssertionFailure()
<< """ % DEFS
tests += Iter(n, 'e%s', sep=' << " + " << ')
tests += """
<< " is expected to be positive, but evaluates to "
<< %(v_sum)s << ".";
}
""" % DEFS
tests += """
// A %(arity)s predicate-formatter functor.
struct PredFormatFunctor%(n)s {
template <%(types)s>
testing::AssertionResult operator()(""" % DEFS
tests += Iter(n, 'const char* e%s', sep=""",
""")
tests += Iter(n, """,
const T%s& v%s""")
tests += """) const {
return PredFormatFunction%(n)s(%(es)s, %(vs)s);
}
};
""" % DEFS
tests += """
// Tests for {EXPECT|ASSERT}_PRED_FORMAT%(n)s.
class Predicate%(n)sTest : public testing::Test {
protected:
virtual void SetUp() {
expected_to_finish_ = true;
finished_ = false;""" % DEFS
tests += """
""" + Iter(n, 'n%s_ = ') + """0;
}
"""
tests += """
virtual void TearDown() {
// Verifies that each of the predicate's arguments was evaluated
// exactly once."""
tests += ''.join(["""
EXPECT_EQ(1, n%s_) <<
"The predicate assertion didn't evaluate argument %s "
"exactly once.";""" % (i, i + 1) for i in OneTo(n)])
tests += """
// Verifies that the control flow in the test function is expected.
if (expected_to_finish_ && !finished_) {
FAIL() << "The predicate assertion unexpactedly aborted the test.";
} else if (!expected_to_finish_ && finished_) {
FAIL() << "The failed predicate assertion didn't abort the test "
"as expected.";
}
}
// true iff the test function is expected to run to finish.
static bool expected_to_finish_;
// true iff the test function did run to finish.
static bool finished_;
""" % DEFS
tests += Iter(n, """
static int n%s_;""")
tests += """
};
bool Predicate%(n)sTest::expected_to_finish_;
bool Predicate%(n)sTest::finished_;
""" % DEFS
tests += Iter(n, """int Predicate%%(n)sTest::n%s_;
""") % DEFS
tests += """
typedef Predicate%(n)sTest EXPECT_PRED_FORMAT%(n)sTest;
typedef Predicate%(n)sTest ASSERT_PRED_FORMAT%(n)sTest;
typedef Predicate%(n)sTest EXPECT_PRED%(n)sTest;
typedef Predicate%(n)sTest ASSERT_PRED%(n)sTest;
""" % DEFS
def GenTest(use_format, use_assert, expect_failure,
use_functor, use_user_type):
"""Returns the test for a predicate assertion macro.
Args:
use_format: true iff the assertion is a *_PRED_FORMAT*.
use_assert: true iff the assertion is a ASSERT_*.
expect_failure: true iff the assertion is expected to fail.
use_functor: true iff the first argument of the assertion is
a functor (as opposed to a function)
use_user_type: true iff the predicate functor/function takes
argument(s) of a user-defined type.
Example:
GenTest(1, 0, 0, 1, 0) returns a test that tests the behavior
of a successful EXPECT_PRED_FORMATn() that takes a functor
whose arguments have built-in types."""
if use_assert:
assrt = 'ASSERT' # 'assert' is reserved, so we cannot use
# that identifier here.
else:
assrt = 'EXPECT'
assertion = assrt + '_PRED'
if use_format:
pred_format = 'PredFormat'
assertion += '_FORMAT'
else:
pred_format = 'Pred'
assertion += '%(n)s' % DEFS
if use_functor:
pred_format_type = 'functor'
pred_format += 'Functor%(n)s()'
else:
pred_format_type = 'function'
pred_format += 'Function%(n)s'
if not use_format:
if use_user_type:
pred_format += 'Bool'
else:
pred_format += 'Int'
test_name = pred_format_type.title()
if use_user_type:
arg_type = 'user-defined type (Bool)'
test_name += 'OnUserType'
if expect_failure:
arg = 'Bool(n%s_++)'
else:
arg = 'Bool(++n%s_)'
else:
arg_type = 'built-in type (int)'
test_name += 'OnBuiltInType'
if expect_failure:
arg = 'n%s_++'
else:
arg = '++n%s_'
if expect_failure:
successful_or_failed = 'failed'
expected_or_not = 'expected.'
test_name += 'Failure'
else:
successful_or_failed = 'successful'
expected_or_not = 'UNEXPECTED!'
test_name += 'Success'
# A map that defines the values used in the test template.
defs = DEFS.copy()
defs.update({
'assert' : assrt,
'assertion' : assertion,
'test_name' : test_name,
'pf_type' : pred_format_type,
'pf' : pred_format,
'arg_type' : arg_type,
'arg' : arg,
'successful' : successful_or_failed,
'expected' : expected_or_not,
})
test = """
// Tests a %(successful)s %(assertion)s where the
// predicate-formatter is a %(pf_type)s on a %(arg_type)s.
TEST_F(%(assertion)sTest, %(test_name)s) {""" % defs
indent = (len(assertion) + 3)*' '
extra_indent = ''
if expect_failure:
extra_indent = ' '
if use_assert:
test += """
expected_to_finish_ = false;
EXPECT_FATAL_FAILURE({ // NOLINT"""
else:
test += """
EXPECT_NONFATAL_FAILURE({ // NOLINT"""
test += '\n' + extra_indent + """ %(assertion)s(%(pf)s""" % defs
test = test % defs
test += Iter(n, ',\n' + indent + extra_indent + '%(arg)s' % defs)
test += ');\n' + extra_indent + ' finished_ = true;\n'
if expect_failure:
test += ' }, "");\n'
test += '}\n'
return test
# Generates tests for all 2**6 = 64 combinations.
tests += ''.join([GenTest(use_format, use_assert, expect_failure,
use_functor, use_user_type)
for use_format in [0, 1]
for use_assert in [0, 1]
for expect_failure in [0, 1]
for use_functor in [0, 1]
for use_user_type in [0, 1]
])
return tests
def UnitTestPostamble():
"""Returns the postamble for the tests."""
return ''
def GenerateUnitTest(n):
"""Returns the tests for up-to n-ary predicate assertions."""
GenerateFile(UNIT_TEST,
UnitTestPreamble()
+ ''.join([TestsForArity(i) for i in OneTo(n)])
+ UnitTestPostamble())
def _Main():
"""The entry point of the script. Generates the header file and its
unit test."""
if len(sys.argv) != 2:
print __doc__
print 'Author: ' + __author__
sys.exit(1)
n = int(sys.argv[1])
GenerateHeader(n)
GenerateUnitTest(n)
if __name__ == '__main__':
_Main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8315,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
2268,
63,
8385,
63,
5991,
63,
5472,
14,
647,
373,
16,
14,
17,
199,
199,
20551,
314,
4514,
402,
4475,
1379,
11944,
22835,
436,
199,
645,
4627,
316,
2295,
14,
199,
199,
7692,
26,
819,
3805,
63,
8385,
63,
5991,
63,
5472,
14,
647,
9141,
63,
689,
1922,
199,
199,
4509,
9141,
63,
689,
1922,
365,
282,
7317,
3000,
14,
199,
199,
1918,
1414,
12821,
314,
4514,
402,
1536,
13,
475,
9141,
63,
689,
1922,
13,
695,
199,
14463,
22835,
12,
436,
14511,
652,
370,
570,
9088,
63,
5991,
63,
5472,
14,
72,
315,
314,
199,
3619,
2382,
314,
2884,
365,
14,
221,
2779,
2597,
12821,
314,
23073,
199,
3248,
511,
315,
570,
9088,
63,
5991,
63,
5472,
63,
2796,
14,
2055,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
20444,
32,
3098,
14,
957,
334,
12674,
1629,
951,
644,
290,
3171,
199,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
199,
3,
17685,
642,
2884,
365,
14,
199,
10484,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
566,
199,
199,
3,
17685,
370,
3877,
314,
4046,
1406,
14,
199,
7311,
275,
747,
14,
515,
14,
904,
8,
10484,
63,
3022,
12,
20644,
2613,
15,
8385,
15,
8385,
63,
5991,
63,
5472,
14,
72,
358,
199,
199,
3,
17685,
370,
3877,
314,
4046,
4137,
511,
14,
199,
15505,
63,
2864,
275,
747,
14,
515,
14,
904,
8,
10484,
63,
3022,
12,
20644,
396,
15,
8385,
63,
5991,
63,
5472,
63,
2796,
14,
2055,
358,
421,
199,
318,
10240,
29423,
8,
78,
304,
523,
408,
3407,
314,
19789,
367,
314,
1406,
570,
14,
819,
3033,
26,
272,
302,
26,
221,
314,
5696,
14554,
369,
402,
314,
11944,
16954,
370,
506,
4046,
14,
523,
408,
819,
327,
437,
2341,
626,
7890,
314,
1338,
1202,
315,
314,
19789,
1978,
14,
523,
28259,
275,
469,
272,
283,
8136,
7,
520,
900,
14,
6205,
3508,
77,
3149,
68,
3149,
57,
659,
272,
283,
3403,
7,
520,
900,
14,
6205,
3508,
57,
659,
272,
283,
1531,
7,
520,
1543,
83,
450,
83,
7,
450,
334,
736,
14,
515,
14,
4846,
8,
1274,
14,
3020,
59,
16,
2522,
302,
395,
272,
283,
78,
7,
520,
302,
272,
789,
819,
372,
334,
199,
624,
501,
1898,
8315,
12,
4475,
3277,
14,
199,
501,
2900,
4481,
4644,
14,
199,
501,
199,
501,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
501,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
501,
7647,
26,
199,
501,
199,
501,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
501,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
501,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
501,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
501,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
501,
4084,
14,
199,
501,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
501,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
501,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
501,
199,
501,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
501,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
501,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
501,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
501,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
501,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
501,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
501,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
501,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
501,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
501,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8315,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
2268,
63,
8385,
63,
5991,
63,
5472,
14,
647,
373,
16,
14,
17,
199,
199,
20551,
314,
4514,
402,
4475,
1379,
11944,
22835,
436,
199,
645,
4627,
316,
2295,
14,
199,
199,
7692,
26,
819,
3805,
63,
8385,
63,
5991,
63,
5472,
14,
647,
9141,
63,
689,
1922,
199,
199,
4509,
9141,
63,
689,
1922,
365,
282,
7317,
3000,
14,
199,
199,
1918,
1414,
12821,
314,
4514,
402,
1536,
13,
475,
9141,
63,
689,
1922,
13,
695,
199,
14463,
22835,
12,
436,
14511,
652,
370,
570,
9088,
63,
5991,
63,
5472,
14,
72,
315,
314,
199,
3619,
2382,
314,
2884,
365,
14,
221,
2779,
2597,
12821,
314,
23073,
199,
3248,
511,
315,
570,
9088,
63,
5991,
63,
5472,
63,
2796,
14,
2055,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
20444,
32,
3098,
14,
957,
334,
12674,
1629,
951,
644,
290,
3171,
199,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
199,
3,
17685,
642,
2884,
365,
14,
199,
10484,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
566,
199,
199,
3,
17685,
370,
3877,
314,
4046,
1406,
14,
199,
7311,
275,
747,
14,
515,
14,
904,
8,
10484,
63,
3022,
12,
20644,
2613,
15,
8385,
15,
8385,
63,
5991,
63,
5472,
14,
72,
358,
199,
199,
3,
17685,
370,
3877,
314,
4046,
4137,
511,
14,
199,
15505,
63,
2864,
275,
747,
14,
515,
14,
904,
8,
10484,
63,
3022,
12,
20644,
396,
15,
8385,
63,
5991,
63,
5472,
63,
2796,
14,
2055,
358,
421,
199,
318,
10240,
29423,
8,
78,
304,
523,
408,
3407,
314,
19789,
367,
314,
1406,
570,
14,
819,
3033,
26,
272,
302,
26,
221,
314,
5696,
14554,
369,
402,
314,
11944,
16954,
370,
506,
4046,
14,
523,
408,
819,
327,
437,
2341,
626,
7890,
314,
1338,
1202,
315,
314,
19789,
1978,
14,
523,
28259,
275,
469,
272,
283,
8136,
7,
520,
900,
14,
6205,
3508,
77,
3149,
68,
3149,
57,
659,
272,
283,
3403,
7,
520,
900,
14,
6205,
3508,
57,
659,
272,
283,
1531,
7,
520,
1543,
83,
450,
83,
7,
450,
334,
736,
14,
515,
14,
4846,
8,
1274,
14,
3020,
59,
16,
2522,
302,
395,
272,
283,
78,
7,
520,
302,
272,
789,
819,
372,
334,
199,
624,
501,
1898,
8315,
12,
4475,
3277,
14,
199,
501,
2900,
4481,
4644,
14,
199,
501,
199,
501,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
501,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
501,
7647,
26,
199,
501,
199,
501,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
501,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
501,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
501,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
501,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
501,
4084,
14,
199,
501,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
501,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
501,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
501,
199,
501,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
501,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
501,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
501,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
501,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
501,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
501,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
501,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
501,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
501,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
501,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ldhwin/pywinauto
|
pywinauto/__init__.py
|
14
|
1225
|
# GUI Application automation and testing library
# Copyright (C) 2006 Mark Mc Mahon
#
# 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.,
# 59 Temple Place,
# Suite 330,
# Boston, MA 02111-1307 USA
"""
Python package for automating GUI manipulation on Windows
"""
__revision__ = "$Revision$"
__version__ = "0.4.2"
import findwindows
WindowAmbiguousError = findwindows.WindowAmbiguousError
WindowNotFoundError = findwindows.WindowNotFoundError
import findbestmatch
MatchError = findbestmatch.MatchError
from application import Application, WindowSpecification
|
lgpl-2.1
|
[
3,
17160,
13515,
25461,
436,
5343,
3555,
202,
199,
3,
1898,
334,
35,
9,
8315,
7173,
22895,
603,
11326,
265,
202,
199,
3,
202,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
202,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
202,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
14,
17,
202,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
202,
199,
3,
202,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
202,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
202,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
202,
199,
3,
1666,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
202,
199,
3,
202,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
202,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
202,
199,
3,
259,
2868,
2290,
2752,
12,
3277,
2020,
202,
199,
3,
259,
8155,
15630,
10902,
12,
202,
199,
3,
259,
14453,
13540,
12,
202,
199,
3,
259,
8226,
12,
4828,
15673,
13,
13421,
8217,
2999,
199,
624,
202,
199,
4718,
2559,
367,
2599,
569,
316,
17160,
26212,
641,
5417,
2999,
199,
624,
202,
199,
363,
5792,
363,
275,
7880,
12714,
17351,
202,
199,
363,
1023,
363,
275,
298,
16,
14,
20,
14,
18,
2,
2999,
199,
646,
2342,
8258,
202,
199,
4301,
29209,
20357,
547,
275,
2342,
8258,
14,
4301,
29209,
20357,
547,
202,
199,
4301,
10870,
275,
2342,
8258,
14,
4301,
10870,
2999,
199,
646,
2342,
7010,
1431,
202,
199,
4486,
547,
275,
2342,
7010,
1431,
14,
4486,
547,
2999,
199,
504,
4223,
492,
13515,
12,
15689,
26235,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
17160,
13515,
25461,
436,
5343,
3555,
202,
199,
3,
1898,
334,
35,
9,
8315,
7173,
22895,
603,
11326,
265,
202,
199,
3,
202,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
202,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
202,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
14,
17,
202,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
202,
199,
3,
202,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
202,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
202,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
202,
199,
3,
1666,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
202,
199,
3,
202,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
202,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
202,
199,
3,
259,
2868,
2290,
2752,
12,
3277,
2020,
202,
199,
3,
259,
8155,
15630,
10902,
12,
202,
199,
3,
259,
14453,
13540,
12,
202,
199,
3,
259,
8226,
12,
4828,
15673,
13,
13421,
8217,
2999,
199,
624,
202,
199,
4718,
2559,
367,
2599,
569,
316,
17160,
26212,
641,
5417,
2999,
199,
624,
202,
199,
363,
5792,
363,
275,
7880,
12714,
17351,
202,
199,
363,
1023,
363,
275,
298,
16,
14,
20,
14,
18,
2,
2999,
199,
646,
2342,
8258,
202,
199,
4301,
29209,
20357,
547,
275,
2342,
8258,
14,
4301,
29209,
20357,
547,
202,
199,
4301,
10870,
275,
2342,
8258,
14,
4301,
10870,
2999,
199,
646,
2342,
7010,
1431,
202,
199,
4486,
547,
275,
2342,
7010,
1431,
14,
4486,
547,
2999,
199,
504,
4223,
492,
13515,
12,
15689,
26235,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
ujjvala-addsol/addsol_hr
|
openerp/addons/stock_landed_costs/stock_landed_costs.py
|
56
|
18361
|
# -*- 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
import openerp.addons.decimal_precision as dp
from openerp.tools.translate import _
import product
class stock_landed_cost(osv.osv):
_name = 'stock.landed.cost'
_description = 'Stock Landed Cost'
_inherit = 'mail.thread'
_track = {
'state': {
'stock_landed_costs.mt_stock_landed_cost_open': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'done',
},
}
def _total_amount(self, cr, uid, ids, name, args, context=None):
result = {}
for cost in self.browse(cr, uid, ids, context=context):
total = 0.0
for line in cost.cost_lines:
total += line.price_unit
result[cost.id] = total
return result
def _get_cost_line(self, cr, uid, ids, context=None):
cost_to_recompute = []
for line in self.pool.get('stock.landed.cost.lines').browse(cr, uid, ids, context=context):
cost_to_recompute.append(line.cost_id.id)
return cost_to_recompute
def get_valuation_lines(self, cr, uid, ids, picking_ids=None, context=None):
picking_obj = self.pool.get('stock.picking')
lines = []
if not picking_ids:
return lines
for picking in picking_obj.browse(cr, uid, picking_ids):
for move in picking.move_lines:
#it doesn't make sense to make a landed cost for a product that isn't set as being valuated in real time at real cost
if move.product_id.valuation != 'real_time' or move.product_id.cost_method != 'real':
continue
total_cost = 0.0
total_qty = move.product_qty
weight = move.product_id and move.product_id.weight * move.product_qty
volume = move.product_id and move.product_id.volume * move.product_qty
for quant in move.quant_ids:
total_cost += quant.cost
vals = dict(product_id=move.product_id.id, move_id=move.id, quantity=move.product_uom_qty, former_cost=total_cost * total_qty, weight=weight, volume=volume)
lines.append(vals)
if not lines:
raise osv.except_osv(_('Error!'), _('The selected picking does not contain any move that would be impacted by landed costs. Landed costs are only possible for products configured in real time valuation with real price costing method. Please make sure it is the case, or you selected the correct picking'))
return lines
_columns = {
'name': fields.char('Name', track_visibility='always', readonly=True, copy=False),
'date': fields.date('Date', required=True, states={'done': [('readonly', True)]}, track_visibility='onchange', copy=False),
'picking_ids': fields.many2many('stock.picking', string='Pickings', states={'done': [('readonly', True)]}, copy=False),
'cost_lines': fields.one2many('stock.landed.cost.lines', 'cost_id', 'Cost Lines', states={'done': [('readonly', True)]}, copy=True),
'valuation_adjustment_lines': fields.one2many('stock.valuation.adjustment.lines', 'cost_id', 'Valuation Adjustments', states={'done': [('readonly', True)]}),
'description': fields.text('Item Description', states={'done': [('readonly', True)]}),
'amount_total': fields.function(_total_amount, type='float', string='Total', digits_compute=dp.get_precision('Account'),
store={
'stock.landed.cost': (lambda self, cr, uid, ids, c={}: ids, ['cost_lines'], 20),
'stock.landed.cost.lines': (_get_cost_line, ['price_unit', 'quantity', 'cost_id'], 20),
}, track_visibility='always'
),
'state': fields.selection([('draft', 'Draft'), ('done', 'Posted'), ('cancel', 'Cancelled')], 'State', readonly=True, track_visibility='onchange', copy=False),
'account_move_id': fields.many2one('account.move', 'Journal Entry', readonly=True, copy=False),
'account_journal_id': fields.many2one('account.journal', 'Account Journal', required=True),
}
_defaults = {
'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'stock.landed.cost'),
'state': 'draft',
'date': fields.date.context_today,
}
def _create_accounting_entries(self, cr, uid, line, move_id, qty_out, context=None):
product_obj = self.pool.get('product.template')
cost_product = line.cost_line_id and line.cost_line_id.product_id
if not cost_product:
return False
accounts = product_obj.get_product_accounts(cr, uid, line.product_id.product_tmpl_id.id, context=context)
debit_account_id = accounts['property_stock_valuation_account_id']
already_out_account_id = accounts['stock_account_output']
credit_account_id = line.cost_line_id.account_id.id or cost_product.property_account_expense.id or cost_product.categ_id.property_account_expense_categ.id
if not credit_account_id:
raise osv.except_osv(_('Error!'), _('Please configure Stock Expense Account for product: %s.') % (cost_product.name))
return self._create_account_move_line(cr, uid, line, move_id, credit_account_id, debit_account_id, qty_out, already_out_account_id, context=context)
def _create_account_move_line(self, cr, uid, line, move_id, credit_account_id, debit_account_id, qty_out, already_out_account_id, context=None):
"""
Generate the account.move.line values to track the landed cost.
Afterwards, for the goods that are already out of stock, we should create the out moves
"""
aml_obj = self.pool.get('account.move.line')
aml_obj.create(cr, uid, {
'name': line.name,
'move_id': move_id,
'product_id': line.product_id.id,
'quantity': line.quantity,
'debit': line.additional_landed_cost,
'account_id': debit_account_id
}, context=context)
aml_obj.create(cr, uid, {
'name': line.name,
'move_id': move_id,
'product_id': line.product_id.id,
'quantity': line.quantity,
'credit': line.additional_landed_cost,
'account_id': credit_account_id
}, context=context)
#Create account move lines for quants already out of stock
if qty_out > 0:
aml_obj.create(cr, uid, {
'name': line.name + ": " + str(qty_out) + _(' already out'),
'move_id': move_id,
'product_id': line.product_id.id,
'quantity': qty_out,
'credit': line.additional_landed_cost * qty_out / line.quantity,
'account_id': debit_account_id
}, context=context)
aml_obj.create(cr, uid, {
'name': line.name + ": " + str(qty_out) + _(' already out'),
'move_id': move_id,
'product_id': line.product_id.id,
'quantity': qty_out,
'debit': line.additional_landed_cost * qty_out / line.quantity,
'account_id': already_out_account_id
}, context=context)
return True
def _create_account_move(self, cr, uid, cost, context=None):
vals = {
'journal_id': cost.account_journal_id.id,
'period_id': self.pool.get('account.period').find(cr, uid, cost.date, context=context)[0],
'date': cost.date,
'ref': cost.name
}
return self.pool.get('account.move').create(cr, uid, vals, context=context)
def _check_sum(self, cr, uid, landed_cost, context=None):
"""
Will check if each cost line its valuation lines sum to the correct amount
and if the overall total amount is correct also
"""
costcor = {}
tot = 0
for valuation_line in landed_cost.valuation_adjustment_lines:
if costcor.get(valuation_line.cost_line_id):
costcor[valuation_line.cost_line_id] += valuation_line.additional_landed_cost
else:
costcor[valuation_line.cost_line_id] = valuation_line.additional_landed_cost
tot += valuation_line.additional_landed_cost
res = (tot == landed_cost.amount_total)
for costl in costcor.keys():
if costcor[costl] != costl.price_unit:
res = False
return res
def button_validate(self, cr, uid, ids, context=None):
quant_obj = self.pool.get('stock.quant')
for cost in self.browse(cr, uid, ids, context=context):
if not cost.valuation_adjustment_lines or not self._check_sum(cr, uid, cost, context=context):
raise osv.except_osv(_('Error!'), _('You cannot validate a landed cost which has no valid valuation lines.'))
move_id = self._create_account_move(cr, uid, cost, context=context)
quant_dict = {}
for line in cost.valuation_adjustment_lines:
if not line.move_id:
continue
per_unit = line.final_cost / line.quantity
diff = per_unit - line.former_cost_per_unit
quants = [quant for quant in line.move_id.quant_ids]
for quant in quants:
if quant.id not in quant_dict:
quant_dict[quant.id] = quant.cost + diff
else:
quant_dict[quant.id] += diff
for key, value in quant_dict.items():
quant_obj.write(cr, uid, key, {'cost': value}, context=context)
qty_out = 0
for quant in line.move_id.quant_ids:
if quant.location_id.usage != 'internal':
qty_out += quant.qty
self._create_accounting_entries(cr, uid, line, move_id, qty_out, context=context)
self.write(cr, uid, cost.id, {'state': 'done', 'account_move_id': move_id}, context=context)
return True
def button_cancel(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state': 'cancel'}, context=context)
return True
def compute_landed_cost(self, cr, uid, ids, context=None):
line_obj = self.pool.get('stock.valuation.adjustment.lines')
unlink_ids = line_obj.search(cr, uid, [('cost_id', 'in', ids)], context=context)
line_obj.unlink(cr, uid, unlink_ids, context=context)
towrite_dict = {}
for cost in self.browse(cr, uid, ids, context=None):
if not cost.picking_ids:
continue
picking_ids = [p.id for p in cost.picking_ids]
total_qty = 0.0
total_cost = 0.0
total_weight = 0.0
total_volume = 0.0
total_line = 0.0
vals = self.get_valuation_lines(cr, uid, [cost.id], picking_ids=picking_ids, context=context)
for v in vals:
for line in cost.cost_lines:
v.update({'cost_id': cost.id, 'cost_line_id': line.id})
self.pool.get('stock.valuation.adjustment.lines').create(cr, uid, v, context=context)
total_qty += v.get('quantity', 0.0)
total_cost += v.get('former_cost', 0.0)
total_weight += v.get('weight', 0.0)
total_volume += v.get('volume', 0.0)
total_line += 1
for line in cost.cost_lines:
for valuation in cost.valuation_adjustment_lines:
value = 0.0
if valuation.cost_line_id and valuation.cost_line_id.id == line.id:
if line.split_method == 'by_quantity' and total_qty:
per_unit = (line.price_unit / total_qty)
value = valuation.quantity * per_unit
elif line.split_method == 'by_weight' and total_weight:
per_unit = (line.price_unit / total_weight)
value = valuation.weight * per_unit
elif line.split_method == 'by_volume' and total_volume:
per_unit = (line.price_unit / total_volume)
value = valuation.volume * per_unit
elif line.split_method == 'equal':
value = (line.price_unit / total_line)
elif line.split_method == 'by_current_cost_price' and total_cost:
per_unit = (line.price_unit / total_cost)
value = valuation.former_cost * per_unit
else:
value = (line.price_unit / total_line)
if valuation.id not in towrite_dict:
towrite_dict[valuation.id] = value
else:
towrite_dict[valuation.id] += value
if towrite_dict:
for key, value in towrite_dict.items():
line_obj.write(cr, uid, key, {'additional_landed_cost': value}, context=context)
return True
class stock_landed_cost_lines(osv.osv):
_name = 'stock.landed.cost.lines'
_description = 'Stock Landed Cost Lines'
def onchange_product_id(self, cr, uid, ids, product_id=False, context=None):
result = {}
if not product_id:
return {'value': {'quantity': 0.0, 'price_unit': 0.0}}
product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
result['name'] = product.name
result['split_method'] = product.split_method
result['price_unit'] = product.standard_price
result['account_id'] = product.property_account_expense and product.property_account_expense.id or product.categ_id.property_account_expense_categ.id
return {'value': result}
_columns = {
'name': fields.char('Description'),
'cost_id': fields.many2one('stock.landed.cost', 'Landed Cost', required=True, ondelete='cascade'),
'product_id': fields.many2one('product.product', 'Product', required=True),
'price_unit': fields.float('Cost', required=True, digits_compute=dp.get_precision('Product Price')),
'split_method': fields.selection(product.SPLIT_METHOD, string='Split Method', required=True),
'account_id': fields.many2one('account.account', 'Account', domain=[('type', '<>', 'view'), ('type', '<>', 'closed')]),
}
class stock_valuation_adjustment_lines(osv.osv):
_name = 'stock.valuation.adjustment.lines'
_description = 'Stock Valuation Adjustment Lines'
def _amount_final(self, cr, uid, ids, name, args, context=None):
result = {}
for line in self.browse(cr, uid, ids, context=context):
result[line.id] = {
'former_cost_per_unit': 0.0,
'final_cost': 0.0,
}
result[line.id]['former_cost_per_unit'] = (line.former_cost / line.quantity if line.quantity else 1.0)
result[line.id]['final_cost'] = (line.former_cost + line.additional_landed_cost)
return result
def _get_name(self, cr, uid, ids, name, arg, context=None):
res = {}
for line in self.browse(cr, uid, ids, context=context):
res[line.id] = line.product_id.code or line.product_id.name or ''
if line.cost_line_id:
res[line.id] += ' - ' + line.cost_line_id.name
return res
_columns = {
'name': fields.function(_get_name, type='char', string='Description', store=True),
'cost_id': fields.many2one('stock.landed.cost', 'Landed Cost', required=True, ondelete='cascade'),
'cost_line_id': fields.many2one('stock.landed.cost.lines', 'Cost Line', readonly=True),
'move_id': fields.many2one('stock.move', 'Stock Move', readonly=True),
'product_id': fields.many2one('product.product', 'Product', required=True),
'quantity': fields.float('Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), required=True),
'weight': fields.float('Weight', digits_compute=dp.get_precision('Product Unit of Measure')),
'volume': fields.float('Volume', digits_compute=dp.get_precision('Product Unit of Measure')),
'former_cost': fields.float('Former Cost', digits_compute=dp.get_precision('Product Price')),
'former_cost_per_unit': fields.function(_amount_final, multi='cost', string='Former Cost(Per Unit)', type='float', digits_compute=dp.get_precision('Account'), store=True),
'additional_landed_cost': fields.float('Additional Landed Cost', digits_compute=dp.get_precision('Product Price')),
'final_cost': fields.function(_amount_final, multi='cost', string='Final Cost', type='float', digits_compute=dp.get_precision('Account'), store=True),
}
_defaults = {
'quantity': 1.0,
'weight': 1.0,
'volume': 1.0,
}
# 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,
646,
5166,
14,
10788,
14,
6355,
63,
6833,
465,
12392,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
646,
3336,
421,
199,
533,
10952,
63,
1502,
770,
63,
6336,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
283,
6088,
14,
1502,
770,
14,
6336,
7,
272,
485,
1802,
275,
283,
17103,
491,
7028,
24681,
7,
272,
485,
6486,
275,
283,
1198,
14,
2671,
7,
339,
485,
3885,
275,
469,
267,
283,
929,
356,
469,
288,
283,
6088,
63,
1502,
770,
63,
25432,
14,
2037,
63,
6088,
63,
1502,
770,
63,
6336,
63,
1490,
356,
2400,
291,
12,
2467,
12,
1747,
12,
1559,
12,
4027,
29,
403,
26,
1559,
459,
929,
418,
508,
283,
4456,
297,
267,
1660,
272,
789,
339,
347,
485,
2923,
63,
4606,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1249,
12,
1067,
29,
403,
304,
267,
754,
275,
1052,
267,
367,
7918,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
3141,
275,
378,
14,
16,
288,
367,
1004,
315,
7918,
14,
6336,
63,
1278,
26,
355,
3141,
847,
1004,
14,
4777,
63,
3248,
288,
754,
59,
6336,
14,
344,
61,
275,
3141,
267,
372,
754,
339,
347,
485,
362,
63,
6336,
63,
604,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
7918,
63,
475,
63,
264,
3357,
275,
942,
267,
367,
1004,
315,
291,
14,
2293,
14,
362,
360,
6088,
14,
1502,
770,
14,
6336,
14,
1278,
1959,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
7918,
63,
475,
63,
264,
3357,
14,
740,
8,
604,
14,
6336,
63,
344,
14,
344,
9,
267,
372,
7918,
63,
475,
63,
264,
3357,
339,
347,
664,
63,
27456,
63,
1278,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
12433,
63,
1580,
29,
403,
12,
1067,
29,
403,
304,
267,
12433,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
6088,
14,
11463,
358,
267,
2385,
275,
942,
267,
340,
440,
12433,
63,
1580,
26,
288,
372,
2385,
398,
367,
12433,
315,
12433,
63,
1113,
14,
4570,
8,
1556,
12,
1747,
12,
12433,
63,
1580,
304,
288,
367,
4057,
315,
12433,
14,
1185,
63,
1278,
26,
355,
327,
390,
3181,
1133,
1852,
12249,
370,
1852,
282,
634,
7028,
7918,
367,
282,
3336,
626,
5712,
1133,
663,
465,
3769,
1139,
23130,
315,
3363,
900,
737,
3363,
7918,
355,
340,
4057,
14,
2558,
63,
344,
14,
27456,
1137,
283,
3093,
63,
521,
7,
503,
4057,
14,
2558,
63,
344,
14,
6336,
63,
765,
1137,
283,
3093,
356,
490,
1980,
355,
3141,
63,
6336,
275,
378,
14,
16,
355,
3141,
63,
5643,
275,
4057,
14,
2558,
63,
5643,
355,
5401,
275,
4057,
14,
2558,
63,
344,
436,
4057,
14,
2558,
63,
344,
14,
3463,
627,
4057,
14,
2558,
63,
5643,
355,
3301,
275,
4057,
14,
2558,
63,
344,
436,
4057,
14,
2558,
63,
344,
14,
2405,
627,
4057,
14,
2558,
63,
5643,
355,
367,
15381,
315,
4057,
14,
13603,
63,
1580,
26,
490,
3141,
63,
6336,
847,
15381,
14,
6336,
355,
5322,
275,
1211,
8,
2558,
63,
344,
29,
1185,
14,
2558,
63,
344,
14,
344,
12,
4057,
63,
344,
29,
1185,
14,
344,
12,
12524,
29,
1185,
14,
2558,
63,
7519,
63,
5643,
12,
26610,
63,
6336,
29,
2923,
63,
6336,
627,
3141,
63,
5643,
12,
5401,
29,
3463,
12,
3301,
29,
2405,
9,
355,
2385,
14,
740,
8,
3643,
9,
267,
340,
440,
2385,
26,
288,
746,
9506,
14,
2590,
63,
4795,
6723,
547,
15659,
4018,
1918,
4895,
12433,
1630,
440,
1395,
1263,
4057,
626,
3955,
506,
1742,
645,
471,
701,
634,
7028,
26819,
14,
491,
7028,
26819,
787,
1454,
3962,
367,
7585,
7526,
315,
3363,
900,
1139,
4086,
543,
3363,
8033,
7918,
316,
1083,
14,
7754,
1852,
3238,
652,
365,
314,
1930,
12,
503,
1265,
4895,
314,
3211,
12433,
1333,
267,
372,
2385,
339,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
985,
297,
4426,
63,
11269,
534,
9223,
297,
6863,
29,
549,
12,
1331,
29,
797,
395,
267,
283,
602,
356,
1504,
14,
602,
360,
2506,
297,
1415,
29,
549,
12,
6363,
3713,
4456,
356,
4274,
6753,
297,
715,
26804,
4426,
63,
11269,
534,
18128,
297,
1331,
29,
797,
395,
267,
283,
11463,
63,
1580,
356,
1504,
14,
3479,
18,
3479,
360,
6088,
14,
11463,
297,
1059,
534,
8587,
780,
297,
6363,
3713,
4456,
356,
4274,
6753,
297,
715,
26804,
1331,
29,
797,
395,
267,
283,
6336,
63,
1278,
356,
1504,
14,
368,
18,
3479,
360,
6088,
14,
1502,
770,
14,
6336,
14,
1278,
297,
283,
6336,
63,
344,
297,
283,
15568,
29406,
297,
6363,
3713,
4456,
356,
4274,
6753,
297,
715,
26804,
1331,
29,
549,
395,
267,
283,
27456,
63,
21806,
63,
1278,
356,
1504,
14,
368,
18,
3479,
360,
6088,
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,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
646,
5166,
14,
10788,
14,
6355,
63,
6833,
465,
12392,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
646,
3336,
421,
199,
533,
10952,
63,
1502,
770,
63,
6336,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
283,
6088,
14,
1502,
770,
14,
6336,
7,
272,
485,
1802,
275,
283,
17103,
491,
7028,
24681,
7,
272,
485,
6486,
275,
283,
1198,
14,
2671,
7,
339,
485,
3885,
275,
469,
267,
283,
929,
356,
469,
288,
283,
6088,
63,
1502,
770,
63,
25432,
14,
2037,
63,
6088,
63,
1502,
770,
63,
6336,
63,
1490,
356,
2400,
291,
12,
2467,
12,
1747,
12,
1559,
12,
4027,
29,
403,
26,
1559,
459,
929,
418,
508,
283,
4456,
297,
267,
1660,
272,
789,
339,
347,
485,
2923,
63,
4606,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1249,
12,
1067,
29,
403,
304,
267,
754,
275,
1052,
267,
367,
7918,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
3141,
275,
378,
14,
16,
288,
367,
1004,
315,
7918,
14,
6336,
63,
1278,
26,
355,
3141,
847,
1004,
14,
4777,
63,
3248,
288,
754,
59,
6336,
14,
344,
61,
275,
3141,
267,
372,
754,
339,
347,
485,
362,
63,
6336,
63,
604,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
7918,
63,
475,
63,
264,
3357,
275,
942,
267,
367,
1004,
315,
291,
14,
2293,
14,
362,
360,
6088,
14,
1502,
770,
14,
6336,
14,
1278,
1959,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
7918,
63,
475,
63,
264,
3357,
14,
740,
8,
604,
14,
6336,
63,
344,
14,
344,
9,
267,
372,
7918,
63,
475,
63,
264,
3357,
339,
347,
664,
63,
27456,
63,
1278,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
12433,
63,
1580,
29,
403,
12,
1067,
29,
403,
304,
267,
12433,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
6088,
14,
11463,
358,
267,
2385,
275,
942,
267,
340,
440,
12433,
63,
1580,
26,
288,
372,
2385,
398,
367,
12433,
315,
12433,
63,
1113,
14,
4570,
8,
1556,
12,
1747,
12,
12433,
63,
1580,
304,
288,
367,
4057,
315,
12433,
14,
1185,
63,
1278,
26,
355,
327,
390,
3181,
1133,
1852,
12249,
370,
1852,
282,
634,
7028,
7918,
367,
282,
3336,
626,
5712,
1133,
663,
465,
3769,
1139,
23130,
315,
3363,
900,
737,
3363,
7918,
355,
340,
4057,
14,
2558,
63,
344,
14,
27456,
1137,
283,
3093,
63,
521,
7,
503,
4057,
14,
2558,
63,
344,
14,
6336,
63,
765,
1137,
283,
3093,
356,
490,
1980,
355,
3141,
63,
6336,
275,
378,
14,
16,
355,
3141,
63,
5643,
275,
4057,
14,
2558,
63,
5643,
355,
5401,
275,
4057,
14,
2558,
63,
344,
436,
4057,
14,
2558,
63,
344,
14,
3463,
627,
4057,
14,
2558,
63,
5643,
355,
3301,
275,
4057,
14,
2558,
63,
344,
436,
4057,
14,
2558,
63,
344,
14,
2405,
627,
4057,
14,
2558,
63,
5643,
355,
367,
15381,
315,
4057,
14,
13603,
63,
1580,
26,
490,
3141,
63,
6336,
847,
15381,
14,
6336,
355,
5322,
275,
1211,
8,
2558,
63,
344,
29,
1185,
14,
2558,
63,
344,
14,
344,
12,
4057,
63,
344,
29,
1185,
14,
344,
12,
12524,
29,
1185,
14,
2558,
63,
7519,
63,
5643,
12,
26610,
63,
6336,
29,
2923,
63,
6336,
627,
3141,
63,
5643,
12,
5401,
29,
3463,
12,
3301,
29,
2405,
9,
355,
2385,
14,
740,
8,
3643,
9,
267,
340,
440,
2385,
26,
288,
746,
9506,
14,
2590,
63,
4795,
6723,
547,
15659,
4018,
1918,
4895,
12433,
1630,
440,
1395,
1263,
4057,
626,
3955,
506,
1742,
645,
471,
701,
634,
7028,
26819,
14,
491,
7028,
26819,
787,
1454,
3962,
367,
7585,
7526,
315,
3363,
900,
1139,
4086,
543,
3363,
8033,
7918,
316,
1083,
14,
7754,
1852,
3238,
652,
365,
314,
1930,
12,
503,
1265,
4895,
314,
3211,
12433,
1333,
267,
372,
2385,
339,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
985,
297,
4426,
63,
11269,
534,
9223,
297,
6863,
29,
549,
12,
1331,
29,
797,
395,
267,
283,
602,
356,
1504,
14,
602,
360,
2506,
297,
1415,
29,
549,
12,
6363,
3713,
4456,
356,
4274,
6753,
297,
715,
26804,
4426,
63,
11269,
534,
18128,
297,
1331,
29,
797,
395,
267,
283,
11463,
63,
1580,
356,
1504,
14,
3479,
18,
3479,
360,
6088,
14,
11463,
297,
1059,
534,
8587,
780,
297,
6363,
3713,
4456,
356,
4274,
6753,
297,
715,
26804,
1331,
29,
797,
395,
267,
283,
6336,
63,
1278,
356,
1504,
14,
368,
18,
3479,
360,
6088,
14,
1502,
770,
14,
6336,
14,
1278,
297,
283,
6336,
63,
344,
297,
283,
15568,
29406,
297,
6363,
3713,
4456,
356,
4274,
6753,
297,
715,
26804,
1331,
29,
549,
395,
267,
283,
27456,
63,
21806,
63,
1278,
356,
1504,
14,
368,
18,
3479,
360,
6088,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
jaredmichaelsmith/grove
|
api/resources/UserResource.py
|
1
|
1057
|
# -*- coding: utf-8 -*-
"""HTTP resources for the comment entities."""
# Third-Party modules
from flask_restful import Resource
from flask_restful import fields
from flask_restful import marshal_with
from flask_restful import current_app
# Project specific modules
from api.models import User
from api.utils import abort_not_exist, require_login
class UserResource(Resource):
"""Class for handling User model API interactions"""
user_fields = {
'date_created': fields.DateTime,
'id': fields.String(attribute='uuid'),
'email': fields.String,
'first_name': fields.String,
'last_name': fields.String,
'photo': fields.String
}
def __init__(self):
pass
@marshal_with(user_fields)
@require_login
def get(self, user, user_id=None):
"""Get a user based on user_id"""
current_app.logger.debug(repr(user))
user = User.query.filter_by(uuid=user_id).first()
if user is None:
abort_not_exist(user_id, 'User')
return user
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
421,
199,
624,
2856,
5944,
367,
314,
3721,
9045,
1041,
421,
199,
3,
31079,
13,
25233,
4621,
199,
504,
7209,
63,
3911,
1893,
492,
7337,
199,
504,
7209,
63,
3911,
1893,
492,
1504,
199,
504,
7209,
63,
3911,
1893,
492,
21985,
63,
1045,
199,
504,
7209,
63,
3911,
1893,
492,
1453,
63,
571,
199,
199,
3,
7290,
2488,
4621,
199,
504,
2986,
14,
992,
492,
2876,
199,
504,
2986,
14,
1208,
492,
12004,
63,
1397,
63,
4494,
12,
4409,
63,
2886,
421,
199,
533,
2876,
4031,
8,
4031,
304,
272,
408,
2543,
367,
7252,
2876,
1402,
3261,
315,
22990,
624,
339,
922,
63,
955,
275,
469,
267,
283,
602,
63,
3966,
356,
1504,
14,
3926,
12,
267,
283,
344,
356,
1504,
14,
1558,
8,
3215,
534,
2580,
659,
267,
283,
2123,
356,
1504,
14,
1558,
12,
267,
283,
2246,
63,
354,
356,
1504,
14,
1558,
12,
267,
283,
2019,
63,
354,
356,
1504,
14,
1558,
12,
267,
283,
13834,
356,
1504,
14,
1558,
272,
789,
339,
347,
636,
826,
721,
277,
304,
267,
986,
339,
768,
18376,
63,
1045,
8,
751,
63,
955,
9,
272,
768,
4365,
63,
2886,
272,
347,
664,
8,
277,
12,
922,
12,
922,
63,
344,
29,
403,
304,
267,
408,
1002,
282,
922,
4079,
641,
922,
63,
344,
624,
398,
1453,
63,
571,
14,
2921,
14,
1757,
8,
2722,
8,
751,
430,
398,
922,
275,
2876,
14,
1131,
14,
1541,
63,
991,
8,
2580,
29,
751,
63,
344,
680,
2246,
342,
267,
340,
922,
365,
488,
26,
288,
12004,
63,
1397,
63,
4494,
8,
751,
63,
344,
12,
283,
1899,
358,
398,
372,
922,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
421,
199,
624,
2856,
5944,
367,
314,
3721,
9045,
1041,
421,
199,
3,
31079,
13,
25233,
4621,
199,
504,
7209,
63,
3911,
1893,
492,
7337,
199,
504,
7209,
63,
3911,
1893,
492,
1504,
199,
504,
7209,
63,
3911,
1893,
492,
21985,
63,
1045,
199,
504,
7209,
63,
3911,
1893,
492,
1453,
63,
571,
199,
199,
3,
7290,
2488,
4621,
199,
504,
2986,
14,
992,
492,
2876,
199,
504,
2986,
14,
1208,
492,
12004,
63,
1397,
63,
4494,
12,
4409,
63,
2886,
421,
199,
533,
2876,
4031,
8,
4031,
304,
272,
408,
2543,
367,
7252,
2876,
1402,
3261,
315,
22990,
624,
339,
922,
63,
955,
275,
469,
267,
283,
602,
63,
3966,
356,
1504,
14,
3926,
12,
267,
283,
344,
356,
1504,
14,
1558,
8,
3215,
534,
2580,
659,
267,
283,
2123,
356,
1504,
14,
1558,
12,
267,
283,
2246,
63,
354,
356,
1504,
14,
1558,
12,
267,
283,
2019,
63,
354,
356,
1504,
14,
1558,
12,
267,
283,
13834,
356,
1504,
14,
1558,
272,
789,
339,
347,
636,
826,
721,
277,
304,
267,
986,
339,
768,
18376,
63,
1045,
8,
751,
63,
955,
9,
272,
768,
4365,
63,
2886,
272,
347,
664,
8,
277,
12,
922,
12,
922,
63,
344,
29,
403,
304,
267,
408,
1002,
282,
922,
4079,
641,
922,
63,
344,
624,
398,
1453,
63,
571,
14,
2921,
14,
1757,
8,
2722,
8,
751,
430,
398,
922,
275,
2876,
14,
1131,
14,
1541,
63,
991,
8,
2580,
29,
751,
63,
344,
680,
2246,
342,
267,
340,
922,
365,
488,
26,
288,
12004,
63,
1397,
63,
4494,
8,
751,
63,
344,
12,
283,
1899,
358,
398,
372,
922,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
av8ramit/tensorflow
|
tensorflow/contrib/eager/python/examples/mnist/mnist.py
|
2
|
9148
|
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""A deep MNIST classifier using convolutional layers.
Sample usage:
python mnist.py --help
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import os
import sys
import time
import tensorflow as tf
import tensorflow.contrib.eager as tfe
from tensorflow.examples.tutorials.mnist import input_data
FLAGS = None
class MNISTModel(tfe.Network):
"""MNIST Network.
Network structure is equivalent to:
https://github.com/tensorflow/tensorflow/blob/r1.6/tensorflow/examples/tutorials/mnist/mnist_deep.py
and
https://github.com/tensorflow/models/blob/master/tutorials/image/mnist/convolutional.py
But written using the tf.layers API.
"""
def __init__(self, data_format):
"""Creates a model for classifying a hand-written digit.
Args:
data_format: Either 'channels_first' or 'channels_last'.
'channels_first' is typically faster on GPUs while 'channels_last' is
typically faster on CPUs. See
https://www.tensorflow.org/performance/performance_guide#data_formats
"""
super(MNISTModel, self).__init__(name='')
if data_format == 'channels_first':
self._input_shape = [-1, 1, 28, 28]
else:
assert data_format == 'channels_last'
self._input_shape = [-1, 28, 28, 1]
self.conv1 = self.track_layer(
tf.layers.Conv2D(32, 5, data_format=data_format, activation=tf.nn.relu))
self.conv2 = self.track_layer(
tf.layers.Conv2D(64, 5, data_format=data_format, activation=tf.nn.relu))
self.fc1 = self.track_layer(tf.layers.Dense(1024, activation=tf.nn.relu))
self.fc2 = self.track_layer(tf.layers.Dense(10))
self.dropout = self.track_layer(tf.layers.Dropout(0.5))
self.max_pool2d = self.track_layer(
tf.layers.MaxPooling2D(
(2, 2), (2, 2), padding='SAME', data_format=data_format))
def call(self, inputs, training):
"""Computes labels from inputs.
Users should invoke __call__ to run the network, which delegates to this
method (and not call this method directly).
Args:
inputs: A batch of images as a Tensor with shape [batch_size, 784].
training: True if invoked in the context of training (causing dropout to
be applied). False otherwise.
Returns:
A Tensor with shape [batch_size, 10] containing the predicted logits
for each image in the batch, for each of the 10 classes.
"""
x = tf.reshape(inputs, self._input_shape)
x = self.conv1(x)
x = self.max_pool2d(x)
x = self.conv2(x)
x = self.max_pool2d(x)
x = tf.layers.flatten(x)
x = self.fc1(x)
x = self.dropout(x, training=training)
x = self.fc2(x)
return x
def loss(predictions, labels):
return tf.reduce_mean(
tf.nn.softmax_cross_entropy_with_logits(
logits=predictions, labels=labels))
def compute_accuracy(predictions, labels):
return tf.reduce_sum(
tf.cast(
tf.equal(
tf.argmax(predictions, axis=1,
output_type=tf.int64),
tf.argmax(labels, axis=1,
output_type=tf.int64)),
dtype=tf.float32)) / float(predictions.shape[0].value)
def train_one_epoch(model, optimizer, dataset, log_interval=None):
"""Trains model on `dataset` using `optimizer`."""
tf.train.get_or_create_global_step()
for (batch, (images, labels)) in enumerate(tfe.Iterator(dataset)):
with tf.contrib.summary.record_summaries_every_n_global_steps(10):
with tfe.GradientTape() as tape:
prediction = model(images, training=True)
loss_value = loss(prediction, labels)
tf.contrib.summary.scalar('loss', loss_value)
tf.contrib.summary.scalar('accuracy',
compute_accuracy(prediction, labels))
grads = tape.gradient(loss_value, model.variables)
optimizer.apply_gradients(zip(grads, model.variables))
if log_interval and batch % log_interval == 0:
print('Batch #%d\tLoss: %.6f' % (batch, loss_value))
def test(model, dataset):
"""Perform an evaluation of `model` on the examples from `dataset`."""
avg_loss = tfe.metrics.Mean('loss')
accuracy = tfe.metrics.Accuracy('accuracy')
for (images, labels) in tfe.Iterator(dataset):
predictions = model(images, training=False)
avg_loss(loss(predictions, labels))
accuracy(tf.argmax(predictions, axis=1, output_type=tf.int64),
tf.argmax(labels, axis=1, output_type=tf.int64))
print('Test set: Average loss: %.4f, Accuracy: %4f%%\n' %
(avg_loss.result(), 100 * accuracy.result()))
with tf.contrib.summary.always_record_summaries():
tf.contrib.summary.scalar('loss', avg_loss.result())
tf.contrib.summary.scalar('accuracy', accuracy.result())
def load_data(data_dir):
"""Returns training and test tf.data.Dataset objects."""
data = input_data.read_data_sets(data_dir, one_hot=True)
train_ds = tf.data.Dataset.from_tensor_slices((data.train.images,
data.train.labels))
test_ds = tf.data.Dataset.from_tensors((data.test.images, data.test.labels))
return (train_ds, test_ds)
def main(_):
tfe.enable_eager_execution()
(device, data_format) = ('/gpu:0', 'channels_first')
if FLAGS.no_gpu or tfe.num_gpus() <= 0:
(device, data_format) = ('/cpu:0', 'channels_last')
print('Using device %s, and data format %s.' % (device, data_format))
# Load the datasets
(train_ds, test_ds) = load_data(FLAGS.data_dir)
train_ds = train_ds.shuffle(60000).batch(FLAGS.batch_size)
# Create the model and optimizer
model = MNISTModel(data_format)
optimizer = tf.train.MomentumOptimizer(FLAGS.lr, FLAGS.momentum)
if FLAGS.output_dir:
train_dir = os.path.join(FLAGS.output_dir, 'train')
test_dir = os.path.join(FLAGS.output_dir, 'eval')
tf.gfile.MakeDirs(FLAGS.output_dir)
else:
train_dir = None
test_dir = None
summary_writer = tf.contrib.summary.create_file_writer(
train_dir, flush_millis=10000)
test_summary_writer = tf.contrib.summary.create_file_writer(
test_dir, flush_millis=10000, name='test')
checkpoint_prefix = os.path.join(FLAGS.checkpoint_dir, 'ckpt')
with tf.device(device):
for epoch in range(1, 11):
with tfe.restore_variables_on_create(
tf.train.latest_checkpoint(FLAGS.checkpoint_dir)):
global_step = tf.train.get_or_create_global_step()
start = time.time()
with summary_writer.as_default():
train_one_epoch(model, optimizer, train_ds, FLAGS.log_interval)
end = time.time()
print('\nTrain time for epoch #%d (global step %d): %f' % (
epoch, global_step.numpy(), end - start))
with test_summary_writer.as_default():
test(model, test_ds)
all_variables = (
model.variables
+ optimizer.variables()
+ [global_step])
tfe.Saver(all_variables).save(
checkpoint_prefix, global_step=global_step)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'--data-dir',
type=str,
default='/tmp/tensorflow/mnist/input_data',
help='Directory for storing input data')
parser.add_argument(
'--batch-size',
type=int,
default=64,
metavar='N',
help='input batch size for training (default: 64)')
parser.add_argument(
'--log-interval',
type=int,
default=10,
metavar='N',
help='how many batches to wait before logging training status')
parser.add_argument(
'--output_dir',
type=str,
default=None,
metavar='N',
help='Directory to write TensorBoard summaries')
parser.add_argument(
'--checkpoint_dir',
type=str,
default='/tmp/tensorflow/mnist/checkpoints/',
metavar='N',
help='Directory to save checkpoints in (once per epoch)')
parser.add_argument(
'--lr',
type=float,
default=0.01,
metavar='LR',
help='learning rate (default: 0.01)')
parser.add_argument(
'--momentum',
type=float,
default=0.5,
metavar='M',
help='SGD momentum (default: 0.5)')
parser.add_argument(
'--no-gpu',
action='store_true',
default=False,
help='disables GPU usage even if a GPU is available')
FLAGS, unparsed = parser.parse_known_args()
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
|
apache-2.0
|
[
3,
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
33,
13217,
603,
25392,
12429,
1808,
17461,
279,
9393,
14,
199,
199,
8176,
4503,
26,
523,
2366,
21945,
631,
14,
647,
1553,
3437,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
7534,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
199,
646,
3228,
465,
2833,
199,
199,
646,
3228,
14,
2828,
14,
10283,
465,
307,
771,
199,
504,
3228,
14,
8589,
14,
23561,
83,
14,
32164,
492,
1324,
63,
576,
199,
199,
4831,
275,
488,
421,
199,
533,
603,
25392,
1685,
8,
84,
771,
14,
4491,
304,
523,
408,
16237,
6225,
7220,
14,
819,
7220,
5523,
365,
7353,
370,
26,
523,
4178,
921,
5031,
14,
957,
15,
16008,
15,
16008,
15,
6582,
15,
82,
17,
14,
22,
15,
16008,
15,
8589,
15,
23561,
83,
15,
32164,
15,
32164,
63,
16131,
14,
647,
523,
436,
523,
4178,
921,
5031,
14,
957,
15,
16008,
15,
992,
15,
6582,
15,
4133,
15,
23561,
83,
15,
1569,
15,
32164,
15,
27625,
279,
14,
647,
819,
11017,
5313,
1808,
314,
2833,
14,
4359,
3261,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
666,
63,
908,
304,
272,
408,
10607,
282,
1402,
367,
28837,
316,
282,
4926,
13,
8938,
10964,
14,
339,
3033,
26,
489,
666,
63,
908,
26,
13083,
283,
6324,
63,
2246,
7,
503,
283,
6324,
63,
2019,
1370,
267,
283,
6324,
63,
2246,
7,
365,
13609,
12930,
641,
18613,
83,
1830,
283,
6324,
63,
2019,
7,
365,
267,
13609,
12930,
641,
28504,
14,
1666,
267,
4178,
921,
1544,
14,
16008,
14,
1308,
15,
20576,
15,
20576,
63,
17348,
3,
576,
63,
6321,
272,
408,
272,
1613,
8,
16237,
6225,
1685,
12,
291,
2843,
826,
721,
354,
13275,
272,
340,
666,
63,
908,
508,
283,
6324,
63,
2246,
356,
489,
291,
423,
1210,
63,
1392,
275,
5243,
17,
12,
413,
12,
7294,
12,
7294,
61,
272,
587,
26,
489,
702,
666,
63,
908,
508,
283,
6324,
63,
2019,
7,
489,
291,
423,
1210,
63,
1392,
275,
5243,
17,
12,
7294,
12,
7294,
12,
413,
61,
272,
291,
14,
5598,
17,
275,
291,
14,
3885,
63,
1897,
8,
267,
2833,
14,
4359,
14,
11596,
18,
36,
8,
708,
12,
959,
12,
666,
63,
908,
29,
576,
63,
908,
12,
10361,
29,
3249,
14,
4411,
14,
12833,
430,
272,
291,
14,
5598,
18,
275,
291,
14,
3885,
63,
1897,
8,
267,
2833,
14,
4359,
14,
11596,
18,
36,
8,
772,
12,
959,
12,
666,
63,
908,
29,
576,
63,
908,
12,
10361,
29,
3249,
14,
4411,
14,
12833,
430,
272,
291,
14,
3003,
17,
275,
291,
14,
3885,
63,
1897,
8,
3249,
14,
4359,
14,
15327,
8,
7727,
12,
10361,
29,
3249,
14,
4411,
14,
12833,
430,
272,
291,
14,
3003,
18,
275,
291,
14,
3885,
63,
1897,
8,
3249,
14,
4359,
14,
15327,
8,
709,
430,
272,
291,
14,
17953,
275,
291,
14,
3885,
63,
1897,
8,
3249,
14,
4359,
14,
30662,
8,
16,
14,
21,
430,
272,
291,
14,
988,
63,
2293,
18,
68,
275,
291,
14,
3885,
63,
1897,
8,
267,
2833,
14,
4359,
14,
4261,
22349,
18,
36,
8,
288,
334,
18,
12,
499,
395,
334,
18,
12,
499,
395,
6273,
534,
19935,
297,
666,
63,
908,
29,
576,
63,
908,
430,
819,
347,
1240,
8,
277,
12,
4153,
12,
6093,
304,
272,
408,
22594,
3628,
687,
4153,
14,
339,
20123,
1077,
12677,
636,
1250,
363,
370,
1255,
314,
2784,
12,
1314,
18703,
2335,
370,
642,
272,
1083,
334,
460,
440,
1240,
642,
1083,
5370,
680,
339,
3033,
26,
489,
4153,
26,
437,
3522,
402,
5935,
465,
282,
5878,
543,
2215,
359,
2912,
63,
890,
12,
1520,
1349,
1055,
489,
6093,
26,
715,
340,
10302,
315,
314,
1067,
402,
6093,
334,
696,
4941,
19795,
370,
267,
506,
6781,
680,
221,
756,
4257,
14,
339,
1803,
26,
489,
437,
5878,
543,
2215,
359,
2912,
63,
890,
12,
1616,
61,
3035,
314,
14746,
11051,
489,
367,
1924,
1834,
315,
314,
3522,
12,
367,
1924,
402,
314,
1616,
3992,
14,
272,
408,
339,
671,
275,
2833,
14,
5217,
8,
3711,
12,
291,
423,
1210,
63,
1392,
9,
272,
671,
275,
291,
14,
5598,
17,
8,
88,
9,
272,
671,
275,
291,
14,
988,
63,
2293,
18,
68,
8,
88,
9,
272,
671,
275,
291,
14,
5598,
18,
8,
88,
9,
272,
671,
275,
291,
14,
988,
63,
2293,
18,
68,
8,
88,
9,
272,
671,
275,
2833,
14,
4359,
14,
8487,
8,
88,
9,
272,
671,
275,
291,
14,
3003,
17,
8,
88,
9,
272,
671,
275,
291,
14,
17953,
8,
88,
12,
6093,
29,
7588,
9,
272,
671,
275,
291,
14,
3003,
18,
8,
88,
9,
272,
372,
671,
421,
199,
318,
5621,
8,
9869,
12,
3628,
304,
523,
372,
2833,
14,
5270,
63,
3670,
8,
489,
2833,
14,
4411,
14,
16395,
63,
7925,
63,
10435,
63,
1045,
63,
10492,
8,
881,
11051,
29,
9869,
12,
3628,
29,
3512,
430,
421,
199,
318,
4526,
63,
13374,
8,
9869,
12,
3628,
304,
523,
372,
2833,
14,
5270,
63,
1838,
8,
489,
2833,
14,
2931,
8,
881,
2833,
14,
1452,
8,
1598,
2833,
14,
16383,
8,
9869,
12,
3114,
29,
17,
12,
717,
1072,
63,
466
] |
[
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
33,
13217,
603,
25392,
12429,
1808,
17461,
279,
9393,
14,
199,
199,
8176,
4503,
26,
523,
2366,
21945,
631,
14,
647,
1553,
3437,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
7534,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
199,
646,
3228,
465,
2833,
199,
199,
646,
3228,
14,
2828,
14,
10283,
465,
307,
771,
199,
504,
3228,
14,
8589,
14,
23561,
83,
14,
32164,
492,
1324,
63,
576,
199,
199,
4831,
275,
488,
421,
199,
533,
603,
25392,
1685,
8,
84,
771,
14,
4491,
304,
523,
408,
16237,
6225,
7220,
14,
819,
7220,
5523,
365,
7353,
370,
26,
523,
4178,
921,
5031,
14,
957,
15,
16008,
15,
16008,
15,
6582,
15,
82,
17,
14,
22,
15,
16008,
15,
8589,
15,
23561,
83,
15,
32164,
15,
32164,
63,
16131,
14,
647,
523,
436,
523,
4178,
921,
5031,
14,
957,
15,
16008,
15,
992,
15,
6582,
15,
4133,
15,
23561,
83,
15,
1569,
15,
32164,
15,
27625,
279,
14,
647,
819,
11017,
5313,
1808,
314,
2833,
14,
4359,
3261,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
666,
63,
908,
304,
272,
408,
10607,
282,
1402,
367,
28837,
316,
282,
4926,
13,
8938,
10964,
14,
339,
3033,
26,
489,
666,
63,
908,
26,
13083,
283,
6324,
63,
2246,
7,
503,
283,
6324,
63,
2019,
1370,
267,
283,
6324,
63,
2246,
7,
365,
13609,
12930,
641,
18613,
83,
1830,
283,
6324,
63,
2019,
7,
365,
267,
13609,
12930,
641,
28504,
14,
1666,
267,
4178,
921,
1544,
14,
16008,
14,
1308,
15,
20576,
15,
20576,
63,
17348,
3,
576,
63,
6321,
272,
408,
272,
1613,
8,
16237,
6225,
1685,
12,
291,
2843,
826,
721,
354,
13275,
272,
340,
666,
63,
908,
508,
283,
6324,
63,
2246,
356,
489,
291,
423,
1210,
63,
1392,
275,
5243,
17,
12,
413,
12,
7294,
12,
7294,
61,
272,
587,
26,
489,
702,
666,
63,
908,
508,
283,
6324,
63,
2019,
7,
489,
291,
423,
1210,
63,
1392,
275,
5243,
17,
12,
7294,
12,
7294,
12,
413,
61,
272,
291,
14,
5598,
17,
275,
291,
14,
3885,
63,
1897,
8,
267,
2833,
14,
4359,
14,
11596,
18,
36,
8,
708,
12,
959,
12,
666,
63,
908,
29,
576,
63,
908,
12,
10361,
29,
3249,
14,
4411,
14,
12833,
430,
272,
291,
14,
5598,
18,
275,
291,
14,
3885,
63,
1897,
8,
267,
2833,
14,
4359,
14,
11596,
18,
36,
8,
772,
12,
959,
12,
666,
63,
908,
29,
576,
63,
908,
12,
10361,
29,
3249,
14,
4411,
14,
12833,
430,
272,
291,
14,
3003,
17,
275,
291,
14,
3885,
63,
1897,
8,
3249,
14,
4359,
14,
15327,
8,
7727,
12,
10361,
29,
3249,
14,
4411,
14,
12833,
430,
272,
291,
14,
3003,
18,
275,
291,
14,
3885,
63,
1897,
8,
3249,
14,
4359,
14,
15327,
8,
709,
430,
272,
291,
14,
17953,
275,
291,
14,
3885,
63,
1897,
8,
3249,
14,
4359,
14,
30662,
8,
16,
14,
21,
430,
272,
291,
14,
988,
63,
2293,
18,
68,
275,
291,
14,
3885,
63,
1897,
8,
267,
2833,
14,
4359,
14,
4261,
22349,
18,
36,
8,
288,
334,
18,
12,
499,
395,
334,
18,
12,
499,
395,
6273,
534,
19935,
297,
666,
63,
908,
29,
576,
63,
908,
430,
819,
347,
1240,
8,
277,
12,
4153,
12,
6093,
304,
272,
408,
22594,
3628,
687,
4153,
14,
339,
20123,
1077,
12677,
636,
1250,
363,
370,
1255,
314,
2784,
12,
1314,
18703,
2335,
370,
642,
272,
1083,
334,
460,
440,
1240,
642,
1083,
5370,
680,
339,
3033,
26,
489,
4153,
26,
437,
3522,
402,
5935,
465,
282,
5878,
543,
2215,
359,
2912,
63,
890,
12,
1520,
1349,
1055,
489,
6093,
26,
715,
340,
10302,
315,
314,
1067,
402,
6093,
334,
696,
4941,
19795,
370,
267,
506,
6781,
680,
221,
756,
4257,
14,
339,
1803,
26,
489,
437,
5878,
543,
2215,
359,
2912,
63,
890,
12,
1616,
61,
3035,
314,
14746,
11051,
489,
367,
1924,
1834,
315,
314,
3522,
12,
367,
1924,
402,
314,
1616,
3992,
14,
272,
408,
339,
671,
275,
2833,
14,
5217,
8,
3711,
12,
291,
423,
1210,
63,
1392,
9,
272,
671,
275,
291,
14,
5598,
17,
8,
88,
9,
272,
671,
275,
291,
14,
988,
63,
2293,
18,
68,
8,
88,
9,
272,
671,
275,
291,
14,
5598,
18,
8,
88,
9,
272,
671,
275,
291,
14,
988,
63,
2293,
18,
68,
8,
88,
9,
272,
671,
275,
2833,
14,
4359,
14,
8487,
8,
88,
9,
272,
671,
275,
291,
14,
3003,
17,
8,
88,
9,
272,
671,
275,
291,
14,
17953,
8,
88,
12,
6093,
29,
7588,
9,
272,
671,
275,
291,
14,
3003,
18,
8,
88,
9,
272,
372,
671,
421,
199,
318,
5621,
8,
9869,
12,
3628,
304,
523,
372,
2833,
14,
5270,
63,
3670,
8,
489,
2833,
14,
4411,
14,
16395,
63,
7925,
63,
10435,
63,
1045,
63,
10492,
8,
881,
11051,
29,
9869,
12,
3628,
29,
3512,
430,
421,
199,
318,
4526,
63,
13374,
8,
9869,
12,
3628,
304,
523,
372,
2833,
14,
5270,
63,
1838,
8,
489,
2833,
14,
2931,
8,
881,
2833,
14,
1452,
8,
1598,
2833,
14,
16383,
8,
9869,
12,
3114,
29,
17,
12,
717,
1072,
63,
466,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
m-movahhedinia/Strigil
|
v_0.0.1.py
|
1
|
5683
|
from urllib import request
from bs4 import BeautifulSoup
import re
from builtins import print
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
"""
The source for the very first version of the web scrapper app.
No classes or functions. Just codes.
"""
# Open the file which contains the links of the root pages and read it line by line.
with open("links2.txt") as file:
content = file.readlines()
content = [line.strip() for line in content]
# Build a list to store the links for the next pages scrapped from the root pages.
Links_temp = []
# This for loop gets every link, and extracts the links of the next pages based on a criteria.
for l in content:
page = request.urlopen(l)
soup = BeautifulSoup(page, "html.parser")
# The findall function from the regular expressions library finds every string from the
# pages source code which follow a specific template written in regular expressions format.
# These two variables are to be used later on for making the template dynamic.
# spec_var = "property"
# regular_expression = "/" + spec_var + "/.+\\\""
links = re.findall("/property/.+\"", str(soup))
# This for loop checks to see if there is a repeated link. It needs to be rewritten
# and optimized in so many ways!
for i in links:
if links.index(i) < len(links)-1:
if i == links[links.index(i) + 1]:
del links[links.index(i) + 1]
# Rebuilds the links which are handled by a script instead of a <a> tag and stores them
# in a list to be retrieved later.
Links_temp.append("http://www.landsoftexas.com" + i.strip("\""))
# The with open line creates the file which is supposed to store the results of the scrapping
with open('result', 'w') as file:
# The for loop below reads the links from the list.
for page in Links_temp:
# Set the web driver as Chrome. This requires the chrome drive to be in the path
# variable. Need to find a way to automate this.
driver = webdriver.Chrome()
# Selenium's get module opens the browser and loads the link given to it, here 'page'.
driver.get(page)
# This is the location of the first element in the web page.
XPATH_1 = '//*[@id="memberBox"]/div/div/div[2]/div[3]/button'
# Selects the element in the given location.
element_1 = driver.find_element_by_xpath(XPATH_1)
# Executes the script which is supposed to show the hidden content of the web page.
element_2 = driver.execute_script("var propid = $('.inventory-item').attr('data-propid');"
" return recordPropertyPhone(461662, propid);", element_1)
# This is an incomplete error handling. It was meant to avoid application crash
# if element_3 could not be found.
# element_3 = "none"
# try:
# element_3 = driver.find_element_by_xpath(XPATH_2)
# element_3.click()
# except:
# XPATH_2 = 'driver.find_element_by_xpath(XPATH_1)'
# The send keys module simulates pressing of the given keys. In this case it is
# there to stop the page from redirecting by stopping loading. Not even sure it works!
element_1.send_keys(Keys.CONTROL + Keys.ESCAPE)
# A little delay in case there is latency in retrieving the hidden content from the
# server. There was a similar delay before the sending the keys above but it cuased
# error. It seems that the elements 1 and 2 are lost when there is a delay.
time.sleep(1)
# Expecting the source of the page to be updated with the new content, this line
# reads the source html code.
source0 = driver.page_source
# Closes the browser window.
driver.quit()
# Finds the position of the given string in the pages source code. This string has
# happened only once in the source.
data_position = source0.find('seller-info')
# Since I knew how much after the position above the data I wanted to scrap was
# located, this line gives the location of the beginning of my data. Also, this
# line trims off the code before this position.
source = source0[data_position + 71:]
# Same as above, this time for the ending of the data.
data_position = source.find('agentPhone') + 24
# Trim the data after the ending position off.
source = source[:data_position]
# Cleaning the data. The last three lines do the same by using regular expressions.
# The line which replaces comma with pipe is there to avoid splitting when opening
# the file in Excel as a csv file.
source = source.replace(" ", " ")
source = source.replace("\n", " ")
source = source.replace(" ", "")
source = source.replace(" <", "<")
source = source.replace("> ", ">")
source = source.replace("&", "&")
source = source.replace(",", "|")
source = source.replace("</p>", ",")
source = re.sub("<.*?>", "", source)
source = re.sub(".*?>", "", source)
source = re.sub("<.*?", "", source)
# prints the final outcome and each one's link so that I can see what the app is
# doing.
print(source + "," + page)
# Writes the outcome to the file. Actially, keeps in buffer then flushes to file.
file.write(source + "," + page + "\n")
file.flush()
# Closes the file but not required.
# file.close()
|
agpl-3.0
|
[
504,
4011,
492,
1056,
202,
199,
504,
9922,
20,
492,
17132,
202,
199,
646,
295,
202,
199,
504,
12963,
492,
870,
202,
199,
504,
19481,
492,
28094,
202,
199,
504,
19481,
14,
17946,
14,
2330,
14,
1612,
492,
17276,
202,
199,
646,
900,
2999,
199,
624,
202,
199,
1918,
1350,
367,
314,
7437,
1642,
1015,
402,
314,
3330,
4061,
2369,
1145,
14,
202,
199,
1944,
3992,
503,
3423,
14,
13870,
9479,
14,
202,
199,
624,
202,
199,
3,
3232,
314,
570,
1314,
3509,
314,
6220,
402,
314,
1738,
6497,
436,
1586,
652,
1004,
701,
1004,
14,
202,
199,
1045,
1551,
480,
4614,
18,
14,
2424,
531,
465,
570,
26,
1128,
1564,
275,
570,
14,
9684,
342,
202,
199,
1317,
275,
359,
604,
14,
1913,
342,
367,
1004,
315,
1564,
61,
2999,
199,
3,
6516,
282,
769,
370,
3877,
314,
6220,
367,
314,
2163,
6497,
4061,
1330,
1915,
687,
314,
1738,
6497,
14,
202,
199,
16974,
63,
808,
275,
942,
202,
199,
3,
961,
367,
4438,
7545,
4036,
2142,
12,
436,
5536,
83,
314,
6220,
402,
314,
2163,
6497,
4079,
641,
282,
15647,
14,
202,
199,
509,
634,
315,
1564,
26,
1128,
2034,
275,
1056,
14,
10890,
8,
76,
9,
1128,
9108,
275,
17132,
8,
1606,
12,
298,
1360,
14,
2087,
531,
1128,
327,
710,
2342,
452,
805,
687,
314,
5578,
8455,
3555,
17651,
4036,
1059,
687,
314,
1128,
327,
6497,
1350,
1233,
1314,
2035,
282,
2488,
1978,
5313,
315,
5578,
8455,
1475,
14,
1128,
327,
5723,
2877,
2860,
787,
370,
506,
1202,
2945,
641,
367,
10663,
314,
1978,
8336,
14,
1128,
327,
3158,
63,
1391,
275,
298,
1829,
2,
1128,
327,
5578,
63,
5599,
275,
10609,
435,
3158,
63,
1391,
435,
3286,
6977,
9780,
341,
1128,
6220,
275,
295,
14,
6452,
4769,
1829,
15,
6977,
60,
5151,
620,
8,
9317,
430,
1128,
327,
961,
367,
4438,
5920,
370,
1937,
340,
2337,
365,
282,
10877,
2142,
14,
2779,
4839,
370,
506,
28286,
1128,
327,
436,
20212,
315,
880,
5002,
15217,
1,
1128,
367,
284,
315,
6220,
26,
1039,
340,
6220,
14,
1080,
8,
73,
9,
665,
822,
8,
4614,
7216,
17,
26,
1675,
340,
284,
508,
6220,
59,
4614,
14,
1080,
8,
73,
9,
435,
413,
2189,
2628,
2150,
6220,
59,
4614,
14,
1080,
8,
73,
9,
435,
413,
61,
1039,
327,
799,
10838,
314,
6220,
1314,
787,
8860,
701,
282,
2884,
3140,
402,
282,
665,
65,
30,
1947,
436,
14086,
3062,
1039,
327,
315,
282,
769,
370,
506,
12396,
2945,
14,
1039,
10967,
83,
63,
808,
14,
740,
480,
1014,
921,
1544,
14,
9688,
1152,
70,
3858,
305,
14,
957,
2,
435,
284,
14,
1913,
4582,
341,
430,
2999,
199,
3,
710,
543,
1551,
1004,
8491,
314,
570,
1314,
365,
20042,
370,
3877,
314,
2058,
402,
314,
10328,
3637,
202,
199,
1045,
1551,
360,
1099,
297,
283,
87,
358,
465,
570,
26,
1128,
327,
710,
367,
4438,
5084,
11597,
314,
6220,
687,
314,
769,
14,
1128,
367,
2034,
315,
10967,
83,
63,
808,
26,
1039,
327,
2494,
314,
3330,
5253,
465,
16776,
14,
961,
5074,
314,
18221,
12912,
370,
506,
315,
314,
931,
1039,
327,
1750,
14,
14012,
370,
2342,
282,
4340,
370,
6384,
676,
323,
642,
14,
1039,
5253,
275,
28094,
14,
18083,
342,
1039,
327,
3240,
9465,
1159,
664,
859,
30848,
314,
7042,
436,
14404,
314,
2142,
1627,
370,
652,
12,
2348,
283,
1606,
1370,
1039,
5253,
14,
362,
8,
1606,
9,
1039,
327,
961,
365,
314,
2909,
402,
314,
1642,
1819,
315,
314,
3330,
2034,
14,
1039,
1323,
3243,
63,
17,
275,
18290,
10,
14251,
344,
628,
1114,
3532,
937,
15,
3015,
15,
3015,
15,
3015,
59,
18,
12978,
3015,
59,
19,
12978,
3887,
7,
1039,
327,
9496,
83,
314,
1819,
315,
314,
1627,
2909,
14,
1039,
1819,
63,
17,
275,
5253,
14,
1623,
63,
2108,
63,
991,
63,
8006,
8,
56,
3243,
63,
17,
9,
1039,
327,
9434,
3862,
314,
2884,
1314,
365,
20042,
370,
2498,
314,
8752,
1564,
402,
314,
3330,
2034,
14,
1039,
1819,
63,
18,
275,
5253,
14,
2526,
63,
1579,
480,
1391,
557,
3150,
275,
2672,
5175,
7212,
13,
1053,
1959,
962,
360,
576,
13,
496,
3150,
358,
9426,
202,
5101,
298,
372,
2777,
3697,
15199,
8,
2466,
975,
2789,
12,
557,
3150,
2736,
401,
1819,
63,
17,
9,
1039,
327,
961,
365,
376,
17110,
1125,
7252,
14,
2779,
1990,
18329,
370,
5126,
4223,
12420,
1039,
327,
340,
1819,
63,
19,
4293,
440,
506,
1911,
14,
1039,
327,
1819,
63,
19,
275,
298,
3592,
2,
1039,
327,
862,
26,
1039,
327,
258,
1819,
63,
19,
275,
5253,
14,
1623,
63,
2108,
63,
991,
63,
8006,
8,
56,
3243,
63,
18,
9,
1039,
327,
258,
1819,
63,
19,
14,
4891,
342,
1039,
327,
871,
26,
1039,
327,
1323,
3243,
63,
18,
275,
283,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
8,
56,
3243,
63,
17,
3171,
1039,
327,
710,
3222,
2883,
859,
4389,
15409,
15105,
316,
402,
314,
1627,
2883,
14,
1010,
642,
1930,
652,
365,
1039,
327,
2337,
370,
3631,
314,
2034,
687,
4660,
316,
701,
23599,
8697,
14,
2832,
2755,
3238,
652,
5419,
1,
1039,
1819,
63,
17,
14,
2254,
63,
1612,
8,
6340,
14,
13060,
435,
17276,
14,
28879,
9,
1039,
327,
437,
12050,
7339,
315,
1930,
2337,
365,
23967,
315,
23812,
314,
8752,
1564,
687,
314,
1039,
327,
1654,
14,
6006,
1990,
282,
8545,
7339,
2544,
314,
10209,
314,
2883,
3432,
1325,
652,
30353,
11185,
1039,
327,
1125,
14,
2779,
12237,
626,
314,
4008,
413,
436,
499,
787,
14669,
1380,
2337,
365,
282,
7339,
14,
1039,
900,
14,
4532,
8,
17,
9,
1039,
327,
15100,
316,
314,
1350,
402,
314,
2034,
370,
506,
4588,
543,
314,
892,
1564,
12,
642,
1004,
1039,
327,
11597,
314,
1350,
3517,
1233,
14,
1039,
1350,
16,
275,
5253,
14,
1606,
63,
1365,
1039,
327,
5980,
874,
314,
7042,
4353,
14,
1039,
5253,
14,
10589,
342,
4341,
327,
31434,
314,
3421,
402,
314,
1627,
1059,
315,
314,
6497,
1350,
1233,
14,
961,
1059,
965,
1039,
327,
21056,
1454,
5403,
315,
314,
1350,
14,
1039,
666,
63,
3124,
275,
1350,
16,
14,
1623,
360,
5891,
1435,
13,
815,
358,
1039,
327,
9336,
473,
1022,
1222,
4212,
8298
] |
[
4011,
492,
1056,
202,
199,
504,
9922,
20,
492,
17132,
202,
199,
646,
295,
202,
199,
504,
12963,
492,
870,
202,
199,
504,
19481,
492,
28094,
202,
199,
504,
19481,
14,
17946,
14,
2330,
14,
1612,
492,
17276,
202,
199,
646,
900,
2999,
199,
624,
202,
199,
1918,
1350,
367,
314,
7437,
1642,
1015,
402,
314,
3330,
4061,
2369,
1145,
14,
202,
199,
1944,
3992,
503,
3423,
14,
13870,
9479,
14,
202,
199,
624,
202,
199,
3,
3232,
314,
570,
1314,
3509,
314,
6220,
402,
314,
1738,
6497,
436,
1586,
652,
1004,
701,
1004,
14,
202,
199,
1045,
1551,
480,
4614,
18,
14,
2424,
531,
465,
570,
26,
1128,
1564,
275,
570,
14,
9684,
342,
202,
199,
1317,
275,
359,
604,
14,
1913,
342,
367,
1004,
315,
1564,
61,
2999,
199,
3,
6516,
282,
769,
370,
3877,
314,
6220,
367,
314,
2163,
6497,
4061,
1330,
1915,
687,
314,
1738,
6497,
14,
202,
199,
16974,
63,
808,
275,
942,
202,
199,
3,
961,
367,
4438,
7545,
4036,
2142,
12,
436,
5536,
83,
314,
6220,
402,
314,
2163,
6497,
4079,
641,
282,
15647,
14,
202,
199,
509,
634,
315,
1564,
26,
1128,
2034,
275,
1056,
14,
10890,
8,
76,
9,
1128,
9108,
275,
17132,
8,
1606,
12,
298,
1360,
14,
2087,
531,
1128,
327,
710,
2342,
452,
805,
687,
314,
5578,
8455,
3555,
17651,
4036,
1059,
687,
314,
1128,
327,
6497,
1350,
1233,
1314,
2035,
282,
2488,
1978,
5313,
315,
5578,
8455,
1475,
14,
1128,
327,
5723,
2877,
2860,
787,
370,
506,
1202,
2945,
641,
367,
10663,
314,
1978,
8336,
14,
1128,
327,
3158,
63,
1391,
275,
298,
1829,
2,
1128,
327,
5578,
63,
5599,
275,
10609,
435,
3158,
63,
1391,
435,
3286,
6977,
9780,
341,
1128,
6220,
275,
295,
14,
6452,
4769,
1829,
15,
6977,
60,
5151,
620,
8,
9317,
430,
1128,
327,
961,
367,
4438,
5920,
370,
1937,
340,
2337,
365,
282,
10877,
2142,
14,
2779,
4839,
370,
506,
28286,
1128,
327,
436,
20212,
315,
880,
5002,
15217,
1,
1128,
367,
284,
315,
6220,
26,
1039,
340,
6220,
14,
1080,
8,
73,
9,
665,
822,
8,
4614,
7216,
17,
26,
1675,
340,
284,
508,
6220,
59,
4614,
14,
1080,
8,
73,
9,
435,
413,
2189,
2628,
2150,
6220,
59,
4614,
14,
1080,
8,
73,
9,
435,
413,
61,
1039,
327,
799,
10838,
314,
6220,
1314,
787,
8860,
701,
282,
2884,
3140,
402,
282,
665,
65,
30,
1947,
436,
14086,
3062,
1039,
327,
315,
282,
769,
370,
506,
12396,
2945,
14,
1039,
10967,
83,
63,
808,
14,
740,
480,
1014,
921,
1544,
14,
9688,
1152,
70,
3858,
305,
14,
957,
2,
435,
284,
14,
1913,
4582,
341,
430,
2999,
199,
3,
710,
543,
1551,
1004,
8491,
314,
570,
1314,
365,
20042,
370,
3877,
314,
2058,
402,
314,
10328,
3637,
202,
199,
1045,
1551,
360,
1099,
297,
283,
87,
358,
465,
570,
26,
1128,
327,
710,
367,
4438,
5084,
11597,
314,
6220,
687,
314,
769,
14,
1128,
367,
2034,
315,
10967,
83,
63,
808,
26,
1039,
327,
2494,
314,
3330,
5253,
465,
16776,
14,
961,
5074,
314,
18221,
12912,
370,
506,
315,
314,
931,
1039,
327,
1750,
14,
14012,
370,
2342,
282,
4340,
370,
6384,
676,
323,
642,
14,
1039,
5253,
275,
28094,
14,
18083,
342,
1039,
327,
3240,
9465,
1159,
664,
859,
30848,
314,
7042,
436,
14404,
314,
2142,
1627,
370,
652,
12,
2348,
283,
1606,
1370,
1039,
5253,
14,
362,
8,
1606,
9,
1039,
327,
961,
365,
314,
2909,
402,
314,
1642,
1819,
315,
314,
3330,
2034,
14,
1039,
1323,
3243,
63,
17,
275,
18290,
10,
14251,
344,
628,
1114,
3532,
937,
15,
3015,
15,
3015,
15,
3015,
59,
18,
12978,
3015,
59,
19,
12978,
3887,
7,
1039,
327,
9496,
83,
314,
1819,
315,
314,
1627,
2909,
14,
1039,
1819,
63,
17,
275,
5253,
14,
1623,
63,
2108,
63,
991,
63,
8006,
8,
56,
3243,
63,
17,
9,
1039,
327,
9434,
3862,
314,
2884,
1314,
365,
20042,
370,
2498,
314,
8752,
1564,
402,
314,
3330,
2034,
14,
1039,
1819,
63,
18,
275,
5253,
14,
2526,
63,
1579,
480,
1391,
557,
3150,
275,
2672,
5175,
7212,
13,
1053,
1959,
962,
360,
576,
13,
496,
3150,
358,
9426,
202,
5101,
298,
372,
2777,
3697,
15199,
8,
2466,
975,
2789,
12,
557,
3150,
2736,
401,
1819,
63,
17,
9,
1039,
327,
961,
365,
376,
17110,
1125,
7252,
14,
2779,
1990,
18329,
370,
5126,
4223,
12420,
1039,
327,
340,
1819,
63,
19,
4293,
440,
506,
1911,
14,
1039,
327,
1819,
63,
19,
275,
298,
3592,
2,
1039,
327,
862,
26,
1039,
327,
258,
1819,
63,
19,
275,
5253,
14,
1623,
63,
2108,
63,
991,
63,
8006,
8,
56,
3243,
63,
18,
9,
1039,
327,
258,
1819,
63,
19,
14,
4891,
342,
1039,
327,
871,
26,
1039,
327,
1323,
3243,
63,
18,
275,
283,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
8,
56,
3243,
63,
17,
3171,
1039,
327,
710,
3222,
2883,
859,
4389,
15409,
15105,
316,
402,
314,
1627,
2883,
14,
1010,
642,
1930,
652,
365,
1039,
327,
2337,
370,
3631,
314,
2034,
687,
4660,
316,
701,
23599,
8697,
14,
2832,
2755,
3238,
652,
5419,
1,
1039,
1819,
63,
17,
14,
2254,
63,
1612,
8,
6340,
14,
13060,
435,
17276,
14,
28879,
9,
1039,
327,
437,
12050,
7339,
315,
1930,
2337,
365,
23967,
315,
23812,
314,
8752,
1564,
687,
314,
1039,
327,
1654,
14,
6006,
1990,
282,
8545,
7339,
2544,
314,
10209,
314,
2883,
3432,
1325,
652,
30353,
11185,
1039,
327,
1125,
14,
2779,
12237,
626,
314,
4008,
413,
436,
499,
787,
14669,
1380,
2337,
365,
282,
7339,
14,
1039,
900,
14,
4532,
8,
17,
9,
1039,
327,
15100,
316,
314,
1350,
402,
314,
2034,
370,
506,
4588,
543,
314,
892,
1564,
12,
642,
1004,
1039,
327,
11597,
314,
1350,
3517,
1233,
14,
1039,
1350,
16,
275,
5253,
14,
1606,
63,
1365,
1039,
327,
5980,
874,
314,
7042,
4353,
14,
1039,
5253,
14,
10589,
342,
4341,
327,
31434,
314,
3421,
402,
314,
1627,
1059,
315,
314,
6497,
1350,
1233,
14,
961,
1059,
965,
1039,
327,
21056,
1454,
5403,
315,
314,
1350,
14,
1039,
666,
63,
3124,
275,
1350,
16,
14,
1623,
360,
5891,
1435,
13,
815,
358,
1039,
327,
9336,
473,
1022,
1222,
4212,
8298,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
cvegaj/ElectriCERT
|
venv3/lib/python3.6/site-packages/pycoin/services/blockchain_info.py
|
1
|
2303
|
import io
import json
import warnings
from .agent import request, urlencode, urlopen
from pycoin.serialize import b2h, h2b
from pycoin.tx import Spendable
class BlockchainInfoProvider(object):
def __init__(self, netcode):
if netcode != 'BTC':
raise ValueError("BlockchainInfo only supports mainnet")
def payments_for_address(self, bitcoin_address):
"return an array of (TX ids, net_payment)"
URL = "https://blockchain.info/address/%s?format=json" % bitcoin_address
d = urlopen(URL).read()
json_response = json.loads(d.decode("utf8"))
response = []
for tx in json_response.get("txs", []):
total_out = 0
for tx_out in tx.get("out", []):
if tx_out.get("addr") == bitcoin_address:
total_out += tx_out.get("value", 0)
if total_out > 0:
response.append((tx.get("hash"), total_out))
return response
def spendables_for_address(self, bitcoin_address):
"""
Return a list of Spendable objects for the
given bitcoin address.
"""
URL = "https://blockchain.info/unspent?active=%s" % bitcoin_address
r = json.loads(urlopen(URL).read().decode("utf8"))
spendables = []
for u in r["unspent_outputs"]:
coin_value = u["value"]
script = h2b(u["script"])
previous_hash = h2b(u["tx_hash"])
previous_index = u["tx_output_n"]
spendables.append(Spendable(coin_value, script, previous_hash, previous_index))
return spendables
def broadcast_tx(self, tx):
s = io.BytesIO()
tx.stream(s)
tx_as_hex = b2h(s.getvalue())
data = urlencode(dict(tx=tx_as_hex)).encode("utf8")
URL = "https://blockchain.info/pushtx"
try:
d = urlopen(URL, data=data).read()
return d
except request.HTTPError as ex:
try:
d = ex.read()
ex.message = d
except:
pass
raise ex
def send_tx(self, tx):
warnings.warn("use BlockchainInfoProvider.broadcast_tx instead of send_tx",
category=DeprecationWarning)
return BlockchainInfoProvider().broadcast_tx(tx)
|
gpl-3.0
|
[
646,
5890,
199,
646,
2022,
199,
646,
3598,
199,
199,
504,
1275,
4054,
492,
1056,
12,
16511,
12,
18279,
199,
199,
504,
1134,
9061,
14,
3549,
492,
330,
18,
72,
12,
394,
18,
66,
199,
504,
1134,
9061,
14,
2347,
492,
428,
6643,
461,
421,
199,
533,
8651,
4429,
2354,
6663,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1851,
600,
304,
267,
340,
1851,
600,
1137,
283,
34,
5708,
356,
288,
746,
1722,
480,
3142,
4429,
2354,
1454,
5171,
2446,
846,
531,
339,
347,
8633,
1470,
63,
509,
63,
1562,
8,
277,
12,
27214,
63,
1562,
304,
267,
298,
1107,
376,
1625,
402,
334,
10051,
2762,
12,
1851,
63,
7948,
2924,
267,
2851,
275,
298,
2859,
921,
1457,
4429,
14,
815,
15,
1562,
3149,
83,
31,
908,
29,
1001,
2,
450,
27214,
63,
1562,
267,
366,
275,
18279,
8,
2632,
680,
739,
342,
267,
2022,
63,
1310,
275,
2022,
14,
3640,
8,
68,
14,
2708,
480,
1624,
24,
2237,
267,
1177,
275,
942,
267,
367,
4773,
315,
2022,
63,
1310,
14,
362,
480,
21863,
401,
12319,
288,
3141,
63,
548,
275,
378,
288,
367,
4773,
63,
548,
315,
4773,
14,
362,
480,
548,
401,
12319,
355,
340,
4773,
63,
548,
14,
362,
480,
2697,
531,
508,
27214,
63,
1562,
26,
490,
3141,
63,
548,
847,
4773,
63,
548,
14,
362,
480,
585,
401,
378,
9,
288,
340,
3141,
63,
548,
690,
378,
26,
355,
1177,
14,
740,
1332,
2347,
14,
362,
480,
2227,
1288,
3141,
63,
548,
430,
267,
372,
1177,
339,
347,
26387,
5921,
63,
509,
63,
1562,
8,
277,
12,
27214,
63,
1562,
304,
267,
408,
267,
1432,
282,
769,
402,
428,
6643,
461,
2251,
367,
314,
267,
1627,
27214,
2287,
14,
267,
408,
267,
2851,
275,
298,
2859,
921,
1457,
4429,
14,
815,
15,
324,
19435,
31,
2682,
2458,
83,
2,
450,
27214,
63,
1562,
267,
519,
275,
2022,
14,
3640,
8,
10890,
8,
2632,
680,
739,
1252,
2708,
480,
1624,
24,
2237,
267,
26387,
5921,
275,
942,
267,
367,
399,
315,
519,
905,
324,
19435,
63,
4467,
6229,
288,
21914,
63,
585,
275,
399,
905,
585,
937,
288,
2884,
275,
394,
18,
66,
8,
85,
905,
1579,
3135,
288,
4136,
63,
2227,
275,
394,
18,
66,
8,
85,
905,
2347,
63,
2227,
3135,
288,
4136,
63,
1080,
275,
399,
905,
2347,
63,
1199,
63,
78,
937,
288,
26387,
5921,
14,
740,
8,
5058,
500,
461,
8,
9061,
63,
585,
12,
2884,
12,
4136,
63,
2227,
12,
4136,
63,
1080,
430,
267,
372,
26387,
5921,
339,
347,
11180,
63,
2347,
8,
277,
12,
4773,
304,
267,
308,
275,
5890,
14,
15466,
342,
267,
4773,
14,
1745,
8,
83,
9,
267,
4773,
63,
305,
63,
4097,
275,
330,
18,
72,
8,
83,
14,
7150,
1012,
267,
666,
275,
16511,
8,
807,
8,
2347,
29,
2347,
63,
305,
63,
4097,
4992,
2143,
480,
1624,
24,
531,
267,
2851,
275,
298,
2859,
921,
1457,
4429,
14,
815,
15,
8843,
517,
88,
2,
267,
862,
26,
288,
366,
275,
18279,
8,
2632,
12,
666,
29,
576,
680,
739,
342,
288,
372,
366,
267,
871,
1056,
14,
12815,
465,
444,
26,
288,
862,
26,
355,
366,
275,
444,
14,
739,
342,
355,
444,
14,
1188,
275,
366,
288,
871,
26,
355,
986,
288,
746,
444,
421,
199,
318,
3222,
63,
2347,
8,
277,
12,
4773,
304,
272,
3598,
14,
4050,
480,
1180,
8651,
4429,
2354,
6663,
14,
10786,
63,
2347,
3140,
402,
3222,
63,
2347,
401,
2116,
4637,
29,
15561,
9,
272,
372,
8651,
4429,
2354,
6663,
1252,
10786,
63,
2347,
8,
2347,
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
] |
[
5890,
199,
646,
2022,
199,
646,
3598,
199,
199,
504,
1275,
4054,
492,
1056,
12,
16511,
12,
18279,
199,
199,
504,
1134,
9061,
14,
3549,
492,
330,
18,
72,
12,
394,
18,
66,
199,
504,
1134,
9061,
14,
2347,
492,
428,
6643,
461,
421,
199,
533,
8651,
4429,
2354,
6663,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1851,
600,
304,
267,
340,
1851,
600,
1137,
283,
34,
5708,
356,
288,
746,
1722,
480,
3142,
4429,
2354,
1454,
5171,
2446,
846,
531,
339,
347,
8633,
1470,
63,
509,
63,
1562,
8,
277,
12,
27214,
63,
1562,
304,
267,
298,
1107,
376,
1625,
402,
334,
10051,
2762,
12,
1851,
63,
7948,
2924,
267,
2851,
275,
298,
2859,
921,
1457,
4429,
14,
815,
15,
1562,
3149,
83,
31,
908,
29,
1001,
2,
450,
27214,
63,
1562,
267,
366,
275,
18279,
8,
2632,
680,
739,
342,
267,
2022,
63,
1310,
275,
2022,
14,
3640,
8,
68,
14,
2708,
480,
1624,
24,
2237,
267,
1177,
275,
942,
267,
367,
4773,
315,
2022,
63,
1310,
14,
362,
480,
21863,
401,
12319,
288,
3141,
63,
548,
275,
378,
288,
367,
4773,
63,
548,
315,
4773,
14,
362,
480,
548,
401,
12319,
355,
340,
4773,
63,
548,
14,
362,
480,
2697,
531,
508,
27214,
63,
1562,
26,
490,
3141,
63,
548,
847,
4773,
63,
548,
14,
362,
480,
585,
401,
378,
9,
288,
340,
3141,
63,
548,
690,
378,
26,
355,
1177,
14,
740,
1332,
2347,
14,
362,
480,
2227,
1288,
3141,
63,
548,
430,
267,
372,
1177,
339,
347,
26387,
5921,
63,
509,
63,
1562,
8,
277,
12,
27214,
63,
1562,
304,
267,
408,
267,
1432,
282,
769,
402,
428,
6643,
461,
2251,
367,
314,
267,
1627,
27214,
2287,
14,
267,
408,
267,
2851,
275,
298,
2859,
921,
1457,
4429,
14,
815,
15,
324,
19435,
31,
2682,
2458,
83,
2,
450,
27214,
63,
1562,
267,
519,
275,
2022,
14,
3640,
8,
10890,
8,
2632,
680,
739,
1252,
2708,
480,
1624,
24,
2237,
267,
26387,
5921,
275,
942,
267,
367,
399,
315,
519,
905,
324,
19435,
63,
4467,
6229,
288,
21914,
63,
585,
275,
399,
905,
585,
937,
288,
2884,
275,
394,
18,
66,
8,
85,
905,
1579,
3135,
288,
4136,
63,
2227,
275,
394,
18,
66,
8,
85,
905,
2347,
63,
2227,
3135,
288,
4136,
63,
1080,
275,
399,
905,
2347,
63,
1199,
63,
78,
937,
288,
26387,
5921,
14,
740,
8,
5058,
500,
461,
8,
9061,
63,
585,
12,
2884,
12,
4136,
63,
2227,
12,
4136,
63,
1080,
430,
267,
372,
26387,
5921,
339,
347,
11180,
63,
2347,
8,
277,
12,
4773,
304,
267,
308,
275,
5890,
14,
15466,
342,
267,
4773,
14,
1745,
8,
83,
9,
267,
4773,
63,
305,
63,
4097,
275,
330,
18,
72,
8,
83,
14,
7150,
1012,
267,
666,
275,
16511,
8,
807,
8,
2347,
29,
2347,
63,
305,
63,
4097,
4992,
2143,
480,
1624,
24,
531,
267,
2851,
275,
298,
2859,
921,
1457,
4429,
14,
815,
15,
8843,
517,
88,
2,
267,
862,
26,
288,
366,
275,
18279,
8,
2632,
12,
666,
29,
576,
680,
739,
342,
288,
372,
366,
267,
871,
1056,
14,
12815,
465,
444,
26,
288,
862,
26,
355,
366,
275,
444,
14,
739,
342,
355,
444,
14,
1188,
275,
366,
288,
871,
26,
355,
986,
288,
746,
444,
421,
199,
318,
3222,
63,
2347,
8,
277,
12,
4773,
304,
272,
3598,
14,
4050,
480,
1180,
8651,
4429,
2354,
6663,
14,
10786,
63,
2347,
3140,
402,
3222,
63,
2347,
401,
2116,
4637,
29,
15561,
9,
272,
372,
8651,
4429,
2354,
6663,
1252,
10786,
63,
2347,
8,
2347,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
alangwansui/mtl_ordercenter
|
openerp/addons/purchase/report/__init__.py
|
68
|
1108
|
# -*- 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 order
import request_quotation
import purchase_report
# 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,
1865,
199,
646,
1056,
63,
29318,
199,
646,
15932,
63,
3070,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
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,
1865,
199,
646,
1056,
63,
29318,
199,
646,
15932,
63,
3070,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
asnorkin/sentiment_analysis
|
site/lib/python2.7/site-packages/wheel/signatures/ed25519py.py
|
565
|
1695
|
# -*- coding: utf-8 -*-
import warnings
import os
from collections import namedtuple
from . import djbec
__all__ = ['crypto_sign', 'crypto_sign_open', 'crypto_sign_keypair', 'Keypair',
'PUBLICKEYBYTES', 'SECRETKEYBYTES', 'SIGNATUREBYTES']
PUBLICKEYBYTES=32
SECRETKEYBYTES=64
SIGNATUREBYTES=64
Keypair = namedtuple('Keypair', ('vk', 'sk')) # verifying key, secret key
def crypto_sign_keypair(seed=None):
"""Return (verifying, secret) key from a given seed, or os.urandom(32)"""
if seed is None:
seed = os.urandom(PUBLICKEYBYTES)
else:
warnings.warn("ed25519ll should choose random seed.",
RuntimeWarning)
if len(seed) != 32:
raise ValueError("seed must be 32 random bytes or None.")
skbytes = seed
vkbytes = djbec.publickey(skbytes)
return Keypair(vkbytes, skbytes+vkbytes)
def crypto_sign(msg, sk):
"""Return signature+message given message and secret key.
The signature is the first SIGNATUREBYTES bytes of the return value.
A copy of msg is in the remainder."""
if len(sk) != SECRETKEYBYTES:
raise ValueError("Bad signing key length %d" % len(sk))
vkbytes = sk[PUBLICKEYBYTES:]
skbytes = sk[:PUBLICKEYBYTES]
sig = djbec.signature(msg, skbytes, vkbytes)
return sig + msg
def crypto_sign_open(signed, vk):
"""Return message given signature+message and the verifying key."""
if len(vk) != PUBLICKEYBYTES:
raise ValueError("Bad verifying key length %d" % len(vk))
rc = djbec.checkvalid(signed[:SIGNATUREBYTES], signed[SIGNATUREBYTES:], vk)
if not rc:
raise ValueError("rc != True", rc)
return signed[SIGNATUREBYTES:]
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
3598,
199,
646,
747,
199,
199,
504,
5055,
492,
12863,
199,
504,
1275,
492,
366,
74,
24554,
199,
199,
363,
452,
363,
275,
788,
10316,
63,
1037,
297,
283,
10316,
63,
1037,
63,
1490,
297,
283,
10316,
63,
1037,
63,
19263,
297,
283,
1197,
3852,
297,
1779,
283,
19476,
3078,
20352,
297,
283,
12961,
3078,
20352,
297,
283,
26588,
20352,
418,
199,
199,
19476,
3078,
20352,
29,
708,
199,
12961,
3078,
20352,
29,
772,
199,
26588,
20352,
29,
772,
199,
199,
1197,
3852,
275,
12863,
360,
1197,
3852,
297,
661,
21405,
297,
283,
1339,
1333,
327,
31866,
790,
12,
7565,
790,
199,
199,
318,
13230,
63,
1037,
63,
19263,
8,
5176,
29,
403,
304,
272,
408,
1767,
334,
4712,
316,
12,
7565,
9,
790,
687,
282,
1627,
6347,
12,
503,
747,
14,
22776,
8,
708,
9471,
14821,
340,
6347,
365,
488,
26,
267,
6347,
275,
747,
14,
22776,
8,
19476,
3078,
20352,
9,
272,
587,
26,
267,
3598,
14,
4050,
480,
379,
2299,
1167,
914,
1077,
11496,
2196,
6347,
4765,
1993,
25178,
9,
272,
340,
822,
8,
5176,
9,
1137,
4337,
26,
267,
746,
1722,
480,
5176,
1471,
506,
4337,
2196,
2783,
503,
488,
2685,
272,
2386,
2394,
275,
6347,
272,
373,
75,
2394,
275,
366,
74,
24554,
14,
5645,
8442,
14655,
8,
1339,
2394,
9,
272,
372,
2606,
3852,
8,
21405,
2394,
12,
2386,
2394,
11,
21405,
2394,
9,
421,
199,
318,
13230,
63,
1037,
8,
1328,
12,
2386,
304,
272,
408,
1767,
4955,
11,
1188,
1627,
1245,
436,
7565,
790,
14,
272,
710,
4955,
365,
314,
1642,
5056,
13214,
20352,
2783,
402,
314,
372,
574,
14,
272,
437,
1331,
402,
1499,
365,
315,
314,
15748,
1041,
272,
340,
822,
8,
1339,
9,
1137,
5795,
11771,
3078,
20352,
26,
267,
746,
1722,
480,
5725,
18057,
790,
2582,
450,
68,
2,
450,
822,
8,
1339,
430,
272,
373,
75,
2394,
275,
2386,
59,
19476,
3078,
20352,
2938,
272,
2386,
2394,
275,
2386,
1491,
19476,
3078,
20352,
61,
272,
5259,
275,
366,
74,
24554,
14,
5233,
8,
1328,
12,
2386,
2394,
12,
373,
75,
2394,
9,
272,
372,
5259,
435,
1499,
421,
199,
318,
13230,
63,
1037,
63,
1490,
8,
1737,
12,
373,
75,
304,
272,
408,
1767,
1245,
1627,
4955,
11,
1188,
436,
314,
31866,
790,
1041,
272,
340,
822,
8,
21405,
9,
1137,
21755,
3078,
20352,
26,
267,
746,
1722,
480,
5725,
31866,
790,
2582,
450,
68,
2,
450,
822,
8,
21405,
430,
272,
4819,
275,
366,
74,
24554,
14,
1074,
1078,
8,
1737,
1491,
26588,
20352,
467,
10514,
59,
26588,
20352,
8429,
373,
75,
9,
272,
340,
440,
4819,
26,
267,
746,
1722,
480,
1195,
1137,
715,
401,
4819,
9,
14821,
372,
10514,
59,
26588,
20352,
2938,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
3598,
199,
646,
747,
199,
199,
504,
5055,
492,
12863,
199,
504,
1275,
492,
366,
74,
24554,
199,
199,
363,
452,
363,
275,
788,
10316,
63,
1037,
297,
283,
10316,
63,
1037,
63,
1490,
297,
283,
10316,
63,
1037,
63,
19263,
297,
283,
1197,
3852,
297,
1779,
283,
19476,
3078,
20352,
297,
283,
12961,
3078,
20352,
297,
283,
26588,
20352,
418,
199,
199,
19476,
3078,
20352,
29,
708,
199,
12961,
3078,
20352,
29,
772,
199,
26588,
20352,
29,
772,
199,
199,
1197,
3852,
275,
12863,
360,
1197,
3852,
297,
661,
21405,
297,
283,
1339,
1333,
327,
31866,
790,
12,
7565,
790,
199,
199,
318,
13230,
63,
1037,
63,
19263,
8,
5176,
29,
403,
304,
272,
408,
1767,
334,
4712,
316,
12,
7565,
9,
790,
687,
282,
1627,
6347,
12,
503,
747,
14,
22776,
8,
708,
9471,
14821,
340,
6347,
365,
488,
26,
267,
6347,
275,
747,
14,
22776,
8,
19476,
3078,
20352,
9,
272,
587,
26,
267,
3598,
14,
4050,
480,
379,
2299,
1167,
914,
1077,
11496,
2196,
6347,
4765,
1993,
25178,
9,
272,
340,
822,
8,
5176,
9,
1137,
4337,
26,
267,
746,
1722,
480,
5176,
1471,
506,
4337,
2196,
2783,
503,
488,
2685,
272,
2386,
2394,
275,
6347,
272,
373,
75,
2394,
275,
366,
74,
24554,
14,
5645,
8442,
14655,
8,
1339,
2394,
9,
272,
372,
2606,
3852,
8,
21405,
2394,
12,
2386,
2394,
11,
21405,
2394,
9,
421,
199,
318,
13230,
63,
1037,
8,
1328,
12,
2386,
304,
272,
408,
1767,
4955,
11,
1188,
1627,
1245,
436,
7565,
790,
14,
272,
710,
4955,
365,
314,
1642,
5056,
13214,
20352,
2783,
402,
314,
372,
574,
14,
272,
437,
1331,
402,
1499,
365,
315,
314,
15748,
1041,
272,
340,
822,
8,
1339,
9,
1137,
5795,
11771,
3078,
20352,
26,
267,
746,
1722,
480,
5725,
18057,
790,
2582,
450,
68,
2,
450,
822,
8,
1339,
430,
272,
373,
75,
2394,
275,
2386,
59,
19476,
3078,
20352,
2938,
272,
2386,
2394,
275,
2386,
1491,
19476,
3078,
20352,
61,
272,
5259,
275,
366,
74,
24554,
14,
5233,
8,
1328,
12,
2386,
2394,
12,
373,
75,
2394,
9,
272,
372,
5259,
435,
1499,
421,
199,
318,
13230,
63,
1037,
63,
1490,
8,
1737,
12,
373,
75,
304,
272,
408,
1767,
1245,
1627,
4955,
11,
1188,
436,
314,
31866,
790,
1041,
272,
340,
822,
8,
21405,
9,
1137,
21755,
3078,
20352,
26,
267,
746,
1722,
480,
5725,
31866,
790,
2582,
450,
68,
2,
450,
822,
8,
21405,
430,
272,
4819,
275,
366,
74,
24554,
14,
1074,
1078,
8,
1737,
1491,
26588,
20352,
467,
10514,
59,
26588,
20352,
8429,
373,
75,
9,
272,
340,
440,
4819,
26,
267,
746,
1722,
480,
1195,
1137,
715,
401,
4819,
9,
14821,
372,
10514,
59,
26588,
20352,
2938,
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,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0,
0,
0,
0,
0,
0,
0,
0
] |
mjcollin/2016spr
|
notebook/lib/pos_tags.py
|
1
|
1029
|
import nltk
class PosTags:
def tag(self, t, as_dicts=True):
'''
With a list of tokens, mark their part of speech and return
a list dicts (no native tuple type in dataframes it seems).
'''
pos = nltk.pos_tag(t)
if as_dicts:
return self.to_dicts(pos)
else:
return pos
def to_dicts(self, pos):
'''
With a list of POS tag tuples, convert the tuples to dicts
because Spark can't store tuples.
'''
retval = []
for p in pos:
retval.append({"word": p[0], "tag": p[1]})
return retval
if __name__ == "__main__":
from tokens import Tokens
import sys
fn = sys.argv[1]
t = Tokens()
pos_tags = PosTags()
with open(fn) as f:
for l in f:
tokens = t.tokenize(l)
pos = pos_tags.tag(tokens)
s = ""
for p in pos:
s = s + p["word"] + " (" + p["tag"] + ") | "
print(s + "\n")
|
mit
|
[
646,
24706,
199,
199,
533,
25987,
9440,
26,
339,
347,
1947,
8,
277,
12,
307,
12,
465,
63,
7892,
29,
549,
304,
267,
1449,
267,
8777,
282,
769,
402,
4645,
12,
2216,
3932,
1777,
402,
32093,
436,
372,
267,
282,
769,
10809,
334,
889,
5438,
2008,
730,
315,
666,
8444,
652,
12237,
680,
267,
1449,
267,
2086,
275,
24706,
14,
1712,
63,
1450,
8,
84,
9,
267,
340,
465,
63,
7892,
26,
288,
372,
291,
14,
475,
63,
7892,
8,
1712,
9,
267,
587,
26,
288,
372,
2086,
2378,
347,
370,
63,
7892,
8,
277,
12,
2086,
304,
267,
1449,
267,
8777,
282,
769,
402,
510,
3100,
1947,
6346,
12,
3957,
314,
6346,
370,
10809,
267,
2952,
13932,
883,
1133,
3877,
6346,
14,
267,
1449,
267,
9151,
275,
942,
267,
367,
299,
315,
2086,
26,
288,
9151,
14,
740,
6333,
1027,
582,
299,
59,
16,
467,
298,
1450,
582,
299,
59,
17,
13412,
267,
372,
9151,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
687,
4645,
492,
8767,
83,
272,
492,
984,
272,
4325,
275,
984,
14,
3020,
59,
17,
61,
339,
307,
275,
8767,
83,
342,
272,
2086,
63,
2969,
275,
25987,
9440,
342,
14821,
543,
1551,
8,
2324,
9,
465,
289,
26,
267,
367,
634,
315,
289,
26,
288,
4645,
275,
307,
14,
15246,
8,
76,
9,
288,
2086,
275,
2086,
63,
2969,
14,
1450,
8,
4504,
9,
288,
308,
275,
3087,
288,
367,
299,
315,
2086,
26,
355,
308,
275,
308,
435,
299,
905,
1027,
937,
435,
298,
1689,
435,
299,
905,
1450,
937,
435,
6099,
1204,
298,
288,
870,
8,
83,
435,
1867,
78,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
24706,
199,
199,
533,
25987,
9440,
26,
339,
347,
1947,
8,
277,
12,
307,
12,
465,
63,
7892,
29,
549,
304,
267,
1449,
267,
8777,
282,
769,
402,
4645,
12,
2216,
3932,
1777,
402,
32093,
436,
372,
267,
282,
769,
10809,
334,
889,
5438,
2008,
730,
315,
666,
8444,
652,
12237,
680,
267,
1449,
267,
2086,
275,
24706,
14,
1712,
63,
1450,
8,
84,
9,
267,
340,
465,
63,
7892,
26,
288,
372,
291,
14,
475,
63,
7892,
8,
1712,
9,
267,
587,
26,
288,
372,
2086,
2378,
347,
370,
63,
7892,
8,
277,
12,
2086,
304,
267,
1449,
267,
8777,
282,
769,
402,
510,
3100,
1947,
6346,
12,
3957,
314,
6346,
370,
10809,
267,
2952,
13932,
883,
1133,
3877,
6346,
14,
267,
1449,
267,
9151,
275,
942,
267,
367,
299,
315,
2086,
26,
288,
9151,
14,
740,
6333,
1027,
582,
299,
59,
16,
467,
298,
1450,
582,
299,
59,
17,
13412,
267,
372,
9151,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
687,
4645,
492,
8767,
83,
272,
492,
984,
272,
4325,
275,
984,
14,
3020,
59,
17,
61,
339,
307,
275,
8767,
83,
342,
272,
2086,
63,
2969,
275,
25987,
9440,
342,
14821,
543,
1551,
8,
2324,
9,
465,
289,
26,
267,
367,
634,
315,
289,
26,
288,
4645,
275,
307,
14,
15246,
8,
76,
9,
288,
2086,
275,
2086,
63,
2969,
14,
1450,
8,
4504,
9,
288,
308,
275,
3087,
288,
367,
299,
315,
2086,
26,
355,
308,
275,
308,
435,
299,
905,
1027,
937,
435,
298,
1689,
435,
299,
905,
1450,
937,
435,
6099,
1204,
298,
288,
870,
8,
83,
435,
1867,
78,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
rohe/pysaml2-3
|
tests/test_05_md.py
|
1
|
52530
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009 Umeå University.
#
# 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 saml2.md"""
__author__ = 'roland.hedberg@umu.se (Roland Hedberg)'
import unittest
try:
from xml.etree import ElementTree
except ImportError:
from elementtree import ElementTree
import saml2
import xmldsig as ds
from saml2 import saml
from saml2 import samlp
from saml2 import md
from saml2.extension import idpdisc
from saml2.extension import shibmd
from saml2 import extension_element_to_element
import md_data, ds_data
class TestEndpointType:
def setup_class(self):
self.endpoint = md.EndpointType_()
def testAccessors(self):
"""Test for EndpointType accessors"""
self.endpoint.binding = saml2.BINDING_HTTP_POST
self.endpoint.location = "http://www.example.com/endpoint"
self.endpoint.response_location = "http://www.example.com/response"
print((list(self.endpoint.__class__.c_attributes.items())))
new_endpoint = md.endpoint_type__from_string(self.endpoint.to_string())
assert new_endpoint.binding == saml2.BINDING_HTTP_POST
assert new_endpoint.location == "http://www.example.com/endpoint"
assert new_endpoint.response_location == "http://www.example.com/response"
def testUsingTestData(self):
"""Test for endpoint_type_from_string() using test data."""
new_endpoint = md.endpoint_type__from_string(md_data.TEST_ENDPOINT)
assert new_endpoint.binding == saml2.BINDING_HTTP_POST
assert new_endpoint.location == "http://www.example.com/endpoint"
assert new_endpoint.response_location == "http://www.example.com/response"
class TestIndexedEndpointType:
def setup_class(self):
self.i_e = md.IndexedEndpointType_()
def testAccessors(self):
"""Test for IndexedEndpointType accessors"""
self.i_e.binding = saml2.BINDING_HTTP_POST
self.i_e.location = "http://www.example.com/endpoint"
self.i_e.response_location = "http://www.example.com/response"
self.i_e.index = "1"
self.i_e.is_default = "false"
new_i_e = md.indexed_endpoint_type__from_string(self.i_e.to_string())
assert new_i_e.binding == saml2.BINDING_HTTP_POST
assert new_i_e.location == "http://www.example.com/endpoint"
assert new_i_e.response_location == "http://www.example.com/response"
assert new_i_e.index == "1"
assert new_i_e.is_default == "false"
def testUsingTestData(self):
"""Test for indexed_endpoint_type_from_string() using test data."""
new_i_e = md.indexed_endpoint_type__from_string(md_data.TEST_INDEXED_ENDPOINT)
assert new_i_e.binding == saml2.BINDING_HTTP_POST
assert new_i_e.location == "http://www.example.com/endpoint"
assert new_i_e.response_location == "http://www.example.com/response"
assert new_i_e.index == "1"
assert new_i_e.is_default == "false"
class TestExtensions:
def setup_class(self):
self.extensions = md.Extensions()
def testAccessors(self):
"""Test for Extensions accessors"""
self.extensions.extension_elements.append(
saml2.extension_element_from_string(
"""<?xml version='1.0' encoding='UTF-8'?>
<hoge>fuga</hoge>
"""))
new_extensions = md.extensions_from_string(self.extensions.to_string())
assert new_extensions.extension_elements[0].tag == "hoge"
assert new_extensions.extension_elements[0].text.strip() == "fuga"
class TestOrganizationName:
def setup_class(self):
self.organization_name = md.OrganizationName()
def testAccessors(self):
"""Test for OrganizationName accessors"""
self.organization_name.lang = "en"
self.organization_name.text = "SIOS Technology, Inc."
new_organization_name = md.organization_name_from_string(
self.organization_name.to_string())
assert new_organization_name.lang == "en"
assert new_organization_name.text.strip() == "SIOS Technology, Inc."
def testUsingTestData(self):
"""Test for organization_name_from_string() using test data."""
new_organization_name = md.organization_name_from_string(
md_data.TEST_ORGANIZATION_NAME)
print((new_organization_name.keyswv()))
assert new_organization_name.lang == "se"
assert new_organization_name.text.strip() == "Catalogix"
class TestOrganizationDisplayName:
def setup_class(self):
self.od_name = md.OrganizationDisplayName()
def testAccessors(self):
"""Test for OrganizationDisplayName accessors"""
self.od_name.lang = "en"
self.od_name.text = "SIOS"
new_od_name = md.organization_display_name_from_string(
self.od_name.to_string())
assert new_od_name.lang == "en"
assert new_od_name.text.strip() == "SIOS"
def testUsingTestData(self):
"""Test for organization_display_name_from_string() using test data."""
new_od_name = md.organization_display_name_from_string(
md_data.TEST_ORGANIZATION_DISPLAY_NAME)
assert new_od_name.lang == "se"
assert new_od_name.text.strip() == "Catalogix"
class TestOrganizationURL:
def setup_class(self):
self.organization_url = md.OrganizationURL()
def testAccessors(self):
"""Test for OrganizationURL accessors"""
self.organization_url.lang = "ja"
self.organization_url.text = "http://www.example.com/"
print((self.organization_url.to_string()))
new_organization_url = md.organization_url_from_string(
self.organization_url.to_string())
assert new_organization_url.lang == "ja"
assert new_organization_url.text.strip() == "http://www.example.com/"
def testUsingTestData(self):
"""Test for organization_url_from_string() using test data."""
new_organization_url = md.organization_url_from_string(
md_data.TEST_ORGANIZATION_URL)
assert new_organization_url.lang == "no"
assert new_organization_url.text.strip() == "http://www.example.com/"
class TestOrganization:
def setup_class(self):
self.organization = md.Organization()
def testAccessors(self):
"""Test for Organization accessors"""
self.organization.extensions = md.Extensions()
self.organization.organization_name.append(
md.organization_name_from_string(md_data.TEST_ORGANIZATION_NAME))
self.organization.organization_display_name.append(
md.organization_display_name_from_string(
md_data.TEST_ORGANIZATION_DISPLAY_NAME))
self.organization.organization_url.append(
md.organization_url_from_string(md_data.TEST_ORGANIZATION_URL))
new_organization = md.organization_from_string(self.organization.to_string())
assert isinstance(new_organization.extensions, md.Extensions)
assert isinstance(new_organization.organization_name[0],
md.OrganizationName)
assert isinstance(new_organization.organization_display_name[0],
md.OrganizationDisplayName)
assert isinstance(new_organization.organization_url[0],
md.OrganizationURL)
assert new_organization.organization_name[0].text.strip() == "Catalogix"
assert new_organization.organization_name[0].lang == "se"
assert new_organization.organization_display_name[0].text.strip() == "Catalogix"
assert new_organization.organization_display_name[0].lang == "se"
assert new_organization.organization_url[0].text.strip() == "http://www.example.com/"
assert new_organization.organization_url[0].lang == "no"
def testUsingTestData(self):
"""Test for organization_from_string() using test data."""
new_organization = md.organization_from_string(
md_data.TEST_ORGANIZATION)
assert isinstance(new_organization.extensions, md.Extensions)
assert isinstance(new_organization.organization_name[0],
md.OrganizationName)
assert isinstance(new_organization.organization_display_name[0],
md.OrganizationDisplayName)
assert isinstance(new_organization.organization_url[0],
md.OrganizationURL)
assert new_organization.organization_name[0].text.strip() == "Catalogix AB"
assert new_organization.organization_name[0].lang == "se"
assert new_organization.organization_display_name[0].text.strip() == "Catalogix AS"
assert new_organization.organization_display_name[0].lang == "no"
assert new_organization.organization_url[0].text.strip() == "http://www.example.com/"
assert new_organization.organization_url[0].lang == "en"
class TestContactPerson:
def setup_class(self):
self.contact_person = md.ContactPerson()
def testAccessors(self):
"""Test for ContactPerson accessors"""
self.contact_person.contact_type = "technical"
self.contact_person.extensions = md.Extensions()
self.contact_person.company = md.Company(text="SIOS Technology, Inc.")
self.contact_person.given_name = md.GivenName(text="Takashi")
self.contact_person.sur_name = md.SurName(text="Matsuo")
self.contact_person.email_address.append(
md.EmailAddress(text="tmatsuo@example.com"))
self.contact_person.email_address.append(
md.EmailAddress(text="tmatsuo@shehas.net"))
self.contact_person.telephone_number.append(
md.TelephoneNumber(text="00-0000-0000"))
new_contact_person = md.contact_person_from_string(
self.contact_person.to_string())
assert new_contact_person.contact_type == "technical"
assert isinstance(new_contact_person.extensions, md.Extensions)
assert new_contact_person.company.text.strip() == "SIOS Technology, Inc."
assert new_contact_person.given_name.text.strip() == "Takashi"
assert new_contact_person.sur_name.text.strip() == "Matsuo"
assert new_contact_person.email_address[0].text.strip() == "tmatsuo@example.com"
assert new_contact_person.email_address[1].text.strip() == "tmatsuo@shehas.net"
assert new_contact_person.telephone_number[0].text.strip() == "00-0000-0000"
def testUsingTestData(self):
"""Test for contact_person_from_string() using test data."""
new_contact_person = md.contact_person_from_string(
md_data.TEST_CONTACT_PERSON)
assert new_contact_person.contact_type == "technical"
assert isinstance(new_contact_person.extensions, md.Extensions)
assert new_contact_person.company.text.strip() == "SIOS Technology, Inc."
assert new_contact_person.given_name.text.strip() == "Takashi"
assert new_contact_person.sur_name.text.strip() == "Matsuo"
assert new_contact_person.email_address[0].text.strip() == "tmatsuo@example.com"
assert new_contact_person.email_address[1].text.strip() == "tmatsuo@shehas.net"
assert new_contact_person.telephone_number[0].text.strip() == "00-0000-0000"
class TestAdditionalMetadataLocation:
def setup_class(self):
self.additional_metadata_location = md.AdditionalMetadataLocation()
def testAccessors(self):
"""Test for AdditionalMetadataLocation accessors"""
self.additional_metadata_location.namespace = (
"http://www.example.com/namespace")
self.additional_metadata_location.text = (
"http://www.example.com/AdditionalMetadataLocation")
new_additional_metadata_location = md.additional_metadata_location_from_string(
self.additional_metadata_location.to_string())
assert new_additional_metadata_location.namespace == "http://www.example.com/namespace"
assert new_additional_metadata_location.text.strip() == "http://www.example.com/AdditionalMetadataLocation"
def testUsingTestData(self):
"""Test for additional_metadata_location_from_string() using test data."""
new_additional_metadata_location = md.additional_metadata_location_from_string(
md_data.TEST_ADDITIONAL_METADATA_LOCATION)
assert new_additional_metadata_location.namespace == "http://www.example.com/namespace"
assert new_additional_metadata_location.text.strip() == "http://www.example.com/AdditionalMetadataLocation"
# class TestKeySize:
#
# def setup_class(self):
# self.key_size = md.KeySize()
#
# def testAccessors(self):
# """Test for KeySize accessors"""
# self.key_size.text = "128"
# new_key_size = md.key_size_from_string(self.key_size.to_string())
# assert new_key_size.text.strip() == "128"
#
# def testUsingTestData(self):
# """Test for key_size_from_string() using test data."""
# new_key_size = md.key_size_from_string(md_data.TEST_KEY_SIZE)
# assert new_key_size.text.strip() == "128"
# class TestOAEPparams:
#
# def setup_class(self):
# self.oaep_params = md.OAEPparams()
#
# def testAccessors(self):
# """Test for OAEPparams accessors"""
# self.oaep_params.text = "9lWu3Q=="
# new_oaep_params = md.oae_pparams_from_string(self.oaep_params.to_string())
# assert new_oaep_params.text.strip() == "9lWu3Q=="
#
# def testUsingTestData(self):
# """Test for oae_pparams_from_string() using test data."""
# new_oaep_params = md.oae_pparams_from_string(md_data.TEST_OAEP_PARAMS)
# assert new_oaep_params.text.strip() == "9lWu3Q=="
class TestEncryptionMethod:
def setup_class(self):
self.encryption_method = md.EncryptionMethod()
def testAccessors(self):
"""Test for EncryptionMethod accessors"""
self.encryption_method.algorithm = (
"http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p")
new_encryption_method = md.encryption_method_from_string(
self.encryption_method.to_string())
assert new_encryption_method.algorithm == "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"
def testUsingTestData(self):
"""Test for encryption_method_from_string() using test data."""
new_encryption_method = md.encryption_method_from_string(
md_data.TEST_ENCRYPTION_METHOD)
assert new_encryption_method.algorithm == "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"
assert new_encryption_method.oae_pparams.text.strip() == "9lWu3Q=="
class TestKeyDescriptor:
def setup_class(self):
self.key_descriptor = md.KeyDescriptor()
def testAccessors(self):
"""Test for KeyDescriptor accessors"""
self.key_descriptor.use = "signing"
self.key_descriptor.key_info = ds.key_info_from_string(
ds_data.TEST_KEY_INFO)
self.key_descriptor.encryption_method.append(md.encryption_method_from_string(
md_data.TEST_ENCRYPTION_METHOD))
new_key_descriptor = md.key_descriptor_from_string(
self.key_descriptor.to_string())
assert new_key_descriptor.use == "signing"
assert isinstance(new_key_descriptor.key_info, ds.KeyInfo)
assert isinstance(new_key_descriptor.encryption_method[0],
md.EncryptionMethod)
def testUsingTestData(self):
"""Test for key_descriptor_from_string() using test data."""
new_key_descriptor = md.key_descriptor_from_string(
md_data.TEST_KEY_DESCRIPTOR)
assert new_key_descriptor.use == "signing"
assert isinstance(new_key_descriptor.key_info, ds.KeyInfo)
assert isinstance(new_key_descriptor.encryption_method[0],
md.EncryptionMethod)
class TestRoleDescriptor:
def setup_class(self):
self.role_descriptor = md.RoleDescriptor()
def testAccessors(self):
"""Test for RoleDescriptor accessors"""
self.role_descriptor.id = "ID"
self.role_descriptor.valid_until = "2008-09-14T01:05:02Z"
self.role_descriptor.cache_duration = "10:00:00:00"
self.role_descriptor.protocol_support_enumeration = samlp.NAMESPACE
self.role_descriptor.error_url = "http://www.example.com/errorURL"
self.role_descriptor.signature = ds.Signature()
self.role_descriptor.extensions = md.Extensions()
self.role_descriptor.key_descriptor.append(md.key_descriptor_from_string(
md_data.TEST_KEY_DESCRIPTOR))
self.role_descriptor.organization = md.Organization()
self.role_descriptor.contact_person.append(md.ContactPerson())
new_role_descriptor = md.role_descriptor_from_string(
self.role_descriptor.to_string())
assert new_role_descriptor.id == "ID"
assert new_role_descriptor.valid_until == "2008-09-14T01:05:02Z"
assert new_role_descriptor.cache_duration == "10:00:00:00"
assert new_role_descriptor.protocol_support_enumeration == samlp.NAMESPACE
assert new_role_descriptor.error_url == "http://www.example.com/errorURL"
assert isinstance(new_role_descriptor.signature, ds.Signature)
assert isinstance(new_role_descriptor.extensions, md.Extensions)
assert isinstance(new_role_descriptor.key_descriptor[0],
md.KeyDescriptor)
assert isinstance(new_role_descriptor.organization, md.Organization)
assert isinstance(new_role_descriptor.contact_person[0],
md.ContactPerson)
def testUsingTestData(self):
"""Test for role_descriptor_from_string() using test data."""
new_role_descriptor = md.role_descriptor_from_string(
md_data.TEST_ROLE_DESCRIPTOR)
assert new_role_descriptor.id == "ID"
assert new_role_descriptor.valid_until == "2008-09-14T01:05:02Z"
assert new_role_descriptor.cache_duration == "10:00:00:00"
assert new_role_descriptor.protocol_support_enumeration == samlp.NAMESPACE
assert new_role_descriptor.error_url == "http://www.example.com/errorURL"
assert isinstance(new_role_descriptor.signature, ds.Signature)
assert isinstance(new_role_descriptor.extensions, md.Extensions)
assert isinstance(new_role_descriptor.key_descriptor[0],
md.KeyDescriptor)
assert isinstance(new_role_descriptor.organization, md.Organization)
assert isinstance(new_role_descriptor.contact_person[0],
md.ContactPerson)
# class TestSSODescriptor:
# def setup_class(self):
# self.sso_descriptor = md.SSODescriptorType_()
#
# def testAccessors(self):
# """Test for SSODescriptorType accessors"""
# self.sso_descriptor.id = "ID"
# self.sso_descriptor.valid_until = "2008-09-14T01:05:02Z"
# self.sso_descriptor.cache_duration = "10:00:00:00"
# self.sso_descriptor.protocol_support_enumeration = samlp.NAMESPACE
# self.sso_descriptor.error_url = "http://www.example.com/errorURL"
# self.sso_descriptor.signature = ds.Signature()
# self.sso_descriptor.extensions = md.Extensions()
# self.sso_descriptor.key_descriptor.append(md.key_descriptor_from_string(
# md_data.TEST_KEY_DESCRIPTOR))
# self.sso_descriptor.organization = md.Organization()
# self.sso_descriptor.contact_person.append(md.ContactPerson())
# self.sso_descriptor.artifact_resolution_service.append(
# md.ArtifactResolutionService())
# self.sso_descriptor.single_logout_service.append(
# md.SingleLogoutService())
# self.sso_descriptor.manage_name_id_service.append(
# md.ManageNameIDService())
# self.sso_descriptor.name_id_format.append(
# md.NameIDFormat())
#
# new_sso_descriptor = md.sso_descriptor_type__from_string(
# self.sso_descriptor.to_string())
# assert new_sso_descriptor.id == "ID"
# assert new_sso_descriptor.valid_until == "2008-09-14T01:05:02Z"
# assert new_sso_descriptor.cache_duration == "10:00:00:00"
# assert new_sso_descriptor.protocol_support_enumeration == samlp.NAMESPACE
# assert new_sso_descriptor.error_url == "http://www.example.com/errorURL"
# assert isinstance(new_sso_descriptor.signature, ds.Signature)
# assert isinstance(new_sso_descriptor.extensions, md.Extensions)
# assert isinstance(new_sso_descriptor.key_descriptor[0],
# md.KeyDescriptor)
# assert isinstance(new_sso_descriptor.organization, md.Organization)
# assert isinstance(new_sso_descriptor.contact_person[0],
# md.ContactPerson)
# assert isinstance(new_sso_descriptor.artifact_resolution_service[0],
# md.ArtifactResolutionService)
# assert isinstance(new_sso_descriptor.single_logout_service[0],
# md.SingleLogoutService)
# assert isinstance(new_sso_descriptor.manage_name_id_service[0],
# md.ManageNameIDService)
# assert isinstance(new_sso_descriptor.name_id_format[0],
# md.NameIDFormat)
#
class TestArtifactResolutionService:
def setup_class(self):
self.i_e = md.ArtifactResolutionService()
def testAccessors(self):
"""Test for ArtifactResolutionService accessors"""
self.i_e.binding = saml2.BINDING_HTTP_POST
self.i_e.location = "http://www.example.com/endpoint"
self.i_e.response_location = "http://www.example.com/response"
self.i_e.index = "1"
self.i_e.is_default = "false"
new_i_e = md.artifact_resolution_service_from_string(self.i_e.to_string())
assert new_i_e.binding == saml2.BINDING_HTTP_POST
assert new_i_e.location == "http://www.example.com/endpoint"
assert new_i_e.response_location == "http://www.example.com/response"
assert new_i_e.index == "1"
assert new_i_e.is_default == "false"
def testUsingTestData(self):
"""Test for artifact_resolution_service_from_string() using test data."""
new_i_e = md.artifact_resolution_service_from_string(
md_data.TEST_ARTIFACT_RESOLUTION_SERVICE)
assert new_i_e.binding == saml2.BINDING_HTTP_POST
assert new_i_e.location == "http://www.example.com/endpoint"
assert new_i_e.response_location == "http://www.example.com/response"
assert new_i_e.index == "1"
assert new_i_e.is_default == "false"
class TestSingleLogout:
def setup_class(self):
self.endpoint = md.SingleLogoutService()
def testAccessors(self):
"""Test for SingleLogoutService accessors"""
self.endpoint.binding = saml2.BINDING_HTTP_POST
self.endpoint.location = "http://www.example.com/endpoint"
self.endpoint.response_location = "http://www.example.com/response"
new_endpoint = md.single_logout_service_from_string(self.endpoint.to_string())
assert new_endpoint.binding == saml2.BINDING_HTTP_POST
assert new_endpoint.location == "http://www.example.com/endpoint"
assert new_endpoint.response_location == "http://www.example.com/response"
def testUsingTestData(self):
"""Test for single_logout_service_from_string() using test data."""
new_endpoint = md.single_logout_service_from_string(
md_data.TEST_SINGLE_LOGOUT_SERVICE)
assert new_endpoint.binding == saml2.BINDING_HTTP_POST
assert new_endpoint.location == "http://www.example.com/endpoint"
assert new_endpoint.response_location == "http://www.example.com/response"
class TestManageNameIDService:
def setup_class(self):
self.endpoint = md.ManageNameIDService()
def testAccessors(self):
"""Test for ManageNameIDService accessors"""
self.endpoint.binding = saml2.BINDING_HTTP_POST
self.endpoint.location = "http://www.example.com/endpoint"
self.endpoint.response_location = "http://www.example.com/response"
new_endpoint = md.manage_name_id_service_from_string(self.endpoint.to_string())
assert new_endpoint.binding == saml2.BINDING_HTTP_POST
assert new_endpoint.location == "http://www.example.com/endpoint"
assert new_endpoint.response_location == "http://www.example.com/response"
def testUsingTestData(self):
"""Test for manage_name_id_service_from_string() using test data."""
new_endpoint = md.manage_name_id_service_from_string(
md_data.TEST_MANAGE_NAMEID_SERVICE)
assert new_endpoint.binding == saml2.BINDING_HTTP_POST
assert new_endpoint.location == "http://www.example.com/endpoint"
assert new_endpoint.response_location == "http://www.example.com/response"
class TestNameIDFormat:
def setup_class(self):
self.name_id_format = md.NameIDFormat()
def testAccessors(self):
"""Test for NameIDFormat accessors"""
self.name_id_format.text = saml.NAMEID_FORMAT_EMAILADDRESS
new_name_id_format = md.name_id_format_from_string(
self.name_id_format.to_string())
assert new_name_id_format.text.strip() == saml.NAMEID_FORMAT_EMAILADDRESS
def testUsingTestData(self):
"""Test for name_id_format_from_string() using test data."""
new_name_id_format = md.name_id_format_from_string(
md_data.TEST_NAME_ID_FORMAT)
assert new_name_id_format.text.strip() == saml.NAMEID_FORMAT_EMAILADDRESS
class TestSingleSignOnService:
def setup_class(self):
self.endpoint = md.SingleSignOnService()
def testAccessors(self):
"""Test for SingelSignOnService accessors"""
self.endpoint.binding = saml2.BINDING_HTTP_POST
self.endpoint.location = "http://www.example.com/endpoint"
self.endpoint.response_location = "http://www.example.com/response"
new_endpoint = md.single_sign_on_service_from_string(self.endpoint.to_string())
assert new_endpoint.binding == saml2.BINDING_HTTP_POST
assert new_endpoint.location == "http://www.example.com/endpoint"
assert new_endpoint.response_location == "http://www.example.com/response"
def testUsingTestData(self):
"""Test for SingelSignOn_service_from_string() using test data."""
new_endpoint = md.single_sign_on_service_from_string(
md_data.TEST_SINGLE_SIGN_ON_SERVICE)
assert new_endpoint.binding == saml2.BINDING_HTTP_POST
assert new_endpoint.location == "http://www.example.com/endpoint"
assert new_endpoint.response_location == "http://www.example.com/response"
class TestNameIDMappingService:
def setup_class(self):
self.endpoint = md.NameIDMappingService()
def testAccessors(self):
"""Test for NameIDMappingService accessors"""
self.endpoint.binding = saml2.BINDING_HTTP_POST
self.endpoint.location = "http://www.example.com/endpoint"
self.endpoint.response_location = "http://www.example.com/response"
new_endpoint = md.name_id_mapping_service_from_string(self.endpoint.to_string())
assert new_endpoint.binding == saml2.BINDING_HTTP_POST
assert new_endpoint.location == "http://www.example.com/endpoint"
assert new_endpoint.response_location == "http://www.example.com/response"
def testUsingTestData(self):
"""Test for name_id_mapping_service_from_string() using test data."""
new_endpoint = md.name_id_mapping_service_from_string(
md_data.TEST_NAME_ID_MAPPING_SERVICE)
assert new_endpoint.binding == saml2.BINDING_HTTP_POST
assert new_endpoint.location == "http://www.example.com/endpoint"
assert new_endpoint.response_location == "http://www.example.com/response"
class TestAssertionIDRequestService:
def setup_class(self):
self.endpoint = md.AssertionIDRequestService()
def testAccessors(self):
"""Test for AssertionIDRequestService accessors"""
self.endpoint.binding = saml2.BINDING_HTTP_POST
self.endpoint.location = "http://www.example.com/endpoint"
self.endpoint.response_location = "http://www.example.com/response"
new_endpoint = md.assertion_id_request_service_from_string(
self.endpoint.to_string())
assert new_endpoint.binding == saml2.BINDING_HTTP_POST
assert new_endpoint.location == "http://www.example.com/endpoint"
assert new_endpoint.response_location == "http://www.example.com/response"
def testUsingTestData(self):
"""Test for assertion_id_request_service_from_string() using test data."""
new_endpoint = md.assertion_id_request_service_from_string(
md_data.TEST_ASSERTION_ID_REQUEST_SERVICE)
assert new_endpoint.binding == saml2.BINDING_HTTP_POST
assert new_endpoint.location == "http://www.example.com/endpoint"
assert new_endpoint.response_location == "http://www.example.com/response"
class TestAttributeProfile:
def setup_class(self):
self.attribute_profile = md.AttributeProfile()
def testAccessors(self):
"""Test for AttributeProfile accessors"""
self.attribute_profile.text = saml.PROFILE_ATTRIBUTE_BASIC
new_attribute_profile = md.attribute_profile_from_string(
self.attribute_profile.to_string())
assert new_attribute_profile.text.strip() == saml.PROFILE_ATTRIBUTE_BASIC
def testUsingTestData(self):
"""Test for name_id_format_from_string() using test data."""
new_attribute_profile = md.attribute_profile_from_string(
md_data.TEST_ATTRIBUTE_PROFILE)
assert new_attribute_profile.text.strip() == saml.PROFILE_ATTRIBUTE_BASIC
class TestIDPSSODescriptor:
def setup_class(self):
self.idp_sso_descriptor = md.IDPSSODescriptor()
def testAccessors(self):
"""Test for IDPSSODescriptor accessors"""
self.idp_sso_descriptor.id = "ID"
self.idp_sso_descriptor.valid_until = "2008-09-14T01:05:02Z"
self.idp_sso_descriptor.cache_duration = "10:00:00:00"
self.idp_sso_descriptor.protocol_support_enumeration = \
samlp.NAMESPACE
self.idp_sso_descriptor.error_url = "http://www.example.com/errorURL"
self.idp_sso_descriptor.signature = ds.Signature()
self.idp_sso_descriptor.extensions = md.Extensions()
self.idp_sso_descriptor.key_descriptor.append(md.key_descriptor_from_string(
md_data.TEST_KEY_DESCRIPTOR))
self.idp_sso_descriptor.organization = md.Organization()
self.idp_sso_descriptor.contact_person.append(md.ContactPerson())
self.idp_sso_descriptor.artifact_resolution_service.append(
md.ArtifactResolutionService())
self.idp_sso_descriptor.single_logout_service.append(
md.SingleLogoutService())
self.idp_sso_descriptor.manage_name_id_service.append(
md.ManageNameIDService())
self.idp_sso_descriptor.name_id_format.append(
md.NameIDFormat())
self.idp_sso_descriptor.want_authn_requests_signed = 'true'
self.idp_sso_descriptor.single_sign_on_service.append(
md.SingleSignOnService())
self.idp_sso_descriptor.name_id_mapping_service.append(
md.NameIDMappingService())
self.idp_sso_descriptor.assertion_id_request_service.append(
md.AssertionIDRequestService())
self.idp_sso_descriptor.attribute_profile.append(
md.AttributeProfile())
self.idp_sso_descriptor.attribute.append(saml.Attribute())
new_idp_sso_descriptor = md.idpsso_descriptor_from_string(
self.idp_sso_descriptor.to_string())
assert new_idp_sso_descriptor.id == "ID"
assert new_idp_sso_descriptor.valid_until == "2008-09-14T01:05:02Z"
assert new_idp_sso_descriptor.cache_duration == "10:00:00:00"
assert new_idp_sso_descriptor.protocol_support_enumeration == samlp.NAMESPACE
assert new_idp_sso_descriptor.error_url == "http://www.example.com/errorURL"
assert isinstance(new_idp_sso_descriptor.signature, ds.Signature)
assert isinstance(new_idp_sso_descriptor.extensions, md.Extensions)
assert isinstance(new_idp_sso_descriptor.key_descriptor[0],
md.KeyDescriptor)
assert isinstance(new_idp_sso_descriptor.organization,
md.Organization)
assert isinstance(new_idp_sso_descriptor.contact_person[0],
md.ContactPerson)
assert isinstance(
new_idp_sso_descriptor.artifact_resolution_service[0],
md.ArtifactResolutionService)
assert isinstance(new_idp_sso_descriptor.single_logout_service[0],
md.SingleLogoutService)
assert isinstance(new_idp_sso_descriptor.manage_name_id_service[0],
md.ManageNameIDService)
assert isinstance(new_idp_sso_descriptor.name_id_format[0],
md.NameIDFormat)
assert new_idp_sso_descriptor.want_authn_requests_signed == "true"
assert isinstance(new_idp_sso_descriptor.single_sign_on_service[0],
md.SingleSignOnService)
assert isinstance(new_idp_sso_descriptor.name_id_mapping_service[0],
md.NameIDMappingService)
assert isinstance(
new_idp_sso_descriptor.assertion_id_request_service[0],
md.AssertionIDRequestService)
assert isinstance(new_idp_sso_descriptor.attribute_profile[0],
md.AttributeProfile)
assert isinstance(new_idp_sso_descriptor.attribute[0],
saml.Attribute)
def testUsingTestData(self):
"""Test for idpsso_descriptor_from_string() using test data."""
new_idp_sso_descriptor = md.idpsso_descriptor_from_string(
md_data.TEST_IDP_SSO_DESCRIPTOR)
assert new_idp_sso_descriptor.id == "ID"
assert new_idp_sso_descriptor.valid_until == "2008-09-14T01:05:02Z"
assert new_idp_sso_descriptor.cache_duration == "10:00:00:00"
assert new_idp_sso_descriptor.protocol_support_enumeration == samlp.NAMESPACE
assert new_idp_sso_descriptor.error_url == "http://www.example.com/errorURL"
assert isinstance(new_idp_sso_descriptor.signature, ds.Signature)
assert isinstance(new_idp_sso_descriptor.extensions, md.Extensions)
assert isinstance(new_idp_sso_descriptor.key_descriptor[0],
md.KeyDescriptor)
assert isinstance(new_idp_sso_descriptor.organization,
md.Organization)
assert isinstance(new_idp_sso_descriptor.contact_person[0],
md.ContactPerson)
assert isinstance(
new_idp_sso_descriptor.artifact_resolution_service[0],
md.ArtifactResolutionService)
assert isinstance(new_idp_sso_descriptor.single_logout_service[0],
md.SingleLogoutService)
assert isinstance(new_idp_sso_descriptor.manage_name_id_service[0],
md.ManageNameIDService)
assert isinstance(new_idp_sso_descriptor.name_id_format[0],
md.NameIDFormat)
assert new_idp_sso_descriptor.want_authn_requests_signed == "true"
assert isinstance(new_idp_sso_descriptor.single_sign_on_service[0],
md.SingleSignOnService)
assert isinstance(new_idp_sso_descriptor.name_id_mapping_service[0],
md.NameIDMappingService)
assert isinstance(
new_idp_sso_descriptor.assertion_id_request_service[0],
md.AssertionIDRequestService)
assert isinstance(new_idp_sso_descriptor.attribute_profile[0],
md.AttributeProfile)
assert isinstance(new_idp_sso_descriptor.attribute[0],
saml.Attribute)
def testUsingScope(self):
descriptor = md.IDPSSODescriptor()
scope = shibmd.Scope()
scope.text = "example.org"
scope.regexp = "false"
descriptor.extensions = md.Extensions()
ext = saml2.element_to_extension_element(scope)
descriptor.extensions.extension_elements.append(ext)
exts = descriptor.extensions
assert len(exts.extension_elements) == 1
elem = exts.extension_elements[0]
inst = saml2.extension_element_to_element(elem,
shibmd.ELEMENT_FROM_STRING,
namespace=shibmd.NAMESPACE)
assert isinstance(inst, shibmd.Scope)
assert inst.text == "example.org"
assert inst.regexp == "false"
class TestAssertionConsumerService:
def setup_class(self):
self.i_e = md.AssertionConsumerService()
def testAccessors(self):
"""Test for AssertionConsumerService accessors"""
self.i_e.binding = saml2.BINDING_HTTP_POST
self.i_e.location = "http://www.example.com/endpoint"
self.i_e.response_location = "http://www.example.com/response"
self.i_e.index = "1"
self.i_e.is_default = "false"
new_i_e = md.assertion_consumer_service_from_string(self.i_e.to_string())
assert new_i_e.binding == saml2.BINDING_HTTP_POST
assert new_i_e.location == "http://www.example.com/endpoint"
assert new_i_e.response_location == "http://www.example.com/response"
assert new_i_e.index == "1"
assert new_i_e.is_default == "false"
def testUsingTestData(self):
"""Test for assertion_consumer_service_from_string() using test data."""
new_i_e = md.assertion_consumer_service_from_string(
md_data.TEST_ASSERTION_CONSUMER_SERVICE)
assert new_i_e.binding == saml2.BINDING_HTTP_POST
assert new_i_e.location == "http://www.example.com/endpoint"
assert new_i_e.response_location == "http://www.example.com/response"
assert new_i_e.index == "1"
assert new_i_e.is_default == "false"
class TestRequestedAttribute:
def setup_class(self):
self.requested_attribute = md.RequestedAttribute()
def testAccessors(self):
"""Test for RequestedAttribute accessors"""
assert isinstance(self.requested_attribute, saml.AttributeType_)
assert isinstance(self.requested_attribute, md.RequestedAttribute)
assert self.requested_attribute.is_required is None
self.requested_attribute.is_required = "true"
new_requested_attribute = md.requested_attribute_from_string(
self.requested_attribute.to_string())
assert new_requested_attribute.is_required == "true"
assert isinstance(new_requested_attribute, saml.AttributeType_)
assert isinstance(new_requested_attribute, md.RequestedAttribute)
def testUsingTestData(self):
"""Test for requested_attribute_from_string() using test data."""
new_requested_attribute = md.requested_attribute_from_string(
md_data.TEST_REQUESTED_ATTRIBUTE)
assert new_requested_attribute.is_required == "true"
assert isinstance(new_requested_attribute, saml.AttributeType_)
assert isinstance(new_requested_attribute, md.RequestedAttribute)
class TestServiceName:
def setup_class(self):
self.service_name = md.ServiceName()
def testAccessors(self):
"""Test for ServiceName accessors"""
self.service_name.lang = "en"
self.service_name.text = "SIOS mail"
new_service_name = md.service_name_from_string(self.service_name.to_string())
assert new_service_name.lang == "en"
assert new_service_name.text.strip() == "SIOS mail"
def testUsingTestData(self):
"""Test for organization_name_from_string() using test data."""
new_service_name = md.service_name_from_string(md_data.TEST_SERVICE_NAME)
assert new_service_name.lang == "en"
assert new_service_name.text.strip() == "Catalogix Whois"
class TestServiceDescription:
def setup_class(self):
self.service_description = md.ServiceDescription()
def testAccessors(self):
"""Test for ServiceDescription accessors"""
self.service_description.lang = "en"
self.service_description.text = "SIOS mail service"
new_service_description = md.service_description_from_string(
self.service_description.to_string())
assert new_service_description.lang == "en"
assert new_service_description.text.strip() == "SIOS mail service"
def testUsingTestData(self):
"""Test for organization_name_from_string() using test data."""
new_service_description = md.service_description_from_string(
md_data.TEST_SERVICE_DESCRIPTION)
assert new_service_description.lang == "en"
assert new_service_description.text.strip() == "Catalogix Whois Service"
class TestAttributeConsumingService:
def setup_class(self):
self.attribute_consuming_service = md.AttributeConsumingService()
def testAccessors(self):
"""Test for AttributeConsumingService accessors"""
self.attribute_consuming_service.service_name.append(md.ServiceName())
self.attribute_consuming_service.service_description.append(
md.ServiceDescription())
self.attribute_consuming_service.requested_attribute.append(
md.RequestedAttribute())
self.attribute_consuming_service.index = "1"
self.attribute_consuming_service.is_default = "true"
new_attribute_consuming_service = md.attribute_consuming_service_from_string(
self.attribute_consuming_service.to_string())
assert new_attribute_consuming_service.index == "1"
assert new_attribute_consuming_service.is_default == "true"
assert isinstance(new_attribute_consuming_service.service_name[0],
md.ServiceName)
assert isinstance(
new_attribute_consuming_service.service_description[0],
md.ServiceDescription)
assert isinstance(
new_attribute_consuming_service.requested_attribute[0],
md.RequestedAttribute)
def testUsingTestData(self):
"""Test for attribute_consuming_service_from_string() using test data."""
new_attribute_consuming_service = md.attribute_consuming_service_from_string(
md_data.TEST_ATTRIBUTE_CONSUMING_SERVICE)
assert new_attribute_consuming_service.index == "1"
assert new_attribute_consuming_service.is_default == "true"
assert isinstance(new_attribute_consuming_service.service_name[0],
md.ServiceName)
assert isinstance(
new_attribute_consuming_service.service_description[0],
md.ServiceDescription)
assert isinstance(
new_attribute_consuming_service.requested_attribute[0],
md.RequestedAttribute)
class TestSPSSODescriptor:
def setup_class(self):
self.sp_sso_descriptor = md.SPSSODescriptor()
def testAccessors(self):
"""Test for SPSSODescriptor accessors"""
self.sp_sso_descriptor.id = "ID"
self.sp_sso_descriptor.valid_until = "2008-09-14T01:05:02Z"
self.sp_sso_descriptor.cache_duration = "10:00:00:00"
self.sp_sso_descriptor.protocol_support_enumeration = \
samlp.NAMESPACE
self.sp_sso_descriptor.error_url = "http://www.example.com/errorURL"
self.sp_sso_descriptor.signature = ds.Signature()
self.sp_sso_descriptor.extensions = md.Extensions()
self.sp_sso_descriptor.key_descriptor.append(md.key_descriptor_from_string(
md_data.TEST_KEY_DESCRIPTOR))
self.sp_sso_descriptor.organization = md.Organization()
self.sp_sso_descriptor.contact_person.append(md.ContactPerson())
self.sp_sso_descriptor.artifact_resolution_service.append(
md.ArtifactResolutionService())
self.sp_sso_descriptor.single_logout_service.append(
md.SingleLogoutService())
self.sp_sso_descriptor.manage_name_id_service.append(
md.ManageNameIDService())
self.sp_sso_descriptor.name_id_format.append(
md.NameIDFormat())
self.sp_sso_descriptor.authn_requests_signed = "true"
self.sp_sso_descriptor.want_assertions_signed = "true"
self.sp_sso_descriptor.assertion_consumer_service.append(
md.AssertionConsumerService())
self.sp_sso_descriptor.attribute_consuming_service.append(
md.AttributeConsumingService())
print((self.sp_sso_descriptor))
new_sp_sso_descriptor = md.spsso_descriptor_from_string(
self.sp_sso_descriptor.to_string())
print(new_sp_sso_descriptor)
assert new_sp_sso_descriptor.id == "ID"
assert new_sp_sso_descriptor.valid_until == "2008-09-14T01:05:02Z"
assert new_sp_sso_descriptor.cache_duration == "10:00:00:00"
assert new_sp_sso_descriptor.protocol_support_enumeration == samlp.NAMESPACE
assert new_sp_sso_descriptor.error_url == "http://www.example.com/errorURL"
assert isinstance(new_sp_sso_descriptor.signature, ds.Signature)
assert isinstance(new_sp_sso_descriptor.extensions, md.Extensions)
assert isinstance(new_sp_sso_descriptor.key_descriptor[0],
md.KeyDescriptor)
assert isinstance(new_sp_sso_descriptor.organization,
md.Organization)
assert isinstance(new_sp_sso_descriptor.contact_person[0],
md.ContactPerson)
assert isinstance(
new_sp_sso_descriptor.artifact_resolution_service[0],
md.ArtifactResolutionService)
assert isinstance(new_sp_sso_descriptor.single_logout_service[0],
md.SingleLogoutService)
assert isinstance(new_sp_sso_descriptor.manage_name_id_service[0],
md.ManageNameIDService)
assert isinstance(new_sp_sso_descriptor.name_id_format[0],
md.NameIDFormat)
assert new_sp_sso_descriptor.authn_requests_signed == "true"
assert new_sp_sso_descriptor.want_assertions_signed == "true"
assert isinstance(
new_sp_sso_descriptor.assertion_consumer_service[0],
md.AssertionConsumerService)
assert isinstance(
new_sp_sso_descriptor.attribute_consuming_service[0],
md.AttributeConsumingService)
def testUsingTestData(self):
"""Test for spsso_descriptor_from_string() using test data."""
new_sp_sso_descriptor = md.spsso_descriptor_from_string(
md_data.TEST_SP_SSO_DESCRIPTOR)
assert new_sp_sso_descriptor.id == "ID"
assert new_sp_sso_descriptor.valid_until == "2008-09-14T01:05:02Z"
assert new_sp_sso_descriptor.cache_duration == "10:00:00:00"
assert new_sp_sso_descriptor.protocol_support_enumeration == samlp.NAMESPACE
assert new_sp_sso_descriptor.error_url == "http://www.example.com/errorURL"
assert isinstance(new_sp_sso_descriptor.signature, ds.Signature)
assert isinstance(new_sp_sso_descriptor.extensions, md.Extensions)
print((new_sp_sso_descriptor.extensions.__dict__))
assert len(new_sp_sso_descriptor.extensions.extension_elements) == 2
for eelem in new_sp_sso_descriptor.extensions.extension_elements:
print(("EE",eelem.__dict__))
dp = extension_element_to_element(eelem, idpdisc.ELEMENT_FROM_STRING,
idpdisc.NAMESPACE)
print(("DP",dp.c_tag, dp.c_namespace,dp.__dict__))
assert isinstance(dp, idpdisc.DiscoveryResponse)
assert isinstance(new_sp_sso_descriptor.key_descriptor[0],
md.KeyDescriptor)
assert isinstance(new_sp_sso_descriptor.organization,
md.Organization)
assert isinstance(new_sp_sso_descriptor.contact_person[0],
md.ContactPerson)
assert isinstance(
new_sp_sso_descriptor.artifact_resolution_service[0],
md.ArtifactResolutionService)
assert isinstance(new_sp_sso_descriptor.single_logout_service[0],
md.SingleLogoutService)
assert isinstance(new_sp_sso_descriptor.manage_name_id_service[0],
md.ManageNameIDService)
assert isinstance(new_sp_sso_descriptor.name_id_format[0],
md.NameIDFormat)
assert new_sp_sso_descriptor.authn_requests_signed == "true"
assert new_sp_sso_descriptor.want_assertions_signed == "true"
assert isinstance(
new_sp_sso_descriptor.assertion_consumer_service[0],
md.AssertionConsumerService)
assert isinstance(
new_sp_sso_descriptor.attribute_consuming_service[0],
md.AttributeConsumingService)
class TestEntityDescriptor:
def setup_class(self):
self.entity_descriptor = md.EntityDescriptor()
def testAccessors(self):
"""Test for RoleDescriptor accessors"""
self.entity_descriptor.id = "ID"
self.entity_descriptor.entity_id = "entityID"
self.entity_descriptor.valid_until = "2008-09-14T01:05:02Z"
self.entity_descriptor.cache_duration = "10:00:00:00"
self.entity_descriptor.signature = ds.Signature()
self.entity_descriptor.extensions = md.Extensions()
self.entity_descriptor.role_descriptor.append(md.RoleDescriptor())
self.entity_descriptor.idpsso_descriptor.append(md.IDPSSODescriptor())
self.entity_descriptor.spsso_descriptor.append(md.SPSSODescriptor())
self.entity_descriptor.organization = md.Organization()
self.entity_descriptor.contact_person.append(md.ContactPerson())
self.entity_descriptor.additional_metadata_location.append(
md.AdditionalMetadataLocation())
new_entity_descriptor = md.entity_descriptor_from_string(
self.entity_descriptor.to_string())
assert new_entity_descriptor.id == "ID"
assert new_entity_descriptor.entity_id == "entityID"
assert new_entity_descriptor.valid_until == "2008-09-14T01:05:02Z"
assert new_entity_descriptor.cache_duration == "10:00:00:00"
assert isinstance(new_entity_descriptor.signature, ds.Signature)
assert isinstance(new_entity_descriptor.extensions, md.Extensions)
assert isinstance(new_entity_descriptor.role_descriptor[0],
md.RoleDescriptor)
assert isinstance(new_entity_descriptor.idpsso_descriptor[0],
md.IDPSSODescriptor)
assert isinstance(new_entity_descriptor.spsso_descriptor[0],
md.SPSSODescriptor)
assert isinstance(new_entity_descriptor.organization,
md.Organization)
assert isinstance(new_entity_descriptor.contact_person[0],
md.ContactPerson)
assert isinstance(
new_entity_descriptor.additional_metadata_location[0],
md.AdditionalMetadataLocation)
def testUsingTestData(self):
"""Test for entity_descriptor_from_string() using test data."""
new_entity_descriptor = md.entity_descriptor_from_string(
md_data.TEST_ENTITY_DESCRIPTOR)
assert new_entity_descriptor.id == "ID"
assert new_entity_descriptor.entity_id == "entityID"
assert new_entity_descriptor.valid_until == "2008-09-14T01:05:02Z"
assert new_entity_descriptor.cache_duration == "10:00:00:00"
assert isinstance(new_entity_descriptor.signature, ds.Signature)
assert isinstance(new_entity_descriptor.extensions, md.Extensions)
assert isinstance(new_entity_descriptor.role_descriptor[0],
md.RoleDescriptor)
assert isinstance(new_entity_descriptor.idpsso_descriptor[0],
md.IDPSSODescriptor)
assert isinstance(new_entity_descriptor.spsso_descriptor[0],
md.SPSSODescriptor)
assert isinstance(new_entity_descriptor.organization,
md.Organization)
assert isinstance(new_entity_descriptor.contact_person[0],
md.ContactPerson)
assert isinstance(new_entity_descriptor.additional_metadata_location[0],
md.AdditionalMetadataLocation)
class TestEntitiesDescriptor:
def setup_class(self):
self.entities_descriptor = md.EntitiesDescriptor()
def testAccessors(self):
"""Test for EntitiesDescriptor accessors"""
self.entities_descriptor.id = "ID"
self.entities_descriptor.name = "name"
self.entities_descriptor.valid_until = "2008-09-14T01:05:02Z"
self.entities_descriptor.cache_duration = "10:00:00:00"
self.entities_descriptor.signature = ds.Signature()
self.entities_descriptor.extensions = md.Extensions()
self.entities_descriptor.entity_descriptor.append(md.EntityDescriptor())
self.entities_descriptor.entities_descriptor.append(
md.EntitiesDescriptor())
new_entities_descriptor = md.entities_descriptor_from_string(
self.entities_descriptor.to_string())
assert new_entities_descriptor.id == "ID"
assert new_entities_descriptor.name == "name"
assert new_entities_descriptor.valid_until == "2008-09-14T01:05:02Z"
assert new_entities_descriptor.cache_duration == "10:00:00:00"
assert isinstance(new_entities_descriptor.signature, ds.Signature)
assert isinstance(new_entities_descriptor.extensions, md.Extensions)
assert isinstance(new_entities_descriptor.entity_descriptor[0],
md.EntityDescriptor)
assert isinstance(new_entities_descriptor.entities_descriptor[0],
md.EntitiesDescriptor)
def testUsingTestData(self):
"""Test for entities_descriptor_from_string() using test data."""
new_entities_descriptor = md.entities_descriptor_from_string(
md_data.TEST_ENTITIES_DESCRIPTOR)
assert new_entities_descriptor.id == "ID"
assert new_entities_descriptor.name == "name"
assert new_entities_descriptor.valid_until == "2008-09-14T01:05:02Z"
assert new_entities_descriptor.cache_duration == "10:00:00:00"
assert isinstance(new_entities_descriptor.signature, ds.Signature)
assert isinstance(new_entities_descriptor.extensions, md.Extensions)
assert isinstance(new_entities_descriptor.entity_descriptor[0],
md.EntityDescriptor)
assert isinstance(new_entities_descriptor.entities_descriptor[0],
md.EntitiesDescriptor)
|
bsd-2-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
35,
9,
8937,
738,
278,
30234,
15904,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
2925,
367,
25607,
18,
14,
1064,
624,
199,
199,
363,
2502,
363,
275,
283,
8459,
460,
14,
19985,
14630,
32,
453,
85,
14,
261,
334,
50,
393,
460,
869,
379,
14630,
3171,
199,
199,
646,
2882,
199,
893,
26,
523,
687,
2748,
14,
9464,
492,
13139,
199,
2590,
3545,
26,
523,
687,
1819,
2350,
492,
13139,
199,
199,
646,
25607,
18,
199,
646,
2748,
68,
4093,
465,
6364,
199,
199,
504,
25607,
18,
492,
25607,
199,
504,
25607,
18,
492,
25607,
80,
199,
504,
25607,
18,
492,
6128,
221,
199,
504,
25607,
18,
14,
3435,
492,
1305,
80,
6409,
199,
504,
25607,
18,
14,
3435,
492,
1033,
1892,
1064,
199,
199,
504,
25607,
18,
492,
3329,
63,
2108,
63,
475,
63,
2108,
199,
646,
6128,
63,
576,
12,
6364,
63,
576,
199,
199,
533,
1379,
11442,
804,
26,
819,
347,
3272,
63,
533,
8,
277,
304,
272,
291,
14,
6520,
275,
6128,
14,
11442,
804,
12798,
819,
347,
511,
3946,
1384,
8,
277,
304,
272,
408,
774,
367,
9599,
1403,
804,
31908,
624,
272,
291,
14,
6520,
14,
9140,
275,
25607,
18,
14,
28347,
63,
2856,
63,
4030,
272,
291,
14,
6520,
14,
1985,
275,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
6520,
2,
272,
291,
14,
6520,
14,
1310,
63,
1985,
275,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
1310,
2,
272,
870,
1332,
513,
8,
277,
14,
6520,
855,
533,
4343,
67,
63,
2987,
14,
1744,
16890,
272,
892,
63,
6520,
275,
6128,
14,
6520,
63,
466,
363,
504,
63,
875,
8,
277,
14,
6520,
14,
475,
63,
875,
1012,
272,
702,
892,
63,
6520,
14,
9140,
508,
25607,
18,
14,
28347,
63,
2856,
63,
4030,
272,
702,
892,
63,
6520,
14,
1985,
508,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
6520,
2,
272,
702,
892,
63,
6520,
14,
1310,
63,
1985,
508,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
1310,
2,
819,
347,
511,
10369,
16550,
8,
277,
304,
272,
408,
774,
367,
6037,
63,
466,
63,
504,
63,
875,
342,
1808,
511,
666,
1041,
272,
892,
63,
6520,
275,
6128,
14,
6520,
63,
466,
363,
504,
63,
875,
8,
1064,
63,
576,
14,
2864,
63,
21054,
9,
272,
702,
892,
63,
6520,
14,
9140,
508,
25607,
18,
14,
28347,
63,
2856,
63,
4030,
272,
702,
892,
63,
6520,
14,
1985,
508,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
6520,
2,
272,
702,
892,
63,
6520,
14,
1310,
63,
1985,
508,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
1310,
2,
16872,
199,
533,
1379,
19067,
11442,
804,
26,
819,
347,
3272,
63,
533,
8,
277,
304,
272,
291,
14,
73,
63,
69,
275,
6128,
14,
19067,
11442,
804,
12798,
819,
347,
511,
3946,
1384,
8,
277,
304,
272,
408,
774,
367,
26437,
11442,
804,
31908,
624,
272,
291,
14,
73,
63,
69,
14,
9140,
275,
25607,
18,
14,
28347,
63,
2856,
63,
4030,
272,
291,
14,
73,
63,
69,
14,
1985,
275,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
6520,
2,
272,
291,
14,
73,
63,
69,
14,
1310,
63,
1985,
275,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
1310,
2,
272,
291,
14,
73,
63,
69,
14,
1080,
275,
298,
17,
2,
272,
291,
14,
73,
63,
69,
14,
374,
63,
885,
275,
298,
3910,
2,
272,
892,
63,
73,
63,
69,
275,
6128,
14,
16821,
63,
6520,
63,
466,
363,
504,
63,
875,
8,
277,
14,
73,
63,
69,
14,
475,
63,
875,
1012,
272,
702,
892,
63,
73,
63,
69,
14,
9140,
508,
25607,
18,
14,
28347,
63,
2856,
63,
4030,
272,
702,
892,
63,
73,
63,
69,
14,
1985,
508,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
6520,
2,
272,
702,
892,
63,
73,
63,
69,
14,
1310,
63,
1985,
508,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
1310,
2,
272,
702,
892,
63,
73,
63,
69,
14,
1080,
508,
298,
17,
2,
272,
702,
892,
63,
73,
63,
69,
14,
374,
63,
885,
508,
298,
3910,
2,
819,
347,
511,
10369,
16550,
8,
277,
304,
272,
408,
774,
367,
15235,
63,
6520,
63,
466,
63,
504,
63,
875,
342,
1808,
511,
666,
1041,
272,
892,
63,
73,
63,
69,
275,
6128,
14,
16821,
63,
6520,
63,
466,
363,
504,
63,
875,
8,
1064,
63,
576,
14,
2864,
63,
10215,
1149,
63,
21054,
9,
272,
702,
892,
63,
73,
63,
69,
14,
9140,
508,
25607,
18,
14,
28347,
63,
2856,
63,
4030,
272,
702,
892,
63,
73,
63,
69,
14,
1985,
508,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
6520,
2,
272,
702,
892,
63,
73,
63,
69,
14,
1310,
63,
1985,
508,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
1310,
2,
272,
702,
892,
63,
73,
63,
69,
14,
1080,
508,
298,
17,
2,
272,
702,
892,
63,
73,
63,
69,
14,
374,
63,
885,
508,
298,
3910,
2,
421,
199,
533,
1379,
10597,
26,
819,
347,
3272,
63,
533,
8,
277,
304,
272,
291,
14,
5359,
275,
6128,
14,
10597,
342,
819,
347,
511,
3946,
1384,
8,
277,
304,
272,
408,
774,
367,
11524,
1356,
31908,
624
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
35,
9,
8937,
738,
278,
30234,
15904,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
2925,
367,
25607,
18,
14,
1064,
624,
199,
199,
363,
2502,
363,
275,
283,
8459,
460,
14,
19985,
14630,
32,
453,
85,
14,
261,
334,
50,
393,
460,
869,
379,
14630,
3171,
199,
199,
646,
2882,
199,
893,
26,
523,
687,
2748,
14,
9464,
492,
13139,
199,
2590,
3545,
26,
523,
687,
1819,
2350,
492,
13139,
199,
199,
646,
25607,
18,
199,
646,
2748,
68,
4093,
465,
6364,
199,
199,
504,
25607,
18,
492,
25607,
199,
504,
25607,
18,
492,
25607,
80,
199,
504,
25607,
18,
492,
6128,
221,
199,
504,
25607,
18,
14,
3435,
492,
1305,
80,
6409,
199,
504,
25607,
18,
14,
3435,
492,
1033,
1892,
1064,
199,
199,
504,
25607,
18,
492,
3329,
63,
2108,
63,
475,
63,
2108,
199,
646,
6128,
63,
576,
12,
6364,
63,
576,
199,
199,
533,
1379,
11442,
804,
26,
819,
347,
3272,
63,
533,
8,
277,
304,
272,
291,
14,
6520,
275,
6128,
14,
11442,
804,
12798,
819,
347,
511,
3946,
1384,
8,
277,
304,
272,
408,
774,
367,
9599,
1403,
804,
31908,
624,
272,
291,
14,
6520,
14,
9140,
275,
25607,
18,
14,
28347,
63,
2856,
63,
4030,
272,
291,
14,
6520,
14,
1985,
275,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
6520,
2,
272,
291,
14,
6520,
14,
1310,
63,
1985,
275,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
1310,
2,
272,
870,
1332,
513,
8,
277,
14,
6520,
855,
533,
4343,
67,
63,
2987,
14,
1744,
16890,
272,
892,
63,
6520,
275,
6128,
14,
6520,
63,
466,
363,
504,
63,
875,
8,
277,
14,
6520,
14,
475,
63,
875,
1012,
272,
702,
892,
63,
6520,
14,
9140,
508,
25607,
18,
14,
28347,
63,
2856,
63,
4030,
272,
702,
892,
63,
6520,
14,
1985,
508,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
6520,
2,
272,
702,
892,
63,
6520,
14,
1310,
63,
1985,
508,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
1310,
2,
819,
347,
511,
10369,
16550,
8,
277,
304,
272,
408,
774,
367,
6037,
63,
466,
63,
504,
63,
875,
342,
1808,
511,
666,
1041,
272,
892,
63,
6520,
275,
6128,
14,
6520,
63,
466,
363,
504,
63,
875,
8,
1064,
63,
576,
14,
2864,
63,
21054,
9,
272,
702,
892,
63,
6520,
14,
9140,
508,
25607,
18,
14,
28347,
63,
2856,
63,
4030,
272,
702,
892,
63,
6520,
14,
1985,
508,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
6520,
2,
272,
702,
892,
63,
6520,
14,
1310,
63,
1985,
508,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
1310,
2,
16872,
199,
533,
1379,
19067,
11442,
804,
26,
819,
347,
3272,
63,
533,
8,
277,
304,
272,
291,
14,
73,
63,
69,
275,
6128,
14,
19067,
11442,
804,
12798,
819,
347,
511,
3946,
1384,
8,
277,
304,
272,
408,
774,
367,
26437,
11442,
804,
31908,
624,
272,
291,
14,
73,
63,
69,
14,
9140,
275,
25607,
18,
14,
28347,
63,
2856,
63,
4030,
272,
291,
14,
73,
63,
69,
14,
1985,
275,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
6520,
2,
272,
291,
14,
73,
63,
69,
14,
1310,
63,
1985,
275,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
1310,
2,
272,
291,
14,
73,
63,
69,
14,
1080,
275,
298,
17,
2,
272,
291,
14,
73,
63,
69,
14,
374,
63,
885,
275,
298,
3910,
2,
272,
892,
63,
73,
63,
69,
275,
6128,
14,
16821,
63,
6520,
63,
466,
363,
504,
63,
875,
8,
277,
14,
73,
63,
69,
14,
475,
63,
875,
1012,
272,
702,
892,
63,
73,
63,
69,
14,
9140,
508,
25607,
18,
14,
28347,
63,
2856,
63,
4030,
272,
702,
892,
63,
73,
63,
69,
14,
1985,
508,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
6520,
2,
272,
702,
892,
63,
73,
63,
69,
14,
1310,
63,
1985,
508,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
1310,
2,
272,
702,
892,
63,
73,
63,
69,
14,
1080,
508,
298,
17,
2,
272,
702,
892,
63,
73,
63,
69,
14,
374,
63,
885,
508,
298,
3910,
2,
819,
347,
511,
10369,
16550,
8,
277,
304,
272,
408,
774,
367,
15235,
63,
6520,
63,
466,
63,
504,
63,
875,
342,
1808,
511,
666,
1041,
272,
892,
63,
73,
63,
69,
275,
6128,
14,
16821,
63,
6520,
63,
466,
363,
504,
63,
875,
8,
1064,
63,
576,
14,
2864,
63,
10215,
1149,
63,
21054,
9,
272,
702,
892,
63,
73,
63,
69,
14,
9140,
508,
25607,
18,
14,
28347,
63,
2856,
63,
4030,
272,
702,
892,
63,
73,
63,
69,
14,
1985,
508,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
6520,
2,
272,
702,
892,
63,
73,
63,
69,
14,
1310,
63,
1985,
508,
298,
1014,
921,
1544,
14,
2694,
14,
957,
15,
1310,
2,
272,
702,
892,
63,
73,
63,
69,
14,
1080,
508,
298,
17,
2,
272,
702,
892,
63,
73,
63,
69,
14,
374,
63,
885,
508,
298,
3910,
2,
421,
199,
533,
1379,
10597,
26,
819,
347,
3272,
63,
533,
8,
277,
304,
272,
291,
14,
5359,
275,
6128,
14,
10597,
342,
819,
347,
511,
3946,
1384,
8,
277,
304,
272,
408,
774,
367,
11524,
1356,
31908,
624,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mrkm4ntr/incubator-airflow
|
tests/executors/test_debug_executor.py
|
11
|
3877
|
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from unittest import mock
from unittest.mock import MagicMock
from airflow.executors.debug_executor import DebugExecutor
from airflow.utils.state import State
class TestDebugExecutor:
@mock.patch("airflow.executors.debug_executor.DebugExecutor._run_task")
def test_sync(self, run_task_mock):
run_task_mock.return_value = True
executor = DebugExecutor()
ti1 = MagicMock(key="t1")
ti2 = MagicMock(key="t2")
executor.tasks_to_run = [ti1, ti2]
executor.sync()
assert not executor.tasks_to_run
run_task_mock.assert_has_calls([mock.call(ti1), mock.call(ti2)])
@mock.patch("airflow.executors.debug_executor.TaskInstance")
def test_run_task(self, task_instance_mock):
ti_key = "key"
job_id = " job_id"
task_instance_mock.key = ti_key
task_instance_mock.job_id = job_id
executor = DebugExecutor()
executor.running = {ti_key}
succeeded = executor._run_task(task_instance_mock)
assert succeeded
task_instance_mock._run_raw_task.assert_called_once_with(job_id=job_id)
def test_queue_task_instance(self):
key = "ti_key"
ti = MagicMock(key=key)
executor = DebugExecutor()
executor.queue_task_instance(task_instance=ti, mark_success=True, pool="pool")
assert key in executor.queued_tasks
assert key in executor.tasks_params
assert executor.tasks_params[key] == {
"mark_success": True,
"pool": "pool",
}
def test_trigger_tasks(self):
execute_async_mock = MagicMock()
executor = DebugExecutor()
executor.execute_async = execute_async_mock
executor.queued_tasks = {
"t1": (None, 1, None, MagicMock(key="t1")),
"t2": (None, 2, None, MagicMock(key="t2")),
}
executor.trigger_tasks(open_slots=4)
assert not executor.queued_tasks
assert len(executor.running) == 2
assert len(executor.tasks_to_run) == 2
assert not execute_async_mock.called
def test_end(self):
ti = MagicMock(key="ti_key")
executor = DebugExecutor()
executor.tasks_to_run = [ti]
executor.running = {ti.key}
executor.end()
ti.set_state.assert_called_once_with(State.UPSTREAM_FAILED)
assert not executor.running
@mock.patch("airflow.executors.debug_executor.DebugExecutor.change_state")
def test_fail_fast(self, change_state_mock):
with mock.patch.dict("os.environ", {"AIRFLOW__DEBUG__FAIL_FAST": "True"}):
executor = DebugExecutor()
ti1 = MagicMock(key="t1")
ti2 = MagicMock(key="t2")
ti1._run_raw_task.side_effect = Exception
executor.tasks_to_run = [ti1, ti2]
executor.sync()
assert executor.fail_fast
assert not executor.tasks_to_run
change_state_mock.assert_has_calls(
[
mock.call(ti1.key, State.FAILED),
mock.call(ti2.key, State.UPSTREAM_FAILED),
]
)
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
504,
2882,
492,
1683,
199,
504,
2882,
14,
1805,
492,
10079,
199,
199,
504,
16321,
14,
1628,
6622,
14,
1757,
63,
13471,
492,
14245,
16752,
199,
504,
16321,
14,
1208,
14,
929,
492,
8511,
421,
199,
533,
1379,
7084,
16752,
26,
272,
768,
1805,
14,
2068,
480,
15815,
14,
1628,
6622,
14,
1757,
63,
13471,
14,
7084,
16752,
423,
1065,
63,
1765,
531,
272,
347,
511,
63,
5186,
8,
277,
12,
1255,
63,
1765,
63,
1805,
304,
267,
1255,
63,
1765,
63,
1805,
14,
1107,
63,
585,
275,
715,
398,
13270,
275,
14245,
16752,
342,
398,
3367,
17,
275,
10079,
8,
498,
628,
84,
17,
531,
267,
3367,
18,
275,
10079,
8,
498,
628,
84,
18,
531,
267,
13270,
14,
5054,
63,
475,
63,
1065,
275,
359,
280,
17,
12,
3367,
18,
61,
398,
13270,
14,
5186,
342,
267,
702,
440,
13270,
14,
5054,
63,
475,
63,
1065,
267,
1255,
63,
1765,
63,
1805,
14,
479,
63,
1989,
63,
5352,
779,
1805,
14,
1250,
8,
280,
17,
395,
1683,
14,
1250,
8,
280,
18,
3948,
339,
768,
1805,
14,
2068,
480,
15815,
14,
1628,
6622,
14,
1757,
63,
13471,
14,
4476,
3244,
531,
272,
347,
511,
63,
1065,
63,
1765,
8,
277,
12,
2120,
63,
842,
63,
1805,
304,
267,
3367,
63,
498,
275,
298,
498,
2,
267,
3906,
63,
344,
275,
298,
3906,
63,
344,
2,
267,
2120,
63,
842,
63,
1805,
14,
498,
275,
3367,
63,
498,
267,
2120,
63,
842,
63,
1805,
14,
2423,
63,
344,
275,
3906,
63,
344,
398,
13270,
275,
14245,
16752,
342,
267,
13270,
14,
5720,
275,
469,
280,
63,
498,
93,
267,
19268,
275,
13270,
423,
1065,
63,
1765,
8,
1765,
63,
842,
63,
1805,
9,
398,
702,
19268,
267,
2120,
63,
842,
63,
1805,
423,
1065,
63,
1773,
63,
1765,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
2423,
63,
344,
29,
2423,
63,
344,
9,
339,
347,
511,
63,
1825,
63,
1765,
63,
842,
8,
277,
304,
267,
790,
275,
298,
280,
63,
498,
2,
267,
3367,
275,
10079,
8,
498,
29,
498,
9,
398,
13270,
275,
14245,
16752,
342,
267,
13270,
14,
1825,
63,
1765,
63,
842,
8,
1765,
63,
842,
29,
280,
12,
2216,
63,
3742,
29,
549,
12,
4203,
628,
2293,
531,
398,
702,
790,
315,
13270,
14,
14268,
63,
5054,
267,
702,
790,
315,
13270,
14,
5054,
63,
1162,
267,
702,
13270,
14,
5054,
63,
1162,
59,
498,
61,
508,
469,
288,
298,
1657,
63,
3742,
582,
715,
12,
288,
298,
2293,
582,
298,
2293,
401,
267,
789,
339,
347,
511,
63,
7631,
63,
5054,
8,
277,
304,
267,
5341,
63,
4146,
63,
1805,
275,
10079,
342,
267,
13270,
275,
14245,
16752,
342,
267,
13270,
14,
2526,
63,
4146,
275,
5341,
63,
4146,
63,
1805,
398,
13270,
14,
14268,
63,
5054,
275,
469,
288,
298,
84,
17,
582,
334,
403,
12,
413,
12,
488,
12,
10079,
8,
498,
628,
84,
17,
8150,
288,
298,
84,
18,
582,
334,
403,
12,
499,
12,
488,
12,
10079,
8,
498,
628,
84,
18,
8150,
267,
789,
398,
13270,
14,
7631,
63,
5054,
8,
1490,
63,
7257,
29,
20,
9,
267,
702,
440,
13270,
14,
14268,
63,
5054,
267,
702,
822,
8,
13471,
14,
5720,
9,
508,
499,
267,
702,
822,
8,
13471,
14,
5054,
63,
475,
63,
1065,
9,
508,
499,
267,
702,
440,
5341,
63,
4146,
63,
1805,
14,
3527,
339,
347,
511,
63,
500,
8,
277,
304,
267,
3367,
275,
10079,
8,
498,
628,
280,
63,
498,
531,
398,
13270,
275,
14245,
16752,
342,
267,
13270,
14,
5054,
63,
475,
63,
1065,
275,
359,
280,
61,
267,
13270,
14,
5720,
275,
469,
280,
14,
498,
93,
267,
13270,
14,
500,
342,
398,
3367,
14,
409,
63,
929,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
2223,
14,
2160,
9484,
63,
12299,
9,
267,
702,
440,
13270,
14,
5720,
339,
768,
1805,
14,
2068,
480,
15815,
14,
1628,
6622,
14,
1757,
63,
13471,
14,
7084,
16752,
14,
1461,
63,
929,
531,
272,
347,
511,
63,
1633,
63,
7015,
8,
277,
12,
1570,
63,
929,
63,
1805,
304,
267,
543,
1683,
14,
2068,
14,
807,
480,
736,
14,
2314,
401,
2420,
33,
3927,
17114,
363,
5287,
363,
8784,
63,
24661,
582,
298,
549,
3570,
304,
288,
13270,
275,
14245,
16752,
342,
398,
3367,
17,
275,
10079,
8,
498,
628,
84,
17,
531,
267,
3367,
18,
275,
10079,
8,
498,
628,
84,
18,
531,
398,
3367,
17,
423,
1065,
63,
1773,
63,
1765,
14,
2441,
63,
5881,
275,
2186,
398,
13270,
14,
5054,
63,
475,
63,
1065,
275,
359,
280,
17,
12,
3367,
18,
61,
398,
13270,
14,
5186,
342,
398,
702,
13270,
14,
1633,
63,
7015,
267,
702,
440,
13270,
14,
5054,
63,
475,
63,
1065,
267,
1570,
63,
929,
63,
1805,
14,
479,
63,
1989,
63,
5352,
8,
288,
359,
355,
1683,
14,
1250,
8,
280,
17,
14,
498,
12,
8511,
14,
12299,
395,
355,
1683,
14,
1250,
8,
280,
18,
14,
498,
12,
8511,
14,
2160,
9484,
63,
12299,
395,
288,
1622,
267,
776,
199,
32768,
32768
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
504,
2882,
492,
1683,
199,
504,
2882,
14,
1805,
492,
10079,
199,
199,
504,
16321,
14,
1628,
6622,
14,
1757,
63,
13471,
492,
14245,
16752,
199,
504,
16321,
14,
1208,
14,
929,
492,
8511,
421,
199,
533,
1379,
7084,
16752,
26,
272,
768,
1805,
14,
2068,
480,
15815,
14,
1628,
6622,
14,
1757,
63,
13471,
14,
7084,
16752,
423,
1065,
63,
1765,
531,
272,
347,
511,
63,
5186,
8,
277,
12,
1255,
63,
1765,
63,
1805,
304,
267,
1255,
63,
1765,
63,
1805,
14,
1107,
63,
585,
275,
715,
398,
13270,
275,
14245,
16752,
342,
398,
3367,
17,
275,
10079,
8,
498,
628,
84,
17,
531,
267,
3367,
18,
275,
10079,
8,
498,
628,
84,
18,
531,
267,
13270,
14,
5054,
63,
475,
63,
1065,
275,
359,
280,
17,
12,
3367,
18,
61,
398,
13270,
14,
5186,
342,
267,
702,
440,
13270,
14,
5054,
63,
475,
63,
1065,
267,
1255,
63,
1765,
63,
1805,
14,
479,
63,
1989,
63,
5352,
779,
1805,
14,
1250,
8,
280,
17,
395,
1683,
14,
1250,
8,
280,
18,
3948,
339,
768,
1805,
14,
2068,
480,
15815,
14,
1628,
6622,
14,
1757,
63,
13471,
14,
4476,
3244,
531,
272,
347,
511,
63,
1065,
63,
1765,
8,
277,
12,
2120,
63,
842,
63,
1805,
304,
267,
3367,
63,
498,
275,
298,
498,
2,
267,
3906,
63,
344,
275,
298,
3906,
63,
344,
2,
267,
2120,
63,
842,
63,
1805,
14,
498,
275,
3367,
63,
498,
267,
2120,
63,
842,
63,
1805,
14,
2423,
63,
344,
275,
3906,
63,
344,
398,
13270,
275,
14245,
16752,
342,
267,
13270,
14,
5720,
275,
469,
280,
63,
498,
93,
267,
19268,
275,
13270,
423,
1065,
63,
1765,
8,
1765,
63,
842,
63,
1805,
9,
398,
702,
19268,
267,
2120,
63,
842,
63,
1805,
423,
1065,
63,
1773,
63,
1765,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
2423,
63,
344,
29,
2423,
63,
344,
9,
339,
347,
511,
63,
1825,
63,
1765,
63,
842,
8,
277,
304,
267,
790,
275,
298,
280,
63,
498,
2,
267,
3367,
275,
10079,
8,
498,
29,
498,
9,
398,
13270,
275,
14245,
16752,
342,
267,
13270,
14,
1825,
63,
1765,
63,
842,
8,
1765,
63,
842,
29,
280,
12,
2216,
63,
3742,
29,
549,
12,
4203,
628,
2293,
531,
398,
702,
790,
315,
13270,
14,
14268,
63,
5054,
267,
702,
790,
315,
13270,
14,
5054,
63,
1162,
267,
702,
13270,
14,
5054,
63,
1162,
59,
498,
61,
508,
469,
288,
298,
1657,
63,
3742,
582,
715,
12,
288,
298,
2293,
582,
298,
2293,
401,
267,
789,
339,
347,
511,
63,
7631,
63,
5054,
8,
277,
304,
267,
5341,
63,
4146,
63,
1805,
275,
10079,
342,
267,
13270,
275,
14245,
16752,
342,
267,
13270,
14,
2526,
63,
4146,
275,
5341,
63,
4146,
63,
1805,
398,
13270,
14,
14268,
63,
5054,
275,
469,
288,
298,
84,
17,
582,
334,
403,
12,
413,
12,
488,
12,
10079,
8,
498,
628,
84,
17,
8150,
288,
298,
84,
18,
582,
334,
403,
12,
499,
12,
488,
12,
10079,
8,
498,
628,
84,
18,
8150,
267,
789,
398,
13270,
14,
7631,
63,
5054,
8,
1490,
63,
7257,
29,
20,
9,
267,
702,
440,
13270,
14,
14268,
63,
5054,
267,
702,
822,
8,
13471,
14,
5720,
9,
508,
499,
267,
702,
822,
8,
13471,
14,
5054,
63,
475,
63,
1065,
9,
508,
499,
267,
702,
440,
5341,
63,
4146,
63,
1805,
14,
3527,
339,
347,
511,
63,
500,
8,
277,
304,
267,
3367,
275,
10079,
8,
498,
628,
280,
63,
498,
531,
398,
13270,
275,
14245,
16752,
342,
267,
13270,
14,
5054,
63,
475,
63,
1065,
275,
359,
280,
61,
267,
13270,
14,
5720,
275,
469,
280,
14,
498,
93,
267,
13270,
14,
500,
342,
398,
3367,
14,
409,
63,
929,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
2223,
14,
2160,
9484,
63,
12299,
9,
267,
702,
440,
13270,
14,
5720,
339,
768,
1805,
14,
2068,
480,
15815,
14,
1628,
6622,
14,
1757,
63,
13471,
14,
7084,
16752,
14,
1461,
63,
929,
531,
272,
347,
511,
63,
1633,
63,
7015,
8,
277,
12,
1570,
63,
929,
63,
1805,
304,
267,
543,
1683,
14,
2068,
14,
807,
480,
736,
14,
2314,
401,
2420,
33,
3927,
17114,
363,
5287,
363,
8784,
63,
24661,
582,
298,
549,
3570,
304,
288,
13270,
275,
14245,
16752,
342,
398,
3367,
17,
275,
10079,
8,
498,
628,
84,
17,
531,
267,
3367,
18,
275,
10079,
8,
498,
628,
84,
18,
531,
398,
3367,
17,
423,
1065,
63,
1773,
63,
1765,
14,
2441,
63,
5881,
275,
2186,
398,
13270,
14,
5054,
63,
475,
63,
1065,
275,
359,
280,
17,
12,
3367,
18,
61,
398,
13270,
14,
5186,
342,
398,
702,
13270,
14,
1633,
63,
7015,
267,
702,
440,
13270,
14,
5054,
63,
475,
63,
1065,
267,
1570,
63,
929,
63,
1805,
14,
479,
63,
1989,
63,
5352,
8,
288,
359,
355,
1683,
14,
1250,
8,
280,
17,
14,
498,
12,
8511,
14,
12299,
395,
355,
1683,
14,
1250,
8,
280,
18,
14,
498,
12,
8511,
14,
2160,
9484,
63,
12299,
395,
288,
1622,
267,
776,
199,
32768,
32768,
0
] |
[
1,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yongshengwang/hue
|
desktop/core/ext-py/kazoo-2.0/kazoo/recipe/party.py
|
54
|
3886
|
"""Party
:Maintainer: Ben Bangert <ben@groovie.org>
:Status: Production
A Zookeeper pool of party members. The :class:`Party` object can be
used for determining members of a party.
"""
import uuid
from kazoo.exceptions import NodeExistsError, NoNodeError
class BaseParty(object):
"""Base implementation of a party."""
def __init__(self, client, path, identifier=None):
"""
:param client: A :class:`~kazoo.client.KazooClient` instance.
:param path: The party path to use.
:param identifier: An identifier to use for this member of the
party when participating.
"""
self.client = client
self.path = path
self.data = str(identifier or "").encode('utf-8')
self.ensured_path = False
self.participating = False
def _ensure_parent(self):
if not self.ensured_path:
# make sure our parent node exists
self.client.ensure_path(self.path)
self.ensured_path = True
def join(self):
"""Join the party"""
return self.client.retry(self._inner_join)
def _inner_join(self):
self._ensure_parent()
try:
self.client.create(self.create_path, self.data, ephemeral=True)
self.participating = True
except NodeExistsError:
# node was already created, perhaps we are recovering from a
# suspended connection
self.participating = True
def leave(self):
"""Leave the party"""
self.participating = False
return self.client.retry(self._inner_leave)
def _inner_leave(self):
try:
self.client.delete(self.create_path)
except NoNodeError:
return False
return True
def __len__(self):
"""Return a count of participating clients"""
self._ensure_parent()
return len(self._get_children())
def _get_children(self):
return self.client.retry(self.client.get_children, self.path)
class Party(BaseParty):
"""Simple pool of participating processes"""
_NODE_NAME = "__party__"
def __init__(self, client, path, identifier=None):
BaseParty.__init__(self, client, path, identifier=identifier)
self.node = uuid.uuid4().hex + self._NODE_NAME
self.create_path = self.path + "/" + self.node
def __iter__(self):
"""Get a list of participating clients' data values"""
self._ensure_parent()
children = self._get_children()
for child in children:
try:
d, _ = self.client.retry(self.client.get, self.path +
"/" + child)
yield d.decode('utf-8')
except NoNodeError: # pragma: nocover
pass
def _get_children(self):
children = BaseParty._get_children(self)
return [c for c in children if self._NODE_NAME in c]
class ShallowParty(BaseParty):
"""Simple shallow pool of participating processes
This differs from the :class:`Party` as the identifier is used in
the name of the party node itself, rather than the data. This
places some restrictions on the length as it must be a valid
Zookeeper node (an alphanumeric string), but reduces the overhead
of getting a list of participants to a single Zookeeper call.
"""
def __init__(self, client, path, identifier=None):
BaseParty.__init__(self, client, path, identifier=identifier)
self.node = '-'.join([uuid.uuid4().hex, self.data.decode('utf-8')])
self.create_path = self.path + "/" + self.node
def __iter__(self):
"""Get a list of participating clients' identifiers"""
self._ensure_parent()
children = self._get_children()
for child in children:
yield child[child.find('-') + 1:]
|
apache-2.0
|
[
624,
25233,
199,
199,
26,
11903,
8368,
281,
26,
26844,
699,
12974,
84,
665,
18486,
32,
23260,
79,
6620,
14,
1308,
30,
199,
26,
3694,
26,
24114,
199,
199,
33,
3107,
23479,
4203,
402,
17135,
7556,
14,
710,
520,
533,
1705,
25233,
64,
909,
883,
506,
199,
2972,
367,
26638,
7556,
402,
282,
17135,
14,
199,
199,
624,
199,
646,
5377,
199,
199,
504,
1022,
4651,
1534,
14,
3924,
492,
5013,
23839,
12,
3091,
1716,
547,
421,
199,
533,
3523,
25233,
8,
785,
304,
272,
408,
1563,
4514,
402,
282,
17135,
1041,
272,
347,
636,
826,
721,
277,
12,
1890,
12,
931,
12,
5148,
29,
403,
304,
267,
408,
267,
520,
635,
1890,
26,
437,
520,
533,
6054,
75,
4651,
1534,
14,
1258,
14,
43,
4651,
1534,
3041,
64,
1256,
14,
267,
520,
635,
931,
26,
710,
17135,
931,
370,
675,
14,
267,
520,
635,
5148,
26,
1626,
5148,
370,
675,
367,
642,
3653,
402,
314,
2574,
17135,
1380,
623,
10479,
1958,
14,
398,
408,
267,
291,
14,
1258,
275,
1890,
267,
291,
14,
515,
275,
931,
267,
291,
14,
576,
275,
620,
8,
5364,
503,
25354,
2143,
360,
1624,
13,
24,
358,
267,
291,
14,
8764,
3297,
63,
515,
275,
756,
267,
291,
14,
462,
10479,
1958,
275,
756,
339,
347,
485,
7505,
63,
1708,
8,
277,
304,
267,
340,
440,
291,
14,
8764,
3297,
63,
515,
26,
288,
327,
1852,
3238,
4154,
1676,
1031,
3495,
288,
291,
14,
1258,
14,
7505,
63,
515,
8,
277,
14,
515,
9,
288,
291,
14,
8764,
3297,
63,
515,
275,
715,
339,
347,
4263,
8,
277,
304,
267,
408,
13005,
314,
17135,
624,
267,
372,
291,
14,
1258,
14,
7154,
8,
277,
423,
5216,
63,
904,
9,
339,
347,
485,
5216,
63,
904,
8,
277,
304,
267,
291,
423,
7505,
63,
1708,
342,
267,
862,
26,
288,
291,
14,
1258,
14,
981,
8,
277,
14,
981,
63,
515,
12,
291,
14,
576,
12,
26288,
29,
549,
9,
288,
291,
14,
462,
10479,
1958,
275,
715,
267,
871,
5013,
23839,
26,
288,
327,
1031,
1990,
2575,
2737,
12,
25358,
781,
787,
22803,
316,
687,
282,
288,
327,
308,
18559,
1950,
288,
291,
14,
462,
10479,
1958,
275,
715,
339,
347,
10137,
8,
277,
304,
267,
408,
23679,
314,
17135,
624,
267,
291,
14,
462,
10479,
1958,
275,
756,
267,
372,
291,
14,
1258,
14,
7154,
8,
277,
423,
5216,
63,
12422,
9,
339,
347,
485,
5216,
63,
12422,
8,
277,
304,
267,
862,
26,
288,
291,
14,
1258,
14,
1807,
8,
277,
14,
981,
63,
515,
9,
267,
871,
3091,
1716,
547,
26,
288,
372,
756,
267,
372,
715,
339,
347,
636,
552,
721,
277,
304,
267,
408,
1767,
282,
2338,
402,
623,
10479,
1958,
13431,
624,
267,
291,
423,
7505,
63,
1708,
342,
267,
372,
822,
8,
277,
423,
362,
63,
3223,
1012,
339,
347,
485,
362,
63,
3223,
8,
277,
304,
267,
372,
291,
14,
1258,
14,
7154,
8,
277,
14,
1258,
14,
362,
63,
3223,
12,
291,
14,
515,
9,
421,
199,
533,
2235,
369,
8,
1563,
25233,
304,
272,
408,
3184,
4203,
402,
623,
10479,
1958,
10358,
624,
272,
485,
8063,
63,
2339,
275,
4396,
7522,
16526,
339,
347,
636,
826,
721,
277,
12,
1890,
12,
931,
12,
5148,
29,
403,
304,
267,
3523,
25233,
855,
826,
721,
277,
12,
1890,
12,
931,
12,
5148,
29,
5364,
9,
267,
291,
14,
932,
275,
5377,
14,
2580,
20,
1252,
4097,
435,
291,
423,
8063,
63,
2339,
267,
291,
14,
981,
63,
515,
275,
291,
14,
515,
435,
10609,
435,
291,
14,
932,
339,
347,
636,
1661,
721,
277,
304,
267,
408,
1002,
282,
769,
402,
623,
10479,
1958,
13431,
7,
666,
1338,
624,
267,
291,
423,
7505,
63,
1708,
342,
267,
4978,
275,
291,
423,
362,
63,
3223,
342,
267,
367,
1982,
315,
4978,
26,
288,
862,
26,
355,
366,
12,
485,
275,
291,
14,
1258,
14,
7154,
8,
277,
14,
1258,
14,
362,
12,
291,
14,
515,
435,
1460,
10609,
435,
1982,
9,
355,
1995,
366,
14,
2708,
360,
1624,
13,
24,
358,
288,
871,
3091,
1716,
547,
26,
221,
327,
11942,
26,
949,
5899,
355,
986,
339,
347,
485,
362,
63,
3223,
8,
277,
304,
267,
4978,
275,
3523,
25233,
423,
362,
63,
3223,
8,
277,
9,
267,
372,
359,
67,
367,
286,
315,
4978,
340,
291,
423,
8063,
63,
2339,
315,
286,
61,
421,
199,
533,
5244,
3306,
25233,
8,
1563,
25233,
304,
272,
408,
3184,
23834,
4203,
402,
623,
10479,
1958,
10358,
339,
961,
22754,
687,
314,
520,
533,
1705,
25233,
64,
465,
314,
5148,
365,
1202,
315,
272,
314,
536,
402,
314,
17135,
1031,
6337,
12,
7830,
2419,
314,
666,
14,
961,
272,
9825,
2005,
24488,
641,
314,
2582,
465,
652,
1471,
506,
282,
1686,
272,
3107,
23479,
1031,
334,
290,
27964,
1059,
395,
1325,
295,
10569,
314,
24075,
272,
402,
10232,
282,
769,
402,
623,
20989,
370,
282,
2849,
3107,
23479,
1240,
14,
339,
408,
272,
347,
636,
826,
721,
277,
12,
1890,
12,
931,
12,
5148,
29,
403,
304,
267,
3523,
25233,
855,
826,
721,
277,
12,
1890,
12,
931,
12,
5148,
29,
5364,
9,
267,
291,
14,
932,
275,
2475,
1370,
904,
779,
2580,
14,
2580,
20,
1252,
4097,
12,
291,
14,
576,
14,
2708,
360,
1624,
13,
24,
2023,
267,
291,
14,
981,
63,
515,
275,
291,
14,
515,
435,
10609,
435,
291,
14,
932,
339,
347,
636,
1661,
721,
277,
304,
267,
408,
1002,
282,
769,
402,
623,
10479,
1958,
13431,
7,
14154,
624,
267,
291,
423,
7505,
63,
1708,
342,
267,
4978,
275,
291,
423,
362,
63,
3223,
342,
267,
367,
1982,
315,
4978,
26,
288,
1995,
1982,
59,
1739,
14,
1623,
21950,
435,
413,
2938,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
25233,
199,
199,
26,
11903,
8368,
281,
26,
26844,
699,
12974,
84,
665,
18486,
32,
23260,
79,
6620,
14,
1308,
30,
199,
26,
3694,
26,
24114,
199,
199,
33,
3107,
23479,
4203,
402,
17135,
7556,
14,
710,
520,
533,
1705,
25233,
64,
909,
883,
506,
199,
2972,
367,
26638,
7556,
402,
282,
17135,
14,
199,
199,
624,
199,
646,
5377,
199,
199,
504,
1022,
4651,
1534,
14,
3924,
492,
5013,
23839,
12,
3091,
1716,
547,
421,
199,
533,
3523,
25233,
8,
785,
304,
272,
408,
1563,
4514,
402,
282,
17135,
1041,
272,
347,
636,
826,
721,
277,
12,
1890,
12,
931,
12,
5148,
29,
403,
304,
267,
408,
267,
520,
635,
1890,
26,
437,
520,
533,
6054,
75,
4651,
1534,
14,
1258,
14,
43,
4651,
1534,
3041,
64,
1256,
14,
267,
520,
635,
931,
26,
710,
17135,
931,
370,
675,
14,
267,
520,
635,
5148,
26,
1626,
5148,
370,
675,
367,
642,
3653,
402,
314,
2574,
17135,
1380,
623,
10479,
1958,
14,
398,
408,
267,
291,
14,
1258,
275,
1890,
267,
291,
14,
515,
275,
931,
267,
291,
14,
576,
275,
620,
8,
5364,
503,
25354,
2143,
360,
1624,
13,
24,
358,
267,
291,
14,
8764,
3297,
63,
515,
275,
756,
267,
291,
14,
462,
10479,
1958,
275,
756,
339,
347,
485,
7505,
63,
1708,
8,
277,
304,
267,
340,
440,
291,
14,
8764,
3297,
63,
515,
26,
288,
327,
1852,
3238,
4154,
1676,
1031,
3495,
288,
291,
14,
1258,
14,
7505,
63,
515,
8,
277,
14,
515,
9,
288,
291,
14,
8764,
3297,
63,
515,
275,
715,
339,
347,
4263,
8,
277,
304,
267,
408,
13005,
314,
17135,
624,
267,
372,
291,
14,
1258,
14,
7154,
8,
277,
423,
5216,
63,
904,
9,
339,
347,
485,
5216,
63,
904,
8,
277,
304,
267,
291,
423,
7505,
63,
1708,
342,
267,
862,
26,
288,
291,
14,
1258,
14,
981,
8,
277,
14,
981,
63,
515,
12,
291,
14,
576,
12,
26288,
29,
549,
9,
288,
291,
14,
462,
10479,
1958,
275,
715,
267,
871,
5013,
23839,
26,
288,
327,
1031,
1990,
2575,
2737,
12,
25358,
781,
787,
22803,
316,
687,
282,
288,
327,
308,
18559,
1950,
288,
291,
14,
462,
10479,
1958,
275,
715,
339,
347,
10137,
8,
277,
304,
267,
408,
23679,
314,
17135,
624,
267,
291,
14,
462,
10479,
1958,
275,
756,
267,
372,
291,
14,
1258,
14,
7154,
8,
277,
423,
5216,
63,
12422,
9,
339,
347,
485,
5216,
63,
12422,
8,
277,
304,
267,
862,
26,
288,
291,
14,
1258,
14,
1807,
8,
277,
14,
981,
63,
515,
9,
267,
871,
3091,
1716,
547,
26,
288,
372,
756,
267,
372,
715,
339,
347,
636,
552,
721,
277,
304,
267,
408,
1767,
282,
2338,
402,
623,
10479,
1958,
13431,
624,
267,
291,
423,
7505,
63,
1708,
342,
267,
372,
822,
8,
277,
423,
362,
63,
3223,
1012,
339,
347,
485,
362,
63,
3223,
8,
277,
304,
267,
372,
291,
14,
1258,
14,
7154,
8,
277,
14,
1258,
14,
362,
63,
3223,
12,
291,
14,
515,
9,
421,
199,
533,
2235,
369,
8,
1563,
25233,
304,
272,
408,
3184,
4203,
402,
623,
10479,
1958,
10358,
624,
272,
485,
8063,
63,
2339,
275,
4396,
7522,
16526,
339,
347,
636,
826,
721,
277,
12,
1890,
12,
931,
12,
5148,
29,
403,
304,
267,
3523,
25233,
855,
826,
721,
277,
12,
1890,
12,
931,
12,
5148,
29,
5364,
9,
267,
291,
14,
932,
275,
5377,
14,
2580,
20,
1252,
4097,
435,
291,
423,
8063,
63,
2339,
267,
291,
14,
981,
63,
515,
275,
291,
14,
515,
435,
10609,
435,
291,
14,
932,
339,
347,
636,
1661,
721,
277,
304,
267,
408,
1002,
282,
769,
402,
623,
10479,
1958,
13431,
7,
666,
1338,
624,
267,
291,
423,
7505,
63,
1708,
342,
267,
4978,
275,
291,
423,
362,
63,
3223,
342,
267,
367,
1982,
315,
4978,
26,
288,
862,
26,
355,
366,
12,
485,
275,
291,
14,
1258,
14,
7154,
8,
277,
14,
1258,
14,
362,
12,
291,
14,
515,
435,
1460,
10609,
435,
1982,
9,
355,
1995,
366,
14,
2708,
360,
1624,
13,
24,
358,
288,
871,
3091,
1716,
547,
26,
221,
327,
11942,
26,
949,
5899,
355,
986,
339,
347,
485,
362,
63,
3223,
8,
277,
304,
267,
4978,
275,
3523,
25233,
423,
362,
63,
3223,
8,
277,
9,
267,
372,
359,
67,
367,
286,
315,
4978,
340,
291,
423,
8063,
63,
2339,
315,
286,
61,
421,
199,
533,
5244,
3306,
25233,
8,
1563,
25233,
304,
272,
408,
3184,
23834,
4203,
402,
623,
10479,
1958,
10358,
339,
961,
22754,
687,
314,
520,
533,
1705,
25233,
64,
465,
314,
5148,
365,
1202,
315,
272,
314,
536,
402,
314,
17135,
1031,
6337,
12,
7830,
2419,
314,
666,
14,
961,
272,
9825,
2005,
24488,
641,
314,
2582,
465,
652,
1471,
506,
282,
1686,
272,
3107,
23479,
1031,
334,
290,
27964,
1059,
395,
1325,
295,
10569,
314,
24075,
272,
402,
10232,
282,
769,
402,
623,
20989,
370,
282,
2849,
3107,
23479,
1240,
14,
339,
408,
272,
347,
636,
826,
721,
277,
12,
1890,
12,
931,
12,
5148,
29,
403,
304,
267,
3523,
25233,
855,
826,
721,
277,
12,
1890,
12,
931,
12,
5148,
29,
5364,
9,
267,
291,
14,
932,
275,
2475,
1370,
904,
779,
2580,
14,
2580,
20,
1252,
4097,
12,
291,
14,
576,
14,
2708,
360,
1624,
13,
24,
2023,
267,
291,
14,
981,
63,
515,
275,
291,
14,
515,
435,
10609,
435,
291,
14,
932,
339,
347,
636,
1661,
721,
277,
304,
267,
408,
1002,
282,
769,
402,
623,
10479,
1958,
13431,
7,
14154,
624,
267,
291,
423,
7505,
63,
1708,
342,
267,
4978,
275,
291,
423,
362,
63,
3223,
342,
267,
367,
1982,
315,
4978,
26,
288,
1995,
1982,
59,
1739,
14,
1623,
21950,
435,
413,
2938,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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__ import division, print_function, absolute_import
import numpy as np
from numpy.testing import assert_allclose, assert_equal, assert_
import pytest
import scipy.linalg
import scipy.sparse.linalg
from scipy.sparse.linalg._onenormest import _onenormest_core, _algorithm_2_2
class MatrixProductOperator(scipy.sparse.linalg.LinearOperator):
"""
This is purely for onenormest testing.
"""
def __init__(self, A, B):
if A.ndim != 2 or B.ndim != 2:
raise ValueError('expected ndarrays representing matrices')
if A.shape[1] != B.shape[0]:
raise ValueError('incompatible shapes')
self.A = A
self.B = B
self.ndim = 2
self.shape = (A.shape[0], B.shape[1])
def _matvec(self, x):
return np.dot(self.A, np.dot(self.B, x))
def _rmatvec(self, x):
return np.dot(np.dot(x, self.A), self.B)
def _matmat(self, X):
return np.dot(self.A, np.dot(self.B, X))
@property
def T(self):
return MatrixProductOperator(self.B.T, self.A.T)
class TestOnenormest(object):
@pytest.mark.xslow
def test_onenormest_table_3_t_2(self):
# This will take multiple seconds if your computer is slow like mine.
# It is stochastic, so the tolerance could be too strict.
np.random.seed(1234)
t = 2
n = 100
itmax = 5
nsamples = 5000
observed = []
expected = []
nmult_list = []
nresample_list = []
for i in range(nsamples):
A = scipy.linalg.inv(np.random.randn(n, n))
est, v, w, nmults, nresamples = _onenormest_core(A, A.T, t, itmax)
observed.append(est)
expected.append(scipy.linalg.norm(A, 1))
nmult_list.append(nmults)
nresample_list.append(nresamples)
observed = np.array(observed, dtype=float)
expected = np.array(expected, dtype=float)
relative_errors = np.abs(observed - expected) / expected
# check the mean underestimation ratio
underestimation_ratio = observed / expected
assert_(0.99 < np.mean(underestimation_ratio) < 1.0)
# check the max and mean required column resamples
assert_equal(np.max(nresample_list), 2)
assert_(0.05 < np.mean(nresample_list) < 0.2)
# check the proportion of norms computed exactly correctly
nexact = np.count_nonzero(relative_errors < 1e-14)
proportion_exact = nexact / float(nsamples)
assert_(0.9 < proportion_exact < 0.95)
# check the average number of matrix*vector multiplications
assert_(3.5 < np.mean(nmult_list) < 4.5)
@pytest.mark.xslow
def test_onenormest_table_4_t_7(self):
# This will take multiple seconds if your computer is slow like mine.
# It is stochastic, so the tolerance could be too strict.
np.random.seed(1234)
t = 7
n = 100
itmax = 5
nsamples = 5000
observed = []
expected = []
nmult_list = []
nresample_list = []
for i in range(nsamples):
A = np.random.randint(-1, 2, size=(n, n))
est, v, w, nmults, nresamples = _onenormest_core(A, A.T, t, itmax)
observed.append(est)
expected.append(scipy.linalg.norm(A, 1))
nmult_list.append(nmults)
nresample_list.append(nresamples)
observed = np.array(observed, dtype=float)
expected = np.array(expected, dtype=float)
relative_errors = np.abs(observed - expected) / expected
# check the mean underestimation ratio
underestimation_ratio = observed / expected
assert_(0.90 < np.mean(underestimation_ratio) < 0.99)
# check the required column resamples
assert_equal(np.max(nresample_list), 0)
# check the proportion of norms computed exactly correctly
nexact = np.count_nonzero(relative_errors < 1e-14)
proportion_exact = nexact / float(nsamples)
assert_(0.15 < proportion_exact < 0.25)
# check the average number of matrix*vector multiplications
assert_(3.5 < np.mean(nmult_list) < 4.5)
def test_onenormest_table_5_t_1(self):
# "note that there is no randomness and hence only one estimate for t=1"
t = 1
n = 100
itmax = 5
alpha = 1 - 1e-6
A = -scipy.linalg.inv(np.identity(n) + alpha*np.eye(n, k=1))
first_col = np.array([1] + [0]*(n-1))
first_row = np.array([(-alpha)**i for i in range(n)])
B = -scipy.linalg.toeplitz(first_col, first_row)
assert_allclose(A, B)
est, v, w, nmults, nresamples = _onenormest_core(B, B.T, t, itmax)
exact_value = scipy.linalg.norm(B, 1)
underest_ratio = est / exact_value
assert_allclose(underest_ratio, 0.05, rtol=1e-4)
assert_equal(nmults, 11)
assert_equal(nresamples, 0)
# check the non-underscored version of onenormest
est_plain = scipy.sparse.linalg.onenormest(B, t=t, itmax=itmax)
assert_allclose(est, est_plain)
@pytest.mark.xslow
def test_onenormest_table_6_t_1(self):
#TODO this test seems to give estimates that match the table,
#TODO even though no attempt has been made to deal with
#TODO complex numbers in the one-norm estimation.
# This will take multiple seconds if your computer is slow like mine.
# It is stochastic, so the tolerance could be too strict.
np.random.seed(1234)
t = 1
n = 100
itmax = 5
nsamples = 5000
observed = []
expected = []
nmult_list = []
nresample_list = []
for i in range(nsamples):
A_inv = np.random.rand(n, n) + 1j * np.random.rand(n, n)
A = scipy.linalg.inv(A_inv)
est, v, w, nmults, nresamples = _onenormest_core(A, A.T, t, itmax)
observed.append(est)
expected.append(scipy.linalg.norm(A, 1))
nmult_list.append(nmults)
nresample_list.append(nresamples)
observed = np.array(observed, dtype=float)
expected = np.array(expected, dtype=float)
relative_errors = np.abs(observed - expected) / expected
# check the mean underestimation ratio
underestimation_ratio = observed / expected
underestimation_ratio_mean = np.mean(underestimation_ratio)
assert_(0.90 < underestimation_ratio_mean < 0.99)
# check the required column resamples
max_nresamples = np.max(nresample_list)
assert_equal(max_nresamples, 0)
# check the proportion of norms computed exactly correctly
nexact = np.count_nonzero(relative_errors < 1e-14)
proportion_exact = nexact / float(nsamples)
assert_(0.7 < proportion_exact < 0.8)
# check the average number of matrix*vector multiplications
mean_nmult = np.mean(nmult_list)
assert_(4 < mean_nmult < 5)
def _help_product_norm_slow(self, A, B):
# for profiling
C = np.dot(A, B)
return scipy.linalg.norm(C, 1)
def _help_product_norm_fast(self, A, B):
# for profiling
t = 2
itmax = 5
D = MatrixProductOperator(A, B)
est, v, w, nmults, nresamples = _onenormest_core(D, D.T, t, itmax)
return est
@pytest.mark.slow
def test_onenormest_linear_operator(self):
# Define a matrix through its product A B.
# Depending on the shapes of A and B,
# it could be easy to multiply this product by a small matrix,
# but it could be annoying to look at all of
# the entries of the product explicitly.
np.random.seed(1234)
n = 6000
k = 3
A = np.random.randn(n, k)
B = np.random.randn(k, n)
fast_estimate = self._help_product_norm_fast(A, B)
exact_value = self._help_product_norm_slow(A, B)
assert_(fast_estimate <= exact_value <= 3*fast_estimate,
'fast: %g\nexact:%g' % (fast_estimate, exact_value))
def test_returns(self):
np.random.seed(1234)
A = scipy.sparse.rand(50, 50, 0.1)
s0 = scipy.linalg.norm(A.todense(), 1)
s1, v = scipy.sparse.linalg.onenormest(A, compute_v=True)
s2, w = scipy.sparse.linalg.onenormest(A, compute_w=True)
s3, v2, w2 = scipy.sparse.linalg.onenormest(A, compute_w=True, compute_v=True)
assert_allclose(s1, s0, rtol=1e-9)
assert_allclose(np.linalg.norm(A.dot(v), 1), s0*np.linalg.norm(v, 1), rtol=1e-9)
assert_allclose(A.dot(v), w, rtol=1e-9)
class TestAlgorithm_2_2(object):
def test_randn_inv(self):
np.random.seed(1234)
n = 20
nsamples = 100
for i in range(nsamples):
# Choose integer t uniformly between 1 and 3 inclusive.
t = np.random.randint(1, 4)
# Choose n uniformly between 10 and 40 inclusive.
n = np.random.randint(10, 41)
# Sample the inverse of a matrix with random normal entries.
A = scipy.linalg.inv(np.random.randn(n, n))
# Compute the 1-norm bounds.
g, ind = _algorithm_2_2(A, A.T, t)
|
bsd-3-clause
|
[
624,
774,
3423,
367,
314,
5178,
14,
10096,
423,
265,
287,
269,
278,
270,
859,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
702,
63,
7520,
12,
702,
63,
1452,
12,
702,
63,
199,
646,
4613,
199,
646,
7026,
14,
10096,
199,
646,
7026,
14,
4421,
14,
10096,
199,
504,
7026,
14,
4421,
14,
10096,
423,
265,
287,
269,
278,
270,
492,
485,
265,
287,
269,
278,
270,
63,
1018,
12,
485,
8833,
63,
18,
63,
18,
421,
199,
533,
8449,
5884,
7961,
8,
14248,
14,
4421,
14,
10096,
14,
26463,
304,
272,
408,
272,
961,
365,
15111,
590,
367,
641,
287,
269,
278,
270,
5343,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
437,
12,
699,
304,
267,
340,
437,
14,
8322,
1137,
499,
503,
699,
14,
8322,
1137,
499,
26,
288,
746,
1722,
360,
2062,
302,
4460,
4814,
6144,
12627,
358,
267,
340,
437,
14,
1392,
59,
17,
61,
1137,
699,
14,
1392,
59,
16,
2189,
288,
746,
1722,
360,
31787,
11751,
358,
267,
291,
14,
33,
275,
437,
267,
291,
14,
34,
275,
699,
267,
291,
14,
8322,
275,
499,
267,
291,
14,
1392,
275,
334,
33,
14,
1392,
59,
16,
467,
699,
14,
1392,
59,
17,
566,
339,
347,
485,
23551,
8,
277,
12,
671,
304,
267,
372,
980,
14,
3287,
8,
277,
14,
33,
12,
980,
14,
3287,
8,
277,
14,
34,
12,
671,
430,
339,
347,
485,
82,
23551,
8,
277,
12,
671,
304,
267,
372,
980,
14,
3287,
8,
1590,
14,
3287,
8,
88,
12,
291,
14,
33,
395,
291,
14,
34,
9,
339,
347,
485,
569,
569,
8,
277,
12,
1323,
304,
267,
372,
980,
14,
3287,
8,
277,
14,
33,
12,
980,
14,
3287,
8,
277,
14,
34,
12,
1323,
430,
339,
768,
1829,
272,
347,
377,
8,
277,
304,
267,
372,
8449,
5884,
7961,
8,
277,
14,
34,
14,
52,
12,
291,
14,
33,
14,
52,
9,
421,
199,
533,
1379,
3314,
287,
269,
278,
270,
8,
785,
304,
339,
768,
4462,
14,
1657,
14,
7977,
674,
272,
347,
511,
63,
265,
287,
269,
278,
270,
63,
1224,
63,
19,
63,
84,
63,
18,
8,
277,
304,
267,
327,
961,
911,
5452,
3663,
4696,
340,
2195,
24189,
365,
11999,
2839,
30820,
14,
267,
327,
2779,
365,
26123,
21913,
12,
880,
314,
13464,
4293,
506,
4634,
7478,
14,
267,
980,
14,
2355,
14,
5176,
8,
4321,
9,
267,
307,
275,
499,
267,
302,
275,
2948,
267,
652,
988,
275,
959,
267,
700,
1889,
275,
22369,
267,
20802,
275,
942,
267,
1420,
275,
942,
267,
302,
14699,
63,
513,
275,
942,
267,
302,
22882,
63,
513,
275,
942,
267,
367,
284,
315,
1425,
8,
561,
1889,
304,
288,
437,
275,
7026,
14,
10096,
14,
5350,
8,
1590,
14,
2355,
14,
10843,
8,
78,
12,
302,
430,
288,
4347,
12,
373,
12,
336,
12,
302,
14699,
83,
12,
302,
470,
1889,
275,
485,
265,
287,
269,
278,
270,
63,
1018,
8,
33,
12,
437,
14,
52,
12,
307,
12,
652,
988,
9,
288,
20802,
14,
740,
8,
597,
9,
288,
1420,
14,
740,
8,
14248,
14,
10096,
14,
4791,
8,
33,
12,
413,
430,
288,
302,
14699,
63,
513,
14,
740,
8,
10756,
427,
83,
9,
288,
302,
22882,
63,
513,
14,
740,
8,
78,
470,
1889,
9,
267,
20802,
275,
980,
14,
1144,
8,
22300,
12,
2152,
29,
1609,
9,
267,
1420,
275,
980,
14,
1144,
8,
2062,
12,
2152,
29,
1609,
9,
267,
3847,
63,
2550,
275,
980,
14,
2101,
8,
22300,
446,
1420,
9,
1182,
1420,
398,
327,
1104,
314,
4615,
625,
271,
3911,
8182,
10463,
267,
625,
271,
3911,
8182,
63,
6884,
275,
20802,
1182,
1420,
267,
702,
2531,
16,
14,
1020,
665,
980,
14,
3670,
8,
324,
271,
3911,
8182,
63,
6884,
9,
665,
413,
14,
16,
9,
398,
327,
1104,
314,
1390,
436,
4615,
1415,
2763,
522,
1889,
267,
702,
63,
1452,
8,
1590,
14,
988,
8,
78,
22882,
63,
513,
395,
499,
9,
267,
702,
2531,
16,
14,
1717,
665,
980,
14,
3670,
8,
78,
22882,
63,
513,
9,
665,
378,
14,
18,
9,
398,
327,
1104,
314,
24382,
402,
6590,
706,
9235,
8840,
6657,
267,
302,
7327,
275,
980,
14,
835,
63,
10262,
8,
6188,
63,
2550,
665,
413,
69,
13,
1079,
9,
267,
24382,
63,
7327,
275,
302,
7327,
1182,
2069,
8,
561,
1889,
9,
267,
702,
2531,
16,
14,
25,
665,
24382,
63,
7327,
665,
378,
14,
2720,
9,
398,
327,
1104,
314,
8095,
1329,
402,
3634,
10,
4106,
8897,
10785,
267,
702,
2531,
19,
14,
21,
665,
980,
14,
3670,
8,
10756,
427,
63,
513,
9,
665,
841,
14,
21,
9,
339,
768,
4462,
14,
1657,
14,
7977,
674,
272,
347,
511,
63,
265,
287,
269,
278,
270,
63,
1224,
63,
20,
63,
84,
63,
23,
8,
277,
304,
267,
327,
961,
911,
5452,
3663,
4696,
340,
2195,
24189,
365,
11999,
2839,
30820,
14,
267,
327,
2779,
365,
26123,
21913,
12,
880,
314,
13464,
4293,
506,
4634,
7478,
14,
267,
980,
14,
2355,
14,
5176,
8,
4321,
9,
267,
307,
275,
1520,
267,
302,
275,
2948,
267,
652,
988,
275,
959,
267,
700,
1889,
275,
22369,
267,
20802,
275,
942,
267,
1420,
275,
942,
267,
302,
14699,
63,
513,
275,
942,
267,
302,
22882,
63,
513,
275,
942,
267,
367,
284,
315,
1425,
8,
561,
1889,
304,
288,
437,
275,
980,
14,
2355,
14,
8393,
2801,
17,
12,
499,
12,
1568,
2687,
78,
12,
302,
430,
288,
4347,
12,
373,
12,
336,
12,
302,
14699,
83,
12,
302,
470,
1889,
275,
485,
265,
287,
269,
278,
270,
63,
1018,
8,
33,
12,
437,
14,
52,
12,
307,
12,
652,
988,
9,
288,
20802,
14,
740,
8,
597,
9,
288,
1420,
14,
740,
8,
14248,
14,
10096,
14,
4791,
8,
33,
12,
413,
430,
288,
302,
14699,
63,
513,
14,
740,
8,
10756,
427,
83,
9,
288,
302,
22882,
63,
513,
14,
740,
8,
78,
470,
1889,
9,
267,
20802,
275,
980,
14,
1144,
8,
22300,
12,
2152,
29,
1609,
9,
267,
1420
] |
[
774,
3423,
367,
314,
5178,
14,
10096,
423,
265,
287,
269,
278,
270,
859,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
702,
63,
7520,
12,
702,
63,
1452,
12,
702,
63,
199,
646,
4613,
199,
646,
7026,
14,
10096,
199,
646,
7026,
14,
4421,
14,
10096,
199,
504,
7026,
14,
4421,
14,
10096,
423,
265,
287,
269,
278,
270,
492,
485,
265,
287,
269,
278,
270,
63,
1018,
12,
485,
8833,
63,
18,
63,
18,
421,
199,
533,
8449,
5884,
7961,
8,
14248,
14,
4421,
14,
10096,
14,
26463,
304,
272,
408,
272,
961,
365,
15111,
590,
367,
641,
287,
269,
278,
270,
5343,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
437,
12,
699,
304,
267,
340,
437,
14,
8322,
1137,
499,
503,
699,
14,
8322,
1137,
499,
26,
288,
746,
1722,
360,
2062,
302,
4460,
4814,
6144,
12627,
358,
267,
340,
437,
14,
1392,
59,
17,
61,
1137,
699,
14,
1392,
59,
16,
2189,
288,
746,
1722,
360,
31787,
11751,
358,
267,
291,
14,
33,
275,
437,
267,
291,
14,
34,
275,
699,
267,
291,
14,
8322,
275,
499,
267,
291,
14,
1392,
275,
334,
33,
14,
1392,
59,
16,
467,
699,
14,
1392,
59,
17,
566,
339,
347,
485,
23551,
8,
277,
12,
671,
304,
267,
372,
980,
14,
3287,
8,
277,
14,
33,
12,
980,
14,
3287,
8,
277,
14,
34,
12,
671,
430,
339,
347,
485,
82,
23551,
8,
277,
12,
671,
304,
267,
372,
980,
14,
3287,
8,
1590,
14,
3287,
8,
88,
12,
291,
14,
33,
395,
291,
14,
34,
9,
339,
347,
485,
569,
569,
8,
277,
12,
1323,
304,
267,
372,
980,
14,
3287,
8,
277,
14,
33,
12,
980,
14,
3287,
8,
277,
14,
34,
12,
1323,
430,
339,
768,
1829,
272,
347,
377,
8,
277,
304,
267,
372,
8449,
5884,
7961,
8,
277,
14,
34,
14,
52,
12,
291,
14,
33,
14,
52,
9,
421,
199,
533,
1379,
3314,
287,
269,
278,
270,
8,
785,
304,
339,
768,
4462,
14,
1657,
14,
7977,
674,
272,
347,
511,
63,
265,
287,
269,
278,
270,
63,
1224,
63,
19,
63,
84,
63,
18,
8,
277,
304,
267,
327,
961,
911,
5452,
3663,
4696,
340,
2195,
24189,
365,
11999,
2839,
30820,
14,
267,
327,
2779,
365,
26123,
21913,
12,
880,
314,
13464,
4293,
506,
4634,
7478,
14,
267,
980,
14,
2355,
14,
5176,
8,
4321,
9,
267,
307,
275,
499,
267,
302,
275,
2948,
267,
652,
988,
275,
959,
267,
700,
1889,
275,
22369,
267,
20802,
275,
942,
267,
1420,
275,
942,
267,
302,
14699,
63,
513,
275,
942,
267,
302,
22882,
63,
513,
275,
942,
267,
367,
284,
315,
1425,
8,
561,
1889,
304,
288,
437,
275,
7026,
14,
10096,
14,
5350,
8,
1590,
14,
2355,
14,
10843,
8,
78,
12,
302,
430,
288,
4347,
12,
373,
12,
336,
12,
302,
14699,
83,
12,
302,
470,
1889,
275,
485,
265,
287,
269,
278,
270,
63,
1018,
8,
33,
12,
437,
14,
52,
12,
307,
12,
652,
988,
9,
288,
20802,
14,
740,
8,
597,
9,
288,
1420,
14,
740,
8,
14248,
14,
10096,
14,
4791,
8,
33,
12,
413,
430,
288,
302,
14699,
63,
513,
14,
740,
8,
10756,
427,
83,
9,
288,
302,
22882,
63,
513,
14,
740,
8,
78,
470,
1889,
9,
267,
20802,
275,
980,
14,
1144,
8,
22300,
12,
2152,
29,
1609,
9,
267,
1420,
275,
980,
14,
1144,
8,
2062,
12,
2152,
29,
1609,
9,
267,
3847,
63,
2550,
275,
980,
14,
2101,
8,
22300,
446,
1420,
9,
1182,
1420,
398,
327,
1104,
314,
4615,
625,
271,
3911,
8182,
10463,
267,
625,
271,
3911,
8182,
63,
6884,
275,
20802,
1182,
1420,
267,
702,
2531,
16,
14,
1020,
665,
980,
14,
3670,
8,
324,
271,
3911,
8182,
63,
6884,
9,
665,
413,
14,
16,
9,
398,
327,
1104,
314,
1390,
436,
4615,
1415,
2763,
522,
1889,
267,
702,
63,
1452,
8,
1590,
14,
988,
8,
78,
22882,
63,
513,
395,
499,
9,
267,
702,
2531,
16,
14,
1717,
665,
980,
14,
3670,
8,
78,
22882,
63,
513,
9,
665,
378,
14,
18,
9,
398,
327,
1104,
314,
24382,
402,
6590,
706,
9235,
8840,
6657,
267,
302,
7327,
275,
980,
14,
835,
63,
10262,
8,
6188,
63,
2550,
665,
413,
69,
13,
1079,
9,
267,
24382,
63,
7327,
275,
302,
7327,
1182,
2069,
8,
561,
1889,
9,
267,
702,
2531,
16,
14,
25,
665,
24382,
63,
7327,
665,
378,
14,
2720,
9,
398,
327,
1104,
314,
8095,
1329,
402,
3634,
10,
4106,
8897,
10785,
267,
702,
2531,
19,
14,
21,
665,
980,
14,
3670,
8,
10756,
427,
63,
513,
9,
665,
841,
14,
21,
9,
339,
768,
4462,
14,
1657,
14,
7977,
674,
272,
347,
511,
63,
265,
287,
269,
278,
270,
63,
1224,
63,
20,
63,
84,
63,
23,
8,
277,
304,
267,
327,
961,
911,
5452,
3663,
4696,
340,
2195,
24189,
365,
11999,
2839,
30820,
14,
267,
327,
2779,
365,
26123,
21913,
12,
880,
314,
13464,
4293,
506,
4634,
7478,
14,
267,
980,
14,
2355,
14,
5176,
8,
4321,
9,
267,
307,
275,
1520,
267,
302,
275,
2948,
267,
652,
988,
275,
959,
267,
700,
1889,
275,
22369,
267,
20802,
275,
942,
267,
1420,
275,
942,
267,
302,
14699,
63,
513,
275,
942,
267,
302,
22882,
63,
513,
275,
942,
267,
367,
284,
315,
1425,
8,
561,
1889,
304,
288,
437,
275,
980,
14,
2355,
14,
8393,
2801,
17,
12,
499,
12,
1568,
2687,
78,
12,
302,
430,
288,
4347,
12,
373,
12,
336,
12,
302,
14699,
83,
12,
302,
470,
1889,
275,
485,
265,
287,
269,
278,
270,
63,
1018,
8,
33,
12,
437,
14,
52,
12,
307,
12,
652,
988,
9,
288,
20802,
14,
740,
8,
597,
9,
288,
1420,
14,
740,
8,
14248,
14,
10096,
14,
4791,
8,
33,
12,
413,
430,
288,
302,
14699,
63,
513,
14,
740,
8,
10756,
427,
83,
9,
288,
302,
22882,
63,
513,
14,
740,
8,
78,
470,
1889,
9,
267,
20802,
275,
980,
14,
1144,
8,
22300,
12,
2152,
29,
1609,
9,
267,
1420,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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443
|
#!/usr/bin/env python
"""Generate go-jstools.py"""
import sys
import textwrap
import virtualenv
filename = 'go-windmill.py'
after_install = """\
import os, subprocess
def after_install(options, home_dir):
etc = join(home_dir, 'etc')
## TODO: this should all come from distutils
## like distutils.sysconfig.get_python_inc()
if sys.platform == 'win32':
lib_dir = join(home_dir, 'Lib')
bin_dir = join(home_dir, 'Scripts')
elif is_jython:
lib_dir = join(home_dir, 'Lib')
bin_dir = join(home_dir, 'bin')
else:
lib_dir = join(home_dir, 'lib', py_version)
bin_dir = join(home_dir, 'bin')
if not os.path.exists(etc):
os.makedirs(etc)
subprocess.call([join(bin_dir, 'easy_install'), 'windmill==%s'])
"""
def generate(filename, version):
# what's commented out below comes from go-pylons.py
#path = version
#if '==' in version:
# path = version[:version.find('==')]
#output = virtualenv.create_bootstrap_script(
# textwrap.dedent(after_install % (path, version)))
output = virtualenv.create_bootstrap_script(
textwrap.dedent(after_install % version))
fp = open(filename, 'w')
fp.write(output)
fp.close()
def main():
if len(sys.argv) != 2:
print >> sys.stderr, 'usage: %s version' % sys.argv[0]
sys.exit(1)
generate(filename, sys.argv[1])
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
6864,
2621,
13,
74,
270,
5998,
14,
647,
624,
199,
646,
984,
199,
646,
13390,
199,
646,
19128,
199,
199,
1501,
275,
283,
1939,
13,
11530,
77,
778,
14,
647,
7,
199,
199,
4399,
63,
3174,
275,
9638,
199,
646,
747,
12,
3873,
199,
318,
2410,
63,
3174,
8,
1419,
12,
5629,
63,
694,
304,
272,
5423,
275,
4263,
8,
4219,
63,
694,
12,
283,
6839,
358,
272,
925,
3254,
26,
642,
1077,
1006,
11492,
687,
7065,
272,
925,
2839,
7065,
14,
24030,
14,
362,
63,
1548,
63,
6559,
342,
272,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
267,
1973,
63,
694,
275,
4263,
8,
4219,
63,
694,
12,
283,
4728,
358,
267,
2517,
63,
694,
275,
4263,
8,
4219,
63,
694,
12,
283,
25681,
358,
272,
916,
365,
63,
27179,
26,
267,
1973,
63,
694,
275,
4263,
8,
4219,
63,
694,
12,
283,
4728,
358,
267,
2517,
63,
694,
275,
4263,
8,
4219,
63,
694,
12,
283,
1393,
358,
272,
587,
26,
267,
1973,
63,
694,
275,
4263,
8,
4219,
63,
694,
12,
283,
773,
297,
1134,
63,
1023,
9,
267,
2517,
63,
694,
275,
4263,
8,
4219,
63,
694,
12,
283,
1393,
358,
339,
340,
440,
747,
14,
515,
14,
2444,
8,
6839,
304,
267,
747,
14,
8347,
8,
6839,
9,
272,
3873,
14,
1250,
779,
904,
8,
1393,
63,
694,
12,
283,
13581,
63,
3174,
659,
283,
11530,
77,
778,
389,
5,
83,
1105,
199,
624,
421,
199,
318,
3550,
8,
1501,
12,
1015,
304,
272,
327,
4052,
1159,
21804,
734,
5084,
12477,
687,
2621,
13,
647,
76,
4654,
14,
647,
339,
327,
515,
275,
1015,
272,
327,
692,
283,
6803,
315,
1015,
26,
272,
327,
259,
931,
275,
1015,
1491,
1023,
14,
1623,
360,
389,
5440,
272,
327,
1199,
275,
19128,
14,
981,
63,
11146,
63,
1579,
8,
272,
327,
259,
13390,
14,
14674,
8,
4399,
63,
3174,
450,
334,
515,
12,
1015,
1724,
339,
1072,
275,
19128,
14,
981,
63,
11146,
63,
1579,
8,
267,
13390,
14,
14674,
8,
4399,
63,
3174,
450,
1015,
430,
272,
4090,
275,
1551,
8,
1501,
12,
283,
87,
358,
272,
4090,
14,
952,
8,
1199,
9,
272,
4090,
14,
1600,
342,
421,
199,
318,
2446,
837,
272,
340,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
267,
870,
4331,
984,
14,
3083,
12,
283,
3807,
26,
450,
83,
1015,
7,
450,
984,
14,
3020,
59,
16,
61,
267,
984,
14,
2224,
8,
17,
9,
272,
3550,
8,
1501,
12,
984,
14,
3020,
59,
17,
566,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
6864,
2621,
13,
74,
270,
5998,
14,
647,
624,
199,
646,
984,
199,
646,
13390,
199,
646,
19128,
199,
199,
1501,
275,
283,
1939,
13,
11530,
77,
778,
14,
647,
7,
199,
199,
4399,
63,
3174,
275,
9638,
199,
646,
747,
12,
3873,
199,
318,
2410,
63,
3174,
8,
1419,
12,
5629,
63,
694,
304,
272,
5423,
275,
4263,
8,
4219,
63,
694,
12,
283,
6839,
358,
272,
925,
3254,
26,
642,
1077,
1006,
11492,
687,
7065,
272,
925,
2839,
7065,
14,
24030,
14,
362,
63,
1548,
63,
6559,
342,
272,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
267,
1973,
63,
694,
275,
4263,
8,
4219,
63,
694,
12,
283,
4728,
358,
267,
2517,
63,
694,
275,
4263,
8,
4219,
63,
694,
12,
283,
25681,
358,
272,
916,
365,
63,
27179,
26,
267,
1973,
63,
694,
275,
4263,
8,
4219,
63,
694,
12,
283,
4728,
358,
267,
2517,
63,
694,
275,
4263,
8,
4219,
63,
694,
12,
283,
1393,
358,
272,
587,
26,
267,
1973,
63,
694,
275,
4263,
8,
4219,
63,
694,
12,
283,
773,
297,
1134,
63,
1023,
9,
267,
2517,
63,
694,
275,
4263,
8,
4219,
63,
694,
12,
283,
1393,
358,
339,
340,
440,
747,
14,
515,
14,
2444,
8,
6839,
304,
267,
747,
14,
8347,
8,
6839,
9,
272,
3873,
14,
1250,
779,
904,
8,
1393,
63,
694,
12,
283,
13581,
63,
3174,
659,
283,
11530,
77,
778,
389,
5,
83,
1105,
199,
624,
421,
199,
318,
3550,
8,
1501,
12,
1015,
304,
272,
327,
4052,
1159,
21804,
734,
5084,
12477,
687,
2621,
13,
647,
76,
4654,
14,
647,
339,
327,
515,
275,
1015,
272,
327,
692,
283,
6803,
315,
1015,
26,
272,
327,
259,
931,
275,
1015,
1491,
1023,
14,
1623,
360,
389,
5440,
272,
327,
1199,
275,
19128,
14,
981,
63,
11146,
63,
1579,
8,
272,
327,
259,
13390,
14,
14674,
8,
4399,
63,
3174,
450,
334,
515,
12,
1015,
1724,
339,
1072,
275,
19128,
14,
981,
63,
11146,
63,
1579,
8,
267,
13390,
14,
14674,
8,
4399,
63,
3174,
450,
1015,
430,
272,
4090,
275,
1551,
8,
1501,
12,
283,
87,
358,
272,
4090,
14,
952,
8,
1199,
9,
272,
4090,
14,
1600,
342,
421,
199,
318,
2446,
837,
272,
340,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
267,
870,
4331,
984,
14,
3083,
12,
283,
3807,
26,
450,
83,
1015,
7,
450,
984,
14,
3020,
59,
16,
61,
267,
984,
14,
2224,
8,
17,
9,
272,
3550,
8,
1501,
12,
984,
14,
3020,
59,
17,
566,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
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zadnouri/numpy
|
numpy/polynomial/legendre.py
|
5
|
57194
|
"""
Legendre Series (:mod: `numpy.polynomial.legendre`)
===================================================
.. currentmodule:: numpy.polynomial.polynomial
This module provides a number of objects (mostly functions) useful for
dealing with Legendre series, including a `Legendre` class that
encapsulates the usual arithmetic operations. (General information
on how this module represents and works with such polynomials is in the
docstring for its "parent" sub-package, `numpy.polynomial`).
Constants
---------
.. autosummary::
:toctree: generated/
legdomain Legendre series default domain, [-1,1].
legzero Legendre series that evaluates identically to 0.
legone Legendre series that evaluates identically to 1.
legx Legendre series for the identity map, ``f(x) = x``.
Arithmetic
----------
.. autosummary::
:toctree: generated/
legmulx multiply a Legendre series in P_i(x) by x.
legadd add two Legendre series.
legsub subtract one Legendre series from another.
legmul multiply two Legendre series.
legdiv divide one Legendre series by another.
legpow raise a Legendre series to an positive integer power
legval evaluate a Legendre series at given points.
legval2d evaluate a 2D Legendre series at given points.
legval3d evaluate a 3D Legendre series at given points.
leggrid2d evaluate a 2D Legendre series on a Cartesian product.
leggrid3d evaluate a 3D Legendre series on a Cartesian product.
Calculus
--------
.. autosummary::
:toctree: generated/
legder differentiate a Legendre series.
legint integrate a Legendre series.
Misc Functions
--------------
.. autosummary::
:toctree: generated/
legfromroots create a Legendre series with specified roots.
legroots find the roots of a Legendre series.
legvander Vandermonde-like matrix for Legendre polynomials.
legvander2d Vandermonde-like matrix for 2D power series.
legvander3d Vandermonde-like matrix for 3D power series.
leggauss Gauss-Legendre quadrature, points and weights.
legweight Legendre weight function.
legcompanion symmetrized companion matrix in Legendre form.
legfit least-squares fit returning a Legendre series.
legtrim trim leading coefficients from a Legendre series.
legline Legendre series representing given straight line.
leg2poly convert a Legendre series to a polynomial.
poly2leg convert a polynomial to a Legendre series.
Classes
-------
Legendre A Legendre series class.
See also
--------
numpy.polynomial.polynomial
numpy.polynomial.chebyshev
numpy.polynomial.laguerre
numpy.polynomial.hermite
numpy.polynomial.hermite_e
"""
from __future__ import division, absolute_import, print_function
import warnings
import numpy as np
import numpy.linalg as la
from numpy.core.multiarray import normalize_axis_index
from . import polyutils as pu
from ._polybase import ABCPolyBase
__all__ = [
'legzero', 'legone', 'legx', 'legdomain', 'legline', 'legadd',
'legsub', 'legmulx', 'legmul', 'legdiv', 'legpow', 'legval', 'legder',
'legint', 'leg2poly', 'poly2leg', 'legfromroots', 'legvander',
'legfit', 'legtrim', 'legroots', 'Legendre', 'legval2d', 'legval3d',
'leggrid2d', 'leggrid3d', 'legvander2d', 'legvander3d', 'legcompanion',
'leggauss', 'legweight']
legtrim = pu.trimcoef
def poly2leg(pol):
"""
Convert a polynomial to a Legendre series.
Convert an array representing the coefficients of a polynomial (relative
to the "standard" basis) ordered from lowest degree to highest, to an
array of the coefficients of the equivalent Legendre series, ordered
from lowest to highest degree.
Parameters
----------
pol : array_like
1-D array containing the polynomial coefficients
Returns
-------
c : ndarray
1-D array containing the coefficients of the equivalent Legendre
series.
See Also
--------
leg2poly
Notes
-----
The easy way to do conversions between polynomial basis sets
is to use the convert method of a class instance.
Examples
--------
>>> from numpy import polynomial as P
>>> p = P.Polynomial(np.arange(4))
>>> p
Polynomial([ 0., 1., 2., 3.], [-1., 1.])
>>> c = P.Legendre(P.poly2leg(p.coef))
>>> c
Legendre([ 1. , 3.25, 1. , 0.75], [-1., 1.])
"""
[pol] = pu.as_series([pol])
deg = len(pol) - 1
res = 0
for i in range(deg, -1, -1):
res = legadd(legmulx(res), pol[i])
return res
def leg2poly(c):
"""
Convert a Legendre series to a polynomial.
Convert an array representing the coefficients of a Legendre series,
ordered from lowest degree to highest, to an array of the coefficients
of the equivalent polynomial (relative to the "standard" basis) ordered
from lowest to highest degree.
Parameters
----------
c : array_like
1-D array containing the Legendre series coefficients, ordered
from lowest order term to highest.
Returns
-------
pol : ndarray
1-D array containing the coefficients of the equivalent polynomial
(relative to the "standard" basis) ordered from lowest order term
to highest.
See Also
--------
poly2leg
Notes
-----
The easy way to do conversions between polynomial basis sets
is to use the convert method of a class instance.
Examples
--------
>>> c = P.Legendre(range(4))
>>> c
Legendre([ 0., 1., 2., 3.], [-1., 1.])
>>> p = c.convert(kind=P.Polynomial)
>>> p
Polynomial([-1. , -3.5, 3. , 7.5], [-1., 1.])
>>> P.leg2poly(range(4))
array([-1. , -3.5, 3. , 7.5])
"""
from .polynomial import polyadd, polysub, polymulx
[c] = pu.as_series([c])
n = len(c)
if n < 3:
return c
else:
c0 = c[-2]
c1 = c[-1]
# i is the current degree of c1
for i in range(n - 1, 1, -1):
tmp = c0
c0 = polysub(c[i - 2], (c1*(i - 1))/i)
c1 = polyadd(tmp, (polymulx(c1)*(2*i - 1))/i)
return polyadd(c0, polymulx(c1))
#
# These are constant arrays are of integer type so as to be compatible
# with the widest range of other types, such as Decimal.
#
# Legendre
legdomain = np.array([-1, 1])
# Legendre coefficients representing zero.
legzero = np.array([0])
# Legendre coefficients representing one.
legone = np.array([1])
# Legendre coefficients representing the identity x.
legx = np.array([0, 1])
def legline(off, scl):
"""
Legendre series whose graph is a straight line.
Parameters
----------
off, scl : scalars
The specified line is given by ``off + scl*x``.
Returns
-------
y : ndarray
This module's representation of the Legendre series for
``off + scl*x``.
See Also
--------
polyline, chebline
Examples
--------
>>> import numpy.polynomial.legendre as L
>>> L.legline(3,2)
array([3, 2])
>>> L.legval(-3, L.legline(3,2)) # should be -3
-3.0
"""
if scl != 0:
return np.array([off, scl])
else:
return np.array([off])
def legfromroots(roots):
"""
Generate a Legendre series with given roots.
The function returns the coefficients of the polynomial
.. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n),
in Legendre form, where the `r_n` are the roots specified in `roots`.
If a zero has multiplicity n, then it must appear in `roots` n times.
For instance, if 2 is a root of multiplicity three and 3 is a root of
multiplicity 2, then `roots` looks something like [2, 2, 2, 3, 3]. The
roots can appear in any order.
If the returned coefficients are `c`, then
.. math:: p(x) = c_0 + c_1 * L_1(x) + ... + c_n * L_n(x)
The coefficient of the last term is not generally 1 for monic
polynomials in Legendre form.
Parameters
----------
roots : array_like
Sequence containing the roots.
Returns
-------
out : ndarray
1-D array of coefficients. If all roots are real then `out` is a
real array, if some of the roots are complex, then `out` is complex
even if all the coefficients in the result are real (see Examples
below).
See Also
--------
polyfromroots, chebfromroots, lagfromroots, hermfromroots,
hermefromroots.
Examples
--------
>>> import numpy.polynomial.legendre as L
>>> L.legfromroots((-1,0,1)) # x^3 - x relative to the standard basis
array([ 0. , -0.4, 0. , 0.4])
>>> j = complex(0,1)
>>> L.legfromroots((-j,j)) # x^2 + 1 relative to the standard basis
array([ 1.33333333+0.j, 0.00000000+0.j, 0.66666667+0.j])
"""
if len(roots) == 0:
return np.ones(1)
else:
[roots] = pu.as_series([roots], trim=False)
roots.sort()
p = [legline(-r, 1) for r in roots]
n = len(p)
while n > 1:
m, r = divmod(n, 2)
tmp = [legmul(p[i], p[i+m]) for i in range(m)]
if r:
tmp[0] = legmul(tmp[0], p[-1])
p = tmp
n = m
return p[0]
def legadd(c1, c2):
"""
Add one Legendre series to another.
Returns the sum of two Legendre series `c1` + `c2`. The arguments
are sequences of coefficients ordered from lowest order term to
highest, i.e., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
Parameters
----------
c1, c2 : array_like
1-D arrays of Legendre series coefficients ordered from low to
high.
Returns
-------
out : ndarray
Array representing the Legendre series of their sum.
See Also
--------
legsub, legmul, legdiv, legpow
Notes
-----
Unlike multiplication, division, etc., the sum of two Legendre series
is a Legendre series (without having to "reproject" the result onto
the basis set) so addition, just like that of "standard" polynomials,
is simply "component-wise."
Examples
--------
>>> from numpy.polynomial import legendre as L
>>> c1 = (1,2,3)
>>> c2 = (3,2,1)
>>> L.legadd(c1,c2)
array([ 4., 4., 4.])
"""
# c1, c2 are trimmed copies
[c1, c2] = pu.as_series([c1, c2])
if len(c1) > len(c2):
c1[:c2.size] += c2
ret = c1
else:
c2[:c1.size] += c1
ret = c2
return pu.trimseq(ret)
def legsub(c1, c2):
"""
Subtract one Legendre series from another.
Returns the difference of two Legendre series `c1` - `c2`. The
sequences of coefficients are from lowest order term to highest, i.e.,
[1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
Parameters
----------
c1, c2 : array_like
1-D arrays of Legendre series coefficients ordered from low to
high.
Returns
-------
out : ndarray
Of Legendre series coefficients representing their difference.
See Also
--------
legadd, legmul, legdiv, legpow
Notes
-----
Unlike multiplication, division, etc., the difference of two Legendre
series is a Legendre series (without having to "reproject" the result
onto the basis set) so subtraction, just like that of "standard"
polynomials, is simply "component-wise."
Examples
--------
>>> from numpy.polynomial import legendre as L
>>> c1 = (1,2,3)
>>> c2 = (3,2,1)
>>> L.legsub(c1,c2)
array([-2., 0., 2.])
>>> L.legsub(c2,c1) # -C.legsub(c1,c2)
array([ 2., 0., -2.])
"""
# c1, c2 are trimmed copies
[c1, c2] = pu.as_series([c1, c2])
if len(c1) > len(c2):
c1[:c2.size] -= c2
ret = c1
else:
c2 = -c2
c2[:c1.size] += c1
ret = c2
return pu.trimseq(ret)
def legmulx(c):
"""Multiply a Legendre series by x.
Multiply the Legendre series `c` by x, where x is the independent
variable.
Parameters
----------
c : array_like
1-D array of Legendre series coefficients ordered from low to
high.
Returns
-------
out : ndarray
Array representing the result of the multiplication.
Notes
-----
The multiplication uses the recursion relationship for Legendre
polynomials in the form
.. math::
xP_i(x) = ((i + 1)*P_{i + 1}(x) + i*P_{i - 1}(x))/(2i + 1)
"""
# c is a trimmed copy
[c] = pu.as_series([c])
# The zero series needs special treatment
if len(c) == 1 and c[0] == 0:
return c
prd = np.empty(len(c) + 1, dtype=c.dtype)
prd[0] = c[0]*0
prd[1] = c[0]
for i in range(1, len(c)):
j = i + 1
k = i - 1
s = i + j
prd[j] = (c[i]*j)/s
prd[k] += (c[i]*i)/s
return prd
def legmul(c1, c2):
"""
Multiply one Legendre series by another.
Returns the product of two Legendre series `c1` * `c2`. The arguments
are sequences of coefficients, from lowest order "term" to highest,
e.g., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.
Parameters
----------
c1, c2 : array_like
1-D arrays of Legendre series coefficients ordered from low to
high.
Returns
-------
out : ndarray
Of Legendre series coefficients representing their product.
See Also
--------
legadd, legsub, legdiv, legpow
Notes
-----
In general, the (polynomial) product of two C-series results in terms
that are not in the Legendre polynomial basis set. Thus, to express
the product as a Legendre series, it is necessary to "reproject" the
product onto said basis set, which may produce "unintuitive" (but
correct) results; see Examples section below.
Examples
--------
>>> from numpy.polynomial import legendre as L
>>> c1 = (1,2,3)
>>> c2 = (3,2)
>>> P.legmul(c1,c2) # multiplication requires "reprojection"
array([ 4.33333333, 10.4 , 11.66666667, 3.6 ])
"""
# s1, s2 are trimmed copies
[c1, c2] = pu.as_series([c1, c2])
if len(c1) > len(c2):
c = c2
xs = c1
else:
c = c1
xs = c2
if len(c) == 1:
c0 = c[0]*xs
c1 = 0
elif len(c) == 2:
c0 = c[0]*xs
c1 = c[1]*xs
else:
nd = len(c)
c0 = c[-2]*xs
c1 = c[-1]*xs
for i in range(3, len(c) + 1):
tmp = c0
nd = nd - 1
c0 = legsub(c[-i]*xs, (c1*(nd - 1))/nd)
c1 = legadd(tmp, (legmulx(c1)*(2*nd - 1))/nd)
return legadd(c0, legmulx(c1))
def legdiv(c1, c2):
"""
Divide one Legendre series by another.
Returns the quotient-with-remainder of two Legendre series
`c1` / `c2`. The arguments are sequences of coefficients from lowest
order "term" to highest, e.g., [1,2,3] represents the series
``P_0 + 2*P_1 + 3*P_2``.
Parameters
----------
c1, c2 : array_like
1-D arrays of Legendre series coefficients ordered from low to
high.
Returns
-------
quo, rem : ndarrays
Of Legendre series coefficients representing the quotient and
remainder.
See Also
--------
legadd, legsub, legmul, legpow
Notes
-----
In general, the (polynomial) division of one Legendre series by another
results in quotient and remainder terms that are not in the Legendre
polynomial basis set. Thus, to express these results as a Legendre
series, it is necessary to "reproject" the results onto the Legendre
basis set, which may produce "unintuitive" (but correct) results; see
Examples section below.
Examples
--------
>>> from numpy.polynomial import legendre as L
>>> c1 = (1,2,3)
>>> c2 = (3,2,1)
>>> L.legdiv(c1,c2) # quotient "intuitive," remainder not
(array([ 3.]), array([-8., -4.]))
>>> c2 = (0,1,2,3)
>>> L.legdiv(c2,c1) # neither "intuitive"
(array([-0.07407407, 1.66666667]), array([-1.03703704, -2.51851852]))
"""
# c1, c2 are trimmed copies
[c1, c2] = pu.as_series([c1, c2])
if c2[-1] == 0:
raise ZeroDivisionError()
lc1 = len(c1)
lc2 = len(c2)
if lc1 < lc2:
return c1[:1]*0, c1
elif lc2 == 1:
return c1/c2[-1], c1[:1]*0
else:
quo = np.empty(lc1 - lc2 + 1, dtype=c1.dtype)
rem = c1
for i in range(lc1 - lc2, - 1, -1):
p = legmul([0]*i + [1], c2)
q = rem[-1]/p[-1]
rem = rem[:-1] - q*p[:-1]
quo[i] = q
return quo, pu.trimseq(rem)
def legpow(c, pow, maxpower=16):
"""Raise a Legendre series to a power.
Returns the Legendre series `c` raised to the power `pow`. The
arguement `c` is a sequence of coefficients ordered from low to high.
i.e., [1,2,3] is the series ``P_0 + 2*P_1 + 3*P_2.``
Parameters
----------
c : array_like
1-D array of Legendre series coefficients ordered from low to
high.
pow : integer
Power to which the series will be raised
maxpower : integer, optional
Maximum power allowed. This is mainly to limit growth of the series
to unmanageable size. Default is 16
Returns
-------
coef : ndarray
Legendre series of power.
See Also
--------
legadd, legsub, legmul, legdiv
Examples
--------
"""
# c is a trimmed copy
[c] = pu.as_series([c])
power = int(pow)
if power != pow or power < 0:
raise ValueError("Power must be a non-negative integer.")
elif maxpower is not None and power > maxpower:
raise ValueError("Power is too large")
elif power == 0:
return np.array([1], dtype=c.dtype)
elif power == 1:
return c
else:
# This can be made more efficient by using powers of two
# in the usual way.
prd = c
for i in range(2, power + 1):
prd = legmul(prd, c)
return prd
def legder(c, m=1, scl=1, axis=0):
"""
Differentiate a Legendre series.
Returns the Legendre series coefficients `c` differentiated `m` times
along `axis`. At each iteration the result is multiplied by `scl` (the
scaling factor is for use in a linear change of variable). The argument
`c` is an array of coefficients from low to high degree along each
axis, e.g., [1,2,3] represents the series ``1*L_0 + 2*L_1 + 3*L_2``
while [[1,2],[1,2]] represents ``1*L_0(x)*L_0(y) + 1*L_1(x)*L_0(y) +
2*L_0(x)*L_1(y) + 2*L_1(x)*L_1(y)`` if axis=0 is ``x`` and axis=1 is
``y``.
Parameters
----------
c : array_like
Array of Legendre series coefficients. If c is multidimensional the
different axis correspond to different variables with the degree in
each axis given by the corresponding index.
m : int, optional
Number of derivatives taken, must be non-negative. (Default: 1)
scl : scalar, optional
Each differentiation is multiplied by `scl`. The end result is
multiplication by ``scl**m``. This is for use in a linear change of
variable. (Default: 1)
axis : int, optional
Axis over which the derivative is taken. (Default: 0).
.. versionadded:: 1.7.0
Returns
-------
der : ndarray
Legendre series of the derivative.
See Also
--------
legint
Notes
-----
In general, the result of differentiating a Legendre series does not
resemble the same operation on a power series. Thus the result of this
function may be "unintuitive," albeit correct; see Examples section
below.
Examples
--------
>>> from numpy.polynomial import legendre as L
>>> c = (1,2,3,4)
>>> L.legder(c)
array([ 6., 9., 20.])
>>> L.legder(c, 3)
array([ 60.])
>>> L.legder(c, scl=-1)
array([ -6., -9., -20.])
>>> L.legder(c, 2,-1)
array([ 9., 60.])
"""
c = np.array(c, ndmin=1, copy=1)
if c.dtype.char in '?bBhHiIlLqQpP':
c = c.astype(np.double)
cnt, iaxis = [int(t) for t in [m, axis]]
if cnt != m:
raise ValueError("The order of derivation must be integer")
if cnt < 0:
raise ValueError("The order of derivation must be non-negative")
if iaxis != axis:
raise ValueError("The axis must be integer")
iaxis = normalize_axis_index(iaxis, c.ndim)
if cnt == 0:
return c
c = np.rollaxis(c, iaxis)
n = len(c)
if cnt >= n:
c = c[:1]*0
else:
for i in range(cnt):
n = n - 1
c *= scl
der = np.empty((n,) + c.shape[1:], dtype=c.dtype)
for j in range(n, 2, -1):
der[j - 1] = (2*j - 1)*c[j]
c[j - 2] += c[j]
if n > 1:
der[1] = 3*c[2]
der[0] = c[1]
c = der
c = np.rollaxis(c, 0, iaxis + 1)
return c
def legint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
"""
Integrate a Legendre series.
Returns the Legendre series coefficients `c` integrated `m` times from
`lbnd` along `axis`. At each iteration the resulting series is
**multiplied** by `scl` and an integration constant, `k`, is added.
The scaling factor is for use in a linear change of variable. ("Buyer
beware": note that, depending on what one is doing, one may want `scl`
to be the reciprocal of what one might expect; for more information,
see the Notes section below.) The argument `c` is an array of
coefficients from low to high degree along each axis, e.g., [1,2,3]
represents the series ``L_0 + 2*L_1 + 3*L_2`` while [[1,2],[1,2]]
represents ``1*L_0(x)*L_0(y) + 1*L_1(x)*L_0(y) + 2*L_0(x)*L_1(y) +
2*L_1(x)*L_1(y)`` if axis=0 is ``x`` and axis=1 is ``y``.
Parameters
----------
c : array_like
Array of Legendre series coefficients. If c is multidimensional the
different axis correspond to different variables with the degree in
each axis given by the corresponding index.
m : int, optional
Order of integration, must be positive. (Default: 1)
k : {[], list, scalar}, optional
Integration constant(s). The value of the first integral at
``lbnd`` is the first value in the list, the value of the second
integral at ``lbnd`` is the second value, etc. If ``k == []`` (the
default), all constants are set to zero. If ``m == 1``, a single
scalar can be given instead of a list.
lbnd : scalar, optional
The lower bound of the integral. (Default: 0)
scl : scalar, optional
Following each integration the result is *multiplied* by `scl`
before the integration constant is added. (Default: 1)
axis : int, optional
Axis over which the integral is taken. (Default: 0).
.. versionadded:: 1.7.0
Returns
-------
S : ndarray
Legendre series coefficient array of the integral.
Raises
------
ValueError
If ``m < 0``, ``len(k) > m``, ``np.isscalar(lbnd) == False``, or
``np.isscalar(scl) == False``.
See Also
--------
legder
Notes
-----
Note that the result of each integration is *multiplied* by `scl`.
Why is this important to note? Say one is making a linear change of
variable :math:`u = ax + b` in an integral relative to `x`. Then
.. math::`dx = du/a`, so one will need to set `scl` equal to
:math:`1/a` - perhaps not what one would have first thought.
Also note that, in general, the result of integrating a C-series needs
to be "reprojected" onto the C-series basis set. Thus, typically,
the result of this function is "unintuitive," albeit correct; see
Examples section below.
Examples
--------
>>> from numpy.polynomial import legendre as L
>>> c = (1,2,3)
>>> L.legint(c)
array([ 0.33333333, 0.4 , 0.66666667, 0.6 ])
>>> L.legint(c, 3)
array([ 1.66666667e-02, -1.78571429e-02, 4.76190476e-02,
-1.73472348e-18, 1.90476190e-02, 9.52380952e-03])
>>> L.legint(c, k=3)
array([ 3.33333333, 0.4 , 0.66666667, 0.6 ])
>>> L.legint(c, lbnd=-2)
array([ 7.33333333, 0.4 , 0.66666667, 0.6 ])
>>> L.legint(c, scl=2)
array([ 0.66666667, 0.8 , 1.33333333, 1.2 ])
"""
c = np.array(c, ndmin=1, copy=1)
if c.dtype.char in '?bBhHiIlLqQpP':
c = c.astype(np.double)
if not np.iterable(k):
k = [k]
cnt, iaxis = [int(t) for t in [m, axis]]
if cnt != m:
raise ValueError("The order of integration must be integer")
if cnt < 0:
raise ValueError("The order of integration must be non-negative")
if len(k) > cnt:
raise ValueError("Too many integration constants")
if iaxis != axis:
raise ValueError("The axis must be integer")
iaxis = normalize_axis_index(iaxis, c.ndim)
if cnt == 0:
return c
c = np.rollaxis(c, iaxis)
k = list(k) + [0]*(cnt - len(k))
for i in range(cnt):
n = len(c)
c *= scl
if n == 1 and np.all(c[0] == 0):
c[0] += k[i]
else:
tmp = np.empty((n + 1,) + c.shape[1:], dtype=c.dtype)
tmp[0] = c[0]*0
tmp[1] = c[0]
if n > 1:
tmp[2] = c[1]/3
for j in range(2, n):
t = c[j]/(2*j + 1)
tmp[j + 1] = t
tmp[j - 1] -= t
tmp[0] += k[i] - legval(lbnd, tmp)
c = tmp
c = np.rollaxis(c, 0, iaxis + 1)
return c
def legval(x, c, tensor=True):
"""
Evaluate a Legendre series at points x.
If `c` is of length `n + 1`, this function returns the value:
.. math:: p(x) = c_0 * L_0(x) + c_1 * L_1(x) + ... + c_n * L_n(x)
The parameter `x` is converted to an array only if it is a tuple or a
list, otherwise it is treated as a scalar. In either case, either `x`
or its elements must support multiplication and addition both with
themselves and with the elements of `c`.
If `c` is a 1-D array, then `p(x)` will have the same shape as `x`. If
`c` is multidimensional, then the shape of the result depends on the
value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
scalars have shape (,).
Trailing zeros in the coefficients will be used in the evaluation, so
they should be avoided if efficiency is a concern.
Parameters
----------
x : array_like, compatible object
If `x` is a list or tuple, it is converted to an ndarray, otherwise
it is left unchanged and treated as a scalar. In either case, `x`
or its elements must support addition and multiplication with
with themselves and with the elements of `c`.
c : array_like
Array of coefficients ordered so that the coefficients for terms of
degree n are contained in c[n]. If `c` is multidimensional the
remaining indices enumerate multiple polynomials. In the two
dimensional case the coefficients may be thought of as stored in
the columns of `c`.
tensor : boolean, optional
If True, the shape of the coefficient array is extended with ones
on the right, one for each dimension of `x`. Scalars have dimension 0
for this action. The result is that every column of coefficients in
`c` is evaluated for every element of `x`. If False, `x` is broadcast
over the columns of `c` for the evaluation. This keyword is useful
when `c` is multidimensional. The default value is True.
.. versionadded:: 1.7.0
Returns
-------
values : ndarray, algebra_like
The shape of the return value is described above.
See Also
--------
legval2d, leggrid2d, legval3d, leggrid3d
Notes
-----
The evaluation uses Clenshaw recursion, aka synthetic division.
Examples
--------
"""
c = np.array(c, ndmin=1, copy=0)
if c.dtype.char in '?bBhHiIlLqQpP':
c = c.astype(np.double)
if isinstance(x, (tuple, list)):
x = np.asarray(x)
if isinstance(x, np.ndarray) and tensor:
c = c.reshape(c.shape + (1,)*x.ndim)
if len(c) == 1:
c0 = c[0]
c1 = 0
elif len(c) == 2:
c0 = c[0]
c1 = c[1]
else:
nd = len(c)
c0 = c[-2]
c1 = c[-1]
for i in range(3, len(c) + 1):
tmp = c0
nd = nd - 1
c0 = c[-i] - (c1*(nd - 1))/nd
c1 = tmp + (c1*x*(2*nd - 1))/nd
return c0 + c1*x
def legval2d(x, y, c):
"""
Evaluate a 2-D Legendre series at points (x, y).
This function returns the values:
.. math:: p(x,y) = \\sum_{i,j} c_{i,j} * L_i(x) * L_j(y)
The parameters `x` and `y` are converted to arrays only if they are
tuples or a lists, otherwise they are treated as a scalars and they
must have the same shape after conversion. In either case, either `x`
and `y` or their elements must support multiplication and addition both
with themselves and with the elements of `c`.
If `c` is a 1-D array a one is implicitly appended to its shape to make
it 2-D. The shape of the result will be c.shape[2:] + x.shape.
Parameters
----------
x, y : array_like, compatible objects
The two dimensional series is evaluated at the points `(x, y)`,
where `x` and `y` must have the same shape. If `x` or `y` is a list
or tuple, it is first converted to an ndarray, otherwise it is left
unchanged and if it isn't an ndarray it is treated as a scalar.
c : array_like
Array of coefficients ordered so that the coefficient of the term
of multi-degree i,j is contained in ``c[i,j]``. If `c` has
dimension greater than two the remaining indices enumerate multiple
sets of coefficients.
Returns
-------
values : ndarray, compatible object
The values of the two dimensional Legendre series at points formed
from pairs of corresponding values from `x` and `y`.
See Also
--------
legval, leggrid2d, legval3d, leggrid3d
Notes
-----
.. versionadded::1.7.0
"""
try:
x, y = np.array((x, y), copy=0)
except:
raise ValueError('x, y are incompatible')
c = legval(x, c)
c = legval(y, c, tensor=False)
return c
def leggrid2d(x, y, c):
"""
Evaluate a 2-D Legendre series on the Cartesian product of x and y.
This function returns the values:
.. math:: p(a,b) = \\sum_{i,j} c_{i,j} * L_i(a) * L_j(b)
where the points `(a, b)` consist of all pairs formed by taking
`a` from `x` and `b` from `y`. The resulting points form a grid with
`x` in the first dimension and `y` in the second.
The parameters `x` and `y` are converted to arrays only if they are
tuples or a lists, otherwise they are treated as a scalars. In either
case, either `x` and `y` or their elements must support multiplication
and addition both with themselves and with the elements of `c`.
If `c` has fewer than two dimensions, ones are implicitly appended to
its shape to make it 2-D. The shape of the result will be c.shape[2:] +
x.shape + y.shape.
Parameters
----------
x, y : array_like, compatible objects
The two dimensional series is evaluated at the points in the
Cartesian product of `x` and `y`. If `x` or `y` is a list or
tuple, it is first converted to an ndarray, otherwise it is left
unchanged and, if it isn't an ndarray, it is treated as a scalar.
c : array_like
Array of coefficients ordered so that the coefficient of the term of
multi-degree i,j is contained in `c[i,j]`. If `c` has dimension
greater than two the remaining indices enumerate multiple sets of
coefficients.
Returns
-------
values : ndarray, compatible object
The values of the two dimensional Chebyshev series at points in the
Cartesian product of `x` and `y`.
See Also
--------
legval, legval2d, legval3d, leggrid3d
Notes
-----
.. versionadded::1.7.0
"""
c = legval(x, c)
c = legval(y, c)
return c
def legval3d(x, y, z, c):
"""
Evaluate a 3-D Legendre series at points (x, y, z).
This function returns the values:
.. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * L_i(x) * L_j(y) * L_k(z)
The parameters `x`, `y`, and `z` are converted to arrays only if
they are tuples or a lists, otherwise they are treated as a scalars and
they must have the same shape after conversion. In either case, either
`x`, `y`, and `z` or their elements must support multiplication and
addition both with themselves and with the elements of `c`.
If `c` has fewer than 3 dimensions, ones are implicitly appended to its
shape to make it 3-D. The shape of the result will be c.shape[3:] +
x.shape.
Parameters
----------
x, y, z : array_like, compatible object
The three dimensional series is evaluated at the points
`(x, y, z)`, where `x`, `y`, and `z` must have the same shape. If
any of `x`, `y`, or `z` is a list or tuple, it is first converted
to an ndarray, otherwise it is left unchanged and if it isn't an
ndarray it is treated as a scalar.
c : array_like
Array of coefficients ordered so that the coefficient of the term of
multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension
greater than 3 the remaining indices enumerate multiple sets of
coefficients.
Returns
-------
values : ndarray, compatible object
The values of the multidimensional polynomial on points formed with
triples of corresponding values from `x`, `y`, and `z`.
See Also
--------
legval, legval2d, leggrid2d, leggrid3d
Notes
-----
.. versionadded::1.7.0
"""
try:
x, y, z = np.array((x, y, z), copy=0)
except:
raise ValueError('x, y, z are incompatible')
c = legval(x, c)
c = legval(y, c, tensor=False)
c = legval(z, c, tensor=False)
return c
def leggrid3d(x, y, z, c):
"""
Evaluate a 3-D Legendre series on the Cartesian product of x, y, and z.
This function returns the values:
.. math:: p(a,b,c) = \\sum_{i,j,k} c_{i,j,k} * L_i(a) * L_j(b) * L_k(c)
where the points `(a, b, c)` consist of all triples formed by taking
`a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form
a grid with `x` in the first dimension, `y` in the second, and `z` in
the third.
The parameters `x`, `y`, and `z` are converted to arrays only if they
are tuples or a lists, otherwise they are treated as a scalars. In
either case, either `x`, `y`, and `z` or their elements must support
multiplication and addition both with themselves and with the elements
of `c`.
If `c` has fewer than three dimensions, ones are implicitly appended to
its shape to make it 3-D. The shape of the result will be c.shape[3:] +
x.shape + y.shape + z.shape.
Parameters
----------
x, y, z : array_like, compatible objects
The three dimensional series is evaluated at the points in the
Cartesian product of `x`, `y`, and `z`. If `x`,`y`, or `z` is a
list or tuple, it is first converted to an ndarray, otherwise it is
left unchanged and, if it isn't an ndarray, it is treated as a
scalar.
c : array_like
Array of coefficients ordered so that the coefficients for terms of
degree i,j are contained in ``c[i,j]``. If `c` has dimension
greater than two the remaining indices enumerate multiple sets of
coefficients.
Returns
-------
values : ndarray, compatible object
The values of the two dimensional polynomial at points in the Cartesian
product of `x` and `y`.
See Also
--------
legval, legval2d, leggrid2d, legval3d
Notes
-----
.. versionadded::1.7.0
"""
c = legval(x, c)
c = legval(y, c)
c = legval(z, c)
return c
def legvander(x, deg):
"""Pseudo-Vandermonde matrix of given degree.
Returns the pseudo-Vandermonde matrix of degree `deg` and sample points
`x`. The pseudo-Vandermonde matrix is defined by
.. math:: V[..., i] = L_i(x)
where `0 <= i <= deg`. The leading indices of `V` index the elements of
`x` and the last index is the degree of the Legendre polynomial.
If `c` is a 1-D array of coefficients of length `n + 1` and `V` is the
array ``V = legvander(x, n)``, then ``np.dot(V, c)`` and
``legval(x, c)`` are the same up to roundoff. This equivalence is
useful both for least squares fitting and for the evaluation of a large
number of Legendre series of the same degree and sample points.
Parameters
----------
x : array_like
Array of points. The dtype is converted to float64 or complex128
depending on whether any of the elements are complex. If `x` is
scalar it is converted to a 1-D array.
deg : int
Degree of the resulting matrix.
Returns
-------
vander : ndarray
The pseudo-Vandermonde matrix. The shape of the returned matrix is
``x.shape + (deg + 1,)``, where The last index is the degree of the
corresponding Legendre polynomial. The dtype will be the same as
the converted `x`.
"""
ideg = int(deg)
if ideg != deg:
raise ValueError("deg must be integer")
if ideg < 0:
raise ValueError("deg must be non-negative")
x = np.array(x, copy=0, ndmin=1) + 0.0
dims = (ideg + 1,) + x.shape
dtyp = x.dtype
v = np.empty(dims, dtype=dtyp)
# Use forward recursion to generate the entries. This is not as accurate
# as reverse recursion in this application but it is more efficient.
v[0] = x*0 + 1
if ideg > 0:
v[1] = x
for i in range(2, ideg + 1):
v[i] = (v[i-1]*x*(2*i - 1) - v[i-2]*(i - 1))/i
return np.rollaxis(v, 0, v.ndim)
def legvander2d(x, y, deg):
"""Pseudo-Vandermonde matrix of given degrees.
Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
points `(x, y)`. The pseudo-Vandermonde matrix is defined by
.. math:: V[..., (deg[1] + 1)*i + j] = L_i(x) * L_j(y),
where `0 <= i <= deg[0]` and `0 <= j <= deg[1]`. The leading indices of
`V` index the points `(x, y)` and the last index encodes the degrees of
the Legendre polynomials.
If ``V = legvander2d(x, y, [xdeg, ydeg])``, then the columns of `V`
correspond to the elements of a 2-D coefficient array `c` of shape
(xdeg + 1, ydeg + 1) in the order
.. math:: c_{00}, c_{01}, c_{02} ... , c_{10}, c_{11}, c_{12} ...
and ``np.dot(V, c.flat)`` and ``legval2d(x, y, c)`` will be the same
up to roundoff. This equivalence is useful both for least squares
fitting and for the evaluation of a large number of 2-D Legendre
series of the same degrees and sample points.
Parameters
----------
x, y : array_like
Arrays of point coordinates, all of the same shape. The dtypes
will be converted to either float64 or complex128 depending on
whether any of the elements are complex. Scalars are converted to
1-D arrays.
deg : list of ints
List of maximum degrees of the form [x_deg, y_deg].
Returns
-------
vander2d : ndarray
The shape of the returned matrix is ``x.shape + (order,)``, where
:math:`order = (deg[0]+1)*(deg([1]+1)`. The dtype will be the same
as the converted `x` and `y`.
See Also
--------
legvander, legvander3d. legval2d, legval3d
Notes
-----
.. versionadded::1.7.0
"""
ideg = [int(d) for d in deg]
is_valid = [id == d and id >= 0 for id, d in zip(ideg, deg)]
if is_valid != [1, 1]:
raise ValueError("degrees must be non-negative integers")
degx, degy = ideg
x, y = np.array((x, y), copy=0) + 0.0
vx = legvander(x, degx)
vy = legvander(y, degy)
v = vx[..., None]*vy[..., None,:]
return v.reshape(v.shape[:-2] + (-1,))
def legvander3d(x, y, z, deg):
"""Pseudo-Vandermonde matrix of given degrees.
Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
points `(x, y, z)`. If `l, m, n` are the given degrees in `x, y, z`,
then The pseudo-Vandermonde matrix is defined by
.. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = L_i(x)*L_j(y)*L_k(z),
where `0 <= i <= l`, `0 <= j <= m`, and `0 <= j <= n`. The leading
indices of `V` index the points `(x, y, z)` and the last index encodes
the degrees of the Legendre polynomials.
If ``V = legvander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns
of `V` correspond to the elements of a 3-D coefficient array `c` of
shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order
.. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},...
and ``np.dot(V, c.flat)`` and ``legval3d(x, y, z, c)`` will be the
same up to roundoff. This equivalence is useful both for least squares
fitting and for the evaluation of a large number of 3-D Legendre
series of the same degrees and sample points.
Parameters
----------
x, y, z : array_like
Arrays of point coordinates, all of the same shape. The dtypes will
be converted to either float64 or complex128 depending on whether
any of the elements are complex. Scalars are converted to 1-D
arrays.
deg : list of ints
List of maximum degrees of the form [x_deg, y_deg, z_deg].
Returns
-------
vander3d : ndarray
The shape of the returned matrix is ``x.shape + (order,)``, where
:math:`order = (deg[0]+1)*(deg([1]+1)*(deg[2]+1)`. The dtype will
be the same as the converted `x`, `y`, and `z`.
See Also
--------
legvander, legvander3d. legval2d, legval3d
Notes
-----
.. versionadded::1.7.0
"""
ideg = [int(d) for d in deg]
is_valid = [id == d and id >= 0 for id, d in zip(ideg, deg)]
if is_valid != [1, 1, 1]:
raise ValueError("degrees must be non-negative integers")
degx, degy, degz = ideg
x, y, z = np.array((x, y, z), copy=0) + 0.0
vx = legvander(x, degx)
vy = legvander(y, degy)
vz = legvander(z, degz)
v = vx[..., None, None]*vy[..., None,:, None]*vz[..., None, None,:]
return v.reshape(v.shape[:-3] + (-1,))
def legfit(x, y, deg, rcond=None, full=False, w=None):
"""
Least squares fit of Legendre series to data.
Return the coefficients of a Legendre series of degree `deg` that is the
least squares fit to the data values `y` given at points `x`. If `y` is
1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple
fits are done, one for each column of `y`, and the resulting
coefficients are stored in the corresponding columns of a 2-D return.
The fitted polynomial(s) are in the form
.. math:: p(x) = c_0 + c_1 * L_1(x) + ... + c_n * L_n(x),
where `n` is `deg`.
Parameters
----------
x : array_like, shape (M,)
x-coordinates of the M sample points ``(x[i], y[i])``.
y : array_like, shape (M,) or (M, K)
y-coordinates of the sample points. Several data sets of sample
points sharing the same x-coordinates can be fitted at once by
passing in a 2D-array that contains one dataset per column.
deg : int or 1-D array_like
Degree(s) of the fitting polynomials. If `deg` is a single integer
all terms up to and including the `deg`'th term are included in the
fit. For NumPy versions >= 1.11.0 a list of integers specifying the
degrees of the terms to include may be used instead.
rcond : float, optional
Relative condition number of the fit. Singular values smaller than
this relative to the largest singular value will be ignored. The
default value is len(x)*eps, where eps is the relative precision of
the float type, about 2e-16 in most cases.
full : bool, optional
Switch determining nature of return value. When it is False (the
default) just the coefficients are returned, when True diagnostic
information from the singular value decomposition is also returned.
w : array_like, shape (`M`,), optional
Weights. If not None, the contribution of each point
``(x[i],y[i])`` to the fit is weighted by `w[i]`. Ideally the
weights are chosen so that the errors of the products ``w[i]*y[i]``
all have the same variance. The default value is None.
.. versionadded:: 1.5.0
Returns
-------
coef : ndarray, shape (M,) or (M, K)
Legendre coefficients ordered from low to high. If `y` was
2-D, the coefficients for the data in column k of `y` are in
column `k`. If `deg` is specified as a list, coefficients for
terms not included in the fit are set equal to zero in the
returned `coef`.
[residuals, rank, singular_values, rcond] : list
These values are only returned if `full` = True
resid -- sum of squared residuals of the least squares fit
rank -- the numerical rank of the scaled Vandermonde matrix
sv -- singular values of the scaled Vandermonde matrix
rcond -- value of `rcond`.
For more details, see `linalg.lstsq`.
Warns
-----
RankWarning
The rank of the coefficient matrix in the least-squares fit is
deficient. The warning is only raised if `full` = False. The
warnings can be turned off by
>>> import warnings
>>> warnings.simplefilter('ignore', RankWarning)
See Also
--------
chebfit, polyfit, lagfit, hermfit, hermefit
legval : Evaluates a Legendre series.
legvander : Vandermonde matrix of Legendre series.
legweight : Legendre weight function (= 1).
linalg.lstsq : Computes a least-squares fit from the matrix.
scipy.interpolate.UnivariateSpline : Computes spline fits.
Notes
-----
The solution is the coefficients of the Legendre series `p` that
minimizes the sum of the weighted squared errors
.. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2,
where :math:`w_j` are the weights. This problem is solved by setting up
as the (typically) overdetermined matrix equation
.. math:: V(x) * c = w * y,
where `V` is the weighted pseudo Vandermonde matrix of `x`, `c` are the
coefficients to be solved for, `w` are the weights, and `y` are the
observed values. This equation is then solved using the singular value
decomposition of `V`.
If some of the singular values of `V` are so small that they are
neglected, then a `RankWarning` will be issued. This means that the
coefficient values may be poorly determined. Using a lower order fit
will usually get rid of the warning. The `rcond` parameter can also be
set to a value smaller than its default, but the resulting fit may be
spurious and have large contributions from roundoff error.
Fits using Legendre series are usually better conditioned than fits
using power series, but much can depend on the distribution of the
sample points and the smoothness of the data. If the quality of the fit
is inadequate splines may be a good alternative.
References
----------
.. [1] Wikipedia, "Curve fitting",
http://en.wikipedia.org/wiki/Curve_fitting
Examples
--------
"""
x = np.asarray(x) + 0.0
y = np.asarray(y) + 0.0
deg = np.asarray(deg)
# check arguments.
if deg.ndim > 1 or deg.dtype.kind not in 'iu' or deg.size == 0:
raise TypeError("deg must be an int or non-empty 1-D array of int")
if deg.min() < 0:
raise ValueError("expected deg >= 0")
if x.ndim != 1:
raise TypeError("expected 1D vector for x")
if x.size == 0:
raise TypeError("expected non-empty vector for x")
if y.ndim < 1 or y.ndim > 2:
raise TypeError("expected 1D or 2D array for y")
if len(x) != len(y):
raise TypeError("expected x and y to have same length")
if deg.ndim == 0:
lmax = deg
order = lmax + 1
van = legvander(x, lmax)
else:
deg = np.sort(deg)
lmax = deg[-1]
order = len(deg)
van = legvander(x, lmax)[:, deg]
# set up the least squares matrices in transposed form
lhs = van.T
rhs = y.T
if w is not None:
w = np.asarray(w) + 0.0
if w.ndim != 1:
raise TypeError("expected 1D vector for w")
if len(x) != len(w):
raise TypeError("expected x and w to have same length")
# apply weights. Don't use inplace operations as they
# can cause problems with NA.
lhs = lhs * w
rhs = rhs * w
# set rcond
if rcond is None:
rcond = len(x)*np.finfo(x.dtype).eps
# Determine the norms of the design matrix columns.
if issubclass(lhs.dtype.type, np.complexfloating):
scl = np.sqrt((np.square(lhs.real) + np.square(lhs.imag)).sum(1))
else:
scl = np.sqrt(np.square(lhs).sum(1))
scl[scl == 0] = 1
# Solve the least squares problem.
c, resids, rank, s = la.lstsq(lhs.T/scl, rhs.T, rcond)
c = (c.T/scl).T
# Expand c to include non-fitted coefficients which are set to zero
if deg.ndim > 0:
if c.ndim == 2:
cc = np.zeros((lmax+1, c.shape[1]), dtype=c.dtype)
else:
cc = np.zeros(lmax+1, dtype=c.dtype)
cc[deg] = c
c = cc
# warn on rank reduction
if rank != order and not full:
msg = "The fit may be poorly conditioned"
warnings.warn(msg, pu.RankWarning, stacklevel=2)
if full:
return c, [resids, rank, s, rcond]
else:
return c
def legcompanion(c):
"""Return the scaled companion matrix of c.
The basis polynomials are scaled so that the companion matrix is
symmetric when `c` is an Legendre basis polynomial. This provides
better eigenvalue estimates than the unscaled case and for basis
polynomials the eigenvalues are guaranteed to be real if
`numpy.linalg.eigvalsh` is used to obtain them.
Parameters
----------
c : array_like
1-D array of Legendre series coefficients ordered from low to high
degree.
Returns
-------
mat : ndarray
Scaled companion matrix of dimensions (deg, deg).
Notes
-----
.. versionadded::1.7.0
"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
raise ValueError('Series must have maximum degree of at least 1.')
if len(c) == 2:
return np.array([[-c[0]/c[1]]])
n = len(c) - 1
mat = np.zeros((n, n), dtype=c.dtype)
scl = 1./np.sqrt(2*np.arange(n) + 1)
top = mat.reshape(-1)[1::n+1]
bot = mat.reshape(-1)[n::n+1]
top[...] = np.arange(1, n)*scl[:n-1]*scl[1:n]
bot[...] = top
mat[:, -1] -= (c[:-1]/c[-1])*(scl/scl[-1])*(n/(2*n - 1))
return mat
def legroots(c):
"""
Compute the roots of a Legendre series.
Return the roots (a.k.a. "zeros") of the polynomial
.. math:: p(x) = \\sum_i c[i] * L_i(x).
Parameters
----------
c : 1-D array_like
1-D array of coefficients.
Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then `out` is also real, otherwise it is complex.
See Also
--------
polyroots, chebroots, lagroots, hermroots, hermeroots
Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such values.
Roots with multiplicity greater than 1 will also show larger errors as
the value of the series near such points is relatively insensitive to
errors in the roots. Isolated roots near the origin can be improved by
a few iterations of Newton's method.
The Legendre series basis polynomials aren't powers of ``x`` so the
results of this function may seem unintuitive.
Examples
--------
>>> import numpy.polynomial.legendre as leg
>>> leg.legroots((1, 2, 3, 4)) # 4L_3 + 3L_2 + 2L_1 + 1L_0, all real roots
array([-0.85099543, -0.11407192, 0.51506735])
"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])
m = legcompanion(c)
r = la.eigvals(m)
r.sort()
return r
def leggauss(deg):
"""
Gauss-Legendre quadrature.
Computes the sample points and weights for Gauss-Legendre quadrature.
These sample points and weights will correctly integrate polynomials of
degree :math:`2*deg - 1` or less over the interval :math:`[-1, 1]` with
the weight function :math:`f(x) = 1`.
Parameters
----------
deg : int
Number of sample points and weights. It must be >= 1.
Returns
-------
x : ndarray
1-D ndarray containing the sample points.
y : ndarray
1-D ndarray containing the weights.
Notes
-----
.. versionadded::1.7.0
The results have only been tested up to degree 100, higher degrees may
be problematic. The weights are determined by using the fact that
.. math:: w_k = c / (L'_n(x_k) * L_{n-1}(x_k))
where :math:`c` is a constant independent of :math:`k` and :math:`x_k`
is the k'th root of :math:`L_n`, and then scaling the results to get
the right value when integrating 1.
"""
ideg = int(deg)
if ideg != deg or ideg < 1:
raise ValueError("deg must be a non-negative integer")
# first approximation of roots. We use the fact that the companion
# matrix is symmetric in this case in order to obtain better zeros.
c = np.array([0]*deg + [1])
m = legcompanion(c)
x = la.eigvalsh(m)
# improve roots by one application of Newton
dy = legval(x, c)
df = legval(x, legder(c))
x -= dy/df
# compute the weights. We scale the factor to avoid possible numerical
# overflow.
fm = legval(x, c[1:])
fm /= np.abs(fm).max()
df /= np.abs(df).max()
w = 1/(fm * df)
# for Legendre we can also symmetrize
w = (w + w[::-1])/2
x = (x - x[::-1])/2
# scale w to get the right value
w *= 2. / w.sum()
return x, w
def legweight(x):
"""
Weight function of the Legendre polynomials.
The weight function is :math:`1` and the interval of integration is
:math:`[-1, 1]`. The Legendre polynomials are orthogonal, but not
normalized, with respect to this weight function.
Parameters
----------
x : array_like
Values at which the weight function will be computed.
Returns
-------
w : ndarray
The weight function at `x`.
Notes
-----
.. versionadded::1.7.0
"""
w = x*0.0 + 1.0
return w
#
# Legendre series class
#
class Legendre(ABCPolyBase):
"""A Legendre series class.
The Legendre class provides the standard Python numerical methods
'+', '-', '*', '//', '%', 'divmod', '**', and '()' as well as the
attributes and methods listed in the `ABCPolyBase` documentation.
Parameters
----------
coef : array_like
Legendre coefficients in order of increasing degree, i.e.,
``(1, 2, 3)`` gives ``1*P_0(x) + 2*P_1(x) + 3*P_2(x)``.
domain : (2,) array_like, optional
Domain to use. The interval ``[domain[0], domain[1]]`` is mapped
to the interval ``[window[0], window[1]]`` by shifting and scaling.
The default value is [-1, 1].
window : (2,) array_like, optional
Window, see `domain` for its use. The default value is [-1, 1].
.. versionadded:: 1.6.0
"""
# Virtual Functions
_add = staticmethod(legadd)
_sub = staticmethod(legsub)
_mul = staticmethod(legmul)
_div = staticmethod(legdiv)
_pow = staticmethod(legpow)
_val = staticmethod(legval)
_int = staticmethod(legint)
_der = staticmethod(legder)
_fit = staticmethod(legfit)
_line = staticmethod(legline)
_roots = staticmethod(legroots)
_fromroots = staticmethod(legfromroots)
# Virtual properties
nickname = 'leg'
domain = np.array(legdomain)
window = np.array(legdomain)
|
bsd-3-clause
|
[
624,
199,
23439,
264,
12403,
18479,
1494,
26,
658,
4714,
14,
22104,
14,
10231,
264,
10522,
199,
12813,
5918,
199,
199,
703,
1453,
578,
447,
2680,
14,
22104,
14,
22104,
199,
199,
2765,
859,
6571,
282,
1329,
402,
2251,
334,
2786,
590,
3423,
9,
2997,
367,
199,
21245,
316,
543,
29420,
6779,
12,
5893,
282,
658,
23439,
264,
64,
1021,
626,
199,
287,
12029,
15409,
314,
20195,
24166,
5331,
14,
221,
334,
14109,
2556,
199,
265,
4212,
642,
859,
8469,
436,
5419,
543,
4066,
27599,
365,
315,
314,
199,
12485,
367,
2399,
298,
1708,
2,
1007,
13,
2491,
12,
658,
4714,
14,
22104,
14963,
199,
199,
22185,
199,
9960,
199,
199,
703,
26651,
29309,
447,
2043,
520,
475,
16970,
26,
4046,
15,
8410,
6768,
2261,
3322,
29420,
6779,
849,
2881,
12,
5243,
17,
12,
17,
1055,
2043,
6768,
4262,
4519,
29420,
6779,
626,
22014,
6120,
17269,
370,
378,
14,
2043,
6768,
368,
5185,
29420,
6779,
626,
22014,
6120,
17269,
370,
413,
14,
2043,
6768,
88,
463,
29420,
6779,
367,
314,
8503,
2341,
12,
1124,
70,
8,
88,
9,
275,
671,
4345,
199,
199,
26291,
18764,
199,
9460,
199,
199,
703,
26651,
29309,
447,
2043,
520,
475,
16970,
26,
4046,
15,
8410,
6768,
3703,
88,
4519,
21699,
282,
29420,
6779,
315,
510,
63,
73,
8,
88,
9,
701,
671,
14,
2043,
6768,
525,
5185,
1050,
2877,
29420,
6779,
14,
2043,
1026,
458,
456,
5185,
24129,
1373,
29420,
6779,
687,
4573,
14,
2043,
6768,
3703,
5185,
21699,
2877,
29420,
6779,
14,
2043,
6768,
3015,
5185,
23003,
1373,
29420,
6779,
701,
4573,
14,
2043,
6768,
8278,
5185,
746,
282,
29420,
6779,
370,
376,
7317,
3000,
7074,
2043,
6768,
637,
5185,
9352,
282,
29420,
6779,
737,
1627,
4501,
14,
2043,
6768,
637,
18,
68,
3777,
9352,
282,
499,
36,
29420,
6779,
737,
1627,
4501,
14,
2043,
6768,
637,
19,
68,
3777,
9352,
282,
650,
36,
29420,
6779,
737,
1627,
4501,
14,
2043,
1026,
2721,
1677,
18,
68,
3322,
9352,
282,
499,
36,
29420,
6779,
641,
282,
14243,
19157,
3336,
14,
2043,
1026,
2721,
1677,
19,
68,
3322,
9352,
282,
650,
36,
29420,
6779,
641,
282,
14243,
19157,
3336,
14,
199,
199,
13862,
527,
199,
518,
199,
199,
703,
26651,
29309,
447,
2043,
520,
475,
16970,
26,
4046,
15,
8410,
6768,
424,
5185,
26796,
323,
282,
29420,
6779,
14,
2043,
6768,
442,
5185,
21494,
282,
29420,
6779,
14,
199,
199,
29926,
17471,
199,
10965,
199,
199,
703,
26651,
29309,
447,
2043,
520,
475,
16970,
26,
4046,
15,
8410,
6768,
504,
12065,
3515,
1218,
282,
29420,
6779,
543,
2013,
14361,
14,
2043,
6768,
12065,
4519,
2342,
314,
14361,
402,
282,
29420,
6779,
14,
2043,
6768,
86,
11438,
3777,
812,
11438,
2106,
271,
13,
2930,
3634,
367,
29420,
27599,
14,
2043,
6768,
86,
11438,
18,
68,
3698,
812,
11438,
2106,
271,
13,
2930,
3634,
367,
499,
36,
7074,
6779,
14,
2043,
6768,
86,
11438,
19,
68,
3698,
812,
11438,
2106,
271,
13,
2930,
3634,
367,
650,
36,
7074,
6779,
14,
2043,
1026,
2721,
23822,
4519,
598,
23822,
13,
23439,
264,
16744,
30985,
12,
4501,
436,
4931,
14,
2043,
6768,
3463,
3777,
29420,
5401,
805,
14,
2043,
6768,
863,
32012,
3515,
4678,
3318,
7068,
1013,
32012,
3634,
315,
29420,
1824,
14,
2043,
6768,
3269,
4483,
5210,
13,
20956,
5542,
8152,
282,
29420,
6779,
14,
2043,
6768,
12263,
5185,
11639,
9186,
12343,
687,
282,
29420,
6779,
14,
2043,
6768,
604,
5185,
29420,
6779,
6144,
1627,
23669,
1004,
14,
2043,
6768,
18,
6023,
4519,
3957,
282,
29420,
6779,
370,
282,
11849,
14,
2043,
8446,
18,
4170,
4519,
3957,
282,
11849,
370,
282,
29420,
6779,
14,
199,
199,
15711,
199,
12797,
272,
29420,
3322,
437,
29420,
6779,
1021,
14,
199,
199,
9295,
2597,
199,
518,
199,
4714,
14,
22104,
14,
22104,
199,
4714,
14,
22104,
14,
25820,
27185,
199,
4714,
14,
22104,
14,
1823,
32302,
199,
4714,
14,
22104,
14,
2523,
19130,
199,
4714,
14,
22104,
14,
2523,
19130,
63,
69,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
3598,
199,
646,
2680,
465,
980,
199,
646,
2680,
14,
10096,
465,
1127,
199,
504,
2680,
14,
1018,
14,
23698,
492,
7666,
63,
3127,
63,
1080,
199,
199,
504,
1275,
492,
8446,
1208,
465,
18848,
199,
504,
13653,
6023,
1095,
492,
14840,
2890,
16242,
1563,
199,
199,
363,
452,
363,
275,
359,
272,
283,
4170,
4262,
297,
283,
4170,
368,
297,
283,
4170,
88,
297,
283,
4170,
2261,
297,
283,
4170,
604,
297,
283,
4170,
525,
297,
272,
283,
274,
458,
456,
297,
283,
4170,
3703,
88,
297,
283,
4170,
3703,
297,
283,
4170,
3015,
297,
283,
4170,
8278,
297,
283,
4170,
637,
297,
283,
4170,
424,
297,
272,
283,
4170,
442,
297,
283,
4170,
18,
6023,
297,
283,
6023,
18,
4170,
297,
283,
4170,
504,
12065,
297,
283,
4170,
86,
11438,
297,
272,
283,
4170,
3269,
297,
283,
4170,
12263,
297,
283,
4170,
12065,
297,
283,
23439,
264,
297,
283,
4170,
637,
18,
68,
297,
283,
4170,
637,
19,
68,
297,
272,
283,
274,
2721,
1677,
18,
68,
297,
283,
274,
2721,
1677,
19,
68,
297,
283,
4170,
86,
11438,
18,
68,
297,
283,
4170,
86,
11438,
19,
68,
297,
283,
4170,
863,
32012,
297,
272,
283,
274,
2721,
23822,
297,
283,
4170,
3463,
418,
199,
199,
4170,
12263,
275,
18848,
14,
12263,
8009,
421,
199,
318,
8446,
18,
4170,
8,
2515,
304,
272,
408,
272,
7905,
282,
11849,
370,
282,
29420,
6779,
14,
339,
7905,
376,
1625,
6144,
314,
12343,
402,
282,
11849,
334,
6188,
272,
370,
314,
298,
6807,
2,
5597,
9,
7741,
687,
18966,
13666,
370,
15356,
12,
370,
376,
272,
1625,
402,
314,
12343,
402,
314,
7353,
29420,
6779,
12,
7741,
272,
687,
18966,
370,
15356,
13666,
14,
339,
3897,
272,
4143,
272,
3708,
520,
1625,
63,
2930,
267,
413,
13,
36,
1625,
3035,
314,
11849,
12343,
339,
1803,
272,
5514,
272,
286,
520,
6800,
267,
413,
13,
36,
1625,
3035,
314,
12343,
402,
314,
7353,
29420,
267,
6779,
14,
339,
1666,
6121,
272,
3001,
272,
6768,
18,
6023,
339,
8144,
272,
9063,
272,
710,
8837,
4340,
370,
886,
24796,
3382,
11849,
5597,
5951,
272,
365,
370,
675
] |
[
199,
23439,
264,
12403,
18479,
1494,
26,
658,
4714,
14,
22104,
14,
10231,
264,
10522,
199,
12813,
5918,
199,
199,
703,
1453,
578,
447,
2680,
14,
22104,
14,
22104,
199,
199,
2765,
859,
6571,
282,
1329,
402,
2251,
334,
2786,
590,
3423,
9,
2997,
367,
199,
21245,
316,
543,
29420,
6779,
12,
5893,
282,
658,
23439,
264,
64,
1021,
626,
199,
287,
12029,
15409,
314,
20195,
24166,
5331,
14,
221,
334,
14109,
2556,
199,
265,
4212,
642,
859,
8469,
436,
5419,
543,
4066,
27599,
365,
315,
314,
199,
12485,
367,
2399,
298,
1708,
2,
1007,
13,
2491,
12,
658,
4714,
14,
22104,
14963,
199,
199,
22185,
199,
9960,
199,
199,
703,
26651,
29309,
447,
2043,
520,
475,
16970,
26,
4046,
15,
8410,
6768,
2261,
3322,
29420,
6779,
849,
2881,
12,
5243,
17,
12,
17,
1055,
2043,
6768,
4262,
4519,
29420,
6779,
626,
22014,
6120,
17269,
370,
378,
14,
2043,
6768,
368,
5185,
29420,
6779,
626,
22014,
6120,
17269,
370,
413,
14,
2043,
6768,
88,
463,
29420,
6779,
367,
314,
8503,
2341,
12,
1124,
70,
8,
88,
9,
275,
671,
4345,
199,
199,
26291,
18764,
199,
9460,
199,
199,
703,
26651,
29309,
447,
2043,
520,
475,
16970,
26,
4046,
15,
8410,
6768,
3703,
88,
4519,
21699,
282,
29420,
6779,
315,
510,
63,
73,
8,
88,
9,
701,
671,
14,
2043,
6768,
525,
5185,
1050,
2877,
29420,
6779,
14,
2043,
1026,
458,
456,
5185,
24129,
1373,
29420,
6779,
687,
4573,
14,
2043,
6768,
3703,
5185,
21699,
2877,
29420,
6779,
14,
2043,
6768,
3015,
5185,
23003,
1373,
29420,
6779,
701,
4573,
14,
2043,
6768,
8278,
5185,
746,
282,
29420,
6779,
370,
376,
7317,
3000,
7074,
2043,
6768,
637,
5185,
9352,
282,
29420,
6779,
737,
1627,
4501,
14,
2043,
6768,
637,
18,
68,
3777,
9352,
282,
499,
36,
29420,
6779,
737,
1627,
4501,
14,
2043,
6768,
637,
19,
68,
3777,
9352,
282,
650,
36,
29420,
6779,
737,
1627,
4501,
14,
2043,
1026,
2721,
1677,
18,
68,
3322,
9352,
282,
499,
36,
29420,
6779,
641,
282,
14243,
19157,
3336,
14,
2043,
1026,
2721,
1677,
19,
68,
3322,
9352,
282,
650,
36,
29420,
6779,
641,
282,
14243,
19157,
3336,
14,
199,
199,
13862,
527,
199,
518,
199,
199,
703,
26651,
29309,
447,
2043,
520,
475,
16970,
26,
4046,
15,
8410,
6768,
424,
5185,
26796,
323,
282,
29420,
6779,
14,
2043,
6768,
442,
5185,
21494,
282,
29420,
6779,
14,
199,
199,
29926,
17471,
199,
10965,
199,
199,
703,
26651,
29309,
447,
2043,
520,
475,
16970,
26,
4046,
15,
8410,
6768,
504,
12065,
3515,
1218,
282,
29420,
6779,
543,
2013,
14361,
14,
2043,
6768,
12065,
4519,
2342,
314,
14361,
402,
282,
29420,
6779,
14,
2043,
6768,
86,
11438,
3777,
812,
11438,
2106,
271,
13,
2930,
3634,
367,
29420,
27599,
14,
2043,
6768,
86,
11438,
18,
68,
3698,
812,
11438,
2106,
271,
13,
2930,
3634,
367,
499,
36,
7074,
6779,
14,
2043,
6768,
86,
11438,
19,
68,
3698,
812,
11438,
2106,
271,
13,
2930,
3634,
367,
650,
36,
7074,
6779,
14,
2043,
1026,
2721,
23822,
4519,
598,
23822,
13,
23439,
264,
16744,
30985,
12,
4501,
436,
4931,
14,
2043,
6768,
3463,
3777,
29420,
5401,
805,
14,
2043,
6768,
863,
32012,
3515,
4678,
3318,
7068,
1013,
32012,
3634,
315,
29420,
1824,
14,
2043,
6768,
3269,
4483,
5210,
13,
20956,
5542,
8152,
282,
29420,
6779,
14,
2043,
6768,
12263,
5185,
11639,
9186,
12343,
687,
282,
29420,
6779,
14,
2043,
6768,
604,
5185,
29420,
6779,
6144,
1627,
23669,
1004,
14,
2043,
6768,
18,
6023,
4519,
3957,
282,
29420,
6779,
370,
282,
11849,
14,
2043,
8446,
18,
4170,
4519,
3957,
282,
11849,
370,
282,
29420,
6779,
14,
199,
199,
15711,
199,
12797,
272,
29420,
3322,
437,
29420,
6779,
1021,
14,
199,
199,
9295,
2597,
199,
518,
199,
4714,
14,
22104,
14,
22104,
199,
4714,
14,
22104,
14,
25820,
27185,
199,
4714,
14,
22104,
14,
1823,
32302,
199,
4714,
14,
22104,
14,
2523,
19130,
199,
4714,
14,
22104,
14,
2523,
19130,
63,
69,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
3598,
199,
646,
2680,
465,
980,
199,
646,
2680,
14,
10096,
465,
1127,
199,
504,
2680,
14,
1018,
14,
23698,
492,
7666,
63,
3127,
63,
1080,
199,
199,
504,
1275,
492,
8446,
1208,
465,
18848,
199,
504,
13653,
6023,
1095,
492,
14840,
2890,
16242,
1563,
199,
199,
363,
452,
363,
275,
359,
272,
283,
4170,
4262,
297,
283,
4170,
368,
297,
283,
4170,
88,
297,
283,
4170,
2261,
297,
283,
4170,
604,
297,
283,
4170,
525,
297,
272,
283,
274,
458,
456,
297,
283,
4170,
3703,
88,
297,
283,
4170,
3703,
297,
283,
4170,
3015,
297,
283,
4170,
8278,
297,
283,
4170,
637,
297,
283,
4170,
424,
297,
272,
283,
4170,
442,
297,
283,
4170,
18,
6023,
297,
283,
6023,
18,
4170,
297,
283,
4170,
504,
12065,
297,
283,
4170,
86,
11438,
297,
272,
283,
4170,
3269,
297,
283,
4170,
12263,
297,
283,
4170,
12065,
297,
283,
23439,
264,
297,
283,
4170,
637,
18,
68,
297,
283,
4170,
637,
19,
68,
297,
272,
283,
274,
2721,
1677,
18,
68,
297,
283,
274,
2721,
1677,
19,
68,
297,
283,
4170,
86,
11438,
18,
68,
297,
283,
4170,
86,
11438,
19,
68,
297,
283,
4170,
863,
32012,
297,
272,
283,
274,
2721,
23822,
297,
283,
4170,
3463,
418,
199,
199,
4170,
12263,
275,
18848,
14,
12263,
8009,
421,
199,
318,
8446,
18,
4170,
8,
2515,
304,
272,
408,
272,
7905,
282,
11849,
370,
282,
29420,
6779,
14,
339,
7905,
376,
1625,
6144,
314,
12343,
402,
282,
11849,
334,
6188,
272,
370,
314,
298,
6807,
2,
5597,
9,
7741,
687,
18966,
13666,
370,
15356,
12,
370,
376,
272,
1625,
402,
314,
12343,
402,
314,
7353,
29420,
6779,
12,
7741,
272,
687,
18966,
370,
15356,
13666,
14,
339,
3897,
272,
4143,
272,
3708,
520,
1625,
63,
2930,
267,
413,
13,
36,
1625,
3035,
314,
11849,
12343,
339,
1803,
272,
5514,
272,
286,
520,
6800,
267,
413,
13,
36,
1625,
3035,
314,
12343,
402,
314,
7353,
29420,
267,
6779,
14,
339,
1666,
6121,
272,
3001,
272,
6768,
18,
6023,
339,
8144,
272,
9063,
272,
710,
8837,
4340,
370,
886,
24796,
3382,
11849,
5597,
5951,
272,
365,
370,
675,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ShassAro/ShassAro
|
Bl_project/blVirtualEnv/lib/python2.7/site-packages/django/core/serializers/pyyaml.py
|
115
|
2635
|
"""
YAML serializer.
Requires PyYaml (http://pyyaml.org/), but that's checked for in __init__.
"""
import decimal
import yaml
import sys
from io import StringIO
from django.db import models
from django.core.serializers.base import DeserializationError
from django.core.serializers.python import Serializer as PythonSerializer
from django.core.serializers.python import Deserializer as PythonDeserializer
from django.utils import six
# Use the C (faster) implementation if possible
try:
from yaml import CSafeLoader as SafeLoader
from yaml import CSafeDumper as SafeDumper
except ImportError:
from yaml import SafeLoader, SafeDumper
class DjangoSafeDumper(SafeDumper):
def represent_decimal(self, data):
return self.represent_scalar('tag:yaml.org,2002:str', str(data))
DjangoSafeDumper.add_representer(decimal.Decimal, DjangoSafeDumper.represent_decimal)
class Serializer(PythonSerializer):
"""
Convert a queryset to YAML.
"""
internal_use_only = False
def handle_field(self, obj, field):
# A nasty special case: base YAML doesn't support serialization of time
# types (as opposed to dates or datetimes, which it does support). Since
# we want to use the "safe" serializer for better interoperability, we
# need to do something with those pesky times. Converting 'em to strings
# isn't perfect, but it's better than a "!!python/time" type which would
# halt deserialization under any other language.
if isinstance(field, models.TimeField) and getattr(obj, field.name) is not None:
self._current[field.name] = str(getattr(obj, field.name))
else:
super(Serializer, self).handle_field(obj, field)
def end_serialization(self):
yaml.dump(self.objects, self.stream, Dumper=DjangoSafeDumper, **self.options)
def getvalue(self):
# Grand-parent super
return super(PythonSerializer, self).getvalue()
def Deserializer(stream_or_string, **options):
"""
Deserialize a stream or string of YAML data.
"""
if isinstance(stream_or_string, bytes):
stream_or_string = stream_or_string.decode('utf-8')
if isinstance(stream_or_string, six.string_types):
stream = StringIO(stream_or_string)
else:
stream = stream_or_string
try:
for obj in PythonDeserializer(yaml.load(stream, Loader=SafeLoader), **options):
yield obj
except GeneratorExit:
raise
except Exception as e:
# Map to deserializer error
six.reraise(DeserializationError, DeserializationError(e), sys.exc_info()[2])
|
gpl-2.0
|
[
624,
199,
23103,
9146,
14,
199,
199,
18153,
1611,
57,
3935,
334,
1014,
921,
647,
5963,
14,
1308,
15,
395,
1325,
626,
1159,
7923,
367,
315,
636,
826,
4343,
199,
624,
199,
199,
646,
6107,
199,
646,
8864,
199,
646,
984,
199,
504,
5890,
492,
5228,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1018,
14,
12844,
14,
1095,
492,
1487,
12161,
547,
199,
504,
1639,
14,
1018,
14,
12844,
14,
1548,
492,
25555,
465,
2018,
7299,
199,
504,
1639,
14,
1018,
14,
12844,
14,
1548,
492,
1487,
8349,
465,
2018,
872,
8349,
199,
504,
1639,
14,
1208,
492,
3816,
199,
199,
3,
3645,
314,
445,
334,
70,
2311,
9,
4514,
340,
3962,
199,
893,
26,
272,
687,
8864,
492,
445,
11090,
5455,
465,
14969,
5455,
272,
687,
8864,
492,
445,
11090,
28593,
465,
14969,
28593,
199,
2590,
3545,
26,
272,
687,
8864,
492,
14969,
5455,
12,
14969,
28593,
421,
199,
533,
5634,
11090,
28593,
8,
11090,
28593,
304,
272,
347,
2954,
63,
6355,
8,
277,
12,
666,
304,
267,
372,
291,
14,
13063,
63,
7033,
360,
1450,
26,
5963,
14,
1308,
12,
15135,
26,
495,
297,
620,
8,
576,
430,
199,
199,
9323,
11090,
28593,
14,
525,
63,
264,
22682,
8,
6355,
14,
6745,
12,
5634,
11090,
28593,
14,
13063,
63,
6355,
9,
421,
199,
533,
25555,
8,
4718,
7299,
304,
272,
408,
272,
7905,
282,
7594,
370,
18916,
14,
272,
408,
339,
5007,
63,
1180,
63,
2118,
275,
756,
339,
347,
2429,
63,
698,
8,
277,
12,
1559,
12,
901,
304,
267,
327,
437,
302,
27352,
4539,
1930,
26,
1300,
18916,
3181,
1133,
2291,
16953,
402,
900,
267,
327,
2943,
334,
305,
25068,
370,
10831,
503,
29297,
12,
1314,
652,
1630,
2291,
680,
9336,
267,
327,
781,
2934,
370,
675,
314,
298,
3489,
2,
9146,
367,
8034,
4661,
9198,
3616,
12,
781,
267,
327,
1929,
370,
886,
6020,
543,
5204,
299,
397,
10562,
5431,
14,
23258,
283,
5633,
370,
3326,
267,
327,
5712,
1133,
23668,
12,
1325,
652,
1159,
8034,
2419,
282,
298,
3480,
1548,
15,
521,
2,
730,
1314,
3955,
267,
327,
394,
4478,
477,
12161,
1334,
1263,
1163,
2637,
14,
267,
340,
1228,
8,
698,
12,
1709,
14,
27115,
9,
436,
2519,
8,
1113,
12,
901,
14,
354,
9,
365,
440,
488,
26,
288,
291,
423,
1818,
59,
698,
14,
354,
61,
275,
620,
8,
5675,
8,
1113,
12,
901,
14,
354,
430,
267,
587,
26,
288,
1613,
8,
7299,
12,
291,
680,
2479,
63,
698,
8,
1113,
12,
901,
9,
339,
347,
1284,
63,
12161,
8,
277,
304,
267,
8864,
14,
2724,
8,
277,
14,
1462,
12,
291,
14,
1745,
12,
19460,
281,
29,
9323,
11090,
28593,
12,
1011,
277,
14,
1419,
9,
339,
347,
664,
585,
8,
277,
304,
267,
327,
598,
3759,
13,
1708,
1613,
267,
372,
1613,
8,
4718,
7299,
12,
291,
680,
7150,
342,
421,
199,
318,
1487,
8349,
8,
1745,
63,
269,
63,
875,
12,
1011,
1419,
304,
272,
408,
272,
1487,
3549,
282,
2547,
503,
1059,
402,
18916,
666,
14,
272,
408,
272,
340,
1228,
8,
1745,
63,
269,
63,
875,
12,
2783,
304,
267,
2547,
63,
269,
63,
875,
275,
2547,
63,
269,
63,
875,
14,
2708,
360,
1624,
13,
24,
358,
272,
340,
1228,
8,
1745,
63,
269,
63,
875,
12,
3816,
14,
875,
63,
1313,
304,
267,
2547,
275,
5228,
8,
1745,
63,
269,
63,
875,
9,
272,
587,
26,
267,
2547,
275,
2547,
63,
269,
63,
875,
272,
862,
26,
267,
367,
1559,
315,
2018,
872,
8349,
8,
5963,
14,
912,
8,
1745,
12,
22865,
29,
11090,
5455,
395,
1011,
1419,
304,
288,
1995,
1559,
272,
871,
15042,
6699,
26,
267,
746,
272,
871,
2186,
465,
325,
26,
267,
327,
9672,
370,
30237,
1125,
267,
3816,
14,
20614,
8,
872,
12161,
547,
12,
1487,
12161,
547,
8,
69,
395,
984,
14,
2804,
63,
815,
3430,
18,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
23103,
9146,
14,
199,
199,
18153,
1611,
57,
3935,
334,
1014,
921,
647,
5963,
14,
1308,
15,
395,
1325,
626,
1159,
7923,
367,
315,
636,
826,
4343,
199,
624,
199,
199,
646,
6107,
199,
646,
8864,
199,
646,
984,
199,
504,
5890,
492,
5228,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1018,
14,
12844,
14,
1095,
492,
1487,
12161,
547,
199,
504,
1639,
14,
1018,
14,
12844,
14,
1548,
492,
25555,
465,
2018,
7299,
199,
504,
1639,
14,
1018,
14,
12844,
14,
1548,
492,
1487,
8349,
465,
2018,
872,
8349,
199,
504,
1639,
14,
1208,
492,
3816,
199,
199,
3,
3645,
314,
445,
334,
70,
2311,
9,
4514,
340,
3962,
199,
893,
26,
272,
687,
8864,
492,
445,
11090,
5455,
465,
14969,
5455,
272,
687,
8864,
492,
445,
11090,
28593,
465,
14969,
28593,
199,
2590,
3545,
26,
272,
687,
8864,
492,
14969,
5455,
12,
14969,
28593,
421,
199,
533,
5634,
11090,
28593,
8,
11090,
28593,
304,
272,
347,
2954,
63,
6355,
8,
277,
12,
666,
304,
267,
372,
291,
14,
13063,
63,
7033,
360,
1450,
26,
5963,
14,
1308,
12,
15135,
26,
495,
297,
620,
8,
576,
430,
199,
199,
9323,
11090,
28593,
14,
525,
63,
264,
22682,
8,
6355,
14,
6745,
12,
5634,
11090,
28593,
14,
13063,
63,
6355,
9,
421,
199,
533,
25555,
8,
4718,
7299,
304,
272,
408,
272,
7905,
282,
7594,
370,
18916,
14,
272,
408,
339,
5007,
63,
1180,
63,
2118,
275,
756,
339,
347,
2429,
63,
698,
8,
277,
12,
1559,
12,
901,
304,
267,
327,
437,
302,
27352,
4539,
1930,
26,
1300,
18916,
3181,
1133,
2291,
16953,
402,
900,
267,
327,
2943,
334,
305,
25068,
370,
10831,
503,
29297,
12,
1314,
652,
1630,
2291,
680,
9336,
267,
327,
781,
2934,
370,
675,
314,
298,
3489,
2,
9146,
367,
8034,
4661,
9198,
3616,
12,
781,
267,
327,
1929,
370,
886,
6020,
543,
5204,
299,
397,
10562,
5431,
14,
23258,
283,
5633,
370,
3326,
267,
327,
5712,
1133,
23668,
12,
1325,
652,
1159,
8034,
2419,
282,
298,
3480,
1548,
15,
521,
2,
730,
1314,
3955,
267,
327,
394,
4478,
477,
12161,
1334,
1263,
1163,
2637,
14,
267,
340,
1228,
8,
698,
12,
1709,
14,
27115,
9,
436,
2519,
8,
1113,
12,
901,
14,
354,
9,
365,
440,
488,
26,
288,
291,
423,
1818,
59,
698,
14,
354,
61,
275,
620,
8,
5675,
8,
1113,
12,
901,
14,
354,
430,
267,
587,
26,
288,
1613,
8,
7299,
12,
291,
680,
2479,
63,
698,
8,
1113,
12,
901,
9,
339,
347,
1284,
63,
12161,
8,
277,
304,
267,
8864,
14,
2724,
8,
277,
14,
1462,
12,
291,
14,
1745,
12,
19460,
281,
29,
9323,
11090,
28593,
12,
1011,
277,
14,
1419,
9,
339,
347,
664,
585,
8,
277,
304,
267,
327,
598,
3759,
13,
1708,
1613,
267,
372,
1613,
8,
4718,
7299,
12,
291,
680,
7150,
342,
421,
199,
318,
1487,
8349,
8,
1745,
63,
269,
63,
875,
12,
1011,
1419,
304,
272,
408,
272,
1487,
3549,
282,
2547,
503,
1059,
402,
18916,
666,
14,
272,
408,
272,
340,
1228,
8,
1745,
63,
269,
63,
875,
12,
2783,
304,
267,
2547,
63,
269,
63,
875,
275,
2547,
63,
269,
63,
875,
14,
2708,
360,
1624,
13,
24,
358,
272,
340,
1228,
8,
1745,
63,
269,
63,
875,
12,
3816,
14,
875,
63,
1313,
304,
267,
2547,
275,
5228,
8,
1745,
63,
269,
63,
875,
9,
272,
587,
26,
267,
2547,
275,
2547,
63,
269,
63,
875,
272,
862,
26,
267,
367,
1559,
315,
2018,
872,
8349,
8,
5963,
14,
912,
8,
1745,
12,
22865,
29,
11090,
5455,
395,
1011,
1419,
304,
288,
1995,
1559,
272,
871,
15042,
6699,
26,
267,
746,
272,
871,
2186,
465,
325,
26,
267,
327,
9672,
370,
30237,
1125,
267,
3816,
14,
20614,
8,
872,
12161,
547,
12,
1487,
12161,
547,
8,
69,
395,
984,
14,
2804,
63,
815,
3430,
18,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mrquim/mrquimrepo
|
plugin.video.castaway/resources/lib/sources/on_demand_sport/Other/rutube_nhlnba.py
|
4
|
1244
|
from __future__ import unicode_literals
from resources.lib.modules import client,webutils,convert
import re,urlparse,json
from resources.lib.modules.log_utils import log
class info():
def __init__(self):
self.mode = 'rutube_nhlnba'
self.name = 'Rutube NHL/NBA 2015./16.'
self.icon = 'rutube.png'
self.paginated = True
self.categorized = False
self.multilink = False
class main():
def __init__(self,url = 'http://rutube.ru/api/video/person/1004439/?page=1&format=json'):
self.base = 'http://fullmatchtv.com'
self.url = url
def items(self):
out=[]
result = client.request(self.url)
jsx = json.loads(result)['results']
for el in jsx:
title = el['title']
url = el['id']
img = el['thumbnail_url']
item = (title.encode('utf-8'),url,img)
out.append(item)
return out
def resolve(self,url):
url = 'http://rutube.ru/api/play/options/'+url+'?format=json'
result = client.request(url)
jsx = json.loads(result)
link = jsx['video_balancer']['m3u8']
return link
def next_page(self):
try:
page = re.findall('page=(\d+)',self.url)[0]
next_page = self.url.replace('page=%s'%(page),'page=%s'%(int(page)+1))
except:
return None
return next_page
|
gpl-2.0
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
5944,
14,
773,
14,
3112,
492,
1890,
12,
31991,
3024,
12,
3916,
199,
646,
295,
12,
10290,
12,
1001,
199,
504,
5944,
14,
773,
14,
3112,
14,
793,
63,
1208,
492,
943,
4388,
199,
533,
2256,
837,
272,
347,
636,
826,
721,
277,
304,
1362,
198,
277,
14,
632,
275,
283,
82,
337,
3375,
63,
29199,
6066,
2470,
7,
267,
291,
14,
354,
275,
283,
50,
337,
3375,
653,
29210,
15,
46,
4134,
6900,
13186,
975,
3530,
267,
291,
14,
4677,
275,
283,
82,
337,
3375,
14,
4524,
7,
267,
291,
14,
28030,
275,
715,
267,
291,
14,
7206,
1759,
275,
756,
267,
291,
14,
3029,
1073,
275,
756,
421,
199,
533,
2446,
837,
8299,
198,
318,
636,
826,
721,
277,
12,
633,
275,
283,
1014,
921,
82,
337,
3375,
14,
6558,
15,
1246,
15,
3722,
15,
5484,
15,
1960,
1602,
1355,
10197,
1606,
29,
17,
6,
908,
29,
1001,
735,
507,
198,
277,
14,
1095,
275,
283,
1014,
921,
2861,
1431,
6993,
14,
957,
7,
507,
198,
277,
14,
633,
275,
1166,
421,
198,
318,
2974,
8,
277,
304,
507,
198,
548,
9811,
507,
198,
1099,
275,
1890,
14,
1069,
8,
277,
14,
633,
9,
507,
198,
3596,
88,
275,
2022,
14,
3640,
8,
1099,
11820,
2604,
418,
507,
198,
509,
579,
315,
8586,
88,
26,
686,
198,
1213,
275,
579,
459,
1213,
418,
686,
198,
633,
275,
579,
459,
344,
418,
686,
198,
4060,
275,
579,
459,
8311,
63,
633,
418,
686,
198,
1053,
275,
334,
1213,
14,
2143,
360,
1624,
13,
24,
659,
633,
12,
4060,
9,
686,
198,
548,
14,
740,
8,
1053,
9,
2742,
198,
1107,
734,
421,
198,
318,
7512,
8,
277,
12,
633,
304,
507,
198,
633,
275,
283,
1014,
921,
82,
337,
3375,
14,
6558,
15,
1246,
15,
2802,
15,
1419,
19047,
633,
4786,
31,
908,
29,
1001,
7,
507,
198,
1099,
275,
1890,
14,
1069,
8,
633,
9,
507,
198,
3596,
88,
275,
2022,
14,
3640,
8,
1099,
9,
507,
198,
1073,
275,
8586,
88,
459,
3722,
63,
11841,
2545,
77,
19,
85,
24,
418,
507,
198,
1107,
2142,
421,
198,
318,
2163,
63,
1606,
8,
277,
304,
507,
198,
893,
26,
686,
198,
1606,
275,
295,
14,
6452,
360,
1606,
2687,
60,
68,
14705,
277,
14,
633,
2788,
16,
61,
686,
198,
2184,
63,
1606,
275,
291,
14,
633,
14,
1814,
360,
1606,
2458,
83,
13328,
1606,
26582,
1606,
2458,
83,
13328,
442,
8,
1606,
6393,
17,
430,
507,
198,
2590,
26,
686,
198,
1107,
488,
507,
198,
1107,
2163,
63,
1606,
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
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
5944,
14,
773,
14,
3112,
492,
1890,
12,
31991,
3024,
12,
3916,
199,
646,
295,
12,
10290,
12,
1001,
199,
504,
5944,
14,
773,
14,
3112,
14,
793,
63,
1208,
492,
943,
4388,
199,
533,
2256,
837,
272,
347,
636,
826,
721,
277,
304,
1362,
198,
277,
14,
632,
275,
283,
82,
337,
3375,
63,
29199,
6066,
2470,
7,
267,
291,
14,
354,
275,
283,
50,
337,
3375,
653,
29210,
15,
46,
4134,
6900,
13186,
975,
3530,
267,
291,
14,
4677,
275,
283,
82,
337,
3375,
14,
4524,
7,
267,
291,
14,
28030,
275,
715,
267,
291,
14,
7206,
1759,
275,
756,
267,
291,
14,
3029,
1073,
275,
756,
421,
199,
533,
2446,
837,
8299,
198,
318,
636,
826,
721,
277,
12,
633,
275,
283,
1014,
921,
82,
337,
3375,
14,
6558,
15,
1246,
15,
3722,
15,
5484,
15,
1960,
1602,
1355,
10197,
1606,
29,
17,
6,
908,
29,
1001,
735,
507,
198,
277,
14,
1095,
275,
283,
1014,
921,
2861,
1431,
6993,
14,
957,
7,
507,
198,
277,
14,
633,
275,
1166,
421,
198,
318,
2974,
8,
277,
304,
507,
198,
548,
9811,
507,
198,
1099,
275,
1890,
14,
1069,
8,
277,
14,
633,
9,
507,
198,
3596,
88,
275,
2022,
14,
3640,
8,
1099,
11820,
2604,
418,
507,
198,
509,
579,
315,
8586,
88,
26,
686,
198,
1213,
275,
579,
459,
1213,
418,
686,
198,
633,
275,
579,
459,
344,
418,
686,
198,
4060,
275,
579,
459,
8311,
63,
633,
418,
686,
198,
1053,
275,
334,
1213,
14,
2143,
360,
1624,
13,
24,
659,
633,
12,
4060,
9,
686,
198,
548,
14,
740,
8,
1053,
9,
2742,
198,
1107,
734,
421,
198,
318,
7512,
8,
277,
12,
633,
304,
507,
198,
633,
275,
283,
1014,
921,
82,
337,
3375,
14,
6558,
15,
1246,
15,
2802,
15,
1419,
19047,
633,
4786,
31,
908,
29,
1001,
7,
507,
198,
1099,
275,
1890,
14,
1069,
8,
633,
9,
507,
198,
3596,
88,
275,
2022,
14,
3640,
8,
1099,
9,
507,
198,
1073,
275,
8586,
88,
459,
3722,
63,
11841,
2545,
77,
19,
85,
24,
418,
507,
198,
1107,
2142,
421,
198,
318,
2163,
63,
1606,
8,
277,
304,
507,
198,
893,
26,
686,
198,
1606,
275,
295,
14,
6452,
360,
1606,
2687,
60,
68,
14705,
277,
14,
633,
2788,
16,
61,
686,
198,
2184,
63,
1606,
275,
291,
14,
633,
14,
1814,
360,
1606,
2458,
83,
13328,
1606,
26582,
1606,
2458,
83,
13328,
442,
8,
1606,
6393,
17,
430,
507,
198,
2590,
26,
686,
198,
1107,
488,
507,
198,
1107,
2163,
63,
1606,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
serl/hls-bba-testbed
|
pylibs/parallelize.py
|
1
|
2494
|
from multiprocessing import Process, Pipe
import sys, time
class AsyncFunction(object):
def __init__(self, fn, args=(), kwargs={}, return_obj=None, return_attr=None):
self.fn = fn
self.args = args
self.kwargs = kwargs
self.result = None
self.return_obj = return_obj
self.return_attr = return_attr
self._conn = None
self._process = None
def _call(self, conn):
result = None
exception = None
try:
result = self.fn(*self.args, **self.kwargs)
except Exception as e:
import traceback
exception = "".join(traceback.format_exception(*sys.exc_info()))
finally:
conn.send((result, exception))
conn.close()
def run(self):
self._conn, child_conn = Pipe(duplex=False)
self._process = Process(target=AsyncFunction._call, args=(self, child_conn))
self._process.start()
def poll(self, timeout=0):
if self._conn.poll(timeout):
self.result, exception = self._conn.recv()
if exception is not None:
raise InnerException(exception)
if self.return_obj is not None and self.return_attr is not None:
self.return_obj.__dict__[self.return_attr] = self.result
self._process.join()
return True
return False
def terminate(self):
if self._process.is_alive():
self._process.terminate()
class InnerException(Exception): pass
class Parallelize(object):
def __init__(self, collection, **kwargs):
self._functions = []
for custom_kwargs in collection:
for k in kwargs:
custom_kwargs[k] = kwargs[k]
self._functions.append(AsyncFunction(**custom_kwargs))
self.results = [None] * len(self._functions)
def run(self, polltime=0.5):
done = 0
for fn in self._functions:
fn.run()
while done is not len(self._functions):
for idx, fn in enumerate(self._functions):
try:
if fn.poll(polltime):
self.results[idx] = fn.result
done += 1
except:
[fn.terminate() for fn in self._functions]
raise
if __name__ == '__main__':
def sleepy(t):
time.sleep(t)
if t == 2:
raise Exception('ciao!')
return "after {0}s".format(t)
class resultclass:
pass
result=resultclass()
coll = [
{'args': (3,), 'return_attr': 'a'},
{'args': (1,), 'return_attr': 'b'}
]
p = Parallelize(coll, fn=sleepy, return_obj=result)
p.run()
print(result.__dict__)
print(p.results)
result=resultclass()
coll = [
{'args': (300,), 'return_attr': 'a'},
{'args': (2,), 'return_attr': 'b'}
]
p = Parallelize(coll, fn=sleepy, return_obj=result)
p.run()
print(result.__dict__)
print(p.results)
|
mit
|
[
504,
12866,
492,
7132,
12,
16850,
199,
646,
984,
12,
900,
199,
199,
533,
15223,
3481,
8,
785,
304,
199,
198,
318,
636,
826,
721,
277,
12,
4325,
12,
1249,
16729,
2074,
10324,
372,
63,
1113,
29,
403,
12,
372,
63,
962,
29,
403,
304,
507,
198,
277,
14,
2324,
275,
4325,
507,
198,
277,
14,
589,
275,
1249,
507,
198,
277,
14,
958,
275,
2074,
507,
198,
277,
14,
1099,
275,
488,
507,
198,
277,
14,
1107,
63,
1113,
275,
372,
63,
1113,
507,
198,
277,
14,
1107,
63,
962,
275,
372,
63,
962,
507,
198,
277,
423,
1631,
275,
488,
507,
198,
277,
423,
1412,
275,
488,
421,
198,
318,
485,
1250,
8,
277,
12,
2557,
304,
507,
198,
1099,
275,
488,
507,
198,
1971,
275,
488,
507,
198,
893,
26,
686,
198,
1099,
275,
291,
14,
2324,
2031,
277,
14,
589,
12,
1011,
277,
14,
958,
9,
507,
198,
2590,
2186,
465,
325,
26,
686,
198,
646,
5190,
686,
198,
1971,
275,
10587,
904,
8,
6894,
14,
908,
63,
1971,
2031,
1274,
14,
2804,
63,
815,
4059,
507,
198,
15172,
26,
686,
198,
1631,
14,
2254,
1332,
1099,
12,
1919,
430,
686,
198,
1631,
14,
1600,
342,
421,
198,
318,
1255,
8,
277,
304,
507,
198,
277,
423,
1631,
12,
1982,
63,
1631,
275,
16850,
8,
68,
26646,
29,
797,
9,
507,
198,
277,
423,
1412,
275,
7132,
8,
1375,
29,
12807,
3481,
423,
1250,
12,
1249,
2687,
277,
12,
1982,
63,
1631,
430,
507,
198,
277,
423,
1412,
14,
928,
342,
421,
198,
318,
11271,
8,
277,
12,
2653,
29,
16,
304,
507,
198,
692,
291,
423,
1631,
14,
6843,
8,
2593,
304,
686,
198,
277,
14,
1099,
12,
1919,
275,
291,
423,
1631,
14,
7637,
342,
686,
198,
692,
1919,
365,
440,
488,
26,
1585,
198,
3730,
19646,
1726,
8,
1971,
9,
686,
198,
692,
291,
14,
1107,
63,
1113,
365,
440,
488,
436,
291,
14,
1107,
63,
962,
365,
440,
488,
26,
1585,
198,
277,
14,
1107,
63,
1113,
855,
807,
12298,
277,
14,
1107,
63,
962,
61,
275,
291,
14,
1099,
686,
198,
277,
423,
1412,
14,
904,
342,
686,
198,
1107,
715,
507,
198,
1107,
756,
421,
198,
318,
15095,
8,
277,
304,
507,
198,
692,
291,
423,
1412,
14,
374,
63,
9631,
837,
686,
198,
277,
423,
1412,
14,
14478,
342,
199,
199,
533,
19646,
1726,
8,
1726,
304,
986,
199,
199,
533,
2235,
4598,
13559,
8,
785,
304,
199,
198,
318,
636,
826,
721,
277,
12,
3245,
12,
1011,
958,
304,
507,
198,
277,
423,
5777,
275,
942,
507,
198,
509,
3537,
63,
958,
315,
3245,
26,
686,
198,
509,
1022,
315,
2074,
26,
1585,
198,
4229,
63,
958,
59,
75,
61,
275,
2074,
59,
75,
61,
686,
198,
277,
423,
5777,
14,
740,
8,
12807,
3481,
3682,
4229,
63,
958,
430,
507,
198,
277,
14,
2604,
275,
359,
403,
61,
627,
822,
8,
277,
423,
5777,
9,
199,
198,
318,
1255,
8,
277,
12,
11271,
521,
29,
16,
14,
21,
304,
507,
198,
4456,
275,
378,
507,
198,
509,
4325,
315,
291,
423,
5777,
26,
686,
198,
2324,
14,
1065,
342,
507,
198,
6710,
4224,
365,
440,
822,
8,
277,
423,
5777,
304,
686,
198,
509,
4280,
12,
4325,
315,
3874,
8,
277,
423,
5777,
304,
1585,
198,
893,
26,
1871,
198,
692,
4325,
14,
6843,
8,
6843,
521,
304,
4671,
198,
277,
14,
2604,
59,
2996,
61,
275,
4325,
14,
1099,
4671,
198,
4456,
847,
413,
1585,
198,
2590,
26,
1871,
198,
59,
2324,
14,
14478,
342,
367,
4325,
315,
291,
423,
5777,
61,
1871,
198,
3730,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
199,
198,
318,
308,
18387,
647,
8,
84,
304,
507,
198,
521,
14,
4532,
8,
84,
9,
507,
198,
692,
307,
508,
499,
26,
686,
198,
3730,
2186,
360,
559,
8035,
10916,
507,
198,
1107,
298,
4399,
469,
16,
93,
83,
1674,
908,
8,
84,
9,
421,
198,
533,
754,
533,
26,
507,
198,
1529,
421,
198,
1099,
29,
1099,
533,
342,
199,
198,
15772,
275,
359,
507,
198,
1445,
589,
356,
334,
19,
4706,
283,
1107,
63,
962,
356,
283,
65,
2267,
507,
198,
1445,
589,
356,
334,
17,
4706,
283,
1107,
63,
962,
356,
283,
66,
936,
199,
198,
61,
199,
198,
80,
275,
2235,
4598,
13559,
8,
15772,
12,
4325,
29,
83,
18387,
647,
12,
372,
63,
1113,
29,
1099,
9,
199,
198,
80,
14,
1065,
342,
199,
198,
1361,
8,
1099,
855,
807,
3368,
199,
198,
1361,
8,
80,
14,
2604,
9,
421,
198,
1099,
29,
1099,
533,
342,
199,
198,
15772,
275,
359,
507,
198,
1445,
589,
356,
334,
5863,
4706,
283,
1107,
63,
962,
356,
283,
65,
2267,
507,
198,
1445,
589,
356,
334,
18,
4706,
283,
1107,
63,
962,
356,
283,
66,
936,
199,
198,
61,
199,
198,
80,
275,
2235,
4598,
13559,
8,
15772,
12,
4325,
29,
83,
18387,
647,
12,
372,
63,
1113,
29,
1099,
9,
199,
198,
80,
14,
1065,
342,
199,
198,
1361,
8,
1099,
855,
807,
3368,
199,
198,
1361,
8,
80,
14,
2604,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
12866,
492,
7132,
12,
16850,
199,
646,
984,
12,
900,
199,
199,
533,
15223,
3481,
8,
785,
304,
199,
198,
318,
636,
826,
721,
277,
12,
4325,
12,
1249,
16729,
2074,
10324,
372,
63,
1113,
29,
403,
12,
372,
63,
962,
29,
403,
304,
507,
198,
277,
14,
2324,
275,
4325,
507,
198,
277,
14,
589,
275,
1249,
507,
198,
277,
14,
958,
275,
2074,
507,
198,
277,
14,
1099,
275,
488,
507,
198,
277,
14,
1107,
63,
1113,
275,
372,
63,
1113,
507,
198,
277,
14,
1107,
63,
962,
275,
372,
63,
962,
507,
198,
277,
423,
1631,
275,
488,
507,
198,
277,
423,
1412,
275,
488,
421,
198,
318,
485,
1250,
8,
277,
12,
2557,
304,
507,
198,
1099,
275,
488,
507,
198,
1971,
275,
488,
507,
198,
893,
26,
686,
198,
1099,
275,
291,
14,
2324,
2031,
277,
14,
589,
12,
1011,
277,
14,
958,
9,
507,
198,
2590,
2186,
465,
325,
26,
686,
198,
646,
5190,
686,
198,
1971,
275,
10587,
904,
8,
6894,
14,
908,
63,
1971,
2031,
1274,
14,
2804,
63,
815,
4059,
507,
198,
15172,
26,
686,
198,
1631,
14,
2254,
1332,
1099,
12,
1919,
430,
686,
198,
1631,
14,
1600,
342,
421,
198,
318,
1255,
8,
277,
304,
507,
198,
277,
423,
1631,
12,
1982,
63,
1631,
275,
16850,
8,
68,
26646,
29,
797,
9,
507,
198,
277,
423,
1412,
275,
7132,
8,
1375,
29,
12807,
3481,
423,
1250,
12,
1249,
2687,
277,
12,
1982,
63,
1631,
430,
507,
198,
277,
423,
1412,
14,
928,
342,
421,
198,
318,
11271,
8,
277,
12,
2653,
29,
16,
304,
507,
198,
692,
291,
423,
1631,
14,
6843,
8,
2593,
304,
686,
198,
277,
14,
1099,
12,
1919,
275,
291,
423,
1631,
14,
7637,
342,
686,
198,
692,
1919,
365,
440,
488,
26,
1585,
198,
3730,
19646,
1726,
8,
1971,
9,
686,
198,
692,
291,
14,
1107,
63,
1113,
365,
440,
488,
436,
291,
14,
1107,
63,
962,
365,
440,
488,
26,
1585,
198,
277,
14,
1107,
63,
1113,
855,
807,
12298,
277,
14,
1107,
63,
962,
61,
275,
291,
14,
1099,
686,
198,
277,
423,
1412,
14,
904,
342,
686,
198,
1107,
715,
507,
198,
1107,
756,
421,
198,
318,
15095,
8,
277,
304,
507,
198,
692,
291,
423,
1412,
14,
374,
63,
9631,
837,
686,
198,
277,
423,
1412,
14,
14478,
342,
199,
199,
533,
19646,
1726,
8,
1726,
304,
986,
199,
199,
533,
2235,
4598,
13559,
8,
785,
304,
199,
198,
318,
636,
826,
721,
277,
12,
3245,
12,
1011,
958,
304,
507,
198,
277,
423,
5777,
275,
942,
507,
198,
509,
3537,
63,
958,
315,
3245,
26,
686,
198,
509,
1022,
315,
2074,
26,
1585,
198,
4229,
63,
958,
59,
75,
61,
275,
2074,
59,
75,
61,
686,
198,
277,
423,
5777,
14,
740,
8,
12807,
3481,
3682,
4229,
63,
958,
430,
507,
198,
277,
14,
2604,
275,
359,
403,
61,
627,
822,
8,
277,
423,
5777,
9,
199,
198,
318,
1255,
8,
277,
12,
11271,
521,
29,
16,
14,
21,
304,
507,
198,
4456,
275,
378,
507,
198,
509,
4325,
315,
291,
423,
5777,
26,
686,
198,
2324,
14,
1065,
342,
507,
198,
6710,
4224,
365,
440,
822,
8,
277,
423,
5777,
304,
686,
198,
509,
4280,
12,
4325,
315,
3874,
8,
277,
423,
5777,
304,
1585,
198,
893,
26,
1871,
198,
692,
4325,
14,
6843,
8,
6843,
521,
304,
4671,
198,
277,
14,
2604,
59,
2996,
61,
275,
4325,
14,
1099,
4671,
198,
4456,
847,
413,
1585,
198,
2590,
26,
1871,
198,
59,
2324,
14,
14478,
342,
367,
4325,
315,
291,
423,
5777,
61,
1871,
198,
3730,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
199,
198,
318,
308,
18387,
647,
8,
84,
304,
507,
198,
521,
14,
4532,
8,
84,
9,
507,
198,
692,
307,
508,
499,
26,
686,
198,
3730,
2186,
360,
559,
8035,
10916,
507,
198,
1107,
298,
4399,
469,
16,
93,
83,
1674,
908,
8,
84,
9,
421,
198,
533,
754,
533,
26,
507,
198,
1529,
421,
198,
1099,
29,
1099,
533,
342,
199,
198,
15772,
275,
359,
507,
198,
1445,
589,
356,
334,
19,
4706,
283,
1107,
63,
962,
356,
283,
65,
2267,
507,
198,
1445,
589,
356,
334,
17,
4706,
283,
1107,
63,
962,
356,
283,
66,
936,
199,
198,
61,
199,
198,
80,
275,
2235,
4598,
13559,
8,
15772,
12,
4325,
29,
83,
18387,
647,
12,
372,
63,
1113,
29,
1099,
9,
199,
198,
80,
14,
1065,
342,
199,
198,
1361,
8,
1099,
855,
807,
3368,
199,
198,
1361,
8,
80,
14,
2604,
9,
421,
198,
1099,
29,
1099,
533,
342,
199,
198,
15772,
275,
359,
507,
198,
1445,
589,
356,
334,
5863,
4706,
283,
1107,
63,
962,
356,
283,
65,
2267,
507,
198,
1445,
589,
356,
334,
18,
4706,
283,
1107,
63,
962,
356,
283,
66,
936,
199,
198,
61,
199,
198,
80,
275,
2235,
4598,
13559,
8,
15772,
12,
4325,
29,
83,
18387,
647,
12,
372,
63,
1113,
29,
1099,
9,
199,
198,
80,
14,
1065,
342,
199,
198,
1361,
8,
1099,
855,
807,
3368,
199,
198,
1361,
8,
80,
14,
2604,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
manuelep/pydal
|
pydal/contrib/reserved_sql_keywords.py
|
29
|
26960
|
# encoding utf-8
__author__ = "Thadeus Burgess <thadeusb@thadeusb.com>"
# we classify as "non-reserved" those key words that are explicitly known
# to the parser but are allowed as column or table names. Some key words
# that are otherwise non-reserved cannot be used as function or data type n
# ames and are in the nonreserved list. (Most of these words represent
# built-in functions or data types with special syntax. The function
# or type is still available but it cannot be redefined by the user.)
# Labeled "reserved" are those tokens that are not allowed as column or
# table names. Some reserved key words are allowable as names for
# functions or data typesself.
# Note at the bottom of the list is a dict containing references to the
# tuples, and also if you add a list don't forget to remove its default
# set of COMMON.
# Keywords that are adapter specific. Such as a list of "postgresql"
# or "mysql" keywords
# These are keywords that are common to all SQL dialects, and should
# never be used as a table or column. Even if you use one of these
# the cursor will throw an OperationalError for the SQL syntax.
from .._compat import PY2
if not PY2:
from functools import reduce
COMMON = set((
'SELECT',
'INSERT',
'DELETE',
'UPDATE',
'DROP',
'CREATE',
'ALTER',
'WHERE',
'FROM',
'INNER',
'JOIN',
'AND',
'OR',
'LIKE',
'ON',
'IN',
'SET',
'BY',
'GROUP',
'ORDER',
'LEFT',
'OUTER',
'IF',
'END',
'THEN',
'LOOP',
'AS',
'ELSE',
'FOR',
'CASE',
'WHEN',
'MIN',
'MAX',
'DISTINCT',
))
POSTGRESQL = set((
'FALSE',
'TRUE',
'ALL',
'ANALYSE',
'ANALYZE',
'AND',
'ANY',
'ARRAY',
'AS',
'ASC',
'ASYMMETRIC',
'AUTHORIZATION',
'BETWEEN',
'BIGINT',
'BINARY',
'BIT',
'BOOLEAN',
'BOTH',
'CASE',
'CAST',
'CHAR',
'CHARACTER',
'CHECK',
'COALESCE',
'COLLATE',
'COLUMN',
'CONSTRAINT',
'CREATE',
'CROSS',
'CURRENT_CATALOG',
'CURRENT_DATE',
'CURRENT_ROLE',
'CURRENT_SCHEMA',
'CURRENT_TIME',
'CURRENT_TIMESTAMP',
'CURRENT_USER',
'DEC',
'DECIMAL',
'DEFAULT',
'DEFERRABLE',
'DESC',
'DISTINCT',
'DO',
'ELSE',
'END',
'EXCEPT',
'EXISTS',
'EXTRACT',
'FETCH',
'FLOAT',
'FOR',
'FOREIGN',
'FREEZE',
'FROM',
'FULL',
'GRANT',
'GREATEST',
'GROUP',
'HAVING',
'ILIKE',
'IN',
'INITIALLY',
'INNER',
'INOUT',
'INT',
'INTEGER',
'INTERSECT',
'INTERVAL',
'INTO',
'IS',
'ISNULL',
'JOIN',
'LEADING',
'LEAST',
'LEFT',
'LIKE',
'LIMIT',
'LOCALTIME',
'LOCALTIMESTAMP',
'NATIONAL',
'NATURAL',
'NCHAR',
'NEW',
'NONE',
'NOT',
'NOTNULL',
'NULL',
'NULLIF',
'NUMERIC',
'OFF',
'OFFSET',
'OLD',
'ON',
'ONLY',
'OR',
'ORDER',
'OUT',
'OUTER',
'OVERLAPS',
'OVERLAY',
'PLACING',
'POSITION',
'PRECISION',
'PRIMARY',
'REAL',
'REFERENCES',
'RETURNING',
'RIGHT',
'ROW',
'SELECT',
'SESSION_USER',
'SETOF',
'SIMILAR',
'SMALLINT',
'SOME',
'SUBSTRING',
'SYMMETRIC',
'TABLE',
'THEN',
'TIME',
'TIMESTAMP',
'TO',
'TRAILING',
'TREAT',
'TRIM',
'UNION',
'UNIQUE',
'USER',
'USING',
'VALUES',
'VARCHAR',
'VARIADIC',
'VERBOSE',
'WHEN',
'WHERE',
'WITH',
'XMLATTRIBUTES',
'XMLCONCAT',
'XMLELEMENT',
'XMLFOREST',
'XMLPARSE',
'XMLPI',
'XMLROOT',
'XMLSERIALIZE',
))
POSTGRESQL_NONRESERVED = set((
'A',
'ABORT',
'ABS',
'ABSENT',
'ABSOLUTE',
'ACCESS',
'ACCORDING',
'ACTION',
'ADA',
'ADD',
'ADMIN',
'AFTER',
'AGGREGATE',
'ALIAS',
'ALLOCATE',
'ALSO',
'ALTER',
'ALWAYS',
'ARE',
'ARRAY_AGG',
'ASENSITIVE',
'ASSERTION',
'ASSIGNMENT',
'AT',
'ATOMIC',
'ATTRIBUTE',
'ATTRIBUTES',
'AVG',
'BACKWARD',
'BASE64',
'BEFORE',
'BEGIN',
'BERNOULLI',
'BIT_LENGTH',
'BITVAR',
'BLOB',
'BOM',
'BREADTH',
'BY',
'C',
'CACHE',
'CALL',
'CALLED',
'CARDINALITY',
'CASCADE',
'CASCADED',
'CATALOG',
'CATALOG_NAME',
'CEIL',
'CEILING',
'CHAIN',
'CHAR_LENGTH',
'CHARACTER_LENGTH',
'CHARACTER_SET_CATALOG',
'CHARACTER_SET_NAME',
'CHARACTER_SET_SCHEMA',
'CHARACTERISTICS',
'CHARACTERS',
'CHECKED',
'CHECKPOINT',
'CLASS',
'CLASS_ORIGIN',
'CLOB',
'CLOSE',
'CLUSTER',
'COBOL',
'COLLATION',
'COLLATION_CATALOG',
'COLLATION_NAME',
'COLLATION_SCHEMA',
'COLLECT',
'COLUMN_NAME',
'COLUMNS',
'COMMAND_FUNCTION',
'COMMAND_FUNCTION_CODE',
'COMMENT',
'COMMIT',
'COMMITTED',
'COMPLETION',
'CONCURRENTLY',
'CONDITION',
'CONDITION_NUMBER',
'CONFIGURATION',
'CONNECT',
'CONNECTION',
'CONNECTION_NAME',
'CONSTRAINT_CATALOG',
'CONSTRAINT_NAME',
'CONSTRAINT_SCHEMA',
'CONSTRAINTS',
'CONSTRUCTOR',
'CONTAINS',
'CONTENT',
'CONTINUE',
'CONVERSION',
'CONVERT',
'COPY',
'CORR',
'CORRESPONDING',
'COST',
'COUNT',
'COVAR_POP',
'COVAR_SAMP',
'CREATEDB',
'CREATEROLE',
'CREATEUSER',
'CSV',
'CUBE',
'CUME_DIST',
'CURRENT',
'CURRENT_DEFAULT_TRANSFORM_GROUP',
'CURRENT_PATH',
'CURRENT_TRANSFORM_GROUP_FOR_TYPE',
'CURSOR',
'CURSOR_NAME',
'CYCLE',
'DATA',
'DATABASE',
'DATE',
'DATETIME_INTERVAL_CODE',
'DATETIME_INTERVAL_PRECISION',
'DAY',
'DEALLOCATE',
'DECLARE',
'DEFAULTS',
'DEFERRED',
'DEFINED',
'DEFINER',
'DEGREE',
'DELETE',
'DELIMITER',
'DELIMITERS',
'DENSE_RANK',
'DEPTH',
'DEREF',
'DERIVED',
'DESCRIBE',
'DESCRIPTOR',
'DESTROY',
'DESTRUCTOR',
'DETERMINISTIC',
'DIAGNOSTICS',
'DICTIONARY',
'DISABLE',
'DISCARD',
'DISCONNECT',
'DISPATCH',
'DOCUMENT',
'DOMAIN',
'DOUBLE',
'DROP',
'DYNAMIC',
'DYNAMIC_FUNCTION',
'DYNAMIC_FUNCTION_CODE',
'EACH',
'ELEMENT',
'EMPTY',
'ENABLE',
'ENCODING',
'ENCRYPTED',
'END-EXEC',
'ENUM',
'EQUALS',
'ESCAPE',
'EVERY',
'EXCEPTION',
'EXCLUDE',
'EXCLUDING',
'EXCLUSIVE',
'EXEC',
'EXECUTE',
'EXISTING',
'EXP',
'EXPLAIN',
'EXTERNAL',
'FAMILY',
'FILTER',
'FINAL',
'FIRST',
'FIRST_VALUE',
'FLAG',
'FLOOR',
'FOLLOWING',
'FORCE',
'FORTRAN',
'FORWARD',
'FOUND',
'FREE',
'FUNCTION',
'FUSION',
'G',
'GENERAL',
'GENERATED',
'GET',
'GLOBAL',
'GO',
'GOTO',
'GRANTED',
'GROUPING',
'HANDLER',
'HEADER',
'HEX',
'HIERARCHY',
'HOLD',
'HOST',
'HOUR',
# 'ID',
'IDENTITY',
'IF',
'IGNORE',
'IMMEDIATE',
'IMMUTABLE',
'IMPLEMENTATION',
'IMPLICIT',
'INCLUDING',
'INCREMENT',
'INDENT',
'INDEX',
'INDEXES',
'INDICATOR',
'INFIX',
'INHERIT',
'INHERITS',
'INITIALIZE',
'INPUT',
'INSENSITIVE',
'INSERT',
'INSTANCE',
'INSTANTIABLE',
'INSTEAD',
'INTERSECTION',
'INVOKER',
'ISOLATION',
'ITERATE',
'K',
'KEY',
'KEY_MEMBER',
'KEY_TYPE',
'LAG',
'LANCOMPILER',
'LANGUAGE',
'LARGE',
'LAST',
'LAST_VALUE',
'LATERAL',
'LC_COLLATE',
'LC_CTYPE',
'LEAD',
'LENGTH',
'LESS',
'LEVEL',
'LIKE_REGEX',
'LISTEN',
'LN',
'LOAD',
'LOCAL',
'LOCATION',
'LOCATOR',
'LOCK',
'LOGIN',
'LOWER',
'M',
'MAP',
'MAPPING',
'MATCH',
'MATCHED',
'MAX',
'MAX_CARDINALITY',
'MAXVALUE',
'MEMBER',
'MERGE',
'MESSAGE_LENGTH',
'MESSAGE_OCTET_LENGTH',
'MESSAGE_TEXT',
'METHOD',
'MIN',
'MINUTE',
'MINVALUE',
'MOD',
'MODE',
'MODIFIES',
'MODIFY',
'MODULE',
'MONTH',
'MORE',
'MOVE',
'MULTISET',
'MUMPS',
# 'NAME',
'NAMES',
'NAMESPACE',
'NCLOB',
'NESTING',
'NEXT',
'NFC',
'NFD',
'NFKC',
'NFKD',
'NIL',
'NO',
'NOCREATEDB',
'NOCREATEROLE',
'NOCREATEUSER',
'NOINHERIT',
'NOLOGIN',
'NORMALIZE',
'NORMALIZED',
'NOSUPERUSER',
'NOTHING',
'NOTIFY',
'NOWAIT',
'NTH_VALUE',
'NTILE',
'NULLABLE',
'NULLS',
'NUMBER',
'OBJECT',
'OCCURRENCES_REGEX',
'OCTET_LENGTH',
'OCTETS',
'OF',
'OIDS',
'OPEN',
'OPERATION',
'OPERATOR',
'OPTION',
'OPTIONS',
'ORDERING',
'ORDINALITY',
'OTHERS',
'OUTPUT',
'OVER',
'OVERRIDING',
'OWNED',
'OWNER',
'P',
'PAD',
'PARAMETER',
'PARAMETER_MODE',
'PARAMETER_NAME',
'PARAMETER_ORDINAL_POSITION',
'PARAMETER_SPECIFIC_CATALOG',
'PARAMETER_SPECIFIC_NAME',
'PARAMETER_SPECIFIC_SCHEMA',
'PARAMETERS',
'PARSER',
'PARTIAL',
'PARTITION',
'PASCAL',
'PASSING',
# 'PASSWORD',
'PATH',
'PERCENT_RANK',
'PERCENTILE_CONT',
'PERCENTILE_DISC',
'PLANS',
'PLI',
'POSITION_REGEX',
'POSTFIX',
'POWER',
'PRECEDING',
'PREFIX',
'PREORDER',
'PREPARE',
'PREPARED',
'PRESERVE',
'PRIOR',
'PRIVILEGES',
'PROCEDURAL',
'PROCEDURE',
'PUBLIC',
'QUOTE',
'RANGE',
'RANK',
'READ',
'READS',
'REASSIGN',
'RECHECK',
'RECURSIVE',
'REF',
'REFERENCING',
'REGR_AVGX',
'REGR_AVGY',
'REGR_COUNT',
'REGR_INTERCEPT',
'REGR_R2',
'REGR_SLOPE',
'REGR_SXX',
'REGR_SXY',
'REGR_SYY',
'REINDEX',
'RELATIVE',
'RELEASE',
'RENAME',
'REPEATABLE',
'REPLACE',
'REPLICA',
'RESET',
'RESPECT',
'RESTART',
'RESTRICT',
'RESULT',
'RETURN',
'RETURNED_CARDINALITY',
'RETURNED_LENGTH',
'RETURNED_OCTET_LENGTH',
'RETURNED_SQLSTATE',
'RETURNS',
'REVOKE',
# 'ROLE',
'ROLLBACK',
'ROLLUP',
'ROUTINE',
'ROUTINE_CATALOG',
'ROUTINE_NAME',
'ROUTINE_SCHEMA',
'ROW_COUNT',
'ROW_NUMBER',
'ROWS',
'RULE',
'SAVEPOINT',
'SCALE',
'SCHEMA',
'SCHEMA_NAME',
'SCOPE',
'SCOPE_CATALOG',
'SCOPE_NAME',
'SCOPE_SCHEMA',
'SCROLL',
'SEARCH',
'SECOND',
'SECTION',
'SECURITY',
'SELF',
'SENSITIVE',
'SEQUENCE',
'SERIALIZABLE',
'SERVER',
'SERVER_NAME',
'SESSION',
'SET',
'SETS',
'SHARE',
'SHOW',
'SIMPLE',
'SIZE',
'SOURCE',
'SPACE',
'SPECIFIC',
'SPECIFIC_NAME',
'SPECIFICTYPE',
'SQL',
'SQLCODE',
'SQLERROR',
'SQLEXCEPTION',
'SQLSTATE',
'SQLWARNING',
'SQRT',
'STABLE',
'STANDALONE',
'START',
'STATE',
'STATEMENT',
'STATIC',
'STATISTICS',
'STDDEV_POP',
'STDDEV_SAMP',
'STDIN',
'STDOUT',
'STORAGE',
'STRICT',
'STRIP',
'STRUCTURE',
'STYLE',
'SUBCLASS_ORIGIN',
'SUBLIST',
'SUBMULTISET',
'SUBSTRING_REGEX',
'SUM',
'SUPERUSER',
'SYSID',
'SYSTEM',
'SYSTEM_USER',
'T',
# 'TABLE_NAME',
'TABLESAMPLE',
'TABLESPACE',
'TEMP',
'TEMPLATE',
'TEMPORARY',
'TERMINATE',
'TEXT',
'THAN',
'TIES',
'TIMEZONE_HOUR',
'TIMEZONE_MINUTE',
'TOP_LEVEL_COUNT',
'TRANSACTION',
'TRANSACTION_ACTIVE',
'TRANSACTIONS_COMMITTED',
'TRANSACTIONS_ROLLED_BACK',
'TRANSFORM',
'TRANSFORMS',
'TRANSLATE',
'TRANSLATE_REGEX',
'TRANSLATION',
'TRIGGER',
'TRIGGER_CATALOG',
'TRIGGER_NAME',
'TRIGGER_SCHEMA',
'TRIM_ARRAY',
'TRUNCATE',
'TRUSTED',
'TYPE',
'UESCAPE',
'UNBOUNDED',
'UNCOMMITTED',
'UNDER',
'UNENCRYPTED',
'UNKNOWN',
'UNLISTEN',
'UNNAMED',
'UNNEST',
'UNTIL',
'UNTYPED',
'UPDATE',
'UPPER',
'URI',
'USAGE',
'USER_DEFINED_TYPE_CATALOG',
'USER_DEFINED_TYPE_CODE',
'USER_DEFINED_TYPE_NAME',
'USER_DEFINED_TYPE_SCHEMA',
'VACUUM',
'VALID',
'VALIDATOR',
'VALUE',
'VAR_POP',
'VAR_SAMP',
'VARBINARY',
'VARIABLE',
'VARYING',
'VERSION',
'VIEW',
'VOLATILE',
'WHENEVER',
'WHITESPACE',
'WIDTH_BUCKET',
'WINDOW',
'WITHIN',
'WITHOUT',
'WORK',
'WRAPPER',
'WRITE',
'XML',
'XMLAGG',
'XMLBINARY',
'XMLCAST',
'XMLCOMMENT',
'XMLDECLARATION',
'XMLDOCUMENT',
'XMLEXISTS',
'XMLITERATE',
'XMLNAMESPACES',
'XMLQUERY',
'XMLSCHEMA',
'XMLTABLE',
'XMLTEXT',
'XMLVALIDATE',
'YEAR',
'YES',
'ZONE',
))
#Thanks villas
FIREBIRD = set((
'ABS',
'ACTIVE',
'ADMIN',
'AFTER',
'ASCENDING',
'AUTO',
'AUTODDL',
'BASED',
'BASENAME',
'BASE_NAME',
'BEFORE',
'BIT_LENGTH',
'BLOB',
'BLOBEDIT',
'BOOLEAN',
'BOTH',
'BUFFER',
'CACHE',
'CHAR_LENGTH',
'CHARACTER_LENGTH',
'CHECK_POINT_LEN',
'CHECK_POINT_LENGTH',
'CLOSE',
'COMMITTED',
'COMPILETIME',
'COMPUTED',
'CONDITIONAL',
'CONNECT',
'CONTAINING',
'CROSS',
'CSTRING',
'CURRENT_CONNECTION',
'CURRENT_ROLE',
'CURRENT_TRANSACTION',
'CURRENT_USER',
'DATABASE',
'DB_KEY',
'DEBUG',
'DESCENDING',
'DISCONNECT',
'DISPLAY',
'DO',
'ECHO',
'EDIT',
'ENTRY_POINT',
'EVENT',
'EXIT',
'EXTERN',
'FALSE',
'FETCH',
'FILE',
'FILTER',
'FREE_IT',
'FUNCTION',
'GDSCODE',
'GENERATOR',
'GEN_ID',
'GLOBAL',
'GROUP_COMMIT_WAIT',
'GROUP_COMMIT_WAIT_TIME',
'HELP',
'IF',
'INACTIVE',
'INDEX',
'INIT',
'INPUT_TYPE',
'INSENSITIVE',
'ISQL',
'LC_MESSAGES',
'LC_TYPE',
'LEADING',
'LENGTH',
'LEV',
'LOGFILE',
'LOG_BUFFER_SIZE',
'LOG_BUF_SIZE',
'LONG',
'LOWER',
'MANUAL',
'MAXIMUM',
'MAXIMUM_SEGMENT',
'MAX_SEGMENT',
'MERGE',
'MESSAGE',
'MINIMUM',
'MODULE_NAME',
'NOAUTO',
'NUM_LOG_BUFS',
'NUM_LOG_BUFFERS',
'OCTET_LENGTH',
'OPEN',
'OUTPUT_TYPE',
'OVERFLOW',
'PAGE',
'PAGELENGTH',
'PAGES',
'PAGE_SIZE',
'PARAMETER',
# 'PASSWORD',
'PLAN',
'POST_EVENT',
'QUIT',
'RAW_PARTITIONS',
'RDB$DB_KEY',
'RECORD_VERSION',
'RECREATE',
'RECURSIVE',
'RELEASE',
'RESERV',
'RESERVING',
'RETAIN',
'RETURN',
'RETURNING_VALUES',
'RETURNS',
# 'ROLE',
'ROW_COUNT',
'ROWS',
'RUNTIME',
'SAVEPOINT',
'SECOND',
'SENSITIVE',
'SHADOW',
'SHARED',
'SHELL',
'SHOW',
'SINGULAR',
'SNAPSHOT',
'SORT',
'STABILITY',
'START',
'STARTING',
'STARTS',
'STATEMENT',
'STATIC',
'STATISTICS',
'SUB_TYPE',
'SUSPEND',
'TERMINATOR',
'TRAILING',
'TRIGGER',
'TRIM',
'TRUE',
'TYPE',
'UNCOMMITTED',
'UNKNOWN',
'USING',
'VARIABLE',
'VERSION',
'WAIT',
'WEEKDAY',
'WHILE',
'YEARDAY',
))
FIREBIRD_NONRESERVED = set((
'BACKUP',
'BLOCK',
'COALESCE',
'COLLATION',
'COMMENT',
'DELETING',
'DIFFERENCE',
'IIF',
'INSERTING',
'LAST',
'LEAVE',
'LOCK',
'NEXT',
'NULLIF',
'NULLS',
'RESTART',
'RETURNING',
'SCALAR_ARRAY',
'SEQUENCE',
'STATEMENT',
'UPDATING',
'ABS',
'ACCENT',
'ACOS',
'ALWAYS',
'ASCII_CHAR',
'ASCII_VAL',
'ASIN',
'ATAN',
'ATAN2',
'BACKUP',
'BIN_AND',
'BIN_OR',
'BIN_SHL',
'BIN_SHR',
'BIN_XOR',
'BLOCK',
'CEIL',
'CEILING',
'COLLATION',
'COMMENT',
'COS',
'COSH',
'COT',
'DATEADD',
'DATEDIFF',
'DECODE',
'DIFFERENCE',
'EXP',
'FLOOR',
'GEN_UUID',
'GENERATED',
'HASH',
'IIF',
'LIST',
'LN',
'LOG',
'LOG10',
'LPAD',
'MATCHED',
'MATCHING',
'MAXVALUE',
'MILLISECOND',
'MINVALUE',
'MOD',
'NEXT',
'OVERLAY',
'PAD',
'PI',
'PLACING',
'POWER',
'PRESERVE',
'RAND',
'REPLACE',
'RESTART',
'RETURNING',
'REVERSE',
'ROUND',
'RPAD',
'SCALAR_ARRAY',
'SEQUENCE',
'SIGN',
'SIN',
'SINH',
'SPACE',
'SQRT',
'TAN',
'TANH',
'TEMPORARY',
'TRUNC',
'WEEK',
))
# Thanks Jonathan Lundell
MYSQL = set((
'ACCESSIBLE',
'ADD',
'ALL',
'ALTER',
'ANALYZE',
'AND',
'AS',
'ASC',
'ASENSITIVE',
'BEFORE',
'BETWEEN',
'BIGINT',
'BINARY',
'BLOB',
'BOTH',
'BY',
'CALL',
'CASCADE',
'CASE',
'CHANGE',
'CHAR',
'CHARACTER',
'CHECK',
'COLLATE',
'COLUMN',
'CONDITION',
'CONSTRAINT',
'CONTINUE',
'CONVERT',
'CREATE',
'CROSS',
'CURRENT_DATE',
'CURRENT_TIME',
'CURRENT_TIMESTAMP',
'CURRENT_USER',
'CURSOR',
'DATABASE',
'DATABASES',
'DAY_HOUR',
'DAY_MICROSECOND',
'DAY_MINUTE',
'DAY_SECOND',
'DEC',
'DECIMAL',
'DECLARE',
'DEFAULT',
'DELAYED',
'DELETE',
'DESC',
'DESCRIBE',
'DETERMINISTIC',
'DISTINCT',
'DISTINCTROW',
'DIV',
'DOUBLE',
'DROP',
'DUAL',
'EACH',
'ELSE',
'ELSEIF',
'ENCLOSED',
'ESCAPED',
'EXISTS',
'EXIT',
'EXPLAIN',
'FALSE',
'FETCH',
'FLOAT',
'FLOAT4',
'FLOAT8',
'FOR',
'FORCE',
'FOREIGN',
'FROM',
'FULLTEXT',
'GRANT',
'GROUP',
'HAVING',
'HIGH_PRIORITY',
'HOUR_MICROSECOND',
'HOUR_MINUTE',
'HOUR_SECOND',
'IF',
'IGNORE',
'IGNORE_SERVER_IDS',
'IGNORE_SERVER_IDS',
'IN',
'INDEX',
'INFILE',
'INNER',
'INOUT',
'INSENSITIVE',
'INSERT',
'INT',
'INT1',
'INT2',
'INT3',
'INT4',
'INT8',
'INTEGER',
'INTERVAL',
'INTO',
'IS',
'ITERATE',
'JOIN',
'KEY',
'KEYS',
'KILL',
'LEADING',
'LEAVE',
'LEFT',
'LIKE',
'LIMIT',
'LINEAR',
'LINES',
'LOAD',
'LOCALTIME',
'LOCALTIMESTAMP',
'LOCK',
'LONG',
'LONGBLOB',
'LONGTEXT',
'LOOP',
'LOW_PRIORITY',
'MASTER_HEARTBEAT_PERIOD',
'MASTER_HEARTBEAT_PERIOD',
'MASTER_SSL_VERIFY_SERVER_CERT',
'MATCH',
'MAXVALUE',
'MAXVALUE',
'MEDIUMBLOB',
'MEDIUMINT',
'MEDIUMTEXT',
'MIDDLEINT',
'MINUTE_MICROSECOND',
'MINUTE_SECOND',
'MOD',
'MODIFIES',
'NATURAL',
'NO_WRITE_TO_BINLOG',
'NOT',
'NULL',
'NUMERIC',
'ON',
'OPTIMIZE',
'OPTION',
'OPTIONALLY',
'OR',
'ORDER',
'OUT',
'OUTER',
'OUTFILE',
'PRECISION',
'PRIMARY',
'PROCEDURE',
'PURGE',
'RANGE',
'READ',
'READ_WRITE',
'READS',
'REAL',
'REFERENCES',
'REGEXP',
'RELEASE',
'RENAME',
'REPEAT',
'REPLACE',
'REQUIRE',
'RESIGNAL',
'RESIGNAL',
'RESTRICT',
'RETURN',
'REVOKE',
'RIGHT',
'RLIKE',
'SCHEMA',
'SCHEMAS',
'SECOND_MICROSECOND',
'SELECT',
'SENSITIVE',
'SEPARATOR',
'SET',
'SHOW',
'SIGNAL',
'SIGNAL',
'SMALLINT',
'SPATIAL',
'SPECIFIC',
'SQL',
'SQL_BIG_RESULT',
'SQL_CALC_FOUND_ROWS',
'SQL_SMALL_RESULT',
'SQLEXCEPTION',
'SQLSTATE',
'SQLWARNING',
'SSL',
'STARTING',
'STRAIGHT_JOIN',
'TABLE',
'TERMINATED',
'THEN',
'TINYBLOB',
'TINYINT',
'TINYTEXT',
'TO',
'TRAILING',
'TRIGGER',
'TRUE',
'UNDO',
'UNION',
'UNIQUE',
'UNLOCK',
'UNSIGNED',
'UPDATE',
'USAGE',
'USE',
'USING',
'UTC_DATE',
'UTC_TIME',
'UTC_TIMESTAMP',
'VALUES',
'VARBINARY',
'VARCHAR',
'VARCHARACTER',
'VARYING',
'WHEN',
'WHERE',
'WHILE',
'WITH',
'WRITE',
'XOR',
'YEAR_MONTH',
'ZEROFILL',
))
MSSQL = set((
'ADD',
'ALL',
'ALTER',
'AND',
'ANY',
'AS',
'ASC',
'AUTHORIZATION',
'BACKUP',
'BEGIN',
'BETWEEN',
'BREAK',
'BROWSE',
'BULK',
'BY',
'CASCADE',
'CASE',
'CHECK',
'CHECKPOINT',
'CLOSE',
'CLUSTERED',
'COALESCE',
'COLLATE',
'COLUMN',
'COMMIT',
'COMPUTE',
'CONSTRAINT',
'CONTAINS',
'CONTAINSTABLE',
'CONTINUE',
'CONVERT',
'CREATE',
'CROSS',
'CURRENT',
'CURRENT_DATE',
'CURRENT_TIME',
'CURRENT_TIMESTAMP',
'CURRENT_USER',
'CURSOR',
'DATABASE',
'DBCC',
'DEALLOCATE',
'DECLARE',
'DEFAULT',
'DELETE',
'DENY',
'DESC',
'DISK',
'DISTINCT',
'DISTRIBUTED',
'DOUBLE',
'DROP',
'DUMMY',
'DUMP',
'ELSE',
'END',
'ERRLVL',
'ESCAPE',
'EXCEPT',
'EXEC',
'EXECUTE',
'EXISTS',
'EXIT',
'FETCH',
'FILE',
'FILLFACTOR',
'FOR',
'FOREIGN',
'FREETEXT',
'FREETEXTTABLE',
'FROM',
'FULL',
'FUNCTION',
'GOTO',
'GRANT',
'GROUP',
'HAVING',
'HOLDLOCK',
'IDENTITY',
'IDENTITY_INSERT',
'IDENTITYCOL',
'IF',
'IN',
'INDEX',
'INNER',
'INSERT',
'INTERSECT',
'INTO',
'IS',
'JOIN',
'KEY',
'KILL',
'LEFT',
'LIKE',
'LINENO',
'LOAD',
'NATIONAL ',
'NOCHECK',
'NONCLUSTERED',
'NOT',
'NULL',
'NULLIF',
'OF',
'OFF',
'OFFSETS',
'ON',
'OPEN',
'OPENDATASOURCE',
'OPENQUERY',
'OPENROWSET',
'OPENXML',
'OPTION',
'OR',
'ORDER',
'OUTER',
'OVER',
'PERCENT',
'PLAN',
'PRECISION',
'PRIMARY',
'PRINT',
'PROC',
'PROCEDURE',
'PUBLIC',
'RAISERROR',
'READ',
'READTEXT',
'RECONFIGURE',
'REFERENCES',
'REPLICATION',
'RESTORE',
'RESTRICT',
'RETURN',
'REVOKE',
'RIGHT',
'ROLLBACK',
'ROWCOUNT',
'ROWGUIDCOL',
'RULE',
'SAVE',
'SCHEMA',
'SELECT',
'SESSION_USER',
'SET',
'SETUSER',
'SHUTDOWN',
'SOME',
'STATISTICS',
'SYSTEM_USER',
'TABLE',
'TEXTSIZE',
'THEN',
'TO',
'TOP',
'TRAN',
'TRANSACTION',
'TRIGGER',
'TRUNCATE',
'TSEQUAL',
'UNION',
'UNIQUE',
'UPDATE',
'UPDATETEXT',
'USE',
'USER',
'VALUES',
'VARYING',
'VIEW',
'WAITFOR',
'WHEN',
'WHERE',
'WHILE',
'WITH',
'WRITETEXT',
))
ORACLE = set((
'ACCESS',
'ADD',
'ALL',
'ALTER',
'AND',
'ANY',
'AS',
'ASC',
'AUDIT',
'BETWEEN',
'BY',
'CHAR',
'CHECK',
'CLUSTER',
'COLUMN',
'COMMENT',
'COMPRESS',
'CONNECT',
'CREATE',
'CURRENT',
'DATE',
'DECIMAL',
'DEFAULT',
'DELETE',
'DESC',
'DISTINCT',
'DROP',
'ELSE',
'EXCLUSIVE',
'EXISTS',
'FILE',
'FLOAT',
'FOR',
'FROM',
'GRANT',
'GROUP',
'HAVING',
'IDENTIFIED',
'IMMEDIATE',
'IN',
'INCREMENT',
'INDEX',
'INITIAL',
'INSERT',
'INTEGER',
'INTERSECT',
'INTO',
'IS',
'LEVEL',
'LIKE',
'LOCK',
'LONG',
'MAXEXTENTS',
'MINUS',
'MLSLABEL',
'MODE',
'MODIFY',
'NOAUDIT',
'NOCOMPRESS',
'NOT',
'NOWAIT',
'NULL',
'NUMBER',
'OF',
'OFFLINE',
'ON',
'ONLINE',
'OPTION',
'OR',
'ORDER',
'PCTFREE',
'PRIOR',
'PRIVILEGES',
'PUBLIC',
'RAW',
'RENAME',
'RESOURCE',
'REVOKE',
'ROW',
'ROWID',
'ROWNUM',
'ROWS',
'SELECT',
'SESSION',
'SET',
'SHARE',
'SIZE',
'SMALLINT',
'START',
'SUCCESSFUL',
'SYNONYM',
'SYSDATE',
'TABLE',
'THEN',
'TO',
'TRIGGER',
'UID',
'UNION',
'UNIQUE',
'UPDATE',
'USER',
'VALIDATE',
'VALUES',
'VARCHAR',
'VARCHAR2',
'VIEW',
'WHENEVER',
'WHERE',
'WITH',
))
SQLITE = set((
'ABORT',
'ACTION',
'ADD',
'AFTER',
'ALL',
'ALTER',
'ANALYZE',
'AND',
'AS',
'ASC',
'ATTACH',
'AUTOINCREMENT',
'BEFORE',
'BEGIN',
'BETWEEN',
'BY',
'CASCADE',
'CASE',
'CAST',
'CHECK',
'COLLATE',
'COLUMN',
'COMMIT',
'CONFLICT',
'CONSTRAINT',
'CREATE',
'CROSS',
'CURRENT_DATE',
'CURRENT_TIME',
'CURRENT_TIMESTAMP',
'DATABASE',
'DEFAULT',
'DEFERRABLE',
'DEFERRED',
'DELETE',
'DESC',
'DETACH',
'DISTINCT',
'DROP',
'EACH',
'ELSE',
'END',
'ESCAPE',
'EXCEPT',
'EXCLUSIVE',
'EXISTS',
'EXPLAIN',
'FAIL',
'FOR',
'FOREIGN',
'FROM',
'FULL',
'GLOB',
'GROUP',
'HAVING',
'IF',
'IGNORE',
'IMMEDIATE',
'IN',
'INDEX',
'INDEXED',
'INITIALLY',
'INNER',
'INSERT',
'INSTEAD',
'INTERSECT',
'INTO',
'IS',
'ISNULL',
'JOIN',
'KEY',
'LEFT',
'LIKE',
'LIMIT',
'MATCH',
'NATURAL',
'NO',
'NOT',
'NOTNULL',
'NULL',
'OF',
'OFFSET',
'ON',
'OR',
'ORDER',
'OUTER',
'PLAN',
'PRAGMA',
'PRIMARY',
'QUERY',
'RAISE',
'REFERENCES',
'REGEXP',
'REINDEX',
'RELEASE',
'RENAME',
'REPLACE',
'RESTRICT',
'RIGHT',
'ROLLBACK',
'ROW',
'SAVEPOINT',
'SELECT',
'SET',
'TABLE',
'TEMP',
'TEMPORARY',
'THEN',
'TO',
'TRANSACTION',
'TRIGGER',
'UNION',
'UNIQUE',
'UPDATE',
'USING',
'VACUUM',
'VALUES',
'VIEW',
'VIRTUAL',
'WHEN',
'WHERE',
))
MONGODB_NONRESERVED = set(('SAFE',))
# remove from here when you add a list.
JDBCSQLITE = SQLITE
DB2 = INFORMIX = INGRES = JDBCPOSTGRESQL = COMMON
ADAPTERS = {
'sqlite': SQLITE,
'mysql': MYSQL,
'postgres': POSTGRESQL,
'postgres_nonreserved': POSTGRESQL_NONRESERVED,
'oracle': ORACLE,
'mssql': MSSQL,
'mssql2': MSSQL,
'db2': DB2,
'informix': INFORMIX,
'firebird': FIREBIRD,
'firebird_embedded': FIREBIRD,
'firebird_nonreserved': FIREBIRD_NONRESERVED,
'ingres': INGRES,
'ingresu': INGRES,
'jdbc:sqlite': JDBCSQLITE,
'jdbc:postgres': JDBCPOSTGRESQL,
'common': COMMON,
'mongodb_nonreserved': MONGODB_NONRESERVED
}
ADAPTERS['all'] = reduce(lambda a, b: a.union(b), (
x for x in ADAPTERS.values()))
|
bsd-3-clause
|
[
3,
2644,
2774,
13,
24,
199,
199,
363,
2502,
363,
275,
298,
52,
2411,
271,
527,
699,
300,
303,
385,
665,
273,
9587,
17411,
32,
273,
9587,
17411,
14,
957,
4335,
199,
199,
3,
259,
781,
28837,
465,
298,
2865,
13,
10421,
2,
5204,
790,
5932,
626,
787,
7662,
6040,
199,
3,
259,
370,
314,
1798,
1325,
787,
4370,
465,
2763,
503,
1817,
1561,
14,
6601,
790,
5932,
199,
3,
259,
626,
787,
4257,
2222,
13,
10421,
3913,
506,
1202,
465,
805,
503,
666,
730,
302,
199,
3,
259,
282,
6415,
436,
787,
315,
314,
2222,
10421,
769,
14,
334,
24625,
402,
3520,
5932,
2954,
199,
3,
259,
6137,
13,
262,
3423,
503,
666,
2943,
543,
4539,
6302,
14,
710,
805,
199,
3,
259,
503,
730,
365,
5139,
2808,
1325,
652,
3913,
506,
295,
4037,
701,
314,
922,
4959,
199,
3,
259,
491,
14502,
298,
10421,
2,
787,
5204,
4645,
626,
787,
440,
4370,
465,
2763,
503,
199,
3,
259,
1817,
1561,
14,
6601,
4644,
790,
5932,
787,
32518,
465,
1561,
367,
199,
3,
259,
3423,
503,
666,
2943,
277,
14,
199,
199,
3,
3390,
737,
314,
9048,
402,
314,
769,
365,
282,
1211,
3035,
6941,
370,
314,
199,
3,
6346,
12,
436,
2597,
340,
1265,
1050,
282,
769,
2793,
1133,
19459,
370,
2813,
2399,
849,
199,
3,
663,
402,
11293,
615,
14,
199,
199,
3,
2606,
3148,
626,
787,
12146,
2488,
14,
32753,
465,
282,
769,
402,
298,
15437,
2,
199,
3,
503,
298,
8644,
2,
7681,
199,
199,
3,
5723,
787,
7681,
626,
787,
2863,
370,
1006,
5385,
10982,
83,
12,
436,
1077,
199,
3,
7078,
506,
1202,
465,
282,
1817,
503,
2763,
14,
22207,
340,
1265,
675,
1373,
402,
3520,
199,
3,
314,
3920,
911,
7978,
376,
6654,
6279,
547,
367,
314,
5385,
6302,
14,
199,
199,
504,
1275,
423,
5819,
492,
7843,
18,
199,
199,
692,
440,
7843,
18,
26,
272,
687,
9143,
492,
7114,
199,
199,
21637,
275,
663,
1332,
272,
283,
4859,
297,
272,
283,
10258,
297,
272,
283,
7014,
297,
272,
283,
10383,
297,
272,
283,
14764,
297,
272,
283,
8366,
297,
272,
283,
19350,
297,
339,
283,
17688,
297,
272,
283,
12491,
297,
272,
283,
31031,
297,
272,
283,
23321,
297,
272,
283,
3649,
297,
272,
283,
726,
297,
272,
283,
21929,
297,
272,
283,
615,
297,
272,
283,
568,
297,
272,
283,
3597,
297,
339,
283,
8285,
297,
272,
283,
7823,
297,
272,
283,
12125,
297,
272,
283,
9894,
297,
272,
283,
1877,
540,
297,
339,
283,
4656,
297,
272,
283,
3902,
297,
272,
283,
2080,
742,
297,
272,
283,
26573,
297,
272,
283,
1179,
297,
272,
283,
2901,
899,
297,
272,
283,
2707,
297,
339,
283,
11320,
297,
272,
283,
9792,
742,
297,
272,
283,
4896,
297,
272,
283,
4283,
297,
272,
283,
13783,
28437,
297,
199,
430,
421,
199,
4030,
39,
3830,
2940,
275,
663,
1332,
272,
283,
19823,
297,
272,
283,
15064,
297,
272,
283,
1761,
297,
272,
283,
31158,
57,
899,
297,
272,
283,
31158,
57,
3687,
297,
272,
283,
3649,
297,
272,
283,
8974,
297,
272,
283,
12322,
297,
272,
283,
1179,
297,
272,
283,
22767,
297,
272,
283,
26222,
3218,
775,
14673,
297,
272,
283,
25303,
2594,
297,
272,
283,
34,
29056,
297,
272,
283,
18643,
2919,
297,
272,
283,
13246,
297,
272,
283,
11970,
297,
272,
283,
25312,
297,
272,
283,
28784,
297,
272,
283,
11320,
297,
272,
283,
18898,
297,
272,
283,
5901,
297,
272,
283,
29007,
297,
272,
283,
8936,
297,
272,
283,
1439,
748,
654,
2089,
297,
272,
283,
3978,
30064,
297,
272,
283,
21436,
297,
272,
283,
30062,
297,
272,
283,
8366,
297,
272,
283,
28368,
297,
272,
283,
14211,
63,
11206,
23622,
297,
272,
283,
14211,
63,
5390,
297,
272,
283,
14211,
63,
15468,
297,
272,
283,
14211,
63,
10926,
297,
272,
283,
14211,
63,
4961,
297,
272,
283,
14211,
63,
20277,
297,
272,
283,
14211,
63,
3791,
297,
272,
283,
16387,
297,
272,
283,
23925,
297,
272,
283,
3472,
297,
272,
283,
5638,
2666,
2617,
297,
272,
283,
15119,
297,
272,
283,
13783,
28437,
297,
272,
283,
1649,
297,
272,
283,
2901,
899,
297,
272,
283,
3902,
297,
272,
283,
11764,
297,
272,
283,
23558,
297,
272,
283,
30335,
297,
272,
283,
32097,
297,
272,
283,
11783,
297,
272,
283,
2707,
297,
272,
283,
18155,
3203,
297,
272,
283,
28170,
3687,
297,
272,
283,
12491,
297,
272,
283,
14742,
297,
272,
283,
3975,
1441,
297,
272,
283,
39,
907,
619,
1719,
297,
272,
283,
7823,
297,
272,
283,
40,
6087,
1206,
297,
272,
283,
1193,
41,
2430,
297,
272,
283,
568,
297,
272,
283,
8727,
41,
28292,
297,
272,
283,
31031,
297,
272,
283,
568,
1877,
297,
272,
283,
2919,
297,
272,
283,
9596,
297,
272,
283,
3843,
32379,
297,
272,
283,
17359,
297,
272,
283,
568,
2566,
297,
272,
283,
1311,
297,
272,
283,
1311,
8084,
297,
272,
283,
23321,
297,
272,
283,
906,
1554,
1206,
297,
272,
283,
906,
11307,
297,
272,
283,
9894,
297,
272,
283,
21929,
297,
272,
283,
13387,
297,
272,
283,
7486,
4961,
297,
272,
283,
7486,
20277,
297,
272,
283,
46,
2594,
748,
297,
272,
283,
28927,
1230,
748,
297,
272,
283,
46,
5901,
297,
272,
283,
11365,
297,
272,
283,
9185,
297,
272,
283,
4609,
297,
272,
283,
4609,
8084,
297,
272,
283,
8084,
297,
272,
283,
46,
1293,
2673,
38,
297,
272,
283,
28425,
297,
272,
283,
7517,
297,
272,
283,
14839,
297,
272,
283,
5104,
297,
272,
283,
615,
297,
272,
283,
10452,
297,
272,
283,
726,
297,
272,
283,
12125,
297,
272,
283,
1877,
297,
272,
283,
1877,
540,
297,
272,
283,
14336,
44,
1282,
51,
297,
272,
283,
14336,
16897,
297,
272,
283,
2749,
1348,
1206,
297,
272,
283,
15717,
297,
272,
283,
14246,
30011,
297,
272,
283,
31035,
297,
272,
283,
15508,
297,
272,
283,
19494,
22243,
297,
272,
283,
7341,
1230,
6024,
297,
272,
283,
12811,
297,
272,
283,
11415,
297,
272,
283,
4859,
297,
272,
283,
12763,
63,
3791,
297,
272,
283,
3597,
3359,
297,
272,
283,
16590,
1193,
689,
297,
272,
283,
28570,
2919,
297,
272,
283,
4118,
3635,
297,
272,
283,
6348,
5353,
297,
272
] |
[
2644,
2774,
13,
24,
199,
199,
363,
2502,
363,
275,
298,
52,
2411,
271,
527,
699,
300,
303,
385,
665,
273,
9587,
17411,
32,
273,
9587,
17411,
14,
957,
4335,
199,
199,
3,
259,
781,
28837,
465,
298,
2865,
13,
10421,
2,
5204,
790,
5932,
626,
787,
7662,
6040,
199,
3,
259,
370,
314,
1798,
1325,
787,
4370,
465,
2763,
503,
1817,
1561,
14,
6601,
790,
5932,
199,
3,
259,
626,
787,
4257,
2222,
13,
10421,
3913,
506,
1202,
465,
805,
503,
666,
730,
302,
199,
3,
259,
282,
6415,
436,
787,
315,
314,
2222,
10421,
769,
14,
334,
24625,
402,
3520,
5932,
2954,
199,
3,
259,
6137,
13,
262,
3423,
503,
666,
2943,
543,
4539,
6302,
14,
710,
805,
199,
3,
259,
503,
730,
365,
5139,
2808,
1325,
652,
3913,
506,
295,
4037,
701,
314,
922,
4959,
199,
3,
259,
491,
14502,
298,
10421,
2,
787,
5204,
4645,
626,
787,
440,
4370,
465,
2763,
503,
199,
3,
259,
1817,
1561,
14,
6601,
4644,
790,
5932,
787,
32518,
465,
1561,
367,
199,
3,
259,
3423,
503,
666,
2943,
277,
14,
199,
199,
3,
3390,
737,
314,
9048,
402,
314,
769,
365,
282,
1211,
3035,
6941,
370,
314,
199,
3,
6346,
12,
436,
2597,
340,
1265,
1050,
282,
769,
2793,
1133,
19459,
370,
2813,
2399,
849,
199,
3,
663,
402,
11293,
615,
14,
199,
199,
3,
2606,
3148,
626,
787,
12146,
2488,
14,
32753,
465,
282,
769,
402,
298,
15437,
2,
199,
3,
503,
298,
8644,
2,
7681,
199,
199,
3,
5723,
787,
7681,
626,
787,
2863,
370,
1006,
5385,
10982,
83,
12,
436,
1077,
199,
3,
7078,
506,
1202,
465,
282,
1817,
503,
2763,
14,
22207,
340,
1265,
675,
1373,
402,
3520,
199,
3,
314,
3920,
911,
7978,
376,
6654,
6279,
547,
367,
314,
5385,
6302,
14,
199,
199,
504,
1275,
423,
5819,
492,
7843,
18,
199,
199,
692,
440,
7843,
18,
26,
272,
687,
9143,
492,
7114,
199,
199,
21637,
275,
663,
1332,
272,
283,
4859,
297,
272,
283,
10258,
297,
272,
283,
7014,
297,
272,
283,
10383,
297,
272,
283,
14764,
297,
272,
283,
8366,
297,
272,
283,
19350,
297,
339,
283,
17688,
297,
272,
283,
12491,
297,
272,
283,
31031,
297,
272,
283,
23321,
297,
272,
283,
3649,
297,
272,
283,
726,
297,
272,
283,
21929,
297,
272,
283,
615,
297,
272,
283,
568,
297,
272,
283,
3597,
297,
339,
283,
8285,
297,
272,
283,
7823,
297,
272,
283,
12125,
297,
272,
283,
9894,
297,
272,
283,
1877,
540,
297,
339,
283,
4656,
297,
272,
283,
3902,
297,
272,
283,
2080,
742,
297,
272,
283,
26573,
297,
272,
283,
1179,
297,
272,
283,
2901,
899,
297,
272,
283,
2707,
297,
339,
283,
11320,
297,
272,
283,
9792,
742,
297,
272,
283,
4896,
297,
272,
283,
4283,
297,
272,
283,
13783,
28437,
297,
199,
430,
421,
199,
4030,
39,
3830,
2940,
275,
663,
1332,
272,
283,
19823,
297,
272,
283,
15064,
297,
272,
283,
1761,
297,
272,
283,
31158,
57,
899,
297,
272,
283,
31158,
57,
3687,
297,
272,
283,
3649,
297,
272,
283,
8974,
297,
272,
283,
12322,
297,
272,
283,
1179,
297,
272,
283,
22767,
297,
272,
283,
26222,
3218,
775,
14673,
297,
272,
283,
25303,
2594,
297,
272,
283,
34,
29056,
297,
272,
283,
18643,
2919,
297,
272,
283,
13246,
297,
272,
283,
11970,
297,
272,
283,
25312,
297,
272,
283,
28784,
297,
272,
283,
11320,
297,
272,
283,
18898,
297,
272,
283,
5901,
297,
272,
283,
29007,
297,
272,
283,
8936,
297,
272,
283,
1439,
748,
654,
2089,
297,
272,
283,
3978,
30064,
297,
272,
283,
21436,
297,
272,
283,
30062,
297,
272,
283,
8366,
297,
272,
283,
28368,
297,
272,
283,
14211,
63,
11206,
23622,
297,
272,
283,
14211,
63,
5390,
297,
272,
283,
14211,
63,
15468,
297,
272,
283,
14211,
63,
10926,
297,
272,
283,
14211,
63,
4961,
297,
272,
283,
14211,
63,
20277,
297,
272,
283,
14211,
63,
3791,
297,
272,
283,
16387,
297,
272,
283,
23925,
297,
272,
283,
3472,
297,
272,
283,
5638,
2666,
2617,
297,
272,
283,
15119,
297,
272,
283,
13783,
28437,
297,
272,
283,
1649,
297,
272,
283,
2901,
899,
297,
272,
283,
3902,
297,
272,
283,
11764,
297,
272,
283,
23558,
297,
272,
283,
30335,
297,
272,
283,
32097,
297,
272,
283,
11783,
297,
272,
283,
2707,
297,
272,
283,
18155,
3203,
297,
272,
283,
28170,
3687,
297,
272,
283,
12491,
297,
272,
283,
14742,
297,
272,
283,
3975,
1441,
297,
272,
283,
39,
907,
619,
1719,
297,
272,
283,
7823,
297,
272,
283,
40,
6087,
1206,
297,
272,
283,
1193,
41,
2430,
297,
272,
283,
568,
297,
272,
283,
8727,
41,
28292,
297,
272,
283,
31031,
297,
272,
283,
568,
1877,
297,
272,
283,
2919,
297,
272,
283,
9596,
297,
272,
283,
3843,
32379,
297,
272,
283,
17359,
297,
272,
283,
568,
2566,
297,
272,
283,
1311,
297,
272,
283,
1311,
8084,
297,
272,
283,
23321,
297,
272,
283,
906,
1554,
1206,
297,
272,
283,
906,
11307,
297,
272,
283,
9894,
297,
272,
283,
21929,
297,
272,
283,
13387,
297,
272,
283,
7486,
4961,
297,
272,
283,
7486,
20277,
297,
272,
283,
46,
2594,
748,
297,
272,
283,
28927,
1230,
748,
297,
272,
283,
46,
5901,
297,
272,
283,
11365,
297,
272,
283,
9185,
297,
272,
283,
4609,
297,
272,
283,
4609,
8084,
297,
272,
283,
8084,
297,
272,
283,
46,
1293,
2673,
38,
297,
272,
283,
28425,
297,
272,
283,
7517,
297,
272,
283,
14839,
297,
272,
283,
5104,
297,
272,
283,
615,
297,
272,
283,
10452,
297,
272,
283,
726,
297,
272,
283,
12125,
297,
272,
283,
1877,
297,
272,
283,
1877,
540,
297,
272,
283,
14336,
44,
1282,
51,
297,
272,
283,
14336,
16897,
297,
272,
283,
2749,
1348,
1206,
297,
272,
283,
15717,
297,
272,
283,
14246,
30011,
297,
272,
283,
31035,
297,
272,
283,
15508,
297,
272,
283,
19494,
22243,
297,
272,
283,
7341,
1230,
6024,
297,
272,
283,
12811,
297,
272,
283,
11415,
297,
272,
283,
4859,
297,
272,
283,
12763,
63,
3791,
297,
272,
283,
3597,
3359,
297,
272,
283,
16590,
1193,
689,
297,
272,
283,
28570,
2919,
297,
272,
283,
4118,
3635,
297,
272,
283,
6348,
5353,
297,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
DiamondLightSource/auto_tomo_calibration-experimental
|
old_code_scripts/measure_resolution/lmfit-py/examples/example_covar.py
|
4
|
2319
|
import sys
from numpy import linspace, zeros, sin, exp, random, sqrt, pi, sign
from scipy.optimize import leastsq
from lmfit import Parameters, Minimizer, report_fit
from lmfit.lineshapes import gaussian
try:
import pylab
HASPYLAB = True
except ImportError:
HASPYLAB = False
HASPYLAB = False
def residual(pars, x, sigma=None, data=None):
yg = gaussian(x, pars['amp_g'].value,
pars['cen_g'].value, pars['wid_g'].value)
slope = pars['line_slope'].value
offset = pars['line_off'].value
model = yg + offset + x * slope
if data is None:
return model
if sigma is None:
return (model - data)
return (model - data)/sigma
n = 201
xmin = 0.
xmax = 20.0
x = linspace(xmin, xmax, n)
p_true = Parameters()
p_true.add('amp_g', value=21.0)
p_true.add('cen_g', value=8.1)
p_true.add('wid_g', value=1.6)
p_true.add('line_off', value=-1.023)
p_true.add('line_slope', value=0.62)
data = (gaussian(x, p_true['amp_g'].value, p_true['cen_g'].value,
p_true['wid_g'].value) +
random.normal(scale=0.23, size=n) +
x*p_true['line_slope'].value + p_true['line_off'].value )
if HASPYLAB:
pylab.plot(x, data, 'r+')
p_fit = Parameters()
p_fit.add('amp_g', value=10.0)
p_fit.add('cen_g', value=9)
p_fit.add('wid_g', value=1)
p_fit.add('line_slope', value=0.0)
p_fit.add('line_off', value=0.0)
myfit = Minimizer(residual, p_fit,
fcn_args=(x,),
fcn_kws={'sigma':0.2, 'data':data})
myfit.prepare_fit()
#
for scale_covar in (True, False):
myfit.scale_covar = scale_covar
print ' ==== scale_covar = ', myfit.scale_covar, ' ==='
for sigma in (0.1, 0.2, 0.23, 0.5):
myfit.userkws['sigma'] = sigma
p_fit['amp_g'].value = 10
p_fit['cen_g'].value = 9
p_fit['wid_g'].value = 1
p_fit['line_slope'].value =0.0
p_fit['line_off'].value =0.0
out = myfit.leastsq()
print ' sigma = ', sigma
print ' chisqr = ', out.chisqr
print ' reduced_chisqr = ', out.redchi
report_fit(out.params, modelpars=p_true, show_correl=False)
print ' =============================='
# if HASPYLAB:
# fit = residual(p_fit, x)
# pylab.plot(x, fit, 'k-')
# pylab.show()
#
|
apache-2.0
|
[
646,
984,
199,
504,
2680,
492,
7403,
2638,
12,
10136,
12,
9829,
12,
1437,
12,
2196,
12,
7452,
12,
6682,
12,
2070,
199,
504,
7026,
14,
13416,
492,
5210,
3526,
199,
199,
504,
24546,
3269,
492,
3897,
12,
10195,
1017,
1793,
12,
3622,
63,
3269,
199,
504,
24546,
3269,
14,
1278,
15221,
83,
492,
28912,
199,
199,
893,
26,
272,
492,
19199,
272,
7509,
4521,
12019,
275,
715,
199,
2590,
3545,
26,
272,
7509,
4521,
12019,
275,
756,
199,
199,
13533,
4521,
12019,
275,
756,
199,
199,
318,
16731,
8,
21152,
12,
671,
12,
10819,
29,
403,
12,
666,
29,
403,
304,
272,
612,
71,
275,
28912,
8,
88,
12,
30903,
459,
5282,
63,
71,
2278,
585,
12,
2116,
30903,
459,
2497,
63,
71,
2278,
585,
12,
30903,
459,
19686,
63,
71,
2278,
585,
9,
339,
24140,
275,
30903,
459,
604,
63,
25278,
2278,
585,
272,
3268,
275,
30903,
459,
604,
63,
1997,
2278,
585,
272,
1402,
275,
612,
71,
435,
3268,
435,
671,
627,
24140,
272,
340,
666,
365,
488,
26,
267,
372,
1402,
272,
340,
10819,
365,
221,
488,
26,
267,
372,
334,
1238,
446,
666,
9,
339,
372,
334,
1238,
446,
666,
2447,
9412,
421,
199,
78,
275,
1784,
199,
21601,
275,
378,
14,
199,
28961,
275,
3388,
14,
16,
199,
88,
275,
7403,
2638,
8,
21601,
12,
19906,
12,
302,
9,
199,
199,
80,
63,
2052,
275,
3897,
342,
199,
80,
63,
2052,
14,
525,
360,
5282,
63,
71,
297,
574,
29,
2025,
14,
16,
9,
199,
80,
63,
2052,
14,
525,
360,
2497,
63,
71,
297,
574,
29,
24,
14,
17,
9,
199,
80,
63,
2052,
14,
525,
360,
19686,
63,
71,
297,
574,
29,
17,
14,
22,
9,
199,
80,
63,
2052,
14,
525,
360,
604,
63,
1997,
297,
574,
4022,
17,
14,
16771,
9,
199,
80,
63,
2052,
14,
525,
360,
604,
63,
25278,
297,
574,
29,
16,
14,
2789,
9,
199,
199,
576,
275,
334,
22911,
8,
88,
12,
299,
63,
2052,
459,
5282,
63,
71,
2278,
585,
12,
299,
63,
2052,
459,
2497,
63,
71,
2278,
585,
12,
326,
299,
63,
2052,
459,
19686,
63,
71,
2278,
585,
9,
435,
267,
2196,
14,
3302,
8,
3467,
29,
16,
14,
1789,
12,
221,
1568,
29,
78,
9,
435,
267,
671,
10,
80,
63,
2052,
459,
604,
63,
25278,
2278,
585,
435,
299,
63,
2052,
459,
604,
63,
1997,
2278,
585,
776,
199,
199,
692,
7509,
4521,
12019,
26,
272,
19199,
14,
2798,
8,
88,
12,
666,
12,
283,
82,
13854,
199,
199,
80,
63,
3269,
275,
3897,
342,
199,
80,
63,
3269,
14,
525,
360,
5282,
63,
71,
297,
574,
29,
709,
14,
16,
9,
199,
80,
63,
3269,
14,
525,
360,
2497,
63,
71,
297,
574,
29,
25,
9,
199,
80,
63,
3269,
14,
525,
360,
19686,
63,
71,
297,
574,
29,
17,
9,
199,
80,
63,
3269,
14,
525,
360,
604,
63,
25278,
297,
574,
29,
16,
14,
16,
9,
199,
80,
63,
3269,
14,
525,
360,
604,
63,
1997,
297,
574,
29,
16,
14,
16,
9,
199,
199,
1662,
3269,
275,
10195,
1017,
1793,
8,
20161,
12,
299,
63,
3269,
12,
2116,
289,
6413,
63,
589,
2687,
88,
4706,
2116,
289,
6413,
63,
28769,
3713,
9412,
356,
16,
14,
18,
12,
283,
576,
356,
576,
1552,
199,
199,
1662,
3269,
14,
6726,
63,
3269,
342,
199,
3,
199,
509,
4666,
63,
331,
1391,
315,
334,
549,
12,
756,
304,
272,
3002,
3269,
14,
3467,
63,
331,
1391,
275,
4666,
63,
331,
1391,
272,
870,
283,
221,
275,
5918,
221,
4666,
63,
331,
1391,
275,
1656,
3002,
3269,
14,
3467,
63,
331,
1391,
12,
283,
275,
6803,
272,
367,
10819,
315,
334,
16,
14,
17,
12,
378,
14,
18,
12,
378,
14,
1789,
12,
378,
14,
21,
304,
267,
3002,
3269,
14,
751,
28769,
459,
9412,
418,
275,
10819,
398,
299,
63,
3269,
459,
5282,
63,
71,
2278,
585,
221,
275,
1616,
267,
299,
63,
3269,
459,
2497,
63,
71,
2278,
585,
221,
275,
221,
1749,
267,
299,
63,
3269,
459,
19686,
63,
71,
2278,
585,
221,
275,
221,
413,
267,
299,
63,
3269,
459,
604,
63,
25278,
2278,
585,
275,
16,
14,
16,
267,
299,
63,
3269,
459,
604,
63,
1997,
2278,
585,
257,
275,
16,
14,
16,
398,
734,
275,
3002,
3269,
14,
11790,
3526,
342,
267,
870,
283,
221,
10819,
3515,
275,
1656,
10819,
267,
870,
283,
221,
682,
374,
16596,
260,
275,
1656,
734,
14,
30883,
16596,
267,
870,
283,
221,
14953,
63,
30883,
16596,
275,
1656,
734,
14,
581,
13175,
398,
3622,
63,
3269,
8,
548,
14,
1162,
12,
1402,
21152,
29,
80,
63,
2052,
12,
2498,
63,
989,
3369,
29,
797,
9,
267,
870,
283,
221,
16248,
5769,
534,
421,
199,
3,
340,
7509,
4521,
12019,
26,
199,
3,
258,
5542,
275,
16731,
8,
80,
63,
3269,
12,
671,
9,
199,
3,
258,
19199,
14,
2798,
8,
88,
12,
5542,
12,
283,
75,
25815,
199,
3,
258,
19199,
14,
2384,
342,
199,
3,
28154,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
984,
199,
504,
2680,
492,
7403,
2638,
12,
10136,
12,
9829,
12,
1437,
12,
2196,
12,
7452,
12,
6682,
12,
2070,
199,
504,
7026,
14,
13416,
492,
5210,
3526,
199,
199,
504,
24546,
3269,
492,
3897,
12,
10195,
1017,
1793,
12,
3622,
63,
3269,
199,
504,
24546,
3269,
14,
1278,
15221,
83,
492,
28912,
199,
199,
893,
26,
272,
492,
19199,
272,
7509,
4521,
12019,
275,
715,
199,
2590,
3545,
26,
272,
7509,
4521,
12019,
275,
756,
199,
199,
13533,
4521,
12019,
275,
756,
199,
199,
318,
16731,
8,
21152,
12,
671,
12,
10819,
29,
403,
12,
666,
29,
403,
304,
272,
612,
71,
275,
28912,
8,
88,
12,
30903,
459,
5282,
63,
71,
2278,
585,
12,
2116,
30903,
459,
2497,
63,
71,
2278,
585,
12,
30903,
459,
19686,
63,
71,
2278,
585,
9,
339,
24140,
275,
30903,
459,
604,
63,
25278,
2278,
585,
272,
3268,
275,
30903,
459,
604,
63,
1997,
2278,
585,
272,
1402,
275,
612,
71,
435,
3268,
435,
671,
627,
24140,
272,
340,
666,
365,
488,
26,
267,
372,
1402,
272,
340,
10819,
365,
221,
488,
26,
267,
372,
334,
1238,
446,
666,
9,
339,
372,
334,
1238,
446,
666,
2447,
9412,
421,
199,
78,
275,
1784,
199,
21601,
275,
378,
14,
199,
28961,
275,
3388,
14,
16,
199,
88,
275,
7403,
2638,
8,
21601,
12,
19906,
12,
302,
9,
199,
199,
80,
63,
2052,
275,
3897,
342,
199,
80,
63,
2052,
14,
525,
360,
5282,
63,
71,
297,
574,
29,
2025,
14,
16,
9,
199,
80,
63,
2052,
14,
525,
360,
2497,
63,
71,
297,
574,
29,
24,
14,
17,
9,
199,
80,
63,
2052,
14,
525,
360,
19686,
63,
71,
297,
574,
29,
17,
14,
22,
9,
199,
80,
63,
2052,
14,
525,
360,
604,
63,
1997,
297,
574,
4022,
17,
14,
16771,
9,
199,
80,
63,
2052,
14,
525,
360,
604,
63,
25278,
297,
574,
29,
16,
14,
2789,
9,
199,
199,
576,
275,
334,
22911,
8,
88,
12,
299,
63,
2052,
459,
5282,
63,
71,
2278,
585,
12,
299,
63,
2052,
459,
2497,
63,
71,
2278,
585,
12,
326,
299,
63,
2052,
459,
19686,
63,
71,
2278,
585,
9,
435,
267,
2196,
14,
3302,
8,
3467,
29,
16,
14,
1789,
12,
221,
1568,
29,
78,
9,
435,
267,
671,
10,
80,
63,
2052,
459,
604,
63,
25278,
2278,
585,
435,
299,
63,
2052,
459,
604,
63,
1997,
2278,
585,
776,
199,
199,
692,
7509,
4521,
12019,
26,
272,
19199,
14,
2798,
8,
88,
12,
666,
12,
283,
82,
13854,
199,
199,
80,
63,
3269,
275,
3897,
342,
199,
80,
63,
3269,
14,
525,
360,
5282,
63,
71,
297,
574,
29,
709,
14,
16,
9,
199,
80,
63,
3269,
14,
525,
360,
2497,
63,
71,
297,
574,
29,
25,
9,
199,
80,
63,
3269,
14,
525,
360,
19686,
63,
71,
297,
574,
29,
17,
9,
199,
80,
63,
3269,
14,
525,
360,
604,
63,
25278,
297,
574,
29,
16,
14,
16,
9,
199,
80,
63,
3269,
14,
525,
360,
604,
63,
1997,
297,
574,
29,
16,
14,
16,
9,
199,
199,
1662,
3269,
275,
10195,
1017,
1793,
8,
20161,
12,
299,
63,
3269,
12,
2116,
289,
6413,
63,
589,
2687,
88,
4706,
2116,
289,
6413,
63,
28769,
3713,
9412,
356,
16,
14,
18,
12,
283,
576,
356,
576,
1552,
199,
199,
1662,
3269,
14,
6726,
63,
3269,
342,
199,
3,
199,
509,
4666,
63,
331,
1391,
315,
334,
549,
12,
756,
304,
272,
3002,
3269,
14,
3467,
63,
331,
1391,
275,
4666,
63,
331,
1391,
272,
870,
283,
221,
275,
5918,
221,
4666,
63,
331,
1391,
275,
1656,
3002,
3269,
14,
3467,
63,
331,
1391,
12,
283,
275,
6803,
272,
367,
10819,
315,
334,
16,
14,
17,
12,
378,
14,
18,
12,
378,
14,
1789,
12,
378,
14,
21,
304,
267,
3002,
3269,
14,
751,
28769,
459,
9412,
418,
275,
10819,
398,
299,
63,
3269,
459,
5282,
63,
71,
2278,
585,
221,
275,
1616,
267,
299,
63,
3269,
459,
2497,
63,
71,
2278,
585,
221,
275,
221,
1749,
267,
299,
63,
3269,
459,
19686,
63,
71,
2278,
585,
221,
275,
221,
413,
267,
299,
63,
3269,
459,
604,
63,
25278,
2278,
585,
275,
16,
14,
16,
267,
299,
63,
3269,
459,
604,
63,
1997,
2278,
585,
257,
275,
16,
14,
16,
398,
734,
275,
3002,
3269,
14,
11790,
3526,
342,
267,
870,
283,
221,
10819,
3515,
275,
1656,
10819,
267,
870,
283,
221,
682,
374,
16596,
260,
275,
1656,
734,
14,
30883,
16596,
267,
870,
283,
221,
14953,
63,
30883,
16596,
275,
1656,
734,
14,
581,
13175,
398,
3622,
63,
3269,
8,
548,
14,
1162,
12,
1402,
21152,
29,
80,
63,
2052,
12,
2498,
63,
989,
3369,
29,
797,
9,
267,
870,
283,
221,
16248,
5769,
534,
421,
199,
3,
340,
7509,
4521,
12019,
26,
199,
3,
258,
5542,
275,
16731,
8,
80,
63,
3269,
12,
671,
9,
199,
3,
258,
19199,
14,
2798,
8,
88,
12,
5542,
12,
283,
75,
25815,
199,
3,
258,
19199,
14,
2384,
342,
199,
3,
28154,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
HiroIshikawa/21playground
|
payblog/blog/lib/python3.5/site-packages/pygments/lexers/igor.py
|
72
|
16870
|
# -*- coding: utf-8 -*-
"""
pygments.lexers.igor
~~~~~~~~~~~~~~~~~~~~
Lexers for Igor Pro.
:copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
from pygments.lexer import RegexLexer, words
from pygments.token import Text, Comment, Keyword, Name, String
__all__ = ['IgorLexer']
class IgorLexer(RegexLexer):
"""
Pygments Lexer for Igor Pro procedure files (.ipf).
See http://www.wavemetrics.com/ and http://www.igorexchange.com/.
.. versionadded:: 2.0
"""
name = 'Igor'
aliases = ['igor', 'igorpro']
filenames = ['*.ipf']
mimetypes = ['text/ipf']
flags = re.IGNORECASE | re.MULTILINE
flowControl = (
'if', 'else', 'elseif', 'endif', 'for', 'endfor', 'strswitch', 'switch',
'case', 'default', 'endswitch', 'do', 'while', 'try', 'catch', 'endtry',
'break', 'continue', 'return',
)
types = (
'variable', 'string', 'constant', 'strconstant', 'NVAR', 'SVAR', 'WAVE',
'STRUCT', 'dfref'
)
keywords = (
'override', 'ThreadSafe', 'static', 'FuncFit', 'Proc', 'Picture',
'Prompt', 'DoPrompt', 'macro', 'window', 'graph', 'function', 'end',
'Structure', 'EndStructure', 'EndMacro', 'Menu', 'SubMenu',
)
operations = (
'Abort', 'AddFIFOData', 'AddFIFOVectData', 'AddMovieAudio',
'AddMovieFrame', 'APMath', 'Append', 'AppendImage',
'AppendLayoutObject', 'AppendMatrixContour', 'AppendText',
'AppendToGraph', 'AppendToLayout', 'AppendToTable', 'AppendXYZContour',
'AutoPositionWindow', 'BackgroundInfo', 'Beep', 'BoundingBall',
'BrowseURL', 'BuildMenu', 'Button', 'cd', 'Chart', 'CheckBox',
'CheckDisplayed', 'ChooseColor', 'Close', 'CloseMovie', 'CloseProc',
'ColorScale', 'ColorTab2Wave', 'Concatenate', 'ControlBar',
'ControlInfo', 'ControlUpdate', 'ConvexHull', 'Convolve', 'CopyFile',
'CopyFolder', 'CopyScales', 'Correlate', 'CreateAliasShortcut', 'Cross',
'CtrlBackground', 'CtrlFIFO', 'CtrlNamedBackground', 'Cursor',
'CurveFit', 'CustomControl', 'CWT', 'Debugger', 'DebuggerOptions',
'DefaultFont', 'DefaultGuiControls', 'DefaultGuiFont', 'DefineGuide',
'DelayUpdate', 'DeleteFile', 'DeleteFolder', 'DeletePoints',
'Differentiate', 'dir', 'Display', 'DisplayHelpTopic',
'DisplayProcedure', 'DoAlert', 'DoIgorMenu', 'DoUpdate', 'DoWindow',
'DoXOPIdle', 'DrawAction', 'DrawArc', 'DrawBezier', 'DrawLine',
'DrawOval', 'DrawPICT', 'DrawPoly', 'DrawRect', 'DrawRRect', 'DrawText',
'DSPDetrend', 'DSPPeriodogram', 'Duplicate', 'DuplicateDataFolder',
'DWT', 'EdgeStats', 'Edit', 'ErrorBars', 'Execute', 'ExecuteScriptText',
'ExperimentModified', 'Extract', 'FastGaussTransform', 'FastOp',
'FBinRead', 'FBinWrite', 'FFT', 'FIFO2Wave', 'FIFOStatus', 'FilterFIR',
'FilterIIR', 'FindLevel', 'FindLevels', 'FindPeak', 'FindPointsInPoly',
'FindRoots', 'FindSequence', 'FindValue', 'FPClustering', 'fprintf',
'FReadLine', 'FSetPos', 'FStatus', 'FTPDelete', 'FTPDownload',
'FTPUpload', 'FuncFit', 'FuncFitMD', 'GetAxis', 'GetFileFolderInfo',
'GetLastUserMenuInfo', 'GetMarquee', 'GetSelection', 'GetWindow',
'GraphNormal', 'GraphWaveDraw', 'GraphWaveEdit', 'Grep', 'GroupBox',
'Hanning', 'HideIgorMenus', 'HideInfo', 'HideProcedures', 'HideTools',
'HilbertTransform', 'Histogram', 'IFFT', 'ImageAnalyzeParticles',
'ImageBlend', 'ImageBoundaryToMask', 'ImageEdgeDetection',
'ImageFileInfo', 'ImageFilter', 'ImageFocus', 'ImageGenerateROIMask',
'ImageHistModification', 'ImageHistogram', 'ImageInterpolate',
'ImageLineProfile', 'ImageLoad', 'ImageMorphology', 'ImageRegistration',
'ImageRemoveBackground', 'ImageRestore', 'ImageRotate', 'ImageSave',
'ImageSeedFill', 'ImageSnake', 'ImageStats', 'ImageThreshold',
'ImageTransform', 'ImageUnwrapPhase', 'ImageWindow', 'IndexSort',
'InsertPoints', 'Integrate', 'IntegrateODE', 'Interp3DPath',
'Interpolate3D', 'KillBackground', 'KillControl', 'KillDataFolder',
'KillFIFO', 'KillFreeAxis', 'KillPath', 'KillPICTs', 'KillStrings',
'KillVariables', 'KillWaves', 'KillWindow', 'KMeans', 'Label', 'Layout',
'Legend', 'LinearFeedbackShiftRegister', 'ListBox', 'LoadData',
'LoadPackagePreferences', 'LoadPICT', 'LoadWave', 'Loess',
'LombPeriodogram', 'Make', 'MakeIndex', 'MarkPerfTestTime',
'MatrixConvolve', 'MatrixCorr', 'MatrixEigenV', 'MatrixFilter',
'MatrixGaussJ', 'MatrixInverse', 'MatrixLinearSolve',
'MatrixLinearSolveTD', 'MatrixLLS', 'MatrixLUBkSub', 'MatrixLUD',
'MatrixMultiply', 'MatrixOP', 'MatrixSchur', 'MatrixSolve',
'MatrixSVBkSub', 'MatrixSVD', 'MatrixTranspose', 'MeasureStyledText',
'Modify', 'ModifyContour', 'ModifyControl', 'ModifyControlList',
'ModifyFreeAxis', 'ModifyGraph', 'ModifyImage', 'ModifyLayout',
'ModifyPanel', 'ModifyTable', 'ModifyWaterfall', 'MoveDataFolder',
'MoveFile', 'MoveFolder', 'MoveString', 'MoveSubwindow', 'MoveVariable',
'MoveWave', 'MoveWindow', 'NeuralNetworkRun', 'NeuralNetworkTrain',
'NewDataFolder', 'NewFIFO', 'NewFIFOChan', 'NewFreeAxis', 'NewImage',
'NewLayout', 'NewMovie', 'NewNotebook', 'NewPanel', 'NewPath',
'NewWaterfall', 'Note', 'Notebook', 'NotebookAction', 'Open',
'OpenNotebook', 'Optimize', 'ParseOperationTemplate', 'PathInfo',
'PauseForUser', 'PauseUpdate', 'PCA', 'PlayMovie', 'PlayMovieAction',
'PlaySnd', 'PlaySound', 'PopupContextualMenu', 'PopupMenu',
'Preferences', 'PrimeFactors', 'Print', 'printf', 'PrintGraphs',
'PrintLayout', 'PrintNotebook', 'PrintSettings', 'PrintTable',
'Project', 'PulseStats', 'PutScrapText', 'pwd', 'Quit',
'RatioFromNumber', 'Redimension', 'Remove', 'RemoveContour',
'RemoveFromGraph', 'RemoveFromLayout', 'RemoveFromTable', 'RemoveImage',
'RemoveLayoutObjects', 'RemovePath', 'Rename', 'RenameDataFolder',
'RenamePath', 'RenamePICT', 'RenameWindow', 'ReorderImages',
'ReorderTraces', 'ReplaceText', 'ReplaceWave', 'Resample',
'ResumeUpdate', 'Reverse', 'Rotate', 'Save', 'SaveData',
'SaveExperiment', 'SaveGraphCopy', 'SaveNotebook',
'SavePackagePreferences', 'SavePICT', 'SaveTableCopy',
'SetActiveSubwindow', 'SetAxis', 'SetBackground', 'SetDashPattern',
'SetDataFolder', 'SetDimLabel', 'SetDrawEnv', 'SetDrawLayer',
'SetFileFolderInfo', 'SetFormula', 'SetIgorHook', 'SetIgorMenuMode',
'SetIgorOption', 'SetMarquee', 'SetProcessSleep', 'SetRandomSeed',
'SetScale', 'SetVariable', 'SetWaveLock', 'SetWindow', 'ShowIgorMenus',
'ShowInfo', 'ShowTools', 'Silent', 'Sleep', 'Slider', 'Smooth',
'SmoothCustom', 'Sort', 'SoundInRecord', 'SoundInSet',
'SoundInStartChart', 'SoundInStatus', 'SoundInStopChart',
'SphericalInterpolate', 'SphericalTriangulate', 'SplitString',
'sprintf', 'sscanf', 'Stack', 'StackWindows',
'StatsAngularDistanceTest', 'StatsANOVA1Test', 'StatsANOVA2NRTest',
'StatsANOVA2RMTest', 'StatsANOVA2Test', 'StatsChiTest',
'StatsCircularCorrelationTest', 'StatsCircularMeans',
'StatsCircularMoments', 'StatsCircularTwoSampleTest',
'StatsCochranTest', 'StatsContingencyTable', 'StatsDIPTest',
'StatsDunnettTest', 'StatsFriedmanTest', 'StatsFTest',
'StatsHodgesAjneTest', 'StatsJBTest', 'StatsKendallTauTest',
'StatsKSTest', 'StatsKWTest', 'StatsLinearCorrelationTest',
'StatsLinearRegression', 'StatsMultiCorrelationTest',
'StatsNPMCTest', 'StatsNPNominalSRTest', 'StatsQuantiles',
'StatsRankCorrelationTest', 'StatsResample', 'StatsSample',
'StatsScheffeTest', 'StatsSignTest', 'StatsSRTest', 'StatsTTest',
'StatsTukeyTest', 'StatsVariancesTest', 'StatsWatsonUSquaredTest',
'StatsWatsonWilliamsTest', 'StatsWheelerWatsonTest',
'StatsWilcoxonRankTest', 'StatsWRCorrelationTest', 'String',
'StructGet', 'StructPut', 'TabControl', 'Tag', 'TextBox', 'Tile',
'TileWindows', 'TitleBox', 'ToCommandLine', 'ToolsGrid',
'Triangulate3d', 'Unwrap', 'ValDisplay', 'Variable', 'WaveMeanStdv',
'WaveStats', 'WaveTransform', 'wfprintf', 'WignerTransform',
'WindowFunction',
)
functions = (
'abs', 'acos', 'acosh', 'AiryA', 'AiryAD', 'AiryB', 'AiryBD', 'alog',
'area', 'areaXY', 'asin', 'asinh', 'atan', 'atan2', 'atanh',
'AxisValFromPixel', 'Besseli', 'Besselj', 'Besselk', 'Bessely', 'bessi',
'bessj', 'bessk', 'bessy', 'beta', 'betai', 'BinarySearch',
'BinarySearchInterp', 'binomial', 'binomialln', 'binomialNoise', 'cabs',
'CaptureHistoryStart', 'ceil', 'cequal', 'char2num', 'chebyshev',
'chebyshevU', 'CheckName', 'cmplx', 'cmpstr', 'conj', 'ContourZ', 'cos',
'cosh', 'cot', 'CountObjects', 'CountObjectsDFR', 'cpowi',
'CreationDate', 'csc', 'DataFolderExists', 'DataFolderRefsEqual',
'DataFolderRefStatus', 'date2secs', 'datetime', 'DateToJulian',
'Dawson', 'DDEExecute', 'DDEInitiate', 'DDEPokeString', 'DDEPokeWave',
'DDERequestWave', 'DDEStatus', 'DDETerminate', 'deltax', 'digamma',
'DimDelta', 'DimOffset', 'DimSize', 'ei', 'enoise', 'equalWaves', 'erf',
'erfc', 'exists', 'exp', 'expInt', 'expNoise', 'factorial', 'fakedata',
'faverage', 'faverageXY', 'FindDimLabel', 'FindListItem', 'floor',
'FontSizeHeight', 'FontSizeStringWidth', 'FresnelCos', 'FresnelSin',
'gamma', 'gammaInc', 'gammaNoise', 'gammln', 'gammp', 'gammq', 'Gauss',
'Gauss1D', 'Gauss2D', 'gcd', 'GetDefaultFontSize',
'GetDefaultFontStyle', 'GetKeyState', 'GetRTError', 'gnoise',
'GrepString', 'hcsr', 'hermite', 'hermiteGauss', 'HyperG0F1',
'HyperG1F1', 'HyperG2F1', 'HyperGNoise', 'HyperGPFQ', 'IgorVersion',
'ilim', 'imag', 'Inf', 'Integrate1D', 'interp', 'Interp2D', 'Interp3D',
'inverseERF', 'inverseERFC', 'ItemsInList', 'jlim', 'Laguerre',
'LaguerreA', 'LaguerreGauss', 'leftx', 'LegendreA', 'limit', 'ln',
'log', 'logNormalNoise', 'lorentzianNoise', 'magsqr', 'MandelbrotPoint',
'MarcumQ', 'MatrixDet', 'MatrixDot', 'MatrixRank', 'MatrixTrace', 'max',
'mean', 'min', 'mod', 'ModDate', 'NaN', 'norm', 'NumberByKey',
'numpnts', 'numtype', 'NumVarOrDefault', 'NVAR_Exists', 'p2rect',
'ParamIsDefault', 'pcsr', 'Pi', 'PixelFromAxisVal', 'pnt2x',
'poissonNoise', 'poly', 'poly2D', 'PolygonArea', 'qcsr', 'r2polar',
'real', 'rightx', 'round', 'sawtooth', 'ScreenResolution', 'sec',
'SelectNumber', 'sign', 'sin', 'sinc', 'sinh', 'SphericalBessJ',
'SphericalBessJD', 'SphericalBessY', 'SphericalBessYD',
'SphericalHarmonics', 'sqrt', 'StartMSTimer', 'StatsBetaCDF',
'StatsBetaPDF', 'StatsBinomialCDF', 'StatsBinomialPDF',
'StatsCauchyCDF', 'StatsCauchyPDF', 'StatsChiCDF', 'StatsChiPDF',
'StatsCMSSDCDF', 'StatsCorrelation', 'StatsDExpCDF', 'StatsDExpPDF',
'StatsErlangCDF', 'StatsErlangPDF', 'StatsErrorPDF', 'StatsEValueCDF',
'StatsEValuePDF', 'StatsExpCDF', 'StatsExpPDF', 'StatsFCDF',
'StatsFPDF', 'StatsFriedmanCDF', 'StatsGammaCDF', 'StatsGammaPDF',
'StatsGeometricCDF', 'StatsGeometricPDF', 'StatsHyperGCDF',
'StatsHyperGPDF', 'StatsInvBetaCDF', 'StatsInvBinomialCDF',
'StatsInvCauchyCDF', 'StatsInvChiCDF', 'StatsInvCMSSDCDF',
'StatsInvDExpCDF', 'StatsInvEValueCDF', 'StatsInvExpCDF',
'StatsInvFCDF', 'StatsInvFriedmanCDF', 'StatsInvGammaCDF',
'StatsInvGeometricCDF', 'StatsInvKuiperCDF', 'StatsInvLogisticCDF',
'StatsInvLogNormalCDF', 'StatsInvMaxwellCDF', 'StatsInvMooreCDF',
'StatsInvNBinomialCDF', 'StatsInvNCChiCDF', 'StatsInvNCFCDF',
'StatsInvNormalCDF', 'StatsInvParetoCDF', 'StatsInvPoissonCDF',
'StatsInvPowerCDF', 'StatsInvQCDF', 'StatsInvQpCDF',
'StatsInvRayleighCDF', 'StatsInvRectangularCDF', 'StatsInvSpearmanCDF',
'StatsInvStudentCDF', 'StatsInvTopDownCDF', 'StatsInvTriangularCDF',
'StatsInvUsquaredCDF', 'StatsInvVonMisesCDF', 'StatsInvWeibullCDF',
'StatsKuiperCDF', 'StatsLogisticCDF', 'StatsLogisticPDF',
'StatsLogNormalCDF', 'StatsLogNormalPDF', 'StatsMaxwellCDF',
'StatsMaxwellPDF', 'StatsMedian', 'StatsMooreCDF', 'StatsNBinomialCDF',
'StatsNBinomialPDF', 'StatsNCChiCDF', 'StatsNCChiPDF', 'StatsNCFCDF',
'StatsNCFPDF', 'StatsNCTCDF', 'StatsNCTPDF', 'StatsNormalCDF',
'StatsNormalPDF', 'StatsParetoCDF', 'StatsParetoPDF', 'StatsPermute',
'StatsPoissonCDF', 'StatsPoissonPDF', 'StatsPowerCDF',
'StatsPowerNoise', 'StatsPowerPDF', 'StatsQCDF', 'StatsQpCDF',
'StatsRayleighCDF', 'StatsRayleighPDF', 'StatsRectangularCDF',
'StatsRectangularPDF', 'StatsRunsCDF', 'StatsSpearmanRhoCDF',
'StatsStudentCDF', 'StatsStudentPDF', 'StatsTopDownCDF',
'StatsTriangularCDF', 'StatsTriangularPDF', 'StatsTrimmedMean',
'StatsUSquaredCDF', 'StatsVonMisesCDF', 'StatsVonMisesNoise',
'StatsVonMisesPDF', 'StatsWaldCDF', 'StatsWaldPDF', 'StatsWeibullCDF',
'StatsWeibullPDF', 'StopMSTimer', 'str2num', 'stringCRC', 'stringmatch',
'strlen', 'strsearch', 'StudentA', 'StudentT', 'sum', 'SVAR_Exists',
'TagVal', 'tan', 'tanh', 'ThreadGroupCreate', 'ThreadGroupRelease',
'ThreadGroupWait', 'ThreadProcessorCount', 'ThreadReturnValue', 'ticks',
'trunc', 'Variance', 'vcsr', 'WaveCRC', 'WaveDims', 'WaveExists',
'WaveMax', 'WaveMin', 'WaveRefsEqual', 'WaveType', 'WhichListItem',
'WinType', 'WNoise', 'x', 'x2pnt', 'xcsr', 'y', 'z', 'zcsr', 'ZernikeR',
)
functions += (
'AddListItem', 'AnnotationInfo', 'AnnotationList', 'AxisInfo',
'AxisList', 'CaptureHistory', 'ChildWindowList', 'CleanupName',
'ContourInfo', 'ContourNameList', 'ControlNameList', 'CsrInfo',
'CsrWave', 'CsrXWave', 'CTabList', 'DataFolderDir', 'date',
'DDERequestString', 'FontList', 'FuncRefInfo', 'FunctionInfo',
'FunctionList', 'FunctionPath', 'GetDataFolder', 'GetDefaultFont',
'GetDimLabel', 'GetErrMessage', 'GetFormula',
'GetIndependentModuleName', 'GetIndexedObjName', 'GetIndexedObjNameDFR',
'GetRTErrMessage', 'GetRTStackInfo', 'GetScrapText', 'GetUserData',
'GetWavesDataFolder', 'GrepList', 'GuideInfo', 'GuideNameList', 'Hash',
'IgorInfo', 'ImageInfo', 'ImageNameList', 'IndexedDir', 'IndexedFile',
'JulianToDate', 'LayoutInfo', 'ListMatch', 'LowerStr', 'MacroList',
'NameOfWave', 'note', 'num2char', 'num2istr', 'num2str',
'OperationList', 'PadString', 'ParseFilePath', 'PathList', 'PICTInfo',
'PICTList', 'PossiblyQuoteName', 'ProcedureText', 'RemoveByKey',
'RemoveEnding', 'RemoveFromList', 'RemoveListItem',
'ReplaceNumberByKey', 'ReplaceString', 'ReplaceStringByKey',
'Secs2Date', 'Secs2Time', 'SelectString', 'SortList',
'SpecialCharacterInfo', 'SpecialCharacterList', 'SpecialDirPath',
'StringByKey', 'StringFromList', 'StringList', 'StrVarOrDefault',
'TableInfo', 'TextFile', 'ThreadGroupGetDF', 'time', 'TraceFromPixel',
'TraceInfo', 'TraceNameList', 'UniqueName', 'UnPadString', 'UpperStr',
'VariableList', 'WaveInfo', 'WaveList', 'WaveName', 'WaveUnits',
'WinList', 'WinName', 'WinRecreation', 'XWaveName',
'ContourNameToWaveRef', 'CsrWaveRef', 'CsrXWaveRef',
'ImageNameToWaveRef', 'NewFreeWave', 'TagWaveRef', 'TraceNameToWaveRef',
'WaveRefIndexed', 'XWaveRefFromTrace', 'GetDataFolderDFR',
'GetWavesDataFolderDFR', 'NewFreeDataFolder', 'ThreadGroupGetDFR',
)
tokens = {
'root': [
(r'//.*$', Comment.Single),
(r'"([^"\\]|\\.)*"', String),
# Flow Control.
(words(flowControl, prefix=r'\b', suffix=r'\b'), Keyword),
# Types.
(words(types, prefix=r'\b', suffix=r'\b'), Keyword.Type),
# Keywords.
(words(keywords, prefix=r'\b', suffix=r'\b'), Keyword.Reserved),
# Built-in operations.
(words(operations, prefix=r'\b', suffix=r'\b'), Name.Class),
# Built-in functions.
(words(functions, prefix=r'\b', suffix=r'\b'), Name.Function),
# Compiler directives.
(r'^#(include|pragma|define|ifdef|ifndef|endif)',
Name.Decorator),
(r'[^a-z"/]+$', Text),
(r'.', Text),
],
}
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
528,
269,
272,
18294,
2878,
339,
491,
476,
1192,
367,
473,
2904,
2165,
14,
339,
520,
7307,
26,
1898,
8315,
13,
7280,
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,
12939,
5838,
12,
5932,
199,
504,
13277,
14,
1418,
492,
4516,
12,
6819,
12,
6431,
12,
2812,
12,
2624,
199,
199,
363,
452,
363,
275,
788,
41,
2904,
5838,
418,
421,
199,
533,
473,
2904,
5838,
8,
19856,
304,
272,
408,
272,
14493,
21125,
367,
473,
2904,
2165,
17782,
1584,
17048,
711,
70,
680,
272,
1666,
1455,
921,
1544,
14,
10024,
6759,
14,
957,
15,
436,
1455,
921,
1544,
14,
528,
720,
88,
1461,
14,
957,
8083,
339,
2508,
7445,
447,
499,
14,
16,
272,
408,
339,
536,
275,
283,
41,
2904,
7,
272,
5481,
275,
788,
528,
269,
297,
283,
528,
269,
496,
418,
272,
6203,
275,
17855,
711,
70,
418,
272,
13290,
275,
788,
505,
15,
711,
70,
418,
339,
3285,
275,
295,
14,
15434,
1204,
295,
14,
16661,
339,
6369,
3717,
275,
334,
267,
283,
692,
297,
283,
2836,
297,
283,
2836,
692,
297,
283,
13739,
297,
283,
509,
297,
283,
500,
509,
297,
283,
495,
5656,
297,
283,
5656,
297,
267,
283,
2546,
297,
283,
885,
297,
283,
3198,
3111,
297,
283,
1117,
297,
283,
6710,
297,
283,
893,
297,
283,
9341,
297,
283,
500,
893,
297,
267,
283,
4785,
297,
283,
6958,
297,
283,
1107,
297,
272,
776,
272,
2943,
275,
334,
267,
283,
1975,
297,
283,
875,
297,
283,
4083,
297,
283,
495,
4083,
297,
283,
46,
5568,
297,
283,
4985,
689,
297,
283,
32482,
297,
267,
283,
8893,
297,
283,
1587,
1121,
7,
272,
776,
272,
7681,
275,
334,
267,
283,
4415,
297,
283,
4436,
11090,
297,
283,
1986,
297,
221,
283,
7465,
13776,
297,
283,
15019,
297,
283,
29439,
297,
267,
283,
20430,
297,
283,
2585,
20430,
297,
283,
11300,
297,
283,
3806,
297,
283,
2180,
297,
283,
1593,
297,
283,
500,
297,
267,
283,
10766,
297,
283,
3005,
10766,
297,
283,
3005,
24673,
297,
283,
5977,
297,
283,
2610,
5977,
297,
272,
776,
272,
5331,
275,
334,
267,
283,
16682,
297,
283,
1123,
20925,
1451,
297,
283,
1123,
20925,
54,
449,
1451,
297,
283,
1123,
19088,
15484,
297,
267,
283,
1123,
19088,
3160,
297,
283,
1282,
18568,
297,
283,
8310,
297,
283,
8310,
3491,
297,
267,
283,
8310,
4798,
1692,
297,
283,
8310,
6443,
714,
10808,
297,
283,
8310,
1872,
297,
267,
283,
8310,
1378,
4578,
297,
283,
8310,
1378,
4798,
297,
283,
8310,
1378,
3186,
297,
283,
8310,
16694,
714,
10808,
297,
267,
283,
3358,
5625,
4301,
297,
283,
14148,
2354,
297,
283,
34,
7840,
297,
283,
8934,
316,
34,
452,
297,
267,
283,
24149,
2632,
297,
283,
3425,
5977,
297,
283,
4259,
297,
283,
2866,
297,
283,
16372,
297,
283,
20530,
297,
267,
283,
1799,
7687,
379,
297,
283,
23932,
4117,
297,
283,
4724,
297,
283,
4724,
19088,
297,
283,
4724,
15019,
297,
267,
283,
4117,
9944,
297,
283,
4117,
7690,
18,
21393,
297,
283,
714,
10592,
297,
283,
3717,
5281,
297,
267,
283,
3717,
2354,
297,
283,
3717,
4152,
297,
283,
714,
26221,
40,
979,
297,
283,
11596,
3344,
297,
283,
5116,
1173,
297,
267,
283,
5116,
7850,
297,
283,
5116,
9944,
83,
297,
283,
8380,
17322,
297,
283,
2499,
14149,
28301,
297,
283,
14072,
297,
267,
283,
9778,
14148,
297,
283,
9778,
20925,
297,
283,
9778,
7989,
14148,
297,
283,
8993,
297,
267,
283,
20966,
13776,
297,
283,
7223,
3717,
297,
283,
35,
21283,
297,
283,
31521,
297,
283,
31521,
4558,
297,
267,
283,
2698,
6986,
297,
283,
2698,
4324,
25457,
297,
283,
2698,
4324,
6986,
297,
283,
16213,
4324,
271,
297,
267,
283,
10796,
4152,
297,
283,
5392,
1173,
297,
283,
5392,
7850,
297,
283,
5392,
10225,
297,
267,
283,
16384,
30906,
323,
297,
283,
694,
297,
283,
7687,
297,
283,
7687,
8673,
12157,
297,
267,
283,
7687,
919,
12194,
297,
283,
2585,
18758,
297,
283,
2585,
41,
2904,
5977,
297,
283,
2585,
4152,
297,
283,
2585,
4301,
297,
267,
283,
2585,
56,
1938,
21068,
297,
283,
9654,
3310,
297,
283,
9654,
27604,
297,
283,
9654,
3655,
90,
4446,
297,
283,
9654,
3049,
297,
267,
283,
9654,
47,
637,
297,
283,
9654,
48,
6196,
297,
283,
9654,
12747,
297,
283,
9654,
8252,
297,
283,
9654,
50,
8252,
297,
283,
9654,
1872,
297,
267,
283,
3177,
11435,
386,
16479,
297,
283,
3177,
48,
15518,
79,
1679,
297,
283,
14773,
297,
283,
14773,
1451,
7850,
297,
267,
283,
19438,
52,
297,
283,
12886,
8257,
297,
283,
4685,
297,
283,
547,
34,
4291,
297,
283,
12049,
297,
283,
12049,
5229,
1872,
297,
267,
283,
20781,
11911,
297,
283,
12147,
297,
283,
16976,
39,
23822,
6939,
297,
283,
16976,
4619,
297,
267,
283,
8223,
262,
3284,
297,
283,
8223,
262,
3534,
297,
283,
1665,
52,
297,
283,
20925,
18,
21393,
297,
283,
20925,
3694,
297,
283,
4131,
1976,
50,
297,
267,
283,
4131,
41,
3927,
297,
283,
6591,
4670,
297,
283,
6591,
4670,
83,
297,
283,
6591,
32448,
297,
283,
6591,
10225,
607,
12747,
297,
267,
283,
6591,
6405,
83,
297,
283,
6591,
5826,
297,
283,
6591,
1110,
297,
283,
17095,
31174,
297,
283,
70,
19139,
297,
267,
283,
38,
3284,
3049,
297,
283,
38,
1084,
6981,
297,
283,
38,
3694,
297,
283,
15123,
5392,
297,
283,
15123,
11950,
297,
267,
283,
15123,
10301,
297,
283,
7465,
13776,
297,
283,
7465,
13776,
5127,
297,
283,
1002,
11220,
297,
283,
26535,
7850,
2354,
297,
267,
283,
1002,
6090,
1899,
5977,
2354,
297,
283,
1002,
10570,
12221,
297,
283,
1002,
7713,
297,
283,
1002,
4301,
297,
267,
283,
4578,
6241,
297,
283,
4578,
21393,
9654,
297,
283,
4578,
21393,
4685,
297,
283,
39,
1155,
297,
283,
2448,
3532,
297,
267,
283,
40,
11495,
297,
283,
18224,
41,
2904,
29230,
527,
297,
283,
18224,
2354,
297,
283,
18224,
919,
6867,
1482,
297,
283,
18224,
11654,
297,
267,
283,
40,
382,
12504,
6939,
297,
283,
25055,
297,
283,
24150
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
528,
269,
272,
18294,
2878,
339,
491,
476,
1192,
367,
473,
2904,
2165,
14,
339,
520,
7307,
26,
1898,
8315,
13,
7280,
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,
12939,
5838,
12,
5932,
199,
504,
13277,
14,
1418,
492,
4516,
12,
6819,
12,
6431,
12,
2812,
12,
2624,
199,
199,
363,
452,
363,
275,
788,
41,
2904,
5838,
418,
421,
199,
533,
473,
2904,
5838,
8,
19856,
304,
272,
408,
272,
14493,
21125,
367,
473,
2904,
2165,
17782,
1584,
17048,
711,
70,
680,
272,
1666,
1455,
921,
1544,
14,
10024,
6759,
14,
957,
15,
436,
1455,
921,
1544,
14,
528,
720,
88,
1461,
14,
957,
8083,
339,
2508,
7445,
447,
499,
14,
16,
272,
408,
339,
536,
275,
283,
41,
2904,
7,
272,
5481,
275,
788,
528,
269,
297,
283,
528,
269,
496,
418,
272,
6203,
275,
17855,
711,
70,
418,
272,
13290,
275,
788,
505,
15,
711,
70,
418,
339,
3285,
275,
295,
14,
15434,
1204,
295,
14,
16661,
339,
6369,
3717,
275,
334,
267,
283,
692,
297,
283,
2836,
297,
283,
2836,
692,
297,
283,
13739,
297,
283,
509,
297,
283,
500,
509,
297,
283,
495,
5656,
297,
283,
5656,
297,
267,
283,
2546,
297,
283,
885,
297,
283,
3198,
3111,
297,
283,
1117,
297,
283,
6710,
297,
283,
893,
297,
283,
9341,
297,
283,
500,
893,
297,
267,
283,
4785,
297,
283,
6958,
297,
283,
1107,
297,
272,
776,
272,
2943,
275,
334,
267,
283,
1975,
297,
283,
875,
297,
283,
4083,
297,
283,
495,
4083,
297,
283,
46,
5568,
297,
283,
4985,
689,
297,
283,
32482,
297,
267,
283,
8893,
297,
283,
1587,
1121,
7,
272,
776,
272,
7681,
275,
334,
267,
283,
4415,
297,
283,
4436,
11090,
297,
283,
1986,
297,
221,
283,
7465,
13776,
297,
283,
15019,
297,
283,
29439,
297,
267,
283,
20430,
297,
283,
2585,
20430,
297,
283,
11300,
297,
283,
3806,
297,
283,
2180,
297,
283,
1593,
297,
283,
500,
297,
267,
283,
10766,
297,
283,
3005,
10766,
297,
283,
3005,
24673,
297,
283,
5977,
297,
283,
2610,
5977,
297,
272,
776,
272,
5331,
275,
334,
267,
283,
16682,
297,
283,
1123,
20925,
1451,
297,
283,
1123,
20925,
54,
449,
1451,
297,
283,
1123,
19088,
15484,
297,
267,
283,
1123,
19088,
3160,
297,
283,
1282,
18568,
297,
283,
8310,
297,
283,
8310,
3491,
297,
267,
283,
8310,
4798,
1692,
297,
283,
8310,
6443,
714,
10808,
297,
283,
8310,
1872,
297,
267,
283,
8310,
1378,
4578,
297,
283,
8310,
1378,
4798,
297,
283,
8310,
1378,
3186,
297,
283,
8310,
16694,
714,
10808,
297,
267,
283,
3358,
5625,
4301,
297,
283,
14148,
2354,
297,
283,
34,
7840,
297,
283,
8934,
316,
34,
452,
297,
267,
283,
24149,
2632,
297,
283,
3425,
5977,
297,
283,
4259,
297,
283,
2866,
297,
283,
16372,
297,
283,
20530,
297,
267,
283,
1799,
7687,
379,
297,
283,
23932,
4117,
297,
283,
4724,
297,
283,
4724,
19088,
297,
283,
4724,
15019,
297,
267,
283,
4117,
9944,
297,
283,
4117,
7690,
18,
21393,
297,
283,
714,
10592,
297,
283,
3717,
5281,
297,
267,
283,
3717,
2354,
297,
283,
3717,
4152,
297,
283,
714,
26221,
40,
979,
297,
283,
11596,
3344,
297,
283,
5116,
1173,
297,
267,
283,
5116,
7850,
297,
283,
5116,
9944,
83,
297,
283,
8380,
17322,
297,
283,
2499,
14149,
28301,
297,
283,
14072,
297,
267,
283,
9778,
14148,
297,
283,
9778,
20925,
297,
283,
9778,
7989,
14148,
297,
283,
8993,
297,
267,
283,
20966,
13776,
297,
283,
7223,
3717,
297,
283,
35,
21283,
297,
283,
31521,
297,
283,
31521,
4558,
297,
267,
283,
2698,
6986,
297,
283,
2698,
4324,
25457,
297,
283,
2698,
4324,
6986,
297,
283,
16213,
4324,
271,
297,
267,
283,
10796,
4152,
297,
283,
5392,
1173,
297,
283,
5392,
7850,
297,
283,
5392,
10225,
297,
267,
283,
16384,
30906,
323,
297,
283,
694,
297,
283,
7687,
297,
283,
7687,
8673,
12157,
297,
267,
283,
7687,
919,
12194,
297,
283,
2585,
18758,
297,
283,
2585,
41,
2904,
5977,
297,
283,
2585,
4152,
297,
283,
2585,
4301,
297,
267,
283,
2585,
56,
1938,
21068,
297,
283,
9654,
3310,
297,
283,
9654,
27604,
297,
283,
9654,
3655,
90,
4446,
297,
283,
9654,
3049,
297,
267,
283,
9654,
47,
637,
297,
283,
9654,
48,
6196,
297,
283,
9654,
12747,
297,
283,
9654,
8252,
297,
283,
9654,
50,
8252,
297,
283,
9654,
1872,
297,
267,
283,
3177,
11435,
386,
16479,
297,
283,
3177,
48,
15518,
79,
1679,
297,
283,
14773,
297,
283,
14773,
1451,
7850,
297,
267,
283,
19438,
52,
297,
283,
12886,
8257,
297,
283,
4685,
297,
283,
547,
34,
4291,
297,
283,
12049,
297,
283,
12049,
5229,
1872,
297,
267,
283,
20781,
11911,
297,
283,
12147,
297,
283,
16976,
39,
23822,
6939,
297,
283,
16976,
4619,
297,
267,
283,
8223,
262,
3284,
297,
283,
8223,
262,
3534,
297,
283,
1665,
52,
297,
283,
20925,
18,
21393,
297,
283,
20925,
3694,
297,
283,
4131,
1976,
50,
297,
267,
283,
4131,
41,
3927,
297,
283,
6591,
4670,
297,
283,
6591,
4670,
83,
297,
283,
6591,
32448,
297,
283,
6591,
10225,
607,
12747,
297,
267,
283,
6591,
6405,
83,
297,
283,
6591,
5826,
297,
283,
6591,
1110,
297,
283,
17095,
31174,
297,
283,
70,
19139,
297,
267,
283,
38,
3284,
3049,
297,
283,
38,
1084,
6981,
297,
283,
38,
3694,
297,
283,
15123,
5392,
297,
283,
15123,
11950,
297,
267,
283,
15123,
10301,
297,
283,
7465,
13776,
297,
283,
7465,
13776,
5127,
297,
283,
1002,
11220,
297,
283,
26535,
7850,
2354,
297,
267,
283,
1002,
6090,
1899,
5977,
2354,
297,
283,
1002,
10570,
12221,
297,
283,
1002,
7713,
297,
283,
1002,
4301,
297,
267,
283,
4578,
6241,
297,
283,
4578,
21393,
9654,
297,
283,
4578,
21393,
4685,
297,
283,
39,
1155,
297,
283,
2448,
3532,
297,
267,
283,
40,
11495,
297,
283,
18224,
41,
2904,
29230,
527,
297,
283,
18224,
2354,
297,
283,
18224,
919,
6867,
1482,
297,
283,
18224,
11654,
297,
267,
283,
40,
382,
12504,
6939,
297,
283,
25055,
297,
283,
24150,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
zuotingbing/spark
|
python/pyspark/rddsampler.py
|
157
|
4250
|
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import sys
import random
import math
class RDDSamplerBase(object):
def __init__(self, withReplacement, seed=None):
self._seed = seed if seed is not None else random.randint(0, sys.maxsize)
self._withReplacement = withReplacement
self._random = None
def initRandomGenerator(self, split):
self._random = random.Random(self._seed ^ split)
# mixing because the initial seeds are close to each other
for _ in range(10):
self._random.randint(0, 1)
def getUniformSample(self):
return self._random.random()
def getPoissonSample(self, mean):
# Using Knuth's algorithm described in
# http://en.wikipedia.org/wiki/Poisson_distribution
if mean < 20.0:
# one exp and k+1 random calls
l = math.exp(-mean)
p = self._random.random()
k = 0
while p > l:
k += 1
p *= self._random.random()
else:
# switch to the log domain, k+1 expovariate (random + log) calls
p = self._random.expovariate(mean)
k = 0
while p < 1.0:
k += 1
p += self._random.expovariate(mean)
return k
def func(self, split, iterator):
raise NotImplementedError
class RDDSampler(RDDSamplerBase):
def __init__(self, withReplacement, fraction, seed=None):
RDDSamplerBase.__init__(self, withReplacement, seed)
self._fraction = fraction
def func(self, split, iterator):
self.initRandomGenerator(split)
if self._withReplacement:
for obj in iterator:
# For large datasets, the expected number of occurrences of each element in
# a sample with replacement is Poisson(frac). We use that to get a count for
# each element.
count = self.getPoissonSample(self._fraction)
for _ in range(0, count):
yield obj
else:
for obj in iterator:
if self.getUniformSample() < self._fraction:
yield obj
class RDDRangeSampler(RDDSamplerBase):
def __init__(self, lowerBound, upperBound, seed=None):
RDDSamplerBase.__init__(self, False, seed)
self._lowerBound = lowerBound
self._upperBound = upperBound
def func(self, split, iterator):
self.initRandomGenerator(split)
for obj in iterator:
if self._lowerBound <= self.getUniformSample() < self._upperBound:
yield obj
class RDDStratifiedSampler(RDDSamplerBase):
def __init__(self, withReplacement, fractions, seed=None):
RDDSamplerBase.__init__(self, withReplacement, seed)
self._fractions = fractions
def func(self, split, iterator):
self.initRandomGenerator(split)
if self._withReplacement:
for key, val in iterator:
# For large datasets, the expected number of occurrences of each element in
# a sample with replacement is Poisson(frac). We use that to get a count for
# each element.
count = self.getPoissonSample(self._fractions[key])
for _ in range(0, count):
yield key, val
else:
for key, val in iterator:
if self.getUniformSample() < self._fractions[key]:
yield key, val
|
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,
646,
984,
199,
646,
2196,
199,
646,
3473,
421,
199,
533,
820,
36,
3177,
865,
82,
1563,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
543,
29475,
12,
6347,
29,
403,
304,
267,
291,
423,
5176,
275,
6347,
340,
6347,
365,
440,
488,
587,
2196,
14,
8393,
8,
16,
12,
984,
14,
13634,
9,
267,
291,
423,
1045,
29475,
275,
543,
29475,
267,
291,
423,
2355,
275,
488,
339,
347,
4205,
3883,
7599,
8,
277,
12,
3715,
304,
267,
291,
423,
2355,
275,
2196,
14,
3883,
8,
277,
423,
5176,
7167,
3715,
9,
398,
327,
13667,
316,
2952,
314,
2536,
26825,
787,
4002,
370,
1924,
1163,
267,
367,
485,
315,
1425,
8,
709,
304,
288,
291,
423,
2355,
14,
8393,
8,
16,
12,
413,
9,
339,
347,
664,
12421,
8176,
8,
277,
304,
267,
372,
291,
423,
2355,
14,
2355,
342,
339,
347,
664,
1575,
18571,
8176,
8,
277,
12,
4615,
304,
267,
327,
11719,
1804,
78,
762,
1159,
5563,
11736,
315,
267,
327,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
1575,
18571,
63,
4972,
267,
340,
4615,
665,
3388,
14,
16,
26,
288,
327,
1373,
1437,
436,
1022,
11,
17,
2196,
4882,
288,
634,
275,
3473,
14,
1474,
2801,
3670,
9,
288,
299,
275,
291,
423,
2355,
14,
2355,
342,
288,
1022,
275,
378,
288,
1830,
299,
690,
634,
26,
355,
1022,
847,
413,
355,
299,
9000,
291,
423,
2355,
14,
2355,
342,
267,
587,
26,
288,
327,
6258,
370,
314,
943,
2881,
12,
1022,
11,
17,
444,
555,
13805,
334,
2355,
435,
943,
9,
4882,
288,
299,
275,
291,
423,
2355,
14,
476,
555,
13805,
8,
3670,
9,
288,
1022,
275,
378,
288,
1830,
299,
665,
413,
14,
16,
26,
355,
1022,
847,
413,
355,
299,
847,
291,
423,
2355,
14,
476,
555,
13805,
8,
3670,
9,
267,
372,
1022,
339,
347,
2562,
8,
277,
12,
3715,
12,
6122,
304,
267,
746,
4279,
421,
199,
533,
820,
36,
3177,
865,
82,
8,
15543,
3177,
865,
82,
1563,
304,
339,
347,
636,
826,
721,
277,
12,
543,
29475,
12,
12347,
12,
6347,
29,
403,
304,
267,
820,
36,
3177,
865,
82,
1563,
855,
826,
721,
277,
12,
543,
29475,
12,
6347,
9,
267,
291,
423,
13054,
275,
12347,
339,
347,
2562,
8,
277,
12,
3715,
12,
6122,
304,
267,
291,
14,
826,
3883,
7599,
8,
1294,
9,
267,
340,
291,
423,
1045,
29475,
26,
288,
367,
1559,
315,
6122,
26,
355,
327,
2104,
7031,
13148,
12,
314,
1420,
1329,
402,
22099,
402,
1924,
1819,
315,
355,
327,
282,
2690,
543,
8343,
365,
4376,
18571,
8,
10865,
680,
2136,
675,
626,
370,
664,
282,
2338,
367,
355,
327,
1924,
1819,
14,
355,
2338,
275,
291,
14,
362,
1575,
18571,
8176,
8,
277,
423,
13054,
9,
355,
367,
485,
315,
1425,
8,
16,
12,
2338,
304,
490,
1995,
1559,
267,
587,
26,
288,
367,
1559,
315,
6122,
26,
355,
340,
291,
14,
362,
12421,
8176,
342,
665,
291,
423,
13054,
26,
490,
1995,
1559,
421,
199,
533,
820,
36,
4564,
618,
27434,
8,
15543,
3177,
865,
82,
1563,
304,
339,
347,
636,
826,
721,
277,
12,
5117,
8934,
12,
7008,
8934,
12,
6347,
29,
403,
304,
267,
820,
36,
3177,
865,
82,
1563,
855,
826,
721,
277,
12,
756,
12,
6347,
9,
267,
291,
423,
2325,
8934,
275,
5117,
8934,
267,
291,
423,
4142,
8934,
275,
7008,
8934,
339,
347,
2562,
8,
277,
12,
3715,
12,
6122,
304,
267,
291,
14,
826,
3883,
7599,
8,
1294,
9,
267,
367,
1559,
315,
6122,
26,
288,
340,
291,
423,
2325,
8934,
2695,
291,
14,
362,
12421,
8176,
342,
665,
291,
423,
4142,
8934,
26,
355,
1995,
1559,
421,
199,
533,
21310,
933,
345,
8981,
27434,
8,
15543,
3177,
865,
82,
1563,
304,
339,
347,
636,
826,
721,
277,
12,
543,
29475,
12,
28213,
2452,
12,
6347,
29,
403,
304,
267,
820,
36,
3177,
865,
82,
1563,
855,
826,
721,
277,
12,
543,
29475,
12,
6347,
9,
267,
291,
423,
21844,
2452,
275,
28213,
2452,
339,
347,
2562,
8,
277,
12,
3715,
12,
6122,
304,
267,
291,
14,
826,
3883,
7599,
8,
1294,
9,
267,
340,
291,
423,
1045,
29475,
26,
288,
367,
790,
12,
1139,
315,
6122,
26,
355,
327,
2104,
7031,
13148,
12,
314,
1420,
1329,
402,
22099,
402,
1924,
1819,
315,
355,
327,
282,
2690,
543,
8343,
365,
4376,
18571,
8,
10865,
680,
2136,
675,
626,
370,
664,
282,
2338,
367,
355,
327,
1924,
1819,
14,
355,
2338,
275,
291,
14,
362,
1575,
18571,
8176,
8,
277,
423,
21844,
2452,
59,
498,
566,
355,
367,
485,
315,
1425,
8,
16,
12,
2338,
304,
490,
1995,
790,
12,
1139,
267,
587,
26,
288,
367,
790,
12,
1139,
315,
6122,
26,
355,
340,
291,
14,
362,
12421,
8176,
342,
665,
291,
423,
21844,
2452,
59,
498,
2189,
490,
1995,
790,
12,
1139,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
646,
984,
199,
646,
2196,
199,
646,
3473,
421,
199,
533,
820,
36,
3177,
865,
82,
1563,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
543,
29475,
12,
6347,
29,
403,
304,
267,
291,
423,
5176,
275,
6347,
340,
6347,
365,
440,
488,
587,
2196,
14,
8393,
8,
16,
12,
984,
14,
13634,
9,
267,
291,
423,
1045,
29475,
275,
543,
29475,
267,
291,
423,
2355,
275,
488,
339,
347,
4205,
3883,
7599,
8,
277,
12,
3715,
304,
267,
291,
423,
2355,
275,
2196,
14,
3883,
8,
277,
423,
5176,
7167,
3715,
9,
398,
327,
13667,
316,
2952,
314,
2536,
26825,
787,
4002,
370,
1924,
1163,
267,
367,
485,
315,
1425,
8,
709,
304,
288,
291,
423,
2355,
14,
8393,
8,
16,
12,
413,
9,
339,
347,
664,
12421,
8176,
8,
277,
304,
267,
372,
291,
423,
2355,
14,
2355,
342,
339,
347,
664,
1575,
18571,
8176,
8,
277,
12,
4615,
304,
267,
327,
11719,
1804,
78,
762,
1159,
5563,
11736,
315,
267,
327,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
1575,
18571,
63,
4972,
267,
340,
4615,
665,
3388,
14,
16,
26,
288,
327,
1373,
1437,
436,
1022,
11,
17,
2196,
4882,
288,
634,
275,
3473,
14,
1474,
2801,
3670,
9,
288,
299,
275,
291,
423,
2355,
14,
2355,
342,
288,
1022,
275,
378,
288,
1830,
299,
690,
634,
26,
355,
1022,
847,
413,
355,
299,
9000,
291,
423,
2355,
14,
2355,
342,
267,
587,
26,
288,
327,
6258,
370,
314,
943,
2881,
12,
1022,
11,
17,
444,
555,
13805,
334,
2355,
435,
943,
9,
4882,
288,
299,
275,
291,
423,
2355,
14,
476,
555,
13805,
8,
3670,
9,
288,
1022,
275,
378,
288,
1830,
299,
665,
413,
14,
16,
26,
355,
1022,
847,
413,
355,
299,
847,
291,
423,
2355,
14,
476,
555,
13805,
8,
3670,
9,
267,
372,
1022,
339,
347,
2562,
8,
277,
12,
3715,
12,
6122,
304,
267,
746,
4279,
421,
199,
533,
820,
36,
3177,
865,
82,
8,
15543,
3177,
865,
82,
1563,
304,
339,
347,
636,
826,
721,
277,
12,
543,
29475,
12,
12347,
12,
6347,
29,
403,
304,
267,
820,
36,
3177,
865,
82,
1563,
855,
826,
721,
277,
12,
543,
29475,
12,
6347,
9,
267,
291,
423,
13054,
275,
12347,
339,
347,
2562,
8,
277,
12,
3715,
12,
6122,
304,
267,
291,
14,
826,
3883,
7599,
8,
1294,
9,
267,
340,
291,
423,
1045,
29475,
26,
288,
367,
1559,
315,
6122,
26,
355,
327,
2104,
7031,
13148,
12,
314,
1420,
1329,
402,
22099,
402,
1924,
1819,
315,
355,
327,
282,
2690,
543,
8343,
365,
4376,
18571,
8,
10865,
680,
2136,
675,
626,
370,
664,
282,
2338,
367,
355,
327,
1924,
1819,
14,
355,
2338,
275,
291,
14,
362,
1575,
18571,
8176,
8,
277,
423,
13054,
9,
355,
367,
485,
315,
1425,
8,
16,
12,
2338,
304,
490,
1995,
1559,
267,
587,
26,
288,
367,
1559,
315,
6122,
26,
355,
340,
291,
14,
362,
12421,
8176,
342,
665,
291,
423,
13054,
26,
490,
1995,
1559,
421,
199,
533,
820,
36,
4564,
618,
27434,
8,
15543,
3177,
865,
82,
1563,
304,
339,
347,
636,
826,
721,
277,
12,
5117,
8934,
12,
7008,
8934,
12,
6347,
29,
403,
304,
267,
820,
36,
3177,
865,
82,
1563,
855,
826,
721,
277,
12,
756,
12,
6347,
9,
267,
291,
423,
2325,
8934,
275,
5117,
8934,
267,
291,
423,
4142,
8934,
275,
7008,
8934,
339,
347,
2562,
8,
277,
12,
3715,
12,
6122,
304,
267,
291,
14,
826,
3883,
7599,
8,
1294,
9,
267,
367,
1559,
315,
6122,
26,
288,
340,
291,
423,
2325,
8934,
2695,
291,
14,
362,
12421,
8176,
342,
665,
291,
423,
4142,
8934,
26,
355,
1995,
1559,
421,
199,
533,
21310,
933,
345,
8981,
27434,
8,
15543,
3177,
865,
82,
1563,
304,
339,
347,
636,
826,
721,
277,
12,
543,
29475,
12,
28213,
2452,
12,
6347,
29,
403,
304,
267,
820,
36,
3177,
865,
82,
1563,
855,
826,
721,
277,
12,
543,
29475,
12,
6347,
9,
267,
291,
423,
21844,
2452,
275,
28213,
2452,
339,
347,
2562,
8,
277,
12,
3715,
12,
6122,
304,
267,
291,
14,
826,
3883,
7599,
8,
1294,
9,
267,
340,
291,
423,
1045,
29475,
26,
288,
367,
790,
12,
1139,
315,
6122,
26,
355,
327,
2104,
7031,
13148,
12,
314,
1420,
1329,
402,
22099,
402,
1924,
1819,
315,
355,
327,
282,
2690,
543,
8343,
365,
4376,
18571,
8,
10865,
680,
2136,
675,
626,
370,
664,
282,
2338,
367,
355,
327,
1924,
1819,
14,
355,
2338,
275,
291,
14,
362,
1575,
18571,
8176,
8,
277,
423,
21844,
2452,
59,
498,
566,
355,
367,
485,
315,
1425,
8,
16,
12,
2338,
304,
490,
1995,
790,
12,
1139,
267,
587,
26,
288,
367,
790,
12,
1139,
315,
6122,
26,
355,
340,
291,
14,
362,
12421,
8176,
342,
665,
291,
423,
21844,
2452,
59,
498,
2189,
490,
1995,
790,
12,
1139,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Bitl/RBXLegacy-src
|
Cut/RBXLegacyDiscordBot/lib/youtube_dl/extractor/limelight.py
|
18
|
15181
|
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..compat import compat_HTTPError
from ..utils import (
determine_ext,
float_or_none,
int_or_none,
smuggle_url,
unsmuggle_url,
ExtractorError,
)
class LimelightBaseIE(InfoExtractor):
_PLAYLIST_SERVICE_URL = 'http://production-ps.lvp.llnw.net/r/PlaylistService/%s/%s/%s'
_API_URL = 'http://api.video.limelight.com/rest/organizations/%s/%s/%s/%s.json'
@classmethod
def _extract_urls(cls, webpage, source_url):
lm = {
'Media': 'media',
'Channel': 'channel',
'ChannelList': 'channel_list',
}
entries = []
for kind, video_id in re.findall(
r'LimelightPlayer\.doLoad(Media|Channel|ChannelList)\(["\'](?P<id>[a-z0-9]{32})',
webpage):
entries.append(cls.url_result(
smuggle_url(
'limelight:%s:%s' % (lm[kind], video_id),
{'source_url': source_url}),
'Limelight%s' % kind, video_id))
for mobj in re.finditer(
# As per [1] class attribute should be exactly equal to
# LimelightEmbeddedPlayerFlash but numerous examples seen
# that don't exactly match it (e.g. [2]).
# 1. http://support.3playmedia.com/hc/en-us/articles/227732408-Limelight-Embedding-the-Captions-Plugin-with-the-Limelight-Player-on-Your-Webpage
# 2. http://www.sedona.com/FacilitatorTraining2017
r'''(?sx)
<object[^>]+class=(["\'])(?:(?!\1).)*\bLimelightEmbeddedPlayerFlash\b(?:(?!\1).)*\1[^>]*>.*?
<param[^>]+
name=(["\'])flashVars\2[^>]+
value=(["\'])(?:(?!\3).)*(?P<kind>media|channel(?:List)?)Id=(?P<id>[a-z0-9]{32})
''', webpage):
kind, video_id = mobj.group('kind'), mobj.group('id')
entries.append(cls.url_result(
smuggle_url(
'limelight:%s:%s' % (kind, video_id),
{'source_url': source_url}),
'Limelight%s' % kind.capitalize(), video_id))
return entries
def _call_playlist_service(self, item_id, method, fatal=True, referer=None):
headers = {}
if referer:
headers['Referer'] = referer
try:
return self._download_json(
self._PLAYLIST_SERVICE_URL % (self._PLAYLIST_SERVICE_PATH, item_id, method),
item_id, 'Downloading PlaylistService %s JSON' % method, fatal=fatal, headers=headers)
except ExtractorError as e:
if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
error = self._parse_json(e.cause.read().decode(), item_id)['detail']['contentAccessPermission']
if error == 'CountryDisabled':
self.raise_geo_restricted()
raise ExtractorError(error, expected=True)
raise
def _call_api(self, organization_id, item_id, method):
return self._download_json(
self._API_URL % (organization_id, self._API_PATH, item_id, method),
item_id, 'Downloading API %s JSON' % method)
def _extract(self, item_id, pc_method, mobile_method, meta_method, referer=None):
pc = self._call_playlist_service(item_id, pc_method, referer=referer)
metadata = self._call_api(pc['orgId'], item_id, meta_method)
mobile = self._call_playlist_service(item_id, mobile_method, fatal=False, referer=referer)
return pc, mobile, metadata
def _extract_info(self, streams, mobile_urls, properties):
video_id = properties['media_id']
formats = []
urls = []
for stream in streams:
stream_url = stream.get('url')
if not stream_url or stream.get('drmProtected') or stream_url in urls:
continue
urls.append(stream_url)
ext = determine_ext(stream_url)
if ext == 'f4m':
formats.extend(self._extract_f4m_formats(
stream_url, video_id, f4m_id='hds', fatal=False))
else:
fmt = {
'url': stream_url,
'abr': float_or_none(stream.get('audioBitRate')),
'fps': float_or_none(stream.get('videoFrameRate')),
'ext': ext,
}
width = int_or_none(stream.get('videoWidthInPixels'))
height = int_or_none(stream.get('videoHeightInPixels'))
vbr = float_or_none(stream.get('videoBitRate'))
if width or height or vbr:
fmt.update({
'width': width,
'height': height,
'vbr': vbr,
})
else:
fmt['vcodec'] = 'none'
rtmp = re.search(r'^(?P<url>rtmpe?://(?P<host>[^/]+)/(?P<app>.+))/(?P<playpath>mp[34]:.+)$', stream_url)
if rtmp:
format_id = 'rtmp'
if stream.get('videoBitRate'):
format_id += '-%d' % int_or_none(stream['videoBitRate'])
http_format_id = format_id.replace('rtmp', 'http')
CDN_HOSTS = (
('delvenetworks.com', 'cpl.delvenetworks.com'),
('video.llnw.net', 's2.content.video.llnw.net'),
)
for cdn_host, http_host in CDN_HOSTS:
if cdn_host not in rtmp.group('host').lower():
continue
http_url = 'http://%s/%s' % (http_host, rtmp.group('playpath')[4:])
urls.append(http_url)
if self._is_valid_url(http_url, video_id, http_format_id):
http_fmt = fmt.copy()
http_fmt.update({
'url': http_url,
'format_id': http_format_id,
})
formats.append(http_fmt)
break
fmt.update({
'url': rtmp.group('url'),
'play_path': rtmp.group('playpath'),
'app': rtmp.group('app'),
'ext': 'flv',
'format_id': format_id,
})
formats.append(fmt)
for mobile_url in mobile_urls:
media_url = mobile_url.get('mobileUrl')
format_id = mobile_url.get('targetMediaPlatform')
if not media_url or format_id in ('Widevine', 'SmoothStreaming') or media_url in urls:
continue
urls.append(media_url)
ext = determine_ext(media_url)
if ext == 'm3u8':
formats.extend(self._extract_m3u8_formats(
media_url, video_id, 'mp4', 'm3u8_native',
m3u8_id=format_id, fatal=False))
elif ext == 'f4m':
formats.extend(self._extract_f4m_formats(
stream_url, video_id, f4m_id=format_id, fatal=False))
else:
formats.append({
'url': media_url,
'format_id': format_id,
'preference': -1,
'ext': ext,
})
self._sort_formats(formats)
title = properties['title']
description = properties.get('description')
timestamp = int_or_none(properties.get('publish_date') or properties.get('create_date'))
duration = float_or_none(properties.get('duration_in_milliseconds'), 1000)
filesize = int_or_none(properties.get('total_storage_in_bytes'))
categories = [properties.get('category')]
tags = properties.get('tags', [])
thumbnails = [{
'url': thumbnail['url'],
'width': int_or_none(thumbnail.get('width')),
'height': int_or_none(thumbnail.get('height')),
} for thumbnail in properties.get('thumbnails', []) if thumbnail.get('url')]
subtitles = {}
for caption in properties.get('captions', []):
lang = caption.get('language_code')
subtitles_url = caption.get('url')
if lang and subtitles_url:
subtitles.setdefault(lang, []).append({
'url': subtitles_url,
})
closed_captions_url = properties.get('closed_captions_url')
if closed_captions_url:
subtitles.setdefault('en', []).append({
'url': closed_captions_url,
'ext': 'ttml',
})
return {
'id': video_id,
'title': title,
'description': description,
'formats': formats,
'timestamp': timestamp,
'duration': duration,
'filesize': filesize,
'categories': categories,
'tags': tags,
'thumbnails': thumbnails,
'subtitles': subtitles,
}
class LimelightMediaIE(LimelightBaseIE):
IE_NAME = 'limelight'
_VALID_URL = r'''(?x)
(?:
limelight:media:|
https?://
(?:
link\.videoplatform\.limelight\.com/media/|
assets\.delvenetworks\.com/player/loader\.swf
)
\?.*?\bmediaId=
)
(?P<id>[a-z0-9]{32})
'''
_TESTS = [{
'url': 'http://link.videoplatform.limelight.com/media/?mediaId=3ffd040b522b4485b6d84effc750cd86',
'info_dict': {
'id': '3ffd040b522b4485b6d84effc750cd86',
'ext': 'mp4',
'title': 'HaP and the HB Prince Trailer',
'description': 'md5:8005b944181778e313d95c1237ddb640',
'thumbnail': r're:^https?://.*\.jpeg$',
'duration': 144.23,
'timestamp': 1244136834,
'upload_date': '20090604',
},
'params': {
# m3u8 download
'skip_download': True,
},
}, {
# video with subtitles
'url': 'limelight:media:a3e00274d4564ec4a9b29b9466432335',
'md5': '2fa3bad9ac321e23860ca23bc2c69e3d',
'info_dict': {
'id': 'a3e00274d4564ec4a9b29b9466432335',
'ext': 'mp4',
'title': '3Play Media Overview Video',
'thumbnail': r're:^https?://.*\.jpeg$',
'duration': 78.101,
'timestamp': 1338929955,
'upload_date': '20120605',
'subtitles': 'mincount:9',
},
}, {
'url': 'https://assets.delvenetworks.com/player/loader.swf?mediaId=8018a574f08d416e95ceaccae4ba0452',
'only_matching': True,
}]
_PLAYLIST_SERVICE_PATH = 'media'
_API_PATH = 'media'
def _real_extract(self, url):
url, smuggled_data = unsmuggle_url(url, {})
video_id = self._match_id(url)
self._initialize_geo_bypass(smuggled_data.get('geo_countries'))
pc, mobile, metadata = self._extract(
video_id, 'getPlaylistByMediaId',
'getMobilePlaylistByMediaId', 'properties',
smuggled_data.get('source_url'))
return self._extract_info(
pc['playlistItems'][0].get('streams', []),
mobile['mediaList'][0].get('mobileUrls', []) if mobile else [],
metadata)
class LimelightChannelIE(LimelightBaseIE):
IE_NAME = 'limelight:channel'
_VALID_URL = r'''(?x)
(?:
limelight:channel:|
https?://
(?:
link\.videoplatform\.limelight\.com/media/|
assets\.delvenetworks\.com/player/loader\.swf
)
\?.*?\bchannelId=
)
(?P<id>[a-z0-9]{32})
'''
_TESTS = [{
'url': 'http://link.videoplatform.limelight.com/media/?channelId=ab6a524c379342f9b23642917020c082',
'info_dict': {
'id': 'ab6a524c379342f9b23642917020c082',
'title': 'Javascript Sample Code',
},
'playlist_mincount': 3,
}, {
'url': 'http://assets.delvenetworks.com/player/loader.swf?channelId=ab6a524c379342f9b23642917020c082',
'only_matching': True,
}]
_PLAYLIST_SERVICE_PATH = 'channel'
_API_PATH = 'channels'
def _real_extract(self, url):
url, smuggled_data = unsmuggle_url(url, {})
channel_id = self._match_id(url)
pc, mobile, medias = self._extract(
channel_id, 'getPlaylistByChannelId',
'getMobilePlaylistWithNItemsByChannelId?begin=0&count=-1',
'media', smuggled_data.get('source_url'))
entries = [
self._extract_info(
pc['playlistItems'][i].get('streams', []),
mobile['mediaList'][i].get('mobileUrls', []) if mobile else [],
medias['media_list'][i])
for i in range(len(medias['media_list']))]
return self.playlist_result(entries, channel_id, pc['title'])
class LimelightChannelListIE(LimelightBaseIE):
IE_NAME = 'limelight:channel_list'
_VALID_URL = r'''(?x)
(?:
limelight:channel_list:|
https?://
(?:
link\.videoplatform\.limelight\.com/media/|
assets\.delvenetworks\.com/player/loader\.swf
)
\?.*?\bchannelListId=
)
(?P<id>[a-z0-9]{32})
'''
_TESTS = [{
'url': 'http://link.videoplatform.limelight.com/media/?channelListId=301b117890c4465c8179ede21fd92e2b',
'info_dict': {
'id': '301b117890c4465c8179ede21fd92e2b',
'title': 'Website - Hero Player',
},
'playlist_mincount': 2,
}, {
'url': 'https://assets.delvenetworks.com/player/loader.swf?channelListId=301b117890c4465c8179ede21fd92e2b',
'only_matching': True,
}]
_PLAYLIST_SERVICE_PATH = 'channel_list'
def _real_extract(self, url):
channel_list_id = self._match_id(url)
channel_list = self._call_playlist_service(channel_list_id, 'getMobileChannelListById')
entries = [
self.url_result('limelight:channel:%s' % channel['id'], 'LimelightChannel')
for channel in channel_list['channelList']]
return self.playlist_result(entries, channel_list_id, channel_list['title'])
|
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,
5819,
492,
8434,
63,
12815,
199,
504,
2508,
1208,
492,
334,
272,
6705,
63,
832,
12,
272,
2069,
63,
269,
63,
3592,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
4383,
1518,
3845,
63,
633,
12,
272,
625,
3300,
1518,
3845,
63,
633,
12,
272,
19783,
12,
199,
9,
421,
199,
533,
491,
1036,
4040,
1563,
4332,
8,
18283,
304,
272,
485,
11625,
4924,
63,
10486,
63,
2632,
275,
283,
1014,
921,
10777,
13,
1190,
14,
6371,
80,
14,
914,
13100,
14,
846,
15,
82,
15,
27259,
3167,
3149,
83,
3149,
83,
3149,
83,
7,
272,
485,
3735,
63,
2632,
275,
283,
1014,
921,
1246,
14,
3722,
14,
18687,
4040,
14,
957,
15,
3911,
15,
19916,
12270,
3149,
83,
3149,
83,
3149,
83,
3149,
83,
14,
1001,
7,
339,
768,
3744,
272,
347,
485,
5005,
63,
3603,
8,
1886,
12,
9248,
12,
1350,
63,
633,
304,
267,
24546,
275,
469,
288,
283,
11398,
356,
283,
4603,
297,
288,
283,
5358,
356,
283,
2775,
297,
288,
283,
5358,
1296,
356,
283,
2775,
63,
513,
297,
267,
789,
267,
4811,
275,
942,
267,
367,
4928,
12,
3991,
63,
344,
315,
295,
14,
6452,
8,
355,
519,
7,
44,
1036,
4040,
10921,
4537,
1117,
6200,
8,
11398,
92,
5358,
92,
5358,
1296,
2862,
779,
3212,
418,
2229,
48,
28,
344,
9514,
65,
13,
90,
16,
13,
25,
8194,
708,
25583,
355,
9248,
304,
288,
4811,
14,
740,
8,
1886,
14,
633,
63,
1099,
8,
355,
4383,
1518,
3845,
63,
633,
8,
490,
283,
18687,
4040,
2689,
83,
2689,
83,
7,
450,
334,
14344,
59,
5091,
467,
3991,
63,
344,
395,
490,
791,
1365,
63,
633,
356,
1350,
63,
633,
8688,
355,
283,
44,
1036,
4040,
5,
83,
7,
450,
4928,
12,
3991,
63,
344,
430,
267,
367,
14208,
315,
295,
14,
19373,
8,
355,
327,
3709,
1126,
359,
17,
61,
1021,
2225,
1077,
506,
8840,
4472,
370,
355,
327,
491,
1036,
4040,
27395,
10921,
29189,
1325,
10330,
293,
527,
7251,
6775,
355,
327,
626,
2793,
1133,
8840,
1336,
652,
334,
69,
14,
71,
14,
359,
18,
6575,
355,
327,
413,
14,
1455,
921,
4058,
14,
19,
2802,
4603,
14,
957,
15,
15907,
15,
287,
13,
527,
15,
19813,
15,
1081,
1138,
12744,
2036,
13,
44,
1036,
4040,
13,
27907,
13,
1589,
13,
9155,
852,
13,
5061,
13,
1045,
13,
1589,
13,
44,
1036,
4040,
13,
10921,
13,
265,
13,
14398,
13,
5926,
1606,
355,
327,
499,
14,
1455,
921,
1544,
14,
939,
265,
65,
14,
957,
15,
1906,
559,
1051,
707,
20463,
10680,
355,
519,
2344,
2229,
12915,
9,
490,
665,
785,
25524,
533,
30982,
3212,
1105,
5169,
2229,
12525,
17,
680,
3342,
60,
66,
44,
1036,
4040,
27395,
10921,
29189,
60,
66,
5169,
2229,
12525,
17,
680,
3342,
60,
17,
28959,
27124,
717,
665,
635,
25524,
1169,
536,
30982,
3212,
1105,
11331,
16270,
60,
18,
25524,
1169,
574,
30982,
3212,
1105,
5169,
2229,
12525,
19,
680,
3342,
2229,
48,
28,
5091,
30,
4603,
92,
2775,
5169,
1296,
5547,
9,
1304,
29,
2229,
48,
28,
344,
9514,
65,
13,
90,
16,
13,
25,
8194,
708,
1552,
355,
21281,
9248,
304,
288,
4928,
12,
3991,
63,
344,
275,
14208,
14,
923,
360,
5091,
659,
14208,
14,
923,
360,
344,
358,
288,
4811,
14,
740,
8,
1886,
14,
633,
63,
1099,
8,
355,
4383,
1518,
3845,
63,
633,
8,
490,
283,
18687,
4040,
2689,
83,
2689,
83,
7,
450,
334,
5091,
12,
3991,
63,
344,
395,
490,
791,
1365,
63,
633,
356,
1350,
63,
633,
8688,
355,
283,
44,
1036,
4040,
5,
83,
7,
450,
4928,
14,
18351,
1062,
3991,
63,
344,
430,
267,
372,
4811,
339,
347,
485,
1250,
63,
10411,
63,
1364,
8,
277,
12,
1242,
63,
344,
12,
1083,
12,
14294,
29,
549,
12,
25104,
29,
403,
304,
267,
2323,
275,
1052,
267,
340,
25104,
26,
288,
2323,
459,
28900,
418,
275,
25104,
267,
862,
26,
288,
372,
291,
423,
4249,
63,
1001,
8,
355,
291,
423,
11625,
4924,
63,
10486,
63,
2632,
450,
334,
277,
423,
11625,
4924,
63,
10486,
63,
3243,
12,
1242,
63,
344,
12,
1083,
395,
355,
1242,
63,
344,
12,
283,
18085,
16527,
513,
3167,
450,
83,
4840,
7,
450,
1083,
12,
14294,
29,
16208,
12,
2323,
29,
2139,
9,
267,
871,
19783,
465,
325,
26,
288,
340,
1228,
8,
69,
14,
2651,
12,
8434,
63,
12815,
9,
436,
325,
14,
2651,
14,
600,
508,
13269,
26,
355,
1125,
275,
291,
423,
1122,
63,
1001,
8,
69,
14,
2651,
14,
739,
1252,
2708,
1062,
1242,
63,
344,
11820,
5506,
2545,
1317,
3946,
7980,
418,
355,
340,
1125,
508,
283,
17393,
15049,
356,
490,
291,
14,
3730,
63,
6721,
63,
17973,
342,
355,
746,
19783,
8,
705,
12,
1420,
29,
549,
9,
288,
746,
339,
347,
485,
1250,
63,
1246,
8,
277,
12,
13237,
63,
344,
12,
1242,
63,
344,
12,
1083,
304,
267,
372,
291,
423,
4249,
63,
1001,
8,
288,
291,
423,
3735,
63,
2632,
450,
334,
9071,
63,
344,
12,
291,
423,
3735,
63,
3243,
12,
1242,
63,
344,
12,
1083,
395,
288,
1242,
63,
344,
12,
283,
18085,
3261,
450,
83,
4840,
7,
450,
1083,
9,
339,
347,
485,
5005,
8,
277,
12,
1242,
63,
344,
12,
13171,
63,
765,
12,
21305,
63,
765,
12,
3404,
63,
765,
12,
25104,
29,
403,
304,
267,
13171,
275,
291,
423,
1250,
63,
10411,
63,
1364,
8,
1053,
63,
344,
12,
13171,
63,
765,
12,
25104,
29,
20996,
9,
267,
3341,
275,
291,
423,
1250,
63,
1246,
8,
2352,
459,
1308,
1304,
995,
1242,
63,
344,
12,
3404,
63,
765,
9,
267,
21305,
275,
291,
423,
1250,
63,
10411,
63,
1364,
8,
1053,
63,
344,
12,
21305,
63,
765,
12,
14294,
29,
797,
12,
25104,
29,
20996,
9,
267,
372,
13171,
12,
21305,
12,
3341,
339,
347,
485,
5005,
63,
815,
8,
277,
12,
13788,
12,
21305,
63,
3603,
12,
4382,
304,
267,
3991,
63,
344,
275,
4382,
459,
4603,
63,
344,
418,
267,
6752,
275,
942,
267,
8187,
275,
942
] |
[
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,
5819,
492,
8434,
63,
12815,
199,
504,
2508,
1208,
492,
334,
272,
6705,
63,
832,
12,
272,
2069,
63,
269,
63,
3592,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
4383,
1518,
3845,
63,
633,
12,
272,
625,
3300,
1518,
3845,
63,
633,
12,
272,
19783,
12,
199,
9,
421,
199,
533,
491,
1036,
4040,
1563,
4332,
8,
18283,
304,
272,
485,
11625,
4924,
63,
10486,
63,
2632,
275,
283,
1014,
921,
10777,
13,
1190,
14,
6371,
80,
14,
914,
13100,
14,
846,
15,
82,
15,
27259,
3167,
3149,
83,
3149,
83,
3149,
83,
7,
272,
485,
3735,
63,
2632,
275,
283,
1014,
921,
1246,
14,
3722,
14,
18687,
4040,
14,
957,
15,
3911,
15,
19916,
12270,
3149,
83,
3149,
83,
3149,
83,
3149,
83,
14,
1001,
7,
339,
768,
3744,
272,
347,
485,
5005,
63,
3603,
8,
1886,
12,
9248,
12,
1350,
63,
633,
304,
267,
24546,
275,
469,
288,
283,
11398,
356,
283,
4603,
297,
288,
283,
5358,
356,
283,
2775,
297,
288,
283,
5358,
1296,
356,
283,
2775,
63,
513,
297,
267,
789,
267,
4811,
275,
942,
267,
367,
4928,
12,
3991,
63,
344,
315,
295,
14,
6452,
8,
355,
519,
7,
44,
1036,
4040,
10921,
4537,
1117,
6200,
8,
11398,
92,
5358,
92,
5358,
1296,
2862,
779,
3212,
418,
2229,
48,
28,
344,
9514,
65,
13,
90,
16,
13,
25,
8194,
708,
25583,
355,
9248,
304,
288,
4811,
14,
740,
8,
1886,
14,
633,
63,
1099,
8,
355,
4383,
1518,
3845,
63,
633,
8,
490,
283,
18687,
4040,
2689,
83,
2689,
83,
7,
450,
334,
14344,
59,
5091,
467,
3991,
63,
344,
395,
490,
791,
1365,
63,
633,
356,
1350,
63,
633,
8688,
355,
283,
44,
1036,
4040,
5,
83,
7,
450,
4928,
12,
3991,
63,
344,
430,
267,
367,
14208,
315,
295,
14,
19373,
8,
355,
327,
3709,
1126,
359,
17,
61,
1021,
2225,
1077,
506,
8840,
4472,
370,
355,
327,
491,
1036,
4040,
27395,
10921,
29189,
1325,
10330,
293,
527,
7251,
6775,
355,
327,
626,
2793,
1133,
8840,
1336,
652,
334,
69,
14,
71,
14,
359,
18,
6575,
355,
327,
413,
14,
1455,
921,
4058,
14,
19,
2802,
4603,
14,
957,
15,
15907,
15,
287,
13,
527,
15,
19813,
15,
1081,
1138,
12744,
2036,
13,
44,
1036,
4040,
13,
27907,
13,
1589,
13,
9155,
852,
13,
5061,
13,
1045,
13,
1589,
13,
44,
1036,
4040,
13,
10921,
13,
265,
13,
14398,
13,
5926,
1606,
355,
327,
499,
14,
1455,
921,
1544,
14,
939,
265,
65,
14,
957,
15,
1906,
559,
1051,
707,
20463,
10680,
355,
519,
2344,
2229,
12915,
9,
490,
665,
785,
25524,
533,
30982,
3212,
1105,
5169,
2229,
12525,
17,
680,
3342,
60,
66,
44,
1036,
4040,
27395,
10921,
29189,
60,
66,
5169,
2229,
12525,
17,
680,
3342,
60,
17,
28959,
27124,
717,
665,
635,
25524,
1169,
536,
30982,
3212,
1105,
11331,
16270,
60,
18,
25524,
1169,
574,
30982,
3212,
1105,
5169,
2229,
12525,
19,
680,
3342,
2229,
48,
28,
5091,
30,
4603,
92,
2775,
5169,
1296,
5547,
9,
1304,
29,
2229,
48,
28,
344,
9514,
65,
13,
90,
16,
13,
25,
8194,
708,
1552,
355,
21281,
9248,
304,
288,
4928,
12,
3991,
63,
344,
275,
14208,
14,
923,
360,
5091,
659,
14208,
14,
923,
360,
344,
358,
288,
4811,
14,
740,
8,
1886,
14,
633,
63,
1099,
8,
355,
4383,
1518,
3845,
63,
633,
8,
490,
283,
18687,
4040,
2689,
83,
2689,
83,
7,
450,
334,
5091,
12,
3991,
63,
344,
395,
490,
791,
1365,
63,
633,
356,
1350,
63,
633,
8688,
355,
283,
44,
1036,
4040,
5,
83,
7,
450,
4928,
14,
18351,
1062,
3991,
63,
344,
430,
267,
372,
4811,
339,
347,
485,
1250,
63,
10411,
63,
1364,
8,
277,
12,
1242,
63,
344,
12,
1083,
12,
14294,
29,
549,
12,
25104,
29,
403,
304,
267,
2323,
275,
1052,
267,
340,
25104,
26,
288,
2323,
459,
28900,
418,
275,
25104,
267,
862,
26,
288,
372,
291,
423,
4249,
63,
1001,
8,
355,
291,
423,
11625,
4924,
63,
10486,
63,
2632,
450,
334,
277,
423,
11625,
4924,
63,
10486,
63,
3243,
12,
1242,
63,
344,
12,
1083,
395,
355,
1242,
63,
344,
12,
283,
18085,
16527,
513,
3167,
450,
83,
4840,
7,
450,
1083,
12,
14294,
29,
16208,
12,
2323,
29,
2139,
9,
267,
871,
19783,
465,
325,
26,
288,
340,
1228,
8,
69,
14,
2651,
12,
8434,
63,
12815,
9,
436,
325,
14,
2651,
14,
600,
508,
13269,
26,
355,
1125,
275,
291,
423,
1122,
63,
1001,
8,
69,
14,
2651,
14,
739,
1252,
2708,
1062,
1242,
63,
344,
11820,
5506,
2545,
1317,
3946,
7980,
418,
355,
340,
1125,
508,
283,
17393,
15049,
356,
490,
291,
14,
3730,
63,
6721,
63,
17973,
342,
355,
746,
19783,
8,
705,
12,
1420,
29,
549,
9,
288,
746,
339,
347,
485,
1250,
63,
1246,
8,
277,
12,
13237,
63,
344,
12,
1242,
63,
344,
12,
1083,
304,
267,
372,
291,
423,
4249,
63,
1001,
8,
288,
291,
423,
3735,
63,
2632,
450,
334,
9071,
63,
344,
12,
291,
423,
3735,
63,
3243,
12,
1242,
63,
344,
12,
1083,
395,
288,
1242,
63,
344,
12,
283,
18085,
3261,
450,
83,
4840,
7,
450,
1083,
9,
339,
347,
485,
5005,
8,
277,
12,
1242,
63,
344,
12,
13171,
63,
765,
12,
21305,
63,
765,
12,
3404,
63,
765,
12,
25104,
29,
403,
304,
267,
13171,
275,
291,
423,
1250,
63,
10411,
63,
1364,
8,
1053,
63,
344,
12,
13171,
63,
765,
12,
25104,
29,
20996,
9,
267,
3341,
275,
291,
423,
1250,
63,
1246,
8,
2352,
459,
1308,
1304,
995,
1242,
63,
344,
12,
3404,
63,
765,
9,
267,
21305,
275,
291,
423,
1250,
63,
10411,
63,
1364,
8,
1053,
63,
344,
12,
21305,
63,
765,
12,
14294,
29,
797,
12,
25104,
29,
20996,
9,
267,
372,
13171,
12,
21305,
12,
3341,
339,
347,
485,
5005,
63,
815,
8,
277,
12,
13788,
12,
21305,
63,
3603,
12,
4382,
304,
267,
3991,
63,
344,
275,
4382,
459,
4603,
63,
344,
418,
267,
6752,
275,
942,
267,
8187,
275,
942,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kbrebanov/ansible-modules-extras
|
database/vertica/vertica_facts.py
|
15
|
9256
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION = """
---
module: vertica_facts
version_added: '2.0'
short_description: Gathers Vertica database facts.
description:
- Gathers Vertica database facts.
options:
cluster:
description:
- Name of the cluster running the schema.
required: false
default: localhost
port:
description:
Database port to connect to.
required: false
default: 5433
db:
description:
- Name of the database running the schema.
required: false
default: null
login_user:
description:
- The username used to authenticate with.
required: false
default: dbadmin
login_password:
description:
- The password used to authenticate with.
required: false
default: null
notes:
- The default authentication assumes that you are either logging in as or sudo'ing
to the C(dbadmin) account on the host.
- This module uses C(pyodbc), a Python ODBC database adapter. You must ensure
that C(unixODBC) and C(pyodbc) is installed on the host and properly configured.
- Configuring C(unixODBC) for Vertica requires C(Driver = /opt/vertica/lib64/libverticaodbc.so)
to be added to the C(Vertica) section of either C(/etc/odbcinst.ini) or C($HOME/.odbcinst.ini)
and both C(ErrorMessagesPath = /opt/vertica/lib64) and C(DriverManagerEncoding = UTF-16)
to be added to the C(Driver) section of either C(/etc/vertica.ini) or C($HOME/.vertica.ini).
requirements: [ 'unixODBC', 'pyodbc' ]
author: "Dariusz Owczarek (@dareko)"
"""
EXAMPLES = """
- name: gathering vertica facts
vertica_facts: db=db_name
"""
try:
import pyodbc
except ImportError:
pyodbc_found = False
else:
pyodbc_found = True
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
class NotSupportedError(Exception):
pass
# module specific functions
def get_schema_facts(cursor, schema=''):
facts = {}
cursor.execute("""
select schema_name, schema_owner, create_time
from schemata
where not is_system_schema and schema_name not in ('public')
and (? = '' or schema_name ilike ?)
""", schema, schema)
while True:
rows = cursor.fetchmany(100)
if not rows:
break
for row in rows:
facts[row.schema_name.lower()] = {
'name': row.schema_name,
'owner': row.schema_owner,
'create_time': str(row.create_time),
'usage_roles': [],
'create_roles': []}
cursor.execute("""
select g.object_name as schema_name, r.name as role_name,
lower(g.privileges_description) privileges_description
from roles r join grants g
on g.grantee = r.name and g.object_type='SCHEMA'
and g.privileges_description like '%USAGE%'
and g.grantee not in ('public', 'dbadmin')
and (? = '' or g.object_name ilike ?)
""", schema, schema)
while True:
rows = cursor.fetchmany(100)
if not rows:
break
for row in rows:
schema_key = row.schema_name.lower()
if 'create' in row.privileges_description:
facts[schema_key]['create_roles'].append(row.role_name)
else:
facts[schema_key]['usage_roles'].append(row.role_name)
return facts
def get_user_facts(cursor, user=''):
facts = {}
cursor.execute("""
select u.user_name, u.is_locked, u.lock_time,
p.password, p.acctexpired as is_expired,
u.profile_name, u.resource_pool,
u.all_roles, u.default_roles
from users u join password_auditor p on p.user_id = u.user_id
where not u.is_super_user
and (? = '' or u.user_name ilike ?)
""", user, user)
while True:
rows = cursor.fetchmany(100)
if not rows:
break
for row in rows:
user_key = row.user_name.lower()
facts[user_key] = {
'name': row.user_name,
'locked': str(row.is_locked),
'password': row.password,
'expired': str(row.is_expired),
'profile': row.profile_name,
'resource_pool': row.resource_pool,
'roles': [],
'default_roles': []}
if row.is_locked:
facts[user_key]['locked_time'] = str(row.lock_time)
if row.all_roles:
facts[user_key]['roles'] = row.all_roles.replace(' ', '').split(',')
if row.default_roles:
facts[user_key]['default_roles'] = row.default_roles.replace(' ', '').split(',')
return facts
def get_role_facts(cursor, role=''):
facts = {}
cursor.execute("""
select r.name, r.assigned_roles
from roles r
where (? = '' or r.name ilike ?)
""", role, role)
while True:
rows = cursor.fetchmany(100)
if not rows:
break
for row in rows:
role_key = row.name.lower()
facts[role_key] = {
'name': row.name,
'assigned_roles': []}
if row.assigned_roles:
facts[role_key]['assigned_roles'] = row.assigned_roles.replace(' ', '').split(',')
return facts
def get_configuration_facts(cursor, parameter=''):
facts = {}
cursor.execute("""
select c.parameter_name, c.current_value, c.default_value
from configuration_parameters c
where c.node_name = 'ALL'
and (? = '' or c.parameter_name ilike ?)
""", parameter, parameter)
while True:
rows = cursor.fetchmany(100)
if not rows:
break
for row in rows:
facts[row.parameter_name.lower()] = {
'parameter_name': row.parameter_name,
'current_value': row.current_value,
'default_value': row.default_value}
return facts
def get_node_facts(cursor, schema=''):
facts = {}
cursor.execute("""
select node_name, node_address, export_address, node_state, node_type,
catalog_path
from nodes
""")
while True:
rows = cursor.fetchmany(100)
if not rows:
break
for row in rows:
facts[row.node_address] = {
'node_name': row.node_name,
'export_address': row.export_address,
'node_state': row.node_state,
'node_type': row.node_type,
'catalog_path': row.catalog_path}
return facts
# module logic
def main():
module = AnsibleModule(
argument_spec=dict(
cluster=dict(default='localhost'),
port=dict(default='5433'),
db=dict(default=None),
login_user=dict(default='dbadmin'),
login_password=dict(default=None),
), supports_check_mode = True)
if not pyodbc_found:
module.fail_json(msg="The python pyodbc module is required.")
db = ''
if module.params['db']:
db = module.params['db']
try:
dsn = (
"Driver=Vertica;"
"Server=%s;"
"Port=%s;"
"Database=%s;"
"User=%s;"
"Password=%s;"
"ConnectionLoadBalance=%s"
) % (module.params['cluster'], module.params['port'], db,
module.params['login_user'], module.params['login_password'], 'true')
db_conn = pyodbc.connect(dsn, autocommit=True)
cursor = db_conn.cursor()
except Exception:
e = get_exception()
module.fail_json(msg="Unable to connect to database: %s." % str(e))
try:
schema_facts = get_schema_facts(cursor)
user_facts = get_user_facts(cursor)
role_facts = get_role_facts(cursor)
configuration_facts = get_configuration_facts(cursor)
node_facts = get_node_facts(cursor)
module.exit_json(changed=False,
ansible_facts={'vertica_schemas': schema_facts,
'vertica_users': user_facts,
'vertica_roles': role_facts,
'vertica_configuration': configuration_facts,
'vertica_nodes': node_facts})
except NotSupportedError:
e = get_exception()
module.fail_json(msg=str(e))
except SystemExit:
# avoid catching this on python 2.4
raise
except Exception:
e = get_exception()
module.fail_json(msg=e)
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,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
809,
15922,
63,
5047,
199,
1023,
63,
3270,
26,
283,
18,
14,
16,
7,
199,
3612,
63,
1802,
26,
19634,
83,
5444,
15922,
3050,
9036,
14,
199,
1802,
26,
523,
446,
19634,
83,
5444,
15922,
3050,
9036,
14,
199,
1419,
26,
523,
4350,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
4350,
3879,
314,
4177,
14,
272,
1415,
26,
3055,
272,
849,
26,
11667,
523,
1844,
26,
272,
1369,
26,
489,
8692,
1844,
370,
4907,
370,
14,
272,
1415,
26,
3055,
272,
849,
26,
13470,
1153,
523,
1592,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
3050,
3879,
314,
4177,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
4676,
63,
751,
26,
272,
1369,
26,
489,
446,
710,
3434,
1202,
370,
12895,
543,
14,
272,
1415,
26,
3055,
272,
849,
26,
1592,
2113,
523,
4676,
63,
2060,
26,
272,
1369,
26,
489,
446,
710,
2505,
1202,
370,
12895,
543,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
199,
5983,
26,
523,
446,
710,
849,
6299,
15194,
626,
1265,
787,
1902,
2050,
315,
465,
503,
14682,
7,
316,
272,
370,
314,
445,
8,
697,
2113,
9,
2933,
641,
314,
1591,
14,
523,
446,
961,
859,
4440,
445,
8,
647,
19887,
395,
282,
2018,
593,
23317,
3050,
12146,
14,
2047,
1471,
4868,
272,
626,
445,
8,
11864,
47,
23317,
9,
436,
445,
8,
647,
19887,
9,
365,
4903,
641,
314,
1591,
436,
7684,
7526,
14,
523,
446,
4094,
4039,
445,
8,
11864,
47,
23317,
9,
367,
5444,
15922,
5074,
445,
8,
6158,
275,
1182,
2992,
15,
12101,
696,
15,
773,
772,
15,
773,
12101,
696,
19887,
14,
1152,
9,
272,
370,
506,
3483,
370,
314,
445,
8,
3673,
15922,
9,
3420,
402,
1902,
445,
29478,
6839,
15,
19887,
3615,
14,
2730,
9,
503,
445,
22187,
9524,
8083,
19887,
3615,
14,
2730,
9,
272,
436,
3865,
445,
8,
547,
14508,
2042,
275,
1182,
2992,
15,
12101,
696,
15,
773,
772,
9,
436,
445,
8,
6158,
2988,
7630,
275,
9094,
13,
975,
9,
272,
370,
506,
3483,
370,
314,
445,
8,
6158,
9,
3420,
402,
1902,
445,
29478,
6839,
15,
12101,
696,
14,
2730,
9,
503,
445,
22187,
9524,
8083,
12101,
696,
14,
2730,
680,
199,
7538,
26,
359,
283,
11864,
47,
23317,
297,
283,
647,
19887,
7,
1622,
199,
2502,
26,
298,
36,
759,
527,
90,
593,
13683,
90,
1530,
75,
8593,
983,
264,
7697,
2924,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
13082,
316,
809,
15922,
9036,
523,
809,
15922,
63,
5047,
26,
1592,
29,
697,
63,
354,
199,
624,
199,
199,
893,
26,
272,
492,
1134,
19887,
199,
2590,
3545,
26,
272,
1134,
19887,
63,
4214,
275,
756,
199,
2836,
26,
272,
1134,
19887,
63,
4214,
275,
715,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
647,
5819,
1194,
492,
664,
63,
1971,
421,
199,
533,
2832,
10682,
547,
8,
1726,
304,
272,
986,
199,
199,
3,
859,
2488,
3423,
199,
199,
318,
664,
63,
3629,
63,
5047,
8,
3937,
12,
4177,
9280,
272,
9036,
275,
1052,
272,
3920,
14,
2526,
4852,
267,
3504,
4177,
63,
354,
12,
4177,
63,
4597,
12,
1218,
63,
521,
267,
687,
308,
24448,
419,
267,
2382,
440,
365,
63,
2253,
63,
3629,
436,
4177,
63,
354,
440,
315,
661,
3455,
358,
267,
436,
7558,
275,
2125,
503,
4177,
63,
354,
284,
2930,
5805,
9,
272,
10327,
4177,
12,
4177,
9,
272,
1830,
715,
26,
267,
4730,
275,
3920,
14,
3535,
3479,
8,
1960,
9,
267,
340,
440,
4730,
26,
288,
2059,
267,
367,
1962,
315,
4730,
26,
288,
9036,
59,
1143,
14,
3629,
63,
354,
14,
2325,
5106,
275,
469,
355,
283,
354,
356,
1962,
14,
3629,
63,
354,
12,
355,
283,
4597,
356,
1962,
14,
3629,
63,
4597,
12,
355,
283,
981,
63,
521,
356,
620,
8,
1143,
14,
981,
63,
521,
395,
355,
283,
3807,
63,
8050,
356,
990,
355,
283,
981,
63,
8050,
356,
23455,
272,
3920,
14,
2526,
4852,
267,
3504,
486,
14,
785,
63,
354,
465,
4177,
63,
354,
12,
519,
14,
354,
465,
4719,
63,
354,
12,
267,
5117,
8,
71,
14,
27852,
63,
1802,
9,
20001,
63,
1802,
267,
687,
11689,
519,
4263,
7192,
2285,
486,
267,
641,
486,
14,
26655,
15557,
275,
519,
14,
354,
436,
486,
14,
785,
63,
466,
534,
10926,
7,
267,
436,
486,
14,
27852,
63,
1802,
2839,
1543,
20274,
5,
7,
267,
436,
486,
14,
26655,
15557,
440,
315,
661,
3455,
297,
283,
697,
2113,
358,
267,
436,
7558,
275,
2125,
503,
486,
14,
785,
63,
354,
284,
2930,
5805,
9,
272,
10327,
4177,
12,
4177,
9,
272,
1830,
715,
26,
267,
4730,
275,
3920,
14,
3535,
3479,
8,
1960,
9,
267,
340,
440,
4730,
26,
288,
2059,
267,
367,
1962,
315,
4730,
26,
288,
4177,
63,
498,
275,
1962,
14,
3629,
63,
354,
14,
2325,
342,
288,
340,
283,
981,
7,
315,
1962,
14,
27852,
63,
1802,
26,
355,
9036,
59,
3629,
63,
498,
2733,
981,
63,
8050,
2278,
740,
8,
1143
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
809,
15922,
63,
5047,
199,
1023,
63,
3270,
26,
283,
18,
14,
16,
7,
199,
3612,
63,
1802,
26,
19634,
83,
5444,
15922,
3050,
9036,
14,
199,
1802,
26,
523,
446,
19634,
83,
5444,
15922,
3050,
9036,
14,
199,
1419,
26,
523,
4350,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
4350,
3879,
314,
4177,
14,
272,
1415,
26,
3055,
272,
849,
26,
11667,
523,
1844,
26,
272,
1369,
26,
489,
8692,
1844,
370,
4907,
370,
14,
272,
1415,
26,
3055,
272,
849,
26,
13470,
1153,
523,
1592,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
3050,
3879,
314,
4177,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
4676,
63,
751,
26,
272,
1369,
26,
489,
446,
710,
3434,
1202,
370,
12895,
543,
14,
272,
1415,
26,
3055,
272,
849,
26,
1592,
2113,
523,
4676,
63,
2060,
26,
272,
1369,
26,
489,
446,
710,
2505,
1202,
370,
12895,
543,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
199,
5983,
26,
523,
446,
710,
849,
6299,
15194,
626,
1265,
787,
1902,
2050,
315,
465,
503,
14682,
7,
316,
272,
370,
314,
445,
8,
697,
2113,
9,
2933,
641,
314,
1591,
14,
523,
446,
961,
859,
4440,
445,
8,
647,
19887,
395,
282,
2018,
593,
23317,
3050,
12146,
14,
2047,
1471,
4868,
272,
626,
445,
8,
11864,
47,
23317,
9,
436,
445,
8,
647,
19887,
9,
365,
4903,
641,
314,
1591,
436,
7684,
7526,
14,
523,
446,
4094,
4039,
445,
8,
11864,
47,
23317,
9,
367,
5444,
15922,
5074,
445,
8,
6158,
275,
1182,
2992,
15,
12101,
696,
15,
773,
772,
15,
773,
12101,
696,
19887,
14,
1152,
9,
272,
370,
506,
3483,
370,
314,
445,
8,
3673,
15922,
9,
3420,
402,
1902,
445,
29478,
6839,
15,
19887,
3615,
14,
2730,
9,
503,
445,
22187,
9524,
8083,
19887,
3615,
14,
2730,
9,
272,
436,
3865,
445,
8,
547,
14508,
2042,
275,
1182,
2992,
15,
12101,
696,
15,
773,
772,
9,
436,
445,
8,
6158,
2988,
7630,
275,
9094,
13,
975,
9,
272,
370,
506,
3483,
370,
314,
445,
8,
6158,
9,
3420,
402,
1902,
445,
29478,
6839,
15,
12101,
696,
14,
2730,
9,
503,
445,
22187,
9524,
8083,
12101,
696,
14,
2730,
680,
199,
7538,
26,
359,
283,
11864,
47,
23317,
297,
283,
647,
19887,
7,
1622,
199,
2502,
26,
298,
36,
759,
527,
90,
593,
13683,
90,
1530,
75,
8593,
983,
264,
7697,
2924,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
13082,
316,
809,
15922,
9036,
523,
809,
15922,
63,
5047,
26,
1592,
29,
697,
63,
354,
199,
624,
199,
199,
893,
26,
272,
492,
1134,
19887,
199,
2590,
3545,
26,
272,
1134,
19887,
63,
4214,
275,
756,
199,
2836,
26,
272,
1134,
19887,
63,
4214,
275,
715,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
647,
5819,
1194,
492,
664,
63,
1971,
421,
199,
533,
2832,
10682,
547,
8,
1726,
304,
272,
986,
199,
199,
3,
859,
2488,
3423,
199,
199,
318,
664,
63,
3629,
63,
5047,
8,
3937,
12,
4177,
9280,
272,
9036,
275,
1052,
272,
3920,
14,
2526,
4852,
267,
3504,
4177,
63,
354,
12,
4177,
63,
4597,
12,
1218,
63,
521,
267,
687,
308,
24448,
419,
267,
2382,
440,
365,
63,
2253,
63,
3629,
436,
4177,
63,
354,
440,
315,
661,
3455,
358,
267,
436,
7558,
275,
2125,
503,
4177,
63,
354,
284,
2930,
5805,
9,
272,
10327,
4177,
12,
4177,
9,
272,
1830,
715,
26,
267,
4730,
275,
3920,
14,
3535,
3479,
8,
1960,
9,
267,
340,
440,
4730,
26,
288,
2059,
267,
367,
1962,
315,
4730,
26,
288,
9036,
59,
1143,
14,
3629,
63,
354,
14,
2325,
5106,
275,
469,
355,
283,
354,
356,
1962,
14,
3629,
63,
354,
12,
355,
283,
4597,
356,
1962,
14,
3629,
63,
4597,
12,
355,
283,
981,
63,
521,
356,
620,
8,
1143,
14,
981,
63,
521,
395,
355,
283,
3807,
63,
8050,
356,
990,
355,
283,
981,
63,
8050,
356,
23455,
272,
3920,
14,
2526,
4852,
267,
3504,
486,
14,
785,
63,
354,
465,
4177,
63,
354,
12,
519,
14,
354,
465,
4719,
63,
354,
12,
267,
5117,
8,
71,
14,
27852,
63,
1802,
9,
20001,
63,
1802,
267,
687,
11689,
519,
4263,
7192,
2285,
486,
267,
641,
486,
14,
26655,
15557,
275,
519,
14,
354,
436,
486,
14,
785,
63,
466,
534,
10926,
7,
267,
436,
486,
14,
27852,
63,
1802,
2839,
1543,
20274,
5,
7,
267,
436,
486,
14,
26655,
15557,
440,
315,
661,
3455,
297,
283,
697,
2113,
358,
267,
436,
7558,
275,
2125,
503,
486,
14,
785,
63,
354,
284,
2930,
5805,
9,
272,
10327,
4177,
12,
4177,
9,
272,
1830,
715,
26,
267,
4730,
275,
3920,
14,
3535,
3479,
8,
1960,
9,
267,
340,
440,
4730,
26,
288,
2059,
267,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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
] |
S0lll0s/powerline
|
powerline/lib/overrides.py
|
33
|
1815
|
# vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import, print_function)
import json
from powerline.lib.dict import REMOVE_THIS_KEY
def parse_value(s):
'''Convert string to Python object
Rules:
* Empty string means that corresponding key should be removed from the
dictionary.
* Strings that start with a minus, digit or with some character that starts
JSON collection or string object are parsed as JSON.
* JSON special values ``null``, ``true``, ``false`` (case matters) are
parsed as JSON.
* All other values are considered to be raw strings.
:param str s: Parsed string.
:return: Python object.
'''
if not s:
return REMOVE_THIS_KEY
elif s[0] in '"{[0123456789-' or s in ('null', 'true', 'false'):
return json.loads(s)
else:
return s
def keyvaluesplit(s):
'''Split K1.K2=VAL into K1.K2 and parsed VAL
'''
if '=' not in s:
raise TypeError('Option must look like option=json_value')
if s[0] == '_':
raise ValueError('Option names must not start with `_\'')
idx = s.index('=')
o = s[:idx]
val = parse_value(s[idx + 1:])
return (o, val)
def parsedotval(s):
'''Parse K1.K2=VAL into {"K1":{"K2":VAL}}
``VAL`` is processed according to rules defined in :py:func:`parse_value`.
'''
if type(s) is tuple:
o, val = s
val = parse_value(val)
else:
o, val = keyvaluesplit(s)
keys = o.split('.')
if len(keys) > 1:
r = (keys[0], {})
rcur = r[1]
for key in keys[1:-1]:
rcur[key] = {}
rcur = rcur[key]
rcur[keys[-1]] = val
return r
else:
return (o, val)
def parse_override_var(s):
'''Parse a semicolon-separated list of strings into a sequence of values
Emits the same items in sequence as :py:func:`parsedotval` does.
'''
return (
parsedotval(item)
for item in s.split(';')
if item
)
|
mit
|
[
3,
6695,
26,
493,
2991,
29,
1624,
13,
24,
26,
889,
386,
199,
504,
636,
2443,
363,
492,
334,
2975,
63,
5955,
12,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
9,
199,
199,
646,
2022,
199,
199,
504,
7074,
604,
14,
773,
14,
807,
492,
5363,
16207,
63,
24571,
63,
3078,
421,
199,
318,
2198,
63,
585,
8,
83,
304,
199,
198,
2344,
7306,
1059,
370,
2018,
909,
421,
198,
12920,
26,
421,
198,
10,
9630,
1059,
4910,
626,
5226,
790,
1077,
506,
4829,
687,
314,
11083,
221,
2600,
14,
199,
198,
10,
24361,
626,
1343,
543,
282,
21357,
12,
10964,
503,
543,
2005,
4528,
626,
9174,
11083,
221,
4840,
3245,
503,
1059,
909,
787,
4565,
465,
4840,
14,
199,
198,
10,
4840,
4539,
1338,
1124,
2307,
4542,
1124,
2052,
4542,
1124,
3910,
1040,
334,
2546,
2530,
878,
9,
787,
11083,
221,
4565,
221,
465,
4840,
14,
199,
198,
10,
2900,
1163,
1338,
787,
8652,
370,
506,
3066,
3326,
14,
421,
198,
26,
635,
620,
308,
26,
2235,
939,
1059,
14,
421,
198,
26,
1107,
26,
2018,
909,
14,
199,
198,
2344,
199,
198,
692,
440,
308,
26,
507,
198,
1107,
5363,
16207,
63,
24571,
63,
3078,
199,
198,
4164,
308,
59,
16,
61,
315,
5522,
91,
59,
11371,
15668,
503,
308,
315,
661,
2307,
297,
283,
2052,
297,
283,
3910,
735,
507,
198,
1107,
2022,
14,
3640,
8,
83,
9,
199,
198,
2836,
26,
507,
198,
1107,
308,
421,
199,
318,
790,
585,
1294,
8,
83,
304,
199,
198,
2344,
8862,
1804,
17,
14,
43,
18,
29,
3204,
1901,
1804,
17,
14,
43,
18,
436,
4565,
8986,
199,
198,
2344,
199,
198,
692,
14051,
440,
315,
308,
26,
507,
198,
3730,
3146,
360,
2602,
1471,
3648,
2839,
945,
29,
1001,
63,
585,
358,
199,
198,
692,
308,
59,
16,
61,
508,
2513,
356,
507,
198,
3730,
1722,
360,
2602,
1561,
1471,
440,
1343,
543,
18494,
3985,
358,
199,
198,
2996,
275,
308,
14,
1080,
23917,
199,
198,
79,
275,
308,
1491,
2996,
61,
199,
198,
637,
275,
2198,
63,
585,
8,
83,
59,
2996,
435,
413,
5728,
199,
198,
1107,
334,
79,
12,
1139,
9,
421,
199,
318,
4565,
357,
637,
8,
83,
304,
199,
198,
2344,
4003,
1804,
17,
14,
43,
18,
29,
3204,
1901,
2420,
43,
17,
18517,
43,
18,
582,
3204,
4863,
421,
198,
1040,
3204,
1040,
365,
7686,
7182,
370,
4713,
3247,
315,
520,
647,
26,
1532,
1705,
1122,
63,
585,
2313,
199,
198,
2344,
199,
198,
692,
730,
8,
83,
9,
365,
2008,
26,
507,
198,
79,
12,
1139,
275,
308,
507,
198,
637,
275,
2198,
63,
585,
8,
637,
9,
199,
198,
2836,
26,
507,
198,
79,
12,
1139,
275,
790,
585,
1294,
8,
83,
9,
421,
198,
1612,
275,
312,
14,
1294,
7563,
199,
198,
692,
822,
8,
1612,
9,
690,
413,
26,
507,
198,
82,
275,
334,
1612,
59,
16,
467,
5009,
507,
198,
82,
895,
275,
519,
59,
17,
61,
507,
198,
509,
790,
315,
2883,
59,
17,
6809,
17,
2189,
686,
198,
82,
895,
59,
498,
61,
275,
1052,
686,
198,
82,
895,
275,
519,
895,
59,
498,
61,
507,
198,
82,
895,
59,
1612,
1988,
17,
2677,
275,
1139,
507,
198,
1107,
519,
199,
198,
2836,
26,
507,
198,
1107,
334,
79,
12,
1139,
9,
421,
199,
318,
2198,
63,
4415,
63,
1391,
8,
83,
304,
199,
198,
2344,
4003,
282,
18734,
12167,
13,
12794,
769,
402,
3326,
1901,
282,
3414,
402,
1338,
421,
198,
37,
1147,
83,
314,
2011,
2974,
315,
3414,
465,
520,
647,
26,
1532,
1705,
6751,
357,
637,
64,
1630,
14,
199,
198,
2344,
199,
198,
1107,
334,
507,
198,
6751,
357,
637,
8,
1053,
9,
507,
198,
509,
1242,
315,
308,
14,
1294,
26468,
507,
198,
692,
1242,
199,
198,
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
] |
[
6695,
26,
493,
2991,
29,
1624,
13,
24,
26,
889,
386,
199,
504,
636,
2443,
363,
492,
334,
2975,
63,
5955,
12,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
9,
199,
199,
646,
2022,
199,
199,
504,
7074,
604,
14,
773,
14,
807,
492,
5363,
16207,
63,
24571,
63,
3078,
421,
199,
318,
2198,
63,
585,
8,
83,
304,
199,
198,
2344,
7306,
1059,
370,
2018,
909,
421,
198,
12920,
26,
421,
198,
10,
9630,
1059,
4910,
626,
5226,
790,
1077,
506,
4829,
687,
314,
11083,
221,
2600,
14,
199,
198,
10,
24361,
626,
1343,
543,
282,
21357,
12,
10964,
503,
543,
2005,
4528,
626,
9174,
11083,
221,
4840,
3245,
503,
1059,
909,
787,
4565,
465,
4840,
14,
199,
198,
10,
4840,
4539,
1338,
1124,
2307,
4542,
1124,
2052,
4542,
1124,
3910,
1040,
334,
2546,
2530,
878,
9,
787,
11083,
221,
4565,
221,
465,
4840,
14,
199,
198,
10,
2900,
1163,
1338,
787,
8652,
370,
506,
3066,
3326,
14,
421,
198,
26,
635,
620,
308,
26,
2235,
939,
1059,
14,
421,
198,
26,
1107,
26,
2018,
909,
14,
199,
198,
2344,
199,
198,
692,
440,
308,
26,
507,
198,
1107,
5363,
16207,
63,
24571,
63,
3078,
199,
198,
4164,
308,
59,
16,
61,
315,
5522,
91,
59,
11371,
15668,
503,
308,
315,
661,
2307,
297,
283,
2052,
297,
283,
3910,
735,
507,
198,
1107,
2022,
14,
3640,
8,
83,
9,
199,
198,
2836,
26,
507,
198,
1107,
308,
421,
199,
318,
790,
585,
1294,
8,
83,
304,
199,
198,
2344,
8862,
1804,
17,
14,
43,
18,
29,
3204,
1901,
1804,
17,
14,
43,
18,
436,
4565,
8986,
199,
198,
2344,
199,
198,
692,
14051,
440,
315,
308,
26,
507,
198,
3730,
3146,
360,
2602,
1471,
3648,
2839,
945,
29,
1001,
63,
585,
358,
199,
198,
692,
308,
59,
16,
61,
508,
2513,
356,
507,
198,
3730,
1722,
360,
2602,
1561,
1471,
440,
1343,
543,
18494,
3985,
358,
199,
198,
2996,
275,
308,
14,
1080,
23917,
199,
198,
79,
275,
308,
1491,
2996,
61,
199,
198,
637,
275,
2198,
63,
585,
8,
83,
59,
2996,
435,
413,
5728,
199,
198,
1107,
334,
79,
12,
1139,
9,
421,
199,
318,
4565,
357,
637,
8,
83,
304,
199,
198,
2344,
4003,
1804,
17,
14,
43,
18,
29,
3204,
1901,
2420,
43,
17,
18517,
43,
18,
582,
3204,
4863,
421,
198,
1040,
3204,
1040,
365,
7686,
7182,
370,
4713,
3247,
315,
520,
647,
26,
1532,
1705,
1122,
63,
585,
2313,
199,
198,
2344,
199,
198,
692,
730,
8,
83,
9,
365,
2008,
26,
507,
198,
79,
12,
1139,
275,
308,
507,
198,
637,
275,
2198,
63,
585,
8,
637,
9,
199,
198,
2836,
26,
507,
198,
79,
12,
1139,
275,
790,
585,
1294,
8,
83,
9,
421,
198,
1612,
275,
312,
14,
1294,
7563,
199,
198,
692,
822,
8,
1612,
9,
690,
413,
26,
507,
198,
82,
275,
334,
1612,
59,
16,
467,
5009,
507,
198,
82,
895,
275,
519,
59,
17,
61,
507,
198,
509,
790,
315,
2883,
59,
17,
6809,
17,
2189,
686,
198,
82,
895,
59,
498,
61,
275,
1052,
686,
198,
82,
895,
275,
519,
895,
59,
498,
61,
507,
198,
82,
895,
59,
1612,
1988,
17,
2677,
275,
1139,
507,
198,
1107,
519,
199,
198,
2836,
26,
507,
198,
1107,
334,
79,
12,
1139,
9,
421,
199,
318,
2198,
63,
4415,
63,
1391,
8,
83,
304,
199,
198,
2344,
4003,
282,
18734,
12167,
13,
12794,
769,
402,
3326,
1901,
282,
3414,
402,
1338,
421,
198,
37,
1147,
83,
314,
2011,
2974,
315,
3414,
465,
520,
647,
26,
1532,
1705,
6751,
357,
637,
64,
1630,
14,
199,
198,
2344,
199,
198,
1107,
334,
507,
198,
6751,
357,
637,
8,
1053,
9,
507,
198,
509,
1242,
315,
308,
14,
1294,
26468,
507,
198,
692,
1242,
199,
198,
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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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
] |
lokeshjindal15/gem5_transform
|
src/mem/slicc/ast/DeclListAST.py
|
65
|
2271
|
# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
# Copyright (c) 2009 The Hewlett-Packard Development Company
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from slicc.ast.AST import AST
class DeclListAST(AST):
def __init__(self, slicc, decls):
super(DeclListAST, self).__init__(slicc)
if not isinstance(decls, (list, tuple)):
decls = [ decls ]
self.decls = decls
def __repr__(self):
return "[DeclListAST: %s]" % (', '.join(repr(d) for d in self.decls))
def files(self, parent=None):
s = set()
for decl in self.decls:
s |= decl.files(parent)
return s
def generate(self):
for decl in self.decls:
decl.generate()
def findMachines(self):
for decl in self.decls:
decl.findMachines()
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
21300,
13,
9300,
7173,
577,
14,
869,
778,
436,
20232,
437,
14,
644,
23521,
199,
3,
1898,
334,
67,
9,
8937,
710,
27849,
13,
29471,
15290,
15878,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
504,
308,
606,
67,
14,
1810,
14,
11307,
492,
20788,
199,
199,
533,
1487,
429,
1296,
11307,
8,
11307,
304,
272,
347,
636,
826,
721,
277,
12,
308,
606,
67,
12,
477,
1886,
304,
267,
1613,
8,
20856,
1296,
11307,
12,
291,
2843,
826,
721,
83,
606,
67,
9,
398,
340,
440,
1228,
8,
31335,
12,
334,
513,
12,
2008,
2298,
288,
477,
1886,
275,
359,
477,
1886,
1622,
267,
291,
14,
31335,
275,
477,
1886,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
7369,
20856,
1296,
11307,
26,
450,
83,
8480,
450,
334,
297,
1987,
904,
8,
2722,
8,
68,
9,
367,
366,
315,
291,
14,
31335,
430,
339,
347,
1584,
8,
277,
12,
1676,
29,
403,
304,
267,
308,
275,
663,
342,
267,
367,
15021,
315,
291,
14,
31335,
26,
288,
308,
8901,
15021,
14,
1725,
8,
1708,
9,
267,
372,
308,
339,
347,
3550,
8,
277,
304,
267,
367,
15021,
315,
291,
14,
31335,
26,
288,
15021,
14,
4208,
342,
339,
347,
2342,
45,
1225,
3746,
8,
277,
304,
267,
367,
15021,
315,
291,
14,
31335,
26,
288,
15021,
14,
1623,
45,
1225,
3746,
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
] |
[
1898,
334,
67,
9,
21300,
13,
9300,
7173,
577,
14,
869,
778,
436,
20232,
437,
14,
644,
23521,
199,
3,
1898,
334,
67,
9,
8937,
710,
27849,
13,
29471,
15290,
15878,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
504,
308,
606,
67,
14,
1810,
14,
11307,
492,
20788,
199,
199,
533,
1487,
429,
1296,
11307,
8,
11307,
304,
272,
347,
636,
826,
721,
277,
12,
308,
606,
67,
12,
477,
1886,
304,
267,
1613,
8,
20856,
1296,
11307,
12,
291,
2843,
826,
721,
83,
606,
67,
9,
398,
340,
440,
1228,
8,
31335,
12,
334,
513,
12,
2008,
2298,
288,
477,
1886,
275,
359,
477,
1886,
1622,
267,
291,
14,
31335,
275,
477,
1886,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
7369,
20856,
1296,
11307,
26,
450,
83,
8480,
450,
334,
297,
1987,
904,
8,
2722,
8,
68,
9,
367,
366,
315,
291,
14,
31335,
430,
339,
347,
1584,
8,
277,
12,
1676,
29,
403,
304,
267,
308,
275,
663,
342,
267,
367,
15021,
315,
291,
14,
31335,
26,
288,
308,
8901,
15021,
14,
1725,
8,
1708,
9,
267,
372,
308,
339,
347,
3550,
8,
277,
304,
267,
367,
15021,
315,
291,
14,
31335,
26,
288,
15021,
14,
4208,
342,
339,
347,
2342,
45,
1225,
3746,
8,
277,
304,
267,
367,
15021,
315,
291,
14,
31335,
26,
288,
15021,
14,
1623,
45,
1225,
3746,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
synth3tk/the-blue-alliance
|
tests/test_notification_base.py
|
7
|
1200
|
import unittest2
import json
from google.appengine.ext import ndb
from google.appengine.ext import testbed
from consts.client_type import ClientType
from consts.notification_type import NotificationType
from notifications.ping import PingNotification
class TestBaseNotification(unittest2.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
# User a Ping notification to test the render and send classes
# It's as simple as it gets
self.notification = PingNotification()
self.keys = { ClientType.OS_ANDROID: ["abc123"], ClientType.WEBHOOK: ["123abc"] }
self.notification.keys = self.keys
def tearDown(self):
self.testbed.deactivate()
def test_render_android(self):
message = self.notification._render_android()
self.assertEqual(self.keys[ClientType.OS_ANDROID], message.device_tokens)
self.assertEqual(self.notification._build_dict(), message.notification)
def test_render_webhook(self):
message = self.notification._render_webhook()
self.assertEqual(message, self.notification._build_dict())
def test_render_ios(self):
pass
|
mit
|
[
646,
2882,
18,
199,
646,
2022,
199,
199,
504,
6233,
14,
15358,
14,
832,
492,
23788,
199,
504,
6233,
14,
15358,
14,
832,
492,
511,
6123,
199,
199,
504,
950,
83,
14,
1258,
63,
466,
492,
6810,
804,
199,
504,
950,
83,
14,
6761,
63,
466,
492,
23362,
804,
199,
504,
13116,
14,
4073,
492,
510,
316,
11598,
421,
199,
533,
1379,
1563,
11598,
8,
2796,
18,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
396,
6123,
275,
511,
6123,
14,
774,
6123,
342,
267,
291,
14,
396,
6123,
14,
8222,
342,
398,
327,
2876,
282,
510,
316,
6955,
370,
511,
314,
3795,
436,
3222,
3992,
267,
327,
2779,
1159,
465,
3486,
465,
652,
7545,
267,
291,
14,
6761,
275,
510,
316,
11598,
342,
267,
291,
14,
1612,
275,
469,
6810,
804,
14,
3100,
63,
25658,
26,
2097,
3175,
4288,
2255,
6810,
804,
14,
13166,
28706,
26,
2097,
4288,
3175,
937,
789,
267,
291,
14,
6761,
14,
1612,
275,
291,
14,
1612,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
396,
6123,
14,
24891,
342,
339,
347,
511,
63,
3352,
63,
6238,
8,
277,
304,
267,
1245,
275,
291,
14,
6761,
423,
3352,
63,
6238,
342,
398,
291,
14,
629,
8,
277,
14,
1612,
59,
3041,
804,
14,
3100,
63,
25658,
467,
1245,
14,
1782,
63,
4504,
9,
267,
291,
14,
629,
8,
277,
14,
6761,
423,
1506,
63,
807,
1062,
1245,
14,
6761,
9,
339,
347,
511,
63,
3352,
63,
22944,
8,
277,
304,
267,
1245,
275,
291,
14,
6761,
423,
3352,
63,
22944,
342,
398,
291,
14,
629,
8,
1188,
12,
291,
14,
6761,
423,
1506,
63,
807,
1012,
339,
347,
511,
63,
3352,
63,
9207,
8,
277,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
18,
199,
646,
2022,
199,
199,
504,
6233,
14,
15358,
14,
832,
492,
23788,
199,
504,
6233,
14,
15358,
14,
832,
492,
511,
6123,
199,
199,
504,
950,
83,
14,
1258,
63,
466,
492,
6810,
804,
199,
504,
950,
83,
14,
6761,
63,
466,
492,
23362,
804,
199,
504,
13116,
14,
4073,
492,
510,
316,
11598,
421,
199,
533,
1379,
1563,
11598,
8,
2796,
18,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
396,
6123,
275,
511,
6123,
14,
774,
6123,
342,
267,
291,
14,
396,
6123,
14,
8222,
342,
398,
327,
2876,
282,
510,
316,
6955,
370,
511,
314,
3795,
436,
3222,
3992,
267,
327,
2779,
1159,
465,
3486,
465,
652,
7545,
267,
291,
14,
6761,
275,
510,
316,
11598,
342,
267,
291,
14,
1612,
275,
469,
6810,
804,
14,
3100,
63,
25658,
26,
2097,
3175,
4288,
2255,
6810,
804,
14,
13166,
28706,
26,
2097,
4288,
3175,
937,
789,
267,
291,
14,
6761,
14,
1612,
275,
291,
14,
1612,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
396,
6123,
14,
24891,
342,
339,
347,
511,
63,
3352,
63,
6238,
8,
277,
304,
267,
1245,
275,
291,
14,
6761,
423,
3352,
63,
6238,
342,
398,
291,
14,
629,
8,
277,
14,
1612,
59,
3041,
804,
14,
3100,
63,
25658,
467,
1245,
14,
1782,
63,
4504,
9,
267,
291,
14,
629,
8,
277,
14,
6761,
423,
1506,
63,
807,
1062,
1245,
14,
6761,
9,
339,
347,
511,
63,
3352,
63,
22944,
8,
277,
304,
267,
1245,
275,
291,
14,
6761,
423,
3352,
63,
22944,
342,
398,
291,
14,
629,
8,
1188,
12,
291,
14,
6761,
423,
1506,
63,
807,
1012,
339,
347,
511,
63,
3352,
63,
9207,
8,
277,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
rsalmaso/scripts
|
scripts/cdblank.py
|
1
|
5608
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 1999-2015, Raffaele Salmaso <raffaele@salmaso.org>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from __future__ import absolute_import, division, print_function, unicode_literals
import os
import os.path
import sys
import getopt
shortopts = 'hfad:s:eql'
longopts = [ 'help', 'fast', 'all', 'device=', 'speed=', 'eject', 'quiet', 'list', 'dummy' ]
class App:
def __init__(self, cmdline, blank, device, speed, verify, eject, quiet, dummy, list):
self._cmdline = cmdline
self._blank = blank
self._device = device
self._speed = speed
self._eject = eject
self._quiet = quiet
self._dummy = dummy
self._list = list
def __call__(self):
return ' '.join([self._cmdline, self._blank, self._device, self._speed, self._eject, self._quiet, self._dummy, self._list])
class HdiUtil(App):
def __init__(self):
App.__init__(
self,
cmdline = 'hdiutil burn',
blank = '-erase',
device = '',
speed = '',
verify = '-noverifyburn',
eject = '-noeject',
quiet = '-verbose',
dummy = '',
list = ''
)
def device(self, device):
self._device = '-device %s' % device
def speed(self, speed):
self._speed = '-speed %s' % speed
def blank(self, t):
if t == 'fast':
self._blank = '-erase'
else:
self._blank = '-fullerase'
def eject(self):
self._eject = '-eject'
def quiet(self):
self._quiet = '-quiet'
def dummy(self):
self._dummy = '-testburn'
def list(self):
''' hdiutil -list must be the only option '''
self._device = ''
self._speed = ''
self._blank = ''
self._eject = ''
self._quiet = ''
self._dummy = ''
self._list = '-list'
class Cdrecord(App):
def __init__(self):
App.__init__(
self,
cmdline = 'cdrecord immed',
blank = '-erase',
device = 'dev=/dev/cdrom',
speed = '',
verify = '',
eject = '',
quiet = '-v',
dummy = '',
list = ''
)
def device(self, device):
self._device = 'dev=%s' % device
def speed(self, speed):
self._speed = 'speed=%s' % speed
def blank(self, t):
if t == 'fast':
self._blank = 'blank=fast'
else:
self._blank = 'blank=disk'
def eject(self):
self._eject = '-eject'
def quiet(self):
self._quiet = ''
def dummy(self):
self._dummy = '-dummy'
def list(self):
self._device = ''
self._speed = ''
self._blank = ''
self._eject = ''
self._quiet = ''
self._dummy = ''
self._list = '-scanbus'
if os.uname()[0] == 'Darwin':
exe = HdiUtil()
else:
exe = Cdrecord()
def usage():
pkgname = os.path.basename(sys.argv[0])
print('''%s (C) 1999-2015, Raffaele Salmaso
This program is distributed under the MIT/X License
You are not allowed to remove the copyright notice
This program allows to blank a cd/dvd from commandline. It
supports MacOsX hdiutil and the ubiquitous cdrecord.
usage: %s [option]
options:
-h, --help = show this help
-f, --fast = erase only TOC [default]
-a, --all = completely erase all disk
-d, --device [default]
-s, --speed <1, 2, 4, 8, max [default]>
-e, --eject = eject disk after burning [default=no]
-q, --quiet = no progress output will be provided
-l, --list = list all burning devices, for --device
--dummy = don't turn on laser
''' % (pkgname, pkgname))
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
except getopt.GetoptError:
usage()
sys.exit(-1)
for o, a in opts:
if o in ('-a', '--all'):
exe.blank('full')
elif o in ('-f', '--fast'):
exe.blank('fast')
elif o in ('-d', '--device'):
exe.device(a)
elif o in ('-s', '--speed'):
exe.speed()
elif o in ('-q', '--quiet'):
exe.quiet()
elif o in ('-e', '--eject'):
exe.eject()
elif o in ('-l', '--list'):
exe.list()
elif o == '--dummy':
exe.dummy()
elif o in ('-h', '--help'):
usage()
sys.exit(0)
os.system(exe())
if __name__ == "__main__":
main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
35,
9,
21300,
13,
7806,
12,
3898,
556,
3624,
274,
428,
279,
5892,
79,
665,
345,
556,
3624,
274,
32,
6327,
5892,
79,
14,
1308,
30,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
221,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
3,
2334,
4141,
14,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
984,
199,
646,
12733,
199,
199,
3612,
3291,
275,
283,
9188,
350,
26,
83,
26,
69,
1710,
7,
199,
2809,
3291,
275,
359,
283,
3437,
297,
283,
7015,
297,
283,
452,
297,
283,
1782,
4009,
283,
7625,
4009,
283,
69,
963,
297,
283,
10243,
297,
283,
513,
297,
283,
5869,
7,
1622,
199,
199,
533,
4693,
26,
272,
347,
636,
826,
721,
277,
12,
21206,
12,
4596,
12,
2243,
12,
8112,
12,
4911,
12,
325,
963,
12,
11971,
12,
7283,
12,
769,
304,
267,
291,
423,
15612,
275,
21206,
267,
291,
423,
2500,
275,
4596,
267,
291,
423,
1782,
275,
2243,
267,
291,
423,
7625,
275,
8112,
267,
291,
423,
69,
963,
275,
325,
963,
267,
291,
423,
10243,
275,
11971,
267,
291,
423,
5869,
275,
7283,
267,
291,
423,
513,
275,
769,
272,
347,
636,
1250,
721,
277,
304,
267,
372,
283,
1987,
904,
779,
277,
423,
15612,
12,
291,
423,
2500,
12,
291,
423,
1782,
12,
291,
423,
7625,
12,
291,
423,
69,
963,
12,
291,
423,
10243,
12,
291,
423,
5869,
12,
291,
423,
513,
566,
199,
199,
533,
869,
328,
9562,
8,
2640,
304,
272,
347,
636,
826,
721,
277,
304,
267,
4693,
855,
826,
721,
288,
291,
12,
288,
21206,
275,
283,
72,
328,
1974,
330,
349,
297,
288,
4596,
275,
2475,
22087,
297,
288,
2243,
275,
3260,
288,
8112,
275,
3260,
288,
4911,
275,
2475,
889,
4712,
30736,
297,
288,
325,
963,
275,
2475,
889,
69,
963,
297,
288,
11971,
275,
2475,
3832,
297,
288,
7283,
275,
3260,
288,
769,
275,
2125,
267,
776,
272,
347,
2243,
8,
277,
12,
2243,
304,
267,
291,
423,
1782,
275,
2475,
1782,
450,
83,
7,
450,
2243,
272,
347,
8112,
8,
277,
12,
8112,
304,
267,
291,
423,
7625,
275,
2475,
7625,
450,
83,
7,
450,
8112,
272,
347,
4596,
8,
277,
12,
307,
304,
267,
340,
307,
508,
283,
7015,
356,
288,
291,
423,
2500,
275,
2475,
22087,
7,
267,
587,
26,
288,
291,
423,
2500,
275,
2475,
1893,
274,
8062,
7,
272,
347,
325,
963,
8,
277,
304,
267,
291,
423,
69,
963,
275,
2475,
69,
963,
7,
272,
347,
11971,
8,
277,
304,
267,
291,
423,
10243,
275,
2475,
10243,
7,
272,
347,
7283,
8,
277,
304,
267,
291,
423,
5869,
275,
2475,
396,
30736,
7,
272,
347,
769,
8,
277,
304,
267,
1449,
394,
328,
1974,
446,
513,
1471,
506,
314,
1454,
945,
1449,
267,
291,
423,
1782,
275,
2125,
267,
291,
423,
7625,
275,
2125,
267,
291,
423,
2500,
275,
2125,
267,
291,
423,
69,
963,
275,
2125,
267,
291,
423,
10243,
275,
2125,
267,
291,
423,
5869,
275,
2125,
267,
291,
423,
513,
275,
2475,
513,
7,
199,
199,
533,
445,
68,
3059,
8,
2640,
304,
272,
347,
636,
826,
721,
277,
304,
267,
4693,
855,
826,
721,
288,
291,
12,
288,
21206,
275,
283,
2866,
3059,
3416,
3594,
297,
288,
4596,
275,
2475,
22087,
297,
288,
2243,
275,
283,
2374,
13043,
2374,
15,
2866,
417,
297,
288,
8112,
275,
3260,
288,
4911,
275,
3260,
288,
325,
963,
275,
3260,
288,
11971,
275,
2475,
86,
297,
288,
7283,
275,
3260,
288,
769,
275,
2125,
267,
776,
272,
347,
2243,
8,
277,
12,
2243,
304,
267,
291,
423,
1782,
275,
283,
2374,
2458,
83,
7,
450,
2243,
272,
347,
8112,
8,
277,
12,
8112,
304,
267,
291,
423,
7625,
275,
283,
7625,
2458,
83,
7,
450,
8112,
272,
347,
4596,
8,
277,
12,
307,
304,
267,
340,
307,
508,
283,
7015,
356,
288,
291,
423,
2500,
275,
283,
2500,
29,
7015,
7,
267,
587,
26,
288,
291,
423,
2500,
275,
283,
2500,
29,
4032,
7,
272,
347,
325,
963,
8,
277,
304,
267,
291,
423,
69,
963,
275,
2475,
69,
963,
7,
272,
347,
11971,
8,
277,
304,
267,
291,
423,
10243,
275,
2125,
272,
347,
7283,
8,
277,
304,
267,
291,
423,
5869,
275,
2475,
5869,
7,
272,
347,
769,
8,
277,
304,
267,
291,
423,
1782,
275,
2125,
267,
291,
423,
7625,
275,
2125,
267,
291,
423,
2500,
275,
2125,
267,
291,
423,
69,
963,
275,
2125,
267,
291,
423,
10243,
275,
2125,
267,
291,
423,
5869,
275,
2125,
267,
291,
423,
513,
275,
2475,
6282,
5610,
7,
199,
199,
692,
747,
14,
16040,
3430,
16,
61,
508,
283,
31065,
356,
272,
14778,
275,
869,
328,
9562
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
35,
9,
21300,
13,
7806,
12,
3898,
556,
3624,
274,
428,
279,
5892,
79,
665,
345,
556,
3624,
274,
32,
6327,
5892,
79,
14,
1308,
30,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
221,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
3,
2334,
4141,
14,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
984,
199,
646,
12733,
199,
199,
3612,
3291,
275,
283,
9188,
350,
26,
83,
26,
69,
1710,
7,
199,
2809,
3291,
275,
359,
283,
3437,
297,
283,
7015,
297,
283,
452,
297,
283,
1782,
4009,
283,
7625,
4009,
283,
69,
963,
297,
283,
10243,
297,
283,
513,
297,
283,
5869,
7,
1622,
199,
199,
533,
4693,
26,
272,
347,
636,
826,
721,
277,
12,
21206,
12,
4596,
12,
2243,
12,
8112,
12,
4911,
12,
325,
963,
12,
11971,
12,
7283,
12,
769,
304,
267,
291,
423,
15612,
275,
21206,
267,
291,
423,
2500,
275,
4596,
267,
291,
423,
1782,
275,
2243,
267,
291,
423,
7625,
275,
8112,
267,
291,
423,
69,
963,
275,
325,
963,
267,
291,
423,
10243,
275,
11971,
267,
291,
423,
5869,
275,
7283,
267,
291,
423,
513,
275,
769,
272,
347,
636,
1250,
721,
277,
304,
267,
372,
283,
1987,
904,
779,
277,
423,
15612,
12,
291,
423,
2500,
12,
291,
423,
1782,
12,
291,
423,
7625,
12,
291,
423,
69,
963,
12,
291,
423,
10243,
12,
291,
423,
5869,
12,
291,
423,
513,
566,
199,
199,
533,
869,
328,
9562,
8,
2640,
304,
272,
347,
636,
826,
721,
277,
304,
267,
4693,
855,
826,
721,
288,
291,
12,
288,
21206,
275,
283,
72,
328,
1974,
330,
349,
297,
288,
4596,
275,
2475,
22087,
297,
288,
2243,
275,
3260,
288,
8112,
275,
3260,
288,
4911,
275,
2475,
889,
4712,
30736,
297,
288,
325,
963,
275,
2475,
889,
69,
963,
297,
288,
11971,
275,
2475,
3832,
297,
288,
7283,
275,
3260,
288,
769,
275,
2125,
267,
776,
272,
347,
2243,
8,
277,
12,
2243,
304,
267,
291,
423,
1782,
275,
2475,
1782,
450,
83,
7,
450,
2243,
272,
347,
8112,
8,
277,
12,
8112,
304,
267,
291,
423,
7625,
275,
2475,
7625,
450,
83,
7,
450,
8112,
272,
347,
4596,
8,
277,
12,
307,
304,
267,
340,
307,
508,
283,
7015,
356,
288,
291,
423,
2500,
275,
2475,
22087,
7,
267,
587,
26,
288,
291,
423,
2500,
275,
2475,
1893,
274,
8062,
7,
272,
347,
325,
963,
8,
277,
304,
267,
291,
423,
69,
963,
275,
2475,
69,
963,
7,
272,
347,
11971,
8,
277,
304,
267,
291,
423,
10243,
275,
2475,
10243,
7,
272,
347,
7283,
8,
277,
304,
267,
291,
423,
5869,
275,
2475,
396,
30736,
7,
272,
347,
769,
8,
277,
304,
267,
1449,
394,
328,
1974,
446,
513,
1471,
506,
314,
1454,
945,
1449,
267,
291,
423,
1782,
275,
2125,
267,
291,
423,
7625,
275,
2125,
267,
291,
423,
2500,
275,
2125,
267,
291,
423,
69,
963,
275,
2125,
267,
291,
423,
10243,
275,
2125,
267,
291,
423,
5869,
275,
2125,
267,
291,
423,
513,
275,
2475,
513,
7,
199,
199,
533,
445,
68,
3059,
8,
2640,
304,
272,
347,
636,
826,
721,
277,
304,
267,
4693,
855,
826,
721,
288,
291,
12,
288,
21206,
275,
283,
2866,
3059,
3416,
3594,
297,
288,
4596,
275,
2475,
22087,
297,
288,
2243,
275,
283,
2374,
13043,
2374,
15,
2866,
417,
297,
288,
8112,
275,
3260,
288,
4911,
275,
3260,
288,
325,
963,
275,
3260,
288,
11971,
275,
2475,
86,
297,
288,
7283,
275,
3260,
288,
769,
275,
2125,
267,
776,
272,
347,
2243,
8,
277,
12,
2243,
304,
267,
291,
423,
1782,
275,
283,
2374,
2458,
83,
7,
450,
2243,
272,
347,
8112,
8,
277,
12,
8112,
304,
267,
291,
423,
7625,
275,
283,
7625,
2458,
83,
7,
450,
8112,
272,
347,
4596,
8,
277,
12,
307,
304,
267,
340,
307,
508,
283,
7015,
356,
288,
291,
423,
2500,
275,
283,
2500,
29,
7015,
7,
267,
587,
26,
288,
291,
423,
2500,
275,
283,
2500,
29,
4032,
7,
272,
347,
325,
963,
8,
277,
304,
267,
291,
423,
69,
963,
275,
2475,
69,
963,
7,
272,
347,
11971,
8,
277,
304,
267,
291,
423,
10243,
275,
2125,
272,
347,
7283,
8,
277,
304,
267,
291,
423,
5869,
275,
2475,
5869,
7,
272,
347,
769,
8,
277,
304,
267,
291,
423,
1782,
275,
2125,
267,
291,
423,
7625,
275,
2125,
267,
291,
423,
2500,
275,
2125,
267,
291,
423,
69,
963,
275,
2125,
267,
291,
423,
10243,
275,
2125,
267,
291,
423,
5869,
275,
2125,
267,
291,
423,
513,
275,
2475,
6282,
5610,
7,
199,
199,
692,
747,
14,
16040,
3430,
16,
61,
508,
283,
31065,
356,
272,
14778,
275,
869,
328,
9562,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
SUNET/eduid-common
|
src/eduid_common/api/request.py
|
1
|
9772
|
#
# Copyright (c) 2018 NORDUnet A/S
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# 3. Neither the name of the NORDUnet nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
"""
This module provides a Request class that extends flask.Request
and adds sanitation to user inputs. This sanitation is performed
on the access methods of the data structures that the request uses to
hold data inputs by the user.
For more information on these structures, see werkzeug.datastructures.
To use this request, assign it to the `request_class` attribute
of the Flask application::
>>> from eduid_common.api.request import Request
>>> from flask import Flask
>>> app = Flask('name')
>>> app.request_class = Request
"""
from flask import Request as BaseRequest
from flask import abort, current_app
from werkzeug._compat import iteritems, itervalues
from werkzeug.datastructures import EnvironHeaders, ImmutableMultiDict, ImmutableTypeConversionDict
from werkzeug.utils import cached_property
from eduid_common.api.sanitation import SanitationProblem, Sanitizer
class SanitationMixin(Sanitizer):
"""
Mixin for werkzeug datastructures providing methods to
sanitize user inputs.
"""
def sanitize_input(self, untrusted_text, strip_characters=False):
logger = current_app.logger
try:
return super(SanitationMixin, self).sanitize_input(
untrusted_text, logger, strip_characters=strip_characters
)
except SanitationProblem:
abort(400)
class SanitizedImmutableMultiDict(ImmutableMultiDict, SanitationMixin): # type: ignore
"""
See `werkzeug.datastructures.ImmutableMultiDict`.
This class is an extension that overrides all access methods to
sanitize the extracted data.
"""
def __getitem__(self, key):
"""
Return the first data value for this key;
raises KeyError if not found.
:param key: The key to be looked up.
:raise KeyError: if the key does not exist.
"""
value = super(SanitizedImmutableMultiDict, self).__getitem__(key)
return self.sanitize_input(value)
def getlist(self, key, type=None):
"""
Return the list of items for a given key. If that key is not in the
`MultiDict`, the return value will be an empty list. Just as `get`
`getlist` accepts a `type` parameter. All items will be converted
with the callable defined there.
:param key: The key to be looked up.
:param type: A callable that is used to cast the value in the
:class:`MultiDict`. If a :exc:`ValueError` is raised
by this callable the value will be removed from the list.
:return: a :class:`list` of all the values for the key.
"""
value_list = super(SanitizedImmutableMultiDict, self).getlist(key, type=type)
return [self.sanitize_input(v) for v in value_list]
def items(self, multi=False):
"""
Return an iterator of ``(key, value)`` pairs.
:param multi: If set to `True` the iterator returned will have a pair
for each value of each key. Otherwise it will only
contain pairs for the first value of each key.
"""
for key, values in iteritems(dict, self):
values = [self.sanitize_input(v) for v in values]
if multi:
for value in values:
yield key, value
else:
yield key, values[0]
def lists(self):
"""Return a list of ``(key, values)`` pairs, where values is the list
of all values associated with the key."""
for key, values in iteritems(dict, self):
values = [self.sanitize_input(v) for v in values]
yield key, values
def values(self):
"""
Returns an iterator of the first value on every key's value list.
"""
for values in itervalues(dict, self):
yield self.sanitize_input(values[0])
def listvalues(self):
"""
Return an iterator of all values associated with a key. Zipping
:meth:`keys` and this is the same as calling :meth:`lists`:
>>> d = MultiDict({"foo": [1, 2, 3]})
>>> zip(d.keys(), d.listvalues()) == d.lists()
True
"""
for values in itervalues(dict, self):
yield (self.sanitize_input(v) for v in values)
def to_dict(self, flat=True):
"""Return the contents as regular dict. If `flat` is `True` the
returned dict will only have the first item present, if `flat` is
`False` all values will be returned as lists.
:param flat: If set to `False` the dict returned will have lists
with all the values in it. Otherwise it will only
contain the first value for each key.
:return: a :class:`dict`
"""
if flat:
d = {}
for k, v in iteritems(self):
v = self.sanitize_input(v)
d[k] = v
return d
return dict(self.lists())
class SanitizedTypeConversionDict(ImmutableTypeConversionDict, SanitationMixin): # type: ignore
"""
See `werkzeug.datastructures.TypeConversionDict`.
This class is an extension that overrides all access methods to
sanitize the extracted data.
"""
def __getitem__(self, key):
"""
Sanitized __getitem__
"""
val = ImmutableTypeConversionDict.__getitem__(self, key)
return self.sanitize_input(val)
def get(self, key, default=None, type=None):
"""
Sanitized, type conversion get.
The value identified by `key` is sanitized, and if `type`
is provided, the value is cast to it.
:param key: the key for the value
:type key: str
:para default: the default if `key` is absent
:type default: str
:param type: The type to cast the value
:type type: type
:rtype: object
"""
try:
val = self.sanitize_input(self[key])
if type is not None:
val = type(val)
except (KeyError, ValueError):
val = default
return val
def values(self):
"""
sanitized values
"""
return [self.sanitize_input(v) for v in ImmutableTypeConversionDict.values(self)]
def items(self):
"""
Sanitized items
"""
return [(v[0], self.sanitize_input(v[1])) for v in ImmutableTypeConversionDict.items(self)]
def pop(self, key):
"""
Sanitized pop
:param key: the key for the value
:type key: str
"""
val = ImmutableTypeConversionDict.pop(key)
return self.sanitize_input(val)
class SanitizedEnvironHeaders(EnvironHeaders, SanitationMixin):
"""
Sanitized and read only version of the headersfrom a WSGI environment.
"""
def __getitem__(self, key, _get_mode=False):
"""
Sanitized __getitem__
:param key: the key for the value
:type key: str
:param _get_mode: is a no-op for this class as there is no index but
used because get() calls it.
:type _get_mode: bool
"""
val = EnvironHeaders.__getitem__(self, key, _get_mode=_get_mode)
return self.sanitize_input(val)
def __iter__(self):
"""
Sanitized __iter__
"""
for val in EnvironHeaders.__iter__(self):
yield self.sanitize_input(val)
class Request(BaseRequest, SanitationMixin):
"""
Request objects with sanitized inputs
"""
parameter_storage_class = SanitizedImmutableMultiDict
dict_storage_class = SanitizedTypeConversionDict
@cached_property
def headers(self):
"""
The headers from the WSGI environ as immutable and sanitized
:class:`~eduid_common.api.request.SanitizedEnvironHeaders`.
"""
return SanitizedEnvironHeaders(self.environ)
def get_data(self, *args, **kwargs):
text = super(Request, self).get_data(*args, **kwargs)
if text:
text = self.sanitize_input(text)
if text is None:
text = ''
return text
|
bsd-3-clause
|
[
3,
199,
3,
1898,
334,
67,
9,
14894,
653,
3731,
53,
846,
437,
15,
51,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
257,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
199,
3,
257,
1928,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
199,
3,
257,
3704,
787,
7647,
26,
199,
3,
199,
3,
258,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
263,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
263,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
199,
3,
263,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
199,
3,
263,
543,
314,
4084,
14,
199,
3,
258,
650,
14,
11443,
314,
536,
402,
314,
653,
3731,
53,
846,
6590,
314,
1561,
402,
2399,
199,
3,
263,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
199,
3,
263,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
199,
3,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
199,
3,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
624,
199,
2765,
859,
6571,
282,
4784,
1021,
626,
16879,
7209,
14,
2017,
199,
460,
9584,
28698,
5314,
370,
922,
4153,
14,
961,
28698,
5314,
365,
10585,
199,
265,
314,
2879,
3102,
402,
314,
666,
13955,
626,
314,
1056,
4440,
370,
199,
12239,
666,
4153,
701,
314,
922,
14,
199,
1858,
1655,
2556,
641,
3520,
13955,
12,
1937,
10380,
14,
23004,
14,
199,
199,
1378,
675,
642,
1056,
12,
5090,
652,
370,
314,
658,
1069,
63,
533,
64,
2225,
199,
1618,
314,
16704,
4223,
447,
339,
1306,
687,
3988,
1535,
63,
2330,
14,
1246,
14,
1069,
492,
4784,
272,
1306,
687,
7209,
492,
16704,
272,
1306,
1145,
275,
16704,
360,
354,
358,
272,
1306,
1145,
14,
1069,
63,
533,
275,
221,
4784,
199,
624,
199,
199,
504,
7209,
492,
4784,
465,
3523,
2017,
199,
504,
7209,
492,
12004,
12,
1453,
63,
571,
199,
504,
10380,
423,
5819,
492,
10849,
12,
24451,
199,
504,
10380,
14,
23004,
492,
3447,
1489,
9883,
12,
25609,
21365,
12,
25609,
804,
20403,
2141,
199,
504,
10380,
14,
1208,
492,
6328,
63,
1829,
199,
199,
504,
3988,
1535,
63,
2330,
14,
1246,
14,
18904,
5314,
492,
29359,
5314,
16467,
12,
428,
9385,
2282,
421,
199,
533,
29359,
5314,
4256,
8,
51,
9385,
2282,
304,
272,
408,
272,
28438,
367,
10380,
666,
13547,
13070,
3102,
370,
272,
21077,
922,
4153,
14,
272,
408,
339,
347,
21077,
63,
1210,
8,
277,
12,
625,
17549,
63,
505,
12,
6202,
63,
16516,
29,
797,
304,
267,
2512,
275,
1453,
63,
571,
14,
2921,
267,
862,
26,
288,
372,
1613,
8,
23906,
5314,
4256,
12,
291,
680,
18177,
63,
1210,
8,
355,
625,
17549,
63,
505,
12,
2512,
12,
6202,
63,
16516,
29,
1913,
63,
16516,
288,
776,
267,
871,
29359,
5314,
16467,
26,
288,
12004,
8,
5303,
9,
421,
199,
533,
428,
9385,
7068,
29174,
21365,
8,
29174,
21365,
12,
29359,
5314,
4256,
304,
221,
327,
730,
26,
3686,
272,
408,
272,
1666,
658,
17719,
14,
23004,
14,
29174,
21365,
2313,
272,
961,
1021,
365,
376,
3329,
626,
10580,
1006,
2879,
3102,
370,
272,
21077,
314,
12509,
666,
14,
272,
408,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
408,
267,
1432,
314,
1642,
666,
574,
367,
642,
790,
27,
267,
6534,
4067,
340,
440,
1911,
14,
398,
520,
635,
790,
26,
710,
790,
370,
506,
21182,
1536,
14,
267,
520,
3730,
4067,
26,
340,
314,
790,
1630,
440,
2187,
14,
267,
408,
267,
574,
275,
1613,
8,
51,
9385,
7068,
29174,
21365,
12,
291,
2843,
6095,
721,
498,
9,
267,
372,
291,
14,
18177,
63,
1210,
8,
585,
9,
339,
347,
664,
513,
8,
277,
12,
790,
12,
730,
29,
403,
304,
267,
408,
267,
1432,
314,
769,
402,
2974,
367,
282,
1627,
790,
14,
982,
626,
790,
365,
440,
315,
314,
267,
658,
21365,
3559,
314,
372,
574,
911,
506,
376,
2701,
769,
14,
221,
13870,
465,
658,
362,
64,
267,
658,
21343,
64,
11479,
282,
658,
466,
64,
2725,
14,
221,
2900,
2974,
911,
506,
6702,
267,
543,
314,
4550,
3247,
2337,
14,
398,
520,
635,
790,
26,
710,
790,
370,
506,
21182,
1536,
14,
267,
520,
635,
730,
26,
437,
4550,
626,
365,
1202,
370,
9106,
314,
574,
315,
314,
2151,
520,
533,
1705,
21365,
2313,
221,
982,
282,
520,
2804,
1705,
3393,
64,
365,
4915,
2151,
701,
642,
4550,
314,
574,
911,
506,
4829,
687,
314,
769,
14,
267,
520,
1107,
26,
282,
520,
533,
1705,
513,
64,
402,
1006,
314,
1338,
367,
314,
790,
14,
267,
408,
267,
574,
63,
513,
275,
1613,
8,
51,
9385,
7068,
29174,
21365,
12,
291,
680,
21343,
8,
498,
12,
730,
29,
466,
9,
267,
372,
359,
277,
14,
18177,
63,
1210,
8,
86,
9,
367,
373,
315,
574,
63,
513,
61,
339,
347,
2974,
8,
277,
12,
3510,
29,
797,
304,
267,
408,
267,
1432,
376,
6122,
402,
15475,
498,
12,
574,
9719,
6342,
14,
398,
520,
635,
3510,
26,
982,
663,
370,
658,
549,
64,
314,
6122,
2138,
911,
1172,
282,
4092,
1993,
367,
1924,
574,
402,
1924,
790,
14,
221
] |
[
199,
3,
1898,
334,
67,
9,
14894,
653,
3731,
53,
846,
437,
15,
51,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
257,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
199,
3,
257,
1928,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
199,
3,
257,
3704,
787,
7647,
26,
199,
3,
199,
3,
258,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
263,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
263,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
199,
3,
263,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
199,
3,
263,
543,
314,
4084,
14,
199,
3,
258,
650,
14,
11443,
314,
536,
402,
314,
653,
3731,
53,
846,
6590,
314,
1561,
402,
2399,
199,
3,
263,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
199,
3,
263,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
199,
3,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
199,
3,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
624,
199,
2765,
859,
6571,
282,
4784,
1021,
626,
16879,
7209,
14,
2017,
199,
460,
9584,
28698,
5314,
370,
922,
4153,
14,
961,
28698,
5314,
365,
10585,
199,
265,
314,
2879,
3102,
402,
314,
666,
13955,
626,
314,
1056,
4440,
370,
199,
12239,
666,
4153,
701,
314,
922,
14,
199,
1858,
1655,
2556,
641,
3520,
13955,
12,
1937,
10380,
14,
23004,
14,
199,
199,
1378,
675,
642,
1056,
12,
5090,
652,
370,
314,
658,
1069,
63,
533,
64,
2225,
199,
1618,
314,
16704,
4223,
447,
339,
1306,
687,
3988,
1535,
63,
2330,
14,
1246,
14,
1069,
492,
4784,
272,
1306,
687,
7209,
492,
16704,
272,
1306,
1145,
275,
16704,
360,
354,
358,
272,
1306,
1145,
14,
1069,
63,
533,
275,
221,
4784,
199,
624,
199,
199,
504,
7209,
492,
4784,
465,
3523,
2017,
199,
504,
7209,
492,
12004,
12,
1453,
63,
571,
199,
504,
10380,
423,
5819,
492,
10849,
12,
24451,
199,
504,
10380,
14,
23004,
492,
3447,
1489,
9883,
12,
25609,
21365,
12,
25609,
804,
20403,
2141,
199,
504,
10380,
14,
1208,
492,
6328,
63,
1829,
199,
199,
504,
3988,
1535,
63,
2330,
14,
1246,
14,
18904,
5314,
492,
29359,
5314,
16467,
12,
428,
9385,
2282,
421,
199,
533,
29359,
5314,
4256,
8,
51,
9385,
2282,
304,
272,
408,
272,
28438,
367,
10380,
666,
13547,
13070,
3102,
370,
272,
21077,
922,
4153,
14,
272,
408,
339,
347,
21077,
63,
1210,
8,
277,
12,
625,
17549,
63,
505,
12,
6202,
63,
16516,
29,
797,
304,
267,
2512,
275,
1453,
63,
571,
14,
2921,
267,
862,
26,
288,
372,
1613,
8,
23906,
5314,
4256,
12,
291,
680,
18177,
63,
1210,
8,
355,
625,
17549,
63,
505,
12,
2512,
12,
6202,
63,
16516,
29,
1913,
63,
16516,
288,
776,
267,
871,
29359,
5314,
16467,
26,
288,
12004,
8,
5303,
9,
421,
199,
533,
428,
9385,
7068,
29174,
21365,
8,
29174,
21365,
12,
29359,
5314,
4256,
304,
221,
327,
730,
26,
3686,
272,
408,
272,
1666,
658,
17719,
14,
23004,
14,
29174,
21365,
2313,
272,
961,
1021,
365,
376,
3329,
626,
10580,
1006,
2879,
3102,
370,
272,
21077,
314,
12509,
666,
14,
272,
408,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
408,
267,
1432,
314,
1642,
666,
574,
367,
642,
790,
27,
267,
6534,
4067,
340,
440,
1911,
14,
398,
520,
635,
790,
26,
710,
790,
370,
506,
21182,
1536,
14,
267,
520,
3730,
4067,
26,
340,
314,
790,
1630,
440,
2187,
14,
267,
408,
267,
574,
275,
1613,
8,
51,
9385,
7068,
29174,
21365,
12,
291,
2843,
6095,
721,
498,
9,
267,
372,
291,
14,
18177,
63,
1210,
8,
585,
9,
339,
347,
664,
513,
8,
277,
12,
790,
12,
730,
29,
403,
304,
267,
408,
267,
1432,
314,
769,
402,
2974,
367,
282,
1627,
790,
14,
982,
626,
790,
365,
440,
315,
314,
267,
658,
21365,
3559,
314,
372,
574,
911,
506,
376,
2701,
769,
14,
221,
13870,
465,
658,
362,
64,
267,
658,
21343,
64,
11479,
282,
658,
466,
64,
2725,
14,
221,
2900,
2974,
911,
506,
6702,
267,
543,
314,
4550,
3247,
2337,
14,
398,
520,
635,
790,
26,
710,
790,
370,
506,
21182,
1536,
14,
267,
520,
635,
730,
26,
437,
4550,
626,
365,
1202,
370,
9106,
314,
574,
315,
314,
2151,
520,
533,
1705,
21365,
2313,
221,
982,
282,
520,
2804,
1705,
3393,
64,
365,
4915,
2151,
701,
642,
4550,
314,
574,
911,
506,
4829,
687,
314,
769,
14,
267,
520,
1107,
26,
282,
520,
533,
1705,
513,
64,
402,
1006,
314,
1338,
367,
314,
790,
14,
267,
408,
267,
574,
63,
513,
275,
1613,
8,
51,
9385,
7068,
29174,
21365,
12,
291,
680,
21343,
8,
498,
12,
730,
29,
466,
9,
267,
372,
359,
277,
14,
18177,
63,
1210,
8,
86,
9,
367,
373,
315,
574,
63,
513,
61,
339,
347,
2974,
8,
277,
12,
3510,
29,
797,
304,
267,
408,
267,
1432,
376,
6122,
402,
15475,
498,
12,
574,
9719,
6342,
14,
398,
520,
635,
3510,
26,
982,
663,
370,
658,
549,
64,
314,
6122,
2138,
911,
1172,
282,
4092,
1993,
367,
1924,
574,
402,
1924,
790,
14,
221,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pymedusa/Medusa
|
medusa/providers/generic_provider.py
|
1
|
42303
|
# coding=utf-8
"""Provider code for Generic Provider."""
from __future__ import unicode_literals
import logging
import operator
import re
from builtins import map
from builtins import object
from builtins import str
from datetime import datetime, timedelta
from os.path import join
from dateutil import parser, tz
from medusa import (
app,
config,
scene_exceptions,
tv,
ui,
)
from medusa.classes import SearchResult
from medusa.common import (
MULTI_EP_RESULT,
Quality,
SEASON_RESULT,
USER_AGENT,
)
from medusa.db import DBConnection
from medusa.helper.common import (
sanitize_filename,
)
from medusa.helpers import (
chmod_as_parent, download_file,
)
from medusa.indexers.config import INDEXER_TVDBV2
from medusa.logger.adapters.style import BraceAdapter
from medusa.name_parser.parser import (
InvalidNameException,
InvalidShowException,
NameParser,
)
from medusa.search import FORCED_SEARCH, PROPER_SEARCH
from medusa.session.core import ProviderSession
from medusa.show.show import Show
from pytimeparse import parse
from requests.utils import add_dict_to_cookiejar, dict_from_cookiejar
log = BraceAdapter(logging.getLogger(__name__))
log.logger.addHandler(logging.NullHandler())
# Keep a list of per provider of recent provider search results
recent_results = {}
class GenericProvider(object):
"""Generic provider."""
NZB = 'nzb'
TORRENT = 'torrent'
NEWZNAB = 'newznab'
TORZNAB = 'torznab'
TORRENTRSS = 'torrentrss'
PROWLARR = 'prowlarr'
def __init__(self, name):
"""Initialize the class."""
self.name = name
self.anime_only = False
self.cache = tv.Cache(self)
self.enable_backlog = False
self.enable_manualsearch = False
self.enable_daily = False
self.enabled = False
self.headers = {'User-Agent': USER_AGENT}
self.proper_strings = ['PROPER|REPACK|REAL|RERIP']
self.provider_type = None # generic type. For ex: nzb or torrent
self.provider_sub_type = None # specific type. For ex: neznab or torznab
self.public = False
self.search_fallback = False
self.search_mode = None
self.session = ProviderSession(cloudflare=True)
self.session.headers.update(self.headers)
self.series = None
self.supports_absolute_numbering = False
self.supports_backlog = True
self.url = ''
self.urls = {}
# Ability to override the search separator. As for example anizb is using '*' instead of space.
self.search_separator = ' '
self.season_templates = (
'S{season:0>2}', # example: 'Series.Name.S03'
)
# Use and configure the attribute enable_cookies to show or hide the cookies input field per provider
self.enable_cookies = False
self.cookies = ''
# Paramaters for reducting the daily search results parsing
self.max_recent_items = 5
self.stop_at = 3
# Delay downloads
self.enable_search_delay = False
self.search_delay = 480 # minutes
@classmethod
def kind(cls):
"""Return the name of the current class."""
return cls.__name__
def create_magnet(self, filename, result):
"""
Create a .magnet file containing the Magnet URI.
:param filename: base filename (without extension).
:param result: SearchResult object.
:returns: True if the magnet file is created and verified.
"""
filename_ext = '{filename}.magnet'.format(filename=filename)
log.info('Saving magnet file {result} to {location}',
{'result': result.name, 'location': filename_ext})
with open(filename_ext, 'w', encoding='utf-8') as fp:
fp.write(result.url)
if self._verify_magnet(filename_ext):
log.info('Saved .magnet file {result} to {location}',
{'result': result.name, 'location': filename_ext})
chmod_as_parent(filename)
return True
return False
def download_result(self, result):
"""Download result from provider."""
if not self.login():
return False
urls, filename = self._make_url(result)
for url in urls:
if 'NO_DOWNLOAD_NAME' in url:
continue
if url.startswith('http'):
self.headers.update({
'Referer': '/'.join(url.split('/')[:3]) + '/'
})
log.info('Downloading {result} from {provider} at {url}',
{'result': result.name, 'provider': self.name, 'url': url})
verify = False if self.public else None
filename_ext = '{filename}.{provider_type}'.format(
filename=filename, provider_type=result.provider.provider_type
)
if download_file(url, filename_ext, session=self.session, headers=self.headers,
verify=verify):
if self._verify_download(filename_ext):
log.info('Saved {result} to {location}',
{'result': result.name, 'location': filename_ext})
return True
if result.url.startswith('magnet:') and app.SAVE_MAGNET_FILE:
if self.create_magnet(filename, result):
return True
log.warning('Failed to download any results for {result}',
{'result': result.name})
return False
def _make_url(self, result):
"""Return url if result is a Magnet link."""
urls = []
filename = ''
if not result or not result.url:
return urls, filename
urls = [result.url]
result_name = sanitize_filename(result.name)
# TODO: Remove this in future versions, kept for the warning
# Some NZB providers (e.g. Jackett) can also download torrents
# A similar check is performed for NZB splitting in medusa/search/core.py @ search_providers()
if (result.url.endswith(GenericProvider.TORRENT)
or result.url.startswith('magnet:')) and self.provider_type == GenericProvider.NZB:
filename = join(app.TORRENT_DIR, result_name + '.torrent')
log.warning('Using Jackett providers as Newznab providers is deprecated!'
' Switch them to Jackett providers as soon as possible.')
else:
filename = join(self._get_storage_dir(), result_name + '.' + self.provider_type)
return urls, filename
def _verify_download(self, file_name):
return True
def get_content(self, url, params=None, timeout=30, **kwargs):
"""Retrieve the torrent/nzb content."""
return self.session.get_content(url, params=params, timeout=timeout, **kwargs)
def find_propers(self, proper_candidates):
"""Find propers in providers."""
results = []
for proper_candidate in proper_candidates:
series_obj = Show.find_by_id(app.showList, proper_candidate['indexer'], proper_candidate['showid'])
if series_obj:
self.series = series_obj
episode_obj = series_obj.get_episode(proper_candidate['season'], proper_candidate['episode'])
for term in self.proper_strings:
search_strings = self._get_episode_search_strings(episode_obj, add_string=term)
for item in self.search(search_strings[0], ep_obj=episode_obj):
search_result = self.get_result(series=series_obj, item=item)
if search_result in results:
continue
search_result.search_type = PROPER_SEARCH
results.append(search_result)
return results
def search_results_in_cache(self, episodes):
"""
Search episodes based on param in cache.
Search the cache (db) for this provider
:param episodes: List of Episode objects
:return: A dict of search results, ordered by episode number
"""
return self.cache.find_episodes(episodes)
def find_search_results(self, series, episodes, search_mode, forced_search=False, download_current_quality=False,
manual_search=False, manual_search_type='episode'):
"""
Search episodes based on param.
Search the provider using http queries.
:param series: Series object
:param episodes: List of Episode objects
:param search_mode: 'eponly' or 'sponly'
:param forced_search: Flag if the search was triggered by a forced search
:param download_current_quality: Flag if we want to include an already downloaded quality in the new search
:param manual_search: Flag if the search was triggered by a manual search
:param manual_search_type: How the manual search was started: For example an 'episode' or 'season'
:return: A dict of search results, ordered by episode number.
"""
self._check_auth()
self.series = series
season_search = (len(episodes) > 1 or manual_search_type == 'season') and search_mode == 'sponly'
results = []
for episode in episodes:
search_strings = []
if season_search:
search_strings = self._get_season_search_strings(episode)
elif search_mode == 'eponly':
search_strings = self._get_episode_search_strings(episode)
for search_string in search_strings:
# Find results from the provider
items = self.search(search_string, ep_obj=episode, manual_search=manual_search)
for item in items:
result = self.get_result(series=series, item=item)
if result not in results:
result.quality = Quality.quality_from_name(result.name, series.is_anime)
results.append(result)
# In season search, we can't loop in episodes lists as we
# only need one episode to get the season string
if search_mode == 'sponly':
break
log.debug('Found {0} unique search results', len(results))
# sort qualities in descending order
results.sort(key=operator.attrgetter('quality'), reverse=True)
# Move through each item and parse with NameParser()
for search_result in results:
if forced_search:
search_result.search_type = FORCED_SEARCH
search_result.download_current_quality = download_current_quality
search_result.result_wanted = True
try:
search_result.parsed_result = NameParser(
parse_method=('normal', 'anime')[series.is_anime]).parse(
search_result.name)
except (InvalidNameException, InvalidShowException) as error:
log.debug('Error during parsing of release name: {release_name}, with error: {error}',
{'release_name': search_result.name, 'error': error})
search_result.add_cache_entry = False
search_result.result_wanted = False
continue
# I don't know why i'm doing this. Maybe remove it later on all together, now i've added the parsed_result
# to the search_result.
search_result.series = search_result.parsed_result.series
search_result.quality = search_result.parsed_result.quality
search_result.release_group = search_result.parsed_result.release_group
search_result.version = search_result.parsed_result.version
search_result.actual_season = search_result.parsed_result.season_number
search_result.actual_episodes = search_result.parsed_result.episode_numbers
if not manual_search:
if not (search_result.series.air_by_date or search_result.series.sports):
if search_mode == 'sponly':
if search_result.parsed_result.episode_numbers:
log.debug(
'This is supposed to be a season pack search but the result {0} is not a valid '
'season pack, skipping it', search_result.name
)
search_result.result_wanted = False
continue
elif not [ep for ep in episodes if
search_result.parsed_result.season_number == (ep.season, ep.scene_season)
[ep.series.is_scene]]:
log.debug(
'This season result {0} is for a season we are not searching for, '
'skipping it', search_result.name
)
search_result.result_wanted = False
continue
else:
# I'm going to split these up for better readability
# Check if at least got a season parsed.
if search_result.parsed_result.season_number is None:
log.debug(
"The result {0} doesn't seem to have a valid season that we are currently trying to "
'snatch, skipping it', search_result.name
)
search_result.result_wanted = False
continue
# Check if we at least got some episode numbers parsed.
if not search_result.parsed_result.episode_numbers:
log.debug(
"The result {0} doesn't seem to match an episode that we are currently trying to "
'snatch, skipping it', search_result.name
)
search_result.result_wanted = False
continue
# Compare the episodes and season from the result with what was searched.
wanted_ep = False
for searched_ep in episodes:
if searched_ep.series.is_scene and searched_ep.scene_episode:
season = searched_ep.scene_season
episode = searched_ep.scene_episode
else:
season = searched_ep.season
episode = searched_ep.episode
if (season == search_result.parsed_result.season_number
and episode in search_result.parsed_result.episode_numbers):
wanted_ep = True
break
if not wanted_ep:
log.debug(
"The result {0} doesn't seem to match an episode that we are currently trying to "
'snatch, skipping it', search_result.name
)
search_result.result_wanted = False
continue
# We've performed some checks to decided if we want to continue with this result.
# If we've hit this, that means this is not an air_by_date and not a sports show. And it seems to be
# a valid result. Let's store the parsed season and episode number and continue.
search_result.actual_season = search_result.parsed_result.season_number
search_result.actual_episodes = search_result.parsed_result.episode_numbers
else:
# air_by_date or sportshow.
search_result.same_day_special = False
if not search_result.parsed_result.is_air_by_date:
log.debug(
"This is supposed to be a date search but the result {0} didn't parse as one, "
'skipping it', search_result.name
)
search_result.result_wanted = False
continue
else:
# Use a query against the tv_episodes table, to match the parsed air_date against.
air_date = search_result.parsed_result.air_date.toordinal()
db = DBConnection()
sql_results = db.select(
'SELECT season, episode FROM tv_episodes WHERE indexer = ? AND showid = ? AND airdate = ?',
[search_result.series.indexer, search_result.series.series_id, air_date]
)
if len(sql_results) == 2:
if int(sql_results[0]['season']) == 0 and int(sql_results[1]['season']) != 0:
search_result.actual_season = int(sql_results[1]['season'])
search_result.actual_episodes = [int(sql_results[1]['episode'])]
search_result.same_day_special = True
elif int(sql_results[1]['season']) == 0 and int(sql_results[0]['season']) != 0:
search_result.actual_season = int(sql_results[0]['season'])
search_result.actual_episodes = [int(sql_results[0]['episode'])]
search_result.same_day_special = True
elif len(sql_results) != 1:
log.warning(
"Tried to look up the date for the episode {0} but the database didn't return proper "
'results, skipping it', search_result.name
)
search_result.result_wanted = False
continue
# @TODO: Need to verify and test this.
if search_result.result_wanted and not search_result.same_day_special:
search_result.actual_season = int(sql_results[0]['season'])
search_result.actual_episodes = [int(sql_results[0]['episode'])]
final_results = {}
cl = []
# Iterate again over the search results, and see if there is anything we want.
for search_result in results:
# Try to cache the item if we want to.
cache_result = search_result.add_result_to_cache(self.cache)
if cache_result is not None:
cl.append(cache_result)
if not search_result.result_wanted:
log.debug("We aren't interested in this result: {0} with url: {1}",
search_result.name, search_result.url)
continue
log.debug('Found result {0} at {1}', search_result.name, search_result.url)
search_result.update_search_result()
if search_result.episode_number == SEASON_RESULT:
log.debug('Found season pack result {0} at {1}', search_result.name, search_result.url)
elif search_result.episode_number == MULTI_EP_RESULT:
log.debug('Found multi-episode ({0}) result {1} at {2}',
', '.join(map(str, search_result.parsed_result.episode_numbers)),
search_result.name,
search_result.url)
else:
log.debug('Found single episode result {0} at {1}', search_result.name, search_result.url)
if search_result.episode_number not in final_results:
final_results[search_result.episode_number] = [search_result]
else:
final_results[search_result.episode_number].append(search_result)
if cl:
# Access to a protected member of a client class
db = self.cache._get_db()
db.mass_action(cl)
return final_results
def get_id(self):
"""Get ID of the provider."""
return GenericProvider.make_id(self.name)
def get_result(self, series, item=None, cache=None):
"""Get result."""
search_result = SearchResult(provider=self, series=series,
item=item, cache=cache)
return search_result
def image_name(self):
"""Return provider image name."""
return self.get_id() + '.png'
def is_active(self):
"""Check if provider is active."""
return False
def is_enabled(self):
"""Check if provider is enabled."""
return bool(self.enabled)
@staticmethod
def make_id(name):
"""Make ID of the provider."""
if not name:
return ''
return re.sub(r'[^\w\d_]', '_', str(name).strip().lower())
def seed_ratio(self):
"""Return ratio."""
return ''
def _check_auth(self):
"""Check if we are autenticated."""
return True
def login(self):
"""Login to provider."""
return True
def search(self, search_strings, age=0, ep_obj=None, **kwargs):
"""Search the provider."""
return []
@staticmethod
def parse_pubdate(pubdate, human_time=False, timezone=None, **kwargs):
"""
Parse publishing date into a datetime object.
:param pubdate: date and time string
:param human_time: string uses human slang ("4 hours ago")
:param timezone: use a different timezone ("US/Eastern")
:keyword dayfirst: Interpret the first value as the day
:keyword yearfirst: Interpret the first value as the year
:returns: a datetime object or None
"""
now_alias = ('right now', 'just now', 'now')
df = kwargs.pop('dayfirst', False)
yf = kwargs.pop('yearfirst', False)
fromtimestamp = kwargs.pop('fromtimestamp', False)
# This can happen from time to time
if pubdate is None:
log.debug('Skipping invalid publishing date.')
return
try:
if human_time:
if pubdate.lower() in now_alias:
seconds = 0
else:
match = re.search(r'(?P<time>[\d.]+\W*)(?P<granularity>\w+)', pubdate)
matched_time = match.group('time')
matched_granularity = match.group('granularity')
# The parse method does not support decimals used with the month,
# months, year or years granularities.
if matched_granularity and matched_granularity in ('month', 'months', 'year', 'years'):
matched_time = int(round(float(matched_time.strip())))
seconds = parse('{0} {1}'.format(matched_time, matched_granularity))
if seconds is None:
log.warning('Failed parsing human time: {0} {1}', matched_time, matched_granularity)
raise ValueError('Failed parsing human time: {0} {1}'.format(matched_time, matched_granularity))
return datetime.now(tz.tzlocal()) - timedelta(seconds=seconds)
if fromtimestamp:
dt = datetime.fromtimestamp(int(pubdate), tz=tz.gettz('UTC'))
else:
day_offset = 0
if 'yesterday at' in pubdate.lower() or 'today at' in pubdate.lower():
# Extract a time
time = re.search(r'(?P<time>[0-9:]+)', pubdate)
if time:
if 'yesterday' in pubdate:
day_offset = 1
pubdate = time.group('time').strip()
dt = parser.parse(pubdate, dayfirst=df, yearfirst=yf, fuzzy=True) - timedelta(days=day_offset)
# Always make UTC aware if naive
if dt.tzinfo is None or dt.tzinfo.utcoffset(dt) is None:
dt = dt.replace(tzinfo=tz.gettz('UTC'))
if timezone:
dt = dt.astimezone(tz.gettz(timezone))
return dt
except (AttributeError, TypeError, ValueError):
log.exception('Failed parsing publishing date: {0}', pubdate)
def _create_air_by_date_search_string(self, show_scene_name, episode, search_string, add_string=None):
"""Create a search string used for series that are indexed by air date."""
episode_string = show_scene_name + self.search_separator
episode_string += str(episode.airdate).replace('-', ' ')
if add_string:
episode_string += self.search_separator + add_string
search_string['Episode'].append(episode_string.strip())
def _create_sports_search_string(self, show_scene_name, episode, search_string, add_string=None):
"""Create a search string used for sport series."""
episode_string = show_scene_name + self.search_separator
episode_string += str(episode.airdate).replace('-', ' ')
episode_string += ('|', ' ')[len(self.proper_strings) > 1]
episode_string += episode.airdate.strftime('%b')
if add_string:
episode_string += self.search_separator + add_string
search_string['Episode'].append(episode_string.strip())
def _create_anime_search_string(self, show_scene_name, episode, search_string, add_string=None):
"""Create a search string used for as anime 'marked' shows."""
episode_string = show_scene_name + self.search_separator
# If the show name is a season scene exception, we want to use the episode number
if episode.scene_season is not None and show_scene_name in scene_exceptions.get_season_scene_exceptions(
episode.series, episode.scene_season):
# This is apparently a season exception, let's use the episode instead of absolute
ep = episode.scene_episode
else:
if episode.series.is_scene and episode.scene_absolute_number:
ep = episode.scene_absolute_number
else:
ep = episode.absolute_number
episode_string += '{episode:0>2}'.format(episode=ep)
if add_string:
episode_string += self.search_separator + add_string
search_string['Episode'].append(episode_string.strip())
def _create_default_search_string(self, show_scene_name, episode, search_string, add_string=None):
"""Create a default search string, used for standard type S01E01 tv series."""
episode_string = show_scene_name + self.search_separator
if episode.series.is_scene and episode.scene_episode:
season_number = episode.scene_season
episode_number = episode.scene_episode
else:
season_number = episode.season
episode_number = episode.episode
episode_string += config.naming_ep_type[2] % {
'seasonnumber': season_number,
'episodenumber': episode_number
}
if add_string:
episode_string += self.search_separator + add_string
search_string['Episode'].append(episode_string.strip())
def _get_episode_search_strings(self, episode, add_string=''):
"""Get episode search strings."""
if not episode:
return []
search_string = {
'Episode': []
}
all_possible_show_names = episode.series.get_all_possible_names()
if episode.scene_season is not None:
all_possible_show_names = all_possible_show_names.union(
episode.series.get_all_possible_names(season=episode.scene_season)
)
for show_name in all_possible_show_names:
if episode.series.air_by_date:
self._create_air_by_date_search_string(show_name, episode, search_string, add_string=add_string)
elif episode.series.sports:
self._create_sports_search_string(show_name, episode, search_string, add_string=add_string)
elif episode.series.anime:
self._create_anime_search_string(show_name, episode, search_string, add_string=add_string)
else:
self._create_default_search_string(show_name, episode, search_string, add_string=add_string)
return [search_string]
def _get_tvdb_id(self):
"""Return the tvdb id if the shows indexer is tvdb. If not, try to use the externals to get it."""
if not self.series:
return None
return self.series.indexerid if self.series.indexer == INDEXER_TVDBV2 else self.series.externals.get('tvdb_id')
def _get_season_search_strings(self, episode):
search_string = {
'Season': []
}
for show_name in episode.series.get_all_possible_names(season=episode.scene_season):
episode_string = show_name + self.search_separator
if episode.series.air_by_date or episode.series.sports:
search_string['Season'].append(episode_string + str(episode.airdate).split('-')[0])
elif episode.series.anime:
search_string['Season'].append(episode_string + 'Season')
else:
for season_template in self.season_templates:
templated_episode_string = episode_string + season_template.format(season=episode.scene_season)
search_string['Season'].append(templated_episode_string.strip())
return [search_string]
def _get_size(self, item):
"""Return default size."""
return -1
def _get_storage_dir(self):
"""Return storage dir."""
return ''
def _get_result_info(self, item):
"""Return default seeders and leechers."""
return -1, -1
def _get_pubdate(self, item):
"""Return publish date of the item.
If provider doesnt have _get_pubdate function this will be used
"""
return None
def _get_title_and_url(self, item):
"""Return title and url from result."""
if not item:
return '', ''
title = item.get('title', '')
url = item.get('link', '')
if title:
title = title.replace(' ', '.')
else:
title = ''
if url:
url = url.replace('&', '&').replace('%26tr%3D', '&tr=')
else:
url = ''
return title, url
@staticmethod
def _get_identifier(item):
"""
Return the identifier for the item.
By default this is the url. Providers can overwrite this, when needed.
"""
return item.url
@property
def recent_results(self):
"""Return recent RSS results from provier."""
return recent_results.get(self.get_id(), [])
@recent_results.setter
def recent_results(self, items):
"""Set recent results from provider."""
if not recent_results.get(self.get_id()):
recent_results.update({self.get_id(): []})
if items:
add_to_list = []
for item in items:
if item not in recent_results[self.get_id()]:
add_to_list += [item]
results = add_to_list + recent_results[self.get_id()]
recent_results[self.get_id()] = results[:self.max_recent_items]
def add_cookies_from_ui(self):
"""
Add the cookies configured from UI to the providers requests session.
:return: A dict with the the keys result as bool and message as string
"""
# Added exception for rss torrent providers, as for them adding cookies initial should be optional.
from medusa.providers.torrent.rss.rsstorrent import TorrentRssProvider
if isinstance(self, TorrentRssProvider) and not self.cookies:
return {'result': True,
'message': 'This is a TorrentRss provider without any cookies provided. '
'Cookies for this provider are considered optional.'}
# This is the generic attribute used to manually add cookies for provider authentication
if not self.enable_cookies:
return {'result': False,
'message': 'Adding cookies is not supported for provider: {0}'.format(self.name)}
if not self.cookies:
return {'result': False,
'message': 'No Cookies added from ui for provider: {0}'.format(self.name)}
cookie_validator = re.compile(r'([\w%]+=[\w%]+)')
if not cookie_validator.findall(self.cookies):
ui.notifications.message(
'Failed to validate cookie for provider {provider}'.format(provider=self.name),
'Cookie is not correctly formatted: {0}'.format(self.cookies))
return {'result': False,
'message': 'Cookie is not correctly formatted: {0}'.format(self.cookies)}
if self.required_cookies:
if self.name == 'Beyond-HD':
if not any('remember_web_' in x.rsplit('=', 1)[0] for x in self.cookies.split(';')):
return {
'result': False,
'message': "You haven't configured the required cookies. Please login at {provider_url}, "
'and make sure you have copied the following cookies: {required_cookies!r}'.format(
provider_url=self.name, required_cookies=self.required_cookies
)
}
else:
if not all(req_cookie in [x.rsplit('=', 1)[0] for x in self.cookies.split(';')]
for req_cookie in self.required_cookies):
return {
'result': False,
'message': "You haven't configured the required cookies. Please login at {provider_url}, "
'and make sure you have copied the following cookies: {required_cookies!r}'.format(
provider_url=self.name, required_cookies=self.required_cookies
)
}
# cookie_validator got at least one cookie key/value pair, let's return success
add_dict_to_cookiejar(self.session.cookies, dict(x.rsplit('=', 1) for x in self.cookies.split(';')))
return {'result': True,
'message': ''}
def check_required_cookies(self):
"""
Check if we have the required cookies in the requests sessions object.
Meaning that we've already successfully authenticated once, and we don't need to go through this again.
Note! This doesn't mean the cookies are correct!
"""
if not hasattr(self, 'required_cookies'):
# A reminder for the developer, implementing cookie based authentication.
log.error(
'You need to configure the required_cookies attribute, for the provider: {provider}',
{'provider': self.name}
)
return False
return all(dict_from_cookiejar(self.session.cookies).get(cookie) for cookie in self.required_cookies)
def cookie_login(self, check_login_text, check_url=None):
"""
Check the response for text that indicates a login prompt.
In that case, the cookie authentication was not successful.
:param check_login_text: A string that's visible when the authentication failed.
:param check_url: The url to use to test the login with cookies. By default the providers home page is used.
:return: False when authentication was not successful. True if successful.
"""
check_url = check_url or self.url
if self.check_required_cookies():
# All required cookies have been found within the current session, we don't need to go through this again.
return True
if self.cookies:
result = self.add_cookies_from_ui()
if not result['result']:
ui.notifications.message(result['message'])
log.warning(result['message'])
return False
else:
log.warning('Failed to login, you will need to add your cookies in the provider settings')
ui.notifications.error('Failed to auth with {provider}'.format(provider=self.name),
'You will need to add your cookies in the provider settings')
return False
response = self.session.get(check_url)
if not response or any([not (response.text and response.status_code == 200),
check_login_text.lower() in response.text.lower()]):
log.warning('Please configure the required cookies for this provider. Check your provider settings')
ui.notifications.error('Wrong cookies for {provider}'.format(provider=self.name),
'Check your provider settings')
self.session.cookies.clear()
return False
else:
return True
def __str__(self):
"""Return provider name and provider type."""
return '{provider_name} ({provider_type})'.format(provider_name=self.name, provider_type=self.provider_type)
def __unicode__(self):
"""Return provider name and provider type."""
return '{provider_name} ({provider_type})'.format(provider_name=self.name, provider_type=self.provider_type)
def to_json(self):
"""Return a json representation for a provider."""
from medusa.providers.torrent.torrent_provider import TorrentProvider
# Generic options
data = {
'name': self.name,
'id': self.get_id(),
'imageName': self.image_name(),
'config': {
'enabled': self.enabled,
'search': {
'backlog': {
'enabled': self.enable_backlog
},
'manual': {
'enabled': self.enable_manualsearch
},
'daily': {
'enabled': self.enable_daily,
'maxRecentItems': self.max_recent_items,
'stopAt': self.stop_at
},
'fallback': self.search_fallback,
'mode': self.search_mode,
'separator': self.search_separator,
'seasonTemplates': self.season_templates,
'delay': {
'enabled': self.enable_search_delay,
'duration': self.search_delay
}
},
'cookies': {
'enabled': self.enable_cookies,
'values': self.cookies
}
},
'animeOnly': self.anime_only,
'type': self.provider_type,
'subType': self.provider_sub_type,
'public': self.public,
'btCacheUrls': self.bt_cache_urls if isinstance(self, TorrentProvider) else [],
'properStrings': self.proper_strings,
'headers': self.headers,
'supportsAbsoluteNumbering': self.supports_absolute_numbering,
'supportsBacklog': self.supports_backlog,
'url': self.custom_url or self.url if hasattr(self, 'custom_url') else self.url,
'urls': self.urls
}
# Custom options (torrent client specific)
if hasattr(self, 'username'):
data['config']['username'] = self.username
if hasattr(self, 'password'):
data['config']['password'] = self.password
if hasattr(self, 'api_key'):
data['config']['apikey'] = self.api_key
if hasattr(self, 'custom_url'):
data['config']['customUrl'] = self.custom_url
if hasattr(self, 'minseed'):
data['config']['minseed'] = self.minseed
if hasattr(self, 'minleech'):
data['config']['minleech'] = self.minleech
if hasattr(self, 'ratio'):
data['config']['ratio'] = self.ratio
if hasattr(self, 'client_ratio'):
data['config']['clientRatio'] = self.client_ratio
if hasattr(self, 'passkey'):
data['config']['passkey'] = self.passkey
if hasattr(self, 'hash'):
data['config']['hash'] = self.hash
if hasattr(self, 'digest'):
data['config']['digest'] = self.digest
if hasattr(self, 'pin'):
data['config']['pin'] = self.pin
if hasattr(self, 'confirmed'):
data['config']['confirmed'] = self.confirmed
if hasattr(self, 'ranked'):
data['config']['ranked'] = self.ranked
if hasattr(self, 'sorting'):
data['config']['sorting'] = self.sorting
if hasattr(self, 'required_cookies'):
data['config']['cookies']['required'] = self.required_cookies
# Custom options (newznab specific)
if hasattr(self, 'default'):
data['default'] = self.default
if hasattr(self, 'cat_ids'):
data['config']['catIds'] = self.cat_ids
if hasattr(self, 'params'):
data['config']['params'] = self.params
if hasattr(self, 'needs_auth'):
data['needsAuth'] = self.needs_auth
# Custom options (torrentrss)
if hasattr(self, 'title_tag'):
data['config']['titleTag'] = self.title_tag
# Custom options (prowlarr):
if hasattr(self, 'manager'):
data['manager'] = self.manager
if hasattr(self, 'id_manager'):
data['idManager'] = self.id_manager
return data
|
gpl-3.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
199,
624,
6663,
1233,
367,
8307,
18489,
1041,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2050,
199,
646,
4182,
199,
646,
295,
199,
504,
12963,
492,
2341,
199,
504,
12963,
492,
909,
199,
504,
12963,
492,
620,
199,
504,
2197,
492,
2197,
12,
6871,
199,
504,
747,
14,
515,
492,
4263,
199,
199,
504,
22208,
492,
1798,
12,
5823,
199,
199,
504,
562,
68,
527,
65,
492,
334,
272,
1145,
12,
272,
1101,
12,
272,
13856,
63,
3924,
12,
272,
13466,
12,
272,
8574,
12,
199,
9,
199,
504,
562,
68,
527,
65,
14,
2888,
492,
8730,
2889,
199,
504,
562,
68,
527,
65,
14,
2330,
492,
334,
272,
24895,
41,
63,
6102,
63,
9517,
12,
272,
24108,
12,
272,
5795,
28883,
63,
9517,
12,
272,
13044,
63,
14565,
12,
199,
9,
199,
504,
562,
68,
527,
65,
14,
697,
492,
6249,
3225,
199,
504,
562,
68,
527,
65,
14,
3676,
14,
2330,
492,
334,
272,
21077,
63,
1501,
12,
199,
9,
199,
504,
562,
68,
527,
65,
14,
7546,
492,
334,
272,
30106,
63,
305,
63,
1708,
12,
5235,
63,
493,
12,
199,
9,
199,
504,
562,
68,
527,
65,
14,
1080,
1192,
14,
888,
492,
17055,
540,
63,
12764,
2846,
54,
18,
199,
504,
562,
68,
527,
65,
14,
2921,
14,
21680,
14,
2487,
492,
699,
5986,
10200,
199,
504,
562,
68,
527,
65,
14,
354,
63,
2087,
14,
2087,
492,
334,
272,
6378,
985,
1726,
12,
272,
6378,
6824,
1726,
12,
272,
2812,
2842,
12,
199,
9,
199,
504,
562,
68,
527,
65,
14,
1733,
492,
2381,
25927,
63,
15962,
12,
3611,
4227,
63,
15962,
199,
504,
562,
68,
527,
65,
14,
1730,
14,
1018,
492,
18489,
4434,
199,
504,
562,
68,
527,
65,
14,
2384,
14,
2384,
492,
12968,
199,
199,
504,
1134,
521,
1122,
492,
2198,
199,
199,
504,
4145,
14,
1208,
492,
1050,
63,
807,
63,
475,
63,
30552,
12,
1211,
63,
504,
63,
30552,
199,
199,
793,
275,
699,
5986,
10200,
8,
4806,
14,
5572,
3460,
354,
8964,
199,
793,
14,
2921,
14,
18826,
8,
4806,
14,
8849,
2461,
1012,
199,
199,
3,
14797,
282,
769,
402,
1126,
5022,
402,
8058,
5022,
2754,
2058,
199,
14951,
63,
2604,
275,
1052,
421,
199,
533,
8307,
6663,
8,
785,
304,
272,
408,
9417,
5022,
1041,
339,
653,
58,
34,
275,
283,
15291,
66,
7,
272,
377,
726,
11574,
275,
283,
14101,
7,
272,
18689,
58,
46,
1217,
275,
283,
1222,
31591,
371,
7,
272,
377,
726,
58,
46,
1217,
275,
283,
8270,
31591,
371,
7,
272,
377,
726,
11574,
22786,
275,
283,
14101,
13614,
7,
272,
3611,
55,
44,
1920,
275,
283,
496,
20159,
5250,
7,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
408,
9345,
314,
1021,
1041,
267,
291,
14,
354,
275,
536,
398,
291,
14,
290,
1036,
63,
2118,
275,
756,
267,
291,
14,
1637,
275,
13466,
14,
4437,
8,
277,
9,
267,
291,
14,
4296,
63,
31267,
275,
756,
267,
291,
14,
4296,
63,
1237,
85,
535,
1047,
275,
756,
267,
291,
14,
4296,
63,
18621,
275,
756,
267,
291,
14,
3827,
275,
756,
267,
291,
14,
2139,
275,
791,
1899,
13,
7788,
356,
13044,
63,
14565,
93,
267,
291,
14,
28314,
63,
5465,
275,
788,
18858,
92,
907,
6961,
92,
15508,
92,
50,
540,
1772,
418,
267,
291,
14,
3780,
63,
466,
275,
488,
221,
327,
7809,
730,
14,
2104,
444,
26,
302,
20176,
503,
17671,
267,
291,
14,
3780,
63,
954,
63,
466,
275,
488,
221,
327,
2488,
730,
14,
2104,
444,
26,
1279,
31591,
371,
503,
11095,
31591,
371,
267,
291,
14,
3455,
275,
756,
267,
291,
14,
1733,
63,
10538,
275,
756,
267,
291,
14,
1733,
63,
632,
275,
488,
267,
291,
14,
1730,
275,
18489,
4434,
8,
4091,
14163,
264,
29,
549,
9,
267,
291,
14,
1730,
14,
2139,
14,
873,
8,
277,
14,
2139,
9,
267,
291,
14,
5602,
275,
488,
267,
291,
14,
9823,
63,
6116,
63,
1955,
316,
275,
756,
267,
291,
14,
9823,
63,
31267,
275,
715,
267,
291,
14,
633,
275,
2125,
267,
291,
14,
3603,
275,
1052,
398,
327,
437,
3195,
370,
4278,
314,
2754,
9432,
14,
3709,
367,
2893,
376,
565,
66,
365,
1808,
13626,
3140,
402,
4601,
14,
267,
291,
14,
1733,
63,
9896,
275,
283,
283,
267,
291,
14,
12605,
63,
5876,
275,
334,
288,
283,
51,
91,
12605,
26,
16,
30,
18,
7293,
221,
327,
2893,
26,
283,
9641,
14,
985,
14,
51,
1644,
7,
267,
776,
398,
327,
3645,
436,
7908,
314,
2225,
4756,
63,
7792,
370,
2498,
503,
13714,
314,
10049,
1324,
901,
1126,
5022,
267,
291,
14,
4296,
63,
7792,
275,
756,
267,
291,
14,
7792,
275,
2125,
398,
327,
12608,
323,
2393,
367,
295,
1601,
316,
314,
26122,
2754,
2058,
6057,
267,
291,
14,
988,
63,
14951,
63,
1744,
275,
959,
267,
291,
14,
2379,
63,
292,
275,
650,
398,
327,
18464,
1187,
28242,
267,
291,
14,
4296,
63,
1733,
63,
5814,
275,
756,
267,
291,
14,
1733,
63,
5814,
275,
29504,
221,
327,
9395,
339,
768,
3744,
272,
347,
4928,
8,
1886,
304,
267,
408,
1767,
314,
536,
402,
314,
1453,
1021,
1041,
267,
372,
843,
855,
354,
363,
339,
347,
1218,
63,
19902,
386,
8,
277,
12,
1788,
12,
754,
304,
267,
408,
267,
2790,
282,
1275,
19902,
386,
570,
3035,
314,
603,
643,
846,
9022,
14,
398,
520,
635,
1788,
26,
1300,
1788,
334,
7395,
3329,
680,
267,
520,
635,
754,
26,
8730,
2889,
909,
14,
267,
520,
5808,
26,
715,
340,
314,
15916,
386,
570,
365,
2737,
436,
16317,
14,
267,
408,
267,
1788,
63,
832,
275,
5041,
1501,
5565,
19902,
386,
1370,
908,
8,
1501,
29,
1501,
9,
267,
943,
14,
815,
360,
30125,
15916,
386,
570,
469,
1099,
93,
370,
469,
1985,
7293,
326,
791,
1099,
356,
754,
14,
354,
12,
283,
1985,
356,
1788,
63,
832,
1552,
398,
543,
1551,
8,
1501,
63,
832,
12,
283,
87,
297,
2644,
534,
1624,
13,
24,
358,
465,
4090,
26,
288,
4090,
14,
952,
8,
1099,
14,
633,
9,
398,
340,
291,
423,
4712,
63,
19902,
386
] |
[
2803,
29,
1624,
13,
24,
199,
199,
624,
6663,
1233,
367,
8307,
18489,
1041,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2050,
199,
646,
4182,
199,
646,
295,
199,
504,
12963,
492,
2341,
199,
504,
12963,
492,
909,
199,
504,
12963,
492,
620,
199,
504,
2197,
492,
2197,
12,
6871,
199,
504,
747,
14,
515,
492,
4263,
199,
199,
504,
22208,
492,
1798,
12,
5823,
199,
199,
504,
562,
68,
527,
65,
492,
334,
272,
1145,
12,
272,
1101,
12,
272,
13856,
63,
3924,
12,
272,
13466,
12,
272,
8574,
12,
199,
9,
199,
504,
562,
68,
527,
65,
14,
2888,
492,
8730,
2889,
199,
504,
562,
68,
527,
65,
14,
2330,
492,
334,
272,
24895,
41,
63,
6102,
63,
9517,
12,
272,
24108,
12,
272,
5795,
28883,
63,
9517,
12,
272,
13044,
63,
14565,
12,
199,
9,
199,
504,
562,
68,
527,
65,
14,
697,
492,
6249,
3225,
199,
504,
562,
68,
527,
65,
14,
3676,
14,
2330,
492,
334,
272,
21077,
63,
1501,
12,
199,
9,
199,
504,
562,
68,
527,
65,
14,
7546,
492,
334,
272,
30106,
63,
305,
63,
1708,
12,
5235,
63,
493,
12,
199,
9,
199,
504,
562,
68,
527,
65,
14,
1080,
1192,
14,
888,
492,
17055,
540,
63,
12764,
2846,
54,
18,
199,
504,
562,
68,
527,
65,
14,
2921,
14,
21680,
14,
2487,
492,
699,
5986,
10200,
199,
504,
562,
68,
527,
65,
14,
354,
63,
2087,
14,
2087,
492,
334,
272,
6378,
985,
1726,
12,
272,
6378,
6824,
1726,
12,
272,
2812,
2842,
12,
199,
9,
199,
504,
562,
68,
527,
65,
14,
1733,
492,
2381,
25927,
63,
15962,
12,
3611,
4227,
63,
15962,
199,
504,
562,
68,
527,
65,
14,
1730,
14,
1018,
492,
18489,
4434,
199,
504,
562,
68,
527,
65,
14,
2384,
14,
2384,
492,
12968,
199,
199,
504,
1134,
521,
1122,
492,
2198,
199,
199,
504,
4145,
14,
1208,
492,
1050,
63,
807,
63,
475,
63,
30552,
12,
1211,
63,
504,
63,
30552,
199,
199,
793,
275,
699,
5986,
10200,
8,
4806,
14,
5572,
3460,
354,
8964,
199,
793,
14,
2921,
14,
18826,
8,
4806,
14,
8849,
2461,
1012,
199,
199,
3,
14797,
282,
769,
402,
1126,
5022,
402,
8058,
5022,
2754,
2058,
199,
14951,
63,
2604,
275,
1052,
421,
199,
533,
8307,
6663,
8,
785,
304,
272,
408,
9417,
5022,
1041,
339,
653,
58,
34,
275,
283,
15291,
66,
7,
272,
377,
726,
11574,
275,
283,
14101,
7,
272,
18689,
58,
46,
1217,
275,
283,
1222,
31591,
371,
7,
272,
377,
726,
58,
46,
1217,
275,
283,
8270,
31591,
371,
7,
272,
377,
726,
11574,
22786,
275,
283,
14101,
13614,
7,
272,
3611,
55,
44,
1920,
275,
283,
496,
20159,
5250,
7,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
408,
9345,
314,
1021,
1041,
267,
291,
14,
354,
275,
536,
398,
291,
14,
290,
1036,
63,
2118,
275,
756,
267,
291,
14,
1637,
275,
13466,
14,
4437,
8,
277,
9,
267,
291,
14,
4296,
63,
31267,
275,
756,
267,
291,
14,
4296,
63,
1237,
85,
535,
1047,
275,
756,
267,
291,
14,
4296,
63,
18621,
275,
756,
267,
291,
14,
3827,
275,
756,
267,
291,
14,
2139,
275,
791,
1899,
13,
7788,
356,
13044,
63,
14565,
93,
267,
291,
14,
28314,
63,
5465,
275,
788,
18858,
92,
907,
6961,
92,
15508,
92,
50,
540,
1772,
418,
267,
291,
14,
3780,
63,
466,
275,
488,
221,
327,
7809,
730,
14,
2104,
444,
26,
302,
20176,
503,
17671,
267,
291,
14,
3780,
63,
954,
63,
466,
275,
488,
221,
327,
2488,
730,
14,
2104,
444,
26,
1279,
31591,
371,
503,
11095,
31591,
371,
267,
291,
14,
3455,
275,
756,
267,
291,
14,
1733,
63,
10538,
275,
756,
267,
291,
14,
1733,
63,
632,
275,
488,
267,
291,
14,
1730,
275,
18489,
4434,
8,
4091,
14163,
264,
29,
549,
9,
267,
291,
14,
1730,
14,
2139,
14,
873,
8,
277,
14,
2139,
9,
267,
291,
14,
5602,
275,
488,
267,
291,
14,
9823,
63,
6116,
63,
1955,
316,
275,
756,
267,
291,
14,
9823,
63,
31267,
275,
715,
267,
291,
14,
633,
275,
2125,
267,
291,
14,
3603,
275,
1052,
398,
327,
437,
3195,
370,
4278,
314,
2754,
9432,
14,
3709,
367,
2893,
376,
565,
66,
365,
1808,
13626,
3140,
402,
4601,
14,
267,
291,
14,
1733,
63,
9896,
275,
283,
283,
267,
291,
14,
12605,
63,
5876,
275,
334,
288,
283,
51,
91,
12605,
26,
16,
30,
18,
7293,
221,
327,
2893,
26,
283,
9641,
14,
985,
14,
51,
1644,
7,
267,
776,
398,
327,
3645,
436,
7908,
314,
2225,
4756,
63,
7792,
370,
2498,
503,
13714,
314,
10049,
1324,
901,
1126,
5022,
267,
291,
14,
4296,
63,
7792,
275,
756,
267,
291,
14,
7792,
275,
2125,
398,
327,
12608,
323,
2393,
367,
295,
1601,
316,
314,
26122,
2754,
2058,
6057,
267,
291,
14,
988,
63,
14951,
63,
1744,
275,
959,
267,
291,
14,
2379,
63,
292,
275,
650,
398,
327,
18464,
1187,
28242,
267,
291,
14,
4296,
63,
1733,
63,
5814,
275,
756,
267,
291,
14,
1733,
63,
5814,
275,
29504,
221,
327,
9395,
339,
768,
3744,
272,
347,
4928,
8,
1886,
304,
267,
408,
1767,
314,
536,
402,
314,
1453,
1021,
1041,
267,
372,
843,
855,
354,
363,
339,
347,
1218,
63,
19902,
386,
8,
277,
12,
1788,
12,
754,
304,
267,
408,
267,
2790,
282,
1275,
19902,
386,
570,
3035,
314,
603,
643,
846,
9022,
14,
398,
520,
635,
1788,
26,
1300,
1788,
334,
7395,
3329,
680,
267,
520,
635,
754,
26,
8730,
2889,
909,
14,
267,
520,
5808,
26,
715,
340,
314,
15916,
386,
570,
365,
2737,
436,
16317,
14,
267,
408,
267,
1788,
63,
832,
275,
5041,
1501,
5565,
19902,
386,
1370,
908,
8,
1501,
29,
1501,
9,
267,
943,
14,
815,
360,
30125,
15916,
386,
570,
469,
1099,
93,
370,
469,
1985,
7293,
326,
791,
1099,
356,
754,
14,
354,
12,
283,
1985,
356,
1788,
63,
832,
1552,
398,
543,
1551,
8,
1501,
63,
832,
12,
283,
87,
297,
2644,
534,
1624,
13,
24,
358,
465,
4090,
26,
288,
4090,
14,
952,
8,
1099,
14,
633,
9,
398,
340,
291,
423,
4712,
63,
19902,
386,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
zkraime/osf.io
|
framework/transactions/handlers.py
|
34
|
2780
|
# -*- coding: utf-8 -*-
import httplib
import logging
from flask import request, current_app
from pymongo.errors import OperationFailure
from framework.transactions import utils, commands, messages
from website import settings
LOCK_ERROR_CODE = httplib.BAD_REQUEST
NO_AUTO_TRANSACTION_ATTR = '_no_auto_transaction'
logger = logging.getLogger(__name__)
def no_auto_transaction(func):
setattr(func, NO_AUTO_TRANSACTION_ATTR, True)
return func
def view_has_annotation(attr):
try:
endpoint = request.url_rule.endpoint
except (RuntimeError, AttributeError):
return False
view = current_app.view_functions[endpoint]
return getattr(view, attr, False)
def transaction_before_request():
"""Setup transaction before handling the request.
"""
if view_has_annotation(NO_AUTO_TRANSACTION_ATTR):
return None
try:
commands.rollback()
logger.error('Transaction already in progress; rolling back.')
except OperationFailure as error:
message = utils.get_error_message(error)
if messages.NO_TRANSACTION_ERROR not in message:
raise
commands.begin()
def transaction_after_request(response):
"""Teardown transaction after handling the request. Rollback if an
uncaught exception occurred, else commit. If the commit fails due to a lock
error, rollback and return error response.
"""
if view_has_annotation(NO_AUTO_TRANSACTION_ATTR):
return response
if response.status_code >= 500:
commands.rollback()
else:
try:
commands.commit()
except OperationFailure as error:
message = utils.get_error_message(error)
if 'lock not granted' in message.lower():
commands.rollback()
return utils.handle_error(LOCK_ERROR_CODE)
raise
return response
def transaction_teardown_request(error=None):
"""Rollback transaction on uncaught error. This code should never be
reached in debug mode, since uncaught errors are raised for use in the
Werkzeug debugger.
"""
if view_has_annotation(NO_AUTO_TRANSACTION_ATTR):
return None
if error is not None:
if not settings.DEBUG_MODE:
logger.error('Uncaught error in `transaction_teardown_request`; '
'this should never happen with `DEBUG_MODE = True`')
# If we're testing, the before_request handlers may not have been executed
# e.g. when Flask#test_request_context() is used
if not current_app.testing:
commands.rollback()
handlers = {
'before_request': transaction_before_request,
'after_request': transaction_after_request,
'teardown_request': transaction_teardown_request,
}
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
8809,
199,
646,
2050,
199,
199,
504,
7209,
492,
1056,
12,
1453,
63,
571,
199,
504,
21878,
14,
2550,
492,
17954,
6782,
199,
199,
504,
10059,
14,
13754,
492,
3778,
12,
3718,
12,
3788,
199,
199,
504,
10691,
492,
2202,
421,
199,
4406,
63,
3170,
63,
6012,
275,
8809,
14,
9439,
63,
6780,
199,
2826,
63,
13883,
63,
12191,
10052,
63,
5280,
275,
2513,
889,
63,
2495,
63,
5945,
7,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
949,
63,
2495,
63,
5945,
8,
1532,
304,
272,
5371,
8,
1532,
12,
4825,
63,
13883,
63,
12191,
10052,
63,
5280,
12,
715,
9,
272,
372,
2562,
421,
199,
318,
2455,
63,
1989,
63,
9340,
8,
962,
304,
272,
862,
26,
267,
6037,
275,
1056,
14,
633,
63,
2200,
14,
6520,
272,
871,
334,
13281,
12,
4281,
304,
267,
372,
756,
272,
2455,
275,
1453,
63,
571,
14,
1345,
63,
5777,
59,
6520,
61,
272,
372,
2519,
8,
1345,
12,
1921,
12,
756,
9,
421,
199,
318,
6008,
63,
5182,
63,
1069,
837,
272,
408,
8555,
6008,
2544,
7252,
314,
1056,
14,
272,
408,
272,
340,
2455,
63,
1989,
63,
9340,
8,
2826,
63,
13883,
63,
12191,
10052,
63,
5280,
304,
267,
372,
488,
272,
862,
26,
267,
3718,
14,
10437,
342,
267,
2512,
14,
705,
360,
10161,
2575,
315,
6696,
27,
882,
10564,
1771,
2659,
272,
871,
17954,
6782,
465,
1125,
26,
267,
1245,
275,
3778,
14,
362,
63,
705,
63,
1188,
8,
705,
9,
267,
340,
3788,
14,
2826,
63,
12191,
10052,
63,
3170,
440,
315,
1245,
26,
288,
746,
272,
3718,
14,
5037,
342,
421,
199,
318,
6008,
63,
4399,
63,
1069,
8,
1310,
304,
272,
408,
6301,
10549,
6008,
2410,
7252,
314,
1056,
14,
820,
14385,
894,
340,
376,
272,
625,
24872,
1919,
8920,
12,
587,
5532,
14,
982,
314,
5532,
6918,
7037,
370,
282,
4650,
272,
1125,
12,
16475,
436,
372,
1125,
1177,
14,
272,
408,
272,
340,
2455,
63,
1989,
63,
9340,
8,
2826,
63,
13883,
63,
12191,
10052,
63,
5280,
304,
267,
372,
1177,
272,
340,
1177,
14,
1205,
63,
600,
2356,
6891,
26,
267,
3718,
14,
10437,
342,
272,
587,
26,
267,
862,
26,
288,
3718,
14,
3543,
342,
267,
871,
17954,
6782,
465,
1125,
26,
288,
1245,
275,
3778,
14,
362,
63,
705,
63,
1188,
8,
705,
9,
288,
340,
283,
831,
440,
10009,
7,
315,
1245,
14,
2325,
837,
355,
3718,
14,
10437,
342,
355,
372,
3778,
14,
2479,
63,
705,
8,
4406,
63,
3170,
63,
6012,
9,
288,
746,
272,
372,
1177,
421,
199,
318,
6008,
63,
15236,
63,
1069,
8,
705,
29,
403,
304,
272,
408,
24363,
894,
6008,
641,
625,
24872,
1125,
14,
961,
1233,
1077,
7078,
506,
272,
13075,
315,
3105,
818,
12,
3967,
625,
24872,
2552,
787,
4915,
367,
675,
315,
314,
272,
22798,
14958,
14,
272,
408,
272,
340,
2455,
63,
1989,
63,
9340,
8,
2826,
63,
13883,
63,
12191,
10052,
63,
5280,
304,
267,
372,
488,
272,
340,
1125,
365,
440,
488,
26,
267,
340,
440,
2202,
14,
5287,
63,
6963,
26,
288,
2512,
14,
705,
360,
1358,
24872,
1125,
315,
658,
5945,
63,
15236,
63,
1069,
64,
27,
283,
586,
283,
3749,
1077,
7078,
5992,
543,
658,
5287,
63,
6963,
275,
715,
64,
358,
267,
327,
982,
781,
3984,
5343,
12,
314,
2544,
63,
1069,
8297,
1443,
440,
1172,
2757,
7934,
267,
327,
325,
14,
71,
14,
1380,
16704,
3,
396,
63,
1069,
63,
1100,
342,
365,
1202,
267,
340,
440,
1453,
63,
571,
14,
4776,
26,
288,
3718,
14,
10437,
342,
421,
199,
5586,
275,
469,
272,
283,
5182,
63,
1069,
356,
6008,
63,
5182,
63,
1069,
12,
272,
283,
4399,
63,
1069,
356,
6008,
63,
4399,
63,
1069,
12,
272,
283,
15236,
63,
1069,
356,
6008,
63,
15236,
63,
1069,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
8809,
199,
646,
2050,
199,
199,
504,
7209,
492,
1056,
12,
1453,
63,
571,
199,
504,
21878,
14,
2550,
492,
17954,
6782,
199,
199,
504,
10059,
14,
13754,
492,
3778,
12,
3718,
12,
3788,
199,
199,
504,
10691,
492,
2202,
421,
199,
4406,
63,
3170,
63,
6012,
275,
8809,
14,
9439,
63,
6780,
199,
2826,
63,
13883,
63,
12191,
10052,
63,
5280,
275,
2513,
889,
63,
2495,
63,
5945,
7,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
949,
63,
2495,
63,
5945,
8,
1532,
304,
272,
5371,
8,
1532,
12,
4825,
63,
13883,
63,
12191,
10052,
63,
5280,
12,
715,
9,
272,
372,
2562,
421,
199,
318,
2455,
63,
1989,
63,
9340,
8,
962,
304,
272,
862,
26,
267,
6037,
275,
1056,
14,
633,
63,
2200,
14,
6520,
272,
871,
334,
13281,
12,
4281,
304,
267,
372,
756,
272,
2455,
275,
1453,
63,
571,
14,
1345,
63,
5777,
59,
6520,
61,
272,
372,
2519,
8,
1345,
12,
1921,
12,
756,
9,
421,
199,
318,
6008,
63,
5182,
63,
1069,
837,
272,
408,
8555,
6008,
2544,
7252,
314,
1056,
14,
272,
408,
272,
340,
2455,
63,
1989,
63,
9340,
8,
2826,
63,
13883,
63,
12191,
10052,
63,
5280,
304,
267,
372,
488,
272,
862,
26,
267,
3718,
14,
10437,
342,
267,
2512,
14,
705,
360,
10161,
2575,
315,
6696,
27,
882,
10564,
1771,
2659,
272,
871,
17954,
6782,
465,
1125,
26,
267,
1245,
275,
3778,
14,
362,
63,
705,
63,
1188,
8,
705,
9,
267,
340,
3788,
14,
2826,
63,
12191,
10052,
63,
3170,
440,
315,
1245,
26,
288,
746,
272,
3718,
14,
5037,
342,
421,
199,
318,
6008,
63,
4399,
63,
1069,
8,
1310,
304,
272,
408,
6301,
10549,
6008,
2410,
7252,
314,
1056,
14,
820,
14385,
894,
340,
376,
272,
625,
24872,
1919,
8920,
12,
587,
5532,
14,
982,
314,
5532,
6918,
7037,
370,
282,
4650,
272,
1125,
12,
16475,
436,
372,
1125,
1177,
14,
272,
408,
272,
340,
2455,
63,
1989,
63,
9340,
8,
2826,
63,
13883,
63,
12191,
10052,
63,
5280,
304,
267,
372,
1177,
272,
340,
1177,
14,
1205,
63,
600,
2356,
6891,
26,
267,
3718,
14,
10437,
342,
272,
587,
26,
267,
862,
26,
288,
3718,
14,
3543,
342,
267,
871,
17954,
6782,
465,
1125,
26,
288,
1245,
275,
3778,
14,
362,
63,
705,
63,
1188,
8,
705,
9,
288,
340,
283,
831,
440,
10009,
7,
315,
1245,
14,
2325,
837,
355,
3718,
14,
10437,
342,
355,
372,
3778,
14,
2479,
63,
705,
8,
4406,
63,
3170,
63,
6012,
9,
288,
746,
272,
372,
1177,
421,
199,
318,
6008,
63,
15236,
63,
1069,
8,
705,
29,
403,
304,
272,
408,
24363,
894,
6008,
641,
625,
24872,
1125,
14,
961,
1233,
1077,
7078,
506,
272,
13075,
315,
3105,
818,
12,
3967,
625,
24872,
2552,
787,
4915,
367,
675,
315,
314,
272,
22798,
14958,
14,
272,
408,
272,
340,
2455,
63,
1989,
63,
9340,
8,
2826,
63,
13883,
63,
12191,
10052,
63,
5280,
304,
267,
372,
488,
272,
340,
1125,
365,
440,
488,
26,
267,
340,
440,
2202,
14,
5287,
63,
6963,
26,
288,
2512,
14,
705,
360,
1358,
24872,
1125,
315,
658,
5945,
63,
15236,
63,
1069,
64,
27,
283,
586,
283,
3749,
1077,
7078,
5992,
543,
658,
5287,
63,
6963,
275,
715,
64,
358,
267,
327,
982,
781,
3984,
5343,
12,
314,
2544,
63,
1069,
8297,
1443,
440,
1172,
2757,
7934,
267,
327,
325,
14,
71,
14,
1380,
16704,
3,
396,
63,
1069,
63,
1100,
342,
365,
1202,
267,
340,
440,
1453,
63,
571,
14,
4776,
26,
288,
3718,
14,
10437,
342,
421,
199,
5586,
275,
469,
272,
283,
5182,
63,
1069,
356,
6008,
63,
5182,
63,
1069,
12,
272,
283,
4399,
63,
1069,
356,
6008,
63,
4399,
63,
1069,
12,
272,
283,
15236,
63,
1069,
356,
6008,
63,
15236,
63,
1069,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tkarna/cofs
|
test/tracerEq/test_consistency_2d.py
|
1
|
5860
|
"""
Tracer box in 2D
================
Solves a standing wave in a rectangular basin using wave equation.
This version uses a constant tracer to check local/global conservation of tracers.
Initial condition for elevation corresponds to a standing wave.
Time step and export interval are chosen based on theoretical
oscillation frequency. Initial condition repeats every 20 exports.
"""
from thetis import *
import pytest
def run_tracer_consistency(constant_c=True, **model_options):
t_cycle = 2000.0 # standing wave period
depth = 50.0 # average depth
lx = np.sqrt(9.81*depth)*t_cycle # wave length
ly = 3000.0
nx = 18
ny = 2
mesh2d = RectangleMesh(nx, ny, lx, ly)
tracer_value = 4.5
elev_amp = 2.0
# estimate of max advective velocity used to estimate time step
u_mag = Constant(1.0)
outputdir = 'outputs'
# bathymetry
p1_2d = get_functionspace(mesh2d, 'CG', 1)
bathymetry_2d = Function(p1_2d, name='Bathymetry')
x_2d, y_2d = SpatialCoordinate(mesh2d)
# non-trivial bathymetry, to properly test 2d tracer conservation
bathymetry_2d.interpolate(depth + depth/10.*sin(x_2d/lx*pi))
# set time step, export interval and run duration
n_steps = 8
t_export = round(float(t_cycle/n_steps))
# for testing tracer conservation, we don't want to come back to the initial condition
t_end = 2.5*t_cycle
# create solver
solver_obj = solver2d.FlowSolver2d(mesh2d, bathymetry_2d)
options = solver_obj.options
options.use_nonlinear_equations = True
options.solve_tracer = True
options.use_limiter_for_tracers = not constant_c
options.simulation_export_time = t_export
options.simulation_end_time = t_end
options.horizontal_velocity_scale = Constant(u_mag)
options.check_volume_conservation_2d = True
options.check_tracer_conservation = True
options.check_tracer_overshoot = True
options.timestepper_type = 'CrankNicolson'
options.output_directory = outputdir
options.fields_to_export = ['uv_2d', 'elev_2d', 'tracer_2d']
options.use_tracer_conservative_form = False
options.update(model_options)
if not options.no_exports:
print_output('Exporting to {:}'.format(options.output_directory))
solver_obj.create_function_spaces()
elev_init = Function(solver_obj.function_spaces.H_2d)
elev_init.project(-elev_amp*cos(2*pi*x_2d/lx))
tracer_init2d = None
if options.solve_tracer and constant_c:
tracer_init2d = Function(solver_obj.function_spaces.Q_2d, name='initial tracer')
tracer_init2d.assign(tracer_value)
if options.solve_tracer and not constant_c:
tracer_init2d = Function(solver_obj.function_spaces.Q_2d, name='initial tracer')
tracer_l = 0
tracer_r = 30.0
tracer_init2d.interpolate(tracer_l + (tracer_r - tracer_l)*0.5*(1.0 + sign(x_2d - lx/4)))
solver_obj.assign_initial_conditions(elev=elev_init, tracer=tracer_init2d)
solver_obj.iterate()
# TODO do these checks every export ...
vol2d, vol2d_rerr = solver_obj.callbacks['export']['volume2d']()
assert vol2d_rerr < 1e-10, '2D volume is not conserved'
if options.solve_tracer:
tracer_int, tracer_int_rerr = solver_obj.callbacks['export']['tracer_2d mass']()
assert abs(tracer_int_rerr) < 1.2e-4, 'tracer is not conserved'
smin, smax, undershoot, overshoot = solver_obj.callbacks['export']['tracer_2d overshoot']()
max_abs_overshoot = max(abs(undershoot), abs(overshoot))
overshoot_tol = 1e-11
if not options.use_tracer_conservative_form:
msg = 'Tracer overshoots are too large: {:}'.format(max_abs_overshoot)
assert max_abs_overshoot < overshoot_tol, msg
# ---------------------------
# standard tests for pytest
# ---------------------------
@pytest.fixture(params=['CrankNicolson', 'SSPRK33', 'ForwardEuler', 'BackwardEuler', 'DIRK22', 'DIRK33'])
def stepper(request):
return request.param
def test_const_tracer(stepper):
"""
Test timeintegrator without slope limiters
Constant tracer, should remain constant
"""
run_tracer_consistency(constant_c=True,
use_nonlinear_equations=True,
solve_tracer=True,
use_limiter_for_tracers=False,
no_exports=True,
timestepper_type=stepper)
def test_nonconst_tracer(stepper):
"""
Test timeintegrator with slope limiters
Non-trivial tracer, should see no overshoots and be conserved
"""
run_tracer_consistency(constant_c=False,
use_nonlinear_equations=True,
solve_tracer=True,
use_limiter_for_tracers=True,
no_exports=True,
timestepper_type=stepper)
def test_nonconst_tracer_conservative(stepper):
"""
Test timeintegrator without slope limiters
Non-trivial tracer, should be conserved
"""
run_tracer_consistency(constant_c=False,
use_nonlinear_equations=True,
solve_tracer=True,
use_limiter_for_tracers=False,
no_exports=True,
use_tracer_conservative_form=True,
timestepper_type=stepper)
# ---------------------------
# run individual setup for debugging
# ---------------------------
if __name__ == '__main__':
run_tracer_consistency(constant_c=False,
use_nonlinear_equations=True,
solve_tracer=True,
use_limiter_for_tracers=False,
no_exports=False,
timestepper_type='CrankNicolson')
|
mit
|
[
624,
199,
2437,
2247,
5689,
315,
499,
36,
199,
1280,
199,
199,
27262,
2310,
282,
10584,
316,
12204,
315,
282,
8626,
11572,
330,
24202,
1808,
12204,
18649,
14,
199,
199,
2765,
1015,
4440,
282,
4413,
29140,
370,
1104,
2257,
15,
2966,
406,
8213,
402,
1468,
67,
1192,
14,
199,
199,
5733,
5558,
367,
12993,
4255,
13718,
370,
282,
10584,
316,
12204,
14,
199,
1366,
3650,
436,
4843,
6252,
787,
12414,
4079,
641,
314,
720,
3294,
199,
26737,
382,
2212,
9857,
14,
6026,
5558,
28908,
4036,
3388,
22609,
14,
199,
624,
199,
504,
314,
16753,
492,
627,
199,
646,
4613,
421,
199,
318,
1255,
63,
16825,
63,
20249,
8,
4083,
63,
67,
29,
549,
12,
1011,
1238,
63,
1419,
304,
339,
307,
63,
7612,
275,
12293,
14,
16,
221,
327,
10584,
316,
12204,
6247,
272,
5818,
275,
5238,
14,
16,
221,
327,
8095,
5818,
272,
634,
88,
275,
980,
14,
5079,
8,
25,
14,
2835,
10,
4631,
3342,
84,
63,
7612,
221,
327,
12204,
2582,
272,
21559,
275,
29664,
14,
16,
272,
8484,
275,
6155,
272,
25758,
275,
499,
272,
9364,
18,
68,
275,
21536,
4593,
12241,
8,
7343,
12,
25758,
12,
634,
88,
12,
21559,
9,
272,
29140,
63,
585,
275,
841,
14,
21,
272,
325,
6972,
63,
5282,
275,
499,
14,
16,
272,
327,
14497,
402,
1390,
1503,
6046,
857,
20508,
1202,
370,
14497,
900,
3650,
272,
399,
63,
5615,
275,
19991,
8,
17,
14,
16,
9,
339,
1072,
694,
275,
283,
4467,
7,
339,
327,
330,
1619,
89,
10987,
272,
299,
17,
63,
18,
68,
275,
664,
63,
1593,
2638,
8,
6480,
18,
68,
12,
283,
4064,
297,
413,
9,
272,
330,
1619,
89,
10987,
63,
18,
68,
275,
6801,
8,
80,
17,
63,
18,
68,
12,
536,
534,
34,
1619,
89,
10987,
358,
272,
671,
63,
18,
68,
12,
612,
63,
18,
68,
275,
13423,
18017,
8,
6480,
18,
68,
9,
272,
327,
2222,
13,
23844,
330,
1619,
89,
10987,
12,
370,
7684,
511,
499,
68,
29140,
406,
8213,
272,
330,
1619,
89,
10987,
63,
18,
68,
14,
21294,
8,
4631,
435,
5818,
15,
709,
2795,
5911,
8,
88,
63,
18,
68,
15,
23605,
10,
1038,
430,
339,
327,
663,
900,
3650,
12,
4843,
6252,
436,
1255,
7373,
272,
302,
63,
5895,
275,
1695,
272,
307,
63,
3790,
275,
6168,
8,
1609,
8,
84,
63,
7612,
15,
78,
63,
5895,
430,
272,
327,
367,
5343,
29140,
406,
8213,
12,
781,
2793,
1133,
2934,
370,
11492,
1771,
370,
314,
2536,
5558,
272,
307,
63,
500,
275,
499,
14,
21,
10,
84,
63,
7612,
339,
327,
1218,
10196,
272,
10196,
63,
1113,
275,
10196,
18,
68,
14,
5060,
24755,
18,
68,
8,
6480,
18,
68,
12,
330,
1619,
89,
10987,
63,
18,
68,
9,
272,
1511,
275,
10196,
63,
1113,
14,
1419,
272,
1511,
14,
1180,
63,
2865,
6676,
63,
15788,
1298,
275,
715,
272,
1511,
14,
11356,
63,
16825,
275,
715,
272,
1511,
14,
1180,
63,
7919,
63,
509,
63,
23047,
1192,
275,
440,
4413,
63,
67,
272,
1511,
14,
22930,
63,
3790,
63,
521,
275,
307,
63,
3790,
272,
1511,
14,
22930,
63,
500,
63,
521,
275,
307,
63,
500,
272,
1511,
14,
11392,
63,
16350,
63,
3467,
275,
19991,
8,
85,
63,
5615,
9,
272,
1511,
14,
1074,
63,
2405,
63,
388,
8213,
63,
18,
68,
275,
715,
272,
1511,
14,
1074,
63,
16825,
63,
388,
8213,
275,
715,
272,
1511,
14,
1074,
63,
16825,
63,
1883,
13927,
357,
275,
715,
272,
1511,
14,
521,
2926,
529,
63,
466,
275,
283,
35,
4648,
20959,
4574,
265,
7,
272,
1511,
14,
1199,
63,
3619,
275,
1072,
694,
272,
1511,
14,
955,
63,
475,
63,
3790,
275,
788,
9154,
63,
18,
68,
297,
283,
24083,
63,
18,
68,
297,
283,
16825,
63,
18,
68,
418,
272,
1511,
14,
1180,
63,
16825,
63,
388,
7297,
1905,
63,
964,
275,
756,
272,
1511,
14,
873,
8,
1238,
63,
1419,
9,
339,
340,
440,
1511,
14,
889,
63,
20775,
26,
267,
870,
63,
1199,
360,
11399,
316,
370,
19850,
5285,
908,
8,
1419,
14,
1199,
63,
3619,
430,
339,
10196,
63,
1113,
14,
981,
63,
1593,
63,
10749,
342,
272,
325,
6972,
63,
826,
275,
6801,
8,
11263,
63,
1113,
14,
1593,
63,
10749,
14,
40,
63,
18,
68,
9,
272,
325,
6972,
63,
826,
14,
1715,
2801,
24083,
63,
5282,
10,
5197,
8,
18,
10,
1038,
10,
88,
63,
18,
68,
15,
23605,
430,
339,
29140,
63,
826,
18,
68,
275,
488,
272,
340,
1511,
14,
11356,
63,
16825,
436,
4413,
63,
67,
26,
267,
29140,
63,
826,
18,
68,
275,
6801,
8,
11263,
63,
1113,
14,
1593,
63,
10749,
14,
49,
63,
18,
68,
12,
536,
534,
2747,
29140,
358,
267,
29140,
63,
826,
18,
68,
14,
5038,
8,
16825,
63,
585,
9,
272,
340,
1511,
14,
11356,
63,
16825,
436,
440,
4413,
63,
67,
26,
267,
29140,
63,
826,
18,
68,
275,
6801,
8,
11263,
63,
1113,
14,
1593,
63,
10749,
14,
49,
63,
18,
68,
12,
536,
534,
2747,
29140,
358,
267,
29140,
63,
76,
275,
378,
267,
29140,
63,
82,
275,
4233,
14,
16,
267,
29140,
63,
826,
18,
68,
14,
21294,
8,
16825,
63,
76,
435,
334,
16825,
63,
82,
446,
29140,
63,
76,
3342,
16,
14,
21,
5830,
17,
14,
16,
435,
2070,
8,
88,
63,
18,
68,
446,
634,
88,
15,
20,
1724,
339,
10196,
63,
1113,
14,
5038,
63,
2747,
63,
9855,
8,
24083,
29,
24083,
63,
826,
12,
29140,
29,
16825,
63,
826,
18,
68,
9,
272,
10196,
63,
1113,
14,
20627,
342,
339,
327,
3254,
886,
3520,
5920,
4036,
4843,
2263,
272,
5236,
18,
68,
12,
5236,
18,
68,
63,
3859,
82,
275,
10196,
63,
1113,
14,
11948,
459,
3790,
2545,
2405,
18,
68,
418,
342,
272,
702,
5236,
18,
68,
63,
3859,
82,
665,
413,
69,
13,
709,
12,
283,
18,
36,
3301,
365,
440,
406,
2485,
7,
272,
340,
1511,
14,
11356,
63,
16825,
26,
267,
29140,
63,
442,
12,
29140,
63,
442,
63,
3859,
82,
275,
10196,
63,
1113,
14,
11948,
459,
3790,
2545,
16825,
63,
18,
68,
12250,
418,
342,
267,
702,
2853,
8,
16825,
63,
442,
63,
3859,
82
] |
[
199,
2437,
2247,
5689,
315,
499,
36,
199,
1280,
199,
199,
27262,
2310,
282,
10584,
316,
12204,
315,
282,
8626,
11572,
330,
24202,
1808,
12204,
18649,
14,
199,
199,
2765,
1015,
4440,
282,
4413,
29140,
370,
1104,
2257,
15,
2966,
406,
8213,
402,
1468,
67,
1192,
14,
199,
199,
5733,
5558,
367,
12993,
4255,
13718,
370,
282,
10584,
316,
12204,
14,
199,
1366,
3650,
436,
4843,
6252,
787,
12414,
4079,
641,
314,
720,
3294,
199,
26737,
382,
2212,
9857,
14,
6026,
5558,
28908,
4036,
3388,
22609,
14,
199,
624,
199,
504,
314,
16753,
492,
627,
199,
646,
4613,
421,
199,
318,
1255,
63,
16825,
63,
20249,
8,
4083,
63,
67,
29,
549,
12,
1011,
1238,
63,
1419,
304,
339,
307,
63,
7612,
275,
12293,
14,
16,
221,
327,
10584,
316,
12204,
6247,
272,
5818,
275,
5238,
14,
16,
221,
327,
8095,
5818,
272,
634,
88,
275,
980,
14,
5079,
8,
25,
14,
2835,
10,
4631,
3342,
84,
63,
7612,
221,
327,
12204,
2582,
272,
21559,
275,
29664,
14,
16,
272,
8484,
275,
6155,
272,
25758,
275,
499,
272,
9364,
18,
68,
275,
21536,
4593,
12241,
8,
7343,
12,
25758,
12,
634,
88,
12,
21559,
9,
272,
29140,
63,
585,
275,
841,
14,
21,
272,
325,
6972,
63,
5282,
275,
499,
14,
16,
272,
327,
14497,
402,
1390,
1503,
6046,
857,
20508,
1202,
370,
14497,
900,
3650,
272,
399,
63,
5615,
275,
19991,
8,
17,
14,
16,
9,
339,
1072,
694,
275,
283,
4467,
7,
339,
327,
330,
1619,
89,
10987,
272,
299,
17,
63,
18,
68,
275,
664,
63,
1593,
2638,
8,
6480,
18,
68,
12,
283,
4064,
297,
413,
9,
272,
330,
1619,
89,
10987,
63,
18,
68,
275,
6801,
8,
80,
17,
63,
18,
68,
12,
536,
534,
34,
1619,
89,
10987,
358,
272,
671,
63,
18,
68,
12,
612,
63,
18,
68,
275,
13423,
18017,
8,
6480,
18,
68,
9,
272,
327,
2222,
13,
23844,
330,
1619,
89,
10987,
12,
370,
7684,
511,
499,
68,
29140,
406,
8213,
272,
330,
1619,
89,
10987,
63,
18,
68,
14,
21294,
8,
4631,
435,
5818,
15,
709,
2795,
5911,
8,
88,
63,
18,
68,
15,
23605,
10,
1038,
430,
339,
327,
663,
900,
3650,
12,
4843,
6252,
436,
1255,
7373,
272,
302,
63,
5895,
275,
1695,
272,
307,
63,
3790,
275,
6168,
8,
1609,
8,
84,
63,
7612,
15,
78,
63,
5895,
430,
272,
327,
367,
5343,
29140,
406,
8213,
12,
781,
2793,
1133,
2934,
370,
11492,
1771,
370,
314,
2536,
5558,
272,
307,
63,
500,
275,
499,
14,
21,
10,
84,
63,
7612,
339,
327,
1218,
10196,
272,
10196,
63,
1113,
275,
10196,
18,
68,
14,
5060,
24755,
18,
68,
8,
6480,
18,
68,
12,
330,
1619,
89,
10987,
63,
18,
68,
9,
272,
1511,
275,
10196,
63,
1113,
14,
1419,
272,
1511,
14,
1180,
63,
2865,
6676,
63,
15788,
1298,
275,
715,
272,
1511,
14,
11356,
63,
16825,
275,
715,
272,
1511,
14,
1180,
63,
7919,
63,
509,
63,
23047,
1192,
275,
440,
4413,
63,
67,
272,
1511,
14,
22930,
63,
3790,
63,
521,
275,
307,
63,
3790,
272,
1511,
14,
22930,
63,
500,
63,
521,
275,
307,
63,
500,
272,
1511,
14,
11392,
63,
16350,
63,
3467,
275,
19991,
8,
85,
63,
5615,
9,
272,
1511,
14,
1074,
63,
2405,
63,
388,
8213,
63,
18,
68,
275,
715,
272,
1511,
14,
1074,
63,
16825,
63,
388,
8213,
275,
715,
272,
1511,
14,
1074,
63,
16825,
63,
1883,
13927,
357,
275,
715,
272,
1511,
14,
521,
2926,
529,
63,
466,
275,
283,
35,
4648,
20959,
4574,
265,
7,
272,
1511,
14,
1199,
63,
3619,
275,
1072,
694,
272,
1511,
14,
955,
63,
475,
63,
3790,
275,
788,
9154,
63,
18,
68,
297,
283,
24083,
63,
18,
68,
297,
283,
16825,
63,
18,
68,
418,
272,
1511,
14,
1180,
63,
16825,
63,
388,
7297,
1905,
63,
964,
275,
756,
272,
1511,
14,
873,
8,
1238,
63,
1419,
9,
339,
340,
440,
1511,
14,
889,
63,
20775,
26,
267,
870,
63,
1199,
360,
11399,
316,
370,
19850,
5285,
908,
8,
1419,
14,
1199,
63,
3619,
430,
339,
10196,
63,
1113,
14,
981,
63,
1593,
63,
10749,
342,
272,
325,
6972,
63,
826,
275,
6801,
8,
11263,
63,
1113,
14,
1593,
63,
10749,
14,
40,
63,
18,
68,
9,
272,
325,
6972,
63,
826,
14,
1715,
2801,
24083,
63,
5282,
10,
5197,
8,
18,
10,
1038,
10,
88,
63,
18,
68,
15,
23605,
430,
339,
29140,
63,
826,
18,
68,
275,
488,
272,
340,
1511,
14,
11356,
63,
16825,
436,
4413,
63,
67,
26,
267,
29140,
63,
826,
18,
68,
275,
6801,
8,
11263,
63,
1113,
14,
1593,
63,
10749,
14,
49,
63,
18,
68,
12,
536,
534,
2747,
29140,
358,
267,
29140,
63,
826,
18,
68,
14,
5038,
8,
16825,
63,
585,
9,
272,
340,
1511,
14,
11356,
63,
16825,
436,
440,
4413,
63,
67,
26,
267,
29140,
63,
826,
18,
68,
275,
6801,
8,
11263,
63,
1113,
14,
1593,
63,
10749,
14,
49,
63,
18,
68,
12,
536,
534,
2747,
29140,
358,
267,
29140,
63,
76,
275,
378,
267,
29140,
63,
82,
275,
4233,
14,
16,
267,
29140,
63,
826,
18,
68,
14,
21294,
8,
16825,
63,
76,
435,
334,
16825,
63,
82,
446,
29140,
63,
76,
3342,
16,
14,
21,
5830,
17,
14,
16,
435,
2070,
8,
88,
63,
18,
68,
446,
634,
88,
15,
20,
1724,
339,
10196,
63,
1113,
14,
5038,
63,
2747,
63,
9855,
8,
24083,
29,
24083,
63,
826,
12,
29140,
29,
16825,
63,
826,
18,
68,
9,
272,
10196,
63,
1113,
14,
20627,
342,
339,
327,
3254,
886,
3520,
5920,
4036,
4843,
2263,
272,
5236,
18,
68,
12,
5236,
18,
68,
63,
3859,
82,
275,
10196,
63,
1113,
14,
11948,
459,
3790,
2545,
2405,
18,
68,
418,
342,
272,
702,
5236,
18,
68,
63,
3859,
82,
665,
413,
69,
13,
709,
12,
283,
18,
36,
3301,
365,
440,
406,
2485,
7,
272,
340,
1511,
14,
11356,
63,
16825,
26,
267,
29140,
63,
442,
12,
29140,
63,
442,
63,
3859,
82,
275,
10196,
63,
1113,
14,
11948,
459,
3790,
2545,
16825,
63,
18,
68,
12250,
418,
342,
267,
702,
2853,
8,
16825,
63,
442,
63,
3859,
82,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
martin-neuhaeusser/benchexec
|
benchexec/oomhandler.py
|
2
|
6248
|
# BenchExec is a framework for reliable benchmarking.
# This file is part of BenchExec.
#
# Copyright (C) 2007-2015 Dirk Beyer
# 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.
# prepare for Python 3
from __future__ import absolute_import, division, print_function, unicode_literals
# THIS MODULE HAS TO WORK WITH PYTHON 2.7!
import logging
import os
import threading
from benchexec.cgroups import MEMORY
from benchexec import util
from ctypes import cdll
_libc = cdll.LoadLibrary('libc.so.6')
_EFD_CLOEXEC = 0x80000 # from <sys/eventfd.h>: mark eventfd as close-on-exec
_BYTE_FACTOR = 1000 # byte in kilobyte
class KillProcessOnOomThread(threading.Thread):
"""
Thread that kills the process when they run out of memory.
Usually the kernel would do this by itself,
but sometimes the process still hangs because it does not even have
enough memory left to get killed
(the memory limit also effects some kernel-internal memory related to our process).
So we disable the kernel-side killing,
and instead let the kernel notify us via an event when the cgroup ran out of memory.
Then we kill the process ourselves and increase the memory limit a little bit.
The notification works by opening an "event file descriptor" with eventfd,
and telling the kernel to notify us about OOMs by writing the event file
descriptor and an file descriptor of the memory.oom_control file
to cgroup.event_control.
The kernel-side process killing is disabled by writing 1 to memory.oom_control.
Sources:
https://www.kernel.org/doc/Documentation/cgroups/memory.txt
https://access.redhat.com/site/documentation//en-US/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/sec-memory.html#ex-OOM-control-notifications
@param cgroups: The cgroups instance to monitor
@param process: The process instance to kill
@param callbackFn: A one-argument function that is called in case of OOM with a string for the reason as argument
"""
def __init__(self, cgroups, kill_process_fn, pid_to_kill, callbackFn=lambda reason: None):
super(KillProcessOnOomThread, self).__init__()
self.name = "KillProcessOnOomThread-" + self.name
self._finished = threading.Event()
self._pid_to_kill = pid_to_kill
self._cgroups = cgroups
self._callback = callbackFn
self._kill_process = kill_process_fn
cgroup = cgroups[MEMORY] #for raw access
ofd = os.open(os.path.join(cgroup, 'memory.oom_control'), os.O_WRONLY)
try:
# Important to use CLOEXEC, otherwise the benchmarked tool inherits
# the file descriptor.
self._efd = _libc.eventfd(0, _EFD_CLOEXEC)
try:
util.write_file('{} {}'.format(self._efd, ofd),
cgroup, 'cgroup.event_control')
# If everything worked, disable Kernel-side process killing.
# This is not allowed if memory.use_hierarchy is enabled,
# but we don't care.
try:
os.write(ofd, '1'.encode('ascii'))
except OSError as e:
logging.debug("Failed to disable kernel-side OOM killer: error %s (%s)",
e.errno, e.strerror)
except EnvironmentError as e:
os.close(self._efd)
raise e
finally:
os.close(ofd)
def run(self):
# os.close gets called in finally,
# which sometimes is executed while the process is shutting down already.
# It happens that the Python interpreter has already cleaned up at this point
# and "os" resolves to None, leading to an AttributeError.
# Thus we keep our own reference to this function.
# (Should not happen anymore since this is no longer a daemon thread,
# but should not hurt anyway.)
close = os.close
try:
# In an eventfd, there are always 8 bytes
_ = os.read(self._efd, 8) # blocks and returns event number (we do not need it)
# If read returned, this means the kernel sent us an event.
# It does so either on OOM or if the cgroup is removed.
if not self._finished.is_set():
self._callback('memory')
logging.debug('Killing process %s due to out-of-memory event from kernel.',
self._pid_to_kill)
self._kill_process(self._pid_to_kill, self._cgroups)
# Also kill all children of subprocesses directly.
with open(os.path.join(self._cgroups[MEMORY], 'tasks'), 'rt') as tasks:
for task in tasks:
self._kill_process(int(task), self._cgroups)
# We now need to increase the memory limit of this cgroup
# to give the process a chance to terminate
self._reset_memory_limit('memory.memsw.limit_in_bytes')
self._reset_memory_limit('memory.limit_in_bytes')
finally:
close(self._efd)
def _reset_memory_limit(self, limitFile):
if self._cgroups.has_value(MEMORY, limitFile):
try:
# Write a high value (1 PB) as the limit
self._cgroups.set_value(MEMORY, limitFile,
str(1 * _BYTE_FACTOR * _BYTE_FACTOR * _BYTE_FACTOR * _BYTE_FACTOR * _BYTE_FACTOR))
except IOError as e:
logging.warning('Failed to increase %s after OOM: error %s (%s).',
limitFile, e.errno, e.strerror)
def cancel(self):
self._finished.set()
|
apache-2.0
|
[
3,
699,
5368,
4858,
365,
282,
10059,
367,
32150,
12338,
316,
14,
199,
3,
961,
570,
365,
1777,
402,
699,
5368,
4858,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
10219,
13,
7806,
221,
25866,
75,
6423,
23009,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
3,
9275,
367,
2018,
650,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
3,
5749,
30223,
7509,
2296,
29557,
43,
1663,
18280,
499,
14,
23,
1,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
5796,
199,
199,
504,
26456,
1628,
14,
67,
2634,
492,
31424,
5347,
199,
504,
26456,
1628,
492,
4884,
199,
199,
504,
5577,
492,
286,
9259,
199,
63,
20217,
275,
286,
9259,
14,
6200,
7424,
360,
20217,
14,
1152,
14,
22,
358,
199,
63,
37,
7902,
63,
10353,
10276,
275,
378,
88,
24,
993,
327,
687,
665,
1274,
15,
1430,
2592,
14,
72,
20020,
2216,
1566,
2592,
465,
4002,
13,
265,
13,
1628,
199,
199,
63,
19714,
63,
26393,
275,
5198,
327,
3696,
315,
1022,
11737,
4414,
199,
199,
533,
1804,
778,
3498,
3314,
47,
676,
4436,
8,
12562,
14,
4436,
304,
272,
408,
272,
11086,
626,
1022,
15350,
314,
2112,
1380,
2985,
1255,
734,
402,
4402,
14,
272,
24612,
314,
5114,
3955,
886,
642,
701,
6337,
12,
272,
1325,
15026,
314,
2112,
5139,
394,
20068,
2952,
652,
1630,
440,
2755,
1172,
272,
8321,
4402,
3602,
370,
664,
26659,
272,
334,
1589,
4402,
2304,
2597,
22414,
2005,
5114,
13,
4672,
4402,
4048,
370,
4154,
2112,
680,
272,
2002,
781,
3507,
314,
5114,
13,
2441,
1022,
12687,
12,
272,
436,
3140,
4691,
314,
5114,
11705,
2739,
4799,
376,
1566,
1380,
314,
286,
923,
21471,
734,
402,
4402,
14,
272,
9442,
781,
14561,
314,
2112,
26495,
436,
19781,
314,
4402,
2304,
282,
12050,
4546,
14,
339,
710,
6955,
5419,
701,
13618,
376,
298,
1430,
570,
5872,
2,
543,
1566,
2592,
12,
272,
436,
1565,
10564,
314,
5114,
370,
11705,
2739,
3595,
593,
7474,
83,
701,
3575,
314,
1566,
570,
272,
5872,
436,
376,
570,
5872,
402,
314,
4402,
14,
7501,
63,
2785,
570,
272,
370,
286,
923,
14,
1430,
63,
2785,
14,
272,
710,
5114,
13,
2441,
2112,
1022,
12687,
365,
6980,
701,
3575,
413,
370,
4402,
14,
7501,
63,
2785,
14,
272,
5800,
83,
26,
272,
4178,
921,
1544,
14,
4989,
14,
1308,
15,
1301,
15,
17763,
15,
67,
2634,
15,
4844,
14,
2424,
272,
4178,
921,
2732,
14,
17164,
14,
957,
15,
2124,
15,
9970,
501,
287,
13,
1668,
15,
10858,
63,
40,
292,
63,
8468,
13219,
63,
14091,
15,
22,
15,
1360,
15,
4031,
63,
14552,
63,
4324,
271,
15,
3321,
13,
4844,
14,
1360,
3,
476,
13,
5757,
45,
13,
2785,
13,
12782,
339,
768,
635,
286,
2634,
26,
710,
286,
2634,
1256,
370,
8372,
272,
768,
635,
2112,
26,
710,
2112,
1256,
370,
14561,
272,
768,
635,
3233,
9656,
26,
437,
1373,
13,
2094,
805,
626,
365,
2797,
315,
1930,
402,
593,
7474,
543,
282,
1059,
367,
314,
4499,
465,
1423,
272,
408,
272,
347,
636,
826,
721,
277,
12,
286,
2634,
12,
14561,
63,
1412,
63,
2324,
12,
4422,
63,
475,
63,
8997,
12,
3233,
9656,
29,
2734,
4499,
26,
488,
304,
267,
1613,
8,
31464,
3498,
3314,
47,
676,
4436,
12,
291,
2843,
826,
4533,
267,
291,
14,
354,
275,
298,
31464,
3498,
3314,
47,
676,
4436,
23245,
435,
291,
14,
354,
267,
291,
423,
8669,
275,
5796,
14,
2390,
342,
267,
291,
423,
3150,
63,
475,
63,
8997,
275,
4422,
63,
475,
63,
8997,
267,
291,
423,
67,
2634,
275,
286,
2634,
267,
291,
423,
3058,
275,
3233,
9656,
267,
291,
423,
8997,
63,
1412,
275,
14561,
63,
1412,
63,
2324,
398,
286,
923,
275,
286,
2634,
59,
19495,
61,
327,
509,
3066,
2879,
267,
402,
68,
275,
747,
14,
1490,
8,
736,
14,
515,
14,
904,
8,
24483,
12,
283,
4844,
14,
7501,
63,
2785,
659,
747,
14,
47,
63,
6524,
10452,
9,
267,
862,
26,
288,
327,
3161,
867,
370,
675,
445,
1484,
10276,
12,
4257,
314,
12338,
379,
4744,
21592,
288,
327,
314,
570,
5872,
14,
288,
291,
423,
69,
2592,
275,
485,
20217,
14,
1430,
2592,
8,
16,
12,
485,
37,
7902,
63,
10353,
10276,
9,
953,
862,
26,
355,
4884,
14,
952,
63,
493,
17519,
9499,
908,
8,
277,
423,
69,
2592,
12,
402,
68,
395,
3660,
286,
923,
12,
283,
24483,
14,
1430,
63,
2785,
358,
2234,
327,
982,
8137,
26731,
12,
3507,
24901,
13,
2441,
2112,
1022,
12687,
14,
355,
327,
961,
365,
440,
4370,
340,
4402,
14,
1180,
63,
14861,
365,
5223,
12,
355,
327,
1325,
781,
2793,
1133,
10296,
14,
355,
862,
26,
490,
747,
14,
952,
8,
1618,
68,
12,
283,
17,
1370,
2143,
360,
4371,
1333,
355,
871,
6440,
465,
325,
26,
490,
2050,
14,
1757,
480,
4276,
370,
3507,
5114,
13,
2441,
593,
7474,
1022,
19576,
26,
1125,
450,
83,
4366,
83,
4186,
3303,
325,
14,
7931,
12,
325,
14,
20395,
9,
288,
871,
25139,
465,
325,
26,
355,
747,
14,
1600,
8,
277,
423,
69,
2592,
9,
355,
746,
325,
267,
3753,
26,
288,
747,
14,
1600,
8,
1618,
68,
9,
339,
347,
1255,
8,
277,
304,
267,
327,
747,
14,
1600,
7545,
2797,
315,
3753,
12,
267,
327,
1314,
15026,
365,
7934,
1830,
314,
2112,
365,
24761,
1337,
3224
] |
[
699,
5368,
4858,
365,
282,
10059,
367,
32150,
12338,
316,
14,
199,
3,
961,
570,
365,
1777,
402,
699,
5368,
4858,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
10219,
13,
7806,
221,
25866,
75,
6423,
23009,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
3,
9275,
367,
2018,
650,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
3,
5749,
30223,
7509,
2296,
29557,
43,
1663,
18280,
499,
14,
23,
1,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
5796,
199,
199,
504,
26456,
1628,
14,
67,
2634,
492,
31424,
5347,
199,
504,
26456,
1628,
492,
4884,
199,
199,
504,
5577,
492,
286,
9259,
199,
63,
20217,
275,
286,
9259,
14,
6200,
7424,
360,
20217,
14,
1152,
14,
22,
358,
199,
63,
37,
7902,
63,
10353,
10276,
275,
378,
88,
24,
993,
327,
687,
665,
1274,
15,
1430,
2592,
14,
72,
20020,
2216,
1566,
2592,
465,
4002,
13,
265,
13,
1628,
199,
199,
63,
19714,
63,
26393,
275,
5198,
327,
3696,
315,
1022,
11737,
4414,
199,
199,
533,
1804,
778,
3498,
3314,
47,
676,
4436,
8,
12562,
14,
4436,
304,
272,
408,
272,
11086,
626,
1022,
15350,
314,
2112,
1380,
2985,
1255,
734,
402,
4402,
14,
272,
24612,
314,
5114,
3955,
886,
642,
701,
6337,
12,
272,
1325,
15026,
314,
2112,
5139,
394,
20068,
2952,
652,
1630,
440,
2755,
1172,
272,
8321,
4402,
3602,
370,
664,
26659,
272,
334,
1589,
4402,
2304,
2597,
22414,
2005,
5114,
13,
4672,
4402,
4048,
370,
4154,
2112,
680,
272,
2002,
781,
3507,
314,
5114,
13,
2441,
1022,
12687,
12,
272,
436,
3140,
4691,
314,
5114,
11705,
2739,
4799,
376,
1566,
1380,
314,
286,
923,
21471,
734,
402,
4402,
14,
272,
9442,
781,
14561,
314,
2112,
26495,
436,
19781,
314,
4402,
2304,
282,
12050,
4546,
14,
339,
710,
6955,
5419,
701,
13618,
376,
298,
1430,
570,
5872,
2,
543,
1566,
2592,
12,
272,
436,
1565,
10564,
314,
5114,
370,
11705,
2739,
3595,
593,
7474,
83,
701,
3575,
314,
1566,
570,
272,
5872,
436,
376,
570,
5872,
402,
314,
4402,
14,
7501,
63,
2785,
570,
272,
370,
286,
923,
14,
1430,
63,
2785,
14,
272,
710,
5114,
13,
2441,
2112,
1022,
12687,
365,
6980,
701,
3575,
413,
370,
4402,
14,
7501,
63,
2785,
14,
272,
5800,
83,
26,
272,
4178,
921,
1544,
14,
4989,
14,
1308,
15,
1301,
15,
17763,
15,
67,
2634,
15,
4844,
14,
2424,
272,
4178,
921,
2732,
14,
17164,
14,
957,
15,
2124,
15,
9970,
501,
287,
13,
1668,
15,
10858,
63,
40,
292,
63,
8468,
13219,
63,
14091,
15,
22,
15,
1360,
15,
4031,
63,
14552,
63,
4324,
271,
15,
3321,
13,
4844,
14,
1360,
3,
476,
13,
5757,
45,
13,
2785,
13,
12782,
339,
768,
635,
286,
2634,
26,
710,
286,
2634,
1256,
370,
8372,
272,
768,
635,
2112,
26,
710,
2112,
1256,
370,
14561,
272,
768,
635,
3233,
9656,
26,
437,
1373,
13,
2094,
805,
626,
365,
2797,
315,
1930,
402,
593,
7474,
543,
282,
1059,
367,
314,
4499,
465,
1423,
272,
408,
272,
347,
636,
826,
721,
277,
12,
286,
2634,
12,
14561,
63,
1412,
63,
2324,
12,
4422,
63,
475,
63,
8997,
12,
3233,
9656,
29,
2734,
4499,
26,
488,
304,
267,
1613,
8,
31464,
3498,
3314,
47,
676,
4436,
12,
291,
2843,
826,
4533,
267,
291,
14,
354,
275,
298,
31464,
3498,
3314,
47,
676,
4436,
23245,
435,
291,
14,
354,
267,
291,
423,
8669,
275,
5796,
14,
2390,
342,
267,
291,
423,
3150,
63,
475,
63,
8997,
275,
4422,
63,
475,
63,
8997,
267,
291,
423,
67,
2634,
275,
286,
2634,
267,
291,
423,
3058,
275,
3233,
9656,
267,
291,
423,
8997,
63,
1412,
275,
14561,
63,
1412,
63,
2324,
398,
286,
923,
275,
286,
2634,
59,
19495,
61,
327,
509,
3066,
2879,
267,
402,
68,
275,
747,
14,
1490,
8,
736,
14,
515,
14,
904,
8,
24483,
12,
283,
4844,
14,
7501,
63,
2785,
659,
747,
14,
47,
63,
6524,
10452,
9,
267,
862,
26,
288,
327,
3161,
867,
370,
675,
445,
1484,
10276,
12,
4257,
314,
12338,
379,
4744,
21592,
288,
327,
314,
570,
5872,
14,
288,
291,
423,
69,
2592,
275,
485,
20217,
14,
1430,
2592,
8,
16,
12,
485,
37,
7902,
63,
10353,
10276,
9,
953,
862,
26,
355,
4884,
14,
952,
63,
493,
17519,
9499,
908,
8,
277,
423,
69,
2592,
12,
402,
68,
395,
3660,
286,
923,
12,
283,
24483,
14,
1430,
63,
2785,
358,
2234,
327,
982,
8137,
26731,
12,
3507,
24901,
13,
2441,
2112,
1022,
12687,
14,
355,
327,
961,
365,
440,
4370,
340,
4402,
14,
1180,
63,
14861,
365,
5223,
12,
355,
327,
1325,
781,
2793,
1133,
10296,
14,
355,
862,
26,
490,
747,
14,
952,
8,
1618,
68,
12,
283,
17,
1370,
2143,
360,
4371,
1333,
355,
871,
6440,
465,
325,
26,
490,
2050,
14,
1757,
480,
4276,
370,
3507,
5114,
13,
2441,
593,
7474,
1022,
19576,
26,
1125,
450,
83,
4366,
83,
4186,
3303,
325,
14,
7931,
12,
325,
14,
20395,
9,
288,
871,
25139,
465,
325,
26,
355,
747,
14,
1600,
8,
277,
423,
69,
2592,
9,
355,
746,
325,
267,
3753,
26,
288,
747,
14,
1600,
8,
1618,
68,
9,
339,
347,
1255,
8,
277,
304,
267,
327,
747,
14,
1600,
7545,
2797,
315,
3753,
12,
267,
327,
1314,
15026,
365,
7934,
1830,
314,
2112,
365,
24761,
1337,
3224,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
aLaix2/O-Nes-Sama
|
DebuggerClient/PPUDebugger.py
|
1
|
8074
|
import wx
import Breakpoint
import Debugger
import DialogAddBreakpoint
import GUI
class PPUDebuggerFrame(GUI.MainFrame, Debugger.Debugger):
#constructor
def __init__(self, parent):
GUI.MainFrame.__init__(self, parent)
Debugger.Debugger.__init__(self)
self.addBreakpointFrame = None
self.breakpoints = []
self.paused = False
self.EventConnect(None)
def __del__(self):
self.EventDisconnect(None)
def EventConnect(self, event):
if not self._connected:
self.ConnectToDebugger()
self.staticTextConnection.SetLabel("Connected")
def EventDisconnect(self, event):
if self._connected:
self.Quit()
self.staticTextConnection.SetLabel("Disconnected")
def EventAddBreakpoint(self, event):
if not self.addBreakpointFrame:
self.addBreakpointFrame = DialogAddBreakpoint.DialogAddBreakpoint(self)
self.addBreakpointFrame.Show(True)
def EventContinue(self, event):
self.Continue()
self.staticRunning.SetLabel('Running')
self.timerContinue.Start()
def EventRun(self, event):
self.paused = False
self.Continue()
self.staticRunning.SetLabel('Running')
self.timerRun.Start()
def EventPause(self, event):
self.paused = True
def ControllerAddBreakpoint(self, type, param1, param2):
typeList = ['address', 'value', 'time']
typeLower = type.lower()
if typeLower in typeList:
if typeLower == 'time':
bpNumber = self.AddBreakpointPPUByTime(param1, param2)
if bpNumber is not False:
breakpoint = Breakpoint.BreakpointPPUByTime(bpNumber, param1, param2)
self.breakpoints.append(breakpoint)
self.listBoxBreakpoints.Append(breakpoint.toString())
elif typeLower == 'address':
bpNumber = self.AddBreakpointPPUByAddress(param1)
if bpNumber is not False:
breakpoint = Breakpoint.BreakpointPPUByAddress(bpNumber, param1)
self.breakpoints.append(breakpoint)
self.listBoxBreakpoints.Append(breakpoint.toString())
elif typeLower == 'value':
bpNumber = self.AddBreakpointPPUByValue(param1, param2)
if bpNumber is not False:
breakpoint = Breakpoint.BreakpointPPUByValue(bpNumber, param1, param2)
self.breakpoints.append(breakpoint)
self.listBoxBreakpoints.Append(breakpoint.toString())
return True
else:
return False
def EventDeleteBreakpoint(self, event):
sel = self.listBoxBreakpoints.GetSelection()
if(sel >= 0):
dlg = wx.MessageDialog(parent=None, message="Are you sure you want to delete it?", caption="Question",
style=wx.YES_NO | wx.ICON_QUESTION)
result = dlg.ShowModal()
if result == wx.ID_YES:
index = self.listBoxBreakpoints.GetSelection()
string = self.listBoxBreakpoints.GetStringSelection()
bpNumber = -1
for elem in self.breakpoints:
if elem.toString() == string:
bpNumber = elem.breakpointNumber
self.listBoxBreakpoints.Delete(index)
self.breakpoints.remove(elem)
self.DeleteBreakpoint(bpNumber)
pass
else:
pass
dlg.Destroy()
#self.listBoxBreakpoints.Delete()
def _StoppedAt(self, number):
string = 'None'
for elem in self.breakpoints:
if elem.breakpointNumber == number:
string = elem.toString()
self.staticRunning.SetLabel('Stopped at: {string:s}'.format(**locals()))
def EventTimerContinue(self, event):
number = self.Reached()
if number is not False:
if number == "ERROR":
self.staticRunning.SetLabel('ERROR')
else:
self._StoppedAt(number)
self.timerContinue.Stop()
def EventTimerRun(self, event):
number = self.Reached()
if number is not False:
if number == "ERROR":
self.staticRunning.SetLabel('ERROR')
else:
if not self.paused:
self.Continue()
else:
self._StoppedAt(number)
self.timerRun.Stop()
def EventUpdateCHR(self, event):
self.GenerateCHR0()
self.GenerateCHR1()
self.panelCHR0.Refresh()
self.panelCHR1.Refresh()
def EventUpdateNametables(self, event):
self.GenerateNametable1()
self.panelNametable1.Refresh()
self.GenerateNametable2()
self.panelNametable2.Refresh()
self.GenerateNametable3()
self.panelNametable3.Refresh()
self.GenerateNametable4()
self.panelNametable4.Refresh()
def EventUpdateOam(self, event):
self.GenerateOams()
self.panelOam.Refresh()
def EventCHRMotion(self, event):
x = event.GetPosition()[0] >> 3 >> 1
y = event.GetPosition()[1] >> 3 >> 1
self.labelCHR.SetLabel("Position: ${y:X}{x:X}".format(**locals()))
def EventNTMotion(self, event):
x = event.GetPosition()[0] >> 3
y = event.GetPosition()[1] >> 3
pos = 0x2000 | (y << 5) | x
self.labelNT.SetLabel("Address: ${pos:X}, Tile: $00, X: {x}, Y: {y}".format(**locals()))
def EventOamMotion(self, event):
pass
def _PaintFromMemory(self, width, height, data, panel, scaling):
img = wx.EmptyImage(width, height)
img.SetData(data)
if scaling:
bmp = img.Scale(width*2, height*2).ConvertToBitmap()
else:
bmp = img.ConvertToBitmap()
dc = wx.PaintDC(panel)
dc.DrawBitmap(bmp, 0, 0)
def _PaintFromImage(self, width, height, image, panel, scaling):
if scaling:
bmp = image.Scale(width*scaling, height*scaling).ConvertToBitmap()
else:
bmp = image.ConvertToBitmap()
dc = wx.PaintDC(panel)
dc.DrawBitmap(bmp, 0, 0)
def EventPaintCHR0(self, event):
self._PaintFromImage(self.CHR_WIDTH, self.CHR_HEIGHT, self.imageCHR0, self.panelCHR0, 2)
def EventPaintCHR1(self, event):
self._PaintFromImage(self.CHR_WIDTH, self.CHR_HEIGHT, self.imageCHR1, self.panelCHR1, 2)
def EventPaintNametable1(self, event):
self._PaintFromImage(self.NAMETABLE_WIDTH, self.NAMETABLE_HEIGHT, self.imageNametable1, self.panelNametable1, 0)
def EventPaintNametable2(self, event):
self._PaintFromImage(self.NAMETABLE_WIDTH, self.NAMETABLE_HEIGHT, self.imageNametable2, self.panelNametable2, 0)
def EventPaintNametable3(self, event):
self._PaintFromImage(self.NAMETABLE_WIDTH, self.NAMETABLE_HEIGHT, self.imageNametable3, self.panelNametable3, 0)
def EventPaintNametable4(self, event):
self._PaintFromImage(self.NAMETABLE_WIDTH, self.NAMETABLE_HEIGHT, self.imageNametable4, self.panelNametable4, 0)
def EventPaintOam(self, event):
self._PaintFromImage(256, 240, self.imageOam, self.panelOam, 2)
def EventEraseBackground(self, event):
pass
def EventNT1LeftDown(self, event):
print event.GetPosition()[0] >> 3
print event.GetPosition()[1] >> 3
#mandatory in wx, create an app, False stands for not deteriction stdin/stdout
#refer manual for details
app = wx.App(False)
#create an object of CalcFrame
frame = PPUDebuggerFrame(None)
#show the frame
frame.Show(True)
#start the applications
app.MainLoop()
|
gpl-3.0
|
[
646,
4818,
2999,
199,
646,
22535,
1403,
202,
199,
646,
14245,
836,
202,
199,
646,
30631,
1123,
28944,
202,
199,
646,
17160,
8065,
199,
533,
510,
6903,
31521,
3160,
8,
14438,
14,
6756,
3160,
12,
14245,
836,
14,
31521,
304,
1128,
327,
1880,
1128,
347,
636,
826,
721,
277,
12,
1676,
304,
1039,
17160,
14,
6756,
3160,
855,
826,
721,
277,
12,
1676,
9,
1039,
14245,
836,
14,
31521,
855,
826,
721,
277,
9,
1039,
291,
14,
525,
28944,
3160,
275,
488,
1039,
291,
14,
4785,
3438,
275,
942,
1039,
291,
14,
22478,
275,
756,
1039,
291,
14,
2390,
8631,
8,
403,
9,
2958,
347,
636,
2264,
721,
277,
304,
1039,
291,
14,
2390,
16761,
8,
403,
9,
2958,
347,
6763,
8631,
8,
277,
12,
1566,
304,
1039,
340,
440,
291,
423,
7113,
26,
1675,
291,
14,
8631,
1378,
31521,
342,
1675,
291,
14,
1986,
1872,
3225,
14,
1084,
4314,
480,
16382,
531,
2958,
347,
6763,
16761,
8,
277,
12,
1566,
304,
1039,
340,
291,
423,
7113,
26,
1675,
291,
14,
24145,
342,
1675,
291,
14,
1986,
1872,
3225,
14,
1084,
4314,
480,
2825,
7113,
531,
2958,
347,
6763,
1123,
28944,
8,
277,
12,
1566,
304,
1039,
340,
440,
291,
14,
525,
28944,
3160,
26,
1675,
291,
14,
525,
28944,
3160,
275,
30631,
1123,
28944,
14,
5619,
1123,
28944,
8,
277,
9,
1039,
291,
14,
525,
28944,
3160,
14,
6824,
8,
549,
9,
2958,
347,
6763,
24055,
8,
277,
12,
1566,
304,
1039,
291,
14,
24055,
342,
1039,
291,
14,
1986,
9602,
14,
1084,
4314,
360,
9602,
358,
1039,
291,
14,
7414,
24055,
14,
3162,
342,
2958,
347,
6763,
2540,
8,
277,
12,
1566,
304,
1039,
291,
14,
22478,
275,
756,
1039,
291,
14,
24055,
342,
1039,
291,
14,
1986,
9602,
14,
1084,
4314,
360,
9602,
358,
1039,
291,
14,
7414,
2540,
14,
3162,
342,
2958,
347,
6763,
30851,
8,
277,
12,
1566,
304,
1039,
291,
14,
22478,
275,
715,
2958,
347,
16282,
1123,
28944,
8,
277,
12,
730,
12,
1215,
17,
12,
1215,
18,
304,
1039,
730,
1296,
275,
788,
1562,
297,
283,
585,
297,
283,
521,
418,
1039,
730,
17846,
275,
730,
14,
2325,
342,
1039,
340,
730,
17846,
315,
730,
1296,
26,
1675,
340,
730,
17846,
508,
283,
521,
356,
2628,
13292,
3259,
275,
291,
14,
1123,
28944,
48,
6903,
2175,
1366,
8,
635,
17,
12,
1215,
18,
9,
2628,
340,
13292,
3259,
365,
440,
756,
26,
4906,
17944,
275,
22535,
1403,
14,
28944,
48,
6903,
2175,
1366,
8,
10913,
3259,
12,
1215,
17,
12,
1215,
18,
9,
4906,
291,
14,
4785,
3438,
14,
740,
8,
20081,
9,
4906,
291,
14,
513,
3532,
13948,
3438,
14,
8310,
8,
20081,
14,
16695,
1012,
1675,
916,
730,
17846,
508,
283,
1562,
356,
2628,
13292,
3259,
275,
291,
14,
1123,
28944,
48,
6903,
2175,
1476,
8,
635,
17,
9,
2628,
340,
13292,
3259,
365,
440,
756,
26,
4906,
17944,
275,
22535,
1403,
14,
28944,
48,
6903,
2175,
1476,
8,
10913,
3259,
12,
1215,
17,
9,
4906,
291,
14,
4785,
3438,
14,
740,
8,
20081,
9,
4906,
291,
14,
513,
3532,
13948,
3438,
14,
8310,
8,
20081,
14,
16695,
1012,
1675,
916,
730,
17846,
508,
283,
585,
356,
2628,
13292,
3259,
275,
291,
14,
1123,
28944,
48,
6903,
2175,
1110,
8,
635,
17,
12,
1215,
18,
9,
2628,
340,
13292,
3259,
365,
440,
756,
26,
4906,
17944,
275,
22535,
1403,
14,
28944,
48,
6903,
2175,
1110,
8,
10913,
3259,
12,
1215,
17,
12,
1215,
18,
9,
4906,
291,
14,
4785,
3438,
14,
740,
8,
20081,
9,
4906,
291,
14,
513,
3532,
13948,
3438,
14,
8310,
8,
20081,
14,
16695,
1012,
1675,
372,
715,
1039,
587,
26,
1675,
372,
756,
2958,
347,
6763,
5392,
28944,
8,
277,
12,
1566,
304,
1039,
13680,
275,
291,
14,
513,
3532,
13948,
3438,
14,
1002,
7713,
342,
1039,
340,
8,
5891,
2356,
378,
304,
1675,
19406,
275,
4818,
14,
2209,
5619,
8,
1708,
29,
403,
12,
1245,
628,
17683,
1265,
3238,
1265,
2934,
370,
3145,
652,
15583,
19038,
628,
16778,
401,
202,
3521,
3449,
29,
6323,
14,
15641,
63,
2826,
1204,
4818,
14,
15903,
63,
2328,
19212,
9,
1675,
754,
275,
19406,
14,
6824,
23689,
342,
1675,
340,
754,
508,
4818,
14,
998,
63,
15641,
26,
2628,
1478,
275,
291,
14,
513,
3532,
13948,
3438,
14,
1002,
7713,
342,
2628,
1059,
275,
291,
14,
513,
3532,
13948,
3438,
14,
1002,
1558,
7713,
342,
2628,
13292,
3259,
275,
446,
17,
2628,
367,
6193,
315,
291,
14,
4785,
3438,
26,
4906,
340,
6193,
14,
16695,
342,
508,
1059,
26,
8282,
13292,
3259,
275,
6193,
14,
20081,
3259,
8282,
291,
14,
513,
3532,
13948,
3438,
14,
5392,
8,
1080,
9,
8282,
291,
14,
4785,
3438,
14,
2168,
8,
6086,
9,
2628,
291,
14,
5392,
28944,
8,
10913,
3259,
9,
2628,
986,
1675,
587,
26,
2628,
986,
1675,
19406,
14,
14704,
342,
1039,
327,
277,
14,
513,
3532,
13948,
3438,
14,
5392,
342,
2958,
347,
485,
28500,
1271,
8,
277,
12,
1329,
304,
1039,
1059,
275,
283,
403,
7,
1039,
367,
6193,
315,
291,
14,
4785,
3438,
26,
1675,
340,
6193,
14,
20081,
3259,
508,
1329,
26,
2628,
1059,
275,
6193,
14,
16695,
342,
1039,
291,
14,
1986,
9602,
14,
1084,
4314,
360,
28500,
737,
26,
469,
875,
26,
83,
5285,
908,
3682,
9350,
4059,
2958,
347,
6763,
7929,
24055,
8,
277,
12,
1566,
304,
1039,
1329,
275,
291,
14,
497,
4583,
342,
1039,
340,
1329,
365,
440,
756,
26,
1675,
340,
1329,
508,
298,
3170,
582,
2628,
291,
14,
1986,
9602,
14,
1084,
4314,
360,
3170,
358,
1675,
587,
26,
2628,
291,
423,
28500,
1271,
8,
1955,
9,
2628,
291,
14,
7414,
24055,
14,
6293,
342,
2958,
347,
6763,
7929,
2540,
8,
277,
12,
1566,
304,
1039,
1329,
275,
291,
14,
497,
4583,
342,
1039,
340,
1329,
365,
440,
756,
26,
1675,
340,
1329,
508,
298,
3170,
582,
2628,
291,
14,
1986,
9602,
14,
1084,
4314,
360,
3170,
358,
1675,
587,
26,
2628,
340,
440,
291,
14,
22478,
26,
4906,
291,
14,
24055,
342,
2628,
587,
26,
4906,
291,
423,
28500,
1271,
8,
1955,
9,
4906,
291,
14,
7414,
2540,
14,
6293,
342,
18801,
347,
6763,
4152,
1244,
50,
8,
277,
12,
1566
] |
[
4818,
2999,
199,
646,
22535,
1403,
202,
199,
646,
14245,
836,
202,
199,
646,
30631,
1123,
28944,
202,
199,
646,
17160,
8065,
199,
533,
510,
6903,
31521,
3160,
8,
14438,
14,
6756,
3160,
12,
14245,
836,
14,
31521,
304,
1128,
327,
1880,
1128,
347,
636,
826,
721,
277,
12,
1676,
304,
1039,
17160,
14,
6756,
3160,
855,
826,
721,
277,
12,
1676,
9,
1039,
14245,
836,
14,
31521,
855,
826,
721,
277,
9,
1039,
291,
14,
525,
28944,
3160,
275,
488,
1039,
291,
14,
4785,
3438,
275,
942,
1039,
291,
14,
22478,
275,
756,
1039,
291,
14,
2390,
8631,
8,
403,
9,
2958,
347,
636,
2264,
721,
277,
304,
1039,
291,
14,
2390,
16761,
8,
403,
9,
2958,
347,
6763,
8631,
8,
277,
12,
1566,
304,
1039,
340,
440,
291,
423,
7113,
26,
1675,
291,
14,
8631,
1378,
31521,
342,
1675,
291,
14,
1986,
1872,
3225,
14,
1084,
4314,
480,
16382,
531,
2958,
347,
6763,
16761,
8,
277,
12,
1566,
304,
1039,
340,
291,
423,
7113,
26,
1675,
291,
14,
24145,
342,
1675,
291,
14,
1986,
1872,
3225,
14,
1084,
4314,
480,
2825,
7113,
531,
2958,
347,
6763,
1123,
28944,
8,
277,
12,
1566,
304,
1039,
340,
440,
291,
14,
525,
28944,
3160,
26,
1675,
291,
14,
525,
28944,
3160,
275,
30631,
1123,
28944,
14,
5619,
1123,
28944,
8,
277,
9,
1039,
291,
14,
525,
28944,
3160,
14,
6824,
8,
549,
9,
2958,
347,
6763,
24055,
8,
277,
12,
1566,
304,
1039,
291,
14,
24055,
342,
1039,
291,
14,
1986,
9602,
14,
1084,
4314,
360,
9602,
358,
1039,
291,
14,
7414,
24055,
14,
3162,
342,
2958,
347,
6763,
2540,
8,
277,
12,
1566,
304,
1039,
291,
14,
22478,
275,
756,
1039,
291,
14,
24055,
342,
1039,
291,
14,
1986,
9602,
14,
1084,
4314,
360,
9602,
358,
1039,
291,
14,
7414,
2540,
14,
3162,
342,
2958,
347,
6763,
30851,
8,
277,
12,
1566,
304,
1039,
291,
14,
22478,
275,
715,
2958,
347,
16282,
1123,
28944,
8,
277,
12,
730,
12,
1215,
17,
12,
1215,
18,
304,
1039,
730,
1296,
275,
788,
1562,
297,
283,
585,
297,
283,
521,
418,
1039,
730,
17846,
275,
730,
14,
2325,
342,
1039,
340,
730,
17846,
315,
730,
1296,
26,
1675,
340,
730,
17846,
508,
283,
521,
356,
2628,
13292,
3259,
275,
291,
14,
1123,
28944,
48,
6903,
2175,
1366,
8,
635,
17,
12,
1215,
18,
9,
2628,
340,
13292,
3259,
365,
440,
756,
26,
4906,
17944,
275,
22535,
1403,
14,
28944,
48,
6903,
2175,
1366,
8,
10913,
3259,
12,
1215,
17,
12,
1215,
18,
9,
4906,
291,
14,
4785,
3438,
14,
740,
8,
20081,
9,
4906,
291,
14,
513,
3532,
13948,
3438,
14,
8310,
8,
20081,
14,
16695,
1012,
1675,
916,
730,
17846,
508,
283,
1562,
356,
2628,
13292,
3259,
275,
291,
14,
1123,
28944,
48,
6903,
2175,
1476,
8,
635,
17,
9,
2628,
340,
13292,
3259,
365,
440,
756,
26,
4906,
17944,
275,
22535,
1403,
14,
28944,
48,
6903,
2175,
1476,
8,
10913,
3259,
12,
1215,
17,
9,
4906,
291,
14,
4785,
3438,
14,
740,
8,
20081,
9,
4906,
291,
14,
513,
3532,
13948,
3438,
14,
8310,
8,
20081,
14,
16695,
1012,
1675,
916,
730,
17846,
508,
283,
585,
356,
2628,
13292,
3259,
275,
291,
14,
1123,
28944,
48,
6903,
2175,
1110,
8,
635,
17,
12,
1215,
18,
9,
2628,
340,
13292,
3259,
365,
440,
756,
26,
4906,
17944,
275,
22535,
1403,
14,
28944,
48,
6903,
2175,
1110,
8,
10913,
3259,
12,
1215,
17,
12,
1215,
18,
9,
4906,
291,
14,
4785,
3438,
14,
740,
8,
20081,
9,
4906,
291,
14,
513,
3532,
13948,
3438,
14,
8310,
8,
20081,
14,
16695,
1012,
1675,
372,
715,
1039,
587,
26,
1675,
372,
756,
2958,
347,
6763,
5392,
28944,
8,
277,
12,
1566,
304,
1039,
13680,
275,
291,
14,
513,
3532,
13948,
3438,
14,
1002,
7713,
342,
1039,
340,
8,
5891,
2356,
378,
304,
1675,
19406,
275,
4818,
14,
2209,
5619,
8,
1708,
29,
403,
12,
1245,
628,
17683,
1265,
3238,
1265,
2934,
370,
3145,
652,
15583,
19038,
628,
16778,
401,
202,
3521,
3449,
29,
6323,
14,
15641,
63,
2826,
1204,
4818,
14,
15903,
63,
2328,
19212,
9,
1675,
754,
275,
19406,
14,
6824,
23689,
342,
1675,
340,
754,
508,
4818,
14,
998,
63,
15641,
26,
2628,
1478,
275,
291,
14,
513,
3532,
13948,
3438,
14,
1002,
7713,
342,
2628,
1059,
275,
291,
14,
513,
3532,
13948,
3438,
14,
1002,
1558,
7713,
342,
2628,
13292,
3259,
275,
446,
17,
2628,
367,
6193,
315,
291,
14,
4785,
3438,
26,
4906,
340,
6193,
14,
16695,
342,
508,
1059,
26,
8282,
13292,
3259,
275,
6193,
14,
20081,
3259,
8282,
291,
14,
513,
3532,
13948,
3438,
14,
5392,
8,
1080,
9,
8282,
291,
14,
4785,
3438,
14,
2168,
8,
6086,
9,
2628,
291,
14,
5392,
28944,
8,
10913,
3259,
9,
2628,
986,
1675,
587,
26,
2628,
986,
1675,
19406,
14,
14704,
342,
1039,
327,
277,
14,
513,
3532,
13948,
3438,
14,
5392,
342,
2958,
347,
485,
28500,
1271,
8,
277,
12,
1329,
304,
1039,
1059,
275,
283,
403,
7,
1039,
367,
6193,
315,
291,
14,
4785,
3438,
26,
1675,
340,
6193,
14,
20081,
3259,
508,
1329,
26,
2628,
1059,
275,
6193,
14,
16695,
342,
1039,
291,
14,
1986,
9602,
14,
1084,
4314,
360,
28500,
737,
26,
469,
875,
26,
83,
5285,
908,
3682,
9350,
4059,
2958,
347,
6763,
7929,
24055,
8,
277,
12,
1566,
304,
1039,
1329,
275,
291,
14,
497,
4583,
342,
1039,
340,
1329,
365,
440,
756,
26,
1675,
340,
1329,
508,
298,
3170,
582,
2628,
291,
14,
1986,
9602,
14,
1084,
4314,
360,
3170,
358,
1675,
587,
26,
2628,
291,
423,
28500,
1271,
8,
1955,
9,
2628,
291,
14,
7414,
24055,
14,
6293,
342,
2958,
347,
6763,
7929,
2540,
8,
277,
12,
1566,
304,
1039,
1329,
275,
291,
14,
497,
4583,
342,
1039,
340,
1329,
365,
440,
756,
26,
1675,
340,
1329,
508,
298,
3170,
582,
2628,
291,
14,
1986,
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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
] |
cjdelisle/cjdns
|
node_build/dependencies/libuv/build/gyp/pylib/gyp/common_test.py
|
13
|
2021
|
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unit tests for the common.py file."""
import gyp.common
import unittest
import sys
class TestTopologicallySorted(unittest.TestCase):
def test_Valid(self):
"""Test that sorting works on a valid graph with one possible order."""
graph = {
'a': ['b', 'c'],
'b': [],
'c': ['d'],
'd': ['b'],
}
def GetEdge(node):
return tuple(graph[node])
self.assertEqual(
gyp.common.TopologicallySorted(graph.keys(), GetEdge),
['a', 'c', 'd', 'b'])
def test_Cycle(self):
"""Test that an exception is thrown on a cyclic graph."""
graph = {
'a': ['b'],
'b': ['c'],
'c': ['d'],
'd': ['a'],
}
def GetEdge(node):
return tuple(graph[node])
self.assertRaises(
gyp.common.CycleError, gyp.common.TopologicallySorted,
graph.keys(), GetEdge)
class TestGetFlavor(unittest.TestCase):
"""Test that gyp.common.GetFlavor works as intended"""
original_platform = ''
def setUp(self):
self.original_platform = sys.platform
def tearDown(self):
sys.platform = self.original_platform
def assertFlavor(self, expected, argument, param):
sys.platform = argument
self.assertEqual(expected, gyp.common.GetFlavor(param))
def test_platform_default(self):
self.assertFlavor('freebsd', 'freebsd9' , {})
self.assertFlavor('freebsd', 'freebsd10', {})
self.assertFlavor('openbsd', 'openbsd5' , {})
self.assertFlavor('solaris', 'sunos5' , {});
self.assertFlavor('solaris', 'sunos' , {});
self.assertFlavor('linux' , 'linux2' , {});
self.assertFlavor('linux' , 'linux3' , {});
self.assertFlavor('linux' , 'linux' , {});
def test_param(self):
self.assertFlavor('foobar', 'linux2' , {'flavor': 'foobar'})
if __name__ == '__main__':
unittest.main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
5072,
2295,
367,
314,
2863,
14,
647,
570,
1041,
199,
199,
646,
4902,
14,
2330,
199,
646,
2882,
199,
646,
984,
421,
199,
533,
1379,
6105,
79,
793,
7288,
22861,
8,
2796,
14,
1746,
304,
523,
347,
511,
63,
3490,
8,
277,
304,
272,
408,
774,
626,
13351,
5419,
641,
282,
1686,
3343,
543,
1373,
3962,
1865,
1041,
272,
3343,
275,
469,
267,
283,
65,
356,
788,
66,
297,
283,
67,
995,
267,
283,
66,
356,
990,
267,
283,
67,
356,
788,
68,
995,
267,
283,
68,
356,
788,
66,
995,
267,
789,
272,
347,
2372,
12886,
8,
932,
304,
489,
372,
2008,
8,
2180,
59,
932,
566,
272,
291,
14,
629,
8,
489,
4902,
14,
2330,
14,
6105,
79,
793,
7288,
22861,
8,
2180,
14,
1612,
1062,
2372,
12886,
395,
489,
788,
65,
297,
283,
67,
297,
283,
68,
297,
283,
66,
1105,
819,
347,
511,
63,
15302,
8,
277,
304,
272,
408,
774,
626,
376,
1919,
365,
14031,
641,
282,
32637,
3343,
1041,
272,
3343,
275,
469,
267,
283,
65,
356,
788,
66,
995,
267,
283,
66,
356,
788,
67,
995,
267,
283,
67,
356,
788,
68,
995,
267,
283,
68,
356,
788,
65,
995,
267,
789,
272,
347,
2372,
12886,
8,
932,
304,
489,
372,
2008,
8,
2180,
59,
932,
566,
272,
291,
14,
1855,
8,
489,
4902,
14,
2330,
14,
15302,
547,
12,
4902,
14,
2330,
14,
6105,
79,
793,
7288,
22861,
12,
489,
3343,
14,
1612,
1062,
2372,
12886,
9,
421,
199,
533,
1379,
1002,
16739,
8,
2796,
14,
1746,
304,
523,
408,
774,
626,
4902,
14,
2330,
14,
1002,
16739,
5419,
465,
11619,
624,
523,
3379,
63,
3246,
275,
2125,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
5043,
63,
3246,
275,
984,
14,
3246,
819,
347,
6766,
8,
277,
304,
272,
984,
14,
3246,
275,
291,
14,
5043,
63,
3246,
819,
347,
702,
16739,
8,
277,
12,
1420,
12,
1423,
12,
1215,
304,
272,
984,
14,
3246,
275,
1423,
272,
291,
14,
629,
8,
2062,
12,
4902,
14,
2330,
14,
1002,
16739,
8,
635,
430,
819,
347,
511,
63,
3246,
63,
885,
8,
277,
304,
272,
291,
14,
479,
16739,
360,
29629,
297,
283,
29629,
25,
7,
2360,
5009,
272,
291,
14,
479,
16739,
360,
29629,
297,
283,
29629,
709,
297,
5009,
272,
291,
14,
479,
16739,
360,
1490,
15746,
297,
283,
1490,
15746,
21,
7,
2360,
5009,
272,
291,
14,
479,
16739,
360,
7873,
4663,
297,
283,
11846,
736,
21,
7,
257,
2360,
1052,
2736,
272,
291,
14,
479,
16739,
360,
7873,
4663,
297,
283,
11846,
736,
7,
259,
2360,
1052,
2736,
272,
291,
14,
479,
16739,
360,
5135,
7,
221,
2360,
283,
5135,
18,
7,
257,
2360,
1052,
2736,
272,
291,
14,
479,
16739,
360,
5135,
7,
221,
2360,
283,
5135,
19,
7,
257,
2360,
1052,
2736,
272,
291,
14,
479,
16739,
360,
5135,
7,
221,
2360,
283,
5135,
7,
259,
2360,
1052,
2736,
819,
347,
511,
63,
635,
8,
277,
304,
272,
291,
14,
479,
16739,
360,
9664,
297,
283,
5135,
18,
7,
2360,
791,
6081,
356,
283,
9664,
3071,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
5072,
2295,
367,
314,
2863,
14,
647,
570,
1041,
199,
199,
646,
4902,
14,
2330,
199,
646,
2882,
199,
646,
984,
421,
199,
533,
1379,
6105,
79,
793,
7288,
22861,
8,
2796,
14,
1746,
304,
523,
347,
511,
63,
3490,
8,
277,
304,
272,
408,
774,
626,
13351,
5419,
641,
282,
1686,
3343,
543,
1373,
3962,
1865,
1041,
272,
3343,
275,
469,
267,
283,
65,
356,
788,
66,
297,
283,
67,
995,
267,
283,
66,
356,
990,
267,
283,
67,
356,
788,
68,
995,
267,
283,
68,
356,
788,
66,
995,
267,
789,
272,
347,
2372,
12886,
8,
932,
304,
489,
372,
2008,
8,
2180,
59,
932,
566,
272,
291,
14,
629,
8,
489,
4902,
14,
2330,
14,
6105,
79,
793,
7288,
22861,
8,
2180,
14,
1612,
1062,
2372,
12886,
395,
489,
788,
65,
297,
283,
67,
297,
283,
68,
297,
283,
66,
1105,
819,
347,
511,
63,
15302,
8,
277,
304,
272,
408,
774,
626,
376,
1919,
365,
14031,
641,
282,
32637,
3343,
1041,
272,
3343,
275,
469,
267,
283,
65,
356,
788,
66,
995,
267,
283,
66,
356,
788,
67,
995,
267,
283,
67,
356,
788,
68,
995,
267,
283,
68,
356,
788,
65,
995,
267,
789,
272,
347,
2372,
12886,
8,
932,
304,
489,
372,
2008,
8,
2180,
59,
932,
566,
272,
291,
14,
1855,
8,
489,
4902,
14,
2330,
14,
15302,
547,
12,
4902,
14,
2330,
14,
6105,
79,
793,
7288,
22861,
12,
489,
3343,
14,
1612,
1062,
2372,
12886,
9,
421,
199,
533,
1379,
1002,
16739,
8,
2796,
14,
1746,
304,
523,
408,
774,
626,
4902,
14,
2330,
14,
1002,
16739,
5419,
465,
11619,
624,
523,
3379,
63,
3246,
275,
2125,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
5043,
63,
3246,
275,
984,
14,
3246,
819,
347,
6766,
8,
277,
304,
272,
984,
14,
3246,
275,
291,
14,
5043,
63,
3246,
819,
347,
702,
16739,
8,
277,
12,
1420,
12,
1423,
12,
1215,
304,
272,
984,
14,
3246,
275,
1423,
272,
291,
14,
629,
8,
2062,
12,
4902,
14,
2330,
14,
1002,
16739,
8,
635,
430,
819,
347,
511,
63,
3246,
63,
885,
8,
277,
304,
272,
291,
14,
479,
16739,
360,
29629,
297,
283,
29629,
25,
7,
2360,
5009,
272,
291,
14,
479,
16739,
360,
29629,
297,
283,
29629,
709,
297,
5009,
272,
291,
14,
479,
16739,
360,
1490,
15746,
297,
283,
1490,
15746,
21,
7,
2360,
5009,
272,
291,
14,
479,
16739,
360,
7873,
4663,
297,
283,
11846,
736,
21,
7,
257,
2360,
1052,
2736,
272,
291,
14,
479,
16739,
360,
7873,
4663,
297,
283,
11846,
736,
7,
259,
2360,
1052,
2736,
272,
291,
14,
479,
16739,
360,
5135,
7,
221,
2360,
283,
5135,
18,
7,
257,
2360,
1052,
2736,
272,
291,
14,
479,
16739,
360,
5135,
7,
221,
2360,
283,
5135,
19,
7,
257,
2360,
1052,
2736,
272,
291,
14,
479,
16739,
360,
5135,
7,
221,
2360,
283,
5135,
7,
259,
2360,
1052,
2736,
819,
347,
511,
63,
635,
8,
277,
304,
272,
291,
14,
479,
16739,
360,
9664,
297,
283,
5135,
18,
7,
2360,
791,
6081,
356,
283,
9664,
3071,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
steventimberman/masterDebater
|
env/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/contrib/ntlmpool.py
|
514
|
4531
|
"""
NTLM authenticating pool, contributed by erikcederstran
Issue #10, see: http://code.google.com/p/urllib3/issues/detail?id=10
"""
from __future__ import absolute_import
try:
from http.client import HTTPSConnection
except ImportError:
from httplib import HTTPSConnection
from logging import getLogger
from ntlm import ntlm
from urllib3 import HTTPSConnectionPool
log = getLogger(__name__)
class NTLMConnectionPool(HTTPSConnectionPool):
"""
Implements an NTLM authentication version of an urllib3 connection pool
"""
scheme = 'https'
def __init__(self, user, pw, authurl, *args, **kwargs):
"""
authurl is a random URL on the server that is protected by NTLM.
user is the Windows user, probably in the DOMAIN\\username format.
pw is the password for the user.
"""
super(NTLMConnectionPool, self).__init__(*args, **kwargs)
self.authurl = authurl
self.rawuser = user
user_parts = user.split('\\', 1)
self.domain = user_parts[0].upper()
self.user = user_parts[1]
self.pw = pw
def _new_conn(self):
# Performs the NTLM handshake that secures the connection. The socket
# must be kept open while requests are performed.
self.num_connections += 1
log.debug('Starting NTLM HTTPS connection no. %d: https://%s%s',
self.num_connections, self.host, self.authurl)
headers = {}
headers['Connection'] = 'Keep-Alive'
req_header = 'Authorization'
resp_header = 'www-authenticate'
conn = HTTPSConnection(host=self.host, port=self.port)
# Send negotiation message
headers[req_header] = (
'NTLM %s' % ntlm.create_NTLM_NEGOTIATE_MESSAGE(self.rawuser))
log.debug('Request headers: %s', headers)
conn.request('GET', self.authurl, None, headers)
res = conn.getresponse()
reshdr = dict(res.getheaders())
log.debug('Response status: %s %s', res.status, res.reason)
log.debug('Response headers: %s', reshdr)
log.debug('Response data: %s [...]', res.read(100))
# Remove the reference to the socket, so that it can not be closed by
# the response object (we want to keep the socket open)
res.fp = None
# Server should respond with a challenge message
auth_header_values = reshdr[resp_header].split(', ')
auth_header_value = None
for s in auth_header_values:
if s[:5] == 'NTLM ':
auth_header_value = s[5:]
if auth_header_value is None:
raise Exception('Unexpected %s response header: %s' %
(resp_header, reshdr[resp_header]))
# Send authentication message
ServerChallenge, NegotiateFlags = \
ntlm.parse_NTLM_CHALLENGE_MESSAGE(auth_header_value)
auth_msg = ntlm.create_NTLM_AUTHENTICATE_MESSAGE(ServerChallenge,
self.user,
self.domain,
self.pw,
NegotiateFlags)
headers[req_header] = 'NTLM %s' % auth_msg
log.debug('Request headers: %s', headers)
conn.request('GET', self.authurl, None, headers)
res = conn.getresponse()
log.debug('Response status: %s %s', res.status, res.reason)
log.debug('Response headers: %s', dict(res.getheaders()))
log.debug('Response data: %s [...]', res.read()[:100])
if res.status != 200:
if res.status == 401:
raise Exception('Server rejected request: wrong '
'username or password')
raise Exception('Wrong server response: %s %s' %
(res.status, res.reason))
res.fp = None
log.debug('Connection established')
return conn
def urlopen(self, method, url, body=None, headers=None, retries=3,
redirect=True, assert_same_host=True):
if headers is None:
headers = {}
headers['Connection'] = 'Keep-Alive'
return super(NTLMConnectionPool, self).urlopen(method, url, body,
headers, retries,
redirect,
assert_same_host)
|
mit
|
[
624,
199,
46,
25112,
28532,
1958,
4203,
12,
406,
24855,
701,
9266,
3258,
301,
424,
495,
290,
199,
199,
17106,
327,
709,
12,
1937,
26,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
4078,
19,
15,
10115,
15,
5506,
31,
344,
29,
709,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
893,
26,
272,
687,
1455,
14,
1258,
492,
14147,
3225,
199,
2590,
3545,
26,
272,
687,
8809,
492,
14147,
3225,
199,
504,
2050,
492,
28138,
199,
504,
302,
5019,
77,
492,
302,
5019,
77,
199,
199,
504,
4011,
19,
492,
14147,
23929,
421,
199,
793,
275,
28138,
3460,
354,
3368,
421,
199,
533,
653,
25112,
23929,
8,
14921,
23929,
304,
272,
408,
272,
24664,
376,
653,
25112,
6299,
1015,
402,
376,
4011,
19,
1950,
4203,
272,
408,
339,
5687,
275,
283,
2859,
7,
339,
347,
636,
826,
721,
277,
12,
922,
12,
19206,
12,
1790,
633,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
1790,
633,
365,
282,
2196,
2851,
641,
314,
1654,
626,
365,
17819,
701,
653,
25112,
14,
267,
922,
365,
314,
5417,
922,
12,
8646,
315,
314,
15265,
1103,
2473,
1475,
14,
267,
19206,
365,
314,
2505,
367,
314,
922,
14,
267,
408,
267,
1613,
8,
46,
25112,
23929,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
1178,
633,
275,
1790,
633,
267,
291,
14,
1773,
751,
275,
922,
267,
922,
63,
4181,
275,
922,
14,
1294,
20786,
413,
9,
267,
291,
14,
2261,
275,
922,
63,
4181,
59,
16,
1055,
4142,
342,
267,
291,
14,
751,
275,
922,
63,
4181,
59,
17,
61,
267,
291,
14,
8796,
275,
19206,
339,
347,
485,
1222,
63,
1631,
8,
277,
304,
267,
327,
29822,
314,
653,
25112,
14305,
626,
6513,
1482,
314,
1950,
14,
710,
2838,
267,
327,
1471,
506,
16204,
1551,
1830,
4145,
787,
10585,
14,
267,
291,
14,
1507,
63,
7995,
847,
413,
267,
943,
14,
1757,
360,
14139,
653,
25112,
14147,
1950,
949,
14,
450,
68,
26,
4178,
13827,
83,
5,
83,
297,
2116,
291,
14,
1507,
63,
7995,
12,
291,
14,
1102,
12,
291,
14,
1178,
633,
9,
398,
2323,
275,
1052,
267,
2323,
459,
3225,
418,
275,
283,
18567,
13,
23692,
7,
267,
2648,
63,
1291,
275,
283,
11626,
7,
267,
3085,
63,
1291,
275,
283,
1544,
13,
13975,
7,
398,
2557,
275,
14147,
3225,
8,
1102,
29,
277,
14,
1102,
12,
1844,
29,
277,
14,
719,
9,
398,
327,
10217,
29184,
425,
1245,
267,
2323,
59,
2103,
63,
1291,
61,
275,
334,
288,
283,
46,
25112,
450,
83,
7,
450,
302,
5019,
77,
14,
981,
63,
46,
25112,
63,
31254,
1387,
41,
1951,
63,
8272,
8,
277,
14,
1773,
751,
430,
267,
943,
14,
1757,
360,
2017,
2323,
26,
450,
83,
297,
2323,
9,
267,
2557,
14,
1069,
360,
2970,
297,
291,
14,
1178,
633,
12,
488,
12,
2323,
9,
267,
522,
275,
2557,
14,
25006,
342,
267,
522,
11244,
275,
1211,
8,
470,
14,
19958,
83,
1012,
267,
943,
14,
1757,
360,
2364,
2004,
26,
450,
83,
450,
83,
297,
522,
14,
1205,
12,
522,
14,
5764,
9,
267,
943,
14,
1757,
360,
2364,
2323,
26,
450,
83,
297,
522,
11244,
9,
267,
943,
14,
1757,
360,
2364,
666,
26,
450,
83,
359,
1396,
4300,
522,
14,
739,
8,
1960,
430,
398,
327,
5852,
314,
3659,
370,
314,
2838,
12,
880,
626,
652,
883,
440,
506,
6876,
701,
267,
327,
314,
1177,
909,
334,
1129,
2934,
370,
4215,
314,
2838,
1551,
9,
267,
522,
14,
3997,
275,
488,
398,
327,
7146,
1077,
22722,
543,
282,
14929,
1245,
267,
1790,
63,
1291,
63,
1459,
275,
522,
11244,
59,
4518,
63,
1291,
1055,
1294,
5102,
5320,
267,
1790,
63,
1291,
63,
585,
275,
488,
267,
367,
308,
315,
1790,
63,
1291,
63,
1459,
26,
288,
340,
308,
1491,
21,
61,
508,
283,
46,
25112,
7596,
355,
1790,
63,
1291,
63,
585,
275,
308,
59,
21,
2938,
267,
340,
1790,
63,
1291,
63,
585,
365,
488,
26,
288,
746,
2186,
360,
8708,
450,
83,
1177,
1406,
26,
450,
83,
7,
450,
1169,
334,
4518,
63,
1291,
12,
522,
11244,
59,
4518,
63,
1291,
2459,
398,
327,
10217,
6299,
1245,
267,
7146,
30531,
12,
5612,
14727,
323,
6381,
275,
971,
288,
302,
5019,
77,
14,
1122,
63,
46,
25112,
63,
1244,
1761,
742,
4962,
63,
8272,
8,
1178,
63,
1291,
63,
585,
9,
267,
1790,
63,
1328,
275,
302,
5019,
77,
14,
981,
63,
46,
25112,
63,
22923,
1951,
63,
8272,
8,
3120,
30531,
12,
12740,
291,
14,
751,
12,
12740,
291,
14,
2261,
12,
12740,
291,
14,
8796,
12,
12740,
5612,
14727,
323,
6381,
9,
267,
2323,
59,
2103,
63,
1291,
61,
275,
283,
46,
25112,
450,
83,
7,
450,
1790,
63,
1328,
267,
943,
14,
1757,
360,
2017,
2323,
26,
450,
83,
297,
2323,
9,
267,
2557,
14,
1069,
360,
2970,
297,
291,
14,
1178,
633,
12,
488,
12,
2323,
9,
267,
522,
275,
2557,
14,
25006,
342,
267,
943,
14,
1757,
360,
2364,
2004,
26,
450,
83,
450,
83,
297,
522,
14,
1205,
12,
522,
14,
5764,
9,
267,
943,
14,
1757,
360,
2364,
2323,
26,
450,
83,
297,
1211,
8,
470,
14,
19958,
83,
4059,
267,
943,
14,
1757,
360,
2364,
666,
26,
450,
83,
359,
1396,
4300,
522,
14,
739,
20523,
1960,
566,
267,
340,
522,
14,
1205,
1137,
1926,
26,
288,
340,
522,
14,
1205,
508,
13952,
26,
355,
746,
2186,
360,
3120,
18935,
1056,
26,
6835,
283,
1816,
283,
2473,
503,
2505,
358,
288,
746,
2186,
360,
14858,
1654,
1177,
26,
450,
83,
450,
83,
7,
450,
1169,
334,
470,
14,
1205,
12,
522,
14,
5764,
430,
398,
522,
14,
3997,
275,
488,
267,
943,
14,
1757,
360,
3225,
23594,
358,
267,
372,
2557,
339,
347,
18279,
8,
277,
12,
1083,
12,
1166,
12,
2396,
29,
403,
12,
2323,
29,
403,
12,
10086,
29,
19,
12,
355,
4660,
29,
549,
12,
702,
63,
7191,
63,
1102,
29,
549,
304,
267,
340,
2323,
365,
488,
26,
288,
2323,
275,
1052,
267,
2323,
459,
3225,
418,
275,
283,
18567,
13,
23692,
7,
267,
372,
1613,
8,
46,
25112,
23929,
12
] |
[
199,
46,
25112,
28532,
1958,
4203,
12,
406,
24855,
701,
9266,
3258,
301,
424,
495,
290,
199,
199,
17106,
327,
709,
12,
1937,
26,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
4078,
19,
15,
10115,
15,
5506,
31,
344,
29,
709,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
893,
26,
272,
687,
1455,
14,
1258,
492,
14147,
3225,
199,
2590,
3545,
26,
272,
687,
8809,
492,
14147,
3225,
199,
504,
2050,
492,
28138,
199,
504,
302,
5019,
77,
492,
302,
5019,
77,
199,
199,
504,
4011,
19,
492,
14147,
23929,
421,
199,
793,
275,
28138,
3460,
354,
3368,
421,
199,
533,
653,
25112,
23929,
8,
14921,
23929,
304,
272,
408,
272,
24664,
376,
653,
25112,
6299,
1015,
402,
376,
4011,
19,
1950,
4203,
272,
408,
339,
5687,
275,
283,
2859,
7,
339,
347,
636,
826,
721,
277,
12,
922,
12,
19206,
12,
1790,
633,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
1790,
633,
365,
282,
2196,
2851,
641,
314,
1654,
626,
365,
17819,
701,
653,
25112,
14,
267,
922,
365,
314,
5417,
922,
12,
8646,
315,
314,
15265,
1103,
2473,
1475,
14,
267,
19206,
365,
314,
2505,
367,
314,
922,
14,
267,
408,
267,
1613,
8,
46,
25112,
23929,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
1178,
633,
275,
1790,
633,
267,
291,
14,
1773,
751,
275,
922,
267,
922,
63,
4181,
275,
922,
14,
1294,
20786,
413,
9,
267,
291,
14,
2261,
275,
922,
63,
4181,
59,
16,
1055,
4142,
342,
267,
291,
14,
751,
275,
922,
63,
4181,
59,
17,
61,
267,
291,
14,
8796,
275,
19206,
339,
347,
485,
1222,
63,
1631,
8,
277,
304,
267,
327,
29822,
314,
653,
25112,
14305,
626,
6513,
1482,
314,
1950,
14,
710,
2838,
267,
327,
1471,
506,
16204,
1551,
1830,
4145,
787,
10585,
14,
267,
291,
14,
1507,
63,
7995,
847,
413,
267,
943,
14,
1757,
360,
14139,
653,
25112,
14147,
1950,
949,
14,
450,
68,
26,
4178,
13827,
83,
5,
83,
297,
2116,
291,
14,
1507,
63,
7995,
12,
291,
14,
1102,
12,
291,
14,
1178,
633,
9,
398,
2323,
275,
1052,
267,
2323,
459,
3225,
418,
275,
283,
18567,
13,
23692,
7,
267,
2648,
63,
1291,
275,
283,
11626,
7,
267,
3085,
63,
1291,
275,
283,
1544,
13,
13975,
7,
398,
2557,
275,
14147,
3225,
8,
1102,
29,
277,
14,
1102,
12,
1844,
29,
277,
14,
719,
9,
398,
327,
10217,
29184,
425,
1245,
267,
2323,
59,
2103,
63,
1291,
61,
275,
334,
288,
283,
46,
25112,
450,
83,
7,
450,
302,
5019,
77,
14,
981,
63,
46,
25112,
63,
31254,
1387,
41,
1951,
63,
8272,
8,
277,
14,
1773,
751,
430,
267,
943,
14,
1757,
360,
2017,
2323,
26,
450,
83,
297,
2323,
9,
267,
2557,
14,
1069,
360,
2970,
297,
291,
14,
1178,
633,
12,
488,
12,
2323,
9,
267,
522,
275,
2557,
14,
25006,
342,
267,
522,
11244,
275,
1211,
8,
470,
14,
19958,
83,
1012,
267,
943,
14,
1757,
360,
2364,
2004,
26,
450,
83,
450,
83,
297,
522,
14,
1205,
12,
522,
14,
5764,
9,
267,
943,
14,
1757,
360,
2364,
2323,
26,
450,
83,
297,
522,
11244,
9,
267,
943,
14,
1757,
360,
2364,
666,
26,
450,
83,
359,
1396,
4300,
522,
14,
739,
8,
1960,
430,
398,
327,
5852,
314,
3659,
370,
314,
2838,
12,
880,
626,
652,
883,
440,
506,
6876,
701,
267,
327,
314,
1177,
909,
334,
1129,
2934,
370,
4215,
314,
2838,
1551,
9,
267,
522,
14,
3997,
275,
488,
398,
327,
7146,
1077,
22722,
543,
282,
14929,
1245,
267,
1790,
63,
1291,
63,
1459,
275,
522,
11244,
59,
4518,
63,
1291,
1055,
1294,
5102,
5320,
267,
1790,
63,
1291,
63,
585,
275,
488,
267,
367,
308,
315,
1790,
63,
1291,
63,
1459,
26,
288,
340,
308,
1491,
21,
61,
508,
283,
46,
25112,
7596,
355,
1790,
63,
1291,
63,
585,
275,
308,
59,
21,
2938,
267,
340,
1790,
63,
1291,
63,
585,
365,
488,
26,
288,
746,
2186,
360,
8708,
450,
83,
1177,
1406,
26,
450,
83,
7,
450,
1169,
334,
4518,
63,
1291,
12,
522,
11244,
59,
4518,
63,
1291,
2459,
398,
327,
10217,
6299,
1245,
267,
7146,
30531,
12,
5612,
14727,
323,
6381,
275,
971,
288,
302,
5019,
77,
14,
1122,
63,
46,
25112,
63,
1244,
1761,
742,
4962,
63,
8272,
8,
1178,
63,
1291,
63,
585,
9,
267,
1790,
63,
1328,
275,
302,
5019,
77,
14,
981,
63,
46,
25112,
63,
22923,
1951,
63,
8272,
8,
3120,
30531,
12,
12740,
291,
14,
751,
12,
12740,
291,
14,
2261,
12,
12740,
291,
14,
8796,
12,
12740,
5612,
14727,
323,
6381,
9,
267,
2323,
59,
2103,
63,
1291,
61,
275,
283,
46,
25112,
450,
83,
7,
450,
1790,
63,
1328,
267,
943,
14,
1757,
360,
2017,
2323,
26,
450,
83,
297,
2323,
9,
267,
2557,
14,
1069,
360,
2970,
297,
291,
14,
1178,
633,
12,
488,
12,
2323,
9,
267,
522,
275,
2557,
14,
25006,
342,
267,
943,
14,
1757,
360,
2364,
2004,
26,
450,
83,
450,
83,
297,
522,
14,
1205,
12,
522,
14,
5764,
9,
267,
943,
14,
1757,
360,
2364,
2323,
26,
450,
83,
297,
1211,
8,
470,
14,
19958,
83,
4059,
267,
943,
14,
1757,
360,
2364,
666,
26,
450,
83,
359,
1396,
4300,
522,
14,
739,
20523,
1960,
566,
267,
340,
522,
14,
1205,
1137,
1926,
26,
288,
340,
522,
14,
1205,
508,
13952,
26,
355,
746,
2186,
360,
3120,
18935,
1056,
26,
6835,
283,
1816,
283,
2473,
503,
2505,
358,
288,
746,
2186,
360,
14858,
1654,
1177,
26,
450,
83,
450,
83,
7,
450,
1169,
334,
470,
14,
1205,
12,
522,
14,
5764,
430,
398,
522,
14,
3997,
275,
488,
267,
943,
14,
1757,
360,
3225,
23594,
358,
267,
372,
2557,
339,
347,
18279,
8,
277,
12,
1083,
12,
1166,
12,
2396,
29,
403,
12,
2323,
29,
403,
12,
10086,
29,
19,
12,
355,
4660,
29,
549,
12,
702,
63,
7191,
63,
1102,
29,
549,
304,
267,
340,
2323,
365,
488,
26,
288,
2323,
275,
1052,
267,
2323,
459,
3225,
418,
275,
283,
18567,
13,
23692,
7,
267,
372,
1613,
8,
46,
25112,
23929,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
realsagi/python_koans
|
python2/koans/about_lists.py
|
54
|
2995
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Based on AboutArrays in the Ruby Koans
#
from runner.koan import *
class AboutLists(Koan):
def test_creating_lists(self):
empty_list = list()
self.assertEqual(list, type(empty_list))
self.assertEqual(__, len(empty_list))
def test_list_literals(self):
nums = list()
self.assertEqual([], nums)
nums[0:] = [1]
self.assertEqual([1], nums)
nums[1:] = [2]
self.assertEqual([1, __], nums)
nums.append(333)
self.assertEqual([1, 2, __], nums)
def test_accessing_list_elements(self):
noms = ['peanut', 'butter', 'and', 'jelly']
self.assertEqual(__, noms[0])
self.assertEqual(__, noms[3])
self.assertEqual(__, noms[-1])
self.assertEqual(__, noms[-3])
def test_slicing_lists(self):
noms = ['peanut', 'butter', 'and', 'jelly']
self.assertEqual(__, noms[0:1])
self.assertEqual(__, noms[0:2])
self.assertEqual(__, noms[2:2])
self.assertEqual(__, noms[2:20])
self.assertEqual(__, noms[4:0])
self.assertEqual(__, noms[4:100])
self.assertEqual(__, noms[5:0])
def test_slicing_to_the_edge(self):
noms = ['peanut', 'butter', 'and', 'jelly']
self.assertEqual(__, noms[2:])
self.assertEqual(__, noms[:2])
def test_lists_and_ranges(self):
self.assertEqual(list, type(range(5)))
self.assertEqual(__, range(5))
self.assertEqual(__, range(5, 9))
def test_ranges_with_steps(self):
self.assertEqual(__, range(0, 8, 2))
self.assertEqual(__, range(1, 8, 3))
self.assertEqual(__, range(5, -7, -4))
self.assertEqual(__, range(5, -8, -4))
def test_insertions(self):
knight = ['you', 'shall', 'pass']
knight.insert(2, 'not')
self.assertEqual(__, knight)
knight.insert(0, 'Arthur')
self.assertEqual(__, knight)
def test_popping_lists(self):
stack = [10, 20, 30, 40]
stack.append('last')
self.assertEqual(__, stack)
popped_value = stack.pop()
self.assertEqual(__, popped_value)
self.assertEqual(__, stack)
popped_value = stack.pop(1)
self.assertEqual(__, popped_value)
self.assertEqual(__, stack)
# Notice that there is a "pop" but no "push" in python?
# Part of the Python philosophy is that there ideally should be one and
# only one way of doing anything. A 'push' is the same as an 'append'.
# To learn more about this try typing "import this" from the python
# console... ;)
def test_use_deques_for_making_queues(self):
from collections import deque
queue = deque([1, 2])
queue.append('last')
self.assertEqual(__, list(queue))
popped_value = queue.popleft()
self.assertEqual(__, popped_value)
self.assertEqual(__, list(queue))
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
199,
3,
21311,
641,
25225,
29033,
315,
314,
820,
10972,
1804,
79,
796,
199,
3,
199,
199,
504,
7876,
14,
7697,
290,
492,
627,
421,
199,
533,
25225,
15116,
8,
31305,
290,
304,
272,
347,
511,
63,
20358,
63,
6717,
8,
277,
304,
267,
2701,
63,
513,
275,
769,
342,
267,
291,
14,
629,
8,
513,
12,
730,
8,
1667,
63,
513,
430,
267,
291,
14,
629,
32485,
822,
8,
1667,
63,
513,
430,
339,
347,
511,
63,
513,
63,
5955,
8,
277,
304,
267,
24047,
275,
769,
342,
267,
291,
14,
629,
8798,
24047,
9,
398,
24047,
59,
16,
2938,
275,
359,
17,
61,
267,
291,
14,
629,
779,
17,
467,
24047,
9,
398,
24047,
59,
17,
2938,
275,
359,
18,
61,
267,
291,
14,
629,
779,
17,
12,
636,
467,
24047,
9,
398,
24047,
14,
740,
8,
11769,
9,
267,
291,
14,
629,
779,
17,
12,
499,
12,
636,
467,
24047,
9,
339,
347,
511,
63,
2732,
316,
63,
513,
63,
5527,
8,
277,
304,
267,
17468,
83,
275,
788,
321,
290,
337,
297,
283,
7911,
351,
297,
283,
460,
297,
283,
74,
29051,
418,
398,
291,
14,
629,
32485,
17468,
83,
59,
16,
566,
267,
291,
14,
629,
32485,
17468,
83,
59,
19,
566,
267,
291,
14,
629,
32485,
17468,
83,
1988,
17,
566,
267,
291,
14,
629,
32485,
17468,
83,
1988,
19,
566,
339,
347,
511,
63,
83,
17463,
63,
6717,
8,
277,
304,
267,
17468,
83,
275,
788,
321,
290,
337,
297,
283,
7911,
351,
297,
283,
460,
297,
283,
74,
29051,
418,
398,
291,
14,
629,
32485,
17468,
83,
59,
16,
26,
17,
566,
267,
291,
14,
629,
32485,
17468,
83,
59,
16,
26,
18,
566,
267,
291,
14,
629,
32485,
17468,
83,
59,
18,
26,
18,
566,
267,
291,
14,
629,
32485,
17468,
83,
59,
18,
26,
1165,
566,
267,
291,
14,
629,
32485,
17468,
83,
59,
20,
26,
16,
566,
267,
291,
14,
629,
32485,
17468,
83,
59,
20,
26,
1960,
566,
267,
291,
14,
629,
32485,
17468,
83,
59,
21,
26,
16,
566,
339,
347,
511,
63,
83,
17463,
63,
475,
63,
1589,
63,
5173,
8,
277,
304,
267,
17468,
83,
275,
788,
321,
290,
337,
297,
283,
7911,
351,
297,
283,
460,
297,
283,
74,
29051,
418,
398,
291,
14,
629,
32485,
17468,
83,
59,
18,
5728,
267,
291,
14,
629,
32485,
17468,
83,
1491,
18,
566,
339,
347,
511,
63,
6717,
63,
460,
63,
8404,
8,
277,
304,
267,
291,
14,
629,
8,
513,
12,
730,
8,
1842,
8,
21,
1724,
267,
291,
14,
629,
32485,
1425,
8,
21,
430,
267,
291,
14,
629,
32485,
1425,
8,
21,
12,
1749,
430,
339,
347,
511,
63,
8404,
63,
1045,
63,
5895,
8,
277,
304,
267,
291,
14,
629,
32485,
1425,
8,
16,
12,
1695,
12,
499,
430,
267,
291,
14,
629,
32485,
1425,
8,
17,
12,
1695,
12,
650,
430,
267,
291,
14,
629,
32485,
1425,
8,
21,
12,
446,
23,
12,
446,
20,
430,
267,
291,
14,
629,
32485,
1425,
8,
21,
12,
446,
24,
12,
446,
20,
430,
339,
347,
511,
63,
262,
13049,
8,
277,
304,
267,
1022,
14873,
275,
788,
13297,
297,
283,
609,
452,
297,
283,
1529,
418,
267,
1022,
14873,
14,
3176,
8,
18,
12,
283,
1397,
358,
267,
291,
14,
629,
32485,
1022,
14873,
9,
398,
1022,
14873,
14,
3176,
8,
16,
12,
283,
1596,
273,
300,
358,
267,
291,
14,
629,
32485,
1022,
14873,
9,
339,
347,
511,
63,
1935,
4073,
63,
6717,
8,
277,
304,
267,
3464,
275,
359,
709,
12,
3388,
12,
4233,
12,
6335,
61,
267,
3464,
14,
740,
360,
2019,
358,
398,
291,
14,
629,
32485,
3464,
9,
398,
4560,
1915,
63,
585,
275,
3464,
14,
1935,
342,
267,
291,
14,
629,
32485,
4560,
1915,
63,
585,
9,
267,
291,
14,
629,
32485,
3464,
9,
398,
4560,
1915,
63,
585,
275,
3464,
14,
1935,
8,
17,
9,
267,
291,
14,
629,
32485,
4560,
1915,
63,
585,
9,
267,
291,
14,
629,
32485,
3464,
9,
398,
327,
3091,
3548,
626,
2337,
365,
282,
298,
1935,
2,
1325,
949,
298,
5335,
2,
315,
2366,
31,
398,
327,
14320,
402,
314,
2018,
14524,
11560,
411,
3577,
365,
626,
2337,
9979,
1183,
1077,
506,
1373,
436,
267,
327,
1454,
1373,
4340,
402,
9689,
7003,
14,
437,
283,
5335,
7,
365,
314,
2011,
465,
376,
283,
740,
1370,
398,
327,
4005,
12537,
1655,
3595,
642,
862,
14090,
298,
646,
642,
2,
687,
314,
2366,
267,
327,
8559,
1396,
8700,
9,
339,
347,
511,
63,
1180,
63,
271,
19658,
63,
509,
63,
391,
17443,
63,
18849,
8,
277,
304,
267,
687,
5055,
492,
15782,
398,
4126,
275,
15782,
779,
17,
12,
499,
566,
267,
4126,
14,
740,
360,
2019,
358,
398,
291,
14,
629,
32485,
769,
8,
1825,
430,
398,
4560,
1915,
63,
585,
275,
4126,
14,
25704,
342,
267,
291,
14,
629,
32485,
4560,
1915,
63,
585,
9,
267,
291,
14,
629,
32485,
769,
8,
1825,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
199,
3,
21311,
641,
25225,
29033,
315,
314,
820,
10972,
1804,
79,
796,
199,
3,
199,
199,
504,
7876,
14,
7697,
290,
492,
627,
421,
199,
533,
25225,
15116,
8,
31305,
290,
304,
272,
347,
511,
63,
20358,
63,
6717,
8,
277,
304,
267,
2701,
63,
513,
275,
769,
342,
267,
291,
14,
629,
8,
513,
12,
730,
8,
1667,
63,
513,
430,
267,
291,
14,
629,
32485,
822,
8,
1667,
63,
513,
430,
339,
347,
511,
63,
513,
63,
5955,
8,
277,
304,
267,
24047,
275,
769,
342,
267,
291,
14,
629,
8798,
24047,
9,
398,
24047,
59,
16,
2938,
275,
359,
17,
61,
267,
291,
14,
629,
779,
17,
467,
24047,
9,
398,
24047,
59,
17,
2938,
275,
359,
18,
61,
267,
291,
14,
629,
779,
17,
12,
636,
467,
24047,
9,
398,
24047,
14,
740,
8,
11769,
9,
267,
291,
14,
629,
779,
17,
12,
499,
12,
636,
467,
24047,
9,
339,
347,
511,
63,
2732,
316,
63,
513,
63,
5527,
8,
277,
304,
267,
17468,
83,
275,
788,
321,
290,
337,
297,
283,
7911,
351,
297,
283,
460,
297,
283,
74,
29051,
418,
398,
291,
14,
629,
32485,
17468,
83,
59,
16,
566,
267,
291,
14,
629,
32485,
17468,
83,
59,
19,
566,
267,
291,
14,
629,
32485,
17468,
83,
1988,
17,
566,
267,
291,
14,
629,
32485,
17468,
83,
1988,
19,
566,
339,
347,
511,
63,
83,
17463,
63,
6717,
8,
277,
304,
267,
17468,
83,
275,
788,
321,
290,
337,
297,
283,
7911,
351,
297,
283,
460,
297,
283,
74,
29051,
418,
398,
291,
14,
629,
32485,
17468,
83,
59,
16,
26,
17,
566,
267,
291,
14,
629,
32485,
17468,
83,
59,
16,
26,
18,
566,
267,
291,
14,
629,
32485,
17468,
83,
59,
18,
26,
18,
566,
267,
291,
14,
629,
32485,
17468,
83,
59,
18,
26,
1165,
566,
267,
291,
14,
629,
32485,
17468,
83,
59,
20,
26,
16,
566,
267,
291,
14,
629,
32485,
17468,
83,
59,
20,
26,
1960,
566,
267,
291,
14,
629,
32485,
17468,
83,
59,
21,
26,
16,
566,
339,
347,
511,
63,
83,
17463,
63,
475,
63,
1589,
63,
5173,
8,
277,
304,
267,
17468,
83,
275,
788,
321,
290,
337,
297,
283,
7911,
351,
297,
283,
460,
297,
283,
74,
29051,
418,
398,
291,
14,
629,
32485,
17468,
83,
59,
18,
5728,
267,
291,
14,
629,
32485,
17468,
83,
1491,
18,
566,
339,
347,
511,
63,
6717,
63,
460,
63,
8404,
8,
277,
304,
267,
291,
14,
629,
8,
513,
12,
730,
8,
1842,
8,
21,
1724,
267,
291,
14,
629,
32485,
1425,
8,
21,
430,
267,
291,
14,
629,
32485,
1425,
8,
21,
12,
1749,
430,
339,
347,
511,
63,
8404,
63,
1045,
63,
5895,
8,
277,
304,
267,
291,
14,
629,
32485,
1425,
8,
16,
12,
1695,
12,
499,
430,
267,
291,
14,
629,
32485,
1425,
8,
17,
12,
1695,
12,
650,
430,
267,
291,
14,
629,
32485,
1425,
8,
21,
12,
446,
23,
12,
446,
20,
430,
267,
291,
14,
629,
32485,
1425,
8,
21,
12,
446,
24,
12,
446,
20,
430,
339,
347,
511,
63,
262,
13049,
8,
277,
304,
267,
1022,
14873,
275,
788,
13297,
297,
283,
609,
452,
297,
283,
1529,
418,
267,
1022,
14873,
14,
3176,
8,
18,
12,
283,
1397,
358,
267,
291,
14,
629,
32485,
1022,
14873,
9,
398,
1022,
14873,
14,
3176,
8,
16,
12,
283,
1596,
273,
300,
358,
267,
291,
14,
629,
32485,
1022,
14873,
9,
339,
347,
511,
63,
1935,
4073,
63,
6717,
8,
277,
304,
267,
3464,
275,
359,
709,
12,
3388,
12,
4233,
12,
6335,
61,
267,
3464,
14,
740,
360,
2019,
358,
398,
291,
14,
629,
32485,
3464,
9,
398,
4560,
1915,
63,
585,
275,
3464,
14,
1935,
342,
267,
291,
14,
629,
32485,
4560,
1915,
63,
585,
9,
267,
291,
14,
629,
32485,
3464,
9,
398,
4560,
1915,
63,
585,
275,
3464,
14,
1935,
8,
17,
9,
267,
291,
14,
629,
32485,
4560,
1915,
63,
585,
9,
267,
291,
14,
629,
32485,
3464,
9,
398,
327,
3091,
3548,
626,
2337,
365,
282,
298,
1935,
2,
1325,
949,
298,
5335,
2,
315,
2366,
31,
398,
327,
14320,
402,
314,
2018,
14524,
11560,
411,
3577,
365,
626,
2337,
9979,
1183,
1077,
506,
1373,
436,
267,
327,
1454,
1373,
4340,
402,
9689,
7003,
14,
437,
283,
5335,
7,
365,
314,
2011,
465,
376,
283,
740,
1370,
398,
327,
4005,
12537,
1655,
3595,
642,
862,
14090,
298,
646,
642,
2,
687,
314,
2366,
267,
327,
8559,
1396,
8700,
9,
339,
347,
511,
63,
1180,
63,
271,
19658,
63,
509,
63,
391,
17443,
63,
18849,
8,
277,
304,
267,
687,
5055,
492,
15782,
398,
4126,
275,
15782,
779,
17,
12,
499,
566,
267,
4126,
14,
740,
360,
2019,
358,
398,
291,
14,
629,
32485,
769,
8,
1825,
430,
398,
4560,
1915,
63,
585,
275,
4126,
14,
25704,
342,
267,
291,
14,
629,
32485,
4560,
1915,
63,
585,
9,
267,
291,
14,
629,
32485,
769,
8,
1825,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
fuzeman/trakt.py
|
tests/oauth/test_oauth.py
|
1
|
5552
|
from __future__ import absolute_import, division, print_function
from tests.core import mock
from tests.core.helpers import assert_url
from trakt import Trakt, TraktClient
from httmock import HTTMock
from threading import Event
import calendar
import datetime
import pytest
def test_authorize_url():
Trakt.site_url = 'http://mock'
assert_url(Trakt['oauth'].authorize_url('urn:ietf:wg:oauth:2.0:oob'), '/oauth/authorize', {
'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob',
'response_type': 'code',
'client_id': 'mock-client_id'
})
assert_url(
Trakt['oauth'].authorize_url('urn:ietf:wg:oauth:2.0:oob', state='state', username='username'),
'/oauth/authorize', {
'username': 'username',
'state': 'state',
'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob',
'response_type': 'code',
'client_id': 'mock-client_id'
}
)
with pytest.raises(ValueError):
TraktClient()['oauth'].authorize_url('urn:ietf:wg:oauth:2.0:oob')
def test_pin_url():
with Trakt.configuration.app(id=1234):
assert_url(Trakt['oauth/pin'].url(), '/pin/1234')
with pytest.raises(ValueError):
Trakt['oauth/pin'].url()
def test_token():
with HTTMock(mock.oauth_token, mock.unknown):
# Validate `token_exchange` request/response
assert Trakt['oauth'].token_exchange('ABCD1234', 'urn:ietf:wg:oauth:2.0:oob') == {
'access_token': 'mock-access_token',
'token_type': 'bearer',
'expires_in': 7200,
'refresh_token': 'mock-refresh_token',
'scope': 'public'
}
# Ensure `token_exchange` raises a `ValueError` on incorrect configuration
with pytest.raises(ValueError):
assert TraktClient()['oauth'].token_exchange('ABCD1234', 'urn:ietf:wg:oauth:2.0:oob')
def test_token_exchange():
with HTTMock(mock.oauth_token, mock.unknown):
# Validate `token_exchange` request/response
assert Trakt['oauth'].token_exchange('ABCD1234', 'urn:ietf:wg:oauth:2.0:oob') == {
'access_token': 'mock-access_token',
'token_type': 'bearer',
'expires_in': 7200,
'refresh_token': 'mock-refresh_token',
'scope': 'public'
}
# Ensure `token_exchange` raises a `ValueError` on incorrect configuration
with pytest.raises(ValueError):
assert TraktClient()['oauth'].token_exchange('ABCD1234', 'urn:ietf:wg:oauth:2.0:oob')
def test_token_refresh():
with HTTMock(mock.oauth_token, mock.unknown):
# Validate `token_exchange` request/response
assert Trakt['oauth'].token_refresh('mock-refresh_token', 'urn:ietf:wg:oauth:2.0:oob') == {
'access_token': 'mock-access_token',
'token_type': 'bearer',
'expires_in': 7200,
'refresh_token': 'mock-refresh_token',
'scope': 'public'
}
# Ensure `token_exchange` raises a `ValueError` on incorrect configuration
with pytest.raises(ValueError):
assert TraktClient()['oauth'].token_refresh('mock-refresh_token', 'urn:ietf:wg:oauth:2.0:oob')
def test_request():
with HTTMock(mock.oauth_token, mock.fixtures, mock.unknown):
# Mock authorization
authorization = {
'access_token': 'mock',
'token_type': 'bearer',
'created_at': calendar.timegm(datetime.datetime.utcnow().utctimetuple()),
'expires_in': 7 * 24 * 60 * 60,
'refresh_token': 'mock-refresh_token',
'scope': 'public'
}
# Test valid token
with Trakt.configuration.oauth.from_response(authorization):
assert Trakt['sync/collection'].movies() is not None
# Test expired token
authorization['expires_in'] = 0
with Trakt.configuration.oauth.from_response(authorization):
assert Trakt['sync/collection'].movies() is None
# Test token refreshing
with Trakt.configuration.oauth.from_response(authorization, refresh=True):
assert Trakt['sync/collection'].movies() is not None
def test_refresh_deadlock():
with HTTMock(mock.oauth_token, mock.sync_get, mock.unknown):
# Construct client
client = TraktClient()
# Configure client
client.configuration.defaults.client(
id='mock-client_id',
secret='mock-client_secret'
)
# Bind to events
refreshed = Event()
looped = Event()
@client.on('oauth.refresh')
def on_token_refreshed(username, authorization):
if refreshed.is_set():
looped.set()
return
refreshed.set()
# Test refresh recursion
assert client['sync/collection'].movies() is None
# Attempt request with expired authorization
expired_authorization = {
'access_token': 'mock-access_token',
'token_type': 'bearer',
'created_at': calendar.timegm(datetime.datetime.utcnow().utctimetuple()),
'expires_in': 0,
'refresh_token': 'mock-refresh_token',
'scope': 'public'
}
with client.configuration.oauth.from_response(expired_authorization, refresh=True, username='mock'):
assert client['sync/collection'].movies() is not None
# Ensure requests inside "oauth.refresh" don't cause refresh loops
assert not looped.is_set()
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
504,
2295,
14,
1018,
492,
1683,
199,
504,
2295,
14,
1018,
14,
7546,
492,
702,
63,
633,
199,
504,
30501,
492,
12643,
5973,
12,
12643,
5973,
3041,
199,
199,
504,
22768,
1805,
492,
869,
1481,
3346,
199,
504,
5796,
492,
6763,
199,
646,
11234,
199,
646,
2197,
199,
646,
4613,
421,
199,
318,
511,
63,
14204,
63,
633,
837,
272,
12643,
5973,
14,
2124,
63,
633,
275,
283,
1014,
921,
1805,
7,
339,
702,
63,
633,
8,
2437,
5973,
459,
6126,
2278,
14204,
63,
633,
360,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
659,
1994,
6126,
15,
14204,
297,
469,
267,
283,
4876,
63,
2302,
356,
283,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
297,
267,
283,
1310,
63,
466,
356,
283,
600,
297,
267,
283,
1258,
63,
344,
356,
283,
1805,
13,
1258,
63,
344,
7,
272,
3828,
339,
702,
63,
633,
8,
267,
12643,
5973,
459,
6126,
2278,
14204,
63,
633,
360,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
297,
1174,
534,
929,
297,
3434,
534,
2473,
659,
267,
1994,
6126,
15,
14204,
297,
469,
288,
283,
2473,
356,
283,
2473,
297,
288,
283,
929,
356,
283,
929,
297,
953,
283,
4876,
63,
2302,
356,
283,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
297,
288,
283,
1310,
63,
466,
356,
283,
600,
297,
288,
283,
1258,
63,
344,
356,
283,
1805,
13,
1258,
63,
344,
7,
267,
789,
272,
776,
339,
543,
4613,
14,
3536,
8,
3393,
304,
267,
12643,
5973,
3041,
12047,
6126,
2278,
14204,
63,
633,
360,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
358,
421,
199,
318,
511,
63,
7751,
63,
633,
837,
272,
543,
12643,
5973,
14,
4758,
14,
571,
8,
344,
29,
4321,
304,
267,
702,
63,
633,
8,
2437,
5973,
459,
6126,
15,
7751,
2278,
633,
1062,
1994,
7751,
15,
4321,
358,
339,
543,
4613,
14,
3536,
8,
3393,
304,
267,
12643,
5973,
459,
6126,
15,
7751,
2278,
633,
342,
421,
199,
318,
511,
63,
1418,
837,
272,
543,
869,
1481,
3346,
8,
1805,
14,
6126,
63,
1418,
12,
1683,
14,
5187,
304,
267,
327,
12134,
658,
1418,
63,
14197,
64,
1056,
15,
1310,
267,
702,
12643,
5973,
459,
6126,
2278,
1418,
63,
14197,
360,
31578,
4321,
297,
283,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
358,
508,
469,
288,
283,
2732,
63,
1418,
356,
283,
1805,
13,
2732,
63,
1418,
297,
288,
283,
1418,
63,
466,
356,
283,
1235,
21462,
297,
288,
283,
12342,
63,
262,
356,
1520,
1840,
12,
288,
283,
6635,
63,
1418,
356,
283,
1805,
13,
6635,
63,
1418,
297,
288,
283,
2645,
356,
283,
3455,
7,
267,
789,
398,
327,
7523,
658,
1418,
63,
14197,
64,
6534,
282,
658,
3393,
64,
641,
8927,
2897,
267,
543,
4613,
14,
3536,
8,
3393,
304,
288,
702,
12643,
5973,
3041,
12047,
6126,
2278,
1418,
63,
14197,
360,
31578,
4321,
297,
283,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
358,
421,
199,
318,
511,
63,
1418,
63,
14197,
837,
272,
543,
869,
1481,
3346,
8,
1805,
14,
6126,
63,
1418,
12,
1683,
14,
5187,
304,
267,
327,
12134,
658,
1418,
63,
14197,
64,
1056,
15,
1310,
267,
702,
12643,
5973,
459,
6126,
2278,
1418,
63,
14197,
360,
31578,
4321,
297,
283,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
358,
508,
469,
288,
283,
2732,
63,
1418,
356,
283,
1805,
13,
2732,
63,
1418,
297,
288,
283,
1418,
63,
466,
356,
283,
1235,
21462,
297,
288,
283,
12342,
63,
262,
356,
1520,
1840,
12,
288,
283,
6635,
63,
1418,
356,
283,
1805,
13,
6635,
63,
1418,
297,
288,
283,
2645,
356,
283,
3455,
7,
267,
789,
398,
327,
7523,
658,
1418,
63,
14197,
64,
6534,
282,
658,
3393,
64,
641,
8927,
2897,
267,
543,
4613,
14,
3536,
8,
3393,
304,
288,
702,
12643,
5973,
3041,
12047,
6126,
2278,
1418,
63,
14197,
360,
31578,
4321,
297,
283,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
358,
421,
199,
318,
511,
63,
1418,
63,
6635,
837,
272,
543,
869,
1481,
3346,
8,
1805,
14,
6126,
63,
1418,
12,
1683,
14,
5187,
304,
267,
327,
12134,
658,
1418,
63,
14197,
64,
1056,
15,
1310,
267,
702,
12643,
5973,
459,
6126,
2278,
1418,
63,
6635,
360,
1805,
13,
6635,
63,
1418,
297,
283,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
358,
508,
469,
288,
283,
2732,
63,
1418,
356,
283,
1805,
13,
2732,
63,
1418,
297,
288,
283,
1418,
63,
466,
356,
283,
1235,
21462,
297,
288,
283,
12342,
63,
262,
356,
1520,
1840,
12,
288,
283,
6635,
63,
1418,
356,
283,
1805,
13,
6635,
63,
1418,
297,
288,
283,
2645,
356,
283,
3455,
7,
267,
789,
398,
327,
7523,
658,
1418,
63,
14197,
64,
6534,
282,
658,
3393,
64,
641,
8927,
2897,
267,
543,
4613,
14,
3536,
8,
3393,
304,
288,
702,
12643,
5973,
3041,
12047,
6126,
2278,
1418,
63,
6635,
360,
1805,
13,
6635,
63,
1418,
297,
283,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
358,
421,
199,
318,
511,
63,
1069,
837,
272,
543,
869,
1481,
3346,
8,
1805,
14,
6126,
63,
1418,
12,
1683,
14,
8769,
12,
1683,
14,
5187,
304,
267,
327,
4420,
13448,
267,
13448,
275,
469,
288,
283,
2732,
63,
1418,
356,
283,
1805,
297,
288,
283,
1418,
63,
466,
356,
283,
1235,
21462,
297,
288,
283,
3966,
63,
292,
356,
11234,
14,
521,
13844,
8,
2083,
14,
2083,
14,
10779,
1252,
5834,
22309,
4000,
288,
283,
12342,
63,
262,
356,
1520,
627,
5504,
627,
5212,
627,
5212,
12,
288,
283,
6635,
63,
1418,
356,
283,
1805,
13,
6635,
63,
1418,
297,
288,
283,
2645,
356,
283,
3455,
7,
267,
789,
398,
327,
1379,
1686,
1526,
267,
543,
12643,
5973,
14,
4758,
14,
6126,
14,
504,
63,
1310,
8,
15846,
304,
288
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
504,
2295,
14,
1018,
492,
1683,
199,
504,
2295,
14,
1018,
14,
7546,
492,
702,
63,
633,
199,
504,
30501,
492,
12643,
5973,
12,
12643,
5973,
3041,
199,
199,
504,
22768,
1805,
492,
869,
1481,
3346,
199,
504,
5796,
492,
6763,
199,
646,
11234,
199,
646,
2197,
199,
646,
4613,
421,
199,
318,
511,
63,
14204,
63,
633,
837,
272,
12643,
5973,
14,
2124,
63,
633,
275,
283,
1014,
921,
1805,
7,
339,
702,
63,
633,
8,
2437,
5973,
459,
6126,
2278,
14204,
63,
633,
360,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
659,
1994,
6126,
15,
14204,
297,
469,
267,
283,
4876,
63,
2302,
356,
283,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
297,
267,
283,
1310,
63,
466,
356,
283,
600,
297,
267,
283,
1258,
63,
344,
356,
283,
1805,
13,
1258,
63,
344,
7,
272,
3828,
339,
702,
63,
633,
8,
267,
12643,
5973,
459,
6126,
2278,
14204,
63,
633,
360,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
297,
1174,
534,
929,
297,
3434,
534,
2473,
659,
267,
1994,
6126,
15,
14204,
297,
469,
288,
283,
2473,
356,
283,
2473,
297,
288,
283,
929,
356,
283,
929,
297,
953,
283,
4876,
63,
2302,
356,
283,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
297,
288,
283,
1310,
63,
466,
356,
283,
600,
297,
288,
283,
1258,
63,
344,
356,
283,
1805,
13,
1258,
63,
344,
7,
267,
789,
272,
776,
339,
543,
4613,
14,
3536,
8,
3393,
304,
267,
12643,
5973,
3041,
12047,
6126,
2278,
14204,
63,
633,
360,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
358,
421,
199,
318,
511,
63,
7751,
63,
633,
837,
272,
543,
12643,
5973,
14,
4758,
14,
571,
8,
344,
29,
4321,
304,
267,
702,
63,
633,
8,
2437,
5973,
459,
6126,
15,
7751,
2278,
633,
1062,
1994,
7751,
15,
4321,
358,
339,
543,
4613,
14,
3536,
8,
3393,
304,
267,
12643,
5973,
459,
6126,
15,
7751,
2278,
633,
342,
421,
199,
318,
511,
63,
1418,
837,
272,
543,
869,
1481,
3346,
8,
1805,
14,
6126,
63,
1418,
12,
1683,
14,
5187,
304,
267,
327,
12134,
658,
1418,
63,
14197,
64,
1056,
15,
1310,
267,
702,
12643,
5973,
459,
6126,
2278,
1418,
63,
14197,
360,
31578,
4321,
297,
283,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
358,
508,
469,
288,
283,
2732,
63,
1418,
356,
283,
1805,
13,
2732,
63,
1418,
297,
288,
283,
1418,
63,
466,
356,
283,
1235,
21462,
297,
288,
283,
12342,
63,
262,
356,
1520,
1840,
12,
288,
283,
6635,
63,
1418,
356,
283,
1805,
13,
6635,
63,
1418,
297,
288,
283,
2645,
356,
283,
3455,
7,
267,
789,
398,
327,
7523,
658,
1418,
63,
14197,
64,
6534,
282,
658,
3393,
64,
641,
8927,
2897,
267,
543,
4613,
14,
3536,
8,
3393,
304,
288,
702,
12643,
5973,
3041,
12047,
6126,
2278,
1418,
63,
14197,
360,
31578,
4321,
297,
283,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
358,
421,
199,
318,
511,
63,
1418,
63,
14197,
837,
272,
543,
869,
1481,
3346,
8,
1805,
14,
6126,
63,
1418,
12,
1683,
14,
5187,
304,
267,
327,
12134,
658,
1418,
63,
14197,
64,
1056,
15,
1310,
267,
702,
12643,
5973,
459,
6126,
2278,
1418,
63,
14197,
360,
31578,
4321,
297,
283,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
358,
508,
469,
288,
283,
2732,
63,
1418,
356,
283,
1805,
13,
2732,
63,
1418,
297,
288,
283,
1418,
63,
466,
356,
283,
1235,
21462,
297,
288,
283,
12342,
63,
262,
356,
1520,
1840,
12,
288,
283,
6635,
63,
1418,
356,
283,
1805,
13,
6635,
63,
1418,
297,
288,
283,
2645,
356,
283,
3455,
7,
267,
789,
398,
327,
7523,
658,
1418,
63,
14197,
64,
6534,
282,
658,
3393,
64,
641,
8927,
2897,
267,
543,
4613,
14,
3536,
8,
3393,
304,
288,
702,
12643,
5973,
3041,
12047,
6126,
2278,
1418,
63,
14197,
360,
31578,
4321,
297,
283,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
358,
421,
199,
318,
511,
63,
1418,
63,
6635,
837,
272,
543,
869,
1481,
3346,
8,
1805,
14,
6126,
63,
1418,
12,
1683,
14,
5187,
304,
267,
327,
12134,
658,
1418,
63,
14197,
64,
1056,
15,
1310,
267,
702,
12643,
5973,
459,
6126,
2278,
1418,
63,
6635,
360,
1805,
13,
6635,
63,
1418,
297,
283,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
358,
508,
469,
288,
283,
2732,
63,
1418,
356,
283,
1805,
13,
2732,
63,
1418,
297,
288,
283,
1418,
63,
466,
356,
283,
1235,
21462,
297,
288,
283,
12342,
63,
262,
356,
1520,
1840,
12,
288,
283,
6635,
63,
1418,
356,
283,
1805,
13,
6635,
63,
1418,
297,
288,
283,
2645,
356,
283,
3455,
7,
267,
789,
398,
327,
7523,
658,
1418,
63,
14197,
64,
6534,
282,
658,
3393,
64,
641,
8927,
2897,
267,
543,
4613,
14,
3536,
8,
3393,
304,
288,
702,
12643,
5973,
3041,
12047,
6126,
2278,
1418,
63,
6635,
360,
1805,
13,
6635,
63,
1418,
297,
283,
349,
26,
15799,
26,
23596,
26,
6126,
26,
18,
14,
16,
26,
25189,
358,
421,
199,
318,
511,
63,
1069,
837,
272,
543,
869,
1481,
3346,
8,
1805,
14,
6126,
63,
1418,
12,
1683,
14,
8769,
12,
1683,
14,
5187,
304,
267,
327,
4420,
13448,
267,
13448,
275,
469,
288,
283,
2732,
63,
1418,
356,
283,
1805,
297,
288,
283,
1418,
63,
466,
356,
283,
1235,
21462,
297,
288,
283,
3966,
63,
292,
356,
11234,
14,
521,
13844,
8,
2083,
14,
2083,
14,
10779,
1252,
5834,
22309,
4000,
288,
283,
12342,
63,
262,
356,
1520,
627,
5504,
627,
5212,
627,
5212,
12,
288,
283,
6635,
63,
1418,
356,
283,
1805,
13,
6635,
63,
1418,
297,
288,
283,
2645,
356,
283,
3455,
7,
267,
789,
398,
327,
1379,
1686,
1526,
267,
543,
12643,
5973,
14,
4758,
14,
6126,
14,
504,
63,
1310,
8,
15846,
304,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
gojira/tensorflow
|
tensorflow/contrib/cluster_resolver/python/training/cluster_resolver_test.py
|
23
|
8811
|
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for Cluster Resolvers."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.contrib.cluster_resolver.python.training.cluster_resolver import SimpleClusterResolver
from tensorflow.contrib.cluster_resolver.python.training.cluster_resolver import UnionClusterResolver
from tensorflow.python.platform import test
from tensorflow.python.training import server_lib
class UnionClusterResolverTest(test.TestCase):
# TODO(frankchn): Transform to parameterized test after it is included in the
# TF open source codebase.
def _verifyClusterSpecEquality(self, cluster_spec, expected_proto):
self.assertProtoEquals(expected_proto, cluster_spec.as_cluster_def())
self.assertProtoEquals(
expected_proto, server_lib.ClusterSpec(cluster_spec).as_cluster_def())
self.assertProtoEquals(
expected_proto,
server_lib.ClusterSpec(cluster_spec.as_cluster_def()).as_cluster_def())
self.assertProtoEquals(
expected_proto,
server_lib.ClusterSpec(cluster_spec.as_dict()).as_cluster_def())
def testSingleClusterResolver(self):
base_cluster_spec = server_lib.ClusterSpec({
"ps": ["ps0:2222", "ps1:2222"],
"worker": ["worker0:2222", "worker1:2222", "worker2:2222"]
})
simple_resolver = SimpleClusterResolver(base_cluster_spec)
union_resolver = UnionClusterResolver(simple_resolver)
expected_proto = """
job { name: 'ps' tasks { key: 0 value: 'ps0:2222' }
tasks { key: 1 value: 'ps1:2222' } }
job { name: 'worker' tasks { key: 0 value: 'worker0:2222' }
tasks { key: 1 value: 'worker1:2222' }
tasks { key: 2 value: 'worker2:2222' } }
"""
actual_cluster_spec = union_resolver.cluster_spec()
self._verifyClusterSpecEquality(actual_cluster_spec, expected_proto)
def testTwoNonOverlappingJobMergedClusterResolver(self):
cluster_spec_1 = server_lib.ClusterSpec({
"ps": [
"ps0:2222",
"ps1:2222"
]
})
cluster_spec_2 = server_lib.ClusterSpec({
"worker": [
"worker0:2222",
"worker1:2222",
"worker2:2222"
]
})
cluster_resolver_1 = SimpleClusterResolver(cluster_spec_1)
cluster_resolver_2 = SimpleClusterResolver(cluster_spec_2)
union_cluster = UnionClusterResolver(cluster_resolver_1, cluster_resolver_2)
cluster_spec = union_cluster.cluster_spec()
expected_proto = """
job { name: 'ps' tasks { key: 0 value: 'ps0:2222' }
tasks { key: 1 value: 'ps1:2222' } }
job { name: 'worker' tasks { key: 0 value: 'worker0:2222' }
tasks { key: 1 value: 'worker1:2222' }
tasks { key: 2 value: 'worker2:2222' } }
"""
self._verifyClusterSpecEquality(cluster_spec, expected_proto)
def testOverlappingJobMergedClusterResolver(self):
cluster_spec_1 = server_lib.ClusterSpec({
"worker": [
"worker4:2222",
"worker5:2222"
]
})
cluster_spec_2 = server_lib.ClusterSpec({
"worker": [
"worker0:2222",
"worker1:2222",
"worker2:2222"
]
})
cluster_resolver_1 = SimpleClusterResolver(cluster_spec_1)
cluster_resolver_2 = SimpleClusterResolver(cluster_spec_2)
union_cluster = UnionClusterResolver(cluster_resolver_1, cluster_resolver_2)
cluster_spec = union_cluster.cluster_spec()
expected_proto = """
job { name: 'worker' tasks { key: 0 value: 'worker4:2222' }
tasks { key: 1 value: 'worker5:2222' }
tasks { key: 2 value: 'worker0:2222' }
tasks { key: 3 value: 'worker1:2222' }
tasks { key: 4 value: 'worker2:2222' } }
"""
self._verifyClusterSpecEquality(cluster_spec, expected_proto)
def testOverlappingSparseJobMergedClusterResolverThrowError(self):
cluster_spec_1 = server_lib.ClusterSpec({
"worker": {
7: "worker4:2222",
9: "worker5:2222"
}
})
cluster_spec_2 = server_lib.ClusterSpec({
"worker": {
3: "worker0:2222",
6: "worker1:2222",
7: "worker2:2222"
}
})
cluster_resolver_1 = SimpleClusterResolver(cluster_spec_1)
cluster_resolver_2 = SimpleClusterResolver(cluster_spec_2)
union_cluster = UnionClusterResolver(cluster_resolver_1, cluster_resolver_2)
self.assertRaises(KeyError, union_cluster.cluster_spec)
def testOverlappingDictAndListThrowError(self):
cluster_spec_1 = server_lib.ClusterSpec({
"worker": [
"worker4:2222",
"worker5:2222"
]
})
cluster_spec_2 = server_lib.ClusterSpec({
"worker": {
1: "worker0:2222",
2: "worker1:2222",
3: "worker2:2222"
}
})
cluster_resolver_1 = SimpleClusterResolver(cluster_spec_1)
cluster_resolver_2 = SimpleClusterResolver(cluster_spec_2)
union_cluster = UnionClusterResolver(cluster_resolver_1, cluster_resolver_2)
self.assertRaises(KeyError, union_cluster.cluster_spec)
def testOverlappingJobNonOverlappingKey(self):
cluster_spec_1 = server_lib.ClusterSpec({
"worker": {
5: "worker4:2222",
9: "worker5:2222"
}
})
cluster_spec_2 = server_lib.ClusterSpec({
"worker": {
3: "worker0:2222",
6: "worker1:2222",
7: "worker2:2222"
}
})
cluster_resolver_1 = SimpleClusterResolver(cluster_spec_1)
cluster_resolver_2 = SimpleClusterResolver(cluster_spec_2)
union_cluster = UnionClusterResolver(cluster_resolver_1, cluster_resolver_2)
cluster_spec = union_cluster.cluster_spec()
expected_proto = """
job { name: 'worker' tasks { key: 3 value: 'worker0:2222' }
tasks { key: 5 value: 'worker4:2222' }
tasks { key: 6 value: 'worker1:2222' }
tasks { key: 7 value: 'worker2:2222' }
tasks { key: 9 value: 'worker5:2222' }}
"""
self._verifyClusterSpecEquality(cluster_spec, expected_proto)
def testMixedModeNonOverlappingKey(self):
cluster_spec_1 = server_lib.ClusterSpec({
"worker": [
"worker4:2222",
"worker5:2222"
]
})
cluster_spec_2 = server_lib.ClusterSpec({
"worker": {
3: "worker0:2222",
6: "worker1:2222",
7: "worker2:2222"
}
})
cluster_resolver_1 = SimpleClusterResolver(cluster_spec_1)
cluster_resolver_2 = SimpleClusterResolver(cluster_spec_2)
union_cluster = UnionClusterResolver(cluster_resolver_1, cluster_resolver_2)
cluster_spec = union_cluster.cluster_spec()
expected_proto = """
job { name: 'worker' tasks { key: 0 value: 'worker4:2222' }
tasks { key: 1 value: 'worker5:2222' }
tasks { key: 3 value: 'worker0:2222' }
tasks { key: 6 value: 'worker1:2222' }
tasks { key: 7 value: 'worker2:2222' }}
"""
self._verifyClusterSpecEquality(cluster_spec, expected_proto)
def testRetainSparseJobWithNoMerging(self):
base_cluster_spec = server_lib.ClusterSpec({
"worker": {
1: "worker0:2222",
3: "worker1:2222",
5: "worker2:2222"
}
})
base_cluster_resolver = SimpleClusterResolver(base_cluster_spec)
union_cluster = UnionClusterResolver(base_cluster_resolver)
cluster_spec = union_cluster.cluster_spec()
expected_proto = """
job { name: 'worker' tasks { key: 1 value: 'worker0:2222' }
tasks { key: 3 value: 'worker1:2222' }
tasks { key: 5 value: 'worker2:2222' } }
"""
self._verifyClusterSpecEquality(cluster_spec, expected_proto)
# TODO(saeta): Include tests for master resolution
if __name__ == "__main__":
test.main()
|
apache-2.0
|
[
3,
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
16454,
26046,
83,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
2828,
14,
4201,
63,
7717,
14,
1548,
14,
7588,
14,
4201,
63,
7717,
492,
5870,
9581,
12407,
199,
504,
3228,
14,
2828,
14,
4201,
63,
7717,
14,
1548,
14,
7588,
14,
4201,
63,
7717,
492,
15961,
9581,
12407,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
7588,
492,
1654,
63,
773,
421,
199,
533,
15961,
9581,
12407,
774,
8,
396,
14,
1746,
304,
523,
327,
3254,
8,
70,
4648,
11019,
304,
19463,
370,
29526,
511,
2410,
652,
365,
5120,
315,
314,
523,
327,
21721,
1551,
1350,
1233,
1095,
14,
819,
347,
485,
4712,
9581,
5307,
22977,
8,
277,
12,
4350,
63,
1650,
12,
1420,
63,
2625,
304,
272,
291,
14,
479,
8548,
13317,
8,
2062,
63,
2625,
12,
4350,
63,
1650,
14,
305,
63,
4201,
63,
318,
1012,
272,
291,
14,
479,
8548,
13317,
8,
267,
1420,
63,
2625,
12,
1654,
63,
773,
14,
9581,
5307,
8,
4201,
63,
1650,
680,
305,
63,
4201,
63,
318,
1012,
272,
291,
14,
479,
8548,
13317,
8,
267,
1420,
63,
2625,
12,
267,
1654,
63,
773,
14,
9581,
5307,
8,
4201,
63,
1650,
14,
305,
63,
4201,
63,
318,
8801,
305,
63,
4201,
63,
318,
1012,
272,
291,
14,
479,
8548,
13317,
8,
267,
1420,
63,
2625,
12,
267,
1654,
63,
773,
14,
9581,
5307,
8,
4201,
63,
1650,
14,
305,
63,
807,
8801,
305,
63,
4201,
63,
318,
1012,
819,
347,
511,
7200,
9581,
12407,
8,
277,
304,
272,
1300,
63,
4201,
63,
1650,
275,
1654,
63,
773,
14,
9581,
5307,
2561,
267,
298,
1190,
582,
2097,
1190,
16,
26,
9993,
401,
298,
1190,
17,
26,
9993,
2255,
267,
298,
6599,
582,
2097,
6599,
16,
26,
9993,
401,
298,
6599,
17,
26,
9993,
401,
298,
6599,
18,
26,
9993,
937,
272,
3828,
272,
3486,
63,
7717,
275,
5870,
9581,
12407,
8,
1095,
63,
4201,
63,
1650,
9,
272,
13629,
63,
7717,
275,
15961,
9581,
12407,
8,
4129,
63,
7717,
9,
339,
1420,
63,
2625,
275,
408,
272,
3906,
469,
536,
26,
283,
1190,
7,
6527,
469,
790,
26,
378,
574,
26,
283,
1190,
16,
26,
9993,
7,
789,
2151,
6527,
469,
790,
26,
413,
574,
26,
283,
1190,
17,
26,
9993,
7,
789,
789,
272,
3906,
469,
536,
26,
283,
6599,
7,
6527,
469,
790,
26,
378,
574,
26,
283,
6599,
16,
26,
9993,
7,
789,
586,
6527,
469,
790,
26,
413,
574,
26,
283,
6599,
17,
26,
9993,
7,
789,
586,
6527,
469,
790,
26,
499,
574,
26,
283,
6599,
18,
26,
9993,
7,
789,
789,
272,
408,
272,
3503,
63,
4201,
63,
1650,
275,
13629,
63,
7717,
14,
4201,
63,
1650,
342,
272,
291,
423,
4712,
9581,
5307,
22977,
8,
6514,
63,
4201,
63,
1650,
12,
1420,
63,
2625,
9,
819,
347,
511,
11467,
6932,
5674,
18352,
6694,
16797,
3046,
9581,
12407,
8,
277,
304,
272,
4350,
63,
1650,
63,
17,
275,
1654,
63,
773,
14,
9581,
5307,
2561,
267,
298,
1190,
582,
359,
288,
298,
1190,
16,
26,
9993,
401,
288,
298,
1190,
17,
26,
9993,
2,
267,
1622,
272,
3828,
272,
4350,
63,
1650,
63,
18,
275,
1654,
63,
773,
14,
9581,
5307,
2561,
267,
298,
6599,
582,
359,
288,
298,
6599,
16,
26,
9993,
401,
288,
298,
6599,
17,
26,
9993,
401,
288,
298,
6599,
18,
26,
9993,
2,
267,
1622,
272,
3828,
272,
4350,
63,
7717,
63,
17,
275,
5870,
9581,
12407,
8,
4201,
63,
1650,
63,
17,
9,
272,
4350,
63,
7717,
63,
18,
275,
5870,
9581,
12407,
8,
4201,
63,
1650,
63,
18,
9,
339,
13629,
63,
4201,
275,
15961,
9581,
12407,
8,
4201,
63,
7717,
63,
17,
12,
4350,
63,
7717,
63,
18,
9,
272,
4350,
63,
1650,
275,
13629,
63,
4201,
14,
4201,
63,
1650,
342,
339,
1420,
63,
2625,
275,
408,
272,
3906,
469,
536,
26,
283,
1190,
7,
6527,
469,
790,
26,
378,
574,
26,
283,
1190,
16,
26,
9993,
7,
789,
2151,
6527,
469,
790,
26,
413,
574,
26,
283,
1190,
17,
26,
9993,
7,
789,
789,
272,
3906,
469,
536,
26,
283,
6599,
7,
6527,
469,
790,
26,
378,
574,
26,
283,
6599,
16,
26,
9993,
7,
789,
586,
6527,
469,
790,
26,
413,
574,
26,
283,
6599,
17,
26,
9993,
7,
789,
586,
6527,
469,
790,
26,
499,
574,
26,
283,
6599,
18,
26,
9993,
7,
789,
789,
272,
408,
272,
291,
423,
4712,
9581,
5307,
22977,
8,
4201,
63,
1650,
12,
1420,
63,
2625,
9,
819,
347,
511,
5674,
18352,
6694,
16797,
3046,
9581,
12407,
8,
277,
304,
272,
4350,
63,
1650,
63,
17,
275,
1654,
63,
773,
14,
9581,
5307,
2561,
267,
298,
6599,
582,
359,
288,
298,
6599,
20,
26,
9993,
401,
288,
298,
6599,
21,
26,
9993,
2,
267,
1622,
272,
3828,
272,
4350,
63,
1650,
63,
18,
275,
1654,
63,
773,
14,
9581,
5307,
2561,
267,
298,
6599,
582,
359,
288,
298,
6599,
16,
26,
9993,
401,
288,
298,
6599,
17,
26,
9993,
401,
288,
298,
6599,
18,
26,
9993,
2,
267,
1622,
272,
3828,
272,
4350,
63,
7717,
63,
17,
275,
5870,
9581,
12407,
8
] |
[
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
16454,
26046,
83,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
2828,
14,
4201,
63,
7717,
14,
1548,
14,
7588,
14,
4201,
63,
7717,
492,
5870,
9581,
12407,
199,
504,
3228,
14,
2828,
14,
4201,
63,
7717,
14,
1548,
14,
7588,
14,
4201,
63,
7717,
492,
15961,
9581,
12407,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
7588,
492,
1654,
63,
773,
421,
199,
533,
15961,
9581,
12407,
774,
8,
396,
14,
1746,
304,
523,
327,
3254,
8,
70,
4648,
11019,
304,
19463,
370,
29526,
511,
2410,
652,
365,
5120,
315,
314,
523,
327,
21721,
1551,
1350,
1233,
1095,
14,
819,
347,
485,
4712,
9581,
5307,
22977,
8,
277,
12,
4350,
63,
1650,
12,
1420,
63,
2625,
304,
272,
291,
14,
479,
8548,
13317,
8,
2062,
63,
2625,
12,
4350,
63,
1650,
14,
305,
63,
4201,
63,
318,
1012,
272,
291,
14,
479,
8548,
13317,
8,
267,
1420,
63,
2625,
12,
1654,
63,
773,
14,
9581,
5307,
8,
4201,
63,
1650,
680,
305,
63,
4201,
63,
318,
1012,
272,
291,
14,
479,
8548,
13317,
8,
267,
1420,
63,
2625,
12,
267,
1654,
63,
773,
14,
9581,
5307,
8,
4201,
63,
1650,
14,
305,
63,
4201,
63,
318,
8801,
305,
63,
4201,
63,
318,
1012,
272,
291,
14,
479,
8548,
13317,
8,
267,
1420,
63,
2625,
12,
267,
1654,
63,
773,
14,
9581,
5307,
8,
4201,
63,
1650,
14,
305,
63,
807,
8801,
305,
63,
4201,
63,
318,
1012,
819,
347,
511,
7200,
9581,
12407,
8,
277,
304,
272,
1300,
63,
4201,
63,
1650,
275,
1654,
63,
773,
14,
9581,
5307,
2561,
267,
298,
1190,
582,
2097,
1190,
16,
26,
9993,
401,
298,
1190,
17,
26,
9993,
2255,
267,
298,
6599,
582,
2097,
6599,
16,
26,
9993,
401,
298,
6599,
17,
26,
9993,
401,
298,
6599,
18,
26,
9993,
937,
272,
3828,
272,
3486,
63,
7717,
275,
5870,
9581,
12407,
8,
1095,
63,
4201,
63,
1650,
9,
272,
13629,
63,
7717,
275,
15961,
9581,
12407,
8,
4129,
63,
7717,
9,
339,
1420,
63,
2625,
275,
408,
272,
3906,
469,
536,
26,
283,
1190,
7,
6527,
469,
790,
26,
378,
574,
26,
283,
1190,
16,
26,
9993,
7,
789,
2151,
6527,
469,
790,
26,
413,
574,
26,
283,
1190,
17,
26,
9993,
7,
789,
789,
272,
3906,
469,
536,
26,
283,
6599,
7,
6527,
469,
790,
26,
378,
574,
26,
283,
6599,
16,
26,
9993,
7,
789,
586,
6527,
469,
790,
26,
413,
574,
26,
283,
6599,
17,
26,
9993,
7,
789,
586,
6527,
469,
790,
26,
499,
574,
26,
283,
6599,
18,
26,
9993,
7,
789,
789,
272,
408,
272,
3503,
63,
4201,
63,
1650,
275,
13629,
63,
7717,
14,
4201,
63,
1650,
342,
272,
291,
423,
4712,
9581,
5307,
22977,
8,
6514,
63,
4201,
63,
1650,
12,
1420,
63,
2625,
9,
819,
347,
511,
11467,
6932,
5674,
18352,
6694,
16797,
3046,
9581,
12407,
8,
277,
304,
272,
4350,
63,
1650,
63,
17,
275,
1654,
63,
773,
14,
9581,
5307,
2561,
267,
298,
1190,
582,
359,
288,
298,
1190,
16,
26,
9993,
401,
288,
298,
1190,
17,
26,
9993,
2,
267,
1622,
272,
3828,
272,
4350,
63,
1650,
63,
18,
275,
1654,
63,
773,
14,
9581,
5307,
2561,
267,
298,
6599,
582,
359,
288,
298,
6599,
16,
26,
9993,
401,
288,
298,
6599,
17,
26,
9993,
401,
288,
298,
6599,
18,
26,
9993,
2,
267,
1622,
272,
3828,
272,
4350,
63,
7717,
63,
17,
275,
5870,
9581,
12407,
8,
4201,
63,
1650,
63,
17,
9,
272,
4350,
63,
7717,
63,
18,
275,
5870,
9581,
12407,
8,
4201,
63,
1650,
63,
18,
9,
339,
13629,
63,
4201,
275,
15961,
9581,
12407,
8,
4201,
63,
7717,
63,
17,
12,
4350,
63,
7717,
63,
18,
9,
272,
4350,
63,
1650,
275,
13629,
63,
4201,
14,
4201,
63,
1650,
342,
339,
1420,
63,
2625,
275,
408,
272,
3906,
469,
536,
26,
283,
1190,
7,
6527,
469,
790,
26,
378,
574,
26,
283,
1190,
16,
26,
9993,
7,
789,
2151,
6527,
469,
790,
26,
413,
574,
26,
283,
1190,
17,
26,
9993,
7,
789,
789,
272,
3906,
469,
536,
26,
283,
6599,
7,
6527,
469,
790,
26,
378,
574,
26,
283,
6599,
16,
26,
9993,
7,
789,
586,
6527,
469,
790,
26,
413,
574,
26,
283,
6599,
17,
26,
9993,
7,
789,
586,
6527,
469,
790,
26,
499,
574,
26,
283,
6599,
18,
26,
9993,
7,
789,
789,
272,
408,
272,
291,
423,
4712,
9581,
5307,
22977,
8,
4201,
63,
1650,
12,
1420,
63,
2625,
9,
819,
347,
511,
5674,
18352,
6694,
16797,
3046,
9581,
12407,
8,
277,
304,
272,
4350,
63,
1650,
63,
17,
275,
1654,
63,
773,
14,
9581,
5307,
2561,
267,
298,
6599,
582,
359,
288,
298,
6599,
20,
26,
9993,
401,
288,
298,
6599,
21,
26,
9993,
2,
267,
1622,
272,
3828,
272,
4350,
63,
1650,
63,
18,
275,
1654,
63,
773,
14,
9581,
5307,
2561,
267,
298,
6599,
582,
359,
288,
298,
6599,
16,
26,
9993,
401,
288,
298,
6599,
17,
26,
9993,
401,
288,
298,
6599,
18,
26,
9993,
2,
267,
1622,
272,
3828,
272,
4350,
63,
7717,
63,
17,
275,
5870,
9581,
12407,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
bokeh/bokeh
|
bokeh/client/session.py
|
1
|
21780
|
#-----------------------------------------------------------------------------
# Copyright (c) 2012 - 2021, Anaconda, Inc., and Bokeh Contributors.
# All rights reserved.
#
# The full license is in the file LICENSE.txt, distributed with this software.
#-----------------------------------------------------------------------------
''' Provide a session object to service Bokeh documents in external Python
clients to a Bokeh server.
Use-Cases
~~~~~~~~~
A client session has two primary uses:
* Implementing automated testing infrastructure around Bokeh server
applications.
* Creating and customizing specific sessions of a Bokeh server application
(running *in the Bokeh server*) before passing them on to a specific
viewer.
'''
#-----------------------------------------------------------------------------
# Boilerplate
#-----------------------------------------------------------------------------
from __future__ import annotations
import logging # isort:skip
log = logging.getLogger(__name__)
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# Standard library imports
from typing import TYPE_CHECKING, Any, Dict
from urllib.parse import quote_plus
# External imports
from typing_extensions import Literal
if TYPE_CHECKING:
from tornado.ioloop import IOLoop
# Bokeh imports
from ..core.types import ID
from ..document import Document
from ..resources import DEFAULT_SERVER_HTTP_URL, SessionCoordinates
from ..util.browser import NEW_PARAM, BrowserLike, BrowserTarget
from ..util.token import generate_jwt_token, generate_session_id
from .states import ErrorReason
from .util import server_url_for_websocket_url, websocket_url_for_server_url
if TYPE_CHECKING:
from ..document.events import DocumentPatchedEvent, SessionCallbackAdded, SessionCallbackRemoved
from ..models.layouts import LayoutDOM
from ..protocol.messages.patch_doc import patch_doc
from ..protocol.messages.server_info_reply import ServerInfo
from ..server.callbacks import DocumentCallbackGroup
from .connection import ClientConnection
#-----------------------------------------------------------------------------
# Globals and constants
#-----------------------------------------------------------------------------
DEFAULT_SESSION_ID = "default"
DEFAULT_SERVER_WEBSOCKET_URL = websocket_url_for_server_url(DEFAULT_SERVER_HTTP_URL)
__all__ = (
'ClientSession',
'pull_session',
'push_session',
'show_session',
)
#-----------------------------------------------------------------------------
# General API
#-----------------------------------------------------------------------------
def pull_session(session_id: ID | None = None, url: str = "default", io_loop: IOLoop | None = None,
arguments: Dict[str, str] | None = None, max_message_size: int = 20*1024*1024) -> ClientSession:
''' Create a session by loading the current server-side document.
``session.document`` will be a fresh document loaded from
the server. While the connection to the server is open,
changes made on the server side will be applied to this
document, and changes made on the client side will be
synced to the server.
If you don't plan to modify ``session.document`` you probably
don't need to use this function; instead you can directly
``show_session()`` or ``server_session()`` without downloading
the session's document into your process first. It's much
more efficient to avoid downloading the session if you don't need
to.
In a production scenario, the ``session_id`` should be
unique for each browser tab, which keeps users from
stomping on each other. It's neither scalable nor secure to
use predictable session IDs or to share session IDs across
users.
For a notebook running on a single machine, ``session_id``
could be something human-readable such as ``"default"`` for
convenience.
If you allow ``pull_session()`` to generate a unique
``session_id``, you can obtain the generated ID with the
``id`` property on the returned ``ClientSession``.
Args:
session_id (string, optional) :
The name of the session, None to autogenerate a random one (default: None)
url : (str, optional): The URL to a Bokeh application on a Bokeh server
can also be `"default"` which will connect to the default app URL
io_loop (``tornado.ioloop.IOLoop``, optional) :
The ``IOLoop`` to use for the websocket
arguments (dict[str, str], optional) :
A dictionary of key/values to be passed as HTTP request arguments
to Bokeh application code (default: None)
Note that should only be provided when pulling new sessions.
If ``session_id`` is not None, or a session with ``session_id``
already exists, these arguments will have no effect.
max_message_size (int, optional) :
Configure the Tornado max websocket message size.
(default: 20 MB)
Returns:
ClientSession :
A new ``ClientSession`` connected to the server
'''
coords = SessionCoordinates(session_id=session_id, url=url)
session = ClientSession(
session_id=session_id, websocket_url=websocket_url_for_server_url(coords.url), io_loop=io_loop, arguments=arguments, max_message_size=max_message_size)
session.pull()
return session
def push_session(document: Document, session_id: ID | None = None, url: str = "default",
io_loop: IOLoop | None = None, max_message_size: int = 20*1024*1024) -> ClientSession:
''' Create a session by pushing the given document to the server,
overwriting any existing server-side document.
``session.document`` in the returned session will be your supplied
document. While the connection to the server is open, changes made on the
server side will be applied to this document, and changes made on the
client side will be synced to the server.
In a production scenario, the ``session_id`` should be unique for each
browser tab, which keeps users from stomping on each other. It's neither
scalable nor secure to use predictable session IDs or to share session
IDs across users.
For a notebook running on a single machine, ``session_id`` could be
something human-readable such as ``"default"`` for convenience.
If you allow ``push_session()`` to generate a unique ``session_id``, you
can obtain the generated ID with the ``id`` property on the returned
``ClientSession``.
Args:
document : (bokeh.document.Document)
The document to be pushed and set as session.document
session_id : (string, optional)
The name of the session, None to autogenerate a random one (default: None)
url : (str, optional): The URL to a Bokeh application on a Bokeh server
can also be `"default"` which will connect to the default app URL
io_loop : (tornado.ioloop.IOLoop, optional)
The IOLoop to use for the websocket
max_message_size (int, optional) :
Configure the Tornado max websocket message size.
(default: 20 MB)
Returns:
ClientSession
A new ClientSession connected to the server
'''
coords = SessionCoordinates(session_id=session_id, url=url)
session = ClientSession(session_id=coords.session_id, websocket_url=websocket_url_for_server_url(coords.url), io_loop=io_loop, max_message_size=max_message_size)
session.push(document)
return session
def show_session(
session_id: ID | None = None,
url: str = "default",
session: ClientSession | None = None,
browser: str | None = None,
new: BrowserTarget = "tab",
controller: BrowserLike | None = None) -> None:
''' Open a browser displaying a session document.
If you have a session from ``pull_session()`` or ``push_session`` you
can ``show_session(session=mysession)``. If you don't need to open a
connection to the server yourself, you can show a new session in a
browser by providing just the ``url``.
Args:
session_id (string, optional) :
The name of the session, None to autogenerate a random one (default: None)
url : (str, optional): The URL to a Bokeh application on a Bokeh server
can also be `"default"` which will connect to the default app URL
session (ClientSession, optional) : session to get session ID and server URL from
If you specify this, you don't need to specify session_id and url
browser (str, optional) : browser to show with (default: None)
For systems that support it, the **browser** argument allows
specifying which browser to display in, e.g. "safari", "firefox",
"opera", "windows-default" (see the :doc:`webbrowser <python:library/webbrowser>`
module documentation in the standard lib for more details).
new (str, optional) : new file output mode (default: "tab")
For file-based output, opens or raises the browser window
showing the current output file. If **new** is 'tab', then
opens a new tab. If **new** is 'window', then opens a new window.
'''
if session is not None:
server_url = server_url_for_websocket_url(session._connection.url)
session_id = session.id
else:
coords = SessionCoordinates(session_id=session_id, url=url)
server_url = coords.url
session_id = coords.session_id
if controller is None:
from bokeh.util.browser import get_browser_controller
controller = get_browser_controller(browser=browser)
controller.open(server_url + "?bokeh-session-id=" + quote_plus(session_id),
new=NEW_PARAM[new])
class ClientSession:
''' Represents a websocket connection to a server-side session.
Each server session stores a Document, which is kept in sync with the
corresponding Document for this ``ClientSession`` instance. Updates on
either side of the connection will automatically propagate to the other
side, as long as the connection is open.
ClientSession objects can (and usually should) be used as a context manager
so that the session is properly closed:
.. code-block:: python
with pull_session(url=app_url) as mysession:
# customize session here
script = server_session(session_id=mysession.id, url=app_url)
return render_template("embed.html", script=script, template="Flask")
If you do not use ``ClientSession`` in this way, it is up to you to ensure
that ``mysession.close()`` is called.
.. autoclasstoc::
'''
_document: Document | None
_id: ID
_connection: ClientConnection
_callbacks: DocumentCallbackGroup
def __init__(self, session_id: ID | None = None, websocket_url: str = DEFAULT_SERVER_WEBSOCKET_URL,
io_loop: IOLoop | None = None, arguments: Dict[str, str] | None = None, max_message_size: int = 20*1024*1024):
''' A connection which attaches to a particular named session on the
server.
Always call either pull() or push() immediately after creating the
session (until these are called ``session.document`` will be ``None``).
The :func:`~bokeh.client.session.push_session` and
:func:`~bokeh.client.session.pull_session()` functions will construct a
``ClientSession`` and push or pull in one step, so they are a good way to
obtain a ``ClientSession``.
Args:
session_id (str) :
The name of the session or None to generate one
websocket_url (str) :
Websocket URL to connect to
io_loop (IOLoop, optional) :
The IOLoop to use for the websocket
arguments (dict[str, str], optional) :
A dictionary of key/values to be passed as HTTP request
arguments to Bokeh application code (default: None)
Note that should only be provided when pulling new sessions.
If ``session_id`` is not None, or a session with ``session_id``
already exists, these arguments will have no effect.
max_message_size (int, optional) :
Configure the Tornado max websocket message size.
(default: 20 MB)
'''
self._document = None
self._id = self._ensure_session_id(session_id)
from .connection import ClientConnection
self._connection = ClientConnection(session=self, io_loop=io_loop, websocket_url=websocket_url, arguments=arguments, max_message_size=max_message_size)
from ..server.callbacks import DocumentCallbackGroup
self._callbacks = DocumentCallbackGroup(self._connection.io_loop)
def __enter__(self) -> ClientSession:
'''
'''
return self
def __exit__(self, exc_type: Any, exc_value: Any, exc_traceback: Any) -> None:
'''
'''
self.close()
# Properties --------------------------------------------------------------
@property
def connected(self) -> bool:
''' Whether this session is currently connected. '''
return self._connection.connected
@property
def error_reason(self) -> ErrorReason | None:
return self._connection.error_reason
@property
def error_code(self) -> int | None:
return self._connection.error_code
@property
def error_detail(self) -> str:
return self._connection.error_detail
@property
def url(self) -> str:
return self._connection.url
@property
def document(self) -> Document:
''' A |Document| that will be kept in sync with the corresponding
``Document`` on the server.
This value is initialized when :func:`pull` or :func:`push` succeeds.
It will be ``None`` until then.
'''
return self._document
@property
def id(self) -> ID:
''' A unique ID for this session. '''
return self._id
@property
def token(self) -> str:
''' A JWT token to authenticate the session. '''
return generate_jwt_token(self.id)
# Public methods ----------------------------------------------------------
def connect(self) -> None:
''' Connect to a Bokeh server at the configured URL. '''
self._connection.connect()
def close(self, why: str = "closed") -> None:
''' Close the connection to the server. '''
self._connection.close(why)
def force_roundtrip(self) -> None:
''' Force a round-trip request/reply to the server, sometimes needed to
avoid race conditions. Mostly useful for testing.
Outside of test suites, this method hurts performance and should not be
needed.
Returns:
None
'''
self._connection.force_roundtrip()
def check_connection_errors(self) -> None:
''' Raises an error, when the connection could not have been
established.
Should be used, after a call to connect.
Returns:
None
'''
if not self.connected:
if self.error_reason is ErrorReason.HTTP_ERROR:
if self.error_code == 404:
raise OSError(f"Check your application path! The given Path is not valid: {self.url}")
raise OSError(f"We received an HTTP-Error. Disconnected with error code: {self.error_code}, given message: {self.error_detail}")
raise OSError("We failed to connect to the server (to start the server, try the 'bokeh serve' command)")
def pull(self) -> None:
''' Pull the server's state and set it as session.document.
If this is called more than once, session.document will be the same
object instance but its contents will be overwritten.
Automatically calls :func:`connect` before pulling.
'''
self.connect()
self.check_connection_errors()
if self.document is None:
doc = Document()
else:
doc = self.document
self._connection.pull_doc(doc)
if self.document is None:
self._attach_document(doc)
def push(self, document: Document | None = None) -> None:
''' Push the given document to the server and record it as ``session.document``.
If this is called more than once, the Document has to be the same (or None
to mean ``session.document``).
.. note::
Automatically calls :func:`~connect` before pushing.
Args:
document (|Document|, optional) :
The document that will be kept in sync with the server document.
None to use ``session.document`` or create a new document.
'''
if self.document is None:
if document is None:
doc = Document()
else:
doc = document
else:
if document is None:
doc = self.document
else:
raise ValueError("Cannot push() a different document from existing session.document")
self.connect()
self.check_connection_errors()
self._connection.push_doc(doc)
if self._document is None:
self._attach_document(doc)
def request_server_info(self) -> ServerInfo:
''' Ask for information about the server.
Returns:
A dictionary of server attributes.
'''
return self._connection.request_server_info()
def show(self, obj: LayoutDOM | None = None, browser: str | None = None,
new: Literal["tab", "window"] = "tab") -> None:
''' Open a browser displaying this session.
Args:
obj (LayoutDOM object, optional) : a Layout (Row/Column),
Plot or Widget object to display. The object will be added
to the session's document.
browser (str, optional) : browser to show with (default: None)
For systems that support it, the **browser** argument allows
specifying which browser to display in, e.g. "safari", "firefox",
"opera", "windows-default" (see the :doc:`webbrowser <python:library/webbrowser>`
module documentation in the standard lib for more details).
new (str, optional) : new file output mode (default: "tab")
For file-based output, opens or raises the browser window
showing the current output file. If **new** is 'tab', then
opens a new tab. If **new** is 'window', then opens a new window.
'''
if obj and obj not in self.document.roots:
self.document.add_root(obj)
show_session(session=self, browser=browser, new=new)
# Internal methods --------------------------------------------------------
def _attach_document(self, document: Document) -> None:
self._document = document
self._document.on_change_dispatch_to(self)
self._callbacks.add_session_callbacks(self._document.session_callbacks)
def _document_patched(self, event: DocumentPatchedEvent) -> None:
if event.setter is self:
log.debug("Not sending notification back to server for a change it requested")
return
# TODO (havocp): our "change sync" protocol is flawed
# because if both sides change the same attribute at the
# same time, they will each end up with the state of the
# other and their final states will differ.
self._connection._send_patch_document(self._id, event)
@classmethod
def _ensure_session_id(cls, session_id: ID | None) -> ID:
if session_id is None:
session_id = generate_session_id()
return session_id
def _handle_patch(self, message: patch_doc) -> None:
message.apply_to_document(self.document, self)
def _loop_until_closed(self) -> None:
''' Execute a blocking loop that runs and executes event callbacks
until the connection is closed (e.g. by hitting Ctrl-C).
This function is intended to facilitate testing ONLY.
'''
self._connection.loop_until_closed()
def _notify_disconnected(self) -> None:
''' Called by the ClientConnection we are using to notify us of disconnect.
'''
if self.document is not None:
self.document.remove_on_change(self)
self._callbacks.remove_all_callbacks()
def _session_callback_added(self, event: SessionCallbackAdded) -> None:
self._callbacks.add_session_callback(event.callback)
def _session_callback_removed(self, event: SessionCallbackRemoved) -> None:
self._callbacks.remove_session_callback(event.callback)
#-----------------------------------------------------------------------------
# Dev API
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Private API
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
|
bsd-3-clause
|
[
18045,
199,
3,
1898,
334,
67,
9,
6029,
446,
499,
15385,
12,
1626,
16928,
983,
12,
3277,
2020,
436,
5088,
16610,
23212,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
710,
2615,
4190,
365,
315,
314,
570,
5113,
14,
2424,
12,
1854,
543,
642,
2032,
14,
199,
18045,
199,
2344,
22896,
282,
2351,
909,
370,
2435,
5088,
16610,
8247,
315,
5957,
2018,
199,
14555,
370,
282,
5088,
16610,
1654,
14,
199,
199,
6119,
13,
1538,
83,
199,
4919,
94,
199,
199,
33,
1890,
2351,
965,
2877,
5062,
4440,
26,
199,
199,
10,
22467,
316,
6384,
23513,
5343,
28890,
6976,
6818,
5088,
16610,
1654,
523,
13103,
14,
199,
199,
10,
20507,
436,
3537,
9147,
2488,
12184,
402,
282,
5088,
16610,
1654,
4223,
523,
334,
5720,
627,
262,
314,
5088,
16610,
1654,
13278,
2544,
9476,
3062,
641,
370,
282,
2488,
523,
27354,
14,
199,
199,
2344,
199,
199,
18045,
199,
3,
5088,
27025,
199,
18045,
199,
504,
636,
2443,
363,
492,
15538,
199,
199,
646,
2050,
327,
365,
361,
26,
2759,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
18045,
199,
3,
24339,
199,
18045,
199,
199,
3,
9739,
3555,
8925,
199,
504,
14090,
492,
11511,
63,
8936,
1206,
12,
6184,
12,
7448,
199,
504,
4011,
14,
1122,
492,
6313,
63,
6666,
199,
199,
3,
18802,
8925,
199,
504,
14090,
63,
5359,
492,
18271,
199,
199,
692,
11511,
63,
8936,
1206,
26,
272,
687,
12148,
14,
27212,
492,
25584,
199,
199,
3,
5088,
16610,
8925,
199,
504,
2508,
1018,
14,
1313,
492,
2870,
199,
504,
2508,
3554,
492,
7543,
199,
504,
2508,
4435,
492,
6186,
63,
6613,
63,
2856,
63,
2632,
12,
8596,
13940,
2335,
199,
504,
2508,
1974,
14,
5750,
492,
18689,
63,
7258,
12,
27620,
12545,
12,
27620,
4277,
199,
504,
2508,
1974,
14,
1418,
492,
3550,
63,
30033,
63,
1418,
12,
3550,
63,
1730,
63,
344,
199,
504,
1275,
4981,
492,
4520,
16148,
199,
504,
1275,
1974,
492,
1654,
63,
633,
63,
509,
63,
13508,
63,
633,
12,
24897,
63,
633,
63,
509,
63,
1000,
63,
633,
199,
199,
692,
11511,
63,
8936,
1206,
26,
272,
687,
2508,
3554,
14,
4368,
492,
7543,
11173,
379,
2390,
12,
8596,
2806,
20201,
12,
8596,
2806,
23407,
272,
687,
2508,
992,
14,
4209,
83,
492,
25604,
10462,
272,
687,
2508,
3922,
14,
3431,
14,
2068,
63,
1301,
492,
3371,
63,
1301,
272,
687,
2508,
3922,
14,
3431,
14,
1000,
63,
815,
63,
8102,
492,
7146,
2354,
272,
687,
2508,
1000,
14,
11948,
492,
7543,
2806,
2448,
272,
687,
1275,
2105,
492,
6810,
3225,
199,
199,
18045,
199,
3,
13641,
83,
436,
5262,
199,
18045,
199,
199,
3472,
63,
12763,
63,
998,
275,
298,
885,
2,
199,
199,
3472,
63,
6613,
63,
13166,
17462,
63,
2632,
275,
24897,
63,
633,
63,
509,
63,
1000,
63,
633,
8,
3472,
63,
6613,
63,
2856,
63,
2632,
9,
199,
199,
363,
452,
363,
275,
334,
272,
283,
3041,
4434,
297,
272,
283,
9302,
63,
1730,
297,
272,
283,
5335,
63,
1730,
297,
272,
283,
2384,
63,
1730,
297,
199,
9,
199,
199,
18045,
199,
3,
1696,
3261,
199,
18045,
199,
199,
318,
10299,
63,
1730,
8,
1730,
63,
344,
26,
2870,
1204,
488,
275,
488,
12,
1166,
26,
620,
275,
298,
885,
401,
5890,
63,
3813,
26,
25584,
1204,
488,
275,
488,
12,
267,
2368,
26,
7448,
59,
495,
12,
620,
61,
1204,
488,
275,
488,
12,
1390,
63,
1188,
63,
890,
26,
1109,
275,
3388,
10,
7727,
10,
7727,
9,
1035,
6810,
4434,
26,
272,
1449,
2790,
282,
2351,
701,
8697,
314,
1453,
1654,
13,
2441,
2213,
14,
339,
1124,
1730,
14,
3554,
1040,
911,
506,
282,
17480,
2213,
6511,
687,
272,
314,
1654,
14,
22117,
314,
1950,
370,
314,
1654,
365,
1551,
12,
272,
4493,
6326,
641,
314,
1654,
5366,
911,
506,
6781,
370,
642,
272,
2213,
12,
436,
4493,
6326,
641,
314,
1890,
5366,
911,
506,
272,
9560,
6867,
370,
314,
1654,
14,
339,
982,
1265,
2793,
1133,
8683,
370,
2811,
1124,
1730,
14,
3554,
1040,
1265,
8646,
272,
2793,
1133,
1929,
370,
675,
642,
805,
27,
3140,
1265,
883,
5370,
272,
1124,
2384,
63,
1730,
8497,
503,
1124,
1000,
63,
1730,
8497,
1928,
25937,
272,
314,
2351,
1159,
2213,
1901,
2195,
2112,
1642,
14,
2779,
1159,
8298,
272,
1655,
13402,
370,
5126,
25937,
314,
2351,
340,
1265,
2793,
1133,
1929,
272,
370,
14,
339,
1010,
282,
9920,
15728,
12,
314,
1124,
1730,
63,
344,
1040,
1077,
506,
272,
3747,
367,
1924,
7042,
5174,
12,
1314,
18578,
4390,
687,
272,
410,
22527,
316,
641,
1924,
1163,
14,
2779,
1159,
15564,
5269,
461,
6590,
11153,
370,
272,
675,
12610,
461,
2351,
11449,
503,
370,
8663,
2351,
11449,
9371,
272,
4390,
14,
339,
2104,
282,
20751,
3879,
641,
282,
2849,
6844,
12,
1124,
1730,
63,
344,
1040,
272,
4293,
506,
6020,
11779,
13,
11875,
4066,
465,
25916,
885,
31002,
367,
272,
16777,
14,
339,
982,
1265,
2040,
1124,
9302,
63,
1730,
8497,
370,
3550,
282,
3747,
272,
1124,
1730,
63,
344,
4542,
1265,
883,
3332,
314,
4046,
2870,
543,
314,
272,
1124,
344,
1040,
3324,
641,
314,
2138,
1124,
3041,
4434,
4345,
339,
3033,
26,
267,
2351,
63,
344,
334,
875,
12,
2716,
9,
520,
288,
710,
536,
402,
314,
2351,
12,
488,
370,
6384,
974,
22978,
282,
2196,
1373,
334,
885,
26,
488,
9,
398,
1166,
520,
334,
495,
12,
2716,
304,
710,
2851,
370,
282,
5088,
16610,
4223,
641,
282,
5088,
16610,
1654,
355,
883,
2597,
506,
28531,
885,
2,
64,
1314,
911,
4907,
370,
314,
849,
1145,
2851,
398,
5890,
63,
3813,
15693,
18443,
14,
27212,
14,
23152,
4542,
2716,
9,
520,
288,
710,
1124,
23152,
1040,
370,
675,
367,
314,
24897,
398,
2368,
334,
807,
59,
495,
12,
620,
467,
2716,
9,
520,
288,
437,
2600,
402,
790,
15,
1459,
370,
506,
3032,
465,
3101,
1056,
2368,
288,
370,
5088,
16610,
4223,
1233,
334,
885,
26,
488,
9,
953,
3390,
626,
1077,
1454,
506,
2741,
1380,
10299,
316,
892,
12184,
14,
288,
982,
1124,
1730,
63,
344,
1040,
365,
440,
488,
12,
503,
282,
2351,
543,
1124,
1730,
63,
344,
1040,
288,
2575,
3495,
12,
3520,
2368,
911,
1172
] |
[
199,
3,
1898,
334,
67,
9,
6029,
446,
499,
15385,
12,
1626,
16928,
983,
12,
3277,
2020,
436,
5088,
16610,
23212,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
710,
2615,
4190,
365,
315,
314,
570,
5113,
14,
2424,
12,
1854,
543,
642,
2032,
14,
199,
18045,
199,
2344,
22896,
282,
2351,
909,
370,
2435,
5088,
16610,
8247,
315,
5957,
2018,
199,
14555,
370,
282,
5088,
16610,
1654,
14,
199,
199,
6119,
13,
1538,
83,
199,
4919,
94,
199,
199,
33,
1890,
2351,
965,
2877,
5062,
4440,
26,
199,
199,
10,
22467,
316,
6384,
23513,
5343,
28890,
6976,
6818,
5088,
16610,
1654,
523,
13103,
14,
199,
199,
10,
20507,
436,
3537,
9147,
2488,
12184,
402,
282,
5088,
16610,
1654,
4223,
523,
334,
5720,
627,
262,
314,
5088,
16610,
1654,
13278,
2544,
9476,
3062,
641,
370,
282,
2488,
523,
27354,
14,
199,
199,
2344,
199,
199,
18045,
199,
3,
5088,
27025,
199,
18045,
199,
504,
636,
2443,
363,
492,
15538,
199,
199,
646,
2050,
327,
365,
361,
26,
2759,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
18045,
199,
3,
24339,
199,
18045,
199,
199,
3,
9739,
3555,
8925,
199,
504,
14090,
492,
11511,
63,
8936,
1206,
12,
6184,
12,
7448,
199,
504,
4011,
14,
1122,
492,
6313,
63,
6666,
199,
199,
3,
18802,
8925,
199,
504,
14090,
63,
5359,
492,
18271,
199,
199,
692,
11511,
63,
8936,
1206,
26,
272,
687,
12148,
14,
27212,
492,
25584,
199,
199,
3,
5088,
16610,
8925,
199,
504,
2508,
1018,
14,
1313,
492,
2870,
199,
504,
2508,
3554,
492,
7543,
199,
504,
2508,
4435,
492,
6186,
63,
6613,
63,
2856,
63,
2632,
12,
8596,
13940,
2335,
199,
504,
2508,
1974,
14,
5750,
492,
18689,
63,
7258,
12,
27620,
12545,
12,
27620,
4277,
199,
504,
2508,
1974,
14,
1418,
492,
3550,
63,
30033,
63,
1418,
12,
3550,
63,
1730,
63,
344,
199,
504,
1275,
4981,
492,
4520,
16148,
199,
504,
1275,
1974,
492,
1654,
63,
633,
63,
509,
63,
13508,
63,
633,
12,
24897,
63,
633,
63,
509,
63,
1000,
63,
633,
199,
199,
692,
11511,
63,
8936,
1206,
26,
272,
687,
2508,
3554,
14,
4368,
492,
7543,
11173,
379,
2390,
12,
8596,
2806,
20201,
12,
8596,
2806,
23407,
272,
687,
2508,
992,
14,
4209,
83,
492,
25604,
10462,
272,
687,
2508,
3922,
14,
3431,
14,
2068,
63,
1301,
492,
3371,
63,
1301,
272,
687,
2508,
3922,
14,
3431,
14,
1000,
63,
815,
63,
8102,
492,
7146,
2354,
272,
687,
2508,
1000,
14,
11948,
492,
7543,
2806,
2448,
272,
687,
1275,
2105,
492,
6810,
3225,
199,
199,
18045,
199,
3,
13641,
83,
436,
5262,
199,
18045,
199,
199,
3472,
63,
12763,
63,
998,
275,
298,
885,
2,
199,
199,
3472,
63,
6613,
63,
13166,
17462,
63,
2632,
275,
24897,
63,
633,
63,
509,
63,
1000,
63,
633,
8,
3472,
63,
6613,
63,
2856,
63,
2632,
9,
199,
199,
363,
452,
363,
275,
334,
272,
283,
3041,
4434,
297,
272,
283,
9302,
63,
1730,
297,
272,
283,
5335,
63,
1730,
297,
272,
283,
2384,
63,
1730,
297,
199,
9,
199,
199,
18045,
199,
3,
1696,
3261,
199,
18045,
199,
199,
318,
10299,
63,
1730,
8,
1730,
63,
344,
26,
2870,
1204,
488,
275,
488,
12,
1166,
26,
620,
275,
298,
885,
401,
5890,
63,
3813,
26,
25584,
1204,
488,
275,
488,
12,
267,
2368,
26,
7448,
59,
495,
12,
620,
61,
1204,
488,
275,
488,
12,
1390,
63,
1188,
63,
890,
26,
1109,
275,
3388,
10,
7727,
10,
7727,
9,
1035,
6810,
4434,
26,
272,
1449,
2790,
282,
2351,
701,
8697,
314,
1453,
1654,
13,
2441,
2213,
14,
339,
1124,
1730,
14,
3554,
1040,
911,
506,
282,
17480,
2213,
6511,
687,
272,
314,
1654,
14,
22117,
314,
1950,
370,
314,
1654,
365,
1551,
12,
272,
4493,
6326,
641,
314,
1654,
5366,
911,
506,
6781,
370,
642,
272,
2213,
12,
436,
4493,
6326,
641,
314,
1890,
5366,
911,
506,
272,
9560,
6867,
370,
314,
1654,
14,
339,
982,
1265,
2793,
1133,
8683,
370,
2811,
1124,
1730,
14,
3554,
1040,
1265,
8646,
272,
2793,
1133,
1929,
370,
675,
642,
805,
27,
3140,
1265,
883,
5370,
272,
1124,
2384,
63,
1730,
8497,
503,
1124,
1000,
63,
1730,
8497,
1928,
25937,
272,
314,
2351,
1159,
2213,
1901,
2195,
2112,
1642,
14,
2779,
1159,
8298,
272,
1655,
13402,
370,
5126,
25937,
314,
2351,
340,
1265,
2793,
1133,
1929,
272,
370,
14,
339,
1010,
282,
9920,
15728,
12,
314,
1124,
1730,
63,
344,
1040,
1077,
506,
272,
3747,
367,
1924,
7042,
5174,
12,
1314,
18578,
4390,
687,
272,
410,
22527,
316,
641,
1924,
1163,
14,
2779,
1159,
15564,
5269,
461,
6590,
11153,
370,
272,
675,
12610,
461,
2351,
11449,
503,
370,
8663,
2351,
11449,
9371,
272,
4390,
14,
339,
2104,
282,
20751,
3879,
641,
282,
2849,
6844,
12,
1124,
1730,
63,
344,
1040,
272,
4293,
506,
6020,
11779,
13,
11875,
4066,
465,
25916,
885,
31002,
367,
272,
16777,
14,
339,
982,
1265,
2040,
1124,
9302,
63,
1730,
8497,
370,
3550,
282,
3747,
272,
1124,
1730,
63,
344,
4542,
1265,
883,
3332,
314,
4046,
2870,
543,
314,
272,
1124,
344,
1040,
3324,
641,
314,
2138,
1124,
3041,
4434,
4345,
339,
3033,
26,
267,
2351,
63,
344,
334,
875,
12,
2716,
9,
520,
288,
710,
536,
402,
314,
2351,
12,
488,
370,
6384,
974,
22978,
282,
2196,
1373,
334,
885,
26,
488,
9,
398,
1166,
520,
334,
495,
12,
2716,
304,
710,
2851,
370,
282,
5088,
16610,
4223,
641,
282,
5088,
16610,
1654,
355,
883,
2597,
506,
28531,
885,
2,
64,
1314,
911,
4907,
370,
314,
849,
1145,
2851,
398,
5890,
63,
3813,
15693,
18443,
14,
27212,
14,
23152,
4542,
2716,
9,
520,
288,
710,
1124,
23152,
1040,
370,
675,
367,
314,
24897,
398,
2368,
334,
807,
59,
495,
12,
620,
467,
2716,
9,
520,
288,
437,
2600,
402,
790,
15,
1459,
370,
506,
3032,
465,
3101,
1056,
2368,
288,
370,
5088,
16610,
4223,
1233,
334,
885,
26,
488,
9,
953,
3390,
626,
1077,
1454,
506,
2741,
1380,
10299,
316,
892,
12184,
14,
288,
982,
1124,
1730,
63,
344,
1040,
365,
440,
488,
12,
503,
282,
2351,
543,
1124,
1730,
63,
344,
1040,
288,
2575,
3495,
12,
3520,
2368,
911,
1172,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nmrao/robotframework
|
src/robot/model/totalstatistics.py
|
27
|
2283
|
# Copyright 2008-2015 Nokia Solutions and Networks
#
# 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 .stats import TotalStat
from .visitor import SuiteVisitor
class TotalStatistics(object):
"""Container for total statistics."""
def __init__(self):
#: Instance of :class:`~robot.model.stats.TotalStat` for critical tests.
self.critical = TotalStat('Critical Tests')
#: Instance of :class:`~robot.model.stats.TotalStat` for all the tests.
self.all = TotalStat('All Tests')
def visit(self, visitor):
visitor.visit_total_statistics(self)
def __iter__(self):
return iter([self.critical, self.all])
@property
def message(self):
"""String representation of the statistics.
For example::
2 critical tests, 1 passed, 1 failed
2 tests total, 1 passed, 1 failed
"""
ctotal, cend, cpass, cfail = self._get_counts(self.critical)
atotal, aend, apass, afail = self._get_counts(self.all)
return ('%d critical test%s, %d passed, %d failed\n'
'%d test%s total, %d passed, %d failed'
% (ctotal, cend, cpass, cfail, atotal, aend, apass, afail))
def _get_counts(self, stat):
ending = 's' if stat.total != 1 else ''
return stat.total, ending, stat.passed, stat.failed
class TotalStatisticsBuilder(SuiteVisitor):
def __init__(self, suite=None):
self.stats = TotalStatistics()
if suite:
suite.visit(self)
def add_test(self, test):
self.stats.all.add_test(test)
if test.critical:
self.stats.critical.add_test(test)
def visit_test(self, test):
self.add_test(test)
def visit_keyword(self, kw):
pass
|
apache-2.0
|
[
3,
221,
1898,
9079,
13,
7806,
653,
745,
4674,
17991,
8653,
436,
17138,
199,
3,
199,
3,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
221,
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,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
199,
504,
1275,
3200,
492,
19271,
11232,
199,
504,
1275,
19863,
492,
14453,
18324,
421,
199,
533,
19271,
20750,
8,
785,
304,
272,
408,
4076,
367,
3141,
11076,
1041,
339,
347,
636,
826,
721,
277,
304,
267,
6079,
10066,
402,
520,
533,
6054,
9751,
14,
1238,
14,
3200,
14,
7316,
11232,
64,
367,
19698,
2295,
14,
267,
291,
14,
13138,
275,
19271,
11232,
360,
27677,
6496,
358,
267,
6079,
10066,
402,
520,
533,
6054,
9751,
14,
1238,
14,
3200,
14,
7316,
11232,
64,
367,
1006,
314,
2295,
14,
267,
291,
14,
452,
275,
19271,
11232,
360,
2422,
6496,
358,
339,
347,
5684,
8,
277,
12,
18040,
304,
267,
18040,
14,
5427,
63,
2923,
63,
13724,
8,
277,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
779,
277,
14,
13138,
12,
291,
14,
452,
566,
339,
768,
1829,
272,
347,
1245,
8,
277,
304,
267,
408,
1558,
6025,
402,
314,
11076,
14,
398,
2104,
2893,
447,
953,
499,
19698,
2295,
12,
413,
3032,
12,
413,
3405,
288,
499,
2295,
3141,
12,
413,
3032,
12,
413,
3405,
267,
408,
267,
286,
2923,
12,
286,
500,
12,
286,
1529,
12,
286,
1633,
275,
291,
423,
362,
63,
6851,
8,
277,
14,
13138,
9,
267,
737,
1735,
12,
282,
500,
12,
282,
1529,
12,
282,
1633,
275,
291,
423,
362,
63,
6851,
8,
277,
14,
452,
9,
267,
372,
16651,
68,
19698,
511,
5,
83,
12,
450,
68,
3032,
12,
450,
68,
3405,
60,
78,
7,
355,
1543,
68,
511,
5,
83,
3141,
12,
450,
68,
3032,
12,
450,
68,
3405,
7,
355,
450,
334,
319,
1735,
12,
286,
500,
12,
286,
1529,
12,
286,
1633,
12,
737,
1735,
12,
282,
500,
12,
282,
1529,
12,
282,
1633,
430,
339,
347,
485,
362,
63,
6851,
8,
277,
12,
5672,
304,
267,
13401,
275,
283,
83,
7,
340,
5672,
14,
2923,
1137,
413,
587,
2125,
267,
372,
5672,
14,
2923,
12,
13401,
12,
5672,
14,
12070,
12,
5672,
14,
4892,
421,
199,
533,
19271,
20750,
6437,
8,
6207,
18324,
304,
339,
347,
636,
826,
721,
277,
12,
5241,
29,
403,
304,
267,
291,
14,
3200,
275,
19271,
20750,
342,
267,
340,
5241,
26,
288,
5241,
14,
5427,
8,
277,
9,
339,
347,
1050,
63,
396,
8,
277,
12,
511,
304,
267,
291,
14,
3200,
14,
452,
14,
525,
63,
396,
8,
396,
9,
267,
340,
511,
14,
13138,
26,
288,
291,
14,
3200,
14,
13138,
14,
525,
63,
396,
8,
396,
9,
339,
347,
5684,
63,
396,
8,
277,
12,
511,
304,
267,
291,
14,
525,
63,
396,
8,
396,
9,
339,
347,
5684,
63,
6691,
8,
277,
12,
4775,
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
] |
[
221,
1898,
9079,
13,
7806,
653,
745,
4674,
17991,
8653,
436,
17138,
199,
3,
199,
3,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
221,
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,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
199,
504,
1275,
3200,
492,
19271,
11232,
199,
504,
1275,
19863,
492,
14453,
18324,
421,
199,
533,
19271,
20750,
8,
785,
304,
272,
408,
4076,
367,
3141,
11076,
1041,
339,
347,
636,
826,
721,
277,
304,
267,
6079,
10066,
402,
520,
533,
6054,
9751,
14,
1238,
14,
3200,
14,
7316,
11232,
64,
367,
19698,
2295,
14,
267,
291,
14,
13138,
275,
19271,
11232,
360,
27677,
6496,
358,
267,
6079,
10066,
402,
520,
533,
6054,
9751,
14,
1238,
14,
3200,
14,
7316,
11232,
64,
367,
1006,
314,
2295,
14,
267,
291,
14,
452,
275,
19271,
11232,
360,
2422,
6496,
358,
339,
347,
5684,
8,
277,
12,
18040,
304,
267,
18040,
14,
5427,
63,
2923,
63,
13724,
8,
277,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
779,
277,
14,
13138,
12,
291,
14,
452,
566,
339,
768,
1829,
272,
347,
1245,
8,
277,
304,
267,
408,
1558,
6025,
402,
314,
11076,
14,
398,
2104,
2893,
447,
953,
499,
19698,
2295,
12,
413,
3032,
12,
413,
3405,
288,
499,
2295,
3141,
12,
413,
3032,
12,
413,
3405,
267,
408,
267,
286,
2923,
12,
286,
500,
12,
286,
1529,
12,
286,
1633,
275,
291,
423,
362,
63,
6851,
8,
277,
14,
13138,
9,
267,
737,
1735,
12,
282,
500,
12,
282,
1529,
12,
282,
1633,
275,
291,
423,
362,
63,
6851,
8,
277,
14,
452,
9,
267,
372,
16651,
68,
19698,
511,
5,
83,
12,
450,
68,
3032,
12,
450,
68,
3405,
60,
78,
7,
355,
1543,
68,
511,
5,
83,
3141,
12,
450,
68,
3032,
12,
450,
68,
3405,
7,
355,
450,
334,
319,
1735,
12,
286,
500,
12,
286,
1529,
12,
286,
1633,
12,
737,
1735,
12,
282,
500,
12,
282,
1529,
12,
282,
1633,
430,
339,
347,
485,
362,
63,
6851,
8,
277,
12,
5672,
304,
267,
13401,
275,
283,
83,
7,
340,
5672,
14,
2923,
1137,
413,
587,
2125,
267,
372,
5672,
14,
2923,
12,
13401,
12,
5672,
14,
12070,
12,
5672,
14,
4892,
421,
199,
533,
19271,
20750,
6437,
8,
6207,
18324,
304,
339,
347,
636,
826,
721,
277,
12,
5241,
29,
403,
304,
267,
291,
14,
3200,
275,
19271,
20750,
342,
267,
340,
5241,
26,
288,
5241,
14,
5427,
8,
277,
9,
339,
347,
1050,
63,
396,
8,
277,
12,
511,
304,
267,
291,
14,
3200,
14,
452,
14,
525,
63,
396,
8,
396,
9,
267,
340,
511,
14,
13138,
26,
288,
291,
14,
3200,
14,
13138,
14,
525,
63,
396,
8,
396,
9,
339,
347,
5684,
63,
396,
8,
277,
12,
511,
304,
267,
291,
14,
525,
63,
396,
8,
396,
9,
339,
347,
5684,
63,
6691,
8,
277,
12,
4775,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,I0);
import numpy as np
from scipy.integrate import ode
import matplotlib.pyplot as PLT
PLOT = True
class SIM(object):
def __init__(self, plt, pvt_init_data):
#print I
# atol = 1e-10
rtol = 1e-5
# tt,YY,dummy_D,dummy_P
self.solver = ode(dyn).set_integrator('dopri5', rtol=rtol)
return
def sim(self, TT, X0, D, P, U, W, property_checker):
if PLOT:
num_dim_x = len(X0)
plot_data = [np.empty(0, dtype=float), np.empty((0, num_dim_x), dtype=float)]
else:
plot_data = None
Ti = TT[0]
Tf = TT[1]
T = Tf - Ti
self.solver.set_solout(solout_fun(property_checker, plot_data)) # (2)
self.solver.set_initial_value(X0, t=0.0)
self.solver.set_f_params(W)
X_ = self.solver.integrate(T)
pvf = property_checker.check(Tf, X_)
dummy_D = np.zeros(D.shape)
dummy_P = np.zeros(P.shape)
ret_t = Tf
ret_X = X_
ret_D = dummy_D
ret_P = dummy_P
if PLOT:
PLT.figure(5)
PLT.plot(plot_data[0], plot_data[1][:, 0])
return (ret_t, ret_X, ret_D, ret_P), pvf
# State Space Modeling Template
# dx/dt = Ax + Bu
# y = Cx + Du
def dyn(t, X, w):
if w > 0:
u = 1.0
elif w < 0:
u = -1.0
else:
u = 0.0
x2 = u
X_ = np.array([x2])
return X_
def solout_fun(property_checker, plot_data):
def solout(t, Y):
if PLOT:
plot_data[0] = np.concatenate((plot_data[0], np.array([t])))
plot_data[1] = np.concatenate((plot_data[1], np.array([Y])))
if property_checker.check(t, Y):
#violating_state[0] = (np.copy(t), np.copy(Y))
# print 'violation found:', violating_state[0]
# return -1 to stop integration
return -1
else:
return 0
return 0
return solout
|
bsd-2-clause
|
[
199,
3,
9498,
23082,
314,
4955,
199,
3,
359,
84,
12,
56,
12,
36,
12,
48,
61,
275,
4389,
63,
1593,
8,
52,
12,
56,
16,
12,
36,
16,
12,
48,
16,
12,
41,
16,
2736,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
14,
26248,
492,
312,
271,
199,
199,
646,
8027,
14,
13563,
465,
10092,
52,
199,
199,
2749,
1387,
275,
715,
421,
199,
533,
428,
1469,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
4488,
12,
299,
5941,
63,
826,
63,
576,
304,
267,
327,
1361,
473,
267,
327,
9543,
275,
413,
69,
13,
709,
267,
10561,
275,
413,
69,
13,
21,
267,
327,
13638,
12,
7080,
12,
5869,
63,
36,
12,
5869,
63,
48,
267,
291,
14,
11263,
275,
312,
271,
8,
17883,
680,
409,
63,
25323,
707,
360,
68,
21993,
21,
297,
10561,
29,
23565,
9,
267,
372,
339,
347,
4389,
8,
277,
12,
377,
52,
12,
1323,
16,
12,
577,
12,
510,
12,
738,
12,
644,
12,
3324,
63,
6743,
304,
398,
340,
10092,
1387,
26,
288,
1967,
63,
3572,
63,
88,
275,
822,
8,
56,
16,
9,
288,
5137,
63,
576,
275,
359,
1590,
14,
1667,
8,
16,
12,
2152,
29,
1609,
395,
980,
14,
1667,
1332,
16,
12,
1967,
63,
3572,
63,
88,
395,
2152,
29,
1609,
1874,
267,
587,
26,
288,
5137,
63,
576,
275,
488,
398,
377,
73,
275,
377,
52,
59,
16,
61,
267,
377,
70,
275,
377,
52,
59,
17,
61,
267,
377,
275,
377,
70,
446,
377,
73,
398,
291,
14,
11263,
14,
409,
63,
1152,
22316,
8,
1152,
22316,
63,
7036,
8,
1829,
63,
6743,
12,
5137,
63,
576,
430,
221,
327,
334,
18,
9,
267,
291,
14,
11263,
14,
409,
63,
2747,
63,
585,
8,
56,
16,
12,
307,
29,
16,
14,
16,
9,
267,
291,
14,
11263,
14,
409,
63,
70,
63,
1162,
8,
55,
9,
267,
1323,
63,
275,
291,
14,
11263,
14,
26248,
8,
52,
9,
398,
299,
19963,
275,
3324,
63,
6743,
14,
1074,
8,
52,
70,
12,
1323,
4602,
398,
7283,
63,
36,
275,
980,
14,
4250,
8,
36,
14,
1392,
9,
267,
7283,
63,
48,
275,
980,
14,
4250,
8,
48,
14,
1392,
9,
267,
2203,
63,
84,
275,
377,
70,
267,
2203,
63,
56,
275,
1323,
63,
267,
2203,
63,
36,
275,
7283,
63,
36,
267,
2203,
63,
48,
275,
7283,
63,
48,
398,
340,
10092,
1387,
26,
288,
10092,
52,
14,
8941,
8,
21,
9,
288,
10092,
52,
14,
2798,
8,
2798,
63,
576,
59,
16,
467,
5137,
63,
576,
59,
17,
61,
3981,
378,
566,
398,
372,
334,
3292,
63,
84,
12,
2203,
63,
56,
12,
2203,
63,
36,
12,
2203,
63,
48,
395,
299,
19963,
421,
199,
3,
8511,
19326,
4900,
2983,
5458,
199,
3,
11868,
15,
3583,
275,
437,
88,
435,
4779,
199,
3,
612,
275,
445,
88,
435,
577,
85,
199,
318,
25653,
8,
84,
12,
1323,
12,
336,
304,
339,
340,
336,
690,
378,
26,
267,
399,
275,
413,
14,
16,
272,
916,
336,
665,
378,
26,
267,
399,
275,
446,
17,
14,
16,
272,
587,
26,
267,
399,
275,
378,
14,
16,
339,
671,
18,
275,
399,
272,
1323,
63,
275,
980,
14,
1144,
779,
88,
18,
566,
272,
372,
1323,
63,
421,
199,
318,
880,
22316,
63,
7036,
8,
1829,
63,
6743,
12,
5137,
63,
576,
304,
339,
347,
880,
22316,
8,
84,
12,
1488,
304,
267,
340,
10092,
1387,
26,
288,
5137,
63,
576,
59,
16,
61,
275,
980,
14,
13433,
1332,
2798,
63,
576,
59,
16,
467,
980,
14,
1144,
779,
84,
11845,
288,
5137,
63,
576,
59,
17,
61,
275,
980,
14,
13433,
1332,
2798,
63,
576,
59,
17,
467,
980,
14,
1144,
779,
57,
11845,
398,
340,
3324,
63,
6743,
14,
1074,
8,
84,
12,
1488,
304,
288,
327,
433,
393,
1958,
63,
929,
59,
16,
61,
275,
334,
1590,
14,
1574,
8,
84,
395,
980,
14,
1574,
8,
57,
430,
288,
327,
870,
283,
433,
10410,
1911,
6536,
1321,
393,
1958,
63,
929,
59,
16,
61,
288,
327,
372,
446,
17,
370,
3631,
13150,
288,
372,
446,
17,
267,
587,
26,
288,
372,
378,
398,
372,
378,
339,
372,
880,
22316,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3,
9498,
23082,
314,
4955,
199,
3,
359,
84,
12,
56,
12,
36,
12,
48,
61,
275,
4389,
63,
1593,
8,
52,
12,
56,
16,
12,
36,
16,
12,
48,
16,
12,
41,
16,
2736,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
14,
26248,
492,
312,
271,
199,
199,
646,
8027,
14,
13563,
465,
10092,
52,
199,
199,
2749,
1387,
275,
715,
421,
199,
533,
428,
1469,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
4488,
12,
299,
5941,
63,
826,
63,
576,
304,
267,
327,
1361,
473,
267,
327,
9543,
275,
413,
69,
13,
709,
267,
10561,
275,
413,
69,
13,
21,
267,
327,
13638,
12,
7080,
12,
5869,
63,
36,
12,
5869,
63,
48,
267,
291,
14,
11263,
275,
312,
271,
8,
17883,
680,
409,
63,
25323,
707,
360,
68,
21993,
21,
297,
10561,
29,
23565,
9,
267,
372,
339,
347,
4389,
8,
277,
12,
377,
52,
12,
1323,
16,
12,
577,
12,
510,
12,
738,
12,
644,
12,
3324,
63,
6743,
304,
398,
340,
10092,
1387,
26,
288,
1967,
63,
3572,
63,
88,
275,
822,
8,
56,
16,
9,
288,
5137,
63,
576,
275,
359,
1590,
14,
1667,
8,
16,
12,
2152,
29,
1609,
395,
980,
14,
1667,
1332,
16,
12,
1967,
63,
3572,
63,
88,
395,
2152,
29,
1609,
1874,
267,
587,
26,
288,
5137,
63,
576,
275,
488,
398,
377,
73,
275,
377,
52,
59,
16,
61,
267,
377,
70,
275,
377,
52,
59,
17,
61,
267,
377,
275,
377,
70,
446,
377,
73,
398,
291,
14,
11263,
14,
409,
63,
1152,
22316,
8,
1152,
22316,
63,
7036,
8,
1829,
63,
6743,
12,
5137,
63,
576,
430,
221,
327,
334,
18,
9,
267,
291,
14,
11263,
14,
409,
63,
2747,
63,
585,
8,
56,
16,
12,
307,
29,
16,
14,
16,
9,
267,
291,
14,
11263,
14,
409,
63,
70,
63,
1162,
8,
55,
9,
267,
1323,
63,
275,
291,
14,
11263,
14,
26248,
8,
52,
9,
398,
299,
19963,
275,
3324,
63,
6743,
14,
1074,
8,
52,
70,
12,
1323,
4602,
398,
7283,
63,
36,
275,
980,
14,
4250,
8,
36,
14,
1392,
9,
267,
7283,
63,
48,
275,
980,
14,
4250,
8,
48,
14,
1392,
9,
267,
2203,
63,
84,
275,
377,
70,
267,
2203,
63,
56,
275,
1323,
63,
267,
2203,
63,
36,
275,
7283,
63,
36,
267,
2203,
63,
48,
275,
7283,
63,
48,
398,
340,
10092,
1387,
26,
288,
10092,
52,
14,
8941,
8,
21,
9,
288,
10092,
52,
14,
2798,
8,
2798,
63,
576,
59,
16,
467,
5137,
63,
576,
59,
17,
61,
3981,
378,
566,
398,
372,
334,
3292,
63,
84,
12,
2203,
63,
56,
12,
2203,
63,
36,
12,
2203,
63,
48,
395,
299,
19963,
421,
199,
3,
8511,
19326,
4900,
2983,
5458,
199,
3,
11868,
15,
3583,
275,
437,
88,
435,
4779,
199,
3,
612,
275,
445,
88,
435,
577,
85,
199,
318,
25653,
8,
84,
12,
1323,
12,
336,
304,
339,
340,
336,
690,
378,
26,
267,
399,
275,
413,
14,
16,
272,
916,
336,
665,
378,
26,
267,
399,
275,
446,
17,
14,
16,
272,
587,
26,
267,
399,
275,
378,
14,
16,
339,
671,
18,
275,
399,
272,
1323,
63,
275,
980,
14,
1144,
779,
88,
18,
566,
272,
372,
1323,
63,
421,
199,
318,
880,
22316,
63,
7036,
8,
1829,
63,
6743,
12,
5137,
63,
576,
304,
339,
347,
880,
22316,
8,
84,
12,
1488,
304,
267,
340,
10092,
1387,
26,
288,
5137,
63,
576,
59,
16,
61,
275,
980,
14,
13433,
1332,
2798,
63,
576,
59,
16,
467,
980,
14,
1144,
779,
84,
11845,
288,
5137,
63,
576,
59,
17,
61,
275,
980,
14,
13433,
1332,
2798,
63,
576,
59,
17,
467,
980,
14,
1144,
779,
57,
11845,
398,
340,
3324,
63,
6743,
14,
1074,
8,
84,
12,
1488,
304,
288,
327,
433,
393,
1958,
63,
929,
59,
16,
61,
275,
334,
1590,
14,
1574,
8,
84,
395,
980,
14,
1574,
8,
57,
430,
288,
327,
870,
283,
433,
10410,
1911,
6536,
1321,
393,
1958,
63,
929,
59,
16,
61,
288,
327,
372,
446,
17,
370,
3631,
13150,
288,
372,
446,
17,
267,
587,
26,
288,
372,
378,
398,
372,
378,
339,
372,
880,
22316,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
irwinlove/django
|
django/middleware/cache.py
|
372
|
7303
|
"""
Cache middleware. If enabled, each Django-powered page will be cached based on
URL. The canonical way to enable cache middleware is to set
``UpdateCacheMiddleware`` as your first piece of middleware, and
``FetchFromCacheMiddleware`` as the last::
MIDDLEWARE_CLASSES = [
'django.middleware.cache.UpdateCacheMiddleware',
...
'django.middleware.cache.FetchFromCacheMiddleware'
]
This is counter-intuitive, but correct: ``UpdateCacheMiddleware`` needs to run
last during the response phase, which processes middleware bottom-up;
``FetchFromCacheMiddleware`` needs to run last during the request phase, which
processes middleware top-down.
The single-class ``CacheMiddleware`` can be used for some simple sites.
However, if any other piece of middleware needs to affect the cache key, you'll
need to use the two-part ``UpdateCacheMiddleware`` and
``FetchFromCacheMiddleware``. This'll most often happen when you're using
Django's ``LocaleMiddleware``.
More details about how the caching works:
* Only GET or HEAD-requests with status code 200 are cached.
* The number of seconds each page is stored for is set by the "max-age" section
of the response's "Cache-Control" header, falling back to the
CACHE_MIDDLEWARE_SECONDS setting if the section was not found.
* This middleware expects that a HEAD request is answered with the same response
headers exactly like the corresponding GET request.
* When a hit occurs, a shallow copy of the original response object is returned
from process_request.
* Pages will be cached based on the contents of the request headers listed in
the response's "Vary" header.
* This middleware also sets ETag, Last-Modified, Expires and Cache-Control
headers on the response object.
"""
from django.conf import settings
from django.core.cache import DEFAULT_CACHE_ALIAS, caches
from django.utils.cache import (
get_cache_key, get_max_age, has_vary_header, learn_cache_key,
patch_response_headers,
)
class UpdateCacheMiddleware(object):
"""
Response-phase cache middleware that updates the cache if the response is
cacheable.
Must be used as part of the two-part update/fetch cache middleware.
UpdateCacheMiddleware must be the first piece of middleware in
MIDDLEWARE_CLASSES so that it'll get called last during the response phase.
"""
def __init__(self):
self.cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
self.key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
self.cache_alias = settings.CACHE_MIDDLEWARE_ALIAS
self.cache = caches[self.cache_alias]
def _should_update_cache(self, request, response):
return hasattr(request, '_cache_update_cache') and request._cache_update_cache
def process_response(self, request, response):
"""Sets the cache, if needed."""
if not self._should_update_cache(request, response):
# We don't need to update the cache, just return.
return response
if response.streaming or response.status_code != 200:
return response
# Don't cache responses that set a user-specific (and maybe security
# sensitive) cookie in response to a cookie-less request.
if not request.COOKIES and response.cookies and has_vary_header(response, 'Cookie'):
return response
# Try to get the timeout from the "max-age" section of the "Cache-
# Control" header before reverting to using the default cache_timeout
# length.
timeout = get_max_age(response)
if timeout is None:
timeout = self.cache_timeout
elif timeout == 0:
# max-age was set to 0, don't bother caching.
return response
patch_response_headers(response, timeout)
if timeout:
cache_key = learn_cache_key(request, response, timeout, self.key_prefix, cache=self.cache)
if hasattr(response, 'render') and callable(response.render):
response.add_post_render_callback(
lambda r: self.cache.set(cache_key, r, timeout)
)
else:
self.cache.set(cache_key, response, timeout)
return response
class FetchFromCacheMiddleware(object):
"""
Request-phase cache middleware that fetches a page from the cache.
Must be used as part of the two-part update/fetch cache middleware.
FetchFromCacheMiddleware must be the last piece of middleware in
MIDDLEWARE_CLASSES so that it'll get called last during the request phase.
"""
def __init__(self):
self.key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
self.cache_alias = settings.CACHE_MIDDLEWARE_ALIAS
self.cache = caches[self.cache_alias]
def process_request(self, request):
"""
Checks whether the page is already cached and returns the cached
version if available.
"""
if request.method not in ('GET', 'HEAD'):
request._cache_update_cache = False
return None # Don't bother checking the cache.
# try and get the cached GET response
cache_key = get_cache_key(request, self.key_prefix, 'GET', cache=self.cache)
if cache_key is None:
request._cache_update_cache = True
return None # No cache information available, need to rebuild.
response = self.cache.get(cache_key)
# if it wasn't found and we are looking for a HEAD, try looking just for that
if response is None and request.method == 'HEAD':
cache_key = get_cache_key(request, self.key_prefix, 'HEAD', cache=self.cache)
response = self.cache.get(cache_key)
if response is None:
request._cache_update_cache = True
return None # No cache information available, need to rebuild.
# hit, return cached response
request._cache_update_cache = False
return response
class CacheMiddleware(UpdateCacheMiddleware, FetchFromCacheMiddleware):
"""
Cache middleware that provides basic behavior for many simple sites.
Also used as the hook point for the cache decorator, which is generated
using the decorator-from-middleware utility.
"""
def __init__(self, cache_timeout=None, **kwargs):
# We need to differentiate between "provided, but using default value",
# and "not provided". If the value is provided using a default, then
# we fall back to system defaults. If it is not provided at all,
# we need to use middleware defaults.
try:
key_prefix = kwargs['key_prefix']
if key_prefix is None:
key_prefix = ''
except KeyError:
key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
self.key_prefix = key_prefix
try:
cache_alias = kwargs['cache_alias']
if cache_alias is None:
cache_alias = DEFAULT_CACHE_ALIAS
except KeyError:
cache_alias = settings.CACHE_MIDDLEWARE_ALIAS
self.cache_alias = cache_alias
if cache_timeout is None:
cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
self.cache_timeout = cache_timeout
self.cache = caches[self.cache_alias]
|
bsd-3-clause
|
[
624,
199,
4437,
10816,
14,
982,
5223,
12,
1924,
5634,
13,
555,
21221,
2034,
911,
506,
6328,
4079,
641,
199,
2632,
14,
710,
11358,
4340,
370,
4756,
2581,
10816,
365,
370,
663,
199,
1040,
4152,
4437,
6608,
1040,
465,
2195,
1642,
14854,
402,
10816,
12,
436,
199,
1040,
11135,
2532,
4437,
6608,
1040,
465,
314,
2061,
447,
339,
30718,
63,
13748,
275,
359,
267,
283,
1176,
14,
5754,
14,
1637,
14,
4152,
4437,
6608,
297,
267,
2263,
267,
283,
1176,
14,
5754,
14,
1637,
14,
11135,
2532,
4437,
6608,
7,
272,
1622,
199,
199,
2765,
365,
7055,
13,
442,
1907,
857,
12,
1325,
3211,
26,
1124,
4152,
4437,
6608,
1040,
4839,
370,
1255,
199,
2019,
5309,
314,
1177,
7669,
12,
1314,
10358,
10816,
9048,
13,
384,
27,
199,
1040,
11135,
2532,
4437,
6608,
1040,
4839,
370,
1255,
2061,
5309,
314,
1056,
7669,
12,
1314,
199,
11816,
10816,
2746,
13,
2110,
14,
199,
199,
1918,
2849,
13,
533,
1124,
4437,
6608,
1040,
883,
506,
1202,
367,
2005,
3486,
15424,
14,
199,
18335,
5907,
12,
340,
1263,
1163,
14854,
402,
10816,
4839,
370,
12787,
314,
2581,
790,
12,
1265,
7171,
199,
9321,
370,
675,
314,
2877,
13,
2064,
1124,
4152,
4437,
6608,
1040,
436,
199,
1040,
11135,
2532,
4437,
6608,
4345,
961,
7171,
4750,
14115,
5992,
1380,
1265,
3984,
1808,
199,
9323,
1159,
1124,
20342,
6608,
4345,
199,
199,
11053,
2436,
3595,
4212,
314,
13627,
5419,
26,
199,
199,
10,
5972,
9576,
503,
13053,
13,
6615,
543,
2004,
1233,
1926,
787,
6328,
14,
199,
199,
10,
710,
1329,
402,
4696,
1924,
2034,
365,
5489,
367,
365,
663,
701,
314,
298,
988,
13,
474,
2,
3420,
523,
402,
314,
1177,
1159,
298,
4437,
13,
3717,
2,
1406,
12,
32039,
1771,
370,
314,
523,
7240,
4576,
63,
19987,
63,
23319,
4260,
340,
314,
3420,
1990,
440,
1911,
14,
199,
199,
10,
961,
10816,
14292,
626,
282,
13053,
1056,
365,
4987,
21221,
543,
314,
2011,
1177,
523,
2323,
8840,
2839,
314,
5226,
9576,
1056,
14,
199,
199,
10,
3979,
282,
9793,
11058,
12,
282,
23834,
1331,
402,
314,
3379,
1177,
909,
365,
2138,
523,
687,
2112,
63,
1069,
14,
199,
199,
10,
510,
7441,
911,
506,
6328,
4079,
641,
314,
4072,
402,
314,
1056,
2323,
10532,
315,
523,
314,
1177,
1159,
298,
54,
695,
2,
1406,
14,
199,
199,
10,
961,
10816,
2597,
5951,
662,
1931,
12,
15237,
13,
11911,
12,
1316,
1038,
470,
436,
11977,
13,
3717,
523,
2323,
641,
314,
1177,
909,
14,
199,
199,
624,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
1637,
492,
6186,
63,
8677,
63,
12644,
12,
18014,
199,
504,
1639,
14,
1208,
14,
1637,
492,
334,
272,
664,
63,
1637,
63,
498,
12,
664,
63,
988,
63,
474,
12,
965,
63,
21989,
63,
1291,
12,
12537,
63,
1637,
63,
498,
12,
272,
3371,
63,
1310,
63,
2139,
12,
199,
9,
421,
199,
533,
6162,
4437,
6608,
8,
785,
304,
272,
408,
272,
7232,
13,
6971,
2581,
10816,
626,
7029,
314,
2581,
340,
314,
1177,
365,
272,
2581,
461,
14,
339,
9498,
506,
1202,
465,
1777,
402,
314,
2877,
13,
2064,
1678,
15,
3535,
2581,
10816,
14,
272,
6162,
4437,
6608,
1471,
506,
314,
1642,
14854,
402,
10816,
315,
272,
30718,
63,
13748,
880,
626,
652,
7171,
664,
2797,
2061,
5309,
314,
1177,
7669,
14,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1637,
63,
2593,
275,
2202,
14,
8677,
63,
19987,
63,
23319,
267,
291,
14,
498,
63,
1861,
275,
2202,
14,
8677,
63,
19987,
63,
3078,
63,
6351,
267,
291,
14,
1637,
63,
3620,
275,
2202,
14,
8677,
63,
19987,
63,
12644,
267,
291,
14,
1637,
275,
18014,
59,
277,
14,
1637,
63,
3620,
61,
339,
347,
485,
5626,
63,
873,
63,
1637,
8,
277,
12,
1056,
12,
1177,
304,
267,
372,
2688,
8,
1069,
12,
2513,
1637,
63,
873,
63,
1637,
358,
436,
1056,
423,
1637,
63,
873,
63,
1637,
339,
347,
2112,
63,
1310,
8,
277,
12,
1056,
12,
1177,
304,
267,
408,
9899,
314,
2581,
12,
340,
4346,
1041,
267,
340,
440,
291,
423,
5626,
63,
873,
63,
1637,
8,
1069,
12,
1177,
304,
288,
327,
2136,
2793,
1133,
1929,
370,
1678,
314,
2581,
12,
2951,
372,
14,
288,
372,
1177,
398,
340,
1177,
14,
12076,
503,
1177,
14,
1205,
63,
600,
1137,
1926,
26,
288,
372,
1177,
398,
327,
7529,
1133,
2581,
9320,
626,
663,
282,
922,
13,
6100,
334,
460,
11703,
6391,
267,
327,
18423,
9,
5494,
315,
1177,
370,
282,
5494,
13,
2003,
1056,
14,
267,
340,
440,
1056,
14,
12189,
2563,
436,
1177,
14,
7792,
436,
965,
63,
21989,
63,
1291,
8,
1310,
12,
283,
7810,
735,
288,
372,
1177,
398,
327,
7649,
370,
664,
314,
2653,
687,
314,
298,
988,
13,
474,
2,
3420,
402,
314,
298,
4437,
13,
267,
327,
8612,
2,
1406,
2544,
29465,
1337,
370,
1808,
314,
849,
2581,
63,
2593,
267,
327,
2582,
14,
267,
2653,
275,
664,
63,
988,
63,
474,
8,
1310,
9,
267,
340,
2653,
365,
488,
26,
288,
2653,
275,
291,
14,
1637,
63,
2593,
267,
916,
2653,
508,
378,
26,
288,
327,
1390,
13,
474,
1990,
663,
370,
378,
12,
2793,
1133,
26962,
13627,
14,
288,
372,
1177,
267,
3371,
63,
1310,
63,
2139,
8,
1310,
12,
2653,
9,
267,
340,
2653,
26,
288,
2581,
63,
498,
275,
12537,
63,
1637,
63,
498,
8,
1069,
12,
1177,
12,
2653,
12,
291,
14,
498,
63,
1861,
12,
2581,
29,
277,
14,
1637,
9,
288,
340,
2688,
8,
1310,
12,
283,
3352,
358,
436,
4550,
8,
1310,
14,
3352,
304,
355,
1177,
14,
525,
63,
1932,
63,
3352,
63,
3058,
8,
490,
2400,
519,
26,
291,
14,
1637,
14,
409,
8,
1637,
63,
498,
12,
519,
12,
2653,
9,
355,
776,
288,
587,
26,
355,
291,
14,
1637,
14,
409,
8,
1637,
63,
498,
12,
1177,
12,
2653,
9,
267,
372,
1177,
421,
199,
533,
16347,
2532,
4437,
6608,
8,
785,
304,
272,
408,
272,
4784,
13,
6971,
2581,
10816,
626,
28053,
282,
2034,
687,
314,
2581,
14,
339,
9498,
506,
1202,
465,
1777,
402,
314,
2877,
13,
2064,
1678,
15,
3535,
2581,
10816,
14
] |
[
199,
4437,
10816,
14,
982,
5223,
12,
1924,
5634,
13,
555,
21221,
2034,
911,
506,
6328,
4079,
641,
199,
2632,
14,
710,
11358,
4340,
370,
4756,
2581,
10816,
365,
370,
663,
199,
1040,
4152,
4437,
6608,
1040,
465,
2195,
1642,
14854,
402,
10816,
12,
436,
199,
1040,
11135,
2532,
4437,
6608,
1040,
465,
314,
2061,
447,
339,
30718,
63,
13748,
275,
359,
267,
283,
1176,
14,
5754,
14,
1637,
14,
4152,
4437,
6608,
297,
267,
2263,
267,
283,
1176,
14,
5754,
14,
1637,
14,
11135,
2532,
4437,
6608,
7,
272,
1622,
199,
199,
2765,
365,
7055,
13,
442,
1907,
857,
12,
1325,
3211,
26,
1124,
4152,
4437,
6608,
1040,
4839,
370,
1255,
199,
2019,
5309,
314,
1177,
7669,
12,
1314,
10358,
10816,
9048,
13,
384,
27,
199,
1040,
11135,
2532,
4437,
6608,
1040,
4839,
370,
1255,
2061,
5309,
314,
1056,
7669,
12,
1314,
199,
11816,
10816,
2746,
13,
2110,
14,
199,
199,
1918,
2849,
13,
533,
1124,
4437,
6608,
1040,
883,
506,
1202,
367,
2005,
3486,
15424,
14,
199,
18335,
5907,
12,
340,
1263,
1163,
14854,
402,
10816,
4839,
370,
12787,
314,
2581,
790,
12,
1265,
7171,
199,
9321,
370,
675,
314,
2877,
13,
2064,
1124,
4152,
4437,
6608,
1040,
436,
199,
1040,
11135,
2532,
4437,
6608,
4345,
961,
7171,
4750,
14115,
5992,
1380,
1265,
3984,
1808,
199,
9323,
1159,
1124,
20342,
6608,
4345,
199,
199,
11053,
2436,
3595,
4212,
314,
13627,
5419,
26,
199,
199,
10,
5972,
9576,
503,
13053,
13,
6615,
543,
2004,
1233,
1926,
787,
6328,
14,
199,
199,
10,
710,
1329,
402,
4696,
1924,
2034,
365,
5489,
367,
365,
663,
701,
314,
298,
988,
13,
474,
2,
3420,
523,
402,
314,
1177,
1159,
298,
4437,
13,
3717,
2,
1406,
12,
32039,
1771,
370,
314,
523,
7240,
4576,
63,
19987,
63,
23319,
4260,
340,
314,
3420,
1990,
440,
1911,
14,
199,
199,
10,
961,
10816,
14292,
626,
282,
13053,
1056,
365,
4987,
21221,
543,
314,
2011,
1177,
523,
2323,
8840,
2839,
314,
5226,
9576,
1056,
14,
199,
199,
10,
3979,
282,
9793,
11058,
12,
282,
23834,
1331,
402,
314,
3379,
1177,
909,
365,
2138,
523,
687,
2112,
63,
1069,
14,
199,
199,
10,
510,
7441,
911,
506,
6328,
4079,
641,
314,
4072,
402,
314,
1056,
2323,
10532,
315,
523,
314,
1177,
1159,
298,
54,
695,
2,
1406,
14,
199,
199,
10,
961,
10816,
2597,
5951,
662,
1931,
12,
15237,
13,
11911,
12,
1316,
1038,
470,
436,
11977,
13,
3717,
523,
2323,
641,
314,
1177,
909,
14,
199,
199,
624,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
1637,
492,
6186,
63,
8677,
63,
12644,
12,
18014,
199,
504,
1639,
14,
1208,
14,
1637,
492,
334,
272,
664,
63,
1637,
63,
498,
12,
664,
63,
988,
63,
474,
12,
965,
63,
21989,
63,
1291,
12,
12537,
63,
1637,
63,
498,
12,
272,
3371,
63,
1310,
63,
2139,
12,
199,
9,
421,
199,
533,
6162,
4437,
6608,
8,
785,
304,
272,
408,
272,
7232,
13,
6971,
2581,
10816,
626,
7029,
314,
2581,
340,
314,
1177,
365,
272,
2581,
461,
14,
339,
9498,
506,
1202,
465,
1777,
402,
314,
2877,
13,
2064,
1678,
15,
3535,
2581,
10816,
14,
272,
6162,
4437,
6608,
1471,
506,
314,
1642,
14854,
402,
10816,
315,
272,
30718,
63,
13748,
880,
626,
652,
7171,
664,
2797,
2061,
5309,
314,
1177,
7669,
14,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1637,
63,
2593,
275,
2202,
14,
8677,
63,
19987,
63,
23319,
267,
291,
14,
498,
63,
1861,
275,
2202,
14,
8677,
63,
19987,
63,
3078,
63,
6351,
267,
291,
14,
1637,
63,
3620,
275,
2202,
14,
8677,
63,
19987,
63,
12644,
267,
291,
14,
1637,
275,
18014,
59,
277,
14,
1637,
63,
3620,
61,
339,
347,
485,
5626,
63,
873,
63,
1637,
8,
277,
12,
1056,
12,
1177,
304,
267,
372,
2688,
8,
1069,
12,
2513,
1637,
63,
873,
63,
1637,
358,
436,
1056,
423,
1637,
63,
873,
63,
1637,
339,
347,
2112,
63,
1310,
8,
277,
12,
1056,
12,
1177,
304,
267,
408,
9899,
314,
2581,
12,
340,
4346,
1041,
267,
340,
440,
291,
423,
5626,
63,
873,
63,
1637,
8,
1069,
12,
1177,
304,
288,
327,
2136,
2793,
1133,
1929,
370,
1678,
314,
2581,
12,
2951,
372,
14,
288,
372,
1177,
398,
340,
1177,
14,
12076,
503,
1177,
14,
1205,
63,
600,
1137,
1926,
26,
288,
372,
1177,
398,
327,
7529,
1133,
2581,
9320,
626,
663,
282,
922,
13,
6100,
334,
460,
11703,
6391,
267,
327,
18423,
9,
5494,
315,
1177,
370,
282,
5494,
13,
2003,
1056,
14,
267,
340,
440,
1056,
14,
12189,
2563,
436,
1177,
14,
7792,
436,
965,
63,
21989,
63,
1291,
8,
1310,
12,
283,
7810,
735,
288,
372,
1177,
398,
327,
7649,
370,
664,
314,
2653,
687,
314,
298,
988,
13,
474,
2,
3420,
402,
314,
298,
4437,
13,
267,
327,
8612,
2,
1406,
2544,
29465,
1337,
370,
1808,
314,
849,
2581,
63,
2593,
267,
327,
2582,
14,
267,
2653,
275,
664,
63,
988,
63,
474,
8,
1310,
9,
267,
340,
2653,
365,
488,
26,
288,
2653,
275,
291,
14,
1637,
63,
2593,
267,
916,
2653,
508,
378,
26,
288,
327,
1390,
13,
474,
1990,
663,
370,
378,
12,
2793,
1133,
26962,
13627,
14,
288,
372,
1177,
267,
3371,
63,
1310,
63,
2139,
8,
1310,
12,
2653,
9,
267,
340,
2653,
26,
288,
2581,
63,
498,
275,
12537,
63,
1637,
63,
498,
8,
1069,
12,
1177,
12,
2653,
12,
291,
14,
498,
63,
1861,
12,
2581,
29,
277,
14,
1637,
9,
288,
340,
2688,
8,
1310,
12,
283,
3352,
358,
436,
4550,
8,
1310,
14,
3352,
304,
355,
1177,
14,
525,
63,
1932,
63,
3352,
63,
3058,
8,
490,
2400,
519,
26,
291,
14,
1637,
14,
409,
8,
1637,
63,
498,
12,
519,
12,
2653,
9,
355,
776,
288,
587,
26,
355,
291,
14,
1637,
14,
409,
8,
1637,
63,
498,
12,
1177,
12,
2653,
9,
267,
372,
1177,
421,
199,
533,
16347,
2532,
4437,
6608,
8,
785,
304,
272,
408,
272,
4784,
13,
6971,
2581,
10816,
626,
28053,
282,
2034,
687,
314,
2581,
14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