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
|
|---|---|---|---|---|---|---|---|---|
mozilla/peekaboo
|
bin/update/deploy.py
|
1
|
3513
|
"""
Deploy this project in dev/stage/production.
Requires commander_ which is installed on the systems that need it.
.. _commander: https://github.com/oremj/commander
This script is supposed to work in Python 2.6.
The only outside dependency is `virtualenv-2.7`.
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from commander.deploy import task
import commander_settings as settings
venv_path = '../venv'
py_path = venv_path + '/bin/python'
@task
def update_code(ctx, tag):
"""Update the code to a specific git reference (tag/sha/etc)."""
with ctx.lcd(settings.SRC_DIR):
ctx.local('git fetch')
ctx.local('git checkout -f %s' % tag)
ctx.local("find . -type f -name '*.pyc' -delete")
# Creating a virtualenv tries to open virtualenv/bin/python for
# writing, but because virtualenv is using it, it fails.
# So we delete it and let virtualenv create a new one.
ctx.local('rm -f {0}/bin/python {1}/bin/python2.7'.format(
venv_path,
venv_path,
))
ctx.local('virtualenv-2.7 {0}'.format(venv_path))
# Activate virtualenv to append to path.
activate_env = os.path.join(
settings.SRC_DIR, venv_path, 'bin', 'activate_this.py'
)
execfile(activate_env, dict(__file__=activate_env))
ctx.local('{0}/bin/pip install bin/peep-2.*.tar.gz'.format(venv_path))
ctx.local('{0}/bin/peep install -r requirements.txt'.format(venv_path))
ctx.local('virtualenv-2.7 --relocatable {0}'.format(venv_path))
@task
def update_assets(ctx):
with ctx.lcd(settings.SRC_DIR):
ctx.local('{0} manage.py collectstatic --noinput'.format(py_path))
@task
def update_db(ctx):
"""Update the database schema, if necessary."""
with ctx.lcd(settings.SRC_DIR):
ctx.local(
'{0} manage.py migrate'.format(py_path)
)
@task
def install_cron(ctx):
"""Use gen-crons.py method to install new crontab.
Ops will need to adjust this to put it in the right place.
"""
with ctx.lcd(settings.SRC_DIR):
ctx.local(
'{0} ./bin/crontab/gen-crons.py -w {1} -u apache > '
'/etc/cron.d/.{2}'.format(
py_path,
settings.SRC_DIR,
settings.CRON_NAME
)
)
ctx.local(
'mv /etc/cron.d/.{0} /etc/cron.d/{1}'.format(
settings.CRON_NAME,
settings.CRON_NAME
)
)
@task
def deploy_app(ctx):
"""Call the remote update script to push changes to webheads."""
ctx.local('/bin/touch %s' % settings.LOCAL_WSGI)
@task
def update_info(ctx):
"""Write info about the current state to a publicly visible file."""
with ctx.lcd(settings.SRC_DIR):
ctx.local('date')
ctx.local('git branch')
ctx.local('git log -3')
ctx.local('git status')
ctx.local('git submodule status')
ctx.local('git rev-parse HEAD > media/revision.txt')
@task
def pre_update(ctx, ref=settings.UPDATE_REF):
"""Update code to pick up changes to this file."""
update_code(ref)
@task
def update(ctx):
update_assets()
# update_locales() # commented out till we switch on i18n
update_db()
@task
def deploy(ctx):
install_cron()
deploy_app()
update_info()
@task
def update_site(ctx, tag):
"""Update the app to prep for deployment."""
pre_update(tag)
update()
|
mpl-2.0
|
[
624,
199,
27597,
642,
2199,
315,
4866,
15,
8614,
15,
10777,
14,
199,
199,
18153,
1923,
11438,
63,
1314,
365,
4903,
641,
314,
10460,
626,
1929,
652,
14,
199,
199,
703,
485,
1404,
11438,
26,
4178,
921,
5031,
14,
957,
15,
720,
77,
74,
15,
1404,
11438,
199,
199,
2765,
2884,
365,
20042,
370,
1736,
315,
2018,
499,
14,
22,
14,
199,
1918,
1454,
9682,
5936,
365,
658,
21611,
13,
18,
14,
23,
2313,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
29658,
199,
199,
504,
1923,
11438,
14,
11060,
492,
2120,
199,
646,
1923,
11438,
63,
1751,
465,
2202,
199,
199,
23195,
63,
515,
275,
20644,
23195,
7,
199,
647,
63,
515,
275,
373,
1813,
63,
515,
435,
1994,
1393,
15,
1548,
7,
421,
199,
32,
1765,
199,
318,
1678,
63,
600,
8,
3799,
12,
1947,
304,
272,
408,
4152,
314,
1233,
370,
282,
2488,
6135,
3659,
334,
1450,
15,
4835,
15,
6839,
10477,
272,
543,
4027,
14,
31670,
8,
1751,
14,
12447,
63,
3022,
304,
267,
4027,
14,
1832,
360,
3187,
5267,
358,
267,
4027,
14,
1832,
360,
3187,
15243,
446,
70,
450,
83,
7,
450,
1947,
9,
267,
4027,
14,
1832,
480,
1623,
1275,
446,
466,
289,
446,
354,
11937,
11357,
7,
446,
1807,
531,
398,
327,
20507,
282,
19128,
11275,
370,
1551,
19128,
15,
1393,
15,
1548,
367,
267,
327,
3575,
12,
1325,
2952,
19128,
365,
1808,
652,
12,
652,
6918,
14,
267,
327,
2002,
781,
3145,
652,
436,
4691,
19128,
1218,
282,
892,
1373,
14,
267,
4027,
14,
1832,
360,
5682,
446,
70,
469,
16,
5995,
1393,
15,
1548,
469,
17,
5995,
1393,
15,
1548,
18,
14,
23,
1370,
908,
8,
288,
373,
1813,
63,
515,
12,
288,
373,
1813,
63,
515,
12,
267,
5082,
267,
4027,
14,
1832,
360,
21611,
13,
18,
14,
23,
469,
16,
5285,
908,
8,
23195,
63,
515,
430,
398,
327,
21904,
2409,
19128,
370,
5666,
370,
931,
14,
267,
15422,
63,
1813,
275,
747,
14,
515,
14,
904,
8,
288,
2202,
14,
12447,
63,
3022,
12,
373,
1813,
63,
515,
12,
283,
1393,
297,
283,
8222,
63,
3749,
14,
647,
7,
267,
776,
267,
22711,
8,
8222,
63,
1813,
12,
1211,
3460,
493,
363,
29,
8222,
63,
1813,
430,
398,
4027,
14,
1832,
11117,
16,
5995,
1393,
15,
9983,
3907,
2517,
15,
321,
1545,
13,
18,
2795,
14,
5369,
14,
6838,
1370,
908,
8,
23195,
63,
515,
430,
267,
4027,
14,
1832,
11117,
16,
5995,
1393,
15,
321,
1545,
3907,
446,
82,
9760,
14,
2424,
1370,
908,
8,
23195,
63,
515,
430,
267,
4027,
14,
1832,
360,
21611,
13,
18,
14,
23,
1553,
264,
2102,
15511,
469,
16,
5285,
908,
8,
23195,
63,
515,
430,
421,
199,
32,
1765,
199,
318,
1678,
63,
12186,
8,
3799,
304,
272,
543,
4027,
14,
31670,
8,
1751,
14,
12447,
63,
3022,
304,
267,
4027,
14,
1832,
11117,
16,
93,
9635,
14,
647,
8775,
1986,
1553,
889,
1210,
1370,
908,
8,
647,
63,
515,
430,
421,
199,
32,
1765,
199,
318,
1678,
63,
697,
8,
3799,
304,
272,
408,
4152,
314,
3050,
4177,
12,
340,
5784,
1041,
339,
543,
4027,
14,
31670,
8,
1751,
14,
12447,
63,
3022,
304,
267,
4027,
14,
1832,
8,
288,
5041,
16,
93,
9635,
14,
647,
12810,
1370,
908,
8,
647,
63,
515,
9,
267,
776,
421,
199,
32,
1765,
199,
318,
3907,
63,
14829,
8,
3799,
304,
272,
408,
6119,
3805,
13,
1556,
4654,
14,
647,
1083,
370,
3907,
892,
2467,
30578,
14,
339,
593,
1190,
911,
1929,
370,
11311,
642,
370,
5324,
652,
315,
314,
2451,
4192,
14,
339,
408,
272,
543,
4027,
14,
31670,
8,
1751,
14,
12447,
63,
3022,
304,
267,
4027,
14,
1832,
8,
288,
5041,
16,
93,
16605,
1393,
15,
1556,
30578,
15,
2268,
13,
1556,
4654,
14,
647,
446,
87,
469,
17,
93,
446,
85,
17098,
690,
283,
288,
1994,
6839,
15,
14829,
14,
68,
8083,
91,
18,
5285,
908,
8,
355,
1134,
63,
515,
12,
355,
2202,
14,
12447,
63,
3022,
12,
355,
2202,
14,
2944,
615,
63,
2339,
288,
776,
267,
776,
267,
4027,
14,
1832,
8,
288,
283,
12393,
1182,
6839,
15,
14829,
14,
68,
8083,
91,
16,
93,
1182,
6839,
15,
14829,
14,
68,
5321,
17,
5285,
908,
8,
355,
2202,
14,
2944,
615,
63,
2339,
12,
355,
2202,
14,
2944,
615,
63,
2339,
288,
776,
267,
776,
421,
199,
32,
1765,
199,
318,
12287,
63,
571,
8,
3799,
304,
272,
408,
2176,
314,
3982,
1678,
2884,
370,
6675,
4493,
370,
3330,
17033,
1041,
272,
4027,
14,
1832,
2336,
1393,
15,
12376,
450,
83,
7,
450,
2202,
14,
7486,
63,
16828,
9,
421,
199,
32,
1765,
199,
318,
1678,
63,
815,
8,
3799,
304,
272,
408,
3534,
2256,
3595,
314,
1453,
1174,
370,
282,
7974,
317,
429,
89,
8917,
570,
1041,
272,
543,
4027,
14,
31670,
8,
1751,
14,
12447,
63,
3022,
304,
267,
4027,
14,
1832,
360,
602,
358,
267,
4027,
14,
1832,
360,
3187,
5246,
358,
267,
4027,
14,
1832,
360,
3187,
943,
446,
19,
358,
267,
4027,
14,
1832,
360,
3187,
2004,
358,
267,
4027,
14,
1832,
360,
3187,
22988,
2004,
358,
267,
4027,
14,
1832,
360,
3187,
6822,
13,
1122,
13053,
690,
5898,
15,
5792,
14,
2424,
358,
421,
199,
32,
1765,
199,
318,
876,
63,
873,
8,
3799,
12,
2984,
29,
1751,
14,
10383,
63,
8279,
304,
272,
408,
4152,
1233,
370,
3732,
1536,
4493,
370,
642,
570,
1041,
272,
1678,
63,
600,
8,
1121,
9,
421,
199,
32,
1765,
199,
318,
1678,
8,
3799,
304,
272,
1678,
63,
12186,
342,
272,
327,
1678,
63,
24763,
342,
221,
327,
21804,
734,
31801,
781,
6258,
641,
284,
1085,
78,
272,
1678,
63,
697,
342,
421,
199,
32,
1765,
199,
318,
12287,
8,
3799,
304,
272,
3907,
63,
14829,
342,
272,
12287,
63,
571,
342,
272,
1678,
63,
815,
342,
421,
199,
32,
1765,
199,
318,
1678,
63,
2124,
8,
3799,
12,
1947,
304,
272,
408,
4152,
314,
1145,
370,
19986,
367,
14295,
1041,
272,
876,
63,
873,
8,
1450,
9,
272,
1678,
342,
199,
32768
] |
[
199,
27597,
642,
2199,
315,
4866,
15,
8614,
15,
10777,
14,
199,
199,
18153,
1923,
11438,
63,
1314,
365,
4903,
641,
314,
10460,
626,
1929,
652,
14,
199,
199,
703,
485,
1404,
11438,
26,
4178,
921,
5031,
14,
957,
15,
720,
77,
74,
15,
1404,
11438,
199,
199,
2765,
2884,
365,
20042,
370,
1736,
315,
2018,
499,
14,
22,
14,
199,
1918,
1454,
9682,
5936,
365,
658,
21611,
13,
18,
14,
23,
2313,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
29658,
199,
199,
504,
1923,
11438,
14,
11060,
492,
2120,
199,
646,
1923,
11438,
63,
1751,
465,
2202,
199,
199,
23195,
63,
515,
275,
20644,
23195,
7,
199,
647,
63,
515,
275,
373,
1813,
63,
515,
435,
1994,
1393,
15,
1548,
7,
421,
199,
32,
1765,
199,
318,
1678,
63,
600,
8,
3799,
12,
1947,
304,
272,
408,
4152,
314,
1233,
370,
282,
2488,
6135,
3659,
334,
1450,
15,
4835,
15,
6839,
10477,
272,
543,
4027,
14,
31670,
8,
1751,
14,
12447,
63,
3022,
304,
267,
4027,
14,
1832,
360,
3187,
5267,
358,
267,
4027,
14,
1832,
360,
3187,
15243,
446,
70,
450,
83,
7,
450,
1947,
9,
267,
4027,
14,
1832,
480,
1623,
1275,
446,
466,
289,
446,
354,
11937,
11357,
7,
446,
1807,
531,
398,
327,
20507,
282,
19128,
11275,
370,
1551,
19128,
15,
1393,
15,
1548,
367,
267,
327,
3575,
12,
1325,
2952,
19128,
365,
1808,
652,
12,
652,
6918,
14,
267,
327,
2002,
781,
3145,
652,
436,
4691,
19128,
1218,
282,
892,
1373,
14,
267,
4027,
14,
1832,
360,
5682,
446,
70,
469,
16,
5995,
1393,
15,
1548,
469,
17,
5995,
1393,
15,
1548,
18,
14,
23,
1370,
908,
8,
288,
373,
1813,
63,
515,
12,
288,
373,
1813,
63,
515,
12,
267,
5082,
267,
4027,
14,
1832,
360,
21611,
13,
18,
14,
23,
469,
16,
5285,
908,
8,
23195,
63,
515,
430,
398,
327,
21904,
2409,
19128,
370,
5666,
370,
931,
14,
267,
15422,
63,
1813,
275,
747,
14,
515,
14,
904,
8,
288,
2202,
14,
12447,
63,
3022,
12,
373,
1813,
63,
515,
12,
283,
1393,
297,
283,
8222,
63,
3749,
14,
647,
7,
267,
776,
267,
22711,
8,
8222,
63,
1813,
12,
1211,
3460,
493,
363,
29,
8222,
63,
1813,
430,
398,
4027,
14,
1832,
11117,
16,
5995,
1393,
15,
9983,
3907,
2517,
15,
321,
1545,
13,
18,
2795,
14,
5369,
14,
6838,
1370,
908,
8,
23195,
63,
515,
430,
267,
4027,
14,
1832,
11117,
16,
5995,
1393,
15,
321,
1545,
3907,
446,
82,
9760,
14,
2424,
1370,
908,
8,
23195,
63,
515,
430,
267,
4027,
14,
1832,
360,
21611,
13,
18,
14,
23,
1553,
264,
2102,
15511,
469,
16,
5285,
908,
8,
23195,
63,
515,
430,
421,
199,
32,
1765,
199,
318,
1678,
63,
12186,
8,
3799,
304,
272,
543,
4027,
14,
31670,
8,
1751,
14,
12447,
63,
3022,
304,
267,
4027,
14,
1832,
11117,
16,
93,
9635,
14,
647,
8775,
1986,
1553,
889,
1210,
1370,
908,
8,
647,
63,
515,
430,
421,
199,
32,
1765,
199,
318,
1678,
63,
697,
8,
3799,
304,
272,
408,
4152,
314,
3050,
4177,
12,
340,
5784,
1041,
339,
543,
4027,
14,
31670,
8,
1751,
14,
12447,
63,
3022,
304,
267,
4027,
14,
1832,
8,
288,
5041,
16,
93,
9635,
14,
647,
12810,
1370,
908,
8,
647,
63,
515,
9,
267,
776,
421,
199,
32,
1765,
199,
318,
3907,
63,
14829,
8,
3799,
304,
272,
408,
6119,
3805,
13,
1556,
4654,
14,
647,
1083,
370,
3907,
892,
2467,
30578,
14,
339,
593,
1190,
911,
1929,
370,
11311,
642,
370,
5324,
652,
315,
314,
2451,
4192,
14,
339,
408,
272,
543,
4027,
14,
31670,
8,
1751,
14,
12447,
63,
3022,
304,
267,
4027,
14,
1832,
8,
288,
5041,
16,
93,
16605,
1393,
15,
1556,
30578,
15,
2268,
13,
1556,
4654,
14,
647,
446,
87,
469,
17,
93,
446,
85,
17098,
690,
283,
288,
1994,
6839,
15,
14829,
14,
68,
8083,
91,
18,
5285,
908,
8,
355,
1134,
63,
515,
12,
355,
2202,
14,
12447,
63,
3022,
12,
355,
2202,
14,
2944,
615,
63,
2339,
288,
776,
267,
776,
267,
4027,
14,
1832,
8,
288,
283,
12393,
1182,
6839,
15,
14829,
14,
68,
8083,
91,
16,
93,
1182,
6839,
15,
14829,
14,
68,
5321,
17,
5285,
908,
8,
355,
2202,
14,
2944,
615,
63,
2339,
12,
355,
2202,
14,
2944,
615,
63,
2339,
288,
776,
267,
776,
421,
199,
32,
1765,
199,
318,
12287,
63,
571,
8,
3799,
304,
272,
408,
2176,
314,
3982,
1678,
2884,
370,
6675,
4493,
370,
3330,
17033,
1041,
272,
4027,
14,
1832,
2336,
1393,
15,
12376,
450,
83,
7,
450,
2202,
14,
7486,
63,
16828,
9,
421,
199,
32,
1765,
199,
318,
1678,
63,
815,
8,
3799,
304,
272,
408,
3534,
2256,
3595,
314,
1453,
1174,
370,
282,
7974,
317,
429,
89,
8917,
570,
1041,
272,
543,
4027,
14,
31670,
8,
1751,
14,
12447,
63,
3022,
304,
267,
4027,
14,
1832,
360,
602,
358,
267,
4027,
14,
1832,
360,
3187,
5246,
358,
267,
4027,
14,
1832,
360,
3187,
943,
446,
19,
358,
267,
4027,
14,
1832,
360,
3187,
2004,
358,
267,
4027,
14,
1832,
360,
3187,
22988,
2004,
358,
267,
4027,
14,
1832,
360,
3187,
6822,
13,
1122,
13053,
690,
5898,
15,
5792,
14,
2424,
358,
421,
199,
32,
1765,
199,
318,
876,
63,
873,
8,
3799,
12,
2984,
29,
1751,
14,
10383,
63,
8279,
304,
272,
408,
4152,
1233,
370,
3732,
1536,
4493,
370,
642,
570,
1041,
272,
1678,
63,
600,
8,
1121,
9,
421,
199,
32,
1765,
199,
318,
1678,
8,
3799,
304,
272,
1678,
63,
12186,
342,
272,
327,
1678,
63,
24763,
342,
221,
327,
21804,
734,
31801,
781,
6258,
641,
284,
1085,
78,
272,
1678,
63,
697,
342,
421,
199,
32,
1765,
199,
318,
12287,
8,
3799,
304,
272,
3907,
63,
14829,
342,
272,
12287,
63,
571,
342,
272,
1678,
63,
815,
342,
421,
199,
32,
1765,
199,
318,
1678,
63,
2124,
8,
3799,
12,
1947,
304,
272,
408,
4152,
314,
1145,
370,
19986,
367,
14295,
1041,
272,
876,
63,
873,
8,
1450,
9,
272,
1678,
342,
199,
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,
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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,
0
] |
ar7z1/ansible
|
lib/ansible/module_utils/online.py
|
73
|
3824
|
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import json
import sys
from ansible.module_utils.basic import env_fallback
from ansible.module_utils.urls import fetch_url
def online_argument_spec():
return dict(
api_token=dict(required=True, fallback=(env_fallback, ['ONLINE_TOKEN', 'ONLINE_API_KEY', 'ONLINE_OAUTH_TOKEN', 'ONLINE_API_TOKEN']),
no_log=True, aliases=['oauth_token']),
api_url=dict(fallback=(env_fallback, ['ONLINE_API_URL']), default='https://api.online.net', aliases=['base_url']),
api_timeout=dict(type='int', default=30, aliases=['timeout']),
validate_certs=dict(default=True, type='bool'),
)
class OnlineException(Exception):
def __init__(self, message):
self.message = message
class Response(object):
def __init__(self, resp, info):
self.body = None
if resp:
self.body = resp.read()
self.info = info
@property
def json(self):
if not self.body:
if "body" in self.info:
return json.loads(self.info["body"])
return None
try:
return json.loads(self.body)
except ValueError:
return None
@property
def status_code(self):
return self.info["status"]
@property
def ok(self):
return self.status_code in (200, 201, 202, 204)
class Online(object):
def __init__(self, module):
self.module = module
self.headers = {
'Authorization': "Bearer %s" % self.module.params.get('api_token'),
'User-Agent': self.get_user_agent_string(module),
'Content-type': 'application/json',
}
self.name = None
def get_resources(self):
results = self.get('/%s' % self.name)
if not results.ok:
raise OnlineException('Error fetching {0} ({1}) [{2}: {3}]'.format(
self.name, '%s/%s' % (self.module.params.get('api_url'), self.name),
results.status_code, results.json['message']
))
return results.json
def _url_builder(self, path):
if path[0] == '/':
path = path[1:]
return '%s/%s' % (self.module.params.get('api_url'), path)
def send(self, method, path, data=None, headers=None):
url = self._url_builder(path)
data = self.module.jsonify(data)
if headers is not None:
self.headers.update(headers)
resp, info = fetch_url(
self.module, url, data=data, headers=self.headers, method=method,
timeout=self.module.params.get('api_timeout')
)
# Exceptions in fetch_url may result in a status -1, the ensures a proper error to the user in all cases
if info['status'] == -1:
self.module.fail_json(msg=info['msg'])
return Response(resp, info)
@staticmethod
def get_user_agent_string(module):
return "ansible %s Python %s" % (module.ansible_version, sys.version.split(' ')[0])
def get(self, path, data=None, headers=None):
return self.send('GET', path, data, headers)
def put(self, path, data=None, headers=None):
return self.send('PUT', path, data, headers)
def post(self, path, data=None, headers=None):
return self.send('POST', path, data, headers)
def delete(self, path, data=None, headers=None):
return self.send('DELETE', path, data, headers)
def patch(self, path, data=None, headers=None):
return self.send("PATCH", path, data, headers)
def update(self, path, data=None, headers=None):
return self.send("UPDATE", path, data, headers)
|
gpl-3.0
|
[
3,
29094,
30200,
6289,
844,
334,
3239,
12378,
15,
11184,
30200,
63,
15746,
14,
2424,
503,
4178,
921,
16374,
14,
1308,
15,
2383,
15,
15400,
13,
18,
13,
16009,
9,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
2022,
199,
646,
984,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
2589,
63,
10538,
199,
504,
3242,
14,
578,
63,
1208,
14,
3603,
492,
5267,
63,
633,
421,
199,
318,
18470,
63,
2094,
63,
1650,
837,
272,
372,
1211,
8,
267,
2986,
63,
1418,
29,
807,
8,
2427,
29,
549,
12,
9567,
2687,
1813,
63,
10538,
12,
788,
615,
6174,
63,
8803,
297,
283,
615,
6174,
63,
3735,
63,
3078,
297,
283,
615,
6174,
63,
24041,
63,
8803,
297,
283,
615,
6174,
63,
3735,
63,
8803,
3815,
2432,
949,
63,
793,
29,
549,
12,
5481,
2968,
6126,
63,
1418,
3815,
267,
2986,
63,
633,
29,
807,
8,
10538,
2687,
1813,
63,
10538,
12,
788,
615,
6174,
63,
3735,
63,
2632,
3815,
849,
534,
2859,
921,
1246,
14,
15178,
14,
846,
297,
5481,
2968,
1095,
63,
633,
3815,
267,
2986,
63,
2593,
29,
807,
8,
466,
534,
442,
297,
849,
29,
1216,
12,
5481,
2968,
2593,
3815,
267,
4107,
63,
8356,
29,
807,
8,
885,
29,
549,
12,
730,
534,
2245,
659,
272,
776,
421,
199,
533,
4068,
604,
1726,
8,
1726,
304,
339,
347,
636,
826,
721,
277,
12,
1245,
304,
267,
291,
14,
1188,
275,
1245,
421,
199,
533,
7232,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
3085,
12,
2256,
304,
267,
291,
14,
2030,
275,
488,
267,
340,
3085,
26,
288,
291,
14,
2030,
275,
3085,
14,
739,
342,
267,
291,
14,
815,
275,
2256,
339,
768,
1829,
272,
347,
2022,
8,
277,
304,
267,
340,
440,
291,
14,
2030,
26,
288,
340,
298,
2030,
2,
315,
291,
14,
815,
26,
355,
372,
2022,
14,
3640,
8,
277,
14,
815,
905,
2030,
3135,
288,
372,
488,
267,
862,
26,
288,
372,
2022,
14,
3640,
8,
277,
14,
2030,
9,
267,
871,
1722,
26,
288,
372,
488,
339,
768,
1829,
272,
347,
2004,
63,
600,
8,
277,
304,
267,
372,
291,
14,
815,
905,
1205,
937,
339,
768,
1829,
272,
347,
4112,
8,
277,
304,
267,
372,
291,
14,
1205,
63,
600,
315,
334,
1840,
12,
1784,
12,
19328,
12,
14785,
9,
421,
199,
533,
4068,
604,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
859,
304,
267,
291,
14,
578,
275,
859,
267,
291,
14,
2139,
275,
469,
288,
283,
11626,
356,
298,
3655,
21462,
450,
83,
2,
450,
291,
14,
578,
14,
1162,
14,
362,
360,
1246,
63,
1418,
659,
288,
283,
1899,
13,
7788,
356,
291,
14,
362,
63,
751,
63,
4054,
63,
875,
8,
578,
395,
288,
283,
2714,
13,
466,
356,
283,
3578,
15,
1001,
297,
267,
789,
267,
291,
14,
354,
275,
488,
339,
347,
664,
63,
4435,
8,
277,
304,
267,
2058,
275,
291,
14,
362,
2336,
5,
83,
7,
450,
291,
14,
354,
9,
267,
340,
440,
2058,
14,
745,
26,
288,
746,
4068,
604,
1726,
360,
547,
21239,
469,
16,
93,
11459,
17,
1552,
8910,
18,
9160,
469,
19,
11049,
1370,
908,
8,
355,
291,
14,
354,
12,
1543,
83,
3149,
83,
7,
450,
334,
277,
14,
578,
14,
1162,
14,
362,
360,
1246,
63,
633,
659,
291,
14,
354,
395,
355,
2058,
14,
1205,
63,
600,
12,
2058,
14,
1001,
459,
1188,
418,
288,
5082,
398,
372,
2058,
14,
1001,
339,
347,
485,
633,
63,
5649,
8,
277,
12,
931,
304,
267,
340,
931,
59,
16,
61,
508,
20549,
288,
931,
275,
931,
59,
17,
2938,
267,
372,
1543,
83,
3149,
83,
7,
450,
334,
277,
14,
578,
14,
1162,
14,
362,
360,
1246,
63,
633,
659,
931,
9,
339,
347,
3222,
8,
277,
12,
1083,
12,
931,
12,
666,
29,
403,
12,
2323,
29,
403,
304,
267,
1166,
275,
291,
423,
633,
63,
5649,
8,
515,
9,
267,
666,
275,
291,
14,
578,
14,
1001,
2021,
8,
576,
9,
398,
340,
2323,
365,
440,
488,
26,
288,
291,
14,
2139,
14,
873,
8,
2139,
9,
398,
3085,
12,
2256,
275,
5267,
63,
633,
8,
288,
291,
14,
578,
12,
1166,
12,
666,
29,
576,
12,
2323,
29,
277,
14,
2139,
12,
1083,
29,
765,
12,
288,
2653,
29,
277,
14,
578,
14,
1162,
14,
362,
360,
1246,
63,
2593,
358,
267,
776,
398,
327,
24873,
315,
5267,
63,
633,
1443,
754,
315,
282,
2004,
446,
17,
12,
314,
15620,
282,
5576,
1125,
370,
314,
922,
315,
1006,
5560,
267,
340,
2256,
459,
1205,
418,
508,
446,
17,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
8,
1328,
29,
815,
459,
1328,
1105,
398,
372,
7232,
8,
4518,
12,
2256,
9,
339,
768,
4639,
272,
347,
664,
63,
751,
63,
4054,
63,
875,
8,
578,
304,
267,
372,
298,
4853,
450,
83,
2018,
450,
83,
2,
450,
334,
578,
14,
4853,
63,
1023,
12,
984,
14,
1023,
14,
1294,
360,
27618,
16,
566,
339,
347,
664,
8,
277,
12,
931,
12,
666,
29,
403,
12,
2323,
29,
403,
304,
267,
372,
291,
14,
2254,
360,
2970,
297,
931,
12,
666,
12,
2323,
9,
339,
347,
5324,
8,
277,
12,
931,
12,
666,
29,
403,
12,
2323,
29,
403,
304,
267,
372,
291,
14,
2254,
360,
4013,
297,
931,
12,
666,
12,
2323,
9,
339,
347,
2963,
8,
277,
12,
931,
12,
666,
29,
403,
12,
2323,
29,
403,
304,
267,
372,
291,
14,
2254,
360,
4030,
297,
931,
12,
666,
12,
2323,
9,
339,
347,
3145,
8,
277,
12,
931,
12,
666,
29,
403,
12,
2323,
29,
403,
304,
267,
372,
291,
14,
2254,
360,
7014,
297,
931,
12,
666,
12,
2323,
9,
339,
347,
3371,
8,
277,
12,
931,
12,
666,
29,
403,
12,
2323,
29,
403,
304,
267,
372,
291,
14,
2254,
480,
17073,
401,
931,
12,
666,
12,
2323,
9,
339,
347,
1678,
8,
277,
12,
931,
12,
666,
29,
403,
12,
2323,
29,
403,
304,
267,
372,
291,
14,
2254,
480,
10383
] |
[
29094,
30200,
6289,
844,
334,
3239,
12378,
15,
11184,
30200,
63,
15746,
14,
2424,
503,
4178,
921,
16374,
14,
1308,
15,
2383,
15,
15400,
13,
18,
13,
16009,
9,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
2022,
199,
646,
984,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
2589,
63,
10538,
199,
504,
3242,
14,
578,
63,
1208,
14,
3603,
492,
5267,
63,
633,
421,
199,
318,
18470,
63,
2094,
63,
1650,
837,
272,
372,
1211,
8,
267,
2986,
63,
1418,
29,
807,
8,
2427,
29,
549,
12,
9567,
2687,
1813,
63,
10538,
12,
788,
615,
6174,
63,
8803,
297,
283,
615,
6174,
63,
3735,
63,
3078,
297,
283,
615,
6174,
63,
24041,
63,
8803,
297,
283,
615,
6174,
63,
3735,
63,
8803,
3815,
2432,
949,
63,
793,
29,
549,
12,
5481,
2968,
6126,
63,
1418,
3815,
267,
2986,
63,
633,
29,
807,
8,
10538,
2687,
1813,
63,
10538,
12,
788,
615,
6174,
63,
3735,
63,
2632,
3815,
849,
534,
2859,
921,
1246,
14,
15178,
14,
846,
297,
5481,
2968,
1095,
63,
633,
3815,
267,
2986,
63,
2593,
29,
807,
8,
466,
534,
442,
297,
849,
29,
1216,
12,
5481,
2968,
2593,
3815,
267,
4107,
63,
8356,
29,
807,
8,
885,
29,
549,
12,
730,
534,
2245,
659,
272,
776,
421,
199,
533,
4068,
604,
1726,
8,
1726,
304,
339,
347,
636,
826,
721,
277,
12,
1245,
304,
267,
291,
14,
1188,
275,
1245,
421,
199,
533,
7232,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
3085,
12,
2256,
304,
267,
291,
14,
2030,
275,
488,
267,
340,
3085,
26,
288,
291,
14,
2030,
275,
3085,
14,
739,
342,
267,
291,
14,
815,
275,
2256,
339,
768,
1829,
272,
347,
2022,
8,
277,
304,
267,
340,
440,
291,
14,
2030,
26,
288,
340,
298,
2030,
2,
315,
291,
14,
815,
26,
355,
372,
2022,
14,
3640,
8,
277,
14,
815,
905,
2030,
3135,
288,
372,
488,
267,
862,
26,
288,
372,
2022,
14,
3640,
8,
277,
14,
2030,
9,
267,
871,
1722,
26,
288,
372,
488,
339,
768,
1829,
272,
347,
2004,
63,
600,
8,
277,
304,
267,
372,
291,
14,
815,
905,
1205,
937,
339,
768,
1829,
272,
347,
4112,
8,
277,
304,
267,
372,
291,
14,
1205,
63,
600,
315,
334,
1840,
12,
1784,
12,
19328,
12,
14785,
9,
421,
199,
533,
4068,
604,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
859,
304,
267,
291,
14,
578,
275,
859,
267,
291,
14,
2139,
275,
469,
288,
283,
11626,
356,
298,
3655,
21462,
450,
83,
2,
450,
291,
14,
578,
14,
1162,
14,
362,
360,
1246,
63,
1418,
659,
288,
283,
1899,
13,
7788,
356,
291,
14,
362,
63,
751,
63,
4054,
63,
875,
8,
578,
395,
288,
283,
2714,
13,
466,
356,
283,
3578,
15,
1001,
297,
267,
789,
267,
291,
14,
354,
275,
488,
339,
347,
664,
63,
4435,
8,
277,
304,
267,
2058,
275,
291,
14,
362,
2336,
5,
83,
7,
450,
291,
14,
354,
9,
267,
340,
440,
2058,
14,
745,
26,
288,
746,
4068,
604,
1726,
360,
547,
21239,
469,
16,
93,
11459,
17,
1552,
8910,
18,
9160,
469,
19,
11049,
1370,
908,
8,
355,
291,
14,
354,
12,
1543,
83,
3149,
83,
7,
450,
334,
277,
14,
578,
14,
1162,
14,
362,
360,
1246,
63,
633,
659,
291,
14,
354,
395,
355,
2058,
14,
1205,
63,
600,
12,
2058,
14,
1001,
459,
1188,
418,
288,
5082,
398,
372,
2058,
14,
1001,
339,
347,
485,
633,
63,
5649,
8,
277,
12,
931,
304,
267,
340,
931,
59,
16,
61,
508,
20549,
288,
931,
275,
931,
59,
17,
2938,
267,
372,
1543,
83,
3149,
83,
7,
450,
334,
277,
14,
578,
14,
1162,
14,
362,
360,
1246,
63,
633,
659,
931,
9,
339,
347,
3222,
8,
277,
12,
1083,
12,
931,
12,
666,
29,
403,
12,
2323,
29,
403,
304,
267,
1166,
275,
291,
423,
633,
63,
5649,
8,
515,
9,
267,
666,
275,
291,
14,
578,
14,
1001,
2021,
8,
576,
9,
398,
340,
2323,
365,
440,
488,
26,
288,
291,
14,
2139,
14,
873,
8,
2139,
9,
398,
3085,
12,
2256,
275,
5267,
63,
633,
8,
288,
291,
14,
578,
12,
1166,
12,
666,
29,
576,
12,
2323,
29,
277,
14,
2139,
12,
1083,
29,
765,
12,
288,
2653,
29,
277,
14,
578,
14,
1162,
14,
362,
360,
1246,
63,
2593,
358,
267,
776,
398,
327,
24873,
315,
5267,
63,
633,
1443,
754,
315,
282,
2004,
446,
17,
12,
314,
15620,
282,
5576,
1125,
370,
314,
922,
315,
1006,
5560,
267,
340,
2256,
459,
1205,
418,
508,
446,
17,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
8,
1328,
29,
815,
459,
1328,
1105,
398,
372,
7232,
8,
4518,
12,
2256,
9,
339,
768,
4639,
272,
347,
664,
63,
751,
63,
4054,
63,
875,
8,
578,
304,
267,
372,
298,
4853,
450,
83,
2018,
450,
83,
2,
450,
334,
578,
14,
4853,
63,
1023,
12,
984,
14,
1023,
14,
1294,
360,
27618,
16,
566,
339,
347,
664,
8,
277,
12,
931,
12,
666,
29,
403,
12,
2323,
29,
403,
304,
267,
372,
291,
14,
2254,
360,
2970,
297,
931,
12,
666,
12,
2323,
9,
339,
347,
5324,
8,
277,
12,
931,
12,
666,
29,
403,
12,
2323,
29,
403,
304,
267,
372,
291,
14,
2254,
360,
4013,
297,
931,
12,
666,
12,
2323,
9,
339,
347,
2963,
8,
277,
12,
931,
12,
666,
29,
403,
12,
2323,
29,
403,
304,
267,
372,
291,
14,
2254,
360,
4030,
297,
931,
12,
666,
12,
2323,
9,
339,
347,
3145,
8,
277,
12,
931,
12,
666,
29,
403,
12,
2323,
29,
403,
304,
267,
372,
291,
14,
2254,
360,
7014,
297,
931,
12,
666,
12,
2323,
9,
339,
347,
3371,
8,
277,
12,
931,
12,
666,
29,
403,
12,
2323,
29,
403,
304,
267,
372,
291,
14,
2254,
480,
17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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
] |
mrshu/scikit-learn
|
sklearn/preprocessing.py
|
1
|
40726
|
# Authors: Alexandre Gramfort <alexandre.gramfort@inria.fr>
# Mathieu Blondel <mathieu@mblondel.org>
# Olivier Grisel <olivier.grisel@ensta.org>
# Andreas Mueller <amueller@ais.uni-bonn.de>
# License: BSD
from collections import Sequence
import warnings
import numbers
import numpy as np
import scipy.sparse as sp
from .utils import check_arrays, array2d, atleast2d_or_csr, safe_asarray
from .utils import warn_if_not_float
from .utils.fixes import unique
from .base import BaseEstimator, TransformerMixin
from .utils.sparsefuncs import inplace_csr_row_normalize_l1
from .utils.sparsefuncs import inplace_csr_row_normalize_l2
from .utils.sparsefuncs import inplace_csr_column_scale
from .utils.sparsefuncs import mean_variance_axis0
__all__ = ['Binarizer',
'KernelCenterer',
'LabelBinarizer',
'LabelEncoder',
'Normalizer',
'StandardScaler',
'binarize',
'normalize',
'scale']
def _mean_and_std(X, axis=0, with_mean=True, with_std=True):
"""Compute mean and std deviation for centering, scaling.
Zero valued std components are reset to 1.0 to avoid NaNs when scaling.
"""
X = np.asarray(X)
Xr = np.rollaxis(X, axis)
if with_mean:
mean_ = Xr.mean(axis=0)
else:
mean_ = None
if with_std:
std_ = Xr.std(axis=0)
if isinstance(std_, np.ndarray):
std_[std_ == 0.0] = 1.0
elif std_ == 0.:
std_ = 1.
else:
std_ = None
return mean_, std_
def scale(X, axis=0, with_mean=True, with_std=True, copy=True):
"""Standardize a dataset along any axis
Center to the mean and component wise scale to unit variance.
Parameters
----------
X : array-like or CSR matrix.
The data to center and scale.
axis : int (0 by default)
axis used to compute the means and standard deviations along. If 0,
independently standardize each feature, otherwise (if 1) standardize
each sample.
with_mean : boolean, True by default
If True, center the data before scaling.
with_std : boolean, True by default
If True, scale the data to unit variance (or equivalently,
unit standard deviation).
copy : boolean, optional, default is True
set to False to perform inplace row normalization and avoid a
copy (if the input is already a numpy array or a scipy.sparse
CSR matrix and if axis is 1).
Notes
-----
This implementation will refuse to center scipy.sparse matrices
since it would make them non-sparse and would potentially crash the
program with memory exhaustion problems.
Instead the caller is expected to either set explicitly
`with_mean=False` (in that case, only variance scaling will be
performed on the features of the CSR matrix) or to call `X.toarray()`
if he/she expects the materialized dense array to fit in memory.
To avoid memory copy the caller should pass a CSR matrix.
See also
--------
:class:`sklearn.preprocessing.StandardScaler` to perform centering and
scaling using the ``Transformer`` API (e.g. as part of a preprocessing
:class:`sklearn.pipeline.Pipeline`)
"""
if sp.issparse(X):
if with_mean:
raise ValueError(
"Cannot center sparse matrices: pass `with_mean=False` instead"
" See docstring for motivation and alternatives.")
if axis != 0:
raise ValueError("Can only scale sparse matrix on axis=0, "
" got axis=%d" % axis)
warn_if_not_float(X, estimator='The scale function')
if not sp.isspmatrix_csr(X):
X = X.tocsr()
copy = False
if copy:
X = X.copy()
_, var = mean_variance_axis0(X)
var[var == 0.0] = 1.0
inplace_csr_column_scale(X, 1 / np.sqrt(var))
else:
X = np.asarray(X)
warn_if_not_float(X, estimator='The scale function')
mean_, std_ = _mean_and_std(
X, axis, with_mean=with_mean, with_std=with_std)
if copy:
X = X.copy()
# Xr is a view on the original array that enables easy use of
# broadcasting on the axis in which we are interested in
Xr = np.rollaxis(X, axis)
if with_mean:
Xr -= mean_
if with_std:
Xr /= std_
return X
class MinMaxScaler(BaseEstimator, TransformerMixin):
"""Standardizes features by scaling each feature to a given range.
This estimator scales and translates each feature individually such
that it is in the given range on the training set, i.e. between
zero and one.
The standardization is given by::
X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0))
X_scaled = X_std / (max - min) + min
where min, max = feature_range.
This standardization is often used as an alternative to zero mean,
unit variance scaling.
Parameters
----------
feature_range: tuple (min, max), default=(0, 1)
Desired range of transformed data.
copy : boolean, optional, default is True
Set to False to perform inplace row normalization and avoid a
copy (if the input is already a numpy array).
Attributes
----------
min_ : ndarray, shape (n_features,)
Per feature adjustment for minimum.
scale_ : ndarray, shape (n_features,)
Per feature relative scaling of the data.
"""
def __init__(self, feature_range=(0, 1), copy=True):
self.feature_range = feature_range
self.copy = copy
def fit(self, X, y=None):
"""Compute the minimum and maximum to be used for later scaling.
Parameters
----------
X : array-like, shape [n_samples, n_features]
The data used to compute the per-feature minimum and maximum
used for later scaling along the features axis.
"""
X = check_arrays(X, sparse_format="dense", copy=self.copy)[0]
warn_if_not_float(X, estimator=self)
feature_range = self.feature_range
if feature_range[0] >= feature_range[1]:
raise ValueError("Minimum of desired feature range must be smaller"
" than maximum. Got %s." % str(feature_range))
min_ = np.min(X, axis=0)
scale_ = np.max(X, axis=0) - min_
# Do not scale constant features
scale_[scale_ == 0.0] = 1.0
self.scale_ = (feature_range[1] - feature_range[0]) / scale_
self.min_ = feature_range[0] - min_ / scale_
return self
def transform(self, X):
"""Scaling features of X according to feature_range.
Parameters
----------
X : array-like with shape [n_samples, n_features]
Input data that will be transformed.
"""
X = check_arrays(X, sparse_format="dense", copy=self.copy)[0]
X *= self.scale_
X += self.min_
return X
class StandardScaler(BaseEstimator, TransformerMixin):
"""Standardize features by removing the mean and scaling to unit variance
Centering and scaling happen indepently on each feature by computing
the relevant statistics on the samples in the training set. Mean and
standard deviation are then stored to be used on later data using the
`transform` method.
Standardization of a dataset is a common requirement for many
machine learning estimators: they might behave badly if the
individual feature do not more or less look like standard normally
distributed data (e.g. Gaussian with 0 mean and unit variance).
For instance many elements used in the objective function of
a learning algorithm (such as the RBF kernel of Support Vector
Machines or the L1 and L2 regularizers of linear models) assume that
all features are centered around 0 and have variance in the same
order. If a feature has a variance that is orders of magnitude larger
that others, it might dominate the objective function and make the
estimator unable to learn from other features correctly as expected.
Parameters
----------
with_mean : boolean, True by default
If True, center the data before scaling.
with_std : boolean, True by default
If True, scale the data to unit variance (or equivalently,
unit standard deviation).
copy : boolean, optional, default is True
Set to False to perform inplace row normalization and avoid a
copy (if the input is already a numpy array or a scipy.sparse
CSR matrix and if axis is 1).
Attributes
----------
`mean_` : array of floats with shape [n_features]
The mean value for each feature in the training set.
`std_` : array of floats with shape [n_features]
The standard deviation for each feature in the training set.
See also
--------
:func:`sklearn.preprocessing.scale` to perform centering and
scaling without using the ``Transformer`` object oriented API
:class:`sklearn.decomposition.RandomizedPCA` with `whiten=True`
to further remove the linear correlation across features.
"""
def __init__(self, copy=True, with_mean=True, with_std=True):
self.with_mean = with_mean
self.with_std = with_std
self.copy = copy
def fit(self, X, y=None):
"""Compute the mean and std to be used for later scaling.
Parameters
----------
X : array-like or CSR matrix with shape [n_samples, n_features]
The data used to compute the mean and standard deviation
used for later scaling along the features axis.
"""
X = check_arrays(X, copy=self.copy, sparse_format="csr")[0]
if sp.issparse(X):
if self.with_mean:
raise ValueError(
"Cannot center sparse matrices: pass `with_mean=False` "
"instead See docstring for motivation and alternatives.")
warn_if_not_float(X, estimator=self)
self.mean_ = None
var = mean_variance_axis0(X)[1]
self.std_ = np.sqrt(var)
self.std_[var == 0.0] = 1.0
return self
else:
warn_if_not_float(X, estimator=self)
self.mean_, self.std_ = _mean_and_std(
X, axis=0, with_mean=self.with_mean, with_std=self.with_std)
return self
def transform(self, X, y=None, copy=None):
"""Perform standardization by centering and scaling
Parameters
----------
X : array-like with shape [n_samples, n_features]
The data used to scale along the features axis.
"""
copy = copy if copy is not None else self.copy
X = check_arrays(X, copy=copy, sparse_format="csr")[0]
if sp.issparse(X):
if self.with_mean:
raise ValueError(
"Cannot center sparse matrices: pass `with_mean=False` "
"instead See docstring for motivation and alternatives.")
warn_if_not_float(X, estimator=self)
inplace_csr_column_scale(X, 1 / self.std_)
else:
warn_if_not_float(X, estimator=self)
if self.with_mean:
X -= self.mean_
if self.with_std:
X /= self.std_
return X
def inverse_transform(self, X, copy=None):
"""Scale back the data to the original representation
Parameters
----------
X : array-like with shape [n_samples, n_features]
The data used to scale along the features axis.
"""
copy = copy if copy is not None else self.copy
if sp.issparse(X):
if self.with_mean:
raise ValueError(
"Cannot uncenter sparse matrices: pass `with_mean=False` "
"instead See docstring for motivation and alternatives.")
if not sp.isspmatrix_csr(X):
X = X.tocsr()
copy = False
if copy:
X = X.copy()
inplace_csr_column_scale(X, self.std_)
else:
X = np.asarray(X)
if copy:
X = X.copy()
if self.with_std:
X *= self.std_
if self.with_mean:
X += self.mean_
return X
class Scaler(StandardScaler):
def __init__(self, copy=True, with_mean=True, with_std=True):
warnings.warn("Scaler was renamed to StandardScaler. The old name "
" will be removed in 0.15.", DeprecationWarning)
super(Scaler, self).__init__(copy, with_mean, with_std)
def normalize(X, norm='l2', axis=1, copy=True):
"""Normalize a dataset along any axis
Parameters
----------
X : array or scipy.sparse matrix with shape [n_samples, n_features]
The data to normalize, element by element.
scipy.sparse matrices should be in CSR format to avoid an
un-necessary copy.
norm : 'l1' or 'l2', optional ('l2' by default)
The norm to use to normalize each non zero sample (or each non-zero
feature if axis is 0).
axis : 0 or 1, optional (1 by default)
axis used to normalize the data along. If 1, independently normalize
each sample, otherwise (if 0) normalize each feature.
copy : boolean, optional, default is True
set to False to perform inplace row normalization and avoid a
copy (if the input is already a numpy array or a scipy.sparse
CSR matrix and if axis is 1).
See also
--------
:class:`sklearn.preprocessing.Normalizer` to perform normalization
using the ``Transformer`` API (e.g. as part of a preprocessing
:class:`sklearn.pipeline.Pipeline`)
"""
if norm not in ('l1', 'l2'):
raise ValueError("'%s' is not a supported norm" % norm)
if axis == 0:
sparse_format = 'csc'
elif axis == 1:
sparse_format = 'csr'
else:
raise ValueError("'%d' is not a supported axis" % axis)
X = check_arrays(X, sparse_format=sparse_format, copy=copy)[0]
warn_if_not_float(X, 'The normalize function')
if axis == 0:
X = X.T
if sp.issparse(X):
if norm == 'l1':
inplace_csr_row_normalize_l1(X)
elif norm == 'l2':
inplace_csr_row_normalize_l2(X)
else:
if norm == 'l1':
norms = np.abs(X).sum(axis=1)[:, np.newaxis]
norms[norms == 0.0] = 1.0
elif norm == 'l2':
norms = np.sqrt(np.sum(X ** 2, axis=1))[:, np.newaxis]
norms[norms == 0.0] = 1.0
X /= norms
if axis == 0:
X = X.T
return X
class Normalizer(BaseEstimator, TransformerMixin):
"""Normalize samples individually to unit norm
Each sample (i.e. each row of the data matrix) with at least one
non zero component is rescaled independently of other samples so
that its norm (l1 or l2) equals one.
This transformer is able to work both with dense numpy arrays and
scipy.sparse matrix (use CSR format if you want to avoid the burden of
a copy / conversion).
Scaling inputs to unit norms is a common operation for text
classification or clustering for instance. For instance the dot
product of two l2-normalized TF-IDF vectors is the cosine similarity
of the vectors and is the base similarity metric for the Vector
Space Model commonly used by the Information Retrieval community.
Parameters
----------
norm : 'l1' or 'l2', optional ('l2' by default)
The norm to use to normalize each non zero sample.
copy : boolean, optional, default is True
set to False to perform inplace row normalization and avoid a
copy (if the input is already a numpy array or a scipy.sparse
CSR matrix).
Notes
-----
This estimator is stateless (besides constructor parameters), the
fit method does nothing but is useful when used in a pipeline.
See also
--------
:func:`sklearn.preprocessing.normalize` equivalent function
without the object oriented API
"""
def __init__(self, norm='l2', copy=True):
self.norm = norm
self.copy = copy
def fit(self, X, y=None):
"""Do nothing and return the estimator unchanged
This method is just there to implement the usual API and hence
work in pipelines.
"""
atleast2d_or_csr(X)
return self
def transform(self, X, y=None, copy=None):
"""Scale each non zero row of X to unit norm
Parameters
----------
X : array or scipy.sparse matrix with shape [n_samples, n_features]
The data to normalize, row by row. scipy.sparse matrices should be
in CSR format to avoid an un-necessary copy.
"""
copy = copy if copy is not None else self.copy
atleast2d_or_csr(X)
return normalize(X, norm=self.norm, axis=1, copy=copy)
def binarize(X, threshold=0.0, copy=True):
"""Boolean thresholding of array-like or scipy.sparse matrix
Parameters
----------
X : array or scipy.sparse matrix with shape [n_samples, n_features]
The data to binarize, element by element.
scipy.sparse matrices should be in CSR format to avoid an
un-necessary copy.
threshold : float, optional (0.0 by default)
The lower bound that triggers feature values to be replaced by 1.0.
copy : boolean, optional, default is True
set to False to perform inplace binarization and avoid a copy
(if the input is already a numpy array or a scipy.sparse CSR
matrix and if axis is 1).
See also
--------
:class:`sklearn.preprocessing.Binarizer` to perform binarization
using the ``Transformer`` API (e.g. as part of a preprocessing
:class:`sklearn.pipeline.Pipeline`)
"""
X = check_arrays(X, sparse_format='csr', copy=copy)[0]
if sp.issparse(X):
cond = X.data > threshold
not_cond = np.logical_not(cond)
X.data[cond] = 1
# FIXME: if enough values became 0, it may be worth changing
# the sparsity structure
X.data[not_cond] = 0
else:
cond = X > threshold
not_cond = np.logical_not(cond)
X[cond] = 1
X[not_cond] = 0
return X
class Binarizer(BaseEstimator, TransformerMixin):
"""Binarize data (set feature values to 0 or 1) according to a threshold
The default threshold is 0.0 so that any non-zero values are set to 1.0
and zeros are left untouched.
Binarization is a common operation on text count data where the
analyst can decide to only consider the presence or absence of a
feature rather than a quantified number of occurences for instance.
It can also be used as a pre-processing step for estimators that
consider boolean random variables (e.g. modeled using the Bernoulli
distribution in a Bayesian setting).
Parameters
----------
threshold : float, optional (0.0 by default)
The lower bound that triggers feature values to be replaced by 1.0.
copy : boolean, optional, default is True
set to False to perform inplace binarization and avoid a copy (if
the input is already a numpy array or a scipy.sparse CSR matrix).
Notes
-----
If the input is a sparse matrix, only the non-zero values are subject
to update by the Binarizer class.
This estimator is stateless (besides constructor parameters), the
fit method does nothing but is useful when used in a pipeline.
"""
def __init__(self, threshold=0.0, copy=True):
self.threshold = threshold
self.copy = copy
def fit(self, X, y=None):
"""Do nothing and return the estimator unchanged
This method is just there to implement the usual API and hence
work in pipelines.
"""
atleast2d_or_csr(X)
return self
def transform(self, X, y=None, copy=None):
"""Binarize each element of X
Parameters
----------
X : array or scipy.sparse matrix with shape [n_samples, n_features]
The data to binarize, element by element.
scipy.sparse matrices should be in CSR format to avoid an
un-necessary copy.
"""
copy = copy if copy is not None else self.copy
return binarize(X, threshold=self.threshold, copy=copy)
def _is_label_indicator_matrix(y):
return hasattr(y, "shape") and len(y.shape) == 2
def _is_multilabel(y):
# the explicit check for ndarray is for forward compatibility; future
# versions of Numpy might want to register ndarray as a Sequence
return (not isinstance(y[0], np.ndarray) and isinstance(y[0], Sequence) and
not isinstance(y[0], basestring) or _is_label_indicator_matrix(y))
class OneHotEncoder(BaseEstimator, TransformerMixin):
"""Encode categorical integer features using a one-hot aka one-of-K scheme.
The input to this transformer should be a matrix of integers, denoting
the values taken on by categorical (discrete) features. The output will be
a sparse matrix were each column corresponds to one possible value of one
feature. It is assumed that input features take on values in the range
[0, n_values).
This encoding is needed for feeding categorical data to scikit-learn
estimators.
Parameters
----------
n_values : 'auto', int or array of int
Number of values per feature.
'auto' : determine value range from training data.
int : maximum value for all features.
array : maximum value per feature.
dtype : number type, default=np.float
Desired dtype of output.
Attributes
----------
`active_features_` : array
Indices for active features, meaning values that actually occur in the
training set. Only available when n_values is ``'auto'``.
`feature_indices_` : array of shape (n_features,)
Indices to feature ranges. Feature ``i`` in the original data is mapped
to features ``feature_indices_[i]`` to ``feature_indices_[i+1]``
(and potentially masked by `active_features_` afterwards)
`n_values_` : array of shape (n_features,)
Maximum number of values per feature.
Examples
--------
Given a dataset with three features and two samples, we let the encoder
find the maximum value per feature and transform the data to a binary
one-hot encoding.
>>> from sklearn.preprocessing import OneHotEncoder
>>> enc = OneHotEncoder()
>>> enc.fit([[0, 0, 3], [1, 1, 0], [0, 2, 1], [1, 0, 2]])
OneHotEncoder(dtype=<type 'float'>, n_values='auto')
>>> enc.n_values_
array([2, 3, 4])
>>> enc.feature_indices_
array([0, 2, 5, 9])
>>> enc.transform([[0, 1, 1]]).toarray()
array([[ 1., 0., 0., 1., 0., 0., 1., 0., 0.]])
See also
--------
LabelEncoder : performs a one-hot encoding on arbitrary class labels.
sklearn.feature_extraction.DictVectorizer : performs a one-hot encoding of
dictionary items (also handles string-valued features).
"""
def __init__(self, n_values="auto", dtype=np.float):
self.n_values = n_values
self.dtype = dtype
def fit(self, X, y=None):
"""Fit OneHotEncoder to X.
Parameters
----------
X : array-like, shape=(n_samples, n_feature)
Input array of type int.
Returns
-------
self
"""
self.fit_transform(X)
return self
def fit_transform(self, X, y=None):
"""Fit OneHotEncoder to X, then transform X.
Equivalent to self.fit(X).transform(X), but more convenient and more
efficient. See fit for the parameters, transform for the return value.
"""
X = check_arrays(X, sparse_format='dense', dtype=np.int)[0]
if np.any(X < 0):
raise ValueError("X needs to contain only non-negative integers.")
n_samples, n_features = X.shape
if self.n_values == 'auto':
n_values = np.max(X, axis=0) + 1
elif isinstance(self.n_values, numbers.Integral):
n_values = np.empty(n_features, dtype=np.int)
n_values.fill(self.n_values)
else:
try:
n_values = np.asarray(self.n_values, dtype=int)
except (ValueError, TypeError):
raise TypeError("Wrong type for parameter `n_values`. Expected"
" 'auto', int or array of ints, got %r"
% type(X))
if n_values.ndim < 1 or n_values.shape[0] != X.shape[1]:
raise ValueError("Shape mismatch: if n_values is an array,"
" it has to be of shape (n_features,).")
self.n_values_ = n_values
n_values = np.hstack([[0], n_values])
indices = np.cumsum(n_values)
self.feature_indices_ = indices
column_indices = (X + indices[:-1]).ravel()
row_indices = np.repeat(np.arange(n_samples, dtype=np.int32),
n_features)
data = np.ones(n_samples * n_features)
out = sp.coo_matrix((data, (row_indices, column_indices)),
shape=(n_samples, indices[-1]),
dtype=self.dtype).tocsr()
if self.n_values == 'auto':
mask = np.array(out.sum(axis=0)).ravel() != 0
active_features = np.where(mask)[0]
out = out[:, active_features]
self.active_features_ = active_features
return out
def transform(self, X):
"""Transform X using one-hot encoding.
Parameters
----------
X : array-like, shape=(n_samples, feature_indices_[-1])
Input array of type int.
Returns
-------
X_out : sparse matrix, dtype=int
Transformed input.
"""
X = check_arrays(X, sparse_format='dense', dtype=np.int)[0]
if np.any(X < 0):
raise ValueError("X needs to contain only non-negative integers.")
n_samples, n_features = X.shape
indices = self.feature_indices_
if n_features != indices.shape[0] - 1:
raise ValueError("X has different shape than during fitting."
" Expected %d, got %d."
% (indices.shape[0] - 1, n_features))
n_values_check = np.max(X, axis=0) + 1
if (n_values_check > self.n_values_).any():
raise ValueError("Feature out of bounds. Try setting n_values.")
column_indices = (X + indices[:-1]).ravel()
row_indices = np.repeat(np.arange(n_samples, dtype=np.int32),
n_features)
data = np.ones(n_samples * n_features)
out = sp.coo_matrix((data, (row_indices, column_indices)),
shape=(n_samples, indices[-1]),
dtype=self.dtype).tocsr()
if self.n_values == 'auto':
out = out[:, self.active_features_]
return out
class LabelEncoder(BaseEstimator, TransformerMixin):
"""Encode labels with value between 0 and n_classes-1.
Attributes
----------
`classes_`: array of shape [n_class]
Holds the label for each class.
Examples
--------
`LabelEncoder` can be used to normalize labels.
>>> from sklearn import preprocessing
>>> le = preprocessing.LabelEncoder()
>>> le.fit([1, 2, 2, 6])
LabelEncoder()
>>> le.classes_
array([1, 2, 6])
>>> le.transform([1, 1, 2, 6]) #doctest: +ELLIPSIS
array([0, 0, 1, 2]...)
>>> le.inverse_transform([0, 0, 1, 2])
array([1, 1, 2, 6])
It can also be used to transform non-numerical labels (as long as they are
hashable and comparable) to numerical labels.
>>> le = preprocessing.LabelEncoder()
>>> le.fit(["paris", "paris", "tokyo", "amsterdam"])
LabelEncoder()
>>> list(le.classes_)
['amsterdam', 'paris', 'tokyo']
>>> le.transform(["tokyo", "tokyo", "paris"]) #doctest: +ELLIPSIS
array([2, 2, 1]...)
>>> list(le.inverse_transform([2, 2, 1]))
['tokyo', 'tokyo', 'paris']
"""
def _check_fitted(self):
if not hasattr(self, "classes_"):
raise ValueError("LabelNormalizer was not fitted yet.")
def fit(self, y):
"""Fit label encoder
Parameters
----------
y : array-like of shape [n_samples]
Target values.
Returns
-------
self : returns an instance of self.
"""
self.classes_ = np.unique(y)
return self
def fit_transform(self, y):
"""Fit label encoder and return encoded labels
Parameters
----------
y : array-like of shape [n_samples]
Target values.
Returns
-------
y : array-like of shape [n_samples]
"""
self.classes_, y = unique(y, return_inverse=True)
return y
def transform(self, y):
"""Transform labels to normalized encoding.
Parameters
----------
y : array-like of shape [n_samples]
Target values.
Returns
-------
y : array-like of shape [n_samples]
"""
self._check_fitted()
classes = np.unique(y)
if len(np.intersect1d(classes, self.classes_)) < len(classes):
diff = np.setdiff1d(classes, self.classes_)
raise ValueError("y contains new labels: %s" % str(diff))
return np.searchsorted(self.classes_, y)
def inverse_transform(self, y):
"""Transform labels back to original encoding.
Parameters
----------
y : numpy array of shape [n_samples]
Target values.
Returns
-------
y : numpy array of shape [n_samples]
"""
self._check_fitted()
y = np.asarray(y)
return self.classes_[y]
class LabelBinarizer(BaseEstimator, TransformerMixin):
"""Binarize labels in a one-vs-all fashion
Several regression and binary classification algorithms are
available in the scikit. A simple way to extend these algorithms
to the multi-class classification case is to use the so-called
one-vs-all scheme.
At learning time, this simply consists in learning one regressor
or binary classifier per class. In doing so, one needs to convert
multi-class labels to binary labels (belong or does not belong
to the class). LabelBinarizer makes this process easy with the
transform method.
At prediction time, one assigns the class for which the corresponding
model gave the greatest confidence. LabelBinarizer makes this easy
with the inverse_transform method.
Parameters
----------
neg_label: int (default: 0)
Value with which negative labels must be encoded.
pos_label: int (default: 1)
Value with which positive labels must be encoded.
Attributes
----------
`classes_`: array of shape [n_class]
Holds the label for each class.
Examples
--------
>>> from sklearn import preprocessing
>>> lb = preprocessing.LabelBinarizer()
>>> lb.fit([1, 2, 6, 4, 2])
LabelBinarizer(neg_label=0, pos_label=1)
>>> lb.classes_
array([1, 2, 4, 6])
>>> lb.transform([1, 6])
array([[1, 0, 0, 0],
[0, 0, 0, 1]])
>>> lb.fit_transform([(1, 2), (3,)])
array([[1, 1, 0],
[0, 0, 1]])
>>> lb.classes_
array([1, 2, 3])
"""
def __init__(self, neg_label=0, pos_label=1):
if neg_label >= pos_label:
raise ValueError("neg_label must be strictly less than pos_label.")
self.neg_label = neg_label
self.pos_label = pos_label
def _check_fitted(self):
if not hasattr(self, "classes_"):
raise ValueError("LabelBinarizer was not fitted yet.")
def fit(self, y):
"""Fit label binarizer
Parameters
----------
y : numpy array of shape [n_samples] or sequence of sequences
Target values. In the multilabel case the nested sequences can
have variable lengths.
Returns
-------
self : returns an instance of self.
"""
self.multilabel = _is_multilabel(y)
if self.multilabel:
self.indicator_matrix_ = _is_label_indicator_matrix(y)
if self.indicator_matrix_:
self.classes_ = np.arange(y.shape[1])
else:
self.classes_ = np.array(sorted(set.union(*map(set, y))))
else:
self.classes_ = np.unique(y)
return self
def transform(self, y):
"""Transform multi-class labels to binary labels
The output of transform is sometimes referred to by some authors as the
1-of-K coding scheme.
Parameters
----------
y : numpy array of shape [n_samples] or sequence of sequences
Target values. In the multilabel case the nested sequences can
have variable lengths.
Returns
-------
Y : numpy array of shape [n_samples, n_classes]
"""
self._check_fitted()
if self.multilabel or len(self.classes_) > 2:
if _is_label_indicator_matrix(y):
# nothing to do as y is already a label indicator matrix
return y
Y = np.zeros((len(y), len(self.classes_)), dtype=np.int)
else:
Y = np.zeros((len(y), 1), dtype=np.int)
Y += self.neg_label
y_is_multilabel = _is_multilabel(y)
if y_is_multilabel and not self.multilabel:
raise ValueError("The object was not fitted with multilabel"
" input!")
elif self.multilabel:
if not _is_multilabel(y):
raise ValueError("y should be a list of label lists/tuples,"
"got %r" % (y,))
# inverse map: label => column index
imap = dict((v, k) for k, v in enumerate(self.classes_))
for i, label_tuple in enumerate(y):
for label in label_tuple:
Y[i, imap[label]] = self.pos_label
return Y
else:
y = np.asarray(y)
if len(self.classes_) == 2:
Y[y == self.classes_[1], 0] = self.pos_label
return Y
elif len(self.classes_) >= 2:
for i, k in enumerate(self.classes_):
Y[y == k, i] = self.pos_label
return Y
else:
# Only one class, returns a matrix with all negative labels.
return Y
def inverse_transform(self, Y, threshold=None):
"""Transform binary labels back to multi-class labels
Parameters
----------
Y : numpy array of shape [n_samples, n_classes]
Target values.
threshold : float or None
Threshold used in the binary and multi-label cases.
Use 0 when:
- Y contains the output of decision_function (classifier)
Use 0.5 when:
- Y contains the output of predict_proba
If None, the threshold is assumed to be half way between
neg_label and pos_label.
Returns
-------
y : numpy array of shape [n_samples] or sequence of sequences
Target values. In the multilabel case the nested sequences can
have variable lengths.
Notes
-----
In the case when the binary labels are fractional
(probabilistic), inverse_transform chooses the class with the
greatest value. Typically, this allows to use the output of a
linear model's decision_function method directly as the input
of inverse_transform.
"""
self._check_fitted()
if threshold is None:
half = (self.pos_label - self.neg_label) / 2.0
threshold = self.neg_label + half
if self.multilabel:
Y = np.array(Y > threshold, dtype=int)
# Return the predictions in the same format as in fit
if self.indicator_matrix_:
# Label indicator matrix format
return Y
else:
# Lists of tuples format
return [tuple(self.classes_[np.flatnonzero(Y[i])])
for i in range(Y.shape[0])]
if len(Y.shape) == 1 or Y.shape[1] == 1:
y = np.array(Y.ravel() > threshold, dtype=int)
else:
y = Y.argmax(axis=1)
return self.classes_[y]
class KernelCenterer(BaseEstimator, TransformerMixin):
"""Center a kernel matrix
Let K(x_i, x_j) be a kernel defined by K(x_i, x_j) = phi(x_i)^T phi(x_j),
where phi(x) is a function mapping x to a hilbert space. KernelCenterer is
a class to center (i.e., normalize to have zero-mean) the data without
explicitly computing phi(x). It is equivalent equivalent to centering
phi(x) with sklearn.preprocessing.StandardScaler(with_std=False).
"""
def fit(self, K, y=None):
"""Fit KernelCenterer
Parameters
----------
K : numpy array of shape [n_samples, n_samples]
Kernel matrix.
Returns
-------
self : returns an instance of self.
"""
K = array2d(K)
n_samples = K.shape[0]
self.K_fit_rows_ = np.sum(K, axis=0) / n_samples
self.K_fit_all_ = self.K_fit_rows_.sum() / n_samples
return self
def transform(self, K, y=None, copy=True):
"""Center kernel
Parameters
----------
K : numpy array of shape [n_samples1, n_samples2]
Kernel matrix.
Returns
-------
K_new : numpy array of shape [n_samples1, n_samples2]
"""
K = array2d(K)
if copy:
K = K.copy()
K_pred_cols = (np.sum(K, axis=1) /
self.K_fit_rows_.shape[0])[:, np.newaxis]
K -= self.K_fit_rows_
K -= K_pred_cols
K += self.K_fit_all_
return K
def add_dummy_feature(X, value=1.0):
"""Augment dataset with an additional dummy feature.
This is useful for fitting an intercept term with implementations which
cannot otherwise fit it directly.
Parameters
----------
X : array or scipy.sparse matrix with shape [n_samples, n_features]
Data.
value : float
Value to use for the dummy feature.
Returns
-------
X : array or scipy.sparse matrix with shape [n_samples, n_features + 1]
Same data with dummy feature added as first column.
Example
--------
>>> from sklearn.preprocessing import add_dummy_feature
>>> add_dummy_feature([[0, 1], [1, 0]])
array([[ 1., 0., 1.],
[ 1., 1., 0.]])
"""
X = safe_asarray(X)
n_samples, n_features = X.shape
shape = (n_samples, n_features + 1)
if sp.issparse(X):
if sp.isspmatrix_coo(X):
# Shift columns to the right.
col = X.col + 1
# Column indices of dummy feature are 0 everywhere.
col = np.concatenate((np.zeros(n_samples), col))
# Row indices of dummy feature are 0, ..., n_samples-1.
row = np.concatenate((np.arange(n_samples), X.row))
# Prepend the dummy feature n_samples times.
data = np.concatenate((np.ones(n_samples) * value, X.data))
return sp.coo_matrix((data, (row, col)), shape)
elif sp.isspmatrix_csc(X):
# Shift index pointers since we need to add n_samples elements.
indptr = X.indptr + n_samples
# indptr[0] must be 0.
indptr = np.concatenate((np.array([0]), indptr))
# Row indices of dummy feature are 0, ..., n_samples-1.
indices = np.concatenate((np.arange(n_samples), X.indices))
# Prepend the dummy feature n_samples times.
data = np.concatenate((np.ones(n_samples) * value, X.data))
return sp.csc_matrix((data, indices, indptr), shape)
else:
klass = X.__class__
X = klass(add_dummy_feature(X.tocoo(), value))
return klass(X)
else:
return np.hstack((np.ones((n_samples, 1)) * value, X))
|
bsd-3-clause
|
[
3,
6642,
26,
22986,
28547,
27211,
10279,
665,
24421,
28547,
14,
1679,
10279,
32,
262,
23714,
14,
4391,
30,
199,
3,
3515,
21066,
29364,
699,
5298,
2264,
665,
3442,
29364,
32,
887,
5298,
2264,
14,
1308,
30,
199,
3,
3515,
593,
317,
26645,
598,
322,
5891,
665,
23711,
26645,
14,
7928,
5891,
32,
287,
1207,
14,
1308,
30,
199,
3,
3515,
6061,
264,
305,
603,
13086,
1435,
665,
455,
13086,
1435,
32,
65,
374,
14,
5411,
13,
13520,
78,
14,
271,
30,
199,
3,
844,
26,
6289,
199,
199,
504,
5055,
492,
10975,
199,
646,
3598,
199,
646,
5579,
199,
199,
646,
2680,
465,
980,
199,
646,
7026,
14,
4421,
465,
2249,
199,
199,
504,
1275,
1208,
492,
1104,
63,
10095,
12,
1625,
18,
68,
12,
737,
11790,
18,
68,
63,
269,
63,
10101,
12,
5048,
63,
8748,
199,
504,
1275,
1208,
492,
7987,
63,
692,
63,
1397,
63,
1609,
199,
504,
1275,
1208,
14,
26205,
492,
3747,
199,
504,
1275,
1095,
492,
3523,
13183,
12,
30486,
4256,
199,
199,
504,
1275,
1208,
14,
4421,
9204,
492,
16304,
63,
10101,
63,
1143,
63,
7721,
63,
76,
17,
199,
504,
1275,
1208,
14,
4421,
9204,
492,
16304,
63,
10101,
63,
1143,
63,
7721,
63,
76,
18,
199,
504,
1275,
1208,
14,
4421,
9204,
492,
16304,
63,
10101,
63,
2301,
63,
3467,
199,
504,
1275,
1208,
14,
4421,
9204,
492,
4615,
63,
6221,
63,
3127,
16,
199,
199,
363,
452,
363,
275,
788,
13394,
31008,
297,
1779,
283,
14127,
18345,
266,
3859,
297,
1779,
283,
4314,
13394,
31008,
297,
1779,
283,
4314,
6679,
297,
1779,
283,
6241,
1793,
297,
1779,
283,
9232,
24274,
297,
1779,
283,
1393,
285,
794,
297,
1779,
283,
7721,
297,
1779,
283,
3467,
418,
421,
199,
318,
485,
3670,
63,
460,
63,
1516,
8,
56,
12,
3114,
29,
16,
12,
543,
63,
3670,
29,
549,
12,
543,
63,
1516,
29,
549,
304,
272,
408,
8564,
4615,
436,
2418,
18458,
367,
8126,
316,
12,
13690,
14,
339,
15708,
574,
68,
2418,
7323,
787,
5305,
370,
413,
14,
16,
370,
5126,
31930,
1380,
13690,
14,
272,
408,
272,
1323,
275,
980,
14,
8748,
8,
56,
9,
272,
1323,
82,
275,
980,
14,
8459,
416,
7291,
8,
56,
12,
3114,
9,
339,
340,
543,
63,
3670,
26,
267,
4615,
63,
275,
1323,
82,
14,
3670,
8,
3127,
29,
16,
9,
272,
587,
26,
267,
4615,
63,
275,
488,
339,
340,
543,
63,
1516,
26,
267,
2418,
63,
275,
1323,
82,
14,
1516,
8,
3127,
29,
16,
9,
267,
340,
1228,
8,
1516,
3131,
980,
14,
8237,
304,
288,
2418,
9925,
1516,
63,
508,
378,
14,
16,
61,
275,
413,
14,
16,
267,
916,
2418,
63,
508,
378,
16781,
288,
2418,
63,
275,
413,
14,
272,
587,
26,
267,
2418,
63,
275,
488,
339,
372,
4615,
3131,
2418,
63,
421,
199,
318,
4666,
8,
56,
12,
3114,
29,
16,
12,
543,
63,
3670,
29,
549,
12,
543,
63,
1516,
29,
549,
12,
1331,
29,
549,
304,
272,
408,
18736,
18980,
806,
282,
4789,
3180,
1263,
3114,
339,
24699,
370,
314,
4615,
436,
3931,
336,
572,
4666,
370,
4137,
11773,
14,
339,
3897,
272,
4143,
272,
1323,
520,
1625,
13,
2930,
503,
16449,
3634,
14,
267,
710,
666,
370,
8126,
436,
4666,
14,
339,
3114,
520,
1109,
334,
16,
701,
849,
9,
267,
3114,
1202,
370,
4526,
314,
4910,
436,
4465,
29052,
1298,
3180,
14,
982,
378,
12,
267,
30426,
28974,
806,
1924,
3878,
12,
4257,
334,
692,
413,
9,
28974,
806,
267,
1924,
2690,
14,
339,
543,
63,
3670,
520,
5046,
12,
715,
701,
849,
267,
982,
715,
12,
8126,
314,
666,
2544,
13690,
14,
339,
543,
63,
1516,
520,
5046,
12,
715,
701,
849,
267,
982,
715,
12,
4666,
314,
666,
370,
4137,
11773,
334,
269,
7353,
590,
12,
267,
4137,
4465,
18458,
680,
339,
1331,
520,
5046,
12,
2716,
12,
849,
365,
715,
267,
663,
370,
756,
370,
5147,
16304,
1962,
16973,
436,
5126,
282,
267,
1331,
334,
692,
314,
1324,
365,
2575,
282,
2680,
1625,
503,
282,
7026,
14,
4421,
267,
16449,
3634,
436,
340,
3114,
365,
413,
680,
339,
8144,
272,
9063,
272,
961,
4514,
911,
2984,
1180,
370,
8126,
7026,
14,
4421,
12627,
272,
3967,
652,
3955,
1852,
3062,
2222,
13,
4421,
436,
3955,
18994,
12420,
314,
272,
2240,
543,
4402,
21354,
833,
1636,
8826,
14,
339,
15345,
314,
8025,
365,
1420,
370,
1902,
663,
7662,
272,
658,
1045,
63,
3670,
29,
797,
64,
334,
262,
626,
1930,
12,
1454,
11773,
13690,
911,
506,
272,
10585,
641,
314,
4534,
402,
314,
16449,
3634,
9,
503,
370,
1240,
658,
56,
14,
18993,
11995,
272,
340,
946,
15,
19195,
14292,
314,
6285,
1759,
9363,
1625,
370,
5542,
315,
4402,
14,
339,
4005,
5126,
4402,
1331,
314,
8025,
1077,
986,
282,
16449,
3634,
14,
339,
1666,
2597,
272,
3001,
272,
520,
533,
1705,
27993,
14,
21402,
14,
9232,
24274,
64,
370,
5147,
8126,
316,
436,
272,
13690,
1808,
314,
1124,
19761,
1040,
3261,
334,
69,
14,
71,
14,
465,
1777,
402,
282,
26471,
272,
520,
533,
1705,
27993,
14,
7379,
14,
17562,
10522,
272,
408,
272,
340,
2249,
14,
30962,
8,
56,
304,
267,
340,
543,
63,
3670,
26,
288,
746,
1722,
8,
355,
298,
6612,
8126,
5178,
12627,
26,
986,
658,
1045,
63,
3670,
29,
797,
64,
3140,
2,
355,
298,
1666,
9214,
367,
1303,
280,
4255,
436,
8679,
10661,
2685,
267,
340,
3114,
1137,
378,
26,
288,
746,
1722,
480,
6049,
1454,
4666,
5178,
3634,
641,
3114,
29,
16,
12,
298,
2490,
298,
4788,
3114,
2458,
68,
2,
450,
3114,
9,
267,
7987,
63,
692,
63,
1397,
63,
1609,
8,
56,
12,
8943,
534,
1918,
4666,
805,
358,
267,
340,
440,
2249,
14,
374,
27349,
63,
10101,
8,
56,
304,
288,
1323,
275,
1323,
14,
475,
10101,
342,
288,
1331,
275,
756,
267,
340,
1331,
26,
288,
1323,
275,
1323,
14,
1574,
342,
267,
5501,
2729,
275,
4615,
63,
6221,
63,
3127,
16,
8,
56,
9,
267,
2729,
59,
1391,
508,
378,
14,
16,
61,
275,
413,
14,
16,
267,
16304,
63,
10101,
63,
2301,
63,
3467,
8,
56,
12,
413,
1182,
980,
14,
5079,
8,
1391,
430,
272,
587,
26,
267
] |
[
6642,
26,
22986,
28547,
27211,
10279,
665,
24421,
28547,
14,
1679,
10279,
32,
262,
23714,
14,
4391,
30,
199,
3,
3515,
21066,
29364,
699,
5298,
2264,
665,
3442,
29364,
32,
887,
5298,
2264,
14,
1308,
30,
199,
3,
3515,
593,
317,
26645,
598,
322,
5891,
665,
23711,
26645,
14,
7928,
5891,
32,
287,
1207,
14,
1308,
30,
199,
3,
3515,
6061,
264,
305,
603,
13086,
1435,
665,
455,
13086,
1435,
32,
65,
374,
14,
5411,
13,
13520,
78,
14,
271,
30,
199,
3,
844,
26,
6289,
199,
199,
504,
5055,
492,
10975,
199,
646,
3598,
199,
646,
5579,
199,
199,
646,
2680,
465,
980,
199,
646,
7026,
14,
4421,
465,
2249,
199,
199,
504,
1275,
1208,
492,
1104,
63,
10095,
12,
1625,
18,
68,
12,
737,
11790,
18,
68,
63,
269,
63,
10101,
12,
5048,
63,
8748,
199,
504,
1275,
1208,
492,
7987,
63,
692,
63,
1397,
63,
1609,
199,
504,
1275,
1208,
14,
26205,
492,
3747,
199,
504,
1275,
1095,
492,
3523,
13183,
12,
30486,
4256,
199,
199,
504,
1275,
1208,
14,
4421,
9204,
492,
16304,
63,
10101,
63,
1143,
63,
7721,
63,
76,
17,
199,
504,
1275,
1208,
14,
4421,
9204,
492,
16304,
63,
10101,
63,
1143,
63,
7721,
63,
76,
18,
199,
504,
1275,
1208,
14,
4421,
9204,
492,
16304,
63,
10101,
63,
2301,
63,
3467,
199,
504,
1275,
1208,
14,
4421,
9204,
492,
4615,
63,
6221,
63,
3127,
16,
199,
199,
363,
452,
363,
275,
788,
13394,
31008,
297,
1779,
283,
14127,
18345,
266,
3859,
297,
1779,
283,
4314,
13394,
31008,
297,
1779,
283,
4314,
6679,
297,
1779,
283,
6241,
1793,
297,
1779,
283,
9232,
24274,
297,
1779,
283,
1393,
285,
794,
297,
1779,
283,
7721,
297,
1779,
283,
3467,
418,
421,
199,
318,
485,
3670,
63,
460,
63,
1516,
8,
56,
12,
3114,
29,
16,
12,
543,
63,
3670,
29,
549,
12,
543,
63,
1516,
29,
549,
304,
272,
408,
8564,
4615,
436,
2418,
18458,
367,
8126,
316,
12,
13690,
14,
339,
15708,
574,
68,
2418,
7323,
787,
5305,
370,
413,
14,
16,
370,
5126,
31930,
1380,
13690,
14,
272,
408,
272,
1323,
275,
980,
14,
8748,
8,
56,
9,
272,
1323,
82,
275,
980,
14,
8459,
416,
7291,
8,
56,
12,
3114,
9,
339,
340,
543,
63,
3670,
26,
267,
4615,
63,
275,
1323,
82,
14,
3670,
8,
3127,
29,
16,
9,
272,
587,
26,
267,
4615,
63,
275,
488,
339,
340,
543,
63,
1516,
26,
267,
2418,
63,
275,
1323,
82,
14,
1516,
8,
3127,
29,
16,
9,
267,
340,
1228,
8,
1516,
3131,
980,
14,
8237,
304,
288,
2418,
9925,
1516,
63,
508,
378,
14,
16,
61,
275,
413,
14,
16,
267,
916,
2418,
63,
508,
378,
16781,
288,
2418,
63,
275,
413,
14,
272,
587,
26,
267,
2418,
63,
275,
488,
339,
372,
4615,
3131,
2418,
63,
421,
199,
318,
4666,
8,
56,
12,
3114,
29,
16,
12,
543,
63,
3670,
29,
549,
12,
543,
63,
1516,
29,
549,
12,
1331,
29,
549,
304,
272,
408,
18736,
18980,
806,
282,
4789,
3180,
1263,
3114,
339,
24699,
370,
314,
4615,
436,
3931,
336,
572,
4666,
370,
4137,
11773,
14,
339,
3897,
272,
4143,
272,
1323,
520,
1625,
13,
2930,
503,
16449,
3634,
14,
267,
710,
666,
370,
8126,
436,
4666,
14,
339,
3114,
520,
1109,
334,
16,
701,
849,
9,
267,
3114,
1202,
370,
4526,
314,
4910,
436,
4465,
29052,
1298,
3180,
14,
982,
378,
12,
267,
30426,
28974,
806,
1924,
3878,
12,
4257,
334,
692,
413,
9,
28974,
806,
267,
1924,
2690,
14,
339,
543,
63,
3670,
520,
5046,
12,
715,
701,
849,
267,
982,
715,
12,
8126,
314,
666,
2544,
13690,
14,
339,
543,
63,
1516,
520,
5046,
12,
715,
701,
849,
267,
982,
715,
12,
4666,
314,
666,
370,
4137,
11773,
334,
269,
7353,
590,
12,
267,
4137,
4465,
18458,
680,
339,
1331,
520,
5046,
12,
2716,
12,
849,
365,
715,
267,
663,
370,
756,
370,
5147,
16304,
1962,
16973,
436,
5126,
282,
267,
1331,
334,
692,
314,
1324,
365,
2575,
282,
2680,
1625,
503,
282,
7026,
14,
4421,
267,
16449,
3634,
436,
340,
3114,
365,
413,
680,
339,
8144,
272,
9063,
272,
961,
4514,
911,
2984,
1180,
370,
8126,
7026,
14,
4421,
12627,
272,
3967,
652,
3955,
1852,
3062,
2222,
13,
4421,
436,
3955,
18994,
12420,
314,
272,
2240,
543,
4402,
21354,
833,
1636,
8826,
14,
339,
15345,
314,
8025,
365,
1420,
370,
1902,
663,
7662,
272,
658,
1045,
63,
3670,
29,
797,
64,
334,
262,
626,
1930,
12,
1454,
11773,
13690,
911,
506,
272,
10585,
641,
314,
4534,
402,
314,
16449,
3634,
9,
503,
370,
1240,
658,
56,
14,
18993,
11995,
272,
340,
946,
15,
19195,
14292,
314,
6285,
1759,
9363,
1625,
370,
5542,
315,
4402,
14,
339,
4005,
5126,
4402,
1331,
314,
8025,
1077,
986,
282,
16449,
3634,
14,
339,
1666,
2597,
272,
3001,
272,
520,
533,
1705,
27993,
14,
21402,
14,
9232,
24274,
64,
370,
5147,
8126,
316,
436,
272,
13690,
1808,
314,
1124,
19761,
1040,
3261,
334,
69,
14,
71,
14,
465,
1777,
402,
282,
26471,
272,
520,
533,
1705,
27993,
14,
7379,
14,
17562,
10522,
272,
408,
272,
340,
2249,
14,
30962,
8,
56,
304,
267,
340,
543,
63,
3670,
26,
288,
746,
1722,
8,
355,
298,
6612,
8126,
5178,
12627,
26,
986,
658,
1045,
63,
3670,
29,
797,
64,
3140,
2,
355,
298,
1666,
9214,
367,
1303,
280,
4255,
436,
8679,
10661,
2685,
267,
340,
3114,
1137,
378,
26,
288,
746,
1722,
480,
6049,
1454,
4666,
5178,
3634,
641,
3114,
29,
16,
12,
298,
2490,
298,
4788,
3114,
2458,
68,
2,
450,
3114,
9,
267,
7987,
63,
692,
63,
1397,
63,
1609,
8,
56,
12,
8943,
534,
1918,
4666,
805,
358,
267,
340,
440,
2249,
14,
374,
27349,
63,
10101,
8,
56,
304,
288,
1323,
275,
1323,
14,
475,
10101,
342,
288,
1331,
275,
756,
267,
340,
1331,
26,
288,
1323,
275,
1323,
14,
1574,
342,
267,
5501,
2729,
275,
4615,
63,
6221,
63,
3127,
16,
8,
56,
9,
267,
2729,
59,
1391,
508,
378,
14,
16,
61,
275,
413,
14,
16,
267,
16304,
63,
10101,
63,
2301,
63,
3467,
8,
56,
12,
413,
1182,
980,
14,
5079,
8,
1391,
430,
272,
587,
26,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sergiocorato/knowledge
|
document_choose_directory/controllers/binary.py
|
13
|
1670
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Therp BV (<http://therp.nl>).
#
# 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 import http
from openerp.addons.web.controllers.main import Binary
class Binary(Binary):
@http.route('/web/binary/upload_attachment', type='http', auth="user")
def upload_attachment(self, callback, model, id, ufile, directory_id=None):
if directory_id:
# we can't use default_parent_id because of
# the ir_attachment.create overwrite in document
http.request.context['parent_id'] = int(directory_id)
# fallback if the above is ever fixed
http.request.context['default_parent_id'] = int(directory_id)
return super(Binary, self).upload_attachment(
callback, model, id, ufile)
|
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,
961,
859,
4248,
334,
35,
9,
6900,
377,
2523,
80,
699,
54,
8642,
1014,
921,
728,
80,
14,
7530,
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,
504,
5166,
492,
1455,
199,
504,
5166,
14,
10788,
14,
2520,
14,
20531,
14,
973,
492,
14161,
421,
199,
533,
14161,
8,
6636,
304,
272,
768,
1014,
14,
4449,
2336,
2520,
15,
3008,
15,
5064,
63,
8905,
297,
730,
534,
1014,
297,
1790,
628,
751,
531,
272,
347,
5802,
63,
8905,
8,
277,
12,
3233,
12,
1402,
12,
1305,
12,
399,
493,
12,
2082,
63,
344,
29,
403,
304,
267,
340,
2082,
63,
344,
26,
288,
327,
781,
883,
1133,
675,
849,
63,
1708,
63,
344,
2952,
402,
288,
327,
314,
8190,
63,
8905,
14,
981,
8970,
315,
2213,
288,
1455,
14,
1069,
14,
1100,
459,
1708,
63,
344,
418,
275,
1109,
8,
3619,
63,
344,
9,
288,
327,
9567,
340,
314,
3432,
365,
14433,
6317,
288,
1455,
14,
1069,
14,
1100,
459,
885,
63,
1708,
63,
344,
418,
275,
1109,
8,
3619,
63,
344,
9,
267,
372,
1613,
8,
6636,
12,
291,
680,
5064,
63,
8905,
8,
288,
3233,
12,
1402,
12,
1305,
12,
399,
493,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
961,
859,
4248,
334,
35,
9,
6900,
377,
2523,
80,
699,
54,
8642,
1014,
921,
728,
80,
14,
7530,
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,
504,
5166,
492,
1455,
199,
504,
5166,
14,
10788,
14,
2520,
14,
20531,
14,
973,
492,
14161,
421,
199,
533,
14161,
8,
6636,
304,
272,
768,
1014,
14,
4449,
2336,
2520,
15,
3008,
15,
5064,
63,
8905,
297,
730,
534,
1014,
297,
1790,
628,
751,
531,
272,
347,
5802,
63,
8905,
8,
277,
12,
3233,
12,
1402,
12,
1305,
12,
399,
493,
12,
2082,
63,
344,
29,
403,
304,
267,
340,
2082,
63,
344,
26,
288,
327,
781,
883,
1133,
675,
849,
63,
1708,
63,
344,
2952,
402,
288,
327,
314,
8190,
63,
8905,
14,
981,
8970,
315,
2213,
288,
1455,
14,
1069,
14,
1100,
459,
1708,
63,
344,
418,
275,
1109,
8,
3619,
63,
344,
9,
288,
327,
9567,
340,
314,
3432,
365,
14433,
6317,
288,
1455,
14,
1069,
14,
1100,
459,
885,
63,
1708,
63,
344,
418,
275,
1109,
8,
3619,
63,
344,
9,
267,
372,
1613,
8,
6636,
12,
291,
680,
5064,
63,
8905,
8,
288,
3233,
12,
1402,
12,
1305,
12,
399,
493,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jsvine/spectra
|
spectra/__init__.py
|
1
|
4083
|
from .core import COLOR_SPACES, Color, Scale
from ._version import __version__
def lab(L, a, b):
"""
Create a spectra.Color object in the CIELAB color space.
:param float L: L coordinate.
:param float a: a coordinate.
:param float b: b coordinate.
:rtype: Color
:returns: A spectra.Color object in the CIELAB color space.
"""
return Color("lab", L, a, b)
def lch(L, c, h):
"""
Create a spectra.Color object in the CIE LCH color space.
Based on `colormath`'s LCHabColor class.
:param float L: L coordinate.
:param float c: c coordinate.
:param float h: h coordinate.
:rtype: Color
:returns: A spectra.Color object in the CIE LCH color space.
"""
return Color("lch", L, c, h)
def xyz(x, y, z):
"""
Create a spectra.Color object in the XYZ color space.
Based on `colormath`'s LCHabColor class.
:param float x: x coordinate.
:param float y: y coordinate.
:param float z: z coordinate.
:rtype: Color
:returns: A spectra.Color object in the XYZ color space.
"""
return Color("xyz", x, y, z)
def rgb(r, g, b):
"""
Create a spectra.Color object in the sRGB color space.
Per `colormath`: "If you pass in upscaled values, we
automatically scale them down to 0.0-1.0."
:param float r: r coordinate.
:param float g: g coordinate.
:param float b: b coordinate.
:rtype: Color
:returns: A spectra.Color object in the sRGB color space.
"""
return Color("rgb", r, g, b)
def cmyk(c, m, y, k):
"""
Create a spectra.Color object in the CMYK color space.
:param float c: c coordinate.
:param float m: m coordinate.
:param float y: y coordinate.
:param float k: k coordinate.
:rtype: Color
:returns: A spectra.Color object in the CMYK color space.
"""
return Color("cmyk", c, m, y, k)
def cmy(c, m, y):
"""
Create a spectra.Color object in the CMY color space.
:param float c: c coordinate.
:param float m: m coordinate.
:param float y: y coordinate.
:rtype: Color
:returns: A spectra.Color object in the CMY color space.
"""
return Color("cmyk", c, m, y)
def hsl(h, s, l):
"""
Create a spectra.Color object in the HSL color space.
:param float h: h coordinate.
:param float s: s coordinate.
:param float l: l coordinate.
:rtype: Color
:returns: A spectra.Color object in the HSL color space.
"""
return Color("hsl", h, s, l)
def hsv(h, s, v):
"""
Create a spectra.Color object in the HSV color space.
:param float h: h coordinate.
:param float s: s coordinate.
:param float v: v coordinate.
:rtype: Color
:returns: A spectra.Color object in the HSV color space.
"""
return Color("hsv", h, s, v)
def html(html_string):
"""
Create an RGB spectra.Color object from a web-color or hexcode.
E.g.: "papayawhip", "#FFF", "#ffffff", "FFEFD5"
:param str html_string: Web-color or hexcode.
:rtype: Color
:returns: A spectra.Color object in the sRGB color space.
"""
return Color.from_html(html_string)
def scale(colors):
"""
Create a color scale, based on a list of spectra.Color objects.
The most common use-case involves passing two colors
(a start and an end), but any number of colors is acceptable.
Instead of spectra.Color objects, you can also pass a list of
web-color or hexcode strings.
:param list colors: spectra.Color objects or web-color/hexcode strings.
:rtype: Scale
:returns: A spectra.Scale object
"""
return Scale(colors)
def range(colors, count):
"""
Create a range of `count` colors between two or more base colors.
Colors should be a list of spectra.Color objects, web-color strings,
or hexcode strings.
:param list colors: spectra.Color objects or web-color/hexcode strings.
:param int count: the number of colors to return.
:rtype: list
:returns: A list of `count` spectra.Color objects.
"""
return Scale(colors).range(count)
|
mit
|
[
504,
1275,
1018,
492,
13513,
726,
63,
5763,
21287,
12,
11581,
12,
22869,
199,
504,
13653,
1023,
492,
636,
1023,
363,
199,
199,
318,
19888,
8,
44,
12,
282,
12,
330,
304,
272,
408,
272,
2790,
282,
30900,
345,
14,
4117,
909,
315,
314,
445,
41,
2901,
1217,
3164,
4601,
14,
339,
520,
635,
2069,
491,
26,
491,
10021,
14,
272,
520,
635,
2069,
282,
26,
282,
10021,
14,
272,
520,
635,
2069,
330,
26,
330,
10021,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
445,
41,
2901,
1217,
3164,
4601,
14,
272,
408,
272,
372,
11581,
480,
5561,
401,
491,
12,
282,
12,
330,
9,
199,
199,
318,
634,
335,
8,
44,
12,
286,
12,
394,
304,
272,
408,
272,
2790,
282,
30900,
345,
14,
4117,
909,
315,
314,
445,
4332,
491,
1244,
3164,
4601,
14,
339,
21311,
641,
658,
2326,
3442,
19097,
83,
491,
1244,
371,
4117,
1021,
14,
339,
520,
635,
2069,
491,
26,
491,
10021,
14,
272,
520,
635,
2069,
286,
26,
286,
10021,
14,
272,
520,
635,
2069,
394,
26,
394,
10021,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
445,
4332,
491,
1244,
3164,
4601,
14,
272,
408,
272,
372,
11581,
480,
76,
335,
401,
491,
12,
286,
12,
394,
9,
199,
199,
318,
24122,
8,
88,
12,
612,
12,
1315,
304,
272,
408,
272,
2790,
282,
30900,
345,
14,
4117,
909,
315,
314,
1323,
26184,
3164,
4601,
14,
339,
21311,
641,
658,
2326,
3442,
19097,
83,
491,
1244,
371,
4117,
1021,
14,
339,
520,
635,
2069,
671,
26,
671,
10021,
14,
272,
520,
635,
2069,
612,
26,
612,
10021,
14,
272,
520,
635,
2069,
1315,
26,
1315,
10021,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
1323,
26184,
3164,
4601,
14,
272,
408,
272,
372,
11581,
480,
8568,
401,
671,
12,
612,
12,
1315,
9,
199,
199,
318,
15180,
8,
82,
12,
486,
12,
330,
304,
272,
408,
272,
2790,
282,
30900,
345,
14,
4117,
909,
315,
314,
308,
12067,
3164,
4601,
14,
339,
3492,
658,
2326,
3442,
8340,
298,
3917,
1265,
986,
315,
1536,
15120,
1338,
12,
781,
272,
5847,
4666,
3062,
3224,
370,
378,
14,
16,
13,
17,
14,
16,
2122,
339,
520,
635,
2069,
519,
26,
519,
10021,
14,
272,
520,
635,
2069,
486,
26,
486,
10021,
14,
272,
520,
635,
2069,
330,
26,
330,
10021,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
308,
12067,
3164,
4601,
14,
272,
408,
272,
372,
11581,
480,
10090,
401,
519,
12,
486,
12,
330,
9,
199,
199,
318,
286,
1662,
75,
8,
67,
12,
333,
12,
612,
12,
1022,
304,
272,
408,
272,
2790,
282,
30900,
345,
14,
4117,
909,
315,
314,
445,
12339,
43,
3164,
4601,
14,
339,
520,
635,
2069,
286,
26,
286,
10021,
14,
272,
520,
635,
2069,
333,
26,
333,
10021,
14,
272,
520,
635,
2069,
612,
26,
612,
10021,
14,
272,
520,
635,
2069,
1022,
26,
1022,
10021,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
445,
12339,
43,
3164,
4601,
14,
272,
408,
272,
372,
11581,
480,
67,
1662,
75,
401,
286,
12,
333,
12,
612,
12,
1022,
9,
199,
199,
318,
286,
1662,
8,
67,
12,
333,
12,
612,
304,
272,
408,
272,
2790,
282,
30900,
345,
14,
4117,
909,
315,
314,
445,
12339,
3164,
4601,
14,
339,
520,
635,
2069,
286,
26,
286,
10021,
14,
272,
520,
635,
2069,
333,
26,
333,
10021,
14,
272,
520,
635,
2069,
612,
26,
612,
10021,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
445,
12339,
3164,
4601,
14,
272,
408,
272,
372,
11581,
480,
67,
1662,
75,
401,
286,
12,
333,
12,
612,
9,
199,
199,
318,
394,
2482,
8,
72,
12,
308,
12,
634,
304,
272,
408,
272,
2790,
282,
30900,
345,
14,
4117,
909,
315,
314,
869,
4929,
3164,
4601,
14,
339,
520,
635,
2069,
394,
26,
394,
10021,
14,
272,
520,
635,
2069,
308,
26,
308,
10021,
14,
272,
520,
635,
2069,
634,
26,
634,
10021,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
869,
4929,
3164,
4601,
14,
272,
408,
272,
372,
11581,
480,
72,
2482,
401,
394,
12,
308,
12,
634,
9,
199,
199,
318,
394,
2772,
8,
72,
12,
308,
12,
373,
304,
272,
408,
272,
2790,
282,
30900,
345,
14,
4117,
909,
315,
314,
869,
4985,
3164,
4601,
14,
339,
520,
635,
2069,
394,
26,
394,
10021,
14,
272,
520,
635,
2069,
308,
26,
308,
10021,
14,
272,
520,
635,
2069,
373,
26,
373,
10021,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
869,
4985,
3164,
4601,
14,
272,
408,
272,
372,
11581,
480,
72,
2772,
401,
394,
12,
308,
12,
373,
9,
199,
199,
318,
3517,
8,
1360,
63,
875,
304,
272,
408,
272,
2790,
376,
19013,
30900,
345,
14,
4117,
909,
687,
282,
3330,
13,
2326,
503,
6318,
600,
14,
339,
662,
14,
71,
16781,
298,
387,
5989,
65,
2191,
711,
401,
5426,
24254,
401,
5426,
12596,
401,
298,
1665,
37,
7902,
21,
2,
339,
520,
635,
620,
3517,
63,
875,
26,
6001,
13,
2326,
503,
6318,
600,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
308,
12067,
3164,
4601,
14,
272,
408,
272,
372,
11581,
14,
504,
63,
1360,
8,
1360,
63,
875,
9,
199,
199,
318,
4666,
8,
7120,
304,
272,
408,
272,
2790,
282,
3164,
4666,
12,
4079,
641,
282,
769,
402,
30900,
345,
14,
4117,
2251,
14,
339,
710,
4750,
2863,
675,
13,
2546,
25613,
2310,
9476,
2877,
9229,
272,
334,
65,
1343,
436,
376,
1284,
395,
1325,
1263,
1329,
402,
9229,
365,
14712,
14,
339,
15345,
402,
30900,
345,
14,
4117,
2251,
12,
1265,
883,
2597,
986,
282,
769,
402,
5591,
3330,
13,
2326,
503,
6318,
600
] |
[
1275,
1018,
492,
13513,
726,
63,
5763,
21287,
12,
11581,
12,
22869,
199,
504,
13653,
1023,
492,
636,
1023,
363,
199,
199,
318,
19888,
8,
44,
12,
282,
12,
330,
304,
272,
408,
272,
2790,
282,
30900,
345,
14,
4117,
909,
315,
314,
445,
41,
2901,
1217,
3164,
4601,
14,
339,
520,
635,
2069,
491,
26,
491,
10021,
14,
272,
520,
635,
2069,
282,
26,
282,
10021,
14,
272,
520,
635,
2069,
330,
26,
330,
10021,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
445,
41,
2901,
1217,
3164,
4601,
14,
272,
408,
272,
372,
11581,
480,
5561,
401,
491,
12,
282,
12,
330,
9,
199,
199,
318,
634,
335,
8,
44,
12,
286,
12,
394,
304,
272,
408,
272,
2790,
282,
30900,
345,
14,
4117,
909,
315,
314,
445,
4332,
491,
1244,
3164,
4601,
14,
339,
21311,
641,
658,
2326,
3442,
19097,
83,
491,
1244,
371,
4117,
1021,
14,
339,
520,
635,
2069,
491,
26,
491,
10021,
14,
272,
520,
635,
2069,
286,
26,
286,
10021,
14,
272,
520,
635,
2069,
394,
26,
394,
10021,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
445,
4332,
491,
1244,
3164,
4601,
14,
272,
408,
272,
372,
11581,
480,
76,
335,
401,
491,
12,
286,
12,
394,
9,
199,
199,
318,
24122,
8,
88,
12,
612,
12,
1315,
304,
272,
408,
272,
2790,
282,
30900,
345,
14,
4117,
909,
315,
314,
1323,
26184,
3164,
4601,
14,
339,
21311,
641,
658,
2326,
3442,
19097,
83,
491,
1244,
371,
4117,
1021,
14,
339,
520,
635,
2069,
671,
26,
671,
10021,
14,
272,
520,
635,
2069,
612,
26,
612,
10021,
14,
272,
520,
635,
2069,
1315,
26,
1315,
10021,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
1323,
26184,
3164,
4601,
14,
272,
408,
272,
372,
11581,
480,
8568,
401,
671,
12,
612,
12,
1315,
9,
199,
199,
318,
15180,
8,
82,
12,
486,
12,
330,
304,
272,
408,
272,
2790,
282,
30900,
345,
14,
4117,
909,
315,
314,
308,
12067,
3164,
4601,
14,
339,
3492,
658,
2326,
3442,
8340,
298,
3917,
1265,
986,
315,
1536,
15120,
1338,
12,
781,
272,
5847,
4666,
3062,
3224,
370,
378,
14,
16,
13,
17,
14,
16,
2122,
339,
520,
635,
2069,
519,
26,
519,
10021,
14,
272,
520,
635,
2069,
486,
26,
486,
10021,
14,
272,
520,
635,
2069,
330,
26,
330,
10021,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
308,
12067,
3164,
4601,
14,
272,
408,
272,
372,
11581,
480,
10090,
401,
519,
12,
486,
12,
330,
9,
199,
199,
318,
286,
1662,
75,
8,
67,
12,
333,
12,
612,
12,
1022,
304,
272,
408,
272,
2790,
282,
30900,
345,
14,
4117,
909,
315,
314,
445,
12339,
43,
3164,
4601,
14,
339,
520,
635,
2069,
286,
26,
286,
10021,
14,
272,
520,
635,
2069,
333,
26,
333,
10021,
14,
272,
520,
635,
2069,
612,
26,
612,
10021,
14,
272,
520,
635,
2069,
1022,
26,
1022,
10021,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
445,
12339,
43,
3164,
4601,
14,
272,
408,
272,
372,
11581,
480,
67,
1662,
75,
401,
286,
12,
333,
12,
612,
12,
1022,
9,
199,
199,
318,
286,
1662,
8,
67,
12,
333,
12,
612,
304,
272,
408,
272,
2790,
282,
30900,
345,
14,
4117,
909,
315,
314,
445,
12339,
3164,
4601,
14,
339,
520,
635,
2069,
286,
26,
286,
10021,
14,
272,
520,
635,
2069,
333,
26,
333,
10021,
14,
272,
520,
635,
2069,
612,
26,
612,
10021,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
445,
12339,
3164,
4601,
14,
272,
408,
272,
372,
11581,
480,
67,
1662,
75,
401,
286,
12,
333,
12,
612,
9,
199,
199,
318,
394,
2482,
8,
72,
12,
308,
12,
634,
304,
272,
408,
272,
2790,
282,
30900,
345,
14,
4117,
909,
315,
314,
869,
4929,
3164,
4601,
14,
339,
520,
635,
2069,
394,
26,
394,
10021,
14,
272,
520,
635,
2069,
308,
26,
308,
10021,
14,
272,
520,
635,
2069,
634,
26,
634,
10021,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
869,
4929,
3164,
4601,
14,
272,
408,
272,
372,
11581,
480,
72,
2482,
401,
394,
12,
308,
12,
634,
9,
199,
199,
318,
394,
2772,
8,
72,
12,
308,
12,
373,
304,
272,
408,
272,
2790,
282,
30900,
345,
14,
4117,
909,
315,
314,
869,
4985,
3164,
4601,
14,
339,
520,
635,
2069,
394,
26,
394,
10021,
14,
272,
520,
635,
2069,
308,
26,
308,
10021,
14,
272,
520,
635,
2069,
373,
26,
373,
10021,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
869,
4985,
3164,
4601,
14,
272,
408,
272,
372,
11581,
480,
72,
2772,
401,
394,
12,
308,
12,
373,
9,
199,
199,
318,
3517,
8,
1360,
63,
875,
304,
272,
408,
272,
2790,
376,
19013,
30900,
345,
14,
4117,
909,
687,
282,
3330,
13,
2326,
503,
6318,
600,
14,
339,
662,
14,
71,
16781,
298,
387,
5989,
65,
2191,
711,
401,
5426,
24254,
401,
5426,
12596,
401,
298,
1665,
37,
7902,
21,
2,
339,
520,
635,
620,
3517,
63,
875,
26,
6001,
13,
2326,
503,
6318,
600,
14,
339,
520,
4500,
26,
11581,
272,
520,
5808,
26,
437,
30900,
345,
14,
4117,
909,
315,
314,
308,
12067,
3164,
4601,
14,
272,
408,
272,
372,
11581,
14,
504,
63,
1360,
8,
1360,
63,
875,
9,
199,
199,
318,
4666,
8,
7120,
304,
272,
408,
272,
2790,
282,
3164,
4666,
12,
4079,
641,
282,
769,
402,
30900,
345,
14,
4117,
2251,
14,
339,
710,
4750,
2863,
675,
13,
2546,
25613,
2310,
9476,
2877,
9229,
272,
334,
65,
1343,
436,
376,
1284,
395,
1325,
1263,
1329,
402,
9229,
365,
14712,
14,
339,
15345,
402,
30900,
345,
14,
4117,
2251,
12,
1265,
883,
2597,
986,
282,
769,
402,
5591,
3330,
13,
2326,
503,
6318,
600,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Alucard24/Alucard-Kernel-LG-G5
|
scripts/rt-tester/rt-tester.py
|
1106
|
5305
|
#!/usr/bin/python
#
# rt-mutex tester
#
# (C) 2006 Thomas Gleixner <tglx@linutronix.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
import os
import sys
import getopt
import shutil
import string
# Globals
quiet = 0
test = 0
comments = 0
sysfsprefix = "/sys/devices/system/rttest/rttest"
statusfile = "/status"
commandfile = "/command"
# Command opcodes
cmd_opcodes = {
"schedother" : "1",
"schedfifo" : "2",
"lock" : "3",
"locknowait" : "4",
"lockint" : "5",
"lockintnowait" : "6",
"lockcont" : "7",
"unlock" : "8",
"signal" : "11",
"resetevent" : "98",
"reset" : "99",
}
test_opcodes = {
"prioeq" : ["P" , "eq" , None],
"priolt" : ["P" , "lt" , None],
"priogt" : ["P" , "gt" , None],
"nprioeq" : ["N" , "eq" , None],
"npriolt" : ["N" , "lt" , None],
"npriogt" : ["N" , "gt" , None],
"unlocked" : ["M" , "eq" , 0],
"trylock" : ["M" , "eq" , 1],
"blocked" : ["M" , "eq" , 2],
"blockedwake" : ["M" , "eq" , 3],
"locked" : ["M" , "eq" , 4],
"opcodeeq" : ["O" , "eq" , None],
"opcodelt" : ["O" , "lt" , None],
"opcodegt" : ["O" , "gt" , None],
"eventeq" : ["E" , "eq" , None],
"eventlt" : ["E" , "lt" , None],
"eventgt" : ["E" , "gt" , None],
}
# Print usage information
def usage():
print "rt-tester.py <-c -h -q -t> <testfile>"
print " -c display comments after first command"
print " -h help"
print " -q quiet mode"
print " -t test mode (syntax check)"
print " testfile: read test specification from testfile"
print " otherwise from stdin"
return
# Print progress when not in quiet mode
def progress(str):
if not quiet:
print str
# Analyse a status value
def analyse(val, top, arg):
intval = int(val)
if top[0] == "M":
intval = intval / (10 ** int(arg))
intval = intval % 10
argval = top[2]
elif top[0] == "O":
argval = int(cmd_opcodes.get(arg, arg))
else:
argval = int(arg)
# progress("%d %s %d" %(intval, top[1], argval))
if top[1] == "eq" and intval == argval:
return 1
if top[1] == "lt" and intval < argval:
return 1
if top[1] == "gt" and intval > argval:
return 1
return 0
# Parse the commandline
try:
(options, arguments) = getopt.getopt(sys.argv[1:],'chqt')
except getopt.GetoptError, ex:
usage()
sys.exit(1)
# Parse commandline options
for option, value in options:
if option == "-c":
comments = 1
elif option == "-q":
quiet = 1
elif option == "-t":
test = 1
elif option == '-h':
usage()
sys.exit(0)
# Select the input source
if arguments:
try:
fd = open(arguments[0])
except Exception,ex:
sys.stderr.write("File not found %s\n" %(arguments[0]))
sys.exit(1)
else:
fd = sys.stdin
linenr = 0
# Read the test patterns
while 1:
linenr = linenr + 1
line = fd.readline()
if not len(line):
break
line = line.strip()
parts = line.split(":")
if not parts or len(parts) < 1:
continue
if len(parts[0]) == 0:
continue
if parts[0].startswith("#"):
if comments > 1:
progress(line)
continue
if comments == 1:
comments = 2
progress(line)
cmd = parts[0].strip().lower()
opc = parts[1].strip().lower()
tid = parts[2].strip()
dat = parts[3].strip()
try:
# Test or wait for a status value
if cmd == "t" or cmd == "w":
testop = test_opcodes[opc]
fname = "%s%s%s" %(sysfsprefix, tid, statusfile)
if test:
print fname
continue
while 1:
query = 1
fsta = open(fname, 'r')
status = fsta.readline().strip()
fsta.close()
stat = status.split(",")
for s in stat:
s = s.strip()
if s.startswith(testop[0]):
# Separate status value
val = s[2:].strip()
query = analyse(val, testop, dat)
break
if query or cmd == "t":
break
progress(" " + status)
if not query:
sys.stderr.write("Test failed in line %d\n" %(linenr))
sys.exit(1)
# Issue a command to the tester
elif cmd == "c":
cmdnr = cmd_opcodes[opc]
# Build command string and sys filename
cmdstr = "%s:%s" %(cmdnr, dat)
fname = "%s%s%s" %(sysfsprefix, tid, commandfile)
if test:
print fname
continue
fcmd = open(fname, 'w')
fcmd.write(cmdstr)
fcmd.close()
except Exception,ex:
sys.stderr.write(str(ex))
sys.stderr.write("\nSyntax error in line %d\n" %(linenr))
if not test:
fd.close()
sys.exit(1)
# Normal exit pass
print "Pass"
sys.exit(0)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
14059,
13,
19078,
17570,
199,
3,
199,
3,
334,
35,
9,
8315,
27864,
598,
274,
1148,
1372,
665,
84,
18660,
32,
472,
5373,
1148,
14,
271,
30,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
1015,
499,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
646,
747,
199,
646,
984,
199,
646,
12733,
199,
646,
5145,
199,
646,
1059,
199,
199,
3,
13641,
83,
199,
10243,
275,
378,
199,
396,
275,
378,
199,
6223,
275,
378,
199,
199,
1274,
2319,
1861,
275,
3286,
1274,
15,
6410,
15,
2253,
15,
2591,
396,
15,
2591,
396,
2,
199,
1205,
493,
275,
3286,
1205,
2,
199,
1531,
493,
275,
3286,
1531,
2,
199,
199,
3,
5817,
27388,
199,
1760,
63,
22022,
275,
469,
272,
298,
10487,
1848,
2,
259,
520,
298,
17,
401,
272,
298,
10487,
22976,
2,
258,
520,
298,
18,
401,
272,
298,
831,
2,
3515,
520,
298,
19,
401,
272,
298,
831,
20870,
2,
259,
520,
298,
20,
401,
272,
298,
831,
442,
2,
755,
520,
298,
21,
401,
272,
298,
831,
442,
20870,
2,
520,
298,
22,
401,
272,
298,
831,
11096,
2,
420,
520,
298,
23,
401,
272,
298,
17966,
2,
263,
520,
298,
24,
401,
272,
298,
4653,
2,
263,
520,
298,
845,
401,
272,
298,
264,
30563,
782,
2,
259,
520,
298,
2905,
401,
272,
298,
3958,
2,
260,
520,
298,
1020,
401,
272,
789,
199,
199,
396,
63,
22022,
275,
469,
272,
298,
20572,
4077,
2,
263,
520,
2097,
48,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1359,
28934,
2,
263,
520,
2097,
48,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1359,
974,
84,
2,
263,
520,
2097,
48,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
78,
20572,
4077,
2,
755,
520,
2097,
46,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
78,
1359,
28934,
2,
755,
520,
2097,
46,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
78,
1359,
974,
84,
2,
755,
520,
2097,
46,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
32489,
2,
420,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
378,
467,
272,
298,
893,
831,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
413,
467,
272,
298,
17726,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
499,
467,
272,
298,
17726,
15181,
2,
257,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
650,
467,
272,
298,
9325,
2,
263,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
841,
467,
272,
298,
14325,
4077,
2,
420,
520,
2097,
47,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
14325,
4116,
2,
420,
520,
2097,
47,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
14325,
3308,
2,
420,
520,
2097,
47,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
12056,
266,
81,
2,
755,
520,
2097,
37,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1430,
4116,
2,
755,
520,
2097,
37,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1430,
3308,
2,
755,
520,
2097,
37,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
789,
199,
199,
3,
9101,
4503,
2556,
199,
318,
4503,
837,
272,
870,
298,
2591,
13,
8234,
14,
647,
25549,
67,
446,
72,
446,
81,
446,
84,
30,
665,
21091,
4335,
272,
870,
298,
446,
67,
259,
2929,
6786,
2410,
1642,
1414,
2,
272,
870,
298,
446,
72,
259,
1720,
2,
272,
870,
298,
446,
81,
259,
11971,
818,
2,
272,
870,
298,
446,
84,
259,
511,
818,
334,
7093,
1104,
2924,
272,
870,
298,
30530,
26,
1586,
511,
8929,
687,
30530,
2,
272,
870,
298,
4257,
687,
9009,
2,
272,
372,
199,
199,
3,
9101,
6696,
1380,
440,
315,
11971,
818,
199,
318,
6696,
8,
495,
304,
272,
340,
440,
11971,
26,
267,
870,
620,
199,
199,
3,
14279,
261,
282,
2004,
574,
199,
318,
21297,
8,
637,
12,
2746,
12,
1680,
304,
339,
26111,
275,
1109,
8,
637,
9,
339,
340,
2746,
59,
16,
61,
508,
298,
45,
582,
267,
26111,
275,
26111,
1182,
334,
709,
1011,
1109,
8,
1273,
430,
199,
198,
442,
637,
275,
26111,
450,
1616,
267,
27610,
275,
2746,
59,
18,
61,
272,
916,
2746,
59,
16,
61,
508,
298,
47,
582,
267,
27610,
275,
1109,
8,
1760,
63,
22022,
14,
362,
8,
1273,
12,
1680,
430,
272,
587,
26,
267,
27610,
275,
1109,
8,
1273,
9,
339,
327,
6696,
3647,
68,
450,
83,
450,
68,
2,
2818,
442,
637,
12,
2746,
59,
17,
467,
27610,
430,
339,
340,
2746,
59,
17,
61,
508,
298,
4077,
2,
436,
26111,
508,
27610,
26,
199,
198,
1107,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
4116,
2,
436,
26111,
665,
27610,
26,
267,
372,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
3308,
2,
436,
26111,
690,
27610,
26,
199,
198,
1107,
413,
272,
372,
378,
199,
199,
3,
6077,
314,
28279,
199,
893,
26,
272,
334,
1419,
12,
2368,
9,
275,
12733,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
7,
335,
8440,
358,
199,
2590,
12733,
14,
1002,
29368,
12,
444,
26,
272,
4503,
342,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
3,
6077,
28279,
1511,
199,
509,
945,
12,
574,
315,
1511,
26,
272,
340,
945,
508,
3905,
67,
582,
267,
6786,
275,
413,
272,
916,
945,
508,
3905,
81,
582,
267,
11971,
275,
413,
272,
916,
945,
508,
3905,
84,
582,
267,
511,
275,
413,
272,
916,
945,
508,
2475,
72,
356,
267,
4503,
342,
267,
984,
14,
2224,
8,
16,
9,
199,
199,
3,
9496,
314,
1324,
1350,
199,
692,
2368,
26,
272,
862,
26,
267,
6111,
275,
1551,
8,
4958,
59,
16,
566,
272,
871,
2186,
12,
476,
26,
267,
984,
14,
3083,
14,
952,
480,
1173,
440,
1911,
450,
83,
60,
78,
2,
2818,
4958,
59,
16,
2459,
267,
984,
14,
2224
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
14059,
13,
19078,
17570,
199,
3,
199,
3,
334,
35,
9,
8315,
27864,
598,
274,
1148,
1372,
665,
84,
18660,
32,
472,
5373,
1148,
14,
271,
30,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
1015,
499,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
646,
747,
199,
646,
984,
199,
646,
12733,
199,
646,
5145,
199,
646,
1059,
199,
199,
3,
13641,
83,
199,
10243,
275,
378,
199,
396,
275,
378,
199,
6223,
275,
378,
199,
199,
1274,
2319,
1861,
275,
3286,
1274,
15,
6410,
15,
2253,
15,
2591,
396,
15,
2591,
396,
2,
199,
1205,
493,
275,
3286,
1205,
2,
199,
1531,
493,
275,
3286,
1531,
2,
199,
199,
3,
5817,
27388,
199,
1760,
63,
22022,
275,
469,
272,
298,
10487,
1848,
2,
259,
520,
298,
17,
401,
272,
298,
10487,
22976,
2,
258,
520,
298,
18,
401,
272,
298,
831,
2,
3515,
520,
298,
19,
401,
272,
298,
831,
20870,
2,
259,
520,
298,
20,
401,
272,
298,
831,
442,
2,
755,
520,
298,
21,
401,
272,
298,
831,
442,
20870,
2,
520,
298,
22,
401,
272,
298,
831,
11096,
2,
420,
520,
298,
23,
401,
272,
298,
17966,
2,
263,
520,
298,
24,
401,
272,
298,
4653,
2,
263,
520,
298,
845,
401,
272,
298,
264,
30563,
782,
2,
259,
520,
298,
2905,
401,
272,
298,
3958,
2,
260,
520,
298,
1020,
401,
272,
789,
199,
199,
396,
63,
22022,
275,
469,
272,
298,
20572,
4077,
2,
263,
520,
2097,
48,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1359,
28934,
2,
263,
520,
2097,
48,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1359,
974,
84,
2,
263,
520,
2097,
48,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
78,
20572,
4077,
2,
755,
520,
2097,
46,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
78,
1359,
28934,
2,
755,
520,
2097,
46,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
78,
1359,
974,
84,
2,
755,
520,
2097,
46,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
32489,
2,
420,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
378,
467,
272,
298,
893,
831,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
413,
467,
272,
298,
17726,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
499,
467,
272,
298,
17726,
15181,
2,
257,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
650,
467,
272,
298,
9325,
2,
263,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
841,
467,
272,
298,
14325,
4077,
2,
420,
520,
2097,
47,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
14325,
4116,
2,
420,
520,
2097,
47,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
14325,
3308,
2,
420,
520,
2097,
47,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
12056,
266,
81,
2,
755,
520,
2097,
37,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1430,
4116,
2,
755,
520,
2097,
37,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1430,
3308,
2,
755,
520,
2097,
37,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
789,
199,
199,
3,
9101,
4503,
2556,
199,
318,
4503,
837,
272,
870,
298,
2591,
13,
8234,
14,
647,
25549,
67,
446,
72,
446,
81,
446,
84,
30,
665,
21091,
4335,
272,
870,
298,
446,
67,
259,
2929,
6786,
2410,
1642,
1414,
2,
272,
870,
298,
446,
72,
259,
1720,
2,
272,
870,
298,
446,
81,
259,
11971,
818,
2,
272,
870,
298,
446,
84,
259,
511,
818,
334,
7093,
1104,
2924,
272,
870,
298,
30530,
26,
1586,
511,
8929,
687,
30530,
2,
272,
870,
298,
4257,
687,
9009,
2,
272,
372,
199,
199,
3,
9101,
6696,
1380,
440,
315,
11971,
818,
199,
318,
6696,
8,
495,
304,
272,
340,
440,
11971,
26,
267,
870,
620,
199,
199,
3,
14279,
261,
282,
2004,
574,
199,
318,
21297,
8,
637,
12,
2746,
12,
1680,
304,
339,
26111,
275,
1109,
8,
637,
9,
339,
340,
2746,
59,
16,
61,
508,
298,
45,
582,
267,
26111,
275,
26111,
1182,
334,
709,
1011,
1109,
8,
1273,
430,
199,
198,
442,
637,
275,
26111,
450,
1616,
267,
27610,
275,
2746,
59,
18,
61,
272,
916,
2746,
59,
16,
61,
508,
298,
47,
582,
267,
27610,
275,
1109,
8,
1760,
63,
22022,
14,
362,
8,
1273,
12,
1680,
430,
272,
587,
26,
267,
27610,
275,
1109,
8,
1273,
9,
339,
327,
6696,
3647,
68,
450,
83,
450,
68,
2,
2818,
442,
637,
12,
2746,
59,
17,
467,
27610,
430,
339,
340,
2746,
59,
17,
61,
508,
298,
4077,
2,
436,
26111,
508,
27610,
26,
199,
198,
1107,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
4116,
2,
436,
26111,
665,
27610,
26,
267,
372,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
3308,
2,
436,
26111,
690,
27610,
26,
199,
198,
1107,
413,
272,
372,
378,
199,
199,
3,
6077,
314,
28279,
199,
893,
26,
272,
334,
1419,
12,
2368,
9,
275,
12733,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
7,
335,
8440,
358,
199,
2590,
12733,
14,
1002,
29368,
12,
444,
26,
272,
4503,
342,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
3,
6077,
28279,
1511,
199,
509,
945,
12,
574,
315,
1511,
26,
272,
340,
945,
508,
3905,
67,
582,
267,
6786,
275,
413,
272,
916,
945,
508,
3905,
81,
582,
267,
11971,
275,
413,
272,
916,
945,
508,
3905,
84,
582,
267,
511,
275,
413,
272,
916,
945,
508,
2475,
72,
356,
267,
4503,
342,
267,
984,
14,
2224,
8,
16,
9,
199,
199,
3,
9496,
314,
1324,
1350,
199,
692,
2368,
26,
272,
862,
26,
267,
6111,
275,
1551,
8,
4958,
59,
16,
566,
272,
871,
2186,
12,
476,
26,
267,
984,
14,
3083,
14,
952,
480,
1173,
440,
1911,
450,
83,
60,
78,
2,
2818,
4958,
59,
16,
2459,
267,
984,
14,
2224,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
foobnix/foobnix
|
foobnix/gui/window.py
|
3
|
3652
|
#-*- coding: utf-8 -*-
'''
Created on 25 сент. 2010
@author: ivan
'''
import logging
from gi.repository import Gtk
from gi.repository import Gdk
from foobnix.fc.fc import FC
from foobnix.gui.service.path_service import get_foobnix_resourse_path_by_name
from foobnix.util import const
from foobnix.gui.state import LoadSave
from foobnix.version import FOOBNIX_VERSION
from foobnix.gui.model.signal import FControl
from foobnix.util.key_utils import is_key, is_key_alt, is_key_control
class MainWindow(Gtk.Window, FControl, LoadSave):
def __init__(self, controls):
FControl.__init__(self, controls)
Gtk.Window.__init__(self, Gtk.WindowType.TOPLEVEL)
self.set_title("Foobnix " + FOOBNIX_VERSION)
self.set_position(Gtk.WindowPosition.CENTER)
self.set_resizable(True)
self.connect("window-state-event", self.on_change_state)
self.connect("delete-event", self.hide_window)
self.connect("key-press-event", self.on_key_press)
try:
self.set_icon_from_file(get_foobnix_resourse_path_by_name(const.ICON_FOOBNIX))
except TypeError as e:
logging.error(str(e))
self.set_opacity(FC().window_opacity)
self.iconified = False
def on_key_press(self, w, e):
if is_key(e, 'Escape'):
self.hide_window()
elif is_key(e, 'space') and not isinstance(self.get_focus(), Gtk.Entry):
self.controls.play_pause()
elif is_key_alt(e) and is_key(e, "1"):
self.controls.perspectives.activate_perspective("fs")
elif is_key_alt(e) and is_key(e, "2"):
self.controls.perspectives.activate_perspective("radio")
elif is_key_alt(e) and is_key(e, "3"):
self.controls.perspectives.activate_perspective("storage")
elif is_key_alt(e) and is_key(e, "4"):
self.controls.perspectives.activate_perspective("info")
elif is_key_control(e) and (is_key(e, "q") or is_key(e, "Cyrillic_shorti")):
self.controls.quit()
elif is_key_control(e) and (is_key(e, "s") or is_key(e, "Cyrillic_yeru")):
self.controls.notetabs.on_save_playlist(self.controls.notetabs.get_current_tree().scroll)
def on_save(self, *a):
pass
def on_load(self):
cfg = FC().main_window_size
if cfg:
self.resize(cfg[2], cfg[3])
self.move(cfg[0], cfg[1])
if FC().window_maximized:
self.maximize()
def show_hide(self):
visible = self.get_property('visible')
if visible:
self.hide()
else:
self.show()
def hide_window(self, *args):
if FC().on_close_window == const.ON_CLOSE_CLOSE:
self.controls.quit()
elif FC().on_close_window == const.ON_CLOSE_HIDE:
self.hide()
elif FC().on_close_window == const.ON_CLOSE_MINIMIZE:
self.iconify()
logging.debug("On close window action %s" % FC().on_close_window)
return True
def on_change_state(self, w, e):
if int(e.new_window_state) == 0:
"""window restored"""
self.iconified = False
FC().window_maximized = False
elif e.new_window_state & Gdk.WindowState.ICONIFIED:#@UndefinedVariable
"""minimized"""
self.iconified = True
FC().window_maximized = False
elif e.new_window_state & Gdk.WindowState.MAXIMIZED:#@UndefinedVariable
"""maximized"""
self.iconified = False
FC().window_maximized = True
self.controls.layout.back_saved_allocation()
|
gpl-3.0
|
[
3,
13,
1837,
2803,
26,
2774,
13,
24,
1882,
199,
2344,
199,
10502,
641,
5661,
24071,
18624,
7413,
14,
7129,
199,
199,
32,
2502,
26,
18831,
290,
199,
2344,
199,
199,
646,
2050,
199,
199,
504,
18895,
14,
8421,
492,
11424,
199,
504,
18895,
14,
8421,
492,
31392,
199,
199,
504,
3925,
10472,
1148,
14,
3003,
14,
3003,
492,
20934,
199,
504,
3925,
10472,
1148,
14,
5885,
14,
1364,
14,
515,
63,
1364,
492,
664,
63,
1421,
10472,
1148,
63,
470,
4010,
63,
515,
63,
991,
63,
354,
199,
504,
3925,
10472,
1148,
14,
1974,
492,
950,
199,
504,
3925,
10472,
1148,
14,
5885,
14,
929,
492,
7190,
8229,
199,
504,
3925,
10472,
1148,
14,
1023,
492,
481,
47,
5488,
46,
3867,
63,
4612,
199,
504,
3925,
10472,
1148,
14,
5885,
14,
1238,
14,
4653,
492,
481,
3717,
199,
504,
3925,
10472,
1148,
14,
1974,
14,
498,
63,
1208,
492,
365,
63,
498,
12,
365,
63,
498,
63,
4478,
12,
365,
63,
498,
63,
2785,
421,
199,
533,
11298,
4301,
8,
18891,
14,
4301,
12,
481,
3717,
12,
7190,
8229,
304,
272,
347,
636,
826,
721,
277,
12,
13467,
304,
267,
481,
3717,
855,
826,
721,
277,
12,
13467,
9,
267,
11424,
14,
4301,
855,
826,
721,
277,
12,
11424,
14,
4301,
804,
14,
11422,
11817,
9,
398,
291,
14,
409,
63,
1213,
480,
5686,
10472,
1148,
298,
435,
481,
47,
5488,
46,
3867,
63,
4612,
9,
267,
291,
14,
409,
63,
3124,
8,
18891,
14,
4301,
5625,
14,
17611,
9,
267,
291,
14,
409,
63,
264,
5946,
461,
8,
549,
9,
267,
291,
14,
2242,
480,
3806,
13,
929,
13,
1430,
401,
291,
14,
265,
63,
1461,
63,
929,
9,
267,
291,
14,
2242,
480,
1807,
13,
1430,
401,
291,
14,
8191,
63,
3806,
9,
267,
291,
14,
2242,
480,
498,
13,
2915,
13,
1430,
401,
291,
14,
265,
63,
498,
63,
2915,
9,
267,
862,
26,
288,
291,
14,
409,
63,
4677,
63,
504,
63,
493,
8,
362,
63,
1421,
10472,
1148,
63,
470,
4010,
63,
515,
63,
991,
63,
354,
8,
1297,
14,
15903,
63,
3230,
5488,
46,
3867,
430,
267,
871,
3146,
465,
325,
26,
288,
2050,
14,
705,
8,
495,
8,
69,
430,
398,
291,
14,
409,
63,
21861,
8,
4161,
1252,
3806,
63,
21861,
9,
267,
291,
14,
4677,
4541,
275,
756,
339,
347,
641,
63,
498,
63,
2915,
8,
277,
12,
336,
12,
325,
304,
267,
340,
365,
63,
498,
8,
69,
12,
283,
10260,
735,
288,
291,
14,
8191,
63,
3806,
342,
267,
916,
365,
63,
498,
8,
69,
12,
283,
2638,
358,
436,
440,
1228,
8,
277,
14,
362,
63,
12283,
1062,
11424,
14,
3900,
304,
288,
291,
14,
13658,
14,
2802,
63,
11241,
342,
267,
916,
365,
63,
498,
63,
4478,
8,
69,
9,
436,
365,
63,
498,
8,
69,
12,
298,
17,
2349,
288,
291,
14,
13658,
14,
529,
1650,
7301,
14,
8222,
63,
529,
16657,
480,
2319,
531,
267,
916,
365,
63,
498,
63,
4478,
8,
69,
9,
436,
365,
63,
498,
8,
69,
12,
298,
18,
2349,
288,
291,
14,
13658,
14,
529,
1650,
7301,
14,
8222,
63,
529,
16657,
480,
11905,
531,
267,
916,
365,
63,
498,
63,
4478,
8,
69,
9,
436,
365,
63,
498,
8,
69,
12,
298,
19,
2349,
288,
291,
14,
13658,
14,
529,
1650,
7301,
14,
8222,
63,
529,
16657,
480,
3494,
531,
267,
916,
365,
63,
498,
63,
4478,
8,
69,
9,
436,
365,
63,
498,
8,
69,
12,
298,
20,
2349,
288,
291,
14,
13658,
14,
529,
1650,
7301,
14,
8222,
63,
529,
16657,
480,
815,
531,
267,
916,
365,
63,
498,
63,
2785,
8,
69,
9,
436,
334,
374,
63,
498,
8,
69,
12,
298,
81,
531,
503,
365,
63,
498,
8,
69,
12,
298,
9156,
11909,
63,
20695,
280,
14150,
288,
291,
14,
13658,
14,
10589,
342,
267,
916,
365,
63,
498,
63,
2785,
8,
69,
9,
436,
334,
374,
63,
498,
8,
69,
12,
298,
83,
531,
503,
365,
63,
498,
8,
69,
12,
298,
9156,
11909,
63,
23009,
85,
14150,
288,
291,
14,
13658,
14,
4610,
8741,
14,
265,
63,
2117,
63,
10411,
8,
277,
14,
13658,
14,
4610,
8741,
14,
362,
63,
1818,
63,
2350,
1252,
6755,
9,
339,
347,
641,
63,
2117,
8,
277,
12,
627,
65,
304,
267,
986,
339,
347,
641,
63,
912,
8,
277,
304,
267,
4810,
275,
20934,
1252,
973,
63,
3806,
63,
890,
267,
340,
4810,
26,
288,
291,
14,
8709,
8,
4128,
59,
18,
467,
4810,
59,
19,
566,
288,
291,
14,
1185,
8,
4128,
59,
16,
467,
4810,
59,
17,
566,
267,
340,
20934,
1252,
3806,
63,
988,
1017,
1759,
26,
288,
291,
14,
988,
11807,
342,
339,
347,
2498,
63,
8191,
8,
277,
304,
267,
8917,
275,
291,
14,
362,
63,
1829,
360,
6604,
358,
267,
340,
8917,
26,
288,
291,
14,
8191,
342,
267,
587,
26,
288,
291,
14,
2384,
342,
339,
347,
13714,
63,
3806,
8,
277,
12,
627,
589,
304,
267,
340,
20934,
1252,
265,
63,
1600,
63,
3806,
508,
950,
14,
615,
63,
18219,
63,
18219,
26,
288,
291,
14,
13658,
14,
10589,
342,
398,
916,
20934,
1252,
265,
63,
1600,
63,
3806,
508,
950,
14,
615,
63,
18219,
63,
40,
11259,
26,
288,
291,
14,
8191,
342,
398,
916,
20934,
1252,
265,
63,
1600,
63,
3806,
508,
950,
14,
615,
63,
18219,
63,
4896,
1469,
11025,
26,
288,
291,
14,
4677,
2021,
342,
398,
2050,
14,
1757,
480,
3314,
4002,
4353,
1595,
450,
83,
2,
450,
20934,
1252,
265,
63,
1600,
63,
3806,
9,
398,
372,
715,
339,
347,
641,
63,
1461,
63,
929,
8,
277,
12,
336,
12,
325,
304,
398,
340,
1109,
8,
69,
14,
1222,
63,
3806,
63,
929,
9,
508,
378,
26,
288,
408,
3806,
14429,
624,
288,
291,
14,
4677,
4541,
275,
756,
288,
20934,
1252,
3806,
63,
988,
1017,
1759,
275,
756,
398,
916,
325,
14,
1222,
63,
3806,
63,
929,
1253,
31392,
14,
4301,
2223,
14,
15903,
31223,
15596,
32,
16283,
2773,
288,
408,
827,
1017,
1759,
624,
288,
291,
14,
4677,
4541,
275,
715,
288,
20934,
1252,
3806,
63,
988,
1017,
1759,
275,
756,
398,
916
] |
[
13,
1837,
2803,
26,
2774,
13,
24,
1882,
199,
2344,
199,
10502,
641,
5661,
24071,
18624,
7413,
14,
7129,
199,
199,
32,
2502,
26,
18831,
290,
199,
2344,
199,
199,
646,
2050,
199,
199,
504,
18895,
14,
8421,
492,
11424,
199,
504,
18895,
14,
8421,
492,
31392,
199,
199,
504,
3925,
10472,
1148,
14,
3003,
14,
3003,
492,
20934,
199,
504,
3925,
10472,
1148,
14,
5885,
14,
1364,
14,
515,
63,
1364,
492,
664,
63,
1421,
10472,
1148,
63,
470,
4010,
63,
515,
63,
991,
63,
354,
199,
504,
3925,
10472,
1148,
14,
1974,
492,
950,
199,
504,
3925,
10472,
1148,
14,
5885,
14,
929,
492,
7190,
8229,
199,
504,
3925,
10472,
1148,
14,
1023,
492,
481,
47,
5488,
46,
3867,
63,
4612,
199,
504,
3925,
10472,
1148,
14,
5885,
14,
1238,
14,
4653,
492,
481,
3717,
199,
504,
3925,
10472,
1148,
14,
1974,
14,
498,
63,
1208,
492,
365,
63,
498,
12,
365,
63,
498,
63,
4478,
12,
365,
63,
498,
63,
2785,
421,
199,
533,
11298,
4301,
8,
18891,
14,
4301,
12,
481,
3717,
12,
7190,
8229,
304,
272,
347,
636,
826,
721,
277,
12,
13467,
304,
267,
481,
3717,
855,
826,
721,
277,
12,
13467,
9,
267,
11424,
14,
4301,
855,
826,
721,
277,
12,
11424,
14,
4301,
804,
14,
11422,
11817,
9,
398,
291,
14,
409,
63,
1213,
480,
5686,
10472,
1148,
298,
435,
481,
47,
5488,
46,
3867,
63,
4612,
9,
267,
291,
14,
409,
63,
3124,
8,
18891,
14,
4301,
5625,
14,
17611,
9,
267,
291,
14,
409,
63,
264,
5946,
461,
8,
549,
9,
267,
291,
14,
2242,
480,
3806,
13,
929,
13,
1430,
401,
291,
14,
265,
63,
1461,
63,
929,
9,
267,
291,
14,
2242,
480,
1807,
13,
1430,
401,
291,
14,
8191,
63,
3806,
9,
267,
291,
14,
2242,
480,
498,
13,
2915,
13,
1430,
401,
291,
14,
265,
63,
498,
63,
2915,
9,
267,
862,
26,
288,
291,
14,
409,
63,
4677,
63,
504,
63,
493,
8,
362,
63,
1421,
10472,
1148,
63,
470,
4010,
63,
515,
63,
991,
63,
354,
8,
1297,
14,
15903,
63,
3230,
5488,
46,
3867,
430,
267,
871,
3146,
465,
325,
26,
288,
2050,
14,
705,
8,
495,
8,
69,
430,
398,
291,
14,
409,
63,
21861,
8,
4161,
1252,
3806,
63,
21861,
9,
267,
291,
14,
4677,
4541,
275,
756,
339,
347,
641,
63,
498,
63,
2915,
8,
277,
12,
336,
12,
325,
304,
267,
340,
365,
63,
498,
8,
69,
12,
283,
10260,
735,
288,
291,
14,
8191,
63,
3806,
342,
267,
916,
365,
63,
498,
8,
69,
12,
283,
2638,
358,
436,
440,
1228,
8,
277,
14,
362,
63,
12283,
1062,
11424,
14,
3900,
304,
288,
291,
14,
13658,
14,
2802,
63,
11241,
342,
267,
916,
365,
63,
498,
63,
4478,
8,
69,
9,
436,
365,
63,
498,
8,
69,
12,
298,
17,
2349,
288,
291,
14,
13658,
14,
529,
1650,
7301,
14,
8222,
63,
529,
16657,
480,
2319,
531,
267,
916,
365,
63,
498,
63,
4478,
8,
69,
9,
436,
365,
63,
498,
8,
69,
12,
298,
18,
2349,
288,
291,
14,
13658,
14,
529,
1650,
7301,
14,
8222,
63,
529,
16657,
480,
11905,
531,
267,
916,
365,
63,
498,
63,
4478,
8,
69,
9,
436,
365,
63,
498,
8,
69,
12,
298,
19,
2349,
288,
291,
14,
13658,
14,
529,
1650,
7301,
14,
8222,
63,
529,
16657,
480,
3494,
531,
267,
916,
365,
63,
498,
63,
4478,
8,
69,
9,
436,
365,
63,
498,
8,
69,
12,
298,
20,
2349,
288,
291,
14,
13658,
14,
529,
1650,
7301,
14,
8222,
63,
529,
16657,
480,
815,
531,
267,
916,
365,
63,
498,
63,
2785,
8,
69,
9,
436,
334,
374,
63,
498,
8,
69,
12,
298,
81,
531,
503,
365,
63,
498,
8,
69,
12,
298,
9156,
11909,
63,
20695,
280,
14150,
288,
291,
14,
13658,
14,
10589,
342,
267,
916,
365,
63,
498,
63,
2785,
8,
69,
9,
436,
334,
374,
63,
498,
8,
69,
12,
298,
83,
531,
503,
365,
63,
498,
8,
69,
12,
298,
9156,
11909,
63,
23009,
85,
14150,
288,
291,
14,
13658,
14,
4610,
8741,
14,
265,
63,
2117,
63,
10411,
8,
277,
14,
13658,
14,
4610,
8741,
14,
362,
63,
1818,
63,
2350,
1252,
6755,
9,
339,
347,
641,
63,
2117,
8,
277,
12,
627,
65,
304,
267,
986,
339,
347,
641,
63,
912,
8,
277,
304,
267,
4810,
275,
20934,
1252,
973,
63,
3806,
63,
890,
267,
340,
4810,
26,
288,
291,
14,
8709,
8,
4128,
59,
18,
467,
4810,
59,
19,
566,
288,
291,
14,
1185,
8,
4128,
59,
16,
467,
4810,
59,
17,
566,
267,
340,
20934,
1252,
3806,
63,
988,
1017,
1759,
26,
288,
291,
14,
988,
11807,
342,
339,
347,
2498,
63,
8191,
8,
277,
304,
267,
8917,
275,
291,
14,
362,
63,
1829,
360,
6604,
358,
267,
340,
8917,
26,
288,
291,
14,
8191,
342,
267,
587,
26,
288,
291,
14,
2384,
342,
339,
347,
13714,
63,
3806,
8,
277,
12,
627,
589,
304,
267,
340,
20934,
1252,
265,
63,
1600,
63,
3806,
508,
950,
14,
615,
63,
18219,
63,
18219,
26,
288,
291,
14,
13658,
14,
10589,
342,
398,
916,
20934,
1252,
265,
63,
1600,
63,
3806,
508,
950,
14,
615,
63,
18219,
63,
40,
11259,
26,
288,
291,
14,
8191,
342,
398,
916,
20934,
1252,
265,
63,
1600,
63,
3806,
508,
950,
14,
615,
63,
18219,
63,
4896,
1469,
11025,
26,
288,
291,
14,
4677,
2021,
342,
398,
2050,
14,
1757,
480,
3314,
4002,
4353,
1595,
450,
83,
2,
450,
20934,
1252,
265,
63,
1600,
63,
3806,
9,
398,
372,
715,
339,
347,
641,
63,
1461,
63,
929,
8,
277,
12,
336,
12,
325,
304,
398,
340,
1109,
8,
69,
14,
1222,
63,
3806,
63,
929,
9,
508,
378,
26,
288,
408,
3806,
14429,
624,
288,
291,
14,
4677,
4541,
275,
756,
288,
20934,
1252,
3806,
63,
988,
1017,
1759,
275,
756,
398,
916,
325,
14,
1222,
63,
3806,
63,
929,
1253,
31392,
14,
4301,
2223,
14,
15903,
31223,
15596,
32,
16283,
2773,
288,
408,
827,
1017,
1759,
624,
288,
291,
14,
4677,
4541,
275,
715,
288,
20934,
1252,
3806,
63,
988,
1017,
1759,
275,
756,
398,
916,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Juniper/neutron
|
neutron/tests/unit/database_stubs.py
|
20
|
7014
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2011, Cisco Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# @author: Rohit Agarwalla, Cisco Systems, Inc.
"""stubs.py provides interface methods for the database test cases"""
from neutron.db import api as db
from neutron.openstack.common import log as logging
LOG = logging.getLogger(__name__)
class NeutronDB(object):
"""Class conisting of methods to call Neutron db methods."""
def get_all_networks(self, tenant_id):
"""Get all networks."""
nets = []
try:
for net in db.network_list(tenant_id):
LOG.debug("Getting network: %s", net.uuid)
net_dict = {}
net_dict["tenant_id"] = net.tenant_id
net_dict["id"] = str(net.uuid)
net_dict["name"] = net.name
nets.append(net_dict)
except Exception as exc:
LOG.error("Failed to get all networks: %s", str(exc))
return nets
def get_network(self, network_id):
"""Get a network."""
net = []
try:
for net in db.network_get(network_id):
LOG.debug("Getting network: %s", net.uuid)
net_dict = {}
net_dict["tenant_id"] = net.tenant_id
net_dict["id"] = str(net.uuid)
net_dict["name"] = net.name
net.append(net_dict)
except Exception as exc:
LOG.error("Failed to get network: %s", str(exc))
return net
def create_network(self, tenant_id, net_name):
"""Create a network."""
net_dict = {}
try:
res = db.network_create(tenant_id, net_name)
LOG.debug("Created network: %s", res.uuid)
net_dict["tenant_id"] = res.tenant_id
net_dict["id"] = str(res.uuid)
net_dict["name"] = res.name
return net_dict
except Exception as exc:
LOG.error("Failed to create network: %s", str(exc))
def delete_network(self, net_id):
"""Delete a network."""
try:
net = db.network_destroy(net_id)
LOG.debug("Deleted network: %s", net.uuid)
net_dict = {}
net_dict["id"] = str(net.uuid)
return net_dict
except Exception as exc:
LOG.error("Failed to delete network: %s", str(exc))
def update_network(self, tenant_id, net_id, param_data):
"""Rename a network."""
try:
net = db.network_update(net_id, tenant_id, **param_data)
LOG.debug("Updated network: %s", net.uuid)
net_dict = {}
net_dict["id"] = str(net.uuid)
net_dict["name"] = net.name
return net_dict
except Exception as exc:
LOG.error("Failed to update network: %s", str(exc))
def get_all_ports(self, net_id):
"""Get all ports."""
ports = []
try:
for port in db.port_list(net_id):
LOG.debug("Getting port: %s", port.uuid)
port_dict = {}
port_dict["id"] = str(port.uuid)
port_dict["net-id"] = str(port.network_id)
port_dict["attachment"] = port.interface_id
port_dict["state"] = port.state
ports.append(port_dict)
return ports
except Exception as exc:
LOG.error("Failed to get all ports: %s", str(exc))
def get_port(self, net_id, port_id):
"""Get a port."""
port_list = []
port = db.port_get(port_id, net_id)
try:
LOG.debug("Getting port: %s", port.uuid)
port_dict = {}
port_dict["id"] = str(port.uuid)
port_dict["net-id"] = str(port.network_id)
port_dict["attachment"] = port.interface_id
port_dict["state"] = port.state
port_list.append(port_dict)
return port_list
except Exception as exc:
LOG.error("Failed to get port: %s", str(exc))
def create_port(self, net_id):
"""Add a port."""
port_dict = {}
try:
port = db.port_create(net_id)
LOG.debug("Creating port %s", port.uuid)
port_dict["id"] = str(port.uuid)
port_dict["net-id"] = str(port.network_id)
port_dict["attachment"] = port.interface_id
port_dict["state"] = port.state
return port_dict
except Exception as exc:
LOG.error("Failed to create port: %s", str(exc))
def delete_port(self, net_id, port_id):
"""Delete a port."""
try:
port = db.port_destroy(port_id, net_id)
LOG.debug("Deleted port %s", port.uuid)
port_dict = {}
port_dict["id"] = str(port.uuid)
return port_dict
except Exception as exc:
LOG.error("Failed to delete port: %s", str(exc))
def update_port(self, net_id, port_id, **kwargs):
"""Update a port."""
try:
port = db.port_update(port_id, net_id, **kwargs)
LOG.debug("Updated port %s", port.uuid)
port_dict = {}
port_dict["id"] = str(port.uuid)
port_dict["net-id"] = str(port.network_id)
port_dict["attachment"] = port.interface_id
port_dict["state"] = port.state
return port_dict
except Exception as exc:
LOG.error("Failed to update port state: %s", str(exc))
def plug_interface(self, net_id, port_id, int_id):
"""Plug interface to a port."""
try:
port = db.port_set_attachment(port_id, net_id, int_id)
LOG.debug("Attached interface to port %s", port.uuid)
port_dict = {}
port_dict["id"] = str(port.uuid)
port_dict["net-id"] = str(port.network_id)
port_dict["attachment"] = port.interface_id
port_dict["state"] = port.state
return port_dict
except Exception as exc:
LOG.error("Failed to plug interface: %s", str(exc))
def unplug_interface(self, net_id, port_id):
"""Unplug interface to a port."""
try:
db.port_unset_attachment(port_id, net_id)
LOG.debug("Detached interface from port %s", port_id)
except Exception as exc:
LOG.error("Failed to unplug interface: %s", str(exc))
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
7760,
12,
28356,
15285,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
3,
199,
3,
768,
2502,
26,
6848,
12948,
21582,
285,
20877,
416,
12,
28356,
15285,
12,
3277,
14,
199,
199,
624,
8957,
14,
647,
6571,
3217,
3102,
367,
314,
3050,
511,
5560,
624,
199,
199,
504,
8224,
14,
697,
492,
2986,
465,
1592,
199,
504,
8224,
14,
8512,
14,
2330,
492,
943,
465,
2050,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
30422,
2846,
8,
785,
304,
272,
408,
2543,
406,
26958,
402,
3102,
370,
1240,
30422,
1592,
3102,
1041,
272,
347,
664,
63,
452,
63,
7642,
8,
277,
12,
8261,
63,
344,
304,
267,
408,
1002,
1006,
11759,
1041,
267,
1851,
83,
275,
942,
267,
862,
26,
288,
367,
1851,
315,
1592,
14,
1200,
63,
513,
8,
4647,
63,
344,
304,
355,
5051,
14,
1757,
480,
28277,
2784,
26,
450,
83,
401,
1851,
14,
2580,
9,
355,
1851,
63,
807,
275,
1052,
355,
1851,
63,
807,
905,
4647,
63,
344,
937,
275,
1851,
14,
4647,
63,
344,
355,
1851,
63,
807,
905,
344,
937,
275,
620,
8,
846,
14,
2580,
9,
355,
1851,
63,
807,
905,
354,
937,
275,
1851,
14,
354,
355,
1851,
83,
14,
740,
8,
846,
63,
807,
9,
267,
871,
2186,
465,
3178,
26,
288,
5051,
14,
705,
480,
4276,
370,
664,
1006,
11759,
26,
450,
83,
401,
620,
8,
2804,
430,
267,
372,
1851,
83,
339,
347,
664,
63,
1200,
8,
277,
12,
2784,
63,
344,
304,
267,
408,
1002,
282,
2784,
1041,
267,
1851,
275,
942,
267,
862,
26,
288,
367,
1851,
315,
1592,
14,
1200,
63,
362,
8,
1200,
63,
344,
304,
355,
5051,
14,
1757,
480,
28277,
2784,
26,
450,
83,
401,
1851,
14,
2580,
9,
355,
1851,
63,
807,
275,
1052,
355,
1851,
63,
807,
905,
4647,
63,
344,
937,
275,
1851,
14,
4647,
63,
344,
355,
1851,
63,
807,
905,
344,
937,
275,
620,
8,
846,
14,
2580,
9,
355,
1851,
63,
807,
905,
354,
937,
275,
1851,
14,
354,
355,
1851,
14,
740,
8,
846,
63,
807,
9,
267,
871,
2186,
465,
3178,
26,
288,
5051,
14,
705,
480,
4276,
370,
664,
2784,
26,
450,
83,
401,
620,
8,
2804,
430,
267,
372,
1851,
339,
347,
1218,
63,
1200,
8,
277,
12,
8261,
63,
344,
12,
1851,
63,
354,
304,
267,
408,
2499,
282,
2784,
1041,
267,
1851,
63,
807,
275,
1052,
267,
862,
26,
288,
522,
275,
1592,
14,
1200,
63,
981,
8,
4647,
63,
344,
12,
1851,
63,
354,
9,
288,
5051,
14,
1757,
480,
10502,
2784,
26,
450,
83,
401,
522,
14,
2580,
9,
288,
1851,
63,
807,
905,
4647,
63,
344,
937,
275,
522,
14,
4647,
63,
344,
288,
1851,
63,
807,
905,
344,
937,
275,
620,
8,
470,
14,
2580,
9,
288,
1851,
63,
807,
905,
354,
937,
275,
522,
14,
354,
288,
372,
1851,
63,
807,
267,
871,
2186,
465,
3178,
26,
288,
5051,
14,
705,
480,
4276,
370,
1218,
2784,
26,
450,
83,
401,
620,
8,
2804,
430,
339,
347,
3145,
63,
1200,
8,
277,
12,
1851,
63,
344,
304,
267,
408,
5392,
282,
2784,
1041,
267,
862,
26,
288,
1851,
275,
1592,
14,
1200,
63,
7237,
8,
846,
63,
344,
9,
288,
5051,
14,
1757,
480,
17735,
2784,
26,
450,
83,
401,
1851,
14,
2580,
9,
288,
1851,
63,
807,
275,
1052,
288,
1851,
63,
807,
905,
344,
937,
275,
620,
8,
846,
14,
2580,
9,
288,
372,
1851,
63,
807,
267,
871,
2186,
465,
3178,
26,
288,
5051,
14,
705,
480,
4276,
370,
3145,
2784,
26,
450,
83,
401,
620,
8,
2804,
430,
339,
347,
1678,
63,
1200,
8,
277,
12,
8261,
63,
344,
12,
1851,
63,
344,
12,
1215,
63,
576,
304,
267,
408,
16843,
282,
2784,
1041,
267,
862,
26,
288,
1851,
275,
1592,
14,
1200,
63,
873,
8,
846,
63,
344,
12,
8261,
63,
344,
12,
1011,
635,
63,
576,
9,
288,
5051,
14,
1757,
480,
19920,
2784,
26,
450,
83,
401,
1851,
14,
2580,
9,
288,
1851,
63,
807,
275,
1052,
288,
1851,
63,
807,
905,
344,
937,
275,
620,
8,
846,
14,
2580,
9,
288,
1851,
63,
807,
905,
354,
937,
275,
1851,
14,
354,
288,
372,
1851,
63,
807,
267,
871,
2186,
465,
3178,
26,
288,
5051,
14,
705,
480,
4276,
370,
1678,
2784,
26,
450,
83,
401,
620,
8,
2804,
430,
339,
347,
664,
63,
452,
63,
5203,
8,
277,
12,
1851,
63,
344,
304,
267,
408,
1002,
1006,
8873,
1041,
267,
8873,
275,
942,
267,
862,
26,
288,
367,
1844,
315,
1592,
14,
719,
63,
513,
8,
846,
63,
344,
304,
355,
5051,
14,
1757,
480,
28277,
1844,
26,
450,
83,
401,
1844,
14,
2580,
9,
355,
1844,
63,
807,
275,
1052,
355,
1844,
63,
807,
905,
344,
937,
275,
620,
8,
719,
14,
2580,
9,
355,
1844,
63,
807,
905,
846,
13,
344,
937,
275,
620,
8,
719,
14,
1200,
63,
344,
9,
355,
1844,
63,
807,
905,
8905,
937,
275,
1844,
14,
3266,
63,
344,
355,
1844,
63,
807,
905,
929,
937,
275,
1844,
14,
929,
355,
8873,
14,
740,
8,
719,
63,
807,
9,
288,
372,
8873,
267,
871,
2186,
465,
3178,
26,
288,
5051,
14,
705,
480
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
7760,
12,
28356,
15285,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
3,
199,
3,
768,
2502,
26,
6848,
12948,
21582,
285,
20877,
416,
12,
28356,
15285,
12,
3277,
14,
199,
199,
624,
8957,
14,
647,
6571,
3217,
3102,
367,
314,
3050,
511,
5560,
624,
199,
199,
504,
8224,
14,
697,
492,
2986,
465,
1592,
199,
504,
8224,
14,
8512,
14,
2330,
492,
943,
465,
2050,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
30422,
2846,
8,
785,
304,
272,
408,
2543,
406,
26958,
402,
3102,
370,
1240,
30422,
1592,
3102,
1041,
272,
347,
664,
63,
452,
63,
7642,
8,
277,
12,
8261,
63,
344,
304,
267,
408,
1002,
1006,
11759,
1041,
267,
1851,
83,
275,
942,
267,
862,
26,
288,
367,
1851,
315,
1592,
14,
1200,
63,
513,
8,
4647,
63,
344,
304,
355,
5051,
14,
1757,
480,
28277,
2784,
26,
450,
83,
401,
1851,
14,
2580,
9,
355,
1851,
63,
807,
275,
1052,
355,
1851,
63,
807,
905,
4647,
63,
344,
937,
275,
1851,
14,
4647,
63,
344,
355,
1851,
63,
807,
905,
344,
937,
275,
620,
8,
846,
14,
2580,
9,
355,
1851,
63,
807,
905,
354,
937,
275,
1851,
14,
354,
355,
1851,
83,
14,
740,
8,
846,
63,
807,
9,
267,
871,
2186,
465,
3178,
26,
288,
5051,
14,
705,
480,
4276,
370,
664,
1006,
11759,
26,
450,
83,
401,
620,
8,
2804,
430,
267,
372,
1851,
83,
339,
347,
664,
63,
1200,
8,
277,
12,
2784,
63,
344,
304,
267,
408,
1002,
282,
2784,
1041,
267,
1851,
275,
942,
267,
862,
26,
288,
367,
1851,
315,
1592,
14,
1200,
63,
362,
8,
1200,
63,
344,
304,
355,
5051,
14,
1757,
480,
28277,
2784,
26,
450,
83,
401,
1851,
14,
2580,
9,
355,
1851,
63,
807,
275,
1052,
355,
1851,
63,
807,
905,
4647,
63,
344,
937,
275,
1851,
14,
4647,
63,
344,
355,
1851,
63,
807,
905,
344,
937,
275,
620,
8,
846,
14,
2580,
9,
355,
1851,
63,
807,
905,
354,
937,
275,
1851,
14,
354,
355,
1851,
14,
740,
8,
846,
63,
807,
9,
267,
871,
2186,
465,
3178,
26,
288,
5051,
14,
705,
480,
4276,
370,
664,
2784,
26,
450,
83,
401,
620,
8,
2804,
430,
267,
372,
1851,
339,
347,
1218,
63,
1200,
8,
277,
12,
8261,
63,
344,
12,
1851,
63,
354,
304,
267,
408,
2499,
282,
2784,
1041,
267,
1851,
63,
807,
275,
1052,
267,
862,
26,
288,
522,
275,
1592,
14,
1200,
63,
981,
8,
4647,
63,
344,
12,
1851,
63,
354,
9,
288,
5051,
14,
1757,
480,
10502,
2784,
26,
450,
83,
401,
522,
14,
2580,
9,
288,
1851,
63,
807,
905,
4647,
63,
344,
937,
275,
522,
14,
4647,
63,
344,
288,
1851,
63,
807,
905,
344,
937,
275,
620,
8,
470,
14,
2580,
9,
288,
1851,
63,
807,
905,
354,
937,
275,
522,
14,
354,
288,
372,
1851,
63,
807,
267,
871,
2186,
465,
3178,
26,
288,
5051,
14,
705,
480,
4276,
370,
1218,
2784,
26,
450,
83,
401,
620,
8,
2804,
430,
339,
347,
3145,
63,
1200,
8,
277,
12,
1851,
63,
344,
304,
267,
408,
5392,
282,
2784,
1041,
267,
862,
26,
288,
1851,
275,
1592,
14,
1200,
63,
7237,
8,
846,
63,
344,
9,
288,
5051,
14,
1757,
480,
17735,
2784,
26,
450,
83,
401,
1851,
14,
2580,
9,
288,
1851,
63,
807,
275,
1052,
288,
1851,
63,
807,
905,
344,
937,
275,
620,
8,
846,
14,
2580,
9,
288,
372,
1851,
63,
807,
267,
871,
2186,
465,
3178,
26,
288,
5051,
14,
705,
480,
4276,
370,
3145,
2784,
26,
450,
83,
401,
620,
8,
2804,
430,
339,
347,
1678,
63,
1200,
8,
277,
12,
8261,
63,
344,
12,
1851,
63,
344,
12,
1215,
63,
576,
304,
267,
408,
16843,
282,
2784,
1041,
267,
862,
26,
288,
1851,
275,
1592,
14,
1200,
63,
873,
8,
846,
63,
344,
12,
8261,
63,
344,
12,
1011,
635,
63,
576,
9,
288,
5051,
14,
1757,
480,
19920,
2784,
26,
450,
83,
401,
1851,
14,
2580,
9,
288,
1851,
63,
807,
275,
1052,
288,
1851,
63,
807,
905,
344,
937,
275,
620,
8,
846,
14,
2580,
9,
288,
1851,
63,
807,
905,
354,
937,
275,
1851,
14,
354,
288,
372,
1851,
63,
807,
267,
871,
2186,
465,
3178,
26,
288,
5051,
14,
705,
480,
4276,
370,
1678,
2784,
26,
450,
83,
401,
620,
8,
2804,
430,
339,
347,
664,
63,
452,
63,
5203,
8,
277,
12,
1851,
63,
344,
304,
267,
408,
1002,
1006,
8873,
1041,
267,
8873,
275,
942,
267,
862,
26,
288,
367,
1844,
315,
1592,
14,
719,
63,
513,
8,
846,
63,
344,
304,
355,
5051,
14,
1757,
480,
28277,
1844,
26,
450,
83,
401,
1844,
14,
2580,
9,
355,
1844,
63,
807,
275,
1052,
355,
1844,
63,
807,
905,
344,
937,
275,
620,
8,
719,
14,
2580,
9,
355,
1844,
63,
807,
905,
846,
13,
344,
937,
275,
620,
8,
719,
14,
1200,
63,
344,
9,
355,
1844,
63,
807,
905,
8905,
937,
275,
1844,
14,
3266,
63,
344,
355,
1844,
63,
807,
905,
929,
937,
275,
1844,
14,
929,
355,
8873,
14,
740,
8,
719,
63,
807,
9,
288,
372,
8873,
267,
871,
2186,
465,
3178,
26,
288,
5051,
14,
705,
480,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
NEricN/RobotCSimulator
|
Python/App/Lib/test/test_dictviews.py
|
43
|
7519
|
import unittest
from test import test_support
class DictSetTest(unittest.TestCase):
def test_constructors_not_callable(self):
kt = type({}.viewkeys())
self.assertRaises(TypeError, kt, {})
self.assertRaises(TypeError, kt)
it = type({}.viewitems())
self.assertRaises(TypeError, it, {})
self.assertRaises(TypeError, it)
vt = type({}.viewvalues())
self.assertRaises(TypeError, vt, {})
self.assertRaises(TypeError, vt)
def test_dict_keys(self):
d = {1: 10, "a": "ABC"}
keys = d.viewkeys()
self.assertEqual(len(keys), 2)
self.assertEqual(set(keys), set([1, "a"]))
self.assertEqual(keys, set([1, "a"]))
self.assertNotEqual(keys, set([1, "a", "b"]))
self.assertNotEqual(keys, set([1, "b"]))
self.assertNotEqual(keys, set([1]))
self.assertNotEqual(keys, 42)
self.assertIn(1, keys)
self.assertIn("a", keys)
self.assertNotIn(10, keys)
self.assertNotIn("Z", keys)
self.assertEqual(d.viewkeys(), d.viewkeys())
e = {1: 11, "a": "def"}
self.assertEqual(d.viewkeys(), e.viewkeys())
del e["a"]
self.assertNotEqual(d.viewkeys(), e.viewkeys())
def test_dict_items(self):
d = {1: 10, "a": "ABC"}
items = d.viewitems()
self.assertEqual(len(items), 2)
self.assertEqual(set(items), set([(1, 10), ("a", "ABC")]))
self.assertEqual(items, set([(1, 10), ("a", "ABC")]))
self.assertNotEqual(items, set([(1, 10), ("a", "ABC"), "junk"]))
self.assertNotEqual(items, set([(1, 10), ("a", "def")]))
self.assertNotEqual(items, set([(1, 10)]))
self.assertNotEqual(items, 42)
self.assertIn((1, 10), items)
self.assertIn(("a", "ABC"), items)
self.assertNotIn((1, 11), items)
self.assertNotIn(1, items)
self.assertNotIn((), items)
self.assertNotIn((1,), items)
self.assertNotIn((1, 2, 3), items)
self.assertEqual(d.viewitems(), d.viewitems())
e = d.copy()
self.assertEqual(d.viewitems(), e.viewitems())
e["a"] = "def"
self.assertNotEqual(d.viewitems(), e.viewitems())
def test_dict_mixed_keys_items(self):
d = {(1, 1): 11, (2, 2): 22}
e = {1: 1, 2: 2}
self.assertEqual(d.viewkeys(), e.viewitems())
self.assertNotEqual(d.viewitems(), e.viewkeys())
def test_dict_values(self):
d = {1: 10, "a": "ABC"}
values = d.viewvalues()
self.assertEqual(set(values), set([10, "ABC"]))
self.assertEqual(len(values), 2)
def test_dict_repr(self):
d = {1: 10, "a": "ABC"}
self.assertIsInstance(repr(d), str)
r = repr(d.viewitems())
self.assertIsInstance(r, str)
self.assertTrue(r == "dict_items([('a', 'ABC'), (1, 10)])" or
r == "dict_items([(1, 10), ('a', 'ABC')])")
r = repr(d.viewkeys())
self.assertIsInstance(r, str)
self.assertTrue(r == "dict_keys(['a', 1])" or
r == "dict_keys([1, 'a'])")
r = repr(d.viewvalues())
self.assertIsInstance(r, str)
self.assertTrue(r == "dict_values(['ABC', 10])" or
r == "dict_values([10, 'ABC'])")
def test_keys_set_operations(self):
d1 = {'a': 1, 'b': 2}
d2 = {'b': 3, 'c': 2}
d3 = {'d': 4, 'e': 5}
self.assertEqual(d1.viewkeys() & d1.viewkeys(), {'a', 'b'})
self.assertEqual(d1.viewkeys() & d2.viewkeys(), {'b'})
self.assertEqual(d1.viewkeys() & d3.viewkeys(), set())
self.assertEqual(d1.viewkeys() & set(d1.viewkeys()), {'a', 'b'})
self.assertEqual(d1.viewkeys() & set(d2.viewkeys()), {'b'})
self.assertEqual(d1.viewkeys() & set(d3.viewkeys()), set())
self.assertEqual(d1.viewkeys() | d1.viewkeys(), {'a', 'b'})
self.assertEqual(d1.viewkeys() | d2.viewkeys(), {'a', 'b', 'c'})
self.assertEqual(d1.viewkeys() | d3.viewkeys(), {'a', 'b', 'd', 'e'})
self.assertEqual(d1.viewkeys() | set(d1.viewkeys()), {'a', 'b'})
self.assertEqual(d1.viewkeys() | set(d2.viewkeys()), {'a', 'b', 'c'})
self.assertEqual(d1.viewkeys() | set(d3.viewkeys()),
{'a', 'b', 'd', 'e'})
self.assertEqual(d1.viewkeys() ^ d1.viewkeys(), set())
self.assertEqual(d1.viewkeys() ^ d2.viewkeys(), {'a', 'c'})
self.assertEqual(d1.viewkeys() ^ d3.viewkeys(), {'a', 'b', 'd', 'e'})
self.assertEqual(d1.viewkeys() ^ set(d1.viewkeys()), set())
self.assertEqual(d1.viewkeys() ^ set(d2.viewkeys()), {'a', 'c'})
self.assertEqual(d1.viewkeys() ^ set(d3.viewkeys()),
{'a', 'b', 'd', 'e'})
self.assertEqual(d1.viewkeys() - d1.viewkeys(), set())
self.assertEqual(d1.viewkeys() - d2.viewkeys(), {'a'})
self.assertEqual(d1.viewkeys() - d3.viewkeys(), {'a', 'b'})
self.assertEqual(d1.viewkeys() - set(d1.viewkeys()), set())
self.assertEqual(d1.viewkeys() - set(d2.viewkeys()), {'a'})
self.assertEqual(d1.viewkeys() - set(d3.viewkeys()), {'a', 'b'})
def test_items_set_operations(self):
d1 = {'a': 1, 'b': 2}
d2 = {'a': 2, 'b': 2}
d3 = {'d': 4, 'e': 5}
self.assertEqual(
d1.viewitems() & d1.viewitems(), {('a', 1), ('b', 2)})
self.assertEqual(d1.viewitems() & d2.viewitems(), {('b', 2)})
self.assertEqual(d1.viewitems() & d3.viewitems(), set())
self.assertEqual(d1.viewitems() & set(d1.viewitems()),
{('a', 1), ('b', 2)})
self.assertEqual(d1.viewitems() & set(d2.viewitems()), {('b', 2)})
self.assertEqual(d1.viewitems() & set(d3.viewitems()), set())
self.assertEqual(d1.viewitems() | d1.viewitems(),
{('a', 1), ('b', 2)})
self.assertEqual(d1.viewitems() | d2.viewitems(),
{('a', 1), ('a', 2), ('b', 2)})
self.assertEqual(d1.viewitems() | d3.viewitems(),
{('a', 1), ('b', 2), ('d', 4), ('e', 5)})
self.assertEqual(d1.viewitems() | set(d1.viewitems()),
{('a', 1), ('b', 2)})
self.assertEqual(d1.viewitems() | set(d2.viewitems()),
{('a', 1), ('a', 2), ('b', 2)})
self.assertEqual(d1.viewitems() | set(d3.viewitems()),
{('a', 1), ('b', 2), ('d', 4), ('e', 5)})
self.assertEqual(d1.viewitems() ^ d1.viewitems(), set())
self.assertEqual(d1.viewitems() ^ d2.viewitems(),
{('a', 1), ('a', 2)})
self.assertEqual(d1.viewitems() ^ d3.viewitems(),
{('a', 1), ('b', 2), ('d', 4), ('e', 5)})
self.assertEqual(d1.viewitems() - d1.viewitems(), set())
self.assertEqual(d1.viewitems() - d2.viewitems(), {('a', 1)})
self.assertEqual(d1.viewitems() - d3.viewitems(), {('a', 1), ('b', 2)})
self.assertEqual(d1.viewitems() - set(d1.viewitems()), set())
self.assertEqual(d1.viewitems() - set(d2.viewitems()), {('a', 1)})
self.assertEqual(d1.viewitems() - set(d3.viewitems()),
{('a', 1), ('b', 2)})
def test_recursive_repr(self):
d = {}
d[42] = d.viewvalues()
self.assertRaises(RuntimeError, repr, d)
def test_main():
test_support.run_unittest(DictSetTest)
if __name__ == "__main__":
test_main()
|
apache-2.0
|
[
646,
2882,
199,
504,
511,
492,
511,
63,
4058,
199,
199,
533,
7448,
1084,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
1880,
83,
63,
1397,
63,
8296,
8,
277,
304,
267,
1022,
84,
275,
730,
24692,
14,
1345,
1612,
1012,
267,
291,
14,
1855,
8,
4333,
12,
1022,
84,
12,
5009,
267,
291,
14,
1855,
8,
4333,
12,
1022,
84,
9,
267,
652,
275,
730,
24692,
14,
1345,
1744,
1012,
267,
291,
14,
1855,
8,
4333,
12,
652,
12,
5009,
267,
291,
14,
1855,
8,
4333,
12,
652,
9,
267,
18585,
275,
730,
24692,
14,
1345,
1459,
1012,
267,
291,
14,
1855,
8,
4333,
12,
18585,
12,
5009,
267,
291,
14,
1855,
8,
4333,
12,
18585,
9,
339,
347,
511,
63,
807,
63,
1612,
8,
277,
304,
267,
366,
275,
469,
17,
26,
1616,
12,
298,
65,
582,
298,
8390,
3570,
267,
2883,
275,
366,
14,
1345,
1612,
342,
267,
291,
14,
629,
8,
552,
8,
1612,
395,
499,
9,
267,
291,
14,
629,
8,
409,
8,
1612,
395,
663,
779,
17,
12,
298,
65,
13045,
267,
291,
14,
629,
8,
1612,
12,
663,
779,
17,
12,
298,
65,
13045,
267,
291,
14,
7418,
8,
1612,
12,
663,
779,
17,
12,
298,
65,
401,
298,
66,
13045,
267,
291,
14,
7418,
8,
1612,
12,
663,
779,
17,
12,
298,
66,
13045,
267,
291,
14,
7418,
8,
1612,
12,
663,
779,
17,
2459,
267,
291,
14,
7418,
8,
1612,
12,
5685,
9,
267,
291,
14,
4080,
8,
17,
12,
2883,
9,
267,
291,
14,
4080,
480,
65,
401,
2883,
9,
267,
291,
14,
8795,
8,
709,
12,
2883,
9,
267,
291,
14,
8795,
480,
58,
401,
2883,
9,
267,
291,
14,
629,
8,
68,
14,
1345,
1612,
1062,
366,
14,
1345,
1612,
1012,
267,
325,
275,
469,
17,
26,
4119,
12,
298,
65,
582,
298,
318,
3570,
267,
291,
14,
629,
8,
68,
14,
1345,
1612,
1062,
325,
14,
1345,
1612,
1012,
267,
2150,
325,
905,
65,
937,
267,
291,
14,
7418,
8,
68,
14,
1345,
1612,
1062,
325,
14,
1345,
1612,
1012,
339,
347,
511,
63,
807,
63,
1744,
8,
277,
304,
267,
366,
275,
469,
17,
26,
1616,
12,
298,
65,
582,
298,
8390,
3570,
267,
2974,
275,
366,
14,
1345,
1744,
342,
267,
291,
14,
629,
8,
552,
8,
1744,
395,
499,
9,
267,
291,
14,
629,
8,
409,
8,
1744,
395,
663,
7694,
17,
12,
1616,
395,
1689,
65,
401,
298,
8390,
531,
2459,
267,
291,
14,
629,
8,
1744,
12,
663,
7694,
17,
12,
1616,
395,
1689,
65,
401,
298,
8390,
531,
2459,
267,
291,
14,
7418,
8,
1744,
12,
663,
7694,
17,
12,
1616,
395,
1689,
65,
401,
298,
8390,
1288,
298,
17941,
13045,
267,
291,
14,
7418,
8,
1744,
12,
663,
7694,
17,
12,
1616,
395,
1689,
65,
401,
298,
318,
531,
2459,
267,
291,
14,
7418,
8,
1744,
12,
663,
7694,
17,
12,
1616,
19563,
267,
291,
14,
7418,
8,
1744,
12,
5685,
9,
267,
291,
14,
4080,
1332,
17,
12,
1616,
395,
2974,
9,
267,
291,
14,
4080,
9313,
65,
401,
298,
8390,
1288,
2974,
9,
267,
291,
14,
8795,
1332,
17,
12,
4119,
395,
2974,
9,
267,
291,
14,
8795,
8,
17,
12,
2974,
9,
267,
291,
14,
8795,
8,
1062,
2974,
9,
267,
291,
14,
8795,
1332,
17,
4706,
2974,
9,
267,
291,
14,
8795,
1332,
17,
12,
499,
12,
650,
395,
2974,
9,
267,
291,
14,
629,
8,
68,
14,
1345,
1744,
1062,
366,
14,
1345,
1744,
1012,
267,
325,
275,
366,
14,
1574,
342,
267,
291,
14,
629,
8,
68,
14,
1345,
1744,
1062,
325,
14,
1345,
1744,
1012,
267,
325,
905,
65,
937,
275,
298,
318,
2,
267,
291,
14,
7418,
8,
68,
14,
1345,
1744,
1062,
325,
14,
1345,
1744,
1012,
339,
347,
511,
63,
807,
63,
10455,
63,
1612,
63,
1744,
8,
277,
304,
267,
366,
275,
26458,
17,
12,
413,
304,
4119,
12,
334,
18,
12,
499,
304,
6928,
93,
267,
325,
275,
469,
17,
26,
413,
12,
499,
26,
499,
93,
267,
291,
14,
629,
8,
68,
14,
1345,
1612,
1062,
325,
14,
1345,
1744,
1012,
267,
291,
14,
7418,
8,
68,
14,
1345,
1744,
1062,
325,
14,
1345,
1612,
1012,
339,
347,
511,
63,
807,
63,
1459,
8,
277,
304,
267,
366,
275,
469,
17,
26,
1616,
12,
298,
65,
582,
298,
8390,
3570,
267,
1338,
275,
366,
14,
1345,
1459,
342,
267,
291,
14,
629,
8,
409,
8,
1459,
395,
663,
779,
709,
12,
298,
8390,
13045,
267,
291,
14,
629,
8,
552,
8,
1459,
395,
499,
9,
339,
347,
511,
63,
807,
63,
2722,
8,
277,
304,
267,
366,
275,
469,
17,
26,
1616,
12,
298,
65,
582,
298,
8390,
3570,
267,
291,
14,
6926,
8,
2722,
8,
68,
395,
620,
9,
267,
519,
275,
4700,
8,
68,
14,
1345,
1744,
1012,
267,
291,
14,
6926,
8,
82,
12,
620,
9,
267,
291,
14,
1815,
8,
82,
508,
298,
807,
63,
1744,
8318,
65,
297,
283,
8390,
659,
334,
17,
12,
1616,
3948,
2,
503,
717,
519,
508,
298,
807,
63,
1744,
7694,
17,
12,
1616,
395,
661,
65,
297,
283,
8390,
2023,
531,
267,
519,
275,
4700,
8,
68,
14,
1345,
1612,
1012,
267,
291,
14,
6926,
8,
82,
12,
620,
9,
267,
291,
14,
1815,
8,
82,
508,
298,
807,
63,
1612,
2941,
65,
297,
413,
566,
2,
503,
717,
519,
508,
298,
807,
63,
1612,
779,
17,
12,
283,
65,
1105,
531,
267,
519,
275,
4700,
8,
68,
14,
1345,
1459,
1012,
267,
291,
14,
6926,
8,
82,
12,
620,
9,
267,
291,
14,
1815,
8,
82,
508,
298,
807,
63,
1459,
2941,
8390,
297,
1616,
566,
2,
503,
717,
519,
508,
298,
807,
63,
1459,
779,
709,
12,
283,
8390,
1105,
531,
339,
347,
511,
63,
1612,
63,
409,
63,
8170,
8,
277,
304,
267,
366,
17,
275,
791,
65,
356,
413,
12,
283,
66,
356,
499,
93,
267,
366,
18,
275,
791,
66,
356,
650,
12,
283,
67,
356,
499,
93,
267,
366,
19,
275,
791,
68,
356,
841,
12,
283,
69,
356,
959,
93,
267,
291,
14,
629,
8,
68,
17,
14,
1345,
1612,
342
] |
[
2882,
199,
504,
511,
492,
511,
63,
4058,
199,
199,
533,
7448,
1084,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
1880,
83,
63,
1397,
63,
8296,
8,
277,
304,
267,
1022,
84,
275,
730,
24692,
14,
1345,
1612,
1012,
267,
291,
14,
1855,
8,
4333,
12,
1022,
84,
12,
5009,
267,
291,
14,
1855,
8,
4333,
12,
1022,
84,
9,
267,
652,
275,
730,
24692,
14,
1345,
1744,
1012,
267,
291,
14,
1855,
8,
4333,
12,
652,
12,
5009,
267,
291,
14,
1855,
8,
4333,
12,
652,
9,
267,
18585,
275,
730,
24692,
14,
1345,
1459,
1012,
267,
291,
14,
1855,
8,
4333,
12,
18585,
12,
5009,
267,
291,
14,
1855,
8,
4333,
12,
18585,
9,
339,
347,
511,
63,
807,
63,
1612,
8,
277,
304,
267,
366,
275,
469,
17,
26,
1616,
12,
298,
65,
582,
298,
8390,
3570,
267,
2883,
275,
366,
14,
1345,
1612,
342,
267,
291,
14,
629,
8,
552,
8,
1612,
395,
499,
9,
267,
291,
14,
629,
8,
409,
8,
1612,
395,
663,
779,
17,
12,
298,
65,
13045,
267,
291,
14,
629,
8,
1612,
12,
663,
779,
17,
12,
298,
65,
13045,
267,
291,
14,
7418,
8,
1612,
12,
663,
779,
17,
12,
298,
65,
401,
298,
66,
13045,
267,
291,
14,
7418,
8,
1612,
12,
663,
779,
17,
12,
298,
66,
13045,
267,
291,
14,
7418,
8,
1612,
12,
663,
779,
17,
2459,
267,
291,
14,
7418,
8,
1612,
12,
5685,
9,
267,
291,
14,
4080,
8,
17,
12,
2883,
9,
267,
291,
14,
4080,
480,
65,
401,
2883,
9,
267,
291,
14,
8795,
8,
709,
12,
2883,
9,
267,
291,
14,
8795,
480,
58,
401,
2883,
9,
267,
291,
14,
629,
8,
68,
14,
1345,
1612,
1062,
366,
14,
1345,
1612,
1012,
267,
325,
275,
469,
17,
26,
4119,
12,
298,
65,
582,
298,
318,
3570,
267,
291,
14,
629,
8,
68,
14,
1345,
1612,
1062,
325,
14,
1345,
1612,
1012,
267,
2150,
325,
905,
65,
937,
267,
291,
14,
7418,
8,
68,
14,
1345,
1612,
1062,
325,
14,
1345,
1612,
1012,
339,
347,
511,
63,
807,
63,
1744,
8,
277,
304,
267,
366,
275,
469,
17,
26,
1616,
12,
298,
65,
582,
298,
8390,
3570,
267,
2974,
275,
366,
14,
1345,
1744,
342,
267,
291,
14,
629,
8,
552,
8,
1744,
395,
499,
9,
267,
291,
14,
629,
8,
409,
8,
1744,
395,
663,
7694,
17,
12,
1616,
395,
1689,
65,
401,
298,
8390,
531,
2459,
267,
291,
14,
629,
8,
1744,
12,
663,
7694,
17,
12,
1616,
395,
1689,
65,
401,
298,
8390,
531,
2459,
267,
291,
14,
7418,
8,
1744,
12,
663,
7694,
17,
12,
1616,
395,
1689,
65,
401,
298,
8390,
1288,
298,
17941,
13045,
267,
291,
14,
7418,
8,
1744,
12,
663,
7694,
17,
12,
1616,
395,
1689,
65,
401,
298,
318,
531,
2459,
267,
291,
14,
7418,
8,
1744,
12,
663,
7694,
17,
12,
1616,
19563,
267,
291,
14,
7418,
8,
1744,
12,
5685,
9,
267,
291,
14,
4080,
1332,
17,
12,
1616,
395,
2974,
9,
267,
291,
14,
4080,
9313,
65,
401,
298,
8390,
1288,
2974,
9,
267,
291,
14,
8795,
1332,
17,
12,
4119,
395,
2974,
9,
267,
291,
14,
8795,
8,
17,
12,
2974,
9,
267,
291,
14,
8795,
8,
1062,
2974,
9,
267,
291,
14,
8795,
1332,
17,
4706,
2974,
9,
267,
291,
14,
8795,
1332,
17,
12,
499,
12,
650,
395,
2974,
9,
267,
291,
14,
629,
8,
68,
14,
1345,
1744,
1062,
366,
14,
1345,
1744,
1012,
267,
325,
275,
366,
14,
1574,
342,
267,
291,
14,
629,
8,
68,
14,
1345,
1744,
1062,
325,
14,
1345,
1744,
1012,
267,
325,
905,
65,
937,
275,
298,
318,
2,
267,
291,
14,
7418,
8,
68,
14,
1345,
1744,
1062,
325,
14,
1345,
1744,
1012,
339,
347,
511,
63,
807,
63,
10455,
63,
1612,
63,
1744,
8,
277,
304,
267,
366,
275,
26458,
17,
12,
413,
304,
4119,
12,
334,
18,
12,
499,
304,
6928,
93,
267,
325,
275,
469,
17,
26,
413,
12,
499,
26,
499,
93,
267,
291,
14,
629,
8,
68,
14,
1345,
1612,
1062,
325,
14,
1345,
1744,
1012,
267,
291,
14,
7418,
8,
68,
14,
1345,
1744,
1062,
325,
14,
1345,
1612,
1012,
339,
347,
511,
63,
807,
63,
1459,
8,
277,
304,
267,
366,
275,
469,
17,
26,
1616,
12,
298,
65,
582,
298,
8390,
3570,
267,
1338,
275,
366,
14,
1345,
1459,
342,
267,
291,
14,
629,
8,
409,
8,
1459,
395,
663,
779,
709,
12,
298,
8390,
13045,
267,
291,
14,
629,
8,
552,
8,
1459,
395,
499,
9,
339,
347,
511,
63,
807,
63,
2722,
8,
277,
304,
267,
366,
275,
469,
17,
26,
1616,
12,
298,
65,
582,
298,
8390,
3570,
267,
291,
14,
6926,
8,
2722,
8,
68,
395,
620,
9,
267,
519,
275,
4700,
8,
68,
14,
1345,
1744,
1012,
267,
291,
14,
6926,
8,
82,
12,
620,
9,
267,
291,
14,
1815,
8,
82,
508,
298,
807,
63,
1744,
8318,
65,
297,
283,
8390,
659,
334,
17,
12,
1616,
3948,
2,
503,
717,
519,
508,
298,
807,
63,
1744,
7694,
17,
12,
1616,
395,
661,
65,
297,
283,
8390,
2023,
531,
267,
519,
275,
4700,
8,
68,
14,
1345,
1612,
1012,
267,
291,
14,
6926,
8,
82,
12,
620,
9,
267,
291,
14,
1815,
8,
82,
508,
298,
807,
63,
1612,
2941,
65,
297,
413,
566,
2,
503,
717,
519,
508,
298,
807,
63,
1612,
779,
17,
12,
283,
65,
1105,
531,
267,
519,
275,
4700,
8,
68,
14,
1345,
1459,
1012,
267,
291,
14,
6926,
8,
82,
12,
620,
9,
267,
291,
14,
1815,
8,
82,
508,
298,
807,
63,
1459,
2941,
8390,
297,
1616,
566,
2,
503,
717,
519,
508,
298,
807,
63,
1459,
779,
709,
12,
283,
8390,
1105,
531,
339,
347,
511,
63,
1612,
63,
409,
63,
8170,
8,
277,
304,
267,
366,
17,
275,
791,
65,
356,
413,
12,
283,
66,
356,
499,
93,
267,
366,
18,
275,
791,
66,
356,
650,
12,
283,
67,
356,
499,
93,
267,
366,
19,
275,
791,
68,
356,
841,
12,
283,
69,
356,
959,
93,
267,
291,
14,
629,
8,
68,
17,
14,
1345,
1612,
342,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
stutivarshney/Bal-Aveksha
|
WebServer/BalAvekshaEnv/lib/python3.5/site-packages/django/db/backends/mysql/base.py
|
27
|
15759
|
"""
MySQL database backend for Django.
Requires mysqlclient: https://pypi.python.org/pypi/mysqlclient/
MySQLdb is supported for Python 2 only: http://sourceforge.net/projects/mysql-python
"""
from __future__ import unicode_literals
import datetime
import re
import sys
import warnings
from django.conf import settings
from django.db import utils
from django.db.backends import utils as backend_utils
from django.db.backends.base.base import BaseDatabaseWrapper
from django.utils import six, timezone
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.encoding import force_str
from django.utils.functional import cached_property
from django.utils.safestring import SafeBytes, SafeText
try:
import MySQLdb as Database
except ImportError as e:
from django.core.exceptions import ImproperlyConfigured
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
from MySQLdb.constants import CLIENT, FIELD_TYPE # isort:skip
from MySQLdb.converters import Thing2Literal, conversions # isort:skip
# Some of these import MySQLdb, so import them after checking if it's installed.
from .client import DatabaseClient # isort:skip
from .creation import DatabaseCreation # isort:skip
from .features import DatabaseFeatures # isort:skip
from .introspection import DatabaseIntrospection # isort:skip
from .operations import DatabaseOperations # isort:skip
from .schema import DatabaseSchemaEditor # isort:skip
from .validation import DatabaseValidation # isort:skip
# We want version (1, 2, 1, 'final', 2) or later. We can't just use
# lexicographic ordering in this check because then (1, 2, 1, 'gamma')
# inadvertently passes the version test.
version = Database.version_info
if (version < (1, 2, 1) or (
version[:3] == (1, 2, 1) and (len(version) < 5 or version[3] != 'final' or version[4] < 2))):
from django.core.exceptions import ImproperlyConfigured
raise ImproperlyConfigured("MySQLdb-1.2.1p2 or newer is required; you have %s" % Database.__version__)
DatabaseError = Database.DatabaseError
IntegrityError = Database.IntegrityError
def adapt_datetime_warn_on_aware_datetime(value, conv):
# Remove this function and rely on the default adapter in Django 2.0.
if settings.USE_TZ and timezone.is_aware(value):
warnings.warn(
"The MySQL database adapter received an aware datetime (%s), "
"probably from cursor.execute(). Update your code to pass a "
"naive datetime in the database connection's time zone (UTC by "
"default).", RemovedInDjango20Warning)
# This doesn't account for the database connection's timezone,
# which isn't known. (That's why this adapter is deprecated.)
value = value.astimezone(timezone.utc).replace(tzinfo=None)
return Thing2Literal(value.strftime("%Y-%m-%d %H:%M:%S.%f"), conv)
# MySQLdb-1.2.1 returns TIME columns as timedelta -- they are more like
# timedelta in terms of actual behavior as they are signed and include days --
# and Django expects time, so we still need to override that. We also need to
# add special handling for SafeText and SafeBytes as MySQLdb's type
# checking is too tight to catch those (see Django ticket #6052).
django_conversions = conversions.copy()
django_conversions.update({
FIELD_TYPE.TIME: backend_utils.typecast_time,
FIELD_TYPE.DECIMAL: backend_utils.typecast_decimal,
FIELD_TYPE.NEWDECIMAL: backend_utils.typecast_decimal,
datetime.datetime: adapt_datetime_warn_on_aware_datetime,
})
# This should match the numerical portion of the version numbers (we can treat
# versions like 5.0.24 and 5.0.24a as the same).
server_version_re = re.compile(r'(\d{1,2})\.(\d{1,2})\.(\d{1,2})')
# MySQLdb-1.2.1 and newer automatically makes use of SHOW WARNINGS on
# MySQL-4.1 and newer, so the MysqlDebugWrapper is unnecessary. Since the
# point is to raise Warnings as exceptions, this can be done with the Python
# warning module, and this is setup when the connection is created, and the
# standard backend_utils.CursorDebugWrapper can be used. Also, using sql_mode
# TRADITIONAL will automatically cause most warnings to be treated as errors.
class CursorWrapper(object):
"""
A thin wrapper around MySQLdb's normal cursor class so that we can catch
particular exception instances and reraise them with the right types.
Implemented as a wrapper, rather than a subclass, so that we aren't stuck
to the particular underlying representation returned by Connection.cursor().
"""
codes_for_integrityerror = (1048,)
def __init__(self, cursor):
self.cursor = cursor
def execute(self, query, args=None):
try:
# args is None means no string interpolation
return self.cursor.execute(query, args)
except Database.OperationalError as e:
# Map some error codes to IntegrityError, since they seem to be
# misclassified and Django would prefer the more logical place.
if e.args[0] in self.codes_for_integrityerror:
six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])
raise
def executemany(self, query, args):
try:
return self.cursor.executemany(query, args)
except Database.OperationalError as e:
# Map some error codes to IntegrityError, since they seem to be
# misclassified and Django would prefer the more logical place.
if e.args[0] in self.codes_for_integrityerror:
six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])
raise
def __getattr__(self, attr):
if attr in self.__dict__:
return self.__dict__[attr]
else:
return getattr(self.cursor, attr)
def __iter__(self):
return iter(self.cursor)
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
# Ticket #17671 - Close instead of passing thru to avoid backend
# specific behavior.
self.close()
class DatabaseWrapper(BaseDatabaseWrapper):
vendor = 'mysql'
# This dictionary maps Field objects to their associated MySQL column
# types, as strings. Column-type strings can contain format strings; they'll
# be interpolated against the values of Field.__dict__ before being output.
# If a column type is set to None, it won't be included in the output.
_data_types = {
'AutoField': 'integer AUTO_INCREMENT',
'BigAutoField': 'bigint AUTO_INCREMENT',
'BinaryField': 'longblob',
'BooleanField': 'bool',
'CharField': 'varchar(%(max_length)s)',
'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
'DateField': 'date',
'DateTimeField': 'datetime',
'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)',
'DurationField': 'bigint',
'FileField': 'varchar(%(max_length)s)',
'FilePathField': 'varchar(%(max_length)s)',
'FloatField': 'double precision',
'IntegerField': 'integer',
'BigIntegerField': 'bigint',
'IPAddressField': 'char(15)',
'GenericIPAddressField': 'char(39)',
'NullBooleanField': 'bool',
'OneToOneField': 'integer',
'PositiveIntegerField': 'integer UNSIGNED',
'PositiveSmallIntegerField': 'smallint UNSIGNED',
'SlugField': 'varchar(%(max_length)s)',
'SmallIntegerField': 'smallint',
'TextField': 'longtext',
'TimeField': 'time',
'UUIDField': 'char(32)',
}
@cached_property
def data_types(self):
if self.features.supports_microsecond_precision:
return dict(self._data_types, DateTimeField='datetime(6)', TimeField='time(6)')
else:
return self._data_types
operators = {
'exact': '= %s',
'iexact': 'LIKE %s',
'contains': 'LIKE BINARY %s',
'icontains': 'LIKE %s',
'regex': 'REGEXP BINARY %s',
'iregex': 'REGEXP %s',
'gt': '> %s',
'gte': '>= %s',
'lt': '< %s',
'lte': '<= %s',
'startswith': 'LIKE BINARY %s',
'endswith': 'LIKE BINARY %s',
'istartswith': 'LIKE %s',
'iendswith': 'LIKE %s',
}
# The patterns below are used to generate SQL pattern lookup clauses when
# the right-hand side of the lookup isn't a raw string (it might be an expression
# or the result of a bilateral transformation).
# In those cases, special characters for LIKE operators (e.g. \, *, _) should be
# escaped on database side.
#
# Note: we use str.format() here for readability as '%' is used as a wildcard for
# the LIKE operator.
pattern_esc = r"REPLACE(REPLACE(REPLACE({}, '\\', '\\\\'), '%%', '\%%'), '_', '\_')"
pattern_ops = {
'contains': "LIKE BINARY CONCAT('%%', {}, '%%')",
'icontains': "LIKE CONCAT('%%', {}, '%%')",
'startswith': "LIKE BINARY CONCAT({}, '%%')",
'istartswith': "LIKE CONCAT({}, '%%')",
'endswith': "LIKE BINARY CONCAT('%%', {})",
'iendswith': "LIKE CONCAT('%%', {})",
}
Database = Database
SchemaEditorClass = DatabaseSchemaEditor
def __init__(self, *args, **kwargs):
super(DatabaseWrapper, self).__init__(*args, **kwargs)
self.features = DatabaseFeatures(self)
self.ops = DatabaseOperations(self)
self.client = DatabaseClient(self)
self.creation = DatabaseCreation(self)
self.introspection = DatabaseIntrospection(self)
self.validation = DatabaseValidation(self)
def get_connection_params(self):
kwargs = {
'conv': django_conversions,
'charset': 'utf8',
}
if six.PY2:
kwargs['use_unicode'] = True
settings_dict = self.settings_dict
if settings_dict['USER']:
kwargs['user'] = settings_dict['USER']
if settings_dict['NAME']:
kwargs['db'] = settings_dict['NAME']
if settings_dict['PASSWORD']:
kwargs['passwd'] = force_str(settings_dict['PASSWORD'])
if settings_dict['HOST'].startswith('/'):
kwargs['unix_socket'] = settings_dict['HOST']
elif settings_dict['HOST']:
kwargs['host'] = settings_dict['HOST']
if settings_dict['PORT']:
kwargs['port'] = int(settings_dict['PORT'])
# We need the number of potentially affected rows after an
# "UPDATE", not the number of changed rows.
kwargs['client_flag'] = CLIENT.FOUND_ROWS
kwargs.update(settings_dict['OPTIONS'])
return kwargs
def get_new_connection(self, conn_params):
conn = Database.connect(**conn_params)
conn.encoders[SafeText] = conn.encoders[six.text_type]
conn.encoders[SafeBytes] = conn.encoders[bytes]
return conn
def init_connection_state(self):
if self.features.is_sql_auto_is_null_enabled:
with self.cursor() as cursor:
# SQL_AUTO_IS_NULL controls whether an AUTO_INCREMENT column on
# a recently inserted row will return when the field is tested
# for NULL. Disabling this brings this aspect of MySQL in line
# with SQL standards.
cursor.execute('SET SQL_AUTO_IS_NULL = 0')
def create_cursor(self):
cursor = self.connection.cursor()
return CursorWrapper(cursor)
def _rollback(self):
try:
BaseDatabaseWrapper._rollback(self)
except Database.NotSupportedError:
pass
def _set_autocommit(self, autocommit):
with self.wrap_database_errors:
self.connection.autocommit(autocommit)
def disable_constraint_checking(self):
"""
Disables foreign key checks, primarily for use in adding rows with forward references. Always returns True,
to indicate constraint checks need to be re-enabled.
"""
self.cursor().execute('SET foreign_key_checks=0')
return True
def enable_constraint_checking(self):
"""
Re-enable foreign key checks after they have been disabled.
"""
# Override needs_rollback in case constraint_checks_disabled is
# nested inside transaction.atomic.
self.needs_rollback, needs_rollback = False, self.needs_rollback
try:
self.cursor().execute('SET foreign_key_checks=1')
finally:
self.needs_rollback = needs_rollback
def check_constraints(self, table_names=None):
"""
Checks each table name in `table_names` for rows with invalid foreign
key references. This method is intended to be used in conjunction with
`disable_constraint_checking()` and `enable_constraint_checking()`, to
determine if rows with invalid references were entered while constraint
checks were off.
Raises an IntegrityError on the first invalid foreign key reference
encountered (if any) and provides detailed information about the
invalid reference in the error message.
Backends can override this method if they can more directly apply
constraint checking (e.g. via "SET CONSTRAINTS ALL IMMEDIATE")
"""
cursor = self.cursor()
if table_names is None:
table_names = self.introspection.table_names(cursor)
for table_name in table_names:
primary_key_column_name = self.introspection.get_primary_key_column(cursor, table_name)
if not primary_key_column_name:
continue
key_columns = self.introspection.get_key_columns(cursor, table_name)
for column_name, referenced_table_name, referenced_column_name in key_columns:
cursor.execute(
"""
SELECT REFERRING.`%s`, REFERRING.`%s` FROM `%s` as REFERRING
LEFT JOIN `%s` as REFERRED
ON (REFERRING.`%s` = REFERRED.`%s`)
WHERE REFERRING.`%s` IS NOT NULL AND REFERRED.`%s` IS NULL
""" % (
primary_key_column_name, column_name, table_name,
referenced_table_name, column_name, referenced_column_name,
column_name, referenced_column_name,
)
)
for bad_row in cursor.fetchall():
raise utils.IntegrityError(
"The row in table '%s' with primary key '%s' has an invalid "
"foreign key: %s.%s contains a value '%s' that does not have a corresponding value in %s.%s."
% (
table_name, bad_row[0], table_name, column_name,
bad_row[1], referenced_table_name, referenced_column_name,
)
)
def is_usable(self):
try:
self.connection.ping()
except Database.Error:
return False
else:
return True
@cached_property
def mysql_version(self):
with self.temporary_connection() as cursor:
cursor.execute('SELECT VERSION()')
server_info = cursor.fetchone()[0]
match = server_version_re.match(server_info)
if not match:
raise Exception('Unable to determine MySQL version from version string %r' % server_info)
return tuple(int(x) for x in match.groups())
|
gpl-3.0
|
[
624,
199,
20784,
3050,
4865,
367,
5634,
14,
199,
199,
18153,
12896,
1258,
26,
4178,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
15,
8644,
1258,
15,
199,
20784,
697,
365,
3748,
367,
2018,
499,
1454,
26,
1455,
921,
22943,
14,
846,
15,
6776,
15,
8644,
13,
1548,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
646,
295,
199,
646,
984,
199,
646,
3598,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
697,
492,
3778,
199,
504,
1639,
14,
697,
14,
7765,
492,
3778,
465,
4865,
63,
1208,
199,
504,
1639,
14,
697,
14,
7765,
14,
1095,
14,
1095,
492,
29103,
4590,
199,
504,
1639,
14,
1208,
492,
3816,
12,
7137,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
1165,
3849,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
495,
199,
504,
1639,
14,
1208,
14,
15481,
492,
6328,
63,
1829,
199,
504,
1639,
14,
1208,
14,
28389,
492,
14969,
5571,
12,
14969,
1872,
199,
199,
893,
26,
272,
492,
25709,
465,
8692,
199,
2590,
3545,
465,
325,
26,
272,
687,
1639,
14,
1018,
14,
3924,
492,
11897,
272,
746,
11897,
480,
547,
8697,
25709,
859,
26,
450,
83,
2,
450,
325,
9,
199,
199,
504,
25709,
14,
5559,
492,
14214,
1309,
12,
26130,
63,
2711,
4483,
327,
365,
361,
26,
2759,
199,
504,
25709,
14,
17911,
492,
3868,
316,
18,
7621,
12,
24796,
755,
327,
365,
361,
26,
2759,
199,
199,
3,
6601,
402,
3520,
492,
25709,
12,
880,
492,
3062,
2410,
7907,
340,
652,
1159,
4903,
14,
199,
504,
1275,
1258,
492,
8692,
3041,
14516,
327,
365,
361,
26,
2759,
199,
504,
1275,
8782,
492,
8692,
13921,
10473,
327,
365,
361,
26,
2759,
199,
504,
1275,
3179,
492,
8692,
10807,
10473,
327,
365,
361,
26,
2759,
199,
504,
1275,
21627,
492,
8692,
30516,
3322,
327,
365,
361,
26,
2759,
199,
504,
1275,
8170,
492,
8692,
12929,
8295,
327,
365,
361,
26,
2759,
199,
504,
1275,
3629,
492,
8692,
6700,
10423,
8540,
327,
365,
361,
26,
2759,
199,
504,
1275,
6136,
492,
8692,
13816,
8295,
327,
365,
361,
26,
2759,
199,
199,
3,
2136,
2934,
1015,
334,
17,
12,
499,
12,
413,
12,
283,
5094,
297,
499,
9,
503,
2945,
14,
2136,
883,
1133,
2951,
675,
199,
3,
1026,
30077,
9770,
7794,
315,
642,
1104,
2952,
2066,
334,
17,
12,
499,
12,
413,
12,
283,
7325,
358,
199,
3,
315,
350,
422,
767,
590,
14933,
314,
1015,
511,
14,
199,
1023,
275,
8692,
14,
1023,
63,
815,
199,
692,
334,
1023,
665,
334,
17,
12,
499,
12,
413,
9,
503,
334,
267,
1015,
1491,
19,
61,
508,
334,
17,
12,
499,
12,
413,
9,
436,
334,
552,
8,
1023,
9,
665,
959,
503,
1015,
59,
19,
61,
1137,
283,
5094,
7,
503,
1015,
59,
20,
61,
665,
499,
15206,
272,
687,
1639,
14,
1018,
14,
3924,
492,
11897,
272,
746,
11897,
480,
20784,
697,
13,
17,
14,
18,
14,
17,
80,
18,
503,
15666,
365,
1415,
27,
1265,
1172,
450,
83,
2,
450,
8692,
855,
1023,
3368,
421,
199,
25198,
275,
8692,
14,
25198,
199,
24823,
275,
8692,
14,
24823,
421,
199,
318,
19520,
63,
2083,
63,
4050,
63,
265,
63,
14600,
63,
2083,
8,
585,
12,
8260,
304,
272,
327,
5852,
642,
805,
436,
19687,
641,
314,
849,
12146,
315,
5634,
499,
14,
16,
14,
272,
340,
2202,
14,
4701,
63,
14226,
436,
7137,
14,
374,
63,
14600,
8,
585,
304,
267,
3598,
14,
4050,
8,
288,
298,
1918,
11200,
3050,
12146,
3086,
376,
20381,
2197,
4366,
83,
395,
298,
288,
298,
6101,
6665,
687,
3920,
14,
2526,
1252,
6162,
2195,
1233,
370,
986,
282,
298,
288,
298,
21578,
2197,
315,
314,
3050,
1950,
1159,
900,
5718,
334,
11288,
701,
298,
288,
298,
885,
680,
401,
23687,
1165,
3849,
9,
267,
327,
961,
3181,
1133,
2933,
367,
314,
3050,
1950,
1159,
7137,
12,
267,
327,
1314,
5712,
1133,
6040,
14,
334,
17231,
1159,
10842,
642,
12146,
365,
5906,
4959,
267,
574,
275,
574,
14,
29648,
8,
7145,
14,
5834,
680,
1814,
8,
9374,
29,
403,
9,
272,
372,
3868,
316,
18,
7621,
8,
585,
14,
6205,
3647,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
4111,
70,
1288,
8260,
9,
199,
199,
3,
25709,
13,
17,
14,
18,
14,
17,
2529,
17032,
4362,
465,
6871,
1553,
2985,
787,
1655,
2839,
199,
3,
6871,
315,
2895,
402,
3503,
5953,
465,
2985,
787,
10514,
436,
2387,
7609,
1553,
199,
3,
436,
5634,
14292,
900,
12,
880,
781,
5139,
1929,
370,
4278,
626,
14,
2136,
2597,
1929,
370,
199,
3,
1050,
4539,
7252,
367,
14969,
1872,
436,
14969,
5571,
465,
25709,
1159,
730,
199,
3,
7907,
365,
4634,
3367,
913,
370,
8579,
5204,
334,
3239,
5634,
12052,
327,
22,
19730,
680,
199,
1176,
63,
388,
6234,
275,
24796,
14,
1574,
342,
199,
1176,
63,
388,
6234,
14,
873,
2561,
272,
26130,
63,
2711,
14,
4961,
26,
4865,
63,
1208,
14,
466,
2931,
63,
521,
12,
272,
26130,
63,
2711,
14,
23925,
26,
4865,
63,
1208,
14,
466,
2931,
63,
6355,
12,
272,
26130,
63,
2711,
14,
11365,
23925,
26,
4865,
63,
1208,
14,
466,
2931,
63,
6355,
12,
272,
2197,
14,
2083,
26,
19520,
63,
2083,
63,
4050,
63,
265,
63,
14600,
63,
2083,
12,
199,
1552,
199,
199,
3,
961,
1077,
1336,
314,
15470,
18046,
402,
314,
1015,
5579,
334,
1129,
883,
14312,
199,
3,
5459,
2839,
959,
14,
16,
14,
1194,
436,
959,
14,
16,
14,
1194,
65,
465,
314,
2011,
680,
199,
1000,
63,
1023,
63,
264,
275,
295,
14,
2014,
8,
82,
13445,
68,
91,
17,
12,
18,
1552,
4537,
2961,
68,
91,
17,
12,
18,
1552,
4537,
2961,
68,
91,
17,
12,
18,
1552,
358,
421,
199,
3,
25709,
13,
17,
14,
18,
14,
17,
436,
15666,
5847,
7704,
675,
402,
428,
16210,
13253,
46,
3881,
641,
199,
3,
11200,
13,
20,
14,
17,
436,
15666,
12,
880,
314,
603,
6398,
7084,
4590,
365,
23361,
14,
9336,
314,
199,
3,
2376,
365,
370,
746,
644,
2627,
465,
4967,
12,
642,
883,
506,
4224,
543,
314,
2018,
199,
3,
5721,
859,
12,
436
] |
[
199,
20784,
3050,
4865,
367,
5634,
14,
199,
199,
18153,
12896,
1258,
26,
4178,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
15,
8644,
1258,
15,
199,
20784,
697,
365,
3748,
367,
2018,
499,
1454,
26,
1455,
921,
22943,
14,
846,
15,
6776,
15,
8644,
13,
1548,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
646,
295,
199,
646,
984,
199,
646,
3598,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
697,
492,
3778,
199,
504,
1639,
14,
697,
14,
7765,
492,
3778,
465,
4865,
63,
1208,
199,
504,
1639,
14,
697,
14,
7765,
14,
1095,
14,
1095,
492,
29103,
4590,
199,
504,
1639,
14,
1208,
492,
3816,
12,
7137,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
1165,
3849,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
495,
199,
504,
1639,
14,
1208,
14,
15481,
492,
6328,
63,
1829,
199,
504,
1639,
14,
1208,
14,
28389,
492,
14969,
5571,
12,
14969,
1872,
199,
199,
893,
26,
272,
492,
25709,
465,
8692,
199,
2590,
3545,
465,
325,
26,
272,
687,
1639,
14,
1018,
14,
3924,
492,
11897,
272,
746,
11897,
480,
547,
8697,
25709,
859,
26,
450,
83,
2,
450,
325,
9,
199,
199,
504,
25709,
14,
5559,
492,
14214,
1309,
12,
26130,
63,
2711,
4483,
327,
365,
361,
26,
2759,
199,
504,
25709,
14,
17911,
492,
3868,
316,
18,
7621,
12,
24796,
755,
327,
365,
361,
26,
2759,
199,
199,
3,
6601,
402,
3520,
492,
25709,
12,
880,
492,
3062,
2410,
7907,
340,
652,
1159,
4903,
14,
199,
504,
1275,
1258,
492,
8692,
3041,
14516,
327,
365,
361,
26,
2759,
199,
504,
1275,
8782,
492,
8692,
13921,
10473,
327,
365,
361,
26,
2759,
199,
504,
1275,
3179,
492,
8692,
10807,
10473,
327,
365,
361,
26,
2759,
199,
504,
1275,
21627,
492,
8692,
30516,
3322,
327,
365,
361,
26,
2759,
199,
504,
1275,
8170,
492,
8692,
12929,
8295,
327,
365,
361,
26,
2759,
199,
504,
1275,
3629,
492,
8692,
6700,
10423,
8540,
327,
365,
361,
26,
2759,
199,
504,
1275,
6136,
492,
8692,
13816,
8295,
327,
365,
361,
26,
2759,
199,
199,
3,
2136,
2934,
1015,
334,
17,
12,
499,
12,
413,
12,
283,
5094,
297,
499,
9,
503,
2945,
14,
2136,
883,
1133,
2951,
675,
199,
3,
1026,
30077,
9770,
7794,
315,
642,
1104,
2952,
2066,
334,
17,
12,
499,
12,
413,
12,
283,
7325,
358,
199,
3,
315,
350,
422,
767,
590,
14933,
314,
1015,
511,
14,
199,
1023,
275,
8692,
14,
1023,
63,
815,
199,
692,
334,
1023,
665,
334,
17,
12,
499,
12,
413,
9,
503,
334,
267,
1015,
1491,
19,
61,
508,
334,
17,
12,
499,
12,
413,
9,
436,
334,
552,
8,
1023,
9,
665,
959,
503,
1015,
59,
19,
61,
1137,
283,
5094,
7,
503,
1015,
59,
20,
61,
665,
499,
15206,
272,
687,
1639,
14,
1018,
14,
3924,
492,
11897,
272,
746,
11897,
480,
20784,
697,
13,
17,
14,
18,
14,
17,
80,
18,
503,
15666,
365,
1415,
27,
1265,
1172,
450,
83,
2,
450,
8692,
855,
1023,
3368,
421,
199,
25198,
275,
8692,
14,
25198,
199,
24823,
275,
8692,
14,
24823,
421,
199,
318,
19520,
63,
2083,
63,
4050,
63,
265,
63,
14600,
63,
2083,
8,
585,
12,
8260,
304,
272,
327,
5852,
642,
805,
436,
19687,
641,
314,
849,
12146,
315,
5634,
499,
14,
16,
14,
272,
340,
2202,
14,
4701,
63,
14226,
436,
7137,
14,
374,
63,
14600,
8,
585,
304,
267,
3598,
14,
4050,
8,
288,
298,
1918,
11200,
3050,
12146,
3086,
376,
20381,
2197,
4366,
83,
395,
298,
288,
298,
6101,
6665,
687,
3920,
14,
2526,
1252,
6162,
2195,
1233,
370,
986,
282,
298,
288,
298,
21578,
2197,
315,
314,
3050,
1950,
1159,
900,
5718,
334,
11288,
701,
298,
288,
298,
885,
680,
401,
23687,
1165,
3849,
9,
267,
327,
961,
3181,
1133,
2933,
367,
314,
3050,
1950,
1159,
7137,
12,
267,
327,
1314,
5712,
1133,
6040,
14,
334,
17231,
1159,
10842,
642,
12146,
365,
5906,
4959,
267,
574,
275,
574,
14,
29648,
8,
7145,
14,
5834,
680,
1814,
8,
9374,
29,
403,
9,
272,
372,
3868,
316,
18,
7621,
8,
585,
14,
6205,
3647,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
4111,
70,
1288,
8260,
9,
199,
199,
3,
25709,
13,
17,
14,
18,
14,
17,
2529,
17032,
4362,
465,
6871,
1553,
2985,
787,
1655,
2839,
199,
3,
6871,
315,
2895,
402,
3503,
5953,
465,
2985,
787,
10514,
436,
2387,
7609,
1553,
199,
3,
436,
5634,
14292,
900,
12,
880,
781,
5139,
1929,
370,
4278,
626,
14,
2136,
2597,
1929,
370,
199,
3,
1050,
4539,
7252,
367,
14969,
1872,
436,
14969,
5571,
465,
25709,
1159,
730,
199,
3,
7907,
365,
4634,
3367,
913,
370,
8579,
5204,
334,
3239,
5634,
12052,
327,
22,
19730,
680,
199,
1176,
63,
388,
6234,
275,
24796,
14,
1574,
342,
199,
1176,
63,
388,
6234,
14,
873,
2561,
272,
26130,
63,
2711,
14,
4961,
26,
4865,
63,
1208,
14,
466,
2931,
63,
521,
12,
272,
26130,
63,
2711,
14,
23925,
26,
4865,
63,
1208,
14,
466,
2931,
63,
6355,
12,
272,
26130,
63,
2711,
14,
11365,
23925,
26,
4865,
63,
1208,
14,
466,
2931,
63,
6355,
12,
272,
2197,
14,
2083,
26,
19520,
63,
2083,
63,
4050,
63,
265,
63,
14600,
63,
2083,
12,
199,
1552,
199,
199,
3,
961,
1077,
1336,
314,
15470,
18046,
402,
314,
1015,
5579,
334,
1129,
883,
14312,
199,
3,
5459,
2839,
959,
14,
16,
14,
1194,
436,
959,
14,
16,
14,
1194,
65,
465,
314,
2011,
680,
199,
1000,
63,
1023,
63,
264,
275,
295,
14,
2014,
8,
82,
13445,
68,
91,
17,
12,
18,
1552,
4537,
2961,
68,
91,
17,
12,
18,
1552,
4537,
2961,
68,
91,
17,
12,
18,
1552,
358,
421,
199,
3,
25709,
13,
17,
14,
18,
14,
17,
436,
15666,
5847,
7704,
675,
402,
428,
16210,
13253,
46,
3881,
641,
199,
3,
11200,
13,
20,
14,
17,
436,
15666,
12,
880,
314,
603,
6398,
7084,
4590,
365,
23361,
14,
9336,
314,
199,
3,
2376,
365,
370,
746,
644,
2627,
465,
4967,
12,
642,
883,
506,
4224,
543,
314,
2018,
199,
3,
5721,
859,
12,
436,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
doganov/edx-platform
|
cms/djangoapps/contentstore/views/program.py
|
27
|
2158
|
"""Programs views for use with Studio."""
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.http import Http404, JsonResponse
from django.utils.decorators import method_decorator
from django.views.generic import View
from edxmako.shortcuts import render_to_response
from openedx.core.djangoapps.programs.models import ProgramsApiConfig
from openedx.core.lib.token_utils import get_id_token
class ProgramAuthoringView(View):
"""View rendering a template which hosts the Programs authoring app.
The Programs authoring app is a Backbone SPA maintained in a separate repository.
The app handles its own routing and provides a UI which can be used to create and
publish new Programs (e.g, XSeries).
"""
@method_decorator(login_required)
def get(self, request, *args, **kwargs):
"""Populate the template context with values required for the authoring app to run."""
programs_config = ProgramsApiConfig.current()
if programs_config.is_studio_tab_enabled and request.user.is_staff:
return render_to_response('program_authoring.html', {
'show_programs_header': programs_config.is_studio_tab_enabled,
'authoring_app_config': programs_config.authoring_app_config,
'lms_base_url': '//{}/'.format(settings.LMS_BASE),
'programs_api_url': programs_config.public_api_url,
'programs_token_url': reverse('programs_id_token'),
'studio_home_url': reverse('home'),
})
else:
raise Http404
class ProgramsIdTokenView(View):
"""Provides id tokens to JavaScript clients for use with the Programs API."""
@method_decorator(login_required)
def get(self, request, *args, **kwargs):
"""Generate and return a token, if the integration is enabled."""
if ProgramsApiConfig.current().is_studio_tab_enabled:
id_token = get_id_token(request.user, 'programs')
return JsonResponse({'id_token': id_token})
else:
raise Http404
|
agpl-3.0
|
[
624,
919,
9292,
6858,
367,
675,
543,
13225,
1041,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
12,
21072,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1083,
63,
11547,
199,
504,
1639,
14,
4196,
14,
6767,
492,
10935,
199,
199,
504,
22435,
19491,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
504,
22709,
14,
1018,
14,
16432,
14,
28464,
14,
992,
492,
2165,
9292,
7394,
2028,
199,
504,
22709,
14,
1018,
14,
773,
14,
1418,
63,
1208,
492,
664,
63,
344,
63,
1418,
421,
199,
533,
18841,
5949,
316,
2768,
8,
2768,
304,
272,
408,
2768,
14066,
282,
1978,
1314,
7057,
314,
2165,
9292,
4132,
316,
1145,
14,
339,
710,
2165,
9292,
4132,
316,
1145,
365,
282,
10257,
21134,
6988,
33,
26391,
315,
282,
7396,
7611,
14,
272,
710,
1145,
10022,
2399,
5705,
14870,
436,
6571,
282,
14041,
1314,
883,
506,
1202,
370,
1218,
436,
272,
2780,
892,
2165,
9292,
334,
69,
14,
71,
12,
1323,
9641,
680,
272,
408,
339,
768,
765,
63,
11547,
8,
2886,
63,
2427,
9,
272,
347,
664,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
9606,
5434,
314,
1978,
1067,
543,
1338,
1415,
367,
314,
4132,
316,
1145,
370,
1255,
1041,
267,
18572,
63,
888,
275,
2165,
9292,
7394,
2028,
14,
1818,
342,
398,
340,
18572,
63,
888,
14,
374,
63,
19806,
63,
2902,
63,
3827,
436,
1056,
14,
751,
14,
374,
63,
7018,
26,
288,
372,
3795,
63,
475,
63,
1310,
360,
6815,
63,
2502,
316,
14,
1360,
297,
469,
355,
283,
2384,
63,
28464,
63,
1291,
356,
18572,
63,
888,
14,
374,
63,
19806,
63,
2902,
63,
3827,
12,
355,
283,
2502,
316,
63,
571,
63,
888,
356,
18572,
63,
888,
14,
2502,
316,
63,
571,
63,
888,
12,
355,
283,
15807,
63,
1095,
63,
633,
356,
18290,
2440,
15,
1370,
908,
8,
1751,
14,
44,
3053,
63,
5825,
395,
355,
283,
28464,
63,
1246,
63,
633,
356,
18572,
63,
888,
14,
3455,
63,
1246,
63,
633,
12,
355,
283,
28464,
63,
1418,
63,
633,
356,
3837,
360,
28464,
63,
344,
63,
1418,
659,
355,
283,
19806,
63,
4219,
63,
633,
356,
3837,
360,
4219,
659,
288,
3828,
267,
587,
26,
288,
746,
4760,
5188,
421,
199,
533,
2165,
9292,
1304,
3264,
2768,
8,
2768,
304,
272,
408,
17473,
1305,
4645,
370,
15250,
13431,
367,
675,
543,
314,
2165,
9292,
3261,
1041,
339,
768,
765,
63,
11547,
8,
2886,
63,
2427,
9,
272,
347,
664,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
6864,
436,
372,
282,
1526,
12,
340,
314,
13150,
365,
5223,
1041,
267,
340,
2165,
9292,
7394,
2028,
14,
1818,
1252,
374,
63,
19806,
63,
2902,
63,
3827,
26,
288,
1305,
63,
1418,
275,
664,
63,
344,
63,
1418,
8,
1069,
14,
751,
12,
283,
28464,
358,
288,
372,
21072,
3252,
344,
63,
1418,
356,
1305,
63,
1418,
1552,
267,
587,
26,
288,
746,
4760,
5188,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
919,
9292,
6858,
367,
675,
543,
13225,
1041,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
12,
21072,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1083,
63,
11547,
199,
504,
1639,
14,
4196,
14,
6767,
492,
10935,
199,
199,
504,
22435,
19491,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
504,
22709,
14,
1018,
14,
16432,
14,
28464,
14,
992,
492,
2165,
9292,
7394,
2028,
199,
504,
22709,
14,
1018,
14,
773,
14,
1418,
63,
1208,
492,
664,
63,
344,
63,
1418,
421,
199,
533,
18841,
5949,
316,
2768,
8,
2768,
304,
272,
408,
2768,
14066,
282,
1978,
1314,
7057,
314,
2165,
9292,
4132,
316,
1145,
14,
339,
710,
2165,
9292,
4132,
316,
1145,
365,
282,
10257,
21134,
6988,
33,
26391,
315,
282,
7396,
7611,
14,
272,
710,
1145,
10022,
2399,
5705,
14870,
436,
6571,
282,
14041,
1314,
883,
506,
1202,
370,
1218,
436,
272,
2780,
892,
2165,
9292,
334,
69,
14,
71,
12,
1323,
9641,
680,
272,
408,
339,
768,
765,
63,
11547,
8,
2886,
63,
2427,
9,
272,
347,
664,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
9606,
5434,
314,
1978,
1067,
543,
1338,
1415,
367,
314,
4132,
316,
1145,
370,
1255,
1041,
267,
18572,
63,
888,
275,
2165,
9292,
7394,
2028,
14,
1818,
342,
398,
340,
18572,
63,
888,
14,
374,
63,
19806,
63,
2902,
63,
3827,
436,
1056,
14,
751,
14,
374,
63,
7018,
26,
288,
372,
3795,
63,
475,
63,
1310,
360,
6815,
63,
2502,
316,
14,
1360,
297,
469,
355,
283,
2384,
63,
28464,
63,
1291,
356,
18572,
63,
888,
14,
374,
63,
19806,
63,
2902,
63,
3827,
12,
355,
283,
2502,
316,
63,
571,
63,
888,
356,
18572,
63,
888,
14,
2502,
316,
63,
571,
63,
888,
12,
355,
283,
15807,
63,
1095,
63,
633,
356,
18290,
2440,
15,
1370,
908,
8,
1751,
14,
44,
3053,
63,
5825,
395,
355,
283,
28464,
63,
1246,
63,
633,
356,
18572,
63,
888,
14,
3455,
63,
1246,
63,
633,
12,
355,
283,
28464,
63,
1418,
63,
633,
356,
3837,
360,
28464,
63,
344,
63,
1418,
659,
355,
283,
19806,
63,
4219,
63,
633,
356,
3837,
360,
4219,
659,
288,
3828,
267,
587,
26,
288,
746,
4760,
5188,
421,
199,
533,
2165,
9292,
1304,
3264,
2768,
8,
2768,
304,
272,
408,
17473,
1305,
4645,
370,
15250,
13431,
367,
675,
543,
314,
2165,
9292,
3261,
1041,
339,
768,
765,
63,
11547,
8,
2886,
63,
2427,
9,
272,
347,
664,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
6864,
436,
372,
282,
1526,
12,
340,
314,
13150,
365,
5223,
1041,
267,
340,
2165,
9292,
7394,
2028,
14,
1818,
1252,
374,
63,
19806,
63,
2902,
63,
3827,
26,
288,
1305,
63,
1418,
275,
664,
63,
344,
63,
1418,
8,
1069,
14,
751,
12,
283,
28464,
358,
288,
372,
21072,
3252,
344,
63,
1418,
356,
1305,
63,
1418,
1552,
267,
587,
26,
288,
746,
4760,
5188,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
ketjow4/NOV
|
Lib/site-packages/numpy/polynomial/tests/test_polynomial.py
|
54
|
16718
|
"""Tests for polynomial module.
"""
from __future__ import division
import numpy as np
import numpy.polynomial.polynomial as poly
from numpy.testing import *
def trim(x) :
return poly.polytrim(x, tol=1e-6)
T0 = [ 1]
T1 = [ 0, 1]
T2 = [-1, 0, 2]
T3 = [ 0, -3, 0, 4]
T4 = [ 1, 0, -8, 0, 8]
T5 = [ 0, 5, 0, -20, 0, 16]
T6 = [-1, 0, 18, 0, -48, 0, 32]
T7 = [ 0, -7, 0, 56, 0, -112, 0, 64]
T8 = [ 1, 0, -32, 0, 160, 0, -256, 0, 128]
T9 = [ 0, 9, 0, -120, 0, 432, 0, -576, 0, 256]
Tlist = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9]
class TestConstants(TestCase) :
def test_polydomain(self) :
assert_equal(poly.polydomain, [-1, 1])
def test_polyzero(self) :
assert_equal(poly.polyzero, [0])
def test_polyone(self) :
assert_equal(poly.polyone, [1])
def test_polyx(self) :
assert_equal(poly.polyx, [0, 1])
class TestArithmetic(TestCase) :
def test_polyadd(self) :
for i in range(5) :
for j in range(5) :
msg = "At i=%d, j=%d" % (i,j)
tgt = np.zeros(max(i,j) + 1)
tgt[i] += 1
tgt[j] += 1
res = poly.polyadd([0]*i + [1], [0]*j + [1])
assert_equal(trim(res), trim(tgt), err_msg=msg)
def test_polysub(self) :
for i in range(5) :
for j in range(5) :
msg = "At i=%d, j=%d" % (i,j)
tgt = np.zeros(max(i,j) + 1)
tgt[i] += 1
tgt[j] -= 1
res = poly.polysub([0]*i + [1], [0]*j + [1])
assert_equal(trim(res), trim(tgt), err_msg=msg)
def test_polymulx(self):
assert_equal(poly.polymulx([0]), [0])
assert_equal(poly.polymulx([1]), [0, 1])
for i in range(1, 5):
ser = [0]*i + [1]
tgt = [0]*(i + 1) + [1]
assert_equal(poly.polymulx(ser), tgt)
def test_polymul(self) :
for i in range(5) :
for j in range(5) :
msg = "At i=%d, j=%d" % (i,j)
tgt = np.zeros(i + j + 1)
tgt[i + j] += 1
res = poly.polymul([0]*i + [1], [0]*j + [1])
assert_equal(trim(res), trim(tgt), err_msg=msg)
def test_polydiv(self) :
# check zero division
assert_raises(ZeroDivisionError, poly.polydiv, [1], [0])
# check scalar division
quo, rem = poly.polydiv([2],[2])
assert_equal((quo, rem), (1, 0))
quo, rem = poly.polydiv([2,2],[2])
assert_equal((quo, rem), ((1,1), 0))
# check rest.
for i in range(5) :
for j in range(5) :
msg = "At i=%d, j=%d" % (i,j)
ci = [0]*i + [1,2]
cj = [0]*j + [1,2]
tgt = poly.polyadd(ci, cj)
quo, rem = poly.polydiv(tgt, ci)
res = poly.polyadd(poly.polymul(quo, ci), rem)
assert_equal(res, tgt, err_msg=msg)
def test_polyval(self) :
def f(x) :
return x*(x**2 - 1)
#check empty input
assert_equal(poly.polyval([], [1]).size, 0)
#check normal input)
x = np.linspace(-1,1)
for i in range(5) :
tgt = x**i
res = poly.polyval(x, [0]*i + [1])
assert_almost_equal(res, tgt)
tgt = f(x)
res = poly.polyval(x, [0, -1, 0, 1])
assert_almost_equal(res, tgt)
#check that shape is preserved
for i in range(3) :
dims = [2]*i
x = np.zeros(dims)
assert_equal(poly.polyval(x, [1]).shape, dims)
assert_equal(poly.polyval(x, [1,0]).shape, dims)
assert_equal(poly.polyval(x, [1,0,0]).shape, dims)
class TestCalculus(TestCase) :
def test_polyint(self) :
# check exceptions
assert_raises(ValueError, poly.polyint, [0], .5)
assert_raises(ValueError, poly.polyint, [0], -1)
assert_raises(ValueError, poly.polyint, [0], 1, [0,0])
# test integration of zero polynomial
for i in range(2, 5):
k = [0]*(i - 2) + [1]
res = poly.polyint([0], m=i, k=k)
assert_almost_equal(res, [0, 1])
# check single integration with integration constant
for i in range(5) :
scl = i + 1
pol = [0]*i + [1]
tgt = [i] + [0]*i + [1/scl]
res = poly.polyint(pol, m=1, k=[i])
assert_almost_equal(trim(res), trim(tgt))
# check single integration with integration constant and lbnd
for i in range(5) :
scl = i + 1
pol = [0]*i + [1]
res = poly.polyint(pol, m=1, k=[i], lbnd=-1)
assert_almost_equal(poly.polyval(-1, res), i)
# check single integration with integration constant and scaling
for i in range(5) :
scl = i + 1
pol = [0]*i + [1]
tgt = [i] + [0]*i + [2/scl]
res = poly.polyint(pol, m=1, k=[i], scl=2)
assert_almost_equal(trim(res), trim(tgt))
# check multiple integrations with default k
for i in range(5) :
for j in range(2,5) :
pol = [0]*i + [1]
tgt = pol[:]
for k in range(j) :
tgt = poly.polyint(tgt, m=1)
res = poly.polyint(pol, m=j)
assert_almost_equal(trim(res), trim(tgt))
# check multiple integrations with defined k
for i in range(5) :
for j in range(2,5) :
pol = [0]*i + [1]
tgt = pol[:]
for k in range(j) :
tgt = poly.polyint(tgt, m=1, k=[k])
res = poly.polyint(pol, m=j, k=range(j))
assert_almost_equal(trim(res), trim(tgt))
# check multiple integrations with lbnd
for i in range(5) :
for j in range(2,5) :
pol = [0]*i + [1]
tgt = pol[:]
for k in range(j) :
tgt = poly.polyint(tgt, m=1, k=[k], lbnd=-1)
res = poly.polyint(pol, m=j, k=range(j), lbnd=-1)
assert_almost_equal(trim(res), trim(tgt))
# check multiple integrations with scaling
for i in range(5) :
for j in range(2,5) :
pol = [0]*i + [1]
tgt = pol[:]
for k in range(j) :
tgt = poly.polyint(tgt, m=1, k=[k], scl=2)
res = poly.polyint(pol, m=j, k=range(j), scl=2)
assert_almost_equal(trim(res), trim(tgt))
def test_polyder(self) :
# check exceptions
assert_raises(ValueError, poly.polyder, [0], .5)
assert_raises(ValueError, poly.polyder, [0], -1)
# check that zeroth deriviative does nothing
for i in range(5) :
tgt = [1] + [0]*i
res = poly.polyder(tgt, m=0)
assert_equal(trim(res), trim(tgt))
# check that derivation is the inverse of integration
for i in range(5) :
for j in range(2,5) :
tgt = [1] + [0]*i
res = poly.polyder(poly.polyint(tgt, m=j), m=j)
assert_almost_equal(trim(res), trim(tgt))
# check derivation with scaling
for i in range(5) :
for j in range(2,5) :
tgt = [1] + [0]*i
res = poly.polyder(poly.polyint(tgt, m=j, scl=2), m=j, scl=.5)
assert_almost_equal(trim(res), trim(tgt))
class TestMisc(TestCase) :
def test_polyfromroots(self) :
res = poly.polyfromroots([])
assert_almost_equal(trim(res), [1])
for i in range(1,5) :
roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
tgt = Tlist[i]
res = poly.polyfromroots(roots)*2**(i-1)
assert_almost_equal(trim(res),trim(tgt))
def test_polyroots(self) :
assert_almost_equal(poly.polyroots([1]), [])
assert_almost_equal(poly.polyroots([1, 2]), [-.5])
for i in range(2,5) :
tgt = np.linspace(-1, 1, i)
res = poly.polyroots(poly.polyfromroots(tgt))
assert_almost_equal(trim(res), trim(tgt))
def test_polyvander(self) :
# check for 1d x
x = np.arange(3)
v = poly.polyvander(x, 3)
assert_(v.shape == (3,4))
for i in range(4) :
coef = [0]*i + [1]
assert_almost_equal(v[...,i], poly.polyval(x, coef))
# check for 2d x
x = np.array([[1,2],[3,4],[5,6]])
v = poly.polyvander(x, 3)
assert_(v.shape == (3,2,4))
for i in range(4) :
coef = [0]*i + [1]
assert_almost_equal(v[...,i], poly.polyval(x, coef))
def test_polyfit(self) :
def f(x) :
return x*(x - 1)*(x - 2)
# Test exceptions
assert_raises(ValueError, poly.polyfit, [1], [1], -1)
assert_raises(TypeError, poly.polyfit, [[1]], [1], 0)
assert_raises(TypeError, poly.polyfit, [], [1], 0)
assert_raises(TypeError, poly.polyfit, [1], [[[1]]], 0)
assert_raises(TypeError, poly.polyfit, [1, 2], [1], 0)
assert_raises(TypeError, poly.polyfit, [1], [1, 2], 0)
assert_raises(TypeError, poly.polyfit, [1], [1], 0, w=[[1]])
assert_raises(TypeError, poly.polyfit, [1], [1], 0, w=[1,1])
# Test fit
x = np.linspace(0,2)
y = f(x)
#
coef3 = poly.polyfit(x, y, 3)
assert_equal(len(coef3), 4)
assert_almost_equal(poly.polyval(x, coef3), y)
#
coef4 = poly.polyfit(x, y, 4)
assert_equal(len(coef4), 5)
assert_almost_equal(poly.polyval(x, coef4), y)
#
coef2d = poly.polyfit(x, np.array([y,y]).T, 3)
assert_almost_equal(coef2d, np.array([coef3,coef3]).T)
# test weighting
w = np.zeros_like(x)
yw = y.copy()
w[1::2] = 1
yw[0::2] = 0
wcoef3 = poly.polyfit(x, yw, 3, w=w)
assert_almost_equal(wcoef3, coef3)
#
wcoef2d = poly.polyfit(x, np.array([yw,yw]).T, 3, w=w)
assert_almost_equal(wcoef2d, np.array([coef3,coef3]).T)
def test_polytrim(self) :
coef = [2, -1, 1, 0]
# Test exceptions
assert_raises(ValueError, poly.polytrim, coef, -1)
# Test results
assert_equal(poly.polytrim(coef), coef[:-1])
assert_equal(poly.polytrim(coef, 1), coef[:-3])
assert_equal(poly.polytrim(coef, 2), [0])
def test_polyline(self) :
assert_equal(poly.polyline(3,4), [3, 4])
class TestPolynomialClass(TestCase) :
p1 = poly.Polynomial([1,2,3])
p2 = poly.Polynomial([1,2,3], [0,1])
p3 = poly.Polynomial([1,2])
p4 = poly.Polynomial([2,2,3])
p5 = poly.Polynomial([3,2,3])
def test_equal(self) :
assert_(self.p1 == self.p1)
assert_(self.p2 == self.p2)
assert_(not self.p1 == self.p2)
assert_(not self.p1 == self.p3)
assert_(not self.p1 == [1,2,3])
def test_not_equal(self) :
assert_(not self.p1 != self.p1)
assert_(not self.p2 != self.p2)
assert_(self.p1 != self.p2)
assert_(self.p1 != self.p3)
assert_(self.p1 != [1,2,3])
def test_add(self) :
tgt = poly.Polynomial([2,4,6])
assert_(self.p1 + self.p1 == tgt)
assert_(self.p1 + [1,2,3] == tgt)
assert_([1,2,3] + self.p1 == tgt)
def test_sub(self) :
tgt = poly.Polynomial([1])
assert_(self.p4 - self.p1 == tgt)
assert_(self.p4 - [1,2,3] == tgt)
assert_([2,2,3] - self.p1 == tgt)
def test_mul(self) :
tgt = poly.Polynomial([1,4,10,12,9])
assert_(self.p1 * self.p1 == tgt)
assert_(self.p1 * [1,2,3] == tgt)
assert_([1,2,3] * self.p1 == tgt)
def test_floordiv(self) :
tgt = poly.Polynomial([1])
assert_(self.p4 // self.p1 == tgt)
assert_(self.p4 // [1,2,3] == tgt)
assert_([2,2,3] // self.p1 == tgt)
def test_mod(self) :
tgt = poly.Polynomial([1])
assert_((self.p4 % self.p1) == tgt)
assert_((self.p4 % [1,2,3]) == tgt)
assert_(([2,2,3] % self.p1) == tgt)
def test_divmod(self) :
tquo = poly.Polynomial([1])
trem = poly.Polynomial([2])
quo, rem = divmod(self.p5, self.p1)
assert_(quo == tquo and rem == trem)
quo, rem = divmod(self.p5, [1,2,3])
assert_(quo == tquo and rem == trem)
quo, rem = divmod([3,2,3], self.p1)
assert_(quo == tquo and rem == trem)
def test_pow(self) :
tgt = poly.Polynomial([1])
for i in range(5) :
res = self.p1**i
assert_(res == tgt)
tgt *= self.p1
def test_call(self) :
# domain = [-1, 1]
x = np.linspace(-1, 1)
tgt = (3*x + 2)*x + 1
assert_almost_equal(self.p1(x), tgt)
# domain = [0, 1]
x = np.linspace(0, 1)
xx = 2*x - 1
assert_almost_equal(self.p2(x), self.p1(xx))
def test_degree(self) :
assert_equal(self.p1.degree(), 2)
def test_trimdeg(self) :
assert_raises(ValueError, self.p1.cutdeg, .5)
assert_raises(ValueError, self.p1.cutdeg, -1)
assert_equal(len(self.p1.cutdeg(3)), 3)
assert_equal(len(self.p1.cutdeg(2)), 3)
assert_equal(len(self.p1.cutdeg(1)), 2)
assert_equal(len(self.p1.cutdeg(0)), 1)
def test_convert(self) :
x = np.linspace(-1,1)
p = self.p1.convert(domain=[0,1])
assert_almost_equal(p(x), self.p1(x))
def test_mapparms(self) :
parms = self.p2.mapparms()
assert_almost_equal(parms, [-1, 2])
def test_trim(self) :
coef = [1, 1e-6, 1e-12, 0]
p = poly.Polynomial(coef)
assert_equal(p.trim().coef, coef[:3])
assert_equal(p.trim(1e-10).coef, coef[:2])
assert_equal(p.trim(1e-5).coef, coef[:1])
def test_truncate(self) :
assert_raises(ValueError, self.p1.truncate, .5)
assert_raises(ValueError, self.p1.truncate, 0)
assert_equal(len(self.p1.truncate(4)), 3)
assert_equal(len(self.p1.truncate(3)), 3)
assert_equal(len(self.p1.truncate(2)), 2)
assert_equal(len(self.p1.truncate(1)), 1)
def test_copy(self) :
p = self.p1.copy()
assert_(self.p1 == p)
def test_integ(self) :
p = self.p2.integ()
assert_almost_equal(p.coef, poly.polyint([1,2,3], 1, 0, scl=.5))
p = self.p2.integ(lbnd=0)
assert_almost_equal(p(0), 0)
p = self.p2.integ(1, 1)
assert_almost_equal(p.coef, poly.polyint([1,2,3], 1, 1, scl=.5))
p = self.p2.integ(2, [1, 2])
assert_almost_equal(p.coef, poly.polyint([1,2,3], 2, [1, 2], scl=.5))
def test_deriv(self) :
p = self.p2.integ(2, [1, 2])
assert_almost_equal(p.deriv(1).coef, self.p2.integ(1, [1]).coef)
assert_almost_equal(p.deriv(2).coef, self.p2.coef)
def test_roots(self) :
p = poly.Polynomial([0, -1, 0, 1], [0, 1])
res = p.roots()
tgt = [0, .5, 1]
assert_almost_equal(res, tgt)
def test_linspace(self):
xdes = np.linspace(0, 1, 20)
ydes = self.p2(xdes)
xres, yres = self.p2.linspace(20)
assert_almost_equal(xres, xdes)
assert_almost_equal(yres, ydes)
def test_fromroots(self) :
roots = [0, .5, 1]
p = poly.Polynomial.fromroots(roots, domain=[0, 1])
res = p.coef
tgt = [0, -1, 0, 1]
assert_almost_equal(res, tgt)
def test_fit(self) :
def f(x) :
return x*(x - 1)*(x - 2)
x = np.linspace(0,3)
y = f(x)
# test default value of domain
p = poly.Polynomial.fit(x, y, 3)
assert_almost_equal(p.domain, [0,3])
# test that fit works in given domains
p = poly.Polynomial.fit(x, y, 3, None)
assert_almost_equal(p(x), y)
assert_almost_equal(p.domain, [0,3])
p = poly.Polynomial.fit(x, y, 3, [])
assert_almost_equal(p(x), y)
assert_almost_equal(p.domain, [-1, 1])
# test that fit accepts weights.
w = np.zeros_like(x)
yw = y.copy()
w[1::2] = 1
yw[0::2] = 0
p = poly.Polynomial.fit(x, yw, 3, w=w)
assert_almost_equal(p(x), y)
def test_identity(self) :
x = np.linspace(0,3)
p = poly.Polynomial.identity()
assert_almost_equal(p(x), x)
p = poly.Polynomial.identity([1,3])
assert_almost_equal(p(x), x)
|
gpl-3.0
|
[
624,
2925,
367,
11849,
859,
14,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
2680,
465,
980,
199,
646,
2680,
14,
22104,
14,
22104,
465,
8446,
199,
504,
2680,
14,
4776,
492,
627,
199,
199,
318,
11639,
8,
88,
9,
520,
272,
372,
8446,
14,
6023,
12263,
8,
88,
12,
9561,
29,
17,
69,
13,
22,
9,
199,
199,
52,
16,
275,
359,
413,
61,
199,
52,
17,
275,
359,
378,
12,
221,
413,
61,
199,
52,
18,
275,
5243,
17,
12,
221,
378,
12,
257,
499,
61,
199,
52,
19,
275,
359,
378,
12,
446,
19,
12,
257,
378,
12,
259,
841,
61,
199,
52,
20,
275,
359,
413,
12,
221,
378,
12,
221,
446,
24,
12,
259,
378,
12,
257,
1695,
61,
199,
52,
21,
275,
359,
378,
12,
221,
959,
12,
257,
378,
12,
221,
446,
1165,
12,
257,
378,
12,
257,
3193,
61,
199,
52,
22,
275,
5243,
17,
12,
221,
378,
12,
221,
6155,
12,
259,
378,
12,
446,
2006,
12,
259,
378,
12,
257,
4337,
61,
199,
52,
23,
275,
359,
378,
12,
446,
23,
12,
257,
378,
12,
257,
12001,
12,
257,
378,
12,
446,
6094,
12,
259,
378,
12,
257,
5049,
61,
199,
52,
24,
275,
359,
413,
12,
221,
378,
12,
446,
708,
12,
259,
378,
12,
21235,
12,
259,
378,
12,
446,
3912,
12,
259,
378,
12,
7960,
61,
199,
52,
25,
275,
359,
378,
12,
221,
1749,
12,
257,
378,
12,
446,
6708,
12,
257,
378,
12,
221,
841,
708,
12,
259,
378,
12,
446,
12255,
12,
257,
378,
12,
7633,
61,
199,
199,
52,
513,
275,
359,
52,
16,
12,
377,
17,
12,
377,
18,
12,
377,
19,
12,
377,
20,
12,
377,
21,
12,
377,
22,
12,
377,
23,
12,
377,
24,
12,
377,
25,
61,
421,
199,
533,
1379,
22185,
8,
1746,
9,
520,
339,
347,
511,
63,
6023,
2261,
8,
277,
9,
520,
267,
702,
63,
1452,
8,
6023,
14,
6023,
2261,
12,
5243,
17,
12,
413,
566,
339,
347,
511,
63,
6023,
4262,
8,
277,
9,
520,
267,
702,
63,
1452,
8,
6023,
14,
6023,
4262,
12,
359,
16,
566,
339,
347,
511,
63,
6023,
368,
8,
277,
9,
520,
267,
702,
63,
1452,
8,
6023,
14,
6023,
368,
12,
359,
17,
566,
339,
347,
511,
63,
6023,
88,
8,
277,
9,
520,
267,
702,
63,
1452,
8,
6023,
14,
6023,
88,
12,
359,
16,
12,
413,
566,
421,
199,
533,
1379,
26291,
18764,
8,
1746,
9,
520,
339,
347,
511,
63,
6023,
525,
8,
277,
9,
520,
267,
367,
284,
315,
1425,
8,
21,
9,
520,
288,
367,
1335,
315,
1425,
8,
21,
9,
520,
355,
1499,
275,
298,
1271,
284,
2458,
68,
12,
1335,
2458,
68,
2,
450,
334,
73,
12,
74,
9,
355,
11967,
275,
980,
14,
4250,
8,
988,
8,
73,
12,
74,
9,
435,
413,
9,
355,
11967,
59,
73,
61,
847,
413,
355,
11967,
59,
74,
61,
847,
413,
355,
522,
275,
8446,
14,
6023,
525,
779,
16,
3672,
73,
435,
359,
17,
467,
359,
16,
3672,
74,
435,
359,
17,
566,
355,
702,
63,
1452,
8,
12263,
8,
470,
395,
11639,
8,
15328,
395,
2329,
63,
1328,
29,
1328,
9,
339,
347,
511,
63,
15743,
456,
8,
277,
9,
520,
267,
367,
284,
315,
1425,
8,
21,
9,
520,
288,
367,
1335,
315,
1425,
8,
21,
9,
520,
355,
1499,
275,
298,
1271,
284,
2458,
68,
12,
1335,
2458,
68,
2,
450,
334,
73,
12,
74,
9,
355,
11967,
275,
980,
14,
4250,
8,
988,
8,
73,
12,
74,
9,
435,
413,
9,
355,
11967,
59,
73,
61,
847,
413,
355,
11967,
59,
74,
61,
4862,
413,
355,
522,
275,
8446,
14,
15743,
456,
779,
16,
3672,
73,
435,
359,
17,
467,
359,
16,
3672,
74,
435,
359,
17,
566,
355,
702,
63,
1452,
8,
12263,
8,
470,
395,
11639,
8,
15328,
395,
2329,
63,
1328,
29,
1328,
9,
339,
347,
511,
63,
6023,
3703,
88,
8,
277,
304,
267,
702,
63,
1452,
8,
6023,
14,
6023,
3703,
88,
779,
16,
2522,
359,
16,
566,
267,
702,
63,
1452,
8,
6023,
14,
6023,
3703,
88,
779,
17,
2522,
359,
16,
12,
413,
566,
267,
367,
284,
315,
1425,
8,
17,
12,
959,
304,
288,
8926,
275,
359,
16,
3672,
73,
435,
359,
17,
61,
288,
11967,
275,
359,
16,
3672,
8,
73,
435,
413,
9,
435,
359,
17,
61,
288,
702,
63,
1452,
8,
6023,
14,
6023,
3703,
88,
8,
332,
395,
11967,
9,
339,
347,
511,
63,
6023,
3703,
8,
277,
9,
520,
267,
367,
284,
315,
1425,
8,
21,
9,
520,
288,
367,
1335,
315,
1425,
8,
21,
9,
520,
355,
1499,
275,
298,
1271,
284,
2458,
68,
12,
1335,
2458,
68,
2,
450,
334,
73,
12,
74,
9,
355,
11967,
275,
980,
14,
4250,
8,
73,
435,
1335,
435,
413,
9,
355,
11967,
59,
73,
435,
1335,
61,
847,
413,
355,
522,
275,
8446,
14,
6023,
3703,
779,
16,
3672,
73,
435,
359,
17,
467,
359,
16,
3672,
74,
435,
359,
17,
566,
355,
702,
63,
1452,
8,
12263,
8,
470,
395,
11639,
8,
15328,
395,
2329,
63,
1328,
29,
1328,
9,
339,
347,
511,
63,
6023,
3015,
8,
277,
9,
520,
267,
327,
1104,
4697,
4629,
267,
702,
63,
3536,
8,
31000,
12,
8446,
14,
6023,
3015,
12,
359,
17,
467,
359,
16,
566,
398,
327,
1104,
6917,
4629,
267,
28419,
12,
18798,
275,
8446,
14,
6023,
3015,
779,
18,
6922,
18,
566,
267,
702,
63,
1452,
1332,
14209,
12,
18798,
395,
334,
17,
12,
378,
430,
267,
28419,
12,
18798,
275,
8446,
14,
6023,
3015,
779,
18,
12,
18,
6922,
18,
566,
267,
702,
63,
1452,
1332,
14209,
12,
18798,
395,
3666,
17,
12,
17,
395,
378,
430,
398,
327,
1104,
4618,
14,
267,
367,
284,
315,
1425,
8,
21,
9,
520,
288,
367,
1335,
315,
1425,
8,
21,
9,
520,
355,
1499,
275,
298,
1271,
284,
2458,
68,
12,
1335,
2458,
68,
2,
450,
334,
73,
12,
74,
9,
355,
16279,
275,
359,
16,
3672,
73,
435,
359,
17,
12,
18,
61,
355,
286,
74,
275,
359,
16,
3672,
74
] |
[
2925,
367,
11849,
859,
14,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
2680,
465,
980,
199,
646,
2680,
14,
22104,
14,
22104,
465,
8446,
199,
504,
2680,
14,
4776,
492,
627,
199,
199,
318,
11639,
8,
88,
9,
520,
272,
372,
8446,
14,
6023,
12263,
8,
88,
12,
9561,
29,
17,
69,
13,
22,
9,
199,
199,
52,
16,
275,
359,
413,
61,
199,
52,
17,
275,
359,
378,
12,
221,
413,
61,
199,
52,
18,
275,
5243,
17,
12,
221,
378,
12,
257,
499,
61,
199,
52,
19,
275,
359,
378,
12,
446,
19,
12,
257,
378,
12,
259,
841,
61,
199,
52,
20,
275,
359,
413,
12,
221,
378,
12,
221,
446,
24,
12,
259,
378,
12,
257,
1695,
61,
199,
52,
21,
275,
359,
378,
12,
221,
959,
12,
257,
378,
12,
221,
446,
1165,
12,
257,
378,
12,
257,
3193,
61,
199,
52,
22,
275,
5243,
17,
12,
221,
378,
12,
221,
6155,
12,
259,
378,
12,
446,
2006,
12,
259,
378,
12,
257,
4337,
61,
199,
52,
23,
275,
359,
378,
12,
446,
23,
12,
257,
378,
12,
257,
12001,
12,
257,
378,
12,
446,
6094,
12,
259,
378,
12,
257,
5049,
61,
199,
52,
24,
275,
359,
413,
12,
221,
378,
12,
446,
708,
12,
259,
378,
12,
21235,
12,
259,
378,
12,
446,
3912,
12,
259,
378,
12,
7960,
61,
199,
52,
25,
275,
359,
378,
12,
221,
1749,
12,
257,
378,
12,
446,
6708,
12,
257,
378,
12,
221,
841,
708,
12,
259,
378,
12,
446,
12255,
12,
257,
378,
12,
7633,
61,
199,
199,
52,
513,
275,
359,
52,
16,
12,
377,
17,
12,
377,
18,
12,
377,
19,
12,
377,
20,
12,
377,
21,
12,
377,
22,
12,
377,
23,
12,
377,
24,
12,
377,
25,
61,
421,
199,
533,
1379,
22185,
8,
1746,
9,
520,
339,
347,
511,
63,
6023,
2261,
8,
277,
9,
520,
267,
702,
63,
1452,
8,
6023,
14,
6023,
2261,
12,
5243,
17,
12,
413,
566,
339,
347,
511,
63,
6023,
4262,
8,
277,
9,
520,
267,
702,
63,
1452,
8,
6023,
14,
6023,
4262,
12,
359,
16,
566,
339,
347,
511,
63,
6023,
368,
8,
277,
9,
520,
267,
702,
63,
1452,
8,
6023,
14,
6023,
368,
12,
359,
17,
566,
339,
347,
511,
63,
6023,
88,
8,
277,
9,
520,
267,
702,
63,
1452,
8,
6023,
14,
6023,
88,
12,
359,
16,
12,
413,
566,
421,
199,
533,
1379,
26291,
18764,
8,
1746,
9,
520,
339,
347,
511,
63,
6023,
525,
8,
277,
9,
520,
267,
367,
284,
315,
1425,
8,
21,
9,
520,
288,
367,
1335,
315,
1425,
8,
21,
9,
520,
355,
1499,
275,
298,
1271,
284,
2458,
68,
12,
1335,
2458,
68,
2,
450,
334,
73,
12,
74,
9,
355,
11967,
275,
980,
14,
4250,
8,
988,
8,
73,
12,
74,
9,
435,
413,
9,
355,
11967,
59,
73,
61,
847,
413,
355,
11967,
59,
74,
61,
847,
413,
355,
522,
275,
8446,
14,
6023,
525,
779,
16,
3672,
73,
435,
359,
17,
467,
359,
16,
3672,
74,
435,
359,
17,
566,
355,
702,
63,
1452,
8,
12263,
8,
470,
395,
11639,
8,
15328,
395,
2329,
63,
1328,
29,
1328,
9,
339,
347,
511,
63,
15743,
456,
8,
277,
9,
520,
267,
367,
284,
315,
1425,
8,
21,
9,
520,
288,
367,
1335,
315,
1425,
8,
21,
9,
520,
355,
1499,
275,
298,
1271,
284,
2458,
68,
12,
1335,
2458,
68,
2,
450,
334,
73,
12,
74,
9,
355,
11967,
275,
980,
14,
4250,
8,
988,
8,
73,
12,
74,
9,
435,
413,
9,
355,
11967,
59,
73,
61,
847,
413,
355,
11967,
59,
74,
61,
4862,
413,
355,
522,
275,
8446,
14,
15743,
456,
779,
16,
3672,
73,
435,
359,
17,
467,
359,
16,
3672,
74,
435,
359,
17,
566,
355,
702,
63,
1452,
8,
12263,
8,
470,
395,
11639,
8,
15328,
395,
2329,
63,
1328,
29,
1328,
9,
339,
347,
511,
63,
6023,
3703,
88,
8,
277,
304,
267,
702,
63,
1452,
8,
6023,
14,
6023,
3703,
88,
779,
16,
2522,
359,
16,
566,
267,
702,
63,
1452,
8,
6023,
14,
6023,
3703,
88,
779,
17,
2522,
359,
16,
12,
413,
566,
267,
367,
284,
315,
1425,
8,
17,
12,
959,
304,
288,
8926,
275,
359,
16,
3672,
73,
435,
359,
17,
61,
288,
11967,
275,
359,
16,
3672,
8,
73,
435,
413,
9,
435,
359,
17,
61,
288,
702,
63,
1452,
8,
6023,
14,
6023,
3703,
88,
8,
332,
395,
11967,
9,
339,
347,
511,
63,
6023,
3703,
8,
277,
9,
520,
267,
367,
284,
315,
1425,
8,
21,
9,
520,
288,
367,
1335,
315,
1425,
8,
21,
9,
520,
355,
1499,
275,
298,
1271,
284,
2458,
68,
12,
1335,
2458,
68,
2,
450,
334,
73,
12,
74,
9,
355,
11967,
275,
980,
14,
4250,
8,
73,
435,
1335,
435,
413,
9,
355,
11967,
59,
73,
435,
1335,
61,
847,
413,
355,
522,
275,
8446,
14,
6023,
3703,
779,
16,
3672,
73,
435,
359,
17,
467,
359,
16,
3672,
74,
435,
359,
17,
566,
355,
702,
63,
1452,
8,
12263,
8,
470,
395,
11639,
8,
15328,
395,
2329,
63,
1328,
29,
1328,
9,
339,
347,
511,
63,
6023,
3015,
8,
277,
9,
520,
267,
327,
1104,
4697,
4629,
267,
702,
63,
3536,
8,
31000,
12,
8446,
14,
6023,
3015,
12,
359,
17,
467,
359,
16,
566,
398,
327,
1104,
6917,
4629,
267,
28419,
12,
18798,
275,
8446,
14,
6023,
3015,
779,
18,
6922,
18,
566,
267,
702,
63,
1452,
1332,
14209,
12,
18798,
395,
334,
17,
12,
378,
430,
267,
28419,
12,
18798,
275,
8446,
14,
6023,
3015,
779,
18,
12,
18,
6922,
18,
566,
267,
702,
63,
1452,
1332,
14209,
12,
18798,
395,
3666,
17,
12,
17,
395,
378,
430,
398,
327,
1104,
4618,
14,
267,
367,
284,
315,
1425,
8,
21,
9,
520,
288,
367,
1335,
315,
1425,
8,
21,
9,
520,
355,
1499,
275,
298,
1271,
284,
2458,
68,
12,
1335,
2458,
68,
2,
450,
334,
73,
12,
74,
9,
355,
16279,
275,
359,
16,
3672,
73,
435,
359,
17,
12,
18,
61,
355,
286,
74,
275,
359,
16,
3672,
74,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tdtrask/ansible
|
lib/ansible/modules/monitoring/newrelic_deployment.py
|
27
|
4370
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2013 Matt Coddington <coddington@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: newrelic_deployment
version_added: "1.2"
author: "Matt Coddington (@mcodd)"
short_description: Notify newrelic about app deployments
description:
- Notify newrelic about app deployments (see https://docs.newrelic.com/docs/apm/new-relic-apm/maintenance/deployment-notifications#api)
options:
token:
description:
- API token, to place in the x-api-key header.
required: true
app_name:
description:
- (one of app_name or application_id are required) The value of app_name in the newrelic.yml file used by the application
required: false
application_id:
description:
- (one of app_name or application_id are required) The application id, found in the URL when viewing the application in RPM
required: false
changelog:
description:
- A list of changes for this deployment
required: false
description:
description:
- Text annotation for the deployment - notes for you
required: false
revision:
description:
- A revision number (e.g., git commit SHA)
required: false
user:
description:
- The name of the user/process that triggered this deployment
required: false
appname:
description:
- Name of the application
required: false
environment:
description:
- The environment for this deployment
required: false
validate_certs:
description:
- If C(no), SSL certificates will not be validated. This should only be used
on personally controlled sites using self-signed certificates.
required: false
default: 'yes'
choices: ['yes', 'no']
version_added: 1.5.1
requirements: []
'''
EXAMPLES = '''
- newrelic_deployment:
token: AAAAAA
app_name: myapp
user: ansible deployment
revision: '1.0'
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url
from ansible.module_utils.six.moves.urllib.parse import urlencode
# ===========================================
# Module execution.
#
def main():
module = AnsibleModule(
argument_spec=dict(
token=dict(required=True, no_log=True),
app_name=dict(required=False),
application_id=dict(required=False),
changelog=dict(required=False),
description=dict(required=False),
revision=dict(required=False),
user=dict(required=False),
appname=dict(required=False),
environment=dict(required=False),
validate_certs=dict(default='yes', type='bool'),
),
required_one_of=[['app_name', 'application_id']],
supports_check_mode=True
)
# build list of params
params = {}
if module.params["app_name"] and module.params["application_id"]:
module.fail_json(msg="only one of 'app_name' or 'application_id' can be set")
if module.params["app_name"]:
params["app_name"] = module.params["app_name"]
elif module.params["application_id"]:
params["application_id"] = module.params["application_id"]
else:
module.fail_json(msg="you must set one of 'app_name' or 'application_id'")
for item in ["changelog", "description", "revision", "user", "appname", "environment"]:
if module.params[item]:
params[item] = module.params[item]
# If we're in check mode, just exit pretending like we succeeded
if module.check_mode:
module.exit_json(changed=True)
# Send the data to NewRelic
url = "https://rpm.newrelic.com/deployments.xml"
data = urlencode(params)
headers = {
'x-api-key': module.params["token"],
}
response, info = fetch_url(module, url, data=data, headers=headers)
if info['status'] in (200, 201):
module.exit_json(changed=True)
else:
module.fail_json(msg="unable to update newrelic: %s" % info['msg'])
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,
1898,
6171,
31653,
445,
364,
1098,
1860,
665,
331,
617,
31673,
32,
6799,
14,
957,
30,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
892,
264,
606,
63,
13605,
199,
1023,
63,
3270,
26,
298,
17,
14,
18,
2,
199,
2502,
26,
298,
45,
6796,
445,
364,
1098,
1860,
8593,
77,
331,
617,
2924,
199,
3612,
63,
1802,
26,
31949,
892,
264,
606,
3595,
1145,
12287,
1470,
199,
1802,
26,
2043,
446,
31949,
892,
264,
606,
3595,
1145,
12287,
1470,
334,
3239,
4178,
921,
4757,
14,
1222,
264,
606,
14,
957,
15,
4757,
15,
439,
77,
15,
1222,
13,
264,
606,
13,
439,
77,
15,
19725,
15,
13605,
13,
12782,
3,
1246,
9,
199,
1419,
26,
523,
1526,
26,
272,
1369,
26,
489,
446,
3261,
1526,
12,
370,
4192,
315,
314,
671,
13,
1246,
13,
498,
1406,
14,
272,
1415,
26,
2549,
523,
1145,
63,
354,
26,
272,
1369,
26,
489,
446,
334,
368,
402,
1145,
63,
354,
503,
4223,
63,
344,
787,
1415,
9,
710,
574,
402,
1145,
63,
354,
315,
314,
892,
264,
606,
14,
11714,
570,
1202,
701,
314,
4223,
272,
1415,
26,
3055,
523,
4223,
63,
344,
26,
272,
1369,
26,
489,
446,
334,
368,
402,
1145,
63,
354,
503,
4223,
63,
344,
787,
1415,
9,
710,
4223,
1305,
12,
1911,
315,
314,
2851,
1380,
2455,
316,
314,
4223,
315,
820,
10793,
272,
1415,
26,
3055,
523,
1570,
793,
26,
272,
1369,
26,
489,
446,
437,
769,
402,
4493,
367,
642,
14295,
272,
1415,
26,
3055,
523,
1369,
26,
272,
1369,
26,
489,
446,
4516,
11262,
367,
314,
14295,
446,
12681,
367,
1265,
272,
1415,
26,
3055,
523,
6974,
26,
272,
1369,
26,
489,
446,
437,
6974,
1329,
334,
69,
14,
71,
2020,
6135,
5532,
12002,
9,
272,
1415,
26,
3055,
523,
922,
26,
272,
1369,
26,
489,
446,
710,
536,
402,
314,
922,
15,
1412,
626,
15572,
642,
14295,
272,
1415,
26,
3055,
523,
20268,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
4223,
272,
1415,
26,
3055,
523,
3734,
26,
272,
1369,
26,
489,
446,
710,
3734,
367,
642,
14295,
272,
1415,
26,
3055,
523,
4107,
63,
8356,
26,
272,
1369,
26,
489,
446,
982,
445,
8,
889,
395,
7799,
14512,
911,
440,
506,
16468,
14,
961,
1077,
1454,
506,
1202,
267,
641,
4954,
1183,
22284,
15424,
1808,
291,
13,
1737,
14512,
14,
272,
1415,
26,
3055,
272,
849,
26,
283,
5066,
7,
272,
3415,
26,
788,
5066,
297,
283,
889,
418,
272,
1015,
63,
3270,
26,
413,
14,
21,
14,
17,
199,
199,
7538,
26,
942,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
892,
264,
606,
63,
13605,
26,
272,
1526,
26,
437,
6151,
33,
272,
1145,
63,
354,
26,
3002,
571,
272,
922,
26,
3242,
14295,
272,
6974,
26,
283,
17,
14,
16,
7,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
3603,
492,
5267,
63,
633,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
16511,
199,
199,
3,
19469,
17575,
199,
3,
5673,
6451,
14,
199,
3,
421,
199,
318,
2446,
837,
339,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
807,
8,
288,
1526,
29,
807,
8,
2427,
29,
549,
12,
949,
63,
793,
29,
549,
395,
288,
1145,
63,
354,
29,
807,
8,
2427,
29,
797,
395,
288,
4223,
63,
344,
29,
807,
8,
2427,
29,
797,
395,
288,
1570,
793,
29,
807,
8,
2427,
29,
797,
395,
288,
1369,
29,
807,
8,
2427,
29,
797,
395,
288,
6974,
29,
807,
8,
2427,
29,
797,
395,
288,
922,
29,
807,
8,
2427,
29,
797,
395,
288,
20268,
29,
807,
8,
2427,
29,
797,
395,
288,
3734,
29,
807,
8,
2427,
29,
797,
395,
288,
4107,
63,
8356,
29,
807,
8,
885,
534,
5066,
297,
730,
534,
2245,
659,
267,
2318,
267,
1415,
63,
368,
63,
1618,
1524,
459,
571,
63,
354,
297,
283,
3578,
63,
344,
2157,
267,
5171,
63,
1074,
63,
632,
29,
549,
272,
776,
339,
327,
1900,
769,
402,
1862,
272,
1862,
275,
1052,
272,
340,
859,
14,
1162,
905,
571,
63,
354,
937,
436,
859,
14,
1162,
905,
3578,
63,
344,
6229,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
2118,
1373,
402,
283,
571,
63,
354,
7,
503,
283,
3578,
63,
344,
7,
883,
506,
663,
531,
339,
340,
859,
14,
1162,
905,
571,
63,
354,
6229,
267,
1862,
905,
571,
63,
354,
937,
275,
859,
14,
1162,
905,
571,
63,
354,
937,
272,
916,
859,
14,
1162,
905,
3578,
63,
344,
6229,
267,
1862,
905,
3578,
63,
344,
937,
275,
859,
14,
1162,
905,
3578,
63,
344,
937,
272,
587,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
13297,
1471,
663,
1373,
402,
283,
571,
63,
354,
7,
503,
283,
3578,
63,
344,
9859,
339,
367,
1242,
315,
2097,
23436,
401,
298,
1802,
401,
298,
5792,
401,
298,
751,
401,
298,
21653,
401,
298,
5418,
6229,
267,
340,
859,
14,
1162,
59,
1053,
2189,
288,
1862,
59,
1053,
61,
275,
859,
14,
1162,
59,
1053,
61,
339,
327,
982,
781,
3984,
315,
1104,
818,
12,
2951,
4458,
876,
724,
1098,
2839,
781,
19268,
272,
340,
859,
14,
1074,
63,
632,
26,
267,
859,
14,
2224,
63,
1001,
8,
2489,
29,
549,
9,
339,
327,
10217,
314,
666,
370,
7053,
497,
606,
272,
1166,
275,
298,
2859,
921,
14191,
14,
1222,
264,
606,
14,
957,
15,
11060,
1470,
14,
1652,
2,
272
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
6171,
31653,
445,
364,
1098,
1860,
665,
331,
617,
31673,
32,
6799,
14,
957,
30,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
892,
264,
606,
63,
13605,
199,
1023,
63,
3270,
26,
298,
17,
14,
18,
2,
199,
2502,
26,
298,
45,
6796,
445,
364,
1098,
1860,
8593,
77,
331,
617,
2924,
199,
3612,
63,
1802,
26,
31949,
892,
264,
606,
3595,
1145,
12287,
1470,
199,
1802,
26,
2043,
446,
31949,
892,
264,
606,
3595,
1145,
12287,
1470,
334,
3239,
4178,
921,
4757,
14,
1222,
264,
606,
14,
957,
15,
4757,
15,
439,
77,
15,
1222,
13,
264,
606,
13,
439,
77,
15,
19725,
15,
13605,
13,
12782,
3,
1246,
9,
199,
1419,
26,
523,
1526,
26,
272,
1369,
26,
489,
446,
3261,
1526,
12,
370,
4192,
315,
314,
671,
13,
1246,
13,
498,
1406,
14,
272,
1415,
26,
2549,
523,
1145,
63,
354,
26,
272,
1369,
26,
489,
446,
334,
368,
402,
1145,
63,
354,
503,
4223,
63,
344,
787,
1415,
9,
710,
574,
402,
1145,
63,
354,
315,
314,
892,
264,
606,
14,
11714,
570,
1202,
701,
314,
4223,
272,
1415,
26,
3055,
523,
4223,
63,
344,
26,
272,
1369,
26,
489,
446,
334,
368,
402,
1145,
63,
354,
503,
4223,
63,
344,
787,
1415,
9,
710,
4223,
1305,
12,
1911,
315,
314,
2851,
1380,
2455,
316,
314,
4223,
315,
820,
10793,
272,
1415,
26,
3055,
523,
1570,
793,
26,
272,
1369,
26,
489,
446,
437,
769,
402,
4493,
367,
642,
14295,
272,
1415,
26,
3055,
523,
1369,
26,
272,
1369,
26,
489,
446,
4516,
11262,
367,
314,
14295,
446,
12681,
367,
1265,
272,
1415,
26,
3055,
523,
6974,
26,
272,
1369,
26,
489,
446,
437,
6974,
1329,
334,
69,
14,
71,
2020,
6135,
5532,
12002,
9,
272,
1415,
26,
3055,
523,
922,
26,
272,
1369,
26,
489,
446,
710,
536,
402,
314,
922,
15,
1412,
626,
15572,
642,
14295,
272,
1415,
26,
3055,
523,
20268,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
4223,
272,
1415,
26,
3055,
523,
3734,
26,
272,
1369,
26,
489,
446,
710,
3734,
367,
642,
14295,
272,
1415,
26,
3055,
523,
4107,
63,
8356,
26,
272,
1369,
26,
489,
446,
982,
445,
8,
889,
395,
7799,
14512,
911,
440,
506,
16468,
14,
961,
1077,
1454,
506,
1202,
267,
641,
4954,
1183,
22284,
15424,
1808,
291,
13,
1737,
14512,
14,
272,
1415,
26,
3055,
272,
849,
26,
283,
5066,
7,
272,
3415,
26,
788,
5066,
297,
283,
889,
418,
272,
1015,
63,
3270,
26,
413,
14,
21,
14,
17,
199,
199,
7538,
26,
942,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
892,
264,
606,
63,
13605,
26,
272,
1526,
26,
437,
6151,
33,
272,
1145,
63,
354,
26,
3002,
571,
272,
922,
26,
3242,
14295,
272,
6974,
26,
283,
17,
14,
16,
7,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
3603,
492,
5267,
63,
633,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
16511,
199,
199,
3,
19469,
17575,
199,
3,
5673,
6451,
14,
199,
3,
421,
199,
318,
2446,
837,
339,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
807,
8,
288,
1526,
29,
807,
8,
2427,
29,
549,
12,
949,
63,
793,
29,
549,
395,
288,
1145,
63,
354,
29,
807,
8,
2427,
29,
797,
395,
288,
4223,
63,
344,
29,
807,
8,
2427,
29,
797,
395,
288,
1570,
793,
29,
807,
8,
2427,
29,
797,
395,
288,
1369,
29,
807,
8,
2427,
29,
797,
395,
288,
6974,
29,
807,
8,
2427,
29,
797,
395,
288,
922,
29,
807,
8,
2427,
29,
797,
395,
288,
20268,
29,
807,
8,
2427,
29,
797,
395,
288,
3734,
29,
807,
8,
2427,
29,
797,
395,
288,
4107,
63,
8356,
29,
807,
8,
885,
534,
5066,
297,
730,
534,
2245,
659,
267,
2318,
267,
1415,
63,
368,
63,
1618,
1524,
459,
571,
63,
354,
297,
283,
3578,
63,
344,
2157,
267,
5171,
63,
1074,
63,
632,
29,
549,
272,
776,
339,
327,
1900,
769,
402,
1862,
272,
1862,
275,
1052,
272,
340,
859,
14,
1162,
905,
571,
63,
354,
937,
436,
859,
14,
1162,
905,
3578,
63,
344,
6229,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
2118,
1373,
402,
283,
571,
63,
354,
7,
503,
283,
3578,
63,
344,
7,
883,
506,
663,
531,
339,
340,
859,
14,
1162,
905,
571,
63,
354,
6229,
267,
1862,
905,
571,
63,
354,
937,
275,
859,
14,
1162,
905,
571,
63,
354,
937,
272,
916,
859,
14,
1162,
905,
3578,
63,
344,
6229,
267,
1862,
905,
3578,
63,
344,
937,
275,
859,
14,
1162,
905,
3578,
63,
344,
937,
272,
587,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
13297,
1471,
663,
1373,
402,
283,
571,
63,
354,
7,
503,
283,
3578,
63,
344,
9859,
339,
367,
1242,
315,
2097,
23436,
401,
298,
1802,
401,
298,
5792,
401,
298,
751,
401,
298,
21653,
401,
298,
5418,
6229,
267,
340,
859,
14,
1162,
59,
1053,
2189,
288,
1862,
59,
1053,
61,
275,
859,
14,
1162,
59,
1053,
61,
339,
327,
982,
781,
3984,
315,
1104,
818,
12,
2951,
4458,
876,
724,
1098,
2839,
781,
19268,
272,
340,
859,
14,
1074,
63,
632,
26,
267,
859,
14,
2224,
63,
1001,
8,
2489,
29,
549,
9,
339,
327,
10217,
314,
666,
370,
7053,
497,
606,
272,
1166,
275,
298,
2859,
921,
14191,
14,
1222,
264,
606,
14,
957,
15,
11060,
1470,
14,
1652,
2,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
greenoaktree/pfp
|
pfp/fields.py
|
1
|
46379
|
#!/usr/bin/env python
# encoding: utf-8
from intervaltree import IntervalTree,Interval
import json
import math
import re
import six
import struct
import pfp.errors as errors
import pfp.utils as utils
import pfp.bitwrap as bitwrap
import pfp.functions as functions
BIG_ENDIAN = ">"
LITTLE_ENDIAN = "<"
def true():
res = Int()
res._pfp__value = 1
return res
def false():
res = Int()
res._pfp__value = 0
return res
def get_value(field):
if isinstance(field, Field):
return field._pfp__value
else:
return field
def get_str(field):
if isinstance(field, Array):
res = field._array_to_str()
elif isinstance(field, Char):
res = chr(PYVAL(field))
else:
res = get_value(field)
return utils.string(res)
PYVAL = get_value
PYSTR = get_str
class BitfieldRW(object):
"""Handles reading and writing the total bits for the bitfield
data type from the input stream, and correctly applying
endian and bit direction settings.
"""
def __init__(self, interp, cls):
"""Set the interpreter and stream for BitFieldReader
:param pfp.interp.PfpInterp interp: The interpreter being used
:param pfp.bitwrap.BitwrappedStream stream: The bitwrapped stream
:param pfp.fields.Field cls: The class (a subclass of :any:`pfp.fields.Field`) - used to determine total size of bitfield (if padded).
"""
self.interp = interp
self.cls = cls
self.max_bits = self.cls.width * 8
self.reserved_bits = 0
# only used with padding is enabled
self._cls_bits = None
# used to write to the stream
self._write_bits = []
def reserve_bits(self, num_bits):
"""Used to "reserve" ``num_bits`` amount of bits in order to keep track
of consecutive bitfields (or are the called bitfield groups?).
E.g. ::
struct {
char a:8, b:8;
char c:4, d:4, e:8;
}
:param int num_bits: The number of bits to claim
:returns: If room existed for the reservation
"""
num_bits = PYVAL(num_bits)
if num_bits + self.reserved_bits > self.max_bits:
return False
self.reserved_bits += num_bits
return True
def read_bits(self, stream, num_bits):
"""Return ``num_bits`` bits, taking into account endianness and
left-right bit directions
"""
padded = self.interp.get_bitfield_padded()
left_right = self.interp.get_bitfield_left_right()
# TODO this needs to be something more like this
# endian = self.interp.get_endian()
endian = NumberBase.endian
if self._cls_bits is None and padded:
raw_bits = stream.read_bits(self.cls.width*8)
self._cls_bits = self._endian_transform(raw_bits, endian)
if self._cls_bits is not None:
if num_bits > len(self._cls_bits):
raise errors.PfpError("BitfieldRW reached invalid state")
if left_right:
res = self._cls_bits[:num_bits]
self._cls_bits = self._cls_bits[num_bits:]
else:
res = self._cls_bits[-num_bits:]
self._cls_bits = self._cls_bits[:-num_bits]
return res
else:
return stream.read_bits(num_bits)
def write_bits(self, stream, raw_bits):
"""Write the bits. Once the size of the written bits is equal
to the number of the reserved bits, flush it to the stream
"""
padded = self.interp.get_bitfield_padded()
left_right = self.interp.get_bitfield_left_right()
# TODO this needs to be something more like this
# endian = self.interp.get_endian()
endian = NumberBase.endian
if padded:
if left_right:
self._write_bits += raw_bits
else:
self._write_bits = raw_bits + self._write_bits
if len(self._write_bits) == self.reserved_bits:
bits = self._endian_transform(self._write_bits, endian)
stream.write_bits(bits)
else:
stream.write_bits(raw_bits)
def _endian_transform(self, bits, endian):
res = []
# perform endianness transformation
for x in six.moves.range(self.cls.width):
if endian == BIG_ENDIAN:
curr_byte_idx = x
else:
curr_byte_idx = (self.cls.width - x - 1)
res += bits[curr_byte_idx*8:(curr_byte_idx+1)*8]
return res
class Field(object):
"""Core class for all fields used in the Pfp DOM.
All methods use the _pfp__XXX naming convention to
avoid conflicting names used in templates, since
struct fields will implement ``__getattr__`` and
``__setattr__`` to directly access child fields"""
_pfp__interp = None
_pfp__name = None
"""The name of the Field"""
_pfp__parent = None
"""The parent of the field"""
_pfp__watchers = []
"""All fields that are watching this field"""
_pfp__watch_fields = []
"""All fields that this field is watching"""
def __init__(self, stream=None, metadata_processor=None):
super(Field, self).__init__()
self._pfp__name = None
self._pfp__frozen = False
self._pfp__offset = -1
# watchers to update when something changes
self._pfp__watchers = []
self._pfp__parent = None
self._pfp__watch_fields = []
self._pfp__no_notify = False
self._pfp__packer = None
self._pfp__unpack = None
self._pfp__pack = None
self._pfp__pack_type = None
self._pfp__no_unpack = False
self._pfp__parsed_packed = None
self._pfp__metadata_processor = metadata_processor
self._ = None
self._pfp__array_idx = None
if stream is not None:
self._pfp__parse(stream, save_offset=True)
def _pfp__process_metadata(self):
"""Process the metadata once the entire struct has been
declared.
"""
if self._pfp__metadata_processor is None:
return
metadata_info = self._pfp__metadata_processor()
if isinstance(metadata_info, list):
for metadata in metadata_info:
if metadata["type"] == "watch":
self._pfp__set_watch(
metadata["watch_fields"],
metadata["update_func"],
*metadata["func_call_info"]
)
elif metadata["type"] == "packed":
del metadata["type"]
self._pfp__set_packer(**metadata)
if self._pfp__can_unpack():
self._pfp__unpack_data(self.raw_data)
def _pfp__watch(self, watcher):
"""Add the watcher to the list of fields that
are watching this field
"""
if self._pfp__parent is not None and isinstance(self._pfp__parent, Union):
self._pfp__parent._pfp__watch(watcher)
else:
self._pfp__watchers.append(watcher)
def _pfp__set_watch(self, watch_fields, update_func, *func_call_info):
"""Subscribe to update events on each field in ``watch_fields``, using
``update_func`` to update self's value when ``watch_field``
changes"""
self._pfp__watch_fields = watch_fields
for watch_field in watch_fields:
watch_field._pfp__watch(self)
self._pfp__update_func = update_func
self._pfp__update_func_call_info = func_call_info
def _pfp__set_packer(self, pack_type, packer=None, pack=None, unpack=None, func_call_info=None):
"""Set the packer/pack/unpack functions for this field, as
well as the pack type.
:pack_type: The data type of the packed data
:packer: A function that can handle packing and unpacking. First
arg is true/false (to pack or unpack). Second arg is the stream.
Must return an array of chars.
:pack: A function that packs data. It must accept an array of chars and return an
array of chars that is a packed form of the input.
:unpack: A function that unpacks data. It must accept an array of chars and
return an array of chars
"""
self._pfp__pack_type = pack_type
self._pfp__unpack = unpack
self._pfp__pack = pack
self._pfp__packer = packer
self._pfp__pack_func_call_info = func_call_info
def _pfp__pack_data(self):
"""Pack the nested field
"""
if self._pfp__pack_type is None:
return
tmp_stream = six.BytesIO()
self._._pfp__build(bitwrap.BitwrappedStream(tmp_stream))
raw_data = tmp_stream.getvalue()
unpack_func = self._pfp__packer
unpack_args = []
if self._pfp__packer is not None:
unpack_func = self._pfp__packer
unpack_args = [true(), raw_data]
elif self._pfp__pack is not None:
unpack_func = self._pfp__pack
unpack_args = [raw_data]
# does not need to be converted to a char array
if not isinstance(unpack_func, functions.NativeFunction):
io_stream = bitwrap.BitwrappedStream(six.BytesIO(raw_data))
unpack_args[-1] = Array(len(raw_data), Char, io_stream)
res = unpack_func.call(unpack_args, *self._pfp__pack_func_call_info, no_cast=True)
if isinstance(res, Array):
res = res._pfp__build()
io_stream = six.BytesIO(res)
tmp_stream = bitwrap.BitwrappedStream(io_stream)
self._pfp__no_unpack = True
self._pfp__parse(tmp_stream)
self._pfp__no_unpack = False
def _pfp__can_unpack(self):
"""Return if this field has a packer/pack/unpack methods
set as well as a pack type
"""
return self._pfp__pack_type is not None
def _pfp__unpack_data(self, raw_data):
"""Means that the field has already been parsed normally,
and that it now needs to be unpacked.
:raw_data: A string of the data that the field consumed while parsing
"""
if self._pfp__pack_type is None:
return
if self._pfp__no_unpack:
return
unpack_func = self._pfp__packer
unpack_args = []
if self._pfp__packer is not None:
unpack_func = self._pfp__packer
unpack_args = [false(), raw_data]
elif self._pfp__unpack is not None:
unpack_func = self._pfp__unpack
unpack_args = [raw_data]
# does not need to be converted to a char array
if not isinstance(unpack_func, functions.NativeFunction):
io_stream = bitwrap.BitwrappedStream(six.BytesIO(raw_data))
unpack_args[-1] = Array(len(raw_data), Char, io_stream)
res = unpack_func.call(unpack_args, *self._pfp__pack_func_call_info, no_cast=True)
if isinstance(res, Array):
res = res._pfp__build()
io_stream = six.BytesIO(res)
tmp_stream = bitwrap.BitwrappedStream(io_stream)
tmp_stream.padded = self._pfp__interp.get_bitfield_padded()
self._ = self._pfp__parsed_packed = self._pfp__pack_type(tmp_stream)
self._._pfp__watch(self)
def _pfp__offset(self):
"""Get the offset of the field into the stream
"""
if self._pfp__parent is not None:
self._pfp__parent
def _pfp__handle_updated(self, watched_field):
"""Handle the watched field that was updated
"""
self._pfp__no_notify = True
# nested data has been changed, so rebuild the
# nested data to update the field
# TODO a global setting to determine this behavior?
# could slow things down a bit for large nested structures
# notice the use of _is_ here - 'is' != '=='. '==' uses
# the __eq__ operator, while is compares id(object) results
if watched_field is self._:
self._pfp__pack_data()
elif self._pfp__update_func is not None:
self._pfp__update_func.call(
[self] + self._pfp__watch_fields,
*self._pfp__update_func_call_info
)
self._pfp__no_notify = False
def _pfp__notify_update(self, child=None):
for watcher in self._pfp__watchers:
watcher._pfp__handle_updated(self)
if self._pfp__parent is not None:
self._pfp__parent._pfp__notify_update(self)
def _pfp__width(self):
"""Return the width of the field (sizeof)
"""
raw_output = six.BytesIO()
output = bitwrap.BitwrappedStream(raw_output)
self._pfp__build(output)
output.flush()
return len(raw_output.getvalue())
def _pfp__freeze(self):
"""Freeze the field so that it cannot be modified (const)
"""
self._pfp__frozen = True
def _pfp__get_root_value(self, val):
"""helper function to fetch the root value of an object"""
if isinstance(val, Field):
return val._pfp__value
else:
return val
def _pfp__set_value(self, new_val):
"""Set the new value if type checking is passes, potentially
(TODO? reevaluate this) casting the value to something else
:new_val: The new value
:returns: TODO
"""
if self._pfp__frozen:
raise errors.UnmodifiableConst()
self._pfp__value = self._pfp__get_root_value(new_val)
self._pfp__notify_parent()
def _pfp__notify_parent(self):
if self._pfp__no_notify:
return
for watcher in self._pfp__watchers:
watcher._pfp__handle_updated(self)
if self._pfp__parent is not None:
self._pfp__parent._pfp__notify_update(self)
def _pfp__build(self, output_stream=None, save_offset=False):
"""Pack this field into a string. If output_stream is specified,
write the output into the output stream
:output_stream: Optional output stream to write the results to
:save_offset: If true, the current offset into the stream will be saved in the field
:returns: Resulting string if ``output_stream`` is not specified. Else the number of bytes writtern.
"""
raise NotImplemented("Inheriting classes must implement the _pfp__build function")
def _pfp__parse(self, stream, save_offset=False):
"""Parse this field from the ``stream``
:stream: An IO stream that can be read from
:save_offset: Save the offset into the stream
:returns: None
"""
raise NotImplemented("Inheriting classes must implement the _pfp__parse function")
def _pfp__maybe_unpack(self):
"""Should be called after initial parsing to unpack any
nested data types
"""
if self._pfp__pack_type is None or (self._pfp__pack is not None and self._pfp__packer is not None):
return
pass
def _pfp__pack(self):
"""Should be called after initial parsing
"""
pass
def __cmp__(self, other):
"""Compare the Field to something else, either another
Field or something else
:other: Another Field instance or something else
:returns: result of cmp()
"""
val = get_value(other)
return cmp(self._pfp__value, val)
def __lt__(self, other):
"""Compare the Field to something else, either another
Field or something else
:other: The other field
:returns: True if equal
"""
val = get_value(other)
return self._pfp__value < val
def __le__(self, other):
val = get_value(other)
return self._pfp__value <= val
def __gt__(self, other):
"""Compare the Field to something else, either another
Field or something else
:other: The other field
:returns: True if equal
"""
val = get_value(other)
return self._pfp__value > val
def __ge__(self, other):
val = get_value(other)
return self._pfp__value >= val
def __ne__(self, other):
val = get_value(other)
return self._pfp__value != val
def __eq__(self, other):
"""See if the two items are equal (True/False)
:other:
:returns:
"""
val = get_value(other)
return self._pfp__value == val
def __repr__(self):
return "{}({!r})".format(self.__class__.__name__, self._pfp__value)
def _pfp__show(self, level=0, include_offset=False):
"""Return a representation of this field
:param int level: The indent level of the output
:param bool include_offset: Include the parsed offsets of this field
"""
return repr(self)
class Void(Field):
"""The void field - used for return value of a function"""
pass
class Struct(Field):
"""The struct field"""
_pfp__show_name = "struct"
_pfp__children = []
"""All children of the struct, in order added"""
_pfp__name_collisions = {}
"""Counters for any naming collisions"""
def __init__(self, stream=None, metadata_processor=None):
# ordered list of children
super(Struct, self).__setattr__("_pfp__children", [])
# for quick child access
super(Struct, self).__setattr__("_pfp__children_map", {})
# reinit it here just for this instance...
self._pfp__name_collisions = {}
super(Struct, self).__init__(metadata_processor=metadata_processor)
if stream is not None:
self._pfp__offset = stream.tell()
def _pfp__process_fields_metadata(self):
"""Tell each child to process its metadata
"""
for child in self._pfp__children:
child._pfp__process_metadata()
def _pfp__set_value(self, value):
"""Initialize the struct. Value should be an array of
fields, one each for each struct member.
:value: An array of fields to initialize the struct with
:returns: None
"""
if self._pfp__frozen:
raise errors.UnmodifiableConst()
if len(value) != len(self._pfp__children):
raise errors.PfpError("struct initialization has wrong number of members")
for x in six.moves.range(len(self._pfp__children)):
self._pfp__children[x]._pfp__set_value(value[x])
def _pfp__add_child(self, name, child, stream=None, overwrite=False):
"""Add a child to the Struct field. If multiple consecutive fields are
added with the same name, an implicit array will be created to store
all fields of that name.
:param str name: The name of the child
:param pfp.fields.Field child: The field to add
:param bool overwrite: Overwrite existing fields (False)
:param pfp.bitwrap.BitwrappedStream stream: unused, but her for compatability with Union._pfp__add_child
:returns: The resulting field added
"""
if not overwrite and self._pfp__is_non_consecutive_duplicate(name, child):
return self._pfp__handle_non_consecutive_duplicate(name, child)
elif not overwrite and name in self._pfp__children_map:
return self._pfp__handle_implicit_array(name, child)
else:
child._pfp__parent = self
self._pfp__children.append(child)
child._pfp__name = name
self._pfp__children_map[name] = child
return child
def _pfp__handle_non_consecutive_duplicate(self, name, child, insert=True):
"""This new child, and potentially one already existing child, need to
have a numeric suffix appended to their name.
An entry will be made for this name in ``self._pfp__name_collisions`` to keep
track of the next available suffix number"""
if name in self._pfp__children_map:
previous_child = self._pfp__children_map[name]
# DO NOT cause __eq__ to be called, we want to test actual objects, not comparison
# operators
if previous_child is not child:
self._pfp__handle_non_consecutive_duplicate(name, previous_child, insert=False)
del self._pfp__children_map[name]
next_suffix = self._pfp__name_collisions.setdefault(name, 0)
new_name = "{}_{}".format(name, next_suffix)
child._pfp__name = new_name
self._pfp__name_collisions[name] = next_suffix + 1
self._pfp__children_map[new_name] = child
self._pfp__parent = self
if insert:
self._pfp__children.append(child)
return child
def _pfp__is_non_consecutive_duplicate(self, name, child):
"""Return True/False if the child is a non-consecutive duplicately named
field. Consecutive duplicately-named fields are stored in an implicit array,
non-consecutive duplicately named fields have a numeric suffix appended to their name"""
if len(self._pfp__children) == 0:
return False
# it should be an implicit array
if self._pfp__children[-1]._pfp__name == name:
return False
# if it's elsewhere in the children name map OR a collision sequence has already been
# started for this name, it should have a numeric suffix
# appended
elif name in self._pfp__children_map or name in self._pfp__name_collisions:
return True
# else, no collision
return False
def _pfp__handle_implicit_array(self, name, child):
"""Handle inserting implicit array elements
"""
existing_child = self._pfp__children_map[name]
if isinstance(existing_child, Array):
# I don't think we should check this
#
#if existing_child.field_cls != child.__class__:
# raise errors.PfpError("implicit arrays must be sequential!")
existing_child.append(child)
return existing_child
else:
cls = child._pfp__class if hasattr(child, "_pfp__class") else child.__class__
ary = Array(0, cls)
# since the array starts with the first item
ary._pfp__offset = existing_child._pfp__offset
ary._pfp__parent = self
ary._pfp__name = name
ary.implicit = True
ary.append(existing_child)
ary.append(child)
exist_idx = -1
for idx,child in enumerate(self._pfp__children):
if child is existing_child:
exist_idx = idx
break
self._pfp__children[exist_idx] = ary
self._pfp__children_map[name] = ary
return ary
def _pfp__parse(self, stream, save_offset=False):
"""Parse the incoming stream
:stream: Input stream to be parsed
:returns: Number of bytes parsed
"""
if save_offset:
self._pfp__offset = stream.tell()
res = 0
for child in self._pfp__children:
res += child._pfp__parse(stream, save_offset)
return res
def _pfp__build(self, stream=None, save_offset=False):
"""Build the field and write the result into the stream
:stream: An IO stream that can be written to
:returns: None
"""
if save_offset and stream is not None:
self._pfp__offset = stream.tell()
# returns either num bytes written or total data
res = utils.binary("") if stream is None else 0
# iterate IN ORDER
for child in self._pfp__children:
child_res = child._pfp__build(stream, save_offset)
res += child_res
return res
def __getattr__(self, name):
"""Custom __getattr__ for quick access to the children"""
children_map = super(Struct, self).__getattribute__("_pfp__children_map")
if name in children_map:
return children_map[name]
else:
# default getattr instead
return super(Struct, self).__getattribute__(name)
def __setattr__(self, name, value):
"""Custom __setattr__ for quick setting of children values
If value is not an instance of ``Field``, assume it is the
value for the field and that the field itself should not
be overridden"""
children_map = super(Struct, self).__getattribute__("_pfp__children_map")
if name in children_map:
if not isinstance(value, Field):
children_map[name]._pfp__set_value(value)
else:
children_map[name] = value
self._pfp__notify_parent()
return children_map[name]
else:
# default getattr instead
return super(Struct, self).__setattr__(name, value)
def __repr__(self):
return object.__repr__(self)
def _pfp__show(self, level=0, include_offset=False):
"""Show the contents of the struct
"""
res = []
res.append("{}{} {{".format(
"{:04x} ".format(self._pfp__offset) if include_offset else "",
self._pfp__show_name
))
for child in self._pfp__children:
res.append("{}{}{:10s} = {}".format(
" "*(level+1),
"{:04x} ".format(child._pfp__offset) if include_offset else "",
child._pfp__name,
child._pfp__show(level+1, include_offset)
))
res.append("{}}}".format(" "*level))
return "\n".join(res)
class Union(Struct):
"""A union field, where each member is an alternate
view of the data"""
_pfp__buff = None
_pfp__size = 0
_pfp__show_name = "union"
def __init__(self, stream=None, metadata_processor=None):
"""Init the union and its buff stream
"""
super(Union, self).__init__(metadata_processor=metadata_processor)
if stream is not None:
self._pfp__offset = stream.tell()
self._pfp__buff = six.BytesIO()
def _pfp__add_child(self, name, child, stream=None):
"""Add a child to the Union field
:name: The name of the child
:child: A :class:`.Field` instance
:returns: The resulting field
"""
res = super(Union, self)._pfp__add_child(name, child)
self._pfp__buff.seek(0, 0)
child._pfp__build(stream=self._pfp__buff)
size = len(self._pfp__buff.getvalue())
self._pfp__buff.seek(0, 0)
if stream is not None:
curr_pos = stream.tell()
stream.seek(curr_pos-size, 0)
return res
def _pfp__notify_update(self, child=None):
"""Handle a child with an updated value
"""
if getattr(self, "_pfp__union_update_other_children", True):
self._pfp__union_update_other_children = False
new_data = child._pfp__build()
new_stream = bitwrap.BitwrappedStream(six.BytesIO(new_data))
for other_child in self._pfp__children:
if other_child is child:
continue
if isinstance(other_child, Array) and other_child._is_stringable():
other_child._pfp__set_value(new_data)
else:
other_child._pfp__parse(new_stream)
new_stream.seek(0)
self._pfp__no_update_other_children = True
super(Union, self)._pfp__notify_update(child=child)
def _pfp__parse(self, stream, save_offset=False):
"""Parse the incoming stream
:stream: Input stream to be parsed
:returns: Number of bytes parsed
"""
if save_offset:
self._pfp__offset = stream.tell()
max_res = 0
for child in self._pfp__children:
child_res = child._pfp__parse(stream, save_offset)
if child_res > max_res:
max_res = child_res
# rewind the stream
stream.seek(child_res, -1)
self._pfp__size = max_res
self._pfp__buff = six.BytesIO(stream.read(self._pfp__size))
return max_res
def _pfp__build(self, stream=None, save_offset=False):
"""Build the union and write the result into the stream.
:stream: None
:returns: None
"""
max_size = -1
if stream is None:
core_stream = six.BytesIO()
new_stream = bitwrap.BitwrappedStream(core_stream)
else:
new_stream = stream
for child in self._pfp__children:
curr_pos = new_stream.tell()
child._pfp__build(new_stream, save_offset)
size = new_stream.tell() - curr_pos
new_stream.seek(-size, 1)
if size > max_size:
max_size = size
new_stream.seek(max_size, 1)
if stream is None:
return core_stream.getvalue()
else:
return max_size
def __setattr__(self, name, value):
"""Custom __setattr__ to keep track of the order things
are writen (to mimic writing to memory)
"""
res = super(Union, self).__setattr__(name, value)
children_map = super(Struct, self).__getattribute__("_pfp__children_map")
if name in children_map:
field = getattr(self, name)
# back to the start of the buffer
self._pfp__buff.seek(0, 0)
field._pfp__build(stream=self._pfp__buff)
return res
class Dom(Struct):
"""The result of an interpreted template"""
def _pfp__build(self, stream=None, save_offset=False):
if stream is None:
io_stream = six.BytesIO()
tmp_stream = bitwrap.BitwrappedStream(io_stream)
tmp_stream.padded = self._pfp__interp.get_bitfield_padded()
super(Dom, self)._pfp__build(tmp_stream, save_offset=save_offset)
# flush out any unaligned bitfields, etc
tmp_stream.flush()
res = io_stream.getvalue()
return res
else:
if not isinstance(stream, bitwrap.BitwrappedStream):
stream = bitwrap.BitwrappedStream(stream)
return super(Dom, self)._pfp__build(stream, save_offset=save_offset)
class NumberBase(Field):
"""The base field for all numeric fields"""
# can be set on individual fields, for all numbers (NumberBase.endian = ...),
# or specific number classes (Int.endian = ...)
endian = LITTLE_ENDIAN # default endianness is LITTLE_ENDIAN apparently..?? wtf
width = 4 # number of bytes
format = "i" # default signed int
bitsize = None # for IntBase
_pfp__value = 0 # default value
def __init__(self, stream=None, bitsize=None, metadata_processor=None, bitfield_rw=None):
"""Special init for the bitsize
"""
self.bitsize = get_value(bitsize)
self.bitfield_rw = bitfield_rw
super(NumberBase, self).__init__(stream, metadata_processor=metadata_processor)
def __nonzero__(self):
"""Used for the not operator"""
return self._pfp__value != 0
def __bool__(self):
"""Used for the not operator"""
return self._pfp__value != 0
def _pfp__parse(self, stream, save_offset=False):
"""Parse the IO stream for this numeric field
:stream: An IO stream that can be read from
:returns: The number of bytes parsed
"""
if save_offset:
self._pfp__offset = stream.tell()
if self.bitsize is None:
raw_data = stream.read(self.width)
data = utils.binary(raw_data)
else:
bits = self.bitfield_rw.read_bits(stream, self.bitsize)
width_diff = self.width - (len(bits)//8) - 1
bits_diff = 8 - (len(bits) % 8)
padding = [0] * (width_diff * 8 + bits_diff)
bits = padding + bits
data = bitwrap.bits_to_bytes(bits)
if self.endian == LITTLE_ENDIAN:
# reverse the data
data = data[::-1]
if len(data) < self.width:
raise errors.PrematureEOF()
self._pfp__data = data
self._pfp__value = struct.unpack(
"{}{}".format(self.endian, self.format),
data
)[0]
return self.width
def _pfp__build(self, stream=None, save_offset=False):
"""Build the field and write the result into the stream
:stream: An IO stream that can be written to
:returns: None
"""
if stream is not None and save_offset:
self._pfp__offset = stream.tell()
if self.bitsize is None:
data = struct.pack(
"{}{}".format(self.endian, self.format),
self._pfp__value
)
if stream is not None:
stream.write(data)
return len(data)
else:
return data
else:
data = struct.pack(
"{}{}".format(BIG_ENDIAN, self.format),
self._pfp__value
)
num_bytes = int(math.ceil(self.bitsize / 8.0))
bit_data = data[-num_bytes:]
raw_bits = bitwrap.bytes_to_bits(bit_data)
bits = raw_bits[-self.bitsize:]
if stream is not None:
self.bitfield_rw.write_bits(stream, bits)
return len(bits) // 8
else:
# TODO this can't be right....
return bits
def _dom_class(self, obj1, obj2):
"""Return the dominating numeric class between the two
:obj1: TODO
:obj2: TODO
:returns: TODO
"""
if isinstance(obj1, Double) or isinstance(obj2, Double):
return Double
if isinstance(obj1, Float) or isinstance(obj2, Float):
return Float
def __iadd__(self, other):
self._pfp__value += self._pfp__get_root_value(other)
return self
def __isub__(self, other):
self._pfp__value -= self._pfp__get_root_value(other)
return self
def __imul__(self, other):
self._pfp__value *= self._pfp__get_root_value(other)
return self
def __idiv__(self, other):
self._pfp__value /= self._pfp__get_root_value(other)
return self
def __iand__(self, other):
self._pfp__value &= self._pfp__get_root_value(other)
return self
def __ixor__(self, other):
self._pfp__value ^= self._pfp__get_root_value(other)
return self
def __ior__(self, other):
self._pfp__value |= self._pfp__get_root_value(other)
return self
def __ifloordiv__(self, other):
self._pfp__value //= self._pfp__get_root_value(other)
return self
def __imod__(self, other):
self._pfp__value %= self._pfp__get_root_value(other)
return self
def __ipow__(self, other):
self._pfp__value **= self._pfp__get_root_value(other)
return self
def __ilshift__(self, other):
self._pfp__value <<= self._pfp__get_root_value(other)
return self
def __irshift__(self, other):
self._pfp__value >>= self._pfp__get_root_value(other)
return self
def __add__(self, other):
res = self.__class__()
res._pfp__set_value(self._pfp__value + self._pfp__get_root_value(other))
return res
def __sub__(self, other):
res = self.__class__()
res._pfp__set_value(self._pfp__value - self._pfp__get_root_value(other))
return res
def __mul__(self, other):
res = self.__class__()
res._pfp__set_value(self._pfp__value * self._pfp__get_root_value(other))
return res
def __truediv__(self, other):
res = self.__class__()
# if truediv is being called, then / should also behave like
# truediv (2/3 == 0.6666 instead of 0 [classic division])
# the default in python 3 is truediv
res._pfp__set_value(self._pfp__value / self._pfp__get_root_value(other))
return res
def __div__(self, other):
res = self.__class__()
res._pfp__set_value(self._pfp__value / self._pfp__get_root_value(other))
return res
def __and__(self, other):
res = self.__class__()
res._pfp__set_value(self._pfp__value & self._pfp__get_root_value(other))
return res
def __xor__(self, other):
res = self.__class__()
res._pfp__set_value(self._pfp__value ^ self._pfp__get_root_value(other))
return res
def __or__(self, other):
res = self.__class__()
res._pfp__set_value(self._pfp__value | self._pfp__get_root_value(other))
return res
def __floordiv__(self, other):
res = self.__class__()
res._pfp__set_value(self._pfp__value // self._pfp__get_root_value(other))
return res
def __mod__(self, other):
res = self.__class__()
res._pfp__set_value(self._pfp__value % self._pfp__get_root_value(other))
return res
def __pow__(self, other):
res = self.__class__()
res._pfp__set_value(self._pfp__value ** self._pfp__get_root_value(other))
return res
def __lshift__(self, other):
res = self.__class__()
res._pfp__set_value(self._pfp__value << self._pfp__get_root_value(other))
return res
def __rshift__(self, other):
res = self.__class__()
res._pfp__set_value(self._pfp__value >> self._pfp__get_root_value(other))
return res
def __invert__(self):
res = self.__class__()
res._pfp__set_value(~self._pfp__value)
return res
def __neg__(self):
res = self.__class__()
res._pfp__set_value(-self._pfp__value)
return res
def __getattr__(self, val):
if val.startswith("__") and attr.endswith("__"):
return getattr(self._pfp__value, val)
raise AttributeError(val)
class IntBase(NumberBase):
"""The base class for all integers"""
signed = True
def _pfp__set_value(self, new_val):
"""Set the value, potentially converting an unsigned
value to a signed one (and visa versa)"""
if self._pfp__frozen:
raise errors.UnmodifiableConst()
if isinstance(new_val, IntBase):
# will automatically convert correctly between ints of
# different sizes, unsigned/signed, etc
raw = new_val._pfp__build()
while len(raw) < self.width:
raw = b"\x00" + raw
while len(raw) > self.width:
raw = raw[1:]
self._pfp__parse(six.BytesIO(raw))
else:
mask = 1 << (8*self.width)
if self.signed:
max_val = (mask//2)-1
min_val = -(mask//2)
else:
max_val = mask-1
min_val = 0
if new_val < min_val:
new_val += -(min_val)
new_val &= (mask-1)
new_val -= -(min_val)
elif new_val > max_val:
new_val &= (mask-1)
self._pfp__value = new_val
self._pfp__notify_parent()
def __repr__(self):
f = ":0{}x".format(self.width*2)
return ("{}({!r} [{" + f + "}]){}").format(
self._pfp__cls_name(),
self._pfp__value,
self._pfp__value,
":{}".format(self.bitsize) if self.bitsize is not None else ""
)
def _pfp__cls_name(self):
"""
"""
return self.__class__.__name__
def __truediv__(self, other):
"""dividing ints should not return a float (python 3
true div behavior). So force floordiv
"""
return self // other
class Char(IntBase):
"""A field representing a signed char"""
width = 1
format = "b"
class UChar(Char):
"""A field representing an unsigned char"""
format = "B"
signed = False
class Short(IntBase):
"""A field representing a signed short"""
width = 2
format = "h"
class UShort(Short):
"""A field representing an unsigned short"""
format = "H"
signed = False
class WChar(Short):
"""A field representing a signed wchar (aka short)"""
pass
class WUChar(UShort):
"""A field representing an unsigned wuchar (aka ushort)"""
signed = False
class Int(IntBase):
"""A field representing a signed int"""
width = 4
format = "i"
class UInt(Int):
"""A field representing an unsigned int"""
format = "I"
signed = False
class Int64(IntBase):
"""A field representing a signed int64"""
width = 8
format = "q"
class UInt64(Int64):
"""A field representing an unsigned int64"""
format = "Q"
signed = False
class Float(NumberBase):
"""A field representing a float"""
width = 4
format = "f"
class Double(NumberBase):
"""A field representing a double"""
width = 8
format = "d"
class Enum(IntBase):
"""The enum field class"""
enum_vals = None
enum_cls = None
enum_name = None
def __init__(self, stream=None, enum_cls=None, enum_vals=None, bitsize=None, metadata_processor=None, bitfield_rw=None):
"""Init the enum
"""
# discard the bitsize value and bitfield_rw value
self.enum_name = None
if enum_vals is not None:
self.enum_vals = enum_vals
if enum_cls is not None:
self.enum_cls = enum_cls
self.endian = enum_cls.endian
self.width = enum_cls.width
self.format = enum_cls.format
super(Enum, self).__init__(stream, metadata_processor=metadata_processor)
def _pfp__parse(self, stream, save_offset=False):
"""Parse the IO stream for this enum
:stream: An IO stream that can be read from
:returns: The number of bytes parsed
"""
res = super(Enum, self)._pfp__parse(stream, save_offset)
if self._pfp__value in self.enum_vals:
self.enum_name = self.enum_vals[self._pfp__value]
else:
self.enum_name = "?? UNK_ENUM ??"
return res
def __repr__(self):
"""Add the enum name to the int representation
"""
res = super(Enum, self).__repr__()
res += "({})".format(self.enum_name)
return res
def _pfp__cls_name(self):
"""
"""
return "Enum<{}>".format(
self.enum_cls.__name__
)
# --------------------------------
class Array(Field):
"""The array field"""
width = -1
"""The number of items of the array. ``len(array_field)`` also works"""
raw_data = None
"""The raw data of the array. Note that this will only be
set if the array's items are a core type (E.g. Int, Char, etc)"""
field_cls = None
"""The class for items in the array"""
implicit = False
"""If the array is an implicit array or not"""
def __init__(self, width, field_cls, stream=None, metadata_processor=None):
""" Create an array field of size "width" from the stream
"""
super(Array, self).__init__(stream=None, metadata_processor=metadata_processor)
self.width = width
self.field_cls = field_cls
self.items = []
self.raw_data = None
self.implicit = False
if stream is not None:
self._pfp__parse(stream, save_offset=True)
else:
for x in six.moves.range(self.width):
self.items.append(self.field_cls())
def append(self, item):
# TODO check for consistent type
item._pfp__parent = self
self.items.append(item)
self.width = len(self.items)
def _is_stringable(self):
# TODO WChar
return self.field_cls in [Char, UChar]
def _array_to_str(self, max_len=-1):
if not self._is_stringable():
return None
if self.raw_data is not None:
if max_len != -1:
return PYSTR(self.raw_data)[:max_len]
return self.raw_data
res = ""
for item in self.items:
if max_len != -1 and len(res) >= max_len:
break
# null-terminate string
if PYVAL(item) == 0:
break
# TODO WChar
res += chr(PYVAL(item))
return res
def __eq__(self, other):
if self._is_stringable() and other.__class__ in [String, WString, str]:
res = self._array_to_str()
return utils.binary(res) == utils.binary(PYSTR(other))
else:
raise Exception("TODO")
def __ne__(self, other):
return not self.__eq__(other)
def _pfp__set_value(self, value):
is_string_type = False
if isinstance(value, String):
is_string_type = True
value = value._pfp__build()
else:
for string_type in list(six.string_types) + [bytes]:
if isinstance(value, string_type):
is_string_type = True
break
if is_string_type and self._is_stringable():
self.raw_data = value
self.width = len(value)
self._pfp__notify_parent()
return
if value.__class__ not in [list, tuple]:
raise Exception("Error, invalid value for array")
# this shouldn't be enforced
# e.g.
# local uchar[16] = {0};
# where the first item should be 0
#
#if len(value) != PYVAL(self.width):
# raise Exception("Array was declared as having {} items, not {} items".format(
# PYVAL(self.width),
# len(value)
# ))
if len(value) > PYVAL(self.width):
raise Exception("This is not actual C, memory corruption is not allowed!")
for idx,item in enumerate(value):
self.items[idx] = item
self._pfp__notify_parent()
def _pfp__parse(self, stream, save_offset=False):
start_offset = stream.tell()
if save_offset:
self._pfp__offset = start_offset
# will always be known widths for these field types
if issubclass(self.field_cls, NumberBase):
length = self.field_cls.width * PYVAL(self.width)
self.raw_data = stream.read(length)
if self._pfp__can_unpack():
self._pfp__unpack_data(self.raw_data)
else:
# optimizations... should reuse existing fields??
self.items = []
for x in six.moves.range(PYVAL(self.width)):
field = self.field_cls(stream)
field._pfp__name = "{}[{}]".format(
self._pfp__name,
x
)
#field._pfp__parse(stream, save_offset)
self.items.append(field)
if self._pfp__can_unpack():
curr_offset = stream.tell()
stream.seek(start_offset, 0)
data = stream.read(curr_offset - start_offset)
# this shouldn't be necessary....
# stream.seek(curr_offset, 0)
self._pfp__unpack_data(data)
def _pfp__build(self, stream=None, save_offset=False):
if stream is not None and save_offset:
self._pfp__offset = stream.tell()
if self.raw_data is None:
res = 0 if stream is not None else utils.binary("")
for item in self.items:
res += item._pfp__build(stream=stream, save_offset=save_offset)
else:
if stream is None:
return self.raw_data
else:
stream.write(self.raw_data)
return len(self.raw_data)
return res
def _pfp__handle_updated(self, watched_field):
if self.raw_data is not None and \
watched_field._pfp__name is not None and \
watched_field._pfp__name.startswith(self._pfp__name) and \
watched_field._pfp__array_idx is not None:
data = watched_field._pfp__build()
offset = watched_field.width * watched_field._pfp__array_idx
self.raw_data = self.raw_data[0:offset] + data + self.raw_data[offset + len(data):]
else:
super(Array, self)._pfp__handle_updated(watched_field)
def __getitem__(self, idx):
if self.raw_data is None:
return self.items[idx]
else:
if self.width < 0 or idx+1 > self.width:
raise IndexError(idx)
width = self.field_cls.width
offset = width * idx
data = self.raw_data[offset:offset+width]
stream = bitwrap.BitwrappedStream(six.BytesIO(data))
res = self.field_cls(stream)
res._pfp__watch(self)
res._pfp__parent = self
res._pfp__array_idx = idx
res._pfp__name = "{}[{}]".format(
self._pfp__name, idx
)
return res
def __setitem__(self, idx, value):
if isinstance(value, Field):
if self.raw_data is None:
self.items[idx] = value
else:
if self.width < 0 or idx+1 > self.width:
raise IndexError(idx)
data = value._pfp__build()
offset = self.field_cls.width * idx
self.raw_data = self.raw_data[0:offset] + data + self.raw_data[offset+self.field_cls.width:]
else:
self[idx]._pfp__set_value(value)
self._pfp__notify_update(self)
def __repr__(self):
other = ""
if self._is_stringable():
res = self._array_to_str(20)
other = " ({!r})".format(res)
return "{}[{}]{}".format(
self.field_cls.__name__ if type(self.field_cls) is type else self.field_cls._typedef_name,
PYVAL(self.width),
other
)
def _pfp__show(self, level=0, include_offset=False):
if self._is_stringable():
res = self.__repr__()
if self._ is not None:
packed_show = self._._pfp__show(level=level+1, include_offset=False)
res += "\n" + (" "*(level+1)) + "_ = " + packed_show
return res
res = [self.__repr__()]
for idx,item in enumerate(self.items):
item_res = "{}{}{}[{}] = {}".format(
" " * (level+1),
"{:04x} ".format(item._pfp__offset) if include_offset else "",
self._pfp__name,
idx,
item._pfp__show(level+2, include_offset)
)
res.append(item_res)
return "\n".join(res)
def __len__(self):
return len(self.items)
# http://www.sweetscape.com/010editor/manual/ArraysStrings.htm
class String(Field):
"""A null-terminated string. String fields should be interchangeable
with char arrays"""
# if the width is -1 when parse is called, read until null
# termination.
width = -1
read_size = 1
terminator = utils.binary("\x00")
def __init__(self, stream=None, metadata_processor=None):
self._pfp__value = ""
super(String, self).__init__(stream=stream, metadata_processor=metadata_processor)
def _pfp__set_value(self, new_val):
"""Set the value of the String, taking into account
escaping and such as well
"""
if not isinstance(new_val, Field):
new_val = utils.binary(utils.string_escape(new_val))
super(String, self)._pfp__set_value(new_val)
def _pfp__parse(self, stream, save_offset=False):
"""Read from the stream until the string is null-terminated
:stream: The input stream
:returns: None
"""
if save_offset:
self._pfp__offset = stream.tell()
res = utils.binary("")
while True:
byte = utils.binary(stream.read(self.read_size))
if len(byte) < self.read_size:
raise errors.PrematureEOF()
# note that the null terminator must be added back when
# built again!
if byte == self.terminator:
break
res += byte
self._pfp__value = res
def _pfp__build(self, stream=None, save_offset=False):
"""Build the String field
:stream: TODO
:returns: TODO
"""
if stream is not None and save_offset:
self._pfp__offset = stream.tell()
data = self._pfp__value + utils.binary("\x00")
if stream is None:
return data
else:
stream.write(data)
return len(data)
def __getitem__(self, idx):
if idx < 0 or idx+1 > len(self._pfp__value):
raise IndexError(idx)
val = self._pfp__value[idx:idx+1]
stream = six.BytesIO(val)
res = Char(stream)
return res
def __setitem__(self, idx, val):
if idx < 0 or idx+1 > len(self._pfp__value):
raise IndexError(idx)
if isinstance(val, Field):
val = val._pfp__build()[-1:]
elif isinstance(val, int):
val = utils.binary(chr(val))
self._pfp__value = self._pfp__value[0:idx] + val + self._pfp__value[idx+1:]
def __add__(self, other):
"""Add two strings together. If other is not a String instance,
a fields.String instance will still be returned
:other: TODO
:returns: TODO
"""
res_field = String()
res = ""
if isinstance(other, String):
res = self._pfp__value + other._pfp__value
else:
res = self._pfp__value + PYSTR(other)
res_field._pfp__set_value(res)
return res_field
def __iadd__(self, other):
"""In-place addition to this String field
:other: TODO
:returns: TODO
"""
if isinstance(other, String):
self._pfp__value += other._pfp__value
else:
self._pfp__value += PYSTR(other)
return self
class WString(String):
width = -1
read_size = 2
terminator = utils.binary("\x00\x00")
def _pfp__parse(self, stream, save_offset=False):
String._pfp__parse(self, stream, save_offset)
self._pfp__value = utils.binary(self._pfp__value.decode("utf-16le"))
def _pfp__build(self, stream=None, save_offset=False):
if stream is not None and save_offset:
self._pfp__offset = stream.tell()
val = self._pfp__value.decode("ISO-8859-1").encode("utf-16le") + b"\x00\x00"
if stream is None:
return val
else:
stream.write(val)
return len(val)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
199,
504,
6252,
2350,
492,
18766,
3987,
12,
8227,
199,
646,
2022,
199,
646,
3473,
199,
646,
295,
199,
646,
3816,
199,
646,
2702,
199,
199,
646,
299,
3997,
14,
2550,
465,
2552,
199,
646,
299,
3997,
14,
1208,
465,
3778,
199,
646,
299,
3997,
14,
2075,
3823,
465,
4546,
3823,
199,
646,
299,
3997,
14,
5777,
465,
3423,
199,
199,
18643,
63,
21046,
275,
28192,
199,
44,
31783,
63,
21046,
275,
3886,
2,
199,
199,
318,
2549,
837,
199,
198,
470,
275,
9805,
342,
199,
198,
470,
423,
80,
3997,
363,
585,
275,
413,
199,
198,
1107,
522,
199,
199,
318,
3055,
837,
199,
198,
470,
275,
9805,
342,
199,
198,
470,
423,
80,
3997,
363,
585,
275,
378,
199,
198,
1107,
522,
199,
199,
318,
664,
63,
585,
8,
698,
304,
199,
198,
692,
1228,
8,
698,
12,
5024,
304,
507,
198,
1107,
901,
423,
80,
3997,
363,
585,
199,
198,
2836,
26,
507,
198,
1107,
901,
199,
199,
318,
664,
63,
495,
8,
698,
304,
199,
198,
692,
1228,
8,
698,
12,
8725,
304,
507,
198,
470,
275,
901,
423,
1144,
63,
475,
63,
495,
342,
199,
198,
4164,
1228,
8,
698,
12,
6659,
304,
507,
198,
470,
275,
8678,
8,
4521,
3204,
8,
698,
430,
199,
198,
2836,
26,
507,
198,
470,
275,
664,
63,
585,
8,
698,
9,
8299,
198,
1107,
3778,
14,
875,
8,
470,
9,
199,
199,
4521,
3204,
275,
664,
63,
585,
199,
4521,
3027,
275,
664,
63,
495,
199,
199,
533,
10199,
698,
25438,
8,
785,
304,
199,
198,
624,
23555,
7664,
436,
3575,
314,
3141,
5821,
367,
314,
4546,
698,
199,
198,
576,
730,
687,
314,
1324,
2547,
12,
436,
6657,
18876,
199,
198,
15009,
436,
4546,
7581,
2202,
14,
199,
198,
624,
421,
198,
318,
636,
826,
721,
277,
12,
23716,
12,
843,
304,
507,
198,
624,
1084,
314,
12693,
436,
2547,
367,
10199,
792,
5929,
2742,
198,
26,
635,
299,
3997,
14,
14252,
14,
48,
3997,
2620,
80,
23716,
26,
710,
12693,
3769,
1202,
507,
198,
26,
635,
299,
3997,
14,
2075,
3823,
14,
4734,
9130,
3296,
2547,
26,
710,
4546,
9130,
2547,
507,
198,
26,
635,
299,
3997,
14,
955,
14,
792,
843,
26,
710,
1021,
334,
65,
5516,
402,
520,
1629,
1705,
80,
3997,
14,
955,
14,
792,
10522,
446,
1202,
370,
6705,
3141,
1568,
402,
4546,
698,
334,
692,
21824,
680,
507,
198,
624,
507,
198,
277,
14,
14252,
275,
23716,
507,
198,
277,
14,
1886,
275,
843,
507,
198,
277,
14,
988,
63,
5609,
275,
291,
14,
1886,
14,
2063,
627,
1695,
507,
198,
277,
14,
10421,
63,
5609,
275,
378,
2742,
198,
3,
1454,
1202,
543,
6273,
365,
5223,
507,
198,
277,
423,
1886,
63,
5609,
275,
488,
2742,
198,
3,
1202,
370,
2218,
370,
314,
2547,
507,
198,
277,
423,
952,
63,
5609,
275,
942,
8299,
198,
318,
32606,
63,
5609,
8,
277,
12,
1967,
63,
5609,
304,
507,
198,
624,
9167,
370,
298,
19643,
2,
1124,
1507,
63,
5609,
1040,
5982,
402,
5821,
315,
1865,
370,
4215,
4426,
507,
198,
1618,
23376,
4546,
955,
334,
269,
787,
314,
2797,
4546,
698,
4652,
31,
680,
2742,
198,
37,
14,
71,
14,
3800,
6319,
198,
1820,
469,
1585,
198,
1560,
282,
26,
24,
12,
330,
26,
24,
27,
1585,
198,
1560,
286,
26,
20,
12,
366,
26,
20,
12,
325,
26,
24,
27,
686,
198,
93,
2742,
198,
26,
635,
1109,
1967,
63,
5609,
26,
710,
1329,
402,
5821,
370,
22498,
507,
198,
26,
5808,
26,
982,
14726,
30482,
367,
314,
25476,
507,
198,
624,
507,
198,
1507,
63,
5609,
275,
7843,
3204,
8,
1507,
63,
5609,
9,
507,
198,
692,
1967,
63,
5609,
435,
291,
14,
10421,
63,
5609,
690,
291,
14,
988,
63,
5609,
26,
686,
198,
1107,
756,
2742,
198,
277,
14,
10421,
63,
5609,
847,
1967,
63,
5609,
507,
198,
1107,
715,
8299,
198,
318,
1586,
63,
5609,
8,
277,
12,
2547,
12,
1967,
63,
5609,
304,
507,
198,
624,
1767,
1124,
1507,
63,
5609,
1040,
5821,
12,
16466,
1901,
2933,
17638,
4171,
436,
11083,
198,
3039,
13,
1019,
4546,
28820,
507,
198,
624,
507,
198,
25201,
275,
291,
14,
14252,
14,
362,
63,
2075,
698,
63,
25201,
342,
507,
198,
3039,
63,
1019,
275,
291,
14,
14252,
14,
362,
63,
2075,
698,
63,
3039,
63,
1019,
342,
2742,
198,
3,
3254,
642,
4839,
370,
506,
6020,
1655,
2839,
642,
507,
198,
3,
17638,
275,
291,
14,
14252,
14,
362,
63,
15009,
342,
507,
198,
15009,
275,
4860,
1563,
14,
15009,
2742,
198,
692,
291,
423,
1886,
63,
5609,
365,
488,
436,
21824,
26,
686,
198,
1773,
63,
5609,
275,
2547,
14,
739,
63,
5609,
8,
277,
14,
1886,
14,
2063,
10,
24,
9,
686,
198,
277,
423,
1886,
63,
5609,
275,
291,
423,
15009,
63,
4711,
8,
1773,
63,
5609,
12,
17638,
9,
2742,
198,
692,
291,
423,
1886,
63,
5609,
365,
440,
488,
26,
686,
198,
692,
1967,
63,
5609,
690,
822,
8,
277,
423,
1886,
63,
5609,
304,
1585,
198,
3730,
2552,
14,
48,
3997,
547,
480,
4734,
698,
25438,
13075,
3866,
1174,
531,
6319,
198,
692,
3602,
63,
1019,
26,
1585,
198,
470,
275,
291,
423,
1886,
63,
5609,
1491,
1507,
63,
5609,
61,
1585,
198,
277,
423,
1886,
63,
5609,
275,
291,
423,
1886,
63,
5609,
59,
1507,
63,
5609,
2938,
686,
198,
2836,
26,
1585,
198,
470,
275,
291,
423,
1886,
63,
5609,
1988,
1507,
63,
5609,
2938,
1585,
198,
277,
423,
1886,
63,
5609,
275,
291,
423,
1886,
63,
5609,
4439,
1507,
63,
5609,
61,
6319,
198,
1107,
522,
2742,
198,
2836,
26,
686,
198,
1107,
2547,
14,
739,
63,
5609,
8,
1507,
63,
5609,
9,
8299,
198,
318,
2218,
63,
5609,
8,
277,
12,
2547,
12,
3066,
63,
5609,
304,
507,
198,
624,
3534,
314,
5821,
14,
19468,
314,
1568,
402,
314,
5313,
5821,
365,
4472,
507,
198,
475,
314,
1329,
402,
314,
4644,
5821,
12,
8976,
652,
370,
314,
2547,
507,
198,
624,
507,
198,
25201,
275,
291,
14,
14252,
14,
362,
63,
2075,
698,
63,
25201,
342,
507
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
199,
504,
6252,
2350,
492,
18766,
3987,
12,
8227,
199,
646,
2022,
199,
646,
3473,
199,
646,
295,
199,
646,
3816,
199,
646,
2702,
199,
199,
646,
299,
3997,
14,
2550,
465,
2552,
199,
646,
299,
3997,
14,
1208,
465,
3778,
199,
646,
299,
3997,
14,
2075,
3823,
465,
4546,
3823,
199,
646,
299,
3997,
14,
5777,
465,
3423,
199,
199,
18643,
63,
21046,
275,
28192,
199,
44,
31783,
63,
21046,
275,
3886,
2,
199,
199,
318,
2549,
837,
199,
198,
470,
275,
9805,
342,
199,
198,
470,
423,
80,
3997,
363,
585,
275,
413,
199,
198,
1107,
522,
199,
199,
318,
3055,
837,
199,
198,
470,
275,
9805,
342,
199,
198,
470,
423,
80,
3997,
363,
585,
275,
378,
199,
198,
1107,
522,
199,
199,
318,
664,
63,
585,
8,
698,
304,
199,
198,
692,
1228,
8,
698,
12,
5024,
304,
507,
198,
1107,
901,
423,
80,
3997,
363,
585,
199,
198,
2836,
26,
507,
198,
1107,
901,
199,
199,
318,
664,
63,
495,
8,
698,
304,
199,
198,
692,
1228,
8,
698,
12,
8725,
304,
507,
198,
470,
275,
901,
423,
1144,
63,
475,
63,
495,
342,
199,
198,
4164,
1228,
8,
698,
12,
6659,
304,
507,
198,
470,
275,
8678,
8,
4521,
3204,
8,
698,
430,
199,
198,
2836,
26,
507,
198,
470,
275,
664,
63,
585,
8,
698,
9,
8299,
198,
1107,
3778,
14,
875,
8,
470,
9,
199,
199,
4521,
3204,
275,
664,
63,
585,
199,
4521,
3027,
275,
664,
63,
495,
199,
199,
533,
10199,
698,
25438,
8,
785,
304,
199,
198,
624,
23555,
7664,
436,
3575,
314,
3141,
5821,
367,
314,
4546,
698,
199,
198,
576,
730,
687,
314,
1324,
2547,
12,
436,
6657,
18876,
199,
198,
15009,
436,
4546,
7581,
2202,
14,
199,
198,
624,
421,
198,
318,
636,
826,
721,
277,
12,
23716,
12,
843,
304,
507,
198,
624,
1084,
314,
12693,
436,
2547,
367,
10199,
792,
5929,
2742,
198,
26,
635,
299,
3997,
14,
14252,
14,
48,
3997,
2620,
80,
23716,
26,
710,
12693,
3769,
1202,
507,
198,
26,
635,
299,
3997,
14,
2075,
3823,
14,
4734,
9130,
3296,
2547,
26,
710,
4546,
9130,
2547,
507,
198,
26,
635,
299,
3997,
14,
955,
14,
792,
843,
26,
710,
1021,
334,
65,
5516,
402,
520,
1629,
1705,
80,
3997,
14,
955,
14,
792,
10522,
446,
1202,
370,
6705,
3141,
1568,
402,
4546,
698,
334,
692,
21824,
680,
507,
198,
624,
507,
198,
277,
14,
14252,
275,
23716,
507,
198,
277,
14,
1886,
275,
843,
507,
198,
277,
14,
988,
63,
5609,
275,
291,
14,
1886,
14,
2063,
627,
1695,
507,
198,
277,
14,
10421,
63,
5609,
275,
378,
2742,
198,
3,
1454,
1202,
543,
6273,
365,
5223,
507,
198,
277,
423,
1886,
63,
5609,
275,
488,
2742,
198,
3,
1202,
370,
2218,
370,
314,
2547,
507,
198,
277,
423,
952,
63,
5609,
275,
942,
8299,
198,
318,
32606,
63,
5609,
8,
277,
12,
1967,
63,
5609,
304,
507,
198,
624,
9167,
370,
298,
19643,
2,
1124,
1507,
63,
5609,
1040,
5982,
402,
5821,
315,
1865,
370,
4215,
4426,
507,
198,
1618,
23376,
4546,
955,
334,
269,
787,
314,
2797,
4546,
698,
4652,
31,
680,
2742,
198,
37,
14,
71,
14,
3800,
6319,
198,
1820,
469,
1585,
198,
1560,
282,
26,
24,
12,
330,
26,
24,
27,
1585,
198,
1560,
286,
26,
20,
12,
366,
26,
20,
12,
325,
26,
24,
27,
686,
198,
93,
2742,
198,
26,
635,
1109,
1967,
63,
5609,
26,
710,
1329,
402,
5821,
370,
22498,
507,
198,
26,
5808,
26,
982,
14726,
30482,
367,
314,
25476,
507,
198,
624,
507,
198,
1507,
63,
5609,
275,
7843,
3204,
8,
1507,
63,
5609,
9,
507,
198,
692,
1967,
63,
5609,
435,
291,
14,
10421,
63,
5609,
690,
291,
14,
988,
63,
5609,
26,
686,
198,
1107,
756,
2742,
198,
277,
14,
10421,
63,
5609,
847,
1967,
63,
5609,
507,
198,
1107,
715,
8299,
198,
318,
1586,
63,
5609,
8,
277,
12,
2547,
12,
1967,
63,
5609,
304,
507,
198,
624,
1767,
1124,
1507,
63,
5609,
1040,
5821,
12,
16466,
1901,
2933,
17638,
4171,
436,
11083,
198,
3039,
13,
1019,
4546,
28820,
507,
198,
624,
507,
198,
25201,
275,
291,
14,
14252,
14,
362,
63,
2075,
698,
63,
25201,
342,
507,
198,
3039,
63,
1019,
275,
291,
14,
14252,
14,
362,
63,
2075,
698,
63,
3039,
63,
1019,
342,
2742,
198,
3,
3254,
642,
4839,
370,
506,
6020,
1655,
2839,
642,
507,
198,
3,
17638,
275,
291,
14,
14252,
14,
362,
63,
15009,
342,
507,
198,
15009,
275,
4860,
1563,
14,
15009,
2742,
198,
692,
291,
423,
1886,
63,
5609,
365,
488,
436,
21824,
26,
686,
198,
1773,
63,
5609,
275,
2547,
14,
739,
63,
5609,
8,
277,
14,
1886,
14,
2063,
10,
24,
9,
686,
198,
277,
423,
1886,
63,
5609,
275,
291,
423,
15009,
63,
4711,
8,
1773,
63,
5609,
12,
17638,
9,
2742,
198,
692,
291,
423,
1886,
63,
5609,
365,
440,
488,
26,
686,
198,
692,
1967,
63,
5609,
690,
822,
8,
277,
423,
1886,
63,
5609,
304,
1585,
198,
3730,
2552,
14,
48,
3997,
547,
480,
4734,
698,
25438,
13075,
3866,
1174,
531,
6319,
198,
692,
3602,
63,
1019,
26,
1585,
198,
470,
275,
291,
423,
1886,
63,
5609,
1491,
1507,
63,
5609,
61,
1585,
198,
277,
423,
1886,
63,
5609,
275,
291,
423,
1886,
63,
5609,
59,
1507,
63,
5609,
2938,
686,
198,
2836,
26,
1585,
198,
470,
275,
291,
423,
1886,
63,
5609,
1988,
1507,
63,
5609,
2938,
1585,
198,
277,
423,
1886,
63,
5609,
275,
291,
423,
1886,
63,
5609,
4439,
1507,
63,
5609,
61,
6319,
198,
1107,
522,
2742,
198,
2836,
26,
686,
198,
1107,
2547,
14,
739,
63,
5609,
8,
1507,
63,
5609,
9,
8299,
198,
318,
2218,
63,
5609,
8,
277,
12,
2547,
12,
3066,
63,
5609,
304,
507,
198,
624,
3534,
314,
5821,
14,
19468,
314,
1568,
402,
314,
5313,
5821,
365,
4472,
507,
198,
475,
314,
1329,
402,
314,
4644,
5821,
12,
8976,
652,
370,
314,
2547,
507,
198,
624,
507,
198,
25201,
275,
291,
14,
14252,
14,
362,
63,
2075,
698,
63,
25201,
342,
507,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Jeebeevee/DouweBot_JJ15
|
plugins_org/weather.py
|
4
|
4119
|
"weather, thanks to wunderground"
from util import hook, http
@hook.api_key('wunderground')
@hook.command(autohelp=False)
def weather(inp, chan='', nick='', reply=None, db=None, api_key=None):
".weather <location> [dontsave] | @<nick> -- gets weather data from Wunderground "\
"http://wunderground.com/weather/api"
if not api_key:
return None
# this database is used by other plugins interested in user's locations,
# like .near in tag.py
db.execute(
"create table if not exists location(chan, nick, loc, lat, lon, primary key(chan, nick))")
if inp[0:1] == '@':
nick = inp[1:].strip()
loc = None
dontsave = True
else:
dontsave = inp.endswith(" dontsave")
# strip off the " dontsave" text if it exists and set it back to `inp` so we don't report it
# back to the user incorrectly
if dontsave:
inp = inp[:-9].strip().lower()
loc = inp
if not loc: # blank line
loc = db.execute(
"select loc from location where chan=? and nick=lower(?)",
(chan, nick)).fetchone()
if not loc:
try:
# grab from old-style weather database
loc = db.execute("select loc from weather where nick=lower(?)",
(nick,)).fetchone()
except db.OperationalError:
pass # no such table
if not loc:
return weather.__doc__
loc = loc[0]
loc, _, state = loc.partition(', ')
# Check to see if a lat, long pair is being passed. This could be done more
# completely with regex, and converting from DMS to decimal degrees. This
# is nice and simple, however.
try:
float(loc)
float(state)
loc = loc + ',' + state
state = ''
except ValueError:
if state:
state = http.quote_plus(state)
state += '/'
loc = http.quote_plus(loc)
url = 'http://api.wunderground.com/api/'
query = '{key}/geolookup/conditions/forecast/q/{state}{loc}.json' \
.format(key=api_key, state=state, loc=loc)
url += query
try:
parsed_json = http.get_json(url)
except IOError:
return 'Could not get data from Wunderground'
info = {}
if 'current_observation' not in parsed_json:
resp = 'Could not find weather for {inp}. '.format(inp=inp)
# In the case of no observation, but results, print some possible
# location matches
if 'results' in parsed_json['response']:
resp += 'Possible matches include: '
results = parsed_json['response']['results']
for place in results[:6]:
resp += '{city}, '.format(**place)
if place['state']:
resp += '{state}, '.format(**place)
if place['country_name']:
resp += '{country_name}; '.format(**place)
resp = resp[:-2]
reply(resp)
return
obs = parsed_json['current_observation']
sf = parsed_json['forecast']['simpleforecast']['forecastday'][0]
info['city'] = obs['display_location']['full']
info['t_f'] = obs['temp_f']
info['t_c'] = obs['temp_c']
info['weather'] = obs['weather']
info['h_f'] = sf['high']['fahrenheit']
info['h_c'] = sf['high']['celsius']
info['l_f'] = sf['low']['fahrenheit']
info['l_c'] = sf['low']['celsius']
info['humid'] = obs['relative_humidity']
info['wind'] = 'Wind: {mph}mph/{kph}kph' \
.format(mph=obs['wind_mph'], kph=obs['wind_kph'])
reply('{city}: {weather}, {t_f}F/{t_c}C'
'(H:{h_f}F/{h_c}C L:{l_f}F/{l_c}C)'
', Humidity: {humid}, {wind}'.format(**info))
lat = float(obs['display_location']['latitude'])
lon = float(obs['display_location']['longitude'])
if inp and not dontsave:
db.execute("insert or replace into location(chan, nick, loc, lat, lon) "
"values (?, ?, ?, ?,?)", (chan, nick.lower(), inp, lat, lon))
db.commit()
|
unlicense
|
[
2,
23026,
12,
2419,
6080,
370,
336,
7138,
3928,
2,
199,
199,
504,
4884,
492,
5759,
12,
1455,
421,
199,
32,
3664,
14,
1246,
63,
498,
360,
87,
7138,
3928,
358,
199,
32,
3664,
14,
1531,
8,
2495,
3437,
29,
797,
9,
199,
318,
29643,
8,
11416,
12,
15985,
4581,
14900,
4581,
9351,
29,
403,
12,
1592,
29,
403,
12,
2986,
63,
498,
29,
403,
304,
272,
3680,
23026,
665,
1985,
30,
359,
13196,
1086,
811,
61,
1204,
768,
28,
11082,
30,
1553,
7545,
29643,
666,
687,
644,
7138,
3928,
1867,
288,
298,
1014,
921,
87,
7138,
3928,
14,
957,
15,
23026,
15,
1246,
2,
339,
340,
440,
2986,
63,
498,
26,
267,
372,
488,
339,
327,
642,
3050,
365,
1202,
701,
1163,
8963,
22201,
315,
922,
1159,
9918,
12,
272,
327,
2839,
1275,
21078,
315,
1947,
14,
647,
272,
1592,
14,
2526,
8,
267,
298,
981,
1817,
340,
440,
3495,
2909,
8,
11984,
12,
14900,
12,
4355,
12,
8396,
12,
6132,
12,
5062,
790,
8,
11984,
12,
14900,
430,
531,
339,
340,
10702,
59,
16,
26,
17,
61,
508,
10267,
356,
267,
14900,
275,
10702,
59,
17,
11455,
1913,
342,
267,
4355,
275,
488,
267,
2793,
1086,
811,
275,
715,
272,
587,
26,
267,
2793,
1086,
811,
275,
10702,
14,
4130,
480,
2793,
1086,
811,
531,
267,
327,
6202,
2331,
314,
298,
2793,
1086,
811,
2,
1318,
340,
652,
3495,
436,
663,
652,
1771,
370,
658,
11416,
64,
880,
781,
2793,
1133,
3622,
652,
267,
327,
1771,
370,
314,
922,
22743,
267,
340,
2793,
1086,
811,
26,
288,
10702,
275,
10702,
4439,
25,
1055,
1913,
1252,
2325,
342,
267,
4355,
275,
10702,
339,
340,
440,
4355,
26,
221,
327,
4596,
1004,
267,
4355,
275,
1592,
14,
2526,
8,
288,
298,
2416,
4355,
687,
2909,
2382,
15985,
18048,
436,
14900,
29,
2325,
2229,
4186,
288,
334,
11984,
12,
14900,
4992,
11591,
342,
267,
340,
440,
4355,
26,
288,
862,
26,
355,
327,
18200,
687,
2269,
13,
2487,
29643,
3050,
355,
4355,
275,
1592,
14,
2526,
480,
2416,
4355,
687,
29643,
2382,
14900,
29,
2325,
2229,
4186,
639,
334,
11082,
4641,
14,
11591,
342,
288,
871,
1592,
14,
31998,
547,
26,
355,
986,
259,
327,
949,
4066,
1817,
288,
340,
440,
4355,
26,
355,
372,
29643,
855,
1301,
363,
267,
4355,
275,
4355,
59,
16,
61,
339,
4355,
12,
5501,
1174,
275,
4355,
14,
5312,
5102,
5320,
339,
327,
2670,
370,
1937,
340,
282,
8396,
12,
1846,
4092,
365,
3769,
3032,
14,
961,
4293,
506,
4224,
1655,
272,
327,
14793,
543,
5163,
12,
436,
13806,
687,
577,
3053,
370,
6107,
14358,
14,
961,
272,
327,
365,
14213,
436,
3486,
12,
13432,
14,
272,
862,
26,
267,
2069,
8,
2102,
9,
267,
2069,
8,
929,
9,
398,
4355,
275,
4355,
435,
13647,
435,
1174,
267,
1174,
275,
2125,
272,
871,
1722,
26,
267,
340,
1174,
26,
288,
1174,
275,
1455,
14,
3513,
63,
6666,
8,
929,
9,
288,
1174,
847,
7324,
398,
4355,
275,
1455,
14,
3513,
63,
6666,
8,
2102,
9,
339,
1166,
275,
283,
1014,
921,
1246,
14,
87,
7138,
3928,
14,
957,
15,
1246,
4805,
272,
1827,
275,
5041,
498,
5995,
6721,
3892,
15,
9855,
15,
29693,
15,
81,
5321,
929,
8847,
2102,
5565,
1001,
7,
971,
288,
1275,
908,
8,
498,
29,
1246,
63,
498,
12,
1174,
29,
929,
12,
4355,
29,
2102,
9,
272,
1166,
847,
1827,
339,
862,
26,
267,
4565,
63,
1001,
275,
1455,
14,
362,
63,
1001,
8,
633,
9,
272,
871,
5925,
26,
267,
372,
283,
6531,
440,
664,
666,
687,
644,
7138,
3928,
7,
339,
2256,
275,
1052,
272,
340,
283,
1818,
63,
24299,
7,
440,
315,
4565,
63,
1001,
26,
267,
3085,
275,
283,
6531,
440,
2342,
29643,
367,
469,
11416,
5565,
1987,
908,
8,
11416,
29,
11416,
9,
398,
327,
1010,
314,
1930,
402,
949,
20038,
12,
1325,
2058,
12,
870,
2005,
3962,
267,
327,
2909,
4450,
267,
340,
283,
2604,
7,
315,
4565,
63,
1001,
459,
1310,
2565,
288,
3085,
847,
283,
28096,
4450,
2387,
26,
283,
288,
2058,
275,
4565,
63,
1001,
459,
1310,
2545,
2604,
418,
953,
367,
4192,
315,
2058,
1491,
22,
2189,
355,
3085,
847,
5041,
3690,
1386,
1987,
908,
3682,
2778,
9,
2234,
340,
4192,
459,
929,
2565,
490,
3085,
847,
5041,
929,
1386,
1987,
908,
3682,
2778,
9,
2234,
340,
4192,
459,
6063,
63,
354,
2565,
490,
3085,
847,
5041,
6063,
63,
354,
12084,
1987,
908,
3682,
2778,
9,
953,
3085,
275,
3085,
4439,
18,
61,
398,
9351,
8,
4518,
9,
267,
372,
339,
16087,
275,
4565,
63,
1001,
459,
1818,
63,
24299,
418,
272,
13330,
275,
4565,
63,
1001,
459,
29693,
2545,
4129,
29693,
2545,
29693,
2977,
3488,
16,
61,
272,
2256,
459,
3690,
418,
275,
16087,
459,
2918,
63,
1985,
2545,
2861,
418,
272,
2256,
459,
84,
63,
70,
418,
275,
16087,
459,
808,
63,
70,
418,
272,
2256,
459,
84,
63,
67,
418,
275,
16087,
459,
808,
63,
67,
418,
272,
2256,
459,
23026,
418,
275,
16087,
459,
23026,
418,
272,
2256,
459,
72,
63,
70,
418,
275,
13330,
459,
6260,
2545,
667,
72,
828,
426,
390,
418,
272,
2256,
459,
72,
63,
67,
418,
275,
13330,
459,
6260,
2545,
6067,
338,
527,
418,
272,
2256,
459,
76,
63,
70,
418,
275,
13330,
459,
674,
2545,
667,
72,
828,
426,
390,
418,
272,
2256,
459,
76,
63,
67,
418,
275,
13330,
459,
674,
2545,
6067,
338,
527,
418,
272,
2256,
459,
72,
453,
344,
418,
275,
16087,
459,
6188,
63,
31812,
418,
272,
2256,
459,
11530,
418,
275,
283,
55,
688,
26,
469,
311,
72,
93,
311,
72,
5321,
75,
838,
93,
75,
838,
7,
971,
267,
1275,
908,
8,
311,
72,
29,
11226,
459,
11530,
63,
311,
72,
995,
1022,
838,
29,
11226,
459,
11530,
63,
75,
838,
1105,
272,
9351,
11117,
3690,
9160,
469,
23026,
1386,
469,
84,
63,
70,
93,
38,
5321,
84,
63,
67,
93,
35,
7,
881,
8189,
40,
14534,
72,
63,
70,
93,
38,
5321,
72,
63,
67,
93,
35,
491,
14534,
76,
63,
70,
93,
38,
5321,
76,
63,
67,
93,
35,
3171,
881,
1656,
869,
21704,
26,
469,
72,
453,
344,
1386,
469,
11530,
5285,
908
] |
[
23026,
12,
2419,
6080,
370,
336,
7138,
3928,
2,
199,
199,
504,
4884,
492,
5759,
12,
1455,
421,
199,
32,
3664,
14,
1246,
63,
498,
360,
87,
7138,
3928,
358,
199,
32,
3664,
14,
1531,
8,
2495,
3437,
29,
797,
9,
199,
318,
29643,
8,
11416,
12,
15985,
4581,
14900,
4581,
9351,
29,
403,
12,
1592,
29,
403,
12,
2986,
63,
498,
29,
403,
304,
272,
3680,
23026,
665,
1985,
30,
359,
13196,
1086,
811,
61,
1204,
768,
28,
11082,
30,
1553,
7545,
29643,
666,
687,
644,
7138,
3928,
1867,
288,
298,
1014,
921,
87,
7138,
3928,
14,
957,
15,
23026,
15,
1246,
2,
339,
340,
440,
2986,
63,
498,
26,
267,
372,
488,
339,
327,
642,
3050,
365,
1202,
701,
1163,
8963,
22201,
315,
922,
1159,
9918,
12,
272,
327,
2839,
1275,
21078,
315,
1947,
14,
647,
272,
1592,
14,
2526,
8,
267,
298,
981,
1817,
340,
440,
3495,
2909,
8,
11984,
12,
14900,
12,
4355,
12,
8396,
12,
6132,
12,
5062,
790,
8,
11984,
12,
14900,
430,
531,
339,
340,
10702,
59,
16,
26,
17,
61,
508,
10267,
356,
267,
14900,
275,
10702,
59,
17,
11455,
1913,
342,
267,
4355,
275,
488,
267,
2793,
1086,
811,
275,
715,
272,
587,
26,
267,
2793,
1086,
811,
275,
10702,
14,
4130,
480,
2793,
1086,
811,
531,
267,
327,
6202,
2331,
314,
298,
2793,
1086,
811,
2,
1318,
340,
652,
3495,
436,
663,
652,
1771,
370,
658,
11416,
64,
880,
781,
2793,
1133,
3622,
652,
267,
327,
1771,
370,
314,
922,
22743,
267,
340,
2793,
1086,
811,
26,
288,
10702,
275,
10702,
4439,
25,
1055,
1913,
1252,
2325,
342,
267,
4355,
275,
10702,
339,
340,
440,
4355,
26,
221,
327,
4596,
1004,
267,
4355,
275,
1592,
14,
2526,
8,
288,
298,
2416,
4355,
687,
2909,
2382,
15985,
18048,
436,
14900,
29,
2325,
2229,
4186,
288,
334,
11984,
12,
14900,
4992,
11591,
342,
267,
340,
440,
4355,
26,
288,
862,
26,
355,
327,
18200,
687,
2269,
13,
2487,
29643,
3050,
355,
4355,
275,
1592,
14,
2526,
480,
2416,
4355,
687,
29643,
2382,
14900,
29,
2325,
2229,
4186,
639,
334,
11082,
4641,
14,
11591,
342,
288,
871,
1592,
14,
31998,
547,
26,
355,
986,
259,
327,
949,
4066,
1817,
288,
340,
440,
4355,
26,
355,
372,
29643,
855,
1301,
363,
267,
4355,
275,
4355,
59,
16,
61,
339,
4355,
12,
5501,
1174,
275,
4355,
14,
5312,
5102,
5320,
339,
327,
2670,
370,
1937,
340,
282,
8396,
12,
1846,
4092,
365,
3769,
3032,
14,
961,
4293,
506,
4224,
1655,
272,
327,
14793,
543,
5163,
12,
436,
13806,
687,
577,
3053,
370,
6107,
14358,
14,
961,
272,
327,
365,
14213,
436,
3486,
12,
13432,
14,
272,
862,
26,
267,
2069,
8,
2102,
9,
267,
2069,
8,
929,
9,
398,
4355,
275,
4355,
435,
13647,
435,
1174,
267,
1174,
275,
2125,
272,
871,
1722,
26,
267,
340,
1174,
26,
288,
1174,
275,
1455,
14,
3513,
63,
6666,
8,
929,
9,
288,
1174,
847,
7324,
398,
4355,
275,
1455,
14,
3513,
63,
6666,
8,
2102,
9,
339,
1166,
275,
283,
1014,
921,
1246,
14,
87,
7138,
3928,
14,
957,
15,
1246,
4805,
272,
1827,
275,
5041,
498,
5995,
6721,
3892,
15,
9855,
15,
29693,
15,
81,
5321,
929,
8847,
2102,
5565,
1001,
7,
971,
288,
1275,
908,
8,
498,
29,
1246,
63,
498,
12,
1174,
29,
929,
12,
4355,
29,
2102,
9,
272,
1166,
847,
1827,
339,
862,
26,
267,
4565,
63,
1001,
275,
1455,
14,
362,
63,
1001,
8,
633,
9,
272,
871,
5925,
26,
267,
372,
283,
6531,
440,
664,
666,
687,
644,
7138,
3928,
7,
339,
2256,
275,
1052,
272,
340,
283,
1818,
63,
24299,
7,
440,
315,
4565,
63,
1001,
26,
267,
3085,
275,
283,
6531,
440,
2342,
29643,
367,
469,
11416,
5565,
1987,
908,
8,
11416,
29,
11416,
9,
398,
327,
1010,
314,
1930,
402,
949,
20038,
12,
1325,
2058,
12,
870,
2005,
3962,
267,
327,
2909,
4450,
267,
340,
283,
2604,
7,
315,
4565,
63,
1001,
459,
1310,
2565,
288,
3085,
847,
283,
28096,
4450,
2387,
26,
283,
288,
2058,
275,
4565,
63,
1001,
459,
1310,
2545,
2604,
418,
953,
367,
4192,
315,
2058,
1491,
22,
2189,
355,
3085,
847,
5041,
3690,
1386,
1987,
908,
3682,
2778,
9,
2234,
340,
4192,
459,
929,
2565,
490,
3085,
847,
5041,
929,
1386,
1987,
908,
3682,
2778,
9,
2234,
340,
4192,
459,
6063,
63,
354,
2565,
490,
3085,
847,
5041,
6063,
63,
354,
12084,
1987,
908,
3682,
2778,
9,
953,
3085,
275,
3085,
4439,
18,
61,
398,
9351,
8,
4518,
9,
267,
372,
339,
16087,
275,
4565,
63,
1001,
459,
1818,
63,
24299,
418,
272,
13330,
275,
4565,
63,
1001,
459,
29693,
2545,
4129,
29693,
2545,
29693,
2977,
3488,
16,
61,
272,
2256,
459,
3690,
418,
275,
16087,
459,
2918,
63,
1985,
2545,
2861,
418,
272,
2256,
459,
84,
63,
70,
418,
275,
16087,
459,
808,
63,
70,
418,
272,
2256,
459,
84,
63,
67,
418,
275,
16087,
459,
808,
63,
67,
418,
272,
2256,
459,
23026,
418,
275,
16087,
459,
23026,
418,
272,
2256,
459,
72,
63,
70,
418,
275,
13330,
459,
6260,
2545,
667,
72,
828,
426,
390,
418,
272,
2256,
459,
72,
63,
67,
418,
275,
13330,
459,
6260,
2545,
6067,
338,
527,
418,
272,
2256,
459,
76,
63,
70,
418,
275,
13330,
459,
674,
2545,
667,
72,
828,
426,
390,
418,
272,
2256,
459,
76,
63,
67,
418,
275,
13330,
459,
674,
2545,
6067,
338,
527,
418,
272,
2256,
459,
72,
453,
344,
418,
275,
16087,
459,
6188,
63,
31812,
418,
272,
2256,
459,
11530,
418,
275,
283,
55,
688,
26,
469,
311,
72,
93,
311,
72,
5321,
75,
838,
93,
75,
838,
7,
971,
267,
1275,
908,
8,
311,
72,
29,
11226,
459,
11530,
63,
311,
72,
995,
1022,
838,
29,
11226,
459,
11530,
63,
75,
838,
1105,
272,
9351,
11117,
3690,
9160,
469,
23026,
1386,
469,
84,
63,
70,
93,
38,
5321,
84,
63,
67,
93,
35,
7,
881,
8189,
40,
14534,
72,
63,
70,
93,
38,
5321,
72,
63,
67,
93,
35,
491,
14534,
76,
63,
70,
93,
38,
5321,
76,
63,
67,
93,
35,
3171,
881,
1656,
869,
21704,
26,
469,
72,
453,
344,
1386,
469,
11530,
5285,
908,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: profitbricks_datacenter
short_description: Create or destroy a ProfitBricks Virtual Datacenter.
description:
- This is a simple module that supports creating or removing vDCs. A vDC is required before you can create servers. This module has a dependency
on profitbricks >= 1.0.0
version_added: "2.0"
options:
name:
description:
- The name of the virtual datacenter.
required: true
description:
description:
- The description of the virtual datacenter.
required: false
location:
description:
- The datacenter location.
required: false
default: us/las
choices: [ "us/las", "de/fra", "de/fkb" ]
subscription_user:
description:
- The ProfitBricks username. Overrides the PB_SUBSCRIPTION_ID environment variable.
required: false
subscription_password:
description:
- THe ProfitBricks password. Overrides the PB_PASSWORD environment variable.
required: false
wait:
description:
- wait for the datacenter to be created before returning
required: false
default: "yes"
type: bool
wait_timeout:
description:
- how long before wait gives up, in seconds
default: 600
state:
description:
- create or terminate datacenters
required: false
default: 'present'
choices: [ "present", "absent" ]
requirements: [ "profitbricks" ]
author: Matt Baldwin (baldwin@stackpointcloud.com)
'''
EXAMPLES = '''
# Create a Datacenter
- profitbricks_datacenter:
datacenter: Tardis One
wait_timeout: 500
# Destroy a Datacenter. This will remove all servers, volumes, and other objects in the datacenter.
- profitbricks_datacenter:
datacenter: Tardis One
wait_timeout: 500
state: absent
'''
import re
import time
HAS_PB_SDK = True
try:
from profitbricks.client import ProfitBricksService, Datacenter
except ImportError:
HAS_PB_SDK = False
from ansible.module_utils.basic import AnsibleModule
LOCATIONS = ['us/las',
'de/fra',
'de/fkb']
uuid_match = re.compile(
r'[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}', re.I)
def _wait_for_completion(profitbricks, promise, wait_timeout, msg):
if not promise:
return
wait_timeout = time.time() + wait_timeout
while wait_timeout > time.time():
time.sleep(5)
operation_result = profitbricks.get_request(
request_id=promise['requestId'],
status=True)
if operation_result['metadata']['status'] == "DONE":
return
elif operation_result['metadata']['status'] == "FAILED":
raise Exception(
'Request failed to complete ' + msg + ' "' + str(
promise['requestId']) + '" to complete.')
raise Exception(
'Timed out waiting for async operation ' + msg + ' "' + str(
promise['requestId']
) + '" to complete.')
def _remove_datacenter(module, profitbricks, datacenter):
try:
profitbricks.delete_datacenter(datacenter)
except Exception as e:
module.fail_json(msg="failed to remove the datacenter: %s" % str(e))
def create_datacenter(module, profitbricks):
"""
Creates a Datacenter
This will create a new Datacenter in the specified location.
module : AnsibleModule object
profitbricks: authenticated profitbricks object.
Returns:
True if a new datacenter was created, false otherwise
"""
name = module.params.get('name')
location = module.params.get('location')
description = module.params.get('description')
wait = module.params.get('wait')
wait_timeout = int(module.params.get('wait_timeout'))
i = Datacenter(
name=name,
location=location,
description=description
)
try:
datacenter_response = profitbricks.create_datacenter(datacenter=i)
if wait:
_wait_for_completion(profitbricks, datacenter_response,
wait_timeout, "_create_datacenter")
results = {
'datacenter_id': datacenter_response['id']
}
return results
except Exception as e:
module.fail_json(msg="failed to create the new datacenter: %s" % str(e))
def remove_datacenter(module, profitbricks):
"""
Removes a Datacenter.
This will remove a datacenter.
module : AnsibleModule object
profitbricks: authenticated profitbricks object.
Returns:
True if the datacenter was deleted, false otherwise
"""
name = module.params.get('name')
changed = False
if(uuid_match.match(name)):
_remove_datacenter(module, profitbricks, name)
changed = True
else:
datacenters = profitbricks.list_datacenters()
for d in datacenters['items']:
vdc = profitbricks.get_datacenter(d['id'])
if name == vdc['properties']['name']:
name = d['id']
_remove_datacenter(module, profitbricks, name)
changed = True
return changed
def main():
module = AnsibleModule(
argument_spec=dict(
name=dict(),
description=dict(),
location=dict(choices=LOCATIONS, default='us/las'),
subscription_user=dict(),
subscription_password=dict(no_log=True),
wait=dict(type='bool', default=True),
wait_timeout=dict(default=600),
state=dict(default='present'),
)
)
if not HAS_PB_SDK:
module.fail_json(msg='profitbricks required for this module')
if not module.params.get('subscription_user'):
module.fail_json(msg='subscription_user parameter is required')
if not module.params.get('subscription_password'):
module.fail_json(msg='subscription_password parameter is required')
subscription_user = module.params.get('subscription_user')
subscription_password = module.params.get('subscription_password')
profitbricks = ProfitBricksService(
username=subscription_user,
password=subscription_password)
state = module.params.get('state')
if state == 'absent':
if not module.params.get('name'):
module.fail_json(msg='name parameter is required deleting a virtual datacenter.')
try:
(changed) = remove_datacenter(module, profitbricks)
module.exit_json(
changed=changed)
except Exception as e:
module.fail_json(msg='failed to set datacenter state: %s' % str(e))
elif state == 'present':
if not module.params.get('name'):
module.fail_json(msg='name parameter is required for a new datacenter')
if not module.params.get('location'):
module.fail_json(msg='location parameter is required for a new datacenter')
try:
(datacenter_dict_array) = create_datacenter(module, profitbricks)
module.exit_json(**datacenter_dict_array)
except Exception as e:
module.fail_json(msg='failed to set datacenter state: %s' % str(e))
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1898,
26,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
32630,
30855,
63,
17770,
199,
3612,
63,
1802,
26,
2790,
503,
11972,
282,
2165,
3269,
34,
322,
5618,
13311,
3918,
4218,
14,
199,
1802,
26,
1362,
446,
961,
365,
282,
3486,
859,
626,
5171,
6425,
503,
12881,
373,
5196,
83,
14,
437,
373,
5196,
365,
1415,
2544,
1265,
883,
1218,
8037,
14,
961,
859,
965,
282,
5936,
2126,
641,
32630,
30855,
2356,
413,
14,
16,
14,
16,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
489,
446,
710,
536,
402,
314,
5791,
16606,
14,
272,
1415,
26,
2549,
523,
1369,
26,
272,
1369,
26,
489,
446,
710,
1369,
402,
314,
5791,
16606,
14,
272,
1415,
26,
3055,
523,
2909,
26,
272,
1369,
26,
489,
446,
710,
16606,
2909,
14,
272,
1415,
26,
3055,
272,
849,
26,
2739,
15,
12536,
272,
3415,
26,
359,
298,
527,
15,
12536,
401,
298,
271,
15,
21844,
401,
298,
271,
15,
70,
7862,
2,
1622,
523,
9966,
63,
751,
26,
272,
1369,
26,
489,
446,
710,
2165,
3269,
34,
322,
5618,
3434,
14,
31144,
314,
510,
34,
63,
6348,
10484,
1075,
63,
998,
3734,
1750,
14,
272,
1415,
26,
3055,
523,
9966,
63,
2060,
26,
272,
1369,
26,
489,
446,
377,
1966,
2165,
3269,
34,
322,
5618,
2505,
14,
31144,
314,
510,
34,
63,
9032,
3734,
1750,
14,
272,
1415,
26,
3055,
523,
3618,
26,
272,
1369,
26,
489,
446,
3618,
367,
314,
16606,
370,
506,
2737,
2544,
8152,
272,
1415,
26,
3055,
272,
849,
26,
298,
5066,
2,
272,
730,
26,
2155,
523,
3618,
63,
2593,
26,
272,
1369,
26,
489,
446,
4212,
1846,
2544,
3618,
10557,
1536,
12,
315,
4696,
272,
849,
26,
11624,
523,
1174,
26,
272,
1369,
26,
489,
446,
1218,
503,
15095,
666,
15660,
272,
1415,
26,
3055,
272,
849,
26,
283,
1881,
7,
272,
3415,
26,
359,
298,
1881,
401,
298,
5575,
2,
1622,
199,
199,
7538,
26,
359,
298,
496,
3269,
30855,
2,
1622,
199,
2502,
26,
31653,
23928,
68,
2676,
334,
4982,
68,
2676,
32,
2340,
1403,
4091,
14,
957,
9,
199,
2344,
199,
199,
8918,
275,
1449,
199,
199,
3,
2790,
282,
3918,
4218,
199,
13,
32630,
30855,
63,
17770,
26,
272,
16606,
26,
16017,
2297,
7309,
272,
3618,
63,
2593,
26,
6891,
199,
199,
3,
20547,
4813,
282,
3918,
4218,
14,
961,
911,
2813,
1006,
8037,
12,
12158,
12,
436,
1163,
2251,
315,
314,
16606,
14,
199,
13,
32630,
30855,
63,
17770,
26,
272,
16606,
26,
16017,
2297,
7309,
272,
3618,
63,
2593,
26,
6891,
272,
1174,
26,
9552,
199,
199,
2344,
199,
199,
646,
295,
199,
646,
900,
199,
199,
13533,
63,
13167,
63,
14939,
275,
715,
199,
893,
26,
272,
687,
32630,
30855,
14,
1258,
492,
2165,
3269,
34,
322,
5618,
3167,
12,
3918,
4218,
199,
2590,
3545,
26,
272,
7509,
63,
13167,
63,
14939,
275,
756,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
421,
199,
5752,
12969,
275,
788,
527,
15,
12536,
297,
1467,
283,
271,
15,
21844,
297,
1467,
283,
271,
15,
70,
7862,
418,
199,
199,
2580,
63,
1431,
275,
295,
14,
2014,
8,
272,
519,
22123,
87,
8194,
24,
17063,
7023,
87,
8194,
20,
17063,
7023,
87,
8194,
20,
17063,
7023,
87,
8194,
20,
17063,
7023,
87,
8194,
713,
7293,
295,
14,
41,
9,
421,
199,
318,
485,
2573,
63,
509,
63,
13207,
8,
496,
3269,
30855,
12,
8023,
572,
12,
3618,
63,
2593,
12,
1499,
304,
272,
340,
440,
8023,
572,
26,
267,
372,
272,
3618,
63,
2593,
275,
900,
14,
521,
342,
435,
3618,
63,
2593,
272,
1830,
3618,
63,
2593,
690,
900,
14,
521,
837,
267,
900,
14,
4532,
8,
21,
9,
267,
3439,
63,
1099,
275,
32630,
30855,
14,
362,
63,
1069,
8,
288,
1056,
63,
344,
29,
12741,
572,
459,
1069,
1304,
995,
288,
2004,
29,
549,
9,
398,
340,
3439,
63,
1099,
459,
2343,
2545,
1205,
418,
508,
298,
22162,
582,
288,
372,
267,
916,
3439,
63,
1099,
459,
2343,
2545,
1205,
418,
508,
298,
12299,
582,
288,
746,
2186,
8,
355,
283,
2017,
3405,
370,
4890,
283,
435,
1499,
435,
283,
3546,
435,
620,
8,
490,
8023,
572,
459,
1069,
1304,
1105,
435,
5522,
370,
4890,
2659,
339,
746,
2186,
8,
267,
283,
28682,
734,
10923,
367,
5316,
3439,
283,
435,
1499,
435,
283,
3546,
435,
620,
8,
288,
8023,
572,
459,
1069,
1304,
418,
267,
776,
435,
5522,
370,
4890,
2659,
421,
199,
318,
485,
2168,
63,
17770,
8,
578,
12,
32630,
30855,
12,
16606,
304,
272,
862,
26,
267,
32630,
30855,
14,
1807,
63,
17770,
8,
17770,
9,
272,
871,
2186,
465,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4892,
370,
2813,
314,
16606,
26,
450,
83,
2,
450,
620,
8,
69,
430,
421,
199,
318,
1218,
63,
17770,
8,
578,
12,
32630,
30855,
304,
272,
408,
272,
10560,
282,
3918,
4218,
339,
961,
911,
1218,
282,
892,
3918,
4218,
315,
314,
2013,
2909,
14,
339,
859,
520,
6953,
909,
272,
32630,
30855,
26,
15082,
32630,
30855,
909,
14,
339,
1803,
26,
267,
715,
340,
282,
892,
16606,
1990,
2737,
12,
3055,
4257,
272,
408,
272,
536,
275,
859,
14,
1162,
14,
362,
360,
354,
358,
272,
2909,
275,
859,
14,
1162,
14,
362,
360,
1985,
358,
272,
1369,
275,
859,
14,
1162,
14,
362,
360,
1802,
358,
272,
3618,
275,
859,
14,
1162,
14,
362,
360,
2573,
358,
272,
3618,
63,
2593,
275,
1109,
8,
578,
14,
1162,
14,
362,
360,
2573,
63,
2593
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1898,
26,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
32630,
30855,
63,
17770,
199,
3612,
63,
1802,
26,
2790,
503,
11972,
282,
2165,
3269,
34,
322,
5618,
13311,
3918,
4218,
14,
199,
1802,
26,
1362,
446,
961,
365,
282,
3486,
859,
626,
5171,
6425,
503,
12881,
373,
5196,
83,
14,
437,
373,
5196,
365,
1415,
2544,
1265,
883,
1218,
8037,
14,
961,
859,
965,
282,
5936,
2126,
641,
32630,
30855,
2356,
413,
14,
16,
14,
16,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
489,
446,
710,
536,
402,
314,
5791,
16606,
14,
272,
1415,
26,
2549,
523,
1369,
26,
272,
1369,
26,
489,
446,
710,
1369,
402,
314,
5791,
16606,
14,
272,
1415,
26,
3055,
523,
2909,
26,
272,
1369,
26,
489,
446,
710,
16606,
2909,
14,
272,
1415,
26,
3055,
272,
849,
26,
2739,
15,
12536,
272,
3415,
26,
359,
298,
527,
15,
12536,
401,
298,
271,
15,
21844,
401,
298,
271,
15,
70,
7862,
2,
1622,
523,
9966,
63,
751,
26,
272,
1369,
26,
489,
446,
710,
2165,
3269,
34,
322,
5618,
3434,
14,
31144,
314,
510,
34,
63,
6348,
10484,
1075,
63,
998,
3734,
1750,
14,
272,
1415,
26,
3055,
523,
9966,
63,
2060,
26,
272,
1369,
26,
489,
446,
377,
1966,
2165,
3269,
34,
322,
5618,
2505,
14,
31144,
314,
510,
34,
63,
9032,
3734,
1750,
14,
272,
1415,
26,
3055,
523,
3618,
26,
272,
1369,
26,
489,
446,
3618,
367,
314,
16606,
370,
506,
2737,
2544,
8152,
272,
1415,
26,
3055,
272,
849,
26,
298,
5066,
2,
272,
730,
26,
2155,
523,
3618,
63,
2593,
26,
272,
1369,
26,
489,
446,
4212,
1846,
2544,
3618,
10557,
1536,
12,
315,
4696,
272,
849,
26,
11624,
523,
1174,
26,
272,
1369,
26,
489,
446,
1218,
503,
15095,
666,
15660,
272,
1415,
26,
3055,
272,
849,
26,
283,
1881,
7,
272,
3415,
26,
359,
298,
1881,
401,
298,
5575,
2,
1622,
199,
199,
7538,
26,
359,
298,
496,
3269,
30855,
2,
1622,
199,
2502,
26,
31653,
23928,
68,
2676,
334,
4982,
68,
2676,
32,
2340,
1403,
4091,
14,
957,
9,
199,
2344,
199,
199,
8918,
275,
1449,
199,
199,
3,
2790,
282,
3918,
4218,
199,
13,
32630,
30855,
63,
17770,
26,
272,
16606,
26,
16017,
2297,
7309,
272,
3618,
63,
2593,
26,
6891,
199,
199,
3,
20547,
4813,
282,
3918,
4218,
14,
961,
911,
2813,
1006,
8037,
12,
12158,
12,
436,
1163,
2251,
315,
314,
16606,
14,
199,
13,
32630,
30855,
63,
17770,
26,
272,
16606,
26,
16017,
2297,
7309,
272,
3618,
63,
2593,
26,
6891,
272,
1174,
26,
9552,
199,
199,
2344,
199,
199,
646,
295,
199,
646,
900,
199,
199,
13533,
63,
13167,
63,
14939,
275,
715,
199,
893,
26,
272,
687,
32630,
30855,
14,
1258,
492,
2165,
3269,
34,
322,
5618,
3167,
12,
3918,
4218,
199,
2590,
3545,
26,
272,
7509,
63,
13167,
63,
14939,
275,
756,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
421,
199,
5752,
12969,
275,
788,
527,
15,
12536,
297,
1467,
283,
271,
15,
21844,
297,
1467,
283,
271,
15,
70,
7862,
418,
199,
199,
2580,
63,
1431,
275,
295,
14,
2014,
8,
272,
519,
22123,
87,
8194,
24,
17063,
7023,
87,
8194,
20,
17063,
7023,
87,
8194,
20,
17063,
7023,
87,
8194,
20,
17063,
7023,
87,
8194,
713,
7293,
295,
14,
41,
9,
421,
199,
318,
485,
2573,
63,
509,
63,
13207,
8,
496,
3269,
30855,
12,
8023,
572,
12,
3618,
63,
2593,
12,
1499,
304,
272,
340,
440,
8023,
572,
26,
267,
372,
272,
3618,
63,
2593,
275,
900,
14,
521,
342,
435,
3618,
63,
2593,
272,
1830,
3618,
63,
2593,
690,
900,
14,
521,
837,
267,
900,
14,
4532,
8,
21,
9,
267,
3439,
63,
1099,
275,
32630,
30855,
14,
362,
63,
1069,
8,
288,
1056,
63,
344,
29,
12741,
572,
459,
1069,
1304,
995,
288,
2004,
29,
549,
9,
398,
340,
3439,
63,
1099,
459,
2343,
2545,
1205,
418,
508,
298,
22162,
582,
288,
372,
267,
916,
3439,
63,
1099,
459,
2343,
2545,
1205,
418,
508,
298,
12299,
582,
288,
746,
2186,
8,
355,
283,
2017,
3405,
370,
4890,
283,
435,
1499,
435,
283,
3546,
435,
620,
8,
490,
8023,
572,
459,
1069,
1304,
1105,
435,
5522,
370,
4890,
2659,
339,
746,
2186,
8,
267,
283,
28682,
734,
10923,
367,
5316,
3439,
283,
435,
1499,
435,
283,
3546,
435,
620,
8,
288,
8023,
572,
459,
1069,
1304,
418,
267,
776,
435,
5522,
370,
4890,
2659,
421,
199,
318,
485,
2168,
63,
17770,
8,
578,
12,
32630,
30855,
12,
16606,
304,
272,
862,
26,
267,
32630,
30855,
14,
1807,
63,
17770,
8,
17770,
9,
272,
871,
2186,
465,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4892,
370,
2813,
314,
16606,
26,
450,
83,
2,
450,
620,
8,
69,
430,
421,
199,
318,
1218,
63,
17770,
8,
578,
12,
32630,
30855,
304,
272,
408,
272,
10560,
282,
3918,
4218,
339,
961,
911,
1218,
282,
892,
3918,
4218,
315,
314,
2013,
2909,
14,
339,
859,
520,
6953,
909,
272,
32630,
30855,
26,
15082,
32630,
30855,
909,
14,
339,
1803,
26,
267,
715,
340,
282,
892,
16606,
1990,
2737,
12,
3055,
4257,
272,
408,
272,
536,
275,
859,
14,
1162,
14,
362,
360,
354,
358,
272,
2909,
275,
859,
14,
1162,
14,
362,
360,
1985,
358,
272,
1369,
275,
859,
14,
1162,
14,
362,
360,
1802,
358,
272,
3618,
275,
859,
14,
1162,
14,
362,
360,
2573,
358,
272,
3618,
63,
2593,
275,
1109,
8,
578,
14,
1162,
14,
362,
360,
2573,
63,
2593,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
anryko/ansible
|
lib/ansible/modules/cloud/openstack/os_keystone_domain.py
|
52
|
5166
|
#!/usr/bin/python
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: os_keystone_domain
short_description: Manage OpenStack Identity Domains
author:
- Monty Taylor (@emonty)
- Haneef Ali (@haneefs)
extends_documentation_fragment: openstack
version_added: "2.1"
description:
- Create, update, or delete OpenStack Identity domains. If a domain
with the supplied name already exists, it will be updated with the
new description and enabled attributes.
options:
name:
description:
- Name that has to be given to the instance
required: true
description:
description:
- Description of the domain
enabled:
description:
- Is the domain enabled
type: bool
default: 'yes'
state:
description:
- Should the resource be present or absent.
choices: [present, absent]
default: present
availability_zone:
description:
- Ignored. Present for backwards compatibility
requirements:
- "python >= 2.7"
- "openstacksdk"
'''
EXAMPLES = '''
# Create a domain
- os_keystone_domain:
cloud: mycloud
state: present
name: demo
description: Demo Domain
# Delete a domain
- os_keystone_domain:
cloud: mycloud
state: absent
name: demo
'''
RETURN = '''
domain:
description: Dictionary describing the domain.
returned: On success when I(state) is 'present'
type: complex
contains:
id:
description: Domain ID.
type: str
sample: "474acfe5-be34-494c-b339-50f06aa143e4"
name:
description: Domain name.
type: str
sample: "demo"
description:
description: Domain description.
type: str
sample: "Demo Domain"
enabled:
description: Domain description.
type: bool
sample: True
id:
description: The domain ID.
returned: On success when I(state) is 'present'
type: str
sample: "474acfe5-be34-494c-b339-50f06aa143e4"
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _needs_update(module, domain):
if module.params['description'] is not None and \
domain.description != module.params['description']:
return True
if domain.enabled != module.params['enabled']:
return True
return False
def _system_state_change(module, domain):
state = module.params['state']
if state == 'absent' and domain:
return True
if state == 'present':
if domain is None:
return True
return _needs_update(module, domain)
return False
def main():
argument_spec = openstack_full_argument_spec(
name=dict(required=True),
description=dict(default=None),
enabled=dict(default=True, type='bool'),
state=dict(default='present', choices=['absent', 'present']),
)
module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec,
supports_check_mode=True,
**module_kwargs)
name = module.params['name']
description = module.params['description']
enabled = module.params['enabled']
state = module.params['state']
sdk, cloud = openstack_cloud_from_module(module)
try:
domains = cloud.search_domains(filters=dict(name=name))
if len(domains) > 1:
module.fail_json(msg='Domain name %s is not unique' % name)
elif len(domains) == 1:
domain = domains[0]
else:
domain = None
if module.check_mode:
module.exit_json(changed=_system_state_change(module, domain))
if state == 'present':
if domain is None:
domain = cloud.create_domain(
name=name, description=description, enabled=enabled)
changed = True
else:
if _needs_update(module, domain):
domain = cloud.update_domain(
domain.id, name=name, description=description,
enabled=enabled)
changed = True
else:
changed = False
module.exit_json(changed=changed, domain=domain, id=domain.id)
elif state == 'absent':
if domain is None:
changed = False
else:
cloud.delete_domain(domain.id)
changed = True
module.exit_json(changed=changed)
except sdk.exceptions.OpenStackCloudException as e:
module.fail_json(msg=str(e))
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1898,
334,
67,
9,
6900,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
747,
63,
19143,
63,
2261,
199,
3612,
63,
1802,
26,
14944,
14260,
22034,
14061,
83,
199,
2502,
26,
272,
446,
10953,
369,
377,
1187,
25339,
8593,
69,
2106,
369,
9,
272,
446,
869,
290,
1024,
70,
15170,
8593,
19262,
1024,
2319,
9,
199,
11036,
63,
9970,
63,
7677,
26,
13869,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
1802,
26,
272,
446,
2790,
12,
1678,
12,
503,
3145,
14260,
22034,
14006,
14,
982,
282,
2881,
489,
543,
314,
6841,
536,
2575,
3495,
12,
652,
911,
506,
4588,
543,
314,
489,
892,
1369,
436,
5223,
3004,
14,
199,
1419,
26,
2043,
536,
26,
1362,
1369,
26,
267,
446,
2812,
626,
965,
370,
506,
1627,
370,
314,
1256,
1362,
1415,
26,
2549,
2043,
1369,
26,
1362,
1369,
26,
267,
446,
11994,
402,
314,
2881,
2043,
5223,
26,
1362,
1369,
26,
267,
446,
6596,
314,
2881,
5223,
1362,
730,
26,
2155,
1362,
849,
26,
283,
5066,
7,
2043,
1174,
26,
1362,
1369,
26,
2126,
446,
7719,
314,
2073,
506,
3451,
503,
9552,
14,
1362,
3415,
26,
359,
1881,
12,
9552,
61,
1362,
849,
26,
3451,
2043,
14962,
63,
2619,
26,
1362,
1369,
26,
2126,
446,
27662,
14,
5543,
1150,
367,
8552,
7163,
199,
7538,
26,
272,
446,
298,
1548,
2356,
499,
14,
23,
2,
272,
446,
298,
8512,
9277,
2,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2790,
282,
2881,
199,
13,
747,
63,
19143,
63,
2261,
26,
1362,
8002,
26,
3002,
4091,
1362,
1174,
26,
3451,
1362,
536,
26,
14779,
1362,
1369,
26,
28939,
14061,
199,
199,
3,
8496,
282,
2881,
199,
13,
747,
63,
19143,
63,
2261,
26,
1362,
8002,
26,
3002,
4091,
1362,
1174,
26,
9552,
1362,
536,
26,
14779,
199,
2344,
199,
199,
9677,
275,
1449,
199,
2261,
26,
272,
1369,
26,
11932,
13660,
314,
2881,
14,
272,
2138,
26,
4068,
3182,
1380,
473,
8,
929,
9,
365,
283,
1881,
7,
272,
730,
26,
6114,
272,
3509,
26,
267,
1305,
26,
288,
1369,
26,
14061,
2870,
14,
288,
730,
26,
620,
288,
2690,
26,
298,
13818,
645,
771,
21,
13,
1235,
1082,
13,
19422,
67,
13,
66,
11870,
13,
1400,
70,
1690,
2158,
12289,
69,
20,
2,
267,
536,
26,
288,
1369,
26,
14061,
536,
14,
288,
730,
26,
620,
288,
2690,
26,
298,
8768,
2,
267,
1369,
26,
288,
1369,
26,
14061,
1369,
14,
288,
730,
26,
620,
288,
2690,
26,
298,
21493,
14061,
2,
267,
5223,
26,
288,
1369,
26,
14061,
1369,
14,
288,
730,
26,
2155,
288,
2690,
26,
715,
199,
199,
344,
26,
272,
1369,
26,
710,
2881,
2870,
14,
272,
2138,
26,
4068,
3182,
1380,
473,
8,
929,
9,
365,
283,
1881,
7,
272,
730,
26,
620,
272,
2690,
26,
298,
13818,
645,
771,
21,
13,
1235,
1082,
13,
19422,
67,
13,
66,
11870,
13,
1400,
70,
1690,
2158,
12289,
69,
20,
2,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
8512,
492,
13869,
63,
2861,
63,
2094,
63,
1650,
12,
13869,
63,
578,
63,
958,
12,
13869,
63,
4091,
63,
504,
63,
578,
421,
199,
318,
485,
10065,
63,
873,
8,
578,
12,
2881,
304,
272,
340,
859,
14,
1162,
459,
1802,
418,
365,
440,
488,
436,
971,
2126,
2881,
14,
1802,
1137,
859,
14,
1162,
459,
1802,
2565,
267,
372,
715,
272,
340,
2881,
14,
3827,
1137,
859,
14,
1162,
459,
3827,
2565,
267,
372,
715,
272,
372,
756,
421,
199,
318,
485,
2253,
63,
929,
63,
1461,
8,
578,
12,
2881,
304,
272,
1174,
275,
859,
14,
1162,
459,
929,
418,
272,
340,
1174,
508,
283,
5575,
7,
436,
2881,
26,
267,
372,
715,
339,
340,
1174,
508,
283,
1881,
356,
267,
340,
2881,
365,
488,
26,
288,
372,
715,
267,
372,
485,
10065,
63,
873,
8,
578,
12,
2881,
9,
339,
372,
756,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
13869,
63,
2861,
63,
2094,
63,
1650,
8,
267,
536,
29,
807,
8,
2427,
29,
549,
395,
267,
1369,
29,
807,
8,
885,
29,
403,
395,
267,
5223,
29,
807,
8,
885,
29,
549,
12,
730,
534,
2245,
659,
267,
1174,
29,
807,
8,
885,
534,
1881,
297,
3415,
2968,
5575,
297,
283,
1881,
3815,
272,
776,
339,
859,
63,
958,
275,
13869,
63,
578,
63,
958,
342,
272,
859,
275,
6953,
8,
2094,
63,
1650,
12,
2574,
5171,
63,
1074,
63,
632,
29,
549,
12,
2574,
1011,
578,
63,
958,
9,
339,
536,
275,
859,
14,
1162,
459,
354,
418,
272,
1369,
275,
859,
14,
1162,
459,
1802,
418,
272,
5223,
275,
859,
14,
1162,
459,
3827,
418,
272,
1174,
275,
859,
14,
1162,
459,
929,
418,
339,
13628,
12,
8002,
275,
13869,
63,
4091,
63,
504,
63,
578,
8,
578,
9,
272,
862,
26,
398,
14006,
275,
8002,
14,
1733,
63,
9756,
8,
4273,
29,
807,
8,
354,
29,
354,
430,
398,
340,
822,
8,
9756,
9,
690,
413,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
534,
7705,
536,
450,
83,
365,
440,
3747,
7,
450,
536,
9,
267,
916,
822,
8,
9756,
9,
508,
413,
26,
288,
2881,
275,
14006,
59,
16,
61,
267,
587,
26,
288,
2881,
275,
488,
398,
340,
859,
14,
1074,
63,
632,
26,
288,
859,
14,
2224,
63,
1001,
8,
2489,
3699,
2253,
63,
929,
63,
1461,
8,
578,
12,
2881,
430,
398,
340,
1174,
508,
283,
1881,
356,
288,
340,
2881
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1898,
334,
67,
9,
6900,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
747,
63,
19143,
63,
2261,
199,
3612,
63,
1802,
26,
14944,
14260,
22034,
14061,
83,
199,
2502,
26,
272,
446,
10953,
369,
377,
1187,
25339,
8593,
69,
2106,
369,
9,
272,
446,
869,
290,
1024,
70,
15170,
8593,
19262,
1024,
2319,
9,
199,
11036,
63,
9970,
63,
7677,
26,
13869,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
1802,
26,
272,
446,
2790,
12,
1678,
12,
503,
3145,
14260,
22034,
14006,
14,
982,
282,
2881,
489,
543,
314,
6841,
536,
2575,
3495,
12,
652,
911,
506,
4588,
543,
314,
489,
892,
1369,
436,
5223,
3004,
14,
199,
1419,
26,
2043,
536,
26,
1362,
1369,
26,
267,
446,
2812,
626,
965,
370,
506,
1627,
370,
314,
1256,
1362,
1415,
26,
2549,
2043,
1369,
26,
1362,
1369,
26,
267,
446,
11994,
402,
314,
2881,
2043,
5223,
26,
1362,
1369,
26,
267,
446,
6596,
314,
2881,
5223,
1362,
730,
26,
2155,
1362,
849,
26,
283,
5066,
7,
2043,
1174,
26,
1362,
1369,
26,
2126,
446,
7719,
314,
2073,
506,
3451,
503,
9552,
14,
1362,
3415,
26,
359,
1881,
12,
9552,
61,
1362,
849,
26,
3451,
2043,
14962,
63,
2619,
26,
1362,
1369,
26,
2126,
446,
27662,
14,
5543,
1150,
367,
8552,
7163,
199,
7538,
26,
272,
446,
298,
1548,
2356,
499,
14,
23,
2,
272,
446,
298,
8512,
9277,
2,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2790,
282,
2881,
199,
13,
747,
63,
19143,
63,
2261,
26,
1362,
8002,
26,
3002,
4091,
1362,
1174,
26,
3451,
1362,
536,
26,
14779,
1362,
1369,
26,
28939,
14061,
199,
199,
3,
8496,
282,
2881,
199,
13,
747,
63,
19143,
63,
2261,
26,
1362,
8002,
26,
3002,
4091,
1362,
1174,
26,
9552,
1362,
536,
26,
14779,
199,
2344,
199,
199,
9677,
275,
1449,
199,
2261,
26,
272,
1369,
26,
11932,
13660,
314,
2881,
14,
272,
2138,
26,
4068,
3182,
1380,
473,
8,
929,
9,
365,
283,
1881,
7,
272,
730,
26,
6114,
272,
3509,
26,
267,
1305,
26,
288,
1369,
26,
14061,
2870,
14,
288,
730,
26,
620,
288,
2690,
26,
298,
13818,
645,
771,
21,
13,
1235,
1082,
13,
19422,
67,
13,
66,
11870,
13,
1400,
70,
1690,
2158,
12289,
69,
20,
2,
267,
536,
26,
288,
1369,
26,
14061,
536,
14,
288,
730,
26,
620,
288,
2690,
26,
298,
8768,
2,
267,
1369,
26,
288,
1369,
26,
14061,
1369,
14,
288,
730,
26,
620,
288,
2690,
26,
298,
21493,
14061,
2,
267,
5223,
26,
288,
1369,
26,
14061,
1369,
14,
288,
730,
26,
2155,
288,
2690,
26,
715,
199,
199,
344,
26,
272,
1369,
26,
710,
2881,
2870,
14,
272,
2138,
26,
4068,
3182,
1380,
473,
8,
929,
9,
365,
283,
1881,
7,
272,
730,
26,
620,
272,
2690,
26,
298,
13818,
645,
771,
21,
13,
1235,
1082,
13,
19422,
67,
13,
66,
11870,
13,
1400,
70,
1690,
2158,
12289,
69,
20,
2,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
8512,
492,
13869,
63,
2861,
63,
2094,
63,
1650,
12,
13869,
63,
578,
63,
958,
12,
13869,
63,
4091,
63,
504,
63,
578,
421,
199,
318,
485,
10065,
63,
873,
8,
578,
12,
2881,
304,
272,
340,
859,
14,
1162,
459,
1802,
418,
365,
440,
488,
436,
971,
2126,
2881,
14,
1802,
1137,
859,
14,
1162,
459,
1802,
2565,
267,
372,
715,
272,
340,
2881,
14,
3827,
1137,
859,
14,
1162,
459,
3827,
2565,
267,
372,
715,
272,
372,
756,
421,
199,
318,
485,
2253,
63,
929,
63,
1461,
8,
578,
12,
2881,
304,
272,
1174,
275,
859,
14,
1162,
459,
929,
418,
272,
340,
1174,
508,
283,
5575,
7,
436,
2881,
26,
267,
372,
715,
339,
340,
1174,
508,
283,
1881,
356,
267,
340,
2881,
365,
488,
26,
288,
372,
715,
267,
372,
485,
10065,
63,
873,
8,
578,
12,
2881,
9,
339,
372,
756,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
13869,
63,
2861,
63,
2094,
63,
1650,
8,
267,
536,
29,
807,
8,
2427,
29,
549,
395,
267,
1369,
29,
807,
8,
885,
29,
403,
395,
267,
5223,
29,
807,
8,
885,
29,
549,
12,
730,
534,
2245,
659,
267,
1174,
29,
807,
8,
885,
534,
1881,
297,
3415,
2968,
5575,
297,
283,
1881,
3815,
272,
776,
339,
859,
63,
958,
275,
13869,
63,
578,
63,
958,
342,
272,
859,
275,
6953,
8,
2094,
63,
1650,
12,
2574,
5171,
63,
1074,
63,
632,
29,
549,
12,
2574,
1011,
578,
63,
958,
9,
339,
536,
275,
859,
14,
1162,
459,
354,
418,
272,
1369,
275,
859,
14,
1162,
459,
1802,
418,
272,
5223,
275,
859,
14,
1162,
459,
3827,
418,
272,
1174,
275,
859,
14,
1162,
459,
929,
418,
339,
13628,
12,
8002,
275,
13869,
63,
4091,
63,
504,
63,
578,
8,
578,
9,
272,
862,
26,
398,
14006,
275,
8002,
14,
1733,
63,
9756,
8,
4273,
29,
807,
8,
354,
29,
354,
430,
398,
340,
822,
8,
9756,
9,
690,
413,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
534,
7705,
536,
450,
83,
365,
440,
3747,
7,
450,
536,
9,
267,
916,
822,
8,
9756,
9,
508,
413,
26,
288,
2881,
275,
14006,
59,
16,
61,
267,
587,
26,
288,
2881,
275,
488,
398,
340,
859,
14,
1074,
63,
632,
26,
288,
859,
14,
2224,
63,
1001,
8,
2489,
3699,
2253,
63,
929,
63,
1461,
8,
578,
12,
2881,
430,
398,
340,
1174,
508,
283,
1881,
356,
288,
340,
2881,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
drpeteb/scipy
|
scipy/weave/ast_tools.py
|
97
|
7418
|
from __future__ import absolute_import, print_function
import token
import symbol
import parser
def issequence(t):
return isinstance(t, (list, tuple))
def int_to_symbol(i):
""" Convert numeric symbol or token to a desriptive name.
"""
try:
return symbol.sym_name[i]
except KeyError:
return token.tok_name[i]
def translate_symbols(ast_tuple):
""" Translate numeric grammar symbols in an ast_tuple descriptive names.
This simply traverses the tree converting any integer value to values
found in symbol.sym_name or token.tok_name.
"""
new_list = []
for item in ast_tuple:
if isinstance(item, int):
new_list.append(int_to_symbol(item))
elif issequence(item):
new_list.append(translate_symbols(item))
else:
new_list.append(item)
if isinstance(ast_tuple, tuple):
return tuple(new_list)
else:
return new_list
def ast_to_string(ast_seq):
"""* Traverse an ast tree sequence, printing out all leaf nodes.
This effectively rebuilds the expression the tree was built
from. I guess its probably missing whitespace. How bout
indent stuff and new lines? Haven't checked this since we're
currently only dealing with simple expressions.
*"""
output = ''
for item in ast_seq:
if isinstance(item, str):
output = output + item
elif issequence(item):
output = output + ast_to_string(item)
return output
def build_atom(expr_string):
""" Build an ast for an atom from the given expr string.
If expr_string is not a string, it is converted to a string
before parsing to an ast_tuple.
"""
# the [1][1] indexing below starts atoms at the third level
# deep in the resulting parse tree. parser.expr will return
# a tree rooted with eval_input -> test_list -> test ...
# I'm considering test to be the root of atom symbols.
# It might be a better idea to move down a little in the
# parse tree. Any benefits? Right now, this works fine.
if isinstance(expr_string, str):
ast = parser.expr(expr_string).totuple()[1][1]
else:
ast = parser.expr(repr(expr_string)).totuple()[1][1]
return ast
def atom_tuple(expr_string):
return build_atom(expr_string)
def atom_list(expr_string):
return tuples_to_lists(build_atom(expr_string))
def find_first_pattern(ast_tuple,pattern_list):
"""* Find the first occurrence of a pattern one of a list of patterns
in ast_tuple.
Used for testing at the moment.
ast_tuple -- tuple or list created by ast.totuple() or ast.tolist().
pattern_list -- A single pattern or list of patterns to search
for in the ast_tuple. If a single pattern is
used, it MUST BE A IN A TUPLE format.
Returns:
found -- true/false indicating whether pattern was found
data -- dictionary of data from first matching pattern in tree.
(see match function by Jeremy Hylton).
*"""
found,data = 0,{}
# convert to a list if input wasn't a list
if not isinstance(pattern_list, list):
pattern_list = [pattern_list]
# look for any of the patterns in a list of patterns
for pattern in pattern_list:
found,data = match(pattern,ast_tuple)
if found:
break
# if we didn't find the pattern, search sub-trees of the parse tree
if not found:
for item in ast_tuple:
if issequence(item):
# only search sub items if they are a list or tuple.
found, data = find_first_pattern(item,pattern_list)
if found:
break
return found,data
name_pattern = (token.NAME, ['var'])
def remove_duplicates(lst):
output = []
for item in lst:
if item not in output:
output.append(item)
return output
reserved_names = ['sin']
def remove_reserved_names(lst):
""" These are functions names -- don't create variables for them
There is a more reobust approach, but this ought to work pretty
well.
"""
output = []
for item in lst:
if item not in reserved_names:
output.append(item)
return output
def harvest_variables(ast_list):
""" Retrieve all the variables that need to be defined.
"""
variables = []
if issequence(ast_list):
found,data = match(name_pattern,ast_list)
if found:
variables.append(data['var'])
for item in ast_list:
if issequence(item):
variables.extend(harvest_variables(item))
variables = remove_duplicates(variables)
variables = remove_reserved_names(variables)
return variables
def match(pattern, data, vars=None):
"""match `data' to `pattern', with variable extraction.
pattern
Pattern to match against, possibly containing variables.
data
Data to be checked and against which variables are extracted.
vars
Dictionary of variables which have already been found. If not
provided, an empty dictionary is created.
The `pattern' value may contain variables of the form ['varname'] which
are allowed to match anything. The value that is matched is returned as
part of a dictionary which maps 'varname' to the matched value. 'varname'
is not required to be a string object, but using strings makes patterns
and the code which uses them more readable.
This function returns two values: a boolean indicating whether a match
was found and a dictionary mapping variable names to their associated
values.
From the Demo/Parser/example.py file
"""
if vars is None:
vars = {}
if isinstance(pattern, list): # 'variables' are ['varname']
vars[pattern[0]] = data
return 1, vars
if not isinstance(pattern, tuple):
return (pattern == data), vars
if len(data) != len(pattern):
return 0, vars
for pattern, data in zip(pattern, data):
same, vars = match(pattern, data, vars)
if not same:
break
return same, vars
def tuples_to_lists(ast_tuple):
""" Convert an ast object tree in tuple form to list form.
"""
if not issequence(ast_tuple):
return ast_tuple
new_list = []
for item in ast_tuple:
new_list.append(tuples_to_lists(item))
return new_list
"""
A little tree I built to help me understand the parse trees.
-----------303------------------------------
| |
304 -------------------------307-------------------------
| | | | | |
1 'result' 9 '[' 308 12 ',' 308 10 ']'
| |
---------309-------- -----309--------
| | | |
291|304 291|304 291|304 |
| | | |
1 'a1' 11 ':' 1 'a2' 2 '10' 11 ':'
"""
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
1526,
199,
646,
5272,
199,
646,
1798,
421,
199,
318,
365,
4041,
8,
84,
304,
272,
372,
1228,
8,
84,
12,
334,
513,
12,
2008,
430,
421,
199,
318,
1109,
63,
475,
63,
5155,
8,
73,
304,
272,
408,
7905,
8950,
5272,
503,
1526,
370,
282,
18618,
322,
21701,
536,
14,
272,
408,
272,
862,
26,
267,
372,
5272,
14,
3840,
63,
354,
59,
73,
61,
272,
871,
4067,
26,
267,
372,
1526,
14,
9305,
63,
354,
59,
73,
61,
421,
199,
318,
9028,
63,
7450,
8,
1810,
63,
2960,
304,
272,
408,
25540,
8950,
12528,
6698,
315,
376,
6073,
63,
2960,
30262,
1561,
14,
398,
961,
9329,
1468,
422,
874,
314,
3123,
13806,
1263,
3000,
574,
370,
1338,
267,
1911,
315,
5272,
14,
3840,
63,
354,
503,
1526,
14,
9305,
63,
354,
14,
272,
408,
272,
892,
63,
513,
275,
942,
272,
367,
1242,
315,
6073,
63,
2960,
26,
267,
340,
1228,
8,
1053,
12,
1109,
304,
288,
892,
63,
513,
14,
740,
8,
442,
63,
475,
63,
5155,
8,
1053,
430,
267,
916,
365,
4041,
8,
1053,
304,
288,
892,
63,
513,
14,
740,
8,
5275,
63,
7450,
8,
1053,
430,
267,
587,
26,
288,
892,
63,
513,
14,
740,
8,
1053,
9,
272,
340,
1228,
8,
1810,
63,
2960,
12,
2008,
304,
267,
372,
2008,
8,
1222,
63,
513,
9,
272,
587,
26,
267,
372,
892,
63,
513,
421,
199,
318,
6073,
63,
475,
63,
875,
8,
1810,
63,
3610,
304,
272,
408,
10,
12643,
2077,
376,
6073,
3123,
3414,
12,
16116,
734,
1006,
11747,
3380,
14,
13359,
961,
27881,
295,
10838,
314,
3965,
314,
3123,
1990,
6137,
268,
687,
14,
221,
473,
9519,
2399,
8646,
4124,
8139,
14,
221,
7494,
330,
548,
268,
4363,
8292,
436,
892,
2385,
31,
221,
869,
15556,
1133,
7923,
642,
3967,
781,
3984,
268,
5544,
1454,
23654,
543,
3486,
8455,
14,
272,
627,
624,
272,
1072,
275,
2125,
272,
367,
1242,
315,
6073,
63,
3610,
26,
267,
340,
1228,
8,
1053,
12,
620,
304,
288,
1072,
275,
1072,
435,
1242,
267,
916,
365,
4041,
8,
1053,
304,
288,
1072,
275,
1072,
435,
6073,
63,
475,
63,
875,
8,
1053,
9,
272,
372,
1072,
421,
199,
318,
1900,
63,
4188,
8,
3684,
63,
875,
304,
272,
408,
6516,
376,
6073,
367,
376,
6222,
687,
314,
1627,
5348,
1059,
14,
398,
982,
5348,
63,
875,
365,
440,
282,
1059,
12,
652,
365,
6702,
370,
282,
1059,
267,
2544,
6057,
370,
376,
6073,
63,
2960,
14,
272,
408,
272,
327,
314,
359,
17,
1527,
17,
61,
16356,
5084,
9174,
14503,
737,
314,
10919,
2166,
272,
327,
13217,
315,
314,
9183,
2198,
3123,
14,
221,
1798,
14,
3684,
911,
372,
272,
327,
282,
3123,
882,
5731,
543,
3468,
63,
1210,
1035,
511,
63,
513,
1035,
511,
2263,
272,
327,
473,
6704,
11201,
316,
511,
370,
506,
314,
1738,
402,
6222,
6698,
14,
272,
327,
2779,
5594,
506,
282,
8034,
16819,
370,
4057,
3224,
282,
12050,
315,
314,
272,
327,
2198,
3123,
14,
6184,
22477,
14948,
31,
20854,
3063,
12,
642,
5419,
15701,
14,
272,
340,
1228,
8,
3684,
63,
875,
12,
620,
304,
267,
6073,
275,
1798,
14,
3684,
8,
3684,
63,
875,
680,
13280,
1363,
3430,
17,
1527,
17,
61,
272,
587,
26,
267,
6073,
275,
1798,
14,
3684,
8,
2722,
8,
3684,
63,
875,
4992,
13280,
1363,
3430,
17,
1527,
17,
61,
272,
372,
6073,
421,
199,
318,
6222,
63,
2960,
8,
3684,
63,
875,
304,
272,
372,
1900,
63,
4188,
8,
3684,
63,
875,
9,
421,
199,
318,
6222,
63,
513,
8,
3684,
63,
875,
304,
272,
372,
6346,
63,
475,
63,
6717,
8,
1506,
63,
4188,
8,
3684,
63,
875,
430,
421,
199,
318,
2342,
63,
2246,
63,
3401,
8,
1810,
63,
2960,
12,
3401,
63,
513,
304,
272,
408,
10,
6668,
314,
1642,
23101,
402,
282,
3851,
1373,
402,
282,
769,
402,
7970,
267,
315,
6073,
63,
2960,
14,
398,
8051,
367,
5343,
737,
314,
12427,
14,
398,
6073,
63,
2960,
259,
1553,
2008,
503,
769,
2737,
701,
6073,
14,
13280,
1363,
342,
503,
6073,
14,
13633,
1252,
267,
3851,
63,
513,
1553,
437,
2849,
3851,
503,
769,
402,
7970,
370,
2754,
717,
367,
315,
314,
6073,
63,
2960,
14,
221,
982,
282,
2849,
3851,
365,
717,
1202,
12,
652,
18095,
6262,
437,
1621,
437,
377,
28970,
1475,
14,
267,
1803,
26,
288,
1911,
1553,
2549,
15,
3910,
9297,
3775,
3851,
1990,
1911,
288,
666,
221,
1553,
2600,
402,
666,
687,
1642,
4877,
3851,
315,
3123,
14,
2151,
334,
3239,
1336,
805,
701,
1603,
69,
264,
1662,
29591,
76,
1860,
680,
272,
627,
624,
272,
1911,
12,
576,
275,
378,
12,
2440,
339,
327,
3957,
370,
282,
769,
340,
1324,
17373,
1133,
282,
769,
272,
340,
440,
1228,
8,
3401,
63,
513,
12,
769,
304,
267,
3851,
63,
513,
275,
359,
3401,
63,
513,
61,
339,
327,
3648,
367,
1263,
402,
314,
7970,
315,
282,
769,
402,
7970,
272,
367,
3851,
315,
3851,
63,
513,
26,
267,
1911,
12,
576,
275,
1336,
8,
3401,
12,
1810,
63,
2960,
9,
267,
340,
1911,
26,
288,
2059,
339,
327,
340,
781,
9980,
1133,
2342,
314,
3851,
12,
2754,
1007,
13,
14635,
402,
314,
2198,
3123,
272,
340,
440,
1911,
26,
267,
367,
1242,
315,
6073,
63,
2960,
26,
288,
340,
365,
4041,
8,
1053,
304,
355,
327,
1454,
2754,
1007,
2974,
340,
2985,
787,
282,
769,
503,
2008,
14,
355,
1911,
12,
666,
275,
2342,
63,
2246,
63,
3401,
8,
1053,
12,
3401,
63,
513,
9,
288,
340,
1911,
26,
355,
2059,
272,
372,
1911,
12,
576,
199,
199,
354,
63,
3401,
275,
334,
1418,
14,
2339,
12,
788,
1391,
1105,
421,
199,
318,
2813,
63,
18563,
8,
6916,
304,
272,
1072,
275,
942,
272,
367,
1242,
315,
9877,
26,
267,
340,
1242,
440,
315,
1072,
26,
288,
1072,
14,
740,
8,
1053,
9,
272,
372,
1072,
199,
199,
10421,
63,
1247,
275,
788,
5911,
418,
421,
199,
318,
2813,
63,
10421,
63,
1247,
8,
6916,
304,
272,
408,
5723,
787,
3423,
1561,
1553,
2793,
1133,
1218,
2860,
367,
3062,
267
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
1526,
199,
646,
5272,
199,
646,
1798,
421,
199,
318,
365,
4041,
8,
84,
304,
272,
372,
1228,
8,
84,
12,
334,
513,
12,
2008,
430,
421,
199,
318,
1109,
63,
475,
63,
5155,
8,
73,
304,
272,
408,
7905,
8950,
5272,
503,
1526,
370,
282,
18618,
322,
21701,
536,
14,
272,
408,
272,
862,
26,
267,
372,
5272,
14,
3840,
63,
354,
59,
73,
61,
272,
871,
4067,
26,
267,
372,
1526,
14,
9305,
63,
354,
59,
73,
61,
421,
199,
318,
9028,
63,
7450,
8,
1810,
63,
2960,
304,
272,
408,
25540,
8950,
12528,
6698,
315,
376,
6073,
63,
2960,
30262,
1561,
14,
398,
961,
9329,
1468,
422,
874,
314,
3123,
13806,
1263,
3000,
574,
370,
1338,
267,
1911,
315,
5272,
14,
3840,
63,
354,
503,
1526,
14,
9305,
63,
354,
14,
272,
408,
272,
892,
63,
513,
275,
942,
272,
367,
1242,
315,
6073,
63,
2960,
26,
267,
340,
1228,
8,
1053,
12,
1109,
304,
288,
892,
63,
513,
14,
740,
8,
442,
63,
475,
63,
5155,
8,
1053,
430,
267,
916,
365,
4041,
8,
1053,
304,
288,
892,
63,
513,
14,
740,
8,
5275,
63,
7450,
8,
1053,
430,
267,
587,
26,
288,
892,
63,
513,
14,
740,
8,
1053,
9,
272,
340,
1228,
8,
1810,
63,
2960,
12,
2008,
304,
267,
372,
2008,
8,
1222,
63,
513,
9,
272,
587,
26,
267,
372,
892,
63,
513,
421,
199,
318,
6073,
63,
475,
63,
875,
8,
1810,
63,
3610,
304,
272,
408,
10,
12643,
2077,
376,
6073,
3123,
3414,
12,
16116,
734,
1006,
11747,
3380,
14,
13359,
961,
27881,
295,
10838,
314,
3965,
314,
3123,
1990,
6137,
268,
687,
14,
221,
473,
9519,
2399,
8646,
4124,
8139,
14,
221,
7494,
330,
548,
268,
4363,
8292,
436,
892,
2385,
31,
221,
869,
15556,
1133,
7923,
642,
3967,
781,
3984,
268,
5544,
1454,
23654,
543,
3486,
8455,
14,
272,
627,
624,
272,
1072,
275,
2125,
272,
367,
1242,
315,
6073,
63,
3610,
26,
267,
340,
1228,
8,
1053,
12,
620,
304,
288,
1072,
275,
1072,
435,
1242,
267,
916,
365,
4041,
8,
1053,
304,
288,
1072,
275,
1072,
435,
6073,
63,
475,
63,
875,
8,
1053,
9,
272,
372,
1072,
421,
199,
318,
1900,
63,
4188,
8,
3684,
63,
875,
304,
272,
408,
6516,
376,
6073,
367,
376,
6222,
687,
314,
1627,
5348,
1059,
14,
398,
982,
5348,
63,
875,
365,
440,
282,
1059,
12,
652,
365,
6702,
370,
282,
1059,
267,
2544,
6057,
370,
376,
6073,
63,
2960,
14,
272,
408,
272,
327,
314,
359,
17,
1527,
17,
61,
16356,
5084,
9174,
14503,
737,
314,
10919,
2166,
272,
327,
13217,
315,
314,
9183,
2198,
3123,
14,
221,
1798,
14,
3684,
911,
372,
272,
327,
282,
3123,
882,
5731,
543,
3468,
63,
1210,
1035,
511,
63,
513,
1035,
511,
2263,
272,
327,
473,
6704,
11201,
316,
511,
370,
506,
314,
1738,
402,
6222,
6698,
14,
272,
327,
2779,
5594,
506,
282,
8034,
16819,
370,
4057,
3224,
282,
12050,
315,
314,
272,
327,
2198,
3123,
14,
6184,
22477,
14948,
31,
20854,
3063,
12,
642,
5419,
15701,
14,
272,
340,
1228,
8,
3684,
63,
875,
12,
620,
304,
267,
6073,
275,
1798,
14,
3684,
8,
3684,
63,
875,
680,
13280,
1363,
3430,
17,
1527,
17,
61,
272,
587,
26,
267,
6073,
275,
1798,
14,
3684,
8,
2722,
8,
3684,
63,
875,
4992,
13280,
1363,
3430,
17,
1527,
17,
61,
272,
372,
6073,
421,
199,
318,
6222,
63,
2960,
8,
3684,
63,
875,
304,
272,
372,
1900,
63,
4188,
8,
3684,
63,
875,
9,
421,
199,
318,
6222,
63,
513,
8,
3684,
63,
875,
304,
272,
372,
6346,
63,
475,
63,
6717,
8,
1506,
63,
4188,
8,
3684,
63,
875,
430,
421,
199,
318,
2342,
63,
2246,
63,
3401,
8,
1810,
63,
2960,
12,
3401,
63,
513,
304,
272,
408,
10,
6668,
314,
1642,
23101,
402,
282,
3851,
1373,
402,
282,
769,
402,
7970,
267,
315,
6073,
63,
2960,
14,
398,
8051,
367,
5343,
737,
314,
12427,
14,
398,
6073,
63,
2960,
259,
1553,
2008,
503,
769,
2737,
701,
6073,
14,
13280,
1363,
342,
503,
6073,
14,
13633,
1252,
267,
3851,
63,
513,
1553,
437,
2849,
3851,
503,
769,
402,
7970,
370,
2754,
717,
367,
315,
314,
6073,
63,
2960,
14,
221,
982,
282,
2849,
3851,
365,
717,
1202,
12,
652,
18095,
6262,
437,
1621,
437,
377,
28970,
1475,
14,
267,
1803,
26,
288,
1911,
1553,
2549,
15,
3910,
9297,
3775,
3851,
1990,
1911,
288,
666,
221,
1553,
2600,
402,
666,
687,
1642,
4877,
3851,
315,
3123,
14,
2151,
334,
3239,
1336,
805,
701,
1603,
69,
264,
1662,
29591,
76,
1860,
680,
272,
627,
624,
272,
1911,
12,
576,
275,
378,
12,
2440,
339,
327,
3957,
370,
282,
769,
340,
1324,
17373,
1133,
282,
769,
272,
340,
440,
1228,
8,
3401,
63,
513,
12,
769,
304,
267,
3851,
63,
513,
275,
359,
3401,
63,
513,
61,
339,
327,
3648,
367,
1263,
402,
314,
7970,
315,
282,
769,
402,
7970,
272,
367,
3851,
315,
3851,
63,
513,
26,
267,
1911,
12,
576,
275,
1336,
8,
3401,
12,
1810,
63,
2960,
9,
267,
340,
1911,
26,
288,
2059,
339,
327,
340,
781,
9980,
1133,
2342,
314,
3851,
12,
2754,
1007,
13,
14635,
402,
314,
2198,
3123,
272,
340,
440,
1911,
26,
267,
367,
1242,
315,
6073,
63,
2960,
26,
288,
340,
365,
4041,
8,
1053,
304,
355,
327,
1454,
2754,
1007,
2974,
340,
2985,
787,
282,
769,
503,
2008,
14,
355,
1911,
12,
666,
275,
2342,
63,
2246,
63,
3401,
8,
1053,
12,
3401,
63,
513,
9,
288,
340,
1911,
26,
355,
2059,
272,
372,
1911,
12,
576,
199,
199,
354,
63,
3401,
275,
334,
1418,
14,
2339,
12,
788,
1391,
1105,
421,
199,
318,
2813,
63,
18563,
8,
6916,
304,
272,
1072,
275,
942,
272,
367,
1242,
315,
9877,
26,
267,
340,
1242,
440,
315,
1072,
26,
288,
1072,
14,
740,
8,
1053,
9,
272,
372,
1072,
199,
199,
10421,
63,
1247,
275,
788,
5911,
418,
421,
199,
318,
2813,
63,
10421,
63,
1247,
8,
6916,
304,
272,
408,
5723,
787,
3423,
1561,
1553,
2793,
1133,
1218,
2860,
367,
3062,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
OpenUpgrade/OpenUpgrade
|
addons/analytic_user_function/__openerp__.py
|
260
|
2015
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Jobs on Contracts',
'version': '1.0',
'category': 'Sales Management',
'description': """
This module allows you to define what is the default function of a specific user on a given account.
====================================================================================================
This is mostly used when a user encodes his timesheet: the values are retrieved
and the fields are auto-filled. But the possibility to change these values is
still available.
Obviously if no data has been recorded for the current account, the default
value is given as usual by the employee data so that this module is perfectly
compatible with older configurations.
""",
'author': 'OpenERP SA',
'website': 'https://www.odoo.com/page/employees',
'depends': ['hr_timesheet_sheet'],
'data': ['analytic_user_function_view.xml', 'security/ir.model.access.csv'],
'demo': [],
'installable': True,
'auto_install': False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
421,
199,
91,
272,
283,
354,
356,
283,
20578,
641,
1448,
1239,
3021,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
18220,
8259,
297,
272,
283,
1802,
356,
408,
199,
2765,
859,
6127,
1265,
370,
5627,
4052,
365,
314,
849,
805,
402,
282,
2488,
922,
641,
282,
1627,
2933,
14,
199,
5695,
2486,
532,
199,
199,
2765,
365,
19762,
1202,
1380,
282,
922,
3752,
83,
17049,
900,
5069,
26,
314,
1338,
787,
12396,
199,
460,
314,
1504,
787,
2599,
13,
17647,
14,
11017,
314,
31077,
370,
1570,
3520,
1338,
365,
199,
32310,
2808,
14,
199,
199,
11394,
2971,
590,
340,
949,
666,
965,
2757,
18894,
367,
314,
1453,
2933,
12,
314,
849,
199,
585,
365,
1627,
465,
20195,
701,
314,
15778,
666,
880,
626,
642,
859,
365,
23668,
590,
199,
6490,
543,
12731,
13422,
14,
339,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
15,
1606,
15,
24561,
297,
272,
283,
8912,
356,
788,
6271,
63,
17739,
63,
5069,
995,
272,
283,
576,
356,
788,
9782,
63,
751,
63,
1593,
63,
1345,
14,
1652,
297,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
995,
272,
283,
8768,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
421,
199,
91,
272,
283,
354,
356,
283,
20578,
641,
1448,
1239,
3021,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
18220,
8259,
297,
272,
283,
1802,
356,
408,
199,
2765,
859,
6127,
1265,
370,
5627,
4052,
365,
314,
849,
805,
402,
282,
2488,
922,
641,
282,
1627,
2933,
14,
199,
5695,
2486,
532,
199,
199,
2765,
365,
19762,
1202,
1380,
282,
922,
3752,
83,
17049,
900,
5069,
26,
314,
1338,
787,
12396,
199,
460,
314,
1504,
787,
2599,
13,
17647,
14,
11017,
314,
31077,
370,
1570,
3520,
1338,
365,
199,
32310,
2808,
14,
199,
199,
11394,
2971,
590,
340,
949,
666,
965,
2757,
18894,
367,
314,
1453,
2933,
12,
314,
849,
199,
585,
365,
1627,
465,
20195,
701,
314,
15778,
666,
880,
626,
642,
859,
365,
23668,
590,
199,
6490,
543,
12731,
13422,
14,
339,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
15,
1606,
15,
24561,
297,
272,
283,
8912,
356,
788,
6271,
63,
17739,
63,
5069,
995,
272,
283,
576,
356,
788,
9782,
63,
751,
63,
1593,
63,
1345,
14,
1652,
297,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
995,
272,
283,
8768,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
2ndQuadrant/ansible
|
lib/ansible/modules/storage/netapp/na_ontap_cluster.py
|
26
|
10668
|
#!/usr/bin/python
# (c) 2017, NetApp, Inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'certified'}
DOCUMENTATION = '''
module: na_ontap_cluster
short_description: NetApp ONTAP cluster - create, join, add license
extends_documentation_fragment:
- netapp.na_ontap
version_added: '2.6'
author: NetApp Ansible Team (@carchi8py) <ng-ansibleteam@netapp.com>
description:
- Create or join or apply licenses to ONTAP clusters
- Cluster join can be performed using only one of the parameters, either cluster_name or cluster_ip_address
options:
state:
description:
- Whether the specified cluster should exist or not.
choices: ['present']
default: present
cluster_name:
description:
- The name of the cluster to manage.
cluster_ip_address:
description:
- IP address of cluster to be joined
license_code:
description:
- License code to be applied to the cluster
license_package:
description:
- License package name of the license to be removed
node_serial_number:
description:
- Serial number of the cluster node
'''
EXAMPLES = """
- name: Create cluster
na_ontap_cluster:
state: present
cluster_name: new_cluster
hostname: "{{ netapp_hostname }}"
username: "{{ netapp_username }}"
password: "{{ netapp_password }}"
- name: Add license from cluster
na_ontap_cluster:
state: present
cluster_name: FPaaS-A300-01
license_code: SGHLQDBBVAAAAAAAAAAAAAAAAAAA
hostname: "{{ netapp_hostname }}"
username: "{{ netapp_username }}"
password: "{{ netapp_password }}"
- name: Join cluster
na_ontap_cluster:
state: present
cluster_ip_address: 10.61.184.181
hostname: "{{ netapp_hostname }}"
username: "{{ netapp_username }}"
password: "{{ netapp_password }}"
- name: Join cluster
na_ontap_cluster:
state: present
cluster_name: FPaaS-A300-01
hostname: "{{ netapp_hostname }}"
username: "{{ netapp_username }}"
password: "{{ netapp_password }}"
"""
RETURN = """
"""
import traceback
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
import ansible.module_utils.netapp as netapp_utils
from ansible.module_utils.netapp_module import NetAppModule
HAS_NETAPP_LIB = netapp_utils.has_netapp_lib()
def local_cmp(a, b):
"""
compares with only values and not keys, keys should be the same for both dicts
:param a: dict 1
:param b: dict 2
:return: difference of values in both dicts
"""
diff = [key for key in a if a[key] != b[key]]
return len(diff)
class NetAppONTAPCluster(object):
"""
object initialize and class methods
"""
def __init__(self):
self.argument_spec = netapp_utils.na_ontap_host_argument_spec()
self.argument_spec.update(dict(
state=dict(required=False, choices=['present'], default='present'),
cluster_name=dict(required=False, type='str'),
cluster_ip_address=dict(required=False, type='str'),
license_code=dict(required=False, type='str'),
license_package=dict(required=False, type='str'),
node_serial_number=dict(required=False, type='str')
))
self.module = AnsibleModule(
argument_spec=self.argument_spec,
supports_check_mode=True,
required_together=[
['license_package', 'node_serial_number']
]
)
self.na_helper = NetAppModule()
self.parameters = self.na_helper.set_parameters(self.module.params)
if HAS_NETAPP_LIB is False:
self.module.fail_json(msg="the python NetApp-Lib module is required")
else:
self.server = netapp_utils.setup_na_ontap_zapi(module=self.module)
def get_licensing_status(self):
"""
Check licensing status
:return: package (key) and licensing status (value)
:rtype: dict
"""
license_status = netapp_utils.zapi.NaElement(
'license-v2-status-list-info')
try:
result = self.server.invoke_successfully(license_status,
enable_tunneling=True)
except netapp_utils.zapi.NaApiError as error:
self.module.fail_json(msg="Error checking license status: %s" %
to_native(error), exception=traceback.format_exc())
return_dictionary = {}
license_v2_status = result.get_child_by_name('license-v2-status')
if license_v2_status:
for license_v2_status_info in license_v2_status.get_children():
package = license_v2_status_info.get_child_content('package')
status = license_v2_status_info.get_child_content('method')
return_dictionary[package] = status
return return_dictionary
def create_cluster(self):
"""
Create a cluster
"""
cluster_create = netapp_utils.zapi.NaElement.create_node_with_children(
'cluster-create', **{'cluster-name': self.parameters['cluster_name']})
try:
self.server.invoke_successfully(cluster_create,
enable_tunneling=True)
except netapp_utils.zapi.NaApiError as error:
# Error 36503 denotes node already being used.
if to_native(error.code) == "36503":
return False
else:
self.module.fail_json(msg='Error creating cluster %s: %s'
% (self.parameters['cluster_name'], to_native(error)),
exception=traceback.format_exc())
return True
def cluster_join(self):
"""
Add a node to an existing cluster
"""
if self.parameters.get('cluster_ip_address') is not None:
cluster_add_node = netapp_utils.zapi.NaElement.create_node_with_children(
'cluster-join', **{'cluster-ip-address': self.parameters['cluster_ip_address']})
for_fail_attribute = self.parameters.get('cluster_ip_address')
elif self.parameters.get('cluster_name') is not None:
cluster_add_node = netapp_utils.zapi.NaElement.create_node_with_children(
'cluster-join', **{'cluster-name': self.parameters['cluster_name']})
for_fail_attribute = self.parameters.get('cluster_name')
else:
return False
try:
self.server.invoke_successfully(cluster_add_node, enable_tunneling=True)
except netapp_utils.zapi.NaApiError as error:
# Error 36503 denotes node already being used.
if to_native(error.code) == "36503":
return False
else:
self.module.fail_json(msg='Error adding node to cluster %s: %s'
% (for_fail_attribute, to_native(error)),
exception=traceback.format_exc())
return True
def license_v2_add(self):
"""
Apply a license to cluster
"""
license_add = netapp_utils.zapi.NaElement.create_node_with_children('license-v2-add')
license_add.add_node_with_children('codes', **{'license-code-v2': self.parameters['license_code']})
try:
self.server.invoke_successfully(license_add, enable_tunneling=True)
except netapp_utils.zapi.NaApiError as error:
self.module.fail_json(msg='Error adding license %s: %s'
% (self.parameters['license_code'], to_native(error)),
exception=traceback.format_exc())
def license_v2_delete(self):
"""
Delete license from cluster
"""
license_delete = netapp_utils.zapi.NaElement.create_node_with_children(
'license-v2-delete', **{'package': self.parameters['license_package'],
'serial-number': self.parameters['node_serial_number']})
try:
self.server.invoke_successfully(license_delete, enable_tunneling=True)
except netapp_utils.zapi.NaApiError as error:
self.module.fail_json(msg='Error deleting license : %s' % (to_native(error)),
exception=traceback.format_exc())
def autosupport_log(self):
"""
Autosupport log for cluster
:return:
"""
results = netapp_utils.get_cserver(self.server)
cserver = netapp_utils.setup_na_ontap_zapi(module=self.module, vserver=results)
netapp_utils.ems_log_event("na_ontap_cluster", cserver)
def apply(self):
"""
Apply action to cluster
"""
property_changed = False
create_flag = False
join_flag = False
self.autosupport_log()
license_status = self.get_licensing_status()
if self.module.check_mode:
pass
else:
if self.parameters.get('state') == 'present':
if self.parameters.get('cluster_name') is not None:
create_flag = self.create_cluster()
if not create_flag:
join_flag = self.cluster_join()
if self.parameters.get('license_code') is not None:
self.license_v2_add()
property_changed = True
if self.parameters.get('license_package') is not None and\
self.parameters.get('node_serial_number') is not None:
if license_status.get(str(self.parameters.get('license_package')).lower()) != 'none':
self.license_v2_delete()
property_changed = True
if property_changed:
new_license_status = self.get_licensing_status()
if local_cmp(license_status, new_license_status) == 0:
property_changed = False
changed = property_changed or create_flag or join_flag
self.module.exit_json(changed=changed)
def main():
"""
Create object and call apply
"""
cluster_obj = NetAppONTAPCluster()
cluster_obj.apply()
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
334,
67,
9,
9708,
12,
28076,
12,
3277,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
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,
2247,
8981,
936,
421,
199,
8948,
275,
1449,
199,
578,
26,
11802,
63,
1888,
439,
63,
4201,
199,
3612,
63,
1802,
26,
28076,
5258,
52,
1282,
4350,
446,
1218,
12,
4263,
12,
1050,
4190,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
15742,
14,
3540,
63,
1888,
439,
199,
1023,
63,
3270,
26,
283,
18,
14,
22,
7,
199,
2502,
26,
28076,
2622,
11682,
8593,
67,
1047,
73,
24,
647,
9,
665,
2753,
13,
4853,
5969,
32,
25830,
14,
957,
30,
199,
1802,
26,
199,
13,
2790,
503,
4263,
503,
4838,
12378,
370,
5258,
52,
1282,
13865,
199,
13,
16454,
4263,
883,
506,
10585,
1808,
1454,
1373,
402,
314,
2633,
12,
1902,
4350,
63,
354,
503,
4350,
63,
711,
63,
1562,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
272,
446,
7480,
314,
2013,
4350,
1077,
2187,
503,
440,
14,
272,
3415,
26,
788,
1881,
418,
272,
849,
26,
3451,
523,
4350,
63,
354,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
4350,
370,
9635,
14,
523,
4350,
63,
711,
63,
1562,
26,
272,
1369,
26,
272,
446,
3531,
2287,
402,
4350,
370,
506,
16538,
523,
4190,
63,
600,
26,
272,
1369,
26,
272,
446,
844,
1233,
370,
506,
6781,
370,
314,
4350,
523,
4190,
63,
2491,
26,
272,
1369,
26,
272,
446,
844,
2559,
536,
402,
314,
4190,
370,
506,
4829,
523,
1031,
63,
2171,
63,
1955,
26,
272,
1369,
26,
272,
446,
11973,
1329,
402,
314,
4350,
1031,
199,
199,
2344,
199,
199,
8918,
275,
408,
272,
446,
536,
26,
2790,
4350,
489,
11802,
63,
1888,
439,
63,
4201,
26,
267,
1174,
26,
3451,
267,
4350,
63,
354,
26,
892,
63,
4201,
267,
6246,
26,
7370,
15742,
63,
4269,
7820,
267,
3434,
26,
7370,
15742,
63,
2473,
7820,
267,
2505,
26,
7370,
15742,
63,
2060,
7820,
272,
446,
536,
26,
2654,
4190,
687,
4350,
489,
11802,
63,
1888,
439,
63,
4201,
26,
267,
1174,
26,
3451,
267,
4350,
63,
354,
26,
481,
48,
2158,
51,
13,
33,
5863,
13,
614,
267,
4190,
63,
600,
26,
18868,
29210,
49,
2846,
34,
54,
24961,
10985,
267,
6246,
26,
7370,
15742,
63,
4269,
7820,
267,
3434,
26,
7370,
15742,
63,
2473,
7820,
267,
2505,
26,
7370,
15742,
63,
2060,
7820,
272,
446,
536,
26,
25733,
4350,
489,
11802,
63,
1888,
439,
63,
4201,
26,
267,
1174,
26,
3451,
267,
4350,
63,
711,
63,
1562,
26,
1616,
14,
2976,
14,
10078,
14,
12851,
267,
6246,
26,
7370,
15742,
63,
4269,
7820,
267,
3434,
26,
7370,
15742,
63,
2473,
7820,
267,
2505,
26,
7370,
15742,
63,
2060,
7820,
272,
446,
536,
26,
25733,
4350,
489,
11802,
63,
1888,
439,
63,
4201,
26,
267,
1174,
26,
3451,
267,
4350,
63,
354,
26,
481,
48,
2158,
51,
13,
33,
5863,
13,
614,
267,
6246,
26,
7370,
15742,
63,
4269,
7820,
267,
3434,
26,
7370,
15742,
63,
2473,
7820,
267,
2505,
26,
7370,
15742,
63,
2060,
7820,
199,
624,
199,
199,
9677,
275,
408,
199,
624,
199,
199,
646,
5190,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
6106,
199,
646,
3242,
14,
578,
63,
1208,
14,
25830,
465,
15742,
63,
1208,
199,
504,
3242,
14,
578,
63,
1208,
14,
25830,
63,
578,
492,
28076,
2377,
199,
199,
13533,
63,
7278,
7121,
63,
5617,
275,
15742,
63,
1208,
14,
1989,
63,
25830,
63,
773,
342,
421,
199,
318,
2257,
63,
5730,
8,
65,
12,
330,
304,
272,
408,
272,
30827,
543,
1454,
1338,
436,
440,
2883,
12,
2883,
1077,
506,
314,
2011,
367,
3865,
10809,
272,
520,
635,
282,
26,
1211,
413,
272,
520,
635,
330,
26,
1211,
499,
272,
520,
1107,
26,
8865,
402,
1338,
315,
3865,
10809,
272,
408,
272,
3915,
275,
359,
498,
367,
790,
315,
282,
340,
282,
59,
498,
61,
1137,
330,
59,
498,
2677,
272,
372,
822,
8,
3028,
9,
421,
199,
533,
28076,
5994,
1282,
9581,
8,
785,
304,
272,
408,
272,
909,
8265,
436,
1021,
3102,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
2094,
63,
1650,
275,
15742,
63,
1208,
14,
3540,
63,
1888,
439,
63,
1102,
63,
2094,
63,
1650,
342,
267,
291,
14,
2094,
63,
1650,
14,
873,
8,
807,
8,
288,
1174,
29,
807,
8,
2427,
29,
797,
12,
3415,
2968,
1881,
995,
849,
534,
1881,
659,
288,
4350,
63,
354,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
495,
659,
288,
4350,
63,
711,
63,
1562,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
495,
659,
288,
4190,
63,
600,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
495,
659,
288,
4190,
63,
2491,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
495,
659,
288,
1031,
63,
2171,
63,
1955,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
495,
358,
267,
5082,
398,
291,
14,
578,
275,
6953,
8,
288,
1423,
63,
1650,
29,
277,
14,
2094,
63,
1650,
12,
288,
5171,
63,
1074,
63,
632,
29,
549,
12,
288,
1415,
63,
6314,
1524,
355,
788,
1682,
63,
2491,
297,
283,
932,
63,
2171,
63,
1955,
418,
288,
1622,
267,
776,
398,
291,
14,
3540,
63,
3676,
275,
28076,
2377,
342,
267,
291,
14,
3214,
275,
291,
14,
3540,
63,
3676,
14,
409,
63,
3214,
8,
277,
14,
578,
14,
1162,
9,
398,
340,
7509,
63,
7278,
7121,
63,
5617,
365,
756,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
8,
1328,
628,
1589,
2366,
28076,
13,
4728,
859,
365,
1415,
531,
267,
587,
26
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
334,
67,
9,
9708,
12,
28076,
12,
3277,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
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,
2247,
8981,
936,
421,
199,
8948,
275,
1449,
199,
578,
26,
11802,
63,
1888,
439,
63,
4201,
199,
3612,
63,
1802,
26,
28076,
5258,
52,
1282,
4350,
446,
1218,
12,
4263,
12,
1050,
4190,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
15742,
14,
3540,
63,
1888,
439,
199,
1023,
63,
3270,
26,
283,
18,
14,
22,
7,
199,
2502,
26,
28076,
2622,
11682,
8593,
67,
1047,
73,
24,
647,
9,
665,
2753,
13,
4853,
5969,
32,
25830,
14,
957,
30,
199,
1802,
26,
199,
13,
2790,
503,
4263,
503,
4838,
12378,
370,
5258,
52,
1282,
13865,
199,
13,
16454,
4263,
883,
506,
10585,
1808,
1454,
1373,
402,
314,
2633,
12,
1902,
4350,
63,
354,
503,
4350,
63,
711,
63,
1562,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
272,
446,
7480,
314,
2013,
4350,
1077,
2187,
503,
440,
14,
272,
3415,
26,
788,
1881,
418,
272,
849,
26,
3451,
523,
4350,
63,
354,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
4350,
370,
9635,
14,
523,
4350,
63,
711,
63,
1562,
26,
272,
1369,
26,
272,
446,
3531,
2287,
402,
4350,
370,
506,
16538,
523,
4190,
63,
600,
26,
272,
1369,
26,
272,
446,
844,
1233,
370,
506,
6781,
370,
314,
4350,
523,
4190,
63,
2491,
26,
272,
1369,
26,
272,
446,
844,
2559,
536,
402,
314,
4190,
370,
506,
4829,
523,
1031,
63,
2171,
63,
1955,
26,
272,
1369,
26,
272,
446,
11973,
1329,
402,
314,
4350,
1031,
199,
199,
2344,
199,
199,
8918,
275,
408,
272,
446,
536,
26,
2790,
4350,
489,
11802,
63,
1888,
439,
63,
4201,
26,
267,
1174,
26,
3451,
267,
4350,
63,
354,
26,
892,
63,
4201,
267,
6246,
26,
7370,
15742,
63,
4269,
7820,
267,
3434,
26,
7370,
15742,
63,
2473,
7820,
267,
2505,
26,
7370,
15742,
63,
2060,
7820,
272,
446,
536,
26,
2654,
4190,
687,
4350,
489,
11802,
63,
1888,
439,
63,
4201,
26,
267,
1174,
26,
3451,
267,
4350,
63,
354,
26,
481,
48,
2158,
51,
13,
33,
5863,
13,
614,
267,
4190,
63,
600,
26,
18868,
29210,
49,
2846,
34,
54,
24961,
10985,
267,
6246,
26,
7370,
15742,
63,
4269,
7820,
267,
3434,
26,
7370,
15742,
63,
2473,
7820,
267,
2505,
26,
7370,
15742,
63,
2060,
7820,
272,
446,
536,
26,
25733,
4350,
489,
11802,
63,
1888,
439,
63,
4201,
26,
267,
1174,
26,
3451,
267,
4350,
63,
711,
63,
1562,
26,
1616,
14,
2976,
14,
10078,
14,
12851,
267,
6246,
26,
7370,
15742,
63,
4269,
7820,
267,
3434,
26,
7370,
15742,
63,
2473,
7820,
267,
2505,
26,
7370,
15742,
63,
2060,
7820,
272,
446,
536,
26,
25733,
4350,
489,
11802,
63,
1888,
439,
63,
4201,
26,
267,
1174,
26,
3451,
267,
4350,
63,
354,
26,
481,
48,
2158,
51,
13,
33,
5863,
13,
614,
267,
6246,
26,
7370,
15742,
63,
4269,
7820,
267,
3434,
26,
7370,
15742,
63,
2473,
7820,
267,
2505,
26,
7370,
15742,
63,
2060,
7820,
199,
624,
199,
199,
9677,
275,
408,
199,
624,
199,
199,
646,
5190,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
6106,
199,
646,
3242,
14,
578,
63,
1208,
14,
25830,
465,
15742,
63,
1208,
199,
504,
3242,
14,
578,
63,
1208,
14,
25830,
63,
578,
492,
28076,
2377,
199,
199,
13533,
63,
7278,
7121,
63,
5617,
275,
15742,
63,
1208,
14,
1989,
63,
25830,
63,
773,
342,
421,
199,
318,
2257,
63,
5730,
8,
65,
12,
330,
304,
272,
408,
272,
30827,
543,
1454,
1338,
436,
440,
2883,
12,
2883,
1077,
506,
314,
2011,
367,
3865,
10809,
272,
520,
635,
282,
26,
1211,
413,
272,
520,
635,
330,
26,
1211,
499,
272,
520,
1107,
26,
8865,
402,
1338,
315,
3865,
10809,
272,
408,
272,
3915,
275,
359,
498,
367,
790,
315,
282,
340,
282,
59,
498,
61,
1137,
330,
59,
498,
2677,
272,
372,
822,
8,
3028,
9,
421,
199,
533,
28076,
5994,
1282,
9581,
8,
785,
304,
272,
408,
272,
909,
8265,
436,
1021,
3102,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
2094,
63,
1650,
275,
15742,
63,
1208,
14,
3540,
63,
1888,
439,
63,
1102,
63,
2094,
63,
1650,
342,
267,
291,
14,
2094,
63,
1650,
14,
873,
8,
807,
8,
288,
1174,
29,
807,
8,
2427,
29,
797,
12,
3415,
2968,
1881,
995,
849,
534,
1881,
659,
288,
4350,
63,
354,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
495,
659,
288,
4350,
63,
711,
63,
1562,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
495,
659,
288,
4190,
63,
600,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
495,
659,
288,
4190,
63,
2491,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
495,
659,
288,
1031,
63,
2171,
63,
1955,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
495,
358,
267,
5082,
398,
291,
14,
578,
275,
6953,
8,
288,
1423,
63,
1650,
29,
277,
14,
2094,
63,
1650,
12,
288,
5171,
63,
1074,
63,
632,
29,
549,
12,
288,
1415,
63,
6314,
1524,
355,
788,
1682,
63,
2491,
297,
283,
932,
63,
2171,
63,
1955,
418,
288,
1622,
267,
776,
398,
291,
14,
3540,
63,
3676,
275,
28076,
2377,
342,
267,
291,
14,
3214,
275,
291,
14,
3540,
63,
3676,
14,
409,
63,
3214,
8,
277,
14,
578,
14,
1162,
9,
398,
340,
7509,
63,
7278,
7121,
63,
5617,
365,
756,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
8,
1328,
628,
1589,
2366,
28076,
13,
4728,
859,
365,
1415,
531,
267,
587,
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,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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
] |
polimediaupv/edx-platform
|
common/djangoapps/track/tests/test_contexts.py
|
119
|
1330
|
# pylint: disable=missing-docstring,maybe-no-member
from unittest import TestCase
from track import contexts
class TestContexts(TestCase):
COURSE_ID = 'test/course_name/course_run'
ORG_ID = 'test'
def test_course_id_from_url(self):
self.assert_parses_course_id_from_url('http://foo.bar.com/courses/{course_id}/more/stuff')
def assert_parses_course_id_from_url(self, format_string):
self.assertEquals(
contexts.course_context_from_url(format_string.format(course_id=self.COURSE_ID)),
{
'course_id': self.COURSE_ID,
'org_id': self.ORG_ID
}
)
def test_no_course_id_in_url(self):
self.assert_empty_context_for_url('http://foo.bar.com/dashboard')
def assert_empty_context_for_url(self, url):
self.assertEquals(
contexts.course_context_from_url(url),
{
'course_id': '',
'org_id': ''
}
)
def test_malformed_course_id(self):
self.assert_empty_context_for_url('http://foo.bar.com/courses/test')
def test_course_id_later_in_url(self):
self.assert_parses_course_id_from_url('http://foo.bar.com/x/y/z/courses/{course_id}')
def test_no_url(self):
self.assert_empty_context_for_url(None)
|
agpl-3.0
|
[
3,
4287,
26,
3507,
29,
4752,
13,
12485,
12,
11853,
13,
889,
13,
1114,
199,
199,
504,
2882,
492,
7640,
199,
199,
504,
4426,
492,
18191,
421,
199,
533,
1379,
2998,
83,
8,
1746,
304,
339,
5099,
14302,
63,
998,
275,
283,
396,
15,
1972,
63,
354,
15,
1972,
63,
1065,
7,
272,
1549,
39,
63,
998,
275,
283,
396,
7,
339,
347,
511,
63,
1972,
63,
344,
63,
504,
63,
633,
8,
277,
304,
267,
291,
14,
479,
63,
462,
874,
63,
1972,
63,
344,
63,
504,
63,
633,
360,
1014,
921,
1421,
14,
1700,
14,
957,
15,
11653,
5321,
1972,
63,
344,
5995,
6878,
15,
14573,
358,
339,
347,
702,
63,
462,
874,
63,
1972,
63,
344,
63,
504,
63,
633,
8,
277,
12,
1475,
63,
875,
304,
267,
291,
14,
2947,
8,
288,
18191,
14,
1972,
63,
1100,
63,
504,
63,
633,
8,
908,
63,
875,
14,
908,
8,
1972,
63,
344,
29,
277,
14,
15552,
63,
998,
1826,
288,
469,
355,
283,
1972,
63,
344,
356,
291,
14,
15552,
63,
998,
12,
355,
283,
1308,
63,
344,
356,
291,
14,
25797,
63,
998,
288,
789,
267,
776,
339,
347,
511,
63,
889,
63,
1972,
63,
344,
63,
262,
63,
633,
8,
277,
304,
267,
291,
14,
479,
63,
1667,
63,
1100,
63,
509,
63,
633,
360,
1014,
921,
1421,
14,
1700,
14,
957,
15,
9743,
358,
339,
347,
702,
63,
1667,
63,
1100,
63,
509,
63,
633,
8,
277,
12,
1166,
304,
267,
291,
14,
2947,
8,
288,
18191,
14,
1972,
63,
1100,
63,
504,
63,
633,
8,
633,
395,
288,
469,
355,
283,
1972,
63,
344,
356,
3260,
355,
283,
1308,
63,
344,
356,
2125,
288,
789,
267,
776,
339,
347,
511,
63,
31029,
63,
1972,
63,
344,
8,
277,
304,
267,
291,
14,
479,
63,
1667,
63,
1100,
63,
509,
63,
633,
360,
1014,
921,
1421,
14,
1700,
14,
957,
15,
11653,
15,
396,
358,
339,
347,
511,
63,
1972,
63,
344,
63,
18103,
63,
262,
63,
633,
8,
277,
304,
267,
291,
14,
479,
63,
462,
874,
63,
1972,
63,
344,
63,
504,
63,
633,
360,
1014,
921,
1421,
14,
1700,
14,
957,
15,
88,
15,
89,
15,
90,
15,
11653,
5321,
1972,
63,
344,
12216,
339,
347,
511,
63,
889,
63,
633,
8,
277,
304,
267,
291,
14,
479,
63,
1667,
63,
1100,
63,
509,
63,
633,
8,
403,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4287,
26,
3507,
29,
4752,
13,
12485,
12,
11853,
13,
889,
13,
1114,
199,
199,
504,
2882,
492,
7640,
199,
199,
504,
4426,
492,
18191,
421,
199,
533,
1379,
2998,
83,
8,
1746,
304,
339,
5099,
14302,
63,
998,
275,
283,
396,
15,
1972,
63,
354,
15,
1972,
63,
1065,
7,
272,
1549,
39,
63,
998,
275,
283,
396,
7,
339,
347,
511,
63,
1972,
63,
344,
63,
504,
63,
633,
8,
277,
304,
267,
291,
14,
479,
63,
462,
874,
63,
1972,
63,
344,
63,
504,
63,
633,
360,
1014,
921,
1421,
14,
1700,
14,
957,
15,
11653,
5321,
1972,
63,
344,
5995,
6878,
15,
14573,
358,
339,
347,
702,
63,
462,
874,
63,
1972,
63,
344,
63,
504,
63,
633,
8,
277,
12,
1475,
63,
875,
304,
267,
291,
14,
2947,
8,
288,
18191,
14,
1972,
63,
1100,
63,
504,
63,
633,
8,
908,
63,
875,
14,
908,
8,
1972,
63,
344,
29,
277,
14,
15552,
63,
998,
1826,
288,
469,
355,
283,
1972,
63,
344,
356,
291,
14,
15552,
63,
998,
12,
355,
283,
1308,
63,
344,
356,
291,
14,
25797,
63,
998,
288,
789,
267,
776,
339,
347,
511,
63,
889,
63,
1972,
63,
344,
63,
262,
63,
633,
8,
277,
304,
267,
291,
14,
479,
63,
1667,
63,
1100,
63,
509,
63,
633,
360,
1014,
921,
1421,
14,
1700,
14,
957,
15,
9743,
358,
339,
347,
702,
63,
1667,
63,
1100,
63,
509,
63,
633,
8,
277,
12,
1166,
304,
267,
291,
14,
2947,
8,
288,
18191,
14,
1972,
63,
1100,
63,
504,
63,
633,
8,
633,
395,
288,
469,
355,
283,
1972,
63,
344,
356,
3260,
355,
283,
1308,
63,
344,
356,
2125,
288,
789,
267,
776,
339,
347,
511,
63,
31029,
63,
1972,
63,
344,
8,
277,
304,
267,
291,
14,
479,
63,
1667,
63,
1100,
63,
509,
63,
633,
360,
1014,
921,
1421,
14,
1700,
14,
957,
15,
11653,
15,
396,
358,
339,
347,
511,
63,
1972,
63,
344,
63,
18103,
63,
262,
63,
633,
8,
277,
304,
267,
291,
14,
479,
63,
462,
874,
63,
1972,
63,
344,
63,
504,
63,
633,
360,
1014,
921,
1421,
14,
1700,
14,
957,
15,
88,
15,
89,
15,
90,
15,
11653,
5321,
1972,
63,
344,
12216,
339,
347,
511,
63,
889,
63,
633,
8,
277,
304,
267,
291,
14,
479,
63,
1667,
63,
1100,
63,
509,
63,
633,
8,
403,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
AltSchool/dynamic-rest
|
tests/migrations/0001_initial.py
|
2
|
6894
|
# -*- coding: utf-8 -*-
# flake8: noqa
# Generated by Django 1.9 on 2016-01-27 16:29
from __future__ import unicode_literals
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='A',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField(blank=True)),
],
),
migrations.CreateModel(
name='B',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('a', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='b', to='tests.A')),
],
),
migrations.CreateModel(
name='C',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('b', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cs', to='tests.B')),
],
),
migrations.CreateModel(
name='Cat',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
],
),
migrations.CreateModel(
name='D',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField(blank=True)),
],
),
migrations.CreateModel(
name='Dog',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
('fur_color', models.TextField()),
('origin', models.TextField()),
],
),
migrations.CreateModel(
name='Event',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
('status', models.TextField(default=b'current')),
],
),
migrations.CreateModel(
name='Group',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
],
),
migrations.CreateModel(
name='Horse',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
('origin', models.TextField()),
],
),
migrations.CreateModel(
name='Location',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
('blob', models.TextField()),
],
),
migrations.CreateModel(
name='Permission',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
('code', models.IntegerField()),
],
),
migrations.CreateModel(
name='Profile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('display_name', models.TextField()),
('thumbnail_url', models.TextField(blank=True, null=True)),
],
),
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
('last_name', models.TextField()),
('groups', models.ManyToManyField(related_name='users', to='tests.Group')),
('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='tests.Location')),
('permissions', models.ManyToManyField(related_name='users', to='tests.Permission')),
],
),
migrations.CreateModel(
name='Zebra',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
('origin', models.TextField()),
],
),
migrations.AddField(
model_name='profile',
name='user',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='tests.User'),
),
migrations.AddField(
model_name='group',
name='permissions',
field=models.ManyToManyField(related_name='groups', to='tests.Permission'),
),
migrations.AddField(
model_name='event',
name='location',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='tests.Location'),
),
migrations.AddField(
model_name='event',
name='users',
field=models.ManyToManyField(to='tests.User'),
),
migrations.AddField(
model_name='cat',
name='backup_home',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='friendly_cats', to='tests.Location'),
),
migrations.AddField(
model_name='cat',
name='home',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tests.Location'),
),
migrations.AddField(
model_name='cat',
name='hunting_grounds',
field=models.ManyToManyField(related_name='annoying_cats', related_query_name=b'getoffmylawn', to='tests.Location'),
),
migrations.AddField(
model_name='cat',
name='parent',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='kittens', to='tests.Cat'),
),
migrations.AddField(
model_name='c',
name='d',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tests.D'),
),
]
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
27510,
24,
26,
8151,
199,
3,
17065,
701,
5634,
413,
14,
25,
641,
7800,
13,
614,
13,
1465,
3193,
26,
1398,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
1639,
14,
697,
14,
992,
14,
14281,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
2536,
275,
715,
339,
5124,
275,
359,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
33,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
8,
2500,
29,
549,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
34,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
65,
297,
1709,
14,
14298,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
4048,
63,
354,
534,
66,
297,
370,
534,
2219,
14,
33,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
35,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
66,
297,
1709,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
4048,
63,
354,
534,
1259,
297,
370,
534,
2219,
14,
34,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
21548,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
36,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
8,
2500,
29,
549,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
36,
974,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
4000,
355,
661,
70,
300,
63,
2326,
297,
1709,
14,
6254,
4000,
355,
661,
6493,
297,
1709,
14,
6254,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
2390,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
4000,
355,
661,
1205,
297,
1709,
14,
6254,
8,
885,
29,
66,
7,
1818,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
2448,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
40,
9050,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
4000,
355,
661,
6493,
297,
1709,
14,
6254,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
6592,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
4000,
355,
661,
6582,
297,
1709,
14,
6254,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
7980,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
4000,
355,
661,
600,
297,
1709,
14,
3901,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
5736,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
2918,
63,
354,
297,
1709,
14,
6254,
4000,
355,
661,
8311,
63,
633,
297,
1709,
14,
6254,
8,
2500,
29,
549,
12,
2973,
29,
549,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
1899,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
4000,
355,
661,
2019,
63,
354,
297,
1709,
14,
6254,
4000,
355,
661,
2634,
297,
1709,
14,
7624,
8,
2407,
63,
354,
534,
3707,
297,
370,
534,
2219,
14,
2448,
3855,
355,
661,
1985,
297,
1709,
14,
3190,
8,
2500,
29,
549,
12,
2973,
29,
549,
12,
641,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
370,
534,
2219,
14,
6592,
3855,
355,
661,
6060,
297,
1709,
14,
7624,
8,
2407,
63,
354,
534,
3707,
297,
370,
534,
2219,
14,
7980,
3855,
288,
2156,
267,
2318,
267,
6180
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
27510,
24,
26,
8151,
199,
3,
17065,
701,
5634,
413,
14,
25,
641,
7800,
13,
614,
13,
1465,
3193,
26,
1398,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
1639,
14,
697,
14,
992,
14,
14281,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
2536,
275,
715,
339,
5124,
275,
359,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
33,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
8,
2500,
29,
549,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
34,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
65,
297,
1709,
14,
14298,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
4048,
63,
354,
534,
66,
297,
370,
534,
2219,
14,
33,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
35,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
66,
297,
1709,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
4048,
63,
354,
534,
1259,
297,
370,
534,
2219,
14,
34,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
21548,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
36,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
8,
2500,
29,
549,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
36,
974,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
4000,
355,
661,
70,
300,
63,
2326,
297,
1709,
14,
6254,
4000,
355,
661,
6493,
297,
1709,
14,
6254,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
2390,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
4000,
355,
661,
1205,
297,
1709,
14,
6254,
8,
885,
29,
66,
7,
1818,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
2448,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
40,
9050,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
4000,
355,
661,
6493,
297,
1709,
14,
6254,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
6592,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
4000,
355,
661,
6582,
297,
1709,
14,
6254,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
7980,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
4000,
355,
661,
600,
297,
1709,
14,
3901,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
5736,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
2918,
63,
354,
297,
1709,
14,
6254,
4000,
355,
661,
8311,
63,
633,
297,
1709,
14,
6254,
8,
2500,
29,
549,
12,
2973,
29,
549,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
1899,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
354,
297,
1709,
14,
6254,
4000,
355,
661,
2019,
63,
354,
297,
1709,
14,
6254,
4000,
355,
661,
2634,
297,
1709,
14,
7624,
8,
2407,
63,
354,
534,
3707,
297,
370,
534,
2219,
14,
2448,
3855,
355,
661,
1985,
297,
1709,
14,
3190,
8,
2500,
29,
549,
12,
2973,
29,
549,
12,
641,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
370,
534,
2219,
14,
6592,
3855,
355,
661,
6060,
297,
1709,
14,
7624,
8,
2407,
63,
354,
534,
3707,
297,
370,
534,
2219,
14,
7980,
3855,
288,
2156,
267,
2318,
267,
6180,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
omnirom/android_external_chromium-org
|
tools/profile_chrome/systrace_controller.py
|
59
|
2926
|
# 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 threading
import zlib
from profile_chrome import controllers
from profile_chrome import util
from pylib import cmd_helper
_SYSTRACE_OPTIONS = [
# Compress the trace before sending it over USB.
'-z',
# Use a large trace buffer to increase the polling interval.
'-b', '16384'
]
# Interval in seconds for sampling systrace data.
_SYSTRACE_INTERVAL = 15
class SystraceController(controllers.BaseController):
def __init__(self, device, categories, ring_buffer):
controllers.BaseController.__init__(self)
self._device = device
self._categories = categories
self._ring_buffer = ring_buffer
self._done = threading.Event()
self._thread = None
self._trace_data = None
def __repr__(self):
return 'systrace'
@staticmethod
def GetCategories(device):
return device.RunShellCommand('atrace --list_categories')
def StartTracing(self, _):
self._thread = threading.Thread(target=self._CollectData)
self._thread.start()
def StopTracing(self):
self._done.set()
def PullTrace(self):
self._thread.join()
self._thread = None
if self._trace_data:
output_name = 'systrace-%s' % util.GetTraceTimestamp()
with open(output_name, 'w') as out:
out.write(self._trace_data)
return output_name
def _RunATraceCommand(self, command):
# We use a separate interface to adb because the one from AndroidCommands
# isn't re-entrant.
# TODO(jbudorick) Look at providing a way to unhandroll this once the
# adb rewrite has fully landed.
device_param = (['-s', str(self._device)] if str(self._device) else [])
cmd = ['adb'] + device_param + ['shell', 'atrace', '--%s' % command] + \
_SYSTRACE_OPTIONS + self._categories
return cmd_helper.GetCmdOutput(cmd)
def _CollectData(self):
trace_data = []
self._RunATraceCommand('async_start')
try:
while not self._done.is_set():
self._done.wait(_SYSTRACE_INTERVAL)
if not self._ring_buffer or self._done.is_set():
trace_data.append(
self._DecodeTraceData(self._RunATraceCommand('async_dump')))
finally:
trace_data.append(
self._DecodeTraceData(self._RunATraceCommand('async_stop')))
self._trace_data = ''.join([zlib.decompress(d) for d in trace_data])
@staticmethod
def _DecodeTraceData(trace_data):
try:
trace_start = trace_data.index('TRACE:')
except ValueError:
raise RuntimeError('Systrace start marker not found')
trace_data = trace_data[trace_start + 6:]
# Collapse CRLFs that are added by adb shell.
if trace_data.startswith('\r\n'):
trace_data = trace_data.replace('\r\n', '\n')
# Skip the initial newline.
return trace_data[1:]
|
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,
5796,
199,
646,
12472,
199,
199,
504,
4690,
63,
9887,
492,
27325,
199,
504,
4690,
63,
9887,
492,
4884,
199,
199,
504,
29219,
492,
2088,
63,
3676,
421,
199,
63,
4669,
3027,
4121,
63,
8808,
275,
359,
272,
327,
3599,
753,
314,
3307,
2544,
10209,
652,
1806,
28655,
14,
272,
2475,
90,
297,
272,
327,
3645,
282,
7031,
3307,
3335,
370,
19781,
314,
12353,
6252,
14,
272,
2475,
66,
297,
283,
975,
8188,
7,
199,
61,
199,
199,
3,
18766,
315,
4696,
367,
15877,
1847,
270,
5986,
666,
14,
199,
63,
4669,
3027,
4121,
63,
17359,
275,
4114,
421,
199,
533,
5515,
270,
5986,
7506,
8,
20531,
14,
1563,
7506,
304,
523,
347,
636,
826,
721,
277,
12,
2243,
12,
9695,
12,
12133,
63,
2738,
304,
272,
27325,
14,
1563,
7506,
855,
826,
721,
277,
9,
272,
291,
423,
1782,
275,
2243,
272,
291,
423,
8906,
275,
9695,
272,
291,
423,
5985,
63,
2738,
275,
12133,
63,
2738,
272,
291,
423,
4456,
275,
5796,
14,
2390,
342,
272,
291,
423,
2671,
275,
488,
272,
291,
423,
3446,
63,
576,
275,
488,
819,
347,
636,
2722,
721,
277,
304,
272,
372,
283,
1786,
270,
5986,
7,
819,
768,
4639,
523,
347,
2372,
28731,
8,
1782,
304,
272,
372,
2243,
14,
2540,
8529,
3110,
360,
292,
5986,
1553,
513,
63,
8906,
358,
819,
347,
7707,
2437,
4477,
8,
277,
12,
27574,
272,
291,
423,
2671,
275,
5796,
14,
4436,
8,
1375,
29,
277,
423,
25023,
1451,
9,
272,
291,
423,
2671,
14,
928,
342,
819,
347,
8015,
2437,
4477,
8,
277,
304,
272,
291,
423,
4456,
14,
409,
342,
819,
347,
27705,
3921,
8,
277,
304,
272,
291,
423,
2671,
14,
904,
342,
272,
291,
423,
2671,
275,
488,
272,
340,
291,
423,
3446,
63,
576,
26,
489,
1072,
63,
354,
275,
283,
1786,
270,
5986,
3295,
83,
7,
450,
4884,
14,
1002,
3921,
10239,
342,
489,
543,
1551,
8,
1199,
63,
354,
12,
283,
87,
358,
465,
734,
26,
267,
734,
14,
952,
8,
277,
423,
3446,
63,
576,
9,
489,
372,
1072,
63,
354,
819,
347,
485,
2540,
619,
5986,
3110,
8,
277,
12,
1414,
304,
272,
327,
2136,
675,
282,
7396,
3217,
370,
28173,
2952,
314,
1373,
687,
14694,
14680,
272,
327,
5712,
1133,
295,
13,
18626,
867,
14,
272,
327,
3254,
8,
74,
464,
68,
269,
2000,
9,
12077,
737,
13070,
282,
4340,
370,
625,
6868,
2827,
642,
5403,
314,
272,
327,
463,
28173,
19913,
965,
9999,
634,
7028,
14,
272,
2243,
63,
635,
275,
21022,
13,
83,
297,
620,
8,
277,
423,
1782,
1874,
340,
620,
8,
277,
423,
1782,
9,
587,
3073,
272,
2088,
275,
788,
13741,
418,
435,
2243,
63,
635,
435,
788,
5641,
297,
283,
292,
5986,
297,
2850,
5,
83,
7,
450,
1414,
61,
435,
971,
267,
485,
4669,
3027,
4121,
63,
8808,
435,
291,
423,
8906,
272,
372,
2088,
63,
3676,
14,
1002,
7874,
2959,
8,
1760,
9,
819,
347,
485,
25023,
1451,
8,
277,
304,
272,
3307,
63,
576,
275,
942,
272,
291,
423,
2540,
619,
5986,
3110,
360,
4146,
63,
928,
358,
272,
862,
26,
489,
1830,
440,
291,
423,
4456,
14,
374,
63,
409,
837,
267,
291,
423,
4456,
14,
2573,
1547,
4669,
3027,
4121,
63,
17359,
9,
267,
340,
440,
291,
423,
5985,
63,
2738,
503,
291,
423,
4456,
14,
374,
63,
409,
837,
881,
3307,
63,
576,
14,
740,
8,
1598,
291,
423,
9400,
3921,
1451,
8,
277,
423,
2540,
619,
5986,
3110,
360,
4146,
63,
2724,
7058,
272,
3753,
26,
489,
3307,
63,
576,
14,
740,
8,
881,
291,
423,
9400,
3921,
1451,
8,
277,
423,
2540,
619,
5986,
3110,
360,
4146,
63,
2379,
7058,
272,
291,
423,
3446,
63,
576,
275,
6522,
904,
779,
15371,
14,
14954,
8,
68,
9,
367,
366,
315,
3307,
63,
576,
566,
819,
768,
4639,
523,
347,
485,
9400,
3921,
1451,
8,
3446,
63,
576,
304,
272,
862,
26,
489,
3307,
63,
928,
275,
3307,
63,
576,
14,
1080,
360,
20112,
10993,
272,
871,
1722,
26,
489,
746,
6064,
360,
4323,
270,
5986,
1343,
3608,
440,
1911,
358,
272,
3307,
63,
576,
275,
3307,
63,
576,
59,
3446,
63,
928,
435,
1227,
2938,
339,
327,
3626,
12057,
445,
2431,
19239,
626,
787,
3483,
701,
28173,
5218,
14,
272,
340,
3307,
63,
576,
14,
2460,
2258,
82,
60,
78,
735,
489,
3307,
63,
576,
275,
3307,
63,
576,
14,
1814,
2258,
82,
60,
78,
297,
1557,
78,
358,
339,
327,
8232,
314,
2536,
8057,
14,
272,
372,
3307,
63,
576,
59,
17,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
5796,
199,
646,
12472,
199,
199,
504,
4690,
63,
9887,
492,
27325,
199,
504,
4690,
63,
9887,
492,
4884,
199,
199,
504,
29219,
492,
2088,
63,
3676,
421,
199,
63,
4669,
3027,
4121,
63,
8808,
275,
359,
272,
327,
3599,
753,
314,
3307,
2544,
10209,
652,
1806,
28655,
14,
272,
2475,
90,
297,
272,
327,
3645,
282,
7031,
3307,
3335,
370,
19781,
314,
12353,
6252,
14,
272,
2475,
66,
297,
283,
975,
8188,
7,
199,
61,
199,
199,
3,
18766,
315,
4696,
367,
15877,
1847,
270,
5986,
666,
14,
199,
63,
4669,
3027,
4121,
63,
17359,
275,
4114,
421,
199,
533,
5515,
270,
5986,
7506,
8,
20531,
14,
1563,
7506,
304,
523,
347,
636,
826,
721,
277,
12,
2243,
12,
9695,
12,
12133,
63,
2738,
304,
272,
27325,
14,
1563,
7506,
855,
826,
721,
277,
9,
272,
291,
423,
1782,
275,
2243,
272,
291,
423,
8906,
275,
9695,
272,
291,
423,
5985,
63,
2738,
275,
12133,
63,
2738,
272,
291,
423,
4456,
275,
5796,
14,
2390,
342,
272,
291,
423,
2671,
275,
488,
272,
291,
423,
3446,
63,
576,
275,
488,
819,
347,
636,
2722,
721,
277,
304,
272,
372,
283,
1786,
270,
5986,
7,
819,
768,
4639,
523,
347,
2372,
28731,
8,
1782,
304,
272,
372,
2243,
14,
2540,
8529,
3110,
360,
292,
5986,
1553,
513,
63,
8906,
358,
819,
347,
7707,
2437,
4477,
8,
277,
12,
27574,
272,
291,
423,
2671,
275,
5796,
14,
4436,
8,
1375,
29,
277,
423,
25023,
1451,
9,
272,
291,
423,
2671,
14,
928,
342,
819,
347,
8015,
2437,
4477,
8,
277,
304,
272,
291,
423,
4456,
14,
409,
342,
819,
347,
27705,
3921,
8,
277,
304,
272,
291,
423,
2671,
14,
904,
342,
272,
291,
423,
2671,
275,
488,
272,
340,
291,
423,
3446,
63,
576,
26,
489,
1072,
63,
354,
275,
283,
1786,
270,
5986,
3295,
83,
7,
450,
4884,
14,
1002,
3921,
10239,
342,
489,
543,
1551,
8,
1199,
63,
354,
12,
283,
87,
358,
465,
734,
26,
267,
734,
14,
952,
8,
277,
423,
3446,
63,
576,
9,
489,
372,
1072,
63,
354,
819,
347,
485,
2540,
619,
5986,
3110,
8,
277,
12,
1414,
304,
272,
327,
2136,
675,
282,
7396,
3217,
370,
28173,
2952,
314,
1373,
687,
14694,
14680,
272,
327,
5712,
1133,
295,
13,
18626,
867,
14,
272,
327,
3254,
8,
74,
464,
68,
269,
2000,
9,
12077,
737,
13070,
282,
4340,
370,
625,
6868,
2827,
642,
5403,
314,
272,
327,
463,
28173,
19913,
965,
9999,
634,
7028,
14,
272,
2243,
63,
635,
275,
21022,
13,
83,
297,
620,
8,
277,
423,
1782,
1874,
340,
620,
8,
277,
423,
1782,
9,
587,
3073,
272,
2088,
275,
788,
13741,
418,
435,
2243,
63,
635,
435,
788,
5641,
297,
283,
292,
5986,
297,
2850,
5,
83,
7,
450,
1414,
61,
435,
971,
267,
485,
4669,
3027,
4121,
63,
8808,
435,
291,
423,
8906,
272,
372,
2088,
63,
3676,
14,
1002,
7874,
2959,
8,
1760,
9,
819,
347,
485,
25023,
1451,
8,
277,
304,
272,
3307,
63,
576,
275,
942,
272,
291,
423,
2540,
619,
5986,
3110,
360,
4146,
63,
928,
358,
272,
862,
26,
489,
1830,
440,
291,
423,
4456,
14,
374,
63,
409,
837,
267,
291,
423,
4456,
14,
2573,
1547,
4669,
3027,
4121,
63,
17359,
9,
267,
340,
440,
291,
423,
5985,
63,
2738,
503,
291,
423,
4456,
14,
374,
63,
409,
837,
881,
3307,
63,
576,
14,
740,
8,
1598,
291,
423,
9400,
3921,
1451,
8,
277,
423,
2540,
619,
5986,
3110,
360,
4146,
63,
2724,
7058,
272,
3753,
26,
489,
3307,
63,
576,
14,
740,
8,
881,
291,
423,
9400,
3921,
1451,
8,
277,
423,
2540,
619,
5986,
3110,
360,
4146,
63,
2379,
7058,
272,
291,
423,
3446,
63,
576,
275,
6522,
904,
779,
15371,
14,
14954,
8,
68,
9,
367,
366,
315,
3307,
63,
576,
566,
819,
768,
4639,
523,
347,
485,
9400,
3921,
1451,
8,
3446,
63,
576,
304,
272,
862,
26,
489,
3307,
63,
928,
275,
3307,
63,
576,
14,
1080,
360,
20112,
10993,
272,
871,
1722,
26,
489,
746,
6064,
360,
4323,
270,
5986,
1343,
3608,
440,
1911,
358,
272,
3307,
63,
576,
275,
3307,
63,
576,
59,
3446,
63,
928,
435,
1227,
2938,
339,
327,
3626,
12057,
445,
2431,
19239,
626,
787,
3483,
701,
28173,
5218,
14,
272,
340,
3307,
63,
576,
14,
2460,
2258,
82,
60,
78,
735,
489,
3307,
63,
576,
275,
3307,
63,
576,
14,
1814,
2258,
82,
60,
78,
297,
1557,
78,
358,
339,
327,
8232,
314,
2536,
8057,
14,
272,
372,
3307,
63,
576,
59,
17,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
emidln/django_roa
|
env/lib/python2.7/site-packages/django/views/generic/create_update.py
|
245
|
8935
|
from django.forms.models import ModelFormMetaclass, ModelForm
from django.template import RequestContext, loader
from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.core.xheaders import populate_xheaders
from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured
from django.utils.translation import ugettext
from django.contrib.auth.views import redirect_to_login
from django.views.generic import GenericViewError
from django.contrib import messages
import warnings
warnings.warn(
'Function-based generic views have been deprecated; use class-based views instead.',
PendingDeprecationWarning
)
def apply_extra_context(extra_context, context):
"""
Adds items from extra_context dict to context. If a value in extra_context
is callable, then it is called and the result is added to context.
"""
for key, value in extra_context.iteritems():
if callable(value):
context[key] = value()
else:
context[key] = value
def get_model_and_form_class(model, form_class):
"""
Returns a model and form class based on the model and form_class
parameters that were passed to the generic view.
If ``form_class`` is given then its associated model will be returned along
with ``form_class`` itself. Otherwise, if ``model`` is given, ``model``
itself will be returned along with a ``ModelForm`` class created from
``model``.
"""
if form_class:
return form_class._meta.model, form_class
if model:
# The inner Meta class fails if model = model is used for some reason.
tmp_model = model
# TODO: we should be able to construct a ModelForm without creating
# and passing in a temporary inner class.
class Meta:
model = tmp_model
class_name = model.__name__ + 'Form'
form_class = ModelFormMetaclass(class_name, (ModelForm,), {'Meta': Meta})
return model, form_class
raise GenericViewError("Generic view must be called with either a model or"
" form_class argument.")
def redirect(post_save_redirect, obj):
"""
Returns a HttpResponseRedirect to ``post_save_redirect``.
``post_save_redirect`` should be a string, and can contain named string-
substitution place holders of ``obj`` field names.
If ``post_save_redirect`` is None, then redirect to ``obj``'s URL returned
by ``get_absolute_url()``. If ``obj`` has no ``get_absolute_url`` method,
then raise ImproperlyConfigured.
This function is meant to handle the post_save_redirect parameter to the
``create_object`` and ``update_object`` views.
"""
if post_save_redirect:
return HttpResponseRedirect(post_save_redirect % obj.__dict__)
elif hasattr(obj, 'get_absolute_url'):
return HttpResponseRedirect(obj.get_absolute_url())
else:
raise ImproperlyConfigured(
"No URL to redirect to. Either pass a post_save_redirect"
" parameter to the generic view or define a get_absolute_url"
" method on the Model.")
def lookup_object(model, object_id, slug, slug_field):
"""
Return the ``model`` object with the passed ``object_id``. If
``object_id`` is None, then return the object whose ``slug_field``
equals the passed ``slug``. If ``slug`` and ``slug_field`` are not passed,
then raise Http404 exception.
"""
lookup_kwargs = {}
if object_id:
lookup_kwargs['%s__exact' % model._meta.pk.name] = object_id
elif slug and slug_field:
lookup_kwargs['%s__exact' % slug_field] = slug
else:
raise GenericViewError(
"Generic view must be called with either an object_id or a"
" slug/slug_field.")
try:
return model.objects.get(**lookup_kwargs)
except ObjectDoesNotExist:
raise Http404("No %s found for %s"
% (model._meta.verbose_name, lookup_kwargs))
def create_object(request, model=None, template_name=None,
template_loader=loader, extra_context=None, post_save_redirect=None,
login_required=False, context_processors=None, form_class=None):
"""
Generic object-creation function.
Templates: ``<app_label>/<model_name>_form.html``
Context:
form
the form for the object
"""
if extra_context is None: extra_context = {}
if login_required and not request.user.is_authenticated():
return redirect_to_login(request.path)
model, form_class = get_model_and_form_class(model, form_class)
if request.method == 'POST':
form = form_class(request.POST, request.FILES)
if form.is_valid():
new_object = form.save()
msg = ugettext("The %(verbose_name)s was created successfully.") %\
{"verbose_name": model._meta.verbose_name}
messages.success(request, msg, fail_silently=True)
return redirect(post_save_redirect, new_object)
else:
form = form_class()
# Create the template, context, response
if not template_name:
template_name = "%s/%s_form.html" % (model._meta.app_label, model._meta.object_name.lower())
t = template_loader.get_template(template_name)
c = RequestContext(request, {
'form': form,
}, context_processors)
apply_extra_context(extra_context, c)
return HttpResponse(t.render(c))
def update_object(request, model=None, object_id=None, slug=None,
slug_field='slug', template_name=None, template_loader=loader,
extra_context=None, post_save_redirect=None, login_required=False,
context_processors=None, template_object_name='object',
form_class=None):
"""
Generic object-update function.
Templates: ``<app_label>/<model_name>_form.html``
Context:
form
the form for the object
object
the original object being edited
"""
if extra_context is None: extra_context = {}
if login_required and not request.user.is_authenticated():
return redirect_to_login(request.path)
model, form_class = get_model_and_form_class(model, form_class)
obj = lookup_object(model, object_id, slug, slug_field)
if request.method == 'POST':
form = form_class(request.POST, request.FILES, instance=obj)
if form.is_valid():
obj = form.save()
msg = ugettext("The %(verbose_name)s was updated successfully.") %\
{"verbose_name": model._meta.verbose_name}
messages.success(request, msg, fail_silently=True)
return redirect(post_save_redirect, obj)
else:
form = form_class(instance=obj)
if not template_name:
template_name = "%s/%s_form.html" % (model._meta.app_label, model._meta.object_name.lower())
t = template_loader.get_template(template_name)
c = RequestContext(request, {
'form': form,
template_object_name: obj,
}, context_processors)
apply_extra_context(extra_context, c)
response = HttpResponse(t.render(c))
populate_xheaders(request, response, model, getattr(obj, obj._meta.pk.attname))
return response
def delete_object(request, model, post_delete_redirect, object_id=None,
slug=None, slug_field='slug', template_name=None,
template_loader=loader, extra_context=None, login_required=False,
context_processors=None, template_object_name='object'):
"""
Generic object-delete function.
The given template will be used to confirm deletetion if this view is
fetched using GET; for safty, deletion will only be performed if this
view is POSTed.
Templates: ``<app_label>/<model_name>_confirm_delete.html``
Context:
object
the original object being deleted
"""
if extra_context is None: extra_context = {}
if login_required and not request.user.is_authenticated():
return redirect_to_login(request.path)
obj = lookup_object(model, object_id, slug, slug_field)
if request.method == 'POST':
obj.delete()
msg = ugettext("The %(verbose_name)s was deleted.") %\
{"verbose_name": model._meta.verbose_name}
messages.success(request, msg, fail_silently=True)
return HttpResponseRedirect(post_delete_redirect)
else:
if not template_name:
template_name = "%s/%s_confirm_delete.html" % (model._meta.app_label, model._meta.object_name.lower())
t = template_loader.get_template(template_name)
c = RequestContext(request, {
template_object_name: obj,
}, context_processors)
apply_extra_context(extra_context, c)
response = HttpResponse(t.render(c))
populate_xheaders(request, response, model, getattr(obj, obj._meta.pk.attname))
return response
|
bsd-3-clause
|
[
504,
1639,
14,
3351,
14,
992,
492,
28455,
29387,
12,
28455,
199,
504,
1639,
14,
1160,
492,
22538,
12,
5077,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
12,
6183,
12,
14935,
199,
504,
1639,
14,
1018,
14,
88,
2139,
492,
13904,
63,
88,
2139,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
12,
11897,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
199,
504,
1639,
14,
2828,
14,
1178,
14,
4196,
492,
4660,
63,
475,
63,
2886,
199,
504,
1639,
14,
4196,
14,
6767,
492,
8307,
2768,
547,
199,
504,
1639,
14,
2828,
492,
3788,
199,
199,
646,
3598,
199,
5451,
14,
4050,
8,
272,
283,
3481,
13,
6788,
7809,
6858,
1172,
2757,
5906,
27,
675,
1021,
13,
6788,
6858,
3140,
3130,
272,
29216,
15561,
199,
9,
421,
199,
318,
4838,
63,
2911,
63,
1100,
8,
2911,
63,
1100,
12,
1067,
304,
272,
408,
272,
15747,
2974,
687,
2402,
63,
1100,
1211,
370,
1067,
14,
221,
982,
282,
574,
315,
2402,
63,
1100,
272,
365,
4550,
12,
2066,
652,
365,
2797,
436,
314,
754,
365,
3483,
370,
1067,
14,
272,
408,
272,
367,
790,
12,
574,
315,
2402,
63,
1100,
14,
4611,
837,
267,
340,
4550,
8,
585,
304,
288,
1067,
59,
498,
61,
275,
574,
342,
267,
587,
26,
288,
1067,
59,
498,
61,
275,
574,
199,
199,
318,
664,
63,
1238,
63,
460,
63,
964,
63,
533,
8,
1238,
12,
1824,
63,
533,
304,
272,
408,
272,
1803,
282,
1402,
436,
1824,
1021,
4079,
641,
314,
1402,
436,
1824,
63,
533,
272,
2633,
626,
4898,
3032,
370,
314,
7809,
2455,
14,
339,
982,
1124,
964,
63,
533,
1040,
365,
1627,
2066,
2399,
4568,
1402,
911,
506,
2138,
3180,
272,
543,
1124,
964,
63,
533,
1040,
6337,
14,
221,
6630,
12,
340,
1124,
1238,
1040,
365,
1627,
12,
1124,
1238,
1040,
272,
6337,
911,
506,
2138,
3180,
543,
282,
1124,
15937,
1040,
1021,
2737,
687,
272,
1124,
1238,
4345,
272,
408,
272,
340,
1824,
63,
533,
26,
267,
372,
1824,
63,
533,
423,
2024,
14,
1238,
12,
1824,
63,
533,
272,
340,
1402,
26,
267,
327,
710,
6506,
6288,
1021,
6918,
340,
1402,
275,
1402,
365,
1202,
367,
2005,
4499,
14,
267,
3529,
63,
1238,
275,
1402,
267,
327,
3254,
26,
781,
1077,
506,
7688,
370,
6982,
282,
28455,
1928,
6425,
267,
327,
436,
9476,
315,
282,
7937,
6506,
1021,
14,
267,
1021,
6288,
26,
288,
1402,
275,
3529,
63,
1238,
267,
1021,
63,
354,
275,
1402,
855,
354,
363,
435,
283,
2821,
7,
267,
1824,
63,
533,
275,
28455,
29387,
8,
533,
63,
354,
12,
334,
15937,
4706,
791,
3396,
356,
6288,
1552,
267,
372,
1402,
12,
1824,
63,
533,
272,
746,
8307,
2768,
547,
480,
9417,
2455,
1471,
506,
2797,
543,
1902,
282,
1402,
503,
2,
2574,
298,
1824,
63,
533,
1423,
2685,
199,
199,
318,
4660,
8,
1932,
63,
2117,
63,
4876,
12,
1559,
304,
272,
408,
272,
1803,
282,
14935,
370,
1124,
1932,
63,
2117,
63,
4876,
4345,
339,
1124,
1932,
63,
2117,
63,
4876,
1040,
1077,
506,
282,
1059,
12,
436,
883,
1395,
4310,
1059,
13,
272,
20584,
4192,
31976,
402,
1124,
1113,
1040,
901,
1561,
14,
339,
982,
1124,
1932,
63,
2117,
63,
4876,
1040,
365,
488,
12,
2066,
4660,
370,
1124,
1113,
1040,
7,
83,
2851,
2138,
272,
701,
1124,
362,
63,
6116,
63,
633,
28566,
221,
982,
1124,
1113,
1040,
965,
949,
1124,
362,
63,
6116,
63,
633,
1040,
1083,
12,
272,
2066,
746,
11897,
14,
339,
961,
805,
365,
18329,
370,
2429,
314,
2963,
63,
2117,
63,
4876,
2725,
370,
314,
272,
1124,
981,
63,
785,
1040,
436,
1124,
873,
63,
785,
1040,
6858,
14,
272,
408,
272,
340,
2963,
63,
2117,
63,
4876,
26,
267,
372,
14935,
8,
1932,
63,
2117,
63,
4876,
450,
1559,
855,
807,
3368,
272,
916,
2688,
8,
1113,
12,
283,
362,
63,
6116,
63,
633,
735,
267,
372,
14935,
8,
1113,
14,
362,
63,
6116,
63,
633,
1012,
272,
587,
26,
267,
746,
11897,
8,
288,
298,
1944,
2851,
370,
4660,
370,
14,
221,
13083,
986,
282,
2963,
63,
2117,
63,
4876,
2,
288,
298,
2725,
370,
314,
7809,
2455,
503,
5627,
282,
664,
63,
6116,
63,
633,
2,
288,
298,
1083,
641,
314,
5822,
2685,
199,
199,
318,
4237,
63,
785,
8,
1238,
12,
909,
63,
344,
12,
8889,
12,
8889,
63,
698,
304,
272,
408,
272,
1432,
314,
1124,
1238,
1040,
909,
543,
314,
3032,
1124,
785,
63,
344,
4345,
221,
982,
272,
1124,
785,
63,
344,
1040,
365,
488,
12,
2066,
372,
314,
909,
7447,
1124,
5464,
63,
698,
1040,
272,
18527,
314,
3032,
1124,
5464,
4345,
221,
982,
1124,
5464,
1040,
436,
1124,
5464,
63,
698,
1040,
787,
440,
3032,
12,
272,
2066,
746,
4760,
5188,
1919,
14,
272,
408,
272,
4237,
63,
958,
275,
1052,
272,
340,
909,
63,
344,
26,
267,
4237,
63,
958,
13890,
83,
363,
7327,
7,
450,
1402,
423,
2024,
14,
2051,
14,
354,
61,
275,
909,
63,
344,
272,
916,
8889,
436,
8889,
63,
698,
26,
267,
4237,
63,
958,
13890,
83,
363,
7327,
7,
450,
8889,
63,
698,
61,
275,
8889,
272,
587,
26,
267,
746,
8307,
2768,
547,
8,
288,
298,
9417,
2455,
1471,
506,
2797,
543,
1902,
376,
909,
63,
344,
503,
282,
2,
288,
298,
8889,
15,
5464,
63,
698,
2685,
272,
862,
26,
267,
372,
1402,
14,
1462,
14,
362,
3682,
3892,
63,
958,
9,
272,
871,
24803,
26,
267,
746,
4760,
5188,
480,
1944,
450,
83,
1911,
367,
450,
83,
2,
1993,
450,
334,
1238,
423,
2024,
14,
3832,
63,
354,
12,
4237,
63,
958,
430,
199,
199,
318,
1218,
63,
785,
8,
1069,
12,
1402,
29,
403,
12,
1978,
63,
354,
29,
403,
12,
267,
1978,
63,
3422,
29,
3422,
12,
2402,
63,
1100,
29,
403,
12,
2963,
63,
2117,
63,
4876,
29,
403,
12,
267,
4676,
63,
2427,
29,
797,
12,
1067,
63,
10547,
29,
403,
12,
1824,
63,
533,
29,
403,
304,
272,
408,
272,
8307,
909,
13,
8782,
805,
14,
339,
31273,
26,
23696,
571,
63,
1302,
23220,
1238,
63,
354,
30,
63,
964,
14,
1360,
1040,
272,
9470,
26,
267,
1824,
288,
314,
1824
] |
[
1639,
14,
3351,
14,
992,
492,
28455,
29387,
12,
28455,
199,
504,
1639,
14,
1160,
492,
22538,
12,
5077,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
12,
6183,
12,
14935,
199,
504,
1639,
14,
1018,
14,
88,
2139,
492,
13904,
63,
88,
2139,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
12,
11897,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
199,
504,
1639,
14,
2828,
14,
1178,
14,
4196,
492,
4660,
63,
475,
63,
2886,
199,
504,
1639,
14,
4196,
14,
6767,
492,
8307,
2768,
547,
199,
504,
1639,
14,
2828,
492,
3788,
199,
199,
646,
3598,
199,
5451,
14,
4050,
8,
272,
283,
3481,
13,
6788,
7809,
6858,
1172,
2757,
5906,
27,
675,
1021,
13,
6788,
6858,
3140,
3130,
272,
29216,
15561,
199,
9,
421,
199,
318,
4838,
63,
2911,
63,
1100,
8,
2911,
63,
1100,
12,
1067,
304,
272,
408,
272,
15747,
2974,
687,
2402,
63,
1100,
1211,
370,
1067,
14,
221,
982,
282,
574,
315,
2402,
63,
1100,
272,
365,
4550,
12,
2066,
652,
365,
2797,
436,
314,
754,
365,
3483,
370,
1067,
14,
272,
408,
272,
367,
790,
12,
574,
315,
2402,
63,
1100,
14,
4611,
837,
267,
340,
4550,
8,
585,
304,
288,
1067,
59,
498,
61,
275,
574,
342,
267,
587,
26,
288,
1067,
59,
498,
61,
275,
574,
199,
199,
318,
664,
63,
1238,
63,
460,
63,
964,
63,
533,
8,
1238,
12,
1824,
63,
533,
304,
272,
408,
272,
1803,
282,
1402,
436,
1824,
1021,
4079,
641,
314,
1402,
436,
1824,
63,
533,
272,
2633,
626,
4898,
3032,
370,
314,
7809,
2455,
14,
339,
982,
1124,
964,
63,
533,
1040,
365,
1627,
2066,
2399,
4568,
1402,
911,
506,
2138,
3180,
272,
543,
1124,
964,
63,
533,
1040,
6337,
14,
221,
6630,
12,
340,
1124,
1238,
1040,
365,
1627,
12,
1124,
1238,
1040,
272,
6337,
911,
506,
2138,
3180,
543,
282,
1124,
15937,
1040,
1021,
2737,
687,
272,
1124,
1238,
4345,
272,
408,
272,
340,
1824,
63,
533,
26,
267,
372,
1824,
63,
533,
423,
2024,
14,
1238,
12,
1824,
63,
533,
272,
340,
1402,
26,
267,
327,
710,
6506,
6288,
1021,
6918,
340,
1402,
275,
1402,
365,
1202,
367,
2005,
4499,
14,
267,
3529,
63,
1238,
275,
1402,
267,
327,
3254,
26,
781,
1077,
506,
7688,
370,
6982,
282,
28455,
1928,
6425,
267,
327,
436,
9476,
315,
282,
7937,
6506,
1021,
14,
267,
1021,
6288,
26,
288,
1402,
275,
3529,
63,
1238,
267,
1021,
63,
354,
275,
1402,
855,
354,
363,
435,
283,
2821,
7,
267,
1824,
63,
533,
275,
28455,
29387,
8,
533,
63,
354,
12,
334,
15937,
4706,
791,
3396,
356,
6288,
1552,
267,
372,
1402,
12,
1824,
63,
533,
272,
746,
8307,
2768,
547,
480,
9417,
2455,
1471,
506,
2797,
543,
1902,
282,
1402,
503,
2,
2574,
298,
1824,
63,
533,
1423,
2685,
199,
199,
318,
4660,
8,
1932,
63,
2117,
63,
4876,
12,
1559,
304,
272,
408,
272,
1803,
282,
14935,
370,
1124,
1932,
63,
2117,
63,
4876,
4345,
339,
1124,
1932,
63,
2117,
63,
4876,
1040,
1077,
506,
282,
1059,
12,
436,
883,
1395,
4310,
1059,
13,
272,
20584,
4192,
31976,
402,
1124,
1113,
1040,
901,
1561,
14,
339,
982,
1124,
1932,
63,
2117,
63,
4876,
1040,
365,
488,
12,
2066,
4660,
370,
1124,
1113,
1040,
7,
83,
2851,
2138,
272,
701,
1124,
362,
63,
6116,
63,
633,
28566,
221,
982,
1124,
1113,
1040,
965,
949,
1124,
362,
63,
6116,
63,
633,
1040,
1083,
12,
272,
2066,
746,
11897,
14,
339,
961,
805,
365,
18329,
370,
2429,
314,
2963,
63,
2117,
63,
4876,
2725,
370,
314,
272,
1124,
981,
63,
785,
1040,
436,
1124,
873,
63,
785,
1040,
6858,
14,
272,
408,
272,
340,
2963,
63,
2117,
63,
4876,
26,
267,
372,
14935,
8,
1932,
63,
2117,
63,
4876,
450,
1559,
855,
807,
3368,
272,
916,
2688,
8,
1113,
12,
283,
362,
63,
6116,
63,
633,
735,
267,
372,
14935,
8,
1113,
14,
362,
63,
6116,
63,
633,
1012,
272,
587,
26,
267,
746,
11897,
8,
288,
298,
1944,
2851,
370,
4660,
370,
14,
221,
13083,
986,
282,
2963,
63,
2117,
63,
4876,
2,
288,
298,
2725,
370,
314,
7809,
2455,
503,
5627,
282,
664,
63,
6116,
63,
633,
2,
288,
298,
1083,
641,
314,
5822,
2685,
199,
199,
318,
4237,
63,
785,
8,
1238,
12,
909,
63,
344,
12,
8889,
12,
8889,
63,
698,
304,
272,
408,
272,
1432,
314,
1124,
1238,
1040,
909,
543,
314,
3032,
1124,
785,
63,
344,
4345,
221,
982,
272,
1124,
785,
63,
344,
1040,
365,
488,
12,
2066,
372,
314,
909,
7447,
1124,
5464,
63,
698,
1040,
272,
18527,
314,
3032,
1124,
5464,
4345,
221,
982,
1124,
5464,
1040,
436,
1124,
5464,
63,
698,
1040,
787,
440,
3032,
12,
272,
2066,
746,
4760,
5188,
1919,
14,
272,
408,
272,
4237,
63,
958,
275,
1052,
272,
340,
909,
63,
344,
26,
267,
4237,
63,
958,
13890,
83,
363,
7327,
7,
450,
1402,
423,
2024,
14,
2051,
14,
354,
61,
275,
909,
63,
344,
272,
916,
8889,
436,
8889,
63,
698,
26,
267,
4237,
63,
958,
13890,
83,
363,
7327,
7,
450,
8889,
63,
698,
61,
275,
8889,
272,
587,
26,
267,
746,
8307,
2768,
547,
8,
288,
298,
9417,
2455,
1471,
506,
2797,
543,
1902,
376,
909,
63,
344,
503,
282,
2,
288,
298,
8889,
15,
5464,
63,
698,
2685,
272,
862,
26,
267,
372,
1402,
14,
1462,
14,
362,
3682,
3892,
63,
958,
9,
272,
871,
24803,
26,
267,
746,
4760,
5188,
480,
1944,
450,
83,
1911,
367,
450,
83,
2,
1993,
450,
334,
1238,
423,
2024,
14,
3832,
63,
354,
12,
4237,
63,
958,
430,
199,
199,
318,
1218,
63,
785,
8,
1069,
12,
1402,
29,
403,
12,
1978,
63,
354,
29,
403,
12,
267,
1978,
63,
3422,
29,
3422,
12,
2402,
63,
1100,
29,
403,
12,
2963,
63,
2117,
63,
4876,
29,
403,
12,
267,
4676,
63,
2427,
29,
797,
12,
1067,
63,
10547,
29,
403,
12,
1824,
63,
533,
29,
403,
304,
272,
408,
272,
8307,
909,
13,
8782,
805,
14,
339,
31273,
26,
23696,
571,
63,
1302,
23220,
1238,
63,
354,
30,
63,
964,
14,
1360,
1040,
272,
9470,
26,
267,
1824,
288,
314,
1824,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ravibhure/ansible
|
lib/ansible/modules/storage/netapp/netapp_e_snapshot_images.py
|
42
|
8818
|
#!/usr/bin/python
# (c) 2016, NetApp, Inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = """
---
module: netapp_e_snapshot_images
short_description: Create and delete snapshot images
description:
- Create and delete snapshots images on snapshot groups for NetApp E-series storage arrays.
- Only the oldest snapshot image can be deleted so consistency is preserved.
- "Related: Snapshot volumes are created from snapshot images."
version_added: '2.2'
author: Kevin Hulquest (@hulquest)
options:
api_username:
required: true
description:
- The username to authenticate with the SANtricity WebServices Proxy or embedded REST API.
api_password:
required: true
description:
- The password to authenticate with the SANtricity WebServices Proxy or embedded REST API.
api_url:
required: true
description:
- The url to the SANtricity WebServices Proxy or embedded REST API.
validate_certs:
required: false
default: true
description:
- Should https certificates be validated?
snapshot_group:
description:
- The name of the snapshot group in which you want to create a snapshot image.
required: True
state:
description:
- Whether a new snapshot image should be created or oldest be deleted.
required: True
choices: ['create', 'remove']
"""
EXAMPLES = """
- name: Create Snapshot
netapp_e_snapshot_images:
ssid: "{{ ssid }}"
api_url: "{{ netapp_api_url }}"
api_username: "{{ netapp_api_username }}"
api_password: "{{ netapp_api_password }}"
validate_certs: "{{ validate_certs }}"
snapshot_group: "3300000060080E5000299C24000005B656D9F394"
state: 'create'
"""
RETURN = """
---
msg:
description: State of operation
type: string
returned: always
sample: "Created snapshot image"
image_id:
description: ID of snaphot image
type: string
returned: state == created
sample: "3400000060080E5000299B640063074057BC5C5E "
"""
HEADERS = {
"Content-Type": "application/json",
"Accept": "application/json",
}
import json
from ansible.module_utils.api import basic_auth_argument_spec
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.urls import open_url
from ansible.module_utils.six.moves.urllib.error import HTTPError
def request(url, data=None, headers=None, method='GET', use_proxy=True,
force=False, last_mod_time=None, timeout=10, validate_certs=True,
url_username=None, url_password=None, http_agent=None, force_basic_auth=True, ignore_errors=False):
try:
r = open_url(url=url, data=data, headers=headers, method=method, use_proxy=use_proxy,
force=force, last_mod_time=last_mod_time, timeout=timeout, validate_certs=validate_certs,
url_username=url_username, url_password=url_password, http_agent=http_agent,
force_basic_auth=force_basic_auth)
except HTTPError:
err = get_exception()
r = err.fp
try:
raw_data = r.read()
if raw_data:
data = json.loads(raw_data)
else:
raw_data = None
except:
if ignore_errors:
pass
else:
raise Exception(raw_data)
resp_code = r.getcode()
if resp_code >= 400 and not ignore_errors:
raise Exception(resp_code, data)
else:
return resp_code, data
def snapshot_group_from_name(module, ssid, api_url, api_pwd, api_usr, name):
snap_groups = 'storage-systems/%s/snapshot-groups' % ssid
snap_groups_url = api_url + snap_groups
(ret, snapshot_groups) = request(snap_groups_url, url_username=api_usr, url_password=api_pwd, headers=HEADERS,
validate_certs=module.params['validate_certs'])
snapshot_group_id = None
for snapshot_group in snapshot_groups:
if name == snapshot_group['label']:
snapshot_group_id = snapshot_group['pitGroupRef']
break
if snapshot_group_id is None:
module.fail_json(msg="Failed to lookup snapshot group. Group [%s]. Id [%s]." % (name, ssid))
return snapshot_group
def oldest_image(module, ssid, api_url, api_pwd, api_usr, name):
get_status = 'storage-systems/%s/snapshot-images' % ssid
url = api_url + get_status
try:
(ret, images) = request(url, url_username=api_usr, url_password=api_pwd, headers=HEADERS,
validate_certs=module.params['validate_certs'])
except:
err = get_exception()
module.fail_json(msg="Failed to get snapshot images for group. Group [%s]. Id [%s]. Error [%s]" %
(name, ssid, str(err)))
if not images:
module.exit_json(msg="There are no snapshot images to remove. Group [%s]. Id [%s]." % (name, ssid))
oldest = min(images, key=lambda x: x['pitSequenceNumber'])
if oldest is None or "pitRef" not in oldest:
module.fail_json(msg="Failed to lookup oldest snapshot group. Group [%s]. Id [%s]." % (name, ssid))
return oldest
def create_image(module, ssid, api_url, pwd, user, p, snapshot_group):
snapshot_group_obj = snapshot_group_from_name(module, ssid, api_url, pwd, user, snapshot_group)
snapshot_group_id = snapshot_group_obj['pitGroupRef']
endpoint = 'storage-systems/%s/snapshot-images' % ssid
url = api_url + endpoint
post_data = json.dumps({'groupId': snapshot_group_id})
image_data = request(url, data=post_data, method='POST', url_username=user, url_password=pwd, headers=HEADERS,
validate_certs=module.params['validate_certs'])
if image_data[1]['status'] == 'optimal':
status = True
id = image_data[1]['id']
else:
status = False
id = ''
return status, id
def delete_image(module, ssid, api_url, pwd, user, snapshot_group):
image = oldest_image(module, ssid, api_url, pwd, user, snapshot_group)
image_id = image['pitRef']
endpoint = 'storage-systems/%s/snapshot-images/%s' % (ssid, image_id)
url = api_url + endpoint
try:
(ret, image_data) = request(url, method='DELETE', url_username=user, url_password=pwd, headers=HEADERS,
validate_certs=module.params['validate_certs'])
except Exception:
e = get_exception()
image_data = (e[0], e[1])
if ret == 204:
deleted_status = True
error_message = ''
else:
deleted_status = False
error_message = image_data[1]['errorMessage']
return deleted_status, error_message
def main():
argument_spec = basic_auth_argument_spec()
argument_spec.update(dict(
snapshot_group=dict(required=True, type='str'),
ssid=dict(required=True, type='str'),
api_url=dict(required=True),
api_username=dict(required=False),
api_password=dict(required=False, no_log=True),
validate_certs=dict(required=False, default=True),
state=dict(required=True, choices=['create', 'remove'], type='str'),
))
module = AnsibleModule(argument_spec)
p = module.params
ssid = p.pop('ssid')
api_url = p.pop('api_url')
user = p.pop('api_username')
pwd = p.pop('api_password')
snapshot_group = p.pop('snapshot_group')
desired_state = p.pop('state')
if not api_url.endswith('/'):
api_url += '/'
if desired_state == 'create':
created_status, snapshot_id = create_image(module, ssid, api_url, pwd, user, p, snapshot_group)
if created_status:
module.exit_json(changed=True, msg='Created snapshot image', image_id=snapshot_id)
else:
module.fail_json(
msg="Could not create snapshot image on system %s, in snapshot group %s" % (ssid, snapshot_group))
else:
deleted, error_msg = delete_image(module, ssid, api_url, pwd, user, snapshot_group)
if deleted:
module.exit_json(changed=True, msg='Deleted snapshot image for snapshot group [%s]' % (snapshot_group))
else:
module.fail_json(
msg="Could not create snapshot image on system %s, in snapshot group %s --- %s" % (
ssid, snapshot_group, error_msg))
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
334,
67,
9,
7800,
12,
28076,
12,
3277,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
15742,
63,
69,
63,
4753,
63,
4782,
199,
3612,
63,
1802,
26,
2790,
436,
3145,
5740,
5935,
199,
1802,
26,
272,
446,
2790,
436,
3145,
19076,
5935,
641,
5740,
4652,
367,
28076,
662,
13,
5602,
4887,
6572,
14,
272,
446,
5972,
314,
29493,
5740,
1834,
883,
506,
5463,
880,
17754,
365,
17731,
14,
272,
446,
298,
13885,
26,
23896,
12158,
787,
2737,
687,
5740,
5935,
2122,
199,
1023,
63,
3270,
26,
283,
18,
14,
18,
7,
199,
2502,
26,
25645,
11908,
869,
348,
613,
8593,
72,
348,
613,
9,
199,
1419,
26,
272,
2986,
63,
2473,
26,
267,
1415,
26,
2549,
267,
1369,
26,
267,
446,
710,
3434,
370,
12895,
543,
314,
428,
879,
599,
3690,
6001,
15803,
12373,
503,
12169,
14880,
3261,
14,
272,
2986,
63,
2060,
26,
267,
1415,
26,
2549,
267,
1369,
26,
267,
446,
710,
2505,
370,
12895,
543,
314,
428,
879,
599,
3690,
6001,
15803,
12373,
503,
12169,
14880,
3261,
14,
272,
2986,
63,
633,
26,
267,
1415,
26,
2549,
267,
1369,
26,
267,
446,
710,
1166,
370,
314,
428,
879,
599,
3690,
6001,
15803,
12373,
503,
12169,
14880,
3261,
14,
272,
4107,
63,
8356,
26,
267,
1415,
26,
3055,
267,
849,
26,
2549,
267,
1369,
26,
267,
446,
7719,
4178,
14512,
506,
16468,
31,
272,
5740,
63,
923,
26,
267,
1369,
26,
288,
446,
710,
536,
402,
314,
5740,
1572,
315,
1314,
1265,
2934,
370,
1218,
282,
5740,
1834,
14,
267,
1415,
26,
715,
272,
1174,
26,
267,
1369,
26,
288,
446,
7480,
282,
892,
5740,
1834,
1077,
506,
2737,
503,
29493,
506,
5463,
14,
267,
1415,
26,
715,
267,
3415,
26,
788,
981,
297,
283,
2168,
418,
199,
624,
199,
8918,
275,
408,
272,
446,
536,
26,
2790,
23896,
489,
15742,
63,
69,
63,
4753,
63,
4782,
26,
267,
25891,
26,
7370,
25891,
7820,
267,
2986,
63,
633,
26,
7370,
15742,
63,
1246,
63,
633,
7820,
267,
2986,
63,
2473,
26,
7370,
15742,
63,
1246,
63,
2473,
7820,
267,
2986,
63,
2060,
26,
7370,
15742,
63,
1246,
63,
2060,
7820,
267,
4107,
63,
8356,
26,
7370,
4107,
63,
8356,
7820,
267,
5740,
63,
923,
26,
298,
1153,
3273,
6683,
1257,
37,
5783,
996,
1020,
35,
1194,
993,
1717,
34,
31441,
36,
25,
38,
13549,
2,
267,
1174,
26,
283,
981,
7,
199,
624,
199,
9677,
275,
408,
199,
2595,
272,
1499,
26,
267,
1369,
26,
8511,
402,
3439,
267,
730,
26,
1059,
267,
2138,
26,
3544,
267,
2690,
26,
298,
10502,
5740,
1834,
2,
272,
1834,
63,
344,
26,
267,
1369,
26,
2870,
402,
13639,
8885,
1834,
267,
730,
26,
1059,
267,
2138,
26,
1174,
508,
2737,
267,
2690,
26,
298,
1082,
3273,
6683,
1257,
37,
5783,
996,
1020,
34,
772,
8010,
1216,
17702,
1641,
6265,
21,
35,
21,
37,
298,
199,
624,
199,
199,
21178,
275,
469,
272,
298,
2714,
13,
804,
582,
298,
3578,
15,
1001,
401,
272,
298,
8422,
582,
298,
3578,
15,
1001,
401,
199,
93,
199,
646,
2022,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
1246,
492,
5678,
63,
1178,
63,
2094,
63,
1650,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
647,
5819,
1194,
492,
664,
63,
1971,
199,
504,
3242,
14,
578,
63,
1208,
14,
3603,
492,
1551,
63,
633,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
705,
492,
15050,
421,
199,
318,
1056,
8,
633,
12,
666,
29,
403,
12,
2323,
29,
403,
12,
1083,
534,
2970,
297,
675,
63,
3280,
29,
549,
12,
288,
3542,
29,
797,
12,
2061,
63,
1494,
63,
521,
29,
403,
12,
2653,
29,
709,
12,
4107,
63,
8356,
29,
549,
12,
288,
1166,
63,
2473,
29,
403,
12,
1166,
63,
2060,
29,
403,
12,
1455,
63,
4054,
29,
403,
12,
3542,
63,
4316,
63,
1178,
29,
549,
12,
3686,
63,
2550,
29,
797,
304,
272,
862,
26,
267,
519,
275,
1551,
63,
633,
8,
633,
29,
633,
12,
666,
29,
576,
12,
2323,
29,
2139,
12,
1083,
29,
765,
12,
675,
63,
3280,
29,
1180,
63,
3280,
12,
2151,
3542,
29,
3990,
12,
2061,
63,
1494,
63,
521,
29,
2019,
63,
1494,
63,
521,
12,
2653,
29,
2593,
12,
4107,
63,
8356,
29,
3502,
63,
8356,
12,
2151,
1166,
63,
2473,
29,
633,
63,
2473,
12,
1166,
63,
2060,
29,
633,
63,
2060,
12,
1455,
63,
4054,
29,
1014,
63,
4054,
12,
2151,
3542,
63,
4316,
63,
1178,
29,
3990,
63,
4316,
63,
1178,
9,
272,
871,
15050,
26,
267,
2329,
275,
664,
63,
1971,
342,
267,
519,
275,
2329,
14,
3997,
339,
862,
26,
267,
3066,
63,
576,
275,
519,
14,
739,
342,
267,
340,
3066,
63,
576,
26,
288,
666,
275,
2022,
14,
3640,
8,
1773,
63,
576,
9,
267,
587,
26,
288,
3066,
63,
576,
275,
488,
272,
871,
26,
267,
340,
3686,
63,
2550,
26,
288,
986,
267,
587,
26,
288,
746,
2186,
8,
1773,
63,
576,
9,
339,
3085,
63,
600,
275,
519,
14,
362,
600,
342,
339,
340,
3085,
63,
600,
2356,
8290,
436,
440,
3686,
63,
2550,
26,
267,
746,
2186,
8,
4518,
63,
600,
12,
666,
9,
272,
587,
26,
267,
372,
3085,
63,
600,
12,
666,
421,
199,
318,
5740,
63,
923,
63,
504,
63,
354,
8,
578,
12,
25891,
12,
2986,
63,
633,
12,
2986,
63,
14258,
12,
2986,
63,
2647,
12,
536,
304,
272,
13639,
63,
2634,
275,
283,
3494,
13,
19135,
3149,
83,
15,
4753,
13
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
334,
67,
9,
7800,
12,
28076,
12,
3277,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
15742,
63,
69,
63,
4753,
63,
4782,
199,
3612,
63,
1802,
26,
2790,
436,
3145,
5740,
5935,
199,
1802,
26,
272,
446,
2790,
436,
3145,
19076,
5935,
641,
5740,
4652,
367,
28076,
662,
13,
5602,
4887,
6572,
14,
272,
446,
5972,
314,
29493,
5740,
1834,
883,
506,
5463,
880,
17754,
365,
17731,
14,
272,
446,
298,
13885,
26,
23896,
12158,
787,
2737,
687,
5740,
5935,
2122,
199,
1023,
63,
3270,
26,
283,
18,
14,
18,
7,
199,
2502,
26,
25645,
11908,
869,
348,
613,
8593,
72,
348,
613,
9,
199,
1419,
26,
272,
2986,
63,
2473,
26,
267,
1415,
26,
2549,
267,
1369,
26,
267,
446,
710,
3434,
370,
12895,
543,
314,
428,
879,
599,
3690,
6001,
15803,
12373,
503,
12169,
14880,
3261,
14,
272,
2986,
63,
2060,
26,
267,
1415,
26,
2549,
267,
1369,
26,
267,
446,
710,
2505,
370,
12895,
543,
314,
428,
879,
599,
3690,
6001,
15803,
12373,
503,
12169,
14880,
3261,
14,
272,
2986,
63,
633,
26,
267,
1415,
26,
2549,
267,
1369,
26,
267,
446,
710,
1166,
370,
314,
428,
879,
599,
3690,
6001,
15803,
12373,
503,
12169,
14880,
3261,
14,
272,
4107,
63,
8356,
26,
267,
1415,
26,
3055,
267,
849,
26,
2549,
267,
1369,
26,
267,
446,
7719,
4178,
14512,
506,
16468,
31,
272,
5740,
63,
923,
26,
267,
1369,
26,
288,
446,
710,
536,
402,
314,
5740,
1572,
315,
1314,
1265,
2934,
370,
1218,
282,
5740,
1834,
14,
267,
1415,
26,
715,
272,
1174,
26,
267,
1369,
26,
288,
446,
7480,
282,
892,
5740,
1834,
1077,
506,
2737,
503,
29493,
506,
5463,
14,
267,
1415,
26,
715,
267,
3415,
26,
788,
981,
297,
283,
2168,
418,
199,
624,
199,
8918,
275,
408,
272,
446,
536,
26,
2790,
23896,
489,
15742,
63,
69,
63,
4753,
63,
4782,
26,
267,
25891,
26,
7370,
25891,
7820,
267,
2986,
63,
633,
26,
7370,
15742,
63,
1246,
63,
633,
7820,
267,
2986,
63,
2473,
26,
7370,
15742,
63,
1246,
63,
2473,
7820,
267,
2986,
63,
2060,
26,
7370,
15742,
63,
1246,
63,
2060,
7820,
267,
4107,
63,
8356,
26,
7370,
4107,
63,
8356,
7820,
267,
5740,
63,
923,
26,
298,
1153,
3273,
6683,
1257,
37,
5783,
996,
1020,
35,
1194,
993,
1717,
34,
31441,
36,
25,
38,
13549,
2,
267,
1174,
26,
283,
981,
7,
199,
624,
199,
9677,
275,
408,
199,
2595,
272,
1499,
26,
267,
1369,
26,
8511,
402,
3439,
267,
730,
26,
1059,
267,
2138,
26,
3544,
267,
2690,
26,
298,
10502,
5740,
1834,
2,
272,
1834,
63,
344,
26,
267,
1369,
26,
2870,
402,
13639,
8885,
1834,
267,
730,
26,
1059,
267,
2138,
26,
1174,
508,
2737,
267,
2690,
26,
298,
1082,
3273,
6683,
1257,
37,
5783,
996,
1020,
34,
772,
8010,
1216,
17702,
1641,
6265,
21,
35,
21,
37,
298,
199,
624,
199,
199,
21178,
275,
469,
272,
298,
2714,
13,
804,
582,
298,
3578,
15,
1001,
401,
272,
298,
8422,
582,
298,
3578,
15,
1001,
401,
199,
93,
199,
646,
2022,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
1246,
492,
5678,
63,
1178,
63,
2094,
63,
1650,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
647,
5819,
1194,
492,
664,
63,
1971,
199,
504,
3242,
14,
578,
63,
1208,
14,
3603,
492,
1551,
63,
633,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
705,
492,
15050,
421,
199,
318,
1056,
8,
633,
12,
666,
29,
403,
12,
2323,
29,
403,
12,
1083,
534,
2970,
297,
675,
63,
3280,
29,
549,
12,
288,
3542,
29,
797,
12,
2061,
63,
1494,
63,
521,
29,
403,
12,
2653,
29,
709,
12,
4107,
63,
8356,
29,
549,
12,
288,
1166,
63,
2473,
29,
403,
12,
1166,
63,
2060,
29,
403,
12,
1455,
63,
4054,
29,
403,
12,
3542,
63,
4316,
63,
1178,
29,
549,
12,
3686,
63,
2550,
29,
797,
304,
272,
862,
26,
267,
519,
275,
1551,
63,
633,
8,
633,
29,
633,
12,
666,
29,
576,
12,
2323,
29,
2139,
12,
1083,
29,
765,
12,
675,
63,
3280,
29,
1180,
63,
3280,
12,
2151,
3542,
29,
3990,
12,
2061,
63,
1494,
63,
521,
29,
2019,
63,
1494,
63,
521,
12,
2653,
29,
2593,
12,
4107,
63,
8356,
29,
3502,
63,
8356,
12,
2151,
1166,
63,
2473,
29,
633,
63,
2473,
12,
1166,
63,
2060,
29,
633,
63,
2060,
12,
1455,
63,
4054,
29,
1014,
63,
4054,
12,
2151,
3542,
63,
4316,
63,
1178,
29,
3990,
63,
4316,
63,
1178,
9,
272,
871,
15050,
26,
267,
2329,
275,
664,
63,
1971,
342,
267,
519,
275,
2329,
14,
3997,
339,
862,
26,
267,
3066,
63,
576,
275,
519,
14,
739,
342,
267,
340,
3066,
63,
576,
26,
288,
666,
275,
2022,
14,
3640,
8,
1773,
63,
576,
9,
267,
587,
26,
288,
3066,
63,
576,
275,
488,
272,
871,
26,
267,
340,
3686,
63,
2550,
26,
288,
986,
267,
587,
26,
288,
746,
2186,
8,
1773,
63,
576,
9,
339,
3085,
63,
600,
275,
519,
14,
362,
600,
342,
339,
340,
3085,
63,
600,
2356,
8290,
436,
440,
3686,
63,
2550,
26,
267,
746,
2186,
8,
4518,
63,
600,
12,
666,
9,
272,
587,
26,
267,
372,
3085,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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
] |
gcode-mirror/audacity
|
lib-src/lv2/sord/waflib/Tools/c_tests.py
|
330
|
4280
|
#! /usr/bin/env python
# encoding: utf-8
# WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
from waflib import Task
from waflib.Configure import conf
from waflib.TaskGen import feature,before_method,after_method
import sys
LIB_CODE='''
#ifdef _MSC_VER
#define testEXPORT __declspec(dllexport)
#else
#define testEXPORT
#endif
testEXPORT int lib_func(void) { return 9; }
'''
MAIN_CODE='''
#ifdef _MSC_VER
#define testEXPORT __declspec(dllimport)
#else
#define testEXPORT
#endif
testEXPORT int lib_func(void);
int main(int argc, char **argv) {
(void)argc; (void)argv;
return !(lib_func() == 9);
}
'''
@feature('link_lib_test')
@before_method('process_source')
def link_lib_test_fun(self):
def write_test_file(task):
task.outputs[0].write(task.generator.code)
rpath=[]
if getattr(self,'add_rpath',False):
rpath=[self.bld.path.get_bld().abspath()]
mode=self.mode
m='%s %s'%(mode,mode)
ex=self.test_exec and'test_exec'or''
bld=self.bld
bld(rule=write_test_file,target='test.'+mode,code=LIB_CODE)
bld(rule=write_test_file,target='main.'+mode,code=MAIN_CODE)
bld(features='%sshlib'%m,source='test.'+mode,target='test')
bld(features='%sprogram %s'%(m,ex),source='main.'+mode,target='app',use='test',rpath=rpath)
@conf
def check_library(self,mode=None,test_exec=True):
if not mode:
mode='c'
if self.env.CXX:
mode='cxx'
self.check(compile_filename=[],features='link_lib_test',msg='Checking for libraries',mode=mode,test_exec=test_exec,)
INLINE_CODE='''
typedef int foo_t;
static %s foo_t static_foo () {return 0; }
%s foo_t foo () {
return 0;
}
'''
INLINE_VALUES=['inline','__inline__','__inline']
@conf
def check_inline(self,**kw):
self.start_msg('Checking for inline')
if not'define_name'in kw:
kw['define_name']='INLINE_MACRO'
if not'features'in kw:
if self.env.CXX:
kw['features']=['cxx']
else:
kw['features']=['c']
for x in INLINE_VALUES:
kw['fragment']=INLINE_CODE%(x,x)
try:
self.check(**kw)
except self.errors.ConfigurationError:
continue
else:
self.end_msg(x)
if x!='inline':
self.define('inline',x,quote=False)
return x
self.fatal('could not use inline functions')
LARGE_FRAGMENT='''#include <unistd.h>
int main(int argc, char **argv) {
(void)argc; (void)argv;
return !(sizeof(off_t) >= 8);
}
'''
@conf
def check_large_file(self,**kw):
if not'define_name'in kw:
kw['define_name']='HAVE_LARGEFILE'
if not'execute'in kw:
kw['execute']=True
if not'features'in kw:
if self.env.CXX:
kw['features']=['cxx','cxxprogram']
else:
kw['features']=['c','cprogram']
kw['fragment']=LARGE_FRAGMENT
kw['msg']='Checking for large file support'
ret=True
try:
if self.env.DEST_BINFMT!='pe':
ret=self.check(**kw)
except self.errors.ConfigurationError:
pass
else:
if ret:
return True
kw['msg']='Checking for -D_FILE_OFFSET_BITS=64'
kw['defines']=['_FILE_OFFSET_BITS=64']
try:
ret=self.check(**kw)
except self.errors.ConfigurationError:
pass
else:
self.define('_FILE_OFFSET_BITS',64)
return ret
self.fatal('There is no support for large files')
ENDIAN_FRAGMENT='''
short int ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
short int ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
int use_ascii (int i) {
return ascii_mm[i] + ascii_ii[i];
}
short int ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
short int ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
int use_ebcdic (int i) {
return ebcdic_mm[i] + ebcdic_ii[i];
}
extern int foo;
'''
class grep_for_endianness(Task.Task):
color='PINK'
def run(self):
txt=self.inputs[0].read(flags='rb').decode('iso8859-1')
if txt.find('LiTTleEnDian')>-1:
self.generator.tmp.append('little')
elif txt.find('BIGenDianSyS')>-1:
self.generator.tmp.append('big')
else:
return-1
@feature('grep_for_endianness')
@after_method('process_source')
def grep_for_endianness_fun(self):
self.create_task('grep_for_endianness',self.compiled_tasks[0].outputs[0])
@conf
def check_endianness(self):
tmp=[]
def check_msg(self):
return tmp[0]
self.check(fragment=ENDIAN_FRAGMENT,features='c grep_for_endianness',msg="Checking for endianness",define='ENDIANNESS',tmp=tmp,okmsg=check_msg)
return tmp[0]
|
gpl-2.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
3,
14750,
1,
4226,
440,
5283,
1,
1455,
921,
21500,
14,
31864,
14,
957,
15,
3187,
15,
4757,
15,
21500,
2706,
15,
4780,
14,
1360,
20930,
2873,
24522,
63,
1589,
63,
21500,
63,
493,
199,
199,
504,
31380,
492,
8495,
199,
504,
31380,
14,
17324,
492,
3743,
199,
504,
31380,
14,
4476,
8168,
492,
3878,
12,
5182,
63,
765,
12,
4399,
63,
765,
199,
646,
984,
199,
5617,
63,
6012,
19938,
199,
3,
27737,
485,
3053,
35,
63,
2111,
199,
3,
4640,
511,
18341,
636,
9427,
1650,
8,
5030,
3113,
719,
9,
199,
3,
2836,
199,
3,
4640,
511,
18341,
199,
3,
13739,
199,
396,
18341,
1109,
1973,
63,
1532,
8,
1647,
9,
469,
372,
1749,
27,
789,
199,
2344,
199,
5848,
63,
6012,
19938,
199,
3,
27737,
485,
3053,
35,
63,
2111,
199,
3,
4640,
511,
18341,
636,
9427,
1650,
8,
5030,
317,
412,
9,
199,
3,
2836,
199,
3,
4640,
511,
18341,
199,
3,
13739,
199,
396,
18341,
1109,
1973,
63,
1532,
8,
1647,
2736,
199,
442,
2446,
8,
442,
1680,
67,
12,
1495,
1011,
3020,
9,
469,
199,
198,
8,
1647,
9,
1273,
67,
27,
334,
1647,
9,
3020,
27,
199,
198,
1107,
8546,
8,
773,
63,
1532,
342,
508,
1749,
2736,
199,
93,
199,
2344,
199,
32,
4445,
360,
1073,
63,
773,
63,
396,
358,
199,
32,
5182,
63,
765,
360,
1412,
63,
1365,
358,
199,
318,
2142,
63,
773,
63,
396,
63,
7036,
8,
277,
304,
199,
198,
318,
2218,
63,
396,
63,
493,
8,
1765,
304,
507,
198,
1765,
14,
4467,
59,
16,
1055,
952,
8,
1765,
14,
4679,
14,
600,
9,
199,
198,
27841,
9811,
199,
198,
692,
2519,
8,
277,
2584,
525,
63,
27841,
297,
797,
304,
507,
198,
27841,
1524,
277,
14,
14341,
14,
515,
14,
362,
63,
14341,
1252,
4832,
5106,
199,
198,
632,
29,
277,
14,
632,
199,
198,
77,
9569,
83,
450,
83,
13328,
632,
12,
632,
9,
199,
198,
476,
29,
277,
14,
396,
63,
1628,
436,
1133,
597,
63,
1628,
7,
269,
891,
199,
198,
14341,
29,
277,
14,
14341,
199,
198,
14341,
8,
2200,
29,
952,
63,
396,
63,
493,
12,
1375,
534,
396,
3530,
11,
632,
12,
600,
29,
5617,
63,
6012,
9,
199,
198,
14341,
8,
2200,
29,
952,
63,
396,
63,
493,
12,
1375,
534,
973,
3530,
11,
632,
12,
600,
29,
5848,
63,
6012,
9,
199,
198,
14341,
8,
3179,
9569,
5510,
773,
5956,
77,
12,
1365,
534,
396,
3530,
11,
632,
12,
1375,
534,
396,
358,
199,
198,
14341,
8,
3179,
9569,
83,
6815,
450,
83,
13328,
77,
12,
476,
395,
1365,
534,
973,
3530,
11,
632,
12,
1375,
534,
571,
297,
1180,
534,
396,
297,
27841,
29,
27841,
9,
199,
32,
2190,
199,
318,
1104,
63,
4342,
8,
277,
12,
632,
29,
403,
12,
396,
63,
1628,
29,
549,
304,
199,
198,
692,
440,
818,
26,
507,
198,
632,
534,
67,
7,
507,
198,
692,
291,
14,
1813,
14,
12206,
26,
686,
198,
632,
534,
9634,
7,
199,
198,
277,
14,
1074,
8,
2014,
63,
1501,
6034,
3179,
534,
1073,
63,
773,
63,
396,
297,
1328,
534,
14740,
367,
8363,
297,
632,
29,
632,
12,
396,
63,
1628,
29,
396,
63,
1628,
4258,
199,
568,
6174,
63,
6012,
19938,
199,
9594,
1109,
3925,
63,
84,
27,
199,
1986,
450,
83,
3925,
63,
84,
2955,
63,
1421,
6248,
469,
1107,
378,
27,
789,
199,
5,
83,
3925,
63,
84,
3925,
6248,
469,
199,
198,
1107,
378,
27,
199,
93,
199,
2344,
199,
568,
6174,
63,
15514,
2968,
6460,
1673,
363,
6460,
363,
1673,
363,
6460,
418,
199,
32,
2190,
199,
318,
1104,
63,
6460,
8,
277,
12663,
829,
304,
199,
198,
277,
14,
928,
63,
1328,
360,
14740,
367,
8308,
358,
199,
198,
692,
440,
5121,
2829,
1132,
63,
354,
7,
262,
4775,
26,
507,
198,
829,
459,
4640,
63,
354,
32373,
568,
6174,
63,
9410,
1092,
7,
199,
198,
692,
440,
7,
3179,
7,
262,
4775,
26,
507,
198,
692,
291,
14,
1813,
14,
12206,
26,
686,
198,
829,
459,
3179,
418,
2968,
9634,
418,
507,
198,
2836,
26,
686,
198,
829,
459,
3179,
418,
2968,
67,
418,
199,
198,
509,
671,
315,
1621,
6174,
63,
15514,
26,
507,
198,
829,
459,
7677,
13784,
568,
6174,
63,
6012,
2840,
88,
12,
88,
9,
507,
198,
893,
26,
686,
198,
277,
14,
1074,
3682,
829,
9,
507,
198,
2590,
291,
14,
2550,
14,
5688,
547,
26,
686,
198,
6958,
507,
198,
2836,
26,
686,
198,
277,
14,
500,
63,
1328,
8,
88,
9,
686,
198,
692,
671,
27909,
6460,
356,
1585,
198,
277,
14,
4640,
360,
6460,
297,
88,
12,
3513,
29,
797,
9,
686,
198,
1107,
671,
199,
198,
277,
14,
16208,
360,
15153,
440,
675,
8308,
3423,
358,
199,
15806,
63,
28147,
19938,
3,
2613,
665,
324,
631,
68,
14,
72,
30,
199,
442,
2446,
8,
442,
1680,
67,
12,
1495,
1011,
3020,
9,
469,
199,
198,
8,
1647,
9,
1273,
67,
27,
334,
1647,
9,
3020,
27,
199,
198,
1107,
8546,
8,
12590,
8,
1997,
63,
84,
9,
2356,
1695,
2736,
199,
93,
199,
2344,
199,
32,
2190,
199,
318,
1104,
63,
9629,
63,
493,
8,
277,
12663,
829,
304,
199,
198,
692,
440,
5121,
2829,
1132,
63,
354,
7,
262,
4775,
26,
507,
198,
829,
459,
4640,
63,
354,
32373,
10767,
63,
15806,
3817,
7,
199,
198,
692,
440,
7,
2526,
7,
262,
4775,
26,
507,
198,
829,
459,
2526,
13784,
549,
199,
198,
692,
440,
7,
3179,
7,
262,
4775,
26,
507,
198,
692,
291,
14,
1813,
14,
12206,
26,
686,
198,
829,
459,
3179,
418,
2968,
9634,
1673,
9634,
6815,
418,
507,
198,
2836,
26,
686,
198,
829,
459,
3179,
418,
2968,
67,
1673,
67,
6815,
418,
199,
198,
829,
459,
7677,
13784,
15806,
63,
28147,
199,
198,
829,
459,
1328,
32373,
14740,
367,
7031,
570,
2291,
7,
199,
198,
3292,
29,
549,
199,
198,
893,
26,
507,
198,
692,
291,
14,
1813,
14,
19374,
63,
9431,
22831,
27909,
321,
356,
686,
198,
3292,
29,
277,
14,
1074,
3682,
829,
9,
199
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
3,
14750,
1,
4226,
440,
5283,
1,
1455,
921,
21500,
14,
31864,
14,
957,
15,
3187,
15,
4757,
15,
21500,
2706,
15,
4780,
14,
1360,
20930,
2873,
24522,
63,
1589,
63,
21500,
63,
493,
199,
199,
504,
31380,
492,
8495,
199,
504,
31380,
14,
17324,
492,
3743,
199,
504,
31380,
14,
4476,
8168,
492,
3878,
12,
5182,
63,
765,
12,
4399,
63,
765,
199,
646,
984,
199,
5617,
63,
6012,
19938,
199,
3,
27737,
485,
3053,
35,
63,
2111,
199,
3,
4640,
511,
18341,
636,
9427,
1650,
8,
5030,
3113,
719,
9,
199,
3,
2836,
199,
3,
4640,
511,
18341,
199,
3,
13739,
199,
396,
18341,
1109,
1973,
63,
1532,
8,
1647,
9,
469,
372,
1749,
27,
789,
199,
2344,
199,
5848,
63,
6012,
19938,
199,
3,
27737,
485,
3053,
35,
63,
2111,
199,
3,
4640,
511,
18341,
636,
9427,
1650,
8,
5030,
317,
412,
9,
199,
3,
2836,
199,
3,
4640,
511,
18341,
199,
3,
13739,
199,
396,
18341,
1109,
1973,
63,
1532,
8,
1647,
2736,
199,
442,
2446,
8,
442,
1680,
67,
12,
1495,
1011,
3020,
9,
469,
199,
198,
8,
1647,
9,
1273,
67,
27,
334,
1647,
9,
3020,
27,
199,
198,
1107,
8546,
8,
773,
63,
1532,
342,
508,
1749,
2736,
199,
93,
199,
2344,
199,
32,
4445,
360,
1073,
63,
773,
63,
396,
358,
199,
32,
5182,
63,
765,
360,
1412,
63,
1365,
358,
199,
318,
2142,
63,
773,
63,
396,
63,
7036,
8,
277,
304,
199,
198,
318,
2218,
63,
396,
63,
493,
8,
1765,
304,
507,
198,
1765,
14,
4467,
59,
16,
1055,
952,
8,
1765,
14,
4679,
14,
600,
9,
199,
198,
27841,
9811,
199,
198,
692,
2519,
8,
277,
2584,
525,
63,
27841,
297,
797,
304,
507,
198,
27841,
1524,
277,
14,
14341,
14,
515,
14,
362,
63,
14341,
1252,
4832,
5106,
199,
198,
632,
29,
277,
14,
632,
199,
198,
77,
9569,
83,
450,
83,
13328,
632,
12,
632,
9,
199,
198,
476,
29,
277,
14,
396,
63,
1628,
436,
1133,
597,
63,
1628,
7,
269,
891,
199,
198,
14341,
29,
277,
14,
14341,
199,
198,
14341,
8,
2200,
29,
952,
63,
396,
63,
493,
12,
1375,
534,
396,
3530,
11,
632,
12,
600,
29,
5617,
63,
6012,
9,
199,
198,
14341,
8,
2200,
29,
952,
63,
396,
63,
493,
12,
1375,
534,
973,
3530,
11,
632,
12,
600,
29,
5848,
63,
6012,
9,
199,
198,
14341,
8,
3179,
9569,
5510,
773,
5956,
77,
12,
1365,
534,
396,
3530,
11,
632,
12,
1375,
534,
396,
358,
199,
198,
14341,
8,
3179,
9569,
83,
6815,
450,
83,
13328,
77,
12,
476,
395,
1365,
534,
973,
3530,
11,
632,
12,
1375,
534,
571,
297,
1180,
534,
396,
297,
27841,
29,
27841,
9,
199,
32,
2190,
199,
318,
1104,
63,
4342,
8,
277,
12,
632,
29,
403,
12,
396,
63,
1628,
29,
549,
304,
199,
198,
692,
440,
818,
26,
507,
198,
632,
534,
67,
7,
507,
198,
692,
291,
14,
1813,
14,
12206,
26,
686,
198,
632,
534,
9634,
7,
199,
198,
277,
14,
1074,
8,
2014,
63,
1501,
6034,
3179,
534,
1073,
63,
773,
63,
396,
297,
1328,
534,
14740,
367,
8363,
297,
632,
29,
632,
12,
396,
63,
1628,
29,
396,
63,
1628,
4258,
199,
568,
6174,
63,
6012,
19938,
199,
9594,
1109,
3925,
63,
84,
27,
199,
1986,
450,
83,
3925,
63,
84,
2955,
63,
1421,
6248,
469,
1107,
378,
27,
789,
199,
5,
83,
3925,
63,
84,
3925,
6248,
469,
199,
198,
1107,
378,
27,
199,
93,
199,
2344,
199,
568,
6174,
63,
15514,
2968,
6460,
1673,
363,
6460,
363,
1673,
363,
6460,
418,
199,
32,
2190,
199,
318,
1104,
63,
6460,
8,
277,
12663,
829,
304,
199,
198,
277,
14,
928,
63,
1328,
360,
14740,
367,
8308,
358,
199,
198,
692,
440,
5121,
2829,
1132,
63,
354,
7,
262,
4775,
26,
507,
198,
829,
459,
4640,
63,
354,
32373,
568,
6174,
63,
9410,
1092,
7,
199,
198,
692,
440,
7,
3179,
7,
262,
4775,
26,
507,
198,
692,
291,
14,
1813,
14,
12206,
26,
686,
198,
829,
459,
3179,
418,
2968,
9634,
418,
507,
198,
2836,
26,
686,
198,
829,
459,
3179,
418,
2968,
67,
418,
199,
198,
509,
671,
315,
1621,
6174,
63,
15514,
26,
507,
198,
829,
459,
7677,
13784,
568,
6174,
63,
6012,
2840,
88,
12,
88,
9,
507,
198,
893,
26,
686,
198,
277,
14,
1074,
3682,
829,
9,
507,
198,
2590,
291,
14,
2550,
14,
5688,
547,
26,
686,
198,
6958,
507,
198,
2836,
26,
686,
198,
277,
14,
500,
63,
1328,
8,
88,
9,
686,
198,
692,
671,
27909,
6460,
356,
1585,
198,
277,
14,
4640,
360,
6460,
297,
88,
12,
3513,
29,
797,
9,
686,
198,
1107,
671,
199,
198,
277,
14,
16208,
360,
15153,
440,
675,
8308,
3423,
358,
199,
15806,
63,
28147,
19938,
3,
2613,
665,
324,
631,
68,
14,
72,
30,
199,
442,
2446,
8,
442,
1680,
67,
12,
1495,
1011,
3020,
9,
469,
199,
198,
8,
1647,
9,
1273,
67,
27,
334,
1647,
9,
3020,
27,
199,
198,
1107,
8546,
8,
12590,
8,
1997,
63,
84,
9,
2356,
1695,
2736,
199,
93,
199,
2344,
199,
32,
2190,
199,
318,
1104,
63,
9629,
63,
493,
8,
277,
12663,
829,
304,
199,
198,
692,
440,
5121,
2829,
1132,
63,
354,
7,
262,
4775,
26,
507,
198,
829,
459,
4640,
63,
354,
32373,
10767,
63,
15806,
3817,
7,
199,
198,
692,
440,
7,
2526,
7,
262,
4775,
26,
507,
198,
829,
459,
2526,
13784,
549,
199,
198,
692,
440,
7,
3179,
7,
262,
4775,
26,
507,
198,
692,
291,
14,
1813,
14,
12206,
26,
686,
198,
829,
459,
3179,
418,
2968,
9634,
1673,
9634,
6815,
418,
507,
198,
2836,
26,
686,
198,
829,
459,
3179,
418,
2968,
67,
1673,
67,
6815,
418,
199,
198,
829,
459,
7677,
13784,
15806,
63,
28147,
199,
198,
829,
459,
1328,
32373,
14740,
367,
7031,
570,
2291,
7,
199,
198,
3292,
29,
549,
199,
198,
893,
26,
507,
198,
692,
291,
14,
1813,
14,
19374,
63,
9431,
22831,
27909,
321,
356,
686,
198,
3292,
29,
277,
14,
1074,
3682,
829,
9,
199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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-packages/django/contrib/gis/db/backends/postgis/const.py
|
528
|
1484
|
"""
PostGIS to GDAL conversion constant definitions
"""
# Lookup to convert pixel type values from GDAL to PostGIS
GDAL_TO_POSTGIS = [None, 4, 6, 5, 8, 7, 10, 11, None, None, None, None]
# Lookup to convert pixel type values from PostGIS to GDAL
POSTGIS_TO_GDAL = [1, 1, 1, 3, 1, 3, 2, 5, 4, None, 6, 7, None, None]
# Struct pack structure for raster header, the raster header has the
# following structure:
#
# Endianness, PostGIS raster version, number of bands, scale, origin,
# skew, srid, width, and height.
#
# Scale, origin, and skew have x and y values. PostGIS currently uses
# a fixed endianness (1) and there is only one version (0).
POSTGIS_HEADER_STRUCTURE = 'B H H d d d d d d i H H'
# Lookup values to convert GDAL pixel types to struct characters. This is
# used to pack and unpack the pixel values of PostGIS raster bands.
GDAL_TO_STRUCT = [
None, 'B', 'H', 'h', 'L', 'l', 'f', 'd',
None, None, None, None,
]
# Size of the packed value in bytes for different numerical types.
# This is needed to cut chunks of band data out of PostGIS raster strings
# when decomposing them into GDALRasters.
# See https://docs.python.org/3/library/struct.html#format-characters
STRUCT_SIZE = {
'b': 1, # Signed char
'B': 1, # Unsigned char
'?': 1, # _Bool
'h': 2, # Short
'H': 2, # Unsigned short
'i': 4, # Integer
'I': 4, # Unsigned Integer
'l': 4, # Long
'L': 4, # Unsigned Long
'f': 4, # Float
'd': 8, # Double
}
|
mit
|
[
624,
199,
6564,
11092,
370,
15801,
8603,
4413,
10269,
199,
624,
199,
3,
12785,
370,
3957,
7148,
730,
1338,
687,
15801,
370,
20929,
199,
17835,
63,
2566,
63,
4030,
11092,
275,
359,
403,
12,
841,
12,
1227,
12,
959,
12,
1695,
12,
1520,
12,
1616,
12,
4119,
12,
488,
12,
488,
12,
488,
12,
488,
61,
199,
199,
3,
12785,
370,
3957,
7148,
730,
1338,
687,
20929,
370,
15801,
199,
4030,
11092,
63,
2566,
63,
17835,
275,
359,
17,
12,
413,
12,
413,
12,
650,
12,
413,
12,
650,
12,
499,
12,
959,
12,
841,
12,
488,
12,
1227,
12,
1520,
12,
488,
12,
488,
61,
199,
199,
3,
13039,
1706,
5523,
367,
19775,
1406,
12,
314,
19775,
1406,
965,
314,
199,
3,
2569,
5523,
26,
199,
3,
199,
3,
3447,
6268,
4171,
12,
20929,
19775,
1015,
12,
1329,
402,
30565,
12,
4666,
12,
6330,
12,
199,
3,
32415,
12,
15627,
12,
3462,
12,
436,
4569,
14,
199,
3,
199,
3,
22869,
12,
6330,
12,
436,
32415,
1172,
671,
436,
612,
1338,
14,
20929,
5544,
4440,
199,
3,
282,
6317,
17638,
4171,
334,
17,
9,
436,
2337,
365,
1454,
1373,
1015,
334,
16,
680,
199,
4030,
11092,
63,
7311,
63,
8893,
3942,
275,
283,
34,
869,
869,
366,
366,
366,
366,
366,
366,
284,
869,
869,
7,
199,
199,
3,
12785,
1338,
370,
3957,
15801,
7148,
2943,
370,
2702,
4110,
14,
961,
365,
199,
3,
1202,
370,
1706,
436,
7787,
314,
7148,
1338,
402,
20929,
19775,
30565,
14,
199,
17835,
63,
2566,
63,
8893,
275,
359,
272,
488,
12,
283,
34,
297,
283,
40,
297,
283,
72,
297,
283,
44,
297,
283,
76,
297,
283,
70,
297,
283,
68,
297,
272,
488,
12,
488,
12,
488,
12,
488,
12,
199,
61,
199,
199,
3,
14579,
402,
314,
13170,
574,
315,
2783,
367,
3365,
15470,
2943,
14,
199,
3,
961,
365,
4346,
370,
10415,
8291,
402,
10981,
666,
734,
402,
20929,
19775,
3326,
199,
3,
1380,
477,
863,
26056,
3062,
1901,
15801,
50,
305,
878,
14,
199,
3,
1666,
4178,
921,
4757,
14,
1548,
14,
1308,
15,
19,
15,
4342,
15,
1820,
14,
1360,
3,
908,
13,
16516,
199,
8893,
63,
4305,
275,
469,
272,
283,
66,
356,
413,
12,
221,
327,
6632,
379,
1495,
272,
283,
34,
356,
413,
12,
221,
327,
1910,
1737,
1495,
272,
8720,
356,
413,
12,
221,
327,
485,
10349,
272,
283,
72,
356,
499,
12,
221,
327,
20124,
272,
283,
40,
356,
499,
12,
221,
327,
1910,
1737,
3974,
272,
283,
73,
356,
841,
12,
221,
327,
7225,
272,
283,
41,
356,
841,
12,
221,
327,
1910,
1737,
7225,
272,
283,
76,
356,
841,
12,
221,
327,
19944,
272,
283,
44,
356,
841,
12,
221,
327,
1910,
1737,
19944,
272,
283,
70,
356,
841,
12,
221,
327,
11140,
272,
283,
68,
356,
1695,
12,
221,
327,
22945,
199,
93,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
6564,
11092,
370,
15801,
8603,
4413,
10269,
199,
624,
199,
3,
12785,
370,
3957,
7148,
730,
1338,
687,
15801,
370,
20929,
199,
17835,
63,
2566,
63,
4030,
11092,
275,
359,
403,
12,
841,
12,
1227,
12,
959,
12,
1695,
12,
1520,
12,
1616,
12,
4119,
12,
488,
12,
488,
12,
488,
12,
488,
61,
199,
199,
3,
12785,
370,
3957,
7148,
730,
1338,
687,
20929,
370,
15801,
199,
4030,
11092,
63,
2566,
63,
17835,
275,
359,
17,
12,
413,
12,
413,
12,
650,
12,
413,
12,
650,
12,
499,
12,
959,
12,
841,
12,
488,
12,
1227,
12,
1520,
12,
488,
12,
488,
61,
199,
199,
3,
13039,
1706,
5523,
367,
19775,
1406,
12,
314,
19775,
1406,
965,
314,
199,
3,
2569,
5523,
26,
199,
3,
199,
3,
3447,
6268,
4171,
12,
20929,
19775,
1015,
12,
1329,
402,
30565,
12,
4666,
12,
6330,
12,
199,
3,
32415,
12,
15627,
12,
3462,
12,
436,
4569,
14,
199,
3,
199,
3,
22869,
12,
6330,
12,
436,
32415,
1172,
671,
436,
612,
1338,
14,
20929,
5544,
4440,
199,
3,
282,
6317,
17638,
4171,
334,
17,
9,
436,
2337,
365,
1454,
1373,
1015,
334,
16,
680,
199,
4030,
11092,
63,
7311,
63,
8893,
3942,
275,
283,
34,
869,
869,
366,
366,
366,
366,
366,
366,
284,
869,
869,
7,
199,
199,
3,
12785,
1338,
370,
3957,
15801,
7148,
2943,
370,
2702,
4110,
14,
961,
365,
199,
3,
1202,
370,
1706,
436,
7787,
314,
7148,
1338,
402,
20929,
19775,
30565,
14,
199,
17835,
63,
2566,
63,
8893,
275,
359,
272,
488,
12,
283,
34,
297,
283,
40,
297,
283,
72,
297,
283,
44,
297,
283,
76,
297,
283,
70,
297,
283,
68,
297,
272,
488,
12,
488,
12,
488,
12,
488,
12,
199,
61,
199,
199,
3,
14579,
402,
314,
13170,
574,
315,
2783,
367,
3365,
15470,
2943,
14,
199,
3,
961,
365,
4346,
370,
10415,
8291,
402,
10981,
666,
734,
402,
20929,
19775,
3326,
199,
3,
1380,
477,
863,
26056,
3062,
1901,
15801,
50,
305,
878,
14,
199,
3,
1666,
4178,
921,
4757,
14,
1548,
14,
1308,
15,
19,
15,
4342,
15,
1820,
14,
1360,
3,
908,
13,
16516,
199,
8893,
63,
4305,
275,
469,
272,
283,
66,
356,
413,
12,
221,
327,
6632,
379,
1495,
272,
283,
34,
356,
413,
12,
221,
327,
1910,
1737,
1495,
272,
8720,
356,
413,
12,
221,
327,
485,
10349,
272,
283,
72,
356,
499,
12,
221,
327,
20124,
272,
283,
40,
356,
499,
12,
221,
327,
1910,
1737,
3974,
272,
283,
73,
356,
841,
12,
221,
327,
7225,
272,
283,
41,
356,
841,
12,
221,
327,
1910,
1737,
7225,
272,
283,
76,
356,
841,
12,
221,
327,
19944,
272,
283,
44,
356,
841,
12,
221,
327,
1910,
1737,
19944,
272,
283,
70,
356,
841,
12,
221,
327,
11140,
272,
283,
68,
356,
1695,
12,
221,
327,
22945,
199,
93,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
civisanalytics/ansible
|
test/units/module_utils/ec2/test_aws.py
|
51
|
2972
|
# -*- coding: utf-8 -*-
# (c) 2015, Allen Sanabria <asanabria@linuxdynasty.org>
#
# 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/>.
try:
import boto3
import botocore
HAS_BOTO3 = True
except:
HAS_BOTO3 = False
from nose.plugins.skip import SkipTest
from ansible.compat.tests import unittest
from ansible.module_utils.ec2 import AWSRetry
if not HAS_BOTO3:
raise SkipTest("test_aws.py requires the python modules 'boto3' and 'botocore'")
class RetryTestCase(unittest.TestCase):
def test_no_failures(self):
self.counter = 0
@AWSRetry.backoff(tries=2, delay=0.1)
def no_failures():
self.counter += 1
r = no_failures()
self.assertEqual(self.counter, 1)
def test_retry_once(self):
self.counter = 0
err_msg = {'Error': {'Code': 'InstanceId.NotFound'}}
@AWSRetry.backoff(tries=2, delay=0.1)
def retry_once():
self.counter += 1
if self.counter < 2:
raise botocore.exceptions.ClientError(err_msg, 'Could not find you')
else:
return 'success'
r = retry_once()
self.assertEqual(r, 'success')
self.assertEqual(self.counter, 2)
def test_reached_limit(self):
self.counter = 0
err_msg = {'Error': {'Code': 'RequestLimitExceeded'}}
@AWSRetry.backoff(tries=4, delay=0.1)
def fail():
self.counter += 1
raise botocore.exceptions.ClientError(err_msg, 'toooo fast!!')
#with self.assertRaises(botocore.exceptions.ClientError):
try:
fail()
except Exception as e:
self.assertEqual(e.response['Error']['Code'], 'RequestLimitExceeded')
self.assertEqual(self.counter, 4)
def test_unexpected_exception_does_not_retry(self):
self.counter = 0
err_msg = {'Error': {'Code': 'AuthFailure'}}
@AWSRetry.backoff(tries=4, delay=0.1)
def raise_unexpected_error():
self.counter += 1
raise botocore.exceptions.ClientError(err_msg, 'unexpected error')
#with self.assertRaises(botocore.exceptions.ClientError):
try:
raise_unexpected_error()
except Exception as e:
self.assertEqual(e.response['Error']['Code'], 'AuthFailure')
self.assertEqual(self.counter, 1)
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
334,
67,
9,
6900,
12,
4580,
552,
29359,
371,
23714,
665,
305,
290,
371,
23714,
32,
472,
85,
2207,
1236,
27352,
14,
1308,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
893,
26,
272,
492,
6055,
19,
272,
492,
21199,
272,
7509,
63,
21373,
19,
275,
715,
199,
2590,
26,
272,
7509,
63,
21373,
19,
275,
756,
199,
199,
504,
11354,
14,
5265,
14,
2759,
492,
18795,
199,
199,
504,
3242,
14,
5819,
14,
2219,
492,
2882,
199,
504,
3242,
14,
578,
63,
1208,
14,
825,
18,
492,
10168,
12989,
199,
199,
692,
440,
7509,
63,
21373,
19,
26,
272,
746,
18795,
480,
396,
63,
7231,
14,
647,
5074,
314,
2366,
4621,
283,
10914,
19,
7,
436,
283,
10914,
1018,
9859,
421,
199,
533,
20506,
1746,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
889,
63,
9968,
8,
277,
304,
267,
291,
14,
5337,
275,
378,
398,
768,
13226,
12989,
14,
21061,
8,
6264,
29,
18,
12,
7339,
29,
16,
14,
17,
9,
267,
347,
949,
63,
9968,
837,
288,
291,
14,
5337,
847,
413,
398,
519,
275,
949,
63,
9968,
342,
267,
291,
14,
629,
8,
277,
14,
5337,
12,
413,
9,
339,
347,
511,
63,
7154,
63,
5089,
8,
277,
304,
267,
291,
14,
5337,
275,
378,
267,
2329,
63,
1328,
275,
791,
547,
356,
791,
3034,
356,
283,
3244,
1304,
14,
4667,
18620,
398,
768,
13226,
12989,
14,
21061,
8,
6264,
29,
18,
12,
7339,
29,
16,
14,
17,
9,
267,
347,
7269,
63,
5089,
837,
288,
291,
14,
5337,
847,
413,
288,
340,
291,
14,
5337,
665,
499,
26,
355,
746,
21199,
14,
3924,
14,
19992,
8,
1508,
63,
1328,
12,
283,
6531,
440,
2342,
1265,
358,
288,
587,
26,
355,
372,
283,
3742,
7,
398,
519,
275,
7269,
63,
5089,
342,
267,
291,
14,
629,
8,
82,
12,
283,
3742,
358,
267,
291,
14,
629,
8,
277,
14,
5337,
12,
499,
9,
339,
347,
511,
63,
30931,
63,
3097,
8,
277,
304,
267,
291,
14,
5337,
275,
378,
267,
2329,
63,
1328,
275,
791,
547,
356,
791,
3034,
356,
283,
2017,
8407,
24748,
18620,
398,
768,
13226,
12989,
14,
21061,
8,
6264,
29,
20,
12,
7339,
29,
16,
14,
17,
9,
267,
347,
2449,
837,
288,
291,
14,
5337,
847,
413,
288,
746,
21199,
14,
3924,
14,
19992,
8,
1508,
63,
1328,
12,
283,
475,
1534,
79,
7377,
3480,
358,
398,
327,
1045,
291,
14,
1855,
8,
10914,
1018,
14,
3924,
14,
19992,
304,
267,
862,
26,
288,
2449,
342,
267,
871,
2186,
465,
325,
26,
288,
291,
14,
629,
8,
69,
14,
1310,
459,
547,
2545,
3034,
995,
283,
2017,
8407,
24748,
358,
267,
291,
14,
629,
8,
277,
14,
5337,
12,
841,
9,
339,
347,
511,
63,
8953,
63,
1971,
63,
9105,
63,
1397,
63,
7154,
8,
277,
304,
267,
291,
14,
5337,
275,
378,
267,
2329,
63,
1328,
275,
791,
547,
356,
791,
3034,
356,
283,
2817,
6782,
18620,
398,
768,
13226,
12989,
14,
21061,
8,
6264,
29,
20,
12,
7339,
29,
16,
14,
17,
9,
267,
347,
746,
63,
8953,
63,
705,
837,
288,
291,
14,
5337,
847,
413,
288,
746,
21199,
14,
3924,
14,
19992,
8,
1508,
63,
1328,
12,
283,
8953,
1125,
358,
398,
327,
1045,
291,
14,
1855,
8,
10914,
1018,
14,
3924,
14,
19992,
304,
267,
862,
26,
288,
746,
63,
8953,
63,
705,
342,
267,
871,
2186,
465,
325,
26,
288,
291,
14,
629,
8,
69,
14,
1310,
459,
547,
2545,
3034,
995,
283,
2817,
6782,
358,
398,
291,
14,
629,
8,
277,
14,
5337,
12,
413,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
334,
67,
9,
6900,
12,
4580,
552,
29359,
371,
23714,
665,
305,
290,
371,
23714,
32,
472,
85,
2207,
1236,
27352,
14,
1308,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
893,
26,
272,
492,
6055,
19,
272,
492,
21199,
272,
7509,
63,
21373,
19,
275,
715,
199,
2590,
26,
272,
7509,
63,
21373,
19,
275,
756,
199,
199,
504,
11354,
14,
5265,
14,
2759,
492,
18795,
199,
199,
504,
3242,
14,
5819,
14,
2219,
492,
2882,
199,
504,
3242,
14,
578,
63,
1208,
14,
825,
18,
492,
10168,
12989,
199,
199,
692,
440,
7509,
63,
21373,
19,
26,
272,
746,
18795,
480,
396,
63,
7231,
14,
647,
5074,
314,
2366,
4621,
283,
10914,
19,
7,
436,
283,
10914,
1018,
9859,
421,
199,
533,
20506,
1746,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
889,
63,
9968,
8,
277,
304,
267,
291,
14,
5337,
275,
378,
398,
768,
13226,
12989,
14,
21061,
8,
6264,
29,
18,
12,
7339,
29,
16,
14,
17,
9,
267,
347,
949,
63,
9968,
837,
288,
291,
14,
5337,
847,
413,
398,
519,
275,
949,
63,
9968,
342,
267,
291,
14,
629,
8,
277,
14,
5337,
12,
413,
9,
339,
347,
511,
63,
7154,
63,
5089,
8,
277,
304,
267,
291,
14,
5337,
275,
378,
267,
2329,
63,
1328,
275,
791,
547,
356,
791,
3034,
356,
283,
3244,
1304,
14,
4667,
18620,
398,
768,
13226,
12989,
14,
21061,
8,
6264,
29,
18,
12,
7339,
29,
16,
14,
17,
9,
267,
347,
7269,
63,
5089,
837,
288,
291,
14,
5337,
847,
413,
288,
340,
291,
14,
5337,
665,
499,
26,
355,
746,
21199,
14,
3924,
14,
19992,
8,
1508,
63,
1328,
12,
283,
6531,
440,
2342,
1265,
358,
288,
587,
26,
355,
372,
283,
3742,
7,
398,
519,
275,
7269,
63,
5089,
342,
267,
291,
14,
629,
8,
82,
12,
283,
3742,
358,
267,
291,
14,
629,
8,
277,
14,
5337,
12,
499,
9,
339,
347,
511,
63,
30931,
63,
3097,
8,
277,
304,
267,
291,
14,
5337,
275,
378,
267,
2329,
63,
1328,
275,
791,
547,
356,
791,
3034,
356,
283,
2017,
8407,
24748,
18620,
398,
768,
13226,
12989,
14,
21061,
8,
6264,
29,
20,
12,
7339,
29,
16,
14,
17,
9,
267,
347,
2449,
837,
288,
291,
14,
5337,
847,
413,
288,
746,
21199,
14,
3924,
14,
19992,
8,
1508,
63,
1328,
12,
283,
475,
1534,
79,
7377,
3480,
358,
398,
327,
1045,
291,
14,
1855,
8,
10914,
1018,
14,
3924,
14,
19992,
304,
267,
862,
26,
288,
2449,
342,
267,
871,
2186,
465,
325,
26,
288,
291,
14,
629,
8,
69,
14,
1310,
459,
547,
2545,
3034,
995,
283,
2017,
8407,
24748,
358,
267,
291,
14,
629,
8,
277,
14,
5337,
12,
841,
9,
339,
347,
511,
63,
8953,
63,
1971,
63,
9105,
63,
1397,
63,
7154,
8,
277,
304,
267,
291,
14,
5337,
275,
378,
267,
2329,
63,
1328,
275,
791,
547,
356,
791,
3034,
356,
283,
2817,
6782,
18620,
398,
768,
13226,
12989,
14,
21061,
8,
6264,
29,
20,
12,
7339,
29,
16,
14,
17,
9,
267,
347,
746,
63,
8953,
63,
705,
837,
288,
291,
14,
5337,
847,
413,
288,
746,
21199,
14,
3924,
14,
19992,
8,
1508,
63,
1328,
12,
283,
8953,
1125,
358,
398,
327,
1045,
291,
14,
1855,
8,
10914,
1018,
14,
3924,
14,
19992,
304,
267,
862,
26,
288,
746,
63,
8953,
63,
705,
342,
267,
871,
2186,
465,
325,
26,
288,
291,
14,
629,
8,
69,
14,
1310,
459,
547,
2545,
3034,
995,
283,
2817,
6782,
358,
398,
291,
14,
629,
8,
277,
14,
5337,
12,
413,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bjoernricks/kaizen
|
kaizen/utils/__init__.py
|
1
|
1170
|
# vim: fileencoding=utf-8 et sw=4 ts=4 tw=80:
# kaizen - Continuously improve, build and manage free software
#
# Copyright (C) 2011 Björn Ricks <bjoern.ricks@gmail.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
from kaizen.utils.template import Template
from kaizen.utils.helpers import real_path, list_contents, list_dir, list_subdir, \
extract_file, get_number_of_cpus
from kaizen.utils.hash import Hash
from kaizen.utils.loader import Loader
|
gpl-2.0
|
[
3,
6695,
26,
570,
2991,
29,
1624,
13,
24,
10844,
5584,
29,
20,
6714,
29,
20,
8900,
29,
1257,
26,
199,
199,
3,
1022,
65,
565,
287,
446,
1448,
1346,
7514,
590,
19053,
12,
1900,
436,
9635,
2867,
2032,
199,
3,
199,
3,
1898,
334,
35,
9,
7760,
221,
699,
74,
14614,
11641,
820,
2000,
83,
665,
468,
79,
27569,
14,
322,
5618,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
199,
3,
11315,
13,
10067,
8217,
199,
199,
504,
1022,
65,
565,
287,
14,
1208,
14,
1160,
492,
5458,
199,
199,
504,
1022,
65,
565,
287,
14,
1208,
14,
7546,
492,
3363,
63,
515,
12,
769,
63,
4407,
12,
769,
63,
694,
12,
769,
63,
10622,
12,
971,
2892,
5536,
63,
493,
12,
664,
63,
1955,
63,
1618,
63,
8896,
199,
199,
504,
1022,
65,
565,
287,
14,
1208,
14,
2227,
492,
16101,
199,
199,
504,
1022,
65,
565,
287,
14,
1208,
14,
3422,
492,
22865,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
570,
2991,
29,
1624,
13,
24,
10844,
5584,
29,
20,
6714,
29,
20,
8900,
29,
1257,
26,
199,
199,
3,
1022,
65,
565,
287,
446,
1448,
1346,
7514,
590,
19053,
12,
1900,
436,
9635,
2867,
2032,
199,
3,
199,
3,
1898,
334,
35,
9,
7760,
221,
699,
74,
14614,
11641,
820,
2000,
83,
665,
468,
79,
27569,
14,
322,
5618,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
199,
3,
11315,
13,
10067,
8217,
199,
199,
504,
1022,
65,
565,
287,
14,
1208,
14,
1160,
492,
5458,
199,
199,
504,
1022,
65,
565,
287,
14,
1208,
14,
7546,
492,
3363,
63,
515,
12,
769,
63,
4407,
12,
769,
63,
694,
12,
769,
63,
10622,
12,
971,
2892,
5536,
63,
493,
12,
664,
63,
1955,
63,
1618,
63,
8896,
199,
199,
504,
1022,
65,
565,
287,
14,
1208,
14,
2227,
492,
16101,
199,
199,
504,
1022,
65,
565,
287,
14,
1208,
14,
3422,
492,
22865,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
jxtech/teambition-api
|
teambition/api/stagetemplates.py
|
3
|
1971
|
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from optionaldict import optionaldict
from teambition.api.base import TeambitionAPI
class StageTemplates(TeambitionAPI):
def get(self):
"""
获取用户自定义的阶段模板
详情请参考
http://docs.teambition.com/wiki/stages-template#stages-template-get
:return: 返回的 JSON 数据包
"""
return self._get('api/stagetemplates')
def create(self, title, stages):
"""
新建模板
详情请参考
http://docs.teambition.com/wiki/stages-template#stages-template-create
:param title: 模板标题
:param stages: 阶段名称列表,至少两个阶段
:return: 返回的 JSON 数据包
"""
if isinstance(stages, (tuple, list)):
stages = ','.join(stages)
return self._post(
'api/stagetemplates',
data={
'title': title,
'stages': stages
}
)
def delete(self, id):
"""
删除模板
详情请参考
http://docs.teambition.com/wiki/stages-template#stages-template-delete
:param id: 路径参数
:return: 返回的 JSON 数据包
"""
return self._delete('api/stagetemplates/{0}'.format(id))
def update(self, id, title=None, stages=None):
"""
更新模板
详情请参考
http://docs.teambition.com/wiki/stages-template#stages-template-update
:param id: 路径参数
:param title: 可选,模板标题
:param stages: 可选,阶段名称列表,至少两个阶段
:return: 返回的 JSON 数据包
"""
data = optionaldict(
title=title,
stages=stages
)
return self._put(
'api/stagetemplates/{0}'.format(id),
data=data
)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
504,
2716,
807,
492,
2716,
807,
199,
199,
504,
8099,
4492,
296,
14,
1246,
14,
1095,
492,
11682,
4492,
296,
3735,
421,
199,
533,
1933,
474,
17969,
8,
13126,
4492,
296,
3735,
304,
339,
347,
664,
8,
277,
304,
267,
408,
267,
9065,
237,
116,
22924,
22445,
27345,
104,
20766,
17837,
232,
8106,
166,
247,
115,
163,
107,
114,
29887,
15771,
124,
398,
221,
8400,
100,
32305,
25977,
32549,
16398,
226,
267,
1455,
921,
4757,
14,
5969,
4492,
296,
14,
957,
15,
6797,
15,
30646,
13,
1160,
3,
30646,
13,
1160,
13,
362,
398,
520,
1107,
26,
9065,
124,
243,
22234,
8106,
4840,
8853,
244,
109,
20466,
21018,
228,
267,
408,
267,
372,
291,
423,
362,
360,
1246,
15,
8614,
5876,
358,
339,
347,
1218,
8,
277,
12,
2538,
12,
24490,
304,
267,
408,
267,
8853,
245,
109,
29427,
119,
29887,
15771,
124,
398,
221,
8400,
100,
32305,
25977,
32549,
16398,
226,
267,
1455,
921,
4757,
14,
5969,
4492,
296,
14,
957,
15,
6797,
15,
30646,
13,
1160,
3,
30646,
13,
1160,
13,
981,
398,
520,
635,
2538,
26,
8853,
102,
95,
15771,
124,
20767,
21262,
247,
267,
520,
635,
24490,
26,
10469,
247,
115,
163,
107,
114,
21434,
19012,
109,
32551,
23243,
12356,
27345,
112,
15348,
240,
4344,
98,
10722,
166,
247,
115,
163,
107,
114,
267,
520,
1107,
26,
9065,
124,
243,
22234,
8106,
4840,
8853,
244,
109,
20466,
21018,
228,
267,
408,
267,
340,
1228,
8,
30646,
12,
334,
2960,
12,
769,
2298,
288,
24490,
275,
12814,
904,
8,
30646,
9,
267,
372,
291,
423,
1932,
8,
288,
283,
1246,
15,
8614,
5876,
297,
288,
666,
3126,
355,
283,
1213,
356,
2538,
12,
355,
283,
30646,
356,
24490,
288,
789,
267,
776,
339,
347,
3145,
8,
277,
12,
1305,
304,
267,
408,
267,
7094,
231,
255,
31459,
29887,
15771,
124,
398,
221,
8400,
100,
32305,
25977,
32549,
16398,
226,
267,
1455,
921,
4757,
14,
5969,
4492,
296,
14,
957,
15,
6797,
15,
30646,
13,
1160,
3,
30646,
13,
1160,
13,
1807,
398,
520,
635,
1305,
26,
9065,
116,
108,
19073,
227,
32549,
12211,
267,
520,
1107,
26,
9065,
124,
243,
22234,
8106,
4840,
8853,
244,
109,
20466,
21018,
228,
267,
408,
267,
372,
291,
423,
1807,
360,
1246,
15,
8614,
5876,
5321,
16,
5285,
908,
8,
344,
430,
339,
347,
1678,
8,
277,
12,
1305,
12,
2538,
29,
403,
12,
24490,
29,
403,
304,
267,
408,
267,
8853,
250,
113,
22737,
29887,
15771,
124,
398,
221,
8400,
100,
32305,
25977,
32549,
16398,
226,
267,
1455,
921,
4757,
14,
5969,
4492,
296,
14,
957,
15,
6797,
15,
30646,
13,
1160,
3,
30646,
13,
1160,
13,
873,
398,
520,
635,
1305,
26,
9065,
116,
108,
19073,
227,
32549,
12211,
267,
520,
635,
2538,
26,
221,
25521,
14333,
232,
12356,
29887,
15771,
124,
20767,
21262,
247,
267,
520,
635,
24490,
26,
221,
25521,
14333,
232,
12356,
166,
247,
115,
163,
107,
114,
21434,
19012,
109,
32551,
23243,
12356,
27345,
112,
15348,
240,
4344,
98,
10722,
166,
247,
115,
163,
107,
114,
267,
520,
1107,
26,
9065,
124,
243,
22234,
8106,
4840,
8853,
244,
109,
20466,
21018,
228,
267,
408,
267,
666,
275,
2716,
807,
8,
288,
2538,
29,
1213,
12,
288,
24490,
29,
30646,
267,
776,
267,
372,
291,
423,
524,
8,
288,
283,
1246,
15,
8614,
5876,
5321,
16,
5285,
908,
8,
344,
395,
288,
666,
29,
576,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
504,
2716,
807,
492,
2716,
807,
199,
199,
504,
8099,
4492,
296,
14,
1246,
14,
1095,
492,
11682,
4492,
296,
3735,
421,
199,
533,
1933,
474,
17969,
8,
13126,
4492,
296,
3735,
304,
339,
347,
664,
8,
277,
304,
267,
408,
267,
9065,
237,
116,
22924,
22445,
27345,
104,
20766,
17837,
232,
8106,
166,
247,
115,
163,
107,
114,
29887,
15771,
124,
398,
221,
8400,
100,
32305,
25977,
32549,
16398,
226,
267,
1455,
921,
4757,
14,
5969,
4492,
296,
14,
957,
15,
6797,
15,
30646,
13,
1160,
3,
30646,
13,
1160,
13,
362,
398,
520,
1107,
26,
9065,
124,
243,
22234,
8106,
4840,
8853,
244,
109,
20466,
21018,
228,
267,
408,
267,
372,
291,
423,
362,
360,
1246,
15,
8614,
5876,
358,
339,
347,
1218,
8,
277,
12,
2538,
12,
24490,
304,
267,
408,
267,
8853,
245,
109,
29427,
119,
29887,
15771,
124,
398,
221,
8400,
100,
32305,
25977,
32549,
16398,
226,
267,
1455,
921,
4757,
14,
5969,
4492,
296,
14,
957,
15,
6797,
15,
30646,
13,
1160,
3,
30646,
13,
1160,
13,
981,
398,
520,
635,
2538,
26,
8853,
102,
95,
15771,
124,
20767,
21262,
247,
267,
520,
635,
24490,
26,
10469,
247,
115,
163,
107,
114,
21434,
19012,
109,
32551,
23243,
12356,
27345,
112,
15348,
240,
4344,
98,
10722,
166,
247,
115,
163,
107,
114,
267,
520,
1107,
26,
9065,
124,
243,
22234,
8106,
4840,
8853,
244,
109,
20466,
21018,
228,
267,
408,
267,
340,
1228,
8,
30646,
12,
334,
2960,
12,
769,
2298,
288,
24490,
275,
12814,
904,
8,
30646,
9,
267,
372,
291,
423,
1932,
8,
288,
283,
1246,
15,
8614,
5876,
297,
288,
666,
3126,
355,
283,
1213,
356,
2538,
12,
355,
283,
30646,
356,
24490,
288,
789,
267,
776,
339,
347,
3145,
8,
277,
12,
1305,
304,
267,
408,
267,
7094,
231,
255,
31459,
29887,
15771,
124,
398,
221,
8400,
100,
32305,
25977,
32549,
16398,
226,
267,
1455,
921,
4757,
14,
5969,
4492,
296,
14,
957,
15,
6797,
15,
30646,
13,
1160,
3,
30646,
13,
1160,
13,
1807,
398,
520,
635,
1305,
26,
9065,
116,
108,
19073,
227,
32549,
12211,
267,
520,
1107,
26,
9065,
124,
243,
22234,
8106,
4840,
8853,
244,
109,
20466,
21018,
228,
267,
408,
267,
372,
291,
423,
1807,
360,
1246,
15,
8614,
5876,
5321,
16,
5285,
908,
8,
344,
430,
339,
347,
1678,
8,
277,
12,
1305,
12,
2538,
29,
403,
12,
24490,
29,
403,
304,
267,
408,
267,
8853,
250,
113,
22737,
29887,
15771,
124,
398,
221,
8400,
100,
32305,
25977,
32549,
16398,
226,
267,
1455,
921,
4757,
14,
5969,
4492,
296,
14,
957,
15,
6797,
15,
30646,
13,
1160,
3,
30646,
13,
1160,
13,
873,
398,
520,
635,
1305,
26,
9065,
116,
108,
19073,
227,
32549,
12211,
267,
520,
635,
2538,
26,
221,
25521,
14333,
232,
12356,
29887,
15771,
124,
20767,
21262,
247,
267,
520,
635,
24490,
26,
221,
25521,
14333,
232,
12356,
166,
247,
115,
163,
107,
114,
21434,
19012,
109,
32551,
23243,
12356,
27345,
112,
15348,
240,
4344,
98,
10722,
166,
247,
115,
163,
107,
114,
267,
520,
1107,
26,
9065,
124,
243,
22234,
8106,
4840,
8853,
244,
109,
20466,
21018,
228,
267,
408,
267,
666,
275,
2716,
807,
8,
288,
2538,
29,
1213,
12,
288,
24490,
29,
30646,
267,
776,
267,
372,
291,
423,
524,
8,
288,
283,
1246,
15,
8614,
5876,
5321,
16,
5285,
908,
8,
344,
395,
288,
666,
29,
576,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
scikit-nano/scikit-nano
|
sknano/apps/nanogen_gui/_pyqt4_ui_swnt_generator.py
|
2
|
25180
|
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'swnt_generator.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_SWNTGenerator(object):
def setupUi(self, SWNTGenerator):
SWNTGenerator.setObjectName(_fromUtf8("SWNTGenerator"))
SWNTGenerator.resize(427, 436)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(SWNTGenerator.sizePolicy().hasHeightForWidth())
SWNTGenerator.setSizePolicy(sizePolicy)
SWNTGenerator.setMinimumSize(QtCore.QSize(400, 400))
SWNTGenerator.setMaximumSize(QtCore.QSize(800, 1000))
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(14)
SWNTGenerator.setFont(font)
self.centralwidget = QtGui.QWidget(SWNTGenerator)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.verticalLayout_25 = QtGui.QVBoxLayout()
self.verticalLayout_25.setObjectName(_fromUtf8("verticalLayout_25"))
self.verticalLayout_24 = QtGui.QVBoxLayout()
self.verticalLayout_24.setObjectName(_fromUtf8("verticalLayout_24"))
self.horizontalLayout_13 = QtGui.QHBoxLayout()
self.horizontalLayout_13.setObjectName(_fromUtf8("horizontalLayout_13"))
self.horizontalLayout_3 = QtGui.QHBoxLayout()
self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3"))
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
self.label_7 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.label_7.setFont(font)
self.label_7.setObjectName(_fromUtf8("label_7"))
self.horizontalLayout_2.addWidget(self.label_7)
self.swnt_n_spin_box = QtGui.QSpinBox(self.centralwidget)
self.swnt_n_spin_box.setMinimumSize(QtCore.QSize(90, 36))
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.swnt_n_spin_box.setFont(font)
self.swnt_n_spin_box.setMaximum(100)
self.swnt_n_spin_box.setProperty("value", 10)
self.swnt_n_spin_box.setObjectName(_fromUtf8("swnt_n_spin_box"))
self.horizontalLayout_2.addWidget(self.swnt_n_spin_box)
self.horizontalLayout_3.addLayout(self.horizontalLayout_2)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.label_14 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.label_14.setFont(font)
self.label_14.setObjectName(_fromUtf8("label_14"))
self.horizontalLayout.addWidget(self.label_14)
self.swnt_m_spin_box = QtGui.QSpinBox(self.centralwidget)
self.swnt_m_spin_box.setMinimumSize(QtCore.QSize(90, 36))
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.swnt_m_spin_box.setFont(font)
self.swnt_m_spin_box.setMaximum(100)
self.swnt_m_spin_box.setProperty("value", 10)
self.swnt_m_spin_box.setObjectName(_fromUtf8("swnt_m_spin_box"))
self.horizontalLayout.addWidget(self.swnt_m_spin_box)
self.horizontalLayout_3.addLayout(self.horizontalLayout)
self.horizontalLayout_13.addLayout(self.horizontalLayout_3)
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_13.addItem(spacerItem)
self.verticalLayout_24.addLayout(self.horizontalLayout_13)
self.horizontalLayout_35 = QtGui.QHBoxLayout()
self.horizontalLayout_35.setObjectName(_fromUtf8("horizontalLayout_35"))
self.horizontalLayout_6 = QtGui.QHBoxLayout()
self.horizontalLayout_6.setObjectName(_fromUtf8("horizontalLayout_6"))
self.label_4 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.label_4.setFont(font)
self.label_4.setObjectName(_fromUtf8("label_4"))
self.horizontalLayout_6.addWidget(self.label_4)
self.swnt_nz_double_spin_box = QtGui.QDoubleSpinBox(self.centralwidget)
self.swnt_nz_double_spin_box.setMinimumSize(QtCore.QSize(100, 36))
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.swnt_nz_double_spin_box.setFont(font)
self.swnt_nz_double_spin_box.setDecimals(2)
self.swnt_nz_double_spin_box.setMaximum(1000.0)
self.swnt_nz_double_spin_box.setProperty("value", 1.0)
self.swnt_nz_double_spin_box.setObjectName(_fromUtf8("swnt_nz_double_spin_box"))
self.horizontalLayout_6.addWidget(self.swnt_nz_double_spin_box)
self.horizontalLayout_35.addLayout(self.horizontalLayout_6)
spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_35.addItem(spacerItem1)
self.verticalLayout_24.addLayout(self.horizontalLayout_35)
self.horizontalLayout_61 = QtGui.QHBoxLayout()
self.horizontalLayout_61.setObjectName(_fromUtf8("horizontalLayout_61"))
self.horizontalLayout_23 = QtGui.QHBoxLayout()
self.horizontalLayout_23.setObjectName(_fromUtf8("horizontalLayout_23"))
self.horizontalLayout_9 = QtGui.QHBoxLayout()
self.horizontalLayout_9.setObjectName(_fromUtf8("horizontalLayout_9"))
self.label_13 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.label_13.setFont(font)
self.label_13.setObjectName(_fromUtf8("label_13"))
self.horizontalLayout_9.addWidget(self.label_13)
self.swnt_Lz_double_spin_box = QtGui.QDoubleSpinBox(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.swnt_Lz_double_spin_box.sizePolicy().hasHeightForWidth())
self.swnt_Lz_double_spin_box.setSizePolicy(sizePolicy)
self.swnt_Lz_double_spin_box.setMinimumSize(QtCore.QSize(200, 36))
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.swnt_Lz_double_spin_box.setFont(font)
self.swnt_Lz_double_spin_box.setReadOnly(True)
self.swnt_Lz_double_spin_box.setDecimals(4)
self.swnt_Lz_double_spin_box.setMaximum(1000.0)
self.swnt_Lz_double_spin_box.setObjectName(_fromUtf8("swnt_Lz_double_spin_box"))
self.horizontalLayout_9.addWidget(self.swnt_Lz_double_spin_box)
self.horizontalLayout_23.addLayout(self.horizontalLayout_9)
self.swnt_fix_Lz_check_box = QtGui.QCheckBox(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.swnt_fix_Lz_check_box.setFont(font)
self.swnt_fix_Lz_check_box.setCheckable(True)
self.swnt_fix_Lz_check_box.setObjectName(_fromUtf8("swnt_fix_Lz_check_box"))
self.horizontalLayout_23.addWidget(self.swnt_fix_Lz_check_box)
self.horizontalLayout_61.addLayout(self.horizontalLayout_23)
spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_61.addItem(spacerItem2)
self.verticalLayout_24.addLayout(self.horizontalLayout_61)
self.verticalLayout_25.addLayout(self.verticalLayout_24)
self.line_2 = QtGui.QFrame(self.centralwidget)
self.line_2.setFrameShape(QtGui.QFrame.HLine)
self.line_2.setFrameShadow(QtGui.QFrame.Sunken)
self.line_2.setObjectName(_fromUtf8("line_2"))
self.verticalLayout_25.addWidget(self.line_2)
self.verticalLayout_23 = QtGui.QVBoxLayout()
self.verticalLayout_23.setObjectName(_fromUtf8("verticalLayout_23"))
self.bundle_generator_check_box = QtGui.QCheckBox(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.bundle_generator_check_box.setFont(font)
self.bundle_generator_check_box.setCheckable(True)
self.bundle_generator_check_box.setObjectName(_fromUtf8("bundle_generator_check_box"))
self.verticalLayout_23.addWidget(self.bundle_generator_check_box)
self.verticalLayout_22 = QtGui.QVBoxLayout()
self.verticalLayout_22.setObjectName(_fromUtf8("verticalLayout_22"))
self.horizontalLayout_11 = QtGui.QHBoxLayout()
self.horizontalLayout_11.setObjectName(_fromUtf8("horizontalLayout_11"))
self.horizontalLayout_4 = QtGui.QHBoxLayout()
self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4"))
self.label = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.label.setFont(font)
self.label.setObjectName(_fromUtf8("label"))
self.horizontalLayout_4.addWidget(self.label)
self.bundle_nx_spin_box = QtGui.QSpinBox(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.bundle_nx_spin_box.sizePolicy().hasHeightForWidth())
self.bundle_nx_spin_box.setSizePolicy(sizePolicy)
self.bundle_nx_spin_box.setMinimumSize(QtCore.QSize(100, 36))
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.bundle_nx_spin_box.setFont(font)
self.bundle_nx_spin_box.setReadOnly(True)
self.bundle_nx_spin_box.setMinimum(1)
self.bundle_nx_spin_box.setObjectName(_fromUtf8("bundle_nx_spin_box"))
self.horizontalLayout_4.addWidget(self.bundle_nx_spin_box)
self.horizontalLayout_11.addLayout(self.horizontalLayout_4)
self.horizontalLayout_7 = QtGui.QHBoxLayout()
self.horizontalLayout_7.setObjectName(_fromUtf8("horizontalLayout_7"))
self.label_2 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.label_2.setFont(font)
self.label_2.setObjectName(_fromUtf8("label_2"))
self.horizontalLayout_7.addWidget(self.label_2)
self.bundle_Lx_line_edit = QtGui.QLineEdit(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.bundle_Lx_line_edit.sizePolicy().hasHeightForWidth())
self.bundle_Lx_line_edit.setSizePolicy(sizePolicy)
self.bundle_Lx_line_edit.setMinimumSize(QtCore.QSize(175, 36))
self.bundle_Lx_line_edit.setMaximumSize(QtCore.QSize(200, 16777215))
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.bundle_Lx_line_edit.setFont(font)
self.bundle_Lx_line_edit.setReadOnly(True)
self.bundle_Lx_line_edit.setObjectName(_fromUtf8("bundle_Lx_line_edit"))
self.horizontalLayout_7.addWidget(self.bundle_Lx_line_edit)
self.horizontalLayout_11.addLayout(self.horizontalLayout_7)
spacerItem3 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_11.addItem(spacerItem3)
self.verticalLayout_22.addLayout(self.horizontalLayout_11)
self.horizontalLayout_10 = QtGui.QHBoxLayout()
self.horizontalLayout_10.setObjectName(_fromUtf8("horizontalLayout_10"))
self.horizontalLayout_5 = QtGui.QHBoxLayout()
self.horizontalLayout_5.setObjectName(_fromUtf8("horizontalLayout_5"))
self.label_3 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.label_3.setFont(font)
self.label_3.setObjectName(_fromUtf8("label_3"))
self.horizontalLayout_5.addWidget(self.label_3)
self.bundle_ny_spin_box = QtGui.QSpinBox(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.bundle_ny_spin_box.sizePolicy().hasHeightForWidth())
self.bundle_ny_spin_box.setSizePolicy(sizePolicy)
self.bundle_ny_spin_box.setMinimumSize(QtCore.QSize(100, 36))
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.bundle_ny_spin_box.setFont(font)
self.bundle_ny_spin_box.setReadOnly(True)
self.bundle_ny_spin_box.setMinimum(1)
self.bundle_ny_spin_box.setObjectName(_fromUtf8("bundle_ny_spin_box"))
self.horizontalLayout_5.addWidget(self.bundle_ny_spin_box)
self.horizontalLayout_10.addLayout(self.horizontalLayout_5)
self.horizontalLayout_8 = QtGui.QHBoxLayout()
self.horizontalLayout_8.setObjectName(_fromUtf8("horizontalLayout_8"))
self.label_12 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.label_12.setFont(font)
self.label_12.setObjectName(_fromUtf8("label_12"))
self.horizontalLayout_8.addWidget(self.label_12)
self.bundle_Ly_line_edit = QtGui.QLineEdit(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.bundle_Ly_line_edit.sizePolicy().hasHeightForWidth())
self.bundle_Ly_line_edit.setSizePolicy(sizePolicy)
self.bundle_Ly_line_edit.setMinimumSize(QtCore.QSize(175, 36))
self.bundle_Ly_line_edit.setMaximumSize(QtCore.QSize(200, 16777215))
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(16)
self.bundle_Ly_line_edit.setFont(font)
self.bundle_Ly_line_edit.setReadOnly(True)
self.bundle_Ly_line_edit.setObjectName(_fromUtf8("bundle_Ly_line_edit"))
self.horizontalLayout_8.addWidget(self.bundle_Ly_line_edit)
self.horizontalLayout_10.addLayout(self.horizontalLayout_8)
spacerItem4 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_10.addItem(spacerItem4)
self.verticalLayout_22.addLayout(self.horizontalLayout_10)
self.verticalLayout_23.addLayout(self.verticalLayout_22)
self.verticalLayout_25.addLayout(self.verticalLayout_23)
self.verticalLayout.addLayout(self.verticalLayout_25)
self.line_8 = QtGui.QFrame(self.centralwidget)
self.line_8.setFrameShape(QtGui.QFrame.HLine)
self.line_8.setFrameShadow(QtGui.QFrame.Sunken)
self.line_8.setObjectName(_fromUtf8("line_8"))
self.verticalLayout.addWidget(self.line_8)
self.verticalLayout_5 = QtGui.QVBoxLayout()
self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5"))
self.horizontalLayout_31 = QtGui.QHBoxLayout()
self.horizontalLayout_31.setObjectName(_fromUtf8("horizontalLayout_31"))
self.horizontalLayout_30 = QtGui.QHBoxLayout()
self.horizontalLayout_30.setObjectName(_fromUtf8("horizontalLayout_30"))
self.horizontalLayout_29 = QtGui.QHBoxLayout()
self.horizontalLayout_29.setObjectName(_fromUtf8("horizontalLayout_29"))
self.label_17 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(18)
self.label_17.setFont(font)
self.label_17.setObjectName(_fromUtf8("label_17"))
self.horizontalLayout_29.addWidget(self.label_17)
self.element1_combo_box = QtGui.QComboBox(self.centralwidget)
self.element1_combo_box.setMinimumSize(QtCore.QSize(0, 36))
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(18)
self.element1_combo_box.setFont(font)
self.element1_combo_box.setObjectName(_fromUtf8("element1_combo_box"))
self.element1_combo_box.addItem(_fromUtf8(""))
self.element1_combo_box.addItem(_fromUtf8(""))
self.element1_combo_box.addItem(_fromUtf8(""))
self.element1_combo_box.addItem(_fromUtf8(""))
self.element1_combo_box.addItem(_fromUtf8(""))
self.horizontalLayout_29.addWidget(self.element1_combo_box)
self.horizontalLayout_30.addLayout(self.horizontalLayout_29)
self.horizontalLayout_28 = QtGui.QHBoxLayout()
self.horizontalLayout_28.setObjectName(_fromUtf8("horizontalLayout_28"))
self.label_18 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(18)
self.label_18.setFont(font)
self.label_18.setObjectName(_fromUtf8("label_18"))
self.horizontalLayout_28.addWidget(self.label_18)
self.element2_combo_box = QtGui.QComboBox(self.centralwidget)
self.element2_combo_box.setMinimumSize(QtCore.QSize(0, 36))
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(18)
self.element2_combo_box.setFont(font)
self.element2_combo_box.setObjectName(_fromUtf8("element2_combo_box"))
self.element2_combo_box.addItem(_fromUtf8(""))
self.element2_combo_box.addItem(_fromUtf8(""))
self.element2_combo_box.addItem(_fromUtf8(""))
self.element2_combo_box.addItem(_fromUtf8(""))
self.element2_combo_box.addItem(_fromUtf8(""))
self.horizontalLayout_28.addWidget(self.element2_combo_box)
self.horizontalLayout_30.addLayout(self.horizontalLayout_28)
self.horizontalLayout_31.addLayout(self.horizontalLayout_30)
spacerItem5 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_31.addItem(spacerItem5)
self.verticalLayout_5.addLayout(self.horizontalLayout_31)
self.horizontalLayout_24 = QtGui.QHBoxLayout()
self.horizontalLayout_24.setObjectName(_fromUtf8("horizontalLayout_24"))
self.horizontalLayout_14 = QtGui.QHBoxLayout()
self.horizontalLayout_14.setObjectName(_fromUtf8("horizontalLayout_14"))
self.elements_bond_label = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(18)
self.elements_bond_label.setFont(font)
self.elements_bond_label.setObjectName(_fromUtf8("elements_bond_label"))
self.horizontalLayout_14.addWidget(self.elements_bond_label)
self.bond_double_spin_box = QtGui.QDoubleSpinBox(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.bond_double_spin_box.sizePolicy().hasHeightForWidth())
self.bond_double_spin_box.setSizePolicy(sizePolicy)
self.bond_double_spin_box.setMinimumSize(QtCore.QSize(150, 36))
font = QtGui.QFont()
font.setFamily(_fromUtf8("Arial"))
font.setPointSize(18)
self.bond_double_spin_box.setFont(font)
self.bond_double_spin_box.setInputMethodHints(QtCore.Qt.ImhFormattedNumbersOnly)
self.bond_double_spin_box.setReadOnly(False)
self.bond_double_spin_box.setDecimals(3)
self.bond_double_spin_box.setMinimum(0.5)
self.bond_double_spin_box.setMaximum(10.0)
self.bond_double_spin_box.setSingleStep(0.01)
self.bond_double_spin_box.setProperty("value", 1.42)
self.bond_double_spin_box.setObjectName(_fromUtf8("bond_double_spin_box"))
self.horizontalLayout_14.addWidget(self.bond_double_spin_box)
self.horizontalLayout_24.addLayout(self.horizontalLayout_14)
spacerItem6 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_24.addItem(spacerItem6)
self.verticalLayout_5.addLayout(self.horizontalLayout_24)
self.verticalLayout.addLayout(self.verticalLayout_5)
spacerItem7 = QtGui.QSpacerItem(20, 75, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem7)
SWNTGenerator.setCentralWidget(self.centralwidget)
self.retranslateUi(SWNTGenerator)
self.element1_combo_box.setCurrentIndex(3)
self.element2_combo_box.setCurrentIndex(3)
QtCore.QMetaObject.connectSlotsByName(SWNTGenerator)
def retranslateUi(self, SWNTGenerator):
SWNTGenerator.setWindowTitle(_translate("SWNTGenerator", "SWNT Generator", None))
self.label_7.setText(_translate("SWNTGenerator", "<html><head/><body><p align=\"right\">n = </p></body></html>", None))
self.label_14.setText(_translate("SWNTGenerator", "<html><head/><body><p align=\"right\">m = </p></body></html>", None))
self.label_4.setText(_translate("SWNTGenerator", "<html><head/><body><p><span style=\" font-style:italic;\">n</span><span style=\" vertical-align:sub;\">z </span>=</p></body></html>", None))
self.label_13.setText(_translate("SWNTGenerator", "<html><head/><body><p><span style=\" font-style:italic;\">L</span><span style=\" vertical-align:sub;\">z </span>= </p></body></html>", None))
self.swnt_Lz_double_spin_box.setSuffix(_translate("SWNTGenerator", " nm", None))
self.swnt_fix_Lz_check_box.setText(_translate("SWNTGenerator", "Fix Lz", None))
self.bundle_generator_check_box.setText(_translate("SWNTGenerator", "Bundle Generator", None))
self.label.setText(_translate("SWNTGenerator", "<html><head/><body><p><span style=\" font-style:italic;\">n</span><span style=\" vertical-align:sub;\">x </span>=</p></body></html>", None))
self.label_2.setText(_translate("SWNTGenerator", "<html><head/><body><p><span style=\" font-style:italic;\">L</span><span style=\" vertical-align:sub;\">x </span>= </p></body></html>", None))
self.label_3.setText(_translate("SWNTGenerator", "<html><head/><body><p><span style=\" font-style:italic;\">n</span><span style=\" vertical-align:sub;\">y </span>=</p></body></html>", None))
self.label_12.setText(_translate("SWNTGenerator", "<html><head/><body><p><span style=\" font-style:italic;\">L</span><span style=\" vertical-align:sub;\">y </span>= </p></body></html>", None))
self.label_17.setText(_translate("SWNTGenerator", "Element 1:", None))
self.element1_combo_box.setItemText(0, _translate("SWNTGenerator", "H", None))
self.element1_combo_box.setItemText(1, _translate("SWNTGenerator", "He", None))
self.element1_combo_box.setItemText(2, _translate("SWNTGenerator", "B", None))
self.element1_combo_box.setItemText(3, _translate("SWNTGenerator", "C", None))
self.element1_combo_box.setItemText(4, _translate("SWNTGenerator", "N", None))
self.label_18.setText(_translate("SWNTGenerator", "Element 2:", None))
self.element2_combo_box.setItemText(0, _translate("SWNTGenerator", "H", None))
self.element2_combo_box.setItemText(1, _translate("SWNTGenerator", "He", None))
self.element2_combo_box.setItemText(2, _translate("SWNTGenerator", "B", None))
self.element2_combo_box.setItemText(3, _translate("SWNTGenerator", "C", None))
self.element2_combo_box.setItemText(4, _translate("SWNTGenerator", "N", None))
self.elements_bond_label.setText(_translate("SWNTGenerator", "<html><head/><body><p>C-C bond =</p></body></html>", None))
self.bond_double_spin_box.setSuffix(_translate("SWNTGenerator", " Å", None))
|
bsd-2-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
8204,
4514,
4046,
687,
7664,
8574,
570,
283,
3519,
343,
63,
4679,
14,
1907,
7,
199,
3,
199,
3,
18208,
701,
26,
14084,
20,
14041,
1233,
4306,
841,
14,
845,
14,
20,
199,
3,
199,
3,
14750,
1,
2900,
4493,
6326,
315,
642,
570,
911,
506,
14669,
1,
199,
199,
504,
14084,
20,
492,
10565,
12,
5928,
199,
199,
893,
26,
272,
485,
12382,
24,
275,
10565,
14,
49,
1558,
14,
12382,
24,
199,
2590,
4281,
26,
272,
347,
485,
12382,
24,
8,
83,
304,
267,
372,
308,
199,
199,
893,
26,
272,
485,
2991,
275,
5928,
14,
12757,
14,
21865,
24,
272,
347,
485,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
304,
267,
372,
5928,
14,
12757,
14,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
12,
485,
2991,
9,
199,
2590,
4281,
26,
272,
347,
485,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
304,
267,
372,
5928,
14,
12757,
14,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
9,
199,
199,
533,
32471,
63,
51,
3705,
52,
7599,
8,
785,
304,
272,
347,
3272,
18203,
8,
277,
12,
428,
3705,
52,
7599,
304,
267,
428,
3705,
52,
7599,
14,
10376,
1547,
12382,
24,
480,
51,
3705,
52,
7599,
2237,
267,
428,
3705,
52,
7599,
14,
8709,
8,
27358,
12,
841,
1344,
9,
267,
22789,
275,
5928,
14,
19934,
8,
10604,
14,
19934,
14,
29373,
12,
5928,
14,
19934,
14,
29373,
9,
267,
22789,
14,
409,
19918,
21537,
8,
16,
9,
267,
22789,
14,
409,
19462,
21537,
8,
16,
9,
267,
22789,
14,
409,
8436,
1858,
6216,
8,
51,
3705,
52,
7599,
14,
890,
4845,
1252,
1989,
8436,
1858,
6216,
1012,
267,
428,
3705,
52,
7599,
14,
21735,
4845,
8,
890,
4845,
9,
267,
428,
3705,
52,
7599,
14,
32608,
2320,
8,
10901,
14,
15531,
8,
5303,
12,
8290,
430,
267,
428,
3705,
52,
7599,
14,
409,
10915,
2320,
8,
10901,
14,
15531,
8,
6718,
12,
5198,
430,
267,
5023,
275,
5928,
14,
49,
6986,
342,
267,
5023,
14,
409,
16345,
1547,
12382,
24,
480,
33,
1383,
2237,
267,
5023,
14,
409,
3428,
2320,
8,
1079,
9,
267,
428,
3705,
52,
7599,
14,
24432,
8,
4246,
9,
267,
291,
14,
16067,
3440,
275,
5928,
14,
23894,
8,
51,
3705,
52,
7599,
9,
267,
291,
14,
16067,
3440,
14,
10376,
1547,
12382,
24,
480,
16067,
3440,
2237,
267,
291,
14,
18656,
275,
5928,
14,
25527,
18536,
8,
277,
14,
16067,
3440,
9,
267,
291,
14,
18656,
14,
10376,
1547,
12382,
24,
480,
18656,
2237,
267,
291,
14,
18656,
63,
821,
275,
5928,
14,
25527,
18536,
342,
267,
291,
14,
18656,
63,
821,
14,
10376,
1547,
12382,
24,
480,
18656,
63,
821,
2237,
267,
291,
14,
18656,
63,
1194,
275,
5928,
14,
25527,
18536,
342,
267,
291,
14,
18656,
63,
1194,
14,
10376,
1547,
12382,
24,
480,
18656,
63,
1194,
2237,
267,
291,
14,
18986,
63,
969,
275,
5928,
14,
27088,
18536,
342,
267,
291,
14,
18986,
63,
969,
14,
10376,
1547,
12382,
24,
480,
18986,
63,
969,
2237,
267,
291,
14,
18986,
63,
19,
275,
5928,
14,
27088,
18536,
342,
267,
291,
14,
18986,
63,
19,
14,
10376,
1547,
12382,
24,
480,
18986,
63,
19,
2237,
267,
291,
14,
18986,
63,
18,
275,
5928,
14,
27088,
18536,
342,
267,
291,
14,
18986,
63,
18,
14,
10376,
1547,
12382,
24,
480,
18986,
63,
18,
2237,
267,
291,
14,
1302,
63,
23,
275,
5928,
14,
19890,
8,
277,
14,
16067,
3440,
9,
267,
5023,
275,
5928,
14,
49,
6986,
342,
267,
5023,
14,
409,
16345,
1547,
12382,
24,
480,
33,
1383,
2237,
267,
5023,
14,
409,
3428,
2320,
8,
975,
9,
267,
291,
14,
1302,
63,
23,
14,
24432,
8,
4246,
9,
267,
291,
14,
1302,
63,
23,
14,
10376,
1547,
12382,
24,
480,
1302,
63,
23,
2237,
267,
291,
14,
18986,
63,
18,
14,
9475,
8,
277,
14,
1302,
63,
23,
9,
267,
291,
14,
3519,
343,
63,
78,
63,
14809,
63,
1977,
275,
5928,
14,
49,
27806,
8,
277,
14,
16067,
3440,
9,
267,
291,
14,
3519,
343,
63,
78,
63,
14809,
63,
1977,
14,
32608,
2320,
8,
10901,
14,
15531,
8,
2710,
12,
8780,
430,
267,
5023,
275,
5928,
14,
49,
6986,
342,
267,
5023,
14,
409,
16345,
1547,
12382,
24,
480,
33,
1383,
2237,
267,
5023,
14,
409,
3428,
2320,
8,
975,
9,
267,
291,
14,
3519,
343,
63,
78,
63,
14809,
63,
1977,
14,
24432,
8,
4246,
9,
267,
291,
14,
3519,
343,
63,
78,
63,
14809,
63,
1977,
14,
409,
10915,
8,
1960,
9,
267,
291,
14,
3519,
343,
63,
78,
63,
14809,
63,
1977,
14,
21173,
480,
585,
401,
1616,
9,
267,
291,
14,
3519,
343,
63,
78,
63,
14809,
63,
1977,
14,
10376,
1547,
12382,
24,
480,
3519,
343,
63,
78,
63,
14809,
63,
1977,
2237,
267,
291,
14,
18986,
63,
18,
14,
9475,
8,
277,
14,
3519,
343,
63,
78,
63,
14809,
63,
1977,
9,
267,
291,
14,
18986,
63,
19,
14,
30571,
8,
277,
14,
18986,
63,
18,
9,
267,
291,
14,
18986,
275,
5928,
14,
27088,
18536,
342,
267,
291,
14,
18986,
14,
10376,
1547,
12382,
24,
480,
18986,
2237,
267,
291,
14,
1302,
63,
1079,
275,
5928,
14,
19890,
8,
277,
14,
16067,
3440,
9,
267,
5023,
275,
5928,
14,
49,
6986,
342,
267,
5023,
14,
409,
16345,
1547,
12382,
24,
480,
33,
1383,
2237,
267,
5023,
14,
409,
3428,
2320,
8,
975,
9,
267,
291,
14,
1302,
63,
1079,
14,
24432,
8,
4246,
9,
267,
291,
14,
1302,
63,
1079,
14,
10376,
1547,
12382,
24,
480,
1302,
63,
1079,
2237,
267,
291,
14,
18986,
14,
9475,
8,
277,
14,
1302,
63,
1079,
9,
267,
291,
14,
3519,
343,
63,
77,
63,
14809,
63,
1977,
275,
5928,
14,
49,
27806,
8,
277,
14,
16067,
3440,
9,
267,
291,
14,
3519,
343,
63,
77,
63,
14809,
63,
1977,
14,
32608,
2320,
8,
10901,
14,
15531,
8,
2710,
12,
8780,
430,
267,
5023,
275,
5928,
14,
49,
6986,
342,
267,
5023,
14,
409,
16345,
1547,
12382,
24,
480,
33,
1383,
2237,
267,
5023,
14,
409,
3428,
2320,
8,
975,
9,
267,
291,
14
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
8204,
4514,
4046,
687,
7664,
8574,
570,
283,
3519,
343,
63,
4679,
14,
1907,
7,
199,
3,
199,
3,
18208,
701,
26,
14084,
20,
14041,
1233,
4306,
841,
14,
845,
14,
20,
199,
3,
199,
3,
14750,
1,
2900,
4493,
6326,
315,
642,
570,
911,
506,
14669,
1,
199,
199,
504,
14084,
20,
492,
10565,
12,
5928,
199,
199,
893,
26,
272,
485,
12382,
24,
275,
10565,
14,
49,
1558,
14,
12382,
24,
199,
2590,
4281,
26,
272,
347,
485,
12382,
24,
8,
83,
304,
267,
372,
308,
199,
199,
893,
26,
272,
485,
2991,
275,
5928,
14,
12757,
14,
21865,
24,
272,
347,
485,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
304,
267,
372,
5928,
14,
12757,
14,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
12,
485,
2991,
9,
199,
2590,
4281,
26,
272,
347,
485,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
304,
267,
372,
5928,
14,
12757,
14,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
9,
199,
199,
533,
32471,
63,
51,
3705,
52,
7599,
8,
785,
304,
272,
347,
3272,
18203,
8,
277,
12,
428,
3705,
52,
7599,
304,
267,
428,
3705,
52,
7599,
14,
10376,
1547,
12382,
24,
480,
51,
3705,
52,
7599,
2237,
267,
428,
3705,
52,
7599,
14,
8709,
8,
27358,
12,
841,
1344,
9,
267,
22789,
275,
5928,
14,
19934,
8,
10604,
14,
19934,
14,
29373,
12,
5928,
14,
19934,
14,
29373,
9,
267,
22789,
14,
409,
19918,
21537,
8,
16,
9,
267,
22789,
14,
409,
19462,
21537,
8,
16,
9,
267,
22789,
14,
409,
8436,
1858,
6216,
8,
51,
3705,
52,
7599,
14,
890,
4845,
1252,
1989,
8436,
1858,
6216,
1012,
267,
428,
3705,
52,
7599,
14,
21735,
4845,
8,
890,
4845,
9,
267,
428,
3705,
52,
7599,
14,
32608,
2320,
8,
10901,
14,
15531,
8,
5303,
12,
8290,
430,
267,
428,
3705,
52,
7599,
14,
409,
10915,
2320,
8,
10901,
14,
15531,
8,
6718,
12,
5198,
430,
267,
5023,
275,
5928,
14,
49,
6986,
342,
267,
5023,
14,
409,
16345,
1547,
12382,
24,
480,
33,
1383,
2237,
267,
5023,
14,
409,
3428,
2320,
8,
1079,
9,
267,
428,
3705,
52,
7599,
14,
24432,
8,
4246,
9,
267,
291,
14,
16067,
3440,
275,
5928,
14,
23894,
8,
51,
3705,
52,
7599,
9,
267,
291,
14,
16067,
3440,
14,
10376,
1547,
12382,
24,
480,
16067,
3440,
2237,
267,
291,
14,
18656,
275,
5928,
14,
25527,
18536,
8,
277,
14,
16067,
3440,
9,
267,
291,
14,
18656,
14,
10376,
1547,
12382,
24,
480,
18656,
2237,
267,
291,
14,
18656,
63,
821,
275,
5928,
14,
25527,
18536,
342,
267,
291,
14,
18656,
63,
821,
14,
10376,
1547,
12382,
24,
480,
18656,
63,
821,
2237,
267,
291,
14,
18656,
63,
1194,
275,
5928,
14,
25527,
18536,
342,
267,
291,
14,
18656,
63,
1194,
14,
10376,
1547,
12382,
24,
480,
18656,
63,
1194,
2237,
267,
291,
14,
18986,
63,
969,
275,
5928,
14,
27088,
18536,
342,
267,
291,
14,
18986,
63,
969,
14,
10376,
1547,
12382,
24,
480,
18986,
63,
969,
2237,
267,
291,
14,
18986,
63,
19,
275,
5928,
14,
27088,
18536,
342,
267,
291,
14,
18986,
63,
19,
14,
10376,
1547,
12382,
24,
480,
18986,
63,
19,
2237,
267,
291,
14,
18986,
63,
18,
275,
5928,
14,
27088,
18536,
342,
267,
291,
14,
18986,
63,
18,
14,
10376,
1547,
12382,
24,
480,
18986,
63,
18,
2237,
267,
291,
14,
1302,
63,
23,
275,
5928,
14,
19890,
8,
277,
14,
16067,
3440,
9,
267,
5023,
275,
5928,
14,
49,
6986,
342,
267,
5023,
14,
409,
16345,
1547,
12382,
24,
480,
33,
1383,
2237,
267,
5023,
14,
409,
3428,
2320,
8,
975,
9,
267,
291,
14,
1302,
63,
23,
14,
24432,
8,
4246,
9,
267,
291,
14,
1302,
63,
23,
14,
10376,
1547,
12382,
24,
480,
1302,
63,
23,
2237,
267,
291,
14,
18986,
63,
18,
14,
9475,
8,
277,
14,
1302,
63,
23,
9,
267,
291,
14,
3519,
343,
63,
78,
63,
14809,
63,
1977,
275,
5928,
14,
49,
27806,
8,
277,
14,
16067,
3440,
9,
267,
291,
14,
3519,
343,
63,
78,
63,
14809,
63,
1977,
14,
32608,
2320,
8,
10901,
14,
15531,
8,
2710,
12,
8780,
430,
267,
5023,
275,
5928,
14,
49,
6986,
342,
267,
5023,
14,
409,
16345,
1547,
12382,
24,
480,
33,
1383,
2237,
267,
5023,
14,
409,
3428,
2320,
8,
975,
9,
267,
291,
14,
3519,
343,
63,
78,
63,
14809,
63,
1977,
14,
24432,
8,
4246,
9,
267,
291,
14,
3519,
343,
63,
78,
63,
14809,
63,
1977,
14,
409,
10915,
8,
1960,
9,
267,
291,
14,
3519,
343,
63,
78,
63,
14809,
63,
1977,
14,
21173,
480,
585,
401,
1616,
9,
267,
291,
14,
3519,
343,
63,
78,
63,
14809,
63,
1977,
14,
10376,
1547,
12382,
24,
480,
3519,
343,
63,
78,
63,
14809,
63,
1977,
2237,
267,
291,
14,
18986,
63,
18,
14,
9475,
8,
277,
14,
3519,
343,
63,
78,
63,
14809,
63,
1977,
9,
267,
291,
14,
18986,
63,
19,
14,
30571,
8,
277,
14,
18986,
63,
18,
9,
267,
291,
14,
18986,
275,
5928,
14,
27088,
18536,
342,
267,
291,
14,
18986,
14,
10376,
1547,
12382,
24,
480,
18986,
2237,
267,
291,
14,
1302,
63,
1079,
275,
5928,
14,
19890,
8,
277,
14,
16067,
3440,
9,
267,
5023,
275,
5928,
14,
49,
6986,
342,
267,
5023,
14,
409,
16345,
1547,
12382,
24,
480,
33,
1383,
2237,
267,
5023,
14,
409,
3428,
2320,
8,
975,
9,
267,
291,
14,
1302,
63,
1079,
14,
24432,
8,
4246,
9,
267,
291,
14,
1302,
63,
1079,
14,
10376,
1547,
12382,
24,
480,
1302,
63,
1079,
2237,
267,
291,
14,
18986,
14,
9475,
8,
277,
14,
1302,
63,
1079,
9,
267,
291,
14,
3519,
343,
63,
77,
63,
14809,
63,
1977,
275,
5928,
14,
49,
27806,
8,
277,
14,
16067,
3440,
9,
267,
291,
14,
3519,
343,
63,
77,
63,
14809,
63,
1977,
14,
32608,
2320,
8,
10901,
14,
15531,
8,
2710,
12,
8780,
430,
267,
5023,
275,
5928,
14,
49,
6986,
342,
267,
5023,
14,
409,
16345,
1547,
12382,
24,
480,
33,
1383,
2237,
267,
5023,
14,
409,
3428,
2320,
8,
975,
9,
267,
291,
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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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
] |
gitlouie/Lectures
|
Python/Functions/memory.py
|
5
|
1027
|
# Before continuing, we should examine Python's memory model
x = 10
# The id() function returns the memory address (or some other unique identifier) of a binding
print "id(x):", id(x)
y = x
print "id(y):", id(y)
# What gets printed?
# So y and x are bound to the same value in memory. Is that what you get for primitive types in C?
# Python binds variables to values in a dictionary called a "namespace"; we call it a
# "referencing environment"
# All values are placed on the heap, and bindings to those values are placed in the namespace.
# All assignment = operators bind a new reference in the namespace
x = "hello"
y = 11
print "new id(y):", id(y)
z = 11 - 1
print id(z)
# y previously was bound to the same 10 as x; now it is bound to a different value
# When all bindings to a value are lost, the value may be garbage collected.
y = 100
# This has implications for references to mutable values
a = []
b = a
a.append(1)
print b
# As a Java programmer, what output do you expect?
# Why did we get that output?
|
mit
|
[
3,
21467,
32620,
12,
781,
1077,
31758,
2018,
1159,
4402,
1402,
199,
88,
275,
1616,
199,
3,
710,
1305,
342,
805,
2529,
314,
4402,
2287,
334,
269,
2005,
1163,
3747,
5148,
9,
402,
282,
11696,
199,
1361,
298,
344,
8,
88,
304,
401,
1305,
8,
88,
9,
199,
89,
275,
671,
199,
1361,
298,
344,
8,
89,
304,
401,
1305,
8,
89,
9,
199,
3,
14791,
7545,
12487,
31,
421,
199,
3,
2002,
612,
436,
671,
787,
3914,
370,
314,
2011,
574,
315,
4402,
14,
6596,
626,
4052,
1265,
664,
367,
18944,
2943,
315,
445,
31,
421,
199,
3,
2018,
5398,
83,
2860,
370,
1338,
315,
282,
2600,
2797,
282,
298,
3251,
11436,
781,
1240,
652,
282,
199,
3,
298,
264,
21532,
3734,
2,
199,
3,
2900,
1338,
787,
15090,
641,
314,
13295,
12,
436,
17792,
370,
5204,
1338,
787,
15090,
315,
314,
3231,
14,
199,
199,
3,
2900,
9801,
275,
10211,
5398,
282,
892,
3659,
315,
314,
3231,
199,
88,
275,
298,
5006,
2,
199,
89,
275,
4119,
199,
1361,
298,
1222,
1305,
8,
89,
304,
401,
1305,
8,
89,
9,
421,
199,
90,
275,
4119,
446,
413,
199,
1361,
1305,
8,
90,
9,
199,
199,
3,
612,
10889,
1990,
3914,
370,
314,
2011,
1616,
465,
671,
27,
3063,
652,
365,
3914,
370,
282,
3365,
574,
199,
199,
3,
3979,
1006,
17792,
370,
282,
574,
787,
14669,
12,
314,
574,
1443,
506,
17516,
13736,
14,
199,
89,
275,
2948,
421,
199,
3,
961,
965,
1742,
10785,
367,
6941,
370,
17194,
1338,
199,
65,
275,
942,
199,
66,
275,
282,
199,
65,
14,
740,
8,
17,
9,
199,
1361,
330,
199,
3,
3709,
282,
9586,
2240,
2626,
12,
4052,
1072,
886,
1265,
4282,
31,
199,
199,
3,
6827,
8103,
781,
664,
626,
1072,
31,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
21467,
32620,
12,
781,
1077,
31758,
2018,
1159,
4402,
1402,
199,
88,
275,
1616,
199,
3,
710,
1305,
342,
805,
2529,
314,
4402,
2287,
334,
269,
2005,
1163,
3747,
5148,
9,
402,
282,
11696,
199,
1361,
298,
344,
8,
88,
304,
401,
1305,
8,
88,
9,
199,
89,
275,
671,
199,
1361,
298,
344,
8,
89,
304,
401,
1305,
8,
89,
9,
199,
3,
14791,
7545,
12487,
31,
421,
199,
3,
2002,
612,
436,
671,
787,
3914,
370,
314,
2011,
574,
315,
4402,
14,
6596,
626,
4052,
1265,
664,
367,
18944,
2943,
315,
445,
31,
421,
199,
3,
2018,
5398,
83,
2860,
370,
1338,
315,
282,
2600,
2797,
282,
298,
3251,
11436,
781,
1240,
652,
282,
199,
3,
298,
264,
21532,
3734,
2,
199,
3,
2900,
1338,
787,
15090,
641,
314,
13295,
12,
436,
17792,
370,
5204,
1338,
787,
15090,
315,
314,
3231,
14,
199,
199,
3,
2900,
9801,
275,
10211,
5398,
282,
892,
3659,
315,
314,
3231,
199,
88,
275,
298,
5006,
2,
199,
89,
275,
4119,
199,
1361,
298,
1222,
1305,
8,
89,
304,
401,
1305,
8,
89,
9,
421,
199,
90,
275,
4119,
446,
413,
199,
1361,
1305,
8,
90,
9,
199,
199,
3,
612,
10889,
1990,
3914,
370,
314,
2011,
1616,
465,
671,
27,
3063,
652,
365,
3914,
370,
282,
3365,
574,
199,
199,
3,
3979,
1006,
17792,
370,
282,
574,
787,
14669,
12,
314,
574,
1443,
506,
17516,
13736,
14,
199,
89,
275,
2948,
421,
199,
3,
961,
965,
1742,
10785,
367,
6941,
370,
17194,
1338,
199,
65,
275,
942,
199,
66,
275,
282,
199,
65,
14,
740,
8,
17,
9,
199,
1361,
330,
199,
3,
3709,
282,
9586,
2240,
2626,
12,
4052,
1072,
886,
1265,
4282,
31,
199,
199,
3,
6827,
8103,
781,
664,
626,
1072,
31,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
viki9698/jizhanggroup
|
djangoappengine/conf/project_template/project_name/settings.py
|
27
|
5321
|
# Django settings for {{ project_name }} project.
# Initialize App Engine and import the default settings (DB backend, etc.).
# If you want to use a different backend you have to remove all occurences
# of "djangoappengine" from this file.
from djangoappengine.settings_base import *
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
# Activate django-dbindexer for the default database
DATABASES['default'] = {'ENGINE': 'dbindexer', 'TARGET': DATABASES['default']}
AUTOLOAD_SITECONF = 'indexes'
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = False
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = '{{ secret_key }}'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
# This loads the index definitions, so it has to come first
'autoload.middleware.AutoloadMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = '{{ project_name }}.urls'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'djangotoolbox',
'autoload',
'dbindexer',
# djangoappengine should come last, so it can override a few manage.py commands
'djangoappengine',
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
|
bsd-3-clause
|
[
3,
5634,
2202,
367,
8448,
2199,
63,
354,
3586,
2199,
14,
199,
199,
3,
11578,
4693,
12580,
436,
492,
314,
849,
2202,
334,
2846,
4865,
12,
5423,
25860,
199,
3,
982,
1265,
2934,
370,
675,
282,
3365,
4865,
1265,
1172,
370,
2813,
1006,
14706,
608,
78,
823,
199,
3,
402,
298,
1176,
15358,
2,
687,
642,
570,
14,
199,
504,
1639,
15358,
14,
1751,
63,
1095,
492,
627,
199,
199,
14288,
51,
275,
334,
272,
327,
661,
14398,
2812,
297,
283,
12695,
63,
2123,
32,
2694,
14,
957,
659,
199,
9,
199,
199,
20600,
3960,
275,
29948,
51,
199,
199,
3,
21904,
2409,
1639,
13,
697,
15615,
367,
314,
849,
3050,
199,
27260,
459,
885,
418,
275,
791,
15956,
356,
283,
697,
15615,
297,
283,
9268,
356,
26931,
21983,
459,
885,
12074,
199,
199,
13883,
7405,
63,
7917,
3103,
275,
283,
10116,
7,
199,
199,
3,
10891,
83,
15,
2261,
1561,
626,
787,
1686,
367,
642,
4770,
27,
1415,
340,
10990,
365,
756,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
21,
15,
1121,
15,
1751,
12645,
6541,
13,
5146,
199,
17350,
63,
23775,
275,
942,
199,
199,
3,
10111,
900,
5718,
367,
642,
12096,
14,
8802,
2370,
883,
506,
1911,
2348,
26,
199,
3,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
1296,
63,
1618,
63,
3903,
63,
13325,
63,
991,
63,
354,
199,
3,
22160,
440,
1006,
3415,
1443,
506,
2808,
641,
1006,
17406,
10460,
14,
199,
3,
1010,
282,
5417,
3734,
642,
1471,
506,
663,
370,
2195,
2656,
900,
5718,
14,
199,
4961,
63,
15353,
275,
283,
8841,
15,
28796,
7,
199,
199,
3,
8466,
1233,
367,
642,
12096,
14,
2900,
3415,
883,
506,
1911,
2348,
26,
199,
3,
1455,
921,
1544,
14,
73,
1085,
2753,
29514,
14,
957,
15,
2975,
15,
3671,
13,
14227,
14,
1360,
199,
13947,
63,
6012,
275,
283,
287,
13,
527,
7,
199,
199,
7917,
63,
998,
275,
413,
199,
199,
3,
982,
1265,
663,
642,
370,
756,
12,
5634,
911,
1852,
2005,
5323,
12270,
880,
465,
440,
199,
3,
370,
2248,
314,
10757,
6279,
2072,
28540,
14,
199,
4701,
63,
41,
1085,
46,
275,
715,
199,
199,
3,
982,
1265,
663,
642,
370,
756,
12,
5634,
911,
440,
1475,
10831,
12,
5579,
436,
199,
3,
1704,
31276,
7182,
370,
314,
1453,
5867,
14,
199,
4701,
63,
44,
709,
46,
275,
715,
199,
199,
3,
982,
1265,
663,
642,
370,
756,
12,
5634,
911,
440,
675,
7137,
13,
14600,
29297,
14,
199,
4701,
63,
14226,
275,
756,
199,
199,
3,
24964,
10036,
931,
370,
314,
2082,
626,
911,
10266,
922,
13,
19044,
1584,
14,
199,
3,
5679,
26,
3286,
1391,
15,
1544,
15,
2694,
14,
957,
15,
4603,
6687,
199,
13669,
63,
5441,
275,
2125,
199,
199,
3,
2851,
626,
10022,
314,
5898,
19733,
687,
31460,
63,
5441,
14,
4155,
3238,
370,
675,
282,
199,
3,
8520,
14457,
14,
199,
3,
6058,
26,
298,
1014,
921,
2694,
14,
957,
15,
4603,
10665,
298,
1014,
921,
4603,
14,
2694,
14,
957,
6687,
199,
13669,
63,
2632,
275,
2125,
199,
199,
3,
24964,
931,
370,
314,
2082,
2955,
1584,
1077,
506,
13736,
370,
14,
199,
3,
7529,
1133,
5324,
7003,
315,
642,
2082,
28225,
27,
3877,
2195,
2955,
1584,
199,
3,
315,
8686,
7,
298,
1986,
6687,
24799,
436,
315,
27815,
9472,
63,
14455,
14,
199,
3,
5679,
26,
3286,
1391,
15,
1544,
15,
2694,
14,
957,
15,
1986,
6687,
199,
10449,
63,
5441,
275,
2125,
199,
199,
3,
2851,
2403,
367,
2955,
1584,
14,
199,
3,
5679,
26,
298,
1014,
921,
2694,
14,
957,
15,
1986,
10665,
298,
1014,
921,
1986,
14,
2694,
14,
957,
6687,
199,
10449,
63,
2632,
275,
1994,
1986,
4805,
199,
199,
3,
10961,
9918,
402,
2955,
1584,
199,
10449,
9472,
63,
14455,
275,
334,
272,
327,
16280,
3326,
2348,
12,
2839,
3286,
4219,
15,
1360,
15,
1986,
2,
503,
298,
35,
11254,
1544,
15,
1176,
15,
1986,
1674,
272,
327,
16763,
675,
7568,
20275,
12,
2755,
641,
5417,
14,
272,
327,
7529,
1133,
19459,
370,
675,
3679,
3792,
12,
440,
3847,
3792,
14,
199,
9,
199,
199,
3,
3820,
402,
11569,
3992,
626,
5715,
4212,
370,
2342,
2955,
1584,
315,
199,
3,
7750,
9918,
14,
199,
10449,
9472,
63,
27087,
3960,
275,
334,
272,
283,
1176,
14,
2828,
14,
18373,
14,
26677,
14,
17521,
11791,
297,
272,
283,
1176,
14,
2828,
14,
18373,
14,
26677,
14,
2640,
13752,
11791,
297,
199,
3,
259,
283,
1176,
14,
2828,
14,
18373,
14,
26677,
14,
2698,
6408,
11791,
297,
199,
9,
199,
199,
3,
4155,
642,
3747,
12,
436,
2793,
1133,
8663,
652,
543,
1263,
2030,
14,
199,
12961,
63,
3078,
275,
11400,
7565,
63,
498,
16339,
199,
199,
3,
3820,
402,
28041,
626,
5715,
4212,
370,
492,
7009,
687,
7750,
5274,
14,
199,
7433,
63,
7405,
3960,
275,
334,
272,
283,
1176,
14,
1160,
14,
16370,
14,
11381,
14,
5455,
297,
272,
283,
1176,
14,
1160,
14,
16370,
14,
571,
63,
12629,
14,
5455,
297,
199,
3,
258,
283,
1176,
14,
1160,
14,
16370,
14,
14488,
14,
5455,
297,
199,
9,
199,
199,
19987,
63,
13748,
275,
334,
272,
327,
961,
14404,
314,
1478,
10269,
12,
880,
652,
965,
370,
11492,
1642,
272,
283,
2495,
912,
14,
5754,
14,
3358,
912,
6608,
297,
339,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
272,
283,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
297,
272,
327,
1910,
3349,
314,
2163,
1004,
367,
3486,
8968,
19193,
316,
23977,
26,
272,
327,
283,
1176,
14,
5754,
14,
4891,
19193,
316,
14,
56,
3160,
4558,
6608,
297,
199,
9,
199,
199,
5441,
63,
18125,
275,
11400,
2199,
63,
354,
3586,
14,
3603,
7,
199,
199,
7433,
63,
14455,
275,
334,
272,
327,
16280,
3326,
2348,
12,
2839,
3286,
4219,
15,
1360,
15,
1176,
63,
5876,
2,
503,
298,
35,
11254,
1544,
15,
1176,
15,
5876,
1674,
272,
327
] |
[
5634,
2202,
367,
8448,
2199,
63,
354,
3586,
2199,
14,
199,
199,
3,
11578,
4693,
12580,
436,
492,
314,
849,
2202,
334,
2846,
4865,
12,
5423,
25860,
199,
3,
982,
1265,
2934,
370,
675,
282,
3365,
4865,
1265,
1172,
370,
2813,
1006,
14706,
608,
78,
823,
199,
3,
402,
298,
1176,
15358,
2,
687,
642,
570,
14,
199,
504,
1639,
15358,
14,
1751,
63,
1095,
492,
627,
199,
199,
14288,
51,
275,
334,
272,
327,
661,
14398,
2812,
297,
283,
12695,
63,
2123,
32,
2694,
14,
957,
659,
199,
9,
199,
199,
20600,
3960,
275,
29948,
51,
199,
199,
3,
21904,
2409,
1639,
13,
697,
15615,
367,
314,
849,
3050,
199,
27260,
459,
885,
418,
275,
791,
15956,
356,
283,
697,
15615,
297,
283,
9268,
356,
26931,
21983,
459,
885,
12074,
199,
199,
13883,
7405,
63,
7917,
3103,
275,
283,
10116,
7,
199,
199,
3,
10891,
83,
15,
2261,
1561,
626,
787,
1686,
367,
642,
4770,
27,
1415,
340,
10990,
365,
756,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
21,
15,
1121,
15,
1751,
12645,
6541,
13,
5146,
199,
17350,
63,
23775,
275,
942,
199,
199,
3,
10111,
900,
5718,
367,
642,
12096,
14,
8802,
2370,
883,
506,
1911,
2348,
26,
199,
3,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
1296,
63,
1618,
63,
3903,
63,
13325,
63,
991,
63,
354,
199,
3,
22160,
440,
1006,
3415,
1443,
506,
2808,
641,
1006,
17406,
10460,
14,
199,
3,
1010,
282,
5417,
3734,
642,
1471,
506,
663,
370,
2195,
2656,
900,
5718,
14,
199,
4961,
63,
15353,
275,
283,
8841,
15,
28796,
7,
199,
199,
3,
8466,
1233,
367,
642,
12096,
14,
2900,
3415,
883,
506,
1911,
2348,
26,
199,
3,
1455,
921,
1544,
14,
73,
1085,
2753,
29514,
14,
957,
15,
2975,
15,
3671,
13,
14227,
14,
1360,
199,
13947,
63,
6012,
275,
283,
287,
13,
527,
7,
199,
199,
7917,
63,
998,
275,
413,
199,
199,
3,
982,
1265,
663,
642,
370,
756,
12,
5634,
911,
1852,
2005,
5323,
12270,
880,
465,
440,
199,
3,
370,
2248,
314,
10757,
6279,
2072,
28540,
14,
199,
4701,
63,
41,
1085,
46,
275,
715,
199,
199,
3,
982,
1265,
663,
642,
370,
756,
12,
5634,
911,
440,
1475,
10831,
12,
5579,
436,
199,
3,
1704,
31276,
7182,
370,
314,
1453,
5867,
14,
199,
4701,
63,
44,
709,
46,
275,
715,
199,
199,
3,
982,
1265,
663,
642,
370,
756,
12,
5634,
911,
440,
675,
7137,
13,
14600,
29297,
14,
199,
4701,
63,
14226,
275,
756,
199,
199,
3,
24964,
10036,
931,
370,
314,
2082,
626,
911,
10266,
922,
13,
19044,
1584,
14,
199,
3,
5679,
26,
3286,
1391,
15,
1544,
15,
2694,
14,
957,
15,
4603,
6687,
199,
13669,
63,
5441,
275,
2125,
199,
199,
3,
2851,
626,
10022,
314,
5898,
19733,
687,
31460,
63,
5441,
14,
4155,
3238,
370,
675,
282,
199,
3,
8520,
14457,
14,
199,
3,
6058,
26,
298,
1014,
921,
2694,
14,
957,
15,
4603,
10665,
298,
1014,
921,
4603,
14,
2694,
14,
957,
6687,
199,
13669,
63,
2632,
275,
2125,
199,
199,
3,
24964,
931,
370,
314,
2082,
2955,
1584,
1077,
506,
13736,
370,
14,
199,
3,
7529,
1133,
5324,
7003,
315,
642,
2082,
28225,
27,
3877,
2195,
2955,
1584,
199,
3,
315,
8686,
7,
298,
1986,
6687,
24799,
436,
315,
27815,
9472,
63,
14455,
14,
199,
3,
5679,
26,
3286,
1391,
15,
1544,
15,
2694,
14,
957,
15,
1986,
6687,
199,
10449,
63,
5441,
275,
2125,
199,
199,
3,
2851,
2403,
367,
2955,
1584,
14,
199,
3,
5679,
26,
298,
1014,
921,
2694,
14,
957,
15,
1986,
10665,
298,
1014,
921,
1986,
14,
2694,
14,
957,
6687,
199,
10449,
63,
2632,
275,
1994,
1986,
4805,
199,
199,
3,
10961,
9918,
402,
2955,
1584,
199,
10449,
9472,
63,
14455,
275,
334,
272,
327,
16280,
3326,
2348,
12,
2839,
3286,
4219,
15,
1360,
15,
1986,
2,
503,
298,
35,
11254,
1544,
15,
1176,
15,
1986,
1674,
272,
327,
16763,
675,
7568,
20275,
12,
2755,
641,
5417,
14,
272,
327,
7529,
1133,
19459,
370,
675,
3679,
3792,
12,
440,
3847,
3792,
14,
199,
9,
199,
199,
3,
3820,
402,
11569,
3992,
626,
5715,
4212,
370,
2342,
2955,
1584,
315,
199,
3,
7750,
9918,
14,
199,
10449,
9472,
63,
27087,
3960,
275,
334,
272,
283,
1176,
14,
2828,
14,
18373,
14,
26677,
14,
17521,
11791,
297,
272,
283,
1176,
14,
2828,
14,
18373,
14,
26677,
14,
2640,
13752,
11791,
297,
199,
3,
259,
283,
1176,
14,
2828,
14,
18373,
14,
26677,
14,
2698,
6408,
11791,
297,
199,
9,
199,
199,
3,
4155,
642,
3747,
12,
436,
2793,
1133,
8663,
652,
543,
1263,
2030,
14,
199,
12961,
63,
3078,
275,
11400,
7565,
63,
498,
16339,
199,
199,
3,
3820,
402,
28041,
626,
5715,
4212,
370,
492,
7009,
687,
7750,
5274,
14,
199,
7433,
63,
7405,
3960,
275,
334,
272,
283,
1176,
14,
1160,
14,
16370,
14,
11381,
14,
5455,
297,
272,
283,
1176,
14,
1160,
14,
16370,
14,
571,
63,
12629,
14,
5455,
297,
199,
3,
258,
283,
1176,
14,
1160,
14,
16370,
14,
14488,
14,
5455,
297,
199,
9,
199,
199,
19987,
63,
13748,
275,
334,
272,
327,
961,
14404,
314,
1478,
10269,
12,
880,
652,
965,
370,
11492,
1642,
272,
283,
2495,
912,
14,
5754,
14,
3358,
912,
6608,
297,
339,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
272,
283,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
297,
272,
327,
1910,
3349,
314,
2163,
1004,
367,
3486,
8968,
19193,
316,
23977,
26,
272,
327,
283,
1176,
14,
5754,
14,
4891,
19193,
316,
14,
56,
3160,
4558,
6608,
297,
199,
9,
199,
199,
5441,
63,
18125,
275,
11400,
2199,
63,
354,
3586,
14,
3603,
7,
199,
199,
7433,
63,
14455,
275,
334,
272,
327,
16280,
3326,
2348,
12,
2839,
3286,
4219,
15,
1360,
15,
1176,
63,
5876,
2,
503,
298,
35,
11254,
1544,
15,
1176,
15,
5876,
1674,
272,
327,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
DoctorJellyface/powerline
|
powerline/bindings/qtile/widget.py
|
34
|
1638
|
# vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import, print_function)
from libqtile.bar import CALCULATED
from libqtile.widget import TextBox
from powerline import Powerline
class QTilePowerline(Powerline):
def do_setup(self, obj):
obj.powerline = self
class PowerlineTextBox(TextBox):
# TODO Replace timeout argument with update_interval argument in next major
# release.
def __init__(self, timeout=2, text=b' ', width=CALCULATED, side='right', update_interval=None, **config):
super(PowerlineTextBox, self).__init__(text, width, **config)
self.side = side
self.update_interval = update_interval or timeout
self.did_run_timer_setup = False
powerline = QTilePowerline(ext='wm', renderer_module='pango_markup')
powerline.setup(self)
def update(self):
if not self.configured:
return True
self.text = self.powerline.render(side=self.side).encode('utf-8')
self.bar.draw()
return True
def cmd_update(self, text):
self.update(text)
def cmd_get(self):
return self.text
def timer_setup(self):
if not self.did_run_timer_setup:
self.did_run_timer_setup = True
self.timeout_add(self.update_interval, self.update)
def _configure(self, qtile, bar):
super(PowerlineTextBox, self)._configure(qtile, bar)
if self.layout.markup:
# QTile-0.9.1: no need to recreate layout or run timer_setup
return
self.layout = self.drawer.textlayout(
self.text,
self.foreground,
self.font,
self.fontsize,
self.fontshadow,
markup=True,
)
self.timer_setup()
# TODO: Remove this at next major release
Powerline = PowerlineTextBox
|
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,
504,
1973,
81,
7172,
14,
1700,
492,
445,
748,
35,
1293,
6989,
199,
504,
1973,
81,
7172,
14,
3440,
492,
4516,
3532,
199,
199,
504,
7074,
604,
492,
18879,
604,
421,
199,
533,
1413,
29746,
6921,
604,
8,
6921,
604,
304,
199,
198,
318,
886,
63,
2758,
8,
277,
12,
1559,
304,
507,
198,
1113,
14,
5652,
604,
275,
291,
421,
199,
533,
18879,
604,
1872,
3532,
8,
1872,
3532,
304,
199,
198,
3,
3254,
14402,
2653,
1423,
543,
1678,
63,
4284,
1423,
315,
2163,
12160,
9948,
198,
3,
420,
4683,
14,
199,
198,
318,
636,
826,
721,
277,
12,
2653,
29,
18,
12,
1318,
29,
66,
7,
1656,
3462,
29,
13329,
35,
1293,
6989,
12,
5366,
534,
1019,
297,
1678,
63,
4284,
29,
403,
12,
1011,
888,
304,
507,
198,
4792,
8,
6921,
604,
1872,
3532,
12,
291,
2843,
826,
721,
505,
12,
3462,
12,
1011,
888,
9,
507,
198,
277,
14,
2441,
275,
5366,
507,
198,
277,
14,
873,
63,
4284,
275,
1678,
63,
4284,
503,
2653,
507,
198,
277,
14,
14887,
63,
1065,
63,
7414,
63,
2758,
275,
756,
507,
198,
5652,
604,
275,
1413,
29746,
6921,
604,
8,
832,
534,
16240,
297,
11889,
63,
578,
534,
80,
17771,
63,
10131,
358,
507,
198,
5652,
604,
14,
2758,
8,
277,
9,
421,
198,
318,
1678,
8,
277,
304,
507,
198,
692,
440,
291,
14,
11786,
26,
686,
198,
1107,
715,
507,
198,
277,
14,
505,
275,
291,
14,
5652,
604,
14,
3352,
8,
2441,
29,
277,
14,
2441,
680,
2143,
360,
1624,
13,
24,
358,
507,
198,
277,
14,
1700,
14,
5485,
342,
507,
198,
1107,
715,
421,
198,
318,
2088,
63,
873,
8,
277,
12,
1318,
304,
507,
198,
277,
14,
873,
8,
505,
9,
421,
198,
318,
2088,
63,
362,
8,
277,
304,
507,
198,
1107,
291,
14,
505,
421,
198,
318,
9715,
63,
2758,
8,
277,
304,
507,
198,
692,
440,
291,
14,
14887,
63,
1065,
63,
7414,
63,
2758,
26,
686,
198,
277,
14,
14887,
63,
1065,
63,
7414,
63,
2758,
275,
715,
686,
198,
277,
14,
2593,
63,
525,
8,
277,
14,
873,
63,
4284,
12,
291,
14,
873,
9,
421,
198,
318,
485,
6472,
8,
277,
12,
1894,
7172,
12,
4681,
304,
507,
198,
4792,
8,
6921,
604,
1872,
3532,
12,
291,
10445,
6472,
8,
81,
7172,
12,
4681,
9,
507,
198,
692,
291,
14,
4209,
14,
10131,
26,
686,
198,
3,
1413,
29746,
13,
16,
14,
25,
14,
17,
26,
949,
1929,
370,
23959,
7054,
503,
1255,
9715,
63,
2758,
686,
198,
1107,
507,
198,
277,
14,
4209,
275,
291,
14,
5485,
281,
14,
505,
4209,
8,
686,
198,
277,
14,
505,
12,
686,
198,
277,
14,
23801,
12,
686,
198,
277,
14,
4246,
12,
686,
198,
277,
14,
22124,
12,
686,
198,
277,
14,
4246,
14714,
12,
686,
198,
10131,
29,
549,
12,
507,
198,
9,
507,
198,
277,
14,
7414,
63,
2758,
342,
421,
199,
3,
3254,
26,
5852,
642,
737,
2163,
12160,
4683,
199,
6921,
604,
275,
18879,
604,
1872,
3532,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
504,
1973,
81,
7172,
14,
1700,
492,
445,
748,
35,
1293,
6989,
199,
504,
1973,
81,
7172,
14,
3440,
492,
4516,
3532,
199,
199,
504,
7074,
604,
492,
18879,
604,
421,
199,
533,
1413,
29746,
6921,
604,
8,
6921,
604,
304,
199,
198,
318,
886,
63,
2758,
8,
277,
12,
1559,
304,
507,
198,
1113,
14,
5652,
604,
275,
291,
421,
199,
533,
18879,
604,
1872,
3532,
8,
1872,
3532,
304,
199,
198,
3,
3254,
14402,
2653,
1423,
543,
1678,
63,
4284,
1423,
315,
2163,
12160,
9948,
198,
3,
420,
4683,
14,
199,
198,
318,
636,
826,
721,
277,
12,
2653,
29,
18,
12,
1318,
29,
66,
7,
1656,
3462,
29,
13329,
35,
1293,
6989,
12,
5366,
534,
1019,
297,
1678,
63,
4284,
29,
403,
12,
1011,
888,
304,
507,
198,
4792,
8,
6921,
604,
1872,
3532,
12,
291,
2843,
826,
721,
505,
12,
3462,
12,
1011,
888,
9,
507,
198,
277,
14,
2441,
275,
5366,
507,
198,
277,
14,
873,
63,
4284,
275,
1678,
63,
4284,
503,
2653,
507,
198,
277,
14,
14887,
63,
1065,
63,
7414,
63,
2758,
275,
756,
507,
198,
5652,
604,
275,
1413,
29746,
6921,
604,
8,
832,
534,
16240,
297,
11889,
63,
578,
534,
80,
17771,
63,
10131,
358,
507,
198,
5652,
604,
14,
2758,
8,
277,
9,
421,
198,
318,
1678,
8,
277,
304,
507,
198,
692,
440,
291,
14,
11786,
26,
686,
198,
1107,
715,
507,
198,
277,
14,
505,
275,
291,
14,
5652,
604,
14,
3352,
8,
2441,
29,
277,
14,
2441,
680,
2143,
360,
1624,
13,
24,
358,
507,
198,
277,
14,
1700,
14,
5485,
342,
507,
198,
1107,
715,
421,
198,
318,
2088,
63,
873,
8,
277,
12,
1318,
304,
507,
198,
277,
14,
873,
8,
505,
9,
421,
198,
318,
2088,
63,
362,
8,
277,
304,
507,
198,
1107,
291,
14,
505,
421,
198,
318,
9715,
63,
2758,
8,
277,
304,
507,
198,
692,
440,
291,
14,
14887,
63,
1065,
63,
7414,
63,
2758,
26,
686,
198,
277,
14,
14887,
63,
1065,
63,
7414,
63,
2758,
275,
715,
686,
198,
277,
14,
2593,
63,
525,
8,
277,
14,
873,
63,
4284,
12,
291,
14,
873,
9,
421,
198,
318,
485,
6472,
8,
277,
12,
1894,
7172,
12,
4681,
304,
507,
198,
4792,
8,
6921,
604,
1872,
3532,
12,
291,
10445,
6472,
8,
81,
7172,
12,
4681,
9,
507,
198,
692,
291,
14,
4209,
14,
10131,
26,
686,
198,
3,
1413,
29746,
13,
16,
14,
25,
14,
17,
26,
949,
1929,
370,
23959,
7054,
503,
1255,
9715,
63,
2758,
686,
198,
1107,
507,
198,
277,
14,
4209,
275,
291,
14,
5485,
281,
14,
505,
4209,
8,
686,
198,
277,
14,
505,
12,
686,
198,
277,
14,
23801,
12,
686,
198,
277,
14,
4246,
12,
686,
198,
277,
14,
22124,
12,
686,
198,
277,
14,
4246,
14714,
12,
686,
198,
10131,
29,
549,
12,
507,
198,
9,
507,
198,
277,
14,
7414,
63,
2758,
342,
421,
199,
3,
3254,
26,
5852,
642,
737,
2163,
12160,
4683,
199,
6921,
604,
275,
18879,
604,
1872,
3532,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
BYK/fb2goog
|
gdata/core.py
|
103
|
8239
|
#!/usr/bin/env python
#
# Copyright (C) 2010 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.
# This module is used for version 2 of the Google Data APIs.
__author__ = 'j.s@google.com (Jeff Scudder)'
"""Provides classes and methods for working with JSON-C.
This module is experimental and subject to backwards incompatible changes.
Jsonc: Class which represents JSON-C data and provides pythonic member
access which is a bit cleaner than working with plain old dicts.
parse_json: Converts a JSON-C string into a Jsonc object.
jsonc_to_string: Converts a Jsonc object into a string of JSON-C.
"""
try:
import simplejson
except ImportError:
try:
# Try to import from django, should work on App Engine
from django.utils import simplejson
except ImportError:
# Should work for Python2.6 and higher.
import json as simplejson
def _convert_to_jsonc(x):
"""Builds a Jsonc objects which wraps the argument's members."""
if isinstance(x, dict):
jsonc_obj = Jsonc()
# Recursively transform all members of the dict.
# When converting a dict, we do not convert _name items into private
# Jsonc members.
for key, value in x.iteritems():
jsonc_obj._dict[key] = _convert_to_jsonc(value)
return jsonc_obj
elif isinstance(x, list):
# Recursively transform all members of the list.
members = []
for item in x:
members.append(_convert_to_jsonc(item))
return members
else:
# Return the base object.
return x
def parse_json(json_string):
"""Converts a JSON-C string into a Jsonc object.
Args:
json_string: str or unicode The JSON to be parsed.
Returns:
A new Jsonc object.
"""
return _convert_to_jsonc(simplejson.loads(json_string))
def parse_json_file(json_file):
return _convert_to_jsonc(simplejson.load(json_file))
def jsonc_to_string(jsonc_obj):
"""Converts a Jsonc object into a string of JSON-C."""
return simplejson.dumps(_convert_to_object(jsonc_obj))
def prettify_jsonc(jsonc_obj, indentation=2):
"""Converts a Jsonc object to a pretified (intented) JSON string."""
return simplejson.dumps(_convert_to_object(jsonc_obj), indent=indentation)
def _convert_to_object(jsonc_obj):
"""Creates a new dict or list which has the data in the Jsonc object.
Used to convert the Jsonc object to a plain old Python object to simplify
conversion to a JSON-C string.
Args:
jsonc_obj: A Jsonc object to be converted into simple Python objects
(dicts, lists, etc.)
Returns:
Either a dict, list, or other object with members converted from Jsonc
objects to the corresponding simple Python object.
"""
if isinstance(jsonc_obj, Jsonc):
plain = {}
for key, value in jsonc_obj._dict.iteritems():
plain[key] = _convert_to_object(value)
return plain
elif isinstance(jsonc_obj, list):
plain = []
for item in jsonc_obj:
plain.append(_convert_to_object(item))
return plain
else:
return jsonc_obj
def _to_jsonc_name(member_name):
"""Converts a Python style member name to a JSON-C style name.
JSON-C uses camelCaseWithLower while Python tends to use
lower_with_underscores so this method converts as follows:
spam becomes spam
spam_and_eggs becomes spamAndEggs
Args:
member_name: str or unicode The Python syle name which should be
converted to JSON-C style.
Returns:
The JSON-C style name as a str or unicode.
"""
characters = []
uppercase_next = False
for character in member_name:
if character == '_':
uppercase_next = True
elif uppercase_next:
characters.append(character.upper())
uppercase_next = False
else:
characters.append(character)
return ''.join(characters)
class Jsonc(object):
"""Represents JSON-C data in an easy to access object format.
To access the members of a JSON structure which looks like this:
{
"data": {
"totalItems": 800,
"items": [
{
"content": {
"1": "rtsp://v5.cache3.c.youtube.com/CiILENy.../0/0/0/video.3gp"
},
"viewCount": 220101,
"commentCount": 22,
"favoriteCount": 201
}
]
},
"apiVersion": "2.0"
}
You would do the following:
x = gdata.core.parse_json(the_above_string)
# Gives you 800
x.data.total_items
# Should be 22
x.data.items[0].comment_count
# The apiVersion is '2.0'
x.api_version
To create a Jsonc object which would produce the above JSON, you would do:
gdata.core.Jsonc(
api_version='2.0',
data=gdata.core.Jsonc(
total_items=800,
items=[
gdata.core.Jsonc(
view_count=220101,
comment_count=22,
favorite_count=201,
content={
'1': ('rtsp://v5.cache3.c.youtube.com'
'/CiILENy.../0/0/0/video.3gp')})]))
or
x = gdata.core.Jsonc()
x.api_version = '2.0'
x.data = gdata.core.Jsonc()
x.data.total_items = 800
x.data.items = []
# etc.
How it works:
The JSON-C data is stored in an internal dictionary (._dict) and the
getattr, setattr, and delattr methods rewrite the name which you provide
to mirror the expected format in JSON-C. (For more details on name
conversion see _to_jsonc_name.) You may also access members using
getitem, setitem, delitem as you would for a dictionary. For example
x.data.total_items is equivalent to x['data']['totalItems']
(Not all dict methods are supported so if you need something other than
the item operations, then you will want to use the ._dict member).
You may need to use getitem or the _dict member to access certain
properties in cases where the JSON-C syntax does not map neatly to Python
objects. For example the YouTube Video feed has some JSON like this:
"content": {"1": "rtsp://v5.cache3.c.youtube.com..."...}
You cannot do x.content.1 in Python, so you would use the getitem as
follows:
x.content['1']
or you could use the _dict member as follows:
x.content._dict['1']
If you need to create a new object with such a mapping you could use.
x.content = gdata.core.Jsonc(_dict={'1': 'rtsp://cache3.c.youtube.com...'})
"""
def __init__(self, _dict=None, **kwargs):
json = _dict or {}
for key, value in kwargs.iteritems():
if key.startswith('_'):
object.__setattr__(self, key, value)
else:
json[_to_jsonc_name(key)] = _convert_to_jsonc(value)
object.__setattr__(self, '_dict', json)
def __setattr__(self, name, value):
if name.startswith('_'):
object.__setattr__(self, name, value)
else:
object.__getattribute__(
self, '_dict')[_to_jsonc_name(name)] = _convert_to_jsonc(value)
def __getattr__(self, name):
if name.startswith('_'):
object.__getattribute__(self, name)
else:
try:
return object.__getattribute__(self, '_dict')[_to_jsonc_name(name)]
except KeyError:
raise AttributeError(
'No member for %s or [\'%s\']' % (name, _to_jsonc_name(name)))
def __delattr__(self, name):
if name.startswith('_'):
object.__delattr__(self, name)
else:
try:
del object.__getattribute__(self, '_dict')[_to_jsonc_name(name)]
except KeyError:
raise AttributeError(
'No member for %s (or [\'%s\'])' % (name, _to_jsonc_name(name)))
# For container methods pass-through to the underlying dict.
def __getitem__(self, key):
return self._dict[key]
def __setitem__(self, key, value):
self._dict[key] = value
def __delitem__(self, key):
del self._dict[key]
|
mpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
259,
1898,
334,
35,
9,
7129,
4475,
3277,
14,
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,
755,
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,
421,
199,
3,
961,
859,
365,
1202,
367,
1015,
499,
402,
314,
4475,
3918,
15913,
14,
421,
199,
363,
2502,
363,
275,
283,
74,
14,
83,
32,
3098,
14,
957,
334,
42,
3609,
13916,
1181,
424,
3171,
421,
199,
624,
17473,
3992,
436,
3102,
367,
6449,
543,
4840,
13,
35,
14,
199,
199,
2765,
859,
365,
22820,
436,
5420,
370,
8552,
18457,
4493,
14,
819,
14587,
67,
26,
8089,
1314,
8469,
4840,
13,
35,
666,
436,
6571,
2366,
530,
3653,
268,
2879,
1314,
365,
282,
4546,
3633,
281,
2419,
6449,
543,
8971,
2269,
10809,
14,
523,
2198,
63,
1001,
26,
19107,
282,
4840,
13,
35,
1059,
1901,
282,
14587,
67,
909,
14,
523,
2022,
67,
63,
475,
63,
875,
26,
19107,
282,
14587,
67,
909,
1901,
282,
1059,
402,
4840,
13,
35,
14,
199,
624,
421,
199,
893,
26,
523,
492,
13804,
199,
2590,
3545,
26,
523,
862,
26,
272,
327,
7649,
370,
492,
687,
1639,
12,
1077,
1736,
641,
4693,
12580,
272,
687,
1639,
14,
1208,
492,
13804,
16421,
871,
3545,
26,
272,
327,
7719,
1736,
367,
2018,
18,
14,
22,
436,
10948,
14,
272,
492,
2022,
465,
13804,
421,
199,
318,
485,
3916,
63,
475,
63,
1001,
67,
8,
88,
304,
523,
408,
27856,
282,
14587,
67,
2251,
1314,
14018,
314,
1423,
1159,
7556,
1041,
819,
340,
1228,
8,
88,
12,
1211,
304,
272,
2022,
67,
63,
1113,
275,
14587,
67,
342,
272,
327,
18306,
9840,
5793,
1006,
7556,
402,
314,
1211,
14,
272,
327,
3979,
13806,
282,
1211,
12,
781,
886,
440,
3957,
485,
354,
2974,
1901,
5726,
272,
327,
14587,
67,
7556,
14,
272,
367,
790,
12,
574,
315,
671,
14,
4611,
837,
489,
2022,
67,
63,
1113,
423,
807,
59,
498,
61,
275,
485,
3916,
63,
475,
63,
1001,
67,
8,
585,
9,
272,
372,
2022,
67,
63,
1113,
523,
916,
1228,
8,
88,
12,
769,
304,
272,
327,
18306,
9840,
5793,
1006,
7556,
402,
314,
769,
14,
272,
7556,
275,
942,
272,
367,
1242,
315,
671,
26,
489,
7556,
14,
740,
1547,
3916,
63,
475,
63,
1001,
67,
8,
1053,
430,
272,
372,
7556,
523,
587,
26,
272,
327,
1432,
314,
1300,
909,
14,
272,
372,
671,
421,
199,
318,
2198,
63,
1001,
8,
1001,
63,
875,
304,
523,
408,
17729,
282,
4840,
13,
35,
1059,
1901,
282,
14587,
67,
909,
14,
12244,
3033,
26,
272,
2022,
63,
875,
26,
620,
503,
2649,
710,
4840,
370,
506,
4565,
14,
12244,
1803,
26,
272,
437,
892,
14587,
67,
909,
14,
523,
408,
819,
372,
485,
3916,
63,
475,
63,
1001,
67,
8,
4129,
1001,
14,
3640,
8,
1001,
63,
875,
430,
421,
199,
318,
2198,
63,
1001,
63,
493,
8,
1001,
63,
493,
304,
523,
372,
485,
3916,
63,
475,
63,
1001,
67,
8,
4129,
1001,
14,
912,
8,
1001,
63,
493,
430,
421,
199,
318,
2022,
67,
63,
475,
63,
875,
8,
1001,
67,
63,
1113,
304,
523,
408,
17729,
282,
14587,
67,
909,
1901,
282,
1059,
402,
4840,
13,
35,
1041,
819,
372,
13804,
14,
4180,
1547,
3916,
63,
475,
63,
785,
8,
1001,
67,
63,
1113,
430,
421,
199,
318,
876,
84,
3338,
63,
1001,
67,
8,
1001,
67,
63,
1113,
12,
14311,
29,
18,
304,
523,
408,
17729,
282,
14587,
67,
909,
370,
282,
876,
8981,
334,
262,
724,
471,
9,
4840,
1059,
1041,
819,
372,
13804,
14,
4180,
1547,
3916,
63,
475,
63,
785,
8,
1001,
67,
63,
1113,
395,
4363,
29,
25152,
9,
4388,
199,
318,
485,
3916,
63,
475,
63,
785,
8,
1001,
67,
63,
1113,
304,
523,
408,
10607,
282,
892,
1211,
503,
769,
1314,
965,
314,
666,
315,
314,
14587,
67,
909,
14,
12244,
8051,
370,
3957,
314,
14587,
67,
909,
370,
282,
8971,
2269,
2018,
909,
370,
15037,
523,
8603,
370,
282,
4840,
13,
35,
1059,
14,
819,
3033,
26,
272,
2022,
67,
63,
1113,
26,
437,
14587,
67,
909,
370,
506,
6702,
1901,
3486,
2018,
2251,
2049,
334,
7892,
12,
5548,
12,
5423,
4959,
819,
1803,
26,
272,
13083,
282,
1211,
12,
769,
12,
503,
1163,
909,
543,
7556,
6702,
687,
14587,
67,
272,
2251,
370,
314,
5226,
3486,
2018,
909,
14,
523,
408,
819,
340,
1228,
8,
1001,
67,
63,
1113,
12,
14587,
67,
304,
272,
8971,
275,
1052,
272,
367,
790,
12,
574,
315,
2022,
67,
63,
1113,
423,
807,
14,
4611,
837,
489,
8971,
59,
498,
61,
275,
485,
3916,
63,
475,
63,
785,
8,
585,
9,
272,
372,
8971,
523,
916,
1228,
8,
1001,
67,
63,
1113,
12,
769,
304,
272,
8971,
275,
942,
272,
367,
1242,
315,
2022,
67,
63,
1113,
26,
489,
8971,
14,
740,
1547,
3916,
63,
475,
63,
785,
8,
1053,
430,
272,
372,
8971,
523,
587,
26,
272,
372,
2022,
67,
63,
1113,
421,
199,
318,
485,
475,
63,
1001,
67,
63,
354,
8,
1114,
63,
354,
304,
523,
408,
17729,
282,
2018,
3449,
3653,
536,
370,
282,
4840,
13,
35,
3449,
536,
14,
12244,
4840,
13,
35,
4440,
31129,
1538,
3007,
17846,
1830,
2018,
16685,
795,
370,
675,
523,
5117,
63,
1045,
63,
7138,
7107,
880,
642,
1083,
15373,
465,
11924,
26,
819,
14909,
15410,
14909,
523,
14909,
63,
460,
63,
14488,
15410,
14909,
3325,
29496,
458,
819,
3033
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
259,
1898,
334,
35,
9,
7129,
4475,
3277,
14,
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,
755,
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,
421,
199,
3,
961,
859,
365,
1202,
367,
1015,
499,
402,
314,
4475,
3918,
15913,
14,
421,
199,
363,
2502,
363,
275,
283,
74,
14,
83,
32,
3098,
14,
957,
334,
42,
3609,
13916,
1181,
424,
3171,
421,
199,
624,
17473,
3992,
436,
3102,
367,
6449,
543,
4840,
13,
35,
14,
199,
199,
2765,
859,
365,
22820,
436,
5420,
370,
8552,
18457,
4493,
14,
819,
14587,
67,
26,
8089,
1314,
8469,
4840,
13,
35,
666,
436,
6571,
2366,
530,
3653,
268,
2879,
1314,
365,
282,
4546,
3633,
281,
2419,
6449,
543,
8971,
2269,
10809,
14,
523,
2198,
63,
1001,
26,
19107,
282,
4840,
13,
35,
1059,
1901,
282,
14587,
67,
909,
14,
523,
2022,
67,
63,
475,
63,
875,
26,
19107,
282,
14587,
67,
909,
1901,
282,
1059,
402,
4840,
13,
35,
14,
199,
624,
421,
199,
893,
26,
523,
492,
13804,
199,
2590,
3545,
26,
523,
862,
26,
272,
327,
7649,
370,
492,
687,
1639,
12,
1077,
1736,
641,
4693,
12580,
272,
687,
1639,
14,
1208,
492,
13804,
16421,
871,
3545,
26,
272,
327,
7719,
1736,
367,
2018,
18,
14,
22,
436,
10948,
14,
272,
492,
2022,
465,
13804,
421,
199,
318,
485,
3916,
63,
475,
63,
1001,
67,
8,
88,
304,
523,
408,
27856,
282,
14587,
67,
2251,
1314,
14018,
314,
1423,
1159,
7556,
1041,
819,
340,
1228,
8,
88,
12,
1211,
304,
272,
2022,
67,
63,
1113,
275,
14587,
67,
342,
272,
327,
18306,
9840,
5793,
1006,
7556,
402,
314,
1211,
14,
272,
327,
3979,
13806,
282,
1211,
12,
781,
886,
440,
3957,
485,
354,
2974,
1901,
5726,
272,
327,
14587,
67,
7556,
14,
272,
367,
790,
12,
574,
315,
671,
14,
4611,
837,
489,
2022,
67,
63,
1113,
423,
807,
59,
498,
61,
275,
485,
3916,
63,
475,
63,
1001,
67,
8,
585,
9,
272,
372,
2022,
67,
63,
1113,
523,
916,
1228,
8,
88,
12,
769,
304,
272,
327,
18306,
9840,
5793,
1006,
7556,
402,
314,
769,
14,
272,
7556,
275,
942,
272,
367,
1242,
315,
671,
26,
489,
7556,
14,
740,
1547,
3916,
63,
475,
63,
1001,
67,
8,
1053,
430,
272,
372,
7556,
523,
587,
26,
272,
327,
1432,
314,
1300,
909,
14,
272,
372,
671,
421,
199,
318,
2198,
63,
1001,
8,
1001,
63,
875,
304,
523,
408,
17729,
282,
4840,
13,
35,
1059,
1901,
282,
14587,
67,
909,
14,
12244,
3033,
26,
272,
2022,
63,
875,
26,
620,
503,
2649,
710,
4840,
370,
506,
4565,
14,
12244,
1803,
26,
272,
437,
892,
14587,
67,
909,
14,
523,
408,
819,
372,
485,
3916,
63,
475,
63,
1001,
67,
8,
4129,
1001,
14,
3640,
8,
1001,
63,
875,
430,
421,
199,
318,
2198,
63,
1001,
63,
493,
8,
1001,
63,
493,
304,
523,
372,
485,
3916,
63,
475,
63,
1001,
67,
8,
4129,
1001,
14,
912,
8,
1001,
63,
493,
430,
421,
199,
318,
2022,
67,
63,
475,
63,
875,
8,
1001,
67,
63,
1113,
304,
523,
408,
17729,
282,
14587,
67,
909,
1901,
282,
1059,
402,
4840,
13,
35,
1041,
819,
372,
13804,
14,
4180,
1547,
3916,
63,
475,
63,
785,
8,
1001,
67,
63,
1113,
430,
421,
199,
318,
876,
84,
3338,
63,
1001,
67,
8,
1001,
67,
63,
1113,
12,
14311,
29,
18,
304,
523,
408,
17729,
282,
14587,
67,
909,
370,
282,
876,
8981,
334,
262,
724,
471,
9,
4840,
1059,
1041,
819,
372,
13804,
14,
4180,
1547,
3916,
63,
475,
63,
785,
8,
1001,
67,
63,
1113,
395,
4363,
29,
25152,
9,
4388,
199,
318,
485,
3916,
63,
475,
63,
785,
8,
1001,
67,
63,
1113,
304,
523,
408,
10607,
282,
892,
1211,
503,
769,
1314,
965,
314,
666,
315,
314,
14587,
67,
909,
14,
12244,
8051,
370,
3957,
314,
14587,
67,
909,
370,
282,
8971,
2269,
2018,
909,
370,
15037,
523,
8603,
370,
282,
4840,
13,
35,
1059,
14,
819,
3033,
26,
272,
2022,
67,
63,
1113,
26,
437,
14587,
67,
909,
370,
506,
6702,
1901,
3486,
2018,
2251,
2049,
334,
7892,
12,
5548,
12,
5423,
4959,
819,
1803,
26,
272,
13083,
282,
1211,
12,
769,
12,
503,
1163,
909,
543,
7556,
6702,
687,
14587,
67,
272,
2251,
370,
314,
5226,
3486,
2018,
909,
14,
523,
408,
819,
340,
1228,
8,
1001,
67,
63,
1113,
12,
14587,
67,
304,
272,
8971,
275,
1052,
272,
367,
790,
12,
574,
315,
2022,
67,
63,
1113,
423,
807,
14,
4611,
837,
489,
8971,
59,
498,
61,
275,
485,
3916,
63,
475,
63,
785,
8,
585,
9,
272,
372,
8971,
523,
916,
1228,
8,
1001,
67,
63,
1113,
12,
769,
304,
272,
8971,
275,
942,
272,
367,
1242,
315,
2022,
67,
63,
1113,
26,
489,
8971,
14,
740,
1547,
3916,
63,
475,
63,
785,
8,
1053,
430,
272,
372,
8971,
523,
587,
26,
272,
372,
2022,
67,
63,
1113,
421,
199,
318,
485,
475,
63,
1001,
67,
63,
354,
8,
1114,
63,
354,
304,
523,
408,
17729,
282,
2018,
3449,
3653,
536,
370,
282,
4840,
13,
35,
3449,
536,
14,
12244,
4840,
13,
35,
4440,
31129,
1538,
3007,
17846,
1830,
2018,
16685,
795,
370,
675,
523,
5117,
63,
1045,
63,
7138,
7107,
880,
642,
1083,
15373,
465,
11924,
26,
819,
14909,
15410,
14909,
523,
14909,
63,
460,
63,
14488,
15410,
14909,
3325,
29496,
458,
819,
3033,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dictoss/active-task-summary
|
ats/libs.py
|
1
|
2855
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import time
import datetime
import logging
import csv
import six
from datetime import date
from django.apps import apps
from django.utils import timezone
logger = logging.getLogger(__name__)
ats_settings = apps.get_app_config('ats')
def get_user_realname(first_name, last_name, is_last_name_front):
if is_last_name_front:
return '%s %s' % (last_name, first_name)
else:
return '%s %s' % (first_name, last_name)
def format_totaltime(td):
totalhour = (td.days * 24) + int(td.seconds / 3600)
minute = int(td.seconds / 60) - (int(td.seconds / 3600) * 60)
return '%d:%02d' % (totalhour, minute)
def format_hours_float(td):
return (td.days * 24) + (td.seconds / 3600.0)
def format_time(timedata):
return '%d:%02d' % (timedata.hour, timedata.minute)
def get_localtime():
_now = timezone.localtime()
# logger.debug("get_localtime() : %s" % (_now))
return _now
def get_thismonth_1st():
_now = timezone.localtime()
_ret = _now.replace(day=1)
# logger.debug("get_thismonth_1st(): %s" % (_ret))
return _ret
def export_csv_task(datalist, add_header, new_line):
_s = ''
if six.PY2:
bufffer = six.BytesIO()
else:
bufffer = six.StringIO()
try:
if True:
_writer = csv.writer(
bufffer, lineterminator=new_line,
quotechar='"', quoting=csv.QUOTE_ALL)
if add_header:
_header = ['date', 'project', 'code', 'job', 'task', 'user', 'tasktime']
_writer.writerow(_header)
for d in datalist:
_line = []
_date = d['taskdate'].isoformat()
_line.append(_date)
_line.append(d['project__name'])
if d['project__external_project__code']:
_line.append(d['project__external_project__code'])
else:
_line.append('')
_line.append(d['task__job__name'])
_line.append(d['task__name'])
_line.append(get_user_realname(d['user__first_name'], d['user__last_name'], ats_settings.ATS_IS_LASTNAME_FRONT))
_line.append(format_time(d['tasktime']))
if six.PY2:
for i in range(len(_line)):
_line[i] = _line[i].encode('utf8')
_writer.writerow(_line)
_s = bufffer.getvalue()
bufffer.close()
if six.PY3:
_s = _s.encode('utf8')
except Exception as e:
logger.error('fail export_csv_task().')
logger.error('EXCEPT: export_csv_task(). e=%s, msg1=%s,msg2=%s',
e, sys.exc_info()[1], sys.exc_info()[2])
return None
return _s
|
bsd-2-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
646,
2197,
199,
646,
2050,
199,
646,
7392,
199,
646,
3816,
199,
504,
2197,
492,
1434,
199,
199,
504,
1639,
14,
5181,
492,
8686,
199,
504,
1639,
14,
1208,
492,
7137,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
1956,
63,
1751,
275,
8686,
14,
362,
63,
571,
63,
888,
360,
1956,
358,
421,
199,
318,
664,
63,
751,
63,
3093,
354,
8,
2246,
63,
354,
12,
2061,
63,
354,
12,
365,
63,
2019,
63,
354,
63,
14708,
304,
272,
340,
365,
63,
2019,
63,
354,
63,
14708,
26,
267,
372,
1543,
83,
450,
83,
7,
450,
334,
2019,
63,
354,
12,
1642,
63,
354,
9,
272,
587,
26,
267,
372,
1543,
83,
450,
83,
7,
450,
334,
2246,
63,
354,
12,
2061,
63,
354,
9,
421,
199,
318,
1475,
63,
2923,
521,
8,
2076,
304,
272,
3141,
5180,
275,
334,
2076,
14,
4899,
627,
5504,
9,
435,
1109,
8,
2076,
14,
4515,
1182,
15751,
9,
272,
12709,
275,
1109,
8,
2076,
14,
4515,
1182,
5212,
9,
446,
334,
442,
8,
2076,
14,
4515,
1182,
15751,
9,
627,
5212,
9,
339,
372,
1543,
68,
2689,
996,
68,
7,
450,
334,
2923,
5180,
12,
12709,
9,
421,
199,
318,
1475,
63,
8419,
63,
1609,
8,
2076,
304,
272,
372,
334,
2076,
14,
4899,
627,
5504,
9,
435,
334,
2076,
14,
4515,
1182,
15751,
14,
16,
9,
421,
199,
318,
1475,
63,
521,
8,
521,
576,
304,
272,
372,
1543,
68,
2689,
996,
68,
7,
450,
334,
521,
576,
14,
5180,
12,
900,
576,
14,
10698,
9,
421,
199,
318,
664,
63,
15198,
837,
272,
485,
2131,
275,
7137,
14,
15198,
342,
339,
327,
2512,
14,
1757,
480,
362,
63,
15198,
342,
259,
520,
450,
83,
2,
450,
6110,
2131,
430,
272,
372,
485,
2131,
421,
199,
318,
664,
63,
3749,
4482,
63,
17,
270,
837,
272,
485,
2131,
275,
7137,
14,
15198,
342,
272,
485,
3292,
275,
485,
2131,
14,
1814,
8,
2977,
29,
17,
9,
339,
327,
2512,
14,
1757,
480,
362,
63,
3749,
4482,
63,
17,
270,
837,
450,
83,
2,
450,
6110,
3292,
430,
272,
372,
485,
3292,
421,
199,
318,
4843,
63,
4737,
63,
1765,
8,
4616,
26279,
12,
1050,
63,
1291,
12,
892,
63,
604,
304,
272,
485,
83,
275,
2125,
272,
340,
3816,
14,
4521,
18,
26,
267,
17893,
2412,
275,
3816,
14,
15466,
342,
272,
587,
26,
267,
17893,
2412,
275,
3816,
14,
6424,
342,
339,
862,
26,
267,
340,
715,
26,
288,
485,
5491,
275,
7392,
14,
5491,
8,
355,
17893,
2412,
12,
1004,
26370,
29,
1222,
63,
604,
12,
355,
6313,
1560,
534,
6949,
18593,
29,
4737,
14,
18495,
63,
1761,
9,
953,
340,
1050,
63,
1291,
26,
355,
485,
1291,
275,
788,
602,
297,
283,
1715,
297,
283,
600,
297,
283,
2423,
297,
283,
1765,
297,
283,
751,
297,
283,
1765,
521,
418,
355,
485,
5491,
14,
22686,
1547,
1291,
9,
953,
367,
366,
315,
6394,
26279,
26,
355,
485,
604,
275,
942,
2234,
485,
602,
275,
366,
459,
1765,
602,
2278,
17070,
342,
355,
485,
604,
14,
740,
1547,
602,
9,
2234,
485,
604,
14,
740,
8,
68,
459,
1715,
363,
354,
1105,
2234,
340,
366,
459,
1715,
363,
5159,
63,
1715,
363,
600,
2565,
490,
485,
604,
14,
740,
8,
68,
459,
1715,
363,
5159,
63,
1715,
363,
600,
1105,
355,
587,
26,
490,
485,
604,
14,
740,
8355,
2234,
485,
604,
14,
740,
8,
68,
459,
1765,
363,
2423,
363,
354,
1105,
355,
485,
604,
14,
740,
8,
68,
459,
1765,
363,
354,
1105,
355,
485,
604,
14,
740,
8,
362,
63,
751,
63,
3093,
354,
8,
68,
459,
751,
363,
2246,
63,
354,
995,
366,
459,
751,
363,
2019,
63,
354,
995,
737,
83,
63,
1751,
14,
619,
51,
63,
1311,
63,
16901,
2339,
63,
5372,
5994,
430,
355,
485,
604,
14,
740,
8,
908,
63,
521,
8,
68,
459,
1765,
521,
5156,
2234,
340,
3816,
14,
4521,
18,
26,
490,
367,
284,
315,
1425,
8,
552,
1547,
604,
2298,
717,
485,
604,
59,
73,
61,
275,
485,
604,
59,
73,
1055,
2143,
360,
1624,
24,
358,
2234,
485,
5491,
14,
22686,
1547,
604,
9,
953,
485,
83,
275,
17893,
2412,
14,
7150,
342,
288,
17893,
2412,
14,
1600,
342,
953,
340,
3816,
14,
4521,
19,
26,
355,
485,
83,
275,
485,
83,
14,
2143,
360,
1624,
24,
358,
272,
871,
2186,
465,
325,
26,
267,
2512,
14,
705,
360,
1633,
4843,
63,
4737,
63,
1765,
1252,
358,
267,
2512,
14,
705,
360,
11764,
26,
4843,
63,
4737,
63,
1765,
1252,
325,
2458,
83,
12,
1499,
17,
2458,
83,
12,
1328,
18,
2458,
83,
297,
2151,
325,
12,
984,
14,
2804,
63,
815,
3430,
17,
467,
984,
14,
2804,
63,
815,
3430,
18,
566,
398,
372,
488,
339,
372,
485,
83,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
646,
2197,
199,
646,
2050,
199,
646,
7392,
199,
646,
3816,
199,
504,
2197,
492,
1434,
199,
199,
504,
1639,
14,
5181,
492,
8686,
199,
504,
1639,
14,
1208,
492,
7137,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
1956,
63,
1751,
275,
8686,
14,
362,
63,
571,
63,
888,
360,
1956,
358,
421,
199,
318,
664,
63,
751,
63,
3093,
354,
8,
2246,
63,
354,
12,
2061,
63,
354,
12,
365,
63,
2019,
63,
354,
63,
14708,
304,
272,
340,
365,
63,
2019,
63,
354,
63,
14708,
26,
267,
372,
1543,
83,
450,
83,
7,
450,
334,
2019,
63,
354,
12,
1642,
63,
354,
9,
272,
587,
26,
267,
372,
1543,
83,
450,
83,
7,
450,
334,
2246,
63,
354,
12,
2061,
63,
354,
9,
421,
199,
318,
1475,
63,
2923,
521,
8,
2076,
304,
272,
3141,
5180,
275,
334,
2076,
14,
4899,
627,
5504,
9,
435,
1109,
8,
2076,
14,
4515,
1182,
15751,
9,
272,
12709,
275,
1109,
8,
2076,
14,
4515,
1182,
5212,
9,
446,
334,
442,
8,
2076,
14,
4515,
1182,
15751,
9,
627,
5212,
9,
339,
372,
1543,
68,
2689,
996,
68,
7,
450,
334,
2923,
5180,
12,
12709,
9,
421,
199,
318,
1475,
63,
8419,
63,
1609,
8,
2076,
304,
272,
372,
334,
2076,
14,
4899,
627,
5504,
9,
435,
334,
2076,
14,
4515,
1182,
15751,
14,
16,
9,
421,
199,
318,
1475,
63,
521,
8,
521,
576,
304,
272,
372,
1543,
68,
2689,
996,
68,
7,
450,
334,
521,
576,
14,
5180,
12,
900,
576,
14,
10698,
9,
421,
199,
318,
664,
63,
15198,
837,
272,
485,
2131,
275,
7137,
14,
15198,
342,
339,
327,
2512,
14,
1757,
480,
362,
63,
15198,
342,
259,
520,
450,
83,
2,
450,
6110,
2131,
430,
272,
372,
485,
2131,
421,
199,
318,
664,
63,
3749,
4482,
63,
17,
270,
837,
272,
485,
2131,
275,
7137,
14,
15198,
342,
272,
485,
3292,
275,
485,
2131,
14,
1814,
8,
2977,
29,
17,
9,
339,
327,
2512,
14,
1757,
480,
362,
63,
3749,
4482,
63,
17,
270,
837,
450,
83,
2,
450,
6110,
3292,
430,
272,
372,
485,
3292,
421,
199,
318,
4843,
63,
4737,
63,
1765,
8,
4616,
26279,
12,
1050,
63,
1291,
12,
892,
63,
604,
304,
272,
485,
83,
275,
2125,
272,
340,
3816,
14,
4521,
18,
26,
267,
17893,
2412,
275,
3816,
14,
15466,
342,
272,
587,
26,
267,
17893,
2412,
275,
3816,
14,
6424,
342,
339,
862,
26,
267,
340,
715,
26,
288,
485,
5491,
275,
7392,
14,
5491,
8,
355,
17893,
2412,
12,
1004,
26370,
29,
1222,
63,
604,
12,
355,
6313,
1560,
534,
6949,
18593,
29,
4737,
14,
18495,
63,
1761,
9,
953,
340,
1050,
63,
1291,
26,
355,
485,
1291,
275,
788,
602,
297,
283,
1715,
297,
283,
600,
297,
283,
2423,
297,
283,
1765,
297,
283,
751,
297,
283,
1765,
521,
418,
355,
485,
5491,
14,
22686,
1547,
1291,
9,
953,
367,
366,
315,
6394,
26279,
26,
355,
485,
604,
275,
942,
2234,
485,
602,
275,
366,
459,
1765,
602,
2278,
17070,
342,
355,
485,
604,
14,
740,
1547,
602,
9,
2234,
485,
604,
14,
740,
8,
68,
459,
1715,
363,
354,
1105,
2234,
340,
366,
459,
1715,
363,
5159,
63,
1715,
363,
600,
2565,
490,
485,
604,
14,
740,
8,
68,
459,
1715,
363,
5159,
63,
1715,
363,
600,
1105,
355,
587,
26,
490,
485,
604,
14,
740,
8355,
2234,
485,
604,
14,
740,
8,
68,
459,
1765,
363,
2423,
363,
354,
1105,
355,
485,
604,
14,
740,
8,
68,
459,
1765,
363,
354,
1105,
355,
485,
604,
14,
740,
8,
362,
63,
751,
63,
3093,
354,
8,
68,
459,
751,
363,
2246,
63,
354,
995,
366,
459,
751,
363,
2019,
63,
354,
995,
737,
83,
63,
1751,
14,
619,
51,
63,
1311,
63,
16901,
2339,
63,
5372,
5994,
430,
355,
485,
604,
14,
740,
8,
908,
63,
521,
8,
68,
459,
1765,
521,
5156,
2234,
340,
3816,
14,
4521,
18,
26,
490,
367,
284,
315,
1425,
8,
552,
1547,
604,
2298,
717,
485,
604,
59,
73,
61,
275,
485,
604,
59,
73,
1055,
2143,
360,
1624,
24,
358,
2234,
485,
5491,
14,
22686,
1547,
604,
9,
953,
485,
83,
275,
17893,
2412,
14,
7150,
342,
288,
17893,
2412,
14,
1600,
342,
953,
340,
3816,
14,
4521,
19,
26,
355,
485,
83,
275,
485,
83,
14,
2143,
360,
1624,
24,
358,
272,
871,
2186,
465,
325,
26,
267,
2512,
14,
705,
360,
1633,
4843,
63,
4737,
63,
1765,
1252,
358,
267,
2512,
14,
705,
360,
11764,
26,
4843,
63,
4737,
63,
1765,
1252,
325,
2458,
83,
12,
1499,
17,
2458,
83,
12,
1328,
18,
2458,
83,
297,
2151,
325,
12,
984,
14,
2804,
63,
815,
3430,
17,
467,
984,
14,
2804,
63,
815,
3430,
18,
566,
398,
372,
488,
339,
372,
485,
83,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
wilyuhm/xtratag
|
insta_api.py
|
1
|
1918
|
#A small web app for searching multiple tags on instagram
#Takes input in the form of a list of tags, returns oembed code for displaying
#images on a webpage
import requests
import json
from collections import defaultdict
import settings
#settings.py includes the following:
client_id = settings.client_id
client_secret = settings.client_secret
access_token = settings.access_token
base_url = "https://api.instagram.com"
#GET Tags/tag-name/media/recent
#Return list of image_ids
def get_image_ids(tag_name):
endpoint_url = "/v1/tags/" + tag_name + '/media/recent'
request_url = base_url + endpoint_url + "?access_token=" + access_token
api_return = requests.get(request_url)
if api_return.status_code == 200: #healthy response
response_dict = api_return.json()
num_images = len(response_dict['data'])
image_ids = []
# print response_dict['data']
for image in response_dict['data']:
image_ids.append(image['link'])
return image_ids
# with open('json_response.json', 'w') as fd:
# json.dump(api_return.json(), fd, indent=4, sort_keys=True)
# fd.close()
else:
print('failure, returned: ' + str(api_return.status_code))
#GET image oembed code
#Return oembed code (does not require access_token)
def get_oembed(image_link):
endpoint_url = '/oembed?url=' + image_link
request_url = base_url + endpoint_url
api_return = requests.get(request_url)
if api_return.status_code == 200:
return api_return.text
else:
print('failure fetching oembed code, returned: ' + str(api_return.status_code))
tags = ['stilts', 'sdzoo', 'jumpingstilts']
picture_id_dict = defaultdict(list) #create dictionary with key=image_id, value=list of tags
for tag in tags:
id_list = get_image_ids(tag)
for id in id_list:
picture_id_dict[id].append(tag)
for image_id, matched_tags in picture_id_dict.items():
if len(matched_tags) == len(tags):
oembed_code = get_oembed(image_id)
print(oembed_code)
|
mit
|
[
3,
33,
7425,
3330,
1145,
367,
18112,
3663,
3762,
641,
2727,
32208,
199,
3,
32488,
1324,
315,
314,
1824,
402,
282,
769,
402,
3762,
12,
2529,
312,
6427,
1233,
367,
20589,
199,
3,
4782,
641,
282,
9248,
199,
199,
646,
4145,
199,
646,
2022,
199,
504,
5055,
492,
10018,
199,
199,
646,
2202,
199,
3,
1751,
14,
647,
6952,
314,
2569,
26,
199,
1258,
63,
344,
275,
2202,
14,
1258,
63,
344,
199,
1258,
63,
4731,
275,
2202,
14,
1258,
63,
4731,
199,
2732,
63,
1418,
275,
2202,
14,
2732,
63,
1418,
199,
199,
1095,
63,
633,
275,
298,
2859,
921,
1246,
14,
3615,
32208,
14,
957,
2,
199,
199,
3,
2970,
25204,
15,
1450,
13,
354,
15,
4603,
15,
14951,
199,
3,
1767,
769,
402,
1834,
63,
1580,
199,
318,
664,
63,
1569,
63,
1580,
8,
1450,
63,
354,
304,
199,
198,
6520,
63,
633,
275,
3286,
86,
17,
15,
2969,
6687,
435,
1947,
63,
354,
435,
1994,
4603,
15,
14951,
7,
199,
198,
1069,
63,
633,
275,
1300,
63,
633,
435,
6037,
63,
633,
435,
23665,
2732,
63,
1418,
628,
435,
2879,
63,
1418,
421,
198,
1246,
63,
1107,
275,
4145,
14,
362,
8,
1069,
63,
633,
9,
421,
198,
692,
2986,
63,
1107,
14,
1205,
63,
600,
508,
1926,
26,
327,
29584,
1177,
507,
198,
1310,
63,
807,
275,
2986,
63,
1107,
14,
1001,
342,
507,
198,
1507,
63,
4782,
275,
822,
8,
1310,
63,
807,
459,
576,
1105,
507,
198,
1569,
63,
1580,
275,
942,
507,
198,
3,
870,
1177,
63,
807,
459,
576,
418,
507,
198,
509,
1834,
315,
1177,
63,
807,
459,
576,
2565,
686,
198,
1569,
63,
1580,
14,
740,
8,
1569,
459,
1073,
1105,
507,
198,
1107,
1834,
63,
1580,
507,
198,
3,
543,
1551,
360,
1001,
63,
1310,
14,
1001,
297,
283,
87,
358,
465,
6111,
26,
507,
198,
3,
221,
198,
1001,
14,
2724,
8,
1246,
63,
1107,
14,
1001,
1062,
6111,
12,
4363,
29,
20,
12,
4069,
63,
1612,
29,
549,
9,
507,
198,
3,
221,
198,
2592,
14,
1600,
342,
199,
198,
2836,
26,
507,
198,
1361,
360,
5328,
12,
2138,
26,
283,
435,
620,
8,
1246,
63,
1107,
14,
1205,
63,
600,
430,
199,
199,
3,
2970,
1834,
312,
6427,
1233,
199,
3,
1767,
312,
6427,
1233,
334,
9105,
440,
4409,
2879,
63,
1418,
9,
199,
318,
664,
63,
79,
6427,
8,
1569,
63,
1073,
304,
199,
198,
6520,
63,
633,
275,
1994,
79,
6427,
31,
633,
534,
435,
1834,
63,
1073,
199,
198,
1069,
63,
633,
275,
1300,
63,
633,
435,
6037,
63,
633,
421,
198,
1246,
63,
1107,
275,
4145,
14,
362,
8,
1069,
63,
633,
9,
421,
198,
692,
2986,
63,
1107,
14,
1205,
63,
600,
508,
1926,
26,
507,
198,
1107,
2986,
63,
1107,
14,
505,
199,
198,
2836,
26,
507,
198,
1361,
360,
5328,
21239,
312,
6427,
1233,
12,
2138,
26,
283,
435,
620,
8,
1246,
63,
1107,
14,
1205,
63,
600,
430,
199,
199,
2969,
275,
788,
270,
382,
1086,
297,
283,
3893,
90,
1534,
297,
283,
11126,
316,
270,
382,
1086,
418,
199,
12538,
63,
344,
63,
807,
275,
10018,
8,
513,
9,
327,
981,
2600,
543,
790,
29,
1569,
63,
344,
12,
574,
29,
513,
402,
3762,
199,
509,
1947,
315,
3762,
26,
199,
198,
344,
63,
513,
275,
664,
63,
1569,
63,
1580,
8,
1450,
9,
199,
198,
509,
1305,
315,
1305,
63,
513,
26,
507,
198,
12538,
63,
344,
63,
807,
59,
344,
1055,
740,
8,
1450,
9,
199,
199,
509,
1834,
63,
344,
12,
7838,
63,
2969,
315,
24945,
63,
344,
63,
807,
14,
1744,
837,
199,
198,
692,
822,
8,
10151,
63,
2969,
9,
508,
822,
8,
2969,
304,
507,
198,
79,
6427,
63,
600,
275,
664,
63,
79,
6427,
8,
1569,
63,
344,
9,
507,
198,
1361,
8,
79,
6427,
63,
600,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
33,
7425,
3330,
1145,
367,
18112,
3663,
3762,
641,
2727,
32208,
199,
3,
32488,
1324,
315,
314,
1824,
402,
282,
769,
402,
3762,
12,
2529,
312,
6427,
1233,
367,
20589,
199,
3,
4782,
641,
282,
9248,
199,
199,
646,
4145,
199,
646,
2022,
199,
504,
5055,
492,
10018,
199,
199,
646,
2202,
199,
3,
1751,
14,
647,
6952,
314,
2569,
26,
199,
1258,
63,
344,
275,
2202,
14,
1258,
63,
344,
199,
1258,
63,
4731,
275,
2202,
14,
1258,
63,
4731,
199,
2732,
63,
1418,
275,
2202,
14,
2732,
63,
1418,
199,
199,
1095,
63,
633,
275,
298,
2859,
921,
1246,
14,
3615,
32208,
14,
957,
2,
199,
199,
3,
2970,
25204,
15,
1450,
13,
354,
15,
4603,
15,
14951,
199,
3,
1767,
769,
402,
1834,
63,
1580,
199,
318,
664,
63,
1569,
63,
1580,
8,
1450,
63,
354,
304,
199,
198,
6520,
63,
633,
275,
3286,
86,
17,
15,
2969,
6687,
435,
1947,
63,
354,
435,
1994,
4603,
15,
14951,
7,
199,
198,
1069,
63,
633,
275,
1300,
63,
633,
435,
6037,
63,
633,
435,
23665,
2732,
63,
1418,
628,
435,
2879,
63,
1418,
421,
198,
1246,
63,
1107,
275,
4145,
14,
362,
8,
1069,
63,
633,
9,
421,
198,
692,
2986,
63,
1107,
14,
1205,
63,
600,
508,
1926,
26,
327,
29584,
1177,
507,
198,
1310,
63,
807,
275,
2986,
63,
1107,
14,
1001,
342,
507,
198,
1507,
63,
4782,
275,
822,
8,
1310,
63,
807,
459,
576,
1105,
507,
198,
1569,
63,
1580,
275,
942,
507,
198,
3,
870,
1177,
63,
807,
459,
576,
418,
507,
198,
509,
1834,
315,
1177,
63,
807,
459,
576,
2565,
686,
198,
1569,
63,
1580,
14,
740,
8,
1569,
459,
1073,
1105,
507,
198,
1107,
1834,
63,
1580,
507,
198,
3,
543,
1551,
360,
1001,
63,
1310,
14,
1001,
297,
283,
87,
358,
465,
6111,
26,
507,
198,
3,
221,
198,
1001,
14,
2724,
8,
1246,
63,
1107,
14,
1001,
1062,
6111,
12,
4363,
29,
20,
12,
4069,
63,
1612,
29,
549,
9,
507,
198,
3,
221,
198,
2592,
14,
1600,
342,
199,
198,
2836,
26,
507,
198,
1361,
360,
5328,
12,
2138,
26,
283,
435,
620,
8,
1246,
63,
1107,
14,
1205,
63,
600,
430,
199,
199,
3,
2970,
1834,
312,
6427,
1233,
199,
3,
1767,
312,
6427,
1233,
334,
9105,
440,
4409,
2879,
63,
1418,
9,
199,
318,
664,
63,
79,
6427,
8,
1569,
63,
1073,
304,
199,
198,
6520,
63,
633,
275,
1994,
79,
6427,
31,
633,
534,
435,
1834,
63,
1073,
199,
198,
1069,
63,
633,
275,
1300,
63,
633,
435,
6037,
63,
633,
421,
198,
1246,
63,
1107,
275,
4145,
14,
362,
8,
1069,
63,
633,
9,
421,
198,
692,
2986,
63,
1107,
14,
1205,
63,
600,
508,
1926,
26,
507,
198,
1107,
2986,
63,
1107,
14,
505,
199,
198,
2836,
26,
507,
198,
1361,
360,
5328,
21239,
312,
6427,
1233,
12,
2138,
26,
283,
435,
620,
8,
1246,
63,
1107,
14,
1205,
63,
600,
430,
199,
199,
2969,
275,
788,
270,
382,
1086,
297,
283,
3893,
90,
1534,
297,
283,
11126,
316,
270,
382,
1086,
418,
199,
12538,
63,
344,
63,
807,
275,
10018,
8,
513,
9,
327,
981,
2600,
543,
790,
29,
1569,
63,
344,
12,
574,
29,
513,
402,
3762,
199,
509,
1947,
315,
3762,
26,
199,
198,
344,
63,
513,
275,
664,
63,
1569,
63,
1580,
8,
1450,
9,
199,
198,
509,
1305,
315,
1305,
63,
513,
26,
507,
198,
12538,
63,
344,
63,
807,
59,
344,
1055,
740,
8,
1450,
9,
199,
199,
509,
1834,
63,
344,
12,
7838,
63,
2969,
315,
24945,
63,
344,
63,
807,
14,
1744,
837,
199,
198,
692,
822,
8,
10151,
63,
2969,
9,
508,
822,
8,
2969,
304,
507,
198,
79,
6427,
63,
600,
275,
664,
63,
79,
6427,
8,
1569,
63,
344,
9,
507,
198,
1361,
8,
79,
6427,
63,
600,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
meabsence/python-for-android
|
python3-alpha/python3-src/Lib/lib2to3/fixes/fix_imports.py
|
203
|
5684
|
"""Fix incompatible imports and module references."""
# Authors: Collin Winter, Nick Edds
# Local imports
from .. import fixer_base
from ..fixer_util import Name, attr_chain
MAPPING = {'StringIO': 'io',
'cStringIO': 'io',
'cPickle': 'pickle',
'__builtin__' : 'builtins',
'copy_reg': 'copyreg',
'Queue': 'queue',
'SocketServer': 'socketserver',
'ConfigParser': 'configparser',
'repr': 'reprlib',
'FileDialog': 'tkinter.filedialog',
'tkFileDialog': 'tkinter.filedialog',
'SimpleDialog': 'tkinter.simpledialog',
'tkSimpleDialog': 'tkinter.simpledialog',
'tkColorChooser': 'tkinter.colorchooser',
'tkCommonDialog': 'tkinter.commondialog',
'Dialog': 'tkinter.dialog',
'Tkdnd': 'tkinter.dnd',
'tkFont': 'tkinter.font',
'tkMessageBox': 'tkinter.messagebox',
'ScrolledText': 'tkinter.scrolledtext',
'Tkconstants': 'tkinter.constants',
'Tix': 'tkinter.tix',
'ttk': 'tkinter.ttk',
'Tkinter': 'tkinter',
'markupbase': '_markupbase',
'_winreg': 'winreg',
'thread': '_thread',
'dummy_thread': '_dummy_thread',
# anydbm and whichdb are handled by fix_imports2
'dbhash': 'dbm.bsd',
'dumbdbm': 'dbm.dumb',
'dbm': 'dbm.ndbm',
'gdbm': 'dbm.gnu',
'xmlrpclib': 'xmlrpc.client',
'DocXMLRPCServer': 'xmlrpc.server',
'SimpleXMLRPCServer': 'xmlrpc.server',
'httplib': 'http.client',
'htmlentitydefs' : 'html.entities',
'HTMLParser' : 'html.parser',
'Cookie': 'http.cookies',
'cookielib': 'http.cookiejar',
'BaseHTTPServer': 'http.server',
'SimpleHTTPServer': 'http.server',
'CGIHTTPServer': 'http.server',
#'test.test_support': 'test.support',
'commands': 'subprocess',
'UserString' : 'collections',
'UserList' : 'collections',
'urlparse' : 'urllib.parse',
'robotparser' : 'urllib.robotparser',
}
def alternates(members):
return "(" + "|".join(map(repr, members)) + ")"
def build_pattern(mapping=MAPPING):
mod_list = ' | '.join(["module_name='%s'" % key for key in mapping])
bare_names = alternates(mapping.keys())
yield """name_import=import_name< 'import' ((%s) |
multiple_imports=dotted_as_names< any* (%s) any* >) >
""" % (mod_list, mod_list)
yield """import_from< 'from' (%s) 'import' ['(']
( any | import_as_name< any 'as' any > |
import_as_names< any* >) [')'] >
""" % mod_list
yield """import_name< 'import' (dotted_as_name< (%s) 'as' any > |
multiple_imports=dotted_as_names<
any* dotted_as_name< (%s) 'as' any > any* >) >
""" % (mod_list, mod_list)
# Find usages of module members in code e.g. thread.foo(bar)
yield "power< bare_with_attr=(%s) trailer<'.' any > any* >" % bare_names
class FixImports(fixer_base.BaseFix):
BM_compatible = True
keep_line_order = True
# This is overridden in fix_imports2.
mapping = MAPPING
# We want to run this fixer late, so fix_import doesn't try to make stdlib
# renames into relative imports.
run_order = 6
def build_pattern(self):
return "|".join(build_pattern(self.mapping))
def compile_pattern(self):
# We override this, so MAPPING can be pragmatically altered and the
# changes will be reflected in PATTERN.
self.PATTERN = self.build_pattern()
super(FixImports, self).compile_pattern()
# Don't match the node if it's within another match.
def match(self, node):
match = super(FixImports, self).match
results = match(node)
if results:
# Module usage could be in the trailer of an attribute lookup, so we
# might have nested matches when "bare_with_attr" is present.
if "bare_with_attr" not in results and \
any(match(obj) for obj in attr_chain(node, "parent")):
return False
return results
return False
def start_tree(self, tree, filename):
super(FixImports, self).start_tree(tree, filename)
self.replace = {}
def transform(self, node, results):
import_mod = results.get("module_name")
if import_mod:
mod_name = import_mod.value
new_name = self.mapping[mod_name]
import_mod.replace(Name(new_name, prefix=import_mod.prefix))
if "name_import" in results:
# If it's not a "from x import x, y" or "import x as y" import,
# marked its usage to be replaced.
self.replace[mod_name] = new_name
if "multiple_imports" in results:
# This is a nasty hack to fix multiple imports on a line (e.g.,
# "import StringIO, urlparse"). The problem is that I can't
# figure out an easy way to make a pattern recognize the keys of
# MAPPING randomly sprinkled in an import statement.
results = self.match(node)
if results:
self.transform(node, results)
else:
# Replace usage of the module.
bare_name = results["bare_with_attr"][0]
new_name = self.replace.get(bare_name.value)
if new_name:
bare_name.replace(Name(new_name, prefix=bare_name.prefix))
|
apache-2.0
|
[
624,
11985,
18457,
8925,
436,
859,
6941,
1041,
199,
3,
6642,
26,
3626,
472,
644,
1058,
12,
653,
2000,
662,
617,
83,
199,
199,
3,
10111,
8925,
199,
504,
2508,
492,
24739,
63,
1095,
199,
504,
2508,
25973,
63,
1974,
492,
2812,
12,
1921,
63,
4429,
199,
199,
20351,
275,
791,
6424,
356,
221,
283,
2308,
297,
1779,
283,
67,
6424,
356,
283,
2308,
297,
1779,
283,
67,
12755,
356,
283,
8092,
297,
1779,
2560,
5351,
12217,
520,
283,
10372,
297,
1779,
283,
1574,
63,
1135,
356,
283,
1574,
1135,
297,
1779,
283,
3737,
356,
283,
1825,
297,
1779,
283,
3869,
3120,
356,
283,
3450,
1000,
297,
1779,
283,
15218,
356,
283,
888,
2087,
297,
1779,
283,
2722,
356,
283,
2722,
773,
297,
1779,
283,
25213,
356,
283,
12223,
14,
493,
7196,
297,
1779,
283,
2663,
25213,
356,
283,
12223,
14,
493,
7196,
297,
1779,
283,
3184,
5619,
356,
283,
12223,
14,
4129,
7196,
297,
1779,
283,
2663,
3184,
5619,
356,
283,
12223,
14,
4129,
7196,
297,
1779,
283,
2663,
4117,
17693,
356,
283,
12223,
14,
2326,
31123,
297,
1779,
283,
2663,
7844,
5619,
356,
283,
12223,
14,
2330,
7196,
297,
1779,
283,
5619,
356,
283,
12223,
14,
7196,
297,
1779,
283,
15189,
68,
977,
356,
283,
12223,
14,
68,
977,
297,
1779,
283,
2663,
6986,
356,
283,
12223,
14,
4246,
297,
1779,
283,
2663,
13695,
356,
283,
12223,
14,
1188,
1977,
297,
1779,
283,
29145,
1872,
356,
283,
12223,
14,
551,
10504,
505,
297,
1779,
283,
15189,
5559,
356,
283,
12223,
14,
5559,
297,
1779,
283,
30167,
356,
283,
12223,
14,
31625,
297,
1779,
283,
24865,
356,
283,
12223,
14,
24865,
297,
1779,
283,
15189,
1058,
356,
283,
12223,
297,
1779,
283,
10131,
1095,
356,
2513,
10131,
1095,
297,
1779,
2513,
15658,
356,
283,
15658,
297,
1779,
283,
2671,
356,
2513,
2671,
297,
1779,
283,
5869,
63,
2671,
356,
2513,
5869,
63,
2671,
297,
1779,
327,
1263,
20666,
436,
1314,
697,
787,
8860,
701,
5325,
63,
12775,
18,
1779,
283,
697,
2227,
356,
283,
20666,
14,
15746,
297,
1779,
283,
29271,
20666,
356,
283,
20666,
14,
29271,
297,
1779,
283,
20666,
356,
283,
20666,
14,
78,
20666,
297,
1779,
283,
17119,
77,
356,
283,
20666,
14,
3689,
297,
1779,
283,
17596,
773,
356,
283,
17596,
14,
1258,
297,
1779,
283,
3768,
27026,
3120,
356,
283,
17596,
14,
1000,
297,
1779,
283,
3184,
27026,
3120,
356,
283,
17596,
14,
1000,
297,
1779,
283,
12942,
356,
283,
1014,
14,
1258,
297,
1779,
283,
15575,
552,
1701,
8710,
7,
520,
283,
1360,
14,
8327,
297,
1779,
283,
27375,
7,
520,
283,
1360,
14,
2087,
297,
1779,
283,
7810,
356,
283,
1014,
14,
7792,
297,
1779,
283,
5306,
773,
356,
283,
1014,
14,
30552,
297,
1779,
283,
1563,
14938,
356,
283,
1014,
14,
1000,
297,
1779,
283,
3184,
14938,
356,
283,
1014,
14,
1000,
297,
1779,
283,
21337,
14938,
356,
283,
1014,
14,
1000,
297,
1779,
17384,
396,
14,
396,
63,
4058,
356,
283,
396,
14,
4058,
297,
1779,
283,
4405,
356,
283,
5781,
297,
1779,
283,
1899,
1558,
7,
520,
283,
7882,
297,
1779,
283,
1899,
1296,
7,
520,
283,
7882,
297,
1779,
283,
10290,
7,
520,
283,
4078,
14,
1122,
297,
1779,
283,
20969,
7,
520,
283,
4078,
14,
20969,
297,
199,
93,
421,
199,
318,
8679,
2335,
8,
6334,
304,
272,
372,
26054,
435,
15733,
1674,
904,
8,
1130,
8,
2722,
12,
7556,
430,
435,
19607,
421,
199,
318,
1900,
63,
3401,
8,
4745,
29,
20351,
304,
272,
3413,
63,
513,
275,
283,
1204,
1987,
904,
5234,
578,
63,
354,
9569,
83,
4065,
450,
790,
367,
790,
315,
4412,
566,
272,
18753,
63,
1247,
275,
8679,
2335,
8,
4745,
14,
1612,
1012,
339,
1995,
408,
354,
63,
646,
29,
646,
63,
354,
28,
283,
646,
7,
3666,
5,
83,
9,
1204,
2049,
3663,
63,
12775,
29,
19404,
63,
305,
63,
1247,
28,
1263,
10,
4366,
83,
9,
1263,
10,
690,
9,
690,
881,
408,
450,
334,
1494,
63,
513,
12,
3413,
63,
513,
9,
272,
1995,
408,
646,
63,
504,
28,
283,
504,
7,
4366,
83,
9,
283,
646,
7,
788,
360,
61,
1598,
334,
1263,
1204,
492,
63,
305,
63,
354,
28,
1263,
283,
305,
7,
1263,
690,
1204,
355,
492,
63,
305,
63,
1247,
28,
1263,
10,
690,
9,
221,
359,
358,
418,
690,
881,
408,
450,
3413,
63,
513,
272,
1995,
408,
646,
63,
354,
28,
283,
646,
7,
334,
19404,
63,
305,
63,
354,
28,
4366,
83,
9,
283,
305,
7,
1263,
690,
1204,
2049,
3663,
63,
12775,
29,
19404,
63,
305,
63,
1247,
28,
326,
1263,
10,
18947,
63,
305,
63,
354,
28,
4366,
83,
9,
283,
305,
7,
1263,
690,
1263,
10,
690,
9,
690,
881,
408,
450,
334,
1494,
63,
513,
12,
3413,
63,
513,
9,
339,
327,
6668,
4503,
83,
402,
859,
7556,
315,
1233,
325,
14,
71,
14,
2462,
14,
1421,
8,
1700,
9,
272,
1995,
298,
5652,
28,
18753,
63,
1045,
63,
962,
2687,
5,
83,
9,
17357,
28,
30484,
1263,
690,
1263,
10,
690,
2,
450,
18753,
63,
1247,
421,
199,
533,
14811,
32447,
8,
25973,
63,
1095,
14,
1563,
11985,
304,
339,
699,
45,
63,
6490,
275,
715,
272,
4215,
63,
604,
63,
1648,
275,
715,
272,
327,
961,
365,
10087,
315,
5325,
63,
12775,
18,
14,
272,
4412,
275,
603,
7121,
1206,
339,
327,
2136,
2934,
370,
1255,
642,
24739,
2465,
12,
880,
5325,
63,
646,
3181,
1133,
862,
370,
1852,
26678,
272,
327,
295,
1247,
1901,
3847,
8925,
14,
272,
1255,
63,
1648,
275,
1227,
339,
347,
1900,
63,
3401,
8,
277,
304,
267,
372,
15733,
1674,
904,
8,
1506,
63,
3401,
8,
277,
14,
4745,
430,
339,
347,
6555,
63,
3401,
8,
277,
304,
267,
327,
2136,
4278,
642,
12,
880,
603,
7121,
1206,
883,
506,
299,
2527,
17174,
29815,
436,
314,
267,
327,
4493,
911,
506,
31948,
315,
31467,
7689,
14,
267,
291,
14,
10764,
275,
291,
14,
1506,
63,
3401,
342,
267,
1613,
8,
11985,
32447,
12,
291,
680,
2014,
63,
3401,
342,
339,
327,
7529,
1133,
1336,
314,
1031,
340,
652,
1159,
4453,
4573,
1336,
14,
272,
347,
1336,
8,
277,
12,
1031,
304,
267,
1336
] |
[
11985,
18457,
8925,
436,
859,
6941,
1041,
199,
3,
6642,
26,
3626,
472,
644,
1058,
12,
653,
2000,
662,
617,
83,
199,
199,
3,
10111,
8925,
199,
504,
2508,
492,
24739,
63,
1095,
199,
504,
2508,
25973,
63,
1974,
492,
2812,
12,
1921,
63,
4429,
199,
199,
20351,
275,
791,
6424,
356,
221,
283,
2308,
297,
1779,
283,
67,
6424,
356,
283,
2308,
297,
1779,
283,
67,
12755,
356,
283,
8092,
297,
1779,
2560,
5351,
12217,
520,
283,
10372,
297,
1779,
283,
1574,
63,
1135,
356,
283,
1574,
1135,
297,
1779,
283,
3737,
356,
283,
1825,
297,
1779,
283,
3869,
3120,
356,
283,
3450,
1000,
297,
1779,
283,
15218,
356,
283,
888,
2087,
297,
1779,
283,
2722,
356,
283,
2722,
773,
297,
1779,
283,
25213,
356,
283,
12223,
14,
493,
7196,
297,
1779,
283,
2663,
25213,
356,
283,
12223,
14,
493,
7196,
297,
1779,
283,
3184,
5619,
356,
283,
12223,
14,
4129,
7196,
297,
1779,
283,
2663,
3184,
5619,
356,
283,
12223,
14,
4129,
7196,
297,
1779,
283,
2663,
4117,
17693,
356,
283,
12223,
14,
2326,
31123,
297,
1779,
283,
2663,
7844,
5619,
356,
283,
12223,
14,
2330,
7196,
297,
1779,
283,
5619,
356,
283,
12223,
14,
7196,
297,
1779,
283,
15189,
68,
977,
356,
283,
12223,
14,
68,
977,
297,
1779,
283,
2663,
6986,
356,
283,
12223,
14,
4246,
297,
1779,
283,
2663,
13695,
356,
283,
12223,
14,
1188,
1977,
297,
1779,
283,
29145,
1872,
356,
283,
12223,
14,
551,
10504,
505,
297,
1779,
283,
15189,
5559,
356,
283,
12223,
14,
5559,
297,
1779,
283,
30167,
356,
283,
12223,
14,
31625,
297,
1779,
283,
24865,
356,
283,
12223,
14,
24865,
297,
1779,
283,
15189,
1058,
356,
283,
12223,
297,
1779,
283,
10131,
1095,
356,
2513,
10131,
1095,
297,
1779,
2513,
15658,
356,
283,
15658,
297,
1779,
283,
2671,
356,
2513,
2671,
297,
1779,
283,
5869,
63,
2671,
356,
2513,
5869,
63,
2671,
297,
1779,
327,
1263,
20666,
436,
1314,
697,
787,
8860,
701,
5325,
63,
12775,
18,
1779,
283,
697,
2227,
356,
283,
20666,
14,
15746,
297,
1779,
283,
29271,
20666,
356,
283,
20666,
14,
29271,
297,
1779,
283,
20666,
356,
283,
20666,
14,
78,
20666,
297,
1779,
283,
17119,
77,
356,
283,
20666,
14,
3689,
297,
1779,
283,
17596,
773,
356,
283,
17596,
14,
1258,
297,
1779,
283,
3768,
27026,
3120,
356,
283,
17596,
14,
1000,
297,
1779,
283,
3184,
27026,
3120,
356,
283,
17596,
14,
1000,
297,
1779,
283,
12942,
356,
283,
1014,
14,
1258,
297,
1779,
283,
15575,
552,
1701,
8710,
7,
520,
283,
1360,
14,
8327,
297,
1779,
283,
27375,
7,
520,
283,
1360,
14,
2087,
297,
1779,
283,
7810,
356,
283,
1014,
14,
7792,
297,
1779,
283,
5306,
773,
356,
283,
1014,
14,
30552,
297,
1779,
283,
1563,
14938,
356,
283,
1014,
14,
1000,
297,
1779,
283,
3184,
14938,
356,
283,
1014,
14,
1000,
297,
1779,
283,
21337,
14938,
356,
283,
1014,
14,
1000,
297,
1779,
17384,
396,
14,
396,
63,
4058,
356,
283,
396,
14,
4058,
297,
1779,
283,
4405,
356,
283,
5781,
297,
1779,
283,
1899,
1558,
7,
520,
283,
7882,
297,
1779,
283,
1899,
1296,
7,
520,
283,
7882,
297,
1779,
283,
10290,
7,
520,
283,
4078,
14,
1122,
297,
1779,
283,
20969,
7,
520,
283,
4078,
14,
20969,
297,
199,
93,
421,
199,
318,
8679,
2335,
8,
6334,
304,
272,
372,
26054,
435,
15733,
1674,
904,
8,
1130,
8,
2722,
12,
7556,
430,
435,
19607,
421,
199,
318,
1900,
63,
3401,
8,
4745,
29,
20351,
304,
272,
3413,
63,
513,
275,
283,
1204,
1987,
904,
5234,
578,
63,
354,
9569,
83,
4065,
450,
790,
367,
790,
315,
4412,
566,
272,
18753,
63,
1247,
275,
8679,
2335,
8,
4745,
14,
1612,
1012,
339,
1995,
408,
354,
63,
646,
29,
646,
63,
354,
28,
283,
646,
7,
3666,
5,
83,
9,
1204,
2049,
3663,
63,
12775,
29,
19404,
63,
305,
63,
1247,
28,
1263,
10,
4366,
83,
9,
1263,
10,
690,
9,
690,
881,
408,
450,
334,
1494,
63,
513,
12,
3413,
63,
513,
9,
272,
1995,
408,
646,
63,
504,
28,
283,
504,
7,
4366,
83,
9,
283,
646,
7,
788,
360,
61,
1598,
334,
1263,
1204,
492,
63,
305,
63,
354,
28,
1263,
283,
305,
7,
1263,
690,
1204,
355,
492,
63,
305,
63,
1247,
28,
1263,
10,
690,
9,
221,
359,
358,
418,
690,
881,
408,
450,
3413,
63,
513,
272,
1995,
408,
646,
63,
354,
28,
283,
646,
7,
334,
19404,
63,
305,
63,
354,
28,
4366,
83,
9,
283,
305,
7,
1263,
690,
1204,
2049,
3663,
63,
12775,
29,
19404,
63,
305,
63,
1247,
28,
326,
1263,
10,
18947,
63,
305,
63,
354,
28,
4366,
83,
9,
283,
305,
7,
1263,
690,
1263,
10,
690,
9,
690,
881,
408,
450,
334,
1494,
63,
513,
12,
3413,
63,
513,
9,
339,
327,
6668,
4503,
83,
402,
859,
7556,
315,
1233,
325,
14,
71,
14,
2462,
14,
1421,
8,
1700,
9,
272,
1995,
298,
5652,
28,
18753,
63,
1045,
63,
962,
2687,
5,
83,
9,
17357,
28,
30484,
1263,
690,
1263,
10,
690,
2,
450,
18753,
63,
1247,
421,
199,
533,
14811,
32447,
8,
25973,
63,
1095,
14,
1563,
11985,
304,
339,
699,
45,
63,
6490,
275,
715,
272,
4215,
63,
604,
63,
1648,
275,
715,
272,
327,
961,
365,
10087,
315,
5325,
63,
12775,
18,
14,
272,
4412,
275,
603,
7121,
1206,
339,
327,
2136,
2934,
370,
1255,
642,
24739,
2465,
12,
880,
5325,
63,
646,
3181,
1133,
862,
370,
1852,
26678,
272,
327,
295,
1247,
1901,
3847,
8925,
14,
272,
1255,
63,
1648,
275,
1227,
339,
347,
1900,
63,
3401,
8,
277,
304,
267,
372,
15733,
1674,
904,
8,
1506,
63,
3401,
8,
277,
14,
4745,
430,
339,
347,
6555,
63,
3401,
8,
277,
304,
267,
327,
2136,
4278,
642,
12,
880,
603,
7121,
1206,
883,
506,
299,
2527,
17174,
29815,
436,
314,
267,
327,
4493,
911,
506,
31948,
315,
31467,
7689,
14,
267,
291,
14,
10764,
275,
291,
14,
1506,
63,
3401,
342,
267,
1613,
8,
11985,
32447,
12,
291,
680,
2014,
63,
3401,
342,
339,
327,
7529,
1133,
1336,
314,
1031,
340,
652,
1159,
4453,
4573,
1336,
14,
272,
347,
1336,
8,
277,
12,
1031,
304,
267,
1336,
0
] |
[
1,
1,
1,
1,
1,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pgid2013
|
build/sqlalchemy/test/orm/inheritance/_poly_fixtures.py
|
1
|
9894
|
from sqlalchemy import Integer, String, ForeignKey, func, desc, and_, or_
from sqlalchemy.orm import interfaces, relationship, mapper, \
clear_mappers, create_session, joinedload, joinedload_all, \
subqueryload, subqueryload_all, polymorphic_union, aliased,\
class_mapper
from sqlalchemy import exc as sa_exc
from sqlalchemy.engine import default
from test.lib import AssertsCompiledSQL, fixtures, testing
from test.lib.schema import Table, Column
from test.lib.testing import assert_raises, eq_
class Company(fixtures.ComparableEntity):
pass
class Person(fixtures.ComparableEntity):
pass
class Engineer(Person):
pass
class Manager(Person):
pass
class Boss(Manager):
pass
class Machine(fixtures.ComparableEntity):
pass
class Paperwork(fixtures.ComparableEntity):
pass
class _PolymorphicFixtureBase(fixtures.MappedTest, AssertsCompiledSQL):
run_inserts = 'once'
run_setup_mappers = 'once'
run_deletes = None
@classmethod
def define_tables(cls, metadata):
global people, engineers, managers, boss
global companies, paperwork, machines
companies = Table('companies', metadata,
Column('company_id', Integer,
primary_key=True,
test_needs_autoincrement=True),
Column('name', String(50)))
people = Table('people', metadata,
Column('person_id', Integer,
primary_key=True,
test_needs_autoincrement=True),
Column('company_id', Integer,
ForeignKey('companies.company_id')),
Column('name', String(50)),
Column('type', String(30)))
engineers = Table('engineers', metadata,
Column('person_id', Integer,
ForeignKey('people.person_id'),
primary_key=True),
Column('status', String(30)),
Column('engineer_name', String(50)),
Column('primary_language', String(50)))
machines = Table('machines', metadata,
Column('machine_id',
Integer, primary_key=True,
test_needs_autoincrement=True),
Column('name', String(50)),
Column('engineer_id', Integer,
ForeignKey('engineers.person_id')))
managers = Table('managers', metadata,
Column('person_id', Integer,
ForeignKey('people.person_id'),
primary_key=True),
Column('status', String(30)),
Column('manager_name', String(50)))
boss = Table('boss', metadata,
Column('boss_id', Integer,
ForeignKey('managers.person_id'),
primary_key=True),
Column('golf_swing', String(30)))
paperwork = Table('paperwork', metadata,
Column('paperwork_id', Integer,
primary_key=True,
test_needs_autoincrement=True),
Column('description', String(50)),
Column('person_id', Integer,
ForeignKey('people.person_id')))
@classmethod
def insert_data(cls):
cls.e1 = e1 = Engineer(
name="dilbert",
engineer_name="dilbert",
primary_language="java",
status="regular engineer",
paperwork=[
Paperwork(description="tps report #1"),
Paperwork(description="tps report #2")],
machines=[
Machine(name='IBM ThinkPad'),
Machine(name='IPhone')])
cls.e2 = e2 = Engineer(
name="wally",
engineer_name="wally",
primary_language="c++",
status="regular engineer",
paperwork=[
Paperwork(description="tps report #3"),
Paperwork(description="tps report #4")],
machines=[Machine(name="Commodore 64")])
cls.b1 = b1 = Boss(
name="pointy haired boss",
golf_swing="fore",
manager_name="pointy",
status="da boss",
paperwork=[Paperwork(description="review #1")])
cls.m1 = m1 = Manager(
name="dogbert",
manager_name="dogbert",
status="regular manager",
paperwork=[
Paperwork(description="review #2"),
Paperwork(description="review #3")])
cls.e3 = e3 = Engineer(
name="vlad",
engineer_name="vlad",
primary_language="cobol",
status="elbonian engineer",
paperwork=[
Paperwork(description='elbonian missive #3')],
machines=[
Machine(name="Commodore 64"),
Machine(name="IBM 3270")])
cls.c1 = c1 = Company(name="MegaCorp, Inc.")
c1.employees = [e1, e2, b1, m1]
cls.c2 = c2 = Company(name="Elbonia, Inc.")
c2.employees = [e3]
sess = create_session()
sess.add(c1)
sess.add(c2)
sess.flush()
sess.expunge_all()
cls.all_employees = [e1, e2, b1, m1, e3]
cls.c1_employees = [e1, e2, b1, m1]
cls.c2_employees = [e3]
def _emps_wo_relationships_fixture(self):
return [
Engineer(
name="dilbert",
engineer_name="dilbert",
primary_language="java",
status="regular engineer"),
Engineer(
name="wally",
engineer_name="wally",
primary_language="c++",
status="regular engineer"),
Boss(
name="pointy haired boss",
golf_swing="fore",
manager_name="pointy",
status="da boss"),
Manager(
name="dogbert",
manager_name="dogbert",
status="regular manager"),
Engineer(
name="vlad",
engineer_name="vlad",
primary_language="cobol",
status="elbonian engineer")
]
@classmethod
def setup_mappers(cls):
mapper(Company, companies,
properties={
'employees':relationship(
Person,
order_by=people.c.person_id)})
mapper(Machine, machines)
person_with_polymorphic,\
manager_with_polymorphic = cls._get_polymorphics()
mapper(Person, people,
with_polymorphic=person_with_polymorphic,
polymorphic_on=people.c.type,
polymorphic_identity='person',
order_by=people.c.person_id,
properties={
'paperwork':relationship(
Paperwork,
order_by=paperwork.c.paperwork_id)})
mapper(Engineer, engineers,
inherits=Person,
polymorphic_identity='engineer',
properties={
'machines':relationship(
Machine,
order_by=machines.c.machine_id)})
mapper(Manager, managers,
with_polymorphic=manager_with_polymorphic,
inherits=Person,
polymorphic_identity='manager')
mapper(Boss, boss,
inherits=Manager,
polymorphic_identity='boss')
mapper(Paperwork, paperwork)
class _Polymorphic(_PolymorphicFixtureBase):
select_type = ""
@classmethod
def _get_polymorphics(cls):
return None, None
class _PolymorphicPolymorphic(_PolymorphicFixtureBase):
select_type = "Polymorphic"
@classmethod
def _get_polymorphics(cls):
return '*', '*'
class _PolymorphicUnions(_PolymorphicFixtureBase):
select_type = "Unions"
@classmethod
def _get_polymorphics(cls):
people, engineers, managers, boss = \
cls.tables.people, cls.tables.engineers, \
cls.tables.managers, cls.tables.boss
person_join = polymorphic_union({
'engineer':people.join(engineers),
'manager':people.join(managers)},
None, 'pjoin')
manager_join = people.join(managers).outerjoin(boss)
person_with_polymorphic = (
[Person, Manager, Engineer], person_join)
manager_with_polymorphic = ('*', manager_join)
return person_with_polymorphic,\
manager_with_polymorphic
class _PolymorphicAliasedJoins(_PolymorphicFixtureBase):
select_type = "AliasedJoins"
@classmethod
def _get_polymorphics(cls):
people, engineers, managers, boss = \
cls.tables.people, cls.tables.engineers, \
cls.tables.managers, cls.tables.boss
person_join = people \
.outerjoin(engineers) \
.outerjoin(managers) \
.select(use_labels=True) \
.alias('pjoin')
manager_join = people \
.join(managers) \
.outerjoin(boss) \
.select(use_labels=True) \
.alias('mjoin')
person_with_polymorphic = (
[Person, Manager, Engineer], person_join)
manager_with_polymorphic = ('*', manager_join)
return person_with_polymorphic,\
manager_with_polymorphic
class _PolymorphicJoins(_PolymorphicFixtureBase):
select_type = "Joins"
@classmethod
def _get_polymorphics(cls):
people, engineers, managers, boss = \
cls.tables.people, cls.tables.engineers, \
cls.tables.managers, cls.tables.boss
person_join = people.outerjoin(engineers).outerjoin(managers)
manager_join = people.join(managers).outerjoin(boss)
person_with_polymorphic = (
[Person, Manager, Engineer], person_join)
manager_with_polymorphic = ('*', manager_join)
return person_with_polymorphic,\
manager_with_polymorphic
|
apache-2.0
|
[
504,
8335,
492,
7225,
12,
2624,
12,
12718,
12,
2562,
12,
4328,
12,
436,
3131,
503,
63,
199,
504,
8335,
14,
1025,
492,
8386,
12,
8931,
12,
7796,
12,
971,
272,
5436,
63,
24469,
12,
1218,
63,
1730,
12,
16538,
912,
12,
16538,
912,
63,
452,
12,
971,
272,
25935,
912,
12,
25935,
912,
63,
452,
12,
27905,
63,
8888,
12,
26642,
4202,
272,
1021,
63,
7153,
199,
504,
8335,
492,
3178,
465,
2937,
63,
2804,
199,
504,
8335,
14,
3908,
492,
849,
199,
199,
504,
511,
14,
773,
492,
10716,
83,
32521,
4657,
12,
15188,
12,
5343,
199,
504,
511,
14,
773,
14,
3629,
492,
6957,
12,
4996,
199,
504,
511,
14,
773,
14,
4776,
492,
702,
63,
3536,
12,
3850,
63,
199,
199,
533,
15878,
8,
8769,
14,
2404,
19816,
7302,
304,
272,
986,
199,
533,
8028,
8,
8769,
14,
2404,
19816,
7302,
304,
272,
986,
199,
533,
12580,
281,
8,
7344,
304,
272,
986,
199,
533,
13537,
8,
7344,
304,
272,
986,
199,
533,
5088,
385,
8,
2988,
304,
272,
986,
199,
533,
18722,
8,
8769,
14,
2404,
19816,
7302,
304,
272,
986,
199,
533,
510,
9804,
800,
8,
8769,
14,
2404,
19816,
7302,
304,
272,
986,
421,
199,
533,
485,
12747,
12543,
12812,
1563,
8,
8769,
14,
20698,
774,
12,
10716,
83,
32521,
4657,
304,
272,
1255,
63,
3176,
83,
275,
283,
5089,
7,
272,
1255,
63,
2758,
63,
24469,
275,
283,
5089,
7,
272,
1255,
63,
26289,
275,
488,
339,
768,
3744,
272,
347,
5627,
63,
5987,
8,
1886,
12,
3341,
304,
267,
2288,
13135,
12,
6869,
1192,
12,
19680,
12,
1234,
385,
267,
2288,
1013,
23461,
12,
15220,
800,
12,
20601,
398,
1013,
23461,
275,
6957,
360,
863,
23461,
297,
3341,
12,
288,
4996,
360,
4627,
63,
344,
297,
7225,
12,
355,
5062,
63,
498,
29,
549,
12,
355,
511,
63,
10065,
63,
27755,
29,
549,
395,
288,
4996,
360,
354,
297,
2624,
8,
1400,
1724,
398,
13135,
275,
6957,
360,
13562,
297,
3341,
12,
288,
4996,
360,
5484,
63,
344,
297,
7225,
12,
355,
5062,
63,
498,
29,
549,
12,
355,
511,
63,
10065,
63,
27755,
29,
549,
395,
288,
4996,
360,
4627,
63,
344,
297,
7225,
12,
355,
12718,
360,
863,
23461,
14,
4627,
63,
344,
3855,
288,
4996,
360,
354,
297,
2624,
8,
1400,
1826,
288,
4996,
360,
466,
297,
2624,
8,
1216,
1724,
398,
6869,
1192,
275,
6957,
360,
3908,
1192,
297,
3341,
12,
288,
4996,
360,
5484,
63,
344,
297,
7225,
12,
355,
12718,
360,
13562,
14,
5484,
63,
344,
659,
355,
5062,
63,
498,
29,
549,
395,
288,
4996,
360,
1205,
297,
2624,
8,
1216,
1826,
288,
4996,
360,
3908,
281,
63,
354,
297,
2624,
8,
1400,
1826,
288,
4996,
360,
3327,
63,
3671,
297,
2624,
8,
1400,
1724,
398,
20601,
275,
6957,
360,
26489,
297,
3341,
12,
1467,
4996,
360,
6744,
63,
344,
297,
326,
7225,
12,
5062,
63,
498,
29,
549,
12,
326,
511,
63,
10065,
63,
27755,
29,
549,
395,
1467,
4996,
360,
354,
297,
2624,
8,
1400,
1826,
1467,
4996,
360,
3908,
281,
63,
344,
297,
7225,
12,
288,
12718,
360,
3908,
1192,
14,
5484,
63,
344,
7058,
398,
19680,
275,
6957,
360,
16259,
297,
3341,
12,
288,
4996,
360,
5484,
63,
344,
297,
7225,
12,
355,
12718,
360,
13562,
14,
5484,
63,
344,
659,
355,
5062,
63,
498,
29,
549,
395,
288,
4996,
360,
1205,
297,
2624,
8,
1216,
1826,
288,
4996,
360,
2609,
63,
354,
297,
2624,
8,
1400,
1724,
398,
1234,
385,
275,
6957,
360,
25020,
297,
3341,
12,
288,
4996,
360,
25020,
63,
344,
297,
7225,
12,
355,
12718,
360,
16259,
14,
5484,
63,
344,
659,
355,
5062,
63,
498,
29,
549,
395,
288,
4996,
360,
1939,
276,
63,
3519,
316,
297,
2624,
8,
1216,
1724,
398,
15220,
800,
275,
6957,
360,
10443,
800,
297,
3341,
12,
288,
4996,
360,
10443,
800,
63,
344,
297,
7225,
12,
355,
5062,
63,
498,
29,
549,
12,
355,
511,
63,
10065,
63,
27755,
29,
549,
395,
288,
4996,
360,
1802,
297,
2624,
8,
1400,
1826,
288,
4996,
360,
5484,
63,
344,
297,
7225,
12,
355,
12718,
360,
13562,
14,
5484,
63,
344,
7058,
339,
768,
3744,
272,
347,
5518,
63,
576,
8,
1886,
304,
398,
843,
14,
69,
17,
275,
325,
17,
275,
12580,
281,
8,
288,
536,
628,
22429,
12504,
401,
288,
6869,
281,
63,
354,
628,
22429,
12504,
401,
288,
5062,
63,
3671,
628,
6138,
401,
288,
2004,
628,
7898,
6869,
281,
401,
288,
15220,
800,
1524,
355,
510,
9804,
800,
8,
1802,
628,
30543,
3622,
327,
17,
1288,
355,
510,
9804,
800,
8,
1802,
628,
30543,
3622,
327,
18,
17857,
288,
20601,
1524,
355,
18722,
8,
354,
534,
2100,
45,
3868,
2292,
18584,
659,
355,
18722,
8,
354,
534,
1772,
72,
368,
2023,
398,
843,
14,
69,
18,
275,
325,
18,
275,
12580,
281,
8,
288,
536,
628,
87,
1183,
401,
288,
6869,
281,
63,
354,
628,
87,
1183,
401,
288,
5062,
63,
3671,
628,
67,
4176,
401,
288,
2004,
628,
7898,
6869,
281,
401,
288,
15220,
800,
1524,
355,
510,
9804,
800,
8,
1802,
628,
30543,
3622,
327,
19,
1288,
355,
510,
9804,
800,
8,
1802,
628,
30543,
3622,
327,
20,
17857,
288,
20601,
1524,
8412,
8,
354,
628,
5150,
364,
720,
5049,
13403,
398,
843,
14,
66,
17,
275,
330,
17,
275,
5088,
385,
8,
288,
536,
628,
555,
262,
369,
394,
5789,
581,
1234,
385,
401,
288,
2621,
276,
63,
3519,
316,
628,
1707,
401,
288,
5256,
63,
354,
628,
555,
262,
369,
401,
288,
2004,
628,
983,
1234,
385,
401,
288,
15220,
800,
1524,
48,
9804,
800,
8,
1802,
628,
8578,
327,
17,
13403,
398,
843,
14,
77,
17,
275,
333,
17,
275,
13537,
8,
288,
536,
628,
13889,
12504,
401,
288,
5256,
63,
354,
628,
13889,
12504,
401,
288,
2004,
628,
7898,
5256,
401,
288,
15220,
800,
1524,
355,
510,
9804,
800,
8,
1802,
628,
8578,
327,
18,
1288,
355,
510,
9804,
800,
8,
1802,
628,
8578,
327,
19,
13403,
398,
843,
14,
69,
19,
275,
325,
19,
275,
12580,
281,
8,
288,
536,
628,
7300,
350,
401,
288,
6869,
281,
63,
354,
628,
7300,
350,
401,
288,
5062
] |
[
8335,
492,
7225,
12,
2624,
12,
12718,
12,
2562,
12,
4328,
12,
436,
3131,
503,
63,
199,
504,
8335,
14,
1025,
492,
8386,
12,
8931,
12,
7796,
12,
971,
272,
5436,
63,
24469,
12,
1218,
63,
1730,
12,
16538,
912,
12,
16538,
912,
63,
452,
12,
971,
272,
25935,
912,
12,
25935,
912,
63,
452,
12,
27905,
63,
8888,
12,
26642,
4202,
272,
1021,
63,
7153,
199,
504,
8335,
492,
3178,
465,
2937,
63,
2804,
199,
504,
8335,
14,
3908,
492,
849,
199,
199,
504,
511,
14,
773,
492,
10716,
83,
32521,
4657,
12,
15188,
12,
5343,
199,
504,
511,
14,
773,
14,
3629,
492,
6957,
12,
4996,
199,
504,
511,
14,
773,
14,
4776,
492,
702,
63,
3536,
12,
3850,
63,
199,
199,
533,
15878,
8,
8769,
14,
2404,
19816,
7302,
304,
272,
986,
199,
533,
8028,
8,
8769,
14,
2404,
19816,
7302,
304,
272,
986,
199,
533,
12580,
281,
8,
7344,
304,
272,
986,
199,
533,
13537,
8,
7344,
304,
272,
986,
199,
533,
5088,
385,
8,
2988,
304,
272,
986,
199,
533,
18722,
8,
8769,
14,
2404,
19816,
7302,
304,
272,
986,
199,
533,
510,
9804,
800,
8,
8769,
14,
2404,
19816,
7302,
304,
272,
986,
421,
199,
533,
485,
12747,
12543,
12812,
1563,
8,
8769,
14,
20698,
774,
12,
10716,
83,
32521,
4657,
304,
272,
1255,
63,
3176,
83,
275,
283,
5089,
7,
272,
1255,
63,
2758,
63,
24469,
275,
283,
5089,
7,
272,
1255,
63,
26289,
275,
488,
339,
768,
3744,
272,
347,
5627,
63,
5987,
8,
1886,
12,
3341,
304,
267,
2288,
13135,
12,
6869,
1192,
12,
19680,
12,
1234,
385,
267,
2288,
1013,
23461,
12,
15220,
800,
12,
20601,
398,
1013,
23461,
275,
6957,
360,
863,
23461,
297,
3341,
12,
288,
4996,
360,
4627,
63,
344,
297,
7225,
12,
355,
5062,
63,
498,
29,
549,
12,
355,
511,
63,
10065,
63,
27755,
29,
549,
395,
288,
4996,
360,
354,
297,
2624,
8,
1400,
1724,
398,
13135,
275,
6957,
360,
13562,
297,
3341,
12,
288,
4996,
360,
5484,
63,
344,
297,
7225,
12,
355,
5062,
63,
498,
29,
549,
12,
355,
511,
63,
10065,
63,
27755,
29,
549,
395,
288,
4996,
360,
4627,
63,
344,
297,
7225,
12,
355,
12718,
360,
863,
23461,
14,
4627,
63,
344,
3855,
288,
4996,
360,
354,
297,
2624,
8,
1400,
1826,
288,
4996,
360,
466,
297,
2624,
8,
1216,
1724,
398,
6869,
1192,
275,
6957,
360,
3908,
1192,
297,
3341,
12,
288,
4996,
360,
5484,
63,
344,
297,
7225,
12,
355,
12718,
360,
13562,
14,
5484,
63,
344,
659,
355,
5062,
63,
498,
29,
549,
395,
288,
4996,
360,
1205,
297,
2624,
8,
1216,
1826,
288,
4996,
360,
3908,
281,
63,
354,
297,
2624,
8,
1400,
1826,
288,
4996,
360,
3327,
63,
3671,
297,
2624,
8,
1400,
1724,
398,
20601,
275,
6957,
360,
26489,
297,
3341,
12,
1467,
4996,
360,
6744,
63,
344,
297,
326,
7225,
12,
5062,
63,
498,
29,
549,
12,
326,
511,
63,
10065,
63,
27755,
29,
549,
395,
1467,
4996,
360,
354,
297,
2624,
8,
1400,
1826,
1467,
4996,
360,
3908,
281,
63,
344,
297,
7225,
12,
288,
12718,
360,
3908,
1192,
14,
5484,
63,
344,
7058,
398,
19680,
275,
6957,
360,
16259,
297,
3341,
12,
288,
4996,
360,
5484,
63,
344,
297,
7225,
12,
355,
12718,
360,
13562,
14,
5484,
63,
344,
659,
355,
5062,
63,
498,
29,
549,
395,
288,
4996,
360,
1205,
297,
2624,
8,
1216,
1826,
288,
4996,
360,
2609,
63,
354,
297,
2624,
8,
1400,
1724,
398,
1234,
385,
275,
6957,
360,
25020,
297,
3341,
12,
288,
4996,
360,
25020,
63,
344,
297,
7225,
12,
355,
12718,
360,
16259,
14,
5484,
63,
344,
659,
355,
5062,
63,
498,
29,
549,
395,
288,
4996,
360,
1939,
276,
63,
3519,
316,
297,
2624,
8,
1216,
1724,
398,
15220,
800,
275,
6957,
360,
10443,
800,
297,
3341,
12,
288,
4996,
360,
10443,
800,
63,
344,
297,
7225,
12,
355,
5062,
63,
498,
29,
549,
12,
355,
511,
63,
10065,
63,
27755,
29,
549,
395,
288,
4996,
360,
1802,
297,
2624,
8,
1400,
1826,
288,
4996,
360,
5484,
63,
344,
297,
7225,
12,
355,
12718,
360,
13562,
14,
5484,
63,
344,
7058,
339,
768,
3744,
272,
347,
5518,
63,
576,
8,
1886,
304,
398,
843,
14,
69,
17,
275,
325,
17,
275,
12580,
281,
8,
288,
536,
628,
22429,
12504,
401,
288,
6869,
281,
63,
354,
628,
22429,
12504,
401,
288,
5062,
63,
3671,
628,
6138,
401,
288,
2004,
628,
7898,
6869,
281,
401,
288,
15220,
800,
1524,
355,
510,
9804,
800,
8,
1802,
628,
30543,
3622,
327,
17,
1288,
355,
510,
9804,
800,
8,
1802,
628,
30543,
3622,
327,
18,
17857,
288,
20601,
1524,
355,
18722,
8,
354,
534,
2100,
45,
3868,
2292,
18584,
659,
355,
18722,
8,
354,
534,
1772,
72,
368,
2023,
398,
843,
14,
69,
18,
275,
325,
18,
275,
12580,
281,
8,
288,
536,
628,
87,
1183,
401,
288,
6869,
281,
63,
354,
628,
87,
1183,
401,
288,
5062,
63,
3671,
628,
67,
4176,
401,
288,
2004,
628,
7898,
6869,
281,
401,
288,
15220,
800,
1524,
355,
510,
9804,
800,
8,
1802,
628,
30543,
3622,
327,
19,
1288,
355,
510,
9804,
800,
8,
1802,
628,
30543,
3622,
327,
20,
17857,
288,
20601,
1524,
8412,
8,
354,
628,
5150,
364,
720,
5049,
13403,
398,
843,
14,
66,
17,
275,
330,
17,
275,
5088,
385,
8,
288,
536,
628,
555,
262,
369,
394,
5789,
581,
1234,
385,
401,
288,
2621,
276,
63,
3519,
316,
628,
1707,
401,
288,
5256,
63,
354,
628,
555,
262,
369,
401,
288,
2004,
628,
983,
1234,
385,
401,
288,
15220,
800,
1524,
48,
9804,
800,
8,
1802,
628,
8578,
327,
17,
13403,
398,
843,
14,
77,
17,
275,
333,
17,
275,
13537,
8,
288,
536,
628,
13889,
12504,
401,
288,
5256,
63,
354,
628,
13889,
12504,
401,
288,
2004,
628,
7898,
5256,
401,
288,
15220,
800,
1524,
355,
510,
9804,
800,
8,
1802,
628,
8578,
327,
18,
1288,
355,
510,
9804,
800,
8,
1802,
628,
8578,
327,
19,
13403,
398,
843,
14,
69,
19,
275,
325,
19,
275,
12580,
281,
8,
288,
536,
628,
7300,
350,
401,
288,
6869,
281,
63,
354,
628,
7300,
350,
401,
288,
5062,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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015
|
2248
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2012-2015 clowwindy
#
# 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 __future__ import absolute_import, division, print_function, \
with_statement
import sys
import os
import logging
import signal
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../'))
from shadowsocks import shell, daemon, eventloop, tcprelay, udprelay, asyncdns
def main():
shell.check_python()
# fix py2exe
if hasattr(sys, "frozen") and sys.frozen in \
("windows_exe", "console_exe"):
p = os.path.dirname(os.path.abspath(sys.executable))
os.chdir(p)
config = shell.get_config(True)
daemon.daemon_exec(config)
try:
logging.info("starting local at %s:%d" %
(config['local_address'], config['local_port']))
dns_resolver = asyncdns.DNSResolver()
tcp_server = tcprelay.TCPRelay(config, dns_resolver, True)
udp_server = udprelay.UDPRelay(config, dns_resolver, True)
loop = eventloop.EventLoop()
dns_resolver.add_to_loop(loop)
tcp_server.add_to_loop(loop)
udp_server.add_to_loop(loop)
def handler(signum, _):
logging.warn('received SIGQUIT, doing graceful shutting down..')
tcp_server.close(next_tick=True)
udp_server.close(next_tick=True)
signal.signal(getattr(signal, 'SIGQUIT', signal.SIGTERM), handler)
def int_handler(signum, _):
sys.exit(1)
signal.signal(signal.SIGINT, int_handler)
daemon.set_user(config.get('user', None))
loop.run()
except Exception as e:
shell.print_exception(e)
sys.exit(1)
if __name__ == '__main__':
main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6029,
13,
7806,
286,
674,
11530,
89,
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,
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,
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,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
971,
272,
543,
63,
6242,
199,
199,
646,
984,
199,
646,
747,
199,
646,
2050,
199,
646,
4673,
199,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
20644,
1333,
199,
504,
15084,
21234,
492,
5218,
12,
11128,
12,
1566,
3813,
12,
14415,
657,
817,
12,
26759,
657,
817,
12,
5316,
5797,
421,
199,
318,
2446,
837,
272,
5218,
14,
1074,
63,
1548,
342,
339,
327,
5325,
1134,
18,
5803,
272,
340,
2688,
8,
1274,
12,
298,
11202,
531,
436,
984,
14,
11202,
315,
971,
288,
1689,
8258,
63,
5803,
401,
298,
6614,
63,
5803,
2349,
267,
299,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
8,
1274,
14,
5904,
430,
267,
747,
14,
8563,
8,
80,
9,
339,
1101,
275,
5218,
14,
362,
63,
888,
8,
549,
9,
339,
11128,
14,
10824,
63,
1628,
8,
888,
9,
339,
862,
26,
267,
2050,
14,
815,
480,
15769,
2257,
737,
450,
83,
2689,
68,
2,
450,
2151,
334,
888,
459,
1832,
63,
1562,
995,
1101,
459,
1832,
63,
719,
5156,
398,
6715,
63,
7717,
275,
5316,
5797,
14,
12323,
12407,
342,
267,
14719,
63,
1000,
275,
14415,
657,
817,
14,
9735,
5640,
1187,
8,
888,
12,
6715,
63,
7717,
12,
715,
9,
267,
18419,
63,
1000,
275,
26759,
657,
817,
14,
3383,
3311,
352,
1187,
8,
888,
12,
6715,
63,
7717,
12,
715,
9,
267,
4438,
275,
1566,
3813,
14,
2390,
7382,
342,
267,
6715,
63,
7717,
14,
525,
63,
475,
63,
3813,
8,
3813,
9,
267,
14719,
63,
1000,
14,
525,
63,
475,
63,
3813,
8,
3813,
9,
267,
18419,
63,
1000,
14,
525,
63,
475,
63,
3813,
8,
3813,
9,
398,
347,
3016,
8,
1037,
453,
12,
27574,
288,
2050,
14,
4050,
360,
9226,
15522,
2328,
649,
12,
9689,
19756,
1893,
24761,
1337,
3224,
703,
358,
288,
14719,
63,
1000,
14,
1600,
8,
2184,
63,
8284,
29,
549,
9,
288,
18419,
63,
1000,
14,
1600,
8,
2184,
63,
8284,
29,
549,
9,
267,
4673,
14,
4653,
8,
5675,
8,
4653,
12,
283,
7864,
2328,
649,
297,
4673,
14,
29190,
395,
3016,
9,
398,
347,
1109,
63,
2232,
8,
1037,
453,
12,
27574,
288,
984,
14,
2224,
8,
17,
9,
267,
4673,
14,
4653,
8,
4653,
14,
21223,
12,
1109,
63,
2232,
9,
398,
11128,
14,
409,
63,
751,
8,
888,
14,
362,
360,
751,
297,
488,
430,
267,
4438,
14,
1065,
342,
272,
871,
2186,
465,
325,
26,
267,
5218,
14,
1361,
63,
1971,
8,
69,
9,
267,
984,
14,
2224,
8,
17,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
3,
199,
3,
1898,
6029,
13,
7806,
286,
674,
11530,
89,
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,
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,
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,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
971,
272,
543,
63,
6242,
199,
199,
646,
984,
199,
646,
747,
199,
646,
2050,
199,
646,
4673,
199,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
20644,
1333,
199,
504,
15084,
21234,
492,
5218,
12,
11128,
12,
1566,
3813,
12,
14415,
657,
817,
12,
26759,
657,
817,
12,
5316,
5797,
421,
199,
318,
2446,
837,
272,
5218,
14,
1074,
63,
1548,
342,
339,
327,
5325,
1134,
18,
5803,
272,
340,
2688,
8,
1274,
12,
298,
11202,
531,
436,
984,
14,
11202,
315,
971,
288,
1689,
8258,
63,
5803,
401,
298,
6614,
63,
5803,
2349,
267,
299,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
8,
1274,
14,
5904,
430,
267,
747,
14,
8563,
8,
80,
9,
339,
1101,
275,
5218,
14,
362,
63,
888,
8,
549,
9,
339,
11128,
14,
10824,
63,
1628,
8,
888,
9,
339,
862,
26,
267,
2050,
14,
815,
480,
15769,
2257,
737,
450,
83,
2689,
68,
2,
450,
2151,
334,
888,
459,
1832,
63,
1562,
995,
1101,
459,
1832,
63,
719,
5156,
398,
6715,
63,
7717,
275,
5316,
5797,
14,
12323,
12407,
342,
267,
14719,
63,
1000,
275,
14415,
657,
817,
14,
9735,
5640,
1187,
8,
888,
12,
6715,
63,
7717,
12,
715,
9,
267,
18419,
63,
1000,
275,
26759,
657,
817,
14,
3383,
3311,
352,
1187,
8,
888,
12,
6715,
63,
7717,
12,
715,
9,
267,
4438,
275,
1566,
3813,
14,
2390,
7382,
342,
267,
6715,
63,
7717,
14,
525,
63,
475,
63,
3813,
8,
3813,
9,
267,
14719,
63,
1000,
14,
525,
63,
475,
63,
3813,
8,
3813,
9,
267,
18419,
63,
1000,
14,
525,
63,
475,
63,
3813,
8,
3813,
9,
398,
347,
3016,
8,
1037,
453,
12,
27574,
288,
2050,
14,
4050,
360,
9226,
15522,
2328,
649,
12,
9689,
19756,
1893,
24761,
1337,
3224,
703,
358,
288,
14719,
63,
1000,
14,
1600,
8,
2184,
63,
8284,
29,
549,
9,
288,
18419,
63,
1000,
14,
1600,
8,
2184,
63,
8284,
29,
549,
9,
267,
4673,
14,
4653,
8,
5675,
8,
4653,
12,
283,
7864,
2328,
649,
297,
4673,
14,
29190,
395,
3016,
9,
398,
347,
1109,
63,
2232,
8,
1037,
453,
12,
27574,
288,
984,
14,
2224,
8,
17,
9,
267,
4673,
14,
4653,
8,
4653,
14,
21223,
12,
1109,
63,
2232,
9,
398,
11128,
14,
409,
63,
751,
8,
888,
14,
362,
360,
751,
297,
488,
430,
267,
4438,
14,
1065,
342,
272,
871,
2186,
465,
325,
26,
267,
5218,
14,
1361,
63,
1971,
8,
69,
9,
267,
984,
14,
2224,
8,
17,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
trondhindenes/ansible
|
lib/ansible/modules/network/aci/aci_encap_pool_range.py
|
15
|
12359
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'certified'}
DOCUMENTATION = r'''
---
module: aci_encap_pool_range
short_description: Manage encap ranges assigned to pools (fvns:EncapBlk, fvns:VsanEncapBlk)
description:
- Manage vlan, vxlan, and vsan ranges that are assigned to pools on Cisco ACI fabrics.
notes:
- The C(pool) must exist in order to add or delete a range.
- More information about the internal APIC classes B(fvns:EncapBlk) and B(fvns:VsanEncapBlk) from
L(the APIC Management Information Model reference,https://developer.cisco.com/docs/apic-mim-ref/).
author:
- Jacob McGill (@jmcgill298)
version_added: '2.5'
options:
allocation_mode:
description:
- The method used for allocating encaps to resources.
- Only vlan and vsan support allocation modes.
choices: [ dynamic, inherit, static]
aliases: [ mode ]
description:
description:
- Description for the pool range.
aliases: [ descr ]
pool:
description:
- The name of the pool that the range should be assigned to.
aliases: [ pool_name ]
pool_allocation_mode:
description:
- The method used for allocating encaps to resources.
- Only vlan and vsan support allocation modes.
choices: [ dynamic, static]
aliases: [ pool_mode ]
pool_type:
description:
- The encap type of C(pool).
required: yes
aliases: [ type ]
choices: [ vlan, vxlan, vsan]
range_end:
description:
- The end of encap range.
type: int
aliases: [ end ]
range_name:
description:
- The name to give to the encap range.
aliases: [ name, range ]
range_start:
description:
- The start of the encap range.
type: int
aliases: [ start ]
state:
description:
- Use C(present) or C(absent) for adding or removing.
- Use C(query) for listing an object or multiple objects.
choices: [ absent, present, query ]
default: present
extends_documentation_fragment: aci
'''
EXAMPLES = r'''
- name: Add a new VLAN range
aci_vlan_pool_encap_block:
host: apic
username: admin
password: SomeSecretPassword
pool: production
pool_type: vlan
encap_start: 20
encap_end: 50
state: present
delegate_to: localhost
- name: Remove a VLAN range
aci_vlan_pool_encap_block:
host: apic
username: admin
password: SomeSecretPassword
pool: production
pool_type: vlan
encap_start: 20
encap_end: 50
state: absent
delegate_to: localhost
- name: Query a VLAN range
aci_vlan_pool_encap_block:
host: apic
username: admin
password: SomeSecretPassword
pool: production
pool_type: vlan
encap_start: 20
encap_end: 50
state: query
delegate_to: localhost
register: query_result
- name: Query a VLAN pool for ranges
aci_vlan_pool_encap_block:
host: apic
username: admin
password: SomeSecretPassword
pool: production
pool_type: vlan
state: query
delegate_to: localhost
register: query_result
- name: Query all VLAN ranges
aci_vlan_pool_encap_block:
host: apic
username: admin
password: SomeSecretPassword
pool_type: vlan
state: query
delegate_to: localhost
register: query_result
'''
RETURN = r'''
current:
description: The existing configuration from the APIC after the module has finished
returned: success
type: list
sample:
[
{
"fvTenant": {
"attributes": {
"descr": "Production environment",
"dn": "uni/tn-production",
"name": "production",
"nameAlias": "",
"ownerKey": "",
"ownerTag": ""
}
}
}
]
error:
description: The error information as returned from the APIC
returned: failure
type: dict
sample:
{
"code": "122",
"text": "unknown managed object class foo"
}
raw:
description: The raw output returned by the APIC REST API (xml or json)
returned: parse error
type: string
sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
sent:
description: The actual/minimal configuration pushed to the APIC
returned: info
type: list
sample:
{
"fvTenant": {
"attributes": {
"descr": "Production environment"
}
}
}
previous:
description: The original configuration from the APIC before the module has started
returned: info
type: list
sample:
[
{
"fvTenant": {
"attributes": {
"descr": "Production",
"dn": "uni/tn-production",
"name": "production",
"nameAlias": "",
"ownerKey": "",
"ownerTag": ""
}
}
}
]
proposed:
description: The assembled configuration from the user-provided parameters
returned: info
type: dict
sample:
{
"fvTenant": {
"attributes": {
"descr": "Production environment",
"name": "production"
}
}
}
filter_string:
description: The filter string used for the request
returned: failure or debug
type: string
sample: ?rsp-prop-include=config-only
method:
description: The HTTP method used for the request to the APIC
returned: failure or debug
type: string
sample: POST
response:
description: The HTTP response from the APIC
returned: failure or debug
type: string
sample: OK (30 bytes)
status:
description: The HTTP status from the APIC
returned: failure or debug
type: int
sample: 200
url:
description: The HTTP url used for the request to the APIC
returned: failure or debug
type: string
sample: https://10.11.12.13/api/mo/uni/tn-production.json
'''
from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
from ansible.module_utils.basic import AnsibleModule
ACI_POOL_MAPPING = dict(
vlan=dict(
aci_class='fvnsVlanInstP',
aci_mo='infra/vlanns-',
),
vxlan=dict(
aci_class='fvnsVxlanInstP',
aci_mo='infra/vxlanns-',
),
vsan=dict(
aci_class='fvnsVsanInstP',
aci_mo='infra/vsanns-',
),
)
def main():
argument_spec = aci_argument_spec()
argument_spec.update(
allocation_mode=dict(type='str', aliases=['mode'], choices=['dynamic', 'inherit', 'static']),
description=dict(type='str', aliases=['descr']),
pool=dict(type='str', aliases=['pool_name']), # Not required for querying all objects
pool_allocation_mode=dict(type='str', aliases=['pool_mode'], choices=['dynamic', 'static']),
pool_type=dict(type='str', aliases=['type'], choices=['vlan', 'vxlan', 'vsan'], required=True),
range_end=dict(type='int', aliases=['end']), # Not required for querying all objects
range_name=dict(type='str', aliases=["name", "range"]), # Not required for querying all objects
range_start=dict(type='int', aliases=["start"]), # Not required for querying all objects
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['pool', 'range_end', 'range_name', 'range_start']],
['state', 'present', ['pool', 'range_end', 'range_name', 'range_start']],
],
)
allocation_mode = module.params['allocation_mode']
description = module.params['description']
pool = module.params['pool']
pool_allocation_mode = module.params['pool_allocation_mode']
pool_type = module.params['pool_type']
range_end = module.params['range_end']
range_name = module.params['range_name']
range_start = module.params['range_start']
state = module.params['state']
if range_end is not None:
encap_end = '{0}-{1}'.format(pool_type, range_end)
else:
encap_end = None
if range_start is not None:
encap_start = '{0}-{1}'.format(pool_type, range_start)
else:
encap_start = None
ACI_RANGE_MAPPING = dict(
vlan=dict(
aci_class='fvnsEncapBlk',
aci_mo='from-[{0}]-to-[{1}]'.format(encap_start, encap_end),
),
vxlan=dict(
aci_class='fvnsEncapBlk',
aci_mo='from-[{0}]-to-[{1}]'.format(encap_start, encap_end),
),
vsan=dict(
aci_class='fvnsVsanEncapBlk',
aci_mo='vsanfrom-[{0}]-to-[{1}]'.format(encap_start, encap_end),
),
)
# Collect proper class and mo information based on pool_type
aci_range_class = ACI_RANGE_MAPPING[pool_type]["aci_class"]
aci_range_mo = ACI_RANGE_MAPPING[pool_type]["aci_mo"]
aci_pool_class = ACI_POOL_MAPPING[pool_type]["aci_class"]
aci_pool_mo = ACI_POOL_MAPPING[pool_type]["aci_mo"]
pool_name = pool
# Validate range_end and range_start are valid for its respective encap type
for encap_id in range_end, range_start:
if encap_id is not None:
if pool_type == 'vlan':
if not 1 <= encap_id <= 4094:
module.fail_json(msg='vlan pools must have "range_start" and "range_end" values between 1 and 4094')
elif pool_type == 'vxlan':
if not 5000 <= encap_id <= 16777215:
module.fail_json(msg='vxlan pools must have "range_start" and "range_end" values between 5000 and 16777215')
elif pool_type == 'vsan':
if not 1 <= encap_id <= 4093:
module.fail_json(msg='vsan pools must have "range_start" and "range_end" values between 1 and 4093')
if range_end is not None and range_start is not None:
# Validate range_start is less than range_end
if range_start > range_end:
module.fail_json(msg='The "range_start" must be less than or equal to the "range_end"')
elif range_end is None and range_start is None:
if range_name is None:
# Reset range managed object to None for aci util to properly handle query
aci_range_mo = None
# Vxlan does not support setting the allocation mode
if pool_type == 'vxlan' and allocation_mode is not None:
module.fail_json(msg='vxlan pools do not support setting the "allocation_mode"; please omit this parameter for vxlan pools')
# ACI Pool URL requires the allocation mode for vlan and vsan pools (ex: uni/infra/vlanns-[poolname]-static)
if pool_type != 'vxlan' and pool is not None:
if pool_allocation_mode is not None:
pool_name = '[{0}]-{1}'.format(pool, pool_allocation_mode)
else:
module.fail_json(msg='ACI requires the "pool_allocation_mode" for "pool_type" of "vlan" and "vsan" when the "pool" is provided')
aci = ACIModule(module)
aci.construct_url(
root_class=dict(
aci_class=aci_pool_class,
aci_rn='{0}{1}'.format(aci_pool_mo, pool_name),
module_object=pool,
target_filter={'name': pool},
),
subclass_1=dict(
aci_class=aci_range_class,
aci_rn='{0}'.format(aci_range_mo),
module_object=aci_range_mo,
target_filter={'from': encap_start, 'to': encap_end, 'name': range_name},
),
)
aci.get_existing()
if state == 'present':
aci.payload(
aci_class=aci_range_class,
class_config={
"allocMode": allocation_mode,
"descr": description,
"from": encap_start,
"name": range_name,
"to": encap_end,
},
)
aci.get_diff(aci_class=aci_range_class)
aci.post_config()
elif state == 'absent':
aci.delete_config()
aci.exit_json()
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,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
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,
2247,
8981,
936,
199,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
19631,
63,
287,
2874,
63,
2293,
63,
1842,
199,
3612,
63,
1802,
26,
14944,
655,
2874,
12271,
7943,
370,
20092,
334,
13692,
561,
26,
1327,
2874,
34,
23333,
12,
289,
86,
561,
26,
54,
18904,
1327,
2874,
34,
23333,
9,
199,
1802,
26,
199,
13,
14944,
10119,
12,
29922,
1502,
12,
436,
8118,
290,
12271,
626,
787,
7943,
370,
20092,
641,
28356,
437,
3553,
31507,
11818,
14,
199,
5983,
26,
199,
13,
710,
445,
8,
2293,
9,
1471,
2187,
315,
1865,
370,
1050,
503,
3145,
282,
1425,
14,
199,
13,
16917,
2556,
3595,
314,
5007,
25418,
3992,
699,
8,
13692,
561,
26,
1327,
2874,
34,
23333,
9,
436,
699,
8,
13692,
561,
26,
54,
18904,
1327,
2874,
34,
23333,
9,
687,
523,
491,
8,
1589,
25418,
8259,
17064,
5822,
3659,
12,
2859,
921,
11071,
14,
19597,
14,
957,
15,
4757,
15,
20789,
13,
77,
1017,
13,
1121,
15,
680,
199,
2502,
26,
199,
13,
1603,
13286,
66,
22895,
39,
778,
8593,
74,
5466,
71,
778,
12877,
9,
199,
1023,
63,
3270,
26,
283,
18,
14,
21,
7,
199,
1419,
26,
523,
18723,
63,
632,
26,
272,
1369,
26,
272,
446,
710,
1083,
1202,
367,
29447,
1958,
22667,
370,
5944,
14,
272,
446,
5972,
10119,
436,
8118,
290,
2291,
18723,
12404,
14,
272,
3415,
26,
359,
8336,
12,
8287,
12,
2955,
61,
272,
5481,
26,
359,
818,
1622,
523,
1369,
26,
272,
1369,
26,
272,
446,
11994,
367,
314,
4203,
1425,
14,
272,
5481,
26,
359,
16193,
1622,
523,
4203,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
4203,
626,
314,
1425,
1077,
506,
7943,
370,
14,
272,
5481,
26,
359,
4203,
63,
354,
1622,
523,
4203,
63,
14940,
63,
632,
26,
272,
1369,
26,
272,
446,
710,
1083,
1202,
367,
29447,
1958,
22667,
370,
5944,
14,
272,
446,
5972,
10119,
436,
8118,
290,
2291,
18723,
12404,
14,
272,
3415,
26,
359,
8336,
12,
2955,
61,
272,
5481,
26,
359,
4203,
63,
632,
1622,
523,
4203,
63,
466,
26,
272,
1369,
26,
272,
446,
710,
655,
2874,
730,
402,
445,
8,
2293,
680,
272,
1415,
26,
9456,
272,
5481,
26,
359,
730,
1622,
272,
3415,
26,
359,
10119,
12,
29922,
1502,
12,
8118,
290,
61,
523,
1425,
63,
500,
26,
272,
1369,
26,
272,
446,
710,
1284,
402,
655,
2874,
1425,
14,
272,
730,
26,
1109,
272,
5481,
26,
359,
1284,
1622,
523,
1425,
63,
354,
26,
272,
1369,
26,
272,
446,
710,
536,
370,
8120,
370,
314,
655,
2874,
1425,
14,
272,
5481,
26,
359,
536,
12,
1425,
1622,
523,
1425,
63,
928,
26,
272,
1369,
26,
272,
446,
710,
1343,
402,
314,
655,
2874,
1425,
14,
272,
730,
26,
1109,
272,
5481,
26,
359,
1343,
1622,
523,
1174,
26,
272,
1369,
26,
272,
446,
3645,
445,
8,
1881,
9,
503,
445,
8,
5575,
9,
367,
7791,
503,
12881,
14,
272,
446,
3645,
445,
8,
1131,
9,
367,
13778,
376,
909,
503,
3663,
2251,
14,
272,
3415,
26,
359,
9552,
12,
3451,
12,
1827,
1622,
272,
849,
26,
3451,
199,
11036,
63,
9970,
63,
7677,
26,
19631,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
2654,
282,
892,
17591,
1425,
523,
19631,
63,
7175,
63,
2293,
63,
287,
2874,
63,
1457,
26,
272,
1591,
26,
2771,
530,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4203,
26,
9920,
272,
4203,
63,
466,
26,
10119,
272,
655,
2874,
63,
928,
26,
3388,
272,
655,
2874,
63,
500,
26,
5238,
272,
1174,
26,
3451,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
5852,
282,
17591,
1425,
523,
19631,
63,
7175,
63,
2293,
63,
287,
2874,
63,
1457,
26,
272,
1591,
26,
2771,
530,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4203,
26,
9920,
272,
4203,
63,
466,
26,
10119,
272,
655,
2874,
63,
928,
26,
3388,
272,
655,
2874,
63,
500,
26,
5238,
272,
1174,
26,
9552,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
8133,
282,
17591,
1425,
523,
19631,
63,
7175,
63,
2293,
63,
287,
2874,
63,
1457,
26,
272,
1591,
26,
2771,
530,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4203,
26,
9920,
272,
4203,
63,
466,
26,
10119,
272,
655,
2874,
63,
928,
26,
3388,
272,
655,
2874,
63,
500,
26,
5238,
272,
1174,
26,
1827,
523,
13080,
63,
475,
26,
11667,
523,
2274,
26,
1827,
63,
1099,
199,
199,
13,
536,
26,
8133,
282,
17591,
4203,
367,
12271,
523,
19631,
63,
7175,
63,
2293,
63,
287,
2874,
63,
1457,
26,
272,
1591,
26,
2771,
530,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4203,
26,
9920,
272,
4203,
63,
466,
26,
10119,
272,
1174,
26,
1827,
523,
13080,
63,
475,
26,
11667,
523,
2274,
26,
1827,
63,
1099,
199,
199,
13,
536,
26,
8133,
1006,
17591,
12271,
523,
19631,
63,
7175,
63,
2293,
63,
287,
2874,
63,
1457,
26,
272,
1591,
26,
2771,
530,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4203,
63,
466,
26,
10119,
272,
1174,
26,
1827,
523,
13080,
63,
475,
26,
11667,
523,
2274,
26,
1827,
63,
1099,
199,
2344,
199,
199,
9677,
275,
519,
2344,
199,
1818,
26,
523,
1369,
26,
710,
3411,
2897,
687,
314,
25418,
2410,
314,
859,
965,
9158,
523,
2138,
26,
3182,
523,
730,
26,
769,
523,
2690,
26,
272,
359,
267,
469,
288,
298,
13692,
27807,
582,
469,
355,
298,
2987,
582,
469,
490,
298,
12113
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
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,
2247,
8981,
936,
199,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
19631,
63,
287,
2874,
63,
2293,
63,
1842,
199,
3612,
63,
1802,
26,
14944,
655,
2874,
12271,
7943,
370,
20092,
334,
13692,
561,
26,
1327,
2874,
34,
23333,
12,
289,
86,
561,
26,
54,
18904,
1327,
2874,
34,
23333,
9,
199,
1802,
26,
199,
13,
14944,
10119,
12,
29922,
1502,
12,
436,
8118,
290,
12271,
626,
787,
7943,
370,
20092,
641,
28356,
437,
3553,
31507,
11818,
14,
199,
5983,
26,
199,
13,
710,
445,
8,
2293,
9,
1471,
2187,
315,
1865,
370,
1050,
503,
3145,
282,
1425,
14,
199,
13,
16917,
2556,
3595,
314,
5007,
25418,
3992,
699,
8,
13692,
561,
26,
1327,
2874,
34,
23333,
9,
436,
699,
8,
13692,
561,
26,
54,
18904,
1327,
2874,
34,
23333,
9,
687,
523,
491,
8,
1589,
25418,
8259,
17064,
5822,
3659,
12,
2859,
921,
11071,
14,
19597,
14,
957,
15,
4757,
15,
20789,
13,
77,
1017,
13,
1121,
15,
680,
199,
2502,
26,
199,
13,
1603,
13286,
66,
22895,
39,
778,
8593,
74,
5466,
71,
778,
12877,
9,
199,
1023,
63,
3270,
26,
283,
18,
14,
21,
7,
199,
1419,
26,
523,
18723,
63,
632,
26,
272,
1369,
26,
272,
446,
710,
1083,
1202,
367,
29447,
1958,
22667,
370,
5944,
14,
272,
446,
5972,
10119,
436,
8118,
290,
2291,
18723,
12404,
14,
272,
3415,
26,
359,
8336,
12,
8287,
12,
2955,
61,
272,
5481,
26,
359,
818,
1622,
523,
1369,
26,
272,
1369,
26,
272,
446,
11994,
367,
314,
4203,
1425,
14,
272,
5481,
26,
359,
16193,
1622,
523,
4203,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
4203,
626,
314,
1425,
1077,
506,
7943,
370,
14,
272,
5481,
26,
359,
4203,
63,
354,
1622,
523,
4203,
63,
14940,
63,
632,
26,
272,
1369,
26,
272,
446,
710,
1083,
1202,
367,
29447,
1958,
22667,
370,
5944,
14,
272,
446,
5972,
10119,
436,
8118,
290,
2291,
18723,
12404,
14,
272,
3415,
26,
359,
8336,
12,
2955,
61,
272,
5481,
26,
359,
4203,
63,
632,
1622,
523,
4203,
63,
466,
26,
272,
1369,
26,
272,
446,
710,
655,
2874,
730,
402,
445,
8,
2293,
680,
272,
1415,
26,
9456,
272,
5481,
26,
359,
730,
1622,
272,
3415,
26,
359,
10119,
12,
29922,
1502,
12,
8118,
290,
61,
523,
1425,
63,
500,
26,
272,
1369,
26,
272,
446,
710,
1284,
402,
655,
2874,
1425,
14,
272,
730,
26,
1109,
272,
5481,
26,
359,
1284,
1622,
523,
1425,
63,
354,
26,
272,
1369,
26,
272,
446,
710,
536,
370,
8120,
370,
314,
655,
2874,
1425,
14,
272,
5481,
26,
359,
536,
12,
1425,
1622,
523,
1425,
63,
928,
26,
272,
1369,
26,
272,
446,
710,
1343,
402,
314,
655,
2874,
1425,
14,
272,
730,
26,
1109,
272,
5481,
26,
359,
1343,
1622,
523,
1174,
26,
272,
1369,
26,
272,
446,
3645,
445,
8,
1881,
9,
503,
445,
8,
5575,
9,
367,
7791,
503,
12881,
14,
272,
446,
3645,
445,
8,
1131,
9,
367,
13778,
376,
909,
503,
3663,
2251,
14,
272,
3415,
26,
359,
9552,
12,
3451,
12,
1827,
1622,
272,
849,
26,
3451,
199,
11036,
63,
9970,
63,
7677,
26,
19631,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
2654,
282,
892,
17591,
1425,
523,
19631,
63,
7175,
63,
2293,
63,
287,
2874,
63,
1457,
26,
272,
1591,
26,
2771,
530,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4203,
26,
9920,
272,
4203,
63,
466,
26,
10119,
272,
655,
2874,
63,
928,
26,
3388,
272,
655,
2874,
63,
500,
26,
5238,
272,
1174,
26,
3451,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
5852,
282,
17591,
1425,
523,
19631,
63,
7175,
63,
2293,
63,
287,
2874,
63,
1457,
26,
272,
1591,
26,
2771,
530,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4203,
26,
9920,
272,
4203,
63,
466,
26,
10119,
272,
655,
2874,
63,
928,
26,
3388,
272,
655,
2874,
63,
500,
26,
5238,
272,
1174,
26,
9552,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
8133,
282,
17591,
1425,
523,
19631,
63,
7175,
63,
2293,
63,
287,
2874,
63,
1457,
26,
272,
1591,
26,
2771,
530,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4203,
26,
9920,
272,
4203,
63,
466,
26,
10119,
272,
655,
2874,
63,
928,
26,
3388,
272,
655,
2874,
63,
500,
26,
5238,
272,
1174,
26,
1827,
523,
13080,
63,
475,
26,
11667,
523,
2274,
26,
1827,
63,
1099,
199,
199,
13,
536,
26,
8133,
282,
17591,
4203,
367,
12271,
523,
19631,
63,
7175,
63,
2293,
63,
287,
2874,
63,
1457,
26,
272,
1591,
26,
2771,
530,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4203,
26,
9920,
272,
4203,
63,
466,
26,
10119,
272,
1174,
26,
1827,
523,
13080,
63,
475,
26,
11667,
523,
2274,
26,
1827,
63,
1099,
199,
199,
13,
536,
26,
8133,
1006,
17591,
12271,
523,
19631,
63,
7175,
63,
2293,
63,
287,
2874,
63,
1457,
26,
272,
1591,
26,
2771,
530,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4203,
63,
466,
26,
10119,
272,
1174,
26,
1827,
523,
13080,
63,
475,
26,
11667,
523,
2274,
26,
1827,
63,
1099,
199,
2344,
199,
199,
9677,
275,
519,
2344,
199,
1818,
26,
523,
1369,
26,
710,
3411,
2897,
687,
314,
25418,
2410,
314,
859,
965,
9158,
523,
2138,
26,
3182,
523,
730,
26,
769,
523,
2690,
26,
272,
359,
267,
469,
288,
298,
13692,
27807,
582,
469,
355,
298,
2987,
582,
469,
490,
298,
12113,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tectronics/mythbox
|
resources/lib/twisted/twisted/test/test_task.py
|
56
|
20565
|
# Copyright (c) 2001-2007 Twisted Matrix Laboratories.
# See LICENSE for details.
from twisted.python.compat import set
from twisted.trial import unittest
from twisted.internet import interfaces, task, reactor, defer, error
# Be compatible with any jerks who used our private stuff
Clock = task.Clock
from twisted.python import failure
class TestableLoopingCall(task.LoopingCall):
def __init__(self, clock, *a, **kw):
super(TestableLoopingCall, self).__init__(*a, **kw)
self.clock = clock
class TestException(Exception):
pass
class ClockTestCase(unittest.TestCase):
"""
Test the non-wallclock based clock implementation.
"""
def testSeconds(self):
"""
Test that the L{seconds} method of the fake clock returns fake time.
"""
c = task.Clock()
self.assertEquals(c.seconds(), 0)
def testCallLater(self):
"""
Test that calls can be scheduled for later with the fake clock and
hands back an L{IDelayedCall}.
"""
c = task.Clock()
call = c.callLater(1, lambda a, b: None, 1, b=2)
self.failUnless(interfaces.IDelayedCall.providedBy(call))
self.assertEquals(call.getTime(), 1)
self.failUnless(call.active())
def testCallLaterCancelled(self):
"""
Test that calls can be cancelled.
"""
c = task.Clock()
call = c.callLater(1, lambda a, b: None, 1, b=2)
call.cancel()
self.failIf(call.active())
def test_callLaterOrdering(self):
"""
Test that the DelayedCall returned is not one previously
created.
"""
c = task.Clock()
call1 = c.callLater(10, lambda a, b: None, 1, b=2)
call2 = c.callLater(1, lambda a, b: None, 3, b=4)
self.failIf(call1 is call2)
def testAdvance(self):
"""
Test that advancing the clock will fire some calls.
"""
events = []
c = task.Clock()
call = c.callLater(2, lambda: events.append(None))
c.advance(1)
self.assertEquals(events, [])
c.advance(1)
self.assertEquals(events, [None])
self.failIf(call.active())
def testAdvanceCancel(self):
"""
Test attemping to cancel the call in a callback.
AlreadyCalled should be raised, not for example a ValueError from
removing the call from Clock.calls. This requires call.called to be
set before the callback is called.
"""
c = task.Clock()
def cb():
self.assertRaises(error.AlreadyCalled, call.cancel)
call = c.callLater(1, cb)
c.advance(1)
def testCallLaterDelayed(self):
"""
Test that calls can be delayed.
"""
events = []
c = task.Clock()
call = c.callLater(1, lambda a, b: events.append((a, b)), 1, b=2)
call.delay(1)
self.assertEquals(call.getTime(), 2)
c.advance(1.5)
self.assertEquals(events, [])
c.advance(1.0)
self.assertEquals(events, [(1, 2)])
def testCallLaterResetLater(self):
"""
Test that calls can have their time reset to a later time.
"""
events = []
c = task.Clock()
call = c.callLater(2, lambda a, b: events.append((a, b)), 1, b=2)
c.advance(1)
call.reset(3)
self.assertEquals(call.getTime(), 4)
c.advance(2)
self.assertEquals(events, [])
c.advance(1)
self.assertEquals(events, [(1, 2)])
def testCallLaterResetSooner(self):
"""
Test that calls can have their time reset to an earlier time.
"""
events = []
c = task.Clock()
call = c.callLater(4, lambda a, b: events.append((a, b)), 1, b=2)
call.reset(3)
self.assertEquals(call.getTime(), 3)
c.advance(3)
self.assertEquals(events, [(1, 2)])
def test_getDelayedCalls(self):
"""
Test that we can get a list of all delayed calls
"""
c = task.Clock()
call = c.callLater(1, lambda x: None)
call2 = c.callLater(2, lambda x: None)
calls = c.getDelayedCalls()
self.assertEquals(set([call, call2]), set(calls))
def test_getDelayedCallsEmpty(self):
"""
Test that we get an empty list from getDelayedCalls on a newly
constructed Clock.
"""
c = task.Clock()
self.assertEquals(c.getDelayedCalls(), [])
def test_providesIReactorTime(self):
c = task.Clock()
self.failUnless(interfaces.IReactorTime.providedBy(c),
"Clock does not provide IReactorTime")
class LoopTestCase(unittest.TestCase):
"""
Tests for L{task.LoopingCall} based on a fake L{IReactorTime}
implementation.
"""
def test_defaultClock(self):
"""
L{LoopingCall}'s default clock should be the reactor.
"""
call = task.LoopingCall(lambda: None)
self.assertEqual(call.clock, reactor)
def test_callbackTimeSkips(self):
"""
When more time than the defined interval passes during the execution
of a callback, L{LoopingCall} should schedule the next call for the
next interval which is still in the future.
"""
times = []
callDuration = None
clock = task.Clock()
def aCallback():
times.append(clock.seconds())
clock.advance(callDuration)
call = task.LoopingCall(aCallback)
call.clock = clock
# Start a LoopingCall with a 0.5 second increment, and immediately call
# the callable.
callDuration = 2
call.start(0.5)
# Verify that the callable was called, and since it was immediate, with
# no skips.
self.assertEqual(times, [0])
# The callback should have advanced the clock by the callDuration.
self.assertEqual(clock.seconds(), callDuration)
# An iteration should have occurred at 2, but since 2 is the present
# and not the future, it is skipped.
clock.advance(0)
self.assertEqual(times, [0])
# 2.5 is in the future, and is not skipped.
callDuration = 1
clock.advance(0.5)
self.assertEqual(times, [0, 2.5])
self.assertEqual(clock.seconds(), 3.5)
# Another iteration should have occurred, but it is again the
# present and not the future, so it is skipped as well.
clock.advance(0)
self.assertEqual(times, [0, 2.5])
# 4 is in the future, and is not skipped.
callDuration = 0
clock.advance(0.5)
self.assertEqual(times, [0, 2.5, 4])
self.assertEqual(clock.seconds(), 4)
def test_reactorTimeSkips(self):
"""
When more time than the defined interval passes between when
L{LoopingCall} schedules itself to run again and when it actually
runs again, it should schedule the next call for the next interval
which is still in the future.
"""
times = []
clock = task.Clock()
def aCallback():
times.append(clock.seconds())
# Start a LoopingCall that tracks the time passed, with a 0.5 second
# increment.
call = task.LoopingCall(aCallback)
call.clock = clock
call.start(0.5)
# Initially, no time should have passed!
self.assertEqual(times, [0])
# Advance the clock by 2 seconds (2 seconds should have passed)
clock.advance(2)
self.assertEqual(times, [0, 2])
# Advance the clock by 1 second (3 total should have passed)
clock.advance(1)
self.assertEqual(times, [0, 2, 3])
# Advance the clock by 0 seconds (this should have no effect!)
clock.advance(0)
self.assertEqual(times, [0, 2, 3])
def test_reactorTimeCountSkips(self):
"""
When L{LoopingCall} schedules itself to run again, if more than the
specified interval has passed, it should schedule the next call for the
next interval which is still in the future. If it was created
using L{LoopingCall.withCount}, a positional argument will be
inserted at the beginning of the argument list, indicating the number
of calls that should have been made.
"""
times = []
clock = task.Clock()
def aCallback(numCalls):
times.append((clock.seconds(), numCalls))
# Start a LoopingCall that tracks the time passed, and the number of
# skips, with a 0.5 second increment.
call = task.LoopingCall.withCount(aCallback)
call.clock = clock
INTERVAL = 0.5
REALISTIC_DELAY = 0.01
call.start(INTERVAL)
# Initially, no seconds should have passed, and one calls should have
# been made.
self.assertEqual(times, [(0, 1)])
# After the interval (plus a small delay, to account for the time that
# the reactor takes to wake up and process the LoopingCall), we should
# still have only made one call.
clock.advance(INTERVAL + REALISTIC_DELAY)
self.assertEqual(times, [(0, 1), (INTERVAL + REALISTIC_DELAY, 1)])
# After advancing the clock by three intervals (plus a small delay to
# account for the reactor), we should have skipped two calls; one less
# than the number of intervals which have completely elapsed. Along
# with the call we did actually make, the final number of calls is 3.
clock.advance((3 * INTERVAL) + REALISTIC_DELAY)
self.assertEqual(times,
[(0, 1), (INTERVAL + REALISTIC_DELAY, 1),
((4 * INTERVAL) + (2 * REALISTIC_DELAY), 3)])
# Advancing the clock by 0 seconds should not cause any changes!
clock.advance(0)
self.assertEqual(times,
[(0, 1), (INTERVAL + REALISTIC_DELAY, 1),
((4 * INTERVAL) + (2 * REALISTIC_DELAY), 3)])
def test_countLengthyIntervalCounts(self):
"""
L{LoopingCall.withCount} counts only calls that were expected to be
made. So, if more than one, but less than two intervals pass between
invocations, it won't increase the count above 1. For example, a
L{LoopingCall} with interval T expects to be invoked at T, 2T, 3T, etc.
However, the reactor takes some time to get around to calling it, so in
practice it will be called at T+something, 2T+something, 3T+something;
and due to other things going on in the reactor, "something" is
variable. It won't increase the count unless "something" is greater
than T. So if the L{LoopingCall} is invoked at T, 2.75T, and 3T,
the count has not increased, even though the distance between
invocation 1 and invocation 2 is 1.75T.
"""
times = []
clock = task.Clock()
def aCallback(count):
times.append((clock.seconds(), count))
# Start a LoopingCall that tracks the time passed, and the number of
# calls, with a 0.5 second increment.
call = task.LoopingCall.withCount(aCallback)
call.clock = clock
INTERVAL = 0.5
REALISTIC_DELAY = 0.01
call.start(INTERVAL)
self.assertEqual(times.pop(), (0, 1))
# About one interval... So far, so good
clock.advance(INTERVAL + REALISTIC_DELAY)
self.assertEqual(times.pop(), (INTERVAL + REALISTIC_DELAY, 1))
# Oh no, something delayed us for a while.
clock.advance(INTERVAL * 1.75)
self.assertEqual(times.pop(), ((2.75 * INTERVAL) + REALISTIC_DELAY, 1))
# Back on track! We got invoked when we expected this time.
clock.advance(INTERVAL * 0.25)
self.assertEqual(times.pop(), ((3.0 * INTERVAL) + REALISTIC_DELAY, 1))
def testBasicFunction(self):
# Arrange to have time advanced enough so that our function is
# called a few times.
# Only need to go to 2.5 to get 3 calls, since the first call
# happens before any time has elapsed.
timings = [0.05, 0.1, 0.1]
clock = task.Clock()
L = []
def foo(a, b, c=None, d=None):
L.append((a, b, c, d))
lc = TestableLoopingCall(clock, foo, "a", "b", d="d")
D = lc.start(0.1)
theResult = []
def saveResult(result):
theResult.append(result)
D.addCallback(saveResult)
clock.pump(timings)
self.assertEquals(len(L), 3,
"got %d iterations, not 3" % (len(L),))
for (a, b, c, d) in L:
self.assertEquals(a, "a")
self.assertEquals(b, "b")
self.assertEquals(c, None)
self.assertEquals(d, "d")
lc.stop()
self.assertIdentical(theResult[0], lc)
# Make sure it isn't planning to do anything further.
self.failIf(clock.calls)
def testDelayedStart(self):
timings = [0.05, 0.1, 0.1]
clock = task.Clock()
L = []
lc = TestableLoopingCall(clock, L.append, None)
d = lc.start(0.1, now=False)
theResult = []
def saveResult(result):
theResult.append(result)
d.addCallback(saveResult)
clock.pump(timings)
self.assertEquals(len(L), 2,
"got %d iterations, not 2" % (len(L),))
lc.stop()
self.assertIdentical(theResult[0], lc)
self.failIf(clock.calls)
def testBadDelay(self):
lc = task.LoopingCall(lambda: None)
self.assertRaises(ValueError, lc.start, -1)
# Make sure that LoopingCall.stop() prevents any subsequent calls.
def _stoppingTest(self, delay):
ran = []
def foo():
ran.append(None)
clock = task.Clock()
lc = TestableLoopingCall(clock, foo)
d = lc.start(delay, now=False)
lc.stop()
self.failIf(ran)
self.failIf(clock.calls)
def testStopAtOnce(self):
return self._stoppingTest(0)
def testStoppingBeforeDelayedStart(self):
return self._stoppingTest(10)
class ReactorLoopTestCase(unittest.TestCase):
# Slightly inferior tests which exercise interactions with an actual
# reactor.
def testFailure(self):
def foo(x):
raise TestException(x)
lc = task.LoopingCall(foo, "bar")
return self.assertFailure(lc.start(0.1), TestException)
def testFailAndStop(self):
def foo(x):
lc.stop()
raise TestException(x)
lc = task.LoopingCall(foo, "bar")
return self.assertFailure(lc.start(0.1), TestException)
def testEveryIteration(self):
ran = []
def foo():
ran.append(None)
if len(ran) > 5:
lc.stop()
lc = task.LoopingCall(foo)
d = lc.start(0)
def stopped(ign):
self.assertEquals(len(ran), 6)
return d.addCallback(stopped)
def testStopAtOnceLater(self):
# Ensure that even when LoopingCall.stop() is called from a
# reactor callback, it still prevents any subsequent calls.
d = defer.Deferred()
def foo():
d.errback(failure.DefaultException(
"This task also should never get called."))
self._lc = task.LoopingCall(foo)
self._lc.start(1, now=False)
reactor.callLater(0, self._callback_for_testStopAtOnceLater, d)
return d
def _callback_for_testStopAtOnceLater(self, d):
self._lc.stop()
reactor.callLater(0, d.callback, "success")
def testWaitDeferred(self):
# Tests if the callable isn't scheduled again before the returned
# deferred has fired.
timings = [0.2, 0.8]
clock = task.Clock()
def foo():
d = defer.Deferred()
d.addCallback(lambda _: lc.stop())
clock.callLater(1, d.callback, None)
return d
lc = TestableLoopingCall(clock, foo)
d = lc.start(0.2)
clock.pump(timings)
self.failIf(clock.calls)
def testFailurePropagation(self):
# Tests if the failure of the errback of the deferred returned by the
# callable is propagated to the lc errback.
#
# To make sure this test does not hang trial when LoopingCall does not
# wait for the callable's deferred, it also checks there are no
# calls in the clock's callLater queue.
timings = [0.3]
clock = task.Clock()
def foo():
d = defer.Deferred()
clock.callLater(0.3, d.errback, TestException())
return d
lc = TestableLoopingCall(clock, foo)
d = lc.start(1)
self.assertFailure(d, TestException)
clock.pump(timings)
self.failIf(clock.calls)
return d
def test_deferredWithCount(self):
"""
In the case that the function passed to L{LoopingCall.withCount}
returns a deferred, which does not fire before the next interval
elapses, the function should not be run again. And if a function call
is skipped in this fashion, the appropriate count should be
provided.
"""
testClock = task.Clock()
d = defer.Deferred()
deferredCounts = []
def countTracker(possibleCount):
# Keep a list of call counts
deferredCounts.append(possibleCount)
# Return a deferred, but only on the first request
if len(deferredCounts) == 1:
return d
else:
return None
# Start a looping call for our countTracker function
# Set the increment to 0.2, and do not call the function on startup.
lc = task.LoopingCall.withCount(countTracker)
lc.clock = testClock
d = lc.start(0.2, now=False)
# Confirm that nothing has happened yet.
self.assertEquals(deferredCounts, [])
# Advance the clock by 0.2 and then 0.4;
testClock.pump([0.2, 0.4])
# We should now have exactly one count (of 1 call)
self.assertEquals(len(deferredCounts), 1)
# Fire the deferred, and advance the clock by another 0.2
d.callback(None)
testClock.pump([0.2])
# We should now have exactly 2 counts...
self.assertEquals(len(deferredCounts), 2)
# The first count should be 1 (one call)
# The second count should be 3 (calls were missed at about 0.6 and 0.8)
self.assertEquals(deferredCounts, [1, 3])
class DeferLaterTests(unittest.TestCase):
"""
Tests for L{task.deferLater}.
"""
def test_callback(self):
"""
The L{Deferred} returned by L{task.deferLater} is called back after
the specified delay with the result of the function passed in.
"""
results = []
flag = object()
def callable(foo, bar):
results.append((foo, bar))
return flag
clock = task.Clock()
d = task.deferLater(clock, 3, callable, 'foo', bar='bar')
d.addCallback(self.assertIdentical, flag)
clock.advance(2)
self.assertEqual(results, [])
clock.advance(1)
self.assertEqual(results, [('foo', 'bar')])
return d
def test_errback(self):
"""
The L{Deferred} returned by L{task.deferLater} is errbacked if the
supplied function raises an exception.
"""
def callable():
raise TestException()
clock = task.Clock()
d = task.deferLater(clock, 1, callable)
clock.advance(1)
return self.assertFailure(d, TestException)
def test_cancel(self):
"""
The L{Deferred} returned by L{task.deferLater} can be
cancelled to prevent the call from actually being performed.
"""
called = []
clock = task.Clock()
d = task.deferLater(clock, 1, called.append, None)
d.cancel()
def cbCancelled(ignored):
# Make sure there are no calls outstanding.
self.assertEquals([], clock.getDelayedCalls())
# And make sure the call didn't somehow happen already.
self.assertFalse(called)
self.assertFailure(d, defer.CancelledError)
d.addCallback(cbCancelled)
return d
|
gpl-2.0
|
[
3,
1898,
334,
67,
9,
12521,
13,
9488,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
504,
7390,
14,
1548,
14,
5819,
492,
663,
199,
199,
504,
7390,
14,
14443,
492,
2882,
199,
199,
504,
7390,
14,
4901,
492,
8386,
12,
2120,
12,
9655,
12,
10133,
12,
1125,
199,
199,
3,
6423,
9025,
543,
1263,
1335,
281,
6080,
3963,
1202,
4154,
5726,
8292,
199,
17387,
275,
2120,
14,
17387,
199,
199,
504,
7390,
14,
1548,
492,
5988,
421,
199,
533,
1379,
461,
7382,
316,
2176,
8,
1765,
14,
7382,
316,
2176,
304,
272,
347,
636,
826,
721,
277,
12,
12516,
12,
627,
65,
12,
1011,
829,
304,
267,
1613,
8,
774,
461,
7382,
316,
2176,
12,
291,
2843,
826,
9308,
65,
12,
1011,
829,
9,
267,
291,
14,
9597,
275,
12516,
4388,
199,
533,
1379,
1726,
8,
1726,
304,
272,
986,
4388,
199,
533,
32425,
1746,
8,
2796,
14,
1746,
304,
272,
408,
272,
1379,
314,
2222,
13,
7567,
9597,
4079,
12516,
4514,
14,
272,
408,
272,
347,
511,
13165,
8,
277,
304,
267,
408,
267,
1379,
626,
314,
491,
91,
4515,
93,
1083,
402,
314,
4026,
12516,
2529,
4026,
900,
14,
267,
408,
267,
286,
275,
2120,
14,
17387,
342,
267,
291,
14,
2947,
8,
67,
14,
4515,
1062,
378,
9,
2378,
347,
511,
2176,
22028,
8,
277,
304,
267,
408,
267,
1379,
626,
4882,
883,
506,
18416,
367,
2945,
543,
314,
4026,
12516,
436,
267,
4926,
83,
1771,
376,
491,
91,
998,
352,
1187,
379,
2176,
5565,
267,
408,
267,
286,
275,
2120,
14,
17387,
342,
267,
1240,
275,
286,
14,
1250,
22028,
8,
17,
12,
2400,
282,
12,
330,
26,
488,
12,
413,
12,
330,
29,
18,
9,
267,
291,
14,
7589,
8,
7436,
14,
998,
352,
1187,
379,
2176,
14,
16929,
2175,
8,
1250,
430,
267,
291,
14,
2947,
8,
1250,
14,
362,
1366,
1062,
413,
9,
267,
291,
14,
7589,
8,
1250,
14,
2682,
1012,
2378,
347,
511,
2176,
22028,
22127,
8,
277,
304,
267,
408,
267,
1379,
626,
4882,
883,
506,
20115,
14,
267,
408,
267,
286,
275,
2120,
14,
17387,
342,
267,
1240,
275,
286,
14,
1250,
22028,
8,
17,
12,
2400,
282,
12,
330,
26,
488,
12,
413,
12,
330,
29,
18,
9,
267,
1240,
14,
6406,
342,
267,
291,
14,
19670,
8,
1250,
14,
2682,
1012,
2378,
347,
511,
63,
1250,
22028,
4738,
316,
8,
277,
304,
267,
408,
267,
1379,
626,
314,
18464,
1187,
379,
2176,
2138,
365,
440,
1373,
10889,
267,
2737,
14,
267,
408,
267,
286,
275,
2120,
14,
17387,
342,
267,
1240,
17,
275,
286,
14,
1250,
22028,
8,
709,
12,
2400,
282,
12,
330,
26,
488,
12,
413,
12,
330,
29,
18,
9,
267,
1240,
18,
275,
286,
14,
1250,
22028,
8,
17,
12,
2400,
282,
12,
330,
26,
488,
12,
650,
12,
330,
29,
20,
9,
267,
291,
14,
19670,
8,
1250,
17,
365,
1240,
18,
9,
2378,
347,
511,
2767,
6278,
8,
277,
304,
267,
408,
267,
1379,
626,
19396,
15763,
314,
12516,
911,
8344,
2005,
4882,
14,
267,
408,
267,
4474,
275,
942,
267,
286,
275,
2120,
14,
17387,
342,
267,
1240,
275,
286,
14,
1250,
22028,
8,
18,
12,
2400,
26,
4474,
14,
740,
8,
403,
430,
267,
286,
14,
21195,
8,
17,
9,
267,
291,
14,
2947,
8,
4368,
12,
3073,
267,
286,
14,
21195,
8,
17,
9,
267,
291,
14,
2947,
8,
4368,
12,
359,
403,
566,
267,
291,
14,
19670,
8,
1250,
14,
2682,
1012,
2378,
347,
511,
2767,
6278,
9083,
8,
277,
304,
267,
408,
267,
1379,
5219,
316,
370,
9311,
314,
1240,
315,
282,
3233,
14,
398,
21086,
10474,
1077,
506,
4915,
12,
440,
367,
2893,
282,
1722,
687,
267,
12881,
314,
1240,
687,
32425,
14,
5352,
14,
961,
5074,
1240,
14,
3527,
370,
506,
267,
663,
2544,
314,
3233,
365,
2797,
14,
267,
408,
267,
286,
275,
2120,
14,
17387,
342,
267,
347,
7434,
837,
288,
291,
14,
1855,
8,
705,
14,
16760,
10474,
12,
1240,
14,
6406,
9,
267,
1240,
275,
286,
14,
1250,
22028,
8,
17,
12,
7434,
9,
267,
286,
14,
21195,
8,
17,
9,
2378,
347,
511,
2176,
22028,
10796,
379,
8,
277,
304,
267,
408,
267,
1379,
626,
4882,
883,
506,
24725,
14,
267,
408,
267,
4474,
275,
942,
267,
286,
275,
2120,
14,
17387,
342,
267,
1240,
275,
286,
14,
1250,
22028,
8,
17,
12,
2400,
282,
12,
330,
26,
4474,
14,
740,
1332,
65,
12,
330,
1826,
413,
12,
330,
29,
18,
9,
267,
1240,
14,
5814,
8,
17,
9,
267,
291,
14,
2947,
8,
1250,
14,
362,
1366,
1062,
499,
9,
267,
286,
14,
21195,
8,
17,
14,
21,
9,
267,
291,
14,
2947,
8,
4368,
12,
3073,
267,
286,
14,
21195,
8,
17,
14,
16,
9,
267,
291,
14,
2947,
8,
4368,
12,
3842,
17,
12,
499,
3948,
2378,
347,
511,
2176,
22028,
9637,
22028,
8,
277,
304,
267,
408,
267,
1379,
626,
4882,
883,
1172,
3932,
900,
5305,
370,
282,
2945,
900,
14,
267,
408,
267,
4474,
275,
942,
267,
286,
275,
2120,
14,
17387,
342,
267,
1240,
275,
286,
14,
1250,
22028,
8,
18,
12,
2400,
282,
12,
330,
26,
4474,
14,
740,
1332,
65,
12,
330,
1826,
413,
12,
330,
29,
18,
9,
267,
286,
14,
21195,
8,
17,
9,
267,
1240,
14,
3958,
8,
19,
9,
267,
291,
14,
2947,
8,
1250,
14,
362,
1366,
1062,
841,
9,
267,
286,
14,
21195,
8,
18,
9,
267,
291,
14,
2947,
8,
4368,
12,
3073,
267,
286,
14,
21195,
8,
17,
9,
267,
291,
14,
2947,
8,
4368,
12,
3842,
17,
12,
499,
3948,
2378,
347,
511,
2176,
22028,
9637,
5158,
265,
281,
8,
277,
304,
267,
408,
267,
1379,
626,
4882,
883,
1172,
3932,
900,
5305,
370,
376,
14119,
900,
14,
267,
408,
267,
4474,
275,
942,
267,
286,
275,
2120,
14,
17387,
342,
267,
1240,
275,
286,
14,
1250,
22028,
8,
20,
12,
2400,
282,
12,
330,
26,
4474,
14,
740,
1332,
65,
12,
330,
1826,
413,
12,
330,
29,
18,
9,
267,
1240,
14,
3958,
8,
19,
9,
267,
291,
14,
2947,
8,
1250,
14,
362,
1366,
1062,
650,
9,
267
] |
[
1898,
334,
67,
9,
12521,
13,
9488,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
504,
7390,
14,
1548,
14,
5819,
492,
663,
199,
199,
504,
7390,
14,
14443,
492,
2882,
199,
199,
504,
7390,
14,
4901,
492,
8386,
12,
2120,
12,
9655,
12,
10133,
12,
1125,
199,
199,
3,
6423,
9025,
543,
1263,
1335,
281,
6080,
3963,
1202,
4154,
5726,
8292,
199,
17387,
275,
2120,
14,
17387,
199,
199,
504,
7390,
14,
1548,
492,
5988,
421,
199,
533,
1379,
461,
7382,
316,
2176,
8,
1765,
14,
7382,
316,
2176,
304,
272,
347,
636,
826,
721,
277,
12,
12516,
12,
627,
65,
12,
1011,
829,
304,
267,
1613,
8,
774,
461,
7382,
316,
2176,
12,
291,
2843,
826,
9308,
65,
12,
1011,
829,
9,
267,
291,
14,
9597,
275,
12516,
4388,
199,
533,
1379,
1726,
8,
1726,
304,
272,
986,
4388,
199,
533,
32425,
1746,
8,
2796,
14,
1746,
304,
272,
408,
272,
1379,
314,
2222,
13,
7567,
9597,
4079,
12516,
4514,
14,
272,
408,
272,
347,
511,
13165,
8,
277,
304,
267,
408,
267,
1379,
626,
314,
491,
91,
4515,
93,
1083,
402,
314,
4026,
12516,
2529,
4026,
900,
14,
267,
408,
267,
286,
275,
2120,
14,
17387,
342,
267,
291,
14,
2947,
8,
67,
14,
4515,
1062,
378,
9,
2378,
347,
511,
2176,
22028,
8,
277,
304,
267,
408,
267,
1379,
626,
4882,
883,
506,
18416,
367,
2945,
543,
314,
4026,
12516,
436,
267,
4926,
83,
1771,
376,
491,
91,
998,
352,
1187,
379,
2176,
5565,
267,
408,
267,
286,
275,
2120,
14,
17387,
342,
267,
1240,
275,
286,
14,
1250,
22028,
8,
17,
12,
2400,
282,
12,
330,
26,
488,
12,
413,
12,
330,
29,
18,
9,
267,
291,
14,
7589,
8,
7436,
14,
998,
352,
1187,
379,
2176,
14,
16929,
2175,
8,
1250,
430,
267,
291,
14,
2947,
8,
1250,
14,
362,
1366,
1062,
413,
9,
267,
291,
14,
7589,
8,
1250,
14,
2682,
1012,
2378,
347,
511,
2176,
22028,
22127,
8,
277,
304,
267,
408,
267,
1379,
626,
4882,
883,
506,
20115,
14,
267,
408,
267,
286,
275,
2120,
14,
17387,
342,
267,
1240,
275,
286,
14,
1250,
22028,
8,
17,
12,
2400,
282,
12,
330,
26,
488,
12,
413,
12,
330,
29,
18,
9,
267,
1240,
14,
6406,
342,
267,
291,
14,
19670,
8,
1250,
14,
2682,
1012,
2378,
347,
511,
63,
1250,
22028,
4738,
316,
8,
277,
304,
267,
408,
267,
1379,
626,
314,
18464,
1187,
379,
2176,
2138,
365,
440,
1373,
10889,
267,
2737,
14,
267,
408,
267,
286,
275,
2120,
14,
17387,
342,
267,
1240,
17,
275,
286,
14,
1250,
22028,
8,
709,
12,
2400,
282,
12,
330,
26,
488,
12,
413,
12,
330,
29,
18,
9,
267,
1240,
18,
275,
286,
14,
1250,
22028,
8,
17,
12,
2400,
282,
12,
330,
26,
488,
12,
650,
12,
330,
29,
20,
9,
267,
291,
14,
19670,
8,
1250,
17,
365,
1240,
18,
9,
2378,
347,
511,
2767,
6278,
8,
277,
304,
267,
408,
267,
1379,
626,
19396,
15763,
314,
12516,
911,
8344,
2005,
4882,
14,
267,
408,
267,
4474,
275,
942,
267,
286,
275,
2120,
14,
17387,
342,
267,
1240,
275,
286,
14,
1250,
22028,
8,
18,
12,
2400,
26,
4474,
14,
740,
8,
403,
430,
267,
286,
14,
21195,
8,
17,
9,
267,
291,
14,
2947,
8,
4368,
12,
3073,
267,
286,
14,
21195,
8,
17,
9,
267,
291,
14,
2947,
8,
4368,
12,
359,
403,
566,
267,
291,
14,
19670,
8,
1250,
14,
2682,
1012,
2378,
347,
511,
2767,
6278,
9083,
8,
277,
304,
267,
408,
267,
1379,
5219,
316,
370,
9311,
314,
1240,
315,
282,
3233,
14,
398,
21086,
10474,
1077,
506,
4915,
12,
440,
367,
2893,
282,
1722,
687,
267,
12881,
314,
1240,
687,
32425,
14,
5352,
14,
961,
5074,
1240,
14,
3527,
370,
506,
267,
663,
2544,
314,
3233,
365,
2797,
14,
267,
408,
267,
286,
275,
2120,
14,
17387,
342,
267,
347,
7434,
837,
288,
291,
14,
1855,
8,
705,
14,
16760,
10474,
12,
1240,
14,
6406,
9,
267,
1240,
275,
286,
14,
1250,
22028,
8,
17,
12,
7434,
9,
267,
286,
14,
21195,
8,
17,
9,
2378,
347,
511,
2176,
22028,
10796,
379,
8,
277,
304,
267,
408,
267,
1379,
626,
4882,
883,
506,
24725,
14,
267,
408,
267,
4474,
275,
942,
267,
286,
275,
2120,
14,
17387,
342,
267,
1240,
275,
286,
14,
1250,
22028,
8,
17,
12,
2400,
282,
12,
330,
26,
4474,
14,
740,
1332,
65,
12,
330,
1826,
413,
12,
330,
29,
18,
9,
267,
1240,
14,
5814,
8,
17,
9,
267,
291,
14,
2947,
8,
1250,
14,
362,
1366,
1062,
499,
9,
267,
286,
14,
21195,
8,
17,
14,
21,
9,
267,
291,
14,
2947,
8,
4368,
12,
3073,
267,
286,
14,
21195,
8,
17,
14,
16,
9,
267,
291,
14,
2947,
8,
4368,
12,
3842,
17,
12,
499,
3948,
2378,
347,
511,
2176,
22028,
9637,
22028,
8,
277,
304,
267,
408,
267,
1379,
626,
4882,
883,
1172,
3932,
900,
5305,
370,
282,
2945,
900,
14,
267,
408,
267,
4474,
275,
942,
267,
286,
275,
2120,
14,
17387,
342,
267,
1240,
275,
286,
14,
1250,
22028,
8,
18,
12,
2400,
282,
12,
330,
26,
4474,
14,
740,
1332,
65,
12,
330,
1826,
413,
12,
330,
29,
18,
9,
267,
286,
14,
21195,
8,
17,
9,
267,
1240,
14,
3958,
8,
19,
9,
267,
291,
14,
2947,
8,
1250,
14,
362,
1366,
1062,
841,
9,
267,
286,
14,
21195,
8,
18,
9,
267,
291,
14,
2947,
8,
4368,
12,
3073,
267,
286,
14,
21195,
8,
17,
9,
267,
291,
14,
2947,
8,
4368,
12,
3842,
17,
12,
499,
3948,
2378,
347,
511,
2176,
22028,
9637,
5158,
265,
281,
8,
277,
304,
267,
408,
267,
1379,
626,
4882,
883,
1172,
3932,
900,
5305,
370,
376,
14119,
900,
14,
267,
408,
267,
4474,
275,
942,
267,
286,
275,
2120,
14,
17387,
342,
267,
1240,
275,
286,
14,
1250,
22028,
8,
20,
12,
2400,
282,
12,
330,
26,
4474,
14,
740,
1332,
65,
12,
330,
1826,
413,
12,
330,
29,
18,
9,
267,
1240,
14,
3958,
8,
19,
9,
267,
291,
14,
2947,
8,
1250,
14,
362,
1366,
1062,
650,
9,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mattnenterprise/servo
|
components/script/dom/bindings/codegen/parser/tests/test_constructor_no_interface_object.py
|
52
|
1525
|
def WebIDLTest(parser, harness):
threw = False
try:
parser.parse("""
[Constructor, NoInterfaceObject]
interface TestConstructorNoInterfaceObject {
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
[NoInterfaceObject, Constructor]
interface TestConstructorNoInterfaceObject {
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
parser = parser.reset()
parser.parse("""
[NoInterfaceObject, NamedConstructor=FooBar]
interface TestNamedConstructorNoInterfaceObject {
};
""")
# Test HTMLConstructor and NoInterfaceObject
parser = parser.reset()
threw = False
try:
parser.parse("""
[NoInterfaceObject, HTMLConstructor]
interface TestHTMLConstructorNoInterfaceObject {
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
parser = parser.reset()
threw = False
try:
parser.parse("""
[HTMLConstructor, NoInterfaceObject]
interface TestHTMLConstructorNoInterfaceObject {
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
|
mpl-2.0
|
[
318,
22817,
774,
8,
2087,
12,
20458,
304,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
359,
11447,
12,
3091,
4267,
1692,
61,
288,
3217,
1379,
11447,
1944,
4267,
1692,
469,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
359,
1944,
4267,
1692,
12,
20297,
61,
288,
3217,
1379,
11447,
1944,
4267,
1692,
469,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
1798,
275,
1798,
14,
3958,
342,
339,
1798,
14,
1122,
4852,
267,
359,
1944,
4267,
1692,
12,
16198,
11447,
29,
5686,
5281,
61,
267,
3217,
1379,
7989,
11447,
1944,
4267,
1692,
469,
267,
16735,
272,
7857,
339,
327,
1379,
4163,
11447,
436,
3091,
4267,
1692,
272,
1798,
275,
1798,
14,
3958,
342,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
359,
1944,
4267,
1692,
12,
4163,
11447,
61,
288,
3217,
1379,
4943,
11447,
1944,
4267,
1692,
469,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
1798,
275,
1798,
14,
3958,
342,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
359,
4943,
11447,
12,
3091,
4267,
1692,
61,
288,
3217,
1379,
4943,
11447,
1944,
4267,
1692,
469,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
22817,
774,
8,
2087,
12,
20458,
304,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
359,
11447,
12,
3091,
4267,
1692,
61,
288,
3217,
1379,
11447,
1944,
4267,
1692,
469,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
359,
1944,
4267,
1692,
12,
20297,
61,
288,
3217,
1379,
11447,
1944,
4267,
1692,
469,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
1798,
275,
1798,
14,
3958,
342,
339,
1798,
14,
1122,
4852,
267,
359,
1944,
4267,
1692,
12,
16198,
11447,
29,
5686,
5281,
61,
267,
3217,
1379,
7989,
11447,
1944,
4267,
1692,
469,
267,
16735,
272,
7857,
339,
327,
1379,
4163,
11447,
436,
3091,
4267,
1692,
272,
1798,
275,
1798,
14,
3958,
342,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
359,
1944,
4267,
1692,
12,
4163,
11447,
61,
288,
3217,
1379,
4943,
11447,
1944,
4267,
1692,
469,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
1798,
275,
1798,
14,
3958,
342,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
359,
4943,
11447,
12,
3091,
4267,
1692,
61,
288,
3217,
1379,
4943,
11447,
1944,
4267,
1692,
469,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
wojons/rethinkdb
|
external/gtest_1.6.0/scripts/upload_gtest.py
|
1963
|
2851
|
#!/usr/bin/env python
#
# Copyright 2009, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""upload_gtest.py v0.1.0 -- uploads a Google Test patch for review.
This simple wrapper passes all command line flags and
--cc=googletestframework@googlegroups.com to upload.py.
USAGE: upload_gtest.py [options for upload.py]
"""
__author__ = 'wan@google.com (Zhanyong Wan)'
import os
import sys
CC_FLAG = '--cc='
GTEST_GROUP = 'googletestframework@googlegroups.com'
def main():
# Finds the path to upload.py, assuming it is in the same directory
# as this file.
my_dir = os.path.dirname(os.path.abspath(__file__))
upload_py_path = os.path.join(my_dir, 'upload.py')
# Adds Google Test discussion group to the cc line if it's not there
# already.
upload_py_argv = [upload_py_path]
found_cc_flag = False
for arg in sys.argv[1:]:
if arg.startswith(CC_FLAG):
found_cc_flag = True
cc_line = arg[len(CC_FLAG):]
cc_list = [addr for addr in cc_line.split(',') if addr]
if GTEST_GROUP not in cc_list:
cc_list.append(GTEST_GROUP)
upload_py_argv.append(CC_FLAG + ','.join(cc_list))
else:
upload_py_argv.append(arg)
if not found_cc_flag:
upload_py_argv.append(CC_FLAG + GTEST_GROUP)
# Invokes upload.py with the modified command line flags.
os.execv(upload_py_path, upload_py_argv)
if __name__ == '__main__':
main()
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8937,
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,
5064,
63,
8385,
14,
647,
373,
16,
14,
17,
14,
16,
1553,
26598,
282,
4475,
1379,
3371,
367,
11248,
14,
199,
199,
2765,
3486,
4975,
14933,
1006,
1414,
1004,
3285,
436,
199,
306,
2055,
29,
3098,
396,
4857,
32,
3098,
2634,
14,
957,
370,
5802,
14,
647,
14,
199,
199,
20274,
26,
5802,
63,
8385,
14,
647,
359,
1419,
367,
5802,
14,
647,
61,
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,
199,
2571,
63,
3719,
275,
2850,
2055,
534,
199,
16151,
63,
7823,
275,
283,
3098,
396,
4857,
32,
3098,
2634,
14,
957,
7,
421,
199,
318,
2446,
837,
523,
327,
31434,
314,
931,
370,
5802,
14,
647,
12,
18002,
652,
365,
315,
314,
2011,
2082,
523,
327,
465,
642,
570,
14,
523,
3002,
63,
694,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
523,
5802,
63,
647,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1662,
63,
694,
12,
283,
5064,
14,
647,
358,
819,
327,
15747,
4475,
1379,
16582,
1572,
370,
314,
7429,
1004,
340,
652,
1159,
440,
2337,
523,
327,
2575,
14,
523,
5802,
63,
647,
63,
3020,
275,
359,
5064,
63,
647,
63,
515,
61,
523,
1911,
63,
2055,
63,
4173,
275,
756,
523,
367,
1680,
315,
984,
14,
3020,
59,
17,
10688,
272,
340,
1680,
14,
2460,
8,
2571,
63,
3719,
304,
489,
1911,
63,
2055,
63,
4173,
275,
715,
489,
7429,
63,
604,
275,
1680,
59,
552,
8,
2571,
63,
3719,
15405,
489,
7429,
63,
513,
275,
359,
2697,
367,
5552,
315,
7429,
63,
604,
14,
1294,
11917,
340,
5552,
61,
489,
340,
18652,
63,
7823,
440,
315,
7429,
63,
513,
26,
267,
7429,
63,
513,
14,
740,
8,
16151,
63,
7823,
9,
489,
5802,
63,
647,
63,
3020,
14,
740,
8,
2571,
63,
3719,
435,
12814,
904,
8,
2055,
63,
513,
430,
272,
587,
26,
489,
5802,
63,
647,
63,
3020,
14,
740,
8,
1273,
9,
819,
340,
440,
1911,
63,
2055,
63,
4173,
26,
272,
5802,
63,
647,
63,
3020,
14,
740,
8,
2571,
63,
3719,
435,
18652,
63,
7823,
9,
819,
327,
30110,
22652,
5802,
14,
647,
543,
314,
6042,
1414,
1004,
3285,
14,
523,
747,
14,
1628,
86,
8,
5064,
63,
647,
63,
515,
12,
5802,
63,
647,
63,
3020,
9,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8937,
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,
5064,
63,
8385,
14,
647,
373,
16,
14,
17,
14,
16,
1553,
26598,
282,
4475,
1379,
3371,
367,
11248,
14,
199,
199,
2765,
3486,
4975,
14933,
1006,
1414,
1004,
3285,
436,
199,
306,
2055,
29,
3098,
396,
4857,
32,
3098,
2634,
14,
957,
370,
5802,
14,
647,
14,
199,
199,
20274,
26,
5802,
63,
8385,
14,
647,
359,
1419,
367,
5802,
14,
647,
61,
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,
199,
2571,
63,
3719,
275,
2850,
2055,
534,
199,
16151,
63,
7823,
275,
283,
3098,
396,
4857,
32,
3098,
2634,
14,
957,
7,
421,
199,
318,
2446,
837,
523,
327,
31434,
314,
931,
370,
5802,
14,
647,
12,
18002,
652,
365,
315,
314,
2011,
2082,
523,
327,
465,
642,
570,
14,
523,
3002,
63,
694,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
523,
5802,
63,
647,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1662,
63,
694,
12,
283,
5064,
14,
647,
358,
819,
327,
15747,
4475,
1379,
16582,
1572,
370,
314,
7429,
1004,
340,
652,
1159,
440,
2337,
523,
327,
2575,
14,
523,
5802,
63,
647,
63,
3020,
275,
359,
5064,
63,
647,
63,
515,
61,
523,
1911,
63,
2055,
63,
4173,
275,
756,
523,
367,
1680,
315,
984,
14,
3020,
59,
17,
10688,
272,
340,
1680,
14,
2460,
8,
2571,
63,
3719,
304,
489,
1911,
63,
2055,
63,
4173,
275,
715,
489,
7429,
63,
604,
275,
1680,
59,
552,
8,
2571,
63,
3719,
15405,
489,
7429,
63,
513,
275,
359,
2697,
367,
5552,
315,
7429,
63,
604,
14,
1294,
11917,
340,
5552,
61,
489,
340,
18652,
63,
7823,
440,
315,
7429,
63,
513,
26,
267,
7429,
63,
513,
14,
740,
8,
16151,
63,
7823,
9,
489,
5802,
63,
647,
63,
3020,
14,
740,
8,
2571,
63,
3719,
435,
12814,
904,
8,
2055,
63,
513,
430,
272,
587,
26,
489,
5802,
63,
647,
63,
3020,
14,
740,
8,
1273,
9,
819,
340,
440,
1911,
63,
2055,
63,
4173,
26,
272,
5802,
63,
647,
63,
3020,
14,
740,
8,
2571,
63,
3719,
435,
18652,
63,
7823,
9,
819,
327,
30110,
22652,
5802,
14,
647,
543,
314,
6042,
1414,
1004,
3285,
14,
523,
747,
14,
1628,
86,
8,
5064,
63,
647,
63,
515,
12,
5802,
63,
647,
63,
3020,
9,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ankravch/flask-restful
|
examples/todo_simple.py
|
21
|
1332
|
from flask import Flask, request
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
todos = {}
class TodoSimple(Resource):
"""
You can try this example as follow:
$ curl http://localhost:5000/todo1 -d "data=Remember the milk" -X PUT
$ curl http://localhost:5000/todo1
{"todo1": "Remember the milk"}
$ curl http://localhost:5000/todo2 -d "data=Change my breakpads" -X PUT
$ curl http://localhost:5000/todo2
{"todo2": "Change my breakpads"}
Or from python if you have requests :
>>> from requests import put, get
>>> put('http://localhost:5000/todo1', data={'data': 'Remember the milk'}).json
{u'todo1': u'Remember the milk'}
>>> get('http://localhost:5000/todo1').json
{u'todo1': u'Remember the milk'}
>>> put('http://localhost:5000/todo2', data={'data': 'Change my breakpads'}).json
{u'todo2': u'Change my breakpads'}
>>> get('http://localhost:5000/todo2').json
{u'todo2': u'Change my breakpads'}
"""
def get(self, todo_id):
return {todo_id: todos[todo_id]}
def put(self, todo_id):
todos[todo_id] = request.form['data']
return {todo_id: todos[todo_id]}
api.add_resource(TodoSimple, '/<string:todo_id>')
if __name__ == '__main__':
app.run(debug=False)
|
bsd-3-clause
|
[
504,
7209,
492,
16704,
12,
1056,
199,
504,
7209,
63,
3911,
1893,
492,
7337,
12,
13986,
199,
199,
571,
275,
16704,
3460,
354,
3368,
199,
1246,
275,
13986,
8,
571,
9,
199,
199,
5766,
736,
275,
1052,
199,
199,
533,
377,
19657,
3184,
8,
4031,
304,
272,
408,
272,
2047,
883,
862,
642,
2893,
465,
2035,
26,
267,
2672,
26145,
1455,
921,
5967,
26,
13128,
15,
11396,
17,
446,
68,
298,
576,
29,
497,
1114,
314,
333,
382,
75,
2,
446,
56,
18337,
267,
2672,
26145,
1455,
921,
5967,
26,
13128,
15,
11396,
17,
267,
2420,
11396,
17,
582,
298,
497,
1114,
314,
333,
382,
75,
3570,
267,
2672,
26145,
1455,
921,
5967,
26,
13128,
15,
11396,
18,
446,
68,
298,
576,
29,
4001,
3002,
2059,
6226,
83,
2,
446,
56,
18337,
267,
2672,
26145,
1455,
921,
5967,
26,
13128,
15,
11396,
18,
267,
2420,
11396,
18,
582,
298,
4001,
3002,
2059,
6226,
83,
3570,
339,
4236,
687,
2366,
340,
1265,
1172,
4145,
520,
1362,
1306,
687,
4145,
492,
5324,
12,
664,
1362,
1306,
5324,
360,
1014,
921,
5967,
26,
13128,
15,
11396,
17,
297,
666,
3713,
576,
356,
283,
497,
1114,
314,
333,
382,
75,
936,
680,
1001,
1362,
469,
85,
1133,
19657,
17,
356,
399,
7,
497,
1114,
314,
333,
382,
75,
936,
1362,
1306,
664,
360,
1014,
921,
5967,
26,
13128,
15,
11396,
17,
1959,
1001,
1362,
469,
85,
1133,
19657,
17,
356,
399,
7,
497,
1114,
314,
333,
382,
75,
936,
1362,
1306,
5324,
360,
1014,
921,
5967,
26,
13128,
15,
11396,
18,
297,
666,
3713,
576,
356,
283,
4001,
3002,
2059,
6226,
83,
936,
680,
1001,
1362,
469,
85,
1133,
19657,
18,
356,
399,
7,
4001,
3002,
2059,
6226,
83,
936,
1362,
1306,
664,
360,
1014,
921,
5967,
26,
13128,
15,
11396,
18,
1959,
1001,
1362,
469,
85,
1133,
19657,
18,
356,
399,
7,
4001,
3002,
2059,
6226,
83,
936,
339,
408,
272,
347,
664,
8,
277,
12,
11386,
63,
344,
304,
267,
372,
469,
11396,
63,
344,
26,
7076,
736,
59,
11396,
63,
344,
9420,
339,
347,
5324,
8,
277,
12,
11386,
63,
344,
304,
267,
7076,
736,
59,
11396,
63,
344,
61,
275,
1056,
14,
964,
459,
576,
418,
267,
372,
469,
11396,
63,
344,
26,
7076,
736,
59,
11396,
63,
344,
9420,
199,
199,
1246,
14,
525,
63,
1927,
8,
52,
19657,
3184,
12,
1994,
28,
875,
26,
11396,
63,
344,
5971,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1145,
14,
1065,
8,
1757,
29,
797,
9,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
7209,
492,
16704,
12,
1056,
199,
504,
7209,
63,
3911,
1893,
492,
7337,
12,
13986,
199,
199,
571,
275,
16704,
3460,
354,
3368,
199,
1246,
275,
13986,
8,
571,
9,
199,
199,
5766,
736,
275,
1052,
199,
199,
533,
377,
19657,
3184,
8,
4031,
304,
272,
408,
272,
2047,
883,
862,
642,
2893,
465,
2035,
26,
267,
2672,
26145,
1455,
921,
5967,
26,
13128,
15,
11396,
17,
446,
68,
298,
576,
29,
497,
1114,
314,
333,
382,
75,
2,
446,
56,
18337,
267,
2672,
26145,
1455,
921,
5967,
26,
13128,
15,
11396,
17,
267,
2420,
11396,
17,
582,
298,
497,
1114,
314,
333,
382,
75,
3570,
267,
2672,
26145,
1455,
921,
5967,
26,
13128,
15,
11396,
18,
446,
68,
298,
576,
29,
4001,
3002,
2059,
6226,
83,
2,
446,
56,
18337,
267,
2672,
26145,
1455,
921,
5967,
26,
13128,
15,
11396,
18,
267,
2420,
11396,
18,
582,
298,
4001,
3002,
2059,
6226,
83,
3570,
339,
4236,
687,
2366,
340,
1265,
1172,
4145,
520,
1362,
1306,
687,
4145,
492,
5324,
12,
664,
1362,
1306,
5324,
360,
1014,
921,
5967,
26,
13128,
15,
11396,
17,
297,
666,
3713,
576,
356,
283,
497,
1114,
314,
333,
382,
75,
936,
680,
1001,
1362,
469,
85,
1133,
19657,
17,
356,
399,
7,
497,
1114,
314,
333,
382,
75,
936,
1362,
1306,
664,
360,
1014,
921,
5967,
26,
13128,
15,
11396,
17,
1959,
1001,
1362,
469,
85,
1133,
19657,
17,
356,
399,
7,
497,
1114,
314,
333,
382,
75,
936,
1362,
1306,
5324,
360,
1014,
921,
5967,
26,
13128,
15,
11396,
18,
297,
666,
3713,
576,
356,
283,
4001,
3002,
2059,
6226,
83,
936,
680,
1001,
1362,
469,
85,
1133,
19657,
18,
356,
399,
7,
4001,
3002,
2059,
6226,
83,
936,
1362,
1306,
664,
360,
1014,
921,
5967,
26,
13128,
15,
11396,
18,
1959,
1001,
1362,
469,
85,
1133,
19657,
18,
356,
399,
7,
4001,
3002,
2059,
6226,
83,
936,
339,
408,
272,
347,
664,
8,
277,
12,
11386,
63,
344,
304,
267,
372,
469,
11396,
63,
344,
26,
7076,
736,
59,
11396,
63,
344,
9420,
339,
347,
5324,
8,
277,
12,
11386,
63,
344,
304,
267,
7076,
736,
59,
11396,
63,
344,
61,
275,
1056,
14,
964,
459,
576,
418,
267,
372,
469,
11396,
63,
344,
26,
7076,
736,
59,
11396,
63,
344,
9420,
199,
199,
1246,
14,
525,
63,
1927,
8,
52,
19657,
3184,
12,
1994,
28,
875,
26,
11396,
63,
344,
5971,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1145,
14,
1065,
8,
1757,
29,
797,
9,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
futurice/vdsm
|
vdsm/network/errors.py
|
2
|
1272
|
#
# Copyright 2011-2014 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Refer to the README and COPYING files for full details of the license
#
ERR_OK = 0
ERR_BAD_PARAMS = 21
ERR_BAD_ADDR = 22
ERR_BAD_NIC = 23
ERR_USED_NIC = 24
ERR_BAD_BONDING = 25
ERR_BAD_VLAN = 26
ERR_BAD_BRIDGE = 27
ERR_USED_BRIDGE = 28
ERR_FAILED_IFUP = 29
ERR_FAILED_IFDOWN = 30
ERR_LOST_CONNECTION = 10 # noConPeer
class ConfigNetworkError(Exception):
def __init__(self, errCode, message):
self.errCode = errCode
self.message = message
Exception.__init__(self, self.errCode, self.message)
|
gpl-2.0
|
[
3,
199,
3,
1898,
7760,
13,
7280,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
199,
3,
199,
3,
21751,
370,
314,
27781,
436,
9685,
1584,
367,
2615,
2436,
402,
314,
4190,
199,
3,
199,
199,
2666,
63,
3593,
275,
378,
199,
2666,
63,
9439,
63,
17978,
275,
7829,
199,
2666,
63,
9439,
63,
7803,
275,
6928,
199,
2666,
63,
9439,
63,
30374,
275,
6546,
199,
2666,
63,
8558,
63,
30374,
275,
5504,
199,
2666,
63,
9439,
63,
34,
615,
36,
1206,
275,
5661,
199,
2666,
63,
9439,
63,
22716,
275,
7875,
199,
2666,
63,
9439,
63,
7184,
998,
4962,
275,
8087,
199,
2666,
63,
8558,
63,
7184,
998,
4962,
275,
7294,
199,
2666,
63,
12299,
63,
4656,
2160,
275,
7349,
199,
2666,
63,
12299,
63,
4656,
8819,
275,
4233,
199,
2666,
63,
1484,
840,
63,
18389,
275,
1616,
259,
327,
949,
714,
12566,
421,
199,
533,
4094,
4491,
547,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
2329,
3034,
12,
1245,
304,
267,
291,
14,
1508,
3034,
275,
2329,
3034,
267,
291,
14,
1188,
275,
1245,
267,
2186,
855,
826,
721,
277,
12,
291,
14,
1508,
3034,
12,
291,
14,
1188,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
1898,
7760,
13,
7280,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
199,
3,
199,
3,
21751,
370,
314,
27781,
436,
9685,
1584,
367,
2615,
2436,
402,
314,
4190,
199,
3,
199,
199,
2666,
63,
3593,
275,
378,
199,
2666,
63,
9439,
63,
17978,
275,
7829,
199,
2666,
63,
9439,
63,
7803,
275,
6928,
199,
2666,
63,
9439,
63,
30374,
275,
6546,
199,
2666,
63,
8558,
63,
30374,
275,
5504,
199,
2666,
63,
9439,
63,
34,
615,
36,
1206,
275,
5661,
199,
2666,
63,
9439,
63,
22716,
275,
7875,
199,
2666,
63,
9439,
63,
7184,
998,
4962,
275,
8087,
199,
2666,
63,
8558,
63,
7184,
998,
4962,
275,
7294,
199,
2666,
63,
12299,
63,
4656,
2160,
275,
7349,
199,
2666,
63,
12299,
63,
4656,
8819,
275,
4233,
199,
2666,
63,
1484,
840,
63,
18389,
275,
1616,
259,
327,
949,
714,
12566,
421,
199,
533,
4094,
4491,
547,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
2329,
3034,
12,
1245,
304,
267,
291,
14,
1508,
3034,
275,
2329,
3034,
267,
291,
14,
1188,
275,
1245,
267,
2186,
855,
826,
721,
277,
12,
291,
14,
1508,
3034,
12,
291,
14,
1188,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
vinchoi/fishplay
|
flask/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/contrib/socks.py
|
151
|
5669
|
# -*- coding: utf-8 -*-
"""
SOCKS support for urllib3
~~~~~~~~~~~~~~~~~~~~~~~~~
This contrib module contains provisional support for SOCKS proxies from within
urllib3. This module supports SOCKS4 (specifically the SOCKS4A variant) and
SOCKS5. To enable its functionality, either install PySocks or install this
module with the ``socks`` extra.
Known Limitations:
- Currently PySocks does not support contacting remote websites via literal
IPv6 addresses. Any such connection attempt will fail.
- Currently PySocks does not support IPv6 connections to the SOCKS proxy. Any
such connection attempt will fail.
"""
from __future__ import absolute_import
try:
import socks
except ImportError:
import warnings
from ..exceptions import DependencyWarning
warnings.warn((
'SOCKS support in urllib3 requires the installation of optional '
'dependencies: specifically, PySocks. For more information, see '
'https://urllib3.readthedocs.org/en/latest/contrib.html#socks-proxies'
),
DependencyWarning
)
raise
from socket import error as SocketError, timeout as SocketTimeout
from ..connection import (
HTTPConnection, HTTPSConnection
)
from ..connectionpool import (
HTTPConnectionPool, HTTPSConnectionPool
)
from ..exceptions import ConnectTimeoutError, NewConnectionError
from ..poolmanager import PoolManager
from ..util.url import parse_url
try:
import ssl
except ImportError:
ssl = None
class SOCKSConnection(HTTPConnection):
"""
A plain-text HTTP connection that connects via a SOCKS proxy.
"""
def __init__(self, *args, **kwargs):
self._socks_options = kwargs.pop('_socks_options')
super(SOCKSConnection, self).__init__(*args, **kwargs)
def _new_conn(self):
"""
Establish a new connection via the SOCKS proxy.
"""
extra_kw = {}
if self.source_address:
extra_kw['source_address'] = self.source_address
if self.socket_options:
extra_kw['socket_options'] = self.socket_options
try:
conn = socks.create_connection(
(self.host, self.port),
proxy_type=self._socks_options['socks_version'],
proxy_addr=self._socks_options['proxy_host'],
proxy_port=self._socks_options['proxy_port'],
proxy_username=self._socks_options['username'],
proxy_password=self._socks_options['password'],
timeout=self.timeout,
**extra_kw
)
except SocketTimeout as e:
raise ConnectTimeoutError(
self, "Connection to %s timed out. (connect timeout=%s)" %
(self.host, self.timeout))
except socks.ProxyError as e:
# This is fragile as hell, but it seems to be the only way to raise
# useful errors here.
if e.socket_err:
error = e.socket_err
if isinstance(error, SocketTimeout):
raise ConnectTimeoutError(
self,
"Connection to %s timed out. (connect timeout=%s)" %
(self.host, self.timeout)
)
else:
raise NewConnectionError(
self,
"Failed to establish a new connection: %s" % error
)
else:
raise NewConnectionError(
self,
"Failed to establish a new connection: %s" % e
)
except SocketError as e: # Defensive: PySocks should catch all these.
raise NewConnectionError(
self, "Failed to establish a new connection: %s" % e)
return conn
# We don't need to duplicate the Verified/Unverified distinction from
# urllib3/connection.py here because the HTTPSConnection will already have been
# correctly set to either the Verified or Unverified form by that module. This
# means the SOCKSHTTPSConnection will automatically be the correct type.
class SOCKSHTTPSConnection(SOCKSConnection, HTTPSConnection):
pass
class SOCKSHTTPConnectionPool(HTTPConnectionPool):
ConnectionCls = SOCKSConnection
class SOCKSHTTPSConnectionPool(HTTPSConnectionPool):
ConnectionCls = SOCKSHTTPSConnection
class SOCKSProxyManager(PoolManager):
"""
A version of the urllib3 ProxyManager that routes connections via the
defined SOCKS proxy.
"""
pool_classes_by_scheme = {
'http': SOCKSHTTPConnectionPool,
'https': SOCKSHTTPSConnectionPool,
}
def __init__(self, proxy_url, username=None, password=None,
num_pools=10, headers=None, **connection_pool_kw):
parsed = parse_url(proxy_url)
if parsed.scheme == 'socks5':
socks_version = socks.PROXY_TYPE_SOCKS5
elif parsed.scheme == 'socks4':
socks_version = socks.PROXY_TYPE_SOCKS4
else:
raise ValueError(
"Unable to determine SOCKS version from %s" % proxy_url
)
self.proxy_url = proxy_url
socks_options = {
'socks_version': socks_version,
'proxy_host': parsed.host,
'proxy_port': parsed.port,
'username': username,
'password': password,
}
connection_pool_kw['_socks_options'] = socks_options
super(SOCKSProxyManager, self).__init__(
num_pools, headers, **connection_pool_kw
)
self.pool_classes_by_scheme = SOCKSProxyManager.pool_classes_by_scheme
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
9469,
51,
2291,
367,
4011,
19,
199,
9753,
4919,
94,
199,
199,
2765,
5914,
859,
3509,
15408,
279,
2291,
367,
26327,
51,
14942,
687,
4453,
199,
4078,
19,
14,
961,
859,
5171,
26327,
51,
20,
334,
6100,
1183,
314,
26327,
51,
20,
33,
9854,
9,
436,
199,
9469,
51,
21,
14,
4005,
4756,
2399,
9330,
12,
1902,
3907,
1611,
51,
27416,
503,
3907,
642,
199,
578,
543,
314,
1124,
21234,
1040,
2402,
14,
199,
199,
24574,
22672,
1298,
26,
199,
199,
13,
13550,
1611,
51,
27416,
1630,
440,
2291,
8966,
316,
3982,
3330,
8619,
4799,
8785,
523,
6509,
22,
7149,
14,
6184,
4066,
1950,
7427,
911,
2449,
14,
199,
13,
13550,
1611,
51,
27416,
1630,
440,
2291,
6509,
22,
6947,
370,
314,
26327,
51,
4566,
14,
6184,
523,
4066,
1950,
7427,
911,
2449,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
893,
26,
272,
492,
6771,
83,
199,
2590,
3545,
26,
272,
492,
3598,
272,
687,
2508,
3924,
492,
22922,
3849,
339,
3598,
14,
4050,
1332,
267,
283,
9469,
51,
2291,
315,
4011,
19,
5074,
314,
12096,
402,
2716,
283,
267,
283,
5714,
26,
22543,
12,
1611,
51,
27416,
14,
221,
2104,
1655,
2556,
12,
1937,
283,
267,
283,
2859,
921,
4078,
19,
14,
25085,
14,
1308,
15,
287,
15,
7410,
15,
2828,
14,
1360,
3,
21234,
13,
17128,
7,
267,
2318,
267,
22922,
3849,
272,
776,
272,
746,
199,
199,
504,
2838,
492,
1125,
465,
17766,
547,
12,
2653,
465,
17766,
6372,
199,
199,
504,
2508,
2105,
492,
334,
272,
3101,
3225,
12,
14147,
3225,
199,
9,
199,
504,
2508,
2105,
2293,
492,
334,
272,
3101,
23929,
12,
14147,
23929,
199,
9,
199,
504,
2508,
3924,
492,
15175,
19382,
12,
7053,
20349,
199,
504,
2508,
2293,
2609,
492,
15553,
2988,
199,
504,
2508,
1974,
14,
633,
492,
2198,
63,
633,
199,
199,
893,
26,
272,
492,
6149,
199,
2590,
3545,
26,
272,
6149,
275,
488,
421,
199,
533,
26327,
51,
3225,
8,
19114,
304,
272,
408,
272,
437,
8971,
13,
505,
3101,
1950,
626,
4907,
83,
4799,
282,
26327,
51,
4566,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
423,
21234,
63,
1419,
275,
2074,
14,
1935,
6412,
21234,
63,
1419,
358,
267,
1613,
8,
9469,
51,
3225,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
485,
1222,
63,
1631,
8,
277,
304,
267,
408,
267,
15896,
13306,
282,
892,
1950,
4799,
314,
26327,
51,
4566,
14,
267,
408,
267,
2402,
63,
829,
275,
1052,
267,
340,
291,
14,
1365,
63,
1562,
26,
288,
2402,
63,
829,
459,
1365,
63,
1562,
418,
275,
291,
14,
1365,
63,
1562,
398,
340,
291,
14,
3450,
63,
1419,
26,
288,
2402,
63,
829,
459,
3450,
63,
1419,
418,
275,
291,
14,
3450,
63,
1419,
398,
862,
26,
288,
2557,
275,
6771,
83,
14,
981,
63,
2105,
8,
355,
334,
277,
14,
1102,
12,
291,
14,
719,
395,
355,
4566,
63,
466,
29,
277,
423,
21234,
63,
1419,
459,
21234,
63,
1023,
995,
355,
4566,
63,
2697,
29,
277,
423,
21234,
63,
1419,
459,
3280,
63,
1102,
995,
355,
4566,
63,
719,
29,
277,
423,
21234,
63,
1419,
459,
3280,
63,
719,
995,
355,
4566,
63,
2473,
29,
277,
423,
21234,
63,
1419,
459,
2473,
995,
355,
4566,
63,
2060,
29,
277,
423,
21234,
63,
1419,
459,
2060,
995,
355,
2653,
29,
277,
14,
2593,
12,
355,
1011,
2911,
63,
829,
288,
776,
398,
871,
17766,
6372,
465,
325,
26,
288,
746,
15175,
19382,
8,
355,
291,
12,
298,
3225,
370,
450,
83,
18590,
734,
14,
334,
2242,
2653,
2458,
83,
2924,
450,
355,
334,
277,
14,
1102,
12,
291,
14,
2593,
430,
398,
871,
6771,
83,
14,
4936,
547,
465,
325,
26,
288,
327,
961,
365,
11101,
441,
465,
394,
1697,
12,
1325,
652,
12237,
370,
506,
314,
1454,
4340,
370,
746,
288,
327,
2997,
2552,
2348,
14,
288,
340,
325,
14,
3450,
63,
1508,
26,
355,
1125,
275,
325,
14,
3450,
63,
1508,
355,
340,
1228,
8,
705,
12,
17766,
6372,
304,
490,
746,
15175,
19382,
8,
717,
291,
12,
717,
298,
3225,
370,
450,
83,
18590,
734,
14,
334,
2242,
2653,
2458,
83,
2924,
450,
717,
334,
277,
14,
1102,
12,
291,
14,
2593,
9,
490,
776,
355,
587,
26,
490,
746,
7053,
20349,
8,
717,
291,
12,
717,
298,
4276,
370,
16873,
282,
892,
1950,
26,
450,
83,
2,
450,
1125,
490,
776,
288,
587,
26,
355,
746,
7053,
20349,
8,
490,
291,
12,
490,
298,
4276,
370,
16873,
282,
892,
1950,
26,
450,
83,
2,
450,
325,
355,
776,
398,
871,
17766,
547,
465,
325,
26,
221,
327,
11391,
287,
3398,
26,
1611,
51,
27416,
1077,
8579,
1006,
3520,
14,
288,
746,
7053,
20349,
8,
355,
291,
12,
298,
4276,
370,
16873,
282,
892,
1950,
26,
450,
83,
2,
450,
325,
9,
398,
372,
2557,
421,
199,
3,
2136,
2793,
1133,
1929,
370,
9250,
314,
5444,
4541,
15,
1358,
12949,
2917,
262,
414,
687,
199,
3,
4011,
19,
15,
2105,
14,
647,
2348,
2952,
314,
14147,
3225,
911,
2575,
1172,
2757,
199,
3,
6657,
663,
370,
1902,
314,
5444,
4541,
503,
1910,
12949,
1824,
701,
626,
859,
14,
961,
199,
3,
4910,
314,
26327,
51,
27945,
911,
5847,
506,
314,
3211,
730,
14,
199,
533,
26327,
51,
27945,
8,
9469,
51,
3225,
12,
14147,
3225,
304,
272,
986,
421,
199,
533,
26327,
51,
19114,
5453,
8,
19114,
5453,
304,
272,
8113,
24342,
275,
26327,
51,
3225,
421,
199,
533,
26327,
51,
14921,
23929,
8,
14921,
23929,
304,
272,
8113,
24342,
275,
26327,
51,
27945,
421,
199,
533,
26327,
51,
4936,
2988,
8,
5453,
2988,
304,
272,
408,
272,
437,
1015,
402,
314,
4011,
19,
12373,
2988,
626,
15777,
6947,
4799,
314,
272,
3247,
26327,
51,
4566,
14,
272,
408,
272,
4203,
63,
2888,
63,
991,
63,
5512,
275,
469,
267,
283,
1014,
356,
26327,
51,
19114,
5453,
12,
267,
283,
2859,
356,
26327,
51,
14921,
23929,
12,
272,
789,
339,
347,
636,
826,
721,
277,
12,
4566,
63,
633,
12,
3434
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
9469,
51,
2291,
367,
4011,
19,
199,
9753,
4919,
94,
199,
199,
2765,
5914,
859,
3509,
15408,
279,
2291,
367,
26327,
51,
14942,
687,
4453,
199,
4078,
19,
14,
961,
859,
5171,
26327,
51,
20,
334,
6100,
1183,
314,
26327,
51,
20,
33,
9854,
9,
436,
199,
9469,
51,
21,
14,
4005,
4756,
2399,
9330,
12,
1902,
3907,
1611,
51,
27416,
503,
3907,
642,
199,
578,
543,
314,
1124,
21234,
1040,
2402,
14,
199,
199,
24574,
22672,
1298,
26,
199,
199,
13,
13550,
1611,
51,
27416,
1630,
440,
2291,
8966,
316,
3982,
3330,
8619,
4799,
8785,
523,
6509,
22,
7149,
14,
6184,
4066,
1950,
7427,
911,
2449,
14,
199,
13,
13550,
1611,
51,
27416,
1630,
440,
2291,
6509,
22,
6947,
370,
314,
26327,
51,
4566,
14,
6184,
523,
4066,
1950,
7427,
911,
2449,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
893,
26,
272,
492,
6771,
83,
199,
2590,
3545,
26,
272,
492,
3598,
272,
687,
2508,
3924,
492,
22922,
3849,
339,
3598,
14,
4050,
1332,
267,
283,
9469,
51,
2291,
315,
4011,
19,
5074,
314,
12096,
402,
2716,
283,
267,
283,
5714,
26,
22543,
12,
1611,
51,
27416,
14,
221,
2104,
1655,
2556,
12,
1937,
283,
267,
283,
2859,
921,
4078,
19,
14,
25085,
14,
1308,
15,
287,
15,
7410,
15,
2828,
14,
1360,
3,
21234,
13,
17128,
7,
267,
2318,
267,
22922,
3849,
272,
776,
272,
746,
199,
199,
504,
2838,
492,
1125,
465,
17766,
547,
12,
2653,
465,
17766,
6372,
199,
199,
504,
2508,
2105,
492,
334,
272,
3101,
3225,
12,
14147,
3225,
199,
9,
199,
504,
2508,
2105,
2293,
492,
334,
272,
3101,
23929,
12,
14147,
23929,
199,
9,
199,
504,
2508,
3924,
492,
15175,
19382,
12,
7053,
20349,
199,
504,
2508,
2293,
2609,
492,
15553,
2988,
199,
504,
2508,
1974,
14,
633,
492,
2198,
63,
633,
199,
199,
893,
26,
272,
492,
6149,
199,
2590,
3545,
26,
272,
6149,
275,
488,
421,
199,
533,
26327,
51,
3225,
8,
19114,
304,
272,
408,
272,
437,
8971,
13,
505,
3101,
1950,
626,
4907,
83,
4799,
282,
26327,
51,
4566,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
423,
21234,
63,
1419,
275,
2074,
14,
1935,
6412,
21234,
63,
1419,
358,
267,
1613,
8,
9469,
51,
3225,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
485,
1222,
63,
1631,
8,
277,
304,
267,
408,
267,
15896,
13306,
282,
892,
1950,
4799,
314,
26327,
51,
4566,
14,
267,
408,
267,
2402,
63,
829,
275,
1052,
267,
340,
291,
14,
1365,
63,
1562,
26,
288,
2402,
63,
829,
459,
1365,
63,
1562,
418,
275,
291,
14,
1365,
63,
1562,
398,
340,
291,
14,
3450,
63,
1419,
26,
288,
2402,
63,
829,
459,
3450,
63,
1419,
418,
275,
291,
14,
3450,
63,
1419,
398,
862,
26,
288,
2557,
275,
6771,
83,
14,
981,
63,
2105,
8,
355,
334,
277,
14,
1102,
12,
291,
14,
719,
395,
355,
4566,
63,
466,
29,
277,
423,
21234,
63,
1419,
459,
21234,
63,
1023,
995,
355,
4566,
63,
2697,
29,
277,
423,
21234,
63,
1419,
459,
3280,
63,
1102,
995,
355,
4566,
63,
719,
29,
277,
423,
21234,
63,
1419,
459,
3280,
63,
719,
995,
355,
4566,
63,
2473,
29,
277,
423,
21234,
63,
1419,
459,
2473,
995,
355,
4566,
63,
2060,
29,
277,
423,
21234,
63,
1419,
459,
2060,
995,
355,
2653,
29,
277,
14,
2593,
12,
355,
1011,
2911,
63,
829,
288,
776,
398,
871,
17766,
6372,
465,
325,
26,
288,
746,
15175,
19382,
8,
355,
291,
12,
298,
3225,
370,
450,
83,
18590,
734,
14,
334,
2242,
2653,
2458,
83,
2924,
450,
355,
334,
277,
14,
1102,
12,
291,
14,
2593,
430,
398,
871,
6771,
83,
14,
4936,
547,
465,
325,
26,
288,
327,
961,
365,
11101,
441,
465,
394,
1697,
12,
1325,
652,
12237,
370,
506,
314,
1454,
4340,
370,
746,
288,
327,
2997,
2552,
2348,
14,
288,
340,
325,
14,
3450,
63,
1508,
26,
355,
1125,
275,
325,
14,
3450,
63,
1508,
355,
340,
1228,
8,
705,
12,
17766,
6372,
304,
490,
746,
15175,
19382,
8,
717,
291,
12,
717,
298,
3225,
370,
450,
83,
18590,
734,
14,
334,
2242,
2653,
2458,
83,
2924,
450,
717,
334,
277,
14,
1102,
12,
291,
14,
2593,
9,
490,
776,
355,
587,
26,
490,
746,
7053,
20349,
8,
717,
291,
12,
717,
298,
4276,
370,
16873,
282,
892,
1950,
26,
450,
83,
2,
450,
1125,
490,
776,
288,
587,
26,
355,
746,
7053,
20349,
8,
490,
291,
12,
490,
298,
4276,
370,
16873,
282,
892,
1950,
26,
450,
83,
2,
450,
325,
355,
776,
398,
871,
17766,
547,
465,
325,
26,
221,
327,
11391,
287,
3398,
26,
1611,
51,
27416,
1077,
8579,
1006,
3520,
14,
288,
746,
7053,
20349,
8,
355,
291,
12,
298,
4276,
370,
16873,
282,
892,
1950,
26,
450,
83,
2,
450,
325,
9,
398,
372,
2557,
421,
199,
3,
2136,
2793,
1133,
1929,
370,
9250,
314,
5444,
4541,
15,
1358,
12949,
2917,
262,
414,
687,
199,
3,
4011,
19,
15,
2105,
14,
647,
2348,
2952,
314,
14147,
3225,
911,
2575,
1172,
2757,
199,
3,
6657,
663,
370,
1902,
314,
5444,
4541,
503,
1910,
12949,
1824,
701,
626,
859,
14,
961,
199,
3,
4910,
314,
26327,
51,
27945,
911,
5847,
506,
314,
3211,
730,
14,
199,
533,
26327,
51,
27945,
8,
9469,
51,
3225,
12,
14147,
3225,
304,
272,
986,
421,
199,
533,
26327,
51,
19114,
5453,
8,
19114,
5453,
304,
272,
8113,
24342,
275,
26327,
51,
3225,
421,
199,
533,
26327,
51,
14921,
23929,
8,
14921,
23929,
304,
272,
8113,
24342,
275,
26327,
51,
27945,
421,
199,
533,
26327,
51,
4936,
2988,
8,
5453,
2988,
304,
272,
408,
272,
437,
1015,
402,
314,
4011,
19,
12373,
2988,
626,
15777,
6947,
4799,
314,
272,
3247,
26327,
51,
4566,
14,
272,
408,
272,
4203,
63,
2888,
63,
991,
63,
5512,
275,
469,
267,
283,
1014,
356,
26327,
51,
19114,
5453,
12,
267,
283,
2859,
356,
26327,
51,
14921,
23929,
12,
272,
789,
339,
347,
636,
826,
721,
277,
12,
4566,
63,
633,
12,
3434,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
cyanjc321/ardupilot
|
Tools/autotest/jsb_sim/runsim.py
|
167
|
12772
|
#!/usr/bin/env python
# run a jsbsim model as a child process
import sys, os, pexpect, socket
import math, time, select, struct, signal, errno
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'pysim'))
import util, atexit, fdpexpect
from pymavlink import fgFDM
class control_state(object):
def __init__(self):
self.aileron = 0
self.elevator = 0
self.throttle = 0
self.rudder = 0
self.ground_height = 0
sitl_state = control_state()
def interpret_address(addrstr):
'''interpret a IP:port string'''
a = addrstr.split(':')
a[1] = int(a[1])
return tuple(a)
def jsb_set(variable, value):
'''set a JSBSim variable'''
global jsb_console
jsb_console.send('set %s %s\r\n' % (variable, value))
def setup_template(home):
'''setup aircraft/Rascal/reset.xml'''
global opts
v = home.split(',')
if len(v) != 4:
print("home should be lat,lng,alt,hdg - '%s'" % home)
sys.exit(1)
latitude = float(v[0])
longitude = float(v[1])
altitude = float(v[2])
heading = float(v[3])
sitl_state.ground_height = altitude
template = os.path.join('aircraft', 'Rascal', 'reset_template.xml')
reset = os.path.join('aircraft', 'Rascal', 'reset.xml')
xml = open(template).read() % { 'LATITUDE' : str(latitude),
'LONGITUDE' : str(longitude),
'HEADING' : str(heading) }
open(reset, mode='w').write(xml)
print("Wrote %s" % reset)
baseport = int(opts.simout.split(':')[1])
template = os.path.join('jsb_sim', 'fgout_template.xml')
out = os.path.join('jsb_sim', 'fgout.xml')
xml = open(template).read() % { 'FGOUTPORT' : str(baseport+3) }
open(out, mode='w').write(xml)
print("Wrote %s" % out)
template = os.path.join('jsb_sim', 'rascal_test_template.xml')
out = os.path.join('jsb_sim', 'rascal_test.xml')
xml = open(template).read() % { 'JSBCONSOLEPORT' : str(baseport+4) }
open(out, mode='w').write(xml)
print("Wrote %s" % out)
def process_sitl_input(buf):
'''process control changes from SITL sim'''
control = list(struct.unpack('<14H', buf))
pwm = control[:11]
(speed, direction, turbulance) = control[11:]
global wind
wind.speed = speed*0.01
wind.direction = direction*0.01
wind.turbulance = turbulance*0.01
aileron = (pwm[0]-1500)/500.0
elevator = (pwm[1]-1500)/500.0
throttle = (pwm[2]-1000)/1000.0
if opts.revthr:
throttle = 1.0 - throttle
rudder = (pwm[3]-1500)/500.0
if opts.elevon:
# fake an elevon plane
ch1 = aileron
ch2 = elevator
aileron = (ch2-ch1)/2.0
# the minus does away with the need for RC2_REV=-1
elevator = -(ch2+ch1)/2.0
if opts.vtail:
# fake an elevon plane
ch1 = elevator
ch2 = rudder
# this matches VTAIL_OUTPUT==2
elevator = (ch2-ch1)/2.0
rudder = (ch2+ch1)/2.0
buf = ''
if aileron != sitl_state.aileron:
buf += 'set fcs/aileron-cmd-norm %s\n' % aileron
sitl_state.aileron = aileron
if elevator != sitl_state.elevator:
buf += 'set fcs/elevator-cmd-norm %s\n' % elevator
sitl_state.elevator = elevator
if rudder != sitl_state.rudder:
buf += 'set fcs/rudder-cmd-norm %s\n' % rudder
sitl_state.rudder = rudder
if throttle != sitl_state.throttle:
buf += 'set fcs/throttle-cmd-norm %s\n' % throttle
sitl_state.throttle = throttle
buf += 'step\n'
global jsb_console
jsb_console.send(buf)
def update_wind(wind):
'''update wind simulation'''
(speed, direction) = wind.current()
jsb_set('atmosphere/psiw-rad', math.radians(direction))
jsb_set('atmosphere/wind-mag-fps', speed/0.3048)
def process_jsb_input(buf, simtime):
'''process FG FDM input from JSBSim'''
global fdm, fg_out, sim_out
fdm.parse(buf)
if fg_out:
try:
agl = fdm.get('agl', units='meters')
fdm.set('altitude', agl+sitl_state.ground_height, units='meters')
fdm.set('rpm', sitl_state.throttle*1000)
fg_out.send(fdm.pack())
except socket.error as e:
if e.errno not in [ errno.ECONNREFUSED ]:
raise
timestamp = int(simtime*1.0e6)
simbuf = struct.pack('<Q17dI',
timestamp,
fdm.get('latitude', units='degrees'),
fdm.get('longitude', units='degrees'),
fdm.get('altitude', units='meters'),
fdm.get('psi', units='degrees'),
fdm.get('v_north', units='mps'),
fdm.get('v_east', units='mps'),
fdm.get('v_down', units='mps'),
fdm.get('A_X_pilot', units='mpss'),
fdm.get('A_Y_pilot', units='mpss'),
fdm.get('A_Z_pilot', units='mpss'),
fdm.get('phidot', units='dps'),
fdm.get('thetadot', units='dps'),
fdm.get('psidot', units='dps'),
fdm.get('phi', units='degrees'),
fdm.get('theta', units='degrees'),
fdm.get('psi', units='degrees'),
fdm.get('vcas', units='mps'),
0x4c56414f)
try:
sim_out.send(simbuf)
except socket.error as e:
if e.errno not in [ errno.ECONNREFUSED ]:
raise
##################
# main program
from optparse import OptionParser
parser = OptionParser("runsim.py [options]")
parser.add_option("--simin", help="SITL input (IP:port)", default="127.0.0.1:5502")
parser.add_option("--simout", help="SITL output (IP:port)", default="127.0.0.1:5501")
parser.add_option("--fgout", help="FG display output (IP:port)", default="127.0.0.1:5503")
parser.add_option("--home", type='string', help="home lat,lng,alt,hdg (required)")
parser.add_option("--script", type='string', help='jsbsim model script', default='jsb_sim/rascal_test.xml')
parser.add_option("--options", type='string', help='jsbsim startup options')
parser.add_option("--elevon", action='store_true', default=False, help='assume elevon input')
parser.add_option("--revthr", action='store_true', default=False, help='reverse throttle')
parser.add_option("--vtail", action='store_true', default=False, help='assume vtail input')
parser.add_option("--wind", dest="wind", help="Simulate wind (speed,direction,turbulance)", default='0,0,0')
parser.add_option("--rate", type='int', help="Simulation rate (Hz)", default=1000)
parser.add_option("--speedup", type='float', default=1.0, help="speedup from realtime")
(opts, args) = parser.parse_args()
for m in [ 'home', 'script' ]:
if not opts.__dict__[m]:
print("Missing required option '%s'" % m)
parser.print_help()
sys.exit(1)
os.chdir(util.reltopdir('Tools/autotest'))
# kill off child when we exit
atexit.register(util.pexpect_close_all)
setup_template(opts.home)
# start child
cmd = "JSBSim --realtime --suspend --nice --simulation-rate=%u --logdirectivefile=jsb_sim/fgout.xml --script=%s" % (opts.rate, opts.script)
if opts.options:
cmd += ' %s' % opts.options
jsb = pexpect.spawn(cmd, logfile=sys.stdout, timeout=10)
jsb.delaybeforesend = 0
util.pexpect_autoclose(jsb)
i = jsb.expect(["Successfully bound to socket for input on port (\d+)",
"Could not bind to socket for input"])
if i == 1:
print("Failed to start JSBSim - is another copy running?")
sys.exit(1)
jsb_out_address = interpret_address("127.0.0.1:%u" % int(jsb.match.group(1)))
jsb.expect("Creating UDP socket on port (\d+)")
jsb_in_address = interpret_address("127.0.0.1:%u" % int(jsb.match.group(1)))
jsb.expect("Successfully connected to socket for output")
jsb.expect("JSBSim Execution beginning")
# setup output to jsbsim
print("JSBSim console on %s" % str(jsb_out_address))
jsb_out = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
jsb_out.connect(jsb_out_address)
jsb_console = fdpexpect.fdspawn(jsb_out.fileno(), logfile=sys.stdout)
jsb_console.delaybeforesend = 0
# setup input from jsbsim
print("JSBSim FG FDM input on %s" % str(jsb_in_address))
jsb_in = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
jsb_in.bind(jsb_in_address)
jsb_in.setblocking(0)
# socket addresses
sim_out_address = interpret_address(opts.simout)
sim_in_address = interpret_address(opts.simin)
# setup input from SITL sim
sim_in = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sim_in.bind(sim_in_address)
sim_in.setblocking(0)
# setup output to SITL sim
sim_out = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sim_out.connect(interpret_address(opts.simout))
sim_out.setblocking(0)
# setup possible output to FlightGear for display
fg_out = None
if opts.fgout:
fg_out = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
fg_out.connect(interpret_address(opts.fgout))
# setup wind generator
wind = util.Wind(opts.wind)
fdm = fgFDM.fgFDM()
jsb_console.send('info\n')
jsb_console.send('resume\n')
jsb.expect(["trim computation time","Trim Results"])
time.sleep(1.5)
jsb_console.send('step\n')
jsb_console.logfile = None
print("Simulator ready to fly")
def main_loop():
'''run main loop'''
tnow = time.time()
last_report = tnow
last_sim_input = tnow
last_wind_update = tnow
frame_count = 0
paused = False
simstep = 1.0/opts.rate
simtime = simstep
frame_time = 1.0/opts.rate
scaled_frame_time = frame_time/opts.speedup
last_wall_time = time.time()
achieved_rate = opts.speedup
while True:
new_frame = False
rin = [jsb_in.fileno(), sim_in.fileno(), jsb_console.fileno(), jsb.fileno()]
try:
(rin, win, xin) = select.select(rin, [], [], 1.0)
except select.error:
util.check_parent()
continue
tnow = time.time()
if jsb_in.fileno() in rin:
buf = jsb_in.recv(fdm.packet_size())
process_jsb_input(buf, simtime)
frame_count += 1
new_frame = True
if sim_in.fileno() in rin:
simbuf = sim_in.recv(28)
process_sitl_input(simbuf)
simtime += simstep
last_sim_input = tnow
# show any jsbsim console output
if jsb_console.fileno() in rin:
util.pexpect_drain(jsb_console)
if jsb.fileno() in rin:
util.pexpect_drain(jsb)
# only simulate wind above 5 meters, to prevent crashes while
# waiting for takeoff
if tnow - last_wind_update > 0.1:
update_wind(wind)
last_wind_update = tnow
if tnow - last_report > 3:
print("FPS %u asl=%.1f agl=%.1f roll=%.1f pitch=%.1f a=(%.2f %.2f %.2f) AR=%.1f" % (
frame_count / (time.time() - last_report),
fdm.get('altitude', units='meters'),
fdm.get('agl', units='meters'),
fdm.get('phi', units='degrees'),
fdm.get('theta', units='degrees'),
fdm.get('A_X_pilot', units='mpss'),
fdm.get('A_Y_pilot', units='mpss'),
fdm.get('A_Z_pilot', units='mpss'),
achieved_rate))
frame_count = 0
last_report = time.time()
if new_frame:
now = time.time()
if now < last_wall_time + scaled_frame_time:
dt = last_wall_time+scaled_frame_time - now
time.sleep(last_wall_time+scaled_frame_time - now)
now = time.time()
if now > last_wall_time and now - last_wall_time < 0.1:
rate = 1.0/(now - last_wall_time)
achieved_rate = (0.98*achieved_rate) + (0.02*rate)
if achieved_rate < opts.rate*opts.speedup:
scaled_frame_time *= 0.999
else:
scaled_frame_time *= 1.001
last_wall_time = now
def exit_handler():
'''exit the sim'''
print("running exit handler")
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGTERM, signal.SIG_IGN)
# JSBSim really doesn't like to die ...
if getattr(jsb, 'pid', None) is not None:
os.kill(jsb.pid, signal.SIGKILL)
jsb_console.send('quit\n')
jsb.close(force=True)
util.pexpect_close_all()
sys.exit(1)
signal.signal(signal.SIGINT, exit_handler)
signal.signal(signal.SIGTERM, exit_handler)
try:
main_loop()
except Exception as ex:
print(ex)
exit_handler()
raise
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1255,
282,
8586,
66,
5206,
1402,
465,
282,
1982,
2112,
199,
199,
646,
984,
12,
747,
12,
28855,
12,
2838,
199,
646,
3473,
12,
900,
12,
3504,
12,
2702,
12,
4673,
12,
7554,
199,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
22159,
19155,
283,
647,
5206,
1333,
199,
199,
646,
4884,
12,
19840,
12,
6111,
16531,
1764,
199,
504,
1134,
24610,
492,
16587,
7902,
45,
199,
199,
533,
3304,
63,
929,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
65,
441,
2641,
275,
378,
267,
291,
14,
24083,
707,
275,
378,
267,
291,
14,
20086,
275,
378,
267,
291,
14,
82,
1181,
424,
275,
378,
267,
291,
14,
3928,
63,
3333,
275,
378,
199,
199,
2221,
76,
63,
929,
275,
3304,
63,
929,
342,
421,
199,
318,
15579,
63,
1562,
8,
2697,
495,
304,
272,
1449,
21533,
282,
3531,
26,
719,
1059,
2344,
272,
282,
275,
5552,
495,
14,
1294,
11633,
272,
282,
59,
17,
61,
275,
1109,
8,
65,
59,
17,
566,
272,
372,
2008,
8,
65,
9,
199,
199,
318,
8586,
66,
63,
409,
8,
1975,
12,
574,
304,
272,
1449,
409,
282,
1603,
12463,
7467,
1750,
2344,
272,
2288,
8586,
66,
63,
6614,
272,
8586,
66,
63,
6614,
14,
2254,
360,
409,
450,
83,
450,
83,
60,
82,
60,
78,
7,
450,
334,
1975,
12,
574,
430,
199,
199,
318,
3272,
63,
1160,
8,
4219,
304,
272,
1449,
2758,
282,
5958,
4800,
15,
50,
305,
915,
15,
3958,
14,
1652,
2344,
272,
2288,
3999,
272,
373,
275,
5629,
14,
1294,
11917,
272,
340,
822,
8,
86,
9,
1137,
841,
26,
267,
870,
480,
4219,
1077,
506,
8396,
12,
23829,
12,
4478,
12,
7952,
71,
446,
1543,
83,
4065,
450,
5629,
9,
267,
984,
14,
2224,
8,
17,
9,
272,
18896,
275,
2069,
8,
86,
59,
16,
566,
272,
18154,
275,
2069,
8,
86,
59,
17,
566,
272,
29534,
275,
2069,
8,
86,
59,
18,
566,
272,
16631,
275,
2069,
8,
86,
59,
19,
566,
272,
13867,
76,
63,
929,
14,
3928,
63,
3333,
275,
29534,
272,
1978,
275,
747,
14,
515,
14,
904,
360,
65,
5958,
4800,
297,
283,
50,
305,
915,
297,
283,
3958,
63,
1160,
14,
1652,
358,
272,
5305,
275,
747,
14,
515,
14,
904,
360,
65,
5958,
4800,
297,
283,
50,
305,
915,
297,
283,
3958,
14,
1652,
358,
272,
2748,
275,
1551,
8,
1160,
680,
739,
342,
450,
469,
283,
20307,
28742,
7,
221,
520,
620,
8,
13331,
395,
2511,
283,
12375,
28742,
7,
520,
620,
8,
13803,
395,
2511,
283,
5211,
1206,
7,
257,
520,
620,
8,
13983,
9,
789,
272,
1551,
8,
3958,
12,
818,
534,
87,
1959,
952,
8,
1652,
9,
272,
870,
480,
55,
22665,
450,
83,
2,
450,
5305,
9,
339,
1300,
719,
275,
1109,
8,
3291,
14,
5206,
548,
14,
1294,
24050,
17,
566,
339,
1978,
275,
747,
14,
515,
14,
904,
360,
3596,
66,
63,
5206,
297,
283,
9681,
548,
63,
1160,
14,
1652,
358,
272,
734,
420,
275,
747,
14,
515,
14,
904,
360,
3596,
66,
63,
5206,
297,
283,
9681,
548,
14,
1652,
358,
272,
2748,
275,
1551,
8,
1160,
680,
739,
342,
450,
469,
283,
27453,
1877,
3657,
7,
221,
520,
620,
8,
1095,
719,
11,
19,
9,
789,
272,
1551,
8,
548,
12,
818,
534,
87,
1959,
952,
8,
1652,
9,
272,
870,
480,
55,
22665,
450,
83,
2,
450,
734,
9,
339,
1978,
275,
747,
14,
515,
14,
904,
360,
3596,
66,
63,
5206,
297,
283,
6360,
915,
63,
396,
63,
1160,
14,
1652,
358,
272,
734,
420,
275,
747,
14,
515,
14,
904,
360,
3596,
66,
63,
5206,
297,
283,
6360,
915,
63,
396,
14,
1652,
358,
272,
2748,
275,
1551,
8,
1160,
680,
739,
342,
450,
469,
283,
11378,
34,
31774,
3657,
7,
221,
520,
620,
8,
1095,
719,
11,
20,
9,
789,
272,
1551,
8,
548,
12,
818,
534,
87,
1959,
952,
8,
1652,
9,
272,
870,
480,
55,
22665,
450,
83,
2,
450,
734,
9,
16872,
199,
318,
2112,
63,
2221,
76,
63,
1210,
8,
1436,
304,
272,
1449,
1412,
3304,
4493,
687,
428,
649,
44,
4389,
2344,
272,
3304,
275,
769,
8,
1820,
14,
5301,
4827,
1079,
40,
297,
4123,
430,
272,
299,
16240,
275,
3304,
1491,
845,
61,
272,
334,
7625,
12,
7581,
12,
307,
300,
25792,
554,
9,
275,
3304,
59,
845,
2938,
339,
2288,
15417,
272,
15417,
14,
7625,
420,
275,
8112,
10,
16,
14,
614,
272,
15417,
14,
6874,
221,
275,
7581,
10,
16,
14,
614,
272,
15417,
14,
16218,
25792,
554,
275,
307,
300,
25792,
554,
10,
16,
14,
614,
2286,
282,
441,
2641,
221,
275,
334,
30425,
59,
16,
11285,
27607,
2447,
5783,
14,
16,
272,
325,
6972,
707,
275,
334,
30425,
59,
17,
11285,
27607,
2447,
5783,
14,
16,
272,
27048,
275,
334,
30425,
59,
18,
11285,
5279,
2447,
5279,
14,
16,
272,
340,
3999,
14,
4964,
28854,
26,
267,
27048,
275,
413,
14,
16,
446,
27048,
272,
519,
1181,
424,
257,
275,
334,
30425,
59,
19,
11285,
27607,
2447,
5783,
14,
16,
339,
340,
3999,
14,
24083,
265,
26,
267,
327,
4026,
376,
325,
6972,
265,
16388,
267,
682,
17,
275,
282,
441,
2641,
267,
682,
18,
275,
325,
6972,
707,
267,
282,
441,
2641,
221,
275,
334,
335,
18,
13,
335,
17,
2447,
18,
14,
16,
267,
327,
314,
21357,
1630,
13437,
543,
314,
1929,
367,
29256,
18,
63,
23817,
4022,
17,
267,
325,
6972,
707,
275,
24953,
335,
18,
11,
335,
17,
2447,
18,
14,
16,
339,
340,
3999,
14,
86,
1521,
26,
267,
327,
4026,
376,
325,
6972,
265,
16388,
267,
682,
17,
275,
325,
6972,
707,
267,
682,
18,
275,
519,
1181,
424,
267,
327,
642,
4450,
812,
30890,
63,
8414,
389,
18,
267,
325,
6972,
707,
275,
334,
335,
18,
13,
335,
17,
2447,
18,
14,
16,
267,
519,
1181,
424,
257,
275,
334,
335,
18,
11,
335,
17,
2447,
18,
14,
16,
339,
4123,
275,
2125,
272,
340,
282,
441
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1255,
282,
8586,
66,
5206,
1402,
465,
282,
1982,
2112,
199,
199,
646,
984,
12,
747,
12,
28855,
12,
2838,
199,
646,
3473,
12,
900,
12,
3504,
12,
2702,
12,
4673,
12,
7554,
199,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
22159,
19155,
283,
647,
5206,
1333,
199,
199,
646,
4884,
12,
19840,
12,
6111,
16531,
1764,
199,
504,
1134,
24610,
492,
16587,
7902,
45,
199,
199,
533,
3304,
63,
929,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
65,
441,
2641,
275,
378,
267,
291,
14,
24083,
707,
275,
378,
267,
291,
14,
20086,
275,
378,
267,
291,
14,
82,
1181,
424,
275,
378,
267,
291,
14,
3928,
63,
3333,
275,
378,
199,
199,
2221,
76,
63,
929,
275,
3304,
63,
929,
342,
421,
199,
318,
15579,
63,
1562,
8,
2697,
495,
304,
272,
1449,
21533,
282,
3531,
26,
719,
1059,
2344,
272,
282,
275,
5552,
495,
14,
1294,
11633,
272,
282,
59,
17,
61,
275,
1109,
8,
65,
59,
17,
566,
272,
372,
2008,
8,
65,
9,
199,
199,
318,
8586,
66,
63,
409,
8,
1975,
12,
574,
304,
272,
1449,
409,
282,
1603,
12463,
7467,
1750,
2344,
272,
2288,
8586,
66,
63,
6614,
272,
8586,
66,
63,
6614,
14,
2254,
360,
409,
450,
83,
450,
83,
60,
82,
60,
78,
7,
450,
334,
1975,
12,
574,
430,
199,
199,
318,
3272,
63,
1160,
8,
4219,
304,
272,
1449,
2758,
282,
5958,
4800,
15,
50,
305,
915,
15,
3958,
14,
1652,
2344,
272,
2288,
3999,
272,
373,
275,
5629,
14,
1294,
11917,
272,
340,
822,
8,
86,
9,
1137,
841,
26,
267,
870,
480,
4219,
1077,
506,
8396,
12,
23829,
12,
4478,
12,
7952,
71,
446,
1543,
83,
4065,
450,
5629,
9,
267,
984,
14,
2224,
8,
17,
9,
272,
18896,
275,
2069,
8,
86,
59,
16,
566,
272,
18154,
275,
2069,
8,
86,
59,
17,
566,
272,
29534,
275,
2069,
8,
86,
59,
18,
566,
272,
16631,
275,
2069,
8,
86,
59,
19,
566,
272,
13867,
76,
63,
929,
14,
3928,
63,
3333,
275,
29534,
272,
1978,
275,
747,
14,
515,
14,
904,
360,
65,
5958,
4800,
297,
283,
50,
305,
915,
297,
283,
3958,
63,
1160,
14,
1652,
358,
272,
5305,
275,
747,
14,
515,
14,
904,
360,
65,
5958,
4800,
297,
283,
50,
305,
915,
297,
283,
3958,
14,
1652,
358,
272,
2748,
275,
1551,
8,
1160,
680,
739,
342,
450,
469,
283,
20307,
28742,
7,
221,
520,
620,
8,
13331,
395,
2511,
283,
12375,
28742,
7,
520,
620,
8,
13803,
395,
2511,
283,
5211,
1206,
7,
257,
520,
620,
8,
13983,
9,
789,
272,
1551,
8,
3958,
12,
818,
534,
87,
1959,
952,
8,
1652,
9,
272,
870,
480,
55,
22665,
450,
83,
2,
450,
5305,
9,
339,
1300,
719,
275,
1109,
8,
3291,
14,
5206,
548,
14,
1294,
24050,
17,
566,
339,
1978,
275,
747,
14,
515,
14,
904,
360,
3596,
66,
63,
5206,
297,
283,
9681,
548,
63,
1160,
14,
1652,
358,
272,
734,
420,
275,
747,
14,
515,
14,
904,
360,
3596,
66,
63,
5206,
297,
283,
9681,
548,
14,
1652,
358,
272,
2748,
275,
1551,
8,
1160,
680,
739,
342,
450,
469,
283,
27453,
1877,
3657,
7,
221,
520,
620,
8,
1095,
719,
11,
19,
9,
789,
272,
1551,
8,
548,
12,
818,
534,
87,
1959,
952,
8,
1652,
9,
272,
870,
480,
55,
22665,
450,
83,
2,
450,
734,
9,
339,
1978,
275,
747,
14,
515,
14,
904,
360,
3596,
66,
63,
5206,
297,
283,
6360,
915,
63,
396,
63,
1160,
14,
1652,
358,
272,
734,
420,
275,
747,
14,
515,
14,
904,
360,
3596,
66,
63,
5206,
297,
283,
6360,
915,
63,
396,
14,
1652,
358,
272,
2748,
275,
1551,
8,
1160,
680,
739,
342,
450,
469,
283,
11378,
34,
31774,
3657,
7,
221,
520,
620,
8,
1095,
719,
11,
20,
9,
789,
272,
1551,
8,
548,
12,
818,
534,
87,
1959,
952,
8,
1652,
9,
272,
870,
480,
55,
22665,
450,
83,
2,
450,
734,
9,
16872,
199,
318,
2112,
63,
2221,
76,
63,
1210,
8,
1436,
304,
272,
1449,
1412,
3304,
4493,
687,
428,
649,
44,
4389,
2344,
272,
3304,
275,
769,
8,
1820,
14,
5301,
4827,
1079,
40,
297,
4123,
430,
272,
299,
16240,
275,
3304,
1491,
845,
61,
272,
334,
7625,
12,
7581,
12,
307,
300,
25792,
554,
9,
275,
3304,
59,
845,
2938,
339,
2288,
15417,
272,
15417,
14,
7625,
420,
275,
8112,
10,
16,
14,
614,
272,
15417,
14,
6874,
221,
275,
7581,
10,
16,
14,
614,
272,
15417,
14,
16218,
25792,
554,
275,
307,
300,
25792,
554,
10,
16,
14,
614,
2286,
282,
441,
2641,
221,
275,
334,
30425,
59,
16,
11285,
27607,
2447,
5783,
14,
16,
272,
325,
6972,
707,
275,
334,
30425,
59,
17,
11285,
27607,
2447,
5783,
14,
16,
272,
27048,
275,
334,
30425,
59,
18,
11285,
5279,
2447,
5279,
14,
16,
272,
340,
3999,
14,
4964,
28854,
26,
267,
27048,
275,
413,
14,
16,
446,
27048,
272,
519,
1181,
424,
257,
275,
334,
30425,
59,
19,
11285,
27607,
2447,
5783,
14,
16,
339,
340,
3999,
14,
24083,
265,
26,
267,
327,
4026,
376,
325,
6972,
265,
16388,
267,
682,
17,
275,
282,
441,
2641,
267,
682,
18,
275,
325,
6972,
707,
267,
282,
441,
2641,
221,
275,
334,
335,
18,
13,
335,
17,
2447,
18,
14,
16,
267,
327,
314,
21357,
1630,
13437,
543,
314,
1929,
367,
29256,
18,
63,
23817,
4022,
17,
267,
325,
6972,
707,
275,
24953,
335,
18,
11,
335,
17,
2447,
18,
14,
16,
339,
340,
3999,
14,
86,
1521,
26,
267,
327,
4026,
376,
325,
6972,
265,
16388,
267,
682,
17,
275,
325,
6972,
707,
267,
682,
18,
275,
519,
1181,
424,
267,
327,
642,
4450,
812,
30890,
63,
8414,
389,
18,
267,
325,
6972,
707,
275,
334,
335,
18,
13,
335,
17,
2447,
18,
14,
16,
267,
519,
1181,
424,
257,
275,
334,
335,
18,
11,
335,
17,
2447,
18,
14,
16,
339,
4123,
275,
2125,
272,
340,
282,
441,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
openwsn-berkeley/coap
|
tests/func/test_multiple_CON.py
|
1
|
1178
|
import logging
import testUtils as utils
import time
import threading
from conftest import IPADDRESS1, \
RESOURCE, \
DUMMYVAL,\
OSCORECLIENTCONTEXT
from coap import coapDefines as d, \
coapOption as o, \
coapObjectSecurity as oscore
#============================ logging ===============================
log = logging.getLogger(utils.getMyLoggerName())
log.addHandler(utils.NullHandler())
#============================ tests ===========================================
def test_GET(logFixture,snoopyDispatcher,twoEndPoints):
(coap1,coap2,securityEnabled) = twoEndPoints
options = []
if securityEnabled:
context = oscore.SecurityContext(OSCORECLIENTCONTEXT)
options = [o.ObjectSecurity(context=context)]
# have coap2 do a get
for _ in range(20):
reply = coap2.GET(
uri = 'coap://[{0}]:{1}/{2}/'.format(IPADDRESS1,d.DEFAULT_UDP_PORT,RESOURCE),
confirmable = True,
options=options
)
assert reply==DUMMYVAL
|
bsd-3-clause
|
[
646,
2050,
202,
199,
646,
511,
7535,
465,
3778,
2999,
199,
646,
900,
202,
199,
646,
5796,
2999,
199,
504,
3743,
396,
492,
3531,
12368,
17,
12,
971,
27843,
30061,
12,
971,
27843,
577,
22472,
3204,
4202,
27843,
4403,
24428,
9901,
9059,
202,
199,
504,
512,
439,
258,
492,
512,
439,
23891,
465,
366,
12,
971,
27843,
512,
439,
2602,
465,
312,
12,
971,
27843,
512,
439,
1692,
7676,
465,
747,
1018,
2999,
199,
3,
1280,
5769,
2050,
16248,
17224,
2999,
199,
793,
275,
2050,
14,
5572,
8,
1208,
14,
362,
5713,
4455,
985,
1012,
202,
199,
793,
14,
18826,
8,
1208,
14,
8849,
2461,
1012,
8428,
202,
199,
3,
1280,
5769,
2295,
19469,
17575,
2999,
199,
318,
511,
63,
2970,
8,
793,
12812,
12,
83,
889,
927,
15461,
12,
5601,
3005,
10225,
304,
11787,
334,
331,
439,
17,
12,
331,
439,
18,
12,
4416,
6589,
9,
275,
2877,
3005,
10225,
2958,
1511,
275,
942,
1128,
340,
6391,
6589,
26,
1039,
1067,
275,
747,
1018,
14,
7676,
2998,
8,
3100,
24428,
9901,
9059,
9,
4341,
1511,
275,
359,
79,
14,
1692,
7676,
8,
1100,
29,
1100,
1874,
11787,
327,
1172,
512,
439,
18,
886,
282,
664,
1128,
367,
485,
315,
1425,
8,
1165,
304,
1039,
9351,
275,
512,
439,
18,
14,
2970,
8,
1675,
5108,
260,
275,
283,
331,
439,
921,
59,
91,
16,
93,
2189,
91,
17,
16152,
18,
5995,
1370,
908,
8,
1772,
12368,
17,
12,
68,
14,
3472,
63,
17457,
63,
3657,
12,
14110,
395,
1675,
12679,
461,
275,
715,
12,
1675,
1511,
29,
1419,
1039,
776,
1039,
702,
9351,
389,
26778,
3204,
10060,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2050,
202,
199,
646,
511,
7535,
465,
3778,
2999,
199,
646,
900,
202,
199,
646,
5796,
2999,
199,
504,
3743,
396,
492,
3531,
12368,
17,
12,
971,
27843,
30061,
12,
971,
27843,
577,
22472,
3204,
4202,
27843,
4403,
24428,
9901,
9059,
202,
199,
504,
512,
439,
258,
492,
512,
439,
23891,
465,
366,
12,
971,
27843,
512,
439,
2602,
465,
312,
12,
971,
27843,
512,
439,
1692,
7676,
465,
747,
1018,
2999,
199,
3,
1280,
5769,
2050,
16248,
17224,
2999,
199,
793,
275,
2050,
14,
5572,
8,
1208,
14,
362,
5713,
4455,
985,
1012,
202,
199,
793,
14,
18826,
8,
1208,
14,
8849,
2461,
1012,
8428,
202,
199,
3,
1280,
5769,
2295,
19469,
17575,
2999,
199,
318,
511,
63,
2970,
8,
793,
12812,
12,
83,
889,
927,
15461,
12,
5601,
3005,
10225,
304,
11787,
334,
331,
439,
17,
12,
331,
439,
18,
12,
4416,
6589,
9,
275,
2877,
3005,
10225,
2958,
1511,
275,
942,
1128,
340,
6391,
6589,
26,
1039,
1067,
275,
747,
1018,
14,
7676,
2998,
8,
3100,
24428,
9901,
9059,
9,
4341,
1511,
275,
359,
79,
14,
1692,
7676,
8,
1100,
29,
1100,
1874,
11787,
327,
1172,
512,
439,
18,
886,
282,
664,
1128,
367,
485,
315,
1425,
8,
1165,
304,
1039,
9351,
275,
512,
439,
18,
14,
2970,
8,
1675,
5108,
260,
275,
283,
331,
439,
921,
59,
91,
16,
93,
2189,
91,
17,
16152,
18,
5995,
1370,
908,
8,
1772,
12368,
17,
12,
68,
14,
3472,
63,
17457,
63,
3657,
12,
14110,
395,
1675,
12679,
461,
275,
715,
12,
1675,
1511,
29,
1419,
1039,
776,
1039,
702,
9351,
389,
26778,
3204,
10060,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
dcsch/pyif
|
pyif/grammar.py
|
1
|
12193
|
from . import action
from .parser import NOUN_TOKEN, HELD_TOKEN, MULTI_TOKEN, MULTIHELD_TOKEN, MULTIEXCEPT_TOKEN, MULTIINSIDE_TOKEN, TOPIC_TOKEN, CREATURE_TOKEN
from .debug import log
class Verb:
def __init__(self, grammar, verb_tokens):
self.grammar = grammar
self.verb_tokens = verb_tokens
self.actions = []
def add_action(self, tokens, action, nouns=None):
self.actions.append((tokens, action, nouns))
def find_action_matching_tokens(self, tokens):
"""
Find an action defined by this verb that matches the given token pattern.
Returns the matching action, and a list of matching noun tokens.
"""
for a in self.actions:
log(" examining action %s" % a[1])
# Does the token count match?
if len(tokens) != len(a[0]):
continue
# Try to match the tokens
matched_noun_tokens = []
match_count = 0
for i in range(len(a[0])):
# Is the token definition a tuple? If so, the token type
# is the first part, and a qualifying function the second
if isinstance(a[0][i], tuple):
t = a[0][i][0]
f = a[0][i][1]
else:
t = a[0][i]
f = None
if t == NOUN_TOKEN or MULTI_TOKEN:
# We are expecting a noun -- is it legal?
log("NOUN_TOKEN")
if self.grammar.legal_noun_token(tokens[i]):
# Is there a qualifying function?
if f == None or f() == True:
log("matched noun token")
matched_noun_tokens.append((tokens[i], t))
match_count += 1
else:
log("noun token matched but qualifying function returned False")
if t == HELD_TOKEN:
# We are expecting a noun -- is it legal?
log("HELD_TOKEN")
if self.grammar.legal_noun_token(tokens[i]):
log("matched noun token")
matched_noun_tokens.append((tokens[i], t))
match_count += 1
elif t == tokens[i]:
log("matched: %s" % t)
match_count += 1
if match_count == len(a[0]):
return (a, matched_noun_tokens)
return (None, None)
class Grammar:
def __init__(self, story):
self.story = story
self.verbs = []
# self.nouns = []
# Meta-verbs
verb = self.add_verb(["brief", "normal"])
verb.add_action([], action.brief)
verb = self.add_verb(["verbose", "long"])
verb.add_action([], action.verbose)
verb = self.add_verb(["superbrief", "short"])
verb.add_action([], action.superbrief)
verb = self.add_verb(["quit", "q", "die"])
verb.add_action([], action.quit)
verb = self.add_verb(["restart"])
verb.add_action([], action.restart)
verb = self.add_verb(["restore"])
verb.add_action([], action.restore)
verb = self.add_verb(["save"])
verb.add_action([], action.save)
verb = self.add_verb(["score"])
verb.add_action([], action.score)
verb = self.add_verb(["version"])
verb.add_action([], action.version)
# Game Verbs
verb = self.add_verb(["answer", "say", "shout", "speak"])
verb.add_action([TOPIC_TOKEN, "to", CREATURE_TOKEN], action.answer)
verb = self.add_verb(["ask"])
verb.add_action([CREATURE_TOKEN, "about", TOPIC_TOKEN], action.ask)
verb.add_action([CREATURE_TOKEN, "for", NOUN_TOKEN], action.ask_for)
verb.add_action([CREATURE_TOKEN, "to", TOPIC_TOKEN], action.ask_to)
verb.add_action(["that", CREATURE_TOKEN, TOPIC_TOKEN], action.ask_to)
verb = self.add_verb(["attack", "break", "crack", "destroy",
"fight", "hit", "kill", "murder", "punch",
"smash", "thump", "torture", "wreck"])
verb.add_action([NOUN_TOKEN], action.attack)
verb = self.add_verb(["blow"])
verb.add_action([HELD_TOKEN], action.blow)
verb = self.add_verb(["bother", "curses", "darn", "drat"])
verb.add_action([], action.mild)
verb.add_action([TOPIC_TOKEN], action.mild)
verb = self.add_verb(["burn", "light"])
verb.add_action([NOUN_TOKEN], action.burn)
verb.add_action([NOUN_TOKEN, "with", HELD_TOKEN], action.burn)
verb = self.add_verb(["buy", "purchase"])
verb.add_action([NOUN_TOKEN], action.buy)
verb = self.add_verb(["climb", "scale"])
verb.add_action([NOUN_TOKEN], action.climb)
verb.add_action(["up", NOUN_TOKEN], action.climb)
verb.add_action(["over", NOUN_TOKEN], action.climb)
verb = self.add_verb(["close", "cover", "shut"])
verb.add_action([NOUN_TOKEN], action.close)
verb.add_action(["up", NOUN_TOKEN], action.close)
verb.add_action(["off", NOUN_TOKEN], action.switch_off)
verb = self.add_verb(["consult"])
verb.add_action([NOUN_TOKEN, "about", TOPIC_TOKEN], action.consult)
verb.add_action([NOUN_TOKEN, "on", TOPIC_TOKEN], action.consult)
verb = self.add_verb(["cut", "chop", "prune", "slice"])
verb.add_action([NOUN_TOKEN], action.cut)
verb = self.add_verb(["dig"])
verb.add_action([NOUN_TOKEN], action.dig)
verb.add_action([NOUN_TOKEN, "with", HELD_TOKEN], action.dig)
verb = self.add_verb(["drink", "sip", "swallow"])
verb.add_action([NOUN_TOKEN], action.drink)
verb = self.add_verb(["drop", "discard", "throw"])
verb.add_action([MULTIHELD_TOKEN], action.drop)
verb.add_action([MULTIEXCEPT_TOKEN, "in", NOUN_TOKEN], action.insert)
verb.add_action([MULTIEXCEPT_TOKEN, "into", NOUN_TOKEN], action.insert)
verb.add_action([MULTIEXCEPT_TOKEN, "down", NOUN_TOKEN], action.insert)
verb.add_action([MULTIEXCEPT_TOKEN, "on", NOUN_TOKEN], action.put_on)
verb.add_action([MULTIEXCEPT_TOKEN, "onto", NOUN_TOKEN], action.put_on)
verb.add_action([HELD_TOKEN, "at", NOUN_TOKEN], action.throw_at)
verb.add_action([HELD_TOKEN, "against", NOUN_TOKEN], action.throw_at)
verb.add_action([HELD_TOKEN, "on", NOUN_TOKEN], action.throw_at)
verb.add_action([HELD_TOKEN, "onto", NOUN_TOKEN], action.throw_at)
verb = self.add_verb(["eat"])
verb.add_action([HELD_TOKEN], action.eat)
verb = self.add_verb(["empty"])
verb.add_action([NOUN_TOKEN], action.empty)
verb.add_action(["out", NOUN_TOKEN], action.empty)
verb.add_action([NOUN_TOKEN, "out"], action.empty)
verb.add_action([NOUN_TOKEN, "to", NOUN_TOKEN], action.empty_to)
verb.add_action([NOUN_TOKEN, "into", NOUN_TOKEN], action.empty_to)
verb.add_action([NOUN_TOKEN, "on", NOUN_TOKEN], action.empty_to)
verb.add_action([NOUN_TOKEN, "onto", NOUN_TOKEN], action.empty_to)
verb = self.add_verb(["enter", "cross"])
verb.add_action([], action.go_in)
verb.add_action([NOUN_TOKEN], action.enter)
# verb = self.add_verb(["examine", "x", "read"])
verb = self.add_verb(["examine", "x", "check", "describe", "watch"])
verb.add_action([NOUN_TOKEN], action.examine)
verb = self.add_verb(["exit", "out", "outside"])
verb.add_action([], action.exit_)
verb.add_action([NOUN_TOKEN], action.exit_)
verb = self.add_verb(["fill"])
verb.add_action([NOUN_TOKEN], action.fill)
verb = self.add_verb(["get"])
verb.add_action(["out"], action.exit_)
verb.add_action(["off"], action.exit_)
verb.add_action(["up"], action.exit_)
verb.add_action([MULTI_TOKEN], action.take)
verb.add_action(["in", NOUN_TOKEN], action.enter)
verb.add_action(["into", NOUN_TOKEN], action.enter)
verb.add_action(["on", NOUN_TOKEN], action.enter)
verb.add_action(["onto", NOUN_TOKEN], action.enter)
verb.add_action(["off", NOUN_TOKEN], action.get_off)
verb.add_action([MULTIINSIDE_TOKEN, "from", NOUN_TOKEN], action.remove)
verb = self.add_verb(["give", "feed", "offer", "pay"])
verb.add_action([HELD_TOKEN, "to", CREATURE_TOKEN], action.give)
verb.add_action(["over", HELD_TOKEN, "to", CREATURE_TOKEN], action.give)
verb.add_action([CREATURE_TOKEN, HELD_TOKEN], action.give) # TODO reverse the tokens
verb = self.add_verb(["go", "run", "walk"])
verb.add_action([], action.vague_go)
verb.add_action([(NOUN_TOKEN, self.is_direction)], action.go)
verb = self.add_verb(["inventory", "inv", "i"])
verb.add_action([], action.inventory)
verb = self.add_verb(["look", "l"])
verb.add_action([], action.look)
verb.add_action(["at", NOUN_TOKEN], action.examine)
verb = self.add_verb(["put"])
verb.add_action([HELD_TOKEN, "on", NOUN_TOKEN], action.put_on)
verb.add_action(["on", HELD_TOKEN], action.wear)
verb = self.add_verb(["search"])
verb.add_action([NOUN_TOKEN], action.search)
verb = self.add_verb(["take", "get"])
verb.add_action([NOUN_TOKEN], action.take)
verb.add_action(["off", NOUN_TOKEN], action.disrobe)
verb = self.add_verb(["wear", "don"])
verb.add_action([HELD_TOKEN], action.wear)
# Directions
verb = self.add_verb(["north", "n"])
verb.add_action([], action.go, [self.story.north])
verb = self.add_verb(["east", "e"])
verb.add_action([], action.go, [self.story.east])
verb = self.add_verb(["south", "s"])
verb.add_action([], action.go, [self.story.south])
verb = self.add_verb(["west", "w"])
verb.add_action([], action.go, [self.story.west])
verb = self.add_verb(["northeast", "ne"])
verb.add_action([], action.go, [self.story.northeast])
verb = self.add_verb(["northwest", "nw"])
verb.add_action([], action.go, [self.story.northwest])
verb = self.add_verb(["southeast", "se"])
verb.add_action([], action.go, [self.story.southeast])
verb = self.add_verb(["southwest", "sw"])
verb.add_action([], action.go, [self.story.southwest])
verb = self.add_verb(["up", "u"])
verb.add_action([], action.go, [self.story.up_above])
verb = self.add_verb(["down", "d"])
verb.add_action([], action.go, [self.story.ground])
verb = self.add_verb(["in"])
verb.add_action([], action.go, [self.story.inside])
verb = self.add_verb(["out"])
verb.add_action([], action.go, [self.story.outside])
# Debugging verbs
verb = self.add_verb(["actions"])
verb.add_action([], action.actions)
verb = self.add_verb(["grammar"])
verb.add_action([], action.grammar)
verb = self.add_verb(["messages"])
verb.add_action([], action.messages)
verb = self.add_verb(["tree"])
verb.add_action([], action.tree)
verb = self.add_verb(["dump"])
verb.add_action([NOUN_TOKEN], action.dump)
def add_verb(self, verb_tokens):
verb = Verb(self, verb_tokens)
self.verbs.append(verb)
return verb
def find_verb_matching_token(self, token):
for verb in self.verbs:
if token in verb.verb_tokens:
return verb
return None
def legal_noun_token(self, noun_token):
"Is this noun token legal? Does it exist somewhere in the story?"
n = self.story.root.find(noun_token)
if n:
return True
else:
return False
def is_direction(self):
return True
|
mit
|
[
199,
504,
1275,
492,
1595,
199,
504,
1275,
2087,
492,
4825,
1734,
63,
8803,
12,
869,
23339,
63,
8803,
12,
24895,
41,
63,
8803,
12,
24895,
41,
1645,
6533,
63,
8803,
12,
24895,
41,
11764,
63,
8803,
12,
24895,
41,
10789,
11259,
63,
8803,
12,
32582,
948,
63,
8803,
12,
15654,
13214,
63,
8803,
199,
504,
1275,
1757,
492,
943,
199,
199,
533,
5444,
66,
26,
339,
347,
636,
826,
721,
277,
12,
12528,
12,
16041,
63,
4504,
304,
267,
291,
14,
15239,
275,
12528,
267,
291,
14,
17050,
63,
4504,
275,
16041,
63,
4504,
267,
291,
14,
3723,
275,
942,
339,
347,
1050,
63,
1287,
8,
277,
12,
4645,
12,
1595,
12,
949,
324,
83,
29,
403,
304,
267,
291,
14,
3723,
14,
740,
1332,
4504,
12,
1595,
12,
949,
324,
83,
430,
5493,
347,
2342,
63,
1287,
63,
9467,
63,
4504,
8,
277,
12,
4645,
304,
267,
408,
267,
6668,
376,
1595,
3247,
701,
642,
16041,
626,
4450,
314,
1627,
1526,
3851,
14,
267,
1803,
314,
4877,
1595,
12,
436,
282,
769,
402,
4877,
949,
324,
4645,
14,
267,
408,
398,
367,
282,
315,
291,
14,
3723,
26,
27180,
943,
480,
15735,
7969,
1595,
450,
83,
2,
450,
282,
59,
17,
566,
953,
327,
12078,
314,
1526,
2338,
1336,
31,
288,
340,
822,
8,
4504,
9,
1137,
822,
8,
65,
59,
16,
4682,
355,
1980,
953,
327,
7649,
370,
1336,
314,
4645,
288,
7838,
63,
889,
324,
63,
4504,
275,
942,
288,
1336,
63,
835,
275,
378,
288,
367,
284,
315,
1425,
8,
552,
8,
65,
59,
16,
18710,
1467,
355,
327,
6596,
314,
1526,
5492,
282,
2008,
31,
221,
982,
880,
12,
314,
1526,
730,
355,
327,
365,
314,
1642,
1777,
12,
436,
282,
6420,
2021,
316,
805,
314,
3499,
355,
340,
1228,
8,
65,
59,
16,
1527,
73,
467,
2008,
304,
490,
307,
275,
282,
59,
16,
1527,
73,
1527,
16,
61,
490,
289,
275,
282,
59,
16,
1527,
73,
1527,
17,
61,
355,
587,
26,
490,
307,
275,
282,
59,
16,
1527,
73,
61,
490,
289,
275,
488,
2234,
340,
307,
508,
4825,
1734,
63,
8803,
503,
24895,
41,
63,
8803,
26,
27042,
327,
2136,
787,
21055,
282,
949,
324,
1553,
365,
652,
18393,
31,
490,
943,
480,
2826,
1734,
63,
8803,
531,
490,
340,
291,
14,
15239,
14,
9666,
63,
889,
324,
63,
1418,
8,
4504,
59,
73,
4682,
2151,
717,
327,
6596,
2337,
282,
6420,
2021,
316,
805,
31,
717,
340,
289,
508,
488,
503,
289,
342,
508,
715,
26,
1169,
943,
480,
10151,
949,
324,
1526,
531,
1169,
7838,
63,
889,
324,
63,
4504,
14,
740,
1332,
4504,
59,
73,
467,
307,
430,
1169,
1336,
63,
835,
847,
413,
717,
587,
26,
1169,
943,
480,
889,
324,
1526,
7838,
1325,
6420,
2021,
316,
805,
2138,
756,
531,
2234,
340,
307,
508,
869,
23339,
63,
8803,
26,
27042,
327,
2136,
787,
21055,
282,
949,
324,
1553,
365,
652,
18393,
31,
490,
943,
480,
1645,
6533,
63,
8803,
531,
490,
340,
291,
14,
15239,
14,
9666,
63,
889,
324,
63,
1418,
8,
4504,
59,
73,
4682,
717,
943,
480,
10151,
949,
324,
1526,
531,
717,
7838,
63,
889,
324,
63,
4504,
14,
740,
1332,
4504,
59,
73,
467,
307,
430,
717,
1336,
63,
835,
847,
413,
2234,
916,
307,
508,
4645,
59,
73,
2189,
490,
943,
480,
10151,
26,
450,
83,
2,
450,
307,
9,
490,
1336,
63,
835,
847,
413,
27180,
340,
1336,
63,
835,
508,
822,
8,
65,
59,
16,
4682,
355,
372,
334,
65,
12,
7838,
63,
889,
324,
63,
4504,
9,
10631,
372,
334,
403,
12,
488,
9,
16872,
199,
533,
10268,
9992,
26,
339,
347,
636,
826,
721,
277,
12,
19222,
304,
267,
291,
14,
17372,
275,
19222,
267,
291,
14,
422,
1533,
275,
942,
199,
3,
263,
291,
14,
889,
324,
83,
275,
942,
398,
327,
6288,
13,
422,
1533,
267,
16041,
275,
291,
14,
525,
63,
17050,
5234,
19127,
401,
298,
3302,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
19127,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
3832,
401,
298,
2809,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
3832,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
4792,
19127,
401,
298,
3612,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
4792,
19127,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
10589,
401,
298,
81,
401,
298,
15130,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
10589,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
10506,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
10506,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
8011,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
8011,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
2117,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
2117,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
3397,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
3397,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
1023,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
1023,
9,
398,
327,
25132,
5444,
1533,
267,
16041,
275,
291,
14,
525,
63,
17050,
5234,
5934,
401,
298,
19787,
401,
298,
13927,
337,
401,
298,
31258,
3135,
267,
16041,
14,
525,
63,
1287,
779,
23740,
63,
8803,
12,
298,
475,
401,
15654,
13214,
63,
8803,
467,
1595,
14,
5934,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
813,
3135,
267,
16041,
14,
525,
63,
1287,
779,
5798,
13214,
63,
8803,
12,
298,
10254,
401,
32582,
948,
63,
8803,
467,
1595,
14,
813,
9,
267,
16041,
14,
525,
63,
1287,
779,
5798,
13214,
63,
8803,
12,
298,
509,
401,
4825,
1734,
63,
8803,
467,
1595,
14,
813,
63,
509,
9,
267,
16041,
14,
525,
63,
1287,
779,
5798,
13214,
63,
8803,
12,
298,
475,
401,
32582,
948,
63,
8803,
467,
1595,
14,
813,
63,
475,
9,
267,
16041,
14,
525,
63,
1287,
5234,
9099,
401,
15654,
13214,
63,
8803,
12,
32582,
948,
63,
8803,
467,
1595,
14,
813,
63,
475,
9,
398,
16041,
275,
291,
14,
525
] |
[
504,
1275,
492,
1595,
199,
504,
1275,
2087,
492,
4825,
1734,
63,
8803,
12,
869,
23339,
63,
8803,
12,
24895,
41,
63,
8803,
12,
24895,
41,
1645,
6533,
63,
8803,
12,
24895,
41,
11764,
63,
8803,
12,
24895,
41,
10789,
11259,
63,
8803,
12,
32582,
948,
63,
8803,
12,
15654,
13214,
63,
8803,
199,
504,
1275,
1757,
492,
943,
199,
199,
533,
5444,
66,
26,
339,
347,
636,
826,
721,
277,
12,
12528,
12,
16041,
63,
4504,
304,
267,
291,
14,
15239,
275,
12528,
267,
291,
14,
17050,
63,
4504,
275,
16041,
63,
4504,
267,
291,
14,
3723,
275,
942,
339,
347,
1050,
63,
1287,
8,
277,
12,
4645,
12,
1595,
12,
949,
324,
83,
29,
403,
304,
267,
291,
14,
3723,
14,
740,
1332,
4504,
12,
1595,
12,
949,
324,
83,
430,
5493,
347,
2342,
63,
1287,
63,
9467,
63,
4504,
8,
277,
12,
4645,
304,
267,
408,
267,
6668,
376,
1595,
3247,
701,
642,
16041,
626,
4450,
314,
1627,
1526,
3851,
14,
267,
1803,
314,
4877,
1595,
12,
436,
282,
769,
402,
4877,
949,
324,
4645,
14,
267,
408,
398,
367,
282,
315,
291,
14,
3723,
26,
27180,
943,
480,
15735,
7969,
1595,
450,
83,
2,
450,
282,
59,
17,
566,
953,
327,
12078,
314,
1526,
2338,
1336,
31,
288,
340,
822,
8,
4504,
9,
1137,
822,
8,
65,
59,
16,
4682,
355,
1980,
953,
327,
7649,
370,
1336,
314,
4645,
288,
7838,
63,
889,
324,
63,
4504,
275,
942,
288,
1336,
63,
835,
275,
378,
288,
367,
284,
315,
1425,
8,
552,
8,
65,
59,
16,
18710,
1467,
355,
327,
6596,
314,
1526,
5492,
282,
2008,
31,
221,
982,
880,
12,
314,
1526,
730,
355,
327,
365,
314,
1642,
1777,
12,
436,
282,
6420,
2021,
316,
805,
314,
3499,
355,
340,
1228,
8,
65,
59,
16,
1527,
73,
467,
2008,
304,
490,
307,
275,
282,
59,
16,
1527,
73,
1527,
16,
61,
490,
289,
275,
282,
59,
16,
1527,
73,
1527,
17,
61,
355,
587,
26,
490,
307,
275,
282,
59,
16,
1527,
73,
61,
490,
289,
275,
488,
2234,
340,
307,
508,
4825,
1734,
63,
8803,
503,
24895,
41,
63,
8803,
26,
27042,
327,
2136,
787,
21055,
282,
949,
324,
1553,
365,
652,
18393,
31,
490,
943,
480,
2826,
1734,
63,
8803,
531,
490,
340,
291,
14,
15239,
14,
9666,
63,
889,
324,
63,
1418,
8,
4504,
59,
73,
4682,
2151,
717,
327,
6596,
2337,
282,
6420,
2021,
316,
805,
31,
717,
340,
289,
508,
488,
503,
289,
342,
508,
715,
26,
1169,
943,
480,
10151,
949,
324,
1526,
531,
1169,
7838,
63,
889,
324,
63,
4504,
14,
740,
1332,
4504,
59,
73,
467,
307,
430,
1169,
1336,
63,
835,
847,
413,
717,
587,
26,
1169,
943,
480,
889,
324,
1526,
7838,
1325,
6420,
2021,
316,
805,
2138,
756,
531,
2234,
340,
307,
508,
869,
23339,
63,
8803,
26,
27042,
327,
2136,
787,
21055,
282,
949,
324,
1553,
365,
652,
18393,
31,
490,
943,
480,
1645,
6533,
63,
8803,
531,
490,
340,
291,
14,
15239,
14,
9666,
63,
889,
324,
63,
1418,
8,
4504,
59,
73,
4682,
717,
943,
480,
10151,
949,
324,
1526,
531,
717,
7838,
63,
889,
324,
63,
4504,
14,
740,
1332,
4504,
59,
73,
467,
307,
430,
717,
1336,
63,
835,
847,
413,
2234,
916,
307,
508,
4645,
59,
73,
2189,
490,
943,
480,
10151,
26,
450,
83,
2,
450,
307,
9,
490,
1336,
63,
835,
847,
413,
27180,
340,
1336,
63,
835,
508,
822,
8,
65,
59,
16,
4682,
355,
372,
334,
65,
12,
7838,
63,
889,
324,
63,
4504,
9,
10631,
372,
334,
403,
12,
488,
9,
16872,
199,
533,
10268,
9992,
26,
339,
347,
636,
826,
721,
277,
12,
19222,
304,
267,
291,
14,
17372,
275,
19222,
267,
291,
14,
422,
1533,
275,
942,
199,
3,
263,
291,
14,
889,
324,
83,
275,
942,
398,
327,
6288,
13,
422,
1533,
267,
16041,
275,
291,
14,
525,
63,
17050,
5234,
19127,
401,
298,
3302,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
19127,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
3832,
401,
298,
2809,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
3832,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
4792,
19127,
401,
298,
3612,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
4792,
19127,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
10589,
401,
298,
81,
401,
298,
15130,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
10589,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
10506,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
10506,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
8011,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
8011,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
2117,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
2117,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
3397,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
3397,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
1023,
3135,
267,
16041,
14,
525,
63,
1287,
8798,
1595,
14,
1023,
9,
398,
327,
25132,
5444,
1533,
267,
16041,
275,
291,
14,
525,
63,
17050,
5234,
5934,
401,
298,
19787,
401,
298,
13927,
337,
401,
298,
31258,
3135,
267,
16041,
14,
525,
63,
1287,
779,
23740,
63,
8803,
12,
298,
475,
401,
15654,
13214,
63,
8803,
467,
1595,
14,
5934,
9,
398,
16041,
275,
291,
14,
525,
63,
17050,
5234,
813,
3135,
267,
16041,
14,
525,
63,
1287,
779,
5798,
13214,
63,
8803,
12,
298,
10254,
401,
32582,
948,
63,
8803,
467,
1595,
14,
813,
9,
267,
16041,
14,
525,
63,
1287,
779,
5798,
13214,
63,
8803,
12,
298,
509,
401,
4825,
1734,
63,
8803,
467,
1595,
14,
813,
63,
509,
9,
267,
16041,
14,
525,
63,
1287,
779,
5798,
13214,
63,
8803,
12,
298,
475,
401,
32582,
948,
63,
8803,
467,
1595,
14,
813,
63,
475,
9,
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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
] |
kochbeck/icsisumm
|
icsisumm-primary-sys34_v1/nltk/nltk-0.9.2/nltk_contrib/classifier/autoclass.py
|
9
|
1327
|
# Natural Language Toolkit - AutoClass
# automatic class value generator
#
# Author: Sumukh Ghodke <sumukh dot ghodke at gmail dot com>
#
# URL: <http://nltk.sf.net>
# This software is distributed under GPL, for license information see LICENSE.TXT
class AutoClass:
def __init__(self, name):
self.name = name
def next(self):
base26 = self.base26()
base26 += 1
return AutoClass(string(base26))
def base26(self):
base26 = 0
length = len(self.name)
for index in range(length):
numeric = ord(self.name[index]) - 97
if (index == length - 1): base26 += numeric
else: base26 += numeric * 26 * (length - index - 1)
return base26
def __eq__(self, other):
if other is None: return False
if self.__class__ != other.__class__: return False
if self.name == other.name: return True
return False
def __hash__(self):
if self.name == None: return id(self)
return 3 * self.name + 7
def __str__(self):
return self.name
FIRST = AutoClass('a')
def string(base26):
strn = ''
while (base26 /26 > 0):
strn = chr((base26 % 26) + 97) + strn
base26 = base26 / 26
strn = chr((base26 % 26) + 97) + strn
return strn
|
gpl-3.0
|
[
3,
653,
292,
4889,
8466,
15650,
6065,
446,
9195,
2543,
199,
3,
221,
4834,
1021,
574,
4306,
199,
3,
199,
3,
6529,
26,
12094,
3210,
72,
598,
72,
364,
415,
665,
1838,
3210,
72,
6308,
23310,
364,
415,
737,
29712,
6308,
2414,
30,
199,
3,
199,
3,
2851,
26,
665,
1014,
921,
7530,
2663,
14,
7646,
14,
846,
30,
199,
3,
961,
2032,
365,
1854,
1334,
14629,
12,
367,
4190,
2556,
1937,
5113,
14,
17715,
199,
199,
533,
9195,
2543,
26,
272,
347,
636,
826,
721,
277,
12,
536,
304,
267,
291,
14,
354,
275,
536,
5493,
347,
2163,
8,
277,
304,
267,
1300,
1479,
275,
291,
14,
1095,
1479,
342,
267,
1300,
1479,
847,
413,
267,
372,
9195,
2543,
8,
875,
8,
1095,
1479,
430,
339,
347,
1300,
1479,
8,
277,
304,
267,
1300,
1479,
275,
378,
267,
2582,
275,
822,
8,
277,
14,
354,
9,
267,
367,
1478,
315,
1425,
8,
1267,
304,
288,
8950,
275,
6206,
8,
277,
14,
354,
59,
1080,
566,
446,
15997,
288,
340,
334,
1080,
508,
2582,
446,
413,
304,
1300,
1479,
847,
8950,
288,
587,
26,
1300,
1479,
847,
8950,
627,
7875,
627,
334,
1267,
446,
1478,
446,
413,
9,
267,
372,
1300,
1479,
2286,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
340,
1163,
365,
488,
26,
372,
756,
267,
340,
291,
855,
533,
363,
1137,
1163,
855,
533,
10651,
372,
756,
267,
340,
291,
14,
354,
508,
1163,
14,
354,
26,
372,
715,
267,
372,
756,
2286,
347,
636,
2227,
721,
277,
304,
267,
340,
291,
14,
354,
508,
488,
26,
372,
1305,
8,
277,
9,
267,
372,
650,
627,
291,
14,
354,
435,
1520,
221,
2286,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
199,
199,
12903,
275,
9195,
2543,
360,
65,
358,
199,
199,
318,
1059,
8,
1095,
1479,
304,
272,
620,
78,
275,
2125,
272,
1830,
334,
1095,
1479,
1182,
1479,
690,
378,
304,
267,
620,
78,
275,
8678,
1332,
1095,
1479,
450,
7875,
9,
435,
15997,
9,
435,
620,
78,
267,
1300,
1479,
275,
1300,
1479,
1182,
7875,
272,
620,
78,
275,
8678,
1332,
1095,
1479,
450,
7875,
9,
435,
15997,
9,
435,
620,
78,
272,
372,
620,
78,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
653,
292,
4889,
8466,
15650,
6065,
446,
9195,
2543,
199,
3,
221,
4834,
1021,
574,
4306,
199,
3,
199,
3,
6529,
26,
12094,
3210,
72,
598,
72,
364,
415,
665,
1838,
3210,
72,
6308,
23310,
364,
415,
737,
29712,
6308,
2414,
30,
199,
3,
199,
3,
2851,
26,
665,
1014,
921,
7530,
2663,
14,
7646,
14,
846,
30,
199,
3,
961,
2032,
365,
1854,
1334,
14629,
12,
367,
4190,
2556,
1937,
5113,
14,
17715,
199,
199,
533,
9195,
2543,
26,
272,
347,
636,
826,
721,
277,
12,
536,
304,
267,
291,
14,
354,
275,
536,
5493,
347,
2163,
8,
277,
304,
267,
1300,
1479,
275,
291,
14,
1095,
1479,
342,
267,
1300,
1479,
847,
413,
267,
372,
9195,
2543,
8,
875,
8,
1095,
1479,
430,
339,
347,
1300,
1479,
8,
277,
304,
267,
1300,
1479,
275,
378,
267,
2582,
275,
822,
8,
277,
14,
354,
9,
267,
367,
1478,
315,
1425,
8,
1267,
304,
288,
8950,
275,
6206,
8,
277,
14,
354,
59,
1080,
566,
446,
15997,
288,
340,
334,
1080,
508,
2582,
446,
413,
304,
1300,
1479,
847,
8950,
288,
587,
26,
1300,
1479,
847,
8950,
627,
7875,
627,
334,
1267,
446,
1478,
446,
413,
9,
267,
372,
1300,
1479,
2286,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
340,
1163,
365,
488,
26,
372,
756,
267,
340,
291,
855,
533,
363,
1137,
1163,
855,
533,
10651,
372,
756,
267,
340,
291,
14,
354,
508,
1163,
14,
354,
26,
372,
715,
267,
372,
756,
2286,
347,
636,
2227,
721,
277,
304,
267,
340,
291,
14,
354,
508,
488,
26,
372,
1305,
8,
277,
9,
267,
372,
650,
627,
291,
14,
354,
435,
1520,
221,
2286,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
199,
199,
12903,
275,
9195,
2543,
360,
65,
358,
199,
199,
318,
1059,
8,
1095,
1479,
304,
272,
620,
78,
275,
2125,
272,
1830,
334,
1095,
1479,
1182,
1479,
690,
378,
304,
267,
620,
78,
275,
8678,
1332,
1095,
1479,
450,
7875,
9,
435,
15997,
9,
435,
620,
78,
267,
1300,
1479,
275,
1300,
1479,
1182,
7875,
272,
620,
78,
275,
8678,
1332,
1095,
1479,
450,
7875,
9,
435,
15997,
9,
435,
620,
78,
272,
372,
620,
78,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
OleLL/Lacourdeshit
|
login.py
|
1
|
1600
|
def login_user(username, password):
"""
This method tries to login a user, if it has success, it will return a json
with information about username availability and password availability and
a json with all cookies, if password and username were correct, these cookies
can be used to make more interaction with the API.
:param username: The username of the instagram account
:param password: The password of the instagram account
:return:
"""
data = { # Defining http post data
"username": username,
"password": password
}
headers = { # Defining necessary headers
"x-csrftoken": csrf,
"referer": "https://www.instagram.com/",
}
cookies = { # Defining necessary cookie(s)
"csrftoken": csrf,
}
req = requests.post( # Posting everything to www.instagram.com/accounts/login/ajax/
"https://www.instagram.com/accounts/login/ajax/",
data=data,
headers=headers,
cookies=cookies
)
if req.status_code == 200: # Checking if the request got a 200 ("ok")
js = json.loads(req.text)
new = { # Creating a new, more plausible json
"valid_username": js["user"],
"valid_password": js["authenticated"]
}
if js["status"] == "ok": # checking status in old json
cookies = {}
for cookie in req.cookies:
cookies.update({cookie.name: cookie.value})
return new, cookies
else:
return False
else:
print req.text
return False
|
unlicense
|
[
318,
4676,
63,
751,
8,
2473,
12,
2505,
304,
272,
408,
272,
961,
1083,
11275,
370,
4676,
282,
922,
12,
340,
652,
965,
3182,
12,
652,
911,
372,
282,
2022,
272,
543,
2556,
3595,
3434,
14962,
436,
2505,
14962,
436,
272,
282,
2022,
543,
1006,
10049,
12,
340,
2505,
436,
3434,
4898,
3211,
12,
3520,
10049,
272,
883,
506,
1202,
370,
1852,
1655,
18752,
543,
314,
3261,
14,
272,
520,
635,
3434,
26,
710,
3434,
402,
314,
2727,
32208,
2933,
272,
520,
635,
2505,
26,
710,
2505,
402,
314,
2727,
32208,
2933,
272,
520,
1107,
26,
272,
408,
272,
666,
275,
469,
221,
327,
1487,
2408,
316,
1455,
2963,
666,
267,
298,
2473,
582,
3434,
12,
267,
298,
2060,
582,
2505,
272,
789,
339,
2323,
275,
469,
221,
327,
1487,
2408,
316,
5784,
2323,
267,
298,
88,
13,
10088,
1418,
582,
19213,
12,
267,
298,
20996,
582,
298,
2859,
921,
1544,
14,
3615,
32208,
14,
957,
10665,
339,
789,
339,
10049,
275,
469,
221,
327,
1487,
2408,
316,
5784,
5494,
8,
83,
9,
267,
298,
10088,
1418,
582,
19213,
12,
272,
789,
339,
2648,
275,
4145,
14,
1932,
8,
221,
327,
7711,
316,
8137,
370,
20732,
14,
3615,
32208,
14,
957,
15,
8370,
15,
2886,
15,
12774,
15,
267,
298,
2859,
921,
1544,
14,
3615,
32208,
14,
957,
15,
8370,
15,
2886,
15,
12774,
10665,
267,
666,
29,
576,
12,
267,
2323,
29,
2139,
12,
267,
10049,
29,
7792,
272,
776,
339,
340,
2648,
14,
1205,
63,
600,
508,
1926,
26,
221,
327,
25109,
340,
314,
1056,
4788,
282,
1926,
1689,
745,
531,
267,
8586,
275,
2022,
14,
3640,
8,
2103,
14,
505,
9,
267,
892,
275,
469,
221,
327,
20507,
282,
892,
12,
1655,
299,
416,
85,
1164,
2022,
288,
298,
1078,
63,
2473,
582,
8586,
905,
751,
2255,
288,
298,
1078,
63,
2060,
582,
8586,
905,
12177,
937,
267,
789,
267,
340,
8586,
905,
1205,
937,
508,
298,
745,
582,
221,
327,
7907,
2004,
315,
2269,
2022,
288,
10049,
275,
1052,
288,
367,
5494,
315,
2648,
14,
7792,
26,
355,
10049,
14,
873,
2561,
5306,
14,
354,
26,
5494,
14,
585,
1552,
288,
372,
892,
12,
10049,
267,
587,
26,
288,
372,
756,
272,
587,
26,
267,
870,
2648,
14,
505,
267,
372,
756,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4676,
63,
751,
8,
2473,
12,
2505,
304,
272,
408,
272,
961,
1083,
11275,
370,
4676,
282,
922,
12,
340,
652,
965,
3182,
12,
652,
911,
372,
282,
2022,
272,
543,
2556,
3595,
3434,
14962,
436,
2505,
14962,
436,
272,
282,
2022,
543,
1006,
10049,
12,
340,
2505,
436,
3434,
4898,
3211,
12,
3520,
10049,
272,
883,
506,
1202,
370,
1852,
1655,
18752,
543,
314,
3261,
14,
272,
520,
635,
3434,
26,
710,
3434,
402,
314,
2727,
32208,
2933,
272,
520,
635,
2505,
26,
710,
2505,
402,
314,
2727,
32208,
2933,
272,
520,
1107,
26,
272,
408,
272,
666,
275,
469,
221,
327,
1487,
2408,
316,
1455,
2963,
666,
267,
298,
2473,
582,
3434,
12,
267,
298,
2060,
582,
2505,
272,
789,
339,
2323,
275,
469,
221,
327,
1487,
2408,
316,
5784,
2323,
267,
298,
88,
13,
10088,
1418,
582,
19213,
12,
267,
298,
20996,
582,
298,
2859,
921,
1544,
14,
3615,
32208,
14,
957,
10665,
339,
789,
339,
10049,
275,
469,
221,
327,
1487,
2408,
316,
5784,
5494,
8,
83,
9,
267,
298,
10088,
1418,
582,
19213,
12,
272,
789,
339,
2648,
275,
4145,
14,
1932,
8,
221,
327,
7711,
316,
8137,
370,
20732,
14,
3615,
32208,
14,
957,
15,
8370,
15,
2886,
15,
12774,
15,
267,
298,
2859,
921,
1544,
14,
3615,
32208,
14,
957,
15,
8370,
15,
2886,
15,
12774,
10665,
267,
666,
29,
576,
12,
267,
2323,
29,
2139,
12,
267,
10049,
29,
7792,
272,
776,
339,
340,
2648,
14,
1205,
63,
600,
508,
1926,
26,
221,
327,
25109,
340,
314,
1056,
4788,
282,
1926,
1689,
745,
531,
267,
8586,
275,
2022,
14,
3640,
8,
2103,
14,
505,
9,
267,
892,
275,
469,
221,
327,
20507,
282,
892,
12,
1655,
299,
416,
85,
1164,
2022,
288,
298,
1078,
63,
2473,
582,
8586,
905,
751,
2255,
288,
298,
1078,
63,
2060,
582,
8586,
905,
12177,
937,
267,
789,
267,
340,
8586,
905,
1205,
937,
508,
298,
745,
582,
221,
327,
7907,
2004,
315,
2269,
2022,
288,
10049,
275,
1052,
288,
367,
5494,
315,
2648,
14,
7792,
26,
355,
10049,
14,
873,
2561,
5306,
14,
354,
26,
5494,
14,
585,
1552,
288,
372,
892,
12,
10049,
267,
587,
26,
288,
372,
756,
272,
587,
26,
267,
870,
2648,
14,
505,
267,
372,
756,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
saymedia/python-danga-gearman
|
dangagearman/task.py
|
2
|
4342
|
import random
import uuid
# Constant that indicates to gearmand the task should be interpeted as unique iff the arg matches.
UNIQ_DATA_CHAR = '-'
class Task(object):
hooks = ('on_complete', 'on_fail', 'on_retry', 'on_status', 'on_post')
def __init__(self, func, arg, uniq=None, background=False, high_priority=False,
timeout=None, retry_count=0, **kwargs):
"""Build a task
Arguments
func - (string) Name of the function this task should execute
arg - (string) Arguments to the function
uniq - How should this Task be collated together on the remote side ?
None - (default) all tasks are unique
True - Task should be treated as unique based on the data
False - All tasks of the same function should be collated together
<string> - All tasks of this name should be collated together
Really only applies to background tasks.
background - (bool) Indicates the task should be executed in the background and the client should return right away.
high_priority - (bool) Put into high priority queue (only useful if some tasks of this functiona are not)
timeout - (integer, seconds) How long should we wait for the task to complete
retry_count - (integer) How many times to retry the task after failing.
"""
for hook in self.hooks:
setattr(self, hook, hook in kwargs and [kwargs[hook]] or [])
self.func = func
self.arg = arg
self.background = background
self.high_priority = high_priority
self.timeout = timeout
self.retry_count = retry_count
if uniq is None:
self.uniq = uuid.uuid1().hex
elif uniq is True:
self.uniq = UNIQ_DATA_CHAR
elif uniq is False:
self.uniq = None
else:
self.uniq = uniq
self.retries_done = 0
self.is_finished = False
self.handle = None
self.result = None
self._hash = hash(self.func + ((self.uniq == UNIQ_DATA_CHAR and self.arg) or self.uniq or str(random.randint(0, 999999))))
def __hash__(self):
return self._hash
def merge_hooks(self, task2):
for hook in self.hooks:
getattr(self, hook).extend(getattr(task2, hook))
def complete(self, result):
"""Mark the job as completed and call on_complete hooks."""
self.result = result
for func in self.on_complete:
func(result)
self._finished()
def fail(self):
"""Mark the job as failed and call on_fail hooks."""
for func in self.on_fail:
func()
self._finished()
def status(self, numerator, denominator):
"""Call on_status hooks"""
for func in self.on_status:
func(numerator, denominator)
def retrying(self):
"""Call on_retry hooks"""
for func in self.on_retry:
func()
def _finished(self):
"""Mark the job as finished and call on_post hooks."""
self.is_finished = True
for func in self.on_post:
func()
for hook in self.hooks:
delattr(self, hook) # TODO: perhaps should just clear the lists?
def __repr__(self):
return "<Task func='%s'>" % self.func
class Taskset(dict):
"""
A Taskset is a group of tasks that are to be run all at once. The
benefit of using a Taskset is allowing multiple tasks to run
in parallel.
"""
def __init__(self, tasks=[]):
super(Taskset, self).__init__((hash(t), t) for t in tasks)
self.cancelled = False
def add(self, task):
self[hash(task)] = task
def add_task(self, *args, **kwargs):
self.add(Task(*args, **kwargs))
def cancel(self):
self.cancelled = True
def __or__(self, taskset2):
for task_hash, task in taskset2.iteritems():
if task_hash in self:
self[task_hash].merge_hooks(task)
else:
self[task_hash] = task # TODO: should clone the task rather than just making a reference
return self
|
mit
|
[
646,
2196,
199,
646,
5377,
199,
199,
3,
19991,
626,
9126,
370,
2312,
5362,
460,
314,
2120,
1077,
506,
1640,
321,
471,
465,
3747,
17963,
314,
1680,
4450,
14,
199,
15134,
49,
63,
3998,
63,
5901,
275,
10791,
199,
199,
533,
8495,
8,
785,
304,
272,
12604,
275,
661,
265,
63,
4883,
297,
283,
265,
63,
1633,
297,
283,
265,
63,
7154,
297,
283,
265,
63,
1205,
297,
283,
265,
63,
1932,
358,
339,
347,
636,
826,
721,
277,
12,
2562,
12,
1680,
12,
625,
9962,
29,
403,
12,
8020,
29,
797,
12,
4721,
63,
6693,
29,
797,
12,
326,
2653,
29,
403,
12,
7269,
63,
835,
29,
16,
12,
1011,
958,
304,
267,
408,
3425,
282,
2120,
27180,
7628,
355,
2562,
446,
334,
875,
9,
2812,
402,
314,
805,
642,
2120,
1077,
5341,
355,
1680,
446,
334,
875,
9,
7628,
370,
314,
805,
355,
625,
9962,
446,
7494,
1077,
642,
8495,
506,
1048,
1776,
10451,
641,
314,
3982,
5366,
5805,
717,
488,
446,
334,
885,
9,
1006,
6527,
787,
3747,
717,
715,
446,
8495,
1077,
506,
10184,
465,
3747,
4079,
641,
314,
666,
717,
756,
446,
2900,
6527,
402,
314,
2011,
805,
1077,
506,
1048,
1776,
10451,
717,
665,
875,
30,
446,
2900,
6527,
402,
642,
536,
1077,
506,
1048,
1776,
10451,
1993,
799,
1183,
1454,
12966,
370,
8020,
6527,
14,
355,
8020,
446,
334,
2245,
9,
19334,
314,
2120,
1077,
506,
7934,
315,
314,
8020,
436,
314,
1890,
1077,
372,
2451,
13437,
14,
355,
4721,
63,
6693,
446,
334,
2245,
9,
16280,
1901,
4721,
7464,
4126,
334,
2118,
2997,
340,
2005,
6527,
402,
642,
805,
65,
787,
440,
9,
355,
2653,
446,
334,
4115,
12,
4696,
9,
7494,
1846,
1077,
781,
3618,
367,
314,
2120,
370,
4890,
355,
7269,
63,
835,
446,
334,
4115,
9,
7494,
5002,
5431,
370,
7269,
314,
2120,
2410,
18648,
14,
267,
408,
267,
367,
5759,
315,
291,
14,
7922,
26,
288,
5371,
8,
277,
12,
5759,
12,
5759,
315,
2074,
436,
359,
958,
59,
3664,
2677,
503,
3073,
398,
291,
14,
1532,
3515,
275,
2562,
267,
291,
14,
1273,
3698,
275,
1680,
267,
291,
14,
7451,
259,
275,
8020,
267,
291,
14,
6260,
63,
6693,
275,
4721,
63,
6693,
267,
291,
14,
2593,
755,
275,
2653,
267,
291,
14,
7154,
63,
835,
257,
275,
7269,
63,
835,
398,
340,
625,
9962,
365,
488,
26,
288,
291,
14,
22484,
275,
5377,
14,
2580,
17,
1252,
4097,
267,
916,
625,
9962,
365,
715,
26,
288,
291,
14,
22484,
275,
6778,
23559,
63,
3998,
63,
5901,
267,
916,
625,
9962,
365,
756,
26,
288,
291,
14,
22484,
275,
488,
267,
587,
26,
288,
291,
14,
22484,
275,
625,
9962,
398,
291,
14,
10937,
63,
4456,
275,
378,
267,
291,
14,
374,
63,
8669,
221,
275,
756,
267,
291,
14,
2479,
755,
275,
488,
267,
291,
14,
1099,
755,
275,
488,
267,
291,
423,
2227,
263,
275,
2631,
8,
277,
14,
1532,
435,
3666,
277,
14,
22484,
508,
6778,
23559,
63,
3998,
63,
5901,
436,
291,
14,
1273,
9,
503,
291,
14,
22484,
503,
620,
8,
2355,
14,
8393,
8,
16,
12,
221,
20036,
7845,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
291,
423,
2227,
339,
347,
5389,
63,
7922,
8,
277,
12,
2120,
18,
304,
267,
367,
5759,
315,
291,
14,
7922,
26,
288,
2519,
8,
277,
12,
5759,
680,
2880,
8,
5675,
8,
1765,
18,
12,
5759,
430,
339,
347,
4890,
8,
277,
12,
754,
304,
267,
408,
6470,
314,
3906,
465,
9709,
436,
1240,
641,
63,
4883,
12604,
1041,
267,
291,
14,
1099,
275,
754,
267,
367,
2562,
315,
291,
14,
265,
63,
4883,
26,
288,
2562,
8,
1099,
9,
267,
291,
423,
8669,
342,
339,
347,
2449,
8,
277,
304,
267,
408,
6470,
314,
3906,
465,
3405,
436,
1240,
641,
63,
1633,
12604,
1041,
267,
367,
2562,
315,
291,
14,
265,
63,
1633,
26,
288,
2562,
342,
267,
291,
423,
8669,
342,
339,
347,
2004,
8,
277,
12,
27640,
12,
21859,
304,
267,
408,
2176,
641,
63,
1205,
12604,
624,
267,
367,
2562,
315,
291,
14,
265,
63,
1205,
26,
288,
2562,
8,
19398,
12,
21859,
9,
339,
347,
7269,
316,
8,
277,
304,
267,
408,
2176,
641,
63,
7154,
12604,
624,
267,
367,
2562,
315,
291,
14,
265,
63,
7154,
26,
288,
2562,
342,
339,
347,
485,
8669,
8,
277,
304,
267,
408,
6470,
314,
3906,
465,
9158,
436,
1240,
641,
63,
1932,
12604,
1041,
267,
291,
14,
374,
63,
8669,
275,
715,
267,
367,
2562,
315,
291,
14,
265,
63,
1932,
26,
288,
2562,
342,
267,
367,
5759,
315,
291,
14,
7922,
26,
288,
24358,
8,
277,
12,
5759,
9,
327,
3254,
26,
25358,
1077,
2951,
5436,
314,
5548,
31,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3886,
4476,
2562,
9569,
83,
7,
4335,
450,
291,
14,
1532,
199,
199,
533,
8495,
409,
8,
807,
304,
272,
408,
272,
437,
8495,
409,
365,
282,
1572,
402,
6527,
626,
787,
370,
506,
1255,
1006,
737,
5403,
14,
710,
272,
22477,
3269,
402,
1808,
282,
8495,
409,
365,
17266,
3663,
6527,
370,
1255,
272,
315,
9861,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
6527,
17894,
267,
1613,
8,
4476,
409,
12,
291,
2843,
826,
721,
8,
2227,
8,
84,
395,
307,
9,
367,
307,
315,
6527,
9,
267,
291,
14,
21924,
275,
756,
339,
347,
1050,
8,
277,
12,
2120,
304,
267,
291,
59,
2227,
8,
1765,
1874,
275,
2120,
339,
347,
1050,
63,
1765,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
525,
8,
4476,
2031,
589,
12,
1011,
958,
430,
339,
347,
9311,
8,
277,
304,
267,
291,
14,
21924,
275,
715,
339,
347,
636,
269,
721,
277,
12,
2120,
409,
18,
304,
267,
367,
2120,
63,
2227,
12,
2120,
315,
2120,
409,
18,
14,
4611,
837,
288,
340,
2120,
63,
2227,
315,
291,
26,
355,
291,
59,
1765,
63,
2227,
1055,
5628,
63,
7922,
8,
1765,
9,
288,
587,
26,
355,
291,
59,
1765,
63,
2227,
61,
275,
2120,
327,
3254,
26,
1077,
7289,
314,
2120,
7830,
2419,
2951,
10663,
282,
3659,
267,
372,
291,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2196,
199,
646,
5377,
199,
199,
3,
19991,
626,
9126,
370,
2312,
5362,
460,
314,
2120,
1077,
506,
1640,
321,
471,
465,
3747,
17963,
314,
1680,
4450,
14,
199,
15134,
49,
63,
3998,
63,
5901,
275,
10791,
199,
199,
533,
8495,
8,
785,
304,
272,
12604,
275,
661,
265,
63,
4883,
297,
283,
265,
63,
1633,
297,
283,
265,
63,
7154,
297,
283,
265,
63,
1205,
297,
283,
265,
63,
1932,
358,
339,
347,
636,
826,
721,
277,
12,
2562,
12,
1680,
12,
625,
9962,
29,
403,
12,
8020,
29,
797,
12,
4721,
63,
6693,
29,
797,
12,
326,
2653,
29,
403,
12,
7269,
63,
835,
29,
16,
12,
1011,
958,
304,
267,
408,
3425,
282,
2120,
27180,
7628,
355,
2562,
446,
334,
875,
9,
2812,
402,
314,
805,
642,
2120,
1077,
5341,
355,
1680,
446,
334,
875,
9,
7628,
370,
314,
805,
355,
625,
9962,
446,
7494,
1077,
642,
8495,
506,
1048,
1776,
10451,
641,
314,
3982,
5366,
5805,
717,
488,
446,
334,
885,
9,
1006,
6527,
787,
3747,
717,
715,
446,
8495,
1077,
506,
10184,
465,
3747,
4079,
641,
314,
666,
717,
756,
446,
2900,
6527,
402,
314,
2011,
805,
1077,
506,
1048,
1776,
10451,
717,
665,
875,
30,
446,
2900,
6527,
402,
642,
536,
1077,
506,
1048,
1776,
10451,
1993,
799,
1183,
1454,
12966,
370,
8020,
6527,
14,
355,
8020,
446,
334,
2245,
9,
19334,
314,
2120,
1077,
506,
7934,
315,
314,
8020,
436,
314,
1890,
1077,
372,
2451,
13437,
14,
355,
4721,
63,
6693,
446,
334,
2245,
9,
16280,
1901,
4721,
7464,
4126,
334,
2118,
2997,
340,
2005,
6527,
402,
642,
805,
65,
787,
440,
9,
355,
2653,
446,
334,
4115,
12,
4696,
9,
7494,
1846,
1077,
781,
3618,
367,
314,
2120,
370,
4890,
355,
7269,
63,
835,
446,
334,
4115,
9,
7494,
5002,
5431,
370,
7269,
314,
2120,
2410,
18648,
14,
267,
408,
267,
367,
5759,
315,
291,
14,
7922,
26,
288,
5371,
8,
277,
12,
5759,
12,
5759,
315,
2074,
436,
359,
958,
59,
3664,
2677,
503,
3073,
398,
291,
14,
1532,
3515,
275,
2562,
267,
291,
14,
1273,
3698,
275,
1680,
267,
291,
14,
7451,
259,
275,
8020,
267,
291,
14,
6260,
63,
6693,
275,
4721,
63,
6693,
267,
291,
14,
2593,
755,
275,
2653,
267,
291,
14,
7154,
63,
835,
257,
275,
7269,
63,
835,
398,
340,
625,
9962,
365,
488,
26,
288,
291,
14,
22484,
275,
5377,
14,
2580,
17,
1252,
4097,
267,
916,
625,
9962,
365,
715,
26,
288,
291,
14,
22484,
275,
6778,
23559,
63,
3998,
63,
5901,
267,
916,
625,
9962,
365,
756,
26,
288,
291,
14,
22484,
275,
488,
267,
587,
26,
288,
291,
14,
22484,
275,
625,
9962,
398,
291,
14,
10937,
63,
4456,
275,
378,
267,
291,
14,
374,
63,
8669,
221,
275,
756,
267,
291,
14,
2479,
755,
275,
488,
267,
291,
14,
1099,
755,
275,
488,
267,
291,
423,
2227,
263,
275,
2631,
8,
277,
14,
1532,
435,
3666,
277,
14,
22484,
508,
6778,
23559,
63,
3998,
63,
5901,
436,
291,
14,
1273,
9,
503,
291,
14,
22484,
503,
620,
8,
2355,
14,
8393,
8,
16,
12,
221,
20036,
7845,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
291,
423,
2227,
339,
347,
5389,
63,
7922,
8,
277,
12,
2120,
18,
304,
267,
367,
5759,
315,
291,
14,
7922,
26,
288,
2519,
8,
277,
12,
5759,
680,
2880,
8,
5675,
8,
1765,
18,
12,
5759,
430,
339,
347,
4890,
8,
277,
12,
754,
304,
267,
408,
6470,
314,
3906,
465,
9709,
436,
1240,
641,
63,
4883,
12604,
1041,
267,
291,
14,
1099,
275,
754,
267,
367,
2562,
315,
291,
14,
265,
63,
4883,
26,
288,
2562,
8,
1099,
9,
267,
291,
423,
8669,
342,
339,
347,
2449,
8,
277,
304,
267,
408,
6470,
314,
3906,
465,
3405,
436,
1240,
641,
63,
1633,
12604,
1041,
267,
367,
2562,
315,
291,
14,
265,
63,
1633,
26,
288,
2562,
342,
267,
291,
423,
8669,
342,
339,
347,
2004,
8,
277,
12,
27640,
12,
21859,
304,
267,
408,
2176,
641,
63,
1205,
12604,
624,
267,
367,
2562,
315,
291,
14,
265,
63,
1205,
26,
288,
2562,
8,
19398,
12,
21859,
9,
339,
347,
7269,
316,
8,
277,
304,
267,
408,
2176,
641,
63,
7154,
12604,
624,
267,
367,
2562,
315,
291,
14,
265,
63,
7154,
26,
288,
2562,
342,
339,
347,
485,
8669,
8,
277,
304,
267,
408,
6470,
314,
3906,
465,
9158,
436,
1240,
641,
63,
1932,
12604,
1041,
267,
291,
14,
374,
63,
8669,
275,
715,
267,
367,
2562,
315,
291,
14,
265,
63,
1932,
26,
288,
2562,
342,
267,
367,
5759,
315,
291,
14,
7922,
26,
288,
24358,
8,
277,
12,
5759,
9,
327,
3254,
26,
25358,
1077,
2951,
5436,
314,
5548,
31,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3886,
4476,
2562,
9569,
83,
7,
4335,
450,
291,
14,
1532,
199,
199,
533,
8495,
409,
8,
807,
304,
272,
408,
272,
437,
8495,
409,
365,
282,
1572,
402,
6527,
626,
787,
370,
506,
1255,
1006,
737,
5403,
14,
710,
272,
22477,
3269,
402,
1808,
282,
8495,
409,
365,
17266,
3663,
6527,
370,
1255,
272,
315,
9861,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
6527,
17894,
267,
1613,
8,
4476,
409,
12,
291,
2843,
826,
721,
8,
2227,
8,
84,
395,
307,
9,
367,
307,
315,
6527,
9,
267,
291,
14,
21924,
275,
756,
339,
347,
1050,
8,
277,
12,
2120,
304,
267,
291,
59,
2227,
8,
1765,
1874,
275,
2120,
339,
347,
1050,
63,
1765,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
525,
8,
4476,
2031,
589,
12,
1011,
958,
430,
339,
347,
9311,
8,
277,
304,
267,
291,
14,
21924,
275,
715,
339,
347,
636,
269,
721,
277,
12,
2120,
409,
18,
304,
267,
367,
2120,
63,
2227,
12,
2120,
315,
2120,
409,
18,
14,
4611,
837,
288,
340,
2120,
63,
2227,
315,
291,
26,
355,
291,
59,
1765,
63,
2227,
1055,
5628,
63,
7922,
8,
1765,
9,
288,
587,
26,
355,
291,
59,
1765,
63,
2227,
61,
275,
2120,
327,
3254,
26,
1077,
7289,
314,
2120,
7830,
2419,
2951,
10663,
282,
3659,
267,
372,
291,
199,
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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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,
0,
0,
0,
0,
0,
0,
0
] |
craigmaloney/twistedtwister
|
create-upload.py
|
5
|
1538
|
#! /usr/bin/env python
'''Helper script for bundling up a game in a ZIP file.
This script will bundle all game files into a ZIP file which is named as
per the argument given on the command-line. The ZIP file will unpack into a
directory of the same name.
The script ignores:
- CVS or SVN subdirectories
- any dotfiles (files starting with ".")
- .pyc and .pyo files
'''
import sys
import os
import zipfile
if len(sys.argv) != 2:
print '''Usage: python %s <release filename-version>
eg. python %s my_cool_game-1.0'''%(sys.argv[0], sys.argv[0])
sys.exit()
base = sys.argv[1]
try:
package = zipfile.ZipFile(base + '.zip', 'w', zipfile.ZIP_DEFLATED)
except RuntimeError:
package = zipfile.ZipFile(base + '.zip', 'w')
# core files
for name in 'README.txt run_game.py'.split():
package.write(name, os.path.join(base, name))
package.write('run_game.py', os.path.join(base, 'run_game.pyw'))
# utility for adding subdirectories
def add_files(generator):
for dirpath, dirnames, filenames in generator:
for name in 'CVS', '.svn':
if name in dirnames:
dirnames.remove(name)
for name in filenames:
suffix = os.path.splitext(name)[1]
if suffix in ('.pyc', '.pyo'): continue
if name[0] == '.': continue
filename = os.path.join(dirpath, name)
package.write(filename, os.path.join(base, filename))
# add the lib and data directories
add_files(os.walk('lib'))
add_files(os.walk('data'))
add_files(os.walk('eggs'))
|
gpl-2.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
2344,
4433,
2884,
367,
330,
725,
2983,
1536,
282,
9219,
315,
282,
18402,
570,
14,
199,
199,
2765,
2884,
911,
8844,
1006,
9219,
1584,
1901,
282,
18402,
570,
1314,
365,
4310,
465,
199,
529,
314,
1423,
1627,
641,
314,
1414,
13,
604,
14,
710,
18402,
570,
911,
7787,
1901,
282,
199,
3619,
402,
314,
2011,
536,
14,
199,
199,
1918,
2884,
24010,
26,
199,
199,
13,
445,
7428,
503,
24639,
24799,
199,
13,
1263,
6308,
1725,
334,
1725,
6617,
543,
298,
2685,
199,
13,
1275,
11357,
436,
1275,
22345,
1584,
199,
199,
2344,
199,
199,
646,
984,
199,
646,
747,
199,
646,
10392,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
272,
870,
1449,
7692,
26,
2366,
450,
83,
665,
3221,
1788,
13,
1023,
30,
199,
199,
5902,
14,
2366,
450,
83,
3002,
63,
18499,
63,
5097,
13,
17,
14,
16,
2344,
2840,
1274,
14,
3020,
59,
16,
467,
984,
14,
3020,
59,
16,
566,
272,
984,
14,
2224,
342,
199,
199,
1095,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
893,
26,
272,
2559,
275,
10392,
14,
15016,
8,
1095,
435,
1987,
3065,
297,
283,
87,
297,
10392,
14,
16977,
63,
28506,
9,
199,
2590,
6064,
26,
272,
2559,
275,
10392,
14,
15016,
8,
1095,
435,
1987,
3065,
297,
283,
87,
358,
199,
199,
3,
6170,
1584,
199,
509,
536,
315,
283,
18195,
14,
2424,
1255,
63,
5097,
14,
647,
1370,
1294,
837,
272,
2559,
14,
952,
8,
354,
12,
747,
14,
515,
14,
904,
8,
1095,
12,
536,
430,
199,
2491,
14,
952,
360,
1065,
63,
5097,
14,
647,
297,
747,
14,
515,
14,
904,
8,
1095,
12,
283,
1065,
63,
5097,
14,
647,
87,
1333,
199,
199,
3,
11420,
367,
7791,
24799,
199,
318,
1050,
63,
1725,
8,
4679,
304,
272,
367,
20648,
12,
22310,
12,
6203,
315,
4306,
26,
267,
367,
536,
315,
283,
35,
7428,
297,
1987,
6836,
356,
288,
340,
536,
315,
22310,
26,
355,
22310,
14,
2168,
8,
354,
9,
398,
367,
536,
315,
6203,
26,
288,
4739,
275,
747,
14,
515,
14,
7973,
8,
354,
2788,
17,
61,
288,
340,
4739,
315,
23500,
11357,
297,
1987,
22345,
735,
1980,
288,
340,
536,
59,
16,
61,
508,
26351,
1980,
288,
1788,
275,
747,
14,
515,
14,
904,
8,
17254,
12,
536,
9,
288,
2559,
14,
952,
8,
1501,
12,
747,
14,
515,
14,
904,
8,
1095,
12,
1788,
430,
199,
199,
3,
1050,
314,
1973,
436,
666,
6602,
199,
525,
63,
1725,
8,
736,
14,
7757,
360,
773,
1333,
199,
525,
63,
1725,
8,
736,
14,
7757,
360,
576,
1333,
199,
525,
63,
1725,
8,
736,
14,
7757,
360,
14488,
1333,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1813,
2366,
199,
2344,
4433,
2884,
367,
330,
725,
2983,
1536,
282,
9219,
315,
282,
18402,
570,
14,
199,
199,
2765,
2884,
911,
8844,
1006,
9219,
1584,
1901,
282,
18402,
570,
1314,
365,
4310,
465,
199,
529,
314,
1423,
1627,
641,
314,
1414,
13,
604,
14,
710,
18402,
570,
911,
7787,
1901,
282,
199,
3619,
402,
314,
2011,
536,
14,
199,
199,
1918,
2884,
24010,
26,
199,
199,
13,
445,
7428,
503,
24639,
24799,
199,
13,
1263,
6308,
1725,
334,
1725,
6617,
543,
298,
2685,
199,
13,
1275,
11357,
436,
1275,
22345,
1584,
199,
199,
2344,
199,
199,
646,
984,
199,
646,
747,
199,
646,
10392,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
272,
870,
1449,
7692,
26,
2366,
450,
83,
665,
3221,
1788,
13,
1023,
30,
199,
199,
5902,
14,
2366,
450,
83,
3002,
63,
18499,
63,
5097,
13,
17,
14,
16,
2344,
2840,
1274,
14,
3020,
59,
16,
467,
984,
14,
3020,
59,
16,
566,
272,
984,
14,
2224,
342,
199,
199,
1095,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
893,
26,
272,
2559,
275,
10392,
14,
15016,
8,
1095,
435,
1987,
3065,
297,
283,
87,
297,
10392,
14,
16977,
63,
28506,
9,
199,
2590,
6064,
26,
272,
2559,
275,
10392,
14,
15016,
8,
1095,
435,
1987,
3065,
297,
283,
87,
358,
199,
199,
3,
6170,
1584,
199,
509,
536,
315,
283,
18195,
14,
2424,
1255,
63,
5097,
14,
647,
1370,
1294,
837,
272,
2559,
14,
952,
8,
354,
12,
747,
14,
515,
14,
904,
8,
1095,
12,
536,
430,
199,
2491,
14,
952,
360,
1065,
63,
5097,
14,
647,
297,
747,
14,
515,
14,
904,
8,
1095,
12,
283,
1065,
63,
5097,
14,
647,
87,
1333,
199,
199,
3,
11420,
367,
7791,
24799,
199,
318,
1050,
63,
1725,
8,
4679,
304,
272,
367,
20648,
12,
22310,
12,
6203,
315,
4306,
26,
267,
367,
536,
315,
283,
35,
7428,
297,
1987,
6836,
356,
288,
340,
536,
315,
22310,
26,
355,
22310,
14,
2168,
8,
354,
9,
398,
367,
536,
315,
6203,
26,
288,
4739,
275,
747,
14,
515,
14,
7973,
8,
354,
2788,
17,
61,
288,
340,
4739,
315,
23500,
11357,
297,
1987,
22345,
735,
1980,
288,
340,
536,
59,
16,
61,
508,
26351,
1980,
288,
1788,
275,
747,
14,
515,
14,
904,
8,
17254,
12,
536,
9,
288,
2559,
14,
952,
8,
1501,
12,
747,
14,
515,
14,
904,
8,
1095,
12,
1788,
430,
199,
199,
3,
1050,
314,
1973,
436,
666,
6602,
199,
525,
63,
1725,
8,
736,
14,
7757,
360,
773,
1333,
199,
525,
63,
1725,
8,
736,
14,
7757,
360,
576,
1333,
199,
525,
63,
1725,
8,
736,
14,
7757,
360,
14488,
1333,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
aequitas/home-assistant
|
homeassistant/components/openevse/sensor.py
|
7
|
3250
|
"""Support for monitoring an OpenEVSE Charger."""
import logging
from requests import RequestException
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (
TEMP_CELSIUS, CONF_HOST, ENERGY_KILO_WATT_HOUR,
CONF_MONITORED_VARIABLES)
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__)
SENSOR_TYPES = {
'status': ['Charging Status', None],
'charge_time': ['Charge Time Elapsed', 'minutes'],
'ambient_temp': ['Ambient Temperature', TEMP_CELSIUS],
'ir_temp': ['IR Temperature', TEMP_CELSIUS],
'rtc_temp': ['RTC Temperature', TEMP_CELSIUS],
'usage_session': ['Usage this Session', ENERGY_KILO_WATT_HOUR],
'usage_total': ['Total Usage', ENERGY_KILO_WATT_HOUR]
}
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_MONITORED_VARIABLES, default=['status']):
vol.All(cv.ensure_list, [vol.In(SENSOR_TYPES)]),
})
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the OpenEVSE sensor."""
import openevsewifi
host = config.get(CONF_HOST)
monitored_variables = config.get(CONF_MONITORED_VARIABLES)
charger = openevsewifi.Charger(host)
dev = []
for variable in monitored_variables:
dev.append(OpenEVSESensor(variable, charger))
add_entities(dev, True)
class OpenEVSESensor(Entity):
"""Implementation of an OpenEVSE sensor."""
def __init__(self, sensor_type, charger):
"""Initialize the sensor."""
self._name = SENSOR_TYPES[sensor_type][0]
self.type = sensor_type
self._state = None
self.charger = charger
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
"""Return the unit of measurement of this sensor."""
return self._unit_of_measurement
def update(self):
"""Get the monitored data from the charger."""
try:
if self.type == 'status':
self._state = self.charger.getStatus()
elif self.type == 'charge_time':
self._state = self.charger.getChargeTimeElapsed() / 60
elif self.type == 'ambient_temp':
self._state = self.charger.getAmbientTemperature()
elif self.type == 'ir_temp':
self._state = self.charger.getIRTemperature()
elif self.type == 'rtc_temp':
self._state = self.charger.getRTCTemperature()
elif self.type == 'usage_session':
self._state = float(self.charger.getUsageSession()) / 1000
elif self.type == 'usage_total':
self._state = float(self.charger.getUsageTotal()) / 1000
else:
self._state = 'Unknown'
except (RequestException, ValueError, KeyError):
_LOGGER.warning("Could not update status for %s", self.name)
|
apache-2.0
|
[
624,
11532,
367,
20391,
376,
3232,
18015,
899,
6659,
836,
1041,
199,
646,
2050,
199,
199,
504,
4145,
492,
4784,
1726,
199,
646,
30291,
465,
5236,
199,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
504,
8846,
14,
4608,
14,
8956,
492,
21966,
63,
10926,
199,
504,
8846,
14,
1297,
492,
334,
272,
24314,
63,
21595,
2684,
1668,
12,
6392,
63,
5449,
12,
21466,
63,
43,
1193,
47,
63,
55,
11712,
63,
2979,
1230,
12,
272,
6392,
63,
32387,
25517,
63,
21161,
9,
199,
504,
8846,
14,
7546,
14,
4502,
492,
17680,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
24151,
63,
7893,
275,
469,
272,
283,
1205,
356,
788,
1049,
1273,
316,
9795,
297,
488,
467,
272,
283,
16441,
63,
521,
356,
788,
31539,
4703,
662,
9982,
297,
283,
10430,
995,
272,
283,
455,
4492,
484,
63,
808,
356,
788,
29209,
6792,
12540,
7899,
297,
24314,
63,
21595,
2684,
1668,
467,
272,
283,
723,
63,
808,
356,
788,
3927,
12540,
7899,
297,
24314,
63,
21595,
2684,
1668,
467,
272,
283,
23392,
63,
808,
356,
788,
50,
5708,
12540,
7899,
297,
24314,
63,
21595,
2684,
1668,
467,
272,
283,
3807,
63,
1730,
356,
788,
7692,
642,
8596,
297,
21466,
63,
43,
1193,
47,
63,
55,
11712,
63,
2979,
1230,
467,
272,
283,
3807,
63,
2923,
356,
788,
7316,
11028,
297,
21466,
63,
43,
1193,
47,
63,
55,
11712,
63,
2979,
1230,
61,
199,
93,
199,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
2561,
272,
5236,
14,
8030,
8,
3103,
63,
5449,
304,
6277,
14,
875,
12,
272,
5236,
14,
7012,
8,
3103,
63,
32387,
25517,
63,
21161,
12,
849,
2968,
1205,
9090,
267,
5236,
14,
2422,
8,
5107,
14,
7505,
63,
513,
12,
359,
5650,
14,
607,
8,
24151,
63,
7893,
16636,
199,
1552,
421,
199,
318,
3272,
63,
3246,
8,
5387,
12,
1101,
12,
1050,
63,
8327,
12,
13172,
63,
815,
29,
403,
304,
272,
408,
1084,
1536,
314,
3232,
18015,
899,
8778,
1041,
272,
492,
1551,
6857,
261,
4326,
339,
1591,
275,
1101,
14,
362,
8,
3103,
63,
5449,
9,
272,
23821,
63,
3669,
275,
1101,
14,
362,
8,
3103,
63,
32387,
25517,
63,
21161,
9,
339,
1495,
836,
275,
1551,
6857,
261,
4326,
14,
1610,
836,
8,
1102,
9,
339,
4866,
275,
942,
272,
367,
1750,
315,
23821,
63,
3669,
26,
267,
4866,
14,
740,
8,
4299,
37,
7428,
654,
2616,
8,
1975,
12,
1495,
836,
430,
339,
1050,
63,
8327,
8,
2374,
12,
715,
9,
421,
199,
533,
3232,
37,
7428,
654,
2616,
8,
7302,
304,
272,
408,
7921,
402,
376,
3232,
18015,
899,
8778,
1041,
339,
347,
636,
826,
721,
277,
12,
8778,
63,
466,
12,
1495,
836,
304,
267,
408,
9345,
314,
8778,
1041,
267,
291,
423,
354,
275,
428,
17850,
63,
7893,
59,
8956,
63,
466,
1527,
16,
61,
267,
291,
14,
466,
275,
8778,
63,
466,
267,
291,
423,
929,
275,
488,
267,
291,
14,
1560,
836,
275,
1495,
836,
267,
291,
423,
3248,
63,
1618,
63,
17912,
275,
428,
17850,
63,
7893,
59,
8956,
63,
466,
1527,
17,
61,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
408,
1767,
314,
536,
402,
314,
8778,
1041,
267,
372,
291,
423,
354,
339,
768,
1829,
272,
347,
1174,
8,
277,
304,
267,
408,
1767,
314,
1174,
402,
314,
8778,
1041,
267,
372,
291,
423,
929,
339,
768,
1829,
272,
347,
4137,
63,
1618,
63,
17912,
8,
277,
304,
267,
408,
1767,
314,
4137,
402,
18216,
402,
642,
8778,
1041,
267,
372,
291,
423,
3248,
63,
1618,
63,
17912,
339,
347,
1678,
8,
277,
304,
267,
408,
1002,
314,
23821,
666,
687,
314,
1495,
836,
1041,
267,
862,
26,
288,
340,
291,
14,
466,
508,
283,
1205,
356,
355,
291,
423,
929,
275,
291,
14,
1560,
836,
14,
362,
3694,
342,
288,
916,
291,
14,
466,
508,
283,
16441,
63,
521,
356,
355,
291,
423,
929,
275,
291,
14,
1560,
836,
14,
362,
31539,
1366,
37,
9982,
342,
1182,
5212,
288,
916,
291,
14,
466,
508,
283,
455,
4492,
484,
63,
808,
356,
355,
291,
423,
929,
275,
291,
14,
1560,
836,
14,
362,
29209,
6792,
27409,
342,
288,
916,
291,
14,
466,
508,
283,
723,
63,
808,
356,
355,
291,
423,
929,
275,
291,
14,
1560,
836,
14,
362,
3927,
27409,
342,
288,
916,
291,
14,
466,
508,
283,
23392,
63,
808,
356,
355,
291,
423,
929,
275,
291,
14,
1560,
836,
14,
362,
11876,
1028,
2109,
7899,
342,
288,
916,
291,
14,
466,
508,
283,
3807,
63,
1730,
356,
355,
291,
423,
929,
275,
2069,
8,
277,
14,
1560,
836,
14,
362,
7692,
4434,
1012,
1182,
5198,
288,
916,
291,
14,
466,
508,
283,
3807,
63,
2923,
356,
355,
291,
423,
929,
275,
2069,
8,
277,
14,
1560,
836,
14,
362,
7692,
7316,
1012,
1182,
5198,
288,
587,
26,
355,
291,
423,
929,
275,
283,
5912,
7,
267,
871,
334,
28724,
12,
1722,
12,
4067,
304,
288,
485,
10186,
14,
3764,
480,
6531,
440,
1678,
2004,
367,
450,
83,
401,
291,
14,
354,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
11532,
367,
20391,
376,
3232,
18015,
899,
6659,
836,
1041,
199,
646,
2050,
199,
199,
504,
4145,
492,
4784,
1726,
199,
646,
30291,
465,
5236,
199,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
504,
8846,
14,
4608,
14,
8956,
492,
21966,
63,
10926,
199,
504,
8846,
14,
1297,
492,
334,
272,
24314,
63,
21595,
2684,
1668,
12,
6392,
63,
5449,
12,
21466,
63,
43,
1193,
47,
63,
55,
11712,
63,
2979,
1230,
12,
272,
6392,
63,
32387,
25517,
63,
21161,
9,
199,
504,
8846,
14,
7546,
14,
4502,
492,
17680,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
24151,
63,
7893,
275,
469,
272,
283,
1205,
356,
788,
1049,
1273,
316,
9795,
297,
488,
467,
272,
283,
16441,
63,
521,
356,
788,
31539,
4703,
662,
9982,
297,
283,
10430,
995,
272,
283,
455,
4492,
484,
63,
808,
356,
788,
29209,
6792,
12540,
7899,
297,
24314,
63,
21595,
2684,
1668,
467,
272,
283,
723,
63,
808,
356,
788,
3927,
12540,
7899,
297,
24314,
63,
21595,
2684,
1668,
467,
272,
283,
23392,
63,
808,
356,
788,
50,
5708,
12540,
7899,
297,
24314,
63,
21595,
2684,
1668,
467,
272,
283,
3807,
63,
1730,
356,
788,
7692,
642,
8596,
297,
21466,
63,
43,
1193,
47,
63,
55,
11712,
63,
2979,
1230,
467,
272,
283,
3807,
63,
2923,
356,
788,
7316,
11028,
297,
21466,
63,
43,
1193,
47,
63,
55,
11712,
63,
2979,
1230,
61,
199,
93,
199,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
2561,
272,
5236,
14,
8030,
8,
3103,
63,
5449,
304,
6277,
14,
875,
12,
272,
5236,
14,
7012,
8,
3103,
63,
32387,
25517,
63,
21161,
12,
849,
2968,
1205,
9090,
267,
5236,
14,
2422,
8,
5107,
14,
7505,
63,
513,
12,
359,
5650,
14,
607,
8,
24151,
63,
7893,
16636,
199,
1552,
421,
199,
318,
3272,
63,
3246,
8,
5387,
12,
1101,
12,
1050,
63,
8327,
12,
13172,
63,
815,
29,
403,
304,
272,
408,
1084,
1536,
314,
3232,
18015,
899,
8778,
1041,
272,
492,
1551,
6857,
261,
4326,
339,
1591,
275,
1101,
14,
362,
8,
3103,
63,
5449,
9,
272,
23821,
63,
3669,
275,
1101,
14,
362,
8,
3103,
63,
32387,
25517,
63,
21161,
9,
339,
1495,
836,
275,
1551,
6857,
261,
4326,
14,
1610,
836,
8,
1102,
9,
339,
4866,
275,
942,
272,
367,
1750,
315,
23821,
63,
3669,
26,
267,
4866,
14,
740,
8,
4299,
37,
7428,
654,
2616,
8,
1975,
12,
1495,
836,
430,
339,
1050,
63,
8327,
8,
2374,
12,
715,
9,
421,
199,
533,
3232,
37,
7428,
654,
2616,
8,
7302,
304,
272,
408,
7921,
402,
376,
3232,
18015,
899,
8778,
1041,
339,
347,
636,
826,
721,
277,
12,
8778,
63,
466,
12,
1495,
836,
304,
267,
408,
9345,
314,
8778,
1041,
267,
291,
423,
354,
275,
428,
17850,
63,
7893,
59,
8956,
63,
466,
1527,
16,
61,
267,
291,
14,
466,
275,
8778,
63,
466,
267,
291,
423,
929,
275,
488,
267,
291,
14,
1560,
836,
275,
1495,
836,
267,
291,
423,
3248,
63,
1618,
63,
17912,
275,
428,
17850,
63,
7893,
59,
8956,
63,
466,
1527,
17,
61,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
408,
1767,
314,
536,
402,
314,
8778,
1041,
267,
372,
291,
423,
354,
339,
768,
1829,
272,
347,
1174,
8,
277,
304,
267,
408,
1767,
314,
1174,
402,
314,
8778,
1041,
267,
372,
291,
423,
929,
339,
768,
1829,
272,
347,
4137,
63,
1618,
63,
17912,
8,
277,
304,
267,
408,
1767,
314,
4137,
402,
18216,
402,
642,
8778,
1041,
267,
372,
291,
423,
3248,
63,
1618,
63,
17912,
339,
347,
1678,
8,
277,
304,
267,
408,
1002,
314,
23821,
666,
687,
314,
1495,
836,
1041,
267,
862,
26,
288,
340,
291,
14,
466,
508,
283,
1205,
356,
355,
291,
423,
929,
275,
291,
14,
1560,
836,
14,
362,
3694,
342,
288,
916,
291,
14,
466,
508,
283,
16441,
63,
521,
356,
355,
291,
423,
929,
275,
291,
14,
1560,
836,
14,
362,
31539,
1366,
37,
9982,
342,
1182,
5212,
288,
916,
291,
14,
466,
508,
283,
455,
4492,
484,
63,
808,
356,
355,
291,
423,
929,
275,
291,
14,
1560,
836,
14,
362,
29209,
6792,
27409,
342,
288,
916,
291,
14,
466,
508,
283,
723,
63,
808,
356,
355,
291,
423,
929,
275,
291,
14,
1560,
836,
14,
362,
3927,
27409,
342,
288,
916,
291,
14,
466,
508,
283,
23392,
63,
808,
356,
355,
291,
423,
929,
275,
291,
14,
1560,
836,
14,
362,
11876,
1028,
2109,
7899,
342,
288,
916,
291,
14,
466,
508,
283,
3807,
63,
1730,
356,
355,
291,
423,
929,
275,
2069,
8,
277,
14,
1560,
836,
14,
362,
7692,
4434,
1012,
1182,
5198,
288,
916,
291,
14,
466,
508,
283,
3807,
63,
2923,
356,
355,
291,
423,
929,
275,
2069,
8,
277,
14,
1560,
836,
14,
362,
7692,
7316,
1012,
1182,
5198,
288,
587,
26,
355,
291,
423,
929,
275,
283,
5912,
7,
267,
871,
334,
28724,
12,
1722,
12,
4067,
304,
288,
485,
10186,
14,
3764,
480,
6531,
440,
1678,
2004,
367,
450,
83,
401,
291,
14,
354,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
clumsy1991/M8_GPE_Kernel
|
scripts/rt-tester/rt-tester.py
|
11005
|
5307
|
#!/usr/bin/python
#
# rt-mutex tester
#
# (C) 2006 Thomas Gleixner <tglx@linutronix.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
import os
import sys
import getopt
import shutil
import string
# Globals
quiet = 0
test = 0
comments = 0
sysfsprefix = "/sys/devices/system/rttest/rttest"
statusfile = "/status"
commandfile = "/command"
# Command opcodes
cmd_opcodes = {
"schedother" : "1",
"schedfifo" : "2",
"lock" : "3",
"locknowait" : "4",
"lockint" : "5",
"lockintnowait" : "6",
"lockcont" : "7",
"unlock" : "8",
"signal" : "11",
"resetevent" : "98",
"reset" : "99",
}
test_opcodes = {
"prioeq" : ["P" , "eq" , None],
"priolt" : ["P" , "lt" , None],
"priogt" : ["P" , "gt" , None],
"nprioeq" : ["N" , "eq" , None],
"npriolt" : ["N" , "lt" , None],
"npriogt" : ["N" , "gt" , None],
"unlocked" : ["M" , "eq" , 0],
"trylock" : ["M" , "eq" , 1],
"blocked" : ["M" , "eq" , 2],
"blockedwake" : ["M" , "eq" , 3],
"locked" : ["M" , "eq" , 4],
"opcodeeq" : ["O" , "eq" , None],
"opcodelt" : ["O" , "lt" , None],
"opcodegt" : ["O" , "gt" , None],
"eventeq" : ["E" , "eq" , None],
"eventlt" : ["E" , "lt" , None],
"eventgt" : ["E" , "gt" , None],
}
# Print usage information
def usage():
print "rt-tester.py <-c -h -q -t> <testfile>"
print " -c display comments after first command"
print " -h help"
print " -q quiet mode"
print " -t test mode (syntax check)"
print " testfile: read test specification from testfile"
print " otherwise from stdin"
return
# Print progress when not in quiet mode
def progress(str):
if not quiet:
print str
# Analyse a status value
def analyse(val, top, arg):
intval = int(val)
if top[0] == "M":
intval = intval / (10 ** int(arg))
intval = intval % 10
argval = top[2]
elif top[0] == "O":
argval = int(cmd_opcodes.get(arg, arg))
else:
argval = int(arg)
# progress("%d %s %d" %(intval, top[1], argval))
if top[1] == "eq" and intval == argval:
return 1
if top[1] == "lt" and intval < argval:
return 1
if top[1] == "gt" and intval > argval:
return 1
return 0
# Parse the commandline
try:
(options, arguments) = getopt.getopt(sys.argv[1:],'chqt')
except getopt.GetoptError, ex:
usage()
sys.exit(1)
# Parse commandline options
for option, value in options:
if option == "-c":
comments = 1
elif option == "-q":
quiet = 1
elif option == "-t":
test = 1
elif option == '-h':
usage()
sys.exit(0)
# Select the input source
if arguments:
try:
fd = open(arguments[0])
except Exception,ex:
sys.stderr.write("File not found %s\n" %(arguments[0]))
sys.exit(1)
else:
fd = sys.stdin
linenr = 0
# Read the test patterns
while 1:
linenr = linenr + 1
line = fd.readline()
if not len(line):
break
line = line.strip()
parts = line.split(":")
if not parts or len(parts) < 1:
continue
if len(parts[0]) == 0:
continue
if parts[0].startswith("#"):
if comments > 1:
progress(line)
continue
if comments == 1:
comments = 2
progress(line)
cmd = parts[0].strip().lower()
opc = parts[1].strip().lower()
tid = parts[2].strip()
dat = parts[3].strip()
try:
# Test or wait for a status value
if cmd == "t" or cmd == "w":
testop = test_opcodes[opc]
fname = "%s%s%s" %(sysfsprefix, tid, statusfile)
if test:
print fname
continue
while 1:
query = 1
fsta = open(fname, 'r')
status = fsta.readline().strip()
fsta.close()
stat = status.split(",")
for s in stat:
s = s.strip()
if s.startswith(testop[0]):
# Separate status value
val = s[2:].strip()
query = analyse(val, testop, dat)
break
if query or cmd == "t":
break
progress(" " + status)
if not query:
sys.stderr.write("Test failed in line %d\n" %(linenr))
sys.exit(1)
# Issue a command to the tester
elif cmd == "c":
cmdnr = cmd_opcodes[opc]
# Build command string and sys filename
cmdstr = "%s:%s" %(cmdnr, dat)
fname = "%s%s%s" %(sysfsprefix, tid, commandfile)
if test:
print fname
continue
fcmd = open(fname, 'w')
fcmd.write(cmdstr)
fcmd.close()
except Exception,ex:
sys.stderr.write(str(ex))
sys.stderr.write("\nSyntax error in line %d\n" %(linenr))
if not test:
fd.close()
sys.exit(1)
# Normal exit pass
print "Pass"
sys.exit(0)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
14059,
13,
19078,
17570,
199,
3,
199,
3,
334,
35,
9,
8315,
27864,
598,
274,
1148,
1372,
665,
84,
18660,
32,
472,
5373,
1148,
14,
271,
30,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
1015,
499,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
646,
747,
199,
646,
984,
199,
646,
12733,
199,
646,
5145,
199,
646,
1059,
199,
199,
3,
13641,
83,
199,
10243,
275,
378,
199,
396,
275,
378,
199,
6223,
275,
378,
199,
199,
1274,
2319,
1861,
275,
3286,
1274,
15,
6410,
15,
2253,
15,
2591,
396,
15,
2591,
396,
2,
199,
1205,
493,
275,
3286,
1205,
2,
199,
1531,
493,
275,
3286,
1531,
2,
199,
199,
3,
5817,
27388,
199,
1760,
63,
22022,
275,
469,
272,
298,
10487,
1848,
2,
259,
520,
298,
17,
401,
272,
298,
10487,
22976,
2,
258,
520,
298,
18,
401,
272,
298,
831,
2,
3515,
520,
298,
19,
401,
272,
298,
831,
20870,
2,
259,
520,
298,
20,
401,
272,
298,
831,
442,
2,
755,
520,
298,
21,
401,
272,
298,
831,
442,
20870,
2,
520,
298,
22,
401,
272,
298,
831,
11096,
2,
420,
520,
298,
23,
401,
272,
298,
17966,
2,
263,
520,
298,
24,
401,
272,
298,
4653,
2,
263,
520,
298,
845,
401,
272,
298,
264,
30563,
782,
2,
259,
520,
298,
2905,
401,
272,
298,
3958,
2,
260,
520,
298,
1020,
401,
272,
789,
199,
199,
396,
63,
22022,
275,
469,
272,
298,
20572,
4077,
2,
263,
520,
2097,
48,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1359,
28934,
2,
263,
520,
2097,
48,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1359,
974,
84,
2,
263,
520,
2097,
48,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
78,
20572,
4077,
2,
755,
520,
2097,
46,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
78,
1359,
28934,
2,
755,
520,
2097,
46,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
78,
1359,
974,
84,
2,
755,
520,
2097,
46,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
32489,
2,
420,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
378,
467,
272,
298,
893,
831,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
413,
467,
272,
298,
17726,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
499,
467,
272,
298,
17726,
15181,
2,
257,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
650,
467,
272,
298,
9325,
2,
263,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
841,
467,
272,
298,
14325,
4077,
2,
420,
520,
2097,
47,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
14325,
4116,
2,
420,
520,
2097,
47,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
14325,
3308,
2,
420,
520,
2097,
47,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
12056,
266,
81,
2,
755,
520,
2097,
37,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1430,
4116,
2,
755,
520,
2097,
37,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1430,
3308,
2,
755,
520,
2097,
37,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
789,
199,
199,
3,
9101,
4503,
2556,
199,
318,
4503,
837,
272,
870,
298,
2591,
13,
8234,
14,
647,
25549,
67,
446,
72,
446,
81,
446,
84,
30,
665,
21091,
4335,
272,
870,
298,
446,
67,
259,
2929,
6786,
2410,
1642,
1414,
2,
272,
870,
298,
446,
72,
259,
1720,
2,
272,
870,
298,
446,
81,
259,
11971,
818,
2,
272,
870,
298,
446,
84,
259,
511,
818,
334,
7093,
1104,
2924,
272,
870,
298,
30530,
26,
1586,
511,
8929,
687,
30530,
2,
272,
870,
298,
4257,
687,
9009,
2,
272,
372,
199,
199,
3,
9101,
6696,
1380,
440,
315,
11971,
818,
199,
318,
6696,
8,
495,
304,
272,
340,
440,
11971,
26,
267,
870,
620,
199,
199,
3,
14279,
261,
282,
2004,
574,
199,
318,
21297,
8,
637,
12,
2746,
12,
1680,
304,
339,
26111,
275,
1109,
8,
637,
9,
339,
340,
2746,
59,
16,
61,
508,
298,
45,
582,
267,
26111,
275,
26111,
1182,
334,
709,
1011,
1109,
8,
1273,
430,
199,
198,
442,
637,
275,
26111,
450,
1616,
267,
27610,
275,
2746,
59,
18,
61,
272,
916,
2746,
59,
16,
61,
508,
298,
47,
582,
267,
27610,
275,
1109,
8,
1760,
63,
22022,
14,
362,
8,
1273,
12,
1680,
430,
272,
587,
26,
267,
27610,
275,
1109,
8,
1273,
9,
339,
327,
6696,
3647,
68,
450,
83,
450,
68,
2,
2818,
442,
637,
12,
2746,
59,
17,
467,
27610,
430,
339,
340,
2746,
59,
17,
61,
508,
298,
4077,
2,
436,
26111,
508,
27610,
26,
199,
198,
1107,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
4116,
2,
436,
26111,
665,
27610,
26,
267,
372,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
3308,
2,
436,
26111,
690,
27610,
26,
199,
198,
1107,
413,
272,
372,
378,
199,
199,
3,
6077,
314,
28279,
199,
893,
26,
272,
334,
1419,
12,
2368,
9,
275,
12733,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
7,
335,
8440,
358,
199,
2590,
12733,
14,
1002,
29368,
12,
444,
26,
272,
4503,
342,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
3,
6077,
28279,
1511,
199,
509,
945,
12,
574,
315,
1511,
26,
272,
340,
945,
508,
3905,
67,
582,
267,
6786,
275,
413,
272,
916,
945,
508,
3905,
81,
582,
267,
11971,
275,
413,
272,
916,
945,
508,
3905,
84,
582,
267,
511,
275,
413,
272,
916,
945,
508,
2475,
72,
356,
267,
4503,
342,
267,
984,
14,
2224,
8,
16,
9,
199,
199,
3,
9496,
314,
1324,
1350,
199,
692,
2368,
26,
272,
862,
26,
267,
6111,
275,
1551,
8,
4958,
59,
16,
566,
272,
871,
2186,
12,
476,
26,
267,
984,
14,
3083,
14,
952,
480,
1173,
440,
1911,
450,
83,
60,
78,
2,
2818,
4958,
59,
16,
2459,
267,
984,
14,
2224
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
14059,
13,
19078,
17570,
199,
3,
199,
3,
334,
35,
9,
8315,
27864,
598,
274,
1148,
1372,
665,
84,
18660,
32,
472,
5373,
1148,
14,
271,
30,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
1015,
499,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
646,
747,
199,
646,
984,
199,
646,
12733,
199,
646,
5145,
199,
646,
1059,
199,
199,
3,
13641,
83,
199,
10243,
275,
378,
199,
396,
275,
378,
199,
6223,
275,
378,
199,
199,
1274,
2319,
1861,
275,
3286,
1274,
15,
6410,
15,
2253,
15,
2591,
396,
15,
2591,
396,
2,
199,
1205,
493,
275,
3286,
1205,
2,
199,
1531,
493,
275,
3286,
1531,
2,
199,
199,
3,
5817,
27388,
199,
1760,
63,
22022,
275,
469,
272,
298,
10487,
1848,
2,
259,
520,
298,
17,
401,
272,
298,
10487,
22976,
2,
258,
520,
298,
18,
401,
272,
298,
831,
2,
3515,
520,
298,
19,
401,
272,
298,
831,
20870,
2,
259,
520,
298,
20,
401,
272,
298,
831,
442,
2,
755,
520,
298,
21,
401,
272,
298,
831,
442,
20870,
2,
520,
298,
22,
401,
272,
298,
831,
11096,
2,
420,
520,
298,
23,
401,
272,
298,
17966,
2,
263,
520,
298,
24,
401,
272,
298,
4653,
2,
263,
520,
298,
845,
401,
272,
298,
264,
30563,
782,
2,
259,
520,
298,
2905,
401,
272,
298,
3958,
2,
260,
520,
298,
1020,
401,
272,
789,
199,
199,
396,
63,
22022,
275,
469,
272,
298,
20572,
4077,
2,
263,
520,
2097,
48,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1359,
28934,
2,
263,
520,
2097,
48,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1359,
974,
84,
2,
263,
520,
2097,
48,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
78,
20572,
4077,
2,
755,
520,
2097,
46,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
78,
1359,
28934,
2,
755,
520,
2097,
46,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
78,
1359,
974,
84,
2,
755,
520,
2097,
46,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
32489,
2,
420,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
378,
467,
272,
298,
893,
831,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
413,
467,
272,
298,
17726,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
499,
467,
272,
298,
17726,
15181,
2,
257,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
650,
467,
272,
298,
9325,
2,
263,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
841,
467,
272,
298,
14325,
4077,
2,
420,
520,
2097,
47,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
14325,
4116,
2,
420,
520,
2097,
47,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
14325,
3308,
2,
420,
520,
2097,
47,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
12056,
266,
81,
2,
755,
520,
2097,
37,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1430,
4116,
2,
755,
520,
2097,
37,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1430,
3308,
2,
755,
520,
2097,
37,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
789,
199,
199,
3,
9101,
4503,
2556,
199,
318,
4503,
837,
272,
870,
298,
2591,
13,
8234,
14,
647,
25549,
67,
446,
72,
446,
81,
446,
84,
30,
665,
21091,
4335,
272,
870,
298,
446,
67,
259,
2929,
6786,
2410,
1642,
1414,
2,
272,
870,
298,
446,
72,
259,
1720,
2,
272,
870,
298,
446,
81,
259,
11971,
818,
2,
272,
870,
298,
446,
84,
259,
511,
818,
334,
7093,
1104,
2924,
272,
870,
298,
30530,
26,
1586,
511,
8929,
687,
30530,
2,
272,
870,
298,
4257,
687,
9009,
2,
272,
372,
199,
199,
3,
9101,
6696,
1380,
440,
315,
11971,
818,
199,
318,
6696,
8,
495,
304,
272,
340,
440,
11971,
26,
267,
870,
620,
199,
199,
3,
14279,
261,
282,
2004,
574,
199,
318,
21297,
8,
637,
12,
2746,
12,
1680,
304,
339,
26111,
275,
1109,
8,
637,
9,
339,
340,
2746,
59,
16,
61,
508,
298,
45,
582,
267,
26111,
275,
26111,
1182,
334,
709,
1011,
1109,
8,
1273,
430,
199,
198,
442,
637,
275,
26111,
450,
1616,
267,
27610,
275,
2746,
59,
18,
61,
272,
916,
2746,
59,
16,
61,
508,
298,
47,
582,
267,
27610,
275,
1109,
8,
1760,
63,
22022,
14,
362,
8,
1273,
12,
1680,
430,
272,
587,
26,
267,
27610,
275,
1109,
8,
1273,
9,
339,
327,
6696,
3647,
68,
450,
83,
450,
68,
2,
2818,
442,
637,
12,
2746,
59,
17,
467,
27610,
430,
339,
340,
2746,
59,
17,
61,
508,
298,
4077,
2,
436,
26111,
508,
27610,
26,
199,
198,
1107,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
4116,
2,
436,
26111,
665,
27610,
26,
267,
372,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
3308,
2,
436,
26111,
690,
27610,
26,
199,
198,
1107,
413,
272,
372,
378,
199,
199,
3,
6077,
314,
28279,
199,
893,
26,
272,
334,
1419,
12,
2368,
9,
275,
12733,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
7,
335,
8440,
358,
199,
2590,
12733,
14,
1002,
29368,
12,
444,
26,
272,
4503,
342,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
3,
6077,
28279,
1511,
199,
509,
945,
12,
574,
315,
1511,
26,
272,
340,
945,
508,
3905,
67,
582,
267,
6786,
275,
413,
272,
916,
945,
508,
3905,
81,
582,
267,
11971,
275,
413,
272,
916,
945,
508,
3905,
84,
582,
267,
511,
275,
413,
272,
916,
945,
508,
2475,
72,
356,
267,
4503,
342,
267,
984,
14,
2224,
8,
16,
9,
199,
199,
3,
9496,
314,
1324,
1350,
199,
692,
2368,
26,
272,
862,
26,
267,
6111,
275,
1551,
8,
4958,
59,
16,
566,
272,
871,
2186,
12,
476,
26,
267,
984,
14,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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
] |
qitianchan/flaskbb
|
flaskbb/message/forms.py
|
4
|
2608
|
# -*- coding: utf-8 -*-
"""
flaskbb.message.forms
~~~~~~~~~~~~~~~~~~~~~
It provides the forms that are needed for the message views.
:copyright: (c) 2014 by the FlaskBB Team.
:license: BSD, see LICENSE for more details.
"""
from flask_login import current_user
from flask_wtf import Form
from wtforms import StringField, TextAreaField, ValidationError, SubmitField
from wtforms.validators import DataRequired
from flask_babelex import lazy_gettext as _
from flaskbb.user.models import User
from flaskbb.message.models import Conversation, Message
class ConversationForm(Form):
to_user = StringField(_("To User"), validators=[
DataRequired(message=_("A Username is required."))])
subject = StringField(_("Subject"), validators=[
DataRequired(message=_("A Subject is required."))])
message = TextAreaField(_("Message"), validators=[
DataRequired(message=_("A Message is required."))])
send_message = SubmitField(_("Start Conversation"))
save_message = SubmitField(_("Save Conversation"))
def validate_to_user(self, field):
user = User.query.filter_by(username=field.data).first()
if not user:
raise ValidationError(_("The Username you entered doesn't exist"))
if user.id == current_user.id:
raise ValidationError(_("You cannot send a PM to yourself."))
def save(self, from_user, to_user, user_id, unread, as_draft=False,
shared_id=None):
conversation = Conversation(
subject=self.subject.data,
draft=as_draft,
shared_id=shared_id,
from_user_id=from_user,
to_user_id=to_user,
user_id=user_id,
unread=unread
)
message = Message(message=self.message.data, user_id=from_user)
return conversation.save(message=message)
class MessageForm(Form):
message = TextAreaField(_("Message"), validators=[
DataRequired(message=_("A Message is required."))])
submit = SubmitField(_("Send Message"))
def save(self, conversation, user_id, unread=False):
"""Saves the form data to the model.
:param conversation: The Conversation object.
:param user_id: The id from the user who sent the message.
:param reciever: If the message should also be stored in the recievers
inbox.
"""
message = Message(message=self.message.data, user_id=user_id)
if unread:
conversation.unread = True
conversation.save()
return message.save(conversation)
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
7209,
2501,
14,
1188,
14,
3351,
272,
18294,
2878,
94,
339,
2779,
6571,
314,
4513,
626,
787,
4346,
367,
314,
1245,
6858,
14,
339,
520,
7307,
26,
334,
67,
9,
6927,
701,
314,
16704,
5342,
11682,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
504,
7209,
63,
2886,
492,
1453,
63,
751,
199,
504,
7209,
63,
87,
3249,
492,
8204,
199,
504,
24756,
3351,
492,
21409,
12,
4516,
11043,
792,
12,
8505,
12,
28295,
792,
199,
504,
24756,
3351,
14,
11346,
492,
3918,
8030,
199,
504,
7209,
63,
66,
7570,
3113,
492,
9617,
63,
5152,
465,
485,
199,
199,
504,
7209,
2501,
14,
751,
14,
992,
492,
2876,
199,
504,
7209,
2501,
14,
1188,
14,
992,
492,
11801,
20592,
12,
6430,
421,
199,
533,
11801,
20592,
2821,
8,
2821,
304,
272,
370,
63,
751,
275,
21409,
6115,
1378,
2876,
1288,
14370,
1524,
267,
3918,
8030,
8,
1188,
9384,
33,
29739,
365,
1415,
13853,
566,
339,
5420,
275,
21409,
6115,
13528,
1288,
14370,
1524,
267,
3918,
8030,
8,
1188,
9384,
33,
26793,
365,
1415,
13853,
566,
339,
1245,
275,
4516,
11043,
792,
6115,
2209,
1288,
14370,
1524,
267,
3918,
8030,
8,
1188,
9384,
33,
6430,
365,
1415,
13853,
566,
339,
3222,
63,
1188,
275,
28295,
792,
6115,
3162,
11801,
20592,
2237,
272,
3354,
63,
1188,
275,
28295,
792,
6115,
8229,
11801,
20592,
2237,
339,
347,
4107,
63,
475,
63,
751,
8,
277,
12,
901,
304,
267,
922,
275,
2876,
14,
1131,
14,
1541,
63,
991,
8,
2473,
29,
698,
14,
576,
680,
2246,
342,
267,
340,
440,
922,
26,
288,
746,
8505,
6115,
1918,
29739,
1265,
19138,
3181,
1133,
2187,
2237,
267,
340,
922,
14,
344,
508,
1453,
63,
751,
14,
344,
26,
288,
746,
8505,
6115,
5556,
3913,
3222,
282,
27320,
370,
28225,
13853,
339,
347,
3354,
8,
277,
12,
687,
63,
751,
12,
370,
63,
751,
12,
922,
63,
344,
12,
625,
739,
12,
465,
63,
7185,
29,
797,
12,
1467,
5709,
63,
344,
29,
403,
304,
398,
3818,
20592,
275,
11801,
20592,
8,
288,
5420,
29,
277,
14,
5875,
14,
576,
12,
288,
11872,
29,
305,
63,
7185,
12,
288,
5709,
63,
344,
29,
5555,
63,
344,
12,
288,
687,
63,
751,
63,
344,
29,
504,
63,
751,
12,
288,
370,
63,
751,
63,
344,
29,
475,
63,
751,
12,
288,
922,
63,
344,
29,
751,
63,
344,
12,
288,
625,
739,
29,
28677,
267,
776,
267,
1245,
275,
6430,
8,
1188,
29,
277,
14,
1188,
14,
576,
12,
922,
63,
344,
29,
504,
63,
751,
9,
267,
372,
3818,
20592,
14,
2117,
8,
1188,
29,
1188,
9,
421,
199,
533,
6430,
2821,
8,
2821,
304,
272,
1245,
275,
4516,
11043,
792,
6115,
2209,
1288,
14370,
1524,
267,
3918,
8030,
8,
1188,
9384,
33,
6430,
365,
1415,
13853,
566,
272,
11482,
275,
28295,
792,
6115,
6795,
6430,
2237,
339,
347,
3354,
8,
277,
12,
3818,
20592,
12,
922,
63,
344,
12,
625,
739,
29,
797,
304,
267,
408,
51,
7047,
314,
1824,
666,
370,
314,
1402,
14,
267,
520,
635,
3818,
20592,
26,
710,
11801,
20592,
909,
14,
267,
520,
635,
922,
63,
344,
26,
710,
1305,
687,
314,
922,
3963,
4847,
314,
1245,
14,
267,
520,
635,
295,
559,
5907,
26,
982,
314,
1245,
1077,
2597,
506,
5489,
315,
314,
295,
559,
5907,
83,
586,
315,
1977,
14,
267,
408,
267,
1245,
275,
6430,
8,
1188,
29,
277,
14,
1188,
14,
576,
12,
922,
63,
344,
29,
751,
63,
344,
9,
398,
340,
625,
739,
26,
288,
3818,
20592,
14,
28677,
275,
715,
288,
3818,
20592,
14,
2117,
342,
267,
372,
1245,
14,
2117,
8,
6435,
20592,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
7209,
2501,
14,
1188,
14,
3351,
272,
18294,
2878,
94,
339,
2779,
6571,
314,
4513,
626,
787,
4346,
367,
314,
1245,
6858,
14,
339,
520,
7307,
26,
334,
67,
9,
6927,
701,
314,
16704,
5342,
11682,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
504,
7209,
63,
2886,
492,
1453,
63,
751,
199,
504,
7209,
63,
87,
3249,
492,
8204,
199,
504,
24756,
3351,
492,
21409,
12,
4516,
11043,
792,
12,
8505,
12,
28295,
792,
199,
504,
24756,
3351,
14,
11346,
492,
3918,
8030,
199,
504,
7209,
63,
66,
7570,
3113,
492,
9617,
63,
5152,
465,
485,
199,
199,
504,
7209,
2501,
14,
751,
14,
992,
492,
2876,
199,
504,
7209,
2501,
14,
1188,
14,
992,
492,
11801,
20592,
12,
6430,
421,
199,
533,
11801,
20592,
2821,
8,
2821,
304,
272,
370,
63,
751,
275,
21409,
6115,
1378,
2876,
1288,
14370,
1524,
267,
3918,
8030,
8,
1188,
9384,
33,
29739,
365,
1415,
13853,
566,
339,
5420,
275,
21409,
6115,
13528,
1288,
14370,
1524,
267,
3918,
8030,
8,
1188,
9384,
33,
26793,
365,
1415,
13853,
566,
339,
1245,
275,
4516,
11043,
792,
6115,
2209,
1288,
14370,
1524,
267,
3918,
8030,
8,
1188,
9384,
33,
6430,
365,
1415,
13853,
566,
339,
3222,
63,
1188,
275,
28295,
792,
6115,
3162,
11801,
20592,
2237,
272,
3354,
63,
1188,
275,
28295,
792,
6115,
8229,
11801,
20592,
2237,
339,
347,
4107,
63,
475,
63,
751,
8,
277,
12,
901,
304,
267,
922,
275,
2876,
14,
1131,
14,
1541,
63,
991,
8,
2473,
29,
698,
14,
576,
680,
2246,
342,
267,
340,
440,
922,
26,
288,
746,
8505,
6115,
1918,
29739,
1265,
19138,
3181,
1133,
2187,
2237,
267,
340,
922,
14,
344,
508,
1453,
63,
751,
14,
344,
26,
288,
746,
8505,
6115,
5556,
3913,
3222,
282,
27320,
370,
28225,
13853,
339,
347,
3354,
8,
277,
12,
687,
63,
751,
12,
370,
63,
751,
12,
922,
63,
344,
12,
625,
739,
12,
465,
63,
7185,
29,
797,
12,
1467,
5709,
63,
344,
29,
403,
304,
398,
3818,
20592,
275,
11801,
20592,
8,
288,
5420,
29,
277,
14,
5875,
14,
576,
12,
288,
11872,
29,
305,
63,
7185,
12,
288,
5709,
63,
344,
29,
5555,
63,
344,
12,
288,
687,
63,
751,
63,
344,
29,
504,
63,
751,
12,
288,
370,
63,
751,
63,
344,
29,
475,
63,
751,
12,
288,
922,
63,
344,
29,
751,
63,
344,
12,
288,
625,
739,
29,
28677,
267,
776,
267,
1245,
275,
6430,
8,
1188,
29,
277,
14,
1188,
14,
576,
12,
922,
63,
344,
29,
504,
63,
751,
9,
267,
372,
3818,
20592,
14,
2117,
8,
1188,
29,
1188,
9,
421,
199,
533,
6430,
2821,
8,
2821,
304,
272,
1245,
275,
4516,
11043,
792,
6115,
2209,
1288,
14370,
1524,
267,
3918,
8030,
8,
1188,
9384,
33,
6430,
365,
1415,
13853,
566,
272,
11482,
275,
28295,
792,
6115,
6795,
6430,
2237,
339,
347,
3354,
8,
277,
12,
3818,
20592,
12,
922,
63,
344,
12,
625,
739,
29,
797,
304,
267,
408,
51,
7047,
314,
1824,
666,
370,
314,
1402,
14,
267,
520,
635,
3818,
20592,
26,
710,
11801,
20592,
909,
14,
267,
520,
635,
922,
63,
344,
26,
710,
1305,
687,
314,
922,
3963,
4847,
314,
1245,
14,
267,
520,
635,
295,
559,
5907,
26,
982,
314,
1245,
1077,
2597,
506,
5489,
315,
314,
295,
559,
5907,
83,
586,
315,
1977,
14,
267,
408,
267,
1245,
275,
6430,
8,
1188,
29,
277,
14,
1188,
14,
576,
12,
922,
63,
344,
29,
751,
63,
344,
9,
398,
340,
625,
739,
26,
288,
3818,
20592,
14,
28677,
275,
715,
288,
3818,
20592,
14,
2117,
342,
267,
372,
1245,
14,
2117,
8,
6435,
20592,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
antfu/biconfigs
|
tests/test_biconfigs.py
|
1
|
3233
|
import biconfigs
import time
import pytest
import datetime
write_count = 0
def test_callbacks_sync():
global write_count
write_count = 0
def before_save(config):
if config.get('abort_save', False):
return False
config = biconfigs.Biconfigs(
before_save=before_save,
parser='json',
async_write=False
)
# Hack to check write times
old_write = config._Biconfigs__write
def alter_write(*args):
global write_count
old_write(*args)
write_count += 1
config._Biconfigs__write = alter_write
assert write_count == 0
config['123'] = '123'
assert write_count == 1
config['abort_save'] = True
assert write_count == 1
config['321'] = '321'
assert write_count == 1
del(config['abort_save'])
assert write_count == 2
write_count = 0
config['123'] = '1234'
assert write_count == 1
config._unbind()
config['123'] = '12345'
assert write_count == 1
config._rebind()
assert write_count == 2
class TestBlocking():
def setup_class(self):
self.writefinished = True
self.writing = False
self.blocking_config = biconfigs.Biconfigs(async_write=False)
self.non_blocking_config = biconfigs.Biconfigs(async_write=True)
def fake_write(*args):
self.writing = True
time.sleep(0.01)
while not self.writefinished:
time.sleep(0.01)
self.writing = False
self.blocking_config._Biconfigs__write = fake_write
self.non_blocking_config._Biconfigs__write = fake_write
def test_blocking(self):
self.blocking_config['item'] = 'value'
assert self.writing == False
def test_non_blocking(self):
assert self.writing == False
self.writefinished = False
self.non_blocking_config['item'] = 'value'
assert self.writing == True
self.writefinished = True
time.sleep(0.03)
assert self.writing == False
def test_invalid_parser_storages():
with pytest.raises(biconfigs.InvalidPaserError):
biconfigs.Biconfigs(parser='invalid_parser')
with pytest.raises(biconfigs.InvalidStorageError):
biconfigs.Biconfigs(storage='invalid_storage')
with pytest.raises(biconfigs.AlreadyCreatedError):
a = biconfigs.Biconfigs(path='tests/.test1.json')
b = biconfigs.Biconfigs(path='tests/.test1.json')
def test_io_expections():
with pytest.raises(biconfigs.InvaildFilePathError):
biconfigs.Biconfigs('/')
with pytest.raises(biconfigs.InvaildFilePathError):
biconfigs.Biconfigs('..')
with pytest.raises(biconfigs.OpenFileError):
biconfigs.Biconfigs(path='tests/not_exits/file')
def test_loads_dumps_expections():
# Loads
with open('tests/.test2.json', 'w') as f:
f.write('!!Invaild json file')
with pytest.raises(biconfigs.LoadError):
biconfigs.Biconfigs(path='tests/.test2.json')
# Dumps
c = biconfigs.Biconfigs(path='tests/.test3.json', async_write=False)
# class "datetime" is not JSON serializable
with pytest.raises(biconfigs.DumpError):
c[time.time()] = datetime.datetime.now()
|
mit
|
[
646,
330,
4677,
5513,
199,
646,
900,
199,
646,
4613,
199,
646,
2197,
199,
199,
952,
63,
835,
275,
378,
199,
318,
511,
63,
11948,
63,
5186,
837,
272,
2288,
2218,
63,
835,
272,
2218,
63,
835,
275,
378,
339,
347,
2544,
63,
2117,
8,
888,
304,
267,
340,
1101,
14,
362,
360,
13845,
63,
2117,
297,
756,
304,
288,
372,
756,
339,
1101,
275,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
267,
2544,
63,
2117,
29,
5182,
63,
2117,
12,
267,
1798,
534,
1001,
297,
267,
5316,
63,
952,
29,
797,
272,
776,
339,
327,
30802,
370,
1104,
2218,
5431,
272,
2269,
63,
952,
275,
1101,
423,
34,
4677,
5513,
363,
952,
272,
347,
17355,
63,
952,
2031,
589,
304,
267,
2288,
2218,
63,
835,
267,
2269,
63,
952,
2031,
589,
9,
267,
2218,
63,
835,
847,
413,
272,
1101,
423,
34,
4677,
5513,
363,
952,
275,
17355,
63,
952,
339,
702,
2218,
63,
835,
508,
378,
272,
1101,
459,
4288,
418,
275,
283,
4288,
7,
272,
702,
2218,
63,
835,
508,
413,
272,
1101,
459,
13845,
63,
2117,
418,
275,
715,
272,
702,
2218,
63,
835,
508,
413,
272,
1101,
459,
12638,
418,
275,
283,
12638,
7,
272,
702,
2218,
63,
835,
508,
413,
272,
2150,
8,
888,
459,
13845,
63,
2117,
1105,
272,
702,
2218,
63,
835,
508,
499,
339,
2218,
63,
835,
275,
378,
272,
1101,
459,
4288,
418,
275,
283,
4321,
7,
272,
702,
2218,
63,
835,
508,
413,
272,
1101,
423,
324,
3409,
342,
272,
1101,
459,
4288,
418,
275,
283,
13261,
7,
272,
702,
2218,
63,
835,
508,
413,
272,
1101,
423,
264,
3409,
342,
272,
702,
2218,
63,
835,
508,
499,
199,
199,
533,
1379,
27132,
837,
272,
347,
3272,
63,
533,
8,
277,
304,
267,
291,
14,
952,
8669,
275,
715,
267,
291,
14,
14827,
275,
756,
267,
291,
14,
13091,
63,
888,
275,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
4146,
63,
952,
29,
797,
9,
267,
291,
14,
2865,
63,
13091,
63,
888,
275,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
4146,
63,
952,
29,
549,
9,
398,
347,
4026,
63,
952,
2031,
589,
304,
288,
291,
14,
14827,
275,
715,
288,
900,
14,
4532,
8,
16,
14,
614,
9,
288,
1830,
440,
291,
14,
952,
8669,
26,
355,
900,
14,
4532,
8,
16,
14,
614,
9,
288,
291,
14,
14827,
275,
756,
398,
291,
14,
13091,
63,
888,
423,
34,
4677,
5513,
363,
952,
275,
4026,
63,
952,
267,
291,
14,
2865,
63,
13091,
63,
888,
423,
34,
4677,
5513,
363,
952,
275,
4026,
63,
952,
339,
347,
511,
63,
13091,
8,
277,
304,
267,
291,
14,
13091,
63,
888,
459,
1053,
418,
275,
283,
585,
7,
267,
702,
291,
14,
14827,
508,
756,
339,
347,
511,
63,
2865,
63,
13091,
8,
277,
304,
267,
702,
291,
14,
14827,
508,
756,
267,
291,
14,
952,
8669,
275,
756,
267,
291,
14,
2865,
63,
13091,
63,
888,
459,
1053,
418,
275,
283,
585,
7,
267,
702,
291,
14,
14827,
508,
715,
267,
291,
14,
952,
8669,
275,
715,
267,
900,
14,
4532,
8,
16,
14,
1644,
9,
267,
702,
291,
14,
14827,
508,
756,
199,
199,
318,
511,
63,
3197,
63,
2087,
63,
3494,
83,
837,
272,
543,
4613,
14,
3536,
8,
4492,
7532,
14,
3364,
4232,
332,
547,
304,
267,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
2087,
534,
3197,
63,
2087,
358,
339,
543,
4613,
14,
3536,
8,
4492,
7532,
14,
3364,
6408,
547,
304,
267,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
3494,
534,
3197,
63,
3494,
358,
339,
543,
4613,
14,
3536,
8,
4492,
7532,
14,
16760,
10502,
547,
304,
267,
282,
275,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
515,
534,
2219,
8083,
396,
17,
14,
1001,
358,
267,
330,
275,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
515,
534,
2219,
8083,
396,
17,
14,
1001,
358,
421,
199,
318,
511,
63,
2308,
63,
476,
321,
2452,
837,
272,
543,
4613,
14,
3536,
8,
4492,
7532,
14,
607,
3042,
668,
14225,
547,
304,
267,
330,
4677,
5513,
14,
34,
4677,
5513,
7825,
339,
543,
4613,
14,
3536,
8,
4492,
7532,
14,
607,
3042,
668,
14225,
547,
304,
267,
330,
4677,
5513,
14,
34,
4677,
5513,
24893,
358,
339,
543,
4613,
14,
3536,
8,
4492,
7532,
14,
4299,
25212,
304,
267,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
515,
534,
2219,
15,
1397,
63,
476,
1405,
15,
493,
358,
199,
199,
318,
511,
63,
3640,
63,
4180,
63,
476,
321,
2452,
837,
272,
327,
30367,
272,
543,
1551,
360,
2219,
8083,
396,
18,
14,
1001,
297,
283,
87,
358,
465,
289,
26,
267,
289,
14,
952,
360,
3480,
607,
3042,
668,
2022,
570,
358,
272,
543,
4613,
14,
3536,
8,
4492,
7532,
14,
6200,
547,
304,
267,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
515,
534,
2219,
8083,
396,
18,
14,
1001,
358,
339,
327,
19460,
83,
272,
286,
275,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
515,
534,
2219,
8083,
396,
19,
14,
1001,
297,
5316,
63,
952,
29,
797,
9,
272,
327,
1021,
298,
2083,
2,
365,
440,
4840,
31244,
272,
543,
4613,
14,
3536,
8,
4492,
7532,
14,
11772,
547,
304,
267,
286,
59,
521,
14,
521,
5106,
275,
2197,
14,
2083,
14,
2131,
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
] |
[
330,
4677,
5513,
199,
646,
900,
199,
646,
4613,
199,
646,
2197,
199,
199,
952,
63,
835,
275,
378,
199,
318,
511,
63,
11948,
63,
5186,
837,
272,
2288,
2218,
63,
835,
272,
2218,
63,
835,
275,
378,
339,
347,
2544,
63,
2117,
8,
888,
304,
267,
340,
1101,
14,
362,
360,
13845,
63,
2117,
297,
756,
304,
288,
372,
756,
339,
1101,
275,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
267,
2544,
63,
2117,
29,
5182,
63,
2117,
12,
267,
1798,
534,
1001,
297,
267,
5316,
63,
952,
29,
797,
272,
776,
339,
327,
30802,
370,
1104,
2218,
5431,
272,
2269,
63,
952,
275,
1101,
423,
34,
4677,
5513,
363,
952,
272,
347,
17355,
63,
952,
2031,
589,
304,
267,
2288,
2218,
63,
835,
267,
2269,
63,
952,
2031,
589,
9,
267,
2218,
63,
835,
847,
413,
272,
1101,
423,
34,
4677,
5513,
363,
952,
275,
17355,
63,
952,
339,
702,
2218,
63,
835,
508,
378,
272,
1101,
459,
4288,
418,
275,
283,
4288,
7,
272,
702,
2218,
63,
835,
508,
413,
272,
1101,
459,
13845,
63,
2117,
418,
275,
715,
272,
702,
2218,
63,
835,
508,
413,
272,
1101,
459,
12638,
418,
275,
283,
12638,
7,
272,
702,
2218,
63,
835,
508,
413,
272,
2150,
8,
888,
459,
13845,
63,
2117,
1105,
272,
702,
2218,
63,
835,
508,
499,
339,
2218,
63,
835,
275,
378,
272,
1101,
459,
4288,
418,
275,
283,
4321,
7,
272,
702,
2218,
63,
835,
508,
413,
272,
1101,
423,
324,
3409,
342,
272,
1101,
459,
4288,
418,
275,
283,
13261,
7,
272,
702,
2218,
63,
835,
508,
413,
272,
1101,
423,
264,
3409,
342,
272,
702,
2218,
63,
835,
508,
499,
199,
199,
533,
1379,
27132,
837,
272,
347,
3272,
63,
533,
8,
277,
304,
267,
291,
14,
952,
8669,
275,
715,
267,
291,
14,
14827,
275,
756,
267,
291,
14,
13091,
63,
888,
275,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
4146,
63,
952,
29,
797,
9,
267,
291,
14,
2865,
63,
13091,
63,
888,
275,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
4146,
63,
952,
29,
549,
9,
398,
347,
4026,
63,
952,
2031,
589,
304,
288,
291,
14,
14827,
275,
715,
288,
900,
14,
4532,
8,
16,
14,
614,
9,
288,
1830,
440,
291,
14,
952,
8669,
26,
355,
900,
14,
4532,
8,
16,
14,
614,
9,
288,
291,
14,
14827,
275,
756,
398,
291,
14,
13091,
63,
888,
423,
34,
4677,
5513,
363,
952,
275,
4026,
63,
952,
267,
291,
14,
2865,
63,
13091,
63,
888,
423,
34,
4677,
5513,
363,
952,
275,
4026,
63,
952,
339,
347,
511,
63,
13091,
8,
277,
304,
267,
291,
14,
13091,
63,
888,
459,
1053,
418,
275,
283,
585,
7,
267,
702,
291,
14,
14827,
508,
756,
339,
347,
511,
63,
2865,
63,
13091,
8,
277,
304,
267,
702,
291,
14,
14827,
508,
756,
267,
291,
14,
952,
8669,
275,
756,
267,
291,
14,
2865,
63,
13091,
63,
888,
459,
1053,
418,
275,
283,
585,
7,
267,
702,
291,
14,
14827,
508,
715,
267,
291,
14,
952,
8669,
275,
715,
267,
900,
14,
4532,
8,
16,
14,
1644,
9,
267,
702,
291,
14,
14827,
508,
756,
199,
199,
318,
511,
63,
3197,
63,
2087,
63,
3494,
83,
837,
272,
543,
4613,
14,
3536,
8,
4492,
7532,
14,
3364,
4232,
332,
547,
304,
267,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
2087,
534,
3197,
63,
2087,
358,
339,
543,
4613,
14,
3536,
8,
4492,
7532,
14,
3364,
6408,
547,
304,
267,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
3494,
534,
3197,
63,
3494,
358,
339,
543,
4613,
14,
3536,
8,
4492,
7532,
14,
16760,
10502,
547,
304,
267,
282,
275,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
515,
534,
2219,
8083,
396,
17,
14,
1001,
358,
267,
330,
275,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
515,
534,
2219,
8083,
396,
17,
14,
1001,
358,
421,
199,
318,
511,
63,
2308,
63,
476,
321,
2452,
837,
272,
543,
4613,
14,
3536,
8,
4492,
7532,
14,
607,
3042,
668,
14225,
547,
304,
267,
330,
4677,
5513,
14,
34,
4677,
5513,
7825,
339,
543,
4613,
14,
3536,
8,
4492,
7532,
14,
607,
3042,
668,
14225,
547,
304,
267,
330,
4677,
5513,
14,
34,
4677,
5513,
24893,
358,
339,
543,
4613,
14,
3536,
8,
4492,
7532,
14,
4299,
25212,
304,
267,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
515,
534,
2219,
15,
1397,
63,
476,
1405,
15,
493,
358,
199,
199,
318,
511,
63,
3640,
63,
4180,
63,
476,
321,
2452,
837,
272,
327,
30367,
272,
543,
1551,
360,
2219,
8083,
396,
18,
14,
1001,
297,
283,
87,
358,
465,
289,
26,
267,
289,
14,
952,
360,
3480,
607,
3042,
668,
2022,
570,
358,
272,
543,
4613,
14,
3536,
8,
4492,
7532,
14,
6200,
547,
304,
267,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
515,
534,
2219,
8083,
396,
18,
14,
1001,
358,
339,
327,
19460,
83,
272,
286,
275,
330,
4677,
5513,
14,
34,
4677,
5513,
8,
515,
534,
2219,
8083,
396,
19,
14,
1001,
297,
5316,
63,
952,
29,
797,
9,
272,
327,
1021,
298,
2083,
2,
365,
440,
4840,
31244,
272,
543,
4613,
14,
3536,
8,
4492,
7532,
14,
11772,
547,
304,
267,
286,
59,
521,
14,
521,
5106,
275,
2197,
14,
2083,
14,
2131,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
azureplus/hue
|
desktop/core/ext-py/pycrypto-2.6.1/lib/Crypto/SelfTest/Cipher/common.py
|
115
|
16599
|
# -*- coding: utf-8 -*-
#
# SelfTest/Hash/common.py: Common code for Crypto.SelfTest.Hash
#
# Written in 2008 by Dwayne C. Litzenberger <dlitz@dlitz.net>
#
# ===================================================================
# The contents of this file are dedicated to the public domain. To
# the extent that dedication to the public domain is not available,
# everyone is granted a worldwide, perpetual, royalty-free,
# non-exclusive license to exercise all rights associated with the
# contents of this file for any purpose whatsoever.
# No rights are reserved.
#
# 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.
# ===================================================================
"""Self-testing for PyCrypto hash modules"""
__revision__ = "$Id$"
import sys
import unittest
from binascii import a2b_hex, b2a_hex
from Crypto.Util.py3compat import *
# For compatibility with Python 2.1 and Python 2.2
if sys.hexversion < 0x02030000:
# Python 2.1 doesn't have a dict() function
# Python 2.2 dict() function raises TypeError if you do dict(MD5='blah')
def dict(**kwargs):
return kwargs.copy()
else:
dict = dict
class _NoDefault: pass # sentinel object
def _extract(d, k, default=_NoDefault):
"""Get an item from a dictionary, and remove it from the dictionary."""
try:
retval = d[k]
except KeyError:
if default is _NoDefault:
raise
return default
del d[k]
return retval
# Generic cipher test case
class CipherSelfTest(unittest.TestCase):
def __init__(self, module, params):
unittest.TestCase.__init__(self)
self.module = module
# Extract the parameters
params = params.copy()
self.description = _extract(params, 'description')
self.key = b(_extract(params, 'key'))
self.plaintext = b(_extract(params, 'plaintext'))
self.ciphertext = b(_extract(params, 'ciphertext'))
self.module_name = _extract(params, 'module_name', None)
mode = _extract(params, 'mode', None)
self.mode_name = str(mode)
if mode is not None:
# Block cipher
self.mode = getattr(self.module, "MODE_" + mode)
self.iv = _extract(params, 'iv', None)
if self.iv is not None: self.iv = b(self.iv)
# Only relevant for OPENPGP mode
self.encrypted_iv = _extract(params, 'encrypted_iv', None)
if self.encrypted_iv is not None:
self.encrypted_iv = b(self.encrypted_iv)
else:
# Stream cipher
self.mode = None
self.iv = None
self.extra_params = params
def shortDescription(self):
return self.description
def _new(self, do_decryption=0):
params = self.extra_params.copy()
# Handle CTR mode parameters. By default, we use Counter.new(self.module.block_size)
if hasattr(self.module, "MODE_CTR") and self.mode == self.module.MODE_CTR:
from Crypto.Util import Counter
ctr_class = _extract(params, 'ctr_class', Counter.new)
ctr_params = _extract(params, 'ctr_params', {}).copy()
if ctr_params.has_key('prefix'): ctr_params['prefix'] = a2b_hex(b(ctr_params['prefix']))
if ctr_params.has_key('suffix'): ctr_params['suffix'] = a2b_hex(b(ctr_params['suffix']))
if not ctr_params.has_key('nbits'):
ctr_params['nbits'] = 8*(self.module.block_size - len(ctr_params.get('prefix', '')) - len(ctr_params.get('suffix', '')))
params['counter'] = ctr_class(**ctr_params)
if self.mode is None:
# Stream cipher
return self.module.new(a2b_hex(self.key), **params)
elif self.iv is None:
# Block cipher without iv
return self.module.new(a2b_hex(self.key), self.mode, **params)
else:
# Block cipher with iv
if do_decryption and self.mode == self.module.MODE_OPENPGP:
# In PGP mode, the IV to feed for decryption is the *encrypted* one
return self.module.new(a2b_hex(self.key), self.mode, a2b_hex(self.encrypted_iv), **params)
else:
return self.module.new(a2b_hex(self.key), self.mode, a2b_hex(self.iv), **params)
def runTest(self):
plaintext = a2b_hex(self.plaintext)
ciphertext = a2b_hex(self.ciphertext)
ct1 = b2a_hex(self._new().encrypt(plaintext))
pt1 = b2a_hex(self._new(1).decrypt(ciphertext))
ct2 = b2a_hex(self._new().encrypt(plaintext))
pt2 = b2a_hex(self._new(1).decrypt(ciphertext))
if hasattr(self.module, "MODE_OPENPGP") and self.mode == self.module.MODE_OPENPGP:
# In PGP mode, data returned by the first encrypt()
# is prefixed with the encrypted IV.
# Here we check it and then remove it from the ciphertexts.
eilen = len(self.encrypted_iv)
self.assertEqual(self.encrypted_iv, ct1[:eilen])
self.assertEqual(self.encrypted_iv, ct2[:eilen])
ct1 = ct1[eilen:]
ct2 = ct2[eilen:]
self.assertEqual(self.ciphertext, ct1) # encrypt
self.assertEqual(self.ciphertext, ct2) # encrypt (second time)
self.assertEqual(self.plaintext, pt1) # decrypt
self.assertEqual(self.plaintext, pt2) # decrypt (second time)
class CipherStreamingSelfTest(CipherSelfTest):
def shortDescription(self):
desc = self.module_name
if self.mode is not None:
desc += " in %s mode" % (self.mode_name,)
return "%s should behave like a stream cipher" % (desc,)
def runTest(self):
plaintext = a2b_hex(self.plaintext)
ciphertext = a2b_hex(self.ciphertext)
# The cipher should work like a stream cipher
# Test counter mode encryption, 3 bytes at a time
ct3 = []
cipher = self._new()
for i in range(0, len(plaintext), 3):
ct3.append(cipher.encrypt(plaintext[i:i+3]))
ct3 = b2a_hex(b("").join(ct3))
self.assertEqual(self.ciphertext, ct3) # encryption (3 bytes at a time)
# Test counter mode decryption, 3 bytes at a time
pt3 = []
cipher = self._new()
for i in range(0, len(ciphertext), 3):
pt3.append(cipher.encrypt(ciphertext[i:i+3]))
# PY3K: This is meant to be text, do not change to bytes (data)
pt3 = b2a_hex(b("").join(pt3))
self.assertEqual(self.plaintext, pt3) # decryption (3 bytes at a time)
class CTRSegfaultTest(unittest.TestCase):
def __init__(self, module, params):
unittest.TestCase.__init__(self)
self.module = module
self.key = b(params['key'])
self.module_name = params.get('module_name', None)
def shortDescription(self):
return """Regression test: %s.new(key, %s.MODE_CTR) should raise TypeError, not segfault""" % (self.module_name, self.module_name)
def runTest(self):
self.assertRaises(TypeError, self.module.new, a2b_hex(self.key), self.module.MODE_CTR)
class CTRWraparoundTest(unittest.TestCase):
def __init__(self, module, params):
unittest.TestCase.__init__(self)
self.module = module
self.key = b(params['key'])
self.module_name = params.get('module_name', None)
def shortDescription(self):
return """Regression test: %s with MODE_CTR should raise OverflowError on wraparound when shortcut used""" % (self.module_name,)
def runTest(self):
from Crypto.Util import Counter
for disable_shortcut in (0, 1): # (False, True) Test CTR-mode shortcut and PyObject_CallObject code paths
for little_endian in (0, 1): # (False, True) Test both endiannesses
ctr = Counter.new(8*self.module.block_size, initial_value=2L**(8*self.module.block_size)-1, little_endian=little_endian, disable_shortcut=disable_shortcut)
cipher = self.module.new(a2b_hex(self.key), self.module.MODE_CTR, counter=ctr)
block = b("\x00") * self.module.block_size
cipher.encrypt(block)
self.assertRaises(OverflowError, cipher.encrypt, block)
class CFBSegmentSizeTest(unittest.TestCase):
def __init__(self, module, params):
unittest.TestCase.__init__(self)
self.module = module
self.key = b(params['key'])
self.description = params['description']
def shortDescription(self):
return self.description
def runTest(self):
"""Regression test: m.new(key, m.MODE_CFB, segment_size=N) should require segment_size to be a multiple of 8 bits"""
for i in range(1, 8):
self.assertRaises(ValueError, self.module.new, a2b_hex(self.key), self.module.MODE_CFB, segment_size=i)
self.module.new(a2b_hex(self.key), self.module.MODE_CFB, "\0"*self.module.block_size, segment_size=8) # should succeed
class RoundtripTest(unittest.TestCase):
def __init__(self, module, params):
from Crypto import Random
unittest.TestCase.__init__(self)
self.module = module
self.iv = Random.get_random_bytes(module.block_size)
self.key = b(params['key'])
self.plaintext = 100 * b(params['plaintext'])
self.module_name = params.get('module_name', None)
def shortDescription(self):
return """%s .decrypt() output of .encrypt() should not be garbled""" % (self.module_name,)
def runTest(self):
for mode in (self.module.MODE_ECB, self.module.MODE_CBC, self.module.MODE_CFB, self.module.MODE_OFB, self.module.MODE_OPENPGP):
encryption_cipher = self.module.new(a2b_hex(self.key), mode, self.iv)
ciphertext = encryption_cipher.encrypt(self.plaintext)
if mode != self.module.MODE_OPENPGP:
decryption_cipher = self.module.new(a2b_hex(self.key), mode, self.iv)
else:
eiv = ciphertext[:self.module.block_size+2]
ciphertext = ciphertext[self.module.block_size+2:]
decryption_cipher = self.module.new(a2b_hex(self.key), mode, eiv)
decrypted_plaintext = decryption_cipher.decrypt(ciphertext)
self.assertEqual(self.plaintext, decrypted_plaintext)
class PGPTest(unittest.TestCase):
def __init__(self, module, params):
unittest.TestCase.__init__(self)
self.module = module
self.key = b(params['key'])
def shortDescription(self):
return "MODE_PGP was implemented incorrectly and insecurely. It's completely banished now."
def runTest(self):
self.assertRaises(ValueError, self.module.new, a2b_hex(self.key),
self.module.MODE_PGP)
class IVLengthTest(unittest.TestCase):
def __init__(self, module, params):
unittest.TestCase.__init__(self)
self.module = module
self.key = b(params['key'])
def shortDescription(self):
return "Check that all modes except MODE_ECB and MODE_CTR require an IV of the proper length"
def runTest(self):
self.assertRaises(ValueError, self.module.new, a2b_hex(self.key),
self.module.MODE_CBC, "")
self.assertRaises(ValueError, self.module.new, a2b_hex(self.key),
self.module.MODE_CFB, "")
self.assertRaises(ValueError, self.module.new, a2b_hex(self.key),
self.module.MODE_OFB, "")
self.assertRaises(ValueError, self.module.new, a2b_hex(self.key),
self.module.MODE_OPENPGP, "")
self.module.new(a2b_hex(self.key), self.module.MODE_ECB, "")
self.module.new(a2b_hex(self.key), self.module.MODE_CTR, "", counter=self._dummy_counter)
def _dummy_counter(self):
return "\0" * self.module.block_size
def make_block_tests(module, module_name, test_data):
tests = []
extra_tests_added = 0
for i in range(len(test_data)):
row = test_data[i]
# Build the "params" dictionary
params = {'mode': 'ECB'}
if len(row) == 3:
(params['plaintext'], params['ciphertext'], params['key']) = row
elif len(row) == 4:
(params['plaintext'], params['ciphertext'], params['key'], params['description']) = row
elif len(row) == 5:
(params['plaintext'], params['ciphertext'], params['key'], params['description'], extra_params) = row
params.update(extra_params)
else:
raise AssertionError("Unsupported tuple size %d" % (len(row),))
# Build the display-name for the test
p2 = params.copy()
p_key = _extract(p2, 'key')
p_plaintext = _extract(p2, 'plaintext')
p_ciphertext = _extract(p2, 'ciphertext')
p_description = _extract(p2, 'description', None)
p_mode = p2.get('mode', 'ECB')
if p_mode == 'ECB':
_extract(p2, 'mode', 'ECB')
if p_description is not None:
description = p_description
elif p_mode == 'ECB' and not p2:
description = "p=%s, k=%s" % (p_plaintext, p_key)
else:
description = "p=%s, k=%s, %r" % (p_plaintext, p_key, p2)
name = "%s #%d: %s" % (module_name, i+1, description)
params['description'] = name
params['module_name'] = module_name
# Add extra test(s) to the test suite before the current test
if not extra_tests_added:
tests += [
CTRSegfaultTest(module, params),
CTRWraparoundTest(module, params),
CFBSegmentSizeTest(module, params),
RoundtripTest(module, params),
PGPTest(module, params),
IVLengthTest(module, params),
]
extra_tests_added = 1
# Add the current test to the test suite
tests.append(CipherSelfTest(module, params))
# When using CTR mode, test that the interface behaves like a stream cipher
if p_mode == 'CTR':
tests.append(CipherStreamingSelfTest(module, params))
# When using CTR mode, test the non-shortcut code path.
if p_mode == 'CTR' and not params.has_key('ctr_class'):
params2 = params.copy()
params2['description'] += " (shortcut disabled)"
ctr_params2 = params.get('ctr_params', {}).copy()
params2['ctr_params'] = ctr_params2
if not params2['ctr_params'].has_key('disable_shortcut'):
params2['ctr_params']['disable_shortcut'] = 1
tests.append(CipherSelfTest(module, params2))
return tests
def make_stream_tests(module, module_name, test_data):
tests = []
for i in range(len(test_data)):
row = test_data[i]
# Build the "params" dictionary
params = {}
if len(row) == 3:
(params['plaintext'], params['ciphertext'], params['key']) = row
elif len(row) == 4:
(params['plaintext'], params['ciphertext'], params['key'], params['description']) = row
elif len(row) == 5:
(params['plaintext'], params['ciphertext'], params['key'], params['description'], extra_params) = row
params.update(extra_params)
else:
raise AssertionError("Unsupported tuple size %d" % (len(row),))
# Build the display-name for the test
p2 = params.copy()
p_key = _extract(p2, 'key')
p_plaintext = _extract(p2, 'plaintext')
p_ciphertext = _extract(p2, 'ciphertext')
p_description = _extract(p2, 'description', None)
if p_description is not None:
description = p_description
elif not p2:
description = "p=%s, k=%s" % (p_plaintext, p_key)
else:
description = "p=%s, k=%s, %r" % (p_plaintext, p_key, p2)
name = "%s #%d: %s" % (module_name, i+1, description)
params['description'] = name
params['module_name'] = module_name
# Add the test to the test suite
tests.append(CipherSelfTest(module, params))
tests.append(CipherStreamingSelfTest(module, params))
return tests
# vim:set ts=4 sw=4 sts=4 expandtab:
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
221,
23820,
774,
15,
3476,
15,
2330,
14,
647,
26,
13964,
1233,
367,
18855,
14,
12887,
774,
14,
3476,
199,
3,
199,
3,
27694,
315,
9079,
701,
577,
3316,
685,
445,
14,
491,
390,
5193,
605,
836,
665,
68,
29382,
32,
68,
29382,
14,
846,
30,
199,
3,
199,
3,
7819,
389,
199,
3,
710,
4072,
402,
642,
570,
787,
29711,
370,
314,
4575,
2881,
14,
221,
4005,
199,
3,
314,
13675,
626,
477,
21171,
370,
314,
4575,
2881,
365,
440,
2808,
12,
199,
3,
4036,
368,
365,
10009,
282,
6701,
13062,
12,
1126,
321,
1688,
12,
882,
89,
13248,
13,
4624,
12,
199,
3,
2222,
13,
12730,
4190,
370,
26511,
1006,
4481,
4568,
543,
314,
199,
3,
4072,
402,
642,
570,
367,
1263,
12016,
4052,
1152,
5907,
14,
199,
3,
3091,
4481,
787,
4644,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
199,
3,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
199,
3,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
199,
3,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
199,
3,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
3,
7819,
389,
199,
199,
624,
12887,
13,
4776,
367,
1611,
17134,
2631,
4621,
624,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
646,
984,
199,
646,
2882,
199,
504,
14755,
492,
282,
18,
66,
63,
4097,
12,
330,
18,
65,
63,
4097,
199,
504,
18855,
14,
9562,
14,
647,
19,
5819,
492,
627,
199,
199,
3,
2104,
7163,
543,
2018,
499,
14,
17,
436,
2018,
499,
14,
18,
199,
692,
984,
14,
4097,
1023,
665,
378,
88,
996,
1644,
993,
26,
272,
327,
2018,
499,
14,
17,
3181,
1133,
1172,
282,
1211,
342,
805,
272,
327,
2018,
499,
14,
18,
1211,
342,
805,
6534,
3146,
340,
1265,
886,
1211,
8,
5127,
21,
534,
12702,
358,
272,
347,
1211,
3682,
958,
304,
267,
372,
2074,
14,
1574,
342,
199,
2836,
26,
272,
1211,
275,
1211,
199,
199,
533,
485,
1944,
2698,
26,
986,
263,
327,
13792,
909,
199,
318,
485,
5005,
8,
68,
12,
1022,
12,
849,
3699,
1944,
2698,
304,
272,
408,
1002,
376,
1242,
687,
282,
2600,
12,
436,
2813,
652,
687,
314,
2600,
1041,
272,
862,
26,
267,
9151,
275,
366,
59,
75,
61,
272,
871,
4067,
26,
267,
340,
849,
365,
485,
1944,
2698,
26,
288,
746,
267,
372,
849,
272,
2150,
366,
59,
75,
61,
272,
372,
9151,
199,
199,
3,
8307,
10830,
511,
1930,
199,
533,
29683,
12887,
774,
8,
2796,
14,
1746,
304,
339,
347,
636,
826,
721,
277,
12,
859,
12,
1862,
304,
267,
2882,
14,
1746,
855,
826,
721,
277,
9,
267,
291,
14,
578,
275,
859,
398,
327,
12892,
314,
2633,
267,
1862,
275,
1862,
14,
1574,
342,
267,
291,
14,
1802,
275,
485,
5005,
8,
1162,
12,
283,
1802,
358,
267,
291,
14,
498,
275,
330,
1547,
5005,
8,
1162,
12,
283,
498,
1333,
267,
291,
14,
17426,
275,
330,
1547,
5005,
8,
1162,
12,
283,
17426,
1333,
267,
291,
14,
27661,
275,
330,
1547,
5005,
8,
1162,
12,
283,
27661,
1333,
267,
291,
14,
578,
63,
354,
275,
485,
5005,
8,
1162,
12,
283,
578,
63,
354,
297,
488,
9,
398,
818,
275,
485,
5005,
8,
1162,
12,
283,
632,
297,
488,
9,
267,
291,
14,
632,
63,
354,
275,
620,
8,
632,
9,
267,
340,
818,
365,
440,
488,
26,
288,
327,
8651,
10830,
288,
291,
14,
632,
275,
2519,
8,
277,
14,
578,
12,
298,
6963,
12172,
435,
818,
9,
288,
291,
14,
1003,
275,
485,
5005,
8,
1162,
12,
283,
1003,
297,
488,
9,
288,
340,
291,
14,
1003,
365,
440,
488,
26,
291,
14,
1003,
275,
330,
8,
277,
14,
1003,
9,
953,
327,
5972,
12082,
367,
24164,
48,
8225,
818,
288,
291,
14,
15078,
63,
1003,
275,
485,
5005,
8,
1162,
12,
283,
15078,
63,
1003,
297,
488,
9,
288,
340,
291,
14,
15078,
63,
1003,
365,
440,
488,
26,
355,
291,
14,
15078,
63,
1003,
275,
330,
8,
277,
14,
15078,
63,
1003,
9,
267,
587,
26,
288,
327,
8271,
10830,
288,
291,
14,
632,
275,
488,
288,
291,
14,
1003,
275,
488,
398,
291,
14,
2911,
63,
1162,
275,
1862,
339,
347,
3974,
5831,
8,
277,
304,
267,
372,
291,
14,
1802,
339,
347,
485,
1222,
8,
277,
12,
886,
63,
271,
7950,
29,
16,
304,
267,
1862,
275,
291,
14,
2911,
63,
1162,
14,
1574,
342,
398,
327,
8690,
445,
1766,
818,
2633,
14,
221,
4885,
849,
12,
781,
675,
14427,
14,
1222,
8,
277,
14,
578,
14,
1457,
63,
890,
9,
267,
340,
2688,
8,
277,
14,
578,
12,
298,
6963,
63,
1028,
50,
531,
436,
291,
14,
632,
508,
291,
14,
578,
14,
6963,
63,
1028,
50,
26,
288,
687,
18855,
14,
9562,
492,
14427,
288,
286,
454,
63,
533,
275,
485,
5005,
8,
1162,
12,
283,
18548,
63,
533,
297,
14427,
14,
1222,
9,
288,
286,
454,
63,
1162,
275,
485,
5005,
8,
1162,
12,
283,
18548,
63,
1162,
297,
13056,
1574,
342,
288,
340,
286,
454,
63,
1162,
14,
1989,
63,
498,
360,
1861,
735,
286,
454,
63,
1162,
459,
1861,
418,
275,
282,
18,
66,
63,
4097,
8,
66,
8,
18548,
63,
1162,
459,
1861,
5156,
288,
340,
286,
454,
63,
1162,
14,
1989,
63,
498,
360,
4511,
735,
286,
454,
63,
1162,
459,
4511,
418,
275,
282,
18,
66,
63,
4097,
8,
66,
8,
18548,
63,
1162,
459,
4511,
5156,
288,
340,
440,
286,
454,
63,
1162,
14,
1989,
63,
498,
360,
4994,
1405,
735,
355,
286,
454,
63,
1162,
459,
4994,
1405,
418,
275,
1695,
5830,
277,
14,
578,
14,
1457,
63,
890,
446,
822,
8,
18548,
63,
1162,
14,
362,
360,
1861,
297,
12381,
446,
822,
8,
18548
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
221,
23820,
774,
15,
3476,
15,
2330,
14,
647,
26,
13964,
1233,
367,
18855,
14,
12887,
774,
14,
3476,
199,
3,
199,
3,
27694,
315,
9079,
701,
577,
3316,
685,
445,
14,
491,
390,
5193,
605,
836,
665,
68,
29382,
32,
68,
29382,
14,
846,
30,
199,
3,
199,
3,
7819,
389,
199,
3,
710,
4072,
402,
642,
570,
787,
29711,
370,
314,
4575,
2881,
14,
221,
4005,
199,
3,
314,
13675,
626,
477,
21171,
370,
314,
4575,
2881,
365,
440,
2808,
12,
199,
3,
4036,
368,
365,
10009,
282,
6701,
13062,
12,
1126,
321,
1688,
12,
882,
89,
13248,
13,
4624,
12,
199,
3,
2222,
13,
12730,
4190,
370,
26511,
1006,
4481,
4568,
543,
314,
199,
3,
4072,
402,
642,
570,
367,
1263,
12016,
4052,
1152,
5907,
14,
199,
3,
3091,
4481,
787,
4644,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
199,
3,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
199,
3,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
199,
3,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
199,
3,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
3,
7819,
389,
199,
199,
624,
12887,
13,
4776,
367,
1611,
17134,
2631,
4621,
624,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
646,
984,
199,
646,
2882,
199,
504,
14755,
492,
282,
18,
66,
63,
4097,
12,
330,
18,
65,
63,
4097,
199,
504,
18855,
14,
9562,
14,
647,
19,
5819,
492,
627,
199,
199,
3,
2104,
7163,
543,
2018,
499,
14,
17,
436,
2018,
499,
14,
18,
199,
692,
984,
14,
4097,
1023,
665,
378,
88,
996,
1644,
993,
26,
272,
327,
2018,
499,
14,
17,
3181,
1133,
1172,
282,
1211,
342,
805,
272,
327,
2018,
499,
14,
18,
1211,
342,
805,
6534,
3146,
340,
1265,
886,
1211,
8,
5127,
21,
534,
12702,
358,
272,
347,
1211,
3682,
958,
304,
267,
372,
2074,
14,
1574,
342,
199,
2836,
26,
272,
1211,
275,
1211,
199,
199,
533,
485,
1944,
2698,
26,
986,
263,
327,
13792,
909,
199,
318,
485,
5005,
8,
68,
12,
1022,
12,
849,
3699,
1944,
2698,
304,
272,
408,
1002,
376,
1242,
687,
282,
2600,
12,
436,
2813,
652,
687,
314,
2600,
1041,
272,
862,
26,
267,
9151,
275,
366,
59,
75,
61,
272,
871,
4067,
26,
267,
340,
849,
365,
485,
1944,
2698,
26,
288,
746,
267,
372,
849,
272,
2150,
366,
59,
75,
61,
272,
372,
9151,
199,
199,
3,
8307,
10830,
511,
1930,
199,
533,
29683,
12887,
774,
8,
2796,
14,
1746,
304,
339,
347,
636,
826,
721,
277,
12,
859,
12,
1862,
304,
267,
2882,
14,
1746,
855,
826,
721,
277,
9,
267,
291,
14,
578,
275,
859,
398,
327,
12892,
314,
2633,
267,
1862,
275,
1862,
14,
1574,
342,
267,
291,
14,
1802,
275,
485,
5005,
8,
1162,
12,
283,
1802,
358,
267,
291,
14,
498,
275,
330,
1547,
5005,
8,
1162,
12,
283,
498,
1333,
267,
291,
14,
17426,
275,
330,
1547,
5005,
8,
1162,
12,
283,
17426,
1333,
267,
291,
14,
27661,
275,
330,
1547,
5005,
8,
1162,
12,
283,
27661,
1333,
267,
291,
14,
578,
63,
354,
275,
485,
5005,
8,
1162,
12,
283,
578,
63,
354,
297,
488,
9,
398,
818,
275,
485,
5005,
8,
1162,
12,
283,
632,
297,
488,
9,
267,
291,
14,
632,
63,
354,
275,
620,
8,
632,
9,
267,
340,
818,
365,
440,
488,
26,
288,
327,
8651,
10830,
288,
291,
14,
632,
275,
2519,
8,
277,
14,
578,
12,
298,
6963,
12172,
435,
818,
9,
288,
291,
14,
1003,
275,
485,
5005,
8,
1162,
12,
283,
1003,
297,
488,
9,
288,
340,
291,
14,
1003,
365,
440,
488,
26,
291,
14,
1003,
275,
330,
8,
277,
14,
1003,
9,
953,
327,
5972,
12082,
367,
24164,
48,
8225,
818,
288,
291,
14,
15078,
63,
1003,
275,
485,
5005,
8,
1162,
12,
283,
15078,
63,
1003,
297,
488,
9,
288,
340,
291,
14,
15078,
63,
1003,
365,
440,
488,
26,
355,
291,
14,
15078,
63,
1003,
275,
330,
8,
277,
14,
15078,
63,
1003,
9,
267,
587,
26,
288,
327,
8271,
10830,
288,
291,
14,
632,
275,
488,
288,
291,
14,
1003,
275,
488,
398,
291,
14,
2911,
63,
1162,
275,
1862,
339,
347,
3974,
5831,
8,
277,
304,
267,
372,
291,
14,
1802,
339,
347,
485,
1222,
8,
277,
12,
886,
63,
271,
7950,
29,
16,
304,
267,
1862,
275,
291,
14,
2911,
63,
1162,
14,
1574,
342,
398,
327,
8690,
445,
1766,
818,
2633,
14,
221,
4885,
849,
12,
781,
675,
14427,
14,
1222,
8,
277,
14,
578,
14,
1457,
63,
890,
9,
267,
340,
2688,
8,
277,
14,
578,
12,
298,
6963,
63,
1028,
50,
531,
436,
291,
14,
632,
508,
291,
14,
578,
14,
6963,
63,
1028,
50,
26,
288,
687,
18855,
14,
9562,
492,
14427,
288,
286,
454,
63,
533,
275,
485,
5005,
8,
1162,
12,
283,
18548,
63,
533,
297,
14427,
14,
1222,
9,
288,
286,
454,
63,
1162,
275,
485,
5005,
8,
1162,
12,
283,
18548,
63,
1162,
297,
13056,
1574,
342,
288,
340,
286,
454,
63,
1162,
14,
1989,
63,
498,
360,
1861,
735,
286,
454,
63,
1162,
459,
1861,
418,
275,
282,
18,
66,
63,
4097,
8,
66,
8,
18548,
63,
1162,
459,
1861,
5156,
288,
340,
286,
454,
63,
1162,
14,
1989,
63,
498,
360,
4511,
735,
286,
454,
63,
1162,
459,
4511,
418,
275,
282,
18,
66,
63,
4097,
8,
66,
8,
18548,
63,
1162,
459,
4511,
5156,
288,
340,
440,
286,
454,
63,
1162,
14,
1989,
63,
498,
360,
4994,
1405,
735,
355,
286,
454,
63,
1162,
459,
4994,
1405,
418,
275,
1695,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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
] |
knittledan/solr_lxml_Example
|
thirdParty/amazonproduct/processors/_lxml.py
|
2
|
2307
|
"""
XPath based paginators for lxml.etree and lxml.objectify based processors.
"""
from amazonproduct.processors import BaseResultPaginator
class XPathPaginator (BaseResultPaginator):
"""
Result paginator using XPath expressions to extract page and result
information from XML.
"""
counter = current_page_xpath = total_pages_xpath = total_results_xpath = None
def paginator_data(self, root):
nspace = root.nsmap.get(None, '')
def fetch_value(xpath, default):
try:
node = root.xpath(xpath, namespaces={'aws': nspace})[0]
return int(node.text)
except (IndexError, ValueError):
return default
return map(lambda a: fetch_value(*a), [
(self.current_page_xpath, 1),
(self.total_pages_xpath, 0),
(self.total_results_xpath, 0)
])
def iterate(self, root):
nspace = root.nsmap.get(None, '')
return root.xpath(self.items, namespaces={'aws': nspace})
class SearchPaginator (XPathPaginator):
counter = 'ItemPage'
current_page_xpath = '//aws:Items/aws:Request/aws:ItemSearchRequest/aws:ItemPage'
total_pages_xpath = '//aws:Items/aws:TotalPages'
total_results_xpath = '//aws:Items/aws:TotalResults'
items = '//aws:Items/aws:Item'
class RelatedItemsPaginator (XPathPaginator):
"""
XPath paginator which will work for both :meth:`item_lookup` and
:meth:`item_search`. The corresponding paths are::
ItemLookupResponse
Items
Item
RelatedItems
RelatedItemPage (counter)
RelatedItemCount (total_results)
RelatedItemPageCount (total_pages)
ItemSearchResponse
Request
ItemSearchRequest
ItemPage (counter)
Items
TotalResults (total_results)
TotalPages (total_pages)
"""
counter = 'RelatedItemPage'
current_page_xpath = '//aws:RelatedItemPage'
total_pages_xpath = '//aws:RelatedItems/aws:RelatedItemPageCount'
total_results_xpath = '//aws:RelatedItems/aws:RelatedItemCount'
items = '//aws:RelatedItems/aws:RelatedItem/aws:Item'
|
mit
|
[
202,
199,
624,
202,
199,
27645,
4079,
9881,
262,
2750,
367,
14490,
14,
9464,
436,
14490,
14,
1113,
825,
3338,
4079,
21620,
14,
202,
199,
624,
2999,
199,
504,
282,
8872,
2558,
14,
10547,
492,
3523,
2889,
23862,
8566,
8065,
199,
533,
1323,
2042,
23862,
8566,
334,
1563,
2889,
23862,
8566,
304,
2958,
408,
1128,
10695,
21398,
1808,
1323,
2042,
8455,
370,
5536,
2034,
436,
754,
1128,
2556,
687,
4692,
14,
1128,
408,
2958,
7055,
275,
1453,
63,
1606,
63,
8006,
275,
3141,
63,
5856,
63,
8006,
275,
3141,
63,
2604,
63,
8006,
275,
488,
2958,
347,
21398,
63,
576,
8,
277,
12,
1738,
304,
1039,
700,
1142,
275,
1738,
14,
561,
1130,
14,
362,
8,
403,
12,
4074,
1039,
347,
5267,
63,
585,
8,
8006,
12,
849,
304,
1675,
862,
26,
2628,
1031,
275,
1738,
14,
8006,
8,
8006,
12,
10747,
3713,
7231,
356,
700,
1142,
1552,
59,
16,
61,
2628,
372,
1109,
8,
932,
14,
505,
9,
1675,
871,
334,
12129,
12,
1722,
304,
2628,
372,
849,
1039,
372,
2341,
8,
2734,
282,
26,
5267,
63,
585,
2031,
65,
395,
359,
1675,
334,
277,
14,
1818,
63,
1606,
63,
8006,
12,
413,
395,
1675,
334,
277,
14,
2923,
63,
5856,
63,
8006,
12,
378,
395,
1675,
334,
277,
14,
2923,
63,
2604,
63,
8006,
12,
378,
9,
1039,
4794,
2958,
347,
13974,
8,
277,
12,
1738,
304,
1039,
700,
1142,
275,
1738,
14,
561,
1130,
14,
362,
8,
403,
12,
4074,
1039,
372,
1738,
14,
8006,
8,
277,
14,
1744,
12,
10747,
3713,
7231,
356,
700,
1142,
1552,
8065,
199,
533,
8730,
23862,
8566,
334,
27645,
23862,
8566,
304,
2958,
7055,
275,
283,
2081,
3276,
7,
1128,
1453,
63,
1606,
63,
8006,
275,
18290,
7231,
26,
7412,
15,
7231,
26,
2017,
15,
7231,
26,
2081,
5278,
2017,
15,
7231,
26,
2081,
3276,
7,
1128,
3141,
63,
5856,
63,
8006,
275,
18290,
7231,
26,
7412,
15,
7231,
26,
7316,
17773,
7,
1128,
3141,
63,
2604,
63,
8006,
275,
18290,
7231,
26,
7412,
15,
7231,
26,
7316,
6579,
7,
1128,
2974,
275,
18290,
7231,
26,
7412,
15,
7231,
26,
2081,
7,
8065,
199,
533,
20116,
7412,
23862,
8566,
334,
27645,
23862,
8566,
304,
2958,
408,
1128,
1323,
2042,
21398,
1314,
911,
1736,
367,
3865,
520,
5247,
1705,
1053,
63,
3892,
64,
436,
1128,
520,
5247,
1705,
1053,
63,
1733,
2313,
710,
5226,
3792,
787,
447,
4341,
7020,
7521,
2364,
16765,
20720,
1675,
7020,
23284,
20116,
7412,
2628,
20116,
2081,
3276,
334,
5337,
9,
2628,
20116,
2081,
2353,
334,
2923,
63,
2604,
9,
2628,
20116,
2081,
3276,
2353,
334,
2923,
63,
5856,
9,
4341,
7020,
5278,
2364,
16765,
4784,
1675,
7020,
5278,
2017,
23284,
7020,
3276,
334,
5337,
9,
16765,
20720,
1675,
19271,
6579,
334,
2923,
63,
2604,
9,
1675,
19271,
17773,
334,
2923,
63,
5856,
9,
2958,
408,
1128,
7055,
275,
283,
13885,
2081,
3276,
7,
1128,
1453,
63,
1606,
63,
8006,
275,
18290,
7231,
26,
13885,
2081,
3276,
7,
1128,
3141,
63,
5856,
63,
8006,
275,
18290,
7231,
26,
13885,
7412,
15,
7231,
26,
13885,
2081,
3276,
2353,
7,
1128,
3141,
63,
2604,
63,
8006,
275,
18290,
7231,
26,
13885,
7412,
15,
7231,
26,
13885,
2081,
2353,
7,
1128,
2974,
275,
18290,
7231,
26,
13885,
7412,
15,
7231,
26,
13885,
2081,
15,
7231,
26,
2081,
7,
10060,
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
] |
[
199,
624,
202,
199,
27645,
4079,
9881,
262,
2750,
367,
14490,
14,
9464,
436,
14490,
14,
1113,
825,
3338,
4079,
21620,
14,
202,
199,
624,
2999,
199,
504,
282,
8872,
2558,
14,
10547,
492,
3523,
2889,
23862,
8566,
8065,
199,
533,
1323,
2042,
23862,
8566,
334,
1563,
2889,
23862,
8566,
304,
2958,
408,
1128,
10695,
21398,
1808,
1323,
2042,
8455,
370,
5536,
2034,
436,
754,
1128,
2556,
687,
4692,
14,
1128,
408,
2958,
7055,
275,
1453,
63,
1606,
63,
8006,
275,
3141,
63,
5856,
63,
8006,
275,
3141,
63,
2604,
63,
8006,
275,
488,
2958,
347,
21398,
63,
576,
8,
277,
12,
1738,
304,
1039,
700,
1142,
275,
1738,
14,
561,
1130,
14,
362,
8,
403,
12,
4074,
1039,
347,
5267,
63,
585,
8,
8006,
12,
849,
304,
1675,
862,
26,
2628,
1031,
275,
1738,
14,
8006,
8,
8006,
12,
10747,
3713,
7231,
356,
700,
1142,
1552,
59,
16,
61,
2628,
372,
1109,
8,
932,
14,
505,
9,
1675,
871,
334,
12129,
12,
1722,
304,
2628,
372,
849,
1039,
372,
2341,
8,
2734,
282,
26,
5267,
63,
585,
2031,
65,
395,
359,
1675,
334,
277,
14,
1818,
63,
1606,
63,
8006,
12,
413,
395,
1675,
334,
277,
14,
2923,
63,
5856,
63,
8006,
12,
378,
395,
1675,
334,
277,
14,
2923,
63,
2604,
63,
8006,
12,
378,
9,
1039,
4794,
2958,
347,
13974,
8,
277,
12,
1738,
304,
1039,
700,
1142,
275,
1738,
14,
561,
1130,
14,
362,
8,
403,
12,
4074,
1039,
372,
1738,
14,
8006,
8,
277,
14,
1744,
12,
10747,
3713,
7231,
356,
700,
1142,
1552,
8065,
199,
533,
8730,
23862,
8566,
334,
27645,
23862,
8566,
304,
2958,
7055,
275,
283,
2081,
3276,
7,
1128,
1453,
63,
1606,
63,
8006,
275,
18290,
7231,
26,
7412,
15,
7231,
26,
2017,
15,
7231,
26,
2081,
5278,
2017,
15,
7231,
26,
2081,
3276,
7,
1128,
3141,
63,
5856,
63,
8006,
275,
18290,
7231,
26,
7412,
15,
7231,
26,
7316,
17773,
7,
1128,
3141,
63,
2604,
63,
8006,
275,
18290,
7231,
26,
7412,
15,
7231,
26,
7316,
6579,
7,
1128,
2974,
275,
18290,
7231,
26,
7412,
15,
7231,
26,
2081,
7,
8065,
199,
533,
20116,
7412,
23862,
8566,
334,
27645,
23862,
8566,
304,
2958,
408,
1128,
1323,
2042,
21398,
1314,
911,
1736,
367,
3865,
520,
5247,
1705,
1053,
63,
3892,
64,
436,
1128,
520,
5247,
1705,
1053,
63,
1733,
2313,
710,
5226,
3792,
787,
447,
4341,
7020,
7521,
2364,
16765,
20720,
1675,
7020,
23284,
20116,
7412,
2628,
20116,
2081,
3276,
334,
5337,
9,
2628,
20116,
2081,
2353,
334,
2923,
63,
2604,
9,
2628,
20116,
2081,
3276,
2353,
334,
2923,
63,
5856,
9,
4341,
7020,
5278,
2364,
16765,
4784,
1675,
7020,
5278,
2017,
23284,
7020,
3276,
334,
5337,
9,
16765,
20720,
1675,
19271,
6579,
334,
2923,
63,
2604,
9,
1675,
19271,
17773,
334,
2923,
63,
5856,
9,
2958,
408,
1128,
7055,
275,
283,
13885,
2081,
3276,
7,
1128,
1453,
63,
1606,
63,
8006,
275,
18290,
7231,
26,
13885,
2081,
3276,
7,
1128,
3141,
63,
5856,
63,
8006,
275,
18290,
7231,
26,
13885,
7412,
15,
7231,
26,
13885,
2081,
3276,
2353,
7,
1128,
3141,
63,
2604,
63,
8006,
275,
18290,
7231,
26,
13885,
7412,
15,
7231,
26,
13885,
2081,
2353,
7,
1128,
2974,
275,
18290,
7231,
26,
13885,
7412,
15,
7231,
26,
13885,
2081,
15,
7231,
26,
2081,
7,
10060,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
zhanqxun/cv_fish
|
win32/Demos/timer_demo.py
|
4
|
2271
|
# -*- Mode: Python; tab-width: 4 -*-
#
# This module, and the timer.pyd core timer support, were written by
# Sam Rushing (rushing@nightmare.com)
import timer
import time
# Timers are based on Windows messages. So we need
# to do the event-loop thing!
import win32event, win32gui
# glork holds a simple counter for us.
class glork:
def __init__ (self, delay=1000, max=10):
self.x = 0
self.max = max
self.id = timer.set_timer (delay, self.increment)
# Could use the threading module, but this is
# a win32 extension test after all! :-)
self.event = win32event.CreateEvent(None, 0, 0, None)
def increment (self, id, time):
print 'x = %d' % self.x
self.x = self.x + 1
# if we've reached the max count,
# kill off the timer.
if self.x > self.max:
# we could have used 'self.id' here, too
timer.kill_timer (id)
win32event.SetEvent(self.event)
# create a counter that will count from '1' thru '10', incrementing
# once a second, and then stop.
def demo (delay=1000, stop=10):
g = glork(delay, stop)
# Timers are message based - so we need
# To run a message loop while waiting for our timers
# to expire.
start_time = time.time()
while 1:
# We can't simply give a timeout of 30 seconds, as
# we may continouusly be recieving other input messages,
# and therefore never expire.
rc = win32event.MsgWaitForMultipleObjects(
(g.event,), # list of objects
0, # wait all
500, # timeout
win32event.QS_ALLEVENTS, # type of input
)
if rc == win32event.WAIT_OBJECT_0:
# Event signalled.
break
elif rc == win32event.WAIT_OBJECT_0+1:
# Message waiting.
if win32gui.PumpWaitingMessages():
raise RuntimeError("We got an unexpected WM_QUIT message!")
else:
# This wait timed-out.
if time.time()-start_time > 30:
raise RuntimeError("We timed out waiting for the timers to expire!")
if __name__=='__main__':
demo()
|
apache-2.0
|
[
3,
1882,
4900,
26,
2018,
27,
5174,
13,
2063,
26,
841,
1882,
202,
199,
3,
2999,
199,
3,
961,
859,
12,
436,
314,
9715,
14,
647,
68,
6170,
9715,
2291,
12,
4898,
5313,
701,
202,
199,
3,
428,
455,
820,
2084,
316,
334,
82,
2084,
316,
32,
14873,
391,
264,
14,
957,
9,
2999,
199,
646,
9715,
202,
199,
646,
900,
2999,
199,
3,
4703,
2393,
787,
4079,
641,
5417,
3788,
14,
221,
2002,
781,
1929,
202,
199,
3,
370,
886,
314,
1566,
13,
3813,
8377,
1,
202,
199,
646,
4747,
708,
1430,
12,
4747,
708,
5885,
2999,
199,
3,
6482,
4708,
15164,
282,
3486,
7055,
367,
2739,
14,
2999,
199,
533,
6482,
4708,
26,
2958,
347,
636,
826,
363,
334,
277,
12,
7339,
29,
5279,
12,
1390,
29,
709,
304,
1039,
291,
14,
88,
275,
378,
1039,
291,
14,
988,
275,
1390,
1039,
291,
14,
344,
275,
9715,
14,
409,
63,
7414,
334,
5814,
12,
291,
14,
9728,
9,
1039,
327,
18615,
675,
314,
5796,
859,
12,
1325,
642,
365,
1039,
327,
282,
4747,
708,
3329,
511,
2410,
1006,
1,
22901,
9,
1039,
291,
14,
1430,
275,
4747,
708,
1430,
14,
2499,
2390,
8,
403,
12,
378,
12,
378,
12,
488,
9,
2958,
347,
11609,
334,
277,
12,
1305,
12,
900,
304,
1039,
870,
283,
88,
275,
450,
68,
7,
450,
291,
14,
88,
1039,
291,
14,
88,
275,
291,
14,
88,
435,
413,
1039,
327,
340,
781,
9064,
13075,
314,
1390,
2338,
12,
1039,
327,
14561,
2331,
314,
9715,
14,
1039,
340,
291,
14,
88,
690,
291,
14,
988,
26,
1675,
327,
781,
4293,
1172,
1202,
283,
277,
14,
344,
7,
2348,
12,
4634,
1675,
9715,
14,
8997,
63,
7414,
334,
344,
9,
1675,
4747,
708,
1430,
14,
1084,
2390,
8,
277,
14,
1430,
9,
2999,
199,
3,
1218,
282,
7055,
626,
911,
2338,
687,
283,
17,
7,
294,
6558,
283,
709,
297,
11609,
316,
202,
199,
3,
5403,
282,
3499,
12,
436,
2066,
3631,
14,
2999,
199,
318,
14779,
334,
5814,
29,
5279,
12,
3631,
29,
709,
304,
1128,
486,
275,
6482,
4708,
8,
5814,
12,
3631,
9,
1128,
327,
4703,
2393,
787,
1245,
4079,
446,
880,
781,
1929,
1128,
327,
4005,
1255,
282,
1245,
4438,
1830,
10923,
367,
4154,
900,
2393,
1128,
327,
370,
16667,
14,
1128,
1343,
63,
521,
275,
900,
14,
521,
342,
1128,
1830,
413,
26,
1039,
327,
2136,
883,
1133,
9329,
8120,
282,
2653,
402,
4233,
4696,
12,
465,
1039,
327,
781,
1443,
9832,
810,
527,
590,
506,
295,
559,
69,
4007,
1163,
1324,
3788,
12,
1039,
327,
436,
16119,
7078,
16667,
14,
1039,
4819,
275,
4747,
708,
1430,
14,
6173,
21433,
8433,
11188,
8,
2628,
334,
71,
14,
1430,
4706,
327,
769,
402,
2251,
2628,
378,
12,
327,
3618,
1006,
2628,
6891,
12,
221,
327,
2653,
2628,
4747,
708,
1430,
14,
23298,
63,
748,
906,
4554,
51,
12,
327,
730,
402,
1324,
2628,
776,
1039,
340,
4819,
508,
4747,
708,
1430,
14,
12458,
63,
9868,
63,
16,
26,
1675,
327,
6763,
2070,
1843,
14,
1675,
2059,
1039,
916,
4819,
508,
4747,
708,
1430,
14,
12458,
63,
9868,
63,
16,
11,
17,
26,
1675,
327,
6430,
10923,
14,
1675,
340,
4747,
708,
5885,
14,
48,
1220,
19189,
14508,
837,
2628,
746,
6064,
480,
6004,
4788,
376,
10537,
644,
45,
63,
2328,
649,
1245,
9124,
1039,
587,
26,
1675,
327,
961,
3618,
18590,
13,
548,
14,
1675,
340,
900,
14,
521,
22251,
928,
63,
521,
690,
4233,
26,
2628,
746,
6064,
480,
6004,
18590,
734,
10923,
367,
314,
900,
2393,
370,
16667,
9124,
2999,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
1128,
14779,
342,
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
] |
[
1882,
4900,
26,
2018,
27,
5174,
13,
2063,
26,
841,
1882,
202,
199,
3,
2999,
199,
3,
961,
859,
12,
436,
314,
9715,
14,
647,
68,
6170,
9715,
2291,
12,
4898,
5313,
701,
202,
199,
3,
428,
455,
820,
2084,
316,
334,
82,
2084,
316,
32,
14873,
391,
264,
14,
957,
9,
2999,
199,
646,
9715,
202,
199,
646,
900,
2999,
199,
3,
4703,
2393,
787,
4079,
641,
5417,
3788,
14,
221,
2002,
781,
1929,
202,
199,
3,
370,
886,
314,
1566,
13,
3813,
8377,
1,
202,
199,
646,
4747,
708,
1430,
12,
4747,
708,
5885,
2999,
199,
3,
6482,
4708,
15164,
282,
3486,
7055,
367,
2739,
14,
2999,
199,
533,
6482,
4708,
26,
2958,
347,
636,
826,
363,
334,
277,
12,
7339,
29,
5279,
12,
1390,
29,
709,
304,
1039,
291,
14,
88,
275,
378,
1039,
291,
14,
988,
275,
1390,
1039,
291,
14,
344,
275,
9715,
14,
409,
63,
7414,
334,
5814,
12,
291,
14,
9728,
9,
1039,
327,
18615,
675,
314,
5796,
859,
12,
1325,
642,
365,
1039,
327,
282,
4747,
708,
3329,
511,
2410,
1006,
1,
22901,
9,
1039,
291,
14,
1430,
275,
4747,
708,
1430,
14,
2499,
2390,
8,
403,
12,
378,
12,
378,
12,
488,
9,
2958,
347,
11609,
334,
277,
12,
1305,
12,
900,
304,
1039,
870,
283,
88,
275,
450,
68,
7,
450,
291,
14,
88,
1039,
291,
14,
88,
275,
291,
14,
88,
435,
413,
1039,
327,
340,
781,
9064,
13075,
314,
1390,
2338,
12,
1039,
327,
14561,
2331,
314,
9715,
14,
1039,
340,
291,
14,
88,
690,
291,
14,
988,
26,
1675,
327,
781,
4293,
1172,
1202,
283,
277,
14,
344,
7,
2348,
12,
4634,
1675,
9715,
14,
8997,
63,
7414,
334,
344,
9,
1675,
4747,
708,
1430,
14,
1084,
2390,
8,
277,
14,
1430,
9,
2999,
199,
3,
1218,
282,
7055,
626,
911,
2338,
687,
283,
17,
7,
294,
6558,
283,
709,
297,
11609,
316,
202,
199,
3,
5403,
282,
3499,
12,
436,
2066,
3631,
14,
2999,
199,
318,
14779,
334,
5814,
29,
5279,
12,
3631,
29,
709,
304,
1128,
486,
275,
6482,
4708,
8,
5814,
12,
3631,
9,
1128,
327,
4703,
2393,
787,
1245,
4079,
446,
880,
781,
1929,
1128,
327,
4005,
1255,
282,
1245,
4438,
1830,
10923,
367,
4154,
900,
2393,
1128,
327,
370,
16667,
14,
1128,
1343,
63,
521,
275,
900,
14,
521,
342,
1128,
1830,
413,
26,
1039,
327,
2136,
883,
1133,
9329,
8120,
282,
2653,
402,
4233,
4696,
12,
465,
1039,
327,
781,
1443,
9832,
810,
527,
590,
506,
295,
559,
69,
4007,
1163,
1324,
3788,
12,
1039,
327,
436,
16119,
7078,
16667,
14,
1039,
4819,
275,
4747,
708,
1430,
14,
6173,
21433,
8433,
11188,
8,
2628,
334,
71,
14,
1430,
4706,
327,
769,
402,
2251,
2628,
378,
12,
327,
3618,
1006,
2628,
6891,
12,
221,
327,
2653,
2628,
4747,
708,
1430,
14,
23298,
63,
748,
906,
4554,
51,
12,
327,
730,
402,
1324,
2628,
776,
1039,
340,
4819,
508,
4747,
708,
1430,
14,
12458,
63,
9868,
63,
16,
26,
1675,
327,
6763,
2070,
1843,
14,
1675,
2059,
1039,
916,
4819,
508,
4747,
708,
1430,
14,
12458,
63,
9868,
63,
16,
11,
17,
26,
1675,
327,
6430,
10923,
14,
1675,
340,
4747,
708,
5885,
14,
48,
1220,
19189,
14508,
837,
2628,
746,
6064,
480,
6004,
4788,
376,
10537,
644,
45,
63,
2328,
649,
1245,
9124,
1039,
587,
26,
1675,
327,
961,
3618,
18590,
13,
548,
14,
1675,
340,
900,
14,
521,
22251,
928,
63,
521,
690,
4233,
26,
2628,
746,
6064,
480,
6004,
18590,
734,
10923,
367,
314,
900,
2393,
370,
16667,
9124,
2999,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
1128,
14779,
342,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
theo-l/django
|
django/conf/locale/de_CH/formats.py
|
16
|
1336
|
# This file is distributed under the same license as the Django package.
#
# The *_FORMAT strings use the Django date format syntax,
# see https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
DATE_FORMAT = 'j. F Y'
TIME_FORMAT = 'H:i'
DATETIME_FORMAT = 'j. F Y H:i'
YEAR_MONTH_FORMAT = 'F Y'
MONTH_DAY_FORMAT = 'j. F'
SHORT_DATE_FORMAT = 'd.m.Y'
SHORT_DATETIME_FORMAT = 'd.m.Y H:i'
FIRST_DAY_OF_WEEK = 1 # Monday
# The *_INPUT_FORMATS strings use the Python strftime format syntax,
# see https://docs.python.org/library/datetime.html#strftime-strptime-behavior
DATE_INPUT_FORMATS = [
'%d.%m.%Y', '%d.%m.%y', # '25.10.2006', '25.10.06'
# '%d. %B %Y', '%d. %b. %Y', # '25. October 2006', '25. Oct. 2006'
]
DATETIME_INPUT_FORMATS = [
'%d.%m.%Y %H:%M:%S', # '25.10.2006 14:30:59'
'%d.%m.%Y %H:%M:%S.%f', # '25.10.2006 14:30:59.000200'
'%d.%m.%Y %H:%M', # '25.10.2006 14:30'
]
# these are the separators for non-monetary numbers. For monetary numbers,
# the DECIMAL_SEPARATOR is a . (decimal point) and the THOUSAND_SEPARATOR is a
# ' (single quote).
# For details, please refer to http://www.bk.admin.ch/dokumentation/sprachen/04915/05016/index.html?lang=de
# (in German) and the documentation
DECIMAL_SEPARATOR = ','
THOUSAND_SEPARATOR = '\xa0' # non-breaking space
NUMBER_GROUPING = 3
|
bsd-3-clause
|
[
3,
961,
570,
365,
1854,
1334,
314,
2011,
4190,
465,
314,
5634,
2559,
14,
199,
3,
199,
3,
710,
20841,
4807,
3326,
675,
314,
5634,
1434,
1475,
6302,
12,
199,
3,
1937,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
10372,
12645,
602,
199,
5390,
63,
4807,
275,
283,
74,
14,
481,
1488,
7,
199,
4961,
63,
4807,
275,
283,
40,
26,
73,
7,
199,
12488,
63,
4807,
275,
283,
74,
14,
481,
1488,
869,
26,
73,
7,
199,
19216,
63,
16413,
63,
4807,
275,
283,
38,
1488,
7,
199,
16413,
63,
11655,
63,
4807,
275,
283,
74,
14,
481,
7,
199,
13003,
63,
5390,
63,
4807,
275,
283,
68,
14,
77,
14,
57,
7,
199,
13003,
63,
12488,
63,
4807,
275,
283,
68,
14,
77,
14,
57,
869,
26,
73,
7,
199,
12903,
63,
11655,
63,
3359,
63,
24929,
275,
413,
221,
327,
32740,
199,
199,
3,
710,
20841,
7321,
63,
14019,
3326,
675,
314,
2018,
14053,
1475,
6302,
12,
199,
3,
1937,
4178,
921,
4757,
14,
1548,
14,
1308,
15,
4342,
15,
2083,
14,
1360,
3,
6205,
13,
9866,
13,
17537,
199,
5390,
63,
7321,
63,
14019,
275,
359,
272,
1543,
68,
4111,
77,
4111,
57,
297,
1543,
68,
4111,
77,
4111,
89,
297,
258,
327,
283,
821,
14,
709,
14,
7968,
297,
283,
821,
14,
709,
14,
1690,
7,
272,
327,
1543,
68,
14,
450,
34,
450,
57,
297,
1543,
68,
14,
450,
66,
14,
450,
57,
297,
221,
327,
283,
821,
14,
18365,
22459,
8315,
297,
283,
821,
14,
18365,
14,
8315,
7,
199,
61,
199,
12488,
63,
7321,
63,
14019,
275,
359,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
2689,
51,
297,
259,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
221,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
297,
755,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
7,
199,
61,
199,
199,
3,
3520,
787,
314,
17658,
367,
2222,
13,
77,
25759,
695,
5579,
14,
2104,
333,
25759,
695,
5579,
12,
199,
3,
314,
31371,
16980,
63,
15828,
365,
282,
1275,
334,
6355,
2376,
9,
436,
314,
377,
2979,
27189,
63,
15828,
365,
282,
199,
3,
283,
334,
4780,
6313,
680,
199,
3,
2104,
2436,
12,
8749,
10618,
370,
1455,
921,
1544,
14,
18314,
14,
2113,
14,
335,
15,
68,
745,
760,
425,
15,
681,
345,
24604,
15,
12809,
1046,
15,
1717,
10882,
15,
1080,
14,
1360,
31,
4159,
29,
271,
199,
3,
334,
262,
22261,
1237,
9,
436,
314,
3794,
199,
23925,
63,
15828,
275,
13647,
199,
28714,
63,
15828,
275,
1557,
1800,
16,
7,
221,
327,
2222,
13,
4785,
316,
4601,
199,
9190,
63,
7823,
1206,
275,
650,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
961,
570,
365,
1854,
1334,
314,
2011,
4190,
465,
314,
5634,
2559,
14,
199,
3,
199,
3,
710,
20841,
4807,
3326,
675,
314,
5634,
1434,
1475,
6302,
12,
199,
3,
1937,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
10372,
12645,
602,
199,
5390,
63,
4807,
275,
283,
74,
14,
481,
1488,
7,
199,
4961,
63,
4807,
275,
283,
40,
26,
73,
7,
199,
12488,
63,
4807,
275,
283,
74,
14,
481,
1488,
869,
26,
73,
7,
199,
19216,
63,
16413,
63,
4807,
275,
283,
38,
1488,
7,
199,
16413,
63,
11655,
63,
4807,
275,
283,
74,
14,
481,
7,
199,
13003,
63,
5390,
63,
4807,
275,
283,
68,
14,
77,
14,
57,
7,
199,
13003,
63,
12488,
63,
4807,
275,
283,
68,
14,
77,
14,
57,
869,
26,
73,
7,
199,
12903,
63,
11655,
63,
3359,
63,
24929,
275,
413,
221,
327,
32740,
199,
199,
3,
710,
20841,
7321,
63,
14019,
3326,
675,
314,
2018,
14053,
1475,
6302,
12,
199,
3,
1937,
4178,
921,
4757,
14,
1548,
14,
1308,
15,
4342,
15,
2083,
14,
1360,
3,
6205,
13,
9866,
13,
17537,
199,
5390,
63,
7321,
63,
14019,
275,
359,
272,
1543,
68,
4111,
77,
4111,
57,
297,
1543,
68,
4111,
77,
4111,
89,
297,
258,
327,
283,
821,
14,
709,
14,
7968,
297,
283,
821,
14,
709,
14,
1690,
7,
272,
327,
1543,
68,
14,
450,
34,
450,
57,
297,
1543,
68,
14,
450,
66,
14,
450,
57,
297,
221,
327,
283,
821,
14,
18365,
22459,
8315,
297,
283,
821,
14,
18365,
14,
8315,
7,
199,
61,
199,
12488,
63,
7321,
63,
14019,
275,
359,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
2689,
51,
297,
259,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
221,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
297,
755,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
7,
199,
61,
199,
199,
3,
3520,
787,
314,
17658,
367,
2222,
13,
77,
25759,
695,
5579,
14,
2104,
333,
25759,
695,
5579,
12,
199,
3,
314,
31371,
16980,
63,
15828,
365,
282,
1275,
334,
6355,
2376,
9,
436,
314,
377,
2979,
27189,
63,
15828,
365,
282,
199,
3,
283,
334,
4780,
6313,
680,
199,
3,
2104,
2436,
12,
8749,
10618,
370,
1455,
921,
1544,
14,
18314,
14,
2113,
14,
335,
15,
68,
745,
760,
425,
15,
681,
345,
24604,
15,
12809,
1046,
15,
1717,
10882,
15,
1080,
14,
1360,
31,
4159,
29,
271,
199,
3,
334,
262,
22261,
1237,
9,
436,
314,
3794,
199,
23925,
63,
15828,
275,
13647,
199,
28714,
63,
15828,
275,
1557,
1800,
16,
7,
221,
327,
2222,
13,
4785,
316,
4601,
199,
9190,
63,
7823,
1206,
275,
650,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
alcobar/asuswrt-merlin
|
release/src/router/samba36/lib/dnspython/examples/reverse.py
|
74
|
1336
|
#!/usr/bin/env python
# Usage: reverse.py <zone_filename>...
#
# This demo script will load in all of the zones specified by the
# filenames on the command line, find all the A RRs in them, and
# construct a reverse mapping table that maps each IP address used to
# the list of names mapping to that address. The table is then sorted
# nicely and printed.
#
# Note! The zone name is taken from the basename of the filename, so
# you must use filenames like "/wherever/you/like/dnspython.org" and
# not something like "/wherever/you/like/foo.db" (unless you're
# working with the ".db" GTLD, of course :)).
#
# If this weren't a demo script, there'd be a way of specifying the
# origin for each zone instead of constructing it from the filename.
import dns.zone
import dns.ipv4
import os.path
import sys
reverse_map = {}
for filename in sys.argv[1:]:
zone = dns.zone.from_file(filename, os.path.basename(filename),
relativize=False)
for (name, ttl, rdata) in zone.iterate_rdatas('A'):
try:
reverse_map[rdata.address].append(name.to_text())
except KeyError:
reverse_map[rdata.address] = [name.to_text()]
keys = reverse_map.keys()
keys.sort(lambda a1, a2: cmp(dns.ipv4.inet_aton(a1), dns.ipv4.inet_aton(a2)))
for k in keys:
v = reverse_map[k]
v.sort()
print k, v
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
11028,
26,
3837,
14,
647,
665,
2619,
63,
1501,
30,
1396,
199,
3,
199,
3,
961,
14779,
2884,
911,
2248,
315,
1006,
402,
314,
18666,
2013,
701,
314,
199,
3,
6203,
641,
314,
1414,
1004,
12,
2342,
1006,
314,
437,
27222,
83,
315,
3062,
12,
436,
199,
3,
6982,
282,
3837,
4412,
1817,
626,
9033,
1924,
3531,
2287,
1202,
370,
199,
3,
314,
769,
402,
1561,
4412,
370,
626,
2287,
14,
221,
710,
1817,
365,
2066,
3355,
199,
3,
14213,
590,
436,
12487,
14,
199,
3,
199,
3,
3390,
1,
221,
710,
5718,
536,
365,
9394,
687,
314,
9593,
402,
314,
1788,
12,
880,
199,
3,
1265,
1471,
675,
6203,
2839,
3286,
4509,
422,
15,
13297,
15,
2930,
15,
5797,
1548,
14,
1308,
2,
436,
199,
3,
440,
6020,
2839,
3286,
4509,
422,
15,
13297,
15,
2930,
15,
1421,
14,
697,
2,
334,
18447,
1265,
3984,
199,
3,
6449,
543,
314,
3680,
697,
2,
598,
52,
6533,
12,
402,
2518,
520,
4992,
199,
3,
199,
3,
982,
642,
781,
828,
1133,
282,
14779,
2884,
12,
2337,
5121,
506,
282,
4340,
402,
9176,
314,
199,
3,
6330,
367,
1924,
5718,
3140,
402,
22048,
652,
687,
314,
1788,
14,
199,
199,
646,
6715,
14,
2619,
199,
646,
6715,
14,
4774,
20,
199,
646,
747,
14,
515,
199,
646,
984,
199,
199,
4471,
63,
1130,
275,
1052,
199,
199,
509,
1788,
315,
984,
14,
3020,
59,
17,
10688,
272,
5718,
275,
6715,
14,
2619,
14,
504,
63,
493,
8,
1501,
12,
747,
14,
515,
14,
4846,
8,
1501,
395,
2892,
13773,
29282,
29,
797,
9,
272,
367,
334,
354,
12,
14856,
12,
27020,
9,
315,
5718,
14,
20627,
63,
82,
11563,
360,
33,
735,
267,
862,
26,
6722,
3837,
63,
1130,
59,
23203,
14,
1562,
1055,
740,
8,
354,
14,
475,
63,
505,
1012,
199,
198,
2590,
4067,
26,
6722,
3837,
63,
1130,
59,
23203,
14,
1562,
61,
275,
359,
354,
14,
475,
63,
505,
5106,
199,
199,
1612,
275,
3837,
63,
1130,
14,
1612,
342,
199,
1612,
14,
3191,
8,
2734,
282,
17,
12,
282,
18,
26,
10467,
8,
5797,
14,
4774,
20,
14,
10811,
63,
25685,
8,
65,
17,
395,
6715,
14,
4774,
20,
14,
10811,
63,
25685,
8,
65,
18,
1724,
199,
509,
1022,
315,
2883,
26,
272,
373,
275,
3837,
63,
1130,
59,
75,
61,
272,
373,
14,
3191,
342,
272,
870,
1022,
12,
373,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
11028,
26,
3837,
14,
647,
665,
2619,
63,
1501,
30,
1396,
199,
3,
199,
3,
961,
14779,
2884,
911,
2248,
315,
1006,
402,
314,
18666,
2013,
701,
314,
199,
3,
6203,
641,
314,
1414,
1004,
12,
2342,
1006,
314,
437,
27222,
83,
315,
3062,
12,
436,
199,
3,
6982,
282,
3837,
4412,
1817,
626,
9033,
1924,
3531,
2287,
1202,
370,
199,
3,
314,
769,
402,
1561,
4412,
370,
626,
2287,
14,
221,
710,
1817,
365,
2066,
3355,
199,
3,
14213,
590,
436,
12487,
14,
199,
3,
199,
3,
3390,
1,
221,
710,
5718,
536,
365,
9394,
687,
314,
9593,
402,
314,
1788,
12,
880,
199,
3,
1265,
1471,
675,
6203,
2839,
3286,
4509,
422,
15,
13297,
15,
2930,
15,
5797,
1548,
14,
1308,
2,
436,
199,
3,
440,
6020,
2839,
3286,
4509,
422,
15,
13297,
15,
2930,
15,
1421,
14,
697,
2,
334,
18447,
1265,
3984,
199,
3,
6449,
543,
314,
3680,
697,
2,
598,
52,
6533,
12,
402,
2518,
520,
4992,
199,
3,
199,
3,
982,
642,
781,
828,
1133,
282,
14779,
2884,
12,
2337,
5121,
506,
282,
4340,
402,
9176,
314,
199,
3,
6330,
367,
1924,
5718,
3140,
402,
22048,
652,
687,
314,
1788,
14,
199,
199,
646,
6715,
14,
2619,
199,
646,
6715,
14,
4774,
20,
199,
646,
747,
14,
515,
199,
646,
984,
199,
199,
4471,
63,
1130,
275,
1052,
199,
199,
509,
1788,
315,
984,
14,
3020,
59,
17,
10688,
272,
5718,
275,
6715,
14,
2619,
14,
504,
63,
493,
8,
1501,
12,
747,
14,
515,
14,
4846,
8,
1501,
395,
2892,
13773,
29282,
29,
797,
9,
272,
367,
334,
354,
12,
14856,
12,
27020,
9,
315,
5718,
14,
20627,
63,
82,
11563,
360,
33,
735,
267,
862,
26,
6722,
3837,
63,
1130,
59,
23203,
14,
1562,
1055,
740,
8,
354,
14,
475,
63,
505,
1012,
199,
198,
2590,
4067,
26,
6722,
3837,
63,
1130,
59,
23203,
14,
1562,
61,
275,
359,
354,
14,
475,
63,
505,
5106,
199,
199,
1612,
275,
3837,
63,
1130,
14,
1612,
342,
199,
1612,
14,
3191,
8,
2734,
282,
17,
12,
282,
18,
26,
10467,
8,
5797,
14,
4774,
20,
14,
10811,
63,
25685,
8,
65,
17,
395,
6715,
14,
4774,
20,
14,
10811,
63,
25685,
8,
65,
18,
1724,
199,
509,
1022,
315,
2883,
26,
272,
373,
275,
3837,
63,
1130,
59,
75,
61,
272,
373,
14,
3191,
342,
272,
870,
1022,
12,
373,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
mujiansu/arangodb
|
3rdParty/V8-4.3.61/build/gyp/test/win/gyptest-cl-optimizations.py
|
247
|
3416
|
#!/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.
"""
Make sure optimization settings are extracted properly.
"""
import TestGyp
import sys
if sys.platform == 'win32':
test = TestGyp.TestGyp(formats=['ninja'])
CHDIR = 'compiler-flags'
test.run_gyp('optimizations.gyp', chdir=CHDIR)
# It's hard to map flags to output contents in a non-fragile way (especially
# handling both 2008/2010), so just verify the correct ninja command line
# contents.
ninja_file = test.built_file_path('obj/test_opt_off.ninja', chdir=CHDIR)
test.must_contain(ninja_file, 'cflags = /Od')
ninja_file = test.built_file_path('obj/test_opt_lev_size.ninja', chdir=CHDIR)
test.must_contain(ninja_file, 'cflags = /O1')
ninja_file = test.built_file_path('obj/test_opt_lev_speed.ninja', chdir=CHDIR)
test.must_contain(ninja_file, 'cflags = /O2')
ninja_file = test.built_file_path('obj/test_opt_lev_max.ninja', chdir=CHDIR)
test.must_contain(ninja_file, 'cflags = /Ox')
ninja_file = test.built_file_path('obj/test_opt_unset.ninja', chdir=CHDIR)
test.must_not_contain(ninja_file, '/Od')
test.must_not_contain(ninja_file, '/O1')
test.must_not_contain(ninja_file, '/Ox')
# Set by default if none specified.
test.must_contain(ninja_file, '/O2')
ninja_file = test.built_file_path('obj/test_opt_fpo.ninja', chdir=CHDIR)
test.must_contain(ninja_file, '/Oy')
test.must_not_contain(ninja_file, '/Oy-')
ninja_file = test.built_file_path('obj/test_opt_fpo_off.ninja', chdir=CHDIR)
test.must_contain(ninja_file, '/Oy-')
ninja_file = test.built_file_path('obj/test_opt_intrinsic.ninja',
chdir=CHDIR)
test.must_contain(ninja_file, '/Oi')
test.must_not_contain(ninja_file, '/Oi-')
ninja_file = test.built_file_path('obj/test_opt_intrinsic_off.ninja',
chdir=CHDIR)
test.must_contain(ninja_file, '/Oi-')
ninja_file = test.built_file_path('obj/test_opt_inline_off.ninja',
chdir=CHDIR)
test.must_contain(ninja_file, '/Ob0')
ninja_file = test.built_file_path('obj/test_opt_inline_manual.ninja',
chdir=CHDIR)
test.must_contain(ninja_file, '/Ob1')
ninja_file = test.built_file_path('obj/test_opt_inline_auto.ninja',
chdir=CHDIR)
test.must_contain(ninja_file, '/Ob2')
ninja_file = test.built_file_path('obj/test_opt_neither.ninja',
chdir=CHDIR)
test.must_not_contain(ninja_file, '/Os')
test.must_not_contain(ninja_file, '/Ot')
ninja_file = test.built_file_path('obj/test_opt_size.ninja',
chdir=CHDIR)
test.must_contain(ninja_file, '/Os')
ninja_file = test.built_file_path('obj/test_opt_speed.ninja',
chdir=CHDIR)
test.must_contain(ninja_file, '/Ot')
ninja_file = test.built_file_path('obj/test_opt_wpo.ninja',
chdir=CHDIR)
test.must_contain(ninja_file, '/GL')
ninja_file = test.built_file_path('obj/test_opt_sp.ninja',
chdir=CHDIR)
test.must_contain(ninja_file, '/GF')
ninja_file = test.built_file_path('obj/test_opt_sp_off.ninja',
chdir=CHDIR)
test.must_not_contain(ninja_file, '/GF')
ninja_file = test.built_file_path('obj/test_opt_fso.ninja',
chdir=CHDIR)
test.must_contain(ninja_file, '/GT')
ninja_file = test.built_file_path('obj/test_opt_fso_off.ninja',
chdir=CHDIR)
test.must_not_contain(ninja_file, '/GT')
test.pass_test()
|
apache-2.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,
199,
5483,
3238,
13712,
2202,
787,
12509,
7684,
14,
199,
624,
199,
199,
646,
25688,
199,
199,
646,
984,
199,
199,
692,
984,
14,
3246,
508,
283,
2676,
708,
356,
523,
511,
275,
25688,
14,
774,
13899,
8,
6321,
2968,
8675,
1105,
819,
6624,
3022,
275,
283,
5772,
13,
2469,
7,
523,
511,
14,
1065,
63,
6179,
360,
6433,
12270,
14,
6179,
297,
13097,
29,
30285,
9,
819,
327,
2779,
1159,
7508,
370,
2341,
3285,
370,
1072,
4072,
315,
282,
2222,
13,
11255,
441,
4340,
334,
397,
910,
1183,
523,
327,
7252,
3865,
9079,
15,
6542,
395,
880,
2951,
4911,
314,
3211,
14822,
1414,
1004,
523,
327,
4072,
14,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
1997,
14,
8675,
297,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
283,
14002,
275,
1182,
47,
68,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
6972,
63,
890,
14,
8675,
297,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
283,
14002,
275,
1182,
47,
17,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
6972,
63,
7625,
14,
8675,
297,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
283,
14002,
275,
1182,
47,
18,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
6972,
63,
988,
14,
8675,
297,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
283,
14002,
275,
1182,
47,
88,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
16787,
14,
8675,
297,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
1397,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
68,
358,
523,
511,
14,
7790,
63,
1397,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
17,
358,
523,
511,
14,
7790,
63,
1397,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
88,
358,
523,
327,
2494,
701,
849,
340,
7179,
2013,
14,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
18,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
70,
555,
14,
8675,
297,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
89,
358,
523,
511,
14,
7790,
63,
1397,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
89,
25815,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
70,
555,
63,
1997,
14,
8675,
297,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
89,
25815,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
442,
24667,
9916,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
73,
358,
523,
511,
14,
7790,
63,
1397,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
73,
25815,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
442,
24667,
9916,
63,
1997,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
73,
25815,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
6460,
63,
1997,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
11394,
16,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
6460,
63,
9285,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
11394,
17,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
6460,
63,
2495,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
11394,
18,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
685,
1711,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
1397,
63,
7747,
8,
8675,
63,
493,
12,
1994,
24351,
358,
523,
511,
14,
7790,
63,
1397,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
84,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
890,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
24351,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
7625,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
84,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
87,
555,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
2226,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
681,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
5483,
3238,
13712,
2202,
787,
12509,
7684,
14,
199,
624,
199,
199,
646,
25688,
199,
199,
646,
984,
199,
199,
692,
984,
14,
3246,
508,
283,
2676,
708,
356,
523,
511,
275,
25688,
14,
774,
13899,
8,
6321,
2968,
8675,
1105,
819,
6624,
3022,
275,
283,
5772,
13,
2469,
7,
523,
511,
14,
1065,
63,
6179,
360,
6433,
12270,
14,
6179,
297,
13097,
29,
30285,
9,
819,
327,
2779,
1159,
7508,
370,
2341,
3285,
370,
1072,
4072,
315,
282,
2222,
13,
11255,
441,
4340,
334,
397,
910,
1183,
523,
327,
7252,
3865,
9079,
15,
6542,
395,
880,
2951,
4911,
314,
3211,
14822,
1414,
1004,
523,
327,
4072,
14,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
1997,
14,
8675,
297,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
283,
14002,
275,
1182,
47,
68,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
6972,
63,
890,
14,
8675,
297,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
283,
14002,
275,
1182,
47,
17,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
6972,
63,
7625,
14,
8675,
297,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
283,
14002,
275,
1182,
47,
18,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
6972,
63,
988,
14,
8675,
297,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
283,
14002,
275,
1182,
47,
88,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
16787,
14,
8675,
297,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
1397,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
68,
358,
523,
511,
14,
7790,
63,
1397,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
17,
358,
523,
511,
14,
7790,
63,
1397,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
88,
358,
523,
327,
2494,
701,
849,
340,
7179,
2013,
14,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
18,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
70,
555,
14,
8675,
297,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
89,
358,
523,
511,
14,
7790,
63,
1397,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
89,
25815,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
70,
555,
63,
1997,
14,
8675,
297,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
89,
25815,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
442,
24667,
9916,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
73,
358,
523,
511,
14,
7790,
63,
1397,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
73,
25815,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
442,
24667,
9916,
63,
1997,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
73,
25815,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
6460,
63,
1997,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
11394,
16,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
6460,
63,
9285,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
11394,
17,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
6460,
63,
2495,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
11394,
18,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
685,
1711,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
1397,
63,
7747,
8,
8675,
63,
493,
12,
1994,
24351,
358,
523,
511,
14,
7790,
63,
1397,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
84,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
890,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
24351,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
7625,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
8,
8675,
63,
493,
12,
1994,
47,
84,
358,
819,
14822,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
360,
1113,
15,
396,
63,
2992,
63,
87,
555,
14,
8675,
297,
489,
13097,
29,
30285,
9,
523,
511,
14,
7790,
63,
7747,
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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
] |
rolando-contrib/scrapy
|
scrapy/http/request/__init__.py
|
6
|
2938
|
"""
This module implements the Request class which is used to represent HTTP
requests in Scrapy.
See documentation in docs/topics/request-response.rst
"""
import six
from w3lib.url import safe_url_string
from scrapy.http.headers import Headers
from scrapy.utils.python import to_bytes
from scrapy.utils.trackref import object_ref
from scrapy.utils.url import escape_ajax
from scrapy.http.common import obsolete_setter
class Request(object_ref):
def __init__(self, url, callback=None, method='GET', headers=None, body=None,
cookies=None, meta=None, encoding='utf-8', priority=0,
dont_filter=False, errback=None, flags=None):
self._encoding = encoding # this one has to be set first
self.method = str(method).upper()
self._set_url(url)
self._set_body(body)
assert isinstance(priority, int), "Request priority not an integer: %r" % priority
self.priority = priority
assert callback or not errback, "Cannot use errback without a callback"
self.callback = callback
self.errback = errback
self.cookies = cookies or {}
self.headers = Headers(headers or {}, encoding=encoding)
self.dont_filter = dont_filter
self._meta = dict(meta) if meta else None
self.flags = [] if flags is None else list(flags)
@property
def meta(self):
if self._meta is None:
self._meta = {}
return self._meta
def _get_url(self):
return self._url
def _set_url(self, url):
if not isinstance(url, six.string_types):
raise TypeError('Request url must be str or unicode, got %s:' % type(url).__name__)
s = safe_url_string(url, self.encoding)
self._url = escape_ajax(s)
if ':' not in self._url:
raise ValueError('Missing scheme in request url: %s' % self._url)
url = property(_get_url, obsolete_setter(_set_url, 'url'))
def _get_body(self):
return self._body
def _set_body(self, body):
if body is None:
self._body = b''
else:
self._body = to_bytes(body, self.encoding)
body = property(_get_body, obsolete_setter(_set_body, 'body'))
@property
def encoding(self):
return self._encoding
def __str__(self):
return "<%s %s>" % (self.method, self.url)
__repr__ = __str__
def copy(self):
"""Return a copy of this Request"""
return self.replace()
def replace(self, *args, **kwargs):
"""Create a new Request with the same attributes except for those
given new values.
"""
for x in ['url', 'method', 'headers', 'body', 'cookies', 'meta',
'encoding', 'priority', 'dont_filter', 'callback', 'errback']:
kwargs.setdefault(x, getattr(self, x))
cls = kwargs.pop('cls', self.__class__)
return cls(*args, **kwargs)
|
bsd-3-clause
|
[
624,
199,
2765,
859,
9031,
314,
4784,
1021,
1314,
365,
1202,
370,
2954,
3101,
199,
6615,
315,
13916,
345,
647,
14,
199,
199,
9295,
3794,
315,
9149,
15,
11299,
15,
1069,
13,
1310,
14,
8332,
199,
624,
199,
646,
3816,
199,
504,
336,
19,
773,
14,
633,
492,
5048,
63,
633,
63,
875,
199,
199,
504,
18918,
14,
1014,
14,
2139,
492,
21391,
199,
504,
18918,
14,
1208,
14,
1548,
492,
370,
63,
2394,
199,
504,
18918,
14,
1208,
14,
3885,
1121,
492,
909,
63,
1121,
199,
504,
18918,
14,
1208,
14,
633,
492,
4772,
63,
12774,
199,
504,
18918,
14,
1014,
14,
2330,
492,
24985,
63,
8345,
421,
199,
533,
4784,
8,
785,
63,
1121,
304,
339,
347,
636,
826,
721,
277,
12,
1166,
12,
3233,
29,
403,
12,
1083,
534,
2970,
297,
2323,
29,
403,
12,
2396,
29,
403,
12,
326,
10049,
29,
403,
12,
3404,
29,
403,
12,
2644,
534,
1624,
13,
24,
297,
7464,
29,
16,
12,
326,
21542,
63,
1541,
29,
797,
12,
2329,
894,
29,
403,
12,
3285,
29,
403,
304,
398,
291,
423,
2991,
275,
2644,
221,
327,
642,
1373,
965,
370,
506,
663,
1642,
267,
291,
14,
765,
275,
620,
8,
765,
680,
4142,
342,
267,
291,
423,
409,
63,
633,
8,
633,
9,
267,
291,
423,
409,
63,
2030,
8,
2030,
9,
267,
702,
1228,
8,
6693,
12,
1109,
395,
298,
2017,
7464,
440,
376,
3000,
26,
450,
82,
2,
450,
7464,
267,
291,
14,
6693,
275,
7464,
398,
702,
3233,
503,
440,
2329,
894,
12,
298,
6612,
675,
2329,
894,
1928,
282,
3233,
2,
267,
291,
14,
3058,
275,
3233,
267,
291,
14,
28940,
275,
2329,
894,
398,
291,
14,
7792,
275,
10049,
503,
1052,
267,
291,
14,
2139,
275,
21391,
8,
2139,
503,
5479,
2644,
29,
2991,
9,
267,
291,
14,
18671,
63,
1541,
275,
21542,
63,
1541,
398,
291,
423,
2024,
275,
1211,
8,
2024,
9,
340,
3404,
587,
488,
267,
291,
14,
2469,
275,
942,
340,
3285,
365,
488,
587,
769,
8,
2469,
9,
339,
768,
1829,
272,
347,
3404,
8,
277,
304,
267,
340,
291,
423,
2024,
365,
488,
26,
288,
291,
423,
2024,
275,
1052,
267,
372,
291,
423,
2024,
339,
347,
485,
362,
63,
633,
8,
277,
304,
267,
372,
291,
423,
633,
339,
347,
485,
409,
63,
633,
8,
277,
12,
1166,
304,
267,
340,
440,
1228,
8,
633,
12,
3816,
14,
875,
63,
1313,
304,
288,
746,
3146,
360,
2017,
1166,
1471,
506,
620,
503,
2649,
12,
4788,
450,
83,
4881,
450,
730,
8,
633,
2843,
354,
3368,
398,
308,
275,
5048,
63,
633,
63,
875,
8,
633,
12,
291,
14,
2991,
9,
267,
291,
423,
633,
275,
4772,
63,
12774,
8,
83,
9,
398,
340,
10871,
440,
315,
291,
423,
633,
26,
288,
746,
1722,
360,
7718,
5687,
315,
1056,
1166,
26,
450,
83,
7,
450,
291,
423,
633,
9,
339,
1166,
275,
3324,
1547,
362,
63,
633,
12,
24985,
63,
8345,
1547,
409,
63,
633,
12,
283,
633,
1333,
339,
347,
485,
362,
63,
2030,
8,
277,
304,
267,
372,
291,
423,
2030,
339,
347,
485,
409,
63,
2030,
8,
277,
12,
2396,
304,
267,
340,
2396,
365,
488,
26,
288,
291,
423,
2030,
275,
330,
891,
267,
587,
26,
288,
291,
423,
2030,
275,
370,
63,
2394,
8,
2030,
12,
291,
14,
2991,
9,
339,
2396,
275,
3324,
1547,
362,
63,
2030,
12,
24985,
63,
8345,
1547,
409,
63,
2030,
12,
283,
2030,
1333,
339,
768,
1829,
272,
347,
2644,
8,
277,
304,
267,
372,
291,
423,
2991,
339,
347,
636,
495,
721,
277,
304,
267,
372,
23054,
83,
450,
83,
4335,
450,
334,
277,
14,
765,
12,
291,
14,
633,
9,
339,
636,
2722,
363,
275,
636,
495,
363,
339,
347,
1331,
8,
277,
304,
267,
408,
1767,
282,
1331,
402,
642,
4784,
624,
267,
372,
291,
14,
1814,
342,
339,
347,
3350,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
2499,
282,
892,
4784,
543,
314,
2011,
3004,
871,
367,
5204,
267,
1627,
892,
1338,
14,
267,
408,
267,
367,
671,
315,
788,
633,
297,
283,
765,
297,
283,
2139,
297,
283,
2030,
297,
283,
7792,
297,
283,
2024,
297,
2116,
283,
2991,
297,
283,
6693,
297,
283,
18671,
63,
1541,
297,
283,
3058,
297,
283,
28940,
2565,
288,
2074,
14,
5486,
8,
88,
12,
2519,
8,
277,
12,
671,
430,
267,
843,
275,
2074,
14,
1935,
360,
1886,
297,
291,
855,
533,
3368,
267,
372,
843,
2031,
589,
12,
1011,
958,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
2765,
859,
9031,
314,
4784,
1021,
1314,
365,
1202,
370,
2954,
3101,
199,
6615,
315,
13916,
345,
647,
14,
199,
199,
9295,
3794,
315,
9149,
15,
11299,
15,
1069,
13,
1310,
14,
8332,
199,
624,
199,
646,
3816,
199,
504,
336,
19,
773,
14,
633,
492,
5048,
63,
633,
63,
875,
199,
199,
504,
18918,
14,
1014,
14,
2139,
492,
21391,
199,
504,
18918,
14,
1208,
14,
1548,
492,
370,
63,
2394,
199,
504,
18918,
14,
1208,
14,
3885,
1121,
492,
909,
63,
1121,
199,
504,
18918,
14,
1208,
14,
633,
492,
4772,
63,
12774,
199,
504,
18918,
14,
1014,
14,
2330,
492,
24985,
63,
8345,
421,
199,
533,
4784,
8,
785,
63,
1121,
304,
339,
347,
636,
826,
721,
277,
12,
1166,
12,
3233,
29,
403,
12,
1083,
534,
2970,
297,
2323,
29,
403,
12,
2396,
29,
403,
12,
326,
10049,
29,
403,
12,
3404,
29,
403,
12,
2644,
534,
1624,
13,
24,
297,
7464,
29,
16,
12,
326,
21542,
63,
1541,
29,
797,
12,
2329,
894,
29,
403,
12,
3285,
29,
403,
304,
398,
291,
423,
2991,
275,
2644,
221,
327,
642,
1373,
965,
370,
506,
663,
1642,
267,
291,
14,
765,
275,
620,
8,
765,
680,
4142,
342,
267,
291,
423,
409,
63,
633,
8,
633,
9,
267,
291,
423,
409,
63,
2030,
8,
2030,
9,
267,
702,
1228,
8,
6693,
12,
1109,
395,
298,
2017,
7464,
440,
376,
3000,
26,
450,
82,
2,
450,
7464,
267,
291,
14,
6693,
275,
7464,
398,
702,
3233,
503,
440,
2329,
894,
12,
298,
6612,
675,
2329,
894,
1928,
282,
3233,
2,
267,
291,
14,
3058,
275,
3233,
267,
291,
14,
28940,
275,
2329,
894,
398,
291,
14,
7792,
275,
10049,
503,
1052,
267,
291,
14,
2139,
275,
21391,
8,
2139,
503,
5479,
2644,
29,
2991,
9,
267,
291,
14,
18671,
63,
1541,
275,
21542,
63,
1541,
398,
291,
423,
2024,
275,
1211,
8,
2024,
9,
340,
3404,
587,
488,
267,
291,
14,
2469,
275,
942,
340,
3285,
365,
488,
587,
769,
8,
2469,
9,
339,
768,
1829,
272,
347,
3404,
8,
277,
304,
267,
340,
291,
423,
2024,
365,
488,
26,
288,
291,
423,
2024,
275,
1052,
267,
372,
291,
423,
2024,
339,
347,
485,
362,
63,
633,
8,
277,
304,
267,
372,
291,
423,
633,
339,
347,
485,
409,
63,
633,
8,
277,
12,
1166,
304,
267,
340,
440,
1228,
8,
633,
12,
3816,
14,
875,
63,
1313,
304,
288,
746,
3146,
360,
2017,
1166,
1471,
506,
620,
503,
2649,
12,
4788,
450,
83,
4881,
450,
730,
8,
633,
2843,
354,
3368,
398,
308,
275,
5048,
63,
633,
63,
875,
8,
633,
12,
291,
14,
2991,
9,
267,
291,
423,
633,
275,
4772,
63,
12774,
8,
83,
9,
398,
340,
10871,
440,
315,
291,
423,
633,
26,
288,
746,
1722,
360,
7718,
5687,
315,
1056,
1166,
26,
450,
83,
7,
450,
291,
423,
633,
9,
339,
1166,
275,
3324,
1547,
362,
63,
633,
12,
24985,
63,
8345,
1547,
409,
63,
633,
12,
283,
633,
1333,
339,
347,
485,
362,
63,
2030,
8,
277,
304,
267,
372,
291,
423,
2030,
339,
347,
485,
409,
63,
2030,
8,
277,
12,
2396,
304,
267,
340,
2396,
365,
488,
26,
288,
291,
423,
2030,
275,
330,
891,
267,
587,
26,
288,
291,
423,
2030,
275,
370,
63,
2394,
8,
2030,
12,
291,
14,
2991,
9,
339,
2396,
275,
3324,
1547,
362,
63,
2030,
12,
24985,
63,
8345,
1547,
409,
63,
2030,
12,
283,
2030,
1333,
339,
768,
1829,
272,
347,
2644,
8,
277,
304,
267,
372,
291,
423,
2991,
339,
347,
636,
495,
721,
277,
304,
267,
372,
23054,
83,
450,
83,
4335,
450,
334,
277,
14,
765,
12,
291,
14,
633,
9,
339,
636,
2722,
363,
275,
636,
495,
363,
339,
347,
1331,
8,
277,
304,
267,
408,
1767,
282,
1331,
402,
642,
4784,
624,
267,
372,
291,
14,
1814,
342,
339,
347,
3350,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
2499,
282,
892,
4784,
543,
314,
2011,
3004,
871,
367,
5204,
267,
1627,
892,
1338,
14,
267,
408,
267,
367,
671,
315,
788,
633,
297,
283,
765,
297,
283,
2139,
297,
283,
2030,
297,
283,
7792,
297,
283,
2024,
297,
2116,
283,
2991,
297,
283,
6693,
297,
283,
18671,
63,
1541,
297,
283,
3058,
297,
283,
28940,
2565,
288,
2074,
14,
5486,
8,
88,
12,
2519,
8,
277,
12,
671,
430,
267,
843,
275,
2074,
14,
1935,
360,
1886,
297,
291,
855,
533,
3368,
267,
372,
843,
2031,
589,
12,
1011,
958,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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
] |
ccn-2m/django
|
django/db/models/aggregates.py
|
521
|
2101
|
"""
Classes to represent the definitions of aggregate functions.
"""
class Aggregate(object):
"""
Default Aggregate definition.
"""
def __init__(self, lookup, **extra):
"""Instantiate a new aggregate.
* lookup is the field on which the aggregate operates.
* extra is a dictionary of additional data to provide for the
aggregate definition
Also utilizes the class variables:
* name, the identifier for this aggregate function.
"""
self.lookup = lookup
self.extra = extra
def _default_alias(self):
return '%s__%s' % (self.lookup, self.name.lower())
default_alias = property(_default_alias)
def add_to_query(self, query, alias, col, source, is_summary):
"""Add the aggregate to the nominated query.
This method is used to convert the generic Aggregate definition into a
backend-specific definition.
* query is the backend-specific query instance to which the aggregate
is to be added.
* col is a column reference describing the subject field
of the aggregate. It can be an alias, or a tuple describing
a table and column name.
* source is the underlying field or aggregate definition for
the column reference. If the aggregate is not an ordinal or
computed type, this reference is used to determine the coerced
output type of the aggregate.
* is_summary is a boolean that is set True if the aggregate is a
summary value rather than an annotation.
"""
klass = getattr(query.aggregates_module, self.name)
aggregate = klass(col, source=source, is_summary=is_summary, **self.extra)
query.aggregates[alias] = aggregate
class Avg(Aggregate):
name = 'Avg'
class Count(Aggregate):
name = 'Count'
class Max(Aggregate):
name = 'Max'
class Min(Aggregate):
name = 'Min'
class StdDev(Aggregate):
name = 'StdDev'
class Sum(Aggregate):
name = 'Sum'
class Variance(Aggregate):
name = 'Variance'
|
bsd-3-clause
|
[
624,
199,
15711,
370,
2954,
314,
10269,
402,
9531,
3423,
14,
199,
624,
199,
199,
533,
29397,
8,
785,
304,
272,
408,
272,
3758,
29397,
5492,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
4237,
12,
1011,
2911,
304,
267,
408,
10083,
18973,
282,
892,
9531,
14,
13359,
627,
4237,
365,
314,
901,
641,
1314,
314,
9531,
1758,
2335,
14,
268,
627,
2402,
365,
282,
2600,
402,
4722,
666,
370,
5647,
367,
314,
1779,
9531,
5492,
398,
6121,
7678,
19030,
397,
314,
1021,
2860,
26,
268,
627,
536,
12,
314,
5148,
367,
642,
9531,
805,
14,
267,
408,
267,
291,
14,
3892,
275,
4237,
267,
291,
14,
2911,
275,
2402,
339,
347,
485,
885,
63,
3620,
8,
277,
304,
267,
372,
1543,
83,
363,
5,
83,
7,
450,
334,
277,
14,
3892,
12,
291,
14,
354,
14,
2325,
1012,
272,
849,
63,
3620,
275,
3324,
1547,
885,
63,
3620,
9,
339,
347,
1050,
63,
475,
63,
1131,
8,
277,
12,
1827,
12,
5162,
12,
1048,
12,
1350,
12,
365,
63,
4705,
304,
267,
408,
1123,
314,
9531,
370,
314,
17468,
23831,
1827,
14,
398,
961,
1083,
365,
1202,
370,
3957,
314,
7809,
29397,
5492,
1901,
282,
267,
4865,
13,
6100,
5492,
14,
13359,
627,
1827,
365,
314,
4865,
13,
6100,
1827,
1256,
370,
1314,
314,
9531,
1779,
365,
370,
506,
3483,
14,
268,
627,
1048,
365,
282,
2763,
3659,
13660,
314,
5420,
901,
1779,
402,
314,
9531,
14,
2779,
883,
506,
376,
5162,
12,
503,
282,
2008,
13660,
1779,
282,
1817,
436,
2763,
536,
14,
268,
627,
1350,
365,
314,
8793,
901,
503,
9531,
5492,
367,
1779,
314,
2763,
3659,
14,
982,
314,
9531,
365,
440,
376,
24943,
503,
1779,
9235,
730,
12,
642,
3659,
365,
1202,
370,
6705,
314,
20650,
6867,
1779,
1072,
730,
402,
314,
9531,
14,
268,
627,
365,
63,
4705,
365,
282,
5046,
626,
365,
663,
715,
340,
314,
9531,
365,
282,
1779,
6212,
574,
7830,
2419,
376,
11262,
14,
267,
408,
267,
8531,
275,
2519,
8,
1131,
14,
21622,
63,
578,
12,
291,
14,
354,
9,
267,
9531,
275,
8531,
8,
761,
12,
1350,
29,
1365,
12,
365,
63,
4705,
29,
374,
63,
4705,
12,
1011,
277,
14,
2911,
9,
267,
1827,
14,
21622,
59,
3620,
61,
275,
9531,
199,
199,
533,
437,
10929,
8,
10170,
304,
272,
536,
275,
283,
16650,
7,
199,
199,
533,
14826,
8,
10170,
304,
272,
536,
275,
283,
2353,
7,
199,
199,
533,
8228,
8,
10170,
304,
272,
536,
275,
283,
4261,
7,
199,
199,
533,
10195,
8,
10170,
304,
272,
536,
275,
283,
4649,
7,
199,
199,
533,
20992,
12680,
8,
10170,
304,
272,
536,
275,
283,
11976,
12680,
7,
199,
199,
533,
12094,
8,
10170,
304,
272,
536,
275,
283,
6959,
7,
199,
199,
533,
21107,
554,
8,
10170,
304,
272,
536,
275,
283,
31805,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
15711,
370,
2954,
314,
10269,
402,
9531,
3423,
14,
199,
624,
199,
199,
533,
29397,
8,
785,
304,
272,
408,
272,
3758,
29397,
5492,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
4237,
12,
1011,
2911,
304,
267,
408,
10083,
18973,
282,
892,
9531,
14,
13359,
627,
4237,
365,
314,
901,
641,
1314,
314,
9531,
1758,
2335,
14,
268,
627,
2402,
365,
282,
2600,
402,
4722,
666,
370,
5647,
367,
314,
1779,
9531,
5492,
398,
6121,
7678,
19030,
397,
314,
1021,
2860,
26,
268,
627,
536,
12,
314,
5148,
367,
642,
9531,
805,
14,
267,
408,
267,
291,
14,
3892,
275,
4237,
267,
291,
14,
2911,
275,
2402,
339,
347,
485,
885,
63,
3620,
8,
277,
304,
267,
372,
1543,
83,
363,
5,
83,
7,
450,
334,
277,
14,
3892,
12,
291,
14,
354,
14,
2325,
1012,
272,
849,
63,
3620,
275,
3324,
1547,
885,
63,
3620,
9,
339,
347,
1050,
63,
475,
63,
1131,
8,
277,
12,
1827,
12,
5162,
12,
1048,
12,
1350,
12,
365,
63,
4705,
304,
267,
408,
1123,
314,
9531,
370,
314,
17468,
23831,
1827,
14,
398,
961,
1083,
365,
1202,
370,
3957,
314,
7809,
29397,
5492,
1901,
282,
267,
4865,
13,
6100,
5492,
14,
13359,
627,
1827,
365,
314,
4865,
13,
6100,
1827,
1256,
370,
1314,
314,
9531,
1779,
365,
370,
506,
3483,
14,
268,
627,
1048,
365,
282,
2763,
3659,
13660,
314,
5420,
901,
1779,
402,
314,
9531,
14,
2779,
883,
506,
376,
5162,
12,
503,
282,
2008,
13660,
1779,
282,
1817,
436,
2763,
536,
14,
268,
627,
1350,
365,
314,
8793,
901,
503,
9531,
5492,
367,
1779,
314,
2763,
3659,
14,
982,
314,
9531,
365,
440,
376,
24943,
503,
1779,
9235,
730,
12,
642,
3659,
365,
1202,
370,
6705,
314,
20650,
6867,
1779,
1072,
730,
402,
314,
9531,
14,
268,
627,
365,
63,
4705,
365,
282,
5046,
626,
365,
663,
715,
340,
314,
9531,
365,
282,
1779,
6212,
574,
7830,
2419,
376,
11262,
14,
267,
408,
267,
8531,
275,
2519,
8,
1131,
14,
21622,
63,
578,
12,
291,
14,
354,
9,
267,
9531,
275,
8531,
8,
761,
12,
1350,
29,
1365,
12,
365,
63,
4705,
29,
374,
63,
4705,
12,
1011,
277,
14,
2911,
9,
267,
1827,
14,
21622,
59,
3620,
61,
275,
9531,
199,
199,
533,
437,
10929,
8,
10170,
304,
272,
536,
275,
283,
16650,
7,
199,
199,
533,
14826,
8,
10170,
304,
272,
536,
275,
283,
2353,
7,
199,
199,
533,
8228,
8,
10170,
304,
272,
536,
275,
283,
4261,
7,
199,
199,
533,
10195,
8,
10170,
304,
272,
536,
275,
283,
4649,
7,
199,
199,
533,
20992,
12680,
8,
10170,
304,
272,
536,
275,
283,
11976,
12680,
7,
199,
199,
533,
12094,
8,
10170,
304,
272,
536,
275,
283,
6959,
7,
199,
199,
533,
21107,
554,
8,
10170,
304,
272,
536,
275,
283,
31805,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
KWARC/mwetoolkit
|
bin/old/indexlib-hacked.py
|
1
|
10320
|
import sys
import array
import codecs
import xml.sax
import gc
from bin.libs.xmlhandler.corpusXMLHandler import CorpusXMLHandler
from xmlhandler.classes.sentence import Sentence
from xmlhandler.classes.word import Word
from util import verbose
gc.set_debug(gc.DEBUG_LEAK)
NGRAM_LIMIT=16
# TODO: Unify this with patternlib and the rest of the toolkit.
ATTRIBUTE_SEPARATOR="\35"
def make_array(initializer=None):
if initializer is None:
return array.array('L')
else:
return array.array('L', initializer)
# Taken from counter.py
def load_array_from_file( an_array, a_filename ) :
MAX_MEM = 10000
fd = open( a_filename )
isMore = True
while isMore :
try :
an_array.fromfile( fd, MAX_MEM )
except EOFError :
isMore = False # Did not read MAX_MEM_ITEMS items? Not a problem...
fd.close()
def save_array_to_file(array, path):
file = open(path, "w")
array.tofile(file)
file.close()
def load_symbols_from_file(symbols, path):
file = codecs.open(path, "r", "utf-8")
id = 0
symbols.number_to_symbol = []
symbols.symbol_to_number = {}
for line in file:
sym = line.rstrip('\n')
symbols.symbol_to_number[sym] = id
symbols.number_to_symbol.append(sym)
id += 1
file.close()
def save_symbols_to_file(symbols, path):
file = codecs.open(path, "w", "utf-8")
for sym in symbols.number_to_symbol:
file.write(sym + '\n')
file.close()
#def compare_indices(corpus, max, pos1, pos2):
# while pos1<max and pos2<max and corpus[pos1] == corpus[pos2]:
# pos1 += 1
# pos2 += 1
#
# if pos1>=max:
# return -1
# elif pos2>=max:
# return 1
# else:
# return int(corpus[pos1] - corpus[pos2])
def compare_ngrams(ngram1, pos1, ngram2, pos2, ngram1_exhausted=-1, ngram2_exhausted=1, limit=NGRAM_LIMIT):
max1 = len(ngram1)
max2 = len(ngram2)
i = 0
while pos1<max1 and pos2<max2 and ngram1[pos1]==ngram2[pos2] and i<NGRAM_LIMIT:
pos1 += 1
pos2 += 1
i += 1
if pos1>=max1 and pos2>=max2:
return 0
elif pos1>=max1:
return ngram1_exhausted
elif pos2>=max2:
return ngram2_exhausted
else:
return int(ngram1[pos1] - ngram2[pos2])
def fuse_suffix_arrays(array1, array2):
# Returns a new SuffixArray fusing the 'corpus' data of each input array.
# This is used to generate indices for combined attributes (e.g., lemma+pos).
fused_array = SuffixArray()
for i in xrange(len(array1.corpus)):
sym1 = array1.symbols.number_to_symbol[array1.corpus[i]]
sym2 = array2.symbols.number_to_symbol[array2.corpus[i]]
fused_array.append_word(sym1 + ATTRIBUTE_SEPARATOR + sym2)
return fused_array
class SymbolTable:
def __init__(self):
self.symbol_to_number = {'': 0}
self.number_to_symbol = ['']
self.last_number = 0
def intern(self, symbol):
if not self.symbol_to_number.has_key(symbol):
self.last_number += 1
self.symbol_to_number[symbol] = self.last_number
#self.number_to_symbol[self.last_number] = symbol
self.number_to_symbol.append(symbol) # Risky and not intention-expressing
return self.symbol_to_number[symbol]
class SuffixArray:
def __init__(self):
self.corpus = make_array() # List of word numbers
self.suffix = make_array() # List of word positions
self.symbols = SymbolTable() # word<->number conversion table
def set_basepath(self, basepath):
self.basepath = basepath
self.corpus_path = basepath + ".corpus"
self.suffix_path = basepath + ".suffix"
self.symbols_path = basepath + ".symbols"
def load(self):
load_array_from_file(self.corpus, self.corpus_path)
load_array_from_file(self.suffix, self.suffix_path)
load_symbols_from_file(self.symbols, self.symbols_path)
def save(self):
save_array_to_file(self.corpus, self.corpus_path)
save_array_to_file(self.suffix, self.suffix_path)
save_symbols_to_file(self.symbols, self.symbols_path)
def append_word(self, word):
self.corpus.append(self.symbols.intern(word))
# For debugging.
def append_string(self, sentence):
for w in sentence.split():
self.append_word(w)
def build_suffix_array(self):
tmpseq = range(0, len(self.corpus))
tmpsuf = sorted(tmpseq, cmp=(lambda a,b: compare_ngrams(self.corpus, a, self.corpus, b)))
self.suffix = make_array(tmpsuf)
def find_ngram_range(self, ngram, min=0, max=None):
# Returns a tuple (min, max) of matching ngram positions in suffix array
# TODO: We will need a more "incremental" approach for searching for
# patterns that use multple word attributes.
if max is None:
max = len(self.suffix) - 1
first = self.binary_search_ngram(ngram, min, max, (lambda a,b: a >= b))
last = self.binary_search_ngram(ngram, min, max, (lambda a,b: a > b))
if first is None:
return None
if last is None:
last = max
else:
last -= 1
if first <= last:
return (first, last)
else:
return None
def binary_search_ngram(self, ngram, first, last, cmp):
# Find the least suffix that satisfies suffix `cmp` ngram.
# 'max' must be one more than 'last', for the case no suffix
# satisfies the comparison.
max = last + 1
min = first
while min < max:
mid = (min+max)/2
if cmp(compare_ngrams(self.corpus, self.suffix[mid], ngram, 0, ngram2_exhausted=0), 0):
max = mid # If 'mid' satisfies, then what we want *is* mid or *is before* mid
else:
mid += 1
min = mid # If 'mid' does not satisfy, what we want *must be after* mid.
if mid > last:
return None
else:
return mid
# For debugging.
def dump_suffixes(self, limit=10):
for pos in self.suffix:
print "%4d:" % pos,
for i in range(pos, pos+limit):
if i < len(self.corpus):
print self.symbols.number_to_symbol[self.corpus[i]],
else:
print "*",
print ""
class Index:
# Attribute order must be the same as the parameters of 'Word'
WORD_ATTRIBUTES = ['surface', 'lemma', 'pos', 'syn']
def __init__(self, basepath=None):
self.arrays = {}
self.metadata = { "corpus_size": 0 }
if basepath is not None:
self.set_basepath(basepath)
def fresh_arrays(self):
for attr in Index.WORD_ATTRIBUTES:
self.arrays[attr] = SuffixArray()
def set_basepath(self, path):
self.basepath = path
self.metadata_path = path + ".info"
def load(self, attribute):
if self.arrays.has_key(attribute):
return self.arrays[attribute]
verbose("Loading corpus files for attribute \"%s\"." % attribute)
array = SuffixArray()
path = self.basepath + "." + attribute
array.set_basepath(path)
try:
array.load()
except IOError, err:
# If attribute is composed, fuse the corresponding suffix arrays.
if '+' in attribute:
attr1, attr2 = attribute.rsplit('+', 1)
array = fuse_suffix_arrays(self.load(attr1), self.load(attr2))
array.set_basepath(path)
array.build_suffix_array()
array.save()
else:
raise err
self.arrays[attribute] = array
return array
def save(self, attribute):
array = self.arrays[attribute]
array.set_basepath(self.basepath + "." + attribute)
array.save()
def load_metadata(self):
metafile = open(self.metadata_path)
for line in metafile:
key, type, value = line.rstrip('\n').split(" ", 2)
if type == "int":
value = int(value)
self.metadata[key] = value
metafile.close()
def save_metadata(self):
metafile = open(self.metadata_path, "w")
for key, value in self.metadata.items():
if isinstance(value, int):
type = "int"
else:
type = "string"
metafile.write("%s %s %s\n" % (key, type, value))
metafile.close()
# Load/save main (non-composite) attributes and metadata
def load_main(self):
self.load_metadata()
for attr in Index.WORD_ATTRIBUTES:
self.load(attr)
def save_main(self):
self.save_metadata()
for attr in Index.WORD_ATTRIBUTES:
self.save(attr)
def append_sentence(self, sentence):
# Adds a sentence (presumably extracted from a XML file) to the index.
for attr in Index.WORD_ATTRIBUTES:
for word in sentence.word_list:
value = getattr(word, attr)
self.arrays[attr].append_word(value)
self.arrays[attr].append_word('') # '' (symbol 0) means end-of-sentence
self.metadata["corpus_size"] += len(sentence.word_list)
def build_suffix_arrays(self, save=False, free_after=False):
for attr in self.arrays.keys():
print "Building suffix array for %s..." % attr
self.arrays[attr].build_suffix_array()
if save:
self.save(attr)
if free_after:
del self.arrays[attr]
def iterate_sentences(self):
# Returns an iterator over all sentences in the corpus.
id = 1
guide = Index.WORD_ATTRIBUTES[0] # guide?
length = len(self.arrays[guide].corpus)
words = []
for i in range(0, length):
if self.arrays[guide].corpus[i] == 0:
# We have already a whole sentence.
sentence = Sentence(words, id)
id += 1
words = []
yield sentence
else:
args = []
for attr in Index.WORD_ATTRIBUTES:
number = self.arrays[attr].corpus[i]
symbol = self.arrays[attr].symbols.number_to_symbol[number]
args.append(symbol)
args.append([])
words.append(Word(*args))
# For debugging.
def print_sentences(self):
for sentence in self.iterate_sentences():
for word in sentence.word_list:
print word.surface,
print ""
# For testing.
#h = SuffixArray()
#s = "the quick brown fox jumps over the lazy dog which wanted the fox to jump away into the house"
#h.append_string(s)
#h.build_suffix_array()
# For more testing.
def index_from_corpus(basepath, corpus_file):
#file = open(corpus_file)
parser = xml.sax.make_parser()
index = Index()
index.set_basepath(basepath)
index.fresh_arrays()
parser.setContentHandler(CorpusXMLHandler(index.append_sentence))
parser.parse(corpus_file)
index.save_metadata()
index.build_suffix_arrays(save=True, free_after=True)
return index
#h = index_from_corpus("../toy/genia/corpus.xml")
#h.set_basepath("/tmp/foo")
#h.save_main()
#t = fuse_suffix_arrays(h.arrays["surface"], h.arrays["pos"])
def standalone_main(argv):
if len(argv) < 3:
print >>sys.stderr, "Usage: python indexlib.py <basepath> <corpus> [<attr>:<attr>:...]"
return 1
basepath = argv[1]
corpus = argv[2]
# Gambiarra -- FIXME FIXME FIXME
if len(argv) > 3:
Index.WORD_ATTRIBUTES = argv[3].split(":")
index = index_from_corpus(basepath, corpus)
print >>sys.stderr, "Done."
if __name__ == "__main__":
standalone_main(sys.argv)
|
gpl-3.0
|
[
646,
984,
199,
646,
1625,
199,
646,
6010,
199,
646,
2748,
14,
14338,
199,
646,
9486,
199,
199,
504,
2517,
14,
8450,
14,
1652,
2232,
14,
16780,
4317,
2461,
492,
7499,
8843,
4317,
2461,
199,
504,
2748,
2232,
14,
2888,
14,
17727,
492,
428,
287,
6692,
199,
504,
2748,
2232,
14,
2888,
14,
1027,
492,
14644,
199,
504,
4884,
492,
3376,
199,
199,
9493,
14,
409,
63,
1757,
8,
9493,
14,
5287,
63,
906,
7872,
9,
421,
199,
46,
10896,
63,
13387,
29,
975,
199,
199,
3,
3254,
26,
1910,
2021,
642,
543,
3851,
773,
436,
314,
4618,
402,
314,
4744,
6065,
14,
199,
17075,
63,
15828,
21024,
1276,
2,
199,
199,
318,
1852,
63,
1144,
8,
6498,
29,
403,
304,
199,
198,
692,
11130,
365,
488,
26,
507,
198,
1107,
1625,
14,
1144,
360,
44,
358,
199,
198,
2836,
26,
507,
198,
1107,
1625,
14,
1144,
360,
44,
297,
11130,
9,
421,
199,
3,
32316,
917,
687,
7055,
14,
647,
199,
318,
2248,
63,
1144,
63,
504,
63,
493,
8,
376,
63,
1144,
12,
282,
63,
1501,
776,
520,
272,
9141,
63,
10293,
275,
11630,
272,
6111,
275,
1551,
8,
282,
63,
1501,
776,
272,
365,
11053,
275,
715,
272,
1830,
365,
11053,
520,
267,
862,
520,
258,
288,
376,
63,
1144,
14,
30717,
8,
6111,
12,
9141,
63,
10293,
776,
267,
871,
21157,
520,
288,
365,
11053,
275,
756,
327,
29503,
440,
1586,
9141,
63,
10293,
63,
10439,
51,
2974,
31,
2832,
282,
5160,
1396,
272,
6111,
14,
1600,
342,
199,
199,
318,
3354,
63,
1144,
63,
475,
63,
493,
8,
1144,
12,
931,
304,
199,
198,
493,
275,
1551,
8,
515,
12,
298,
87,
531,
199,
198,
1144,
14,
475,
493,
8,
493,
9,
199,
198,
493,
14,
1600,
342,
199,
199,
318,
2248,
63,
7450,
63,
504,
63,
493,
8,
7450,
12,
931,
304,
199,
198,
493,
275,
6010,
14,
1490,
8,
515,
12,
298,
82,
401,
298,
1624,
13,
24,
531,
199,
198,
344,
275,
378,
199,
198,
7450,
14,
1955,
63,
475,
63,
5155,
275,
942,
199,
198,
7450,
14,
5155,
63,
475,
63,
1955,
275,
1052,
199,
198,
509,
1004,
315,
570,
26,
507,
198,
3840,
275,
1004,
14,
6735,
2258,
78,
358,
507,
198,
7450,
14,
5155,
63,
475,
63,
1955,
59,
3840,
61,
275,
1305,
507,
198,
7450,
14,
1955,
63,
475,
63,
5155,
14,
740,
8,
3840,
9,
507,
198,
344,
847,
413,
421,
198,
493,
14,
1600,
342,
199,
199,
318,
3354,
63,
7450,
63,
475,
63,
493,
8,
7450,
12,
931,
304,
199,
198,
493,
275,
6010,
14,
1490,
8,
515,
12,
298,
87,
401,
298,
1624,
13,
24,
531,
199,
198,
509,
4678,
315,
6698,
14,
1955,
63,
475,
63,
5155,
26,
507,
198,
493,
14,
952,
8,
3840,
435,
1557,
78,
358,
199,
198,
493,
14,
1600,
342,
421,
199,
3,
318,
6540,
63,
4108,
8,
16780,
12,
1390,
12,
2086,
17,
12,
2086,
18,
304,
199,
3,
198,
6710,
2086,
17,
28,
988,
436,
2086,
18,
28,
988,
436,
16831,
59,
1712,
17,
61,
508,
16831,
59,
1712,
18,
2189,
199,
3,
198,
198,
1712,
17,
847,
413,
199,
3,
198,
198,
1712,
18,
847,
413,
199,
3,
199,
3,
198,
692,
2086,
17,
8119,
988,
26,
199,
3,
198,
198,
1107,
446,
17,
199,
3,
198,
4164,
2086,
18,
8119,
988,
26,
199,
3,
198,
198,
1107,
413,
199,
3,
198,
2836,
26,
199,
3,
198,
198,
1107,
1109,
8,
16780,
59,
1712,
17,
61,
446,
16831,
59,
1712,
18,
566,
199,
199,
318,
6540,
63,
78,
9292,
8,
78,
1679,
17,
12,
2086,
17,
12,
302,
1679,
18,
12,
2086,
18,
12,
302,
1679,
17,
63,
476,
2411,
7274,
4022,
17,
12,
302,
1679,
18,
63,
476,
2411,
7274,
29,
17,
12,
2304,
29,
46,
10896,
63,
13387,
304,
199,
198,
988,
17,
275,
822,
8,
78,
1679,
17,
9,
199,
198,
988,
18,
275,
822,
8,
78,
1679,
18,
9,
199,
198,
73,
275,
378,
199,
198,
6710,
2086,
17,
28,
988,
17,
436,
2086,
18,
28,
988,
18,
436,
302,
1679,
17,
59,
1712,
17,
19219,
78,
1679,
18,
59,
1712,
18,
61,
436,
284,
28,
46,
10896,
63,
13387,
26,
507,
198,
1712,
17,
847,
413,
507,
198,
1712,
18,
847,
413,
507,
198,
73,
847,
413,
421,
198,
692,
2086,
17,
8119,
988,
17,
436,
2086,
18,
8119,
988,
18,
26,
507,
198,
1107,
378,
199,
198,
4164,
2086,
17,
8119,
988,
17,
26,
507,
198,
1107,
302,
1679,
17,
63,
476,
2411,
7274,
199,
198,
4164,
2086,
18,
8119,
988,
18,
26,
507,
198,
1107,
302,
1679,
18,
63,
476,
2411,
7274,
199,
198,
2836,
26,
507,
198,
1107,
1109,
8,
78,
1679,
17,
59,
1712,
17,
61,
446,
302,
1679,
18,
59,
1712,
18,
566,
199,
199,
318,
289,
1180,
63,
4511,
63,
10095,
8,
1144,
17,
12,
1625,
18,
304,
199,
198,
3,
1803,
282,
892,
428,
2875,
3836,
289,
4941,
314,
283,
16780,
7,
666,
402,
1924,
1324,
1625,
14,
199,
198,
3,
961,
365,
1202,
370,
3550,
4918,
367,
12149,
3004,
334,
69,
14,
71,
2020,
1026,
77,
391,
11,
1712,
680,
421,
198,
30032,
63,
1144,
275,
428,
2875,
3836,
342,
199,
198,
509,
284,
315,
4945,
8,
552,
8,
1144,
17,
14,
16780,
2298,
507,
198,
3840,
17,
275,
1625,
17,
14,
7450,
14,
1955,
63,
475,
63,
5155,
59,
1144,
17,
14,
16780,
59,
73,
2677,
507,
198,
3840,
18,
275,
1625,
18,
14,
7450,
14,
1955,
63,
475,
63,
5155,
59,
1144,
18,
14,
16780,
59,
73,
2677,
507,
198,
30032,
63,
1144,
14,
740,
63,
1027,
8,
3840,
17,
435,
10762,
2100,
4586,
63,
15828,
435,
4678,
18,
9,
421,
198,
1107,
28580,
63,
1144,
421,
199,
533,
10080,
3186,
26,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
5155,
63,
475,
63,
1955,
275,
791,
356,
378,
93,
507,
198,
277,
14,
1955,
63,
475,
63,
5155,
275,
24506,
507,
198,
277,
14,
2019,
63,
1955,
275,
378,
421,
198,
318,
10757,
8,
277,
12,
5272,
304,
507,
198,
692,
440,
291,
14,
5155,
63,
475,
63,
1955
] |
[
984,
199,
646,
1625,
199,
646,
6010,
199,
646,
2748,
14,
14338,
199,
646,
9486,
199,
199,
504,
2517,
14,
8450,
14,
1652,
2232,
14,
16780,
4317,
2461,
492,
7499,
8843,
4317,
2461,
199,
504,
2748,
2232,
14,
2888,
14,
17727,
492,
428,
287,
6692,
199,
504,
2748,
2232,
14,
2888,
14,
1027,
492,
14644,
199,
504,
4884,
492,
3376,
199,
199,
9493,
14,
409,
63,
1757,
8,
9493,
14,
5287,
63,
906,
7872,
9,
421,
199,
46,
10896,
63,
13387,
29,
975,
199,
199,
3,
3254,
26,
1910,
2021,
642,
543,
3851,
773,
436,
314,
4618,
402,
314,
4744,
6065,
14,
199,
17075,
63,
15828,
21024,
1276,
2,
199,
199,
318,
1852,
63,
1144,
8,
6498,
29,
403,
304,
199,
198,
692,
11130,
365,
488,
26,
507,
198,
1107,
1625,
14,
1144,
360,
44,
358,
199,
198,
2836,
26,
507,
198,
1107,
1625,
14,
1144,
360,
44,
297,
11130,
9,
421,
199,
3,
32316,
917,
687,
7055,
14,
647,
199,
318,
2248,
63,
1144,
63,
504,
63,
493,
8,
376,
63,
1144,
12,
282,
63,
1501,
776,
520,
272,
9141,
63,
10293,
275,
11630,
272,
6111,
275,
1551,
8,
282,
63,
1501,
776,
272,
365,
11053,
275,
715,
272,
1830,
365,
11053,
520,
267,
862,
520,
258,
288,
376,
63,
1144,
14,
30717,
8,
6111,
12,
9141,
63,
10293,
776,
267,
871,
21157,
520,
288,
365,
11053,
275,
756,
327,
29503,
440,
1586,
9141,
63,
10293,
63,
10439,
51,
2974,
31,
2832,
282,
5160,
1396,
272,
6111,
14,
1600,
342,
199,
199,
318,
3354,
63,
1144,
63,
475,
63,
493,
8,
1144,
12,
931,
304,
199,
198,
493,
275,
1551,
8,
515,
12,
298,
87,
531,
199,
198,
1144,
14,
475,
493,
8,
493,
9,
199,
198,
493,
14,
1600,
342,
199,
199,
318,
2248,
63,
7450,
63,
504,
63,
493,
8,
7450,
12,
931,
304,
199,
198,
493,
275,
6010,
14,
1490,
8,
515,
12,
298,
82,
401,
298,
1624,
13,
24,
531,
199,
198,
344,
275,
378,
199,
198,
7450,
14,
1955,
63,
475,
63,
5155,
275,
942,
199,
198,
7450,
14,
5155,
63,
475,
63,
1955,
275,
1052,
199,
198,
509,
1004,
315,
570,
26,
507,
198,
3840,
275,
1004,
14,
6735,
2258,
78,
358,
507,
198,
7450,
14,
5155,
63,
475,
63,
1955,
59,
3840,
61,
275,
1305,
507,
198,
7450,
14,
1955,
63,
475,
63,
5155,
14,
740,
8,
3840,
9,
507,
198,
344,
847,
413,
421,
198,
493,
14,
1600,
342,
199,
199,
318,
3354,
63,
7450,
63,
475,
63,
493,
8,
7450,
12,
931,
304,
199,
198,
493,
275,
6010,
14,
1490,
8,
515,
12,
298,
87,
401,
298,
1624,
13,
24,
531,
199,
198,
509,
4678,
315,
6698,
14,
1955,
63,
475,
63,
5155,
26,
507,
198,
493,
14,
952,
8,
3840,
435,
1557,
78,
358,
199,
198,
493,
14,
1600,
342,
421,
199,
3,
318,
6540,
63,
4108,
8,
16780,
12,
1390,
12,
2086,
17,
12,
2086,
18,
304,
199,
3,
198,
6710,
2086,
17,
28,
988,
436,
2086,
18,
28,
988,
436,
16831,
59,
1712,
17,
61,
508,
16831,
59,
1712,
18,
2189,
199,
3,
198,
198,
1712,
17,
847,
413,
199,
3,
198,
198,
1712,
18,
847,
413,
199,
3,
199,
3,
198,
692,
2086,
17,
8119,
988,
26,
199,
3,
198,
198,
1107,
446,
17,
199,
3,
198,
4164,
2086,
18,
8119,
988,
26,
199,
3,
198,
198,
1107,
413,
199,
3,
198,
2836,
26,
199,
3,
198,
198,
1107,
1109,
8,
16780,
59,
1712,
17,
61,
446,
16831,
59,
1712,
18,
566,
199,
199,
318,
6540,
63,
78,
9292,
8,
78,
1679,
17,
12,
2086,
17,
12,
302,
1679,
18,
12,
2086,
18,
12,
302,
1679,
17,
63,
476,
2411,
7274,
4022,
17,
12,
302,
1679,
18,
63,
476,
2411,
7274,
29,
17,
12,
2304,
29,
46,
10896,
63,
13387,
304,
199,
198,
988,
17,
275,
822,
8,
78,
1679,
17,
9,
199,
198,
988,
18,
275,
822,
8,
78,
1679,
18,
9,
199,
198,
73,
275,
378,
199,
198,
6710,
2086,
17,
28,
988,
17,
436,
2086,
18,
28,
988,
18,
436,
302,
1679,
17,
59,
1712,
17,
19219,
78,
1679,
18,
59,
1712,
18,
61,
436,
284,
28,
46,
10896,
63,
13387,
26,
507,
198,
1712,
17,
847,
413,
507,
198,
1712,
18,
847,
413,
507,
198,
73,
847,
413,
421,
198,
692,
2086,
17,
8119,
988,
17,
436,
2086,
18,
8119,
988,
18,
26,
507,
198,
1107,
378,
199,
198,
4164,
2086,
17,
8119,
988,
17,
26,
507,
198,
1107,
302,
1679,
17,
63,
476,
2411,
7274,
199,
198,
4164,
2086,
18,
8119,
988,
18,
26,
507,
198,
1107,
302,
1679,
18,
63,
476,
2411,
7274,
199,
198,
2836,
26,
507,
198,
1107,
1109,
8,
78,
1679,
17,
59,
1712,
17,
61,
446,
302,
1679,
18,
59,
1712,
18,
566,
199,
199,
318,
289,
1180,
63,
4511,
63,
10095,
8,
1144,
17,
12,
1625,
18,
304,
199,
198,
3,
1803,
282,
892,
428,
2875,
3836,
289,
4941,
314,
283,
16780,
7,
666,
402,
1924,
1324,
1625,
14,
199,
198,
3,
961,
365,
1202,
370,
3550,
4918,
367,
12149,
3004,
334,
69,
14,
71,
2020,
1026,
77,
391,
11,
1712,
680,
421,
198,
30032,
63,
1144,
275,
428,
2875,
3836,
342,
199,
198,
509,
284,
315,
4945,
8,
552,
8,
1144,
17,
14,
16780,
2298,
507,
198,
3840,
17,
275,
1625,
17,
14,
7450,
14,
1955,
63,
475,
63,
5155,
59,
1144,
17,
14,
16780,
59,
73,
2677,
507,
198,
3840,
18,
275,
1625,
18,
14,
7450,
14,
1955,
63,
475,
63,
5155,
59,
1144,
18,
14,
16780,
59,
73,
2677,
507,
198,
30032,
63,
1144,
14,
740,
63,
1027,
8,
3840,
17,
435,
10762,
2100,
4586,
63,
15828,
435,
4678,
18,
9,
421,
198,
1107,
28580,
63,
1144,
421,
199,
533,
10080,
3186,
26,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277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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
] |
mganeva/mantid
|
qt/python/mantidqt/project/projectsaver.py
|
1
|
5274
|
# 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
# SPDX - License - Identifier: GPL - 3.0 +
# This file is part of the mantidqt package
#
from __future__ import (absolute_import, division, print_function, unicode_literals)
from json import dump
import os
from mantid.api import AnalysisDataService as ADS
from mantidqt.project.workspacesaver import WorkspaceSaver
from mantidqt.project.plotssaver import PlotsSaver
from mantid import logger
class ProjectSaver(object):
def __init__(self, project_file_ext):
self.project_file_ext = project_file_ext
def save_project(self, file_name, workspace_to_save=None, plots_to_save=None, interfaces_to_save=None,
project_recovery=True):
"""
The method that will actually save the project and call relevant savers for workspaces, plots, interfaces etc.
:param file_name: String; The file_name of the
:param workspace_to_save: List; of Strings that will have workspace names in it, if None will save all
:param plots_to_save: List; of matplotlib.figure objects to save to the project file.
:param interfaces_to_save: List of Lists of Window and Encoder; the interfaces to save and the encoders to use
:param project_recovery: Bool; If the behaviour of Project Save should be altered to function correctly inside
of project recovery
:return: None; If the method cannot be completed.
"""
# Check if the file_name doesn't exist
if file_name is None:
logger.warning("Please select a valid file name")
return
# Check this isn't saving a blank project file
if (workspace_to_save is None and plots_to_save is None and interfaces_to_save is None) and project_recovery:
logger.warning("Can not save an empty project")
return
directory = os.path.dirname(file_name)
# Save workspaces to that location
if project_recovery:
workspace_saver = WorkspaceSaver(directory=directory)
workspace_saver.save_workspaces(workspaces_to_save=workspace_to_save)
saved_workspaces = workspace_saver.get_output_list()
else:
# Assume that this is project recovery so pass a list of workspace names
saved_workspaces = ADS.getObjectNames()
# Generate plots
plots_to_save_list = PlotsSaver().save_plots(plots_to_save)
# Save interfaces
if interfaces_to_save is None:
interfaces_to_save = []
interfaces = self._return_interfaces_dicts(directory=directory, interfaces_to_save=interfaces_to_save)
# Pass dicts to Project Writer
writer = ProjectWriter(workspace_names=saved_workspaces,
plots_to_save=plots_to_save_list,
interfaces_to_save=interfaces,
save_location=file_name,
project_file_ext=self.project_file_ext)
writer.write_out()
@staticmethod
def _return_interfaces_dicts(directory, interfaces_to_save):
interfaces = []
for interface, encoder in interfaces_to_save:
# Add to the dictionary encoded data with the key as the first tag in the list on the encoder attributes
try:
tag = encoder.tags[0]
encoded_dict = encoder.encode(interface, directory)
encoded_dict["tag"] = tag
interfaces.append(encoded_dict)
except Exception as e:
# Catch any exception and log it
if isinstance(e, KeyboardInterrupt):
raise
logger.warning("Project Saver: An interface could not be saver error: " + str(e))
return interfaces
class ProjectWriter(object):
def __init__(self, save_location, workspace_names, project_file_ext, plots_to_save, interfaces_to_save):
self.workspace_names = workspace_names
self.file_name = save_location
self.project_file_ext = project_file_ext
self.plots_to_save = plots_to_save
self.interfaces_to_save = interfaces_to_save
def write_out(self):
"""
Write out the project file that contains workspace names, interfaces information, plot preferences etc.
"""
# Get the JSON string versions
to_save_dict = {"workspaces": self.workspace_names, "plots": self.plots_to_save,
"interfaces": self.interfaces_to_save}
# Open file and save the string to it alongside the workspace_names
if self.project_file_ext not in os.path.basename(self.file_name):
self.file_name = self.file_name + self.project_file_ext
try:
with open(self.file_name, "w+") as f:
dump(obj=to_save_dict, fp=f)
except Exception as e:
# Catch any exception and log it
if isinstance(e, KeyboardInterrupt):
raise
logger.warning("JSON project file unable to be opened/written to")
|
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,
258,
653,
7181,
36,
593,
1151,
31196,
20548,
16871,
31671,
12,
31615,
290,
8360,
8408,
5800,
199,
3,
258,
1253,
1010,
6329,
337,
7964,
310,
446,
491,
618,
11908,
199,
3,
6988,
19596,
446,
844,
446,
23285,
26,
14629,
446,
650,
14,
16,
435,
199,
3,
221,
961,
570,
365,
1777,
402,
314,
2169,
5700,
8440,
2559,
199,
3,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
9,
199,
199,
504,
2022,
492,
5461,
199,
646,
747,
199,
199,
504,
2169,
5700,
14,
1246,
492,
21916,
1451,
3167,
465,
437,
3177,
199,
504,
2169,
5700,
8440,
14,
1715,
14,
800,
10749,
28396,
492,
9361,
2638,
20829,
199,
504,
2169,
5700,
8440,
14,
1715,
14,
2798,
28023,
422,
492,
510,
4555,
20829,
199,
504,
2169,
5700,
492,
2512,
421,
199,
533,
7290,
20829,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
2199,
63,
493,
63,
832,
304,
267,
291,
14,
1715,
63,
493,
63,
832,
275,
2199,
63,
493,
63,
832,
339,
347,
3354,
63,
1715,
8,
277,
12,
570,
63,
354,
12,
14466,
63,
475,
63,
2117,
29,
403,
12,
19695,
63,
475,
63,
2117,
29,
403,
12,
8386,
63,
475,
63,
2117,
29,
403,
12,
2151,
2199,
63,
29920,
29,
549,
304,
267,
408,
267,
710,
1083,
626,
911,
5965,
3354,
314,
2199,
436,
1240,
12082,
2937,
14895,
367,
1736,
10749,
12,
19695,
12,
8386,
5423,
14,
267,
520,
635,
570,
63,
354,
26,
2624,
27,
710,
570,
63,
354,
402,
314,
267,
520,
635,
14466,
63,
475,
63,
2117,
26,
3820,
27,
402,
24361,
626,
911,
1172,
14466,
1561,
315,
652,
12,
340,
488,
911,
3354,
1006,
267,
520,
635,
19695,
63,
475,
63,
2117,
26,
3820,
27,
402,
8027,
14,
8941,
2251,
370,
3354,
370,
314,
2199,
570,
14,
267,
520,
635,
8386,
63,
475,
63,
2117,
26,
3820,
402,
31289,
402,
15689,
436,
3447,
2693,
27,
314,
8386,
370,
3354,
436,
314,
10295,
83,
370,
675,
267,
520,
635,
2199,
63,
29920,
26,
19287,
27,
982,
314,
13942,
402,
7290,
11063,
1077,
506,
29815,
370,
805,
6657,
6272,
267,
402,
2199,
24201,
267,
520,
1107,
26,
488,
27,
982,
314,
1083,
3913,
506,
9709,
14,
267,
408,
267,
327,
2670,
340,
314,
570,
63,
354,
3181,
1133,
2187,
267,
340,
570,
63,
354,
365,
488,
26,
288,
2512,
14,
3764,
480,
8254,
3504,
282,
1686,
570,
536,
531,
288,
372,
398,
327,
2670,
642,
5712,
1133,
13369,
282,
4596,
2199,
570,
267,
340,
334,
13249,
63,
475,
63,
2117,
365,
488,
436,
19695,
63,
475,
63,
2117,
365,
488,
436,
8386,
63,
475,
63,
2117,
365,
488,
9,
436,
2199,
63,
29920,
26,
288,
2512,
14,
3764,
480,
6049,
440,
3354,
376,
2701,
2199,
531,
288,
372,
398,
2082,
275,
747,
14,
515,
14,
3475,
8,
493,
63,
354,
9,
267,
327,
11063,
1736,
10749,
370,
626,
2909,
267,
340,
2199,
63,
29920,
26,
288,
14466,
63,
21166,
275,
9361,
2638,
20829,
8,
3619,
29,
3619,
9,
288,
14466,
63,
21166,
14,
2117,
63,
800,
10749,
8,
800,
10749,
63,
475,
63,
2117,
29,
13249,
63,
475,
63,
2117,
9,
288,
6290,
63,
800,
10749,
275,
14466,
63,
21166,
14,
362,
63,
1199,
63,
513,
342,
267,
587,
26,
288,
327,
16269,
626,
642,
365,
2199,
24201,
880,
986,
282,
769,
402,
14466,
1561,
288,
6290,
63,
800,
10749,
275,
437,
3177,
14,
362,
1692,
5866,
342,
398,
327,
7958,
19695,
267,
19695,
63,
475,
63,
2117,
63,
513,
275,
510,
4555,
20829,
1252,
2117,
63,
13701,
8,
13701,
63,
475,
63,
2117,
9,
398,
327,
11063,
8386,
267,
340,
8386,
63,
475,
63,
2117,
365,
488,
26,
288,
8386,
63,
475,
63,
2117,
275,
942,
398,
8386,
275,
291,
423,
1107,
63,
7436,
63,
7892,
8,
3619,
29,
3619,
12,
8386,
63,
475,
63,
2117,
29,
7436,
63,
475,
63,
2117,
9,
398,
327,
8325,
10809,
370,
7290,
24441,
267,
7060,
275,
7290,
6261,
8,
13249,
63,
1247,
29,
8420,
63,
800,
10749,
12,
3044,
19695,
63,
475,
63,
2117,
29,
13701,
63,
475,
63,
2117,
63,
513,
12,
3044,
8386,
63,
475,
63,
2117,
29,
7436,
12,
3044,
3354,
63,
1985,
29,
493,
63,
354,
12,
3044,
2199,
63,
493,
63,
832,
29,
277,
14,
1715,
63,
493,
63,
832,
9,
267,
7060,
14,
952,
63,
548,
342,
339,
768,
4639,
272,
347,
485,
1107,
63,
7436,
63,
7892,
8,
3619,
12,
8386,
63,
475,
63,
2117,
304,
267,
8386,
275,
942,
267,
367,
3217,
12,
10295,
315,
8386,
63,
475,
63,
2117,
26,
288,
327,
2654,
370,
314,
2600,
5737,
666,
543,
314,
790,
465,
314,
1642,
1947,
315,
314,
769,
641,
314,
10295,
3004,
288,
862,
26,
355,
1947,
275,
10295,
14,
2969,
59,
16,
61,
355,
5737,
63,
807,
275,
10295,
14,
2143,
8,
3266,
12,
2082,
9,
355,
5737,
63,
807,
905,
1450,
937,
275,
1947,
355,
8386,
14,
740,
8,
8167,
63,
807,
9,
288,
871,
2186,
465,
325,
26,
355,
327,
32754,
1263,
1919,
436,
943,
652,
355,
340,
1228,
8,
69,
12,
13483,
304,
490,
746,
355,
2512,
14,
3764,
480,
4761,
428,
28396,
26,
1626,
3217,
4293,
440,
506,
17559,
1125,
26,
298,
435,
620,
8,
69,
430,
398,
372,
8386,
421,
199,
533,
7290,
6261,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
3354,
63,
1985,
12,
14466,
63,
1247,
12,
2199,
63,
493,
63,
832,
12,
19695,
63,
475,
63,
2117,
12,
8386,
63,
475,
63,
2117,
304,
267,
291,
14,
13249,
63,
1247,
275,
14466,
63,
1247,
267,
291,
14,
493,
63,
354,
275,
3354,
63,
1985,
267,
291,
14,
1715,
63,
493,
63,
832,
275,
2199,
63,
493,
63,
832,
267,
291,
14,
13701,
63,
475,
63,
2117,
275,
19695,
63,
475,
63,
2117,
267,
291,
14,
7436,
63,
475,
63,
2117,
275,
8386,
63,
475,
63
] |
[
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,
258,
653,
7181,
36,
593,
1151,
31196,
20548,
16871,
31671,
12,
31615,
290,
8360,
8408,
5800,
199,
3,
258,
1253,
1010,
6329,
337,
7964,
310,
446,
491,
618,
11908,
199,
3,
6988,
19596,
446,
844,
446,
23285,
26,
14629,
446,
650,
14,
16,
435,
199,
3,
221,
961,
570,
365,
1777,
402,
314,
2169,
5700,
8440,
2559,
199,
3,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
9,
199,
199,
504,
2022,
492,
5461,
199,
646,
747,
199,
199,
504,
2169,
5700,
14,
1246,
492,
21916,
1451,
3167,
465,
437,
3177,
199,
504,
2169,
5700,
8440,
14,
1715,
14,
800,
10749,
28396,
492,
9361,
2638,
20829,
199,
504,
2169,
5700,
8440,
14,
1715,
14,
2798,
28023,
422,
492,
510,
4555,
20829,
199,
504,
2169,
5700,
492,
2512,
421,
199,
533,
7290,
20829,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
2199,
63,
493,
63,
832,
304,
267,
291,
14,
1715,
63,
493,
63,
832,
275,
2199,
63,
493,
63,
832,
339,
347,
3354,
63,
1715,
8,
277,
12,
570,
63,
354,
12,
14466,
63,
475,
63,
2117,
29,
403,
12,
19695,
63,
475,
63,
2117,
29,
403,
12,
8386,
63,
475,
63,
2117,
29,
403,
12,
2151,
2199,
63,
29920,
29,
549,
304,
267,
408,
267,
710,
1083,
626,
911,
5965,
3354,
314,
2199,
436,
1240,
12082,
2937,
14895,
367,
1736,
10749,
12,
19695,
12,
8386,
5423,
14,
267,
520,
635,
570,
63,
354,
26,
2624,
27,
710,
570,
63,
354,
402,
314,
267,
520,
635,
14466,
63,
475,
63,
2117,
26,
3820,
27,
402,
24361,
626,
911,
1172,
14466,
1561,
315,
652,
12,
340,
488,
911,
3354,
1006,
267,
520,
635,
19695,
63,
475,
63,
2117,
26,
3820,
27,
402,
8027,
14,
8941,
2251,
370,
3354,
370,
314,
2199,
570,
14,
267,
520,
635,
8386,
63,
475,
63,
2117,
26,
3820,
402,
31289,
402,
15689,
436,
3447,
2693,
27,
314,
8386,
370,
3354,
436,
314,
10295,
83,
370,
675,
267,
520,
635,
2199,
63,
29920,
26,
19287,
27,
982,
314,
13942,
402,
7290,
11063,
1077,
506,
29815,
370,
805,
6657,
6272,
267,
402,
2199,
24201,
267,
520,
1107,
26,
488,
27,
982,
314,
1083,
3913,
506,
9709,
14,
267,
408,
267,
327,
2670,
340,
314,
570,
63,
354,
3181,
1133,
2187,
267,
340,
570,
63,
354,
365,
488,
26,
288,
2512,
14,
3764,
480,
8254,
3504,
282,
1686,
570,
536,
531,
288,
372,
398,
327,
2670,
642,
5712,
1133,
13369,
282,
4596,
2199,
570,
267,
340,
334,
13249,
63,
475,
63,
2117,
365,
488,
436,
19695,
63,
475,
63,
2117,
365,
488,
436,
8386,
63,
475,
63,
2117,
365,
488,
9,
436,
2199,
63,
29920,
26,
288,
2512,
14,
3764,
480,
6049,
440,
3354,
376,
2701,
2199,
531,
288,
372,
398,
2082,
275,
747,
14,
515,
14,
3475,
8,
493,
63,
354,
9,
267,
327,
11063,
1736,
10749,
370,
626,
2909,
267,
340,
2199,
63,
29920,
26,
288,
14466,
63,
21166,
275,
9361,
2638,
20829,
8,
3619,
29,
3619,
9,
288,
14466,
63,
21166,
14,
2117,
63,
800,
10749,
8,
800,
10749,
63,
475,
63,
2117,
29,
13249,
63,
475,
63,
2117,
9,
288,
6290,
63,
800,
10749,
275,
14466,
63,
21166,
14,
362,
63,
1199,
63,
513,
342,
267,
587,
26,
288,
327,
16269,
626,
642,
365,
2199,
24201,
880,
986,
282,
769,
402,
14466,
1561,
288,
6290,
63,
800,
10749,
275,
437,
3177,
14,
362,
1692,
5866,
342,
398,
327,
7958,
19695,
267,
19695,
63,
475,
63,
2117,
63,
513,
275,
510,
4555,
20829,
1252,
2117,
63,
13701,
8,
13701,
63,
475,
63,
2117,
9,
398,
327,
11063,
8386,
267,
340,
8386,
63,
475,
63,
2117,
365,
488,
26,
288,
8386,
63,
475,
63,
2117,
275,
942,
398,
8386,
275,
291,
423,
1107,
63,
7436,
63,
7892,
8,
3619,
29,
3619,
12,
8386,
63,
475,
63,
2117,
29,
7436,
63,
475,
63,
2117,
9,
398,
327,
8325,
10809,
370,
7290,
24441,
267,
7060,
275,
7290,
6261,
8,
13249,
63,
1247,
29,
8420,
63,
800,
10749,
12,
3044,
19695,
63,
475,
63,
2117,
29,
13701,
63,
475,
63,
2117,
63,
513,
12,
3044,
8386,
63,
475,
63,
2117,
29,
7436,
12,
3044,
3354,
63,
1985,
29,
493,
63,
354,
12,
3044,
2199,
63,
493,
63,
832,
29,
277,
14,
1715,
63,
493,
63,
832,
9,
267,
7060,
14,
952,
63,
548,
342,
339,
768,
4639,
272,
347,
485,
1107,
63,
7436,
63,
7892,
8,
3619,
12,
8386,
63,
475,
63,
2117,
304,
267,
8386,
275,
942,
267,
367,
3217,
12,
10295,
315,
8386,
63,
475,
63,
2117,
26,
288,
327,
2654,
370,
314,
2600,
5737,
666,
543,
314,
790,
465,
314,
1642,
1947,
315,
314,
769,
641,
314,
10295,
3004,
288,
862,
26,
355,
1947,
275,
10295,
14,
2969,
59,
16,
61,
355,
5737,
63,
807,
275,
10295,
14,
2143,
8,
3266,
12,
2082,
9,
355,
5737,
63,
807,
905,
1450,
937,
275,
1947,
355,
8386,
14,
740,
8,
8167,
63,
807,
9,
288,
871,
2186,
465,
325,
26,
355,
327,
32754,
1263,
1919,
436,
943,
652,
355,
340,
1228,
8,
69,
12,
13483,
304,
490,
746,
355,
2512,
14,
3764,
480,
4761,
428,
28396,
26,
1626,
3217,
4293,
440,
506,
17559,
1125,
26,
298,
435,
620,
8,
69,
430,
398,
372,
8386,
421,
199,
533,
7290,
6261,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
3354,
63,
1985,
12,
14466,
63,
1247,
12,
2199,
63,
493,
63,
832,
12,
19695,
63,
475,
63,
2117,
12,
8386,
63,
475,
63,
2117,
304,
267,
291,
14,
13249,
63,
1247,
275,
14466,
63,
1247,
267,
291,
14,
493,
63,
354,
275,
3354,
63,
1985,
267,
291,
14,
1715,
63,
493,
63,
832,
275,
2199,
63,
493,
63,
832,
267,
291,
14,
13701,
63,
475,
63,
2117,
275,
19695,
63,
475,
63,
2117,
267,
291,
14,
7436,
63,
475,
63,
2117,
275,
8386,
63,
475,
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,
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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
] |
jamesylgan/szechuantech
|
python-scripts/pycparser/_ast_gen.py
|
22
|
8675
|
#-----------------------------------------------------------------
# _ast_gen.py
#
# Generates the AST Node classes from a specification given in
# a configuration file
#
# The design of this module was inspired by astgen.py from the
# Python 2.5 code-base.
#
# Eli Bendersky [http://eli.thegreenplace.net]
# License: BSD
#-----------------------------------------------------------------
import pprint
from string import Template
class ASTCodeGenerator(object):
def __init__(self, cfg_filename='_c_ast.cfg'):
""" Initialize the code generator from a configuration
file.
"""
self.cfg_filename = cfg_filename
self.node_cfg = [NodeCfg(name, contents)
for (name, contents) in self.parse_cfgfile(cfg_filename)]
def generate(self, file=None):
""" Generates the code into file, an open file buffer.
"""
src = Template(_PROLOGUE_COMMENT).substitute(
cfg_filename=self.cfg_filename)
src += _PROLOGUE_CODE
for node_cfg in self.node_cfg:
src += node_cfg.generate_source() + '\n\n'
file.write(src)
def parse_cfgfile(self, filename):
""" Parse the configuration file and yield pairs of
(name, contents) for each node.
"""
with open(filename, "r") as f:
for line in f:
line = line.strip()
if not line or line.startswith('#'):
continue
colon_i = line.find(':')
lbracket_i = line.find('[')
rbracket_i = line.find(']')
if colon_i < 1 or lbracket_i <= colon_i or rbracket_i <= lbracket_i:
raise RuntimeError("Invalid line in %s:\n%s\n" % (filename, line))
name = line[:colon_i]
val = line[lbracket_i + 1:rbracket_i]
vallist = [v.strip() for v in val.split(',')] if val else []
yield name, vallist
class NodeCfg(object):
""" Node configuration.
name: node name
contents: a list of contents - attributes and child nodes
See comment at the top of the configuration file for details.
"""
def __init__(self, name, contents):
self.name = name
self.all_entries = []
self.attr = []
self.child = []
self.seq_child = []
for entry in contents:
clean_entry = entry.rstrip('*')
self.all_entries.append(clean_entry)
if entry.endswith('**'):
self.seq_child.append(clean_entry)
elif entry.endswith('*'):
self.child.append(clean_entry)
else:
self.attr.append(entry)
def generate_source(self):
src = self._gen_init()
src += '\n' + self._gen_children()
src += '\n' + self._gen_attr_names()
return src
def _gen_init(self):
src = "class %s(Node):\n" % self.name
if self.all_entries:
args = ', '.join(self.all_entries)
slots = ', '.join("'{0}'".format(e) for e in self.all_entries)
slots += ", 'coord', '__weakref__'"
arglist = '(self, %s, coord=None)' % args
else:
slots = "'coord', '__weakref__'"
arglist = '(self, coord=None)'
src += " __slots__ = (%s)\n" % slots
src += " def __init__%s:\n" % arglist
for name in self.all_entries + ['coord']:
src += " self.%s = %s\n" % (name, name)
return src
def _gen_children(self):
src = ' def children(self):\n'
if self.all_entries:
src += ' nodelist = []\n'
for child in self.child:
src += (
' if self.%(child)s is not None:' +
' nodelist.append(("%(child)s", self.%(child)s))\n') % (
dict(child=child))
for seq_child in self.seq_child:
src += (
' for i, child in enumerate(self.%(child)s or []):\n'
' nodelist.append(("%(child)s[%%d]" %% i, child))\n') % (
dict(child=seq_child))
src += ' return tuple(nodelist)\n'
else:
src += ' return ()\n'
return src
def _gen_attr_names(self):
src = " attr_names = (" + ''.join("%r, " % nm for nm in self.attr) + ')'
return src
_PROLOGUE_COMMENT = \
r'''#-----------------------------------------------------------------
# ** ATTENTION **
# This code was automatically generated from the file:
# $cfg_filename
#
# Do not modify it directly. Modify the configuration file and
# run the generator again.
# ** ** *** ** **
#
# pycparser: c_ast.py
#
# AST Node classes.
#
# Eli Bendersky [http://eli.thegreenplace.net]
# License: BSD
#-----------------------------------------------------------------
'''
_PROLOGUE_CODE = r'''
import sys
class Node(object):
__slots__ = ()
""" Abstract base class for AST nodes.
"""
def children(self):
""" A sequence of all children that are Nodes
"""
pass
def show(self, buf=sys.stdout, offset=0, attrnames=False, nodenames=False, showcoord=False, _my_node_name=None):
""" Pretty print the Node and all its attributes and
children (recursively) to a buffer.
buf:
Open IO buffer into which the Node is printed.
offset:
Initial offset (amount of leading spaces)
attrnames:
True if you want to see the attribute names in
name=value pairs. False to only see the values.
nodenames:
True if you want to see the actual node names
within their parents.
showcoord:
Do you want the coordinates of each Node to be
displayed.
"""
lead = ' ' * offset
if nodenames and _my_node_name is not None:
buf.write(lead + self.__class__.__name__+ ' <' + _my_node_name + '>: ')
else:
buf.write(lead + self.__class__.__name__+ ': ')
if self.attr_names:
if attrnames:
nvlist = [(n, getattr(self,n)) for n in self.attr_names]
attrstr = ', '.join('%s=%s' % nv for nv in nvlist)
else:
vlist = [getattr(self, n) for n in self.attr_names]
attrstr = ', '.join('%s' % v for v in vlist)
buf.write(attrstr)
if showcoord:
buf.write(' (at %s)' % self.coord)
buf.write('\n')
for (child_name, child) in self.children():
child.show(
buf,
offset=offset + 2,
attrnames=attrnames,
nodenames=nodenames,
showcoord=showcoord,
_my_node_name=child_name)
class NodeVisitor(object):
""" A base NodeVisitor class for visiting c_ast nodes.
Subclass it and define your own visit_XXX methods, where
XXX is the class name you want to visit with these
methods.
For example:
class ConstantVisitor(NodeVisitor):
def __init__(self):
self.values = []
def visit_Constant(self, node):
self.values.append(node.value)
Creates a list of values of all the constant nodes
encountered below the given node. To use it:
cv = ConstantVisitor()
cv.visit(node)
Notes:
* generic_visit() will be called for AST nodes for which
no visit_XXX method was defined.
* The children of nodes for which a visit_XXX was
defined will not be visited - if you need this, call
generic_visit() on the node.
You can use:
NodeVisitor.generic_visit(self, node)
* Modeled after Python's own AST visiting facilities
(the ast module of Python 3.0)
"""
def visit(self, node):
""" Visit a node.
"""
method = 'visit_' + node.__class__.__name__
visitor = getattr(self, method, self.generic_visit)
return visitor(node)
def generic_visit(self, node):
""" Called if no explicit visitor function exists for a
node. Implements preorder visiting of the node.
"""
for c_name, c in node.children():
self.visit(c)
'''
if __name__ == "__main__":
import sys
ast_gen = ASTCodeGenerator('_c_ast.cfg')
ast_gen.generate(open('c_ast.py', 'w'))
|
mit
|
[
7656,
13,
199,
3,
485,
1810,
63,
2268,
14,
647,
199,
3,
199,
3,
21687,
314,
20788,
5013,
3992,
687,
282,
8929,
1627,
315,
199,
3,
282,
2897,
570,
199,
3,
199,
3,
710,
12899,
402,
642,
859,
1990,
315,
8721,
581,
701,
6073,
2268,
14,
647,
687,
314,
199,
3,
2018,
499,
14,
21,
1233,
13,
1095,
14,
199,
3,
199,
3,
662,
317,
699,
13747,
12267,
359,
1014,
921,
18865,
14,
1589,
7731,
2778,
14,
846,
61,
199,
3,
844,
26,
6289,
199,
7656,
13,
199,
646,
10933,
199,
504,
1059,
492,
5458,
421,
199,
533,
20788,
3034,
7599,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
4810,
63,
1501,
17574,
67,
63,
1810,
14,
4128,
735,
267,
408,
11578,
314,
1233,
4306,
687,
282,
2897,
288,
570,
14,
267,
408,
267,
291,
14,
4128,
63,
1501,
275,
4810,
63,
1501,
267,
291,
14,
932,
63,
4128,
275,
359,
1716,
22457,
8,
354,
12,
4072,
9,
288,
367,
334,
354,
12,
4072,
9,
315,
291,
14,
1122,
63,
4128,
493,
8,
4128,
63,
1501,
1874,
339,
347,
3550,
8,
277,
12,
570,
29,
403,
304,
267,
408,
21687,
314,
1233,
1901,
570,
12,
376,
1551,
570,
3335,
14,
267,
408,
267,
2928,
275,
5458,
1547,
2514,
4947,
4187,
63,
10973,
680,
20374,
8,
288,
4810,
63,
1501,
29,
277,
14,
4128,
63,
1501,
9,
398,
2928,
847,
485,
2514,
4947,
4187,
63,
6012,
267,
367,
1031,
63,
4128,
315,
291,
14,
932,
63,
4128,
26,
288,
2928,
847,
1031,
63,
4128,
14,
4208,
63,
1365,
342,
435,
1557,
78,
60,
78,
7,
398,
570,
14,
952,
8,
2164,
9,
339,
347,
2198,
63,
4128,
493,
8,
277,
12,
1788,
304,
267,
408,
6077,
314,
2897,
570,
436,
1995,
6342,
402,
288,
334,
354,
12,
4072,
9,
367,
1924,
1031,
14,
267,
408,
267,
543,
1551,
8,
1501,
12,
298,
82,
531,
465,
289,
26,
288,
367,
1004,
315,
289,
26,
355,
1004,
275,
1004,
14,
1913,
342,
355,
340,
440,
1004,
503,
1004,
14,
2460,
7863,
735,
490,
1980,
355,
18307,
63,
73,
275,
1004,
14,
1623,
11633,
355,
634,
14594,
63,
73,
275,
1004,
14,
1623,
11894,
358,
355,
519,
14594,
63,
73,
275,
1004,
14,
1623,
360,
10374,
355,
340,
18307,
63,
73,
665,
413,
503,
634,
14594,
63,
73,
2695,
18307,
63,
73,
503,
519,
14594,
63,
73,
2695,
634,
14594,
63,
73,
26,
490,
746,
6064,
480,
3364,
1004,
315,
450,
83,
3427,
78,
5,
83,
60,
78,
2,
450,
334,
1501,
12,
1004,
430,
2234,
536,
275,
1004,
1491,
12167,
63,
73,
61,
355,
1139,
275,
1004,
59,
6374,
345,
2284,
63,
73,
435,
413,
26,
4848,
345,
2284,
63,
73,
61,
355,
1139,
513,
275,
359,
86,
14,
1913,
342,
367,
373,
315,
1139,
14,
1294,
29972,
340,
1139,
587,
942,
355,
1995,
536,
12,
1139,
513,
421,
199,
533,
5013,
22457,
8,
785,
304,
272,
408,
5013,
2897,
14,
398,
536,
26,
1031,
536,
267,
4072,
26,
282,
769,
402,
4072,
446,
3004,
436,
1982,
3380,
267,
1666,
3721,
737,
314,
2746,
402,
314,
2897,
570,
367,
2436,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
536,
12,
4072,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
452,
63,
3189,
275,
942,
267,
291,
14,
962,
275,
942,
267,
291,
14,
1739,
275,
942,
267,
291,
14,
3610,
63,
1739,
275,
942,
398,
367,
2397,
315,
4072,
26,
288,
3633,
63,
2373,
275,
2397,
14,
6735,
360,
13418,
288,
291,
14,
452,
63,
3189,
14,
740,
8,
3118,
63,
2373,
9,
953,
340,
2397,
14,
4130,
31260,
735,
355,
291,
14,
3610,
63,
1739,
14,
740,
8,
3118,
63,
2373,
9,
288,
916,
2397,
14,
4130,
18225,
735,
355,
291,
14,
1739,
14,
740,
8,
3118,
63,
2373,
9,
288,
587,
26,
355,
291,
14,
962,
14,
740,
8,
2373,
9,
339,
347,
3550,
63,
1365,
8,
277,
304,
267,
2928,
275,
291,
423,
2268,
63,
826,
342,
267,
2928,
847,
1557,
78,
7,
435,
291,
423,
2268,
63,
3223,
342,
267,
2928,
847,
1557,
78,
7,
435,
291,
423,
2268,
63,
962,
63,
1247,
342,
267,
372,
2928,
339,
347,
485,
2268,
63,
826,
8,
277,
304,
267,
2928,
275,
298,
533,
450,
83,
8,
1716,
17211,
78,
2,
450,
291,
14,
354,
398,
340,
291,
14,
452,
63,
3189,
26,
288,
1249,
275,
1656,
1987,
904,
8,
277,
14,
452,
63,
3189,
9,
288,
14319,
275,
1656,
1987,
904,
15587,
91,
16,
30366,
908,
8,
69,
9,
367,
325,
315,
291,
14,
452,
63,
3189,
9,
288,
14319,
847,
3872,
283,
7988,
297,
2560,
21330,
363,
4065,
288,
24660,
275,
8189,
277,
12,
450,
83,
12,
11021,
29,
403,
3171,
450,
1249,
267,
587,
26,
288,
14319,
275,
3546,
7988,
297,
2560,
21330,
363,
4065,
288,
24660,
275,
8189,
277,
12,
11021,
29,
403,
3171,
398,
2928,
847,
298,
259,
636,
7257,
363,
275,
4366,
83,
2862,
78,
2,
450,
14319,
267,
2928,
847,
298,
259,
347,
636,
826,
363,
5,
83,
3427,
78,
2,
450,
24660,
398,
367,
536,
315,
291,
14,
452,
63,
3189,
435,
788,
7988,
2565,
288,
2928,
847,
298,
263,
291,
4111,
83,
275,
450,
83,
60,
78,
2,
450,
334,
354,
12,
536,
9,
398,
372,
2928,
339,
347,
485,
2268,
63,
3223,
8,
277,
304,
267,
2928,
275,
283,
259,
347,
4978,
8,
277,
17211,
78,
7,
398,
340,
291,
14,
452,
63,
3189,
26,
288,
2928,
847,
283,
263,
13642,
275,
942,
60,
78,
7,
953,
367,
1982,
315,
291,
14,
1739,
26,
355,
2928,
847,
334,
490,
283,
263,
340,
291,
31706,
1739,
9,
83,
365,
440,
488,
4881,
435,
490,
283,
13642,
14,
740,
9313,
2840,
1739,
9,
83,
401,
291,
31706,
1739,
9,
83,
25105,
78,
358,
450,
334,
717,
1211,
8,
1739,
29,
1739,
430,
953,
367,
5412,
63,
1739,
315,
291,
14,
3610,
63,
1739,
26,
355,
2928,
847,
334,
490,
283,
263,
367,
284,
12,
1982,
315,
3874,
8,
277,
31706,
1739,
9,
83,
503,
12319,
60,
78,
7,
490,
283,
3322,
13642,
14,
740,
9313,
2840,
1739,
9,
83,
59,
8530,
68
] |
[
13,
199,
3,
485,
1810,
63,
2268,
14,
647,
199,
3,
199,
3,
21687,
314,
20788,
5013,
3992,
687,
282,
8929,
1627,
315,
199,
3,
282,
2897,
570,
199,
3,
199,
3,
710,
12899,
402,
642,
859,
1990,
315,
8721,
581,
701,
6073,
2268,
14,
647,
687,
314,
199,
3,
2018,
499,
14,
21,
1233,
13,
1095,
14,
199,
3,
199,
3,
662,
317,
699,
13747,
12267,
359,
1014,
921,
18865,
14,
1589,
7731,
2778,
14,
846,
61,
199,
3,
844,
26,
6289,
199,
7656,
13,
199,
646,
10933,
199,
504,
1059,
492,
5458,
421,
199,
533,
20788,
3034,
7599,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
4810,
63,
1501,
17574,
67,
63,
1810,
14,
4128,
735,
267,
408,
11578,
314,
1233,
4306,
687,
282,
2897,
288,
570,
14,
267,
408,
267,
291,
14,
4128,
63,
1501,
275,
4810,
63,
1501,
267,
291,
14,
932,
63,
4128,
275,
359,
1716,
22457,
8,
354,
12,
4072,
9,
288,
367,
334,
354,
12,
4072,
9,
315,
291,
14,
1122,
63,
4128,
493,
8,
4128,
63,
1501,
1874,
339,
347,
3550,
8,
277,
12,
570,
29,
403,
304,
267,
408,
21687,
314,
1233,
1901,
570,
12,
376,
1551,
570,
3335,
14,
267,
408,
267,
2928,
275,
5458,
1547,
2514,
4947,
4187,
63,
10973,
680,
20374,
8,
288,
4810,
63,
1501,
29,
277,
14,
4128,
63,
1501,
9,
398,
2928,
847,
485,
2514,
4947,
4187,
63,
6012,
267,
367,
1031,
63,
4128,
315,
291,
14,
932,
63,
4128,
26,
288,
2928,
847,
1031,
63,
4128,
14,
4208,
63,
1365,
342,
435,
1557,
78,
60,
78,
7,
398,
570,
14,
952,
8,
2164,
9,
339,
347,
2198,
63,
4128,
493,
8,
277,
12,
1788,
304,
267,
408,
6077,
314,
2897,
570,
436,
1995,
6342,
402,
288,
334,
354,
12,
4072,
9,
367,
1924,
1031,
14,
267,
408,
267,
543,
1551,
8,
1501,
12,
298,
82,
531,
465,
289,
26,
288,
367,
1004,
315,
289,
26,
355,
1004,
275,
1004,
14,
1913,
342,
355,
340,
440,
1004,
503,
1004,
14,
2460,
7863,
735,
490,
1980,
355,
18307,
63,
73,
275,
1004,
14,
1623,
11633,
355,
634,
14594,
63,
73,
275,
1004,
14,
1623,
11894,
358,
355,
519,
14594,
63,
73,
275,
1004,
14,
1623,
360,
10374,
355,
340,
18307,
63,
73,
665,
413,
503,
634,
14594,
63,
73,
2695,
18307,
63,
73,
503,
519,
14594,
63,
73,
2695,
634,
14594,
63,
73,
26,
490,
746,
6064,
480,
3364,
1004,
315,
450,
83,
3427,
78,
5,
83,
60,
78,
2,
450,
334,
1501,
12,
1004,
430,
2234,
536,
275,
1004,
1491,
12167,
63,
73,
61,
355,
1139,
275,
1004,
59,
6374,
345,
2284,
63,
73,
435,
413,
26,
4848,
345,
2284,
63,
73,
61,
355,
1139,
513,
275,
359,
86,
14,
1913,
342,
367,
373,
315,
1139,
14,
1294,
29972,
340,
1139,
587,
942,
355,
1995,
536,
12,
1139,
513,
421,
199,
533,
5013,
22457,
8,
785,
304,
272,
408,
5013,
2897,
14,
398,
536,
26,
1031,
536,
267,
4072,
26,
282,
769,
402,
4072,
446,
3004,
436,
1982,
3380,
267,
1666,
3721,
737,
314,
2746,
402,
314,
2897,
570,
367,
2436,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
536,
12,
4072,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
452,
63,
3189,
275,
942,
267,
291,
14,
962,
275,
942,
267,
291,
14,
1739,
275,
942,
267,
291,
14,
3610,
63,
1739,
275,
942,
398,
367,
2397,
315,
4072,
26,
288,
3633,
63,
2373,
275,
2397,
14,
6735,
360,
13418,
288,
291,
14,
452,
63,
3189,
14,
740,
8,
3118,
63,
2373,
9,
953,
340,
2397,
14,
4130,
31260,
735,
355,
291,
14,
3610,
63,
1739,
14,
740,
8,
3118,
63,
2373,
9,
288,
916,
2397,
14,
4130,
18225,
735,
355,
291,
14,
1739,
14,
740,
8,
3118,
63,
2373,
9,
288,
587,
26,
355,
291,
14,
962,
14,
740,
8,
2373,
9,
339,
347,
3550,
63,
1365,
8,
277,
304,
267,
2928,
275,
291,
423,
2268,
63,
826,
342,
267,
2928,
847,
1557,
78,
7,
435,
291,
423,
2268,
63,
3223,
342,
267,
2928,
847,
1557,
78,
7,
435,
291,
423,
2268,
63,
962,
63,
1247,
342,
267,
372,
2928,
339,
347,
485,
2268,
63,
826,
8,
277,
304,
267,
2928,
275,
298,
533,
450,
83,
8,
1716,
17211,
78,
2,
450,
291,
14,
354,
398,
340,
291,
14,
452,
63,
3189,
26,
288,
1249,
275,
1656,
1987,
904,
8,
277,
14,
452,
63,
3189,
9,
288,
14319,
275,
1656,
1987,
904,
15587,
91,
16,
30366,
908,
8,
69,
9,
367,
325,
315,
291,
14,
452,
63,
3189,
9,
288,
14319,
847,
3872,
283,
7988,
297,
2560,
21330,
363,
4065,
288,
24660,
275,
8189,
277,
12,
450,
83,
12,
11021,
29,
403,
3171,
450,
1249,
267,
587,
26,
288,
14319,
275,
3546,
7988,
297,
2560,
21330,
363,
4065,
288,
24660,
275,
8189,
277,
12,
11021,
29,
403,
3171,
398,
2928,
847,
298,
259,
636,
7257,
363,
275,
4366,
83,
2862,
78,
2,
450,
14319,
267,
2928,
847,
298,
259,
347,
636,
826,
363,
5,
83,
3427,
78,
2,
450,
24660,
398,
367,
536,
315,
291,
14,
452,
63,
3189,
435,
788,
7988,
2565,
288,
2928,
847,
298,
263,
291,
4111,
83,
275,
450,
83,
60,
78,
2,
450,
334,
354,
12,
536,
9,
398,
372,
2928,
339,
347,
485,
2268,
63,
3223,
8,
277,
304,
267,
2928,
275,
283,
259,
347,
4978,
8,
277,
17211,
78,
7,
398,
340,
291,
14,
452,
63,
3189,
26,
288,
2928,
847,
283,
263,
13642,
275,
942,
60,
78,
7,
953,
367,
1982,
315,
291,
14,
1739,
26,
355,
2928,
847,
334,
490,
283,
263,
340,
291,
31706,
1739,
9,
83,
365,
440,
488,
4881,
435,
490,
283,
13642,
14,
740,
9313,
2840,
1739,
9,
83,
401,
291,
31706,
1739,
9,
83,
25105,
78,
358,
450,
334,
717,
1211,
8,
1739,
29,
1739,
430,
953,
367,
5412,
63,
1739,
315,
291,
14,
3610,
63,
1739,
26,
355,
2928,
847,
334,
490,
283,
263,
367,
284,
12,
1982,
315,
3874,
8,
277,
31706,
1739,
9,
83,
503,
12319,
60,
78,
7,
490,
283,
3322,
13642,
14,
740,
9313,
2840,
1739,
9,
83,
59,
8530,
68,
0
] |
[
1,
1,
1,
1,
1,
1,
1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org.wso2.ppaas.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/thrift/transport/TTwisted.py
|
19
|
6528
|
#
# 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 cStringIO import StringIO
from zope.interface import implements, Interface, Attribute
from twisted.internet.protocol import Protocol, ServerFactory, ClientFactory, \
connectionDone
from twisted.internet import defer
from twisted.protocols import basic
from twisted.python import log
from twisted.web import server, resource, http
import TTransport
class TMessageSenderTransport(TTransport.TTransportBase):
def __init__(self):
self.__wbuf = StringIO()
def write(self, buf):
self.__wbuf.write(buf)
def flush(self):
msg = self.__wbuf.getvalue()
self.__wbuf = StringIO()
self.sendMessage(msg)
def sendMessage(self, message):
raise NotImplementedError
class TCallbackTransport(TMessageSenderTransport):
def __init__(self, func):
TMessageSenderTransport.__init__(self)
self.func = func
def sendMessage(self, message):
self.func(message)
class ThriftClientProtocol(basic.Int32StringReceiver):
MAX_LENGTH = 2 ** 31 - 1
def __init__(self, client_class, iprot_factory, oprot_factory=None):
self._client_class = client_class
self._iprot_factory = iprot_factory
if oprot_factory is None:
self._oprot_factory = iprot_factory
else:
self._oprot_factory = oprot_factory
self.recv_map = {}
self.started = defer.Deferred()
def dispatch(self, msg):
self.sendString(msg)
def connectionMade(self):
tmo = TCallbackTransport(self.dispatch)
self.client = self._client_class(tmo, self._oprot_factory)
self.started.callback(self.client)
def connectionLost(self, reason=connectionDone):
for k, v in self.client._reqs.iteritems():
tex = TTransport.TTransportException(
type=TTransport.TTransportException.END_OF_FILE,
message='Connection closed')
v.errback(tex)
def stringReceived(self, frame):
tr = TTransport.TMemoryBuffer(frame)
iprot = self._iprot_factory.getProtocol(tr)
(fname, mtype, rseqid) = iprot.readMessageBegin()
try:
method = self.recv_map[fname]
except KeyError:
method = getattr(self.client, 'recv_' + fname)
self.recv_map[fname] = method
method(iprot, mtype, rseqid)
class ThriftServerProtocol(basic.Int32StringReceiver):
MAX_LENGTH = 2 ** 31 - 1
def dispatch(self, msg):
self.sendString(msg)
def processError(self, error):
self.transport.loseConnection()
def processOk(self, _, tmo):
msg = tmo.getvalue()
if len(msg) > 0:
self.dispatch(msg)
def stringReceived(self, frame):
tmi = TTransport.TMemoryBuffer(frame)
tmo = TTransport.TMemoryBuffer()
iprot = self.factory.iprot_factory.getProtocol(tmi)
oprot = self.factory.oprot_factory.getProtocol(tmo)
d = self.factory.processor.process(iprot, oprot)
d.addCallbacks(self.processOk, self.processError,
callbackArgs=(tmo,))
class IThriftServerFactory(Interface):
processor = Attribute("Thrift processor")
iprot_factory = Attribute("Input protocol factory")
oprot_factory = Attribute("Output protocol factory")
class IThriftClientFactory(Interface):
client_class = Attribute("Thrift client class")
iprot_factory = Attribute("Input protocol factory")
oprot_factory = Attribute("Output protocol factory")
class ThriftServerFactory(ServerFactory):
implements(IThriftServerFactory)
protocol = ThriftServerProtocol
def __init__(self, processor, iprot_factory, oprot_factory=None):
self.processor = processor
self.iprot_factory = iprot_factory
if oprot_factory is None:
self.oprot_factory = iprot_factory
else:
self.oprot_factory = oprot_factory
class ThriftClientFactory(ClientFactory):
implements(IThriftClientFactory)
protocol = ThriftClientProtocol
def __init__(self, client_class, iprot_factory, oprot_factory=None):
self.client_class = client_class
self.iprot_factory = iprot_factory
if oprot_factory is None:
self.oprot_factory = iprot_factory
else:
self.oprot_factory = oprot_factory
def buildProtocol(self, addr):
p = self.protocol(self.client_class, self.iprot_factory,
self.oprot_factory)
p.factory = self
return p
class ThriftResource(resource.Resource):
allowedMethods = ('POST',)
def __init__(self, processor, inputProtocolFactory,
outputProtocolFactory=None):
resource.Resource.__init__(self)
self.inputProtocolFactory = inputProtocolFactory
if outputProtocolFactory is None:
self.outputProtocolFactory = inputProtocolFactory
else:
self.outputProtocolFactory = outputProtocolFactory
self.processor = processor
def getChild(self, path, request):
return self
def _cbProcess(self, _, request, tmo):
msg = tmo.getvalue()
request.setResponseCode(http.OK)
request.setHeader("content-type", "application/x-thrift")
request.write(msg)
request.finish()
def render_POST(self, request):
request.content.seek(0, 0)
data = request.content.read()
tmi = TTransport.TMemoryBuffer(data)
tmo = TTransport.TMemoryBuffer()
iprot = self.inputProtocolFactory.getProtocol(tmi)
oprot = self.outputProtocolFactory.getProtocol(tmo)
d = self.processor.process(iprot, oprot)
d.addCallback(self._cbProcess, request, tmo)
return server.NOT_DONE_YET
|
apache-2.0
|
[
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
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,
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,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
199,
199,
504,
15073,
492,
5228,
199,
199,
504,
20110,
14,
3266,
492,
9031,
12,
14816,
12,
3882,
199,
504,
7390,
14,
4901,
14,
3922,
492,
11557,
12,
7146,
2927,
12,
6810,
2927,
12,
971,
272,
1950,
10759,
199,
504,
7390,
14,
4901,
492,
10133,
199,
504,
7390,
14,
16541,
492,
5678,
199,
504,
7390,
14,
1548,
492,
943,
199,
504,
7390,
14,
2520,
492,
1654,
12,
2073,
12,
1455,
199,
199,
646,
19391,
421,
199,
533,
377,
2209,
28002,
7836,
8,
1481,
4808,
14,
1481,
4808,
1563,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
855,
87,
1436,
275,
5228,
342,
339,
347,
2218,
8,
277,
12,
4123,
304,
267,
291,
855,
87,
1436,
14,
952,
8,
1436,
9,
339,
347,
8976,
8,
277,
304,
267,
1499,
275,
291,
855,
87,
1436,
14,
7150,
342,
267,
291,
855,
87,
1436,
275,
5228,
342,
267,
291,
14,
2254,
2209,
8,
1328,
9,
339,
347,
3222,
2209,
8,
277,
12,
1245,
304,
267,
746,
4279,
421,
199,
533,
377,
2806,
7836,
8,
52,
2209,
28002,
7836,
304,
339,
347,
636,
826,
721,
277,
12,
2562,
304,
267,
377,
2209,
28002,
7836,
855,
826,
721,
277,
9,
267,
291,
14,
1532,
275,
2562,
339,
347,
3222,
2209,
8,
277,
12,
1245,
304,
267,
291,
14,
1532,
8,
1188,
9,
421,
199,
533,
3868,
6501,
3041,
3658,
8,
4316,
14,
3241,
708,
1558,
21800,
304,
339,
9141,
63,
9127,
275,
499,
1011,
7105,
446,
413,
339,
347,
636,
826,
721,
277,
12,
1890,
63,
533,
12,
5052,
63,
3702,
12,
4833,
63,
3702,
29,
403,
304,
267,
291,
423,
1258,
63,
533,
275,
1890,
63,
533,
267,
291,
423,
10141,
63,
3702,
275,
5052,
63,
3702,
267,
340,
4833,
63,
3702,
365,
488,
26,
288,
291,
423,
12603,
63,
3702,
275,
5052,
63,
3702,
267,
587,
26,
288,
291,
423,
12603,
63,
3702,
275,
4833,
63,
3702,
398,
291,
14,
7637,
63,
1130,
275,
1052,
267,
291,
14,
8924,
275,
10133,
14,
9937,
342,
339,
347,
7634,
8,
277,
12,
1499,
304,
267,
291,
14,
2254,
1558,
8,
1328,
9,
339,
347,
1950,
26973,
8,
277,
304,
267,
307,
573,
275,
377,
2806,
7836,
8,
277,
14,
6052,
9,
267,
291,
14,
1258,
275,
291,
423,
1258,
63,
533,
8,
84,
573,
12,
291,
423,
12603,
63,
3702,
9,
267,
291,
14,
8924,
14,
3058,
8,
277,
14,
1258,
9,
339,
347,
1950,
14074,
8,
277,
12,
4499,
29,
2105,
10759,
304,
267,
367,
1022,
12,
373,
315,
291,
14,
1258,
423,
12720,
14,
4611,
837,
288,
14709,
275,
19391,
14,
1481,
4808,
1726,
8,
355,
730,
29,
1481,
4808,
14,
1481,
4808,
1726,
14,
3902,
63,
3359,
63,
3817,
12,
355,
1245,
534,
3225,
6876,
358,
288,
373,
14,
28940,
8,
3858,
9,
339,
347,
1059,
9392,
8,
277,
12,
2787,
304,
267,
5651,
275,
19391,
14,
52,
8628,
3299,
8,
1943,
9,
267,
5052,
275,
291,
423,
10141,
63,
3702,
14,
362,
3658,
8,
454,
9,
267,
334,
5252,
12,
21021,
12,
519,
26693,
9,
275,
5052,
14,
739,
22039,
342,
398,
862,
26,
288,
1083,
275,
291,
14,
7637,
63,
1130,
59,
5252,
61,
267,
871,
4067,
26,
288,
1083,
275,
2519,
8,
277,
14,
1258,
12,
283,
7637,
8650,
435,
6748,
9,
288,
291,
14,
7637,
63,
1130,
59,
5252,
61,
275,
1083,
398,
1083,
8,
10141,
12,
21021,
12,
519,
26693,
9,
421,
199,
533,
3868,
6501,
3120,
3658,
8,
4316,
14,
3241,
708,
1558,
21800,
304,
339,
9141,
63,
9127,
275,
499,
1011,
7105,
446,
413,
339,
347,
7634,
8,
277,
12,
1499,
304,
267,
291,
14,
2254,
1558,
8,
1328,
9,
339,
347,
2112,
547,
8,
277,
12,
1125,
304,
267,
291,
14,
5545,
14,
32452,
342,
339,
347,
2112,
11622,
8,
277,
12,
5501,
307,
573,
304,
267,
1499,
275,
307,
573,
14,
7150,
342,
398,
340,
822,
8,
1328,
9,
690,
378,
26,
288,
291,
14,
6052,
8,
1328,
9,
339,
347,
1059,
9392,
8,
277,
12,
2787,
304,
267,
307,
2664,
275,
19391,
14,
52,
8628,
3299,
8,
1943,
9,
267,
307,
573,
275,
19391,
14,
52,
8628,
3299,
342,
398,
5052,
275,
291,
14,
3702,
14,
10141,
63,
3702,
14,
362,
3658,
8,
84,
2664,
9,
267,
4833,
275,
291,
14,
3702,
14,
12603,
63,
3702,
14,
362,
3658,
8,
84,
573,
9,
398,
366,
275,
291,
14,
3702,
14,
6459,
14,
1412,
8,
10141,
12,
4833,
9,
267,
366,
14,
10053,
83,
8,
277,
14,
1412,
11622,
12,
291,
14,
1412,
547,
12,
288,
3233,
6213,
2687,
84,
573,
4641,
421,
199,
533,
473,
2719,
6501,
3120,
2927,
8,
4267,
304,
339,
12495,
275,
3882,
480,
2719,
6501,
12495,
531,
339,
5052,
63,
3702,
275,
3882,
480,
3205,
4113,
6434,
531,
339,
4833,
63,
3702,
275,
3882,
480,
2959,
4113,
6434,
531,
421,
199,
533,
473,
2719,
6501,
30115,
8,
4267,
304,
339,
1890,
63,
533,
275,
3882,
480,
2719,
6501,
1890,
1021,
531,
339,
5052,
63,
3702,
275,
3882,
480,
3205,
4113,
6434,
531,
339,
4833,
63,
3702,
275,
3882,
480,
2959
] |
[
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
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,
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,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
199,
199,
504,
15073,
492,
5228,
199,
199,
504,
20110,
14,
3266,
492,
9031,
12,
14816,
12,
3882,
199,
504,
7390,
14,
4901,
14,
3922,
492,
11557,
12,
7146,
2927,
12,
6810,
2927,
12,
971,
272,
1950,
10759,
199,
504,
7390,
14,
4901,
492,
10133,
199,
504,
7390,
14,
16541,
492,
5678,
199,
504,
7390,
14,
1548,
492,
943,
199,
504,
7390,
14,
2520,
492,
1654,
12,
2073,
12,
1455,
199,
199,
646,
19391,
421,
199,
533,
377,
2209,
28002,
7836,
8,
1481,
4808,
14,
1481,
4808,
1563,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
855,
87,
1436,
275,
5228,
342,
339,
347,
2218,
8,
277,
12,
4123,
304,
267,
291,
855,
87,
1436,
14,
952,
8,
1436,
9,
339,
347,
8976,
8,
277,
304,
267,
1499,
275,
291,
855,
87,
1436,
14,
7150,
342,
267,
291,
855,
87,
1436,
275,
5228,
342,
267,
291,
14,
2254,
2209,
8,
1328,
9,
339,
347,
3222,
2209,
8,
277,
12,
1245,
304,
267,
746,
4279,
421,
199,
533,
377,
2806,
7836,
8,
52,
2209,
28002,
7836,
304,
339,
347,
636,
826,
721,
277,
12,
2562,
304,
267,
377,
2209,
28002,
7836,
855,
826,
721,
277,
9,
267,
291,
14,
1532,
275,
2562,
339,
347,
3222,
2209,
8,
277,
12,
1245,
304,
267,
291,
14,
1532,
8,
1188,
9,
421,
199,
533,
3868,
6501,
3041,
3658,
8,
4316,
14,
3241,
708,
1558,
21800,
304,
339,
9141,
63,
9127,
275,
499,
1011,
7105,
446,
413,
339,
347,
636,
826,
721,
277,
12,
1890,
63,
533,
12,
5052,
63,
3702,
12,
4833,
63,
3702,
29,
403,
304,
267,
291,
423,
1258,
63,
533,
275,
1890,
63,
533,
267,
291,
423,
10141,
63,
3702,
275,
5052,
63,
3702,
267,
340,
4833,
63,
3702,
365,
488,
26,
288,
291,
423,
12603,
63,
3702,
275,
5052,
63,
3702,
267,
587,
26,
288,
291,
423,
12603,
63,
3702,
275,
4833,
63,
3702,
398,
291,
14,
7637,
63,
1130,
275,
1052,
267,
291,
14,
8924,
275,
10133,
14,
9937,
342,
339,
347,
7634,
8,
277,
12,
1499,
304,
267,
291,
14,
2254,
1558,
8,
1328,
9,
339,
347,
1950,
26973,
8,
277,
304,
267,
307,
573,
275,
377,
2806,
7836,
8,
277,
14,
6052,
9,
267,
291,
14,
1258,
275,
291,
423,
1258,
63,
533,
8,
84,
573,
12,
291,
423,
12603,
63,
3702,
9,
267,
291,
14,
8924,
14,
3058,
8,
277,
14,
1258,
9,
339,
347,
1950,
14074,
8,
277,
12,
4499,
29,
2105,
10759,
304,
267,
367,
1022,
12,
373,
315,
291,
14,
1258,
423,
12720,
14,
4611,
837,
288,
14709,
275,
19391,
14,
1481,
4808,
1726,
8,
355,
730,
29,
1481,
4808,
14,
1481,
4808,
1726,
14,
3902,
63,
3359,
63,
3817,
12,
355,
1245,
534,
3225,
6876,
358,
288,
373,
14,
28940,
8,
3858,
9,
339,
347,
1059,
9392,
8,
277,
12,
2787,
304,
267,
5651,
275,
19391,
14,
52,
8628,
3299,
8,
1943,
9,
267,
5052,
275,
291,
423,
10141,
63,
3702,
14,
362,
3658,
8,
454,
9,
267,
334,
5252,
12,
21021,
12,
519,
26693,
9,
275,
5052,
14,
739,
22039,
342,
398,
862,
26,
288,
1083,
275,
291,
14,
7637,
63,
1130,
59,
5252,
61,
267,
871,
4067,
26,
288,
1083,
275,
2519,
8,
277,
14,
1258,
12,
283,
7637,
8650,
435,
6748,
9,
288,
291,
14,
7637,
63,
1130,
59,
5252,
61,
275,
1083,
398,
1083,
8,
10141,
12,
21021,
12,
519,
26693,
9,
421,
199,
533,
3868,
6501,
3120,
3658,
8,
4316,
14,
3241,
708,
1558,
21800,
304,
339,
9141,
63,
9127,
275,
499,
1011,
7105,
446,
413,
339,
347,
7634,
8,
277,
12,
1499,
304,
267,
291,
14,
2254,
1558,
8,
1328,
9,
339,
347,
2112,
547,
8,
277,
12,
1125,
304,
267,
291,
14,
5545,
14,
32452,
342,
339,
347,
2112,
11622,
8,
277,
12,
5501,
307,
573,
304,
267,
1499,
275,
307,
573,
14,
7150,
342,
398,
340,
822,
8,
1328,
9,
690,
378,
26,
288,
291,
14,
6052,
8,
1328,
9,
339,
347,
1059,
9392,
8,
277,
12,
2787,
304,
267,
307,
2664,
275,
19391,
14,
52,
8628,
3299,
8,
1943,
9,
267,
307,
573,
275,
19391,
14,
52,
8628,
3299,
342,
398,
5052,
275,
291,
14,
3702,
14,
10141,
63,
3702,
14,
362,
3658,
8,
84,
2664,
9,
267,
4833,
275,
291,
14,
3702,
14,
12603,
63,
3702,
14,
362,
3658,
8,
84,
573,
9,
398,
366,
275,
291,
14,
3702,
14,
6459,
14,
1412,
8,
10141,
12,
4833,
9,
267,
366,
14,
10053,
83,
8,
277,
14,
1412,
11622,
12,
291,
14,
1412,
547,
12,
288,
3233,
6213,
2687,
84,
573,
4641,
421,
199,
533,
473,
2719,
6501,
3120,
2927,
8,
4267,
304,
339,
12495,
275,
3882,
480,
2719,
6501,
12495,
531,
339,
5052,
63,
3702,
275,
3882,
480,
3205,
4113,
6434,
531,
339,
4833,
63,
3702,
275,
3882,
480,
2959,
4113,
6434,
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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
] |
camptocamp/ngo-addons-backport
|
addons/account_asset/report/__init__.py
|
445
|
1074
|
# -*- 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 account_asset_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,
2933,
63,
6562,
63,
3070,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
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,
2933,
63,
6562,
63,
3070,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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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
] |
DaveBackus/Data_Bootcamp
|
Code/Lab/googlefinance.py
|
1
|
3562
|
"""
This file demonstrates how to read minute level data from the
Google finance api
"""
import datetime as dt
import numpy as np
import pandas as pd
import pandas_datareader as pdr
import requests as r
import sys
from io import StriongIO
def retrieve_single_timeseries(ticker, secs=60, ndays=5):
"""
Grabs data from Google finance. It retrieves the data for `ticker` at
`secs` intervals for the most recent `ndays`. The fields it retrieves
for each interval is (time, open price, close price, volume of trade)
Parameters
----------
ticker : String
Single ticker name
secs : scalar(Int)
Number of seconds to sample at
ndays : scalar(Int)
Number of days of data to retrieve (max is 5)
Returns
-------
data : DataFrame
Pandas DataFrame with the stock open, close, volume, and date
information.
"""
# Get the Base url
baseurl = "http://www.google.com/finance/getprices"
# Dictionary for parameters
pdict = {}
pdict["q"] = ticker
pdict["i"] = secs
pdict["p"] = str(ndays) + "d"
pdict["f"] = "d,c,v,o"
# Retrieve data
raw_html = r.get(baseurl, params=pdict)
raw_text = raw_html.text
# Clean data
data = clean_data(raw_text, ticker)
return data
def clean_data(raw_text, ticker):
"""
Takes the raw text output of the html request and cleans it into a
pandas dataframe
Parameters
----------
raw_text : String
The text generated by the html request
Returns
-------
data : Pandas.DataFrame
DataFrame with relevant data
"""
# Split by line separators
all_lines = raw_text.split("\n")
metadata = all_lines[1:7]
data_csv = StringIO("\n".join(all_lines[7:]))
# Deal with metadata that we care about
for line in metadata:
if "COLUMNS=" in line:
# Get columns
columns = line.split("COLUMNS=")[1].split(",")
elif "INTERVAL" in line:
timeincrement = int(line.split("INTERVAL=")[1])
elif "TIMEZONE_OFFSET" in line:
# Get timezone offset in seconds
tzoffset = int(line.split("TIMEZONE_OFFSET=")[1])*60
elif "MARKET_OPEN_MINUTE" in line:
opentime = ()
# Load data into pandas
data = pd.read_csv(data_csv, names=columns)
# Fix the date rows
data.insert(0, "DateTime", np.NaN)
data.insert(1, "TICKER", ticker)
for i, row in data.iterrows():
if row["DATE"][0] is "a":
secsfromepoch = int(row["DATE"][1:])
basedate = dt.datetime.utcfromtimestamp(secsfromepoch + tzoffset)
data.set_value(i, "DateTime", basedate)
else:
secsfrombase = int(row["DATE"])
data.set_value(i, "DateTime", basedate + dt.timedelta(seconds=secsfrombase*timeincrement))
# Fix the data (no price changes when market is closed)
# Drop irrelevant info, compute incremental returns, rename, and set index
data = data.drop(labels="DATE", axis=1)
data = data.rename(columns={"DateTime": "DATE"})
data.insert(1, "RETURNS", 100*(data["CLOSE"]/data["OPEN"] - 1))
data.set_value(data.index, "VOLUME", data["VOLUME"]/1e6)
return data
stock_tickers = ["AAPL", "F", "GM" ,"GOOG", "MSFT",
"MDLZ", "FOXA", "VRSK", "PCLN",
"SBUX", "ROST", "WFM", "CHKP",
"MAT", "LVNTA", "AMAT", "ADI"]
dfs = []
for tick in stock_tickers:
dfs.append(retrieve_single_timeseries(tick))
fulldata = pd.concat(dfs)
|
mit
|
[
624,
199,
2765,
570,
23789,
31216,
4212,
370,
1586,
12709,
2166,
666,
687,
314,
199,
13266,
2583,
554,
2986,
199,
624,
199,
646,
2197,
465,
4487,
199,
646,
2680,
465,
980,
199,
646,
10634,
465,
6454,
199,
646,
10634,
63,
576,
5503,
465,
299,
5012,
199,
646,
4145,
465,
519,
199,
646,
984,
199,
199,
504,
5890,
492,
31309,
951,
2090,
421,
199,
318,
8044,
63,
4780,
63,
28551,
8,
28572,
12,
20091,
29,
2259,
12,
302,
4899,
29,
21,
304,
272,
408,
272,
10268,
1533,
666,
687,
4475,
2583,
554,
14,
2779,
9619,
2310,
314,
666,
367,
658,
28572,
64,
737,
272,
658,
4855,
64,
15802,
367,
314,
4750,
8058,
658,
977,
5758,
2313,
710,
1504,
652,
9619,
2310,
272,
367,
1924,
6252,
365,
334,
521,
12,
1551,
8033,
12,
4002,
8033,
12,
3301,
402,
21032,
9,
339,
3897,
272,
4143,
272,
32721,
520,
2624,
267,
13050,
32721,
536,
272,
20091,
520,
6917,
8,
3241,
9,
267,
4860,
402,
4696,
370,
2690,
737,
272,
302,
4899,
520,
6917,
8,
3241,
9,
267,
4860,
402,
7609,
402,
666,
370,
8044,
334,
988,
365,
959,
9,
339,
1803,
272,
5514,
272,
666,
520,
10071,
267,
510,
7683,
10071,
543,
314,
10952,
1551,
12,
4002,
12,
3301,
12,
436,
1434,
267,
2556,
14,
339,
408,
272,
327,
2372,
314,
3523,
1166,
272,
1300,
633,
275,
298,
1014,
921,
1544,
14,
3098,
14,
957,
15,
2408,
554,
15,
362,
32434,
2,
339,
327,
11932,
367,
2633,
272,
299,
807,
275,
1052,
272,
299,
807,
905,
81,
937,
275,
32721,
272,
299,
807,
905,
73,
937,
275,
20091,
272,
299,
807,
905,
80,
937,
275,
620,
8,
977,
5758,
9,
435,
298,
68,
2,
272,
299,
807,
905,
70,
937,
275,
298,
68,
12,
67,
12,
86,
12,
79,
2,
339,
327,
13939,
666,
272,
3066,
63,
1360,
275,
519,
14,
362,
8,
28937,
12,
1862,
29,
80,
807,
9,
272,
3066,
63,
505,
275,
3066,
63,
1360,
14,
505,
339,
327,
12762,
666,
272,
666,
275,
3633,
63,
576,
8,
1773,
63,
505,
12,
32721,
9,
339,
372,
666,
199,
199,
318,
3633,
63,
576,
8,
1773,
63,
505,
12,
32721,
304,
272,
408,
272,
17415,
314,
3066,
1318,
1072,
402,
314,
3517,
1056,
436,
15158,
796,
652,
1901,
282,
272,
10634,
27168,
339,
3897,
272,
4143,
272,
3066,
63,
505,
520,
2624,
267,
710,
1318,
4046,
701,
314,
3517,
1056,
339,
1803,
272,
5514,
272,
666,
520,
510,
7683,
14,
9205,
267,
10071,
543,
12082,
666,
339,
408,
272,
327,
11740,
701,
1004,
17658,
272,
1006,
63,
1278,
275,
3066,
63,
505,
14,
1294,
4582,
78,
531,
272,
3341,
275,
1006,
63,
1278,
59,
17,
26,
23,
61,
272,
666,
63,
4737,
275,
5228,
4582,
78,
1674,
904,
8,
452,
63,
1278,
59,
23,
16720,
339,
327,
1487,
279,
543,
3341,
626,
781,
10296,
3595,
272,
367,
1004,
315,
3341,
26,
267,
340,
298,
28427,
628,
315,
1004,
26,
288,
327,
2372,
4362,
288,
4362,
275,
1004,
14,
1294,
480,
28427,
29,
9981,
17,
1055,
1294,
20324,
267,
916,
298,
17359,
2,
315,
1004,
26,
288,
900,
9728,
275,
1109,
8,
604,
14,
1294,
480,
17359,
29,
9981,
17,
566,
267,
916,
298,
4961,
15353,
63,
14839,
2,
315,
1004,
26,
288,
327,
2372,
7137,
3268,
315,
4696,
288,
5823,
2743,
275,
1109,
8,
604,
14,
1294,
480,
4961,
15353,
63,
14839,
29,
9981,
17,
19100,
2259,
267,
916,
298,
10520,
775,
63,
9935,
63,
4896,
4586,
2,
315,
1004,
26,
288,
1551,
521,
275,
6248,
339,
327,
7190,
666,
1901,
10634,
272,
666,
275,
6454,
14,
739,
63,
4737,
8,
576,
63,
4737,
12,
1561,
29,
3406,
9,
339,
327,
14811,
314,
1434,
4730,
272,
666,
14,
3176,
8,
16,
12,
298,
3926,
401,
980,
14,
14300,
9,
272,
666,
14,
3176,
8,
17,
12,
298,
52,
13884,
540,
401,
32721,
9,
272,
367,
284,
12,
1962,
315,
666,
14,
1661,
3838,
837,
267,
340,
1962,
905,
5390,
9210,
16,
61,
365,
298,
65,
582,
288,
20091,
70,
5864,
5132,
275,
1109,
8,
1143,
905,
5390,
9210,
17,
5728,
288,
1300,
602,
275,
4487,
14,
2083,
14,
5834,
18531,
8,
4855,
70,
5864,
5132,
435,
5823,
2743,
9,
288,
666,
14,
409,
63,
585,
8,
73,
12,
298,
3926,
401,
1300,
602,
9,
267,
587,
26,
288,
20091,
504,
1095,
275,
1109,
8,
1143,
905,
5390,
3135,
288,
666,
14,
409,
63,
585,
8,
73,
12,
298,
3926,
401,
1300,
602,
435,
4487,
14,
7473,
8,
4515,
29,
4855,
504,
1095,
10,
521,
9728,
430,
339,
327,
14811,
314,
666,
334,
889,
8033,
4493,
1380,
26584,
365,
6876,
9,
339,
327,
18110,
8190,
21906,
2256,
12,
4526,
16316,
2529,
12,
11441,
12,
436,
663,
1478,
272,
666,
275,
666,
14,
4824,
8,
3512,
628,
5390,
401,
3114,
29,
17,
9,
272,
666,
275,
666,
14,
8165,
8,
3406,
8871,
3926,
582,
298,
5390,
5984,
272,
666,
14,
3176,
8,
17,
12,
298,
7341,
1230,
2709,
401,
2948,
5830,
576,
905,
18219,
937,
15,
576,
905,
9935,
937,
446,
413,
430,
272,
666,
14,
409,
63,
585,
8,
576,
14,
1080,
12,
298,
16689,
401,
666,
905,
16689,
937,
15,
17,
69,
22,
9,
339,
372,
666,
421,
199,
6088,
63,
8284,
1192,
275,
2097,
33,
1282,
44,
401,
298,
38,
401,
298,
22636,
2,
2360,
2,
17316,
39,
401,
298,
3053,
2161,
401,
326,
298,
5127,
44,
58,
401,
298,
3230,
56,
33,
401,
298,
20271,
8656,
401,
298,
48,
1981,
46,
401,
326,
298,
51,
2910,
56,
401,
298,
1092,
840,
401,
298,
55,
22367,
401,
298,
1244,
24974,
401,
326,
298,
16996,
401,
298,
18750,
46,
6166,
401,
298,
1156,
619,
401,
298,
1554,
41,
937,
199,
10434,
275,
942,
199,
199,
509,
11748,
315,
10952,
63,
8284,
1192,
26,
272,
366,
2319,
14,
740,
8,
14270,
63,
4780,
63,
28551,
8,
8284,
430,
199,
199,
2861,
576,
275,
6454,
14,
9419,
8,
10434,
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
] |
[
199,
2765,
570,
23789,
31216,
4212,
370,
1586,
12709,
2166,
666,
687,
314,
199,
13266,
2583,
554,
2986,
199,
624,
199,
646,
2197,
465,
4487,
199,
646,
2680,
465,
980,
199,
646,
10634,
465,
6454,
199,
646,
10634,
63,
576,
5503,
465,
299,
5012,
199,
646,
4145,
465,
519,
199,
646,
984,
199,
199,
504,
5890,
492,
31309,
951,
2090,
421,
199,
318,
8044,
63,
4780,
63,
28551,
8,
28572,
12,
20091,
29,
2259,
12,
302,
4899,
29,
21,
304,
272,
408,
272,
10268,
1533,
666,
687,
4475,
2583,
554,
14,
2779,
9619,
2310,
314,
666,
367,
658,
28572,
64,
737,
272,
658,
4855,
64,
15802,
367,
314,
4750,
8058,
658,
977,
5758,
2313,
710,
1504,
652,
9619,
2310,
272,
367,
1924,
6252,
365,
334,
521,
12,
1551,
8033,
12,
4002,
8033,
12,
3301,
402,
21032,
9,
339,
3897,
272,
4143,
272,
32721,
520,
2624,
267,
13050,
32721,
536,
272,
20091,
520,
6917,
8,
3241,
9,
267,
4860,
402,
4696,
370,
2690,
737,
272,
302,
4899,
520,
6917,
8,
3241,
9,
267,
4860,
402,
7609,
402,
666,
370,
8044,
334,
988,
365,
959,
9,
339,
1803,
272,
5514,
272,
666,
520,
10071,
267,
510,
7683,
10071,
543,
314,
10952,
1551,
12,
4002,
12,
3301,
12,
436,
1434,
267,
2556,
14,
339,
408,
272,
327,
2372,
314,
3523,
1166,
272,
1300,
633,
275,
298,
1014,
921,
1544,
14,
3098,
14,
957,
15,
2408,
554,
15,
362,
32434,
2,
339,
327,
11932,
367,
2633,
272,
299,
807,
275,
1052,
272,
299,
807,
905,
81,
937,
275,
32721,
272,
299,
807,
905,
73,
937,
275,
20091,
272,
299,
807,
905,
80,
937,
275,
620,
8,
977,
5758,
9,
435,
298,
68,
2,
272,
299,
807,
905,
70,
937,
275,
298,
68,
12,
67,
12,
86,
12,
79,
2,
339,
327,
13939,
666,
272,
3066,
63,
1360,
275,
519,
14,
362,
8,
28937,
12,
1862,
29,
80,
807,
9,
272,
3066,
63,
505,
275,
3066,
63,
1360,
14,
505,
339,
327,
12762,
666,
272,
666,
275,
3633,
63,
576,
8,
1773,
63,
505,
12,
32721,
9,
339,
372,
666,
199,
199,
318,
3633,
63,
576,
8,
1773,
63,
505,
12,
32721,
304,
272,
408,
272,
17415,
314,
3066,
1318,
1072,
402,
314,
3517,
1056,
436,
15158,
796,
652,
1901,
282,
272,
10634,
27168,
339,
3897,
272,
4143,
272,
3066,
63,
505,
520,
2624,
267,
710,
1318,
4046,
701,
314,
3517,
1056,
339,
1803,
272,
5514,
272,
666,
520,
510,
7683,
14,
9205,
267,
10071,
543,
12082,
666,
339,
408,
272,
327,
11740,
701,
1004,
17658,
272,
1006,
63,
1278,
275,
3066,
63,
505,
14,
1294,
4582,
78,
531,
272,
3341,
275,
1006,
63,
1278,
59,
17,
26,
23,
61,
272,
666,
63,
4737,
275,
5228,
4582,
78,
1674,
904,
8,
452,
63,
1278,
59,
23,
16720,
339,
327,
1487,
279,
543,
3341,
626,
781,
10296,
3595,
272,
367,
1004,
315,
3341,
26,
267,
340,
298,
28427,
628,
315,
1004,
26,
288,
327,
2372,
4362,
288,
4362,
275,
1004,
14,
1294,
480,
28427,
29,
9981,
17,
1055,
1294,
20324,
267,
916,
298,
17359,
2,
315,
1004,
26,
288,
900,
9728,
275,
1109,
8,
604,
14,
1294,
480,
17359,
29,
9981,
17,
566,
267,
916,
298,
4961,
15353,
63,
14839,
2,
315,
1004,
26,
288,
327,
2372,
7137,
3268,
315,
4696,
288,
5823,
2743,
275,
1109,
8,
604,
14,
1294,
480,
4961,
15353,
63,
14839,
29,
9981,
17,
19100,
2259,
267,
916,
298,
10520,
775,
63,
9935,
63,
4896,
4586,
2,
315,
1004,
26,
288,
1551,
521,
275,
6248,
339,
327,
7190,
666,
1901,
10634,
272,
666,
275,
6454,
14,
739,
63,
4737,
8,
576,
63,
4737,
12,
1561,
29,
3406,
9,
339,
327,
14811,
314,
1434,
4730,
272,
666,
14,
3176,
8,
16,
12,
298,
3926,
401,
980,
14,
14300,
9,
272,
666,
14,
3176,
8,
17,
12,
298,
52,
13884,
540,
401,
32721,
9,
272,
367,
284,
12,
1962,
315,
666,
14,
1661,
3838,
837,
267,
340,
1962,
905,
5390,
9210,
16,
61,
365,
298,
65,
582,
288,
20091,
70,
5864,
5132,
275,
1109,
8,
1143,
905,
5390,
9210,
17,
5728,
288,
1300,
602,
275,
4487,
14,
2083,
14,
5834,
18531,
8,
4855,
70,
5864,
5132,
435,
5823,
2743,
9,
288,
666,
14,
409,
63,
585,
8,
73,
12,
298,
3926,
401,
1300,
602,
9,
267,
587,
26,
288,
20091,
504,
1095,
275,
1109,
8,
1143,
905,
5390,
3135,
288,
666,
14,
409,
63,
585,
8,
73,
12,
298,
3926,
401,
1300,
602,
435,
4487,
14,
7473,
8,
4515,
29,
4855,
504,
1095,
10,
521,
9728,
430,
339,
327,
14811,
314,
666,
334,
889,
8033,
4493,
1380,
26584,
365,
6876,
9,
339,
327,
18110,
8190,
21906,
2256,
12,
4526,
16316,
2529,
12,
11441,
12,
436,
663,
1478,
272,
666,
275,
666,
14,
4824,
8,
3512,
628,
5390,
401,
3114,
29,
17,
9,
272,
666,
275,
666,
14,
8165,
8,
3406,
8871,
3926,
582,
298,
5390,
5984,
272,
666,
14,
3176,
8,
17,
12,
298,
7341,
1230,
2709,
401,
2948,
5830,
576,
905,
18219,
937,
15,
576,
905,
9935,
937,
446,
413,
430,
272,
666,
14,
409,
63,
585,
8,
576,
14,
1080,
12,
298,
16689,
401,
666,
905,
16689,
937,
15,
17,
69,
22,
9,
339,
372,
666,
421,
199,
6088,
63,
8284,
1192,
275,
2097,
33,
1282,
44,
401,
298,
38,
401,
298,
22636,
2,
2360,
2,
17316,
39,
401,
298,
3053,
2161,
401,
326,
298,
5127,
44,
58,
401,
298,
3230,
56,
33,
401,
298,
20271,
8656,
401,
298,
48,
1981,
46,
401,
326,
298,
51,
2910,
56,
401,
298,
1092,
840,
401,
298,
55,
22367,
401,
298,
1244,
24974,
401,
326,
298,
16996,
401,
298,
18750,
46,
6166,
401,
298,
1156,
619,
401,
298,
1554,
41,
937,
199,
10434,
275,
942,
199,
199,
509,
11748,
315,
10952,
63,
8284,
1192,
26,
272,
366,
2319,
14,
740,
8,
14270,
63,
4780,
63,
28551,
8,
8284,
430,
199,
199,
2861,
576,
275,
6454,
14,
9419,
8,
10434,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
popazerty/EG-2
|
lib/python/Screens/NetworkSetup.py
|
4
|
140093
|
from boxbranding import getBoxType, getMachineBrand, getMachineName
from os import path as os_path, remove, unlink, rename, chmod, access, X_OK
from shutil import move
import time
from enigma import eTimer
from Screens.Screen import Screen
from Screens.MessageBox import MessageBox
from Screens.Standby import TryQuitMainloop
from Screens.HelpMenu import HelpableScreen
from Components.About import about
from Components.Console import Console
from Components.Network import iNetwork
from Components.Sources.StaticText import StaticText
from Components.Sources.Boolean import Boolean
from Components.Sources.List import List
from Components.SystemInfo import SystemInfo
from Components.Label import Label, MultiColorLabel
from Components.ScrollLabel import ScrollLabel
from Components.Pixmap import Pixmap, MultiPixmap
from Components.MenuList import MenuList
from Components.config import config, ConfigSubsection, ConfigYesNo, ConfigIP, ConfigText, ConfigPassword, ConfigSelection, getConfigListEntry, ConfigNumber, ConfigLocations, NoSave, ConfigMacText
from Components.ConfigList import ConfigListScreen
from Components.PluginComponent import plugins
from Components.FileList import MultiFileSelectList
from Components.ActionMap import ActionMap, NumberActionMap, HelpableActionMap
from Tools.Directories import fileExists, resolveFilename, SCOPE_PLUGINS, SCOPE_ACTIVE_SKIN
from Tools.LoadPixmap import LoadPixmap
from Plugins.Plugin import PluginDescriptor
class NetworkAdapterSelection(Screen,HelpableScreen):
def __init__(self, session):
Screen.__init__(self, session)
HelpableScreen.__init__(self)
Screen.setTitle(self, _("Network Setup"))
self.wlan_errortext = _("No working wireless network adapter found.\nPlease verify that you have attached a compatible WLAN device and your network is configured correctly.")
self.lan_errortext = _("No working local network adapter found.\nPlease verify that you have attached a network cable and your network is configured correctly.")
self.oktext = _("Press OK on your remote control to continue.")
self.edittext = _("Press OK to edit the settings.")
self.defaulttext = _("Press yellow to set this interface as the default interface.")
self.restartLanRef = None
self["key_red"] = StaticText(_("Close"))
self["key_green"] = StaticText(_("Select"))
self["key_yellow"] = StaticText("")
self["key_blue"] = StaticText("")
self["introduction"] = StaticText(self.edittext)
self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
{
"cancel": (self.close, _("Exit network interface list")),
"ok": (self.okbuttonClick, _("Select interface")),
})
self["ColorActions"] = HelpableActionMap(self, "ColorActions",
{
"red": (self.close, _("Exit network interface list")),
"green": (self.okbuttonClick, _("Select interface")),
"blue": (self.openNetworkWizard, _("Use the network wizard to configure selected network adapter")),
})
self["DefaultInterfaceAction"] = HelpableActionMap(self, "ColorActions",
{
"yellow": (self.setDefaultInterface, [_("Set interface as the default Interface"),_("* Only available if more than one interface is active.")] ),
})
self.adapters = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()]
if not self.adapters:
self.adapters = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getConfiguredAdapters()]
if len(self.adapters) == 0:
self.adapters = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getInstalledAdapters()]
self.onChangedEntry = [ ]
self.list = []
self["list"] = List(self.list)
self.updateList()
if not self.selectionChanged in self["list"].onSelectionChanged:
self["list"].onSelectionChanged.append(self.selectionChanged)
if len(self.adapters) == 1:
self.onFirstExecBegin.append(self.okbuttonClick)
self.onClose.append(self.cleanup)
def createSummary(self):
from Screens.PluginBrowser import PluginBrowserSummary
return PluginBrowserSummary
def selectionChanged(self):
item = self["list"].getCurrent()
if item:
name = item[0]
desc = item[1]
else:
name = ""
desc = ""
for cb in self.onChangedEntry:
cb(name, desc)
def buildInterfaceList(self,iface,name,default,active ):
divpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_ACTIVE_SKIN, "div-h.png"))
defaultpng = None
activepng = None
description = None
interfacepng = None
if not iNetwork.isWirelessInterface(iface):
if active is True:
interfacepng = LoadPixmap(resolveFilename(SCOPE_ACTIVE_SKIN, "icons/network_wired-active.png"))
elif active is False:
interfacepng = LoadPixmap(resolveFilename(SCOPE_ACTIVE_SKIN, "icons/network_wired-inactive.png"))
else:
interfacepng = LoadPixmap(resolveFilename(SCOPE_ACTIVE_SKIN, "icons/network_wired.png"))
elif iNetwork.isWirelessInterface(iface):
if active is True:
interfacepng = LoadPixmap(resolveFilename(SCOPE_ACTIVE_SKIN, "icons/network_wireless-active.png"))
elif active is False:
interfacepng = LoadPixmap(resolveFilename(SCOPE_ACTIVE_SKIN, "icons/network_wireless-inactive.png"))
else:
interfacepng = LoadPixmap(resolveFilename(SCOPE_ACTIVE_SKIN, "icons/network_wireless.png"))
num_configured_if = len(iNetwork.getConfiguredAdapters())
if num_configured_if >= 2:
if default is True:
defaultpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_ACTIVE_SKIN, "buttons/button_blue.png"))
elif default is False:
defaultpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_ACTIVE_SKIN, "buttons/button_blue_off.png"))
if active is True:
activepng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_ACTIVE_SKIN, "icons/lock_on.png"))
elif active is False:
activepng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_ACTIVE_SKIN, "icons/lock_error.png"))
description = iNetwork.getFriendlyAdapterDescription(iface)
return iface, name, description, interfacepng, defaultpng, activepng, divpng
def updateList(self):
self.list = []
default_gw = None
num_configured_if = len(iNetwork.getConfiguredAdapters())
if num_configured_if >= 2:
self["key_yellow"].setText(_("Default"))
self["introduction"].setText(self.defaulttext)
self["DefaultInterfaceAction"].setEnabled(True)
else:
self["key_yellow"].setText("")
self["introduction"].setText(self.edittext)
self["DefaultInterfaceAction"].setEnabled(False)
if num_configured_if < 2 and os_path.exists("/etc/default_gw"):
unlink("/etc/default_gw")
if os_path.exists("/etc/default_gw"):
fp = file('/etc/default_gw', 'r')
result = fp.read()
fp.close()
default_gw = result
for x in self.adapters:
if x[1] == default_gw:
default_int = True
else:
default_int = False
if iNetwork.getAdapterAttribute(x[1], 'up') is True:
active_int = True
else:
active_int = False
self.list.append(self.buildInterfaceList(x[1], _(x[0]), default_int, active_int ))
if os_path.exists(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkWizard/networkwizard.xml")):
self["key_blue"].setText(_("Network wizard"))
self["list"].setList(self.list)
def setDefaultInterface(self):
selection = self["list"].getCurrent()
num_if = len(self.list)
old_default_gw = None
num_configured_if = len(iNetwork.getConfiguredAdapters())
if os_path.exists("/etc/default_gw"):
fp = open('/etc/default_gw', 'r')
old_default_gw = fp.read()
fp.close()
if num_configured_if > 1 and (not old_default_gw or old_default_gw != selection[0]):
fp = open('/etc/default_gw', 'w+')
fp.write(selection[0])
fp.close()
self.restartLan()
elif old_default_gw and num_configured_if < 2:
unlink("/etc/default_gw")
self.restartLan()
def okbuttonClick(self):
selection = self["list"].getCurrent()
if selection is not None:
self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, selection[0])
def AdapterSetupClosed(self, *ret):
if len(self.adapters) == 1:
self.close()
else:
self.updateList()
def cleanup(self):
iNetwork.stopLinkStateConsole()
iNetwork.stopRestartConsole()
iNetwork.stopGetInterfacesConsole()
def restartLan(self):
iNetwork.restartNetwork(self.restartLanDataAvail)
self.restartLanRef = self.session.openWithCallback(self.restartfinishedCB, MessageBox, _("Please wait while we configure your network..."), type = MessageBox.TYPE_INFO, enable_input = False)
def restartLanDataAvail(self, data):
if data is True:
iNetwork.getInterfaces(self.getInterfacesDataAvail)
def getInterfacesDataAvail(self, data):
if data is True:
self.restartLanRef.close(True)
def restartfinishedCB(self, data):
if data is True:
self.updateList()
self.session.open(MessageBox, _("Finished configuring your network"), type = MessageBox.TYPE_INFO, timeout = 10, default = False)
def openNetworkWizard(self):
if os_path.exists(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkWizard/networkwizard.xml")):
try:
from Plugins.SystemPlugins.NetworkWizard.NetworkWizard import NetworkWizard
except ImportError:
self.session.open(MessageBox, _("The network wizard extension is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
else:
selection = self["list"].getCurrent()
if selection is not None:
self.session.openWithCallback(self.AdapterSetupClosed, NetworkWizard, selection[0])
class NameserverSetup(Screen, ConfigListScreen, HelpableScreen):
def __init__(self, session):
Screen.__init__(self, session)
HelpableScreen.__init__(self)
Screen.setTitle(self, _("Nameserver settings"))
self.backupNameserverList = iNetwork.getNameserverList()[:]
print "backup-list:", self.backupNameserverList
self["key_red"] = StaticText(_("Cancel"))
self["key_green"] = StaticText(_("Save"))
self["key_yellow"] = StaticText(_("Add"))
self["key_blue"] = StaticText(_("Delete"))
self["introduction"] = StaticText(_("Press OK to activate the settings."))
self.createConfig()
self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
{
"cancel": (self.cancel, _("Exit nameserver configuration")),
"ok": (self.ok, _("Activate current configuration")),
})
self["ColorActions"] = HelpableActionMap(self, "ColorActions",
{
"red": (self.cancel, _("Exit nameserver configuration")),
"green": (self.ok, _("Activate current configuration")),
"yellow": (self.add, _("Add a nameserver entry")),
"blue": (self.remove, _("Remove a nameserver entry")),
})
self["actions"] = NumberActionMap(["SetupActions"],
{
"ok": self.ok,
}, -2)
self.list = []
ConfigListScreen.__init__(self, self.list)
self.createSetup()
def createConfig(self):
self.nameservers = iNetwork.getNameserverList()
self.nameserverEntries = [ NoSave(ConfigIP(default=nameserver)) for nameserver in self.nameservers]
def createSetup(self):
self.list = []
i = 1
for x in self.nameserverEntries:
self.list.append(getConfigListEntry(_("Nameserver %d") % i, x))
i += 1
self["config"].list = self.list
self["config"].l.setList(self.list)
def ok(self):
iNetwork.clearNameservers()
for nameserver in self.nameserverEntries:
iNetwork.addNameserver(nameserver.value)
iNetwork.writeNameserverConfig()
self.close()
def run(self):
self.ok()
def cancel(self):
iNetwork.clearNameservers()
print "backup-list:", self.backupNameserverList
for nameserver in self.backupNameserverList:
iNetwork.addNameserver(nameserver)
self.close()
def add(self):
iNetwork.addNameserver([0, 0, 0, 0])
self.createConfig()
self.createSetup()
def remove(self):
print "currentIndex:", self["config"].getCurrentIndex()
index = self["config"].getCurrentIndex()
if index < len(self.nameservers):
iNetwork.removeNameserver(self.nameservers[index])
self.createConfig()
self.createSetup()
class NetworkMacSetup(Screen, ConfigListScreen, HelpableScreen):
def __init__(self, session):
Screen.__init__(self, session)
HelpableScreen.__init__(self)
Screen.setTitle(self, _("MAC-address settings"))
self.curMac = self.getmac('eth0')
self.getConfigMac = NoSave(ConfigMacText(default=self.curMac))
self["key_red"] = StaticText(_("Cancel"))
self["key_green"] = StaticText(_("Save"))
self["introduction"] = StaticText(_("Press OK to set the MAC-address."))
self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
{
"cancel": (self.cancel, _("Exit nameserver configuration")),
"ok": (self.ok, _("Activate current configuration")),
})
self["ColorActions"] = HelpableActionMap(self, "ColorActions",
{
"red": (self.cancel, _("Exit MAC-address configuration")),
"green": (self.ok, _("Activate MAC-address configuration")),
})
self["actions"] = NumberActionMap(["SetupActions"],
{
"ok": self.ok,
}, -2)
self.list = []
ConfigListScreen.__init__(self, self.list)
self.createSetup()
def getmac(self, iface):
eth = about.getIfConfig(iface)
return eth['hwaddr']
def createSetup(self):
self.list = []
self.list.append(getConfigListEntry(_("MAC-address"), self.getConfigMac))
self["config"].list = self.list
self["config"].l.setList(self.list)
def ok(self):
MAC = self.getConfigMac.value
f = open('/etc/enigma2/hwmac', 'w')
f.write(MAC)
f.close()
self.restartLan()
def run(self):
self.ok()
def cancel(self):
self.close()
def restartLan(self):
iNetwork.restartNetwork(self.restartLanDataAvail)
self.restartLanRef = self.session.openWithCallback(self.restartfinishedCB, MessageBox, _("Please wait while we configure your network..."), type = MessageBox.TYPE_INFO, enable_input = False)
def restartLanDataAvail(self, data):
if data is True:
iNetwork.getInterfaces(self.getInterfacesDataAvail)
def getInterfacesDataAvail(self, data):
if data is True:
self.restartLanRef.close(True)
def restartfinishedCB(self, data):
if data is True:
self.session.openWithCallback(self.close, MessageBox, _("Finished configuring your network"), type = MessageBox.TYPE_INFO, timeout = 10, default = False)
class AdapterSetup(Screen, ConfigListScreen, HelpableScreen):
def __init__(self, session, networkinfo, essid=None):
Screen.__init__(self, session)
HelpableScreen.__init__(self)
Screen.setTitle(self, _("Adapter settings"))
self.session = session
if isinstance(networkinfo, (list, tuple)):
self.iface = networkinfo[0]
self.essid = networkinfo[1]
else:
self.iface = networkinfo
self.essid = essid
self.extended = None
self.applyConfigRef = None
self.finished_cb = None
self.oktext = _("Press OK on your remote control to continue.")
self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
self.createConfig()
self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
{
"cancel": (self.keyCancel, _("exit network adapter configuration")),
"ok": (self.keySave, _("activate network adapter configuration")),
})
self["ColorActions"] = HelpableActionMap(self, "ColorActions",
{
"red": (self.keyCancel, _("exit network adapter configuration")),
"green": (self.keySave, _("activate network adapter configuration")),
"blue": (self.KeyBlue, _("open nameserver configuration")),
})
self["actions"] = NumberActionMap(["SetupActions"],
{
"ok": self.keySave,
}, -2)
self.list = []
ConfigListScreen.__init__(self, self.list,session = self.session)
self.createSetup()
self.onLayoutFinish.append(self.layoutFinished)
self.onClose.append(self.cleanup)
self["DNS1text"] = StaticText(_("Primary DNS"))
self["DNS2text"] = StaticText(_("Secondary DNS"))
self["DNS1"] = StaticText()
self["DNS2"] = StaticText()
self["introduction"] = StaticText(_("Current settings:"))
self["IPtext"] = StaticText(_("IP address"))
self["Netmasktext"] = StaticText(_("Netmask"))
self["Gatewaytext"] = StaticText(_("Gateway"))
self["IP"] = StaticText()
self["Mask"] = StaticText()
self["Gateway"] = StaticText()
self["Adaptertext"] = StaticText(_("Network:"))
self["Adapter"] = StaticText()
self["introduction2"] = StaticText(_("Press OK to activate the settings."))
self["key_red"] = StaticText(_("Cancel"))
self["key_green"] = StaticText(_("Save"))
self["key_blue"] = StaticText(_("Edit DNS"))
self["VKeyIcon"] = Boolean(False)
self["HelpWindow"] = Pixmap()
self["HelpWindow"].hide()
def layoutFinished(self):
self["DNS1"].setText(self.primaryDNS.getText())
self["DNS2"].setText(self.secondaryDNS.getText())
if self.ipConfigEntry.getText() is not None:
if self.ipConfigEntry.getText() == "0.0.0.0":
self["IP"].setText(_("N/A"))
else:
self["IP"].setText(self.ipConfigEntry.getText())
else:
self["IP"].setText(_("N/A"))
if self.netmaskConfigEntry.getText() is not None:
if self.netmaskConfigEntry.getText() == "0.0.0.0":
self["Mask"].setText(_("N/A"))
else:
self["Mask"].setText(self.netmaskConfigEntry.getText())
else:
self["IP"].setText(_("N/A"))
if iNetwork.getAdapterAttribute(self.iface, "gateway"):
if self.gatewayConfigEntry.getText() == "0.0.0.0":
self["Gatewaytext"].setText(_("Gateway"))
self["Gateway"].setText(_("N/A"))
else:
self["Gatewaytext"].setText(_("Gateway"))
self["Gateway"].setText(self.gatewayConfigEntry.getText())
else:
self["Gateway"].setText("")
self["Gatewaytext"].setText("")
self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
def createConfig(self):
self.InterfaceEntry = None
self.dhcpEntry = None
self.gatewayEntry = None
self.hiddenSSID = None
self.wlanSSID = None
self.encryption = None
self.encryptionType = None
self.encryptionKey = None
self.encryptionlist = None
self.weplist = None
self.wsconfig = None
self.default = None
if iNetwork.isWirelessInterface(self.iface):
from Plugins.SystemPlugins.WirelessLan.Wlan import wpaSupplicant
self.ws = wpaSupplicant()
self.encryptionlist = []
self.encryptionlist.append(("Unencrypted", _("Unencrypted")))
self.encryptionlist.append(("WEP", _("WEP")))
self.encryptionlist.append(("WPA", _("WPA")))
self.encryptionlist.append(("WPA/WPA2", _("WPA or WPA2")))
self.encryptionlist.append(("WPA2", _("WPA2")))
self.weplist = []
self.weplist.append("ASCII")
self.weplist.append("HEX")
self.wsconfig = self.ws.loadConfig(self.iface)
if self.essid is None:
self.essid = self.wsconfig['ssid']
config.plugins.wlan.hiddenessid = NoSave(ConfigYesNo(default = self.wsconfig['hiddenessid']))
config.plugins.wlan.essid = NoSave(ConfigText(default = self.essid, visible_width = 50, fixed_size = False))
config.plugins.wlan.encryption = NoSave(ConfigSelection(self.encryptionlist, default = self.wsconfig['encryption'] ))
config.plugins.wlan.wepkeytype = NoSave(ConfigSelection(self.weplist, default = self.wsconfig['wepkeytype'] ))
config.plugins.wlan.psk = NoSave(ConfigPassword(default = self.wsconfig['key'], visible_width = 50, fixed_size = False))
self.activateInterfaceEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "up") or False))
self.dhcpConfigEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "dhcp") or False))
self.ipConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0])
self.netmaskConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0]))
if iNetwork.getAdapterAttribute(self.iface, "gateway"):
self.dhcpdefault = True
else:
self.dhcpdefault = False
self.hasGatewayConfigEntry = NoSave(ConfigYesNo(default=self.dhcpdefault or False))
self.gatewayConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0]))
nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
def createSetup(self):
if SystemInfo["WakeOnLAN"]:
self.wolstartvalue = config.network.wol.value
self.list = []
self.InterfaceEntry = getConfigListEntry(_("Use interface"), self.activateInterfaceEntry)
self.list.append(self.InterfaceEntry)
if self.activateInterfaceEntry.value:
self.dhcpEntry = getConfigListEntry(_("Use DHCP"), self.dhcpConfigEntry)
self.list.append(self.dhcpEntry)
if not self.dhcpConfigEntry.value:
self.list.append(getConfigListEntry(_('IP address'), self.ipConfigEntry))
self.list.append(getConfigListEntry(_('Netmask'), self.netmaskConfigEntry))
self.gatewayEntry = getConfigListEntry(_('Use a gateway'), self.hasGatewayConfigEntry)
self.list.append(self.gatewayEntry)
if self.hasGatewayConfigEntry.value:
self.list.append(getConfigListEntry(_('Gateway'), self.gatewayConfigEntry))
if SystemInfo["WakeOnLAN"] and ((self.iface == 'eth0' and not getBoxType() == 'et10000') or (self.iface == 'eth1' and getBoxType() == 'et10000')):
self.list.append(getConfigListEntry(_('Enable Wake On LAN'), config.network.wol))
self.extended = None
self.configStrings = None
for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
callFnc = p.__call__["ifaceSupported"](self.iface)
if callFnc is not None:
if p.__call__.has_key("WlanPluginEntry"): # internally used only for WLAN Plugin
self.extended = callFnc
if p.__call__.has_key("configStrings"):
self.configStrings = p.__call__["configStrings"]
self.hiddenSSID = getConfigListEntry(_("Hidden network"), config.plugins.wlan.hiddenessid)
self.list.append(self.hiddenSSID)
self.wlanSSID = getConfigListEntry(_("Network name (SSID)"), config.plugins.wlan.essid)
self.list.append(self.wlanSSID)
self.encryption = getConfigListEntry(_("Encryption"), config.plugins.wlan.encryption)
self.list.append(self.encryption)
self.encryptionType = getConfigListEntry(_("Encryption key type"), config.plugins.wlan.wepkeytype)
self.encryptionKey = getConfigListEntry(_("Encryption key"), config.plugins.wlan.psk)
if config.plugins.wlan.encryption.value != "Unencrypted":
if config.plugins.wlan.encryption.value == 'WEP':
self.list.append(self.encryptionType)
self.list.append(self.encryptionKey)
self["config"].list = self.list
self["config"].l.setList(self.list)
def KeyBlue(self):
self.session.openWithCallback(self.NameserverSetupClosed, NameserverSetup)
def newConfig(self):
if self["config"].getCurrent() == self.InterfaceEntry:
self.createSetup()
if self["config"].getCurrent() == self.dhcpEntry:
self.createSetup()
if self["config"].getCurrent() == self.gatewayEntry:
self.createSetup()
if iNetwork.isWirelessInterface(self.iface):
if self["config"].getCurrent() == self.encryption:
self.createSetup()
def keyLeft(self):
ConfigListScreen.keyLeft(self)
self.newConfig()
def keyRight(self):
ConfigListScreen.keyRight(self)
self.newConfig()
def keySave(self):
self.hideInputHelp()
if self["config"].isChanged() or (SystemInfo["WakeOnLAN"] and self.wolstartvalue != config.network.wol.value):
self.session.openWithCallback(self.keySaveConfirm, MessageBox, (_("Are you sure you want to activate this network configuration?\n\n") + self.oktext ) )
else:
if self.finished_cb:
self.finished_cb()
else:
self.close('cancel')
config.network.save()
def keySaveConfirm(self, ret = False):
if ret:
num_configured_if = len(iNetwork.getConfiguredAdapters())
if num_configured_if >= 1:
if self.iface in iNetwork.getConfiguredAdapters():
self.applyConfig(True)
else:
self.session.openWithCallback(self.secondIfaceFoundCB, MessageBox, _("A second configured interface has been found.\n\nDo you want to disable the second network interface?"), default = True)
else:
self.applyConfig(True)
else:
self.keyCancel()
def secondIfaceFoundCB(self, data):
if data is False:
self.applyConfig(True)
else:
configuredInterfaces = iNetwork.getConfiguredAdapters()
for interface in configuredInterfaces:
if interface == self.iface:
continue
iNetwork.setAdapterAttribute(interface, "up", False)
iNetwork.deactivateInterface(configuredInterfaces,self.deactivateSecondInterfaceCB)
def deactivateSecondInterfaceCB(self, data):
if data is True:
self.applyConfig(True)
def applyConfig(self, ret = False):
if ret:
self.applyConfigRef = None
iNetwork.setAdapterAttribute(self.iface, "up", self.activateInterfaceEntry.value)
iNetwork.setAdapterAttribute(self.iface, "dhcp", self.dhcpConfigEntry.value)
iNetwork.setAdapterAttribute(self.iface, "ip", self.ipConfigEntry.value)
iNetwork.setAdapterAttribute(self.iface, "netmask", self.netmaskConfigEntry.value)
if self.hasGatewayConfigEntry.value:
iNetwork.setAdapterAttribute(self.iface, "gateway", self.gatewayConfigEntry.value)
else:
iNetwork.removeAdapterAttribute(self.iface, "gateway")
if self.extended is not None and self.configStrings is not None:
iNetwork.setAdapterAttribute(self.iface, "configStrings", self.configStrings(self.iface))
self.ws.writeConfig(self.iface)
if self.activateInterfaceEntry.value is False:
iNetwork.deactivateInterface(self.iface,self.deactivateInterfaceCB)
iNetwork.writeNetworkConfig()
self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
else:
if self.oldInterfaceState is False:
iNetwork.activateInterface(self.iface,self.deactivateInterfaceCB)
else:
iNetwork.deactivateInterface(self.iface,self.activateInterfaceCB)
iNetwork.writeNetworkConfig()
self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
else:
self.keyCancel()
def deactivateInterfaceCB(self, data):
if data is True:
self.applyConfigDataAvail(True)
def activateInterfaceCB(self, data):
if data is True:
iNetwork.activateInterface(self.iface,self.applyConfigDataAvail)
def applyConfigDataAvail(self, data):
if data is True:
iNetwork.getInterfaces(self.getInterfacesDataAvail)
def getInterfacesDataAvail(self, data):
if data is True:
self.applyConfigRef.close(True)
def applyConfigfinishedCB(self,data):
if data is True:
if self.finished_cb:
self.session.openWithCallback(lambda x : self.finished_cb(), MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
else:
self.session.openWithCallback(self.ConfigfinishedCB, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
def ConfigfinishedCB(self,data):
if data is not None:
if data is True:
self.close('ok')
def keyCancelConfirm(self, result):
if not result:
return
if SystemInfo["WakeOnLAN"]:
config.network.wol.setValue(self.wolstartvalue)
if self.oldInterfaceState is False:
iNetwork.deactivateInterface(self.iface,self.keyCancelCB)
else:
self.close('cancel')
def keyCancel(self):
self.hideInputHelp()
if self["config"].isChanged() or (SystemInfo["WakeOnLAN"] and self.wolstartvalue != config.network.wol.value):
self.session.openWithCallback(self.keyCancelConfirm, MessageBox, _("Really close without saving settings?"), default = False)
else:
self.close('cancel')
def keyCancelCB(self,data):
if data is not None:
if data is True:
self.close('cancel')
def runAsync(self, finished_cb):
self.finished_cb = finished_cb
self.keySave()
def NameserverSetupClosed(self, *ret):
iNetwork.loadNameserverConfig()
nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
self.createSetup()
self.layoutFinished()
def cleanup(self):
iNetwork.stopLinkStateConsole()
def hideInputHelp(self):
current = self["config"].getCurrent()
if current == self.wlanSSID:
if current[1].help_window.instance is not None:
current[1].help_window.instance.hide()
elif current == self.encryptionKey and config.plugins.wlan.encryption.value is not "Unencrypted":
if current[1].help_window.instance is not None:
current[1].help_window.instance.hide()
class AdapterSetupConfiguration(Screen, HelpableScreen):
def __init__(self, session,iface):
Screen.__init__(self, session)
HelpableScreen.__init__(self)
Screen.setTitle(self, _("Network Setup"))
self.session = session
self.iface = iface
self.restartLanRef = None
self.LinkState = None
self.onChangedEntry = [ ]
self.mainmenu = ""
self["menulist"] = MenuList(self.mainmenu)
self["key_red"] = StaticText(_("Close"))
self["description"] = StaticText()
self["IFtext"] = StaticText()
self["IF"] = StaticText()
self["Statustext"] = StaticText()
self["statuspic"] = MultiPixmap()
self["statuspic"].hide()
self.oktext = _("Press OK on your remote control to continue.")
self.reboottext = _("Your STB will restart after pressing OK on your remote control.")
self.errortext = _("No working wireless network interface found.\n Please verify that you have attached a compatible WLAN device or enable your local network interface.")
self.missingwlanplugintxt = _("The wireless LAN plugin is not installed!\nPlease install it.")
self["WizardActions"] = HelpableActionMap(self, "WizardActions",
{
"up": (self.up, _("move up to previous entry")),
"down": (self.down, _("move down to next entry")),
"left": (self.left, _("move up to first entry")),
"right": (self.right, _("move down to last entry")),
})
self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
{
"cancel": (self.close, _("exit networkadapter setup menu")),
"ok": (self.ok, _("select menu entry")),
})
self["ColorActions"] = HelpableActionMap(self, "ColorActions",
{
"red": (self.close, _("exit networkadapter setup menu")),
})
self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
{
"ok": self.ok,
"back": self.close,
"up": self.up,
"down": self.down,
"red": self.close,
"left": self.left,
"right": self.right,
}, -2)
self.updateStatusbar()
self.onClose.append(self.cleanup)
if not self.selectionChanged in self["menulist"].onSelectionChanged:
self["menulist"].onSelectionChanged.append(self.selectionChanged)
self.selectionChanged()
def queryWirelessDevice(self,iface):
try:
from pythonwifi.iwlibs import Wireless
import errno
except ImportError:
return False
else:
try:
ifobj = Wireless(iface) # a Wireless NIC Object
wlanresponse = ifobj.getAPaddr()
except IOError, (error_no, error_str):
if error_no in (errno.EOPNOTSUPP, errno.ENODEV, errno.EPERM):
return False
else:
print "error: ",error_no,error_str
return True
else:
return True
def ok(self):
self.cleanup()
if self["menulist"].getCurrent()[1] == 'edit':
if iNetwork.isWirelessInterface(self.iface):
try:
from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
except ImportError:
self.session.open(MessageBox, self.missingwlanplugintxt, type = MessageBox.TYPE_INFO,timeout = 10 )
else:
if self.queryWirelessDevice(self.iface):
self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
else:
self.showErrorMessage() # Display Wlan not available Message
else:
self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
if self["menulist"].getCurrent()[1] == 'test':
self.session.open(NetworkAdapterTest,self.iface)
if self["menulist"].getCurrent()[1] == 'dns':
self.session.open(NameserverSetup)
if self["menulist"].getCurrent()[1] == 'mac':
self.session.open(NetworkMacSetup)
if self["menulist"].getCurrent()[1] == 'scanwlan':
try:
from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
except ImportError:
self.session.open(MessageBox, self.missingwlanplugintxt, type = MessageBox.TYPE_INFO,timeout = 10 )
else:
if self.queryWirelessDevice(self.iface):
self.session.openWithCallback(self.WlanScanClosed, WlanScan, self.iface)
else:
self.showErrorMessage() # Display Wlan not available Message
if self["menulist"].getCurrent()[1] == 'wlanstatus':
try:
from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
except ImportError:
self.session.open(MessageBox, self.missingwlanplugintxt, type = MessageBox.TYPE_INFO,timeout = 10 )
else:
if self.queryWirelessDevice(self.iface):
self.session.openWithCallback(self.WlanStatusClosed, WlanStatus,self.iface)
else:
self.showErrorMessage() # Display Wlan not available Message
if self["menulist"].getCurrent()[1] == 'lanrestart':
self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
if self["menulist"].getCurrent()[1] == 'openwizard':
from Plugins.SystemPlugins.NetworkWizard.NetworkWizard import NetworkWizard
self.session.openWithCallback(self.AdapterSetupClosed, NetworkWizard, self.iface)
if self["menulist"].getCurrent()[1][0] == 'extendedSetup':
self.extended = self["menulist"].getCurrent()[1][2]
self.extended(self.session, self.iface)
def up(self):
self["menulist"].up()
def down(self):
self["menulist"].down()
def left(self):
self["menulist"].pageUp()
def right(self):
self["menulist"].pageDown()
def createSummary(self):
from Screens.PluginBrowser import PluginBrowserSummary
return PluginBrowserSummary
def selectionChanged(self):
if self["menulist"].getCurrent()[1] == 'edit':
self["description"].setText(_("Edit the network configuration of your %s %s.\n" ) % (getMachineBrand(), getMachineName()) + self.oktext )
if self["menulist"].getCurrent()[1] == 'test':
self["description"].setText(_("Test the network configuration of your %s %s.\n" ) % (getMachineBrand(), getMachineName()) + self.oktext )
if self["menulist"].getCurrent()[1] == 'dns':
self["description"].setText(_("Edit the Nameserver configuration of your %s %s.\n" ) % (getMachineBrand(), getMachineName()) + self.oktext )
if self["menulist"].getCurrent()[1] == 'scanwlan':
self["description"].setText(_("Scan your network for wireless access points and connect to them using your selected wireless device.\n" ) + self.oktext )
if self["menulist"].getCurrent()[1] == 'wlanstatus':
self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
if self["menulist"].getCurrent()[1] == 'lanrestart':
self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
if self["menulist"].getCurrent()[1] == 'openwizard':
self["description"].setText(_("Use the network wizard to configure your Network\n" ) + self.oktext )
if self["menulist"].getCurrent()[1][0] == 'extendedSetup':
self["description"].setText(_(self["menulist"].getCurrent()[1][1]) + self.oktext )
if self["menulist"].getCurrent()[1] == 'mac':
self["description"].setText(_("Set the MAC-address of your %s %s.\n" ) % (getMachineBrand(), getMachineName()) + self.oktext )
item = self["menulist"].getCurrent()
if item:
name = str(self["menulist"].getCurrent()[0])
desc = self["description"].text
else:
name = ""
desc = ""
for cb in self.onChangedEntry:
cb(name, desc)
def updateStatusbar(self, data = None):
self.mainmenu = self.genMainMenu()
self["menulist"].l.setList(self.mainmenu)
self["IFtext"].setText(_("Network:"))
self["IF"].setText(iNetwork.getFriendlyAdapterName(self.iface))
self["Statustext"].setText(_("Link:"))
if iNetwork.isWirelessInterface(self.iface):
try:
from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
except:
self["statuspic"].setPixmapNum(1)
self["statuspic"].show()
else:
iStatus.getDataForInterface(self.iface,self.getInfoCB)
else:
iNetwork.getLinkState(self.iface,self.dataAvail)
def doNothing(self):
pass
def genMainMenu(self):
menu = [(_("Adapter settings"), "edit"), (_("Nameserver settings"), "dns"), (_("Network test"), "test"), (_("Restart network"), "lanrestart")]
self.extended = None
self.extendedSetup = None
for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
callFnc = p.__call__["ifaceSupported"](self.iface)
if callFnc is not None:
self.extended = callFnc
if p.__call__.has_key("WlanPluginEntry"): # internally used only for WLAN Plugin
menu.append((_("Scan wireless networks"), "scanwlan"))
if iNetwork.getAdapterAttribute(self.iface, "up"):
menu.append((_("Show WLAN status"), "wlanstatus"))
else:
if p.__call__.has_key("menuEntryName"):
menuEntryName = p.__call__["menuEntryName"](self.iface)
else:
menuEntryName = _('Extended setup...')
if p.__call__.has_key("menuEntryDescription"):
menuEntryDescription = p.__call__["menuEntryDescription"](self.iface)
else:
menuEntryDescription = _('Extended network setup plugin...')
self.extendedSetup = ('extendedSetup',menuEntryDescription, self.extended)
menu.append((menuEntryName,self.extendedSetup))
if os_path.exists(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkWizard/networkwizard.xml")):
menu.append((_("Network wizard"), "openwizard"))
kernel_ver = about.getKernelVersionString()
if kernel_ver <= "3.5.0":
menu.append((_("Network MAC settings"), "mac"))
return menu
def AdapterSetupClosed(self, *ret):
if ret is not None and len(ret):
if ret[0] == 'ok' and (iNetwork.isWirelessInterface(self.iface) and iNetwork.getAdapterAttribute(self.iface, "up") is True):
try:
from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
except ImportError:
self.session.open(MessageBox, self.missingwlanplugintxt, type = MessageBox.TYPE_INFO,timeout = 10 )
else:
if self.queryWirelessDevice(self.iface):
self.session.openWithCallback(self.WlanStatusClosed, WlanStatus,self.iface)
else:
self.showErrorMessage() # Display Wlan not available Message
else:
self.updateStatusbar()
else:
self.updateStatusbar()
def WlanStatusClosed(self, *ret):
if ret is not None and len(ret):
from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
iStatus.stopWlanConsole()
self.updateStatusbar()
def WlanScanClosed(self,*ret):
if ret[0] is not None:
self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,ret[0])
else:
from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
iStatus.stopWlanConsole()
self.updateStatusbar()
def restartLan(self, ret = False):
if ret:
iNetwork.restartNetwork(self.restartLanDataAvail)
self.restartLanRef = self.session.openWithCallback(self.restartfinishedCB, MessageBox, _("Please wait while your network is restarting..."), type = MessageBox.TYPE_INFO, enable_input = False)
def restartLanDataAvail(self, data):
if data is True:
iNetwork.getInterfaces(self.getInterfacesDataAvail)
def getInterfacesDataAvail(self, data):
if data is True:
self.restartLanRef.close(True)
def restartfinishedCB(self,data):
if data is True:
self.updateStatusbar()
self.session.open(MessageBox, _("Finished restarting your network"), type = MessageBox.TYPE_INFO, timeout = 10, default = False)
def dataAvail(self,data):
self.LinkState = None
for line in data.splitlines():
line = line.strip()
if 'Link detected:' in line:
if "yes" in line:
self.LinkState = True
else:
self.LinkState = False
if self.LinkState:
iNetwork.checkNetworkState(self.checkNetworkCB)
else:
self["statuspic"].setPixmapNum(1)
self["statuspic"].show()
def showErrorMessage(self):
self.session.open(MessageBox, self.errortext, type = MessageBox.TYPE_INFO,timeout = 10 )
def cleanup(self):
iNetwork.stopLinkStateConsole()
iNetwork.stopDeactivateInterfaceConsole()
iNetwork.stopActivateInterfaceConsole()
iNetwork.stopPingConsole()
try:
from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
except ImportError:
pass
else:
iStatus.stopWlanConsole()
def getInfoCB(self,data,status):
self.LinkState = None
if data is not None:
if data is True:
if status is not None:
if status[self.iface]["essid"] == "off" or status[self.iface]["accesspoint"] == "Not-Associated" or status[self.iface]["accesspoint"] == False:
self.LinkState = False
self["statuspic"].setPixmapNum(1)
self["statuspic"].show()
else:
self.LinkState = True
iNetwork.checkNetworkState(self.checkNetworkCB)
def checkNetworkCB(self,data):
if iNetwork.getAdapterAttribute(self.iface, "up") is True:
if self.LinkState is True:
if data <= 2:
self["statuspic"].setPixmapNum(0)
else:
self["statuspic"].setPixmapNum(1)
self["statuspic"].show()
else:
self["statuspic"].setPixmapNum(1)
self["statuspic"].show()
else:
self["statuspic"].setPixmapNum(1)
self["statuspic"].show()
class NetworkAdapterTest(Screen):
def __init__(self, session,iface):
Screen.__init__(self, session)
Screen.setTitle(self, _("Network Test"))
self.iface = iface
self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
self.setLabels()
self.onClose.append(self.cleanup)
self.onHide.append(self.cleanup)
self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
{
"ok": self.KeyOK,
"blue": self.KeyOK,
"up": lambda: self.updownhandler('up'),
"down": lambda: self.updownhandler('down'),
}, -2)
self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
{
"red": self.cancel,
"back": self.cancel,
}, -2)
self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
{
"red": self.closeInfo,
"back": self.closeInfo,
}, -2)
self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
{
"green": self.KeyGreen,
}, -2)
self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
{
"green": self.KeyGreenRestart,
}, -2)
self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
{
"yellow": self.KeyYellow,
}, -2)
self["shortcutsgreen_restart"].setEnabled(False)
self["updown_actions"].setEnabled(False)
self["infoshortcuts"].setEnabled(False)
self.onClose.append(self.delTimer)
self.onLayoutFinish.append(self.layoutFinished)
self.steptimer = False
self.nextstep = 0
self.activebutton = 0
self.nextStepTimer = eTimer()
self.nextStepTimer.callback.append(self.nextStepTimerFire)
def cancel(self):
if self.oldInterfaceState is False:
iNetwork.setAdapterAttribute(self.iface, "up", self.oldInterfaceState)
iNetwork.deactivateInterface(self.iface)
self.close()
def closeInfo(self):
self["shortcuts"].setEnabled(True)
self["infoshortcuts"].setEnabled(False)
self["InfoText"].hide()
self["InfoTextBorder"].hide()
self["key_red"].setText(_("Close"))
def delTimer(self):
del self.steptimer
del self.nextStepTimer
def nextStepTimerFire(self):
self.nextStepTimer.stop()
self.steptimer = False
self.runTest()
def updownhandler(self,direction):
if direction == 'up':
if self.activebutton >=2:
self.activebutton -= 1
else:
self.activebutton = 6
self.setActiveButton(self.activebutton)
if direction == 'down':
if self.activebutton <=5:
self.activebutton += 1
else:
self.activebutton = 1
self.setActiveButton(self.activebutton)
def setActiveButton(self,button):
if button == 1:
self["EditSettingsButton"].setPixmapNum(0)
self["EditSettings_Text"].setForegroundColorNum(0)
self["NetworkInfo"].setPixmapNum(0)
self["NetworkInfo_Text"].setForegroundColorNum(1)
self["AdapterInfo"].setPixmapNum(1) # active
self["AdapterInfo_Text"].setForegroundColorNum(2) # active
if button == 2:
self["AdapterInfo_Text"].setForegroundColorNum(1)
self["AdapterInfo"].setPixmapNum(0)
self["DhcpInfo"].setPixmapNum(0)
self["DhcpInfo_Text"].setForegroundColorNum(1)
self["NetworkInfo"].setPixmapNum(1) # active
self["NetworkInfo_Text"].setForegroundColorNum(2) # active
if button == 3:
self["NetworkInfo"].setPixmapNum(0)
self["NetworkInfo_Text"].setForegroundColorNum(1)
self["IPInfo"].setPixmapNum(0)
self["IPInfo_Text"].setForegroundColorNum(1)
self["DhcpInfo"].setPixmapNum(1) # active
self["DhcpInfo_Text"].setForegroundColorNum(2) # active
if button == 4:
self["DhcpInfo"].setPixmapNum(0)
self["DhcpInfo_Text"].setForegroundColorNum(1)
self["DNSInfo"].setPixmapNum(0)
self["DNSInfo_Text"].setForegroundColorNum(1)
self["IPInfo"].setPixmapNum(1) # active
self["IPInfo_Text"].setForegroundColorNum(2) # active
if button == 5:
self["IPInfo"].setPixmapNum(0)
self["IPInfo_Text"].setForegroundColorNum(1)
self["EditSettingsButton"].setPixmapNum(0)
self["EditSettings_Text"].setForegroundColorNum(0)
self["DNSInfo"].setPixmapNum(1) # active
self["DNSInfo_Text"].setForegroundColorNum(2) # active
if button == 6:
self["DNSInfo"].setPixmapNum(0)
self["DNSInfo_Text"].setForegroundColorNum(1)
self["EditSettingsButton"].setPixmapNum(1) # active
self["EditSettings_Text"].setForegroundColorNum(2) # active
self["AdapterInfo"].setPixmapNum(0)
self["AdapterInfo_Text"].setForegroundColorNum(1)
def runTest(self):
next = self.nextstep
if next == 0:
self.doStep1()
elif next == 1:
self.doStep2()
elif next == 2:
self.doStep3()
elif next == 3:
self.doStep4()
elif next == 4:
self.doStep5()
elif next == 5:
self.doStep6()
self.nextstep += 1
def doStep1(self):
self.steptimer = True
self.nextStepTimer.start(300)
self["key_yellow"].setText(_("Stop test"))
def doStep2(self):
self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
self["Adapter"].setForegroundColorNum(2)
self["Adaptertext"].setForegroundColorNum(1)
self["AdapterInfo_Text"].setForegroundColorNum(1)
self["AdapterInfo_OK"].show()
self.steptimer = True
self.nextStepTimer.start(300)
def doStep3(self):
self["Networktext"].setForegroundColorNum(1)
self["Network"].setText(_("Please wait..."))
self.getLinkState(self.iface)
self["NetworkInfo_Text"].setForegroundColorNum(1)
self.steptimer = True
self.nextStepTimer.start(1000)
def doStep4(self):
self["Dhcptext"].setForegroundColorNum(1)
if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
self["Dhcp"].setForegroundColorNum(2)
self["Dhcp"].setText(_("enabled"))
self["DhcpInfo_Check"].setPixmapNum(0)
else:
self["Dhcp"].setForegroundColorNum(1)
self["Dhcp"].setText(_("disabled"))
self["DhcpInfo_Check"].setPixmapNum(1)
self["DhcpInfo_Check"].show()
self["DhcpInfo_Text"].setForegroundColorNum(1)
self.steptimer = True
self.nextStepTimer.start(1000)
def doStep5(self):
self["IPtext"].setForegroundColorNum(1)
self["IP"].setText(_("Please wait..."))
iNetwork.checkNetworkState(self.NetworkStatedataAvail)
def doStep6(self):
self.steptimer = False
self.nextStepTimer.stop()
self["DNStext"].setForegroundColorNum(1)
self["DNS"].setText(_("Please wait..."))
iNetwork.checkDNSLookup(self.DNSLookupdataAvail)
def KeyGreen(self):
self["shortcutsgreen"].setEnabled(False)
self["shortcutsyellow"].setEnabled(True)
self["updown_actions"].setEnabled(False)
self["key_yellow"].setText("")
self["key_green"].setText("")
self.steptimer = True
self.nextStepTimer.start(1000)
def KeyGreenRestart(self):
self.nextstep = 0
self.layoutFinished()
self["Adapter"].setText("")
self["Network"].setText("")
self["Dhcp"].setText("")
self["IP"].setText("")
self["DNS"].setText("")
self["AdapterInfo_Text"].setForegroundColorNum(0)
self["NetworkInfo_Text"].setForegroundColorNum(0)
self["DhcpInfo_Text"].setForegroundColorNum(0)
self["IPInfo_Text"].setForegroundColorNum(0)
self["DNSInfo_Text"].setForegroundColorNum(0)
self["shortcutsgreen_restart"].setEnabled(False)
self["shortcutsgreen"].setEnabled(False)
self["shortcutsyellow"].setEnabled(True)
self["updown_actions"].setEnabled(False)
self["key_yellow"].setText("")
self["key_green"].setText("")
self.steptimer = True
self.nextStepTimer.start(1000)
def KeyOK(self):
self["infoshortcuts"].setEnabled(True)
self["shortcuts"].setEnabled(False)
if self.activebutton == 1: # Adapter Check
self["InfoText"].setText(_("This test detects your configured LAN adapter."))
self["InfoTextBorder"].show()
self["InfoText"].show()
self["key_red"].setText(_("Back"))
if self.activebutton == 2: #LAN Check
self["InfoText"].setText(_("This test checks whether a network cable is connected to your LAN adapter.\nIf you get a \"disconnected\" message:\n- verify that a network cable is attached\n- verify that the cable is not broken"))
self["InfoTextBorder"].show()
self["InfoText"].show()
self["key_red"].setText(_("Back"))
if self.activebutton == 3: #DHCP Check
self["InfoText"].setText(_("This test checks whether your LAN adapter is set up for automatic IP address configuration with DHCP.\nIf you get a \"disabled\" message:\n - then your LAN adapter is configured for manual IP setup\n- verify thay you have entered correct IP informations in the adapter setup dialog.\nIf you get an \"enabled\" message:\n-verify that you have a configured and working DHCP server in your network."))
self["InfoTextBorder"].show()
self["InfoText"].show()
self["key_red"].setText(_("Back"))
if self.activebutton == 4: # IP Check
self["InfoText"].setText(_("This test checks whether a valid IP address is found for your LAN adapter.\nIf you get a \"unconfirmed\" message:\n- no valid IP address was found\n- please check your DHCP, cabling and adapter setup"))
self["InfoTextBorder"].show()
self["InfoText"].show()
self["key_red"].setText(_("Back"))
if self.activebutton == 5: # DNS Check
self["InfoText"].setText(_("This test checks for configured nameservers.\nIf you get a \"unconfirmed\" message:\n- please check your DHCP, cabling and adapter setup\n- if you configured your nameservers manually please verify your entries in the \"Nameserver\" configuration"))
self["InfoTextBorder"].show()
self["InfoText"].show()
self["key_red"].setText(_("Back"))
if self.activebutton == 6: # Edit Settings
self.session.open(AdapterSetup,self.iface)
def KeyYellow(self):
self.nextstep = 0
self["shortcutsgreen_restart"].setEnabled(True)
self["shortcutsgreen"].setEnabled(False)
self["shortcutsyellow"].setEnabled(False)
self["key_green"].setText(_("Restart test"))
self["key_yellow"].setText("")
self.steptimer = False
self.nextStepTimer.stop()
def layoutFinished(self):
self.setTitle(_("Network test: ") + iNetwork.getFriendlyAdapterName(self.iface) )
self["shortcutsyellow"].setEnabled(False)
self["AdapterInfo_OK"].hide()
self["NetworkInfo_Check"].hide()
self["DhcpInfo_Check"].hide()
self["IPInfo_Check"].hide()
self["DNSInfo_Check"].hide()
self["EditSettings_Text"].hide()
self["EditSettingsButton"].hide()
self["InfoText"].hide()
self["InfoTextBorder"].hide()
self["key_yellow"].setText("")
def setLabels(self):
self["Adaptertext"] = MultiColorLabel(_("LAN adapter"))
self["Adapter"] = MultiColorLabel()
self["AdapterInfo"] = MultiPixmap()
self["AdapterInfo_Text"] = MultiColorLabel(_("Show info"))
self["AdapterInfo_OK"] = Pixmap()
if self.iface in iNetwork.wlan_interfaces:
self["Networktext"] = MultiColorLabel(_("Wireless network"))
else:
self["Networktext"] = MultiColorLabel(_("Local network"))
self["Network"] = MultiColorLabel()
self["NetworkInfo"] = MultiPixmap()
self["NetworkInfo_Text"] = MultiColorLabel(_("Show info"))
self["NetworkInfo_Check"] = MultiPixmap()
self["Dhcptext"] = MultiColorLabel(_("DHCP"))
self["Dhcp"] = MultiColorLabel()
self["DhcpInfo"] = MultiPixmap()
self["DhcpInfo_Text"] = MultiColorLabel(_("Show info"))
self["DhcpInfo_Check"] = MultiPixmap()
self["IPtext"] = MultiColorLabel(_("IP address"))
self["IP"] = MultiColorLabel()
self["IPInfo"] = MultiPixmap()
self["IPInfo_Text"] = MultiColorLabel(_("Show info"))
self["IPInfo_Check"] = MultiPixmap()
self["DNStext"] = MultiColorLabel(_("Nameserver"))
self["DNS"] = MultiColorLabel()
self["DNSInfo"] = MultiPixmap()
self["DNSInfo_Text"] = MultiColorLabel(_("Show info"))
self["DNSInfo_Check"] = MultiPixmap()
self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
self["EditSettingsButton"] = MultiPixmap()
self["key_red"] = StaticText(_("Close"))
self["key_green"] = StaticText(_("Start test"))
self["key_yellow"] = StaticText(_("Stop test"))
self["InfoTextBorder"] = Pixmap()
self["InfoText"] = Label()
def getLinkState(self,iface):
if iface in iNetwork.wlan_interfaces:
try:
from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
except:
self["Network"].setForegroundColorNum(1)
self["Network"].setText(_("disconnected"))
self["NetworkInfo_Check"].setPixmapNum(1)
self["NetworkInfo_Check"].show()
else:
iStatus.getDataForInterface(self.iface,self.getInfoCB)
else:
iNetwork.getLinkState(iface,self.LinkStatedataAvail)
def LinkStatedataAvail(self,data):
for item in data.splitlines():
if "Link detected:" in item:
if "yes" in item:
self["Network"].setForegroundColorNum(2)
self["Network"].setText(_("connected"))
self["NetworkInfo_Check"].setPixmapNum(0)
else:
self["Network"].setForegroundColorNum(1)
self["Network"].setText(_("disconnected"))
self["NetworkInfo_Check"].setPixmapNum(1)
break
else:
self["Network"].setText(_("unknown"))
self["NetworkInfo_Check"].show()
def NetworkStatedataAvail(self,data):
if data <= 2:
self["IP"].setForegroundColorNum(2)
self["IP"].setText(_("confirmed"))
self["IPInfo_Check"].setPixmapNum(0)
else:
self["IP"].setForegroundColorNum(1)
self["IP"].setText(_("unconfirmed"))
self["IPInfo_Check"].setPixmapNum(1)
self["IPInfo_Check"].show()
self["IPInfo_Text"].setForegroundColorNum(1)
self.steptimer = True
self.nextStepTimer.start(300)
def DNSLookupdataAvail(self,data):
if data <= 2:
self["DNS"].setForegroundColorNum(2)
self["DNS"].setText(_("confirmed"))
self["DNSInfo_Check"].setPixmapNum(0)
else:
self["DNS"].setForegroundColorNum(1)
self["DNS"].setText(_("unconfirmed"))
self["DNSInfo_Check"].setPixmapNum(1)
self["DNSInfo_Check"].show()
self["DNSInfo_Text"].setForegroundColorNum(1)
self["EditSettings_Text"].show()
self["EditSettingsButton"].setPixmapNum(1)
self["EditSettings_Text"].setForegroundColorNum(2) # active
self["EditSettingsButton"].show()
self["key_yellow"].setText("")
self["key_green"].setText(_("Restart test"))
self["shortcutsgreen"].setEnabled(False)
self["shortcutsgreen_restart"].setEnabled(True)
self["shortcutsyellow"].setEnabled(False)
self["updown_actions"].setEnabled(True)
self.activebutton = 6
def getInfoCB(self,data,status):
if data is not None:
if data is True:
if status is not None:
if status[self.iface]["essid"] == "off" or status[self.iface]["accesspoint"] == "Not-Associated" or status[self.iface]["accesspoint"] == False:
self["Network"].setForegroundColorNum(1)
self["Network"].setText(_("disconnected"))
self["NetworkInfo_Check"].setPixmapNum(1)
self["NetworkInfo_Check"].show()
else:
self["Network"].setForegroundColorNum(2)
self["Network"].setText(_("connected"))
self["NetworkInfo_Check"].setPixmapNum(0)
self["NetworkInfo_Check"].show()
def cleanup(self):
iNetwork.stopLinkStateConsole()
iNetwork.stopDNSConsole()
try:
from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
except ImportError:
pass
else:
iStatus.stopWlanConsole()
class NetworkMountsMenu(Screen,HelpableScreen):
def __init__(self, session):
Screen.__init__(self, session)
HelpableScreen.__init__(self)
Screen.setTitle(self, _("Mounts Setup"))
self.session = session
self.onChangedEntry = [ ]
self.mainmenu = self.genMainMenu()
self["menulist"] = MenuList(self.mainmenu)
self["key_red"] = StaticText(_("Close"))
self["introduction"] = StaticText()
self["WizardActions"] = HelpableActionMap(self, "WizardActions",
{
"up": (self.up, _("move up to previous entry")),
"down": (self.down, _("move down to next entry")),
"left": (self.left, _("move up to first entry")),
"right": (self.right, _("move down to last entry")),
})
self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
{
"cancel": (self.close, _("exit mounts setup menu")),
"ok": (self.ok, _("select menu entry")),
})
self["ColorActions"] = HelpableActionMap(self, "ColorActions",
{
"red": (self.close, _("exit networkadapter setup menu")),
})
self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
{
"ok": self.ok,
"back": self.close,
"up": self.up,
"down": self.down,
"red": self.close,
"left": self.left,
"right": self.right,
}, -2)
if not self.selectionChanged in self["menulist"].onSelectionChanged:
self["menulist"].onSelectionChanged.append(self.selectionChanged)
self.selectionChanged()
def createSummary(self):
from Screens.PluginBrowser import PluginBrowserSummary
return PluginBrowserSummary
def selectionChanged(self):
item = self["menulist"].getCurrent()
if item:
if item[1][0] == 'extendedSetup':
self["introduction"].setText(_(item[1][1]))
name = str(self["menulist"].getCurrent()[0])
desc = self["introduction"].text
else:
name = ""
desc = ""
for cb in self.onChangedEntry:
cb(name, desc)
def ok(self):
if self["menulist"].getCurrent()[1][0] == 'extendedSetup':
self.extended = self["menulist"].getCurrent()[1][2]
self.extended(self.session)
def up(self):
self["menulist"].up()
def down(self):
self["menulist"].down()
def left(self):
self["menulist"].pageUp()
def right(self):
self["menulist"].pageDown()
def genMainMenu(self):
menu = []
self.extended = None
self.extendedSetup = None
for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKMOUNTS):
callFnc = p.__call__["ifaceSupported"](self)
if callFnc is not None:
self.extended = callFnc
if p.__call__.has_key("menuEntryName"):
menuEntryName = p.__call__["menuEntryName"](self)
else:
menuEntryName = _('Extended Setup...')
if p.__call__.has_key("menuEntryDescription"):
menuEntryDescription = p.__call__["menuEntryDescription"](self)
else:
menuEntryDescription = _('Extended Networksetup Plugin...')
self.extendedSetup = ('extendedSetup',menuEntryDescription, self.extended)
menu.append((menuEntryName,self.extendedSetup))
return menu
class NetworkAfp(Screen):
def __init__(self, session):
Screen.__init__(self, session)
Screen.setTitle(self, _("AFP Setup"))
self.skinName = "NetworkServiceSetup"
self.onChangedEntry = [ ]
self['lab1'] = Label(_("Autostart:"))
self['labactive'] = Label(_(_("Disabled")))
self['lab2'] = Label(_("Current Status:"))
self['labstop'] = Label(_("Stopped"))
self['labrun'] = Label(_("Running"))
self['key_red'] = Label(_("Remove Service"))
self['key_green'] = Label(_("Start"))
self['key_yellow'] = Label(_("Autostart"))
self['key_blue'] = Label()
self['status_summary'] = StaticText()
self['autostartstatus_summary'] = StaticText()
self.Console = Console()
self.my_afp_active = False
self.my_afp_run = False
self['actions'] = ActionMap(['WizardActions', 'ColorActions'], {'ok': self.close, 'back': self.close, 'red': self.UninstallCheck, 'green': self.AfpStartStop, 'yellow': self.activateAfp})
self.service_name = 'packagegroup-base-appletalk netatalk'
self.onLayoutFinish.append(self.InstallCheck)
def InstallCheck(self):
self.Console.ePopen('/usr/bin/opkg list_installed ' + self.service_name, self.checkNetworkState)
def checkNetworkState(self, str, retval, extra_args):
if 'Collected errors' in str:
self.session.openWithCallback(self.close, MessageBox, _("A background update check is in progress, please wait a few minutes and try again."), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
elif not str:
self.feedscheck = self.session.open(MessageBox,_('Please wait whilst feeds state is checked.'), MessageBox.TYPE_INFO, enable_input = False)
self.feedscheck.setTitle(_('Checking Feeds'))
cmd1 = "opkg update"
self.CheckConsole = Console()
self.CheckConsole.ePopen(cmd1, self.checkNetworkStateFinished)
else:
self.updateService()
def checkNetworkStateFinished(self, result, retval,extra_args=None):
if 'bad address' in result:
self.session.openWithCallback(self.InstallPackageFailed, MessageBox, _("Your %s %s is not connected to the internet, please check your network settings and try again.") % (getMachineBrand(), getMachineName()), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
elif ('wget returned 1' or 'wget returned 255' or '404 Not Found') in result:
self.session.openWithCallback(self.InstallPackageFailed, MessageBox, _("Sorry feeds are down for maintenance, please try again later."), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
else:
self.session.openWithCallback(self.InstallPackage,MessageBox,_('Your %s %s will be restarted after the installation of service\nReady to install "%s" ?') % (getMachineBrand(), getMachineName(), self.service_name), MessageBox.TYPE_YESNO)
def InstallPackage(self, val):
if val:
self.doInstall(self.installComplete, self.service_name)
else:
self.feedscheck.close()
self.close()
def InstallPackageFailed(self, val):
self.feedscheck.close()
self.close()
def doInstall(self, callback, pkgname):
self.message = self.session.open(MessageBox,_("please wait..."), MessageBox.TYPE_INFO, enable_input = False)
self.message.setTitle(_('Installing Service'))
self.Console.ePopen('/usr/bin/opkg install ' + pkgname, callback)
def installComplete(self,result = None, retval = None, extra_args = None):
self.session.open(TryQuitMainloop, 2)
def UninstallCheck(self):
self.Console.ePopen('/usr/bin/opkg list_installed ' + self.service_name, self.RemovedataAvail)
def RemovedataAvail(self, str, retval, extra_args):
if str:
restartbox = self.session.openWithCallback(self.RemovePackage,MessageBox,_('Your %s %s will be restarted after the removal of service\nDo you want to remove now ?') % (getMachineBrand(), getMachineName()), MessageBox.TYPE_YESNO)
restartbox.setTitle(_('Ready to remove "%s" ?') % self.service_name)
else:
self.updateService()
def RemovePackage(self, val):
if val:
self.doRemove(self.removeComplete, self.service_name)
def doRemove(self, callback, pkgname):
self.message = self.session.open(MessageBox,_("please wait..."), MessageBox.TYPE_INFO, enable_input = False)
self.message.setTitle(_('Removing Service'))
self.Console.ePopen('/usr/bin/opkg remove ' + pkgname + ' --force-remove --autoremove', callback)
def removeComplete(self,result = None, retval = None, extra_args = None):
self.session.open(TryQuitMainloop, 2)
def createSummary(self):
return NetworkServicesSummary
def AfpStartStop(self):
if not self.my_afp_run:
self.Console.ePopen('/etc/init.d/atalk start', self.StartStopCallback)
elif self.my_afp_run:
self.Console.ePopen('/etc/init.d/atalk stop', self.StartStopCallback)
def StartStopCallback(self, result = None, retval = None, extra_args = None):
time.sleep(3)
self.updateService()
def activateAfp(self):
if fileExists('/etc/rc2.d/S20atalk'):
self.Console.ePopen('update-rc.d -f atalk remove', self.StartStopCallback)
else:
self.Console.ePopen('update-rc.d -f atalk defaults', self.StartStopCallback)
def updateService(self,result = None, retval = None, extra_args = None):
import process
p = process.ProcessList()
afp_process = str(p.named('afpd')).strip('[]')
self['labrun'].hide()
self['labstop'].hide()
self['labactive'].setText(_("Disabled"))
self.my_afp_active = False
self.my_afp_run = False
if fileExists('/etc/rc2.d/S20atalk'):
self['labactive'].setText(_("Enabled"))
self['labactive'].show()
self.my_afp_active = True
if afp_process:
self.my_afp_run = True
if self.my_afp_run:
self['labstop'].hide()
self['labactive'].show()
self['labrun'].show()
self['key_green'].setText(_("Stop"))
status_summary= self['lab2'].text + ' ' + self['labrun'].text
else:
self['labrun'].hide()
self['labstop'].show()
self['labactive'].show()
self['key_green'].setText(_("Start"))
status_summary= self['lab2'].text + ' ' + self['labstop'].text
title = _("AFP Setup")
autostartstatus_summary = self['lab1'].text + ' ' + self['labactive'].text
for cb in self.onChangedEntry:
cb(title, status_summary, autostartstatus_summary)
class NetworkFtp(Screen):
def __init__(self, session):
Screen.__init__(self, session)
Screen.setTitle(self, _("FTP Setup"))
self.onChangedEntry = [ ]
self['lab1'] = Label(_("Ftpd service type: Vsftpd server"))
self['lab2'] = Label(_("Current Status:"))
self['labstop'] = Label(_("Stopped"))
self['labrun'] = Label(_("Running"))
self['key_green'] = Label(_("Enable"))
self['key_red'] = Label()
self.my_ftp_active = False
self.Console = Console()
self['actions'] = ActionMap(['WizardActions', 'ColorActions'], {'ok': self.close, 'back': self.close, 'green': self.FtpStartStop})
self.onLayoutFinish.append(self.updateService)
def createSummary(self):
return NetworkServicesSummary
def FtpStartStop(self):
if not self.my_ftp_active:
if fileExists('/etc/inetd.conf'):
inme = open('/etc/inetd.conf', 'r')
out = open('/etc/inetd.tmp', 'w')
for line in inme.readlines():
if 'vsftpd' in line:
line = line.replace('#', '')
out.write(line)
out.close()
inme.close()
if fileExists('/etc/inetd.tmp'):
move('/etc/inetd.tmp', '/etc/inetd.conf')
self.Console.ePopen('killall -HUP inetd')
self.updateService()
elif self.my_ftp_active:
if fileExists('/etc/inetd.conf'):
inme = open('/etc/inetd.conf', 'r')
out = open('/etc/inetd.tmp', 'w')
for line in inme.readlines():
if 'vsftpd' in line:
line = '#' + line
out.write(line)
out.close()
inme.close()
if fileExists('/etc/inetd.tmp'):
move('/etc/inetd.tmp', '/etc/inetd.conf')
self.Console.ePopen('killall -HUP inetd')
self.updateService()
def updateService(self):
self['labrun'].hide()
self['labstop'].hide()
self.my_ftp_active = False
if fileExists('/etc/inetd.conf'):
f = open('/etc/inetd.conf', 'r')
for line in f.readlines():
parts = line.strip().split()
if parts[0] == 'ftp':
self.my_ftp_active = True
continue
f.close()
if self.my_ftp_active:
self['labstop'].hide()
self['labrun'].show()
self['key_green'].setText(_("Disable"))
status_summary= self['lab2'].text + ' ' + self['labrun'].text
else:
self['labstop'].show()
self['labrun'].hide()
self['key_green'].setText(_("Enable"))
status_summary= self['lab2'].text + ' ' + self['labstop'].text
title = _("FTP Setup")
autostartstatus_summary = ""
for cb in self.onChangedEntry:
cb(title, status_summary, autostartstatus_summary)
class NetworkNfs(Screen):
def __init__(self, session):
Screen.__init__(self, session)
Screen.setTitle(self, _("NFS Setup"))
self.skinName = "NetworkServiceSetup"
self.onChangedEntry = [ ]
self['lab1'] = Label(_("Autostart:"))
self['labactive'] = Label(_(_("Disabled")))
self['lab2'] = Label(_("Current Status:"))
self['labstop'] = Label(_("Stopped"))
self['labrun'] = Label(_("Running"))
self['key_green'] = Label(_("Start"))
self['key_red'] = Label(_("Remove Service"))
self['key_yellow'] = Label(_("Autostart"))
self['key_blue'] = Label()
self.Console = Console()
self.my_nfs_active = False
self.my_nfs_run = False
self['actions'] = ActionMap(['WizardActions', 'ColorActions'], {'ok': self.close, 'back': self.close, 'red': self.UninstallCheck, 'green': self.NfsStartStop, 'yellow': self.Nfsset})
self.service_name = 'packagegroup-base-nfs'
self.onLayoutFinish.append(self.InstallCheck)
def InstallCheck(self):
self.Console.ePopen('/usr/bin/opkg list_installed ' + self.service_name, self.checkNetworkState)
def checkNetworkState(self, str, retval, extra_args):
if 'Collected errors' in str:
self.session.openWithCallback(self.close, MessageBox, _("A background update check is in progress, please wait a few minutes and try again."), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
elif not str:
self.feedscheck = self.session.open(MessageBox,_('Please wait whilst feeds state is checked.'), MessageBox.TYPE_INFO, enable_input = False)
self.feedscheck.setTitle(_('Checking Feeds'))
cmd1 = "opkg update"
self.CheckConsole = Console()
self.CheckConsole.ePopen(cmd1, self.checkNetworkStateFinished)
else:
self.updateService()
def checkNetworkStateFinished(self, result, retval,extra_args=None):
if 'bad address' in result:
self.session.openWithCallback(self.InstallPackageFailed, MessageBox, _("Your %s %s is not connected to the internet, please check your network settings and try again.") % (getMachineBrand(), getMachineName()), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
elif ('wget returned 1' or 'wget returned 255' or '404 Not Found') in result:
self.session.openWithCallback(self.InstallPackageFailed, MessageBox, _("Sorry feeds are down for maintenance, please try again later."), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
else:
self.session.openWithCallback(self.InstallPackage,MessageBox,_('Your %s %s will be restarted after the installation of service\nReady to install "%s" ?') % (getMachineBrand(), getMachineName(), self.service_name), MessageBox.TYPE_YESNO)
def InstallPackage(self, val):
if val:
self.doInstall(self.installComplete, self.service_name)
else:
self.feedscheck.close()
self.close()
def InstallPackageFailed(self, val):
self.feedscheck.close()
self.close()
def doInstall(self, callback, pkgname):
self.message = self.session.open(MessageBox,_("please wait..."), MessageBox.TYPE_INFO, enable_input = False)
self.message.setTitle(_('Installing Service'))
self.Console.ePopen('/usr/bin/opkg install ' + pkgname, callback)
def installComplete(self,result = None, retval = None, extra_args = None):
self.session.open(TryQuitMainloop, 2)
def UninstallCheck(self):
self.Console.ePopen('/usr/bin/opkg list_installed ' + self.service_name, self.RemovedataAvail)
def RemovedataAvail(self, str, retval, extra_args):
if str:
restartbox = self.session.openWithCallback(self.RemovePackage,MessageBox,_('Your %s %s will be restarted after the removal of service\nDo you want to remove now ?') % (getMachineBrand(), getMachineName()), MessageBox.TYPE_YESNO)
restartbox.setTitle(_('Ready to remove "%s" ?') % self.service_name)
else:
self.updateService()
def RemovePackage(self, val):
if val:
self.doRemove(self.removeComplete, self.service_name)
def doRemove(self, callback, pkgname):
self.message = self.session.open(MessageBox,_("please wait..."), MessageBox.TYPE_INFO, enable_input = False)
self.message.setTitle(_('Removing Service'))
self.Console.ePopen('/usr/bin/opkg remove ' + pkgname + ' --force-remove --autoremove', callback)
def removeComplete(self,result = None, retval = None, extra_args = None):
self.session.open(TryQuitMainloop, 2)
def createSummary(self):
return NetworkServicesSummary
def NfsStartStop(self):
if not self.my_nfs_run:
self.Console.ePopen('/etc/init.d/nfsserver start', self.StartStopCallback)
elif self.my_nfs_run:
self.Console.ePopen('/etc/init.d/nfsserver stop', self.StartStopCallback)
def StartStopCallback(self, result = None, retval = None, extra_args = None):
time.sleep(3)
self.updateService()
def Nfsset(self):
if fileExists('/etc/rc2.d/S11nfsserver'):
self.Console.ePopen('update-rc.d -f nfsserver remove', self.StartStopCallback)
else:
self.Console.ePopen('update-rc.d -f nfsserver defaults 11', self.StartStopCallback)
def updateService(self):
import process
p = process.ProcessList()
nfs_process = str(p.named('nfsd')).strip('[]')
self['labrun'].hide()
self['labstop'].hide()
self['labactive'].setText(_("Disabled"))
self.my_nfs_active = False
self.my_nfs_run = False
if fileExists('/etc/rc2.d/S11nfsserver'):
self['labactive'].setText(_("Enabled"))
self['labactive'].show()
self.my_nfs_active = True
if nfs_process:
self.my_nfs_run = True
if self.my_nfs_run:
self['labstop'].hide()
self['labrun'].show()
self['key_green'].setText(_("Stop"))
status_summary= self['lab2'].text + ' ' + self['labrun'].text
else:
self['labstop'].show()
self['labrun'].hide()
self['key_green'].setText(_("Start"))
status_summary= self['lab2'].text + ' ' + self['labstop'].text
title = _("NFS Setup")
autostartstatus_summary = self['lab1'].text + ' ' + self['labactive'].text
for cb in self.onChangedEntry:
cb(title, status_summary, autostartstatus_summary)
class NetworkOpenvpn(Screen):
def __init__(self, session):
Screen.__init__(self, session)
Screen.setTitle(self, _("OpenVpn Setup"))
self.skinName = "NetworkServiceSetup"
self.onChangedEntry = [ ]
self['lab1'] = Label(_("Autostart:"))
self['labactive'] = Label(_(_("Disabled")))
self['lab2'] = Label(_("Current Status:"))
self['labstop'] = Label(_("Stopped"))
self['labrun'] = Label(_("Running"))
self['key_green'] = Label(_("Start"))
self['key_red'] = Label(_("Remove Service"))
self['key_yellow'] = Label(_("Autostart"))
self['key_blue'] = Label(_("Show Log"))
self.Console = Console()
self.my_vpn_active = False
self.my_vpn_run = False
self['actions'] = ActionMap(['WizardActions', 'ColorActions'], {'ok': self.close, 'back': self.close, 'red': self.UninstallCheck, 'green': self.VpnStartStop, 'yellow': self.activateVpn, 'blue': self.Vpnshowlog})
self.service_name = 'openvpn'
self.onLayoutFinish.append(self.InstallCheck)
def InstallCheck(self):
self.Console.ePopen('/usr/bin/opkg list_installed ' + self.service_name, self.checkNetworkState)
def checkNetworkState(self, str, retval, extra_args):
if 'Collected errors' in str:
self.session.openWithCallback(self.close, MessageBox, _("A background update check is in progress, please wait a few minutes and try again."), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
elif not str:
self.feedscheck = self.session.open(MessageBox,_('Please wait whilst feeds state is checked.'), MessageBox.TYPE_INFO, enable_input = False)
self.feedscheck.setTitle(_('Checking Feeds'))
cmd1 = "opkg update"
self.CheckConsole = Console()
self.CheckConsole.ePopen(cmd1, self.checkNetworkStateFinished)
else:
self.updateService()
def checkNetworkStateFinished(self, result, retval,extra_args=None):
if 'bad address' in result:
self.session.openWithCallback(self.InstallPackageFailed, MessageBox, _("Your %s %s is not connected to the internet, please check your network settings and try again.") % (getMachineBrand(), getMachineName()), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
elif ('wget returned 1' or 'wget returned 255' or '404 Not Found') in result:
self.session.openWithCallback(self.InstallPackageFailed, MessageBox, _("Sorry feeds are down for maintenance, please try again later."), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
else:
self.session.openWithCallback(self.InstallPackage, MessageBox, _('Ready to install "%s" ?') % self.service_name, MessageBox.TYPE_YESNO)
def InstallPackage(self, val):
if val:
self.doInstall(self.installComplete, self.service_name)
else:
self.feedscheck.close()
self.close()
def InstallPackageFailed(self, val):
self.feedscheck.close()
self.close()
def doInstall(self, callback, pkgname):
self.message = self.session.open(MessageBox,_("please wait..."), MessageBox.TYPE_INFO, enable_input = False)
self.message.setTitle(_('Installing Service'))
self.Console.ePopen('/usr/bin/opkg install ' + pkgname, callback)
def installComplete(self,result = None, retval = None, extra_args = None):
self.message.close()
self.feedscheck.close()
self.updateService()
def UninstallCheck(self):
self.Console.ePopen('/usr/bin/opkg list_installed ' + self.service_name, self.RemovedataAvail)
def RemovedataAvail(self, str, retval, extra_args):
if str:
self.session.openWithCallback(self.RemovePackage, MessageBox, _('Ready to remove "%s" ?') % self.service_name, MessageBox.TYPE_YESNO)
else:
self.updateService()
def RemovePackage(self, val):
if val:
self.doRemove(self.removeComplete, self.service_name)
def doRemove(self, callback, pkgname):
self.message = self.session.open(MessageBox,_("please wait..."), MessageBox.TYPE_INFO, enable_input = False)
self.message.setTitle(_('Removing Service'))
self.Console.ePopen('/usr/bin/opkg remove ' + pkgname + ' --force-remove --autoremove', callback)
def removeComplete(self,result = None, retval = None, extra_args = None):
self.message.close()
self.close()
def createSummary(self):
return NetworkServicesSummary
def Vpnshowlog(self):
self.session.open(NetworkVpnLog)
def VpnStartStop(self):
if not self.my_vpn_run:
self.Console.ePopen('/etc/init.d/openvpn start', self.StartStopCallback)
elif self.my_vpn_run:
self.Console.ePopen('/etc/init.d/openvpn stop', self.StartStopCallback)
def StartStopCallback(self, result = None, retval = None, extra_args = None):
time.sleep(3)
self.updateService()
def activateVpn(self):
if fileExists('/etc/rc2.d/S20openvpn'):
self.Console.ePopen('update-rc.d -f openvpn remove', self.StartStopCallback)
else:
self.Console.ePopen('update-rc.d -f openvpn defaults', self.StartStopCallback)
def updateService(self):
import process
p = process.ProcessList()
openvpn_process = str(p.named('openvpn')).strip('[]')
self['labrun'].hide()
self['labstop'].hide()
self['labactive'].setText(_("Disabled"))
self.my_Vpn_active = False
self.my_vpn_run = False
if fileExists('/etc/rc2.d/S20openvpn'):
self['labactive'].setText(_("Enabled"))
self['labactive'].show()
self.my_Vpn_active = True
if openvpn_process:
self.my_vpn_run = True
if self.my_vpn_run:
self['labstop'].hide()
self['labrun'].show()
self['key_green'].setText(_("Stop"))
status_summary= self['lab2'].text + ' ' + self['labrun'].text
else:
self['labstop'].show()
self['labrun'].hide()
self['key_green'].setText(_("Start"))
status_summary= self['lab2'].text + ' ' + self['labstop'].text
title = _("OpenVpn Setup")
autostartstatus_summary = self['lab1'].text + ' ' + self['labactive'].text
for cb in self.onChangedEntry:
cb(title, status_summary, autostartstatus_summary)
class NetworkVpnLog(Screen):
def __init__(self, session):
Screen.__init__(self, session)
Screen.setTitle(self, _("OpenVpn Log"))
self.skinName = "NetworkInadynLog"
self['infotext'] = ScrollLabel('')
self.Console = Console()
self['actions'] = ActionMap(['WizardActions', 'ColorActions'], {'ok': self.close, 'back': self.close, 'up': self['infotext'].pageUp, 'down': self['infotext'].pageDown})
strview = ''
self.Console.ePopen('tail /etc/openvpn/openvpn.log > /etc/openvpn/tmp.log')
time.sleep(1)
if fileExists('/etc/openvpn/tmp.log'):
f = open('/etc/openvpn/tmp.log', 'r')
for line in f.readlines():
strview += line
f.close()
remove('/etc/openvpn/tmp.log')
self['infotext'].setText(strview)
class NetworkSamba(Screen):
def __init__(self, session):
Screen.__init__(self, session)
Screen.setTitle(self, _("Samba Setup"))
self.skinName = "NetworkServiceSetup"
self.onChangedEntry = [ ]
self['lab1'] = Label(_("Autostart:"))
self['labactive'] = Label(_(_("Disabled")))
self['lab2'] = Label(_("Current Status:"))
self['labstop'] = Label(_("Stopped"))
self['labrun'] = Label(_("Running"))
self['key_green'] = Label(_("Start"))
self['key_red'] = Label(_("Remove Service"))
self['key_yellow'] = Label(_("Autostart"))
self['key_blue'] = Label(_("Show Log"))
self.Console = Console()
self.my_Samba_active = False
self.my_Samba_run = False
self['actions'] = ActionMap(['WizardActions', 'ColorActions'], {'ok': self.close, 'back': self.close, 'red': self.UninstallCheck, 'green': self.SambaStartStop, 'yellow': self.activateSamba, 'blue': self.Sambashowlog})
self.service_name = 'packagegroup-base-smbfs'
self.onLayoutFinish.append(self.InstallCheck)
def InstallCheck(self):
self.Console.ePopen('/usr/bin/opkg list_installed ' + self.service_name, self.checkNetworkState)
def checkNetworkState(self, str, retval, extra_args):
if 'Collected errors' in str:
self.session.openWithCallback(self.close, MessageBox, _("A background update check is in progress, please wait a few minutes and try again."), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
elif not str:
self.feedscheck = self.session.open(MessageBox,_('Please wait whilst feeds state is checked.'), MessageBox.TYPE_INFO, enable_input = False)
self.feedscheck.setTitle(_('Checking Feeds'))
cmd1 = "opkg update"
self.CheckConsole = Console()
self.CheckConsole.ePopen(cmd1, self.checkNetworkStateFinished)
else:
self.updateService()
def checkNetworkStateFinished(self, result, retval,extra_args=None):
if 'bad address' in result:
self.session.openWithCallback(self.InstallPackageFailed, MessageBox, _("Your %s %s is not connected to the internet, please check your network settings and try again.") % (getMachineBrand(), getMachineName()), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
elif ('wget returned 1' or 'wget returned 255' or '404 Not Found') in result:
self.session.openWithCallback(self.InstallPackageFailed, MessageBox, _("Sorry feeds are down for maintenance, please try again later."), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
else:
self.session.openWithCallback(self.QuestionCallback, MessageBox,_('Your %s %s will be restarted after the installation of service\nReady to install "%s" ?') % (getMachineBrand(), getMachineName(), self.service_name), MessageBox.TYPE_YESNO)
def QuestionCallback(self, val):
if val:
self.session.openWithCallback(self.InstallPackage, MessageBox, _('Do you want to also install samba client ?\nThis allows you to mount your windows shares on this device.'), MessageBox.TYPE_YESNO)
else:
self.feedscheck.close()
self.close()
def InstallPackage(self, val):
if val:
self.service_name += ' packagegroup-base-smbfs-client'
self.doInstall(self.installComplete, self.service_name)
def InstallPackageFailed(self, val):
self.feedscheck.close()
self.close()
def doInstall(self, callback, pkgname):
self.message = self.session.open(MessageBox,_("please wait..."), MessageBox.TYPE_INFO, enable_input = False)
self.message.setTitle(_('Installing Service'))
self.Console.ePopen('/usr/bin/opkg install ' + pkgname, callback)
def installComplete(self,result = None, retval = None, extra_args = None):
self.session.open(TryQuitMainloop, 2)
def UninstallCheck(self):
self.Console.ePopen('/usr/bin/opkg list_installed ' + self.service_name, self.RemovedataAvail)
def RemovedataAvail(self, str, retval, extra_args):
if str:
restartbox = self.session.openWithCallback(self.RemovePackage,MessageBox,_('Your %s %s will be restarted after the removal of service\nDo you want to remove now ?') % (getMachineBrand(), getMachineName()), MessageBox.TYPE_YESNO)
restartbox.setTitle(_('Ready to remove "%s" ?') % self.service_name)
else:
self.updateService()
def RemovePackage(self, val):
if val:
self.doRemove(self.removeComplete, self.service_name)
def doRemove(self, callback, pkgname):
self.message = self.session.open(MessageBox,_("please wait..."), MessageBox.TYPE_INFO, enable_input = False)
self.message.setTitle(_('Removing Service'))
self.Console.ePopen('/usr/bin/opkg remove ' + pkgname + ' --force-remove --autoremove', callback)
def removeComplete(self,result = None, retval = None, extra_args = None):
self.session.open(TryQuitMainloop, 2)
def createSummary(self):
return NetworkServicesSummary
def Sambashowlog(self):
self.session.open(NetworkSambaLog)
def SambaStartStop(self):
commands = []
if not self.my_Samba_run:
commands.append('/etc/init.d/samba start')
commands.append('nmbd -D')
commands.append('smbd -D')
elif self.my_Samba_run:
commands.append('/etc/init.d/samba stop')
commands.append('killall nmbd')
commands.append('killall smbd')
self.Console.eBatch(commands, self.StartStopCallback, debug=True)
def StartStopCallback(self, result = None, retval = None, extra_args = None):
time.sleep(3)
self.updateService()
def activateSamba(self):
if access('/etc/network/if-up.d/01samba-start', X_OK):
chmod('/etc/network/if-up.d/01samba-start', 0644)
elif not access('/etc/network/if-up.d/01samba-start', X_OK):
chmod('/etc/network/if-up.d/01samba-start', 0755)
if fileExists('/etc/rc2.d/S20samba'):
self.Console.ePopen('update-rc.d -f samba remove', self.StartStopCallback)
else:
self.Console.ePopen('update-rc.d -f samba defaults', self.StartStopCallback)
def updateService(self):
import process
p = process.ProcessList()
samba_process = str(p.named('smbd')).strip('[]')
self['labrun'].hide()
self['labstop'].hide()
self['labactive'].setText(_("Disabled"))
self.my_Samba_active = False
self.my_Samba_run = False
if fileExists('/etc/rc2.d/S20samba'):
self['labactive'].setText(_("Enabled"))
self['labactive'].show()
self.my_Samba_active = True
if access('/etc/network/if-up.d/01samba-start', X_OK):
self['labactive'].setText(_("Enabled"))
self['labactive'].show()
self.my_Samba_active = True
if samba_process:
self.my_Samba_run = True
if self.my_Samba_run:
self['labstop'].hide()
self['labactive'].show()
self['labrun'].show()
self['key_green'].setText(_("Stop"))
status_summary = self['lab2'].text + ' ' + self['labrun'].text
else:
self['labrun'].hide()
self['labstop'].show()
self['labactive'].show()
self['key_green'].setText(_("Start"))
status_summary = self['lab2'].text + ' ' + self['labstop'].text
title = _("Samba Setup")
autostartstatus_summary = self['lab1'].text + ' ' + self['labactive'].text
for cb in self.onChangedEntry:
cb(title, status_summary, autostartstatus_summary)
class NetworkSambaLog(Screen):
def __init__(self, session):
Screen.__init__(self, session)
Screen.setTitle(self, _("Samba Log"))
self.skinName = "NetworkInadynLog"
self['infotext'] = ScrollLabel('')
self.Console = Console()
self['actions'] = ActionMap(['WizardActions', 'ColorActions'], {'ok': self.close, 'back': self.close, 'up': self['infotext'].pageUp, 'down': self['infotext'].pageDown})
strview = ''
self.Console.ePopen('tail /tmp/smb.log > /tmp/tmp.log')
time.sleep(1)
if fileExists('/tmp/tmp.log'):
f = open('/tmp/tmp.log', 'r')
for line in f.readlines():
strview += line
f.close()
remove('/tmp/tmp.log')
self['infotext'].setText(strview)
class NetworkTelnet(Screen):
def __init__(self, session):
Screen.__init__(self, session)
Screen.setTitle(self, _("Telnet Setup"))
self.onChangedEntry = [ ]
self['lab1'] = Label(_("You can disable Telnet Server and use ssh to login."))
self['lab2'] = Label(_("Current Status:"))
self['labstop'] = Label(_("Stopped"))
self['labrun'] = Label(_("Running"))
self['key_green'] = Label(_("Enable"))
self['key_red'] = Label()
self.Console = Console()
self.my_telnet_active = False
self['actions'] = ActionMap(['WizardActions', 'ColorActions'], {'ok': self.close, 'back': self.close, 'green': self.TelnetStartStop})
self.onLayoutFinish.append(self.updateService)
def createSummary(self):
return NetworkServicesSummary
def TelnetStartStop(self):
if not self.my_telnet_active:
if fileExists('/etc/inetd.conf'):
inme = open('/etc/inetd.conf', 'r')
out = open('/etc/inetd.tmp', 'w')
for line in inme.readlines():
if 'telnetd' in line:
line = line.replace('#', '')
out.write(line)
out.close()
inme.close()
if fileExists('/etc/inetd.tmp'):
move('/etc/inetd.tmp', '/etc/inetd.conf')
self.Console.ePopen('killall -HUP inetd')
elif self.my_telnet_active:
if fileExists('/etc/inetd.conf'):
inme = open('/etc/inetd.conf', 'r')
out = open('/etc/inetd.tmp', 'w')
for line in inme.readlines():
if 'telnetd' in line:
line = '#' + line
out.write(line)
out.close()
inme.close()
if fileExists('/etc/inetd.tmp'):
move('/etc/inetd.tmp', '/etc/inetd.conf')
self.Console.ePopen('killall -HUP inetd')
self.updateService()
def updateService(self):
self['labrun'].hide()
self['labstop'].hide()
self.my_telnet_active = False
if fileExists('/etc/inetd.conf'):
f = open('/etc/inetd.conf', 'r')
for line in f.readlines():
parts = line.strip().split()
if parts[0] == 'telnet':
self.my_telnet_active = True
continue
f.close()
if self.my_telnet_active:
self['labstop'].hide()
self['labrun'].show()
self['key_green'].setText(_("Disable"))
status_summary= self['lab2'].text + ' ' + self['labrun'].text
else:
self['labstop'].show()
self['labrun'].hide()
self['key_green'].setText(_("Enable"))
status_summary= self['lab2'].text + ' ' + self['labstop'].text
title = _("Telnet Setup")
autostartstatus_summary = ""
for cb in self.onChangedEntry:
cb(title, status_summary, autostartstatus_summary)
class NetworkInadyn(Screen):
def __init__(self, session):
Screen.__init__(self, session)
Screen.setTitle(self, _("Inadyn Setup"))
self.onChangedEntry = [ ]
self['autostart'] = Label(_("Autostart:"))
self['labactive'] = Label(_(_("Active")))
self['labdisabled'] = Label(_(_("Disabled")))
self['status'] = Label(_("Current Status:"))
self['labstop'] = Label(_("Stopped"))
self['labrun'] = Label(_("Running"))
self['time'] = Label(_("Time Update in Minutes:"))
self['labtime'] = Label()
self['username'] = Label(_("Username") + ":")
self['labuser'] = Label()
self['password'] = Label(_("Password") + ":")
self['labpass'] = Label()
self['alias'] = Label(_("Alias") + ":")
self['labalias'] = Label()
self['sactive'] = Pixmap()
self['sinactive'] = Pixmap()
self['system'] = Label(_("System") + ":")
self['labsys'] = Label()
self['key_red'] = Label(_("Remove Service"))
self['key_green'] = Label(_("Start"))
self['key_yellow'] = Label(_("Autostart"))
self['key_blue'] = Label(_("Show Log"))
self['actions'] = ActionMap(['WizardActions', 'ColorActions', 'SetupActions'], {'ok': self.setupinadyn, 'back': self.close, 'menu': self.setupinadyn, 'red': self.UninstallCheck, 'green': self.InadynStartStop, 'yellow': self.autostart, 'blue': self.inaLog})
self.Console = Console()
self.service_name = 'inadyn-mt'
self.onLayoutFinish.append(self.InstallCheck)
def InstallCheck(self):
self.Console.ePopen('/usr/bin/opkg list_installed ' + self.service_name, self.checkNetworkState)
def checkNetworkState(self, str, retval, extra_args):
if 'Collected errors' in str:
self.session.openWithCallback(self.close, MessageBox, _("A background update check is in progress, please wait a few minutes and try again."), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
elif not str:
self.feedscheck = self.session.open(MessageBox,_('Please wait whilst feeds state is checked.'), MessageBox.TYPE_INFO, enable_input = False)
self.feedscheck.setTitle(_('Checking Feeds'))
cmd1 = "opkg update"
self.CheckConsole = Console()
self.CheckConsole.ePopen(cmd1, self.checkNetworkStateFinished)
else:
self.updateService()
def checkNetworkStateFinished(self, result, retval,extra_args=None):
if 'bad address' in result:
self.session.openWithCallback(self.InstallPackageFailed, MessageBox, _("Your %s %s is not connected to the internet, please check your network settings and try again.") % (getMachineBrand(), getMachineName()), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
elif ('wget returned 1' or 'wget returned 255' or '404 Not Found') in result:
self.session.openWithCallback(self.InstallPackageFailed, MessageBox, _("Sorry feeds are down for maintenance, please try again later."), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
else:
self.session.openWithCallback(self.InstallPackage, MessageBox, _('Ready to install "%s" ?') % self.service_name, MessageBox.TYPE_YESNO)
def InstallPackage(self, val):
if val:
self.doInstall(self.installComplete, self.service_name)
else:
self.feedscheck.close()
self.close()
def InstallPackageFailed(self, val):
self.feedscheck.close()
self.close()
def doInstall(self, callback, pkgname):
self.message = self.session.open(MessageBox,_("please wait..."), MessageBox.TYPE_INFO, enable_input = False)
self.message.setTitle(_('Installing Service'))
self.Console.ePopen('/usr/bin/opkg install ' + pkgname, callback)
def installComplete(self,result = None, retval = None, extra_args = None):
self.message.close()
self.feedscheck.close()
self.updateService()
def UninstallCheck(self):
self.Console.ePopen('/usr/bin/opkg list_installed ' + self.service_name, self.RemovedataAvail)
def RemovedataAvail(self, str, retval, extra_args):
if str:
self.session.openWithCallback(self.RemovePackage, MessageBox, _('Ready to remove "%s" ?') % self.service_name, MessageBox.TYPE_YESNO)
else:
self.updateService()
def RemovePackage(self, val):
if val:
self.doRemove(self.removeComplete, self.service_name)
def doRemove(self, callback, pkgname):
self.message = self.session.open(MessageBox,_("please wait..."), MessageBox.TYPE_INFO, enable_input = False)
self.message.setTitle(_('Removing Service'))
self.Console.ePopen('/usr/bin/opkg remove ' + pkgname + ' --force-remove --autoremove', callback)
def removeComplete(self,result = None, retval = None, extra_args = None):
self.message.close()
self.close()
def createSummary(self):
return NetworkServicesSummary
def InadynStartStop(self):
if not self.my_inadyn_run:
self.Console.ePopen('/etc/init.d/inadyn-mt start', self.StartStopCallback)
elif self.my_inadyn_run:
self.Console.ePopen('/etc/init.d/inadyn-mt stop', self.StartStopCallback)
def StartStopCallback(self, result = None, retval = None, extra_args = None):
time.sleep(3)
self.updateService()
def autostart(self):
if fileExists('/etc/rc2.d/S20inadyn-mt'):
self.Console.ePopen('update-rc.d -f inadyn-mt remove', self.StartStopCallback)
else:
self.Console.ePopen('update-rc.d -f inadyn-mt defaults', self.StartStopCallback)
def updateService(self):
import process
p = process.ProcessList()
inadyn_process = str(p.named('inadyn-mt')).strip('[]')
self['labrun'].hide()
self['labstop'].hide()
self['labactive'].hide()
self['labdisabled'].hide()
self['sactive'].hide()
self.my_inadyn_active = False
self.my_inadyn_run = False
if fileExists('/etc/rc2.d/S20inadyn-mt'):
self['labdisabled'].hide()
self['labactive'].show()
self.my_inadyn_active = True
autostartstatus_summary = self['autostart'].text + ' ' + self['labactive'].text
else:
self['labactive'].hide()
self['labdisabled'].show()
autostartstatus_summary = self['autostart'].text + ' ' + self['labdisabled'].text
if inadyn_process:
self.my_inadyn_run = True
if self.my_inadyn_run:
self['labstop'].hide()
self['labrun'].show()
self['key_green'].setText(_("Stop"))
status_summary = self['status'].text + ' ' + self['labrun'].text
else:
self['labstop'].show()
self['labrun'].hide()
self['key_green'].setText(_("Start"))
status_summary = self['status'].text + ' ' + self['labstop'].text
#self.my_nabina_state = False
if fileExists('/etc/inadyn.conf'):
f = open('/etc/inadyn.conf', 'r')
for line in f.readlines():
line = line.strip()
if line.startswith('username '):
line = line[9:]
self['labuser'].setText(line)
elif line.startswith('password '):
line = line[9:]
self['labpass'].setText(line)
elif line.startswith('alias '):
line = line[6:]
self['labalias'].setText(line)
elif line.startswith('update_period_sec '):
line = line[18:]
line = (int(line) / 60)
self['labtime'].setText(str(line))
elif line.startswith('dyndns_system ') or line.startswith('#dyndns_system '):
if line.startswith('#'):
line = line[15:]
self['sactive'].hide()
else:
line = line[14:]
self['sactive'].show()
self['labsys'].setText(line)
f.close()
title = _("Inadyn Setup")
for cb in self.onChangedEntry:
cb(title, status_summary, autostartstatus_summary)
def setupinadyn(self):
self.session.openWithCallback(self.updateService, NetworkInadynSetup)
def inaLog(self):
self.session.open(NetworkInadynLog)
class NetworkInadynSetup(Screen, ConfigListScreen):
def __init__(self, session):
Screen.__init__(self, session)
self.onChangedEntry = [ ]
self.list = []
ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.selectionChanged)
Screen.setTitle(self, _("Inadyn Setup"))
self['key_red'] = Label(_("Save"))
self['actions'] = ActionMap(['WizardActions', 'ColorActions', 'VirtualKeyboardActions'], {'red': self.saveIna, 'back': self.close, 'showVirtualKeyboard': self.KeyText})
self["HelpWindow"] = Pixmap()
self["HelpWindow"].hide()
self.updateList()
if not self.selectionChanged in self["config"].onSelectionChanged:
self["config"].onSelectionChanged.append(self.selectionChanged)
def createSummary(self):
from Screens.PluginBrowser import PluginBrowserSummary
return PluginBrowserSummary
def selectionChanged(self):
item = self["config"].getCurrent()
if item:
name = str(item[0])
desc = str(item[1].value)
else:
name = ""
desc = ""
for cb in self.onChangedEntry:
cb(name, desc)
def updateList(self):
self.ina_user = NoSave(ConfigText(fixed_size=False))
self.ina_pass = NoSave(ConfigText(fixed_size=False))
self.ina_alias = NoSave(ConfigText(fixed_size=False))
self.ina_period = NoSave(ConfigNumber())
self.ina_sysactive = NoSave(ConfigYesNo(default='False'))
self.ina_system = NoSave(ConfigSelection(default = "dyndns@dyndns.org", choices = [("dyndns@dyndns.org", "dyndns@dyndns.org"), ("statdns@dyndns.org", "statdns@dyndns.org"), ("custom@dyndns.org", "custom@dyndns.org"), ("default@no-ip.com", "default@no-ip.com")]))
if fileExists('/etc/inadyn.conf'):
f = open('/etc/inadyn.conf', 'r')
for line in f.readlines():
line = line.strip()
if line.startswith('username '):
line = line[9:]
self.ina_user.value = line
ina_user1 = getConfigListEntry(_("Username") + ":", self.ina_user)
self.list.append(ina_user1)
elif line.startswith('password '):
line = line[9:]
self.ina_pass.value = line
ina_pass1 = getConfigListEntry(_("Password") + ":", self.ina_pass)
self.list.append(ina_pass1)
elif line.startswith('alias '):
line = line[6:]
self.ina_alias.value = line
ina_alias1 = getConfigListEntry(_("Alias") + ":", self.ina_alias)
self.list.append(ina_alias1)
elif line.startswith('update_period_sec '):
line = line[18:]
line = (int(line) / 60)
self.ina_period.value = line
ina_period1 = getConfigListEntry(_("Time Update in Minutes") + ":", self.ina_period)
self.list.append(ina_period1)
elif line.startswith('dyndns_system ') or line.startswith('#dyndns_system '):
if not line.startswith('#'):
self.ina_sysactive.value = True
line = line[14:]
else:
self.ina_sysactive.value = False
line = line[15:]
ina_sysactive1 = getConfigListEntry(_("Set System") + ":", self.ina_sysactive)
self.list.append(ina_sysactive1)
self.ina_value = line
ina_system1 = getConfigListEntry(_("System") + ":", self.ina_system)
self.list.append(ina_system1)
f.close()
self['config'].list = self.list
self['config'].l.setList(self.list)
def KeyText(self):
sel = self['config'].getCurrent()
if sel:
if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
if self["config"].getCurrent()[1].help_window.instance is not None:
self["config"].getCurrent()[1].help_window.hide()
self.vkvar = sel[0]
if self.vkvar == _("Username") + ':' or self.vkvar == _("Password") + ':' or self.vkvar == _("Alias") + ':' or self.vkvar == _("System") + ':':
from Screens.VirtualKeyBoard import VirtualKeyBoard
self.session.openWithCallback(self.VirtualKeyBoardCallback, VirtualKeyBoard, title = self["config"].getCurrent()[0], text = self["config"].getCurrent()[1].value)
def VirtualKeyBoardCallback(self, callback = None):
if callback is not None and len(callback):
self["config"].getCurrent()[1].setValue(callback)
self["config"].invalidate(self["config"].getCurrent())
def saveIna(self):
if fileExists('/etc/inadyn.conf'):
inme = open('/etc/inadyn.conf', 'r')
out = open('/etc/inadyn.conf.tmp', 'w')
for line in inme.readlines():
line = line.replace('\n', '')
if line.startswith('username '):
line = ('username ' + self.ina_user.value.strip())
elif line.startswith('password '):
line = ('password ' + self.ina_pass.value.strip())
elif line.startswith('alias '):
line = ('alias ' + self.ina_alias.value.strip())
elif line.startswith('update_period_sec '):
strview = (self.ina_period.value * 60)
strview = str(strview)
line = ('update_period_sec ' + strview)
elif line.startswith('dyndns_system ') or line.startswith('#dyndns_system '):
if self.ina_sysactive.value:
line = ('dyndns_system ' + self.ina_system.value.strip())
else:
line = ('#dyndns_system ' + self.ina_system.value.strip())
out.write((line + '\n'))
out.close()
inme.close()
else:
self.session.open(MessageBox, _("Sorry Inadyn Config is Missing"), MessageBox.TYPE_INFO)
self.close()
if fileExists('/etc/inadyn.conf.tmp'):
rename('/etc/inadyn.conf.tmp', '/etc/inadyn.conf')
self.myStop()
def myStop(self):
self.close()
class NetworkInadynLog(Screen):
def __init__(self, session):
Screen.__init__(self, session)
Screen.setTitle(self, _("Inadyn Log"))
self['infotext'] = ScrollLabel('')
self['actions'] = ActionMap(['WizardActions', 'DirectionActions', 'ColorActions'], {'ok': self.close,
'back': self.close,
'up': self['infotext'].pageUp,
'down': self['infotext'].pageDown})
strview = ''
if fileExists('/var/log/inadyn.log'):
f = open('/var/log/inadyn.log', 'r')
for line in f.readlines():
strview += line
f.close()
self['infotext'].setText(strview)
config.networkushare = ConfigSubsection()
config.networkushare.mediafolders = NoSave(ConfigLocations(default=""))
class NetworkuShare(Screen):
def __init__(self, session):
Screen.__init__(self, session)
Screen.setTitle(self, _("uShare Setup"))
self.onChangedEntry = [ ]
self['autostart'] = Label(_("Autostart:"))
self['labactive'] = Label(_(_("Active")))
self['labdisabled'] = Label(_(_("Disabled")))
self['status'] = Label(_("Current Status:"))
self['labstop'] = Label(_("Stopped"))
self['labrun'] = Label(_("Running"))
self['username'] = Label(_("uShare Name") + ":")
self['labuser'] = Label()
self['iface'] = Label(_("Interface") + ":")
self['labiface'] = Label()
self['port'] = Label(_("uShare Port") + ":")
self['labport'] = Label()
self['telnetport'] = Label(_("Telnet Port") + ":")
self['labtelnetport'] = Label()
self['sharedir'] = Label(_("Share Folder's") + ":")
self['labsharedir'] = Label()
self['web'] = Label(_("Web Interface") + ":")
self['webactive'] = Pixmap()
self['webinactive'] = Pixmap()
self['telnet'] = Label(_("Telnet Interface") + ":")
self['telnetactive'] = Pixmap()
self['telnetinactive'] = Pixmap()
self['xbox'] = Label(_("XBox 360 support") + ":")
self['xboxactive'] = Pixmap()
self['xboxinactive'] = Pixmap()
self['dlna'] = Label(_("DLNA support") + ":")
self['dlnaactive'] = Pixmap()
self['dlnainactive'] = Pixmap()
self['key_red'] = Label(_("Remove Service"))
self['key_green'] = Label(_("Start"))
self['key_yellow'] = Label(_("Autostart"))
self['key_blue'] = Label(_("Show Log"))
self['actions'] = ActionMap(['WizardActions', 'ColorActions', 'SetupActions'], {'ok': self.setupushare, 'back': self.close, 'menu': self.setupushare, 'red': self.UninstallCheck, 'green': self.uShareStartStop, 'yellow': self.autostart, 'blue': self.ushareLog})
self.Console = Console()
self.service_name = 'ushare'
self.onLayoutFinish.append(self.InstallCheck)
def InstallCheck(self):
self.Console.ePopen('/usr/bin/opkg list_installed ' + self.service_name, self.checkNetworkState)
def checkNetworkState(self, str, retval, extra_args):
if 'Collected errors' in str:
self.session.openWithCallback(self.close, MessageBox, _("A background update check is in progress, please wait a few minutes and try again."), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
elif not str:
self.feedscheck = self.session.open(MessageBox,_('Please wait whilst feeds state is checked.'), MessageBox.TYPE_INFO, enable_input = False)
self.feedscheck.setTitle(_('Checking Feeds'))
cmd1 = "opkg update"
self.CheckConsole = Console()
self.CheckConsole.ePopen(cmd1, self.checkNetworkStateFinished)
else:
self.updateService()
def checkNetworkStateFinished(self, result, retval,extra_args=None):
if 'bad address' in result:
self.session.openWithCallback(self.InstallPackageFailed, MessageBox, _("Your %s %s is not connected to the internet, please check your network settings and try again.") % (getMachineBrand(), getMachineName()), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
elif ('wget returned 1' or 'wget returned 255' or '404 Not Found') in result:
self.session.openWithCallback(self.InstallPackageFailed, MessageBox, _("Sorry feeds are down for maintenance, please try again later."), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
else:
self.session.openWithCallback(self.InstallPackage, MessageBox, _('Ready to install "%s" ?') % self.service_name, MessageBox.TYPE_YESNO)
def InstallPackage(self, val):
if val:
self.doInstall(self.installComplete, self.service_name)
else:
self.feedscheck.close()
self.close()
def InstallPackageFailed(self, val):
self.feedscheck.close()
self.close()
def doInstall(self, callback, pkgname):
self.message = self.session.open(MessageBox,_("please wait..."), MessageBox.TYPE_INFO, enable_input = False)
self.message.setTitle(_('Installing Service'))
self.Console.ePopen('/usr/bin/opkg install ' + pkgname, callback)
def installComplete(self,result = None, retval = None, extra_args = None):
self.message.close()
self.feedscheck.close()
self.updateService()
def UninstallCheck(self):
self.Console.ePopen('/usr/bin/opkg list_installed ' + self.service_name, self.RemovedataAvail)
def RemovedataAvail(self, str, retval, extra_args):
if str:
self.session.openWithCallback(self.RemovePackage, MessageBox, _('Ready to remove "%s" ?') % self.service_name, MessageBox.TYPE_YESNO)
else:
self.updateService()
def RemovePackage(self, val):
if val:
self.doRemove(self.removeComplete, self.service_name)
def doRemove(self, callback, pkgname):
self.message = self.session.open(MessageBox,_("please wait..."), MessageBox.TYPE_INFO, enable_input = False)
self.message.setTitle(_('Removing Service'))
self.Console.ePopen('/usr/bin/opkg remove ' + pkgname + ' --force-remove --autoremove', callback)
def removeComplete(self,result = None, retval = None, extra_args = None):
self.message.close()
self.close()
def createSummary(self):
return NetworkServicesSummary
def uShareStartStop(self):
if not self.my_ushare_run:
self.Console.ePopen('/etc/init.d/ushare start >> /tmp/uShare.log', self.StartStopCallback)
elif self.my_ushare_run:
self.Console.ePopen('/etc/init.d/ushare stop >> /tmp/uShare.log', self.StartStopCallback)
def StartStopCallback(self, result = None, retval = None, extra_args = None):
time.sleep(3)
self.updateService()
def autostart(self):
if fileExists('/etc/rc2.d/S20ushare'):
self.Console.ePopen('update-rc.d -f ushare remove', self.StartStopCallback)
else:
self.Console.ePopen('update-rc.d -f ushare defaults', self.StartStopCallback)
def updateService(self):
import process
p = process.ProcessList()
ushare_process = str(p.named('ushare')).strip('[]')
self['labrun'].hide()
self['labstop'].hide()
self['labactive'].hide()
self['labdisabled'].hide()
self.my_ushare_active = False
self.my_ushare_run = False
if not fileExists('/tmp/uShare.log'):
f = open('/tmp/uShare.log', "w")
f.write("")
f.close()
if fileExists('/etc/rc2.d/S20ushare'):
self['labdisabled'].hide()
self['labactive'].show()
self.my_ushare_active = True
autostartstatus_summary = self['autostart'].text + ' ' + self['labactive'].text
else:
self['labactive'].hide()
self['labdisabled'].show()
autostartstatus_summary = self['autostart'].text + ' ' + self['labdisabled'].text
if ushare_process:
self.my_ushare_run = True
if self.my_ushare_run:
self['labstop'].hide()
self['labrun'].show()
self['key_green'].setText(_("Stop"))
status_summary= self['status'].text + ' ' + self['labstop'].text
else:
self['labstop'].show()
self['labrun'].hide()
self['key_green'].setText(_("Start"))
status_summary= self['status'].text + ' ' + self['labstop'].text
if fileExists('/etc/ushare.conf'):
f = open('/etc/ushare.conf', 'r')
for line in f.readlines():
line = line.strip()
if line.startswith('USHARE_NAME='):
line = line[12:]
self['labuser'].setText(line)
elif line.startswith('USHARE_IFACE='):
line = line[13:]
self['labiface'].setText(line)
elif line.startswith('USHARE_PORT='):
line = line[12:]
self['labport'].setText(line)
elif line.startswith('USHARE_TELNET_PORT='):
line = line[19:]
self['labtelnetport'].setText(line)
elif line.startswith('USHARE_DIR='):
line = line[11:]
self.mediafolders = line
self['labsharedir'].setText(line)
elif line.startswith('ENABLE_WEB='):
if line[11:] == 'no':
self['webactive'].hide()
self['webinactive'].show()
else:
self['webactive'].show()
self['webinactive'].hide()
elif line.startswith('ENABLE_TELNET='):
if line[14:] == 'no':
self['telnetactive'].hide()
self['telnetinactive'].show()
else:
self['telnetactive'].show()
self['telnetinactive'].hide()
elif line.startswith('ENABLE_XBOX='):
if line[12:] == 'no':
self['xboxactive'].hide()
self['xboxinactive'].show()
else:
self['xboxactive'].show()
self['xboxinactive'].hide()
elif line.startswith('ENABLE_DLNA='):
if line[12:] == 'no':
self['dlnaactive'].hide()
self['dlnainactive'].show()
else:
self['dlnaactive'].show()
self['dlnainactive'].hide()
f.close()
title = _("uShare Setup")
for cb in self.onChangedEntry:
cb(title, status_summary, autostartstatus_summary)
def setupushare(self):
self.session.openWithCallback(self.updateService, NetworkuShareSetup)
def ushareLog(self):
self.session.open(NetworkuShareLog)
class NetworkuShareSetup(Screen, ConfigListScreen):
def __init__(self, session):
Screen.__init__(self, session)
Screen.setTitle(self, _("uShare Setup"))
self.onChangedEntry = [ ]
self.list = []
ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.selectionChanged)
Screen.setTitle(self, _("uShare Setup"))
self['key_red'] = Label(_("Save"))
self['key_green'] = Label(_("Shares"))
self['actions'] = ActionMap(['WizardActions', 'ColorActions', 'VirtualKeyboardActions'], {'red': self.saveuShare, 'green': self.selectfolders, 'back': self.close, 'showVirtualKeyboard': self.KeyText})
self["HelpWindow"] = Pixmap()
self["HelpWindow"].hide()
self.updateList()
if not self.selectionChanged in self["config"].onSelectionChanged:
self["config"].onSelectionChanged.append(self.selectionChanged)
def createSummary(self):
from Screens.PluginBrowser import PluginBrowserSummary
return PluginBrowserSummary
def selectionChanged(self):
item = self["config"].getCurrent()
if item:
name = str(item[0])
desc = str(item[1].value)
else:
name = ""
desc = ""
for cb in self.onChangedEntry:
cb(name, desc)
def updateList(self, ret=None):
self.list = []
self.ushare_user = NoSave(ConfigText(default=getBoxType(),fixed_size=False))
self.ushare_iface = NoSave(ConfigText(fixed_size=False))
self.ushare_port = NoSave(ConfigNumber())
self.ushare_telnetport = NoSave(ConfigNumber())
self.ushare_web = NoSave(ConfigYesNo(default='True'))
self.ushare_telnet = NoSave(ConfigYesNo(default='True'))
self.ushare_xbox= NoSave(ConfigYesNo(default='True'))
self.ushare_ps3= NoSave(ConfigYesNo(default='True'))
self.ushare_system = NoSave(ConfigSelection(default = "dyndns@dyndns.org", choices = [("dyndns@dyndns.org", "dyndns@dyndns.org"), ("statdns@dyndns.org", "statdns@dyndns.org"), ("custom@dyndns.org", "custom@dyndns.org")]))
if fileExists('/etc/ushare.conf'):
f = open('/etc/ushare.conf', 'r')
for line in f.readlines():
line = line.strip()
if line.startswith('USHARE_NAME='):
line = line[12:]
self.ushare_user.value = line
ushare_user1 = getConfigListEntry(_("uShare Name") + ":", self.ushare_user)
self.list.append(ushare_user1)
elif line.startswith('USHARE_IFACE='):
line = line[13:]
self.ushare_iface.value = line
ushare_iface1 = getConfigListEntry(_("Interface") + ":", self.ushare_iface)
self.list.append(ushare_iface1)
elif line.startswith('USHARE_PORT='):
line = line[12:]
self.ushare_port.value = line
ushare_port1 = getConfigListEntry(_("uShare Port") + ":", self.ushare_port)
self.list.append(ushare_port1)
elif line.startswith('USHARE_TELNET_PORT='):
line = line[19:]
self.ushare_telnetport.value = line
ushare_telnetport1 = getConfigListEntry(_("Telnet Port") + ":", self.ushare_telnetport)
self.list.append(ushare_telnetport1)
elif line.startswith('ENABLE_WEB='):
if line[11:] == 'no':
self.ushare_web.value = False
else:
self.ushare_web.value = True
ushare_web1 = getConfigListEntry(_("Web Interface") + ":", self.ushare_web)
self.list.append(ushare_web1)
elif line.startswith('ENABLE_TELNET='):
if line[14:] == 'no':
self.ushare_telnet.value = False
else:
self.ushare_telnet.value = True
ushare_telnet1 = getConfigListEntry(_("Telnet Interface") + ":", self.ushare_telnet)
self.list.append(ushare_telnet1)
elif line.startswith('ENABLE_XBOX='):
if line[12:] == 'no':
self.ushare_xbox.value = False
else:
self.ushare_xbox.value = True
ushare_xbox1 = getConfigListEntry(_("XBox 360 support") + ":", self.ushare_xbox)
self.list.append(ushare_xbox1)
elif line.startswith('ENABLE_DLNA='):
if line[12:] == 'no':
self.ushare_ps3.value = False
else:
self.ushare_ps3.value = True
ushare_ps31 = getConfigListEntry(_("DLNA support") + ":", self.ushare_ps3)
self.list.append(ushare_ps31)
f.close()
self['config'].list = self.list
self['config'].l.setList(self.list)
def KeyText(self):
sel = self['config'].getCurrent()
if sel:
if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
if self["config"].getCurrent()[1].help_window.instance is not None:
self["config"].getCurrent()[1].help_window.hide()
self.vkvar = sel[0]
if self.vkvar == _("uShare Name") + ":" or self.vkvar == _("Share Folder's") + ":":
from Screens.VirtualKeyBoard import VirtualKeyBoard
self.session.openWithCallback(self.VirtualKeyBoardCallback, VirtualKeyBoard, title = self["config"].getCurrent()[0], text = self["config"].getCurrent()[1].value)
def VirtualKeyBoardCallback(self, callback = None):
if callback is not None and len(callback):
self["config"].getCurrent()[1].setValue(callback)
self["config"].invalidate(self["config"].getCurrent())
def saveuShare(self):
if fileExists('/etc/ushare.conf'):
inme = open('/etc/ushare.conf', 'r')
out = open('/etc/ushare.conf.tmp', 'w')
for line in inme.readlines():
line = line.replace('\n', '')
if line.startswith('USHARE_NAME='):
line = ('USHARE_NAME=' + self.ushare_user.value.strip())
elif line.startswith('USHARE_IFACE='):
line = ('USHARE_IFACE=' + self.ushare_iface.value.strip())
elif line.startswith('USHARE_PORT='):
line = ('USHARE_PORT=' + str(self.ushare_port.value))
elif line.startswith('USHARE_TELNET_PORT='):
line = ('USHARE_TELNET_PORT=' + str(self.ushare_telnetport.value))
elif line.startswith('USHARE_DIR='):
line = ('USHARE_DIR=' + ', '.join( config.networkushare.mediafolders.value ))
elif line.startswith('ENABLE_WEB='):
if not self.ushare_web.value:
line = 'ENABLE_WEB=no'
else:
line = 'ENABLE_WEB=yes'
elif line.startswith('ENABLE_TELNET='):
if not self.ushare_telnet.value:
line = 'ENABLE_TELNET=no'
else:
line = 'ENABLE_TELNET=yes'
elif line.startswith('ENABLE_XBOX='):
if not self.ushare_xbox.value:
line = 'ENABLE_XBOX=no'
else:
line = 'ENABLE_XBOX=yes'
elif line.startswith('ENABLE_DLNA='):
if not self.ushare_ps3.value:
line = 'ENABLE_DLNA=no'
else:
line = 'ENABLE_DLNA=yes'
out.write((line + '\n'))
out.close()
inme.close()
else:
open('/tmp/uShare.log', "a").write(_("Sorry uShare Config is Missing") + '\n')
self.session.open(MessageBox, _("Sorry uShare Config is Missing"), MessageBox.TYPE_INFO)
self.close()
if fileExists('/etc/ushare.conf.tmp'):
rename('/etc/ushare.conf.tmp', '/etc/ushare.conf')
self.myStop()
def myStop(self):
self.close()
def selectfolders(self):
self.session.openWithCallback(self.updateList,uShareSelection)
class uShareSelection(Screen):
def __init__(self, session):
Screen.__init__(self, session)
Screen.setTitle(self, _("Select folders"))
self["key_red"] = StaticText(_("Cancel"))
self["key_green"] = StaticText(_("Save"))
self["key_yellow"] = StaticText()
if fileExists('/etc/ushare.conf'):
f = open('/etc/ushare.conf', 'r')
for line in f.readlines():
line = line.strip()
if line.startswith('USHARE_DIR='):
line = line[11:]
self.mediafolders = line
self.selectedFiles = [str(n) for n in self.mediafolders.split(', ')]
defaultDir = '/media/'
self.filelist = MultiFileSelectList(self.selectedFiles, defaultDir,showFiles = False )
self["checkList"] = self.filelist
self["actions"] = ActionMap(["DirectionActions", "OkCancelActions", "ShortcutActions"],
{
"cancel": self.exit,
"red": self.exit,
"yellow": self.changeSelectionState,
"green": self.saveSelection,
"ok": self.okClicked,
"left": self.left,
"right": self.right,
"down": self.down,
"up": self.up
}, -1)
if not self.selectionChanged in self["checkList"].onSelectionChanged:
self["checkList"].onSelectionChanged.append(self.selectionChanged)
self.onLayoutFinish.append(self.layoutFinished)
def layoutFinished(self):
idx = 0
self["checkList"].moveToIndex(idx)
self.selectionChanged()
def selectionChanged(self):
current = self["checkList"].getCurrent()[0]
if current[2] is True:
self["key_yellow"].setText(_("Deselect"))
else:
self["key_yellow"].setText(_("Select"))
def up(self):
self["checkList"].up()
def down(self):
self["checkList"].down()
def left(self):
self["checkList"].pageUp()
def right(self):
self["checkList"].pageDown()
def changeSelectionState(self):
self["checkList"].changeSelectionState()
self.selectedFiles = self["checkList"].getSelectedList()
def saveSelection(self):
self.selectedFiles = self["checkList"].getSelectedList()
config.networkushare.mediafolders.value = self.selectedFiles
self.close(None)
def exit(self):
self.close(None)
def okClicked(self):
if self.filelist.canDescent():
self.filelist.descent()
class NetworkuShareLog(Screen):
def __init__(self, session):
Screen.__init__(self, session)
self.skinName = "NetworkInadynLog"
Screen.setTitle(self, _("uShare Log"))
self['infotext'] = ScrollLabel('')
self.Console = Console()
self['actions'] = ActionMap(['WizardActions', 'ColorActions'], {'ok': self.close, 'back': self.close, 'up': self['infotext'].pageUp, 'down': self['infotext'].pageDown})
strview = ''
self.Console.ePopen('tail /tmp/uShare.log > /tmp/tmp.log')
time.sleep(1)
if fileExists('/tmp/tmp.log'):
f = open('/tmp/tmp.log', 'r')
for line in f.readlines():
strview += line
f.close()
remove('/tmp/tmp.log')
self['infotext'].setText(strview)
config.networkminidlna = ConfigSubsection()
config.networkminidlna.mediafolders = NoSave(ConfigLocations(default=""))
class NetworkMiniDLNA(Screen):
def __init__(self, session):
Screen.__init__(self, session)
Screen.setTitle(self, _("MiniDLNA Setup"))
self.onChangedEntry = [ ]
self['autostart'] = Label(_("Autostart:"))
self['labactive'] = Label(_(_("Active")))
self['labdisabled'] = Label(_(_("Disabled")))
self['status'] = Label(_("Current Status:"))
self['labstop'] = Label(_("Stopped"))
self['labrun'] = Label(_("Running"))
self['username'] = Label(_("Name") + ":")
self['labuser'] = Label()
self['iface'] = Label(_("Interface") + ":")
self['labiface'] = Label()
self['port'] = Label(_("Port") + ":")
self['labport'] = Label()
self['serialno'] = Label(_("Serial No") + ":")
self['labserialno'] = Label()
self['sharedir'] = Label(_("Share Folder's") + ":")
self['labsharedir'] = Label()
self['inotify'] = Label(_("Inotify Monitoring") + ":")
self['inotifyactive'] = Pixmap()
self['inotifyinactive'] = Pixmap()
self['tivo'] = Label(_("TiVo support") + ":")
self['tivoactive'] = Pixmap()
self['tivoinactive'] = Pixmap()
self['dlna'] = Label(_("Strict DLNA") + ":")
self['dlnaactive'] = Pixmap()
self['dlnainactive'] = Pixmap()
self['key_red'] = Label(_("Remove Service"))
self['key_green'] = Label(_("Start"))
self['key_yellow'] = Label(_("Autostart"))
self['key_blue'] = Label(_("Show Log"))
self['actions'] = ActionMap(['WizardActions', 'ColorActions', 'SetupActions'], {'ok': self.setupminidlna, 'back': self.close, 'menu': self.setupminidlna, 'red': self.UninstallCheck, 'green': self.MiniDLNAStartStop, 'yellow': self.autostart, 'blue': self.minidlnaLog})
self.Console = Console()
self.service_name = 'minidlna'
self.onLayoutFinish.append(self.InstallCheck)
def InstallCheck(self):
self.Console.ePopen('/usr/bin/opkg list_installed ' + self.service_name, self.checkNetworkState)
def checkNetworkState(self, str, retval, extra_args):
if 'Collected errors' in str:
self.session.openWithCallback(self.close, MessageBox, _("A background update check is in progress, please wait a few minutes and try again."), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
elif not str:
self.feedscheck = self.session.open(MessageBox,_('Please wait whilst feeds state is checked.'), MessageBox.TYPE_INFO, enable_input = False)
self.feedscheck.setTitle(_('Checking Feeds'))
cmd1 = "opkg update"
self.CheckConsole = Console()
self.CheckConsole.ePopen(cmd1, self.checkNetworkStateFinished)
else:
self.updateService()
def checkNetworkStateFinished(self, result, retval,extra_args=None):
if 'bad address' in result:
self.session.openWithCallback(self.InstallPackageFailed, MessageBox, _("Your %s %s is not connected to the internet, please check your network settings and try again.") % (getMachineBrand(), getMachineName()), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
elif ('wget returned 1' or 'wget returned 255' or '404 Not Found') in result:
self.session.openWithCallback(self.InstallPackageFailed, MessageBox, _("Sorry feeds are down for maintenance, please try again later."), type=MessageBox.TYPE_INFO, timeout=10, close_on_any_key=True)
else:
self.session.openWithCallback(self.InstallPackage, MessageBox, _('Ready to install "%s" ?') % self.service_name, MessageBox.TYPE_YESNO)
def InstallPackage(self, val):
if val:
self.doInstall(self.installComplete, self.service_name)
else:
self.feedscheck.close()
self.close()
def InstallPackageFailed(self, val):
self.feedscheck.close()
self.close()
def doInstall(self, callback, pkgname):
self.message = self.session.open(MessageBox,_("please wait..."), MessageBox.TYPE_INFO, enable_input = False)
self.message.setTitle(_('Installing Service'))
self.Console.ePopen('/usr/bin/opkg install ' + pkgname, callback)
def installComplete(self,result = None, retval = None, extra_args = None):
self.message.close()
self.feedscheck.close()
self.updateService()
def UninstallCheck(self):
self.Console.ePopen('/usr/bin/opkg list_installed ' + self.service_name, self.RemovedataAvail)
def RemovedataAvail(self, str, retval, extra_args):
if str:
self.session.openWithCallback(self.RemovePackage, MessageBox, _('Ready to remove "%s" ?') % self.service_name, MessageBox.TYPE_YESNO)
else:
self.updateService()
def RemovePackage(self, val):
if val:
self.doRemove(self.removeComplete, self.service_name)
def doRemove(self, callback, pkgname):
self.message = self.session.open(MessageBox,_("please wait..."), MessageBox.TYPE_INFO, enable_input = False)
self.message.setTitle(_('Removing Service'))
self.Console.ePopen('/usr/bin/opkg remove ' + pkgname + ' --force-remove --autoremove', callback)
def removeComplete(self,result = None, retval = None, extra_args = None):
self.message.close()
self.close()
def createSummary(self):
return NetworkServicesSummary
def MiniDLNAStartStop(self):
if not self.my_minidlna_run:
self.Console.ePopen('/etc/init.d/minidlna start', self.StartStopCallback)
elif self.my_minidlna_run:
self.Console.ePopen('/etc/init.d/minidlna stop', self.StartStopCallback)
def StartStopCallback(self, result = None, retval = None, extra_args = None):
time.sleep(3)
self.updateService()
def autostart(self):
if fileExists('/etc/rc2.d/S20minidlna'):
self.Console.ePopen('update-rc.d -f minidlna remove', self.StartStopCallback)
else:
self.Console.ePopen('update-rc.d -f minidlna defaults', self.StartStopCallback)
def updateService(self):
import process
p = process.ProcessList()
minidlna_process = str(p.named('minidlnad')).strip('[]')
self['labrun'].hide()
self['labstop'].hide()
self['labactive'].hide()
self['labdisabled'].hide()
self.my_minidlna_active = False
self.my_minidlna_run = False
if fileExists('/etc/rc2.d/S20minidlna'):
self['labdisabled'].hide()
self['labactive'].show()
self.my_minidlna_active = True
autostartstatus_summary = self['autostart'].text + ' ' + self['labactive'].text
else:
self['labactive'].hide()
self['labdisabled'].show()
autostartstatus_summary = self['autostart'].text + ' ' + self['labdisabled'].text
if minidlna_process:
self.my_minidlna_run = True
if self.my_minidlna_run:
self['labstop'].hide()
self['labrun'].show()
self['key_green'].setText(_("Stop"))
status_summary = self['status'].text + ' ' + self['labstop'].text
else:
self['labstop'].show()
self['labrun'].hide()
self['key_green'].setText(_("Start"))
status_summary = self['status'].text + ' ' + self['labstop'].text
if fileExists('/etc/minidlna.conf'):
f = open('/etc/minidlna.conf', 'r')
for line in f.readlines():
line = line.strip()
if line.startswith('friendly_name='):
line = line[14:]
self['labuser'].setText(line)
elif line.startswith('network_interface='):
line = line[18:]
self['labiface'].setText(line)
elif line.startswith('port='):
line = line[5:]
self['labport'].setText(line)
elif line.startswith('serial='):
line = line[7:]
self['labserialno'].setText(line)
elif line.startswith('media_dir='):
line = line[10:]
self.mediafolders = line
self['labsharedir'].setText(line)
elif line.startswith('inotify='):
if line[8:] == 'no':
self['inotifyactive'].hide()
self['inotifyinactive'].show()
else:
self['inotifyactive'].show()
self['inotifyinactive'].hide()
elif line.startswith('enable_tivo='):
if line[12:] == 'no':
self['tivoactive'].hide()
self['tivoinactive'].show()
else:
self['tivoactive'].show()
self['tivoinactive'].hide()
elif line.startswith('strict_dlna='):
if line[12:] == 'no':
self['dlnaactive'].hide()
self['dlnainactive'].show()
else:
self['dlnaactive'].show()
self['dlnainactive'].hide()
f.close()
title = _("MiniDLNA Setup")
for cb in self.onChangedEntry:
cb(title, status_summary, autostartstatus_summary)
def setupminidlna(self):
self.session.openWithCallback(self.updateService, NetworkMiniDLNASetup)
def minidlnaLog(self):
self.session.open(NetworkMiniDLNALog)
class NetworkMiniDLNASetup(Screen, ConfigListScreen):
def __init__(self, session):
Screen.__init__(self, session)
Screen.setTitle(self, _("MiniDLNA Setup"))
self.onChangedEntry = [ ]
self.list = []
ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.selectionChanged)
Screen.setTitle(self, _("MiniDLNA Setup"))
self.skinName = "NetworkuShareSetup"
self['key_red'] = Label(_("Save"))
self['key_green'] = Label(_("Shares"))
self['actions'] = ActionMap(['WizardActions', 'ColorActions', 'VirtualKeyboardActions'], {'red': self.saveMinidlna, 'green': self.selectfolders, 'back': self.close, 'showVirtualKeyboard': self.KeyText})
self["HelpWindow"] = Pixmap()
self["HelpWindow"].hide()
self.updateList()
if not self.selectionChanged in self["config"].onSelectionChanged:
self["config"].onSelectionChanged.append(self.selectionChanged)
def createSummary(self):
from Screens.PluginBrowser import PluginBrowserSummary
return PluginBrowserSummary
def selectionChanged(self):
item = self["config"].getCurrent()
if item:
name = str(item[0])
desc = str(item[1].value)
else:
name = ""
desc = ""
for cb in self.onChangedEntry:
cb(name, desc)
def updateList(self, ret=None):
self.list = []
self.minidlna_name = NoSave(ConfigText(default=getBoxType(),fixed_size=False))
self.minidlna_iface = NoSave(ConfigText(fixed_size=False))
self.minidlna_port = NoSave(ConfigNumber())
self.minidlna_serialno = NoSave(ConfigNumber())
self.minidlna_web = NoSave(ConfigYesNo(default='True'))
self.minidlna_inotify = NoSave(ConfigYesNo(default='True'))
self.minidlna_tivo= NoSave(ConfigYesNo(default='True'))
self.minidlna_strictdlna= NoSave(ConfigYesNo(default='True'))
if fileExists('/etc/minidlna.conf'):
f = open('/etc/minidlna.conf', 'r')
for line in f.readlines():
line = line.strip()
if line.startswith('friendly_name='):
line = line[14:]
self.minidlna_name.value = line
minidlna_name1 = getConfigListEntry(_("Name") + ":", self.minidlna_name)
self.list.append(minidlna_name1)
elif line.startswith('network_interface='):
line = line[18:]
self.minidlna_iface.value = line
minidlna_iface1 = getConfigListEntry(_("Interface") + ":", self.minidlna_iface)
self.list.append(minidlna_iface1)
elif line.startswith('port='):
line = line[5:]
self.minidlna_port.value = line
minidlna_port1 = getConfigListEntry(_("Port") + ":", self.minidlna_port)
self.list.append(minidlna_port1)
elif line.startswith('serial='):
line = line[7:]
self.minidlna_serialno.value = line
minidlna_serialno1 = getConfigListEntry(_("Serial No") + ":", self.minidlna_serialno)
self.list.append(minidlna_serialno1)
elif line.startswith('inotify='):
if line[8:] == 'no':
self.minidlna_inotify.value = False
else:
self.minidlna_inotify.value = True
minidlna_inotify1 = getConfigListEntry(_("Inotify Monitoring") + ":", self.minidlna_inotify)
self.list.append(minidlna_inotify1)
elif line.startswith('enable_tivo='):
if line[12:] == 'no':
self.minidlna_tivo.value = False
else:
self.minidlna_tivo.value = True
minidlna_tivo1 = getConfigListEntry(_("TiVo support") + ":", self.minidlna_tivo)
self.list.append(minidlna_tivo1)
elif line.startswith('strict_dlna='):
if line[12:] == 'no':
self.minidlna_strictdlna.value = False
else:
self.minidlna_strictdlna.value = True
minidlna_strictdlna1 = getConfigListEntry(_("Strict DLNA") + ":", self.minidlna_strictdlna)
self.list.append(minidlna_strictdlna1)
f.close()
self['config'].list = self.list
self['config'].l.setList(self.list)
def KeyText(self):
sel = self['config'].getCurrent()
if sel:
if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
if self["config"].getCurrent()[1].help_window.instance is not None:
self["config"].getCurrent()[1].help_window.hide()
self.vkvar = sel[0]
if self.vkvar == _("Name") + ":" or self.vkvar == _("Share Folder's") + ":":
from Screens.VirtualKeyBoard import VirtualKeyBoard
self.session.openWithCallback(self.VirtualKeyBoardCallback, VirtualKeyBoard, title = self["config"].getCurrent()[0], text = self["config"].getCurrent()[1].value)
def VirtualKeyBoardCallback(self, callback = None):
if callback is not None and len(callback):
self["config"].getCurrent()[1].setValue(callback)
self["config"].invalidate(self["config"].getCurrent())
def saveMinidlna(self):
if fileExists('/etc/minidlna.conf'):
inme = open('/etc/minidlna.conf', 'r')
out = open('/etc/minidlna.conf.tmp', 'w')
for line in inme.readlines():
line = line.replace('\n', '')
if line.startswith('friendly_name='):
line = ('friendly_name=' + self.minidlna_name.value.strip())
elif line.startswith('network_interface='):
line = ('network_interface=' + self.minidlna_iface.value.strip())
elif line.startswith('port='):
line = ('port=' + str(self.minidlna_port.value))
elif line.startswith('serial='):
line = ('serial=' + str(self.minidlna_serialno.value))
elif line.startswith('media_dir='):
line = ('media_dir=' + ', '.join( config.networkminidlna.mediafolders.value ))
elif line.startswith('inotify='):
if not self.minidlna_inotify.value:
line = 'inotify=no'
else:
line = 'inotify=yes'
elif line.startswith('enable_tivo='):
if not self.minidlna_tivo.value:
line = 'enable_tivo=no'
else:
line = 'enable_tivo=yes'
elif line.startswith('strict_dlna='):
if not self.minidlna_strictdlna.value:
line = 'strict_dlna=no'
else:
line = 'strict_dlna=yes'
out.write((line + '\n'))
out.close()
inme.close()
else:
self.session.open(MessageBox, _("Sorry MiniDLNA Config is Missing"), MessageBox.TYPE_INFO)
self.close()
if fileExists('/etc/minidlna.conf.tmp'):
rename('/etc/minidlna.conf.tmp', '/etc/minidlna.conf')
self.myStop()
def myStop(self):
self.close()
def selectfolders(self):
self.session.openWithCallback(self.updateList,MiniDLNASelection)
class MiniDLNASelection(Screen):
def __init__(self, session):
Screen.__init__(self, session)
Screen.setTitle(self, _("Select folders"))
self.skinName = "uShareSelection"
self["key_red"] = StaticText(_("Cancel"))
self["key_green"] = StaticText(_("Save"))
self["key_yellow"] = StaticText()
if fileExists('/etc/minidlna.conf'):
f = open('/etc/minidlna.conf', 'r')
for line in f.readlines():
line = line.strip()
if line.startswith('media_dir='):
line = line[11:]
self.mediafolders = line
self.selectedFiles = [str(n) for n in self.mediafolders.split(', ')]
defaultDir = '/media/'
self.filelist = MultiFileSelectList(self.selectedFiles, defaultDir,showFiles = False )
self["checkList"] = self.filelist
self["actions"] = ActionMap(["DirectionActions", "OkCancelActions", "ShortcutActions"],
{
"cancel": self.exit,
"red": self.exit,
"yellow": self.changeSelectionState,
"green": self.saveSelection,
"ok": self.okClicked,
"left": self.left,
"right": self.right,
"down": self.down,
"up": self.up
}, -1)
if not self.selectionChanged in self["checkList"].onSelectionChanged:
self["checkList"].onSelectionChanged.append(self.selectionChanged)
self.onLayoutFinish.append(self.layoutFinished)
def layoutFinished(self):
idx = 0
self["checkList"].moveToIndex(idx)
self.selectionChanged()
def selectionChanged(self):
current = self["checkList"].getCurrent()[0]
if current[2] is True:
self["key_yellow"].setText(_("Deselect"))
else:
self["key_yellow"].setText(_("Select"))
def up(self):
self["checkList"].up()
def down(self):
self["checkList"].down()
def left(self):
self["checkList"].pageUp()
def right(self):
self["checkList"].pageDown()
def changeSelectionState(self):
self["checkList"].changeSelectionState()
self.selectedFiles = self["checkList"].getSelectedList()
def saveSelection(self):
self.selectedFiles = self["checkList"].getSelectedList()
config.networkminidlna.mediafolders.value = self.selectedFiles
self.close(None)
def exit(self):
self.close(None)
def okClicked(self):
if self.filelist.canDescent():
self.filelist.descent()
class NetworkMiniDLNALog(Screen):
def __init__(self, session):
Screen.__init__(self, session)
self.skinName = "NetworkInadynLog"
Screen.setTitle(self, _("MiniDLNA Log"))
self['infotext'] = ScrollLabel('')
self.Console = Console()
self['actions'] = ActionMap(['WizardActions', 'ColorActions'], {'ok': self.close, 'back': self.close, 'up': self['infotext'].pageUp, 'down': self['infotext'].pageDown})
strview = ''
self.Console.ePopen('tail /var/volatile/log/minidlna.log > /tmp/tmp.log')
time.sleep(1)
if fileExists('/tmp/tmp.log'):
f = open('/tmp/tmp.log', 'r')
for line in f.readlines():
strview += line
f.close()
remove('/tmp/tmp.log')
self['infotext'].setText(strview)
class NetworkServicesSummary(Screen):
def __init__(self, session, parent):
Screen.__init__(self, session, parent = parent)
self["title"] = StaticText("")
self["status_summary"] = StaticText("")
self["autostartstatus_summary"] = StaticText("")
self.onShow.append(self.addWatcher)
self.onHide.append(self.removeWatcher)
def addWatcher(self):
self.parent.onChangedEntry.append(self.selectionChanged)
self.parent.updateService()
def removeWatcher(self):
self.parent.onChangedEntry.remove(self.selectionChanged)
def selectionChanged(self, title, status_summary, autostartstatus_summary):
self["title"].text = title
self["status_summary"].text = status_summary
self["autostartstatus_summary"].text = autostartstatus_summary
|
gpl-2.0
|
[
504,
1234,
1774,
3759,
316,
492,
664,
3532,
804,
12,
664,
8412,
34,
3759,
12,
664,
8412,
985,
199,
504,
747,
492,
931,
465,
747,
63,
515,
12,
2813,
12,
17002,
12,
11441,
12,
30106,
12,
2879,
12,
1323,
63,
3593,
199,
504,
5145,
492,
4057,
199,
646,
900,
199,
199,
504,
655,
27021,
492,
325,
7929,
199,
199,
504,
29372,
14,
9616,
492,
17804,
199,
504,
29372,
14,
13695,
492,
28923,
199,
504,
29372,
14,
31060,
492,
7649,
24145,
6756,
3813,
199,
504,
29372,
14,
8673,
5977,
492,
15456,
461,
9616,
199,
504,
17823,
14,
18816,
492,
3595,
199,
504,
17823,
14,
9270,
492,
19809,
199,
504,
17823,
14,
4491,
492,
284,
4491,
199,
504,
17823,
14,
13959,
14,
25289,
492,
13599,
1872,
199,
504,
17823,
14,
13959,
14,
4082,
492,
9411,
199,
504,
17823,
14,
13959,
14,
1296,
492,
3820,
199,
504,
17823,
14,
3989,
2354,
492,
6187,
2354,
199,
504,
17823,
14,
4314,
492,
10354,
12,
6879,
4117,
4314,
199,
504,
17823,
14,
13127,
4314,
492,
13916,
2827,
4314,
199,
504,
17823,
14,
16049,
492,
510,
12879,
12,
6879,
16049,
199,
504,
17823,
14,
5977,
1296,
492,
18281,
1296,
199,
504,
17823,
14,
888,
492,
1101,
12,
4094,
31839,
12,
4094,
28246,
12,
4094,
1772,
12,
4094,
1872,
12,
4094,
6139,
12,
32245,
12,
664,
2028,
16934,
12,
4094,
3259,
12,
4094,
27727,
12,
3091,
8229,
12,
4094,
3399,
1872,
199,
504,
17823,
14,
2028,
1296,
492,
4094,
1296,
9616,
199,
504,
17823,
14,
5061,
7004,
492,
8963,
199,
504,
17823,
14,
1173,
1296,
492,
6879,
1173,
5446,
1296,
199,
504,
17823,
14,
3310,
2956,
492,
10033,
2956,
12,
4860,
3310,
2956,
12,
15456,
461,
3310,
2956,
199,
504,
23228,
14,
13752,
492,
570,
7965,
12,
7512,
8117,
12,
428,
1439,
1510,
63,
16483,
10789,
12,
428,
1439,
1510,
63,
10401,
63,
30619,
199,
504,
23228,
14,
6200,
16049,
492,
7190,
16049,
199,
504,
30317,
14,
5061,
492,
11349,
4311,
421,
199,
533,
7220,
10200,
7713,
8,
9616,
12,
8673,
461,
9616,
304,
199,
198,
318,
636,
826,
721,
277,
12,
2351,
304,
507,
198,
9616,
855,
826,
721,
277,
12,
2351,
9,
507,
198,
8673,
461,
9616,
855,
826,
721,
277,
9,
507,
198,
9616,
14,
31675,
8,
277,
12,
3824,
4491,
12439,
2237,
2742,
198,
277,
14,
87,
1502,
63,
705,
505,
275,
3824,
1944,
6449,
11799,
2003,
2784,
12146,
1911,
3134,
78,
8254,
4911,
626,
1265,
1172,
10102,
282,
9025,
644,
10825,
2243,
436,
2195,
2784,
365,
7526,
6657,
2685,
507,
198,
277,
14,
1502,
63,
705,
505,
275,
3824,
1944,
6449,
2257,
2784,
12146,
1911,
3134,
78,
8254,
4911,
626,
1265,
1172,
10102,
282,
2784,
286,
461,
436,
2195,
2784,
365,
7526,
6657,
2685,
507,
198,
277,
14,
745,
505,
275,
3824,
14414,
9949,
641,
2195,
3982,
3304,
370,
1980,
2685,
507,
198,
277,
14,
3773,
505,
275,
3824,
14414,
9949,
370,
5283,
314,
2202,
2685,
507,
198,
277,
14,
885,
505,
275,
3824,
14414,
31194,
370,
663,
642,
3217,
465,
314,
849,
3217,
2685,
507,
198,
277,
14,
10506,
44,
290,
2891,
275,
488,
2742,
198,
277,
905,
498,
63,
581,
937,
275,
13599,
1872,
6115,
4724,
2237,
507,
198,
277,
905,
498,
63,
7731,
937,
275,
13599,
1872,
6115,
5446,
2237,
507,
198,
277,
905,
498,
63,
14514,
937,
275,
13599,
1872,
10804,
507,
198,
277,
905,
498,
63,
6304,
937,
275,
13599,
1872,
10804,
507,
198,
277,
905,
18206,
5199,
937,
275,
13599,
1872,
8,
277,
14,
3773,
505,
9,
2742,
198,
277,
905,
11622,
9083,
9303,
937,
275,
15456,
461,
3310,
2956,
8,
277,
12,
298,
11622,
9083,
9303,
401,
686,
198,
91,
686,
198,
2,
6406,
582,
334,
277,
14,
1600,
12,
3824,
6699,
2784,
3217,
769,
8150,
686,
198,
2,
745,
582,
334,
277,
14,
745,
3887,
12040,
12,
3824,
5446,
3217,
8150,
686,
198,
1552,
2742,
198,
277,
905,
4117,
9303,
937,
275,
15456,
461,
3310,
2956,
8,
277,
12,
298,
4117,
9303,
401,
686,
198,
91,
686,
198,
2,
581,
582,
334,
277,
14,
1600,
12,
3824,
6699,
2784,
3217,
769,
8150,
686,
198,
2,
7731,
582,
334,
277,
14,
745,
3887,
12040,
12,
3824,
5446,
3217,
8150,
686,
198,
2,
6304,
582,
334,
277,
14,
1490,
4491,
20120,
12,
3824,
6119,
314,
2784,
12262,
370,
7908,
4895,
2784,
12146,
8150,
686,
198,
1552,
2742,
198,
277,
905,
2698,
4267,
3310,
937,
275,
15456,
461,
3310,
2956,
8,
277,
12,
298,
4117,
9303,
401,
686,
198,
91,
686,
198,
2,
14514,
582,
334,
277,
14,
409,
2698,
4267,
12,
359,
14332,
1084,
3217,
465,
314,
849,
14816,
1288,
14332,
10,
5972,
2808,
340,
1655,
2419,
1373,
3217,
365,
4702,
2685,
61,
2318,
686,
198,
1552,
2742,
198,
277,
14,
21680,
275,
3842,
73,
4491,
14,
362,
38,
11974,
10200,
985,
8,
88,
395,
88,
9,
367,
671,
315,
284,
4491,
14,
362,
10200,
1296,
5106,
2742,
198,
692,
440,
291,
14,
21680,
26,
686,
198,
277,
14,
21680,
275,
3842,
73,
4491,
14,
362,
38,
11974,
10200,
985,
8,
88,
395,
88,
9,
367,
671,
315,
284,
4491,
14,
362,
9902,
2767,
12552,
5106,
2742,
198,
692,
822,
8,
277,
14,
21680,
9,
508,
378,
26,
686,
198,
277,
14,
21680,
275,
3842,
73,
4491,
14,
362,
38,
11974,
10200,
985,
8,
88,
395,
88,
9,
367,
671,
315,
284,
4491,
14,
362,
21268,
2767,
12552,
5106,
2742,
198,
277,
14,
265,
6970,
3900,
275,
359,
1622,
507,
198,
277,
14,
513,
275,
942,
507,
198,
277,
905,
513,
937,
275,
3820,
8,
277,
14,
513,
9,
507,
198,
277,
14,
873,
1296,
342,
507,
198,
692,
440,
291,
14,
5592,
6970,
315,
291,
905,
513,
4140,
265,
7713,
6970,
26,
686,
198,
277,
905,
513,
4140,
265,
7713,
6970,
14,
740,
8,
277,
14,
5592,
6970,
9,
2742,
198,
692,
822,
8,
277,
14,
21680,
9,
508,
413,
26,
686,
198,
277,
14,
265,
7147,
4858,
5595,
14,
740,
8,
277,
14,
745,
3887,
12040,
9,
507,
198,
277,
14,
265,
4724,
14,
740,
8,
277,
14,
7661,
9,
421,
198,
318,
1218,
10407,
8,
277,
304,
507,
198,
504,
29372,
14,
5061,
11930,
492,
11349,
11930,
10407
] |
[
1234,
1774,
3759,
316,
492,
664,
3532,
804,
12,
664,
8412,
34,
3759,
12,
664,
8412,
985,
199,
504,
747,
492,
931,
465,
747,
63,
515,
12,
2813,
12,
17002,
12,
11441,
12,
30106,
12,
2879,
12,
1323,
63,
3593,
199,
504,
5145,
492,
4057,
199,
646,
900,
199,
199,
504,
655,
27021,
492,
325,
7929,
199,
199,
504,
29372,
14,
9616,
492,
17804,
199,
504,
29372,
14,
13695,
492,
28923,
199,
504,
29372,
14,
31060,
492,
7649,
24145,
6756,
3813,
199,
504,
29372,
14,
8673,
5977,
492,
15456,
461,
9616,
199,
504,
17823,
14,
18816,
492,
3595,
199,
504,
17823,
14,
9270,
492,
19809,
199,
504,
17823,
14,
4491,
492,
284,
4491,
199,
504,
17823,
14,
13959,
14,
25289,
492,
13599,
1872,
199,
504,
17823,
14,
13959,
14,
4082,
492,
9411,
199,
504,
17823,
14,
13959,
14,
1296,
492,
3820,
199,
504,
17823,
14,
3989,
2354,
492,
6187,
2354,
199,
504,
17823,
14,
4314,
492,
10354,
12,
6879,
4117,
4314,
199,
504,
17823,
14,
13127,
4314,
492,
13916,
2827,
4314,
199,
504,
17823,
14,
16049,
492,
510,
12879,
12,
6879,
16049,
199,
504,
17823,
14,
5977,
1296,
492,
18281,
1296,
199,
504,
17823,
14,
888,
492,
1101,
12,
4094,
31839,
12,
4094,
28246,
12,
4094,
1772,
12,
4094,
1872,
12,
4094,
6139,
12,
32245,
12,
664,
2028,
16934,
12,
4094,
3259,
12,
4094,
27727,
12,
3091,
8229,
12,
4094,
3399,
1872,
199,
504,
17823,
14,
2028,
1296,
492,
4094,
1296,
9616,
199,
504,
17823,
14,
5061,
7004,
492,
8963,
199,
504,
17823,
14,
1173,
1296,
492,
6879,
1173,
5446,
1296,
199,
504,
17823,
14,
3310,
2956,
492,
10033,
2956,
12,
4860,
3310,
2956,
12,
15456,
461,
3310,
2956,
199,
504,
23228,
14,
13752,
492,
570,
7965,
12,
7512,
8117,
12,
428,
1439,
1510,
63,
16483,
10789,
12,
428,
1439,
1510,
63,
10401,
63,
30619,
199,
504,
23228,
14,
6200,
16049,
492,
7190,
16049,
199,
504,
30317,
14,
5061,
492,
11349,
4311,
421,
199,
533,
7220,
10200,
7713,
8,
9616,
12,
8673,
461,
9616,
304,
199,
198,
318,
636,
826,
721,
277,
12,
2351,
304,
507,
198,
9616,
855,
826,
721,
277,
12,
2351,
9,
507,
198,
8673,
461,
9616,
855,
826,
721,
277,
9,
507,
198,
9616,
14,
31675,
8,
277,
12,
3824,
4491,
12439,
2237,
2742,
198,
277,
14,
87,
1502,
63,
705,
505,
275,
3824,
1944,
6449,
11799,
2003,
2784,
12146,
1911,
3134,
78,
8254,
4911,
626,
1265,
1172,
10102,
282,
9025,
644,
10825,
2243,
436,
2195,
2784,
365,
7526,
6657,
2685,
507,
198,
277,
14,
1502,
63,
705,
505,
275,
3824,
1944,
6449,
2257,
2784,
12146,
1911,
3134,
78,
8254,
4911,
626,
1265,
1172,
10102,
282,
2784,
286,
461,
436,
2195,
2784,
365,
7526,
6657,
2685,
507,
198,
277,
14,
745,
505,
275,
3824,
14414,
9949,
641,
2195,
3982,
3304,
370,
1980,
2685,
507,
198,
277,
14,
3773,
505,
275,
3824,
14414,
9949,
370,
5283,
314,
2202,
2685,
507,
198,
277,
14,
885,
505,
275,
3824,
14414,
31194,
370,
663,
642,
3217,
465,
314,
849,
3217,
2685,
507,
198,
277,
14,
10506,
44,
290,
2891,
275,
488,
2742,
198,
277,
905,
498,
63,
581,
937,
275,
13599,
1872,
6115,
4724,
2237,
507,
198,
277,
905,
498,
63,
7731,
937,
275,
13599,
1872,
6115,
5446,
2237,
507,
198,
277,
905,
498,
63,
14514,
937,
275,
13599,
1872,
10804,
507,
198,
277,
905,
498,
63,
6304,
937,
275,
13599,
1872,
10804,
507,
198,
277,
905,
18206,
5199,
937,
275,
13599,
1872,
8,
277,
14,
3773,
505,
9,
2742,
198,
277,
905,
11622,
9083,
9303,
937,
275,
15456,
461,
3310,
2956,
8,
277,
12,
298,
11622,
9083,
9303,
401,
686,
198,
91,
686,
198,
2,
6406,
582,
334,
277,
14,
1600,
12,
3824,
6699,
2784,
3217,
769,
8150,
686,
198,
2,
745,
582,
334,
277,
14,
745,
3887,
12040,
12,
3824,
5446,
3217,
8150,
686,
198,
1552,
2742,
198,
277,
905,
4117,
9303,
937,
275,
15456,
461,
3310,
2956,
8,
277,
12,
298,
4117,
9303,
401,
686,
198,
91,
686,
198,
2,
581,
582,
334,
277,
14,
1600,
12,
3824,
6699,
2784,
3217,
769,
8150,
686,
198,
2,
7731,
582,
334,
277,
14,
745,
3887,
12040,
12,
3824,
5446,
3217,
8150,
686,
198,
2,
6304,
582,
334,
277,
14,
1490,
4491,
20120,
12,
3824,
6119,
314,
2784,
12262,
370,
7908,
4895,
2784,
12146,
8150,
686,
198,
1552,
2742,
198,
277,
905,
2698,
4267,
3310,
937,
275,
15456,
461,
3310,
2956,
8,
277,
12,
298,
4117,
9303,
401,
686,
198,
91,
686,
198,
2,
14514,
582,
334,
277,
14,
409,
2698,
4267,
12,
359,
14332,
1084,
3217,
465,
314,
849,
14816,
1288,
14332,
10,
5972,
2808,
340,
1655,
2419,
1373,
3217,
365,
4702,
2685,
61,
2318,
686,
198,
1552,
2742,
198,
277,
14,
21680,
275,
3842,
73,
4491,
14,
362,
38,
11974,
10200,
985,
8,
88,
395,
88,
9,
367,
671,
315,
284,
4491,
14,
362,
10200,
1296,
5106,
2742,
198,
692,
440,
291,
14,
21680,
26,
686,
198,
277,
14,
21680,
275,
3842,
73,
4491,
14,
362,
38,
11974,
10200,
985,
8,
88,
395,
88,
9,
367,
671,
315,
284,
4491,
14,
362,
9902,
2767,
12552,
5106,
2742,
198,
692,
822,
8,
277,
14,
21680,
9,
508,
378,
26,
686,
198,
277,
14,
21680,
275,
3842,
73,
4491,
14,
362,
38,
11974,
10200,
985,
8,
88,
395,
88,
9,
367,
671,
315,
284,
4491,
14,
362,
21268,
2767,
12552,
5106,
2742,
198,
277,
14,
265,
6970,
3900,
275,
359,
1622,
507,
198,
277,
14,
513,
275,
942,
507,
198,
277,
905,
513,
937,
275,
3820,
8,
277,
14,
513,
9,
507,
198,
277,
14,
873,
1296,
342,
507,
198,
692,
440,
291,
14,
5592,
6970,
315,
291,
905,
513,
4140,
265,
7713,
6970,
26,
686,
198,
277,
905,
513,
4140,
265,
7713,
6970,
14,
740,
8,
277,
14,
5592,
6970,
9,
2742,
198,
692,
822,
8,
277,
14,
21680,
9,
508,
413,
26,
686,
198,
277,
14,
265,
7147,
4858,
5595,
14,
740,
8,
277,
14,
745,
3887,
12040,
9,
507,
198,
277,
14,
265,
4724,
14,
740,
8,
277,
14,
7661,
9,
421,
198,
318,
1218,
10407,
8,
277,
304,
507,
198,
504,
29372,
14,
5061,
11930,
492,
11349,
11930,
10407,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
direvus/ansible
|
lib/ansible/modules/cloud/google/gce_net.py
|
32
|
18212
|
#!/usr/bin/python
# Copyright 2013 Google Inc.
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: gce_net
version_added: "1.5"
short_description: create/destroy GCE networks and firewall rules
description:
- This module can create and destroy Google Compute Engine networks and
firewall rules U(https://cloud.google.com/compute/docs/networking).
The I(name) parameter is reserved for referencing a network while the
I(fwname) parameter is used to reference firewall rules.
IPv4 Address ranges must be specified using the CIDR
U(http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) format.
Full install/configuration instructions for the gce* modules can
be found in the comments of ansible/test/gce_tests.py.
options:
allowed:
description:
- the protocol:ports to allow (I(tcp:80) or I(tcp:80,443) or I(tcp:80-800;udp:1-25))
this parameter is mandatory when creating or updating a firewall rule
ipv4_range:
description:
- the IPv4 address range in CIDR notation for the network
this parameter is not mandatory when you specified existing network in name parameter,
but when you create new network, this parameter is mandatory
aliases: ['cidr']
fwname:
description:
- name of the firewall rule
aliases: ['fwrule']
name:
description:
- name of the network
src_range:
description:
- the source IPv4 address range in CIDR notation
default: []
aliases: ['src_cidr']
src_tags:
description:
- the source instance tags for creating a firewall rule
default: []
target_tags:
version_added: "1.9"
description:
- the target instance tags for creating a firewall rule
default: []
state:
description:
- desired state of the network or firewall
default: "present"
choices: ["active", "present", "absent", "deleted"]
service_account_email:
version_added: "1.6"
description:
- service account email
pem_file:
version_added: "1.6"
description:
- path to the pem file associated with the service account email
This option is deprecated. Use C(credentials_file).
credentials_file:
version_added: "2.1.0"
description:
- path to the JSON file associated with the service account email
project_id:
version_added: "1.6"
description:
- your GCE project ID
mode:
version_added: "2.2"
description:
- network mode for Google Cloud
C(legacy) indicates a network with an IP address range;
C(auto) automatically generates subnetworks in different regions;
C(custom) uses networks to group subnets of user specified IP address ranges
https://cloud.google.com/compute/docs/networking#network_types
default: "legacy"
choices: ["legacy", "auto", "custom"]
subnet_name:
version_added: "2.2"
description:
- name of subnet to create
subnet_region:
version_added: "2.2"
description:
- region of subnet to create
subnet_desc:
version_added: "2.2"
description:
- description of subnet to create
requirements:
- "python >= 2.6"
- "apache-libcloud >= 0.13.3, >= 0.17.0 if using JSON credentials"
author: "Eric Johnson (@erjohnso) <erjohnso@google.com>, Tom Melendez (@supertom) <supertom@google.com>"
'''
EXAMPLES = '''
# Create a 'legacy' Network
- name: Create Legacy Network
gce_net:
name: legacynet
ipv4_range: '10.24.17.0/24'
mode: legacy
state: present
# Create an 'auto' Network
- name: Create Auto Network
gce_net:
name: autonet
mode: auto
state: present
# Create a 'custom' Network
- name: Create Custom Network
gce_net:
name: customnet
mode: custom
subnet_name: "customsubnet"
subnet_region: us-east1
ipv4_range: '10.240.16.0/24'
state: "present"
# Create Firewall Rule with Source Tags
- name: Create Firewall Rule w/Source Tags
gce_net:
name: default
fwname: "my-firewall-rule"
allowed: tcp:80
state: "present"
src_tags: "foo,bar"
# Create Firewall Rule with Source Range
- name: Create Firewall Rule w/Source Range
gce_net:
name: default
fwname: "my-firewall-rule"
allowed: tcp:80
state: "present"
src_range: ['10.1.1.1/32']
# Create Custom Subnetwork
- name: Create Custom Subnetwork
gce_net:
name: privatenet
mode: custom
subnet_name: subnet_example
subnet_region: us-central1
ipv4_range: '10.0.0.0/16'
'''
RETURN = '''
allowed:
description: Rules (ports and protocols) specified by this firewall rule.
returned: When specified
type: string
sample: "tcp:80;icmp"
fwname:
description: Name of the firewall rule.
returned: When specified
type: string
sample: "my-fwname"
ipv4_range:
description: IPv4 range of the specified network or subnetwork.
returned: when specified or when a subnetwork is created
type: string
sample: "10.0.0.0/16"
name:
description: Name of the network.
returned: always
type: string
sample: "my-network"
src_range:
description: IP address blocks a firewall rule applies to.
returned: when specified
type: list
sample: [ '10.1.1.12/8' ]
src_tags:
description: Instance Tags firewall rule applies to.
returned: when specified while creating a firewall rule
type: list
sample: [ 'foo', 'bar' ]
state:
description: State of the item operated on.
returned: always
type: string
sample: "present"
subnet_name:
description: Name of the subnetwork.
returned: when specified or when a subnetwork is created
type: string
sample: "my-subnetwork"
subnet_region:
description: Region of the specified subnet.
returned: when specified or when a subnetwork is created
type: string
sample: "us-east1"
target_tags:
description: Instance Tags with these tags receive traffic allowed by firewall rule.
returned: when specified while creating a firewall rule
type: list
sample: [ 'foo', 'bar' ]
'''
try:
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
from libcloud.common.google import GoogleBaseError, QuotaExceededError, ResourceExistsError, ResourceNotFoundError
_ = Provider.GCE
HAS_LIBCLOUD = True
except ImportError:
HAS_LIBCLOUD = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.gce import gce_connect, unexpected_error_msg
def format_allowed_section(allowed):
"""Format each section of the allowed list"""
if allowed.count(":") == 0:
protocol = allowed
ports = []
elif allowed.count(":") == 1:
protocol, ports = allowed.split(":")
else:
return []
if ports.count(","):
ports = ports.split(",")
elif ports:
ports = [ports]
return_val = {"IPProtocol": protocol}
if ports:
return_val["ports"] = ports
return return_val
def format_allowed(allowed):
"""Format the 'allowed' value so that it is GCE compatible."""
return_value = []
if allowed.count(";") == 0:
return [format_allowed_section(allowed)]
else:
sections = allowed.split(";")
for section in sections:
return_value.append(format_allowed_section(section))
return return_value
def sorted_allowed_list(allowed_list):
"""Sort allowed_list (output of format_allowed) by protocol and port."""
# sort by protocol
allowed_by_protocol = sorted(allowed_list, key=lambda x: x['IPProtocol'])
# sort the ports list
return sorted(allowed_by_protocol, key=lambda y: sorted(y.get('ports', [])))
def main():
module = AnsibleModule(
argument_spec=dict(
allowed=dict(),
ipv4_range=dict(),
fwname=dict(),
name=dict(),
src_range=dict(default=[], type='list'),
src_tags=dict(default=[], type='list'),
target_tags=dict(default=[], type='list'),
state=dict(default='present'),
service_account_email=dict(),
pem_file=dict(type='path'),
credentials_file=dict(type='path'),
project_id=dict(),
mode=dict(default='legacy', choices=['legacy', 'auto', 'custom']),
subnet_name=dict(),
subnet_region=dict(),
subnet_desc=dict(),
)
)
if not HAS_LIBCLOUD:
module.fail_json(msg='libcloud with GCE support (0.17.0+) required for this module')
gce = gce_connect(module)
allowed = module.params.get('allowed')
ipv4_range = module.params.get('ipv4_range')
fwname = module.params.get('fwname')
name = module.params.get('name')
src_range = module.params.get('src_range')
src_tags = module.params.get('src_tags')
target_tags = module.params.get('target_tags')
state = module.params.get('state')
mode = module.params.get('mode')
subnet_name = module.params.get('subnet_name')
subnet_region = module.params.get('subnet_region')
subnet_desc = module.params.get('subnet_desc')
changed = False
json_output = {'state': state}
if state in ['active', 'present']:
network = None
subnet = None
try:
network = gce.ex_get_network(name)
json_output['name'] = name
if mode == 'legacy':
json_output['ipv4_range'] = network.cidr
if network and mode == 'custom' and subnet_name:
if not hasattr(gce, 'ex_get_subnetwork'):
module.fail_json(msg="Update libcloud to a more recent version (>1.0) that supports network 'mode' parameter", changed=False)
subnet = gce.ex_get_subnetwork(subnet_name, region=subnet_region)
json_output['subnet_name'] = subnet_name
json_output['ipv4_range'] = subnet.cidr
except ResourceNotFoundError:
pass
except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False)
# user wants to create a new network that doesn't yet exist
if name and not network:
if not ipv4_range and mode != 'auto':
module.fail_json(msg="Network '" + name + "' is not found. To create network in legacy or custom mode, 'ipv4_range' parameter is required",
changed=False)
args = [ipv4_range if mode == 'legacy' else None]
kwargs = {}
if mode != 'legacy':
kwargs['mode'] = mode
try:
network = gce.ex_create_network(name, *args, **kwargs)
json_output['name'] = name
json_output['ipv4_range'] = ipv4_range
changed = True
except TypeError:
module.fail_json(msg="Update libcloud to a more recent version (>1.0) that supports network 'mode' parameter", changed=False)
except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False)
if (subnet_name or ipv4_range) and not subnet and mode == 'custom':
if not hasattr(gce, 'ex_create_subnetwork'):
module.fail_json(msg='Update libcloud to a more recent version (>1.0) that supports subnetwork creation', changed=changed)
if not subnet_name or not ipv4_range or not subnet_region:
module.fail_json(msg="subnet_name, ipv4_range, and subnet_region required for custom mode", changed=changed)
try:
subnet = gce.ex_create_subnetwork(subnet_name, cidr=ipv4_range, network=name, region=subnet_region, description=subnet_desc)
json_output['subnet_name'] = subnet_name
json_output['ipv4_range'] = ipv4_range
changed = True
except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=changed)
if fwname:
# user creating a firewall rule
if not allowed and not src_range and not src_tags:
if changed and network:
module.fail_json(
msg="Network created, but missing required " + "firewall rule parameter(s)", changed=True)
module.fail_json(
msg="Missing required firewall rule parameter(s)",
changed=False)
allowed_list = format_allowed(allowed)
# Fetch existing rule and if it exists, compare attributes
# update if attributes changed. Create if doesn't exist.
try:
fw_changed = False
fw = gce.ex_get_firewall(fwname)
# If old and new attributes are different, we update the firewall rule.
# This implicitly lets us clear out attributes as well.
# allowed_list is required and must not be None for firewall rules.
if allowed_list and (sorted_allowed_list(allowed_list) != sorted_allowed_list(fw.allowed)):
fw.allowed = allowed_list
fw_changed = True
# source_ranges might not be set in the project; cast it to an empty list
fw.source_ranges = fw.source_ranges or []
# If these attributes are lists, we sort them first, then compare.
# Otherwise, we update if they differ.
if fw.source_ranges != src_range:
if isinstance(src_range, list):
if sorted(fw.source_ranges) != sorted(src_range):
fw.source_ranges = src_range
fw_changed = True
else:
fw.source_ranges = src_range
fw_changed = True
# source_tags might not be set in the project; cast it to an empty list
fw.source_tags = fw.source_tags or []
if fw.source_tags != src_tags:
if isinstance(src_tags, list):
if sorted(fw.source_tags) != sorted(src_tags):
fw.source_tags = src_tags
fw_changed = True
else:
fw.source_tags = src_tags
fw_changed = True
# target_tags might not be set in the project; cast it to an empty list
fw.target_tags = fw.target_tags or []
if fw.target_tags != target_tags:
if isinstance(target_tags, list):
if sorted(fw.target_tags) != sorted(target_tags):
fw.target_tags = target_tags
fw_changed = True
else:
fw.target_tags = target_tags
fw_changed = True
if fw_changed is True:
try:
gce.ex_update_firewall(fw)
changed = True
except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False)
# Firewall rule not found so we try to create it.
except ResourceNotFoundError:
try:
gce.ex_create_firewall(fwname, allowed_list, network=name,
source_ranges=src_range, source_tags=src_tags, target_tags=target_tags)
changed = True
except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False)
except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False)
json_output['fwname'] = fwname
json_output['allowed'] = allowed
json_output['src_range'] = src_range
json_output['src_tags'] = src_tags
json_output['target_tags'] = target_tags
if state in ['absent', 'deleted']:
if fwname:
json_output['fwname'] = fwname
fw = None
try:
fw = gce.ex_get_firewall(fwname)
except ResourceNotFoundError:
pass
except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False)
if fw:
gce.ex_destroy_firewall(fw)
changed = True
elif subnet_name:
if not hasattr(gce, 'ex_get_subnetwork') or not hasattr(gce, 'ex_destroy_subnetwork'):
module.fail_json(msg='Update libcloud to a more recent version (>1.0) that supports subnetwork creation', changed=changed)
json_output['name'] = subnet_name
subnet = None
try:
subnet = gce.ex_get_subnetwork(subnet_name, region=subnet_region)
except ResourceNotFoundError:
pass
except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False)
if subnet:
gce.ex_destroy_subnetwork(subnet)
changed = True
elif name:
json_output['name'] = name
network = None
try:
network = gce.ex_get_network(name)
except ResourceNotFoundError:
pass
except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False)
if network:
try:
gce.ex_destroy_network(network)
except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False)
changed = True
json_output['changed'] = changed
module.exit_json(**json_output)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1898,
6171,
4475,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
21319,
63,
846,
199,
1023,
63,
3270,
26,
298,
17,
14,
21,
2,
199,
3612,
63,
1802,
26,
1218,
15,
7237,
31556,
11759,
436,
12042,
4713,
199,
1802,
26,
272,
446,
961,
859,
883,
1218,
436,
11972,
4475,
8354,
12580,
11759,
436,
489,
12042,
4713,
738,
8,
2859,
921,
4091,
14,
3098,
14,
957,
15,
3357,
15,
4757,
15,
1200,
316,
680,
489,
710,
473,
8,
354,
9,
2725,
365,
4644,
367,
28524,
282,
2784,
1830,
314,
489,
473,
8,
8835,
354,
9,
2725,
365,
1202,
370,
3659,
12042,
4713,
14,
489,
6509,
20,
9906,
12271,
1471,
506,
2013,
1808,
314,
29215,
489,
738,
8,
1014,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
2543,
2003,
63,
2620,
13,
7705,
63,
8056,
9,
1475,
14,
489,
16579,
3907,
15,
4758,
15794,
367,
314,
21319,
10,
4621,
883,
489,
506,
1911,
315,
314,
6786,
402,
3242,
15,
396,
15,
22833,
63,
2219,
14,
647,
14,
199,
1419,
26,
523,
4370,
26,
272,
1369,
26,
489,
446,
314,
4113,
26,
5203,
370,
2040,
334,
41,
8,
8815,
26,
1257,
9,
503,
473,
8,
8815,
26,
1257,
12,
16284,
9,
503,
473,
8,
8815,
26,
1257,
13,
6718,
27,
15036,
26,
17,
13,
821,
430,
267,
642,
2725,
365,
15230,
1380,
6425,
503,
12928,
282,
12042,
2332,
523,
3278,
20,
63,
1842,
26,
272,
1369,
26,
489,
446,
314,
6509,
20,
2287,
1425,
315,
29215,
15843,
367,
314,
2784,
267,
642,
2725,
365,
440,
15230,
1380,
1265,
2013,
3411,
2784,
315,
536,
2725,
12,
267,
1325,
1380,
1265,
1218,
892,
2784,
12,
642,
2725,
365,
15230,
272,
5481,
26,
788,
10509,
418,
523,
13908,
354,
26,
272,
1369,
26,
489,
446,
536,
402,
314,
12042,
2332,
272,
5481,
26,
788,
8835,
2200,
418,
523,
536,
26,
272,
1369,
26,
489,
446,
536,
402,
314,
2784,
523,
2928,
63,
1842,
26,
272,
1369,
26,
489,
446,
314,
1350,
6509,
20,
2287,
1425,
315,
29215,
15843,
272,
849,
26,
942,
272,
5481,
26,
788,
2164,
63,
10509,
418,
523,
2928,
63,
2969,
26,
272,
1369,
26,
489,
446,
314,
1350,
1256,
3762,
367,
6425,
282,
12042,
2332,
272,
849,
26,
942,
523,
1347,
63,
2969,
26,
272,
1015,
63,
3270,
26,
298,
17,
14,
25,
2,
272,
1369,
26,
489,
446,
314,
1347,
1256,
3762,
367,
6425,
282,
12042,
2332,
272,
849,
26,
942,
523,
1174,
26,
272,
1369,
26,
489,
446,
6387,
1174,
402,
314,
2784,
503,
12042,
272,
849,
26,
298,
1881,
2,
272,
3415,
26,
2097,
2682,
401,
298,
1881,
401,
298,
5575,
401,
298,
6062,
937,
523,
2435,
63,
2048,
63,
2123,
26,
272,
1015,
63,
3270,
26,
298,
17,
14,
22,
2,
272,
1369,
26,
489,
446,
2435,
2933,
3031,
523,
4837,
77,
63,
493,
26,
272,
1015,
63,
3270,
26,
298,
17,
14,
22,
2,
272,
1369,
26,
489,
446,
931,
370,
314,
4837,
77,
570,
4568,
543,
314,
2435,
2933,
3031,
267,
961,
945,
365,
5906,
14,
3645,
445,
8,
6942,
63,
493,
680,
523,
6235,
63,
493,
26,
272,
1015,
63,
3270,
26,
298,
18,
14,
17,
14,
16,
2,
272,
1369,
26,
489,
446,
931,
370,
314,
4840,
570,
4568,
543,
314,
2435,
2933,
3031,
523,
2199,
63,
344,
26,
272,
1015,
63,
3270,
26,
298,
17,
14,
22,
2,
272,
1369,
26,
489,
446,
2195,
31556,
2199,
2870,
523,
818,
26,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
272,
1369,
26,
489,
446,
2784,
818,
367,
4475,
8142,
267,
445,
8,
10000,
9,
9126,
282,
2784,
543,
376,
3531,
2287,
1425,
27,
267,
445,
8,
2495,
9,
5847,
12821,
1007,
7642,
315,
3365,
16150,
27,
267,
445,
8,
4229,
9,
4440,
11759,
370,
1572,
18709,
402,
922,
2013,
3531,
2287,
12271,
267,
4178,
921,
4091,
14,
3098,
14,
957,
15,
3357,
15,
4757,
15,
1200,
316,
3,
1200,
63,
1313,
272,
849,
26,
298,
10000,
2,
272,
3415,
26,
2097,
10000,
401,
298,
2495,
401,
298,
4229,
937,
523,
6303,
63,
354,
26,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
272,
1369,
26,
489,
446,
536,
402,
6303,
370,
1218,
523,
6303,
63,
4551,
26,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
272,
1369,
26,
489,
446,
4897,
402,
6303,
370,
1218,
523,
6303,
63,
3257,
26,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
272,
1369,
26,
489,
446,
1369,
402,
6303,
370,
1218,
199,
199,
7538,
26,
272,
446,
298,
1548,
2356,
499,
14,
22,
2,
272,
446,
298,
3796,
13,
30651,
2356,
378,
14,
969,
14,
19,
12,
2356,
378,
14,
1196,
14,
16,
340,
1808,
4840,
6235,
2,
199,
2502,
26,
298,
37,
1567,
7135,
25338,
265,
8593,
281,
743,
25338,
79,
9,
665,
281,
743,
25338,
79,
32,
3098,
14,
957,
6244,
21644,
3194,
552,
271,
90,
8593,
4792,
3151,
9,
665,
4792,
3151,
32,
3098,
14,
957,
4335,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2790,
282,
283,
10000,
7,
7220,
199,
13,
536,
26,
2790,
26251,
7220,
523,
21319,
63,
846,
26,
272,
536,
26,
12139,
846,
272,
3278,
20,
63,
1842,
26,
283,
709,
14,
1194,
14,
1196,
14,
16,
15,
1194,
7,
272,
818,
26,
12139,
272,
1174,
26,
3451,
199,
199,
3,
2790,
376,
283,
2495,
7,
7220,
199,
13,
536,
26,
2790,
9195,
7220,
523,
21319,
63,
846,
26,
272,
536,
26,
6384,
25759,
272,
818,
26,
2599,
272,
1174,
26,
3451,
199,
199,
3,
2790,
282,
283,
4229,
7,
7220,
199,
13,
536
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1898,
6171,
4475,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
21319,
63,
846,
199,
1023,
63,
3270,
26,
298,
17,
14,
21,
2,
199,
3612,
63,
1802,
26,
1218,
15,
7237,
31556,
11759,
436,
12042,
4713,
199,
1802,
26,
272,
446,
961,
859,
883,
1218,
436,
11972,
4475,
8354,
12580,
11759,
436,
489,
12042,
4713,
738,
8,
2859,
921,
4091,
14,
3098,
14,
957,
15,
3357,
15,
4757,
15,
1200,
316,
680,
489,
710,
473,
8,
354,
9,
2725,
365,
4644,
367,
28524,
282,
2784,
1830,
314,
489,
473,
8,
8835,
354,
9,
2725,
365,
1202,
370,
3659,
12042,
4713,
14,
489,
6509,
20,
9906,
12271,
1471,
506,
2013,
1808,
314,
29215,
489,
738,
8,
1014,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
2543,
2003,
63,
2620,
13,
7705,
63,
8056,
9,
1475,
14,
489,
16579,
3907,
15,
4758,
15794,
367,
314,
21319,
10,
4621,
883,
489,
506,
1911,
315,
314,
6786,
402,
3242,
15,
396,
15,
22833,
63,
2219,
14,
647,
14,
199,
1419,
26,
523,
4370,
26,
272,
1369,
26,
489,
446,
314,
4113,
26,
5203,
370,
2040,
334,
41,
8,
8815,
26,
1257,
9,
503,
473,
8,
8815,
26,
1257,
12,
16284,
9,
503,
473,
8,
8815,
26,
1257,
13,
6718,
27,
15036,
26,
17,
13,
821,
430,
267,
642,
2725,
365,
15230,
1380,
6425,
503,
12928,
282,
12042,
2332,
523,
3278,
20,
63,
1842,
26,
272,
1369,
26,
489,
446,
314,
6509,
20,
2287,
1425,
315,
29215,
15843,
367,
314,
2784,
267,
642,
2725,
365,
440,
15230,
1380,
1265,
2013,
3411,
2784,
315,
536,
2725,
12,
267,
1325,
1380,
1265,
1218,
892,
2784,
12,
642,
2725,
365,
15230,
272,
5481,
26,
788,
10509,
418,
523,
13908,
354,
26,
272,
1369,
26,
489,
446,
536,
402,
314,
12042,
2332,
272,
5481,
26,
788,
8835,
2200,
418,
523,
536,
26,
272,
1369,
26,
489,
446,
536,
402,
314,
2784,
523,
2928,
63,
1842,
26,
272,
1369,
26,
489,
446,
314,
1350,
6509,
20,
2287,
1425,
315,
29215,
15843,
272,
849,
26,
942,
272,
5481,
26,
788,
2164,
63,
10509,
418,
523,
2928,
63,
2969,
26,
272,
1369,
26,
489,
446,
314,
1350,
1256,
3762,
367,
6425,
282,
12042,
2332,
272,
849,
26,
942,
523,
1347,
63,
2969,
26,
272,
1015,
63,
3270,
26,
298,
17,
14,
25,
2,
272,
1369,
26,
489,
446,
314,
1347,
1256,
3762,
367,
6425,
282,
12042,
2332,
272,
849,
26,
942,
523,
1174,
26,
272,
1369,
26,
489,
446,
6387,
1174,
402,
314,
2784,
503,
12042,
272,
849,
26,
298,
1881,
2,
272,
3415,
26,
2097,
2682,
401,
298,
1881,
401,
298,
5575,
401,
298,
6062,
937,
523,
2435,
63,
2048,
63,
2123,
26,
272,
1015,
63,
3270,
26,
298,
17,
14,
22,
2,
272,
1369,
26,
489,
446,
2435,
2933,
3031,
523,
4837,
77,
63,
493,
26,
272,
1015,
63,
3270,
26,
298,
17,
14,
22,
2,
272,
1369,
26,
489,
446,
931,
370,
314,
4837,
77,
570,
4568,
543,
314,
2435,
2933,
3031,
267,
961,
945,
365,
5906,
14,
3645,
445,
8,
6942,
63,
493,
680,
523,
6235,
63,
493,
26,
272,
1015,
63,
3270,
26,
298,
18,
14,
17,
14,
16,
2,
272,
1369,
26,
489,
446,
931,
370,
314,
4840,
570,
4568,
543,
314,
2435,
2933,
3031,
523,
2199,
63,
344,
26,
272,
1015,
63,
3270,
26,
298,
17,
14,
22,
2,
272,
1369,
26,
489,
446,
2195,
31556,
2199,
2870,
523,
818,
26,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
272,
1369,
26,
489,
446,
2784,
818,
367,
4475,
8142,
267,
445,
8,
10000,
9,
9126,
282,
2784,
543,
376,
3531,
2287,
1425,
27,
267,
445,
8,
2495,
9,
5847,
12821,
1007,
7642,
315,
3365,
16150,
27,
267,
445,
8,
4229,
9,
4440,
11759,
370,
1572,
18709,
402,
922,
2013,
3531,
2287,
12271,
267,
4178,
921,
4091,
14,
3098,
14,
957,
15,
3357,
15,
4757,
15,
1200,
316,
3,
1200,
63,
1313,
272,
849,
26,
298,
10000,
2,
272,
3415,
26,
2097,
10000,
401,
298,
2495,
401,
298,
4229,
937,
523,
6303,
63,
354,
26,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
272,
1369,
26,
489,
446,
536,
402,
6303,
370,
1218,
523,
6303,
63,
4551,
26,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
272,
1369,
26,
489,
446,
4897,
402,
6303,
370,
1218,
523,
6303,
63,
3257,
26,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
272,
1369,
26,
489,
446,
1369,
402,
6303,
370,
1218,
199,
199,
7538,
26,
272,
446,
298,
1548,
2356,
499,
14,
22,
2,
272,
446,
298,
3796,
13,
30651,
2356,
378,
14,
969,
14,
19,
12,
2356,
378,
14,
1196,
14,
16,
340,
1808,
4840,
6235,
2,
199,
2502,
26,
298,
37,
1567,
7135,
25338,
265,
8593,
281,
743,
25338,
79,
9,
665,
281,
743,
25338,
79,
32,
3098,
14,
957,
6244,
21644,
3194,
552,
271,
90,
8593,
4792,
3151,
9,
665,
4792,
3151,
32,
3098,
14,
957,
4335,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2790,
282,
283,
10000,
7,
7220,
199,
13,
536,
26,
2790,
26251,
7220,
523,
21319,
63,
846,
26,
272,
536,
26,
12139,
846,
272,
3278,
20,
63,
1842,
26,
283,
709,
14,
1194,
14,
1196,
14,
16,
15,
1194,
7,
272,
818,
26,
12139,
272,
1174,
26,
3451,
199,
199,
3,
2790,
376,
283,
2495,
7,
7220,
199,
13,
536,
26,
2790,
9195,
7220,
523,
21319,
63,
846,
26,
272,
536,
26,
6384,
25759,
272,
818,
26,
2599,
272,
1174,
26,
3451,
199,
199,
3,
2790,
282,
283,
4229,
7,
7220,
199,
13,
536,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
LIBOTAO/keras
|
keras/layers/core.py
|
1
|
23220
|
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division
import theano
import theano.tensor as T
import numpy as np
from .. import activations, initializations, regularizers, constraints
from ..utils.theano_utils import shared_zeros, floatX
from ..utils.generic_utils import make_tuple
from ..regularizers import ActivityRegularizer, Regularizer
from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
from six.moves import zip
class Layer(object):
def __init__(self):
self.params = []
def init_updates(self):
self.updates = []
def set_previous(self, layer, connection_map={}):
assert self.nb_input == layer.nb_output == 1, "Cannot connect layers: input count and output count should be 1."
if not self.supports_masked_input() and layer.get_output_mask() is not None:
raise Exception("Cannot connect non-masking layer to layer with masked output")
self.previous = layer
@property
def nb_input(self):
return 1
@property
def nb_output(self):
return 1
def get_output(self, train=False):
return self.get_input(train)
def get_input(self, train=False):
if hasattr(self, 'previous'):
return self.previous.get_output(train=train)
else:
return self.input
def supports_masked_input(self):
''' Whether or not this layer respects the output mask of its previous layer in its calculations. If you try
to attach a layer that does *not* support masked_input to a layer that gives a non-None output_mask() that is
an error'''
return False
def get_output_mask(self, train=None):
'''
For some models (such as RNNs) you want a way of being able to mark some output data-points as
"masked", so they are not used in future calculations. In such a model, get_output_mask() should return a mask
of one less dimension than get_output() (so if get_output is (nb_samples, nb_timesteps, nb_dimensions), then the mask
is (nb_samples, nb_timesteps), with a one for every unmasked datapoint, and a zero for every masked one.
If there is *no* masking then it shall return None. For instance if you attach an Activation layer (they support masking)
to a layer with an output_mask, then that Activation shall also have an output_mask. If you attach it to a layer with no
such mask, then the Activation's get_output_mask shall return None.
Some layers have an output_mask even if their input is unmasked, notably Embedding which can turn the entry "0" into
a mask.
'''
return None
def set_weights(self, weights):
for p, w in zip(self.params, weights):
if p.eval().shape != w.shape:
raise Exception("Layer shape %s not compatible with weight shape %s." % (p.eval().shape, w.shape))
p.set_value(floatX(w))
def get_weights(self):
weights = []
for p in self.params:
weights.append(p.get_value())
return weights
def get_config(self):
return {"name": self.__class__.__name__}
def get_params(self):
consts = []
updates = []
if hasattr(self, 'regularizers'):
regularizers = self.regularizers
else:
regularizers = []
if hasattr(self, 'constraints') and len(self.constraints) == len(self.params):
for c in self.constraints:
if c:
consts.append(c)
else:
consts.append(constraints.identity())
elif hasattr(self, 'constraint') and self.constraint:
consts += [self.constraint for _ in range(len(self.params))]
else:
consts += [constraints.identity() for _ in range(len(self.params))]
if hasattr(self, 'updates') and self.updates:
updates += self.updates
return self.params, regularizers, consts, updates
def set_name(self, name):
for i in range(len(self.params)):
self.params[i].name = '%s_p%d' % (name, i)
class MaskedLayer(Layer):
'''
If your layer trivially supports masking (by simply copying the input mask to the output), then subclass MaskedLayer
instead of Layer, and make sure that you incorporate the input mask into your calculation of get_output()
'''
def supports_masked_input(self):
return True
def get_input_mask(self, train=False):
if hasattr(self, 'previous'):
return self.previous.get_output_mask(train)
else:
return None
def get_output_mask(self, train=False):
''' The default output mask is just the input mask unchanged. Override this in your own
implementations if, for instance, you are reshaping the input'''
return self.get_input_mask(train)
class Masking(MaskedLayer):
"""Mask an input sequence by using a mask value to identify padding.
This layer copies the input to the output layer with identified padding
replaced with 0s and creates an output mask in the process.
At each timestep, if the values all equal `mask_value`,
then the corresponding mask value for the timestep is 0 (skipped),
otherwise it is 1.
"""
def __init__(self, mask_value=0.):
super(Masking, self).__init__()
self.mask_value = mask_value
self.input = T.tensor3()
def get_output_mask(self, train=False):
X = self.get_input(train)
return T.any(T.ones_like(X) * (1. - T.eq(X, self.mask_value)), axis=-1)
def get_output(self, train=False):
X = self.get_input(train)
return X * T.shape_padright(T.any((1. - T.eq(X, self.mask_value)), axis=-1))
def get_config(self):
return {"name": self.__class__.__name__,
"mask_value": self.mask_value}
class Merge(Layer):
def __init__(self, layers, mode='sum'):
''' Merge the output of a list of layers or containers into a single tensor.
mode: {'sum', 'mul', 'concat'}
'''
if len(layers) < 2:
raise Exception("Please specify two or more input layers (or containers) to merge")
self.mode = mode
self.layers = layers
self.params = []
self.regularizers = []
self.constraints = []
self.updates = []
for l in self.layers:
params, regs, consts, updates = l.get_params()
self.regularizers += regs
self.updates += updates
# params and constraints have the same size
for p, c in zip(params, consts):
if p not in self.params:
self.params.append(p)
self.constraints.append(c)
def get_params(self):
return self.params, self.regularizers, self.constraints, self.updates
def get_output(self, train=False):
if self.mode == 'sum':
s = self.layers[0].get_output(train)
for i in range(1, len(self.layers)):
s += self.layers[i].get_output(train)
return s
elif self.mode == 'concat':
inputs = [self.layers[i].get_output(train) for i in range(len(self.layers))]
return T.concatenate(inputs, axis=-1)
elif self.mode == 'mul':
s = self.layers[0].get_output(train)
for i in range(1, len(self.layers)):
s *= self.layers[i].get_output(train)
return s
else:
raise Exception('Unknown merge mode')
def get_input(self, train=False):
res = []
for i in range(len(self.layers)):
o = self.layers[i].get_input(train)
if not type(o) == list:
o = [o]
for output in o:
if output not in res:
res.append(output)
return res
@property
def input(self):
return self.get_input()
def supports_masked_input(self):
return False
def get_output_mask(self, train=None):
return None
def get_weights(self):
weights = []
for l in self.layers:
weights += l.get_weights()
return weights
def set_weights(self, weights):
for i in range(len(self.layers)):
nb_param = len(self.layers[i].params)
self.layers[i].set_weights(weights[:nb_param])
weights = weights[nb_param:]
def get_config(self):
return {"name": self.__class__.__name__,
"layers": [l.get_config() for l in self.layers],
"mode": self.mode}
class Dropout(MaskedLayer):
'''
Hinton's dropout.
'''
def __init__(self, p):
super(Dropout, self).__init__()
self.p = p
self.srng = RandomStreams(seed=np.random.randint(10e6))
def get_output(self, train=False):
X = self.get_input(train)
if self.p > 0.:
retain_prob = 1. - self.p
if train:
X *= self.srng.binomial(X.shape, p=retain_prob, dtype=theano.config.floatX)
else:
X *= retain_prob
return X
def get_config(self):
return {"name": self.__class__.__name__,
"p": self.p}
class Activation(MaskedLayer):
'''
Apply an activation function to an output.
'''
def __init__(self, activation, target=0, beta=0.1):
super(Activation, self).__init__()
self.activation = activations.get(activation)
self.target = target
self.beta = beta
def get_output(self, train=False):
X = self.get_input(train)
return self.activation(X)
def get_config(self):
return {"name": self.__class__.__name__,
"activation": self.activation.__name__,
"target": self.target,
"beta": self.beta}
class Reshape(Layer):
'''
Reshape an output to a certain shape.
Can't be used as first layer in a model (no fixed input!)
First dimension is assumed to be nb_samples.
'''
def __init__(self, *dims):
super(Reshape, self).__init__()
self.dims = dims
def get_output(self, train=False):
X = self.get_input(train)
nshape = make_tuple(X.shape[0], *self.dims)
return theano.tensor.reshape(X, nshape)
def get_config(self):
return {"name": self.__class__.__name__,
"dims": self.dims}
class Permute(Layer):
'''
Permute the dimensions of the data according to the given tuple
'''
def __init__(self, dims):
super(Permute, self).__init__()
self.dims = dims
def get_output(self, train):
X = self.get_input(train)
return X.dimshuffle((0,) + self.dims)
def get_config(self):
return {"name": self.__class__.__name__,
"dims": self.dims}
class Flatten(Layer):
'''
Reshape input to flat shape.
First dimension is assumed to be nb_samples.
'''
def __init__(self):
super(Flatten, self).__init__()
def get_output(self, train=False):
X = self.get_input(train)
size = theano.tensor.prod(X.shape) // X.shape[0]
nshape = (X.shape[0], size)
return theano.tensor.reshape(X, nshape)
class RepeatVector(Layer):
'''
Repeat input n times.
Dimensions of input are assumed to be (nb_samples, dim).
Return tensor of shape (nb_samples, n, dim).
'''
def __init__(self, n):
super(RepeatVector, self).__init__()
self.n = n
def get_output(self, train=False):
X = self.get_input(train)
tensors = [X]*self.n
stacked = theano.tensor.stack(*tensors)
return stacked.dimshuffle((1, 0, 2))
def get_config(self):
return {"name": self.__class__.__name__,
"n": self.n}
class Dense(Layer):
'''
Just your regular fully connected NN layer.
'''
def __init__(self, input_dim, output_dim, init='glorot_uniform', activation='linear', weights=None, name=None,
W_regularizer=None, b_regularizer=None, activity_regularizer=None,
W_constraint=None, b_constraint=None):
super(Dense, self).__init__()
self.init = initializations.get(init)
self.activation = activations.get(activation)
self.input_dim = input_dim
self.output_dim = output_dim
self.input = T.matrix()
self.W = self.init((self.input_dim, self.output_dim))
self.b = shared_zeros((self.output_dim))
self.params = [self.W, self.b]
self.regularizers = []
self.W_regularizer = regularizers.get(W_regularizer)
if self.W_regularizer:
self.W_regularizer.set_param(self.W)
self.regularizers.append(self.W_regularizer)
self.b_regularizer = regularizers.get(b_regularizer)
if self.b_regularizer:
self.b_regularizer.set_param(self.b)
self.regularizers.append(self.b_regularizer)
self.activity_regularizer = regularizers.get(activity_regularizer)
if self.activity_regularizer:
self.activity_regularizer.set_layer(self)
self.regularizers.append(self.activity_regularizer)
self.W_constraint = constraints.get(W_constraint)
self.b_constraint = constraints.get(b_constraint)
self.constraints = [self.W_constraint, self.b_constraint]
if weights is not None:
self.set_weights(weights)
if name is not None:
self.set_name(name)
def set_name(self, name):
self.W.name = '%s_W' % name
self.b.name = '%s_b' % name
def get_output(self, train=False):
X = self.get_input(train)
output = self.activation(T.dot(X, self.W) + self.b)
return output
def get_config(self):
return {"name": self.__class__.__name__,
"input_dim": self.input_dim,
"output_dim": self.output_dim,
"init": self.init.__name__,
"activation": self.activation.__name__,
"W_regularizer": self.W_regularizer.get_config() if self.W_regularizer else None,
"b_regularizer": self.b_regularizer.get_config() if self.b_regularizer else None,
"activity_regularizer": self.activity_regularizer.get_config() if self.activity_regularizer else None,
"W_constraint": self.W_constraint.get_config() if self.W_constraint else None,
"b_constraint": self.b_constraint.get_config() if self.b_constraint else None}
class ActivityRegularization(Layer):
'''
Layer that passes through its input unchanged, but applies an update
to the cost function based on the activity.
'''
def __init__(self, l1=0., l2=0.):
super(ActivityRegularization, self).__init__()
self.l1 = l1
self.l2 = l2
activity_regularizer = ActivityRegularizer(l1=l1, l2=l2)
activity_regularizer.set_layer(self)
self.regularizers = [activity_regularizer]
def get_output(self, train=False):
return self.get_input(train)
def get_config(self):
return {"name": self.__class__.__name__,
"l1": self.l1,
"l2": self.l2}
class TimeDistributedDense(MaskedLayer):
'''
Apply a same DenseLayer for each dimension[1] (shared_dimension) input
Especially useful after a recurrent network with 'return_sequence=True'
Tensor input dimensions: (nb_sample, shared_dimension, input_dim)
Tensor output dimensions: (nb_sample, shared_dimension, output_dim)
'''
def __init__(self, input_dim, output_dim, init='glorot_uniform', activation='linear', weights=None,
W_regularizer=None, b_regularizer=None, activity_regularizer=None,
W_constraint=None, b_constraint=None):
super(TimeDistributedDense, self).__init__()
self.init = initializations.get(init)
self.activation = activations.get(activation)
self.input_dim = input_dim
self.output_dim = output_dim
self.input = T.tensor3()
self.W = self.init((self.input_dim, self.output_dim))
self.b = shared_zeros((self.output_dim))
self.params = [self.W, self.b]
self.regularizers = []
self.W_regularizer = regularizers.get(W_regularizer)
if self.W_regularizer:
self.W_regularizer.set_param(self.W)
self.regularizers.append(self.W_regularizer)
self.b_regularizer = regularizers.get(b_regularizer)
if self.b_regularizer:
self.b_regularizer.set_param(self.b)
self.regularizers.append(self.b_regularizer)
self.activity_regularizer = regularizers.get(activity_regularizer)
if self.activity_regularizer:
self.activity_regularizer.set_layer(self)
self.regularizers.append(self.activity_regularizer)
self.W_constraint = constraints.get(W_constraint)
self.b_constraint = constraints.get(b_constraint)
self.constraints = [self.W_constraint, self.b_constraint]
if weights is not None:
self.set_weights(weights)
def get_output(self, train=False):
X = self.get_input(train)
output = self.activation(T.dot(X.dimshuffle(1, 0, 2), self.W) + self.b)
return output.dimshuffle(1, 0, 2)
def get_config(self):
return {"name": self.__class__.__name__,
"input_dim": self.input_dim,
"output_dim": self.output_dim,
"init": self.init.__name__,
"activation": self.activation.__name__,
"W_regularizer": self.W_regularizer.get_config() if self.W_regularizer else None,
"b_regularizer": self.b_regularizer.get_config() if self.b_regularizer else None,
"activity_regularizer": self.activity_regularizer.get_config() if self.activity_regularizer else None,
"W_constraint": self.W_constraint.get_config() if self.W_constraint else None,
"b_constraint": self.b_constraint.get_config() if self.b_constraint else None}
class AutoEncoder(Layer):
'''
A customizable autoencoder model.
If output_reconstruction then dim(input) = dim(output)
else dim(output) = dim(hidden)
'''
def __init__(self, encoder, decoder, output_reconstruction=True, weights=None):
super(AutoEncoder, self).__init__()
self.output_reconstruction = output_reconstruction
self.encoder = encoder
self.decoder = decoder
self.decoder.set_previous(self.encoder)
self.params = []
self.regularizers = []
self.constraints = []
self.updates = []
for layer in [self.encoder, self.decoder]:
params, regularizers, constraints, updates = layer.get_params()
self.regularizers += regularizers
self.updates += updates
for p, c in zip(params, constraints):
if p not in self.params:
self.params.append(p)
self.constraints.append(c)
if weights is not None:
self.set_weights(weights)
def set_previous(self, node):
self.encoder.set_previous(node)
def get_weights(self):
weights = []
for layer in [self.encoder, self.decoder]:
weights += layer.get_weights()
return weights
def set_weights(self, weights):
nb_param = len(self.encoder.params)
self.encoder.set_weights(weights[:nb_param])
self.decoder.set_weights(weights[nb_param:])
def get_input(self, train=False):
return self.encoder.get_input(train)
@property
def input(self):
return self.encoder.input
def _get_hidden(self, train=False):
return self.encoder.get_output(train)
def get_output(self, train=False):
if not train and not self.output_reconstruction:
return self.encoder.get_output(train)
return self.decoder.get_output(train)
def get_config(self):
return {"name": self.__class__.__name__,
"encoder_config": self.encoder.get_config(),
"decoder_config": self.decoder.get_config(),
"output_reconstruction": self.output_reconstruction}
class MaxoutDense(Layer):
'''
Max-out layer, nb_feature is the number of pieces in the piecewise linear approx.
Refer to http://arxiv.org/pdf/1302.4389.pdf
'''
def __init__(self, input_dim, output_dim, nb_feature=4, init='glorot_uniform', weights=None,
W_regularizer=None, b_regularizer=None, activity_regularizer=None,
W_constraint=None, b_constraint=None):
super(MaxoutDense, self).__init__()
self.init = initializations.get(init)
self.input_dim = input_dim
self.output_dim = output_dim
self.nb_feature = nb_feature
self.input = T.matrix()
self.W = self.init((self.nb_feature, self.input_dim, self.output_dim))
self.b = shared_zeros((self.nb_feature, self.output_dim))
self.params = [self.W, self.b]
self.regularizers = []
self.W_regularizer = regularizers.get(W_regularizer)
if self.W_regularizer:
self.W_regularizer.set_param(self.W)
self.regularizers.append(self.W_regularizer)
self.b_regularizer = regularizers.get(b_regularizer)
if self.b_regularizer:
self.b_regularizer.set_param(self.b)
self.regularizers.append(self.b_regularizer)
self.activity_regularizer = regularizers.get(activity_regularizer)
if self.activity_regularizer:
self.activity_regularizer.set_layer(self)
self.regularizers.append(self.activity_regularizer)
self.W_constraint = constraints.get(W_constraint)
self.b_constraint = constraints.get(b_constraint)
self.constraints = [self.W_constraint, self.b_constraint]
if weights is not None:
self.set_weights(weights)
def get_output(self, train=False):
X = self.get_input(train)
# -- don't need activation since it's just linear.
output = T.max(T.dot(X, self.W) + self.b, axis=1)
return output
def get_config(self):
return {"name": self.__class__.__name__,
"input_dim": self.input_dim,
"output_dim": self.output_dim,
"init": self.init.__name__,
"nb_feature": self.nb_feature,
"W_regularizer": self.W_regularizer.get_config() if self.W_regularizer else None,
"b_regularizer": self.b_regularizer.get_config() if self.b_regularizer else None,
"activity_regularizer": self.activity_regularizer.get_config() if self.activity_regularizer else None,
"W_constraint": self.W_constraint.get_config() if self.W_constraint else None,
"b_constraint": self.b_constraint.get_config() if self.b_constraint else None}
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
199,
199,
646,
14377,
199,
646,
14377,
14,
3128,
465,
377,
199,
646,
2680,
465,
980,
199,
199,
504,
2508,
492,
32038,
12,
2536,
12270,
12,
5578,
6315,
12,
9565,
199,
504,
2508,
1208,
14,
32057,
63,
1208,
492,
5709,
63,
4250,
12,
2069,
56,
199,
504,
2508,
1208,
14,
6767,
63,
1208,
492,
1852,
63,
2960,
199,
504,
2508,
7898,
6315,
492,
21885,
16038,
1793,
12,
18528,
1793,
199,
199,
504,
14377,
14,
16647,
14,
12686,
63,
77,
12430,
492,
603,
14058,
63,
3883,
19358,
465,
9571,
19358,
199,
504,
3816,
14,
4912,
492,
3482,
421,
199,
533,
11915,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1162,
275,
942,
339,
347,
4205,
63,
7618,
8,
277,
304,
267,
291,
14,
7618,
275,
942,
339,
347,
663,
63,
6352,
8,
277,
12,
4045,
12,
1950,
63,
1130,
16420,
267,
702,
291,
14,
4994,
63,
1210,
508,
4045,
14,
4994,
63,
1199,
508,
413,
12,
298,
6612,
4907,
9393,
26,
1324,
2338,
436,
1072,
2338,
1077,
506,
413,
2122,
267,
340,
440,
291,
14,
9823,
63,
11018,
63,
1210,
342,
436,
4045,
14,
362,
63,
1199,
63,
2629,
342,
365,
440,
488,
26,
288,
746,
2186,
480,
6612,
4907,
2222,
13,
2629,
316,
4045,
370,
4045,
543,
9742,
1072,
531,
267,
291,
14,
6352,
275,
4045,
339,
768,
1829,
272,
347,
8526,
63,
1210,
8,
277,
304,
267,
372,
413,
339,
768,
1829,
272,
347,
8526,
63,
1199,
8,
277,
304,
267,
372,
413,
339,
347,
664,
63,
1199,
8,
277,
12,
3560,
29,
797,
304,
267,
372,
291,
14,
362,
63,
1210,
8,
2834,
9,
339,
347,
664,
63,
1210,
8,
277,
12,
3560,
29,
797,
304,
267,
340,
2688,
8,
277,
12,
283,
6352,
735,
288,
372,
291,
14,
6352,
14,
362,
63,
1199,
8,
2834,
29,
2834,
9,
267,
587,
26,
288,
372,
291,
14,
1210,
339,
347,
5171,
63,
11018,
63,
1210,
8,
277,
304,
267,
1449,
7480,
503,
440,
642,
4045,
14021,
83,
314,
1072,
3656,
402,
2399,
4136,
4045,
315,
2399,
24258,
14,
982,
1265,
862,
267,
370,
6554,
282,
4045,
626,
1630,
627,
1397,
10,
2291,
9742,
63,
1210,
370,
282,
4045,
626,
10557,
282,
2222,
13,
403,
1072,
63,
2629,
342,
626,
365,
267,
376,
1125,
2344,
267,
372,
756,
339,
347,
664,
63,
1199,
63,
2629,
8,
277,
12,
3560,
29,
403,
304,
267,
1449,
267,
2104,
2005,
1709,
334,
10180,
465,
32378,
2438,
9,
1265,
2934,
282,
4340,
402,
3769,
7688,
370,
2216,
2005,
1072,
666,
13,
3438,
465,
267,
298,
11018,
401,
880,
2985,
787,
440,
1202,
315,
6466,
24258,
14,
1010,
4066,
282,
1402,
12,
664,
63,
1199,
63,
2629,
342,
1077,
372,
282,
3656,
267,
402,
1373,
6656,
6240,
2419,
664,
63,
1199,
342,
334,
1152,
340,
664,
63,
1199,
365,
334,
4994,
63,
3356,
12,
8526,
63,
521,
5895,
12,
8526,
63,
13320,
395,
2066,
314,
3656,
267,
365,
334,
4994,
63,
3356,
12,
8526,
63,
521,
5895,
395,
543,
282,
1373,
367,
4036,
625,
11018,
666,
1403,
12,
436,
282,
4697,
367,
4036,
9742,
1373,
14,
398,
982,
2337,
365,
627,
889,
10,
3656,
316,
2066,
652,
10989,
372,
488,
14,
2104,
1256,
340,
1265,
6554,
376,
29441,
4045,
334,
29002,
2291,
3656,
316,
9,
267,
370,
282,
4045,
543,
376,
1072,
63,
2629,
12,
2066,
626,
29441,
10989,
2597,
1172,
376,
1072,
63,
2629,
14,
982,
1265,
6554,
652,
370,
282,
4045,
543,
949,
267,
4066,
3656,
12,
2066,
314,
29441,
1159,
664,
63,
1199,
63,
2629,
10989,
372,
488,
14,
398,
6601,
9393,
1172,
376,
1072,
63,
2629,
2755,
340,
3932,
1324,
365,
625,
11018,
12,
440,
6665,
24297,
1098,
1314,
883,
7485,
314,
2397,
298,
16,
2,
1901,
267,
282,
3656,
14,
267,
1449,
267,
372,
488,
339,
347,
663,
63,
4916,
8,
277,
12,
4931,
304,
267,
367,
299,
12,
336,
315,
3482,
8,
277,
14,
1162,
12,
4931,
304,
288,
340,
299,
14,
2579,
1252,
1392,
1137,
336,
14,
1392,
26,
355,
746,
2186,
480,
5003,
2215,
450,
83,
440,
9025,
543,
5401,
2215,
450,
83,
2122,
450,
334,
80,
14,
2579,
1252,
1392,
12,
336,
14,
1392,
430,
288,
299,
14,
409,
63,
585,
8,
31293,
8,
87,
430,
339,
347,
664,
63,
4916,
8,
277,
304,
267,
4931,
275,
942,
267,
367,
299,
315,
291,
14,
1162,
26,
288,
4931,
14,
740,
8,
80,
14,
362,
63,
585,
1012,
267,
372,
4931,
339,
347,
664,
63,
888,
8,
277,
304,
267,
372,
2420,
354,
582,
291,
855,
533,
4914,
354,
363,
93,
339,
347,
664,
63,
1162,
8,
277,
304,
267,
950,
83,
275,
942,
267,
7029,
275,
942,
398,
340,
2688,
8,
277,
12,
283,
7898,
6315,
735,
288,
5578,
6315,
275,
291,
14,
7898,
6315,
267,
587,
26,
288,
5578,
6315,
275,
942,
398,
340,
2688,
8,
277,
12,
283,
9882,
358,
436,
822,
8,
277,
14,
9882,
9,
508,
822,
8,
277,
14,
1162,
304,
288,
367,
286,
315,
291,
14,
9882,
26,
355,
340,
286,
26,
490,
950,
83,
14,
740,
8,
67,
9,
355,
587,
26,
490,
950,
83,
14,
740,
8,
9882,
14,
5582,
1012,
267,
916,
2688,
8,
277,
12,
283,
5631,
358,
436,
291,
14,
5631,
26,
288,
950,
83,
847,
359,
277,
14,
5631,
367,
485,
315,
1425,
8,
552,
8,
277,
14,
1162,
10524,
267,
587,
26,
288,
950,
83,
847,
359,
9882,
14,
5582,
342,
367,
485,
315,
1425,
8,
552,
8,
277,
14,
1162,
10524,
398,
340,
2688,
8,
277,
12,
283,
7618,
358,
436,
291,
14,
7618,
26,
288,
7029,
847,
291,
14,
7618,
398,
372,
291,
14,
1162,
12,
5578,
6315,
12,
950,
83,
12,
7029,
339,
347,
663,
63,
354,
8,
277,
12,
536,
304,
267,
367,
284,
315,
1425,
8,
552,
8,
277,
14,
1162,
2298,
288,
291,
14,
1162,
59,
73,
1055,
354,
275,
1543,
83,
63,
80,
5,
68,
7,
450,
334,
354,
12,
284,
9,
421,
199,
533,
17581,
379,
5003,
8,
5003,
304,
272,
1449,
272,
982,
2195
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
199,
199,
646,
14377,
199,
646,
14377,
14,
3128,
465,
377,
199,
646,
2680,
465,
980,
199,
199,
504,
2508,
492,
32038,
12,
2536,
12270,
12,
5578,
6315,
12,
9565,
199,
504,
2508,
1208,
14,
32057,
63,
1208,
492,
5709,
63,
4250,
12,
2069,
56,
199,
504,
2508,
1208,
14,
6767,
63,
1208,
492,
1852,
63,
2960,
199,
504,
2508,
7898,
6315,
492,
21885,
16038,
1793,
12,
18528,
1793,
199,
199,
504,
14377,
14,
16647,
14,
12686,
63,
77,
12430,
492,
603,
14058,
63,
3883,
19358,
465,
9571,
19358,
199,
504,
3816,
14,
4912,
492,
3482,
421,
199,
533,
11915,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1162,
275,
942,
339,
347,
4205,
63,
7618,
8,
277,
304,
267,
291,
14,
7618,
275,
942,
339,
347,
663,
63,
6352,
8,
277,
12,
4045,
12,
1950,
63,
1130,
16420,
267,
702,
291,
14,
4994,
63,
1210,
508,
4045,
14,
4994,
63,
1199,
508,
413,
12,
298,
6612,
4907,
9393,
26,
1324,
2338,
436,
1072,
2338,
1077,
506,
413,
2122,
267,
340,
440,
291,
14,
9823,
63,
11018,
63,
1210,
342,
436,
4045,
14,
362,
63,
1199,
63,
2629,
342,
365,
440,
488,
26,
288,
746,
2186,
480,
6612,
4907,
2222,
13,
2629,
316,
4045,
370,
4045,
543,
9742,
1072,
531,
267,
291,
14,
6352,
275,
4045,
339,
768,
1829,
272,
347,
8526,
63,
1210,
8,
277,
304,
267,
372,
413,
339,
768,
1829,
272,
347,
8526,
63,
1199,
8,
277,
304,
267,
372,
413,
339,
347,
664,
63,
1199,
8,
277,
12,
3560,
29,
797,
304,
267,
372,
291,
14,
362,
63,
1210,
8,
2834,
9,
339,
347,
664,
63,
1210,
8,
277,
12,
3560,
29,
797,
304,
267,
340,
2688,
8,
277,
12,
283,
6352,
735,
288,
372,
291,
14,
6352,
14,
362,
63,
1199,
8,
2834,
29,
2834,
9,
267,
587,
26,
288,
372,
291,
14,
1210,
339,
347,
5171,
63,
11018,
63,
1210,
8,
277,
304,
267,
1449,
7480,
503,
440,
642,
4045,
14021,
83,
314,
1072,
3656,
402,
2399,
4136,
4045,
315,
2399,
24258,
14,
982,
1265,
862,
267,
370,
6554,
282,
4045,
626,
1630,
627,
1397,
10,
2291,
9742,
63,
1210,
370,
282,
4045,
626,
10557,
282,
2222,
13,
403,
1072,
63,
2629,
342,
626,
365,
267,
376,
1125,
2344,
267,
372,
756,
339,
347,
664,
63,
1199,
63,
2629,
8,
277,
12,
3560,
29,
403,
304,
267,
1449,
267,
2104,
2005,
1709,
334,
10180,
465,
32378,
2438,
9,
1265,
2934,
282,
4340,
402,
3769,
7688,
370,
2216,
2005,
1072,
666,
13,
3438,
465,
267,
298,
11018,
401,
880,
2985,
787,
440,
1202,
315,
6466,
24258,
14,
1010,
4066,
282,
1402,
12,
664,
63,
1199,
63,
2629,
342,
1077,
372,
282,
3656,
267,
402,
1373,
6656,
6240,
2419,
664,
63,
1199,
342,
334,
1152,
340,
664,
63,
1199,
365,
334,
4994,
63,
3356,
12,
8526,
63,
521,
5895,
12,
8526,
63,
13320,
395,
2066,
314,
3656,
267,
365,
334,
4994,
63,
3356,
12,
8526,
63,
521,
5895,
395,
543,
282,
1373,
367,
4036,
625,
11018,
666,
1403,
12,
436,
282,
4697,
367,
4036,
9742,
1373,
14,
398,
982,
2337,
365,
627,
889,
10,
3656,
316,
2066,
652,
10989,
372,
488,
14,
2104,
1256,
340,
1265,
6554,
376,
29441,
4045,
334,
29002,
2291,
3656,
316,
9,
267,
370,
282,
4045,
543,
376,
1072,
63,
2629,
12,
2066,
626,
29441,
10989,
2597,
1172,
376,
1072,
63,
2629,
14,
982,
1265,
6554,
652,
370,
282,
4045,
543,
949,
267,
4066,
3656,
12,
2066,
314,
29441,
1159,
664,
63,
1199,
63,
2629,
10989,
372,
488,
14,
398,
6601,
9393,
1172,
376,
1072,
63,
2629,
2755,
340,
3932,
1324,
365,
625,
11018,
12,
440,
6665,
24297,
1098,
1314,
883,
7485,
314,
2397,
298,
16,
2,
1901,
267,
282,
3656,
14,
267,
1449,
267,
372,
488,
339,
347,
663,
63,
4916,
8,
277,
12,
4931,
304,
267,
367,
299,
12,
336,
315,
3482,
8,
277,
14,
1162,
12,
4931,
304,
288,
340,
299,
14,
2579,
1252,
1392,
1137,
336,
14,
1392,
26,
355,
746,
2186,
480,
5003,
2215,
450,
83,
440,
9025,
543,
5401,
2215,
450,
83,
2122,
450,
334,
80,
14,
2579,
1252,
1392,
12,
336,
14,
1392,
430,
288,
299,
14,
409,
63,
585,
8,
31293,
8,
87,
430,
339,
347,
664,
63,
4916,
8,
277,
304,
267,
4931,
275,
942,
267,
367,
299,
315,
291,
14,
1162,
26,
288,
4931,
14,
740,
8,
80,
14,
362,
63,
585,
1012,
267,
372,
4931,
339,
347,
664,
63,
888,
8,
277,
304,
267,
372,
2420,
354,
582,
291,
855,
533,
4914,
354,
363,
93,
339,
347,
664,
63,
1162,
8,
277,
304,
267,
950,
83,
275,
942,
267,
7029,
275,
942,
398,
340,
2688,
8,
277,
12,
283,
7898,
6315,
735,
288,
5578,
6315,
275,
291,
14,
7898,
6315,
267,
587,
26,
288,
5578,
6315,
275,
942,
398,
340,
2688,
8,
277,
12,
283,
9882,
358,
436,
822,
8,
277,
14,
9882,
9,
508,
822,
8,
277,
14,
1162,
304,
288,
367,
286,
315,
291,
14,
9882,
26,
355,
340,
286,
26,
490,
950,
83,
14,
740,
8,
67,
9,
355,
587,
26,
490,
950,
83,
14,
740,
8,
9882,
14,
5582,
1012,
267,
916,
2688,
8,
277,
12,
283,
5631,
358,
436,
291,
14,
5631,
26,
288,
950,
83,
847,
359,
277,
14,
5631,
367,
485,
315,
1425,
8,
552,
8,
277,
14,
1162,
10524,
267,
587,
26,
288,
950,
83,
847,
359,
9882,
14,
5582,
342,
367,
485,
315,
1425,
8,
552,
8,
277,
14,
1162,
10524,
398,
340,
2688,
8,
277,
12,
283,
7618,
358,
436,
291,
14,
7618,
26,
288,
7029,
847,
291,
14,
7618,
398,
372,
291,
14,
1162,
12,
5578,
6315,
12,
950,
83,
12,
7029,
339,
347,
663,
63,
354,
8,
277,
12,
536,
304,
267,
367,
284,
315,
1425,
8,
552,
8,
277,
14,
1162,
2298,
288,
291,
14,
1162,
59,
73,
1055,
354,
275,
1543,
83,
63,
80,
5,
68,
7,
450,
334,
354,
12,
284,
9,
421,
199,
533,
17581,
379,
5003,
8,
5003,
304,
272,
1449,
272,
982,
2195,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
QiJune/Paddle
|
python/paddle/trainer_config_helpers/evaluators.py
|
7
|
25289
|
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from paddle.trainer.config_parser import *
from default_decorators import *
__all__ = [
"evaluator_base",
"classification_error_evaluator",
"auc_evaluator",
"pnpair_evaluator",
"precision_recall_evaluator",
"ctc_error_evaluator",
"chunk_evaluator",
"sum_evaluator",
"column_sum_evaluator",
"value_printer_evaluator",
"gradient_printer_evaluator",
"maxid_printer_evaluator",
"maxframe_printer_evaluator",
"seqtext_printer_evaluator",
"classification_error_printer_evaluator",
"detection_map_evaluator",
]
class EvaluatorAttribute(object):
FOR_CLASSIFICATION = 1
FOR_REGRESSION = 1 << 1
FOR_RANK = 1 << 2
FOR_PRINT = 1 << 3
FOR_UTILS = 1 << 4
FOR_DETECTION = 1 << 5
KEYS = [
"for_classification", "for_regression", "for_rank", "for_print",
"for_utils", "for_detection"
]
@staticmethod
def to_key(idx):
tmp = 1
for i in xrange(0, len(EvaluatorAttribute.KEYS)):
if idx == tmp:
return EvaluatorAttribute.KEYS[i]
else:
tmp = (tmp << 1)
def evaluator(*attrs):
def impl(method):
for attr in attrs:
setattr(method, EvaluatorAttribute.to_key(attr), True)
method.is_evaluator = True
return method
return impl
def evaluator_base(input,
type,
label=None,
weight=None,
name=None,
chunk_scheme=None,
num_chunk_types=None,
classification_threshold=None,
positive_label=None,
dict_file=None,
result_file=None,
num_results=None,
delimited=None,
top_k=None,
excluded_chunk_types=None,
overlap_threshold=None,
background_id=None,
evaluate_difficult=None,
ap_type=None):
"""
Evaluator will evaluate the network status while training/testing.
User can use evaluator by classify/regression job. For example.
.. code-block:: python
classify(prediction, output, evaluator=classification_error_evaluator)
And user could define evaluator separately as follow.
.. code-block:: python
classification_error_evaluator("ErrorRate", prediction, label)
The evaluator often contains a name parameter. It will also be printed when
evaluating network. The printed information may look like the following.
.. code-block:: text
Batch=200 samples=20000 AvgCost=0.679655 CurrentCost=0.662179 Eval:
classification_error_evaluator=0.4486
CurrentEval: ErrorRate=0.3964
:param input: Input layers, a object of LayerOutput or a list of
LayerOutput.
:type input: list|LayerOutput
:param label: An input layer containing the ground truth label.
:type label: LayerOutput|None
:param weight: An input layer which is a weight for each sample.
Each evaluator may calculate differently to use this weight.
:type weight: LayerOutput.
:param top_k: number k in top-k error rate
:type top_k: int
:param overlap_threshold: In detection tasks to filter detection results
:type overlap_threshold: float
:param background_id: Identifier of background class
:type background_id: int
:param evaluate_difficult: Whether to evaluate difficult objects
:type evaluate_difficult: bool
:param ap_type: How to calculate average persicion
:type ap_type: str
"""
# inputs type assertions.
assert classification_threshold is None or isinstance(
classification_threshold, float)
assert positive_label is None or isinstance(positive_label, int)
assert num_results is None or isinstance(num_results, int)
assert top_k is None or isinstance(top_k, int)
if not isinstance(input, list):
input = [input]
if label:
input.append(label)
if weight:
input.append(weight)
Evaluator(
name=name,
type=type,
inputs=[i.name for i in input],
chunk_scheme=chunk_scheme,
num_chunk_types=num_chunk_types,
classification_threshold=classification_threshold,
positive_label=positive_label,
dict_file=dict_file,
result_file=result_file,
delimited=delimited,
num_results=num_results,
top_k=top_k,
excluded_chunk_types=excluded_chunk_types,
overlap_threshold=overlap_threshold,
background_id=background_id,
evaluate_difficult=evaluate_difficult,
ap_type=ap_type)
@evaluator(EvaluatorAttribute.FOR_DETECTION)
@wrap_name_default()
def detection_map_evaluator(input,
label,
overlap_threshold=0.5,
background_id=0,
evaluate_difficult=False,
ap_type="11point",
name=None):
"""
Detection mAP Evaluator. It will print mean Average Precision (mAP) for detection.
The detection mAP Evaluator based on the output of detection_output layer counts
the true positive and the false positive bbox and integral them to get the
mAP.
The simple usage is:
.. code-block:: python
eval = detection_map_evaluator(input=det_output,label=lbl)
:param input: Input layer.
:type input: LayerOutput
:param label: Label layer.
:type label: LayerOutput
:param overlap_threshold: The bbox overlap threshold of a true positive.
:type overlap_threshold: float
:param background_id: The background class index.
:type background_id: int
:param evaluate_difficult: Whether evaluate a difficult ground truth.
:type evaluate_difficult: bool
"""
if not isinstance(input, list):
input = [input]
if label:
input.append(label)
evaluator_base(
name=name,
type="detection_map",
input=input,
label=label,
overlap_threshold=overlap_threshold,
background_id=background_id,
evaluate_difficult=evaluate_difficult,
ap_type=ap_type)
@evaluator(EvaluatorAttribute.FOR_CLASSIFICATION)
@wrap_name_default()
def classification_error_evaluator(input,
label,
name=None,
weight=None,
top_k=None,
threshold=None):
"""
Classification Error Evaluator. It will print error rate for classification.
The classification error is:
.. math::
classification\\_error = \\frac{NumOfWrongPredicts}{NumOfAllSamples}
The simple usage is:
.. code-block:: python
eval = classification_error_evaluator(input=prob,label=lbl)
:param name: Evaluator name.
:type name: basestring
:param input: Input Layer name. The output prediction of network.
:type input: LayerOutput
:param label: Label layer name.
:type label: basestring
:param weight: Weight Layer name. It should be a matrix with size
[sample_num, 1]. And will just multiply to NumOfWrongPredicts
and NumOfAllSamples. So, the elements of weight are all one,
then means not set weight. The larger weight it is, the more
important this sample is.
:type weight: LayerOutput
:param top_k: number k in top-k error rate
:type top_k: int
:param threshold: The classification threshold.
:type threshold: float
:return: None.
"""
evaluator_base(
name=name,
type="classification_error",
input=input,
label=label,
weight=weight,
top_k=top_k,
classification_threshold=threshold, )
@evaluator(EvaluatorAttribute.FOR_CLASSIFICATION)
@wrap_name_default()
def auc_evaluator(
input,
label,
name=None,
weight=None, ):
"""
Auc Evaluator which adapts to binary classification.
The simple usage:
.. code-block:: python
eval = auc_evaluator(input, label)
:param name: Evaluator name.
:type name: None|basestring
:param input: Input Layer name. The output prediction of network.
:type input: LayerOutput
:param label: Label layer name.
:type label: None|basestring
:param weight: Weight Layer name. It should be a matrix with size
[sample_num, 1].
:type weight: LayerOutput
"""
evaluator_base(
name=name,
type="last-column-auc",
input=input,
label=label,
weight=weight)
@evaluator(EvaluatorAttribute.FOR_RANK)
@wrap_name_default()
def pnpair_evaluator(
input,
label,
query_id,
weight=None,
name=None, ):
"""
Positive-negative pair rate Evaluator which adapts to rank task like
learning to rank. This evaluator must contain at least three layers.
The simple usage:
.. code-block:: python
eval = pnpair_evaluator(input, label, query_id)
:param input: Input Layer name. The output prediction of network.
:type input: LayerOutput
:param label: Label layer name.
:type label: LayerOutput
:param query_id: Query_id layer name. Query_id indicates that which query
each sample belongs to. Its shape should be
the same as output of Label layer.
:type query_id: LayerOutput
:param weight: Weight Layer name. It should be a matrix with size
[sample_num, 1] which indicates the weight of each sample.
The default weight of sample is 1 if the weight layer is None.
And the pair weight is the mean of the two samples' weight.
:type weight: LayerOutput
:param name: Evaluator name.
:type name: None|basestring
"""
if not isinstance(input, list):
input = [input]
if label:
input.append(label)
if query_id:
input.append(query_id)
evaluator_base(
input=input,
type="pnpair",
weight=weight,
name=name, )
@evaluator(EvaluatorAttribute.FOR_CLASSIFICATION)
@wrap_name_default()
def precision_recall_evaluator(
input,
label,
positive_label=None,
weight=None,
name=None, ):
"""
An Evaluator to calculate precision and recall, F1-score.
It is adapt to the task with multiple labels.
- If positive_label=-1, it will print the average precision, recall,
F1-score of all labels.
- If use specify positive_label, it will print the precision, recall,
F1-score of this label.
The simple usage:
.. code-block:: python
eval = precision_recall_evaluator(input, label)
:param name: Evaluator name.
:type name: None|basestring
:param input: Input Layer name. The output prediction of network.
:type input: LayerOutput
:param label: Label layer name.
:type label: LayerOutput
:param positive_label: The input label layer.
:type positive_label: LayerOutput.
:param weight: Weight Layer name. It should be a matrix with size
[sample_num, 1]. (TODO, explaination)
:type weight: LayerOutput
"""
evaluator_base(
name=name,
type="precision_recall",
input=input,
label=label,
positive_label=positive_label,
weight=weight)
@evaluator(EvaluatorAttribute.FOR_CLASSIFICATION)
@wrap_name_default()
def ctc_error_evaluator(
input,
label,
name=None, ):
"""
This evaluator is to calculate sequence-to-sequence edit distance.
The simple usage is :
.. code-block:: python
eval = ctc_error_evaluator(input=input, label=lbl)
:param name: Evaluator name.
:type name: None|basestring
:param input: Input Layer. Should be the same as the input for ctc_layer.
:type input: LayerOutput
:param label: input label, which is a data_layer. Should be the same as the
label for ctc_layer
:type label: LayerOutput
"""
evaluator_base(
name=name, type="ctc_edit_distance", input=input, label=label)
@evaluator(EvaluatorAttribute.FOR_CLASSIFICATION)
@wrap_name_default()
def chunk_evaluator(
input,
label,
chunk_scheme,
num_chunk_types,
name=None,
excluded_chunk_types=None, ):
"""
Chunk evaluator is used to evaluate segment labelling accuracy for a
sequence. It calculates precision, recall and F1 scores for the chunk detection.
To use chunk evaluator, several concepts need to be clarified firstly.
* **Chunk type** is the type of the whole chunk and a chunk consists of one or several words. (For example in NER, ORG for organization name, PER for person name etc.)
* **Tag type** indicates the position of a word in a chunk. (B for begin, I for inside, E for end, S for single)
We can name a label by combining tag type and chunk type. (ie. B-ORG for begining of an organization name)
The construction of label dictionary should obey the following rules:
- Use one of the listed labelling schemes. These schemes differ in ways indicating chunk boundry.
.. code-block:: text
Scheme Description
plain Use the same label for the whole chunk.
IOB Two labels for chunk type X, B-X for chunk begining and I-X for chunk inside.
IOE Two labels for chunk type X, E-X for chunk ending and I-X for chunk inside.
IOBES Four labels for chunk type X, B-X for chunk begining, I-X for chunk inside, E-X for chunk end and S-X for single word chunk.
To make it clear, let's illustrate by an NER example.
Assuming that there are three named entity types including ORG, PER and LOC which are called 'chunk type' here,
if 'IOB' scheme were used, the label set will be extended to a set including B-ORG, I-ORG, B-PER, I-PER, B-LOC, I-LOC and O,
in which B-ORG for begining of ORG and I-ORG for inside of ORG.
Prefixes which are called 'tag type' here are added to chunk types and there are two tag types including B and I.
Of course, the training data should be labeled accordingly.
- Mapping is done correctly by the listed equations and assigning protocol.
The following table are equations to extract tag type and chunk type from a label.
.. code-block:: text
tagType = label % numTagType
chunkType = label / numTagType
otherChunkType = numChunkTypes
The following table shows the mapping rule between tagType and tag type in each scheme.
.. code-block:: text
Scheme Begin Inside End Single
plain 0 - - -
IOB 0 1 - -
IOE - 0 1 -
IOBES 0 1 2 3
Continue the NER example, and the label dict should look like this to satify above equations:
.. code-block:: text
B-ORG 0
I-ORG 1
B-PER 2
I-PER 3
B-LOC 4
I-LOC 5
O 6
In this example, chunkType has three values: 0 for ORG, 1 for PER, 2 for LOC, because the scheme is
"IOB" so tagType has two values: 0 for B and 1 for I.
Here we will use I-LOC to explain the above mapping rules in detail.
For I-LOC, the label id is 5, so we can get tagType=1 and chunkType=2, which means I-LOC is a part of NER chunk LOC
and the tag is I.
The simple usage is:
.. code-block:: python
eval = chunk_evaluator(input, label, chunk_scheme, num_chunk_types)
:param input: The input layers.
:type input: LayerOutput
:param label: An input layer containing the ground truth label.
:type label: LayerOutput
:param chunk_scheme: The labelling schemes support 4 types. It is one of
"IOB", "IOE", "IOBES", "plain". It is required.
:type chunk_scheme: basestring
:param num_chunk_types: number of chunk types other than "other"
:param name: The Evaluator name, it is optional.
:type name: basename|None
:param excluded_chunk_types: chunks of these types are not considered
:type excluded_chunk_types: list of integer|None
"""
evaluator_base(
name=name,
type="chunk",
input=input,
label=label,
chunk_scheme=chunk_scheme,
num_chunk_types=num_chunk_types,
excluded_chunk_types=excluded_chunk_types, )
@evaluator(EvaluatorAttribute.FOR_UTILS)
@wrap_name_default()
def sum_evaluator(
input,
name=None,
weight=None, ):
"""
An Evaluator to sum the result of input.
The simple usage:
.. code-block:: python
eval = sum_evaluator(input)
:param name: Evaluator name.
:type name: None|basestring
:param input: Input Layer name.
:type input: LayerOutput
:param weight: Weight Layer name. It should be a matrix with size
[sample_num, 1]. (TODO, explaination)
:type weight: LayerOutput
"""
evaluator_base(name=name, type="sum", input=input, weight=weight)
@evaluator(EvaluatorAttribute.FOR_UTILS)
@wrap_name_default()
def column_sum_evaluator(
input,
name=None,
weight=None, ):
"""
This Evaluator is used to sum the last column of input.
The simple usage is:
.. code-block:: python
eval = column_sum_evaluator(input, label)
:param name: Evaluator name.
:type name: None|basestring
:param input: Input Layer name.
:type input: LayerOutput
"""
evaluator_base(
name=name, type="last-column-sum", input=input, weight=weight)
"""
The following are printer Evaluators which are usually used to
print the result, like value or gradient of input layers, the
results generated in machine translation, the classification error etc.
"""
@evaluator(EvaluatorAttribute.FOR_PRINT)
@wrap_name_default()
def value_printer_evaluator(
input,
name=None, ):
"""
This Evaluator is used to print the values of input layers. It contains
one or more input layers.
The simple usage is:
.. code-block:: python
eval = value_printer_evaluator(input)
:param input: One or more input layers.
:type input: LayerOutput|list
:param name: Evaluator name.
:type name: None|basestring
"""
evaluator_base(name=name, type="value_printer", input=input)
@evaluator(EvaluatorAttribute.FOR_PRINT)
@wrap_name_default()
def gradient_printer_evaluator(
input,
name=None, ):
"""
This Evaluator is used to print the gradient of input layers. It contains
one or more input layers.
The simple usage is:
.. code-block:: python
eval = gradient_printer_evaluator(input)
:param input: One or more input layers.
:type input: LayerOutput|list
:param name: Evaluator name.
:type name: None|basestring
"""
evaluator_base(name=name, type="gradient_printer", input=input)
@evaluator(EvaluatorAttribute.FOR_PRINT)
@wrap_name_default()
def maxid_printer_evaluator(
input,
num_results=None,
name=None, ):
"""
This Evaluator is used to print maximum top k values and their indexes
of each row of input layers. It contains one or more input layers.
k is specified by num_results.
The simple usage is:
.. code-block:: python
eval = maxid_printer_evaluator(input)
:param input: Input Layer name.
:type input: LayerOutput|list
:param num_results: This number is used to specify the top k numbers.
It is 1 by default.
:type num_results: int.
:param name: Evaluator name.
:type name: None|basestring
"""
evaluator_base(
name=name, type="max_id_printer", input=input, num_results=num_results)
@evaluator(EvaluatorAttribute.FOR_PRINT)
@wrap_name_default()
def maxframe_printer_evaluator(
input,
num_results=None,
name=None, ):
"""
This Evaluator is used to print the top k frames of each input layers.
The input layers should contain sequences info or sequences type.
k is specified by num_results.
It contains one or more input layers.
Note:
The width of each frame is 1.
The simple usage is:
.. code-block:: python
eval = maxframe_printer_evaluator(input)
:param input: Input Layer name.
:type input: LayerOutput|list
:param name: Evaluator name.
:type name: None|basestring
"""
evaluator_base(
name=name,
type="max_frame_printer",
input=input,
num_results=num_results)
@evaluator(EvaluatorAttribute.FOR_PRINT)
@wrap_name_default()
def seqtext_printer_evaluator(
input,
result_file,
id_input=None,
dict_file=None,
delimited=None,
name=None, ):
"""
Sequence text printer will print text according to index matrix and a
dictionary. There can be multiple input to this layer:
1. If there is no id_input, the input must be a matrix containing
the sequence of indices;
2. If there is id_input, it should be ids, and interpreted as sample ids.
The output format will be:
1. sequence without sub-sequence, and there is probability.
.. code-block:: python
id \t prob space_seperated_tokens_from_dictionary_according_to_seq
2. sequence without sub-sequence, and there is not probability.
.. code-block:: python
id \t space_seperated_tokens_from_dictionary_according_to_seq
3. sequence with sub-sequence, and there is not probability.
.. code-block:: python
id \t space_seperated_tokens_from_dictionary_according_to_sub_seq
\t \t space_seperated_tokens_from_dictionary_according_to_sub_seq
...
Typically SequenceTextPrinter layer takes output of maxid or RecurrentGroup
with maxid (when generating) as an input.
The simple usage is:
.. code-block:: python
eval = seqtext_printer_evaluator(input=maxid_layer,
id_input=sample_id,
dict_file=dict_file,
result_file=result_file)
:param input: Input Layer name.
:type input: LayerOutput|list
:param result_file: Path of the file to store the generated results.
:type result_file: basestring
:param id_input: Index of the input sequence, and the specified index will
be prited in the gereated results. This an optional
parameter.
:type id_input: LayerOutput
:param dict_file: Path of dictionary. This is an optional parameter.
Every line is a word in the dictionary with
(line number - 1) as the word index.
If this parameter is set to None, or to an empty string,
only word index are printed in the generated results.
:type dict_file: basestring
:param delimited: Whether to use space to separate output tokens.
Default is True. No space is added if set to False.
:type delimited: bool
:param name: Evaluator name.
:type name: None|basestring
:return: The seq_text_printer that prints the generated sequence to a file.
:rtype: evaluator
"""
assert isinstance(result_file, basestring)
if id_input is None:
inputs = [input]
else:
inputs = [id_input, input]
input.parents.append(id_input)
evaluator_base(
name=name,
type="seq_text_printer",
input=inputs,
dict_file=dict_file,
result_file=result_file,
delimited=delimited)
@evaluator(EvaluatorAttribute.FOR_PRINT)
@wrap_name_default()
def classification_error_printer_evaluator(
input,
label,
threshold=0.5,
name=None, ):
"""
This Evaluator is used to print the classification error of each sample.
The simple usage is:
.. code-block:: python
eval = classification_error_printer_evaluator(input)
:param input: Input layer.
:type input: LayerOutput
:param label: Input label layer.
:type label: LayerOutput
:param name: Evaluator name.
:type name: None|basestring
"""
evaluator_base(
name=name,
type="classification_error_printer",
input=input,
label=label,
classification_threshold=threshold)
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
7800,
510,
20101,
48,
20101,
6642,
14,
2900,
5924,
5702,
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,
504,
28525,
14,
2834,
281,
14,
888,
63,
2087,
492,
627,
199,
504,
849,
63,
11582,
492,
627,
199,
199,
363,
452,
363,
275,
359,
272,
298,
27406,
63,
1095,
401,
272,
298,
14368,
63,
705,
63,
27406,
401,
272,
298,
19129,
63,
27406,
401,
272,
298,
4812,
3852,
63,
27406,
401,
272,
298,
6833,
63,
19183,
63,
27406,
401,
272,
298,
319,
67,
63,
705,
63,
27406,
401,
272,
298,
4604,
63,
27406,
401,
272,
298,
1838,
63,
27406,
401,
272,
298,
2301,
63,
1838,
63,
27406,
401,
272,
298,
585,
63,
11835,
63,
27406,
401,
272,
298,
7490,
63,
11835,
63,
27406,
401,
272,
298,
988,
344,
63,
11835,
63,
27406,
401,
272,
298,
988,
1943,
63,
11835,
63,
27406,
401,
272,
298,
3610,
505,
63,
11835,
63,
27406,
401,
272,
298,
14368,
63,
705,
63,
11835,
63,
27406,
401,
272,
298,
11934,
63,
1130,
63,
27406,
401,
199,
61,
421,
199,
533,
16494,
16530,
1646,
8,
785,
304,
272,
2381,
63,
31163,
23380,
2594,
275,
413,
272,
2381,
63,
907,
3975,
9577,
275,
413,
5213,
413,
272,
2381,
63,
50,
15874,
275,
413,
5213,
499,
272,
2381,
63,
21754,
275,
413,
5213,
650,
272,
2381,
63,
29076,
51,
275,
413,
5213,
841,
272,
2381,
63,
17442,
23658,
275,
413,
5213,
959,
339,
9301,
51,
275,
359,
267,
298,
509,
63,
14368,
401,
298,
509,
63,
12513,
401,
298,
509,
63,
4648,
401,
298,
509,
63,
1361,
401,
267,
298,
509,
63,
1208,
401,
298,
509,
63,
11934,
2,
272,
1622,
339,
768,
4639,
272,
347,
370,
63,
498,
8,
2996,
304,
267,
3529,
275,
413,
267,
367,
284,
315,
4945,
8,
16,
12,
822,
8,
10006,
16530,
1646,
14,
17434,
2298,
288,
340,
4280,
508,
3529,
26,
355,
372,
16494,
16530,
1646,
14,
17434,
59,
73,
61,
288,
587,
26,
355,
3529,
275,
334,
2791,
5213,
413,
9,
421,
199,
318,
29207,
2031,
3288,
304,
272,
347,
11512,
8,
765,
304,
267,
367,
1921,
315,
3290,
26,
288,
5371,
8,
765,
12,
16494,
16530,
1646,
14,
475,
63,
498,
8,
962,
395,
715,
9,
267,
1083,
14,
374,
63,
27406,
275,
715,
267,
372,
1083,
339,
372,
11512,
421,
199,
318,
29207,
63,
1095,
8,
1210,
12,
673,
730,
12,
673,
1768,
29,
403,
12,
673,
5401,
29,
403,
12,
673,
536,
29,
403,
12,
673,
3728,
63,
5512,
29,
403,
12,
673,
1967,
63,
4604,
63,
1313,
29,
403,
12,
673,
12505,
63,
7227,
29,
403,
12,
673,
7317,
63,
1302,
29,
403,
12,
673,
1211,
63,
493,
29,
403,
12,
673,
754,
63,
493,
29,
403,
12,
673,
1967,
63,
2604,
29,
403,
12,
673,
21941,
29,
403,
12,
673,
2746,
63,
75,
29,
403,
12,
673,
8789,
63,
4604,
63,
1313,
29,
403,
12,
673,
15145,
63,
7227,
29,
403,
12,
673,
8020,
63,
344,
29,
403,
12,
673,
9352,
63,
7330,
1792,
427,
29,
403,
12,
673,
2771,
63,
466,
29,
403,
304,
272,
408,
272,
16494,
16530,
911,
9352,
314,
2784,
2004,
1830,
6093,
15,
4776,
14,
339,
2876,
883,
675,
29207,
701,
28837,
15,
12513,
3906,
14,
2104,
2893,
14,
339,
2508,
221,
1233,
13,
1457,
447,
2366,
398,
28837,
8,
14845,
12,
1072,
12,
29207,
29,
14368,
63,
705,
63,
27406,
9,
339,
6061,
922,
4293,
5627,
29207,
18159,
465,
2035,
14,
339,
2508,
221,
1233,
13,
1457,
447,
2366,
398,
12505,
63,
705,
63,
27406,
480,
30676,
401,
12044,
12,
1768,
9,
339,
710,
29207,
14115,
3509,
282,
536,
2725,
14,
2779,
911,
2597,
506,
12487,
1380,
272,
27083,
2784,
14,
710,
12487,
2556,
1443,
3648,
2839,
314,
2569,
14,
339,
2508,
221,
1233,
13,
1457,
447,
1318,
13359,
17206,
29,
1840,
5845,
29,
27140,
437,
10929,
15568,
29,
16,
14,
1822,
28338,
9338,
15568,
29,
16,
14,
1272,
9335,
25,
16494,
26,
268,
12505,
63,
705,
63,
27406,
29,
16,
14,
1602,
1184,
268,
9338,
10006,
26,
4520,
6621,
29,
16,
14,
1355,
772,
339,
520,
635,
1324,
26,
6924,
9393,
12,
282,
909,
402,
11915,
2959,
503,
282,
769,
402,
2116,
11915,
2959,
14,
272,
520,
466,
1324,
26,
769,
92,
5003,
2959,
272,
520,
635,
1768,
26,
1626,
1324,
4045,
3035,
314,
19252,
16865,
1768,
14,
272,
520,
466,
1768,
26,
11915,
2959,
92,
403,
272,
520,
635,
5401,
26,
1626,
1324,
4045,
1314,
365,
282,
5401,
367,
1924,
2690,
14,
673,
7048,
29207,
1443,
8671,
23142,
370,
675,
642,
5401,
14,
272,
520,
466,
5401,
26,
11915,
2959,
14,
272,
520,
635,
2746,
63,
75,
26,
1329,
1022,
315,
2746,
13,
75,
1125,
6634,
272,
520,
466,
2746,
63,
75,
26,
1109,
272,
520,
635,
15145,
63,
7227,
26,
1010,
15212,
6527,
370,
2457,
15212,
2058,
272,
520,
466,
15145,
63,
7227,
26,
2069,
272,
520,
635,
8020,
63,
344,
26,
23285,
402,
8020,
1021,
272,
520,
466,
8020,
63,
344,
26,
1109,
272,
520,
635,
9352,
63,
7330,
1792,
427,
26,
7480,
370,
9352,
29870,
2251,
272,
520,
466,
9352,
63,
7330,
1792,
427,
26,
2155,
272,
520,
635,
2771,
63,
466,
26,
7494,
370,
8671,
8095,
1126,
338,
9718,
272,
520,
466,
2771,
63,
466,
26,
620,
272,
408,
272,
327,
4153,
730,
22835,
14,
272,
702,
12505,
63,
7227,
365,
488,
503,
1228,
8,
267,
12505,
63,
7227
] |
[
1898,
334,
67,
9,
7800,
510,
20101,
48,
20101,
6642,
14,
2900,
5924,
5702,
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,
504,
28525,
14,
2834,
281,
14,
888,
63,
2087,
492,
627,
199,
504,
849,
63,
11582,
492,
627,
199,
199,
363,
452,
363,
275,
359,
272,
298,
27406,
63,
1095,
401,
272,
298,
14368,
63,
705,
63,
27406,
401,
272,
298,
19129,
63,
27406,
401,
272,
298,
4812,
3852,
63,
27406,
401,
272,
298,
6833,
63,
19183,
63,
27406,
401,
272,
298,
319,
67,
63,
705,
63,
27406,
401,
272,
298,
4604,
63,
27406,
401,
272,
298,
1838,
63,
27406,
401,
272,
298,
2301,
63,
1838,
63,
27406,
401,
272,
298,
585,
63,
11835,
63,
27406,
401,
272,
298,
7490,
63,
11835,
63,
27406,
401,
272,
298,
988,
344,
63,
11835,
63,
27406,
401,
272,
298,
988,
1943,
63,
11835,
63,
27406,
401,
272,
298,
3610,
505,
63,
11835,
63,
27406,
401,
272,
298,
14368,
63,
705,
63,
11835,
63,
27406,
401,
272,
298,
11934,
63,
1130,
63,
27406,
401,
199,
61,
421,
199,
533,
16494,
16530,
1646,
8,
785,
304,
272,
2381,
63,
31163,
23380,
2594,
275,
413,
272,
2381,
63,
907,
3975,
9577,
275,
413,
5213,
413,
272,
2381,
63,
50,
15874,
275,
413,
5213,
499,
272,
2381,
63,
21754,
275,
413,
5213,
650,
272,
2381,
63,
29076,
51,
275,
413,
5213,
841,
272,
2381,
63,
17442,
23658,
275,
413,
5213,
959,
339,
9301,
51,
275,
359,
267,
298,
509,
63,
14368,
401,
298,
509,
63,
12513,
401,
298,
509,
63,
4648,
401,
298,
509,
63,
1361,
401,
267,
298,
509,
63,
1208,
401,
298,
509,
63,
11934,
2,
272,
1622,
339,
768,
4639,
272,
347,
370,
63,
498,
8,
2996,
304,
267,
3529,
275,
413,
267,
367,
284,
315,
4945,
8,
16,
12,
822,
8,
10006,
16530,
1646,
14,
17434,
2298,
288,
340,
4280,
508,
3529,
26,
355,
372,
16494,
16530,
1646,
14,
17434,
59,
73,
61,
288,
587,
26,
355,
3529,
275,
334,
2791,
5213,
413,
9,
421,
199,
318,
29207,
2031,
3288,
304,
272,
347,
11512,
8,
765,
304,
267,
367,
1921,
315,
3290,
26,
288,
5371,
8,
765,
12,
16494,
16530,
1646,
14,
475,
63,
498,
8,
962,
395,
715,
9,
267,
1083,
14,
374,
63,
27406,
275,
715,
267,
372,
1083,
339,
372,
11512,
421,
199,
318,
29207,
63,
1095,
8,
1210,
12,
673,
730,
12,
673,
1768,
29,
403,
12,
673,
5401,
29,
403,
12,
673,
536,
29,
403,
12,
673,
3728,
63,
5512,
29,
403,
12,
673,
1967,
63,
4604,
63,
1313,
29,
403,
12,
673,
12505,
63,
7227,
29,
403,
12,
673,
7317,
63,
1302,
29,
403,
12,
673,
1211,
63,
493,
29,
403,
12,
673,
754,
63,
493,
29,
403,
12,
673,
1967,
63,
2604,
29,
403,
12,
673,
21941,
29,
403,
12,
673,
2746,
63,
75,
29,
403,
12,
673,
8789,
63,
4604,
63,
1313,
29,
403,
12,
673,
15145,
63,
7227,
29,
403,
12,
673,
8020,
63,
344,
29,
403,
12,
673,
9352,
63,
7330,
1792,
427,
29,
403,
12,
673,
2771,
63,
466,
29,
403,
304,
272,
408,
272,
16494,
16530,
911,
9352,
314,
2784,
2004,
1830,
6093,
15,
4776,
14,
339,
2876,
883,
675,
29207,
701,
28837,
15,
12513,
3906,
14,
2104,
2893,
14,
339,
2508,
221,
1233,
13,
1457,
447,
2366,
398,
28837,
8,
14845,
12,
1072,
12,
29207,
29,
14368,
63,
705,
63,
27406,
9,
339,
6061,
922,
4293,
5627,
29207,
18159,
465,
2035,
14,
339,
2508,
221,
1233,
13,
1457,
447,
2366,
398,
12505,
63,
705,
63,
27406,
480,
30676,
401,
12044,
12,
1768,
9,
339,
710,
29207,
14115,
3509,
282,
536,
2725,
14,
2779,
911,
2597,
506,
12487,
1380,
272,
27083,
2784,
14,
710,
12487,
2556,
1443,
3648,
2839,
314,
2569,
14,
339,
2508,
221,
1233,
13,
1457,
447,
1318,
13359,
17206,
29,
1840,
5845,
29,
27140,
437,
10929,
15568,
29,
16,
14,
1822,
28338,
9338,
15568,
29,
16,
14,
1272,
9335,
25,
16494,
26,
268,
12505,
63,
705,
63,
27406,
29,
16,
14,
1602,
1184,
268,
9338,
10006,
26,
4520,
6621,
29,
16,
14,
1355,
772,
339,
520,
635,
1324,
26,
6924,
9393,
12,
282,
909,
402,
11915,
2959,
503,
282,
769,
402,
2116,
11915,
2959,
14,
272,
520,
466,
1324,
26,
769,
92,
5003,
2959,
272,
520,
635,
1768,
26,
1626,
1324,
4045,
3035,
314,
19252,
16865,
1768,
14,
272,
520,
466,
1768,
26,
11915,
2959,
92,
403,
272,
520,
635,
5401,
26,
1626,
1324,
4045,
1314,
365,
282,
5401,
367,
1924,
2690,
14,
673,
7048,
29207,
1443,
8671,
23142,
370,
675,
642,
5401,
14,
272,
520,
466,
5401,
26,
11915,
2959,
14,
272,
520,
635,
2746,
63,
75,
26,
1329,
1022,
315,
2746,
13,
75,
1125,
6634,
272,
520,
466,
2746,
63,
75,
26,
1109,
272,
520,
635,
15145,
63,
7227,
26,
1010,
15212,
6527,
370,
2457,
15212,
2058,
272,
520,
466,
15145,
63,
7227,
26,
2069,
272,
520,
635,
8020,
63,
344,
26,
23285,
402,
8020,
1021,
272,
520,
466,
8020,
63,
344,
26,
1109,
272,
520,
635,
9352,
63,
7330,
1792,
427,
26,
7480,
370,
9352,
29870,
2251,
272,
520,
466,
9352,
63,
7330,
1792,
427,
26,
2155,
272,
520,
635,
2771,
63,
466,
26,
7494,
370,
8671,
8095,
1126,
338,
9718,
272,
520,
466,
2771,
63,
466,
26,
620,
272,
408,
272,
327,
4153,
730,
22835,
14,
272,
702,
12505,
63,
7227,
365,
488,
503,
1228,
8,
267,
12505,
63,
7227,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
smendez/lean
|
paart/apps/infrastructure/links.py
|
2
|
3745
|
from __future__ import absolute_import
from django.utils.translation import ugettext_lazy as _
from agencies.permissions import PERMISSION_AGENCY_EDIT, PERMISSION_AGENCY_VIEW
from navigation.classes import Link
from .icons import (icon_projects, icon_project_edit, icon_project_delete,
icon_project_view, icon_agency_projects, icon_project_create,
icon_project_info_edit, icon_project_info_view, icon_project_info_delete,
icon_project_budget_edit, icon_project_budget_view, icon_project_budget_delete,
icon_project_details_edit, icon_project_details_view, icon_project_details_delete,
icon_project_file_list, icon_project_file_upload, icon_project_file_delete,
icon_project_file_download)
from .permissions import (PERMISSION_PROJECT_EDIT, PERMISSION_PROJECT_DELETE,
PERMISSION_PROJECT_VIEW)
link_projects = Link(text=_(u'projects'), view='infrastructure_project_list', icon=icon_projects)
link_project_edit = Link(text=_(u'edit'), view='infrastructure_project_edit', args='resolved_object.pk', icon=icon_project_edit)
link_project_delete = Link(text=_(u'delete'), view='infrastructure_project_delete', args='resolved_object.pk', icon=icon_project_delete)
link_project_view = Link(text=_(u'view'), view='infrastructure_project_view', args='resolved_object.pk', icon=icon_project_view)
link_project_view_basic = Link(text=_(u'basic'), view='infrastructure_project_view', args='resolved_object.pk', icon=icon_project_view)
link_project_create = Link(text=_(u'add project'), view='infrastructure_project_create', args='agency.pk', icon=icon_project_create)
link_project_info_edit = Link(text=_(u'edit'), view='project_info_edit', args='resolved_object.pk', icon=icon_project_info_edit)
link_project_info_delete = Link(text=_(u'delete'), view='project_info_delete', args='resolved_object.pk', icon=icon_project_info_delete)
link_project_info_view = Link(text=_(u'information'), view='project_info_view', args='resolved_object.pk', icon=icon_project_info_view, children_view_regex=['project_info'])
link_project_budget_edit = Link(text=_(u'edit'), view='project_budget_edit', args='resolved_object.pk', icon=icon_project_budget_edit)
link_project_budget_delete = Link(text=_(u'delete'), view='project_budget_delete', args='resolved_object.pk', icon=icon_project_budget_delete)
link_project_budget_view = Link(text=_(u'budget'), view='project_budget_view', args='resolved_object.pk', icon=icon_project_budget_view, children_view_regex=['project_budget'])
link_project_details_edit = Link(text=_(u'edit'), view='project_details_edit', args='resolved_object.pk', icon=icon_project_details_edit)
link_project_details_delete = Link(text=_(u'delete'), view='project_details_delete', args='resolved_object.pk', icon=icon_project_details_delete)
link_project_details_view = Link(text=_(u'details'), view='project_details_view', args='resolved_object.pk', icon=icon_project_details_view, children_view_regex=['project_details'])
link_project_file_list = Link(text=_(u'files'), view='infrastructure_project_file_list', args='project.pk', icon=icon_project_file_list, children_view_regex=['project_file'])
link_project_file_upload = Link(text=_(u'upload file'), view='infrastructure_project_file_upload', args='project.pk', icon=icon_project_file_upload)
link_project_file_delete = Link(text=_(u'delete'), view='infrastructure_project_file_delete', args='resolved_object.pk', icon=icon_project_file_delete)
link_project_file_download = Link(text=_(u'download'), view='infrastructure_project_file_download', args='resolved_object.pk', icon=icon_project_file_download)
link_agency_project_list = Link(text=_(u'infrastructure'), view='agency_infrastructure_project_list', args='resolved_object.pk', icon=icon_agency_projects)
|
gpl-3.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
1839,
287,
2578,
14,
6060,
492,
13873,
22320,
63,
1254,
17059,
63,
17929,
12,
13873,
22320,
63,
1254,
17059,
63,
12058,
199,
504,
19191,
14,
2888,
492,
10967,
199,
199,
504,
1275,
16471,
492,
334,
4677,
63,
6776,
12,
7016,
63,
1715,
63,
3773,
12,
7016,
63,
1715,
63,
1807,
12,
272,
7016,
63,
1715,
63,
1345,
12,
7016,
63,
643,
9501,
63,
6776,
12,
7016,
63,
1715,
63,
981,
12,
272,
7016,
63,
1715,
63,
815,
63,
3773,
12,
7016,
63,
1715,
63,
815,
63,
1345,
12,
7016,
63,
1715,
63,
815,
63,
1807,
12,
272,
7016,
63,
1715,
63,
16501,
63,
3773,
12,
7016,
63,
1715,
63,
16501,
63,
1345,
12,
7016,
63,
1715,
63,
16501,
63,
1807,
12,
272,
7016,
63,
1715,
63,
5087,
63,
3773,
12,
7016,
63,
1715,
63,
5087,
63,
1345,
12,
7016,
63,
1715,
63,
5087,
63,
1807,
12,
272,
7016,
63,
1715,
63,
493,
63,
513,
12,
7016,
63,
1715,
63,
493,
63,
5064,
12,
7016,
63,
1715,
63,
493,
63,
1807,
12,
272,
7016,
63,
1715,
63,
493,
63,
4249,
9,
199,
504,
1275,
6060,
492,
334,
4227,
22320,
63,
10797,
63,
17929,
12,
13873,
22320,
63,
10797,
63,
7014,
12,
272,
13873,
22320,
63,
10797,
63,
12058,
9,
199,
199,
1073,
63,
6776,
275,
10967,
8,
505,
17441,
85,
7,
6776,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
513,
297,
7016,
29,
4677,
63,
6776,
9,
199,
199,
1073,
63,
1715,
63,
3773,
275,
10967,
8,
505,
17441,
85,
7,
3773,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
3773,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
3773,
9,
199,
1073,
63,
1715,
63,
1807,
275,
10967,
8,
505,
17441,
85,
5121,
69,
1268,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
1807,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
1807,
9,
199,
1073,
63,
1715,
63,
1345,
275,
10967,
8,
505,
17441,
85,
7,
1345,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
1345,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
1345,
9,
199,
1073,
63,
1715,
63,
1345,
63,
4316,
275,
10967,
8,
505,
17441,
85,
7,
4316,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
1345,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
1345,
9,
199,
1073,
63,
1715,
63,
981,
275,
10967,
8,
505,
17441,
85,
7,
525,
2199,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
981,
297,
1249,
534,
643,
9501,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
981,
9,
199,
199,
1073,
63,
1715,
63,
815,
63,
3773,
275,
10967,
8,
505,
17441,
85,
7,
3773,
659,
2455,
534,
1715,
63,
815,
63,
3773,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
815,
63,
3773,
9,
199,
1073,
63,
1715,
63,
815,
63,
1807,
275,
10967,
8,
505,
17441,
85,
5121,
69,
1268,
659,
2455,
534,
1715,
63,
815,
63,
1807,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
815,
63,
1807,
9,
199,
1073,
63,
1715,
63,
815,
63,
1345,
275,
10967,
8,
505,
17441,
85,
7,
11697,
659,
2455,
534,
1715,
63,
815,
63,
1345,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
815,
63,
1345,
12,
4978,
63,
1345,
63,
3821,
2968,
1715,
63,
815,
1105,
199,
199,
1073,
63,
1715,
63,
16501,
63,
3773,
275,
10967,
8,
505,
17441,
85,
7,
3773,
659,
2455,
534,
1715,
63,
16501,
63,
3773,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
16501,
63,
3773,
9,
199,
1073,
63,
1715,
63,
16501,
63,
1807,
275,
10967,
8,
505,
17441,
85,
5121,
69,
1268,
659,
2455,
534,
1715,
63,
16501,
63,
1807,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
16501,
63,
1807,
9,
199,
1073,
63,
1715,
63,
16501,
63,
1345,
275,
10967,
8,
505,
17441,
85,
7,
16501,
659,
2455,
534,
1715,
63,
16501,
63,
1345,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
16501,
63,
1345,
12,
4978,
63,
1345,
63,
3821,
2968,
1715,
63,
16501,
1105,
199,
199,
1073,
63,
1715,
63,
5087,
63,
3773,
275,
10967,
8,
505,
17441,
85,
7,
3773,
659,
2455,
534,
1715,
63,
5087,
63,
3773,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
5087,
63,
3773,
9,
199,
1073,
63,
1715,
63,
5087,
63,
1807,
275,
10967,
8,
505,
17441,
85,
5121,
69,
1268,
659,
2455,
534,
1715,
63,
5087,
63,
1807,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
5087,
63,
1807,
9,
199,
1073,
63,
1715,
63,
5087,
63,
1345,
275,
10967,
8,
505,
17441,
85,
5121,
6473,
83,
659,
2455,
534,
1715,
63,
5087,
63,
1345,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
5087,
63,
1345,
12,
4978,
63,
1345,
63,
3821,
2968,
1715,
63,
5087,
1105,
199,
199,
1073,
63,
1715,
63,
493,
63,
513,
275,
10967,
8,
505,
17441,
85,
7,
1725,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
493,
63,
513,
297,
1249,
534,
1715,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
493,
63,
513,
12,
4978,
63,
1345,
63,
3821,
2968,
1715,
63,
493,
1105,
199,
1073,
63,
1715,
63,
493,
63,
5064,
275,
10967,
8,
505,
17441,
85,
7,
5064,
570,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
493,
63,
5064,
297,
1249,
534,
1715,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
493,
63,
5064,
9,
199,
1073,
63,
1715,
63,
493,
63,
1807,
275,
10967,
8,
505,
17441,
85,
5121,
69,
1268,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
493,
63,
1807,
297,
1249,
534,
13697,
63,
785
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
1839,
287,
2578,
14,
6060,
492,
13873,
22320,
63,
1254,
17059,
63,
17929,
12,
13873,
22320,
63,
1254,
17059,
63,
12058,
199,
504,
19191,
14,
2888,
492,
10967,
199,
199,
504,
1275,
16471,
492,
334,
4677,
63,
6776,
12,
7016,
63,
1715,
63,
3773,
12,
7016,
63,
1715,
63,
1807,
12,
272,
7016,
63,
1715,
63,
1345,
12,
7016,
63,
643,
9501,
63,
6776,
12,
7016,
63,
1715,
63,
981,
12,
272,
7016,
63,
1715,
63,
815,
63,
3773,
12,
7016,
63,
1715,
63,
815,
63,
1345,
12,
7016,
63,
1715,
63,
815,
63,
1807,
12,
272,
7016,
63,
1715,
63,
16501,
63,
3773,
12,
7016,
63,
1715,
63,
16501,
63,
1345,
12,
7016,
63,
1715,
63,
16501,
63,
1807,
12,
272,
7016,
63,
1715,
63,
5087,
63,
3773,
12,
7016,
63,
1715,
63,
5087,
63,
1345,
12,
7016,
63,
1715,
63,
5087,
63,
1807,
12,
272,
7016,
63,
1715,
63,
493,
63,
513,
12,
7016,
63,
1715,
63,
493,
63,
5064,
12,
7016,
63,
1715,
63,
493,
63,
1807,
12,
272,
7016,
63,
1715,
63,
493,
63,
4249,
9,
199,
504,
1275,
6060,
492,
334,
4227,
22320,
63,
10797,
63,
17929,
12,
13873,
22320,
63,
10797,
63,
7014,
12,
272,
13873,
22320,
63,
10797,
63,
12058,
9,
199,
199,
1073,
63,
6776,
275,
10967,
8,
505,
17441,
85,
7,
6776,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
513,
297,
7016,
29,
4677,
63,
6776,
9,
199,
199,
1073,
63,
1715,
63,
3773,
275,
10967,
8,
505,
17441,
85,
7,
3773,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
3773,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
3773,
9,
199,
1073,
63,
1715,
63,
1807,
275,
10967,
8,
505,
17441,
85,
5121,
69,
1268,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
1807,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
1807,
9,
199,
1073,
63,
1715,
63,
1345,
275,
10967,
8,
505,
17441,
85,
7,
1345,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
1345,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
1345,
9,
199,
1073,
63,
1715,
63,
1345,
63,
4316,
275,
10967,
8,
505,
17441,
85,
7,
4316,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
1345,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
1345,
9,
199,
1073,
63,
1715,
63,
981,
275,
10967,
8,
505,
17441,
85,
7,
525,
2199,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
981,
297,
1249,
534,
643,
9501,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
981,
9,
199,
199,
1073,
63,
1715,
63,
815,
63,
3773,
275,
10967,
8,
505,
17441,
85,
7,
3773,
659,
2455,
534,
1715,
63,
815,
63,
3773,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
815,
63,
3773,
9,
199,
1073,
63,
1715,
63,
815,
63,
1807,
275,
10967,
8,
505,
17441,
85,
5121,
69,
1268,
659,
2455,
534,
1715,
63,
815,
63,
1807,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
815,
63,
1807,
9,
199,
1073,
63,
1715,
63,
815,
63,
1345,
275,
10967,
8,
505,
17441,
85,
7,
11697,
659,
2455,
534,
1715,
63,
815,
63,
1345,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
815,
63,
1345,
12,
4978,
63,
1345,
63,
3821,
2968,
1715,
63,
815,
1105,
199,
199,
1073,
63,
1715,
63,
16501,
63,
3773,
275,
10967,
8,
505,
17441,
85,
7,
3773,
659,
2455,
534,
1715,
63,
16501,
63,
3773,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
16501,
63,
3773,
9,
199,
1073,
63,
1715,
63,
16501,
63,
1807,
275,
10967,
8,
505,
17441,
85,
5121,
69,
1268,
659,
2455,
534,
1715,
63,
16501,
63,
1807,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
16501,
63,
1807,
9,
199,
1073,
63,
1715,
63,
16501,
63,
1345,
275,
10967,
8,
505,
17441,
85,
7,
16501,
659,
2455,
534,
1715,
63,
16501,
63,
1345,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
16501,
63,
1345,
12,
4978,
63,
1345,
63,
3821,
2968,
1715,
63,
16501,
1105,
199,
199,
1073,
63,
1715,
63,
5087,
63,
3773,
275,
10967,
8,
505,
17441,
85,
7,
3773,
659,
2455,
534,
1715,
63,
5087,
63,
3773,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
5087,
63,
3773,
9,
199,
1073,
63,
1715,
63,
5087,
63,
1807,
275,
10967,
8,
505,
17441,
85,
5121,
69,
1268,
659,
2455,
534,
1715,
63,
5087,
63,
1807,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
5087,
63,
1807,
9,
199,
1073,
63,
1715,
63,
5087,
63,
1345,
275,
10967,
8,
505,
17441,
85,
5121,
6473,
83,
659,
2455,
534,
1715,
63,
5087,
63,
1345,
297,
1249,
534,
13697,
63,
785,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
5087,
63,
1345,
12,
4978,
63,
1345,
63,
3821,
2968,
1715,
63,
5087,
1105,
199,
199,
1073,
63,
1715,
63,
493,
63,
513,
275,
10967,
8,
505,
17441,
85,
7,
1725,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
493,
63,
513,
297,
1249,
534,
1715,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
493,
63,
513,
12,
4978,
63,
1345,
63,
3821,
2968,
1715,
63,
493,
1105,
199,
1073,
63,
1715,
63,
493,
63,
5064,
275,
10967,
8,
505,
17441,
85,
7,
5064,
570,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
493,
63,
5064,
297,
1249,
534,
1715,
14,
2051,
297,
7016,
29,
4677,
63,
1715,
63,
493,
63,
5064,
9,
199,
1073,
63,
1715,
63,
493,
63,
1807,
275,
10967,
8,
505,
17441,
85,
5121,
69,
1268,
659,
2455,
534,
19505,
6976,
63,
1715,
63,
493,
63,
1807,
297,
1249,
534,
13697,
63,
785,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
difcareer/Mobile-Security-Framework-MobSF
|
StaticAnalyzer/migrations/0001_initial.py
|
33
|
4971
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.CreateModel(
name='StaticAnalyzerAndroid',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('TITLE', models.TextField()),
('APP_NAME', models.TextField()),
('SIZE', models.CharField(max_length=50)),
('MD5', models.CharField(max_length=30)),
('SHA1', models.TextField()),
('SHA256', models.TextField()),
('PACKAGENAME', models.TextField()),
('MAINACTIVITY', models.TextField()),
('TARGET_SDK', models.CharField(max_length=50)),
('MAX_SDK', models.CharField(max_length=50)),
('MIN_SDK', models.CharField(max_length=50)),
('ANDROVERNAME', models.CharField(max_length=100)),
('ANDROVER', models.CharField(max_length=50)),
('MANIFEST_ANAL', models.TextField()),
('PERMISSIONS', models.TextField()),
('FILES', models.TextField()),
('CERTZ', models.TextField()),
('ACTIVITIES', models.TextField()),
('RECEIVERS', models.TextField()),
('PROVIDERS', models.TextField()),
('SERVICES', models.TextField()),
('LIBRARIES', models.TextField()),
('CNT_ACT', models.CharField(max_length=50)),
('CNT_PRO', models.CharField(max_length=50)),
('CNT_SER', models.CharField(max_length=50)),
('CNT_BRO', models.CharField(max_length=50)),
('CERT_INFO', models.TextField()),
('NATIVE', models.CharField(max_length=50)),
('DYNAMIC', models.CharField(max_length=50)),
('REFLECT', models.CharField(max_length=50)),
('CRYPTO', models.CharField(max_length=50)),
('OBFUS', models.CharField(max_length=50)),
('API', models.TextField()),
('DANG', models.TextField()),
('URLS', models.TextField()),
('EMAILS', models.TextField()),
('STRINGS', models.TextField()),
('ZIPPED', models.TextField()),
('MANI', models.TextField()),
('EXPORTED_ACT', models.TextField()),
],
),
migrations.CreateModel(
name='StaticAnalyzerIOSZIP',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('TITLE', models.TextField()),
('APPNAMEX', models.TextField()),
('SIZE', models.CharField(max_length=50)),
('MD5', models.CharField(max_length=50)),
('SHA1', models.TextField()),
('SHA256', models.TextField()),
('INFOPLIST', models.TextField()),
('BINNAME', models.TextField()),
('IDF', models.TextField()),
('VERSION', models.CharField(max_length=50)),
('SDK', models.TextField()),
('PLTFM', models.TextField()),
('MINX', models.TextField()),
('BIN_ANAL', models.TextField()),
('LIBS', models.TextField()),
('FILES', models.TextField()),
('SFILESX', models.TextField()),
('HTML', models.TextField()),
('CODEANAL', models.TextField()),
('URLnFile', models.TextField()),
('EmailnFile', models.TextField()),
],
),
migrations.CreateModel(
name='StaticAnalyzerIPA',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('TITLE', models.TextField()),
('APPNAMEX', models.TextField()),
('SIZE', models.CharField(max_length=50)),
('MD5', models.CharField(max_length=50)),
('SHA1', models.TextField()),
('SHA256', models.TextField()),
('INFOPLIST', models.TextField()),
('BINNAME', models.TextField()),
('IDF', models.TextField()),
('VERSION', models.CharField(max_length=50)),
('SDK', models.TextField()),
('PLTFM', models.TextField()),
('MINX', models.TextField()),
('BIN_ANAL', models.TextField()),
('LIBS', models.TextField()),
('FILES', models.TextField()),
('SFILESX', models.TextField()),
],
),
]
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
12,
6180,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
9278,
17606,
20762,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
19091,
297,
1709,
14,
6254,
4000,
355,
661,
7121,
63,
2339,
297,
1709,
14,
6254,
4000,
355,
661,
4305,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
5127,
21,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1216,
1826,
355,
661,
8461,
17,
297,
1709,
14,
6254,
4000,
355,
661,
8461,
3912,
297,
1709,
14,
6254,
4000,
355,
661,
6961,
1254,
11536,
297,
1709,
14,
6254,
4000,
355,
661,
5848,
20425,
1922,
297,
1709,
14,
6254,
4000,
355,
661,
9268,
63,
14939,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
4283,
63,
14939,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
4896,
63,
14939,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
3649,
1092,
2111,
2339,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
1826,
355,
661,
3649,
1092,
2111,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
24067,
63,
31158,
297,
1709,
14,
6254,
4000,
355,
661,
4227,
31978,
297,
1709,
14,
6254,
4000,
355,
661,
9472,
297,
1709,
14,
6254,
4000,
355,
661,
11163,
58,
297,
1709,
14,
6254,
4000,
355,
661,
20425,
19144,
297,
1709,
14,
6254,
4000,
355,
661,
28467,
41,
17223,
297,
1709,
14,
6254,
4000,
355,
661,
21403,
3960,
297,
1709,
14,
6254,
4000,
355,
661,
3279,
8670,
297,
1709,
14,
6254,
4000,
355,
661,
32723,
297,
1709,
14,
6254,
4000,
355,
661,
35,
12460,
63,
3036,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
35,
12460,
63,
2514,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
35,
12460,
63,
3279,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
35,
12460,
63,
21111,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
11163,
63,
4531,
297,
1709,
14,
6254,
4000,
355,
661,
46,
14277,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
28080,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
8279,
3923,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
2944,
7431,
2566,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
5488,
38,
1668,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
3735,
297,
1709,
14,
6254,
4000,
355,
661,
36,
3986,
297,
1709,
14,
6254,
4000,
355,
661,
31582,
297,
1709,
14,
6254,
4000,
355,
661,
10089,
51,
297,
1709,
14,
6254,
4000,
355,
661,
31271,
297,
1709,
14,
6254,
4000,
355,
661,
16977,
19359,
297,
1709,
14,
6254,
4000,
355,
661,
6588,
41,
297,
1709,
14,
6254,
4000,
355,
661,
18341,
1149,
63,
3036,
297,
1709,
14,
6254,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
9278,
17606,
13532,
16977,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
19091,
297,
1709,
14,
6254,
4000,
355,
661,
7121,
7335,
1438,
297,
1709,
14,
6254,
4000,
355,
661,
4305,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
5127,
21,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
8461,
17,
297,
1709,
14,
6254,
4000,
355,
661,
8461,
3912,
297,
1709,
14,
6254,
4000,
355,
661,
11384,
1938,
4924,
297,
1709,
14,
6254,
4000,
355,
661,
9431,
2339,
297,
1709,
14,
6254,
4000,
355,
661,
998,
38,
297,
1709,
14,
6254,
4000,
355,
661,
4612,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
14939,
297,
1709,
14,
6254,
4000,
355,
661,
2749,
6145,
45,
297,
1709,
14,
6254,
4000,
355,
661,
4896,
56,
297,
1709,
14,
6254,
4000,
355,
661,
9431,
63,
31158,
297,
1709,
14,
6254,
4000,
355,
661,
25161,
297,
1709,
14,
6254,
4000,
355,
661,
9472,
297,
1709,
14,
6254,
4000,
355,
661,
51,
9472,
56,
297,
1709,
14,
6254,
4000,
355,
661,
4943,
297,
1709,
14,
6254,
4000,
355,
661,
6012,
31158,
297,
1709,
14,
6254,
4000,
355,
661,
2632,
78,
1173,
297,
1709,
14,
6254,
4000,
355,
661,
7035,
78,
1173,
297,
1709,
14,
6254,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
9278,
17606,
1772,
33,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
19091,
297,
1709,
14,
6254,
4000,
355,
661,
7121,
7335,
1438,
297,
1709,
14,
6254,
4000,
355,
661,
4305,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
5127,
21,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
8461,
17,
297,
1709,
14,
6254,
4000,
355,
661,
8461,
3912,
297,
1709,
14,
6254,
4000,
355,
661,
11384,
1938,
4924,
297,
1709,
14,
6254,
4000,
355,
661,
9431,
2339,
297,
1709,
14,
6254,
4000,
355,
661,
998,
38,
297,
1709,
14,
6254,
4000,
355,
661,
4612,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
14939,
297,
1709,
14,
6254,
4000,
355,
661,
2749,
6145,
45,
297,
1709,
14,
6254,
4000,
355,
661,
4896,
56,
297,
1709,
14,
6254,
4000,
355,
661,
9431,
63,
31158,
297,
1709,
14,
6254,
4000,
355,
661,
25161,
297,
1709,
14,
6254,
4000,
355,
661
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
12,
6180,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
9278,
17606,
20762,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
19091,
297,
1709,
14,
6254,
4000,
355,
661,
7121,
63,
2339,
297,
1709,
14,
6254,
4000,
355,
661,
4305,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
5127,
21,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1216,
1826,
355,
661,
8461,
17,
297,
1709,
14,
6254,
4000,
355,
661,
8461,
3912,
297,
1709,
14,
6254,
4000,
355,
661,
6961,
1254,
11536,
297,
1709,
14,
6254,
4000,
355,
661,
5848,
20425,
1922,
297,
1709,
14,
6254,
4000,
355,
661,
9268,
63,
14939,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
4283,
63,
14939,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
4896,
63,
14939,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
3649,
1092,
2111,
2339,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
1826,
355,
661,
3649,
1092,
2111,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
24067,
63,
31158,
297,
1709,
14,
6254,
4000,
355,
661,
4227,
31978,
297,
1709,
14,
6254,
4000,
355,
661,
9472,
297,
1709,
14,
6254,
4000,
355,
661,
11163,
58,
297,
1709,
14,
6254,
4000,
355,
661,
20425,
19144,
297,
1709,
14,
6254,
4000,
355,
661,
28467,
41,
17223,
297,
1709,
14,
6254,
4000,
355,
661,
21403,
3960,
297,
1709,
14,
6254,
4000,
355,
661,
3279,
8670,
297,
1709,
14,
6254,
4000,
355,
661,
32723,
297,
1709,
14,
6254,
4000,
355,
661,
35,
12460,
63,
3036,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
35,
12460,
63,
2514,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
35,
12460,
63,
3279,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
35,
12460,
63,
21111,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
11163,
63,
4531,
297,
1709,
14,
6254,
4000,
355,
661,
46,
14277,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
28080,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
8279,
3923,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
2944,
7431,
2566,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
5488,
38,
1668,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
3735,
297,
1709,
14,
6254,
4000,
355,
661,
36,
3986,
297,
1709,
14,
6254,
4000,
355,
661,
31582,
297,
1709,
14,
6254,
4000,
355,
661,
10089,
51,
297,
1709,
14,
6254,
4000,
355,
661,
31271,
297,
1709,
14,
6254,
4000,
355,
661,
16977,
19359,
297,
1709,
14,
6254,
4000,
355,
661,
6588,
41,
297,
1709,
14,
6254,
4000,
355,
661,
18341,
1149,
63,
3036,
297,
1709,
14,
6254,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
9278,
17606,
13532,
16977,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
19091,
297,
1709,
14,
6254,
4000,
355,
661,
7121,
7335,
1438,
297,
1709,
14,
6254,
4000,
355,
661,
4305,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
5127,
21,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
8461,
17,
297,
1709,
14,
6254,
4000,
355,
661,
8461,
3912,
297,
1709,
14,
6254,
4000,
355,
661,
11384,
1938,
4924,
297,
1709,
14,
6254,
4000,
355,
661,
9431,
2339,
297,
1709,
14,
6254,
4000,
355,
661,
998,
38,
297,
1709,
14,
6254,
4000,
355,
661,
4612,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
14939,
297,
1709,
14,
6254,
4000,
355,
661,
2749,
6145,
45,
297,
1709,
14,
6254,
4000,
355,
661,
4896,
56,
297,
1709,
14,
6254,
4000,
355,
661,
9431,
63,
31158,
297,
1709,
14,
6254,
4000,
355,
661,
25161,
297,
1709,
14,
6254,
4000,
355,
661,
9472,
297,
1709,
14,
6254,
4000,
355,
661,
51,
9472,
56,
297,
1709,
14,
6254,
4000,
355,
661,
4943,
297,
1709,
14,
6254,
4000,
355,
661,
6012,
31158,
297,
1709,
14,
6254,
4000,
355,
661,
2632,
78,
1173,
297,
1709,
14,
6254,
4000,
355,
661,
7035,
78,
1173,
297,
1709,
14,
6254,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
9278,
17606,
1772,
33,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
19091,
297,
1709,
14,
6254,
4000,
355,
661,
7121,
7335,
1438,
297,
1709,
14,
6254,
4000,
355,
661,
4305,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
5127,
21,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
8461,
17,
297,
1709,
14,
6254,
4000,
355,
661,
8461,
3912,
297,
1709,
14,
6254,
4000,
355,
661,
11384,
1938,
4924,
297,
1709,
14,
6254,
4000,
355,
661,
9431,
2339,
297,
1709,
14,
6254,
4000,
355,
661,
998,
38,
297,
1709,
14,
6254,
4000,
355,
661,
4612,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
1826,
355,
661,
14939,
297,
1709,
14,
6254,
4000,
355,
661,
2749,
6145,
45,
297,
1709,
14,
6254,
4000,
355,
661,
4896,
56,
297,
1709,
14,
6254,
4000,
355,
661,
9431,
63,
31158,
297,
1709,
14,
6254,
4000,
355,
661,
25161,
297,
1709,
14,
6254,
4000,
355,
661,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ebu/PlugIt
|
tests/proxy_internal/test_plugit.py
|
1
|
12013
|
from _utils import TestBase
import json
import uuid
class TestPlugIt(TestBase):
@classmethod
def setup_class(self):
super(TestPlugIt, self).setup_class()
from plugit_proxy.plugIt import PlugIt
self.plugIt = PlugIt('http://0.0.0.0/')
myself = self
def _doQuery(url, method='GET', getParmeters=None, postParameters=None, files=None, extraHeaders={}, session={}):
myself.lastDoQueryCall = {'url': url, 'method': method, 'getParmeters': getParmeters, 'postParameters': postParameters, 'files': files, 'extraHeaders': extraHeaders, 'session': session}
class DummyResponse():
def json(self):
return myself.plugIt.toReplyJson()
@property
def status_code(self):
return myself.plugIt.toReplyStatusCode()
@property
def headers(self):
return myself.plugIt.toReplyHeaders()
@property
def content(self):
return json.dumps(self.json())
return DummyResponse()
self.plugIt.doQuery = _doQuery
def test_ping(self):
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {'data': self.lastDoQueryCall['url'].split('data=', 1)[1]}
assert(self.plugIt.ping())
self.plugIt.toReplyStatusCode = lambda: 404
assert(not self.plugIt.ping())
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {'data': self.lastDoQueryCall['url'].split('data=', 1)[1] * 2}
assert(not self.plugIt.ping())
assert(self.lastDoQueryCall['url'].startswith('ping'))
def test_check_version(self):
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {'result': 'Ok', 'version': self.plugIt.PI_API_VERSION, 'protocol': self.plugIt.PI_API_NAME}
assert(self.plugIt.checkVersion())
assert(self.lastDoQueryCall['url'] == 'version')
self.plugIt.toReplyJson = lambda: {'result': 'poney', 'version': self.plugIt.PI_API_VERSION, 'protocol': self.plugIt.PI_API_NAME}
assert(not self.plugIt.checkVersion())
self.plugIt.toReplyJson = lambda: {'result': 'Ok', 'version': self.plugIt.PI_API_VERSION * 2, 'protocol': self.plugIt.PI_API_NAME}
assert(not self.plugIt.checkVersion())
self.plugIt.toReplyJson = lambda: {'result': 'Ok', 'version': self.plugIt.PI_API_VERSION, 'protocol': self.plugIt.PI_API_NAME * 2}
assert(not self.plugIt.checkVersion())
self.plugIt.toReplyStatusCode = lambda: 201
self.plugIt.toReplyJson = lambda: {'result': 'Ok', 'version': self.plugIt.PI_API_VERSION, 'protocol': self.plugIt.PI_API_NAME}
assert(not self.plugIt.checkVersion())
def test_new_mail(self):
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {'result': 'Ok'}
message_id = str(uuid.uuid4())
message = str(uuid.uuid4())
assert(self.plugIt.newMail(message_id, message))
assert(self.lastDoQueryCall['url'] == 'mail')
assert(self.lastDoQueryCall['postParameters'].get('response_id') == message_id)
assert(self.lastDoQueryCall['postParameters'].get('message') == message)
self.plugIt.toReplyStatusCode = lambda: 201
assert(not self.plugIt.newMail(message_id, message))
def test_media(self):
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {}
self.plugIt.toReplyHeaders = lambda: {}
media = str(uuid.uuid4())
data, content_type, cache_control = self.plugIt.getMedia(media)
assert(data == '{}')
assert(content_type == 'application/octet-stream')
assert(self.lastDoQueryCall['url'] == 'media/{}'.format(media))
assert(not cache_control)
self.plugIt.toReplyHeaders = lambda: {'content-type': 'test', 'cache-control': 'public, max-age=31536000'}
data, content_type, cache_control = self.plugIt.getMedia(media)
assert(data == '{}')
assert(content_type == 'test')
assert(cache_control == 'public, max-age=31536000')
self.plugIt.toReplyStatusCode = lambda: 201
data, content_type, cache_control = self.plugIt.getMedia(media)
assert(not data)
assert(not content_type)
def test_meta(self):
k = str(uuid.uuid4())
path = str(uuid.uuid4())
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {'k': k}
self.plugIt.toReplyHeaders = lambda: {'expire': 'Wed, 21 Oct 2015 07:28:00 GMT'}
data = self.plugIt.getMeta(path)
assert(self.lastDoQueryCall['url'] == 'meta/{}'.format(path))
assert(data['k'] == k)
# Data should not be cached
self.plugIt.toReplyJson = lambda: {'k2': k}
data = self.plugIt.getMeta(path)
assert(data['k2'] == k)
def test_meta_fail(self):
path = str(uuid.uuid4())
self.plugIt.toReplyStatusCode = lambda: 201
assert(not self.plugIt.getMeta(path))
def test_meta_cache(self):
k = str(uuid.uuid4())
path = str(uuid.uuid4())
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {'k': k}
self.plugIt.toReplyHeaders = lambda: {}
# Data should be cached
data = self.plugIt.getMeta(path)
self.plugIt.toReplyJson = lambda: {'k2': k}
data = self.plugIt.getMeta(path)
assert(data['k'] == k)
def test_template(self):
k = str(uuid.uuid4())
path = str(uuid.uuid4())
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {'k': k, 'template_tag': '-'}
self.plugIt.toReplyHeaders = lambda: {}
data = json.loads(self.plugIt.getTemplate(path))
assert(self.lastDoQueryCall['url'] == 'template/{}'.format(path))
assert(data['k'] == k)
# Data should be cached
self.plugIt.toReplyJson = lambda: {'k2': k, 'template_tag': '-'}
data = json.loads(self.plugIt.getTemplate(path))
assert(data['k'] == k)
def test_template_fail(self):
path = str(uuid.uuid4())
self.plugIt.toReplyStatusCode = lambda: 201
assert(not self.plugIt.getTemplate(path))
def test_template_no_meta_no_template(self):
path = str(uuid.uuid4())
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {}
assert(not self.plugIt.getTemplate(path))
def test_do_action_normal_mode(self):
path = str(uuid.uuid4())
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {}
self.plugIt.toReplyHeaders = lambda: {}
assert(self.plugIt.doAction(path) == ({}, {}, {}))
assert(self.lastDoQueryCall['url'] == 'action/{}'.format(path))
def test_do_action_proxy_mode(self):
path = str(uuid.uuid4())
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {}
self.plugIt.toReplyHeaders = lambda: {}
assert(self.plugIt.doAction(path, proxyMode=True) == ("{}", {}, {}))
assert(self.lastDoQueryCall['url'] == path)
def test_do_action_proxy_mode_no_remplate(self):
k = str(uuid.uuid4())
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {'k': k}
self.plugIt.toReplyHeaders = lambda: {'ebuio-plugit-notemplate': True}
r, __, __ = self.plugIt.doAction('', proxyMode=True)
assert(r.__class__.__name__ == 'PlugItNoTemplate')
assert(json.loads(r.content)['k'] == k)
def test_do_action_data(self):
path = str(uuid.uuid4())
k = str(uuid.uuid4())
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {'k': k}
self.plugIt.toReplyHeaders = lambda: {}
assert(self.plugIt.doAction(path) == ({'k': k}, {}, {}))
def test_do_action_500(self):
self.plugIt.toReplyStatusCode = lambda: 500
assert(self.plugIt.doAction('')[0].__class__.__name__ == 'PlugIt500')
def test_do_action_fail(self):
self.plugIt.toReplyStatusCode = lambda: 501
assert(self.plugIt.doAction('') == (None, {}, {}))
def test_do_action_special_codes(self):
special_codes = [429, 404, 403, 401, 304]
for x in range(200, 500):
self.plugIt.toReplyStatusCode = lambda: x
r, __, __ = self.plugIt.doAction('')
if x in special_codes:
assert(r.__class__.__name__ == 'PlugItSpecialCode')
assert(r.code == x)
else:
assert(r.__class__.__name__ != 'PlugItSpecialCode')
def test_do_action_session(self):
k = str(uuid.uuid4())
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {}
self.plugIt.toReplyHeaders = lambda: {'Ebuio-PlugIt-SetSession-k': k}
assert(self.plugIt.doAction('') == ({}, {'k': k}, {}))
def test_do_action_redirect(self):
k = str(uuid.uuid4())
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {}
self.plugIt.toReplyHeaders = lambda: {'ebuio-plugit-redirect': k}
r, session, headers = self.plugIt.doAction('')
assert(r.__class__.__name__ == 'PlugItRedirect')
assert(r.url == k)
assert(not r.no_prefix)
assert(session == {})
assert(headers == {})
def test_do_action_redirect_noprefix(self):
k = str(uuid.uuid4())
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {}
self.plugIt.toReplyHeaders = lambda: {'ebuio-plugit-redirect': k, 'ebuio-plugit-redirect-noprefix': "True"}
r, session, headers = self.plugIt.doAction('')
assert(r.__class__.__name__ == 'PlugItRedirect')
assert(r.url == k)
assert(r.no_prefix)
assert(session == {})
assert(headers == {})
def test_do_action_file(self):
k = str(uuid.uuid4())
content_type = str(uuid.uuid4())
content_disposition = str(uuid.uuid4())
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {'k': k}
self.plugIt.toReplyHeaders = lambda: {'ebuio-plugit-itafile': k, 'Content-Type': content_type}
r, session, headers = self.plugIt.doAction('')
assert(r.__class__.__name__ == 'PlugItFile')
assert(json.loads(r.content)['k'] == k)
assert(r.content_type == content_type)
assert(r.content_disposition == '')
assert(session == {})
assert(headers == {})
self.plugIt.toReplyHeaders = lambda: {'ebuio-plugit-itafile': k, 'Content-Type': content_type, 'content-disposition': content_disposition}
r, __, __ = self.plugIt.doAction('')
assert(r.content_disposition == content_disposition)
def test_do_action_etag(self):
k = str(uuid.uuid4())
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {}
self.plugIt.toReplyHeaders = lambda: {'ETag': k}
r, session, headers = self.plugIt.doAction('')
assert(headers == {'ETag': k})
def test_do_action_crossdomain(self):
k = str(uuid.uuid4())
self.plugIt.toReplyStatusCode = lambda: 200
self.plugIt.toReplyJson = lambda: {}
for header in ['Access-Control-Allow-Origin', 'Access-Control-Allow-Credentials', 'Access-Control-Expose-Headers', 'Access-Control-Max-Age', 'Access-Control-Allow-Methods', 'Access-Control-Allow-Headers']:
self.plugIt.toReplyHeaders = lambda: {header: k}
r, session, headers = self.plugIt.doAction('')
assert(headers == {header: k})
|
bsd-3-clause
|
[
504,
485,
1208,
492,
1379,
1563,
421,
199,
646,
2022,
199,
646,
5377,
421,
199,
533,
1379,
19173,
7940,
8,
14440,
304,
339,
768,
3744,
272,
347,
3272,
63,
533,
8,
277,
304,
267,
1613,
8,
774,
19173,
7940,
12,
291,
680,
2758,
63,
533,
342,
398,
687,
14202,
390,
63,
3280,
14,
13963,
7940,
492,
7497,
1518,
7940,
398,
291,
14,
13963,
7940,
275,
7497,
1518,
7940,
360,
1014,
921,
16,
14,
16,
14,
16,
14,
16,
6217,
398,
3002,
277,
275,
291,
398,
347,
485,
1117,
3227,
8,
633,
12,
1083,
534,
2970,
297,
664,
1262,
20893,
29,
403,
12,
2963,
5976,
29,
403,
12,
1584,
29,
403,
12,
2402,
9883,
10324,
2351,
16420,
288,
3002,
277,
14,
2019,
2585,
3227,
2176,
275,
791,
633,
356,
1166,
12,
283,
765,
356,
1083,
12,
283,
362,
1262,
20893,
356,
664,
1262,
20893,
12,
283,
1932,
5976,
356,
2963,
5976,
12,
283,
1725,
356,
1584,
12,
283,
2911,
9883,
356,
2402,
9883,
12,
283,
1730,
356,
2351,
93,
953,
1021,
9762,
2364,
837,
355,
347,
2022,
8,
277,
304,
490,
372,
3002,
277,
14,
13963,
7940,
14,
475,
14166,
9653,
342,
2234,
768,
1829,
355,
347,
2004,
63,
600,
8,
277,
304,
490,
372,
3002,
277,
14,
13963,
7940,
14,
475,
14166,
23018,
342,
2234,
768,
1829,
355,
347,
2323,
8,
277,
304,
490,
372,
3002,
277,
14,
13963,
7940,
14,
475,
14166,
9883,
342,
2234,
768,
1829,
355,
347,
1564,
8,
277,
304,
490,
372,
2022,
14,
4180,
8,
277,
14,
1001,
1012,
953,
372,
9762,
2364,
342,
398,
291,
14,
13963,
7940,
14,
1117,
3227,
275,
485,
1117,
3227,
339,
347,
511,
63,
4073,
8,
277,
304,
398,
291,
14,
13963,
7940,
14,
475,
14166,
23018,
275,
2400,
26,
1926,
267,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
791,
576,
356,
291,
14,
2019,
2585,
3227,
2176,
459,
633,
2278,
1294,
360,
576,
4009,
413,
2788,
17,
9420,
398,
702,
8,
277,
14,
13963,
7940,
14,
4073,
1012,
398,
291,
14,
13963,
7940,
14,
475,
14166,
23018,
275,
2400,
26,
7901,
398,
702,
8,
1397,
291,
14,
13963,
7940,
14,
4073,
1012,
398,
291,
14,
13963,
7940,
14,
475,
14166,
23018,
275,
2400,
26,
1926,
267,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
791,
576,
356,
291,
14,
2019,
2585,
3227,
2176,
459,
633,
2278,
1294,
360,
576,
4009,
413,
2788,
17,
61,
627,
499,
93,
398,
702,
8,
1397,
291,
14,
13963,
7940,
14,
4073,
1012,
398,
702,
8,
277,
14,
2019,
2585,
3227,
2176,
459,
633,
2278,
2460,
360,
4073,
1333,
339,
347,
511,
63,
1074,
63,
1023,
8,
277,
304,
398,
291,
14,
13963,
7940,
14,
475,
14166,
23018,
275,
2400,
26,
1926,
267,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
791,
1099,
356,
283,
11622,
297,
283,
1023,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
4612,
12,
283,
3922,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
2339,
93,
398,
702,
8,
277,
14,
13963,
7940,
14,
1074,
3353,
1012,
267,
702,
8,
277,
14,
2019,
2585,
3227,
2176,
459,
633,
418,
508,
283,
1023,
358,
398,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
791,
1099,
356,
283,
80,
13234,
297,
283,
1023,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
4612,
12,
283,
3922,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
2339,
93,
267,
702,
8,
1397,
291,
14,
13963,
7940,
14,
1074,
3353,
1012,
398,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
791,
1099,
356,
283,
11622,
297,
283,
1023,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
4612,
627,
499,
12,
283,
3922,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
2339,
93,
267,
702,
8,
1397,
291,
14,
13963,
7940,
14,
1074,
3353,
1012,
398,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
791,
1099,
356,
283,
11622,
297,
283,
1023,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
4612,
12,
283,
3922,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
2339,
627,
499,
93,
267,
702,
8,
1397,
291,
14,
13963,
7940,
14,
1074,
3353,
1012,
398,
291,
14,
13963,
7940,
14,
475,
14166,
23018,
275,
2400,
26,
1784,
267,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
791,
1099,
356,
283,
11622,
297,
283,
1023,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
4612,
12,
283,
3922,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
2339,
93,
398,
702,
8,
1397,
291,
14,
13963,
7940,
14,
1074,
3353,
1012,
339,
347,
511,
63,
1222,
63,
1198,
8,
277,
304,
398,
291,
14,
13963,
7940,
14,
475,
14166,
23018,
275,
2400,
26,
1926,
267,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
791,
1099,
356,
283,
11622,
936,
398,
1245,
63,
344,
275,
620,
8,
2580,
14,
2580,
20,
1012,
267,
1245,
275,
620,
8,
2580,
14,
2580,
20,
1012,
398,
702,
8,
277,
14,
13963,
7940,
14,
1222,
13681,
8,
1188,
63,
344,
12,
1245,
430,
267,
702,
8,
277,
14,
2019,
2585,
3227,
2176,
459,
633,
418,
508,
283,
1198,
358,
267,
702,
8,
277,
14,
2019,
2585,
3227,
2176,
459,
1932,
5976,
2278,
362,
360,
1310,
63,
344,
358,
508,
1245,
63,
344,
9,
267,
702,
8,
277,
14,
2019,
2585,
3227,
2176,
459,
1932,
5976,
2278,
362,
360,
1188,
358,
508,
1245,
9,
398,
291,
14,
13963,
7940,
14,
475,
14166,
23018,
275,
2400,
26,
1784,
267,
702,
8,
1397,
291,
14,
13963,
7940,
14,
1222,
13681,
8,
1188,
63,
344,
12,
1245,
430,
339,
347,
511,
63,
4603,
8,
277,
304,
267,
291,
14,
13963,
7940,
14,
475,
14166,
23018,
275,
2400,
26,
1926,
267,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
1052,
267,
291,
14,
13963,
7940,
14,
475,
14166,
9883,
275,
2400,
26,
1052,
398,
5898,
275,
620,
8,
2580,
14,
2580,
20,
1012,
398,
666,
12,
1564,
63,
466,
12,
2581,
63,
2785,
275,
291,
14,
13963,
7940,
14,
362
] |
[
485,
1208,
492,
1379,
1563,
421,
199,
646,
2022,
199,
646,
5377,
421,
199,
533,
1379,
19173,
7940,
8,
14440,
304,
339,
768,
3744,
272,
347,
3272,
63,
533,
8,
277,
304,
267,
1613,
8,
774,
19173,
7940,
12,
291,
680,
2758,
63,
533,
342,
398,
687,
14202,
390,
63,
3280,
14,
13963,
7940,
492,
7497,
1518,
7940,
398,
291,
14,
13963,
7940,
275,
7497,
1518,
7940,
360,
1014,
921,
16,
14,
16,
14,
16,
14,
16,
6217,
398,
3002,
277,
275,
291,
398,
347,
485,
1117,
3227,
8,
633,
12,
1083,
534,
2970,
297,
664,
1262,
20893,
29,
403,
12,
2963,
5976,
29,
403,
12,
1584,
29,
403,
12,
2402,
9883,
10324,
2351,
16420,
288,
3002,
277,
14,
2019,
2585,
3227,
2176,
275,
791,
633,
356,
1166,
12,
283,
765,
356,
1083,
12,
283,
362,
1262,
20893,
356,
664,
1262,
20893,
12,
283,
1932,
5976,
356,
2963,
5976,
12,
283,
1725,
356,
1584,
12,
283,
2911,
9883,
356,
2402,
9883,
12,
283,
1730,
356,
2351,
93,
953,
1021,
9762,
2364,
837,
355,
347,
2022,
8,
277,
304,
490,
372,
3002,
277,
14,
13963,
7940,
14,
475,
14166,
9653,
342,
2234,
768,
1829,
355,
347,
2004,
63,
600,
8,
277,
304,
490,
372,
3002,
277,
14,
13963,
7940,
14,
475,
14166,
23018,
342,
2234,
768,
1829,
355,
347,
2323,
8,
277,
304,
490,
372,
3002,
277,
14,
13963,
7940,
14,
475,
14166,
9883,
342,
2234,
768,
1829,
355,
347,
1564,
8,
277,
304,
490,
372,
2022,
14,
4180,
8,
277,
14,
1001,
1012,
953,
372,
9762,
2364,
342,
398,
291,
14,
13963,
7940,
14,
1117,
3227,
275,
485,
1117,
3227,
339,
347,
511,
63,
4073,
8,
277,
304,
398,
291,
14,
13963,
7940,
14,
475,
14166,
23018,
275,
2400,
26,
1926,
267,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
791,
576,
356,
291,
14,
2019,
2585,
3227,
2176,
459,
633,
2278,
1294,
360,
576,
4009,
413,
2788,
17,
9420,
398,
702,
8,
277,
14,
13963,
7940,
14,
4073,
1012,
398,
291,
14,
13963,
7940,
14,
475,
14166,
23018,
275,
2400,
26,
7901,
398,
702,
8,
1397,
291,
14,
13963,
7940,
14,
4073,
1012,
398,
291,
14,
13963,
7940,
14,
475,
14166,
23018,
275,
2400,
26,
1926,
267,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
791,
576,
356,
291,
14,
2019,
2585,
3227,
2176,
459,
633,
2278,
1294,
360,
576,
4009,
413,
2788,
17,
61,
627,
499,
93,
398,
702,
8,
1397,
291,
14,
13963,
7940,
14,
4073,
1012,
398,
702,
8,
277,
14,
2019,
2585,
3227,
2176,
459,
633,
2278,
2460,
360,
4073,
1333,
339,
347,
511,
63,
1074,
63,
1023,
8,
277,
304,
398,
291,
14,
13963,
7940,
14,
475,
14166,
23018,
275,
2400,
26,
1926,
267,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
791,
1099,
356,
283,
11622,
297,
283,
1023,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
4612,
12,
283,
3922,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
2339,
93,
398,
702,
8,
277,
14,
13963,
7940,
14,
1074,
3353,
1012,
267,
702,
8,
277,
14,
2019,
2585,
3227,
2176,
459,
633,
418,
508,
283,
1023,
358,
398,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
791,
1099,
356,
283,
80,
13234,
297,
283,
1023,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
4612,
12,
283,
3922,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
2339,
93,
267,
702,
8,
1397,
291,
14,
13963,
7940,
14,
1074,
3353,
1012,
398,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
791,
1099,
356,
283,
11622,
297,
283,
1023,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
4612,
627,
499,
12,
283,
3922,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
2339,
93,
267,
702,
8,
1397,
291,
14,
13963,
7940,
14,
1074,
3353,
1012,
398,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
791,
1099,
356,
283,
11622,
297,
283,
1023,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
4612,
12,
283,
3922,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
2339,
627,
499,
93,
267,
702,
8,
1397,
291,
14,
13963,
7940,
14,
1074,
3353,
1012,
398,
291,
14,
13963,
7940,
14,
475,
14166,
23018,
275,
2400,
26,
1784,
267,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
791,
1099,
356,
283,
11622,
297,
283,
1023,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
4612,
12,
283,
3922,
356,
291,
14,
13963,
7940,
14,
2252,
63,
3735,
63,
2339,
93,
398,
702,
8,
1397,
291,
14,
13963,
7940,
14,
1074,
3353,
1012,
339,
347,
511,
63,
1222,
63,
1198,
8,
277,
304,
398,
291,
14,
13963,
7940,
14,
475,
14166,
23018,
275,
2400,
26,
1926,
267,
291,
14,
13963,
7940,
14,
475,
14166,
9653,
275,
2400,
26,
791,
1099,
356,
283,
11622,
936,
398,
1245,
63,
344,
275,
620,
8,
2580,
14,
2580,
20,
1012,
267,
1245,
275,
620,
8,
2580,
14,
2580,
20,
1012,
398,
702,
8,
277,
14,
13963,
7940,
14,
1222,
13681,
8,
1188,
63,
344,
12,
1245,
430,
267,
702,
8,
277,
14,
2019,
2585,
3227,
2176,
459,
633,
418,
508,
283,
1198,
358,
267,
702,
8,
277,
14,
2019,
2585,
3227,
2176,
459,
1932,
5976,
2278,
362,
360,
1310,
63,
344,
358,
508,
1245,
63,
344,
9,
267,
702,
8,
277,
14,
2019,
2585,
3227,
2176,
459,
1932,
5976,
2278,
362,
360,
1188,
358,
508,
1245,
9,
398,
291,
14,
13963,
7940,
14,
475,
14166,
23018,
275,
2400,
26,
1784,
267,
702,
8,
1397,
291,
14,
13963,
7940,
14,
1222,
13681,
8,
1188,
63,
344,
12,
1245,
430,
339,
347,
511,
63,
4603,
8,
277,
304,
267,
291,
14,
13963,
7940,
14,
475,
14166,
23018,
275,
2400,
26,
1926,
267,
291,
14,
13963,
7940,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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
] |
dingocuster/scikit-learn
|
sklearn/metrics/regression.py
|
175
|
16953
|
"""Metrics to assess performance on regression task
Functions named as ``*_score`` return a scalar value to maximize: the higher
the better
Function named as ``*_error`` or ``*_loss`` return a scalar value to minimize:
the lower the better
"""
# Authors: Alexandre Gramfort <alexandre.gramfort@inria.fr>
# Mathieu Blondel <mathieu@mblondel.org>
# Olivier Grisel <olivier.grisel@ensta.org>
# Arnaud Joly <a.joly@ulg.ac.be>
# Jochen Wersdorfer <jochen@wersdoerfer.de>
# Lars Buitinck <L.J.Buitinck@uva.nl>
# Joel Nothman <joel.nothman@gmail.com>
# Noel Dawe <noel@dawe.me>
# Manoj Kumar <manojkumarsivaraj334@gmail.com>
# Michael Eickenberg <michael.eickenberg@gmail.com>
# Konstantin Shmelkov <konstantin.shmelkov@polytechnique.edu>
# License: BSD 3 clause
from __future__ import division
import numpy as np
from ..utils.validation import check_array, check_consistent_length
from ..utils.validation import column_or_1d
import warnings
__ALL__ = [
"mean_absolute_error",
"mean_squared_error",
"median_absolute_error",
"r2_score",
"explained_variance_score"
]
def _check_reg_targets(y_true, y_pred, multioutput):
"""Check that y_true and y_pred belong to the same regression task
Parameters
----------
y_true : array-like,
y_pred : array-like,
multioutput : array-like or string in ['raw_values', uniform_average',
'variance_weighted'] or None
None is accepted due to backward compatibility of r2_score().
Returns
-------
type_true : one of {'continuous', continuous-multioutput'}
The type of the true target data, as output by
'utils.multiclass.type_of_target'
y_true : array-like of shape = (n_samples, n_outputs)
Ground truth (correct) target values.
y_pred : array-like of shape = (n_samples, n_outputs)
Estimated target values.
multioutput : array-like of shape = (n_outputs) or string in ['raw_values',
uniform_average', 'variance_weighted'] or None
Custom output weights if ``multioutput`` is array-like or
just the corresponding argument if ``multioutput`` is a
correct keyword.
"""
check_consistent_length(y_true, y_pred)
y_true = check_array(y_true, ensure_2d=False)
y_pred = check_array(y_pred, ensure_2d=False)
if y_true.ndim == 1:
y_true = y_true.reshape((-1, 1))
if y_pred.ndim == 1:
y_pred = y_pred.reshape((-1, 1))
if y_true.shape[1] != y_pred.shape[1]:
raise ValueError("y_true and y_pred have different number of output "
"({0}!={1})".format(y_true.shape[1], y_pred.shape[1]))
n_outputs = y_true.shape[1]
multioutput_options = (None, 'raw_values', 'uniform_average',
'variance_weighted')
if multioutput not in multioutput_options:
multioutput = check_array(multioutput, ensure_2d=False)
if n_outputs == 1:
raise ValueError("Custom weights are useful only in "
"multi-output cases.")
elif n_outputs != len(multioutput):
raise ValueError(("There must be equally many custom weights "
"(%d) as outputs (%d).") %
(len(multioutput), n_outputs))
y_type = 'continuous' if n_outputs == 1 else 'continuous-multioutput'
return y_type, y_true, y_pred, multioutput
def mean_absolute_error(y_true, y_pred,
sample_weight=None,
multioutput='uniform_average'):
"""Mean absolute error regression loss
Read more in the :ref:`User Guide <mean_absolute_error>`.
Parameters
----------
y_true : array-like of shape = (n_samples) or (n_samples, n_outputs)
Ground truth (correct) target values.
y_pred : array-like of shape = (n_samples) or (n_samples, n_outputs)
Estimated target values.
sample_weight : array-like of shape = (n_samples), optional
Sample weights.
multioutput : string in ['raw_values', 'uniform_average']
or array-like of shape (n_outputs)
Defines aggregating of multiple output values.
Array-like value defines weights used to average errors.
'raw_values' :
Returns a full set of errors in case of multioutput input.
'uniform_average' :
Errors of all outputs are averaged with uniform weight.
Returns
-------
loss : float or ndarray of floats
If multioutput is 'raw_values', then mean absolute error is returned
for each output separately.
If multioutput is 'uniform_average' or an ndarray of weights, then the
weighted average of all output errors is returned.
MAE output is non-negative floating point. The best value is 0.0.
Examples
--------
>>> from sklearn.metrics import mean_absolute_error
>>> y_true = [3, -0.5, 2, 7]
>>> y_pred = [2.5, 0.0, 2, 8]
>>> mean_absolute_error(y_true, y_pred)
0.5
>>> y_true = [[0.5, 1], [-1, 1], [7, -6]]
>>> y_pred = [[0, 2], [-1, 2], [8, -5]]
>>> mean_absolute_error(y_true, y_pred)
0.75
>>> mean_absolute_error(y_true, y_pred, multioutput='raw_values')
array([ 0.5, 1. ])
>>> mean_absolute_error(y_true, y_pred, multioutput=[0.3, 0.7])
... # doctest: +ELLIPSIS
0.849...
"""
y_type, y_true, y_pred, multioutput = _check_reg_targets(
y_true, y_pred, multioutput)
output_errors = np.average(np.abs(y_pred - y_true),
weights=sample_weight, axis=0)
if multioutput == 'raw_values':
return output_errors
elif multioutput == 'uniform_average':
# pass None as weights to np.average: uniform mean
multioutput = None
return np.average(output_errors, weights=multioutput)
def mean_squared_error(y_true, y_pred,
sample_weight=None,
multioutput='uniform_average'):
"""Mean squared error regression loss
Read more in the :ref:`User Guide <mean_squared_error>`.
Parameters
----------
y_true : array-like of shape = (n_samples) or (n_samples, n_outputs)
Ground truth (correct) target values.
y_pred : array-like of shape = (n_samples) or (n_samples, n_outputs)
Estimated target values.
sample_weight : array-like of shape = (n_samples), optional
Sample weights.
multioutput : string in ['raw_values', 'uniform_average']
or array-like of shape (n_outputs)
Defines aggregating of multiple output values.
Array-like value defines weights used to average errors.
'raw_values' :
Returns a full set of errors in case of multioutput input.
'uniform_average' :
Errors of all outputs are averaged with uniform weight.
Returns
-------
loss : float or ndarray of floats
A non-negative floating point value (the best value is 0.0), or an
array of floating point values, one for each individual target.
Examples
--------
>>> from sklearn.metrics import mean_squared_error
>>> y_true = [3, -0.5, 2, 7]
>>> y_pred = [2.5, 0.0, 2, 8]
>>> mean_squared_error(y_true, y_pred)
0.375
>>> y_true = [[0.5, 1],[-1, 1],[7, -6]]
>>> y_pred = [[0, 2],[-1, 2],[8, -5]]
>>> mean_squared_error(y_true, y_pred) # doctest: +ELLIPSIS
0.708...
>>> mean_squared_error(y_true, y_pred, multioutput='raw_values')
... # doctest: +ELLIPSIS
array([ 0.416..., 1. ])
>>> mean_squared_error(y_true, y_pred, multioutput=[0.3, 0.7])
... # doctest: +ELLIPSIS
0.824...
"""
y_type, y_true, y_pred, multioutput = _check_reg_targets(
y_true, y_pred, multioutput)
output_errors = np.average((y_true - y_pred) ** 2, axis=0,
weights=sample_weight)
if multioutput == 'raw_values':
return output_errors
elif multioutput == 'uniform_average':
# pass None as weights to np.average: uniform mean
multioutput = None
return np.average(output_errors, weights=multioutput)
def median_absolute_error(y_true, y_pred):
"""Median absolute error regression loss
Read more in the :ref:`User Guide <median_absolute_error>`.
Parameters
----------
y_true : array-like of shape = (n_samples)
Ground truth (correct) target values.
y_pred : array-like of shape = (n_samples)
Estimated target values.
Returns
-------
loss : float
A positive floating point value (the best value is 0.0).
Examples
--------
>>> from sklearn.metrics import median_absolute_error
>>> y_true = [3, -0.5, 2, 7]
>>> y_pred = [2.5, 0.0, 2, 8]
>>> median_absolute_error(y_true, y_pred)
0.5
"""
y_type, y_true, y_pred, _ = _check_reg_targets(y_true, y_pred,
'uniform_average')
if y_type == 'continuous-multioutput':
raise ValueError("Multioutput not supported in median_absolute_error")
return np.median(np.abs(y_pred - y_true))
def explained_variance_score(y_true, y_pred,
sample_weight=None,
multioutput='uniform_average'):
"""Explained variance regression score function
Best possible score is 1.0, lower values are worse.
Read more in the :ref:`User Guide <explained_variance_score>`.
Parameters
----------
y_true : array-like of shape = (n_samples) or (n_samples, n_outputs)
Ground truth (correct) target values.
y_pred : array-like of shape = (n_samples) or (n_samples, n_outputs)
Estimated target values.
sample_weight : array-like of shape = (n_samples), optional
Sample weights.
multioutput : string in ['raw_values', 'uniform_average', \
'variance_weighted'] or array-like of shape (n_outputs)
Defines aggregating of multiple output scores.
Array-like value defines weights used to average scores.
'raw_values' :
Returns a full set of scores in case of multioutput input.
'uniform_average' :
Scores of all outputs are averaged with uniform weight.
'variance_weighted' :
Scores of all outputs are averaged, weighted by the variances
of each individual output.
Returns
-------
score : float or ndarray of floats
The explained variance or ndarray if 'multioutput' is 'raw_values'.
Notes
-----
This is not a symmetric function.
Examples
--------
>>> from sklearn.metrics import explained_variance_score
>>> y_true = [3, -0.5, 2, 7]
>>> y_pred = [2.5, 0.0, 2, 8]
>>> explained_variance_score(y_true, y_pred) # doctest: +ELLIPSIS
0.957...
>>> y_true = [[0.5, 1], [-1, 1], [7, -6]]
>>> y_pred = [[0, 2], [-1, 2], [8, -5]]
>>> explained_variance_score(y_true, y_pred, multioutput='uniform_average')
... # doctest: +ELLIPSIS
0.983...
"""
y_type, y_true, y_pred, multioutput = _check_reg_targets(
y_true, y_pred, multioutput)
y_diff_avg = np.average(y_true - y_pred, weights=sample_weight, axis=0)
numerator = np.average((y_true - y_pred - y_diff_avg) ** 2,
weights=sample_weight, axis=0)
y_true_avg = np.average(y_true, weights=sample_weight, axis=0)
denominator = np.average((y_true - y_true_avg) ** 2,
weights=sample_weight, axis=0)
nonzero_numerator = numerator != 0
nonzero_denominator = denominator != 0
valid_score = nonzero_numerator & nonzero_denominator
output_scores = np.ones(y_true.shape[1])
output_scores[valid_score] = 1 - (numerator[valid_score] /
denominator[valid_score])
output_scores[nonzero_numerator & ~nonzero_denominator] = 0.
if multioutput == 'raw_values':
# return scores individually
return output_scores
elif multioutput == 'uniform_average':
# passing to np.average() None as weights results is uniform mean
avg_weights = None
elif multioutput == 'variance_weighted':
avg_weights = denominator
else:
avg_weights = multioutput
return np.average(output_scores, weights=avg_weights)
def r2_score(y_true, y_pred,
sample_weight=None,
multioutput=None):
"""R^2 (coefficient of determination) regression score function.
Best possible score is 1.0 and it can be negative (because the
model can be arbitrarily worse). A constant model that always
predicts the expected value of y, disregarding the input features,
would get a R^2 score of 0.0.
Read more in the :ref:`User Guide <r2_score>`.
Parameters
----------
y_true : array-like of shape = (n_samples) or (n_samples, n_outputs)
Ground truth (correct) target values.
y_pred : array-like of shape = (n_samples) or (n_samples, n_outputs)
Estimated target values.
sample_weight : array-like of shape = (n_samples), optional
Sample weights.
multioutput : string in ['raw_values', 'uniform_average',
'variance_weighted'] or None or array-like of shape (n_outputs)
Defines aggregating of multiple output scores.
Array-like value defines weights used to average scores.
Default value correponds to 'variance_weighted', but
will be changed to 'uniform_average' in next versions.
'raw_values' :
Returns a full set of scores in case of multioutput input.
'uniform_average' :
Scores of all outputs are averaged with uniform weight.
'variance_weighted' :
Scores of all outputs are averaged, weighted by the variances
of each individual output.
Returns
-------
z : float or ndarray of floats
The R^2 score or ndarray of scores if 'multioutput' is
'raw_values'.
Notes
-----
This is not a symmetric function.
Unlike most other scores, R^2 score may be negative (it need not actually
be the square of a quantity R).
References
----------
.. [1] `Wikipedia entry on the Coefficient of determination
<http://en.wikipedia.org/wiki/Coefficient_of_determination>`_
Examples
--------
>>> from sklearn.metrics import r2_score
>>> y_true = [3, -0.5, 2, 7]
>>> y_pred = [2.5, 0.0, 2, 8]
>>> r2_score(y_true, y_pred) # doctest: +ELLIPSIS
0.948...
>>> y_true = [[0.5, 1], [-1, 1], [7, -6]]
>>> y_pred = [[0, 2], [-1, 2], [8, -5]]
>>> r2_score(y_true, y_pred, multioutput='variance_weighted') # doctest: +ELLIPSIS
0.938...
"""
y_type, y_true, y_pred, multioutput = _check_reg_targets(
y_true, y_pred, multioutput)
if sample_weight is not None:
sample_weight = column_or_1d(sample_weight)
weight = sample_weight[:, np.newaxis]
else:
weight = 1.
numerator = (weight * (y_true - y_pred) ** 2).sum(axis=0,
dtype=np.float64)
denominator = (weight * (y_true - np.average(
y_true, axis=0, weights=sample_weight)) ** 2).sum(axis=0,
dtype=np.float64)
nonzero_denominator = denominator != 0
nonzero_numerator = numerator != 0
valid_score = nonzero_denominator & nonzero_numerator
output_scores = np.ones([y_true.shape[1]])
output_scores[valid_score] = 1 - (numerator[valid_score] /
denominator[valid_score])
# arbitrary set to zero to avoid -inf scores, having a constant
# y_true is not interesting for scoring a regression anyway
output_scores[nonzero_numerator & ~nonzero_denominator] = 0.
if multioutput is None and y_true.shape[1] != 1:
# @FIXME change in 0.18
warnings.warn("Default 'multioutput' behavior now corresponds to "
"'variance_weighted' value, it will be changed "
"to 'uniform_average' in 0.18.",
DeprecationWarning)
multioutput = 'variance_weighted'
if multioutput == 'raw_values':
# return scores individually
return output_scores
elif multioutput == 'uniform_average':
# passing None as weights results is uniform mean
avg_weights = None
elif multioutput == 'variance_weighted':
avg_weights = denominator
# avoid fail on constant y or one-element arrays
if not np.any(nonzero_denominator):
if not np.any(nonzero_numerator):
return 1.0
else:
return 0.0
else:
avg_weights = multioutput
return np.average(output_scores, weights=avg_weights)
|
bsd-3-clause
|
[
624,
17213,
370,
465,
5480,
10238,
641,
10864,
2120,
199,
199,
13967,
4310,
465,
1124,
10,
63,
3397,
1040,
372,
282,
6917,
574,
370,
1390,
11807,
26,
314,
10948,
199,
1589,
8034,
199,
199,
3481,
4310,
465,
1124,
10,
63,
705,
1040,
503,
1124,
10,
63,
4358,
1040,
372,
282,
6917,
574,
370,
24720,
26,
199,
1589,
5117,
314,
8034,
199,
624,
199,
199,
3,
6642,
26,
22986,
28547,
27211,
10279,
665,
24421,
28547,
14,
1679,
10279,
32,
262,
23714,
14,
4391,
30,
199,
3,
3515,
21066,
29364,
699,
5298,
2264,
665,
3442,
29364,
32,
887,
5298,
2264,
14,
1308,
30,
199,
3,
3515,
593,
317,
26645,
598,
322,
5891,
665,
23711,
26645,
14,
7928,
5891,
32,
287,
1207,
14,
1308,
30,
199,
3,
3515,
1952,
3540,
1181,
1603,
16242,
665,
65,
14,
74,
16242,
32,
27092,
14,
645,
14,
1235,
30,
199,
3,
3515,
7135,
24604,
644,
1192,
68,
269,
2412,
665,
743,
24604,
32,
12203,
1117,
281,
2412,
14,
271,
30,
199,
3,
3515,
491,
4291,
4779,
390,
262,
346,
665,
44,
14,
42,
14,
1713,
390,
262,
346,
32,
85,
3042,
14,
7530,
30,
199,
3,
3515,
7135,
352,
3091,
273,
1237,
665,
743,
352,
14,
889,
273,
1237,
32,
6799,
14,
957,
30,
199,
3,
3515,
3091,
352,
577,
65,
1129,
665,
889,
352,
32,
983,
1129,
14,
278,
30,
199,
3,
3515,
4688,
79,
74,
1804,
453,
285,
665,
1237,
79,
17421,
453,
285,
338,
1391,
9091,
8425,
32,
6799,
14,
957,
30,
199,
3,
3515,
16922,
662,
2000,
287,
14630,
665,
22333,
14,
69,
2000,
287,
14630,
32,
6799,
14,
957,
30,
199,
3,
3515,
1804,
265,
4715,
262,
5244,
26908,
7697,
86,
665,
75,
265,
4715,
262,
14,
609,
26908,
7697,
86,
32,
6023,
266,
11019,
2029,
14,
8654,
30,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
2508,
1208,
14,
6136,
492,
1104,
63,
1144,
12,
1104,
63,
15478,
63,
1267,
199,
504,
2508,
1208,
14,
6136,
492,
2763,
63,
269,
63,
17,
68,
199,
199,
646,
3598,
199,
199,
363,
1761,
363,
275,
359,
272,
298,
3670,
63,
6116,
63,
705,
401,
272,
298,
3670,
63,
12973,
63,
705,
401,
272,
298,
13106,
63,
6116,
63,
705,
401,
272,
298,
82,
18,
63,
3397,
401,
272,
298,
1474,
23918,
63,
6221,
63,
3397,
2,
199,
61,
421,
199,
318,
485,
1074,
63,
1135,
63,
4684,
8,
89,
63,
2052,
12,
612,
63,
5991,
12,
3510,
1199,
304,
272,
408,
1799,
626,
612,
63,
2052,
436,
612,
63,
5991,
13511,
370,
314,
2011,
10864,
2120,
339,
3897,
272,
4143,
272,
612,
63,
2052,
520,
1625,
13,
2930,
12,
339,
612,
63,
5991,
520,
1625,
13,
2930,
12,
339,
3510,
1199,
520,
1625,
13,
2930,
503,
1059,
315,
788,
1773,
63,
1459,
297,
14818,
63,
8536,
297,
267,
283,
6221,
63,
13522,
418,
503,
488,
267,
488,
365,
10226,
7037,
370,
13388,
7163,
402,
519,
18,
63,
3397,
1252,
339,
1803,
272,
5514,
272,
730,
63,
2052,
520,
1373,
402,
791,
23458,
297,
19922,
13,
3029,
1199,
936,
267,
710,
730,
402,
314,
2549,
1347,
666,
12,
465,
1072,
701,
267,
283,
1208,
14,
30016,
14,
466,
63,
1618,
63,
1375,
7,
339,
612,
63,
2052,
520,
1625,
13,
2930,
402,
2215,
275,
334,
78,
63,
3356,
12,
302,
63,
4467,
9,
267,
598,
2363,
16865,
334,
4525,
9,
1347,
1338,
14,
339,
612,
63,
5991,
520,
1625,
13,
2930,
402,
2215,
275,
334,
78,
63,
3356,
12,
302,
63,
4467,
9,
267,
15896,
12754,
1347,
1338,
14,
339,
3510,
1199,
520,
1625,
13,
2930,
402,
2215,
275,
334,
78,
63,
4467,
9,
503,
1059,
315,
788,
1773,
63,
1459,
297,
267,
14818,
63,
8536,
297,
283,
6221,
63,
13522,
418,
503,
488,
267,
8388,
1072,
4931,
340,
1124,
3029,
1199,
1040,
365,
1625,
13,
2930,
503,
267,
2951,
314,
5226,
1423,
340,
1124,
3029,
1199,
1040,
365,
282,
267,
3211,
4252,
14,
339,
408,
272,
1104,
63,
15478,
63,
1267,
8,
89,
63,
2052,
12,
612,
63,
5991,
9,
272,
612,
63,
2052,
275,
1104,
63,
1144,
8,
89,
63,
2052,
12,
4868,
63,
18,
68,
29,
797,
9,
272,
612,
63,
5991,
275,
1104,
63,
1144,
8,
89,
63,
5991,
12,
4868,
63,
18,
68,
29,
797,
9,
339,
340,
612,
63,
2052,
14,
8322,
508,
413,
26,
267,
612,
63,
2052,
275,
612,
63,
2052,
14,
5217,
18138,
17,
12,
413,
430,
339,
340,
612,
63,
5991,
14,
8322,
508,
413,
26,
267,
612,
63,
5991,
275,
612,
63,
5991,
14,
5217,
18138,
17,
12,
413,
430,
339,
340,
612,
63,
2052,
14,
1392,
59,
17,
61,
1137,
612,
63,
5991,
14,
1392,
59,
17,
2189,
267,
746,
1722,
480,
89,
63,
2052,
436,
612,
63,
5991,
1172,
3365,
1329,
402,
1072,
298,
586,
298,
2561,
16,
93,
1111,
91,
17,
25974,
908,
8,
89,
63,
2052,
14,
1392,
59,
17,
467,
612,
63,
5991,
14,
1392,
59,
17,
2459,
339,
302,
63,
4467,
275,
612,
63,
2052,
14,
1392,
59,
17,
61,
272,
3510,
1199,
63,
1419,
275,
334,
403,
12,
283,
1773,
63,
1459,
297,
283,
8830,
63,
8536,
297,
2574,
283,
6221,
63,
13522,
358,
272,
340,
3510,
1199,
440,
315,
3510,
1199,
63,
1419,
26,
267,
3510,
1199,
275,
1104,
63,
1144,
8,
3029,
1199,
12,
4868,
63,
18,
68,
29,
797,
9,
267,
340,
302,
63,
4467,
508,
413,
26,
288,
746,
1722,
480,
7223,
4931,
787,
2997,
1454,
315,
298,
2490,
298,
3029,
13,
1199,
5560,
2685,
267,
916,
302,
63,
4467,
1137,
822,
8,
3029,
1199,
304,
288,
746,
1722,
9313,
10924,
1471,
506,
11960,
1183,
5002,
3537,
4931,
298,
2892,
26448,
68,
9,
465,
4704,
4366,
68,
26744,
450,
2490,
334,
552,
8,
3029,
1199,
395,
302,
63,
4467,
430,
272,
612,
63,
466,
275,
283,
23458,
7,
340,
302,
63,
4467,
508,
413,
587,
283,
23458,
13,
3029,
1199,
7,
339,
372,
612,
63,
466,
12,
612,
63,
2052,
12,
612,
63,
5991,
12,
3510,
1199,
421,
199,
318,
4615,
63,
6116,
63,
705,
8,
89,
63,
2052,
12
] |
[
17213,
370,
465,
5480,
10238,
641,
10864,
2120,
199,
199,
13967,
4310,
465,
1124,
10,
63,
3397,
1040,
372,
282,
6917,
574,
370,
1390,
11807,
26,
314,
10948,
199,
1589,
8034,
199,
199,
3481,
4310,
465,
1124,
10,
63,
705,
1040,
503,
1124,
10,
63,
4358,
1040,
372,
282,
6917,
574,
370,
24720,
26,
199,
1589,
5117,
314,
8034,
199,
624,
199,
199,
3,
6642,
26,
22986,
28547,
27211,
10279,
665,
24421,
28547,
14,
1679,
10279,
32,
262,
23714,
14,
4391,
30,
199,
3,
3515,
21066,
29364,
699,
5298,
2264,
665,
3442,
29364,
32,
887,
5298,
2264,
14,
1308,
30,
199,
3,
3515,
593,
317,
26645,
598,
322,
5891,
665,
23711,
26645,
14,
7928,
5891,
32,
287,
1207,
14,
1308,
30,
199,
3,
3515,
1952,
3540,
1181,
1603,
16242,
665,
65,
14,
74,
16242,
32,
27092,
14,
645,
14,
1235,
30,
199,
3,
3515,
7135,
24604,
644,
1192,
68,
269,
2412,
665,
743,
24604,
32,
12203,
1117,
281,
2412,
14,
271,
30,
199,
3,
3515,
491,
4291,
4779,
390,
262,
346,
665,
44,
14,
42,
14,
1713,
390,
262,
346,
32,
85,
3042,
14,
7530,
30,
199,
3,
3515,
7135,
352,
3091,
273,
1237,
665,
743,
352,
14,
889,
273,
1237,
32,
6799,
14,
957,
30,
199,
3,
3515,
3091,
352,
577,
65,
1129,
665,
889,
352,
32,
983,
1129,
14,
278,
30,
199,
3,
3515,
4688,
79,
74,
1804,
453,
285,
665,
1237,
79,
17421,
453,
285,
338,
1391,
9091,
8425,
32,
6799,
14,
957,
30,
199,
3,
3515,
16922,
662,
2000,
287,
14630,
665,
22333,
14,
69,
2000,
287,
14630,
32,
6799,
14,
957,
30,
199,
3,
3515,
1804,
265,
4715,
262,
5244,
26908,
7697,
86,
665,
75,
265,
4715,
262,
14,
609,
26908,
7697,
86,
32,
6023,
266,
11019,
2029,
14,
8654,
30,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
2508,
1208,
14,
6136,
492,
1104,
63,
1144,
12,
1104,
63,
15478,
63,
1267,
199,
504,
2508,
1208,
14,
6136,
492,
2763,
63,
269,
63,
17,
68,
199,
199,
646,
3598,
199,
199,
363,
1761,
363,
275,
359,
272,
298,
3670,
63,
6116,
63,
705,
401,
272,
298,
3670,
63,
12973,
63,
705,
401,
272,
298,
13106,
63,
6116,
63,
705,
401,
272,
298,
82,
18,
63,
3397,
401,
272,
298,
1474,
23918,
63,
6221,
63,
3397,
2,
199,
61,
421,
199,
318,
485,
1074,
63,
1135,
63,
4684,
8,
89,
63,
2052,
12,
612,
63,
5991,
12,
3510,
1199,
304,
272,
408,
1799,
626,
612,
63,
2052,
436,
612,
63,
5991,
13511,
370,
314,
2011,
10864,
2120,
339,
3897,
272,
4143,
272,
612,
63,
2052,
520,
1625,
13,
2930,
12,
339,
612,
63,
5991,
520,
1625,
13,
2930,
12,
339,
3510,
1199,
520,
1625,
13,
2930,
503,
1059,
315,
788,
1773,
63,
1459,
297,
14818,
63,
8536,
297,
267,
283,
6221,
63,
13522,
418,
503,
488,
267,
488,
365,
10226,
7037,
370,
13388,
7163,
402,
519,
18,
63,
3397,
1252,
339,
1803,
272,
5514,
272,
730,
63,
2052,
520,
1373,
402,
791,
23458,
297,
19922,
13,
3029,
1199,
936,
267,
710,
730,
402,
314,
2549,
1347,
666,
12,
465,
1072,
701,
267,
283,
1208,
14,
30016,
14,
466,
63,
1618,
63,
1375,
7,
339,
612,
63,
2052,
520,
1625,
13,
2930,
402,
2215,
275,
334,
78,
63,
3356,
12,
302,
63,
4467,
9,
267,
598,
2363,
16865,
334,
4525,
9,
1347,
1338,
14,
339,
612,
63,
5991,
520,
1625,
13,
2930,
402,
2215,
275,
334,
78,
63,
3356,
12,
302,
63,
4467,
9,
267,
15896,
12754,
1347,
1338,
14,
339,
3510,
1199,
520,
1625,
13,
2930,
402,
2215,
275,
334,
78,
63,
4467,
9,
503,
1059,
315,
788,
1773,
63,
1459,
297,
267,
14818,
63,
8536,
297,
283,
6221,
63,
13522,
418,
503,
488,
267,
8388,
1072,
4931,
340,
1124,
3029,
1199,
1040,
365,
1625,
13,
2930,
503,
267,
2951,
314,
5226,
1423,
340,
1124,
3029,
1199,
1040,
365,
282,
267,
3211,
4252,
14,
339,
408,
272,
1104,
63,
15478,
63,
1267,
8,
89,
63,
2052,
12,
612,
63,
5991,
9,
272,
612,
63,
2052,
275,
1104,
63,
1144,
8,
89,
63,
2052,
12,
4868,
63,
18,
68,
29,
797,
9,
272,
612,
63,
5991,
275,
1104,
63,
1144,
8,
89,
63,
5991,
12,
4868,
63,
18,
68,
29,
797,
9,
339,
340,
612,
63,
2052,
14,
8322,
508,
413,
26,
267,
612,
63,
2052,
275,
612,
63,
2052,
14,
5217,
18138,
17,
12,
413,
430,
339,
340,
612,
63,
5991,
14,
8322,
508,
413,
26,
267,
612,
63,
5991,
275,
612,
63,
5991,
14,
5217,
18138,
17,
12,
413,
430,
339,
340,
612,
63,
2052,
14,
1392,
59,
17,
61,
1137,
612,
63,
5991,
14,
1392,
59,
17,
2189,
267,
746,
1722,
480,
89,
63,
2052,
436,
612,
63,
5991,
1172,
3365,
1329,
402,
1072,
298,
586,
298,
2561,
16,
93,
1111,
91,
17,
25974,
908,
8,
89,
63,
2052,
14,
1392,
59,
17,
467,
612,
63,
5991,
14,
1392,
59,
17,
2459,
339,
302,
63,
4467,
275,
612,
63,
2052,
14,
1392,
59,
17,
61,
272,
3510,
1199,
63,
1419,
275,
334,
403,
12,
283,
1773,
63,
1459,
297,
283,
8830,
63,
8536,
297,
2574,
283,
6221,
63,
13522,
358,
272,
340,
3510,
1199,
440,
315,
3510,
1199,
63,
1419,
26,
267,
3510,
1199,
275,
1104,
63,
1144,
8,
3029,
1199,
12,
4868,
63,
18,
68,
29,
797,
9,
267,
340,
302,
63,
4467,
508,
413,
26,
288,
746,
1722,
480,
7223,
4931,
787,
2997,
1454,
315,
298,
2490,
298,
3029,
13,
1199,
5560,
2685,
267,
916,
302,
63,
4467,
1137,
822,
8,
3029,
1199,
304,
288,
746,
1722,
9313,
10924,
1471,
506,
11960,
1183,
5002,
3537,
4931,
298,
2892,
26448,
68,
9,
465,
4704,
4366,
68,
26744,
450,
2490,
334,
552,
8,
3029,
1199,
395,
302,
63,
4467,
430,
272,
612,
63,
466,
275,
283,
23458,
7,
340,
302,
63,
4467,
508,
413,
587,
283,
23458,
13,
3029,
1199,
7,
339,
372,
612,
63,
466,
12,
612,
63,
2052,
12,
612,
63,
5991,
12,
3510,
1199,
421,
199,
318,
4615,
63,
6116,
63,
705,
8,
89,
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,
1,
1,
1,
1,
1
] |
max0d41/kazoo
|
kazoo/client.py
|
2
|
49800
|
"""Kazoo Zookeeper Client"""
import inspect
import logging
import os
import re
import warnings
from collections import defaultdict, deque
from functools import partial
from os.path import split
from kazoo.exceptions import (
AuthFailedError,
ConfigurationError,
ConnectionClosedError,
ConnectionLoss,
NoNodeError,
NodeExistsError,
SessionExpiredError,
WriterNotClosedException,
)
from kazoo.handlers.threading import SequentialThreadingHandler
from kazoo.handlers.utils import capture_exceptions, wrap
from kazoo.hosts import collect_hosts
from kazoo.loggingsupport import BLATHER
from kazoo.protocol.connection import ConnectionHandler
from kazoo.protocol.paths import normpath
from kazoo.protocol.paths import _prefix_root
from kazoo.protocol.serialization import (
Auth,
CheckVersion,
CloseInstance,
Create,
Delete,
Exists,
GetChildren,
GetChildren2,
GetACL,
SetACL,
GetData,
SetData,
Sync,
Transaction
)
from kazoo.protocol.states import KazooState
from kazoo.protocol.states import KeeperState
from kazoo.retry import KazooRetry
from kazoo.security import ACL
from kazoo.security import OPEN_ACL_UNSAFE
# convenience API
from kazoo.recipe.barrier import Barrier
from kazoo.recipe.barrier import DoubleBarrier
from kazoo.recipe.counter import Counter
from kazoo.recipe.election import Election
from kazoo.recipe.lock import Lock
from kazoo.recipe.lock import Semaphore
from kazoo.recipe.partitioner import SetPartitioner
from kazoo.recipe.party import Party
from kazoo.recipe.party import ShallowParty
from kazoo.recipe.queue import Queue
from kazoo.recipe.queue import LockingQueue
from kazoo.recipe.watchers import ChildrenWatch
from kazoo.recipe.watchers import DataWatch
try: # pragma: nocover
basestring
except NameError: # pragma: nocover
basestring = str
LOST_STATES = (KeeperState.EXPIRED_SESSION, KeeperState.AUTH_FAILED,
KeeperState.CLOSED)
ENVI_VERSION = re.compile('[\w\s:.]*=([\d\.]*).*', re.DOTALL)
log = logging.getLogger(__name__)
_RETRY_COMPAT_DEFAULTS = dict(
max_retries=None,
retry_delay=0.1,
retry_backoff=2,
retry_jitter=0.8,
retry_max_delay=3600,
)
_RETRY_COMPAT_MAPPING = dict(
max_retries='max_tries',
retry_delay='delay',
retry_backoff='backoff',
retry_jitter='max_jitter',
retry_max_delay='max_delay',
)
class KazooClient(object):
"""An Apache Zookeeper Python client supporting alternate callback
handlers and high-level functionality.
Watch functions registered with this class will not get session
events, unlike the default Zookeeper watches. They will also be
called with a single argument, a
:class:`~kazoo.protocol.states.WatchedEvent` instance.
"""
def __init__(self, hosts='127.0.0.1:2181',
timeout=10.0, client_id=None, handler=None,
default_acl=None, auth_data=None, read_only=None,
randomize_hosts=True, connection_retry=None,
command_retry=None, logger=None, **kwargs):
"""Create a :class:`KazooClient` instance. All time arguments
are in seconds.
:param hosts: Comma-separated list of hosts to connect to
(e.g. 127.0.0.1:2181,127.0.0.1:2182,[::1]:2183).
:param timeout: The longest to wait for a Zookeeper connection.
:param client_id: A Zookeeper client id, used when
re-establishing a prior session connection.
:param handler: An instance of a class implementing the
:class:`~kazoo.interfaces.IHandler` interface
for callback handling.
:param default_acl: A default ACL used on node creation.
:param auth_data:
A list of authentication credentials to use for the
connection. Should be a list of (scheme, credential)
tuples as :meth:`add_auth` takes.
:param read_only: Allow connections to read only servers.
:param randomize_hosts: By default randomize host selection.
:param connection_retry:
A :class:`kazoo.retry.KazooRetry` object to use for
retrying the connection to Zookeeper. Also can be a dict of
options which will be used for creating one.
:param command_retry:
A :class:`kazoo.retry.KazooRetry` object to use for
the :meth:`KazooClient.retry` method. Also can be a dict of
options which will be used for creating one.
:param logger: A custom logger to use instead of the module
global `log` instance.
Basic Example:
.. code-block:: python
zk = KazooClient()
zk.start()
children = zk.get_children('/')
zk.stop()
As a convenience all recipe classes are available as attributes
and get automatically bound to the client. For example::
zk = KazooClient()
zk.start()
lock = zk.Lock('/lock_path')
.. versionadded:: 0.6
The read_only option. Requires Zookeeper 3.4+
.. versionadded:: 0.6
The retry_max_delay option.
.. versionadded:: 0.6
The randomize_hosts option.
.. versionchanged:: 0.8
Removed the unused watcher argument (was second argument).
.. versionadded:: 1.2
The connection_retry, command_retry and logger options.
"""
self.logger = logger or log
# Record the handler strategy used
self.handler = handler if handler else SequentialThreadingHandler()
if inspect.isclass(self.handler):
raise ConfigurationError("Handler must be an instance of a class, "
"not the class: %s" % self.handler)
self.auth_data = auth_data if auth_data else set([])
self.default_acl = default_acl
self.randomize_hosts = randomize_hosts
self.hosts = None
self.chroot = None
self.set_hosts(hosts)
# Curator like simplified state tracking, and listeners for
# state transitions
self._state = KeeperState.CLOSED
self.state = KazooState.LOST
self.state_listeners = set()
self._reset()
self.read_only = read_only
if client_id:
self._session_id = client_id[0]
self._session_passwd = client_id[1]
else:
self._reset_session()
# ZK uses milliseconds
self._session_timeout = int(timeout * 1000)
# We use events like twitter's client to track current and
# desired state (connected, and whether to shutdown)
self._live = self.handler.event_object()
self._writer_stopped = self.handler.event_object()
self._stopped = self.handler.event_object()
self._stopped.set()
self._writer_stopped.set()
self.retry = self._conn_retry = None
if type(connection_retry) is dict:
self._conn_retry = KazooRetry(**connection_retry)
elif type(connection_retry) is KazooRetry:
self._conn_retry = connection_retry
if type(command_retry) is dict:
self.retry = KazooRetry(**command_retry)
elif type(command_retry) is KazooRetry:
self.retry = command_retry
if type(self._conn_retry) is KazooRetry:
if self.handler.sleep_func != self._conn_retry.sleep_func:
raise ConfigurationError("Retry handler and event handler "
" must use the same sleep func")
if type(self.retry) is KazooRetry:
if self.handler.sleep_func != self.retry.sleep_func:
raise ConfigurationError(
"Command retry handler and event handler "
"must use the same sleep func")
if self.retry is None or self._conn_retry is None:
old_retry_keys = dict(_RETRY_COMPAT_DEFAULTS)
for key in old_retry_keys:
try:
old_retry_keys[key] = kwargs.pop(key)
warnings.warn(
'Passing retry configuration param %s to the '
'client directly is deprecated, please pass a '
'configured retry object (using param %s)' % (
key, _RETRY_COMPAT_MAPPING[key]),
DeprecationWarning, stacklevel=2)
except KeyError:
pass
retry_keys = {}
for oldname, value in old_retry_keys.items():
retry_keys[_RETRY_COMPAT_MAPPING[oldname]] = value
if self._conn_retry is None:
self._conn_retry = KazooRetry(
sleep_func=self.handler.sleep_func,
**retry_keys)
if self.retry is None:
self.retry = KazooRetry(
sleep_func=self.handler.sleep_func,
**retry_keys)
self._conn_retry.interrupt = lambda: self._stopped.is_set()
self._connection = ConnectionHandler(
self, self._conn_retry.copy(), logger=self.logger)
# Every retry call should have its own copy of the retry helper
# to avoid shared retry counts
self._retry = self.retry
def _retry(*args, **kwargs):
return self._retry.copy()(*args, **kwargs)
self.retry = _retry
self.Barrier = partial(Barrier, self)
self.Counter = partial(Counter, self)
self.DoubleBarrier = partial(DoubleBarrier, self)
self.ChildrenWatch = partial(ChildrenWatch, self)
self.DataWatch = partial(DataWatch, self)
self.Election = partial(Election, self)
self.Lock = partial(Lock, self)
self.Party = partial(Party, self)
self.Queue = partial(Queue, self)
self.LockingQueue = partial(LockingQueue, self)
self.SetPartitioner = partial(SetPartitioner, self)
self.Semaphore = partial(Semaphore, self)
self.ShallowParty = partial(ShallowParty, self)
# If we got any unhandled keywords, complain like Python would
if kwargs:
raise TypeError('__init__() got unexpected keyword arguments: %s'
% (kwargs.keys(),))
def _reset(self):
"""Resets a variety of client states for a new connection."""
self._queue = deque()
self._pending = deque()
self._reset_watchers()
self._reset_session()
self.last_zxid = 0
self._protocol_version = None
def _reset_watchers(self):
self._child_watchers = defaultdict(set)
self._data_watchers = defaultdict(set)
def _reset_session(self):
self._session_id = None
self._session_passwd = b'\x00' * 16
@property
def client_state(self):
"""Returns the last Zookeeper client state
This is the non-simplified state information and is generally
not as useful as the simplified KazooState information.
"""
return self._state
@property
def client_id(self):
"""Returns the client id for this Zookeeper session if
connected.
:returns: client id which consists of the session id and
password.
:rtype: tuple
"""
if self._live.is_set():
return (self._session_id, self._session_passwd)
return None
@property
def connected(self):
"""Returns whether the Zookeeper connection has been
established."""
return self._live.is_set()
def set_hosts(self, hosts, randomize_hosts=None):
""" sets the list of hosts used by this client.
This function accepts the same format hosts parameter as the init
function and sets the client to use the new hosts the next time it
needs to look up a set of hosts. This function does not affect the
current connected status.
It is not currently possible to change the chroot with this function,
setting a host list with a new chroot will raise a ConfigurationError.
:param hosts: see description in :meth:`KazooClient.__init__`
:param randomize_hosts: override client default for host randomization
:raises:
:exc:`ConfigurationError` if the hosts argument changes the chroot
.. versionadded:: 1.4
.. warning::
Using this function to point a client to a completely disparate
zookeeper server cluster has undefined behavior.
"""
if randomize_hosts is None:
randomize_hosts = self.randomize_hosts
self.hosts, chroot = collect_hosts(hosts, randomize_hosts)
if chroot:
new_chroot = normpath(chroot)
else:
new_chroot = ''
if self.chroot is not None and new_chroot != self.chroot:
raise ConfigurationError("Changing chroot at runtime is not "
"currently supported")
self.chroot = new_chroot
def add_listener(self, listener):
"""Add a function to be called for connection state changes.
This function will be called with a
:class:`~kazoo.protocol.states.KazooState` instance indicating
the new connection state on state transitions.
.. warning::
This function must not block. If its at all likely that it
might need data or a value that could result in blocking
than the :meth:`~kazoo.interfaces.IHandler.spawn` method
should be used so that the listener can return immediately.
"""
if not (listener and callable(listener)):
raise ConfigurationError("listener must be callable")
self.state_listeners.add(listener)
def remove_listener(self, listener):
"""Remove a listener function"""
self.state_listeners.discard(listener)
def _make_state_change(self, state):
# skip if state is current
if self.state == state:
return
self.state = state
# Create copy of listeners for iteration in case one needs to
# remove itself
for listener in list(self.state_listeners):
try:
remove = listener(state)
if remove is True:
self.remove_listener(listener)
except Exception:
self.logger.exception("Error in connection state listener")
def _session_callback(self, state):
if state == self._state:
return
# Note that we don't check self.state == LOST since that's also
# the client's initial state
dead_state = self._state in LOST_STATES
self._state = state
# If we were previously closed or had an expired session, and
# are now connecting, don't bother with the rest of the
# transitions since they only apply after
# we've established a connection
if dead_state and state == KeeperState.CONNECTING:
self.logger.log(BLATHER, "Skipping state change")
return
if state in (KeeperState.CONNECTED, KeeperState.CONNECTED_RO):
self.logger.info("Zookeeper connection established, "
"state: %s", state)
self._live.set()
self._make_state_change(KazooState.CONNECTED)
elif state in LOST_STATES:
self.logger.info("Zookeeper session lost, state: %s", state)
self._live.clear()
self._make_state_change(KazooState.LOST)
self._notify_pending(state)
self._reset()
else:
self.logger.info("Zookeeper connection lost")
# Connection lost
self._live.clear()
self._notify_pending(state)
self._make_state_change(KazooState.SUSPENDED)
self._reset_watchers()
def _notify_pending(self, state):
"""Used to clear a pending response queue and request queue
during connection drops."""
if state == KeeperState.AUTH_FAILED:
exc = AuthFailedError()
elif state == KeeperState.EXPIRED_SESSION:
exc = SessionExpiredError()
else:
exc = ConnectionLoss()
while True:
try:
request, async_object, xid = self._pending.popleft()
if async_object:
async_object.set_exception(exc)
except IndexError:
break
while True:
try:
request, async_object = self._queue.popleft()
if async_object:
async_object.set_exception(exc)
except IndexError:
break
def _safe_close(self):
self.handler.stop()
timeout = self._session_timeout // 1000
if timeout < 10:
timeout = 10
if not self._connection.stop(timeout):
raise WriterNotClosedException(
"Writer still open from prior connection "
"and wouldn't close after %s seconds" % timeout)
def _call(self, request, async_object):
"""Ensure there's an active connection and put the request in
the queue if there is.
Returns False if the call short circuits due to AUTH_FAILED,
CLOSED, EXPIRED_SESSION or CONNECTING state.
"""
if self._state == KeeperState.AUTH_FAILED:
async_object.set_exception(AuthFailedError())
return False
elif self._state == KeeperState.CLOSED:
async_object.set_exception(ConnectionClosedError(
"Connection has been closed"))
return False
elif self._state in (KeeperState.EXPIRED_SESSION,
KeeperState.CONNECTING):
async_object.set_exception(SessionExpiredError())
return False
self._queue.append((request, async_object))
# wake the connection, guarding against a race with close()
write_sock = self._connection._write_sock
if write_sock is None:
async_object.set_exception(ConnectionClosedError(
"Connection has been closed"))
try:
write_sock.send(b'\0')
except:
async_object.set_exception(ConnectionClosedError(
"Connection has been closed"))
def start(self, timeout=15):
"""Initiate connection to ZK.
:param timeout: Time in seconds to wait for connection to
succeed.
:raises: :attr:`~kazoo.interfaces.IHandler.timeout_exception`
if the connection wasn't established within `timeout`
seconds.
"""
event = self.start_async()
event.wait(timeout=timeout)
if not self.connected:
# We time-out, ensure we are disconnected
self.stop()
raise self.handler.timeout_exception("Connection time-out")
if self.chroot and not self.exists("/"):
warnings.warn("No chroot path exists, the chroot path "
"should be created before normal use.")
def start_async(self):
"""Asynchronously initiate connection to ZK.
:returns: An event object that can be checked to see if the
connection is alive.
:rtype: :class:`~threading.Event` compatible object.
"""
# If we're already connected, ignore
if self._live.is_set():
return self._live
# Make sure we're safely closed
self._safe_close()
# We've been asked to connect, clear the stop and our writer
# thread indicator
self._stopped.clear()
self._writer_stopped.clear()
# Start the handler
self.handler.start()
# Start the connection
self._connection.start()
return self._live
def stop(self):
"""Gracefully stop this Zookeeper session.
This method can be called while a reconnection attempt is in
progress, which will then be halted.
Once the connection is closed, its session becomes invalid. All
the ephemeral nodes in the ZooKeeper server associated with the
session will be removed. The watches left on those nodes (and
on their parents) will be triggered.
"""
if self._stopped.is_set():
return
self._stopped.set()
self._queue.append((CloseInstance, None))
self._connection._write_sock.send(b'\0')
self._safe_close()
def restart(self):
"""Stop and restart the Zookeeper session."""
self.stop()
self.start()
def close(self):
"""Free any resources held by the client.
This method should be called on a stopped client before it is
discarded. Not doing so may result in filehandles being leaked.
.. versionadded:: 1.0
"""
self._connection.close()
def command(self, cmd=b'ruok'):
"""Sent a management command to the current ZK server.
Examples are `ruok`, `envi` or `stat`.
:returns: An unstructured textual response.
:rtype: str
:raises:
:exc:`ConnectionLoss` if there is no connection open, or
possibly a :exc:`socket.error` if there's a problem with
the connection used just for this command.
.. versionadded:: 0.5
"""
if not self._live.is_set():
raise ConnectionLoss("No connection to server")
peer = self._connection._socket.getpeername()[:2]
sock = self.handler.create_connection(
peer, timeout=self._session_timeout / 1000.0)
sock.sendall(cmd)
result = sock.recv(8192)
sock.close()
return result.decode('utf-8', 'replace')
def server_version(self):
"""Get the version of the currently connected ZK server.
:returns: The server version, for example (3, 4, 3).
:rtype: tuple
.. versionadded:: 0.5
"""
data = self.command(b'envi')
string = ENVI_VERSION.match(data).group(1)
return tuple([int(i) for i in string.split('.')])
def add_auth(self, scheme, credential):
"""Send credentials to server.
:param scheme: authentication scheme (default supported:
"digest").
:param credential: the credential -- value depends on scheme.
:returns: True if it was successful.
:rtype: bool
:raises:
:exc:`~kazoo.exceptions.AuthFailedError` if it failed though
the session state will be set to AUTH_FAILED as well.
"""
return self.add_auth_async(scheme, credential).get()
def add_auth_async(self, scheme, credential):
"""Asynchronously send credentials to server. Takes the same
arguments as :meth:`add_auth`.
:rtype: :class:`~kazoo.interfaces.IAsyncResult`
"""
if not isinstance(scheme, basestring):
raise TypeError("Invalid type for scheme")
if not isinstance(credential, basestring):
raise TypeError("Invalid type for credential")
# we need this auth data to re-authenticate on reconnect
self.auth_data.add((scheme, credential))
async_result = self.handler.async_result()
self._call(Auth(0, scheme, credential), async_result)
return async_result
def unchroot(self, path):
"""Strip the chroot if applicable from the path."""
if not self.chroot:
return path
if path.startswith(self.chroot):
return path[len(self.chroot):]
else:
return path
def sync_async(self, path):
"""Asynchronous sync.
:rtype: :class:`~kazoo.interfaces.IAsyncResult`
"""
async_result = self.handler.async_result()
self._call(Sync(_prefix_root(self.chroot, path)), async_result)
return async_result
def sync(self, path):
"""Sync, blocks until response is acknowledged.
Flushes channel between process and leader.
:param path: path of node.
:returns: The node path that was synced.
:raises:
:exc:`~kazoo.exceptions.ZookeeperError` if the server
returns a non-zero error code.
.. versionadded:: 0.5
"""
return self.sync_async(path).get()
def create(self, path, value=b"", acl=None, ephemeral=False,
sequence=False, makepath=False):
"""Create a node with the given value as its data. Optionally
set an ACL on the node.
The ephemeral and sequence arguments determine the type of the
node.
An ephemeral node will be automatically removed by ZooKeeper
when the session associated with the creation of the node
expires.
A sequential node will be given the specified path plus a
suffix `i` where i is the current sequential number of the
node. The sequence number is always fixed length of 10 digits,
0 padded. Once such a node is created, the sequential number
will be incremented by one.
If a node with the same actual path already exists in
ZooKeeper, a NodeExistsError will be raised. Note that since a
different actual path is used for each invocation of creating
sequential nodes with the same path argument, the call will
never raise NodeExistsError.
If the parent node does not exist in ZooKeeper, a NoNodeError
will be raised. Setting the optional `makepath` argument to
`True` will create all missing parent nodes instead.
An ephemeral node cannot have children. If the parent node of
the given path is ephemeral, a NoChildrenForEphemeralsError
will be raised.
This operation, if successful, will trigger all the watches
left on the node of the given path by :meth:`exists` and
:meth:`get` API calls, and the watches left on the parent node
by :meth:`get_children` API calls.
The maximum allowable size of the node value is 1 MB. Values
larger than this will cause a ZookeeperError to be raised.
:param path: Path of node.
:param value: Initial bytes value of node.
:param acl: :class:`~kazoo.security.ACL` list.
:param ephemeral: Boolean indicating whether node is ephemeral
(tied to this session).
:param sequence: Boolean indicating whether path is suffixed
with a unique index.
:param makepath: Whether the path should be created if it
doesn't exist.
:returns: Real path of the new node.
:rtype: str
:raises:
:exc:`~kazoo.exceptions.NodeExistsError` if the node
already exists.
:exc:`~kazoo.exceptions.NoNodeError` if parent nodes are
missing.
:exc:`~kazoo.exceptions.NoChildrenForEphemeralsError` if
the parent node is an ephemeral node.
:exc:`~kazoo.exceptions.ZookeeperError` if the provided
value is too large.
:exc:`~kazoo.exceptions.ZookeeperError` if the server
returns a non-zero error code.
"""
acl = acl or self.default_acl
return self.create_async(path, value, acl=acl, ephemeral=ephemeral,
sequence=sequence, makepath=makepath).get()
def create_async(self, path, value=b"", acl=None, ephemeral=False,
sequence=False, makepath=False):
"""Asynchronously create a ZNode. Takes the same arguments as
:meth:`create`.
:rtype: :class:`~kazoo.interfaces.IAsyncResult`
.. versionadded:: 1.1
The makepath option.
"""
if acl is None and self.default_acl:
acl = self.default_acl
if not isinstance(path, basestring):
raise TypeError("path must be a string")
if acl and (isinstance(acl, ACL) or
not isinstance(acl, (tuple, list))):
raise TypeError("acl must be a tuple/list of ACL's")
if value is not None and not isinstance(value, bytes):
raise TypeError("value must be a byte string")
if not isinstance(ephemeral, bool):
raise TypeError("ephemeral must be a bool")
if not isinstance(sequence, bool):
raise TypeError("sequence must be a bool")
if not isinstance(makepath, bool):
raise TypeError("makepath must be a bool")
flags = 0
if ephemeral:
flags |= 1
if sequence:
flags |= 2
if acl is None:
acl = OPEN_ACL_UNSAFE
async_result = self.handler.async_result()
@capture_exceptions(async_result)
def do_create():
result = self._create_async_inner(
path, value, acl, flags, trailing=sequence)
result.rawlink(create_completion)
@capture_exceptions(async_result)
def retry_completion(result):
result.get()
do_create()
@wrap(async_result)
def create_completion(result):
try:
return self.unchroot(result.get())
except NoNodeError:
if not makepath:
raise
if sequence and path.endswith('/'):
parent = path.rstrip('/')
else:
parent, _ = split(path)
self.ensure_path_async(parent, acl).rawlink(retry_completion)
do_create()
return async_result
def _create_async_inner(self, path, value, acl, flags, trailing=False):
async_result = self.handler.async_result()
call_result = self._call(
Create(_prefix_root(self.chroot, path, trailing=trailing),
value, acl, flags), async_result)
if call_result is False:
# We hit a short-circuit exit on the _call. Because we are
# not using the original async_result here, we bubble the
# exception upwards to the do_create function in
# KazooClient.create so that it gets set on the correct
# async_result object
raise async_result.exception
return async_result
def ensure_path(self, path, acl=None):
"""Recursively create a path if it doesn't exist.
:param path: Path of node.
:param acl: Permissions for node.
"""
return self.ensure_path_async(path, acl).get()
def ensure_path_async(self, path, acl=None):
"""Recursively create a path asynchronously if it doesn't
exist. Takes the same arguments as :meth:`ensure_path`.
:rtype: :class:`~kazoo.interfaces.IAsyncResult`
.. versionadded:: 1.1
"""
acl = acl or self.default_acl
async_result = self.handler.async_result()
@wrap(async_result)
def create_completion(result):
try:
return result.get()
except NodeExistsError:
return True
@capture_exceptions(async_result)
def prepare_completion(next_path, result):
result.get()
self.create_async(next_path, acl=acl).rawlink(create_completion)
@wrap(async_result)
def exists_completion(path, result):
if result.get():
return True
parent, node = split(path)
if node:
self.ensure_path_async(parent, acl=acl).rawlink(
partial(prepare_completion, path))
else:
self.create_async(path, acl=acl).rawlink(create_completion)
self.exists_async(path).rawlink(partial(exists_completion, path))
return async_result
def exists(self, path, watch=None):
"""Check if a node exists.
If a watch is provided, it will be left on the node with the
given path. The watch will be triggered by a successful
operation that creates/deletes the node or sets the data on the
node.
:param path: Path of node.
:param watch: Optional watch callback to set for future changes
to this path.
:returns: ZnodeStat of the node if it exists, else None if the
node does not exist.
:rtype: :class:`~kazoo.protocol.states.ZnodeStat` or `None`.
:raises:
:exc:`~kazoo.exceptions.ZookeeperError` if the server
returns a non-zero error code.
"""
return self.exists_async(path, watch).get()
def exists_async(self, path, watch=None):
"""Asynchronously check if a node exists. Takes the same
arguments as :meth:`exists`.
:rtype: :class:`~kazoo.interfaces.IAsyncResult`
"""
if not isinstance(path, basestring):
raise TypeError("path must be a string")
if watch and not callable(watch):
raise TypeError("watch must be a callable")
async_result = self.handler.async_result()
self._call(Exists(_prefix_root(self.chroot, path), watch),
async_result)
return async_result
def get(self, path, watch=None):
"""Get the value of a node.
If a watch is provided, it will be left on the node with the
given path. The watch will be triggered by a successful
operation that sets data on the node, or deletes the node.
:param path: Path of node.
:param watch: Optional watch callback to set for future changes
to this path.
:returns:
Tuple (value, :class:`~kazoo.protocol.states.ZnodeStat`) of
node.
:rtype: tuple
:raises:
:exc:`~kazoo.exceptions.NoNodeError` if the node doesn't
exist
:exc:`~kazoo.exceptions.ZookeeperError` if the server
returns a non-zero error code
"""
return self.get_async(path, watch).get()
def get_async(self, path, watch=None):
"""Asynchronously get the value of a node. Takes the same
arguments as :meth:`get`.
:rtype: :class:`~kazoo.interfaces.IAsyncResult`
"""
if not isinstance(path, basestring):
raise TypeError("path must be a string")
if watch and not callable(watch):
raise TypeError("watch must be a callable")
async_result = self.handler.async_result()
self._call(GetData(_prefix_root(self.chroot, path), watch),
async_result)
return async_result
def get_children(self, path, watch=None, include_data=False):
"""Get a list of child nodes of a path.
If a watch is provided it will be left on the node with the
given path. The watch will be triggered by a successful
operation that deletes the node of the given path or
creates/deletes a child under the node.
The list of children returned is not sorted and no guarantee is
provided as to its natural or lexical order.
:param path: Path of node to list.
:param watch: Optional watch callback to set for future changes
to this path.
:param include_data:
Include the :class:`~kazoo.protocol.states.ZnodeStat` of
the node in addition to the children. This option changes
the return value to be a tuple of (children, stat).
:returns: List of child node names, or tuple if `include_data`
is `True`.
:rtype: list
:raises:
:exc:`~kazoo.exceptions.NoNodeError` if the node doesn't
exist.
:exc:`~kazoo.exceptions.ZookeeperError` if the server
returns a non-zero error code.
.. versionadded:: 0.5
The `include_data` option.
"""
return self.get_children_async(path, watch, include_data).get()
def get_children_async(self, path, watch=None, include_data=False):
"""Asynchronously get a list of child nodes of a path. Takes
the same arguments as :meth:`get_children`.
:rtype: :class:`~kazoo.interfaces.IAsyncResult`
"""
if not isinstance(path, basestring):
raise TypeError("path must be a string")
if watch and not callable(watch):
raise TypeError("watch must be a callable")
if not isinstance(include_data, bool):
raise TypeError("include_data must be a bool")
async_result = self.handler.async_result()
if include_data:
req = GetChildren2(_prefix_root(self.chroot, path), watch)
else:
req = GetChildren(_prefix_root(self.chroot, path), watch)
self._call(req, async_result)
return async_result
def get_acls(self, path):
"""Return the ACL and stat of the node of the given path.
:param path: Path of the node.
:returns: The ACL array of the given node and its
:class:`~kazoo.protocol.states.ZnodeStat`.
:rtype: tuple of (:class:`~kazoo.security.ACL` list,
:class:`~kazoo.protocol.states.ZnodeStat`)
:raises:
:exc:`~kazoo.exceptions.NoNodeError` if the node doesn't
exist.
:exc:`~kazoo.exceptions.ZookeeperError` if the server
returns a non-zero error code
.. versionadded:: 0.5
"""
return self.get_acls_async(path).get()
def get_acls_async(self, path):
"""Return the ACL and stat of the node of the given path. Takes
the same arguments as :meth:`get_acls`.
:rtype: :class:`~kazoo.interfaces.IAsyncResult`
"""
if not isinstance(path, basestring):
raise TypeError("path must be a string")
async_result = self.handler.async_result()
self._call(GetACL(_prefix_root(self.chroot, path)), async_result)
return async_result
def set_acls(self, path, acls, version=-1):
"""Set the ACL for the node of the given path.
Set the ACL for the node of the given path if such a node
exists and the given version matches the version of the node.
:param path: Path for the node.
:param acls: List of :class:`~kazoo.security.ACL` objects to
set.
:param version: The expected node version that must match.
:returns: The stat of the node.
:raises:
:exc:`~kazoo.exceptions.BadVersionError` if version doesn't
match.
:exc:`~kazoo.exceptions.NoNodeError` if the node doesn't
exist.
:exc:`~kazoo.exceptions.InvalidACLError` if the ACL is
invalid.
:exc:`~kazoo.exceptions.ZookeeperError` if the server
returns a non-zero error code.
.. versionadded:: 0.5
"""
return self.set_acls_async(path, acls, version).get()
def set_acls_async(self, path, acls, version=-1):
"""Set the ACL for the node of the given path. Takes the same
arguments as :meth:`set_acls`.
:rtype: :class:`~kazoo.interfaces.IAsyncResult`
"""
if not isinstance(path, basestring):
raise TypeError("path must be a string")
if isinstance(acls, ACL) or not isinstance(acls, (tuple, list)):
raise TypeError("acl must be a tuple/list of ACL's")
if not isinstance(version, int):
raise TypeError("version must be an int")
async_result = self.handler.async_result()
self._call(SetACL(_prefix_root(self.chroot, path), acls, version),
async_result)
return async_result
def set(self, path, value, version=-1):
"""Set the value of a node.
If the version of the node being updated is newer than the
supplied version (and the supplied version is not -1), a
BadVersionError will be raised.
This operation, if successful, will trigger all the watches on
the node of the given path left by :meth:`get` API calls.
The maximum allowable size of the value is 1 MB. Values larger
than this will cause a ZookeeperError to be raised.
:param path: Path of node.
:param value: New data value.
:param version: Version of node being updated, or -1.
:returns: Updated :class:`~kazoo.protocol.states.ZnodeStat` of
the node.
:raises:
:exc:`~kazoo.exceptions.BadVersionError` if version doesn't
match.
:exc:`~kazoo.exceptions.NoNodeError` if the node doesn't
exist.
:exc:`~kazoo.exceptions.ZookeeperError` if the provided
value is too large.
:exc:`~kazoo.exceptions.ZookeeperError` if the server
returns a non-zero error code.
"""
return self.set_async(path, value, version).get()
def set_async(self, path, value, version=-1):
"""Set the value of a node. Takes the same arguments as
:meth:`set`.
:rtype: :class:`~kazoo.interfaces.IAsyncResult`
"""
if not isinstance(path, basestring):
raise TypeError("path must be a string")
if value is not None and not isinstance(value, bytes):
raise TypeError("value must be a byte string")
if not isinstance(version, int):
raise TypeError("version must be an int")
async_result = self.handler.async_result()
self._call(SetData(_prefix_root(self.chroot, path), value, version),
async_result)
return async_result
def transaction(self):
"""Create and return a :class:`TransactionRequest` object
Creates a :class:`TransactionRequest` object. A Transaction can
consist of multiple operations which can be committed as a
single atomic unit. Either all of the operations will succeed
or none of them.
:returns: A TransactionRequest.
:rtype: :class:`TransactionRequest`
.. versionadded:: 0.6
Requires Zookeeper 3.4+
"""
return TransactionRequest(self)
def delete(self, path, version=-1, recursive=False):
"""Delete a node.
The call will succeed if such a node exists, and the given
version matches the node's version (if the given version is -1,
the default, it matches any node's versions).
This operation, if successful, will trigger all the watches on
the node of the given path left by `exists` API calls, and the
watches on the parent node left by `get_children` API calls.
:param path: Path of node to delete.
:param version: Version of node to delete, or -1 for any.
:param recursive: Recursively delete node and all its children,
defaults to False.
:type recursive: bool
:raises:
:exc:`~kazoo.exceptions.BadVersionError` if version doesn't
match.
:exc:`~kazoo.exceptions.NoNodeError` if the node doesn't
exist.
:exc:`~kazoo.exceptions.NotEmptyError` if the node has
children.
:exc:`~kazoo.exceptions.ZookeeperError` if the server
returns a non-zero error code.
"""
if not isinstance(recursive, bool):
raise TypeError("recursive must be a bool")
if recursive:
return self._delete_recursive(path)
else:
return self.delete_async(path, version).get()
def delete_async(self, path, version=-1):
"""Asynchronously delete a node. Takes the same arguments as
:meth:`delete`, with the exception of `recursive`.
:rtype: :class:`~kazoo.interfaces.IAsyncResult`
"""
if not isinstance(path, basestring):
raise TypeError("path must be a string")
if not isinstance(version, int):
raise TypeError("version must be an int")
async_result = self.handler.async_result()
self._call(Delete(_prefix_root(self.chroot, path), version),
async_result)
return async_result
def _delete_recursive(self, path):
try:
children = self.get_children(path)
except NoNodeError:
return True
if children:
for child in children:
if path == "/":
child_path = path + child
else:
child_path = path + "/" + child
self._delete_recursive(child_path)
try:
self.delete(path)
except NoNodeError: # pragma: nocover
pass
class TransactionRequest(object):
"""A Zookeeper Transaction Request
A Transaction provides a builder object that can be used to
construct and commit an atomic set of operations. The transaction
must be committed before its sent.
Transactions are not thread-safe and should not be accessed from
multiple threads at once.
.. note::
The ``committed`` attribute only indicates whether this
transaction has been sent to Zookeeper and is used to prevent
duplicate commits of the same transaction. The result should be
checked to determine if the transaction executed as desired.
.. versionadded:: 0.6
Requires Zookeeper 3.4+
"""
def __init__(self, client):
self.client = client
self.operations = []
self.committed = False
def create(self, path, value=b"", acl=None, ephemeral=False,
sequence=False):
"""Add a create ZNode to the transaction. Takes the same
arguments as :meth:`KazooClient.create`, with the exception
of `makepath`.
:returns: None
"""
if acl is None and self.client.default_acl:
acl = self.client.default_acl
if not isinstance(path, basestring):
raise TypeError("path must be a string")
if acl and not isinstance(acl, (tuple, list)):
raise TypeError("acl must be a tuple/list of ACL's")
if not isinstance(value, bytes):
raise TypeError("value must be a byte string")
if not isinstance(ephemeral, bool):
raise TypeError("ephemeral must be a bool")
if not isinstance(sequence, bool):
raise TypeError("sequence must be a bool")
flags = 0
if ephemeral:
flags |= 1
if sequence:
flags |= 2
if acl is None:
acl = OPEN_ACL_UNSAFE
self._add(Create(_prefix_root(self.client.chroot, path), value, acl,
flags), None)
def delete(self, path, version=-1):
"""Add a delete ZNode to the transaction. Takes the same
arguments as :meth:`KazooClient.delete`, with the exception of
`recursive`.
"""
if not isinstance(path, basestring):
raise TypeError("path must be a string")
if not isinstance(version, int):
raise TypeError("version must be an int")
self._add(Delete(_prefix_root(self.client.chroot, path), version))
def set_data(self, path, value, version=-1):
"""Add a set ZNode value to the transaction. Takes the same
arguments as :meth:`KazooClient.set`.
"""
if not isinstance(path, basestring):
raise TypeError("path must be a string")
if not isinstance(value, bytes):
raise TypeError("value must be a byte string")
if not isinstance(version, int):
raise TypeError("version must be an int")
self._add(SetData(_prefix_root(self.client.chroot, path), value,
version))
def check(self, path, version):
"""Add a Check Version to the transaction.
This command will fail and abort a transaction if the path
does not match the specified version.
"""
if not isinstance(path, basestring):
raise TypeError("path must be a string")
if not isinstance(version, int):
raise TypeError("version must be an int")
self._add(CheckVersion(_prefix_root(self.client.chroot, path),
version))
def commit_async(self):
"""Commit the transaction asynchronously.
:rtype: :class:`~kazoo.interfaces.IAsyncResult`
"""
self._check_tx_state()
self.committed = True
async_object = self.client.handler.async_result()
self.client._call(Transaction(self.operations), async_object)
return async_object
def commit(self):
"""Commit the transaction.
:returns: A list of the results for each operation in the
transaction.
"""
return self.commit_async().get()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, exc_tb):
"""Commit and cleanup accumulated transaction data."""
if not exc_type:
self.commit()
def _check_tx_state(self):
if self.committed:
raise ValueError('Transaction already committed')
def _add(self, request, post_processor=None):
self._check_tx_state()
self.client.logger.log(BLATHER, 'Added %r to %r', request, self)
self.operations.append(request)
|
apache-2.0
|
[
624,
43,
4651,
1534,
3107,
23479,
6810,
624,
199,
646,
6485,
199,
646,
2050,
199,
646,
747,
199,
646,
295,
199,
646,
3598,
199,
504,
5055,
492,
10018,
12,
15782,
199,
504,
9143,
492,
7417,
199,
504,
747,
14,
515,
492,
3715,
199,
199,
504,
1022,
4651,
1534,
14,
3924,
492,
334,
272,
3590,
4276,
547,
12,
272,
11595,
547,
12,
272,
8113,
15190,
547,
12,
272,
8113,
8610,
12,
272,
3091,
1716,
547,
12,
272,
5013,
23839,
12,
272,
8596,
20898,
547,
12,
272,
24441,
1763,
15190,
1726,
12,
199,
9,
199,
504,
1022,
4651,
1534,
14,
5586,
14,
12562,
492,
3240,
9092,
4436,
316,
2461,
199,
504,
1022,
4651,
1534,
14,
5586,
14,
1208,
492,
12296,
63,
3924,
12,
4816,
199,
504,
1022,
4651,
1534,
14,
5146,
492,
8775,
63,
5146,
199,
504,
1022,
4651,
1534,
14,
793,
71,
780,
384,
719,
492,
15979,
619,
3452,
199,
504,
1022,
4651,
1534,
14,
3922,
14,
2105,
492,
8113,
2461,
199,
504,
1022,
4651,
1534,
14,
3922,
14,
3771,
492,
25962,
199,
504,
1022,
4651,
1534,
14,
3922,
14,
3771,
492,
485,
1861,
63,
1231,
199,
504,
1022,
4651,
1534,
14,
3922,
14,
12161,
492,
334,
272,
3590,
12,
272,
2670,
3353,
12,
272,
15524,
3244,
12,
272,
2790,
12,
272,
8496,
12,
272,
1316,
1670,
12,
272,
2372,
7139,
12,
272,
2372,
7139,
18,
12,
272,
2372,
18765,
12,
272,
2494,
18765,
12,
272,
2372,
1451,
12,
272,
2494,
1451,
12,
272,
22407,
12,
272,
18244,
199,
9,
199,
504,
1022,
4651,
1534,
14,
3922,
14,
4981,
492,
1804,
4651,
1534,
2223,
199,
504,
1022,
4651,
1534,
14,
3922,
14,
4981,
492,
1804,
1024,
529,
2223,
199,
504,
1022,
4651,
1534,
14,
7154,
492,
1804,
4651,
1534,
12989,
199,
504,
1022,
4651,
1534,
14,
4416,
492,
16543,
199,
504,
1022,
4651,
1534,
14,
4416,
492,
24164,
63,
18765,
63,
1734,
27657,
199,
199,
3,
16777,
3261,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
1700,
10742,
492,
12377,
10742,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
1700,
10742,
492,
22945,
5281,
10742,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
5337,
492,
14427,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
28507,
492,
662,
1486,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
831,
492,
15536,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
831,
492,
3240,
17185,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
5312,
281,
492,
2494,
13068,
281,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
7522,
492,
2235,
369,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
7522,
492,
5244,
3306,
25233,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
1825,
492,
10703,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
1825,
492,
15536,
316,
3737,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
6821,
1192,
492,
12988,
828,
13978,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
6821,
1192,
492,
3918,
13978,
199,
199,
893,
26,
221,
327,
11942,
26,
949,
5899,
272,
7116,
199,
2590,
12746,
26,
221,
327,
11942,
26,
949,
5899,
272,
7116,
275,
620,
199,
199,
1484,
840,
63,
23162,
275,
334,
43,
1024,
529,
2223,
14,
25632,
7387,
63,
12763,
12,
1804,
1024,
529,
2223,
14,
5580,
63,
12299,
12,
2049,
1804,
1024,
529,
2223,
14,
26270,
9,
199,
9984,
41,
63,
4612,
275,
295,
14,
2014,
360,
7023,
87,
60,
83,
14010,
3672,
29,
16510,
68,
4537,
3672,
680,
7693,
295,
14,
16504,
9,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
63,
27778,
63,
29720,
63,
30773,
275,
1211,
8,
272,
1390,
63,
10937,
29,
403,
12,
272,
7269,
63,
5814,
29,
16,
14,
17,
12,
272,
7269,
63,
21061,
29,
18,
12,
272,
7269,
63,
17676,
351,
29,
16,
14,
24,
12,
272,
7269,
63,
988,
63,
5814,
29,
11035,
12,
199,
9,
199,
199,
63,
27778,
63,
29720,
63,
20351,
275,
1211,
8,
272,
1390,
63,
10937,
534,
988,
63,
6264,
297,
272,
7269,
63,
5814,
534,
5814,
297,
272,
7269,
63,
21061,
534,
21061,
297,
272,
7269,
63,
17676,
351,
534,
988,
63,
17676,
351,
297,
272,
7269,
63,
988,
63,
5814,
534,
988,
63,
5814,
297,
199,
9,
421,
199,
533,
1804,
4651,
1534,
3041,
8,
785,
304,
272,
408,
2493,
3668,
3107,
23479,
2018,
1890,
21038,
18034,
3233,
272,
8297,
436,
4721,
13,
1896,
9330,
14,
339,
29075,
3423,
7264,
543,
642,
1021,
911,
440,
664,
2351,
272,
4474,
12,
29750,
314,
849,
3107,
23479,
9626,
397,
14,
9322,
911,
2597,
506,
272,
2797,
543,
282,
2849,
1423,
12,
282,
272,
520,
533,
6054,
75,
4651,
1534,
14,
3922,
14,
4981,
14,
13978,
379,
2390,
64,
1256,
14,
339,
408,
272,
347,
636,
826,
721,
277,
12,
7057,
534,
4195,
14,
16,
14,
16,
14,
17,
26,
9252,
17,
297,
326,
2653,
29,
709,
14,
16,
12,
1890,
63,
344,
29,
403,
12,
3016,
29,
403,
12,
326,
849,
63,
5853,
29,
403,
12,
1790,
63,
576,
29,
403,
12,
1586,
63,
2118,
29,
403,
12,
326,
2196,
794,
63,
5146,
29,
549,
12,
1950,
63,
7154,
29,
403,
12,
326,
1414,
63,
7154,
29,
403,
12,
2512,
29,
403,
12,
1011,
958,
304,
267,
408,
2499,
282,
520,
533,
1705,
43,
4651,
1534,
3041,
64,
1256,
14,
2900,
900,
2368,
267,
787,
315,
4696,
14,
398,
520,
635,
7057,
26,
5429,
391,
13,
12794,
769,
402,
7057,
370,
4907,
370,
1993,
334,
69,
14,
71,
14,
12792,
14,
16,
14,
16,
14,
17,
26,
9252,
17,
12,
4195,
14,
16,
14,
16,
14,
17,
26,
9252,
18,
12,
10345,
17,
2189,
9252,
19,
680,
267,
520,
635,
2653,
26,
710,
21303,
370,
3618,
367,
282,
3107,
23479,
1950,
14,
267,
520,
635,
1890,
63,
344,
26,
437,
3107,
23479,
1890,
1305,
12,
1202,
1380,
2079,
295,
13,
597,
13306,
316,
282,
6791,
2351,
1950,
14,
267,
520,
635,
3016,
26,
1626,
1256,
402,
282,
1021,
18234,
314,
717,
520,
533,
6054,
75,
4651,
1534,
14,
7436,
14,
41,
2461,
64,
3217,
717,
367,
3233,
7252,
14,
267,
520,
635,
849,
63,
5853,
26,
437,
849,
16543,
1202,
641,
1031,
7143,
14,
267,
520,
635,
1790,
63,
576,
26,
288,
437
] |
[
43,
4651,
1534,
3107,
23479,
6810,
624,
199,
646,
6485,
199,
646,
2050,
199,
646,
747,
199,
646,
295,
199,
646,
3598,
199,
504,
5055,
492,
10018,
12,
15782,
199,
504,
9143,
492,
7417,
199,
504,
747,
14,
515,
492,
3715,
199,
199,
504,
1022,
4651,
1534,
14,
3924,
492,
334,
272,
3590,
4276,
547,
12,
272,
11595,
547,
12,
272,
8113,
15190,
547,
12,
272,
8113,
8610,
12,
272,
3091,
1716,
547,
12,
272,
5013,
23839,
12,
272,
8596,
20898,
547,
12,
272,
24441,
1763,
15190,
1726,
12,
199,
9,
199,
504,
1022,
4651,
1534,
14,
5586,
14,
12562,
492,
3240,
9092,
4436,
316,
2461,
199,
504,
1022,
4651,
1534,
14,
5586,
14,
1208,
492,
12296,
63,
3924,
12,
4816,
199,
504,
1022,
4651,
1534,
14,
5146,
492,
8775,
63,
5146,
199,
504,
1022,
4651,
1534,
14,
793,
71,
780,
384,
719,
492,
15979,
619,
3452,
199,
504,
1022,
4651,
1534,
14,
3922,
14,
2105,
492,
8113,
2461,
199,
504,
1022,
4651,
1534,
14,
3922,
14,
3771,
492,
25962,
199,
504,
1022,
4651,
1534,
14,
3922,
14,
3771,
492,
485,
1861,
63,
1231,
199,
504,
1022,
4651,
1534,
14,
3922,
14,
12161,
492,
334,
272,
3590,
12,
272,
2670,
3353,
12,
272,
15524,
3244,
12,
272,
2790,
12,
272,
8496,
12,
272,
1316,
1670,
12,
272,
2372,
7139,
12,
272,
2372,
7139,
18,
12,
272,
2372,
18765,
12,
272,
2494,
18765,
12,
272,
2372,
1451,
12,
272,
2494,
1451,
12,
272,
22407,
12,
272,
18244,
199,
9,
199,
504,
1022,
4651,
1534,
14,
3922,
14,
4981,
492,
1804,
4651,
1534,
2223,
199,
504,
1022,
4651,
1534,
14,
3922,
14,
4981,
492,
1804,
1024,
529,
2223,
199,
504,
1022,
4651,
1534,
14,
7154,
492,
1804,
4651,
1534,
12989,
199,
504,
1022,
4651,
1534,
14,
4416,
492,
16543,
199,
504,
1022,
4651,
1534,
14,
4416,
492,
24164,
63,
18765,
63,
1734,
27657,
199,
199,
3,
16777,
3261,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
1700,
10742,
492,
12377,
10742,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
1700,
10742,
492,
22945,
5281,
10742,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
5337,
492,
14427,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
28507,
492,
662,
1486,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
831,
492,
15536,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
831,
492,
3240,
17185,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
5312,
281,
492,
2494,
13068,
281,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
7522,
492,
2235,
369,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
7522,
492,
5244,
3306,
25233,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
1825,
492,
10703,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
1825,
492,
15536,
316,
3737,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
6821,
1192,
492,
12988,
828,
13978,
199,
504,
1022,
4651,
1534,
14,
13191,
14,
6821,
1192,
492,
3918,
13978,
199,
199,
893,
26,
221,
327,
11942,
26,
949,
5899,
272,
7116,
199,
2590,
12746,
26,
221,
327,
11942,
26,
949,
5899,
272,
7116,
275,
620,
199,
199,
1484,
840,
63,
23162,
275,
334,
43,
1024,
529,
2223,
14,
25632,
7387,
63,
12763,
12,
1804,
1024,
529,
2223,
14,
5580,
63,
12299,
12,
2049,
1804,
1024,
529,
2223,
14,
26270,
9,
199,
9984,
41,
63,
4612,
275,
295,
14,
2014,
360,
7023,
87,
60,
83,
14010,
3672,
29,
16510,
68,
4537,
3672,
680,
7693,
295,
14,
16504,
9,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
63,
27778,
63,
29720,
63,
30773,
275,
1211,
8,
272,
1390,
63,
10937,
29,
403,
12,
272,
7269,
63,
5814,
29,
16,
14,
17,
12,
272,
7269,
63,
21061,
29,
18,
12,
272,
7269,
63,
17676,
351,
29,
16,
14,
24,
12,
272,
7269,
63,
988,
63,
5814,
29,
11035,
12,
199,
9,
199,
199,
63,
27778,
63,
29720,
63,
20351,
275,
1211,
8,
272,
1390,
63,
10937,
534,
988,
63,
6264,
297,
272,
7269,
63,
5814,
534,
5814,
297,
272,
7269,
63,
21061,
534,
21061,
297,
272,
7269,
63,
17676,
351,
534,
988,
63,
17676,
351,
297,
272,
7269,
63,
988,
63,
5814,
534,
988,
63,
5814,
297,
199,
9,
421,
199,
533,
1804,
4651,
1534,
3041,
8,
785,
304,
272,
408,
2493,
3668,
3107,
23479,
2018,
1890,
21038,
18034,
3233,
272,
8297,
436,
4721,
13,
1896,
9330,
14,
339,
29075,
3423,
7264,
543,
642,
1021,
911,
440,
664,
2351,
272,
4474,
12,
29750,
314,
849,
3107,
23479,
9626,
397,
14,
9322,
911,
2597,
506,
272,
2797,
543,
282,
2849,
1423,
12,
282,
272,
520,
533,
6054,
75,
4651,
1534,
14,
3922,
14,
4981,
14,
13978,
379,
2390,
64,
1256,
14,
339,
408,
272,
347,
636,
826,
721,
277,
12,
7057,
534,
4195,
14,
16,
14,
16,
14,
17,
26,
9252,
17,
297,
326,
2653,
29,
709,
14,
16,
12,
1890,
63,
344,
29,
403,
12,
3016,
29,
403,
12,
326,
849,
63,
5853,
29,
403,
12,
1790,
63,
576,
29,
403,
12,
1586,
63,
2118,
29,
403,
12,
326,
2196,
794,
63,
5146,
29,
549,
12,
1950,
63,
7154,
29,
403,
12,
326,
1414,
63,
7154,
29,
403,
12,
2512,
29,
403,
12,
1011,
958,
304,
267,
408,
2499,
282,
520,
533,
1705,
43,
4651,
1534,
3041,
64,
1256,
14,
2900,
900,
2368,
267,
787,
315,
4696,
14,
398,
520,
635,
7057,
26,
5429,
391,
13,
12794,
769,
402,
7057,
370,
4907,
370,
1993,
334,
69,
14,
71,
14,
12792,
14,
16,
14,
16,
14,
17,
26,
9252,
17,
12,
4195,
14,
16,
14,
16,
14,
17,
26,
9252,
18,
12,
10345,
17,
2189,
9252,
19,
680,
267,
520,
635,
2653,
26,
710,
21303,
370,
3618,
367,
282,
3107,
23479,
1950,
14,
267,
520,
635,
1890,
63,
344,
26,
437,
3107,
23479,
1890,
1305,
12,
1202,
1380,
2079,
295,
13,
597,
13306,
316,
282,
6791,
2351,
1950,
14,
267,
520,
635,
3016,
26,
1626,
1256,
402,
282,
1021,
18234,
314,
717,
520,
533,
6054,
75,
4651,
1534,
14,
7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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
] |
maciek263/django2
|
myvenv/Lib/site-packages/pip/_vendor/progress/spinner.py
|
404
|
1341
|
# -*- coding: utf-8 -*-
# Copyright (c) 2012 Giorgos Verigakis <verigak@gmail.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import unicode_literals
from . import Infinite
from .helpers import WriteMixin
class Spinner(WriteMixin, Infinite):
message = ''
phases = ('-', '\\', '|', '/')
hide_cursor = True
def update(self):
i = self.index % len(self.phases)
self.write(self.phases[i])
class PieSpinner(Spinner):
phases = ['◷', '◶', '◵', '◴']
class MoonSpinner(Spinner):
phases = ['◑', '◒', '◐', '◓']
class LineSpinner(Spinner):
phases = ['⎺', '⎻', '⎼', '⎽', '⎼', '⎻']
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
6029,
598,
73,
1308,
736,
5444,
528,
1151,
374,
665,
422,
528,
1151,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
367,
1263,
199,
3,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
2741,
626,
314,
3432,
199,
3,
4248,
4245,
436,
642,
4983,
4245,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
2334,
17632,
8990,
51,
11727,
2990,
199,
3,
1663,
14142,
7816,
2296,
5749,
4141,
6931,
11727,
5292,
2990,
1634,
199,
3,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
2334,
17632,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
8703,
12,
9168,
12,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
1634,
199,
3,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
492,
1010,
8005,
199,
504,
1275,
7546,
492,
6990,
4256,
421,
199,
533,
8360,
5216,
8,
3534,
4256,
12,
1010,
8005,
304,
272,
1245,
275,
2125,
272,
22587,
275,
12291,
297,
6468,
297,
11280,
297,
15107,
272,
13714,
63,
3937,
275,
715,
339,
347,
1678,
8,
277,
304,
267,
284,
275,
291,
14,
1080,
450,
822,
8,
277,
14,
14236,
9,
267,
291,
14,
952,
8,
277,
14,
14236,
59,
73,
566,
421,
199,
533,
510,
1873,
5058,
5216,
8,
5058,
5216,
304,
272,
22587,
275,
788,
159,
246,
116,
297,
283,
159,
246,
115,
297,
283,
159,
246,
114,
297,
283,
159,
246,
113,
418,
421,
199,
533,
3930,
265,
5058,
5216,
8,
5058,
5216,
304,
272,
22587,
275,
788,
159,
246,
240,
297,
283,
159,
246,
241,
297,
283,
159,
246,
239,
297,
283,
159,
246,
242,
418,
421,
199,
533,
7030,
5058,
5216,
8,
5058,
5216,
304,
272,
22587,
275,
788,
159,
237,
119,
297,
283,
159,
237,
120,
297,
283,
159,
237,
121,
297,
283,
159,
237,
122,
297,
283,
159,
237,
121,
297,
283,
159,
237,
120,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
6029,
598,
73,
1308,
736,
5444,
528,
1151,
374,
665,
422,
528,
1151,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
367,
1263,
199,
3,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
2741,
626,
314,
3432,
199,
3,
4248,
4245,
436,
642,
4983,
4245,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
2334,
17632,
8990,
51,
11727,
2990,
199,
3,
1663,
14142,
7816,
2296,
5749,
4141,
6931,
11727,
5292,
2990,
1634,
199,
3,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
2334,
17632,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
8703,
12,
9168,
12,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
1634,
199,
3,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
492,
1010,
8005,
199,
504,
1275,
7546,
492,
6990,
4256,
421,
199,
533,
8360,
5216,
8,
3534,
4256,
12,
1010,
8005,
304,
272,
1245,
275,
2125,
272,
22587,
275,
12291,
297,
6468,
297,
11280,
297,
15107,
272,
13714,
63,
3937,
275,
715,
339,
347,
1678,
8,
277,
304,
267,
284,
275,
291,
14,
1080,
450,
822,
8,
277,
14,
14236,
9,
267,
291,
14,
952,
8,
277,
14,
14236,
59,
73,
566,
421,
199,
533,
510,
1873,
5058,
5216,
8,
5058,
5216,
304,
272,
22587,
275,
788,
159,
246,
116,
297,
283,
159,
246,
115,
297,
283,
159,
246,
114,
297,
283,
159,
246,
113,
418,
421,
199,
533,
3930,
265,
5058,
5216,
8,
5058,
5216,
304,
272,
22587,
275,
788,
159,
246,
240,
297,
283,
159,
246,
241,
297,
283,
159,
246,
239,
297,
283,
159,
246,
242,
418,
421,
199,
533,
7030,
5058,
5216,
8,
5058,
5216,
304,
272,
22587,
275,
788,
159,
237,
119,
297,
283,
159,
237,
120,
297,
283,
159,
237,
121,
297,
283,
159,
237,
122,
297,
283,
159,
237,
121,
297,
283,
159,
237,
120,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
AllanYangZhou/oppia
|
core/domain/user_jobs_continuous_test.py
|
1
|
41847
|
# coding: utf-8
#
# Copyright 2014 The Oppia 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 user dashboard computations."""
import collections
from core import jobs_registry
from core.domain import collection_services
from core.domain import event_services
from core.domain import exp_domain
from core.domain import exp_jobs_one_off
from core.domain import exp_services
from core.domain import feedback_services
from core.domain import rating_services
from core.domain import rights_manager
from core.domain import stats_domain
from core.domain import stats_services
from core.domain import user_jobs_continuous
from core.domain import user_services
from core.platform import models
from core.tests import test_utils
import feconf
import utils
(exp_models, stats_models, user_models,) = models.Registry.import_models([
models.NAMES.exploration, models.NAMES.statistics, models.NAMES.user])
taskqueue_services = models.Registry.import_taskqueue_services()
COLLECTION_ID = 'cid'
COLLECTION_TITLE = 'Title'
EXP_ID = 'eid'
EXP_TITLE = 'Title'
EXP_1_ID = 'eid1'
EXP_1_TITLE = 'Title1'
EXP_2_ID = 'eid2'
EXP_2_TITLE = 'Title2'
FEEDBACK_THREAD_SUBJECT = 'feedback thread subject'
USER_ID = 'user_id'
ANOTHER_USER_ID = 'another_user_id'
USER_A_EMAIL = 'user_a@example.com'
USER_A_USERNAME = 'a'
USER_B_EMAIL = 'user_b@example.com'
USER_B_USERNAME = 'b'
class ModifiedRecentUpdatesAggregator(
user_jobs_continuous.DashboardRecentUpdatesAggregator):
"""A modified DashboardRecentUpdatesAggregator that does not start a new
batch job when the previous one has finished.
"""
@classmethod
def _get_batch_job_manager_class(cls):
return ModifiedRecentUpdatesMRJobManager
@classmethod
def _kickoff_batch_job_after_previous_one_ends(cls):
pass
class ModifiedRecentUpdatesMRJobManager(
user_jobs_continuous.RecentUpdatesMRJobManager):
@classmethod
def _get_continuous_computation_class(cls):
return ModifiedRecentUpdatesAggregator
class RecentUpdatesAggregatorUnitTests(test_utils.GenericTestBase):
"""Tests for computations involving the 'recent notifications' section of
the user dashboard.
"""
ALL_CC_MANAGERS_FOR_TESTS = [
ModifiedRecentUpdatesAggregator]
def _get_expected_activity_created_dict(
self, user_id, activity_id, activity_title, activity_type,
commit_type, last_updated_ms):
return {
'activity_id': activity_id,
'activity_title': activity_title,
'author_id': user_id,
'last_updated_ms': last_updated_ms,
'subject': (
'New %s created with title \'%s\'.' % (
activity_type, activity_title)),
'type': commit_type,
}
def _get_most_recent_exp_snapshot_created_on_ms(self, exp_id):
most_recent_snapshot = exp_services.get_exploration_snapshots_metadata(
exp_id)[-1]
return most_recent_snapshot['created_on_ms']
def _get_most_recent_collection_snapshot_created_on_ms(
self, collection_id):
most_recent_snapshot = (
collection_services.get_collection_snapshots_metadata(
collection_id)[-1])
return most_recent_snapshot['created_on_ms']
def _get_test_context(self):
return self.swap(
jobs_registry, 'ALL_CONTINUOUS_COMPUTATION_MANAGERS',
self.ALL_CC_MANAGERS_FOR_TESTS)
def test_basic_computation_for_explorations(self):
with self._get_test_context():
self.save_new_valid_exploration(
EXP_ID, USER_ID, title=EXP_TITLE, category='Category')
expected_last_updated_ms = (
self._get_most_recent_exp_snapshot_created_on_ms(EXP_ID))
ModifiedRecentUpdatesAggregator.start_computation()
self.assertEqual(
self.count_jobs_in_taskqueue(
taskqueue_services.QUEUE_NAME_CONTINUOUS_JOBS), 1)
self.process_and_flush_pending_tasks()
recent_notifications = (
ModifiedRecentUpdatesAggregator.get_recent_notifications(
USER_ID)[1])
self.assertEqual(len(recent_notifications), 1)
self.assertEqual(
recent_notifications[0],
self._get_expected_activity_created_dict(
USER_ID, EXP_ID, EXP_TITLE, 'exploration',
feconf.UPDATE_TYPE_EXPLORATION_COMMIT,
expected_last_updated_ms))
def test_basic_computation_ignores_automated_exploration_commits(self):
with self._get_test_context():
self.save_new_exp_with_states_schema_v0(EXP_ID, USER_ID, EXP_TITLE)
# Confirm that the exploration is at version 1.
exploration = exp_services.get_exploration_by_id(EXP_ID)
self.assertEqual(exploration.version, 1)
v1_last_updated_ms = (
self._get_most_recent_exp_snapshot_created_on_ms(EXP_ID))
# Start migration job on all explorations, including this one.
job_id = (
exp_jobs_one_off.ExplorationMigrationJobManager.create_new())
exp_jobs_one_off.ExplorationMigrationJobManager.enqueue(job_id)
self.process_and_flush_pending_tasks()
# Confirm that the exploration is at version 2.
exploration = exp_services.get_exploration_by_id(EXP_ID)
self.assertEqual(exploration.version, 2)
v2_last_updated_ms = (
self._get_most_recent_exp_snapshot_created_on_ms(EXP_ID))
# Run the aggregator.
ModifiedRecentUpdatesAggregator.start_computation()
self.assertEqual(
self.count_jobs_in_taskqueue(
taskqueue_services.QUEUE_NAME_CONTINUOUS_JOBS), 1)
self.process_and_flush_pending_tasks()
ModifiedRecentUpdatesAggregator.stop_computation(USER_ID)
recent_notifications = (
ModifiedRecentUpdatesAggregator.get_recent_notifications(
USER_ID)[1])
self.assertEqual(len(recent_notifications), 1)
self.assertEqual(
recent_notifications[0],
self._get_expected_activity_created_dict(
USER_ID, EXP_ID, EXP_TITLE, 'exploration',
feconf.UPDATE_TYPE_EXPLORATION_COMMIT, v1_last_updated_ms))
self.assertLess(
recent_notifications[0]['last_updated_ms'], v2_last_updated_ms)
# Another user makes a commit; this one should now show up in the
# original user's dashboard.
exp_services.update_exploration(
ANOTHER_USER_ID, EXP_ID, [], 'Update exploration')
v3_last_updated_ms = (
self._get_most_recent_exp_snapshot_created_on_ms(EXP_ID))
ModifiedRecentUpdatesAggregator.start_computation()
self.assertEqual(
self.count_jobs_in_taskqueue(
taskqueue_services.QUEUE_NAME_CONTINUOUS_JOBS), 1)
self.process_and_flush_pending_tasks()
recent_notifications = (
ModifiedRecentUpdatesAggregator.get_recent_notifications(
USER_ID)[1])
self.assertEqual([{
'type': feconf.UPDATE_TYPE_EXPLORATION_COMMIT,
'last_updated_ms': v3_last_updated_ms,
'activity_id': EXP_ID,
'activity_title': EXP_TITLE,
'author_id': ANOTHER_USER_ID,
'subject': 'Update exploration',
}], recent_notifications)
def test_basic_computation_with_an_update_after_exploration_is_created(
self):
with self._get_test_context():
self.save_new_valid_exploration(
EXP_ID, USER_ID, title=EXP_TITLE, category='Category')
# Another user makes a commit; this, too, shows up in the
# original user's dashboard.
exp_services.update_exploration(
ANOTHER_USER_ID, EXP_ID, [], 'Update exploration')
expected_last_updated_ms = (
self._get_most_recent_exp_snapshot_created_on_ms(EXP_ID))
ModifiedRecentUpdatesAggregator.start_computation()
self.assertEqual(
self.count_jobs_in_taskqueue(
taskqueue_services.QUEUE_NAME_CONTINUOUS_JOBS), 1)
self.process_and_flush_pending_tasks()
recent_notifications = (
ModifiedRecentUpdatesAggregator.get_recent_notifications(
USER_ID)[1])
self.assertEqual([{
'type': feconf.UPDATE_TYPE_EXPLORATION_COMMIT,
'last_updated_ms': expected_last_updated_ms,
'activity_id': EXP_ID,
'activity_title': EXP_TITLE,
'author_id': ANOTHER_USER_ID,
'subject': 'Update exploration',
}], recent_notifications)
def test_basic_computation_works_if_exploration_is_deleted(self):
with self._get_test_context():
self.save_new_valid_exploration(
EXP_ID, USER_ID, title=EXP_TITLE, category='Category')
last_updated_ms_before_deletion = (
self._get_most_recent_exp_snapshot_created_on_ms(EXP_ID))
exp_services.delete_exploration(USER_ID, EXP_ID)
ModifiedRecentUpdatesAggregator.start_computation()
self.assertEqual(
self.count_jobs_in_taskqueue(
taskqueue_services.QUEUE_NAME_CONTINUOUS_JOBS), 1)
self.process_and_flush_pending_tasks()
recent_notifications = (
ModifiedRecentUpdatesAggregator.get_recent_notifications(
USER_ID)[1])
self.assertEqual(len(recent_notifications), 1)
self.assertEqual(sorted(recent_notifications[0].keys()), [
'activity_id', 'activity_title', 'author_id',
'last_updated_ms', 'subject', 'type'])
self.assertDictContainsSubset({
'type': feconf.UPDATE_TYPE_EXPLORATION_COMMIT,
'activity_id': EXP_ID,
'activity_title': EXP_TITLE,
'author_id': USER_ID,
'subject': feconf.COMMIT_MESSAGE_EXPLORATION_DELETED,
}, recent_notifications[0])
self.assertLess(
last_updated_ms_before_deletion,
recent_notifications[0]['last_updated_ms'])
def test_multiple_exploration_commits_and_feedback_messages(self):
with self._get_test_context():
self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME)
editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL)
# User creates an exploration.
self.save_new_valid_exploration(
EXP_1_ID, editor_id, title=EXP_1_TITLE,
category='Category')
exp1_last_updated_ms = (
self._get_most_recent_exp_snapshot_created_on_ms(EXP_1_ID))
# User gives feedback on it.
feedback_services.create_thread(
EXP_1_ID, None, editor_id, FEEDBACK_THREAD_SUBJECT,
'text')
thread_id = feedback_services.get_all_threads(EXP_1_ID, False)[0].id
message = feedback_services.get_messages(thread_id)[0]
# User creates another exploration.
self.save_new_valid_exploration(
EXP_2_ID, editor_id, title=EXP_2_TITLE,
category='Category')
exp2_last_updated_ms = (
self._get_most_recent_exp_snapshot_created_on_ms(EXP_2_ID))
ModifiedRecentUpdatesAggregator.start_computation()
self.assertEqual(
self.count_jobs_in_taskqueue(
taskqueue_services.QUEUE_NAME_CONTINUOUS_JOBS), 1)
self.process_and_flush_pending_tasks()
recent_notifications = (
ModifiedRecentUpdatesAggregator.get_recent_notifications(
editor_id)[1])
self.assertEqual([(
self._get_expected_activity_created_dict(
editor_id, EXP_2_ID, EXP_2_TITLE, 'exploration',
feconf.UPDATE_TYPE_EXPLORATION_COMMIT,
exp2_last_updated_ms)
), {
'activity_id': EXP_1_ID,
'activity_title': EXP_1_TITLE,
'author_id': editor_id,
'last_updated_ms': utils.get_time_in_millisecs(
message.created_on),
'subject': FEEDBACK_THREAD_SUBJECT,
'type': feconf.UPDATE_TYPE_FEEDBACK_MESSAGE,
}, (
self._get_expected_activity_created_dict(
editor_id, EXP_1_ID, EXP_1_TITLE, 'exploration',
feconf.UPDATE_TYPE_EXPLORATION_COMMIT,
exp1_last_updated_ms)
)], recent_notifications)
def test_making_feedback_thread_does_not_subscribe_to_exploration(self):
with self._get_test_context():
self.signup(USER_A_EMAIL, USER_A_USERNAME)
user_a_id = self.get_user_id_from_email(USER_A_EMAIL)
self.signup(USER_B_EMAIL, USER_B_USERNAME)
user_b_id = self.get_user_id_from_email(USER_B_EMAIL)
# User A creates an exploration.
self.save_new_valid_exploration(
EXP_ID, user_a_id, title=EXP_TITLE, category='Category')
exp_last_updated_ms = (
self._get_most_recent_exp_snapshot_created_on_ms(EXP_ID))
# User B starts a feedback thread.
feedback_services.create_thread(
EXP_ID, None, user_b_id, FEEDBACK_THREAD_SUBJECT, 'text')
thread_id = feedback_services.get_all_threads(EXP_ID, False)[0].id
message = feedback_services.get_messages(thread_id)[0]
ModifiedRecentUpdatesAggregator.start_computation()
self.assertEqual(
self.count_jobs_in_taskqueue(
taskqueue_services.QUEUE_NAME_CONTINUOUS_JOBS), 1)
self.process_and_flush_pending_tasks()
recent_notifications_for_user_a = (
ModifiedRecentUpdatesAggregator.get_recent_notifications(
user_a_id)[1])
recent_notifications_for_user_b = (
ModifiedRecentUpdatesAggregator.get_recent_notifications(
user_b_id)[1])
expected_thread_notification = {
'activity_id': EXP_ID,
'activity_title': EXP_TITLE,
'author_id': user_b_id,
'last_updated_ms': utils.get_time_in_millisecs(
message.created_on),
'subject': FEEDBACK_THREAD_SUBJECT,
'type': feconf.UPDATE_TYPE_FEEDBACK_MESSAGE,
}
expected_creation_notification = (
self._get_expected_activity_created_dict(
user_a_id, EXP_ID, EXP_TITLE, 'exploration',
feconf.UPDATE_TYPE_EXPLORATION_COMMIT,
exp_last_updated_ms))
# User A sees A's commit and B's feedback thread.
self.assertEqual(
recent_notifications_for_user_a, [
expected_thread_notification,
expected_creation_notification
])
# User B sees only her feedback thread, but no commits.
self.assertEqual(
recent_notifications_for_user_b, [
expected_thread_notification,
])
def test_subscribing_to_exploration_subscribes_to_its_feedback_threads(
self):
with self._get_test_context():
self.signup(USER_A_EMAIL, USER_A_USERNAME)
user_a_id = self.get_user_id_from_email(USER_A_EMAIL)
self.signup(USER_B_EMAIL, USER_B_USERNAME)
user_b_id = self.get_user_id_from_email(USER_B_EMAIL)
user_a = user_services.UserActionsInfo(user_a_id)
# User A creates an exploration.
self.save_new_valid_exploration(
EXP_ID, user_a_id, title=EXP_TITLE, category='Category')
exp_last_updated_ms = (
self._get_most_recent_exp_snapshot_created_on_ms(EXP_ID))
# User B starts a feedback thread.
feedback_services.create_thread(
EXP_ID, None, user_b_id, FEEDBACK_THREAD_SUBJECT, 'text')
thread_id = feedback_services.get_all_threads(EXP_ID, False)[0].id
message = feedback_services.get_messages(thread_id)[0]
# User A adds user B as an editor of the exploration.
rights_manager.assign_role_for_exploration(
user_a, EXP_ID, user_b_id, rights_manager.ROLE_EDITOR)
ModifiedRecentUpdatesAggregator.start_computation()
self.assertEqual(
self.count_jobs_in_taskqueue(
taskqueue_services.QUEUE_NAME_CONTINUOUS_JOBS), 1)
self.process_and_flush_pending_tasks()
recent_notifications_for_user_a = (
ModifiedRecentUpdatesAggregator.get_recent_notifications(
user_a_id)[1])
recent_notifications_for_user_b = (
ModifiedRecentUpdatesAggregator.get_recent_notifications(
user_b_id)[1])
expected_thread_notification = {
'activity_id': EXP_ID,
'activity_title': EXP_TITLE,
'author_id': user_b_id,
'last_updated_ms': utils.get_time_in_millisecs(
message.created_on),
'subject': FEEDBACK_THREAD_SUBJECT,
'type': feconf.UPDATE_TYPE_FEEDBACK_MESSAGE,
}
expected_creation_notification = (
self._get_expected_activity_created_dict(
user_a_id, EXP_ID, EXP_TITLE, 'exploration',
feconf.UPDATE_TYPE_EXPLORATION_COMMIT,
exp_last_updated_ms))
# User A sees A's commit and B's feedback thread.
self.assertEqual(
recent_notifications_for_user_a, [
expected_thread_notification,
expected_creation_notification
])
# User B sees A's commit and B's feedback thread.
self.assertEqual(
recent_notifications_for_user_b, [
expected_thread_notification,
expected_creation_notification,
])
def test_basic_computation_for_collections(self):
with self._get_test_context():
self.save_new_default_collection(
COLLECTION_ID, USER_ID, title=COLLECTION_TITLE)
expected_last_updated_ms = (
self._get_most_recent_collection_snapshot_created_on_ms(
COLLECTION_ID))
ModifiedRecentUpdatesAggregator.start_computation()
self.assertEqual(
self.count_jobs_in_taskqueue(
taskqueue_services.QUEUE_NAME_CONTINUOUS_JOBS), 1)
self.process_and_flush_pending_tasks()
recent_notifications = (
ModifiedRecentUpdatesAggregator.get_recent_notifications(
USER_ID)[1])
self.assertEqual(len(recent_notifications), 1)
self.assertEqual(
recent_notifications[0],
self._get_expected_activity_created_dict(
USER_ID, COLLECTION_ID, COLLECTION_TITLE, 'collection',
feconf.UPDATE_TYPE_COLLECTION_COMMIT,
expected_last_updated_ms))
def test_basic_computation_with_an_update_after_collection_is_created(self):
with self._get_test_context():
self.save_new_default_collection(
COLLECTION_ID, USER_ID, title=COLLECTION_TITLE)
# Another user makes a commit; this, too, shows up in the
# original user's dashboard.
collection_services.update_collection(
ANOTHER_USER_ID, COLLECTION_ID, [{
'cmd': 'edit_collection_property',
'property_name': 'title',
'new_value': 'A new title'
}], 'Update collection')
expected_last_updated_ms = (
self._get_most_recent_collection_snapshot_created_on_ms(
COLLECTION_ID))
ModifiedRecentUpdatesAggregator.start_computation()
self.assertEqual(
self.count_jobs_in_taskqueue(
taskqueue_services.QUEUE_NAME_CONTINUOUS_JOBS), 1)
self.process_and_flush_pending_tasks()
recent_notifications = (
ModifiedRecentUpdatesAggregator.get_recent_notifications(
USER_ID)[1])
self.assertEqual([{
'type': feconf.UPDATE_TYPE_COLLECTION_COMMIT,
'last_updated_ms': expected_last_updated_ms,
'activity_id': COLLECTION_ID,
'activity_title': 'A new title',
'author_id': ANOTHER_USER_ID,
'subject': 'Update collection',
}], recent_notifications)
def test_basic_computation_works_if_collection_is_deleted(self):
with self._get_test_context():
self.save_new_default_collection(
COLLECTION_ID, USER_ID, title=COLLECTION_TITLE)
last_updated_ms_before_deletion = (
self._get_most_recent_collection_snapshot_created_on_ms(
COLLECTION_ID))
collection_services.delete_collection(USER_ID, COLLECTION_ID)
ModifiedRecentUpdatesAggregator.start_computation()
self.assertEqual(
self.count_jobs_in_taskqueue(
taskqueue_services.QUEUE_NAME_CONTINUOUS_JOBS), 1)
self.process_and_flush_pending_tasks()
recent_notifications = (
ModifiedRecentUpdatesAggregator.get_recent_notifications(
USER_ID)[1])
self.assertEqual(len(recent_notifications), 1)
self.assertEqual(sorted(recent_notifications[0].keys()), [
'activity_id', 'activity_title', 'author_id',
'last_updated_ms', 'subject', 'type'])
self.assertDictContainsSubset({
'type': feconf.UPDATE_TYPE_COLLECTION_COMMIT,
'activity_id': COLLECTION_ID,
'activity_title': COLLECTION_TITLE,
'author_id': USER_ID,
'subject': feconf.COMMIT_MESSAGE_COLLECTION_DELETED,
}, recent_notifications[0])
self.assertLess(
last_updated_ms_before_deletion,
recent_notifications[0]['last_updated_ms'])
class ModifiedUserStatsAggregator(
user_jobs_continuous.UserStatsAggregator):
"""A modified UserStatsAggregator that does not start a new
batch job when the previous one has finished.
"""
@classmethod
def _get_batch_job_manager_class(cls):
return ModifiedUserStatsMRJobManager
@classmethod
def _kickoff_batch_job_after_previous_one_ends(cls):
pass
class ModifiedUserStatsMRJobManager(
user_jobs_continuous.UserStatsMRJobManager):
@classmethod
def _get_continuous_computation_class(cls):
return ModifiedUserStatsAggregator
class UserStatsAggregatorTest(test_utils.GenericTestBase):
""" Tests the calculation of a user's statistics -
impact score, average ratings, total plays
from the continuous computation of UserStatsAggregator.
"""
EXP_ID_1 = 'exp_id_1'
EXP_ID_2 = 'exp_id_2'
EXP_ID_3 = 'exp_id_3'
EXP_DEFAULT_VERSION = 1
USER_SESSION_ID = 'session1'
USER_A_EMAIL = 'a@example.com'
USER_B_EMAIL = 'b@example.com'
USER_A_USERNAME = 'a'
USER_B_USERNAME = 'b'
MIN_NUM_COMPLETIONS = 2
EXPONENT = 2.0 / 3
def setUp(self):
super(UserStatsAggregatorTest, self).setUp()
self.num_completions = collections.defaultdict(int)
self.num_starts = collections.defaultdict(int)
self.signup(self.USER_A_EMAIL, self.USER_A_USERNAME)
self.signup(self.USER_B_EMAIL, self.USER_B_USERNAME)
self.user_a_id = self.get_user_id_from_email(self.USER_A_EMAIL)
self.user_b_id = self.get_user_id_from_email(self.USER_B_EMAIL)
self.user_a = user_services.UserActionsInfo(self.user_a_id)
def _mock_get_statistics(self, exp_id, unused_version):
current_completions = {
self.EXP_ID_1: stats_domain.ExplorationStats(
self.EXP_ID_1, self.EXP_DEFAULT_VERSION, 5, 2, 0, 0, 0, 0, {
'state1': stats_domain.StateStats(
0, 0, 0, 0, 0, 0, 3, 1, 0, 0, 0),
'state2': stats_domain.StateStats(
0, 0, 0, 0, 0, 0, 7, 1, 0, 0, 0),
}
),
self.EXP_ID_2: stats_domain.ExplorationStats(
self.EXP_ID_2, self.EXP_DEFAULT_VERSION, 5, 2, 0, 0, 0, 0, {
'state1': stats_domain.StateStats(
0, 0, 0, 0, 0, 0, 3, 1, 0, 0, 0),
'state2': stats_domain.StateStats(
0, 0, 0, 0, 0, 0, 7, 1, 0, 0, 0),
}
),
self.EXP_ID_3: stats_domain.ExplorationStats(
self.EXP_ID_3, self.EXP_DEFAULT_VERSION, 0, 0, 0, 0, 0, 0, {})
}
return current_completions[exp_id]
@classmethod
def _mock_get_zero_impact_score(cls, unused_exploration_id):
return 0
@classmethod
def _mock_get_below_zero_impact_score(cls, unused_exploration_id):
return -1
@classmethod
def _mock_get_positive_impact_score(cls, unused_exploration_id):
return 1
def _run_computation(self):
"""Runs the MapReduce job after running the continuous
statistics aggregator for explorations to get the correct num
completion events.
"""
with self.swap(
stats_services, 'get_exploration_stats', self._mock_get_statistics):
ModifiedUserStatsAggregator.start_computation()
self.process_and_flush_pending_tasks()
def _generate_user_ids(self, count):
"""Generate unique user ids to rate an exploration. Each user id needs
to be unique since each user can only give an exploration one rating.
"""
return ['user%d' % i for i in range(count)]
def _create_exploration(self, exp_id, user_id):
exploration = exp_domain.Exploration.create_default_exploration(exp_id)
exp_services.save_new_exploration(user_id, exploration)
return exploration
def _record_start(self, exp_id, exp_version, state):
"""Record start event to an exploration.
Completing the exploration is not necessary here since the total_plays
are currently being counted taking into account only the # of starts.
"""
event_services.StartExplorationEventHandler.record(
exp_id, exp_version, state, self.USER_SESSION_ID, {},
feconf.PLAY_TYPE_NORMAL)
def _rate_exploration(self, exp_id, num_ratings, rating):
"""Create num_ratings ratings for exploration with exp_id,
of value rating.
"""
# Each user id needs to be unique since each user can only give an
# exploration one rating.
user_ids = self._generate_user_ids(num_ratings)
for user_id in user_ids:
rating_services.assign_rating_to_exploration(
user_id, exp_id, rating)
def _record_exploration_rating(self, exp_id, ratings):
user_ids = self._generate_user_ids(len(ratings))
self.process_and_flush_pending_tasks()
for ind, user_id in enumerate(user_ids):
event_services.RateExplorationEventHandler.record(
exp_id, user_id, ratings[ind], None)
self.process_and_flush_pending_tasks()
def _record_exploration_rating_for_user(
self, exp_id, user_id, rating, old_rating=None):
self.process_and_flush_pending_tasks()
event_services.RateExplorationEventHandler.record(
exp_id, user_id, rating, old_rating)
self.process_and_flush_pending_tasks()
def test_stats_for_user_with_no_explorations(self):
"""Test that a user who is not a contributor on any exploration
is not assigned value of impact score, total plays and average ratings.
"""
self._run_computation()
user_stats_model = user_models.UserStatsModel.get(
self.user_a_id, strict=False)
self.assertIsNone(user_stats_model)
def test_standard_user_stats_calculation_one_exploration(self):
exploration = self._create_exploration(self.EXP_ID_1, self.user_a_id)
# Give this exploration an average rating of 4.
avg_rating = 4
self._rate_exploration(exploration.id, 5, avg_rating)
# The expected answer count is the sum of the first hit counts in the
# statistics defined in _get_mock_statistics() method above.
expected_answer_count = 15
reach = expected_answer_count ** self.EXPONENT
expected_user_impact_score = round(
((avg_rating - 2) * reach) ** self.EXPONENT)
# Verify that the impact score matches the expected.
self._run_computation()
user_stats_model = user_models.UserStatsModel.get(self.user_a_id)
self.assertEqual(
user_stats_model.impact_score, expected_user_impact_score)
def test_exploration_multiple_contributors(self):
exploration = self._create_exploration(self.EXP_ID_1, self.user_a_id)
# Give this exploration an average rating of 4.
avg_rating = 4
self._rate_exploration(exploration.id, 5, avg_rating)
exp_services.update_exploration(self.user_b_id, self.EXP_ID_1, [], '')
# The expected answer count is the sum of the first hit counts in the
# statistics defined in _get_mock_statistics() method above.
expected_answer_count = 15
reach = expected_answer_count ** self.EXPONENT
contrib = 0.5
expected_user_impact_score = round(
((avg_rating - 2) * reach * contrib) ** self.EXPONENT)
# Verify that the impact score matches the expected.
self._run_computation()
user_stats_model = user_models.UserStatsModel.get(self.user_a_id)
self.assertEqual(
user_stats_model.impact_score, expected_user_impact_score)
user_stats_model = user_models.UserStatsModel.get(self.user_b_id)
self.assertEqual(
user_stats_model.impact_score, expected_user_impact_score)
def test_standard_user_stats_calculation_multiple_explorations(self):
exploration_1 = self._create_exploration(self.EXP_ID_1, self.user_a_id)
exploration_2 = self._create_exploration(self.EXP_ID_2, self.user_a_id)
avg_rating = 4
self._rate_exploration(exploration_1.id, 2, avg_rating)
self._rate_exploration(exploration_2.id, 2, avg_rating)
# The expected answer count is the sum of the first hit counts in the
# statistics defined in _get_mock_statistics() method above.
expected_answer_count = 15
reach = expected_answer_count ** self.EXPONENT
impact_per_exp = ((avg_rating - 2) * reach) # * 1 for contribution
expected_user_impact_score = round(
(impact_per_exp * 2) ** self.EXPONENT)
# Verify that the impact score matches the expected.
self._run_computation()
user_stats_model = user_models.UserStatsModel.get(self.user_a_id)
self.assertEqual(
user_stats_model.impact_score, expected_user_impact_score)
def test_only_yield_when_rating_greater_than_two(self):
"""Tests that map only yields an impact score for an
exploration when the impact score is greater than 0.
"""
self._create_exploration(self.EXP_ID_1, self.user_a_id)
# Give two ratings of 1.
self._rate_exploration(self.EXP_ID_1, 2, 1)
self._run_computation()
user_stats_model = user_models.UserStatsModel.get(
self.user_a_id, strict=False)
self.assertEqual(user_stats_model.impact_score, 0)
ModifiedUserStatsAggregator.stop_computation(self.user_a_id)
# Give two ratings of 2.
self._rate_exploration(self.EXP_ID_1, 2, 2)
self._run_computation()
user_stats_model = user_models.UserStatsModel.get(
self.user_a_id, strict=False)
self.assertEqual(user_stats_model.impact_score, 0)
ModifiedUserStatsAggregator.stop_computation(self.user_a_id)
# Give two ratings of 3. The impact score should now be nonzero.
self._rate_exploration(self.EXP_ID_1, 2, 3)
self._run_computation()
user_stats_model = user_models.UserStatsModel.get(
self.user_a_id, strict=False)
self.assertIsNotNone(user_stats_model)
self.assertGreater(user_stats_model.impact_score, 0)
def test_impact_for_exp_with_no_answers(self):
"""Test that when an exploration has no answers, it is considered to
have no reach.
"""
exploration = self._create_exploration(self.EXP_ID_3, self.user_a_id)
self._rate_exploration(exploration.id, 5, 3)
self._run_computation()
user_stats_model = user_models.UserStatsModel.get(self.user_a_id)
self.assertEqual(user_stats_model.impact_score, 0)
def test_impact_for_exp_with_no_ratings(self):
"""Test that when an exploration has no ratings, the impact returned
from the impact function is 0.
"""
self._create_exploration(self.EXP_ID_1, self.user_a_id)
user_stats_model = user_models.UserStatsModel.get(
self.user_a_id, strict=False)
self.assertEqual(user_stats_model, None)
def test_realtime_layer_batch_job_no_ratings_plays(self):
self._create_exploration(
self.EXP_ID_1, self.user_a_id)
user_stats = (
user_jobs_continuous.UserStatsAggregator.get_dashboard_stats(
self.user_a_id))
self.assertEquals(
user_stats['total_plays'], 0)
self.assertEquals(
user_stats['num_ratings'], 0)
self.assertEquals(
user_stats['average_ratings'], None)
def test_realtime_layer_batch_job_single_rating(self):
self._create_exploration(
self.EXP_ID_1, self.user_a_id)
self._record_exploration_rating(self.EXP_ID_1, [4])
user_stats = (
user_jobs_continuous.UserStatsAggregator.get_dashboard_stats(
self.user_a_id))
self.assertEquals(user_stats['total_plays'], 0)
self.assertEquals(user_stats['num_ratings'], 1)
self.assertEquals(user_stats['average_ratings'], 4)
def test_realtime_layer_batch_job_single_exploration_one_owner(self):
exploration = self._create_exploration(
self.EXP_ID_1, self.user_a_id)
exp_id = self.EXP_ID_1
exp_version = self.EXP_DEFAULT_VERSION
state = exploration.init_state_name
self._record_start(exp_id, exp_version, state)
self._record_start(exp_id, exp_version, state)
self._record_exploration_rating(exp_id, [2, 5])
user_stats = (
user_jobs_continuous.UserStatsAggregator.get_dashboard_stats(
self.user_a_id))
self.assertEquals(user_stats['total_plays'], 2)
self.assertEquals(user_stats['num_ratings'], 2)
self.assertEquals(user_stats['average_ratings'], 3.5)
def test_realtime_layer_batch_job_single_exploration_multiple_owners(self):
exploration = self._create_exploration(
self.EXP_ID_1, self.user_a_id)
rights_manager.assign_role_for_exploration(
self.user_a, self.EXP_ID_1, self.user_b_id,
rights_manager.ROLE_OWNER)
exp_version = self.EXP_DEFAULT_VERSION
exp_id = self.EXP_ID_1
state = exploration.init_state_name
self._record_start(exp_id, exp_version, state)
self._record_start(exp_id, exp_version, state)
self._record_exploration_rating(exp_id, [3, 4, 5])
self._record_exploration_rating(exp_id, [1, 5, 4])
expected_results = {
'total_plays': 2,
'num_ratings': 6,
'average_ratings': 22 / 6.0
}
user_stats_1 = (
user_jobs_continuous.UserStatsAggregator.get_dashboard_stats(
self.user_a_id))
self.assertEquals(
user_stats_1['total_plays'], expected_results['total_plays'])
self.assertEquals(
user_stats_1['num_ratings'], expected_results['num_ratings'])
self.assertEquals(
user_stats_1['average_ratings'],
expected_results['average_ratings'])
user_stats_2 = (
user_jobs_continuous.UserStatsAggregator.get_dashboard_stats(
self.user_b_id))
self.assertEquals(
user_stats_2['total_plays'], expected_results['total_plays'])
self.assertEquals(
user_stats_2['num_ratings'], expected_results['num_ratings'])
self.assertEquals(
user_stats_2['average_ratings'],
expected_results['average_ratings'])
def test_realtime_layer_batch_job_multiple_explorations_one_owner(self):
self._create_exploration(
self.EXP_ID_1, self.user_a_id)
self._create_exploration(
self.EXP_ID_2, self.user_a_id)
self._record_exploration_rating(self.EXP_ID_1, [4, 5, 2])
self._record_exploration_rating(self.EXP_ID_2, [5, 2])
user_stats = (
user_jobs_continuous.UserStatsAggregator.get_dashboard_stats(
self.user_a_id))
self.assertEquals(user_stats['total_plays'], 0)
self.assertEquals(user_stats['num_ratings'], 5)
self.assertEquals(user_stats['average_ratings'], 18 / 5.0)
def test_realtime_layer_batch_job_user_rate_same_exp_multiple_times(self):
self._create_exploration(
self.EXP_ID_1, self.user_a_id)
exp_id_1 = self.EXP_ID_1
self._record_exploration_rating_for_user(exp_id_1, self.user_b_id, 5)
user_stats = (
user_jobs_continuous.UserStatsAggregator.get_dashboard_stats(
self.user_a_id))
self.assertEquals(user_stats['total_plays'], 0)
self.assertEquals(user_stats['num_ratings'], 1)
self.assertEquals(user_stats['average_ratings'], 5)
self._record_exploration_rating_for_user(
exp_id_1, self.user_b_id, 3, old_rating=5)
user_stats = (
user_jobs_continuous.UserStatsAggregator.get_dashboard_stats(
self.user_a_id))
self.assertEquals(user_stats['total_plays'], 0)
self.assertEquals(user_stats['num_ratings'], 1)
self.assertEquals(user_stats['average_ratings'], 3)
def test_both_realtime_layer_and_batch_data(self):
exploration_1 = self._create_exploration(self.EXP_ID_1, self.user_a_id)
exploration_2 = self._create_exploration(self.EXP_ID_2, self.user_a_id)
exp_id_1 = self.EXP_ID_1
exp_id_2 = self.EXP_ID_2
exp_version = self.EXP_DEFAULT_VERSION
state_1 = exploration_1.init_state_name
state_2 = exploration_2.init_state_name
self._rate_exploration(exp_id_1, 2, 4)
self._rate_exploration(exp_id_2, 4, 3)
# Run the computation and check data from batch job.
self._run_computation()
user_stats_model = user_models.UserStatsModel.get(self.user_a_id)
# The total plays is the sum of the number of starts of both the
# exploration_1 and exploration_2 as defined in the
# _mock_get_statistics() method above.
self.assertEqual(user_stats_model.total_plays, 14)
self.assertEqual(user_stats_model.num_ratings, 6)
self.assertEqual(user_stats_model.average_ratings, 20 / 6.0)
# Stop the batch job. Fire up a few events and check data from realtime
# job.
ModifiedUserStatsAggregator.stop_computation(self.user_a_id)
self._record_start(exp_id_1, exp_version, state_1)
self._record_start(exp_id_2, exp_version, state_2)
self._record_exploration_rating(exp_id_1, [2, 5])
self._record_exploration_rating(exp_id_2, [4, 1])
user_stats = (
user_jobs_continuous.UserStatsAggregator.get_dashboard_stats(
self.user_a_id))
# After recording two start events, the total plays is now increased by
# two.
self.assertEquals(user_stats['total_plays'], 16)
self.assertEquals(user_stats['num_ratings'], 10)
self.assertEquals(user_stats['average_ratings'], 32 / 10.0)
|
apache-2.0
|
[
3,
2803,
26,
2774,
13,
24,
199,
3,
199,
3,
1898,
6927,
710,
593,
802,
4674,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
13,
1311,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
2925,
367,
922,
17216,
28319,
1298,
1041,
199,
199,
646,
5055,
199,
199,
504,
6170,
492,
9643,
63,
5189,
199,
504,
6170,
14,
2261,
492,
3245,
63,
5950,
199,
504,
6170,
14,
2261,
492,
1566,
63,
5950,
199,
504,
6170,
14,
2261,
492,
1437,
63,
2261,
199,
504,
6170,
14,
2261,
492,
1437,
63,
6920,
63,
368,
63,
1997,
199,
504,
6170,
14,
2261,
492,
1437,
63,
5950,
199,
504,
6170,
14,
2261,
492,
17145,
63,
5950,
199,
504,
6170,
14,
2261,
492,
18360,
63,
5950,
199,
504,
6170,
14,
2261,
492,
4481,
63,
2609,
199,
504,
6170,
14,
2261,
492,
5020,
63,
2261,
199,
504,
6170,
14,
2261,
492,
5020,
63,
5950,
199,
504,
6170,
14,
2261,
492,
922,
63,
6920,
63,
23458,
199,
504,
6170,
14,
2261,
492,
922,
63,
5950,
199,
504,
6170,
14,
3246,
492,
1709,
199,
504,
6170,
14,
2219,
492,
511,
63,
1208,
199,
646,
1964,
2190,
199,
646,
3778,
199,
199,
8,
1474,
63,
992,
12,
5020,
63,
992,
12,
922,
63,
992,
4258,
275,
1709,
14,
10899,
14,
646,
63,
992,
779,
272,
1709,
14,
14546,
14,
29028,
12,
1709,
14,
14546,
14,
13724,
12,
1709,
14,
14546,
14,
751,
566,
199,
1765,
1825,
63,
5950,
275,
1709,
14,
10899,
14,
646,
63,
1765,
1825,
63,
5950,
342,
199,
199,
29374,
63,
998,
275,
283,
7504,
7,
199,
29374,
63,
19091,
275,
283,
6888,
7,
199,
199,
11992,
63,
998,
275,
283,
30065,
7,
199,
11992,
63,
19091,
275,
283,
6888,
7,
199,
11992,
63,
17,
63,
998,
275,
283,
30065,
17,
7,
199,
11992,
63,
17,
63,
19091,
275,
283,
6888,
17,
7,
199,
11992,
63,
18,
63,
998,
275,
283,
30065,
18,
7,
199,
11992,
63,
18,
63,
19091,
275,
283,
6888,
18,
7,
199,
199,
18068,
7111,
63,
16103,
63,
6348,
5550,
275,
283,
13485,
2462,
5420,
7,
199,
199,
3791,
63,
998,
275,
283,
751,
63,
344,
7,
199,
879,
18400,
63,
3791,
63,
998,
275,
283,
13565,
63,
751,
63,
344,
7,
199,
3791,
63,
33,
63,
10089,
275,
283,
751,
63,
65,
32,
2694,
14,
957,
7,
199,
3791,
63,
33,
63,
11958,
275,
283,
65,
7,
199,
3791,
63,
34,
63,
10089,
275,
283,
751,
63,
66,
32,
2694,
14,
957,
7,
199,
3791,
63,
34,
63,
11958,
275,
283,
66,
7,
421,
199,
533,
22016,
29574,
16083,
23933,
8,
267,
922,
63,
6920,
63,
23458,
14,
30122,
29574,
16083,
23933,
304,
272,
408,
33,
6042,
577,
1119,
3576,
29574,
16083,
23933,
626,
1630,
440,
1343,
282,
892,
1362,
3522,
3906,
1380,
314,
4136,
1373,
965,
9158,
14,
272,
408,
272,
768,
3744,
272,
347,
485,
362,
63,
2912,
63,
2423,
63,
2609,
63,
533,
8,
1886,
304,
267,
372,
22016,
29574,
16083,
22153,
6694,
2988,
339,
768,
3744,
272,
347,
485,
31257,
1997,
63,
2912,
63,
2423,
63,
4399,
63,
6352,
63,
368,
63,
3198,
8,
1886,
304,
267,
986,
421,
199,
533,
22016,
29574,
16083,
22153,
6694,
2988,
8,
267,
922,
63,
6920,
63,
23458,
14,
29574,
16083,
22153,
6694,
2988,
304,
339,
768,
3744,
272,
347,
485,
362,
63,
23458,
63,
31598,
63,
533,
8,
1886,
304,
267,
372,
22016,
29574,
16083,
23933,
421,
199,
533,
799,
2946,
16083,
23933,
5072,
2925,
8,
396,
63,
1208,
14,
9417,
14440,
304,
272,
408,
2925,
367,
28319,
1298,
25613,
4007,
314,
283,
14951,
13116,
7,
3420,
402,
272,
314,
922,
17216,
14,
272,
408,
339,
11727,
63,
2571,
63,
20600,
3960,
63,
2707,
63,
7569,
275,
359,
267,
22016,
29574,
16083,
23933,
61,
339,
347,
485,
362,
63,
2062,
63,
8240,
63,
3966,
63,
807,
8,
288,
291,
12,
922,
63,
344,
12,
10679,
63,
344,
12,
10679,
63,
1213,
12,
10679,
63,
466,
12,
288,
5532,
63,
466,
12,
2061,
63,
5334,
63,
706,
304,
267,
372,
469,
288,
283,
8240,
63,
344,
356,
10679,
63,
344,
12,
288,
283,
8240,
63,
1213,
356,
10679,
63,
1213,
12,
288,
283,
2502,
63,
344,
356,
922,
63,
344,
12,
288,
283,
2019,
63,
5334,
63,
706,
356,
2061,
63,
5334,
63,
706,
12,
288,
283,
5875,
356,
334,
355,
283,
4665,
450,
83,
2737,
543,
2538,
19095,
83,
60,
30484,
450,
334,
490,
10679,
63,
466,
12,
10679,
63,
1213,
1826,
288,
283,
466,
356,
5532,
63,
466,
12,
267,
789,
339,
347,
485,
362,
63,
2786,
63,
14951,
63,
1474,
63,
4753,
63,
3966,
63,
265,
63,
706,
8,
277,
12,
1437,
63,
344,
304,
267,
4750,
63,
14951,
63,
4753,
275,
1437,
63,
5950,
14,
362,
63,
29028,
63,
15331,
63,
2343,
8,
288,
1437,
63,
344,
15786,
17,
61,
267,
372,
4750,
63,
14951,
63,
4753,
459,
3966,
63,
265,
63,
706,
418,
339,
347,
485,
362,
63,
2786,
63,
14951,
63,
3627,
63,
4753,
63,
3966,
63,
265,
63,
706,
8,
288,
291,
12,
3245,
63,
344,
304,
267,
4750,
63,
14951,
63,
4753,
275,
334,
288,
3245,
63,
5950,
14,
362,
63,
3627,
63,
15331,
63,
2343,
8,
355,
3245,
63,
344,
15786,
17,
566,
267,
372,
4750,
63,
14951,
63,
4753,
459,
3966,
63,
265,
63,
706,
418,
339,
347,
485,
362,
63,
396,
63,
1100,
8,
277,
304,
267,
372,
291,
14,
9286,
8
] |
[
2803,
26,
2774,
13,
24,
199,
3,
199,
3,
1898,
6927,
710,
593,
802,
4674,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
13,
1311,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
2925,
367,
922,
17216,
28319,
1298,
1041,
199,
199,
646,
5055,
199,
199,
504,
6170,
492,
9643,
63,
5189,
199,
504,
6170,
14,
2261,
492,
3245,
63,
5950,
199,
504,
6170,
14,
2261,
492,
1566,
63,
5950,
199,
504,
6170,
14,
2261,
492,
1437,
63,
2261,
199,
504,
6170,
14,
2261,
492,
1437,
63,
6920,
63,
368,
63,
1997,
199,
504,
6170,
14,
2261,
492,
1437,
63,
5950,
199,
504,
6170,
14,
2261,
492,
17145,
63,
5950,
199,
504,
6170,
14,
2261,
492,
18360,
63,
5950,
199,
504,
6170,
14,
2261,
492,
4481,
63,
2609,
199,
504,
6170,
14,
2261,
492,
5020,
63,
2261,
199,
504,
6170,
14,
2261,
492,
5020,
63,
5950,
199,
504,
6170,
14,
2261,
492,
922,
63,
6920,
63,
23458,
199,
504,
6170,
14,
2261,
492,
922,
63,
5950,
199,
504,
6170,
14,
3246,
492,
1709,
199,
504,
6170,
14,
2219,
492,
511,
63,
1208,
199,
646,
1964,
2190,
199,
646,
3778,
199,
199,
8,
1474,
63,
992,
12,
5020,
63,
992,
12,
922,
63,
992,
4258,
275,
1709,
14,
10899,
14,
646,
63,
992,
779,
272,
1709,
14,
14546,
14,
29028,
12,
1709,
14,
14546,
14,
13724,
12,
1709,
14,
14546,
14,
751,
566,
199,
1765,
1825,
63,
5950,
275,
1709,
14,
10899,
14,
646,
63,
1765,
1825,
63,
5950,
342,
199,
199,
29374,
63,
998,
275,
283,
7504,
7,
199,
29374,
63,
19091,
275,
283,
6888,
7,
199,
199,
11992,
63,
998,
275,
283,
30065,
7,
199,
11992,
63,
19091,
275,
283,
6888,
7,
199,
11992,
63,
17,
63,
998,
275,
283,
30065,
17,
7,
199,
11992,
63,
17,
63,
19091,
275,
283,
6888,
17,
7,
199,
11992,
63,
18,
63,
998,
275,
283,
30065,
18,
7,
199,
11992,
63,
18,
63,
19091,
275,
283,
6888,
18,
7,
199,
199,
18068,
7111,
63,
16103,
63,
6348,
5550,
275,
283,
13485,
2462,
5420,
7,
199,
199,
3791,
63,
998,
275,
283,
751,
63,
344,
7,
199,
879,
18400,
63,
3791,
63,
998,
275,
283,
13565,
63,
751,
63,
344,
7,
199,
3791,
63,
33,
63,
10089,
275,
283,
751,
63,
65,
32,
2694,
14,
957,
7,
199,
3791,
63,
33,
63,
11958,
275,
283,
65,
7,
199,
3791,
63,
34,
63,
10089,
275,
283,
751,
63,
66,
32,
2694,
14,
957,
7,
199,
3791,
63,
34,
63,
11958,
275,
283,
66,
7,
421,
199,
533,
22016,
29574,
16083,
23933,
8,
267,
922,
63,
6920,
63,
23458,
14,
30122,
29574,
16083,
23933,
304,
272,
408,
33,
6042,
577,
1119,
3576,
29574,
16083,
23933,
626,
1630,
440,
1343,
282,
892,
1362,
3522,
3906,
1380,
314,
4136,
1373,
965,
9158,
14,
272,
408,
272,
768,
3744,
272,
347,
485,
362,
63,
2912,
63,
2423,
63,
2609,
63,
533,
8,
1886,
304,
267,
372,
22016,
29574,
16083,
22153,
6694,
2988,
339,
768,
3744,
272,
347,
485,
31257,
1997,
63,
2912,
63,
2423,
63,
4399,
63,
6352,
63,
368,
63,
3198,
8,
1886,
304,
267,
986,
421,
199,
533,
22016,
29574,
16083,
22153,
6694,
2988,
8,
267,
922,
63,
6920,
63,
23458,
14,
29574,
16083,
22153,
6694,
2988,
304,
339,
768,
3744,
272,
347,
485,
362,
63,
23458,
63,
31598,
63,
533,
8,
1886,
304,
267,
372,
22016,
29574,
16083,
23933,
421,
199,
533,
799,
2946,
16083,
23933,
5072,
2925,
8,
396,
63,
1208,
14,
9417,
14440,
304,
272,
408,
2925,
367,
28319,
1298,
25613,
4007,
314,
283,
14951,
13116,
7,
3420,
402,
272,
314,
922,
17216,
14,
272,
408,
339,
11727,
63,
2571,
63,
20600,
3960,
63,
2707,
63,
7569,
275,
359,
267,
22016,
29574,
16083,
23933,
61,
339,
347,
485,
362,
63,
2062,
63,
8240,
63,
3966,
63,
807,
8,
288,
291,
12,
922,
63,
344,
12,
10679,
63,
344,
12,
10679,
63,
1213,
12,
10679,
63,
466,
12,
288,
5532,
63,
466,
12,
2061,
63,
5334,
63,
706,
304,
267,
372,
469,
288,
283,
8240,
63,
344,
356,
10679,
63,
344,
12,
288,
283,
8240,
63,
1213,
356,
10679,
63,
1213,
12,
288,
283,
2502,
63,
344,
356,
922,
63,
344,
12,
288,
283,
2019,
63,
5334,
63,
706,
356,
2061,
63,
5334,
63,
706,
12,
288,
283,
5875,
356,
334,
355,
283,
4665,
450,
83,
2737,
543,
2538,
19095,
83,
60,
30484,
450,
334,
490,
10679,
63,
466,
12,
10679,
63,
1213,
1826,
288,
283,
466,
356,
5532,
63,
466,
12,
267,
789,
339,
347,
485,
362,
63,
2786,
63,
14951,
63,
1474,
63,
4753,
63,
3966,
63,
265,
63,
706,
8,
277,
12,
1437,
63,
344,
304,
267,
4750,
63,
14951,
63,
4753,
275,
1437,
63,
5950,
14,
362,
63,
29028,
63,
15331,
63,
2343,
8,
288,
1437,
63,
344,
15786,
17,
61,
267,
372,
4750,
63,
14951,
63,
4753,
459,
3966,
63,
265,
63,
706,
418,
339,
347,
485,
362,
63,
2786,
63,
14951,
63,
3627,
63,
4753,
63,
3966,
63,
265,
63,
706,
8,
288,
291,
12,
3245,
63,
344,
304,
267,
4750,
63,
14951,
63,
4753,
275,
334,
288,
3245,
63,
5950,
14,
362,
63,
3627,
63,
15331,
63,
2343,
8,
355,
3245,
63,
344,
15786,
17,
566,
267,
372,
4750,
63,
14951,
63,
4753,
459,
3966,
63,
265,
63,
706,
418,
339,
347,
485,
362,
63,
396,
63,
1100,
8,
277,
304,
267,
372,
291,
14,
9286,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ZhaoCJ/django
|
tests/model_fields/test_imagefield.py
|
4
|
16020
|
from __future__ import unicode_literals
import os
import shutil
from unittest import skipIf
from django.core.exceptions import ImproperlyConfigured
from django.core.files import File
from django.core.files.images import ImageFile
from django.test import TestCase
from django.utils._os import upath
try:
from .models import Image
except ImproperlyConfigured:
Image = None
if Image:
from .models import (Person, PersonWithHeight, PersonWithHeightAndWidth,
PersonDimensionsFirst, PersonTwoImages, TestImageFieldFile)
from .models import temp_storage_dir
else:
# Pillow not available, create dummy classes (tests will be skipped anyway)
class Person():
pass
PersonWithHeight = PersonWithHeightAndWidth = PersonDimensionsFirst = Person
PersonTwoImages = Person
class ImageFieldTestMixin(object):
"""
Mixin class to provide common functionality to ImageField test classes.
"""
# Person model to use for tests.
PersonModel = PersonWithHeightAndWidth
# File class to use for file instances.
File = ImageFile
def setUp(self):
"""
Creates a pristine temp directory (or deletes and recreates if it
already exists) that the model uses as its storage directory.
Sets up two ImageFile instances for use in tests.
"""
if os.path.exists(temp_storage_dir):
shutil.rmtree(temp_storage_dir)
os.mkdir(temp_storage_dir)
file_path1 = os.path.join(os.path.dirname(upath(__file__)), "4x8.png")
self.file1 = self.File(open(file_path1, 'rb'))
file_path2 = os.path.join(os.path.dirname(upath(__file__)), "8x4.png")
self.file2 = self.File(open(file_path2, 'rb'))
def tearDown(self):
"""
Removes temp directory and all its contents.
"""
shutil.rmtree(temp_storage_dir)
def check_dimensions(self, instance, width, height,
field_name='mugshot'):
"""
Asserts that the given width and height values match both the
field's height and width attributes and the height and width fields
(if defined) the image field is caching to.
Note, this method will check for dimension fields named by adding
"_width" or "_height" to the name of the ImageField. So, the
models used in these tests must have their fields named
accordingly.
By default, we check the field named "mugshot", but this can be
specified by passing the field_name parameter.
"""
field = getattr(instance, field_name)
# Check height/width attributes of field.
if width is None and height is None:
self.assertRaises(ValueError, getattr, field, 'width')
self.assertRaises(ValueError, getattr, field, 'height')
else:
self.assertEqual(field.width, width)
self.assertEqual(field.height, height)
# Check height/width fields of model, if defined.
width_field_name = field_name + '_width'
if hasattr(instance, width_field_name):
self.assertEqual(getattr(instance, width_field_name), width)
height_field_name = field_name + '_height'
if hasattr(instance, height_field_name):
self.assertEqual(getattr(instance, height_field_name), height)
@skipIf(Image is None, "PIL is required to test ImageField")
class ImageFieldTests(ImageFieldTestMixin, TestCase):
"""
Tests for ImageField that don't need to be run with each of the
different test model classes.
"""
def test_equal_notequal_hash(self):
"""
Bug #9786: Ensure '==' and '!=' work correctly.
Bug #9508: make sure hash() works as expected (equal items must
hash to the same value).
"""
# Create two Persons with different mugshots.
p1 = self.PersonModel(name="Joe")
p1.mugshot.save("mug", self.file1)
p2 = self.PersonModel(name="Bob")
p2.mugshot.save("mug", self.file2)
self.assertEqual(p1.mugshot == p2.mugshot, False)
self.assertEqual(p1.mugshot != p2.mugshot, True)
# Test again with an instance fetched from the db.
p1_db = self.PersonModel.objects.get(name="Joe")
self.assertEqual(p1_db.mugshot == p2.mugshot, False)
self.assertEqual(p1_db.mugshot != p2.mugshot, True)
# Instance from db should match the local instance.
self.assertEqual(p1_db.mugshot == p1.mugshot, True)
self.assertEqual(hash(p1_db.mugshot), hash(p1.mugshot))
self.assertEqual(p1_db.mugshot != p1.mugshot, False)
def test_instantiate_missing(self):
"""
If the underlying file is unavailable, still create instantiate the
object without error.
"""
p = self.PersonModel(name="Joan")
p.mugshot.save("shot", self.file1)
p = self.PersonModel.objects.get(name="Joan")
path = p.mugshot.path
shutil.move(path, path + '.moved')
p2 = self.PersonModel.objects.get(name="Joan")
def test_delete_when_missing(self):
"""
Bug #8175: correctly delete an object where the file no longer
exists on the file system.
"""
p = self.PersonModel(name="Fred")
p.mugshot.save("shot", self.file1)
os.remove(p.mugshot.path)
p.delete()
def test_size_method(self):
"""
Bug #8534: FileField.size should not leave the file open.
"""
p = self.PersonModel(name="Joan")
p.mugshot.save("shot", self.file1)
# Get a "clean" model instance
p = self.PersonModel.objects.get(name="Joan")
# It won't have an opened file.
self.assertEqual(p.mugshot.closed, True)
# After asking for the size, the file should still be closed.
_ = p.mugshot.size
self.assertEqual(p.mugshot.closed, True)
def test_pickle(self):
"""
Tests that ImageField can be pickled, unpickled, and that the
image of the unpickled version is the same as the original.
"""
import pickle
p = Person(name="Joe")
p.mugshot.save("mug", self.file1)
dump = pickle.dumps(p)
p2 = Person(name="Bob")
p2.mugshot = self.file1
loaded_p = pickle.loads(dump)
self.assertEqual(p.mugshot, loaded_p.mugshot)
@skipIf(Image is None, "PIL is required to test ImageField")
class ImageFieldTwoDimensionsTests(ImageFieldTestMixin, TestCase):
"""
Tests behavior of an ImageField and its dimensions fields.
"""
def test_constructor(self):
"""
Tests assigning an image field through the model's constructor.
"""
p = self.PersonModel(name='Joe', mugshot=self.file1)
self.check_dimensions(p, 4, 8)
p.save()
self.check_dimensions(p, 4, 8)
def test_image_after_constructor(self):
"""
Tests behavior when image is not passed in constructor.
"""
p = self.PersonModel(name='Joe')
# TestImageField value will default to being an instance of its
# attr_class, a TestImageFieldFile, with name == None, which will
# cause it to evaluate as False.
self.assertEqual(isinstance(p.mugshot, TestImageFieldFile), True)
self.assertEqual(bool(p.mugshot), False)
# Test setting a fresh created model instance.
p = self.PersonModel(name='Joe')
p.mugshot = self.file1
self.check_dimensions(p, 4, 8)
def test_create(self):
"""
Tests assigning an image in Manager.create().
"""
p = self.PersonModel.objects.create(name='Joe', mugshot=self.file1)
self.check_dimensions(p, 4, 8)
def test_default_value(self):
"""
Tests that the default value for an ImageField is an instance of
the field's attr_class (TestImageFieldFile in this case) with no
name (name set to None).
"""
p = self.PersonModel()
self.assertEqual(isinstance(p.mugshot, TestImageFieldFile), True)
self.assertEqual(bool(p.mugshot), False)
def test_assignment_to_None(self):
"""
Tests that assigning ImageField to None clears dimensions.
"""
p = self.PersonModel(name='Joe', mugshot=self.file1)
self.check_dimensions(p, 4, 8)
# If image assigned to None, dimension fields should be cleared.
p.mugshot = None
self.check_dimensions(p, None, None)
p.mugshot = self.file2
self.check_dimensions(p, 8, 4)
def test_field_save_and_delete_methods(self):
"""
Tests assignment using the field's save method and deletion using
the field's delete method.
"""
p = self.PersonModel(name='Joe')
p.mugshot.save("mug", self.file1)
self.check_dimensions(p, 4, 8)
# A new file should update dimensions.
p.mugshot.save("mug", self.file2)
self.check_dimensions(p, 8, 4)
# Field and dimensions should be cleared after a delete.
p.mugshot.delete(save=False)
self.assertEqual(p.mugshot, None)
self.check_dimensions(p, None, None)
def test_dimensions(self):
"""
Checks that dimensions are updated correctly in various situations.
"""
p = self.PersonModel(name='Joe')
# Dimensions should get set if file is saved.
p.mugshot.save("mug", self.file1)
self.check_dimensions(p, 4, 8)
# Test dimensions after fetching from database.
p = self.PersonModel.objects.get(name='Joe')
# Bug 11084: Dimensions should not get recalculated if file is
# coming from the database. We test this by checking if the file
# was opened.
self.assertEqual(p.mugshot.was_opened, False)
self.check_dimensions(p, 4, 8)
# After checking dimensions on the image field, the file will have
# opened.
self.assertEqual(p.mugshot.was_opened, True)
# Dimensions should now be cached, and if we reset was_opened and
# check dimensions again, the file should not have opened.
p.mugshot.was_opened = False
self.check_dimensions(p, 4, 8)
self.assertEqual(p.mugshot.was_opened, False)
# If we assign a new image to the instance, the dimensions should
# update.
p.mugshot = self.file2
self.check_dimensions(p, 8, 4)
# Dimensions were recalculated, and hence file should have opened.
self.assertEqual(p.mugshot.was_opened, True)
@skipIf(Image is None, "PIL is required to test ImageField")
class ImageFieldNoDimensionsTests(ImageFieldTwoDimensionsTests):
"""
Tests behavior of an ImageField with no dimension fields.
"""
PersonModel = Person
@skipIf(Image is None, "PIL is required to test ImageField")
class ImageFieldOneDimensionTests(ImageFieldTwoDimensionsTests):
"""
Tests behavior of an ImageField with one dimensions field.
"""
PersonModel = PersonWithHeight
@skipIf(Image is None, "PIL is required to test ImageField")
class ImageFieldDimensionsFirstTests(ImageFieldTwoDimensionsTests):
"""
Tests behavior of an ImageField where the dimensions fields are
defined before the ImageField.
"""
PersonModel = PersonDimensionsFirst
@skipIf(Image is None, "PIL is required to test ImageField")
class ImageFieldUsingFileTests(ImageFieldTwoDimensionsTests):
"""
Tests behavior of an ImageField when assigning it a File instance
rather than an ImageFile instance.
"""
PersonModel = PersonDimensionsFirst
File = File
@skipIf(Image is None, "PIL is required to test ImageField")
class TwoImageFieldTests(ImageFieldTestMixin, TestCase):
"""
Tests a model with two ImageFields.
"""
PersonModel = PersonTwoImages
def test_constructor(self):
p = self.PersonModel(mugshot=self.file1, headshot=self.file2)
self.check_dimensions(p, 4, 8, 'mugshot')
self.check_dimensions(p, 8, 4, 'headshot')
p.save()
self.check_dimensions(p, 4, 8, 'mugshot')
self.check_dimensions(p, 8, 4, 'headshot')
def test_create(self):
p = self.PersonModel.objects.create(mugshot=self.file1,
headshot=self.file2)
self.check_dimensions(p, 4, 8)
self.check_dimensions(p, 8, 4, 'headshot')
def test_assignment(self):
p = self.PersonModel()
self.check_dimensions(p, None, None, 'mugshot')
self.check_dimensions(p, None, None, 'headshot')
p.mugshot = self.file1
self.check_dimensions(p, 4, 8, 'mugshot')
self.check_dimensions(p, None, None, 'headshot')
p.headshot = self.file2
self.check_dimensions(p, 4, 8, 'mugshot')
self.check_dimensions(p, 8, 4, 'headshot')
# Clear the ImageFields one at a time.
p.mugshot = None
self.check_dimensions(p, None, None, 'mugshot')
self.check_dimensions(p, 8, 4, 'headshot')
p.headshot = None
self.check_dimensions(p, None, None, 'mugshot')
self.check_dimensions(p, None, None, 'headshot')
def test_field_save_and_delete_methods(self):
p = self.PersonModel(name='Joe')
p.mugshot.save("mug", self.file1)
self.check_dimensions(p, 4, 8, 'mugshot')
self.check_dimensions(p, None, None, 'headshot')
p.headshot.save("head", self.file2)
self.check_dimensions(p, 4, 8, 'mugshot')
self.check_dimensions(p, 8, 4, 'headshot')
# We can use save=True when deleting the image field with null=True
# dimension fields and the other field has an image.
p.headshot.delete(save=True)
self.check_dimensions(p, 4, 8, 'mugshot')
self.check_dimensions(p, None, None, 'headshot')
p.mugshot.delete(save=False)
self.check_dimensions(p, None, None, 'mugshot')
self.check_dimensions(p, None, None, 'headshot')
def test_dimensions(self):
"""
Checks that dimensions are updated correctly in various situations.
"""
p = self.PersonModel(name='Joe')
# Dimensions should get set for the saved file.
p.mugshot.save("mug", self.file1)
p.headshot.save("head", self.file2)
self.check_dimensions(p, 4, 8, 'mugshot')
self.check_dimensions(p, 8, 4, 'headshot')
# Test dimensions after fetching from database.
p = self.PersonModel.objects.get(name='Joe')
# Bug 11084: Dimensions should not get recalculated if file is
# coming from the database. We test this by checking if the file
# was opened.
self.assertEqual(p.mugshot.was_opened, False)
self.assertEqual(p.headshot.was_opened, False)
self.check_dimensions(p, 4, 8,'mugshot')
self.check_dimensions(p, 8, 4, 'headshot')
# After checking dimensions on the image fields, the files will
# have been opened.
self.assertEqual(p.mugshot.was_opened, True)
self.assertEqual(p.headshot.was_opened, True)
# Dimensions should now be cached, and if we reset was_opened and
# check dimensions again, the file should not have opened.
p.mugshot.was_opened = False
p.headshot.was_opened = False
self.check_dimensions(p, 4, 8,'mugshot')
self.check_dimensions(p, 8, 4, 'headshot')
self.assertEqual(p.mugshot.was_opened, False)
self.assertEqual(p.headshot.was_opened, False)
# If we assign a new image to the instance, the dimensions should
# update.
p.mugshot = self.file2
p.headshot = self.file1
self.check_dimensions(p, 8, 4, 'mugshot')
self.check_dimensions(p, 4, 8, 'headshot')
# Dimensions were recalculated, and hence file should have opened.
self.assertEqual(p.mugshot.was_opened, True)
self.assertEqual(p.headshot.was_opened, True)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
747,
199,
646,
5145,
199,
504,
2882,
492,
3372,
3917,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1018,
14,
1725,
492,
3814,
199,
504,
1639,
14,
1018,
14,
1725,
14,
4782,
492,
6047,
1173,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
1208,
423,
736,
492,
1536,
1619,
199,
199,
893,
26,
272,
687,
1275,
992,
492,
6047,
199,
2590,
11897,
26,
272,
6047,
275,
488,
199,
199,
692,
6047,
26,
272,
687,
1275,
992,
492,
334,
7344,
12,
8028,
3007,
8436,
12,
8028,
3007,
8436,
3325,
6216,
12,
267,
8028,
23370,
7147,
12,
8028,
11467,
18882,
12,
1379,
21910,
1173,
9,
272,
687,
1275,
992,
492,
2388,
63,
3494,
63,
694,
199,
2836,
26,
272,
327,
18130,
674,
440,
2808,
12,
1218,
7283,
3992,
334,
2219,
911,
506,
9645,
15988,
9,
272,
1021,
8028,
837,
267,
986,
272,
8028,
3007,
8436,
275,
8028,
3007,
8436,
3325,
6216,
275,
8028,
23370,
7147,
275,
8028,
272,
8028,
11467,
18882,
275,
8028,
421,
199,
533,
6047,
792,
22060,
8,
785,
304,
272,
408,
272,
28438,
1021,
370,
5647,
2863,
9330,
370,
6047,
792,
511,
3992,
14,
272,
408,
339,
327,
8028,
1402,
370,
675,
367,
2295,
14,
272,
8028,
1685,
275,
8028,
3007,
8436,
3325,
6216,
272,
327,
3814,
1021,
370,
675,
367,
570,
4454,
14,
272,
3814,
275,
6047,
1173,
339,
347,
3613,
8,
277,
304,
267,
408,
267,
10560,
282,
1979,
270,
1132,
2388,
2082,
334,
269,
21812,
436,
23959,
83,
340,
652,
267,
2575,
3495,
9,
626,
314,
1402,
4440,
465,
2399,
4887,
2082,
14,
398,
10729,
1536,
2877,
6047,
1173,
4454,
367,
675,
315,
2295,
14,
267,
408,
267,
340,
747,
14,
515,
14,
2444,
8,
808,
63,
3494,
63,
694,
304,
288,
5145,
14,
9242,
8,
808,
63,
3494,
63,
694,
9,
267,
747,
14,
8215,
8,
808,
63,
3494,
63,
694,
9,
398,
570,
63,
515,
17,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
384,
1619,
3460,
493,
22159,
298,
20,
88,
24,
14,
4524,
531,
267,
291,
14,
493,
17,
275,
291,
14,
1173,
8,
1490,
8,
493,
63,
515,
17,
12,
283,
4848,
1333,
398,
570,
63,
515,
18,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
384,
1619,
3460,
493,
22159,
298,
24,
88,
20,
14,
4524,
531,
267,
291,
14,
493,
18,
275,
291,
14,
1173,
8,
1490,
8,
493,
63,
515,
18,
12,
283,
4848,
1333,
339,
347,
6766,
8,
277,
304,
267,
408,
267,
23169,
2388,
2082,
436,
1006,
2399,
4072,
14,
267,
408,
267,
5145,
14,
9242,
8,
808,
63,
3494,
63,
694,
9,
339,
347,
1104,
63,
13320,
8,
277,
12,
1256,
12,
3462,
12,
4569,
12,
586,
901,
63,
354,
534,
6553,
458,
8885,
735,
267,
408,
267,
10716,
83,
626,
314,
1627,
3462,
436,
4569,
1338,
1336,
3865,
314,
267,
901,
1159,
4569,
436,
3462,
3004,
436,
314,
4569,
436,
3462,
1504,
267,
334,
692,
3247,
9,
314,
1834,
901,
365,
13627,
370,
14,
398,
3390,
12,
642,
1083,
911,
1104,
367,
6240,
1504,
4310,
701,
7791,
267,
2668,
2063,
2,
503,
2668,
3333,
2,
370,
314,
536,
402,
314,
6047,
792,
14,
221,
2002,
12,
314,
267,
1709,
1202,
315,
3520,
2295,
1471,
1172,
3932,
1504,
4310,
267,
24137,
14,
398,
4885,
849,
12,
781,
1104,
314,
901,
4310,
298,
6553,
458,
8885,
401,
1325,
642,
883,
506,
267,
2013,
701,
9476,
314,
901,
63,
354,
2725,
14,
267,
408,
267,
901,
275,
2519,
8,
842,
12,
901,
63,
354,
9,
267,
327,
2670,
4569,
15,
2063,
3004,
402,
901,
14,
267,
340,
3462,
365,
488,
436,
4569,
365,
488,
26,
288,
291,
14,
1855,
8,
3393,
12,
2519,
12,
901,
12,
283,
2063,
358,
288,
291,
14,
1855,
8,
3393,
12,
2519,
12,
901,
12,
283,
3333,
358,
267,
587,
26,
288,
291,
14,
629,
8,
698,
14,
2063,
12,
3462,
9,
288,
291,
14,
629,
8,
698,
14,
3333,
12,
4569,
9,
398,
327,
2670,
4569,
15,
2063,
1504,
402,
1402,
12,
340,
3247,
14,
267,
3462,
63,
698,
63,
354,
275,
901,
63,
354,
435,
2513,
2063,
7,
267,
340,
2688,
8,
842,
12,
3462,
63,
698,
63,
354,
304,
288,
291,
14,
629,
8,
5675,
8,
842,
12,
3462,
63,
698,
63,
354,
395,
3462,
9,
267,
4569,
63,
698,
63,
354,
275,
901,
63,
354,
435,
2513,
3333,
7,
267,
340,
2688,
8,
842,
12,
4569,
63,
698,
63,
354,
304,
288,
291,
14,
629,
8,
5675,
8,
842,
12,
4569,
63,
698,
63,
354,
395,
4569,
9,
421,
199,
32,
15118,
8,
3491,
365,
488,
12,
298,
48,
1193,
365,
1415,
370,
511,
6047,
792,
531,
199,
533,
6047,
792,
2925,
8,
21910,
22060,
12,
7640,
304,
272,
408,
272,
6496,
367,
6047,
792,
626,
2793,
1133,
1929,
370,
506,
1255,
543,
1924,
402,
314,
272,
3365,
511,
1402,
3992,
14,
272,
408,
339,
347,
511,
63,
1452,
63,
4610,
537,
63,
2227,
8,
277,
304,
267,
408,
267,
21605,
327,
2576,
1184,
26,
7523,
283,
6803,
436,
14597,
534,
1736,
6657,
14,
267,
21605,
327,
25,
14585,
26,
1852,
3238,
2631,
342,
5419,
465,
1420,
334,
1452,
2974,
1471,
267,
2631,
370,
314,
2011,
574,
680,
267,
408,
267,
327,
2790,
2877,
8028,
83,
543,
3365,
8504,
458,
8885,
83,
14,
267,
299,
17,
275,
291,
14,
7344,
1685,
8,
354,
628,
5691,
69,
531,
267,
299,
17,
14,
6553,
458,
8885,
14,
2117,
480,
77,
1518,
401,
291,
14,
493,
17,
9,
267,
299,
18,
275,
291,
14,
7344,
1685,
8,
354,
628,
22593,
531,
267,
299,
18,
14,
6553,
458,
8885,
14,
2117,
480,
77,
1518,
401,
291,
14,
493,
18,
9,
267,
291,
14,
629,
8,
80,
17,
14,
6553,
458,
8885,
508,
299,
18,
14,
6553,
458,
8885,
12,
756,
9,
267,
291,
14,
629,
8,
80,
17,
14,
6553,
458,
8885,
1137,
299,
18,
14,
6553,
458,
8885,
12,
715,
9,
398,
327,
1379,
4020,
543,
376,
1256,
19251,
687,
314,
1592,
14,
267,
299
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
747,
199,
646,
5145,
199,
504,
2882,
492,
3372,
3917,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1018,
14,
1725,
492,
3814,
199,
504,
1639,
14,
1018,
14,
1725,
14,
4782,
492,
6047,
1173,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
1208,
423,
736,
492,
1536,
1619,
199,
199,
893,
26,
272,
687,
1275,
992,
492,
6047,
199,
2590,
11897,
26,
272,
6047,
275,
488,
199,
199,
692,
6047,
26,
272,
687,
1275,
992,
492,
334,
7344,
12,
8028,
3007,
8436,
12,
8028,
3007,
8436,
3325,
6216,
12,
267,
8028,
23370,
7147,
12,
8028,
11467,
18882,
12,
1379,
21910,
1173,
9,
272,
687,
1275,
992,
492,
2388,
63,
3494,
63,
694,
199,
2836,
26,
272,
327,
18130,
674,
440,
2808,
12,
1218,
7283,
3992,
334,
2219,
911,
506,
9645,
15988,
9,
272,
1021,
8028,
837,
267,
986,
272,
8028,
3007,
8436,
275,
8028,
3007,
8436,
3325,
6216,
275,
8028,
23370,
7147,
275,
8028,
272,
8028,
11467,
18882,
275,
8028,
421,
199,
533,
6047,
792,
22060,
8,
785,
304,
272,
408,
272,
28438,
1021,
370,
5647,
2863,
9330,
370,
6047,
792,
511,
3992,
14,
272,
408,
339,
327,
8028,
1402,
370,
675,
367,
2295,
14,
272,
8028,
1685,
275,
8028,
3007,
8436,
3325,
6216,
272,
327,
3814,
1021,
370,
675,
367,
570,
4454,
14,
272,
3814,
275,
6047,
1173,
339,
347,
3613,
8,
277,
304,
267,
408,
267,
10560,
282,
1979,
270,
1132,
2388,
2082,
334,
269,
21812,
436,
23959,
83,
340,
652,
267,
2575,
3495,
9,
626,
314,
1402,
4440,
465,
2399,
4887,
2082,
14,
398,
10729,
1536,
2877,
6047,
1173,
4454,
367,
675,
315,
2295,
14,
267,
408,
267,
340,
747,
14,
515,
14,
2444,
8,
808,
63,
3494,
63,
694,
304,
288,
5145,
14,
9242,
8,
808,
63,
3494,
63,
694,
9,
267,
747,
14,
8215,
8,
808,
63,
3494,
63,
694,
9,
398,
570,
63,
515,
17,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
384,
1619,
3460,
493,
22159,
298,
20,
88,
24,
14,
4524,
531,
267,
291,
14,
493,
17,
275,
291,
14,
1173,
8,
1490,
8,
493,
63,
515,
17,
12,
283,
4848,
1333,
398,
570,
63,
515,
18,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
384,
1619,
3460,
493,
22159,
298,
24,
88,
20,
14,
4524,
531,
267,
291,
14,
493,
18,
275,
291,
14,
1173,
8,
1490,
8,
493,
63,
515,
18,
12,
283,
4848,
1333,
339,
347,
6766,
8,
277,
304,
267,
408,
267,
23169,
2388,
2082,
436,
1006,
2399,
4072,
14,
267,
408,
267,
5145,
14,
9242,
8,
808,
63,
3494,
63,
694,
9,
339,
347,
1104,
63,
13320,
8,
277,
12,
1256,
12,
3462,
12,
4569,
12,
586,
901,
63,
354,
534,
6553,
458,
8885,
735,
267,
408,
267,
10716,
83,
626,
314,
1627,
3462,
436,
4569,
1338,
1336,
3865,
314,
267,
901,
1159,
4569,
436,
3462,
3004,
436,
314,
4569,
436,
3462,
1504,
267,
334,
692,
3247,
9,
314,
1834,
901,
365,
13627,
370,
14,
398,
3390,
12,
642,
1083,
911,
1104,
367,
6240,
1504,
4310,
701,
7791,
267,
2668,
2063,
2,
503,
2668,
3333,
2,
370,
314,
536,
402,
314,
6047,
792,
14,
221,
2002,
12,
314,
267,
1709,
1202,
315,
3520,
2295,
1471,
1172,
3932,
1504,
4310,
267,
24137,
14,
398,
4885,
849,
12,
781,
1104,
314,
901,
4310,
298,
6553,
458,
8885,
401,
1325,
642,
883,
506,
267,
2013,
701,
9476,
314,
901,
63,
354,
2725,
14,
267,
408,
267,
901,
275,
2519,
8,
842,
12,
901,
63,
354,
9,
267,
327,
2670,
4569,
15,
2063,
3004,
402,
901,
14,
267,
340,
3462,
365,
488,
436,
4569,
365,
488,
26,
288,
291,
14,
1855,
8,
3393,
12,
2519,
12,
901,
12,
283,
2063,
358,
288,
291,
14,
1855,
8,
3393,
12,
2519,
12,
901,
12,
283,
3333,
358,
267,
587,
26,
288,
291,
14,
629,
8,
698,
14,
2063,
12,
3462,
9,
288,
291,
14,
629,
8,
698,
14,
3333,
12,
4569,
9,
398,
327,
2670,
4569,
15,
2063,
1504,
402,
1402,
12,
340,
3247,
14,
267,
3462,
63,
698,
63,
354,
275,
901,
63,
354,
435,
2513,
2063,
7,
267,
340,
2688,
8,
842,
12,
3462,
63,
698,
63,
354,
304,
288,
291,
14,
629,
8,
5675,
8,
842,
12,
3462,
63,
698,
63,
354,
395,
3462,
9,
267,
4569,
63,
698,
63,
354,
275,
901,
63,
354,
435,
2513,
3333,
7,
267,
340,
2688,
8,
842,
12,
4569,
63,
698,
63,
354,
304,
288,
291,
14,
629,
8,
5675,
8,
842,
12,
4569,
63,
698,
63,
354,
395,
4569,
9,
421,
199,
32,
15118,
8,
3491,
365,
488,
12,
298,
48,
1193,
365,
1415,
370,
511,
6047,
792,
531,
199,
533,
6047,
792,
2925,
8,
21910,
22060,
12,
7640,
304,
272,
408,
272,
6496,
367,
6047,
792,
626,
2793,
1133,
1929,
370,
506,
1255,
543,
1924,
402,
314,
272,
3365,
511,
1402,
3992,
14,
272,
408,
339,
347,
511,
63,
1452,
63,
4610,
537,
63,
2227,
8,
277,
304,
267,
408,
267,
21605,
327,
2576,
1184,
26,
7523,
283,
6803,
436,
14597,
534,
1736,
6657,
14,
267,
21605,
327,
25,
14585,
26,
1852,
3238,
2631,
342,
5419,
465,
1420,
334,
1452,
2974,
1471,
267,
2631,
370,
314,
2011,
574,
680,
267,
408,
267,
327,
2790,
2877,
8028,
83,
543,
3365,
8504,
458,
8885,
83,
14,
267,
299,
17,
275,
291,
14,
7344,
1685,
8,
354,
628,
5691,
69,
531,
267,
299,
17,
14,
6553,
458,
8885,
14,
2117,
480,
77,
1518,
401,
291,
14,
493,
17,
9,
267,
299,
18,
275,
291,
14,
7344,
1685,
8,
354,
628,
22593,
531,
267,
299,
18,
14,
6553,
458,
8885,
14,
2117,
480,
77,
1518,
401,
291,
14,
493,
18,
9,
267,
291,
14,
629,
8,
80,
17,
14,
6553,
458,
8885,
508,
299,
18,
14,
6553,
458,
8885,
12,
756,
9,
267,
291,
14,
629,
8,
80,
17,
14,
6553,
458,
8885,
1137,
299,
18,
14,
6553,
458,
8885,
12,
715,
9,
398,
327,
1379,
4020,
543,
376,
1256,
19251,
687,
314,
1592,
14,
267,
299,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lupyuen/RaspberryPiImage
|
home/pi/GrovePi/Software/Python/others/temboo/Library/Dropbox/FilesAndMetadata/__init__.py
|
4
|
2525
|
from temboo.Library.Dropbox.FilesAndMetadata.ChunkedUpload import ChunkedUpload, ChunkedUploadInputSet, ChunkedUploadResultSet, ChunkedUploadChoreographyExecution
from temboo.Library.Dropbox.FilesAndMetadata.CommitChunkedUpload import CommitChunkedUpload, CommitChunkedUploadInputSet, CommitChunkedUploadResultSet, CommitChunkedUploadChoreographyExecution
from temboo.Library.Dropbox.FilesAndMetadata.CreateCopyRef import CreateCopyRef, CreateCopyRefInputSet, CreateCopyRefResultSet, CreateCopyRefChoreographyExecution
from temboo.Library.Dropbox.FilesAndMetadata.Delta import Delta, DeltaInputSet, DeltaResultSet, DeltaChoreographyExecution
from temboo.Library.Dropbox.FilesAndMetadata.GetDownloadLink import GetDownloadLink, GetDownloadLinkInputSet, GetDownloadLinkResultSet, GetDownloadLinkChoreographyExecution
from temboo.Library.Dropbox.FilesAndMetadata.GetFile import GetFile, GetFileInputSet, GetFileResultSet, GetFileChoreographyExecution
from temboo.Library.Dropbox.FilesAndMetadata.GetFileRevisions import GetFileRevisions, GetFileRevisionsInputSet, GetFileRevisionsResultSet, GetFileRevisionsChoreographyExecution
from temboo.Library.Dropbox.FilesAndMetadata.GetShareableLink import GetShareableLink, GetShareableLinkInputSet, GetShareableLinkResultSet, GetShareableLinkChoreographyExecution
from temboo.Library.Dropbox.FilesAndMetadata.GetThumbnail import GetThumbnail, GetThumbnailInputSet, GetThumbnailResultSet, GetThumbnailChoreographyExecution
from temboo.Library.Dropbox.FilesAndMetadata.LatestCursor import LatestCursor, LatestCursorInputSet, LatestCursorResultSet, LatestCursorChoreographyExecution
from temboo.Library.Dropbox.FilesAndMetadata.ListFolderContents import ListFolderContents, ListFolderContentsInputSet, ListFolderContentsResultSet, ListFolderContentsChoreographyExecution
from temboo.Library.Dropbox.FilesAndMetadata.LongPollDelta import LongPollDelta, LongPollDeltaInputSet, LongPollDeltaResultSet, LongPollDeltaChoreographyExecution
from temboo.Library.Dropbox.FilesAndMetadata.RestoreFileToRevision import RestoreFileToRevision, RestoreFileToRevisionInputSet, RestoreFileToRevisionResultSet, RestoreFileToRevisionChoreographyExecution
from temboo.Library.Dropbox.FilesAndMetadata.SearchFilesAndFolders import SearchFilesAndFolders, SearchFilesAndFoldersInputSet, SearchFilesAndFoldersResultSet, SearchFilesAndFoldersChoreographyExecution
from temboo.Library.Dropbox.FilesAndMetadata.UploadFile import UploadFile, UploadFileInputSet, UploadFileResultSet, UploadFileChoreographyExecution
|
apache-2.0
|
[
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
9856,
379,
10301,
492,
25246,
379,
10301,
12,
25246,
379,
10301,
24478,
12,
25246,
379,
10301,
21722,
12,
25246,
379,
10301,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
11421,
9856,
379,
10301,
492,
21447,
9856,
379,
10301,
12,
21447,
9856,
379,
10301,
24478,
12,
21447,
9856,
379,
10301,
21722,
12,
21447,
9856,
379,
10301,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
2499,
5116,
2891,
492,
2790,
5116,
2891,
12,
2790,
5116,
2891,
24478,
12,
2790,
5116,
2891,
21722,
12,
2790,
5116,
2891,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
13411,
492,
18464,
502,
12,
18464,
502,
24478,
12,
18464,
502,
21722,
12,
18464,
502,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
1002,
11950,
3834,
492,
2372,
11950,
3834,
12,
2372,
11950,
3834,
24478,
12,
2372,
11950,
3834,
21722,
12,
2372,
11950,
3834,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
26535,
492,
2372,
1173,
12,
2372,
1173,
24478,
12,
2372,
1173,
21722,
12,
2372,
1173,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
26535,
497,
13193,
492,
2372,
1173,
497,
13193,
12,
2372,
1173,
497,
13193,
24478,
12,
2372,
1173,
497,
13193,
21722,
12,
2372,
1173,
497,
13193,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
1002,
18713,
461,
3834,
492,
2372,
18713,
461,
3834,
12,
2372,
18713,
461,
3834,
24478,
12,
2372,
18713,
461,
3834,
21722,
12,
2372,
18713,
461,
3834,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
1002,
2719,
5820,
492,
2372,
2719,
5820,
12,
2372,
2719,
5820,
24478,
12,
2372,
2719,
5820,
21722,
12,
2372,
2719,
5820,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
31438,
8993,
492,
491,
27126,
8993,
12,
491,
27126,
8993,
24478,
12,
491,
27126,
8993,
21722,
12,
491,
27126,
8993,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
1296,
7850,
11383,
492,
3820,
7850,
11383,
12,
3820,
7850,
11383,
24478,
12,
3820,
7850,
11383,
21722,
12,
3820,
7850,
11383,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
9551,
24022,
13411,
492,
19944,
24022,
13411,
12,
19944,
24022,
13411,
24478,
12,
19944,
24022,
13411,
21722,
12,
19944,
24022,
13411,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
21012,
1173,
1378,
12714,
492,
22379,
1173,
1378,
12714,
12,
22379,
1173,
1378,
12714,
24478,
12,
22379,
1173,
1378,
12714,
21722,
12,
22379,
1173,
1378,
12714,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
5278,
5535,
3325,
7850,
83,
492,
8730,
5535,
3325,
7850,
83,
12,
8730,
5535,
3325,
7850,
83,
24478,
12,
8730,
5535,
3325,
7850,
83,
21722,
12,
8730,
5535,
3325,
7850,
83,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
10301,
1173,
492,
19149,
1173,
12,
19149,
1173,
24478,
12,
19149,
1173,
21722,
12,
19149,
1173,
6209,
13322,
9773,
11310,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
9856,
379,
10301,
492,
25246,
379,
10301,
12,
25246,
379,
10301,
24478,
12,
25246,
379,
10301,
21722,
12,
25246,
379,
10301,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
11421,
9856,
379,
10301,
492,
21447,
9856,
379,
10301,
12,
21447,
9856,
379,
10301,
24478,
12,
21447,
9856,
379,
10301,
21722,
12,
21447,
9856,
379,
10301,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
2499,
5116,
2891,
492,
2790,
5116,
2891,
12,
2790,
5116,
2891,
24478,
12,
2790,
5116,
2891,
21722,
12,
2790,
5116,
2891,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
13411,
492,
18464,
502,
12,
18464,
502,
24478,
12,
18464,
502,
21722,
12,
18464,
502,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
1002,
11950,
3834,
492,
2372,
11950,
3834,
12,
2372,
11950,
3834,
24478,
12,
2372,
11950,
3834,
21722,
12,
2372,
11950,
3834,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
26535,
492,
2372,
1173,
12,
2372,
1173,
24478,
12,
2372,
1173,
21722,
12,
2372,
1173,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
26535,
497,
13193,
492,
2372,
1173,
497,
13193,
12,
2372,
1173,
497,
13193,
24478,
12,
2372,
1173,
497,
13193,
21722,
12,
2372,
1173,
497,
13193,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
1002,
18713,
461,
3834,
492,
2372,
18713,
461,
3834,
12,
2372,
18713,
461,
3834,
24478,
12,
2372,
18713,
461,
3834,
21722,
12,
2372,
18713,
461,
3834,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
1002,
2719,
5820,
492,
2372,
2719,
5820,
12,
2372,
2719,
5820,
24478,
12,
2372,
2719,
5820,
21722,
12,
2372,
2719,
5820,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
31438,
8993,
492,
491,
27126,
8993,
12,
491,
27126,
8993,
24478,
12,
491,
27126,
8993,
21722,
12,
491,
27126,
8993,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
1296,
7850,
11383,
492,
3820,
7850,
11383,
12,
3820,
7850,
11383,
24478,
12,
3820,
7850,
11383,
21722,
12,
3820,
7850,
11383,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
9551,
24022,
13411,
492,
19944,
24022,
13411,
12,
19944,
24022,
13411,
24478,
12,
19944,
24022,
13411,
21722,
12,
19944,
24022,
13411,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
21012,
1173,
1378,
12714,
492,
22379,
1173,
1378,
12714,
12,
22379,
1173,
1378,
12714,
24478,
12,
22379,
1173,
1378,
12714,
21722,
12,
22379,
1173,
1378,
12714,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
5278,
5535,
3325,
7850,
83,
492,
8730,
5535,
3325,
7850,
83,
12,
8730,
5535,
3325,
7850,
83,
24478,
12,
8730,
5535,
3325,
7850,
83,
21722,
12,
8730,
5535,
3325,
7850,
83,
6209,
13322,
9773,
11310,
199,
504,
29072,
15056,
14,
7424,
14,
11070,
1977,
14,
5535,
3325,
5142,
14,
10301,
1173,
492,
19149,
1173,
12,
19149,
1173,
24478,
12,
19149,
1173,
21722,
12,
19149,
1173,
6209,
13322,
9773,
11310,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
xtfxme/uwsgi
|
contrib/uwsgi-cache-monitor.py
|
2
|
4594
|
import mmap
import os
import struct
import array
import time
import sys
from optparse import OptionParser
class Cache:
def __init__(self, filename, cache_slots, block_size=65536, sample_sleep=1):
self.block_size = block_size
self.cache_slots = cache_slots
self.key_size = 2048
self.item_size = 2 + 2 + 4 + 8 + 8 + 8 + 8 + 8 + self.key_size
self.block_size_start = self.item_size * self.cache_slots
fd = os.open(filename, os.O_RDONLY)
self.cache_store = mmap.mmap(fd, 0, mmap.MAP_SHARED, mmap.PROT_READ)
self.sample_sleep = sample_sleep
self.samples = 0
self.history = []
self.cache_full = 0
self.cache_empty = 0
self.cache_items = 0
self.block_sizes = 0
def store_read_item_block(self, position):
pos = self.cache_store.tell()
# uwsgi cache stores cache entries first and then the blocks
self.cache_store.seek(self.block_size_start + (position * self.block_size))
buf = self.cache_store.read(self.block_size)
self.cache_store.seek(pos)
return buf
def store_read_item(self, position):
buf = self.cache_store.read(self.item_size)
fields = struct.unpack_from('@HHIQQQQQ2048c', buf)
key = array.array('c', fields[8:self.key_size+8]).tostring().rstrip('\x00')
if [x for x in key if x!= '\x00']:
buf = self.store_read_item_block(position)
value = array.array('c', buf).tostring().rstrip('\x00')
else:
value = ''
return (position, key, value, len(value))
def read(self):
data = [self.store_read_item(i) for i in range(self.cache_slots)]
self.cache_store.seek(0)
self.update_stats(data)
if self.sample_sleep:
time.sleep(self.sample_sleep)
return data
def update_stats(self, data):
# data is a list of (position, key, value, len(value)) tuples
items = len([1 for x in data if x[3] > 0])
self.cache_items += items
full, empty = items == self.cache_slots, items == 0
if full:
self.cache_full += 1
if empty:
self.cache_empty += 1
self.samples += 1
block_sizes = sum([x[3] for x in data])
self.block_sizes += block_sizes
self.history.append({'full': full, 'empty': empty, 'data': data, \
'items': items, 'block_sizes': block_sizes})
def dump(self):
return {
'samples': self.samples,
'history': self.history,
'cache_slots': self.cache_slots,
'sample_sleep': self.sample_sleep,
'cache_empty': self.cache_empty,
'cache_full': self.cache_full,
'cache_items': self.cache_items,
'block_sizes': self.block_sizes,
}
def show_dump(self):
d = self.dump()
print()
print("Recorded %d samples (%d second(s) sleep between samples)" % \
(d['samples'], d['sample_sleep']))
print("Cache empty %d times, full %d times, %.2f items on average" % \
(d['cache_empty'], d['cache_full'], d['cache_items'] / d['samples']))
print("Block size average size: %d bytes" % \
(d['block_sizes'] / d['cache_items'] * 8))
print("Data in cache average: %d bytes" % \
(d['block_sizes'] / d['samples'] * 8))
def main(options):
cache = Cache(options.cache_store, options.cache_slots, options.block_size,
options.sleep_time)
print("Recording...")
while True:
try:
data = cache.read()
except KeyboardInterrupt:
cache.show_dump()
sys.exit(0)
if __name__ == '__main__':
parser = OptionParser()
parser.add_option("-s", "--cache-slots", dest="cache_slots", type="int",
help="Slots available in the cache, uwsgi cache option")
parser.add_option("-c", "--cache-store", dest="cache_store", default="uwsgi.cache",
help="The filename of the cache store, uwsgi cache-store option. Default: uwsgi.cache")
parser.add_option("-b", "--block-size", dest="block_size", default=65536, type="int",
help="The size of the cache block, uwsgi cache-blocksize option. Default: 65536")
parser.add_option("-t", "--sleep-time", dest="sleep_time", default=1, type="int",
help="The time to sleep between each sample. Default: 1")
(options, args) = parser.parse_args()
if not options.cache_slots:
parser.error('Option -s / --cache-slots is mandatory')
main(options)
|
gpl-2.0
|
[
646,
21991,
199,
646,
747,
199,
646,
2702,
199,
646,
1625,
199,
646,
900,
199,
646,
984,
199,
504,
8691,
492,
13491,
199,
199,
533,
11977,
26,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
2581,
63,
7257,
12,
1853,
63,
890,
29,
10027,
1344,
12,
2690,
63,
4532,
29,
17,
304,
398,
291,
14,
1457,
63,
890,
275,
1853,
63,
890,
267,
291,
14,
1637,
63,
7257,
275,
2581,
63,
7257,
398,
291,
14,
498,
63,
890,
275,
18427,
267,
291,
14,
1053,
63,
890,
275,
499,
435,
499,
435,
841,
435,
1695,
435,
1695,
435,
1695,
435,
1695,
435,
1695,
435,
291,
14,
498,
63,
890,
267,
291,
14,
1457,
63,
890,
63,
928,
275,
291,
14,
1053,
63,
890,
627,
291,
14,
1637,
63,
7257,
398,
6111,
275,
747,
14,
1490,
8,
1501,
12,
747,
14,
47,
63,
15543,
10452,
9,
267,
291,
14,
1637,
63,
1617,
275,
21991,
14,
20671,
8,
2592,
12,
378,
12,
21991,
14,
5443,
63,
13772,
12,
21991,
14,
21998,
63,
5670,
9,
398,
291,
14,
3271,
63,
4532,
275,
2690,
63,
4532,
267,
291,
14,
3356,
275,
378,
267,
291,
14,
5570,
275,
942,
267,
291,
14,
1637,
63,
2861,
275,
378,
267,
291,
14,
1637,
63,
1667,
275,
378,
267,
291,
14,
1637,
63,
1744,
275,
378,
267,
291,
14,
1457,
63,
7723,
275,
378,
339,
347,
3877,
63,
739,
63,
1053,
63,
1457,
8,
277,
12,
3421,
304,
267,
2086,
275,
291,
14,
1637,
63,
1617,
14,
9974,
342,
267,
327,
399,
6508,
2581,
14086,
2581,
4811,
1642,
436,
2066,
314,
5664,
267,
291,
14,
1637,
63,
1617,
14,
5507,
8,
277,
14,
1457,
63,
890,
63,
928,
435,
334,
3124,
627,
291,
14,
1457,
63,
890,
430,
267,
4123,
275,
291,
14,
1637,
63,
1617,
14,
739,
8,
277,
14,
1457,
63,
890,
9,
267,
291,
14,
1637,
63,
1617,
14,
5507,
8,
1712,
9,
267,
372,
4123,
339,
347,
3877,
63,
739,
63,
1053,
8,
277,
12,
3421,
304,
267,
4123,
275,
291,
14,
1637,
63,
1617,
14,
739,
8,
277,
14,
1053,
63,
890,
9,
267,
1504,
275,
2702,
14,
5301,
63,
504,
16591,
10213,
41,
12917,
12917,
49,
18343,
67,
297,
4123,
9,
267,
790,
275,
1625,
14,
1144,
360,
67,
297,
1504,
59,
24,
26,
277,
14,
498,
63,
890,
11,
24,
6575,
14028,
1252,
6735,
2258,
88,
383,
358,
398,
340,
359,
88,
367,
671,
315,
790,
340,
671,
1111,
1557,
88,
383,
2565,
288,
4123,
275,
291,
14,
1617,
63,
739,
63,
1053,
63,
1457,
8,
3124,
9,
288,
574,
275,
1625,
14,
1144,
360,
67,
297,
4123,
680,
14028,
1252,
6735,
2258,
88,
383,
358,
267,
587,
26,
288,
574,
275,
2125,
267,
372,
334,
3124,
12,
790,
12,
574,
12,
822,
8,
585,
430,
339,
347,
1586,
8,
277,
304,
267,
666,
275,
359,
277,
14,
1617,
63,
739,
63,
1053,
8,
73,
9,
367,
284,
315,
1425,
8,
277,
14,
1637,
63,
7257,
1874,
267,
291,
14,
1637,
63,
1617,
14,
5507,
8,
16,
9,
267,
291,
14,
873,
63,
3200,
8,
576,
9,
267,
340,
291,
14,
3271,
63,
4532,
26,
288,
900,
14,
4532,
8,
277,
14,
3271,
63,
4532,
9,
267,
372,
666,
20950,
347,
1678,
63,
3200,
8,
277,
12,
666,
304,
267,
327,
666,
365,
282,
769,
402,
334,
3124,
12,
790,
12,
574,
12,
822,
8,
585,
430,
6346,
267,
2974,
275,
822,
779,
17,
367,
671,
315,
666,
340,
671,
59,
19,
61,
690,
378,
566,
267,
291,
14,
1637,
63,
1744,
847,
2974,
267,
2615,
12,
2701,
275,
2974,
508,
291,
14,
1637,
63,
7257,
12,
2974,
508,
378,
267,
340,
2615,
26,
288,
291,
14,
1637,
63,
2861,
847,
413,
267,
340,
2701,
26,
288,
291,
14,
1637,
63,
1667,
847,
413,
267,
291,
14,
3356,
847,
413,
267,
1853,
63,
7723,
275,
3089,
779,
88,
59,
19,
61,
367,
671,
315,
666,
566,
267,
291,
14,
1457,
63,
7723,
847,
1853,
63,
7723,
267,
291,
14,
5570,
14,
740,
3252,
2861,
356,
2615,
12,
283,
1667,
356,
2701,
12,
283,
576,
356,
666,
12,
971,
288,
283,
1744,
356,
2974,
12,
283,
1457,
63,
7723,
356,
1853,
63,
7723,
1552,
339,
347,
5461,
8,
277,
304,
267,
372,
469,
288,
283,
3356,
356,
291,
14,
3356,
12,
288,
283,
5570,
356,
291,
14,
5570,
12,
288,
283,
1637,
63,
7257,
356,
291,
14,
1637,
63,
7257,
12,
288,
283,
3271,
63,
4532,
356,
291,
14,
3271,
63,
4532,
12,
7205,
283,
1637,
63,
1667,
356,
291,
14,
1637,
63,
1667,
12,
288,
283,
1637,
63,
2861,
356,
291,
14,
1637,
63,
2861,
12,
288,
283,
1637,
63,
1744,
356,
291,
14,
1637,
63,
1744,
12,
288,
283,
1457,
63,
7723,
356,
291,
14,
1457,
63,
7723,
12,
268,
789,
339,
347,
2498,
63,
2724,
8,
277,
304,
267,
366,
275,
291,
14,
2724,
342,
267,
870,
342,
267,
870,
480,
497,
15402,
450,
68,
5845,
4366,
68,
3499,
8,
83,
9,
9435,
3382,
5845,
2924,
450,
971,
288,
334,
68,
459,
3356,
995,
366,
459,
3271,
63,
4532,
5156,
267,
870,
480,
4437,
2701,
450,
68,
5431,
12,
2615,
450,
68,
5431,
12,
10536,
18,
70,
2974,
641,
8095,
2,
450,
971,
288,
334,
68,
459,
1637,
63,
1667,
995,
366,
459,
1637,
63,
2861,
995,
366,
459,
1637,
63,
1744,
418,
1182,
366,
459,
3356,
5156,
267,
870,
480,
3142,
1568,
8095,
1568,
26,
450,
68,
2783,
2,
450,
971,
288,
334,
68,
459,
1457,
63,
7723,
418,
1182,
366,
459,
1637,
63,
1744,
418,
627,
1695,
430,
267,
870,
480,
1451,
315,
2581,
8095,
26,
450,
68,
2783,
2,
450,
971,
288,
334,
68,
459,
1457,
63,
7723,
418,
1182,
366,
459,
3356,
418,
627,
1695,
430,
199,
199,
318,
2446,
8,
1419,
304,
272,
2581,
275,
11977,
8,
1419,
14,
1637,
63,
1617,
12,
1511,
14,
1637,
63,
7257,
12,
1511,
14,
1457,
63,
890,
12,
267,
1511,
14,
4532,
63,
521,
9,
272,
870,
480,
26040,
12594,
272,
1830,
715,
26,
267,
862,
26,
288,
666,
275,
2581,
14,
739,
342,
267,
871,
13483,
26,
288,
2581,
14
] |
[
21991,
199,
646,
747,
199,
646,
2702,
199,
646,
1625,
199,
646,
900,
199,
646,
984,
199,
504,
8691,
492,
13491,
199,
199,
533,
11977,
26,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
2581,
63,
7257,
12,
1853,
63,
890,
29,
10027,
1344,
12,
2690,
63,
4532,
29,
17,
304,
398,
291,
14,
1457,
63,
890,
275,
1853,
63,
890,
267,
291,
14,
1637,
63,
7257,
275,
2581,
63,
7257,
398,
291,
14,
498,
63,
890,
275,
18427,
267,
291,
14,
1053,
63,
890,
275,
499,
435,
499,
435,
841,
435,
1695,
435,
1695,
435,
1695,
435,
1695,
435,
1695,
435,
291,
14,
498,
63,
890,
267,
291,
14,
1457,
63,
890,
63,
928,
275,
291,
14,
1053,
63,
890,
627,
291,
14,
1637,
63,
7257,
398,
6111,
275,
747,
14,
1490,
8,
1501,
12,
747,
14,
47,
63,
15543,
10452,
9,
267,
291,
14,
1637,
63,
1617,
275,
21991,
14,
20671,
8,
2592,
12,
378,
12,
21991,
14,
5443,
63,
13772,
12,
21991,
14,
21998,
63,
5670,
9,
398,
291,
14,
3271,
63,
4532,
275,
2690,
63,
4532,
267,
291,
14,
3356,
275,
378,
267,
291,
14,
5570,
275,
942,
267,
291,
14,
1637,
63,
2861,
275,
378,
267,
291,
14,
1637,
63,
1667,
275,
378,
267,
291,
14,
1637,
63,
1744,
275,
378,
267,
291,
14,
1457,
63,
7723,
275,
378,
339,
347,
3877,
63,
739,
63,
1053,
63,
1457,
8,
277,
12,
3421,
304,
267,
2086,
275,
291,
14,
1637,
63,
1617,
14,
9974,
342,
267,
327,
399,
6508,
2581,
14086,
2581,
4811,
1642,
436,
2066,
314,
5664,
267,
291,
14,
1637,
63,
1617,
14,
5507,
8,
277,
14,
1457,
63,
890,
63,
928,
435,
334,
3124,
627,
291,
14,
1457,
63,
890,
430,
267,
4123,
275,
291,
14,
1637,
63,
1617,
14,
739,
8,
277,
14,
1457,
63,
890,
9,
267,
291,
14,
1637,
63,
1617,
14,
5507,
8,
1712,
9,
267,
372,
4123,
339,
347,
3877,
63,
739,
63,
1053,
8,
277,
12,
3421,
304,
267,
4123,
275,
291,
14,
1637,
63,
1617,
14,
739,
8,
277,
14,
1053,
63,
890,
9,
267,
1504,
275,
2702,
14,
5301,
63,
504,
16591,
10213,
41,
12917,
12917,
49,
18343,
67,
297,
4123,
9,
267,
790,
275,
1625,
14,
1144,
360,
67,
297,
1504,
59,
24,
26,
277,
14,
498,
63,
890,
11,
24,
6575,
14028,
1252,
6735,
2258,
88,
383,
358,
398,
340,
359,
88,
367,
671,
315,
790,
340,
671,
1111,
1557,
88,
383,
2565,
288,
4123,
275,
291,
14,
1617,
63,
739,
63,
1053,
63,
1457,
8,
3124,
9,
288,
574,
275,
1625,
14,
1144,
360,
67,
297,
4123,
680,
14028,
1252,
6735,
2258,
88,
383,
358,
267,
587,
26,
288,
574,
275,
2125,
267,
372,
334,
3124,
12,
790,
12,
574,
12,
822,
8,
585,
430,
339,
347,
1586,
8,
277,
304,
267,
666,
275,
359,
277,
14,
1617,
63,
739,
63,
1053,
8,
73,
9,
367,
284,
315,
1425,
8,
277,
14,
1637,
63,
7257,
1874,
267,
291,
14,
1637,
63,
1617,
14,
5507,
8,
16,
9,
267,
291,
14,
873,
63,
3200,
8,
576,
9,
267,
340,
291,
14,
3271,
63,
4532,
26,
288,
900,
14,
4532,
8,
277,
14,
3271,
63,
4532,
9,
267,
372,
666,
20950,
347,
1678,
63,
3200,
8,
277,
12,
666,
304,
267,
327,
666,
365,
282,
769,
402,
334,
3124,
12,
790,
12,
574,
12,
822,
8,
585,
430,
6346,
267,
2974,
275,
822,
779,
17,
367,
671,
315,
666,
340,
671,
59,
19,
61,
690,
378,
566,
267,
291,
14,
1637,
63,
1744,
847,
2974,
267,
2615,
12,
2701,
275,
2974,
508,
291,
14,
1637,
63,
7257,
12,
2974,
508,
378,
267,
340,
2615,
26,
288,
291,
14,
1637,
63,
2861,
847,
413,
267,
340,
2701,
26,
288,
291,
14,
1637,
63,
1667,
847,
413,
267,
291,
14,
3356,
847,
413,
267,
1853,
63,
7723,
275,
3089,
779,
88,
59,
19,
61,
367,
671,
315,
666,
566,
267,
291,
14,
1457,
63,
7723,
847,
1853,
63,
7723,
267,
291,
14,
5570,
14,
740,
3252,
2861,
356,
2615,
12,
283,
1667,
356,
2701,
12,
283,
576,
356,
666,
12,
971,
288,
283,
1744,
356,
2974,
12,
283,
1457,
63,
7723,
356,
1853,
63,
7723,
1552,
339,
347,
5461,
8,
277,
304,
267,
372,
469,
288,
283,
3356,
356,
291,
14,
3356,
12,
288,
283,
5570,
356,
291,
14,
5570,
12,
288,
283,
1637,
63,
7257,
356,
291,
14,
1637,
63,
7257,
12,
288,
283,
3271,
63,
4532,
356,
291,
14,
3271,
63,
4532,
12,
7205,
283,
1637,
63,
1667,
356,
291,
14,
1637,
63,
1667,
12,
288,
283,
1637,
63,
2861,
356,
291,
14,
1637,
63,
2861,
12,
288,
283,
1637,
63,
1744,
356,
291,
14,
1637,
63,
1744,
12,
288,
283,
1457,
63,
7723,
356,
291,
14,
1457,
63,
7723,
12,
268,
789,
339,
347,
2498,
63,
2724,
8,
277,
304,
267,
366,
275,
291,
14,
2724,
342,
267,
870,
342,
267,
870,
480,
497,
15402,
450,
68,
5845,
4366,
68,
3499,
8,
83,
9,
9435,
3382,
5845,
2924,
450,
971,
288,
334,
68,
459,
3356,
995,
366,
459,
3271,
63,
4532,
5156,
267,
870,
480,
4437,
2701,
450,
68,
5431,
12,
2615,
450,
68,
5431,
12,
10536,
18,
70,
2974,
641,
8095,
2,
450,
971,
288,
334,
68,
459,
1637,
63,
1667,
995,
366,
459,
1637,
63,
2861,
995,
366,
459,
1637,
63,
1744,
418,
1182,
366,
459,
3356,
5156,
267,
870,
480,
3142,
1568,
8095,
1568,
26,
450,
68,
2783,
2,
450,
971,
288,
334,
68,
459,
1457,
63,
7723,
418,
1182,
366,
459,
1637,
63,
1744,
418,
627,
1695,
430,
267,
870,
480,
1451,
315,
2581,
8095,
26,
450,
68,
2783,
2,
450,
971,
288,
334,
68,
459,
1457,
63,
7723,
418,
1182,
366,
459,
3356,
418,
627,
1695,
430,
199,
199,
318,
2446,
8,
1419,
304,
272,
2581,
275,
11977,
8,
1419,
14,
1637,
63,
1617,
12,
1511,
14,
1637,
63,
7257,
12,
1511,
14,
1457,
63,
890,
12,
267,
1511,
14,
4532,
63,
521,
9,
272,
870,
480,
26040,
12594,
272,
1830,
715,
26,
267,
862,
26,
288,
666,
275,
2581,
14,
739,
342,
267,
871,
13483,
26,
288,
2581,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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seconds, Config, int64x64_t
import ns.core
import ns.network
import ns.internet
import ns.mobility
import ns.csma
import ns.applications
class TestSimulator(unittest.TestCase):
def testScheduleNow(self):
def callback(args):
self._args_received = args
self._cb_time = Simulator.Now()
Simulator.Destroy()
self._args_received = None
self._cb_time = None
Simulator.ScheduleNow(callback, "args")
Simulator.Run()
self.assertEqual(self._args_received, "args")
self.assertEqual(self._cb_time.GetSeconds(), 0.0)
def testSchedule(self):
def callback(args):
self._args_received = args
self._cb_time = Simulator.Now()
Simulator.Destroy()
self._args_received = None
self._cb_time = None
Simulator.Schedule(Seconds(123), callback, "args")
Simulator.Run()
self.assertEqual(self._args_received, "args")
self.assertEqual(self._cb_time.GetSeconds(), 123.0)
def testScheduleDestroy(self):
def callback(args):
self._args_received = args
self._cb_time = Simulator.Now()
Simulator.Destroy()
self._args_received = None
self._cb_time = None
def null(): pass
Simulator.Schedule(Seconds(123), null)
Simulator.ScheduleDestroy(callback, "args")
Simulator.Run()
Simulator.Destroy()
self.assertEqual(self._args_received, "args")
self.assertEqual(self._cb_time.GetSeconds(), 123.0)
def testScheduleWithContext(self):
def callback(context, args):
self._context_received = context
self._args_received = args
self._cb_time = Simulator.Now()
Simulator.Destroy()
self._args_received = None
self._cb_time = None
self._context_received = None
Simulator.ScheduleWithContext(54321, Seconds(123), callback, "args")
Simulator.Run()
self.assertEqual(self._context_received, 54321)
self.assertEqual(self._args_received, "args")
self.assertEqual(self._cb_time.GetSeconds(), 123.0)
def testTimeComparison(self):
self.assert_(Seconds(123) == Seconds(123))
self.assert_(Seconds(123) >= Seconds(123))
self.assert_(Seconds(123) <= Seconds(123))
self.assert_(Seconds(124) > Seconds(123))
self.assert_(Seconds(123) < Seconds(124))
def testTimeNumericOperations(self):
self.assertEqual(Seconds(10) + Seconds(5), Seconds(15))
self.assertEqual(Seconds(10) - Seconds(5), Seconds(5))
v1 = int64x64_t(5.0)*int64x64_t(10)
self.assertEqual(v1, int64x64_t(50))
def testConfig(self):
Config.SetDefault("ns3::OnOffApplication::PacketSize", ns.core.UintegerValue(123))
# hm.. no Config.Get?
def testSocket(self):
node = ns.network.Node()
internet = ns.internet.InternetStackHelper()
internet.Install(node)
self._received_packet = None
def rx_callback(socket):
assert self._received_packet is None
self._received_packet = socket.Recv()
sink = ns.network.Socket.CreateSocket(node, ns.core.TypeId.LookupByName("ns3::UdpSocketFactory"))
sink.Bind(ns.network.InetSocketAddress(ns.network.Ipv4Address.GetAny(), 80))
sink.SetRecvCallback(rx_callback)
source = ns.network.Socket.CreateSocket(node, ns.core.TypeId.LookupByName("ns3::UdpSocketFactory"))
source.SendTo(ns.network.Packet(19), 0, ns.network.InetSocketAddress(ns.network.Ipv4Address("127.0.0.1"), 80))
Simulator.Run()
self.assert_(self._received_packet is not None)
self.assertEqual(self._received_packet.GetSize(), 19)
def testAttributes(self):
##
## Yes, I know, the GetAttribute interface for Python is
## horrible, we should fix this soon, I hope.
##
queue = ns.network.DropTailQueue()
queue.SetAttribute("MaxPackets", ns.core.UintegerValue(123456))
limit = ns.core.UintegerValue()
queue.GetAttribute("MaxPackets", limit)
self.assertEqual(limit.Get(), 123456)
## -- object pointer values
mobility = ns.mobility.RandomWaypointMobilityModel()
ptr = ns.core.PointerValue()
mobility.GetAttribute("PositionAllocator", ptr)
self.assertEqual(ptr.GetObject(), None)
pos = ns.mobility.ListPositionAllocator()
mobility.SetAttribute("PositionAllocator", ns.core.PointerValue(pos))
ptr = ns.core.PointerValue()
mobility.GetAttribute("PositionAllocator", ptr)
self.assert_(ptr.GetObject() is not None)
def testIdentity(self):
csma = ns.csma.CsmaNetDevice()
channel = ns.csma.CsmaChannel()
csma.Attach(channel)
c1 = csma.GetChannel()
c2 = csma.GetChannel()
self.assert_(c1 is c2)
def testTypeId(self):
typeId1 = ns.core.TypeId.LookupByNameFailSafe("ns3::UdpSocketFactory")
self.assertEqual(typeId1.GetName (), "ns3::UdpSocketFactory")
self.assertRaises(KeyError, ns.core.TypeId.LookupByNameFailSafe, "__InvalidTypeName__")
def testCommandLine(self):
cmd = ns.core.CommandLine()
cmd.AddValue("Test1", "this is a test option")
cmd.AddValue("Test2", "this is a test option")
cmd.AddValue("Test3", "this is a test option", variable="test_xxx")
cmd.Test1 = None
cmd.Test2 = None
cmd.test_xxx = None
class Foo:
pass
foo = Foo()
foo.test_foo = None
cmd.AddValue("Test4", "this is a test option", variable="test_foo", namespace=foo)
cmd.Parse(["python", "--Test1=value1", "--Test2=value2", "--Test3=123", "--Test4=xpto"])
self.assertEqual(cmd.Test1, "value1")
self.assertEqual(cmd.Test2, "value2")
self.assertEqual(cmd.test_xxx, "123")
self.assertEqual(foo.test_foo, "xpto")
def testSubclass(self):
class MyNode(ns.network.Node):
def __init__(self):
super(MyNode, self).__init__()
node = MyNode()
if __name__ == '__main__':
unittest.main()
|
gpl-2.0
|
[
646,
2882,
199,
504,
700,
14,
1018,
492,
10751,
6109,
12,
3240,
2776,
12,
4094,
12,
1109,
772,
88,
772,
63,
84,
199,
646,
700,
14,
1018,
199,
646,
700,
14,
1200,
199,
646,
700,
14,
4901,
199,
646,
700,
14,
16364,
199,
646,
700,
14,
1259,
391,
199,
646,
700,
14,
15853,
421,
199,
533,
1379,
11397,
8,
2796,
14,
1746,
304,
339,
347,
511,
15535,
14351,
8,
277,
304,
267,
347,
3233,
8,
589,
304,
288,
291,
423,
589,
63,
9226,
275,
1249,
288,
291,
423,
2894,
63,
521,
275,
10751,
6109,
14,
14351,
342,
267,
10751,
6109,
14,
14704,
342,
267,
291,
423,
589,
63,
9226,
275,
488,
267,
291,
423,
2894,
63,
521,
275,
488,
267,
10751,
6109,
14,
15535,
14351,
8,
3058,
12,
298,
589,
531,
267,
10751,
6109,
14,
2540,
342,
267,
291,
14,
629,
8,
277,
423,
589,
63,
9226,
12,
298,
589,
531,
267,
291,
14,
629,
8,
277,
423,
2894,
63,
521,
14,
1002,
13165,
1062,
378,
14,
16,
9,
339,
347,
511,
15535,
8,
277,
304,
267,
347,
3233,
8,
589,
304,
288,
291,
423,
589,
63,
9226,
275,
1249,
288,
291,
423,
2894,
63,
521,
275,
10751,
6109,
14,
14351,
342,
267,
10751,
6109,
14,
14704,
342,
267,
291,
423,
589,
63,
9226,
275,
488,
267,
291,
423,
2894,
63,
521,
275,
488,
267,
10751,
6109,
14,
15535,
8,
13165,
8,
4288,
395,
3233,
12,
298,
589,
531,
267,
10751,
6109,
14,
2540,
342,
267,
291,
14,
629,
8,
277,
423,
589,
63,
9226,
12,
298,
589,
531,
267,
291,
14,
629,
8,
277,
423,
2894,
63,
521,
14,
1002,
13165,
1062,
11869,
14,
16,
9,
339,
347,
511,
15535,
14704,
8,
277,
304,
267,
347,
3233,
8,
589,
304,
288,
291,
423,
589,
63,
9226,
275,
1249,
288,
291,
423,
2894,
63,
521,
275,
10751,
6109,
14,
14351,
342,
267,
10751,
6109,
14,
14704,
342,
267,
291,
423,
589,
63,
9226,
275,
488,
267,
291,
423,
2894,
63,
521,
275,
488,
267,
347,
2973,
837,
986,
267,
10751,
6109,
14,
15535,
8,
13165,
8,
4288,
395,
2973,
9,
267,
10751,
6109,
14,
15535,
14704,
8,
3058,
12,
298,
589,
531,
267,
10751,
6109,
14,
2540,
342,
267,
10751,
6109,
14,
14704,
342,
267,
291,
14,
629,
8,
277,
423,
589,
63,
9226,
12,
298,
589,
531,
267,
291,
14,
629,
8,
277,
423,
2894,
63,
521,
14,
1002,
13165,
1062,
11869,
14,
16,
9,
339,
347,
511,
15535,
3007,
2998,
8,
277,
304,
267,
347,
3233,
8,
1100,
12,
1249,
304,
288,
291,
423,
1100,
63,
9226,
275,
1067,
288,
291,
423,
589,
63,
9226,
275,
1249,
288,
291,
423,
2894,
63,
521,
275,
10751,
6109,
14,
14351,
342,
267,
10751,
6109,
14,
14704,
342,
267,
291,
423,
589,
63,
9226,
275,
488,
267,
291,
423,
2894,
63,
521,
275,
488,
267,
291,
423,
1100,
63,
9226,
275,
488,
267,
10751,
6109,
14,
15535,
3007,
2998,
8,
1477,
12638,
12,
3240,
2776,
8,
4288,
395,
3233,
12,
298,
589,
531,
267,
10751,
6109,
14,
2540,
342,
267,
291,
14,
629,
8,
277,
423,
1100,
63,
9226,
12,
959,
10657,
17,
9,
267,
291,
14,
629,
8,
277,
423,
589,
63,
9226,
12,
298,
589,
531,
267,
291,
14,
629,
8,
277,
423,
2894,
63,
521,
14,
1002,
13165,
1062,
11869,
14,
16,
9,
339,
347,
511,
1366,
25834,
8,
277,
304,
267,
291,
14,
479,
2531,
13165,
8,
4288,
9,
508,
3240,
2776,
8,
4288,
430,
267,
291,
14,
479,
2531,
13165,
8,
4288,
9,
2356,
3240,
2776,
8,
4288,
430,
267,
291,
14,
479,
2531,
13165,
8,
4288,
9,
2695,
3240,
2776,
8,
4288,
430,
267,
291,
14,
479,
2531,
13165,
8,
7214,
9,
690,
3240,
2776,
8,
4288,
430,
267,
291,
14,
479,
2531,
13165,
8,
4288,
9,
665,
3240,
2776,
8,
7214,
430,
339,
347,
511,
1366,
14687,
12929,
8,
277,
304,
267,
291,
14,
629,
8,
13165,
8,
709,
9,
435,
3240,
2776,
8,
21,
395,
3240,
2776,
8,
1046,
430,
267,
291,
14,
629,
8,
13165,
8,
709,
9,
446,
3240,
2776,
8,
21,
395,
3240,
2776,
8,
21,
430,
2728,
373,
17,
275,
1109,
772,
88,
772,
63,
84,
8,
21,
14,
16,
3342,
442,
772,
88,
772,
63,
84,
8,
709,
9,
267,
291,
14,
629,
8,
86,
17,
12,
1109,
772,
88,
772,
63,
84,
8,
1400,
430,
339,
347,
511,
2028,
8,
277,
304,
267,
4094,
14,
1084,
2698,
480,
561,
19,
447,
3314,
5195,
5039,
447,
2726,
2320,
401,
700,
14,
1018,
14,
28676,
8,
4288,
430,
267,
327,
394,
77,
703,
949,
4094,
14,
1002,
31,
339,
347,
511,
3869,
8,
277,
304,
267,
1031,
275,
700,
14,
1200,
14,
1716,
342,
267,
21408,
275,
700,
14,
4901,
14,
29820,
4851,
4433,
342,
267,
21408,
14,
8154,
8,
932,
9,
267,
291,
423,
9226,
63,
6253,
275,
488,
398,
347,
12951,
63,
3058,
8,
3450,
304,
288,
702,
291,
423,
9226,
63,
6253,
365,
488,
288,
291,
423,
9226,
63,
6253,
275,
2838,
14,
15838,
342,
398,
19241,
275,
700,
14,
1200,
14,
3869,
14,
2499,
3869,
8,
932,
12,
700,
14,
1018,
14,
2568,
14,
7521,
11190,
480,
561,
19,
447,
22086,
3869,
2927,
2237,
267,
19241,
14,
8198,
8,
561,
14,
1200,
14,
23741,
8,
561,
14,
1200,
14,
1762,
20,
1476,
14,
1002,
9874,
1062,
5939,
430,
267,
19241,
14,
1084,
15838,
2806,
8,
6872,
63,
3058,
9,
398,
1350,
275,
700,
14,
1200,
14,
3869,
14,
2499,
3869,
8,
932,
12,
700,
14,
1018,
14,
2568,
14,
7521,
11190,
480,
561,
19,
447,
22086,
3869,
2927,
2237,
267,
1350,
14,
6795,
1378,
8,
561,
14,
1200,
14,
2726,
8,
1167,
395,
378,
12,
700,
14,
1200,
14,
23741,
8,
561,
14,
1200,
14,
1762,
20,
1476,
480,
4195,
14,
16,
14,
16,
14,
17,
1288,
5939,
430,
398,
10751,
6109,
14,
2540,
342,
267,
291,
14,
479,
2531,
277,
423,
9226,
63,
6253,
365,
440,
488,
9,
267,
291,
14,
629,
8,
277,
423,
9226,
63,
6253,
14,
21817,
1062,
5851,
9,
2378,
347,
511,
5379,
8,
277,
304,
267,
925,
267,
925,
29715,
12,
473,
5715
] |
[
2882,
199,
504,
700,
14,
1018,
492,
10751,
6109,
12,
3240,
2776,
12,
4094,
12,
1109,
772,
88,
772,
63,
84,
199,
646,
700,
14,
1018,
199,
646,
700,
14,
1200,
199,
646,
700,
14,
4901,
199,
646,
700,
14,
16364,
199,
646,
700,
14,
1259,
391,
199,
646,
700,
14,
15853,
421,
199,
533,
1379,
11397,
8,
2796,
14,
1746,
304,
339,
347,
511,
15535,
14351,
8,
277,
304,
267,
347,
3233,
8,
589,
304,
288,
291,
423,
589,
63,
9226,
275,
1249,
288,
291,
423,
2894,
63,
521,
275,
10751,
6109,
14,
14351,
342,
267,
10751,
6109,
14,
14704,
342,
267,
291,
423,
589,
63,
9226,
275,
488,
267,
291,
423,
2894,
63,
521,
275,
488,
267,
10751,
6109,
14,
15535,
14351,
8,
3058,
12,
298,
589,
531,
267,
10751,
6109,
14,
2540,
342,
267,
291,
14,
629,
8,
277,
423,
589,
63,
9226,
12,
298,
589,
531,
267,
291,
14,
629,
8,
277,
423,
2894,
63,
521,
14,
1002,
13165,
1062,
378,
14,
16,
9,
339,
347,
511,
15535,
8,
277,
304,
267,
347,
3233,
8,
589,
304,
288,
291,
423,
589,
63,
9226,
275,
1249,
288,
291,
423,
2894,
63,
521,
275,
10751,
6109,
14,
14351,
342,
267,
10751,
6109,
14,
14704,
342,
267,
291,
423,
589,
63,
9226,
275,
488,
267,
291,
423,
2894,
63,
521,
275,
488,
267,
10751,
6109,
14,
15535,
8,
13165,
8,
4288,
395,
3233,
12,
298,
589,
531,
267,
10751,
6109,
14,
2540,
342,
267,
291,
14,
629,
8,
277,
423,
589,
63,
9226,
12,
298,
589,
531,
267,
291,
14,
629,
8,
277,
423,
2894,
63,
521,
14,
1002,
13165,
1062,
11869,
14,
16,
9,
339,
347,
511,
15535,
14704,
8,
277,
304,
267,
347,
3233,
8,
589,
304,
288,
291,
423,
589,
63,
9226,
275,
1249,
288,
291,
423,
2894,
63,
521,
275,
10751,
6109,
14,
14351,
342,
267,
10751,
6109,
14,
14704,
342,
267,
291,
423,
589,
63,
9226,
275,
488,
267,
291,
423,
2894,
63,
521,
275,
488,
267,
347,
2973,
837,
986,
267,
10751,
6109,
14,
15535,
8,
13165,
8,
4288,
395,
2973,
9,
267,
10751,
6109,
14,
15535,
14704,
8,
3058,
12,
298,
589,
531,
267,
10751,
6109,
14,
2540,
342,
267,
10751,
6109,
14,
14704,
342,
267,
291,
14,
629,
8,
277,
423,
589,
63,
9226,
12,
298,
589,
531,
267,
291,
14,
629,
8,
277,
423,
2894,
63,
521,
14,
1002,
13165,
1062,
11869,
14,
16,
9,
339,
347,
511,
15535,
3007,
2998,
8,
277,
304,
267,
347,
3233,
8,
1100,
12,
1249,
304,
288,
291,
423,
1100,
63,
9226,
275,
1067,
288,
291,
423,
589,
63,
9226,
275,
1249,
288,
291,
423,
2894,
63,
521,
275,
10751,
6109,
14,
14351,
342,
267,
10751,
6109,
14,
14704,
342,
267,
291,
423,
589,
63,
9226,
275,
488,
267,
291,
423,
2894,
63,
521,
275,
488,
267,
291,
423,
1100,
63,
9226,
275,
488,
267,
10751,
6109,
14,
15535,
3007,
2998,
8,
1477,
12638,
12,
3240,
2776,
8,
4288,
395,
3233,
12,
298,
589,
531,
267,
10751,
6109,
14,
2540,
342,
267,
291,
14,
629,
8,
277,
423,
1100,
63,
9226,
12,
959,
10657,
17,
9,
267,
291,
14,
629,
8,
277,
423,
589,
63,
9226,
12,
298,
589,
531,
267,
291,
14,
629,
8,
277,
423,
2894,
63,
521,
14,
1002,
13165,
1062,
11869,
14,
16,
9,
339,
347,
511,
1366,
25834,
8,
277,
304,
267,
291,
14,
479,
2531,
13165,
8,
4288,
9,
508,
3240,
2776,
8,
4288,
430,
267,
291,
14,
479,
2531,
13165,
8,
4288,
9,
2356,
3240,
2776,
8,
4288,
430,
267,
291,
14,
479,
2531,
13165,
8,
4288,
9,
2695,
3240,
2776,
8,
4288,
430,
267,
291,
14,
479,
2531,
13165,
8,
7214,
9,
690,
3240,
2776,
8,
4288,
430,
267,
291,
14,
479,
2531,
13165,
8,
4288,
9,
665,
3240,
2776,
8,
7214,
430,
339,
347,
511,
1366,
14687,
12929,
8,
277,
304,
267,
291,
14,
629,
8,
13165,
8,
709,
9,
435,
3240,
2776,
8,
21,
395,
3240,
2776,
8,
1046,
430,
267,
291,
14,
629,
8,
13165,
8,
709,
9,
446,
3240,
2776,
8,
21,
395,
3240,
2776,
8,
21,
430,
2728,
373,
17,
275,
1109,
772,
88,
772,
63,
84,
8,
21,
14,
16,
3342,
442,
772,
88,
772,
63,
84,
8,
709,
9,
267,
291,
14,
629,
8,
86,
17,
12,
1109,
772,
88,
772,
63,
84,
8,
1400,
430,
339,
347,
511,
2028,
8,
277,
304,
267,
4094,
14,
1084,
2698,
480,
561,
19,
447,
3314,
5195,
5039,
447,
2726,
2320,
401,
700,
14,
1018,
14,
28676,
8,
4288,
430,
267,
327,
394,
77,
703,
949,
4094,
14,
1002,
31,
339,
347,
511,
3869,
8,
277,
304,
267,
1031,
275,
700,
14,
1200,
14,
1716,
342,
267,
21408,
275,
700,
14,
4901,
14,
29820,
4851,
4433,
342,
267,
21408,
14,
8154,
8,
932,
9,
267,
291,
423,
9226,
63,
6253,
275,
488,
398,
347,
12951,
63,
3058,
8,
3450,
304,
288,
702,
291,
423,
9226,
63,
6253,
365,
488,
288,
291,
423,
9226,
63,
6253,
275,
2838,
14,
15838,
342,
398,
19241,
275,
700,
14,
1200,
14,
3869,
14,
2499,
3869,
8,
932,
12,
700,
14,
1018,
14,
2568,
14,
7521,
11190,
480,
561,
19,
447,
22086,
3869,
2927,
2237,
267,
19241,
14,
8198,
8,
561,
14,
1200,
14,
23741,
8,
561,
14,
1200,
14,
1762,
20,
1476,
14,
1002,
9874,
1062,
5939,
430,
267,
19241,
14,
1084,
15838,
2806,
8,
6872,
63,
3058,
9,
398,
1350,
275,
700,
14,
1200,
14,
3869,
14,
2499,
3869,
8,
932,
12,
700,
14,
1018,
14,
2568,
14,
7521,
11190,
480,
561,
19,
447,
22086,
3869,
2927,
2237,
267,
1350,
14,
6795,
1378,
8,
561,
14,
1200,
14,
2726,
8,
1167,
395,
378,
12,
700,
14,
1200,
14,
23741,
8,
561,
14,
1200,
14,
1762,
20,
1476,
480,
4195,
14,
16,
14,
16,
14,
17,
1288,
5939,
430,
398,
10751,
6109,
14,
2540,
342,
267,
291,
14,
479,
2531,
277,
423,
9226,
63,
6253,
365,
440,
488,
9,
267,
291,
14,
629,
8,
277,
423,
9226,
63,
6253,
14,
21817,
1062,
5851,
9,
2378,
347,
511,
5379,
8,
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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
imtapps/django-dynamic-validation
|
dynamic_validation/templatetags/dynamic_validation_tags.py
|
1
|
1727
|
from django.template import Library, Node, Variable
from django.template.base import TemplateSyntaxError, VariableDoesNotExist
from dynamic_validation import models
register = Library()
__all__ = ('violations_for', )
@register.tag
def violations_for(parser, token):
"""
usage:
{% violations_for trigger_model as var_name optional_silent_indicator_variable %}
"""
bits = token.split_contents()
if len(bits) < 4 or bits[2] != 'as':
raise TemplateSyntaxError("Must pass 'trigger_model as var_name' to %s tag" % bits[0])
node_args = [bits[1], bits[3]]
if len(bits) == 5:
node_args.append(bits[4])
return ViolationsForNode(*node_args)
class ViolationsForNode(Node):
def __init__(self, trigger_model, var_name, silent_indicator=None):
self.trigger_model = Variable(trigger_model)
self.var_name = var_name
self.silent_indicator = silent_indicator
def render(self, context):
silent_indicator = Variable(self.silent_indicator).resolve(context) if self.silent_indicator else None
try:
trigger_model = self.trigger_model.resolve(context)
violations = models.Violation.objects.get_by_trigger_model(trigger_model)
if silent_indicator:
violations = [v for v in violations if not v.rule.dynamic_fields.get('silent')]
context[self.var_name] = models.ViolationsWrapper(violations)
except VariableDoesNotExist:
pass
return ''
|
bsd-2-clause
|
[
199,
504,
1639,
14,
1160,
492,
11243,
12,
5013,
12,
4905,
199,
504,
1639,
14,
1160,
14,
1095,
492,
17762,
12,
4905,
7400,
199,
199,
504,
8336,
63,
6136,
492,
1709,
421,
199,
2683,
275,
11243,
342,
199,
199,
363,
452,
363,
275,
661,
433,
22938,
63,
509,
297,
776,
421,
199,
32,
2683,
14,
1450,
199,
318,
1321,
22938,
63,
509,
8,
2087,
12,
1526,
304,
272,
408,
272,
4503,
26,
272,
7749,
1321,
22938,
63,
509,
6804,
63,
1238,
465,
2729,
63,
354,
2716,
63,
14434,
63,
15785,
63,
1975,
3674,
272,
408,
272,
5821,
275,
1526,
14,
1294,
63,
4407,
342,
272,
340,
822,
8,
5609,
9,
665,
841,
503,
5821,
59,
18,
61,
1137,
283,
305,
356,
267,
746,
17762,
480,
13757,
986,
283,
7631,
63,
1238,
465,
2729,
63,
354,
7,
370,
450,
83,
1947,
2,
450,
5821,
59,
16,
566,
272,
1031,
63,
589,
275,
359,
5609,
59,
17,
467,
5821,
59,
19,
2677,
272,
340,
822,
8,
5609,
9,
508,
959,
26,
267,
1031,
63,
589,
14,
740,
8,
5609,
59,
20,
566,
272,
372,
6561,
22938,
1858,
1716,
2031,
932,
63,
589,
9,
421,
199,
533,
6561,
22938,
1858,
1716,
8,
1716,
304,
339,
347,
636,
826,
721,
277,
12,
6804,
63,
1238,
12,
2729,
63,
354,
12,
10866,
63,
15785,
29,
403,
304,
267,
291,
14,
7631,
63,
1238,
275,
4905,
8,
7631,
63,
1238,
9,
267,
291,
14,
1391,
63,
354,
275,
2729,
63,
354,
267,
291,
14,
14434,
63,
15785,
275,
10866,
63,
15785,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
10866,
63,
15785,
275,
4905,
8,
277,
14,
14434,
63,
15785,
680,
6983,
8,
1100,
9,
340,
291,
14,
14434,
63,
15785,
587,
488,
267,
862,
26,
288,
6804,
63,
1238,
275,
291,
14,
7631,
63,
1238,
14,
6983,
8,
1100,
9,
288,
1321,
22938,
275,
1709,
14,
2201,
10410,
14,
1462,
14,
362,
63,
991,
63,
7631,
63,
1238,
8,
7631,
63,
1238,
9,
288,
340,
10866,
63,
15785,
26,
14924,
3777,
355,
1321,
22938,
275,
359,
86,
367,
373,
315,
1321,
22938,
340,
440,
373,
14,
2200,
14,
7764,
63,
955,
14,
362,
360,
14434,
5440,
6208,
3322,
288,
1067,
59,
277,
14,
1391,
63,
354,
61,
275,
1709,
14,
2201,
22938,
4590,
8,
433,
22938,
9,
267,
871,
4905,
7400,
26,
288,
986,
267,
372,
2125,
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
] |
[
504,
1639,
14,
1160,
492,
11243,
12,
5013,
12,
4905,
199,
504,
1639,
14,
1160,
14,
1095,
492,
17762,
12,
4905,
7400,
199,
199,
504,
8336,
63,
6136,
492,
1709,
421,
199,
2683,
275,
11243,
342,
199,
199,
363,
452,
363,
275,
661,
433,
22938,
63,
509,
297,
776,
421,
199,
32,
2683,
14,
1450,
199,
318,
1321,
22938,
63,
509,
8,
2087,
12,
1526,
304,
272,
408,
272,
4503,
26,
272,
7749,
1321,
22938,
63,
509,
6804,
63,
1238,
465,
2729,
63,
354,
2716,
63,
14434,
63,
15785,
63,
1975,
3674,
272,
408,
272,
5821,
275,
1526,
14,
1294,
63,
4407,
342,
272,
340,
822,
8,
5609,
9,
665,
841,
503,
5821,
59,
18,
61,
1137,
283,
305,
356,
267,
746,
17762,
480,
13757,
986,
283,
7631,
63,
1238,
465,
2729,
63,
354,
7,
370,
450,
83,
1947,
2,
450,
5821,
59,
16,
566,
272,
1031,
63,
589,
275,
359,
5609,
59,
17,
467,
5821,
59,
19,
2677,
272,
340,
822,
8,
5609,
9,
508,
959,
26,
267,
1031,
63,
589,
14,
740,
8,
5609,
59,
20,
566,
272,
372,
6561,
22938,
1858,
1716,
2031,
932,
63,
589,
9,
421,
199,
533,
6561,
22938,
1858,
1716,
8,
1716,
304,
339,
347,
636,
826,
721,
277,
12,
6804,
63,
1238,
12,
2729,
63,
354,
12,
10866,
63,
15785,
29,
403,
304,
267,
291,
14,
7631,
63,
1238,
275,
4905,
8,
7631,
63,
1238,
9,
267,
291,
14,
1391,
63,
354,
275,
2729,
63,
354,
267,
291,
14,
14434,
63,
15785,
275,
10866,
63,
15785,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
10866,
63,
15785,
275,
4905,
8,
277,
14,
14434,
63,
15785,
680,
6983,
8,
1100,
9,
340,
291,
14,
14434,
63,
15785,
587,
488,
267,
862,
26,
288,
6804,
63,
1238,
275,
291,
14,
7631,
63,
1238,
14,
6983,
8,
1100,
9,
288,
1321,
22938,
275,
1709,
14,
2201,
10410,
14,
1462,
14,
362,
63,
991,
63,
7631,
63,
1238,
8,
7631,
63,
1238,
9,
288,
340,
10866,
63,
15785,
26,
14924,
3777,
355,
1321,
22938,
275,
359,
86,
367,
373,
315,
1321,
22938,
340,
440,
373,
14,
2200,
14,
7764,
63,
955,
14,
362,
360,
14434,
5440,
6208,
3322,
288,
1067,
59,
277,
14,
1391,
63,
354,
61,
275,
1709,
14,
2201,
22938,
4590,
8,
433,
22938,
9,
267,
871,
4905,
7400,
26,
288,
986,
267,
372,
2125,
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,
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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
] |
PetaVision/projects
|
momentLearn/scripts/recon_simple.py
|
2
|
1138
|
import os, sys
lib_path = os.path.abspath("/home/slundquist/workspace/PetaVision/plab/")
sys.path.append(lib_path)
from plotRecon import plotRecon
from plotReconError import plotReconError
#For plotting
#import matplotlib.pyplot as plt
outputDir = "/nh/compneuro/Data/momentLearn/output/simple_momentum_out/"
skipFrames = 10 #Only print every 20th frame
startFrames = 0
doPlotRecon = True
doPlotErr = False
errShowPlots = False
layers = [
"a1_ImageRescale",
"a4_Recon",
]
#Layers for constructing recon error
preErrLayers = [
"a1_LeftDownsample",
"a5_RightDownsample",
]
postErrLayers = [
"a3_LeftRecon",
"a7_RightRecon",
]
gtLayers = None
#gtLayers = [
# #"a25_DepthRescale",
# #"a25_DepthRescale",
# #"a25_DepthRescale",
# "a25_DepthRescale",
# "a25_DepthRescale",
# "a25_DepthRescale",
#]
preToPostScale = [
.007,
.007,
]
if(doPlotRecon):
print("Plotting reconstructions")
plotRecon(layers, outputDir, skipFrames)
if(doPlotErr):
print("Plotting reconstruction error")
plotReconError(preErrLayers, postErrLayers, preToPostScale, outputDir, errShowPlots, skipFrames, gtLayers)
|
epl-1.0
|
[
646,
747,
12,
984,
199,
773,
63,
515,
275,
747,
14,
515,
14,
4832,
4769,
4219,
15,
2482,
725,
392,
631,
15,
13249,
15,
48,
1841,
2201,
438,
15,
1168,
371,
13589,
199,
1274,
14,
515,
14,
740,
8,
773,
63,
515,
9,
199,
504,
5137,
497,
388,
492,
5137,
497,
388,
199,
504,
5137,
497,
388,
547,
492,
5137,
497,
388,
547,
199,
199,
3,
1858,
25174,
199,
3,
646,
8027,
14,
13563,
465,
4488,
199,
199,
1199,
3567,
275,
3286,
29199,
15,
863,
685,
9129,
15,
1451,
15,
17282,
21424,
15,
1199,
15,
4129,
63,
25710,
63,
548,
6687,
199,
2759,
22024,
275,
1616,
327,
5903,
870,
4036,
3388,
273,
2787,
199,
928,
22024,
275,
378,
199,
1117,
10711,
497,
388,
275,
715,
199,
1117,
10711,
5432,
275,
756,
199,
1508,
6824,
48,
4555,
275,
756,
199,
4359,
275,
359,
2043,
298,
65,
17,
63,
3491,
1322,
2357,
401,
2043,
298,
65,
20,
63,
497,
388,
401,
2043,
1622,
199,
199,
3,
16862,
367,
22048,
24711,
1125,
199,
657,
5432,
16862,
275,
359,
2043,
298,
65,
17,
63,
8185,
36,
23311,
865,
401,
2043,
298,
65,
21,
63,
9121,
36,
23311,
865,
401,
199,
61,
199,
199,
1932,
5432,
16862,
275,
359,
2043,
298,
65,
19,
63,
8185,
497,
388,
401,
2043,
298,
65,
23,
63,
9121,
497,
388,
401,
199,
61,
199,
199,
3308,
16862,
275,
488,
199,
3,
3308,
16862,
275,
359,
199,
3,
257,
20383,
65,
821,
63,
14125,
1322,
2357,
401,
199,
3,
257,
20383,
65,
821,
63,
14125,
1322,
2357,
401,
199,
3,
257,
20383,
65,
821,
63,
14125,
1322,
2357,
401,
199,
3,
257,
298,
65,
821,
63,
14125,
1322,
2357,
401,
199,
3,
257,
298,
65,
821,
63,
14125,
1322,
2357,
401,
199,
3,
257,
298,
65,
821,
63,
14125,
1322,
2357,
401,
199,
3,
61,
199,
199,
657,
1378,
6564,
9944,
275,
359,
2043,
1275,
8255,
12,
2043,
1275,
8255,
12,
199,
61,
421,
199,
692,
8,
1117,
10711,
497,
388,
304,
2043,
870,
480,
10711,
1337,
24711,
10583,
531,
2043,
5137,
497,
388,
8,
4359,
12,
1072,
3567,
12,
3372,
22024,
9,
199,
199,
692,
8,
1117,
10711,
5432,
304,
2043,
870,
480,
10711,
1337,
295,
12708,
1125,
531,
2043,
5137,
497,
388,
547,
8,
657,
5432,
16862,
12,
2963,
5432,
16862,
12,
876,
1378,
6564,
9944,
12,
1072,
3567,
12,
2329,
6824,
48,
4555,
12,
3372,
22024,
12,
16484,
16862,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
12,
984,
199,
773,
63,
515,
275,
747,
14,
515,
14,
4832,
4769,
4219,
15,
2482,
725,
392,
631,
15,
13249,
15,
48,
1841,
2201,
438,
15,
1168,
371,
13589,
199,
1274,
14,
515,
14,
740,
8,
773,
63,
515,
9,
199,
504,
5137,
497,
388,
492,
5137,
497,
388,
199,
504,
5137,
497,
388,
547,
492,
5137,
497,
388,
547,
199,
199,
3,
1858,
25174,
199,
3,
646,
8027,
14,
13563,
465,
4488,
199,
199,
1199,
3567,
275,
3286,
29199,
15,
863,
685,
9129,
15,
1451,
15,
17282,
21424,
15,
1199,
15,
4129,
63,
25710,
63,
548,
6687,
199,
2759,
22024,
275,
1616,
327,
5903,
870,
4036,
3388,
273,
2787,
199,
928,
22024,
275,
378,
199,
1117,
10711,
497,
388,
275,
715,
199,
1117,
10711,
5432,
275,
756,
199,
1508,
6824,
48,
4555,
275,
756,
199,
4359,
275,
359,
2043,
298,
65,
17,
63,
3491,
1322,
2357,
401,
2043,
298,
65,
20,
63,
497,
388,
401,
2043,
1622,
199,
199,
3,
16862,
367,
22048,
24711,
1125,
199,
657,
5432,
16862,
275,
359,
2043,
298,
65,
17,
63,
8185,
36,
23311,
865,
401,
2043,
298,
65,
21,
63,
9121,
36,
23311,
865,
401,
199,
61,
199,
199,
1932,
5432,
16862,
275,
359,
2043,
298,
65,
19,
63,
8185,
497,
388,
401,
2043,
298,
65,
23,
63,
9121,
497,
388,
401,
199,
61,
199,
199,
3308,
16862,
275,
488,
199,
3,
3308,
16862,
275,
359,
199,
3,
257,
20383,
65,
821,
63,
14125,
1322,
2357,
401,
199,
3,
257,
20383,
65,
821,
63,
14125,
1322,
2357,
401,
199,
3,
257,
20383,
65,
821,
63,
14125,
1322,
2357,
401,
199,
3,
257,
298,
65,
821,
63,
14125,
1322,
2357,
401,
199,
3,
257,
298,
65,
821,
63,
14125,
1322,
2357,
401,
199,
3,
257,
298,
65,
821,
63,
14125,
1322,
2357,
401,
199,
3,
61,
199,
199,
657,
1378,
6564,
9944,
275,
359,
2043,
1275,
8255,
12,
2043,
1275,
8255,
12,
199,
61,
421,
199,
692,
8,
1117,
10711,
497,
388,
304,
2043,
870,
480,
10711,
1337,
24711,
10583,
531,
2043,
5137,
497,
388,
8,
4359,
12,
1072,
3567,
12,
3372,
22024,
9,
199,
199,
692,
8,
1117,
10711,
5432,
304,
2043,
870,
480,
10711,
1337,
295,
12708,
1125,
531,
2043,
5137,
497,
388,
547,
8,
657,
5432,
16862,
12,
2963,
5432,
16862,
12,
876,
1378,
6564,
9944,
12,
1072,
3567,
12,
2329,
6824,
48,
4555,
12,
3372,
22024,
12,
16484,
16862,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
alexlo03/ansible
|
lib/ansible/module_utils/network/f5/bigip.py
|
20
|
3737
|
# -*- coding: utf-8 -*-
#
# Copyright (c) 2017 F5 Networks Inc.
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import time
try:
from f5.bigip import ManagementRoot
from icontrol.exceptions import iControlUnexpectedHTTPError
HAS_F5SDK = True
except ImportError:
HAS_F5SDK = False
try:
from library.module_utils.network.f5.common import F5BaseClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.icontrol import iControlRestSession
except ImportError:
from ansible.module_utils.network.f5.common import F5BaseClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.icontrol import iControlRestSession
class F5Client(F5BaseClient):
def __init__(self, *args, **kwargs):
super(F5Client, self).__init__(*args, **kwargs)
self.provider = self.merge_provider_params()
@property
def api(self):
exc = None
if self._client:
return self._client
for x in range(0, 10):
try:
result = ManagementRoot(
self.provider['server'],
self.provider['user'],
self.provider['password'],
port=self.provider['server_port'],
verify=self.provider['validate_certs'],
token='tmos'
)
self._client = result
return self._client
except Exception as ex:
exc = ex
time.sleep(1)
error = 'Unable to connect to {0} on port {1}.'.format(
self.provider['server'], self.provider['server_port']
)
if exc is not None:
error += ' The reported error was "{0}".'.format(str(exc))
raise F5ModuleError(error)
class F5RestClient(F5BaseClient):
def __init__(self, *args, **kwargs):
super(F5RestClient, self).__init__(*args, **kwargs)
self.provider = self.merge_provider_params()
@property
def api(self):
exc = None
if self._client:
return self._client
for x in range(0, 10):
try:
url = "https://{0}:{1}/mgmt/shared/authn/login".format(
self.provider['server'], self.provider['server_port']
)
payload = {
'username': self.provider['user'],
'password': self.provider['password'],
'loginProviderName': self.provider['auth_provider'] or 'tmos'
}
session = iControlRestSession()
session.verify = self.provider['validate_certs']
response = session.post(url, json=payload)
if response.status not in [200]:
raise F5ModuleError('Status code: {0}. Unexpected Error: {1} for uri: {2}\nText: {3}'.format(
response.status, response.reason, response.url, response.content
))
session.headers['X-F5-Auth-Token'] = response.json()['token']['token']
self._client = session
return self._client
except Exception as ex:
exc = ex
time.sleep(1)
error = 'Unable to connect to {0} on port {1}.'.format(
self.provider['server'], self.provider['server_port']
)
if exc is not None:
error += ' The reported error was "{0}".'.format(str(exc))
raise F5ModuleError(error)
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
9708,
481,
21,
17138,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
646,
900,
199,
199,
893,
26,
272,
687,
289,
21,
14,
17833,
492,
8259,
6405,
272,
687,
284,
2785,
14,
3924,
492,
284,
3717,
8708,
12815,
272,
7509,
63,
38,
21,
14939,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
38,
21,
14939,
275,
756,
199,
199,
893,
26,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
481,
21,
1563,
3041,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
481,
21,
12232,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
73,
2785,
492,
284,
3717,
13726,
4434,
199,
2590,
3545,
26,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
481,
21,
1563,
3041,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
481,
21,
12232,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
73,
2785,
492,
284,
3717,
13726,
4434,
421,
199,
533,
481,
21,
3041,
8,
38,
21,
1563,
3041,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
38,
21,
3041,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
3780,
275,
291,
14,
5628,
63,
3780,
63,
1162,
342,
339,
768,
1829,
272,
347,
2986,
8,
277,
304,
267,
3178,
275,
488,
267,
340,
291,
423,
1258,
26,
288,
372,
291,
423,
1258,
398,
367,
671,
315,
1425,
8,
16,
12,
1616,
304,
288,
862,
26,
355,
754,
275,
8259,
6405,
8,
490,
291,
14,
3780,
459,
1000,
995,
490,
291,
14,
3780,
459,
751,
995,
490,
291,
14,
3780,
459,
2060,
995,
490,
1844,
29,
277,
14,
3780,
459,
1000,
63,
719,
995,
490,
4911,
29,
277,
14,
3780,
459,
3502,
63,
8356,
995,
490,
1526,
534,
84,
16908,
7,
355,
776,
355,
291,
423,
1258,
275,
754,
355,
372,
291,
423,
1258,
288,
871,
2186,
465,
444,
26,
355,
3178,
275,
444,
355,
900,
14,
4532,
8,
17,
9,
267,
1125,
275,
283,
6005,
370,
4907,
370,
469,
16,
93,
641,
1844,
469,
17,
5565,
1370,
908,
8,
288,
291,
14,
3780,
459,
1000,
995,
291,
14,
3780,
459,
1000,
63,
719,
418,
267,
776,
398,
340,
3178,
365,
440,
488,
26,
288,
1125,
847,
283,
710,
14581,
1125,
1990,
5310,
16,
5469,
1370,
908,
8,
495,
8,
2804,
430,
267,
746,
481,
21,
12232,
8,
705,
9,
421,
199,
533,
481,
21,
13726,
3041,
8,
38,
21,
1563,
3041,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
38,
21,
13726,
3041,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
3780,
275,
291,
14,
5628,
63,
3780,
63,
1162,
342,
339,
768,
1829,
272,
347,
2986,
8,
277,
304,
267,
3178,
275,
488,
267,
340,
291,
423,
1258,
26,
288,
372,
291,
423,
1258,
267,
367,
671,
315,
1425,
8,
16,
12,
1616,
304,
288,
862,
26,
355,
1166,
275,
298,
2859,
20193,
16,
16495,
17,
5995,
9752,
15,
5555,
15,
1178,
78,
15,
2886,
1674,
908,
8,
490,
291,
14,
3780,
459,
1000,
995,
291,
14,
3780,
459,
1000,
63,
719,
418,
355,
776,
355,
4886,
275,
469,
490,
283,
2473,
356,
291,
14,
3780,
459,
751,
995,
490,
283,
2060,
356,
291,
14,
3780,
459,
2060,
995,
490,
283,
2886,
6663,
985,
356,
291,
14,
3780,
459,
1178,
63,
3780,
418,
503,
283,
84,
16908,
7,
355,
789,
355,
2351,
275,
284,
3717,
13726,
4434,
342,
355,
2351,
14,
4712,
275,
291,
14,
3780,
459,
3502,
63,
8356,
418,
355,
1177,
275,
2351,
14,
1932,
8,
633,
12,
2022,
29,
4749,
9,
2234,
340,
1177,
14,
1205,
440,
315,
359,
1840,
2189,
490,
746,
481,
21,
12232,
360,
3694,
1233,
26,
469,
16,
5565,
25345,
4520,
26,
469,
17,
93,
367,
5108,
26,
469,
18,
4988,
78,
1872,
26,
469,
19,
5285,
908,
8,
717,
1177,
14,
1205,
12,
1177,
14,
5764,
12,
1177,
14,
633,
12,
1177,
14,
1317,
490,
5082,
2234,
2351,
14,
2139,
459,
56,
13,
38,
21,
13,
2817,
13,
3264,
418,
275,
1177,
14,
1001,
12047,
1418,
2545,
1418,
418,
355,
291,
423,
1258,
275,
2351,
355,
372,
291,
423,
1258,
288,
871,
2186,
465,
444,
26,
355,
3178,
275,
444,
355,
900,
14,
4532,
8,
17,
9,
267,
1125,
275,
283,
6005,
370,
4907,
370,
469,
16,
93,
641,
1844,
469,
17,
5565,
1370,
908,
8,
288,
291,
14,
3780,
459,
1000,
995,
291,
14,
3780,
459,
1000,
63,
719,
418,
267,
776,
267,
340,
3178,
365,
440,
488,
26,
288,
1125,
847,
283,
710,
14581,
1125,
1990,
5310,
16,
5469,
1370,
908,
8,
495,
8,
2804,
430,
267,
746,
481,
21,
12232,
8,
705,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
9708,
481,
21,
17138,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
646,
900,
199,
199,
893,
26,
272,
687,
289,
21,
14,
17833,
492,
8259,
6405,
272,
687,
284,
2785,
14,
3924,
492,
284,
3717,
8708,
12815,
272,
7509,
63,
38,
21,
14939,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
38,
21,
14939,
275,
756,
199,
199,
893,
26,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
481,
21,
1563,
3041,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
481,
21,
12232,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
73,
2785,
492,
284,
3717,
13726,
4434,
199,
2590,
3545,
26,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
481,
21,
1563,
3041,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
481,
21,
12232,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
73,
2785,
492,
284,
3717,
13726,
4434,
421,
199,
533,
481,
21,
3041,
8,
38,
21,
1563,
3041,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
38,
21,
3041,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
3780,
275,
291,
14,
5628,
63,
3780,
63,
1162,
342,
339,
768,
1829,
272,
347,
2986,
8,
277,
304,
267,
3178,
275,
488,
267,
340,
291,
423,
1258,
26,
288,
372,
291,
423,
1258,
398,
367,
671,
315,
1425,
8,
16,
12,
1616,
304,
288,
862,
26,
355,
754,
275,
8259,
6405,
8,
490,
291,
14,
3780,
459,
1000,
995,
490,
291,
14,
3780,
459,
751,
995,
490,
291,
14,
3780,
459,
2060,
995,
490,
1844,
29,
277,
14,
3780,
459,
1000,
63,
719,
995,
490,
4911,
29,
277,
14,
3780,
459,
3502,
63,
8356,
995,
490,
1526,
534,
84,
16908,
7,
355,
776,
355,
291,
423,
1258,
275,
754,
355,
372,
291,
423,
1258,
288,
871,
2186,
465,
444,
26,
355,
3178,
275,
444,
355,
900,
14,
4532,
8,
17,
9,
267,
1125,
275,
283,
6005,
370,
4907,
370,
469,
16,
93,
641,
1844,
469,
17,
5565,
1370,
908,
8,
288,
291,
14,
3780,
459,
1000,
995,
291,
14,
3780,
459,
1000,
63,
719,
418,
267,
776,
398,
340,
3178,
365,
440,
488,
26,
288,
1125,
847,
283,
710,
14581,
1125,
1990,
5310,
16,
5469,
1370,
908,
8,
495,
8,
2804,
430,
267,
746,
481,
21,
12232,
8,
705,
9,
421,
199,
533,
481,
21,
13726,
3041,
8,
38,
21,
1563,
3041,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
38,
21,
13726,
3041,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
3780,
275,
291,
14,
5628,
63,
3780,
63,
1162,
342,
339,
768,
1829,
272,
347,
2986,
8,
277,
304,
267,
3178,
275,
488,
267,
340,
291,
423,
1258,
26,
288,
372,
291,
423,
1258,
267,
367,
671,
315,
1425,
8,
16,
12,
1616,
304,
288,
862,
26,
355,
1166,
275,
298,
2859,
20193,
16,
16495,
17,
5995,
9752,
15,
5555,
15,
1178,
78,
15,
2886,
1674,
908,
8,
490,
291,
14,
3780,
459,
1000,
995,
291,
14,
3780,
459,
1000,
63,
719,
418,
355,
776,
355,
4886,
275,
469,
490,
283,
2473,
356,
291,
14,
3780,
459,
751,
995,
490,
283,
2060,
356,
291,
14,
3780,
459,
2060,
995,
490,
283,
2886,
6663,
985,
356,
291,
14,
3780,
459,
1178,
63,
3780,
418,
503,
283,
84,
16908,
7,
355,
789,
355,
2351,
275,
284,
3717,
13726,
4434,
342,
355,
2351,
14,
4712,
275,
291,
14,
3780,
459,
3502,
63,
8356,
418,
355,
1177,
275,
2351,
14,
1932,
8,
633,
12,
2022,
29,
4749,
9,
2234,
340,
1177,
14,
1205,
440,
315,
359,
1840,
2189,
490,
746,
481,
21,
12232,
360,
3694,
1233,
26,
469,
16,
5565,
25345,
4520,
26,
469,
17,
93,
367,
5108,
26,
469,
18,
4988,
78,
1872,
26,
469,
19,
5285,
908,
8,
717,
1177,
14,
1205,
12,
1177,
14,
5764,
12,
1177,
14,
633,
12,
1177,
14,
1317,
490,
5082,
2234,
2351,
14,
2139,
459,
56,
13,
38,
21,
13,
2817,
13,
3264,
418,
275,
1177,
14,
1001,
12047,
1418,
2545,
1418,
418,
355,
291,
423,
1258,
275,
2351,
355,
372,
291,
423,
1258,
288,
871,
2186,
465,
444,
26,
355,
3178,
275,
444,
355,
900,
14,
4532,
8,
17,
9,
267,
1125,
275,
283,
6005,
370,
4907,
370,
469,
16,
93,
641,
1844,
469,
17,
5565,
1370,
908,
8,
288,
291,
14,
3780,
459,
1000,
995,
291,
14,
3780,
459,
1000,
63,
719,
418,
267,
776,
267,
340,
3178,
365,
440,
488,
26,
288,
1125,
847,
283,
710,
14581,
1125,
1990,
5310,
16,
5469,
1370,
908,
8,
495,
8,
2804,
430,
267,
746,
481,
21,
12232,
8,
705,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
awalls-cx18/gnuradio
|
gr-blocks/python/blocks/qa_file_source.py
|
6
|
5402
|
#!/usr/bin/env python
#
# Copyright 2018 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio 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, or (at your option)
# any later version.
#
# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
import os
import tempfile
import array
import pmt
from gnuradio import gr, gr_unittest, blocks
class test_file_source(gr_unittest.TestCase):
@classmethod
def setUpClass(cls):
os.environ['GR_CONF_CONTROLPORT_ON'] = 'False'
cls._datafile = tempfile.NamedTemporaryFile()
cls._datafilename = cls._datafile.name
cls._vector = [x for x in range(1000)]
with open(cls._datafilename, 'wb') as f:
array.array('f', cls._vector).tofile(f)
@classmethod
def tearDownClass(cls):
del cls._vector
del cls._datafilename
del cls._datafile
def setUp (self):
self.tb = gr.top_block()
def tearDown (self):
self.tb = None
def test_file_source(self):
src = blocks.file_source(gr.sizeof_float, self._datafilename)
snk = blocks.vector_sink_f()
self.tb.connect(src, snk)
self.tb.run()
result_data = snk.data()
self.assertFloatTuplesAlmostEqual(self._vector, result_data)
self.assertEqual(len(snk.tags()), 0)
def test_file_source_no_such_file(self):
"""
Try to open a non-existant file and verify exception is thrown.
"""
try:
_ = blocks.file_source(gr.sizeof_float, "___no_such_file___")
self.assertTrue(False)
except RuntimeError:
self.assertTrue(True)
def test_file_source_with_offset(self):
expected_result = self._vector[100:]
src = blocks.file_source(gr.sizeof_float, self._datafilename, offset=100)
snk = blocks.vector_sink_f()
self.tb.connect(src, snk)
self.tb.run()
result_data = snk.data()
self.assertFloatTuplesAlmostEqual(expected_result, result_data)
self.assertEqual(len(snk.tags()), 0)
def test_source_with_offset_and_len(self):
expected_result = self._vector[100:100+600]
src = blocks.file_source(gr.sizeof_float, self._datafilename, offset=100, len=600)
snk = blocks.vector_sink_f()
self.tb.connect(src, snk)
self.tb.run()
result_data = snk.data()
self.assertFloatTuplesAlmostEqual(expected_result, result_data)
self.assertEqual(len(snk.tags()), 0)
def test_file_source_can_seek_after_open(self):
src = blocks.file_source(gr.sizeof_float, self._datafilename)
self.assertTrue(src.seek(0, os.SEEK_SET))
self.assertTrue(src.seek(len(self._vector)-1, os.SEEK_SET))
# Seek past end of file - this will also log a warning
self.assertFalse(src.seek(len(self._vector), os.SEEK_SET))
# Negative seek - this will also log a warning
self.assertFalse(src.seek(-1, os.SEEK_SET))
self.assertTrue(src.seek(1, os.SEEK_END))
self.assertTrue(src.seek(len(self._vector), os.SEEK_END))
# Seek past end of file - this will also log a warning
self.assertFalse(src.seek(0, os.SEEK_END))
self.assertTrue(src.seek(0, os.SEEK_SET))
self.assertTrue(src.seek(1, os.SEEK_CUR))
# Seek past end of file - this will also log a warning
self.assertFalse(src.seek(len(self._vector), os.SEEK_CUR))
def test_begin_tag(self):
expected_result = self._vector
src = blocks.file_source(gr.sizeof_float, self._datafilename)
src.set_begin_tag(pmt.string_to_symbol("file_begin"))
snk = blocks.vector_sink_f()
self.tb.connect(src, snk)
self.tb.run()
result_data = snk.data()
self.assertFloatTuplesAlmostEqual(expected_result, result_data)
self.assertEqual(len(snk.tags()), 1)
def test_begin_tag_repeat(self):
expected_result = self._vector + self._vector
src = blocks.file_source(gr.sizeof_float, self._datafilename, True)
src.set_begin_tag(pmt.string_to_symbol("file_begin"))
head = blocks.head(gr.sizeof_float, 2 * len(self._vector))
snk = blocks.vector_sink_f()
self.tb.connect(src, head, snk)
self.tb.run()
result_data = snk.data()
self.assertFloatTuplesAlmostEqual(expected_result, result_data)
tags = snk.tags()
self.assertEqual(len(tags), 2)
self.assertEqual(str(tags[0].key), "file_begin")
self.assertEqual(str(tags[0].value), "0")
self.assertEqual(tags[0].offset, 0)
self.assertEqual(str(tags[1].key), "file_begin")
self.assertEqual(str(tags[1].value), "1")
self.assertEqual(tags[1].offset, 1000)
if __name__ == '__main__':
gr_unittest.run(test_file_source, "test_file_source.xml")
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
14894,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1664,
13514,
199,
3,
199,
3,
1664,
13514,
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,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1664,
13514,
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,
1664,
13514,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
199,
646,
747,
199,
646,
5549,
199,
646,
1625,
199,
646,
30961,
199,
504,
24526,
492,
7192,
12,
7192,
63,
2796,
12,
5664,
199,
199,
533,
511,
63,
493,
63,
1365,
8,
2587,
63,
2796,
14,
1746,
304,
339,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
747,
14,
2314,
459,
3975,
63,
3103,
63,
13060,
3657,
63,
615,
418,
275,
283,
797,
7,
267,
843,
423,
31423,
275,
5549,
14,
19320,
342,
267,
843,
423,
576,
1501,
275,
843,
423,
31423,
14,
354,
267,
843,
423,
4106,
275,
359,
88,
367,
671,
315,
1425,
8,
5279,
1874,
267,
543,
1551,
8,
1886,
423,
576,
1501,
12,
283,
6603,
358,
465,
289,
26,
288,
1625,
14,
1144,
360,
70,
297,
843,
423,
4106,
680,
475,
493,
8,
70,
9,
339,
768,
3744,
272,
347,
24468,
8,
1886,
304,
267,
2150,
843,
423,
4106,
267,
2150,
843,
423,
576,
1501,
267,
2150,
843,
423,
31423,
339,
347,
3613,
334,
277,
304,
267,
291,
14,
5842,
275,
7192,
14,
2119,
63,
1457,
342,
339,
347,
6766,
334,
277,
304,
267,
291,
14,
5842,
275,
488,
339,
347,
511,
63,
493,
63,
1365,
8,
277,
304,
267,
2928,
275,
5664,
14,
493,
63,
1365,
8,
2587,
14,
12590,
63,
1609,
12,
291,
423,
576,
1501,
9,
267,
6895,
75,
275,
5664,
14,
4106,
63,
11279,
63,
70,
342,
267,
291,
14,
5842,
14,
2242,
8,
2164,
12,
6895,
75,
9,
267,
291,
14,
5842,
14,
1065,
342,
398,
754,
63,
576,
275,
6895,
75,
14,
576,
342,
267,
291,
14,
479,
5136,
7075,
83,
7331,
8,
277,
423,
4106,
12,
754,
63,
576,
9,
267,
291,
14,
629,
8,
552,
8,
5167,
75,
14,
2969,
4000,
378,
9,
339,
347,
511,
63,
493,
63,
1365,
63,
889,
63,
10180,
63,
493,
8,
277,
304,
267,
408,
267,
7649,
370,
1551,
282,
2222,
13,
4494,
867,
570,
436,
4911,
1919,
365,
14031,
14,
267,
408,
267,
862,
26,
288,
485,
275,
5664,
14,
493,
63,
1365,
8,
2587,
14,
12590,
63,
1609,
12,
4396,
63,
889,
63,
10180,
63,
493,
8989,
531,
288,
291,
14,
1815,
8,
797,
9,
267,
871,
6064,
26,
288,
291,
14,
1815,
8,
549,
9,
339,
347,
511,
63,
493,
63,
1365,
63,
1045,
63,
2743,
8,
277,
304,
267,
1420,
63,
1099,
275,
291,
423,
4106,
59,
1960,
2938,
398,
2928,
275,
5664,
14,
493,
63,
1365,
8,
2587,
14,
12590,
63,
1609,
12,
291,
423,
576,
1501,
12,
3268,
29,
1960,
9,
267,
6895,
75,
275,
5664,
14,
4106,
63,
11279,
63,
70,
342,
398,
291,
14,
5842,
14,
2242,
8,
2164,
12,
6895,
75,
9,
267,
291,
14,
5842,
14,
1065,
342,
398,
754,
63,
576,
275,
6895,
75,
14,
576,
342,
267,
291,
14,
479,
5136,
7075,
83,
7331,
8,
2062,
63,
1099,
12,
754,
63,
576,
9,
267,
291,
14,
629,
8,
552,
8,
5167,
75,
14,
2969,
4000,
378,
9,
339,
347,
511,
63,
1365,
63,
1045,
63,
2743,
63,
460,
63,
552,
8,
277,
304,
267,
1420,
63,
1099,
275,
291,
423,
4106,
59,
1960,
26,
1960,
11,
6683,
61,
398,
2928,
275,
5664,
14,
493,
63,
1365,
8,
2587,
14,
12590,
63,
1609,
12,
291,
423,
576,
1501,
12,
3268,
29,
1960,
12,
822,
29,
6683,
9,
267,
6895,
75,
275,
5664,
14,
4106,
63,
11279,
63,
70,
342,
267,
291,
14,
5842,
14,
2242,
8,
2164,
12,
6895,
75,
9,
267,
291,
14,
5842,
14,
1065,
342,
398,
754,
63,
576,
275,
6895,
75,
14,
576,
342,
267,
291,
14,
479,
5136,
7075,
83,
7331,
8,
2062,
63,
1099,
12,
754,
63,
576,
9,
267,
291,
14,
629,
8,
552,
8,
5167,
75,
14,
2969,
4000,
378,
9,
339,
347,
511,
63,
493,
63,
1365,
63,
2425,
63,
5507,
63,
4399,
63,
1490,
8,
277,
304,
398,
2928,
275,
5664,
14,
493,
63,
1365,
8,
2587,
14,
12590,
63,
1609,
12,
291,
423,
576,
1501,
9,
267,
291,
14,
1815,
8,
2164,
14,
5507,
8,
16,
12,
747,
14,
18439,
63,
3597,
430,
267,
291,
14,
1815,
8,
2164,
14,
5507,
8,
552,
8,
277,
423,
4106,
7216,
17,
12,
747,
14,
18439,
63,
3597,
430,
267,
327,
1666,
75,
13541,
1284,
402,
570,
446,
642,
911,
2597,
943,
282,
5721,
267,
291,
14,
3334,
8,
2164,
14,
5507,
8,
552,
8,
277,
423,
4106,
395,
747,
14,
18439,
63,
3597,
430,
267,
327,
32548,
12005,
446,
642,
911,
2597,
943,
282,
5721,
267,
291,
14,
3334,
8,
2164,
14,
5507,
2801,
17,
12,
747,
14,
18439,
63,
3597,
430,
398,
291,
14,
1815,
8,
2164,
14,
5507,
8,
17,
12,
747,
14,
18439,
63,
3902,
430,
267,
291,
14,
1815,
8,
2164,
14,
5507,
8,
552,
8,
277,
423,
4106,
395,
747,
14,
18439,
63,
3902,
430,
267,
327,
1666,
75,
13541,
1284,
402,
570,
446,
642,
911,
2597,
943,
282,
5721,
267,
291,
14,
3334,
8,
2164,
14,
5507,
8,
16
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
14894,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1664,
13514,
199,
3,
199,
3,
1664,
13514,
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,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1664,
13514,
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,
1664,
13514,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
199,
646,
747,
199,
646,
5549,
199,
646,
1625,
199,
646,
30961,
199,
504,
24526,
492,
7192,
12,
7192,
63,
2796,
12,
5664,
199,
199,
533,
511,
63,
493,
63,
1365,
8,
2587,
63,
2796,
14,
1746,
304,
339,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
747,
14,
2314,
459,
3975,
63,
3103,
63,
13060,
3657,
63,
615,
418,
275,
283,
797,
7,
267,
843,
423,
31423,
275,
5549,
14,
19320,
342,
267,
843,
423,
576,
1501,
275,
843,
423,
31423,
14,
354,
267,
843,
423,
4106,
275,
359,
88,
367,
671,
315,
1425,
8,
5279,
1874,
267,
543,
1551,
8,
1886,
423,
576,
1501,
12,
283,
6603,
358,
465,
289,
26,
288,
1625,
14,
1144,
360,
70,
297,
843,
423,
4106,
680,
475,
493,
8,
70,
9,
339,
768,
3744,
272,
347,
24468,
8,
1886,
304,
267,
2150,
843,
423,
4106,
267,
2150,
843,
423,
576,
1501,
267,
2150,
843,
423,
31423,
339,
347,
3613,
334,
277,
304,
267,
291,
14,
5842,
275,
7192,
14,
2119,
63,
1457,
342,
339,
347,
6766,
334,
277,
304,
267,
291,
14,
5842,
275,
488,
339,
347,
511,
63,
493,
63,
1365,
8,
277,
304,
267,
2928,
275,
5664,
14,
493,
63,
1365,
8,
2587,
14,
12590,
63,
1609,
12,
291,
423,
576,
1501,
9,
267,
6895,
75,
275,
5664,
14,
4106,
63,
11279,
63,
70,
342,
267,
291,
14,
5842,
14,
2242,
8,
2164,
12,
6895,
75,
9,
267,
291,
14,
5842,
14,
1065,
342,
398,
754,
63,
576,
275,
6895,
75,
14,
576,
342,
267,
291,
14,
479,
5136,
7075,
83,
7331,
8,
277,
423,
4106,
12,
754,
63,
576,
9,
267,
291,
14,
629,
8,
552,
8,
5167,
75,
14,
2969,
4000,
378,
9,
339,
347,
511,
63,
493,
63,
1365,
63,
889,
63,
10180,
63,
493,
8,
277,
304,
267,
408,
267,
7649,
370,
1551,
282,
2222,
13,
4494,
867,
570,
436,
4911,
1919,
365,
14031,
14,
267,
408,
267,
862,
26,
288,
485,
275,
5664,
14,
493,
63,
1365,
8,
2587,
14,
12590,
63,
1609,
12,
4396,
63,
889,
63,
10180,
63,
493,
8989,
531,
288,
291,
14,
1815,
8,
797,
9,
267,
871,
6064,
26,
288,
291,
14,
1815,
8,
549,
9,
339,
347,
511,
63,
493,
63,
1365,
63,
1045,
63,
2743,
8,
277,
304,
267,
1420,
63,
1099,
275,
291,
423,
4106,
59,
1960,
2938,
398,
2928,
275,
5664,
14,
493,
63,
1365,
8,
2587,
14,
12590,
63,
1609,
12,
291,
423,
576,
1501,
12,
3268,
29,
1960,
9,
267,
6895,
75,
275,
5664,
14,
4106,
63,
11279,
63,
70,
342,
398,
291,
14,
5842,
14,
2242,
8,
2164,
12,
6895,
75,
9,
267,
291,
14,
5842,
14,
1065,
342,
398,
754,
63,
576,
275,
6895,
75,
14,
576,
342,
267,
291,
14,
479,
5136,
7075,
83,
7331,
8,
2062,
63,
1099,
12,
754,
63,
576,
9,
267,
291,
14,
629,
8,
552,
8,
5167,
75,
14,
2969,
4000,
378,
9,
339,
347,
511,
63,
1365,
63,
1045,
63,
2743,
63,
460,
63,
552,
8,
277,
304,
267,
1420,
63,
1099,
275,
291,
423,
4106,
59,
1960,
26,
1960,
11,
6683,
61,
398,
2928,
275,
5664,
14,
493,
63,
1365,
8,
2587,
14,
12590,
63,
1609,
12,
291,
423,
576,
1501,
12,
3268,
29,
1960,
12,
822,
29,
6683,
9,
267,
6895,
75,
275,
5664,
14,
4106,
63,
11279,
63,
70,
342,
267,
291,
14,
5842,
14,
2242,
8,
2164,
12,
6895,
75,
9,
267,
291,
14,
5842,
14,
1065,
342,
398,
754,
63,
576,
275,
6895,
75,
14,
576,
342,
267,
291,
14,
479,
5136,
7075,
83,
7331,
8,
2062,
63,
1099,
12,
754,
63,
576,
9,
267,
291,
14,
629,
8,
552,
8,
5167,
75,
14,
2969,
4000,
378,
9,
339,
347,
511,
63,
493,
63,
1365,
63,
2425,
63,
5507,
63,
4399,
63,
1490,
8,
277,
304,
398,
2928,
275,
5664,
14,
493,
63,
1365,
8,
2587,
14,
12590,
63,
1609,
12,
291,
423,
576,
1501,
9,
267,
291,
14,
1815,
8,
2164,
14,
5507,
8,
16,
12,
747,
14,
18439,
63,
3597,
430,
267,
291,
14,
1815,
8,
2164,
14,
5507,
8,
552,
8,
277,
423,
4106,
7216,
17,
12,
747,
14,
18439,
63,
3597,
430,
267,
327,
1666,
75,
13541,
1284,
402,
570,
446,
642,
911,
2597,
943,
282,
5721,
267,
291,
14,
3334,
8,
2164,
14,
5507,
8,
552,
8,
277,
423,
4106,
395,
747,
14,
18439,
63,
3597,
430,
267,
327,
32548,
12005,
446,
642,
911,
2597,
943,
282,
5721,
267,
291,
14,
3334,
8,
2164,
14,
5507,
2801,
17,
12,
747,
14,
18439,
63,
3597,
430,
398,
291,
14,
1815,
8,
2164,
14,
5507,
8,
17,
12,
747,
14,
18439,
63,
3902,
430,
267,
291,
14,
1815,
8,
2164,
14,
5507,
8,
552,
8,
277,
423,
4106,
395,
747,
14,
18439,
63,
3902,
430,
267,
327,
1666,
75,
13541,
1284,
402,
570,
446,
642,
911,
2597,
943,
282,
5721,
267,
291,
14,
3334,
8,
2164,
14,
5507,
8,
16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1,
1,
1
] |
harayz/raspberry_pwn
|
src/pexpect-2.3/pxssh.py
|
14
|
14565
|
"""This class extends pexpect.spawn to specialize setting up SSH connections.
This adds methods for login, logout, and expecting the shell prompt.
$Id: pxssh.py 487 2007-08-29 22:33:29Z noah $
"""
from pexpect import *
import pexpect
import time
__all__ = ['ExceptionPxssh', 'pxssh']
# Exception classes used by this module.
class ExceptionPxssh(ExceptionPexpect):
"""Raised for pxssh exceptions.
"""
class pxssh (spawn):
"""This class extends pexpect.spawn to specialize setting up SSH
connections. This adds methods for login, logout, and expecting the shell
prompt. It does various tricky things to handle many situations in the SSH
login process. For example, if the session is your first login, then pxssh
automatically accepts the remote certificate; or if you have public key
authentication setup then pxssh won't wait for the password prompt.
pxssh uses the shell prompt to synchronize output from the remote host. In
order to make this more robust it sets the shell prompt to something more
unique than just $ or #. This should work on most Borne/Bash or Csh style
shells.
Example that runs a few commands on a remote server and prints the result::
import pxssh
import getpass
try:
s = pxssh.pxssh()
hostname = raw_input('hostname: ')
username = raw_input('username: ')
password = getpass.getpass('password: ')
s.login (hostname, username, password)
s.sendline ('uptime') # run a command
s.prompt() # match the prompt
print s.before # print everything before the prompt.
s.sendline ('ls -l')
s.prompt()
print s.before
s.sendline ('df')
s.prompt()
print s.before
s.logout()
except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)
Note that if you have ssh-agent running while doing development with pxssh
then this can lead to a lot of confusion. Many X display managers (xdm,
gdm, kdm, etc.) will automatically start a GUI agent. You may see a GUI
dialog box popup asking for a password during development. You should turn
off any key agents during testing. The 'force_password' attribute will turn
off public key authentication. This will only work if the remote SSH server
is configured to allow password logins. Example of using 'force_password'
attribute::
s = pxssh.pxssh()
s.force_password = True
hostname = raw_input('hostname: ')
username = raw_input('username: ')
password = getpass.getpass('password: ')
s.login (hostname, username, password)
"""
def __init__ (self, timeout=30, maxread=2000, searchwindowsize=None, logfile=None, cwd=None, env=None):
spawn.__init__(self, None, timeout=timeout, maxread=maxread, searchwindowsize=searchwindowsize, logfile=logfile, cwd=cwd, env=env)
self.name = '<pxssh>'
#SUBTLE HACK ALERT! Note that the command to set the prompt uses a
#slightly different string than the regular expression to match it. This
#is because when you set the prompt the command will echo back, but we
#don't want to match the echoed command. So if we make the set command
#slightly different than the regex we eliminate the problem. To make the
#set command different we add a backslash in front of $. The $ doesn't
#need to be escaped, but it doesn't hurt and serves to make the set
#prompt command different than the regex.
# used to match the command-line prompt
self.UNIQUE_PROMPT = "\[PEXPECT\][\$\#] "
self.PROMPT = self.UNIQUE_PROMPT
# used to set shell command-line prompt to UNIQUE_PROMPT.
self.PROMPT_SET_SH = "PS1='[PEXPECT]\$ '"
self.PROMPT_SET_CSH = "set prompt='[PEXPECT]\$ '"
self.SSH_OPTS = "-o'RSAAuthentication=no' -o 'PubkeyAuthentication=no'"
# Disabling X11 forwarding gets rid of the annoying SSH_ASKPASS from
# displaying a GUI password dialog. I have not figured out how to
# disable only SSH_ASKPASS without also disabling X11 forwarding.
# Unsetting SSH_ASKPASS on the remote side doesn't disable it! Annoying!
#self.SSH_OPTS = "-x -o'RSAAuthentication=no' -o 'PubkeyAuthentication=no'"
self.force_password = False
self.auto_prompt_reset = True
def levenshtein_distance(self, a,b):
"""This calculates the Levenshtein distance between a and b.
"""
n, m = len(a), len(b)
if n > m:
a,b = b,a
n,m = m,n
current = range(n+1)
for i in range(1,m+1):
previous, current = current, [i]+[0]*n
for j in range(1,n+1):
add, delete = previous[j]+1, current[j-1]+1
change = previous[j-1]
if a[j-1] != b[i-1]:
change = change + 1
current[j] = min(add, delete, change)
return current[n]
def synch_original_prompt (self):
"""This attempts to find the prompt. Basically, press enter and record
the response; press enter again and record the response; if the two
responses are similar then assume we are at the original prompt. """
# All of these timing pace values are magic.
# I came up with these based on what seemed reliable for
# connecting to a heavily loaded machine I have.
# If latency is worse than these values then this will fail.
self.read_nonblocking(size=10000,timeout=1) # GAS: Clear out the cache before getting the prompt
time.sleep(0.1)
self.sendline()
time.sleep(0.5)
x = self.read_nonblocking(size=1000,timeout=1)
time.sleep(0.1)
self.sendline()
time.sleep(0.5)
a = self.read_nonblocking(size=1000,timeout=1)
time.sleep(0.1)
self.sendline()
time.sleep(0.5)
b = self.read_nonblocking(size=1000,timeout=1)
ld = self.levenshtein_distance(a,b)
len_a = len(a)
if len_a == 0:
return False
if float(ld)/len_a < 0.4:
return True
return False
### TODO: This is getting messy and I'm pretty sure this isn't perfect.
### TODO: I need to draw a flow chart for this.
def login (self,server,username,password='',terminal_type='ansi',original_prompt=r"[#$]",login_timeout=10,port=None,auto_prompt_reset=True):
"""This logs the user into the given server. It uses the
'original_prompt' to try to find the prompt right after login. When it
finds the prompt it immediately tries to reset the prompt to something
more easily matched. The default 'original_prompt' is very optimistic
and is easily fooled. It's more reliable to try to match the original
prompt as exactly as possible to prevent false matches by server
strings such as the "Message Of The Day". On many systems you can
disable the MOTD on the remote server by creating a zero-length file
called "~/.hushlogin" on the remote server. If a prompt cannot be found
then this will not necessarily cause the login to fail. In the case of
a timeout when looking for the prompt we assume that the original
prompt was so weird that we could not match it, so we use a few tricks
to guess when we have reached the prompt. Then we hope for the best and
blindly try to reset the prompt to something more unique. If that fails
then login() raises an ExceptionPxssh exception.
In some situations it is not possible or desirable to reset the
original prompt. In this case, set 'auto_prompt_reset' to False to
inhibit setting the prompt to the UNIQUE_PROMPT. Remember that pxssh
uses a unique prompt in the prompt() method. If the original prompt is
not reset then this will disable the prompt() method unless you
manually set the PROMPT attribute. """
ssh_options = '-q'
if self.force_password:
ssh_options = ssh_options + ' ' + self.SSH_OPTS
if port is not None:
ssh_options = ssh_options + ' -p %s'%(str(port))
cmd = "ssh %s -l %s %s" % (ssh_options, username, server)
# This does not distinguish between a remote server 'password' prompt
# and a local ssh 'passphrase' prompt (for unlocking a private key).
spawn._spawn(self, cmd)
i = self.expect(["(?i)are you sure you want to continue connecting", original_prompt, "(?i)(?:password)|(?:passphrase for key)", "(?i)permission denied", "(?i)terminal type", TIMEOUT, "(?i)connection closed by remote host"], timeout=login_timeout)
# First phase
if i==0:
# New certificate -- always accept it.
# This is what you get if SSH does not have the remote host's
# public key stored in the 'known_hosts' cache.
self.sendline("yes")
i = self.expect(["(?i)are you sure you want to continue connecting", original_prompt, "(?i)(?:password)|(?:passphrase for key)", "(?i)permission denied", "(?i)terminal type", TIMEOUT])
if i==2: # password or passphrase
self.sendline(password)
i = self.expect(["(?i)are you sure you want to continue connecting", original_prompt, "(?i)(?:password)|(?:passphrase for key)", "(?i)permission denied", "(?i)terminal type", TIMEOUT])
if i==4:
self.sendline(terminal_type)
i = self.expect(["(?i)are you sure you want to continue connecting", original_prompt, "(?i)(?:password)|(?:passphrase for key)", "(?i)permission denied", "(?i)terminal type", TIMEOUT])
# Second phase
if i==0:
# This is weird. This should not happen twice in a row.
self.close()
raise ExceptionPxssh ('Weird error. Got "are you sure" prompt twice.')
elif i==1: # can occur if you have a public key pair set to authenticate.
### TODO: May NOT be OK if expect() got tricked and matched a false prompt.
pass
elif i==2: # password prompt again
# For incorrect passwords, some ssh servers will
# ask for the password again, others return 'denied' right away.
# If we get the password prompt again then this means
# we didn't get the password right the first time.
self.close()
raise ExceptionPxssh ('password refused')
elif i==3: # permission denied -- password was bad.
self.close()
raise ExceptionPxssh ('permission denied')
elif i==4: # terminal type again? WTF?
self.close()
raise ExceptionPxssh ('Weird error. Got "terminal type" prompt twice.')
elif i==5: # Timeout
#This is tricky... I presume that we are at the command-line prompt.
#It may be that the shell prompt was so weird that we couldn't match
#it. Or it may be that we couldn't log in for some other reason. I
#can't be sure, but it's safe to guess that we did login because if
#I presume wrong and we are not logged in then this should be caught
#later when I try to set the shell prompt.
pass
elif i==6: # Connection closed by remote host
self.close()
raise ExceptionPxssh ('connection closed')
else: # Unexpected
self.close()
raise ExceptionPxssh ('unexpected login response')
if not self.synch_original_prompt():
self.close()
raise ExceptionPxssh ('could not synchronize with original prompt')
# We appear to be in.
# set shell prompt to something unique.
if auto_prompt_reset:
if not self.set_unique_prompt():
self.close()
raise ExceptionPxssh ('could not set shell prompt\n'+self.before)
return True
def logout (self):
"""This sends exit to the remote shell. If there are stopped jobs then
this automatically sends exit twice. """
self.sendline("exit")
index = self.expect([EOF, "(?i)there are stopped jobs"])
if index==1:
self.sendline("exit")
self.expect(EOF)
self.close()
def prompt (self, timeout=20):
"""This matches the shell prompt. This is little more than a short-cut
to the expect() method. This returns True if the shell prompt was
matched. This returns False if there was a timeout. Note that if you
called login() with auto_prompt_reset set to False then you should have
manually set the PROMPT attribute to a regex pattern for matching the
prompt. """
i = self.expect([self.PROMPT, TIMEOUT], timeout=timeout)
if i==1:
return False
return True
def set_unique_prompt (self):
"""This sets the remote prompt to something more unique than # or $.
This makes it easier for the prompt() method to match the shell prompt
unambiguously. This method is called automatically by the login()
method, but you may want to call it manually if you somehow reset the
shell prompt. For example, if you 'su' to a different user then you
will need to manually reset the prompt. This sends shell commands to
the remote host to set the prompt, so this assumes the remote host is
ready to receive commands.
Alternatively, you may use your own prompt pattern. Just set the PROMPT
attribute to a regular expression that matches it. In this case you
should call login() with auto_prompt_reset=False; then set the PROMPT
attribute. After that the prompt() method will try to match your prompt
pattern."""
self.sendline ("unset PROMPT_COMMAND")
self.sendline (self.PROMPT_SET_SH) # sh-style
i = self.expect ([TIMEOUT, self.PROMPT], timeout=10)
if i == 0: # csh-style
self.sendline (self.PROMPT_SET_CSH)
i = self.expect ([TIMEOUT, self.PROMPT], timeout=10)
if i == 0:
return False
return True
# vi:ts=4:sw=4:expandtab:ft=python:
|
gpl-3.0
|
[
624,
2765,
1021,
16879,
28855,
14,
10212,
370,
4539,
794,
4260,
1536,
12027,
6947,
14,
199,
2765,
9584,
3102,
367,
4676,
12,
22079,
12,
436,
21055,
314,
5218,
8457,
14,
199,
199,
4,
1304,
26,
21162,
5510,
14,
647,
841,
1555,
10219,
13,
2036,
13,
1398,
6928,
26,
1153,
26,
1398,
58,
949,
11326,
2672,
199,
624,
199,
199,
504,
28855,
492,
627,
199,
646,
28855,
199,
646,
900,
199,
199,
363,
452,
363,
275,
788,
1726,
48,
88,
5510,
297,
283,
5326,
5510,
418,
199,
199,
3,
2186,
3992,
1202,
701,
642,
859,
14,
199,
533,
2186,
48,
88,
5510,
8,
1726,
48,
4921,
304,
272,
408,
16894,
367,
21162,
5510,
4967,
14,
272,
408,
199,
199,
533,
21162,
5510,
334,
10212,
304,
339,
408,
2765,
1021,
16879,
28855,
14,
10212,
370,
4539,
794,
4260,
1536,
12027,
272,
6947,
14,
961,
9584,
3102,
367,
4676,
12,
22079,
12,
436,
21055,
314,
5218,
272,
8457,
14,
2779,
1630,
7750,
32553,
7645,
370,
2429,
5002,
24325,
315,
314,
12027,
272,
4676,
2112,
14,
2104,
2893,
12,
340,
314,
2351,
365,
2195,
1642,
4676,
12,
2066,
21162,
5510,
272,
5847,
11479,
314,
3982,
5897,
27,
503,
340,
1265,
1172,
4575,
790,
272,
6299,
3272,
2066,
21162,
5510,
7859,
1133,
3618,
367,
314,
2505,
8457,
14,
339,
21162,
5510,
4440,
314,
5218,
8457,
370,
31021,
1072,
687,
314,
3982,
1591,
14,
1010,
272,
1865,
370,
1852,
642,
1655,
23399,
652,
5951,
314,
5218,
8457,
370,
6020,
1655,
272,
3747,
2419,
2951,
2672,
503,
327,
14,
961,
1077,
1736,
641,
4750,
699,
269,
685,
15,
34,
1119,
503,
445,
609,
3449,
272,
1033,
6840,
14,
339,
5679,
626,
7858,
282,
9284,
3718,
641,
282,
3982,
1654,
436,
14767,
314,
754,
447,
2728,
492,
21162,
5510,
267,
492,
18354,
267,
862,
26,
2476,
17907,
288,
308,
275,
21162,
5510,
14,
5326,
5510,
342,
288,
6246,
275,
3066,
63,
1210,
360,
4269,
26,
5320,
288,
3434,
275,
3066,
63,
1210,
360,
2473,
26,
5320,
288,
2505,
275,
18354,
14,
27481,
360,
2060,
26,
5320,
288,
308,
14,
2886,
334,
4269,
12,
3434,
12,
2505,
9,
288,
308,
14,
29857,
661,
24853,
358,
221,
327,
1255,
282,
1414,
288,
308,
14,
7650,
342,
3777,
327,
1336,
314,
8457,
288,
870,
308,
14,
5182,
260,
327,
870,
8137,
2544,
314,
8457,
14,
288,
308,
14,
29857,
661,
478,
446,
76,
358,
288,
308,
14,
7650,
342,
288,
870,
308,
14,
5182,
288,
308,
14,
29857,
661,
1587,
358,
288,
308,
14,
7650,
342,
288,
870,
308,
14,
5182,
288,
308,
14,
11646,
342,
267,
871,
21162,
5510,
14,
1726,
48,
88,
5510,
12,
325,
26,
288,
870,
298,
5326,
5510,
3405,
641,
4676,
2122,
288,
870,
620,
8,
69,
9,
339,
3390,
626,
340,
1265,
1172,
8635,
13,
4054,
3879,
1830,
9689,
16367,
543,
21162,
5510,
272,
2066,
642,
883,
12690,
370,
282,
13918,
402,
26314,
14,
15517,
1323,
2929,
19680,
334,
2207,
77,
12,
272,
486,
6428,
12,
1022,
6428,
12,
5423,
4959,
911,
5847,
1343,
282,
17160,
6631,
14,
2047,
1443,
1937,
282,
17160,
272,
9592,
5689,
22365,
7198,
316,
367,
282,
2505,
5309,
16367,
14,
2047,
1077,
7485,
272,
2331,
1263,
790,
22867,
5309,
5343,
14,
710,
283,
3990,
63,
2060,
7,
2225,
911,
7485,
272,
2331,
4575,
790,
6299,
14,
961,
911,
1454,
1736,
340,
314,
3982,
12027,
1654,
272,
365,
7526,
370,
2040,
2505,
4676,
83,
14,
5679,
402,
1808,
283,
3990,
63,
2060,
7,
272,
2225,
447,
953,
308,
275,
21162,
5510,
14,
5326,
5510,
342,
288,
308,
14,
3990,
63,
2060,
275,
715,
288,
6246,
275,
3066,
63,
1210,
360,
4269,
26,
5320,
288,
3434,
275,
3066,
63,
1210,
360,
2473,
26,
5320,
288,
2505,
275,
18354,
14,
27481,
360,
2060,
26,
5320,
288,
308,
14,
2886,
334,
4269,
12,
3434,
12,
2505,
9,
272,
408,
339,
347,
636,
826,
363,
334,
277,
12,
2653,
29,
1216,
12,
1390,
739,
29,
8269,
12,
2754,
3806,
890,
29,
403,
12,
17251,
29,
403,
12,
8288,
29,
403,
12,
2589,
29,
403,
304,
267,
15187,
855,
826,
721,
277,
12,
488,
12,
2653,
29,
2593,
12,
1390,
739,
29,
988,
739,
12,
2754,
3806,
890,
29,
1733,
3806,
890,
12,
17251,
29,
12804,
12,
8288,
29,
6525,
12,
2589,
29,
1813,
9,
398,
291,
14,
354,
275,
2650,
5326,
5510,
3524,
2728,
327,
6348,
52,
906,
31697,
12112,
5397,
1,
3390,
626,
314,
1414,
370,
663,
314,
8457,
4440,
282,
267,
327,
83,
4040,
590,
3365,
1059,
2419,
314,
5578,
3965,
370,
1336,
652,
14,
961,
267,
327,
374,
2952,
1380,
1265,
663,
314,
8457,
314,
1414,
911,
11343,
1771,
12,
1325,
781,
267,
327,
13196,
1133,
2934,
370,
1336,
314,
11343,
379,
1414,
14,
2002,
340,
781,
1852,
314,
663,
1414,
267,
327,
83,
4040,
590,
3365,
2419,
314,
5163,
781,
20714,
323,
314,
5160,
14,
4005,
1852,
314,
267,
327,
409,
1414,
3365,
781,
1050,
282,
13831,
315,
13738,
402,
2672,
14,
710,
2672,
3181,
1133,
267,
327,
9321,
370,
506,
11077,
12,
1325,
652,
3181,
1133,
394,
20471,
436,
23739,
370,
1852,
314,
663,
267,
327,
7650,
1414,
3365,
2419,
314,
5163,
14,
398,
327,
1202,
370,
1336,
314,
1414,
13,
604,
8457,
267,
291,
14,
28060,
63,
2514,
26178,
275,
1867,
59,
48,
16957,
60,
30679,
16827,
3,
61,
298,
267,
291,
14,
2514,
26178,
275,
291,
14,
28060,
63,
2514,
26178,
398,
327,
1202,
370,
663,
5218,
1414,
13,
604,
8457,
370,
6778,
41,
10526,
63,
2514,
26178,
14,
267,
291,
14,
2514,
26178,
63,
3597,
63,
3234,
275,
298,
5067,
17,
30845,
48,
16957,
7272,
4,
5522,
267,
291,
14,
2514,
26178,
63,
3597,
63,
35,
3234,
275,
298,
409,
8457,
30845,
48,
16957,
7272,
4,
5522,
267,
291,
14,
13716,
63,
25636,
275,
3905,
79,
7,
15062,
2276,
762,
4101,
29,
889,
7,
446,
79,
283,
18060,
498,
10348,
29,
889,
4065,
267,
327,
5289,
14744,
1323,
845,
24119,
7545,
16146,
402,
314,
22984,
22440,
12027,
63,
7946,
6909,
687,
267,
327,
20589,
282,
17160,
2505,
9592,
14,
473,
1172,
440,
6085,
3297,
734,
4212,
370,
267,
327,
3507,
1454,
12027,
63,
7946,
6909,
1928,
2597,
30723,
1323,
845,
24119
] |
[
2765,
1021,
16879,
28855,
14,
10212,
370,
4539,
794,
4260,
1536,
12027,
6947,
14,
199,
2765,
9584,
3102,
367,
4676,
12,
22079,
12,
436,
21055,
314,
5218,
8457,
14,
199,
199,
4,
1304,
26,
21162,
5510,
14,
647,
841,
1555,
10219,
13,
2036,
13,
1398,
6928,
26,
1153,
26,
1398,
58,
949,
11326,
2672,
199,
624,
199,
199,
504,
28855,
492,
627,
199,
646,
28855,
199,
646,
900,
199,
199,
363,
452,
363,
275,
788,
1726,
48,
88,
5510,
297,
283,
5326,
5510,
418,
199,
199,
3,
2186,
3992,
1202,
701,
642,
859,
14,
199,
533,
2186,
48,
88,
5510,
8,
1726,
48,
4921,
304,
272,
408,
16894,
367,
21162,
5510,
4967,
14,
272,
408,
199,
199,
533,
21162,
5510,
334,
10212,
304,
339,
408,
2765,
1021,
16879,
28855,
14,
10212,
370,
4539,
794,
4260,
1536,
12027,
272,
6947,
14,
961,
9584,
3102,
367,
4676,
12,
22079,
12,
436,
21055,
314,
5218,
272,
8457,
14,
2779,
1630,
7750,
32553,
7645,
370,
2429,
5002,
24325,
315,
314,
12027,
272,
4676,
2112,
14,
2104,
2893,
12,
340,
314,
2351,
365,
2195,
1642,
4676,
12,
2066,
21162,
5510,
272,
5847,
11479,
314,
3982,
5897,
27,
503,
340,
1265,
1172,
4575,
790,
272,
6299,
3272,
2066,
21162,
5510,
7859,
1133,
3618,
367,
314,
2505,
8457,
14,
339,
21162,
5510,
4440,
314,
5218,
8457,
370,
31021,
1072,
687,
314,
3982,
1591,
14,
1010,
272,
1865,
370,
1852,
642,
1655,
23399,
652,
5951,
314,
5218,
8457,
370,
6020,
1655,
272,
3747,
2419,
2951,
2672,
503,
327,
14,
961,
1077,
1736,
641,
4750,
699,
269,
685,
15,
34,
1119,
503,
445,
609,
3449,
272,
1033,
6840,
14,
339,
5679,
626,
7858,
282,
9284,
3718,
641,
282,
3982,
1654,
436,
14767,
314,
754,
447,
2728,
492,
21162,
5510,
267,
492,
18354,
267,
862,
26,
2476,
17907,
288,
308,
275,
21162,
5510,
14,
5326,
5510,
342,
288,
6246,
275,
3066,
63,
1210,
360,
4269,
26,
5320,
288,
3434,
275,
3066,
63,
1210,
360,
2473,
26,
5320,
288,
2505,
275,
18354,
14,
27481,
360,
2060,
26,
5320,
288,
308,
14,
2886,
334,
4269,
12,
3434,
12,
2505,
9,
288,
308,
14,
29857,
661,
24853,
358,
221,
327,
1255,
282,
1414,
288,
308,
14,
7650,
342,
3777,
327,
1336,
314,
8457,
288,
870,
308,
14,
5182,
260,
327,
870,
8137,
2544,
314,
8457,
14,
288,
308,
14,
29857,
661,
478,
446,
76,
358,
288,
308,
14,
7650,
342,
288,
870,
308,
14,
5182,
288,
308,
14,
29857,
661,
1587,
358,
288,
308,
14,
7650,
342,
288,
870,
308,
14,
5182,
288,
308,
14,
11646,
342,
267,
871,
21162,
5510,
14,
1726,
48,
88,
5510,
12,
325,
26,
288,
870,
298,
5326,
5510,
3405,
641,
4676,
2122,
288,
870,
620,
8,
69,
9,
339,
3390,
626,
340,
1265,
1172,
8635,
13,
4054,
3879,
1830,
9689,
16367,
543,
21162,
5510,
272,
2066,
642,
883,
12690,
370,
282,
13918,
402,
26314,
14,
15517,
1323,
2929,
19680,
334,
2207,
77,
12,
272,
486,
6428,
12,
1022,
6428,
12,
5423,
4959,
911,
5847,
1343,
282,
17160,
6631,
14,
2047,
1443,
1937,
282,
17160,
272,
9592,
5689,
22365,
7198,
316,
367,
282,
2505,
5309,
16367,
14,
2047,
1077,
7485,
272,
2331,
1263,
790,
22867,
5309,
5343,
14,
710,
283,
3990,
63,
2060,
7,
2225,
911,
7485,
272,
2331,
4575,
790,
6299,
14,
961,
911,
1454,
1736,
340,
314,
3982,
12027,
1654,
272,
365,
7526,
370,
2040,
2505,
4676,
83,
14,
5679,
402,
1808,
283,
3990,
63,
2060,
7,
272,
2225,
447,
953,
308,
275,
21162,
5510,
14,
5326,
5510,
342,
288,
308,
14,
3990,
63,
2060,
275,
715,
288,
6246,
275,
3066,
63,
1210,
360,
4269,
26,
5320,
288,
3434,
275,
3066,
63,
1210,
360,
2473,
26,
5320,
288,
2505,
275,
18354,
14,
27481,
360,
2060,
26,
5320,
288,
308,
14,
2886,
334,
4269,
12,
3434,
12,
2505,
9,
272,
408,
339,
347,
636,
826,
363,
334,
277,
12,
2653,
29,
1216,
12,
1390,
739,
29,
8269,
12,
2754,
3806,
890,
29,
403,
12,
17251,
29,
403,
12,
8288,
29,
403,
12,
2589,
29,
403,
304,
267,
15187,
855,
826,
721,
277,
12,
488,
12,
2653,
29,
2593,
12,
1390,
739,
29,
988,
739,
12,
2754,
3806,
890,
29,
1733,
3806,
890,
12,
17251,
29,
12804,
12,
8288,
29,
6525,
12,
2589,
29,
1813,
9,
398,
291,
14,
354,
275,
2650,
5326,
5510,
3524,
2728,
327,
6348,
52,
906,
31697,
12112,
5397,
1,
3390,
626,
314,
1414,
370,
663,
314,
8457,
4440,
282,
267,
327,
83,
4040,
590,
3365,
1059,
2419,
314,
5578,
3965,
370,
1336,
652,
14,
961,
267,
327,
374,
2952,
1380,
1265,
663,
314,
8457,
314,
1414,
911,
11343,
1771,
12,
1325,
781,
267,
327,
13196,
1133,
2934,
370,
1336,
314,
11343,
379,
1414,
14,
2002,
340,
781,
1852,
314,
663,
1414,
267,
327,
83,
4040,
590,
3365,
2419,
314,
5163,
781,
20714,
323,
314,
5160,
14,
4005,
1852,
314,
267,
327,
409,
1414,
3365,
781,
1050,
282,
13831,
315,
13738,
402,
2672,
14,
710,
2672,
3181,
1133,
267,
327,
9321,
370,
506,
11077,
12,
1325,
652,
3181,
1133,
394,
20471,
436,
23739,
370,
1852,
314,
663,
267,
327,
7650,
1414,
3365,
2419,
314,
5163,
14,
398,
327,
1202,
370,
1336,
314,
1414,
13,
604,
8457,
267,
291,
14,
28060,
63,
2514,
26178,
275,
1867,
59,
48,
16957,
60,
30679,
16827,
3,
61,
298,
267,
291,
14,
2514,
26178,
275,
291,
14,
28060,
63,
2514,
26178,
398,
327,
1202,
370,
663,
5218,
1414,
13,
604,
8457,
370,
6778,
41,
10526,
63,
2514,
26178,
14,
267,
291,
14,
2514,
26178,
63,
3597,
63,
3234,
275,
298,
5067,
17,
30845,
48,
16957,
7272,
4,
5522,
267,
291,
14,
2514,
26178,
63,
3597,
63,
35,
3234,
275,
298,
409,
8457,
30845,
48,
16957,
7272,
4,
5522,
267,
291,
14,
13716,
63,
25636,
275,
3905,
79,
7,
15062,
2276,
762,
4101,
29,
889,
7,
446,
79,
283,
18060,
498,
10348,
29,
889,
4065,
267,
327,
5289,
14744,
1323,
845,
24119,
7545,
16146,
402,
314,
22984,
22440,
12027,
63,
7946,
6909,
687,
267,
327,
20589,
282,
17160,
2505,
9592,
14,
473,
1172,
440,
6085,
3297,
734,
4212,
370,
267,
327,
3507,
1454,
12027,
63,
7946,
6909,
1928,
2597,
30723,
1323,
845,
24119,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dmsurti/reynolds-blender
|
reynolds_blender/add_block.py
|
1
|
4877
|
#------------------------------------------------------------------------------
# Reynolds-Blender | The Blender add-on for Reynolds, an OpenFoam toolbox.
#------------------------------------------------------------------------------
# Copyright|
#------------------------------------------------------------------------------
# Deepak Surti (dmsurti@gmail.com)
# Prabhu R (IIT Bombay, prabhu@aero.iitb.ac.in)
# Shivasubramanian G (IIT Bombay, sgopalak@iitb.ac.in)
#------------------------------------------------------------------------------
# License
#
# This file is part of reynolds-blender.
#
# reynolds-blender 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.
#
# reynolds-blender 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 reynolds-blender. If not, see <http://www.gnu.org/licenses/>.
#------------------------------------------------------------------------------
# -----------
# bpy imports
# -----------
import bpy, bmesh
from bpy.props import (StringProperty,
BoolProperty,
IntProperty,
FloatProperty,
EnumProperty,
PointerProperty,
IntVectorProperty,
FloatVectorProperty,
CollectionProperty
)
from bpy.types import (Panel,
Operator,
PropertyGroup,
UIList
)
from bpy.path import abspath
from mathutils import Matrix, Vector
# --------------
# python imports
# --------------
import operator
import os
# ------------------------
# reynolds blender imports
# ------------------------
from reynolds_blender.gui.register import register_classes, unregister_classes
from reynolds_blender.gui.attrs import set_scene_attrs, del_scene_attrs
from reynolds_blender.gui.custom_operator import create_custom_operators
from reynolds_blender.gui.renderer import ReynoldsGUIRenderer
# ----------------
# reynolds imports
# ----------------
from reynolds.dict.parser import ReynoldsFoamDict
from reynolds.foam.cmd_runner import FoamCmdRunner
# ------------------------------------------------------------------------
# operators
# ------------------------------------------------------------------------
def add_block(self, context):
print(' Add block ')
scene = context.scene
w = scene.block_width
h = scene.block_height
t = scene.block_thickness
bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0))
bpy.ops.transform.resize(value=(w / 2, t / 2, h / 2))
bpy.ops.transform.translate(value=(w / 2, t / 2, h / 2))
bpy.ops.object.transform_apply(location=True, rotation=False, scale=True)
return {'FINISHED'}
# ------------------------------------------------------------------------
# Panel
# ------------------------------------------------------------------------
class BlockMeshAddOperator(bpy.types.Operator):
bl_idname = "reynolds.of_bmd_add_panel"
bl_label = "Add block of given widht, height, thickness"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_category = "Tools"
bl_context = "objectmode"
@classmethod
def poll(cls, context):
return True
def execute(self, context):
return {'FINISHED'}
# Return True to force redraw
def check(self, context):
return True
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self, width=700)
def draw(self, context):
layout = self.layout
scene = context.scene
# ---------------------------------------
# Render Block Cells using YAML GUI Spec
# ---------------------------------------
gui_renderer = ReynoldsGUIRenderer(scene, layout,
'add_block.yaml')
gui_renderer.render()
# ------------------------------------------------------------------------
# register and unregister
# ------------------------------------------------------------------------
def register():
register_classes(__name__)
set_scene_attrs('add_block.yaml')
create_custom_operators('add_block.yaml', __name__)
def unregister():
unregister_classes(__name__)
del_scene_attrs('add_block.yaml')
if __name__ == "__main__":
register()
|
gpl-3.0
|
[
20974,
199,
3,
799,
1236,
8250,
13,
34,
24912,
1204,
710,
699,
24912,
1050,
13,
265,
367,
799,
1236,
8250,
12,
376,
3232,
15563,
455,
4744,
1977,
14,
199,
20974,
199,
3,
1898,
92,
199,
20974,
199,
3,
258,
577,
1024,
22460,
17079,
280,
755,
334,
68,
706,
300,
280,
32,
6799,
14,
957,
9,
199,
3,
258,
510,
14411,
10616,
820,
3698,
334,
41,
649,
699,
676,
19558,
12,
299,
14411,
10616,
32,
65,
3478,
14,
73,
390,
66,
14,
645,
14,
262,
9,
199,
3,
258,
5244,
1003,
305,
456,
345,
1237,
5653,
598,
334,
41,
649,
699,
676,
19558,
12,
12578,
411,
279,
1151,
32,
73,
390,
66,
14,
645,
14,
262,
9,
199,
20974,
199,
3,
844,
199,
3,
199,
3,
258,
961,
570,
365,
1777,
402,
295,
1236,
8250,
13,
66,
24912,
14,
199,
3,
199,
3,
258,
295,
1236,
8250,
13,
66,
24912,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
258,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
258,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
258,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
258,
295,
1236,
8250,
13,
66,
24912,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
258,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
258,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
199,
3,
258,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
258,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
258,
3180,
543,
295,
1236,
8250,
13,
66,
24912,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
20974,
199,
199,
3,
3001,
2595,
199,
3,
20575,
8925,
199,
3,
3001,
2595,
199,
646,
20575,
12,
330,
6480,
199,
504,
20575,
14,
6750,
492,
334,
31821,
12,
2432,
19287,
3697,
12,
2432,
9805,
3697,
12,
2432,
11140,
3697,
12,
2432,
11305,
3697,
12,
2432,
28833,
3697,
12,
2432,
9805,
3646,
3697,
12,
2432,
11140,
3646,
3697,
12,
2432,
18003,
3697,
2432,
776,
199,
504,
20575,
14,
1313,
492,
334,
10185,
12,
2432,
11013,
12,
2432,
16158,
2448,
12,
2432,
738,
1193,
631,
2432,
776,
199,
504,
20575,
14,
515,
492,
19529,
199,
504,
3473,
1208,
492,
8449,
12,
11388,
199,
199,
3,
3001,
8648,
199,
3,
2366,
8925,
199,
3,
3001,
8648,
199,
646,
4182,
199,
646,
747,
199,
199,
3,
10652,
518,
199,
3,
295,
1236,
8250,
330,
24912,
8925,
199,
3,
10652,
518,
199,
199,
504,
295,
1236,
8250,
63,
66,
24912,
14,
5885,
14,
2683,
492,
2274,
63,
2888,
12,
24369,
63,
2888,
199,
504,
295,
1236,
8250,
63,
66,
24912,
14,
5885,
14,
3288,
492,
663,
63,
10436,
63,
3288,
12,
2150,
63,
10436,
63,
3288,
199,
504,
295,
1236,
8250,
63,
66,
24912,
14,
5885,
14,
4229,
63,
3856,
492,
1218,
63,
4229,
63,
12688,
199,
504,
295,
1236,
8250,
63,
66,
24912,
14,
5885,
14,
12471,
492,
799,
1236,
8250,
17188,
3927,
287,
5813,
199,
199,
3,
10652,
199,
3,
295,
1236,
8250,
8925,
199,
3,
10652,
199,
504,
295,
1236,
8250,
14,
807,
14,
2087,
492,
799,
1236,
8250,
15563,
455,
2141,
199,
504,
295,
1236,
8250,
14,
545,
455,
14,
1760,
63,
5933,
492,
481,
79,
455,
7874,
7446,
199,
199,
3,
5620,
518,
199,
3,
259,
10211,
199,
3,
5620,
518,
199,
199,
318,
1050,
63,
1457,
8,
277,
12,
1067,
304,
272,
870,
360,
2654,
1853,
5320,
272,
13856,
275,
1067,
14,
10436,
339,
336,
275,
13856,
14,
1457,
63,
2063,
272,
394,
275,
13856,
14,
1457,
63,
3333,
272,
307,
275,
13856,
14,
1457,
63,
26199,
339,
20575,
14,
1483,
14,
6480,
14,
16161,
63,
11477,
63,
525,
8,
1985,
2687,
16,
12,
378,
12,
378,
430,
272,
20575,
14,
1483,
14,
4711,
14,
8709,
8,
585,
2687,
87,
1182,
499,
12,
307,
1182,
499,
12,
394,
1182,
499,
430,
272,
20575,
14,
1483,
14,
4711,
14,
5275,
8,
585,
2687,
87,
1182,
499,
12,
307,
1182,
499,
12,
394,
1182,
499,
430,
272,
20575,
14,
1483,
14,
785,
14,
4711,
63,
4998,
8,
1985,
29,
549,
12,
13038,
29,
797,
12,
4666,
29,
549,
9,
272,
372,
791,
17383,
20450,
936,
199,
199,
3,
5620,
518,
199,
3,
259,
510,
4822,
199,
3,
5620,
518,
199,
199,
533,
8651,
12241,
1123,
7961,
8,
66,
647,
14,
1313,
14,
7961,
304,
272,
6826,
63,
344,
354,
275,
298,
264,
1236,
8250,
14,
1618,
63,
66,
1064,
63,
525,
63,
7885,
2,
272,
6826,
63,
1302,
275,
298,
1123,
1853,
402,
1627,
336,
344,
517,
12,
4569,
12,
294,
17437,
2,
272,
6826,
63,
2638,
63,
466,
275,
298,
12058,
63,
19,
36,
2,
272,
6826,
63,
4551,
63,
466,
275,
298,
20261,
2,
272,
6826,
63,
3710,
275,
298,
11654,
2,
272,
6826,
63,
1100,
275,
298,
785,
632,
2,
339,
768,
3744,
272,
347,
11271,
8,
1886,
12,
1067,
304,
267,
372,
715,
339,
347,
5341,
8,
277,
12,
1067,
304,
267,
372,
791,
17383,
20450,
936,
339,
327,
1432,
715,
370,
3542,
295,
5485,
272,
347,
1104,
8,
277,
12,
1067,
304,
267,
372,
715,
339,
347,
12677,
8,
277,
12,
1067,
12,
1566,
304,
267,
372,
1067,
14,
3806,
63,
2609,
14,
15195,
63,
6750,
63,
7196,
8,
277,
12,
3462,
29,
15946,
9,
339,
347,
5954,
8,
277,
12,
1067,
304,
267,
7054,
275,
291,
14,
4209,
267,
13856,
275,
1067,
14,
10436,
398,
327,
11016,
12797,
267,
327,
17769,
8651,
445,
6840,
1808,
18916,
17160,
31511,
267,
327,
11016,
12797,
398,
11621,
63,
12471,
275,
799,
1236,
8250,
17188,
3927,
287,
5813,
8,
10436,
12,
7054,
12,
5644,
283,
525,
63,
1457,
14,
5963,
358,
267,
11621,
63,
12471,
14,
3352,
342,
421,
199,
3,
5620,
518,
199,
3,
2274,
436,
24369,
199,
3,
5620,
518,
199,
199,
318,
2274,
837,
272,
2274,
63,
2888,
3460,
354,
3368,
272,
663,
63,
10436,
63,
3288
] |
[
199,
3,
799,
1236,
8250,
13,
34,
24912,
1204,
710,
699,
24912,
1050,
13,
265,
367,
799,
1236,
8250,
12,
376,
3232,
15563,
455,
4744,
1977,
14,
199,
20974,
199,
3,
1898,
92,
199,
20974,
199,
3,
258,
577,
1024,
22460,
17079,
280,
755,
334,
68,
706,
300,
280,
32,
6799,
14,
957,
9,
199,
3,
258,
510,
14411,
10616,
820,
3698,
334,
41,
649,
699,
676,
19558,
12,
299,
14411,
10616,
32,
65,
3478,
14,
73,
390,
66,
14,
645,
14,
262,
9,
199,
3,
258,
5244,
1003,
305,
456,
345,
1237,
5653,
598,
334,
41,
649,
699,
676,
19558,
12,
12578,
411,
279,
1151,
32,
73,
390,
66,
14,
645,
14,
262,
9,
199,
20974,
199,
3,
844,
199,
3,
199,
3,
258,
961,
570,
365,
1777,
402,
295,
1236,
8250,
13,
66,
24912,
14,
199,
3,
199,
3,
258,
295,
1236,
8250,
13,
66,
24912,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
258,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
258,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
258,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
258,
295,
1236,
8250,
13,
66,
24912,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
258,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
258,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
199,
3,
258,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
258,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
258,
3180,
543,
295,
1236,
8250,
13,
66,
24912,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
20974,
199,
199,
3,
3001,
2595,
199,
3,
20575,
8925,
199,
3,
3001,
2595,
199,
646,
20575,
12,
330,
6480,
199,
504,
20575,
14,
6750,
492,
334,
31821,
12,
2432,
19287,
3697,
12,
2432,
9805,
3697,
12,
2432,
11140,
3697,
12,
2432,
11305,
3697,
12,
2432,
28833,
3697,
12,
2432,
9805,
3646,
3697,
12,
2432,
11140,
3646,
3697,
12,
2432,
18003,
3697,
2432,
776,
199,
504,
20575,
14,
1313,
492,
334,
10185,
12,
2432,
11013,
12,
2432,
16158,
2448,
12,
2432,
738,
1193,
631,
2432,
776,
199,
504,
20575,
14,
515,
492,
19529,
199,
504,
3473,
1208,
492,
8449,
12,
11388,
199,
199,
3,
3001,
8648,
199,
3,
2366,
8925,
199,
3,
3001,
8648,
199,
646,
4182,
199,
646,
747,
199,
199,
3,
10652,
518,
199,
3,
295,
1236,
8250,
330,
24912,
8925,
199,
3,
10652,
518,
199,
199,
504,
295,
1236,
8250,
63,
66,
24912,
14,
5885,
14,
2683,
492,
2274,
63,
2888,
12,
24369,
63,
2888,
199,
504,
295,
1236,
8250,
63,
66,
24912,
14,
5885,
14,
3288,
492,
663,
63,
10436,
63,
3288,
12,
2150,
63,
10436,
63,
3288,
199,
504,
295,
1236,
8250,
63,
66,
24912,
14,
5885,
14,
4229,
63,
3856,
492,
1218,
63,
4229,
63,
12688,
199,
504,
295,
1236,
8250,
63,
66,
24912,
14,
5885,
14,
12471,
492,
799,
1236,
8250,
17188,
3927,
287,
5813,
199,
199,
3,
10652,
199,
3,
295,
1236,
8250,
8925,
199,
3,
10652,
199,
504,
295,
1236,
8250,
14,
807,
14,
2087,
492,
799,
1236,
8250,
15563,
455,
2141,
199,
504,
295,
1236,
8250,
14,
545,
455,
14,
1760,
63,
5933,
492,
481,
79,
455,
7874,
7446,
199,
199,
3,
5620,
518,
199,
3,
259,
10211,
199,
3,
5620,
518,
199,
199,
318,
1050,
63,
1457,
8,
277,
12,
1067,
304,
272,
870,
360,
2654,
1853,
5320,
272,
13856,
275,
1067,
14,
10436,
339,
336,
275,
13856,
14,
1457,
63,
2063,
272,
394,
275,
13856,
14,
1457,
63,
3333,
272,
307,
275,
13856,
14,
1457,
63,
26199,
339,
20575,
14,
1483,
14,
6480,
14,
16161,
63,
11477,
63,
525,
8,
1985,
2687,
16,
12,
378,
12,
378,
430,
272,
20575,
14,
1483,
14,
4711,
14,
8709,
8,
585,
2687,
87,
1182,
499,
12,
307,
1182,
499,
12,
394,
1182,
499,
430,
272,
20575,
14,
1483,
14,
4711,
14,
5275,
8,
585,
2687,
87,
1182,
499,
12,
307,
1182,
499,
12,
394,
1182,
499,
430,
272,
20575,
14,
1483,
14,
785,
14,
4711,
63,
4998,
8,
1985,
29,
549,
12,
13038,
29,
797,
12,
4666,
29,
549,
9,
272,
372,
791,
17383,
20450,
936,
199,
199,
3,
5620,
518,
199,
3,
259,
510,
4822,
199,
3,
5620,
518,
199,
199,
533,
8651,
12241,
1123,
7961,
8,
66,
647,
14,
1313,
14,
7961,
304,
272,
6826,
63,
344,
354,
275,
298,
264,
1236,
8250,
14,
1618,
63,
66,
1064,
63,
525,
63,
7885,
2,
272,
6826,
63,
1302,
275,
298,
1123,
1853,
402,
1627,
336,
344,
517,
12,
4569,
12,
294,
17437,
2,
272,
6826,
63,
2638,
63,
466,
275,
298,
12058,
63,
19,
36,
2,
272,
6826,
63,
4551,
63,
466,
275,
298,
20261,
2,
272,
6826,
63,
3710,
275,
298,
11654,
2,
272,
6826,
63,
1100,
275,
298,
785,
632,
2,
339,
768,
3744,
272,
347,
11271,
8,
1886,
12,
1067,
304,
267,
372,
715,
339,
347,
5341,
8,
277,
12,
1067,
304,
267,
372,
791,
17383,
20450,
936,
339,
327,
1432,
715,
370,
3542,
295,
5485,
272,
347,
1104,
8,
277,
12,
1067,
304,
267,
372,
715,
339,
347,
12677,
8,
277,
12,
1067,
12,
1566,
304,
267,
372,
1067,
14,
3806,
63,
2609,
14,
15195,
63,
6750,
63,
7196,
8,
277,
12,
3462,
29,
15946,
9,
339,
347,
5954,
8,
277,
12,
1067,
304,
267,
7054,
275,
291,
14,
4209,
267,
13856,
275,
1067,
14,
10436,
398,
327,
11016,
12797,
267,
327,
17769,
8651,
445,
6840,
1808,
18916,
17160,
31511,
267,
327,
11016,
12797,
398,
11621,
63,
12471,
275,
799,
1236,
8250,
17188,
3927,
287,
5813,
8,
10436,
12,
7054,
12,
5644,
283,
525,
63,
1457,
14,
5963,
358,
267,
11621,
63,
12471,
14,
3352,
342,
421,
199,
3,
5620,
518,
199,
3,
2274,
436,
24369,
199,
3,
5620,
518,
199,
199,
318,
2274,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mensi/cydra
|
cydra/web/themes.py
|
1
|
3596
|
# -*- coding: utf-8 -*-
#
# Copyright 2012 Manuel Stocker <mensi@mensi.ch>
#
# This file is part of Cydra.
#
# Cydra 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.
#
# Cydra 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 Cydra. If not, see http://www.gnu.org/licenses
import os.path
import types
import flask
from flask.globals import _request_ctx_stack
from flask.helpers import send_from_directory
from jinja2 import BaseLoader, TemplateNotFound, FileSystemLoader
from werkzeug.exceptions import NotFound
from cydra.component import Interface, BroadcastAttributeProxy
import logging
logger = logging.getLogger(__name__)
class IThemeProvider(Interface):
"""Components providing themes for the website"""
_iface_attribute_proxy = BroadcastAttributeProxy(merge_lists=True)
def get_themes(self):
"""Return an iterable with Theme instances"""
pass
class Theme(object):
def __init__(self, path, name=None):
if name is None:
name = os.path.basename(path)
self.name = name
self.template_path = os.path.join(path, 'templates')
self.static_path = os.path.join(path, 'static')
def get_blueprint_loader(self, blueprint_name):
return FileSystemLoader(os.path.join(self.template_path, blueprint_name))
def get_loader(self):
return FileSystemLoader(self.template_path)
def patch_static(obj, blueprint_name=''):
def themed_send_static_file(self, filename):
# do we have an active theme?
theme = None
if hasattr(flask.g, 'theme'):
theme = flask.g.theme
if theme is not None:
try:
return send_from_directory(os.path.join(theme.static_path, blueprint_name), filename)
except NotFound:
pass
if not self.has_static_folder:
raise RuntimeError('No static folder for this object')
return send_from_directory(self.static_folder, filename)
obj.send_static_file = types.MethodType(themed_send_static_file, obj)
class ThemedTemplateLoader(BaseLoader):
def __init__(self, app):
self.app = app
self.app_loader = app.jinja_loader
def get_source(self, environment, template):
for loader in self._iter_loaders():
try:
return loader.get_source(environment, template)
except TemplateNotFound:
pass
raise TemplateNotFound(template)
def _iter_loaders(self):
# do we have an active theme?
theme = None
if hasattr(flask.g, 'theme'):
theme = flask.g.theme
if theme is None:
logger.debug("No Theme found")
# is there an active blueprint?
bp = _request_ctx_stack.top.request.blueprint
if bp is not None and bp in self.app.blueprints:
bp = self.app.blueprints[bp]
logger.debug("Request in BP: %s", bp.name)
if theme is not None:
yield theme.get_blueprint_loader(bp.name)
yield bp.jinja_loader
if theme is not None:
yield theme.get_loader()
yield self.app_loader
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6029,
4688,
13086,
9785,
22043,
665,
1410,
338,
32,
1410,
338,
14,
335,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
18461,
28385,
14,
199,
3,
199,
3,
18461,
28385,
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,
18461,
28385,
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,
18461,
28385,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
199,
646,
747,
14,
515,
199,
646,
2943,
199,
646,
7209,
199,
504,
7209,
14,
8473,
492,
485,
1069,
63,
3799,
63,
2340,
199,
504,
7209,
14,
7546,
492,
3222,
63,
504,
63,
3619,
199,
504,
10321,
18,
492,
3523,
5455,
12,
5458,
4667,
12,
23754,
5455,
199,
504,
10380,
14,
3924,
492,
21909,
199,
199,
504,
6325,
28385,
14,
3173,
492,
14816,
12,
699,
5659,
1646,
4936,
199,
199,
646,
2050,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
533,
473,
16849,
6663,
8,
4267,
304,
272,
408,
22714,
13070,
17915,
367,
314,
10691,
624,
339,
485,
11166,
63,
3215,
63,
3280,
275,
699,
5659,
1646,
4936,
8,
5628,
63,
6717,
29,
549,
9,
339,
347,
664,
63,
23900,
8,
277,
304,
267,
408,
1767,
376,
6076,
543,
23978,
4454,
624,
267,
986,
199,
199,
533,
23978,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
931,
12,
536,
29,
403,
304,
267,
340,
536,
365,
488,
26,
288,
536,
275,
747,
14,
515,
14,
4846,
8,
515,
9,
267,
291,
14,
354,
275,
536,
267,
291,
14,
1160,
63,
515,
275,
747,
14,
515,
14,
904,
8,
515,
12,
283,
5876,
358,
267,
291,
14,
1986,
63,
515,
275,
747,
14,
515,
14,
904,
8,
515,
12,
283,
1986,
358,
339,
347,
664,
63,
15918,
63,
3422,
8,
277,
12,
16808,
63,
354,
304,
267,
372,
23754,
5455,
8,
736,
14,
515,
14,
904,
8,
277,
14,
1160,
63,
515,
12,
16808,
63,
354,
430,
339,
347,
664,
63,
3422,
8,
277,
304,
267,
372,
23754,
5455,
8,
277,
14,
1160,
63,
515,
9,
199,
199,
318,
3371,
63,
1986,
8,
1113,
12,
16808,
63,
354,
9280,
272,
347,
314,
3594,
63,
2254,
63,
1986,
63,
493,
8,
277,
12,
1788,
304,
267,
327,
886,
781,
1172,
376,
4702,
8879,
31,
267,
8879,
275,
488,
267,
340,
2688,
8,
15720,
14,
71,
12,
283,
7915,
735,
288,
8879,
275,
7209,
14,
71,
14,
7915,
267,
340,
8879,
365,
440,
488,
26,
288,
862,
26,
355,
372,
3222,
63,
504,
63,
3619,
8,
736,
14,
515,
14,
904,
8,
7915,
14,
1986,
63,
515,
12,
16808,
63,
354,
395,
1788,
9,
288,
871,
21909,
26,
355,
986,
398,
340,
440,
291,
14,
1989,
63,
1986,
63,
3741,
26,
288,
746,
6064,
360,
1944,
2955,
4922,
367,
642,
909,
358,
267,
372,
3222,
63,
504,
63,
3619,
8,
277,
14,
1986,
63,
3741,
12,
1788,
9,
339,
1559,
14,
2254,
63,
1986,
63,
493,
275,
2943,
14,
24674,
8,
1589,
3594,
63,
2254,
63,
1986,
63,
493,
12,
1559,
9,
199,
199,
533,
710,
3594,
4231,
5455,
8,
1563,
5455,
304,
272,
347,
636,
826,
721,
277,
12,
1145,
304,
267,
291,
14,
571,
275,
1145,
267,
291,
14,
571,
63,
3422,
275,
1145,
14,
12264,
63,
3422,
339,
347,
664,
63,
1365,
8,
277,
12,
3734,
12,
1978,
304,
267,
367,
5077,
315,
291,
423,
1661,
63,
16370,
837,
288,
862,
26,
355,
372,
5077,
14,
362,
63,
1365,
8,
5418,
12,
1978,
9,
288,
871,
5458,
4667,
26,
355,
986,
267,
746,
5458,
4667,
8,
1160,
9,
339,
347,
485,
1661,
63,
16370,
8,
277,
304,
267,
327,
886,
781,
1172,
376,
4702,
8879,
31,
267,
8879,
275,
488,
267,
340,
2688,
8,
15720,
14,
71,
12,
283,
7915,
735,
288,
8879,
275,
7209,
14,
71,
14,
7915,
267,
340,
8879,
365,
488,
26,
288,
2512,
14,
1757,
480,
1944,
23978,
1911,
531,
398,
327,
365,
2337,
376,
4702,
16808,
31,
267,
13292,
275,
485,
1069,
63,
3799,
63,
2340,
14,
2119,
14,
1069,
14,
15918,
267,
340,
13292,
365,
440,
488,
436,
13292,
315,
291,
14,
571,
14,
15918,
83,
26,
288,
13292,
275,
291,
14,
571,
14,
15918,
83,
59,
10913,
61,
288,
2512,
14,
1757,
480,
2017,
315,
699,
48,
26,
450,
83,
401,
13292,
14,
354,
9,
288,
340,
8879,
365,
440,
488,
26,
355,
1995,
8879,
14,
362,
63,
15918,
63,
3422,
8,
10913,
14,
354,
9,
288,
1995,
13292,
14,
12264,
63,
3422,
398,
340,
8879,
365,
440,
488,
26,
288,
1995,
8879,
14,
362,
63,
3422,
342,
398,
1995,
291,
14,
571,
63,
3422,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6029,
4688,
13086,
9785,
22043,
665,
1410,
338,
32,
1410,
338,
14,
335,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
18461,
28385,
14,
199,
3,
199,
3,
18461,
28385,
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,
18461,
28385,
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,
18461,
28385,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
199,
646,
747,
14,
515,
199,
646,
2943,
199,
646,
7209,
199,
504,
7209,
14,
8473,
492,
485,
1069,
63,
3799,
63,
2340,
199,
504,
7209,
14,
7546,
492,
3222,
63,
504,
63,
3619,
199,
504,
10321,
18,
492,
3523,
5455,
12,
5458,
4667,
12,
23754,
5455,
199,
504,
10380,
14,
3924,
492,
21909,
199,
199,
504,
6325,
28385,
14,
3173,
492,
14816,
12,
699,
5659,
1646,
4936,
199,
199,
646,
2050,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
533,
473,
16849,
6663,
8,
4267,
304,
272,
408,
22714,
13070,
17915,
367,
314,
10691,
624,
339,
485,
11166,
63,
3215,
63,
3280,
275,
699,
5659,
1646,
4936,
8,
5628,
63,
6717,
29,
549,
9,
339,
347,
664,
63,
23900,
8,
277,
304,
267,
408,
1767,
376,
6076,
543,
23978,
4454,
624,
267,
986,
199,
199,
533,
23978,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
931,
12,
536,
29,
403,
304,
267,
340,
536,
365,
488,
26,
288,
536,
275,
747,
14,
515,
14,
4846,
8,
515,
9,
267,
291,
14,
354,
275,
536,
267,
291,
14,
1160,
63,
515,
275,
747,
14,
515,
14,
904,
8,
515,
12,
283,
5876,
358,
267,
291,
14,
1986,
63,
515,
275,
747,
14,
515,
14,
904,
8,
515,
12,
283,
1986,
358,
339,
347,
664,
63,
15918,
63,
3422,
8,
277,
12,
16808,
63,
354,
304,
267,
372,
23754,
5455,
8,
736,
14,
515,
14,
904,
8,
277,
14,
1160,
63,
515,
12,
16808,
63,
354,
430,
339,
347,
664,
63,
3422,
8,
277,
304,
267,
372,
23754,
5455,
8,
277,
14,
1160,
63,
515,
9,
199,
199,
318,
3371,
63,
1986,
8,
1113,
12,
16808,
63,
354,
9280,
272,
347,
314,
3594,
63,
2254,
63,
1986,
63,
493,
8,
277,
12,
1788,
304,
267,
327,
886,
781,
1172,
376,
4702,
8879,
31,
267,
8879,
275,
488,
267,
340,
2688,
8,
15720,
14,
71,
12,
283,
7915,
735,
288,
8879,
275,
7209,
14,
71,
14,
7915,
267,
340,
8879,
365,
440,
488,
26,
288,
862,
26,
355,
372,
3222,
63,
504,
63,
3619,
8,
736,
14,
515,
14,
904,
8,
7915,
14,
1986,
63,
515,
12,
16808,
63,
354,
395,
1788,
9,
288,
871,
21909,
26,
355,
986,
398,
340,
440,
291,
14,
1989,
63,
1986,
63,
3741,
26,
288,
746,
6064,
360,
1944,
2955,
4922,
367,
642,
909,
358,
267,
372,
3222,
63,
504,
63,
3619,
8,
277,
14,
1986,
63,
3741,
12,
1788,
9,
339,
1559,
14,
2254,
63,
1986,
63,
493,
275,
2943,
14,
24674,
8,
1589,
3594,
63,
2254,
63,
1986,
63,
493,
12,
1559,
9,
199,
199,
533,
710,
3594,
4231,
5455,
8,
1563,
5455,
304,
272,
347,
636,
826,
721,
277,
12,
1145,
304,
267,
291,
14,
571,
275,
1145,
267,
291,
14,
571,
63,
3422,
275,
1145,
14,
12264,
63,
3422,
339,
347,
664,
63,
1365,
8,
277,
12,
3734,
12,
1978,
304,
267,
367,
5077,
315,
291,
423,
1661,
63,
16370,
837,
288,
862,
26,
355,
372,
5077,
14,
362,
63,
1365,
8,
5418,
12,
1978,
9,
288,
871,
5458,
4667,
26,
355,
986,
267,
746,
5458,
4667,
8,
1160,
9,
339,
347,
485,
1661,
63,
16370,
8,
277,
304,
267,
327,
886,
781,
1172,
376,
4702,
8879,
31,
267,
8879,
275,
488,
267,
340,
2688,
8,
15720,
14,
71,
12,
283,
7915,
735,
288,
8879,
275,
7209,
14,
71,
14,
7915,
267,
340,
8879,
365,
488,
26,
288,
2512,
14,
1757,
480,
1944,
23978,
1911,
531,
398,
327,
365,
2337,
376,
4702,
16808,
31,
267,
13292,
275,
485,
1069,
63,
3799,
63,
2340,
14,
2119,
14,
1069,
14,
15918,
267,
340,
13292,
365,
440,
488,
436,
13292,
315,
291,
14,
571,
14,
15918,
83,
26,
288,
13292,
275,
291,
14,
571,
14,
15918,
83,
59,
10913,
61,
288,
2512,
14,
1757,
480,
2017,
315,
699,
48,
26,
450,
83,
401,
13292,
14,
354,
9,
288,
340,
8879,
365,
440,
488,
26,
355,
1995,
8879,
14,
362,
63,
15918,
63,
3422,
8,
10913,
14,
354,
9,
288,
1995,
13292,
14,
12264,
63,
3422,
398,
340,
8879,
365,
440,
488,
26,
288,
1995,
8879,
14,
362,
63,
3422,
342,
398,
1995,
291,
14,
571,
63,
3422,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
katestrykermcm/katemcmanus-byte1
|
lib/flask/__init__.py
|
345
|
1672
|
# -*- coding: utf-8 -*-
"""
flask
~~~~~
A microframework based on Werkzeug. It's extensively documented
and follows best practice patterns.
:copyright: (c) 2011 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""
__version__ = '0.10'
# utilities we import from Werkzeug and Jinja2 that are unused
# in the module but are exported as public interface.
from werkzeug.exceptions import abort
from werkzeug.utils import redirect
from jinja2 import Markup, escape
from .app import Flask, Request, Response
from .config import Config
from .helpers import url_for, flash, send_file, send_from_directory, \
get_flashed_messages, get_template_attribute, make_response, safe_join, \
stream_with_context
from .globals import current_app, g, request, session, _request_ctx_stack, \
_app_ctx_stack
from .ctx import has_request_context, has_app_context, \
after_this_request, copy_current_request_context
from .module import Module
from .blueprints import Blueprint
from .templating import render_template, render_template_string
# the signals
from .signals import signals_available, template_rendered, request_started, \
request_finished, got_request_exception, request_tearing_down, \
appcontext_tearing_down, appcontext_pushed, \
appcontext_popped, message_flashed
# We're not exposing the actual json module but a convenient wrapper around
# it.
from . import json
# This was the only thing that flask used to export at one point and it had
# a more generic name.
jsonify = json.jsonify
# backwards compat, goes away in 1.0
from .sessions import SecureCookieSession as Session
json_available = True
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
7209,
272,
221,
2878,
94,
339,
437,
9967,
4857,
4079,
641,
22798,
14,
221,
2779,
1159,
2178,
9840,
22751,
272,
436,
11924,
5526,
24471,
7970,
14,
339,
520,
7307,
26,
334,
67,
9,
7760,
701,
1952,
827,
32472,
19728,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
199,
363,
1023,
363,
275,
283,
16,
14,
709,
7,
199,
199,
3,
15841,
781,
492,
687,
22798,
436,
17300,
18,
626,
787,
9563,
199,
3,
315,
314,
859,
1325,
787,
16629,
465,
4575,
3217,
14,
199,
504,
10380,
14,
3924,
492,
12004,
199,
504,
10380,
14,
1208,
492,
4660,
199,
504,
10321,
18,
492,
17504,
12,
4772,
199,
199,
504,
1275,
571,
492,
16704,
12,
4784,
12,
7232,
199,
504,
1275,
888,
492,
4094,
199,
504,
1275,
7546,
492,
1166,
63,
509,
12,
14775,
12,
3222,
63,
493,
12,
3222,
63,
504,
63,
3619,
12,
971,
272,
664,
63,
11331,
379,
63,
3431,
12,
664,
63,
1160,
63,
3215,
12,
1852,
63,
1310,
12,
5048,
63,
904,
12,
971,
272,
2547,
63,
1045,
63,
1100,
199,
504,
1275,
8473,
492,
1453,
63,
571,
12,
486,
12,
1056,
12,
2351,
12,
485,
1069,
63,
3799,
63,
2340,
12,
971,
1362,
485,
571,
63,
3799,
63,
2340,
199,
504,
1275,
3799,
492,
965,
63,
1069,
63,
1100,
12,
965,
63,
571,
63,
1100,
12,
971,
1362,
2410,
63,
3749,
63,
1069,
12,
1331,
63,
1818,
63,
1069,
63,
1100,
199,
504,
1275,
578,
492,
5673,
199,
504,
1275,
15918,
83,
492,
22447,
1361,
199,
504,
1275,
808,
24615,
492,
3795,
63,
1160,
12,
3795,
63,
1160,
63,
875,
199,
199,
3,
314,
10166,
199,
504,
1275,
10458,
492,
10166,
63,
4561,
12,
1978,
63,
16841,
12,
1056,
63,
8924,
12,
971,
1362,
1056,
63,
8669,
12,
4788,
63,
1069,
63,
1971,
12,
1056,
63,
266,
9332,
63,
2110,
12,
971,
1362,
1145,
1100,
63,
266,
9332,
63,
2110,
12,
1145,
1100,
63,
5335,
379,
12,
971,
1362,
1145,
1100,
63,
1935,
1915,
12,
1245,
63,
11331,
379,
199,
199,
3,
2136,
3984,
440,
444,
555,
1044,
314,
3503,
2022,
859,
1325,
282,
22700,
4975,
6818,
199,
3,
652,
14,
199,
504,
1275,
492,
2022,
199,
199,
3,
961,
1990,
314,
1454,
8377,
626,
7209,
1202,
370,
4843,
737,
1373,
2376,
436,
652,
10530,
199,
3,
282,
1655,
7809,
536,
14,
199,
1001,
2021,
275,
2022,
14,
1001,
2021,
199,
199,
3,
8552,
8434,
12,
13538,
13437,
315,
413,
14,
16,
199,
504,
1275,
11676,
492,
30894,
7810,
4434,
465,
8596,
199,
1001,
63,
4561,
275,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
7209,
272,
221,
2878,
94,
339,
437,
9967,
4857,
4079,
641,
22798,
14,
221,
2779,
1159,
2178,
9840,
22751,
272,
436,
11924,
5526,
24471,
7970,
14,
339,
520,
7307,
26,
334,
67,
9,
7760,
701,
1952,
827,
32472,
19728,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
199,
363,
1023,
363,
275,
283,
16,
14,
709,
7,
199,
199,
3,
15841,
781,
492,
687,
22798,
436,
17300,
18,
626,
787,
9563,
199,
3,
315,
314,
859,
1325,
787,
16629,
465,
4575,
3217,
14,
199,
504,
10380,
14,
3924,
492,
12004,
199,
504,
10380,
14,
1208,
492,
4660,
199,
504,
10321,
18,
492,
17504,
12,
4772,
199,
199,
504,
1275,
571,
492,
16704,
12,
4784,
12,
7232,
199,
504,
1275,
888,
492,
4094,
199,
504,
1275,
7546,
492,
1166,
63,
509,
12,
14775,
12,
3222,
63,
493,
12,
3222,
63,
504,
63,
3619,
12,
971,
272,
664,
63,
11331,
379,
63,
3431,
12,
664,
63,
1160,
63,
3215,
12,
1852,
63,
1310,
12,
5048,
63,
904,
12,
971,
272,
2547,
63,
1045,
63,
1100,
199,
504,
1275,
8473,
492,
1453,
63,
571,
12,
486,
12,
1056,
12,
2351,
12,
485,
1069,
63,
3799,
63,
2340,
12,
971,
1362,
485,
571,
63,
3799,
63,
2340,
199,
504,
1275,
3799,
492,
965,
63,
1069,
63,
1100,
12,
965,
63,
571,
63,
1100,
12,
971,
1362,
2410,
63,
3749,
63,
1069,
12,
1331,
63,
1818,
63,
1069,
63,
1100,
199,
504,
1275,
578,
492,
5673,
199,
504,
1275,
15918,
83,
492,
22447,
1361,
199,
504,
1275,
808,
24615,
492,
3795,
63,
1160,
12,
3795,
63,
1160,
63,
875,
199,
199,
3,
314,
10166,
199,
504,
1275,
10458,
492,
10166,
63,
4561,
12,
1978,
63,
16841,
12,
1056,
63,
8924,
12,
971,
1362,
1056,
63,
8669,
12,
4788,
63,
1069,
63,
1971,
12,
1056,
63,
266,
9332,
63,
2110,
12,
971,
1362,
1145,
1100,
63,
266,
9332,
63,
2110,
12,
1145,
1100,
63,
5335,
379,
12,
971,
1362,
1145,
1100,
63,
1935,
1915,
12,
1245,
63,
11331,
379,
199,
199,
3,
2136,
3984,
440,
444,
555,
1044,
314,
3503,
2022,
859,
1325,
282,
22700,
4975,
6818,
199,
3,
652,
14,
199,
504,
1275,
492,
2022,
199,
199,
3,
961,
1990,
314,
1454,
8377,
626,
7209,
1202,
370,
4843,
737,
1373,
2376,
436,
652,
10530,
199,
3,
282,
1655,
7809,
536,
14,
199,
1001,
2021,
275,
2022,
14,
1001,
2021,
199,
199,
3,
8552,
8434,
12,
13538,
13437,
315,
413,
14,
16,
199,
504,
1275,
11676,
492,
30894,
7810,
4434,
465,
8596,
199,
1001,
63,
4561,
275,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
bobthekingofegypt/servo
|
tests/wpt/web-platform-tests/tools/html5lib/html5lib/tests/tokenizertotree.py
|
483
|
1965
|
from __future__ import absolute_import, division, unicode_literals
import sys
import os
import json
import re
import html5lib
from . import support
from . import test_tokenizer
p = html5lib.HTMLParser()
unnamespaceExpected = re.compile(r"^(\|\s*)<html ([^>]+)>", re.M).sub
def main(out_path):
if not os.path.exists(out_path):
sys.stderr.write("Path %s does not exist" % out_path)
sys.exit(1)
for filename in support.get_data_files('tokenizer', '*.test'):
run_file(filename, out_path)
def run_file(filename, out_path):
try:
tests_data = json.load(open(filename, "r"))
except ValueError:
sys.stderr.write("Failed to load %s\n" % filename)
return
name = os.path.splitext(os.path.split(filename)[1])[0]
output_file = open(os.path.join(out_path, "tokenizer_%s.dat" % name), "w")
if 'tests' in tests_data:
for test_data in tests_data['tests']:
if 'initialStates' not in test_data:
test_data["initialStates"] = ["Data state"]
for initial_state in test_data["initialStates"]:
if initial_state != "Data state":
# don't support this yet
continue
test = make_test(test_data)
output_file.write(test)
output_file.close()
def make_test(test_data):
if 'doubleEscaped' in test_data:
test_data = test_tokenizer.unescape_test(test_data)
rv = []
rv.append("#data")
rv.append(test_data["input"].encode("utf8"))
rv.append("#errors")
tree = p.parse(test_data["input"])
output = p.tree.testSerializer(tree)
output = "\n".join(("| " + line[3:]) if line.startswith("| ") else line
for line in output.split("\n"))
output = unnamespaceExpected(r"\1<\2>", output)
rv.append(output.encode("utf8"))
rv.append("")
return "\n".join(rv)
if __name__ == "__main__":
main(sys.argv[1])
|
mpl-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
646,
984,
199,
646,
747,
199,
646,
2022,
199,
646,
295,
199,
199,
646,
3517,
21,
773,
199,
504,
1275,
492,
2291,
199,
504,
1275,
492,
511,
63,
13771,
199,
199,
80,
275,
3517,
21,
773,
14,
27375,
342,
199,
199,
324,
3251,
6964,
275,
295,
14,
2014,
8,
82,
16136,
2961,
6113,
83,
13278,
28,
1360,
334,
17478,
11896,
7166,
295,
14,
45,
680,
954,
421,
199,
318,
2446,
8,
548,
63,
515,
304,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
548,
63,
515,
304,
267,
984,
14,
3083,
14,
952,
480,
2042,
450,
83,
1630,
440,
2187,
2,
450,
734,
63,
515,
9,
267,
984,
14,
2224,
8,
17,
9,
339,
367,
1788,
315,
2291,
14,
362,
63,
576,
63,
1725,
360,
13771,
297,
11937,
396,
735,
267,
1255,
63,
493,
8,
1501,
12,
734,
63,
515,
9,
421,
199,
318,
1255,
63,
493,
8,
1501,
12,
734,
63,
515,
304,
272,
862,
26,
267,
2295,
63,
576,
275,
2022,
14,
912,
8,
1490,
8,
1501,
12,
298,
82,
2237,
272,
871,
1722,
26,
267,
984,
14,
3083,
14,
952,
480,
4276,
370,
2248,
450,
83,
60,
78,
2,
450,
1788,
9,
267,
372,
272,
536,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
1294,
8,
1501,
2788,
17,
11057,
16,
61,
272,
1072,
63,
493,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
548,
63,
515,
12,
298,
13771,
4970,
83,
14,
4616,
2,
450,
536,
395,
298,
87,
531,
339,
340,
283,
2219,
7,
315,
2295,
63,
576,
26,
267,
367,
511,
63,
576,
315,
2295,
63,
576,
459,
2219,
2565,
288,
340,
283,
2747,
18010,
7,
440,
315,
511,
63,
576,
26,
355,
511,
63,
576,
905,
2747,
18010,
937,
275,
2097,
1451,
1174,
937,
953,
367,
2536,
63,
929,
315,
511,
63,
576,
905,
2747,
18010,
6229,
355,
340,
2536,
63,
929,
1137,
298,
1451,
1174,
582,
490,
327,
2793,
1133,
2291,
642,
5966,
490,
1980,
355,
511,
275,
1852,
63,
396,
8,
396,
63,
576,
9,
355,
1072,
63,
493,
14,
952,
8,
396,
9,
339,
1072,
63,
493,
14,
1600,
342,
421,
199,
318,
1852,
63,
396,
8,
396,
63,
576,
304,
272,
340,
283,
3157,
23953,
7,
315,
511,
63,
576,
26,
267,
511,
63,
576,
275,
511,
63,
13771,
14,
22726,
63,
396,
8,
396,
63,
576,
9,
339,
4336,
275,
942,
272,
4336,
14,
740,
10064,
576,
531,
272,
4336,
14,
740,
8,
396,
63,
576,
905,
1210,
4140,
2143,
480,
1624,
24,
2237,
272,
4336,
14,
740,
10064,
2550,
531,
272,
3123,
275,
299,
14,
1122,
8,
396,
63,
576,
905,
1210,
3135,
272,
1072,
275,
299,
14,
2350,
14,
396,
7299,
8,
2350,
9,
272,
1072,
275,
1867,
78,
1674,
904,
9313,
92,
298,
435,
1004,
59,
19,
5728,
340,
1004,
14,
2460,
25795,
221,
6099,
587,
1004,
2432,
367,
1004,
315,
1072,
14,
1294,
4582,
78,
2237,
272,
1072,
275,
625,
3251,
6964,
8,
82,
3212,
17,
31873,
18,
7166,
1072,
9,
272,
4336,
14,
740,
8,
1199,
14,
2143,
480,
1624,
24,
2237,
272,
4336,
14,
740,
10804,
272,
372,
1867,
78,
1674,
904,
8,
6310,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
8,
1274,
14,
3020,
59,
17,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
646,
984,
199,
646,
747,
199,
646,
2022,
199,
646,
295,
199,
199,
646,
3517,
21,
773,
199,
504,
1275,
492,
2291,
199,
504,
1275,
492,
511,
63,
13771,
199,
199,
80,
275,
3517,
21,
773,
14,
27375,
342,
199,
199,
324,
3251,
6964,
275,
295,
14,
2014,
8,
82,
16136,
2961,
6113,
83,
13278,
28,
1360,
334,
17478,
11896,
7166,
295,
14,
45,
680,
954,
421,
199,
318,
2446,
8,
548,
63,
515,
304,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
548,
63,
515,
304,
267,
984,
14,
3083,
14,
952,
480,
2042,
450,
83,
1630,
440,
2187,
2,
450,
734,
63,
515,
9,
267,
984,
14,
2224,
8,
17,
9,
339,
367,
1788,
315,
2291,
14,
362,
63,
576,
63,
1725,
360,
13771,
297,
11937,
396,
735,
267,
1255,
63,
493,
8,
1501,
12,
734,
63,
515,
9,
421,
199,
318,
1255,
63,
493,
8,
1501,
12,
734,
63,
515,
304,
272,
862,
26,
267,
2295,
63,
576,
275,
2022,
14,
912,
8,
1490,
8,
1501,
12,
298,
82,
2237,
272,
871,
1722,
26,
267,
984,
14,
3083,
14,
952,
480,
4276,
370,
2248,
450,
83,
60,
78,
2,
450,
1788,
9,
267,
372,
272,
536,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
1294,
8,
1501,
2788,
17,
11057,
16,
61,
272,
1072,
63,
493,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
548,
63,
515,
12,
298,
13771,
4970,
83,
14,
4616,
2,
450,
536,
395,
298,
87,
531,
339,
340,
283,
2219,
7,
315,
2295,
63,
576,
26,
267,
367,
511,
63,
576,
315,
2295,
63,
576,
459,
2219,
2565,
288,
340,
283,
2747,
18010,
7,
440,
315,
511,
63,
576,
26,
355,
511,
63,
576,
905,
2747,
18010,
937,
275,
2097,
1451,
1174,
937,
953,
367,
2536,
63,
929,
315,
511,
63,
576,
905,
2747,
18010,
6229,
355,
340,
2536,
63,
929,
1137,
298,
1451,
1174,
582,
490,
327,
2793,
1133,
2291,
642,
5966,
490,
1980,
355,
511,
275,
1852,
63,
396,
8,
396,
63,
576,
9,
355,
1072,
63,
493,
14,
952,
8,
396,
9,
339,
1072,
63,
493,
14,
1600,
342,
421,
199,
318,
1852,
63,
396,
8,
396,
63,
576,
304,
272,
340,
283,
3157,
23953,
7,
315,
511,
63,
576,
26,
267,
511,
63,
576,
275,
511,
63,
13771,
14,
22726,
63,
396,
8,
396,
63,
576,
9,
339,
4336,
275,
942,
272,
4336,
14,
740,
10064,
576,
531,
272,
4336,
14,
740,
8,
396,
63,
576,
905,
1210,
4140,
2143,
480,
1624,
24,
2237,
272,
4336,
14,
740,
10064,
2550,
531,
272,
3123,
275,
299,
14,
1122,
8,
396,
63,
576,
905,
1210,
3135,
272,
1072,
275,
299,
14,
2350,
14,
396,
7299,
8,
2350,
9,
272,
1072,
275,
1867,
78,
1674,
904,
9313,
92,
298,
435,
1004,
59,
19,
5728,
340,
1004,
14,
2460,
25795,
221,
6099,
587,
1004,
2432,
367,
1004,
315,
1072,
14,
1294,
4582,
78,
2237,
272,
1072,
275,
625,
3251,
6964,
8,
82,
3212,
17,
31873,
18,
7166,
1072,
9,
272,
4336,
14,
740,
8,
1199,
14,
2143,
480,
1624,
24,
2237,
272,
4336,
14,
740,
10804,
272,
372,
1867,
78,
1674,
904,
8,
6310,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
8,
1274,
14,
3020,
59,
17,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
JamesMGreene/phantomjs
|
src/qt/qtwebkit/Tools/QueueStatusServer/handlers/dashboard.py
|
140
|
2786
|
# Copyright (C) 2009 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import operator
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from model.attachment import Attachment
from model.queues import Queue
class Dashboard(webapp.RequestHandler):
# We may want to sort these?
_ordered_queues = Queue.all()
_header_names = [queue.short_name() for queue in _ordered_queues]
def _build_bubble(self, attachment, queue):
queue_status = attachment.status_for_queue(queue)
bubble = {
"status_class": attachment.state_from_queue_status(queue_status) if queue_status else "none",
"status_date": queue_status.date if queue_status else None,
}
return bubble
def _build_row(self, attachment):
row = {
"bug_id": attachment.bug_id(),
"attachment_id": attachment.id,
"bubbles": [self._build_bubble(attachment, queue) for queue in self._ordered_queues],
}
return row
def get(self):
template_values = {
"headers": self._header_names,
"rows": [self._build_row(attachment) for attachment in Attachment.recent(limit=25)],
}
self.response.out.write(template.render("templates/dashboard.html", template_values))
|
bsd-3-clause
|
[
3,
1898,
334,
35,
9,
8937,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
221,
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,
221,
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,
646,
4182,
199,
199,
504,
6233,
14,
15358,
14,
832,
492,
24812,
199,
504,
6233,
14,
15358,
14,
832,
14,
22632,
492,
1978,
199,
199,
504,
1402,
14,
8905,
492,
21328,
434,
199,
504,
1402,
14,
18849,
492,
10703,
421,
199,
533,
577,
1119,
3576,
8,
22632,
14,
11149,
304,
272,
327,
2136,
1443,
2934,
370,
4069,
3520,
31,
272,
485,
8235,
63,
18849,
275,
10703,
14,
452,
342,
272,
485,
1291,
63,
1247,
275,
359,
1825,
14,
3612,
63,
354,
342,
367,
4126,
315,
485,
8235,
63,
18849,
61,
339,
347,
485,
1506,
63,
66,
21749,
8,
277,
12,
12193,
12,
4126,
304,
267,
4126,
63,
1205,
275,
12193,
14,
1205,
63,
509,
63,
1825,
8,
1825,
9,
267,
330,
21749,
275,
469,
288,
298,
1205,
63,
533,
582,
12193,
14,
929,
63,
504,
63,
1825,
63,
1205,
8,
1825,
63,
1205,
9,
340,
4126,
63,
1205,
587,
298,
3592,
401,
288,
298,
1205,
63,
602,
582,
4126,
63,
1205,
14,
602,
340,
4126,
63,
1205,
587,
488,
12,
267,
789,
267,
372,
330,
21749,
339,
347,
485,
1506,
63,
1143,
8,
277,
12,
12193,
304,
267,
1962,
275,
469,
288,
298,
1266,
63,
344,
582,
12193,
14,
1266,
63,
344,
1062,
288,
298,
8905,
63,
344,
582,
12193,
14,
344,
12,
288,
298,
66,
21749,
83,
582,
359,
277,
423,
1506,
63,
66,
21749,
8,
8905,
12,
4126,
9,
367,
4126,
315,
291,
423,
8235,
63,
18849,
467,
267,
789,
267,
372,
1962,
339,
347,
664,
8,
277,
304,
267,
1978,
63,
1459,
275,
469,
288,
298,
2139,
582,
291,
423,
1291,
63,
1247,
12,
288,
298,
3838,
582,
359,
277,
423,
1506,
63,
1143,
8,
8905,
9,
367,
12193,
315,
21328,
434,
14,
14951,
8,
3097,
29,
821,
4360,
267,
789,
267,
291,
14,
1310,
14,
548,
14,
952,
8,
1160,
14,
3352,
480,
5876,
15,
9743,
14,
1360,
401,
1978,
63,
1459,
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
] |
[
1898,
334,
35,
9,
8937,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
221,
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,
221,
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,
646,
4182,
199,
199,
504,
6233,
14,
15358,
14,
832,
492,
24812,
199,
504,
6233,
14,
15358,
14,
832,
14,
22632,
492,
1978,
199,
199,
504,
1402,
14,
8905,
492,
21328,
434,
199,
504,
1402,
14,
18849,
492,
10703,
421,
199,
533,
577,
1119,
3576,
8,
22632,
14,
11149,
304,
272,
327,
2136,
1443,
2934,
370,
4069,
3520,
31,
272,
485,
8235,
63,
18849,
275,
10703,
14,
452,
342,
272,
485,
1291,
63,
1247,
275,
359,
1825,
14,
3612,
63,
354,
342,
367,
4126,
315,
485,
8235,
63,
18849,
61,
339,
347,
485,
1506,
63,
66,
21749,
8,
277,
12,
12193,
12,
4126,
304,
267,
4126,
63,
1205,
275,
12193,
14,
1205,
63,
509,
63,
1825,
8,
1825,
9,
267,
330,
21749,
275,
469,
288,
298,
1205,
63,
533,
582,
12193,
14,
929,
63,
504,
63,
1825,
63,
1205,
8,
1825,
63,
1205,
9,
340,
4126,
63,
1205,
587,
298,
3592,
401,
288,
298,
1205,
63,
602,
582,
4126,
63,
1205,
14,
602,
340,
4126,
63,
1205,
587,
488,
12,
267,
789,
267,
372,
330,
21749,
339,
347,
485,
1506,
63,
1143,
8,
277,
12,
12193,
304,
267,
1962,
275,
469,
288,
298,
1266,
63,
344,
582,
12193,
14,
1266,
63,
344,
1062,
288,
298,
8905,
63,
344,
582,
12193,
14,
344,
12,
288,
298,
66,
21749,
83,
582,
359,
277,
423,
1506,
63,
66,
21749,
8,
8905,
12,
4126,
9,
367,
4126,
315,
291,
423,
8235,
63,
18849,
467,
267,
789,
267,
372,
1962,
339,
347,
664,
8,
277,
304,
267,
1978,
63,
1459,
275,
469,
288,
298,
2139,
582,
291,
423,
1291,
63,
1247,
12,
288,
298,
3838,
582,
359,
277,
423,
1506,
63,
1143,
8,
8905,
9,
367,
12193,
315,
21328,
434,
14,
14951,
8,
3097,
29,
821,
4360,
267,
789,
267,
291,
14,
1310,
14,
548,
14,
952,
8,
1160,
14,
3352,
480,
5876,
15,
9743,
14,
1360,
401,
1978,
63,
1459,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
bruceSz/git_syncer
|
gsyncer/monitor/monitor-sample.py
|
1
|
1493
|
import re
from wsgiref.simple_server import make_server
def hello_world_app(environ,start_response):
status = '200 OK'
headers = [('Content-type','text/plain')]
print environ
start_response(status,headers)
return ["hello world"]
def event_analyst(environ,start_response):
status = '200 OK'
headers = [('Content-type','text/plain')]
start_response(status,headers)
if environ['REQUEST_METHOD']!='POST':
return ['Error HTTP method: please use post']
else:
try:
request_body_size = int(environ.get('CONTENT_LENGTH',0))
except (ValueError):
request_body_size = 0
request_body = environ['wsgi.input'].read(request_body_size)
print request_body
return [str(request_body)]
def not_found(environ,start_response):
start_response('404 NOT FOUND',[('Content-type','text/plain')])
return ['Not Found']
urls = [
(r'^$',hello_world_app),
(r'push_event$',event_analyst)
]
def app(environ,start_response):
status = '200 OK'
headers = [('Content-type','text/plain')]
path = environ.get('PATH_INFO','').lstrip('/')
for regex,callback in urls:
match = re.search(regex,path)
if match is not None:
return callback(environ,start_response)
return not_found(environ,start_response)
if __name__ == '__main__':
httpd = make_server('',8080,app)
print "Serving on port 8080"
httpd.serve_forever()
|
apache-2.0
|
[
646,
295,
199,
504,
12464,
1121,
14,
4129,
63,
1000,
492,
1852,
63,
1000,
421,
199,
318,
16509,
63,
7617,
63,
571,
8,
2314,
12,
928,
63,
1310,
304,
272,
2004,
275,
283,
1840,
9949,
7,
272,
2323,
275,
4274,
2714,
13,
466,
1673,
505,
15,
6104,
5440,
272,
870,
6160,
339,
1343,
63,
1310,
8,
1205,
12,
2139,
9,
339,
372,
2097,
5006,
6701,
937,
421,
199,
318,
1566,
63,
4797,
270,
8,
2314,
12,
928,
63,
1310,
304,
2286,
2004,
275,
283,
1840,
9949,
7,
272,
2323,
275,
4274,
2714,
13,
466,
1673,
505,
15,
6104,
5440,
339,
1343,
63,
1310,
8,
1205,
12,
2139,
9,
272,
340,
6160,
459,
6780,
63,
9977,
418,
27909,
4030,
356,
267,
372,
788,
547,
3101,
1083,
26,
8749,
675,
2963,
418,
272,
587,
26,
267,
862,
26,
288,
1056,
63,
2030,
63,
890,
275,
1109,
8,
2314,
14,
362,
360,
9663,
63,
9127,
297,
16,
430,
267,
871,
334,
3393,
304,
288,
1056,
63,
2030,
63,
890,
275,
378,
398,
1056,
63,
2030,
275,
6160,
459,
6508,
14,
1210,
2278,
739,
8,
1069,
63,
2030,
63,
890,
9,
4960,
870,
1056,
63,
2030,
267,
372,
359,
495,
8,
1069,
63,
2030,
1874,
26339,
16872,
199,
318,
440,
63,
4214,
8,
2314,
12,
928,
63,
1310,
304,
272,
1343,
63,
1310,
360,
5188,
2845,
481,
47,
6131,
297,
19412,
2714,
13,
466,
1673,
505,
15,
6104,
2023,
272,
372,
788,
1763,
2643,
418,
199,
199,
3603,
275,
359,
272,
334,
82,
4289,
4268,
5006,
63,
7617,
63,
571,
395,
272,
334,
82,
7,
5335,
63,
1430,
4268,
1430,
63,
4797,
270,
9,
199,
61,
421,
199,
318,
1145,
8,
2314,
12,
928,
63,
1310,
304,
272,
2004,
275,
283,
1840,
9949,
7,
272,
2323,
275,
4274,
2714,
13,
466,
1673,
505,
15,
6104,
5440,
272,
931,
275,
6160,
14,
362,
360,
3243,
63,
4531,
26516,
10124,
7825,
272,
367,
5163,
12,
3058,
315,
8187,
26,
267,
1336,
275,
295,
14,
1733,
8,
3821,
12,
515,
9,
267,
340,
1336,
365,
440,
488,
26,
288,
372,
3233,
8,
2314,
12,
928,
63,
1310,
9,
339,
372,
440,
63,
4214,
8,
2314,
12,
928,
63,
1310,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
339,
23913,
275,
1852,
63,
1000,
8594,
15844,
12,
571,
9,
272,
870,
298,
1505,
4007,
641,
1844,
30220,
2,
272,
23913,
14,
4909,
63,
21327,
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
] |
[
295,
199,
504,
12464,
1121,
14,
4129,
63,
1000,
492,
1852,
63,
1000,
421,
199,
318,
16509,
63,
7617,
63,
571,
8,
2314,
12,
928,
63,
1310,
304,
272,
2004,
275,
283,
1840,
9949,
7,
272,
2323,
275,
4274,
2714,
13,
466,
1673,
505,
15,
6104,
5440,
272,
870,
6160,
339,
1343,
63,
1310,
8,
1205,
12,
2139,
9,
339,
372,
2097,
5006,
6701,
937,
421,
199,
318,
1566,
63,
4797,
270,
8,
2314,
12,
928,
63,
1310,
304,
2286,
2004,
275,
283,
1840,
9949,
7,
272,
2323,
275,
4274,
2714,
13,
466,
1673,
505,
15,
6104,
5440,
339,
1343,
63,
1310,
8,
1205,
12,
2139,
9,
272,
340,
6160,
459,
6780,
63,
9977,
418,
27909,
4030,
356,
267,
372,
788,
547,
3101,
1083,
26,
8749,
675,
2963,
418,
272,
587,
26,
267,
862,
26,
288,
1056,
63,
2030,
63,
890,
275,
1109,
8,
2314,
14,
362,
360,
9663,
63,
9127,
297,
16,
430,
267,
871,
334,
3393,
304,
288,
1056,
63,
2030,
63,
890,
275,
378,
398,
1056,
63,
2030,
275,
6160,
459,
6508,
14,
1210,
2278,
739,
8,
1069,
63,
2030,
63,
890,
9,
4960,
870,
1056,
63,
2030,
267,
372,
359,
495,
8,
1069,
63,
2030,
1874,
26339,
16872,
199,
318,
440,
63,
4214,
8,
2314,
12,
928,
63,
1310,
304,
272,
1343,
63,
1310,
360,
5188,
2845,
481,
47,
6131,
297,
19412,
2714,
13,
466,
1673,
505,
15,
6104,
2023,
272,
372,
788,
1763,
2643,
418,
199,
199,
3603,
275,
359,
272,
334,
82,
4289,
4268,
5006,
63,
7617,
63,
571,
395,
272,
334,
82,
7,
5335,
63,
1430,
4268,
1430,
63,
4797,
270,
9,
199,
61,
421,
199,
318,
1145,
8,
2314,
12,
928,
63,
1310,
304,
272,
2004,
275,
283,
1840,
9949,
7,
272,
2323,
275,
4274,
2714,
13,
466,
1673,
505,
15,
6104,
5440,
272,
931,
275,
6160,
14,
362,
360,
3243,
63,
4531,
26516,
10124,
7825,
272,
367,
5163,
12,
3058,
315,
8187,
26,
267,
1336,
275,
295,
14,
1733,
8,
3821,
12,
515,
9,
267,
340,
1336,
365,
440,
488,
26,
288,
372,
3233,
8,
2314,
12,
928,
63,
1310,
9,
339,
372,
440,
63,
4214,
8,
2314,
12,
928,
63,
1310,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
339,
23913,
275,
1852,
63,
1000,
8594,
15844,
12,
571,
9,
272,
870,
298,
1505,
4007,
641,
1844,
30220,
2,
272,
23913,
14,
4909,
63,
21327,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
watonyweng/nova
|
nova/conductor/tasks/base.py
|
56
|
1639
|
# 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 abc
import functools
from oslo_utils import excutils
import six
def rollback_wrapper(original):
@functools.wraps(original)
def wrap(self):
try:
return original(self)
except Exception:
with excutils.save_and_reraise_exception():
self.rollback()
return wrap
@six.add_metaclass(abc.ABCMeta)
class TaskBase(object):
def __init__(self, context, instance):
self.context = context
self.instance = instance
@rollback_wrapper
def execute(self):
"""Run task's logic, written in _execute() method
"""
return self._execute()
@abc.abstractmethod
def _execute(self):
"""Descendants should place task's logic here, while resource
initialization should be performed over __init__
"""
pass
def rollback(self):
"""Rollback failed task
Descendants should implement this method to allow task user to
rollback status to state before execute method was call
"""
pass
|
apache-2.0
|
[
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
13022,
199,
646,
9143,
199,
199,
504,
11258,
63,
1208,
492,
32763,
199,
646,
3816,
421,
199,
318,
16475,
63,
5029,
8,
5043,
304,
272,
768,
17869,
14,
13582,
8,
5043,
9,
272,
347,
4816,
8,
277,
304,
267,
862,
26,
288,
372,
3379,
8,
277,
9,
267,
871,
2186,
26,
288,
543,
32763,
14,
2117,
63,
460,
63,
20614,
63,
1971,
837,
355,
291,
14,
10437,
342,
272,
372,
4816,
421,
199,
32,
4174,
14,
525,
63,
6577,
8,
3175,
14,
22254,
9,
199,
533,
8495,
1563,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1067,
12,
1256,
304,
267,
291,
14,
1100,
275,
1067,
267,
291,
14,
842,
275,
1256,
339,
768,
10437,
63,
5029,
272,
347,
5341,
8,
277,
304,
267,
408,
2540,
2120,
1159,
9661,
12,
5313,
315,
485,
2526,
342,
1083,
267,
408,
267,
372,
291,
423,
2526,
342,
339,
768,
3175,
14,
10315,
272,
347,
485,
2526,
8,
277,
304,
267,
408,
9921,
500,
2285,
1077,
4192,
2120,
1159,
9661,
2348,
12,
1830,
2073,
267,
11097,
1077,
506,
10585,
1806,
636,
826,
363,
267,
408,
267,
986,
339,
347,
16475,
8,
277,
304,
267,
408,
24363,
894,
3405,
2120,
267,
8055,
67,
500,
2285,
1077,
5669,
642,
1083,
370,
2040,
2120,
922,
370,
267,
16475,
2004,
370,
1174,
2544,
5341,
1083,
221,
1990,
1240,
267,
408,
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
] |
[
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,
13022,
199,
646,
9143,
199,
199,
504,
11258,
63,
1208,
492,
32763,
199,
646,
3816,
421,
199,
318,
16475,
63,
5029,
8,
5043,
304,
272,
768,
17869,
14,
13582,
8,
5043,
9,
272,
347,
4816,
8,
277,
304,
267,
862,
26,
288,
372,
3379,
8,
277,
9,
267,
871,
2186,
26,
288,
543,
32763,
14,
2117,
63,
460,
63,
20614,
63,
1971,
837,
355,
291,
14,
10437,
342,
272,
372,
4816,
421,
199,
32,
4174,
14,
525,
63,
6577,
8,
3175,
14,
22254,
9,
199,
533,
8495,
1563,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1067,
12,
1256,
304,
267,
291,
14,
1100,
275,
1067,
267,
291,
14,
842,
275,
1256,
339,
768,
10437,
63,
5029,
272,
347,
5341,
8,
277,
304,
267,
408,
2540,
2120,
1159,
9661,
12,
5313,
315,
485,
2526,
342,
1083,
267,
408,
267,
372,
291,
423,
2526,
342,
339,
768,
3175,
14,
10315,
272,
347,
485,
2526,
8,
277,
304,
267,
408,
9921,
500,
2285,
1077,
4192,
2120,
1159,
9661,
2348,
12,
1830,
2073,
267,
11097,
1077,
506,
10585,
1806,
636,
826,
363,
267,
408,
267,
986,
339,
347,
16475,
8,
277,
304,
267,
408,
24363,
894,
3405,
2120,
267,
8055,
67,
500,
2285,
1077,
5669,
642,
1083,
370,
2040,
2120,
922,
370,
267,
16475,
2004,
370,
1174,
2544,
5341,
1083,
221,
1990,
1240,
267,
408,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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##############################################################################
#
# Copyright (c) 2009 Veritos - Jan Verlaan - www.veritos.nl
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs.
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company like Veritos.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
##############################################################################
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
1898,
334,
67,
9,
8937,
5444,
390,
736,
446,
17474,
5444,
416,
290,
446,
20732,
14,
422,
390,
736,
14,
7530,
199,
3,
199,
3,
14750,
26,
961,
2240,
465,
4066,
365,
11619,
370,
506,
1202,
701,
22398,
28661,
199,
3,
2240,
16465,
3963,
5452,
314,
8852,
9163,
83,
3616,
402,
465,
5480,
316,
1006,
12330,
199,
3,
406,
13436,
9183,
687,
2399,
1566,
1061,
315,
9587,
27164,
2578,
436,
18227,
14,
199,
3,
9599,
4390,
3963,
787,
10023,
367,
282,
10144,
13,
475,
13,
1180,
8744,
543,
2414,
23012,
199,
3,
486,
10475,
397,
436,
2291,
787,
30390,
1503,
722,
68,
370,
16077,
282,
2868,
2290,
199,
3,
7591,
15878,
2839,
5444,
390,
736,
14,
199,
3,
199,
3,
961,
2240,
365,
2868,
2290,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
3,
199,
4605,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
1898,
334,
67,
9,
8937,
5444,
390,
736,
446,
17474,
5444,
416,
290,
446,
20732,
14,
422,
390,
736,
14,
7530,
199,
3,
199,
3,
14750,
26,
961,
2240,
465,
4066,
365,
11619,
370,
506,
1202,
701,
22398,
28661,
199,
3,
2240,
16465,
3963,
5452,
314,
8852,
9163,
83,
3616,
402,
465,
5480,
316,
1006,
12330,
199,
3,
406,
13436,
9183,
687,
2399,
1566,
1061,
315,
9587,
27164,
2578,
436,
18227,
14,
199,
3,
9599,
4390,
3963,
787,
10023,
367,
282,
10144,
13,
475,
13,
1180,
8744,
543,
2414,
23012,
199,
3,
486,
10475,
397,
436,
2291,
787,
30390,
1503,
722,
68,
370,
16077,
282,
2868,
2290,
199,
3,
7591,
15878,
2839,
5444,
390,
736,
14,
199,
3,
199,
3,
961,
2240,
365,
2868,
2290,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
3,
199,
4605,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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