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
|
|---|---|---|---|---|---|---|---|---|
as110/as110.github.io
|
node_modules/grunt-docker/node_modules/docker/node_modules/pygmentize-bundled/vendor/pygments/build-3.3/pygments/formatters/__init__.py
|
363
|
1827
|
# -*- coding: utf-8 -*-
"""
pygments.formatters
~~~~~~~~~~~~~~~~~~~
Pygments formatters.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import os.path
import fnmatch
from pygments.formatters._mapping import FORMATTERS
from pygments.plugin import find_plugin_formatters
from pygments.util import ClassNotFound
ns = globals()
for fcls in FORMATTERS:
ns[fcls.__name__] = fcls
del fcls
__all__ = ['get_formatter_by_name', 'get_formatter_for_filename',
'get_all_formatters'] + [cls.__name__ for cls in FORMATTERS]
_formatter_alias_cache = {}
_formatter_filename_cache = []
def _init_formatter_cache():
if _formatter_alias_cache:
return
for cls in get_all_formatters():
for alias in cls.aliases:
_formatter_alias_cache[alias] = cls
for fn in cls.filenames:
_formatter_filename_cache.append((fn, cls))
def find_formatter_class(name):
_init_formatter_cache()
cls = _formatter_alias_cache.get(name, None)
return cls
def get_formatter_by_name(name, **options):
_init_formatter_cache()
cls = _formatter_alias_cache.get(name, None)
if not cls:
raise ClassNotFound("No formatter found for name %r" % name)
return cls(**options)
def get_formatter_for_filename(fn, **options):
_init_formatter_cache()
fn = os.path.basename(fn)
for pattern, cls in _formatter_filename_cache:
if fnmatch.fnmatch(fn, pattern):
return cls(**options)
raise ClassNotFound("No formatter found for file name %r" % fn)
def get_all_formatters():
"""Return a generator for all formatters."""
for formatter in FORMATTERS:
yield formatter
for _, formatter in find_plugin_formatters():
yield formatter
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
24270,
272,
18294,
23597,
339,
14493,
30514,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
646,
747,
14,
515,
199,
646,
15951,
199,
199,
504,
13277,
14,
24270,
423,
4745,
492,
11295,
619,
1157,
51,
199,
504,
13277,
14,
2718,
492,
2342,
63,
2718,
63,
24270,
199,
504,
13277,
14,
1974,
492,
8089,
4667,
199,
199,
561,
275,
7992,
342,
199,
509,
289,
1886,
315,
11295,
619,
1157,
51,
26,
272,
700,
59,
70,
1886,
855,
354,
22705,
275,
289,
1886,
199,
2264,
289,
1886,
199,
199,
363,
452,
363,
275,
788,
362,
63,
8911,
63,
991,
63,
354,
297,
283,
362,
63,
8911,
63,
509,
63,
1501,
297,
1779,
283,
362,
63,
452,
63,
24270,
418,
435,
359,
1886,
855,
354,
363,
367,
843,
315,
11295,
619,
1157,
51,
61,
421,
199,
63,
8911,
63,
3620,
63,
1637,
275,
1052,
199,
63,
8911,
63,
1501,
63,
1637,
275,
942,
199,
199,
318,
485,
826,
63,
8911,
63,
1637,
837,
272,
340,
485,
8911,
63,
3620,
63,
1637,
26,
267,
372,
272,
367,
843,
315,
664,
63,
452,
63,
24270,
837,
267,
367,
5162,
315,
843,
14,
8602,
26,
288,
485,
8911,
63,
3620,
63,
1637,
59,
3620,
61,
275,
843,
267,
367,
4325,
315,
843,
14,
10309,
26,
288,
485,
8911,
63,
1501,
63,
1637,
14,
740,
1332,
2324,
12,
843,
430,
421,
199,
318,
2342,
63,
8911,
63,
533,
8,
354,
304,
272,
485,
826,
63,
8911,
63,
1637,
342,
272,
843,
275,
485,
8911,
63,
3620,
63,
1637,
14,
362,
8,
354,
12,
488,
9,
272,
372,
843,
421,
199,
318,
664,
63,
8911,
63,
991,
63,
354,
8,
354,
12,
1011,
1419,
304,
272,
485,
826,
63,
8911,
63,
1637,
342,
272,
843,
275,
485,
8911,
63,
3620,
63,
1637,
14,
362,
8,
354,
12,
488,
9,
272,
340,
440,
843,
26,
267,
746,
8089,
4667,
480,
1944,
9698,
1911,
367,
536,
450,
82,
2,
450,
536,
9,
272,
372,
843,
3682,
1419,
9,
421,
199,
318,
664,
63,
8911,
63,
509,
63,
1501,
8,
2324,
12,
1011,
1419,
304,
272,
485,
826,
63,
8911,
63,
1637,
342,
272,
4325,
275,
747,
14,
515,
14,
4846,
8,
2324,
9,
272,
367,
3851,
12,
843,
315,
485,
8911,
63,
1501,
63,
1637,
26,
267,
340,
15951,
14,
15359,
8,
2324,
12,
3851,
304,
288,
372,
843,
3682,
1419,
9,
272,
746,
8089,
4667,
480,
1944,
9698,
1911,
367,
570,
536,
450,
82,
2,
450,
4325,
9,
421,
199,
318,
664,
63,
452,
63,
24270,
837,
272,
408,
1767,
282,
4306,
367,
1006,
30514,
1041,
272,
367,
9698,
315,
11295,
619,
1157,
51,
26,
267,
1995,
9698,
272,
367,
5501,
9698,
315,
2342,
63,
2718,
63,
24270,
837,
267,
1995,
9698,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
24270,
272,
18294,
23597,
339,
14493,
30514,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
646,
747,
14,
515,
199,
646,
15951,
199,
199,
504,
13277,
14,
24270,
423,
4745,
492,
11295,
619,
1157,
51,
199,
504,
13277,
14,
2718,
492,
2342,
63,
2718,
63,
24270,
199,
504,
13277,
14,
1974,
492,
8089,
4667,
199,
199,
561,
275,
7992,
342,
199,
509,
289,
1886,
315,
11295,
619,
1157,
51,
26,
272,
700,
59,
70,
1886,
855,
354,
22705,
275,
289,
1886,
199,
2264,
289,
1886,
199,
199,
363,
452,
363,
275,
788,
362,
63,
8911,
63,
991,
63,
354,
297,
283,
362,
63,
8911,
63,
509,
63,
1501,
297,
1779,
283,
362,
63,
452,
63,
24270,
418,
435,
359,
1886,
855,
354,
363,
367,
843,
315,
11295,
619,
1157,
51,
61,
421,
199,
63,
8911,
63,
3620,
63,
1637,
275,
1052,
199,
63,
8911,
63,
1501,
63,
1637,
275,
942,
199,
199,
318,
485,
826,
63,
8911,
63,
1637,
837,
272,
340,
485,
8911,
63,
3620,
63,
1637,
26,
267,
372,
272,
367,
843,
315,
664,
63,
452,
63,
24270,
837,
267,
367,
5162,
315,
843,
14,
8602,
26,
288,
485,
8911,
63,
3620,
63,
1637,
59,
3620,
61,
275,
843,
267,
367,
4325,
315,
843,
14,
10309,
26,
288,
485,
8911,
63,
1501,
63,
1637,
14,
740,
1332,
2324,
12,
843,
430,
421,
199,
318,
2342,
63,
8911,
63,
533,
8,
354,
304,
272,
485,
826,
63,
8911,
63,
1637,
342,
272,
843,
275,
485,
8911,
63,
3620,
63,
1637,
14,
362,
8,
354,
12,
488,
9,
272,
372,
843,
421,
199,
318,
664,
63,
8911,
63,
991,
63,
354,
8,
354,
12,
1011,
1419,
304,
272,
485,
826,
63,
8911,
63,
1637,
342,
272,
843,
275,
485,
8911,
63,
3620,
63,
1637,
14,
362,
8,
354,
12,
488,
9,
272,
340,
440,
843,
26,
267,
746,
8089,
4667,
480,
1944,
9698,
1911,
367,
536,
450,
82,
2,
450,
536,
9,
272,
372,
843,
3682,
1419,
9,
421,
199,
318,
664,
63,
8911,
63,
509,
63,
1501,
8,
2324,
12,
1011,
1419,
304,
272,
485,
826,
63,
8911,
63,
1637,
342,
272,
4325,
275,
747,
14,
515,
14,
4846,
8,
2324,
9,
272,
367,
3851,
12,
843,
315,
485,
8911,
63,
1501,
63,
1637,
26,
267,
340,
15951,
14,
15359,
8,
2324,
12,
3851,
304,
288,
372,
843,
3682,
1419,
9,
272,
746,
8089,
4667,
480,
1944,
9698,
1911,
367,
570,
536,
450,
82,
2,
450,
4325,
9,
421,
199,
318,
664,
63,
452,
63,
24270,
837,
272,
408,
1767,
282,
4306,
367,
1006,
30514,
1041,
272,
367,
9698,
315,
11295,
619,
1157,
51,
26,
267,
1995,
9698,
272,
367,
5501,
9698,
315,
2342,
63,
2718,
63,
24270,
837,
267,
1995,
9698,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
UOMx/edx-platform
|
openedx/core/djangoapps/credentials/tests/test_utils.py
|
2
|
4932
|
"""Tests covering Credentials utilities."""
import unittest
from django.conf import settings
from django.core.cache import cache
from django.test import TestCase
from nose.plugins.attrib import attr
import httpretty
from edx_oauth2_provider.tests.factories import ClientFactory
from provider.constants import CONFIDENTIAL
from openedx.core.djangoapps.credentials.tests.mixins import CredentialsApiConfigMixin, CredentialsDataMixin
from openedx.core.djangoapps.credentials.models import CredentialsApiConfig
from openedx.core.djangoapps.credentials.utils import (
get_user_credentials, get_user_program_credentials
)
from openedx.core.djangoapps.programs.tests.mixins import ProgramsApiConfigMixin, ProgramsDataMixin
from openedx.core.djangoapps.programs.models import ProgramsApiConfig
from student.tests.factories import UserFactory
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@attr('shard_2')
class TestCredentialsRetrieval(ProgramsApiConfigMixin, CredentialsApiConfigMixin, CredentialsDataMixin,
ProgramsDataMixin, TestCase):
""" Tests covering the retrieval of user credentials from the Credentials
service.
"""
def setUp(self):
super(TestCredentialsRetrieval, self).setUp()
ClientFactory(name=CredentialsApiConfig.OAUTH2_CLIENT_NAME, client_type=CONFIDENTIAL)
ClientFactory(name=ProgramsApiConfig.OAUTH2_CLIENT_NAME, client_type=CONFIDENTIAL)
self.user = UserFactory()
cache.clear()
@httpretty.activate
def test_get_user_credentials(self):
"""Verify user credentials data can be retrieve."""
self.create_credentials_config()
self.mock_credentials_api(self.user)
actual = get_user_credentials(self.user)
self.assertEqual(actual, self.CREDENTIALS_API_RESPONSE['results'])
@httpretty.activate
def test_get_user_credentials_caching(self):
"""Verify that when enabled, the cache is used for non-staff users."""
self.create_credentials_config(cache_ttl=1)
self.mock_credentials_api(self.user)
# Warm up the cache.
get_user_credentials(self.user)
# Hit the cache.
get_user_credentials(self.user)
# Verify only one request was made.
self.assertEqual(len(httpretty.httpretty.latest_requests), 1)
staff_user = UserFactory(is_staff=True)
# Hit the Credentials API twice.
for _ in range(2):
get_user_credentials(staff_user)
# Verify that three requests have been made (one for student, two for staff).
self.assertEqual(len(httpretty.httpretty.latest_requests), 3)
def test_get_user_program_credentials_issuance_disable(self):
"""Verify that user program credentials cannot be retrieved if issuance is disabled."""
self.create_credentials_config(enable_learner_issuance=False)
actual = get_user_program_credentials(self.user)
self.assertEqual(actual, [])
@httpretty.activate
def test_get_user_program_credentials_no_credential(self):
"""Verify behavior if no credential exist."""
self.create_credentials_config()
self.mock_credentials_api(self.user, data={'results': []})
actual = get_user_program_credentials(self.user)
self.assertEqual(actual, [])
@httpretty.activate
def test_get_user_programs_credentials(self):
"""Verify program credentials data can be retrieved and parsed correctly."""
# create credentials and program configuration
self.create_credentials_config()
self.create_programs_config()
# Mocking the API responses from programs and credentials
self.mock_programs_api()
self.mock_credentials_api(self.user, reset_url=False)
actual = get_user_program_credentials(self.user)
expected = self.PROGRAMS_API_RESPONSE['results'][:2]
expected[0]['credential_url'] = self.PROGRAMS_CREDENTIALS_DATA[0]['certificate_url']
expected[1]['credential_url'] = self.PROGRAMS_CREDENTIALS_DATA[1]['certificate_url']
# checking response from API is as expected
self.assertEqual(len(actual), 2)
self.assertEqual(actual, expected)
@httpretty.activate
def test_get_user_program_credentials_revoked(self):
"""Verify behavior if credential revoked."""
self.create_credentials_config()
credential_data = {"results": [
{
"id": 1,
"username": "test",
"credential": {
"credential_id": 1,
"program_id": 1
},
"status": "revoked",
"uuid": "dummy-uuid-1"
}
]}
self.mock_credentials_api(self.user, data=credential_data)
actual = get_user_program_credentials(self.user)
self.assertEqual(actual, [])
|
agpl-3.0
|
[
624,
2925,
8486,
316,
23934,
15841,
1041,
199,
646,
2882,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
1637,
492,
2581,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
646,
22768,
9118,
199,
504,
22435,
63,
6126,
18,
63,
3780,
14,
2219,
14,
15406,
492,
6810,
2927,
199,
504,
5022,
14,
5559,
492,
6392,
7466,
4938,
199,
199,
504,
22709,
14,
1018,
14,
16432,
14,
6942,
14,
2219,
14,
30192,
492,
23934,
7394,
2028,
4256,
12,
23934,
1451,
4256,
199,
504,
22709,
14,
1018,
14,
16432,
14,
6942,
14,
992,
492,
23934,
7394,
2028,
199,
504,
22709,
14,
1018,
14,
16432,
14,
6942,
14,
1208,
492,
334,
272,
664,
63,
751,
63,
6942,
12,
664,
63,
751,
63,
6815,
63,
6942,
199,
9,
199,
504,
22709,
14,
1018,
14,
16432,
14,
28464,
14,
2219,
14,
30192,
492,
2165,
9292,
7394,
2028,
4256,
12,
2165,
9292,
1451,
4256,
199,
504,
22709,
14,
1018,
14,
16432,
14,
28464,
14,
992,
492,
2165,
9292,
7394,
2028,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
421,
199,
32,
2796,
14,
11278,
8,
1751,
14,
5441,
63,
18125,
508,
283,
15807,
14,
3603,
297,
283,
774,
1454,
1686,
315,
21577,
358,
199,
32,
962,
360,
10810,
63,
18,
358,
199,
533,
1379,
13428,
6816,
322,
2579,
8,
919,
9292,
7394,
2028,
4256,
12,
23934,
7394,
2028,
4256,
12,
23934,
1451,
4256,
12,
3044,
2165,
9292,
1451,
4256,
12,
7640,
304,
272,
408,
6496,
8486,
316,
314,
27157,
402,
922,
6235,
687,
314,
23934,
272,
2435,
14,
272,
408,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
13428,
6816,
322,
2579,
12,
291,
680,
5996,
342,
398,
6810,
2927,
8,
354,
29,
13428,
7394,
2028,
14,
24041,
18,
63,
9901,
63,
2339,
12,
1890,
63,
466,
29,
3103,
7466,
4938,
9,
267,
6810,
2927,
8,
354,
29,
919,
9292,
7394,
2028,
14,
24041,
18,
63,
9901,
63,
2339,
12,
1890,
63,
466,
29,
3103,
7466,
4938,
9,
267,
291,
14,
751,
275,
16047,
342,
398,
2581,
14,
3584,
342,
339,
768,
16916,
9118,
14,
8222,
272,
347,
511,
63,
362,
63,
751,
63,
6942,
8,
277,
304,
267,
408,
7496,
922,
6235,
666,
883,
506,
8044,
1041,
267,
291,
14,
981,
63,
6942,
63,
888,
342,
267,
291,
14,
1805,
63,
6942,
63,
1246,
8,
277,
14,
751,
9,
398,
3503,
275,
664,
63,
751,
63,
6942,
8,
277,
14,
751,
9,
267,
291,
14,
629,
8,
6514,
12,
291,
14,
30553,
8246,
51,
63,
3735,
63,
12801,
459,
2604,
1105,
339,
768,
16916,
9118,
14,
8222,
272,
347,
511,
63,
362,
63,
751,
63,
6942,
63,
22738,
8,
277,
304,
267,
408,
7496,
626,
1380,
5223,
12,
314,
2581,
365,
1202,
367,
2222,
13,
7018,
4390,
1041,
267,
291,
14,
981,
63,
6942,
63,
888,
8,
1637,
63,
12130,
29,
17,
9,
267,
291,
14,
1805,
63,
6942,
63,
1246,
8,
277,
14,
751,
9,
398,
327,
644,
5362,
1536,
314,
2581,
14,
267,
664,
63,
751,
63,
6942,
8,
277,
14,
751,
9,
398,
327,
869,
390,
314,
2581,
14,
267,
664,
63,
751,
63,
6942,
8,
277,
14,
751,
9,
398,
327,
7635,
1454,
1373,
1056,
1990,
6326,
14,
267,
291,
14,
629,
8,
552,
8,
16916,
9118,
14,
16916,
9118,
14,
7410,
63,
6615,
395,
413,
9,
398,
12622,
63,
751,
275,
16047,
8,
374,
63,
7018,
29,
549,
9,
398,
327,
869,
390,
314,
23934,
3261,
13373,
14,
267,
367,
485,
315,
1425,
8,
18,
304,
288,
664,
63,
751,
63,
6942,
8,
7018,
63,
751,
9,
398,
327,
7635,
626,
7795,
4145,
1172,
2757,
6326,
334,
368,
367,
6474,
12,
2877,
367,
12622,
680,
267,
291,
14,
629,
8,
552,
8,
16916,
9118,
14,
16916,
9118,
14,
7410,
63,
6615,
395,
650,
9,
339,
347,
511,
63,
362,
63,
751,
63,
6815,
63,
6942,
63,
374,
9648,
554,
63,
5993,
8,
277,
304,
267,
408,
7496,
626,
922,
2240,
6235,
3913,
506,
12396,
340,
365,
9648,
554,
365,
6980,
1041,
267,
291,
14,
981,
63,
6942,
63,
888,
8,
4296,
63,
29144,
63,
374,
9648,
554,
29,
797,
9,
267,
3503,
275,
664,
63,
751,
63,
6815,
63,
6942,
8,
277,
14,
751,
9,
267,
291,
14,
629,
8,
6514,
12,
3073,
339,
768,
16916,
9118,
14,
8222,
272,
347,
511,
63,
362,
63,
751,
63,
6815,
63,
6942,
63,
889,
63,
15591,
8,
277,
304,
267,
408,
7496,
5953,
340,
949,
16338,
2187,
1041,
267,
291,
14,
981,
63,
6942,
63,
888,
342,
267,
291,
14,
1805,
63,
6942,
63,
1246,
8,
277,
14,
751,
12,
666,
3713,
2604,
356,
942,
1552,
267,
3503,
275,
664,
63,
751,
63,
6815,
63,
6942,
8,
277,
14,
751,
9,
267,
291,
14,
629,
8,
6514,
12,
3073,
339,
768,
16916,
9118,
14,
8222,
272,
347,
511,
63,
362,
63,
751,
63,
28464,
63,
6942,
8,
277,
304,
267,
408,
7496,
2240,
6235,
666,
883,
506,
12396,
436,
4565,
6657,
1041,
267,
327,
1218,
6235,
436,
2240,
2897,
267,
291,
14,
981,
63,
6942,
63,
888,
342,
267,
291,
14,
981,
63,
28464,
63,
888,
342,
398,
327,
4420,
316,
314,
3261,
9320,
687,
18572,
436,
6235,
267,
291,
14,
1805,
63,
28464,
63,
1246,
342,
267,
291,
14,
1805,
63,
6942,
63,
1246,
8,
277,
14,
751,
12,
5305,
63,
633,
29,
797,
9,
398,
3503,
275,
664,
63,
751,
63,
6815,
63,
6942,
8,
277,
14,
751,
9,
267,
1420,
275,
291,
14,
15605,
51,
63,
3735,
63,
12801,
459,
2604,
418,
1491,
18,
61,
267,
1420,
59,
16,
2733,
15591,
63,
633,
418,
275,
291,
14,
15605,
51,
63,
30553,
8246,
51,
63,
3998,
59,
16,
2733,
6999,
63,
633,
418,
267,
1420,
59,
17,
2733,
15591,
63,
633,
418,
275,
291,
14,
15605,
51,
63,
30553,
8246,
51,
63,
3998,
59,
17,
2733,
6999,
63,
633,
418,
398,
327,
7907,
1177,
687,
3261,
365,
465,
1420,
267,
291,
14,
629,
8,
552,
8,
6514,
395,
499,
9,
267,
291,
14,
629,
8,
6514,
12,
1420,
9,
339,
768,
16916,
9118,
14,
8222,
272,
347
] |
[
2925,
8486,
316,
23934,
15841,
1041,
199,
646,
2882,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
1637,
492,
2581,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
646,
22768,
9118,
199,
504,
22435,
63,
6126,
18,
63,
3780,
14,
2219,
14,
15406,
492,
6810,
2927,
199,
504,
5022,
14,
5559,
492,
6392,
7466,
4938,
199,
199,
504,
22709,
14,
1018,
14,
16432,
14,
6942,
14,
2219,
14,
30192,
492,
23934,
7394,
2028,
4256,
12,
23934,
1451,
4256,
199,
504,
22709,
14,
1018,
14,
16432,
14,
6942,
14,
992,
492,
23934,
7394,
2028,
199,
504,
22709,
14,
1018,
14,
16432,
14,
6942,
14,
1208,
492,
334,
272,
664,
63,
751,
63,
6942,
12,
664,
63,
751,
63,
6815,
63,
6942,
199,
9,
199,
504,
22709,
14,
1018,
14,
16432,
14,
28464,
14,
2219,
14,
30192,
492,
2165,
9292,
7394,
2028,
4256,
12,
2165,
9292,
1451,
4256,
199,
504,
22709,
14,
1018,
14,
16432,
14,
28464,
14,
992,
492,
2165,
9292,
7394,
2028,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
421,
199,
32,
2796,
14,
11278,
8,
1751,
14,
5441,
63,
18125,
508,
283,
15807,
14,
3603,
297,
283,
774,
1454,
1686,
315,
21577,
358,
199,
32,
962,
360,
10810,
63,
18,
358,
199,
533,
1379,
13428,
6816,
322,
2579,
8,
919,
9292,
7394,
2028,
4256,
12,
23934,
7394,
2028,
4256,
12,
23934,
1451,
4256,
12,
3044,
2165,
9292,
1451,
4256,
12,
7640,
304,
272,
408,
6496,
8486,
316,
314,
27157,
402,
922,
6235,
687,
314,
23934,
272,
2435,
14,
272,
408,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
13428,
6816,
322,
2579,
12,
291,
680,
5996,
342,
398,
6810,
2927,
8,
354,
29,
13428,
7394,
2028,
14,
24041,
18,
63,
9901,
63,
2339,
12,
1890,
63,
466,
29,
3103,
7466,
4938,
9,
267,
6810,
2927,
8,
354,
29,
919,
9292,
7394,
2028,
14,
24041,
18,
63,
9901,
63,
2339,
12,
1890,
63,
466,
29,
3103,
7466,
4938,
9,
267,
291,
14,
751,
275,
16047,
342,
398,
2581,
14,
3584,
342,
339,
768,
16916,
9118,
14,
8222,
272,
347,
511,
63,
362,
63,
751,
63,
6942,
8,
277,
304,
267,
408,
7496,
922,
6235,
666,
883,
506,
8044,
1041,
267,
291,
14,
981,
63,
6942,
63,
888,
342,
267,
291,
14,
1805,
63,
6942,
63,
1246,
8,
277,
14,
751,
9,
398,
3503,
275,
664,
63,
751,
63,
6942,
8,
277,
14,
751,
9,
267,
291,
14,
629,
8,
6514,
12,
291,
14,
30553,
8246,
51,
63,
3735,
63,
12801,
459,
2604,
1105,
339,
768,
16916,
9118,
14,
8222,
272,
347,
511,
63,
362,
63,
751,
63,
6942,
63,
22738,
8,
277,
304,
267,
408,
7496,
626,
1380,
5223,
12,
314,
2581,
365,
1202,
367,
2222,
13,
7018,
4390,
1041,
267,
291,
14,
981,
63,
6942,
63,
888,
8,
1637,
63,
12130,
29,
17,
9,
267,
291,
14,
1805,
63,
6942,
63,
1246,
8,
277,
14,
751,
9,
398,
327,
644,
5362,
1536,
314,
2581,
14,
267,
664,
63,
751,
63,
6942,
8,
277,
14,
751,
9,
398,
327,
869,
390,
314,
2581,
14,
267,
664,
63,
751,
63,
6942,
8,
277,
14,
751,
9,
398,
327,
7635,
1454,
1373,
1056,
1990,
6326,
14,
267,
291,
14,
629,
8,
552,
8,
16916,
9118,
14,
16916,
9118,
14,
7410,
63,
6615,
395,
413,
9,
398,
12622,
63,
751,
275,
16047,
8,
374,
63,
7018,
29,
549,
9,
398,
327,
869,
390,
314,
23934,
3261,
13373,
14,
267,
367,
485,
315,
1425,
8,
18,
304,
288,
664,
63,
751,
63,
6942,
8,
7018,
63,
751,
9,
398,
327,
7635,
626,
7795,
4145,
1172,
2757,
6326,
334,
368,
367,
6474,
12,
2877,
367,
12622,
680,
267,
291,
14,
629,
8,
552,
8,
16916,
9118,
14,
16916,
9118,
14,
7410,
63,
6615,
395,
650,
9,
339,
347,
511,
63,
362,
63,
751,
63,
6815,
63,
6942,
63,
374,
9648,
554,
63,
5993,
8,
277,
304,
267,
408,
7496,
626,
922,
2240,
6235,
3913,
506,
12396,
340,
365,
9648,
554,
365,
6980,
1041,
267,
291,
14,
981,
63,
6942,
63,
888,
8,
4296,
63,
29144,
63,
374,
9648,
554,
29,
797,
9,
267,
3503,
275,
664,
63,
751,
63,
6815,
63,
6942,
8,
277,
14,
751,
9,
267,
291,
14,
629,
8,
6514,
12,
3073,
339,
768,
16916,
9118,
14,
8222,
272,
347,
511,
63,
362,
63,
751,
63,
6815,
63,
6942,
63,
889,
63,
15591,
8,
277,
304,
267,
408,
7496,
5953,
340,
949,
16338,
2187,
1041,
267,
291,
14,
981,
63,
6942,
63,
888,
342,
267,
291,
14,
1805,
63,
6942,
63,
1246,
8,
277,
14,
751,
12,
666,
3713,
2604,
356,
942,
1552,
267,
3503,
275,
664,
63,
751,
63,
6815,
63,
6942,
8,
277,
14,
751,
9,
267,
291,
14,
629,
8,
6514,
12,
3073,
339,
768,
16916,
9118,
14,
8222,
272,
347,
511,
63,
362,
63,
751,
63,
28464,
63,
6942,
8,
277,
304,
267,
408,
7496,
2240,
6235,
666,
883,
506,
12396,
436,
4565,
6657,
1041,
267,
327,
1218,
6235,
436,
2240,
2897,
267,
291,
14,
981,
63,
6942,
63,
888,
342,
267,
291,
14,
981,
63,
28464,
63,
888,
342,
398,
327,
4420,
316,
314,
3261,
9320,
687,
18572,
436,
6235,
267,
291,
14,
1805,
63,
28464,
63,
1246,
342,
267,
291,
14,
1805,
63,
6942,
63,
1246,
8,
277,
14,
751,
12,
5305,
63,
633,
29,
797,
9,
398,
3503,
275,
664,
63,
751,
63,
6815,
63,
6942,
8,
277,
14,
751,
9,
267,
1420,
275,
291,
14,
15605,
51,
63,
3735,
63,
12801,
459,
2604,
418,
1491,
18,
61,
267,
1420,
59,
16,
2733,
15591,
63,
633,
418,
275,
291,
14,
15605,
51,
63,
30553,
8246,
51,
63,
3998,
59,
16,
2733,
6999,
63,
633,
418,
267,
1420,
59,
17,
2733,
15591,
63,
633,
418,
275,
291,
14,
15605,
51,
63,
30553,
8246,
51,
63,
3998,
59,
17,
2733,
6999,
63,
633,
418,
398,
327,
7907,
1177,
687,
3261,
365,
465,
1420,
267,
291,
14,
629,
8,
552,
8,
6514,
395,
499,
9,
267,
291,
14,
629,
8,
6514,
12,
1420,
9,
339,
768,
16916,
9118,
14,
8222,
272,
347,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
grap/account-financial-tools
|
__unported__/account_tax_update/__init__.py
|
44
|
1084
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2012 Therp BV (<http://therp.nl>).
# This module copyright (C) 2013 Camptocamp (<http://www.camptocamp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import model
|
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,
6029,
377,
2523,
80,
699,
54,
8642,
1014,
921,
728,
80,
14,
7530,
10121,
199,
3,
259,
961,
859,
4248,
334,
35,
9,
6171,
24569,
475,
20290,
8642,
1014,
921,
1544,
14,
20290,
475,
20290,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
1275,
492,
1402,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
6029,
377,
2523,
80,
699,
54,
8642,
1014,
921,
728,
80,
14,
7530,
10121,
199,
3,
259,
961,
859,
4248,
334,
35,
9,
6171,
24569,
475,
20290,
8642,
1014,
921,
1544,
14,
20290,
475,
20290,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
1275,
492,
1402,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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Y3K = True
except AttributeError:
pass #Not all versions have sys.version_info
import thriftpy
profiler = thriftpy.load(os.path.join(os.path.dirname(os.path.realpath(__file__)), "profiler.thrift"), module_name="profiler_thrift")
from thriftpy.protocol.binary import TBinaryProtocolFactory
from thriftpy.transport import TMemoryBuffer
# noinspection PyUnresolvedReferences
from profiler_thrift import ProfilerRequest, ProfilerResponse, Stats, FuncStat, Function, TreeStats, CallTreeStat
def serialize(thrift_object,
protocol_factory=TBinaryProtocolFactory()):
transport = TMemoryBuffer()
protocol = protocol_factory.get_protocol(transport)
thrift_object.write(protocol)
return transport.getvalue()
def deserialize(base,
buf,
protocol_factory=TBinaryProtocolFactory()):
transport = TMemoryBuffer(buf)
protocol = protocol_factory.get_protocol(transport)
base.read(protocol)
return base
if IS_PY3K:
import pkgutil
else:
from _imps import _pydev_pkgutil_old as pkgutil
|
apache-2.0
|
[
646,
747,
199,
646,
984,
199,
199,
1311,
63,
4521,
19,
43,
275,
756,
199,
199,
893,
26,
272,
340,
984,
14,
1023,
63,
815,
59,
16,
61,
2356,
650,
26,
267,
2281,
63,
4521,
19,
43,
275,
715,
199,
2590,
4281,
26,
272,
986,
221,
327,
1763,
1006,
5459,
1172,
984,
14,
1023,
63,
815,
199,
199,
646,
17199,
647,
199,
20132,
275,
17199,
647,
14,
912,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
22159,
298,
20132,
14,
8430,
1288,
859,
63,
354,
628,
20132,
63,
8430,
531,
421,
199,
504,
17199,
647,
14,
3922,
14,
3008,
492,
15934,
2927,
199,
504,
17199,
647,
14,
5545,
492,
377,
8628,
3299,
199,
199,
3,
30870,
1611,
1358,
13697,
15242,
199,
504,
23173,
63,
8430,
492,
14386,
82,
2017,
12,
14386,
82,
2364,
12,
29062,
12,
28794,
11232,
12,
6801,
12,
12178,
8257,
12,
23491,
11232,
199,
199,
318,
8437,
8,
8430,
63,
785,
12,
1598,
4113,
63,
3702,
29,
16805,
2927,
5109,
272,
7773,
275,
377,
8628,
3299,
342,
272,
4113,
275,
4113,
63,
3702,
14,
362,
63,
3922,
8,
5545,
9,
272,
17199,
63,
785,
14,
952,
8,
3922,
9,
272,
372,
7773,
14,
7150,
342,
199,
199,
318,
22920,
8,
1095,
12,
355,
4123,
12,
355,
4113,
63,
3702,
29,
16805,
2927,
5109,
272,
7773,
275,
377,
8628,
3299,
8,
1436,
9,
272,
4113,
275,
4113,
63,
3702,
14,
362,
63,
3922,
8,
5545,
9,
272,
1300,
14,
739,
8,
3922,
9,
272,
372,
1300,
421,
199,
692,
2281,
63,
4521,
19,
43,
26,
272,
492,
28728,
199,
2836,
26,
272,
687,
485,
3236,
83,
492,
485,
23996,
63,
4600,
1974,
63,
1753,
465,
28728,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
199,
646,
984,
199,
199,
1311,
63,
4521,
19,
43,
275,
756,
199,
199,
893,
26,
272,
340,
984,
14,
1023,
63,
815,
59,
16,
61,
2356,
650,
26,
267,
2281,
63,
4521,
19,
43,
275,
715,
199,
2590,
4281,
26,
272,
986,
221,
327,
1763,
1006,
5459,
1172,
984,
14,
1023,
63,
815,
199,
199,
646,
17199,
647,
199,
20132,
275,
17199,
647,
14,
912,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
22159,
298,
20132,
14,
8430,
1288,
859,
63,
354,
628,
20132,
63,
8430,
531,
421,
199,
504,
17199,
647,
14,
3922,
14,
3008,
492,
15934,
2927,
199,
504,
17199,
647,
14,
5545,
492,
377,
8628,
3299,
199,
199,
3,
30870,
1611,
1358,
13697,
15242,
199,
504,
23173,
63,
8430,
492,
14386,
82,
2017,
12,
14386,
82,
2364,
12,
29062,
12,
28794,
11232,
12,
6801,
12,
12178,
8257,
12,
23491,
11232,
199,
199,
318,
8437,
8,
8430,
63,
785,
12,
1598,
4113,
63,
3702,
29,
16805,
2927,
5109,
272,
7773,
275,
377,
8628,
3299,
342,
272,
4113,
275,
4113,
63,
3702,
14,
362,
63,
3922,
8,
5545,
9,
272,
17199,
63,
785,
14,
952,
8,
3922,
9,
272,
372,
7773,
14,
7150,
342,
199,
199,
318,
22920,
8,
1095,
12,
355,
4123,
12,
355,
4113,
63,
3702,
29,
16805,
2927,
5109,
272,
7773,
275,
377,
8628,
3299,
8,
1436,
9,
272,
4113,
275,
4113,
63,
3702,
14,
362,
63,
3922,
8,
5545,
9,
272,
1300,
14,
739,
8,
3922,
9,
272,
372,
1300,
421,
199,
692,
2281,
63,
4521,
19,
43,
26,
272,
492,
28728,
199,
2836,
26,
272,
687,
485,
3236,
83,
492,
485,
23996,
63,
4600,
1974,
63,
1753,
465,
28728,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
mkelcb/knet
|
knet/com/io/knet_IO.py
|
1
|
22995
|
# -*- coding: utf-8 -*-
#MIT License
#Copyright (c) 2017 Marton Kelemen
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
import numpy as np
import struct
#import pyplink
# from pyplink import *
#from ..pyplink import PyPlink
#from ..io.pyplink import PyPlink
#from ..io.pyplink import *
from ..io import pyplink
from pathlib import Path
import collections
import gc
##################################################################################################
# PLINK Binary / Phenotype Load
##################################################################################################
#location= "C:/Users/leo/Google Drive/PHD/0Rotations/!0Implementation/tests/knet/py/data/toy/wtccc2_hg19_toy"
#results = loadPLINK(location, recodeCaseControl = False)
#location = args.bfile
#males = fam.gender == 1
#for genotypes in bed.iter_geno_marker(bim.pos):
# male_genotypes = genotypes[males.values]
#male_genotypes = genotypes[males.values]
#location = args.out
def get_d_code(dataType) : # need to convert dataType into single letter codes
if( dataType == 'float32') : d_code = 'f'
elif ( dataType == 'float16') : d_code = 'e'
else : d_code = 'd'
return(d_code)
def writePLINK_Pheno(location, y, indList = None) :
y = y.ravel()
with open(location + ".pheno", "w") as file:
for i in range(0, len(y) ):
if indList is None : file.write("IND"+ str(int(i+1)) + "\tIND" + str(int(i+1)) + "\t" +str(y[i]) + "\n")
else : file.write(str(indList[i]) + "\t" +str(indList[i]) + "\t" +str(y[i]) + "\n")
def writePLINK(location, M) :
# load plink file
bed = pyplink.PyPlink(location, mode='w', bed_format='SNP-major')
for i in range(M.shape[1]):
#print("writing SNP", i, "to file")
bed.write_genotypes(M[:,i])
with open(location + ".fam", "w") as file:
for i in range( M.shape[0] ):
file.write("IND"+ str(int(i+1)) + "\tIND" + str(int(i+1)) + "\t0\t0\t0\t0" + "\n")
with open(location + ".bim", "w") as file:
for i in range( M.shape[1] ):
file.write( "1\tSNP" + str(int(i)) + "\t0\t" + str( int( (i+1) * 1000)) + "\tA\tB" + "\n")
#location = args.knet, loadPhenos = False
#male_genotypes = genotypes[males.values]
def loadPLINK(location, loadPhenos = True, caseControl = True, recodeCaseControl = True, replaceMissing = False) :
# load plink file
bed = pyplink.PyPlink(location, mode='r', bed_format='SNP-major')
bim = bed.get_bim()
fam = bed.get_fam()
if loadPhenos :
# process phenotypes
status= fam['status']
if caseControl : # if trait is binary
if recodeCaseControl : y = recodeCaseControlQuantitative(status) # if we want to treat it as a quantitative trait
else : y = recodeCaseControlOneHot(status)# otherwise use the 'softmax' format
else : y = np.array(status)# otherwise just leave it alone
else : y = None # if there are no phenotypes
# load genotypes from PLINK into RAM
M = np.zeros( (bed.get_nb_samples(),bed.get_nb_markers()) , dtype =np.int8) # pre allocate a matrix with the correct size
#loci_names = list()
loci_names = np.empty(bed.get_nb_markers( ), dtype = np.dtype((str, 25)) ) ## assume no rsid will be longer than 25 chars
# Iterating over all loci
counter = 0
for loci_name, genotypes in bed:
if replaceMissing : genotypes[genotypes==-1] = 0 # replace no calls with 0
#if(M is None) :
# M = genotypes
#else :
# M = np.column_stack( (M, genotypes) )
M[:,counter] = genotypes # much faster to just paste this in (column stack is 10x slower)
#loci_names.append(loci_name)
loci_names[counter] = loci_name
counter = counter +1
# produce GCTA compatible ID list
id_list = list()
id_list.append( list(fam["fid"]))
id_list.append( list(fam["iid"]))
return ( {"y" : y, "M" : M, "rsid" : loci_names.tolist(), "IDs" : id_list, "A1" : list(bim.a1), "A2" : list(bim.a2) } ) # return results
#A1_alleles = list(bim.a1)
def recodeCaseControlOneHot(status) :
# transcode phenotype into 1 hot array
y = np.zeros( (len(status),2) )
for i in range(len(status)) :
result = np.array([0,0])
result[ int(status[i] -1) ] =1 # transocde phenotype into one-of-k format: in plink case =2, control =1, so we set the element to 1 to at the inde-1 position
y[i] =result
return(y)
def recodeCaseControlQuantitative(status) : # transcode binary phenotype into a quantitative phenotype ( IE just turn the 1/2 into 0.0 and 1.0 )
y = np.zeros( (len(status)) )
for i in range(len(status)) :
y[i] =(status[i] -1)
return(y)
def recodeOneHotCaseControl(y) :
# transcode 1 hot array into binary
status = np.zeros( ( (len(y), 1) ) , dtype = int )
for i in range(y.shape[0]) :
status[ i ] = int( np.argmax(y[i,:]) + 1 )
return(status)
#location= "C:/!0datasets/adni/wgs/glmnettest/igap05_filtered_f1_train.pheno"
#results = loadPLINKPheno(location, caseControl = False, recodeCaseControl = False)
def loadPLINKPheno(location, caseControl = True, recodeCaseControl = True) :
status = list()
#print("FUCK YOU")
with open(location, "r") as id:
for i in id:
itmp = i.rstrip().split()
status.append( np.float32(itmp[2]) )
if caseControl : # if trait is binary
if recodeCaseControl : y = recodeCaseControlQuantitative(status) # if we want to treat it as a quantitative trait
else : y = recodeCaseControlOneHot(status)# otherwise use the 'softmax' format
else : y = np.array(status)# otherwise just leave it alone
return ( y.astype('float32') )
# column binds Genotype matrices (IE stacks them next to each other)
#M_list = [ results2["M"], results["M"] ]
#allM = concatChroms(M_list)
def concatChroms(M_list) :
return(np.concatenate(M_list, axis=1))
##################################################################################################
# Generic data IO (IE any kind of matrix or array)
##################################################################################################
# writes a matrix onto disk in a binary (2 files, 1 that stores the dimensions, the other the binary data)
def writeMatrixToDisk(location,data, dataType ="float32") :
d_code = get_d_code(dataType)
# get dimensions of matrix
nrows = data.shape[0]
ncols = data.shape[1]
# write the dimensions onto disk
with open(location + ".id", "w") as idFile:
idFile.write(str(nrows) + "\t" +str(ncols) )
# flatten matrix
flat = data.ravel()
flatData = struct.pack(d_code*len(flat),*flat )
with open(location + ".bin", "wb") as flat_File:
flat_File.write(flatData)
# loads matrix from disk ( that was written by the above)
def loadMatrixFromDisk(location, dataType ="float32") :
d_code = get_d_code(dataType)
# load id file to get dimensions
with open(location + ".id", "r") as idFile:
itmp = idFile.readline().rstrip().split()
nrows = int(itmp[0])
ncols = int(itmp[1])
# how many elements to expect in the binary in total
totalNum =nrows * ncols
# open binary file
with open(location + ".bin", "rb") as BinFile:
BinFileContent = BinFile.read()
# reformat data into correct dimensions
flat = np.array( struct.unpack(d_code*totalNum, BinFileContent ), dtype = dataType )
data = flat.reshape(nrows,ncols)
return(data)
# writes an array onto disk ( 2 files, 1 text file that stores the length, the other the binary)
def writeVectorToDisk(location,data, dataType ="float32") :
d_code = get_d_code(dataType)
# write the dimensions onto disk
with open(location + ".id", "w") as idFile:
idFile.write( str( len(data) ) )
flatData = struct.pack(d_code*len(data),*data )
with open(location + ".bin", "wb") as flat_File:
flat_File.write(flatData)
# loads array from disk ( that was written by the above function)
def loadVectorFromDisk(location, dataType ="float32") :
d_code = get_d_code(dataType)
# load id file to get dimensions
with open(location + ".id", "r") as idFile:
itmp = idFile.readline().rstrip()
totalNum = int(itmp) # how many elements to expect in the binary in total
# open binary file
with open(location + ".bin", "rb") as BinFile:
BinFileContent = BinFile.read()
# reformat data into correct dimensions
flat = np.array( struct.unpack(d_code*totalNum, BinFileContent ), dtype = dataType )
return(flat)
def loadIndices(location) :
fileName = location
indices = list()
with open(fileName, "r") as id:
for i in id:
itmp = i.rstrip().split()
indices.append( np.int(itmp[0]) )
return ( np.array(indices) )
def loadsnpIDs(location) :
fileName = location
snpIDs = list()
with open(fileName, "r") as id:
for i in id:
itmp = i.rstrip().split()
snpIDs.append( itmp[0] )
return ( np.array(snpIDs) )
def writeSNPeffects(location,SNPIds, SNP_effects) :
fileName = location
with open(fileName, "w") as file:
for i in range( len(SNPIds) ):
file.write( str(SNPIds[i]) + "\t" + str(SNP_effects[i]) + "\n")
##################################################################################################
# GCTA formatted kinship, as these are Lower Triangle matrices they have to be treated separately
##################################################################################################
# writes a kinship matrix onto disk in the GCTA format
def writeGCTA_GRM(location,K, id_list, numSNPs) :
# generate filenames
BinFileName = location+".grm.bin"
IDFileName = location+".grm.id"
NFileName = location+".grm.N.bin"
# how many to write
numIndis = len(id_list[0])
numPairs = int( numIndis*(numIndis+1)/2 )
N_vals = [numSNPs] * numPairs # the number of surviving SNPs used, the number of Individuals
# write N file
NFileData = struct.pack("f"*numPairs,*N_vals )
del N_vals; gc.collect();
with open(NFileName, "wb") as NFile:
NFile.write(NFileData)
del NFileData; gc.collect();
# write ID list
with open(IDFileName, "w") as idFile:
for i in range( len(id_list[0]) ):
idFile.write(id_list[0][i] + "\t" + id_list[1][i] + "\n")
gc.collect();
# write GRM to disk: unravel the GRM's lower triangle
grm_indices = np.tril_indices(numIndis)
grm_pairs= list (K[grm_indices[0], grm_indices[1]] )
del grm_indices; gc.collect();
# write out binary
GRMFileData = struct.pack("f"*numPairs,*grm_pairs )
del grm_pairs; gc.collect();
with open(BinFileName, "wb") as GRM_File:
GRM_File.write(GRMFileData)
# loads a kinship matrix from disk in the GCTA format ( written out by the above function)
def loadGCTA_GRM(location) :
# generate filenames
BinFileName = location+".grm.bin"
IDFileName = location+".grm.id"
NFileName = location+".grm.N.bin"
# load the familiy/individual IDs
id_list = list()
id_list.append([])
id_list.append([])
with open(IDFileName, "r") as id:
for i in id:
itmp = i.rstrip().split()
id_list[0].append(itmp[0])
id_list[1].append(itmp[1])
id.close()
# how many peopple in total, IE the number of entries in the binary file
n_subj = len(id_list[0])
nn = int( n_subj*(n_subj+1)/2 )
# load Binary
with open(BinFileName, "rb") as BinFile:
BinFileContent = BinFile.read()
BinFile.close()
# reformat it into the correct dimensions ( as only the lower triangle was stored flattened)
K = np.zeros((n_subj, n_subj))
grm_vals = list(struct.unpack("f"*nn, BinFileContent ))
inds = np.tril_indices_from(K)
K[inds] = grm_vals # reconstruct the full matrix from the LT
K[(inds[1], inds[0])] = grm_vals
# load the 'N' file
with open(NFileName, "rb") as NFile:
NFileContent = NFile.read()
NFile.close()
N_vals = list(struct.unpack("f"*nn, NFileContent ))
gc.collect();
return ( {"K" : K, "ids" : id_list, "N" :N_vals} ) # return results
def load_N_fromGCTA_GRM(location) :
NFileName = location+".grm.N.bin"
# load the 'N' file
with open(NFileName, "rb") as NFile:
NFileContent = NFile.read(4) # only load the first 4 bytes = 16 bit float, as unlike GCTA I use the same number of SNPs for all
N = struct.unpack("f", NFileContent )[0]
return ( N )
# writes human readable text file of a Variance Compnent Analysis results
def writeVCResults(location,allModels ) :
# write ID list
with open(location, "w") as targetFile:
for i in range( len(allModels) ):
line = "Model with "+ str( len(allModels[i]["vc"]) ) + " genetic variance component(s):"
print(line) # want to save output to console too..
targetFile.write(line + "\n")
line = "BIC: " + str( allModels[i]["bic"] )
print(line)
targetFile.write(line + "\n")
line = "h2: " + str( allModels[i]["h2"] )
print(line)
targetFile.write(line + "\n")
line = "h2_CI95 lb: " + str( allModels[i]["h2_lb"] ) + " / ub: " + str( allModels[i]["h2_ub"] )
print(line)
targetFile.write(line + "\n")
line = "Ve: " + str( allModels[i]["ve"] )
print(line)
targetFile.write(line + "\n")
epistasisCounter = 2
for j in range( len(allModels[i]["vc"]) ) : # go through all variance components
note = ""
if j == 0 : note ="(additive)" # first element is always the additive VC
elif j == allModels[i]["domcol"] : note ="(dominance)" # if j is the same col as the dominance effect
else :
note ="(epistasis "+str(epistasisCounter)+"-way)"
epistasisCounter = epistasisCounter +1
line = "VC"+str(j+1)+" "+note+": "+ str( allModels[i]["vc"][j] ) + " / p-value: " + str( allModels[i]["p"][j] ) + " / vc_se: " + str( allModels[i]["vc_se"][j] )
print(line + "\n")
targetFile.write(line + "\n")
line = "_________________________________"
print(line)
targetFile.write(line + "\n")
##################################################################################################
# write regions
##################################################################################################
def writeRegionData(location,regions, deltas) :
fileName = location
with open(fileName, "w") as file:
for i in range( len(deltas) ):
file.write( str(regions[i][0]) + "\t" + str(regions[i][1]) + "\t" + str(deltas[i]) + "\n")
def loadRegionData(location) :
fileName = location
regions = list()
deltas = list()
with open(fileName, "r") as id:
for i in id:
itmp = i.rstrip().split()
regions.append( np.array( [int(itmp[0]) , int(itmp[1])] ) )
deltas.append( np.float64(itmp[2]) )
return ( {"REGIONS":regions, "DELTAS":deltas } )
##################################################################################################
# Summary Stats
##################################################################################################
#location ="C:/!0datasets/adni/wgs/stage1_p05_short_ordered.txt"
def loadSummaryStats(location) :
fileName = location
summaryData = list()
with open(fileName, "r") as id:
for i in id:
itmp = i.rstrip().split()
summaryData.append( np.float64(itmp[2]) ) # the Betas are stored in the 3rd column
# process them into priors
# take their abs ( as it doesnt matter if its negative or positive)
summaryData = np.abs(summaryData)
# scale them to be 0-1
max_x = np.max(summaryData)
min_x = np.min(summaryData)
denominator = (max_x - min_x)
if denominator != 0 : summaryData = (summaryData -min_x )/ denominator # watch out fo division by 0
return ( summaryData )
#import numpy as np
#location ="C:/!0datasets/adni/wgs/h2/stage1score05_filtered_001_ordered_pruned.txt"
#priors = summaryData
def loadSummaryStats_noscale(location) :
fileName = location
summaryData = list()
with open(fileName, "r") as id:
for i in id:
itmp = i.rstrip().split()
summaryData.append( np.float64(itmp[2]) ) # the Betas are stored in the 3rd column
return ( summaryData )
##################################################################################################
# LDAK helper
##################################################################################################
def loadLDAKWeights(location) :
fileName = location
weights = list()
counter = 0
with open(fileName, "r") as id:
for i in id:
if counter > 0 : # weight file has header
itmp = i.rstrip().split()
weights.append( np.float64(itmp[1]) )
counter = counter +1
return ( weights )
def loadKinshipLocations(location) :
fileName = location
kinshipLocations = list()
with open(fileName, "r") as id:
for i in id:
itmp = i.rstrip().split()
kinshipLocations.append(itmp[0] )
return ( kinshipLocations )
# loads the file that stores how many regions we have, and then loads each file in turn and adds their rsids into
def loadLDAKRegions(location) :
fileName = location + "region_number"
numRegions = -1
with open(fileName, "r") as NFile:
#itmp = NFile.rstrip().split()
numRegions = np.int(NFile.readline())
numRegions = numRegions +1 # as we have the background region, which is 'region0'
allRegions = list() # a list of lists
for j in range(numRegions) :
fileName = location + "region" + str(j)
nextRegion = list()
allRegions.append(nextRegion)
with open(fileName, "r") as region:
for i in region:
nextRegion.append(i.rstrip().split()[0]) # each line in the file is the rsid
return ( allRegions )
def loadLDAKRegionsDeltas(location) :# takes an reml file
MAXDELTA = np.exp(10)
allDeltas = list()
with open(location, "r") as remlResults:
for i in remlResults:
if i.find("Her_") > -1 : #
itmp = i.rstrip().split()
h2 = np.float64( itmp[1]) # the 2nd item is the h2
if h2 == 0 : delta = MAXDELTA
else : delta = (1-h2) /h2
allDeltas.append(delta)
# h2 = Va/Vphe ~ = Va/1 = Va
# Vphe = Va + Ve -> Ve = Vphe - Va = Ve = 1 -h2
# delta = Ve/Va == (1-Va) / Va == (1-h2) / h2
return(allDeltas)
# lines that contain the h2 results all contain "Her_"
# Her_K1 0.000000 0.000000
# Her_R1 0.000135 0.000773
##################################################################################################
# write/load eigen Summaries of kinships
##################################################################################################
def writeEigenSum(location, eigSums) :
for i in range( len(eigSums) ):
writeMatrixToDisk(location + "eigVec" + str(i+1) , eigSums[i].vectors)
writeVectorToDisk(location + "eigVal" + str(i+1), eigSums[i].values)
def loadEigenSum(location) :
eigSums = list()
moreFiles = True
counter = 1
while moreFiles : # keep going until we run out of files to load
currentLocation = location + "eigVec" + str(counter) + ".id" # files are expected to be named as eigVec1.id/bin etc
my_file = Path(currentLocation)
if my_file.is_file(): # check if it exists
filename = location + "eigVec" + str(counter)
vectors = loadMatrixFromDisk(filename)
filename = location + "eigVal" + str(counter)
values = loadVectorFromDisk(filename)
eigenSummary = collections.namedtuple('values', 'vectors')
eigenSummary.values = values
eigenSummary.vectors =vectors
eigSums.append( eigenSummary )
else : moreFiles = False
counter = counter +1
return(eigSums)
##################################################################################################
##################################################################################################
# location="dummyregions" # local test
#deltas = [1,2]
#regions = list()
#regions.append( np.array([0,50]))
#regions.append( np.array([25,75]))
#writeRegionData(location,regions, deltas)
# results = loadRegionData(location)
# local testing
#gcta_data2 = loadGCTA_GRM(location)
#location = "data/gcta/output/wtccc2_hg19_toy"
# writeGCTA_GRM(location, gcta_data["K"], gcta_data["ids"], gcta_data["N"])
# local test
#location = "data/testMatrix"
#data = np.random.normal(size=[ 100,100], scale=1)
#location = "data/testVec"
#dataVec = np.random.normal( size=50, scale=1)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
13965,
844,
199,
199,
3,
7384,
334,
67,
9,
9708,
603,
580,
265,
25645,
274,
1410,
199,
199,
3,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
221,
199,
3,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
3,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
26734,
14,
199,
199,
646,
2680,
465,
980,
199,
646,
2702,
199,
3,
646,
1134,
80,
1073,
199,
3,
687,
1134,
80,
1073,
492,
627,
199,
199,
3,
504,
2508,
647,
80,
1073,
492,
1611,
48,
1073,
199,
3,
504,
2508,
2308,
14,
647,
80,
1073,
492,
1611,
48,
1073,
199,
199,
3,
504,
2508,
2308,
14,
647,
80,
1073,
492,
627,
199,
199,
504,
2508,
2308,
492,
1134,
80,
1073,
199,
199,
504,
32212,
492,
6912,
199,
646,
5055,
199,
646,
9486,
199,
199,
3060,
1371,
309,
199,
3,
510,
7916,
14161,
1182,
11308,
287,
7818,
7190,
199,
3060,
1371,
309,
199,
3,
1985,
29,
298,
35,
11254,
12117,
15,
274,
79,
15,
13266,
577,
6053,
15,
9791,
36,
15,
16,
14728,
1298,
15,
1,
16,
7921,
15,
2219,
15,
75,
846,
15,
647,
15,
576,
15,
19126,
15,
9115,
19504,
18,
63,
9208,
1167,
63,
19126,
2,
199,
3,
2604,
275,
2248,
2749,
12394,
8,
1985,
12,
295,
600,
1538,
3717,
275,
756,
9,
199,
3,
1985,
275,
1249,
14,
66,
493,
199,
3,
391,
2978,
275,
21450,
14,
15791,
508,
413,
199,
199,
3,
509,
3805,
27760,
315,
30739,
14,
1661,
63,
2268,
79,
63,
4211,
8,
66,
1017,
14,
1712,
304,
199,
3,
259,
610,
274,
63,
2268,
27760,
275,
3805,
27760,
59,
391,
2978,
14,
1459,
61,
199,
199,
3,
17667,
63,
2268,
27760,
275,
3805,
27760,
59,
391,
2978,
14,
1459,
61,
199,
3,
1985,
275,
1249,
14,
548,
199,
199,
318,
664,
63,
68,
63,
600,
8,
576,
804,
9,
520,
258,
327,
1929,
370,
221,
3957,
666,
804,
1901,
2849,
8082,
9479,
272,
340,
8,
666,
804,
508,
283,
1609,
708,
358,
520,
366,
63,
600,
275,
283,
70,
7,
272,
916,
334,
666,
804,
508,
283,
1609,
975,
358,
520,
366,
63,
600,
275,
283,
69,
7,
5591,
587,
520,
366,
63,
600,
275,
283,
68,
7,
221,
2286,
372,
8,
68,
63,
600,
9,
199,
199,
318,
2218,
2749,
12394,
63,
5663,
287,
79,
8,
1985,
12,
612,
12,
7654,
1296,
275,
488,
9,
520,
272,
612,
275,
612,
14,
11186,
342,
2286,
543,
1551,
8,
1985,
435,
3680,
17579,
79,
401,
298,
87,
531,
465,
570,
26,
4960,
367,
284,
315,
1425,
8,
16,
12,
822,
8,
89,
9,
3461,
288,
340,
7654,
1296,
365,
488,
520,
570,
14,
952,
480,
3192,
7709,
620,
8,
442,
8,
73,
11,
17,
430,
435,
1867,
84,
3192,
2,
435,
620,
8,
442,
8,
73,
11,
17,
430,
435,
1867,
84,
2,
435,
495,
8,
89,
59,
73,
566,
435,
1867,
78,
531,
288,
587,
520,
570,
14,
952,
8,
495,
8,
688,
1296,
59,
73,
566,
435,
1867,
84,
2,
435,
495,
8,
688,
1296,
59,
73,
566,
435,
1867,
84,
2,
435,
495,
8,
89,
59,
73,
566,
435,
1867,
78,
531,
6905,
199,
318,
2218,
2749,
12394,
8,
1985,
12,
603,
9,
520,
272,
327,
2248,
299,
1073,
570,
272,
30739,
275,
1134,
80,
1073,
14,
2713,
48,
1073,
8,
1985,
12,
818,
534,
87,
297,
30739,
63,
908,
534,
8199,
48,
13,
8452,
358,
272,
367,
284,
315,
1425,
8,
45,
14,
1392,
59,
17,
4682,
267,
327,
1361,
480,
14827,
428,
14970,
401,
284,
12,
298,
475,
570,
531,
267,
30739,
14,
952,
63,
2268,
27760,
8,
45,
3981,
73,
566,
2286,
543,
1551,
8,
1985,
435,
3680,
18493,
401,
298,
87,
531,
465,
570,
26,
4960,
367,
284,
315,
1425,
8,
603,
14,
1392,
59,
16,
61,
3461,
288,
570,
14,
952,
480,
3192,
7709,
620,
8,
442,
8,
73,
11,
17,
430,
435,
1867,
84,
3192,
2,
435,
620,
8,
442,
8,
73,
11,
17,
430,
435,
1867,
84,
16,
60,
84,
16,
60,
84,
16,
60,
84,
16,
2,
435,
1867,
78,
531,
221,
25979,
543,
1551,
8,
1985,
435,
3680,
66,
1017,
401,
298,
87,
531,
465,
570,
26,
4960,
367,
284,
315,
1425,
8,
603,
14,
1392,
59,
17,
61,
3461,
288,
570,
14,
952,
8,
298,
17,
60,
84,
8199,
48,
2,
435,
620,
8,
442,
8,
73,
430,
435,
1867,
84,
16,
60,
84,
2,
435,
620,
8,
1109,
8,
334,
73,
11,
17,
9,
627,
5198,
430,
435,
1867,
84,
33,
60,
84,
34,
2,
221,
435,
1867,
78,
531,
9948,
199,
3,
1985,
275,
1249,
14,
75,
846,
12,
2248,
5663,
287,
736,
275,
756,
199,
3,
17667,
63,
2268,
27760,
275,
3805,
27760,
59,
391,
2978,
14,
1459,
61,
199,
318,
2248,
2749,
12394,
8,
1985,
12,
2248,
5663,
287,
736,
275,
715,
12,
1930,
3717,
275,
715,
12,
295,
600,
1538,
3717,
275
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
13965,
844,
199,
199,
3,
7384,
334,
67,
9,
9708,
603,
580,
265,
25645,
274,
1410,
199,
199,
3,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
221,
199,
3,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
3,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
26734,
14,
199,
199,
646,
2680,
465,
980,
199,
646,
2702,
199,
3,
646,
1134,
80,
1073,
199,
3,
687,
1134,
80,
1073,
492,
627,
199,
199,
3,
504,
2508,
647,
80,
1073,
492,
1611,
48,
1073,
199,
3,
504,
2508,
2308,
14,
647,
80,
1073,
492,
1611,
48,
1073,
199,
199,
3,
504,
2508,
2308,
14,
647,
80,
1073,
492,
627,
199,
199,
504,
2508,
2308,
492,
1134,
80,
1073,
199,
199,
504,
32212,
492,
6912,
199,
646,
5055,
199,
646,
9486,
199,
199,
3060,
1371,
309,
199,
3,
510,
7916,
14161,
1182,
11308,
287,
7818,
7190,
199,
3060,
1371,
309,
199,
3,
1985,
29,
298,
35,
11254,
12117,
15,
274,
79,
15,
13266,
577,
6053,
15,
9791,
36,
15,
16,
14728,
1298,
15,
1,
16,
7921,
15,
2219,
15,
75,
846,
15,
647,
15,
576,
15,
19126,
15,
9115,
19504,
18,
63,
9208,
1167,
63,
19126,
2,
199,
3,
2604,
275,
2248,
2749,
12394,
8,
1985,
12,
295,
600,
1538,
3717,
275,
756,
9,
199,
3,
1985,
275,
1249,
14,
66,
493,
199,
3,
391,
2978,
275,
21450,
14,
15791,
508,
413,
199,
199,
3,
509,
3805,
27760,
315,
30739,
14,
1661,
63,
2268,
79,
63,
4211,
8,
66,
1017,
14,
1712,
304,
199,
3,
259,
610,
274,
63,
2268,
27760,
275,
3805,
27760,
59,
391,
2978,
14,
1459,
61,
199,
199,
3,
17667,
63,
2268,
27760,
275,
3805,
27760,
59,
391,
2978,
14,
1459,
61,
199,
3,
1985,
275,
1249,
14,
548,
199,
199,
318,
664,
63,
68,
63,
600,
8,
576,
804,
9,
520,
258,
327,
1929,
370,
221,
3957,
666,
804,
1901,
2849,
8082,
9479,
272,
340,
8,
666,
804,
508,
283,
1609,
708,
358,
520,
366,
63,
600,
275,
283,
70,
7,
272,
916,
334,
666,
804,
508,
283,
1609,
975,
358,
520,
366,
63,
600,
275,
283,
69,
7,
5591,
587,
520,
366,
63,
600,
275,
283,
68,
7,
221,
2286,
372,
8,
68,
63,
600,
9,
199,
199,
318,
2218,
2749,
12394,
63,
5663,
287,
79,
8,
1985,
12,
612,
12,
7654,
1296,
275,
488,
9,
520,
272,
612,
275,
612,
14,
11186,
342,
2286,
543,
1551,
8,
1985,
435,
3680,
17579,
79,
401,
298,
87,
531,
465,
570,
26,
4960,
367,
284,
315,
1425,
8,
16,
12,
822,
8,
89,
9,
3461,
288,
340,
7654,
1296,
365,
488,
520,
570,
14,
952,
480,
3192,
7709,
620,
8,
442,
8,
73,
11,
17,
430,
435,
1867,
84,
3192,
2,
435,
620,
8,
442,
8,
73,
11,
17,
430,
435,
1867,
84,
2,
435,
495,
8,
89,
59,
73,
566,
435,
1867,
78,
531,
288,
587,
520,
570,
14,
952,
8,
495,
8,
688,
1296,
59,
73,
566,
435,
1867,
84,
2,
435,
495,
8,
688,
1296,
59,
73,
566,
435,
1867,
84,
2,
435,
495,
8,
89,
59,
73,
566,
435,
1867,
78,
531,
6905,
199,
318,
2218,
2749,
12394,
8,
1985,
12,
603,
9,
520,
272,
327,
2248,
299,
1073,
570,
272,
30739,
275,
1134,
80,
1073,
14,
2713,
48,
1073,
8,
1985,
12,
818,
534,
87,
297,
30739,
63,
908,
534,
8199,
48,
13,
8452,
358,
272,
367,
284,
315,
1425,
8,
45,
14,
1392,
59,
17,
4682,
267,
327,
1361,
480,
14827,
428,
14970,
401,
284,
12,
298,
475,
570,
531,
267,
30739,
14,
952,
63,
2268,
27760,
8,
45,
3981,
73,
566,
2286,
543,
1551,
8,
1985,
435,
3680,
18493,
401,
298,
87,
531,
465,
570,
26,
4960,
367,
284,
315,
1425,
8,
603,
14,
1392,
59,
16,
61,
3461,
288,
570,
14,
952,
480,
3192,
7709,
620,
8,
442,
8,
73,
11,
17,
430,
435,
1867,
84,
3192,
2,
435,
620,
8,
442,
8,
73,
11,
17,
430,
435,
1867,
84,
16,
60,
84,
16,
60,
84,
16,
60,
84,
16,
2,
435,
1867,
78,
531,
221,
25979,
543,
1551,
8,
1985,
435,
3680,
66,
1017,
401,
298,
87,
531,
465,
570,
26,
4960,
367,
284,
315,
1425,
8,
603,
14,
1392,
59,
17,
61,
3461,
288,
570,
14,
952,
8,
298,
17,
60,
84,
8199,
48,
2,
435,
620,
8,
442,
8,
73,
430,
435,
1867,
84,
16,
60,
84,
2,
435,
620,
8,
1109,
8,
334,
73,
11,
17,
9,
627,
5198,
430,
435,
1867,
84,
33,
60,
84,
34,
2,
221,
435,
1867,
78,
531,
9948,
199,
3,
1985,
275,
1249,
14,
75,
846,
12,
2248,
5663,
287,
736,
275,
756,
199,
3,
17667,
63,
2268,
27760,
275,
3805,
27760,
59,
391,
2978,
14,
1459,
61,
199,
318,
2248,
2749,
12394,
8,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
aabbox/kbengine
|
kbe/src/lib/python/Lib/test/test_strtod.py
|
84
|
20594
|
# Tests for the correctly-rounded string -> float conversions
# introduced in Python 2.7 and 3.1.
import random
import unittest
import re
import sys
import test.support
if getattr(sys, 'float_repr_style', '') != 'short':
raise unittest.SkipTest('correctly-rounded string->float conversions '
'not available on this system')
# Correctly rounded str -> float in pure Python, for comparison.
strtod_parser = re.compile(r""" # A numeric string consists of:
(?P<sign>[-+])? # an optional sign, followed by
(?=\d|\.\d) # a number with at least one digit
(?P<int>\d*) # having a (possibly empty) integer part
(?:\.(?P<frac>\d*))? # followed by an optional fractional part
(?:E(?P<exp>[-+]?\d+))? # and an optional exponent
\Z
""", re.VERBOSE | re.IGNORECASE).match
# Pure Python version of correctly rounded string->float conversion.
# Avoids any use of floating-point by returning the result as a hex string.
def strtod(s, mant_dig=53, min_exp = -1021, max_exp = 1024):
"""Convert a finite decimal string to a hex string representing an
IEEE 754 binary64 float. Return 'inf' or '-inf' on overflow.
This function makes no use of floating-point arithmetic at any
stage."""
# parse string into a pair of integers 'a' and 'b' such that
# abs(decimal value) = a/b, along with a boolean 'negative'.
m = strtod_parser(s)
if m is None:
raise ValueError('invalid numeric string')
fraction = m.group('frac') or ''
intpart = int(m.group('int') + fraction)
exp = int(m.group('exp') or '0') - len(fraction)
negative = m.group('sign') == '-'
a, b = intpart*10**max(exp, 0), 10**max(0, -exp)
# quick return for zeros
if not a:
return '-0x0.0p+0' if negative else '0x0.0p+0'
# compute exponent e for result; may be one too small in the case
# that the rounded value of a/b lies in a different binade from a/b
d = a.bit_length() - b.bit_length()
d += (a >> d if d >= 0 else a << -d) >= b
e = max(d, min_exp) - mant_dig
# approximate a/b by number of the form q * 2**e; adjust e if necessary
a, b = a << max(-e, 0), b << max(e, 0)
q, r = divmod(a, b)
if 2*r > b or 2*r == b and q & 1:
q += 1
if q.bit_length() == mant_dig+1:
q //= 2
e += 1
# double check that (q, e) has the right form
assert q.bit_length() <= mant_dig and e >= min_exp - mant_dig
assert q.bit_length() == mant_dig or e == min_exp - mant_dig
# check for overflow and underflow
if e + q.bit_length() > max_exp:
return '-inf' if negative else 'inf'
if not q:
return '-0x0.0p+0' if negative else '0x0.0p+0'
# for hex representation, shift so # bits after point is a multiple of 4
hexdigs = 1 + (mant_dig-2)//4
shift = 3 - (mant_dig-2)%4
q, e = q << shift, e - shift
return '{}0x{:x}.{:0{}x}p{:+d}'.format(
'-' if negative else '',
q // 16**hexdigs,
q % 16**hexdigs,
hexdigs,
e + 4*hexdigs)
TEST_SIZE = 10
class StrtodTests(unittest.TestCase):
def check_strtod(self, s):
"""Compare the result of Python's builtin correctly rounded
string->float conversion (using float) to a pure Python
correctly rounded string->float implementation. Fail if the
two methods give different results."""
try:
fs = float(s)
except OverflowError:
got = '-inf' if s[0] == '-' else 'inf'
except MemoryError:
got = 'memory error'
else:
got = fs.hex()
expected = strtod(s)
self.assertEqual(expected, got,
"Incorrectly rounded str->float conversion for {}: "
"expected {}, got {}".format(s, expected, got))
def test_short_halfway_cases(self):
# exact halfway cases with a small number of significant digits
for k in 0, 5, 10, 15, 20:
# upper = smallest integer >= 2**54/5**k
upper = -(-2**54//5**k)
# lower = smallest odd number >= 2**53/5**k
lower = -(-2**53//5**k)
if lower % 2 == 0:
lower += 1
for i in range(TEST_SIZE):
# Select a random odd n in [2**53/5**k,
# 2**54/5**k). Then n * 10**k gives a halfway case
# with small number of significant digits.
n, e = random.randrange(lower, upper, 2), k
# Remove any additional powers of 5.
while n % 5 == 0:
n, e = n // 5, e + 1
assert n % 10 in (1, 3, 7, 9)
# Try numbers of the form n * 2**p2 * 10**e, p2 >= 0,
# until n * 2**p2 has more than 20 significant digits.
digits, exponent = n, e
while digits < 10**20:
s = '{}e{}'.format(digits, exponent)
self.check_strtod(s)
# Same again, but with extra trailing zeros.
s = '{}e{}'.format(digits * 10**40, exponent - 40)
self.check_strtod(s)
digits *= 2
# Try numbers of the form n * 5**p2 * 10**(e - p5), p5
# >= 0, with n * 5**p5 < 10**20.
digits, exponent = n, e
while digits < 10**20:
s = '{}e{}'.format(digits, exponent)
self.check_strtod(s)
# Same again, but with extra trailing zeros.
s = '{}e{}'.format(digits * 10**40, exponent - 40)
self.check_strtod(s)
digits *= 5
exponent -= 1
def test_halfway_cases(self):
# test halfway cases for the round-half-to-even rule
for i in range(100 * TEST_SIZE):
# bit pattern for a random finite positive (or +0.0) float
bits = random.randrange(2047*2**52)
# convert bit pattern to a number of the form m * 2**e
e, m = divmod(bits, 2**52)
if e:
m, e = m + 2**52, e - 1
e -= 1074
# add 0.5 ulps
m, e = 2*m + 1, e - 1
# convert to a decimal string
if e >= 0:
digits = m << e
exponent = 0
else:
# m * 2**e = (m * 5**-e) * 10**e
digits = m * 5**-e
exponent = e
s = '{}e{}'.format(digits, exponent)
self.check_strtod(s)
def test_boundaries(self):
# boundaries expressed as triples (n, e, u), where
# n*10**e is an approximation to the boundary value and
# u*10**e is 1ulp
boundaries = [
(10000000000000000000, -19, 1110), # a power of 2 boundary (1.0)
(17976931348623159077, 289, 1995), # overflow boundary (2.**1024)
(22250738585072013831, -327, 4941), # normal/subnormal (2.**-1022)
(0, -327, 4941), # zero
]
for n, e, u in boundaries:
for j in range(1000):
digits = n + random.randrange(-3*u, 3*u)
exponent = e
s = '{}e{}'.format(digits, exponent)
self.check_strtod(s)
n *= 10
u *= 10
e -= 1
def test_underflow_boundary(self):
# test values close to 2**-1075, the underflow boundary; similar
# to boundary_tests, except that the random error doesn't scale
# with n
for exponent in range(-400, -320):
base = 10**-exponent // 2**1075
for j in range(TEST_SIZE):
digits = base + random.randrange(-1000, 1000)
s = '{}e{}'.format(digits, exponent)
self.check_strtod(s)
def test_bigcomp(self):
for ndigs in 5, 10, 14, 15, 16, 17, 18, 19, 20, 40, 41, 50:
dig10 = 10**ndigs
for i in range(10 * TEST_SIZE):
digits = random.randrange(dig10)
exponent = random.randrange(-400, 400)
s = '{}e{}'.format(digits, exponent)
self.check_strtod(s)
def test_parsing(self):
# make '0' more likely to be chosen than other digits
digits = '000000123456789'
signs = ('+', '-', '')
# put together random short valid strings
# \d*[.\d*]?e
for i in range(1000):
for j in range(TEST_SIZE):
s = random.choice(signs)
intpart_len = random.randrange(5)
s += ''.join(random.choice(digits) for _ in range(intpart_len))
if random.choice([True, False]):
s += '.'
fracpart_len = random.randrange(5)
s += ''.join(random.choice(digits)
for _ in range(fracpart_len))
else:
fracpart_len = 0
if random.choice([True, False]):
s += random.choice(['e', 'E'])
s += random.choice(signs)
exponent_len = random.randrange(1, 4)
s += ''.join(random.choice(digits)
for _ in range(exponent_len))
if intpart_len + fracpart_len:
self.check_strtod(s)
else:
try:
float(s)
except ValueError:
pass
else:
assert False, "expected ValueError"
@test.support.bigmemtest(size=test.support._2G+10, memuse=3, dry_run=False)
def test_oversized_digit_strings(self, maxsize):
# Input string whose length doesn't fit in an INT.
s = "1." + "1" * maxsize
with self.assertRaises(ValueError):
float(s)
del s
s = "0." + "0" * maxsize + "1"
with self.assertRaises(ValueError):
float(s)
del s
def test_large_exponents(self):
# Verify that the clipping of the exponent in strtod doesn't affect the
# output values.
def positive_exp(n):
""" Long string with value 1.0 and exponent n"""
return '0.{}1e+{}'.format('0'*(n-1), n)
def negative_exp(n):
""" Long string with value 1.0 and exponent -n"""
return '1{}e-{}'.format('0'*n, n)
self.assertEqual(float(positive_exp(10000)), 1.0)
self.assertEqual(float(positive_exp(20000)), 1.0)
self.assertEqual(float(positive_exp(30000)), 1.0)
self.assertEqual(float(negative_exp(10000)), 1.0)
self.assertEqual(float(negative_exp(20000)), 1.0)
self.assertEqual(float(negative_exp(30000)), 1.0)
def test_particular(self):
# inputs that produced crashes or incorrectly rounded results with
# previous versions of dtoa.c, for various reasons
test_strings = [
# issue 7632 bug 1, originally reported failing case
'2183167012312112312312.23538020374420446192e-370',
# 5 instances of issue 7632 bug 2
'12579816049008305546974391768996369464963024663104e-357',
'17489628565202117263145367596028389348922981857013e-357',
'18487398785991994634182916638542680759613590482273e-357',
'32002864200581033134358724675198044527469366773928e-358',
'94393431193180696942841837085033647913224148539854e-358',
'73608278998966969345824653500136787876436005957953e-358',
'64774478836417299491718435234611299336288082136054e-358',
'13704940134126574534878641876947980878824688451169e-357',
'46697445774047060960624497964425416610480524760471e-358',
# failing case for bug introduced by METD in r77451 (attempted
# fix for issue 7632, bug 2), and fixed in r77482.
'28639097178261763178489759107321392745108491825303e-311',
# two numbers demonstrating a flaw in the bigcomp 'dig == 0'
# correction block (issue 7632, bug 3)
'1.00000000000000001e44',
'1.0000000000000000100000000000000000000001e44',
# dtoa.c bug for numbers just smaller than a power of 2 (issue
# 7632, bug 4)
'99999999999999994487665465554760717039532578546e-47',
# failing case for off-by-one error introduced by METD in
# r77483 (dtoa.c cleanup), fixed in r77490
'965437176333654931799035513671997118345570045914469' #...
'6213413350821416312194420007991306908470147322020121018368e0',
# incorrect lsb detection for round-half-to-even when
# bc->scale != 0 (issue 7632, bug 6).
'104308485241983990666713401708072175773165034278685' #...
'682646111762292409330928739751702404658197872319129' #...
'036519947435319418387839758990478549477777586673075' #...
'945844895981012024387992135617064532141489278815239' #...
'849108105951619997829153633535314849999674266169258' #...
'928940692239684771590065027025835804863585454872499' #...
'320500023126142553932654370362024104462255244034053' #...
'203998964360882487378334860197725139151265590832887' #...
'433736189468858614521708567646743455601905935595381' #...
'852723723645799866672558576993978025033590728687206' #...
'296379801363024094048327273913079612469982585674824' #...
'156000783167963081616214710691759864332339239688734' #...
'656548790656486646106983450809073750535624894296242' #...
'072010195710276073042036425579852459556183541199012' #...
'652571123898996574563824424330960027873516082763671875e-1075',
# demonstration that original fix for issue 7632 bug 1 was
# buggy; the exit condition was too strong
'247032822920623295e-341',
# demonstrate similar problem to issue 7632 bug1: crash
# with 'oversized quotient in quorem' message.
'99037485700245683102805043437346965248029601286431e-373',
'99617639833743863161109961162881027406769510558457e-373',
'98852915025769345295749278351563179840130565591462e-372',
'99059944827693569659153042769690930905148015876788e-373',
'98914979205069368270421829889078356254059760327101e-372',
# issue 7632 bug 5: the following 2 strings convert differently
'1000000000000000000000000000000000000000e-16',
'10000000000000000000000000000000000000000e-17',
# issue 7632 bug 7
'991633793189150720000000000000000000000000000000000000000e-33',
# And another, similar, failing halfway case
'4106250198039490000000000000000000000000000000000000000e-38',
# issue 7632 bug 8: the following produced 10.0
'10.900000000000000012345678912345678912345',
# two humongous values from issue 7743
'116512874940594195638617907092569881519034793229385' #...
'228569165191541890846564669771714896916084883987920' #...
'473321268100296857636200926065340769682863349205363' #...
'349247637660671783209907949273683040397979984107806' #...
'461822693332712828397617946036239581632976585100633' #...
'520260770761060725403904123144384571612073732754774' #...
'588211944406465572591022081973828448927338602556287' #...
'851831745419397433012491884869454462440536895047499' #...
'436551974649731917170099387762871020403582994193439' #...
'761933412166821484015883631622539314203799034497982' #...
'130038741741727907429575673302461380386596501187482' #...
'006257527709842179336488381672818798450229339123527' #...
'858844448336815912020452294624916993546388956561522' #...
'161875352572590420823607478788399460162228308693742' #...
'05287663441403533948204085390898399055004119873046875e-1075',
'525440653352955266109661060358202819561258984964913' #...
'892256527849758956045218257059713765874251436193619' #...
'443248205998870001633865657517447355992225852945912' #...
'016668660000210283807209850662224417504752264995360' #...
'631512007753855801075373057632157738752800840302596' #...
'237050247910530538250008682272783660778181628040733' #...
'653121492436408812668023478001208529190359254322340' #...
'397575185248844788515410722958784640926528544043090' #...
'115352513640884988017342469275006999104519620946430' #...
'818767147966495485406577703972687838176778993472989' #...
'561959000047036638938396333146685137903018376496408' #...
'319705333868476925297317136513970189073693314710318' #...
'991252811050501448326875232850600451776091303043715' #...
'157191292827614046876950225714743118291034780466325' #...
'085141343734564915193426994587206432697337118211527' #...
'278968731294639353354774788602467795167875117481660' #...
'4738791256853675690543663283782215866825e-1180',
# exercise exit conditions in bigcomp comparison loop
'2602129298404963083833853479113577253105939995688e2',
'260212929840496308383385347911357725310593999568896e0',
'26021292984049630838338534791135772531059399956889601e-2',
'260212929840496308383385347911357725310593999568895e0',
'260212929840496308383385347911357725310593999568897e0',
'260212929840496308383385347911357725310593999568996e0',
'260212929840496308383385347911357725310593999568866e0',
# 2**53
'9007199254740992.00',
# 2**1024 - 2**970: exact overflow boundary. All values
# smaller than this should round to something finite; any value
# greater than or equal to this one overflows.
'179769313486231580793728971405303415079934132710037' #...
'826936173778980444968292764750946649017977587207096' #...
'330286416692887910946555547851940402630657488671505' #...
'820681908902000708383676273854845817711531764475730' #...
'270069855571366959622842914819860834936475292719074' #...
'168444365510704342711559699508093042880177904174497792',
# 2**1024 - 2**970 - tiny
'179769313486231580793728971405303415079934132710037' #...
'826936173778980444968292764750946649017977587207096' #...
'330286416692887910946555547851940402630657488671505' #...
'820681908902000708383676273854845817711531764475730' #...
'270069855571366959622842914819860834936475292719074' #...
'168444365510704342711559699508093042880177904174497791.999',
# 2**1024 - 2**970 + tiny
'179769313486231580793728971405303415079934132710037' #...
'826936173778980444968292764750946649017977587207096' #...
'330286416692887910946555547851940402630657488671505' #...
'820681908902000708383676273854845817711531764475730' #...
'270069855571366959622842914819860834936475292719074' #...
'168444365510704342711559699508093042880177904174497792.001',
# 1 - 2**-54, +-tiny
'999999999999999944488848768742172978818416595458984375e-54',
'9999999999999999444888487687421729788184165954589843749999999e-54',
'9999999999999999444888487687421729788184165954589843750000001e-54',
# Value found by Rick Regan that gives a result of 2**-968
# under Gay's dtoa.c (as of Nov 04, 2010); since fixed.
# (Fixed some time ago in Python's dtoa.c.)
'0.0000000000000000000000000000000000000000100000000' #...
'000000000576129113423785429971690421191214034235435' #...
'087147763178149762956868991692289869941246658073194' #...
'51982237978882039897143840789794921875',
]
for s in test_strings:
self.check_strtod(s)
def test_main():
test.support.run_unittest(StrtodTests)
if __name__ == "__main__":
test_main()
|
lgpl-3.0
|
[
3,
6496,
367,
314,
6657,
13,
25677,
1059,
1035,
2069,
24796,
199,
3,
21399,
315,
2018,
499,
14,
23,
436,
650,
14,
17,
14,
199,
199,
646,
2196,
199,
646,
2882,
199,
646,
295,
199,
646,
984,
199,
646,
511,
14,
4058,
199,
199,
692,
2519,
8,
1274,
12,
283,
1609,
63,
2722,
63,
2487,
297,
4074,
1137,
283,
3612,
356,
272,
746,
2882,
14,
25755,
360,
4525,
590,
13,
25677,
1059,
5118,
1609,
24796,
283,
1169,
283,
1397,
2808,
641,
642,
2656,
358,
199,
199,
3,
31057,
590,
24671,
620,
1035,
2069,
315,
15111,
2018,
12,
367,
9132,
14,
199,
199,
495,
5766,
63,
2087,
275,
295,
14,
2014,
8,
82,
624,
259,
327,
437,
8950,
1059,
18581,
402,
26,
272,
7558,
48,
28,
1037,
30,
27371,
566,
31,
3515,
327,
376,
2716,
2070,
12,
9437,
701,
272,
7558,
9529,
68,
6113,
3134,
68,
9,
4519,
327,
282,
1329,
543,
737,
5210,
1373,
10964,
272,
7558,
48,
28,
442,
3072,
68,
13278,
3777,
327,
9445,
282,
334,
19614,
2701,
9,
3000,
1777,
272,
7558,
3427,
14,
2229,
48,
28,
10865,
3072,
68,
10,
22119,
258,
327,
9437,
701,
376,
2716,
27487,
1777,
272,
16697,
37,
2229,
48,
28,
1474,
30,
27371,
22426,
68,
11,
22119,
221,
327,
436,
376,
2716,
16588,
272,
971,
58,
199,
7208,
295,
14,
16075,
1204,
295,
14,
15434,
680,
1431,
199,
199,
3,
510,
608,
2018,
1015,
402,
6657,
24671,
1059,
5118,
1609,
8603,
14,
199,
3,
19503,
83,
1263,
675,
402,
8402,
13,
1403,
701,
8152,
314,
754,
465,
282,
6318,
1059,
14,
199,
318,
620,
5766,
8,
83,
12,
333,
867,
63,
18367,
29,
2481,
12,
1748,
63,
1474,
275,
446,
709,
2025,
12,
1390,
63,
1474,
275,
6619,
304,
272,
408,
7306,
282,
21837,
6107,
1059,
370,
282,
6318,
1059,
6144,
376,
272,
473,
29146,
1520,
1477,
3366,
772,
2069,
14,
221,
1432,
283,
4904,
7,
503,
2475,
4904,
7,
641,
15784,
14,
272,
961,
805,
7704,
949,
675,
402,
8402,
13,
1403,
24166,
737,
1263,
272,
9546,
1041,
339,
327,
2198,
1059,
1901,
282,
4092,
402,
9446,
283,
65,
7,
436,
283,
66,
7,
4066,
626,
272,
327,
2853,
8,
6355,
574,
9,
275,
282,
15,
66,
12,
3180,
543,
282,
5046,
283,
7371,
1370,
272,
333,
275,
620,
5766,
63,
2087,
8,
83,
9,
272,
340,
333,
365,
488,
26,
267,
746,
1722,
360,
3197,
8950,
1059,
358,
272,
12347,
275,
333,
14,
923,
360,
10865,
358,
503,
2125,
272,
1109,
2064,
275,
1109,
8,
77,
14,
923,
360,
442,
358,
435,
12347,
9,
272,
1437,
275,
1109,
8,
77,
14,
923,
360,
1474,
358,
503,
283,
16,
358,
446,
822,
8,
13054,
9,
272,
6946,
275,
333,
14,
923,
360,
1037,
358,
508,
10791,
272,
282,
12,
330,
275,
1109,
2064,
10,
709,
538,
988,
8,
1474,
12,
378,
395,
1616,
538,
988,
8,
16,
12,
446,
1474,
9,
339,
327,
12530,
372,
367,
10136,
272,
340,
440,
282,
26,
267,
372,
2475,
16,
88,
16,
14,
16,
80,
11,
16,
7,
340,
6946,
587,
283,
16,
88,
16,
14,
16,
80,
11,
16,
7,
339,
327,
4526,
16588,
325,
367,
754,
27,
1443,
506,
1373,
4634,
7425,
315,
314,
1930,
272,
327,
626,
314,
24671,
574,
402,
282,
15,
66,
1212,
397,
315,
282,
3365,
2517,
9587,
687,
282,
15,
66,
272,
366,
275,
282,
14,
2075,
63,
1267,
342,
446,
330,
14,
2075,
63,
1267,
342,
272,
366,
847,
334,
65,
4331,
366,
340,
366,
2356,
378,
587,
282,
5213,
446,
68,
9,
2356,
330,
272,
325,
275,
1390,
8,
68,
12,
1748,
63,
1474,
9,
446,
333,
867,
63,
18367,
339,
327,
19917,
282,
15,
66,
701,
1329,
402,
314,
1824,
1894,
627,
499,
538,
69,
27,
11311,
325,
340,
5784,
272,
282,
12,
330,
275,
282,
5213,
1390,
2801,
69,
12,
378,
395,
330,
5213,
1390,
8,
69,
12,
378,
9,
272,
1894,
12,
519,
275,
16438,
8,
65,
12,
330,
9,
272,
340,
499,
10,
82,
690,
330,
503,
499,
10,
82,
508,
330,
436,
1894,
1253,
413,
26,
267,
1894,
847,
413,
267,
340,
1894,
14,
2075,
63,
1267,
342,
508,
333,
867,
63,
18367,
11,
17,
26,
288,
1894,
5001,
29,
499,
288,
325,
847,
413,
339,
327,
4270,
1104,
626,
334,
81,
12,
325,
9,
965,
314,
2451,
1824,
272,
702,
1894,
14,
2075,
63,
1267,
342,
2695,
333,
867,
63,
18367,
436,
325,
2356,
1748,
63,
1474,
446,
333,
867,
63,
18367,
272,
702,
1894,
14,
2075,
63,
1267,
342,
508,
333,
867,
63,
18367,
503,
325,
508,
1748,
63,
1474,
446,
333,
867,
63,
18367,
339,
327,
1104,
367,
15784,
436,
1334,
1659,
272,
340,
325,
435,
1894,
14,
2075,
63,
1267,
342,
690,
1390,
63,
1474,
26,
267,
372,
2475,
4904,
7,
340,
6946,
587,
283,
4904,
7,
272,
340,
440,
1894,
26,
267,
372,
2475,
16,
88,
16,
14,
16,
80,
11,
16,
7,
340,
6946,
587,
283,
16,
88,
16,
14,
16,
80,
11,
16,
7,
339,
327,
367,
6318,
6025,
12,
7706,
880,
327,
5821,
2410,
2376,
365,
282,
3663,
402,
841,
272,
6318,
328,
458,
275,
413,
435,
334,
77,
867,
63,
18367,
13,
18,
28428,
20,
272,
7706,
275,
650,
446,
334,
77,
867,
63,
18367,
13,
18,
19656,
20,
272,
1894,
12,
325,
275,
1894,
5213,
7706,
12,
325,
446,
7706,
272,
372,
9005,
16,
88,
28476,
88,
26944,
26,
16,
2440,
88,
93,
80,
28476,
11,
68,
5285,
908,
8,
267,
10791,
340,
6946,
587,
3260,
267,
1894,
5001,
3193,
538,
4097,
328,
458,
12,
267,
1894,
450,
3193,
538,
4097,
328,
458,
12,
267,
6318,
328,
458,
12,
267,
325,
435,
841,
10,
4097,
328,
458,
9,
199,
199,
2864,
63,
4305,
275,
1616,
199,
199,
533,
8303,
5766,
2925,
8,
2796,
14,
1746,
304,
272,
347,
1104,
63,
495,
5766,
8,
277,
12,
308,
304,
267,
408,
16051,
314,
754,
402,
2018,
1159,
6762,
6657,
24671,
267,
1059,
5118,
1609,
8603,
334,
4941,
2069,
9,
370,
282,
15111,
2018,
267,
6657,
24671,
1059,
5118,
1609,
4514,
14,
221,
12176,
340,
314,
267,
2877,
3102,
8120,
3365,
2058,
1041,
398,
862,
26,
288
] |
[
6496,
367,
314,
6657,
13,
25677,
1059,
1035,
2069,
24796,
199,
3,
21399,
315,
2018,
499,
14,
23,
436,
650,
14,
17,
14,
199,
199,
646,
2196,
199,
646,
2882,
199,
646,
295,
199,
646,
984,
199,
646,
511,
14,
4058,
199,
199,
692,
2519,
8,
1274,
12,
283,
1609,
63,
2722,
63,
2487,
297,
4074,
1137,
283,
3612,
356,
272,
746,
2882,
14,
25755,
360,
4525,
590,
13,
25677,
1059,
5118,
1609,
24796,
283,
1169,
283,
1397,
2808,
641,
642,
2656,
358,
199,
199,
3,
31057,
590,
24671,
620,
1035,
2069,
315,
15111,
2018,
12,
367,
9132,
14,
199,
199,
495,
5766,
63,
2087,
275,
295,
14,
2014,
8,
82,
624,
259,
327,
437,
8950,
1059,
18581,
402,
26,
272,
7558,
48,
28,
1037,
30,
27371,
566,
31,
3515,
327,
376,
2716,
2070,
12,
9437,
701,
272,
7558,
9529,
68,
6113,
3134,
68,
9,
4519,
327,
282,
1329,
543,
737,
5210,
1373,
10964,
272,
7558,
48,
28,
442,
3072,
68,
13278,
3777,
327,
9445,
282,
334,
19614,
2701,
9,
3000,
1777,
272,
7558,
3427,
14,
2229,
48,
28,
10865,
3072,
68,
10,
22119,
258,
327,
9437,
701,
376,
2716,
27487,
1777,
272,
16697,
37,
2229,
48,
28,
1474,
30,
27371,
22426,
68,
11,
22119,
221,
327,
436,
376,
2716,
16588,
272,
971,
58,
199,
7208,
295,
14,
16075,
1204,
295,
14,
15434,
680,
1431,
199,
199,
3,
510,
608,
2018,
1015,
402,
6657,
24671,
1059,
5118,
1609,
8603,
14,
199,
3,
19503,
83,
1263,
675,
402,
8402,
13,
1403,
701,
8152,
314,
754,
465,
282,
6318,
1059,
14,
199,
318,
620,
5766,
8,
83,
12,
333,
867,
63,
18367,
29,
2481,
12,
1748,
63,
1474,
275,
446,
709,
2025,
12,
1390,
63,
1474,
275,
6619,
304,
272,
408,
7306,
282,
21837,
6107,
1059,
370,
282,
6318,
1059,
6144,
376,
272,
473,
29146,
1520,
1477,
3366,
772,
2069,
14,
221,
1432,
283,
4904,
7,
503,
2475,
4904,
7,
641,
15784,
14,
272,
961,
805,
7704,
949,
675,
402,
8402,
13,
1403,
24166,
737,
1263,
272,
9546,
1041,
339,
327,
2198,
1059,
1901,
282,
4092,
402,
9446,
283,
65,
7,
436,
283,
66,
7,
4066,
626,
272,
327,
2853,
8,
6355,
574,
9,
275,
282,
15,
66,
12,
3180,
543,
282,
5046,
283,
7371,
1370,
272,
333,
275,
620,
5766,
63,
2087,
8,
83,
9,
272,
340,
333,
365,
488,
26,
267,
746,
1722,
360,
3197,
8950,
1059,
358,
272,
12347,
275,
333,
14,
923,
360,
10865,
358,
503,
2125,
272,
1109,
2064,
275,
1109,
8,
77,
14,
923,
360,
442,
358,
435,
12347,
9,
272,
1437,
275,
1109,
8,
77,
14,
923,
360,
1474,
358,
503,
283,
16,
358,
446,
822,
8,
13054,
9,
272,
6946,
275,
333,
14,
923,
360,
1037,
358,
508,
10791,
272,
282,
12,
330,
275,
1109,
2064,
10,
709,
538,
988,
8,
1474,
12,
378,
395,
1616,
538,
988,
8,
16,
12,
446,
1474,
9,
339,
327,
12530,
372,
367,
10136,
272,
340,
440,
282,
26,
267,
372,
2475,
16,
88,
16,
14,
16,
80,
11,
16,
7,
340,
6946,
587,
283,
16,
88,
16,
14,
16,
80,
11,
16,
7,
339,
327,
4526,
16588,
325,
367,
754,
27,
1443,
506,
1373,
4634,
7425,
315,
314,
1930,
272,
327,
626,
314,
24671,
574,
402,
282,
15,
66,
1212,
397,
315,
282,
3365,
2517,
9587,
687,
282,
15,
66,
272,
366,
275,
282,
14,
2075,
63,
1267,
342,
446,
330,
14,
2075,
63,
1267,
342,
272,
366,
847,
334,
65,
4331,
366,
340,
366,
2356,
378,
587,
282,
5213,
446,
68,
9,
2356,
330,
272,
325,
275,
1390,
8,
68,
12,
1748,
63,
1474,
9,
446,
333,
867,
63,
18367,
339,
327,
19917,
282,
15,
66,
701,
1329,
402,
314,
1824,
1894,
627,
499,
538,
69,
27,
11311,
325,
340,
5784,
272,
282,
12,
330,
275,
282,
5213,
1390,
2801,
69,
12,
378,
395,
330,
5213,
1390,
8,
69,
12,
378,
9,
272,
1894,
12,
519,
275,
16438,
8,
65,
12,
330,
9,
272,
340,
499,
10,
82,
690,
330,
503,
499,
10,
82,
508,
330,
436,
1894,
1253,
413,
26,
267,
1894,
847,
413,
267,
340,
1894,
14,
2075,
63,
1267,
342,
508,
333,
867,
63,
18367,
11,
17,
26,
288,
1894,
5001,
29,
499,
288,
325,
847,
413,
339,
327,
4270,
1104,
626,
334,
81,
12,
325,
9,
965,
314,
2451,
1824,
272,
702,
1894,
14,
2075,
63,
1267,
342,
2695,
333,
867,
63,
18367,
436,
325,
2356,
1748,
63,
1474,
446,
333,
867,
63,
18367,
272,
702,
1894,
14,
2075,
63,
1267,
342,
508,
333,
867,
63,
18367,
503,
325,
508,
1748,
63,
1474,
446,
333,
867,
63,
18367,
339,
327,
1104,
367,
15784,
436,
1334,
1659,
272,
340,
325,
435,
1894,
14,
2075,
63,
1267,
342,
690,
1390,
63,
1474,
26,
267,
372,
2475,
4904,
7,
340,
6946,
587,
283,
4904,
7,
272,
340,
440,
1894,
26,
267,
372,
2475,
16,
88,
16,
14,
16,
80,
11,
16,
7,
340,
6946,
587,
283,
16,
88,
16,
14,
16,
80,
11,
16,
7,
339,
327,
367,
6318,
6025,
12,
7706,
880,
327,
5821,
2410,
2376,
365,
282,
3663,
402,
841,
272,
6318,
328,
458,
275,
413,
435,
334,
77,
867,
63,
18367,
13,
18,
28428,
20,
272,
7706,
275,
650,
446,
334,
77,
867,
63,
18367,
13,
18,
19656,
20,
272,
1894,
12,
325,
275,
1894,
5213,
7706,
12,
325,
446,
7706,
272,
372,
9005,
16,
88,
28476,
88,
26944,
26,
16,
2440,
88,
93,
80,
28476,
11,
68,
5285,
908,
8,
267,
10791,
340,
6946,
587,
3260,
267,
1894,
5001,
3193,
538,
4097,
328,
458,
12,
267,
1894,
450,
3193,
538,
4097,
328,
458,
12,
267,
6318,
328,
458,
12,
267,
325,
435,
841,
10,
4097,
328,
458,
9,
199,
199,
2864,
63,
4305,
275,
1616,
199,
199,
533,
8303,
5766,
2925,
8,
2796,
14,
1746,
304,
272,
347,
1104,
63,
495,
5766,
8,
277,
12,
308,
304,
267,
408,
16051,
314,
754,
402,
2018,
1159,
6762,
6657,
24671,
267,
1059,
5118,
1609,
8603,
334,
4941,
2069,
9,
370,
282,
15111,
2018,
267,
6657,
24671,
1059,
5118,
1609,
4514,
14,
221,
12176,
340,
314,
267,
2877,
3102,
8120,
3365,
2058,
1041,
398,
862,
26,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
sanger-pathogens/iva
|
iva/assembly.py
|
1
|
29056
|
# Copyright (c) 2014-2016 Genome Research Ltd.
#
# This file is part of IVA.
#
# IVA is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
import os
import pysam
import tempfile
import shutil
from iva import contig, mapping, seed, mummer, graph, edge, common
import pyfastaq
class Assembly:
def __init__(self, contigs_file=None, map_index_k=15, map_index_s=3, threads=1, kmc_threads=1, max_insert=800, map_minid=0.5, min_clip=3, ext_min_cov=5, ext_min_ratio=2, ext_bases=100, verbose=0, seed_min_cov=5, seed_min_ratio=10, seed_min_kmer_count=200, seed_max_kmer_count=1000000000, seed_start_length=None, seed_stop_length=500, seed_overlap_length=None, make_new_seeds=False, contig_iter_trim=10, seed_ext_max_bases=50, max_contigs=50, clean=True, strand_bias=0):
self.contigs = {}
self.contig_lengths = {}
self.map_index_k = map_index_k
self.map_index_s = map_index_s
self.threads = threads
self.kmc_threads = kmc_threads
self.max_insert = max_insert
self.map_minid = map_minid
self.min_clip = min_clip
self.ext_min_cov = ext_min_cov
self.ext_min_ratio = ext_min_ratio
self.ext_bases = ext_bases
self.verbose = verbose
self.clean = clean
self.make_new_seeds = make_new_seeds
self.seed_start_length = seed_start_length
self.seed_stop_length = seed_stop_length
self.seed_min_kmer_count = seed_min_kmer_count
self.seed_max_kmer_count = seed_max_kmer_count
self.seed_ext_max_bases = seed_ext_max_bases
self.seed_overlap_length = seed_overlap_length
self.seed_min_cov = seed_min_cov
self.seed_min_ratio = seed_min_ratio
self.contig_iter_trim = contig_iter_trim
self.max_contigs = max_contigs
self.strand_bias = strand_bias
self.contigs_trimmed_for_strand_bias = set()
self.used_seeds = set()
if contigs_file is None:
self.make_new_seeds = True
else:
contigs = {}
pyfastaq.tasks.file_to_dict(contigs_file, contigs)
for ctg in contigs:
self._add_contig(contigs[ctg])
def _add_contig(self, ctg, min_length=1):
if len(ctg) < min_length:
return
assert ctg.id not in self.contigs
assert len(ctg) > 0
self.contigs[ctg.id] = contig.Contig(ctg, verbose=self.verbose)
self.contig_lengths[ctg.id] = [[len(self.contigs[ctg.id]), 0, 0]]
def write_contigs_to_file(self, filename, min_length=None, do_not_write=None, only_write=None, biggest_first=False, order_by_orfs=False, prefix=None):
if do_not_write is None:
do_not_write = set()
if only_write is None:
only_write = set()
printed = 0
if min_length is None:
min_length = self.map_index_k + 1
f = pyfastaq.utils.open_file_write(filename)
if biggest_first:
contig_names = self._contig_names_size_order(biggest_first=True)
elif order_by_orfs:
names = self._get_contig_order_by_orfs()
contig_names = [x[0] for x in names]
contig_revcomp = [x[1] for x in names]
else:
contig_names = sorted(list(self.contigs.keys()))
for i in range(len(contig_names)):
name = contig_names[i]
if len(self.contigs[name]) >= min_length and name not in do_not_write and (name in only_write or len(only_write)==0):
if order_by_orfs and contig_revcomp[i]:
self.contigs[name].fa.revcomp()
suffix = ' (reversed)'
else:
suffix = ''
if prefix is None:
print(self.contigs[name].fa, file=f)
else:
printed += 1
new_name = prefix + '.' + str(printed).zfill(5)
self.contigs[name].fa.id = new_name
print(self.contigs[name].fa, file=f)
self.contigs[name].fa.id = name
if self.verbose >= 2:
print('Reported {} as {}{}.'.format(name,
new_name,
suffix))
if order_by_orfs and contig_revcomp[i]:
self.contigs[name].fa.revcomp()
pyfastaq.utils.close(f)
def _get_contig_order_by_orfs(self, min_length=300):
longest_orfs = []
no_orfs = set()
ordered_names = []
for contig in self.contigs.values():
orfs = contig.fa.all_orfs(min_length)
reverse = False
max_length = 0
for coords, rev in orfs:
if len(coords) > max_length:
max_length = len(coords)
reverse = rev
if max_length > 0:
longest_orfs.append((contig.fa.id, max_length, reverse))
else:
no_orfs.add((contig.fa.id, len(contig.fa)))
all_in_size_order = self._contig_names_size_order(biggest_first=True)
ordered_names = sorted(longest_orfs, key=lambda x:x[1], reverse=True)
ordered_names = [(x[0], x[2]) for x in ordered_names]
for t in sorted(no_orfs, key=lambda x:x[1], reverse=True):
ordered_names.append((t[0], False))
return ordered_names
def _map_reads(self, fwd_reads, rev_reads, out_prefix, required_flag=None, exclude_flag=None, sort_reads=False, mate_ref=None, no_map_contigs=None):
if no_map_contigs is None:
no_map_contigs = set()
if self.verbose:
print(' map reads', fwd_reads, rev_reads, sep='\t')
reference = out_prefix + '.ref.fa'
self.write_contigs_to_file(reference, do_not_write=no_map_contigs)
mapping.map_reads(fwd_reads, rev_reads, reference, out_prefix, index_k=self.map_index_k, index_s=self.map_index_s, threads=self.threads, max_insert=self.max_insert, minid=self.map_minid, verbose=self.verbose, required_flag=required_flag, sort=sort_reads, exclude_flag=exclude_flag)
if self.clean:
os.unlink(reference)
os.unlink(reference + '.fai')
def _extend_contigs_with_bam(self, bam_in, out_prefix=None, output_all_useful_reads=False):
if out_prefix is not None:
fa_out1 = pyfastaq.utils.open_file_write(out_prefix + '_1.fa')
fa_out2 = pyfastaq.utils.open_file_write(out_prefix + '_2.fa')
keep_read_types = set([mapping.CAN_EXTEND_LEFT, mapping.CAN_EXTEND_RIGHT, mapping.KEEP])
if output_all_useful_reads:
keep_read_types.add(mapping.BOTH_UNMAPPED)
previous_sam = None
left_seqs = []
right_seqs = []
sam_reader = pysam.Samfile(bam_in, "rb")
for current_sam in sam_reader.fetch(until_eof=True):
if previous_sam is None:
previous_sam = current_sam
continue
previous_type, current_type = mapping.get_pair_type(previous_sam, current_sam, self._get_ref_length_sam_pair(sam_reader, previous_sam, current_sam), self.max_insert, min_clip=self.min_clip)
for sam, sam_type in [(previous_sam, previous_type), (current_sam, current_type)]:
if sam_type == mapping.CAN_EXTEND_LEFT:
name = mapping.get_ref_name(sam, sam_reader)
clipped = mapping.soft_clipped(sam)[0]
self.contigs[name].add_left_kmer(common.decode(sam.seq[:clipped]))
elif sam_type == mapping.CAN_EXTEND_RIGHT:
name = mapping.get_ref_name(sam, sam_reader)
self.contigs[name].add_right_kmer(common.decode(sam.seq[sam.qend:]))
if out_prefix is not None and sam_type in keep_read_types:
if sam.is_read1:
print(mapping.sam_to_fasta(sam), file=fa_out1)
else:
print(mapping.sam_to_fasta(sam), file=fa_out2)
previous_sam = None
if out_prefix is not None:
pyfastaq.utils.close(fa_out1)
pyfastaq.utils.close(fa_out2)
total_bases_added = 0
for ctg in self.contigs:
left_length, right_length = self.contigs[ctg].extend(self.ext_min_cov, self.ext_min_ratio, self.ext_bases)
if self.verbose:
print(' extend contig ' + ctg, 'new_length:' + str(len(self.contigs[ctg])), 'added_left:' + str(left_length), 'added_right:' + str(right_length), sep='\t')
self.contig_lengths[ctg].append([len(self.contigs[ctg]), left_length, right_length])
total_bases_added += left_length + right_length
return total_bases_added
def _trim_contig_for_strand_bias(self, bam, ctg_name):
assert os.path.exists(bam)
if ctg_name in self.contigs_trimmed_for_strand_bias:
return
ctg_length = len(self.contigs[ctg_name])
fwd_cov = mapping.get_bam_region_coverage(bam, ctg_name, ctg_length)
rev_cov = mapping.get_bam_region_coverage(bam, ctg_name, ctg_length, rev=True)
first_good_base = 0
while first_good_base < ctg_length:
total_cov = fwd_cov[first_good_base] + rev_cov[first_good_base]
if total_cov >= self.ext_min_cov and min(fwd_cov[first_good_base], rev_cov[first_good_base]) / total_cov >= self.strand_bias:
break
first_good_base += 1
last_good_base = ctg_length - 1
while last_good_base > first_good_base:
total_cov = fwd_cov[last_good_base] + rev_cov[last_good_base]
if total_cov >= self.ext_min_cov and min(fwd_cov[last_good_base], rev_cov[last_good_base]) / total_cov >= self.strand_bias:
break
last_good_base -= 1
if self.verbose >= 2:
print('Trimming strand biased ends of contig', ctg_name, '- good base range is', first_good_base + 1, 'to', last_good_base + 1, 'from', ctg_length, 'bases')
self.contigs[ctg_name].fa.seq = self.contigs[ctg_name].fa.seq[first_good_base:last_good_base+1]
def _good_intervals_from_strand_coverage(self, fwd_cov, rev_cov):
assert len(fwd_cov) == len(rev_cov)
good_intervals = []
start = None
cov_ok = False
for i in range(len(fwd_cov)):
total_cov = fwd_cov[i] + rev_cov[i]
cov_ok = total_cov >= self.ext_min_cov and min(fwd_cov[i], rev_cov[i]) / total_cov >= self.strand_bias
if cov_ok:
if start is None:
start = i
else:
if start is not None:
good_intervals.append((start, i-1))
start = None
if cov_ok and start is not None:
good_intervals.append((start, i-1))
return good_intervals
def _subcontigs_from_strand_bias(self, bam, ctg_name):
ctg_length = len(self.contigs[ctg_name])
fwd_cov = mapping.get_bam_region_coverage(bam, ctg_name, ctg_length)
rev_cov = mapping.get_bam_region_coverage(bam, ctg_name, ctg_length, rev=True)
good_intervals = self._good_intervals_from_strand_coverage(fwd_cov, rev_cov)
new_contigs = []
if len(good_intervals) == 1:
self.contigs[ctg_name].fa.seq = self.contigs[ctg_name].fa.seq[good_intervals[0][0]:good_intervals[0][1]+1]
elif len(good_intervals) > 1:
for i in range(len(good_intervals)):
start = good_intervals[i][0]
end = good_intervals[i][1]
if end - start + 1 >= 100:
new_contigs.append(pyfastaq.sequences.Fasta(ctg_name + '.' + str(i+1), self.contigs[ctg_name].fa[start:end+1]))
return new_contigs
def _trim_strand_biased_ends(self, reads_prefix, out_prefix=None, tag_as_trimmed=False, break_contigs=False):
tmpdir = tempfile.mkdtemp(prefix='tmp.trim_strand_biased_ends.', dir=os.getcwd())
tmp_prefix = os.path.join(tmpdir, 'out')
sorted_bam = tmp_prefix + '.bam'
unsorted_bam = tmp_prefix + '.unsorted.bam'
original_map_minid = self.map_minid
self.map_minid = 0.9
self._map_reads(reads_prefix + '_1.fa', reads_prefix + '_2.fa', tmp_prefix, sort_reads=True)
assert os.path.exists(sorted_bam)
self.map_minid = original_map_minid
new_contigs = []
contigs_to_remove = set()
for ctg in self.contigs:
if break_contigs:
subcontigs = self._subcontigs_from_strand_bias(sorted_bam, ctg)
if len(subcontigs):
new_contigs.extend(subcontigs)
contigs_to_remove.add(ctg)
elif ctg not in self.contigs_trimmed_for_strand_bias:
self._trim_contig_for_strand_bias(sorted_bam, ctg)
# contig could get completely trimmed so nothing left, in which
# case, we need to remove it
if len(self.contigs[ctg]) == 0:
contigs_to_remove.add(ctg)
elif tag_as_trimmed:
self.contigs_trimmed_for_strand_bias.add(ctg)
for ctg in contigs_to_remove:
self._remove_contig(ctg)
for ctg in new_contigs:
self._add_contig(ctg, min_length=0.75 * self.self.seed_stop_length)
if out_prefix is not None:
mapping.bam_file_to_fasta_pair_files(unsorted_bam, out_prefix + '_1.fa', out_prefix + '_2.fa', remove_proper_pairs=True)
shutil.rmtree(tmpdir)
def trim_contigs(self, trim):
for ctg in self.contigs:
if self._contig_worth_extending(ctg):
self.contigs[ctg].fa.trim(trim, trim)
self.contig_lengths[ctg][-1][0] -= 2 * trim
def _contig_worth_extending(self, name):
if name in self.contigs_trimmed_for_strand_bias:
return False
return len(self.contig_lengths[name]) < 3 \
or self.contig_lengths[name][-1][0] > max([self.contig_lengths[name][x][0] for x in range(len(self.contig_lengths[name])-2)])
def _worth_extending(self):
for ctg in self.contigs:
if self._contig_worth_extending(ctg):
return True
return False
def _extend_with_reads(self, reads_prefix, out_prefix, no_map_contigs):
tmpdir = tempfile.mkdtemp(prefix='tmp.extend.', dir=os.getcwd())
tmp_prefix = os.path.join(tmpdir, 'reads')
total_bases_added = 0
for i in range(5):
bam_prefix = out_prefix + '.' + str(i+1) + '.map'
bam = bam_prefix + '.bam'
self._map_reads(reads_prefix + '_1.fa', reads_prefix + '_2.fa', bam_prefix, no_map_contigs=no_map_contigs)
reads_prefix = tmp_prefix + '.' + str(i)
bases_added = self._extend_contigs_with_bam(bam, out_prefix=reads_prefix)
total_bases_added += bases_added
if self.clean:
os.unlink(bam)
if bases_added < 0.2 * self.ext_bases:
break
shutil.rmtree(tmpdir)
return total_bases_added
def _read_pair_extension_iterations(self, reads_prefix, out_prefix, no_map_contigs=None):
if no_map_contigs is None:
no_map_contigs = set()
assert(len(self.contigs) > len(no_map_contigs))
if self.verbose:
print('{:-^79}'.format(' ' + out_prefix + ' start extension subiteration 0001 '), flush=True)
bases_added = self._extend_with_reads(reads_prefix, out_prefix + '.1', no_map_contigs)
current_reads_prefix = reads_prefix
if bases_added == 0:
return True
try_contig_trim = False
i = 1
while self._worth_extending() or try_contig_trim:
i += 1
if self.verbose:
print('{:-^79}'.format(' ' + out_prefix + ' start extension subiteration ' + str(i).zfill(4) + ' '), flush=True)
if i % 5 == 0:
tmpdir = tempfile.mkdtemp(prefix='tmp.filter_reads.', dir=os.getcwd())
tmp_prefix = os.path.join(tmpdir, 'out')
bam = tmp_prefix + '.bam'
original_map_minid = self.map_minid
self.map_minid = 0.9
self._map_reads(current_reads_prefix + '_1.fa', current_reads_prefix + '_2.fa', tmp_prefix)
self.map_minid = original_map_minid
filter_prefix = reads_prefix + '.subiter.' + str(i) + '.reads'
mapping.bam_file_to_fasta_pair_files(bam, filter_prefix + '_1.fa', filter_prefix + '_2.fa', remove_proper_pairs=True)
if current_reads_prefix != reads_prefix:
os.unlink(current_reads_prefix + '_1.fa')
os.unlink(current_reads_prefix + '_2.fa')
current_reads_prefix = filter_prefix
shutil.rmtree(tmpdir)
iter_prefix = out_prefix + '.' + str(i)
bases_added = self._extend_with_reads(current_reads_prefix, iter_prefix, no_map_contigs)
if bases_added == 0:
if not try_contig_trim:
if self.verbose:
print(' No bases added. Try trimming contigs')
self._trim_strand_biased_ends(reads_prefix, tag_as_trimmed=False)
if len(self.contigs) <= len(no_map_contigs):
if self.verbose:
print(' lost contigs during trimming. No more iterations')
return False
self.trim_contigs(self.contig_iter_trim)
try_contig_trim = True
else:
if self.verbose:
print(' No bases added after trimming. No more iterations')
break
else:
try_contig_trim = False
if current_reads_prefix != reads_prefix:
os.unlink(current_reads_prefix + '_1.fa')
os.unlink(current_reads_prefix + '_2.fa')
return True
def read_pair_extend(self, reads_prefix, out_prefix):
assert(len(self.contigs))
current_reads_prefix = reads_prefix
i = 1
new_seed_name = 'dummy'
while 1:
if self.verbose:
print('{:_^79}'.format(' START ITERATION ' + str(i) + ' '), flush=True)
self._read_pair_extension_iterations(current_reads_prefix, out_prefix + '.' + str(i))
filtered_reads_prefix = out_prefix + '.' + str(i) + '.filtered'
self._trim_strand_biased_ends(reads_prefix, tag_as_trimmed=True, out_prefix=filtered_reads_prefix)
self._remove_contained_contigs(list(self.contigs.keys()))
self._merge_overlapping_contigs(list(self.contigs.keys()))
if reads_prefix != current_reads_prefix:
os.unlink(current_reads_prefix + '_1.fa')
os.unlink(current_reads_prefix + '_2.fa')
current_reads_prefix = filtered_reads_prefix
i += 1
reads_left = os.path.getsize(current_reads_prefix + '_1.fa') > 0 and os.path.getsize(current_reads_prefix + '_2.fa') > 0
if not self.make_new_seeds or new_seed_name is None or not self.make_new_seeds or len(self.contigs) >= self.max_contigs or not reads_left:
if reads_prefix != current_reads_prefix:
os.unlink(current_reads_prefix + '_1.fa')
os.unlink(current_reads_prefix + '_2.fa')
break
if self.verbose:
print('{:_^79}'.format(' Try making new seed '), flush=True)
new_seed_name = self.add_new_seed_contig(current_reads_prefix + '_1.fa', current_reads_prefix + '_2.fa')
if new_seed_name is None:
if self.verbose:
print('Couldn\'t make new seed and extend it. Stopping assembly.')
if len(self.contigs) == 0:
print('No contigs made.')
print('Read coverage may be too low, in which case try reducing --seed_min_kmer_cov, --ext_min_cov and --seed_ext_min_cov.')
print('Alternatively --max_insert could be incorrect, which is currently set to:', self.max_insert)
if reads_prefix != current_reads_prefix:
os.unlink(current_reads_prefix + '_1.fa')
os.unlink(current_reads_prefix + '_2.fa')
break
def _run_nucmer(self, contigs_to_use=None):
if contigs_to_use is None:
contigs_to_use = set()
if len(contigs_to_use) + len(self.contigs) <= 1:
return []
tmpdir = tempfile.mkdtemp(prefix='tmp.remove_self_contigs.', dir=os.getcwd())
nucmer_out = os.path.join(tmpdir, 'nucmer.out')
contigs_fasta = os.path.join(tmpdir, 'contigs.fa')
self.write_contigs_to_file(contigs_fasta, only_write=contigs_to_use)
mummer.run_nucmer(contigs_fasta, contigs_fasta, nucmer_out)
hits = [hit for hit in mummer.file_reader(nucmer_out) if not hit.is_self_hit()]
for hit in hits:
hit.sort()
hits = list(set(hits))
shutil.rmtree(tmpdir)
return hits
def _remove_contained_contigs(self, contigs):
if len(contigs) <= 1:
return
hits = self._run_nucmer(contigs_to_use=contigs)
for contig in self._contig_names_size_order()[:-1]:
if self._contig_contained_in_nucmer_hits(hits, contig, 95):
hits = self._remove_contig_from_nucmer_hits(hits, contig)
self._remove_contig(contig)
contigs.remove(contig)
if self.verbose >= 2:
print('Removing contained contig:', contig)
def _coords_to_new_contig(self, coords_list):
new_contig = pyfastaq.sequences.Fasta(coords_list[0][0], '')
descriptions = []
for name, coords, reverse in coords_list:
assert name in self.contigs
if reverse:
seq = pyfastaq.sequences.Fasta('ni', self.contigs[name].fa.seq[coords.start:coords.end+1])
seq.revcomp()
new_contig.seq += seq.seq
descriptions.append('{}[{}<-{}]'.format(name, coords.end, coords.start))
else:
new_contig.seq += self.contigs[name].fa.seq[coords.start:coords.end+1]
descriptions.append('{}[{}->{}]'.format(name, coords.start, coords.end))
if self.verbose >= 2:
final_description = '{}[0->{}]'.format(new_contig.id,
len(new_contig.seq))
print('Merging contigs:',
' + '.join(descriptions),
'==>',
final_description)
return new_contig
def _merge_overlapping_contigs(self, contigs):
if len(contigs) <= 1:
return
hits = self._run_nucmer(contigs)
assembly_graph = graph.Graph(self, contigs=contigs)
for hit in hits:
e = hit.to_graph_edge()
if e is not None:
assembly_graph.add_edge(e)
for connected_component in assembly_graph.connected_components():
if len(connected_component) < 2:
continue
simple_path = assembly_graph.find_simple_path(connected_component)
assert assembly_graph.simple_path_is_consistent(simple_path)
if len(simple_path) > 1:
simple_path = assembly_graph.remove_redundant_nodes_from_simple_path(simple_path)
coords = assembly_graph.merged_coords_from_simple_nonredundant_path(simple_path)
new_contig = self._coords_to_new_contig(coords)
for name, x, y in coords:
self._remove_contig(name)
self._add_contig(new_contig)
def _contig_names_size_order(self, biggest_first=False):
return sorted(self.contigs, key=lambda x:len(self.contigs[x]), reverse=biggest_first)
def _contig_contained_in_nucmer_hits(self, hits, contig, min_percent):
assert contig in self.contigs
contig_length = len(self.contigs[contig])
coords = []
for hit in [hit for hit in hits if contig in [hit.qry_name, hit.ref_name] and hit.qry_name != hit.ref_name]:
start = min(hit.qry_start, hit.qry_end)
end = max(hit.qry_start, hit.qry_end)
coords.append(pyfastaq.intervals.Interval(start, end))
if len(coords) == 0:
return False
pyfastaq.intervals.merge_overlapping_in_list(coords)
total_bases_matched = pyfastaq.intervals.length_sum_from_list(coords)
return min_percent <= 100.0 * total_bases_matched / len(self.contigs[contig])
def _remove_contig_from_nucmer_hits(self, hits, contig):
return [x for x in hits if contig not in [x.ref_name, x.qry_name]]
def _remove_contig(self, contig):
if contig in self.contigs:
del self.contigs[contig]
if contig in self.contig_lengths:
del self.contig_lengths[contig]
if contig in self.contigs_trimmed_for_strand_bias:
self.contigs_trimmed_for_strand_bias.remove(contig)
def _get_ref_length(self, samfile, sam):
if sam.is_unmapped:
return None
else:
return len(self.contigs[mapping.get_ref_name(sam, samfile)])
def _get_ref_length_sam_pair(self, samfile, sam1, sam2):
len1 = self._get_ref_length(samfile, sam1)
len2 = self._get_ref_length(samfile, sam2)
if len1 == len2:
return len1
else:
return None
def _get_unmapped_pairs(self, reads1, reads2, out_prefix):
self._map_reads(reads1, reads2, out_prefix, required_flag=12)
mapping.bam_file_to_fasta_pair_files(out_prefix + '.bam', out_prefix + '_1.fa', out_prefix + '_2.fa')
os.unlink(out_prefix + '.bam')
def add_new_seed_contig(self, reads1, reads2, contig_name=None, max_attempts=10):
if len(self.contigs):
tmpdir = tempfile.mkdtemp(prefix='tmp.make_seed.', dir=os.getcwd())
tmp_prefix = os.path.join(tmpdir, 'out')
seed_reads1 = tmp_prefix + '_1.fa'
seed_reads2 = tmp_prefix + '_2.fa'
if contig_name is not None:
self._map_reads(reads1, reads2, tmp_prefix, required_flag=5, exclude_flag=8, mate_ref=contig_name)
mapping.bam_to_fasta(tmp_prefix + '.bam', seed_reads1)
seed_reads2 = None
else:
self._get_unmapped_pairs(reads1, reads2, tmp_prefix)
else:
seed_reads1 = reads1
seed_reads2 = reads2
made_seed = False
for i in range(max_attempts):
s = seed.Seed(reads1=seed_reads1, reads2=seed_reads2, extend_length=self.seed_ext_max_bases, seed_length=self.seed_start_length, seed_min_count=self.seed_min_kmer_count, seed_max_count=self.seed_max_kmer_count, ext_min_cov=self.seed_min_cov, ext_min_ratio=self.seed_min_ratio, verbose=self.verbose, kmc_threads=self.kmc_threads, map_threads=self.threads, sequences_to_ignore=self.used_seeds, contigs_to_check=self.contigs)
if s.seq is None or len(s.seq) == 0:
break
if self.seed_overlap_length is None:
s.overlap_length = len(s.seq)
else:
s.overlap_length = self.seed_overlap_length
s.extend(reads1, reads2, self.seed_stop_length)
self.used_seeds.add(s.seq)
if len(s.seq) >= 0.75 * self.seed_stop_length:
made_seed = True
break
elif self.verbose:
print(" Couldn't extend seed enough. That was attempt", i+1, 'of', max_attempts, flush=True)
if len(self.contigs):
shutil.rmtree(tmpdir)
if not made_seed or len(s.seq) == 0:
return None
if self.verbose:
print(" Extended seed OK.", flush=True)
new_name = 'seeded.' + '1'.zfill(5)
i = 1
while new_name in self.contigs:
i += 1
new_name = 'seeded.' + str(i).zfill(5)
self._add_contig(pyfastaq.sequences.Fasta(new_name, s.seq))
return new_name
|
gpl-3.0
|
[
3,
1898,
334,
67,
9,
6927,
13,
9261,
18870,
1377,
26993,
12126,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
473,
15162,
14,
199,
3,
199,
3,
473,
15162,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
199,
3,
1015,
14,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
199,
3,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
199,
3,
2436,
14,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
646,
747,
199,
646,
10382,
455,
199,
646,
5549,
199,
646,
5145,
199,
504,
284,
3042,
492,
406,
17277,
12,
4412,
12,
6347,
12,
333,
453,
2626,
12,
3343,
12,
6275,
12,
2863,
199,
646,
1134,
20309,
81,
199,
199,
533,
3709,
9621,
26,
272,
347,
636,
826,
721,
277,
12,
406,
280,
458,
63,
493,
29,
403,
12,
2341,
63,
1080,
63,
75,
29,
1046,
12,
2341,
63,
1080,
63,
83,
29,
19,
12,
7183,
29,
17,
12,
1022,
5466,
63,
6962,
29,
17,
12,
1390,
63,
3176,
29,
6718,
12,
2341,
63,
827,
344,
29,
16,
14,
21,
12,
1748,
63,
7548,
29,
19,
12,
1599,
63,
827,
63,
8695,
29,
21,
12,
1599,
63,
827,
63,
6884,
29,
18,
12,
1599,
63,
12087,
29,
1960,
12,
3376,
29,
16,
12,
6347,
63,
827,
63,
8695,
29,
21,
12,
6347,
63,
827,
63,
6884,
29,
709,
12,
6347,
63,
827,
63,
75,
2626,
63,
835,
29,
1840,
12,
6347,
63,
988,
63,
75,
2626,
63,
835,
29,
17,
25464,
12,
6347,
63,
928,
63,
1267,
29,
403,
12,
6347,
63,
2379,
63,
1267,
29,
5783,
12,
6347,
63,
16736,
63,
1267,
29,
403,
12,
1852,
63,
1222,
63,
5176,
83,
29,
797,
12,
406,
17277,
63,
1661,
63,
12263,
29,
709,
12,
6347,
63,
832,
63,
988,
63,
12087,
29,
1400,
12,
1390,
63,
388,
280,
458,
29,
1400,
12,
3633,
29,
549,
12,
620,
460,
63,
8160,
29,
16,
304,
267,
291,
14,
388,
280,
458,
275,
1052,
267,
291,
14,
27952,
63,
14563,
275,
1052,
267,
291,
14,
1130,
63,
1080,
63,
75,
275,
2341,
63,
1080,
63,
75,
267,
291,
14,
1130,
63,
1080,
63,
83,
275,
2341,
63,
1080,
63,
83,
267,
291,
14,
6962,
275,
7183,
267,
291,
14,
75,
5466,
63,
6962,
275,
1022,
5466,
63,
6962,
267,
291,
14,
988,
63,
3176,
275,
1390,
63,
3176,
267,
291,
14,
1130,
63,
827,
344,
275,
2341,
63,
827,
344,
267,
291,
14,
827,
63,
7548,
275,
1748,
63,
7548,
267,
291,
14,
832,
63,
827,
63,
8695,
275,
1599,
63,
827,
63,
8695,
267,
291,
14,
832,
63,
827,
63,
6884,
275,
1599,
63,
827,
63,
6884,
267,
291,
14,
832,
63,
12087,
275,
1599,
63,
12087,
267,
291,
14,
3832,
275,
3376,
267,
291,
14,
3118,
275,
3633,
267,
291,
14,
1875,
63,
1222,
63,
5176,
83,
275,
1852,
63,
1222,
63,
5176,
83,
267,
291,
14,
5176,
63,
928,
63,
1267,
275,
6347,
63,
928,
63,
1267,
267,
291,
14,
5176,
63,
2379,
63,
1267,
275,
6347,
63,
2379,
63,
1267,
267,
291,
14,
5176,
63,
827,
63,
75,
2626,
63,
835,
275,
6347,
63,
827,
63,
75,
2626,
63,
835,
267,
291,
14,
5176,
63,
988,
63,
75,
2626,
63,
835,
275,
6347,
63,
988,
63,
75,
2626,
63,
835,
267,
291,
14,
5176,
63,
832,
63,
988,
63,
12087,
275,
6347,
63,
832,
63,
988,
63,
12087,
267,
291,
14,
5176,
63,
16736,
63,
1267,
275,
6347,
63,
16736,
63,
1267,
267,
291,
14,
5176,
63,
827,
63,
8695,
275,
6347,
63,
827,
63,
8695,
267,
291,
14,
5176,
63,
827,
63,
6884,
275,
6347,
63,
827,
63,
6884,
267,
291,
14,
27952,
63,
1661,
63,
12263,
275,
406,
17277,
63,
1661,
63,
12263,
267,
291,
14,
988,
63,
388,
280,
458,
275,
1390,
63,
388,
280,
458,
267,
291,
14,
30964,
63,
8160,
275,
620,
460,
63,
8160,
267,
291,
14,
388,
280,
458,
63,
12263,
3594,
63,
509,
63,
30964,
63,
8160,
275,
663,
342,
267,
291,
14,
2972,
63,
5176,
83,
275,
663,
342,
398,
340,
406,
280,
458,
63,
493,
365,
488,
26,
288,
291,
14,
1875,
63,
1222,
63,
5176,
83,
275,
715,
267,
587,
26,
288,
406,
280,
458,
275,
1052,
288,
1134,
20309,
81,
14,
5054,
14,
493,
63,
475,
63,
807,
8,
388,
280,
458,
63,
493,
12,
406,
280,
458,
9,
288,
367,
9428,
71,
315,
406,
280,
458,
26,
355,
291,
423,
525,
63,
27952,
8,
388,
280,
458,
59,
319,
71,
566,
2378,
347,
485,
525,
63,
27952,
8,
277,
12,
9428,
71,
12,
1748,
63,
1267,
29,
17,
304,
267,
340,
822,
8,
319,
71,
9,
665,
1748,
63,
1267,
26,
288,
372,
267,
702,
9428,
71,
14,
344,
440,
315,
291,
14,
388,
280,
458,
267,
702,
822,
8,
319,
71,
9,
690,
378,
267,
291,
14,
388,
280,
458,
59,
319,
71,
14,
344,
61,
275,
406,
17277,
14,
714,
17277,
8,
319,
71,
12,
3376,
29,
277,
14,
3832,
9,
267,
291,
14,
27952,
63,
14563,
59,
319,
71,
14,
344,
61,
275,
3474,
552,
8,
277,
14,
388,
280,
458,
59,
319,
71,
14,
344,
2522,
378,
12,
378,
2677,
2378,
347,
2218,
63,
388,
280,
458,
63,
475,
63,
493,
8,
277,
12,
1788,
12,
1748,
63,
1267,
29,
403,
12,
886,
63,
1397,
63,
952,
29,
403,
12,
1454,
63,
952,
29,
403,
12,
7282,
3199,
63,
2246,
29,
797,
12,
1865,
63,
991,
63,
269,
2319,
29,
797,
12,
2403,
29,
403,
304,
267,
340,
886,
63,
1397,
63,
952,
365,
488
] |
[
1898,
334,
67,
9,
6927,
13,
9261,
18870,
1377,
26993,
12126,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
473,
15162,
14,
199,
3,
199,
3,
473,
15162,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
199,
3,
1015,
14,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
199,
3,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
199,
3,
2436,
14,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
646,
747,
199,
646,
10382,
455,
199,
646,
5549,
199,
646,
5145,
199,
504,
284,
3042,
492,
406,
17277,
12,
4412,
12,
6347,
12,
333,
453,
2626,
12,
3343,
12,
6275,
12,
2863,
199,
646,
1134,
20309,
81,
199,
199,
533,
3709,
9621,
26,
272,
347,
636,
826,
721,
277,
12,
406,
280,
458,
63,
493,
29,
403,
12,
2341,
63,
1080,
63,
75,
29,
1046,
12,
2341,
63,
1080,
63,
83,
29,
19,
12,
7183,
29,
17,
12,
1022,
5466,
63,
6962,
29,
17,
12,
1390,
63,
3176,
29,
6718,
12,
2341,
63,
827,
344,
29,
16,
14,
21,
12,
1748,
63,
7548,
29,
19,
12,
1599,
63,
827,
63,
8695,
29,
21,
12,
1599,
63,
827,
63,
6884,
29,
18,
12,
1599,
63,
12087,
29,
1960,
12,
3376,
29,
16,
12,
6347,
63,
827,
63,
8695,
29,
21,
12,
6347,
63,
827,
63,
6884,
29,
709,
12,
6347,
63,
827,
63,
75,
2626,
63,
835,
29,
1840,
12,
6347,
63,
988,
63,
75,
2626,
63,
835,
29,
17,
25464,
12,
6347,
63,
928,
63,
1267,
29,
403,
12,
6347,
63,
2379,
63,
1267,
29,
5783,
12,
6347,
63,
16736,
63,
1267,
29,
403,
12,
1852,
63,
1222,
63,
5176,
83,
29,
797,
12,
406,
17277,
63,
1661,
63,
12263,
29,
709,
12,
6347,
63,
832,
63,
988,
63,
12087,
29,
1400,
12,
1390,
63,
388,
280,
458,
29,
1400,
12,
3633,
29,
549,
12,
620,
460,
63,
8160,
29,
16,
304,
267,
291,
14,
388,
280,
458,
275,
1052,
267,
291,
14,
27952,
63,
14563,
275,
1052,
267,
291,
14,
1130,
63,
1080,
63,
75,
275,
2341,
63,
1080,
63,
75,
267,
291,
14,
1130,
63,
1080,
63,
83,
275,
2341,
63,
1080,
63,
83,
267,
291,
14,
6962,
275,
7183,
267,
291,
14,
75,
5466,
63,
6962,
275,
1022,
5466,
63,
6962,
267,
291,
14,
988,
63,
3176,
275,
1390,
63,
3176,
267,
291,
14,
1130,
63,
827,
344,
275,
2341,
63,
827,
344,
267,
291,
14,
827,
63,
7548,
275,
1748,
63,
7548,
267,
291,
14,
832,
63,
827,
63,
8695,
275,
1599,
63,
827,
63,
8695,
267,
291,
14,
832,
63,
827,
63,
6884,
275,
1599,
63,
827,
63,
6884,
267,
291,
14,
832,
63,
12087,
275,
1599,
63,
12087,
267,
291,
14,
3832,
275,
3376,
267,
291,
14,
3118,
275,
3633,
267,
291,
14,
1875,
63,
1222,
63,
5176,
83,
275,
1852,
63,
1222,
63,
5176,
83,
267,
291,
14,
5176,
63,
928,
63,
1267,
275,
6347,
63,
928,
63,
1267,
267,
291,
14,
5176,
63,
2379,
63,
1267,
275,
6347,
63,
2379,
63,
1267,
267,
291,
14,
5176,
63,
827,
63,
75,
2626,
63,
835,
275,
6347,
63,
827,
63,
75,
2626,
63,
835,
267,
291,
14,
5176,
63,
988,
63,
75,
2626,
63,
835,
275,
6347,
63,
988,
63,
75,
2626,
63,
835,
267,
291,
14,
5176,
63,
832,
63,
988,
63,
12087,
275,
6347,
63,
832,
63,
988,
63,
12087,
267,
291,
14,
5176,
63,
16736,
63,
1267,
275,
6347,
63,
16736,
63,
1267,
267,
291,
14,
5176,
63,
827,
63,
8695,
275,
6347,
63,
827,
63,
8695,
267,
291,
14,
5176,
63,
827,
63,
6884,
275,
6347,
63,
827,
63,
6884,
267,
291,
14,
27952,
63,
1661,
63,
12263,
275,
406,
17277,
63,
1661,
63,
12263,
267,
291,
14,
988,
63,
388,
280,
458,
275,
1390,
63,
388,
280,
458,
267,
291,
14,
30964,
63,
8160,
275,
620,
460,
63,
8160,
267,
291,
14,
388,
280,
458,
63,
12263,
3594,
63,
509,
63,
30964,
63,
8160,
275,
663,
342,
267,
291,
14,
2972,
63,
5176,
83,
275,
663,
342,
398,
340,
406,
280,
458,
63,
493,
365,
488,
26,
288,
291,
14,
1875,
63,
1222,
63,
5176,
83,
275,
715,
267,
587,
26,
288,
406,
280,
458,
275,
1052,
288,
1134,
20309,
81,
14,
5054,
14,
493,
63,
475,
63,
807,
8,
388,
280,
458,
63,
493,
12,
406,
280,
458,
9,
288,
367,
9428,
71,
315,
406,
280,
458,
26,
355,
291,
423,
525,
63,
27952,
8,
388,
280,
458,
59,
319,
71,
566,
2378,
347,
485,
525,
63,
27952,
8,
277,
12,
9428,
71,
12,
1748,
63,
1267,
29,
17,
304,
267,
340,
822,
8,
319,
71,
9,
665,
1748,
63,
1267,
26,
288,
372,
267,
702,
9428,
71,
14,
344,
440,
315,
291,
14,
388,
280,
458,
267,
702,
822,
8,
319,
71,
9,
690,
378,
267,
291,
14,
388,
280,
458,
59,
319,
71,
14,
344,
61,
275,
406,
17277,
14,
714,
17277,
8,
319,
71,
12,
3376,
29,
277,
14,
3832,
9,
267,
291,
14,
27952,
63,
14563,
59,
319,
71,
14,
344,
61,
275,
3474,
552,
8,
277,
14,
388,
280,
458,
59,
319,
71,
14,
344,
2522,
378,
12,
378,
2677,
2378,
347,
2218,
63,
388,
280,
458,
63,
475,
63,
493,
8,
277,
12,
1788,
12,
1748,
63,
1267,
29,
403,
12,
886,
63,
1397,
63,
952,
29,
403,
12,
1454,
63,
952,
29,
403,
12,
7282,
3199,
63,
2246,
29,
797,
12,
1865,
63,
991,
63,
269,
2319,
29,
797,
12,
2403,
29,
403,
304,
267,
340,
886,
63,
1397,
63,
952,
365,
488,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
AOSP-YU/platform_external_skia
|
tools/skp/page_sets/skia_tigersvg_desktop.py
|
33
|
1279
|
# 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.
# pylint: disable=W0401,W0614
from telemetry.page import page as page_module
from telemetry.page import page_set as page_set_module
class SkiaBuildbotDesktopPage(page_module.Page):
def __init__(self, url, page_set):
super(SkiaBuildbotDesktopPage, self).__init__(
url=url,
page_set=page_set,
credentials_path='data/credentials.json')
self.user_agent_type = 'desktop'
self.archive_data_file = 'data/skia_tigersvg_desktop.json'
def RunNavigateSteps(self, action_runner):
action_runner.NavigateToPage(self)
action_runner.Wait(5)
class SkiaTigersvgDesktopPageSet(page_set_module.PageSet):
""" Pages designed to represent the median, not highly optimized web """
def __init__(self):
super(SkiaTigersvgDesktopPageSet, self).__init__(
user_agent_type='desktop',
archive_data_file='data/skia_tigersvg_desktop.json')
urls_list = [
# Why: from fmalita
('http://upload.wikimedia.org/wikipedia/commons/f/fd/'
'Ghostscript_Tiger.svg'),
]
for url in urls_list:
self.AddUserStory(SkiaBuildbotDesktopPage(url, self))
|
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,
3,
4287,
26,
3507,
29,
55,
28025,
12,
55,
1690,
1079,
421,
199,
504,
17298,
14,
1606,
492,
2034,
465,
2034,
63,
578,
199,
504,
17298,
14,
1606,
492,
2034,
63,
409,
465,
2034,
63,
409,
63,
578,
421,
199,
533,
29201,
4674,
3425,
3018,
20436,
3276,
8,
1606,
63,
578,
14,
3276,
304,
819,
347,
636,
826,
721,
277,
12,
1166,
12,
2034,
63,
409,
304,
272,
1613,
8,
14194,
4674,
3425,
3018,
20436,
3276,
12,
291,
2843,
826,
721,
267,
1166,
29,
633,
12,
267,
2034,
63,
409,
29,
1606,
63,
409,
12,
267,
6235,
63,
515,
534,
576,
15,
6942,
14,
1001,
358,
272,
291,
14,
751,
63,
4054,
63,
466,
275,
283,
14487,
7,
272,
291,
14,
6404,
63,
576,
63,
493,
275,
283,
576,
15,
1339,
4674,
63,
280,
836,
10273,
63,
14487,
14,
1001,
7,
819,
347,
3378,
31914,
20960,
8,
277,
12,
1595,
63,
5933,
304,
272,
1595,
63,
5933,
14,
31914,
1378,
3276,
8,
277,
9,
272,
1595,
63,
5933,
14,
7536,
8,
21,
9,
421,
199,
533,
29201,
4674,
52,
528,
1192,
10929,
20436,
3276,
1084,
8,
1606,
63,
409,
63,
578,
14,
3276,
1084,
304,
819,
408,
510,
7441,
19829,
370,
2954,
314,
17312,
12,
440,
4721,
590,
20212,
3330,
408,
819,
347,
636,
826,
721,
277,
304,
272,
1613,
8,
14194,
4674,
52,
528,
1192,
10929,
20436,
3276,
1084,
12,
291,
2843,
826,
721,
489,
922,
63,
4054,
63,
466,
534,
14487,
297,
489,
6359,
63,
576,
63,
493,
534,
576,
15,
1339,
4674,
63,
280,
836,
10273,
63,
14487,
14,
1001,
358,
339,
8187,
63,
513,
275,
359,
489,
327,
6827,
26,
687,
289,
2174,
21492,
489,
661,
1014,
921,
5064,
14,
5319,
1036,
2391,
14,
1308,
15,
13961,
15,
2330,
83,
15,
70,
15,
2592,
4805,
2126,
283,
39,
1102,
1579,
63,
52,
528,
281,
14,
10273,
659,
272,
1622,
339,
367,
1166,
315,
8187,
63,
513,
26,
489,
291,
14,
1123,
1899,
25120,
8,
14194,
4674,
3425,
3018,
20436,
3276,
8,
633,
12,
291,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
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,
3,
4287,
26,
3507,
29,
55,
28025,
12,
55,
1690,
1079,
421,
199,
504,
17298,
14,
1606,
492,
2034,
465,
2034,
63,
578,
199,
504,
17298,
14,
1606,
492,
2034,
63,
409,
465,
2034,
63,
409,
63,
578,
421,
199,
533,
29201,
4674,
3425,
3018,
20436,
3276,
8,
1606,
63,
578,
14,
3276,
304,
819,
347,
636,
826,
721,
277,
12,
1166,
12,
2034,
63,
409,
304,
272,
1613,
8,
14194,
4674,
3425,
3018,
20436,
3276,
12,
291,
2843,
826,
721,
267,
1166,
29,
633,
12,
267,
2034,
63,
409,
29,
1606,
63,
409,
12,
267,
6235,
63,
515,
534,
576,
15,
6942,
14,
1001,
358,
272,
291,
14,
751,
63,
4054,
63,
466,
275,
283,
14487,
7,
272,
291,
14,
6404,
63,
576,
63,
493,
275,
283,
576,
15,
1339,
4674,
63,
280,
836,
10273,
63,
14487,
14,
1001,
7,
819,
347,
3378,
31914,
20960,
8,
277,
12,
1595,
63,
5933,
304,
272,
1595,
63,
5933,
14,
31914,
1378,
3276,
8,
277,
9,
272,
1595,
63,
5933,
14,
7536,
8,
21,
9,
421,
199,
533,
29201,
4674,
52,
528,
1192,
10929,
20436,
3276,
1084,
8,
1606,
63,
409,
63,
578,
14,
3276,
1084,
304,
819,
408,
510,
7441,
19829,
370,
2954,
314,
17312,
12,
440,
4721,
590,
20212,
3330,
408,
819,
347,
636,
826,
721,
277,
304,
272,
1613,
8,
14194,
4674,
52,
528,
1192,
10929,
20436,
3276,
1084,
12,
291,
2843,
826,
721,
489,
922,
63,
4054,
63,
466,
534,
14487,
297,
489,
6359,
63,
576,
63,
493,
534,
576,
15,
1339,
4674,
63,
280,
836,
10273,
63,
14487,
14,
1001,
358,
339,
8187,
63,
513,
275,
359,
489,
327,
6827,
26,
687,
289,
2174,
21492,
489,
661,
1014,
921,
5064,
14,
5319,
1036,
2391,
14,
1308,
15,
13961,
15,
2330,
83,
15,
70,
15,
2592,
4805,
2126,
283,
39,
1102,
1579,
63,
52,
528,
281,
14,
10273,
659,
272,
1622,
339,
367,
1166,
315,
8187,
63,
513,
26,
489,
291,
14,
1123,
1899,
25120,
8,
14194,
4674,
3425,
3018,
20436,
3276,
8,
633,
12,
291,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,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stack-dashboard
|
openstack_dashboard/dashboards/project/containers/tables.py
|
5
|
16556
|
# Copyright 2012 Nebula, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
import django
from django.conf import settings
from django import shortcuts
from django import template
from django.template import defaultfilters as filters
from django.utils import http
from django.utils import safestring
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from horizon import exceptions
from horizon import messages
from horizon import tables
from horizon.utils.urlresolvers import reverse # noqa
from openstack_dashboard import api
from openstack_dashboard.api import swift
from openstack_dashboard.dashboards.project.containers import utils
LOG = logging.getLogger(__name__)
static_url = getattr(settings, 'STATIC_URL', '/static/')
LOADING_IMAGE = '<img src="%s/dashboard/img/loading.gif" />' % static_url
def _escape_full_url(url):
# NOTE (lhcheng): In Django 1.8, HttpRequest.get_full_path()
# method now escapes unsafe characters
# TODO(robcresswell): Remove in M, once django 1.7 is dropped
if django.VERSION < (1, 8):
return http.urlquote(url)
return url
class ViewContainer(tables.LinkAction):
name = "view"
verbose_name = _("View Details")
url = "horizon:project:containers:container_detail"
classes = ("ajax-modal", "btn-view")
def get_link_url(self, datum=None):
obj_id = self.table.get_object_id(datum)
return reverse(self.url, args=(obj_id,))
class MakePublicContainer(tables.Action):
name = "make_public"
verbose_name = _("Make Public")
icon = "pencil"
def allowed(self, request, container):
# Container metadata have not been loaded
if not hasattr(container, 'is_public'):
return False
return not container.is_public
def single(self, table, request, obj_id):
try:
api.swift.swift_update_container(request,
obj_id,
metadata=({'is_public': True}))
LOG.info('Updating container "%s" access to public.' % obj_id)
messages.success(request,
_('Successfully updated container access to '
'public.'))
except Exception:
exceptions.handle(request,
_('Unable to update container access.'))
return shortcuts.redirect('horizon:project:containers:index')
class MakePrivateContainer(tables.Action):
name = "make_private"
verbose_name = _("Make Private")
icon = "pencil"
def allowed(self, request, container):
# Container metadata have not been loaded
if not hasattr(container, 'is_public'):
return False
return container.is_public
def single(self, table, request, obj_id):
try:
api.swift.swift_update_container(request,
obj_id,
metadata=({'is_public': False}))
LOG.info('Updating container "%s" access to private.' % obj_id)
messages.success(request,
_('Successfully updated container access to '
'private.'))
except Exception:
exceptions.handle(request,
_('Unable to update container access.'))
return shortcuts.redirect('horizon:project:containers:index')
class DeleteContainer(tables.DeleteAction):
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete Container",
u"Delete Containers",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Deleted Container",
u"Deleted Containers",
count
)
success_url = "horizon:project:containers:index"
def delete(self, request, obj_id):
try:
api.swift.swift_delete_container(request, obj_id)
except exceptions.Conflict as exc:
exceptions.handle(request, exc, redirect=self.success_url)
except Exception:
exceptions.handle(request,
_('Unable to delete container.'),
redirect=self.success_url)
def get_success_url(self, request=None):
"""Returns the URL to redirect to after a successful action.
"""
current_container = self.table.kwargs.get("container_name", None)
# If the current_container is deleted, then redirect to the default
# completion url
if current_container in self.success_ids:
return self.success_url
return request.get_full_path()
class CreateContainer(tables.LinkAction):
name = "create"
verbose_name = _("Create Container")
url = "horizon:project:containers:create"
classes = ("ajax-modal",)
icon = "plus"
class ListObjects(tables.LinkAction):
name = "list_objects"
verbose_name = _("View Container")
url = "horizon:project:containers:index"
icon = "list"
def get_link_url(self, datum=None):
container_name = http.urlquote(datum.name)
args = (utils.wrap_delimiter(container_name),)
return reverse(self.url, args=args)
class CreatePseudoFolder(tables.LinkAction):
name = "create_pseudo_folder"
verbose_name = _("Create Pseudo-folder")
url = "horizon:project:containers:create_pseudo_folder"
classes = ("ajax-modal",)
icon = "plus"
def get_link_url(self, datum=None):
# Usable for both the container and object tables
if getattr(datum, 'container', datum):
container_name = http.urlquote(datum.name)
else:
container_name = self.table.kwargs['container_name']
subfolders = self.table.kwargs.get('subfolder_path', '')
args = (bit for bit in (container_name, subfolders) if bit)
return reverse(self.url, args=args)
def allowed(self, request, datum=None):
if self.table.kwargs.get('container_name', None):
return True
return False
def update(self, request, obj):
# This will only be called for the row, so we can remove the button
# styles meant for the table action version.
self.attrs = {'class': 'ajax-modal'}
class UploadObject(tables.LinkAction):
name = "upload"
verbose_name = _("Upload Object")
url = "horizon:project:containers:object_upload"
classes = ("ajax-modal",)
icon = "upload"
def get_link_url(self, datum=None):
# Usable for both the container and object tables
if getattr(datum, 'container', datum):
# This is a container
container_name = datum.name
else:
# This is a table action, and we already have the container name
container_name = self.table.kwargs['container_name']
subfolders = self.table.kwargs.get('subfolder_path', '')
args = (bit for bit in (container_name, subfolders) if bit)
return reverse(self.url, args=args)
def allowed(self, request, datum=None):
if self.table.kwargs.get('container_name', None):
return True
return False
def update(self, request, obj):
# This will only be called for the row, so we can remove the button
# styles meant for the table action version.
self.attrs = {'class': 'ajax-modal'}
def get_size_used(container):
return filters.filesizeformat(container.bytes)
def get_container_link(container):
return reverse("horizon:project:containers:index",
args=(utils.wrap_delimiter(container.name),))
class ContainerAjaxUpdateRow(tables.Row):
ajax = True
def get_data(self, request, container_name):
container = api.swift.swift_get_container(request,
container_name,
with_data=False)
return container
def get_metadata(container):
# If the metadata has not been loading, display a loading image
if not hasattr(container, 'is_public'):
return safestring.mark_safe(LOADING_IMAGE)
template_name = 'project/containers/_container_metadata.html'
context = {"container": container}
return template.loader.render_to_string(template_name, context)
def get_metadata_loaded(container):
# Determine if metadata has been loaded if the attribute is already set.
return hasattr(container, 'is_public') and container.is_public is not None
class ContainersTable(tables.DataTable):
METADATA_LOADED_CHOICES = (
(False, None),
(True, True),
)
name = tables.Column("name",
link=get_container_link,
verbose_name=_("Container Name"))
metadata = tables.Column(get_metadata,
verbose_name=_("Container Details"),
classes=('nowrap-col', ),)
metadata_loaded = tables.Column(get_metadata_loaded,
status=True,
status_choices=METADATA_LOADED_CHOICES,
hidden=True)
class Meta(object):
name = "containers"
verbose_name = _("Containers")
row_class = ContainerAjaxUpdateRow
status_columns = ['metadata_loaded', ]
table_actions = (CreateContainer,)
row_actions = (ViewContainer, MakePublicContainer,
MakePrivateContainer, DeleteContainer,)
browser_table = "navigation"
footer = False
def get_object_id(self, container):
return container.name
def get_absolute_url(self):
url = super(ContainersTable, self).get_absolute_url()
return _escape_full_url(url)
def get_full_url(self):
"""Returns the encoded absolute URL path with its query string.
This is used for the POST action attribute on the form element
wrapping the table. We use this method to persist the
pagination marker.
"""
url = super(ContainersTable, self).get_full_url()
return _escape_full_url(url)
class ViewObject(tables.LinkAction):
name = "view"
verbose_name = _("View Details")
url = "horizon:project:containers:object_detail"
classes = ("ajax-modal", "btn-view")
allowed_data_types = ("objects",)
def get_link_url(self, obj):
container_name = self.table.kwargs['container_name']
return reverse(self.url, args=(container_name, obj.name))
class UpdateObject(tables.LinkAction):
name = "update_object"
verbose_name = _("Edit")
url = "horizon:project:containers:object_update"
classes = ("ajax-modal",)
icon = "pencil"
allowed_data_types = ("objects",)
def get_link_url(self, obj):
container_name = self.table.kwargs['container_name']
return reverse(self.url, args=(container_name, obj.name))
class DeleteObject(tables.DeleteAction):
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete Object",
u"Delete Objects",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Deleted Object",
u"Deleted Objects",
count
)
name = "delete_object"
allowed_data_types = ("objects", "subfolders",)
def delete(self, request, obj_id):
obj = self.table.get_object_by_id(obj_id)
container_name = obj.container_name
datum_type = getattr(obj, self.table._meta.data_type_name, None)
if datum_type == 'subfolders':
obj_id = obj_id[(len(container_name) + 1):] + "/"
api.swift.swift_delete_object(request, container_name, obj_id)
def get_success_url(self, request):
url = super(DeleteObject, self).get_success_url(request)
return _escape_full_url(url)
class DeleteMultipleObjects(DeleteObject):
name = "delete_multiple_objects"
class CopyObject(tables.LinkAction):
name = "copy"
verbose_name = _("Copy")
url = "horizon:project:containers:object_copy"
classes = ("ajax-modal",)
icon = "circle-arrow-right"
allowed_data_types = ("objects",)
def get_link_url(self, obj):
container_name = self.table.kwargs['container_name']
return reverse(self.url, args=(container_name, obj.name))
class DownloadObject(tables.LinkAction):
name = "download"
verbose_name = _("Download")
url = "horizon:project:containers:object_download"
icon = "download"
allowed_data_types = ("objects",)
def get_link_url(self, obj):
container_name = self.table.kwargs['container_name']
return reverse(self.url, args=(container_name, obj.name))
def allowed(self, request, object):
return object.bytes and object.bytes > 0
class ObjectFilterAction(tables.FilterAction):
def _filtered_data(self, table, filter_string):
request = table.request
container = self.table.kwargs['container_name']
subfolder = self.table.kwargs['subfolder_path']
prefix = utils.wrap_delimiter(subfolder) if subfolder else ''
self.filtered_data = api.swift.swift_filter_objects(request,
filter_string,
container,
prefix=prefix)
return self.filtered_data
def filter_subfolders_data(self, table, objects, filter_string):
data = self._filtered_data(table, filter_string)
return [datum for datum in data if
datum.content_type == "application/pseudo-folder"]
def filter_objects_data(self, table, objects, filter_string):
data = self._filtered_data(table, filter_string)
return [datum for datum in data if
datum.content_type != "application/pseudo-folder"]
def allowed(self, request, datum=None):
if self.table.kwargs.get('container_name', None):
return True
return False
def sanitize_name(name):
return name.split(swift.FOLDER_DELIMITER)[-1]
def get_size(obj):
if obj.bytes is None:
return _("pseudo-folder")
return filters.filesizeformat(obj.bytes)
def get_link_subfolder(subfolder):
container_name = subfolder.container_name
return reverse("horizon:project:containers:index",
args=(utils.wrap_delimiter(container_name),
utils.wrap_delimiter(subfolder.name)))
class ObjectsTable(tables.DataTable):
name = tables.Column("name",
link=get_link_subfolder,
allowed_data_types=("subfolders",),
verbose_name=_("Object Name"),
filters=(sanitize_name,))
size = tables.Column(get_size, verbose_name=_('Size'))
class Meta(object):
name = "objects"
verbose_name = _("Objects")
table_actions = (ObjectFilterAction, CreatePseudoFolder, UploadObject,
DeleteMultipleObjects)
row_actions = (DownloadObject, UpdateObject, CopyObject,
ViewObject, DeleteObject)
data_types = ("subfolders", "objects")
browser_table = "content"
footer = False
def get_absolute_url(self):
url = super(ObjectsTable, self).get_absolute_url()
return _escape_full_url(url)
def get_full_url(self):
"""Returns the encoded absolute URL path with its query string.
This is used for the POST action attribute on the form element
wrapping the table. We use this method to persist the
pagination marker.
"""
url = super(ObjectsTable, self).get_full_url()
return _escape_full_url(url)
|
apache-2.0
|
[
3,
1898,
6029,
653,
2871,
7586,
12,
3277,
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,
646,
2050,
199,
199,
646,
1639,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
492,
3974,
12946,
199,
504,
1639,
492,
1978,
199,
504,
1639,
14,
1160,
492,
849,
4273,
465,
4766,
199,
504,
1639,
14,
1208,
492,
1455,
199,
504,
1639,
14,
1208,
492,
5048,
875,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
1208,
14,
6893,
492,
26843,
63,
6395,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
3788,
199,
504,
21726,
492,
6716,
199,
504,
21726,
14,
1208,
14,
16522,
492,
3837,
221,
327,
8151,
199,
199,
504,
13869,
63,
9743,
492,
2986,
199,
504,
13869,
63,
9743,
14,
1246,
492,
16275,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
13577,
492,
3778,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
1986,
63,
633,
275,
2519,
8,
1751,
12,
283,
10449,
63,
2632,
297,
1994,
1986,
6217,
199,
7405,
1206,
63,
9438,
275,
2650,
4060,
2928,
5961,
83,
15,
9743,
15,
4060,
15,
8786,
14,
14513,
2,
22294,
450,
2955,
63,
633,
421,
199,
318,
485,
3765,
63,
2861,
63,
633,
8,
633,
304,
272,
327,
6944,
334,
25514,
335,
7420,
304,
1010,
5634,
413,
14,
24,
12,
20730,
14,
362,
63,
2861,
63,
515,
342,
272,
327,
1083,
3063,
24644,
19293,
4110,
272,
327,
3254,
8,
293,
3776,
753,
20501,
304,
5852,
315,
603,
12,
5403,
1639,
413,
14,
23,
365,
17481,
272,
340,
1639,
14,
4612,
665,
334,
17,
12,
1695,
304,
267,
372,
1455,
14,
633,
3513,
8,
633,
9,
272,
372,
1166,
421,
199,
533,
10935,
4076,
8,
5987,
14,
3834,
3310,
304,
272,
536,
275,
298,
1345,
2,
272,
3376,
63,
354,
275,
3824,
2768,
15621,
531,
272,
1166,
275,
298,
16561,
26,
1715,
26,
13577,
26,
3600,
63,
5506,
2,
272,
3992,
275,
1689,
12774,
13,
17713,
401,
298,
9633,
13,
1345,
531,
339,
347,
664,
63,
1073,
63,
633,
8,
277,
12,
18908,
29,
403,
304,
267,
1559,
63,
344,
275,
291,
14,
1224,
14,
362,
63,
785,
63,
344,
8,
18945,
9,
267,
372,
3837,
8,
277,
14,
633,
12,
1249,
2687,
1113,
63,
344,
4641,
421,
199,
533,
4155,
9885,
4076,
8,
5987,
14,
3310,
304,
272,
536,
275,
298,
1875,
63,
3455,
2,
272,
3376,
63,
354,
275,
3824,
5483,
1684,
531,
272,
7016,
275,
298,
897,
24707,
2,
339,
347,
4370,
8,
277,
12,
1056,
12,
3970,
304,
267,
327,
15395,
3341,
1172,
440,
2757,
6511,
267,
340,
440,
2688,
8,
3600,
12,
283,
374,
63,
3455,
735,
288,
372,
756,
267,
372,
440,
3970,
14,
374,
63,
3455,
339,
347,
2849,
8,
277,
12,
1817,
12,
1056,
12,
1559,
63,
344,
304,
267,
862,
26,
288,
2986,
14,
13215,
14,
13215,
63,
873,
63,
3600,
8,
1069,
12,
6163,
1559,
63,
344,
12,
6163,
3341,
2687,
1445,
374,
63,
3455,
356,
715,
12466,
288,
5051,
14,
815,
360,
24993,
3970,
2071,
83,
2,
2879,
370,
4575,
3530,
450,
1559,
63,
344,
9,
288,
3788,
14,
3742,
8,
1069,
12,
2490,
4018,
25001,
4588,
3970,
2879,
370,
283,
3044,
283,
3455,
12459,
267,
871,
2186,
26,
288,
4967,
14,
2479,
8,
1069,
12,
2892,
4018,
6005,
370,
1678,
3970,
2879,
12459,
267,
372,
3974,
12946,
14,
4876,
360,
16561,
26,
1715,
26,
13577,
26,
1080,
358,
421,
199,
533,
4155,
12185,
4076,
8,
5987,
14,
3310,
304,
272,
536,
275,
298,
1875,
63,
4239,
2,
272,
3376,
63,
354,
275,
3824,
5483,
18551,
531,
272,
7016,
275,
298,
897,
24707,
2,
339,
347,
4370,
8,
277,
12,
1056,
12,
3970,
304,
267,
327,
15395,
3341,
1172,
440,
2757,
6511,
267,
340,
440,
2688,
8,
3600,
12,
283,
374,
63,
3455,
735,
288,
372,
756,
267,
372,
3970,
14,
374,
63,
3455,
339,
347,
2849,
8,
277,
12,
1817,
12,
1056,
12,
1559,
63,
344,
304,
267,
862,
26,
288,
2986,
14,
13215,
14,
13215,
63,
873,
63,
3600,
8,
1069,
12,
6163,
1559,
63,
344,
12,
6163,
3341,
2687,
1445,
374,
63,
3455,
356,
756,
12466,
288,
5051,
14,
815,
360,
24993,
3970,
2071,
83,
2,
2879,
370,
5726,
3530,
450,
1559,
63,
344,
9,
288,
3788,
14,
3742,
8,
1069,
12,
2490,
4018,
25001,
4588,
3970,
2879,
370,
283,
3044,
283,
4239,
12459,
267,
871,
2186,
26,
288,
4967,
14,
2479,
8,
1069,
12,
2892,
4018,
6005,
370,
1678,
3970,
2879,
12459,
267,
372,
3974,
12946,
14,
4876,
360,
16561,
26,
1715,
26,
13577,
26,
1080,
358,
421,
199,
533,
8496,
4076,
8,
5987,
14,
5392,
3310,
304,
272,
768,
4639,
272,
347,
1595,
63,
1881,
8,
835,
304,
267,
372,
26843,
63,
6395,
8,
288,
399,
2,
5392,
15395,
401,
288,
399,
2,
5392,
1448,
877,
1192,
401,
288,
2338,
267,
776,
339,
768,
4639,
272,
347,
1595,
63,
18597,
8,
835,
304,
267,
372,
26843,
63,
6395,
8,
288,
399,
2,
17735,
15395,
401,
288,
399,
2,
17735,
1448,
877,
1192,
401,
288,
2338,
267,
776,
339,
3182,
63,
633,
275,
298,
16561,
26,
1715,
26,
13577,
26,
1080,
2,
339,
347,
3145,
8,
277,
12,
1056,
12,
1559,
63,
344,
304,
267,
862,
26,
288,
2986,
14,
13215,
14,
13215,
63,
1807,
63,
3600,
8,
1069,
12,
1559,
63
] |
[
1898,
6029,
653,
2871,
7586,
12,
3277,
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,
646,
2050,
199,
199,
646,
1639,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
492,
3974,
12946,
199,
504,
1639,
492,
1978,
199,
504,
1639,
14,
1160,
492,
849,
4273,
465,
4766,
199,
504,
1639,
14,
1208,
492,
1455,
199,
504,
1639,
14,
1208,
492,
5048,
875,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
1208,
14,
6893,
492,
26843,
63,
6395,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
3788,
199,
504,
21726,
492,
6716,
199,
504,
21726,
14,
1208,
14,
16522,
492,
3837,
221,
327,
8151,
199,
199,
504,
13869,
63,
9743,
492,
2986,
199,
504,
13869,
63,
9743,
14,
1246,
492,
16275,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
13577,
492,
3778,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
1986,
63,
633,
275,
2519,
8,
1751,
12,
283,
10449,
63,
2632,
297,
1994,
1986,
6217,
199,
7405,
1206,
63,
9438,
275,
2650,
4060,
2928,
5961,
83,
15,
9743,
15,
4060,
15,
8786,
14,
14513,
2,
22294,
450,
2955,
63,
633,
421,
199,
318,
485,
3765,
63,
2861,
63,
633,
8,
633,
304,
272,
327,
6944,
334,
25514,
335,
7420,
304,
1010,
5634,
413,
14,
24,
12,
20730,
14,
362,
63,
2861,
63,
515,
342,
272,
327,
1083,
3063,
24644,
19293,
4110,
272,
327,
3254,
8,
293,
3776,
753,
20501,
304,
5852,
315,
603,
12,
5403,
1639,
413,
14,
23,
365,
17481,
272,
340,
1639,
14,
4612,
665,
334,
17,
12,
1695,
304,
267,
372,
1455,
14,
633,
3513,
8,
633,
9,
272,
372,
1166,
421,
199,
533,
10935,
4076,
8,
5987,
14,
3834,
3310,
304,
272,
536,
275,
298,
1345,
2,
272,
3376,
63,
354,
275,
3824,
2768,
15621,
531,
272,
1166,
275,
298,
16561,
26,
1715,
26,
13577,
26,
3600,
63,
5506,
2,
272,
3992,
275,
1689,
12774,
13,
17713,
401,
298,
9633,
13,
1345,
531,
339,
347,
664,
63,
1073,
63,
633,
8,
277,
12,
18908,
29,
403,
304,
267,
1559,
63,
344,
275,
291,
14,
1224,
14,
362,
63,
785,
63,
344,
8,
18945,
9,
267,
372,
3837,
8,
277,
14,
633,
12,
1249,
2687,
1113,
63,
344,
4641,
421,
199,
533,
4155,
9885,
4076,
8,
5987,
14,
3310,
304,
272,
536,
275,
298,
1875,
63,
3455,
2,
272,
3376,
63,
354,
275,
3824,
5483,
1684,
531,
272,
7016,
275,
298,
897,
24707,
2,
339,
347,
4370,
8,
277,
12,
1056,
12,
3970,
304,
267,
327,
15395,
3341,
1172,
440,
2757,
6511,
267,
340,
440,
2688,
8,
3600,
12,
283,
374,
63,
3455,
735,
288,
372,
756,
267,
372,
440,
3970,
14,
374,
63,
3455,
339,
347,
2849,
8,
277,
12,
1817,
12,
1056,
12,
1559,
63,
344,
304,
267,
862,
26,
288,
2986,
14,
13215,
14,
13215,
63,
873,
63,
3600,
8,
1069,
12,
6163,
1559,
63,
344,
12,
6163,
3341,
2687,
1445,
374,
63,
3455,
356,
715,
12466,
288,
5051,
14,
815,
360,
24993,
3970,
2071,
83,
2,
2879,
370,
4575,
3530,
450,
1559,
63,
344,
9,
288,
3788,
14,
3742,
8,
1069,
12,
2490,
4018,
25001,
4588,
3970,
2879,
370,
283,
3044,
283,
3455,
12459,
267,
871,
2186,
26,
288,
4967,
14,
2479,
8,
1069,
12,
2892,
4018,
6005,
370,
1678,
3970,
2879,
12459,
267,
372,
3974,
12946,
14,
4876,
360,
16561,
26,
1715,
26,
13577,
26,
1080,
358,
421,
199,
533,
4155,
12185,
4076,
8,
5987,
14,
3310,
304,
272,
536,
275,
298,
1875,
63,
4239,
2,
272,
3376,
63,
354,
275,
3824,
5483,
18551,
531,
272,
7016,
275,
298,
897,
24707,
2,
339,
347,
4370,
8,
277,
12,
1056,
12,
3970,
304,
267,
327,
15395,
3341,
1172,
440,
2757,
6511,
267,
340,
440,
2688,
8,
3600,
12,
283,
374,
63,
3455,
735,
288,
372,
756,
267,
372,
3970,
14,
374,
63,
3455,
339,
347,
2849,
8,
277,
12,
1817,
12,
1056,
12,
1559,
63,
344,
304,
267,
862,
26,
288,
2986,
14,
13215,
14,
13215,
63,
873,
63,
3600,
8,
1069,
12,
6163,
1559,
63,
344,
12,
6163,
3341,
2687,
1445,
374,
63,
3455,
356,
756,
12466,
288,
5051,
14,
815,
360,
24993,
3970,
2071,
83,
2,
2879,
370,
5726,
3530,
450,
1559,
63,
344,
9,
288,
3788,
14,
3742,
8,
1069,
12,
2490,
4018,
25001,
4588,
3970,
2879,
370,
283,
3044,
283,
4239,
12459,
267,
871,
2186,
26,
288,
4967,
14,
2479,
8,
1069,
12,
2892,
4018,
6005,
370,
1678,
3970,
2879,
12459,
267,
372,
3974,
12946,
14,
4876,
360,
16561,
26,
1715,
26,
13577,
26,
1080,
358,
421,
199,
533,
8496,
4076,
8,
5987,
14,
5392,
3310,
304,
272,
768,
4639,
272,
347,
1595,
63,
1881,
8,
835,
304,
267,
372,
26843,
63,
6395,
8,
288,
399,
2,
5392,
15395,
401,
288,
399,
2,
5392,
1448,
877,
1192,
401,
288,
2338,
267,
776,
339,
768,
4639,
272,
347,
1595,
63,
18597,
8,
835,
304,
267,
372,
26843,
63,
6395,
8,
288,
399,
2,
17735,
15395,
401,
288,
399,
2,
17735,
1448,
877,
1192,
401,
288,
2338,
267,
776,
339,
3182,
63,
633,
275,
298,
16561,
26,
1715,
26,
13577,
26,
1080,
2,
339,
347,
3145,
8,
277,
12,
1056,
12,
1559,
63,
344,
304,
267,
862,
26,
288,
2986,
14,
13215,
14,
13215,
63,
1807,
63,
3600,
8,
1069,
12,
1559,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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tests/test_manager.py
|
5
|
9624
|
"""
Tests for manager.py
"""
import ddt
from nose.plugins.attrib import attr
from unittest import TestCase
from ..block_structure import BlockStructureBlockData
from ..config import RAISE_ERROR_WHEN_NOT_FOUND, STORAGE_BACKING_FOR_CACHE, waffle
from ..exceptions import UsageKeyNotInBlockStructure, BlockStructureNotFound
from ..manager import BlockStructureManager
from ..transformers import BlockStructureTransformers
from .helpers import (
MockModulestoreFactory, MockCache, MockTransformer,
ChildrenMapTestMixin, UsageKeyFactoryMixin,
mock_registered_transformers,
)
class TestTransformer1(MockTransformer):
"""
Test Transformer class with basic functionality to verify collected and
transformed data.
"""
collect_data_key = 't1.collect'
transform_data_key = 't1.transform'
collect_call_count = 0
@classmethod
def collect(cls, block_structure):
"""
Collects block data for the block structure.
"""
cls._set_block_values(block_structure, cls.collect_data_key)
cls.collect_call_count += 1
def transform(self, usage_info, block_structure):
"""
Transforms the block structure.
"""
self._set_block_values(block_structure, self.transform_data_key)
@classmethod
def assert_collected(cls, block_structure):
"""
Asserts data was collected for the block structure.
"""
cls._assert_block_values(block_structure, cls.collect_data_key)
@classmethod
def assert_transformed(cls, block_structure):
"""
Asserts the block structure was transformed.
"""
cls._assert_block_values(block_structure, cls.transform_data_key)
@classmethod
def _set_block_values(cls, block_structure, data_key):
"""
Sets a value for each block in the given structure, using the given
data key.
"""
for block_key in block_structure.topological_traversal():
block_structure.set_transformer_block_field(
block_key, cls, data_key, cls._create_block_value(block_key, data_key)
)
@classmethod
def _assert_block_values(cls, block_structure, data_key):
"""
Verifies the value for each block in the given structure, for the given
data key.
"""
for block_key in block_structure.topological_traversal():
assert (
block_structure.get_transformer_block_field(
block_key,
cls,
data_key,
) == cls._create_block_value(block_key, data_key)
)
@classmethod
def _create_block_value(cls, block_key, data_key):
"""
Returns a unique deterministic value for the given block key
and data key.
"""
return data_key + 't1.val1.' + unicode(block_key)
@attr(shard=2)
@ddt.ddt
class TestBlockStructureManager(UsageKeyFactoryMixin, ChildrenMapTestMixin, TestCase):
"""
Test class for BlockStructureManager.
"""
def setUp(self):
super(TestBlockStructureManager, self).setUp()
TestTransformer1.collect_call_count = 0
self.registered_transformers = [TestTransformer1()]
with mock_registered_transformers(self.registered_transformers):
self.transformers = BlockStructureTransformers(self.registered_transformers)
self.children_map = self.SIMPLE_CHILDREN_MAP
self.modulestore = MockModulestoreFactory.create(self.children_map, self.block_key_factory)
self.cache = MockCache()
self.bs_manager = BlockStructureManager(self.block_key_factory(0), self.modulestore, self.cache)
def collect_and_verify(self, expect_modulestore_called, expect_cache_updated):
"""
Calls the manager's get_collected method and verifies its result
and behavior.
"""
self.modulestore.get_items_call_count = 0
self.cache.set_call_count = 0
with mock_registered_transformers(self.registered_transformers):
block_structure = self.bs_manager.get_collected()
self.assert_block_structure(block_structure, self.children_map)
TestTransformer1.assert_collected(block_structure)
if expect_modulestore_called:
self.assertGreater(self.modulestore.get_items_call_count, 0)
else:
self.assertEquals(self.modulestore.get_items_call_count, 0)
self.assertEquals(self.cache.set_call_count, 1 if expect_cache_updated else 0)
def test_get_transformed(self):
with mock_registered_transformers(self.registered_transformers):
block_structure = self.bs_manager.get_transformed(self.transformers)
self.assert_block_structure(block_structure, self.children_map)
TestTransformer1.assert_collected(block_structure)
TestTransformer1.assert_transformed(block_structure)
def test_get_transformed_with_starting_block(self):
with mock_registered_transformers(self.registered_transformers):
block_structure = self.bs_manager.get_transformed(
self.transformers,
starting_block_usage_key=self.block_key_factory(1),
)
substructure_of_children_map = [[], [3, 4], [], [], []]
self.assert_block_structure(block_structure, substructure_of_children_map, missing_blocks=[0, 2])
TestTransformer1.assert_collected(block_structure)
TestTransformer1.assert_transformed(block_structure)
def test_get_transformed_with_collected(self):
with mock_registered_transformers(self.registered_transformers):
collected_block_structure = self.bs_manager.get_collected()
# using the same collected block structure,
# transform at different starting blocks
for (starting_block, expected_structure, expected_missing_blocks) in [
(0, [[1, 2], [3, 4], [], [], []], []),
(1, [[], [3, 4], [], [], []], [0, 2]),
(2, [[], [], [], [], []], [0, 1, 3, 4]),
]:
block_structure = self.bs_manager.get_transformed(
self.transformers,
starting_block_usage_key=self.block_key_factory(starting_block),
collected_block_structure=collected_block_structure,
)
self.assert_block_structure(block_structure, expected_structure, missing_blocks=expected_missing_blocks)
def test_get_transformed_with_nonexistent_starting_block(self):
with mock_registered_transformers(self.registered_transformers):
with self.assertRaises(UsageKeyNotInBlockStructure):
self.bs_manager.get_transformed(self.transformers, starting_block_usage_key=100)
def test_get_collected_cached(self):
self.collect_and_verify(expect_modulestore_called=True, expect_cache_updated=True)
self.collect_and_verify(expect_modulestore_called=False, expect_cache_updated=False)
self.assertEquals(TestTransformer1.collect_call_count, 1)
def test_get_collected_error_raised(self):
with waffle().override(RAISE_ERROR_WHEN_NOT_FOUND, active=True):
with mock_registered_transformers(self.registered_transformers):
with self.assertRaises(BlockStructureNotFound):
self.bs_manager.get_collected()
@ddt.data(True, False)
def test_update_collected_if_needed(self, with_storage_backing):
with waffle().override(STORAGE_BACKING_FOR_CACHE, active=with_storage_backing):
with mock_registered_transformers(self.registered_transformers):
self.assertEquals(TestTransformer1.collect_call_count, 0)
self.bs_manager.update_collected_if_needed()
self.assertEquals(TestTransformer1.collect_call_count, 1)
self.bs_manager.update_collected_if_needed()
self.assertEquals(TestTransformer1.collect_call_count, 1 if with_storage_backing else 2)
self.collect_and_verify(expect_modulestore_called=False, expect_cache_updated=False)
def test_get_collected_transformer_version(self):
self.collect_and_verify(expect_modulestore_called=True, expect_cache_updated=True)
# transformer code writes new schema version; data not re-collected
TestTransformer1.WRITE_VERSION += 1
self.collect_and_verify(expect_modulestore_called=False, expect_cache_updated=False)
# transformer code requires new schema version; data re-collected
TestTransformer1.READ_VERSION += 1
self.collect_and_verify(expect_modulestore_called=True, expect_cache_updated=True)
# old transformer code can read new schema version; data not re-collected
TestTransformer1.READ_VERSION -= 1
self.collect_and_verify(expect_modulestore_called=False, expect_cache_updated=False)
self.assertEquals(TestTransformer1.collect_call_count, 2)
def test_get_collected_structure_version(self):
self.collect_and_verify(expect_modulestore_called=True, expect_cache_updated=True)
BlockStructureBlockData.VERSION += 1
self.collect_and_verify(expect_modulestore_called=True, expect_cache_updated=True)
self.assertEquals(TestTransformer1.collect_call_count, 2)
def test_clear(self):
self.collect_and_verify(expect_modulestore_called=True, expect_cache_updated=True)
self.bs_manager.clear()
self.collect_and_verify(expect_modulestore_called=True, expect_cache_updated=True)
self.assertEquals(TestTransformer1.collect_call_count, 2)
|
agpl-3.0
|
[
624,
199,
2925,
367,
5256,
14,
647,
199,
624,
199,
646,
366,
3583,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
504,
2882,
492,
7640,
199,
199,
504,
2508,
1457,
63,
6976,
492,
8651,
10766,
3142,
1451,
199,
504,
2508,
888,
492,
31632,
4971,
63,
3170,
63,
9792,
742,
63,
4609,
63,
13945,
12,
4384,
726,
2962,
63,
7111,
1206,
63,
2707,
63,
8677,
12,
336,
9181,
274,
199,
504,
2508,
3924,
492,
11028,
1197,
1763,
607,
3142,
10766,
12,
8651,
10766,
4667,
199,
504,
2508,
2609,
492,
8651,
10766,
2988,
199,
504,
2508,
1515,
22932,
492,
8651,
10766,
3188,
22932,
199,
504,
1275,
7546,
492,
334,
272,
4420,
2377,
1617,
2927,
12,
4420,
4437,
12,
4420,
19761,
12,
272,
12988,
828,
2956,
22060,
12,
11028,
1197,
2927,
4256,
12,
272,
1683,
63,
11616,
63,
1515,
22932,
12,
199,
9,
421,
199,
533,
1379,
19761,
17,
8,
3346,
19761,
304,
272,
408,
272,
1379,
30486,
1021,
543,
5678,
9330,
370,
4911,
13736,
436,
272,
14834,
666,
14,
272,
408,
272,
8775,
63,
576,
63,
498,
275,
283,
84,
17,
14,
7112,
7,
272,
5793,
63,
576,
63,
498,
275,
283,
84,
17,
14,
4711,
7,
272,
8775,
63,
1250,
63,
835,
275,
378,
339,
768,
3744,
272,
347,
8775,
8,
1886,
12,
1853,
63,
6976,
304,
267,
408,
267,
19649,
83,
1853,
666,
367,
314,
1853,
5523,
14,
267,
408,
267,
843,
423,
409,
63,
1457,
63,
1459,
8,
1457,
63,
6976,
12,
843,
14,
7112,
63,
576,
63,
498,
9,
267,
843,
14,
7112,
63,
1250,
63,
835,
847,
413,
339,
347,
5793,
8,
277,
12,
4503,
63,
815,
12,
1853,
63,
6976,
304,
267,
408,
267,
6266,
3351,
314,
1853,
5523,
14,
267,
408,
267,
291,
423,
409,
63,
1457,
63,
1459,
8,
1457,
63,
6976,
12,
291,
14,
4711,
63,
576,
63,
498,
9,
339,
768,
3744,
272,
347,
702,
63,
22766,
8,
1886,
12,
1853,
63,
6976,
304,
267,
408,
267,
10716,
83,
666,
1990,
13736,
367,
314,
1853,
5523,
14,
267,
408,
267,
843,
423,
479,
63,
1457,
63,
1459,
8,
1457,
63,
6976,
12,
843,
14,
7112,
63,
576,
63,
498,
9,
339,
768,
3744,
272,
347,
702,
63,
20209,
8,
1886,
12,
1853,
63,
6976,
304,
267,
408,
267,
10716,
83,
314,
1853,
5523,
1990,
14834,
14,
267,
408,
267,
843,
423,
479,
63,
1457,
63,
1459,
8,
1457,
63,
6976,
12,
843,
14,
4711,
63,
576,
63,
498,
9,
339,
768,
3744,
272,
347,
485,
409,
63,
1457,
63,
1459,
8,
1886,
12,
1853,
63,
6976,
12,
666,
63,
498,
304,
267,
408,
267,
10729,
282,
574,
367,
1924,
1853,
315,
314,
1627,
5523,
12,
1808,
314,
1627,
267,
666,
790,
14,
267,
408,
267,
367,
1853,
63,
498,
315,
1853,
63,
6976,
14,
16851,
7954,
63,
1239,
16222,
837,
288,
1853,
63,
6976,
14,
409,
63,
19754,
63,
1457,
63,
698,
8,
355,
1853,
63,
498,
12,
843,
12,
666,
63,
498,
12,
843,
423,
981,
63,
1457,
63,
585,
8,
1457,
63,
498,
12,
666,
63,
498,
9,
288,
776,
339,
768,
3744,
272,
347,
485,
479,
63,
1457,
63,
1459,
8,
1886,
12,
1853,
63,
6976,
12,
666,
63,
498,
304,
267,
408,
267,
26114,
314,
574,
367,
1924,
1853,
315,
314,
1627,
5523,
12,
367,
314,
1627,
267,
666,
790,
14,
267,
408,
267,
367,
1853,
63,
498,
315,
1853,
63,
6976,
14,
16851,
7954,
63,
1239,
16222,
837,
288,
702,
334,
355,
1853,
63,
6976,
14,
362,
63,
19754,
63,
1457,
63,
698,
8,
490,
1853,
63,
498,
12,
490,
843,
12,
490,
666,
63,
498,
12,
355,
776,
508,
843,
423,
981,
63,
1457,
63,
585,
8,
1457,
63,
498,
12,
666,
63,
498,
9,
288,
776,
339,
768,
3744,
272,
347,
485,
981,
63,
1457,
63,
585,
8,
1886,
12,
1853,
63,
498,
12,
666,
63,
498,
304,
267,
408,
267,
1803,
282,
3747,
25286,
574,
367,
314,
1627,
1853,
790,
267,
436,
666,
790,
14,
267,
408,
267,
372,
666,
63,
498,
435,
283,
84,
17,
14,
637,
17,
3530,
435,
2649,
8,
1457,
63,
498,
9,
421,
199,
32,
962,
8,
10810,
29,
18,
9,
199,
32,
11138,
14,
11138,
199,
533,
1379,
3142,
10766,
2988,
8,
7692,
1197,
2927,
4256,
12,
12988,
828,
2956,
22060,
12,
7640,
304,
272,
408,
272,
1379,
1021,
367,
8651,
10766,
2988,
14,
272,
408,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
3142,
10766,
2988,
12,
291,
680,
5996,
342,
398,
1379,
19761,
17,
14,
7112,
63,
1250,
63,
835,
275,
378,
267,
291,
14,
11616,
63,
1515,
22932,
275,
359,
774,
19761,
17,
5106,
267,
543,
1683,
63,
11616,
63,
1515,
22932,
8,
277,
14,
11616,
63,
1515,
22932,
304,
288,
291,
14,
1515,
22932,
275,
8651,
10766,
3188,
22932,
8,
277,
14,
11616,
63,
1515,
22932,
9,
398,
291,
14,
3223,
63,
1130,
275,
291,
14,
27548,
63,
1244,
1193,
4564,
742,
63,
5443,
267,
291,
14,
10012,
275,
4420,
2377,
1617,
2927,
14,
981,
8,
277,
14,
3223,
63,
1130,
12,
291,
14,
1457,
63,
498,
63,
3702,
9,
267,
291,
14,
1637,
275,
4420,
4437,
342,
267,
291,
14,
1533,
63,
2609,
275,
8651,
10766,
2988,
8,
277,
14,
1457,
63,
498,
63,
3702,
8,
16,
395,
291,
14,
10012,
12,
291,
14,
1637,
9,
339,
347,
8775,
63,
460,
63,
4712,
8,
277,
12,
4282,
63,
10012,
63,
3527,
12,
4282,
63,
1637,
63,
5334,
304,
267,
408,
267,
28055,
314,
5256,
1159,
664,
63,
22766,
1083,
436,
22694,
2399,
754,
267,
436,
5953,
14,
267,
408,
267,
291,
14,
10012,
14,
362,
63,
1744,
63,
1250,
63,
835,
275,
378,
267,
291,
14,
1637,
14,
409,
63,
1250,
63,
835,
275,
378,
267,
543,
1683,
63,
11616,
63,
1515,
22932,
8,
277,
14,
11616,
63,
1515,
22932,
304,
288,
1853,
63,
6976,
275,
291,
14,
1533,
63,
2609,
14,
362,
63,
22766,
342,
267,
291,
14,
479,
63,
1457,
63,
6976,
8,
1457,
63,
6976,
12,
291,
14,
3223,
63,
1130,
9,
267,
1379,
19761,
17,
14,
479,
63,
22766,
8,
1457,
63,
6976,
9,
267,
340,
4282,
63,
10012
] |
[
199,
2925,
367,
5256,
14,
647,
199,
624,
199,
646,
366,
3583,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
504,
2882,
492,
7640,
199,
199,
504,
2508,
1457,
63,
6976,
492,
8651,
10766,
3142,
1451,
199,
504,
2508,
888,
492,
31632,
4971,
63,
3170,
63,
9792,
742,
63,
4609,
63,
13945,
12,
4384,
726,
2962,
63,
7111,
1206,
63,
2707,
63,
8677,
12,
336,
9181,
274,
199,
504,
2508,
3924,
492,
11028,
1197,
1763,
607,
3142,
10766,
12,
8651,
10766,
4667,
199,
504,
2508,
2609,
492,
8651,
10766,
2988,
199,
504,
2508,
1515,
22932,
492,
8651,
10766,
3188,
22932,
199,
504,
1275,
7546,
492,
334,
272,
4420,
2377,
1617,
2927,
12,
4420,
4437,
12,
4420,
19761,
12,
272,
12988,
828,
2956,
22060,
12,
11028,
1197,
2927,
4256,
12,
272,
1683,
63,
11616,
63,
1515,
22932,
12,
199,
9,
421,
199,
533,
1379,
19761,
17,
8,
3346,
19761,
304,
272,
408,
272,
1379,
30486,
1021,
543,
5678,
9330,
370,
4911,
13736,
436,
272,
14834,
666,
14,
272,
408,
272,
8775,
63,
576,
63,
498,
275,
283,
84,
17,
14,
7112,
7,
272,
5793,
63,
576,
63,
498,
275,
283,
84,
17,
14,
4711,
7,
272,
8775,
63,
1250,
63,
835,
275,
378,
339,
768,
3744,
272,
347,
8775,
8,
1886,
12,
1853,
63,
6976,
304,
267,
408,
267,
19649,
83,
1853,
666,
367,
314,
1853,
5523,
14,
267,
408,
267,
843,
423,
409,
63,
1457,
63,
1459,
8,
1457,
63,
6976,
12,
843,
14,
7112,
63,
576,
63,
498,
9,
267,
843,
14,
7112,
63,
1250,
63,
835,
847,
413,
339,
347,
5793,
8,
277,
12,
4503,
63,
815,
12,
1853,
63,
6976,
304,
267,
408,
267,
6266,
3351,
314,
1853,
5523,
14,
267,
408,
267,
291,
423,
409,
63,
1457,
63,
1459,
8,
1457,
63,
6976,
12,
291,
14,
4711,
63,
576,
63,
498,
9,
339,
768,
3744,
272,
347,
702,
63,
22766,
8,
1886,
12,
1853,
63,
6976,
304,
267,
408,
267,
10716,
83,
666,
1990,
13736,
367,
314,
1853,
5523,
14,
267,
408,
267,
843,
423,
479,
63,
1457,
63,
1459,
8,
1457,
63,
6976,
12,
843,
14,
7112,
63,
576,
63,
498,
9,
339,
768,
3744,
272,
347,
702,
63,
20209,
8,
1886,
12,
1853,
63,
6976,
304,
267,
408,
267,
10716,
83,
314,
1853,
5523,
1990,
14834,
14,
267,
408,
267,
843,
423,
479,
63,
1457,
63,
1459,
8,
1457,
63,
6976,
12,
843,
14,
4711,
63,
576,
63,
498,
9,
339,
768,
3744,
272,
347,
485,
409,
63,
1457,
63,
1459,
8,
1886,
12,
1853,
63,
6976,
12,
666,
63,
498,
304,
267,
408,
267,
10729,
282,
574,
367,
1924,
1853,
315,
314,
1627,
5523,
12,
1808,
314,
1627,
267,
666,
790,
14,
267,
408,
267,
367,
1853,
63,
498,
315,
1853,
63,
6976,
14,
16851,
7954,
63,
1239,
16222,
837,
288,
1853,
63,
6976,
14,
409,
63,
19754,
63,
1457,
63,
698,
8,
355,
1853,
63,
498,
12,
843,
12,
666,
63,
498,
12,
843,
423,
981,
63,
1457,
63,
585,
8,
1457,
63,
498,
12,
666,
63,
498,
9,
288,
776,
339,
768,
3744,
272,
347,
485,
479,
63,
1457,
63,
1459,
8,
1886,
12,
1853,
63,
6976,
12,
666,
63,
498,
304,
267,
408,
267,
26114,
314,
574,
367,
1924,
1853,
315,
314,
1627,
5523,
12,
367,
314,
1627,
267,
666,
790,
14,
267,
408,
267,
367,
1853,
63,
498,
315,
1853,
63,
6976,
14,
16851,
7954,
63,
1239,
16222,
837,
288,
702,
334,
355,
1853,
63,
6976,
14,
362,
63,
19754,
63,
1457,
63,
698,
8,
490,
1853,
63,
498,
12,
490,
843,
12,
490,
666,
63,
498,
12,
355,
776,
508,
843,
423,
981,
63,
1457,
63,
585,
8,
1457,
63,
498,
12,
666,
63,
498,
9,
288,
776,
339,
768,
3744,
272,
347,
485,
981,
63,
1457,
63,
585,
8,
1886,
12,
1853,
63,
498,
12,
666,
63,
498,
304,
267,
408,
267,
1803,
282,
3747,
25286,
574,
367,
314,
1627,
1853,
790,
267,
436,
666,
790,
14,
267,
408,
267,
372,
666,
63,
498,
435,
283,
84,
17,
14,
637,
17,
3530,
435,
2649,
8,
1457,
63,
498,
9,
421,
199,
32,
962,
8,
10810,
29,
18,
9,
199,
32,
11138,
14,
11138,
199,
533,
1379,
3142,
10766,
2988,
8,
7692,
1197,
2927,
4256,
12,
12988,
828,
2956,
22060,
12,
7640,
304,
272,
408,
272,
1379,
1021,
367,
8651,
10766,
2988,
14,
272,
408,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
3142,
10766,
2988,
12,
291,
680,
5996,
342,
398,
1379,
19761,
17,
14,
7112,
63,
1250,
63,
835,
275,
378,
267,
291,
14,
11616,
63,
1515,
22932,
275,
359,
774,
19761,
17,
5106,
267,
543,
1683,
63,
11616,
63,
1515,
22932,
8,
277,
14,
11616,
63,
1515,
22932,
304,
288,
291,
14,
1515,
22932,
275,
8651,
10766,
3188,
22932,
8,
277,
14,
11616,
63,
1515,
22932,
9,
398,
291,
14,
3223,
63,
1130,
275,
291,
14,
27548,
63,
1244,
1193,
4564,
742,
63,
5443,
267,
291,
14,
10012,
275,
4420,
2377,
1617,
2927,
14,
981,
8,
277,
14,
3223,
63,
1130,
12,
291,
14,
1457,
63,
498,
63,
3702,
9,
267,
291,
14,
1637,
275,
4420,
4437,
342,
267,
291,
14,
1533,
63,
2609,
275,
8651,
10766,
2988,
8,
277,
14,
1457,
63,
498,
63,
3702,
8,
16,
395,
291,
14,
10012,
12,
291,
14,
1637,
9,
339,
347,
8775,
63,
460,
63,
4712,
8,
277,
12,
4282,
63,
10012,
63,
3527,
12,
4282,
63,
1637,
63,
5334,
304,
267,
408,
267,
28055,
314,
5256,
1159,
664,
63,
22766,
1083,
436,
22694,
2399,
754,
267,
436,
5953,
14,
267,
408,
267,
291,
14,
10012,
14,
362,
63,
1744,
63,
1250,
63,
835,
275,
378,
267,
291,
14,
1637,
14,
409,
63,
1250,
63,
835,
275,
378,
267,
543,
1683,
63,
11616,
63,
1515,
22932,
8,
277,
14,
11616,
63,
1515,
22932,
304,
288,
1853,
63,
6976,
275,
291,
14,
1533,
63,
2609,
14,
362,
63,
22766,
342,
267,
291,
14,
479,
63,
1457,
63,
6976,
8,
1457,
63,
6976,
12,
291,
14,
3223,
63,
1130,
9,
267,
1379,
19761,
17,
14,
479,
63,
22766,
8,
1457,
63,
6976,
9,
267,
340,
4282,
63,
10012,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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licenses/LICENSE-2.0 <see LICENSE file>
from datetime import datetime
from freezegun import freeze_time
from ggrc import db
from ggrc_workflows.models import Cycle
from ggrc_workflows.models import CycleTaskGroupObjectTask
from ggrc_workflows.models import TaskGroup
from ggrc_workflows.models import Workflow
from integration.ggrc import TestCase
from integration.ggrc_workflows.generator import WorkflowsGenerator
from integration.ggrc.api_helper import Api
from integration.ggrc.generator import ObjectGenerator
from integration.ggrc.models import factories
class TestBasicWorkflowActions(TestCase):
def setUp(self):
super(TestBasicWorkflowActions, self).setUp()
self.api = Api()
self.generator = WorkflowsGenerator()
self.object_generator = ObjectGenerator()
self.random_objects = self.object_generator.generate_random_objects()
self.create_test_cases()
def tearDown(self):
pass
def test_create_workflows(self):
_, wflow = self.generator.generate_workflow(self.one_time_workflow_1)
self.assertIsInstance(wflow, Workflow)
task_groups = db.session.query(TaskGroup)\
.filter(TaskGroup.workflow_id == wflow.id).all()
self.assertEqual(len(task_groups),
len(self.one_time_workflow_1["task_groups"]))
def test_workflows(self):
for workflow in self.all_workflows:
_, wflow = self.generator.generate_workflow(workflow)
self.assertIsInstance(wflow, Workflow)
task_groups = db.session.query(TaskGroup)\
.filter(TaskGroup.workflow_id == wflow.id).all()
self.assertEqual(len(task_groups),
len(workflow["task_groups"]))
def test_activate_wf(self):
for workflow in self.all_workflows:
_, wflow = self.generator.generate_workflow(workflow)
response, wflow = self.generator.activate_workflow(wflow)
self.assert200(response)
def test_one_time_workflow_edits(self):
_, wflow = self.generator.generate_workflow(self.one_time_workflow_1)
wf_dict = {"title": "modified one time wf"}
self.generator.modify_workflow(wflow, data=wf_dict)
modified_wf = db.session.query(Workflow).filter(
Workflow.id == wflow.id).one()
self.assertEqual(wf_dict["title"], modified_wf.title)
def test_one_time_wf_activate(self):
_, wflow = self.generator.generate_workflow(self.one_time_workflow_1)
self.generator.generate_cycle(wflow)
self.generator.activate_workflow(wflow)
tasks = [len(tg.get("task_group_tasks", []))
for tg in self.one_time_workflow_1["task_groups"]]
cycle_tasks = db.session.query(CycleTaskGroupObjectTask).join(
Cycle).join(Workflow).filter(Workflow.id == wflow.id).all()
active_wf = db.session.query(Workflow).filter(
Workflow.id == wflow.id).one()
self.assertEqual(sum(tasks), len(cycle_tasks))
self.assertEqual(active_wf.status, "Active")
def test_one_time_wf_state_transition_dates(self):
_, wflow = self.generator.generate_workflow(self.one_time_workflow_1)
self.generator.generate_cycle(wflow)
self.generator.activate_workflow(wflow)
cycle_tasks = db.session.query(CycleTaskGroupObjectTask).join(
Cycle).join(Workflow).filter(Workflow.id == wflow.id).all()
with freeze_time("2015-6-9 13:00:00"):
today = datetime.now()
transitions = [
("InProgress", None, None),
("Finished", today, None),
("Declined", None, None),
("Finished", today, None),
("Verified", today, today),
("Finished", today, None),
]
# Iterate over possible transitions and check if dates got set correctly
for (status, expected_finished, expected_verified) in transitions:
cycle_task = cycle_tasks[0]
_, task = self.generator.modify_object(cycle_task, {"status": status})
self.assertEqual(task.finished_date, expected_finished)
self.assertEqual(task.verified_date, expected_verified)
def test_delete_calls(self):
_, workflow = self.generator.generate_workflow()
self.generator.generate_task_group(workflow)
_, task_group = self.generator.generate_task_group(workflow)
task_groups = db.session.query(TaskGroup).filter(
TaskGroup.workflow_id == workflow.id).all()
self.assertEqual(len(task_groups), 2)
response = self.generator.api.delete(task_group)
self.assert200(response)
task_groups = db.session.query(TaskGroup).filter(
TaskGroup.workflow_id == workflow.id).all()
self.assertEqual(len(task_groups), 1)
def create_test_cases(self):
self.quarterly_wf_1 = {
"title": "quarterly wf 1",
"description": "",
"frequency": "quarterly",
"task_groups": [{
"title": "tg_1",
"task_group_tasks": [{
"description": factories.random_str(100),
"relative_start_day": 5,
"relative_start_month": 1,
"relative_end_day": 25,
"relative_end_month": 2,
}, {
"description": factories.random_str(100),
"relative_start_day": 15,
"relative_start_month": 2,
"relative_end_day": 28,
"relative_end_month": 2,
}, {
"description": factories.random_str(100),
"relative_start_day": 1,
"relative_start_month": 1,
"relative_end_day": 1,
"relative_end_month": 1,
},
],
},
]
}
self.weekly_wf_1 = {
"title": "weekly thingy",
"description": "start this many a time",
"frequency": "weekly",
"task_groups": [{
"title": "tg_2",
"task_group_tasks": [{
"description": factories.random_str(100),
"relative_end_day": 1,
"relative_end_month": None,
"relative_start_day": 5,
"relative_start_month": None,
}, {
"title": "monday task",
"relative_end_day": 1,
"relative_end_month": None,
"relative_start_day": 1,
"relative_start_month": None,
}, {
"title": "weekend task",
"relative_end_day": 4,
"relative_end_month": None,
"relative_start_day": 1,
"relative_start_month": None,
},
],
"task_group_objects": self.random_objects
},
]
}
self.one_time_workflow_1 = {
"title": "one time wf test",
"description": "some test workflow",
"task_groups": [{
"title": "tg_1",
"task_group_tasks": [{}, {}, {}]
}, {
"title": "tg_2",
"task_group_tasks": [{
"description": factories.random_str(100)
}, {}
],
"task_group_objects": self.random_objects[:2]
}, {
"title": "tg_3",
"task_group_tasks": [{
"title": "simple task 1",
"description": factories.random_str(100)
}, {
"title": factories.random_str(),
"description": factories.random_str(100)
}, {
"title": factories.random_str(),
"description": factories.random_str(100)
}
],
"task_group_objects": self.random_objects
}
]
}
self.one_time_workflow_2 = {
"title": "test_wf_title",
"description": "some test workflow",
"task_groups": [
{
"title": "tg_1",
"task_group_tasks": [{}, {}, {}]
},
{
"title": "tg_2",
"task_group_tasks": [{
"description": factories.random_str(100)
}, {}],
"task_group_objects": self.random_objects[:2]
},
{
"title": "tg_3",
"task_group_tasks": [{
"title": "simple task 1",
"description": factories.random_str(100)
}, {
"title": factories.random_str(),
"description": factories.random_str(100)
}, {
"title": factories.random_str(),
"description": factories.random_str(100)
}],
"task_group_objects": []
}
]
}
self.monthly_workflow_1 = {
"title": "monthly test wf",
"description": "start this many a time",
"frequency": "monthly",
"task_groups": [
{
"title": "tg_2",
"task_group_tasks": [{
"description": factories.random_str(100),
"relative_end_day": 1,
"relative_end_month": None,
"relative_start_day": 5,
"relative_start_month": None,
}, {
"title": "monday task",
"relative_end_day": 1,
"relative_end_month": None,
"relative_start_day": 1,
"relative_start_month": None,
}, {
"title": "weekend task",
"relative_end_day": 4,
"relative_end_month": None,
"relative_start_day": 1,
"relative_start_month": None,
}],
"task_group_objects": self.random_objects
},
]
}
self.all_workflows = [
self.one_time_workflow_1,
self.one_time_workflow_2,
self.weekly_wf_1,
self.monthly_workflow_1,
self.quarterly_wf_1,
]
|
apache-2.0
|
[
3,
1898,
334,
35,
9,
9708,
4475,
3277,
14,
199,
3,
3909,
1334,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
665,
3239,
5113,
570,
30,
199,
199,
504,
2197,
492,
2197,
199,
504,
22778,
17924,
492,
22778,
63,
521,
199,
199,
504,
486,
71,
1195,
492,
1592,
199,
504,
486,
71,
1195,
63,
25964,
14,
992,
492,
18461,
2265,
199,
504,
486,
71,
1195,
63,
25964,
14,
992,
492,
18461,
2265,
4476,
2448,
1692,
4476,
199,
504,
486,
71,
1195,
63,
25964,
14,
992,
492,
8495,
2448,
199,
504,
486,
71,
1195,
63,
25964,
14,
992,
492,
27282,
199,
504,
13150,
14,
2721,
1195,
492,
7640,
199,
504,
13150,
14,
2721,
1195,
63,
25964,
14,
4679,
492,
9361,
22777,
7599,
199,
504,
13150,
14,
2721,
1195,
14,
1246,
63,
3676,
492,
13986,
199,
504,
13150,
14,
2721,
1195,
14,
4679,
492,
6935,
7599,
199,
504,
13150,
14,
2721,
1195,
14,
992,
492,
22115,
421,
199,
533,
1379,
6845,
17527,
9303,
8,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
1613,
8,
774,
6845,
17527,
9303,
12,
291,
680,
5996,
342,
272,
291,
14,
1246,
275,
13986,
342,
272,
291,
14,
4679,
275,
9361,
22777,
7599,
342,
272,
291,
14,
785,
63,
4679,
275,
6935,
7599,
342,
339,
291,
14,
2355,
63,
1462,
275,
291,
14,
785,
63,
4679,
14,
4208,
63,
2355,
63,
1462,
342,
272,
291,
14,
981,
63,
396,
63,
9403,
342,
819,
347,
6766,
8,
277,
304,
272,
986,
819,
347,
511,
63,
981,
63,
25964,
8,
277,
304,
272,
5501,
336,
1659,
275,
291,
14,
4679,
14,
4208,
63,
8856,
8,
277,
14,
368,
63,
521,
63,
8856,
63,
17,
9,
272,
291,
14,
6926,
8,
87,
1659,
12,
27282,
9,
339,
2120,
63,
2634,
275,
1592,
14,
1730,
14,
1131,
8,
4476,
2448,
2862,
267,
1275,
1541,
8,
4476,
2448,
14,
8856,
63,
344,
508,
336,
1659,
14,
344,
680,
452,
342,
339,
291,
14,
629,
8,
552,
8,
1765,
63,
2634,
395,
2151,
822,
8,
277,
14,
368,
63,
521,
63,
8856,
63,
17,
905,
1765,
63,
2634,
13045,
819,
347,
511,
63,
25964,
8,
277,
304,
272,
367,
10431,
315,
291,
14,
452,
63,
25964,
26,
489,
5501,
336,
1659,
275,
291,
14,
4679,
14,
4208,
63,
8856,
8,
8856,
9,
489,
291,
14,
6926,
8,
87,
1659,
12,
27282,
9,
2541,
2120,
63,
2634,
275,
1592,
14,
1730,
14,
1131,
8,
4476,
2448,
2862,
881,
1275,
1541,
8,
4476,
2448,
14,
8856,
63,
344,
508,
336,
1659,
14,
344,
680,
452,
342,
2541,
291,
14,
629,
8,
552,
8,
1765,
63,
2634,
395,
2432,
822,
8,
8856,
905,
1765,
63,
2634,
13045,
819,
347,
511,
63,
8222,
63,
14114,
8,
277,
304,
272,
367,
10431,
315,
291,
14,
452,
63,
25964,
26,
489,
5501,
336,
1659,
275,
291,
14,
4679,
14,
4208,
63,
8856,
8,
8856,
9,
489,
1177,
12,
336,
1659,
275,
291,
14,
4679,
14,
8222,
63,
8856,
8,
87,
1659,
9,
2541,
291,
14,
479,
1840,
8,
1310,
9,
819,
347,
511,
63,
368,
63,
521,
63,
8856,
63,
6297,
1086,
8,
277,
304,
272,
5501,
336,
1659,
275,
291,
14,
4679,
14,
4208,
63,
8856,
8,
277,
14,
368,
63,
521,
63,
8856,
63,
17,
9,
339,
17328,
63,
807,
275,
2420,
1213,
582,
298,
5540,
1373,
900,
17328,
3570,
272,
291,
14,
4679,
14,
8951,
63,
8856,
8,
87,
1659,
12,
666,
29,
14114,
63,
807,
9,
339,
6042,
63,
14114,
275,
1592,
14,
1730,
14,
1131,
8,
17527,
680,
1541,
8,
267,
27282,
14,
344,
508,
336,
1659,
14,
344,
680,
368,
342,
272,
291,
14,
629,
8,
14114,
63,
807,
905,
1213,
2255,
6042,
63,
14114,
14,
1213,
9,
819,
347,
511,
63,
368,
63,
521,
63,
14114,
63,
8222,
8,
277,
304,
272,
5501,
336,
1659,
275,
291,
14,
4679,
14,
4208,
63,
8856,
8,
277,
14,
368,
63,
521,
63,
8856,
63,
17,
9,
272,
291,
14,
4679,
14,
4208,
63,
7612,
8,
87,
1659,
9,
272,
291,
14,
4679,
14,
8222,
63,
8856,
8,
87,
1659,
9,
339,
6527,
275,
359,
552,
8,
17699,
14,
362,
480,
1765,
63,
923,
63,
5054,
401,
15927,
1467,
367,
22387,
315,
291,
14,
368,
63,
521,
63,
8856,
63,
17,
905,
1765,
63,
2634,
15261,
339,
8643,
63,
5054,
275,
1592,
14,
1730,
14,
1131,
8,
15302,
4476,
2448,
1692,
4476,
680,
904,
8,
267,
18461,
2265,
680,
904,
8,
17527,
680,
1541,
8,
17527,
14,
344,
508,
336,
1659,
14,
344,
680,
452,
342,
272,
4702,
63,
14114,
275,
1592,
14,
1730,
14,
1131,
8,
17527,
680,
1541,
8,
267,
27282,
14,
344,
508,
336,
1659,
14,
344,
680,
368,
342,
339,
291,
14,
629,
8,
1838,
8,
5054,
395,
822,
8,
7612,
63,
5054,
430,
272,
291,
14,
629,
8,
2682,
63,
14114,
14,
1205,
12,
298,
7472,
531,
819,
347,
511,
63,
368,
63,
521,
63,
14114,
63,
929,
63,
14143,
63,
9356,
8,
277,
304,
272,
5501,
336,
1659,
275,
291,
14,
4679,
14,
4208,
63,
8856,
8,
277,
14,
368,
63,
521,
63,
8856,
63,
17,
9,
272,
291,
14,
4679,
14,
4208,
63,
7612,
8,
87,
1659,
9,
272,
291,
14,
4679,
14,
8222,
63,
8856,
8,
87,
1659,
9,
339,
8643,
63,
5054,
275,
1592,
14,
1730,
14,
1131,
8,
15302,
4476,
2448,
1692,
4476,
680,
904,
8,
267,
18461,
2265,
680,
904,
8,
17527,
680,
1541,
8,
17527,
14,
344,
508,
336,
1659,
14,
344,
680,
452,
342,
272,
543,
22778,
63,
521,
480,
7806,
13,
22,
13,
25,
4944,
26,
383,
26,
383,
2349,
489,
11168,
275,
2197,
14,
2131,
342,
489,
19077,
275,
359,
881,
1689,
607,
11504,
401,
488,
12,
488,
395,
881,
1689,
13430,
401,
11168,
12,
488,
395,
881,
1689,
20856,
1942,
401,
488,
12,
488,
395,
881,
1689,
13430,
401,
11168,
12,
488,
395,
881,
1689,
3673,
4541,
401,
11168,
12,
11168,
395,
881,
1689,
13430,
401,
11168,
12,
488,
395,
489,
1622,
489,
327,
23989,
1806,
3962,
19077,
436,
1104,
340,
10831,
4788,
663,
6657,
489,
367,
334,
1205,
12,
1420,
63,
8669,
12,
1420
] |
[
1898,
334,
35,
9,
9708,
4475,
3277,
14,
199,
3,
3909,
1334,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
665,
3239,
5113,
570,
30,
199,
199,
504,
2197,
492,
2197,
199,
504,
22778,
17924,
492,
22778,
63,
521,
199,
199,
504,
486,
71,
1195,
492,
1592,
199,
504,
486,
71,
1195,
63,
25964,
14,
992,
492,
18461,
2265,
199,
504,
486,
71,
1195,
63,
25964,
14,
992,
492,
18461,
2265,
4476,
2448,
1692,
4476,
199,
504,
486,
71,
1195,
63,
25964,
14,
992,
492,
8495,
2448,
199,
504,
486,
71,
1195,
63,
25964,
14,
992,
492,
27282,
199,
504,
13150,
14,
2721,
1195,
492,
7640,
199,
504,
13150,
14,
2721,
1195,
63,
25964,
14,
4679,
492,
9361,
22777,
7599,
199,
504,
13150,
14,
2721,
1195,
14,
1246,
63,
3676,
492,
13986,
199,
504,
13150,
14,
2721,
1195,
14,
4679,
492,
6935,
7599,
199,
504,
13150,
14,
2721,
1195,
14,
992,
492,
22115,
421,
199,
533,
1379,
6845,
17527,
9303,
8,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
1613,
8,
774,
6845,
17527,
9303,
12,
291,
680,
5996,
342,
272,
291,
14,
1246,
275,
13986,
342,
272,
291,
14,
4679,
275,
9361,
22777,
7599,
342,
272,
291,
14,
785,
63,
4679,
275,
6935,
7599,
342,
339,
291,
14,
2355,
63,
1462,
275,
291,
14,
785,
63,
4679,
14,
4208,
63,
2355,
63,
1462,
342,
272,
291,
14,
981,
63,
396,
63,
9403,
342,
819,
347,
6766,
8,
277,
304,
272,
986,
819,
347,
511,
63,
981,
63,
25964,
8,
277,
304,
272,
5501,
336,
1659,
275,
291,
14,
4679,
14,
4208,
63,
8856,
8,
277,
14,
368,
63,
521,
63,
8856,
63,
17,
9,
272,
291,
14,
6926,
8,
87,
1659,
12,
27282,
9,
339,
2120,
63,
2634,
275,
1592,
14,
1730,
14,
1131,
8,
4476,
2448,
2862,
267,
1275,
1541,
8,
4476,
2448,
14,
8856,
63,
344,
508,
336,
1659,
14,
344,
680,
452,
342,
339,
291,
14,
629,
8,
552,
8,
1765,
63,
2634,
395,
2151,
822,
8,
277,
14,
368,
63,
521,
63,
8856,
63,
17,
905,
1765,
63,
2634,
13045,
819,
347,
511,
63,
25964,
8,
277,
304,
272,
367,
10431,
315,
291,
14,
452,
63,
25964,
26,
489,
5501,
336,
1659,
275,
291,
14,
4679,
14,
4208,
63,
8856,
8,
8856,
9,
489,
291,
14,
6926,
8,
87,
1659,
12,
27282,
9,
2541,
2120,
63,
2634,
275,
1592,
14,
1730,
14,
1131,
8,
4476,
2448,
2862,
881,
1275,
1541,
8,
4476,
2448,
14,
8856,
63,
344,
508,
336,
1659,
14,
344,
680,
452,
342,
2541,
291,
14,
629,
8,
552,
8,
1765,
63,
2634,
395,
2432,
822,
8,
8856,
905,
1765,
63,
2634,
13045,
819,
347,
511,
63,
8222,
63,
14114,
8,
277,
304,
272,
367,
10431,
315,
291,
14,
452,
63,
25964,
26,
489,
5501,
336,
1659,
275,
291,
14,
4679,
14,
4208,
63,
8856,
8,
8856,
9,
489,
1177,
12,
336,
1659,
275,
291,
14,
4679,
14,
8222,
63,
8856,
8,
87,
1659,
9,
2541,
291,
14,
479,
1840,
8,
1310,
9,
819,
347,
511,
63,
368,
63,
521,
63,
8856,
63,
6297,
1086,
8,
277,
304,
272,
5501,
336,
1659,
275,
291,
14,
4679,
14,
4208,
63,
8856,
8,
277,
14,
368,
63,
521,
63,
8856,
63,
17,
9,
339,
17328,
63,
807,
275,
2420,
1213,
582,
298,
5540,
1373,
900,
17328,
3570,
272,
291,
14,
4679,
14,
8951,
63,
8856,
8,
87,
1659,
12,
666,
29,
14114,
63,
807,
9,
339,
6042,
63,
14114,
275,
1592,
14,
1730,
14,
1131,
8,
17527,
680,
1541,
8,
267,
27282,
14,
344,
508,
336,
1659,
14,
344,
680,
368,
342,
272,
291,
14,
629,
8,
14114,
63,
807,
905,
1213,
2255,
6042,
63,
14114,
14,
1213,
9,
819,
347,
511,
63,
368,
63,
521,
63,
14114,
63,
8222,
8,
277,
304,
272,
5501,
336,
1659,
275,
291,
14,
4679,
14,
4208,
63,
8856,
8,
277,
14,
368,
63,
521,
63,
8856,
63,
17,
9,
272,
291,
14,
4679,
14,
4208,
63,
7612,
8,
87,
1659,
9,
272,
291,
14,
4679,
14,
8222,
63,
8856,
8,
87,
1659,
9,
339,
6527,
275,
359,
552,
8,
17699,
14,
362,
480,
1765,
63,
923,
63,
5054,
401,
15927,
1467,
367,
22387,
315,
291,
14,
368,
63,
521,
63,
8856,
63,
17,
905,
1765,
63,
2634,
15261,
339,
8643,
63,
5054,
275,
1592,
14,
1730,
14,
1131,
8,
15302,
4476,
2448,
1692,
4476,
680,
904,
8,
267,
18461,
2265,
680,
904,
8,
17527,
680,
1541,
8,
17527,
14,
344,
508,
336,
1659,
14,
344,
680,
452,
342,
272,
4702,
63,
14114,
275,
1592,
14,
1730,
14,
1131,
8,
17527,
680,
1541,
8,
267,
27282,
14,
344,
508,
336,
1659,
14,
344,
680,
368,
342,
339,
291,
14,
629,
8,
1838,
8,
5054,
395,
822,
8,
7612,
63,
5054,
430,
272,
291,
14,
629,
8,
2682,
63,
14114,
14,
1205,
12,
298,
7472,
531,
819,
347,
511,
63,
368,
63,
521,
63,
14114,
63,
929,
63,
14143,
63,
9356,
8,
277,
304,
272,
5501,
336,
1659,
275,
291,
14,
4679,
14,
4208,
63,
8856,
8,
277,
14,
368,
63,
521,
63,
8856,
63,
17,
9,
272,
291,
14,
4679,
14,
4208,
63,
7612,
8,
87,
1659,
9,
272,
291,
14,
4679,
14,
8222,
63,
8856,
8,
87,
1659,
9,
339,
8643,
63,
5054,
275,
1592,
14,
1730,
14,
1131,
8,
15302,
4476,
2448,
1692,
4476,
680,
904,
8,
267,
18461,
2265,
680,
904,
8,
17527,
680,
1541,
8,
17527,
14,
344,
508,
336,
1659,
14,
344,
680,
452,
342,
272,
543,
22778,
63,
521,
480,
7806,
13,
22,
13,
25,
4944,
26,
383,
26,
383,
2349,
489,
11168,
275,
2197,
14,
2131,
342,
489,
19077,
275,
359,
881,
1689,
607,
11504,
401,
488,
12,
488,
395,
881,
1689,
13430,
401,
11168,
12,
488,
395,
881,
1689,
20856,
1942,
401,
488,
12,
488,
395,
881,
1689,
13430,
401,
11168,
12,
488,
395,
881,
1689,
3673,
4541,
401,
11168,
12,
11168,
395,
881,
1689,
13430,
401,
11168,
12,
488,
395,
489,
1622,
489,
327,
23989,
1806,
3962,
19077,
436,
1104,
340,
10831,
4788,
663,
6657,
489,
367,
334,
1205,
12,
1420,
63,
8669,
12,
1420,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ShyamSS-95/Bolt
|
bolt/lib/nonlinear/tests/performance/performance_solver_components.py
|
1
|
1333
|
import arrayfire as af
import numpy as np
import pylab as pl
from bolt.lib.physical_system import physical_system
from bolt.lib.nonlinear_solver.nonlinear_solver \
import nonlinear_solver
from bolt.lib.nonlinear_solver.tests.performance.input_files \
import domain
from bolt.lib.nonlinear_solver.tests.performance.input_files \
import boundary_conditions
from bolt.lib.nonlinear_solver.tests.performance.input_files \
import params
from bolt.lib.nonlinear_solver.tests.performance.input_files \
import initialize
import bolt.src.nonrelativistic_boltzmann.advection_terms as advection_terms
import bolt.src.nonrelativistic_boltzmann.collision_operator \
as collision_operator
import bolt.src.nonrelativistic_boltzmann.moment_defs as moment_defs
# Defining the physical system to be solved:
system = physical_system(domain,
boundary_conditions,
params,
initialize,
advection_terms,
collision_operator.BGK,
moment_defs
)
# Defining a nonlinear solver object:
nls = nonlinear_solver(system, True)
nls.strang_timestep(0.001)
af.sync()
for i in range(100):
nls.strang_timestep(0.001)
af.sync()
nls.print_performance_timings(101)
|
gpl-3.0
|
[
646,
1625,
8935,
465,
15871,
199,
646,
2680,
465,
980,
199,
646,
19199,
465,
1620,
199,
199,
504,
330,
28934,
14,
773,
14,
15020,
63,
2253,
492,
14095,
63,
2253,
199,
504,
330,
28934,
14,
773,
14,
2865,
6676,
63,
11263,
14,
2865,
6676,
63,
11263,
971,
272,
492,
2222,
6676,
63,
11263,
199,
199,
504,
330,
28934,
14,
773,
14,
2865,
6676,
63,
11263,
14,
2219,
14,
20576,
14,
1210,
63,
1725,
971,
272,
492,
2881,
199,
504,
330,
28934,
14,
773,
14,
2865,
6676,
63,
11263,
14,
2219,
14,
20576,
14,
1210,
63,
1725,
971,
272,
492,
8424,
63,
9855,
199,
504,
330,
28934,
14,
773,
14,
2865,
6676,
63,
11263,
14,
2219,
14,
20576,
14,
1210,
63,
1725,
971,
272,
492,
1862,
199,
504,
330,
28934,
14,
773,
14,
2865,
6676,
63,
11263,
14,
2219,
14,
20576,
14,
1210,
63,
1725,
971,
272,
492,
8265,
421,
199,
646,
330,
28934,
14,
2164,
14,
2865,
17060,
3804,
11108,
63,
23484,
3903,
20059,
14,
350,
432,
414,
63,
9187,
465,
1503,
432,
414,
63,
9187,
199,
646,
330,
28934,
14,
2164,
14,
2865,
17060,
3804,
11108,
63,
23484,
3903,
20059,
14,
761,
23656,
63,
3856,
971,
272,
465,
25061,
63,
3856,
199,
646,
330,
28934,
14,
2164,
14,
2865,
17060,
3804,
11108,
63,
23484,
3903,
20059,
14,
17282,
63,
8710,
465,
12427,
63,
8710,
199,
199,
3,
1487,
2408,
316,
314,
14095,
2656,
370,
506,
308,
7064,
26,
199,
2253,
275,
14095,
63,
2253,
8,
2261,
12,
586,
8424,
63,
9855,
12,
586,
1862,
12,
586,
8265,
12,
586,
1503,
432,
414,
63,
9187,
12,
586,
25061,
63,
3856,
14,
18998,
43,
12,
586,
12427,
63,
8710,
717,
776,
199,
199,
3,
1487,
2408,
316,
282,
2222,
6676,
10196,
909,
26,
199,
78,
478,
275,
2222,
6676,
63,
11263,
8,
2253,
12,
715,
9,
199,
78,
478,
14,
495,
621,
63,
521,
2926,
8,
16,
14,
4587,
9,
199,
2756,
14,
5186,
342,
199,
199,
509,
284,
315,
1425,
8,
1960,
304,
272,
302,
478,
14,
495,
621,
63,
521,
2926,
8,
16,
14,
4587,
9,
199,
2756,
14,
5186,
342,
199,
199,
78,
478,
14,
1361,
63,
20576,
63,
27337,
8,
4893,
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
] |
[
1625,
8935,
465,
15871,
199,
646,
2680,
465,
980,
199,
646,
19199,
465,
1620,
199,
199,
504,
330,
28934,
14,
773,
14,
15020,
63,
2253,
492,
14095,
63,
2253,
199,
504,
330,
28934,
14,
773,
14,
2865,
6676,
63,
11263,
14,
2865,
6676,
63,
11263,
971,
272,
492,
2222,
6676,
63,
11263,
199,
199,
504,
330,
28934,
14,
773,
14,
2865,
6676,
63,
11263,
14,
2219,
14,
20576,
14,
1210,
63,
1725,
971,
272,
492,
2881,
199,
504,
330,
28934,
14,
773,
14,
2865,
6676,
63,
11263,
14,
2219,
14,
20576,
14,
1210,
63,
1725,
971,
272,
492,
8424,
63,
9855,
199,
504,
330,
28934,
14,
773,
14,
2865,
6676,
63,
11263,
14,
2219,
14,
20576,
14,
1210,
63,
1725,
971,
272,
492,
1862,
199,
504,
330,
28934,
14,
773,
14,
2865,
6676,
63,
11263,
14,
2219,
14,
20576,
14,
1210,
63,
1725,
971,
272,
492,
8265,
421,
199,
646,
330,
28934,
14,
2164,
14,
2865,
17060,
3804,
11108,
63,
23484,
3903,
20059,
14,
350,
432,
414,
63,
9187,
465,
1503,
432,
414,
63,
9187,
199,
646,
330,
28934,
14,
2164,
14,
2865,
17060,
3804,
11108,
63,
23484,
3903,
20059,
14,
761,
23656,
63,
3856,
971,
272,
465,
25061,
63,
3856,
199,
646,
330,
28934,
14,
2164,
14,
2865,
17060,
3804,
11108,
63,
23484,
3903,
20059,
14,
17282,
63,
8710,
465,
12427,
63,
8710,
199,
199,
3,
1487,
2408,
316,
314,
14095,
2656,
370,
506,
308,
7064,
26,
199,
2253,
275,
14095,
63,
2253,
8,
2261,
12,
586,
8424,
63,
9855,
12,
586,
1862,
12,
586,
8265,
12,
586,
1503,
432,
414,
63,
9187,
12,
586,
25061,
63,
3856,
14,
18998,
43,
12,
586,
12427,
63,
8710,
717,
776,
199,
199,
3,
1487,
2408,
316,
282,
2222,
6676,
10196,
909,
26,
199,
78,
478,
275,
2222,
6676,
63,
11263,
8,
2253,
12,
715,
9,
199,
78,
478,
14,
495,
621,
63,
521,
2926,
8,
16,
14,
4587,
9,
199,
2756,
14,
5186,
342,
199,
199,
509,
284,
315,
1425,
8,
1960,
304,
272,
302,
478,
14,
495,
621,
63,
521,
2926,
8,
16,
14,
4587,
9,
199,
2756,
14,
5186,
342,
199,
199,
78,
478,
14,
1361,
63,
20576,
63,
27337,
8,
4893,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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718
|
# -*- coding: utf-8 -*-
# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for yapf.__init__.main."""
from contextlib import contextmanager
import sys
import unittest
import yapf
try:
from StringIO import StringIO
except ImportError: # Python 3
# Note: io.StringIO is different in Python 2, so try for python 2 first.
from io import StringIO
@contextmanager
def captured_output():
new_out, new_err = StringIO(), StringIO()
old_out, old_err = sys.stdout, sys.stderr
try:
sys.stdout, sys.stderr = new_out, new_err
yield sys.stdout, sys.stderr
finally:
sys.stdout, sys.stderr = old_out, old_err
@contextmanager
def patched_input(code):
"Monkey patch code as though it were coming from stdin."
def lines():
for line in code.splitlines():
yield line
raise EOFError()
def patch_raw_input(lines=lines()):
return next(lines)
try:
raw_input = yapf.py3compat.raw_input
yapf.py3compat.raw_input = patch_raw_input
yield
finally:
yapf.py3compat.raw_input = raw_input
class RunMainTest(unittest.TestCase):
def testShouldHandleYapfError(self):
"""run_main should handle YapfError and sys.exit(1)"""
expected_message = 'yapf: Input filenames did not match any python files\n'
sys.argv = ['yapf', 'foo.c']
with captured_output() as (out, err):
with self.assertRaises(SystemExit):
ret = yapf.run_main()
self.assertEqual(out.getvalue(), '')
self.assertEqual(err.getvalue(), expected_message)
class MainTest(unittest.TestCase):
def testNoPythonFilesMatched(self):
with self.assertRaisesRegexp(yapf.errors.YapfError,
'did not match any python files'):
yapf.main(['yapf', 'foo.c'])
def testEchoInput(self):
code = "a = 1\nb = 2\n"
with patched_input(code):
with captured_output() as (out, err):
ret = yapf.main([])
self.assertEqual(ret, 0)
self.assertEqual(out.getvalue(), code)
def testEchoInputWithStyle(self):
code = "def f(a = 1):\n return 2*a\n"
chromium_code = "def f(a=1):\n return 2 * a\n"
with patched_input(code):
with captured_output() as (out, err):
ret = yapf.main(['-', '--style=chromium'])
self.assertEqual(ret, 1)
self.assertEqual(out.getvalue(), chromium_code)
def testEchoBadInput(self):
bad_syntax = " a = 1\n"
with patched_input(bad_syntax):
with captured_output() as (out, err):
with self.assertRaisesRegexp(SyntaxError, "unexpected indent"):
ret = yapf.main([])
def testHelp(self):
with captured_output() as (out, err):
ret = yapf.main(['-', '--style-help', '--style=pep8'])
self.assertEqual(ret, 0)
help_message = out.getvalue()
self.assertIn("INDENT_WIDTH=4", help_message)
self.assertIn("The number of spaces required before a trailing comment.",
help_message)
def testVersion(self):
with captured_output() as (out, err):
ret = yapf.main(['-', '--version'])
self.assertEqual(ret, 0)
version = 'yapf {}\n'.format(yapf.__version__)
self.assertEqual(version, out.getvalue())
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
6900,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
624,
2925,
367,
612,
439,
70,
855,
826,
4343,
973,
1041,
199,
199,
504,
15502,
492,
27608,
199,
646,
984,
199,
646,
2882,
199,
646,
612,
439,
70,
199,
199,
893,
26,
523,
687,
5228,
492,
5228,
199,
2590,
3545,
26,
221,
327,
2018,
650,
523,
327,
3390,
26,
5890,
14,
6424,
365,
3365,
315,
2018,
499,
12,
880,
862,
367,
2366,
499,
1642,
14,
523,
687,
5890,
492,
5228,
421,
199,
32,
14237,
199,
318,
17487,
63,
1199,
837,
523,
892,
63,
548,
12,
892,
63,
1508,
275,
5228,
1062,
5228,
342,
523,
2269,
63,
548,
12,
2269,
63,
1508,
275,
984,
14,
2703,
12,
984,
14,
3083,
523,
862,
26,
272,
984,
14,
2703,
12,
984,
14,
3083,
275,
892,
63,
548,
12,
892,
63,
1508,
272,
1995,
984,
14,
2703,
12,
984,
14,
3083,
523,
3753,
26,
272,
984,
14,
2703,
12,
984,
14,
3083,
275,
2269,
63,
548,
12,
2269,
63,
1508,
421,
199,
32,
14237,
199,
318,
19483,
63,
1210,
8,
600,
304,
523,
298,
6671,
498,
3371,
1233,
465,
10617,
652,
4898,
17262,
687,
9009,
2122,
819,
347,
2385,
837,
272,
367,
1004,
315,
1233,
14,
7644,
837,
489,
1995,
1004,
272,
746,
21157,
342,
819,
347,
3371,
63,
1773,
63,
1210,
8,
1278,
29,
1278,
5109,
272,
372,
2163,
8,
1278,
9,
819,
862,
26,
272,
3066,
63,
1210,
275,
612,
439,
70,
14,
647,
19,
5819,
14,
1773,
63,
1210,
272,
612,
439,
70,
14,
647,
19,
5819,
14,
1773,
63,
1210,
275,
3371,
63,
1773,
63,
1210,
272,
1995,
523,
3753,
26,
272,
612,
439,
70,
14,
647,
19,
5819,
14,
1773,
63,
1210,
275,
3066,
63,
1210,
421,
199,
533,
3378,
6756,
774,
8,
2796,
14,
1746,
304,
819,
347,
511,
11408,
5940,
57,
439,
70,
547,
8,
277,
304,
272,
408,
1065,
63,
973,
1077,
2429,
1488,
439,
70,
547,
436,
984,
14,
2224,
8,
17,
9471,
272,
1420,
63,
1188,
275,
283,
89,
439,
70,
26,
6924,
6203,
8103,
440,
1336,
1263,
2366,
1584,
60,
78,
7,
272,
984,
14,
3020,
275,
788,
89,
439,
70,
297,
283,
1421,
14,
67,
418,
272,
543,
17487,
63,
1199,
342,
465,
334,
548,
12,
2329,
304,
489,
543,
291,
14,
1855,
8,
24738,
304,
267,
2203,
275,
612,
439,
70,
14,
1065,
63,
973,
342,
489,
291,
14,
629,
8,
548,
14,
7150,
1062,
4074,
489,
291,
14,
629,
8,
1508,
14,
7150,
1062,
1420,
63,
1188,
9,
421,
199,
533,
11298,
774,
8,
2796,
14,
1746,
304,
819,
347,
511,
1944,
4718,
5535,
4486,
379,
8,
277,
304,
272,
543,
291,
14,
10835,
8,
89,
439,
70,
14,
2550,
14,
57,
439,
70,
547,
12,
639,
283,
14887,
440,
1336,
1263,
2366,
1584,
735,
489,
612,
439,
70,
14,
973,
2941,
89,
439,
70,
297,
283,
1421,
14,
67,
1105,
819,
347,
511,
18690,
3205,
8,
277,
304,
272,
1233,
275,
298,
65,
275,
413,
60,
4994,
275,
499,
60,
78,
2,
272,
543,
19483,
63,
1210,
8,
600,
304,
489,
543,
17487,
63,
1199,
342,
465,
334,
548,
12,
2329,
304,
267,
2203,
275,
612,
439,
70,
14,
973,
4157,
267,
291,
14,
629,
8,
3292,
12,
378,
9,
267,
291,
14,
629,
8,
548,
14,
7150,
1062,
1233,
9,
819,
347,
511,
18690,
3205,
3007,
6609,
8,
277,
304,
272,
1233,
275,
298,
318,
289,
8,
65,
275,
413,
17211,
78,
259,
372,
499,
10,
65,
60,
78,
2,
272,
682,
7419,
63,
600,
275,
298,
318,
289,
8,
65,
29,
17,
17211,
78,
221,
372,
499,
627,
282,
60,
78,
2,
272,
543,
19483,
63,
1210,
8,
600,
304,
489,
543,
17487,
63,
1199,
342,
465,
334,
548,
12,
2329,
304,
267,
2203,
275,
612,
439,
70,
14,
973,
2941,
14382,
2850,
2487,
29,
13211,
1105,
267,
291,
14,
629,
8,
3292,
12,
413,
9,
267,
291,
14,
629,
8,
548,
14,
7150,
1062,
682,
7419,
63,
600,
9,
819,
347,
511,
18690,
5725,
3205,
8,
277,
304,
272,
4875,
63,
7093,
275,
298,
221,
282,
275,
413,
60,
78,
2,
272,
543,
19483,
63,
1210,
8,
4087,
63,
7093,
304,
489,
543,
17487,
63,
1199,
342,
465,
334,
548,
12,
2329,
304,
267,
543,
291,
14,
10835,
8,
9294,
12,
298,
8953,
4363,
2349,
881,
2203,
275,
612,
439,
70,
14,
973,
4157,
819,
347,
511,
8673,
8,
277,
304,
272,
543,
17487,
63,
1199,
342,
465,
334,
548,
12,
2329,
304,
489,
2203,
275,
612,
439,
70,
14,
973,
2941,
14382,
2850,
2487,
13,
3437,
297,
2850,
2487,
29,
12636,
24,
1105,
489,
291,
14,
629,
8,
3292,
12,
378,
9,
489,
1720,
63,
1188,
275,
734,
14,
7150,
342,
489,
291,
14,
4080,
480,
29080,
63,
11139,
29,
20,
401,
1720,
63,
1188,
9,
489,
291,
14,
4080,
480,
1918,
1329,
402,
7883,
1415,
2544,
282,
8520,
3721,
4765,
490,
1720,
63,
1188,
9,
819,
347,
511,
3353,
8,
277,
304,
272,
543,
17487,
63,
1199,
342,
465,
334,
548,
12,
2329,
304,
489,
2203,
275,
612,
439,
70,
14,
973,
2941,
14382,
2850,
1023,
1105,
489,
291,
14,
629,
8,
3292,
12,
378,
9,
489,
1015,
275,
283,
89,
439,
70,
22902,
78,
1370,
908,
8,
89,
439,
70,
855,
1023,
3368,
489,
291,
14
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
6900,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
624,
2925,
367,
612,
439,
70,
855,
826,
4343,
973,
1041,
199,
199,
504,
15502,
492,
27608,
199,
646,
984,
199,
646,
2882,
199,
646,
612,
439,
70,
199,
199,
893,
26,
523,
687,
5228,
492,
5228,
199,
2590,
3545,
26,
221,
327,
2018,
650,
523,
327,
3390,
26,
5890,
14,
6424,
365,
3365,
315,
2018,
499,
12,
880,
862,
367,
2366,
499,
1642,
14,
523,
687,
5890,
492,
5228,
421,
199,
32,
14237,
199,
318,
17487,
63,
1199,
837,
523,
892,
63,
548,
12,
892,
63,
1508,
275,
5228,
1062,
5228,
342,
523,
2269,
63,
548,
12,
2269,
63,
1508,
275,
984,
14,
2703,
12,
984,
14,
3083,
523,
862,
26,
272,
984,
14,
2703,
12,
984,
14,
3083,
275,
892,
63,
548,
12,
892,
63,
1508,
272,
1995,
984,
14,
2703,
12,
984,
14,
3083,
523,
3753,
26,
272,
984,
14,
2703,
12,
984,
14,
3083,
275,
2269,
63,
548,
12,
2269,
63,
1508,
421,
199,
32,
14237,
199,
318,
19483,
63,
1210,
8,
600,
304,
523,
298,
6671,
498,
3371,
1233,
465,
10617,
652,
4898,
17262,
687,
9009,
2122,
819,
347,
2385,
837,
272,
367,
1004,
315,
1233,
14,
7644,
837,
489,
1995,
1004,
272,
746,
21157,
342,
819,
347,
3371,
63,
1773,
63,
1210,
8,
1278,
29,
1278,
5109,
272,
372,
2163,
8,
1278,
9,
819,
862,
26,
272,
3066,
63,
1210,
275,
612,
439,
70,
14,
647,
19,
5819,
14,
1773,
63,
1210,
272,
612,
439,
70,
14,
647,
19,
5819,
14,
1773,
63,
1210,
275,
3371,
63,
1773,
63,
1210,
272,
1995,
523,
3753,
26,
272,
612,
439,
70,
14,
647,
19,
5819,
14,
1773,
63,
1210,
275,
3066,
63,
1210,
421,
199,
533,
3378,
6756,
774,
8,
2796,
14,
1746,
304,
819,
347,
511,
11408,
5940,
57,
439,
70,
547,
8,
277,
304,
272,
408,
1065,
63,
973,
1077,
2429,
1488,
439,
70,
547,
436,
984,
14,
2224,
8,
17,
9471,
272,
1420,
63,
1188,
275,
283,
89,
439,
70,
26,
6924,
6203,
8103,
440,
1336,
1263,
2366,
1584,
60,
78,
7,
272,
984,
14,
3020,
275,
788,
89,
439,
70,
297,
283,
1421,
14,
67,
418,
272,
543,
17487,
63,
1199,
342,
465,
334,
548,
12,
2329,
304,
489,
543,
291,
14,
1855,
8,
24738,
304,
267,
2203,
275,
612,
439,
70,
14,
1065,
63,
973,
342,
489,
291,
14,
629,
8,
548,
14,
7150,
1062,
4074,
489,
291,
14,
629,
8,
1508,
14,
7150,
1062,
1420,
63,
1188,
9,
421,
199,
533,
11298,
774,
8,
2796,
14,
1746,
304,
819,
347,
511,
1944,
4718,
5535,
4486,
379,
8,
277,
304,
272,
543,
291,
14,
10835,
8,
89,
439,
70,
14,
2550,
14,
57,
439,
70,
547,
12,
639,
283,
14887,
440,
1336,
1263,
2366,
1584,
735,
489,
612,
439,
70,
14,
973,
2941,
89,
439,
70,
297,
283,
1421,
14,
67,
1105,
819,
347,
511,
18690,
3205,
8,
277,
304,
272,
1233,
275,
298,
65,
275,
413,
60,
4994,
275,
499,
60,
78,
2,
272,
543,
19483,
63,
1210,
8,
600,
304,
489,
543,
17487,
63,
1199,
342,
465,
334,
548,
12,
2329,
304,
267,
2203,
275,
612,
439,
70,
14,
973,
4157,
267,
291,
14,
629,
8,
3292,
12,
378,
9,
267,
291,
14,
629,
8,
548,
14,
7150,
1062,
1233,
9,
819,
347,
511,
18690,
3205,
3007,
6609,
8,
277,
304,
272,
1233,
275,
298,
318,
289,
8,
65,
275,
413,
17211,
78,
259,
372,
499,
10,
65,
60,
78,
2,
272,
682,
7419,
63,
600,
275,
298,
318,
289,
8,
65,
29,
17,
17211,
78,
221,
372,
499,
627,
282,
60,
78,
2,
272,
543,
19483,
63,
1210,
8,
600,
304,
489,
543,
17487,
63,
1199,
342,
465,
334,
548,
12,
2329,
304,
267,
2203,
275,
612,
439,
70,
14,
973,
2941,
14382,
2850,
2487,
29,
13211,
1105,
267,
291,
14,
629,
8,
3292,
12,
413,
9,
267,
291,
14,
629,
8,
548,
14,
7150,
1062,
682,
7419,
63,
600,
9,
819,
347,
511,
18690,
5725,
3205,
8,
277,
304,
272,
4875,
63,
7093,
275,
298,
221,
282,
275,
413,
60,
78,
2,
272,
543,
19483,
63,
1210,
8,
4087,
63,
7093,
304,
489,
543,
17487,
63,
1199,
342,
465,
334,
548,
12,
2329,
304,
267,
543,
291,
14,
10835,
8,
9294,
12,
298,
8953,
4363,
2349,
881,
2203,
275,
612,
439,
70,
14,
973,
4157,
819,
347,
511,
8673,
8,
277,
304,
272,
543,
17487,
63,
1199,
342,
465,
334,
548,
12,
2329,
304,
489,
2203,
275,
612,
439,
70,
14,
973,
2941,
14382,
2850,
2487,
13,
3437,
297,
2850,
2487,
29,
12636,
24,
1105,
489,
291,
14,
629,
8,
3292,
12,
378,
9,
489,
1720,
63,
1188,
275,
734,
14,
7150,
342,
489,
291,
14,
4080,
480,
29080,
63,
11139,
29,
20,
401,
1720,
63,
1188,
9,
489,
291,
14,
4080,
480,
1918,
1329,
402,
7883,
1415,
2544,
282,
8520,
3721,
4765,
490,
1720,
63,
1188,
9,
819,
347,
511,
3353,
8,
277,
304,
272,
543,
17487,
63,
1199,
342,
465,
334,
548,
12,
2329,
304,
489,
2203,
275,
612,
439,
70,
14,
973,
2941,
14382,
2850,
1023,
1105,
489,
291,
14,
629,
8,
3292,
12,
378,
9,
489,
1015,
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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
] |
theflofly/tensorflow
|
tensorflow/python/training/proximal_gradient_descent.py
|
12
|
4434
|
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""ProximalGradientDescent for TensorFlow."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.python.framework import ops
# pylint: disable=unused-import
from tensorflow.python.ops import math_ops
# pylint: enable=unused-import
from tensorflow.python.training import optimizer
from tensorflow.python.training import training_ops
from tensorflow.python.util.tf_export import tf_export
@tf_export(v1=["train.ProximalGradientDescentOptimizer"])
class ProximalGradientDescentOptimizer(optimizer.Optimizer):
# pylint: disable=line-too-long
"""Optimizer that implements the proximal gradient descent algorithm.
See this [paper](http://papers.nips.cc/paper/3793-efficient-learning-using-forward-backward-splitting.pdf).
"""
def __init__(self, learning_rate, l1_regularization_strength=0.0,
l2_regularization_strength=0.0, use_locking=False,
name="ProximalGradientDescent"):
"""Construct a new proximal gradient descent optimizer.
Args:
learning_rate: A Tensor or a floating point value. The learning
rate to use.
l1_regularization_strength: A float value, must be greater than or
equal to zero.
l2_regularization_strength: A float value, must be greater than or
equal to zero.
use_locking: If True use locks for update operations.
name: Optional name prefix for the operations created when applying
gradients. Defaults to "GradientDescent".
"""
super(ProximalGradientDescentOptimizer, self).__init__(use_locking, name)
self._learning_rate = learning_rate
self._l1_regularization_strength = l1_regularization_strength
self._l2_regularization_strength = l2_regularization_strength
self._l1_regularization_strength_tensor = None
self._l2_regularization_strength_tensor = None
def _apply_dense(self, grad, var):
return training_ops.apply_proximal_gradient_descent(
var,
self._learning_rate_tensor,
self._l1_regularization_strength_tensor,
self._l2_regularization_strength_tensor,
grad,
use_locking=self._use_locking).op
def _resource_apply_dense(self, grad, var):
return training_ops.resource_apply_proximal_gradient_descent(
var.handle,
self._learning_rate_tensor,
self._l1_regularization_strength_tensor,
self._l2_regularization_strength_tensor,
grad,
use_locking=self._use_locking)
def _apply_sparse(self, grad, var):
return training_ops.sparse_apply_proximal_gradient_descent(
var,
self._learning_rate_tensor,
self._l1_regularization_strength_tensor,
self._l2_regularization_strength_tensor,
grad.values,
grad.indices,
use_locking=self._use_locking).op
def _resource_apply_sparse(self, grad, var, indices):
return training_ops.resource_sparse_apply_proximal_gradient_descent(
var.handle,
math_ops.cast(self._learning_rate_tensor, grad.dtype),
math_ops.cast(self._l1_regularization_strength_tensor, grad.dtype),
math_ops.cast(self._l2_regularization_strength_tensor, grad.dtype),
grad,
indices,
use_locking=self._use_locking)
def _prepare(self):
self._learning_rate_tensor = ops.convert_to_tensor(self._learning_rate,
name="learning_rate")
self._l1_regularization_strength_tensor = ops.convert_to_tensor(
self._l1_regularization_strength, name="l1_regularization_strength")
self._l2_regularization_strength_tensor = ops.convert_to_tensor(
self._l2_regularization_strength, name="l2_regularization_strength")
|
apache-2.0
|
[
3,
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
624,
26689,
7265,
9942,
26232,
367,
9134,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
3,
4287,
26,
4756,
29,
8618,
13,
646,
199,
504,
3228,
14,
1548,
14,
7588,
492,
10736,
199,
504,
3228,
14,
1548,
14,
7588,
492,
6093,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1974,
14,
3249,
63,
3790,
492,
2833,
63,
3790,
421,
199,
32,
3249,
63,
3790,
8,
86,
17,
6270,
2834,
14,
26689,
7265,
9942,
26232,
13946,
3135,
199,
533,
2165,
88,
7265,
9942,
26232,
13946,
8,
12290,
14,
13946,
304,
523,
327,
4287,
26,
3507,
29,
604,
13,
7354,
13,
2809,
523,
408,
13946,
626,
9031,
314,
10645,
7265,
6709,
31518,
5563,
14,
819,
1666,
642,
359,
10443,
8738,
1014,
921,
10443,
83,
14,
78,
6142,
14,
2055,
15,
10443,
15,
1401,
3129,
13,
21069,
13,
10546,
13,
4941,
13,
6688,
13,
15457,
13,
1294,
1337,
14,
5607,
680,
523,
408,
819,
347,
636,
826,
721,
277,
12,
9328,
63,
1866,
12,
634,
17,
63,
18948,
63,
21049,
29,
16,
14,
16,
12,
2049,
634,
18,
63,
18948,
63,
21049,
29,
16,
14,
16,
12,
675,
63,
24056,
29,
797,
12,
2049,
536,
628,
26689,
7265,
9942,
26232,
2349,
272,
408,
11493,
282,
892,
10645,
7265,
6709,
31518,
10736,
14,
339,
3033,
26,
489,
9328,
63,
1866,
26,
437,
5878,
503,
282,
8402,
2376,
574,
14,
221,
710,
9328,
267,
6634,
370,
675,
14,
489,
634,
17,
63,
18948,
63,
21049,
26,
437,
2069,
574,
12,
1471,
506,
8932,
2419,
503,
267,
4472,
370,
4697,
14,
489,
634,
18,
63,
18948,
63,
21049,
26,
437,
2069,
574,
12,
1471,
506,
8932,
2419,
503,
267,
4472,
370,
4697,
14,
489,
675,
63,
24056,
26,
982,
715,
675,
23340,
367,
1678,
5331,
14,
489,
536,
26,
4879,
536,
2403,
367,
314,
5331,
2737,
1380,
18876,
267,
12661,
14,
7827,
370,
298,
9942,
26232,
1674,
272,
408,
272,
1613,
8,
26689,
7265,
9942,
26232,
13946,
12,
291,
2843,
826,
721,
1180,
63,
24056,
12,
536,
9,
272,
291,
423,
10546,
63,
1866,
275,
9328,
63,
1866,
272,
291,
423,
76,
17,
63,
18948,
63,
21049,
275,
634,
17,
63,
18948,
63,
21049,
272,
291,
423,
76,
18,
63,
18948,
63,
21049,
275,
634,
18,
63,
18948,
63,
21049,
272,
291,
423,
76,
17,
63,
18948,
63,
21049,
63,
3128,
275,
488,
272,
291,
423,
76,
18,
63,
18948,
63,
21049,
63,
3128,
275,
488,
819,
347,
485,
4998,
63,
7253,
8,
277,
12,
7659,
12,
2729,
304,
272,
372,
6093,
63,
1483,
14,
4998,
63,
8221,
7265,
63,
7490,
63,
26269,
8,
267,
2729,
12,
267,
291,
423,
10546,
63,
1866,
63,
3128,
12,
267,
291,
423,
76,
17,
63,
18948,
63,
21049,
63,
3128,
12,
267,
291,
423,
76,
18,
63,
18948,
63,
21049,
63,
3128,
12,
267,
7659,
12,
267,
675,
63,
24056,
29,
277,
423,
1180,
63,
24056,
680,
411,
819,
347,
485,
1927,
63,
4998,
63,
7253,
8,
277,
12,
7659,
12,
2729,
304,
272,
372,
6093,
63,
1483,
14,
1927,
63,
4998,
63,
8221,
7265,
63,
7490,
63,
26269,
8,
267,
2729,
14,
2479,
12,
267,
291,
423,
10546,
63,
1866,
63,
3128,
12,
267,
291,
423,
76,
17,
63,
18948,
63,
21049,
63,
3128,
12,
267,
291,
423,
76,
18,
63,
18948,
63,
21049,
63,
3128,
12,
267,
7659,
12,
267,
675,
63,
24056,
29,
277,
423,
1180,
63,
24056,
9,
819,
347,
485,
4998,
63,
4421,
8,
277,
12,
7659,
12,
2729,
304,
272,
372,
6093,
63,
1483,
14,
4421,
63,
4998,
63,
8221,
7265,
63,
7490,
63,
26269,
8,
267,
2729,
12,
267,
291,
423,
10546,
63,
1866,
63,
3128,
12,
267,
291,
423,
76,
17,
63,
18948,
63,
21049,
63,
3128,
12,
267,
291,
423,
76,
18,
63,
18948,
63,
21049,
63,
3128,
12,
267,
7659,
14,
1459,
12,
267,
7659,
14,
4108,
12,
267,
675,
63,
24056,
29,
277,
423,
1180,
63,
24056,
680,
411,
819,
347,
485,
1927,
63,
4998,
63,
4421,
8,
277,
12,
7659,
12,
2729,
12,
4918,
304,
272,
372,
6093,
63,
1483,
14,
1927,
63,
4421,
63,
4998,
63,
8221,
7265,
63,
7490,
63,
26269,
8,
267,
2729,
14,
2479,
12,
267,
3473,
63,
1483,
14,
2931,
8,
277,
423,
10546,
63,
1866,
63,
3128,
12,
7659,
14,
2271,
395,
267,
3473,
63,
1483,
14,
2931,
8,
277,
423,
76,
17,
63,
18948,
63,
21049,
63,
3128,
12,
7659,
14,
2271,
395,
267,
3473,
63,
1483,
14,
2931,
8,
277,
423,
76,
18,
63,
18948,
63,
21049,
63,
3128,
12,
7659,
14,
2271,
395,
267,
7659,
12,
267,
4918,
12,
267,
675,
63,
24056,
29,
277,
423,
1180,
63,
24056,
9,
819,
347,
485,
6726,
8,
277,
304,
272,
291,
423,
10546,
63,
1866,
63,
3128,
275,
4156,
14,
3916,
63,
475,
63,
3128,
8,
277,
423,
10546,
63,
1866,
12,
10940,
536,
628,
10546,
63,
1866,
531,
272,
291,
423,
76,
17,
63,
18948,
63,
21049,
63,
3128,
275,
4156,
14,
3916,
63,
475,
63,
3128
] |
[
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
624,
26689,
7265,
9942,
26232,
367,
9134,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
3,
4287,
26,
4756,
29,
8618,
13,
646,
199,
504,
3228,
14,
1548,
14,
7588,
492,
10736,
199,
504,
3228,
14,
1548,
14,
7588,
492,
6093,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1974,
14,
3249,
63,
3790,
492,
2833,
63,
3790,
421,
199,
32,
3249,
63,
3790,
8,
86,
17,
6270,
2834,
14,
26689,
7265,
9942,
26232,
13946,
3135,
199,
533,
2165,
88,
7265,
9942,
26232,
13946,
8,
12290,
14,
13946,
304,
523,
327,
4287,
26,
3507,
29,
604,
13,
7354,
13,
2809,
523,
408,
13946,
626,
9031,
314,
10645,
7265,
6709,
31518,
5563,
14,
819,
1666,
642,
359,
10443,
8738,
1014,
921,
10443,
83,
14,
78,
6142,
14,
2055,
15,
10443,
15,
1401,
3129,
13,
21069,
13,
10546,
13,
4941,
13,
6688,
13,
15457,
13,
1294,
1337,
14,
5607,
680,
523,
408,
819,
347,
636,
826,
721,
277,
12,
9328,
63,
1866,
12,
634,
17,
63,
18948,
63,
21049,
29,
16,
14,
16,
12,
2049,
634,
18,
63,
18948,
63,
21049,
29,
16,
14,
16,
12,
675,
63,
24056,
29,
797,
12,
2049,
536,
628,
26689,
7265,
9942,
26232,
2349,
272,
408,
11493,
282,
892,
10645,
7265,
6709,
31518,
10736,
14,
339,
3033,
26,
489,
9328,
63,
1866,
26,
437,
5878,
503,
282,
8402,
2376,
574,
14,
221,
710,
9328,
267,
6634,
370,
675,
14,
489,
634,
17,
63,
18948,
63,
21049,
26,
437,
2069,
574,
12,
1471,
506,
8932,
2419,
503,
267,
4472,
370,
4697,
14,
489,
634,
18,
63,
18948,
63,
21049,
26,
437,
2069,
574,
12,
1471,
506,
8932,
2419,
503,
267,
4472,
370,
4697,
14,
489,
675,
63,
24056,
26,
982,
715,
675,
23340,
367,
1678,
5331,
14,
489,
536,
26,
4879,
536,
2403,
367,
314,
5331,
2737,
1380,
18876,
267,
12661,
14,
7827,
370,
298,
9942,
26232,
1674,
272,
408,
272,
1613,
8,
26689,
7265,
9942,
26232,
13946,
12,
291,
2843,
826,
721,
1180,
63,
24056,
12,
536,
9,
272,
291,
423,
10546,
63,
1866,
275,
9328,
63,
1866,
272,
291,
423,
76,
17,
63,
18948,
63,
21049,
275,
634,
17,
63,
18948,
63,
21049,
272,
291,
423,
76,
18,
63,
18948,
63,
21049,
275,
634,
18,
63,
18948,
63,
21049,
272,
291,
423,
76,
17,
63,
18948,
63,
21049,
63,
3128,
275,
488,
272,
291,
423,
76,
18,
63,
18948,
63,
21049,
63,
3128,
275,
488,
819,
347,
485,
4998,
63,
7253,
8,
277,
12,
7659,
12,
2729,
304,
272,
372,
6093,
63,
1483,
14,
4998,
63,
8221,
7265,
63,
7490,
63,
26269,
8,
267,
2729,
12,
267,
291,
423,
10546,
63,
1866,
63,
3128,
12,
267,
291,
423,
76,
17,
63,
18948,
63,
21049,
63,
3128,
12,
267,
291,
423,
76,
18,
63,
18948,
63,
21049,
63,
3128,
12,
267,
7659,
12,
267,
675,
63,
24056,
29,
277,
423,
1180,
63,
24056,
680,
411,
819,
347,
485,
1927,
63,
4998,
63,
7253,
8,
277,
12,
7659,
12,
2729,
304,
272,
372,
6093,
63,
1483,
14,
1927,
63,
4998,
63,
8221,
7265,
63,
7490,
63,
26269,
8,
267,
2729,
14,
2479,
12,
267,
291,
423,
10546,
63,
1866,
63,
3128,
12,
267,
291,
423,
76,
17,
63,
18948,
63,
21049,
63,
3128,
12,
267,
291,
423,
76,
18,
63,
18948,
63,
21049,
63,
3128,
12,
267,
7659,
12,
267,
675,
63,
24056,
29,
277,
423,
1180,
63,
24056,
9,
819,
347,
485,
4998,
63,
4421,
8,
277,
12,
7659,
12,
2729,
304,
272,
372,
6093,
63,
1483,
14,
4421,
63,
4998,
63,
8221,
7265,
63,
7490,
63,
26269,
8,
267,
2729,
12,
267,
291,
423,
10546,
63,
1866,
63,
3128,
12,
267,
291,
423,
76,
17,
63,
18948,
63,
21049,
63,
3128,
12,
267,
291,
423,
76,
18,
63,
18948,
63,
21049,
63,
3128,
12,
267,
7659,
14,
1459,
12,
267,
7659,
14,
4108,
12,
267,
675,
63,
24056,
29,
277,
423,
1180,
63,
24056,
680,
411,
819,
347,
485,
1927,
63,
4998,
63,
4421,
8,
277,
12,
7659,
12,
2729,
12,
4918,
304,
272,
372,
6093,
63,
1483,
14,
1927,
63,
4421,
63,
4998,
63,
8221,
7265,
63,
7490,
63,
26269,
8,
267,
2729,
14,
2479,
12,
267,
3473,
63,
1483,
14,
2931,
8,
277,
423,
10546,
63,
1866,
63,
3128,
12,
7659,
14,
2271,
395,
267,
3473,
63,
1483,
14,
2931,
8,
277,
423,
76,
17,
63,
18948,
63,
21049,
63,
3128,
12,
7659,
14,
2271,
395,
267,
3473,
63,
1483,
14,
2931,
8,
277,
423,
76,
18,
63,
18948,
63,
21049,
63,
3128,
12,
7659,
14,
2271,
395,
267,
7659,
12,
267,
4918,
12,
267,
675,
63,
24056,
29,
277,
423,
1180,
63,
24056,
9,
819,
347,
485,
6726,
8,
277,
304,
272,
291,
423,
10546,
63,
1866,
63,
3128,
275,
4156,
14,
3916,
63,
475,
63,
3128,
8,
277,
423,
10546,
63,
1866,
12,
10940,
536,
628,
10546,
63,
1866,
531,
272,
291,
423,
76,
17,
63,
18948,
63,
21049,
63,
3128,
275,
4156,
14,
3916,
63,
475,
63,
3128,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dufferzafar/mitmproxy
|
test/netlib/http/http1/test_read.py
|
2
|
11189
|
from __future__ import absolute_import, print_function, division
from io import BytesIO
from mock import Mock
import pytest
from netlib.exceptions import HttpException, HttpSyntaxException, HttpReadDisconnect, TcpDisconnect
from netlib.http import Headers
from netlib.http.http1.read import (
read_request, read_response, read_request_head,
read_response_head, read_body, connection_close, expected_http_body_size, _get_first_line,
_read_request_line, _parse_authority_form, _read_response_line, _check_http_version,
_read_headers, _read_chunked, get_header_tokens
)
from netlib.tutils import treq, tresp, raises
from netlib import exceptions
def test_get_header_tokens():
headers = Headers()
assert get_header_tokens(headers, "foo") == []
headers["foo"] = "bar"
assert get_header_tokens(headers, "foo") == ["bar"]
headers["foo"] = "bar, voing"
assert get_header_tokens(headers, "foo") == ["bar", "voing"]
headers.set_all("foo", ["bar, voing", "oink"])
assert get_header_tokens(headers, "foo") == ["bar", "voing", "oink"]
@pytest.mark.parametrize("input", [
b"GET / HTTP/1.1\r\n\r\nskip",
b"GET / HTTP/1.1\r\n\r\nskip",
b"GET / HTTP/1.1\r\n\r\nskip",
b"GET / HTTP/1.1 \r\n\r\nskip",
])
def test_read_request(input):
rfile = BytesIO(input)
r = read_request(rfile)
assert r.method == "GET"
assert r.content == b""
assert r.http_version == "HTTP/1.1"
assert r.timestamp_end
assert rfile.read() == b"skip"
@pytest.mark.parametrize("input", [
b"CONNECT :0 0",
])
def test_read_request_error(input):
rfile = BytesIO(input)
raises(exceptions.HttpException, read_request, rfile)
def test_read_request_head():
rfile = BytesIO(
b"GET / HTTP/1.1\r\n"
b"Content-Length: 4\r\n"
b"\r\n"
b"skip"
)
rfile.reset_timestamps = Mock()
rfile.first_byte_timestamp = 42
r = read_request_head(rfile)
assert r.method == "GET"
assert r.headers["Content-Length"] == "4"
assert r.content is None
assert rfile.reset_timestamps.called
assert r.timestamp_start == 42
assert rfile.read() == b"skip"
@pytest.mark.parametrize("input", [
b"HTTP/1.1 418 I'm a teapot\r\n\r\nbody",
b"HTTP/1.1 418 I'm a teapot\r\n\r\nbody",
b"HTTP/1.1 418 I'm a teapot\r\n\r\nbody",
b"HTTP/1.1 418 I'm a teapot \r\n\r\nbody",
])
def test_read_response(input):
req = treq()
rfile = BytesIO(input)
r = read_response(rfile, req)
assert r.http_version == "HTTP/1.1"
assert r.status_code == 418
assert r.reason == "I'm a teapot"
assert r.content == b"body"
assert r.timestamp_end
def test_read_response_head():
rfile = BytesIO(
b"HTTP/1.1 418 I'm a teapot\r\n"
b"Content-Length: 4\r\n"
b"\r\n"
b"skip"
)
rfile.reset_timestamps = Mock()
rfile.first_byte_timestamp = 42
r = read_response_head(rfile)
assert r.status_code == 418
assert r.headers["Content-Length"] == "4"
assert r.content is None
assert rfile.reset_timestamps.called
assert r.timestamp_start == 42
assert rfile.read() == b"skip"
class TestReadBody(object):
def test_chunked(self):
rfile = BytesIO(b"3\r\nfoo\r\n0\r\n\r\nbar")
body = b"".join(read_body(rfile, None))
assert body == b"foo"
assert rfile.read() == b"bar"
def test_known_size(self):
rfile = BytesIO(b"foobar")
body = b"".join(read_body(rfile, 3))
assert body == b"foo"
assert rfile.read() == b"bar"
def test_known_size_limit(self):
rfile = BytesIO(b"foobar")
with raises(HttpException):
b"".join(read_body(rfile, 3, 2))
def test_known_size_too_short(self):
rfile = BytesIO(b"foo")
with raises(HttpException):
b"".join(read_body(rfile, 6))
def test_unknown_size(self):
rfile = BytesIO(b"foobar")
body = b"".join(read_body(rfile, -1))
assert body == b"foobar"
def test_unknown_size_limit(self):
rfile = BytesIO(b"foobar")
with raises(HttpException):
b"".join(read_body(rfile, -1, 3))
def test_max_chunk_size(self):
rfile = BytesIO(b"123456")
assert list(read_body(rfile, -1, max_chunk_size=None)) == [b"123456"]
rfile = BytesIO(b"123456")
assert list(read_body(rfile, -1, max_chunk_size=1)) == [b"1", b"2", b"3", b"4", b"5", b"6"]
def test_connection_close():
headers = Headers()
assert connection_close(b"HTTP/1.0", headers)
assert not connection_close(b"HTTP/1.1", headers)
headers["connection"] = "keep-alive"
assert not connection_close(b"HTTP/1.1", headers)
headers["connection"] = "close"
assert connection_close(b"HTTP/1.1", headers)
headers["connection"] = "foobar"
assert connection_close(b"HTTP/1.0", headers)
assert not connection_close(b"HTTP/1.1", headers)
def test_expected_http_body_size():
# Expect: 100-continue
assert expected_http_body_size(
treq(headers=Headers(expect="100-continue", content_length="42"))
) == 0
# http://tools.ietf.org/html/rfc7230#section-3.3
assert expected_http_body_size(
treq(method=b"HEAD"),
tresp(headers=Headers(content_length="42"))
) == 0
assert expected_http_body_size(
treq(method=b"CONNECT"),
tresp()
) == 0
for code in (100, 204, 304):
assert expected_http_body_size(
treq(),
tresp(status_code=code)
) == 0
# chunked
assert expected_http_body_size(
treq(headers=Headers(transfer_encoding="chunked")),
) is None
# explicit length
for val in (b"foo", b"-7"):
with raises(HttpSyntaxException):
expected_http_body_size(
treq(headers=Headers(content_length=val))
)
assert expected_http_body_size(
treq(headers=Headers(content_length="42"))
) == 42
# no length
assert expected_http_body_size(
treq(headers=Headers())
) == 0
assert expected_http_body_size(
treq(headers=Headers()), tresp(headers=Headers())
) == -1
def test_get_first_line():
rfile = BytesIO(b"foo\r\nbar")
assert _get_first_line(rfile) == b"foo"
rfile = BytesIO(b"\r\nfoo\r\nbar")
assert _get_first_line(rfile) == b"foo"
with raises(HttpReadDisconnect):
rfile = BytesIO(b"")
_get_first_line(rfile)
with raises(HttpReadDisconnect):
rfile = Mock()
rfile.readline.side_effect = TcpDisconnect
_get_first_line(rfile)
def test_read_request_line():
def t(b):
return _read_request_line(BytesIO(b))
assert (t(b"GET / HTTP/1.1") ==
("relative", b"GET", None, None, None, b"/", b"HTTP/1.1"))
assert (t(b"OPTIONS * HTTP/1.1") ==
("relative", b"OPTIONS", None, None, None, b"*", b"HTTP/1.1"))
assert (t(b"CONNECT foo:42 HTTP/1.1") ==
("authority", b"CONNECT", None, b"foo", 42, None, b"HTTP/1.1"))
assert (t(b"GET http://foo:42/bar HTTP/1.1") ==
("absolute", b"GET", b"http", b"foo", 42, b"/bar", b"HTTP/1.1"))
with raises(HttpSyntaxException):
t(b"GET / WTF/1.1")
with raises(HttpSyntaxException):
t(b"this is not http")
with raises(HttpReadDisconnect):
t(b"")
def test_parse_authority_form():
assert _parse_authority_form(b"foo:42") == (b"foo", 42)
with raises(HttpSyntaxException):
_parse_authority_form(b"foo")
with raises(HttpSyntaxException):
_parse_authority_form(b"foo:bar")
with raises(HttpSyntaxException):
_parse_authority_form(b"foo:99999999")
with raises(HttpSyntaxException):
_parse_authority_form(b"f\x00oo:80")
def test_read_response_line():
def t(b):
return _read_response_line(BytesIO(b))
assert t(b"HTTP/1.1 200 OK") == (b"HTTP/1.1", 200, b"OK")
assert t(b"HTTP/1.1 200") == (b"HTTP/1.1", 200, b"")
# https://github.com/mitmproxy/mitmproxy/issues/784
assert t(b"HTTP/1.1 200 Non-Autoris\xc3\xa9") == (b"HTTP/1.1", 200, b"Non-Autoris\xc3\xa9")
with raises(HttpSyntaxException):
assert t(b"HTTP/1.1")
with raises(HttpSyntaxException):
t(b"HTTP/1.1 OK OK")
with raises(HttpSyntaxException):
t(b"WTF/1.1 200 OK")
with raises(HttpReadDisconnect):
t(b"")
def test_check_http_version():
_check_http_version(b"HTTP/0.9")
_check_http_version(b"HTTP/1.0")
_check_http_version(b"HTTP/1.1")
_check_http_version(b"HTTP/2.0")
with raises(HttpSyntaxException):
_check_http_version(b"WTF/1.0")
with raises(HttpSyntaxException):
_check_http_version(b"HTTP/1.10")
with raises(HttpSyntaxException):
_check_http_version(b"HTTP/1.b")
class TestReadHeaders(object):
@staticmethod
def _read(data):
return _read_headers(BytesIO(data))
def test_read_simple(self):
data = (
b"Header: one\r\n"
b"Header2: two\r\n"
b"\r\n"
)
headers = self._read(data)
assert headers.fields == ((b"Header", b"one"), (b"Header2", b"two"))
def test_read_multi(self):
data = (
b"Header: one\r\n"
b"Header: two\r\n"
b"\r\n"
)
headers = self._read(data)
assert headers.fields == ((b"Header", b"one"), (b"Header", b"two"))
def test_read_continued(self):
data = (
b"Header: one\r\n"
b"\ttwo\r\n"
b"Header2: three\r\n"
b"\r\n"
)
headers = self._read(data)
assert headers.fields == ((b"Header", b"one\r\n two"), (b"Header2", b"three"))
def test_read_continued_err(self):
data = b"\tfoo: bar\r\n"
with raises(HttpSyntaxException):
self._read(data)
def test_read_err(self):
data = b"foo"
with raises(HttpSyntaxException):
self._read(data)
def test_read_empty_name(self):
data = b":foo"
with raises(HttpSyntaxException):
self._read(data)
def test_read_empty_value(self):
data = b"bar:"
headers = self._read(data)
assert headers.fields == ((b"bar", b""),)
def test_read_chunked():
req = treq(content=None)
req.headers["Transfer-Encoding"] = "chunked"
data = b"1\r\na\r\n0\r\n"
with raises(HttpSyntaxException):
b"".join(_read_chunked(BytesIO(data)))
data = b"1\r\na\r\n0\r\n\r\n"
assert b"".join(_read_chunked(BytesIO(data))) == b"a"
data = b"\r\n\r\n1\r\na\r\n1\r\nb\r\n0\r\n\r\n"
assert b"".join(_read_chunked(BytesIO(data))) == b"ab"
data = b"\r\n"
with raises("closed prematurely"):
b"".join(_read_chunked(BytesIO(data)))
data = b"1\r\nfoo"
with raises("malformed chunked body"):
b"".join(_read_chunked(BytesIO(data)))
data = b"foo\r\nfoo"
with raises(HttpSyntaxException):
b"".join(_read_chunked(BytesIO(data)))
data = b"5\r\naaaaa\r\n0\r\n\r\n"
with raises("too large"):
b"".join(_read_chunked(BytesIO(data), limit=2))
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
12,
4629,
199,
199,
504,
5890,
492,
11808,
199,
504,
1683,
492,
4420,
199,
646,
4613,
199,
199,
504,
1851,
773,
14,
3924,
492,
4760,
1726,
12,
4760,
16626,
1726,
12,
4760,
3284,
16761,
12,
377,
1850,
16761,
199,
504,
1851,
773,
14,
1014,
492,
21391,
199,
504,
1851,
773,
14,
1014,
14,
1014,
17,
14,
739,
492,
334,
272,
1586,
63,
1069,
12,
1586,
63,
1310,
12,
1586,
63,
1069,
63,
2993,
12,
272,
1586,
63,
1310,
63,
2993,
12,
1586,
63,
2030,
12,
1950,
63,
1600,
12,
1420,
63,
1014,
63,
2030,
63,
890,
12,
485,
362,
63,
2246,
63,
604,
12,
272,
485,
739,
63,
1069,
63,
604,
12,
485,
1122,
63,
23635,
63,
964,
12,
485,
739,
63,
1310,
63,
604,
12,
485,
1074,
63,
1014,
63,
1023,
12,
272,
485,
739,
63,
2139,
12,
485,
739,
63,
19955,
12,
664,
63,
1291,
63,
4504,
199,
9,
199,
504,
1851,
773,
14,
84,
1208,
492,
307,
2103,
12,
307,
4518,
12,
6534,
199,
504,
1851,
773,
492,
4967,
421,
199,
318,
511,
63,
362,
63,
1291,
63,
4504,
837,
272,
2323,
275,
21391,
342,
272,
702,
664,
63,
1291,
63,
4504,
8,
2139,
12,
298,
1421,
531,
508,
942,
272,
2323,
905,
1421,
937,
275,
298,
1700,
2,
272,
702,
664,
63,
1291,
63,
4504,
8,
2139,
12,
298,
1421,
531,
508,
2097,
1700,
937,
272,
2323,
905,
1421,
937,
275,
298,
1700,
12,
14164,
316,
2,
272,
702,
664,
63,
1291,
63,
4504,
8,
2139,
12,
298,
1421,
531,
508,
2097,
1700,
401,
298,
2392,
316,
937,
272,
2323,
14,
409,
63,
452,
480,
1421,
401,
2097,
1700,
12,
14164,
316,
401,
298,
79,
2292,
3135,
272,
702,
664,
63,
1291,
63,
4504,
8,
2139,
12,
298,
1421,
531,
508,
2097,
1700,
401,
298,
2392,
316,
401,
298,
79,
2292,
937,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
1210,
401,
359,
272,
330,
2,
2970,
1182,
3101,
15,
17,
14,
17,
60,
82,
60,
78,
60,
82,
60,
561,
5194,
401,
272,
330,
2,
2970,
221,
1182,
3101,
15,
17,
14,
17,
60,
82,
60,
78,
60,
82,
60,
561,
5194,
401,
272,
330,
2,
2970,
221,
1182,
221,
3101,
15,
17,
14,
17,
60,
82,
60,
78,
60,
82,
60,
561,
5194,
401,
272,
330,
2,
2970,
257,
1182,
257,
3101,
15,
17,
14,
17,
257,
971,
82,
60,
78,
60,
82,
60,
561,
5194,
401,
199,
566,
199,
318,
511,
63,
739,
63,
1069,
8,
1210,
304,
272,
519,
493,
275,
11808,
8,
1210,
9,
272,
519,
275,
1586,
63,
1069,
8,
23830,
9,
272,
702,
519,
14,
765,
508,
298,
2970,
2,
272,
702,
519,
14,
1317,
508,
330,
341,
272,
702,
519,
14,
1014,
63,
1023,
508,
298,
2856,
15,
17,
14,
17,
2,
272,
702,
519,
14,
3954,
63,
500,
272,
702,
519,
493,
14,
739,
342,
508,
330,
2,
2759,
2,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
1210,
401,
359,
272,
330,
2,
14657,
520,
16,
378,
401,
199,
566,
199,
318,
511,
63,
739,
63,
1069,
63,
705,
8,
1210,
304,
272,
519,
493,
275,
11808,
8,
1210,
9,
272,
6534,
8,
3924,
14,
5779,
1726,
12,
1586,
63,
1069,
12,
519,
493,
9,
421,
199,
318,
511,
63,
739,
63,
1069,
63,
2993,
837,
272,
519,
493,
275,
11808,
8,
267,
330,
2,
2970,
1182,
3101,
15,
17,
14,
17,
60,
82,
60,
78,
2,
267,
330,
2,
2714,
13,
4625,
26,
841,
60,
82,
60,
78,
2,
267,
330,
3212,
82,
60,
78,
2,
267,
330,
2,
2759,
2,
272,
776,
272,
519,
493,
14,
3958,
63,
25430,
275,
4420,
342,
272,
519,
493,
14,
2246,
63,
4414,
63,
3954,
275,
5685,
272,
519,
275,
1586,
63,
1069,
63,
2993,
8,
23830,
9,
272,
702,
519,
14,
765,
508,
298,
2970,
2,
272,
702,
519,
14,
2139,
905,
2714,
13,
4625,
937,
508,
298,
20,
2,
272,
702,
519,
14,
1317,
365,
488,
272,
702,
519,
493,
14,
3958,
63,
25430,
14,
3527,
272,
702,
519,
14,
3954,
63,
928,
508,
5685,
272,
702,
519,
493,
14,
739,
342,
508,
330,
2,
2759,
2,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
1210,
401,
359,
272,
330,
2,
2856,
15,
17,
14,
17,
841,
1085,
473,
6704,
282,
1565,
439,
357,
60,
82,
60,
78,
60,
82,
60,
78,
2030,
401,
272,
330,
2,
2856,
15,
17,
14,
17,
257,
841,
1085,
473,
6704,
282,
1565,
439,
357,
60,
82,
60,
78,
60,
82,
60,
78,
2030,
401,
272,
330,
2,
2856,
15,
17,
14,
17,
257,
841,
1085,
257,
473,
6704,
282,
1565,
439,
357,
60,
82,
60,
78,
60,
82,
60,
78,
2030,
401,
272,
330,
2,
2856,
15,
17,
14,
17,
257,
841,
1085,
257,
473,
6704,
282,
1565,
439,
357,
257,
971,
82,
60,
78,
60,
82,
60,
78,
2030,
401,
199,
566,
199,
318,
511,
63,
739,
63,
1310,
8,
1210,
304,
272,
2648,
275,
307,
2103,
342,
272,
519,
493,
275,
11808,
8,
1210,
9,
272,
519,
275,
1586,
63,
1310,
8,
23830,
12,
2648,
9,
272,
702,
519,
14,
1014,
63,
1023,
508,
298,
2856,
15,
17,
14,
17,
2,
272,
702,
519,
14,
1205,
63,
600,
508,
841,
1085,
272,
702,
519,
14,
5764,
508,
298,
41,
6704,
282,
1565,
439,
357,
2,
272,
702,
519,
14,
1317,
508,
330,
2,
2030,
2,
272,
702,
519,
14,
3954,
63,
500,
421,
199,
318,
511,
63,
739,
63,
1310,
63,
2993,
837,
272,
519,
493,
275,
11808,
8,
267,
330,
2,
2856,
15,
17,
14,
17,
841,
1085,
473,
6704,
282,
1565,
439,
357,
60,
82,
60,
78,
2,
267,
330,
2,
2714,
13,
4625,
26,
841,
60,
82,
60,
78,
2,
267,
330,
3212,
82,
60,
78,
2,
267,
330,
2,
2759,
2,
272,
776,
272,
519,
493,
14,
3958,
63,
25430,
275,
4420,
342,
272,
519,
493,
14,
2246,
63,
4414,
63,
3954,
275,
5685,
272,
519,
275,
1586,
63,
1310,
63,
2993,
8,
23830,
9,
272,
702,
519,
14,
1205,
63,
600
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
12,
4629,
199,
199,
504,
5890,
492,
11808,
199,
504,
1683,
492,
4420,
199,
646,
4613,
199,
199,
504,
1851,
773,
14,
3924,
492,
4760,
1726,
12,
4760,
16626,
1726,
12,
4760,
3284,
16761,
12,
377,
1850,
16761,
199,
504,
1851,
773,
14,
1014,
492,
21391,
199,
504,
1851,
773,
14,
1014,
14,
1014,
17,
14,
739,
492,
334,
272,
1586,
63,
1069,
12,
1586,
63,
1310,
12,
1586,
63,
1069,
63,
2993,
12,
272,
1586,
63,
1310,
63,
2993,
12,
1586,
63,
2030,
12,
1950,
63,
1600,
12,
1420,
63,
1014,
63,
2030,
63,
890,
12,
485,
362,
63,
2246,
63,
604,
12,
272,
485,
739,
63,
1069,
63,
604,
12,
485,
1122,
63,
23635,
63,
964,
12,
485,
739,
63,
1310,
63,
604,
12,
485,
1074,
63,
1014,
63,
1023,
12,
272,
485,
739,
63,
2139,
12,
485,
739,
63,
19955,
12,
664,
63,
1291,
63,
4504,
199,
9,
199,
504,
1851,
773,
14,
84,
1208,
492,
307,
2103,
12,
307,
4518,
12,
6534,
199,
504,
1851,
773,
492,
4967,
421,
199,
318,
511,
63,
362,
63,
1291,
63,
4504,
837,
272,
2323,
275,
21391,
342,
272,
702,
664,
63,
1291,
63,
4504,
8,
2139,
12,
298,
1421,
531,
508,
942,
272,
2323,
905,
1421,
937,
275,
298,
1700,
2,
272,
702,
664,
63,
1291,
63,
4504,
8,
2139,
12,
298,
1421,
531,
508,
2097,
1700,
937,
272,
2323,
905,
1421,
937,
275,
298,
1700,
12,
14164,
316,
2,
272,
702,
664,
63,
1291,
63,
4504,
8,
2139,
12,
298,
1421,
531,
508,
2097,
1700,
401,
298,
2392,
316,
937,
272,
2323,
14,
409,
63,
452,
480,
1421,
401,
2097,
1700,
12,
14164,
316,
401,
298,
79,
2292,
3135,
272,
702,
664,
63,
1291,
63,
4504,
8,
2139,
12,
298,
1421,
531,
508,
2097,
1700,
401,
298,
2392,
316,
401,
298,
79,
2292,
937,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
1210,
401,
359,
272,
330,
2,
2970,
1182,
3101,
15,
17,
14,
17,
60,
82,
60,
78,
60,
82,
60,
561,
5194,
401,
272,
330,
2,
2970,
221,
1182,
3101,
15,
17,
14,
17,
60,
82,
60,
78,
60,
82,
60,
561,
5194,
401,
272,
330,
2,
2970,
221,
1182,
221,
3101,
15,
17,
14,
17,
60,
82,
60,
78,
60,
82,
60,
561,
5194,
401,
272,
330,
2,
2970,
257,
1182,
257,
3101,
15,
17,
14,
17,
257,
971,
82,
60,
78,
60,
82,
60,
561,
5194,
401,
199,
566,
199,
318,
511,
63,
739,
63,
1069,
8,
1210,
304,
272,
519,
493,
275,
11808,
8,
1210,
9,
272,
519,
275,
1586,
63,
1069,
8,
23830,
9,
272,
702,
519,
14,
765,
508,
298,
2970,
2,
272,
702,
519,
14,
1317,
508,
330,
341,
272,
702,
519,
14,
1014,
63,
1023,
508,
298,
2856,
15,
17,
14,
17,
2,
272,
702,
519,
14,
3954,
63,
500,
272,
702,
519,
493,
14,
739,
342,
508,
330,
2,
2759,
2,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
1210,
401,
359,
272,
330,
2,
14657,
520,
16,
378,
401,
199,
566,
199,
318,
511,
63,
739,
63,
1069,
63,
705,
8,
1210,
304,
272,
519,
493,
275,
11808,
8,
1210,
9,
272,
6534,
8,
3924,
14,
5779,
1726,
12,
1586,
63,
1069,
12,
519,
493,
9,
421,
199,
318,
511,
63,
739,
63,
1069,
63,
2993,
837,
272,
519,
493,
275,
11808,
8,
267,
330,
2,
2970,
1182,
3101,
15,
17,
14,
17,
60,
82,
60,
78,
2,
267,
330,
2,
2714,
13,
4625,
26,
841,
60,
82,
60,
78,
2,
267,
330,
3212,
82,
60,
78,
2,
267,
330,
2,
2759,
2,
272,
776,
272,
519,
493,
14,
3958,
63,
25430,
275,
4420,
342,
272,
519,
493,
14,
2246,
63,
4414,
63,
3954,
275,
5685,
272,
519,
275,
1586,
63,
1069,
63,
2993,
8,
23830,
9,
272,
702,
519,
14,
765,
508,
298,
2970,
2,
272,
702,
519,
14,
2139,
905,
2714,
13,
4625,
937,
508,
298,
20,
2,
272,
702,
519,
14,
1317,
365,
488,
272,
702,
519,
493,
14,
3958,
63,
25430,
14,
3527,
272,
702,
519,
14,
3954,
63,
928,
508,
5685,
272,
702,
519,
493,
14,
739,
342,
508,
330,
2,
2759,
2,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
1210,
401,
359,
272,
330,
2,
2856,
15,
17,
14,
17,
841,
1085,
473,
6704,
282,
1565,
439,
357,
60,
82,
60,
78,
60,
82,
60,
78,
2030,
401,
272,
330,
2,
2856,
15,
17,
14,
17,
257,
841,
1085,
473,
6704,
282,
1565,
439,
357,
60,
82,
60,
78,
60,
82,
60,
78,
2030,
401,
272,
330,
2,
2856,
15,
17,
14,
17,
257,
841,
1085,
257,
473,
6704,
282,
1565,
439,
357,
60,
82,
60,
78,
60,
82,
60,
78,
2030,
401,
272,
330,
2,
2856,
15,
17,
14,
17,
257,
841,
1085,
257,
473,
6704,
282,
1565,
439,
357,
257,
971,
82,
60,
78,
60,
82,
60,
78,
2030,
401,
199,
566,
199,
318,
511,
63,
739,
63,
1310,
8,
1210,
304,
272,
2648,
275,
307,
2103,
342,
272,
519,
493,
275,
11808,
8,
1210,
9,
272,
519,
275,
1586,
63,
1310,
8,
23830,
12,
2648,
9,
272,
702,
519,
14,
1014,
63,
1023,
508,
298,
2856,
15,
17,
14,
17,
2,
272,
702,
519,
14,
1205,
63,
600,
508,
841,
1085,
272,
702,
519,
14,
5764,
508,
298,
41,
6704,
282,
1565,
439,
357,
2,
272,
702,
519,
14,
1317,
508,
330,
2,
2030,
2,
272,
702,
519,
14,
3954,
63,
500,
421,
199,
318,
511,
63,
739,
63,
1310,
63,
2993,
837,
272,
519,
493,
275,
11808,
8,
267,
330,
2,
2856,
15,
17,
14,
17,
841,
1085,
473,
6704,
282,
1565,
439,
357,
60,
82,
60,
78,
2,
267,
330,
2,
2714,
13,
4625,
26,
841,
60,
82,
60,
78,
2,
267,
330,
3212,
82,
60,
78,
2,
267,
330,
2,
2759,
2,
272,
776,
272,
519,
493,
14,
3958,
63,
25430,
275,
4420,
342,
272,
519,
493,
14,
2246,
63,
4414,
63,
3954,
275,
5685,
272,
519,
275,
1586,
63,
1310,
63,
2993,
8,
23830,
9,
272,
702,
519,
14,
1205,
63,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Flumotion/flumotion
|
flumotion/test/bouncertest.py
|
3
|
1796
|
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
# Flumotion - a streaming media server
# Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L.
# Copyright (C) 2010,2011 Flumotion Services, S.A.
# All rights reserved.
#
# This file may be distributed and/or modified under the terms of
# the GNU Lesser General Public License version 2.1 as published by
# the Free Software Foundation.
# This file is distributed without any warranty; without even the implied
# warranty of merchantability or fitness for a particular purpose.
# See "LICENSE.LGPL" in the source distribution for more information.
#
# Headers in this file shall remain intact.
from flumotion.common import testsuite
from twisted.internet import defer, reactor
from flumotion.common import keycards
class BouncerTestHelper(testsuite.TestCase):
bouncerClass = None
def _generate_config(self, properties):
conf = {'name': 'fake',
'avatarId': '/default/fake',
'plugs': {},
'properties': properties}
return conf
def get_bouncer(self, properties={}):
if not self.bouncerClass:
raise NotImplemented("Subclass should set bouncerClass")
return self.bouncerClass(self._generate_config(properties))
def stop_bouncer(self, bouncer, d):
def _stop(res):
bouncer.stop()
return res
return d.addBoth(_stop)
def check_auth(self, keycard, bouncer, successful):
def check_result(result):
if successful:
self.assertEquals(result.state, keycards.AUTHENTICATED)
else:
self.assertIdentical(result, None)
d = defer.maybeDeferred(bouncer.authenticate, keycard)
d.addCallback(check_result)
return d
|
lgpl-2.1
|
[
3,
1882,
4900,
26,
2018,
1882,
199,
3,
1321,
26,
338,
26,
386,
26,
3519,
29,
20,
26,
10329,
29,
20,
26,
1086,
29,
20,
199,
199,
3,
11040,
453,
23193,
446,
282,
18490,
5898,
1654,
199,
3,
1898,
334,
35,
9,
8353,
12,
9397,
12,
7968,
12,
9488,
12,
9300,
12,
8664,
481,
10836,
500,
79,
12,
428,
14,
44,
14,
199,
3,
1898,
334,
35,
9,
7129,
12,
8128,
11040,
453,
23193,
21813,
12,
428,
14,
33,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
570,
1443,
506,
1854,
436,
15,
269,
6042,
1334,
314,
2895,
402,
199,
3,
314,
1664,
6401,
1696,
1684,
844,
1015,
499,
14,
17,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
14,
199,
3,
961,
570,
365,
1854,
1928,
1263,
3750,
27,
1928,
2755,
314,
2478,
199,
3,
3750,
402,
4004,
26938,
3616,
503,
5542,
4171,
367,
282,
6770,
12016,
14,
199,
3,
1666,
298,
3961,
14,
44,
12006,
2,
315,
314,
1350,
4084,
367,
1655,
2556,
14,
199,
3,
199,
3,
21391,
315,
642,
570,
10989,
5706,
315,
4552,
14,
199,
199,
504,
2717,
453,
23193,
14,
2330,
492,
2295,
2577,
199,
199,
504,
7390,
14,
4901,
492,
10133,
12,
9655,
199,
199,
504,
2717,
453,
23193,
14,
2330,
492,
790,
13761,
421,
199,
533,
5088,
31794,
774,
4433,
8,
14239,
14,
1746,
304,
339,
1234,
31794,
2543,
275,
488,
339,
347,
485,
4208,
63,
888,
8,
277,
12,
4382,
304,
267,
3743,
275,
791,
354,
356,
283,
3183,
297,
355,
283,
14584,
1304,
356,
1994,
885,
15,
3183,
297,
355,
283,
1168,
85,
458,
356,
5479,
355,
283,
3282,
356,
4382,
93,
267,
372,
3743,
339,
347,
664,
63,
656,
31794,
8,
277,
12,
4382,
16420,
267,
340,
440,
291,
14,
656,
31794,
2543,
26,
288,
746,
3784,
480,
23636,
1077,
663,
1234,
31794,
2543,
531,
267,
372,
291,
14,
656,
31794,
2543,
8,
277,
423,
4208,
63,
888,
8,
3282,
430,
339,
347,
3631,
63,
656,
31794,
8,
277,
12,
1234,
31794,
12,
366,
304,
398,
347,
485,
2379,
8,
470,
304,
288,
1234,
31794,
14,
2379,
342,
288,
372,
522,
267,
372,
366,
14,
525,
18088,
1547,
2379,
9,
339,
347,
1104,
63,
1178,
8,
277,
12,
790,
5841,
12,
1234,
31794,
12,
9512,
304,
398,
347,
1104,
63,
1099,
8,
1099,
304,
288,
340,
9512,
26,
355,
291,
14,
2947,
8,
1099,
14,
929,
12,
790,
13761,
14,
22923,
6989,
9,
288,
587,
26,
355,
291,
14,
479,
22469,
8,
1099,
12,
488,
9,
267,
366,
275,
10133,
14,
11853,
9937,
8,
656,
31794,
14,
13975,
12,
790,
5841,
9,
267,
366,
14,
10053,
8,
1074,
63,
1099,
9,
267,
372,
366,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1882,
199,
3,
1321,
26,
338,
26,
386,
26,
3519,
29,
20,
26,
10329,
29,
20,
26,
1086,
29,
20,
199,
199,
3,
11040,
453,
23193,
446,
282,
18490,
5898,
1654,
199,
3,
1898,
334,
35,
9,
8353,
12,
9397,
12,
7968,
12,
9488,
12,
9300,
12,
8664,
481,
10836,
500,
79,
12,
428,
14,
44,
14,
199,
3,
1898,
334,
35,
9,
7129,
12,
8128,
11040,
453,
23193,
21813,
12,
428,
14,
33,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
570,
1443,
506,
1854,
436,
15,
269,
6042,
1334,
314,
2895,
402,
199,
3,
314,
1664,
6401,
1696,
1684,
844,
1015,
499,
14,
17,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
14,
199,
3,
961,
570,
365,
1854,
1928,
1263,
3750,
27,
1928,
2755,
314,
2478,
199,
3,
3750,
402,
4004,
26938,
3616,
503,
5542,
4171,
367,
282,
6770,
12016,
14,
199,
3,
1666,
298,
3961,
14,
44,
12006,
2,
315,
314,
1350,
4084,
367,
1655,
2556,
14,
199,
3,
199,
3,
21391,
315,
642,
570,
10989,
5706,
315,
4552,
14,
199,
199,
504,
2717,
453,
23193,
14,
2330,
492,
2295,
2577,
199,
199,
504,
7390,
14,
4901,
492,
10133,
12,
9655,
199,
199,
504,
2717,
453,
23193,
14,
2330,
492,
790,
13761,
421,
199,
533,
5088,
31794,
774,
4433,
8,
14239,
14,
1746,
304,
339,
1234,
31794,
2543,
275,
488,
339,
347,
485,
4208,
63,
888,
8,
277,
12,
4382,
304,
267,
3743,
275,
791,
354,
356,
283,
3183,
297,
355,
283,
14584,
1304,
356,
1994,
885,
15,
3183,
297,
355,
283,
1168,
85,
458,
356,
5479,
355,
283,
3282,
356,
4382,
93,
267,
372,
3743,
339,
347,
664,
63,
656,
31794,
8,
277,
12,
4382,
16420,
267,
340,
440,
291,
14,
656,
31794,
2543,
26,
288,
746,
3784,
480,
23636,
1077,
663,
1234,
31794,
2543,
531,
267,
372,
291,
14,
656,
31794,
2543,
8,
277,
423,
4208,
63,
888,
8,
3282,
430,
339,
347,
3631,
63,
656,
31794,
8,
277,
12,
1234,
31794,
12,
366,
304,
398,
347,
485,
2379,
8,
470,
304,
288,
1234,
31794,
14,
2379,
342,
288,
372,
522,
267,
372,
366,
14,
525,
18088,
1547,
2379,
9,
339,
347,
1104,
63,
1178,
8,
277,
12,
790,
5841,
12,
1234,
31794,
12,
9512,
304,
398,
347,
1104,
63,
1099,
8,
1099,
304,
288,
340,
9512,
26,
355,
291,
14,
2947,
8,
1099,
14,
929,
12,
790,
13761,
14,
22923,
6989,
9,
288,
587,
26,
355,
291,
14,
479,
22469,
8,
1099,
12,
488,
9,
267,
366,
275,
10133,
14,
11853,
9937,
8,
656,
31794,
14,
13975,
12,
790,
5841,
9,
267,
366,
14,
10053,
8,
1074,
63,
1099,
9,
267,
372,
366,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
sahitya-pavurala/luigi
|
luigi/contrib/esindex.py
|
29
|
14121
|
# -*- coding: utf-8 -*-
#
# Copyright 2012-2015 Spotify AB
#
# 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.
#
"""
Support for Elasticsearch (1.0.0 or newer).
Provides an :class:`ElasticsearchTarget` and a :class:`CopyToIndex` template task.
Modeled after :class:`luigi.contrib.rdbms.CopyToTable`.
A minimal example (assuming elasticsearch is running on localhost:9200):
.. code-block:: python
class ExampleIndex(CopyToIndex):
index = 'example'
def docs(self):
return [{'_id': 1, 'title': 'An example document.'}]
if __name__ == '__main__':
task = ExampleIndex()
luigi.build([task], local_scheduler=True)
All options:
.. code-block:: python
class ExampleIndex(CopyToIndex):
host = 'localhost'
port = 9200
index = 'example'
doc_type = 'default'
purge_existing_index = True
marker_index_hist_size = 1
def docs(self):
return [{'_id': 1, 'title': 'An example document.'}]
if __name__ == '__main__':
task = ExampleIndex()
luigi.build([task], local_scheduler=True)
`Host`, `port`, `index`, `doc_type` parameters are standard elasticsearch.
`purge_existing_index` will delete the index, whenever an update is required.
This is useful, when one deals with "dumps" that represent the whole data, not just updates.
`marker_index_hist_size` sets the maximum number of entries in the 'marker'
index:
* 0 (default) keeps all updates,
* 1 to only remember the most recent update to the index.
This can be useful, if an index needs to recreated, even though
the corresponding indexing task has been run sometime in the past - but
a later indexing task might have altered the index in the meantime.
There are a two luigi `luigi.cfg` configuration options:
.. code-block:: ini
[elasticsearch]
marker-index = update_log
marker-doc-type = entry
"""
# pylint: disable=F0401,E1101,C0103
import abc
import datetime
import hashlib
import json
import logging
import itertools
import luigi
from luigi import six
logger = logging.getLogger('luigi-interface')
try:
import elasticsearch
if elasticsearch.__version__ < (1, 0, 0):
logger.warning("This module works with elasticsearch 1.0.0 "
"or newer only.")
from elasticsearch.helpers import bulk
from elasticsearch.connection import Urllib3HttpConnection
except ImportError:
logger.warning("Loading esindex module without elasticsearch installed. "
"Will crash at runtime if esindex functionality is used.")
class ElasticsearchTarget(luigi.Target):
""" Target for a resource in Elasticsearch."""
marker_index = luigi.configuration.get_config().get('elasticsearch',
'marker-index', 'update_log')
marker_doc_type = luigi.configuration.get_config().get('elasticsearch',
'marker-doc-type', 'entry')
def __init__(self, host, port, index, doc_type, update_id,
marker_index_hist_size=0, http_auth=None, timeout=10,
extra_elasticsearch_args={}):
"""
:param host: Elasticsearch server host
:type host: str
:param port: Elasticsearch server port
:type port: int
:param index: index name
:type index: str
:param doc_type: doctype name
:type doc_type: str
:param update_id: an identifier for this data set
:type update_id: str
:param marker_index_hist_size: list of changes to the index to remember
:type marker_index_hist_size: int
:param timeout: Elasticsearch connection timeout
:type timeout: int
:param extra_elasticsearch_args: extra args for Elasticsearch
:type Extra: dict
"""
self.host = host
self.port = port
self.http_auth = http_auth
self.index = index
self.doc_type = doc_type
self.update_id = update_id
self.marker_index_hist_size = marker_index_hist_size
self.timeout = timeout
self.extra_elasticsearch_args = extra_elasticsearch_args
self.es = elasticsearch.Elasticsearch(
connection_class=Urllib3HttpConnection,
host=self.host,
port=self.port,
http_auth=self.http_auth,
timeout=self.timeout,
**self.extra_elasticsearch_args
)
def marker_index_document_id(self):
"""
Generate an id for the indicator document.
"""
params = '%s:%s:%s' % (self.index, self.doc_type, self.update_id)
return hashlib.sha1(params.encode('utf-8')).hexdigest()
def touch(self):
"""
Mark this update as complete.
The document id would be sufficent but,
for documentation,
we index the parameters `update_id`, `target_index`, `target_doc_type` and `date` as well.
"""
self.create_marker_index()
self.es.index(index=self.marker_index, doc_type=self.marker_doc_type,
id=self.marker_index_document_id(), body={
'update_id': self.update_id,
'target_index': self.index,
'target_doc_type': self.doc_type,
'date': datetime.datetime.now()})
self.es.indices.flush(index=self.marker_index)
self.ensure_hist_size()
def exists(self):
"""
Test, if this task has been run.
"""
try:
self.es.get(index=self.marker_index, doc_type=self.marker_doc_type, id=self.marker_index_document_id())
return True
except elasticsearch.NotFoundError:
logger.debug('Marker document not found.')
except elasticsearch.ElasticsearchException as err:
logger.warn(err)
return False
def create_marker_index(self):
"""
Create the index that will keep track of the tasks if necessary.
"""
if not self.es.indices.exists(index=self.marker_index):
self.es.indices.create(index=self.marker_index)
def ensure_hist_size(self):
"""
Shrink the history of updates for
a `index/doc_type` combination down to `self.marker_index_hist_size`.
"""
if self.marker_index_hist_size == 0:
return
result = self.es.search(index=self.marker_index,
doc_type=self.marker_doc_type,
body={'query': {
'term': {'target_index': self.index}}},
sort=('date:desc',))
for i, hit in enumerate(result.get('hits').get('hits'), start=1):
if i > self.marker_index_hist_size:
marker_document_id = hit.get('_id')
self.es.delete(id=marker_document_id, index=self.marker_index,
doc_type=self.marker_doc_type)
self.es.indices.flush(index=self.marker_index)
class CopyToIndex(luigi.Task):
"""
Template task for inserting a data set into Elasticsearch.
Usage:
1. Subclass and override the required `index` attribute.
2. Implement a custom `docs` method, that returns an iterable over the documents.
A document can be a JSON string,
e.g. from a newline-delimited JSON (ldj) file (default implementation)
or some dictionary.
Optional attributes:
* doc_type (default),
* host (localhost),
* port (9200),
* settings ({'settings': {}})
* mapping (None),
* chunk_size (2000),
* raise_on_error (True),
* purge_existing_index (False),
* marker_index_hist_size (0)
If settings are defined, they are only applied at index creation time.
"""
@property
def host(self):
"""
ES hostname.
"""
return 'localhost'
@property
def port(self):
"""
ES port.
"""
return 9200
@property
def http_auth(self):
"""
ES optional http auth information as either ‘:’ separated string or a tuple,
e.g. `('user', 'pass')` or `"user:pass"`.
"""
return None
@abc.abstractproperty
def index(self):
"""
The target index.
May exist or not.
"""
return None
@property
def doc_type(self):
"""
The target doc_type.
"""
return 'default'
@property
def mapping(self):
"""
Dictionary with custom mapping or `None`.
"""
return None
@property
def settings(self):
"""
Settings to be used at index creation time.
"""
return {'settings': {}}
@property
def chunk_size(self):
"""
Single API call for this number of docs.
"""
return 2000
@property
def raise_on_error(self):
"""
Whether to fail fast.
"""
return True
@property
def purge_existing_index(self):
"""
Whether to delete the `index` completely before any indexing.
"""
return False
@property
def marker_index_hist_size(self):
"""
Number of event log entries in the marker index. 0: unlimited.
"""
return 0
@property
def timeout(self):
"""
Timeout.
"""
return 10
@property
def extra_elasticsearch_args(self):
"""
Extra arguments to pass to the Elasticsearch constructor
"""
return {}
def docs(self):
"""
Return the documents to be indexed.
Beside the user defined fields, the document may contain an `_index`, `_type` and `_id`.
"""
with self.input().open('r') as fobj:
for line in fobj:
yield line
# everything below will rarely have to be overridden
def _docs(self):
"""
Since `self.docs` may yield documents that do not explicitly contain `_index` or `_type`,
add those attributes here, if necessary.
"""
iterdocs = iter(self.docs())
first = next(iterdocs)
needs_parsing = False
if isinstance(first, six.string_types):
needs_parsing = True
elif isinstance(first, dict):
pass
else:
raise RuntimeError('Document must be either JSON strings or dict.')
for doc in itertools.chain([first], iterdocs):
if needs_parsing:
doc = json.loads(doc)
if '_index' not in doc:
doc['_index'] = self.index
if '_type' not in doc:
doc['_type'] = self.doc_type
yield doc
def _init_connection(self):
return elasticsearch.Elasticsearch(
connection_class=Urllib3HttpConnection,
host=self.host,
port=self.port,
http_auth=self.http_auth,
timeout=self.timeout,
**self.extra_elasticsearch_args
)
def create_index(self):
"""
Override to provide code for creating the target index.
By default it will be created without any special settings or mappings.
"""
es = self._init_connection()
if not es.indices.exists(index=self.index):
es.indices.create(index=self.index, body=self.settings)
def delete_index(self):
"""
Delete the index, if it exists.
"""
es = self._init_connection()
if es.indices.exists(index=self.index):
es.indices.delete(index=self.index)
def update_id(self):
"""
This id will be a unique identifier for this indexing task.
"""
return self.task_id
def output(self):
"""
Returns a ElasticsearchTarget representing the inserted dataset.
Normally you don't override this.
"""
return ElasticsearchTarget(
host=self.host,
port=self.port,
http_auth=self.http_auth,
index=self.index,
doc_type=self.doc_type,
update_id=self.update_id(),
marker_index_hist_size=self.marker_index_hist_size,
timeout=self.timeout,
extra_elasticsearch_args=self.extra_elasticsearch_args
)
def run(self):
"""
Run task, namely:
* purge existing index, if requested (`purge_existing_index`),
* create the index, if missing,
* apply mappings, if given,
* set refresh interval to -1 (disable) for performance reasons,
* bulk index in batches of size `chunk_size` (2000),
* set refresh interval to 1s,
* refresh Elasticsearch,
* create entry in marker index.
"""
if self.purge_existing_index:
self.delete_index()
self.create_index()
es = self._init_connection()
if self.mapping:
es.indices.put_mapping(index=self.index, doc_type=self.doc_type,
body=self.mapping)
es.indices.put_settings({"index": {"refresh_interval": "-1"}},
index=self.index)
bulk(es, self._docs(), chunk_size=self.chunk_size,
raise_on_error=self.raise_on_error)
es.indices.put_settings({"index": {"refresh_interval": "1s"}},
index=self.index)
es.indices.refresh()
self.output().touch()
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6029,
13,
7806,
428,
555,
3338,
14840,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
624,
199,
11532,
367,
19509,
1733,
334,
17,
14,
16,
14,
16,
503,
15666,
680,
199,
199,
17473,
376,
520,
533,
1705,
27822,
1733,
4277,
64,
436,
282,
520,
533,
1705,
5116,
1378,
2681,
64,
1978,
2120,
14,
199,
199,
1385,
1146,
2410,
520,
533,
1705,
26795,
14,
2828,
14,
82,
697,
706,
14,
5116,
1378,
3186,
2313,
199,
199,
33,
13460,
2893,
334,
405,
12848,
24380,
1733,
365,
3879,
641,
11667,
26,
25,
1840,
304,
199,
199,
703,
1233,
13,
1457,
447,
2366,
339,
1021,
5679,
2681,
8,
5116,
1378,
2681,
304,
267,
1478,
275,
283,
2694,
7,
398,
347,
9149,
8,
277,
304,
288,
372,
9016,
63,
344,
356,
413,
12,
283,
1213,
356,
283,
2493,
2893,
2213,
14,
20623,
339,
340,
636,
354,
363,
508,
2560,
973,
3706,
267,
2120,
275,
5679,
2681,
342,
267,
19485,
14,
1506,
779,
1765,
467,
2257,
63,
8874,
29,
549,
9,
199,
199,
2422,
1511,
26,
199,
199,
703,
1233,
13,
1457,
447,
2366,
339,
1021,
5679,
2681,
8,
5116,
1378,
2681,
304,
267,
1591,
275,
283,
5967,
7,
267,
1844,
275,
1749,
1840,
267,
1478,
275,
283,
2694,
7,
267,
1382,
63,
466,
275,
283,
885,
7,
267,
18503,
63,
5952,
63,
1080,
275,
715,
267,
3608,
63,
1080,
63,
11141,
63,
890,
275,
413,
398,
347,
9149,
8,
277,
304,
288,
372,
9016,
63,
344,
356,
413,
12,
283,
1213,
356,
283,
2493,
2893,
2213,
14,
20623,
339,
340,
636,
354,
363,
508,
2560,
973,
3706,
267,
2120,
275,
5679,
2681,
342,
267,
19485,
14,
1506,
779,
1765,
467,
2257,
63,
8874,
29,
549,
9,
199,
199,
64,
4965,
3559,
658,
719,
3559,
658,
1080,
3559,
658,
1301,
63,
466,
64,
2633,
787,
4465,
24380,
1733,
14,
199,
199,
64,
18254,
63,
5952,
63,
1080,
64,
911,
3145,
314,
1478,
12,
18119,
376,
1678,
365,
1415,
14,
199,
2765,
365,
2997,
12,
1380,
1373,
477,
2551,
543,
298,
4180,
2,
626,
2954,
314,
8852,
666,
12,
440,
2951,
7029,
14,
199,
199,
64,
4211,
63,
1080,
63,
11141,
63,
890,
64,
5951,
314,
5696,
1329,
402,
4811,
315,
314,
283,
4211,
7,
199,
1080,
26,
199,
199,
10,
378,
334,
885,
9,
18578,
1006,
7029,
12,
199,
10,
413,
370,
1454,
21027,
314,
4750,
8058,
1678,
370,
314,
1478,
14,
199,
199,
2765,
883,
506,
2997,
12,
340,
376,
1478,
4839,
370,
295,
3966,
12,
2755,
10617,
199,
1589,
5226,
16356,
2120,
965,
2757,
1255,
2005,
521,
315,
314,
13541,
446,
1325,
199,
65,
2945,
16356,
2120,
5594,
1172,
29815,
314,
1478,
315,
314,
4615,
521,
14,
199,
199,
10924,
787,
282,
2877,
19485,
658,
26795,
14,
4128,
64,
2897,
1511,
26,
199,
199,
703,
1233,
13,
1457,
447,
20364,
339,
359,
25651,
61,
339,
3608,
13,
1080,
275,
1678,
63,
793,
272,
3608,
13,
1301,
13,
466,
275,
2397,
199,
199,
624,
199,
199,
3,
4287,
26,
3507,
29,
38,
28025,
12,
37,
24827,
12,
35,
28399,
199,
646,
13022,
199,
646,
2197,
199,
646,
8337,
199,
646,
2022,
199,
646,
2050,
199,
646,
7975,
199,
199,
646,
19485,
199,
199,
504,
19485,
492,
3816,
199,
199,
2921,
275,
2050,
14,
5572,
360,
26795,
13,
3266,
358,
199,
199,
893,
26,
272,
492,
24380,
1733,
272,
340,
24380,
1733,
855,
1023,
363,
665,
334,
17,
12,
378,
12,
378,
304,
267,
2512,
14,
3764,
480,
2765,
859,
5419,
543,
24380,
1733,
413,
14,
16,
14,
16,
298,
2432,
298,
269,
15666,
1454,
2685,
272,
687,
24380,
1733,
14,
7546,
492,
13137,
272,
687,
24380,
1733,
14,
2105,
492,
20503,
773,
19,
5779,
3225,
199,
199,
2590,
3545,
26,
272,
2512,
14,
3764,
480,
19236,
9455,
1080,
859,
1928,
24380,
1733,
4903,
14,
298,
673,
298,
20326,
12420,
737,
8836,
340,
9455,
1080,
9330,
365,
1202,
2685,
421,
199,
533,
19509,
1733,
4277,
8,
26795,
14,
4277,
304,
272,
408,
10256,
367,
282,
2073,
315,
19509,
1733,
1041,
339,
3608,
63,
1080,
275,
19485,
14,
4758,
14,
362,
63,
888,
1252,
362,
360,
25651,
297,
9144,
283,
4211,
13,
1080,
297,
283,
873,
63,
793,
358,
272,
3608,
63,
1301,
63,
466,
275,
19485,
14,
4758,
14,
362,
63,
888,
1252,
362,
360,
25651,
297,
15491,
283,
4211,
13,
1301,
13,
466,
297,
283,
2373,
358,
339,
347,
636,
826,
721,
277,
12,
1591,
12,
1844,
12,
1478,
12,
1382,
63,
466,
12,
1678,
63,
344,
12,
326,
3608,
63,
1080,
63,
11141,
63,
890,
29,
16,
12,
1455,
63,
1178,
29,
403,
12,
2653,
29,
709,
12,
326,
2402,
63,
25651,
63,
589,
16420,
267,
408,
267,
520,
635,
1591,
26,
19509,
1733,
1654,
1591,
267,
520,
466,
1591,
26,
620,
267,
520,
635,
1844,
26,
19509,
1733,
1654,
1844,
267,
520,
466,
1844,
26,
1109,
267,
520,
635,
1478,
26,
1478,
536,
267,
520,
466,
1478,
26,
620,
267,
520,
635,
1382,
63,
466,
26,
13265,
536,
267,
520,
466,
1382,
63,
466,
26,
620,
267,
520,
635,
1678,
63,
344,
26,
376,
5148,
367,
642,
666,
663,
267,
520,
466,
1678,
63,
344,
26,
620,
267,
520,
635,
3608,
63,
1080,
63,
11141,
63,
890,
26,
769,
402,
4493,
370,
314,
1478,
370,
21027,
267,
520,
466,
3608,
63,
1080,
63,
11141,
63,
890,
26,
1109,
267
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6029,
13,
7806,
428,
555,
3338,
14840,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
624,
199,
11532,
367,
19509,
1733,
334,
17,
14,
16,
14,
16,
503,
15666,
680,
199,
199,
17473,
376,
520,
533,
1705,
27822,
1733,
4277,
64,
436,
282,
520,
533,
1705,
5116,
1378,
2681,
64,
1978,
2120,
14,
199,
199,
1385,
1146,
2410,
520,
533,
1705,
26795,
14,
2828,
14,
82,
697,
706,
14,
5116,
1378,
3186,
2313,
199,
199,
33,
13460,
2893,
334,
405,
12848,
24380,
1733,
365,
3879,
641,
11667,
26,
25,
1840,
304,
199,
199,
703,
1233,
13,
1457,
447,
2366,
339,
1021,
5679,
2681,
8,
5116,
1378,
2681,
304,
267,
1478,
275,
283,
2694,
7,
398,
347,
9149,
8,
277,
304,
288,
372,
9016,
63,
344,
356,
413,
12,
283,
1213,
356,
283,
2493,
2893,
2213,
14,
20623,
339,
340,
636,
354,
363,
508,
2560,
973,
3706,
267,
2120,
275,
5679,
2681,
342,
267,
19485,
14,
1506,
779,
1765,
467,
2257,
63,
8874,
29,
549,
9,
199,
199,
2422,
1511,
26,
199,
199,
703,
1233,
13,
1457,
447,
2366,
339,
1021,
5679,
2681,
8,
5116,
1378,
2681,
304,
267,
1591,
275,
283,
5967,
7,
267,
1844,
275,
1749,
1840,
267,
1478,
275,
283,
2694,
7,
267,
1382,
63,
466,
275,
283,
885,
7,
267,
18503,
63,
5952,
63,
1080,
275,
715,
267,
3608,
63,
1080,
63,
11141,
63,
890,
275,
413,
398,
347,
9149,
8,
277,
304,
288,
372,
9016,
63,
344,
356,
413,
12,
283,
1213,
356,
283,
2493,
2893,
2213,
14,
20623,
339,
340,
636,
354,
363,
508,
2560,
973,
3706,
267,
2120,
275,
5679,
2681,
342,
267,
19485,
14,
1506,
779,
1765,
467,
2257,
63,
8874,
29,
549,
9,
199,
199,
64,
4965,
3559,
658,
719,
3559,
658,
1080,
3559,
658,
1301,
63,
466,
64,
2633,
787,
4465,
24380,
1733,
14,
199,
199,
64,
18254,
63,
5952,
63,
1080,
64,
911,
3145,
314,
1478,
12,
18119,
376,
1678,
365,
1415,
14,
199,
2765,
365,
2997,
12,
1380,
1373,
477,
2551,
543,
298,
4180,
2,
626,
2954,
314,
8852,
666,
12,
440,
2951,
7029,
14,
199,
199,
64,
4211,
63,
1080,
63,
11141,
63,
890,
64,
5951,
314,
5696,
1329,
402,
4811,
315,
314,
283,
4211,
7,
199,
1080,
26,
199,
199,
10,
378,
334,
885,
9,
18578,
1006,
7029,
12,
199,
10,
413,
370,
1454,
21027,
314,
4750,
8058,
1678,
370,
314,
1478,
14,
199,
199,
2765,
883,
506,
2997,
12,
340,
376,
1478,
4839,
370,
295,
3966,
12,
2755,
10617,
199,
1589,
5226,
16356,
2120,
965,
2757,
1255,
2005,
521,
315,
314,
13541,
446,
1325,
199,
65,
2945,
16356,
2120,
5594,
1172,
29815,
314,
1478,
315,
314,
4615,
521,
14,
199,
199,
10924,
787,
282,
2877,
19485,
658,
26795,
14,
4128,
64,
2897,
1511,
26,
199,
199,
703,
1233,
13,
1457,
447,
20364,
339,
359,
25651,
61,
339,
3608,
13,
1080,
275,
1678,
63,
793,
272,
3608,
13,
1301,
13,
466,
275,
2397,
199,
199,
624,
199,
199,
3,
4287,
26,
3507,
29,
38,
28025,
12,
37,
24827,
12,
35,
28399,
199,
646,
13022,
199,
646,
2197,
199,
646,
8337,
199,
646,
2022,
199,
646,
2050,
199,
646,
7975,
199,
199,
646,
19485,
199,
199,
504,
19485,
492,
3816,
199,
199,
2921,
275,
2050,
14,
5572,
360,
26795,
13,
3266,
358,
199,
199,
893,
26,
272,
492,
24380,
1733,
272,
340,
24380,
1733,
855,
1023,
363,
665,
334,
17,
12,
378,
12,
378,
304,
267,
2512,
14,
3764,
480,
2765,
859,
5419,
543,
24380,
1733,
413,
14,
16,
14,
16,
298,
2432,
298,
269,
15666,
1454,
2685,
272,
687,
24380,
1733,
14,
7546,
492,
13137,
272,
687,
24380,
1733,
14,
2105,
492,
20503,
773,
19,
5779,
3225,
199,
199,
2590,
3545,
26,
272,
2512,
14,
3764,
480,
19236,
9455,
1080,
859,
1928,
24380,
1733,
4903,
14,
298,
673,
298,
20326,
12420,
737,
8836,
340,
9455,
1080,
9330,
365,
1202,
2685,
421,
199,
533,
19509,
1733,
4277,
8,
26795,
14,
4277,
304,
272,
408,
10256,
367,
282,
2073,
315,
19509,
1733,
1041,
339,
3608,
63,
1080,
275,
19485,
14,
4758,
14,
362,
63,
888,
1252,
362,
360,
25651,
297,
9144,
283,
4211,
13,
1080,
297,
283,
873,
63,
793,
358,
272,
3608,
63,
1301,
63,
466,
275,
19485,
14,
4758,
14,
362,
63,
888,
1252,
362,
360,
25651,
297,
15491,
283,
4211,
13,
1301,
13,
466,
297,
283,
2373,
358,
339,
347,
636,
826,
721,
277,
12,
1591,
12,
1844,
12,
1478,
12,
1382,
63,
466,
12,
1678,
63,
344,
12,
326,
3608,
63,
1080,
63,
11141,
63,
890,
29,
16,
12,
1455,
63,
1178,
29,
403,
12,
2653,
29,
709,
12,
326,
2402,
63,
25651,
63,
589,
16420,
267,
408,
267,
520,
635,
1591,
26,
19509,
1733,
1654,
1591,
267,
520,
466,
1591,
26,
620,
267,
520,
635,
1844,
26,
19509,
1733,
1654,
1844,
267,
520,
466,
1844,
26,
1109,
267,
520,
635,
1478,
26,
1478,
536,
267,
520,
466,
1478,
26,
620,
267,
520,
635,
1382,
63,
466,
26,
13265,
536,
267,
520,
466,
1382,
63,
466,
26,
620,
267,
520,
635,
1678,
63,
344,
26,
376,
5148,
367,
642,
666,
663,
267,
520,
466,
1678,
63,
344,
26,
620,
267,
520,
635,
3608,
63,
1080,
63,
11141,
63,
890,
26,
769,
402,
4493,
370,
314,
1478,
370,
21027,
267,
520,
466,
3608,
63,
1080,
63,
11141,
63,
890,
26,
1109,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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""
import codecs
from io import BytesIO
from MarkupPy import markup
class HTMLFormat:
BOOK_ENDINGS = 'h3'
title = 'html'
extensions = ('html', )
@classmethod
def export_set(cls, dataset):
"""HTML representation of a Dataset."""
stream = BytesIO()
page = markup.page()
page.table.open()
if dataset.headers is not None:
new_header = [item if item is not None else '' for item in dataset.headers]
page.thead.open()
headers = markup.oneliner.th(new_header)
page.tr(headers)
page.thead.close()
for row in dataset:
new_row = [item if item is not None else '' for item in row]
html_row = markup.oneliner.td(new_row)
page.tr(html_row)
page.table.close()
# Allow unicode characters in output
wrapper = codecs.getwriter("utf8")(stream)
wrapper.writelines(str(page))
return stream.getvalue().decode('utf-8')
@classmethod
def export_book(cls, databook):
"""HTML representation of a Databook."""
stream = BytesIO()
# Allow unicode characters in output
wrapper = codecs.getwriter("utf8")(stream)
for i, dset in enumerate(databook._datasets):
title = (dset.title if dset.title else 'Set %s' % (i))
wrapper.write('<{}>{}</{}>\n'.format(cls.BOOK_ENDINGS, title, cls.BOOK_ENDINGS))
wrapper.write(dset.html)
wrapper.write('\n')
return stream.getvalue().decode('utf-8')
|
mit
|
[
624,
23159,
773,
446,
4163,
4843,
2291,
14,
199,
624,
199,
199,
646,
6010,
199,
504,
5890,
492,
11808,
199,
199,
504,
17504,
2713,
492,
9189,
421,
199,
533,
4163,
3484,
26,
272,
4367,
3593,
63,
3902,
3881,
275,
283,
72,
19,
7,
339,
2538,
275,
283,
1360,
7,
272,
5478,
275,
661,
1360,
297,
776,
339,
768,
3744,
272,
347,
4843,
63,
409,
8,
1886,
12,
4789,
304,
267,
408,
4943,
6025,
402,
282,
20284,
1041,
398,
2547,
275,
11808,
342,
398,
2034,
275,
9189,
14,
1606,
342,
267,
2034,
14,
1224,
14,
1490,
342,
398,
340,
4789,
14,
2139,
365,
440,
488,
26,
288,
892,
63,
1291,
275,
359,
1053,
340,
1242,
365,
440,
488,
587,
2125,
367,
1242,
315,
4789,
14,
2139,
61,
953,
2034,
14,
21519,
14,
1490,
342,
288,
2323,
275,
9189,
14,
265,
352,
16187,
14,
273,
8,
1222,
63,
1291,
9,
288,
2034,
14,
454,
8,
2139,
9,
288,
2034,
14,
21519,
14,
1600,
342,
398,
367,
1962,
315,
4789,
26,
288,
892,
63,
1143,
275,
359,
1053,
340,
1242,
365,
440,
488,
587,
2125,
367,
1242,
315,
1962,
61,
953,
3517,
63,
1143,
275,
9189,
14,
265,
352,
16187,
14,
2076,
8,
1222,
63,
1143,
9,
288,
2034,
14,
454,
8,
1360,
63,
1143,
9,
398,
2034,
14,
1224,
14,
1600,
342,
398,
327,
9812,
2649,
4110,
315,
1072,
267,
4975,
275,
6010,
14,
362,
5491,
480,
1624,
24,
25232,
1745,
9,
267,
4975,
14,
23277,
8,
495,
8,
1606,
430,
398,
372,
2547,
14,
7150,
1252,
2708,
360,
1624,
13,
24,
358,
339,
768,
3744,
272,
347,
4843,
63,
2706,
8,
1886,
12,
366,
1936,
6992,
304,
267,
408,
4943,
6025,
402,
282,
577,
1936,
6992,
1041,
398,
2547,
275,
11808,
342,
398,
327,
9812,
2649,
4110,
315,
1072,
267,
4975,
275,
6010,
14,
362,
5491,
480,
1624,
24,
25232,
1745,
9,
398,
367,
284,
12,
366,
409,
315,
3874,
8,
68,
1936,
6992,
423,
12281,
304,
288,
2538,
275,
334,
68,
409,
14,
1213,
340,
366,
409,
14,
1213,
587,
283,
1084,
450,
83,
7,
450,
334,
73,
430,
288,
4975,
14,
952,
4827,
2440,
30,
2440,
1108,
2440,
3072,
78,
1370,
908,
8,
1886,
14,
21155,
63,
3902,
3881,
12,
2538,
12,
843,
14,
21155,
63,
3902,
3881,
430,
288,
4975,
14,
952,
8,
68,
409,
14,
1360,
9,
288,
4975,
14,
952,
2258,
78,
358,
398,
372,
2547,
14,
7150,
1252,
2708,
360,
1624,
13,
24,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
23159,
773,
446,
4163,
4843,
2291,
14,
199,
624,
199,
199,
646,
6010,
199,
504,
5890,
492,
11808,
199,
199,
504,
17504,
2713,
492,
9189,
421,
199,
533,
4163,
3484,
26,
272,
4367,
3593,
63,
3902,
3881,
275,
283,
72,
19,
7,
339,
2538,
275,
283,
1360,
7,
272,
5478,
275,
661,
1360,
297,
776,
339,
768,
3744,
272,
347,
4843,
63,
409,
8,
1886,
12,
4789,
304,
267,
408,
4943,
6025,
402,
282,
20284,
1041,
398,
2547,
275,
11808,
342,
398,
2034,
275,
9189,
14,
1606,
342,
267,
2034,
14,
1224,
14,
1490,
342,
398,
340,
4789,
14,
2139,
365,
440,
488,
26,
288,
892,
63,
1291,
275,
359,
1053,
340,
1242,
365,
440,
488,
587,
2125,
367,
1242,
315,
4789,
14,
2139,
61,
953,
2034,
14,
21519,
14,
1490,
342,
288,
2323,
275,
9189,
14,
265,
352,
16187,
14,
273,
8,
1222,
63,
1291,
9,
288,
2034,
14,
454,
8,
2139,
9,
288,
2034,
14,
21519,
14,
1600,
342,
398,
367,
1962,
315,
4789,
26,
288,
892,
63,
1143,
275,
359,
1053,
340,
1242,
365,
440,
488,
587,
2125,
367,
1242,
315,
1962,
61,
953,
3517,
63,
1143,
275,
9189,
14,
265,
352,
16187,
14,
2076,
8,
1222,
63,
1143,
9,
288,
2034,
14,
454,
8,
1360,
63,
1143,
9,
398,
2034,
14,
1224,
14,
1600,
342,
398,
327,
9812,
2649,
4110,
315,
1072,
267,
4975,
275,
6010,
14,
362,
5491,
480,
1624,
24,
25232,
1745,
9,
267,
4975,
14,
23277,
8,
495,
8,
1606,
430,
398,
372,
2547,
14,
7150,
1252,
2708,
360,
1624,
13,
24,
358,
339,
768,
3744,
272,
347,
4843,
63,
2706,
8,
1886,
12,
366,
1936,
6992,
304,
267,
408,
4943,
6025,
402,
282,
577,
1936,
6992,
1041,
398,
2547,
275,
11808,
342,
398,
327,
9812,
2649,
4110,
315,
1072,
267,
4975,
275,
6010,
14,
362,
5491,
480,
1624,
24,
25232,
1745,
9,
398,
367,
284,
12,
366,
409,
315,
3874,
8,
68,
1936,
6992,
423,
12281,
304,
288,
2538,
275,
334,
68,
409,
14,
1213,
340,
366,
409,
14,
1213,
587,
283,
1084,
450,
83,
7,
450,
334,
73,
430,
288,
4975,
14,
952,
4827,
2440,
30,
2440,
1108,
2440,
3072,
78,
1370,
908,
8,
1886,
14,
21155,
63,
3902,
3881,
12,
2538,
12,
843,
14,
21155,
63,
3902,
3881,
430,
288,
4975,
14,
952,
8,
68,
409,
14,
1360,
9,
288,
4975,
14,
952,
2258,
78,
358,
398,
372,
2547,
14,
7150,
1252,
2708,
360,
1624,
13,
24,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
09zwcbupt/ryu
|
ryu/controller/mac_to_network.py
|
53
|
1960
|
# Copyright (C) 2011 Nippon Telegraph and Telephone Corporation.
# Copyright (C) 2011 Isaku Yamahata <yamahata at valinux co jp>
#
# 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 logging
from ryu.exception import MacAddressDuplicated
from ryu.lib.mac import haddr_to_str
LOG = logging.getLogger('ryu.controller.mac_to_network')
class MacToNetwork(object):
def __init__(self, nw):
super(MacToNetwork, self).__init__()
self.mac_to_net = {}
self.dpid = {}
self.nw = nw
def get_network(self, mac, default=None):
return self.mac_to_net.get(mac, default)
def add_mac(self, mac, nw_id, nw_id_external=None):
_nw_id = self.mac_to_net.get(mac)
if _nw_id == nw_id:
return
# allow changing from nw_id_external to known nw id
if _nw_id is None or _nw_id == nw_id_external:
self.mac_to_net[mac] = nw_id
LOG.debug('overwrite nw_id: mac %s nw old %s new %s',
haddr_to_str(mac), _nw_id, nw_id)
return
if nw_id == nw_id_external:
# this can happens when the packet traverses
# VM-> tap-> ovs-> ext-port-> wire-> ext-port-> ovs-> tap-> VM
return
LOG.warn('duplicated nw_id: mac %s nw old %s new %s',
haddr_to_str(mac), _nw_id, nw_id)
raise MacAddressDuplicated(mac=mac)
def del_mac(self, mac):
del self.mac_to_net[mac]
|
apache-2.0
|
[
3,
1898,
334,
35,
9,
7760,
653,
711,
678,
23884,
2180,
436,
23884,
9339,
11098,
14,
199,
3,
1898,
334,
35,
9,
7760,
6596,
1151,
85,
1488,
14541,
72,
419,
665,
11552,
391,
72,
419,
737,
1139,
7226,
512,
28921,
30,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
2050,
199,
199,
504,
25494,
14,
1971,
492,
10444,
1476,
36,
16724,
199,
504,
25494,
14,
773,
14,
3088,
492,
394,
2697,
63,
475,
63,
495,
199,
199,
4947,
275,
2050,
14,
5572,
360,
651,
85,
14,
5538,
14,
3088,
63,
475,
63,
1200,
358,
421,
199,
533,
10444,
1378,
4491,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
22823,
304,
267,
1613,
8,
3399,
1378,
4491,
12,
291,
2843,
826,
4533,
267,
291,
14,
3088,
63,
475,
63,
846,
275,
1052,
267,
291,
14,
26050,
275,
1052,
267,
291,
14,
13100,
275,
22823,
339,
347,
664,
63,
1200,
8,
277,
12,
4497,
12,
849,
29,
403,
304,
267,
372,
291,
14,
3088,
63,
475,
63,
846,
14,
362,
8,
3088,
12,
849,
9,
339,
347,
1050,
63,
3088,
8,
277,
12,
4497,
12,
22823,
63,
344,
12,
22823,
63,
344,
63,
5159,
29,
403,
304,
267,
485,
13100,
63,
344,
275,
291,
14,
3088,
63,
475,
63,
846,
14,
362,
8,
3088,
9,
267,
340,
485,
13100,
63,
344,
508,
22823,
63,
344,
26,
288,
372,
398,
327,
2040,
13729,
687,
22823,
63,
344,
63,
5159,
370,
6040,
22823,
1305,
267,
340,
485,
13100,
63,
344,
365,
488,
503,
485,
13100,
63,
344,
508,
22823,
63,
344,
63,
5159,
26,
288,
291,
14,
3088,
63,
475,
63,
846,
59,
3088,
61,
275,
22823,
63,
344,
288,
5051,
14,
1757,
360,
14658,
22823,
63,
344,
26,
4497,
450,
83,
22823,
2269,
450,
83,
892,
450,
83,
297,
1993,
394,
2697,
63,
475,
63,
495,
8,
3088,
395,
485,
13100,
63,
344,
12,
22823,
63,
344,
9,
288,
372,
398,
340,
22823,
63,
344,
508,
22823,
63,
344,
63,
5159,
26,
288,
327,
642,
883,
10986,
1380,
314,
3644,
1468,
422,
874,
288,
327,
7525,
5118,
24410,
5118,
23671,
5118,
1599,
13,
719,
5118,
11799,
5118,
1599,
13,
719,
5118,
23671,
5118,
24410,
5118,
7525,
288,
372,
398,
5051,
14,
4050,
360,
68,
16724,
22823,
63,
344,
26,
4497,
450,
83,
22823,
2269,
450,
83,
892,
450,
83,
297,
326,
394,
2697,
63,
475,
63,
495,
8,
3088,
395,
485,
13100,
63,
344,
12,
22823,
63,
344,
9,
398,
746,
10444,
1476,
36,
16724,
8,
3088,
29,
3088,
9,
339,
347,
2150,
63,
3088,
8,
277,
12,
4497,
304,
267,
2150,
291,
14,
3088,
63,
475,
63,
846,
59,
3088,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
7760,
653,
711,
678,
23884,
2180,
436,
23884,
9339,
11098,
14,
199,
3,
1898,
334,
35,
9,
7760,
6596,
1151,
85,
1488,
14541,
72,
419,
665,
11552,
391,
72,
419,
737,
1139,
7226,
512,
28921,
30,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
2050,
199,
199,
504,
25494,
14,
1971,
492,
10444,
1476,
36,
16724,
199,
504,
25494,
14,
773,
14,
3088,
492,
394,
2697,
63,
475,
63,
495,
199,
199,
4947,
275,
2050,
14,
5572,
360,
651,
85,
14,
5538,
14,
3088,
63,
475,
63,
1200,
358,
421,
199,
533,
10444,
1378,
4491,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
22823,
304,
267,
1613,
8,
3399,
1378,
4491,
12,
291,
2843,
826,
4533,
267,
291,
14,
3088,
63,
475,
63,
846,
275,
1052,
267,
291,
14,
26050,
275,
1052,
267,
291,
14,
13100,
275,
22823,
339,
347,
664,
63,
1200,
8,
277,
12,
4497,
12,
849,
29,
403,
304,
267,
372,
291,
14,
3088,
63,
475,
63,
846,
14,
362,
8,
3088,
12,
849,
9,
339,
347,
1050,
63,
3088,
8,
277,
12,
4497,
12,
22823,
63,
344,
12,
22823,
63,
344,
63,
5159,
29,
403,
304,
267,
485,
13100,
63,
344,
275,
291,
14,
3088,
63,
475,
63,
846,
14,
362,
8,
3088,
9,
267,
340,
485,
13100,
63,
344,
508,
22823,
63,
344,
26,
288,
372,
398,
327,
2040,
13729,
687,
22823,
63,
344,
63,
5159,
370,
6040,
22823,
1305,
267,
340,
485,
13100,
63,
344,
365,
488,
503,
485,
13100,
63,
344,
508,
22823,
63,
344,
63,
5159,
26,
288,
291,
14,
3088,
63,
475,
63,
846,
59,
3088,
61,
275,
22823,
63,
344,
288,
5051,
14,
1757,
360,
14658,
22823,
63,
344,
26,
4497,
450,
83,
22823,
2269,
450,
83,
892,
450,
83,
297,
1993,
394,
2697,
63,
475,
63,
495,
8,
3088,
395,
485,
13100,
63,
344,
12,
22823,
63,
344,
9,
288,
372,
398,
340,
22823,
63,
344,
508,
22823,
63,
344,
63,
5159,
26,
288,
327,
642,
883,
10986,
1380,
314,
3644,
1468,
422,
874,
288,
327,
7525,
5118,
24410,
5118,
23671,
5118,
1599,
13,
719,
5118,
11799,
5118,
1599,
13,
719,
5118,
23671,
5118,
24410,
5118,
7525,
288,
372,
398,
5051,
14,
4050,
360,
68,
16724,
22823,
63,
344,
26,
4497,
450,
83,
22823,
2269,
450,
83,
892,
450,
83,
297,
326,
394,
2697,
63,
475,
63,
495,
8,
3088,
395,
485,
13100,
63,
344,
12,
22823,
63,
344,
9,
398,
746,
10444,
1476,
36,
16724,
8,
3088,
29,
3088,
9,
339,
347,
2150,
63,
3088,
8,
277,
12,
4497,
304,
267,
2150,
291,
14,
3088,
63,
475,
63,
846,
59,
3088,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
xiaowing/pgmail_crawler
|
PgmailCrawler.py
|
1
|
16174
|
'''
@author: xiaowing
@license: MIT License
'''
import io, sys, shutil, getopt, time, random, queue, urllib.parse, pdb, threading
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') # Change the default encode of stdout.
import requests
import psycopg2
from datetime import date, datetime
from dateutil.relativedelta import relativedelta
from threading import Thread
from bs4 import BeautifulSoup
import ProxyipGetter
class PgmailCrawler:
__base_url = 'http://www.postgresql.org/'
__base_maillist_url = 'http://www.postgresql.org/list/'
RETRY_TIMES = 3
#dest_list = ['pgsql-patches/', 'pgsql-hackers/', 'pgsql-cluster-hackers/']
dest_list = ['pgsql-patches/', 'pgsql-hackers/']
def __init__(self, start_year, start_month, dest_no=0, host="localhost", port=5432, database="postgres", pguser="postgres", userpwd=""):
# pretend as a request from browser
self.headers = [
{'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:34.0) Gecko/20100101 Firefox/34.0'},
{'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'},
{'User-Agent': 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.12 Safari/535.11'},
{'User-Agent': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)'},
{'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0'},
{'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/44.0.2403.89 Chrome/44.0.2403.89 Safari/537.36'}
]
self.proxies_dict = PgmailCrawler.generateProxies()
self.link_list = queue.Queue()
self.info_list = []
self.pghost = host
self.pgport = port
self.database = database
self.pguser = pguser
self.password = userpwd
self.start_time = date(start_year, start_month, 1)
self.dest_no = dest_no
self._value_lock = threading.Lock()
def randHeader(self):
return self.headers[random.randint(0, len(self.headers)-1)]
def doCrawling(self):
begin_date = self.start_time
while True:
crawling_link = PgmailCrawler.parsingDateToIndexUrl(begin_date, self.dest_no)
next_link = self.__initLinksInternal(crawling_link, by_next = False)
self.getMailInfos()
self.saveMailInfosIntoDB()
while next_link:
crawling_link = next_link
next_link = self.__initLinksInternal(next_link, by_next=True)
self.getMailInfos()
self.saveMailInfosIntoDB()
begin_date = PgmailCrawler.parsingDateFromUrl(crawling_link)
# Ignore the rest pages of current crawling year-month
# skip to the next month
begin_date = begin_date + relativedelta(months=+1)
# The only exit of this infinite loop is the begin_date greater than today.
if begin_date > date.today():
#pdb.set_trace()
return
def __initLinksInternal(self, index_page_url, by_next = False):
print(("Crawler %d Retriving mail links from %s..." %(self.dest_no, index_page_url)), flush=True)
toget_flg = True
while toget_flg:
try:
source_code = requests.Session().get(index_page_url, headers = self.randHeader(), proxies=self.proxies_dict)
toget_flg = False
plain_text = source_code.text
soup = BeautifulSoup(plain_text, "html.parser")
for ul in soup.find_all('ul', id=False):
if ul.parent.name == 'li':
continue
if ul.parent.name == 'div' and ul.parent.attrs['id'] == 'pgSideNav':
continue
first_link = True
for li in ul.find_all('li'):
if by_next and first_link:
first_link = False
else:
self.link_list.put(li.a['href'])
else:
first_link = True
# Retrieve the "href" attribute of <a href="xxxxx">Next</a>
next_link_tag = soup.find(PgmailCrawler.a_with_text_next)
if next_link_tag != None:
next_link = next_link_tag['href']
next_link = urllib.parse.urljoin(PgmailCrawler.__base_url, next_link)
# Retrieve a new proxy for the crawler every time after a page scaned.
with self._value_lock:
self.proxies_dict = PgmailCrawler.generateProxies()
if next_link != index_page_url:
return next_link
return None
except requests.exceptions.ConnectionError:
time.sleep(30)
except Exception as e:
print("Crawler %d encountered an error while crawling %s. Error type: %s, Message: %s" %(self.dest_no, index_page_url, type(e),e))
time.sleep(1)
def getMailInfos(self):
cnt = 0
while not self.link_list.empty():
link = self.link_list.get()
mail_link = urllib.parse.urljoin(PgmailCrawler.__base_url, link)
self.__getMailInfoFromLink(mail_link)
def saveMailInfosIntoDB(self):
if len(self.info_list) > 0:
print("Crawler %d saving data to DB." %self.dest_no)
self.__insertMailInfoFromList()
self.info_list = []
def __getMailInfoFromLink(self, link):
try:
page_source = requests.Session().get(link, headers = self.randHeader(), proxies=self.proxies_dict)
#page_source = requests.Session().get(link, headers = self.randHeader())
if not page_source.status_code == requests.codes["ok"]:
return
plain_text = page_source.text
soup = BeautifulSoup(plain_text, "html.parser")
msgtb = soup.find('table', class_='message')
infodict = { 'sender': "", 'title': "", 'datetime': ""}
for th in msgtb.find_all('th'):
if th.string == 'From:':
td = th.find_next_sibling('td')
infodict['sender'] = td.get_text()
if th.string == 'Subject:':
td = th.find_next_sibling('td')
infodict['title'] = td.get_text()
if th.string == 'Date:':
td = th.find_next_sibling('td')
infodict['datetime'] = td.get_text()
else:
info = MailInfo(url=link, title_text=infodict['title'], date_text=infodict['datetime'], from_text=infodict['sender'])
self.info_list.append(info)
except requests.exceptions.ConnectionError:
time.sleep(30)
except Exception as e:
print("Crawler %d encountered an error while crawling %s. Error type: %s, Message: %s" %(self.dest_no, link, type(e),e))
time.sleep(1)
def __insertMailInfoFromList(self):
if self.password == "":
conn = psycopg2.connect(host = self.pghost, port = self.pgport, database = self.database, user = self.pguser)
else:
conn = psycopg2.connect(host = self.pghost, port = self.pgport, database = self.database, user = self.pguser, password = self.password)
conn.autocommit = True
try:
cur = conn.cursor()
for mi in self.info_list:
try:
cur.execute("INSERT INTO sch_crawler.mail_info VALUES (%(sender)s, %(title)s, %(time)s, %(url)s);",
{'sender': mi.sender, 'title': mi.title,
'time': mi.date, 'url': mi.url})
except psycopg2.DatabaseError as ex:
print("Crawler %d encountered an Database error. SQLSTATE: %s, MESSAGE: %s." %(self.dest_no, ex.pgcode, ex))
cur.close()
except psycopg2.Error as e:
print("Crawler %d encountered an %s error. SQLSTATE: %s, MESSAGE: %s." %(self.dest_no, type(e), e.pgcode, e))
finally:
conn.close()
@classmethod
def a_with_text_next(cls, tag):
return tag.name == 'a' and tag.get_text() == 'Next'
@classmethod
def generateProxies(cls):
i = PgmailCrawler.RETRY_TIMES
while i > 0:
proxies = ProxyipGetter.getLatestProxys()
if ProxyipGetter.testUsability(proxies) != requests.codes['ok']:
time.sleep(5)
i = i - 1
else:
return proxies
else:
raise ConnectionError('Cannot retrieve a proper proxy.')
@classmethod
def parsingDateFromUrl(cls, url):
if not isinstance(url, str):
raise TypeError()
url = url.rstrip('/')
slash_index = url.rfind('/')
if slash_index == -1:
raise ValueError()
timestamp_string = url[(slash_index+1):]
format_string = ["%Y%m%d%H%M", "%Y-%m"]
try:
t = time.strptime(timestamp_string, format_string[0])
dt = date(*t[:3])
except ValueError:
t = time.strptime(timestamp_string, format_string[1])
dt = date(*t[:3])
return dt
@classmethod
def parsingDateToIndexUrl(cls, dt, destidx=0):
if not isinstance(dt, date):
raise TypeError()
ym = dt.strftime('%Y-%m')
url = urllib.parse.urljoin(PgmailCrawler.__base_maillist_url, PgmailCrawler.dest_list[destidx])
url = urllib.parse.urljoin(url, ym)
return url
class MailInfo:
def __init__(self, url, title_text, date_text, from_text):
self.url = url
self.title = title_text
# convert the text format of date into datetime
try:
tm = time.strptime(date_text, "%Y-%m-%d %H:%M:%S")
self.date = datetime(*tm[:6])
except ValueError as e:
# since the date_text is incorrect, set the datetime as now
self.date = datetime.now()
# the from_text is similar to "Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>"
lgt_index = from_text.find('<')
rgt_index = from_text.rfind('>')
if lgt_index >= 0:
if rgt_index >= 0:
new_from_text = from_text[(lgt_index+1):rgt_index]
else:
new_from_text = from_text[(lgt_index+1):]
else:
if rgt_index >= 0:
new_from_text = from_text[:rgt_index]
else:
new_from_text = from_text
self.sender = new_from_text.replace('(at)', '@').replace('(dot)', '.')
def __str__(self):
return str("%s, %s, %s" %(self.sender, self.title, self.date))
def main(argv):
# handler the input arguments
if len(argv) < 2 or len(argv) > 16:
print("Invalid arguments.")
sys.exit(1)
format_string = "y:m:h:p:d:u:w:v"
try:
opts, args = getopt.getopt(sys.argv[1:], format_string, ["version"])
except getopt.GetoptError as err:
print(str(err))
sys.exit(2)
start_year = 0
start_month = 0
host = "localhost"
port = 5432
database = "postgres"
username = "postgres"
password = ""
for op, value in opts:
if op == "-y":
try:
start_year = int(value)
if start_year < 1997 or start_year > date.today().year:
raise ValueError
except ValueError:
print("Invalid year number: %s" %value)
sys.exit(3)
elif op == "-m":
try:
start_month = int(value)
if start_month < 1 or start_month > 12:
raise ValueError
except ValueError:
print("Invalid month number: %s" %value)
sys.exit(3)
elif op == "-h":
host = value
elif op == "-p":
try:
port = int(value)
if port < 0 or port > 65535:
raise ValueError
except ValueError:
print("Invalid port number: %s" %value)
sys.exit(3)
elif op == "-d":
database = value
elif op == "-u":
username = value
elif op == "-w":
password = value
elif op in ("-v", "--version"):
version()
sys.exit(0)
else:
print("Unhanded option.")
sys.exit(3)
if start_year == 0 or start_month == 0:
print("It's necessary to input start year and start month")
sys.exit(3)
if(len(args) > 0):
print("Unrecognised arguments.")
sys.exit(3)
# ping the PostgreSQL server to make sure the data can be inserted into database
if not ping_pg_server(host=host, port=port, database=database, user=username, pwd=password):
print("Connection to PostgreSQL instance(%s:%d %s) failed." %(host, port, database))
sys.exit(3)
# create crawlers and start retrieving data, Thread : Crawler = 1:1
start_time = datetime.now()
thread_list = []
for x in range(0, len(PgmailCrawler.dest_list)):
crawler = PgmailCrawler(start_year=start_year, start_month=start_month, dest_no=x, host=host, port=port, database=database, pguser=username, userpwd=password)
t = Thread(target=sub_crawling_job, args=(crawler,))
t.start()
thread_list.append(t)
for element in thread_list:
if element.is_alive():
element.join()
else:
end_time = datetime.now()
print("The whole duration is %s" %(end_time - start_time))
time.sleep(3)
sys.exit(0)
def ping_pg_server(host, port, database, user, pwd):
conn = None
result = True
try:
if pwd == "":
conn = psycopg2.connect(host = host, port = port, database = database, user = user)
else:
conn = psycopg2.connect(host = host, port = port, database = database, user = user, password = pwd)
conn.autocommit = True
try:
cur = conn.cursor()
cur.execute("SELECT 1;")
cur.fetchone()
cur.close()
except psycopg2.Error as e:
raise e
finally:
conn.close()
except psycopg2.Error as ex:
print("SQLSTATE: %s, MESSAGE: %s." %(ex.pgcode, ex))
result = False
return result
def sub_crawling_job(crawler):
if not isinstance(crawler, PgmailCrawler):
print("Incorrect argument. PgmailCrawler expected.", flush=True)
return
start_time = datetime.now()
print(("Crawler %d Start crawling at %s" %(crawler.dest_no, start_time)), flush=True)
try:
crawler.doCrawling()
end_time = datetime.now()
print("Crawler %d's crawling ended at %s" %(crawler.dest_no, end_time))
except Exception as ex:
end_time = datetime.now()
print("Crawler %d's encountered an unexpected error and the job was interrupted at %s. Error: %s, Message: %s"
%(crawler.dest_no, end_time, type(ex), ex))
print(("The duration of Crawler %d's crawling is %s" %(crawler.dest_no, (end_time - start_time))), flush=True)
def version():
print ("PgmailCrawler v0.2.0")
if __name__ == '__main__':
main(sys.argv)
|
mit
|
[
172,
120,
124,
2344,
202,
199,
32,
2502,
26,
259,
671,
4674,
583,
316,
202,
199,
32,
1682,
26,
257,
10697,
844,
20712,
199,
2344,
2999,
199,
646,
5890,
12,
984,
12,
5145,
12,
12733,
12,
900,
12,
2196,
12,
4126,
12,
4011,
14,
1122,
12,
10543,
12,
5796,
202,
199,
1274,
14,
2703,
275,
5890,
14,
1872,
29365,
8,
1274,
14,
2703,
14,
2738,
12,
2991,
534,
1624,
24,
358,
221,
327,
7743,
314,
849,
3752,
402,
3839,
14,
2999,
199,
646,
4145,
202,
199,
646,
15492,
18,
2999,
199,
504,
2197,
492,
1434,
12,
2197,
202,
199,
504,
22208,
14,
32300,
492,
20599,
202,
199,
504,
5796,
492,
11086,
202,
199,
504,
9922,
20,
492,
17132,
2999,
199,
646,
12373,
711,
22038,
2999,
199,
533,
510,
6799,
35,
16057,
26,
1128,
636,
1095,
63,
633,
275,
283,
1014,
921,
1544,
14,
15437,
14,
1308,
4805,
1128,
636,
1095,
63,
1198,
513,
63,
633,
275,
283,
1014,
921,
1544,
14,
15437,
14,
1308,
15,
513,
4805,
1128,
17409,
5782,
63,
11342,
654,
275,
650,
1128,
327,
2614,
63,
513,
275,
788,
80,
458,
1710,
13,
11350,
3678,
283,
80,
458,
1710,
13,
20875,
1192,
3678,
283,
80,
458,
1710,
13,
4201,
13,
20875,
1192,
15,
418,
1128,
2053,
63,
513,
275,
788,
80,
458,
1710,
13,
11350,
3678,
283,
80,
458,
1710,
13,
20875,
1192,
15,
418,
2958,
347,
636,
826,
721,
277,
12,
1343,
63,
3403,
12,
1343,
63,
4482,
12,
2053,
63,
889,
29,
16,
12,
1591,
628,
5967,
401,
1844,
29,
1477,
708,
12,
3050,
628,
10675,
401,
10275,
751,
628,
10675,
401,
922,
14258,
17364,
1039,
327,
27830,
465,
282,
1056,
687,
7042,
1039,
291,
14,
2139,
275,
359,
1675,
791,
1899,
13,
7788,
356,
283,
22285,
15,
21,
14,
16,
334,
56,
845,
27,
31631,
27,
10130,
671,
1184,
63,
772,
27,
4336,
26,
1082,
14,
16,
9,
30506,
15,
1797,
4587,
614,
24584,
15,
1082,
14,
16,
2267,
1675,
791,
1899,
13,
7788,
356,
283,
22285,
15,
21,
14,
16,
334,
8647,
27,
738,
27,
5417,
23350,
1227,
14,
17,
27,
655,
13,
1668,
27,
4336,
26,
17,
14,
25,
14,
17,
14,
22,
9,
30506,
15,
8664,
713,
614,
24584,
15,
19,
14,
21,
14,
22,
2267,
1675,
791,
1899,
13,
7788,
356,
283,
22285,
15,
21,
14,
16,
334,
8647,
23350,
1227,
14,
18,
9,
21257,
21666,
15,
7920,
14,
845,
334,
43,
4943,
12,
2839,
30506,
9,
16776,
15,
1196,
14,
16,
14,
24548,
14,
713,
428,
2756,
759,
15,
7920,
14,
845,
2267,
1675,
791,
1899,
13,
7788,
356,
283,
22285,
15,
21,
14,
16,
334,
6490,
27,
603,
2684,
37,
1616,
14,
16,
27,
5417,
23350,
1227,
14,
18,
27,
12480,
1326,
15,
22,
14,
16,
9,
2267,
1675,
791,
1899,
13,
7788,
356,
283,
22285,
15,
21,
14,
16,
334,
56,
845,
27,
31631,
27,
10130,
671,
1184,
63,
772,
27,
4336,
26,
2167,
14,
16,
9,
30506,
15,
1797,
4587,
614,
24584,
15,
2167,
14,
16,
2267,
1675,
791,
1899,
13,
7788,
356,
283,
22285,
15,
21,
14,
16,
334,
56,
845,
27,
10130,
671,
1184,
63,
772,
9,
21257,
21666,
15,
24416,
14,
1344,
334,
43,
4943,
12,
2839,
30506,
9,
31631,
12051,
15,
1602,
14,
16,
14,
1194,
1644,
14,
1407,
16776,
15,
1602,
14,
16,
14,
1194,
1644,
14,
1407,
428,
2756,
759,
15,
24416,
14,
1344,
936,
1039,
1622,
13594,
291,
14,
17128,
63,
807,
275,
510,
6799,
35,
16057,
14,
4208,
26689,
1500,
342,
1039,
291,
14,
1073,
63,
513,
275,
4126,
14,
3737,
342,
1039,
291,
14,
815,
63,
513,
275,
942,
1039,
291,
14,
4198,
1102,
275,
1591,
1039,
291,
14,
4198,
719,
275,
1844,
1039,
291,
14,
4659,
275,
3050,
1039,
291,
14,
4198,
751,
275,
10275,
751,
1039,
291,
14,
2060,
275,
922,
14258,
1039,
291,
14,
928,
63,
521,
275,
1434,
8,
928,
63,
3403,
12,
1343,
63,
4482,
12,
413,
9,
1039,
291,
14,
2614,
63,
889,
275,
2053,
63,
889,
1039,
291,
423,
585,
63,
831,
275,
5796,
14,
6432,
342,
2958,
347,
10261,
2567,
8,
277,
304,
1039,
372,
291,
14,
2139,
59,
2355,
14,
8393,
8,
16,
12,
822,
8,
277,
14,
2139,
7216,
17,
1874,
2958,
347,
886,
35,
1773,
2983,
8,
277,
304,
1039,
5386,
63,
602,
275,
291,
14,
928,
63,
521,
1039,
1830,
715,
26,
1675,
286,
1773,
2983,
63,
1073,
275,
510,
6799,
35,
16057,
14,
11059,
2506,
1378,
2681,
6417,
8,
5037,
63,
602,
12,
291,
14,
2614,
63,
889,
9,
1675,
2163,
63,
1073,
275,
291,
855,
826,
16974,
8405,
8,
67,
1773,
2983,
63,
1073,
12,
701,
63,
2184,
275,
756,
9,
1675,
291,
14,
362,
13681,
32083,
342,
1675,
291,
14,
2117,
13681,
32083,
19448,
2846,
342,
1675,
1830,
2163,
63,
1073,
26,
2628,
286,
1773,
2983,
63,
1073,
275,
2163,
63,
1073,
2628,
2163,
63,
1073,
275,
291,
855,
826,
16974,
8405,
8,
2184,
63,
1073,
12,
701,
63,
2184,
29,
549,
9,
2628,
291,
14,
362,
13681,
32083,
342,
2628,
291,
14,
2117,
13681,
32083,
19448,
2846,
342,
1675,
5386,
63,
602,
275,
510,
6799,
35,
16057,
14,
11059,
2506,
2532,
6417,
8,
67,
1773,
2983,
63,
1073,
9,
11556,
327,
14092,
314,
4618,
6497,
402,
1453,
286,
1773,
2983,
5361,
13,
4482,
1675,
327,
3372,
370,
314,
2163,
5794,
1675,
5386,
63,
602,
275,
5386,
63,
602,
435,
20599,
8,
16745,
29744,
17,
9,
17554,
1675,
327,
710,
1454,
4458,
402,
642,
15258,
4438,
365,
314,
5386,
63,
602,
8932,
2419,
11168,
14,
1675,
340,
5386,
63,
602,
690,
1434,
14,
8136,
837,
2628,
327,
10511,
14,
409,
63,
3446,
342,
2628,
372,
2958,
347,
636,
826,
16974,
8405,
8,
277,
12,
1478,
63,
1606,
63,
633,
12,
701,
63,
2184,
275,
756,
304,
1039,
870,
9313,
35,
16057,
450,
68,
8747,
322,
4007,
6016,
6220,
687,
450,
83,
11500,
2818,
277,
14,
2614,
63,
889,
12,
1478,
63,
1606,
63,
633,
1826,
8976,
29,
549,
9,
1039,
370,
362,
63,
2327,
71,
275,
715,
1039,
1830,
221,
370,
362,
63,
2327,
71,
26,
1675,
862,
26,
2628,
1350,
63,
600,
275,
4145,
14
] |
[
120,
124,
2344,
202,
199,
32,
2502,
26,
259,
671,
4674,
583,
316,
202,
199,
32,
1682,
26,
257,
10697,
844,
20712,
199,
2344,
2999,
199,
646,
5890,
12,
984,
12,
5145,
12,
12733,
12,
900,
12,
2196,
12,
4126,
12,
4011,
14,
1122,
12,
10543,
12,
5796,
202,
199,
1274,
14,
2703,
275,
5890,
14,
1872,
29365,
8,
1274,
14,
2703,
14,
2738,
12,
2991,
534,
1624,
24,
358,
221,
327,
7743,
314,
849,
3752,
402,
3839,
14,
2999,
199,
646,
4145,
202,
199,
646,
15492,
18,
2999,
199,
504,
2197,
492,
1434,
12,
2197,
202,
199,
504,
22208,
14,
32300,
492,
20599,
202,
199,
504,
5796,
492,
11086,
202,
199,
504,
9922,
20,
492,
17132,
2999,
199,
646,
12373,
711,
22038,
2999,
199,
533,
510,
6799,
35,
16057,
26,
1128,
636,
1095,
63,
633,
275,
283,
1014,
921,
1544,
14,
15437,
14,
1308,
4805,
1128,
636,
1095,
63,
1198,
513,
63,
633,
275,
283,
1014,
921,
1544,
14,
15437,
14,
1308,
15,
513,
4805,
1128,
17409,
5782,
63,
11342,
654,
275,
650,
1128,
327,
2614,
63,
513,
275,
788,
80,
458,
1710,
13,
11350,
3678,
283,
80,
458,
1710,
13,
20875,
1192,
3678,
283,
80,
458,
1710,
13,
4201,
13,
20875,
1192,
15,
418,
1128,
2053,
63,
513,
275,
788,
80,
458,
1710,
13,
11350,
3678,
283,
80,
458,
1710,
13,
20875,
1192,
15,
418,
2958,
347,
636,
826,
721,
277,
12,
1343,
63,
3403,
12,
1343,
63,
4482,
12,
2053,
63,
889,
29,
16,
12,
1591,
628,
5967,
401,
1844,
29,
1477,
708,
12,
3050,
628,
10675,
401,
10275,
751,
628,
10675,
401,
922,
14258,
17364,
1039,
327,
27830,
465,
282,
1056,
687,
7042,
1039,
291,
14,
2139,
275,
359,
1675,
791,
1899,
13,
7788,
356,
283,
22285,
15,
21,
14,
16,
334,
56,
845,
27,
31631,
27,
10130,
671,
1184,
63,
772,
27,
4336,
26,
1082,
14,
16,
9,
30506,
15,
1797,
4587,
614,
24584,
15,
1082,
14,
16,
2267,
1675,
791,
1899,
13,
7788,
356,
283,
22285,
15,
21,
14,
16,
334,
8647,
27,
738,
27,
5417,
23350,
1227,
14,
17,
27,
655,
13,
1668,
27,
4336,
26,
17,
14,
25,
14,
17,
14,
22,
9,
30506,
15,
8664,
713,
614,
24584,
15,
19,
14,
21,
14,
22,
2267,
1675,
791,
1899,
13,
7788,
356,
283,
22285,
15,
21,
14,
16,
334,
8647,
23350,
1227,
14,
18,
9,
21257,
21666,
15,
7920,
14,
845,
334,
43,
4943,
12,
2839,
30506,
9,
16776,
15,
1196,
14,
16,
14,
24548,
14,
713,
428,
2756,
759,
15,
7920,
14,
845,
2267,
1675,
791,
1899,
13,
7788,
356,
283,
22285,
15,
21,
14,
16,
334,
6490,
27,
603,
2684,
37,
1616,
14,
16,
27,
5417,
23350,
1227,
14,
18,
27,
12480,
1326,
15,
22,
14,
16,
9,
2267,
1675,
791,
1899,
13,
7788,
356,
283,
22285,
15,
21,
14,
16,
334,
56,
845,
27,
31631,
27,
10130,
671,
1184,
63,
772,
27,
4336,
26,
2167,
14,
16,
9,
30506,
15,
1797,
4587,
614,
24584,
15,
2167,
14,
16,
2267,
1675,
791,
1899,
13,
7788,
356,
283,
22285,
15,
21,
14,
16,
334,
56,
845,
27,
10130,
671,
1184,
63,
772,
9,
21257,
21666,
15,
24416,
14,
1344,
334,
43,
4943,
12,
2839,
30506,
9,
31631,
12051,
15,
1602,
14,
16,
14,
1194,
1644,
14,
1407,
16776,
15,
1602,
14,
16,
14,
1194,
1644,
14,
1407,
428,
2756,
759,
15,
24416,
14,
1344,
936,
1039,
1622,
13594,
291,
14,
17128,
63,
807,
275,
510,
6799,
35,
16057,
14,
4208,
26689,
1500,
342,
1039,
291,
14,
1073,
63,
513,
275,
4126,
14,
3737,
342,
1039,
291,
14,
815,
63,
513,
275,
942,
1039,
291,
14,
4198,
1102,
275,
1591,
1039,
291,
14,
4198,
719,
275,
1844,
1039,
291,
14,
4659,
275,
3050,
1039,
291,
14,
4198,
751,
275,
10275,
751,
1039,
291,
14,
2060,
275,
922,
14258,
1039,
291,
14,
928,
63,
521,
275,
1434,
8,
928,
63,
3403,
12,
1343,
63,
4482,
12,
413,
9,
1039,
291,
14,
2614,
63,
889,
275,
2053,
63,
889,
1039,
291,
423,
585,
63,
831,
275,
5796,
14,
6432,
342,
2958,
347,
10261,
2567,
8,
277,
304,
1039,
372,
291,
14,
2139,
59,
2355,
14,
8393,
8,
16,
12,
822,
8,
277,
14,
2139,
7216,
17,
1874,
2958,
347,
886,
35,
1773,
2983,
8,
277,
304,
1039,
5386,
63,
602,
275,
291,
14,
928,
63,
521,
1039,
1830,
715,
26,
1675,
286,
1773,
2983,
63,
1073,
275,
510,
6799,
35,
16057,
14,
11059,
2506,
1378,
2681,
6417,
8,
5037,
63,
602,
12,
291,
14,
2614,
63,
889,
9,
1675,
2163,
63,
1073,
275,
291,
855,
826,
16974,
8405,
8,
67,
1773,
2983,
63,
1073,
12,
701,
63,
2184,
275,
756,
9,
1675,
291,
14,
362,
13681,
32083,
342,
1675,
291,
14,
2117,
13681,
32083,
19448,
2846,
342,
1675,
1830,
2163,
63,
1073,
26,
2628,
286,
1773,
2983,
63,
1073,
275,
2163,
63,
1073,
2628,
2163,
63,
1073,
275,
291,
855,
826,
16974,
8405,
8,
2184,
63,
1073,
12,
701,
63,
2184,
29,
549,
9,
2628,
291,
14,
362,
13681,
32083,
342,
2628,
291,
14,
2117,
13681,
32083,
19448,
2846,
342,
1675,
5386,
63,
602,
275,
510,
6799,
35,
16057,
14,
11059,
2506,
2532,
6417,
8,
67,
1773,
2983,
63,
1073,
9,
11556,
327,
14092,
314,
4618,
6497,
402,
1453,
286,
1773,
2983,
5361,
13,
4482,
1675,
327,
3372,
370,
314,
2163,
5794,
1675,
5386,
63,
602,
275,
5386,
63,
602,
435,
20599,
8,
16745,
29744,
17,
9,
17554,
1675,
327,
710,
1454,
4458,
402,
642,
15258,
4438,
365,
314,
5386,
63,
602,
8932,
2419,
11168,
14,
1675,
340,
5386,
63,
602,
690,
1434,
14,
8136,
837,
2628,
327,
10511,
14,
409,
63,
3446,
342,
2628,
372,
2958,
347,
636,
826,
16974,
8405,
8,
277,
12,
1478,
63,
1606,
63,
633,
12,
701,
63,
2184,
275,
756,
304,
1039,
870,
9313,
35,
16057,
450,
68,
8747,
322,
4007,
6016,
6220,
687,
450,
83,
11500,
2818,
277,
14,
2614,
63,
889,
12,
1478,
63,
1606,
63,
633,
1826,
8976,
29,
549,
9,
1039,
370,
362,
63,
2327,
71,
275,
715,
1039,
1830,
221,
370,
362,
63,
2327,
71,
26,
1675,
862,
26,
2628,
1350,
63,
600,
275,
4145,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
strk/mapnik
|
scons/scons-local-2.2.0/SCons/Tool/rpcgen.py
|
14
|
2918
|
"""SCons.Tool.rpcgen
Tool-specific initialization for RPCGEN tools.
Three normally shouldn't be any need to import this module directly.
It will usually be imported through the generic SCons.Tool.Tool()
selection method.
"""
#
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
__revision__ = "src/engine/SCons/Tool/rpcgen.py issue-2856:2676:d23b7a2f45e8 2012/08/05 15:38:28 garyo"
from SCons.Builder import Builder
import SCons.Util
cmd = "cd ${SOURCE.dir} && $RPCGEN -%s $RPCGENFLAGS %s -o ${TARGET.abspath} ${SOURCE.file}"
rpcgen_client = cmd % ('l', '$RPCGENCLIENTFLAGS')
rpcgen_header = cmd % ('h', '$RPCGENHEADERFLAGS')
rpcgen_service = cmd % ('m', '$RPCGENSERVICEFLAGS')
rpcgen_xdr = cmd % ('c', '$RPCGENXDRFLAGS')
def generate(env):
"Add RPCGEN Builders and construction variables for an Environment."
client = Builder(action=rpcgen_client, suffix='_clnt.c', src_suffix='.x')
header = Builder(action=rpcgen_header, suffix='.h', src_suffix='.x')
service = Builder(action=rpcgen_service, suffix='_svc.c', src_suffix='.x')
xdr = Builder(action=rpcgen_xdr, suffix='_xdr.c', src_suffix='.x')
env.Append(BUILDERS={'RPCGenClient' : client,
'RPCGenHeader' : header,
'RPCGenService' : service,
'RPCGenXDR' : xdr})
env['RPCGEN'] = 'rpcgen'
env['RPCGENFLAGS'] = SCons.Util.CLVar('')
env['RPCGENCLIENTFLAGS'] = SCons.Util.CLVar('')
env['RPCGENHEADERFLAGS'] = SCons.Util.CLVar('')
env['RPCGENSERVICEFLAGS'] = SCons.Util.CLVar('')
env['RPCGENXDRFLAGS'] = SCons.Util.CLVar('')
def exists(env):
return env.Detect('rpcgen')
# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
|
lgpl-2.1
|
[
624,
18521,
14,
5157,
14,
4354,
2268,
199,
199,
5157,
13,
6100,
11097,
367,
820,
48,
4064,
742,
7249,
14,
199,
199,
21485,
12252,
9296,
1133,
506,
1263,
1929,
370,
492,
642,
859,
5370,
14,
199,
7940,
911,
9987,
506,
8439,
4012,
314,
7809,
8218,
14,
5157,
14,
5157,
342,
199,
5592,
1083,
14,
199,
624,
199,
199,
3,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
12,
6029,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
5157,
15,
4354,
2268,
14,
647,
4976,
13,
1651,
1367,
26,
1479,
2114,
26,
68,
1789,
66,
23,
65,
18,
70,
2322,
69,
24,
6029,
15,
2036,
15,
1717,
4114,
26,
1703,
26,
1651,
486,
695,
79,
2,
199,
199,
504,
8218,
14,
6437,
492,
19286,
199,
646,
8218,
14,
9562,
199,
199,
1760,
275,
298,
2866,
10839,
10187,
14,
694,
93,
10883,
2672,
18612,
4064,
742,
446,
5,
83,
2672,
18612,
4064,
742,
4831,
450,
83,
446,
79,
10839,
9268,
14,
4832,
93,
10839,
10187,
14,
493,
7063,
199,
199,
4354,
2268,
63,
1258,
257,
275,
2088,
450,
661,
76,
297,
4505,
18612,
4064,
742,
9901,
4831,
358,
199,
4354,
2268,
63,
1291,
257,
275,
2088,
450,
661,
72,
297,
4505,
18612,
4064,
742,
7311,
4831,
358,
199,
4354,
2268,
63,
1364,
221,
275,
2088,
450,
661,
77,
297,
4505,
18612,
4064,
742,
10486,
4831,
358,
199,
4354,
2268,
63,
2207,
82,
420,
275,
2088,
450,
661,
67,
297,
4505,
18612,
4064,
742,
56,
4564,
4831,
358,
199,
199,
318,
3550,
8,
1813,
304,
272,
298,
1123,
820,
48,
4064,
742,
19286,
83,
436,
14538,
2860,
367,
376,
9711,
2122,
2286,
1890,
221,
275,
19286,
8,
1287,
29,
4354,
2268,
63,
1258,
12,
221,
4739,
17574,
429,
343,
14,
67,
297,
2928,
63,
4511,
15637,
88,
358,
272,
1406,
221,
275,
19286,
8,
1287,
29,
4354,
2268,
63,
1291,
12,
221,
4739,
15637,
72,
297,
420,
2928,
63,
4511,
15637,
88,
358,
272,
2435,
275,
19286,
8,
1287,
29,
4354,
2268,
63,
1364,
12,
4739,
17574,
10599,
14,
67,
297,
221,
2928,
63,
4511,
15637,
88,
358,
272,
671,
5012,
258,
275,
19286,
8,
1287,
29,
4354,
2268,
63,
2207,
82,
12,
258,
4739,
17574,
2207,
82,
14,
67,
297,
221,
2928,
63,
4511,
15637,
88,
358,
272,
2589,
14,
8310,
8,
8248,
3960,
3713,
18612,
4064,
287,
3041,
7,
221,
520,
1890,
12,
586,
283,
18612,
4064,
287,
2567,
7,
221,
520,
1406,
12,
586,
283,
18612,
4064,
287,
3167,
7,
520,
2435,
12,
586,
283,
18612,
4064,
287,
56,
4564,
7,
258,
520,
671,
5012,
1552,
272,
2589,
459,
18612,
4064,
742,
418,
275,
283,
4354,
2268,
7,
272,
2589,
459,
18612,
4064,
742,
4831,
418,
275,
8218,
14,
9562,
14,
1981,
5894,
8355,
272,
2589,
459,
18612,
4064,
742,
9901,
4831,
418,
275,
8218,
14,
9562,
14,
1981,
5894,
8355,
272,
2589,
459,
18612,
4064,
742,
7311,
4831,
418,
275,
8218,
14,
9562,
14,
1981,
5894,
8355,
272,
2589,
459,
18612,
4064,
742,
10486,
4831,
418,
275,
8218,
14,
9562,
14,
1981,
5894,
8355,
272,
2589,
459,
18612,
4064,
742,
56,
4564,
4831,
418,
275,
8218,
14,
9562,
14,
1981,
5894,
8355,
199,
199,
318,
3495,
8,
1813,
304,
272,
372,
2589,
14,
20064,
360,
4354,
2268,
358,
199,
199,
3,
10111,
17198,
26,
199,
3,
5174,
13,
2063,
26,
20,
199,
3,
4363,
13,
8741,
13,
632,
26,
20613,
199,
3,
9599,
26,
199,
3,
6695,
26,
663,
26414,
20849,
29,
20,
20105,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
18521,
14,
5157,
14,
4354,
2268,
199,
199,
5157,
13,
6100,
11097,
367,
820,
48,
4064,
742,
7249,
14,
199,
199,
21485,
12252,
9296,
1133,
506,
1263,
1929,
370,
492,
642,
859,
5370,
14,
199,
7940,
911,
9987,
506,
8439,
4012,
314,
7809,
8218,
14,
5157,
14,
5157,
342,
199,
5592,
1083,
14,
199,
624,
199,
199,
3,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
12,
6029,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
5157,
15,
4354,
2268,
14,
647,
4976,
13,
1651,
1367,
26,
1479,
2114,
26,
68,
1789,
66,
23,
65,
18,
70,
2322,
69,
24,
6029,
15,
2036,
15,
1717,
4114,
26,
1703,
26,
1651,
486,
695,
79,
2,
199,
199,
504,
8218,
14,
6437,
492,
19286,
199,
646,
8218,
14,
9562,
199,
199,
1760,
275,
298,
2866,
10839,
10187,
14,
694,
93,
10883,
2672,
18612,
4064,
742,
446,
5,
83,
2672,
18612,
4064,
742,
4831,
450,
83,
446,
79,
10839,
9268,
14,
4832,
93,
10839,
10187,
14,
493,
7063,
199,
199,
4354,
2268,
63,
1258,
257,
275,
2088,
450,
661,
76,
297,
4505,
18612,
4064,
742,
9901,
4831,
358,
199,
4354,
2268,
63,
1291,
257,
275,
2088,
450,
661,
72,
297,
4505,
18612,
4064,
742,
7311,
4831,
358,
199,
4354,
2268,
63,
1364,
221,
275,
2088,
450,
661,
77,
297,
4505,
18612,
4064,
742,
10486,
4831,
358,
199,
4354,
2268,
63,
2207,
82,
420,
275,
2088,
450,
661,
67,
297,
4505,
18612,
4064,
742,
56,
4564,
4831,
358,
199,
199,
318,
3550,
8,
1813,
304,
272,
298,
1123,
820,
48,
4064,
742,
19286,
83,
436,
14538,
2860,
367,
376,
9711,
2122,
2286,
1890,
221,
275,
19286,
8,
1287,
29,
4354,
2268,
63,
1258,
12,
221,
4739,
17574,
429,
343,
14,
67,
297,
2928,
63,
4511,
15637,
88,
358,
272,
1406,
221,
275,
19286,
8,
1287,
29,
4354,
2268,
63,
1291,
12,
221,
4739,
15637,
72,
297,
420,
2928,
63,
4511,
15637,
88,
358,
272,
2435,
275,
19286,
8,
1287,
29,
4354,
2268,
63,
1364,
12,
4739,
17574,
10599,
14,
67,
297,
221,
2928,
63,
4511,
15637,
88,
358,
272,
671,
5012,
258,
275,
19286,
8,
1287,
29,
4354,
2268,
63,
2207,
82,
12,
258,
4739,
17574,
2207,
82,
14,
67,
297,
221,
2928,
63,
4511,
15637,
88,
358,
272,
2589,
14,
8310,
8,
8248,
3960,
3713,
18612,
4064,
287,
3041,
7,
221,
520,
1890,
12,
586,
283,
18612,
4064,
287,
2567,
7,
221,
520,
1406,
12,
586,
283,
18612,
4064,
287,
3167,
7,
520,
2435,
12,
586,
283,
18612,
4064,
287,
56,
4564,
7,
258,
520,
671,
5012,
1552,
272,
2589,
459,
18612,
4064,
742,
418,
275,
283,
4354,
2268,
7,
272,
2589,
459,
18612,
4064,
742,
4831,
418,
275,
8218,
14,
9562,
14,
1981,
5894,
8355,
272,
2589,
459,
18612,
4064,
742,
9901,
4831,
418,
275,
8218,
14,
9562,
14,
1981,
5894,
8355,
272,
2589,
459,
18612,
4064,
742,
7311,
4831,
418,
275,
8218,
14,
9562,
14,
1981,
5894,
8355,
272,
2589,
459,
18612,
4064,
742,
10486,
4831,
418,
275,
8218,
14,
9562,
14,
1981,
5894,
8355,
272,
2589,
459,
18612,
4064,
742,
56,
4564,
4831,
418,
275,
8218,
14,
9562,
14,
1981,
5894,
8355,
199,
199,
318,
3495,
8,
1813,
304,
272,
372,
2589,
14,
20064,
360,
4354,
2268,
358,
199,
199,
3,
10111,
17198,
26,
199,
3,
5174,
13,
2063,
26,
20,
199,
3,
4363,
13,
8741,
13,
632,
26,
20613,
199,
3,
9599,
26,
199,
3,
6695,
26,
663,
26414,
20849,
29,
20,
20105,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
xebitstudios/nw.js
|
test/remoting/testcfg.py
|
68
|
2628
|
import test
import os
from os.path import join, dirname, exists, basename, isdir
import re
import utils
class RemotingTestCase(test.TestCase):
def __init__(self, path, file, arch, mode, nwdir, context, config, additional=[]):
super(RemotingTestCase, self).__init__(context, path, arch, mode, nwdir)
self.file = file
self.config = config
self.arch = arch
self.mode = mode
self.additional_flags = additional
self.nwdir = nwdir
def GetTmpDir(self):
return "%s.%d" % (self.tmpdir, self.thread_id)
def GetChromeDriver(self, arch, mode, nwdir):
if utils.IsWindows():
return os.path.abspath(join(nwdir, 'chromedriver.exe'))
return os.path.abspath(join(nwdir, 'chromedriver'))
def AfterRun(self, result):
return
def BeforeRun(self):
return
def GetLabel(self):
return "%s %s" % (self.mode, self.GetName())
def GetName(self):
return self.path[-1]
def GetEnv(self):
libpath = join(self.file, '..', '..', '..', '..', '..', 'third_party/webdriver/pylib')
return {'PYTHONPATH': libpath, 'CHROMEDRIVER': self.GetChromeDriver(self.arch, self.mode, self.nwdir)}
def GetCommand(self):
result = ['python']
result += [self.file + '/test.py']
return result
def IsFailureOutput(self, output):
return output.exit_code != 0
def GetSource(self):
return open(self.file).read()
class RemotingTestConfiguration(test.TestConfiguration):
def __init__(self, context, root, section, additional=[]):
super(RemotingTestConfiguration, self).__init__(context, root)
self.section = section
self.additional_flags = additional
def Ls(self, path):
def SelectTest(name):
return os.path.isdir(os.path.join(path, name))
return [f[0:] for f in os.listdir(path) if SelectTest(f)]
def ListTests(self, current_path, path, arch, mode, nwdir):
all_tests = [current_path + [t] for t in self.Ls(join(self.root))]
result = []
for test in all_tests:
if self.Contains(path, test):
file_path = join(self.root, reduce(join, test[1:], ""))
result.append(RemotingTestCase(test, file_path, arch, mode, nwdir, self.context,
self, self.additional_flags))
return result
def GetBuildRequirements(self):
return ['sample', 'sample=shell']
def GetTestStatus(self, sections, defs):
status_file = join(self.root, '%s.status' % (self.section))
if exists(status_file):
test.ReadConfigurationInto(status_file, sections, defs)
def GetConfiguration(context, root):
return RemotingTestConfiguration(context, root, 'remoting')
|
mit
|
[
646,
511,
199,
646,
747,
199,
504,
747,
14,
515,
492,
4263,
12,
9017,
12,
3495,
12,
9593,
12,
26004,
199,
646,
295,
199,
646,
3778,
199,
199,
533,
799,
77,
15866,
1746,
8,
396,
14,
1746,
304,
819,
347,
636,
826,
721,
277,
12,
931,
12,
570,
12,
3819,
12,
818,
12,
22823,
694,
12,
1067,
12,
1101,
12,
4722,
17894,
272,
1613,
8,
497,
77,
15866,
1746,
12,
291,
2843,
826,
721,
1100,
12,
931,
12,
3819,
12,
818,
12,
22823,
694,
9,
272,
291,
14,
493,
275,
570,
272,
291,
14,
888,
275,
1101,
272,
291,
14,
1047,
275,
3819,
272,
291,
14,
632,
275,
818,
272,
291,
14,
8460,
63,
2469,
275,
4722,
272,
291,
14,
13100,
694,
275,
22823,
694,
819,
347,
2372,
52,
311,
3567,
8,
277,
304,
272,
372,
2071,
83,
4111,
68,
2,
450,
334,
277,
14,
8616,
12,
291,
14,
2671,
63,
344,
9,
819,
347,
2372,
18083,
6158,
8,
277,
12,
3819,
12,
818,
12,
22823,
694,
304,
272,
340,
3778,
14,
1831,
8647,
837,
267,
372,
747,
14,
515,
14,
4832,
8,
904,
8,
13100,
694,
12,
283,
9887,
3090,
14,
5803,
1333,
339,
372,
747,
14,
515,
14,
4832,
8,
904,
8,
13100,
694,
12,
283,
9887,
3090,
1333,
12244,
347,
12836,
2540,
8,
277,
12,
754,
304,
489,
372,
819,
347,
21467,
2540,
8,
277,
304,
489,
372,
819,
347,
2372,
4314,
8,
277,
304,
272,
372,
2071,
83,
450,
83,
2,
450,
334,
277,
14,
632,
12,
291,
14,
21266,
1012,
819,
347,
2372,
985,
8,
277,
304,
272,
372,
291,
14,
515,
1988,
17,
61,
819,
347,
2372,
7744,
8,
277,
304,
489,
1973,
515,
275,
4263,
8,
277,
14,
493,
12,
19155,
19155,
19155,
19155,
19155,
283,
11470,
63,
7522,
15,
17946,
15,
24111,
358,
489,
372,
791,
29266,
356,
1973,
515,
12,
283,
30334,
1149,
6129,
2111,
356,
291,
14,
1002,
18083,
6158,
8,
277,
14,
1047,
12,
291,
14,
632,
12,
291,
14,
13100,
694,
6769,
819,
347,
2372,
3110,
8,
277,
304,
272,
754,
275,
788,
1548,
418,
272,
754,
847,
359,
277,
14,
493,
435,
1994,
396,
14,
647,
418,
339,
372,
754,
819,
347,
6596,
6782,
2959,
8,
277,
12,
1072,
304,
272,
372,
1072,
14,
2224,
63,
600,
1137,
378,
819,
347,
2372,
2980,
8,
277,
304,
272,
372,
1551,
8,
277,
14,
493,
680,
739,
342,
199,
199,
533,
799,
77,
15866,
774,
5688,
8,
396,
14,
774,
5688,
304,
819,
347,
636,
826,
721,
277,
12,
1067,
12,
1738,
12,
3420,
12,
4722,
17894,
272,
1613,
8,
497,
77,
15866,
774,
5688,
12,
291,
2843,
826,
721,
1100,
12,
1738,
9,
272,
291,
14,
2792,
275,
3420,
272,
291,
14,
8460,
63,
2469,
275,
4722,
819,
347,
491,
83,
8,
277,
12,
931,
304,
272,
347,
9496,
774,
8,
354,
304,
489,
372,
747,
14,
515,
14,
6027,
8,
736,
14,
515,
14,
904,
8,
515,
12,
536,
430,
272,
372,
359,
70,
59,
16,
2938,
367,
289,
315,
747,
14,
7374,
8,
515,
9,
340,
9496,
774,
8,
70,
1874,
819,
347,
3820,
2925,
8,
277,
12,
1453,
63,
515,
12,
931,
12,
3819,
12,
818,
12,
22823,
694,
304,
272,
1006,
63,
2219,
275,
359,
1818,
63,
515,
435,
359,
84,
61,
367,
307,
315,
291,
14,
44,
83,
8,
904,
8,
277,
14,
1231,
10524,
272,
754,
275,
942,
272,
367,
511,
315,
1006,
63,
2219,
26,
489,
340,
291,
14,
6906,
8,
515,
12,
511,
304,
267,
570,
63,
515,
275,
4263,
8,
277,
14,
1231,
12,
7114,
8,
904,
12,
511,
59,
17,
8429,
25491,
267,
754,
14,
740,
8,
497,
77,
15866,
1746,
8,
396,
12,
570,
63,
515,
12,
3819,
12,
818,
12,
22823,
694,
12,
291,
14,
1100,
12,
3660,
291,
12,
291,
14,
8460,
63,
2469,
430,
272,
372,
754,
819,
347,
2372,
3425,
13902,
1470,
8,
277,
304,
272,
372,
788,
3271,
297,
283,
3271,
29,
5641,
418,
819,
347,
2372,
774,
3694,
8,
277,
12,
10189,
12,
22603,
304,
272,
2004,
63,
493,
275,
4263,
8,
277,
14,
1231,
12,
1543,
83,
14,
1205,
7,
450,
334,
277,
14,
2792,
430,
272,
340,
3495,
8,
1205,
63,
493,
304,
489,
511,
14,
3284,
5688,
19448,
8,
1205,
63,
493,
12,
10189,
12,
22603,
9,
199,
199,
318,
2372,
5688,
8,
1100,
12,
1738,
304,
523,
372,
799,
77,
15866,
774,
5688,
8,
1100,
12,
1738,
12,
283,
13179,
15866,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
511,
199,
646,
747,
199,
504,
747,
14,
515,
492,
4263,
12,
9017,
12,
3495,
12,
9593,
12,
26004,
199,
646,
295,
199,
646,
3778,
199,
199,
533,
799,
77,
15866,
1746,
8,
396,
14,
1746,
304,
819,
347,
636,
826,
721,
277,
12,
931,
12,
570,
12,
3819,
12,
818,
12,
22823,
694,
12,
1067,
12,
1101,
12,
4722,
17894,
272,
1613,
8,
497,
77,
15866,
1746,
12,
291,
2843,
826,
721,
1100,
12,
931,
12,
3819,
12,
818,
12,
22823,
694,
9,
272,
291,
14,
493,
275,
570,
272,
291,
14,
888,
275,
1101,
272,
291,
14,
1047,
275,
3819,
272,
291,
14,
632,
275,
818,
272,
291,
14,
8460,
63,
2469,
275,
4722,
272,
291,
14,
13100,
694,
275,
22823,
694,
819,
347,
2372,
52,
311,
3567,
8,
277,
304,
272,
372,
2071,
83,
4111,
68,
2,
450,
334,
277,
14,
8616,
12,
291,
14,
2671,
63,
344,
9,
819,
347,
2372,
18083,
6158,
8,
277,
12,
3819,
12,
818,
12,
22823,
694,
304,
272,
340,
3778,
14,
1831,
8647,
837,
267,
372,
747,
14,
515,
14,
4832,
8,
904,
8,
13100,
694,
12,
283,
9887,
3090,
14,
5803,
1333,
339,
372,
747,
14,
515,
14,
4832,
8,
904,
8,
13100,
694,
12,
283,
9887,
3090,
1333,
12244,
347,
12836,
2540,
8,
277,
12,
754,
304,
489,
372,
819,
347,
21467,
2540,
8,
277,
304,
489,
372,
819,
347,
2372,
4314,
8,
277,
304,
272,
372,
2071,
83,
450,
83,
2,
450,
334,
277,
14,
632,
12,
291,
14,
21266,
1012,
819,
347,
2372,
985,
8,
277,
304,
272,
372,
291,
14,
515,
1988,
17,
61,
819,
347,
2372,
7744,
8,
277,
304,
489,
1973,
515,
275,
4263,
8,
277,
14,
493,
12,
19155,
19155,
19155,
19155,
19155,
283,
11470,
63,
7522,
15,
17946,
15,
24111,
358,
489,
372,
791,
29266,
356,
1973,
515,
12,
283,
30334,
1149,
6129,
2111,
356,
291,
14,
1002,
18083,
6158,
8,
277,
14,
1047,
12,
291,
14,
632,
12,
291,
14,
13100,
694,
6769,
819,
347,
2372,
3110,
8,
277,
304,
272,
754,
275,
788,
1548,
418,
272,
754,
847,
359,
277,
14,
493,
435,
1994,
396,
14,
647,
418,
339,
372,
754,
819,
347,
6596,
6782,
2959,
8,
277,
12,
1072,
304,
272,
372,
1072,
14,
2224,
63,
600,
1137,
378,
819,
347,
2372,
2980,
8,
277,
304,
272,
372,
1551,
8,
277,
14,
493,
680,
739,
342,
199,
199,
533,
799,
77,
15866,
774,
5688,
8,
396,
14,
774,
5688,
304,
819,
347,
636,
826,
721,
277,
12,
1067,
12,
1738,
12,
3420,
12,
4722,
17894,
272,
1613,
8,
497,
77,
15866,
774,
5688,
12,
291,
2843,
826,
721,
1100,
12,
1738,
9,
272,
291,
14,
2792,
275,
3420,
272,
291,
14,
8460,
63,
2469,
275,
4722,
819,
347,
491,
83,
8,
277,
12,
931,
304,
272,
347,
9496,
774,
8,
354,
304,
489,
372,
747,
14,
515,
14,
6027,
8,
736,
14,
515,
14,
904,
8,
515,
12,
536,
430,
272,
372,
359,
70,
59,
16,
2938,
367,
289,
315,
747,
14,
7374,
8,
515,
9,
340,
9496,
774,
8,
70,
1874,
819,
347,
3820,
2925,
8,
277,
12,
1453,
63,
515,
12,
931,
12,
3819,
12,
818,
12,
22823,
694,
304,
272,
1006,
63,
2219,
275,
359,
1818,
63,
515,
435,
359,
84,
61,
367,
307,
315,
291,
14,
44,
83,
8,
904,
8,
277,
14,
1231,
10524,
272,
754,
275,
942,
272,
367,
511,
315,
1006,
63,
2219,
26,
489,
340,
291,
14,
6906,
8,
515,
12,
511,
304,
267,
570,
63,
515,
275,
4263,
8,
277,
14,
1231,
12,
7114,
8,
904,
12,
511,
59,
17,
8429,
25491,
267,
754,
14,
740,
8,
497,
77,
15866,
1746,
8,
396,
12,
570,
63,
515,
12,
3819,
12,
818,
12,
22823,
694,
12,
291,
14,
1100,
12,
3660,
291,
12,
291,
14,
8460,
63,
2469,
430,
272,
372,
754,
819,
347,
2372,
3425,
13902,
1470,
8,
277,
304,
272,
372,
788,
3271,
297,
283,
3271,
29,
5641,
418,
819,
347,
2372,
774,
3694,
8,
277,
12,
10189,
12,
22603,
304,
272,
2004,
63,
493,
275,
4263,
8,
277,
14,
1231,
12,
1543,
83,
14,
1205,
7,
450,
334,
277,
14,
2792,
430,
272,
340,
3495,
8,
1205,
63,
493,
304,
489,
511,
14,
3284,
5688,
19448,
8,
1205,
63,
493,
12,
10189,
12,
22603,
9,
199,
199,
318,
2372,
5688,
8,
1100,
12,
1738,
304,
523,
372,
799,
77,
15866,
774,
5688,
8,
1100,
12,
1738,
12,
283,
13179,
15866,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
DeadBugEngineering/myHDL_shenanigans
|
ssd1306_8x64bit_driver/myhdl_10dev/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/__init__.py
|
152
|
2854
|
"""
urllib3 - Thread-safe connection pooling and re-using.
"""
from __future__ import absolute_import
import warnings
from .connectionpool import (
HTTPConnectionPool,
HTTPSConnectionPool,
connection_from_url
)
from . import exceptions
from .filepost import encode_multipart_formdata
from .poolmanager import PoolManager, ProxyManager, proxy_from_url
from .response import HTTPResponse
from .util.request import make_headers
from .util.url import get_host
from .util.timeout import Timeout
from .util.retry import Retry
# Set default logging handler to avoid "No handler found" warnings.
import logging
try: # Python 2.7+
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
__author__ = 'Andrey Petrov (andrey.petrov@shazow.net)'
__license__ = 'MIT'
__version__ = '1.15.1'
__all__ = (
'HTTPConnectionPool',
'HTTPSConnectionPool',
'PoolManager',
'ProxyManager',
'HTTPResponse',
'Retry',
'Timeout',
'add_stderr_logger',
'connection_from_url',
'disable_warnings',
'encode_multipart_formdata',
'get_host',
'make_headers',
'proxy_from_url',
)
logging.getLogger(__name__).addHandler(NullHandler())
def add_stderr_logger(level=logging.DEBUG):
"""
Helper for quickly adding a StreamHandler to the logger. Useful for
debugging.
Returns the handler after adding it.
"""
# This method needs to be in this __init__.py to get the __name__ correct
# even if urllib3 is vendored within another package.
logger = logging.getLogger(__name__)
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
logger.addHandler(handler)
logger.setLevel(level)
logger.debug('Added a stderr logging handler to logger: %s', __name__)
return handler
# ... Clean up.
del NullHandler
# All warning filters *must* be appended unless you're really certain that they
# shouldn't be: otherwise, it's very hard for users to use most Python
# mechanisms to silence them.
# SecurityWarning's always go off by default.
warnings.simplefilter('always', exceptions.SecurityWarning, append=True)
# SubjectAltNameWarning's should go off once per host
warnings.simplefilter('default', exceptions.SubjectAltNameWarning, append=True)
# InsecurePlatformWarning's don't vary between requests, so we keep it default.
warnings.simplefilter('default', exceptions.InsecurePlatformWarning,
append=True)
# SNIMissingWarnings should go off only once.
warnings.simplefilter('default', exceptions.SNIMissingWarning, append=True)
def disable_warnings(category=exceptions.HTTPWarning):
"""
Helper for quickly disabling all urllib3 warnings.
"""
warnings.simplefilter('ignore', category)
|
lgpl-2.1
|
[
624,
199,
4078,
19,
446,
11086,
13,
3489,
1950,
20699,
436,
295,
13,
4941,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
3598,
199,
199,
504,
1275,
2105,
2293,
492,
334,
272,
3101,
23929,
12,
272,
14147,
23929,
12,
272,
1950,
63,
504,
63,
633,
199,
9,
199,
199,
504,
1275,
492,
4967,
199,
504,
1275,
493,
1932,
492,
3752,
63,
10123,
63,
30942,
199,
504,
1275,
2293,
2609,
492,
15553,
2988,
12,
12373,
2988,
12,
4566,
63,
504,
63,
633,
199,
504,
1275,
1310,
492,
29034,
199,
504,
1275,
1974,
14,
1069,
492,
1852,
63,
2139,
199,
504,
1275,
1974,
14,
633,
492,
664,
63,
1102,
199,
504,
1275,
1974,
14,
2593,
492,
12878,
199,
504,
1275,
1974,
14,
7154,
492,
20506,
421,
199,
3,
2494,
849,
2050,
3016,
370,
5126,
298,
1944,
3016,
1911,
2,
3598,
14,
199,
646,
2050,
199,
893,
26,
221,
327,
2018,
499,
14,
23,
11,
272,
687,
2050,
492,
12119,
2461,
199,
2590,
3545,
26,
272,
1021,
12119,
2461,
8,
4806,
14,
2461,
304,
267,
347,
8689,
8,
277,
12,
2777,
304,
288,
986,
199,
199,
363,
2502,
363,
275,
283,
3325,
17885,
31449,
293,
86,
334,
460,
17885,
14,
321,
1374,
86,
32,
609,
4651,
583,
14,
846,
3171,
199,
363,
1682,
363,
275,
283,
13965,
7,
199,
363,
1023,
363,
275,
283,
17,
14,
1046,
14,
17,
7,
199,
199,
363,
452,
363,
275,
334,
272,
283,
19114,
5453,
297,
272,
283,
14921,
23929,
297,
272,
283,
5453,
2988,
297,
272,
283,
4936,
2988,
297,
272,
283,
27068,
297,
272,
283,
12989,
297,
272,
283,
6372,
297,
272,
283,
525,
63,
3083,
63,
2921,
297,
272,
283,
2105,
63,
504,
63,
633,
297,
272,
283,
5993,
63,
5451,
297,
272,
283,
2143,
63,
10123,
63,
30942,
297,
272,
283,
362,
63,
1102,
297,
272,
283,
1875,
63,
2139,
297,
272,
283,
3280,
63,
504,
63,
633,
297,
199,
9,
199,
199,
4806,
14,
5572,
3460,
354,
28634,
18826,
8,
8849,
2461,
1012,
421,
199,
318,
1050,
63,
3083,
63,
2921,
8,
1896,
29,
4806,
14,
5287,
304,
272,
408,
272,
11642,
367,
23661,
7791,
282,
8271,
2461,
370,
314,
2512,
14,
18491,
367,
272,
10201,
14,
339,
1803,
314,
3016,
2410,
7791,
652,
14,
272,
408,
272,
327,
961,
1083,
4839,
370,
506,
315,
642,
636,
826,
4343,
647,
370,
664,
314,
636,
354,
363,
3211,
272,
327,
2755,
340,
4011,
19,
365,
373,
500,
2908,
4453,
4573,
2559,
14,
272,
2512,
275,
2050,
14,
5572,
3460,
354,
3368,
272,
3016,
275,
2050,
14,
22482,
342,
272,
3016,
14,
26076,
8,
4806,
14,
7772,
24713,
18331,
9,
83,
2818,
20056,
9,
83,
2818,
1188,
9,
83,
1333,
272,
2512,
14,
18826,
8,
2232,
9,
272,
2512,
14,
13548,
8,
1896,
9,
272,
2512,
14,
1757,
360,
20201,
282,
4635,
2050,
3016,
370,
2512,
26,
450,
83,
297,
636,
354,
3368,
272,
372,
3016,
199,
199,
3,
2263,
12762,
1536,
14,
199,
2264,
12119,
2461,
421,
199,
3,
2900,
5721,
4766,
627,
7790,
10,
506,
11544,
7444,
1265,
3984,
7710,
9842,
626,
2985,
199,
3,
9296,
1133,
506,
26,
4257,
12,
652,
1159,
7437,
7508,
367,
4390,
370,
675,
4750,
2018,
199,
3,
562,
10832,
706,
370,
9767,
21225,
3062,
14,
199,
3,
13863,
3849,
1159,
3544,
2621,
2331,
701,
849,
14,
199,
5451,
14,
18815,
360,
9223,
297,
4967,
14,
7676,
3849,
12,
5666,
29,
549,
9,
199,
3,
26793,
29171,
3849,
1159,
1077,
2621,
2331,
5403,
1126,
1591,
199,
5451,
14,
18815,
360,
885,
297,
4967,
14,
13528,
29171,
3849,
12,
5666,
29,
549,
9,
199,
3,
1010,
7817,
10397,
3849,
1159,
2793,
1133,
17083,
3382,
4145,
12,
880,
781,
4215,
652,
849,
14,
199,
5451,
14,
18815,
360,
885,
297,
4967,
14,
607,
7817,
10397,
3849,
12,
1993,
5666,
29,
549,
9,
199,
3,
428,
46,
1469,
374,
1044,
15921,
1077,
2621,
2331,
1454,
5403,
14,
199,
5451,
14,
18815,
360,
885,
297,
4967,
14,
8199,
1469,
374,
1044,
3849,
12,
5666,
29,
549,
9,
421,
199,
318,
3507,
63,
5451,
8,
3710,
29,
3924,
14,
2856,
3849,
304,
272,
408,
272,
11642,
367,
23661,
30723,
1006,
4011,
19,
3598,
14,
272,
408,
272,
3598,
14,
18815,
360,
4247,
297,
4637,
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
] |
[
199,
4078,
19,
446,
11086,
13,
3489,
1950,
20699,
436,
295,
13,
4941,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
3598,
199,
199,
504,
1275,
2105,
2293,
492,
334,
272,
3101,
23929,
12,
272,
14147,
23929,
12,
272,
1950,
63,
504,
63,
633,
199,
9,
199,
199,
504,
1275,
492,
4967,
199,
504,
1275,
493,
1932,
492,
3752,
63,
10123,
63,
30942,
199,
504,
1275,
2293,
2609,
492,
15553,
2988,
12,
12373,
2988,
12,
4566,
63,
504,
63,
633,
199,
504,
1275,
1310,
492,
29034,
199,
504,
1275,
1974,
14,
1069,
492,
1852,
63,
2139,
199,
504,
1275,
1974,
14,
633,
492,
664,
63,
1102,
199,
504,
1275,
1974,
14,
2593,
492,
12878,
199,
504,
1275,
1974,
14,
7154,
492,
20506,
421,
199,
3,
2494,
849,
2050,
3016,
370,
5126,
298,
1944,
3016,
1911,
2,
3598,
14,
199,
646,
2050,
199,
893,
26,
221,
327,
2018,
499,
14,
23,
11,
272,
687,
2050,
492,
12119,
2461,
199,
2590,
3545,
26,
272,
1021,
12119,
2461,
8,
4806,
14,
2461,
304,
267,
347,
8689,
8,
277,
12,
2777,
304,
288,
986,
199,
199,
363,
2502,
363,
275,
283,
3325,
17885,
31449,
293,
86,
334,
460,
17885,
14,
321,
1374,
86,
32,
609,
4651,
583,
14,
846,
3171,
199,
363,
1682,
363,
275,
283,
13965,
7,
199,
363,
1023,
363,
275,
283,
17,
14,
1046,
14,
17,
7,
199,
199,
363,
452,
363,
275,
334,
272,
283,
19114,
5453,
297,
272,
283,
14921,
23929,
297,
272,
283,
5453,
2988,
297,
272,
283,
4936,
2988,
297,
272,
283,
27068,
297,
272,
283,
12989,
297,
272,
283,
6372,
297,
272,
283,
525,
63,
3083,
63,
2921,
297,
272,
283,
2105,
63,
504,
63,
633,
297,
272,
283,
5993,
63,
5451,
297,
272,
283,
2143,
63,
10123,
63,
30942,
297,
272,
283,
362,
63,
1102,
297,
272,
283,
1875,
63,
2139,
297,
272,
283,
3280,
63,
504,
63,
633,
297,
199,
9,
199,
199,
4806,
14,
5572,
3460,
354,
28634,
18826,
8,
8849,
2461,
1012,
421,
199,
318,
1050,
63,
3083,
63,
2921,
8,
1896,
29,
4806,
14,
5287,
304,
272,
408,
272,
11642,
367,
23661,
7791,
282,
8271,
2461,
370,
314,
2512,
14,
18491,
367,
272,
10201,
14,
339,
1803,
314,
3016,
2410,
7791,
652,
14,
272,
408,
272,
327,
961,
1083,
4839,
370,
506,
315,
642,
636,
826,
4343,
647,
370,
664,
314,
636,
354,
363,
3211,
272,
327,
2755,
340,
4011,
19,
365,
373,
500,
2908,
4453,
4573,
2559,
14,
272,
2512,
275,
2050,
14,
5572,
3460,
354,
3368,
272,
3016,
275,
2050,
14,
22482,
342,
272,
3016,
14,
26076,
8,
4806,
14,
7772,
24713,
18331,
9,
83,
2818,
20056,
9,
83,
2818,
1188,
9,
83,
1333,
272,
2512,
14,
18826,
8,
2232,
9,
272,
2512,
14,
13548,
8,
1896,
9,
272,
2512,
14,
1757,
360,
20201,
282,
4635,
2050,
3016,
370,
2512,
26,
450,
83,
297,
636,
354,
3368,
272,
372,
3016,
199,
199,
3,
2263,
12762,
1536,
14,
199,
2264,
12119,
2461,
421,
199,
3,
2900,
5721,
4766,
627,
7790,
10,
506,
11544,
7444,
1265,
3984,
7710,
9842,
626,
2985,
199,
3,
9296,
1133,
506,
26,
4257,
12,
652,
1159,
7437,
7508,
367,
4390,
370,
675,
4750,
2018,
199,
3,
562,
10832,
706,
370,
9767,
21225,
3062,
14,
199,
3,
13863,
3849,
1159,
3544,
2621,
2331,
701,
849,
14,
199,
5451,
14,
18815,
360,
9223,
297,
4967,
14,
7676,
3849,
12,
5666,
29,
549,
9,
199,
3,
26793,
29171,
3849,
1159,
1077,
2621,
2331,
5403,
1126,
1591,
199,
5451,
14,
18815,
360,
885,
297,
4967,
14,
13528,
29171,
3849,
12,
5666,
29,
549,
9,
199,
3,
1010,
7817,
10397,
3849,
1159,
2793,
1133,
17083,
3382,
4145,
12,
880,
781,
4215,
652,
849,
14,
199,
5451,
14,
18815,
360,
885,
297,
4967,
14,
607,
7817,
10397,
3849,
12,
1993,
5666,
29,
549,
9,
199,
3,
428,
46,
1469,
374,
1044,
15921,
1077,
2621,
2331,
1454,
5403,
14,
199,
5451,
14,
18815,
360,
885,
297,
4967,
14,
8199,
1469,
374,
1044,
3849,
12,
5666,
29,
549,
9,
421,
199,
318,
3507,
63,
5451,
8,
3710,
29,
3924,
14,
2856,
3849,
304,
272,
408,
272,
11642,
367,
23661,
30723,
1006,
4011,
19,
3598,
14,
272,
408,
272,
3598,
14,
18815,
360,
4247,
297,
4637,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
MalloyPower/parsing-python
|
front-end/testsuite-python-lib/Python-3.1/Lib/email/feedparser.py
|
2
|
20356
|
# Copyright (C) 2004-2006 Python Software Foundation
# Authors: Baxter, Wouters and Warsaw
# Contact: email-sig@python.org
"""FeedParser - An email feed parser.
The feed parser implements an interface for incrementally parsing an email
message, line by line. This has advantages for certain applications, such as
those reading email messages off a socket.
FeedParser.feed() is the primary interface for pushing new data into the
parser. It returns when there's nothing more it can do with the available
data. When you have no more data to push into the parser, call .close().
This completes the parsing and returns the root message object.
The other advantage of this parser is that it will never throw a parsing
exception. Instead, when it finds something unexpected, it adds a 'defect' to
the current message. Defects are just instances that live on the message
object's .defects attribute.
"""
__all__ = ['FeedParser']
import re
from email import errors
from email import message
NLCRE = re.compile('\r\n|\r|\n')
NLCRE_bol = re.compile('(\r\n|\r|\n)')
NLCRE_eol = re.compile('(\r\n|\r|\n)$')
NLCRE_crack = re.compile('(\r\n|\r|\n)')
# RFC 2822 $3.6.8 Optional fields. ftext is %d33-57 / %d59-126, Any character
# except controls, SP, and ":".
headerRE = re.compile(r'^(From |[\041-\071\073-\176]{1,}:|[\t ])')
EMPTYSTRING = ''
NL = '\n'
NeedMoreData = object()
class BufferedSubFile(object):
"""A file-ish object that can have new data loaded into it.
You can also push and pop line-matching predicates onto a stack. When the
current predicate matches the current line, a false EOF response
(i.e. empty string) is returned instead. This lets the parser adhere to a
simple abstraction -- it parses until EOF closes the current message.
"""
def __init__(self):
# The last partial line pushed into this object.
self._partial = ''
# The list of full, pushed lines, in reverse order
self._lines = []
# The stack of false-EOF checking predicates.
self._eofstack = []
# A flag indicating whether the file has been closed or not.
self._closed = False
def push_eof_matcher(self, pred):
self._eofstack.append(pred)
def pop_eof_matcher(self):
return self._eofstack.pop()
def close(self):
# Don't forget any trailing partial line.
self._lines.append(self._partial)
self._partial = ''
self._closed = True
def readline(self):
if not self._lines:
if self._closed:
return ''
return NeedMoreData
# Pop the line off the stack and see if it matches the current
# false-EOF predicate.
line = self._lines.pop()
# RFC 2046, section 5.1.2 requires us to recognize outer level
# boundaries at any level of inner nesting. Do this, but be sure it's
# in the order of most to least nested.
for ateof in self._eofstack[::-1]:
if ateof(line):
# We're at the false EOF. But push the last line back first.
self._lines.append(line)
return ''
return line
def unreadline(self, line):
# Let the consumer push a line back into the buffer.
assert line is not NeedMoreData
self._lines.append(line)
def push(self, data):
"""Push some new data into this object."""
# Handle any previous leftovers
data, self._partial = self._partial + data, ''
# Crack into lines, but preserve the newlines on the end of each
parts = NLCRE_crack.split(data)
# The *ahem* interesting behaviour of re.split when supplied grouping
# parentheses is that the last element of the resulting list is the
# data after the final RE. In the case of a NL/CR terminated string,
# this is the empty string.
self._partial = parts.pop()
# parts is a list of strings, alternating between the line contents
# and the eol character(s). Gather up a list of lines after
# re-attaching the newlines.
lines = []
for i in range(len(parts) // 2):
lines.append(parts[i*2] + parts[i*2+1])
self.pushlines(lines)
def pushlines(self, lines):
# Reverse and insert at the front of the lines.
self._lines[:0] = lines[::-1]
def is_closed(self):
return self._closed
def __iter__(self):
return self
def __next__(self):
line = self.readline()
if line == '':
raise StopIteration
return line
class FeedParser:
"""A feed-style parser of email."""
def __init__(self, _factory=message.Message):
"""_factory is called with no arguments to create a new message obj"""
self._factory = _factory
self._input = BufferedSubFile()
self._msgstack = []
self._parse = self._parsegen().__next__
self._cur = None
self._last = None
self._headersonly = False
# Non-public interface for supporting Parser's headersonly flag
def _set_headersonly(self):
self._headersonly = True
def feed(self, data):
"""Push more data into the parser."""
self._input.push(data)
self._call_parse()
def _call_parse(self):
try:
self._parse()
except StopIteration:
pass
def close(self):
"""Parse all remaining data and return the root message object."""
self._input.close()
self._call_parse()
root = self._pop_message()
assert not self._msgstack
# Look for final set of defects
if root.get_content_maintype() == 'multipart' \
and not root.is_multipart():
root.defects.append(errors.MultipartInvariantViolationDefect())
return root
def _new_message(self):
msg = self._factory()
if self._cur and self._cur.get_content_type() == 'multipart/digest':
msg.set_default_type('message/rfc822')
if self._msgstack:
self._msgstack[-1].attach(msg)
self._msgstack.append(msg)
self._cur = msg
self._last = msg
def _pop_message(self):
retval = self._msgstack.pop()
if self._msgstack:
self._cur = self._msgstack[-1]
else:
self._cur = None
return retval
def _parsegen(self):
# Create a new message and start by parsing headers.
self._new_message()
headers = []
# Collect the headers, searching for a line that doesn't match the RFC
# 2822 header or continuation pattern (including an empty line).
for line in self._input:
if line is NeedMoreData:
yield NeedMoreData
continue
if not headerRE.match(line):
# If we saw the RFC defined header/body separator
# (i.e. newline), just throw it away. Otherwise the line is
# part of the body so push it back.
if not NLCRE.match(line):
self._input.unreadline(line)
break
headers.append(line)
# Done with the headers, so parse them and figure out what we're
# supposed to see in the body of the message.
self._parse_headers(headers)
# Headers-only parsing is a backwards compatibility hack, which was
# necessary in the older parser, which could throw errors. All
# remaining lines in the input are thrown into the message body.
if self._headersonly:
lines = []
while True:
line = self._input.readline()
if line is NeedMoreData:
yield NeedMoreData
continue
if line == '':
break
lines.append(line)
self._cur.set_payload(EMPTYSTRING.join(lines))
return
if self._cur.get_content_type() == 'message/delivery-status':
# message/delivery-status contains blocks of headers separated by
# a blank line. We'll represent each header block as a separate
# nested message object, but the processing is a bit different
# than standard message/* types because there is no body for the
# nested messages. A blank line separates the subparts.
while True:
self._input.push_eof_matcher(NLCRE.match)
for retval in self._parsegen():
if retval is NeedMoreData:
yield NeedMoreData
continue
break
msg = self._pop_message()
# We need to pop the EOF matcher in order to tell if we're at
# the end of the current file, not the end of the last block
# of message headers.
self._input.pop_eof_matcher()
# The input stream must be sitting at the newline or at the
# EOF. We want to see if we're at the end of this subpart, so
# first consume the blank line, then test the next line to see
# if we're at this subpart's EOF.
while True:
line = self._input.readline()
if line is NeedMoreData:
yield NeedMoreData
continue
break
while True:
line = self._input.readline()
if line is NeedMoreData:
yield NeedMoreData
continue
break
if line == '':
break
# Not at EOF so this is a line we're going to need.
self._input.unreadline(line)
return
if self._cur.get_content_maintype() == 'message':
# The message claims to be a message/* type, then what follows is
# another RFC 2822 message.
for retval in self._parsegen():
if retval is NeedMoreData:
yield NeedMoreData
continue
break
self._pop_message()
return
if self._cur.get_content_maintype() == 'multipart':
boundary = self._cur.get_boundary()
if boundary is None:
# The message /claims/ to be a multipart but it has not
# defined a boundary. That's a problem which we'll handle by
# reading everything until the EOF and marking the message as
# defective.
self._cur.defects.append(errors.NoBoundaryInMultipartDefect())
lines = []
for line in self._input:
if line is NeedMoreData:
yield NeedMoreData
continue
lines.append(line)
self._cur.set_payload(EMPTYSTRING.join(lines))
return
# Create a line match predicate which matches the inter-part
# boundary as well as the end-of-multipart boundary. Don't push
# this onto the input stream until we've scanned past the
# preamble.
separator = '--' + boundary
boundaryre = re.compile(
'(?P<sep>' + re.escape(separator) +
r')(?P<end>--)?(?P<ws>[ \t]*)(?P<linesep>\r\n|\r|\n)?$')
capturing_preamble = True
preamble = []
linesep = False
while True:
line = self._input.readline()
if line is NeedMoreData:
yield NeedMoreData
continue
if line == '':
break
mo = boundaryre.match(line)
if mo:
# If we're looking at the end boundary, we're done with
# this multipart. If there was a newline at the end of
# the closing boundary, then we need to initialize the
# epilogue with the empty string (see below).
if mo.group('end'):
linesep = mo.group('linesep')
break
# We saw an inter-part boundary. Were we in the preamble?
if capturing_preamble:
if preamble:
# According to RFC 2046, the last newline belongs
# to the boundary.
lastline = preamble[-1]
eolmo = NLCRE_eol.search(lastline)
if eolmo:
preamble[-1] = lastline[:-len(eolmo.group(0))]
self._cur.preamble = EMPTYSTRING.join(preamble)
capturing_preamble = False
self._input.unreadline(line)
continue
# We saw a boundary separating two parts. Consume any
# multiple boundary lines that may be following. Our
# interpretation of RFC 2046 BNF grammar does not produce
# body parts within such double boundaries.
while True:
line = self._input.readline()
if line is NeedMoreData:
yield NeedMoreData
continue
mo = boundaryre.match(line)
if not mo:
self._input.unreadline(line)
break
# Recurse to parse this subpart; the input stream points
# at the subpart's first line.
self._input.push_eof_matcher(boundaryre.match)
for retval in self._parsegen():
if retval is NeedMoreData:
yield NeedMoreData
continue
break
# Because of RFC 2046, the newline preceding the boundary
# separator actually belongs to the boundary, not the
# previous subpart's payload (or epilogue if the previous
# part is a multipart).
if self._last.get_content_maintype() == 'multipart':
epilogue = self._last.epilogue
if epilogue == '':
self._last.epilogue = None
elif epilogue is not None:
mo = NLCRE_eol.search(epilogue)
if mo:
end = len(mo.group(0))
self._last.epilogue = epilogue[:-end]
else:
payload = self._last.get_payload()
if isinstance(payload, str):
mo = NLCRE_eol.search(payload)
if mo:
payload = payload[:-len(mo.group(0))]
self._last.set_payload(payload)
self._input.pop_eof_matcher()
self._pop_message()
# Set the multipart up for newline cleansing, which will
# happen if we're in a nested multipart.
self._last = self._cur
else:
# I think we must be in the preamble
assert capturing_preamble
preamble.append(line)
# We've seen either the EOF or the end boundary. If we're still
# capturing the preamble, we never saw the start boundary. Note
# that as a defect and store the captured text as the payload.
# Everything from here to the EOF is epilogue.
if capturing_preamble:
self._cur.defects.append(errors.StartBoundaryNotFoundDefect())
self._cur.set_payload(EMPTYSTRING.join(preamble))
epilogue = []
for line in self._input:
if line is NeedMoreData:
yield NeedMoreData
continue
self._cur.epilogue = EMPTYSTRING.join(epilogue)
return
# If the end boundary ended in a newline, we'll need to make sure
# the epilogue isn't None
if linesep:
epilogue = ['']
else:
epilogue = []
for line in self._input:
if line is NeedMoreData:
yield NeedMoreData
continue
epilogue.append(line)
# Any CRLF at the front of the epilogue is not technically part of
# the epilogue. Also, watch out for an empty string epilogue,
# which means a single newline.
if epilogue:
firstline = epilogue[0]
bolmo = NLCRE_bol.match(firstline)
if bolmo:
epilogue[0] = firstline[len(bolmo.group(0)):]
self._cur.epilogue = EMPTYSTRING.join(epilogue)
return
# Otherwise, it's some non-multipart type, so the entire rest of the
# file contents becomes the payload.
lines = []
for line in self._input:
if line is NeedMoreData:
yield NeedMoreData
continue
lines.append(line)
self._cur.set_payload(EMPTYSTRING.join(lines))
def _parse_headers(self, lines):
# Passed a list of lines that make up the headers for the current msg
lastheader = ''
lastvalue = []
for lineno, line in enumerate(lines):
# Check for continuation
if line[0] in ' \t':
if not lastheader:
# The first line of the headers was a continuation. This
# is illegal, so let's note the defect, store the illegal
# line, and ignore it for purposes of headers.
defect = errors.FirstHeaderLineIsContinuationDefect(line)
self._cur.defects.append(defect)
continue
lastvalue.append(line)
continue
if lastheader:
# XXX reconsider the joining of folded lines
lhdr = EMPTYSTRING.join(lastvalue)[:-1].rstrip('\r\n')
self._cur[lastheader] = lhdr
lastheader, lastvalue = '', []
# Check for envelope header, i.e. unix-from
if line.startswith('From '):
if lineno == 0:
# Strip off the trailing newline
mo = NLCRE_eol.search(line)
if mo:
line = line[:-len(mo.group(0))]
self._cur.set_unixfrom(line)
continue
elif lineno == len(lines) - 1:
# Something looking like a unix-from at the end - it's
# probably the first line of the body, so push back the
# line and stop.
self._input.unreadline(line)
return
else:
# Weirdly placed unix-from line. Note this as a defect
# and ignore it.
defect = errors.MisplacedEnvelopeHeaderDefect(line)
self._cur.defects.append(defect)
continue
# Split the line on the colon separating field name from value.
i = line.find(':')
if i < 0:
defect = errors.MalformedHeaderDefect(line)
self._cur.defects.append(defect)
continue
lastheader = line[:i]
lastvalue = [line[i+1:].lstrip()]
# Done with all the lines, so handle the last header.
if lastheader:
# XXX reconsider the joining of folded lines
self._cur[lastheader] = EMPTYSTRING.join(lastvalue).rstrip('\r\n')
|
mit
|
[
3,
1898,
334,
35,
9,
8353,
13,
7968,
2018,
2290,
2752,
199,
3,
6642,
26,
699,
1219,
351,
12,
644,
810,
878,
436,
644,
285,
2231,
87,
199,
3,
18684,
26,
3031,
13,
4093,
32,
1548,
14,
1308,
199,
199,
624,
7658,
2842,
446,
1626,
3031,
4733,
1798,
14,
199,
199,
1918,
4733,
1798,
9031,
376,
3217,
367,
11609,
1183,
6057,
376,
3031,
199,
1188,
12,
1004,
701,
1004,
14,
221,
961,
965,
19396,
867,
7441,
367,
9842,
13103,
12,
4066,
465,
199,
273,
3362,
7664,
3031,
3788,
2331,
282,
2838,
14,
199,
199,
7658,
2842,
14,
3871,
342,
365,
314,
5062,
3217,
367,
6675,
316,
892,
666,
1901,
314,
199,
2087,
14,
221,
2779,
2529,
1380,
2337,
1159,
6548,
1655,
652,
883,
886,
543,
314,
2808,
199,
576,
14,
221,
3979,
1265,
1172,
949,
1655,
666,
370,
6675,
1901,
314,
1798,
12,
1240,
1275,
1600,
1252,
199,
2765,
29672,
314,
6057,
436,
2529,
314,
1738,
1245,
909,
14,
199,
199,
1918,
1163,
30268,
402,
642,
1798,
365,
626,
652,
911,
7078,
7978,
282,
6057,
199,
1971,
14,
221,
15345,
12,
1380,
652,
17651,
6020,
10537,
12,
652,
9584,
282,
283,
25546,
7,
370,
199,
1589,
1453,
1245,
14,
221,
11391,
449,
83,
787,
2951,
4454,
626,
12166,
641,
314,
1245,
199,
785,
1159,
1275,
25546,
83,
2225,
14,
199,
624,
199,
199,
363,
452,
363,
275,
788,
7658,
2842,
418,
199,
199,
646,
295,
199,
199,
504,
3031,
492,
2552,
199,
504,
3031,
492,
1245,
199,
199,
14176,
5798,
275,
295,
14,
2014,
2258,
82,
60,
78,
6113,
82,
6113,
78,
358,
199,
14176,
5798,
63,
23484,
275,
295,
14,
2014,
360,
2961,
82,
60,
78,
6113,
82,
6113,
78,
5942,
199,
14176,
5798,
63,
20470,
275,
295,
14,
2014,
360,
2961,
82,
60,
78,
6113,
82,
6113,
78,
9,
9988,
199,
14176,
5798,
63,
67,
8085,
275,
295,
14,
2014,
360,
2961,
82,
60,
78,
6113,
82,
6113,
78,
5942,
199,
3,
7329,
7294,
1081,
2672,
19,
14,
22,
14,
24,
4879,
1504,
14,
221,
289,
505,
365,
450,
68,
1153,
13,
1641,
1182,
450,
68,
1427,
13,
7957,
12,
6184,
4528,
199,
3,
871,
13467,
12,
6988,
12,
436,
7244,
1674,
199,
1291,
907,
275,
295,
14,
2014,
8,
82,
31996,
2532,
1204,
7023,
10531,
2696,
25960,
60,
26010,
2696,
10216,
8194,
17,
12,
9160,
92,
7023,
84,
4794,
358,
199,
13993,
5353,
275,
2125,
199,
14176,
275,
1557,
78,
7,
199,
199,
17809,
11053,
1451,
275,
909,
342,
4388,
201,
199,
533,
26832,
2610,
1173,
8,
785,
304,
272,
408,
33,
570,
13,
2453,
909,
626,
883,
1172,
892,
666,
6511,
1901,
652,
14,
339,
2047,
883,
2597,
6675,
436,
4560,
1004,
13,
9467,
11944,
83,
14602,
282,
3464,
14,
221,
3979,
314,
272,
1453,
11944,
4450,
314,
1453,
1004,
12,
282,
3055,
9027,
1177,
272,
334,
73,
14,
69,
14,
2701,
1059,
9,
365,
2138,
3140,
14,
221,
961,
19083,
314,
1798,
1503,
1681,
370,
282,
272,
3486,
2236,
29639,
1553,
652,
19953,
5133,
9027,
27811,
314,
1453,
1245,
14,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
327,
710,
2061,
7417,
1004,
22319,
1901,
642,
909,
14,
267,
291,
423,
6672,
275,
2125,
267,
327,
710,
769,
402,
2615,
12,
22319,
2385,
12,
315,
3837,
1865,
267,
291,
423,
1278,
275,
942,
267,
327,
710,
3464,
402,
3055,
13,
13178,
7907,
11944,
83,
14,
267,
291,
423,
11670,
2340,
275,
942,
267,
327,
437,
3305,
9297,
3775,
314,
570,
965,
2757,
6876,
503,
440,
14,
267,
291,
423,
5938,
275,
756,
339,
347,
6675,
63,
11670,
63,
16135,
8,
277,
12,
8869,
304,
267,
291,
423,
11670,
2340,
14,
740,
8,
5991,
9,
339,
347,
4560,
63,
11670,
63,
16135,
8,
277,
304,
267,
372,
291,
423,
11670,
2340,
14,
1935,
342,
339,
347,
4002,
8,
277,
304,
267,
327,
7529,
1133,
19459,
1263,
8520,
7417,
1004,
14,
267,
291,
423,
1278,
14,
740,
8,
277,
423,
6672,
9,
267,
291,
423,
6672,
275,
2125,
267,
291,
423,
5938,
275,
715,
339,
347,
14441,
8,
277,
304,
267,
340,
440,
291,
423,
1278,
26,
288,
340,
291,
423,
5938,
26,
355,
372,
2125,
288,
372,
14012,
11053,
1451,
267,
327,
13244,
314,
1004,
2331,
314,
3464,
436,
1937,
340,
652,
4450,
314,
1453,
267,
327,
3055,
13,
13178,
11944,
14,
267,
1004,
275,
291,
423,
1278,
14,
1935,
342,
267,
327,
7329,
499,
13702,
12,
3420,
959,
14,
17,
14,
18,
5074,
2739,
370,
27159,
6890,
2166,
267,
327,
18135,
737,
1263,
2166,
402,
6506,
19500,
14,
221,
4226,
642,
12,
1325,
506,
3238,
652,
1159,
267,
327,
315,
314,
1865,
402,
4750,
370,
5210,
6032,
14,
267,
367,
282,
266,
1618,
315,
291,
423,
11670,
2340,
14172,
17,
2189,
288,
340,
282,
266,
1618,
8,
604,
304,
355,
327,
2136,
3984,
737,
314,
3055,
9027,
14,
221,
11017,
6675,
314,
2061,
1004,
1771,
1642,
14,
355,
291,
423,
1278,
14,
740,
8,
604,
9,
355,
372,
2125,
267,
372,
1004,
339,
347,
625,
6407,
8,
277,
12,
1004,
304,
267,
327,
12230,
314,
9790,
6675,
282,
1004,
1771,
1901,
314,
3335,
14,
267,
702,
1004,
365,
440,
14012,
11053,
1451,
267,
291,
423,
1278,
14,
740,
8,
604,
9,
339,
347,
6675,
8,
277,
12,
666,
304,
267,
408,
10731,
2005,
892,
666,
1901,
642,
909,
1041,
267,
327,
8690,
1263,
4136,
28844,
475,
14895,
267,
666,
12,
291,
423,
6672,
275,
291,
423,
6672,
435,
666,
12,
2125,
267,
327,
445,
8085,
1901,
2385,
12,
1325,
11211,
314,
14930,
641,
314,
1284,
402,
1924,
267,
4184,
275,
24719,
5798,
63,
67,
8085,
14,
1294,
8,
576,
9,
267,
327,
710,
627,
65,
27037,
10,
19604,
13942,
402,
295,
14,
1294,
1380,
6841,
17786,
267,
327,
23592,
365,
626,
314,
2061,
1819,
402,
314,
9183,
769,
365,
314,
267,
327,
666,
2410,
314,
4242,
5363,
14,
221,
1010,
314,
1930,
402,
282,
24719,
15,
2944,
15745,
1059,
12,
267,
327,
642,
365,
314,
2701,
1059,
14,
267,
291,
423,
6672,
275,
4184,
14,
1935,
342,
267,
327,
4184,
365,
282,
769,
402,
3326,
12,
8679,
1958,
3382,
314,
1004,
4072,
267,
327,
436,
314,
17645
] |
[
1898,
334,
35,
9,
8353,
13,
7968,
2018,
2290,
2752,
199,
3,
6642,
26,
699,
1219,
351,
12,
644,
810,
878,
436,
644,
285,
2231,
87,
199,
3,
18684,
26,
3031,
13,
4093,
32,
1548,
14,
1308,
199,
199,
624,
7658,
2842,
446,
1626,
3031,
4733,
1798,
14,
199,
199,
1918,
4733,
1798,
9031,
376,
3217,
367,
11609,
1183,
6057,
376,
3031,
199,
1188,
12,
1004,
701,
1004,
14,
221,
961,
965,
19396,
867,
7441,
367,
9842,
13103,
12,
4066,
465,
199,
273,
3362,
7664,
3031,
3788,
2331,
282,
2838,
14,
199,
199,
7658,
2842,
14,
3871,
342,
365,
314,
5062,
3217,
367,
6675,
316,
892,
666,
1901,
314,
199,
2087,
14,
221,
2779,
2529,
1380,
2337,
1159,
6548,
1655,
652,
883,
886,
543,
314,
2808,
199,
576,
14,
221,
3979,
1265,
1172,
949,
1655,
666,
370,
6675,
1901,
314,
1798,
12,
1240,
1275,
1600,
1252,
199,
2765,
29672,
314,
6057,
436,
2529,
314,
1738,
1245,
909,
14,
199,
199,
1918,
1163,
30268,
402,
642,
1798,
365,
626,
652,
911,
7078,
7978,
282,
6057,
199,
1971,
14,
221,
15345,
12,
1380,
652,
17651,
6020,
10537,
12,
652,
9584,
282,
283,
25546,
7,
370,
199,
1589,
1453,
1245,
14,
221,
11391,
449,
83,
787,
2951,
4454,
626,
12166,
641,
314,
1245,
199,
785,
1159,
1275,
25546,
83,
2225,
14,
199,
624,
199,
199,
363,
452,
363,
275,
788,
7658,
2842,
418,
199,
199,
646,
295,
199,
199,
504,
3031,
492,
2552,
199,
504,
3031,
492,
1245,
199,
199,
14176,
5798,
275,
295,
14,
2014,
2258,
82,
60,
78,
6113,
82,
6113,
78,
358,
199,
14176,
5798,
63,
23484,
275,
295,
14,
2014,
360,
2961,
82,
60,
78,
6113,
82,
6113,
78,
5942,
199,
14176,
5798,
63,
20470,
275,
295,
14,
2014,
360,
2961,
82,
60,
78,
6113,
82,
6113,
78,
9,
9988,
199,
14176,
5798,
63,
67,
8085,
275,
295,
14,
2014,
360,
2961,
82,
60,
78,
6113,
82,
6113,
78,
5942,
199,
3,
7329,
7294,
1081,
2672,
19,
14,
22,
14,
24,
4879,
1504,
14,
221,
289,
505,
365,
450,
68,
1153,
13,
1641,
1182,
450,
68,
1427,
13,
7957,
12,
6184,
4528,
199,
3,
871,
13467,
12,
6988,
12,
436,
7244,
1674,
199,
1291,
907,
275,
295,
14,
2014,
8,
82,
31996,
2532,
1204,
7023,
10531,
2696,
25960,
60,
26010,
2696,
10216,
8194,
17,
12,
9160,
92,
7023,
84,
4794,
358,
199,
13993,
5353,
275,
2125,
199,
14176,
275,
1557,
78,
7,
199,
199,
17809,
11053,
1451,
275,
909,
342,
4388,
201,
199,
533,
26832,
2610,
1173,
8,
785,
304,
272,
408,
33,
570,
13,
2453,
909,
626,
883,
1172,
892,
666,
6511,
1901,
652,
14,
339,
2047,
883,
2597,
6675,
436,
4560,
1004,
13,
9467,
11944,
83,
14602,
282,
3464,
14,
221,
3979,
314,
272,
1453,
11944,
4450,
314,
1453,
1004,
12,
282,
3055,
9027,
1177,
272,
334,
73,
14,
69,
14,
2701,
1059,
9,
365,
2138,
3140,
14,
221,
961,
19083,
314,
1798,
1503,
1681,
370,
282,
272,
3486,
2236,
29639,
1553,
652,
19953,
5133,
9027,
27811,
314,
1453,
1245,
14,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
327,
710,
2061,
7417,
1004,
22319,
1901,
642,
909,
14,
267,
291,
423,
6672,
275,
2125,
267,
327,
710,
769,
402,
2615,
12,
22319,
2385,
12,
315,
3837,
1865,
267,
291,
423,
1278,
275,
942,
267,
327,
710,
3464,
402,
3055,
13,
13178,
7907,
11944,
83,
14,
267,
291,
423,
11670,
2340,
275,
942,
267,
327,
437,
3305,
9297,
3775,
314,
570,
965,
2757,
6876,
503,
440,
14,
267,
291,
423,
5938,
275,
756,
339,
347,
6675,
63,
11670,
63,
16135,
8,
277,
12,
8869,
304,
267,
291,
423,
11670,
2340,
14,
740,
8,
5991,
9,
339,
347,
4560,
63,
11670,
63,
16135,
8,
277,
304,
267,
372,
291,
423,
11670,
2340,
14,
1935,
342,
339,
347,
4002,
8,
277,
304,
267,
327,
7529,
1133,
19459,
1263,
8520,
7417,
1004,
14,
267,
291,
423,
1278,
14,
740,
8,
277,
423,
6672,
9,
267,
291,
423,
6672,
275,
2125,
267,
291,
423,
5938,
275,
715,
339,
347,
14441,
8,
277,
304,
267,
340,
440,
291,
423,
1278,
26,
288,
340,
291,
423,
5938,
26,
355,
372,
2125,
288,
372,
14012,
11053,
1451,
267,
327,
13244,
314,
1004,
2331,
314,
3464,
436,
1937,
340,
652,
4450,
314,
1453,
267,
327,
3055,
13,
13178,
11944,
14,
267,
1004,
275,
291,
423,
1278,
14,
1935,
342,
267,
327,
7329,
499,
13702,
12,
3420,
959,
14,
17,
14,
18,
5074,
2739,
370,
27159,
6890,
2166,
267,
327,
18135,
737,
1263,
2166,
402,
6506,
19500,
14,
221,
4226,
642,
12,
1325,
506,
3238,
652,
1159,
267,
327,
315,
314,
1865,
402,
4750,
370,
5210,
6032,
14,
267,
367,
282,
266,
1618,
315,
291,
423,
11670,
2340,
14172,
17,
2189,
288,
340,
282,
266,
1618,
8,
604,
304,
355,
327,
2136,
3984,
737,
314,
3055,
9027,
14,
221,
11017,
6675,
314,
2061,
1004,
1771,
1642,
14,
355,
291,
423,
1278,
14,
740,
8,
604,
9,
355,
372,
2125,
267,
372,
1004,
339,
347,
625,
6407,
8,
277,
12,
1004,
304,
267,
327,
12230,
314,
9790,
6675,
282,
1004,
1771,
1901,
314,
3335,
14,
267,
702,
1004,
365,
440,
14012,
11053,
1451,
267,
291,
423,
1278,
14,
740,
8,
604,
9,
339,
347,
6675,
8,
277,
12,
666,
304,
267,
408,
10731,
2005,
892,
666,
1901,
642,
909,
1041,
267,
327,
8690,
1263,
4136,
28844,
475,
14895,
267,
666,
12,
291,
423,
6672,
275,
291,
423,
6672,
435,
666,
12,
2125,
267,
327,
445,
8085,
1901,
2385,
12,
1325,
11211,
314,
14930,
641,
314,
1284,
402,
1924,
267,
4184,
275,
24719,
5798,
63,
67,
8085,
14,
1294,
8,
576,
9,
267,
327,
710,
627,
65,
27037,
10,
19604,
13942,
402,
295,
14,
1294,
1380,
6841,
17786,
267,
327,
23592,
365,
626,
314,
2061,
1819,
402,
314,
9183,
769,
365,
314,
267,
327,
666,
2410,
314,
4242,
5363,
14,
221,
1010,
314,
1930,
402,
282,
24719,
15,
2944,
15745,
1059,
12,
267,
327,
642,
365,
314,
2701,
1059,
14,
267,
291,
423,
6672,
275,
4184,
14,
1935,
342,
267,
327,
4184,
365,
282,
769,
402,
3326,
12,
8679,
1958,
3382,
314,
1004,
4072,
267,
327,
436,
314,
17645,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
DazWorrall/ansible
|
lib/ansible/module_utils/facts/network/generic_bsd.py
|
55
|
11823
|
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import re
import socket
import struct
from ansible.module_utils.facts.network.base import Network
class GenericBsdIfconfigNetwork(Network):
"""
This is a generic BSD subclass of Network using the ifconfig command.
It defines
- interfaces (a list of interface names)
- interface_<name> dictionary of ipv4, ipv6, and mac address information.
- all_ipv4_addresses and all_ipv6_addresses: lists of all configured addresses.
"""
platform = 'Generic_BSD_Ifconfig'
def populate(self, collected_facts=None):
network_facts = {}
ifconfig_path = self.module.get_bin_path('ifconfig')
if ifconfig_path is None:
return network_facts
route_path = self.module.get_bin_path('route')
if route_path is None:
return network_facts
default_ipv4, default_ipv6 = self.get_default_interfaces(route_path)
interfaces, ips = self.get_interfaces_info(ifconfig_path)
interfaces = self.detect_type_media(interfaces)
self.merge_default_interface(default_ipv4, interfaces, 'ipv4')
self.merge_default_interface(default_ipv6, interfaces, 'ipv6')
network_facts['interfaces'] = sorted(list(interfaces.keys()))
for iface in interfaces:
network_facts[iface] = interfaces[iface]
network_facts['default_ipv4'] = default_ipv4
network_facts['default_ipv6'] = default_ipv6
network_facts['all_ipv4_addresses'] = ips['all_ipv4_addresses']
network_facts['all_ipv6_addresses'] = ips['all_ipv6_addresses']
return network_facts
def detect_type_media(self, interfaces):
for iface in interfaces:
if 'media' in interfaces[iface]:
if 'ether' in interfaces[iface]['media'].lower():
interfaces[iface]['type'] = 'ether'
return interfaces
def get_default_interfaces(self, route_path):
# Use the commands:
# route -n get 8.8.8.8 -> Google public DNS
# route -n get -inet6 2404:6800:400a:800::1012 -> ipv6.google.com
# to find out the default outgoing interface, address, and gateway
command = dict(v4=[route_path, '-n', 'get', '8.8.8.8'],
v6=[route_path, '-n', 'get', '-inet6', '2404:6800:400a:800::1012'])
interface = dict(v4={}, v6={})
for v in 'v4', 'v6':
if v == 'v6' and not socket.has_ipv6:
continue
rc, out, err = self.module.run_command(command[v])
if not out:
# v6 routing may result in
# RTNETLINK answers: Invalid argument
continue
for line in out.splitlines():
words = line.split()
# Collect output from route command
if len(words) > 1:
if words[0] == 'interface:':
interface[v]['interface'] = words[1]
if words[0] == 'gateway:':
interface[v]['gateway'] = words[1]
return interface['v4'], interface['v6']
def get_interfaces_info(self, ifconfig_path, ifconfig_options='-a'):
interfaces = {}
current_if = {}
ips = dict(
all_ipv4_addresses=[],
all_ipv6_addresses=[],
)
# FreeBSD, DragonflyBSD, NetBSD, OpenBSD and OS X all implicitly add '-a'
# when running the command 'ifconfig'.
# Solaris must explicitly run the command 'ifconfig -a'.
rc, out, err = self.module.run_command([ifconfig_path, ifconfig_options])
for line in out.splitlines():
if line:
words = line.split()
if words[0] == 'pass':
continue
elif re.match('^\S', line) and len(words) > 3:
current_if = self.parse_interface_line(words)
interfaces[current_if['device']] = current_if
elif words[0].startswith('options='):
self.parse_options_line(words, current_if, ips)
elif words[0] == 'nd6':
self.parse_nd6_line(words, current_if, ips)
elif words[0] == 'ether':
self.parse_ether_line(words, current_if, ips)
elif words[0] == 'media:':
self.parse_media_line(words, current_if, ips)
elif words[0] == 'status:':
self.parse_status_line(words, current_if, ips)
elif words[0] == 'lladdr':
self.parse_lladdr_line(words, current_if, ips)
elif words[0] == 'inet':
self.parse_inet_line(words, current_if, ips)
elif words[0] == 'inet6':
self.parse_inet6_line(words, current_if, ips)
elif words[0] == 'tunnel':
self.parse_tunnel_line(words, current_if, ips)
else:
self.parse_unknown_line(words, current_if, ips)
return interfaces, ips
def parse_interface_line(self, words):
device = words[0][0:-1]
current_if = {'device': device, 'ipv4': [], 'ipv6': [], 'type': 'unknown'}
current_if['flags'] = self.get_options(words[1])
if 'LOOPBACK' in current_if['flags']:
current_if['type'] = 'loopback'
current_if['macaddress'] = 'unknown' # will be overwritten later
if len(words) >= 5: # Newer FreeBSD versions
current_if['metric'] = words[3]
current_if['mtu'] = words[5]
else:
current_if['mtu'] = words[3]
return current_if
def parse_options_line(self, words, current_if, ips):
# Mac has options like this...
current_if['options'] = self.get_options(words[0])
def parse_nd6_line(self, words, current_if, ips):
# FreeBSD has options like this...
current_if['options'] = self.get_options(words[1])
def parse_ether_line(self, words, current_if, ips):
current_if['macaddress'] = words[1]
current_if['type'] = 'ether'
def parse_media_line(self, words, current_if, ips):
# not sure if this is useful - we also drop information
current_if['media'] = words[1]
if len(words) > 2:
current_if['media_select'] = words[2]
if len(words) > 3:
current_if['media_type'] = words[3][1:]
if len(words) > 4:
current_if['media_options'] = self.get_options(words[4])
def parse_status_line(self, words, current_if, ips):
current_if['status'] = words[1]
def parse_lladdr_line(self, words, current_if, ips):
current_if['lladdr'] = words[1]
def parse_inet_line(self, words, current_if, ips):
# netbsd show aliases like this
# lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33184
# inet 127.0.0.1 netmask 0xff000000
# inet alias 127.1.1.1 netmask 0xff000000
if words[1] == 'alias':
del words[1]
address = {'address': words[1]}
# cidr style ip address (eg, 127.0.0.1/24) in inet line
# used in netbsd ifconfig -e output after 7.1
if '/' in address['address']:
ip_address, cidr_mask = address['address'].split('/')
address['address'] = ip_address
netmask_length = int(cidr_mask)
netmask_bin = (1 << 32) - (1 << 32 >> int(netmask_length))
address['netmask'] = socket.inet_ntoa(struct.pack('!L', netmask_bin))
if len(words) > 5:
address['broadcast'] = words[3]
else:
# deal with hex netmask
if re.match('([0-9a-f]){8}', words[3]) and len(words[3]) == 8:
words[3] = '0x' + words[3]
if words[3].startswith('0x'):
address['netmask'] = socket.inet_ntoa(struct.pack('!L', int(words[3], base=16)))
else:
# otherwise assume this is a dotted quad
address['netmask'] = words[3]
# calculate the network
address_bin = struct.unpack('!L', socket.inet_aton(address['address']))[0]
netmask_bin = struct.unpack('!L', socket.inet_aton(address['netmask']))[0]
address['network'] = socket.inet_ntoa(struct.pack('!L', address_bin & netmask_bin))
if 'broadcast' not in address:
# broadcast may be given or we need to calculate
if len(words) > 5:
address['broadcast'] = words[5]
else:
address['broadcast'] = socket.inet_ntoa(struct.pack('!L', address_bin | (~netmask_bin & 0xffffffff)))
# add to our list of addresses
if not words[1].startswith('127.'):
ips['all_ipv4_addresses'].append(address['address'])
current_if['ipv4'].append(address)
def parse_inet6_line(self, words, current_if, ips):
address = {'address': words[1]}
# using cidr style addresses, ala NetBSD ifconfig post 7.1
if '/' in address['address']:
ip_address, cidr_mask = address['address'].split('/')
address['address'] = ip_address
address['prefix'] = cidr_mask
if len(words) > 5:
address['scope'] = words[5]
else:
if (len(words) >= 4) and (words[2] == 'prefixlen'):
address['prefix'] = words[3]
if (len(words) >= 6) and (words[4] == 'scopeid'):
address['scope'] = words[5]
localhost6 = ['::1', '::1/128', 'fe80::1%lo0']
if address['address'] not in localhost6:
ips['all_ipv6_addresses'].append(address['address'])
current_if['ipv6'].append(address)
def parse_tunnel_line(self, words, current_if, ips):
current_if['type'] = 'tunnel'
def parse_unknown_line(self, words, current_if, ips):
# we are going to ignore unknown lines here - this may be
# a bad idea - but you can override it in your subclass
pass
# TODO: these are module scope static function candidates
# (most of the class is really...)
def get_options(self, option_string):
start = option_string.find('<') + 1
end = option_string.rfind('>')
if (start > 0) and (end > 0) and (end > start + 1):
option_csv = option_string[start:end]
return option_csv.split(',')
else:
return []
def merge_default_interface(self, defaults, interfaces, ip_type):
if 'interface' not in defaults:
return
if not defaults['interface'] in interfaces:
return
ifinfo = interfaces[defaults['interface']]
# copy all the interface values across except addresses
for item in ifinfo:
if item != 'ipv4' and item != 'ipv6':
defaults[item] = ifinfo[item]
if len(ifinfo[ip_type]) > 0:
for item in ifinfo[ip_type][0]:
defaults[item] = ifinfo[ip_type][0][item]
|
gpl-3.0
|
[
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
295,
199,
646,
2838,
199,
646,
2702,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
1200,
14,
1095,
492,
7220,
421,
199,
533,
8307,
34,
3893,
3917,
888,
4491,
8,
4491,
304,
272,
408,
272,
961,
365,
282,
7809,
6289,
5516,
402,
7220,
1808,
314,
340,
888,
1414,
14,
272,
2779,
7890,
272,
446,
8386,
334,
65,
769,
402,
3217,
1561,
9,
272,
446,
3217,
27718,
354,
30,
2600,
402,
3278,
20,
12,
3278,
22,
12,
436,
4497,
2287,
2556,
14,
272,
446,
1006,
63,
4774,
20,
63,
7423,
436,
1006,
63,
4774,
22,
63,
7423,
26,
5548,
402,
1006,
7526,
7149,
14,
272,
408,
272,
4298,
275,
283,
9417,
63,
15400,
63,
3917,
888,
7,
339,
347,
13904,
8,
277,
12,
13736,
63,
5047,
29,
403,
304,
267,
2784,
63,
5047,
275,
1052,
267,
340,
888,
63,
515,
275,
291,
14,
578,
14,
362,
63,
1393,
63,
515,
360,
692,
888,
358,
398,
340,
340,
888,
63,
515,
365,
488,
26,
288,
372,
2784,
63,
5047,
398,
7475,
63,
515,
275,
291,
14,
578,
14,
362,
63,
1393,
63,
515,
360,
4449,
358,
398,
340,
7475,
63,
515,
365,
488,
26,
288,
372,
2784,
63,
5047,
398,
849,
63,
4774,
20,
12,
849,
63,
4774,
22,
275,
291,
14,
362,
63,
885,
63,
7436,
8,
4449,
63,
515,
9,
267,
8386,
12,
15017,
275,
291,
14,
362,
63,
7436,
63,
815,
8,
692,
888,
63,
515,
9,
267,
8386,
275,
291,
14,
13552,
63,
466,
63,
4603,
8,
7436,
9,
398,
291,
14,
5628,
63,
885,
63,
3266,
8,
885,
63,
4774,
20,
12,
8386,
12,
283,
4774,
20,
358,
267,
291,
14,
5628,
63,
885,
63,
3266,
8,
885,
63,
4774,
22,
12,
8386,
12,
283,
4774,
22,
358,
267,
2784,
63,
5047,
459,
7436,
418,
275,
3355,
8,
513,
8,
7436,
14,
1612,
4059,
398,
367,
13395,
315,
8386,
26,
288,
2784,
63,
5047,
59,
11166,
61,
275,
8386,
59,
11166,
61,
398,
2784,
63,
5047,
459,
885,
63,
4774,
20,
418,
275,
849,
63,
4774,
20,
267,
2784,
63,
5047,
459,
885,
63,
4774,
22,
418,
275,
849,
63,
4774,
22,
267,
2784,
63,
5047,
459,
452,
63,
4774,
20,
63,
7423,
418,
275,
15017,
459,
452,
63,
4774,
20,
63,
7423,
418,
267,
2784,
63,
5047,
459,
452,
63,
4774,
22,
63,
7423,
418,
275,
15017,
459,
452,
63,
4774,
22,
63,
7423,
418,
398,
372,
2784,
63,
5047,
339,
347,
9696,
63,
466,
63,
4603,
8,
277,
12,
8386,
304,
267,
367,
13395,
315,
8386,
26,
288,
340,
283,
4603,
7,
315,
8386,
59,
11166,
2189,
355,
340,
283,
27732,
7,
315,
8386,
59,
11166,
2733,
4603,
2278,
2325,
837,
490,
8386,
59,
11166,
2733,
466,
418,
275,
283,
27732,
7,
267,
372,
8386,
339,
347,
664,
63,
885,
63,
7436,
8,
277,
12,
7475,
63,
515,
304,
398,
327,
3645,
314,
3718,
26,
267,
327,
258,
7475,
446,
78,
664,
1695,
14,
24,
14,
24,
14,
24,
14960,
1035,
4475,
4575,
10237,
267,
327,
258,
7475,
446,
78,
664,
446,
10811,
22,
499,
5188,
26,
2333,
383,
26,
5303,
65,
26,
6718,
447,
4893,
18,
259,
1035,
3278,
22,
14,
3098,
14,
957,
267,
327,
370,
2342,
734,
314,
849,
21507,
3217,
12,
2287,
12,
436,
10391,
398,
1414,
275,
1211,
8,
86,
20,
1524,
4449,
63,
515,
12,
2475,
78,
297,
283,
362,
297,
283,
24,
14,
24,
14,
24,
14,
24,
995,
2432,
373,
22,
1524,
4449,
63,
515,
12,
2475,
78,
297,
283,
362,
297,
2475,
10811,
22,
297,
283,
1194,
966,
26,
2333,
383,
26,
5303,
65,
26,
6718,
447,
4893,
18,
1105,
398,
3217,
275,
1211,
8,
86,
20,
10324,
373,
22,
21146,
398,
367,
373,
315,
283,
86,
20,
297,
283,
86,
22,
356,
953,
340,
373,
508,
283,
86,
22,
7,
436,
440,
2838,
14,
1989,
63,
4774,
22,
26,
355,
1980,
288,
4819,
12,
734,
12,
2329,
275,
291,
14,
578,
14,
1065,
63,
1531,
8,
1531,
59,
86,
566,
288,
340,
440,
734,
26,
355,
327,
373,
22,
14870,
1443,
754,
315,
355,
327,
257,
24090,
7278,
7916,
17133,
26,
6378,
1423,
355,
1980,
288,
367,
1004,
315,
734,
14,
7644,
837,
355,
5932,
275,
1004,
14,
1294,
342,
355,
327,
19649,
1072,
687,
7475,
1414,
355,
340,
822,
8,
3148,
9,
690,
413,
26,
490,
340,
5932,
59,
16,
61,
508,
283,
3266,
25156,
717,
3217,
59,
86,
2733,
3266,
418,
275,
5932,
59,
17,
61,
490,
340,
5932,
59,
16,
61,
508,
283,
7019,
25156,
717,
3217,
59,
86,
2733,
7019,
418,
275,
5932,
59,
17,
61,
398,
372,
3217,
459,
86,
20,
995,
3217,
459,
86,
22,
418,
339,
347,
664,
63,
7436,
63,
815,
8,
277,
12,
340,
888,
63,
515,
12,
340,
888,
63,
1419,
18274,
65,
735,
267,
8386,
275,
1052,
267,
1453,
63,
692,
275,
1052,
267,
15017,
275,
1211,
8,
288,
1006,
63,
4774,
20,
63,
7423,
6034,
288,
1006,
63,
4774,
22,
63,
7423,
6034,
267,
776,
267,
327,
2868,
15400,
12,
577,
2527
] |
[
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
295,
199,
646,
2838,
199,
646,
2702,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
1200,
14,
1095,
492,
7220,
421,
199,
533,
8307,
34,
3893,
3917,
888,
4491,
8,
4491,
304,
272,
408,
272,
961,
365,
282,
7809,
6289,
5516,
402,
7220,
1808,
314,
340,
888,
1414,
14,
272,
2779,
7890,
272,
446,
8386,
334,
65,
769,
402,
3217,
1561,
9,
272,
446,
3217,
27718,
354,
30,
2600,
402,
3278,
20,
12,
3278,
22,
12,
436,
4497,
2287,
2556,
14,
272,
446,
1006,
63,
4774,
20,
63,
7423,
436,
1006,
63,
4774,
22,
63,
7423,
26,
5548,
402,
1006,
7526,
7149,
14,
272,
408,
272,
4298,
275,
283,
9417,
63,
15400,
63,
3917,
888,
7,
339,
347,
13904,
8,
277,
12,
13736,
63,
5047,
29,
403,
304,
267,
2784,
63,
5047,
275,
1052,
267,
340,
888,
63,
515,
275,
291,
14,
578,
14,
362,
63,
1393,
63,
515,
360,
692,
888,
358,
398,
340,
340,
888,
63,
515,
365,
488,
26,
288,
372,
2784,
63,
5047,
398,
7475,
63,
515,
275,
291,
14,
578,
14,
362,
63,
1393,
63,
515,
360,
4449,
358,
398,
340,
7475,
63,
515,
365,
488,
26,
288,
372,
2784,
63,
5047,
398,
849,
63,
4774,
20,
12,
849,
63,
4774,
22,
275,
291,
14,
362,
63,
885,
63,
7436,
8,
4449,
63,
515,
9,
267,
8386,
12,
15017,
275,
291,
14,
362,
63,
7436,
63,
815,
8,
692,
888,
63,
515,
9,
267,
8386,
275,
291,
14,
13552,
63,
466,
63,
4603,
8,
7436,
9,
398,
291,
14,
5628,
63,
885,
63,
3266,
8,
885,
63,
4774,
20,
12,
8386,
12,
283,
4774,
20,
358,
267,
291,
14,
5628,
63,
885,
63,
3266,
8,
885,
63,
4774,
22,
12,
8386,
12,
283,
4774,
22,
358,
267,
2784,
63,
5047,
459,
7436,
418,
275,
3355,
8,
513,
8,
7436,
14,
1612,
4059,
398,
367,
13395,
315,
8386,
26,
288,
2784,
63,
5047,
59,
11166,
61,
275,
8386,
59,
11166,
61,
398,
2784,
63,
5047,
459,
885,
63,
4774,
20,
418,
275,
849,
63,
4774,
20,
267,
2784,
63,
5047,
459,
885,
63,
4774,
22,
418,
275,
849,
63,
4774,
22,
267,
2784,
63,
5047,
459,
452,
63,
4774,
20,
63,
7423,
418,
275,
15017,
459,
452,
63,
4774,
20,
63,
7423,
418,
267,
2784,
63,
5047,
459,
452,
63,
4774,
22,
63,
7423,
418,
275,
15017,
459,
452,
63,
4774,
22,
63,
7423,
418,
398,
372,
2784,
63,
5047,
339,
347,
9696,
63,
466,
63,
4603,
8,
277,
12,
8386,
304,
267,
367,
13395,
315,
8386,
26,
288,
340,
283,
4603,
7,
315,
8386,
59,
11166,
2189,
355,
340,
283,
27732,
7,
315,
8386,
59,
11166,
2733,
4603,
2278,
2325,
837,
490,
8386,
59,
11166,
2733,
466,
418,
275,
283,
27732,
7,
267,
372,
8386,
339,
347,
664,
63,
885,
63,
7436,
8,
277,
12,
7475,
63,
515,
304,
398,
327,
3645,
314,
3718,
26,
267,
327,
258,
7475,
446,
78,
664,
1695,
14,
24,
14,
24,
14,
24,
14960,
1035,
4475,
4575,
10237,
267,
327,
258,
7475,
446,
78,
664,
446,
10811,
22,
499,
5188,
26,
2333,
383,
26,
5303,
65,
26,
6718,
447,
4893,
18,
259,
1035,
3278,
22,
14,
3098,
14,
957,
267,
327,
370,
2342,
734,
314,
849,
21507,
3217,
12,
2287,
12,
436,
10391,
398,
1414,
275,
1211,
8,
86,
20,
1524,
4449,
63,
515,
12,
2475,
78,
297,
283,
362,
297,
283,
24,
14,
24,
14,
24,
14,
24,
995,
2432,
373,
22,
1524,
4449,
63,
515,
12,
2475,
78,
297,
283,
362,
297,
2475,
10811,
22,
297,
283,
1194,
966,
26,
2333,
383,
26,
5303,
65,
26,
6718,
447,
4893,
18,
1105,
398,
3217,
275,
1211,
8,
86,
20,
10324,
373,
22,
21146,
398,
367,
373,
315,
283,
86,
20,
297,
283,
86,
22,
356,
953,
340,
373,
508,
283,
86,
22,
7,
436,
440,
2838,
14,
1989,
63,
4774,
22,
26,
355,
1980,
288,
4819,
12,
734,
12,
2329,
275,
291,
14,
578,
14,
1065,
63,
1531,
8,
1531,
59,
86,
566,
288,
340,
440,
734,
26,
355,
327,
373,
22,
14870,
1443,
754,
315,
355,
327,
257,
24090,
7278,
7916,
17133,
26,
6378,
1423,
355,
1980,
288,
367,
1004,
315,
734,
14,
7644,
837,
355,
5932,
275,
1004,
14,
1294,
342,
355,
327,
19649,
1072,
687,
7475,
1414,
355,
340,
822,
8,
3148,
9,
690,
413,
26,
490,
340,
5932,
59,
16,
61,
508,
283,
3266,
25156,
717,
3217,
59,
86,
2733,
3266,
418,
275,
5932,
59,
17,
61,
490,
340,
5932,
59,
16,
61,
508,
283,
7019,
25156,
717,
3217,
59,
86,
2733,
7019,
418,
275,
5932,
59,
17,
61,
398,
372,
3217,
459,
86,
20,
995,
3217,
459,
86,
22,
418,
339,
347,
664,
63,
7436,
63,
815,
8,
277,
12,
340,
888,
63,
515,
12,
340,
888,
63,
1419,
18274,
65,
735,
267,
8386,
275,
1052,
267,
1453,
63,
692,
275,
1052,
267,
15017,
275,
1211,
8,
288,
1006,
63,
4774,
20,
63,
7423,
6034,
288,
1006,
63,
4774,
22,
63,
7423,
6034,
267,
776,
267,
327,
2868,
15400,
12,
577,
2527,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
slyphon/pants
|
tests/python/pants_test/build_graph/test_build_file_parser.py
|
5
|
12566
|
# coding=utf-8
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)
import os
from collections import namedtuple
from textwrap import dedent
from pants.base.build_file import FilesystemBuildFile
from pants.build_graph.address import BuildFileAddress
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants.build_graph.build_file_parser import BuildFileParser
from pants.build_graph.target import Target
from pants_test.base_test import BaseTest
# TODO(Eric Ayers) Explicit unit tests are missing for registered_alises, parse_spec,
# parse_build_file_family
class ErrorTarget(Target):
def __init__(self, *args, **kwargs):
assert False, "This fake target should never be initialized in this test!"
class BuildFileParserBasicsTest(BaseTest):
def test_addressable_exceptions(self):
self.add_to_build_file('a/BUILD', 'target()')
build_file_a = FilesystemBuildFile(self.build_root, 'a/BUILD')
with self.assertRaises(BuildFileParser.ExecuteError):
self.build_file_parser.parse_build_file(build_file_a)
self.add_to_build_file('b/BUILD', 'target(name="foo", "bad_arg")')
build_file_b = FilesystemBuildFile(self.build_root, 'b/BUILD')
with self.assertRaises(BuildFileParser.BuildFileParserError):
self.build_file_parser.parse_build_file(build_file_b)
self.add_to_build_file('d/BUILD', dedent(
"""
target(
name="foo",
dependencies=[
object(),
]
)
"""
))
build_file_d = FilesystemBuildFile(self.build_root, 'd/BUILD')
with self.assertRaises(BuildFileParser.BuildFileParserError):
self.build_file_parser.parse_build_file(build_file_d)
def test_noop_parse(self):
self.add_to_build_file('BUILD', '')
build_file = FilesystemBuildFile(self.build_root, '')
address_map = set(self.build_file_parser.parse_build_file(build_file))
self.assertEqual(len(address_map), 0)
class BuildFileParserTargetTest(BaseTest):
@property
def alias_groups(self):
return BuildFileAliases(targets={'fake': ErrorTarget})
def test_trivial_target(self):
self.add_to_build_file('BUILD', 'fake(name="foozle")')
build_file = FilesystemBuildFile(self.build_root, 'BUILD')
address_map = self.build_file_parser.parse_build_file(build_file)
self.assertEqual(len(address_map), 1)
address, proxy = address_map.popitem()
self.assertEqual(address, BuildFileAddress(build_file, 'foozle'))
self.assertEqual(proxy.addressed_name, 'foozle')
self.assertEqual(proxy.addressed_type, ErrorTarget)
def test_sibling_build_files(self):
self.add_to_build_file('BUILD', dedent(
"""
fake(name="base",
dependencies=[
':foo',
])
"""))
self.add_to_build_file('BUILD.foo', dedent(
"""
fake(name="foo",
dependencies=[
':bat',
])
"""))
self.add_to_build_file('./BUILD.bar', dedent(
"""
fake(name="bat")
"""))
bar_build_file = FilesystemBuildFile(self.build_root, 'BUILD.bar')
base_build_file = FilesystemBuildFile(self.build_root, 'BUILD')
foo_build_file = FilesystemBuildFile(self.build_root, 'BUILD.foo')
address_map = self.build_file_parser.address_map_from_build_file(bar_build_file)
addresses = address_map.keys()
self.assertEqual({bar_build_file, base_build_file, foo_build_file},
set([address.build_file for address in addresses]))
self.assertEqual({':base', ':foo', ':bat'},
set([address.spec for address in addresses]))
def test_build_file_duplicates(self):
# This workspace has two targets in the same file with the same name.
self.add_to_build_file('BUILD', 'fake(name="foo")\n')
self.add_to_build_file('BUILD', 'fake(name="foo")\n')
with self.assertRaises(BuildFileParser.AddressableConflictException):
base_build_file = FilesystemBuildFile(self.build_root, 'BUILD')
self.build_file_parser.parse_build_file(base_build_file)
def test_sibling_build_files_duplicates(self):
# This workspace is malformed, you can't shadow a name in a sibling BUILD file
self.add_to_build_file('BUILD', dedent(
"""
fake(name="base",
dependencies=[
':foo',
])
"""))
self.add_to_build_file('BUILD.foo', dedent(
"""
fake(name="foo",
dependencies=[
':bat',
])
"""))
self.add_to_build_file('./BUILD.bar', dedent(
"""
fake(name="base")
"""))
with self.assertRaises(BuildFileParser.SiblingConflictException):
base_build_file = FilesystemBuildFile(self.build_root, 'BUILD')
self.build_file_parser.address_map_from_build_file(base_build_file)
class BuildFileParserExposedObjectTest(BaseTest):
@property
def alias_groups(self):
return BuildFileAliases(objects={'fake_object': object()})
def test_exposed_object(self):
self.add_to_build_file('BUILD', """fake_object""")
build_file = FilesystemBuildFile(self.build_root, 'BUILD')
address_map = self.build_file_parser.parse_build_file(build_file)
self.assertEqual(len(address_map), 0)
class BuildFileParserExposedContextAwareObjectFactoryTest(BaseTest):
Jar = namedtuple('Jar', ['org', 'name', 'rev'])
Repository = namedtuple('Repository', ['name', 'url', 'push_db_basedir'])
Artifact = namedtuple('Artifact', ['org', 'name', 'repo'])
class JarLibrary(Target):
def __init__(self, jars=None, **kwargs):
super(BuildFileParserExposedContextAwareObjectFactoryTest.JarLibrary, self).__init__(**kwargs)
self.jars = jars or []
class JvmLibrary(Target):
def __init__(self, provides=None, **kwargs):
super(BuildFileParserExposedContextAwareObjectFactoryTest.JvmLibrary, self).__init__(**kwargs)
self.provides = provides
class JavaLibrary(JvmLibrary):
pass
class ScalaLibrary(JvmLibrary):
pass
@classmethod
def make_lib(cls, parse_context):
def real_make_lib(org, name, rev):
dep = parse_context.create_object('jar', org=org, name=name, rev=rev)
parse_context.create_object('jar_library', name=name, jars=[dep])
return real_make_lib
@classmethod
def create_java_libraries(cls, parse_context):
def real_create_java_libraries(base_name,
org='com.twitter',
provides_java_name=None,
provides_scala_name=None):
def provides_artifact(provides_name):
if provides_name is None:
return None
jvm_repo = cls.Repository(
name='maven-central',
url='http://maven.example.com',
push_db_basedir=os.path.join('build-support', 'ivy', 'pushdb'),
)
return parse_context.create_object('artifact',
org=org,
name=provides_name,
repo=jvm_repo)
parse_context.create_object('java_library',
name='{}-java'.format(base_name),
provides=provides_artifact(provides_java_name))
parse_context.create_object('scala_library',
name='{}-scala'.format(base_name),
provides=provides_artifact(provides_scala_name))
return real_create_java_libraries
def setUp(self):
super(BuildFileParserExposedContextAwareObjectFactoryTest, self).setUp()
self._paths = set()
def path_relative_util(self, parse_context):
def real_path_relative_util(path):
self._paths.add(os.path.join(parse_context.rel_path, path))
return real_path_relative_util
@property
def alias_groups(self):
return BuildFileAliases(
targets={
'jar_library': self.JarLibrary,
'java_library': self.JavaLibrary,
'scala_library': self.ScalaLibrary,
},
context_aware_object_factories={
'make_lib': self.make_lib,
'create_java_libraries': self.create_java_libraries,
'path_util': self.path_relative_util,
},
objects={
'artifact': self.Artifact,
'jar': self.Jar,
}
)
def test_context_aware_object_factories(self):
contents = dedent("""
create_java_libraries(base_name="create-java-libraries",
provides_java_name="test-java",
provides_scala_name="test-scala")
make_lib("com.foo.test", "does_not_exists", "1.0")
path_util("baz")
""")
self.create_file('3rdparty/BUILD', contents)
build_file = FilesystemBuildFile(self.build_root, '3rdparty/BUILD')
address_map = self.build_file_parser.parse_build_file(build_file)
registered_proxies = set(address_map.values())
self.assertEqual(len(registered_proxies), 3)
targets_created = {}
for target_proxy in registered_proxies:
targets_created[target_proxy.addressed_name] = target_proxy.addressed_type
self.assertEqual({'does_not_exists',
'create-java-libraries-scala',
'create-java-libraries-java'},
set(targets_created.keys()))
self.assertEqual(targets_created['does_not_exists'], self.JarLibrary)
self.assertEqual(targets_created['create-java-libraries-java'], self.JavaLibrary)
self.assertEqual(targets_created['create-java-libraries-scala'], self.ScalaLibrary)
self.assertEqual({'3rdparty/baz'}, self._paths)
def test_raises_parse_error(self):
self.add_to_build_file('BUILD', 'foo(name = = "baz")')
build_file = FilesystemBuildFile(self.build_root, 'BUILD')
with self.assertRaises(BuildFileParser.ParseError):
self.build_file_parser.parse_build_file(build_file)
# Test some corner cases for the context printing
# Error at beginning of BUILD file
build_file = self.add_to_build_file('begin/BUILD', dedent("""
*?&INVALID! = 'foo'
target(
name='bar',
dependencies= [
':baz',
],
)
"""))
with self.assertRaises(BuildFileParser.ParseError):
self.build_file_parser.parse_build_file(build_file)
# Error at end of BUILD file
build_file = self.add_to_build_file('end/BUILD', dedent("""
target(
name='bar',
dependencies= [
':baz',
],
)
*?&INVALID! = 'foo'
"""))
with self.assertRaises(BuildFileParser.ParseError):
self.build_file_parser.parse_build_file(build_file)
# Error in the middle of BUILD file > 6 lines
build_file = self.add_to_build_file('middle/BUILD', dedent("""
target(
name='bar',
*?&INVALID! = 'foo'
dependencies = [
':baz',
],
)
"""))
with self.assertRaises(BuildFileParser.ParseError):
self.build_file_parser.parse_build_file(build_file)
# Error in very short build file.
build_file = self.add_to_build_file('short/BUILD', dedent("""
target(name='bar', dependencies = [':baz'],) *?&INVALID! = 'foo'
"""))
with self.assertRaises(BuildFileParser.ParseError):
self.build_file_parser.parse_build_file(build_file)
def test_raises_execute_error(self):
self.add_to_build_file('BUILD', 'undefined_alias(name="baz")')
build_file = FilesystemBuildFile(self.build_root, 'BUILD')
with self.assertRaises(BuildFileParser.ExecuteError):
self.build_file_parser.parse_build_file(build_file)
def test_build_file_parser_error_hierarcy(self):
"""Exception handling code depends on the fact that all explicit exceptions from BuildFileParser
are subclassed from the BuildFileParserError base class.
"""
def assert_build_file_parser_error(e):
self.assertIsInstance(e, BuildFileParser.BuildFileParserError)
assert_build_file_parser_error(BuildFileParser.BuildFileScanError())
assert_build_file_parser_error(BuildFileParser.AddressableConflictException())
assert_build_file_parser_error(BuildFileParser.SiblingConflictException())
assert_build_file_parser_error(BuildFileParser.ParseError())
assert_build_file_parser_error(BuildFileParser.ExecuteError())
|
apache-2.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
1898,
6927,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
16952,
12,
6032,
63,
14129,
12,
870,
63,
1593,
12,
717,
2649,
63,
5955,
12,
543,
63,
6242,
9,
199,
199,
646,
747,
199,
504,
5055,
492,
12863,
199,
504,
13390,
492,
22622,
199,
199,
504,
18081,
14,
1095,
14,
1506,
63,
493,
492,
3814,
2253,
16052,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1562,
492,
6516,
1173,
1476,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1506,
63,
493,
63,
8602,
492,
6516,
1173,
6985,
3274,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1506,
63,
493,
63,
2087,
492,
6516,
1173,
2842,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1375,
492,
10256,
199,
504,
18081,
63,
396,
14,
1095,
63,
396,
492,
3523,
774,
421,
199,
3,
3254,
8,
37,
1567,
437,
89,
1192,
9,
23872,
4137,
2295,
787,
4124,
367,
7264,
63,
279,
1388,
12,
2198,
63,
1650,
12,
199,
3,
2198,
63,
1506,
63,
493,
63,
6606,
199,
533,
4520,
4277,
8,
4277,
304,
819,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
702,
756,
12,
298,
2765,
4026,
1347,
1077,
7078,
506,
10038,
315,
642,
511,
9539,
421,
199,
533,
6516,
1173,
2842,
6845,
26935,
8,
23170,
304,
819,
347,
511,
63,
1562,
461,
63,
3924,
8,
277,
304,
272,
291,
14,
525,
63,
475,
63,
1506,
63,
493,
360,
65,
15,
8248,
297,
283,
1375,
19004,
272,
1900,
63,
493,
63,
65,
275,
3814,
2253,
16052,
8,
277,
14,
1506,
63,
1231,
12,
283,
65,
15,
8248,
358,
339,
543,
291,
14,
1855,
8,
16052,
2842,
14,
12049,
547,
304,
489,
291,
14,
1506,
63,
493,
63,
2087,
14,
1122,
63,
1506,
63,
493,
8,
1506,
63,
493,
63,
65,
9,
339,
291,
14,
525,
63,
475,
63,
1506,
63,
493,
360,
66,
15,
8248,
297,
283,
1375,
8,
354,
628,
1421,
401,
298,
4087,
63,
1273,
531,
358,
272,
1900,
63,
493,
63,
66,
275,
3814,
2253,
16052,
8,
277,
14,
1506,
63,
1231,
12,
283,
66,
15,
8248,
358,
272,
543,
291,
14,
1855,
8,
16052,
2842,
14,
16052,
21811,
304,
489,
291,
14,
1506,
63,
493,
63,
2087,
14,
1122,
63,
1506,
63,
493,
8,
1506,
63,
493,
63,
66,
9,
339,
291,
14,
525,
63,
475,
63,
1506,
63,
493,
360,
68,
15,
8248,
297,
22622,
8,
489,
408,
489,
1347,
8,
267,
536,
628,
1421,
401,
267,
5124,
1524,
881,
909,
1062,
267,
1622,
489,
776,
489,
408,
272,
5082,
272,
1900,
63,
493,
63,
68,
275,
3814,
2253,
16052,
8,
277,
14,
1506,
63,
1231,
12,
283,
68,
15,
8248,
358,
272,
543,
291,
14,
1855,
8,
16052,
2842,
14,
16052,
21811,
304,
489,
291,
14,
1506,
63,
493,
63,
2087,
14,
1122,
63,
1506,
63,
493,
8,
1506,
63,
493,
63,
68,
9,
819,
347,
511,
63,
12921,
63,
1122,
8,
277,
304,
272,
291,
14,
525,
63,
475,
63,
1506,
63,
493,
360,
8248,
297,
4074,
272,
1900,
63,
493,
275,
3814,
2253,
16052,
8,
277,
14,
1506,
63,
1231,
12,
4074,
272,
2287,
63,
1130,
275,
663,
8,
277,
14,
1506,
63,
493,
63,
2087,
14,
1122,
63,
1506,
63,
493,
8,
1506,
63,
493,
430,
272,
291,
14,
629,
8,
552,
8,
1562,
63,
1130,
395,
378,
9,
421,
199,
533,
6516,
1173,
2842,
4277,
774,
8,
23170,
304,
819,
768,
1829,
523,
347,
5162,
63,
2634,
8,
277,
304,
272,
372,
6516,
1173,
6985,
3274,
8,
4684,
3713,
3183,
356,
4520,
4277,
1552,
819,
347,
511,
63,
23844,
63,
1375,
8,
277,
304,
272,
291,
14,
525,
63,
475,
63,
1506,
63,
493,
360,
8248,
297,
283,
3183,
8,
354,
628,
1421,
90,
274,
531,
358,
272,
1900,
63,
493,
275,
3814,
2253,
16052,
8,
277,
14,
1506,
63,
1231,
12,
283,
8248,
358,
272,
2287,
63,
1130,
275,
291,
14,
1506,
63,
493,
63,
2087,
14,
1122,
63,
1506,
63,
493,
8,
1506,
63,
493,
9,
339,
291,
14,
629,
8,
552,
8,
1562,
63,
1130,
395,
413,
9,
272,
2287,
12,
4566,
275,
2287,
63,
1130,
14,
24882,
342,
272,
291,
14,
629,
8,
1562,
12,
6516,
1173,
1476,
8,
1506,
63,
493,
12,
283,
1421,
90,
274,
1333,
272,
291,
14,
629,
8,
3280,
14,
525,
5111,
63,
354,
12,
283,
1421,
90,
274,
358,
272,
291,
14,
629,
8,
3280,
14,
525,
5111,
63,
466,
12,
4520,
4277,
9,
819,
347,
511,
63,
17285,
63,
1506,
63,
1725,
8,
277,
304,
272,
291,
14,
525,
63,
475,
63,
1506,
63,
493,
360,
8248,
297,
22622,
8,
489,
408,
489,
4026,
8,
354,
628,
1095,
401,
1779,
5124,
1524,
1467,
7596,
1421,
297,
1779,
4794,
489,
24072,
339,
291,
14,
525,
63,
475,
63,
1506,
63,
493,
360,
8248,
14,
1421,
297,
22622,
8,
489,
408,
489,
4026,
8,
354,
628,
1421,
401,
1779,
5124,
1524,
1467,
7596,
13475,
297,
1779,
4794,
489,
24072,
339,
291,
14,
525,
63,
475,
63,
1506,
63,
493,
17371,
8248,
14,
1700,
297,
22622,
8,
489,
408,
489,
4026,
8,
354,
628,
13475,
531,
489,
24072,
339,
4681,
63,
1506,
63,
493,
275,
3814,
2253,
16052,
8,
277,
14,
1506,
63,
1231,
12,
283,
8248,
14,
1700,
358,
272,
1300,
63,
1506,
63,
493,
275,
3814,
2253,
16052,
8,
277,
14,
1506,
63,
1231,
12,
283,
8248,
358,
272,
3925,
63,
1506,
63,
493,
275,
3814,
2253,
16052,
8,
277,
14,
1506,
63,
1231,
12,
283,
8248,
14,
1421,
358,
339,
2287,
63,
1130,
275,
291,
14,
1506,
63,
493,
63,
2087,
14,
1562,
63,
1130,
63,
504,
63,
1506,
63,
493,
8,
1700,
63,
1506,
63,
493,
9,
272,
7149,
275,
2287,
63,
1130,
14,
1612,
342,
272,
291,
14,
629,
2561,
1700,
63,
1506,
63,
493,
12,
1300,
63,
1506,
63,
493,
12,
3925,
63,
1506,
63,
493,
1386,
2151,
663,
779,
1562,
14,
1506,
63,
493,
367,
2287
] |
[
2803,
29,
1624,
13,
24,
199,
3,
1898,
6927,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
16952,
12,
6032,
63,
14129,
12,
870,
63,
1593,
12,
717,
2649,
63,
5955,
12,
543,
63,
6242,
9,
199,
199,
646,
747,
199,
504,
5055,
492,
12863,
199,
504,
13390,
492,
22622,
199,
199,
504,
18081,
14,
1095,
14,
1506,
63,
493,
492,
3814,
2253,
16052,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1562,
492,
6516,
1173,
1476,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1506,
63,
493,
63,
8602,
492,
6516,
1173,
6985,
3274,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1506,
63,
493,
63,
2087,
492,
6516,
1173,
2842,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1375,
492,
10256,
199,
504,
18081,
63,
396,
14,
1095,
63,
396,
492,
3523,
774,
421,
199,
3,
3254,
8,
37,
1567,
437,
89,
1192,
9,
23872,
4137,
2295,
787,
4124,
367,
7264,
63,
279,
1388,
12,
2198,
63,
1650,
12,
199,
3,
2198,
63,
1506,
63,
493,
63,
6606,
199,
533,
4520,
4277,
8,
4277,
304,
819,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
702,
756,
12,
298,
2765,
4026,
1347,
1077,
7078,
506,
10038,
315,
642,
511,
9539,
421,
199,
533,
6516,
1173,
2842,
6845,
26935,
8,
23170,
304,
819,
347,
511,
63,
1562,
461,
63,
3924,
8,
277,
304,
272,
291,
14,
525,
63,
475,
63,
1506,
63,
493,
360,
65,
15,
8248,
297,
283,
1375,
19004,
272,
1900,
63,
493,
63,
65,
275,
3814,
2253,
16052,
8,
277,
14,
1506,
63,
1231,
12,
283,
65,
15,
8248,
358,
339,
543,
291,
14,
1855,
8,
16052,
2842,
14,
12049,
547,
304,
489,
291,
14,
1506,
63,
493,
63,
2087,
14,
1122,
63,
1506,
63,
493,
8,
1506,
63,
493,
63,
65,
9,
339,
291,
14,
525,
63,
475,
63,
1506,
63,
493,
360,
66,
15,
8248,
297,
283,
1375,
8,
354,
628,
1421,
401,
298,
4087,
63,
1273,
531,
358,
272,
1900,
63,
493,
63,
66,
275,
3814,
2253,
16052,
8,
277,
14,
1506,
63,
1231,
12,
283,
66,
15,
8248,
358,
272,
543,
291,
14,
1855,
8,
16052,
2842,
14,
16052,
21811,
304,
489,
291,
14,
1506,
63,
493,
63,
2087,
14,
1122,
63,
1506,
63,
493,
8,
1506,
63,
493,
63,
66,
9,
339,
291,
14,
525,
63,
475,
63,
1506,
63,
493,
360,
68,
15,
8248,
297,
22622,
8,
489,
408,
489,
1347,
8,
267,
536,
628,
1421,
401,
267,
5124,
1524,
881,
909,
1062,
267,
1622,
489,
776,
489,
408,
272,
5082,
272,
1900,
63,
493,
63,
68,
275,
3814,
2253,
16052,
8,
277,
14,
1506,
63,
1231,
12,
283,
68,
15,
8248,
358,
272,
543,
291,
14,
1855,
8,
16052,
2842,
14,
16052,
21811,
304,
489,
291,
14,
1506,
63,
493,
63,
2087,
14,
1122,
63,
1506,
63,
493,
8,
1506,
63,
493,
63,
68,
9,
819,
347,
511,
63,
12921,
63,
1122,
8,
277,
304,
272,
291,
14,
525,
63,
475,
63,
1506,
63,
493,
360,
8248,
297,
4074,
272,
1900,
63,
493,
275,
3814,
2253,
16052,
8,
277,
14,
1506,
63,
1231,
12,
4074,
272,
2287,
63,
1130,
275,
663,
8,
277,
14,
1506,
63,
493,
63,
2087,
14,
1122,
63,
1506,
63,
493,
8,
1506,
63,
493,
430,
272,
291,
14,
629,
8,
552,
8,
1562,
63,
1130,
395,
378,
9,
421,
199,
533,
6516,
1173,
2842,
4277,
774,
8,
23170,
304,
819,
768,
1829,
523,
347,
5162,
63,
2634,
8,
277,
304,
272,
372,
6516,
1173,
6985,
3274,
8,
4684,
3713,
3183,
356,
4520,
4277,
1552,
819,
347,
511,
63,
23844,
63,
1375,
8,
277,
304,
272,
291,
14,
525,
63,
475,
63,
1506,
63,
493,
360,
8248,
297,
283,
3183,
8,
354,
628,
1421,
90,
274,
531,
358,
272,
1900,
63,
493,
275,
3814,
2253,
16052,
8,
277,
14,
1506,
63,
1231,
12,
283,
8248,
358,
272,
2287,
63,
1130,
275,
291,
14,
1506,
63,
493,
63,
2087,
14,
1122,
63,
1506,
63,
493,
8,
1506,
63,
493,
9,
339,
291,
14,
629,
8,
552,
8,
1562,
63,
1130,
395,
413,
9,
272,
2287,
12,
4566,
275,
2287,
63,
1130,
14,
24882,
342,
272,
291,
14,
629,
8,
1562,
12,
6516,
1173,
1476,
8,
1506,
63,
493,
12,
283,
1421,
90,
274,
1333,
272,
291,
14,
629,
8,
3280,
14,
525,
5111,
63,
354,
12,
283,
1421,
90,
274,
358,
272,
291,
14,
629,
8,
3280,
14,
525,
5111,
63,
466,
12,
4520,
4277,
9,
819,
347,
511,
63,
17285,
63,
1506,
63,
1725,
8,
277,
304,
272,
291,
14,
525,
63,
475,
63,
1506,
63,
493,
360,
8248,
297,
22622,
8,
489,
408,
489,
4026,
8,
354,
628,
1095,
401,
1779,
5124,
1524,
1467,
7596,
1421,
297,
1779,
4794,
489,
24072,
339,
291,
14,
525,
63,
475,
63,
1506,
63,
493,
360,
8248,
14,
1421,
297,
22622,
8,
489,
408,
489,
4026,
8,
354,
628,
1421,
401,
1779,
5124,
1524,
1467,
7596,
13475,
297,
1779,
4794,
489,
24072,
339,
291,
14,
525,
63,
475,
63,
1506,
63,
493,
17371,
8248,
14,
1700,
297,
22622,
8,
489,
408,
489,
4026,
8,
354,
628,
13475,
531,
489,
24072,
339,
4681,
63,
1506,
63,
493,
275,
3814,
2253,
16052,
8,
277,
14,
1506,
63,
1231,
12,
283,
8248,
14,
1700,
358,
272,
1300,
63,
1506,
63,
493,
275,
3814,
2253,
16052,
8,
277,
14,
1506,
63,
1231,
12,
283,
8248,
358,
272,
3925,
63,
1506,
63,
493,
275,
3814,
2253,
16052,
8,
277,
14,
1506,
63,
1231,
12,
283,
8248,
14,
1421,
358,
339,
2287,
63,
1130,
275,
291,
14,
1506,
63,
493,
63,
2087,
14,
1562,
63,
1130,
63,
504,
63,
1506,
63,
493,
8,
1700,
63,
1506,
63,
493,
9,
272,
7149,
275,
2287,
63,
1130,
14,
1612,
342,
272,
291,
14,
629,
2561,
1700,
63,
1506,
63,
493,
12,
1300,
63,
1506,
63,
493,
12,
3925,
63,
1506,
63,
493,
1386,
2151,
663,
779,
1562,
14,
1506,
63,
493,
367,
2287,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
shotgunsoftware/pyqt-uploader
|
uploader.py
|
1
|
58592
|
#!/usr/bin/env python
"""
A PyQt interface for uploading files to Shotgun.
Allows you to configure that app for a specific shotgun instance and directory structure.
Uploaded files need to be linked to an existing entity, but can have notes and tags applied.
Author: Rob Blau <rblau@laika.com>
"""
################################################################################
# DEFAULT PREFS: Change these if you want people to use the script without config changes
################################################################################
DEFAULT_SHOTGUN_API = "/net/a/place/where/we/put/the/shotgun_api3.py"
DEFAULT_SHOTGUN_URL = "http://shotgun.kickass-studios.com/"
DEFAULT_SHOTGUN_SCRIPT = "thumb_uploader"
DEFAULT_SHOTGUN_KEY = "ALONGSTRINGOFNUMBERSANDLETTERSFROMSHOTGUN"
DEFAULT_IMAGE_COMMAND = "convert $in $out"
DEFAULT_MOVIE_COMMAND = "ffmpeg -y -i $in -f mjpeg -ss $offset -vframes 1 -s svga -an $out"
DEFAULT_TAGS = "to_be_filed"
DEFAULT_PATH_FIELD = "sg_path_to_file"
DEFAULT_LINK_MAP = """\
Asset: /job_root/*/assets/$type/${name}
Task: /job_root/*/shots/$entity.Shot.name/${name}
"""
################################################################################
# THE ACTUAL CODE: You shouldn't need to go beyond this point for configuration
################################################################################
import re
import os
import sys
import urllib
import socket
import getpass
import tempfile
import mimetypes
from PyQt4 import QtGui
from PyQt4 import QtCore
try:
from main_window import Ui_MainWindow
from prefs_dialog import Ui_Preferences
except:
# to work when catt'ed together for standalone emailing
pass
################################################################################
# Globals
################################################################################
DEFAULT_COL_WIDTHS = "44,406,64,274,274"
################################################################################
# Model
################################################################################
class ShotgunFileModel(QtCore.QAbstractTableModel):
# Mapping from display text to an attribute of the modeled object
__HEADERS = [
{'disp': 'Frame', 'attr': 'hero_offset', 'default': '', 'editable': True},
{'disp': 'Path', 'attr': 'path', 'default': '', 'editable': False},
{'disp': 'Linked To', 'attr': 'link_name', 'default': '', 'editable': False},
{'disp': 'Tags', 'attr': 'tags', 'default': '', 'editable': True},
{'disp': 'Note', 'attr': 'note', 'default': '', 'editable': True},
]
# model methods
def __init__(self, undo_stack, parent=None):
"""constructor"""
super(ShotgunFileModel, self).__init__(parent)
self.stack = undo_stack
self.files = []
def rowCount(self, parent=QtCore.QModelIndex()):
"""number of rows is the number of files"""
return len(self.files)
def columnCount(self, parent=QtCore.QModelIndex()):
"""number of columns is the number of headers"""
return len(self.__HEADERS)
def data(self, index, role=QtCore.Qt.DisplayRole):
"""method to return data for the various display roles in qt"""
# display role, actually return the info
if index.isValid() and role == QtCore.Qt.DisplayRole:
f = self.files[index.row()]
attr = self.__HEADERS[index.column()]['attr']
ret = getattr(f, attr, None)
if ret is not None:
return QtCore.QVariant(ret)
else:
return QtCore.QVariant(self.__HEADERS[index.column()]['default'])
# not worrying about this role, just return invalid variant
return QtCore.QVariant()
def headerData(self, section, orientation, role):
"""return data for header row"""
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
return QtCore.QVariant(self.__HEADERS[section]['disp'])
return QtCore.QVariant()
def setData(self, index, value, role):
"""set data for a given index"""
if (role != QtCore.Qt.EditRole):
return False
self.stack.push(ChangeValueCommand(index, value, self))
return True
# drag and drop methods
def supportedDropActions(self):
"""what drop actions do we support, treat move or copy as an insert"""
return QtCore.Qt.MoveAction | QtCore.Qt.CopyAction
def flags(self, index):
"""all items can accept drops, hero_offset is editable for video, otherwise use editable"""
flags = QtCore.Qt.ItemIsDropEnabled | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
if self.__HEADERS[index.column()]['attr'] == 'hero_offset':
f = self.files[index.row()]
mime_guess = mimetypes.guess_type(f.path)[0]
if mime_guess is not None and mime_guess.startswith('video'):
flags |= QtCore.Qt.ItemIsEditable
elif self.__HEADERS[index.column()]['editable']:
flags |= QtCore.Qt.ItemIsEditable
return flags
def mimeTypes(self):
"""return a list of supported mime types. enables drop"""
# text/uri-list is what most finder style file browsers use
return QtCore.QStringList(['text/uri-list'])
def dropMimeData(self, data, action, row, column, parent):
"""handle the drop action, currently just uri-list"""
if data.hasFormat('text/uri-list'):
if data.hasUrls():
files = [str(url.toLocalFile()) for url in data.urls()]
elif data.hasText():
files = [str(urllib.urlretrieve(uri)[0])
for uri in str(data.text()).split()
if urllib.splittype(uri)[0] == 'file']
# Just let people know what's been added
self.emit(QtCore.SIGNAL('filesAdded(QStringList)'), files)
return True
return False
# model object access
def _update_data(self, row, column, value):
"""update internal data at (row, column) to value"""
f = self.files[row]
setattr(f, self.__HEADERS[column]['attr'], str(value))
self.emit(QtCore.SIGNAL('modelReset()'))
def clear(self):
self.files = []
self.reset()
self.emit(QtCore.SIGNAL('modelReset()'))
def insert_files(self, files, row):
self.beginInsertRows(QtCore.QModelIndex(), row, row+len(files)-1)
self.files[row:row] = files
self.endInsertRows()
def append_files(self, files):
self.insert_files(files, len(self.files))
def delete_files(self, first, last):
self.beginRemoveRows(QtCore.QModelIndex(), first, last)
self.files[first:last] = []
self.endRemoveRows()
self.emit(QtCore.SIGNAL('modelReset()'))
################################################################################
# File Object
################################################################################
class ShotgunFile(object):
"""wrapper around info needed to upload a file"""
def __init__(self, path, tags, link, hero_offset=None, note=''):
self.path = path
self.tags = tags
self.hero_offset = ''
self.link = link
self.note = note
self.link_name = link.get('name', link.get('code', ''))
if hero_offset is None:
# default offset to 1 for video mime-types
mime_guess = mimetypes.guess_type(path)[0]
if mime_guess is not None and mime_guess.startswith('video'):
self.hero_offset = '1'
self.size = os.path.getsize(path)
################################################################################
# Commands
################################################################################
class ChangeValueCommand(QtGui.QUndoCommand):
def __init__(self, index, value, model, text='value change', parent=None):
QtGui.QUndoCommand.__init__(self, text, parent)
self.__old = index.data(QtCore.Qt.DisplayRole).toString()
self.__new = value.toString()
self.__row = index.row()
self.__col = index.column()
self.__model = model
def redo(self):
self.__model._update_data(self.__row, self.__col, self.__new)
def undo(self):
self.__model._update_data(self.__row, self.__col, self.__old)
################################################################################
class NewFileCommand(QtGui.QUndoCommand):
def __init__(self, model, files, text='new files', parent=None):
QtGui.QUndoCommand.__init__(self, text, parent)
self.model = model
self.files = files
def redo(self):
self.first = self.model.rowCount()
self.model.append_files(self.files)
self.last = self.model.rowCount()
def undo(self):
self.model.delete_files(self.first, self.last)
################################################################################
class DeleteFilesCommand(QtGui.QUndoCommand):
def __init__(self, model, rows, text='delete files', parent=None):
QtGui.QUndoCommand.__init__(self, text, parent)
self.model = model
self.files = dict([(row, model.files[row]) for row in rows])
def redo(self):
# make sure we do this in reverse order so rows stay accurate while
# deleting
for row in reversed(sorted(self.files.keys())):
self.model.delete_files(row, row+1)
def undo(self):
# make sure we do this in row order to keep things as they were
for row in sorted(self.files.keys()):
self.model.insert_files([self.files[row]], row)
################################################################################
# Prefereneces
################################################################################
class PrefsDialog(QtGui.QDialog):
def __init__(self):
QtGui.QDialog.__init__(self)
# setup gui
self.gui = Ui_Preferences()
self.gui.setupUi(self)
# restore state
settings = QtCore.QSettings('ShotgunSharing', 'uploader')
self.gui.image_command.setText(settings.value("prefs/image_command", DEFAULT_IMAGE_COMMAND).toString())
self.gui.movie_command.setText(settings.value("prefs/movie_command", DEFAULT_MOVIE_COMMAND).toString())
self.gui.shotgun_url.setText(settings.value("prefs/shotgun_url", DEFAULT_SHOTGUN_URL).toString())
self.gui.shotgun_script.setText(settings.value("prefs/shotgun_script", DEFAULT_SHOTGUN_SCRIPT).toString())
self.gui.shotgun_key.setText(settings.value("prefs/shotgun_key", DEFAULT_SHOTGUN_KEY).toString())
self.gui.shotgun_api.setText(settings.value("prefs/shotgun_api", DEFAULT_SHOTGUN_API).toString())
self.gui.path_field.setText(settings.value("prefs/path_field", DEFAULT_PATH_FIELD).toString())
self.gui.link_map.setText(settings.value("prefs/link_map", DEFAULT_LINK_MAP).toString())
self.restoreGeometry(settings.value("prefs/geometry").toByteArray())
# hook up buttons
self.connect(self.gui.buttons, QtCore.SIGNAL('accepted()'), self.ok)
self.connect(self.gui.buttons, QtCore.SIGNAL('rejected()'), self.cancel)
self.__sync_with_fields()
def __sync_with_fields(self):
# outside classes should use these to access current settings
self.image_command = str(self.gui.image_command.text())
self.movie_command = str(self.gui.movie_command.text())
self.shotgun_url = str(self.gui.shotgun_url.text())
self.shotgun_script = str(self.gui.shotgun_script.text())
self.shotgun_key = str(self.gui.shotgun_key.text())
self.shotgun_api = str(self.gui.shotgun_api.text())
self.path_field = str(self.gui.path_field.text())
self.link_map = str(self.gui.link_map.toPlainText())
def ok(self):
# save settings
settings = QtCore.QSettings('ShotgunSharing', 'uploader')
settings.setValue("prefs/image_command", QtCore.QVariant(self.gui.image_command.text()))
settings.setValue("prefs/movie_command", QtCore.QVariant(self.gui.movie_command.text()))
settings.setValue("prefs/shotgun_url", QtCore.QVariant(self.gui.shotgun_url.text()))
settings.setValue("prefs/shotgun_script", QtCore.QVariant(self.gui.shotgun_script.text()))
settings.setValue("prefs/shotgun_key", QtCore.QVariant(self.gui.shotgun_key.text()))
settings.setValue("prefs/shotgun_api", QtCore.QVariant(self.gui.shotgun_api.text()))
settings.setValue("prefs/path_field", QtCore.QVariant(self.gui.path_field.text()))
settings.setValue("prefs/link_map", QtCore.QVariant(self.gui.link_map.toPlainText()))
settings.setValue("prefs/geometry", self.saveGeometry())
# update instance members
self.__sync_with_fields()
def cancel(self):
# always save geometry. don't care about the other settings
settings = QtCore.QSettings('ShotgunSharing', 'uploader')
settings.setValue("prefs/geometry", self.saveGeometry())
################################################################################
# Main Window
################################################################################
class Uploader(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
# setup gui
self.gui = Ui_MainWindow()
self.gui.setupUi(self)
# setup undo/redo
self.stack = QtGui.QUndoStack(self)
undo = self.stack.createUndoAction(self)
undo.setShortcut(QtGui.QKeySequence('Ctrl+Z'))
redo = self.stack.createRedoAction(self)
redo.setShortcut(QtGui.QKeySequence('Shift+Ctrl+Z'))
self.gui.menuEdit.addAction(undo)
self.gui.menuEdit.addAction(redo)
# setup model
self.model = ShotgunFileModel(self.stack, self.gui.file_table_view)
self.gui.file_table_view.setModel(self.model)
self.gui.file_table_view.viewport().setAcceptDrops(True)
self.gui.file_table_view.setDropIndicatorShown(True)
# connect up signals
self.connect(self.gui.buttons, QtCore.SIGNAL('accepted()'), self.ok)
self.connect(self.gui.buttons, QtCore.SIGNAL('rejected()'), self.close_window)
self.connect(self.gui.action_Preferences, QtCore.SIGNAL('activated()'), self.do_prefs)
self.connect(self.gui.action_Quit, QtCore.SIGNAL('activated()'), self.close_window)
self.connect(self.gui.action_Add_Files, QtCore.SIGNAL('activated()'), self.add_files)
self.connect(self.gui.action_Delete_Selected, QtCore.SIGNAL('activated()'), self.delete_selected)
self.connect(self.gui.file_table_view.selectionModel(), QtCore.SIGNAL('selectionChanged(QItemSelection, QItemSelection)'), self.table_selection_changed)
self.connect(self.model, QtCore.SIGNAL('filesAdded(QStringList)'), self.add_files)
self.connect(self.gui.project, QtCore.SIGNAL('currentIndexChanged(QString)'), self.link_data_changed)
self.connect(self.gui.link_type, QtCore.SIGNAL('currentIndexChanged(QString)'), self.link_data_changed)
# default action states
self.gui.action_Delete_Selected.setEnabled(False)
# load up prefs
self.prefs = PrefsDialog()
# connect to shotgun
self.__conn = None
self.__conn = self.__connect_to_shotgun()
if not self.__conn:
self.gui.buttons.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
else:
self.gui.buttons.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)
# restore state
settings = QtCore.QSettings('ShotgunSharing', 'uploader')
self.gui.tags.setText(settings.value("main/tags", DEFAULT_TAGS).toString())
self.restoreGeometry(settings.value("main/geometry").toByteArray())
# restore column widths
col_widths = [int(w.strip()) for w in str(settings.value("main/col_widths", DEFAULT_COL_WIDTHS).toString()).split(',') if w.strip()]
for i in xrange(min(len(col_widths), self.model.columnCount())):
self.gui.file_table_view.setColumnWidth(i, col_widths[i])
def __connect_to_shotgun(self):
"""
Try to connect to shotgun, alerting on failure.
If connected, sync up interface with shotgun instance settings.
"""
# try to load up the shotgun api
try:
if os.path.isdir(self.prefs.shotgun_api):
sys.path.append(self.prefs.shotgun_api)
else:
sys.path.append(os.path.dirname(self.prefs.shotgun_api))
import shotgun_api3 as sg
except ImportError:
sys.path.pop()
QtGui.QMessageBox.critical(self, self.tr("uploader"),
self.tr("shotgun_api3_preview module not found. Update your Preferences."),
QtGui.QMessageBox.Ok)
return None
# try to connect to shotgun
try:
conn = sg.Shotgun(self.prefs.shotgun_url, self.prefs.shotgun_script, self.prefs.shotgun_key)
# verify with a simple fine
conn.find_one('Project', [])
except Exception, e:
QtGui.QMessageBox.critical(self, self.tr("uploader"),
self.tr("Could not connect to shotgun:\n\n%s.\n\nUpdate your Preferences." % e.message),
QtGui.QMessageBox.Ok)
return None
# validate connection by seeing if Attachments are accessible
try:
# use path_field to validate that is set right, if it is set
conn.schema_field_read('Attachment', self.prefs.path_field or 'project')
except socket.gaierror:
# raised if connection straight out failed
QtGui.QMessageBox.critical(self, self.tr("uploader"),
self.tr("cannot connect to shotgun host. Update your Preferences."),
QtGui.QMessageBox.Ok)
return None
except sg.Fault, e:
QtGui.QMessageBox.critical(self, self.tr("uploader"),
self.tr("Cannot get path field:\n%s.\n\nUpdate your Preferences." % e.message),
QtGui.QMessageBox.Ok)
if conn:
# got a conn. get sync'ed up with it
self.__conn = conn
# load up defaults for entity selection fields
settings = QtCore.QSettings('ShotgunSharing', 'uploader')
default_project = str(settings.value("main/project", '').toString())
default_link_type = str(settings.value("main/link_type", '').toString())
# load up projects, populate the completer and combo box
projects = [(p['name'], p['id']) for p in conn.find('Project', [], ['name']) if p['name'] != 'Template Project']
completer = QtGui.QCompleter([p[0] for p in projects], self)
completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
self.gui.project.clear()
for p in projects:
self.gui.project.addItem(p[0], p[1])
if p[0] == default_project:
# name matched default project, select it
self.gui.project.setCurrentIndex(self.gui.project.count()-1)
self.gui.project.setCompleter(completer)
self.gui.project.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp('|'.join([p[0] for p in projects]), QtCore.Qt.CaseInsensitive), self))
# setup link type, populate the completer and combo box
# TODO: should make sure these are active in the instance
link_types = ['', 'Asset', 'Scene', 'Sequence', 'Shot', 'Task', 'Project', 'Tool', 'Ticket']
completer = QtGui.QCompleter(link_types, self)
completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
self.gui.link_type.clear()
for l in link_types:
self.gui.link_type.addItem(l)
if l == default_link_type:
# name matches default, update selection
self.gui.link_type.setCurrentIndex(self.gui.link_type.count()-1)
self.gui.link_type.setCompleter(completer)
self.gui.link_type.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp('|'.join(link_types), QtCore.Qt.CaseInsensitive), self))
# default used to update reference to
self.default_link = conn.find_one('HumanUser', [['login', 'is', getpass.getuser()]], ['name'])
return conn
return None
def link_data_changed(self, ignored):
"""respond to an update for project or link type"""
# zero out the selected link
self.gui.link_name.clear()
project = int(self.gui.project.itemData(self.gui.project.currentIndex()).toInt()[0])
link_type = str(self.gui.link_type.currentText())
if not link_type:
# can't do anything without link type selected
return
filters = project and [['project', 'is', {'type': 'Project', 'id': project}]] or []
if link_type in ['Project']:
filters = []
# find possible matches, grabbing values that are useful for generating
# a pretty name for the different entity types
matches = self.__conn.find(link_type, filters, ['display_name', 'content', 'name', 'code', 'sg_sequence', 'sg_asset_type'])
texts = ['']
self.gui.link_name.addItem('', 0)
if matches and ('sg_sequence' in matches[0]):
# going to need sequences
seqs = self.__conn.find('Sequence', filters, ['code'])
seq_map = dict([(s['id'], s['code']) for s in seqs])
for match in matches:
# TODO: make the set of extra info included with a name richer
# look for something that has a good name
text = match.get('display_name', match.get('content', match.get('name', match.get('code', None))))
if text is None:
# just in case the entity type has no field we know about as a
# useful name
break
if 'sg_sequence' in match:
# display the sequence if we've got it
text = text + " (%s)" % (match['sg_sequence'] and seq_map[match['sg_sequence']['id']] or 'None')
elif 'sg_asset_type' in match:
# display the asset type if we've got it
text = text + " (%s)" % match['sg_asset_type']
self.gui.link_name.addItem(text, match['id'])
texts.append(text)
# And setup the completer
completer = QtGui.QCompleter(texts, self)
completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
self.gui.link_name.setCompleter(completer)
self.gui.link_name.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp('|'.join(texts), QtCore.Qt.CaseInsensitive), self))
def delete_selected(self):
"""grab selection and delete it"""
rows = dict([(index.row(), None) for index in self.gui.file_table_view.selectedIndexes()]).keys()
self.stack.push(DeleteFilesCommand(self.model, rows))
def add_files(self, fnames=None):
if fnames is None:
# pop up the file chooser dialog box if the files weren't passed in
settings = QtCore.QSettings('ShotgunSharing', 'uploader')
# default to the last dir we used
d = settings.value("fdialog/dir", QtCore.QString()).toString()
fnames = [str(f) for f in QtGui.QFileDialog.getOpenFileNames(self, 'Select files to upload', d)]
if fnames:
# save the dir of the first file selected
settings.setValue("fdialog/dir", os.path.dirname(fnames[0]))
if fnames:
tags = str(self.gui.tags.text())
files = []
project = int(self.gui.project.itemData(self.gui.project.currentIndex()).toInt()[0])
skipped_fnames = []
for fname in [str(f) for f in fnames]:
if str(self.gui.link_name.currentText()):
# if link_name has been selected, use all the info used to
# get to that entity
link_type = str(self.gui.link_type.currentText())
link_name = str(self.gui.link_name.currentText())
link_id = int(self.gui.link_name.itemData(self.gui.link_name.currentIndex()).toInt()[0])
link = {'type': link_type, 'name': link_name, 'id': link_id, 'project': {'type': 'Project', 'id': project}}
else:
# otherwise try to figure out the link from the path rules
# in the prefs
link = self.__link_for_file(fname)
if link is None:
# didn't have a link, remember that so we can error
skipped_fnames.append(fname)
continue
f = ShotgunFile(str(fname), tags, link)
files.append(f)
# we've got the file objects we're going to create. do it
self.stack.push(NewFileCommand(self.model, files))
for i in xrange(self.model.columnCount()):
# make sure we can see the data
self.gui.file_table_view.resizeColumnToContents(i)
if skipped_fnames:
# and let people know if we skipped something becuase of no links
QtGui.QMessageBox.warning(self, self.tr("uploader"),
self.tr("Couldn't figure out link for:\n%s\n\nPlease select what to link it to." % '\n'.join(skipped_fnames)),
QtGui.QMessageBox.Ok)
# Pattern - find an odd # of $ which doesn't have a $ before it
# then match {pattern} or pattern, keep pattern in the match group 'name'
__PATTERN_RE = re.compile(r'(?<!\$)\$(\$\$)*{?(?P<name>[_a-z][_a-z0-9.]*)}?')
def __link_for_file(self, fname, warn=False):
try:
import shotgun_api3_preview as sg
for line in [line for line in self.prefs.link_map.split('\n') if line]:
try:
# translate the lines link_type: match into a useful regexp
(link_type, link_match) = [s.strip() for s in line.split(':', 1)]
re_match = link_match
# translate glob syntax to regexp
re_match = re_match.replace('?', '.{1}')
re_match = re_match.replace('*', '[^%s]+' % os.sep)
name_map = {}
def track_names(match):
"""map temp group names to the pattern they are generated for"""
pat = '(?P<name%s>[^%s]+)' % (len(name_map), os.sep)
name_map['name%d' % len(name_map)] = match.group('name')
return pat
# find all variable replacements and replace them with regexp
# syntax that'll grab the text from the file paths for us
result_re = self.__PATTERN_RE.sub(track_names, re_match)
# now we've got a workable regexp, match against the file name
match = re.search(result_re, fname)
if match:
# we have a rule that matches, create a shotgun filter
# representing that match and see if it worked
filters = []
for (key, value) in match.groupdict().iteritems():
filters.append([name_map[key], 'is', value])
link = self.__conn.find_one(link_type, filters, ['name', 'code'])
return link
except ValueError:
if warn:
QtGui.QMessageBox.warning(self, self.tr("uploader"),
self.tr("Couldn't parse link map line '%s'. Fix your Preferences." % line),
QtGui.QMessageBox.Ok)
except sg.Fault:
# error in shotgun, no link, keep on trying
pass
# no matches
except ImportError:
# couldn't import shotgun, not configured correctly, just return
pass
return None
def table_selection_changed(self, selected=None, deselected=None):
"""allow delete selected only when there is a row selected"""
columns = self.model.columnCount()
rows = len(self.gui.file_table_view.selectedIndexes())/columns
any = (rows > 0)
self.gui.action_Delete_Selected.setEnabled(any)
def do_prefs(self):
"""show the prefs dialog and resync with shotgun"""
if self.prefs.exec_() == QtGui.QDialog.Accepted:
self.__conn = self.__connect_to_shotgun()
self.__link_for_file('', warn=True)
if not self.__conn:
self.gui.buttons.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
else:
self.gui.buttons.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)
def ok(self):
"""make the magic happen"""
conn = self.__conn
prog = QtGui.QProgressDialog()
# guess that progress will progress along with bytes uploaded
maximum = sum([f.size for f in self.model.files])
nfiles = len(self.model.files)
prog.setMaximum(maximum)
prog.setLabelText("%-80s" % "Uploading %d/%d: %s" % (0, nfiles, ''))
prog.setValue(0)
prog.show()
i = 0
while self.model.files:
i += 1
f = self.model.files[0]
# let folks know what we're doing
prog.setLabelText("%-80s" % "Uploading %d/%d: %s" % (i, nfiles, f.path))
if prog.wasCanceled():
break
# upload
f_id = conn.upload(f.link['type'], f.link['id'], f.path)
# update tags, path, and reference for
data = {'attachment_reference_links': [self.default_link]}
if self.prefs.path_field:
data[self.prefs.path_field] = f.path
if f.tags:
data['tag_list'] = f.tags.split(',')
conn.update('Attachment', f_id, data)
# do thumbnails for files we can
mime = mimetypes.guess_type(f.path)[0]
if mime is not None and (mime.startswith('video') or mime.startswith('image')):
tmp = tempfile.mktemp('.jpg', 'uploader_')
try:
# figure out which command to run
cmd = None
if mime.startswith('image'):
cmd = self.prefs.image_command
elif mime.startswith('video'):
cmd = self.prefs.movie_command
if cmd is not None:
# do the replacements for the command and run it
cmd = cmd.replace('$in', '"%s"' % f.path)
cmd = cmd.replace('$out', '"%s"' % tmp)
cmd = cmd.replace('$offset', '"%s"' % f.hero_offset)
os.system(cmd)
if os.path.exists(tmp):
# it worked, upload the thumbnail
conn.upload_thumbnail('Attachment', f_id, tmp)
finally:
# make sure we clean up
if os.path.exists(tmp):
os.remove(tmp)
if f.note:
# add the note if set
conn.create('Note', {'content': f.note, 'note_links': [{'type': 'Attachment', 'id': f_id}],
'project': f.link.get('project', f.link)})
# update progress
prog.setValue(prog.value()+f.size)
# get rid of the file from the interface
self.model.delete_files(0, 1)
# allow the gui to update
QtGui.QApplication.processEvents()
# all done, make sure we're clear
prog.setValue(maximum)
self.stack.clear()
def close_window(self):
# save state
settings = QtCore.QSettings('ShotgunSharing', 'uploader')
settings.setValue("main/tags", QtCore.QVariant(self.gui.tags.text()))
settings.setValue("main/project", QtCore.QVariant(self.gui.project.currentText()))
settings.setValue("main/link_type", QtCore.QVariant(self.gui.link_type.currentText()))
settings.setValue("main/geometry", self.saveGeometry())
col_widths = ','.join([str(self.gui.file_table_view.columnWidth(i)) for i in xrange(self.model.columnCount())])
settings.setValue("main/col_widths", QtCore.QVariant(col_widths))
# shut down
self.close()
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'main_window.ui'
#
# Created: Tue Mar 16 22:32:04 2010
# by: PyQt4 UI code generator 4.6.2
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(617, 471)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.label_3 = QtGui.QLabel(self.centralwidget)
self.label_3.setTextFormat(QtCore.Qt.AutoText)
self.label_3.setWordWrap(True)
self.label_3.setObjectName("label_3")
self.verticalLayout.addWidget(self.label_3)
self.groupBox = QtGui.QGroupBox(self.centralwidget)
self.groupBox.setObjectName("groupBox")
self.horizontalLayout_3 = QtGui.QHBoxLayout(self.groupBox)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.frame = QtGui.QFrame(self.groupBox)
self.frame.setFrameShape(QtGui.QFrame.NoFrame)
self.frame.setFrameShadow(QtGui.QFrame.Raised)
self.frame.setObjectName("frame")
self.gridLayout = QtGui.QGridLayout(self.frame)
self.gridLayout.setMargin(0)
self.gridLayout.setObjectName("gridLayout")
self.label = QtGui.QLabel(self.frame)
self.label.setMaximumSize(QtCore.QSize(47, 20))
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.project = QtGui.QComboBox(self.frame)
self.project.setEditable(True)
self.project.setInsertPolicy(QtGui.QComboBox.NoInsert)
self.project.setFrame(True)
self.project.setObjectName("project")
self.gridLayout.addWidget(self.project, 0, 1, 1, 1)
self.label_4 = QtGui.QLabel(self.frame)
self.label_4.setObjectName("label_4")
self.gridLayout.addWidget(self.label_4, 0, 2, 1, 1)
self.tags = QtGui.QLineEdit(self.frame)
self.tags.setObjectName("tags")
self.gridLayout.addWidget(self.tags, 0, 3, 1, 1)
self.label_2 = QtGui.QLabel(self.frame)
self.label_2.setMaximumSize(QtCore.QSize(65, 20))
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
self.link_type = QtGui.QComboBox(self.frame)
self.link_type.setEditable(True)
self.link_type.setInsertPolicy(QtGui.QComboBox.NoInsert)
self.link_type.setObjectName("link_type")
self.gridLayout.addWidget(self.link_type, 1, 1, 1, 1)
self.label_5 = QtGui.QLabel(self.frame)
self.label_5.setMaximumSize(QtCore.QSize(71, 20))
self.label_5.setObjectName("label_5")
self.gridLayout.addWidget(self.label_5, 1, 2, 1, 1)
self.link_name = QtGui.QComboBox(self.frame)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.link_name.sizePolicy().hasHeightForWidth())
self.link_name.setSizePolicy(sizePolicy)
self.link_name.setEditable(True)
self.link_name.setInsertPolicy(QtGui.QComboBox.NoInsert)
self.link_name.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContentsOnFirstShow)
self.link_name.setObjectName("link_name")
self.gridLayout.addWidget(self.link_name, 1, 3, 1, 1)
self.horizontalLayout_3.addWidget(self.frame)
self.verticalLayout.addWidget(self.groupBox)
self.groupBox_2 = QtGui.QGroupBox(self.centralwidget)
self.groupBox_2.setObjectName("groupBox_2")
self.horizontalLayout_4 = QtGui.QHBoxLayout(self.groupBox_2)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.file_table_view = QtGui.QTableView(self.groupBox_2)
font = QtGui.QFont()
font.setFamily("Helvetica")
font.setPointSize(12)
self.file_table_view.setFont(font)
self.file_table_view.setEditTriggers(QtGui.QAbstractItemView.AnyKeyPressed|QtGui.QAbstractItemView.DoubleClicked|QtGui.QAbstractItemView.EditKeyPressed|QtGui.QAbstractItemView.SelectedClicked)
self.file_table_view.setDragDropMode(QtGui.QAbstractItemView.DropOnly)
self.file_table_view.setAlternatingRowColors(True)
self.file_table_view.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.file_table_view.setSortingEnabled(False)
self.file_table_view.setWordWrap(False)
self.file_table_view.setObjectName("file_table_view")
self.file_table_view.horizontalHeader().setDefaultSectionSize(40)
self.file_table_view.horizontalHeader().setHighlightSections(True)
self.file_table_view.horizontalHeader().setStretchLastSection(True)
self.file_table_view.verticalHeader().setVisible(False)
self.file_table_view.verticalHeader().setStretchLastSection(False)
self.horizontalLayout_4.addWidget(self.file_table_view)
self.verticalLayout.addWidget(self.groupBox_2)
self.frame_3 = QtGui.QFrame(self.centralwidget)
self.frame_3.setFrameShape(QtGui.QFrame.NoFrame)
self.frame_3.setFrameShadow(QtGui.QFrame.Raised)
self.frame_3.setObjectName("frame_3")
self.horizontalLayout = QtGui.QHBoxLayout(self.frame_3)
self.horizontalLayout.setMargin(0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.buttons = QtGui.QDialogButtonBox(self.frame_3)
self.buttons.setOrientation(QtCore.Qt.Horizontal)
self.buttons.setStandardButtons(QtGui.QDialogButtonBox.Close|QtGui.QDialogButtonBox.Ok)
self.buttons.setObjectName("buttons")
self.horizontalLayout.addWidget(self.buttons)
self.verticalLayout.addWidget(self.frame_3)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 617, 22))
self.menubar.setObjectName("menubar")
self.menu_File = QtGui.QMenu(self.menubar)
self.menu_File.setObjectName("menu_File")
self.menuEdit = QtGui.QMenu(self.menubar)
self.menuEdit.setObjectName("menuEdit")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.action_Preferences = QtGui.QAction(MainWindow)
self.action_Preferences.setObjectName("action_Preferences")
self.action_Quit = QtGui.QAction(MainWindow)
self.action_Quit.setObjectName("action_Quit")
self.action_Add_Files = QtGui.QAction(MainWindow)
self.action_Add_Files.setObjectName("action_Add_Files")
self.action_Delete_Selected = QtGui.QAction(MainWindow)
self.action_Delete_Selected.setObjectName("action_Delete_Selected")
self.menu_File.addAction(self.action_Add_Files)
self.menu_File.addAction(self.action_Delete_Selected)
self.menu_File.addSeparator()
self.menu_File.addAction(self.action_Preferences)
self.menu_File.addAction(self.action_Quit)
self.menubar.addAction(self.menu_File.menuAction())
self.menubar.addAction(self.menuEdit.menuAction())
self.label_3.setBuddy(self.file_table_view)
self.label_4.setBuddy(self.tags)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "Shotgun File Uploader", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Lucida Grande\'; font-size:13pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt;\">Instructions: </span><span style=\" font-size:9pt; font-weight:600;\">Add files via the menu or drag & drop</span><span style=\" font-size:9pt;\">. Just type to </span><span style=\" font-size:9pt; font-weight:600;\">adjust the hero frames for movies</span><span style=\" font-size:9pt;\">. Hint: You can use a tag like \"to_be_filed\" to be able to easily find uploaded Files in Shotgun. Select Project/Link Type/Link Name to </span><span style=\" font-size:9pt; font-weight:600;\">link added files to a specific entity</span><span style=\" font-size:9pt;\">. Leave these blank to </span><span style=\" font-size:9pt; font-weight:600;\">let the config try to figure out the linked entity from the file path</span><span style=\" font-size:9pt;\">. If all else fails, the file will be linked to your shotgun account for easy searching. Configure Shotgun access and thumbnail generation through the preferences.</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
self.groupBox.setTitle(QtGui.QApplication.translate("MainWindow", "Shotgun Defaults", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("MainWindow", "Project:", None, QtGui.QApplication.UnicodeUTF8))
self.label_4.setText(QtGui.QApplication.translate("MainWindow", "Tags:", None, QtGui.QApplication.UnicodeUTF8))
self.tags.setText(QtGui.QApplication.translate("MainWindow", "to_be_filed", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("MainWindow", "Link Type:", None, QtGui.QApplication.UnicodeUTF8))
self.label_5.setText(QtGui.QApplication.translate("MainWindow", "Link Name:", None, QtGui.QApplication.UnicodeUTF8))
self.groupBox_2.setTitle(QtGui.QApplication.translate("MainWindow", "Files to Upload", None, QtGui.QApplication.UnicodeUTF8))
self.menu_File.setTitle(QtGui.QApplication.translate("MainWindow", "&File", None, QtGui.QApplication.UnicodeUTF8))
self.menuEdit.setTitle(QtGui.QApplication.translate("MainWindow", "Edit", None, QtGui.QApplication.UnicodeUTF8))
self.action_Preferences.setText(QtGui.QApplication.translate("MainWindow", "Preferences...", None, QtGui.QApplication.UnicodeUTF8))
self.action_Preferences.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+,", None, QtGui.QApplication.UnicodeUTF8))
self.action_Quit.setText(QtGui.QApplication.translate("MainWindow", "&Quit", None, QtGui.QApplication.UnicodeUTF8))
self.action_Quit.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+Q", None, QtGui.QApplication.UnicodeUTF8))
self.action_Add_Files.setText(QtGui.QApplication.translate("MainWindow", "&Add Files...", None, QtGui.QApplication.UnicodeUTF8))
self.action_Add_Files.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+O", None, QtGui.QApplication.UnicodeUTF8))
self.action_Delete_Selected.setText(QtGui.QApplication.translate("MainWindow", "&Delete Selected", None, QtGui.QApplication.UnicodeUTF8))
self.action_Delete_Selected.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+Backspace", None, QtGui.QApplication.UnicodeUTF8))
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'prefs_dialog.ui'
#
# Created: Tue Mar 16 16:40:24 2010
# by: PyQt4 UI code generator 4.6.2
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_Preferences(object):
def setupUi(self, Preferences):
Preferences.setObjectName("Preferences")
Preferences.resize(662, 722)
Preferences.setMinimumSize(QtCore.QSize(629, 419))
self.gridLayout = QtGui.QGridLayout(Preferences)
self.gridLayout.setObjectName("gridLayout")
self.groupBox = QtGui.QGroupBox(Preferences)
self.groupBox.setObjectName("groupBox")
self.verticalLayout = QtGui.QVBoxLayout(self.groupBox)
self.verticalLayout.setSpacing(0)
self.verticalLayout.setMargin(0)
self.verticalLayout.setObjectName("verticalLayout")
self.frame_2 = QtGui.QFrame(self.groupBox)
self.frame_2.setFrameShape(QtGui.QFrame.NoFrame)
self.frame_2.setFrameShadow(QtGui.QFrame.Raised)
self.frame_2.setObjectName("frame_2")
self.gridLayout_4 = QtGui.QGridLayout(self.frame_2)
self.gridLayout_4.setObjectName("gridLayout_4")
self.label_2 = QtGui.QLabel(self.frame_2)
font = QtGui.QFont()
font.setWeight(75)
font.setBold(True)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.gridLayout_4.addWidget(self.label_2, 1, 0, 1, 1)
self.label = QtGui.QLabel(self.frame_2)
font = QtGui.QFont()
font.setWeight(75)
font.setBold(True)
self.label.setFont(font)
self.label.setObjectName("label")
self.gridLayout_4.addWidget(self.label, 0, 0, 1, 1)
self.movie_command = QtGui.QLineEdit(self.frame_2)
self.movie_command.setObjectName("movie_command")
self.gridLayout_4.addWidget(self.movie_command, 1, 1, 1, 1)
self.image_command = QtGui.QLineEdit(self.frame_2)
self.image_command.setObjectName("image_command")
self.gridLayout_4.addWidget(self.image_command, 0, 1, 1, 1)
self.verticalLayout.addWidget(self.frame_2)
self.frame = QtGui.QFrame(self.groupBox)
self.frame.setFrameShape(QtGui.QFrame.NoFrame)
self.frame.setFrameShadow(QtGui.QFrame.Raised)
self.frame.setObjectName("frame")
self.horizontalLayout = QtGui.QHBoxLayout(self.frame)
self.horizontalLayout.setObjectName("horizontalLayout")
self.label_8 = QtGui.QLabel(self.frame)
self.label_8.setWordWrap(True)
self.label_8.setObjectName("label_8")
self.horizontalLayout.addWidget(self.label_8)
self.verticalLayout.addWidget(self.frame)
self.gridLayout.addWidget(self.groupBox, 0, 0, 1, 1)
self.buttons = QtGui.QDialogButtonBox(Preferences)
self.buttons.setOrientation(QtCore.Qt.Horizontal)
self.buttons.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttons.setObjectName("buttons")
self.gridLayout.addWidget(self.buttons, 3, 0, 1, 1)
self.groupBox_2 = QtGui.QGroupBox(Preferences)
self.groupBox_2.setObjectName("groupBox_2")
self.gridLayout_3 = QtGui.QGridLayout(self.groupBox_2)
self.gridLayout_3.setObjectName("gridLayout_3")
self.frame_3 = QtGui.QFrame(self.groupBox_2)
self.frame_3.setFrameShape(QtGui.QFrame.NoFrame)
self.frame_3.setFrameShadow(QtGui.QFrame.Raised)
self.frame_3.setObjectName("frame_3")
self.gridLayout_2 = QtGui.QGridLayout(self.frame_3)
self.gridLayout_2.setMargin(0)
self.gridLayout_2.setObjectName("gridLayout_2")
self.label_3 = QtGui.QLabel(self.frame_3)
font = QtGui.QFont()
font.setWeight(75)
font.setBold(True)
self.label_3.setFont(font)
self.label_3.setObjectName("label_3")
self.gridLayout_2.addWidget(self.label_3, 0, 0, 1, 1)
self.shotgun_url = QtGui.QLineEdit(self.frame_3)
self.shotgun_url.setObjectName("shotgun_url")
self.gridLayout_2.addWidget(self.shotgun_url, 0, 1, 1, 1)
self.label_4 = QtGui.QLabel(self.frame_3)
font = QtGui.QFont()
font.setWeight(75)
font.setBold(True)
self.label_4.setFont(font)
self.label_4.setObjectName("label_4")
self.gridLayout_2.addWidget(self.label_4, 1, 0, 1, 1)
self.label_5 = QtGui.QLabel(self.frame_3)
font = QtGui.QFont()
font.setWeight(75)
font.setBold(True)
self.label_5.setFont(font)
self.label_5.setObjectName("label_5")
self.gridLayout_2.addWidget(self.label_5, 2, 0, 1, 1)
self.label_6 = QtGui.QLabel(self.frame_3)
font = QtGui.QFont()
font.setWeight(75)
font.setBold(True)
self.label_6.setFont(font)
self.label_6.setObjectName("label_6")
self.gridLayout_2.addWidget(self.label_6, 3, 0, 1, 1)
self.label_7 = QtGui.QLabel(self.frame_3)
self.label_7.setObjectName("label_7")
self.gridLayout_2.addWidget(self.label_7, 4, 0, 1, 1)
self.shotgun_script = QtGui.QLineEdit(self.frame_3)
self.shotgun_script.setObjectName("shotgun_script")
self.gridLayout_2.addWidget(self.shotgun_script, 1, 1, 1, 1)
self.shotgun_key = QtGui.QLineEdit(self.frame_3)
self.shotgun_key.setObjectName("shotgun_key")
self.gridLayout_2.addWidget(self.shotgun_key, 2, 1, 1, 1)
self.shotgun_api = QtGui.QLineEdit(self.frame_3)
self.shotgun_api.setObjectName("shotgun_api")
self.gridLayout_2.addWidget(self.shotgun_api, 3, 1, 1, 1)
self.path_field = QtGui.QLineEdit(self.frame_3)
self.path_field.setObjectName("path_field")
self.gridLayout_2.addWidget(self.path_field, 4, 1, 1, 1)
self.gridLayout_3.addWidget(self.frame_3, 5, 1, 1, 1)
self.label_9 = QtGui.QLabel(self.groupBox_2)
self.label_9.setWordWrap(True)
self.label_9.setObjectName("label_9")
self.gridLayout_3.addWidget(self.label_9, 6, 1, 1, 1)
self.gridLayout.addWidget(self.groupBox_2, 1, 0, 1, 1)
self.groupBox_3 = QtGui.QGroupBox(Preferences)
self.groupBox_3.setObjectName("groupBox_3")
self.verticalLayout_2 = QtGui.QVBoxLayout(self.groupBox_3)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.link_map = QtGui.QTextEdit(self.groupBox_3)
self.link_map.setTabChangesFocus(True)
self.link_map.setAcceptRichText(False)
self.link_map.setObjectName("link_map")
self.verticalLayout_2.addWidget(self.link_map)
self.label_10 = QtGui.QLabel(self.groupBox_3)
self.label_10.setWordWrap(True)
self.label_10.setObjectName("label_10")
self.verticalLayout_2.addWidget(self.label_10)
self.gridLayout.addWidget(self.groupBox_3, 2, 0, 1, 1)
self.retranslateUi(Preferences)
QtCore.QObject.connect(self.buttons, QtCore.SIGNAL("accepted()"), Preferences.accept)
QtCore.QObject.connect(self.buttons, QtCore.SIGNAL("rejected()"), Preferences.reject)
QtCore.QMetaObject.connectSlotsByName(Preferences)
def retranslateUi(self, Preferences):
Preferences.setWindowTitle(QtGui.QApplication.translate("Preferences", "Preferences", None, QtGui.QApplication.UnicodeUTF8))
self.groupBox.setTitle(QtGui.QApplication.translate("Preferences", "Thumbnail Generation", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("Preferences", "Movie Command:", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("Preferences", "Image Command:", None, QtGui.QApplication.UnicodeUTF8))
self.movie_command.setText(QtGui.QApplication.translate("Preferences", "ffmpeg -y -i $in -f mjpeg -ss $offset -vframes 1 -s svga -an $out", None, QtGui.QApplication.UnicodeUTF8))
self.image_command.setText(QtGui.QApplication.translate("Preferences", "convert $in $out", None, QtGui.QApplication.UnicodeUTF8))
self.label_8.setText(QtGui.QApplication.translate("Preferences", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Lucida Grande\'; font-size:13pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:9pt;\">The commands to run to generate a thumbnail for a generic image, movie, or photoshop doc respectively. The string $in will be replaced with the path to the input file. The string $out will be replaced with the temporary thumbnail file. The string $offset will be replaced with the offset to the hero frame.</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
self.groupBox_2.setTitle(QtGui.QApplication.translate("Preferences", "Shotgun", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("Preferences", "Shotgun URL:", None, QtGui.QApplication.UnicodeUTF8))
self.shotgun_url.setText(QtGui.QApplication.translate("Preferences", "http://shotgun.kickass-studios.com/", None, QtGui.QApplication.UnicodeUTF8))
self.label_4.setText(QtGui.QApplication.translate("Preferences", "Shotgun Script:", None, QtGui.QApplication.UnicodeUTF8))
self.label_5.setText(QtGui.QApplication.translate("Preferences", "Shotgun Script Key:", None, QtGui.QApplication.UnicodeUTF8))
self.label_6.setText(QtGui.QApplication.translate("Preferences", "Path to Shotgun API:", None, QtGui.QApplication.UnicodeUTF8))
self.label_7.setToolTip(QtGui.QApplication.translate("Preferences", "The (optional) name of the field on the Attachment entity to set to the full path of the file being uploaded. Good to keep track of where the source file for the upload was.", None, QtGui.QApplication.UnicodeUTF8))
self.label_7.setText(QtGui.QApplication.translate("Preferences", "Field for full path:", None, QtGui.QApplication.UnicodeUTF8))
self.shotgun_script.setText(QtGui.QApplication.translate("Preferences", "thumb_uploader", None, QtGui.QApplication.UnicodeUTF8))
self.shotgun_key.setText(QtGui.QApplication.translate("Preferences", "ALONGSTRINGOFNUMBERSANDLETTERSFROMSHOTGUN", None, QtGui.QApplication.UnicodeUTF8))
self.shotgun_api.setText(QtGui.QApplication.translate("Preferences", "/net/a/place/where/we/put/the/shotgun_api3_preview.py", None, QtGui.QApplication.UnicodeUTF8))
self.path_field.setText(QtGui.QApplication.translate("Preferences", "sg_path_to_file", None, QtGui.QApplication.UnicodeUTF8))
self.label_9.setText(QtGui.QApplication.translate("Preferences", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Lucida Grande\'; font-size:13pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:10pt;\">The information needed to connect to shotgun. On upload the value in \"Field for full path\" (if filled out) with be used as the field on Attachment entities to fill out with the path to file you uploaded.</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
self.groupBox_3.setTitle(QtGui.QApplication.translate("Preferences", "Link Mapping", None, QtGui.QApplication.UnicodeUTF8))
self.link_map.setHtml(QtGui.QApplication.translate("Preferences", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Lucida Grande\'; font-size:13pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Asset: /job_root/*/assets/$type/$name</p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Task: /job_root/*/shots/$entity.shot.name/$entity.task.name</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
self.label_10.setText(QtGui.QApplication.translate("Preferences", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Lucida Grande\'; font-size:13pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:10pt;\">The values filled out in this table will determine what an uploaded file will be linked to. The formate is \'Entity Type\': \'Match\'. Match is an expression that is run against the full path of the file being uploaded. Variables starting with \'$\' will be matched against the full path of the file being uploaded. The name of the variable will be used in a shotgun find_one call to find the entity to link to. If there are no matches, the file is linked to the Person entity matching the username of the person doing the upload. These rules are evaluated in order and the first match wins.</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
w = Uploader()
w.show()
w.raise_()
sys.exit(app.exec_())
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
33,
14084,
3217,
367,
24349,
1584,
370,
5244,
357,
17924,
14,
199,
199,
19780,
1265,
370,
7908,
626,
1145,
367,
282,
2488,
1033,
357,
17924,
1256,
436,
2082,
5523,
14,
199,
21145,
1584,
1929,
370,
506,
10632,
370,
376,
3411,
4642,
12,
1325,
883,
1172,
12681,
436,
3762,
6781,
14,
199,
199,
5949,
26,
820,
2873,
699,
416,
85,
665,
4848,
416,
85,
32,
416,
26966,
14,
957,
30,
199,
624,
199,
199,
13289,
199,
3,
6186,
19924,
7079,
26,
7743,
3520,
340,
1265,
2934,
13135,
370,
675,
314,
2884,
1928,
1101,
4493,
199,
13289,
199,
3472,
63,
25041,
39,
1734,
63,
3735,
275,
3286,
846,
15,
65,
15,
2778,
15,
4509,
15,
1129,
15,
524,
15,
1589,
15,
2782,
17924,
63,
1246,
19,
14,
647,
2,
199,
3472,
63,
25041,
39,
1734,
63,
2632,
275,
298,
1014,
921,
2782,
17924,
14,
31257,
405,
13,
270,
14525,
736,
14,
957,
6687,
199,
3472,
63,
25041,
39,
1734,
63,
10484,
275,
298,
16534,
63,
13671,
2,
199,
3472,
63,
25041,
39,
1734,
63,
3078,
275,
298,
748,
7770,
5353,
3359,
8861,
29298,
44,
1573,
13107,
1092,
3053,
40,
1387,
39,
1734,
2,
199,
3472,
63,
9438,
63,
10761,
275,
298,
3916,
2672,
262,
2672,
548,
2,
199,
3472,
63,
24321,
4332,
63,
10761,
275,
298,
27648,
446,
89,
446,
73,
2672,
262,
446,
70,
333,
14230,
446,
385,
2672,
2743,
446,
86,
8444,
413,
446,
83,
19291,
5294,
446,
290,
2672,
548,
2,
199,
3472,
63,
17626,
275,
298,
475,
63,
1235,
63,
493,
68,
2,
199,
3472,
63,
3243,
63,
8609,
275,
298,
1226,
63,
515,
63,
475,
63,
493,
2,
199,
3472,
63,
7916,
63,
5443,
275,
9638,
199,
19979,
26,
1182,
2423,
63,
1231,
6331,
15,
12186,
21792,
466,
15,
10545,
354,
93,
199,
4476,
26,
1182,
2423,
63,
1231,
6331,
15,
2782,
83,
21792,
4502,
14,
2662,
357,
14,
354,
15,
10545,
354,
93,
199,
624,
199,
199,
13289,
199,
3,
2334,
21401,
13841,
22547,
26,
2047,
9296,
1133,
1929,
370,
2621,
20561,
642,
2376,
367,
2897,
199,
13289,
199,
646,
295,
199,
646,
747,
199,
646,
984,
199,
646,
4011,
199,
646,
2838,
199,
646,
18354,
199,
646,
5549,
199,
646,
13290,
199,
199,
504,
14084,
20,
492,
5928,
199,
504,
14084,
20,
492,
10565,
199,
199,
893,
26,
272,
687,
2446,
63,
3806,
492,
32471,
63,
16031,
272,
687,
28516,
63,
7196,
492,
32471,
63,
30772,
199,
2590,
26,
272,
327,
370,
1736,
1380,
6230,
84,
7,
379,
10451,
367,
18042,
3031,
316,
272,
986,
199,
199,
13289,
199,
3,
13641,
83,
199,
13289,
199,
3472,
63,
3978,
63,
11139,
51,
275,
298,
1602,
12,
13344,
12,
772,
12,
9014,
12,
9014,
2,
421,
199,
13289,
199,
3,
5822,
199,
13289,
199,
533,
5244,
357,
17924,
1173,
1685,
8,
10901,
14,
49,
8458,
3186,
1685,
304,
272,
327,
12340,
687,
2929,
1318,
370,
376,
2225,
402,
314,
818,
1146,
909,
272,
636,
21178,
275,
359,
267,
791,
13654,
356,
283,
3160,
297,
283,
962,
356,
283,
31863,
63,
2743,
297,
283,
885,
356,
3260,
283,
10820,
356,
715,
1386,
267,
791,
13654,
356,
283,
2042,
297,
283,
962,
356,
283,
515,
297,
283,
885,
356,
3260,
283,
10820,
356,
756,
1386,
267,
791,
13654,
356,
283,
26748,
4005,
297,
283,
962,
356,
283,
1073,
63,
354,
297,
283,
885,
356,
3260,
283,
10820,
356,
756,
1386,
267,
791,
13654,
356,
283,
9440,
297,
283,
962,
356,
283,
2969,
297,
283,
885,
356,
3260,
283,
10820,
356,
715,
1386,
267,
791,
13654,
356,
283,
7443,
297,
283,
962,
356,
283,
4610,
297,
283,
885,
356,
3260,
283,
10820,
356,
715,
1386,
272,
1622,
339,
327,
1402,
3102,
272,
347,
636,
826,
721,
277,
12,
18172,
63,
2340,
12,
1676,
29,
403,
304,
267,
408,
1880,
624,
267,
1613,
8,
2662,
357,
17924,
1173,
1685,
12,
291,
2843,
826,
721,
1708,
9,
267,
291,
14,
2340,
275,
18172,
63,
2340,
267,
291,
14,
1725,
275,
942,
339,
347,
1962,
2353,
8,
277,
12,
1676,
29,
10901,
14,
49,
1685,
2681,
5109,
267,
408,
1955,
402,
4730,
365,
314,
1329,
402,
1584,
624,
267,
372,
822,
8,
277,
14,
1725,
9,
339,
347,
2763,
2353,
8,
277,
12,
1676,
29,
10901,
14,
49,
1685,
2681,
5109,
267,
408,
1955,
402,
4362,
365,
314,
1329,
402,
2323,
624,
267,
372,
822,
8,
277,
855,
21178,
9,
339,
347,
666,
8,
277,
12,
1478,
12,
4719,
29,
10901,
14,
4238,
14,
7687,
7422,
304,
267,
408,
765,
370,
372,
666,
367,
314,
7750,
2929,
11689,
315,
19227,
624,
267,
327,
2929,
4719,
12,
5965,
372,
314,
2256,
267,
340,
1478,
14,
18728,
342,
436,
4719,
508,
10565,
14,
4238,
14,
7687,
7422,
26,
288,
289,
275,
291,
14,
1725,
59,
1080,
14,
1143,
5106,
288,
1921,
275,
291,
855,
21178,
59,
1080,
14,
2301,
342,
2733,
962,
418,
288,
2203,
275,
2519,
8,
70,
12,
1921,
12,
488,
9,
288,
340,
2203,
365,
440,
488,
26,
355,
372,
10565,
14,
49,
12935,
8,
3292,
9,
288,
587,
26,
355,
372,
10565,
14,
49,
12935,
8,
277,
855,
21178,
59,
1080,
14,
2301,
342,
2733,
885,
1105,
267,
327,
440,
30944,
316,
3595,
642,
4719,
12,
2951,
372,
3866,
9854,
267,
372,
10565,
14,
49,
12935,
342,
339,
347,
1406,
1451,
8,
277,
12,
3420,
12,
16774,
12,
4719,
304,
267,
408,
1107,
666,
367,
1406,
1962,
624,
267,
340,
16774,
508,
10565,
14,
4238,
14,
19918,
436,
4719,
508,
10565,
14,
4238,
14,
7687,
7422,
26,
288,
372,
10565,
14,
49,
12935,
8,
277,
855,
21178,
59,
2792,
2733,
13654,
1105,
267,
372,
10565,
14,
49,
12935,
342,
339,
347,
663,
1451,
8,
277,
12,
1478,
12,
574,
12,
4719,
304,
267,
408,
409,
666,
367,
282,
1627,
1478,
624,
267,
340,
334,
3756,
1137,
10565,
14,
4238,
14,
4685,
7422,
304,
288,
372,
756,
267,
291,
14,
2340,
14,
5335,
8,
4001,
1110,
3110,
8,
1080,
12,
574,
12,
291,
430,
267,
372,
715,
339,
327,
18981,
436,
5978,
3102,
272,
347,
3748,
11070,
9303,
8,
277,
304,
267,
408,
10058,
5978,
5445
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
33,
14084,
3217,
367,
24349,
1584,
370,
5244,
357,
17924,
14,
199,
199,
19780,
1265,
370,
7908,
626,
1145,
367,
282,
2488,
1033,
357,
17924,
1256,
436,
2082,
5523,
14,
199,
21145,
1584,
1929,
370,
506,
10632,
370,
376,
3411,
4642,
12,
1325,
883,
1172,
12681,
436,
3762,
6781,
14,
199,
199,
5949,
26,
820,
2873,
699,
416,
85,
665,
4848,
416,
85,
32,
416,
26966,
14,
957,
30,
199,
624,
199,
199,
13289,
199,
3,
6186,
19924,
7079,
26,
7743,
3520,
340,
1265,
2934,
13135,
370,
675,
314,
2884,
1928,
1101,
4493,
199,
13289,
199,
3472,
63,
25041,
39,
1734,
63,
3735,
275,
3286,
846,
15,
65,
15,
2778,
15,
4509,
15,
1129,
15,
524,
15,
1589,
15,
2782,
17924,
63,
1246,
19,
14,
647,
2,
199,
3472,
63,
25041,
39,
1734,
63,
2632,
275,
298,
1014,
921,
2782,
17924,
14,
31257,
405,
13,
270,
14525,
736,
14,
957,
6687,
199,
3472,
63,
25041,
39,
1734,
63,
10484,
275,
298,
16534,
63,
13671,
2,
199,
3472,
63,
25041,
39,
1734,
63,
3078,
275,
298,
748,
7770,
5353,
3359,
8861,
29298,
44,
1573,
13107,
1092,
3053,
40,
1387,
39,
1734,
2,
199,
3472,
63,
9438,
63,
10761,
275,
298,
3916,
2672,
262,
2672,
548,
2,
199,
3472,
63,
24321,
4332,
63,
10761,
275,
298,
27648,
446,
89,
446,
73,
2672,
262,
446,
70,
333,
14230,
446,
385,
2672,
2743,
446,
86,
8444,
413,
446,
83,
19291,
5294,
446,
290,
2672,
548,
2,
199,
3472,
63,
17626,
275,
298,
475,
63,
1235,
63,
493,
68,
2,
199,
3472,
63,
3243,
63,
8609,
275,
298,
1226,
63,
515,
63,
475,
63,
493,
2,
199,
3472,
63,
7916,
63,
5443,
275,
9638,
199,
19979,
26,
1182,
2423,
63,
1231,
6331,
15,
12186,
21792,
466,
15,
10545,
354,
93,
199,
4476,
26,
1182,
2423,
63,
1231,
6331,
15,
2782,
83,
21792,
4502,
14,
2662,
357,
14,
354,
15,
10545,
354,
93,
199,
624,
199,
199,
13289,
199,
3,
2334,
21401,
13841,
22547,
26,
2047,
9296,
1133,
1929,
370,
2621,
20561,
642,
2376,
367,
2897,
199,
13289,
199,
646,
295,
199,
646,
747,
199,
646,
984,
199,
646,
4011,
199,
646,
2838,
199,
646,
18354,
199,
646,
5549,
199,
646,
13290,
199,
199,
504,
14084,
20,
492,
5928,
199,
504,
14084,
20,
492,
10565,
199,
199,
893,
26,
272,
687,
2446,
63,
3806,
492,
32471,
63,
16031,
272,
687,
28516,
63,
7196,
492,
32471,
63,
30772,
199,
2590,
26,
272,
327,
370,
1736,
1380,
6230,
84,
7,
379,
10451,
367,
18042,
3031,
316,
272,
986,
199,
199,
13289,
199,
3,
13641,
83,
199,
13289,
199,
3472,
63,
3978,
63,
11139,
51,
275,
298,
1602,
12,
13344,
12,
772,
12,
9014,
12,
9014,
2,
421,
199,
13289,
199,
3,
5822,
199,
13289,
199,
533,
5244,
357,
17924,
1173,
1685,
8,
10901,
14,
49,
8458,
3186,
1685,
304,
272,
327,
12340,
687,
2929,
1318,
370,
376,
2225,
402,
314,
818,
1146,
909,
272,
636,
21178,
275,
359,
267,
791,
13654,
356,
283,
3160,
297,
283,
962,
356,
283,
31863,
63,
2743,
297,
283,
885,
356,
3260,
283,
10820,
356,
715,
1386,
267,
791,
13654,
356,
283,
2042,
297,
283,
962,
356,
283,
515,
297,
283,
885,
356,
3260,
283,
10820,
356,
756,
1386,
267,
791,
13654,
356,
283,
26748,
4005,
297,
283,
962,
356,
283,
1073,
63,
354,
297,
283,
885,
356,
3260,
283,
10820,
356,
756,
1386,
267,
791,
13654,
356,
283,
9440,
297,
283,
962,
356,
283,
2969,
297,
283,
885,
356,
3260,
283,
10820,
356,
715,
1386,
267,
791,
13654,
356,
283,
7443,
297,
283,
962,
356,
283,
4610,
297,
283,
885,
356,
3260,
283,
10820,
356,
715,
1386,
272,
1622,
339,
327,
1402,
3102,
272,
347,
636,
826,
721,
277,
12,
18172,
63,
2340,
12,
1676,
29,
403,
304,
267,
408,
1880,
624,
267,
1613,
8,
2662,
357,
17924,
1173,
1685,
12,
291,
2843,
826,
721,
1708,
9,
267,
291,
14,
2340,
275,
18172,
63,
2340,
267,
291,
14,
1725,
275,
942,
339,
347,
1962,
2353,
8,
277,
12,
1676,
29,
10901,
14,
49,
1685,
2681,
5109,
267,
408,
1955,
402,
4730,
365,
314,
1329,
402,
1584,
624,
267,
372,
822,
8,
277,
14,
1725,
9,
339,
347,
2763,
2353,
8,
277,
12,
1676,
29,
10901,
14,
49,
1685,
2681,
5109,
267,
408,
1955,
402,
4362,
365,
314,
1329,
402,
2323,
624,
267,
372,
822,
8,
277,
855,
21178,
9,
339,
347,
666,
8,
277,
12,
1478,
12,
4719,
29,
10901,
14,
4238,
14,
7687,
7422,
304,
267,
408,
765,
370,
372,
666,
367,
314,
7750,
2929,
11689,
315,
19227,
624,
267,
327,
2929,
4719,
12,
5965,
372,
314,
2256,
267,
340,
1478,
14,
18728,
342,
436,
4719,
508,
10565,
14,
4238,
14,
7687,
7422,
26,
288,
289,
275,
291,
14,
1725,
59,
1080,
14,
1143,
5106,
288,
1921,
275,
291,
855,
21178,
59,
1080,
14,
2301,
342,
2733,
962,
418,
288,
2203,
275,
2519,
8,
70,
12,
1921,
12,
488,
9,
288,
340,
2203,
365,
440,
488,
26,
355,
372,
10565,
14,
49,
12935,
8,
3292,
9,
288,
587,
26,
355,
372,
10565,
14,
49,
12935,
8,
277,
855,
21178,
59,
1080,
14,
2301,
342,
2733,
885,
1105,
267,
327,
440,
30944,
316,
3595,
642,
4719,
12,
2951,
372,
3866,
9854,
267,
372,
10565,
14,
49,
12935,
342,
339,
347,
1406,
1451,
8,
277,
12,
3420,
12,
16774,
12,
4719,
304,
267,
408,
1107,
666,
367,
1406,
1962,
624,
267,
340,
16774,
508,
10565,
14,
4238,
14,
19918,
436,
4719,
508,
10565,
14,
4238,
14,
7687,
7422,
26,
288,
372,
10565,
14,
49,
12935,
8,
277,
855,
21178,
59,
2792,
2733,
13654,
1105,
267,
372,
10565,
14,
49,
12935,
342,
339,
347,
663,
1451,
8,
277,
12,
1478,
12,
574,
12,
4719,
304,
267,
408,
409,
666,
367,
282,
1627,
1478,
624,
267,
340,
334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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
] |
greggparrish/musicscout
|
musicscout/utils.py
|
1
|
4665
|
from bs4 import BeautifulSoup
import os
import re
import requests
from mutagen import File
from mutagen.id3 import ID3NoHeaderError
from mutagen.easyid3 import EasyID3
from .config import Config
cf = Config().conf_vars()
MEDIA_SITES = ['youtu', 'soundcloud']
USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
class Utils:
def symlink_musicdir(self):
''' Cache has to be within mpd music dir to load tracks,
so symlink it if user didn't choose a path already in
their mpd music dir '''
try:
rel_path = cf['cache_dir'].split('/')[-1]
os.symlink(
cf['cache_dir'],
os.path.join(
cf['music_dir'],
rel_path))
except FileExistsError:
pass
def create_dir(self, path):
''' Used to create intial dirs, and genre dirs within cache '''
if not os.path.exists(path):
os.makedirs(path)
return path
def clean_cache(self):
''' Remove partial downloads '''
for root, subFolders, files in os.walk(cf['cache_dir']):
for file in files:
if '.part' in file:
os.remove(os.path.join(root, file))
def format_link(self, link):
if 'recaptcha' in link or 'widgets.wp.com' in link:
fl = False
elif 'youtu' in link:
fl = link.split('?')[0]
elif 'soundcloud' in link:
if 'player/?url' in link:
fl = "https{}".format(re.search(r'https(.*?)\&', link).group(1).replace('%2F', '/'))
else:
fl = "https://api{}".format(link.split('api')[1].replace('%2F', '/'))
elif 'redditmedia' in link:
fl = "https:" + link
else:
fl = link
return fl.strip()
def reddit_links(self, p):
links = []
ll = BeautifulSoup(p['content'][0]['value'], 'lxml')
for l in ll.find_all('a'):
if any(m in l.get('href') for m in MEDIA_SITES):
links.append(l.get('href'))
return links
def tumblr_links(self, p):
links = []
r = BeautifulSoup(p['summary'], 'lxml')
frames = r.find_all('iframe')
for f in frames:
src = f.get('src')
if src:
links.append(f.get('src'))
return links
def bandcamp_embed(self, link, embed):
if 'EmbeddedPlayer' in link or 'VideoEmbed' in link:
if 'http' not in link:
link = 'https:' + link
try:
fl = re.search(r'href=[\'"]?([^\'" >]+)', str(embed)).groups()[0]
except Exception:
player = BeautifulSoup(requests.get(link, headers={"user-agent": USER_AGENT}).content, 'lxml')
try:
fl = player.find('a', {'class': 'logo'}).get('href')
except Exception:
fl = False
return fl
def blog_links(self, p):
links = []
try:
r = BeautifulSoup(requests.get(p.link, headers={"user-agent": USER_AGENT}).content, 'lxml')
except requests.exceptions.RequestException as e:
print(e)
if r:
frames = r.find_all('iframe')
for f in frames:
if f.has_attr('src'):
if 'bandcamp' in f['src']:
bfl = self.bandcamp_embed(f['src'], f)
if bfl is not False:
links.append(bfl)
elif any(m in f['src'] for m in MEDIA_SITES):
links.append(self.format_link(f['src']))
return links
def add_metadata(self, path, link, genre):
if os.path.isfile(path):
fn = path.split('/')[-1]
vi = fn.split('__')[0]
vidinfo = re.sub(r"[\(\[].*?[\)\]]", "", vi)
if '-' in vidinfo:
artist = vidinfo.split('-')[0]
fulltitle = vidinfo.split('-')[1]
title = fulltitle.split('__')[0]
else:
title = vidinfo
artist = ''
if '?' in link:
link = link.split('?')[0]
try:
song = EasyID3(path)
except ID3NoHeaderError:
song = File(path, easy=True)
EasyID3.RegisterTextKey('comment', 'COMM')
song['title'] = title
song['artist'] = artist
song['genre'] = genre
song['comment'] = link
song.save()
|
unlicense
|
[
504,
9922,
20,
492,
17132,
199,
646,
747,
199,
646,
295,
199,
646,
4145,
199,
199,
504,
8567,
24758,
492,
3814,
199,
504,
8567,
24758,
14,
344,
19,
492,
2870,
19,
1944,
26599,
199,
504,
8567,
24758,
14,
13581,
344,
19,
492,
18951,
998,
19,
199,
199,
504,
1275,
888,
492,
4094,
199,
199,
2177,
275,
4094,
1252,
2190,
63,
2936,
342,
199,
13669,
63,
51,
649,
654,
275,
788,
89,
548,
85,
297,
283,
14990,
4091,
418,
199,
3791,
63,
14565,
275,
283,
22285,
15,
21,
14,
16,
334,
56,
845,
27,
10130,
671,
1184,
63,
772,
9,
21257,
21666,
15,
24416,
14,
1344,
334,
43,
4943,
12,
2839,
30506,
9,
16776,
15,
2010,
14,
16,
14,
8551,
25,
14,
6019,
428,
2756,
759,
15,
24416,
14,
1344,
7,
421,
199,
533,
17397,
26,
272,
347,
15296,
63,
20544,
694,
8,
277,
304,
267,
1449,
11977,
965,
370,
506,
4453,
6118,
68,
30891,
2935,
370,
2248,
18917,
12,
288,
880,
15296,
652,
340,
922,
9980,
1133,
11496,
282,
931,
2575,
315,
288,
3932,
6118,
68,
30891,
2935,
1449,
267,
862,
26,
288,
4668,
63,
515,
275,
3980,
459,
1637,
63,
694,
2278,
1294,
25804,
17,
61,
288,
747,
14,
13380,
8,
355,
3980,
459,
1637,
63,
694,
995,
355,
747,
14,
515,
14,
904,
8,
490,
3980,
459,
20544,
63,
694,
995,
490,
4668,
63,
515,
430,
267,
871,
3814,
23839,
26,
288,
986,
339,
347,
1218,
63,
694,
8,
277,
12,
931,
304,
267,
1449,
8051,
370,
1218,
315,
1009,
7606,
12,
436,
28749,
7606,
4453,
2581,
1449,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
304,
288,
747,
14,
8347,
8,
515,
9,
267,
372,
931,
339,
347,
3633,
63,
1637,
8,
277,
304,
267,
1449,
5852,
7417,
28242,
1449,
267,
367,
1738,
12,
1007,
7850,
83,
12,
1584,
315,
747,
14,
7757,
8,
2177,
459,
1637,
63,
694,
9090,
288,
367,
570,
315,
1584,
26,
355,
340,
1987,
2064,
7,
315,
570,
26,
490,
747,
14,
2168,
8,
736,
14,
515,
14,
904,
8,
1231,
12,
570,
430,
339,
347,
1475,
63,
1073,
8,
277,
12,
2142,
304,
267,
340,
283,
2761,
6182,
9518,
7,
315,
2142,
503,
283,
8583,
14,
14649,
14,
957,
7,
315,
2142,
26,
288,
2717,
275,
756,
267,
916,
283,
89,
548,
85,
7,
315,
2142,
26,
288,
2717,
275,
2142,
14,
1294,
360,
31,
5832,
16,
61,
267,
916,
283,
14990,
4091,
7,
315,
2142,
26,
288,
340,
283,
6147,
10197,
633,
7,
315,
2142,
26,
355,
2717,
275,
298,
2859,
13536,
908,
8,
264,
14,
1733,
8,
82,
7,
2859,
17140,
2862,
16749,
2142,
680,
923,
8,
17,
680,
1814,
3508,
18,
38,
297,
1994,
1333,
288,
587,
26,
355,
2717,
275,
298,
2859,
921,
1246,
13536,
908,
8,
1073,
14,
1294,
360,
1246,
5832,
17,
1055,
1814,
3508,
18,
38,
297,
1994,
1333,
267,
916,
283,
18374,
4603,
7,
315,
2142,
26,
288,
2717,
275,
298,
2859,
5424,
435,
2142,
267,
587,
26,
288,
2717,
275,
2142,
267,
372,
2717,
14,
1913,
342,
339,
347,
8992,
1741,
63,
4614,
8,
277,
12,
299,
304,
267,
6220,
275,
942,
267,
18338,
275,
17132,
8,
80,
459,
1317,
3488,
16,
2733,
585,
995,
283,
22899,
358,
267,
367,
634,
315,
18338,
14,
1623,
63,
452,
360,
65,
735,
288,
340,
1263,
8,
77,
315,
634,
14,
362,
360,
6399,
358,
367,
333,
315,
31460,
63,
51,
649,
654,
304,
355,
6220,
14,
740,
8,
76,
14,
362,
360,
6399,
1333,
267,
372,
6220,
339,
347,
307,
453,
3345,
82,
63,
4614,
8,
277,
12,
299,
304,
267,
6220,
275,
942,
267,
519,
275,
17132,
8,
80,
459,
4705,
995,
283,
22899,
358,
267,
11223,
275,
519,
14,
1623,
63,
452,
360,
20052,
358,
267,
367,
289,
315,
11223,
26,
288,
2928,
275,
289,
14,
362,
360,
2164,
358,
288,
340,
2928,
26,
355,
6220,
14,
740,
8,
70,
14,
362,
360,
2164,
1333,
267,
372,
6220,
339,
347,
10981,
20290,
63,
6427,
8,
277,
12,
2142,
12,
6441,
304,
267,
340,
283,
27395,
10921,
7,
315,
2142,
503,
283,
9166,
13200,
7,
315,
2142,
26,
288,
340,
283,
1014,
7,
440,
315,
2142,
26,
355,
2142,
275,
283,
2859,
4881,
435,
2142,
288,
862,
26,
355,
2717,
275,
295,
14,
1733,
8,
82,
7,
6399,
1524,
3985,
937,
31,
7059,
3985,
2,
690,
28798,
620,
8,
6427,
4992,
2634,
3430,
16,
61,
288,
871,
2186,
26,
355,
7748,
275,
17132,
8,
6615,
14,
362,
8,
1073,
12,
2323,
8871,
751,
13,
4054,
582,
13044,
63,
14565,
21385,
1317,
12,
283,
22899,
358,
355,
862,
26,
490,
2717,
275,
7748,
14,
1623,
360,
65,
297,
791,
533,
356,
283,
9733,
936,
680,
362,
360,
6399,
358,
355,
871,
2186,
26,
490,
2717,
275,
756,
267,
372,
2717,
339,
347,
19936,
63,
4614,
8,
277,
12,
299,
304,
267,
6220,
275,
942,
267,
862,
26,
288,
519,
275,
17132,
8,
6615,
14,
362,
8,
80,
14,
1073,
12,
2323,
8871,
751,
13,
4054,
582,
13044,
63,
14565,
21385,
1317,
12,
283,
22899,
358,
267,
871,
4145,
14,
3924,
14,
28724,
465,
325,
26,
288,
870,
8,
69,
9,
267,
340,
519,
26,
288,
11223,
275,
519,
14,
1623,
63,
452,
360,
20052,
358,
288,
367,
289,
315,
11223,
26,
355,
340,
289,
14,
1989,
63,
962,
360,
2164,
735,
490,
340,
283,
7877,
20290,
7,
315,
289,
459,
2164,
2565,
717,
330,
2327,
275,
291,
14,
7877,
20290,
63,
6427,
8,
70,
459,
2164,
995,
289,
9,
717,
340,
330,
2327,
365,
440,
756,
26,
1169,
6220,
14,
740,
8,
66,
2327,
9,
490,
916,
1263,
8,
77,
315,
289,
459,
2164,
418,
367,
333,
315,
31460,
63,
51,
649,
654,
304,
717,
6220,
14,
740,
8,
277,
14,
908,
63,
1073,
8,
70,
459,
2164,
5156,
267,
372,
6220,
339,
347,
1050,
63,
2343,
8,
277,
12,
931,
12,
2142,
12,
28749,
304,
267,
340,
747,
14,
515,
14,
6292,
8,
515,
304,
288,
4325,
275,
931,
14,
1294,
25804,
17,
61,
288,
1321,
275,
4325,
14,
1294,
10714,
5832,
16,
61,
288,
27767,
815,
275,
295,
14,
954,
8,
82,
29354,
2961
] |
[
9922,
20,
492,
17132,
199,
646,
747,
199,
646,
295,
199,
646,
4145,
199,
199,
504,
8567,
24758,
492,
3814,
199,
504,
8567,
24758,
14,
344,
19,
492,
2870,
19,
1944,
26599,
199,
504,
8567,
24758,
14,
13581,
344,
19,
492,
18951,
998,
19,
199,
199,
504,
1275,
888,
492,
4094,
199,
199,
2177,
275,
4094,
1252,
2190,
63,
2936,
342,
199,
13669,
63,
51,
649,
654,
275,
788,
89,
548,
85,
297,
283,
14990,
4091,
418,
199,
3791,
63,
14565,
275,
283,
22285,
15,
21,
14,
16,
334,
56,
845,
27,
10130,
671,
1184,
63,
772,
9,
21257,
21666,
15,
24416,
14,
1344,
334,
43,
4943,
12,
2839,
30506,
9,
16776,
15,
2010,
14,
16,
14,
8551,
25,
14,
6019,
428,
2756,
759,
15,
24416,
14,
1344,
7,
421,
199,
533,
17397,
26,
272,
347,
15296,
63,
20544,
694,
8,
277,
304,
267,
1449,
11977,
965,
370,
506,
4453,
6118,
68,
30891,
2935,
370,
2248,
18917,
12,
288,
880,
15296,
652,
340,
922,
9980,
1133,
11496,
282,
931,
2575,
315,
288,
3932,
6118,
68,
30891,
2935,
1449,
267,
862,
26,
288,
4668,
63,
515,
275,
3980,
459,
1637,
63,
694,
2278,
1294,
25804,
17,
61,
288,
747,
14,
13380,
8,
355,
3980,
459,
1637,
63,
694,
995,
355,
747,
14,
515,
14,
904,
8,
490,
3980,
459,
20544,
63,
694,
995,
490,
4668,
63,
515,
430,
267,
871,
3814,
23839,
26,
288,
986,
339,
347,
1218,
63,
694,
8,
277,
12,
931,
304,
267,
1449,
8051,
370,
1218,
315,
1009,
7606,
12,
436,
28749,
7606,
4453,
2581,
1449,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
304,
288,
747,
14,
8347,
8,
515,
9,
267,
372,
931,
339,
347,
3633,
63,
1637,
8,
277,
304,
267,
1449,
5852,
7417,
28242,
1449,
267,
367,
1738,
12,
1007,
7850,
83,
12,
1584,
315,
747,
14,
7757,
8,
2177,
459,
1637,
63,
694,
9090,
288,
367,
570,
315,
1584,
26,
355,
340,
1987,
2064,
7,
315,
570,
26,
490,
747,
14,
2168,
8,
736,
14,
515,
14,
904,
8,
1231,
12,
570,
430,
339,
347,
1475,
63,
1073,
8,
277,
12,
2142,
304,
267,
340,
283,
2761,
6182,
9518,
7,
315,
2142,
503,
283,
8583,
14,
14649,
14,
957,
7,
315,
2142,
26,
288,
2717,
275,
756,
267,
916,
283,
89,
548,
85,
7,
315,
2142,
26,
288,
2717,
275,
2142,
14,
1294,
360,
31,
5832,
16,
61,
267,
916,
283,
14990,
4091,
7,
315,
2142,
26,
288,
340,
283,
6147,
10197,
633,
7,
315,
2142,
26,
355,
2717,
275,
298,
2859,
13536,
908,
8,
264,
14,
1733,
8,
82,
7,
2859,
17140,
2862,
16749,
2142,
680,
923,
8,
17,
680,
1814,
3508,
18,
38,
297,
1994,
1333,
288,
587,
26,
355,
2717,
275,
298,
2859,
921,
1246,
13536,
908,
8,
1073,
14,
1294,
360,
1246,
5832,
17,
1055,
1814,
3508,
18,
38,
297,
1994,
1333,
267,
916,
283,
18374,
4603,
7,
315,
2142,
26,
288,
2717,
275,
298,
2859,
5424,
435,
2142,
267,
587,
26,
288,
2717,
275,
2142,
267,
372,
2717,
14,
1913,
342,
339,
347,
8992,
1741,
63,
4614,
8,
277,
12,
299,
304,
267,
6220,
275,
942,
267,
18338,
275,
17132,
8,
80,
459,
1317,
3488,
16,
2733,
585,
995,
283,
22899,
358,
267,
367,
634,
315,
18338,
14,
1623,
63,
452,
360,
65,
735,
288,
340,
1263,
8,
77,
315,
634,
14,
362,
360,
6399,
358,
367,
333,
315,
31460,
63,
51,
649,
654,
304,
355,
6220,
14,
740,
8,
76,
14,
362,
360,
6399,
1333,
267,
372,
6220,
339,
347,
307,
453,
3345,
82,
63,
4614,
8,
277,
12,
299,
304,
267,
6220,
275,
942,
267,
519,
275,
17132,
8,
80,
459,
4705,
995,
283,
22899,
358,
267,
11223,
275,
519,
14,
1623,
63,
452,
360,
20052,
358,
267,
367,
289,
315,
11223,
26,
288,
2928,
275,
289,
14,
362,
360,
2164,
358,
288,
340,
2928,
26,
355,
6220,
14,
740,
8,
70,
14,
362,
360,
2164,
1333,
267,
372,
6220,
339,
347,
10981,
20290,
63,
6427,
8,
277,
12,
2142,
12,
6441,
304,
267,
340,
283,
27395,
10921,
7,
315,
2142,
503,
283,
9166,
13200,
7,
315,
2142,
26,
288,
340,
283,
1014,
7,
440,
315,
2142,
26,
355,
2142,
275,
283,
2859,
4881,
435,
2142,
288,
862,
26,
355,
2717,
275,
295,
14,
1733,
8,
82,
7,
6399,
1524,
3985,
937,
31,
7059,
3985,
2,
690,
28798,
620,
8,
6427,
4992,
2634,
3430,
16,
61,
288,
871,
2186,
26,
355,
7748,
275,
17132,
8,
6615,
14,
362,
8,
1073,
12,
2323,
8871,
751,
13,
4054,
582,
13044,
63,
14565,
21385,
1317,
12,
283,
22899,
358,
355,
862,
26,
490,
2717,
275,
7748,
14,
1623,
360,
65,
297,
791,
533,
356,
283,
9733,
936,
680,
362,
360,
6399,
358,
355,
871,
2186,
26,
490,
2717,
275,
756,
267,
372,
2717,
339,
347,
19936,
63,
4614,
8,
277,
12,
299,
304,
267,
6220,
275,
942,
267,
862,
26,
288,
519,
275,
17132,
8,
6615,
14,
362,
8,
80,
14,
1073,
12,
2323,
8871,
751,
13,
4054,
582,
13044,
63,
14565,
21385,
1317,
12,
283,
22899,
358,
267,
871,
4145,
14,
3924,
14,
28724,
465,
325,
26,
288,
870,
8,
69,
9,
267,
340,
519,
26,
288,
11223,
275,
519,
14,
1623,
63,
452,
360,
20052,
358,
288,
367,
289,
315,
11223,
26,
355,
340,
289,
14,
1989,
63,
962,
360,
2164,
735,
490,
340,
283,
7877,
20290,
7,
315,
289,
459,
2164,
2565,
717,
330,
2327,
275,
291,
14,
7877,
20290,
63,
6427,
8,
70,
459,
2164,
995,
289,
9,
717,
340,
330,
2327,
365,
440,
756,
26,
1169,
6220,
14,
740,
8,
66,
2327,
9,
490,
916,
1263,
8,
77,
315,
289,
459,
2164,
418,
367,
333,
315,
31460,
63,
51,
649,
654,
304,
717,
6220,
14,
740,
8,
277,
14,
908,
63,
1073,
8,
70,
459,
2164,
5156,
267,
372,
6220,
339,
347,
1050,
63,
2343,
8,
277,
12,
931,
12,
2142,
12,
28749,
304,
267,
340,
747,
14,
515,
14,
6292,
8,
515,
304,
288,
4325,
275,
931,
14,
1294,
25804,
17,
61,
288,
1321,
275,
4325,
14,
1294,
10714,
5832,
16,
61,
288,
27767,
815,
275,
295,
14,
954,
8,
82,
29354,
2961,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
grounduphq/stexchange
|
docs/conf.py
|
1
|
7758
|
# -*- coding: utf-8 -*-
#
# stexchange documentation build configuration file, created by
# sphinx-quickstart on Sun Feb 17 11:46:20 2013.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = []
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'stexchange'
copyright = u'2013, ChangeMyName'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.1'
# The full version, including alpha/beta/rc tags.
release = '0.1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'stexchangedoc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'stexchange.tex', u'stexchange Documentation',
u'ChangeToMyName', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'stexchange', u'stexchange Documentation',
[u'ChangeToMyName'], 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'stexchange', u'stexchange Documentation',
u'ChangeToMyName', 'stexchange', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
308,
3858,
1461,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
25625,
21141,
5557,
4119,
26,
2466,
26,
1165,
6171,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
10065,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
942,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
1159,
3858,
1461,
7,
199,
7307,
275,
399,
7,
6965,
12,
7743,
5713,
985,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
16,
14,
17,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
16,
14,
17,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
3671,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
5473,
63,
7435,
275,
4044,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
1360,
63,
7915,
275,
283,
885,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
675,
465,
29139,
402,
314,
199,
3,
9149,
14,
221,
961,
570,
1077,
506,
282,
5417,
7016,
570,
17048,
12802,
9,
3769,
3193,
88,
975,
503,
4337,
88,
708,
199,
3,
11094,
7031,
14,
199,
3,
1360,
63,
22229,
275,
488,
199,
199,
3,
2654
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
308,
3858,
1461,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
25625,
21141,
5557,
4119,
26,
2466,
26,
1165,
6171,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
10065,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
942,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
1159,
3858,
1461,
7,
199,
7307,
275,
399,
7,
6965,
12,
7743,
5713,
985,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
16,
14,
17,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
16,
14,
17,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
3671,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
5473,
63,
7435,
275,
4044,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
1360,
63,
7915,
275,
283,
885,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
675,
465,
29139,
402,
314,
199,
3,
9149,
14,
221,
961,
570,
1077,
506,
282,
5417,
7016,
570,
17048,
12802,
9,
3769,
3193,
88,
975,
503,
4337,
88,
708,
199,
3,
11094,
7031,
14,
199,
3,
1360,
63,
22229,
275,
488,
199,
199,
3,
2654,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
PongPi/isl-odoo
|
addons/portal_project/__openerp__.py
|
380
|
1686
|
# -*- 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': 'Portal Project',
'version': '0.1',
'category': 'Tools',
'complexity': 'easy',
'description': """
This module adds project menu and features (tasks) to your portal if project and portal are installed.
======================================================================================================
""",
'author': 'OpenERP SA',
'depends': ['project', 'portal'],
'data': [
'security/portal_security.xml',
'security/ir.model.access.csv',
'portal_project_view.xml',
],
'demo': [],
'installable': True,
'auto_install': True,
'category': 'Hidden',
}
# 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,
26708,
7290,
297,
272,
283,
1023,
356,
283,
16,
14,
17,
297,
272,
283,
3710,
356,
283,
11654,
297,
272,
283,
5254,
1209,
356,
283,
13581,
297,
272,
283,
1802,
356,
408,
199,
2765,
859,
9584,
2199,
6269,
436,
4534,
334,
5054,
9,
370,
2195,
18428,
340,
2199,
436,
18428,
787,
4903,
14,
199,
5695,
2486,
23476,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
8912,
356,
788,
1715,
297,
283,
8707,
995,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
8707,
63,
4416,
14,
1652,
297,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
8707,
63,
1715,
63,
1345,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
715,
12,
272,
283,
3710,
356,
283,
14983,
297,
199,
93,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
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,
26708,
7290,
297,
272,
283,
1023,
356,
283,
16,
14,
17,
297,
272,
283,
3710,
356,
283,
11654,
297,
272,
283,
5254,
1209,
356,
283,
13581,
297,
272,
283,
1802,
356,
408,
199,
2765,
859,
9584,
2199,
6269,
436,
4534,
334,
5054,
9,
370,
2195,
18428,
340,
2199,
436,
18428,
787,
4903,
14,
199,
5695,
2486,
23476,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
8912,
356,
788,
1715,
297,
283,
8707,
995,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
8707,
63,
4416,
14,
1652,
297,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
8707,
63,
1715,
63,
1345,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
715,
12,
272,
283,
3710,
356,
283,
14983,
297,
199,
93,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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
0,
0,
0,
0,
0
] |
rbalda/neural_ocr
|
env/lib/python2.7/site-packages/django/views/decorators/vary.py
|
586
|
1200
|
from functools import wraps
from django.utils.cache import patch_vary_headers
from django.utils.decorators import available_attrs
def vary_on_headers(*headers):
"""
A view decorator that adds the specified headers to the Vary header of the
response. Usage:
@vary_on_headers('Cookie', 'Accept-language')
def index(request):
...
Note that the header names are not case-sensitive.
"""
def decorator(func):
@wraps(func, assigned=available_attrs(func))
def inner_func(*args, **kwargs):
response = func(*args, **kwargs)
patch_vary_headers(response, headers)
return response
return inner_func
return decorator
def vary_on_cookie(func):
"""
A view decorator that adds "Cookie" to the Vary header of a response. This
indicates that a page's contents depends on cookies. Usage:
@vary_on_cookie
def index(request):
...
"""
@wraps(func, assigned=available_attrs(func))
def inner_func(*args, **kwargs):
response = func(*args, **kwargs)
patch_vary_headers(response, ('Cookie',))
return response
return inner_func
|
mit
|
[
504,
9143,
492,
14018,
199,
199,
504,
1639,
14,
1208,
14,
1637,
492,
3371,
63,
21989,
63,
2139,
199,
504,
1639,
14,
1208,
14,
11582,
492,
2808,
63,
3288,
421,
199,
318,
17083,
63,
265,
63,
2139,
2031,
2139,
304,
272,
408,
272,
437,
2455,
7531,
626,
9584,
314,
2013,
2323,
370,
314,
812,
695,
1406,
402,
314,
272,
1177,
14,
11028,
26,
10817,
768,
21989,
63,
265,
63,
2139,
360,
7810,
297,
283,
8422,
13,
3671,
358,
2126,
347,
1478,
8,
1069,
304,
1779,
2263,
339,
3390,
626,
314,
1406,
1561,
787,
440,
1930,
13,
7361,
14,
272,
408,
272,
347,
7531,
8,
1532,
304,
267,
768,
13582,
8,
1532,
12,
7943,
29,
4561,
63,
3288,
8,
1532,
430,
267,
347,
6506,
63,
1532,
2031,
589,
12,
1011,
958,
304,
288,
1177,
275,
2562,
2031,
589,
12,
1011,
958,
9,
288,
3371,
63,
21989,
63,
2139,
8,
1310,
12,
2323,
9,
288,
372,
1177,
267,
372,
6506,
63,
1532,
272,
372,
7531,
421,
199,
318,
17083,
63,
265,
63,
5306,
8,
1532,
304,
272,
408,
272,
437,
2455,
7531,
626,
9584,
298,
7810,
2,
370,
314,
812,
695,
1406,
402,
282,
1177,
14,
961,
272,
9126,
626,
282,
2034,
1159,
4072,
8350,
641,
10049,
14,
11028,
26,
398,
768,
21989,
63,
265,
63,
5306,
267,
347,
1478,
8,
1069,
304,
288,
2263,
272,
408,
272,
768,
13582,
8,
1532,
12,
7943,
29,
4561,
63,
3288,
8,
1532,
430,
272,
347,
6506,
63,
1532,
2031,
589,
12,
1011,
958,
304,
267,
1177,
275,
2562,
2031,
589,
12,
1011,
958,
9,
267,
3371,
63,
21989,
63,
2139,
8,
1310,
12,
661,
7810,
16829,
267,
372,
1177,
272,
372,
6506,
63,
1532,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
9143,
492,
14018,
199,
199,
504,
1639,
14,
1208,
14,
1637,
492,
3371,
63,
21989,
63,
2139,
199,
504,
1639,
14,
1208,
14,
11582,
492,
2808,
63,
3288,
421,
199,
318,
17083,
63,
265,
63,
2139,
2031,
2139,
304,
272,
408,
272,
437,
2455,
7531,
626,
9584,
314,
2013,
2323,
370,
314,
812,
695,
1406,
402,
314,
272,
1177,
14,
11028,
26,
10817,
768,
21989,
63,
265,
63,
2139,
360,
7810,
297,
283,
8422,
13,
3671,
358,
2126,
347,
1478,
8,
1069,
304,
1779,
2263,
339,
3390,
626,
314,
1406,
1561,
787,
440,
1930,
13,
7361,
14,
272,
408,
272,
347,
7531,
8,
1532,
304,
267,
768,
13582,
8,
1532,
12,
7943,
29,
4561,
63,
3288,
8,
1532,
430,
267,
347,
6506,
63,
1532,
2031,
589,
12,
1011,
958,
304,
288,
1177,
275,
2562,
2031,
589,
12,
1011,
958,
9,
288,
3371,
63,
21989,
63,
2139,
8,
1310,
12,
2323,
9,
288,
372,
1177,
267,
372,
6506,
63,
1532,
272,
372,
7531,
421,
199,
318,
17083,
63,
265,
63,
5306,
8,
1532,
304,
272,
408,
272,
437,
2455,
7531,
626,
9584,
298,
7810,
2,
370,
314,
812,
695,
1406,
402,
282,
1177,
14,
961,
272,
9126,
626,
282,
2034,
1159,
4072,
8350,
641,
10049,
14,
11028,
26,
398,
768,
21989,
63,
265,
63,
5306,
267,
347,
1478,
8,
1069,
304,
288,
2263,
272,
408,
272,
768,
13582,
8,
1532,
12,
7943,
29,
4561,
63,
3288,
8,
1532,
430,
272,
347,
6506,
63,
1532,
2031,
589,
12,
1011,
958,
304,
267,
1177,
275,
2562,
2031,
589,
12,
1011,
958,
9,
267,
3371,
63,
21989,
63,
2139,
8,
1310,
12,
661,
7810,
16829,
267,
372,
1177,
272,
372,
6506,
63,
1532,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
dex4er/django
|
django/contrib/admin/templatetags/admin_modify.py
|
106
|
2356
|
from django import template
register = template.Library()
@register.inclusion_tag('admin/prepopulated_fields_js.html', takes_context=True)
def prepopulated_fields_js(context):
"""
Creates a list of prepopulated_fields that should render Javascript for
the prepopulated fields for both the admin form and inlines.
"""
prepopulated_fields = []
if context['add'] and 'adminform' in context:
prepopulated_fields.extend(context['adminform'].prepopulated_fields)
if 'inline_admin_formsets' in context:
for inline_admin_formset in context['inline_admin_formsets']:
for inline_admin_form in inline_admin_formset:
if inline_admin_form.original is None:
prepopulated_fields.extend(inline_admin_form.prepopulated_fields)
context.update({'prepopulated_fields': prepopulated_fields})
return context
@register.inclusion_tag('admin/submit_line.html', takes_context=True)
def submit_row(context):
"""
Displays the row of buttons for delete and save.
"""
opts = context['opts']
change = context['change']
is_popup = context['is_popup']
save_as = context['save_as']
ctx = {
'opts': opts,
'show_delete_link': (not is_popup and context['has_delete_permission']
and change and context.get('show_delete', True)),
'show_save_as_new': not is_popup and change and save_as,
'show_save_and_add_another': context['has_add_permission'] and
not is_popup and (not save_as or context['add']),
'show_save_and_continue': not is_popup and context['has_change_permission'],
'is_popup': is_popup,
'show_save': True,
'preserved_filters': context.get('preserved_filters'),
}
if context.get('original') is not None:
ctx['original'] = context['original']
return ctx
@register.filter
def cell_count(inline_admin_form):
"""Returns the number of cells used in a tabular inline"""
count = 1 # Hidden cell with hidden 'id' field
for fieldset in inline_admin_form:
# Loop through all the fields (one per cell)
for line in fieldset:
for field in line:
count += 1
if inline_admin_form.formset.can_delete:
# Delete checkbox
count += 1
return count
|
bsd-3-clause
|
[
504,
1639,
492,
1978,
199,
199,
2683,
275,
1978,
14,
7424,
342,
199,
199,
32,
2683,
14,
24265,
63,
1450,
360,
2113,
15,
657,
21440,
63,
955,
63,
3596,
14,
1360,
297,
6181,
63,
1100,
29,
549,
9,
199,
318,
876,
21440,
63,
955,
63,
3596,
8,
1100,
304,
272,
408,
272,
10560,
282,
769,
402,
876,
21440,
63,
955,
626,
1077,
3795,
31861,
367,
272,
314,
876,
21440,
1504,
367,
3865,
314,
4628,
1824,
436,
29177,
14,
272,
408,
272,
876,
21440,
63,
955,
275,
942,
272,
340,
1067,
459,
525,
418,
436,
283,
2113,
964,
7,
315,
1067,
26,
267,
876,
21440,
63,
955,
14,
2880,
8,
1100,
459,
2113,
964,
2278,
657,
21440,
63,
955,
9,
272,
340,
283,
6460,
63,
2113,
63,
31033,
7,
315,
1067,
26,
267,
367,
8308,
63,
2113,
63,
10724,
315,
1067,
459,
6460,
63,
2113,
63,
31033,
2565,
288,
367,
8308,
63,
2113,
63,
964,
315,
8308,
63,
2113,
63,
10724,
26,
355,
340,
8308,
63,
2113,
63,
964,
14,
5043,
365,
488,
26,
490,
876,
21440,
63,
955,
14,
2880,
8,
6460,
63,
2113,
63,
964,
14,
657,
21440,
63,
955,
9,
272,
1067,
14,
873,
3252,
657,
21440,
63,
955,
356,
876,
21440,
63,
955,
1552,
272,
372,
1067,
199,
199,
32,
2683,
14,
24265,
63,
1450,
360,
2113,
15,
7275,
63,
604,
14,
1360,
297,
6181,
63,
1100,
29,
549,
9,
199,
318,
11482,
63,
1143,
8,
1100,
304,
272,
408,
272,
28750,
314,
1962,
402,
15766,
367,
3145,
436,
3354,
14,
272,
408,
272,
3999,
275,
1067,
459,
3291,
418,
272,
1570,
275,
1067,
459,
1461,
418,
272,
365,
63,
16020,
275,
1067,
459,
374,
63,
16020,
418,
272,
3354,
63,
305,
275,
1067,
459,
2117,
63,
305,
418,
272,
4027,
275,
469,
267,
283,
3291,
356,
3999,
12,
267,
283,
2384,
63,
1807,
63,
1073,
356,
334,
1397,
365,
63,
16020,
436,
1067,
459,
1989,
63,
1807,
63,
5693,
418,
2892,
436,
1570,
436,
1067,
14,
362,
360,
2384,
63,
1807,
297,
715,
1826,
267,
283,
2384,
63,
2117,
63,
305,
63,
1222,
356,
440,
365,
63,
16020,
436,
1570,
436,
3354,
63,
305,
12,
267,
283,
2384,
63,
2117,
63,
460,
63,
525,
63,
13565,
356,
1067,
459,
1989,
63,
525,
63,
5693,
418,
436,
1169,
440,
365,
63,
16020,
436,
334,
1397,
3354,
63,
305,
503,
1067,
459,
525,
3815,
267,
283,
2384,
63,
2117,
63,
460,
63,
6958,
356,
440,
365,
63,
16020,
436,
1067,
459,
1989,
63,
1461,
63,
5693,
995,
267,
283,
374,
63,
16020,
356,
365,
63,
16020,
12,
267,
283,
2384,
63,
2117,
356,
715,
12,
267,
283,
32104,
63,
4273,
356,
1067,
14,
362,
360,
32104,
63,
4273,
659,
272,
789,
272,
340,
1067,
14,
362,
360,
5043,
358,
365,
440,
488,
26,
267,
4027,
459,
5043,
418,
275,
1067,
459,
5043,
418,
272,
372,
4027,
199,
199,
32,
2683,
14,
1541,
199,
318,
4917,
63,
835,
8,
6460,
63,
2113,
63,
964,
304,
272,
408,
3407,
314,
1329,
402,
10106,
1202,
315,
282,
5174,
2238,
8308,
624,
272,
2338,
275,
413,
327,
26401,
4917,
543,
8752,
283,
344,
7,
901,
272,
367,
901,
409,
315,
8308,
63,
2113,
63,
964,
26,
267,
327,
18175,
4012,
1006,
314,
1504,
334,
368,
1126,
4917,
9,
267,
367,
1004,
315,
901,
409,
26,
288,
367,
901,
315,
1004,
26,
355,
2338,
847,
413,
272,
340,
8308,
63,
2113,
63,
964,
14,
10724,
14,
2425,
63,
1807,
26,
267,
327,
8496,
24190,
267,
2338,
847,
413,
272,
372,
2338,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
492,
1978,
199,
199,
2683,
275,
1978,
14,
7424,
342,
199,
199,
32,
2683,
14,
24265,
63,
1450,
360,
2113,
15,
657,
21440,
63,
955,
63,
3596,
14,
1360,
297,
6181,
63,
1100,
29,
549,
9,
199,
318,
876,
21440,
63,
955,
63,
3596,
8,
1100,
304,
272,
408,
272,
10560,
282,
769,
402,
876,
21440,
63,
955,
626,
1077,
3795,
31861,
367,
272,
314,
876,
21440,
1504,
367,
3865,
314,
4628,
1824,
436,
29177,
14,
272,
408,
272,
876,
21440,
63,
955,
275,
942,
272,
340,
1067,
459,
525,
418,
436,
283,
2113,
964,
7,
315,
1067,
26,
267,
876,
21440,
63,
955,
14,
2880,
8,
1100,
459,
2113,
964,
2278,
657,
21440,
63,
955,
9,
272,
340,
283,
6460,
63,
2113,
63,
31033,
7,
315,
1067,
26,
267,
367,
8308,
63,
2113,
63,
10724,
315,
1067,
459,
6460,
63,
2113,
63,
31033,
2565,
288,
367,
8308,
63,
2113,
63,
964,
315,
8308,
63,
2113,
63,
10724,
26,
355,
340,
8308,
63,
2113,
63,
964,
14,
5043,
365,
488,
26,
490,
876,
21440,
63,
955,
14,
2880,
8,
6460,
63,
2113,
63,
964,
14,
657,
21440,
63,
955,
9,
272,
1067,
14,
873,
3252,
657,
21440,
63,
955,
356,
876,
21440,
63,
955,
1552,
272,
372,
1067,
199,
199,
32,
2683,
14,
24265,
63,
1450,
360,
2113,
15,
7275,
63,
604,
14,
1360,
297,
6181,
63,
1100,
29,
549,
9,
199,
318,
11482,
63,
1143,
8,
1100,
304,
272,
408,
272,
28750,
314,
1962,
402,
15766,
367,
3145,
436,
3354,
14,
272,
408,
272,
3999,
275,
1067,
459,
3291,
418,
272,
1570,
275,
1067,
459,
1461,
418,
272,
365,
63,
16020,
275,
1067,
459,
374,
63,
16020,
418,
272,
3354,
63,
305,
275,
1067,
459,
2117,
63,
305,
418,
272,
4027,
275,
469,
267,
283,
3291,
356,
3999,
12,
267,
283,
2384,
63,
1807,
63,
1073,
356,
334,
1397,
365,
63,
16020,
436,
1067,
459,
1989,
63,
1807,
63,
5693,
418,
2892,
436,
1570,
436,
1067,
14,
362,
360,
2384,
63,
1807,
297,
715,
1826,
267,
283,
2384,
63,
2117,
63,
305,
63,
1222,
356,
440,
365,
63,
16020,
436,
1570,
436,
3354,
63,
305,
12,
267,
283,
2384,
63,
2117,
63,
460,
63,
525,
63,
13565,
356,
1067,
459,
1989,
63,
525,
63,
5693,
418,
436,
1169,
440,
365,
63,
16020,
436,
334,
1397,
3354,
63,
305,
503,
1067,
459,
525,
3815,
267,
283,
2384,
63,
2117,
63,
460,
63,
6958,
356,
440,
365,
63,
16020,
436,
1067,
459,
1989,
63,
1461,
63,
5693,
995,
267,
283,
374,
63,
16020,
356,
365,
63,
16020,
12,
267,
283,
2384,
63,
2117,
356,
715,
12,
267,
283,
32104,
63,
4273,
356,
1067,
14,
362,
360,
32104,
63,
4273,
659,
272,
789,
272,
340,
1067,
14,
362,
360,
5043,
358,
365,
440,
488,
26,
267,
4027,
459,
5043,
418,
275,
1067,
459,
5043,
418,
272,
372,
4027,
199,
199,
32,
2683,
14,
1541,
199,
318,
4917,
63,
835,
8,
6460,
63,
2113,
63,
964,
304,
272,
408,
3407,
314,
1329,
402,
10106,
1202,
315,
282,
5174,
2238,
8308,
624,
272,
2338,
275,
413,
327,
26401,
4917,
543,
8752,
283,
344,
7,
901,
272,
367,
901,
409,
315,
8308,
63,
2113,
63,
964,
26,
267,
327,
18175,
4012,
1006,
314,
1504,
334,
368,
1126,
4917,
9,
267,
367,
1004,
315,
901,
409,
26,
288,
367,
901,
315,
1004,
26,
355,
2338,
847,
413,
272,
340,
8308,
63,
2113,
63,
964,
14,
10724,
14,
2425,
63,
1807,
26,
267,
327,
8496,
24190,
267,
2338,
847,
413,
272,
372,
2338,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
wkfwkf/statsmodels
|
statsmodels/distributions/mixture_rvs.py
|
27
|
9592
|
from statsmodels.compat.python import range
import numpy as np
def _make_index(prob,size):
"""
Returns a boolean index for given probabilities.
Notes
---------
prob = [.75,.25] means that there is a 75% chance of the first column
being True and a 25% chance of the second column being True. The
columns are mutually exclusive.
"""
rv = np.random.uniform(size=(size,1))
cumprob = np.cumsum(prob)
return np.logical_and(np.r_[0,cumprob[:-1]] <= rv, rv < cumprob)
def mixture_rvs(prob, size, dist, kwargs=None):
"""
Sample from a mixture of distributions.
Parameters
----------
prob : array-like
Probability of sampling from each distribution in dist
size : int
The length of the returned sample.
dist : array-like
An iterable of distributions objects from scipy.stats.
kwargs : tuple of dicts, optional
A tuple of dicts. Each dict in kwargs can have keys loc, scale, and
args to be passed to the respective distribution in dist. If not
provided, the distribution defaults are used.
Examples
--------
Say we want 5000 random variables from mixture of normals with two
distributions norm(-1,.5) and norm(1,.5) and we want to sample from the
first with probability .75 and the second with probability .25.
>>> from scipy import stats
>>> prob = [.75,.25]
>>> Y = mixture_rvs(prob, 5000, dist=[stats.norm, stats.norm], kwargs =
(dict(loc=-1,scale=.5),dict(loc=1,scale=.5)))
"""
if len(prob) != len(dist):
raise ValueError("You must provide as many probabilities as distributions")
if not np.allclose(np.sum(prob), 1):
raise ValueError("prob does not sum to 1")
if kwargs is None:
kwargs = ({},)*len(prob)
idx = _make_index(prob,size)
sample = np.empty(size)
for i in range(len(prob)):
sample_idx = idx[...,i]
sample_size = sample_idx.sum()
loc = kwargs[i].get('loc',0)
scale = kwargs[i].get('scale',1)
args = kwargs[i].get('args',())
sample[sample_idx] = dist[i].rvs(*args, **dict(loc=loc,scale=scale,
size=sample_size))
return sample
class MixtureDistribution(object):
'''univariate mixture distribution
for simple case for now (unbound support)
does not yet inherit from scipy.stats.distributions
adding pdf to mixture_rvs, some restrictions on broadcasting
Currently it does not hold any state, all arguments included in each method.
'''
#def __init__(self, prob, size, dist, kwargs=None):
def rvs(self, prob, size, dist, kwargs=None):
return mixture_rvs(prob, size, dist, kwargs=kwargs)
def pdf(self, x, prob, dist, kwargs=None):
"""
pdf a mixture of distributions.
Parameters
----------
prob : array-like
Probability of sampling from each distribution in dist
dist : array-like
An iterable of distributions objects from scipy.stats.
kwargs : tuple of dicts, optional
A tuple of dicts. Each dict in kwargs can have keys loc, scale, and
args to be passed to the respective distribution in dist. If not
provided, the distribution defaults are used.
Examples
--------
Say we want 5000 random variables from mixture of normals with two
distributions norm(-1,.5) and norm(1,.5) and we want to sample from the
first with probability .75 and the second with probability .25.
>>> from scipy import stats
>>> prob = [.75,.25]
>>> Y = mixture.pdf(x, prob, dist=[stats.norm, stats.norm], kwargs =
(dict(loc=-1,scale=.5),dict(loc=1,scale=.5)))
"""
if len(prob) != len(dist):
raise ValueError("You must provide as many probabilities as distributions")
if not np.allclose(np.sum(prob), 1):
raise ValueError("prob does not sum to 1")
if kwargs is None:
kwargs = ({},)*len(prob)
for i in range(len(prob)):
loc = kwargs[i].get('loc',0)
scale = kwargs[i].get('scale',1)
args = kwargs[i].get('args',())
if i == 0: #assume all broadcast the same as the first dist
pdf_ = prob[i] * dist[i].pdf(x, *args, loc=loc, scale=scale)
else:
pdf_ += prob[i] * dist[i].pdf(x, *args, loc=loc, scale=scale)
return pdf_
def cdf(self, x, prob, dist, kwargs=None):
"""
cdf of a mixture of distributions.
Parameters
----------
prob : array-like
Probability of sampling from each distribution in dist
size : int
The length of the returned sample.
dist : array-like
An iterable of distributions objects from scipy.stats.
kwargs : tuple of dicts, optional
A tuple of dicts. Each dict in kwargs can have keys loc, scale, and
args to be passed to the respective distribution in dist. If not
provided, the distribution defaults are used.
Examples
--------
Say we want 5000 random variables from mixture of normals with two
distributions norm(-1,.5) and norm(1,.5) and we want to sample from the
first with probability .75 and the second with probability .25.
>>> from scipy import stats
>>> prob = [.75,.25]
>>> Y = mixture.pdf(x, prob, dist=[stats.norm, stats.norm], kwargs =
(dict(loc=-1,scale=.5),dict(loc=1,scale=.5)))
"""
if len(prob) != len(dist):
raise ValueError("You must provide as many probabilities as distributions")
if not np.allclose(np.sum(prob), 1):
raise ValueError("prob does not sum to 1")
if kwargs is None:
kwargs = ({},)*len(prob)
for i in range(len(prob)):
loc = kwargs[i].get('loc',0)
scale = kwargs[i].get('scale',1)
args = kwargs[i].get('args',())
if i == 0: #assume all broadcast the same as the first dist
cdf_ = prob[i] * dist[i].cdf(x, *args, loc=loc, scale=scale)
else:
cdf_ += prob[i] * dist[i].cdf(x, *args, loc=loc, scale=scale)
return cdf_
def mv_mixture_rvs(prob, size, dist, nvars, **kwargs):
"""
Sample from a mixture of multivariate distributions.
Parameters
----------
prob : array-like
Probability of sampling from each distribution in dist
size : int
The length of the returned sample.
dist : array-like
An iterable of distributions instances with callable method rvs.
nvargs : int
dimension of the multivariate distribution, could be inferred instead
kwargs : tuple of dicts, optional
ignored
Examples
--------
Say we want 2000 random variables from mixture of normals with two
multivariate normal distributions, and we want to sample from the
first with probability .4 and the second with probability .6.
import statsmodels.sandbox.distributions.mv_normal as mvd
cov3 = np.array([[ 1. , 0.5 , 0.75],
[ 0.5 , 1.5 , 0.6 ],
[ 0.75, 0.6 , 2. ]])
mu = np.array([-1, 0.0, 2.0])
mu2 = np.array([4, 2.0, 2.0])
mvn3 = mvd.MVNormal(mu, cov3)
mvn32 = mvd.MVNormal(mu2, cov3/2., 4)
rvs = mix.mv_mixture_rvs([0.4, 0.6], 2000, [mvn3, mvn32], 3)
"""
if len(prob) != len(dist):
raise ValueError("You must provide as many probabilities as distributions")
if not np.allclose(np.sum(prob), 1):
raise ValueError("prob does not sum to 1")
if kwargs is None:
kwargs = ({},)*len(prob)
idx = _make_index(prob,size)
sample = np.empty((size, nvars))
for i in range(len(prob)):
sample_idx = idx[...,i]
sample_size = sample_idx.sum()
#loc = kwargs[i].get('loc',0)
#scale = kwargs[i].get('scale',1)
#args = kwargs[i].get('args',())
# use int to avoid numpy bug with np.random.multivariate_normal
sample[sample_idx] = dist[i].rvs(size=int(sample_size))
return sample
if __name__ == '__main__':
from scipy import stats
obs_dist = mixture_rvs([.25,.75], size=10000, dist=[stats.norm, stats.beta],
kwargs=(dict(loc=-1,scale=.5),dict(loc=1,scale=1,args=(1,.5))))
nobs = 10000
mix = MixtureDistribution()
## mrvs = mixture_rvs([1/3.,2/3.], size=nobs, dist=[stats.norm, stats.norm],
## kwargs = (dict(loc=-1,scale=.5),dict(loc=1,scale=.75)))
mix_kwds = (dict(loc=-1,scale=.25),dict(loc=1,scale=.75))
mrvs = mix.rvs([1/3.,2/3.], size=nobs, dist=[stats.norm, stats.norm],
kwargs=mix_kwds)
grid = np.linspace(-4,4, 100)
mpdf = mix.pdf(grid, [1/3.,2/3.], dist=[stats.norm, stats.norm],
kwargs=mix_kwds)
mcdf = mix.cdf(grid, [1/3.,2/3.], dist=[stats.norm, stats.norm],
kwargs=mix_kwds)
doplot = 1
if doplot:
import matplotlib.pyplot as plt
plt.figure()
plt.hist(mrvs, bins=50, normed=True, color='red')
plt.title('histogram of sample and pdf')
plt.plot(grid, mpdf, lw=2, color='black')
plt.figure()
plt.hist(mrvs, bins=50, normed=True, cumulative=True, color='red')
plt.title('histogram of sample and pdf')
plt.plot(grid, mcdf, lw=2, color='black')
plt.show()
|
bsd-3-clause
|
[
504,
5020,
992,
14,
5819,
14,
1548,
492,
1425,
199,
646,
2680,
465,
980,
199,
199,
318,
485,
1875,
63,
1080,
8,
6101,
12,
890,
304,
272,
408,
272,
1803,
282,
5046,
1478,
367,
1627,
19555,
14,
339,
8144,
272,
3001,
13,
272,
5128,
275,
26496,
2194,
18485,
821,
61,
4910,
626,
2337,
365,
282,
13098,
5,
22044,
402,
314,
1642,
2763,
272,
3769,
715,
436,
282,
5661,
5,
22044,
402,
314,
3499,
2763,
3769,
715,
14,
710,
272,
4362,
787,
16108,
13914,
14,
272,
408,
272,
4336,
275,
980,
14,
2355,
14,
8830,
8,
890,
2687,
890,
12,
17,
430,
272,
286,
1220,
29891,
275,
980,
14,
23916,
8,
6101,
9,
272,
372,
980,
14,
7954,
63,
460,
8,
1590,
14,
82,
9925,
16,
12,
67,
1220,
29891,
4439,
17,
2677,
2695,
4336,
12,
4336,
665,
286,
1220,
29891,
9,
199,
199,
318,
31885,
63,
23322,
8,
6101,
12,
1568,
12,
2917,
12,
2074,
29,
403,
304,
272,
408,
272,
15227,
687,
282,
31885,
402,
10208,
14,
339,
3897,
272,
4143,
272,
5128,
520,
1625,
13,
2930,
267,
22770,
3616,
402,
15877,
687,
1924,
4084,
315,
2917,
272,
1568,
520,
1109,
267,
710,
2582,
402,
314,
2138,
2690,
14,
272,
2917,
520,
1625,
13,
2930,
267,
1626,
6076,
402,
10208,
2251,
687,
7026,
14,
3200,
14,
272,
2074,
520,
2008,
402,
10809,
12,
2716,
267,
437,
2008,
402,
10809,
14,
221,
7048,
1211,
315,
2074,
883,
1172,
2883,
4355,
12,
4666,
12,
436,
267,
1249,
370,
506,
3032,
370,
314,
26820,
4084,
315,
2917,
14,
221,
982,
440,
267,
2741,
12,
314,
4084,
4243,
787,
1202,
14,
339,
6058,
272,
3001,
272,
428,
1187,
781,
2934,
22369,
2196,
2860,
687,
31885,
402,
27421,
543,
2877,
272,
10208,
6316,
2801,
17,
18485,
21,
9,
436,
6316,
8,
17,
18485,
21,
9,
436,
781,
2934,
370,
2690,
687,
314,
272,
1642,
543,
12224,
1275,
2194,
436,
314,
3499,
543,
12224,
1275,
821,
14,
339,
1306,
687,
7026,
492,
5020,
272,
1306,
5128,
275,
26496,
2194,
18485,
821,
61,
272,
1306,
1488,
275,
31885,
63,
23322,
8,
6101,
12,
22369,
12,
2917,
1524,
3200,
14,
4791,
12,
5020,
14,
4791,
467,
2074,
275,
355,
334,
807,
8,
2102,
4022,
17,
12,
3467,
15856,
21,
395,
807,
8,
2102,
29,
17,
12,
3467,
15856,
21,
1724,
272,
408,
272,
340,
822,
8,
6101,
9,
1137,
822,
8,
2686,
304,
267,
746,
1722,
480,
5556,
1471,
5647,
465,
5002,
19555,
465,
10208,
531,
272,
340,
440,
980,
14,
7520,
8,
1590,
14,
1838,
8,
6101,
395,
413,
304,
267,
746,
1722,
480,
6101,
1630,
440,
3089,
370,
413,
531,
339,
340,
2074,
365,
488,
26,
267,
2074,
275,
11459,
1386,
3342,
552,
8,
6101,
9,
339,
4280,
275,
485,
1875,
63,
1080,
8,
6101,
12,
890,
9,
272,
2690,
275,
980,
14,
1667,
8,
890,
9,
272,
367,
284,
315,
1425,
8,
552,
8,
6101,
2298,
267,
2690,
63,
2996,
275,
4280,
18999,
73,
61,
267,
2690,
63,
890,
275,
2690,
63,
2996,
14,
1838,
342,
267,
4355,
275,
2074,
59,
73,
1055,
362,
360,
2102,
297,
16,
9,
267,
4666,
275,
2074,
59,
73,
1055,
362,
360,
3467,
297,
17,
9,
267,
1249,
275,
2074,
59,
73,
1055,
362,
360,
589,
297,
1012,
267,
2690,
59,
3271,
63,
2996,
61,
275,
2917,
59,
73,
1055,
23322,
2031,
589,
12,
1011,
807,
8,
2102,
29,
2102,
12,
3467,
29,
3467,
12,
288,
1568,
29,
3271,
63,
890,
430,
272,
372,
2690,
421,
199,
533,
603,
73,
4167,
8580,
8,
785,
304,
272,
1449,
324,
23225,
31885,
4084,
339,
367,
3486,
1930,
367,
3063,
334,
18124,
2291,
9,
272,
1630,
440,
5966,
8287,
687,
7026,
14,
3200,
14,
5613,
339,
7791,
11249,
370,
31885,
63,
23322,
12,
2005,
24488,
641,
32001,
272,
13550,
652,
1630,
440,
10266,
1263,
1174,
12,
1006,
2368,
5120,
315,
1924,
1083,
14,
272,
1449,
339,
327,
318,
636,
826,
721,
277,
12,
5128,
12,
1568,
12,
2917,
12,
2074,
29,
403,
304,
339,
347,
519,
3122,
8,
277,
12,
5128,
12,
1568,
12,
2917,
12,
2074,
29,
403,
304,
267,
372,
31885,
63,
23322,
8,
6101,
12,
1568,
12,
2917,
12,
2074,
29,
958,
9,
2378,
347,
11249,
8,
277,
12,
671,
12,
5128,
12,
2917,
12,
2074,
29,
403,
304,
267,
408,
267,
11249,
282,
31885,
402,
10208,
14,
398,
3897,
267,
4143,
267,
5128,
520,
1625,
13,
2930,
288,
22770,
3616,
402,
15877,
687,
1924,
4084,
315,
2917,
267,
2917,
520,
1625,
13,
2930,
288,
1626,
6076,
402,
10208,
2251,
687,
7026,
14,
3200,
14,
267,
2074,
520,
2008,
402,
10809,
12,
2716,
288,
437,
2008,
402,
10809,
14,
221,
7048,
1211,
315,
2074,
883,
1172,
2883,
4355,
12,
4666,
12,
436,
288,
1249,
370,
506,
3032,
370,
314,
26820,
4084,
315,
2917,
14,
221,
982,
440,
288,
2741,
12,
314,
4084,
4243,
787,
1202,
14,
398,
6058,
267,
3001,
267,
428,
1187,
781,
2934,
22369,
2196,
2860,
687,
31885,
402,
27421,
543,
2877,
267,
10208,
6316,
2801,
17,
18485,
21,
9,
436,
6316,
8,
17,
18485,
21,
9,
436,
781,
2934,
370,
2690,
687,
314,
267,
1642,
543,
12224,
1275,
2194,
436,
314,
3499,
543,
12224,
1275,
821,
14,
398,
1306,
687,
7026,
492,
5020,
267,
1306,
5128,
275,
26496,
2194,
18485,
821,
61,
267,
1306,
1488,
275,
31885,
14,
5607,
8,
88,
12,
5128,
12,
2917,
1524,
3200,
14,
4791,
12,
5020,
14,
4791,
467,
2074,
275,
490,
334,
807,
8,
2102,
4022,
17,
12,
3467,
15856,
21,
395,
807,
8,
2102,
29,
17,
12,
3467,
15856,
21,
1724,
267,
408,
267,
340,
822,
8,
6101,
9,
1137,
822,
8,
2686,
304,
288,
746,
1722,
480,
5556,
1471,
5647,
465,
5002,
19555,
465,
10208,
531,
267,
340,
440,
980,
14,
7520,
8,
1590,
14,
1838,
8,
6101,
395,
413,
304,
288,
746,
1722,
480,
6101,
1630,
440,
3089,
370,
413,
531,
398,
340,
2074,
365,
488,
26,
288,
2074,
275,
11459,
1386,
3342,
552,
8,
6101,
9,
398,
367,
284,
315,
1425,
8,
552,
8,
6101,
2298,
288,
4355,
275,
2074,
59,
73,
1055,
362,
360,
2102,
297,
16,
9,
288,
4666,
275,
2074,
59,
73,
1055,
362,
360,
3467
] |
[
5020,
992,
14,
5819,
14,
1548,
492,
1425,
199,
646,
2680,
465,
980,
199,
199,
318,
485,
1875,
63,
1080,
8,
6101,
12,
890,
304,
272,
408,
272,
1803,
282,
5046,
1478,
367,
1627,
19555,
14,
339,
8144,
272,
3001,
13,
272,
5128,
275,
26496,
2194,
18485,
821,
61,
4910,
626,
2337,
365,
282,
13098,
5,
22044,
402,
314,
1642,
2763,
272,
3769,
715,
436,
282,
5661,
5,
22044,
402,
314,
3499,
2763,
3769,
715,
14,
710,
272,
4362,
787,
16108,
13914,
14,
272,
408,
272,
4336,
275,
980,
14,
2355,
14,
8830,
8,
890,
2687,
890,
12,
17,
430,
272,
286,
1220,
29891,
275,
980,
14,
23916,
8,
6101,
9,
272,
372,
980,
14,
7954,
63,
460,
8,
1590,
14,
82,
9925,
16,
12,
67,
1220,
29891,
4439,
17,
2677,
2695,
4336,
12,
4336,
665,
286,
1220,
29891,
9,
199,
199,
318,
31885,
63,
23322,
8,
6101,
12,
1568,
12,
2917,
12,
2074,
29,
403,
304,
272,
408,
272,
15227,
687,
282,
31885,
402,
10208,
14,
339,
3897,
272,
4143,
272,
5128,
520,
1625,
13,
2930,
267,
22770,
3616,
402,
15877,
687,
1924,
4084,
315,
2917,
272,
1568,
520,
1109,
267,
710,
2582,
402,
314,
2138,
2690,
14,
272,
2917,
520,
1625,
13,
2930,
267,
1626,
6076,
402,
10208,
2251,
687,
7026,
14,
3200,
14,
272,
2074,
520,
2008,
402,
10809,
12,
2716,
267,
437,
2008,
402,
10809,
14,
221,
7048,
1211,
315,
2074,
883,
1172,
2883,
4355,
12,
4666,
12,
436,
267,
1249,
370,
506,
3032,
370,
314,
26820,
4084,
315,
2917,
14,
221,
982,
440,
267,
2741,
12,
314,
4084,
4243,
787,
1202,
14,
339,
6058,
272,
3001,
272,
428,
1187,
781,
2934,
22369,
2196,
2860,
687,
31885,
402,
27421,
543,
2877,
272,
10208,
6316,
2801,
17,
18485,
21,
9,
436,
6316,
8,
17,
18485,
21,
9,
436,
781,
2934,
370,
2690,
687,
314,
272,
1642,
543,
12224,
1275,
2194,
436,
314,
3499,
543,
12224,
1275,
821,
14,
339,
1306,
687,
7026,
492,
5020,
272,
1306,
5128,
275,
26496,
2194,
18485,
821,
61,
272,
1306,
1488,
275,
31885,
63,
23322,
8,
6101,
12,
22369,
12,
2917,
1524,
3200,
14,
4791,
12,
5020,
14,
4791,
467,
2074,
275,
355,
334,
807,
8,
2102,
4022,
17,
12,
3467,
15856,
21,
395,
807,
8,
2102,
29,
17,
12,
3467,
15856,
21,
1724,
272,
408,
272,
340,
822,
8,
6101,
9,
1137,
822,
8,
2686,
304,
267,
746,
1722,
480,
5556,
1471,
5647,
465,
5002,
19555,
465,
10208,
531,
272,
340,
440,
980,
14,
7520,
8,
1590,
14,
1838,
8,
6101,
395,
413,
304,
267,
746,
1722,
480,
6101,
1630,
440,
3089,
370,
413,
531,
339,
340,
2074,
365,
488,
26,
267,
2074,
275,
11459,
1386,
3342,
552,
8,
6101,
9,
339,
4280,
275,
485,
1875,
63,
1080,
8,
6101,
12,
890,
9,
272,
2690,
275,
980,
14,
1667,
8,
890,
9,
272,
367,
284,
315,
1425,
8,
552,
8,
6101,
2298,
267,
2690,
63,
2996,
275,
4280,
18999,
73,
61,
267,
2690,
63,
890,
275,
2690,
63,
2996,
14,
1838,
342,
267,
4355,
275,
2074,
59,
73,
1055,
362,
360,
2102,
297,
16,
9,
267,
4666,
275,
2074,
59,
73,
1055,
362,
360,
3467,
297,
17,
9,
267,
1249,
275,
2074,
59,
73,
1055,
362,
360,
589,
297,
1012,
267,
2690,
59,
3271,
63,
2996,
61,
275,
2917,
59,
73,
1055,
23322,
2031,
589,
12,
1011,
807,
8,
2102,
29,
2102,
12,
3467,
29,
3467,
12,
288,
1568,
29,
3271,
63,
890,
430,
272,
372,
2690,
421,
199,
533,
603,
73,
4167,
8580,
8,
785,
304,
272,
1449,
324,
23225,
31885,
4084,
339,
367,
3486,
1930,
367,
3063,
334,
18124,
2291,
9,
272,
1630,
440,
5966,
8287,
687,
7026,
14,
3200,
14,
5613,
339,
7791,
11249,
370,
31885,
63,
23322,
12,
2005,
24488,
641,
32001,
272,
13550,
652,
1630,
440,
10266,
1263,
1174,
12,
1006,
2368,
5120,
315,
1924,
1083,
14,
272,
1449,
339,
327,
318,
636,
826,
721,
277,
12,
5128,
12,
1568,
12,
2917,
12,
2074,
29,
403,
304,
339,
347,
519,
3122,
8,
277,
12,
5128,
12,
1568,
12,
2917,
12,
2074,
29,
403,
304,
267,
372,
31885,
63,
23322,
8,
6101,
12,
1568,
12,
2917,
12,
2074,
29,
958,
9,
2378,
347,
11249,
8,
277,
12,
671,
12,
5128,
12,
2917,
12,
2074,
29,
403,
304,
267,
408,
267,
11249,
282,
31885,
402,
10208,
14,
398,
3897,
267,
4143,
267,
5128,
520,
1625,
13,
2930,
288,
22770,
3616,
402,
15877,
687,
1924,
4084,
315,
2917,
267,
2917,
520,
1625,
13,
2930,
288,
1626,
6076,
402,
10208,
2251,
687,
7026,
14,
3200,
14,
267,
2074,
520,
2008,
402,
10809,
12,
2716,
288,
437,
2008,
402,
10809,
14,
221,
7048,
1211,
315,
2074,
883,
1172,
2883,
4355,
12,
4666,
12,
436,
288,
1249,
370,
506,
3032,
370,
314,
26820,
4084,
315,
2917,
14,
221,
982,
440,
288,
2741,
12,
314,
4084,
4243,
787,
1202,
14,
398,
6058,
267,
3001,
267,
428,
1187,
781,
2934,
22369,
2196,
2860,
687,
31885,
402,
27421,
543,
2877,
267,
10208,
6316,
2801,
17,
18485,
21,
9,
436,
6316,
8,
17,
18485,
21,
9,
436,
781,
2934,
370,
2690,
687,
314,
267,
1642,
543,
12224,
1275,
2194,
436,
314,
3499,
543,
12224,
1275,
821,
14,
398,
1306,
687,
7026,
492,
5020,
267,
1306,
5128,
275,
26496,
2194,
18485,
821,
61,
267,
1306,
1488,
275,
31885,
14,
5607,
8,
88,
12,
5128,
12,
2917,
1524,
3200,
14,
4791,
12,
5020,
14,
4791,
467,
2074,
275,
490,
334,
807,
8,
2102,
4022,
17,
12,
3467,
15856,
21,
395,
807,
8,
2102,
29,
17,
12,
3467,
15856,
21,
1724,
267,
408,
267,
340,
822,
8,
6101,
9,
1137,
822,
8,
2686,
304,
288,
746,
1722,
480,
5556,
1471,
5647,
465,
5002,
19555,
465,
10208,
531,
267,
340,
440,
980,
14,
7520,
8,
1590,
14,
1838,
8,
6101,
395,
413,
304,
288,
746,
1722,
480,
6101,
1630,
440,
3089,
370,
413,
531,
398,
340,
2074,
365,
488,
26,
288,
2074,
275,
11459,
1386,
3342,
552,
8,
6101,
9,
398,
367,
284,
315,
1425,
8,
552,
8,
6101,
2298,
288,
4355,
275,
2074,
59,
73,
1055,
362,
360,
2102,
297,
16,
9,
288,
4666,
275,
2074,
59,
73,
1055,
362,
360,
3467,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
acdh-oeaw/totetiroler
|
places/views.py
|
1
|
4026
|
import requests
import json
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.shortcuts import render, redirect, get_object_or_404
from django.views import generic
from django.views.generic.edit import DeleteView
from django.core.urlresolvers import reverse_lazy
from .models import Place, AlternativeName
from .forms import PlaceForm, AlternativeNameForm
@login_required
def create_place(request):
if request.method == "POST":
form = PlaceForm(request.POST)
if form.is_valid():
form.save()
return redirect('places:place_list')
else:
return render(request, 'places/edit_places.html', {'form': form})
else:
form = PlaceForm()
return render(request, 'places/edit_places.html', {'form': form})
class AlternativeNameListView(generic.ListView):
template_name = "places/list_alternativenames.html"
context_object_name = 'object_list'
def get_queryset(self):
return AlternativeName.objects.all()
@login_required
def create_alternativename(request):
if request.method == "POST":
form = AlternativeNameForm(request.POST)
if form.is_valid():
form.save()
return redirect('places:alternativenames_list')
else:
return render(request, 'places/edit_alternativenames.html', {'form': form})
else:
form = AlternativeNameForm()
return render(request, 'places/edit_alternativenames.html', {'form': form})
@login_required
def edit_alternativename(request, pk):
instance = get_object_or_404(AlternativeName, id=pk)
if request.method == "POST":
form = AlternativeNameForm(request.POST, instance=instance)
if form.is_valid():
form.save()
return redirect('places:alternativenames_list')
else:
return render(
request, 'places/edit_alternativenames.html', {'form': form, 'instance': instance}
)
else:
form = AlternativeNameForm(instance=instance)
return render(
request, 'places/edit_alternativenames.html', {'form': form, 'instance': instance})
class AlternativeNameDelete(DeleteView):
model = AlternativeName
template_name = 'webpage/confirm_delete.html'
success_url = reverse_lazy('places:alternativename_list')
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(AlternativeNameDelete, self).dispatch(*args, **kwargs)
class PlaceListView(generic.ListView):
template_name = "places/list_places.html"
context_object_name = 'object_list'
def get_queryset(self):
return Place.objects.all()
@login_required
def edit_place(request, pk):
instance = Place.objects.get(id=pk)
username = "&username=digitalarchiv"
if request.method == "GET":
placeName = instance.name
root = "http://api.geonames.org/searchJSON?q="
params = "&fuzzy=0.6&lang=de&maxRows=100"
url = root + placeName + params + username
try:
r = requests.get(url)
except requests.exceptions.RequestException as e:
url = e
response = r.text
responseJSON = json.loads(response)
responseJSON = responseJSON['geonames']
form = PlaceForm(instance=instance)
print(url)
return render(
request, 'places/edit_places.html',
{'object': instance, 'form': form, 'responseJSON': responseJSON}
)
else:
form = PlaceForm(request.POST, instance=instance)
if form.is_valid():
form.save()
return redirect('places:place_list')
class PlaceDelete(DeleteView):
model = Place
template_name = 'webpage/confirm_delete.html'
success_url = reverse_lazy('places:place_list')
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(PlaceDelete, self).dispatch(*args, **kwargs)
|
mit
|
[
646,
4145,
199,
646,
2022,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1083,
63,
11547,
199,
504,
1639,
14,
17469,
492,
3795,
12,
4660,
12,
664,
63,
785,
63,
269,
63,
5188,
199,
504,
1639,
14,
4196,
492,
7809,
199,
504,
1639,
14,
4196,
14,
6767,
14,
3773,
492,
8496,
2768,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
63,
6395,
199,
199,
504,
1275,
992,
492,
10902,
12,
17669,
1905,
985,
199,
504,
1275,
3351,
492,
10902,
2821,
12,
17669,
1905,
985,
2821,
421,
199,
32,
2886,
63,
2427,
199,
318,
1218,
63,
2778,
8,
1069,
304,
272,
340,
1056,
14,
765,
508,
298,
4030,
582,
267,
1824,
275,
10902,
2821,
8,
1069,
14,
4030,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
288,
1824,
14,
2117,
342,
288,
372,
4660,
360,
10696,
26,
2778,
63,
513,
358,
267,
587,
26,
288,
372,
3795,
8,
1069,
12,
283,
10696,
15,
3773,
63,
10696,
14,
1360,
297,
791,
964,
356,
1824,
1552,
272,
587,
26,
267,
1824,
275,
10902,
2821,
342,
267,
372,
3795,
8,
1069,
12,
283,
10696,
15,
3773,
63,
10696,
14,
1360,
297,
791,
964,
356,
1824,
1552,
421,
199,
533,
17669,
1905,
985,
23239,
8,
6767,
14,
23239,
304,
272,
1978,
63,
354,
275,
298,
10696,
15,
513,
63,
10280,
2159,
1856,
14015,
14,
1360,
2,
272,
1067,
63,
785,
63,
354,
275,
283,
785,
63,
513,
7,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
372,
17669,
1905,
985,
14,
1462,
14,
452,
342,
421,
199,
32,
2886,
63,
2427,
199,
318,
1218,
63,
10280,
2159,
1856,
313,
8,
1069,
304,
272,
340,
1056,
14,
765,
508,
298,
4030,
582,
267,
1824,
275,
17669,
1905,
985,
2821,
8,
1069,
14,
4030,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
288,
1824,
14,
2117,
342,
288,
372,
4660,
360,
10696,
26,
10280,
2159,
1856,
14015,
63,
513,
358,
267,
587,
26,
288,
372,
3795,
8,
1069,
12,
283,
10696,
15,
3773,
63,
10280,
2159,
1856,
14015,
14,
1360,
297,
791,
964,
356,
1824,
1552,
272,
587,
26,
267,
1824,
275,
17669,
1905,
985,
2821,
342,
267,
372,
3795,
8,
1069,
12,
283,
10696,
15,
3773,
63,
10280,
2159,
1856,
14015,
14,
1360,
297,
791,
964,
356,
1824,
1552,
421,
199,
32,
2886,
63,
2427,
199,
318,
5283,
63,
10280,
2159,
1856,
313,
8,
1069,
12,
3803,
304,
272,
1256,
275,
664,
63,
785,
63,
269,
63,
5188,
8,
19978,
1905,
985,
12,
1305,
29,
2051,
9,
272,
340,
1056,
14,
765,
508,
298,
4030,
582,
267,
1824,
275,
17669,
1905,
985,
2821,
8,
1069,
14,
4030,
12,
1256,
29,
842,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
288,
1824,
14,
2117,
342,
288,
372,
4660,
360,
10696,
26,
10280,
2159,
1856,
14015,
63,
513,
358,
267,
587,
26,
288,
372,
3795,
8,
355,
1056,
12,
283,
10696,
15,
3773,
63,
10280,
2159,
1856,
14015,
14,
1360,
297,
791,
964,
356,
1824,
12,
283,
842,
356,
1256,
93,
288,
776,
272,
587,
26,
267,
1824,
275,
17669,
1905,
985,
2821,
8,
842,
29,
842,
9,
267,
372,
3795,
8,
288,
1056,
12,
283,
10696,
15,
3773,
63,
10280,
2159,
1856,
14015,
14,
1360,
297,
791,
964,
356,
1824,
12,
283,
842,
356,
1256,
1552,
421,
199,
533,
17669,
1905,
985,
5392,
8,
5392,
2768,
304,
272,
1402,
275,
17669,
1905,
985,
272,
1978,
63,
354,
275,
283,
12022,
15,
9548,
63,
1807,
14,
1360,
7,
272,
3182,
63,
633,
275,
3837,
63,
6395,
360,
10696,
26,
10280,
2159,
1856,
313,
63,
513,
358,
339,
768,
765,
63,
11547,
8,
2886,
63,
2427,
9,
272,
347,
7634,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
1613,
8,
19978,
1905,
985,
5392,
12,
291,
680,
6052,
2031,
589,
12,
1011,
958,
9,
421,
199,
533,
10902,
23239,
8,
6767,
14,
23239,
304,
272,
1978,
63,
354,
275,
298,
10696,
15,
513,
63,
10696,
14,
1360,
2,
272,
1067,
63,
785,
63,
354,
275,
283,
785,
63,
513,
7,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
372,
10902,
14,
1462,
14,
452,
342,
421,
199,
32,
2886,
63,
2427,
199,
318,
5283,
63,
2778,
8,
1069,
12,
3803,
304,
272,
1256,
275,
10902,
14,
1462,
14,
362,
8,
344,
29,
2051,
9,
272,
3434,
275,
11746,
2473,
29,
25888,
1047,
1003,
2,
272,
340,
1056,
14,
765,
508,
298,
2970,
582,
267,
4192,
985,
275,
1256,
14,
354,
267,
1738,
275,
298,
1014,
921,
1246,
14,
303,
265,
14015,
14,
1308,
15,
1733,
6243,
31,
81,
628,
267,
1862,
275,
11746,
24529,
29,
16,
14,
22,
6,
4159,
29,
271,
6,
988,
13405,
29,
1960,
2,
267,
1166,
275,
1738,
435,
4192,
985,
435,
1862,
435,
3434,
267,
862,
26,
288,
519,
275,
4145,
14,
362,
8,
633,
9,
267,
871,
4145,
14,
3924,
14,
28724,
465,
325,
26,
288,
1166,
275,
325,
267,
1177,
275,
519,
14,
505,
267,
1177,
6243,
275,
2022,
14,
3640,
8,
1310,
9,
267,
1177,
6243,
275,
1177,
6243,
459,
303,
265,
14015,
418,
267,
1824,
275,
10902,
2821,
8,
842,
29,
842,
9,
267,
870,
8,
633,
9,
267,
372,
3795,
8,
288,
1056,
12,
283,
10696,
15,
3773,
63,
10696,
14,
1360,
297,
288,
791,
785,
356,
1256,
12,
283,
964,
356,
1824,
12,
283,
1310,
6243,
356,
1177,
6243,
93,
267,
776,
272,
587,
26,
267,
1824,
275,
10902,
2821,
8,
1069,
14,
4030,
12,
1256,
29,
842,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
288,
1824,
14,
2117,
342,
267,
372,
4660,
360,
10696,
26,
2778,
63,
513,
358,
421,
199,
533,
10902,
5392,
8,
5392,
2768,
304,
272,
1402,
275,
10902,
272,
1978,
63,
354,
275,
283,
12022,
15,
9548,
63,
1807,
14,
1360,
7,
272,
3182,
63,
633,
275,
3837,
63,
6395,
360,
10696,
26,
2778,
63,
513,
358,
339,
768,
765,
63,
11547,
8,
2886,
63,
2427,
9,
272,
347,
7634,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
1613,
8,
11613,
5392,
12,
291,
680,
6052,
2031,
589,
12,
1011
] |
[
4145,
199,
646,
2022,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1083,
63,
11547,
199,
504,
1639,
14,
17469,
492,
3795,
12,
4660,
12,
664,
63,
785,
63,
269,
63,
5188,
199,
504,
1639,
14,
4196,
492,
7809,
199,
504,
1639,
14,
4196,
14,
6767,
14,
3773,
492,
8496,
2768,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
63,
6395,
199,
199,
504,
1275,
992,
492,
10902,
12,
17669,
1905,
985,
199,
504,
1275,
3351,
492,
10902,
2821,
12,
17669,
1905,
985,
2821,
421,
199,
32,
2886,
63,
2427,
199,
318,
1218,
63,
2778,
8,
1069,
304,
272,
340,
1056,
14,
765,
508,
298,
4030,
582,
267,
1824,
275,
10902,
2821,
8,
1069,
14,
4030,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
288,
1824,
14,
2117,
342,
288,
372,
4660,
360,
10696,
26,
2778,
63,
513,
358,
267,
587,
26,
288,
372,
3795,
8,
1069,
12,
283,
10696,
15,
3773,
63,
10696,
14,
1360,
297,
791,
964,
356,
1824,
1552,
272,
587,
26,
267,
1824,
275,
10902,
2821,
342,
267,
372,
3795,
8,
1069,
12,
283,
10696,
15,
3773,
63,
10696,
14,
1360,
297,
791,
964,
356,
1824,
1552,
421,
199,
533,
17669,
1905,
985,
23239,
8,
6767,
14,
23239,
304,
272,
1978,
63,
354,
275,
298,
10696,
15,
513,
63,
10280,
2159,
1856,
14015,
14,
1360,
2,
272,
1067,
63,
785,
63,
354,
275,
283,
785,
63,
513,
7,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
372,
17669,
1905,
985,
14,
1462,
14,
452,
342,
421,
199,
32,
2886,
63,
2427,
199,
318,
1218,
63,
10280,
2159,
1856,
313,
8,
1069,
304,
272,
340,
1056,
14,
765,
508,
298,
4030,
582,
267,
1824,
275,
17669,
1905,
985,
2821,
8,
1069,
14,
4030,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
288,
1824,
14,
2117,
342,
288,
372,
4660,
360,
10696,
26,
10280,
2159,
1856,
14015,
63,
513,
358,
267,
587,
26,
288,
372,
3795,
8,
1069,
12,
283,
10696,
15,
3773,
63,
10280,
2159,
1856,
14015,
14,
1360,
297,
791,
964,
356,
1824,
1552,
272,
587,
26,
267,
1824,
275,
17669,
1905,
985,
2821,
342,
267,
372,
3795,
8,
1069,
12,
283,
10696,
15,
3773,
63,
10280,
2159,
1856,
14015,
14,
1360,
297,
791,
964,
356,
1824,
1552,
421,
199,
32,
2886,
63,
2427,
199,
318,
5283,
63,
10280,
2159,
1856,
313,
8,
1069,
12,
3803,
304,
272,
1256,
275,
664,
63,
785,
63,
269,
63,
5188,
8,
19978,
1905,
985,
12,
1305,
29,
2051,
9,
272,
340,
1056,
14,
765,
508,
298,
4030,
582,
267,
1824,
275,
17669,
1905,
985,
2821,
8,
1069,
14,
4030,
12,
1256,
29,
842,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
288,
1824,
14,
2117,
342,
288,
372,
4660,
360,
10696,
26,
10280,
2159,
1856,
14015,
63,
513,
358,
267,
587,
26,
288,
372,
3795,
8,
355,
1056,
12,
283,
10696,
15,
3773,
63,
10280,
2159,
1856,
14015,
14,
1360,
297,
791,
964,
356,
1824,
12,
283,
842,
356,
1256,
93,
288,
776,
272,
587,
26,
267,
1824,
275,
17669,
1905,
985,
2821,
8,
842,
29,
842,
9,
267,
372,
3795,
8,
288,
1056,
12,
283,
10696,
15,
3773,
63,
10280,
2159,
1856,
14015,
14,
1360,
297,
791,
964,
356,
1824,
12,
283,
842,
356,
1256,
1552,
421,
199,
533,
17669,
1905,
985,
5392,
8,
5392,
2768,
304,
272,
1402,
275,
17669,
1905,
985,
272,
1978,
63,
354,
275,
283,
12022,
15,
9548,
63,
1807,
14,
1360,
7,
272,
3182,
63,
633,
275,
3837,
63,
6395,
360,
10696,
26,
10280,
2159,
1856,
313,
63,
513,
358,
339,
768,
765,
63,
11547,
8,
2886,
63,
2427,
9,
272,
347,
7634,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
1613,
8,
19978,
1905,
985,
5392,
12,
291,
680,
6052,
2031,
589,
12,
1011,
958,
9,
421,
199,
533,
10902,
23239,
8,
6767,
14,
23239,
304,
272,
1978,
63,
354,
275,
298,
10696,
15,
513,
63,
10696,
14,
1360,
2,
272,
1067,
63,
785,
63,
354,
275,
283,
785,
63,
513,
7,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
372,
10902,
14,
1462,
14,
452,
342,
421,
199,
32,
2886,
63,
2427,
199,
318,
5283,
63,
2778,
8,
1069,
12,
3803,
304,
272,
1256,
275,
10902,
14,
1462,
14,
362,
8,
344,
29,
2051,
9,
272,
3434,
275,
11746,
2473,
29,
25888,
1047,
1003,
2,
272,
340,
1056,
14,
765,
508,
298,
2970,
582,
267,
4192,
985,
275,
1256,
14,
354,
267,
1738,
275,
298,
1014,
921,
1246,
14,
303,
265,
14015,
14,
1308,
15,
1733,
6243,
31,
81,
628,
267,
1862,
275,
11746,
24529,
29,
16,
14,
22,
6,
4159,
29,
271,
6,
988,
13405,
29,
1960,
2,
267,
1166,
275,
1738,
435,
4192,
985,
435,
1862,
435,
3434,
267,
862,
26,
288,
519,
275,
4145,
14,
362,
8,
633,
9,
267,
871,
4145,
14,
3924,
14,
28724,
465,
325,
26,
288,
1166,
275,
325,
267,
1177,
275,
519,
14,
505,
267,
1177,
6243,
275,
2022,
14,
3640,
8,
1310,
9,
267,
1177,
6243,
275,
1177,
6243,
459,
303,
265,
14015,
418,
267,
1824,
275,
10902,
2821,
8,
842,
29,
842,
9,
267,
870,
8,
633,
9,
267,
372,
3795,
8,
288,
1056,
12,
283,
10696,
15,
3773,
63,
10696,
14,
1360,
297,
288,
791,
785,
356,
1256,
12,
283,
964,
356,
1824,
12,
283,
1310,
6243,
356,
1177,
6243,
93,
267,
776,
272,
587,
26,
267,
1824,
275,
10902,
2821,
8,
1069,
14,
4030,
12,
1256,
29,
842,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
288,
1824,
14,
2117,
342,
267,
372,
4660,
360,
10696,
26,
2778,
63,
513,
358,
421,
199,
533,
10902,
5392,
8,
5392,
2768,
304,
272,
1402,
275,
10902,
272,
1978,
63,
354,
275,
283,
12022,
15,
9548,
63,
1807,
14,
1360,
7,
272,
3182,
63,
633,
275,
3837,
63,
6395,
360,
10696,
26,
2778,
63,
513,
358,
339,
768,
765,
63,
11547,
8,
2886,
63,
2427,
9,
272,
347,
7634,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
1613,
8,
11613,
5392,
12,
291,
680,
6052,
2031,
589,
12,
1011,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
urandu/rethinkdb
|
test/rql_test/connections/http_support/jinja2/testsuite/utils.py
|
415
|
2235
|
# -*- coding: utf-8 -*-
"""
jinja2.testsuite.utils
~~~~~~~~~~~~~~~~~~~~~~
Tests utilities jinja uses.
:copyright: (c) 2010 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
import gc
import unittest
import pickle
from jinja2.testsuite import JinjaTestCase
from jinja2.utils import LRUCache, escape, object_type_repr
class LRUCacheTestCase(JinjaTestCase):
def test_simple(self):
d = LRUCache(3)
d["a"] = 1
d["b"] = 2
d["c"] = 3
d["a"]
d["d"] = 4
assert len(d) == 3
assert 'a' in d and 'c' in d and 'd' in d and 'b' not in d
def test_pickleable(self):
cache = LRUCache(2)
cache["foo"] = 42
cache["bar"] = 23
cache["foo"]
for protocol in range(3):
copy = pickle.loads(pickle.dumps(cache, protocol))
assert copy.capacity == cache.capacity
assert copy._mapping == cache._mapping
assert copy._queue == cache._queue
class HelpersTestCase(JinjaTestCase):
def test_object_type_repr(self):
class X(object):
pass
self.assert_equal(object_type_repr(42), 'int object')
self.assert_equal(object_type_repr([]), 'list object')
self.assert_equal(object_type_repr(X()),
'jinja2.testsuite.utils.X object')
self.assert_equal(object_type_repr(None), 'None')
self.assert_equal(object_type_repr(Ellipsis), 'Ellipsis')
class MarkupLeakTestCase(JinjaTestCase):
def test_markup_leaks(self):
counts = set()
for count in range(20):
for item in range(1000):
escape("foo")
escape("<foo>")
escape(u"foo")
escape(u"<foo>")
counts.add(len(gc.get_objects()))
assert len(counts) == 1, 'ouch, c extension seems to leak objects'
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(LRUCacheTestCase))
suite.addTest(unittest.makeSuite(HelpersTestCase))
# this test only tests the c extension
if not hasattr(escape, 'func_code'):
suite.addTest(unittest.makeSuite(MarkupLeakTestCase))
return suite
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10321,
18,
14,
14239,
14,
1208,
272,
18294,
2878,
1714,
339,
6496,
15841,
10321,
4440,
14,
339,
520,
7307,
26,
334,
67,
9,
7129,
701,
314,
17300,
11682,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
9486,
199,
646,
2882,
199,
199,
646,
5927,
199,
199,
504,
10321,
18,
14,
14239,
492,
17300,
1746,
199,
199,
504,
10321,
18,
14,
1208,
492,
491,
9500,
4437,
12,
4772,
12,
909,
63,
466,
63,
2722,
421,
199,
533,
491,
9500,
4437,
1746,
8,
42,
4135,
1746,
304,
339,
347,
511,
63,
4129,
8,
277,
304,
267,
366,
275,
491,
9500,
4437,
8,
19,
9,
267,
366,
905,
65,
937,
275,
413,
267,
366,
905,
66,
937,
275,
499,
267,
366,
905,
67,
937,
275,
650,
267,
366,
905,
65,
937,
267,
366,
905,
68,
937,
275,
841,
267,
702,
822,
8,
68,
9,
508,
650,
267,
702,
283,
65,
7,
315,
366,
436,
283,
67,
7,
315,
366,
436,
283,
68,
7,
315,
366,
436,
283,
66,
7,
440,
315,
366,
339,
347,
511,
63,
8092,
461,
8,
277,
304,
267,
2581,
275,
491,
9500,
4437,
8,
18,
9,
267,
2581,
905,
1421,
937,
275,
5685,
267,
2581,
905,
1700,
937,
275,
6546,
267,
2581,
905,
1421,
937,
398,
367,
4113,
315,
1425,
8,
19,
304,
288,
1331,
275,
5927,
14,
3640,
8,
8092,
14,
4180,
8,
1637,
12,
4113,
430,
288,
702,
1331,
14,
10457,
508,
2581,
14,
10457,
288,
702,
1331,
423,
4745,
508,
2581,
423,
4745,
288,
702,
1331,
423,
1825,
508,
2581,
423,
1825,
421,
199,
533,
11642,
83,
1746,
8,
42,
4135,
1746,
304,
339,
347,
511,
63,
785,
63,
466,
63,
2722,
8,
277,
304,
267,
1021,
1323,
8,
785,
304,
288,
986,
267,
291,
14,
479,
63,
1452,
8,
785,
63,
466,
63,
2722,
8,
2260,
395,
283,
442,
909,
358,
267,
291,
14,
479,
63,
1452,
8,
785,
63,
466,
63,
2722,
25550,
283,
513,
909,
358,
267,
291,
14,
479,
63,
1452,
8,
785,
63,
466,
63,
2722,
8,
56,
4000,
586,
283,
12264,
18,
14,
14239,
14,
1208,
14,
56,
909,
358,
267,
291,
14,
479,
63,
1452,
8,
785,
63,
466,
63,
2722,
8,
403,
395,
283,
403,
358,
267,
291,
14,
479,
63,
1452,
8,
785,
63,
466,
63,
2722,
8,
23525,
2316,
395,
283,
23525,
2316,
358,
421,
199,
533,
17504,
2553,
1151,
1746,
8,
42,
4135,
1746,
304,
339,
347,
511,
63,
10131,
63,
28477,
8,
277,
304,
267,
8242,
275,
663,
342,
267,
367,
2338,
315,
1425,
8,
1165,
304,
288,
367,
1242,
315,
1425,
8,
5279,
304,
355,
4772,
480,
1421,
531,
355,
4772,
6757,
1421,
9579,
355,
4772,
8,
85,
2,
1421,
531,
355,
4772,
8,
85,
17030,
1421,
9579,
288,
8242,
14,
525,
8,
552,
8,
9493,
14,
362,
63,
1462,
4059,
267,
702,
822,
8,
6851,
9,
508,
413,
12,
283,
13087,
12,
286,
3329,
12237,
370,
25831,
2251,
7,
421,
199,
318,
5241,
837,
272,
5241,
275,
2882,
14,
10591,
342,
272,
5241,
14,
15714,
8,
2796,
14,
18275,
8,
44,
9500,
4437,
1746,
430,
272,
5241,
14,
15714,
8,
2796,
14,
18275,
8,
4433,
83,
1746,
430,
339,
327,
642,
511,
1454,
2295,
314,
286,
3329,
272,
340,
440,
2688,
8,
3765,
12,
283,
1532,
63,
600,
735,
267,
5241,
14,
15714,
8,
2796,
14,
18275,
8,
23393,
2553,
1151,
1746,
430,
339,
372,
5241,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
10321,
18,
14,
14239,
14,
1208,
272,
18294,
2878,
1714,
339,
6496,
15841,
10321,
4440,
14,
339,
520,
7307,
26,
334,
67,
9,
7129,
701,
314,
17300,
11682,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
9486,
199,
646,
2882,
199,
199,
646,
5927,
199,
199,
504,
10321,
18,
14,
14239,
492,
17300,
1746,
199,
199,
504,
10321,
18,
14,
1208,
492,
491,
9500,
4437,
12,
4772,
12,
909,
63,
466,
63,
2722,
421,
199,
533,
491,
9500,
4437,
1746,
8,
42,
4135,
1746,
304,
339,
347,
511,
63,
4129,
8,
277,
304,
267,
366,
275,
491,
9500,
4437,
8,
19,
9,
267,
366,
905,
65,
937,
275,
413,
267,
366,
905,
66,
937,
275,
499,
267,
366,
905,
67,
937,
275,
650,
267,
366,
905,
65,
937,
267,
366,
905,
68,
937,
275,
841,
267,
702,
822,
8,
68,
9,
508,
650,
267,
702,
283,
65,
7,
315,
366,
436,
283,
67,
7,
315,
366,
436,
283,
68,
7,
315,
366,
436,
283,
66,
7,
440,
315,
366,
339,
347,
511,
63,
8092,
461,
8,
277,
304,
267,
2581,
275,
491,
9500,
4437,
8,
18,
9,
267,
2581,
905,
1421,
937,
275,
5685,
267,
2581,
905,
1700,
937,
275,
6546,
267,
2581,
905,
1421,
937,
398,
367,
4113,
315,
1425,
8,
19,
304,
288,
1331,
275,
5927,
14,
3640,
8,
8092,
14,
4180,
8,
1637,
12,
4113,
430,
288,
702,
1331,
14,
10457,
508,
2581,
14,
10457,
288,
702,
1331,
423,
4745,
508,
2581,
423,
4745,
288,
702,
1331,
423,
1825,
508,
2581,
423,
1825,
421,
199,
533,
11642,
83,
1746,
8,
42,
4135,
1746,
304,
339,
347,
511,
63,
785,
63,
466,
63,
2722,
8,
277,
304,
267,
1021,
1323,
8,
785,
304,
288,
986,
267,
291,
14,
479,
63,
1452,
8,
785,
63,
466,
63,
2722,
8,
2260,
395,
283,
442,
909,
358,
267,
291,
14,
479,
63,
1452,
8,
785,
63,
466,
63,
2722,
25550,
283,
513,
909,
358,
267,
291,
14,
479,
63,
1452,
8,
785,
63,
466,
63,
2722,
8,
56,
4000,
586,
283,
12264,
18,
14,
14239,
14,
1208,
14,
56,
909,
358,
267,
291,
14,
479,
63,
1452,
8,
785,
63,
466,
63,
2722,
8,
403,
395,
283,
403,
358,
267,
291,
14,
479,
63,
1452,
8,
785,
63,
466,
63,
2722,
8,
23525,
2316,
395,
283,
23525,
2316,
358,
421,
199,
533,
17504,
2553,
1151,
1746,
8,
42,
4135,
1746,
304,
339,
347,
511,
63,
10131,
63,
28477,
8,
277,
304,
267,
8242,
275,
663,
342,
267,
367,
2338,
315,
1425,
8,
1165,
304,
288,
367,
1242,
315,
1425,
8,
5279,
304,
355,
4772,
480,
1421,
531,
355,
4772,
6757,
1421,
9579,
355,
4772,
8,
85,
2,
1421,
531,
355,
4772,
8,
85,
17030,
1421,
9579,
288,
8242,
14,
525,
8,
552,
8,
9493,
14,
362,
63,
1462,
4059,
267,
702,
822,
8,
6851,
9,
508,
413,
12,
283,
13087,
12,
286,
3329,
12237,
370,
25831,
2251,
7,
421,
199,
318,
5241,
837,
272,
5241,
275,
2882,
14,
10591,
342,
272,
5241,
14,
15714,
8,
2796,
14,
18275,
8,
44,
9500,
4437,
1746,
430,
272,
5241,
14,
15714,
8,
2796,
14,
18275,
8,
4433,
83,
1746,
430,
339,
327,
642,
511,
1454,
2295,
314,
286,
3329,
272,
340,
440,
2688,
8,
3765,
12,
283,
1532,
63,
600,
735,
267,
5241,
14,
15714,
8,
2796,
14,
18275,
8,
23393,
2553,
1151,
1746,
430,
339,
372,
5241,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
percyfal/bokeh
|
bokeh/models/axes.py
|
2
|
5823
|
''' Guide renderers for various kinds of axes that can be added to
Bokeh plots
'''
from __future__ import absolute_import
from ..core.has_props import abstract
from ..core.properties import Auto, Datetime, Dict, Either, Enum, Float, Include, Instance, Int, Override, Seq, String, Tuple
from ..core.property_mixins import LineProps, TextProps
from .formatters import BasicTickFormatter, CategoricalTickFormatter, DatetimeTickFormatter, LogTickFormatter, TickFormatter
from .renderers import GuideRenderer
from .tickers import Ticker, BasicTicker, LogTicker, CategoricalTicker, DatetimeTicker, FixedTicker
@abstract
class Axis(GuideRenderer):
''' A base class that defines common properties for all axis types.
'''
bounds = Either(Auto, Tuple(Float, Float), Tuple(Datetime, Datetime), help="""
Bounds for the rendered axis. If unset, the axis will span the
entire plot in the given dimension.
""")
x_range_name = String('default', help="""
A particular (named) x-range to use for computing screen
locations when rendering an axis on the plot. If unset, use the
default x-range.
""")
y_range_name = String('default', help="""
A particular (named) y-range to use for computing screen
locations when rendering an axis on the plot. If unset, use the
default y-range.
""")
ticker = Instance(Ticker, help="""
A Ticker to use for computing locations of axis components.
The property may also be passed a sequence of floating point numbers as
a shorthand for creating and configuring a ``FixedTicker``, e.g. the
following code
.. code-block:: python
from bokeh.plotting import figure
p = figure()
p.xaxis.ticker = [10, 20, 37.4]
is equivalent to:
.. code-block:: python
from bokeh.plotting import figure
from bokeh.models.tickers import FixedTicker
p = figure()
p.xaxis.ticker = FixedTicker(ticks=[10, 20, 37.4])
""").accepts(Seq(Float), lambda ticks: FixedTicker(ticks=ticks))
formatter = Instance(TickFormatter, help="""
A TickFormatter to use for formatting the visual appearance
of ticks.
""")
axis_label = String(default='', help="""
A text label for the axis, displayed parallel to the axis rule.
.. note::
LaTeX notation is not currently supported; please see
:bokeh-issue:`647` to track progress or contribute.
""")
axis_label_standoff = Int(default=5, help="""
The distance in pixels that the axis labels should be offset
from the tick labels.
""")
axis_label_props = Include(TextProps, help="""
The %s of the axis label.
""")
axis_label_text_font_size = Override(default={'value': "10pt"})
axis_label_text_font_style = Override(default="italic")
major_label_standoff = Int(default=5, help="""
The distance in pixels that the major tick labels should be
offset from the associated ticks.
""")
major_label_orientation = Either(Enum("horizontal", "vertical"), Float, help="""
What direction the major label text should be oriented. If a
number is supplied, the angle of the text is measured from horizontal.
""")
major_label_overrides = Dict(Either(Float, String), String, default={}, help="""
Provide explicit tick label values for specific tick locations that
override normal formatting.
""")
major_label_props = Include(TextProps, help="""
The %s of the major tick labels.
""")
major_label_text_align = Override(default="center")
major_label_text_baseline = Override(default="alphabetic")
major_label_text_font_size = Override(default={'value': "8pt"})
axis_props = Include(LineProps, help="""
The %s of the axis line.
""")
major_tick_props = Include(LineProps, help="""
The %s of the major ticks.
""")
major_tick_in = Int(default=2, help="""
The distance in pixels that major ticks should extend into the
main plot area.
""")
major_tick_out = Int(default=6, help="""
The distance in pixels that major ticks should extend out of the
main plot area.
""")
minor_tick_props = Include(LineProps, help="""
The %s of the minor ticks.
""")
minor_tick_in = Int(default=0, help="""
The distance in pixels that minor ticks should extend into the
main plot area.
""")
minor_tick_out = Int(default=4, help="""
The distance in pixels that major ticks should extend out of the
main plot area.
""")
@abstract
class ContinuousAxis(Axis):
''' A base class for all numeric, non-categorical axes types.
'''
pass
class LinearAxis(ContinuousAxis):
''' An axis that picks nice numbers for tick locations on a
linear scale. Configured with a ``BasicTickFormatter`` by default.
'''
ticker = Override(default=lambda: BasicTicker())
formatter = Override(default=lambda: BasicTickFormatter())
class LogAxis(ContinuousAxis):
''' An axis that picks nice numbers for tick locations on a
log scale. Configured with a ``LogTickFormatter`` by default.
'''
ticker = Override(default=lambda: LogTicker())
formatter = Override(default=lambda: LogTickFormatter())
class CategoricalAxis(Axis):
''' An axis that picks evenly spaced tick locations for a
collection of categories/factors.
'''
ticker = Override(default=lambda: CategoricalTicker())
formatter = Override(default=lambda: CategoricalTickFormatter())
class DatetimeAxis(LinearAxis):
''' An LinearAxis that picks nice numbers for tick locations on
a datetime scale. Configured with a ``DatetimeTickFormatter`` by
default.
'''
ticker = Override(default=lambda: DatetimeTicker())
formatter = Override(default=lambda: DatetimeTickFormatter())
|
bsd-3-clause
|
[
2344,
15423,
2903,
26529,
367,
7750,
24241,
402,
7824,
626,
883,
506,
3483,
370,
199,
2208,
16610,
19695,
199,
199,
2344,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
2508,
1018,
14,
1989,
63,
6750,
492,
9006,
199,
504,
2508,
1018,
14,
3282,
492,
9195,
12,
29825,
12,
7448,
12,
13083,
12,
11305,
12,
11140,
12,
15783,
12,
10066,
12,
9805,
12,
11041,
12,
28534,
12,
2624,
12,
11634,
199,
504,
2508,
1018,
14,
1829,
63,
30192,
492,
7030,
24188,
12,
4516,
24188,
199,
199,
504,
1275,
24270,
492,
10082,
11763,
7772,
12,
31227,
11763,
7772,
12,
29825,
11763,
7772,
12,
5297,
11763,
7772,
12,
18742,
7772,
199,
504,
1275,
828,
26529,
492,
15423,
11355,
199,
504,
1275,
8284,
1192,
492,
18742,
281,
12,
10082,
11763,
281,
12,
5297,
11763,
281,
12,
31227,
11763,
281,
12,
29825,
11763,
281,
12,
18659,
11763,
281,
199,
199,
32,
6198,
199,
533,
23205,
8,
4324,
271,
11355,
304,
272,
1449,
437,
1300,
1021,
626,
7890,
2863,
4382,
367,
1006,
3114,
2943,
14,
339,
1449,
339,
10461,
275,
13083,
8,
3358,
12,
11634,
8,
5136,
12,
11140,
395,
11634,
8,
19636,
12,
29825,
395,
1720,
11916,
272,
21972,
83,
367,
314,
8018,
3114,
14,
982,
15376,
12,
314,
3114,
911,
13598,
314,
272,
8039,
5137,
315,
314,
1627,
6240,
14,
272,
7857,
339,
671,
63,
1842,
63,
354,
275,
2624,
360,
885,
297,
1720,
11916,
272,
437,
6770,
334,
4579,
9,
671,
13,
1842,
370,
675,
367,
17226,
6426,
272,
9918,
1380,
14066,
376,
3114,
641,
314,
5137,
14,
982,
15376,
12,
675,
314,
272,
849,
671,
13,
1842,
14,
272,
7857,
339,
612,
63,
1842,
63,
354,
275,
2624,
360,
885,
297,
1720,
11916,
272,
437,
6770,
334,
4579,
9,
612,
13,
1842,
370,
675,
367,
17226,
6426,
272,
9918,
1380,
14066,
376,
3114,
641,
314,
5137,
14,
982,
15376,
12,
675,
314,
272,
849,
612,
13,
1842,
14,
272,
7857,
339,
32721,
275,
10066,
8,
11763,
281,
12,
1720,
11916,
272,
437,
18742,
281,
370,
675,
367,
17226,
9918,
402,
3114,
7323,
14,
339,
710,
3324,
1443,
2597,
506,
3032,
282,
3414,
402,
8402,
2376,
5579,
465,
272,
282,
1033,
23999,
367,
6425,
436,
1101,
4039,
282,
1124,
9515,
11763,
281,
4542,
325,
14,
71,
14,
314,
272,
2569,
1233,
339,
2508,
1233,
13,
1457,
447,
2366,
398,
687,
25214,
14,
2798,
1337,
492,
9658,
398,
299,
275,
9658,
342,
267,
299,
14,
21854,
14,
28572,
275,
359,
709,
12,
3388,
12,
6877,
14,
20,
61,
339,
365,
7353,
370,
26,
339,
2508,
1233,
13,
1457,
447,
2366,
398,
687,
25214,
14,
2798,
1337,
492,
9658,
267,
687,
25214,
14,
992,
14,
8284,
1192,
492,
18659,
11763,
281,
398,
299,
275,
9658,
342,
267,
299,
14,
21854,
14,
28572,
275,
18659,
11763,
281,
8,
10406,
1524,
709,
12,
3388,
12,
6877,
14,
20,
566,
339,
408,
680,
27692,
8,
11205,
8,
5136,
395,
2400,
17779,
26,
18659,
11763,
281,
8,
10406,
29,
10406,
430,
339,
9698,
275,
10066,
8,
11763,
7772,
12,
1720,
11916,
272,
437,
18742,
7772,
370,
675,
367,
10803,
314,
13104,
7468,
554,
272,
402,
17779,
14,
272,
7857,
339,
3114,
63,
1302,
275,
2624,
8,
885,
4581,
1720,
11916,
272,
437,
1318,
1768,
367,
314,
3114,
12,
9080,
9861,
370,
314,
3114,
2332,
14,
339,
2508,
5317,
447,
267,
14081,
15843,
365,
440,
5544,
3748,
27,
8749,
1937,
267,
520,
656,
16610,
13,
5237,
1705,
8557,
64,
370,
4426,
6696,
503,
28567,
14,
339,
7857,
339,
3114,
63,
1302,
63,
7935,
1997,
275,
9805,
8,
885,
29,
21,
12,
1720,
11916,
272,
710,
6033,
315,
11094,
626,
314,
3114,
3628,
1077,
506,
3268,
272,
687,
314,
11748,
3628,
14,
272,
7857,
339,
3114,
63,
1302,
63,
6750,
275,
15783,
8,
1872,
24188,
12,
1720,
11916,
272,
710,
450,
83,
402,
314,
3114,
1768,
14,
272,
7857,
339,
3114,
63,
1302,
63,
505,
63,
4246,
63,
890,
275,
11041,
8,
885,
3713,
585,
356,
298,
709,
541,
5984,
339,
3114,
63,
1302,
63,
505,
63,
4246,
63,
2487,
275,
11041,
8,
885,
628,
21843,
531,
339,
12160,
63,
1302,
63,
7935,
1997,
275,
9805,
8,
885,
29,
21,
12,
1720,
11916,
272,
710,
6033,
315,
11094,
626,
314,
12160,
11748,
3628,
1077,
506,
272,
3268,
687,
314,
4568,
17779,
14,
272,
7857,
339,
12160,
63,
1302,
63,
17001,
275,
13083,
8,
5081,
480,
11392,
401,
298,
7870,
1288,
11140,
12,
1720,
11916,
272,
14791,
7581,
314,
12160,
1768,
1318,
1077,
506,
503,
24555,
471,
14,
982,
282,
272,
1329,
365,
6841,
12,
314,
9324,
402,
314,
1318,
365,
27396,
687,
17528,
14,
272,
7857,
339,
12160,
63,
1302,
63,
12867,
275,
7448,
8,
37,
1711,
8,
5136,
12,
2624,
395,
2624,
12,
849,
10324,
1720,
11916,
272,
22896,
5027,
11748,
1768,
1338,
367,
2488,
11748,
9918,
626,
272,
4278,
3293,
10803,
14,
272,
7857,
339,
12160,
63,
1302,
63,
6750,
275,
15783,
8,
1872,
24188,
12,
1720,
11916,
272,
710,
450,
83,
402,
314,
12160,
11748,
3628,
14,
272,
7857,
339,
12160,
63,
1302,
63,
505,
63,
5743,
275,
11041,
8,
885,
628,
4218,
531,
339,
12160,
63,
1302,
63,
505,
63,
14232,
275,
11041,
8,
885,
628,
10305,
7570,
764,
531,
339,
12160,
63,
1302,
63,
505,
63,
4246,
63,
890,
275,
11041,
8,
885,
3713,
585,
356,
298,
24,
541,
5984,
339,
3114,
63,
6750,
275,
15783,
8,
3049,
24188,
12,
1720,
11916,
272,
710,
450,
83,
402,
314,
3114,
1004,
14,
272,
7857,
339,
12160,
63,
8284,
63,
6750,
275,
15783,
8,
3049,
24188,
12,
1720,
11916,
272,
710,
450,
83,
402,
314,
12160,
17779,
14,
272,
7857,
339,
12160,
63,
8284,
63,
262,
275,
9805,
8,
885,
29,
18,
12,
1720,
11916,
272,
710,
6033,
315,
11094,
626,
12160,
17779,
1077,
12247,
1901,
314,
272,
2446,
5137,
9150,
14,
272,
7857,
339,
12160,
63,
8284,
63,
548,
275,
9805,
8,
885,
29,
22,
12,
1720,
11916,
272,
710,
6033,
315,
11094,
626,
12160,
17779,
1077,
12247,
734,
402,
314,
272,
2446,
5137,
9150,
14,
272,
7857,
339,
12612,
63,
8284,
63,
6750,
275,
15783,
8,
3049,
24188,
12,
1720,
11916,
272,
710,
450,
83,
402
] |
[
15423,
2903,
26529,
367,
7750,
24241,
402,
7824,
626,
883,
506,
3483,
370,
199,
2208,
16610,
19695,
199,
199,
2344,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
2508,
1018,
14,
1989,
63,
6750,
492,
9006,
199,
504,
2508,
1018,
14,
3282,
492,
9195,
12,
29825,
12,
7448,
12,
13083,
12,
11305,
12,
11140,
12,
15783,
12,
10066,
12,
9805,
12,
11041,
12,
28534,
12,
2624,
12,
11634,
199,
504,
2508,
1018,
14,
1829,
63,
30192,
492,
7030,
24188,
12,
4516,
24188,
199,
199,
504,
1275,
24270,
492,
10082,
11763,
7772,
12,
31227,
11763,
7772,
12,
29825,
11763,
7772,
12,
5297,
11763,
7772,
12,
18742,
7772,
199,
504,
1275,
828,
26529,
492,
15423,
11355,
199,
504,
1275,
8284,
1192,
492,
18742,
281,
12,
10082,
11763,
281,
12,
5297,
11763,
281,
12,
31227,
11763,
281,
12,
29825,
11763,
281,
12,
18659,
11763,
281,
199,
199,
32,
6198,
199,
533,
23205,
8,
4324,
271,
11355,
304,
272,
1449,
437,
1300,
1021,
626,
7890,
2863,
4382,
367,
1006,
3114,
2943,
14,
339,
1449,
339,
10461,
275,
13083,
8,
3358,
12,
11634,
8,
5136,
12,
11140,
395,
11634,
8,
19636,
12,
29825,
395,
1720,
11916,
272,
21972,
83,
367,
314,
8018,
3114,
14,
982,
15376,
12,
314,
3114,
911,
13598,
314,
272,
8039,
5137,
315,
314,
1627,
6240,
14,
272,
7857,
339,
671,
63,
1842,
63,
354,
275,
2624,
360,
885,
297,
1720,
11916,
272,
437,
6770,
334,
4579,
9,
671,
13,
1842,
370,
675,
367,
17226,
6426,
272,
9918,
1380,
14066,
376,
3114,
641,
314,
5137,
14,
982,
15376,
12,
675,
314,
272,
849,
671,
13,
1842,
14,
272,
7857,
339,
612,
63,
1842,
63,
354,
275,
2624,
360,
885,
297,
1720,
11916,
272,
437,
6770,
334,
4579,
9,
612,
13,
1842,
370,
675,
367,
17226,
6426,
272,
9918,
1380,
14066,
376,
3114,
641,
314,
5137,
14,
982,
15376,
12,
675,
314,
272,
849,
612,
13,
1842,
14,
272,
7857,
339,
32721,
275,
10066,
8,
11763,
281,
12,
1720,
11916,
272,
437,
18742,
281,
370,
675,
367,
17226,
9918,
402,
3114,
7323,
14,
339,
710,
3324,
1443,
2597,
506,
3032,
282,
3414,
402,
8402,
2376,
5579,
465,
272,
282,
1033,
23999,
367,
6425,
436,
1101,
4039,
282,
1124,
9515,
11763,
281,
4542,
325,
14,
71,
14,
314,
272,
2569,
1233,
339,
2508,
1233,
13,
1457,
447,
2366,
398,
687,
25214,
14,
2798,
1337,
492,
9658,
398,
299,
275,
9658,
342,
267,
299,
14,
21854,
14,
28572,
275,
359,
709,
12,
3388,
12,
6877,
14,
20,
61,
339,
365,
7353,
370,
26,
339,
2508,
1233,
13,
1457,
447,
2366,
398,
687,
25214,
14,
2798,
1337,
492,
9658,
267,
687,
25214,
14,
992,
14,
8284,
1192,
492,
18659,
11763,
281,
398,
299,
275,
9658,
342,
267,
299,
14,
21854,
14,
28572,
275,
18659,
11763,
281,
8,
10406,
1524,
709,
12,
3388,
12,
6877,
14,
20,
566,
339,
408,
680,
27692,
8,
11205,
8,
5136,
395,
2400,
17779,
26,
18659,
11763,
281,
8,
10406,
29,
10406,
430,
339,
9698,
275,
10066,
8,
11763,
7772,
12,
1720,
11916,
272,
437,
18742,
7772,
370,
675,
367,
10803,
314,
13104,
7468,
554,
272,
402,
17779,
14,
272,
7857,
339,
3114,
63,
1302,
275,
2624,
8,
885,
4581,
1720,
11916,
272,
437,
1318,
1768,
367,
314,
3114,
12,
9080,
9861,
370,
314,
3114,
2332,
14,
339,
2508,
5317,
447,
267,
14081,
15843,
365,
440,
5544,
3748,
27,
8749,
1937,
267,
520,
656,
16610,
13,
5237,
1705,
8557,
64,
370,
4426,
6696,
503,
28567,
14,
339,
7857,
339,
3114,
63,
1302,
63,
7935,
1997,
275,
9805,
8,
885,
29,
21,
12,
1720,
11916,
272,
710,
6033,
315,
11094,
626,
314,
3114,
3628,
1077,
506,
3268,
272,
687,
314,
11748,
3628,
14,
272,
7857,
339,
3114,
63,
1302,
63,
6750,
275,
15783,
8,
1872,
24188,
12,
1720,
11916,
272,
710,
450,
83,
402,
314,
3114,
1768,
14,
272,
7857,
339,
3114,
63,
1302,
63,
505,
63,
4246,
63,
890,
275,
11041,
8,
885,
3713,
585,
356,
298,
709,
541,
5984,
339,
3114,
63,
1302,
63,
505,
63,
4246,
63,
2487,
275,
11041,
8,
885,
628,
21843,
531,
339,
12160,
63,
1302,
63,
7935,
1997,
275,
9805,
8,
885,
29,
21,
12,
1720,
11916,
272,
710,
6033,
315,
11094,
626,
314,
12160,
11748,
3628,
1077,
506,
272,
3268,
687,
314,
4568,
17779,
14,
272,
7857,
339,
12160,
63,
1302,
63,
17001,
275,
13083,
8,
5081,
480,
11392,
401,
298,
7870,
1288,
11140,
12,
1720,
11916,
272,
14791,
7581,
314,
12160,
1768,
1318,
1077,
506,
503,
24555,
471,
14,
982,
282,
272,
1329,
365,
6841,
12,
314,
9324,
402,
314,
1318,
365,
27396,
687,
17528,
14,
272,
7857,
339,
12160,
63,
1302,
63,
12867,
275,
7448,
8,
37,
1711,
8,
5136,
12,
2624,
395,
2624,
12,
849,
10324,
1720,
11916,
272,
22896,
5027,
11748,
1768,
1338,
367,
2488,
11748,
9918,
626,
272,
4278,
3293,
10803,
14,
272,
7857,
339,
12160,
63,
1302,
63,
6750,
275,
15783,
8,
1872,
24188,
12,
1720,
11916,
272,
710,
450,
83,
402,
314,
12160,
11748,
3628,
14,
272,
7857,
339,
12160,
63,
1302,
63,
505,
63,
5743,
275,
11041,
8,
885,
628,
4218,
531,
339,
12160,
63,
1302,
63,
505,
63,
14232,
275,
11041,
8,
885,
628,
10305,
7570,
764,
531,
339,
12160,
63,
1302,
63,
505,
63,
4246,
63,
890,
275,
11041,
8,
885,
3713,
585,
356,
298,
24,
541,
5984,
339,
3114,
63,
6750,
275,
15783,
8,
3049,
24188,
12,
1720,
11916,
272,
710,
450,
83,
402,
314,
3114,
1004,
14,
272,
7857,
339,
12160,
63,
8284,
63,
6750,
275,
15783,
8,
3049,
24188,
12,
1720,
11916,
272,
710,
450,
83,
402,
314,
12160,
17779,
14,
272,
7857,
339,
12160,
63,
8284,
63,
262,
275,
9805,
8,
885,
29,
18,
12,
1720,
11916,
272,
710,
6033,
315,
11094,
626,
12160,
17779,
1077,
12247,
1901,
314,
272,
2446,
5137,
9150,
14,
272,
7857,
339,
12160,
63,
8284,
63,
548,
275,
9805,
8,
885,
29,
22,
12,
1720,
11916,
272,
710,
6033,
315,
11094,
626,
12160,
17779,
1077,
12247,
734,
402,
314,
272,
2446,
5137,
9150,
14,
272,
7857,
339,
12612,
63,
8284,
63,
6750,
275,
15783,
8,
3049,
24188,
12,
1720,
11916,
272,
710,
450,
83,
402,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
ryancanhelpyou/servo
|
tests/wpt/web-platform-tests/webdriver/javascript/execute_script_test.py
|
65
|
5664
|
import os
import sys
import unittest
sys.path.insert(1, os.path.abspath(os.path.join(__file__, "../..")))
import base_test
class ExecuteScriptTest(base_test.WebDriverBaseTest):
def test_ecmascript_translates_null_return_to_none(self):
self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html"))
result = self.driver.execute_script("return null;")
self.assertIsNone(result)
def test_ecmascript_translates_undefined_return_to_none(self):
self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html"))
result = self.driver.execute_script("var undef; return undef;")
self.assertIsNone(result)
def test_can_return_numbers_from_scripts(self):
self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html"))
self.assertEquals(1, self.driver.execute_script("return 1;"))
self.assertEquals(3.14, self.driver.execute_script("return 3.14;"))
def test_can_return_strings_from_scripts(self):
self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html"))
self.assertEquals("hello, world!",
self.driver.execute_script("return 'hello, world!'"))
def test_can_return_booleans_from_scripts(self):
self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html"))
self.assertTrue(self.driver.execute_script("return true;"))
self.assertFalse(self.driver.execute_script("return false;"))
def test_can_return_an_array_of_primitives(self):
self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html"))
result = self.driver.execute_script("return [1, false, null, 3.14]")
self.assertListEqual([1, False, None, 3.14], result)
def test_can_return_nested_arrays(self):
self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html"))
result = self.driver.execute_script("return [[1, 2, [3]]]")
self.assertIsInstance(result, list)
self.assertEquals(1, len(result))
result = result[0]
self.assertListEqual([1, 2], result[:2])
self.assertListEqual([3], result[2])
def test_can_return_object_literals(self):
self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html"))
result = self.driver.execute_script("return {}")
self.assertDictEqual({}, result)
result = self.driver.execute_script("return {a: 1, b: false, c: null}")
self.assertDictEqual({
"a": 1,
"b": False,
"c": None
}, result)
def test_can_return_complex_object_literals(self):
self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html"))
result = self.driver.execute_script("return {a:{b: 'hello'}}")
self.assertIsInstance(result, dict)
self.assertIsInstance(result['a'], dict)
self.assertDictEqual({"b": "hello"}, result["a"])
def test_dom_element_return_value_is_translated_to_a_web_element(self):
self.driver.get(self.webserver.where_is(
"javascript/res/return_document_body.html"))
result = self.driver.execute_script("return document.body")
self.assertEquals(result.text, "Hello, world!")
def test_return_an_array_of_dom_elements(self):
self.driver.get(self.webserver.where_is(
"javascript/res/return_array_of_dom_elements.html"))
result = self.driver.execute_script(
"var nodes = document.getElementsByTagName('div');"
"return [nodes[0], nodes[1]]")
self.assertIsInstance(result, list)
self.assertEquals(2, len(result))
self.assertEquals("a", result[0].text)
self.assertEquals("b", result[1].text)
def test_node_list_return_value_is_translated_to_list_of_web_elements(self):
self.driver.get(self.webserver.where_is(
"javascript/res/return_array_of_dom_elements.html"))
result = self.driver.execute_script(
"return document.getElementsByTagName('div');")
self.assertIsInstance(result, list)
self.assertEquals(2, len(result))
self.assertEquals("a", result[0].text)
self.assertEquals("b", result[1].text)
def test_return_object_literal_with_dom_element_property(self):
self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html"))
result = self.driver.execute_script("return {a: document.body}")
self.assertIsInstance(result, dict)
self.assertEquals("body", result["a"].tag_name)
def test_scripts_execute_in_anonymous_function_and_do_not_pollute_global_scope(self):
self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html"))
self.driver.execute_script("var x = 1;")
self.assertEquals("undefined", self.driver.execute_script("return typeof x;"));
def test_scripts_can_modify_context_window_object(self):
self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html"))
self.driver.execute_script("window.x = 1;")
self.assertEquals("number", self.driver.execute_script("return typeof x;"));
self.assertEquals(1, self.driver.execute_script("return x;"));
def test_that_ecmascript_returns_document_title(self):
self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html"))
result = self.driver.execute_script("return document.title;")
self.assertEquals("executeScript test", result)
if __name__ == "__main__":
unittest.main()
|
mpl-2.0
|
[
646,
747,
199,
646,
984,
199,
646,
2882,
199,
199,
1274,
14,
515,
14,
3176,
8,
17,
12,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
3460,
493,
3108,
29024,
703,
13324,
199,
646,
1300,
63,
396,
421,
199,
533,
17009,
5229,
774,
8,
1095,
63,
396,
14,
27009,
23170,
304,
272,
347,
511,
63,
825,
5892,
1669,
63,
5275,
83,
63,
2307,
63,
1107,
63,
475,
63,
3592,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
267,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
2973,
15027,
267,
291,
14,
7702,
8,
1099,
9,
339,
347,
511,
63,
825,
5892,
1669,
63,
5275,
83,
63,
10705,
63,
1107,
63,
475,
63,
3592,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
267,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1391,
625,
318,
27,
372,
625,
318,
15027,
267,
291,
14,
7702,
8,
1099,
9,
339,
347,
511,
63,
2425,
63,
1107,
63,
10548,
63,
504,
63,
6429,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
267,
291,
14,
2947,
8,
17,
12,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
413,
27,
2237,
267,
291,
14,
2947,
8,
19,
14,
1079,
12,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
650,
14,
1079,
27,
2237,
339,
347,
511,
63,
2425,
63,
1107,
63,
5465,
63,
504,
63,
6429,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
267,
291,
14,
2947,
480,
5006,
12,
6701,
17716,
268,
7542,
221,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
283,
5006,
12,
6701,
11213,
2237,
339,
347,
511,
63,
2425,
63,
1107,
63,
15056,
274,
796,
63,
504,
63,
6429,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
267,
291,
14,
1815,
8,
277,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
2549,
27,
2237,
267,
291,
14,
3334,
8,
277,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
3055,
27,
2237,
339,
347,
511,
63,
2425,
63,
1107,
63,
290,
63,
1144,
63,
1618,
63,
1359,
22337,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
398,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
359,
17,
12,
3055,
12,
2973,
12,
650,
14,
1079,
12523,
267,
291,
14,
16671,
779,
17,
12,
756,
12,
488,
12,
650,
14,
1079,
467,
754,
9,
339,
347,
511,
63,
2425,
63,
1107,
63,
6376,
63,
10095,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
267,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
3474,
17,
12,
499,
12,
359,
19,
2677,
12523,
398,
291,
14,
6926,
8,
1099,
12,
769,
9,
267,
291,
14,
2947,
8,
17,
12,
822,
8,
1099,
430,
398,
754,
275,
754,
59,
16,
61,
267,
291,
14,
16671,
779,
17,
12,
499,
467,
754,
1491,
18,
566,
267,
291,
14,
16671,
779,
19,
467,
754,
59,
18,
566,
339,
347,
511,
63,
2425,
63,
1107,
63,
785,
63,
5955,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
398,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
1052,
531,
267,
291,
14,
19512,
16037,
754,
9,
398,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
469,
65,
26,
413,
12,
330,
26,
3055,
12,
286,
26,
2973,
15412,
267,
291,
14,
19512,
2561,
288,
298,
65,
582,
413,
12,
288,
298,
66,
582,
756,
12,
288,
298,
67,
582,
488,
267,
1660,
754,
9,
339,
347,
511,
63,
2425,
63,
1107,
63,
5254,
63,
785,
63,
5955,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
267,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
469,
65,
14534,
66,
26,
283,
5006,
936,
15412,
267,
291,
14,
6926,
8,
1099,
12,
1211,
9,
267,
291,
14,
6926,
8,
1099,
459,
65,
995,
1211,
9,
267,
291,
14,
19512,
6333,
66,
582,
298,
5006,
6018,
754,
905,
65,
3135,
339,
347,
511,
63,
4556,
63,
2108,
63,
1107,
63,
585,
63,
374,
63,
18065,
63,
475,
63,
65,
63,
2520,
63,
2108,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
8,
267,
1057,
198,
2,
9554,
15,
470,
15,
1107,
63,
3554,
63,
2030,
14,
1360,
2237,
398,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
2213,
14,
2030,
531,
267,
291,
14,
2947,
8,
1099,
14,
505,
12,
298,
6257,
12,
6701,
9124,
339,
347,
511,
63,
1107,
63,
290,
63,
1144,
63,
1618,
63,
4556,
63,
5527,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
8,
267,
1057,
198,
2,
9554,
15,
470,
15,
1107,
63,
1144,
63,
1618,
63,
4556,
63,
5527,
14,
1360,
2237,
398,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
8,
268,
198,
259,
298,
1391,
3380,
275,
2213,
14,
15045,
360,
3015,
358,
9426,
268,
198,
259,
298,
1107,
359,
2415,
59,
16,
467,
3380,
59,
17,
2677,
531,
398,
291,
14
] |
[
747,
199,
646,
984,
199,
646,
2882,
199,
199,
1274,
14,
515,
14,
3176,
8,
17,
12,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
3460,
493,
3108,
29024,
703,
13324,
199,
646,
1300,
63,
396,
421,
199,
533,
17009,
5229,
774,
8,
1095,
63,
396,
14,
27009,
23170,
304,
272,
347,
511,
63,
825,
5892,
1669,
63,
5275,
83,
63,
2307,
63,
1107,
63,
475,
63,
3592,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
267,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
2973,
15027,
267,
291,
14,
7702,
8,
1099,
9,
339,
347,
511,
63,
825,
5892,
1669,
63,
5275,
83,
63,
10705,
63,
1107,
63,
475,
63,
3592,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
267,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1391,
625,
318,
27,
372,
625,
318,
15027,
267,
291,
14,
7702,
8,
1099,
9,
339,
347,
511,
63,
2425,
63,
1107,
63,
10548,
63,
504,
63,
6429,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
267,
291,
14,
2947,
8,
17,
12,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
413,
27,
2237,
267,
291,
14,
2947,
8,
19,
14,
1079,
12,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
650,
14,
1079,
27,
2237,
339,
347,
511,
63,
2425,
63,
1107,
63,
5465,
63,
504,
63,
6429,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
267,
291,
14,
2947,
480,
5006,
12,
6701,
17716,
268,
7542,
221,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
283,
5006,
12,
6701,
11213,
2237,
339,
347,
511,
63,
2425,
63,
1107,
63,
15056,
274,
796,
63,
504,
63,
6429,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
267,
291,
14,
1815,
8,
277,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
2549,
27,
2237,
267,
291,
14,
3334,
8,
277,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
3055,
27,
2237,
339,
347,
511,
63,
2425,
63,
1107,
63,
290,
63,
1144,
63,
1618,
63,
1359,
22337,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
398,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
359,
17,
12,
3055,
12,
2973,
12,
650,
14,
1079,
12523,
267,
291,
14,
16671,
779,
17,
12,
756,
12,
488,
12,
650,
14,
1079,
467,
754,
9,
339,
347,
511,
63,
2425,
63,
1107,
63,
6376,
63,
10095,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
267,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
3474,
17,
12,
499,
12,
359,
19,
2677,
12523,
398,
291,
14,
6926,
8,
1099,
12,
769,
9,
267,
291,
14,
2947,
8,
17,
12,
822,
8,
1099,
430,
398,
754,
275,
754,
59,
16,
61,
267,
291,
14,
16671,
779,
17,
12,
499,
467,
754,
1491,
18,
566,
267,
291,
14,
16671,
779,
19,
467,
754,
59,
18,
566,
339,
347,
511,
63,
2425,
63,
1107,
63,
785,
63,
5955,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
398,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
1052,
531,
267,
291,
14,
19512,
16037,
754,
9,
398,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
469,
65,
26,
413,
12,
330,
26,
3055,
12,
286,
26,
2973,
15412,
267,
291,
14,
19512,
2561,
288,
298,
65,
582,
413,
12,
288,
298,
66,
582,
756,
12,
288,
298,
67,
582,
488,
267,
1660,
754,
9,
339,
347,
511,
63,
2425,
63,
1107,
63,
5254,
63,
785,
63,
5955,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
9554,
15,
470,
15,
2526,
63,
1579,
63,
396,
14,
1360,
2237,
267,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
469,
65,
14534,
66,
26,
283,
5006,
936,
15412,
267,
291,
14,
6926,
8,
1099,
12,
1211,
9,
267,
291,
14,
6926,
8,
1099,
459,
65,
995,
1211,
9,
267,
291,
14,
19512,
6333,
66,
582,
298,
5006,
6018,
754,
905,
65,
3135,
339,
347,
511,
63,
4556,
63,
2108,
63,
1107,
63,
585,
63,
374,
63,
18065,
63,
475,
63,
65,
63,
2520,
63,
2108,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
8,
267,
1057,
198,
2,
9554,
15,
470,
15,
1107,
63,
3554,
63,
2030,
14,
1360,
2237,
398,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
480,
1107,
2213,
14,
2030,
531,
267,
291,
14,
2947,
8,
1099,
14,
505,
12,
298,
6257,
12,
6701,
9124,
339,
347,
511,
63,
1107,
63,
290,
63,
1144,
63,
1618,
63,
4556,
63,
5527,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
8,
267,
1057,
198,
2,
9554,
15,
470,
15,
1107,
63,
1144,
63,
1618,
63,
4556,
63,
5527,
14,
1360,
2237,
398,
754,
275,
291,
14,
3090,
14,
2526,
63,
1579,
8,
268,
198,
259,
298,
1391,
3380,
275,
2213,
14,
15045,
360,
3015,
358,
9426,
268,
198,
259,
298,
1107,
359,
2415,
59,
16,
467,
3380,
59,
17,
2677,
531,
398,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hansey/youtube-dl
|
test/test_write_annotations.py
|
42
|
2546
|
#!/usr/bin/env python
# coding: utf-8
from __future__ import unicode_literals
# Allow direct execution
import os
import sys
import unittest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from test.helper import get_params, try_rm
import io
import xml.etree.ElementTree
import youtube_dl.YoutubeDL
import youtube_dl.extractor
class YoutubeDL(youtube_dl.YoutubeDL):
def __init__(self, *args, **kwargs):
super(YoutubeDL, self).__init__(*args, **kwargs)
self.to_stderr = self.to_screen
params = get_params({
'writeannotations': True,
'skip_download': True,
'writeinfojson': False,
'format': 'flv',
})
TEST_ID = 'gr51aVj-mLg'
ANNOTATIONS_FILE = TEST_ID + '.annotations.xml'
EXPECTED_ANNOTATIONS = ['Speech bubble', 'Note', 'Title', 'Spotlight', 'Label']
class TestAnnotations(unittest.TestCase):
def setUp(self):
# Clear old files
self.tearDown()
def test_info_json(self):
expected = list(EXPECTED_ANNOTATIONS) # Two annotations could have the same text.
ie = youtube_dl.extractor.YoutubeIE()
ydl = YoutubeDL(params)
ydl.add_info_extractor(ie)
ydl.download([TEST_ID])
self.assertTrue(os.path.exists(ANNOTATIONS_FILE))
annoxml = None
with io.open(ANNOTATIONS_FILE, 'r', encoding='utf-8') as annof:
annoxml = xml.etree.ElementTree.parse(annof)
self.assertTrue(annoxml is not None, 'Failed to parse annotations XML')
root = annoxml.getroot()
self.assertEqual(root.tag, 'document')
annotationsTag = root.find('annotations')
self.assertEqual(annotationsTag.tag, 'annotations')
annotations = annotationsTag.findall('annotation')
# Not all the annotations have TEXT children and the annotations are returned unsorted.
for a in annotations:
self.assertEqual(a.tag, 'annotation')
if a.get('type') == 'text':
textTag = a.find('TEXT')
text = textTag.text
self.assertTrue(text in expected) # assertIn only added in python 2.7
# remove the first occurance, there could be more than one annotation with the same text
expected.remove(text)
# We should have seen (and removed) all the expected annotation texts.
self.assertEqual(len(expected), 0, 'Not all expected annotations were found.')
def tearDown(self):
try_rm(ANNOTATIONS_FILE)
if __name__ == '__main__':
unittest.main()
|
unlicense
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
3,
9812,
4125,
6451,
199,
646,
747,
199,
646,
984,
199,
646,
2882,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
363,
7845,
199,
199,
504,
511,
14,
3676,
492,
664,
63,
1162,
12,
862,
63,
5682,
421,
199,
646,
5890,
199,
199,
646,
2748,
14,
9464,
14,
15325,
199,
199,
646,
22378,
63,
5030,
14,
57,
7715,
8045,
199,
646,
22378,
63,
5030,
14,
22677,
421,
199,
533,
1488,
7715,
8045,
8,
9788,
63,
5030,
14,
57,
7715,
8045,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
57,
7715,
8045,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
475,
63,
3083,
275,
291,
14,
475,
63,
5410,
199,
199,
1162,
275,
664,
63,
1162,
2561,
272,
283,
952,
11270,
356,
715,
12,
272,
283,
2759,
63,
4249,
356,
715,
12,
272,
283,
952,
815,
1001,
356,
756,
12,
272,
283,
908,
356,
283,
22753,
297,
199,
1552,
421,
199,
2864,
63,
998,
275,
283,
2587,
2869,
65,
54,
74,
13,
77,
44,
71,
7,
199,
879,
4609,
12969,
63,
3817,
275,
7393,
63,
998,
435,
1987,
11270,
14,
1652,
7,
199,
22358,
63,
879,
4609,
12969,
275,
788,
27047,
12736,
330,
21749,
297,
283,
7443,
297,
283,
6888,
297,
283,
5058,
357,
4040,
297,
283,
4314,
418,
421,
199,
533,
1379,
21761,
1298,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
327,
14836,
2269,
1584,
267,
291,
14,
12336,
342,
339,
347,
511,
63,
815,
63,
1001,
8,
277,
304,
267,
1420,
275,
769,
8,
22358,
63,
879,
4609,
12969,
9,
221,
327,
16853,
15538,
4293,
1172,
314,
2011,
1318,
14,
267,
13446,
275,
22378,
63,
5030,
14,
22677,
14,
57,
7715,
4332,
342,
267,
31676,
275,
1488,
7715,
8045,
8,
1162,
9,
267,
31676,
14,
525,
63,
815,
63,
22677,
8,
1873,
9,
267,
31676,
14,
4249,
779,
2864,
63,
998,
566,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
879,
4609,
12969,
63,
3817,
430,
267,
22984,
1652,
275,
488,
267,
543,
5890,
14,
1490,
8,
879,
4609,
12969,
63,
3817,
12,
283,
82,
297,
2644,
534,
1624,
13,
24,
358,
465,
22984,
70,
26,
288,
22984,
1652,
275,
2748,
14,
9464,
14,
15325,
14,
1122,
8,
25264,
70,
9,
267,
291,
14,
1815,
8,
25264,
1652,
365,
440,
488,
12,
283,
4276,
370,
2198,
15538,
4692,
358,
267,
1738,
275,
22984,
1652,
14,
24544,
342,
267,
291,
14,
629,
8,
1231,
14,
1450,
12,
283,
3554,
358,
267,
15538,
1931,
275,
1738,
14,
1623,
360,
11270,
358,
267,
291,
14,
629,
8,
11270,
1931,
14,
1450,
12,
283,
11270,
358,
267,
15538,
275,
15538,
1931,
14,
6452,
360,
9340,
358,
398,
327,
2832,
1006,
314,
15538,
1172,
11951,
4978,
436,
314,
15538,
787,
2138,
625,
5917,
14,
267,
367,
282,
315,
15538,
26,
288,
291,
14,
629,
8,
65,
14,
1450,
12,
283,
9340,
358,
288,
340,
282,
14,
362,
360,
466,
358,
508,
283,
505,
356,
355,
1318,
1931,
275,
282,
14,
1623,
360,
3876,
358,
355,
1318,
275,
1318,
1931,
14,
505,
355,
291,
14,
1815,
8,
505,
315,
1420,
9,
221,
327,
702,
607,
1454,
3483,
315,
2366,
499,
14,
23,
355,
327,
2813,
314,
1642,
4781,
554,
12,
2337,
4293,
506,
1655,
2419,
1373,
11262,
543,
314,
2011,
1318,
355,
1420,
14,
2168,
8,
505,
9,
267,
327,
2136,
1077,
1172,
6775,
334,
460,
4829,
9,
1006,
314,
1420,
11262,
24857,
14,
267,
291,
14,
629,
8,
552,
8,
2062,
395,
378,
12,
283,
1763,
1006,
1420,
15538,
4898,
1911,
2659,
339,
347,
6766,
8,
277,
304,
267,
862,
63,
5682,
8,
879,
4609,
12969,
63,
3817,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
3,
9812,
4125,
6451,
199,
646,
747,
199,
646,
984,
199,
646,
2882,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
363,
7845,
199,
199,
504,
511,
14,
3676,
492,
664,
63,
1162,
12,
862,
63,
5682,
421,
199,
646,
5890,
199,
199,
646,
2748,
14,
9464,
14,
15325,
199,
199,
646,
22378,
63,
5030,
14,
57,
7715,
8045,
199,
646,
22378,
63,
5030,
14,
22677,
421,
199,
533,
1488,
7715,
8045,
8,
9788,
63,
5030,
14,
57,
7715,
8045,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
57,
7715,
8045,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
475,
63,
3083,
275,
291,
14,
475,
63,
5410,
199,
199,
1162,
275,
664,
63,
1162,
2561,
272,
283,
952,
11270,
356,
715,
12,
272,
283,
2759,
63,
4249,
356,
715,
12,
272,
283,
952,
815,
1001,
356,
756,
12,
272,
283,
908,
356,
283,
22753,
297,
199,
1552,
421,
199,
2864,
63,
998,
275,
283,
2587,
2869,
65,
54,
74,
13,
77,
44,
71,
7,
199,
879,
4609,
12969,
63,
3817,
275,
7393,
63,
998,
435,
1987,
11270,
14,
1652,
7,
199,
22358,
63,
879,
4609,
12969,
275,
788,
27047,
12736,
330,
21749,
297,
283,
7443,
297,
283,
6888,
297,
283,
5058,
357,
4040,
297,
283,
4314,
418,
421,
199,
533,
1379,
21761,
1298,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
327,
14836,
2269,
1584,
267,
291,
14,
12336,
342,
339,
347,
511,
63,
815,
63,
1001,
8,
277,
304,
267,
1420,
275,
769,
8,
22358,
63,
879,
4609,
12969,
9,
221,
327,
16853,
15538,
4293,
1172,
314,
2011,
1318,
14,
267,
13446,
275,
22378,
63,
5030,
14,
22677,
14,
57,
7715,
4332,
342,
267,
31676,
275,
1488,
7715,
8045,
8,
1162,
9,
267,
31676,
14,
525,
63,
815,
63,
22677,
8,
1873,
9,
267,
31676,
14,
4249,
779,
2864,
63,
998,
566,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
879,
4609,
12969,
63,
3817,
430,
267,
22984,
1652,
275,
488,
267,
543,
5890,
14,
1490,
8,
879,
4609,
12969,
63,
3817,
12,
283,
82,
297,
2644,
534,
1624,
13,
24,
358,
465,
22984,
70,
26,
288,
22984,
1652,
275,
2748,
14,
9464,
14,
15325,
14,
1122,
8,
25264,
70,
9,
267,
291,
14,
1815,
8,
25264,
1652,
365,
440,
488,
12,
283,
4276,
370,
2198,
15538,
4692,
358,
267,
1738,
275,
22984,
1652,
14,
24544,
342,
267,
291,
14,
629,
8,
1231,
14,
1450,
12,
283,
3554,
358,
267,
15538,
1931,
275,
1738,
14,
1623,
360,
11270,
358,
267,
291,
14,
629,
8,
11270,
1931,
14,
1450,
12,
283,
11270,
358,
267,
15538,
275,
15538,
1931,
14,
6452,
360,
9340,
358,
398,
327,
2832,
1006,
314,
15538,
1172,
11951,
4978,
436,
314,
15538,
787,
2138,
625,
5917,
14,
267,
367,
282,
315,
15538,
26,
288,
291,
14,
629,
8,
65,
14,
1450,
12,
283,
9340,
358,
288,
340,
282,
14,
362,
360,
466,
358,
508,
283,
505,
356,
355,
1318,
1931,
275,
282,
14,
1623,
360,
3876,
358,
355,
1318,
275,
1318,
1931,
14,
505,
355,
291,
14,
1815,
8,
505,
315,
1420,
9,
221,
327,
702,
607,
1454,
3483,
315,
2366,
499,
14,
23,
355,
327,
2813,
314,
1642,
4781,
554,
12,
2337,
4293,
506,
1655,
2419,
1373,
11262,
543,
314,
2011,
1318,
355,
1420,
14,
2168,
8,
505,
9,
267,
327,
2136,
1077,
1172,
6775,
334,
460,
4829,
9,
1006,
314,
1420,
11262,
24857,
14,
267,
291,
14,
629,
8,
552,
8,
2062,
395,
378,
12,
283,
1763,
1006,
1420,
15538,
4898,
1911,
2659,
339,
347,
6766,
8,
277,
304,
267,
862,
63,
5682,
8,
879,
4609,
12969,
63,
3817,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dmarteau/QGIS
|
python/PyQt/PyQt5/uic/__init__.py
|
45
|
1461
|
# -*- coding: utf-8 -*-
"""
***************************************************************************
__init__.py
---------------------
Date : February 2016
Copyright : (C) 2016 by Jürgen E. Fischer
Email : jef at norbit dot de
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Jürgen E. Fischer'
__date__ = 'February 2016'
__copyright__ = '(C) 2016, Jürgen E. Fischer'
import warnings
from PyQt5.uic.Compiler import indenter, compiler
from PyQt5.uic.objcreator import widgetPluginPath
from PyQt5.uic import properties, uiparser, Compiler
from PyQt5.uic import *
__PyQtLoadUiType = loadUiType
def __loadUiType(*args, **kwargs):
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
return __PyQtLoadUiType(*args, **kwargs)
loadUiType = __loadUiType
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
636,
826,
4343,
647,
272,
10652,
9858,
272,
6148,
463,
520,
21141,
26709,
7800,
272,
1898,
3322,
520,
334,
35,
9,
7800,
701,
1603,
17709,
82,
2268,
662,
14,
481,
374,
7641,
272,
11426,
4483,
520,
1335,
2829,
737,
6590,
2075,
6308,
477,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
42,
17709,
82,
2268,
662,
14,
481,
374,
7641,
7,
199,
363,
602,
363,
275,
283,
27717,
26709,
7800,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
7800,
12,
1603,
17709,
82,
2268,
662,
14,
481,
374,
7641,
7,
199,
199,
646,
3598,
199,
504,
14084,
21,
14,
85,
530,
14,
9131,
492,
315,
848,
351,
12,
6365,
199,
504,
14084,
21,
14,
85,
530,
14,
1113,
9986,
492,
3938,
5061,
2042,
199,
504,
14084,
21,
14,
85,
530,
492,
4382,
12,
8574,
2087,
12,
27154,
199,
504,
14084,
21,
14,
85,
530,
492,
627,
199,
199,
363,
24107,
6200,
18203,
804,
275,
2248,
18203,
804,
421,
199,
318,
636,
912,
18203,
804,
2031,
589,
12,
1011,
958,
304,
272,
543,
3598,
14,
9341,
63,
5451,
837,
267,
3598,
14,
23945,
480,
4247,
401,
4637,
29,
15561,
9,
267,
372,
636,
24107,
6200,
18203,
804,
2031,
589,
12,
1011,
958,
9,
421,
199,
912,
18203,
804,
275,
636,
912,
18203,
804,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
636,
826,
4343,
647,
272,
10652,
9858,
272,
6148,
463,
520,
21141,
26709,
7800,
272,
1898,
3322,
520,
334,
35,
9,
7800,
701,
1603,
17709,
82,
2268,
662,
14,
481,
374,
7641,
272,
11426,
4483,
520,
1335,
2829,
737,
6590,
2075,
6308,
477,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
42,
17709,
82,
2268,
662,
14,
481,
374,
7641,
7,
199,
363,
602,
363,
275,
283,
27717,
26709,
7800,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
7800,
12,
1603,
17709,
82,
2268,
662,
14,
481,
374,
7641,
7,
199,
199,
646,
3598,
199,
504,
14084,
21,
14,
85,
530,
14,
9131,
492,
315,
848,
351,
12,
6365,
199,
504,
14084,
21,
14,
85,
530,
14,
1113,
9986,
492,
3938,
5061,
2042,
199,
504,
14084,
21,
14,
85,
530,
492,
4382,
12,
8574,
2087,
12,
27154,
199,
504,
14084,
21,
14,
85,
530,
492,
627,
199,
199,
363,
24107,
6200,
18203,
804,
275,
2248,
18203,
804,
421,
199,
318,
636,
912,
18203,
804,
2031,
589,
12,
1011,
958,
304,
272,
543,
3598,
14,
9341,
63,
5451,
837,
267,
3598,
14,
23945,
480,
4247,
401,
4637,
29,
15561,
9,
267,
372,
636,
24107,
6200,
18203,
804,
2031,
589,
12,
1011,
958,
9,
421,
199,
912,
18203,
804,
275,
636,
912,
18203,
804,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
zang-cloud/zang-python
|
tests/inboundxml/test_dial.py
|
2
|
2276
|
import unittest
from zang.inboundxml.elements.dial import Dial
from zang.domain.enums.http_method import HttpMethod
from zang.inboundxml.elements.number import Number
class TestDial(unittest.TestCase):
def test_init_with_required_values(self):
expected = '<Dial></Dial>'
assert Dial().xml == expected
def test_init_with_arguments(self):
text = '(555)555-5555'
dial = Dial(number=text)
expected = '<Dial>%s</Dial>' % text
assert dial.xml == expected
def test_init_add_element(self):
text = '(555)555-5555'
number = Number(text)
dial = Dial()
dial.addElement(number)
expected = '<Dial><Number>%s</Number></Dial>' % text
assert dial.xml == expected
def test_init_remove_element_at_index(self):
text = 'Hello from Zang!'
number = Number(text)
dial = Dial()
dial.addElement(number)
expected = '<Dial><Number>%s</Number></Dial>' % text
assert dial.xml == expected
dial.removeElementAtIndex(0)
expected = '<Dial></Dial>'
assert dial.xml == expected
def test_remove_element_at_out_of_range_index(self):
text = 'Hello from Zang!'
number = Number(text)
dial = Dial()
dial.addElement(number)
index = len(dial._content)
self.assertRaises(
IndexError, lambda: dial.removeElementAtIndex(index))
def test_init_with_optional_attributes(self):
method = HttpMethod.GET
dial = Dial(method=method)
expected = '<Dial method="%s"></Dial>' % (method.value)
assert dial.xml == expected
def test_init_with_unsupported_attributes(self):
self.assertRaises(TypeError, lambda: Dial(foo='bar'))
def test_with_update_attributes(self):
dial = Dial()
timeLimit = 0
dial.timeLimit = 0
expected = '<Dial timeLimit="%s"></Dial>' % (timeLimit)
assert dial.xml == expected
def test_udefinded_method_with_primitive_type(self):
self.assertRaises(TypeError, lambda: Dial().addElement(0.5))
def test_udefinded_method_with_base_node(self):
self.assertRaises(AttributeError, lambda: Dial().url)
if __name__ == '__main__':
unittest.main()
|
mit
|
[
646,
2882,
199,
504,
1315,
621,
14,
26108,
1652,
14,
5527,
14,
328,
279,
492,
577,
2380,
199,
504,
1315,
621,
14,
2261,
14,
19921,
14,
1014,
63,
765,
492,
4760,
3767,
199,
504,
1315,
621,
14,
26108,
1652,
14,
5527,
14,
1955,
492,
4860,
421,
199,
533,
1379,
1341,
279,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
826,
63,
1045,
63,
2427,
63,
1459,
8,
277,
304,
267,
1420,
275,
2650,
1341,
279,
2957,
1341,
279,
3524,
267,
702,
577,
2380,
1252,
1652,
508,
1420,
339,
347,
511,
63,
826,
63,
1045,
63,
4958,
8,
277,
304,
267,
1318,
275,
8189,
15722,
9,
15722,
13,
19161,
7,
267,
487,
279,
275,
577,
2380,
8,
1955,
29,
505,
9,
267,
1420,
275,
2650,
1341,
279,
6598,
83,
1108,
1341,
279,
3524,
450,
1318,
267,
702,
487,
279,
14,
1652,
508,
1420,
339,
347,
511,
63,
826,
63,
525,
63,
2108,
8,
277,
304,
267,
1318,
275,
8189,
15722,
9,
15722,
13,
19161,
7,
267,
1329,
275,
4860,
8,
505,
9,
267,
487,
279,
275,
577,
2380,
342,
267,
487,
279,
14,
525,
2162,
8,
1955,
9,
267,
1420,
275,
2650,
1341,
279,
2535,
3259,
6598,
83,
1108,
3259,
2957,
1341,
279,
3524,
450,
1318,
267,
702,
487,
279,
14,
1652,
508,
1420,
339,
347,
511,
63,
826,
63,
2168,
63,
2108,
63,
292,
63,
1080,
8,
277,
304,
267,
1318,
275,
283,
6257,
687,
3107,
621,
11213,
267,
1329,
275,
4860,
8,
505,
9,
267,
487,
279,
275,
577,
2380,
342,
267,
487,
279,
14,
525,
2162,
8,
1955,
9,
267,
1420,
275,
2650,
1341,
279,
2535,
3259,
6598,
83,
1108,
3259,
2957,
1341,
279,
3524,
450,
1318,
267,
702,
487,
279,
14,
1652,
508,
1420,
267,
487,
279,
14,
2168,
2162,
1271,
2681,
8,
16,
9,
267,
1420,
275,
2650,
1341,
279,
2957,
1341,
279,
3524,
267,
702,
487,
279,
14,
1652,
508,
1420,
339,
347,
511,
63,
2168,
63,
2108,
63,
292,
63,
548,
63,
1618,
63,
1842,
63,
1080,
8,
277,
304,
267,
1318,
275,
283,
6257,
687,
3107,
621,
11213,
267,
1329,
275,
4860,
8,
505,
9,
267,
487,
279,
275,
577,
2380,
342,
267,
487,
279,
14,
525,
2162,
8,
1955,
9,
267,
1478,
275,
822,
8,
328,
279,
423,
1317,
9,
267,
291,
14,
1855,
8,
288,
7888,
12,
2400,
26,
487,
279,
14,
2168,
2162,
1271,
2681,
8,
1080,
430,
339,
347,
511,
63,
826,
63,
1045,
63,
4144,
63,
2987,
8,
277,
304,
267,
1083,
275,
4760,
3767,
14,
2970,
267,
487,
279,
275,
577,
2380,
8,
765,
29,
765,
9,
267,
1420,
275,
2650,
1341,
279,
1083,
5961,
83,
10070,
1341,
279,
3524,
450,
334,
765,
14,
585,
9,
267,
702,
487,
279,
14,
1652,
508,
1420,
339,
347,
511,
63,
826,
63,
1045,
63,
15267,
63,
2987,
8,
277,
304,
267,
291,
14,
1855,
8,
4333,
12,
2400,
26,
577,
2380,
8,
1421,
534,
1700,
1333,
339,
347,
511,
63,
1045,
63,
873,
63,
2987,
8,
277,
304,
267,
487,
279,
275,
577,
2380,
342,
267,
900,
8407,
275,
378,
267,
487,
279,
14,
521,
8407,
275,
378,
267,
1420,
275,
2650,
1341,
279,
900,
8407,
5961,
83,
10070,
1341,
279,
3524,
450,
334,
521,
8407,
9,
267,
702,
487,
279,
14,
1652,
508,
1420,
339,
347,
511,
63,
85,
318,
262,
770,
63,
765,
63,
1045,
63,
16161,
63,
466,
8,
277,
304,
267,
291,
14,
1855,
8,
4333,
12,
2400,
26,
577,
2380,
1252,
525,
2162,
8,
16,
14,
21,
430,
339,
347,
511,
63,
85,
318,
262,
770,
63,
765,
63,
1045,
63,
1095,
63,
932,
8,
277,
304,
267,
291,
14,
1855,
8,
10227,
12,
2400,
26,
577,
2380,
1252,
633,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2882,
199,
504,
1315,
621,
14,
26108,
1652,
14,
5527,
14,
328,
279,
492,
577,
2380,
199,
504,
1315,
621,
14,
2261,
14,
19921,
14,
1014,
63,
765,
492,
4760,
3767,
199,
504,
1315,
621,
14,
26108,
1652,
14,
5527,
14,
1955,
492,
4860,
421,
199,
533,
1379,
1341,
279,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
826,
63,
1045,
63,
2427,
63,
1459,
8,
277,
304,
267,
1420,
275,
2650,
1341,
279,
2957,
1341,
279,
3524,
267,
702,
577,
2380,
1252,
1652,
508,
1420,
339,
347,
511,
63,
826,
63,
1045,
63,
4958,
8,
277,
304,
267,
1318,
275,
8189,
15722,
9,
15722,
13,
19161,
7,
267,
487,
279,
275,
577,
2380,
8,
1955,
29,
505,
9,
267,
1420,
275,
2650,
1341,
279,
6598,
83,
1108,
1341,
279,
3524,
450,
1318,
267,
702,
487,
279,
14,
1652,
508,
1420,
339,
347,
511,
63,
826,
63,
525,
63,
2108,
8,
277,
304,
267,
1318,
275,
8189,
15722,
9,
15722,
13,
19161,
7,
267,
1329,
275,
4860,
8,
505,
9,
267,
487,
279,
275,
577,
2380,
342,
267,
487,
279,
14,
525,
2162,
8,
1955,
9,
267,
1420,
275,
2650,
1341,
279,
2535,
3259,
6598,
83,
1108,
3259,
2957,
1341,
279,
3524,
450,
1318,
267,
702,
487,
279,
14,
1652,
508,
1420,
339,
347,
511,
63,
826,
63,
2168,
63,
2108,
63,
292,
63,
1080,
8,
277,
304,
267,
1318,
275,
283,
6257,
687,
3107,
621,
11213,
267,
1329,
275,
4860,
8,
505,
9,
267,
487,
279,
275,
577,
2380,
342,
267,
487,
279,
14,
525,
2162,
8,
1955,
9,
267,
1420,
275,
2650,
1341,
279,
2535,
3259,
6598,
83,
1108,
3259,
2957,
1341,
279,
3524,
450,
1318,
267,
702,
487,
279,
14,
1652,
508,
1420,
267,
487,
279,
14,
2168,
2162,
1271,
2681,
8,
16,
9,
267,
1420,
275,
2650,
1341,
279,
2957,
1341,
279,
3524,
267,
702,
487,
279,
14,
1652,
508,
1420,
339,
347,
511,
63,
2168,
63,
2108,
63,
292,
63,
548,
63,
1618,
63,
1842,
63,
1080,
8,
277,
304,
267,
1318,
275,
283,
6257,
687,
3107,
621,
11213,
267,
1329,
275,
4860,
8,
505,
9,
267,
487,
279,
275,
577,
2380,
342,
267,
487,
279,
14,
525,
2162,
8,
1955,
9,
267,
1478,
275,
822,
8,
328,
279,
423,
1317,
9,
267,
291,
14,
1855,
8,
288,
7888,
12,
2400,
26,
487,
279,
14,
2168,
2162,
1271,
2681,
8,
1080,
430,
339,
347,
511,
63,
826,
63,
1045,
63,
4144,
63,
2987,
8,
277,
304,
267,
1083,
275,
4760,
3767,
14,
2970,
267,
487,
279,
275,
577,
2380,
8,
765,
29,
765,
9,
267,
1420,
275,
2650,
1341,
279,
1083,
5961,
83,
10070,
1341,
279,
3524,
450,
334,
765,
14,
585,
9,
267,
702,
487,
279,
14,
1652,
508,
1420,
339,
347,
511,
63,
826,
63,
1045,
63,
15267,
63,
2987,
8,
277,
304,
267,
291,
14,
1855,
8,
4333,
12,
2400,
26,
577,
2380,
8,
1421,
534,
1700,
1333,
339,
347,
511,
63,
1045,
63,
873,
63,
2987,
8,
277,
304,
267,
487,
279,
275,
577,
2380,
342,
267,
900,
8407,
275,
378,
267,
487,
279,
14,
521,
8407,
275,
378,
267,
1420,
275,
2650,
1341,
279,
900,
8407,
5961,
83,
10070,
1341,
279,
3524,
450,
334,
521,
8407,
9,
267,
702,
487,
279,
14,
1652,
508,
1420,
339,
347,
511,
63,
85,
318,
262,
770,
63,
765,
63,
1045,
63,
16161,
63,
466,
8,
277,
304,
267,
291,
14,
1855,
8,
4333,
12,
2400,
26,
577,
2380,
1252,
525,
2162,
8,
16,
14,
21,
430,
339,
347,
511,
63,
85,
318,
262,
770,
63,
765,
63,
1045,
63,
1095,
63,
932,
8,
277,
304,
267,
291,
14,
1855,
8,
10227,
12,
2400,
26,
577,
2380,
1252,
633,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lamdnhan/osf.io
|
website/addons/wiki/model.py
|
6
|
4973
|
# -*- coding: utf-8 -*-
import datetime
import functools
import logging
from bleach import linkify
from bleach.callbacks import nofollow
import markdown
from markdown.extensions import codehilite, fenced_code, wikilinks
from modularodm import fields
from framework.forms.utils import sanitize
from framework.guid.model import GuidStoredObject
from website import settings
from website.addons.base import AddonNodeSettingsBase
from website.addons.wiki import utils as wiki_utils
from website.addons.wiki.settings import WIKI_CHANGE_DATE
from website.project.model import write_permissions_revoked
from .exceptions import (
NameEmptyError,
NameInvalidError,
NameMaximumLengthError,
)
logger = logging.getLogger(__name__)
class AddonWikiNodeSettings(AddonNodeSettingsBase):
def after_register(self, node, registration, user, save=True):
"""Copy wiki settings to registrations."""
clone = self.clone()
clone.owner = registration
if save:
clone.save()
return clone, None
def to_json(self, user):
return {}
@write_permissions_revoked.connect
def subscribe_on_write_permissions_revoked(node):
# Migrate every page on the node
for wiki_name in node.wiki_private_uuids:
wiki_utils.migrate_uuid(node, wiki_name)
def build_wiki_url(node, label, base, end):
return node.web_url_for('project_wiki_view', wname=label)
def validate_page_name(value):
value = (value or '').strip()
if not value:
raise NameEmptyError('Page name cannot be blank.')
if value.find('/') != -1:
raise NameInvalidError('Page name cannot contain forward slashes.')
if len(value) > 100:
raise NameMaximumLengthError('Page name cannot be greater than 100 characters.')
return True
def render_content(content, node):
html_output = markdown.markdown(
content,
extensions=[
wikilinks.WikiLinkExtension(
configs=[
('base_url', ''),
('end_url', ''),
('build_url', functools.partial(build_wiki_url, node))
]
),
fenced_code.FencedCodeExtension(),
codehilite.CodeHiliteExtension(
[('css_class', 'highlight')]
)
]
)
# linkify gets called after santize, because we're adding rel="nofollow"
# to <a> elements - but don't want to allow them for other elements.
sanitized_content = sanitize(html_output, **settings.WIKI_WHITELIST)
return sanitized_content
class NodeWikiPage(GuidStoredObject):
_id = fields.StringField(primary=True)
page_name = fields.StringField(validate=validate_page_name)
version = fields.IntegerField()
date = fields.DateTimeField(auto_now_add=datetime.datetime.utcnow)
is_current = fields.BooleanField()
content = fields.StringField(default='')
user = fields.ForeignField('user')
node = fields.ForeignField('node')
@property
def deep_url(self):
return '{}wiki/{}/'.format(self.node.deep_url, self.page_name)
@property
def url(self):
return '{}wiki/{}/'.format(self.node.url, self.page_name)
@property
def rendered_before_update(self):
return self.date < WIKI_CHANGE_DATE
def html(self, node):
"""The cleaned HTML of the page"""
sanitized_content = render_content(self.content, node=node)
try:
return linkify(
sanitized_content,
[nofollow, ],
)
except TypeError:
logger.warning('Returning unlinkified content.')
return sanitized_content
def raw_text(self, node):
""" The raw text of the page, suitable for using in a test search"""
return sanitize(self.html(node), tags=[], strip=True)
def get_draft(self, node):
"""
Return most recently edited version of wiki, whether that is the
last saved version or the most recent sharejs draft.
"""
db = wiki_utils.share_db()
sharejs_uuid = wiki_utils.get_sharejs_uuid(node, self.page_name)
doc_item = db['docs'].find_one({'_id': sharejs_uuid})
if doc_item:
sharejs_version = doc_item['_v']
sharejs_timestamp = doc_item['_m']['mtime']
sharejs_timestamp /= 1000 # Convert to appropriate units
sharejs_date = datetime.datetime.utcfromtimestamp(sharejs_timestamp)
if sharejs_version > 1 and sharejs_date > self.date:
return doc_item['_data']
return self.content
def save(self, *args, **kwargs):
rv = super(NodeWikiPage, self).save(*args, **kwargs)
if self.node:
self.node.update_search()
return rv
def rename(self, new_name, save=True):
self.page_name = new_name
if save:
self.save()
def to_json(self):
return {}
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
2197,
199,
646,
9143,
199,
646,
2050,
199,
199,
504,
29603,
1225,
492,
2142,
2021,
199,
504,
29603,
1225,
14,
11948,
492,
949,
7207,
199,
199,
646,
18502,
199,
504,
18502,
14,
5359,
492,
1233,
72,
1638,
266,
12,
289,
4894,
68,
63,
600,
12,
336,
3258,
382,
2292,
83,
199,
504,
3413,
2238,
364,
77,
492,
1504,
199,
199,
504,
10059,
14,
3351,
14,
1208,
492,
21077,
199,
504,
10059,
14,
9473,
14,
1238,
492,
598,
1535,
4759,
581,
1692,
199,
199,
504,
10691,
492,
2202,
199,
504,
10691,
14,
10788,
14,
1095,
492,
29366,
1716,
5268,
1563,
199,
504,
10691,
14,
10788,
14,
6797,
492,
3778,
465,
17195,
63,
1208,
199,
504,
10691,
14,
10788,
14,
6797,
14,
1751,
492,
644,
41,
16944,
63,
16062,
63,
5390,
199,
504,
10691,
14,
1715,
14,
1238,
492,
2218,
63,
6060,
63,
4964,
7620,
199,
199,
504,
1275,
3924,
492,
334,
272,
2812,
4699,
547,
12,
272,
2812,
3364,
547,
12,
272,
2812,
10915,
4625,
547,
12,
199,
9,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
29366,
26198,
1716,
5268,
8,
19654,
1716,
5268,
1563,
304,
339,
347,
2410,
63,
2683,
8,
277,
12,
1031,
12,
10991,
12,
922,
12,
3354,
29,
549,
304,
267,
408,
5116,
17195,
2202,
370,
25483,
3801,
1041,
267,
7289,
275,
291,
14,
6311,
342,
267,
7289,
14,
4597,
275,
10991,
267,
340,
3354,
26,
288,
7289,
14,
2117,
342,
267,
372,
7289,
12,
488,
339,
347,
370,
63,
1001,
8,
277,
12,
922,
304,
267,
372,
1052,
421,
199,
32,
952,
63,
6060,
63,
4964,
7620,
14,
2242,
199,
318,
23421,
63,
265,
63,
952,
63,
6060,
63,
4964,
7620,
8,
932,
304,
272,
327,
28195,
1866,
4036,
2034,
641,
314,
1031,
272,
367,
17195,
63,
354,
315,
1031,
14,
6797,
63,
4239,
63,
18401,
26,
267,
17195,
63,
1208,
14,
8462,
63,
2580,
8,
932,
12,
17195,
63,
354,
9,
421,
199,
318,
1900,
63,
6797,
63,
633,
8,
932,
12,
1768,
12,
1300,
12,
1284,
304,
272,
372,
1031,
14,
2520,
63,
633,
63,
509,
360,
1715,
63,
6797,
63,
1345,
297,
336,
354,
29,
1302,
9,
421,
199,
318,
4107,
63,
1606,
63,
354,
8,
585,
304,
272,
574,
275,
334,
585,
503,
12548,
1913,
342,
339,
340,
440,
574,
26,
267,
746,
2812,
4699,
547,
360,
3276,
536,
3913,
506,
4596,
2659,
272,
340,
574,
14,
1623,
7825,
1137,
446,
17,
26,
267,
746,
2812,
3364,
547,
360,
3276,
536,
3913,
1395,
7568,
20275,
2659,
272,
340,
822,
8,
585,
9,
690,
2948,
26,
267,
746,
2812,
10915,
4625,
547,
360,
3276,
536,
3913,
506,
8932,
2419,
2948,
4110,
2659,
272,
372,
715,
421,
199,
318,
3795,
63,
1317,
8,
1317,
12,
1031,
304,
272,
3517,
63,
1199,
275,
18502,
14,
15653,
8,
267,
1564,
12,
267,
5478,
1524,
288,
336,
3258,
382,
2292,
83,
14,
26198,
3834,
6382,
8,
355,
11585,
1524,
490,
661,
1095,
63,
633,
297,
9929,
490,
661,
500,
63,
633,
297,
9929,
490,
661,
1506,
63,
633,
297,
9143,
14,
6672,
8,
1506,
63,
6797,
63,
633,
12,
1031,
430,
355,
1622,
288,
2318,
288,
289,
4894,
68,
63,
600,
14,
38,
4894,
68,
3034,
6382,
1062,
288,
1233,
72,
1638,
266,
14,
3034,
40,
1638,
266,
6382,
8,
355,
4274,
3919,
63,
533,
297,
283,
14337,
5440,
288,
776,
267,
1622,
272,
776,
339,
327,
2142,
2021,
7545,
2797,
2410,
308,
4466,
806,
12,
2952,
781,
3984,
7791,
4668,
628,
31678,
2,
272,
327,
257,
370,
665,
65,
30,
4008,
446,
1325,
2793,
1133,
2934,
370,
2040,
3062,
367,
1163,
4008,
14,
272,
31734,
63,
1317,
275,
21077,
8,
1360,
63,
1199,
12,
1011,
1751,
14,
18759,
16944,
63,
18817,
4924,
9,
272,
372,
31734,
63,
1317,
421,
199,
533,
5013,
26198,
3276,
8,
18834,
4759,
581,
1692,
304,
339,
485,
344,
275,
1504,
14,
14912,
8,
3327,
29,
549,
9,
339,
2034,
63,
354,
275,
1504,
14,
14912,
8,
3502,
29,
3502,
63,
1606,
63,
354,
9,
272,
1015,
275,
1504,
14,
3901,
342,
272,
1434,
275,
1504,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
2083,
14,
2083,
14,
10779,
9,
272,
365,
63,
1818,
275,
1504,
14,
5036,
342,
272,
1564,
275,
1504,
14,
14912,
8,
885,
13275,
339,
922,
275,
1504,
14,
20931,
792,
360,
751,
358,
272,
1031,
275,
1504,
14,
20931,
792,
360,
932,
358,
339,
768,
1829,
272,
347,
13217,
63,
633,
8,
277,
304,
267,
372,
9005,
6797,
19655,
1370,
908,
8,
277,
14,
932,
14,
16131,
63,
633,
12,
291,
14,
1606,
63,
354,
9,
339,
768,
1829,
272,
347,
1166,
8,
277,
304,
267,
372,
9005,
6797,
19655,
1370,
908,
8,
277,
14,
932,
14,
633,
12,
291,
14,
1606,
63,
354,
9,
339,
768,
1829,
272,
347,
8018,
63,
5182,
63,
873,
8,
277,
304,
267,
372,
291,
14,
602,
665,
644,
41,
16944,
63,
16062,
63,
5390,
339,
347,
3517,
8,
277,
12,
1031,
304,
267,
408,
1918,
12364,
4163,
402,
314,
2034,
624,
267,
31734,
63,
1317,
275,
3795,
63,
1317,
8,
277,
14,
1317,
12,
1031,
29,
932,
9,
267,
862,
26,
288,
372,
2142,
2021,
8,
355,
31734,
63,
1317,
12,
355,
359,
31678,
12,
2156,
288,
776,
267,
871,
3146,
26,
288,
2512,
14,
3764,
360,
1767,
316,
17002,
4541,
1564,
2659,
288,
372,
31734,
63,
1317,
339,
347,
3066,
63,
505,
8,
277,
12,
1031,
304,
267,
408,
710,
3066,
1318,
402,
314,
2034,
12,
11233,
367,
1808,
315,
282,
511,
2754,
624,
398,
372,
21077,
8,
277,
14,
1360,
8,
932,
395,
3762,
6034,
6202,
29,
549,
9,
339,
347,
664,
63,
7185,
8,
277,
12,
1031,
304,
267,
408,
267,
1432,
4750,
23568,
21062,
1015,
402,
17195,
12,
3775,
626,
365,
314,
267,
2061,
6290,
1015,
503,
314,
4750,
8058,
8663,
3596,
11872,
14,
267,
408,
398,
1592,
275,
17195,
63,
1208,
14,
6251,
63,
697,
342,
267,
8663,
3596,
63,
2580,
275,
17195,
63,
1208,
14,
362,
63,
6251,
3596,
63,
2580,
8,
932,
12,
291,
14,
1606,
63,
354,
9
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
2197,
199,
646,
9143,
199,
646,
2050,
199,
199,
504,
29603,
1225,
492,
2142,
2021,
199,
504,
29603,
1225,
14,
11948,
492,
949,
7207,
199,
199,
646,
18502,
199,
504,
18502,
14,
5359,
492,
1233,
72,
1638,
266,
12,
289,
4894,
68,
63,
600,
12,
336,
3258,
382,
2292,
83,
199,
504,
3413,
2238,
364,
77,
492,
1504,
199,
199,
504,
10059,
14,
3351,
14,
1208,
492,
21077,
199,
504,
10059,
14,
9473,
14,
1238,
492,
598,
1535,
4759,
581,
1692,
199,
199,
504,
10691,
492,
2202,
199,
504,
10691,
14,
10788,
14,
1095,
492,
29366,
1716,
5268,
1563,
199,
504,
10691,
14,
10788,
14,
6797,
492,
3778,
465,
17195,
63,
1208,
199,
504,
10691,
14,
10788,
14,
6797,
14,
1751,
492,
644,
41,
16944,
63,
16062,
63,
5390,
199,
504,
10691,
14,
1715,
14,
1238,
492,
2218,
63,
6060,
63,
4964,
7620,
199,
199,
504,
1275,
3924,
492,
334,
272,
2812,
4699,
547,
12,
272,
2812,
3364,
547,
12,
272,
2812,
10915,
4625,
547,
12,
199,
9,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
29366,
26198,
1716,
5268,
8,
19654,
1716,
5268,
1563,
304,
339,
347,
2410,
63,
2683,
8,
277,
12,
1031,
12,
10991,
12,
922,
12,
3354,
29,
549,
304,
267,
408,
5116,
17195,
2202,
370,
25483,
3801,
1041,
267,
7289,
275,
291,
14,
6311,
342,
267,
7289,
14,
4597,
275,
10991,
267,
340,
3354,
26,
288,
7289,
14,
2117,
342,
267,
372,
7289,
12,
488,
339,
347,
370,
63,
1001,
8,
277,
12,
922,
304,
267,
372,
1052,
421,
199,
32,
952,
63,
6060,
63,
4964,
7620,
14,
2242,
199,
318,
23421,
63,
265,
63,
952,
63,
6060,
63,
4964,
7620,
8,
932,
304,
272,
327,
28195,
1866,
4036,
2034,
641,
314,
1031,
272,
367,
17195,
63,
354,
315,
1031,
14,
6797,
63,
4239,
63,
18401,
26,
267,
17195,
63,
1208,
14,
8462,
63,
2580,
8,
932,
12,
17195,
63,
354,
9,
421,
199,
318,
1900,
63,
6797,
63,
633,
8,
932,
12,
1768,
12,
1300,
12,
1284,
304,
272,
372,
1031,
14,
2520,
63,
633,
63,
509,
360,
1715,
63,
6797,
63,
1345,
297,
336,
354,
29,
1302,
9,
421,
199,
318,
4107,
63,
1606,
63,
354,
8,
585,
304,
272,
574,
275,
334,
585,
503,
12548,
1913,
342,
339,
340,
440,
574,
26,
267,
746,
2812,
4699,
547,
360,
3276,
536,
3913,
506,
4596,
2659,
272,
340,
574,
14,
1623,
7825,
1137,
446,
17,
26,
267,
746,
2812,
3364,
547,
360,
3276,
536,
3913,
1395,
7568,
20275,
2659,
272,
340,
822,
8,
585,
9,
690,
2948,
26,
267,
746,
2812,
10915,
4625,
547,
360,
3276,
536,
3913,
506,
8932,
2419,
2948,
4110,
2659,
272,
372,
715,
421,
199,
318,
3795,
63,
1317,
8,
1317,
12,
1031,
304,
272,
3517,
63,
1199,
275,
18502,
14,
15653,
8,
267,
1564,
12,
267,
5478,
1524,
288,
336,
3258,
382,
2292,
83,
14,
26198,
3834,
6382,
8,
355,
11585,
1524,
490,
661,
1095,
63,
633,
297,
9929,
490,
661,
500,
63,
633,
297,
9929,
490,
661,
1506,
63,
633,
297,
9143,
14,
6672,
8,
1506,
63,
6797,
63,
633,
12,
1031,
430,
355,
1622,
288,
2318,
288,
289,
4894,
68,
63,
600,
14,
38,
4894,
68,
3034,
6382,
1062,
288,
1233,
72,
1638,
266,
14,
3034,
40,
1638,
266,
6382,
8,
355,
4274,
3919,
63,
533,
297,
283,
14337,
5440,
288,
776,
267,
1622,
272,
776,
339,
327,
2142,
2021,
7545,
2797,
2410,
308,
4466,
806,
12,
2952,
781,
3984,
7791,
4668,
628,
31678,
2,
272,
327,
257,
370,
665,
65,
30,
4008,
446,
1325,
2793,
1133,
2934,
370,
2040,
3062,
367,
1163,
4008,
14,
272,
31734,
63,
1317,
275,
21077,
8,
1360,
63,
1199,
12,
1011,
1751,
14,
18759,
16944,
63,
18817,
4924,
9,
272,
372,
31734,
63,
1317,
421,
199,
533,
5013,
26198,
3276,
8,
18834,
4759,
581,
1692,
304,
339,
485,
344,
275,
1504,
14,
14912,
8,
3327,
29,
549,
9,
339,
2034,
63,
354,
275,
1504,
14,
14912,
8,
3502,
29,
3502,
63,
1606,
63,
354,
9,
272,
1015,
275,
1504,
14,
3901,
342,
272,
1434,
275,
1504,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
2083,
14,
2083,
14,
10779,
9,
272,
365,
63,
1818,
275,
1504,
14,
5036,
342,
272,
1564,
275,
1504,
14,
14912,
8,
885,
13275,
339,
922,
275,
1504,
14,
20931,
792,
360,
751,
358,
272,
1031,
275,
1504,
14,
20931,
792,
360,
932,
358,
339,
768,
1829,
272,
347,
13217,
63,
633,
8,
277,
304,
267,
372,
9005,
6797,
19655,
1370,
908,
8,
277,
14,
932,
14,
16131,
63,
633,
12,
291,
14,
1606,
63,
354,
9,
339,
768,
1829,
272,
347,
1166,
8,
277,
304,
267,
372,
9005,
6797,
19655,
1370,
908,
8,
277,
14,
932,
14,
633,
12,
291,
14,
1606,
63,
354,
9,
339,
768,
1829,
272,
347,
8018,
63,
5182,
63,
873,
8,
277,
304,
267,
372,
291,
14,
602,
665,
644,
41,
16944,
63,
16062,
63,
5390,
339,
347,
3517,
8,
277,
12,
1031,
304,
267,
408,
1918,
12364,
4163,
402,
314,
2034,
624,
267,
31734,
63,
1317,
275,
3795,
63,
1317,
8,
277,
14,
1317,
12,
1031,
29,
932,
9,
267,
862,
26,
288,
372,
2142,
2021,
8,
355,
31734,
63,
1317,
12,
355,
359,
31678,
12,
2156,
288,
776,
267,
871,
3146,
26,
288,
2512,
14,
3764,
360,
1767,
316,
17002,
4541,
1564,
2659,
288,
372,
31734,
63,
1317,
339,
347,
3066,
63,
505,
8,
277,
12,
1031,
304,
267,
408,
710,
3066,
1318,
402,
314,
2034,
12,
11233,
367,
1808,
315,
282,
511,
2754,
624,
398,
372,
21077,
8,
277,
14,
1360,
8,
932,
395,
3762,
6034,
6202,
29,
549,
9,
339,
347,
664,
63,
7185,
8,
277,
12,
1031,
304,
267,
408,
267,
1432,
4750,
23568,
21062,
1015,
402,
17195,
12,
3775,
626,
365,
314,
267,
2061,
6290,
1015,
503,
314,
4750,
8058,
8663,
3596,
11872,
14,
267,
408,
398,
1592,
275,
17195,
63,
1208,
14,
6251,
63,
697,
342,
267,
8663,
3596,
63,
2580,
275,
17195,
63,
1208,
14,
362,
63,
6251,
3596,
63,
2580,
8,
932,
12,
291,
14,
1606,
63,
354,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lvasselt/cassandra-shawn
|
test/system/__init__.py
|
2
|
9506
|
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os, sys, time, signal, httplib
__all__ = ['root', 'thrift_client']
from thrift.transport import TTransport
from thrift.transport import TSocket
from thrift.transport import THttpClient
from thrift.protocol import TBinaryProtocol
try:
import avro.ipc as ipc
import avro.protocol as protocol
except ImportError:
pass
# add cassandra directory to sys.path
L = os.path.abspath(__file__).split(os.path.sep)[:-3]
root = os.path.sep.join(L)
_ipath = os.path.join(root, 'interface', 'thrift', 'gen-py')
sys.path.append(os.path.join(_ipath, 'cassandra'))
import Cassandra
def get_thrift_client(host='127.0.0.1', port=9170):
socket = TSocket.TSocket(host, port)
transport = TTransport.TFramedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
client = Cassandra.Client(protocol)
client.transport = transport
return client
thrift_client = get_thrift_client()
def get_avro_client(host='127.0.0.1', port=9170):
schema = os.path.join(root, 'interface/avro', 'cassandra.avpr')
proto = protocol.parse(open(schema).read())
client = ipc.HTTPTransceiver(host, port)
return ipc.Requestor(proto, client)
pid_fname = "system_test.pid"
def pid():
return int(open(pid_fname).read())
class BaseTester(object):
# leave this True unless you are manually starting a server and then
# running only a single test against it; tests assume they start
# against an empty db.
runserver = True
client = None
extra_args = []
def open_client(self):
raise NotImplementedError()
def close_client(self):
raise NotImplementedError()
def define_schema(self):
raise NotImplementedError()
def setUp(self):
if self.runserver:
if os.path.exists(pid_fname):
pid_path = os.path.join(root, pid_fname)
print "Unclean shutdown detected, (%s found)" % pid_path
sys.exit()
# clean out old stuff
import shutil
# todo get directories from conf/cassandra.yaml
for dirname in ['system', 'data', 'commitlog']:
try:
shutil.rmtree('build/test/cassandra/' + dirname)
except OSError:
pass
# start the server
import subprocess as sp
os.chdir(root)
os.environ['CASSANDRA_INCLUDE'] = 'test/cassandra.in.sh'
args = ['bin/cassandra', '-p', pid_fname] + self.extra_args
process = sp.Popen(args, stderr=sp.PIPE, stdout=sp.PIPE)
time.sleep(0.1)
# connect to it, with a timeout in case something went wrong
start = time.time()
while time.time() < start + 10:
try:
self.open_client()
except:
time.sleep(0.1)
else:
break
else:
print "Couldn't connect to server; aborting regression test"
# see if process is still alive
process.poll()
if process.returncode is None:
os.kill(pid(), signal.SIGKILL) # just in case
else:
stdout_value, stderr_value = process.communicate()
print "Stdout: %s" % (stdout_value)
print "Stderr: %s" % (stderr_value)
sys.exit()
else:
try:
self.open_client()
except:
pass
self.define_schema()
def tearDown(self):
if self.runserver:
self.close_client()
open('/tmp/kill', 'w').write('killing %s\n' % pid())
os.kill(pid(), signal.SIGTERM)
# TODO kill server with SIGKILL if it's still alive
time.sleep(0.5)
# TODO assert server is Truly Dead
class ThriftTester(BaseTester):
client = thrift_client
def open_client(self):
self.client.transport.open()
def close_client(self):
self.client.transport.close()
def define_schema(self):
keyspace1 = Cassandra.KsDef('Keyspace1', 'org.apache.cassandra.locator.SimpleStrategy', None, 1,
[
Cassandra.CfDef('Keyspace1', 'Standard1'),
Cassandra.CfDef('Keyspace1', 'Standard2'),
Cassandra.CfDef('Keyspace1', 'StandardLong1', comparator_type='LongType'),
Cassandra.CfDef('Keyspace1', 'StandardLong2', comparator_type='LongType'),
Cassandra.CfDef('Keyspace1', 'StandardInteger1', comparator_type='IntegerType'),
Cassandra.CfDef('Keyspace1', 'Super1', column_type='Super', subcomparator_type='LongType', row_cache_size=1000, key_cache_size=0),
Cassandra.CfDef('Keyspace1', 'Super2', column_type='Super', subcomparator_type='LongType'),
Cassandra.CfDef('Keyspace1', 'Super3', column_type='Super', subcomparator_type='LongType'),
Cassandra.CfDef('Keyspace1', 'Super4', column_type='Super', subcomparator_type='UTF8Type'),
Cassandra.CfDef('Keyspace1', 'Indexed1', column_metadata=[Cassandra.ColumnDef('birthdate', 'LongType', Cassandra.IndexType.KEYS, 'birthdate')]),
])
keyspace2 = Cassandra.KsDef('Keyspace2', 'org.apache.cassandra.locator.SimpleStrategy', None, 1,
[
Cassandra.CfDef('Keyspace2', 'Standard1'),
Cassandra.CfDef('Keyspace2', 'Standard3'),
Cassandra.CfDef('Keyspace2', 'Super3', column_type='Super', subcomparator_type='BytesType'),
Cassandra.CfDef('Keyspace2', 'Super4', column_type='Super', subcomparator_type='TimeUUIDType'),
])
for ks in [keyspace1, keyspace2]:
self.client.system_add_keyspace(ks)
class AvroTester(BaseTester):
client = None
extra_args = ['-a']
def open_client(self):
self.client = get_avro_client()
def close_client(self):
self.client.transceiver.conn.close()
def define_schema(self):
keyspace1 = dict()
keyspace1['name'] = 'Keyspace1'
keyspace1['replication_factor'] = 1
keyspace1['strategy_class'] = 'org.apache.cassandra.locator.SimpleStrategy'
keyspace1['cf_defs'] = [{
'keyspace': 'Keyspace1',
'name': 'Standard1',
}]
keyspace1['cf_defs'].append({
'keyspace': 'Keyspace1',
'name': 'Super1',
'column_type': 'Super',
'comparator_type': 'BytesType',
'subcomparator_type': 'LongType',
'comment': '',
'row_cache_size': 1000,
'preload_row_cache': False,
'key_cache_size': 0
})
keyspace1['cf_defs'].append({
'keyspace': 'Keyspace1',
'name': 'Super2',
'column_type': 'Super',
'subcomparator_type': 'LongType',
})
keyspace1['cf_defs'].append({
'keyspace': 'Keyspace1',
'name': 'Super3',
'column_type': 'Super',
'subcomparator_type': 'LongType',
})
keyspace1['cf_defs'].append({
'keyspace': 'Keyspace1',
'name': 'Super4',
'column_type': 'Super',
'subcomparator_type': 'UTF8Type',
})
keyspace1['cf_defs'].append({
'keyspace': 'Keyspace1',
'name': 'Indexed1',
'column_metadata': [{'name': 'birthdate', 'validation_class': 'LongType', 'index_type': 'KEYS', 'index_name': 'birthdate'}],
})
self.client.request('system_add_keyspace', {'ks_def': keyspace1})
keyspace2 = dict()
keyspace2['name'] = 'Keyspace2'
keyspace2['replication_factor'] = 1
keyspace2['strategy_class'] = 'org.apache.cassandra.locator.SimpleStrategy'
keyspace2['cf_defs'] = [{
'keyspace': 'Keyspace2',
'name': 'Standard1',
}]
keyspace2['cf_defs'].append({
'keyspace': 'Keyspace2',
'name': 'Standard3',
})
keyspace2['cf_defs'].append({
'keyspace': 'Keyspace2',
'name': 'Super3',
'column_type': 'Super',
'subcomparator_type': 'BytesType',
})
keyspace2['cf_defs'].append({
'keyspace': 'Keyspace2',
'name': 'Super4',
'column_type': 'Super',
'subcomparator_type': 'TimeUUIDType',
});
self.client.request('system_add_keyspace', {'ks_def': keyspace2})
# vim:ai sw=4 ts=4 tw=0 et
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
747,
12,
984,
12,
900,
12,
4673,
12,
8809,
199,
199,
363,
452,
363,
275,
788,
1231,
297,
283,
8430,
63,
1258,
418,
199,
199,
504,
17199,
14,
5545,
492,
19391,
199,
504,
17199,
14,
5545,
492,
377,
3869,
199,
504,
17199,
14,
5545,
492,
4221,
3370,
3041,
199,
504,
17199,
14,
3922,
492,
15934,
199,
893,
26,
272,
492,
2289,
293,
14,
32352,
465,
284,
2352,
272,
492,
2289,
293,
14,
3922,
465,
4113,
199,
2590,
3545,
26,
272,
986,
199,
199,
3,
1050,
286,
22388,
2082,
370,
984,
14,
515,
199,
44,
275,
747,
14,
515,
14,
4832,
3460,
493,
28634,
1294,
8,
736,
14,
515,
14,
4127,
31280,
19,
61,
199,
1231,
275,
747,
14,
515,
14,
4127,
14,
904,
8,
44,
9,
199,
63,
73,
515,
275,
747,
14,
515,
14,
904,
8,
1231,
12,
283,
3266,
297,
283,
8430,
297,
283,
2268,
13,
647,
358,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
904,
1547,
73,
515,
12,
283,
67,
22388,
1333,
199,
646,
445,
22388,
199,
199,
318,
664,
63,
8430,
63,
1258,
8,
1102,
534,
4195,
14,
16,
14,
16,
14,
17,
297,
1844,
29,
25,
11010,
304,
272,
2838,
275,
377,
3869,
14,
52,
3869,
8,
1102,
12,
1844,
9,
272,
7773,
275,
19391,
14,
52,
3160,
68,
7836,
8,
3450,
9,
272,
4113,
275,
15934,
14,
17302,
8,
5545,
9,
272,
1890,
275,
445,
22388,
14,
3041,
8,
3922,
9,
272,
1890,
14,
5545,
275,
7773,
272,
372,
1890,
199,
8430,
63,
1258,
275,
664,
63,
8430,
63,
1258,
342,
199,
199,
318,
664,
63,
1214,
293,
63,
1258,
8,
1102,
534,
4195,
14,
16,
14,
16,
14,
17,
297,
1844,
29,
25,
11010,
304,
272,
4177,
275,
747,
14,
515,
14,
904,
8,
1231,
12,
283,
3266,
15,
1214,
293,
297,
283,
67,
22388,
14,
1214,
2700,
358,
272,
4104,
275,
4113,
14,
1122,
8,
1490,
8,
3629,
680,
739,
1012,
272,
1890,
275,
284,
2352,
14,
2856,
3188,
6594,
8,
1102,
12,
1844,
9,
272,
372,
284,
2352,
14,
2017,
269,
8,
2625,
12,
1890,
9,
199,
199,
3150,
63,
5252,
275,
298,
2253,
63,
396,
14,
3150,
2,
199,
318,
4422,
837,
272,
372,
1109,
8,
1490,
8,
3150,
63,
5252,
680,
739,
1012,
199,
199,
533,
3523,
22403,
8,
785,
304,
272,
327,
10137,
642,
715,
7444,
1265,
787,
10250,
6617,
282,
1654,
436,
2066,
272,
327,
3879,
1454,
282,
2849,
511,
6169,
652,
27,
2295,
5534,
2985,
1343,
272,
327,
6169,
376,
2701,
1592,
14,
272,
1255,
1000,
275,
715,
272,
1890,
275,
488,
272,
2402,
63,
589,
275,
942,
339,
347,
1551,
63,
1258,
8,
277,
304,
267,
746,
4279,
342,
339,
347,
4002,
63,
1258,
8,
277,
304,
267,
746,
4279,
342,
2286,
347,
5627,
63,
3629,
8,
277,
304,
267,
746,
4279,
342,
339,
347,
3613,
8,
277,
304,
267,
340,
291,
14,
1065,
1000,
26,
288,
340,
747,
14,
515,
14,
2444,
8,
3150,
63,
5252,
304,
355,
4422,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1231,
12,
4422,
63,
5252,
9,
355,
870,
298,
1358,
3118,
12842,
10501,
12,
4366,
83,
1911,
2924,
450,
4422,
63,
515,
355,
984,
14,
2224,
342,
953,
327,
3633,
734,
2269,
8292,
288,
492,
5145,
288,
327,
11386,
664,
6602,
687,
3743,
15,
67,
22388,
14,
5963,
288,
367,
9017,
315,
788,
2253,
297,
283,
576,
297,
283,
3543,
793,
2565,
355,
862,
26,
490,
5145,
14,
9242,
360,
1506,
15,
396,
15,
67,
22388,
4805,
435,
9017,
9,
355,
871,
6440,
26,
490,
986,
288,
327,
1343,
314,
1654,
288,
492,
3873,
465,
2249,
288,
747,
14,
8563,
8,
1231,
9,
288,
747,
14,
2314,
459,
35,
3755,
3649,
2847,
63,
18171,
418,
275,
283,
396,
15,
67,
22388,
14,
262,
14,
609,
7,
288,
1249,
275,
788,
1393,
15,
67,
22388,
297,
2475,
80,
297,
4422,
63,
5252,
61,
435,
291,
14,
2911,
63,
589,
288,
2112,
275,
2249,
14,
7942,
8,
589,
12,
4635,
29,
681,
14,
6089,
12,
3839,
29,
681,
14,
6089,
9,
288,
900,
14,
4532,
8,
16,
14,
17,
9,
953,
327,
4907,
370,
652,
12,
543,
282,
2653,
315,
1930,
6020,
22396,
6835,
288,
1343,
275,
900,
14,
521,
342,
288,
1830,
900,
14,
521,
342,
665,
1343,
435,
1616,
26,
355,
862,
26,
490,
291,
14,
1490,
63,
1258,
342,
355,
871,
26,
490,
900,
14,
4532,
8,
16,
14,
17,
9,
355,
587,
26,
490,
2059,
288,
587,
26,
355,
870,
298,
20485,
1133,
4907,
370,
1654,
27,
12004,
316,
10864,
511,
2,
355,
327,
1937,
340,
2112,
365,
5139,
19708,
355,
2112,
14,
6843,
342,
14977,
340,
2112,
14,
9913,
365,
488,
26,
490,
747,
14,
8997,
8,
3150,
1062,
4673,
14,
7864,
30691,
9,
327,
2951,
315,
1930,
355,
587,
26,
490,
3839,
63,
585,
12,
4635,
63,
585,
275,
2112,
14,
10664,
342,
490,
870,
298,
26080,
26,
450,
83,
2,
450,
334,
2703,
63,
585,
9,
490,
870,
298,
933,
2303,
26,
450,
83,
2,
450,
334,
3083,
63,
585
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
747,
12,
984,
12,
900,
12,
4673,
12,
8809,
199,
199,
363,
452,
363,
275,
788,
1231,
297,
283,
8430,
63,
1258,
418,
199,
199,
504,
17199,
14,
5545,
492,
19391,
199,
504,
17199,
14,
5545,
492,
377,
3869,
199,
504,
17199,
14,
5545,
492,
4221,
3370,
3041,
199,
504,
17199,
14,
3922,
492,
15934,
199,
893,
26,
272,
492,
2289,
293,
14,
32352,
465,
284,
2352,
272,
492,
2289,
293,
14,
3922,
465,
4113,
199,
2590,
3545,
26,
272,
986,
199,
199,
3,
1050,
286,
22388,
2082,
370,
984,
14,
515,
199,
44,
275,
747,
14,
515,
14,
4832,
3460,
493,
28634,
1294,
8,
736,
14,
515,
14,
4127,
31280,
19,
61,
199,
1231,
275,
747,
14,
515,
14,
4127,
14,
904,
8,
44,
9,
199,
63,
73,
515,
275,
747,
14,
515,
14,
904,
8,
1231,
12,
283,
3266,
297,
283,
8430,
297,
283,
2268,
13,
647,
358,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
904,
1547,
73,
515,
12,
283,
67,
22388,
1333,
199,
646,
445,
22388,
199,
199,
318,
664,
63,
8430,
63,
1258,
8,
1102,
534,
4195,
14,
16,
14,
16,
14,
17,
297,
1844,
29,
25,
11010,
304,
272,
2838,
275,
377,
3869,
14,
52,
3869,
8,
1102,
12,
1844,
9,
272,
7773,
275,
19391,
14,
52,
3160,
68,
7836,
8,
3450,
9,
272,
4113,
275,
15934,
14,
17302,
8,
5545,
9,
272,
1890,
275,
445,
22388,
14,
3041,
8,
3922,
9,
272,
1890,
14,
5545,
275,
7773,
272,
372,
1890,
199,
8430,
63,
1258,
275,
664,
63,
8430,
63,
1258,
342,
199,
199,
318,
664,
63,
1214,
293,
63,
1258,
8,
1102,
534,
4195,
14,
16,
14,
16,
14,
17,
297,
1844,
29,
25,
11010,
304,
272,
4177,
275,
747,
14,
515,
14,
904,
8,
1231,
12,
283,
3266,
15,
1214,
293,
297,
283,
67,
22388,
14,
1214,
2700,
358,
272,
4104,
275,
4113,
14,
1122,
8,
1490,
8,
3629,
680,
739,
1012,
272,
1890,
275,
284,
2352,
14,
2856,
3188,
6594,
8,
1102,
12,
1844,
9,
272,
372,
284,
2352,
14,
2017,
269,
8,
2625,
12,
1890,
9,
199,
199,
3150,
63,
5252,
275,
298,
2253,
63,
396,
14,
3150,
2,
199,
318,
4422,
837,
272,
372,
1109,
8,
1490,
8,
3150,
63,
5252,
680,
739,
1012,
199,
199,
533,
3523,
22403,
8,
785,
304,
272,
327,
10137,
642,
715,
7444,
1265,
787,
10250,
6617,
282,
1654,
436,
2066,
272,
327,
3879,
1454,
282,
2849,
511,
6169,
652,
27,
2295,
5534,
2985,
1343,
272,
327,
6169,
376,
2701,
1592,
14,
272,
1255,
1000,
275,
715,
272,
1890,
275,
488,
272,
2402,
63,
589,
275,
942,
339,
347,
1551,
63,
1258,
8,
277,
304,
267,
746,
4279,
342,
339,
347,
4002,
63,
1258,
8,
277,
304,
267,
746,
4279,
342,
2286,
347,
5627,
63,
3629,
8,
277,
304,
267,
746,
4279,
342,
339,
347,
3613,
8,
277,
304,
267,
340,
291,
14,
1065,
1000,
26,
288,
340,
747,
14,
515,
14,
2444,
8,
3150,
63,
5252,
304,
355,
4422,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1231,
12,
4422,
63,
5252,
9,
355,
870,
298,
1358,
3118,
12842,
10501,
12,
4366,
83,
1911,
2924,
450,
4422,
63,
515,
355,
984,
14,
2224,
342,
953,
327,
3633,
734,
2269,
8292,
288,
492,
5145,
288,
327,
11386,
664,
6602,
687,
3743,
15,
67,
22388,
14,
5963,
288,
367,
9017,
315,
788,
2253,
297,
283,
576,
297,
283,
3543,
793,
2565,
355,
862,
26,
490,
5145,
14,
9242,
360,
1506,
15,
396,
15,
67,
22388,
4805,
435,
9017,
9,
355,
871,
6440,
26,
490,
986,
288,
327,
1343,
314,
1654,
288,
492,
3873,
465,
2249,
288,
747,
14,
8563,
8,
1231,
9,
288,
747,
14,
2314,
459,
35,
3755,
3649,
2847,
63,
18171,
418,
275,
283,
396,
15,
67,
22388,
14,
262,
14,
609,
7,
288,
1249,
275,
788,
1393,
15,
67,
22388,
297,
2475,
80,
297,
4422,
63,
5252,
61,
435,
291,
14,
2911,
63,
589,
288,
2112,
275,
2249,
14,
7942,
8,
589,
12,
4635,
29,
681,
14,
6089,
12,
3839,
29,
681,
14,
6089,
9,
288,
900,
14,
4532,
8,
16,
14,
17,
9,
953,
327,
4907,
370,
652,
12,
543,
282,
2653,
315,
1930,
6020,
22396,
6835,
288,
1343,
275,
900,
14,
521,
342,
288,
1830,
900,
14,
521,
342,
665,
1343,
435,
1616,
26,
355,
862,
26,
490,
291,
14,
1490,
63,
1258,
342,
355,
871,
26,
490,
900,
14,
4532,
8,
16,
14,
17,
9,
355,
587,
26,
490,
2059,
288,
587,
26,
355,
870,
298,
20485,
1133,
4907,
370,
1654,
27,
12004,
316,
10864,
511,
2,
355,
327,
1937,
340,
2112,
365,
5139,
19708,
355,
2112,
14,
6843,
342,
14977,
340,
2112,
14,
9913,
365,
488,
26,
490,
747,
14,
8997,
8,
3150,
1062,
4673,
14,
7864,
30691,
9,
327,
2951,
315,
1930,
355,
587,
26,
490,
3839,
63,
585,
12,
4635,
63,
585,
275,
2112,
14,
10664,
342,
490,
870,
298,
26080,
26,
450,
83,
2,
450,
334,
2703,
63,
585,
9,
490,
870,
298,
933,
2303,
26,
450,
83,
2,
450,
334,
3083,
63,
585,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pablocastro/elasticsearch
|
dev-tools/create_bwc_repo_with_ancient_indices.py
|
92
|
2753
|
import create_bwc_index
import logging
import os
import shutil
import subprocess
import sys
import tempfile
def fetch_version(version):
logging.info('fetching ES version %s' % version)
if subprocess.call([sys.executable, os.path.join(os.path.split(sys.argv[0])[0], 'get-bwc-version.py'), version]) != 0:
raise RuntimeError('failed to download ES version %s' % version)
def main():
'''
Creates a back compat index (.zip) using v0.20 and then creates a snapshot of it using v1.1
'''
logging.basicConfig(format='[%(levelname)s] [%(asctime)s] %(message)s', level=logging.INFO,
datefmt='%Y-%m-%d %I:%M:%S %p')
logging.getLogger('elasticsearch').setLevel(logging.ERROR)
logging.getLogger('urllib3').setLevel(logging.WARN)
tmp_dir = tempfile.mkdtemp()
try:
data_dir = os.path.join(tmp_dir, 'data')
logging.info('Temp data dir: %s' % data_dir)
first_version = '0.20.6'
second_version = '1.1.2'
index_name = 'index-%s-and-%s' % (first_version, second_version)
# Download old ES releases if necessary:
release_dir = os.path.join('backwards', 'elasticsearch-%s' % first_version)
if not os.path.exists(release_dir):
fetch_version(first_version)
node = create_bwc_index.start_node(first_version, release_dir, data_dir, cluster_name=index_name)
client = create_bwc_index.create_client()
# Creates the index & indexes docs w/ first_version:
create_bwc_index.generate_index(client, first_version, index_name)
# Make sure we write segments:
flush_result = client.indices.flush(index=index_name)
if not flush_result['ok']:
raise RuntimeError('flush failed: %s' % str(flush_result))
create_bwc_index.shutdown_node(node)
print('%s server output:\n%s' % (first_version, node.stdout.read().decode('utf-8')))
node = None
release_dir = os.path.join('backwards', 'elasticsearch-%s' % second_version)
if not os.path.exists(release_dir):
fetch_version(second_version)
# Now use second_version to snapshot the index:
node = create_bwc_index.start_node(second_version, release_dir, data_dir, cluster_name=index_name)
client = create_bwc_index.create_client()
repo_dir = os.path.join(tmp_dir, 'repo')
create_bwc_index.snapshot_index(client, second_version, repo_dir)
create_bwc_index.shutdown_node(node)
print('%s server output:\n%s' % (second_version, node.stdout.read().decode('utf-8')))
create_bwc_index.compress(tmp_dir, "src/test/resources/org/elasticsearch/bwcompat", 'unsupportedrepo-%s.zip' % first_version, 'repo')
node = None
finally:
if node is not None:
create_bwc_index.shutdown_node(node)
shutil.rmtree(tmp_dir)
if __name__ == '__main__':
main()
|
apache-2.0
|
[
646,
1218,
63,
12415,
67,
63,
1080,
199,
646,
2050,
199,
646,
747,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
199,
646,
5549,
199,
199,
318,
5267,
63,
1023,
8,
1023,
304,
523,
2050,
14,
815,
360,
3535,
316,
10427,
1015,
450,
83,
7,
450,
1015,
9,
523,
340,
3873,
14,
1250,
779,
1274,
14,
5904,
12,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
1294,
8,
1274,
14,
3020,
59,
16,
11057,
16,
467,
283,
362,
13,
12415,
67,
13,
1023,
14,
647,
659,
1015,
566,
1137,
378,
26,
272,
746,
6064,
360,
4892,
370,
5235,
10427,
1015,
450,
83,
7,
450,
1015,
9,
199,
199,
318,
2446,
837,
523,
1449,
523,
10560,
282,
1771,
8434,
1478,
17048,
3065,
9,
1808,
373,
16,
14,
1165,
436,
2066,
8491,
282,
5740,
402,
652,
1808,
373,
17,
14,
17,
523,
1449,
12244,
2050,
14,
19602,
8,
908,
30845,
2840,
20056,
9,
83,
61,
359,
2840,
18331,
9,
83,
61,
2818,
1188,
9,
83,
297,
2166,
29,
4806,
14,
4531,
12,
1993,
1434,
5045,
9569,
57,
3295,
77,
3295,
68,
450,
41,
2689,
45,
2689,
51,
450,
80,
358,
523,
2050,
14,
5572,
360,
25651,
1959,
13548,
8,
4806,
14,
3170,
9,
523,
2050,
14,
5572,
360,
4078,
19,
1959,
13548,
8,
4806,
14,
17449,
9,
819,
3529,
63,
694,
275,
5549,
14,
11983,
342,
523,
862,
26,
272,
666,
63,
694,
275,
747,
14,
515,
14,
904,
8,
2791,
63,
694,
12,
283,
576,
358,
272,
2050,
14,
815,
360,
6530,
666,
2935,
26,
450,
83,
7,
450,
666,
63,
694,
9,
339,
1642,
63,
1023,
275,
283,
16,
14,
1165,
14,
22,
7,
272,
3499,
63,
1023,
275,
283,
17,
14,
17,
14,
18,
7,
272,
1478,
63,
354,
275,
283,
1080,
3295,
83,
13,
460,
3295,
83,
7,
450,
334,
2246,
63,
1023,
12,
3499,
63,
1023,
9,
339,
327,
17955,
2269,
10427,
19015,
340,
5784,
26,
272,
4683,
63,
694,
275,
747,
14,
515,
14,
904,
360,
22269,
297,
283,
25651,
3295,
83,
7,
450,
1642,
63,
1023,
9,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
3221,
63,
694,
304,
489,
5267,
63,
1023,
8,
2246,
63,
1023,
9,
339,
1031,
275,
1218,
63,
12415,
67,
63,
1080,
14,
928,
63,
932,
8,
2246,
63,
1023,
12,
4683,
63,
694,
12,
666,
63,
694,
12,
4350,
63,
354,
29,
1080,
63,
354,
9,
272,
1890,
275,
1218,
63,
12415,
67,
63,
1080,
14,
981,
63,
1258,
342,
339,
327,
10560,
314,
1478,
1253,
10507,
9149,
336,
15,
1642,
63,
1023,
26,
272,
1218,
63,
12415,
67,
63,
1080,
14,
4208,
63,
1080,
8,
1258,
12,
1642,
63,
1023,
12,
1478,
63,
354,
9,
339,
327,
4155,
3238,
781,
2218,
11998,
26,
272,
8976,
63,
1099,
275,
1890,
14,
4108,
14,
4939,
8,
1080,
29,
1080,
63,
354,
9,
272,
340,
440,
8976,
63,
1099,
459,
745,
2565,
489,
746,
6064,
360,
4939,
3405,
26,
450,
83,
7,
450,
620,
8,
4939,
63,
1099,
430,
339,
1218,
63,
12415,
67,
63,
1080,
14,
8831,
63,
932,
8,
932,
9,
272,
870,
3508,
83,
1654,
1072,
3427,
78,
5,
83,
7,
450,
334,
2246,
63,
1023,
12,
1031,
14,
2703,
14,
739,
1252,
2708,
360,
1624,
13,
24,
7058,
272,
1031,
275,
488,
339,
4683,
63,
694,
275,
747,
14,
515,
14,
904,
360,
22269,
297,
283,
25651,
3295,
83,
7,
450,
3499,
63,
1023,
9,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
3221,
63,
694,
304,
489,
5267,
63,
1023,
8,
4375,
63,
1023,
9,
339,
327,
7356,
675,
3499,
63,
1023,
370,
5740,
314,
1478,
26,
272,
1031,
275,
1218,
63,
12415,
67,
63,
1080,
14,
928,
63,
932,
8,
4375,
63,
1023,
12,
4683,
63,
694,
12,
666,
63,
694,
12,
4350,
63,
354,
29,
1080,
63,
354,
9,
272,
1890,
275,
1218,
63,
12415,
67,
63,
1080,
14,
981,
63,
1258,
342,
339,
3831,
63,
694,
275,
747,
14,
515,
14,
904,
8,
2791,
63,
694,
12,
283,
3417,
358,
272,
1218,
63,
12415,
67,
63,
1080,
14,
4753,
63,
1080,
8,
1258,
12,
3499,
63,
1023,
12,
3831,
63,
694,
9,
272,
1218,
63,
12415,
67,
63,
1080,
14,
8831,
63,
932,
8,
932,
9,
272,
870,
3508,
83,
1654,
1072,
3427,
78,
5,
83,
7,
450,
334,
4375,
63,
1023,
12,
1031,
14,
2703,
14,
739,
1252,
2708,
360,
1624,
13,
24,
7058,
339,
1218,
63,
12415,
67,
63,
1080,
14,
6447,
8,
2791,
63,
694,
12,
298,
2164,
15,
396,
15,
4435,
15,
1308,
15,
25651,
15,
12415,
5819,
401,
283,
15267,
3417,
3295,
83,
14,
3065,
7,
450,
1642,
63,
1023,
12,
283,
3417,
358,
339,
1031,
275,
488,
523,
3753,
26,
272,
340,
1031,
365,
440,
488,
26,
489,
1218,
63,
12415,
67,
63,
1080,
14,
8831,
63,
932,
8,
932,
9,
272,
5145,
14,
9242,
8,
2791,
63,
694,
9,
1362,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2446,
342,
2043,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1218,
63,
12415,
67,
63,
1080,
199,
646,
2050,
199,
646,
747,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
199,
646,
5549,
199,
199,
318,
5267,
63,
1023,
8,
1023,
304,
523,
2050,
14,
815,
360,
3535,
316,
10427,
1015,
450,
83,
7,
450,
1015,
9,
523,
340,
3873,
14,
1250,
779,
1274,
14,
5904,
12,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
1294,
8,
1274,
14,
3020,
59,
16,
11057,
16,
467,
283,
362,
13,
12415,
67,
13,
1023,
14,
647,
659,
1015,
566,
1137,
378,
26,
272,
746,
6064,
360,
4892,
370,
5235,
10427,
1015,
450,
83,
7,
450,
1015,
9,
199,
199,
318,
2446,
837,
523,
1449,
523,
10560,
282,
1771,
8434,
1478,
17048,
3065,
9,
1808,
373,
16,
14,
1165,
436,
2066,
8491,
282,
5740,
402,
652,
1808,
373,
17,
14,
17,
523,
1449,
12244,
2050,
14,
19602,
8,
908,
30845,
2840,
20056,
9,
83,
61,
359,
2840,
18331,
9,
83,
61,
2818,
1188,
9,
83,
297,
2166,
29,
4806,
14,
4531,
12,
1993,
1434,
5045,
9569,
57,
3295,
77,
3295,
68,
450,
41,
2689,
45,
2689,
51,
450,
80,
358,
523,
2050,
14,
5572,
360,
25651,
1959,
13548,
8,
4806,
14,
3170,
9,
523,
2050,
14,
5572,
360,
4078,
19,
1959,
13548,
8,
4806,
14,
17449,
9,
819,
3529,
63,
694,
275,
5549,
14,
11983,
342,
523,
862,
26,
272,
666,
63,
694,
275,
747,
14,
515,
14,
904,
8,
2791,
63,
694,
12,
283,
576,
358,
272,
2050,
14,
815,
360,
6530,
666,
2935,
26,
450,
83,
7,
450,
666,
63,
694,
9,
339,
1642,
63,
1023,
275,
283,
16,
14,
1165,
14,
22,
7,
272,
3499,
63,
1023,
275,
283,
17,
14,
17,
14,
18,
7,
272,
1478,
63,
354,
275,
283,
1080,
3295,
83,
13,
460,
3295,
83,
7,
450,
334,
2246,
63,
1023,
12,
3499,
63,
1023,
9,
339,
327,
17955,
2269,
10427,
19015,
340,
5784,
26,
272,
4683,
63,
694,
275,
747,
14,
515,
14,
904,
360,
22269,
297,
283,
25651,
3295,
83,
7,
450,
1642,
63,
1023,
9,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
3221,
63,
694,
304,
489,
5267,
63,
1023,
8,
2246,
63,
1023,
9,
339,
1031,
275,
1218,
63,
12415,
67,
63,
1080,
14,
928,
63,
932,
8,
2246,
63,
1023,
12,
4683,
63,
694,
12,
666,
63,
694,
12,
4350,
63,
354,
29,
1080,
63,
354,
9,
272,
1890,
275,
1218,
63,
12415,
67,
63,
1080,
14,
981,
63,
1258,
342,
339,
327,
10560,
314,
1478,
1253,
10507,
9149,
336,
15,
1642,
63,
1023,
26,
272,
1218,
63,
12415,
67,
63,
1080,
14,
4208,
63,
1080,
8,
1258,
12,
1642,
63,
1023,
12,
1478,
63,
354,
9,
339,
327,
4155,
3238,
781,
2218,
11998,
26,
272,
8976,
63,
1099,
275,
1890,
14,
4108,
14,
4939,
8,
1080,
29,
1080,
63,
354,
9,
272,
340,
440,
8976,
63,
1099,
459,
745,
2565,
489,
746,
6064,
360,
4939,
3405,
26,
450,
83,
7,
450,
620,
8,
4939,
63,
1099,
430,
339,
1218,
63,
12415,
67,
63,
1080,
14,
8831,
63,
932,
8,
932,
9,
272,
870,
3508,
83,
1654,
1072,
3427,
78,
5,
83,
7,
450,
334,
2246,
63,
1023,
12,
1031,
14,
2703,
14,
739,
1252,
2708,
360,
1624,
13,
24,
7058,
272,
1031,
275,
488,
339,
4683,
63,
694,
275,
747,
14,
515,
14,
904,
360,
22269,
297,
283,
25651,
3295,
83,
7,
450,
3499,
63,
1023,
9,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
3221,
63,
694,
304,
489,
5267,
63,
1023,
8,
4375,
63,
1023,
9,
339,
327,
7356,
675,
3499,
63,
1023,
370,
5740,
314,
1478,
26,
272,
1031,
275,
1218,
63,
12415,
67,
63,
1080,
14,
928,
63,
932,
8,
4375,
63,
1023,
12,
4683,
63,
694,
12,
666,
63,
694,
12,
4350,
63,
354,
29,
1080,
63,
354,
9,
272,
1890,
275,
1218,
63,
12415,
67,
63,
1080,
14,
981,
63,
1258,
342,
339,
3831,
63,
694,
275,
747,
14,
515,
14,
904,
8,
2791,
63,
694,
12,
283,
3417,
358,
272,
1218,
63,
12415,
67,
63,
1080,
14,
4753,
63,
1080,
8,
1258,
12,
3499,
63,
1023,
12,
3831,
63,
694,
9,
272,
1218,
63,
12415,
67,
63,
1080,
14,
8831,
63,
932,
8,
932,
9,
272,
870,
3508,
83,
1654,
1072,
3427,
78,
5,
83,
7,
450,
334,
4375,
63,
1023,
12,
1031,
14,
2703,
14,
739,
1252,
2708,
360,
1624,
13,
24,
7058,
339,
1218,
63,
12415,
67,
63,
1080,
14,
6447,
8,
2791,
63,
694,
12,
298,
2164,
15,
396,
15,
4435,
15,
1308,
15,
25651,
15,
12415,
5819,
401,
283,
15267,
3417,
3295,
83,
14,
3065,
7,
450,
1642,
63,
1023,
12,
283,
3417,
358,
339,
1031,
275,
488,
523,
3753,
26,
272,
340,
1031,
365,
440,
488,
26,
489,
1218,
63,
12415,
67,
63,
1080,
14,
8831,
63,
932,
8,
932,
9,
272,
5145,
14,
9242,
8,
2791,
63,
694,
9,
1362,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2446,
342,
2043,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
yongni/grpc
|
src/python/grpcio_tests/tests/unit/_rpc_test.py
|
16
|
35279
|
# Copyright 2016 gRPC authors.
#
# 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.
"""Test of RPCs made against gRPC Python's application-layer API."""
import itertools
import threading
import unittest
from concurrent import futures
import grpc
from grpc.framework.foundation import logging_pool
from tests.unit.framework.common import test_constants
from tests.unit.framework.common import test_control
_SERIALIZE_REQUEST = lambda bytestring: bytestring * 2
_DESERIALIZE_REQUEST = lambda bytestring: bytestring[len(bytestring) // 2:]
_SERIALIZE_RESPONSE = lambda bytestring: bytestring * 3
_DESERIALIZE_RESPONSE = lambda bytestring: bytestring[:len(bytestring) // 3]
_UNARY_UNARY = '/test/UnaryUnary'
_UNARY_STREAM = '/test/UnaryStream'
_STREAM_UNARY = '/test/StreamUnary'
_STREAM_STREAM = '/test/StreamStream'
class _Callback(object):
def __init__(self):
self._condition = threading.Condition()
self._value = None
self._called = False
def __call__(self, value):
with self._condition:
self._value = value
self._called = True
self._condition.notify_all()
def value(self):
with self._condition:
while not self._called:
self._condition.wait()
return self._value
class _Handler(object):
def __init__(self, control):
self._control = control
def handle_unary_unary(self, request, servicer_context):
self._control.control()
if servicer_context is not None:
servicer_context.set_trailing_metadata((('testkey', 'testvalue',),))
# TODO(https://github.com/grpc/grpc/issues/8483): test the values
# returned by these methods rather than only "smoke" testing that
# the return after having been called.
servicer_context.is_active()
servicer_context.time_remaining()
return request
def handle_unary_stream(self, request, servicer_context):
for _ in range(test_constants.STREAM_LENGTH):
self._control.control()
yield request
self._control.control()
if servicer_context is not None:
servicer_context.set_trailing_metadata((('testkey', 'testvalue',),))
def handle_stream_unary(self, request_iterator, servicer_context):
if servicer_context is not None:
servicer_context.invocation_metadata()
self._control.control()
response_elements = []
for request in request_iterator:
self._control.control()
response_elements.append(request)
self._control.control()
if servicer_context is not None:
servicer_context.set_trailing_metadata((('testkey', 'testvalue',),))
return b''.join(response_elements)
def handle_stream_stream(self, request_iterator, servicer_context):
self._control.control()
if servicer_context is not None:
servicer_context.set_trailing_metadata((('testkey', 'testvalue',),))
for request in request_iterator:
self._control.control()
yield request
self._control.control()
class _MethodHandler(grpc.RpcMethodHandler):
def __init__(self, request_streaming, response_streaming,
request_deserializer, response_serializer, unary_unary,
unary_stream, stream_unary, stream_stream):
self.request_streaming = request_streaming
self.response_streaming = response_streaming
self.request_deserializer = request_deserializer
self.response_serializer = response_serializer
self.unary_unary = unary_unary
self.unary_stream = unary_stream
self.stream_unary = stream_unary
self.stream_stream = stream_stream
class _GenericHandler(grpc.GenericRpcHandler):
def __init__(self, handler):
self._handler = handler
def service(self, handler_call_details):
if handler_call_details.method == _UNARY_UNARY:
return _MethodHandler(False, False, None, None,
self._handler.handle_unary_unary, None, None,
None)
elif handler_call_details.method == _UNARY_STREAM:
return _MethodHandler(False, True, _DESERIALIZE_REQUEST,
_SERIALIZE_RESPONSE, None,
self._handler.handle_unary_stream, None, None)
elif handler_call_details.method == _STREAM_UNARY:
return _MethodHandler(True, False, _DESERIALIZE_REQUEST,
_SERIALIZE_RESPONSE, None, None,
self._handler.handle_stream_unary, None)
elif handler_call_details.method == _STREAM_STREAM:
return _MethodHandler(True, True, None, None, None, None, None,
self._handler.handle_stream_stream)
else:
return None
def _unary_unary_multi_callable(channel):
return channel.unary_unary(_UNARY_UNARY)
def _unary_stream_multi_callable(channel):
return channel.unary_stream(
_UNARY_STREAM,
request_serializer=_SERIALIZE_REQUEST,
response_deserializer=_DESERIALIZE_RESPONSE)
def _stream_unary_multi_callable(channel):
return channel.stream_unary(
_STREAM_UNARY,
request_serializer=_SERIALIZE_REQUEST,
response_deserializer=_DESERIALIZE_RESPONSE)
def _stream_stream_multi_callable(channel):
return channel.stream_stream(_STREAM_STREAM)
class RPCTest(unittest.TestCase):
def setUp(self):
self._control = test_control.PauseFailControl()
self._handler = _Handler(self._control)
self._server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY)
self._server = grpc.server(self._server_pool)
port = self._server.add_insecure_port('[::]:0')
self._server.add_generic_rpc_handlers((_GenericHandler(self._handler),))
self._server.start()
self._channel = grpc.insecure_channel('localhost:%d' % port)
def tearDown(self):
self._server.stop(None)
self._server_pool.shutdown(wait=True)
def testUnrecognizedMethod(self):
request = b'abc'
with self.assertRaises(grpc.RpcError) as exception_context:
self._channel.unary_unary('NoSuchMethod')(request)
self.assertEqual(grpc.StatusCode.UNIMPLEMENTED,
exception_context.exception.code())
def testSuccessfulUnaryRequestBlockingUnaryResponse(self):
request = b'\x07\x08'
expected_response = self._handler.handle_unary_unary(request, None)
multi_callable = _unary_unary_multi_callable(self._channel)
response = multi_callable(
request,
metadata=(('test', 'SuccessfulUnaryRequestBlockingUnaryResponse'),))
self.assertEqual(expected_response, response)
def testSuccessfulUnaryRequestBlockingUnaryResponseWithCall(self):
request = b'\x07\x08'
expected_response = self._handler.handle_unary_unary(request, None)
multi_callable = _unary_unary_multi_callable(self._channel)
response, call = multi_callable.with_call(
request,
metadata=(('test',
'SuccessfulUnaryRequestBlockingUnaryResponseWithCall'),))
self.assertEqual(expected_response, response)
self.assertIs(grpc.StatusCode.OK, call.code())
def testSuccessfulUnaryRequestFutureUnaryResponse(self):
request = b'\x07\x08'
expected_response = self._handler.handle_unary_unary(request, None)
multi_callable = _unary_unary_multi_callable(self._channel)
response_future = multi_callable.future(
request,
metadata=(('test', 'SuccessfulUnaryRequestFutureUnaryResponse'),))
response = response_future.result()
self.assertIsInstance(response_future, grpc.Future)
self.assertIsInstance(response_future, grpc.Call)
self.assertEqual(expected_response, response)
self.assertIsNone(response_future.exception())
self.assertIsNone(response_future.traceback())
def testSuccessfulUnaryRequestStreamResponse(self):
request = b'\x37\x58'
expected_responses = tuple(
self._handler.handle_unary_stream(request, None))
multi_callable = _unary_stream_multi_callable(self._channel)
response_iterator = multi_callable(
request,
metadata=(('test', 'SuccessfulUnaryRequestStreamResponse'),))
responses = tuple(response_iterator)
self.assertSequenceEqual(expected_responses, responses)
def testSuccessfulStreamRequestBlockingUnaryResponse(self):
requests = tuple(b'\x07\x08'
for _ in range(test_constants.STREAM_LENGTH))
expected_response = self._handler.handle_stream_unary(
iter(requests), None)
request_iterator = iter(requests)
multi_callable = _stream_unary_multi_callable(self._channel)
response = multi_callable(
request_iterator,
metadata=(
('test', 'SuccessfulStreamRequestBlockingUnaryResponse'),))
self.assertEqual(expected_response, response)
def testSuccessfulStreamRequestBlockingUnaryResponseWithCall(self):
requests = tuple(b'\x07\x08'
for _ in range(test_constants.STREAM_LENGTH))
expected_response = self._handler.handle_stream_unary(
iter(requests), None)
request_iterator = iter(requests)
multi_callable = _stream_unary_multi_callable(self._channel)
response, call = multi_callable.with_call(
request_iterator,
metadata=(
('test',
'SuccessfulStreamRequestBlockingUnaryResponseWithCall'),))
self.assertEqual(expected_response, response)
self.assertIs(grpc.StatusCode.OK, call.code())
def testSuccessfulStreamRequestFutureUnaryResponse(self):
requests = tuple(b'\x07\x08'
for _ in range(test_constants.STREAM_LENGTH))
expected_response = self._handler.handle_stream_unary(
iter(requests), None)
request_iterator = iter(requests)
multi_callable = _stream_unary_multi_callable(self._channel)
response_future = multi_callable.future(
request_iterator,
metadata=(('test', 'SuccessfulStreamRequestFutureUnaryResponse'),))
response = response_future.result()
self.assertEqual(expected_response, response)
self.assertIsNone(response_future.exception())
self.assertIsNone(response_future.traceback())
def testSuccessfulStreamRequestStreamResponse(self):
requests = tuple(b'\x77\x58'
for _ in range(test_constants.STREAM_LENGTH))
expected_responses = tuple(
self._handler.handle_stream_stream(iter(requests), None))
request_iterator = iter(requests)
multi_callable = _stream_stream_multi_callable(self._channel)
response_iterator = multi_callable(
request_iterator,
metadata=(('test', 'SuccessfulStreamRequestStreamResponse'),))
responses = tuple(response_iterator)
self.assertSequenceEqual(expected_responses, responses)
def testSequentialInvocations(self):
first_request = b'\x07\x08'
second_request = b'\x0809'
expected_first_response = self._handler.handle_unary_unary(
first_request, None)
expected_second_response = self._handler.handle_unary_unary(
second_request, None)
multi_callable = _unary_unary_multi_callable(self._channel)
first_response = multi_callable(
first_request, metadata=(('test', 'SequentialInvocations'),))
second_response = multi_callable(
second_request, metadata=(('test', 'SequentialInvocations'),))
self.assertEqual(expected_first_response, first_response)
self.assertEqual(expected_second_response, second_response)
def testConcurrentBlockingInvocations(self):
pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY)
requests = tuple(b'\x07\x08'
for _ in range(test_constants.STREAM_LENGTH))
expected_response = self._handler.handle_stream_unary(
iter(requests), None)
expected_responses = [expected_response
] * test_constants.THREAD_CONCURRENCY
response_futures = [None] * test_constants.THREAD_CONCURRENCY
multi_callable = _stream_unary_multi_callable(self._channel)
for index in range(test_constants.THREAD_CONCURRENCY):
request_iterator = iter(requests)
response_future = pool.submit(
multi_callable,
request_iterator,
metadata=(('test', 'ConcurrentBlockingInvocations'),))
response_futures[index] = response_future
responses = tuple(response_future.result()
for response_future in response_futures)
pool.shutdown(wait=True)
self.assertSequenceEqual(expected_responses, responses)
def testConcurrentFutureInvocations(self):
requests = tuple(b'\x07\x08'
for _ in range(test_constants.STREAM_LENGTH))
expected_response = self._handler.handle_stream_unary(
iter(requests), None)
expected_responses = [expected_response
] * test_constants.THREAD_CONCURRENCY
response_futures = [None] * test_constants.THREAD_CONCURRENCY
multi_callable = _stream_unary_multi_callable(self._channel)
for index in range(test_constants.THREAD_CONCURRENCY):
request_iterator = iter(requests)
response_future = multi_callable.future(
request_iterator,
metadata=(('test', 'ConcurrentFutureInvocations'),))
response_futures[index] = response_future
responses = tuple(response_future.result()
for response_future in response_futures)
self.assertSequenceEqual(expected_responses, responses)
def testWaitingForSomeButNotAllConcurrentFutureInvocations(self):
pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY)
request = b'\x67\x68'
expected_response = self._handler.handle_unary_unary(request, None)
response_futures = [None] * test_constants.THREAD_CONCURRENCY
lock = threading.Lock()
test_is_running_cell = [True]
def wrap_future(future):
def wrap():
try:
return future.result()
except grpc.RpcError:
with lock:
if test_is_running_cell[0]:
raise
return None
return wrap
multi_callable = _unary_unary_multi_callable(self._channel)
for index in range(test_constants.THREAD_CONCURRENCY):
inner_response_future = multi_callable.future(
request,
metadata=(
('test',
'WaitingForSomeButNotAllConcurrentFutureInvocations'),))
outer_response_future = pool.submit(
wrap_future(inner_response_future))
response_futures[index] = outer_response_future
some_completed_response_futures_iterator = itertools.islice(
futures.as_completed(response_futures),
test_constants.THREAD_CONCURRENCY // 2)
for response_future in some_completed_response_futures_iterator:
self.assertEqual(expected_response, response_future.result())
with lock:
test_is_running_cell[0] = False
def testConsumingOneStreamResponseUnaryRequest(self):
request = b'\x57\x38'
multi_callable = _unary_stream_multi_callable(self._channel)
response_iterator = multi_callable(
request,
metadata=(('test', 'ConsumingOneStreamResponseUnaryRequest'),))
next(response_iterator)
def testConsumingSomeButNotAllStreamResponsesUnaryRequest(self):
request = b'\x57\x38'
multi_callable = _unary_stream_multi_callable(self._channel)
response_iterator = multi_callable(
request,
metadata=(
('test', 'ConsumingSomeButNotAllStreamResponsesUnaryRequest'),))
for _ in range(test_constants.STREAM_LENGTH // 2):
next(response_iterator)
def testConsumingSomeButNotAllStreamResponsesStreamRequest(self):
requests = tuple(b'\x67\x88'
for _ in range(test_constants.STREAM_LENGTH))
request_iterator = iter(requests)
multi_callable = _stream_stream_multi_callable(self._channel)
response_iterator = multi_callable(
request_iterator,
metadata=(('test',
'ConsumingSomeButNotAllStreamResponsesStreamRequest'),))
for _ in range(test_constants.STREAM_LENGTH // 2):
next(response_iterator)
def testConsumingTooManyStreamResponsesStreamRequest(self):
requests = tuple(b'\x67\x88'
for _ in range(test_constants.STREAM_LENGTH))
request_iterator = iter(requests)
multi_callable = _stream_stream_multi_callable(self._channel)
response_iterator = multi_callable(
request_iterator,
metadata=(
('test', 'ConsumingTooManyStreamResponsesStreamRequest'),))
for _ in range(test_constants.STREAM_LENGTH):
next(response_iterator)
for _ in range(test_constants.STREAM_LENGTH):
with self.assertRaises(StopIteration):
next(response_iterator)
self.assertIsNotNone(response_iterator.initial_metadata())
self.assertIs(grpc.StatusCode.OK, response_iterator.code())
self.assertIsNotNone(response_iterator.details())
self.assertIsNotNone(response_iterator.trailing_metadata())
def testCancelledUnaryRequestUnaryResponse(self):
request = b'\x07\x17'
multi_callable = _unary_unary_multi_callable(self._channel)
with self._control.pause():
response_future = multi_callable.future(
request,
metadata=(('test', 'CancelledUnaryRequestUnaryResponse'),))
response_future.cancel()
self.assertTrue(response_future.cancelled())
with self.assertRaises(grpc.FutureCancelledError):
response_future.result()
with self.assertRaises(grpc.FutureCancelledError):
response_future.exception()
with self.assertRaises(grpc.FutureCancelledError):
response_future.traceback()
self.assertIs(grpc.StatusCode.CANCELLED, response_future.code())
def testCancelledUnaryRequestStreamResponse(self):
request = b'\x07\x19'
multi_callable = _unary_stream_multi_callable(self._channel)
with self._control.pause():
response_iterator = multi_callable(
request,
metadata=(('test', 'CancelledUnaryRequestStreamResponse'),))
self._control.block_until_paused()
response_iterator.cancel()
with self.assertRaises(grpc.RpcError) as exception_context:
next(response_iterator)
self.assertIs(grpc.StatusCode.CANCELLED,
exception_context.exception.code())
self.assertIsNotNone(response_iterator.initial_metadata())
self.assertIs(grpc.StatusCode.CANCELLED, response_iterator.code())
self.assertIsNotNone(response_iterator.details())
self.assertIsNotNone(response_iterator.trailing_metadata())
def testCancelledStreamRequestUnaryResponse(self):
requests = tuple(b'\x07\x08'
for _ in range(test_constants.STREAM_LENGTH))
request_iterator = iter(requests)
multi_callable = _stream_unary_multi_callable(self._channel)
with self._control.pause():
response_future = multi_callable.future(
request_iterator,
metadata=(('test', 'CancelledStreamRequestUnaryResponse'),))
self._control.block_until_paused()
response_future.cancel()
self.assertTrue(response_future.cancelled())
with self.assertRaises(grpc.FutureCancelledError):
response_future.result()
with self.assertRaises(grpc.FutureCancelledError):
response_future.exception()
with self.assertRaises(grpc.FutureCancelledError):
response_future.traceback()
self.assertIsNotNone(response_future.initial_metadata())
self.assertIs(grpc.StatusCode.CANCELLED, response_future.code())
self.assertIsNotNone(response_future.details())
self.assertIsNotNone(response_future.trailing_metadata())
def testCancelledStreamRequestStreamResponse(self):
requests = tuple(b'\x07\x08'
for _ in range(test_constants.STREAM_LENGTH))
request_iterator = iter(requests)
multi_callable = _stream_stream_multi_callable(self._channel)
with self._control.pause():
response_iterator = multi_callable(
request_iterator,
metadata=(('test', 'CancelledStreamRequestStreamResponse'),))
response_iterator.cancel()
with self.assertRaises(grpc.RpcError):
next(response_iterator)
self.assertIsNotNone(response_iterator.initial_metadata())
self.assertIs(grpc.StatusCode.CANCELLED, response_iterator.code())
self.assertIsNotNone(response_iterator.details())
self.assertIsNotNone(response_iterator.trailing_metadata())
def testExpiredUnaryRequestBlockingUnaryResponse(self):
request = b'\x07\x17'
multi_callable = _unary_unary_multi_callable(self._channel)
with self._control.pause():
with self.assertRaises(grpc.RpcError) as exception_context:
multi_callable.with_call(
request,
timeout=test_constants.SHORT_TIMEOUT,
metadata=(
('test', 'ExpiredUnaryRequestBlockingUnaryResponse'),))
self.assertIsInstance(exception_context.exception, grpc.Call)
self.assertIsNotNone(exception_context.exception.initial_metadata())
self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED,
exception_context.exception.code())
self.assertIsNotNone(exception_context.exception.details())
self.assertIsNotNone(exception_context.exception.trailing_metadata())
def testExpiredUnaryRequestFutureUnaryResponse(self):
request = b'\x07\x17'
callback = _Callback()
multi_callable = _unary_unary_multi_callable(self._channel)
with self._control.pause():
response_future = multi_callable.future(
request,
timeout=test_constants.SHORT_TIMEOUT,
metadata=(('test', 'ExpiredUnaryRequestFutureUnaryResponse'),))
response_future.add_done_callback(callback)
value_passed_to_callback = callback.value()
self.assertIs(response_future, value_passed_to_callback)
self.assertIsNotNone(response_future.initial_metadata())
self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, response_future.code())
self.assertIsNotNone(response_future.details())
self.assertIsNotNone(response_future.trailing_metadata())
with self.assertRaises(grpc.RpcError) as exception_context:
response_future.result()
self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED,
exception_context.exception.code())
self.assertIsInstance(response_future.exception(), grpc.RpcError)
self.assertIsNotNone(response_future.traceback())
self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED,
response_future.exception().code())
def testExpiredUnaryRequestStreamResponse(self):
request = b'\x07\x19'
multi_callable = _unary_stream_multi_callable(self._channel)
with self._control.pause():
with self.assertRaises(grpc.RpcError) as exception_context:
response_iterator = multi_callable(
request,
timeout=test_constants.SHORT_TIMEOUT,
metadata=(('test', 'ExpiredUnaryRequestStreamResponse'),))
next(response_iterator)
self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED,
exception_context.exception.code())
self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED,
response_iterator.code())
def testExpiredStreamRequestBlockingUnaryResponse(self):
requests = tuple(b'\x07\x08'
for _ in range(test_constants.STREAM_LENGTH))
request_iterator = iter(requests)
multi_callable = _stream_unary_multi_callable(self._channel)
with self._control.pause():
with self.assertRaises(grpc.RpcError) as exception_context:
multi_callable(
request_iterator,
timeout=test_constants.SHORT_TIMEOUT,
metadata=(
('test', 'ExpiredStreamRequestBlockingUnaryResponse'),))
self.assertIsInstance(exception_context.exception, grpc.RpcError)
self.assertIsInstance(exception_context.exception, grpc.Call)
self.assertIsNotNone(exception_context.exception.initial_metadata())
self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED,
exception_context.exception.code())
self.assertIsNotNone(exception_context.exception.details())
self.assertIsNotNone(exception_context.exception.trailing_metadata())
def testExpiredStreamRequestFutureUnaryResponse(self):
requests = tuple(b'\x07\x18'
for _ in range(test_constants.STREAM_LENGTH))
request_iterator = iter(requests)
callback = _Callback()
multi_callable = _stream_unary_multi_callable(self._channel)
with self._control.pause():
response_future = multi_callable.future(
request_iterator,
timeout=test_constants.SHORT_TIMEOUT,
metadata=(('test', 'ExpiredStreamRequestFutureUnaryResponse'),))
with self.assertRaises(grpc.FutureTimeoutError):
response_future.result(timeout=test_constants.SHORT_TIMEOUT /
2.0)
response_future.add_done_callback(callback)
value_passed_to_callback = callback.value()
with self.assertRaises(grpc.RpcError) as exception_context:
response_future.result()
self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, response_future.code())
self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED,
exception_context.exception.code())
self.assertIsInstance(response_future.exception(), grpc.RpcError)
self.assertIsNotNone(response_future.traceback())
self.assertIs(response_future, value_passed_to_callback)
self.assertIsNotNone(response_future.initial_metadata())
self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, response_future.code())
self.assertIsNotNone(response_future.details())
self.assertIsNotNone(response_future.trailing_metadata())
def testExpiredStreamRequestStreamResponse(self):
requests = tuple(b'\x67\x18'
for _ in range(test_constants.STREAM_LENGTH))
request_iterator = iter(requests)
multi_callable = _stream_stream_multi_callable(self._channel)
with self._control.pause():
with self.assertRaises(grpc.RpcError) as exception_context:
response_iterator = multi_callable(
request_iterator,
timeout=test_constants.SHORT_TIMEOUT,
metadata=(('test', 'ExpiredStreamRequestStreamResponse'),))
next(response_iterator)
self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED,
exception_context.exception.code())
self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED,
response_iterator.code())
def testFailedUnaryRequestBlockingUnaryResponse(self):
request = b'\x37\x17'
multi_callable = _unary_unary_multi_callable(self._channel)
with self._control.fail():
with self.assertRaises(grpc.RpcError) as exception_context:
multi_callable.with_call(
request,
metadata=(
('test', 'FailedUnaryRequestBlockingUnaryResponse'),))
self.assertIs(grpc.StatusCode.UNKNOWN,
exception_context.exception.code())
def testFailedUnaryRequestFutureUnaryResponse(self):
request = b'\x37\x17'
callback = _Callback()
multi_callable = _unary_unary_multi_callable(self._channel)
with self._control.fail():
response_future = multi_callable.future(
request,
metadata=(('test', 'FailedUnaryRequestFutureUnaryResponse'),))
response_future.add_done_callback(callback)
value_passed_to_callback = callback.value()
self.assertIsInstance(response_future, grpc.Future)
self.assertIsInstance(response_future, grpc.Call)
with self.assertRaises(grpc.RpcError) as exception_context:
response_future.result()
self.assertIs(grpc.StatusCode.UNKNOWN,
exception_context.exception.code())
self.assertIsInstance(response_future.exception(), grpc.RpcError)
self.assertIsNotNone(response_future.traceback())
self.assertIs(grpc.StatusCode.UNKNOWN,
response_future.exception().code())
self.assertIs(response_future, value_passed_to_callback)
def testFailedUnaryRequestStreamResponse(self):
request = b'\x37\x17'
multi_callable = _unary_stream_multi_callable(self._channel)
with self.assertRaises(grpc.RpcError) as exception_context:
with self._control.fail():
response_iterator = multi_callable(
request,
metadata=(('test', 'FailedUnaryRequestStreamResponse'),))
next(response_iterator)
self.assertIs(grpc.StatusCode.UNKNOWN,
exception_context.exception.code())
def testFailedStreamRequestBlockingUnaryResponse(self):
requests = tuple(b'\x47\x58'
for _ in range(test_constants.STREAM_LENGTH))
request_iterator = iter(requests)
multi_callable = _stream_unary_multi_callable(self._channel)
with self._control.fail():
with self.assertRaises(grpc.RpcError) as exception_context:
multi_callable(
request_iterator,
metadata=(
('test', 'FailedStreamRequestBlockingUnaryResponse'),))
self.assertIs(grpc.StatusCode.UNKNOWN,
exception_context.exception.code())
def testFailedStreamRequestFutureUnaryResponse(self):
requests = tuple(b'\x07\x18'
for _ in range(test_constants.STREAM_LENGTH))
request_iterator = iter(requests)
callback = _Callback()
multi_callable = _stream_unary_multi_callable(self._channel)
with self._control.fail():
response_future = multi_callable.future(
request_iterator,
metadata=(('test', 'FailedStreamRequestFutureUnaryResponse'),))
response_future.add_done_callback(callback)
value_passed_to_callback = callback.value()
with self.assertRaises(grpc.RpcError) as exception_context:
response_future.result()
self.assertIs(grpc.StatusCode.UNKNOWN, response_future.code())
self.assertIs(grpc.StatusCode.UNKNOWN,
exception_context.exception.code())
self.assertIsInstance(response_future.exception(), grpc.RpcError)
self.assertIsNotNone(response_future.traceback())
self.assertIs(response_future, value_passed_to_callback)
def testFailedStreamRequestStreamResponse(self):
requests = tuple(b'\x67\x88'
for _ in range(test_constants.STREAM_LENGTH))
request_iterator = iter(requests)
multi_callable = _stream_stream_multi_callable(self._channel)
with self._control.fail():
with self.assertRaises(grpc.RpcError) as exception_context:
response_iterator = multi_callable(
request_iterator,
metadata=(('test', 'FailedStreamRequestStreamResponse'),))
tuple(response_iterator)
self.assertIs(grpc.StatusCode.UNKNOWN,
exception_context.exception.code())
self.assertIs(grpc.StatusCode.UNKNOWN, response_iterator.code())
def testIgnoredUnaryRequestFutureUnaryResponse(self):
request = b'\x37\x17'
multi_callable = _unary_unary_multi_callable(self._channel)
multi_callable.future(
request,
metadata=(('test', 'IgnoredUnaryRequestFutureUnaryResponse'),))
def testIgnoredUnaryRequestStreamResponse(self):
request = b'\x37\x17'
multi_callable = _unary_stream_multi_callable(self._channel)
multi_callable(
request, metadata=(('test', 'IgnoredUnaryRequestStreamResponse'),))
def testIgnoredStreamRequestFutureUnaryResponse(self):
requests = tuple(b'\x07\x18'
for _ in range(test_constants.STREAM_LENGTH))
request_iterator = iter(requests)
multi_callable = _stream_unary_multi_callable(self._channel)
multi_callable.future(
request_iterator,
metadata=(('test', 'IgnoredStreamRequestFutureUnaryResponse'),))
def testIgnoredStreamRequestStreamResponse(self):
requests = tuple(b'\x67\x88'
for _ in range(test_constants.STREAM_LENGTH))
request_iterator = iter(requests)
multi_callable = _stream_stream_multi_callable(self._channel)
multi_callable(
request_iterator,
metadata=(('test', 'IgnoredStreamRequestStreamResponse'),))
if __name__ == '__main__':
unittest.main(verbosity=2)
|
apache-2.0
|
[
3,
1898,
7800,
30700,
11462,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
624,
774,
402,
11785,
83,
6326,
6169,
30700,
2018,
1159,
4223,
13,
1897,
3261,
1041,
199,
199,
646,
7975,
199,
646,
5796,
199,
646,
2882,
199,
504,
23002,
492,
27471,
199,
199,
646,
19753,
199,
504,
19753,
14,
4857,
14,
4214,
425,
492,
2050,
63,
2293,
199,
199,
504,
2295,
14,
3248,
14,
4857,
14,
2330,
492,
511,
63,
5559,
199,
504,
2295,
14,
3248,
14,
4857,
14,
2330,
492,
511,
63,
2785,
199,
199,
63,
19637,
11025,
63,
6780,
275,
2400,
23888,
26,
23888,
627,
499,
199,
63,
4448,
540,
4938,
11025,
63,
6780,
275,
2400,
23888,
26,
23888,
59,
552,
8,
991,
396,
5985,
9,
5001,
499,
2938,
199,
63,
19637,
11025,
63,
12801,
275,
2400,
23888,
26,
23888,
627,
650,
199,
63,
4448,
540,
4938,
11025,
63,
12801,
275,
2400,
23888,
26,
23888,
1491,
552,
8,
991,
396,
5985,
9,
5001,
650,
61,
199,
199,
63,
31401,
63,
31401,
275,
1994,
396,
15,
22401,
22401,
7,
199,
63,
31401,
63,
9484,
275,
1994,
396,
15,
22401,
3296,
7,
199,
63,
9484,
63,
31401,
275,
1994,
396,
15,
3296,
22401,
7,
199,
63,
9484,
63,
9484,
275,
1994,
396,
15,
3296,
3296,
7,
421,
199,
533,
485,
2806,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
5394,
275,
5796,
14,
9558,
342,
267,
291,
423,
585,
275,
488,
267,
291,
423,
3527,
275,
756,
339,
347,
636,
1250,
721,
277,
12,
574,
304,
267,
543,
291,
423,
5394,
26,
288,
291,
423,
585,
275,
574,
288,
291,
423,
3527,
275,
715,
288,
291,
423,
5394,
14,
6814,
63,
452,
342,
339,
347,
574,
8,
277,
304,
267,
543,
291,
423,
5394,
26,
288,
1830,
440,
291,
423,
3527,
26,
355,
291,
423,
5394,
14,
2573,
342,
288,
372,
291,
423,
585,
421,
199,
533,
485,
2461,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
3304,
304,
267,
291,
423,
2785,
275,
3304,
339,
347,
2429,
63,
13124,
63,
13124,
8,
277,
12,
1056,
12,
8926,
30150,
63,
1100,
304,
267,
291,
423,
2785,
14,
2785,
342,
267,
340,
8926,
30150,
63,
1100,
365,
440,
488,
26,
288,
8926,
30150,
63,
1100,
14,
409,
63,
15910,
63,
2343,
17861,
396,
498,
297,
283,
396,
585,
5529,
430,
288,
327,
3254,
8,
2859,
921,
5031,
14,
957,
15,
15391,
15,
15391,
15,
10115,
15,
1349,
2658,
304,
511,
314,
1338,
288,
327,
2138,
701,
3520,
3102,
7830,
2419,
1454,
298,
30697,
2,
5343,
626,
288,
327,
314,
372,
2410,
9445,
2757,
2797,
14,
288,
8926,
30150,
63,
1100,
14,
374,
63,
2682,
342,
288,
8926,
30150,
63,
1100,
14,
521,
63,
11266,
342,
267,
372,
1056,
339,
347,
2429,
63,
13124,
63,
1745,
8,
277,
12,
1056,
12,
8926,
30150,
63,
1100,
304,
267,
367,
485,
315,
1425,
8,
396,
63,
5559,
14,
9484,
63,
9127,
304,
288,
291,
423,
2785,
14,
2785,
342,
288,
1995,
1056,
267,
291,
423,
2785,
14,
2785,
342,
267,
340,
8926,
30150,
63,
1100,
365,
440,
488,
26,
288,
8926,
30150,
63,
1100,
14,
409,
63,
15910,
63,
2343,
17861,
396,
498,
297,
283,
396,
585,
5529,
430,
339,
347,
2429,
63,
1745,
63,
13124,
8,
277,
12,
1056,
63,
5778,
12,
8926,
30150,
63,
1100,
304,
267,
340,
8926,
30150,
63,
1100,
365,
440,
488,
26,
288,
8926,
30150,
63,
1100,
14,
30158,
63,
2343,
342,
267,
291,
423,
2785,
14,
2785,
342,
267,
1177,
63,
5527,
275,
942,
267,
367,
1056,
315,
1056,
63,
5778,
26,
288,
291,
423,
2785,
14,
2785,
342,
288,
1177,
63,
5527,
14,
740,
8,
1069,
9,
267,
291,
423,
2785,
14,
2785,
342,
267,
340,
8926,
30150,
63,
1100,
365,
440,
488,
26,
288,
8926,
30150,
63,
1100,
14,
409,
63,
15910,
63,
2343,
17861,
396,
498,
297,
283,
396,
585,
5529,
430,
267,
372,
330,
17067,
904,
8,
1310,
63,
5527,
9,
339,
347,
2429,
63,
1745,
63,
1745,
8,
277,
12,
1056,
63,
5778,
12,
8926,
30150,
63,
1100,
304,
267,
291,
423,
2785,
14,
2785,
342,
267,
340,
8926,
30150,
63,
1100,
365,
440,
488,
26,
288,
8926,
30150,
63,
1100,
14,
409,
63,
15910,
63,
2343,
17861,
396,
498,
297,
283,
396,
585,
5529,
430,
267,
367,
1056,
315,
1056,
63,
5778,
26,
288,
291,
423,
2785,
14,
2785,
342,
288,
1995,
1056,
267,
291,
423,
2785,
14,
2785,
342,
421,
199,
533,
485,
3767,
2461,
8,
15391,
14,
15569,
3767,
2461,
304,
339,
347,
636,
826,
721,
277,
12,
1056,
63,
12076,
12,
1177,
63,
12076,
12,
326,
1056,
63,
27470,
12,
1177,
63,
8349,
12,
21603,
63,
13124,
12,
326,
21603,
63,
1745,
12,
2547,
63,
13124,
12,
2547,
63,
1745,
304,
267,
291,
14,
1069,
63,
12076,
275,
1056,
63,
12076,
267,
291,
14,
1310,
63,
12076,
275,
1177,
63,
12076,
267,
291,
14,
1069,
63,
27470,
275,
1056,
63,
27470,
267,
291,
14,
1310,
63,
8349,
275,
1177,
63,
8349,
267,
291,
14,
13124,
63,
13124,
275,
21603,
63,
13124,
267,
291,
14,
13124,
63,
1745,
275,
21603,
63,
1745,
267,
291,
14,
1745,
63,
13124,
275,
2547,
63,
13124,
267,
291,
14,
1745,
63,
1745,
275,
2547,
63,
1745,
421,
199,
533,
485,
9417,
2461,
8,
15391,
14,
9417,
15569,
2461,
304,
339,
347,
636,
826,
721,
277,
12,
3016,
304,
267,
291,
423,
2232,
275
] |
[
1898,
7800,
30700,
11462,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
624,
774,
402,
11785,
83,
6326,
6169,
30700,
2018,
1159,
4223,
13,
1897,
3261,
1041,
199,
199,
646,
7975,
199,
646,
5796,
199,
646,
2882,
199,
504,
23002,
492,
27471,
199,
199,
646,
19753,
199,
504,
19753,
14,
4857,
14,
4214,
425,
492,
2050,
63,
2293,
199,
199,
504,
2295,
14,
3248,
14,
4857,
14,
2330,
492,
511,
63,
5559,
199,
504,
2295,
14,
3248,
14,
4857,
14,
2330,
492,
511,
63,
2785,
199,
199,
63,
19637,
11025,
63,
6780,
275,
2400,
23888,
26,
23888,
627,
499,
199,
63,
4448,
540,
4938,
11025,
63,
6780,
275,
2400,
23888,
26,
23888,
59,
552,
8,
991,
396,
5985,
9,
5001,
499,
2938,
199,
63,
19637,
11025,
63,
12801,
275,
2400,
23888,
26,
23888,
627,
650,
199,
63,
4448,
540,
4938,
11025,
63,
12801,
275,
2400,
23888,
26,
23888,
1491,
552,
8,
991,
396,
5985,
9,
5001,
650,
61,
199,
199,
63,
31401,
63,
31401,
275,
1994,
396,
15,
22401,
22401,
7,
199,
63,
31401,
63,
9484,
275,
1994,
396,
15,
22401,
3296,
7,
199,
63,
9484,
63,
31401,
275,
1994,
396,
15,
3296,
22401,
7,
199,
63,
9484,
63,
9484,
275,
1994,
396,
15,
3296,
3296,
7,
421,
199,
533,
485,
2806,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
5394,
275,
5796,
14,
9558,
342,
267,
291,
423,
585,
275,
488,
267,
291,
423,
3527,
275,
756,
339,
347,
636,
1250,
721,
277,
12,
574,
304,
267,
543,
291,
423,
5394,
26,
288,
291,
423,
585,
275,
574,
288,
291,
423,
3527,
275,
715,
288,
291,
423,
5394,
14,
6814,
63,
452,
342,
339,
347,
574,
8,
277,
304,
267,
543,
291,
423,
5394,
26,
288,
1830,
440,
291,
423,
3527,
26,
355,
291,
423,
5394,
14,
2573,
342,
288,
372,
291,
423,
585,
421,
199,
533,
485,
2461,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
3304,
304,
267,
291,
423,
2785,
275,
3304,
339,
347,
2429,
63,
13124,
63,
13124,
8,
277,
12,
1056,
12,
8926,
30150,
63,
1100,
304,
267,
291,
423,
2785,
14,
2785,
342,
267,
340,
8926,
30150,
63,
1100,
365,
440,
488,
26,
288,
8926,
30150,
63,
1100,
14,
409,
63,
15910,
63,
2343,
17861,
396,
498,
297,
283,
396,
585,
5529,
430,
288,
327,
3254,
8,
2859,
921,
5031,
14,
957,
15,
15391,
15,
15391,
15,
10115,
15,
1349,
2658,
304,
511,
314,
1338,
288,
327,
2138,
701,
3520,
3102,
7830,
2419,
1454,
298,
30697,
2,
5343,
626,
288,
327,
314,
372,
2410,
9445,
2757,
2797,
14,
288,
8926,
30150,
63,
1100,
14,
374,
63,
2682,
342,
288,
8926,
30150,
63,
1100,
14,
521,
63,
11266,
342,
267,
372,
1056,
339,
347,
2429,
63,
13124,
63,
1745,
8,
277,
12,
1056,
12,
8926,
30150,
63,
1100,
304,
267,
367,
485,
315,
1425,
8,
396,
63,
5559,
14,
9484,
63,
9127,
304,
288,
291,
423,
2785,
14,
2785,
342,
288,
1995,
1056,
267,
291,
423,
2785,
14,
2785,
342,
267,
340,
8926,
30150,
63,
1100,
365,
440,
488,
26,
288,
8926,
30150,
63,
1100,
14,
409,
63,
15910,
63,
2343,
17861,
396,
498,
297,
283,
396,
585,
5529,
430,
339,
347,
2429,
63,
1745,
63,
13124,
8,
277,
12,
1056,
63,
5778,
12,
8926,
30150,
63,
1100,
304,
267,
340,
8926,
30150,
63,
1100,
365,
440,
488,
26,
288,
8926,
30150,
63,
1100,
14,
30158,
63,
2343,
342,
267,
291,
423,
2785,
14,
2785,
342,
267,
1177,
63,
5527,
275,
942,
267,
367,
1056,
315,
1056,
63,
5778,
26,
288,
291,
423,
2785,
14,
2785,
342,
288,
1177,
63,
5527,
14,
740,
8,
1069,
9,
267,
291,
423,
2785,
14,
2785,
342,
267,
340,
8926,
30150,
63,
1100,
365,
440,
488,
26,
288,
8926,
30150,
63,
1100,
14,
409,
63,
15910,
63,
2343,
17861,
396,
498,
297,
283,
396,
585,
5529,
430,
267,
372,
330,
17067,
904,
8,
1310,
63,
5527,
9,
339,
347,
2429,
63,
1745,
63,
1745,
8,
277,
12,
1056,
63,
5778,
12,
8926,
30150,
63,
1100,
304,
267,
291,
423,
2785,
14,
2785,
342,
267,
340,
8926,
30150,
63,
1100,
365,
440,
488,
26,
288,
8926,
30150,
63,
1100,
14,
409,
63,
15910,
63,
2343,
17861,
396,
498,
297,
283,
396,
585,
5529,
430,
267,
367,
1056,
315,
1056,
63,
5778,
26,
288,
291,
423,
2785,
14,
2785,
342,
288,
1995,
1056,
267,
291,
423,
2785,
14,
2785,
342,
421,
199,
533,
485,
3767,
2461,
8,
15391,
14,
15569,
3767,
2461,
304,
339,
347,
636,
826,
721,
277,
12,
1056,
63,
12076,
12,
1177,
63,
12076,
12,
326,
1056,
63,
27470,
12,
1177,
63,
8349,
12,
21603,
63,
13124,
12,
326,
21603,
63,
1745,
12,
2547,
63,
13124,
12,
2547,
63,
1745,
304,
267,
291,
14,
1069,
63,
12076,
275,
1056,
63,
12076,
267,
291,
14,
1310,
63,
12076,
275,
1177,
63,
12076,
267,
291,
14,
1069,
63,
27470,
275,
1056,
63,
27470,
267,
291,
14,
1310,
63,
8349,
275,
1177,
63,
8349,
267,
291,
14,
13124,
63,
13124,
275,
21603,
63,
13124,
267,
291,
14,
13124,
63,
1745,
275,
21603,
63,
1745,
267,
291,
14,
1745,
63,
13124,
275,
2547,
63,
13124,
267,
291,
14,
1745,
63,
1745,
275,
2547,
63,
1745,
421,
199,
533,
485,
9417,
2461,
8,
15391,
14,
9417,
15569,
2461,
304,
339,
347,
636,
826,
721,
277,
12,
3016,
304,
267,
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,
1,
1,
1,
1,
1,
1
] |
citrix-openstack-build/neutron
|
neutron/tests/base.py
|
3
|
3108
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2010-2011 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Base Test Case for all Unit Tests"""
import logging
import os
import fixtures
from oslo.config import cfg
import stubout
import testtools
from neutron.common import exceptions
CONF = cfg.CONF
TRUE_STRING = ['True', '1']
LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s"
class BaseTestCase(testtools.TestCase):
def setUp(self):
super(BaseTestCase, self).setUp()
if os.environ.get('OS_DEBUG') in TRUE_STRING:
_level = logging.DEBUG
else:
_level = logging.INFO
capture_logs = os.environ.get('OS_LOG_CAPTURE') in TRUE_STRING
if not capture_logs:
logging.basicConfig(format=LOG_FORMAT, level=_level)
self.log_fixture = self.useFixture(
fixtures.FakeLogger(
format=LOG_FORMAT,
level=_level,
nuke_handlers=capture_logs,
))
test_timeout = int(os.environ.get('OS_TEST_TIMEOUT', 0))
if test_timeout == -1:
test_timeout = 0
if test_timeout > 0:
self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
# If someone does use tempfile directly, ensure that it's cleaned up
self.useFixture(fixtures.NestedTempfile())
self.useFixture(fixtures.TempHomeDir())
self.addCleanup(CONF.reset)
if os.environ.get('OS_STDOUT_CAPTURE') in TRUE_STRING:
stdout = self.useFixture(fixtures.StringStream('stdout')).stream
self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
if os.environ.get('OS_STDERR_CAPTURE') in TRUE_STRING:
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
self.stubs = stubout.StubOutForTesting()
self.stubs.Set(exceptions, '_FATAL_EXCEPTION_FORMAT_ERRORS', True)
def config(self, **kw):
"""Override some configuration values.
The keyword arguments are the names of configuration options to
override and their values.
If a group argument is supplied, the overrides are applied to
the specified configuration option group.
All overrides are automatically cleared at the end of the current
test by the fixtures cleanup process.
"""
group = kw.pop('group', None)
for k, v in kw.iteritems():
CONF.set_override(k, v, group)
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
7129,
13,
8128,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
624,
1563,
1379,
12425,
367,
1006,
12008,
6496,
624,
199,
199,
646,
2050,
199,
646,
747,
199,
199,
646,
15188,
199,
504,
11258,
14,
888,
492,
4810,
199,
646,
10098,
548,
199,
646,
30741,
199,
199,
504,
8224,
14,
2330,
492,
4967,
421,
199,
3103,
275,
4810,
14,
3103,
199,
15064,
63,
5353,
275,
788,
549,
297,
283,
17,
418,
199,
4947,
63,
4807,
275,
11792,
18331,
9,
83,
2818,
20056,
9,
24,
83,
359,
2840,
354,
9,
83,
61,
2818,
1188,
9,
83,
2,
421,
199,
533,
3523,
1746,
8,
396,
2537,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
20760,
12,
291,
680,
5996,
342,
398,
340,
747,
14,
2314,
14,
362,
360,
3100,
63,
5287,
358,
315,
9074,
4187,
63,
5353,
26,
288,
485,
1896,
275,
2050,
14,
5287,
267,
587,
26,
288,
485,
1896,
275,
2050,
14,
4531,
267,
12296,
63,
7270,
275,
747,
14,
2314,
14,
362,
360,
3100,
63,
4947,
63,
28342,
3942,
358,
315,
9074,
4187,
63,
5353,
267,
340,
440,
12296,
63,
7270,
26,
288,
2050,
14,
19602,
8,
908,
29,
4947,
63,
4807,
12,
2166,
3699,
1896,
9,
267,
291,
14,
793,
63,
5997,
275,
291,
14,
31015,
8,
288,
15188,
14,
8249,
4455,
8,
355,
1475,
29,
4947,
63,
4807,
12,
355,
2166,
3699,
1896,
12,
355,
15699,
415,
63,
5586,
29,
12685,
63,
7270,
12,
288,
5082,
398,
511,
63,
2593,
275,
1109,
8,
736,
14,
2314,
14,
362,
360,
3100,
63,
2864,
63,
8899,
297,
378,
430,
267,
340,
511,
63,
2593,
508,
446,
17,
26,
288,
511,
63,
2593,
275,
378,
267,
340,
511,
63,
2593,
690,
378,
26,
288,
291,
14,
31015,
8,
8769,
14,
6372,
8,
396,
63,
2593,
12,
486,
484,
274,
29,
549,
430,
398,
327,
982,
17122,
1630,
675,
5549,
5370,
12,
4868,
626,
652,
1159,
12364,
1536,
267,
291,
14,
31015,
8,
8769,
14,
13029,
6530,
493,
1012,
267,
291,
14,
31015,
8,
8769,
14,
6530,
12054,
3567,
1012,
398,
291,
14,
12808,
8,
3103,
14,
3958,
9,
398,
340,
747,
14,
2314,
14,
362,
360,
3100,
63,
13850,
63,
28342,
3942,
358,
315,
9074,
4187,
63,
5353,
26,
288,
3839,
275,
291,
14,
31015,
8,
8769,
14,
1558,
3296,
360,
2703,
11103,
1745,
288,
291,
14,
31015,
8,
8769,
14,
6671,
498,
11173,
360,
1274,
14,
2703,
297,
3839,
430,
267,
340,
747,
14,
2314,
14,
362,
360,
3100,
63,
18472,
2666,
63,
28342,
3942,
358,
315,
9074,
4187,
63,
5353,
26,
288,
4635,
275,
291,
14,
31015,
8,
8769,
14,
1558,
3296,
360,
3083,
11103,
1745,
288,
291,
14,
31015,
8,
8769,
14,
6671,
498,
11173,
360,
1274,
14,
3083,
297,
4635,
430,
267,
291,
14,
8957,
275,
10098,
548,
14,
11975,
1858,
9029,
342,
267,
291,
14,
8957,
14,
1084,
8,
3924,
12,
2513,
29086,
63,
15375,
63,
4807,
63,
21477,
297,
715,
9,
339,
347,
1101,
8,
277,
12,
1011,
829,
304,
267,
408,
11954,
2005,
2897,
1338,
14,
398,
710,
4252,
2368,
787,
314,
1561,
402,
2897,
1511,
370,
267,
4278,
436,
3932,
1338,
14,
398,
982,
282,
1572,
1423,
365,
6841,
12,
314,
10580,
787,
6781,
370,
267,
314,
2013,
2897,
945,
1572,
14,
398,
2900,
10580,
787,
5847,
20518,
737,
314,
1284,
402,
314,
1453,
267,
511,
701,
314,
15188,
9058,
2112,
14,
267,
408,
267,
1572,
275,
4775,
14,
1935,
360,
923,
297,
488,
9,
267,
367,
1022,
12,
373,
315,
4775,
14,
4611,
837,
288,
6392,
14,
409,
63,
4415,
8,
75,
12,
373,
12,
1572,
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
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
7129,
13,
8128,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
624,
1563,
1379,
12425,
367,
1006,
12008,
6496,
624,
199,
199,
646,
2050,
199,
646,
747,
199,
199,
646,
15188,
199,
504,
11258,
14,
888,
492,
4810,
199,
646,
10098,
548,
199,
646,
30741,
199,
199,
504,
8224,
14,
2330,
492,
4967,
421,
199,
3103,
275,
4810,
14,
3103,
199,
15064,
63,
5353,
275,
788,
549,
297,
283,
17,
418,
199,
4947,
63,
4807,
275,
11792,
18331,
9,
83,
2818,
20056,
9,
24,
83,
359,
2840,
354,
9,
83,
61,
2818,
1188,
9,
83,
2,
421,
199,
533,
3523,
1746,
8,
396,
2537,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
20760,
12,
291,
680,
5996,
342,
398,
340,
747,
14,
2314,
14,
362,
360,
3100,
63,
5287,
358,
315,
9074,
4187,
63,
5353,
26,
288,
485,
1896,
275,
2050,
14,
5287,
267,
587,
26,
288,
485,
1896,
275,
2050,
14,
4531,
267,
12296,
63,
7270,
275,
747,
14,
2314,
14,
362,
360,
3100,
63,
4947,
63,
28342,
3942,
358,
315,
9074,
4187,
63,
5353,
267,
340,
440,
12296,
63,
7270,
26,
288,
2050,
14,
19602,
8,
908,
29,
4947,
63,
4807,
12,
2166,
3699,
1896,
9,
267,
291,
14,
793,
63,
5997,
275,
291,
14,
31015,
8,
288,
15188,
14,
8249,
4455,
8,
355,
1475,
29,
4947,
63,
4807,
12,
355,
2166,
3699,
1896,
12,
355,
15699,
415,
63,
5586,
29,
12685,
63,
7270,
12,
288,
5082,
398,
511,
63,
2593,
275,
1109,
8,
736,
14,
2314,
14,
362,
360,
3100,
63,
2864,
63,
8899,
297,
378,
430,
267,
340,
511,
63,
2593,
508,
446,
17,
26,
288,
511,
63,
2593,
275,
378,
267,
340,
511,
63,
2593,
690,
378,
26,
288,
291,
14,
31015,
8,
8769,
14,
6372,
8,
396,
63,
2593,
12,
486,
484,
274,
29,
549,
430,
398,
327,
982,
17122,
1630,
675,
5549,
5370,
12,
4868,
626,
652,
1159,
12364,
1536,
267,
291,
14,
31015,
8,
8769,
14,
13029,
6530,
493,
1012,
267,
291,
14,
31015,
8,
8769,
14,
6530,
12054,
3567,
1012,
398,
291,
14,
12808,
8,
3103,
14,
3958,
9,
398,
340,
747,
14,
2314,
14,
362,
360,
3100,
63,
13850,
63,
28342,
3942,
358,
315,
9074,
4187,
63,
5353,
26,
288,
3839,
275,
291,
14,
31015,
8,
8769,
14,
1558,
3296,
360,
2703,
11103,
1745,
288,
291,
14,
31015,
8,
8769,
14,
6671,
498,
11173,
360,
1274,
14,
2703,
297,
3839,
430,
267,
340,
747,
14,
2314,
14,
362,
360,
3100,
63,
18472,
2666,
63,
28342,
3942,
358,
315,
9074,
4187,
63,
5353,
26,
288,
4635,
275,
291,
14,
31015,
8,
8769,
14,
1558,
3296,
360,
3083,
11103,
1745,
288,
291,
14,
31015,
8,
8769,
14,
6671,
498,
11173,
360,
1274,
14,
3083,
297,
4635,
430,
267,
291,
14,
8957,
275,
10098,
548,
14,
11975,
1858,
9029,
342,
267,
291,
14,
8957,
14,
1084,
8,
3924,
12,
2513,
29086,
63,
15375,
63,
4807,
63,
21477,
297,
715,
9,
339,
347,
1101,
8,
277,
12,
1011,
829,
304,
267,
408,
11954,
2005,
2897,
1338,
14,
398,
710,
4252,
2368,
787,
314,
1561,
402,
2897,
1511,
370,
267,
4278,
436,
3932,
1338,
14,
398,
982,
282,
1572,
1423,
365,
6841,
12,
314,
10580,
787,
6781,
370,
267,
314,
2013,
2897,
945,
1572,
14,
398,
2900,
10580,
787,
5847,
20518,
737,
314,
1284,
402,
314,
1453,
267,
511,
701,
314,
15188,
9058,
2112,
14,
267,
408,
267,
1572,
275,
4775,
14,
1935,
360,
923,
297,
488,
9,
267,
367,
1022,
12,
373,
315,
4775,
14,
4611,
837,
288,
6392,
14,
409,
63,
4415,
8,
75,
12,
373,
12,
1572,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
radicalbit/ambari
|
ambari-server/src/main/resources/common-services/OOZIE/4.2.0.3.0/package/scripts/check_oozie_server_status.py
|
8
|
1418
|
"""
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 ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl
from ambari_commons import OSConst
@OsFamilyFuncImpl(os_family=OSConst.WINSRV_FAMILY)
def check_oozie_server_status():
import status_params
from resource_management.libraries.functions.windows_service_utils import check_windows_service_status
check_windows_service_status(status_params.oozie_server_win_service_name)
@OsFamilyFuncImpl(os_family=OsFamilyImpl.DEFAULT)
def check_oozie_server_status():
import status_params
from resource_management.libraries.functions.check_process_status import check_process_status
check_process_status(status_params.pid_file)
|
apache-2.0
|
[
624,
199,
31661,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
269,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
16832,
543,
642,
1736,
367,
4722,
2556,
199,
1135,
1005,
316,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
475,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
2,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
1045,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
339,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3097,
1298,
1334,
314,
844,
14,
199,
199,
624,
199,
199,
504,
16353,
759,
63,
2330,
83,
14,
736,
63,
6606,
63,
5472,
492,
593,
83,
16345,
7465,
4748,
12,
593,
83,
16345,
4748,
199,
504,
16353,
759,
63,
2330,
83,
492,
4403,
6361,
421,
199,
32,
24351,
16345,
7465,
4748,
8,
736,
63,
6606,
29,
3100,
6361,
14,
7941,
31546,
63,
38,
1156,
1193,
57,
9,
199,
318,
1104,
63,
18811,
63,
1000,
63,
1205,
837,
523,
492,
2004,
63,
1162,
523,
687,
2073,
63,
8110,
14,
10159,
14,
5777,
14,
8258,
63,
1364,
63,
1208,
492,
1104,
63,
8258,
63,
1364,
63,
1205,
819,
1104,
63,
8258,
63,
1364,
63,
1205,
8,
1205,
63,
1162,
14,
18811,
63,
1000,
63,
2676,
63,
1364,
63,
354,
9,
421,
199,
32,
24351,
16345,
7465,
4748,
8,
736,
63,
6606,
29,
24351,
16345,
4748,
14,
3472,
9,
199,
318,
1104,
63,
18811,
63,
1000,
63,
1205,
837,
523,
492,
2004,
63,
1162,
523,
687,
2073,
63,
8110,
14,
10159,
14,
5777,
14,
1074,
63,
1412,
63,
1205,
492,
1104,
63,
1412,
63,
1205,
819,
1104,
63,
1412,
63,
1205,
8,
1205,
63,
1162,
14,
3150,
63,
493,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
31661,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
269,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
16832,
543,
642,
1736,
367,
4722,
2556,
199,
1135,
1005,
316,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
475,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
2,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
1045,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
339,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3097,
1298,
1334,
314,
844,
14,
199,
199,
624,
199,
199,
504,
16353,
759,
63,
2330,
83,
14,
736,
63,
6606,
63,
5472,
492,
593,
83,
16345,
7465,
4748,
12,
593,
83,
16345,
4748,
199,
504,
16353,
759,
63,
2330,
83,
492,
4403,
6361,
421,
199,
32,
24351,
16345,
7465,
4748,
8,
736,
63,
6606,
29,
3100,
6361,
14,
7941,
31546,
63,
38,
1156,
1193,
57,
9,
199,
318,
1104,
63,
18811,
63,
1000,
63,
1205,
837,
523,
492,
2004,
63,
1162,
523,
687,
2073,
63,
8110,
14,
10159,
14,
5777,
14,
8258,
63,
1364,
63,
1208,
492,
1104,
63,
8258,
63,
1364,
63,
1205,
819,
1104,
63,
8258,
63,
1364,
63,
1205,
8,
1205,
63,
1162,
14,
18811,
63,
1000,
63,
2676,
63,
1364,
63,
354,
9,
421,
199,
32,
24351,
16345,
7465,
4748,
8,
736,
63,
6606,
29,
24351,
16345,
4748,
14,
3472,
9,
199,
318,
1104,
63,
18811,
63,
1000,
63,
1205,
837,
523,
492,
2004,
63,
1162,
523,
687,
2073,
63,
8110,
14,
10159,
14,
5777,
14,
1074,
63,
1412,
63,
1205,
492,
1104,
63,
1412,
63,
1205,
819,
1104,
63,
1412,
63,
1205,
8,
1205,
63,
1162,
14,
3150,
63,
493,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
uhlik/render_maxwell
|
support/material_preview_mxi.py
|
2
|
3590
|
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
# -*- coding: utf-8 -*-
# The MIT License (MIT)
#
# Copyright (c) 2015 Jakub Uhlík
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is furnished
# to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
import sys
import traceback
import argparse
import textwrap
import json
import os
import shlex
import subprocess
LOG_FILE_PATH = None
def log(msg, indent=0):
m = "{0}> {1}".format(" " * indent, msg)
print(m)
if(LOG_FILE_PATH is not None):
with open(LOG_FILE_PATH, mode='a', encoding='utf-8', ) as f:
f.write("{}{}".format(m, "\n"))
def main(args):
mp = os.path.join(args.directory, 'render.mxi')
ep = os.path.join(args.directory, 'render.exr')
a = numpy.zeros((1, 1, 3), dtype=numpy.float, )
if(os.path.exists(mp)):
log('reading mxi: {}'.format(mp), 2)
i = CmaxwellMxi()
i.read(mp)
a, _ = i.getRenderBuffer(32)
elif(os.path.exists(ep)):
log('reading exr: {}'.format(ep), 2)
i = CmaxwellMxi()
i.readImage(ep)
i.write(mp)
a, _ = i.getRenderBuffer(32)
else:
log('image not found..', 2)
np = os.path.join(args.directory, "preview.npy")
log('writing numpy: {}'.format(np), 2)
numpy.save(np, a)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=textwrap.dedent('''Make Maxwell Material from serialized data'''), epilog='',
formatter_class=argparse.RawDescriptionHelpFormatter, add_help=True, )
parser.add_argument('pymaxwell_path', type=str, help='path to directory containing pymaxwell')
parser.add_argument('numpy_path', type=str, help='path to directory containing numpy')
parser.add_argument('log_file', type=str, help='path to log file')
parser.add_argument('directory', type=str, help='path to temp directory')
args = parser.parse_args()
PYMAXWELL_PATH = args.pymaxwell_path
NUMPY_PATH = args.numpy_path
try:
from pymaxwell import *
except ImportError:
if(not os.path.exists(PYMAXWELL_PATH)):
raise OSError("pymaxwell for python 3.5 does not exist ({})".format(PYMAXWELL_PATH))
sys.path.insert(0, PYMAXWELL_PATH)
from pymaxwell import *
try:
import numpy
except ImportError:
sys.path.insert(0, NUMPY_PATH)
import numpy
LOG_FILE_PATH = args.log_file
try:
main(args)
except Exception as e:
import traceback
m = traceback.format_exc()
log(m)
sys.exit(1)
sys.exit(0)
|
gpl-2.0
|
[
3381,
7424,
15,
30052,
15,
4718,
14,
4857,
15,
21167,
15,
19,
14,
21,
15,
1393,
15,
1548,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
710,
10697,
844,
334,
13965,
9,
199,
3,
199,
3,
1898,
334,
67,
9,
6900,
1603,
1151,
456,
738,
15544,
13676,
75,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
199,
3,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
3,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
199,
3,
2334,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
646,
984,
199,
646,
5190,
199,
646,
7534,
199,
646,
13390,
199,
646,
2022,
199,
646,
747,
199,
646,
16701,
199,
646,
3873,
421,
199,
4947,
63,
3817,
63,
3243,
275,
488,
421,
199,
318,
943,
8,
1328,
12,
4363,
29,
16,
304,
272,
333,
275,
5310,
16,
93,
30,
469,
17,
5469,
908,
480,
259,
298,
627,
4363,
12,
1499,
9,
272,
870,
8,
77,
9,
272,
340,
8,
4947,
63,
3817,
63,
3243,
365,
440,
488,
304,
267,
543,
1551,
8,
4947,
63,
3817,
63,
3243,
12,
818,
534,
65,
297,
2644,
534,
1624,
13,
24,
297,
776,
465,
289,
26,
288,
289,
14,
952,
20794,
13536,
908,
8,
77,
12,
1867,
78,
2237,
421,
199,
318,
2446,
8,
589,
304,
272,
6118,
275,
747,
14,
515,
14,
904,
8,
589,
14,
3619,
12,
283,
3352,
14,
77,
6865,
358,
272,
5442,
275,
747,
14,
515,
14,
904,
8,
589,
14,
3619,
12,
283,
3352,
14,
476,
82,
358,
272,
282,
275,
2680,
14,
4250,
1332,
17,
12,
413,
12,
650,
395,
2152,
29,
4714,
14,
1609,
12,
776,
272,
340,
8,
736,
14,
515,
14,
2444,
8,
311,
2298,
267,
943,
360,
19332,
333,
6865,
26,
9499,
908,
8,
311,
395,
499,
9,
267,
284,
275,
445,
988,
20501,
45,
6865,
342,
267,
284,
14,
739,
8,
311,
9,
267,
282,
12,
485,
275,
284,
14,
362,
9216,
3299,
8,
708,
9,
272,
916,
8,
736,
14,
515,
14,
2444,
8,
1545,
2298,
267,
943,
360,
19332,
444,
82,
26,
9499,
908,
8,
1545,
395,
499,
9,
267,
284,
275,
445,
988,
20501,
45,
6865,
342,
267,
284,
14,
739,
3491,
8,
1545,
9,
267,
284,
14,
952,
8,
311,
9,
267,
282,
12,
485,
275,
284,
14,
362,
9216,
3299,
8,
708,
9,
272,
587,
26,
267,
943,
360,
1569,
440,
1911,
703,
297,
499,
9,
2286,
980,
275,
747,
14,
515,
14,
904,
8,
589,
14,
3619,
12,
298,
7780,
14,
20245,
531,
272,
943,
360,
14827,
2680,
26,
9499,
908,
8,
1590,
395,
499,
9,
272,
2680,
14,
2117,
8,
1590,
12,
282,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1798,
275,
7534,
14,
10730,
8,
1802,
29,
505,
3823,
14,
14674,
10505,
5483,
8228,
20501,
26570,
687,
6380,
666,
891,
659,
29850,
4581,
3660,
9698,
63,
533,
29,
18978,
14,
7963,
5831,
22779,
12,
1050,
63,
3437,
29,
549,
12,
776,
272,
1798,
14,
525,
63,
2094,
360,
647,
988,
20501,
63,
515,
297,
730,
29,
495,
12,
1720,
534,
515,
370,
2082,
3035,
1134,
988,
20501,
358,
272,
1798,
14,
525,
63,
2094,
360,
4714,
63,
515,
297,
730,
29,
495,
12,
1720,
534,
515,
370,
2082,
3035,
2680,
358,
272,
1798,
14,
525,
63,
2094,
360,
793,
63,
493,
297,
730,
29,
495,
12,
1720,
534,
515,
370,
943,
570,
358,
272,
1798,
14,
525,
63,
2094,
360,
3619,
297,
730,
29,
495,
12,
1720,
534,
515,
370,
2388,
2082,
358,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
2286,
7843,
4283,
55,
14952,
63,
3243,
275,
1249,
14,
647,
988,
20501,
63,
515,
272,
653,
22759,
57,
63,
3243,
275,
1249,
14,
4714,
63,
515,
2286,
862,
26,
267,
687,
1134,
988,
20501,
492,
627,
272,
871,
3545,
26,
267,
340,
8,
1397,
747,
14,
515,
14,
2444,
8,
4521,
4283,
55,
14952,
63,
3243,
2298,
288,
746,
6440,
480,
647,
988,
20501,
367,
2366,
650,
14,
21,
1630,
440,
2187,
11459,
25974,
908,
8,
4521,
4283,
55,
14952,
63,
3243,
430,
267,
984,
14,
515,
14,
3176,
8,
16,
12,
7843,
4283,
55,
14952,
63,
3243,
9,
267,
687,
1134,
988,
20501,
492,
627,
2286,
862,
26,
267,
492,
2680,
272,
871,
3545,
26,
267,
984,
14,
515,
14,
3176,
8,
16,
12,
653,
22759,
57,
63,
3243,
9,
267,
492,
2680,
2286,
5051,
63,
3817,
63,
3243,
275,
1249,
14,
793,
63,
493,
2286,
862,
26,
267,
2446,
8,
589,
9,
272,
871,
2186,
465,
325,
26,
267,
492,
5190,
267,
333,
275,
5190,
14,
908,
63,
2804,
342,
267,
943,
8,
77,
9,
267,
984,
14,
2224,
8,
17,
9,
272,
984,
14,
2224,
8,
16,
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
] |
[
7424,
15,
30052,
15,
4718,
14,
4857,
15,
21167,
15,
19,
14,
21,
15,
1393,
15,
1548,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
710,
10697,
844,
334,
13965,
9,
199,
3,
199,
3,
1898,
334,
67,
9,
6900,
1603,
1151,
456,
738,
15544,
13676,
75,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
199,
3,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
3,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
199,
3,
2334,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
646,
984,
199,
646,
5190,
199,
646,
7534,
199,
646,
13390,
199,
646,
2022,
199,
646,
747,
199,
646,
16701,
199,
646,
3873,
421,
199,
4947,
63,
3817,
63,
3243,
275,
488,
421,
199,
318,
943,
8,
1328,
12,
4363,
29,
16,
304,
272,
333,
275,
5310,
16,
93,
30,
469,
17,
5469,
908,
480,
259,
298,
627,
4363,
12,
1499,
9,
272,
870,
8,
77,
9,
272,
340,
8,
4947,
63,
3817,
63,
3243,
365,
440,
488,
304,
267,
543,
1551,
8,
4947,
63,
3817,
63,
3243,
12,
818,
534,
65,
297,
2644,
534,
1624,
13,
24,
297,
776,
465,
289,
26,
288,
289,
14,
952,
20794,
13536,
908,
8,
77,
12,
1867,
78,
2237,
421,
199,
318,
2446,
8,
589,
304,
272,
6118,
275,
747,
14,
515,
14,
904,
8,
589,
14,
3619,
12,
283,
3352,
14,
77,
6865,
358,
272,
5442,
275,
747,
14,
515,
14,
904,
8,
589,
14,
3619,
12,
283,
3352,
14,
476,
82,
358,
272,
282,
275,
2680,
14,
4250,
1332,
17,
12,
413,
12,
650,
395,
2152,
29,
4714,
14,
1609,
12,
776,
272,
340,
8,
736,
14,
515,
14,
2444,
8,
311,
2298,
267,
943,
360,
19332,
333,
6865,
26,
9499,
908,
8,
311,
395,
499,
9,
267,
284,
275,
445,
988,
20501,
45,
6865,
342,
267,
284,
14,
739,
8,
311,
9,
267,
282,
12,
485,
275,
284,
14,
362,
9216,
3299,
8,
708,
9,
272,
916,
8,
736,
14,
515,
14,
2444,
8,
1545,
2298,
267,
943,
360,
19332,
444,
82,
26,
9499,
908,
8,
1545,
395,
499,
9,
267,
284,
275,
445,
988,
20501,
45,
6865,
342,
267,
284,
14,
739,
3491,
8,
1545,
9,
267,
284,
14,
952,
8,
311,
9,
267,
282,
12,
485,
275,
284,
14,
362,
9216,
3299,
8,
708,
9,
272,
587,
26,
267,
943,
360,
1569,
440,
1911,
703,
297,
499,
9,
2286,
980,
275,
747,
14,
515,
14,
904,
8,
589,
14,
3619,
12,
298,
7780,
14,
20245,
531,
272,
943,
360,
14827,
2680,
26,
9499,
908,
8,
1590,
395,
499,
9,
272,
2680,
14,
2117,
8,
1590,
12,
282,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1798,
275,
7534,
14,
10730,
8,
1802,
29,
505,
3823,
14,
14674,
10505,
5483,
8228,
20501,
26570,
687,
6380,
666,
891,
659,
29850,
4581,
3660,
9698,
63,
533,
29,
18978,
14,
7963,
5831,
22779,
12,
1050,
63,
3437,
29,
549,
12,
776,
272,
1798,
14,
525,
63,
2094,
360,
647,
988,
20501,
63,
515,
297,
730,
29,
495,
12,
1720,
534,
515,
370,
2082,
3035,
1134,
988,
20501,
358,
272,
1798,
14,
525,
63,
2094,
360,
4714,
63,
515,
297,
730,
29,
495,
12,
1720,
534,
515,
370,
2082,
3035,
2680,
358,
272,
1798,
14,
525,
63,
2094,
360,
793,
63,
493,
297,
730,
29,
495,
12,
1720,
534,
515,
370,
943,
570,
358,
272,
1798,
14,
525,
63,
2094,
360,
3619,
297,
730,
29,
495,
12,
1720,
534,
515,
370,
2388,
2082,
358,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
2286,
7843,
4283,
55,
14952,
63,
3243,
275,
1249,
14,
647,
988,
20501,
63,
515,
272,
653,
22759,
57,
63,
3243,
275,
1249,
14,
4714,
63,
515,
2286,
862,
26,
267,
687,
1134,
988,
20501,
492,
627,
272,
871,
3545,
26,
267,
340,
8,
1397,
747,
14,
515,
14,
2444,
8,
4521,
4283,
55,
14952,
63,
3243,
2298,
288,
746,
6440,
480,
647,
988,
20501,
367,
2366,
650,
14,
21,
1630,
440,
2187,
11459,
25974,
908,
8,
4521,
4283,
55,
14952,
63,
3243,
430,
267,
984,
14,
515,
14,
3176,
8,
16,
12,
7843,
4283,
55,
14952,
63,
3243,
9,
267,
687,
1134,
988,
20501,
492,
627,
2286,
862,
26,
267,
492,
2680,
272,
871,
3545,
26,
267,
984,
14,
515,
14,
3176,
8,
16,
12,
653,
22759,
57,
63,
3243,
9,
267,
492,
2680,
2286,
5051,
63,
3817,
63,
3243,
275,
1249,
14,
793,
63,
493,
2286,
862,
26,
267,
2446,
8,
589,
9,
272,
871,
2186,
465,
325,
26,
267,
492,
5190,
267,
333,
275,
5190,
14,
908,
63,
2804,
342,
267,
943,
8,
77,
9,
267,
984,
14,
2224,
8,
17,
9,
272,
984,
14,
2224,
8,
16,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
fengshao0907/robomongo
|
src/third-party/mongodb/site_scons/site_tools/jsheader.py
|
12
|
1331
|
import os
from SCons.Builder import Builder
def jsToH(target, source, env):
outFile = str( target[0] )
h = ['#include "mongo/base/string_data.h"'
,'namespace mongo {'
,'struct JSFile{ const char* name; const StringData& source; };'
,'namespace JSFiles{'
]
def cppEscape(s):
s = s.strip()
s = s.replace( '\\', '\\\\' )
s = s.replace( '"', r'\"' )
return s
for s in source:
filename = str(s)
objname = os.path.split(filename)[1].split('.')[0]
stringname = '_jscode_raw_' + objname
h.append('const StringData ' + stringname + " = ")
for l in open( filename, 'r' ):
h.append( '"' + cppEscape(l) + r'\n" ' )
h.append(";")
h.append('extern const JSFile %s;'%objname) #symbols aren't exported w/o this
h.append('const JSFile %s = { "%s", %s };'%(objname, filename.replace('\\', '/'), stringname))
h.append("} // namespace JSFiles")
h.append("} // namespace mongo")
h.append("")
text = '\n'.join(h);
out = open( outFile, 'wb' )
try:
out.write( text )
finally:
out.close()
jshBuilder = Builder( action=jsToH )
def generate(env, **kw):
env.Append( BUILDERS=dict( JSHeader=jshBuilder ) )
def exists(env):
return True
|
gpl-3.0
|
[
646,
747,
199,
199,
504,
8218,
14,
6437,
492,
19286,
199,
199,
318,
8586,
1378,
40,
8,
1375,
12,
1350,
12,
2589,
304,
339,
734,
1173,
275,
620,
8,
1347,
59,
16,
61,
776,
339,
394,
275,
221,
788,
3,
2613,
298,
9217,
15,
1095,
15,
875,
63,
576,
14,
72,
4507,
267,
20606,
3251,
18006,
791,
267,
20606,
1820,
18001,
1173,
91,
950,
1495,
10,
536,
27,
950,
2624,
1451,
6,
1350,
27,
789,
8942,
267,
20606,
3251,
18001,
5535,
1445,
268,
1622,
339,
347,
7246,
10260,
8,
83,
304,
267,
308,
275,
308,
14,
1913,
342,
267,
308,
275,
308,
14,
1814,
8,
6468,
297,
31375,
7,
776,
267,
308,
275,
308,
14,
1814,
8,
32089,
519,
1154,
4507,
776,
267,
372,
308,
339,
367,
308,
315,
1350,
26,
267,
1788,
275,
620,
8,
83,
9,
267,
1559,
354,
275,
747,
14,
515,
14,
1294,
8,
1501,
2788,
17,
1055,
1294,
19237,
16,
61,
267,
1059,
354,
275,
2513,
3596,
600,
63,
1773,
8650,
435,
1559,
354,
398,
394,
14,
740,
360,
1297,
2624,
1451,
283,
435,
1059,
354,
435,
298,
275,
6099,
398,
367,
634,
315,
1551,
8,
1788,
12,
283,
82,
7,
3461,
288,
394,
14,
740,
8,
14788,
435,
7246,
10260,
8,
76,
9,
435,
519,
1154,
78,
2,
283,
776,
398,
394,
14,
740,
480,
15027,
267,
394,
14,
740,
360,
18587,
950,
18001,
1173,
450,
83,
27,
5956,
1113,
354,
9,
327,
7450,
10621,
1133,
16629,
336,
15,
79,
642,
267,
394,
14,
740,
360,
1297,
18001,
1173,
450,
83,
275,
469,
2071,
83,
401,
450,
83,
789,
8942,
2840,
1113,
354,
12,
1788,
14,
1814,
20786,
1994,
659,
1059,
354,
430,
339,
394,
14,
740,
480,
93,
5001,
3231,
18001,
5535,
531,
272,
394,
14,
740,
480,
93,
5001,
3231,
18006,
531,
272,
394,
14,
740,
10804,
339,
1318,
275,
1557,
78,
1370,
904,
8,
72,
2736,
339,
734,
275,
1551,
8,
734,
1173,
12,
283,
6603,
7,
776,
272,
862,
26,
267,
734,
14,
952,
8,
1318,
776,
272,
3753,
26,
267,
734,
14,
1600,
342,
199,
199,
74,
609,
6437,
275,
19286,
8,
1595,
29,
3596,
1378,
40,
776,
199,
199,
318,
3550,
8,
1813,
12,
1011,
829,
304,
272,
2589,
14,
8310,
8,
22974,
3960,
29,
807,
8,
18001,
2567,
29,
74,
609,
6437,
776,
776,
199,
199,
318,
3495,
8,
1813,
304,
272,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
199,
199,
504,
8218,
14,
6437,
492,
19286,
199,
199,
318,
8586,
1378,
40,
8,
1375,
12,
1350,
12,
2589,
304,
339,
734,
1173,
275,
620,
8,
1347,
59,
16,
61,
776,
339,
394,
275,
221,
788,
3,
2613,
298,
9217,
15,
1095,
15,
875,
63,
576,
14,
72,
4507,
267,
20606,
3251,
18006,
791,
267,
20606,
1820,
18001,
1173,
91,
950,
1495,
10,
536,
27,
950,
2624,
1451,
6,
1350,
27,
789,
8942,
267,
20606,
3251,
18001,
5535,
1445,
268,
1622,
339,
347,
7246,
10260,
8,
83,
304,
267,
308,
275,
308,
14,
1913,
342,
267,
308,
275,
308,
14,
1814,
8,
6468,
297,
31375,
7,
776,
267,
308,
275,
308,
14,
1814,
8,
32089,
519,
1154,
4507,
776,
267,
372,
308,
339,
367,
308,
315,
1350,
26,
267,
1788,
275,
620,
8,
83,
9,
267,
1559,
354,
275,
747,
14,
515,
14,
1294,
8,
1501,
2788,
17,
1055,
1294,
19237,
16,
61,
267,
1059,
354,
275,
2513,
3596,
600,
63,
1773,
8650,
435,
1559,
354,
398,
394,
14,
740,
360,
1297,
2624,
1451,
283,
435,
1059,
354,
435,
298,
275,
6099,
398,
367,
634,
315,
1551,
8,
1788,
12,
283,
82,
7,
3461,
288,
394,
14,
740,
8,
14788,
435,
7246,
10260,
8,
76,
9,
435,
519,
1154,
78,
2,
283,
776,
398,
394,
14,
740,
480,
15027,
267,
394,
14,
740,
360,
18587,
950,
18001,
1173,
450,
83,
27,
5956,
1113,
354,
9,
327,
7450,
10621,
1133,
16629,
336,
15,
79,
642,
267,
394,
14,
740,
360,
1297,
18001,
1173,
450,
83,
275,
469,
2071,
83,
401,
450,
83,
789,
8942,
2840,
1113,
354,
12,
1788,
14,
1814,
20786,
1994,
659,
1059,
354,
430,
339,
394,
14,
740,
480,
93,
5001,
3231,
18001,
5535,
531,
272,
394,
14,
740,
480,
93,
5001,
3231,
18006,
531,
272,
394,
14,
740,
10804,
339,
1318,
275,
1557,
78,
1370,
904,
8,
72,
2736,
339,
734,
275,
1551,
8,
734,
1173,
12,
283,
6603,
7,
776,
272,
862,
26,
267,
734,
14,
952,
8,
1318,
776,
272,
3753,
26,
267,
734,
14,
1600,
342,
199,
199,
74,
609,
6437,
275,
19286,
8,
1595,
29,
3596,
1378,
40,
776,
199,
199,
318,
3550,
8,
1813,
12,
1011,
829,
304,
272,
2589,
14,
8310,
8,
22974,
3960,
29,
807,
8,
18001,
2567,
29,
74,
609,
6437,
776,
776,
199,
199,
318,
3495,
8,
1813,
304,
272,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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ressions
re_int = re.compile('\D{0,1}\d+') # integer with one prefix character
re_ind = re.compile('\[.+\]') # interior of square brackets for tally in lattices
re_rpt = re.compile('\d+[rRiI]') # repitition syntax of MCNP input file
re_prm = re.compile('((imp:n|imp:p|tmp)\s+\S+)') # imp or tmp parameters in cell card
re_prm = re.compile('[it]mp:*[npe]*[=\s]+\S+')
fmt_d = lambda s: '{{:<{}d}}'.format(len(s))
fmt_g = lambda s: '{{:<{}g}}'.format(len(s))
fmt_s = lambda s: '{{:<{}s}}'.fromat(len(s))
fmt_s = lambda s: '{}'
class __CIDClass(object):
"""
There are two levels of card types. 1-st level is purely defined by card
position in the input file. There can be:
* message card
* title card
* cell card
* surface card
* data card.
Data cards can be of different type that is defined by the card's first
entry. Therefore data cards can be characterized by type of the 2-nd level:
* m cards,
* f cards,
* etc.
This class is to describe the 1-st level of card types.
"""
# no-information cards
comment = -1
blankline = -2
# card types in order they appear in MCNP input
message = 1
title = 2
cell = 3
surface = 4
data = 5
@classmethod
def get_name(cls, cid):
"""
Return the name of the card type by its index.
"""
for k, v in cls.__dict__.items():
if '__' not in k and v == cid:
return k
else:
print 'No attribute with name', cid
raise ValueError()
CID = __CIDClass()
class Card(object):
"""
Representation of a card.
"""
def __init__(self, lines, ctype, pos, debug=None):
# Original lines, as read from the input file
self.lines = lines
# card type by its position in the input. See CID class.
self.ctype = ctype
# data card type. Defined from the get_values() method.
# has sence only to data cards (see ctype). For other card types
# is None.
self.dtype = None
# Input file line number, where the card was found.
self.pos = pos
# File-like object to write debug info (if not None)
self.debug = debug
# template string. Represents the general structure of the card. It is
# a copy of lines, but meaningful parts are replaced by format
# specifiers, {}
self.template = ''
# List of strings represenging meaningful parts of the card. The
# original multi-line string card is obtained as
# template.format(*input)
self.input = []
# Dictionary of parts that are removed from input before processing it.
# For example, repitition syntax (e.g. 5r or 7i) is replaced with '!'
# to prevent its modification.
self.hidden = {}
# List of (v, t) tuples, where v -- value and t -- its type.
self.values = []
# Split card to template and meaningful part is always needed. Other operations
# are optional.
self.get_input()
def print_debug(self, comment, key='tihv'):
d = self.debug
if d:
print >> d, 'Line {}, {} card. {}'.format(self.pos, CID.get_name(self.ctype), comment)
if 't' in key:
print >> d, ' template:', repr(self.template)
if 'i' in key:
print >> d, ' input: ', self.input
if 'h' in key:
print >> d, ' hidden: ', self.hidden
if 'v' in key:
print >> d, ' values: ', self.values
def get_input(self):
"""
Recompute template, input and hidden attributes from lines
"""
mline = ''.join(self.lines)
bad_chars = '\t'
for c in bad_chars:
if c in mline:
if self.debug:
self.print_debug('get_input: bad character in input cards', '')
else:
raise ValueError('Bad character in input file. Run with --debug option.')
if self.ctype in (CID.comment, CID.blankline):
# nothing to do for comments or blanklines:
self.input = ''
self.template = mline
else:
# TODO: protect { and } in comment parts of the card.
tmpl = [] # part of template
inpt = [] # input, meaningful parts of the card.
if mline.split()[0][:2] == 'fc':
# this is tally comment. It always in one line and is not delimited by & or $
i = mline[:80]
t = mline.replace(i, '{}', 1)
inpt = [i]
tmpl = [t]
else:
for l in self.lines:
if is_commented(l):
tmpl.append(l)
else:
# entries optionally delimited from comments by $ or &
d1 = l.find(' $') # requires that delimiters prefixed with space-
d2 = l.find(' &')
if -1 < d1 and -1 < d2:
# both & and $ in the line. Use the most left
d = min(d1, d2)
elif d1 == -1 and d2 == -1:
# no delimiters at all, whole line is meaningful except the new-line char
d = len(l) - 1
else:
# only one of delimiters is given.
d = max(d1, d2)
i = l[:d]
t = l[d:]
inpt.append(i)
tmpl.append(fmt_s(i) + t)
self.input = inpt
self.template = ''.join(tmpl)
self.print_debug('get_input', 'ti')
return
def _protect_nums(self):
"""
In the meaningful part of the card replace numbers that do not represent cell, surface or a cell parameter with some unused char.
"""
inpt = '\n'.join(self.input)
d = {}
# in cell card:
if self.ctype == CID.cell and 'like' not in inpt:
d['~'] = [] # float values in cells
tokens = inpt.replace('=', ' ').split()
# material density
cell, mat, rho = tokens[:3]
if int(mat) != 0:
for s in (cell, mat, rho):
inpt = inpt.replace(s, '~', 1)
inpt = inpt.replace('~', cell, 1)
inpt = inpt.replace('~', mat, 1)
d['~'].append(rho)
# imp and tmp parameters:
for s in re_prm.findall(inpt):
d['~'].append(s)
inpt = inpt.replace(s, '~', 1)
# replace repitition syntax in junks:
sbl = re_rpt.findall(inpt)
if sbl:
for s in sbl:
inpt = inpt.replace(s, '!', 1)
d['!'] = sbl
if self.ctype == CID.data and inpt.lstrip().lower()[0] == 'f' and inpt.lstrip()[1].isdigit():
# this is tally card. Hide indexes in square brackets
sbl = re_ind.findall(inpt)
if sbl:
for s in sbl:
inpt = inpt.replace(s, '|', 1)
d['|'] = sbl
self.input = inpt.split('\n')
self.hidden = d
self.print_debug('_protect_nums', 'ih')
return
def get_values(self):
"""
Replace integers in the meaningfull part with format specifiers, and populate the `values` attribute.
"""
self._protect_nums()
if self.ctype == CID.cell:
inpt, vt = _split_cell(self.input)
self.name = vt[0][0]
elif self.ctype == CID.surface:
inpt, vt, stype, scoef = _split_surface(self.input)
self.stype = stype.lower()
self.scoefs = scoef
self.name = vt[0][0]
elif self.ctype == CID.data:
inpt, vt, dtype = _split_data(self.input)
self.dtype = dtype
else:
inpt = self.input
vt = []
self.input = inpt
self.values = vt
self.print_debug('get_values', 'iv')
return
def card(self, wrap=False):
"""
Return multi-line string representing the card.
"""
if self.input:
# put values back to meaningful parts:
inpt = '\n'.join(self.input)
inpt = inpt.format(*map(lambda t: t[0], self.values))
# put back hidden parts:
for k, vl in self.hidden.items():
for v in vl:
inpt = inpt.replace(k, v, 1)
inpt = inpt.split('\n')
if wrap:
tparts = self.template.split('{}')[1:]
newt = [''] # new template parts
newi = [] # new input parts
self.print_debug('card wrap=True', '')
for i, t in zip(inpt, tparts):
self.print_debug(' ' + repr(i) + repr(t), '')
il = []
tl = [t]
while len(i.rstrip()) > 79:
# first try to shift to left
if i[:5] == ' '*5:
i = ' '*5 + i.lstrip()
if len(i.rstrip()) > 79:
# input i must be wrapped. Find proper place:
for dc in ' :':
k = i.rstrip().rfind(dc, 0, 75)
if k > 6:
il.append(i[:k])
tl.append('\n')
i = ' ' + i[k:]
self.print_debug('card wrap=True' + repr(il[-1]) + repr(i), '')
break
else:
# there is no proper place to wrap.
self.print_debug('card wrap=True cannot wrap line ' + repr(i), '')
# raise ValueError('Cannot wrap card on line', self.pos)
warnings.warn('Cannot wrap card on line {}'.format(self.pos))
break
else:
# input i fits to one line. Do nothing.
pass
newt += tl
newi += il + [i]
tmpl = '{}'.join(newt)
inpt = newi
else:
tmpl = self.template
card = tmpl.format(*inpt)
else:
card = self.template
return card
def remove_spaces(self):
"""
Remove extra spaces from meaningful parts.
"""
self.print_debug('before remove_spaces', 'i')
if self.ctype in (CID.cell, CID.surface, CID.data):
inpt = []
for i in self.input:
indented = i[:5] == ' '*5
# leave only one sep. space
i = ' '.join(i.split())
i = i.strip()
# spaces before/after some characters are not needed:
for c in '):':
i = i.replace(' ' + c, c)
for c in '(:':
i = i.replace(c + ' ', c)
if indented:
i = ' '*5 + i
inpt.append(i)
self.print_debug(i, '')
self.input = inpt
self.print_debug('after remove_spaces', 'i')
return
def apply_map(self, f):
"""
Replace Ni in self.values by Mi = f(Ni, Ti).
"""
self.print_debug('before apply_map', 'v')
# u and fill should be renumberd in the same way, but types
# must remain different, to let explicit u=0
# self.values = map(lambda t: (f(t[0], t[1]), t[1]), self.values)
newvals = []
for t in self.values:
if t[1] == 'fill':
t1 = 'u'
else:
t1 = t[1]
newvals.append((f(t[0], t1), t[1]))
self.values = newvals
self.print_debug('after apply_map', 'v')
return
def _split_cell(input_):
"""
Replace integers in the meaningful parts of a cell card with format specifiers,
and return a list of replaced values together with their types.
"""
# meaningful parts together. Originally, they cannot have \n chars, since
# all of them should land to the card template, therefore, after all
# entries are replaced with format specifiers, it can be split back to a
# list easily at \n positions.
inpt = '\n'.join(input_)
vals = [] # list of values
fmts = [] # value format. It contains digits, thus will be inserted into inpt later.
tp = '_' # temporary placeholder for format specifiers
if 'like ' in inpt.lower():
# raise NotImplementedError()
warnings.warn('Parser for "like but" card, found on line {}, is not implemented'.format(self.pos))
else:
# cell card has usual format.
t = inpt.split()
# Get cell name
js = t.pop(0)
inpt = inpt.replace(js, tp, 1)
vals.append((int(js), 'cel'))
fmts.append(fmt_d(js))
# get material and density.
# Density, if specified in cells card, should be allready hidden
ms = t.pop(0)
inpt = inpt.replace(ms, tp, 1)
vals.append((int(ms), 'mat'))
fmts.append(fmt_d(ms))
# Get geometry and parameters blocks I assume that geom and param
# blocks are separated by at least one space, so there will be an
# element in t starting with alpha char -- This will be the first token
# from the param block.
geom = []
parm = []
while t:
e = t.pop(0)
if e[0].isalpha():
parm = [e] + t
break
else:
geom.append(e)
# replace integer entries in geom block:
for s in re_int.findall(' '.join(geom)):
# s is a surface or a cell (later only if prefixed by #)
t = 'cel' if s[0] == '#' else 'sur'
s = s if s[0].isdigit() else s[1:]
f = fmt_d(s)
inpt = inpt.replace(s, tp, 1)
vals.append((int(s), t))
fmts.append(f)
# replace values in parameters block. Values are prefixed with = or space(s)
# Note that tmp and imp values must be hidden
t = ' '.join(parm).replace('=', ' ').split() # get rid of =.
while t:
s = t.pop(0)
parsed = False
if s.lower() == 'u' or 'fill' in s.lower():
# I assume that only one integer follows.
vs = t.pop(0)
vv = int(vs)
vf = fmt_d(vs)
# TODO fill value can be an array
vt = 'fill' if 'fill' in s.lower() else 'u' # this distinguish between fill and u is necessary to put explicit u=0 to cells filled with some other universe.
# vt = 'u'
parsed = True
# warn if there is possibility for an array following the fill keyword:
if 'fill' is s.lower() and 'lat' in ''.join(parm).lower():
print "WARNING: fill keyword followed by an array cannot be parsed"
if parsed:
inpt = inpt.replace(vs, tp, 1)
vals.append((vv, vt))
fmts.append(vf)
# replace '_' with fmts:
for f in fmts:
inpt = inpt.replace(tp, f, 1)
return inpt.split('\n'), vals
def _split_surface(input_):
"""
Similar to _split_cell(), but for surface cards.
"""
inpt = '\n'.join(input_)
t = inpt.split()
vals = [] # like in split_cell()
fmts = []
tp = '_'
# get surface name:
js = t.pop(0)
if not js[0].isdigit():
js = js[1:]
inpt = inpt.replace(js, tp, 1)
vals.append((int(js), 'sur'))
fmts.append(fmt_d(js))
# get TR or periodic surface:
ns = t.pop(0)
if ns[0].isdigit():
# TR is given
inpt = inpt.replace(ns, tp, 1)
vals.append((int(ns), 'tr'))
fmts.append(fmt_d(ns))
st = t.pop(0)
elif ns[0] == '-':
# periodic surface
ns = ns[1:]
inpt = inpt.replace(ns, tp, 1)
vals.append((int(ns), 'sur'))
fmts.append(fmt_d(ns))
st = t.pop(0)
elif ns[0].isalpha():
# ns is the surface type
st = ns
else:
raise ValueError(input_, inpt, ns)
# define coefficients
scoef = map(float, t)
for f in fmts:
inpt = inpt.replace(tp, f, 1)
return inpt.split('\n'), vals, st, scoef
def _get_int(s):
r = ''
for c in s:
if r and c.isalpha():
break
elif c.isdigit():
r += c
return r
def _split_data(input_):
inpt = '\n'.join(input_)
t = inpt.split()
vals = []
fmts = []
tp = '_'
if 'tr' in t[0][:3].lower():
# TRn card
dtype = 'TRn'
ns = _get_int(t[0])
inpt = inpt.replace(ns, tp, 1)
vals.append((int(ns), 'tr'))
fmts.append(fmt_d(ns))
elif t[0][0].lower() == 'm' and 'mode' not in t[0].lower():
# Mn, MTn or MPNn card
ms = _get_int(t[0])
inpt = inpt.replace(ms, tp, 1)
vals.append((int(ms), 'mat'))
fmts.append(fmt_d(ms))
# additional tests to define data card type:
if t[0][1].isdigit():
dtype = 'Mn'
elif t[0][1].lower() == 't':
dtype = 'MTn'
elif t[0][1].lower() == 'p':
dtype = 'MPNn'
elif t[0][0].lower() == 'f' and t[0][1].isdigit():
# FN card
dtype = 'Fn'
ns = _get_int(t[0]) # tally number
inpt = inpt.replace(ns, tp, 1)
vals.append((int(ns), 'tal'))
fmts.append(fmt_d(ns))
# define type of integers by tally type:
nv = int(ns[-1])
if nv in [1, 2]:
typ = 'sur'
elif nv in [4, 6, 7, 8]:
typ = 'cel'
else:
typ = ''
if typ:
# Lattice indices, surrounded by square brakets must allready be hidden
# Special treatment, if tally has 'u=' syntax.
hasu = 'u' in inpt.lower() and '=' in inpt.lower()
# find all integers -- they are cells or surfaces
for s in re_int.findall(inpt):
ss = s[1:]
tpe = typ
if hasu:
# ss can be universe. To distinguish this, one needs to look
# back in previous cheracters in c.
i1 = inpt.rfind(tp)
i2 = inpt.find(ss)
part = inpt[i1:i2]
while ' ' in part:
part = part.replace(' ', '')
if part[-2:].lower() == 'u=':
tpe = 'u'
inpt = inpt.replace(ss, tp, 1)
vals.append((int(ss), tpe))
fmts.append(fmt_d(ss))
else:
dtype = None
for f in fmts:
inpt = inpt.replace(tp, f, 1)
return inpt.split('\n'), vals, dtype
def is_commented(l):
"""
Return True if l is a commented line.
"""
res = False
# remove newline chars at the end of l:
l = l.splitlines()[0]
if 'c ' in l[0:6].lstrip().lower():
res = True
#print 'is_com "c "',
elif 'c' == l.lower():
res = True
#print 'is_com "c"',
#print 'is_com', res
return res
def is_fc_card(l):
"""
Return true, if line l is tally comment cards, fcN
"""
return l.lstrip().lower()[:2] == 'fc'
def is_blankline(l):
"""
Return True, if l is the delimiter blank line.
"""
return l.strip() == ''
def get_cards(inp, debug=None):
"""
Iterable, return (str, Itype), where str is a list of lines representing a
card, and Itype is the type of the card (i.e. message, cell, surface or data)
inp -- is the filename.
"""
def _yield(card, ct, ln):
return Card(card, ct, ln, debug)
cln = 0 # current line number. Used only for debug
with open(inp, 'r') as f:
# define the first block:
# -----------------------
# Next block ID
ncid = 0 # 0 is not used in card ID dictionary CID.
# Parse the 1-st line. It can be message, cell or data block.
l = f.next()
cln += 1
kw = l.lower().split()[0]
if 'message:' == kw:
# read message block right here
res = [l]
while not is_blankline(l):
l = f.next()
cln += 1
res.append(l)
yield _yield(res, CID.message, cln-1) # message card
yield _yield(l, CID.blankline, cln) # blank line
l = f.next()
cln += 1
ncid = CID.title
elif 'continue' == kw:
# input file for continue job. Contains only data block.
ncid = CID.data
else:
ncid = CID.title
if ncid == CID.title:
# l contains the title card
yield _yield([l], ncid, cln)
ncid += 1
# read all other lines
# --------------------
# Line can be a continuation line in the following cases:
# * all lines in the message block, i.e. before the blank line delimiter
# * if line starts with 5 or more spaces,
# * if previous line ends with & sign.
# Thus, the role of the current line (continuation or not) can be
# defined by the line itself (5 spaces), or by previous lines (message
# block or & sign). This can lead to inconsistency, when previous line
# is delimited by &, but is followed by the blank line delimiter. in
# this case (rather theretical), blank line delimiter (as appeared more
# lately) delimites the card from the previous line.
cf = False # continuation line flag. Set to true only when prev. line contains &.
# Comment lines (CL) can be between cards or inside them. CL between two cards are yielded as block of comments
# (although usually, CL are used to describe cards that follow them).
# CL inside a card will belong to the card.
card = [] # card is a list of lines.
cmnt = [] # list of comment lines.
for l in f:
cln += 1
if is_blankline(l):
# blank line delimiter. Stops card even if previous line contains &
if card:
# card can be empty, for example, when several empty lines are at the end of file
yield _yield(card, ncid, cln - len(card) - len(cmnt))
if cmnt:
yield _yield(cmnt, CID.comment, cln - len(cmnt))
cmnt = []
yield _yield(l, CID.blankline, cln)
ncid += 1
card = []
if ncid == 6:
break
elif l[0:5] == ' ' or cf:
# l is continuation line.
if cmnt:
card += cmnt # previous comment lines, if any, belong to the current card.
cmnt = []
card.append(l)
cf = l.find('&', 0, 81) > -1
elif is_commented(l):
# l is a line comment. Where it belongs (to the current card or to the next one),
# depends on the next line, therefore, just store temorarily.
cmnt.append(l)
else:
# l is the 1-st line of a card. Return previous card and comments
if card:
yield _yield(card, ncid, cln - len(card) - len(cmnt))
if cmnt:
yield _yield(cmnt, CID.comment, cln - len(cmnt))
cmnt = []
card = [l]
cf = not is_fc_card(l) and l.find('&', 0, 81) > -1 # if tally comment card, i.e. started with fc, the & character does not mean continuation.
if card:
yield _yield(card, ncid, cln - len(card) - len(cmnt))
if cmnt:
yield _yield(cmnt, CID.comment, cln - len(cmnt))
def are_close_lists(x, y, re=1e-4, pci=[]):
"""
Return True if x and y are close.
"""
if len(x) != len(y):
res = False
msg = 'Different lenght'
# pci -- list of indices that define elements of x and y to be checked for proportionality only.
if len(pci) == 0:
# empty list means all x and y elements compare without arbitrary normalization.
xe = x[:]
ye = y[:]
xp = []
yp = []
else:
if len(pci) %2 == 1:
# augment with len(x) +1
pci = tuple(pci) + (len(x) + 1, )
xe = []
ye = []
xp = []
yp = []
i = 0
for i1, i2 in zip(pci[0::2], pci[1::2]):
xe += x[i:i1]
ye += y[i:i1]
xp += x[i1:i2]
yp += y[i1:i2]
i = i2
# normalize yp
xpn = sum(map(lambda e: e**2, xp))
ypn = sum(map(lambda e: e**2, yp))
if xpn > 0 and ypn > 0:
yp = map(lambda e: e*xpn/ypn, yp)
msg = []
res = []
for xl, yl in zip([xe, xp], [ye, yp]):
# compare xl and yl without normalization
if xl == yl:
res.append(True)
msg.append('exact match')
else:
n = 0
for xx, yy in zip(xl, yl):
if xx == yy:
r = True
elif xx != 0:
r = abs((xx - yy)/xx) <= re
else:
r = abs((xx - yy)/xx) <= re
if not r:
m = 'diff at {}'.format(n)
break
else:
m = 'all elements are close or equal'
r = True
res.append(r)
msg.append(m)
if not res[-1]:
result = False
break
else:
result = True
print 'are_equal', x, y, re, pci
for xl, yl, r, m in zip([xe, xp], [ye, yp], res, msg):
print ' '*5, m, r, ':'
print ' '*15, xl
print ' '*15, yl
if r:
break
return result
if __name__ == '__main__':
pass
|
gpl-3.0
|
[
624,
199,
13967,
367,
6057,
603,
12874,
48,
1324,
1584,
14,
199,
624,
199,
646,
295,
199,
646,
3598,
421,
199,
3,
5578,
8455,
199,
264,
63,
442,
275,
295,
14,
2014,
2258,
36,
91,
16,
12,
17,
4988,
68,
13854,
327,
3000,
543,
1373,
2403,
4528,
199,
264,
63,
688,
275,
295,
14,
2014,
2258,
59,
6977,
60,
10374,
258,
327,
4661,
17942,
402,
12386,
21873,
367,
307,
1183,
315,
8396,
7724,
199,
264,
63,
82,
541,
275,
295,
14,
2014,
2258,
68,
21324,
82,
28522,
41,
10374,
221,
327,
295,
1038,
3348,
6302,
402,
603,
12874,
48,
1324,
570,
199,
264,
63,
2700,
77,
275,
295,
14,
2014,
360,
1332,
3236,
26,
78,
92,
3236,
26,
80,
92,
2791,
2862,
83,
7896,
51,
11,
5942,
258,
327,
1742,
503,
3529,
2633,
315,
4917,
12564,
199,
264,
63,
2700,
77,
275,
295,
14,
2014,
11894,
390,
61,
311,
26,
23033,
78,
321,
3672,
59,
9529,
83,
24621,
51,
13854,
199,
199,
5045,
63,
68,
275,
2400,
308,
26,
11400,
16875,
2440,
68,
4863,
1370,
908,
8,
552,
8,
83,
430,
199,
5045,
63,
71,
275,
2400,
308,
26,
11400,
16875,
2440,
71,
4863,
1370,
908,
8,
552,
8,
83,
430,
199,
5045,
63,
83,
275,
2400,
308,
26,
11400,
16875,
2440,
83,
4863,
1370,
504,
292,
8,
552,
8,
83,
430,
199,
5045,
63,
83,
275,
2400,
308,
26,
19574,
421,
199,
533,
636,
35,
998,
2543,
8,
785,
304,
272,
408,
272,
6006,
787,
2877,
11106,
402,
12564,
2943,
14,
413,
13,
270,
2166,
365,
15111,
590,
3247,
701,
12564,
272,
3421,
315,
314,
1324,
570,
14,
221,
6006,
883,
506,
26,
881,
627,
1245,
12564,
881,
627,
2538,
12564,
881,
627,
4917,
12564,
881,
627,
13195,
12564,
881,
627,
666,
12564,
14,
339,
3918,
27181,
883,
506,
402,
3365,
730,
626,
365,
3247,
701,
314,
12564,
1159,
1642,
272,
2397,
14,
21039,
666,
27181,
883,
506,
2735,
15312,
701,
730,
402,
314,
499,
13,
977,
2166,
26,
881,
627,
333,
27181,
12,
881,
627,
289,
27181,
12,
881,
627,
5423,
14,
339,
961,
1021,
365,
370,
13743,
314,
413,
13,
270,
2166,
402,
12564,
2943,
14,
272,
408,
272,
327,
949,
13,
11697,
27181,
272,
3721,
275,
446,
17,
272,
4596,
604,
275,
446,
18,
272,
327,
12564,
2943,
315,
1865,
2985,
7468,
315,
603,
12874,
48,
1324,
272,
1245,
275,
413,
272,
2538,
275,
499,
272,
4917,
275,
650,
272,
13195,
275,
841,
272,
666,
275,
959,
339,
768,
3744,
272,
347,
664,
63,
354,
8,
1886,
12,
12229,
304,
267,
408,
267,
1432,
314,
536,
402,
314,
12564,
730,
701,
2399,
1478,
14,
267,
408,
267,
367,
1022,
12,
373,
315,
843,
855,
807,
4343,
1744,
837,
288,
340,
2560,
7,
440,
315,
1022,
436,
373,
508,
12229,
26,
355,
372,
1022,
267,
587,
26,
288,
870,
283,
1944,
2225,
543,
536,
297,
12229,
288,
746,
1722,
342,
199,
199,
35,
998,
275,
636,
35,
998,
2543,
342,
199,
199,
533,
445,
1005,
8,
785,
304,
272,
408,
272,
17634,
425,
402,
282,
12564,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2385,
12,
16360,
12,
2086,
12,
3105,
29,
403,
304,
398,
327,
12769,
2385,
12,
465,
1586,
687,
314,
1324,
570,
267,
291,
14,
1278,
275,
2385,
398,
327,
12564,
730,
701,
2399,
3421,
315,
314,
1324,
14,
1666,
445,
998,
1021,
14,
267,
291,
14,
3667,
275,
16360,
398,
327,
666,
12564,
730,
14,
11391,
1942,
687,
314,
664,
63,
1459,
342,
1083,
14,
267,
327,
965,
4334,
301,
1454,
370,
666,
27181,
334,
3239,
16360,
680,
2104,
1163,
12564,
2943,
267,
327,
365,
488,
14,
267,
291,
14,
2271,
275,
488,
398,
327,
6924,
570,
1004,
1329,
12,
2382,
314,
12564,
1990,
1911,
14,
267,
291,
14,
1712,
275,
2086,
398,
327,
3814,
13,
2930,
909,
370,
2218,
3105,
2256,
334,
692,
440,
488,
9,
267,
291,
14,
1757,
275,
3105,
398,
327,
1978,
1059,
14,
21591,
314,
8605,
5523,
402,
314,
12564,
14,
2779,
365,
267,
327,
282,
1331,
402,
2385,
12,
1325,
26562,
4184,
787,
8717,
701,
1475,
267,
327,
29558,
12,
1052,
267,
291,
14,
1160,
275,
2125,
398,
327,
3820,
402,
3326,
295,
7732,
1540,
26562,
4184,
402,
314,
12564,
14,
710,
267,
327,
3379,
3510,
13,
604,
1059,
12564,
365,
15884,
465,
267,
327,
1978,
14,
908,
2031,
1210,
9,
267,
291,
14,
1210,
275,
942,
398,
327,
11932,
402,
4184,
626,
787,
4829,
687,
1324,
2544,
6661,
652,
14,
267,
327,
2104,
2893,
12,
295,
1038,
3348,
6302,
334,
69,
14,
71,
14,
959,
82,
503,
1520,
73,
9,
365,
8717,
543,
29376,
267,
327,
370,
7981,
2399,
7100,
14,
267,
291,
14,
5642,
275,
1052,
398,
327,
3820,
402,
334,
86,
12,
307,
9,
6346,
12,
2382,
373,
1553,
574,
436,
307,
1553,
2399,
730,
14,
267,
291,
14,
1459,
275,
942,
398,
327,
11740,
12564,
370,
1978,
436,
26562,
1777,
365,
3544,
4346,
14,
5439,
5331,
267,
327,
787,
2716,
14,
267,
291,
14,
362,
63,
1210,
342,
339,
347,
870,
63,
1757,
8,
277,
12,
3721,
12,
790,
534,
280,
22926,
735,
267,
366,
275,
291,
14,
1757,
267,
340,
366,
26,
288,
870,
4331,
366,
12,
283,
3049,
5479,
1052,
12564,
14,
9499,
908,
8,
277,
14,
1712,
12,
445,
998,
14,
362,
63,
354,
8,
277,
14,
3667,
395,
3721,
9,
288,
340,
283,
84,
7,
315,
790,
26,
355,
870,
4331,
366,
12,
283,
259,
1978,
6536,
4700,
8,
277,
14,
1160,
9,
288,
340,
283,
73,
7,
315,
790,
26,
355,
870,
4331,
366,
12,
283,
259,
1324,
26,
257,
1656,
291,
14,
1210,
288,
340,
283,
72,
7,
315,
790,
26,
355,
870,
4331,
366,
12,
283,
259,
8752,
26,
221,
1656,
291,
14,
5642,
288,
340,
283,
86,
7,
315,
790,
26,
355,
870,
4331,
366,
12,
283,
259,
1338,
26,
221,
1656,
291,
14,
1459,
339,
347,
664,
63,
1210,
8,
277,
304,
267,
408,
267,
799,
3357,
1978,
12,
1324,
436,
8752,
3004,
687,
2385,
267,
408,
398,
333,
604,
275,
6522,
904,
8,
277,
14,
1278,
9,
267,
4875,
63,
6574,
275,
1557,
84,
7
] |
[
199,
13967,
367,
6057,
603,
12874,
48,
1324,
1584,
14,
199,
624,
199,
646,
295,
199,
646,
3598,
421,
199,
3,
5578,
8455,
199,
264,
63,
442,
275,
295,
14,
2014,
2258,
36,
91,
16,
12,
17,
4988,
68,
13854,
327,
3000,
543,
1373,
2403,
4528,
199,
264,
63,
688,
275,
295,
14,
2014,
2258,
59,
6977,
60,
10374,
258,
327,
4661,
17942,
402,
12386,
21873,
367,
307,
1183,
315,
8396,
7724,
199,
264,
63,
82,
541,
275,
295,
14,
2014,
2258,
68,
21324,
82,
28522,
41,
10374,
221,
327,
295,
1038,
3348,
6302,
402,
603,
12874,
48,
1324,
570,
199,
264,
63,
2700,
77,
275,
295,
14,
2014,
360,
1332,
3236,
26,
78,
92,
3236,
26,
80,
92,
2791,
2862,
83,
7896,
51,
11,
5942,
258,
327,
1742,
503,
3529,
2633,
315,
4917,
12564,
199,
264,
63,
2700,
77,
275,
295,
14,
2014,
11894,
390,
61,
311,
26,
23033,
78,
321,
3672,
59,
9529,
83,
24621,
51,
13854,
199,
199,
5045,
63,
68,
275,
2400,
308,
26,
11400,
16875,
2440,
68,
4863,
1370,
908,
8,
552,
8,
83,
430,
199,
5045,
63,
71,
275,
2400,
308,
26,
11400,
16875,
2440,
71,
4863,
1370,
908,
8,
552,
8,
83,
430,
199,
5045,
63,
83,
275,
2400,
308,
26,
11400,
16875,
2440,
83,
4863,
1370,
504,
292,
8,
552,
8,
83,
430,
199,
5045,
63,
83,
275,
2400,
308,
26,
19574,
421,
199,
533,
636,
35,
998,
2543,
8,
785,
304,
272,
408,
272,
6006,
787,
2877,
11106,
402,
12564,
2943,
14,
413,
13,
270,
2166,
365,
15111,
590,
3247,
701,
12564,
272,
3421,
315,
314,
1324,
570,
14,
221,
6006,
883,
506,
26,
881,
627,
1245,
12564,
881,
627,
2538,
12564,
881,
627,
4917,
12564,
881,
627,
13195,
12564,
881,
627,
666,
12564,
14,
339,
3918,
27181,
883,
506,
402,
3365,
730,
626,
365,
3247,
701,
314,
12564,
1159,
1642,
272,
2397,
14,
21039,
666,
27181,
883,
506,
2735,
15312,
701,
730,
402,
314,
499,
13,
977,
2166,
26,
881,
627,
333,
27181,
12,
881,
627,
289,
27181,
12,
881,
627,
5423,
14,
339,
961,
1021,
365,
370,
13743,
314,
413,
13,
270,
2166,
402,
12564,
2943,
14,
272,
408,
272,
327,
949,
13,
11697,
27181,
272,
3721,
275,
446,
17,
272,
4596,
604,
275,
446,
18,
272,
327,
12564,
2943,
315,
1865,
2985,
7468,
315,
603,
12874,
48,
1324,
272,
1245,
275,
413,
272,
2538,
275,
499,
272,
4917,
275,
650,
272,
13195,
275,
841,
272,
666,
275,
959,
339,
768,
3744,
272,
347,
664,
63,
354,
8,
1886,
12,
12229,
304,
267,
408,
267,
1432,
314,
536,
402,
314,
12564,
730,
701,
2399,
1478,
14,
267,
408,
267,
367,
1022,
12,
373,
315,
843,
855,
807,
4343,
1744,
837,
288,
340,
2560,
7,
440,
315,
1022,
436,
373,
508,
12229,
26,
355,
372,
1022,
267,
587,
26,
288,
870,
283,
1944,
2225,
543,
536,
297,
12229,
288,
746,
1722,
342,
199,
199,
35,
998,
275,
636,
35,
998,
2543,
342,
199,
199,
533,
445,
1005,
8,
785,
304,
272,
408,
272,
17634,
425,
402,
282,
12564,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2385,
12,
16360,
12,
2086,
12,
3105,
29,
403,
304,
398,
327,
12769,
2385,
12,
465,
1586,
687,
314,
1324,
570,
267,
291,
14,
1278,
275,
2385,
398,
327,
12564,
730,
701,
2399,
3421,
315,
314,
1324,
14,
1666,
445,
998,
1021,
14,
267,
291,
14,
3667,
275,
16360,
398,
327,
666,
12564,
730,
14,
11391,
1942,
687,
314,
664,
63,
1459,
342,
1083,
14,
267,
327,
965,
4334,
301,
1454,
370,
666,
27181,
334,
3239,
16360,
680,
2104,
1163,
12564,
2943,
267,
327,
365,
488,
14,
267,
291,
14,
2271,
275,
488,
398,
327,
6924,
570,
1004,
1329,
12,
2382,
314,
12564,
1990,
1911,
14,
267,
291,
14,
1712,
275,
2086,
398,
327,
3814,
13,
2930,
909,
370,
2218,
3105,
2256,
334,
692,
440,
488,
9,
267,
291,
14,
1757,
275,
3105,
398,
327,
1978,
1059,
14,
21591,
314,
8605,
5523,
402,
314,
12564,
14,
2779,
365,
267,
327,
282,
1331,
402,
2385,
12,
1325,
26562,
4184,
787,
8717,
701,
1475,
267,
327,
29558,
12,
1052,
267,
291,
14,
1160,
275,
2125,
398,
327,
3820,
402,
3326,
295,
7732,
1540,
26562,
4184,
402,
314,
12564,
14,
710,
267,
327,
3379,
3510,
13,
604,
1059,
12564,
365,
15884,
465,
267,
327,
1978,
14,
908,
2031,
1210,
9,
267,
291,
14,
1210,
275,
942,
398,
327,
11932,
402,
4184,
626,
787,
4829,
687,
1324,
2544,
6661,
652,
14,
267,
327,
2104,
2893,
12,
295,
1038,
3348,
6302,
334,
69,
14,
71,
14,
959,
82,
503,
1520,
73,
9,
365,
8717,
543,
29376,
267,
327,
370,
7981,
2399,
7100,
14,
267,
291,
14,
5642,
275,
1052,
398,
327,
3820,
402,
334,
86,
12,
307,
9,
6346,
12,
2382,
373,
1553,
574,
436,
307,
1553,
2399,
730,
14,
267,
291,
14,
1459,
275,
942,
398,
327,
11740,
12564,
370,
1978,
436,
26562,
1777,
365,
3544,
4346,
14,
5439,
5331,
267,
327,
787,
2716,
14,
267,
291,
14,
362,
63,
1210,
342,
339,
347,
870,
63,
1757,
8,
277,
12,
3721,
12,
790,
534,
280,
22926,
735,
267,
366,
275,
291,
14,
1757,
267,
340,
366,
26,
288,
870,
4331,
366,
12,
283,
3049,
5479,
1052,
12564,
14,
9499,
908,
8,
277,
14,
1712,
12,
445,
998,
14,
362,
63,
354,
8,
277,
14,
3667,
395,
3721,
9,
288,
340,
283,
84,
7,
315,
790,
26,
355,
870,
4331,
366,
12,
283,
259,
1978,
6536,
4700,
8,
277,
14,
1160,
9,
288,
340,
283,
73,
7,
315,
790,
26,
355,
870,
4331,
366,
12,
283,
259,
1324,
26,
257,
1656,
291,
14,
1210,
288,
340,
283,
72,
7,
315,
790,
26,
355,
870,
4331,
366,
12,
283,
259,
8752,
26,
221,
1656,
291,
14,
5642,
288,
340,
283,
86,
7,
315,
790,
26,
355,
870,
4331,
366,
12,
283,
259,
1338,
26,
221,
1656,
291,
14,
1459,
339,
347,
664,
63,
1210,
8,
277,
304,
267,
408,
267,
799,
3357,
1978,
12,
1324,
436,
8752,
3004,
687,
2385,
267,
408,
398,
333,
604,
275,
6522,
904,
8,
277,
14,
1278,
9,
267,
4875,
63,
6574,
275,
1557,
84,
7,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
LubyRuffy/theHarvester
|
discovery/shodan/api.py
|
23
|
7549
|
try:
from json import dumps, loads
except:
from simplejson import dumps, loads
from urllib2 import urlopen
from urllib import urlencode
__all__ = ['WebAPI']
class WebAPIError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return self.value
class WebAPI:
"""Wrapper around the SHODAN webservices API"""
class DatalossDb:
def __init__(self, parent):
self.parent = parent
def search(self, **kwargs):
"""Search the Dataloss DB archive.
Arguments:
name -- Name of the affected company/ organisation
arrest -- whether the incident resulted in an arrest
breaches -- the type of breach that occurred (Hack, MissingLaptop etc.)
country -- country where the incident took place
ext -- whether an external, third party was affected
ext_names -- the name of the third party company that was affected
lawsuit -- whether the incident resulted in a lawsuit
records -- the number of records that were lost/ stolen
recovered -- whether the affected items were recovered
sub_types -- the sub-categorization of the affected company/ organization
source -- whether the incident occurred from inside or outside the organization
stocks -- stock symbol of the affected company
types -- the basic type of organization (government, business, educational)
uid -- unique ID for the incident
Returns:
A dictionary with 2 main items: matches (list) and total (int).
"""
return self.parent._request('datalossdb/search', dict(**kwargs))
class Exploits:
def __init__(self, parent):
self.parent = parent
def search(self, query, sources=[],
cve=None, osvdb=None, msb=None, bid=None):
"""Search the entire Shodan Exploits archive using the same query syntax
as the website.
Arguments:
query -- exploit search query; same syntax as website
Optional arguments:
sources -- metasploit, cve, osvdb, exploitdb, or packetstorm
cve -- CVE identifier (ex. 2010-0432)
osvdb -- OSVDB identifier (ex. 11666)
msb -- Microsoft Security Bulletin ID (ex. MS05-030)
bid -- Bugtraq identifier (ex. 13951)
"""
if sources:
query += ' source:' + ','.join(sources)
if cve:
query += ' cve:%s' % (str(cve).strip())
if osvdb:
query += ' osvdb:%s' % (str(osvdb).strip())
if msb:
query += ' msb:%s' % (str(msb).strip())
if bid:
query += ' bid:%s' % (str(bid).strip())
return self.parent._request('search_exploits', {'q': query})
class ExploitDb:
def __init__(self, parent):
self.parent = parent
def download(self, id):
"""Download the exploit code from the ExploitDB archive.
Arguments:
id -- ID of the ExploitDB entry
Returns:
A dictionary with the following fields:
filename -- Name of the file
content-type -- Mimetype
data -- Contents of the file
"""
return self.parent._request('exploitdb/download', {'id': id})
def search(self, query, **kwargs):
"""Search the ExploitDB archive.
Arguments:
query -- Search terms
Optional arguments:
author -- Name of the exploit submitter
platform -- Target platform (e.g. windows, linux, hardware etc.)
port -- Service port number
type -- Any, dos, local, papers, remote, shellcode and webapps
Returns:
A dictionary with 2 main items: matches (list) and total (int).
Each item in 'matches' is a dictionary with the following elements:
id
author
date
description
platform
port
type
"""
return (
self.parent._request(
'exploitdb/search', dict(q=query, **kwargs))
)
class Msf:
def __init__(self, parent):
self.parent = parent
def download(self, id):
"""Download a metasploit module given the fullname (id) of it.
Arguments:
id -- fullname of the module (ex. auxiliary/admin/backupexec/dump)
Returns:
A dictionary with the following fields:
filename -- Name of the file
content-type -- Mimetype
data -- File content
"""
return self.parent._request('msf/download', {'id': id})
def search(self, query, **kwargs):
"""Search for a Metasploit module.
"""
return self.parent._request('msf/search', dict(q=query, **kwargs))
def __init__(self, key):
"""Initializes the API object.
Arguments:
key -- your API key
"""
self.api_key = key
self.base_url = 'http://www.shodanhq.com/api/'
self.dataloss = self.DatalossDb(self)
self.exploits = self.Exploits(self)
self.exploitdb = self.ExploitDb(self)
self.msf = self.Msf(self)
def _request(self, function, params):
"""General-purpose function to create web requests to SHODAN.
Arguments:
function -- name of the function you want to execute
params -- dictionary of parameters for the function
Returns
A JSON string containing the function's results.
"""
# Add the API key parameter automatically
params['key'] = self.api_key
# Send the request
data = urlopen(
self.base_url +
function +
'?' +
urlencode(
params)).read(
)
# Parse the text into JSON
data = loads(data)
# Raise an exception if an error occurred
if data.get('error', None):
raise WebAPIError(data['error'])
# Return the data
return data
def fingerprint(self, banner):
"""Determine the software based on the banner.
Arguments:
banner - HTTP banner
Returns:
A list of software that matched the given banner.
"""
return self._request('fingerprint', {'banner': banner})
def host(self, ip):
"""Get all available information on an IP.
Arguments:
ip -- IP of the computer
Returns:
All available information SHODAN has on the given IP,
subject to API key restrictions.
"""
return self._request('host', {'ip': ip})
def search(self, query):
"""Search the SHODAN database.
Arguments:
query -- search query; identical syntax to the website
Returns:
A dictionary with 3 main items: matches, countries and total.
Visit the website for more detailed information.
"""
return self._request('search', {'q': query})
|
gpl-2.0
|
[
893,
26,
272,
687,
2022,
492,
16864,
12,
14404,
199,
2590,
26,
272,
687,
13804,
492,
16864,
12,
14404,
199,
504,
4011,
18,
492,
18279,
199,
504,
4011,
492,
16511,
199,
199,
363,
452,
363,
275,
788,
5926,
3735,
418,
421,
199,
533,
6001,
3735,
547,
8,
1726,
304,
339,
347,
636,
826,
721,
277,
12,
574,
304,
267,
291,
14,
585,
275,
574,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
585,
421,
199,
533,
6001,
3735,
26,
339,
408,
4590,
6818,
314,
428,
2979,
36,
879,
3330,
5950,
3261,
624,
339,
1021,
577,
7539,
26890,
8882,
26,
398,
347,
636,
826,
721,
277,
12,
1676,
304,
288,
291,
14,
1708,
275,
1676,
398,
347,
2754,
8,
277,
12,
1011,
958,
304,
288,
408,
5278,
314,
577,
7539,
26890,
6249,
6359,
14,
953,
7628,
26,
288,
536,
3515,
1553,
2812,
402,
314,
16955,
7233,
15,
5981,
13181,
953,
601,
3911,
263,
1553,
3775,
314,
315,
12689,
522,
30355,
315,
376,
601,
3911,
288,
330,
12784,
397,
420,
1553,
314,
730,
402,
330,
12784,
626,
8920,
334,
40,
564,
12,
15626,
44,
439,
2119,
5423,
4959,
288,
9023,
755,
1553,
9023,
2382,
314,
315,
12689,
27221,
4192,
288,
1599,
3698,
1553,
3775,
376,
5957,
12,
10919,
17135,
1990,
16955,
288,
1599,
63,
1247,
258,
1553,
314,
536,
402,
314,
10919,
17135,
7233,
626,
1990,
16955,
288,
1127,
3569,
4993,
755,
1553,
3775,
314,
315,
12689,
522,
30355,
315,
282,
1127,
3569,
4993,
288,
5767,
755,
1553,
314,
1329,
402,
5767,
626,
4898,
14669,
15,
26123,
552,
288,
295,
13560,
258,
1553,
3775,
314,
16955,
2974,
4898,
295,
13560,
288,
1007,
63,
1313,
258,
1553,
314,
1007,
13,
7206,
2072,
402,
314,
16955,
7233,
15,
13237,
288,
1350,
263,
1553,
3775,
314,
315,
12689,
8920,
687,
6272,
503,
9682,
314,
13237,
288,
10952,
83,
263,
1553,
10952,
5272,
402,
314,
16955,
7233,
288,
2943,
260,
1553,
314,
5678,
730,
402,
13237,
334,
71,
27639,
12,
26440,
12,
3988,
947,
6279,
9,
288,
1747,
3698,
1553,
3747,
2870,
367,
314,
315,
12689,
953,
1803,
26,
288,
437,
2600,
543,
499,
2446,
2974,
26,
4450,
334,
513,
9,
436,
3141,
334,
442,
680,
953,
408,
288,
372,
291,
14,
1708,
423,
1069,
360,
4616,
12201,
385,
697,
15,
1733,
297,
1211,
3682,
958,
430,
339,
1021,
7910,
320,
1405,
26,
398,
347,
636,
826,
721,
277,
12,
1676,
304,
288,
291,
14,
1708,
275,
1676,
398,
347,
2754,
8,
277,
12,
1827,
12,
5274,
6034,
673,
286,
432,
29,
403,
12,
9506,
697,
29,
403,
12,
6605,
66,
29,
403,
12,
330,
344,
29,
403,
304,
288,
408,
5278,
314,
8039,
5244,
364,
290,
7910,
320,
1405,
6359,
1808,
314,
2011,
1827,
6302,
288,
465,
314,
10691,
14,
953,
7628,
26,
288,
1827,
259,
1553,
15868,
390,
2754,
1827,
27,
2011,
6302,
465,
10691,
953,
4879,
2368,
26,
288,
5274,
221,
1553,
7647,
20222,
320,
390,
12,
286,
432,
12,
9506,
697,
12,
15868,
390,
697,
12,
503,
3644,
26949,
288,
286,
432,
420,
1553,
445,
2524,
5148,
334,
476,
14,
7129,
13,
17436,
9,
288,
9506,
697,
259,
1553,
4403,
54,
2846,
5148,
334,
476,
14,
25186,
1272,
9,
288,
6605,
66,
420,
1553,
15332,
13863,
699,
348,
274,
1346,
2870,
334,
476,
14,
14282,
1717,
13,
22739,
9,
288,
330,
344,
420,
1553,
21605,
1239,
81,
5148,
334,
476,
14,
22317,
2869,
9,
953,
408,
288,
340,
5274,
26,
355,
1827,
847,
283,
1350,
4881,
435,
12814,
904,
8,
4553,
9,
288,
340,
286,
432,
26,
355,
1827,
847,
283,
286,
432,
2689,
83,
7,
450,
334,
495,
8,
67,
432,
680,
1913,
1012,
288,
340,
9506,
697,
26,
355,
1827,
847,
283,
9506,
697,
2689,
83,
7,
450,
334,
495,
8,
4795,
697,
680,
1913,
1012,
288,
340,
6605,
66,
26,
355,
1827,
847,
283,
6605,
66,
2689,
83,
7,
450,
334,
495,
8,
706,
66,
680,
1913,
1012,
288,
340,
330,
344,
26,
355,
1827,
847,
283,
330,
344,
2689,
83,
7,
450,
334,
495,
8,
17949,
680,
1913,
1012,
288,
372,
291,
14,
1708,
423,
1069,
360,
1733,
63,
16971,
1405,
297,
791,
81,
356,
1827,
1552,
339,
1021,
7910,
320,
390,
8882,
26,
398,
347,
636,
826,
721,
277,
12,
1676,
304,
288,
291,
14,
1708,
275,
1676,
398,
347,
5235,
8,
277,
12,
1305,
304,
288,
408,
11950,
314,
15868,
390,
1233,
687,
314,
7910,
320,
390,
2846,
6359,
14,
953,
7628,
26,
288,
1305,
259,
1553,
2870,
402,
314,
7910,
320,
390,
2846,
2397,
953,
1803,
26,
288,
437,
2600,
543,
314,
2569,
1504,
26,
288,
1788,
263,
1553,
2812,
402,
314,
570,
288,
1564,
13,
466,
259,
1553,
603,
1036,
466,
288,
666,
3322,
1553,
6646,
83,
402,
314,
570,
953,
408,
288,
372,
291,
14,
1708,
423,
1069,
360,
16971,
390,
697,
15,
4249,
297,
791,
344,
356,
1305,
1552,
398,
347,
2754,
8,
277,
12,
1827,
12,
1011,
958,
304,
288,
408,
5278,
314,
7910,
320,
390,
2846,
6359,
14,
953,
7628,
26,
288,
1827,
258,
1553,
8730,
2895,
953,
4879,
2368,
26,
288,
4132,
259,
1553,
2812,
402,
314,
15868,
390,
11482,
351,
288,
4298,
221,
1553,
10256,
4298,
334,
69,
14,
71,
14,
10061,
12,
18369,
12,
14991,
5423,
4959,
288,
1844,
420,
1553,
7591,
1844,
1329,
288,
730,
420,
1553,
6184,
12,
31069,
12,
2257,
12,
299,
439,
1192,
12,
3982,
12,
5218,
600,
436,
3330,
5181,
953,
1803,
26,
288,
437,
2600,
543,
499,
2446,
2974,
26,
4450,
334,
513,
9,
436,
3141,
334,
442,
680,
288,
7048,
1242,
315,
283,
6742,
7,
365,
282,
2600,
543,
314,
2569,
4008,
26,
953,
1305,
288,
4132,
288,
1434,
288,
1369,
288,
4298,
288,
1844,
288,
730,
953,
408,
288,
372,
334,
355,
291,
14,
1708,
423,
1069,
8,
490,
283,
16971,
390,
697,
15,
1733,
297,
1211,
8,
81,
29,
1131,
12,
1011,
958,
430,
288,
776,
339,
1021,
603,
7646,
26,
398,
347,
636,
826,
721,
277,
12,
1676,
304,
288,
291,
14,
1708,
275,
1676,
398,
347,
5235,
8,
277,
12,
1305,
304,
288,
408,
11950,
282,
7647,
20222,
320,
390,
859,
1627,
314,
11064,
334,
344,
9
] |
[
26,
272,
687,
2022,
492,
16864,
12,
14404,
199,
2590,
26,
272,
687,
13804,
492,
16864,
12,
14404,
199,
504,
4011,
18,
492,
18279,
199,
504,
4011,
492,
16511,
199,
199,
363,
452,
363,
275,
788,
5926,
3735,
418,
421,
199,
533,
6001,
3735,
547,
8,
1726,
304,
339,
347,
636,
826,
721,
277,
12,
574,
304,
267,
291,
14,
585,
275,
574,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
585,
421,
199,
533,
6001,
3735,
26,
339,
408,
4590,
6818,
314,
428,
2979,
36,
879,
3330,
5950,
3261,
624,
339,
1021,
577,
7539,
26890,
8882,
26,
398,
347,
636,
826,
721,
277,
12,
1676,
304,
288,
291,
14,
1708,
275,
1676,
398,
347,
2754,
8,
277,
12,
1011,
958,
304,
288,
408,
5278,
314,
577,
7539,
26890,
6249,
6359,
14,
953,
7628,
26,
288,
536,
3515,
1553,
2812,
402,
314,
16955,
7233,
15,
5981,
13181,
953,
601,
3911,
263,
1553,
3775,
314,
315,
12689,
522,
30355,
315,
376,
601,
3911,
288,
330,
12784,
397,
420,
1553,
314,
730,
402,
330,
12784,
626,
8920,
334,
40,
564,
12,
15626,
44,
439,
2119,
5423,
4959,
288,
9023,
755,
1553,
9023,
2382,
314,
315,
12689,
27221,
4192,
288,
1599,
3698,
1553,
3775,
376,
5957,
12,
10919,
17135,
1990,
16955,
288,
1599,
63,
1247,
258,
1553,
314,
536,
402,
314,
10919,
17135,
7233,
626,
1990,
16955,
288,
1127,
3569,
4993,
755,
1553,
3775,
314,
315,
12689,
522,
30355,
315,
282,
1127,
3569,
4993,
288,
5767,
755,
1553,
314,
1329,
402,
5767,
626,
4898,
14669,
15,
26123,
552,
288,
295,
13560,
258,
1553,
3775,
314,
16955,
2974,
4898,
295,
13560,
288,
1007,
63,
1313,
258,
1553,
314,
1007,
13,
7206,
2072,
402,
314,
16955,
7233,
15,
13237,
288,
1350,
263,
1553,
3775,
314,
315,
12689,
8920,
687,
6272,
503,
9682,
314,
13237,
288,
10952,
83,
263,
1553,
10952,
5272,
402,
314,
16955,
7233,
288,
2943,
260,
1553,
314,
5678,
730,
402,
13237,
334,
71,
27639,
12,
26440,
12,
3988,
947,
6279,
9,
288,
1747,
3698,
1553,
3747,
2870,
367,
314,
315,
12689,
953,
1803,
26,
288,
437,
2600,
543,
499,
2446,
2974,
26,
4450,
334,
513,
9,
436,
3141,
334,
442,
680,
953,
408,
288,
372,
291,
14,
1708,
423,
1069,
360,
4616,
12201,
385,
697,
15,
1733,
297,
1211,
3682,
958,
430,
339,
1021,
7910,
320,
1405,
26,
398,
347,
636,
826,
721,
277,
12,
1676,
304,
288,
291,
14,
1708,
275,
1676,
398,
347,
2754,
8,
277,
12,
1827,
12,
5274,
6034,
673,
286,
432,
29,
403,
12,
9506,
697,
29,
403,
12,
6605,
66,
29,
403,
12,
330,
344,
29,
403,
304,
288,
408,
5278,
314,
8039,
5244,
364,
290,
7910,
320,
1405,
6359,
1808,
314,
2011,
1827,
6302,
288,
465,
314,
10691,
14,
953,
7628,
26,
288,
1827,
259,
1553,
15868,
390,
2754,
1827,
27,
2011,
6302,
465,
10691,
953,
4879,
2368,
26,
288,
5274,
221,
1553,
7647,
20222,
320,
390,
12,
286,
432,
12,
9506,
697,
12,
15868,
390,
697,
12,
503,
3644,
26949,
288,
286,
432,
420,
1553,
445,
2524,
5148,
334,
476,
14,
7129,
13,
17436,
9,
288,
9506,
697,
259,
1553,
4403,
54,
2846,
5148,
334,
476,
14,
25186,
1272,
9,
288,
6605,
66,
420,
1553,
15332,
13863,
699,
348,
274,
1346,
2870,
334,
476,
14,
14282,
1717,
13,
22739,
9,
288,
330,
344,
420,
1553,
21605,
1239,
81,
5148,
334,
476,
14,
22317,
2869,
9,
953,
408,
288,
340,
5274,
26,
355,
1827,
847,
283,
1350,
4881,
435,
12814,
904,
8,
4553,
9,
288,
340,
286,
432,
26,
355,
1827,
847,
283,
286,
432,
2689,
83,
7,
450,
334,
495,
8,
67,
432,
680,
1913,
1012,
288,
340,
9506,
697,
26,
355,
1827,
847,
283,
9506,
697,
2689,
83,
7,
450,
334,
495,
8,
4795,
697,
680,
1913,
1012,
288,
340,
6605,
66,
26,
355,
1827,
847,
283,
6605,
66,
2689,
83,
7,
450,
334,
495,
8,
706,
66,
680,
1913,
1012,
288,
340,
330,
344,
26,
355,
1827,
847,
283,
330,
344,
2689,
83,
7,
450,
334,
495,
8,
17949,
680,
1913,
1012,
288,
372,
291,
14,
1708,
423,
1069,
360,
1733,
63,
16971,
1405,
297,
791,
81,
356,
1827,
1552,
339,
1021,
7910,
320,
390,
8882,
26,
398,
347,
636,
826,
721,
277,
12,
1676,
304,
288,
291,
14,
1708,
275,
1676,
398,
347,
5235,
8,
277,
12,
1305,
304,
288,
408,
11950,
314,
15868,
390,
1233,
687,
314,
7910,
320,
390,
2846,
6359,
14,
953,
7628,
26,
288,
1305,
259,
1553,
2870,
402,
314,
7910,
320,
390,
2846,
2397,
953,
1803,
26,
288,
437,
2600,
543,
314,
2569,
1504,
26,
288,
1788,
263,
1553,
2812,
402,
314,
570,
288,
1564,
13,
466,
259,
1553,
603,
1036,
466,
288,
666,
3322,
1553,
6646,
83,
402,
314,
570,
953,
408,
288,
372,
291,
14,
1708,
423,
1069,
360,
16971,
390,
697,
15,
4249,
297,
791,
344,
356,
1305,
1552,
398,
347,
2754,
8,
277,
12,
1827,
12,
1011,
958,
304,
288,
408,
5278,
314,
7910,
320,
390,
2846,
6359,
14,
953,
7628,
26,
288,
1827,
258,
1553,
8730,
2895,
953,
4879,
2368,
26,
288,
4132,
259,
1553,
2812,
402,
314,
15868,
390,
11482,
351,
288,
4298,
221,
1553,
10256,
4298,
334,
69,
14,
71,
14,
10061,
12,
18369,
12,
14991,
5423,
4959,
288,
1844,
420,
1553,
7591,
1844,
1329,
288,
730,
420,
1553,
6184,
12,
31069,
12,
2257,
12,
299,
439,
1192,
12,
3982,
12,
5218,
600,
436,
3330,
5181,
953,
1803,
26,
288,
437,
2600,
543,
499,
2446,
2974,
26,
4450,
334,
513,
9,
436,
3141,
334,
442,
680,
288,
7048,
1242,
315,
283,
6742,
7,
365,
282,
2600,
543,
314,
2569,
4008,
26,
953,
1305,
288,
4132,
288,
1434,
288,
1369,
288,
4298,
288,
1844,
288,
730,
953,
408,
288,
372,
334,
355,
291,
14,
1708,
423,
1069,
8,
490,
283,
16971,
390,
697,
15,
1733,
297,
1211,
8,
81,
29,
1131,
12,
1011,
958,
430,
288,
776,
339,
1021,
603,
7646,
26,
398,
347,
636,
826,
721,
277,
12,
1676,
304,
288,
291,
14,
1708,
275,
1676,
398,
347,
5235,
8,
277,
12,
1305,
304,
288,
408,
11950,
282,
7647,
20222,
320,
390,
859,
1627,
314,
11064,
334,
344,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hadyelsahar/RE-NLG-Dataset
|
run_example.py
|
1
|
2574
|
from pipeline.pipeline import *
from pipeline.entitylinker import *
from pipeline.triplealigner import *
from pipeline.datareader import DBpediaAbstractsDataReader
from pipeline.writer import *
from pipeline.coreference import *
from pipeline.placeholdertagger import *
from utils.triplereader import *
from utils.triplereaderitems import *
from utils.triplereadertriples import *
from utils.labelreader import *
from pipeline.filter import *
# Reading the DBpedia Abstracts Dataset
reader = DBpediaAbstractsDataReader('./datasets/wikipedia-abstracts/csv/sample-dbpedia-abstracts-es.csv')
trip_read = TripleReader('./datasets/wikidata/sample-wikidata-triples.csv')
label_read = LabelReader('./datasets/wikidata/sample-wikidata-labels.csv', 'es')
trip_read_items = TripleReaderItems('./datasets/wikidata/sample-wikidata-triples.csv')
trip_read_trip = TripleReaderTriples('./datasets/wikidata/sample-wikidata-triples.csv')
keyword_ent_linker = KeywordMatchingEntityLinker(trip_read_items, label_read)
salign = SimpleAligner(trip_read)
#prop = WikidataPropertyLinker('./datasets/wikidata/wikidata-properties.csv')
date = DateLinker()
#SPOalign = SPOAligner(trip_read)
nsalign = NoSubjectAlign(trip_read)
noalign = NoAligner(trip_read_trip)
filter_entities = ['http://www.wikidata.org/entity/Q4167410', 'http://www.wikidata.org/entity/Q13406463']
ent_filt = EntityTypeFilter(trip_read_trip, filter_entities)
sen_lim = SentenceLimiter()
main_ent_lim = MainEntityLimiter()
writer = JsonWriter('./out-test', "", 1)
prop_tag = PropertyPlaceholderTagger()
writer_triples = CustomeWriterTriples('./out-test', "", 1)
writer_entities = CustomeWriterEntities('./out-test', "", 1)
for d in reader.read_documents():
#print d.title
#print label_read.get(d.docid)
try:
print "Processing Document Title: %s ..." % d.title
if not ent_filt.run(d):
continue
d = keyword_ent_linker.run(d)
d = date.run(d)
#d = link.run(d)
# d = nsalign.run(d)
#d = coref.run(d)
d = salign.run(d)
#d = prop.run(d)
#d = SPOalign.run(d)
d = sen_lim.run(d, 0)
if not main_ent_lim.run(d):
continue
d = noalign.run(d)
d = prop_tag.run(d)
writer_triples.run(d)
writer_entities.run(d)
# writer.run(d)
print "Document Title: %s \t Number of Annotated Entities %s \t Number of Annotated Triples %s" % (d.title, len(d.entities), len(d.triples))
except Exception as e:
print "error Processing document %s" % d.title
|
mit
|
[
504,
7679,
14,
7379,
492,
627,
199,
504,
7679,
14,
4502,
20311,
492,
627,
199,
504,
7679,
14,
19956,
5743,
281,
492,
627,
199,
504,
7679,
14,
576,
5503,
492,
6249,
321,
2391,
8458,
83,
1451,
5929,
199,
504,
7679,
14,
5491,
492,
627,
199,
504,
7679,
14,
1018,
1769,
492,
627,
199,
504,
7679,
14,
6199,
1450,
836,
492,
627,
199,
504,
3778,
14,
19956,
5503,
492,
627,
199,
504,
3778,
14,
19956,
8273,
271,
4006,
492,
627,
199,
504,
3778,
14,
19956,
5503,
7254,
2978,
492,
627,
199,
504,
3778,
14,
1302,
5503,
492,
627,
199,
504,
7679,
14,
1541,
492,
627,
199,
199,
3,
799,
5384,
314,
6249,
321,
2391,
11836,
83,
20284,
199,
5503,
275,
6249,
321,
2391,
8458,
83,
1451,
5929,
17371,
12281,
15,
13961,
13,
6198,
83,
15,
4737,
15,
3271,
13,
697,
321,
2391,
13,
6198,
83,
13,
397,
14,
4737,
358,
199,
199,
7254,
63,
739,
275,
12480,
11045,
5929,
17371,
12281,
15,
5319,
344,
419,
15,
3271,
13,
5319,
344,
419,
13,
7254,
2978,
14,
4737,
358,
199,
1302,
63,
739,
275,
10354,
5929,
17371,
12281,
15,
5319,
344,
419,
15,
3271,
13,
5319,
344,
419,
13,
3512,
14,
4737,
297,
283,
397,
358,
199,
7254,
63,
739,
63,
1744,
275,
12480,
11045,
5929,
7412,
17371,
12281,
15,
5319,
344,
419,
15,
3271,
13,
5319,
344,
419,
13,
7254,
2978,
14,
4737,
358,
199,
7254,
63,
739,
63,
7254,
275,
12480,
11045,
5929,
32220,
2978,
17371,
12281,
15,
5319,
344,
419,
15,
3271,
13,
5319,
344,
419,
13,
7254,
2978,
14,
4737,
358,
199,
199,
6691,
63,
484,
63,
20311,
275,
6431,
14215,
7302,
3834,
281,
8,
7254,
63,
739,
63,
1744,
12,
1768,
63,
739,
9,
199,
83,
5743,
275,
5870,
9497,
281,
8,
7254,
63,
739,
9,
199,
199,
3,
4469,
275,
644,
3258,
344,
419,
3697,
3834,
281,
17371,
12281,
15,
5319,
344,
419,
15,
5319,
344,
419,
13,
3282,
14,
4737,
358,
199,
602,
275,
6148,
3834,
281,
342,
199,
3,
51,
1512,
5743,
275,
428,
1512,
9497,
281,
8,
7254,
63,
739,
9,
199,
561,
5743,
275,
3091,
13528,
9497,
8,
7254,
63,
739,
9,
199,
889,
5743,
275,
3091,
9497,
281,
8,
7254,
63,
739,
63,
7254,
9,
199,
199,
1541,
63,
8327,
275,
788,
1014,
921,
1544,
14,
5319,
344,
419,
14,
1308,
15,
4502,
15,
49,
25209,
1342,
709,
297,
283,
1014,
921,
1544,
14,
5319,
344,
419,
14,
1308,
15,
4502,
15,
49,
969,
2167,
772,
2766,
418,
199,
484,
63,
18872,
275,
17680,
804,
4131,
8,
7254,
63,
739,
63,
7254,
12,
2457,
63,
8327,
9,
199,
2464,
63,
4175,
275,
428,
287,
6692,
7219,
1661,
342,
199,
973,
63,
484,
63,
4175,
275,
11298,
7302,
7219,
1661,
342,
199,
199,
5491,
275,
14587,
6261,
17371,
548,
13,
396,
297,
4873,
413,
9,
199,
199,
4469,
63,
1450,
275,
16158,
20185,
1931,
836,
342,
199,
199,
5491,
63,
7254,
2978,
275,
445,
5999,
6261,
32220,
2978,
17371,
548,
13,
396,
297,
4873,
413,
9,
199,
5491,
63,
8327,
275,
445,
5999,
6261,
24672,
17371,
548,
13,
396,
297,
4873,
413,
9,
199,
199,
509,
366,
315,
7002,
14,
739,
63,
12233,
837,
272,
327,
1361,
366,
14,
1213,
339,
327,
1361,
1768,
63,
739,
14,
362,
8,
68,
14,
1301,
344,
9,
272,
862,
26,
267,
870,
298,
9589,
7543,
16881,
26,
450,
83,
21742,
450,
366,
14,
1213,
267,
340,
440,
15992,
63,
18872,
14,
1065,
8,
68,
304,
288,
1980,
398,
366,
275,
4252,
63,
484,
63,
20311,
14,
1065,
8,
68,
9,
267,
366,
275,
1434,
14,
1065,
8,
68,
9,
267,
327,
68,
275,
2142,
14,
1065,
8,
68,
9,
398,
327,
366,
275,
700,
5743,
14,
1065,
8,
68,
9,
398,
327,
68,
275,
512,
1121,
14,
1065,
8,
68,
9,
267,
366,
275,
308,
5743,
14,
1065,
8,
68,
9,
267,
327,
68,
275,
5931,
14,
1065,
8,
68,
9,
267,
327,
68,
275,
428,
1512,
5743,
14,
1065,
8,
68,
9,
267,
366,
275,
4334,
63,
4175,
14,
1065,
8,
68,
12,
378,
9,
398,
340,
440,
2446,
63,
484,
63,
4175,
14,
1065,
8,
68,
304,
288,
1980,
398,
366,
275,
949,
5743,
14,
1065,
8,
68,
9,
267,
366,
275,
5931,
63,
1450,
14,
1065,
8,
68,
9,
398,
7060,
63,
7254,
2978,
14,
1065,
8,
68,
9,
267,
7060,
63,
8327,
14,
1065,
8,
68,
9,
267,
327,
7060,
14,
1065,
8,
68,
9,
267,
870,
298,
5564,
16881,
26,
450,
83,
971,
84,
4860,
402,
1626,
1397,
972,
3447,
5080,
450,
83,
971,
84,
4860,
402,
1626,
1397,
972,
12480,
80,
2978,
450,
83,
2,
450,
334,
68,
14,
1213,
12,
822,
8,
68,
14,
8327,
395,
822,
8,
68,
14,
7254,
2978,
430,
339,
871,
2186,
465,
325,
26,
267,
870,
298,
705,
20157,
2213,
450,
83,
2,
450,
366,
14,
1213,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
7679,
14,
7379,
492,
627,
199,
504,
7679,
14,
4502,
20311,
492,
627,
199,
504,
7679,
14,
19956,
5743,
281,
492,
627,
199,
504,
7679,
14,
576,
5503,
492,
6249,
321,
2391,
8458,
83,
1451,
5929,
199,
504,
7679,
14,
5491,
492,
627,
199,
504,
7679,
14,
1018,
1769,
492,
627,
199,
504,
7679,
14,
6199,
1450,
836,
492,
627,
199,
504,
3778,
14,
19956,
5503,
492,
627,
199,
504,
3778,
14,
19956,
8273,
271,
4006,
492,
627,
199,
504,
3778,
14,
19956,
5503,
7254,
2978,
492,
627,
199,
504,
3778,
14,
1302,
5503,
492,
627,
199,
504,
7679,
14,
1541,
492,
627,
199,
199,
3,
799,
5384,
314,
6249,
321,
2391,
11836,
83,
20284,
199,
5503,
275,
6249,
321,
2391,
8458,
83,
1451,
5929,
17371,
12281,
15,
13961,
13,
6198,
83,
15,
4737,
15,
3271,
13,
697,
321,
2391,
13,
6198,
83,
13,
397,
14,
4737,
358,
199,
199,
7254,
63,
739,
275,
12480,
11045,
5929,
17371,
12281,
15,
5319,
344,
419,
15,
3271,
13,
5319,
344,
419,
13,
7254,
2978,
14,
4737,
358,
199,
1302,
63,
739,
275,
10354,
5929,
17371,
12281,
15,
5319,
344,
419,
15,
3271,
13,
5319,
344,
419,
13,
3512,
14,
4737,
297,
283,
397,
358,
199,
7254,
63,
739,
63,
1744,
275,
12480,
11045,
5929,
7412,
17371,
12281,
15,
5319,
344,
419,
15,
3271,
13,
5319,
344,
419,
13,
7254,
2978,
14,
4737,
358,
199,
7254,
63,
739,
63,
7254,
275,
12480,
11045,
5929,
32220,
2978,
17371,
12281,
15,
5319,
344,
419,
15,
3271,
13,
5319,
344,
419,
13,
7254,
2978,
14,
4737,
358,
199,
199,
6691,
63,
484,
63,
20311,
275,
6431,
14215,
7302,
3834,
281,
8,
7254,
63,
739,
63,
1744,
12,
1768,
63,
739,
9,
199,
83,
5743,
275,
5870,
9497,
281,
8,
7254,
63,
739,
9,
199,
199,
3,
4469,
275,
644,
3258,
344,
419,
3697,
3834,
281,
17371,
12281,
15,
5319,
344,
419,
15,
5319,
344,
419,
13,
3282,
14,
4737,
358,
199,
602,
275,
6148,
3834,
281,
342,
199,
3,
51,
1512,
5743,
275,
428,
1512,
9497,
281,
8,
7254,
63,
739,
9,
199,
561,
5743,
275,
3091,
13528,
9497,
8,
7254,
63,
739,
9,
199,
889,
5743,
275,
3091,
9497,
281,
8,
7254,
63,
739,
63,
7254,
9,
199,
199,
1541,
63,
8327,
275,
788,
1014,
921,
1544,
14,
5319,
344,
419,
14,
1308,
15,
4502,
15,
49,
25209,
1342,
709,
297,
283,
1014,
921,
1544,
14,
5319,
344,
419,
14,
1308,
15,
4502,
15,
49,
969,
2167,
772,
2766,
418,
199,
484,
63,
18872,
275,
17680,
804,
4131,
8,
7254,
63,
739,
63,
7254,
12,
2457,
63,
8327,
9,
199,
2464,
63,
4175,
275,
428,
287,
6692,
7219,
1661,
342,
199,
973,
63,
484,
63,
4175,
275,
11298,
7302,
7219,
1661,
342,
199,
199,
5491,
275,
14587,
6261,
17371,
548,
13,
396,
297,
4873,
413,
9,
199,
199,
4469,
63,
1450,
275,
16158,
20185,
1931,
836,
342,
199,
199,
5491,
63,
7254,
2978,
275,
445,
5999,
6261,
32220,
2978,
17371,
548,
13,
396,
297,
4873,
413,
9,
199,
5491,
63,
8327,
275,
445,
5999,
6261,
24672,
17371,
548,
13,
396,
297,
4873,
413,
9,
199,
199,
509,
366,
315,
7002,
14,
739,
63,
12233,
837,
272,
327,
1361,
366,
14,
1213,
339,
327,
1361,
1768,
63,
739,
14,
362,
8,
68,
14,
1301,
344,
9,
272,
862,
26,
267,
870,
298,
9589,
7543,
16881,
26,
450,
83,
21742,
450,
366,
14,
1213,
267,
340,
440,
15992,
63,
18872,
14,
1065,
8,
68,
304,
288,
1980,
398,
366,
275,
4252,
63,
484,
63,
20311,
14,
1065,
8,
68,
9,
267,
366,
275,
1434,
14,
1065,
8,
68,
9,
267,
327,
68,
275,
2142,
14,
1065,
8,
68,
9,
398,
327,
366,
275,
700,
5743,
14,
1065,
8,
68,
9,
398,
327,
68,
275,
512,
1121,
14,
1065,
8,
68,
9,
267,
366,
275,
308,
5743,
14,
1065,
8,
68,
9,
267,
327,
68,
275,
5931,
14,
1065,
8,
68,
9,
267,
327,
68,
275,
428,
1512,
5743,
14,
1065,
8,
68,
9,
267,
366,
275,
4334,
63,
4175,
14,
1065,
8,
68,
12,
378,
9,
398,
340,
440,
2446,
63,
484,
63,
4175,
14,
1065,
8,
68,
304,
288,
1980,
398,
366,
275,
949,
5743,
14,
1065,
8,
68,
9,
267,
366,
275,
5931,
63,
1450,
14,
1065,
8,
68,
9,
398,
7060,
63,
7254,
2978,
14,
1065,
8,
68,
9,
267,
7060,
63,
8327,
14,
1065,
8,
68,
9,
267,
327,
7060,
14,
1065,
8,
68,
9,
267,
870,
298,
5564,
16881,
26,
450,
83,
971,
84,
4860,
402,
1626,
1397,
972,
3447,
5080,
450,
83,
971,
84,
4860,
402,
1626,
1397,
972,
12480,
80,
2978,
450,
83,
2,
450,
334,
68,
14,
1213,
12,
822,
8,
68,
14,
8327,
395,
822,
8,
68,
14,
7254,
2978,
430,
339,
871,
2186,
465,
325,
26,
267,
870,
298,
705,
20157,
2213,
450,
83,
2,
450,
366,
14,
1213,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
farhi-naz/phantomjs
|
src/qt/qtwebkit/Tools/Scripts/webkitpy/layout_tests/models/test_results.py
|
126
|
3187
|
# Copyright (C) 2010 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import cPickle
from webkitpy.layout_tests.models import test_failures
class TestResult(object):
"""Data object containing the results of a single test."""
@staticmethod
def loads(string):
return cPickle.loads(string)
def __init__(self, test_name, failures=None, test_run_time=None, has_stderr=False, reftest_type=None, pid=None, references=None):
self.test_name = test_name
self.failures = failures or []
self.test_run_time = test_run_time or 0 # The time taken to execute the test itself.
self.has_stderr = has_stderr
self.reftest_type = reftest_type or []
self.pid = pid
self.references = references or []
# FIXME: Setting this in the constructor makes this class hard to mutate.
self.type = test_failures.determine_result_type(failures)
# These are set by the worker, not by the driver, so they are not passed to the constructor.
self.worker_name = ''
self.shard_name = ''
self.total_run_time = 0 # The time taken to run the test plus any references, compute diffs, etc.
self.test_number = None
def __eq__(self, other):
return (self.test_name == other.test_name and
self.failures == other.failures and
self.test_run_time == other.test_run_time)
def __ne__(self, other):
return not (self == other)
def has_failure_matching_types(self, *failure_classes):
for failure in self.failures:
if type(failure) in failure_classes:
return True
return False
def dumps(self):
return cPickle.dumps(self)
|
bsd-3-clause
|
[
3,
1898,
334,
35,
9,
7129,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
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,
646,
17572,
199,
199,
504,
18007,
14,
4209,
63,
2219,
14,
992,
492,
511,
63,
9968,
421,
199,
533,
23795,
8,
785,
304,
272,
408,
1451,
909,
3035,
314,
2058,
402,
282,
2849,
511,
1041,
339,
768,
4639,
272,
347,
14404,
8,
875,
304,
267,
372,
17572,
14,
3640,
8,
875,
9,
339,
347,
636,
826,
721,
277,
12,
511,
63,
354,
12,
9081,
29,
403,
12,
511,
63,
1065,
63,
521,
29,
403,
12,
965,
63,
3083,
29,
797,
12,
2984,
396,
63,
466,
29,
403,
12,
4422,
29,
403,
12,
6941,
29,
403,
304,
267,
291,
14,
396,
63,
354,
275,
511,
63,
354,
267,
291,
14,
9968,
275,
9081,
503,
942,
267,
291,
14,
396,
63,
1065,
63,
521,
275,
511,
63,
1065,
63,
521,
503,
378,
221,
327,
710,
900,
9394,
370,
5341,
314,
511,
6337,
14,
267,
291,
14,
1989,
63,
3083,
275,
965,
63,
3083,
267,
291,
14,
30155,
63,
466,
275,
2984,
396,
63,
466,
503,
942,
267,
291,
14,
3150,
275,
4422,
267,
291,
14,
12635,
275,
6941,
503,
942,
398,
327,
7600,
26,
13510,
642,
315,
314,
3787,
7704,
642,
1021,
7508,
370,
31173,
14,
267,
291,
14,
466,
275,
511,
63,
9968,
14,
22189,
63,
1099,
63,
466,
8,
9968,
9,
398,
327,
5723,
787,
663,
701,
314,
7239,
12,
440,
701,
314,
5253,
12,
880,
2985,
787,
440,
3032,
370,
314,
3787,
14,
267,
291,
14,
6599,
63,
354,
275,
2125,
267,
291,
14,
10810,
63,
354,
275,
2125,
267,
291,
14,
2923,
63,
1065,
63,
521,
275,
378,
221,
327,
710,
900,
9394,
370,
1255,
314,
511,
12254,
1263,
6941,
12,
4526,
14981,
12,
5423,
14,
267,
291,
14,
396,
63,
1955,
275,
488,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
334,
277,
14,
396,
63,
354,
508,
1163,
14,
396,
63,
354,
436,
355,
291,
14,
9968,
508,
1163,
14,
9968,
436,
355,
291,
14,
396,
63,
1065,
63,
521,
508,
1163,
14,
396,
63,
1065,
63,
521,
9,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
334,
277,
508,
1163,
9,
339,
347,
965,
63,
5328,
63,
9467,
63,
1313,
8,
277,
12,
627,
5328,
63,
2888,
304,
267,
367,
5988,
315,
291,
14,
9968,
26,
288,
340,
730,
8,
5328,
9,
315,
5988,
63,
2888,
26,
355,
372,
715,
267,
372,
756,
339,
347,
16864,
8,
277,
304,
267,
372,
17572,
14,
4180,
8,
277,
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
] |
[
1898,
334,
35,
9,
7129,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
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,
646,
17572,
199,
199,
504,
18007,
14,
4209,
63,
2219,
14,
992,
492,
511,
63,
9968,
421,
199,
533,
23795,
8,
785,
304,
272,
408,
1451,
909,
3035,
314,
2058,
402,
282,
2849,
511,
1041,
339,
768,
4639,
272,
347,
14404,
8,
875,
304,
267,
372,
17572,
14,
3640,
8,
875,
9,
339,
347,
636,
826,
721,
277,
12,
511,
63,
354,
12,
9081,
29,
403,
12,
511,
63,
1065,
63,
521,
29,
403,
12,
965,
63,
3083,
29,
797,
12,
2984,
396,
63,
466,
29,
403,
12,
4422,
29,
403,
12,
6941,
29,
403,
304,
267,
291,
14,
396,
63,
354,
275,
511,
63,
354,
267,
291,
14,
9968,
275,
9081,
503,
942,
267,
291,
14,
396,
63,
1065,
63,
521,
275,
511,
63,
1065,
63,
521,
503,
378,
221,
327,
710,
900,
9394,
370,
5341,
314,
511,
6337,
14,
267,
291,
14,
1989,
63,
3083,
275,
965,
63,
3083,
267,
291,
14,
30155,
63,
466,
275,
2984,
396,
63,
466,
503,
942,
267,
291,
14,
3150,
275,
4422,
267,
291,
14,
12635,
275,
6941,
503,
942,
398,
327,
7600,
26,
13510,
642,
315,
314,
3787,
7704,
642,
1021,
7508,
370,
31173,
14,
267,
291,
14,
466,
275,
511,
63,
9968,
14,
22189,
63,
1099,
63,
466,
8,
9968,
9,
398,
327,
5723,
787,
663,
701,
314,
7239,
12,
440,
701,
314,
5253,
12,
880,
2985,
787,
440,
3032,
370,
314,
3787,
14,
267,
291,
14,
6599,
63,
354,
275,
2125,
267,
291,
14,
10810,
63,
354,
275,
2125,
267,
291,
14,
2923,
63,
1065,
63,
521,
275,
378,
221,
327,
710,
900,
9394,
370,
1255,
314,
511,
12254,
1263,
6941,
12,
4526,
14981,
12,
5423,
14,
267,
291,
14,
396,
63,
1955,
275,
488,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
334,
277,
14,
396,
63,
354,
508,
1163,
14,
396,
63,
354,
436,
355,
291,
14,
9968,
508,
1163,
14,
9968,
436,
355,
291,
14,
396,
63,
1065,
63,
521,
508,
1163,
14,
396,
63,
1065,
63,
521,
9,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
334,
277,
508,
1163,
9,
339,
347,
965,
63,
5328,
63,
9467,
63,
1313,
8,
277,
12,
627,
5328,
63,
2888,
304,
267,
367,
5988,
315,
291,
14,
9968,
26,
288,
340,
730,
8,
5328,
9,
315,
5988,
63,
2888,
26,
355,
372,
715,
267,
372,
756,
339,
347,
16864,
8,
277,
304,
267,
372,
17572,
14,
4180,
8,
277,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lyw07/kolibri
|
kolibri/core/logger/api.py
|
2
|
10012
|
import logging
from django.core.exceptions import ObjectDoesNotExist
from django.db.models.query import F
from django.db.utils import IntegrityError
from django.http import Http404
from django_filters import ModelChoiceFilter
from django_filters.rest_framework import CharFilter
from django_filters.rest_framework import DjangoFilterBackend
from django_filters.rest_framework import FilterSet
from rest_framework import filters
from rest_framework import status
from rest_framework import viewsets
from rest_framework.exceptions import ValidationError
from rest_framework.response import Response
from .models import AttemptLog
from .models import ContentSessionLog
from .models import ContentSummaryLog
from .models import ExamAttemptLog
from .models import ExamLog
from .models import MasteryLog
from .models import UserSessionLog
from .permissions import ExamActivePermissions
from .serializers import AttemptLogSerializer
from .serializers import ContentSessionLogSerializer
from .serializers import ContentSummaryLogSerializer
from .serializers import ExamAttemptLogSerializer
from .serializers import ExamLogSerializer
from .serializers import MasteryLogSerializer
from .serializers import TotalContentProgressSerializer
from .serializers import UserSessionLogSerializer
from kolibri.core.auth.api import KolibriAuthPermissions
from kolibri.core.auth.api import KolibriAuthPermissionsFilter
from kolibri.core.auth.filters import HierarchyRelationsFilter
from kolibri.core.auth.models import Classroom
from kolibri.core.auth.models import Collection
from kolibri.core.auth.models import Facility
from kolibri.core.auth.models import FacilityUser
from kolibri.core.auth.models import LearnerGroup
from kolibri.core.content.api import OptionalPageNumberPagination
from kolibri.core.exams.models import Exam
logger = logging.getLogger(__name__)
class BaseLogFilter(FilterSet):
facility = ModelChoiceFilter(
method="filter_facility", queryset=Facility.objects.all()
)
classroom = ModelChoiceFilter(
method="filter_classroom", queryset=Classroom.objects.all()
)
learner_group = ModelChoiceFilter(
method="filter_learner_group", queryset=LearnerGroup.objects.all()
)
# Only a superuser can filter by facilities
def filter_facility(self, queryset, name, value):
return queryset.filter(user__facility=value)
def filter_classroom(self, queryset, name, value):
return HierarchyRelationsFilter(queryset).filter_by_hierarchy(
ancestor_collection=value, target_user=F("user")
)
def filter_learner_group(self, queryset, name, value):
return HierarchyRelationsFilter(queryset).filter_by_hierarchy(
ancestor_collection=value, target_user=F("user")
)
class LoggerViewSet(viewsets.ModelViewSet):
def update(self, request, *args, **kwargs):
partial = kwargs.pop("partial", False)
model = self.queryset.model
lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
try:
instance = model.objects.get(id=self.kwargs[lookup_url_kwarg])
self.check_object_permissions(request, instance)
except (ValueError, ObjectDoesNotExist):
raise Http404
serializer = self.get_serializer(instance, data=request.data, partial=partial)
serializer.is_valid(raise_exception=True)
self.perform_update(serializer)
if getattr(instance, "_prefetched_objects_cache", None):
# If 'prefetch_related' has been applied to a queryset, we need to
# forcibly invalidate the prefetch cache on the instance.
instance._prefetched_objects_cache = {}
default_response = dict(request.data)
# First look if the computed fields to be updated are listed:
updating_fields = getattr(serializer.root, "update_fields", None)
# If not, fetch all the fields that are computed methods:
if updating_fields is None:
updating_fields = [
field
for field in serializer.fields
if getattr(serializer.fields[field], "method_name", None)
]
for field in updating_fields:
method_name = getattr(serializer.fields[field], "method_name", None)
if method_name:
method = getattr(serializer.root, method_name)
default_response[field] = method(instance)
return Response(default_response)
def create(self, request, *args, **kwargs):
try:
return super(LoggerViewSet, self).create(request, *args, **kwargs)
except IntegrityError:
# The object has been created previously: let's calculate its id and return it
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
obj = serializer.Meta.model(**serializer.validated_data)
obj.id = obj.calculate_uuid()
final_obj = self.get_serializer(obj)
return Response(final_obj.data)
except ValidationError as e:
logger.error("Failed to validate data: {}".format(e))
return Response(request.data, status.HTTP_400_BAD_REQUEST)
class ContentSessionLogFilter(BaseLogFilter):
class Meta:
model = ContentSessionLog
fields = ["user_id", "content_id"]
class ContentSessionLogViewSet(LoggerViewSet):
permission_classes = (KolibriAuthPermissions,)
filter_backends = (KolibriAuthPermissionsFilter, DjangoFilterBackend)
queryset = ContentSessionLog.objects.all()
serializer_class = ContentSessionLogSerializer
pagination_class = OptionalPageNumberPagination
filter_class = ContentSessionLogFilter
class ContentSummaryLogFilter(BaseLogFilter):
class Meta:
model = ContentSummaryLog
fields = ["user_id", "content_id"]
class ContentSummaryLogViewSet(LoggerViewSet):
permission_classes = (KolibriAuthPermissions,)
filter_backends = (KolibriAuthPermissionsFilter, DjangoFilterBackend)
queryset = ContentSummaryLog.objects.all()
serializer_class = ContentSummaryLogSerializer
pagination_class = OptionalPageNumberPagination
filter_class = ContentSummaryLogFilter
class TotalContentProgressViewSet(viewsets.ModelViewSet):
permission_classes = (KolibriAuthPermissions,)
filter_backends = (KolibriAuthPermissionsFilter,)
queryset = FacilityUser.objects.all()
serializer_class = TotalContentProgressSerializer
class UserSessionLogFilter(BaseLogFilter):
class Meta:
model = UserSessionLog
fields = ["user_id"]
class UserSessionLogViewSet(LoggerViewSet):
permission_classes = (KolibriAuthPermissions,)
filter_backends = (KolibriAuthPermissionsFilter, DjangoFilterBackend)
queryset = UserSessionLog.objects.all()
serializer_class = UserSessionLogSerializer
pagination_class = OptionalPageNumberPagination
filter_class = UserSessionLogFilter
class MasteryFilter(FilterSet):
class Meta:
model = MasteryLog
fields = ["summarylog"]
class MasteryLogViewSet(LoggerViewSet):
permission_classes = (KolibriAuthPermissions,)
filter_backends = (KolibriAuthPermissionsFilter, DjangoFilterBackend)
queryset = MasteryLog.objects.all()
serializer_class = MasteryLogSerializer
pagination_class = OptionalPageNumberPagination
filter_class = MasteryFilter
class AttemptFilter(BaseLogFilter):
content = CharFilter(method="filter_content")
def filter_content(self, queryset, name, value):
return queryset.filter(masterylog__summarylog__content_id=value)
class Meta:
model = AttemptLog
fields = ["masterylog", "complete", "user", "content", "item"]
class AttemptLogViewSet(LoggerViewSet):
permission_classes = (KolibriAuthPermissions,)
filter_backends = (
KolibriAuthPermissionsFilter,
DjangoFilterBackend,
filters.OrderingFilter,
)
queryset = AttemptLog.objects.all()
serializer_class = AttemptLogSerializer
pagination_class = OptionalPageNumberPagination
filter_class = AttemptFilter
ordering_fields = ("end_timestamp",)
ordering = ("end_timestamp",)
class ExamAttemptFilter(BaseLogFilter):
exam = ModelChoiceFilter(method="filter_exam", queryset=Exam.objects.all())
user = ModelChoiceFilter(method="filter_user", queryset=FacilityUser.objects.all())
content = CharFilter(field_name="content_id")
def filter_exam(self, queryset, name, value):
return queryset.filter(examlog__exam=value)
def filter_user(self, queryset, name, value):
return queryset.filter(examlog__user=value)
class Meta:
model = ExamAttemptLog
fields = ["examlog", "exam", "user", "content", "item"]
class ExamAttemptLogViewSet(LoggerViewSet):
permission_classes = (ExamActivePermissions, KolibriAuthPermissions)
filter_backends = (
KolibriAuthPermissionsFilter,
DjangoFilterBackend,
filters.OrderingFilter,
)
queryset = ExamAttemptLog.objects.all()
serializer_class = ExamAttemptLogSerializer
pagination_class = OptionalPageNumberPagination
filter_class = ExamAttemptFilter
class ExamLogFilter(BaseLogFilter):
collection = ModelChoiceFilter(
method="filter_collection", queryset=Collection.objects.all()
)
def filter_collection(self, queryset, name, collection):
return HierarchyRelationsFilter(queryset).filter_by_hierarchy(
target_user=F("user"), ancestor_collection=collection
)
class Meta:
model = ExamLog
fields = ["user", "exam"]
class ExamLogViewSet(viewsets.ModelViewSet):
permission_classes = (KolibriAuthPermissions,)
filter_backends = (KolibriAuthPermissionsFilter, DjangoFilterBackend)
queryset = ExamLog.objects.all()
serializer_class = ExamLogSerializer
pagination_class = OptionalPageNumberPagination
filter_class = ExamLogFilter
|
mit
|
[
646,
2050,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
199,
504,
1639,
14,
697,
14,
992,
14,
1131,
492,
481,
199,
504,
1639,
14,
697,
14,
1208,
492,
26864,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
504,
1639,
63,
4273,
492,
5822,
9054,
4131,
199,
504,
1639,
63,
4273,
14,
3911,
63,
4857,
492,
6659,
4131,
199,
504,
1639,
63,
4273,
14,
3911,
63,
4857,
492,
5634,
4131,
8447,
199,
504,
1639,
63,
4273,
14,
3911,
63,
4857,
492,
9388,
1084,
199,
504,
4618,
63,
4857,
492,
4766,
199,
504,
4618,
63,
4857,
492,
2004,
199,
504,
4618,
63,
4857,
492,
2455,
2193,
199,
504,
4618,
63,
4857,
14,
3924,
492,
8505,
199,
504,
4618,
63,
4857,
14,
1310,
492,
7232,
199,
199,
504,
1275,
992,
492,
23115,
2445,
199,
504,
1275,
992,
492,
6646,
4434,
2445,
199,
504,
1275,
992,
492,
6646,
10407,
2445,
199,
504,
1275,
992,
492,
1316,
455,
23272,
2445,
199,
504,
1275,
992,
492,
1316,
455,
2445,
199,
504,
1275,
992,
492,
26728,
89,
2445,
199,
504,
1275,
992,
492,
2876,
4434,
2445,
199,
504,
1275,
6060,
492,
1316,
455,
7472,
17004,
199,
504,
1275,
12844,
492,
23115,
2445,
7299,
199,
504,
1275,
12844,
492,
6646,
4434,
2445,
7299,
199,
504,
1275,
12844,
492,
6646,
10407,
2445,
7299,
199,
504,
1275,
12844,
492,
1316,
455,
23272,
2445,
7299,
199,
504,
1275,
12844,
492,
1316,
455,
2445,
7299,
199,
504,
1275,
12844,
492,
26728,
89,
2445,
7299,
199,
504,
1275,
12844,
492,
19271,
2714,
11504,
7299,
199,
504,
1275,
12844,
492,
2876,
4434,
2445,
7299,
199,
504,
20817,
773,
322,
14,
1018,
14,
1178,
14,
1246,
492,
1804,
79,
773,
322,
2817,
17004,
199,
504,
20817,
773,
322,
14,
1018,
14,
1178,
14,
1246,
492,
1804,
79,
773,
322,
2817,
17004,
4131,
199,
504,
20817,
773,
322,
14,
1018,
14,
1178,
14,
4273,
492,
869,
8641,
5640,
1298,
4131,
199,
504,
20817,
773,
322,
14,
1018,
14,
1178,
14,
992,
492,
8089,
11245,
199,
504,
20817,
773,
322,
14,
1018,
14,
1178,
14,
992,
492,
18003,
199,
504,
20817,
773,
322,
14,
1018,
14,
1178,
14,
992,
492,
10859,
12498,
199,
504,
20817,
773,
322,
14,
1018,
14,
1178,
14,
992,
492,
10859,
12498,
1899,
199,
504,
20817,
773,
322,
14,
1018,
14,
1178,
14,
992,
492,
7005,
1060,
281,
2448,
199,
504,
20817,
773,
322,
14,
1018,
14,
1317,
14,
1246,
492,
4879,
3276,
3259,
23862,
3155,
199,
504,
20817,
773,
322,
14,
1018,
14,
15425,
83,
14,
992,
492,
1316,
455,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
3523,
2445,
4131,
8,
4131,
1084,
304,
272,
21395,
275,
5822,
9054,
4131,
8,
267,
1083,
628,
1541,
63,
22354,
401,
7594,
29,
1906,
12498,
14,
1462,
14,
452,
342,
272,
776,
272,
1021,
11245,
275,
5822,
9054,
4131,
8,
267,
1083,
628,
1541,
63,
533,
11245,
401,
7594,
29,
2543,
11245,
14,
1462,
14,
452,
342,
272,
776,
272,
22876,
63,
923,
275,
5822,
9054,
4131,
8,
267,
1083,
628,
1541,
63,
29144,
63,
923,
401,
7594,
29,
21424,
281,
2448,
14,
1462,
14,
452,
342,
272,
776,
339,
327,
5972,
282,
32590,
883,
2457,
701,
30242,
7999,
272,
347,
2457,
63,
22354,
8,
277,
12,
7594,
12,
536,
12,
574,
304,
267,
372,
7594,
14,
1541,
8,
751,
363,
22354,
29,
585,
9,
339,
347,
2457,
63,
533,
11245,
8,
277,
12,
7594,
12,
536,
12,
574,
304,
267,
372,
869,
8641,
5640,
1298,
4131,
8,
7924,
680,
1541,
63,
991,
63,
14861,
8,
288,
18432,
63,
3627,
29,
585,
12,
1347,
63,
751,
29,
38,
480,
751,
531,
267,
776,
339,
347,
2457,
63,
29144,
63,
923,
8,
277,
12,
7594,
12,
536,
12,
574,
304,
267,
372,
869,
8641,
5640,
1298,
4131,
8,
7924,
680,
1541,
63,
991,
63,
14861,
8,
288,
18432,
63,
3627,
29,
585,
12,
1347,
63,
751,
29,
38,
480,
751,
531,
267,
776,
421,
199,
533,
15996,
21902,
8,
1345,
2193,
14,
1685,
21902,
304,
272,
347,
1678,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
7417,
275,
2074,
14,
1935,
480,
6672,
401,
756,
9,
267,
1402,
275,
291,
14,
7924,
14,
1238,
267,
4237,
63,
633,
63,
12745,
275,
291,
14,
3892,
63,
633,
63,
12745,
503,
291,
14,
3892,
63,
698,
267,
862,
26,
288,
1256,
275,
1402,
14,
1462,
14,
362,
8,
344,
29,
277,
14,
958,
59,
3892,
63,
633,
63,
12745,
566,
288,
291,
14,
1074,
63,
785,
63,
6060,
8,
1069,
12,
1256,
9,
267,
871,
334,
3393,
12,
24803,
304,
288,
746,
4760,
5188,
267,
9146,
275,
291,
14,
362,
63,
8349,
8,
842,
12,
666,
29,
1069,
14,
576,
12,
7417,
29,
6672,
9,
267,
9146,
14,
374,
63,
1078,
8,
3730,
63,
1971,
29,
549,
9,
267,
291,
14,
15795,
63,
873,
8,
8349,
9,
398,
340,
2519,
8,
842,
12,
2668,
13829,
13534,
63,
1462,
63,
1637,
401,
488,
304,
288,
327,
982,
283,
15576,
63,
2407,
7,
965,
2757,
6781,
370,
282,
7594,
12,
781,
1929,
370,
288,
327,
367,
559,
66,
590,
24841,
314,
21544,
2581,
641,
314,
1256,
14,
288,
1256,
423,
13829,
13534,
63,
1462,
63,
1637,
275,
1052,
267,
849,
63,
1310,
275,
1211,
8,
1069,
14,
576,
9,
267,
327,
7758,
3648,
340,
314,
9235,
1504,
370,
506,
4588,
787,
10532,
26,
267,
12928,
63,
955,
275,
2519,
8,
8349,
14,
1231,
12,
298,
873,
63,
955,
401,
488,
9,
267,
327,
982,
440,
12,
5267,
1006,
314,
1504,
626,
787,
9235,
3102,
26,
267,
340,
12928,
63,
955,
365,
488,
26,
288,
12928,
63,
955,
275,
359,
355,
901,
355,
367,
901,
315,
9146,
14,
955,
355,
340,
2519,
8,
8349,
14,
955,
59,
698,
467,
298,
765,
63,
354,
401,
488,
9,
288,
1622,
267,
367,
901,
315,
12928,
63,
955,
26,
288,
1083,
63,
354,
275,
2519,
8,
8349,
14,
955,
59,
698,
467,
298,
765,
63,
354,
401,
488,
9,
288,
340,
1083,
63,
354,
26,
355,
1083,
275,
2519,
8,
8349,
14,
1231,
12,
1083,
63,
354,
9,
355,
849,
63,
1310,
59,
698
] |
[
2050,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
199,
504,
1639,
14,
697,
14,
992,
14,
1131,
492,
481,
199,
504,
1639,
14,
697,
14,
1208,
492,
26864,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
504,
1639,
63,
4273,
492,
5822,
9054,
4131,
199,
504,
1639,
63,
4273,
14,
3911,
63,
4857,
492,
6659,
4131,
199,
504,
1639,
63,
4273,
14,
3911,
63,
4857,
492,
5634,
4131,
8447,
199,
504,
1639,
63,
4273,
14,
3911,
63,
4857,
492,
9388,
1084,
199,
504,
4618,
63,
4857,
492,
4766,
199,
504,
4618,
63,
4857,
492,
2004,
199,
504,
4618,
63,
4857,
492,
2455,
2193,
199,
504,
4618,
63,
4857,
14,
3924,
492,
8505,
199,
504,
4618,
63,
4857,
14,
1310,
492,
7232,
199,
199,
504,
1275,
992,
492,
23115,
2445,
199,
504,
1275,
992,
492,
6646,
4434,
2445,
199,
504,
1275,
992,
492,
6646,
10407,
2445,
199,
504,
1275,
992,
492,
1316,
455,
23272,
2445,
199,
504,
1275,
992,
492,
1316,
455,
2445,
199,
504,
1275,
992,
492,
26728,
89,
2445,
199,
504,
1275,
992,
492,
2876,
4434,
2445,
199,
504,
1275,
6060,
492,
1316,
455,
7472,
17004,
199,
504,
1275,
12844,
492,
23115,
2445,
7299,
199,
504,
1275,
12844,
492,
6646,
4434,
2445,
7299,
199,
504,
1275,
12844,
492,
6646,
10407,
2445,
7299,
199,
504,
1275,
12844,
492,
1316,
455,
23272,
2445,
7299,
199,
504,
1275,
12844,
492,
1316,
455,
2445,
7299,
199,
504,
1275,
12844,
492,
26728,
89,
2445,
7299,
199,
504,
1275,
12844,
492,
19271,
2714,
11504,
7299,
199,
504,
1275,
12844,
492,
2876,
4434,
2445,
7299,
199,
504,
20817,
773,
322,
14,
1018,
14,
1178,
14,
1246,
492,
1804,
79,
773,
322,
2817,
17004,
199,
504,
20817,
773,
322,
14,
1018,
14,
1178,
14,
1246,
492,
1804,
79,
773,
322,
2817,
17004,
4131,
199,
504,
20817,
773,
322,
14,
1018,
14,
1178,
14,
4273,
492,
869,
8641,
5640,
1298,
4131,
199,
504,
20817,
773,
322,
14,
1018,
14,
1178,
14,
992,
492,
8089,
11245,
199,
504,
20817,
773,
322,
14,
1018,
14,
1178,
14,
992,
492,
18003,
199,
504,
20817,
773,
322,
14,
1018,
14,
1178,
14,
992,
492,
10859,
12498,
199,
504,
20817,
773,
322,
14,
1018,
14,
1178,
14,
992,
492,
10859,
12498,
1899,
199,
504,
20817,
773,
322,
14,
1018,
14,
1178,
14,
992,
492,
7005,
1060,
281,
2448,
199,
504,
20817,
773,
322,
14,
1018,
14,
1317,
14,
1246,
492,
4879,
3276,
3259,
23862,
3155,
199,
504,
20817,
773,
322,
14,
1018,
14,
15425,
83,
14,
992,
492,
1316,
455,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
3523,
2445,
4131,
8,
4131,
1084,
304,
272,
21395,
275,
5822,
9054,
4131,
8,
267,
1083,
628,
1541,
63,
22354,
401,
7594,
29,
1906,
12498,
14,
1462,
14,
452,
342,
272,
776,
272,
1021,
11245,
275,
5822,
9054,
4131,
8,
267,
1083,
628,
1541,
63,
533,
11245,
401,
7594,
29,
2543,
11245,
14,
1462,
14,
452,
342,
272,
776,
272,
22876,
63,
923,
275,
5822,
9054,
4131,
8,
267,
1083,
628,
1541,
63,
29144,
63,
923,
401,
7594,
29,
21424,
281,
2448,
14,
1462,
14,
452,
342,
272,
776,
339,
327,
5972,
282,
32590,
883,
2457,
701,
30242,
7999,
272,
347,
2457,
63,
22354,
8,
277,
12,
7594,
12,
536,
12,
574,
304,
267,
372,
7594,
14,
1541,
8,
751,
363,
22354,
29,
585,
9,
339,
347,
2457,
63,
533,
11245,
8,
277,
12,
7594,
12,
536,
12,
574,
304,
267,
372,
869,
8641,
5640,
1298,
4131,
8,
7924,
680,
1541,
63,
991,
63,
14861,
8,
288,
18432,
63,
3627,
29,
585,
12,
1347,
63,
751,
29,
38,
480,
751,
531,
267,
776,
339,
347,
2457,
63,
29144,
63,
923,
8,
277,
12,
7594,
12,
536,
12,
574,
304,
267,
372,
869,
8641,
5640,
1298,
4131,
8,
7924,
680,
1541,
63,
991,
63,
14861,
8,
288,
18432,
63,
3627,
29,
585,
12,
1347,
63,
751,
29,
38,
480,
751,
531,
267,
776,
421,
199,
533,
15996,
21902,
8,
1345,
2193,
14,
1685,
21902,
304,
272,
347,
1678,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
7417,
275,
2074,
14,
1935,
480,
6672,
401,
756,
9,
267,
1402,
275,
291,
14,
7924,
14,
1238,
267,
4237,
63,
633,
63,
12745,
275,
291,
14,
3892,
63,
633,
63,
12745,
503,
291,
14,
3892,
63,
698,
267,
862,
26,
288,
1256,
275,
1402,
14,
1462,
14,
362,
8,
344,
29,
277,
14,
958,
59,
3892,
63,
633,
63,
12745,
566,
288,
291,
14,
1074,
63,
785,
63,
6060,
8,
1069,
12,
1256,
9,
267,
871,
334,
3393,
12,
24803,
304,
288,
746,
4760,
5188,
267,
9146,
275,
291,
14,
362,
63,
8349,
8,
842,
12,
666,
29,
1069,
14,
576,
12,
7417,
29,
6672,
9,
267,
9146,
14,
374,
63,
1078,
8,
3730,
63,
1971,
29,
549,
9,
267,
291,
14,
15795,
63,
873,
8,
8349,
9,
398,
340,
2519,
8,
842,
12,
2668,
13829,
13534,
63,
1462,
63,
1637,
401,
488,
304,
288,
327,
982,
283,
15576,
63,
2407,
7,
965,
2757,
6781,
370,
282,
7594,
12,
781,
1929,
370,
288,
327,
367,
559,
66,
590,
24841,
314,
21544,
2581,
641,
314,
1256,
14,
288,
1256,
423,
13829,
13534,
63,
1462,
63,
1637,
275,
1052,
267,
849,
63,
1310,
275,
1211,
8,
1069,
14,
576,
9,
267,
327,
7758,
3648,
340,
314,
9235,
1504,
370,
506,
4588,
787,
10532,
26,
267,
12928,
63,
955,
275,
2519,
8,
8349,
14,
1231,
12,
298,
873,
63,
955,
401,
488,
9,
267,
327,
982,
440,
12,
5267,
1006,
314,
1504,
626,
787,
9235,
3102,
26,
267,
340,
12928,
63,
955,
365,
488,
26,
288,
12928,
63,
955,
275,
359,
355,
901,
355,
367,
901,
315,
9146,
14,
955,
355,
340,
2519,
8,
8349,
14,
955,
59,
698,
467,
298,
765,
63,
354,
401,
488,
9,
288,
1622,
267,
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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mKeRix/home-assistant
|
homeassistant/components/upcloud/switch.py
|
7
|
1281
|
"""Support for interacting with UpCloud servers."""
import logging
import voluptuous as vol
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
from homeassistant.const import STATE_OFF
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import dispatcher_send
from . import CONF_SERVERS, DATA_UPCLOUD, SIGNAL_UPDATE_UPCLOUD, UpCloudServerEntity
_LOGGER = logging.getLogger(__name__)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{vol.Required(CONF_SERVERS): vol.All(cv.ensure_list, [cv.string])}
)
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the UpCloud server switch."""
upcloud = hass.data[DATA_UPCLOUD]
servers = config.get(CONF_SERVERS)
devices = [UpCloudSwitch(upcloud, uuid) for uuid in servers]
add_entities(devices, True)
class UpCloudSwitch(UpCloudServerEntity, SwitchEntity):
"""Representation of an UpCloud server switch."""
def turn_on(self, **kwargs):
"""Start the server."""
if self.state == STATE_OFF:
self.data.start()
dispatcher_send(self.hass, SIGNAL_UPDATE_UPCLOUD)
def turn_off(self, **kwargs):
"""Stop the server."""
if self.is_on:
self.data.stop()
|
mit
|
[
624,
11532,
367,
17232,
316,
543,
4949,
9089,
8037,
1041,
199,
646,
2050,
199,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
4608,
14,
5656,
492,
21966,
63,
10926,
12,
17711,
7302,
199,
504,
8846,
14,
1297,
492,
11377,
63,
7517,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
504,
8846,
14,
7546,
14,
14913,
492,
17475,
63,
2254,
199,
199,
504,
1275,
492,
6392,
63,
6613,
51,
12,
7126,
63,
2160,
29495,
12,
24360,
63,
10383,
63,
2160,
29495,
12,
4949,
9089,
3120,
7302,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
8,
272,
469,
5650,
14,
8030,
8,
3103,
63,
6613,
51,
304,
5236,
14,
2422,
8,
5107,
14,
7505,
63,
513,
12,
359,
5107,
14,
875,
566,
93,
199,
9,
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,
4949,
9089,
1654,
6258,
1041,
272,
1536,
4091,
275,
6298,
14,
576,
59,
3998,
63,
2160,
29495,
61,
339,
8037,
275,
1101,
14,
362,
8,
3103,
63,
6613,
51,
9,
339,
7256,
275,
359,
1721,
9089,
10167,
8,
384,
4091,
12,
5377,
9,
367,
5377,
315,
8037,
61,
339,
1050,
63,
8327,
8,
6410,
12,
715,
9,
421,
199,
533,
4949,
9089,
10167,
8,
1721,
9089,
3120,
7302,
12,
17711,
7302,
304,
272,
408,
20609,
402,
376,
4949,
9089,
1654,
6258,
1041,
339,
347,
7485,
63,
265,
8,
277,
12,
1011,
958,
304,
267,
408,
3162,
314,
1654,
1041,
267,
340,
291,
14,
929,
508,
11377,
63,
7517,
26,
288,
291,
14,
576,
14,
928,
342,
288,
17475,
63,
2254,
8,
277,
14,
5387,
12,
24360,
63,
10383,
63,
2160,
29495,
9,
339,
347,
7485,
63,
1997,
8,
277,
12,
1011,
958,
304,
267,
408,
6293,
314,
1654,
1041,
267,
340,
291,
14,
374,
63,
265,
26,
288,
291,
14,
576,
14,
2379,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
11532,
367,
17232,
316,
543,
4949,
9089,
8037,
1041,
199,
646,
2050,
199,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
4608,
14,
5656,
492,
21966,
63,
10926,
12,
17711,
7302,
199,
504,
8846,
14,
1297,
492,
11377,
63,
7517,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
504,
8846,
14,
7546,
14,
14913,
492,
17475,
63,
2254,
199,
199,
504,
1275,
492,
6392,
63,
6613,
51,
12,
7126,
63,
2160,
29495,
12,
24360,
63,
10383,
63,
2160,
29495,
12,
4949,
9089,
3120,
7302,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
8,
272,
469,
5650,
14,
8030,
8,
3103,
63,
6613,
51,
304,
5236,
14,
2422,
8,
5107,
14,
7505,
63,
513,
12,
359,
5107,
14,
875,
566,
93,
199,
9,
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,
4949,
9089,
1654,
6258,
1041,
272,
1536,
4091,
275,
6298,
14,
576,
59,
3998,
63,
2160,
29495,
61,
339,
8037,
275,
1101,
14,
362,
8,
3103,
63,
6613,
51,
9,
339,
7256,
275,
359,
1721,
9089,
10167,
8,
384,
4091,
12,
5377,
9,
367,
5377,
315,
8037,
61,
339,
1050,
63,
8327,
8,
6410,
12,
715,
9,
421,
199,
533,
4949,
9089,
10167,
8,
1721,
9089,
3120,
7302,
12,
17711,
7302,
304,
272,
408,
20609,
402,
376,
4949,
9089,
1654,
6258,
1041,
339,
347,
7485,
63,
265,
8,
277,
12,
1011,
958,
304,
267,
408,
3162,
314,
1654,
1041,
267,
340,
291,
14,
929,
508,
11377,
63,
7517,
26,
288,
291,
14,
576,
14,
928,
342,
288,
17475,
63,
2254,
8,
277,
14,
5387,
12,
24360,
63,
10383,
63,
2160,
29495,
9,
339,
347,
7485,
63,
1997,
8,
277,
12,
1011,
958,
304,
267,
408,
6293,
314,
1654,
1041,
267,
340,
291,
14,
374,
63,
265,
26,
288,
291,
14,
576,
14,
2379,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
talishte/ctigre
|
env/lib/python2.7/site-packages/django/contrib/gis/geos/prototypes/prepared.py
|
623
|
1032
|
from ctypes import c_char
from django.contrib.gis.geos.libgeos import GEOM_PTR, PREPGEOM_PTR
from django.contrib.gis.geos.prototypes.errcheck import check_predicate
from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc
# Prepared geometry constructor and destructors.
geos_prepare = GEOSFunc('GEOSPrepare')
geos_prepare.argtypes = [GEOM_PTR]
geos_prepare.restype = PREPGEOM_PTR
prepared_destroy = GEOSFunc('GEOSPreparedGeom_destroy')
prepared_destroy.argtpes = [PREPGEOM_PTR]
prepared_destroy.restype = None
# Prepared geometry binary predicate support.
def prepared_predicate(func):
func.argtypes= [PREPGEOM_PTR, GEOM_PTR]
func.restype = c_char
func.errcheck = check_predicate
return func
prepared_contains = prepared_predicate(GEOSFunc('GEOSPreparedContains'))
prepared_contains_properly = prepared_predicate(GEOSFunc('GEOSPreparedContainsProperly'))
prepared_covers = prepared_predicate(GEOSFunc('GEOSPreparedCovers'))
prepared_intersects = prepared_predicate(GEOSFunc('GEOSPreparedIntersects'))
|
bsd-2-clause
|
[
504,
5577,
492,
286,
63,
1560,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
773,
12151,
492,
8991,
7474,
63,
14528,
12,
19924,
48,
31080,
63,
14528,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
16141,
83,
14,
21205,
492,
1104,
63,
14463,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
16141,
83,
14,
2671,
3489,
492,
11920,
7465,
199,
199,
3,
5543,
9508,
3400,
3787,
436,
32133,
83,
14,
199,
12151,
63,
6726,
275,
11920,
7465,
360,
14151,
22281,
358,
199,
12151,
63,
6726,
14,
10025,
275,
359,
31080,
63,
14528,
61,
199,
12151,
63,
6726,
14,
9990,
275,
19924,
48,
31080,
63,
14528,
199,
199,
19260,
63,
7237,
275,
11920,
7465,
360,
14151,
25634,
13427,
63,
7237,
358,
199,
19260,
63,
7237,
14,
1273,
84,
22020,
275,
359,
4225,
48,
31080,
63,
14528,
61,
199,
19260,
63,
7237,
14,
9990,
275,
488,
199,
199,
3,
5543,
9508,
3400,
3366,
11944,
2291,
14,
199,
318,
16318,
63,
14463,
8,
1532,
304,
272,
2562,
14,
10025,
29,
359,
4225,
48,
31080,
63,
14528,
12,
8991,
7474,
63,
14528,
61,
272,
2562,
14,
9990,
275,
286,
63,
1560,
272,
2562,
14,
21205,
275,
1104,
63,
14463,
272,
372,
2562,
199,
199,
19260,
63,
6134,
275,
16318,
63,
14463,
8,
31887,
360,
14151,
25634,
6906,
1333,
199,
19260,
63,
6134,
63,
28314,
590,
275,
16318,
63,
14463,
8,
31887,
360,
14151,
25634,
6906,
919,
529,
590,
1333,
199,
19260,
63,
5899,
83,
275,
16318,
63,
14463,
8,
31887,
360,
14151,
25634,
967,
14895,
1333,
199,
19260,
63,
1058,
25353,
275,
16318,
63,
14463,
8,
31887,
360,
14151,
25634,
2620,
25353,
1333,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
5577,
492,
286,
63,
1560,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
773,
12151,
492,
8991,
7474,
63,
14528,
12,
19924,
48,
31080,
63,
14528,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
16141,
83,
14,
21205,
492,
1104,
63,
14463,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
16141,
83,
14,
2671,
3489,
492,
11920,
7465,
199,
199,
3,
5543,
9508,
3400,
3787,
436,
32133,
83,
14,
199,
12151,
63,
6726,
275,
11920,
7465,
360,
14151,
22281,
358,
199,
12151,
63,
6726,
14,
10025,
275,
359,
31080,
63,
14528,
61,
199,
12151,
63,
6726,
14,
9990,
275,
19924,
48,
31080,
63,
14528,
199,
199,
19260,
63,
7237,
275,
11920,
7465,
360,
14151,
25634,
13427,
63,
7237,
358,
199,
19260,
63,
7237,
14,
1273,
84,
22020,
275,
359,
4225,
48,
31080,
63,
14528,
61,
199,
19260,
63,
7237,
14,
9990,
275,
488,
199,
199,
3,
5543,
9508,
3400,
3366,
11944,
2291,
14,
199,
318,
16318,
63,
14463,
8,
1532,
304,
272,
2562,
14,
10025,
29,
359,
4225,
48,
31080,
63,
14528,
12,
8991,
7474,
63,
14528,
61,
272,
2562,
14,
9990,
275,
286,
63,
1560,
272,
2562,
14,
21205,
275,
1104,
63,
14463,
272,
372,
2562,
199,
199,
19260,
63,
6134,
275,
16318,
63,
14463,
8,
31887,
360,
14151,
25634,
6906,
1333,
199,
19260,
63,
6134,
63,
28314,
590,
275,
16318,
63,
14463,
8,
31887,
360,
14151,
25634,
6906,
919,
529,
590,
1333,
199,
19260,
63,
5899,
83,
275,
16318,
63,
14463,
8,
31887,
360,
14151,
25634,
967,
14895,
1333,
199,
19260,
63,
1058,
25353,
275,
16318,
63,
14463,
8,
31887,
360,
14151,
25634,
2620,
25353,
1333,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
leonth/private-configs
|
sublime-text-3/Packages/Jedi - Python autocompletion/jedi/keywords.py
|
4
|
2217
|
from __future__ import with_statement
import pydoc
import keyword
from jedi._compatibility import is_py3k
from jedi.parser import representation as pr
from jedi import common
import builtin
try:
from pydoc_data import topics as pydoc_topics
except ImportError:
# Python 2.6
import pydoc_topics
if is_py3k:
keys = keyword.kwlist
else:
keys = keyword.kwlist + ['None', 'False', 'True']
def keywords(string='', pos=(0, 0), all=False):
if all:
return set([Keyword(k, pos) for k in keys])
if string in keys:
return set([Keyword(string, pos)])
return set()
def keyword_names(*args, **kwargs):
kwds = []
for k in keywords(*args, **kwargs):
start = k.start_pos
end = start[0], start[1] + len(k.name)
kwds.append(pr.Name(k.parent, [(k.name, start)], start, end, k))
return kwds
def get_operator(string, pos):
return Keyword(string, pos)
class Keyword(object):
def __init__(self, name, pos):
self.name = name
self.start_pos = pos
self.parent = builtin.Builtin.scope
def get_parent_until(self):
return self.parent
@property
def names(self):
""" For a `parsing.Name` like comparision """
return [self.name]
@property
def docstr(self):
return imitate_pydoc(self.name)
def __repr__(self):
return '<%s: %s>' % (type(self).__name__, self.name)
def imitate_pydoc(string):
"""
It's not possible to get the pydoc's without starting the annoying pager
stuff.
"""
# str needed because of possible unicode stuff in py2k (pydoc doesn't work
# with unicode strings)
string = str(string)
h = pydoc.help
with common.ignored(KeyError):
# try to access symbols
string = h.symbols[string]
string, _, related = string.partition(' ')
get_target = lambda s: h.topics.get(s, h.keywords.get(s))
while isinstance(string, str):
string = get_target(string)
try:
# is a tuple now
label, related = string
except TypeError:
return ''
try:
return pydoc_topics.topics[label] if pydoc_topics else ''
except KeyError:
return ''
|
mit
|
[
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
29164,
199,
646,
4252,
199,
199,
504,
1335,
6297,
423,
15390,
492,
365,
63,
647,
19,
75,
199,
504,
1335,
6297,
14,
2087,
492,
6025,
465,
5448,
199,
504,
1335,
6297,
492,
2863,
199,
646,
6762,
199,
199,
893,
26,
272,
687,
29164,
63,
576,
492,
17398,
465,
29164,
63,
11299,
199,
2590,
3545,
26,
272,
327,
2018,
499,
14,
22,
272,
492,
29164,
63,
11299,
199,
199,
692,
365,
63,
647,
19,
75,
26,
272,
2883,
275,
4252,
14,
829,
513,
199,
2836,
26,
272,
2883,
275,
4252,
14,
829,
513,
435,
788,
403,
297,
283,
797,
297,
283,
549,
418,
421,
199,
318,
7681,
8,
875,
4581,
2086,
2687,
16,
12,
378,
395,
1006,
29,
797,
304,
272,
340,
1006,
26,
267,
372,
663,
779,
10650,
8,
75,
12,
2086,
9,
367,
1022,
315,
2883,
566,
272,
340,
1059,
315,
2883,
26,
267,
372,
663,
779,
10650,
8,
875,
12,
2086,
3948,
272,
372,
663,
342,
421,
199,
318,
4252,
63,
1247,
2031,
589,
12,
1011,
958,
304,
272,
16286,
275,
942,
272,
367,
1022,
315,
7681,
2031,
589,
12,
1011,
958,
304,
267,
1343,
275,
1022,
14,
928,
63,
1712,
267,
1284,
275,
1343,
59,
16,
467,
1343,
59,
17,
61,
435,
822,
8,
75,
14,
354,
9,
267,
16286,
14,
740,
8,
2700,
14,
985,
8,
75,
14,
1708,
12,
3842,
75,
14,
354,
12,
1343,
4360,
1343,
12,
1284,
12,
1022,
430,
272,
372,
16286,
421,
199,
318,
664,
63,
3856,
8,
875,
12,
2086,
304,
272,
372,
6431,
8,
875,
12,
2086,
9,
421,
199,
533,
6431,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
2086,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
928,
63,
1712,
275,
2086,
267,
291,
14,
1708,
275,
6762,
14,
12306,
14,
2645,
339,
347,
664,
63,
1708,
63,
8111,
8,
277,
304,
267,
372,
291,
14,
1708,
339,
768,
1829,
272,
347,
1561,
8,
277,
304,
267,
408,
2104,
282,
658,
11059,
14,
985,
64,
2839,
1013,
759,
438,
408,
267,
372,
359,
277,
14,
354,
61,
339,
768,
1829,
272,
347,
1382,
495,
8,
277,
304,
267,
372,
284,
1147,
323,
63,
25048,
8,
277,
14,
354,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
18342,
83,
26,
450,
83,
3524,
450,
334,
466,
8,
277,
2843,
354,
3108,
291,
14,
354,
9,
421,
199,
318,
284,
1147,
323,
63,
25048,
8,
875,
304,
272,
408,
272,
2779,
1159,
440,
3962,
370,
664,
314,
29164,
1159,
1928,
6617,
314,
22984,
22440,
26581,
272,
8292,
14,
272,
408,
272,
327,
620,
4346,
2952,
402,
3962,
2649,
8292,
315,
1134,
18,
75,
334,
25048,
3181,
1133,
1736,
272,
327,
543,
2649,
3326,
9,
272,
1059,
275,
620,
8,
875,
9,
272,
394,
275,
29164,
14,
3437,
272,
543,
2863,
14,
11996,
8,
10230,
304,
267,
327,
862,
370,
2879,
6698,
267,
1059,
275,
394,
14,
7450,
59,
875,
61,
267,
1059,
12,
5501,
4048,
275,
1059,
14,
5312,
360,
5320,
339,
664,
63,
1375,
275,
2400,
308,
26,
394,
14,
11299,
14,
362,
8,
83,
12,
394,
14,
7511,
14,
362,
8,
83,
430,
272,
1830,
1228,
8,
875,
12,
620,
304,
267,
1059,
275,
664,
63,
1375,
8,
875,
9,
339,
862,
26,
267,
327,
365,
282,
2008,
3063,
267,
1768,
12,
4048,
275,
1059,
272,
871,
3146,
26,
267,
372,
2125,
339,
862,
26,
267,
372,
29164,
63,
11299,
14,
11299,
59,
1302,
61,
340,
29164,
63,
11299,
587,
2125,
272,
871,
4067,
26,
267,
372,
2125,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
543,
63,
6242,
199,
199,
646,
29164,
199,
646,
4252,
199,
199,
504,
1335,
6297,
423,
15390,
492,
365,
63,
647,
19,
75,
199,
504,
1335,
6297,
14,
2087,
492,
6025,
465,
5448,
199,
504,
1335,
6297,
492,
2863,
199,
646,
6762,
199,
199,
893,
26,
272,
687,
29164,
63,
576,
492,
17398,
465,
29164,
63,
11299,
199,
2590,
3545,
26,
272,
327,
2018,
499,
14,
22,
272,
492,
29164,
63,
11299,
199,
199,
692,
365,
63,
647,
19,
75,
26,
272,
2883,
275,
4252,
14,
829,
513,
199,
2836,
26,
272,
2883,
275,
4252,
14,
829,
513,
435,
788,
403,
297,
283,
797,
297,
283,
549,
418,
421,
199,
318,
7681,
8,
875,
4581,
2086,
2687,
16,
12,
378,
395,
1006,
29,
797,
304,
272,
340,
1006,
26,
267,
372,
663,
779,
10650,
8,
75,
12,
2086,
9,
367,
1022,
315,
2883,
566,
272,
340,
1059,
315,
2883,
26,
267,
372,
663,
779,
10650,
8,
875,
12,
2086,
3948,
272,
372,
663,
342,
421,
199,
318,
4252,
63,
1247,
2031,
589,
12,
1011,
958,
304,
272,
16286,
275,
942,
272,
367,
1022,
315,
7681,
2031,
589,
12,
1011,
958,
304,
267,
1343,
275,
1022,
14,
928,
63,
1712,
267,
1284,
275,
1343,
59,
16,
467,
1343,
59,
17,
61,
435,
822,
8,
75,
14,
354,
9,
267,
16286,
14,
740,
8,
2700,
14,
985,
8,
75,
14,
1708,
12,
3842,
75,
14,
354,
12,
1343,
4360,
1343,
12,
1284,
12,
1022,
430,
272,
372,
16286,
421,
199,
318,
664,
63,
3856,
8,
875,
12,
2086,
304,
272,
372,
6431,
8,
875,
12,
2086,
9,
421,
199,
533,
6431,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
2086,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
928,
63,
1712,
275,
2086,
267,
291,
14,
1708,
275,
6762,
14,
12306,
14,
2645,
339,
347,
664,
63,
1708,
63,
8111,
8,
277,
304,
267,
372,
291,
14,
1708,
339,
768,
1829,
272,
347,
1561,
8,
277,
304,
267,
408,
2104,
282,
658,
11059,
14,
985,
64,
2839,
1013,
759,
438,
408,
267,
372,
359,
277,
14,
354,
61,
339,
768,
1829,
272,
347,
1382,
495,
8,
277,
304,
267,
372,
284,
1147,
323,
63,
25048,
8,
277,
14,
354,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
18342,
83,
26,
450,
83,
3524,
450,
334,
466,
8,
277,
2843,
354,
3108,
291,
14,
354,
9,
421,
199,
318,
284,
1147,
323,
63,
25048,
8,
875,
304,
272,
408,
272,
2779,
1159,
440,
3962,
370,
664,
314,
29164,
1159,
1928,
6617,
314,
22984,
22440,
26581,
272,
8292,
14,
272,
408,
272,
327,
620,
4346,
2952,
402,
3962,
2649,
8292,
315,
1134,
18,
75,
334,
25048,
3181,
1133,
1736,
272,
327,
543,
2649,
3326,
9,
272,
1059,
275,
620,
8,
875,
9,
272,
394,
275,
29164,
14,
3437,
272,
543,
2863,
14,
11996,
8,
10230,
304,
267,
327,
862,
370,
2879,
6698,
267,
1059,
275,
394,
14,
7450,
59,
875,
61,
267,
1059,
12,
5501,
4048,
275,
1059,
14,
5312,
360,
5320,
339,
664,
63,
1375,
275,
2400,
308,
26,
394,
14,
11299,
14,
362,
8,
83,
12,
394,
14,
7511,
14,
362,
8,
83,
430,
272,
1830,
1228,
8,
875,
12,
620,
304,
267,
1059,
275,
664,
63,
1375,
8,
875,
9,
339,
862,
26,
267,
327,
365,
282,
2008,
3063,
267,
1768,
12,
4048,
275,
1059,
272,
871,
3146,
26,
267,
372,
2125,
339,
862,
26,
267,
372,
29164,
63,
11299,
14,
11299,
59,
1302,
61,
340,
29164,
63,
11299,
587,
2125,
272,
871,
4067,
26,
267,
372,
2125,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
gdelpierre/ansible-modules-core
|
network/nxos/nxos_bgp_neighbor_af.py
|
19
|
39971
|
#!/usr/bin/python
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
DOCUMENTATION = '''
---
module: nxos_bgp_neighbor_af
version_added: "2.2"
short_description: Manages BGP address-family's neighbors configuration.
description:
- Manages BGP address-family's neighbors configurations on NX-OS switches.
author: Gabriele Gerbino (@GGabriele)
extends_documentation_fragment: nxos
notes:
- C(state=absent) removes the whole BGP address-family's
neighbor configuration.
- Default, when supported, removes properties
- In order to default maximum-prefix configuration, only
C(max_prefix_limit=default) is needed.
options:
asn:
description:
- BGP autonomous system number. Valid values are String,
Integer in ASPLAIN or ASDOT notation.
required: true
vrf:
description:
- Name of the VRF. The name 'default' is a valid VRF representing
the global bgp.
required: false
default: default
neighbor:
description:
- Neighbor Identifier. Valid values are string. Neighbors may use
IPv4 or IPv6 notation, with or without prefix length.
required: true
afi:
description:
- Address Family Identifier.
required: true
choices: ['ipv4','ipv6', 'vpnv4', 'vpnv6', 'l2vpn']
safi:
description:
- Sub Address Family Identifier.
required: true
choices: ['unicast','multicast', 'evpn']
additional_paths_receive:
description:
- Valid values are enable for basic command enablement; disable
for disabling the command at the neighbor af level
(it adds the disable keyword to the basic command); and inherit
to remove the command at this level (the command value is
inherited from a higher BGP layer).
required: false
choices: ['enable','disable', 'inherit']
default: null
additional_paths_send:
description:
- Valid values are enable for basic command enablement; disable
for disabling the command at the neighbor af level
(it adds the disable keyword to the basic command); and inherit
to remove the command at this level (the command value is
inherited from a higher BGP layer).
required: false
choices: ['enable','disable', 'inherit']
default: null
advertise_map_exist:
description:
- Conditional route advertisement. This property requires two
route maps, an advertise-map and an exist-map. Valid values are
an array specifying both the advertise-map name and the exist-map
name, or simply 'default' e.g. ['my_advertise_map',
'my_exist_map']. This command is mutually exclusive with the
advertise_map_non_exist property.
required: false
default: null
advertise_map_non_exist:
description:
- Conditional route advertisement. This property requires two
route maps, an advertise-map and an exist-map. Valid values are
an array specifying both the advertise-map name and the
non-exist-map name, or simply 'default' e.g.
['my_advertise_map', 'my_non_exist_map']. This command is mutually
exclusive with the advertise_map_exist property.
required: false
default: null
allowas_in:
description:
- Activate allowas-in property
required: false
default: null
allowas_in_max:
description:
- Optional max-occurrences value for allowas_in. Valid values are
an integer value or 'default'. Can be used independently or in
conjunction with allowas_in.
required: false
default: null
as_override:
description:
- Activate the as-override feature.
required: false
choices: ['true', 'false']
default: null
default_originate:
description:
- Activate the default-originate feature.
required: false
choices: ['true', 'false']
default: null
default_originate_route_map:
description:
- Optional route-map for the default_originate property. Can be
used independently or in conjunction with C(default_originate).
Valid values are a string defining a route-map name,
or 'default'.
required: false
default: null
filter_list_in:
description:
- Valid values are a string defining a filter-list name,
or 'default'.
required: false
default: null
filter_list_out:
description:
- Valid values are a string defining a filter-list name,
or 'default'.
required: false
default: null
max_prefix_limit:
description:
- maximum-prefix limit value. Valid values are an integer value
or 'default'.
required: false
default: null
max_prefix_interval:
description:
- Optional restart interval. Valid values are an integer.
Requires max_prefix_limit.
required: false
default: null
max_prefix_threshold:
description:
- Optional threshold percentage at which to generate a warning.
Valid values are an integer value.
Requires max_prefix_limit.
required: false
default: null
max_prefix_warning:
description:
- Optional warning-only keyword. Requires max_prefix_limit.
required: false
choices: ['true','false']
default: null
next_hop_self:
description:
- Activate the next-hop-self feature.
required: false
choices: ['true','false']
default: null
next_hop_third_party:
description:
- Activate the next-hop-third-party feature.
required: false
choices: ['true','false']
default: null
prefix_list_in:
description:
- Valid values are a string defining a prefix-list name,
or 'default'.
required: false
default: null
prefix_list_out:
description:
- Valid values are a string defining a prefix-list name,
or 'default'.
required: false
default: null
route_map_in:
description:
- Valid values are a string defining a route-map name,
or 'default'.
required: false
default: null
route_map_out:
description:
- Valid values are a string defining a route-map name,
or 'default'.
required: false
default: null
route_reflector_client:
description:
- Router reflector client.
required: false
choices: ['true','false']
default: null
send_community:
description:
- send-community attribute.
required: false
choices: ['none', 'both', 'extended', 'standard', 'default']
default: null
soft_reconfiguration_in:
description:
- Valid values are 'enable' for basic command enablement; 'always'
to add the always keyword to the basic command; and 'inherit' to
remove the command at this level (the command value is inherited
from a higher BGP layer).
required: false
choices: ['enable','always','inherit']
default: null
soo:
description:
- Site-of-origin. Valid values are a string defining a VPN
extcommunity or 'default'.
required: false
default: null
suppress_inactive:
description:
- suppress-inactive feature.
required: false
choices: ['true','false','default']
default: null
unsuppress_map:
description:
- unsuppress-map. Valid values are a string defining a route-map
name or 'default'.
required: false
default: null
weight:
description:
- Weight value. Valid values are an integer value or 'default'.
required: false
default: null
state:
description:
- Determines whether the config should be present or not
on the device.
required: false
default: present
choices: ['present','absent']
'''
EXAMPLES = '''
configure RR client
- nxos_bgp_neighbor_af:
asn: 65535
neighbor: '3.3.3.3'
afi: ipv4
safi: unicast
route_reflector_client: true
state: present
username: "{{ un }}"
password: "{{ pwd }}"
host: "{{ inventory_hostname }}"
'''
RETURN = '''
proposed:
description: k/v pairs of parameters passed into module
returned: verbose mode
type: dict
sample: {"afi": "ipv4", "asn": "65535",
"neighbor": "3.3.3.3", "route_reflector_client": true,
"safi": "unicast", "vrf": "default"}
existing:
description: k/v pairs of existing configuration
returned: verbose mode
type: dict
sample: {}
end_state:
description: k/v pairs of configuration after module execution
returned: verbose mode
type: dict
sample: {"additional_paths_receive": "inherit",
"additional_paths_send": "inherit",
"advertise_map_exist": [], "advertise_map_non_exist": [],
"afi": "ipv4", "allowas_in": false,
"allowas_in_max": "", "as_override": false,
"asn": "65535", "default_originate": false,
"default_originate_route_map": "", "filter_list_in": "",
"filter_list_out": "", "max_prefix_interval": "",
"max_prefix_limit": "", "max_prefix_threshold": "",
"max_prefix_warning": "", "neighbor": "3.3.3.3",
"next_hop_self": false, "next_hop_third_party": true,
"prefix_list_in": "", "prefix_list_out": "",
"route_map_in": "", "route_map_out": "",
"route_reflector_client": true, "safi": "unicast",
"send_community": "",
"soft_reconfiguration_in": "inherit", "soo": "",
"suppress_inactive": false, "unsuppress_map": "",
"vrf": "default", "weight": ""}
updates:
description: commands sent to the device
returned: always
type: list
sample: ["router bgp 65535", "neighbor 3.3.3.3",
"address-family ipv4 unicast", "route-reflector-client"]
changed:
description: check to see if a change was made on the device
returned: always
type: boolean
sample: true
'''
# COMMON CODE FOR MIGRATION
import re
import ansible.module_utils.nxos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
from ansible.module_utils.network import NetworkModule
from ansible.module_utils.shell import ShellError
def to_list(val):
if isinstance(val, (list, tuple)):
return list(val)
elif val is not None:
return [val]
else:
return list()
class CustomNetworkConfig(NetworkConfig):
def expand_section(self, configobj, S=None):
if S is None:
S = list()
S.append(configobj)
for child in configobj.children:
if child in S:
continue
self.expand_section(child, S)
return S
def get_object(self, path):
for item in self.items:
if item.text == path[-1]:
parents = [p.text for p in item.parents]
if parents == path[:-1]:
return item
def to_block(self, section):
return '\n'.join([item.raw for item in section])
def get_section(self, path):
try:
section = self.get_section_objects(path)
return self.to_block(section)
except ValueError:
return list()
def get_section_objects(self, path):
if not isinstance(path, list):
path = [path]
obj = self.get_object(path)
if not obj:
raise ValueError('path does not exist in config')
return self.expand_section(obj)
def add(self, lines, parents=None):
"""Adds one or lines of configuration
"""
ancestors = list()
offset = 0
obj = None
## global config command
if not parents:
for line in to_list(lines):
item = ConfigLine(line)
item.raw = line
if item not in self.items:
self.items.append(item)
else:
for index, p in enumerate(parents):
try:
i = index + 1
obj = self.get_section_objects(parents[:i])[0]
ancestors.append(obj)
except ValueError:
# add parent to config
offset = index * self.indent
obj = ConfigLine(p)
obj.raw = p.rjust(len(p) + offset)
if ancestors:
obj.parents = list(ancestors)
ancestors[-1].children.append(obj)
self.items.append(obj)
ancestors.append(obj)
# add child objects
for line in to_list(lines):
# check if child already exists
for child in ancestors[-1].children:
if child.text == line:
break
else:
offset = len(parents) * self.indent
item = ConfigLine(line)
item.raw = line.rjust(len(line) + offset)
item.parents = ancestors
ancestors[-1].children.append(item)
self.items.append(item)
def get_network_module(**kwargs):
try:
return get_module(**kwargs)
except NameError:
return NetworkModule(**kwargs)
def get_config(module, include_defaults=False):
config = module.params['config']
if not config:
try:
config = module.get_config()
except AttributeError:
defaults = module.params['include_defaults']
config = module.config.get_config(include_defaults=defaults)
return CustomNetworkConfig(indent=2, contents=config)
def load_config(module, candidate):
config = get_config(module)
commands = candidate.difference(config)
commands = [str(c).strip() for c in commands]
save_config = module.params['save']
result = dict(changed=False)
if commands:
if not module.check_mode:
try:
module.configure(commands)
except AttributeError:
module.config(commands)
if save_config:
try:
module.config.save_config()
except AttributeError:
module.execute(['copy running-config startup-config'])
result['changed'] = True
result['updates'] = commands
return result
# END OF COMMON CODE
WARNINGS = []
BOOL_PARAMS = [
'allowas_in',
'as_override',
'default_originate',
'next_hop_self',
'next_hop_third_party',
'route_reflector_client',
'suppress_inactive'
]
PARAM_TO_COMMAND_KEYMAP = {
'afi': 'address-family',
'asn': 'router bgp',
'neighbor': 'neighbor',
'additional_paths_receive': 'capability additional-paths receive',
'additional_paths_send': 'capability additional-paths send',
'advertise_map_exist': 'advertise-map exist',
'advertise_map_non_exist': 'advertise-map non-exist',
'allowas_in': 'allowas-in',
'allowas_in_max': 'allowas-in max',
'as_override': 'as-override',
'default_originate': 'default-originate',
'default_originate_route_map': 'default-originate route-map',
'filter_list_in': 'filter-list in',
'filter_list_out': 'filter-list out',
'max_prefix_limit': 'maximum-prefix',
'max_prefix_interval': 'maximum-prefix options',
'max_prefix_threshold': 'maximum-prefix options',
'max_prefix_warning': 'maximum-prefix options',
'next_hop_self': 'next-hop-self',
'next_hop_third_party': 'next-hop-third-party',
'prefix_list_in': 'prefix-list in',
'prefix_list_out': 'prefix-list out',
'route_map_in': 'route-map in',
'route_map_out': 'route-map out',
'route_reflector_client': 'route-reflector-client',
'safi': 'address-family',
'send_community': 'send-community',
'soft_reconfiguration_in': 'soft-reconfiguration inbound',
'soo': 'soo',
'suppress_inactive': 'suppress-inactive',
'unsuppress_map': 'unsuppress-map',
'weight': 'weight',
'vrf': 'vrf'
}
PARAM_TO_DEFAULT_KEYMAP = {}
def invoke(name, *args, **kwargs):
func = globals().get(name)
if func:
return func(*args, **kwargs)
def get_value(arg, config, module):
if arg in BOOL_PARAMS:
REGEX = re.compile(r'\s+{0}\s*'.format(PARAM_TO_COMMAND_KEYMAP[arg]), re.M)
value = False
try:
if REGEX.search(config):
value = True
except TypeError:
value = False
else:
REGEX = re.compile(r'(?:{0}\s)(?P<value>.*)$'.format(PARAM_TO_COMMAND_KEYMAP[arg]), re.M)
value = ''
if PARAM_TO_COMMAND_KEYMAP[arg] in config:
value = REGEX.search(config).group('value')
return value
def in_out_param(arg, config, module):
value = ''
for line in config:
if PARAM_TO_COMMAND_KEYMAP[arg].split()[0] in line:
splitted_line = line.split()
if splitted_line[-1] == PARAM_TO_COMMAND_KEYMAP[arg].split()[1]:
value = splitted_line[1]
return value
def get_custom_value(arg, config, module):
splitted_config = config.splitlines()
value = ''
if (arg.startswith('filter_list') or arg.startswith('prefix_list') or
arg.startswith('route_map')):
value = in_out_param(arg, splitted_config, module)
elif arg == 'send_community':
for line in splitted_config:
if PARAM_TO_COMMAND_KEYMAP[arg] in line:
splitted_line = line.split()
if len(splitted_line) == 1:
value = 'none'
else:
value = splitted_line[1]
elif arg == 'additional_paths_receive':
value = 'inherit'
for line in splitted_config:
if PARAM_TO_COMMAND_KEYMAP[arg] in line:
if 'disable' in line:
value = 'disable'
else:
value = 'enable'
elif arg == 'additional_paths_send':
value = 'inherit'
for line in splitted_config:
if PARAM_TO_COMMAND_KEYMAP[arg] in line:
if 'disable' in line:
value = 'disable'
else:
value = 'enable'
elif arg == 'advertise_map_exist':
value = []
for line in splitted_config:
if 'advertise-map' in line and 'exist-map' in line:
splitted_line = line.split()
value = [splitted_line[1], splitted_line[3]]
elif arg == 'advertise_map_non_exist':
value = []
for line in splitted_config:
if 'advertise-map' in line and 'non-exist-map' in line:
splitted_line = line.split()
value = [splitted_line[1], splitted_line[3]]
elif arg == 'allowas_in_max':
for line in splitted_config:
if 'allowas-in' in line:
splitted_line = line.split()
if len(splitted_line) == 2:
value = splitted_line[-1]
elif arg.startswith('max_prefix'):
for line in splitted_config:
if 'maximum-prefix' in line:
splitted_line = line.split()
if arg == 'max_prefix_limit':
value = splitted_line[1]
elif arg == 'max_prefix_interval' and 'restart' in line:
value = splitted_line[-1]
elif arg == 'max_prefix_threshold' and len(splitted_line) > 2:
try:
int(splitted_line[2])
value = splitted_line[2]
except ValueError:
value = ''
elif arg == 'max_prefix_warning':
if 'warning-only' in line:
value = True
else:
value = False
elif arg == 'soft_reconfiguration_in':
value = 'inherit'
for line in splitted_config:
if PARAM_TO_COMMAND_KEYMAP[arg] in line:
if 'always' in line:
value = 'always'
else:
value = 'enable'
elif arg == 'next_hop_third_party':
PRESENT_REGEX = re.compile(r'\s+{0}\s*'.format(PARAM_TO_COMMAND_KEYMAP[arg]), re.M)
ABSENT_REGEX = re.compile(r'\s+no\s+{0}\s*'.format(PARAM_TO_COMMAND_KEYMAP[arg]), re.M)
value = False
try:
if ABSENT_REGEX.search(config):
value = False
elif PRESENT_REGEX.search(config):
value = True
except TypeError:
value = False
return value
def get_existing(module, args):
existing = {}
netcfg = get_config(module)
custom = [
'allowas_in_max',
'send_community',
'additional_paths_send',
'additional_paths_receive',
'advertise_map_exist',
'advertise_map_non_exist',
'filter_list_in',
'filter_list_out',
'max_prefix_limit',
'max_prefix_interval',
'max_prefix_threshold',
'max_prefix_warning',
'next_hop_third_party',
'prefix_list_in',
'prefix_list_out',
'route_map_in',
'route_map_out',
'soft_reconfiguration_in'
]
try:
asn_regex = '.*router\sbgp\s(?P<existing_asn>\d+).*'
match_asn = re.match(asn_regex, str(netcfg), re.DOTALL)
existing_asn_group = match_asn.groupdict()
existing_asn = existing_asn_group['existing_asn']
except AttributeError:
existing_asn = ''
if existing_asn:
parents = ["router bgp {0}".format(existing_asn)]
if module.params['vrf'] != 'default':
parents.append('vrf {0}'.format(module.params['vrf']))
parents.append('neighbor {0}'.format(module.params['neighbor']))
parents.append('address-family {0} {1}'.format(
module.params['afi'], module.params['safi']))
config = netcfg.get_section(parents)
if config:
for arg in args:
if arg not in ['asn', 'vrf', 'neighbor', 'afi', 'safi']:
if arg in custom:
existing[arg] = get_custom_value(arg, config, module)
else:
existing[arg] = get_value(arg, config, module)
existing['asn'] = existing_asn
existing['neighbor'] = module.params['neighbor']
existing['vrf'] = module.params['vrf']
existing['afi'] = module.params['afi']
existing['safi'] = module.params['safi']
else:
WARNINGS.append("The BGP process didn't exist but the task"
" just created it.")
return existing
def apply_key_map(key_map, table):
new_dict = {}
for key, value in table.items():
new_key = key_map.get(key)
if new_key:
value = table.get(key)
if value:
new_dict[new_key] = value
else:
new_dict[new_key] = value
return new_dict
def get_address_family_command(key, value, module):
command = "address-family {0} {1}".format(
module.params['afi'], module.params['safi'])
return command
def get_capability_additional_paths_receive_command(key, value, module):
command = ''
if value == 'enable':
command = key
elif value == 'disable':
command = '{0} {1}'.format(key, value)
return command
def get_capability_additional_paths_send_command(key, value, module):
command = ''
if value == 'enable':
command = key
elif value == 'disable':
command = '{0} {1}'.format(key, value)
return command
def get_advertise_map_exist_command(key, value, module):
command = 'advertise-map {0} exist-map {1}'.format(
value[0], value[1])
return command
def get_advertise_map_non_exist_command(key, value, module):
command = 'advertise-map {0} non-exist-map {1}'.format(
value[0], value[1])
return command
def get_allowas_in_max_command(key, value, module):
command = 'allowas-in {0}'.format(value)
return command
def get_filter_list_in_command(key, value, module):
command = 'filter-list {0} in'.format(value)
return command
def get_filter_list_out_command(key, value, module):
command = 'filter-list {0} out'.format(value)
return command
def get_prefix_list_in_command(key, value, module):
command = 'prefix-list {0} in'.format(value)
return command
def get_prefix_list_out_command(key, value, module):
command = 'prefix-list {0} out'.format(value)
return command
def get_route_map_in_command(key, value, module):
command = 'route-map {0} in'.format(value)
return command
def get_route_map_out_command(key, value, module):
command = 'route-map {0} out'.format(value)
return command
def get_maximum_prefix_command(key, value, module):
return get_maximum_prefix_options_command(key, value, module)
def get_maximum_prefix_options_command(key, value, module):
command = 'maximum-prefix {0}'.format(module.params['max_prefix_limit'])
if module.params['max_prefix_threshold']:
command += ' {0}'.format(module.params['max_prefix_threshold'])
if module.params['max_prefix_interval']:
command += ' restart {0}'.format(module.params['max_prefix_interval'])
elif module.params['max_prefix_warning']:
command += ' warning-only'
return command
def get_soft_reconfiguration_inbound_command(key, value, module):
command = ''
if value == 'enable':
command = key
elif value == 'always':
command = '{0} {1}'.format(key, value)
return command
def get_default_command(key, value, existing_commands):
command = ''
if key == 'send-community' and existing_commands.get(key) == 'none':
command = 'no {0}'.format(key)
elif existing_commands.get(key):
existing_value = existing_commands.get(key)
if value == 'inherit':
if existing_value != 'inherit':
command = 'no {0}'.format(key)
else:
if key == 'advertise-map exist':
command = 'no advertise-map {0} exist-map {1}'.format(
existing_value[0], existing_value[1])
elif key == 'advertise-map non-exist':
command = 'no advertise-map {0} non-exist-map {1}'.format(
existing_value[0], existing_value[1])
elif key == 'filter-list in':
command = 'no filter-list {0} in'.format(existing_value)
elif key == 'filter-list out':
command = 'no filter-list {0} out'.format(existing_value)
elif key == 'prefix-list in':
command = 'no prefix-list {0} in'.format(existing_value)
elif key == 'prefix-list out':
command = 'no prefix-list {0} out'.format(existing_value)
elif key == 'route-map in':
command = 'no route-map {0} in'.format(existing_value)
elif key == 'route-map out':
command = 'no route-map {0} out'.format(existing_value)
elif key.startswith('maximum-prefix'):
command = 'no maximum-prefix {0}'.format(
existing_commands.get('maximum-prefix'))
elif key == 'allowas-in max':
command = ['no allowas-in {0}'.format(existing_value)]
command.append('allowas-in')
else:
command = 'no {0} {1}'.format(key, existing_value)
else:
if key.replace(' ', '_').replace('-', '_') in BOOL_PARAMS:
command = 'no {0}'.format(key)
return command
def fix_proposed(module, proposed):
allowas_in = proposed.get('allowas_in')
allowas_in_max = proposed.get('allowas_in_max')
if allowas_in is False and allowas_in_max:
proposed.pop('allowas_in_max')
elif allowas_in and allowas_in_max:
proposed.pop('allowas_in')
return proposed
def state_present(module, existing, proposed, candidate):
commands = list()
proposed = fix_proposed(module, proposed)
proposed_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, proposed)
existing_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, existing)
custom = [
'address-family',
'capability additional-paths receive',
'capability additional-paths send',
'advertise-map exist',
'advertise-map non-exist',
'allowas-in max',
'filter-list in',
'filter-list out',
'maximum-prefix',
'maximum-prefix options',
'prefix-list in',
'prefix-list out',
'route-map in',
'route-map out',
'soft-reconfiguration inbound'
]
for key, value in proposed_commands.iteritems():
if key == 'send-community' and value == 'none':
commands.append('{0}'.format(key))
elif value is True and key != 'maximum-prefix options':
commands.append(key)
elif value is False and key != 'maximum-prefix options':
commands.append('no {0}'.format(key))
elif value == 'default' or value == 'inherit':
command = get_default_command(key, value, existing_commands)
if isinstance(command, str):
if command and command not in commands:
commands.append(command)
elif isinstance(command, list):
for cmd in command:
if cmd not in commands:
commands.append(cmd)
elif key in custom:
fixed_key = key.replace(' ', '_').replace('-', '_')
command = invoke('get_%s_command' % fixed_key, key, value, module)
if command and command not in commands:
commands.append(command)
else:
command = '{0} {1}'.format(key, value)
commands.append(command)
if commands:
parents = ["router bgp {0}".format(module.params['asn'])]
if module.params['vrf'] != 'default':
parents.append('vrf {0}'.format(module.params['vrf']))
parents.append('neighbor {0}'.format(module.params['neighbor']))
if len(commands) == 1:
candidate.add(commands, parents=parents)
elif len(commands) > 1:
af_command = 'address-family {0} {1}'.format(
module.params['afi'], module.params['safi'])
if af_command in commands:
commands.remove(af_command)
parents.append('address-family {0} {1}'.format(
module.params['afi'], module.params['safi']))
candidate.add(commands, parents=parents)
def state_absent(module, existing, proposed, candidate):
commands = []
parents = ["router bgp {0}".format(module.params['asn'])]
if module.params['vrf'] != 'default':
parents.append('vrf {0}'.format(module.params['vrf']))
parents.append('neighbor {0}'.format(module.params['neighbor']))
commands.append('no address-family {0} {1}'.format(
module.params['afi'], module.params['safi']))
candidate.add(commands, parents=parents)
def main():
argument_spec = dict(
asn=dict(required=True, type='str'),
vrf=dict(required=False, type='str', default='default'),
neighbor=dict(required=True, type='str'),
afi=dict(required=True, type='str'),
safi=dict(required=True, type='str'),
additional_paths_receive=dict(required=False, type='str',
choices=['enable', 'disable', 'inherit']),
additional_paths_send=dict(required=False, type='str',
choices=['enable', 'disable', 'inherit']),
advertise_map_exist=dict(required=False, type='list'),
advertise_map_non_exist=dict(required=False, type='list'),
allowas_in=dict(required=False, type='bool'),
allowas_in_max=dict(required=False, type='str'),
as_override=dict(required=False, type='bool'),
default_originate=dict(required=False, type='bool'),
default_originate_route_map=dict(required=False, type='str'),
filter_list_in=dict(required=False, type='str'),
filter_list_out=dict(required=False, type='str'),
max_prefix_limit=dict(required=False, type='str'),
max_prefix_interval=dict(required=False, type='str'),
max_prefix_threshold=dict(required=False, type='str'),
max_prefix_warning=dict(required=False, type='bool'),
next_hop_self=dict(required=False, type='bool'),
next_hop_third_party=dict(required=False, type='bool'),
prefix_list_in=dict(required=False, type='str'),
prefix_list_out=dict(required=False, type='str'),
route_map_in=dict(required=False, type='str'),
route_map_out=dict(required=False, type='str'),
route_reflector_client=dict(required=False, type='bool'),
send_community=dict(required=False, choices=['none',
'both',
'extended',
'standard',
'default']),
soft_reconfiguration_in=dict(required=False, type='str',
choices=['enable', 'always', 'inherit']),
soo=dict(required=False, type='str'),
suppress_inactive=dict(required=False, type='bool'),
unsuppress_map=dict(required=False, type='str'),
weight=dict(required=False, type='str'),
state=dict(choices=['present', 'absent'], default='present',
required=False),
include_defaults=dict(default=True),
config=dict(),
save=dict(type='bool', default=False)
)
module = get_network_module(argument_spec=argument_spec,
mutually_exclusive=[['advertise_map_exist',
'advertise_map_non_exist']],
supports_check_mode=True)
state = module.params['state']
if ((module.params['max_prefix_interval'] or
module.params['max_prefix_warning'] or
module.params['max_prefix_threshold']) and
not module.params['max_prefix_limit']):
module.fail_json(msg='max_prefix_limit is required when using '
'max_prefix_warning, max_prefix_limit or '
'max_prefix_threshold.')
if module.params['vrf'] == 'default' and module.params['soo']:
module.fail_json(msg='SOO is only allowed in non-default VRF')
args = [
'afi',
'asn',
'neighbor',
'additional_paths_receive',
'additional_paths_send',
'advertise_map_exist',
'advertise_map_non_exist',
'allowas_in',
'allowas_in_max',
'as_override',
'default_originate',
'default_originate_route_map',
'filter_list_in',
'filter_list_out',
'max_prefix_limit',
'max_prefix_interval',
'max_prefix_threshold',
'max_prefix_warning',
'next_hop_self',
'next_hop_third_party',
'prefix_list_in',
'prefix_list_out',
'route_map_in',
'route_map_out',
'soft_reconfiguration_in',
'soo',
'suppress_inactive',
'unsuppress_map',
'weight',
'route_reflector_client',
'safi',
'send_community',
'vrf'
]
existing = invoke('get_existing', module, args)
if existing.get('asn'):
if (existing.get('asn') != module.params['asn'] and
state == 'present'):
module.fail_json(msg='Another BGP ASN already exists.',
proposed_asn=module.params['asn'],
existing_asn=existing.get('asn'))
if module.params['advertise_map_exist'] == ['default']:
module.params['advertise_map_exist'] = 'default'
if module.params['advertise_map_non_exist'] == ['default']:
module.params['advertise_map_non_exist'] = 'default'
end_state = existing
proposed_args = dict((k, v) for k, v in module.params.iteritems()
if v is not None and k in args)
proposed = {}
for key, value in proposed_args.iteritems():
if key not in ['asn', 'vrf', 'neighbor']:
if not isinstance(value, list):
if str(value).lower() == 'true':
value = True
elif str(value).lower() == 'false':
value = False
elif str(value).lower() == 'default':
value = PARAM_TO_DEFAULT_KEYMAP.get(key)
if value is None:
if key in BOOL_PARAMS:
value = False
else:
value = 'default'
if existing.get(key) or (not existing.get(key) and value):
proposed[key] = value
result = {}
if state == 'present' or (state == 'absent' and existing):
candidate = CustomNetworkConfig(indent=3)
invoke('state_%s' % state, module, existing, proposed, candidate)
try:
response = load_config(module, candidate)
result.update(response)
except ShellError:
exc = get_exception()
module.fail_json(msg=str(exc))
else:
result['updates'] = []
result['connected'] = module.connected
if module._verbosity > 0:
end_state = invoke('get_existing', module, args)
result['end_state'] = end_state
result['existing'] = existing
result['proposed'] = proposed_args
if WARNINGS:
result['warnings'] = WARNINGS
module.exit_json(**result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
22072,
63,
10132,
63,
13881,
63,
2756,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
21612,
27893,
2287,
13,
6606,
1159,
15845,
2897,
14,
199,
1802,
26,
272,
446,
21612,
27893,
2287,
13,
6606,
1159,
15845,
13422,
641,
653,
56,
13,
3100,
24563,
14,
199,
2502,
26,
598,
371,
322,
8081,
22261,
1393,
79,
8593,
2916,
371,
322,
8081,
9,
199,
11036,
63,
9970,
63,
7677,
26,
22072,
199,
5983,
26,
272,
446,
445,
8,
929,
29,
5575,
9,
14185,
314,
8852,
27893,
2287,
13,
6606,
1159,
489,
15503,
2897,
14,
272,
446,
3758,
12,
1380,
3748,
12,
14185,
4382,
272,
446,
1010,
1865,
370,
849,
5696,
13,
1861,
2897,
12,
1454,
489,
445,
8,
988,
63,
1861,
63,
3097,
29,
885,
9,
365,
4346,
14,
199,
1419,
26,
272,
16723,
26,
267,
1369,
26,
288,
446,
27893,
6384,
30671,
7376,
2656,
1329,
14,
4821,
1338,
787,
2624,
12,
1598,
7225,
315,
4319,
2749,
9021,
503,
437,
3693,
1387,
15843,
14,
267,
1415,
26,
2549,
272,
15209,
26,
267,
1369,
26,
288,
446,
2812,
402,
314,
812,
11778,
14,
710,
536,
283,
885,
7,
365,
282,
1686,
812,
11778,
6144,
1598,
314,
2288,
16884,
14,
267,
1415,
26,
3055,
267,
849,
26,
849,
272,
15503,
26,
267,
1369,
26,
288,
446,
5612,
7201,
23285,
14,
4821,
1338,
787,
1059,
14,
5612,
7398,
1443,
675,
1598,
6509,
20,
503,
6509,
22,
15843,
12,
543,
503,
1928,
2403,
2582,
14,
267,
1415,
26,
2549,
272,
282,
329,
26,
267,
1369,
26,
288,
446,
9906,
481,
4632,
23285,
14,
267,
1415,
26,
2549,
267,
3415,
26,
788,
4774,
20,
1673,
4774,
22,
297,
283,
9702,
86,
20,
297,
283,
9702,
86,
22,
297,
283,
76,
18,
9702,
418,
272,
2937,
329,
26,
267,
1369,
26,
288,
446,
4804,
9906,
481,
4632,
23285,
14,
267,
1415,
26,
2549,
267,
3415,
26,
788,
5209,
1810,
1673,
23797,
297,
283,
6857,
4812,
418,
272,
4722,
63,
3771,
63,
9391,
26,
267,
1369,
26,
288,
446,
4821,
1338,
787,
4756,
367,
5678,
1414,
4756,
434,
27,
3507,
1598,
367,
30723,
314,
1414,
737,
314,
15503,
15871,
2166,
1598,
334,
390,
9584,
314,
3507,
4252,
370,
314,
5678,
1414,
2736,
436,
8287,
1598,
370,
2813,
314,
1414,
737,
642,
2166,
334,
1589,
1414,
574,
365,
1598,
12623,
687,
282,
10948,
27893,
4045,
680,
267,
1415,
26,
3055,
267,
3415,
26,
788,
4296,
1673,
5993,
297,
283,
6486,
418,
267,
849,
26,
2973,
272,
4722,
63,
3771,
63,
2254,
26,
267,
1369,
26,
288,
446,
4821,
1338,
787,
4756,
367,
5678,
1414,
4756,
434,
27,
3507,
1598,
367,
30723,
314,
1414,
737,
314,
15503,
15871,
2166,
1598,
334,
390,
9584,
314,
3507,
4252,
370,
314,
5678,
1414,
2736,
436,
8287,
1598,
370,
2813,
314,
1414,
737,
642,
2166,
334,
1589,
1414,
574,
365,
1598,
12623,
687,
282,
10948,
27893,
4045,
680,
267,
1415,
26,
3055,
267,
3415,
26,
788,
4296,
1673,
5993,
297,
283,
6486,
418,
267,
849,
26,
2973,
272,
19613,
261,
63,
1130,
63,
4494,
26,
267,
1369,
26,
288,
446,
24191,
7475,
19613,
261,
434,
14,
961,
3324,
5074,
2877,
1598,
7475,
9033,
12,
376,
19613,
261,
13,
1130,
436,
376,
2187,
13,
1130,
14,
4821,
1338,
787,
1598,
376,
1625,
9176,
3865,
314,
19613,
261,
13,
1130,
536,
436,
314,
2187,
13,
1130,
1598,
536,
12,
503,
9329,
283,
885,
7,
325,
14,
71,
14,
788,
1662,
63,
24576,
261,
63,
1130,
297,
1598,
283,
1662,
63,
4494,
63,
1130,
2278,
961,
1414,
365,
16108,
13914,
543,
314,
1598,
19613,
261,
63,
1130,
63,
2865,
63,
4494,
3324,
14,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
19613,
261,
63,
1130,
63,
2865,
63,
4494,
26,
267,
1369,
26,
288,
446,
24191,
7475,
19613,
261,
434,
14,
961,
3324,
5074,
2877,
1598,
7475,
9033,
12,
376,
19613,
261,
13,
1130,
436,
376,
2187,
13,
1130,
14,
4821,
1338,
787,
1598,
376,
1625,
9176,
3865,
314,
19613,
261,
13,
1130,
536,
436,
314,
1598,
2222,
13,
4494,
13,
1130,
536,
12,
503,
9329,
283,
885,
7,
325,
14,
71,
14,
1598,
788,
1662,
63,
24576,
261,
63,
1130,
297,
283,
1662,
63,
2865,
63,
4494,
63,
1130,
2278,
961,
1414,
365,
16108,
1598,
13914,
543,
314,
19613,
261,
63,
1130,
63,
4494,
3324,
14,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
2040,
305,
63,
262,
26,
267,
1369,
26,
288,
446,
21904,
2409,
2040,
305,
13,
262,
3324,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
2040,
305,
63,
262,
63,
988,
26,
267,
1369,
26,
288,
446,
4879,
1390,
13,
20051,
10056,
574,
367,
2040,
305,
63,
262,
14,
4821,
1338,
787,
1598,
376,
3000,
574,
503,
283,
885,
1370,
6855,
506,
1202,
30426,
503,
315,
1598,
22888,
543,
2040,
305,
63,
262,
14,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
465,
63,
4415,
26,
267,
1369,
26,
288,
446,
21904,
2409,
314,
465,
13,
4415,
3878,
14,
267,
1415,
26,
3055,
267,
3415,
26,
788,
2052,
297,
283,
3910,
418,
267,
849,
26,
2973,
272,
849,
63,
6493,
323
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
22072,
63,
10132,
63,
13881,
63,
2756,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
21612,
27893,
2287,
13,
6606,
1159,
15845,
2897,
14,
199,
1802,
26,
272,
446,
21612,
27893,
2287,
13,
6606,
1159,
15845,
13422,
641,
653,
56,
13,
3100,
24563,
14,
199,
2502,
26,
598,
371,
322,
8081,
22261,
1393,
79,
8593,
2916,
371,
322,
8081,
9,
199,
11036,
63,
9970,
63,
7677,
26,
22072,
199,
5983,
26,
272,
446,
445,
8,
929,
29,
5575,
9,
14185,
314,
8852,
27893,
2287,
13,
6606,
1159,
489,
15503,
2897,
14,
272,
446,
3758,
12,
1380,
3748,
12,
14185,
4382,
272,
446,
1010,
1865,
370,
849,
5696,
13,
1861,
2897,
12,
1454,
489,
445,
8,
988,
63,
1861,
63,
3097,
29,
885,
9,
365,
4346,
14,
199,
1419,
26,
272,
16723,
26,
267,
1369,
26,
288,
446,
27893,
6384,
30671,
7376,
2656,
1329,
14,
4821,
1338,
787,
2624,
12,
1598,
7225,
315,
4319,
2749,
9021,
503,
437,
3693,
1387,
15843,
14,
267,
1415,
26,
2549,
272,
15209,
26,
267,
1369,
26,
288,
446,
2812,
402,
314,
812,
11778,
14,
710,
536,
283,
885,
7,
365,
282,
1686,
812,
11778,
6144,
1598,
314,
2288,
16884,
14,
267,
1415,
26,
3055,
267,
849,
26,
849,
272,
15503,
26,
267,
1369,
26,
288,
446,
5612,
7201,
23285,
14,
4821,
1338,
787,
1059,
14,
5612,
7398,
1443,
675,
1598,
6509,
20,
503,
6509,
22,
15843,
12,
543,
503,
1928,
2403,
2582,
14,
267,
1415,
26,
2549,
272,
282,
329,
26,
267,
1369,
26,
288,
446,
9906,
481,
4632,
23285,
14,
267,
1415,
26,
2549,
267,
3415,
26,
788,
4774,
20,
1673,
4774,
22,
297,
283,
9702,
86,
20,
297,
283,
9702,
86,
22,
297,
283,
76,
18,
9702,
418,
272,
2937,
329,
26,
267,
1369,
26,
288,
446,
4804,
9906,
481,
4632,
23285,
14,
267,
1415,
26,
2549,
267,
3415,
26,
788,
5209,
1810,
1673,
23797,
297,
283,
6857,
4812,
418,
272,
4722,
63,
3771,
63,
9391,
26,
267,
1369,
26,
288,
446,
4821,
1338,
787,
4756,
367,
5678,
1414,
4756,
434,
27,
3507,
1598,
367,
30723,
314,
1414,
737,
314,
15503,
15871,
2166,
1598,
334,
390,
9584,
314,
3507,
4252,
370,
314,
5678,
1414,
2736,
436,
8287,
1598,
370,
2813,
314,
1414,
737,
642,
2166,
334,
1589,
1414,
574,
365,
1598,
12623,
687,
282,
10948,
27893,
4045,
680,
267,
1415,
26,
3055,
267,
3415,
26,
788,
4296,
1673,
5993,
297,
283,
6486,
418,
267,
849,
26,
2973,
272,
4722,
63,
3771,
63,
2254,
26,
267,
1369,
26,
288,
446,
4821,
1338,
787,
4756,
367,
5678,
1414,
4756,
434,
27,
3507,
1598,
367,
30723,
314,
1414,
737,
314,
15503,
15871,
2166,
1598,
334,
390,
9584,
314,
3507,
4252,
370,
314,
5678,
1414,
2736,
436,
8287,
1598,
370,
2813,
314,
1414,
737,
642,
2166,
334,
1589,
1414,
574,
365,
1598,
12623,
687,
282,
10948,
27893,
4045,
680,
267,
1415,
26,
3055,
267,
3415,
26,
788,
4296,
1673,
5993,
297,
283,
6486,
418,
267,
849,
26,
2973,
272,
19613,
261,
63,
1130,
63,
4494,
26,
267,
1369,
26,
288,
446,
24191,
7475,
19613,
261,
434,
14,
961,
3324,
5074,
2877,
1598,
7475,
9033,
12,
376,
19613,
261,
13,
1130,
436,
376,
2187,
13,
1130,
14,
4821,
1338,
787,
1598,
376,
1625,
9176,
3865,
314,
19613,
261,
13,
1130,
536,
436,
314,
2187,
13,
1130,
1598,
536,
12,
503,
9329,
283,
885,
7,
325,
14,
71,
14,
788,
1662,
63,
24576,
261,
63,
1130,
297,
1598,
283,
1662,
63,
4494,
63,
1130,
2278,
961,
1414,
365,
16108,
13914,
543,
314,
1598,
19613,
261,
63,
1130,
63,
2865,
63,
4494,
3324,
14,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
19613,
261,
63,
1130,
63,
2865,
63,
4494,
26,
267,
1369,
26,
288,
446,
24191,
7475,
19613,
261,
434,
14,
961,
3324,
5074,
2877,
1598,
7475,
9033,
12,
376,
19613,
261,
13,
1130,
436,
376,
2187,
13,
1130,
14,
4821,
1338,
787,
1598,
376,
1625,
9176,
3865,
314,
19613,
261,
13,
1130,
536,
436,
314,
1598,
2222,
13,
4494,
13,
1130,
536,
12,
503,
9329,
283,
885,
7,
325,
14,
71,
14,
1598,
788,
1662,
63,
24576,
261,
63,
1130,
297,
283,
1662,
63,
2865,
63,
4494,
63,
1130,
2278,
961,
1414,
365,
16108,
1598,
13914,
543,
314,
19613,
261,
63,
1130,
63,
4494,
3324,
14,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
2040,
305,
63,
262,
26,
267,
1369,
26,
288,
446,
21904,
2409,
2040,
305,
13,
262,
3324,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
2040,
305,
63,
262,
63,
988,
26,
267,
1369,
26,
288,
446,
4879,
1390,
13,
20051,
10056,
574,
367,
2040,
305,
63,
262,
14,
4821,
1338,
787,
1598,
376,
3000,
574,
503,
283,
885,
1370,
6855,
506,
1202,
30426,
503,
315,
1598,
22888,
543,
2040,
305,
63,
262,
14,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
465,
63,
4415,
26,
267,
1369,
26,
288,
446,
21904,
2409,
314,
465,
13,
4415,
3878,
14,
267,
1415,
26,
3055,
267,
3415,
26,
788,
2052,
297,
283,
3910,
418,
267,
849,
26,
2973,
272,
849,
63,
6493,
323,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
cainmatt/django
|
django/utils/datastructures.py
|
394
|
9231
|
import copy
from collections import OrderedDict
from django.utils import six
class OrderedSet(object):
"""
A set which keeps the ordering of the inserted items.
Currently backs onto OrderedDict.
"""
def __init__(self, iterable=None):
self.dict = OrderedDict(((x, None) for x in iterable) if iterable else [])
def add(self, item):
self.dict[item] = None
def remove(self, item):
del self.dict[item]
def discard(self, item):
try:
self.remove(item)
except KeyError:
pass
def __iter__(self):
return iter(self.dict.keys())
def __contains__(self, item):
return item in self.dict
def __bool__(self):
return bool(self.dict)
def __nonzero__(self): # Python 2 compatibility
return type(self).__bool__(self)
def __len__(self):
return len(self.dict)
class MultiValueDictKeyError(KeyError):
pass
class MultiValueDict(dict):
"""
A subclass of dictionary customized to handle multiple values for the
same key.
>>> d = MultiValueDict({'name': ['Adrian', 'Simon'], 'position': ['Developer']})
>>> d['name']
'Simon'
>>> d.getlist('name')
['Adrian', 'Simon']
>>> d.getlist('doesnotexist')
[]
>>> d.getlist('doesnotexist', ['Adrian', 'Simon'])
['Adrian', 'Simon']
>>> d.get('lastname', 'nonexistent')
'nonexistent'
>>> d.setlist('lastname', ['Holovaty', 'Willison'])
This class exists to solve the irritating problem raised by cgi.parse_qs,
which returns a list for every key, even though most Web forms submit
single name-value pairs.
"""
def __init__(self, key_to_list_mapping=()):
super(MultiValueDict, self).__init__(key_to_list_mapping)
def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__,
super(MultiValueDict, self).__repr__())
def __getitem__(self, key):
"""
Returns the last data value for this key, or [] if it's an empty list;
raises KeyError if not found.
"""
try:
list_ = super(MultiValueDict, self).__getitem__(key)
except KeyError:
raise MultiValueDictKeyError(repr(key))
try:
return list_[-1]
except IndexError:
return []
def __setitem__(self, key, value):
super(MultiValueDict, self).__setitem__(key, [value])
def __copy__(self):
return self.__class__([
(k, v[:])
for k, v in self.lists()
])
def __deepcopy__(self, memo=None):
if memo is None:
memo = {}
result = self.__class__()
memo[id(self)] = result
for key, value in dict.items(self):
dict.__setitem__(result, copy.deepcopy(key, memo),
copy.deepcopy(value, memo))
return result
def __getstate__(self):
obj_dict = self.__dict__.copy()
obj_dict['_data'] = {k: self.getlist(k) for k in self}
return obj_dict
def __setstate__(self, obj_dict):
data = obj_dict.pop('_data', {})
for k, v in data.items():
self.setlist(k, v)
self.__dict__.update(obj_dict)
def get(self, key, default=None):
"""
Returns the last data value for the passed key. If key doesn't exist
or value is an empty list, then default is returned.
"""
try:
val = self[key]
except KeyError:
return default
if val == []:
return default
return val
def getlist(self, key, default=None):
"""
Returns the list of values for the passed key. If key doesn't exist,
then a default value is returned.
"""
try:
return super(MultiValueDict, self).__getitem__(key)
except KeyError:
if default is None:
return []
return default
def setlist(self, key, list_):
super(MultiValueDict, self).__setitem__(key, list_)
def setdefault(self, key, default=None):
if key not in self:
self[key] = default
# Do not return default here because __setitem__() may store
# another value -- QueryDict.__setitem__() does. Look it up.
return self[key]
def setlistdefault(self, key, default_list=None):
if key not in self:
if default_list is None:
default_list = []
self.setlist(key, default_list)
# Do not return default_list here because setlist() may store
# another value -- QueryDict.setlist() does. Look it up.
return self.getlist(key)
def appendlist(self, key, value):
"""Appends an item to the internal list associated with key."""
self.setlistdefault(key).append(value)
def _iteritems(self):
"""
Yields (key, value) pairs, where value is the last item in the list
associated with the key.
"""
for key in self:
yield key, self[key]
def _iterlists(self):
"""Yields (key, list) pairs."""
return six.iteritems(super(MultiValueDict, self))
def _itervalues(self):
"""Yield the last value on every key list."""
for key in self:
yield self[key]
if six.PY3:
items = _iteritems
lists = _iterlists
values = _itervalues
else:
iteritems = _iteritems
iterlists = _iterlists
itervalues = _itervalues
def items(self):
return list(self.iteritems())
def lists(self):
return list(self.iterlists())
def values(self):
return list(self.itervalues())
def copy(self):
"""Returns a shallow copy of this object."""
return copy.copy(self)
def update(self, *args, **kwargs):
"""
update() extends rather than replaces existing key lists.
Also accepts keyword args.
"""
if len(args) > 1:
raise TypeError("update expected at most 1 arguments, got %d" % len(args))
if args:
other_dict = args[0]
if isinstance(other_dict, MultiValueDict):
for key, value_list in other_dict.lists():
self.setlistdefault(key).extend(value_list)
else:
try:
for key, value in other_dict.items():
self.setlistdefault(key).append(value)
except TypeError:
raise ValueError("MultiValueDict.update() takes either a MultiValueDict or dictionary")
for key, value in six.iteritems(kwargs):
self.setlistdefault(key).append(value)
def dict(self):
"""
Returns current object as a dict with singular values.
"""
return {key: self[key] for key in self}
class ImmutableList(tuple):
"""
A tuple-like object that raises useful errors when it is asked to mutate.
Example::
>>> a = ImmutableList(range(5), warning="You cannot mutate this.")
>>> a[3] = '4'
Traceback (most recent call last):
...
AttributeError: You cannot mutate this.
"""
def __new__(cls, *args, **kwargs):
if 'warning' in kwargs:
warning = kwargs['warning']
del kwargs['warning']
else:
warning = 'ImmutableList object is immutable.'
self = tuple.__new__(cls, *args, **kwargs)
self.warning = warning
return self
def complain(self, *wargs, **kwargs):
if isinstance(self.warning, Exception):
raise self.warning
else:
raise AttributeError(self.warning)
# All list mutation functions complain.
__delitem__ = complain
__delslice__ = complain
__iadd__ = complain
__imul__ = complain
__setitem__ = complain
__setslice__ = complain
append = complain
extend = complain
insert = complain
pop = complain
remove = complain
sort = complain
reverse = complain
class DictWrapper(dict):
"""
Wraps accesses to a dictionary so that certain values (those starting with
the specified prefix) are passed through a function before being returned.
The prefix is removed before looking up the real value.
Used by the SQL construction code to ensure that values are correctly
quoted before being used.
"""
def __init__(self, data, func, prefix):
super(DictWrapper, self).__init__(data)
self.func = func
self.prefix = prefix
def __getitem__(self, key):
"""
Retrieves the real value after stripping the prefix string (if
present). If the prefix is present, pass the value through self.func
before returning, otherwise return the raw value.
"""
if key.startswith(self.prefix):
use_func = True
key = key[len(self.prefix):]
else:
use_func = False
value = super(DictWrapper, self).__getitem__(key)
if use_func:
return self.func(value)
return value
|
bsd-3-clause
|
[
646,
1331,
199,
504,
5055,
492,
8773,
199,
199,
504,
1639,
14,
1208,
492,
3816,
421,
199,
533,
23617,
8,
785,
304,
272,
408,
272,
437,
663,
1314,
18578,
314,
7794,
402,
314,
11788,
2974,
14,
272,
13550,
1771,
83,
14602,
8773,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
6076,
29,
403,
304,
267,
291,
14,
807,
275,
8773,
12925,
88,
12,
488,
9,
367,
671,
315,
6076,
9,
340,
6076,
587,
3073,
339,
347,
1050,
8,
277,
12,
1242,
304,
267,
291,
14,
807,
59,
1053,
61,
275,
488,
339,
347,
2813,
8,
277,
12,
1242,
304,
267,
2150,
291,
14,
807,
59,
1053,
61,
339,
347,
16895,
8,
277,
12,
1242,
304,
267,
862,
26,
288,
291,
14,
2168,
8,
1053,
9,
267,
871,
4067,
26,
288,
986,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
14,
807,
14,
1612,
1012,
339,
347,
636,
6134,
721,
277,
12,
1242,
304,
267,
372,
1242,
315,
291,
14,
807,
339,
347,
636,
2245,
721,
277,
304,
267,
372,
2155,
8,
277,
14,
807,
9,
339,
347,
636,
10262,
721,
277,
304,
420,
327,
2018,
499,
7163,
267,
372,
730,
8,
277,
2843,
2245,
721,
277,
9,
339,
347,
636,
552,
721,
277,
304,
267,
372,
822,
8,
277,
14,
807,
9,
421,
199,
533,
6879,
24811,
10230,
8,
10230,
304,
272,
986,
421,
199,
533,
6879,
24811,
8,
807,
304,
272,
408,
272,
437,
5516,
402,
2600,
26707,
370,
2429,
3663,
1338,
367,
314,
272,
2011,
790,
14,
339,
1306,
366,
275,
6879,
24811,
3252,
354,
356,
788,
2767,
18429,
297,
283,
7467,
265,
995,
283,
3124,
356,
788,
31032,
13678,
272,
1306,
366,
459,
354,
418,
272,
283,
7467,
265,
7,
272,
1306,
366,
14,
21343,
360,
354,
358,
272,
788,
2767,
18429,
297,
283,
7467,
265,
418,
272,
1306,
366,
14,
21343,
360,
9105,
889,
3858,
631,
358,
272,
942,
272,
1306,
366,
14,
21343,
360,
9105,
889,
3858,
631,
297,
788,
2767,
18429,
297,
283,
7467,
265,
1105,
272,
788,
2767,
18429,
297,
283,
7467,
265,
418,
272,
1306,
366,
14,
362,
360,
31164,
297,
283,
21573,
358,
272,
283,
21573,
7,
272,
1306,
366,
14,
409,
513,
360,
31164,
297,
788,
17810,
320,
16305,
89,
297,
283,
55,
8148,
834,
1105,
339,
961,
1021,
3495,
370,
14241,
314,
8190,
11133,
1958,
5160,
4915,
701,
16004,
14,
1122,
63,
6177,
12,
272,
1314,
2529,
282,
769,
367,
4036,
790,
12,
2755,
10617,
4750,
6001,
4513,
11482,
272,
2849,
536,
13,
585,
6342,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
790,
63,
475,
63,
513,
63,
4745,
23603,
267,
1613,
8,
3947,
24811,
12,
291,
2843,
826,
721,
498,
63,
475,
63,
513,
63,
4745,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
23054,
83,
26,
450,
83,
4335,
450,
334,
277,
855,
533,
4914,
354,
3108,
2490,
1613,
8,
3947,
24811,
12,
291,
2843,
2722,
29133,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
408,
267,
1803,
314,
2061,
666,
574,
367,
642,
790,
12,
503,
942,
340,
652,
1159,
376,
2701,
769,
27,
267,
6534,
4067,
340,
440,
1911,
14,
267,
408,
267,
862,
26,
288,
769,
63,
275,
1613,
8,
3947,
24811,
12,
291,
2843,
6095,
721,
498,
9,
267,
871,
4067,
26,
288,
746,
6879,
24811,
10230,
8,
2722,
8,
498,
430,
267,
862,
26,
288,
372,
769,
63,
1988,
17,
61,
267,
871,
7888,
26,
288,
372,
942,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
1613,
8,
3947,
24811,
12,
291,
2843,
8617,
721,
498,
12,
359,
585,
566,
339,
347,
636,
1574,
721,
277,
304,
267,
372,
291,
855,
533,
721,
59,
288,
334,
75,
12,
373,
1491,
566,
288,
367,
1022,
12,
373,
315,
291,
14,
6717,
342,
267,
4794,
339,
347,
636,
8293,
721,
277,
12,
11955,
29,
403,
304,
267,
340,
11955,
365,
488,
26,
288,
11955,
275,
1052,
267,
754,
275,
291,
855,
533,
4533,
267,
11955,
59,
344,
8,
277,
1874,
275,
754,
267,
367,
790,
12,
574,
315,
1211,
14,
1744,
8,
277,
304,
288,
1211,
855,
8617,
721,
1099,
12,
1331,
14,
8293,
8,
498,
12,
11955,
395,
2490,
1331,
14,
8293,
8,
585,
12,
11955,
430,
267,
372,
754,
339,
347,
636,
16011,
721,
277,
304,
267,
1559,
63,
807,
275,
291,
855,
807,
4343,
1574,
342,
267,
1559,
63,
807,
8680,
576,
418,
275,
469,
75,
26,
291,
14,
21343,
8,
75,
9,
367,
1022,
315,
291,
93,
267,
372,
1559,
63,
807,
339,
347,
636,
17212,
721,
277,
12,
1559,
63,
807,
304,
267,
666,
275,
1559,
63,
807,
14,
1935,
6412,
576,
297,
5009,
267,
367,
1022,
12,
373,
315,
666,
14,
1744,
837,
288,
291,
14,
409,
513,
8,
75,
12,
373,
9,
267,
291,
855,
807,
4343,
873,
8,
1113,
63,
807,
9,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
408,
267,
1803,
314,
2061,
666,
574,
367,
314,
3032,
790,
14,
982,
790,
3181,
1133,
2187,
267,
503,
574,
365,
376,
2701,
769,
12,
2066,
849,
365,
2138,
14,
267,
408,
267,
862,
26,
288,
1139,
275,
291,
59,
498,
61,
267,
871,
4067,
26,
288,
372,
849,
267,
340,
1139,
508,
18410,
288,
372,
849,
267,
372,
1139,
339,
347,
664,
513,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
408,
267,
1803,
314,
769,
402,
1338,
367,
314,
3032,
790,
14,
982,
790,
3181,
1133,
2187,
12,
267,
2066,
282,
849,
574,
365,
2138,
14,
267,
408,
267,
862,
26,
288,
372,
1613,
8,
3947,
24811,
12,
291,
2843,
6095,
721,
498,
9,
267,
871,
4067,
26,
288,
340,
849,
365,
488,
26,
355,
372,
942,
288,
372,
849,
339,
347,
663,
513,
8,
277,
12,
790,
12,
769,
7822,
267,
1613,
8,
3947,
24811,
12,
291,
2843,
8617,
721,
498,
12,
769,
4602,
339,
347,
29408,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
340,
790,
440,
315,
291,
26,
288,
291,
59,
498,
61,
275,
849,
288,
327,
4226,
440,
372,
849,
2348,
2952,
636,
8617,
4533,
1443,
3877
] |
[
1331,
199,
504,
5055,
492,
8773,
199,
199,
504,
1639,
14,
1208,
492,
3816,
421,
199,
533,
23617,
8,
785,
304,
272,
408,
272,
437,
663,
1314,
18578,
314,
7794,
402,
314,
11788,
2974,
14,
272,
13550,
1771,
83,
14602,
8773,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
6076,
29,
403,
304,
267,
291,
14,
807,
275,
8773,
12925,
88,
12,
488,
9,
367,
671,
315,
6076,
9,
340,
6076,
587,
3073,
339,
347,
1050,
8,
277,
12,
1242,
304,
267,
291,
14,
807,
59,
1053,
61,
275,
488,
339,
347,
2813,
8,
277,
12,
1242,
304,
267,
2150,
291,
14,
807,
59,
1053,
61,
339,
347,
16895,
8,
277,
12,
1242,
304,
267,
862,
26,
288,
291,
14,
2168,
8,
1053,
9,
267,
871,
4067,
26,
288,
986,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
14,
807,
14,
1612,
1012,
339,
347,
636,
6134,
721,
277,
12,
1242,
304,
267,
372,
1242,
315,
291,
14,
807,
339,
347,
636,
2245,
721,
277,
304,
267,
372,
2155,
8,
277,
14,
807,
9,
339,
347,
636,
10262,
721,
277,
304,
420,
327,
2018,
499,
7163,
267,
372,
730,
8,
277,
2843,
2245,
721,
277,
9,
339,
347,
636,
552,
721,
277,
304,
267,
372,
822,
8,
277,
14,
807,
9,
421,
199,
533,
6879,
24811,
10230,
8,
10230,
304,
272,
986,
421,
199,
533,
6879,
24811,
8,
807,
304,
272,
408,
272,
437,
5516,
402,
2600,
26707,
370,
2429,
3663,
1338,
367,
314,
272,
2011,
790,
14,
339,
1306,
366,
275,
6879,
24811,
3252,
354,
356,
788,
2767,
18429,
297,
283,
7467,
265,
995,
283,
3124,
356,
788,
31032,
13678,
272,
1306,
366,
459,
354,
418,
272,
283,
7467,
265,
7,
272,
1306,
366,
14,
21343,
360,
354,
358,
272,
788,
2767,
18429,
297,
283,
7467,
265,
418,
272,
1306,
366,
14,
21343,
360,
9105,
889,
3858,
631,
358,
272,
942,
272,
1306,
366,
14,
21343,
360,
9105,
889,
3858,
631,
297,
788,
2767,
18429,
297,
283,
7467,
265,
1105,
272,
788,
2767,
18429,
297,
283,
7467,
265,
418,
272,
1306,
366,
14,
362,
360,
31164,
297,
283,
21573,
358,
272,
283,
21573,
7,
272,
1306,
366,
14,
409,
513,
360,
31164,
297,
788,
17810,
320,
16305,
89,
297,
283,
55,
8148,
834,
1105,
339,
961,
1021,
3495,
370,
14241,
314,
8190,
11133,
1958,
5160,
4915,
701,
16004,
14,
1122,
63,
6177,
12,
272,
1314,
2529,
282,
769,
367,
4036,
790,
12,
2755,
10617,
4750,
6001,
4513,
11482,
272,
2849,
536,
13,
585,
6342,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
790,
63,
475,
63,
513,
63,
4745,
23603,
267,
1613,
8,
3947,
24811,
12,
291,
2843,
826,
721,
498,
63,
475,
63,
513,
63,
4745,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
23054,
83,
26,
450,
83,
4335,
450,
334,
277,
855,
533,
4914,
354,
3108,
2490,
1613,
8,
3947,
24811,
12,
291,
2843,
2722,
29133,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
408,
267,
1803,
314,
2061,
666,
574,
367,
642,
790,
12,
503,
942,
340,
652,
1159,
376,
2701,
769,
27,
267,
6534,
4067,
340,
440,
1911,
14,
267,
408,
267,
862,
26,
288,
769,
63,
275,
1613,
8,
3947,
24811,
12,
291,
2843,
6095,
721,
498,
9,
267,
871,
4067,
26,
288,
746,
6879,
24811,
10230,
8,
2722,
8,
498,
430,
267,
862,
26,
288,
372,
769,
63,
1988,
17,
61,
267,
871,
7888,
26,
288,
372,
942,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
1613,
8,
3947,
24811,
12,
291,
2843,
8617,
721,
498,
12,
359,
585,
566,
339,
347,
636,
1574,
721,
277,
304,
267,
372,
291,
855,
533,
721,
59,
288,
334,
75,
12,
373,
1491,
566,
288,
367,
1022,
12,
373,
315,
291,
14,
6717,
342,
267,
4794,
339,
347,
636,
8293,
721,
277,
12,
11955,
29,
403,
304,
267,
340,
11955,
365,
488,
26,
288,
11955,
275,
1052,
267,
754,
275,
291,
855,
533,
4533,
267,
11955,
59,
344,
8,
277,
1874,
275,
754,
267,
367,
790,
12,
574,
315,
1211,
14,
1744,
8,
277,
304,
288,
1211,
855,
8617,
721,
1099,
12,
1331,
14,
8293,
8,
498,
12,
11955,
395,
2490,
1331,
14,
8293,
8,
585,
12,
11955,
430,
267,
372,
754,
339,
347,
636,
16011,
721,
277,
304,
267,
1559,
63,
807,
275,
291,
855,
807,
4343,
1574,
342,
267,
1559,
63,
807,
8680,
576,
418,
275,
469,
75,
26,
291,
14,
21343,
8,
75,
9,
367,
1022,
315,
291,
93,
267,
372,
1559,
63,
807,
339,
347,
636,
17212,
721,
277,
12,
1559,
63,
807,
304,
267,
666,
275,
1559,
63,
807,
14,
1935,
6412,
576,
297,
5009,
267,
367,
1022,
12,
373,
315,
666,
14,
1744,
837,
288,
291,
14,
409,
513,
8,
75,
12,
373,
9,
267,
291,
855,
807,
4343,
873,
8,
1113,
63,
807,
9,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
408,
267,
1803,
314,
2061,
666,
574,
367,
314,
3032,
790,
14,
982,
790,
3181,
1133,
2187,
267,
503,
574,
365,
376,
2701,
769,
12,
2066,
849,
365,
2138,
14,
267,
408,
267,
862,
26,
288,
1139,
275,
291,
59,
498,
61,
267,
871,
4067,
26,
288,
372,
849,
267,
340,
1139,
508,
18410,
288,
372,
849,
267,
372,
1139,
339,
347,
664,
513,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
408,
267,
1803,
314,
769,
402,
1338,
367,
314,
3032,
790,
14,
982,
790,
3181,
1133,
2187,
12,
267,
2066,
282,
849,
574,
365,
2138,
14,
267,
408,
267,
862,
26,
288,
372,
1613,
8,
3947,
24811,
12,
291,
2843,
6095,
721,
498,
9,
267,
871,
4067,
26,
288,
340,
849,
365,
488,
26,
355,
372,
942,
288,
372,
849,
339,
347,
663,
513,
8,
277,
12,
790,
12,
769,
7822,
267,
1613,
8,
3947,
24811,
12,
291,
2843,
8617,
721,
498,
12,
769,
4602,
339,
347,
29408,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
340,
790,
440,
315,
291,
26,
288,
291,
59,
498,
61,
275,
849,
288,
327,
4226,
440,
372,
849,
2348,
2952,
636,
8617,
4533,
1443,
3877,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kavitshah8/SDNDeveloper
|
pox/misc/packet_dump.py
|
46
|
2821
|
# Copyright 2012 James McCauley
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
A simple component that dumps packet_in info to the log.
Use --verbose for really verbose dumps.
Use --show to show all packets.
"""
from pox.core import core
import pox.openflow.libopenflow_01 as of
import pox.lib.packet as pkt
from pox.lib.util import dpidToStr
log = core.getLogger()
_verbose = None
_max_length = None
_types = None
_show_by_default = None
def _handle_PacketIn (event):
packet = event.parsed
show = _show_by_default
p = packet
while p:
if p.__class__.__name__.lower() in _types:
if _show_by_default:
# This packet is hidden
return
else:
# This packet should be shown
show = True
break
return
if not hasattr(p, 'next'): break
p = p.next
if not show: return
msg = dpidToStr(event.dpid) + ": "
msg = ""
if _verbose:
msg += packet.dump()
else:
p = packet
while p:
if isinstance(p, basestring):
msg += "[%s bytes]" % (len(p),)
break
msg += "[%s]" % (p.__class__.__name__,)
p = p.next
if _max_length:
if len(msg) > _max_length:
msg = msg[:_max_length-3]
msg += "..."
core.getLogger("dump:" + dpidToStr(event.dpid)).debug(msg)
def launch (verbose = False, max_length = 110, full_packets = True,
hide = False, show = False):
global _verbose, _max_length, _types, _show_by_default
_verbose = verbose
_max_length = max_length
force_show = (show is True) or (hide is False and show is False)
if isinstance(hide, basestring):
hide = hide.replace(',', ' ').replace('|', ' ')
hide = set([p.lower() for p in hide.split()])
else:
hide = set()
if isinstance(show, basestring):
show = show.replace(',', ' ').replace('|', ' ')
show = set([p.lower() for p in show.split()])
else:
show = set()
if hide and show:
raise RuntimeError("Can't both show and hide packet types")
if show:
_types = show
else:
_types = hide
_show_by_default = not not hide
if force_show:
_show_by_default = force_show
if full_packets:
# Send full packets to controller
core.openflow.miss_send_len = 0xffff
core.openflow.addListenerByName("PacketIn", _handle_PacketIn)
log.info("Packet dumper running")
|
apache-2.0
|
[
3,
1898,
6029,
1603,
14015,
22895,
3630,
443,
89,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
26,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
199,
33,
3486,
3931,
626,
16864,
3644,
63,
262,
2256,
370,
314,
943,
14,
199,
199,
6119,
1553,
3832,
367,
7710,
3376,
16864,
14,
199,
6119,
1553,
2384,
370,
2498,
1006,
14593,
14,
199,
624,
199,
199,
504,
1115,
88,
14,
1018,
492,
6170,
199,
646,
1115,
88,
14,
1490,
1659,
14,
773,
1490,
1659,
63,
614,
465,
402,
199,
646,
1115,
88,
14,
773,
14,
6253,
465,
19927,
199,
504,
1115,
88,
14,
773,
14,
1974,
492,
366,
3150,
1378,
2848,
199,
199,
793,
275,
6170,
14,
5572,
342,
199,
199,
63,
3832,
275,
488,
199,
63,
988,
63,
1267,
275,
488,
199,
63,
1313,
275,
488,
199,
63,
2384,
63,
991,
63,
885,
275,
488,
199,
199,
318,
485,
2479,
63,
2726,
607,
334,
1430,
304,
523,
3644,
275,
1566,
14,
6751,
819,
2498,
275,
485,
2384,
63,
991,
63,
885,
523,
299,
275,
3644,
523,
1830,
299,
26,
272,
340,
299,
855,
533,
4914,
354,
4343,
2325,
342,
315,
485,
1313,
26,
489,
340,
485,
2384,
63,
991,
63,
885,
26,
267,
327,
961,
3644,
365,
8752,
267,
372,
489,
587,
26,
267,
327,
961,
3644,
1077,
506,
9164,
267,
2498,
275,
715,
267,
2059,
489,
372,
272,
340,
440,
2688,
8,
80,
12,
283,
2184,
735,
2059,
272,
299,
275,
299,
14,
2184,
819,
340,
440,
2498,
26,
372,
819,
1499,
275,
366,
3150,
1378,
2848,
8,
1430,
14,
26050,
9,
435,
7244,
298,
523,
1499,
275,
3087,
523,
340,
485,
3832,
26,
272,
1499,
847,
3644,
14,
2724,
342,
523,
587,
26,
272,
299,
275,
3644,
272,
1830,
299,
26,
489,
340,
1228,
8,
80,
12,
7116,
304,
267,
1499,
847,
26503,
83,
2783,
8480,
450,
334,
552,
8,
80,
16945,
267,
2059,
489,
1499,
847,
26503,
83,
8480,
450,
334,
80,
855,
533,
4914,
354,
3108,
9,
489,
299,
275,
299,
14,
2184,
819,
340,
485,
988,
63,
1267,
26,
272,
340,
822,
8,
1328,
9,
690,
485,
988,
63,
1267,
26,
489,
1499,
275,
1499,
1491,
63,
988,
63,
1267,
13,
19,
61,
489,
1499,
847,
298,
11500,
523,
6170,
14,
5572,
480,
2724,
5424,
435,
366,
3150,
1378,
2848,
8,
1430,
14,
26050,
4992,
1757,
8,
1328,
9,
421,
199,
318,
10623,
334,
3832,
275,
756,
12,
1390,
63,
1267,
275,
16814,
12,
2615,
63,
18853,
275,
715,
12,
288,
13714,
275,
756,
12,
2498,
275,
756,
304,
523,
2288,
485,
3832,
12,
485,
988,
63,
1267,
12,
485,
1313,
12,
485,
2384,
63,
991,
63,
885,
523,
485,
3832,
275,
3376,
523,
485,
988,
63,
1267,
275,
1390,
63,
1267,
523,
3542,
63,
2384,
275,
334,
2384,
365,
715,
9,
503,
334,
8191,
365,
756,
436,
2498,
365,
756,
9,
523,
340,
1228,
8,
8191,
12,
7116,
304,
272,
13714,
275,
13714,
14,
1814,
32718,
283,
27274,
1814,
20137,
297,
283,
5320,
272,
13714,
275,
663,
779,
80,
14,
2325,
342,
367,
299,
315,
13714,
14,
1294,
9383,
523,
587,
26,
272,
13714,
275,
663,
342,
523,
340,
1228,
8,
2384,
12,
7116,
304,
272,
2498,
275,
2498,
14,
1814,
32718,
283,
27274,
1814,
20137,
297,
283,
5320,
272,
2498,
275,
663,
779,
80,
14,
2325,
342,
367,
299,
315,
2498,
14,
1294,
9383,
523,
587,
26,
272,
2498,
275,
663,
342,
819,
340,
13714,
436,
2498,
26,
272,
746,
6064,
480,
6049,
1133,
3865,
2498,
436,
13714,
3644,
2943,
531,
819,
340,
2498,
26,
272,
485,
1313,
275,
2498,
523,
587,
26,
272,
485,
1313,
275,
13714,
523,
485,
2384,
63,
991,
63,
885,
275,
440,
440,
13714,
523,
340,
3542,
63,
2384,
26,
272,
485,
2384,
63,
991,
63,
885,
275,
3542,
63,
2384,
819,
340,
2615,
63,
18853,
26,
272,
327,
10217,
2615,
14593,
370,
7614,
272,
6170,
14,
1490,
1659,
14,
18420,
63,
2254,
63,
552,
275,
378,
27581,
819,
6170,
14,
1490,
1659,
14,
525,
10464,
11190,
480,
2726,
607,
401,
485,
2479,
63,
2726,
607,
9,
819,
943,
14,
815,
480,
2726,
5461,
281,
3879,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6029,
1603,
14015,
22895,
3630,
443,
89,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
26,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
199,
33,
3486,
3931,
626,
16864,
3644,
63,
262,
2256,
370,
314,
943,
14,
199,
199,
6119,
1553,
3832,
367,
7710,
3376,
16864,
14,
199,
6119,
1553,
2384,
370,
2498,
1006,
14593,
14,
199,
624,
199,
199,
504,
1115,
88,
14,
1018,
492,
6170,
199,
646,
1115,
88,
14,
1490,
1659,
14,
773,
1490,
1659,
63,
614,
465,
402,
199,
646,
1115,
88,
14,
773,
14,
6253,
465,
19927,
199,
504,
1115,
88,
14,
773,
14,
1974,
492,
366,
3150,
1378,
2848,
199,
199,
793,
275,
6170,
14,
5572,
342,
199,
199,
63,
3832,
275,
488,
199,
63,
988,
63,
1267,
275,
488,
199,
63,
1313,
275,
488,
199,
63,
2384,
63,
991,
63,
885,
275,
488,
199,
199,
318,
485,
2479,
63,
2726,
607,
334,
1430,
304,
523,
3644,
275,
1566,
14,
6751,
819,
2498,
275,
485,
2384,
63,
991,
63,
885,
523,
299,
275,
3644,
523,
1830,
299,
26,
272,
340,
299,
855,
533,
4914,
354,
4343,
2325,
342,
315,
485,
1313,
26,
489,
340,
485,
2384,
63,
991,
63,
885,
26,
267,
327,
961,
3644,
365,
8752,
267,
372,
489,
587,
26,
267,
327,
961,
3644,
1077,
506,
9164,
267,
2498,
275,
715,
267,
2059,
489,
372,
272,
340,
440,
2688,
8,
80,
12,
283,
2184,
735,
2059,
272,
299,
275,
299,
14,
2184,
819,
340,
440,
2498,
26,
372,
819,
1499,
275,
366,
3150,
1378,
2848,
8,
1430,
14,
26050,
9,
435,
7244,
298,
523,
1499,
275,
3087,
523,
340,
485,
3832,
26,
272,
1499,
847,
3644,
14,
2724,
342,
523,
587,
26,
272,
299,
275,
3644,
272,
1830,
299,
26,
489,
340,
1228,
8,
80,
12,
7116,
304,
267,
1499,
847,
26503,
83,
2783,
8480,
450,
334,
552,
8,
80,
16945,
267,
2059,
489,
1499,
847,
26503,
83,
8480,
450,
334,
80,
855,
533,
4914,
354,
3108,
9,
489,
299,
275,
299,
14,
2184,
819,
340,
485,
988,
63,
1267,
26,
272,
340,
822,
8,
1328,
9,
690,
485,
988,
63,
1267,
26,
489,
1499,
275,
1499,
1491,
63,
988,
63,
1267,
13,
19,
61,
489,
1499,
847,
298,
11500,
523,
6170,
14,
5572,
480,
2724,
5424,
435,
366,
3150,
1378,
2848,
8,
1430,
14,
26050,
4992,
1757,
8,
1328,
9,
421,
199,
318,
10623,
334,
3832,
275,
756,
12,
1390,
63,
1267,
275,
16814,
12,
2615,
63,
18853,
275,
715,
12,
288,
13714,
275,
756,
12,
2498,
275,
756,
304,
523,
2288,
485,
3832,
12,
485,
988,
63,
1267,
12,
485,
1313,
12,
485,
2384,
63,
991,
63,
885,
523,
485,
3832,
275,
3376,
523,
485,
988,
63,
1267,
275,
1390,
63,
1267,
523,
3542,
63,
2384,
275,
334,
2384,
365,
715,
9,
503,
334,
8191,
365,
756,
436,
2498,
365,
756,
9,
523,
340,
1228,
8,
8191,
12,
7116,
304,
272,
13714,
275,
13714,
14,
1814,
32718,
283,
27274,
1814,
20137,
297,
283,
5320,
272,
13714,
275,
663,
779,
80,
14,
2325,
342,
367,
299,
315,
13714,
14,
1294,
9383,
523,
587,
26,
272,
13714,
275,
663,
342,
523,
340,
1228,
8,
2384,
12,
7116,
304,
272,
2498,
275,
2498,
14,
1814,
32718,
283,
27274,
1814,
20137,
297,
283,
5320,
272,
2498,
275,
663,
779,
80,
14,
2325,
342,
367,
299,
315,
2498,
14,
1294,
9383,
523,
587,
26,
272,
2498,
275,
663,
342,
819,
340,
13714,
436,
2498,
26,
272,
746,
6064,
480,
6049,
1133,
3865,
2498,
436,
13714,
3644,
2943,
531,
819,
340,
2498,
26,
272,
485,
1313,
275,
2498,
523,
587,
26,
272,
485,
1313,
275,
13714,
523,
485,
2384,
63,
991,
63,
885,
275,
440,
440,
13714,
523,
340,
3542,
63,
2384,
26,
272,
485,
2384,
63,
991,
63,
885,
275,
3542,
63,
2384,
819,
340,
2615,
63,
18853,
26,
272,
327,
10217,
2615,
14593,
370,
7614,
272,
6170,
14,
1490,
1659,
14,
18420,
63,
2254,
63,
552,
275,
378,
27581,
819,
6170,
14,
1490,
1659,
14,
525,
10464,
11190,
480,
2726,
607,
401,
485,
2479,
63,
2726,
607,
9,
819,
943,
14,
815,
480,
2726,
5461,
281,
3879,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
amaniak/fabric
|
tests/test_project.py
|
38
|
5250
|
import unittest
import os
import fudge
from fudge.inspector import arg
from fabric.contrib import project
class UploadProjectTestCase(unittest.TestCase):
"""Test case for :func: `fabric.contrib.project.upload_project`."""
fake_tmp = "testtempfolder"
def setUp(self):
fudge.clear_expectations()
# We need to mock out run, local, and put
self.fake_run = fudge.Fake('project.run', callable=True)
self.patched_run = fudge.patch_object(
project,
'run',
self.fake_run
)
self.fake_local = fudge.Fake('local', callable=True)
self.patched_local = fudge.patch_object(
project,
'local',
self.fake_local
)
self.fake_put = fudge.Fake('put', callable=True)
self.patched_put = fudge.patch_object(
project,
'put',
self.fake_put
)
# We don't want to create temp folders
self.fake_mkdtemp = fudge.Fake(
'mkdtemp',
expect_call=True
).returns(self.fake_tmp)
self.patched_mkdtemp = fudge.patch_object(
project,
'mkdtemp',
self.fake_mkdtemp
)
def tearDown(self):
self.patched_run.restore()
self.patched_local.restore()
self.patched_put.restore()
fudge.clear_expectations()
@fudge.with_fakes
def test_temp_folder_is_used(self):
"""A unique temp folder is used for creating the archive to upload."""
# Exercise
project.upload_project()
@fudge.with_fakes
def test_project_is_archived_locally(self):
"""The project should be archived locally before being uploaded."""
# local() is called more than once so we need an extra next_call()
# otherwise fudge compares the args to the last call to local()
self.fake_local.with_args(arg.startswith("tar -czf")).next_call()
# Exercise
project.upload_project()
@fudge.with_fakes
def test_current_directory_is_uploaded_by_default(self):
"""By default the project uploaded is the current working directory."""
cwd_path, cwd_name = os.path.split(os.getcwd())
# local() is called more than once so we need an extra next_call()
# otherwise fudge compares the args to the last call to local()
self.fake_local.with_args(
arg.endswith("-C %s %s" % (cwd_path, cwd_name))
).next_call()
# Exercise
project.upload_project()
@fudge.with_fakes
def test_path_to_local_project_can_be_specified(self):
"""It should be possible to specify which local folder to upload."""
project_path = "path/to/my/project"
# local() is called more than once so we need an extra next_call()
# otherwise fudge compares the args to the last call to local()
self.fake_local.with_args(
arg.endswith("-C %s %s" % os.path.split(project_path))
).next_call()
# Exercise
project.upload_project(local_dir=project_path)
@fudge.with_fakes
def test_path_to_local_project_can_end_in_separator(self):
"""A local path ending in a separator should be handled correctly."""
project_path = "path/to/my"
base = "project"
# local() is called more than once so we need an extra next_call()
# otherwise fudge compares the args to the last call to local()
self.fake_local.with_args(
arg.endswith("-C %s %s" % (project_path, base))
).next_call()
# Exercise
project.upload_project(local_dir="%s/%s/" % (project_path, base))
@fudge.with_fakes
def test_default_remote_folder_is_home(self):
"""Project is uploaded to remote home by default."""
local_dir = "folder"
# local() is called more than once so we need an extra next_call()
# otherwise fudge compares the args to the last call to local()
self.fake_put.with_args(
"%s/folder.tar.gz" % self.fake_tmp, "folder.tar.gz", use_sudo=False
).next_call()
# Exercise
project.upload_project(local_dir=local_dir)
@fudge.with_fakes
def test_path_to_remote_folder_can_be_specified(self):
"""It should be possible to specify which local folder to upload to."""
local_dir = "folder"
remote_path = "path/to/remote/folder"
# local() is called more than once so we need an extra next_call()
# otherwise fudge compares the args to the last call to local()
self.fake_put.with_args(
"%s/folder.tar.gz" % self.fake_tmp, "%s/folder.tar.gz" % remote_path, use_sudo=False
).next_call()
# Exercise
project.upload_project(local_dir=local_dir, remote_dir=remote_path)
|
bsd-2-clause
|
[
646,
2882,
199,
646,
747,
199,
199,
646,
289,
16603,
199,
504,
289,
16603,
14,
26047,
492,
1680,
199,
199,
504,
2630,
14,
2828,
492,
2199,
421,
199,
533,
19149,
4761,
1746,
8,
2796,
14,
1746,
304,
272,
408,
774,
1930,
367,
520,
1532,
26,
658,
4991,
14,
2828,
14,
1715,
14,
5064,
63,
1715,
17105,
339,
4026,
63,
2791,
275,
298,
396,
808,
3741,
2,
2378,
347,
3613,
8,
277,
304,
267,
289,
16603,
14,
3584,
63,
15752,
342,
398,
327,
2136,
1929,
370,
1683,
734,
1255,
12,
2257,
12,
436,
5324,
398,
291,
14,
3183,
63,
1065,
275,
289,
16603,
14,
8249,
360,
1715,
14,
1065,
297,
4550,
29,
549,
9,
267,
291,
14,
22631,
63,
1065,
275,
289,
16603,
14,
2068,
63,
785,
8,
3044,
2199,
12,
3044,
283,
1065,
297,
3044,
291,
14,
3183,
63,
1065,
2574,
776,
398,
291,
14,
3183,
63,
1832,
275,
289,
16603,
14,
8249,
360,
1832,
297,
4550,
29,
549,
9,
267,
291,
14,
22631,
63,
1832,
275,
289,
16603,
14,
2068,
63,
785,
8,
639,
2199,
12,
639,
283,
1832,
297,
639,
291,
14,
3183,
63,
1832,
2490,
776,
398,
291,
14,
3183,
63,
524,
275,
289,
16603,
14,
8249,
360,
524,
297,
4550,
29,
549,
9,
267,
291,
14,
22631,
63,
524,
275,
289,
16603,
14,
2068,
63,
785,
8,
3044,
2199,
12,
3044,
283,
524,
297,
3044,
291,
14,
3183,
63,
524,
2574,
776,
398,
327,
2136,
2793,
1133,
2934,
370,
1218,
2388,
16533,
267,
291,
14,
3183,
63,
11983,
275,
289,
16603,
14,
8249,
8,
1816,
283,
11983,
297,
1816,
4282,
63,
1250,
29,
549,
1169,
7092,
5808,
8,
277,
14,
3183,
63,
2791,
9,
267,
291,
14,
22631,
63,
11983,
275,
289,
16603,
14,
2068,
63,
785,
8,
3521,
2199,
12,
3521,
283,
11983,
297,
3521,
291,
14,
3183,
63,
11983,
3044,
776,
2378,
347,
6766,
8,
277,
304,
267,
291,
14,
22631,
63,
1065,
14,
8011,
342,
267,
291,
14,
22631,
63,
1832,
14,
8011,
342,
267,
291,
14,
22631,
63,
524,
14,
8011,
342,
398,
289,
16603,
14,
3584,
63,
15752,
342,
2378,
768,
70,
16603,
14,
1045,
63,
27443,
272,
347,
511,
63,
808,
63,
3741,
63,
374,
63,
2972,
8,
277,
304,
267,
408,
33,
3747,
2388,
4922,
365,
1202,
367,
6425,
314,
6359,
370,
5802,
1041,
398,
327,
1316,
20616,
267,
2199,
14,
5064,
63,
1715,
342,
2378,
768,
70,
16603,
14,
1045,
63,
27443,
272,
347,
511,
63,
1715,
63,
374,
63,
1047,
12905,
63,
31294,
8,
277,
304,
267,
408,
1918,
2199,
1077,
506,
3819,
12905,
17738,
2544,
3769,
14238,
1041,
398,
327,
2257,
342,
365,
2797,
1655,
2419,
5403,
880,
781,
1929,
376,
2402,
2163,
63,
1250,
342,
267,
327,
4257,
289,
16603,
30827,
314,
1249,
370,
314,
2061,
1240,
370,
2257,
342,
267,
291,
14,
3183,
63,
1832,
14,
1045,
63,
589,
8,
1273,
14,
2460,
480,
5369,
446,
16823,
70,
21688,
2184,
63,
1250,
342,
398,
327,
1316,
20616,
267,
2199,
14,
5064,
63,
1715,
342,
2378,
768,
70,
16603,
14,
1045,
63,
27443,
272,
347,
511,
63,
1818,
63,
3619,
63,
374,
63,
19044,
63,
991,
63,
885,
8,
277,
304,
267,
408,
2175,
849,
314,
2199,
14238,
365,
314,
1453,
6449,
2082,
1041,
398,
8288,
63,
515,
12,
8288,
63,
354,
275,
747,
14,
515,
14,
1294,
8,
736,
14,
9458,
1012,
398,
327,
2257,
342,
365,
2797,
1655,
2419,
5403,
880,
781,
1929,
376,
2402,
2163,
63,
1250,
342,
267,
327,
4257,
289,
16603,
30827,
314,
1249,
370,
314,
2061,
1240,
370,
2257,
342,
267,
291,
14,
3183,
63,
1832,
14,
1045,
63,
589,
8,
288,
1680,
14,
4130,
6096,
35,
450,
83,
450,
83,
2,
450,
334,
6525,
63,
515,
12,
8288,
63,
354,
430,
267,
7092,
2184,
63,
1250,
342,
398,
327,
1316,
20616,
267,
2199,
14,
5064,
63,
1715,
342,
2378,
768,
70,
16603,
14,
1045,
63,
27443,
272,
347,
511,
63,
515,
63,
475,
63,
1832,
63,
1715,
63,
2425,
63,
1235,
63,
10085,
8,
277,
304,
267,
408,
7940,
1077,
506,
3962,
370,
4165,
1314,
2257,
4922,
370,
5802,
1041,
398,
2199,
63,
515,
275,
298,
515,
15,
475,
15,
1662,
15,
1715,
2,
398,
327,
2257,
342,
365,
2797,
1655,
2419,
5403,
880,
781,
1929,
376,
2402,
2163,
63,
1250,
342,
267,
327,
4257,
289,
16603,
30827,
314,
1249,
370,
314,
2061,
1240,
370,
2257,
342,
267,
291,
14,
3183,
63,
1832,
14,
1045,
63,
589,
8,
288,
1680,
14,
4130,
6096,
35,
450,
83,
450,
83,
2,
450,
747,
14,
515,
14,
1294,
8,
1715,
63,
515,
430,
267,
7092,
2184,
63,
1250,
342,
398,
327,
1316,
20616,
267,
2199,
14,
5064,
63,
1715,
8,
1832,
63,
694,
29,
1715,
63,
515,
9,
2378,
768,
70,
16603,
14,
1045,
63,
27443,
272,
347,
511,
63,
515,
63,
475,
63,
1832,
63,
1715,
63,
2425,
63,
500,
63,
262,
63,
9896,
8,
277,
304,
267,
408,
33,
2257,
931,
13401,
315,
282,
9432,
1077,
506,
8860,
6657,
1041,
398,
2199,
63,
515,
275,
298,
515,
15,
475,
15,
1662,
2,
267,
1300,
275,
298,
1715,
2,
398,
327,
2257,
342,
365,
2797,
1655,
2419,
5403,
880,
781,
1929,
376,
2402,
2163,
63,
1250,
342,
267,
327,
4257,
289,
16603,
30827,
314,
1249,
370,
314,
2061,
1240,
370,
2257,
342,
267,
291,
14,
3183,
63,
1832,
14,
1045,
63,
589,
8,
288,
1680,
14,
4130,
6096,
35,
450,
83,
450,
83,
2,
450,
334,
1715,
63,
515,
12,
1300,
430,
267,
7092,
2184,
63,
1250,
342,
398,
327,
1316,
20616,
267,
2199,
14,
5064,
63,
1715,
8,
1832,
63,
694,
5961,
83,
3149,
83,
6687,
450,
334,
1715,
63,
515,
12,
1300,
430,
2378,
768,
70,
16603,
14,
1045,
63,
27443,
272,
347,
511,
63,
885,
63,
3846,
63,
3741,
63,
374,
63,
4219,
8,
277,
304,
267,
408,
4761,
365,
14238,
370,
3982,
5629,
701,
849,
1041,
398,
2257,
63,
694,
275,
298,
3741,
2,
398,
327,
2257,
342,
365,
2797,
1655,
2419,
5403,
880,
781,
1929,
376,
2402,
2163,
63,
1250,
342,
267,
327,
4257,
289,
16603,
30827,
314,
1249,
370,
314,
2061,
1240,
370,
2257,
342,
267,
291,
14
] |
[
2882,
199,
646,
747,
199,
199,
646,
289,
16603,
199,
504,
289,
16603,
14,
26047,
492,
1680,
199,
199,
504,
2630,
14,
2828,
492,
2199,
421,
199,
533,
19149,
4761,
1746,
8,
2796,
14,
1746,
304,
272,
408,
774,
1930,
367,
520,
1532,
26,
658,
4991,
14,
2828,
14,
1715,
14,
5064,
63,
1715,
17105,
339,
4026,
63,
2791,
275,
298,
396,
808,
3741,
2,
2378,
347,
3613,
8,
277,
304,
267,
289,
16603,
14,
3584,
63,
15752,
342,
398,
327,
2136,
1929,
370,
1683,
734,
1255,
12,
2257,
12,
436,
5324,
398,
291,
14,
3183,
63,
1065,
275,
289,
16603,
14,
8249,
360,
1715,
14,
1065,
297,
4550,
29,
549,
9,
267,
291,
14,
22631,
63,
1065,
275,
289,
16603,
14,
2068,
63,
785,
8,
3044,
2199,
12,
3044,
283,
1065,
297,
3044,
291,
14,
3183,
63,
1065,
2574,
776,
398,
291,
14,
3183,
63,
1832,
275,
289,
16603,
14,
8249,
360,
1832,
297,
4550,
29,
549,
9,
267,
291,
14,
22631,
63,
1832,
275,
289,
16603,
14,
2068,
63,
785,
8,
639,
2199,
12,
639,
283,
1832,
297,
639,
291,
14,
3183,
63,
1832,
2490,
776,
398,
291,
14,
3183,
63,
524,
275,
289,
16603,
14,
8249,
360,
524,
297,
4550,
29,
549,
9,
267,
291,
14,
22631,
63,
524,
275,
289,
16603,
14,
2068,
63,
785,
8,
3044,
2199,
12,
3044,
283,
524,
297,
3044,
291,
14,
3183,
63,
524,
2574,
776,
398,
327,
2136,
2793,
1133,
2934,
370,
1218,
2388,
16533,
267,
291,
14,
3183,
63,
11983,
275,
289,
16603,
14,
8249,
8,
1816,
283,
11983,
297,
1816,
4282,
63,
1250,
29,
549,
1169,
7092,
5808,
8,
277,
14,
3183,
63,
2791,
9,
267,
291,
14,
22631,
63,
11983,
275,
289,
16603,
14,
2068,
63,
785,
8,
3521,
2199,
12,
3521,
283,
11983,
297,
3521,
291,
14,
3183,
63,
11983,
3044,
776,
2378,
347,
6766,
8,
277,
304,
267,
291,
14,
22631,
63,
1065,
14,
8011,
342,
267,
291,
14,
22631,
63,
1832,
14,
8011,
342,
267,
291,
14,
22631,
63,
524,
14,
8011,
342,
398,
289,
16603,
14,
3584,
63,
15752,
342,
2378,
768,
70,
16603,
14,
1045,
63,
27443,
272,
347,
511,
63,
808,
63,
3741,
63,
374,
63,
2972,
8,
277,
304,
267,
408,
33,
3747,
2388,
4922,
365,
1202,
367,
6425,
314,
6359,
370,
5802,
1041,
398,
327,
1316,
20616,
267,
2199,
14,
5064,
63,
1715,
342,
2378,
768,
70,
16603,
14,
1045,
63,
27443,
272,
347,
511,
63,
1715,
63,
374,
63,
1047,
12905,
63,
31294,
8,
277,
304,
267,
408,
1918,
2199,
1077,
506,
3819,
12905,
17738,
2544,
3769,
14238,
1041,
398,
327,
2257,
342,
365,
2797,
1655,
2419,
5403,
880,
781,
1929,
376,
2402,
2163,
63,
1250,
342,
267,
327,
4257,
289,
16603,
30827,
314,
1249,
370,
314,
2061,
1240,
370,
2257,
342,
267,
291,
14,
3183,
63,
1832,
14,
1045,
63,
589,
8,
1273,
14,
2460,
480,
5369,
446,
16823,
70,
21688,
2184,
63,
1250,
342,
398,
327,
1316,
20616,
267,
2199,
14,
5064,
63,
1715,
342,
2378,
768,
70,
16603,
14,
1045,
63,
27443,
272,
347,
511,
63,
1818,
63,
3619,
63,
374,
63,
19044,
63,
991,
63,
885,
8,
277,
304,
267,
408,
2175,
849,
314,
2199,
14238,
365,
314,
1453,
6449,
2082,
1041,
398,
8288,
63,
515,
12,
8288,
63,
354,
275,
747,
14,
515,
14,
1294,
8,
736,
14,
9458,
1012,
398,
327,
2257,
342,
365,
2797,
1655,
2419,
5403,
880,
781,
1929,
376,
2402,
2163,
63,
1250,
342,
267,
327,
4257,
289,
16603,
30827,
314,
1249,
370,
314,
2061,
1240,
370,
2257,
342,
267,
291,
14,
3183,
63,
1832,
14,
1045,
63,
589,
8,
288,
1680,
14,
4130,
6096,
35,
450,
83,
450,
83,
2,
450,
334,
6525,
63,
515,
12,
8288,
63,
354,
430,
267,
7092,
2184,
63,
1250,
342,
398,
327,
1316,
20616,
267,
2199,
14,
5064,
63,
1715,
342,
2378,
768,
70,
16603,
14,
1045,
63,
27443,
272,
347,
511,
63,
515,
63,
475,
63,
1832,
63,
1715,
63,
2425,
63,
1235,
63,
10085,
8,
277,
304,
267,
408,
7940,
1077,
506,
3962,
370,
4165,
1314,
2257,
4922,
370,
5802,
1041,
398,
2199,
63,
515,
275,
298,
515,
15,
475,
15,
1662,
15,
1715,
2,
398,
327,
2257,
342,
365,
2797,
1655,
2419,
5403,
880,
781,
1929,
376,
2402,
2163,
63,
1250,
342,
267,
327,
4257,
289,
16603,
30827,
314,
1249,
370,
314,
2061,
1240,
370,
2257,
342,
267,
291,
14,
3183,
63,
1832,
14,
1045,
63,
589,
8,
288,
1680,
14,
4130,
6096,
35,
450,
83,
450,
83,
2,
450,
747,
14,
515,
14,
1294,
8,
1715,
63,
515,
430,
267,
7092,
2184,
63,
1250,
342,
398,
327,
1316,
20616,
267,
2199,
14,
5064,
63,
1715,
8,
1832,
63,
694,
29,
1715,
63,
515,
9,
2378,
768,
70,
16603,
14,
1045,
63,
27443,
272,
347,
511,
63,
515,
63,
475,
63,
1832,
63,
1715,
63,
2425,
63,
500,
63,
262,
63,
9896,
8,
277,
304,
267,
408,
33,
2257,
931,
13401,
315,
282,
9432,
1077,
506,
8860,
6657,
1041,
398,
2199,
63,
515,
275,
298,
515,
15,
475,
15,
1662,
2,
267,
1300,
275,
298,
1715,
2,
398,
327,
2257,
342,
365,
2797,
1655,
2419,
5403,
880,
781,
1929,
376,
2402,
2163,
63,
1250,
342,
267,
327,
4257,
289,
16603,
30827,
314,
1249,
370,
314,
2061,
1240,
370,
2257,
342,
267,
291,
14,
3183,
63,
1832,
14,
1045,
63,
589,
8,
288,
1680,
14,
4130,
6096,
35,
450,
83,
450,
83,
2,
450,
334,
1715,
63,
515,
12,
1300,
430,
267,
7092,
2184,
63,
1250,
342,
398,
327,
1316,
20616,
267,
2199,
14,
5064,
63,
1715,
8,
1832,
63,
694,
5961,
83,
3149,
83,
6687,
450,
334,
1715,
63,
515,
12,
1300,
430,
2378,
768,
70,
16603,
14,
1045,
63,
27443,
272,
347,
511,
63,
885,
63,
3846,
63,
3741,
63,
374,
63,
4219,
8,
277,
304,
267,
408,
4761,
365,
14238,
370,
3982,
5629,
701,
849,
1041,
398,
2257,
63,
694,
275,
298,
3741,
2,
398,
327,
2257,
342,
365,
2797,
1655,
2419,
5403,
880,
781,
1929,
376,
2402,
2163,
63,
1250,
342,
267,
327,
4257,
289,
16603,
30827,
314,
1249,
370,
314,
2061,
1240,
370,
2257,
342,
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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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
] |
thompsnm/ancprb
|
flightpath/printrun/printrun/projectlayer.py
|
20
|
38361
|
# This file is part of the Printrun suite.
#
# Printrun 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.
#
# Printrun 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 Printrun. If not, see <http://www.gnu.org/licenses/>.
import xml.etree.ElementTree
import wx
import wx.lib.agw.floatspin as floatspin
import os
import time
import zipfile
import tempfile
import shutil
from cairosvg.surface import PNGSurface
import cStringIO
import imghdr
import copy
import re
from collections import OrderedDict
import itertools
import math
class DisplayFrame(wx.Frame):
def __init__(self, parent, title, res = (1024, 768), printer = None, scale = 1.0, offset = (0, 0)):
wx.Frame.__init__(self, parent = parent, title = title, size = res)
self.printer = printer
self.control_frame = parent
self.pic = wx.StaticBitmap(self)
self.bitmap = wx.EmptyBitmap(*res)
self.bbitmap = wx.EmptyBitmap(*res)
self.slicer = 'bitmap'
self.dpi = 96
dc = wx.MemoryDC()
dc.SelectObject(self.bbitmap)
dc.SetBackground(wx.Brush("black"))
dc.Clear()
dc.SelectObject(wx.NullBitmap)
self.SetBackgroundColour("black")
self.pic.Hide()
self.SetDoubleBuffered(True)
self.SetPosition((self.control_frame.GetSize().x, 0))
self.Show()
self.scale = scale
self.index = 0
self.size = res
self.offset = offset
self.running = False
self.layer_red = False
def clear_layer(self):
try:
dc = wx.MemoryDC()
dc.SelectObject(self.bitmap)
dc.SetBackground(wx.Brush("black"))
dc.Clear()
self.pic.SetBitmap(self.bitmap)
self.pic.Show()
self.Refresh()
except:
raise
pass
def resize(self, res = (1024, 768)):
self.bitmap = wx.EmptyBitmap(*res)
self.bbitmap = wx.EmptyBitmap(*res)
dc = wx.MemoryDC()
dc.SelectObject(self.bbitmap)
dc.SetBackground(wx.Brush("black"))
dc.Clear()
dc.SelectObject(wx.NullBitmap)
def draw_layer(self, image):
try:
dc = wx.MemoryDC()
dc.SelectObject(self.bitmap)
dc.SetBackground(wx.Brush("black"))
dc.Clear()
if self.slicer == 'Slic3r' or self.slicer == 'Skeinforge':
if self.scale != 1.0:
layercopy = copy.deepcopy(image)
height = float(layercopy.get('height').replace('m', ''))
width = float(layercopy.get('width').replace('m', ''))
layercopy.set('height', str(height * self.scale) + 'mm')
layercopy.set('width', str(width * self.scale) + 'mm')
layercopy.set('viewBox', '0 0 ' + str(width * self.scale) + ' ' + str(height * self.scale))
g = layercopy.find("{http://www.w3.org/2000/svg}g")
g.set('transform', 'scale(' + str(self.scale) + ')')
stream = cStringIO.StringIO(PNGSurface.convert(dpi = self.dpi, bytestring = xml.etree.ElementTree.tostring(layercopy)))
else:
stream = cStringIO.StringIO(PNGSurface.convert(dpi = self.dpi, bytestring = xml.etree.ElementTree.tostring(image)))
pngImage = wx.ImageFromStream(stream)
# print "w:", pngImage.Width, ", dpi:", self.dpi, ", w (mm): ",(pngImage.Width / self.dpi) * 25.4
if self.layer_red:
pngImage = pngImage.AdjustChannels(1, 0, 0, 1)
dc.DrawBitmap(wx.BitmapFromImage(pngImage), self.offset[0], self.offset[1], True)
elif self.slicer == 'bitmap':
if isinstance(image, str):
image = wx.Image(image)
if self.layer_red:
image = image.AdjustChannels(1, 0, 0, 1)
dc.DrawBitmap(wx.BitmapFromImage(image.Scale(image.Width * self.scale, image.Height * self.scale)), self.offset[0], -self.offset[1], True)
else:
raise Exception(self.slicer + " is an unknown method.")
self.pic.SetBitmap(self.bitmap)
self.pic.Show()
self.Refresh()
except:
raise
pass
def show_img_delay(self, image):
print "Showing", str(time.clock())
self.control_frame.set_current_layer(self.index)
self.draw_layer(image)
wx.FutureCall(1000 * self.interval, self.hide_pic_and_rise)
def rise(self):
if (self.direction == "Top Down"):
print "Lowering", str(time.clock())
else:
print "Rising", str(time.clock())
if self.printer is not None and self.printer.online:
self.printer.send_now("G91")
if (self.prelift_gcode):
for line in self.prelift_gcode.split('\n'):
if line:
self.printer.send_now(line)
if (self.direction == "Top Down"):
self.printer.send_now("G1 Z-%f F%g" % (self.overshoot, self.z_axis_rate,))
self.printer.send_now("G1 Z%f F%g" % (self.overshoot - self.thickness, self.z_axis_rate,))
else: # self.direction == "Bottom Up"
self.printer.send_now("G1 Z%f F%g" % (self.overshoot, self.z_axis_rate,))
self.printer.send_now("G1 Z-%f F%g" % (self.overshoot - self.thickness, self.z_axis_rate,))
if (self.postlift_gcode):
for line in self.postlift_gcode.split('\n'):
if line:
self.printer.send_now(line)
self.printer.send_now("G90")
else:
time.sleep(self.pause)
wx.FutureCall(1000 * self.pause, self.next_img)
def hide_pic(self):
print "Hiding", str(time.clock())
self.pic.Hide()
def hide_pic_and_rise(self):
wx.CallAfter(self.hide_pic)
wx.FutureCall(500, self.rise)
def next_img(self):
if not self.running:
return
if self.index < len(self.layers):
print self.index
wx.CallAfter(self.show_img_delay, self.layers[self.index])
self.index += 1
else:
print "end"
wx.CallAfter(self.pic.Hide)
wx.CallAfter(self.Refresh)
def present(self,
layers,
interval = 0.5,
pause = 0.2,
overshoot = 0.0,
z_axis_rate = 200,
prelift_gcode = "",
postlift_gcode = "",
direction = "Top Down",
thickness = 0.4,
scale = 1,
size = (1024, 768),
offset = (0, 0),
layer_red = False):
wx.CallAfter(self.pic.Hide)
wx.CallAfter(self.Refresh)
self.layers = layers
self.scale = scale
self.thickness = thickness
self.size = size
self.interval = interval
self.pause = pause
self.overshoot = overshoot
self.z_axis_rate = z_axis_rate
self.prelift_gcode = prelift_gcode
self.postlift_gcode = postlift_gcode
self.direction = direction
self.layer_red = layer_red
self.offset = offset
self.index = 0
self.running = True
self.next_img()
class SettingsFrame(wx.Frame):
def _set_setting(self, name, value):
if self.pronterface:
self.pronterface.set(name, value)
def _get_setting(self, name, val):
if self.pronterface:
try:
return getattr(self.pronterface.settings, name)
except AttributeError:
return val
else:
return val
def __init__(self, parent, printer = None):
wx.Frame.__init__(self, parent, title = "ProjectLayer Control", style = (wx.DEFAULT_FRAME_STYLE | wx.WS_EX_CONTEXTHELP))
self.SetExtraStyle(wx.FRAME_EX_CONTEXTHELP)
self.pronterface = parent
self.display_frame = DisplayFrame(self, title = "ProjectLayer Display", printer = printer)
self.panel = wx.Panel(self)
vbox = wx.BoxSizer(wx.VERTICAL)
buttonbox = wx.StaticBoxSizer(wx.StaticBox(self.panel, label = "Controls"), wx.HORIZONTAL)
load_button = wx.Button(self.panel, -1, "Load")
load_button.Bind(wx.EVT_BUTTON, self.load_file)
load_button.SetHelpText("Choose an SVG file created from Slic3r or Skeinforge, or a zip file of bitmap images (with extension: .3dlp.zip).")
buttonbox.Add(load_button, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
present_button = wx.Button(self.panel, -1, "Present")
present_button.Bind(wx.EVT_BUTTON, self.start_present)
present_button.SetHelpText("Starts the presentation of the slices.")
buttonbox.Add(present_button, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
self.pause_button = wx.Button(self.panel, -1, "Pause")
self.pause_button.Bind(wx.EVT_BUTTON, self.pause_present)
self.pause_button.SetHelpText("Pauses the presentation. Can be resumed afterwards by clicking this button, or restarted by clicking present again.")
buttonbox.Add(self.pause_button, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
stop_button = wx.Button(self.panel, -1, "Stop")
stop_button.Bind(wx.EVT_BUTTON, self.stop_present)
stop_button.SetHelpText("Stops presenting the slices.")
buttonbox.Add(stop_button, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
self.help_button = wx.ContextHelpButton(self.panel)
buttonbox.Add(self.help_button, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
fieldboxsizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, label = "Settings"), wx.VERTICAL)
fieldsizer = wx.GridBagSizer(10, 10)
# Left Column
fieldsizer.Add(wx.StaticText(self.panel, -1, "Layer (mm):"), pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
self.thickness = wx.TextCtrl(self.panel, -1, str(self._get_setting("project_layer", "0.1")), size = (80, -1))
self.thickness.Bind(wx.EVT_TEXT, self.update_thickness)
self.thickness.SetHelpText("The thickness of each slice. Should match the value used to slice the model. SVG files update this value automatically, 3dlp.zip files have to be manually entered.")
fieldsizer.Add(self.thickness, pos = (0, 1))
fieldsizer.Add(wx.StaticText(self.panel, -1, "Exposure (s):"), pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
self.interval = wx.TextCtrl(self.panel, -1, str(self._get_setting("project_interval", "0.5")), size = (80, -1))
self.interval.Bind(wx.EVT_TEXT, self.update_interval)
self.interval.SetHelpText("How long each slice should be displayed.")
fieldsizer.Add(self.interval, pos = (1, 1))
fieldsizer.Add(wx.StaticText(self.panel, -1, "Blank (s):"), pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
self.pause = wx.TextCtrl(self.panel, -1, str(self._get_setting("project_pause", "0.5")), size = (80, -1))
self.pause.Bind(wx.EVT_TEXT, self.update_pause)
self.pause.SetHelpText("The pause length between slices. This should take into account any movement of the Z axis, plus time to prepare the resin surface (sliding, tilting, sweeping, etc).")
fieldsizer.Add(self.pause, pos = (2, 1))
fieldsizer.Add(wx.StaticText(self.panel, -1, "Scale:"), pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL)
self.scale = floatspin.FloatSpin(self.panel, -1, value = self._get_setting('project_scale', 1.0), increment = 0.1, digits = 3, size = (80, -1))
self.scale.Bind(floatspin.EVT_FLOATSPIN, self.update_scale)
self.scale.SetHelpText("The additional scaling of each slice.")
fieldsizer.Add(self.scale, pos = (3, 1))
fieldsizer.Add(wx.StaticText(self.panel, -1, "Direction:"), pos = (4, 0), flag = wx.ALIGN_CENTER_VERTICAL)
self.direction = wx.ComboBox(self.panel, -1, choices = ["Top Down", "Bottom Up"], value = self._get_setting('project_direction', "Top Down"), size = (80, -1))
self.direction.Bind(wx.EVT_COMBOBOX, self.update_direction)
self.direction.SetHelpText("The direction the Z axis should move. Top Down is where the projector is above the model, Bottom up is where the projector is below the model.")
fieldsizer.Add(self.direction, pos = (4, 1), flag = wx.ALIGN_CENTER_VERTICAL)
fieldsizer.Add(wx.StaticText(self.panel, -1, "Overshoot (mm):"), pos = (5, 0), flag = wx.ALIGN_CENTER_VERTICAL)
self.overshoot = floatspin.FloatSpin(self.panel, -1, value = self._get_setting('project_overshoot', 3.0), increment = 0.1, digits = 1, min_val = 0, size = (80, -1))
self.overshoot.Bind(floatspin.EVT_FLOATSPIN, self.update_overshoot)
self.overshoot.SetHelpText("How far the axis should move beyond the next slice position for each slice. For Top Down printers this would dunk the model under the resi and then return. For Bottom Up printers this would raise the base away from the vat and then return.")
fieldsizer.Add(self.overshoot, pos = (5, 1))
fieldsizer.Add(wx.StaticText(self.panel, -1, "Pre-lift Gcode:"), pos = (6, 0), flag = wx.ALIGN_CENTER_VERTICAL)
self.prelift_gcode = wx.TextCtrl(self.panel, -1, str(self._get_setting("project_prelift_gcode", "").replace("\\n", '\n')), size = (-1, 35), style = wx.TE_MULTILINE)
self.prelift_gcode.SetHelpText("Additional gcode to run before raising the Z axis. Be sure to take into account any additional time needed in the pause value, and be careful what gcode is added!")
self.prelift_gcode.Bind(wx.EVT_TEXT, self.update_prelift_gcode)
fieldsizer.Add(self.prelift_gcode, pos = (6, 1), span = (2, 1))
fieldsizer.Add(wx.StaticText(self.panel, -1, "Post-lift Gcode:"), pos = (6, 2), flag = wx.ALIGN_CENTER_VERTICAL)
self.postlift_gcode = wx.TextCtrl(self.panel, -1, str(self._get_setting("project_postlift_gcode", "").replace("\\n", '\n')), size = (-1, 35), style = wx.TE_MULTILINE)
self.postlift_gcode.SetHelpText("Additional gcode to run after raising the Z axis. Be sure to take into account any additional time needed in the pause value, and be careful what gcode is added!")
self.postlift_gcode.Bind(wx.EVT_TEXT, self.update_postlift_gcode)
fieldsizer.Add(self.postlift_gcode, pos = (6, 3), span = (2, 1))
# Right Column
fieldsizer.Add(wx.StaticText(self.panel, -1, "X (px):"), pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
projectX = int(math.floor(float(self._get_setting("project_x", 1920))))
self.X = wx.SpinCtrl(self.panel, -1, str(projectX), max = 999999, size = (80, -1))
self.X.Bind(wx.EVT_SPINCTRL, self.update_resolution)
self.X.SetHelpText("The projector resolution in the X axis.")
fieldsizer.Add(self.X, pos = (0, 3))
fieldsizer.Add(wx.StaticText(self.panel, -1, "Y (px):"), pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
projectY = int(math.floor(float(self._get_setting("project_y", 1200))))
self.Y = wx.SpinCtrl(self.panel, -1, str(projectY), max = 999999, size = (80, -1))
self.Y.Bind(wx.EVT_SPINCTRL, self.update_resolution)
self.Y.SetHelpText("The projector resolution in the Y axis.")
fieldsizer.Add(self.Y, pos = (1, 3))
fieldsizer.Add(wx.StaticText(self.panel, -1, "OffsetX (mm):"), pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL)
self.offset_X = floatspin.FloatSpin(self.panel, -1, value = self._get_setting("project_offset_x", 0.0), increment = 1, digits = 1, size = (80, -1))
self.offset_X.Bind(floatspin.EVT_FLOATSPIN, self.update_offset)
self.offset_X.SetHelpText("How far the slice should be offset from the edge in the X axis.")
fieldsizer.Add(self.offset_X, pos = (2, 3))
fieldsizer.Add(wx.StaticText(self.panel, -1, "OffsetY (mm):"), pos = (3, 2), flag = wx.ALIGN_CENTER_VERTICAL)
self.offset_Y = floatspin.FloatSpin(self.panel, -1, value = self._get_setting("project_offset_y", 0.0), increment = 1, digits = 1, size = (80, -1))
self.offset_Y.Bind(floatspin.EVT_FLOATSPIN, self.update_offset)
self.offset_Y.SetHelpText("How far the slice should be offset from the edge in the Y axis.")
fieldsizer.Add(self.offset_Y, pos = (3, 3))
fieldsizer.Add(wx.StaticText(self.panel, -1, "ProjectedX (mm):"), pos = (4, 2), flag = wx.ALIGN_CENTER_VERTICAL)
self.projected_X_mm = floatspin.FloatSpin(self.panel, -1, value = self._get_setting("project_projected_x", 505.0), increment = 1, digits = 1, size = (80, -1))
self.projected_X_mm.Bind(floatspin.EVT_FLOATSPIN, self.update_projected_Xmm)
self.projected_X_mm.SetHelpText("The actual width of the entire projected image. Use the Calibrate grid to show the full size of the projected image, and measure the width at the same level where the slice will be projected onto the resin.")
fieldsizer.Add(self.projected_X_mm, pos = (4, 3))
fieldsizer.Add(wx.StaticText(self.panel, -1, "Z Axis Speed (mm/min):"), pos = (5, 2), flag = wx.ALIGN_CENTER_VERTICAL)
self.z_axis_rate = wx.SpinCtrl(self.panel, -1, str(self._get_setting("project_z_axis_rate", 200)), max = 9999, size = (80, -1))
self.z_axis_rate.Bind(wx.EVT_SPINCTRL, self.update_z_axis_rate)
self.z_axis_rate.SetHelpText("Speed of the Z axis in mm/minute. Take into account that slower rates may require a longer pause value.")
fieldsizer.Add(self.z_axis_rate, pos = (5, 3))
fieldboxsizer.Add(fieldsizer)
# Display
displayboxsizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, label = "Display"), wx.VERTICAL)
displaysizer = wx.GridBagSizer(10, 10)
displaysizer.Add(wx.StaticText(self.panel, -1, "Fullscreen:"), pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
self.fullscreen = wx.CheckBox(self.panel, -1)
self.fullscreen.Bind(wx.EVT_CHECKBOX, self.update_fullscreen)
self.fullscreen.SetHelpText("Toggles the project screen to full size.")
displaysizer.Add(self.fullscreen, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
displaysizer.Add(wx.StaticText(self.panel, -1, "Calibrate:"), pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
self.calibrate = wx.CheckBox(self.panel, -1)
self.calibrate.Bind(wx.EVT_CHECKBOX, self.show_calibrate)
self.calibrate.SetHelpText("Toggles the calibration grid. Each grid should be 10mmx10mm in size. Use the grid to ensure the projected size is correct. See also the help for the ProjectedX field.")
displaysizer.Add(self.calibrate, pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL)
displaysizer.Add(wx.StaticText(self.panel, -1, "1st Layer:"), pos = (0, 4), flag = wx.ALIGN_CENTER_VERTICAL)
first_layer_boxer = wx.BoxSizer(wx.HORIZONTAL)
self.first_layer = wx.CheckBox(self.panel, -1)
self.first_layer.Bind(wx.EVT_CHECKBOX, self.show_first_layer)
self.first_layer.SetHelpText("Displays the first layer of the model. Use this to project the first layer for longer so it holds to the base. Note: this value does not affect the first layer when the \"Present\" run is started, it should be used manually.")
first_layer_boxer.Add(self.first_layer, flag = wx.ALIGN_CENTER_VERTICAL)
first_layer_boxer.Add(wx.StaticText(self.panel, -1, " (s):"), flag = wx.ALIGN_CENTER_VERTICAL)
self.show_first_layer_timer = floatspin.FloatSpin(self.panel, -1, value=-1, increment = 1, digits = 1, size = (55, -1))
self.show_first_layer_timer.SetHelpText("How long to display the first layer for. -1 = unlimited.")
first_layer_boxer.Add(self.show_first_layer_timer, flag = wx.ALIGN_CENTER_VERTICAL)
displaysizer.Add(first_layer_boxer, pos = (0, 6), flag = wx.ALIGN_CENTER_VERTICAL)
displaysizer.Add(wx.StaticText(self.panel, -1, "Red:"), pos = (0, 7), flag = wx.ALIGN_CENTER_VERTICAL)
self.layer_red = wx.CheckBox(self.panel, -1)
self.layer_red.Bind(wx.EVT_CHECKBOX, self.show_layer_red)
self.layer_red.SetHelpText("Toggles whether the image should be red. Useful for positioning whilst resin is in the printer as it should not cause a reaction.")
displaysizer.Add(self.layer_red, pos = (0, 8), flag = wx.ALIGN_CENTER_VERTICAL)
displayboxsizer.Add(displaysizer)
# Info
infosizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, label = "Info"), wx.VERTICAL)
infofieldsizer = wx.GridBagSizer(10, 10)
filelabel = wx.StaticText(self.panel, -1, "File:")
filelabel.SetHelpText("The name of the model currently loaded.")
infofieldsizer.Add(filelabel, pos = (0, 0))
self.filename = wx.StaticText(self.panel, -1, "")
infofieldsizer.Add(self.filename, pos = (0, 1))
totallayerslabel = wx.StaticText(self.panel, -1, "Total Layers:")
totallayerslabel.SetHelpText("The total number of layers found in the model.")
infofieldsizer.Add(totallayerslabel, pos = (1, 0))
self.total_layers = wx.StaticText(self.panel, -1)
infofieldsizer.Add(self.total_layers, pos = (1, 1))
currentlayerlabel = wx.StaticText(self.panel, -1, "Current Layer:")
currentlayerlabel.SetHelpText("The current layer being displayed.")
infofieldsizer.Add(currentlayerlabel, pos = (2, 0))
self.current_layer = wx.StaticText(self.panel, -1, "0")
infofieldsizer.Add(self.current_layer, pos = (2, 1))
estimatedtimelabel = wx.StaticText(self.panel, -1, "Estimated Time:")
estimatedtimelabel.SetHelpText("An estimate of the remaining time until print completion.")
infofieldsizer.Add(estimatedtimelabel, pos = (3, 0))
self.estimated_time = wx.StaticText(self.panel, -1, "")
infofieldsizer.Add(self.estimated_time, pos = (3, 1))
infosizer.Add(infofieldsizer)
#
vbox.Add(buttonbox, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP | wx.BOTTOM, border = 10)
vbox.Add(fieldboxsizer, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 10)
vbox.Add(displayboxsizer, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 10)
vbox.Add(infosizer, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 10)
self.panel.SetSizer(vbox)
self.panel.Fit()
self.Fit()
self.SetPosition((0, 0))
self.Show()
def __del__(self):
if hasattr(self, 'image_dir') and self.image_dir != '':
shutil.rmtree(self.image_dir)
if self.display_frame:
self.display_frame.Destroy()
def set_total_layers(self, total):
self.total_layers.SetLabel(str(total))
self.set_estimated_time()
def set_current_layer(self, index):
self.current_layer.SetLabel(str(index))
self.set_estimated_time()
def display_filename(self, name):
self.filename.SetLabel(name)
def set_estimated_time(self):
if not hasattr(self, 'layers'):
return
current_layer = int(self.current_layer.GetLabel())
remaining_layers = len(self.layers[0]) - current_layer
# 0.5 for delay between hide and rise
estimated_time = remaining_layers * (float(self.interval.GetValue()) + float(self.pause.GetValue()) + 0.5)
self.estimated_time.SetLabel(time.strftime("%H:%M:%S", time.gmtime(estimated_time)))
def parse_svg(self, name):
et = xml.etree.ElementTree.ElementTree(file = name)
# xml.etree.ElementTree.dump(et)
slicer = 'Slic3r' if et.getroot().find('{http://www.w3.org/2000/svg}metadata') is None else 'Skeinforge'
zlast = 0
zdiff = 0
ol = []
if (slicer == 'Slic3r'):
height = et.getroot().get('height').replace('m', '')
width = et.getroot().get('width').replace('m', '')
for i in et.findall("{http://www.w3.org/2000/svg}g"):
z = float(i.get('{http://slic3r.org/namespaces/slic3r}z'))
zdiff = z - zlast
zlast = z
svgSnippet = xml.etree.ElementTree.Element('{http://www.w3.org/2000/svg}svg')
svgSnippet.set('height', height + 'mm')
svgSnippet.set('width', width + 'mm')
svgSnippet.set('viewBox', '0 0 ' + width + ' ' + height)
svgSnippet.set('style', 'background-color:black;fill:white;')
svgSnippet.append(i)
ol += [svgSnippet]
else:
slice_layers = et.findall("{http://www.w3.org/2000/svg}metadata")[0].findall("{http://www.reprap.org/slice}layers")[0]
minX = slice_layers.get('minX')
maxX = slice_layers.get('maxX')
minY = slice_layers.get('minY')
maxY = slice_layers.get('maxY')
height = str(abs(float(minY)) + abs(float(maxY)))
width = str(abs(float(minX)) + abs(float(maxX)))
for g in et.findall("{http://www.w3.org/2000/svg}g")[0].findall("{http://www.w3.org/2000/svg}g"):
g.set('transform', '')
text_element = g.findall("{http://www.w3.org/2000/svg}text")[0]
g.remove(text_element)
path_elements = g.findall("{http://www.w3.org/2000/svg}path")
for p in path_elements:
p.set('transform', 'translate(' + maxX + ',' + maxY + ')')
p.set('fill', 'white')
z = float(g.get('id').split("z:")[-1])
zdiff = z - zlast
zlast = z
svgSnippet = xml.etree.ElementTree.Element('{http://www.w3.org/2000/svg}svg')
svgSnippet.set('height', height + 'mm')
svgSnippet.set('width', width + 'mm')
svgSnippet.set('viewBox', '0 0 ' + width + ' ' + height)
svgSnippet.set('style', 'background-color:black;fill:white;')
svgSnippet.append(g)
ol += [svgSnippet]
return ol, zdiff, slicer
def parse_3DLP_zip(self, name):
if not zipfile.is_zipfile(name):
raise Exception(name + " is not a zip file!")
accepted_image_types = ['gif', 'tiff', 'jpg', 'jpeg', 'bmp', 'png']
zipFile = zipfile.ZipFile(name, 'r')
self.image_dir = tempfile.mkdtemp()
zipFile.extractall(self.image_dir)
ol = []
# Note: the following funky code extracts any numbers from the filenames, matches
# them with the original then sorts them. It allows for filenames of the
# format: abc_1.png, which would be followed by abc_10.png alphabetically.
os.chdir(self.image_dir)
vals = filter(os.path.isfile, os.listdir('.'))
keys = map(lambda p: int(re.search('\d+', p).group()), vals)
imagefilesDict = dict(itertools.izip(keys, vals))
imagefilesOrderedDict = OrderedDict(sorted(imagefilesDict.items(), key = lambda t: t[0]))
for f in imagefilesOrderedDict.values():
path = os.path.join(self.image_dir, f)
if os.path.isfile(path) and imghdr.what(path) in accepted_image_types:
ol.append(path)
return ol, -1, "bitmap"
def load_file(self, event):
dlg = wx.FileDialog(self, ("Open file to print"), style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
dlg.SetWildcard(("Slic3r or Skeinforge svg files (;*.svg;*.SVG;);3DLP Zip (;*.3dlp.zip;)"))
if dlg.ShowModal() == wx.ID_OK:
name = dlg.GetPath()
if not(os.path.exists(name)):
self.status.SetStatusText(("File not found!"))
return
if name.endswith(".3dlp.zip"):
layers = self.parse_3DLP_zip(name)
layerHeight = float(self.thickness.GetValue())
else:
layers = self.parse_svg(name)
layerHeight = layers[1]
self.thickness.SetValue(str(layers[1]))
print "Layer thickness detected:", layerHeight, "mm"
print len(layers[0]), "layers found, total height", layerHeight * len(layers[0]), "mm"
self.layers = layers
self.set_total_layers(len(layers[0]))
self.set_current_layer(0)
self.current_filename = os.path.basename(name)
self.display_filename(self.current_filename)
self.slicer = layers[2]
self.display_frame.slicer = self.slicer
dlg.Destroy()
def show_calibrate(self, event):
if self.calibrate.IsChecked():
self.present_calibrate(event)
else:
if hasattr(self, 'layers'):
self.display_frame.slicer = self.layers[2]
self.display_frame.scale = float(self.scale.GetValue())
self.display_frame.clear_layer()
def show_first_layer(self, event):
if self.first_layer.IsChecked():
self.present_first_layer(event)
else:
if hasattr(self, 'layers'):
self.display_frame.slicer = self.layers[2]
self.display_frame.scale = float(self.scale.GetValue())
self.display_frame.clear_layer()
def show_layer_red(self, event):
self.display_frame.layer_red = self.layer_red.IsChecked()
def present_calibrate(self, event):
if self.calibrate.IsChecked():
self.display_frame.Raise()
self.display_frame.offset = (float(self.offset_X.GetValue()), -float(self.offset_Y.GetValue()))
self.display_frame.scale = 1.0
resolution_x_pixels = int(self.X.GetValue())
resolution_y_pixels = int(self.Y.GetValue())
gridBitmap = wx.EmptyBitmap(resolution_x_pixels, resolution_y_pixels)
dc = wx.MemoryDC()
dc.SelectObject(gridBitmap)
dc.SetBackground(wx.Brush("black"))
dc.Clear()
dc.SetPen(wx.Pen("red", 7))
dc.DrawLine(0, 0, resolution_x_pixels, 0)
dc.DrawLine(0, 0, 0, resolution_y_pixels)
dc.DrawLine(resolution_x_pixels, 0, resolution_x_pixels, resolution_y_pixels)
dc.DrawLine(0, resolution_y_pixels, resolution_x_pixels, resolution_y_pixels)
dc.SetPen(wx.Pen("red", 2))
aspectRatio = float(resolution_x_pixels) / float(resolution_y_pixels)
projectedXmm = float(self.projected_X_mm.GetValue())
projectedYmm = round(projectedXmm / aspectRatio)
pixelsXPerMM = resolution_x_pixels / projectedXmm
pixelsYPerMM = resolution_y_pixels / projectedYmm
gridCountX = int(projectedXmm / 10)
gridCountY = int(projectedYmm / 10)
for y in xrange(0, gridCountY + 1):
for x in xrange(0, gridCountX + 1):
dc.DrawLine(0, y * (pixelsYPerMM * 10), resolution_x_pixels, y * (pixelsYPerMM * 10))
dc.DrawLine(x * (pixelsXPerMM * 10), 0, x * (pixelsXPerMM * 10), resolution_y_pixels)
self.first_layer.SetValue(False)
self.display_frame.slicer = 'bitmap'
self.display_frame.draw_layer(gridBitmap.ConvertToImage())
def present_first_layer(self, event):
if (self.first_layer.GetValue()):
if not hasattr(self, "layers"):
print "No model loaded!"
self.first_layer.SetValue(False)
return
self.display_frame.offset = (float(self.offset_X.GetValue()), float(self.offset_Y.GetValue()))
self.display_frame.scale = float(self.scale.GetValue())
self.display_frame.slicer = self.layers[2]
self.display_frame.dpi = self.get_dpi()
self.display_frame.draw_layer(copy.deepcopy(self.layers[0][0]))
self.calibrate.SetValue(False)
if self.show_first_layer_timer != -1.0:
def unpresent_first_layer():
self.display_frame.clear_layer()
self.first_layer.SetValue(False)
wx.CallLater(self.show_first_layer_timer.GetValue() * 1000, unpresent_first_layer)
def update_offset(self, event):
offset_x = float(self.offset_X.GetValue())
offset_y = float(self.offset_Y.GetValue())
self.display_frame.offset = (offset_x, offset_y)
self._set_setting('project_offset_x', offset_x)
self._set_setting('project_offset_y', offset_y)
self.refresh_display(event)
def refresh_display(self, event):
self.present_calibrate(event)
self.present_first_layer(event)
def update_thickness(self, event):
self._set_setting('project_layer', self.thickness.GetValue())
self.refresh_display(event)
def update_projected_Xmm(self, event):
self._set_setting('project_projected_x', self.projected_X_mm.GetValue())
self.refresh_display(event)
def update_scale(self, event):
scale = float(self.scale.GetValue())
self.display_frame.scale = scale
self._set_setting('project_scale', scale)
self.refresh_display(event)
def update_interval(self, event):
interval = float(self.interval.GetValue())
self.display_frame.interval = interval
self._set_setting('project_interval', interval)
self.set_estimated_time()
self.refresh_display(event)
def update_pause(self, event):
pause = float(self.pause.GetValue())
self.display_frame.pause = pause
self._set_setting('project_pause', pause)
self.set_estimated_time()
self.refresh_display(event)
def update_overshoot(self, event):
overshoot = float(self.overshoot.GetValue())
self.display_frame.pause = overshoot
self._set_setting('project_overshoot', overshoot)
def update_prelift_gcode(self, event):
prelift_gcode = self.prelift_gcode.GetValue().replace('\n', "\\n")
self.display_frame.prelift_gcode = prelift_gcode
self._set_setting('project_prelift_gcode', prelift_gcode)
def update_postlift_gcode(self, event):
postlift_gcode = self.postlift_gcode.GetValue().replace('\n', "\\n")
self.display_frame.postlift_gcode = postlift_gcode
self._set_setting('project_postlift_gcode', postlift_gcode)
def update_z_axis_rate(self, event):
z_axis_rate = int(self.z_axis_rate.GetValue())
self.display_frame.z_axis_rate = z_axis_rate
self._set_setting('project_z_axis_rate', z_axis_rate)
def update_direction(self, event):
direction = self.direction.GetValue()
self.display_frame.direction = direction
self._set_setting('project_direction', direction)
def update_fullscreen(self, event):
if (self.fullscreen.GetValue()):
self.display_frame.ShowFullScreen(1)
else:
self.display_frame.ShowFullScreen(0)
self.refresh_display(event)
def update_resolution(self, event):
x = int(self.X.GetValue())
y = int(self.Y.GetValue())
self.display_frame.resize((x, y))
self._set_setting('project_x', x)
self._set_setting('project_y', y)
self.refresh_display(event)
def get_dpi(self):
resolution_x_pixels = int(self.X.GetValue())
projected_x_mm = float(self.projected_X_mm.GetValue())
projected_x_inches = projected_x_mm / 25.4
return resolution_x_pixels / projected_x_inches
def start_present(self, event):
if not hasattr(self, "layers"):
print "No model loaded!"
return
self.pause_button.SetLabel("Pause")
self.set_current_layer(0)
self.display_frame.Raise()
if (self.fullscreen.GetValue()):
self.display_frame.ShowFullScreen(1)
self.display_frame.slicer = self.layers[2]
self.display_frame.dpi = self.get_dpi()
self.display_frame.present(self.layers[0][:],
thickness = float(self.thickness.GetValue()),
interval = float(self.interval.GetValue()),
scale = float(self.scale.GetValue()),
pause = float(self.pause.GetValue()),
overshoot = float(self.overshoot.GetValue()),
z_axis_rate = int(self.z_axis_rate.GetValue()),
prelift_gcode = self.prelift_gcode.GetValue(),
postlift_gcode = self.postlift_gcode.GetValue(),
direction = self.direction.GetValue(),
size = (float(self.X.GetValue()), float(self.Y.GetValue())),
offset = (float(self.offset_X.GetValue()), float(self.offset_Y.GetValue())),
layer_red = self.layer_red.IsChecked())
def stop_present(self, event):
print "Stop"
self.pause_button.SetLabel("Pause")
self.set_current_layer(0)
self.display_frame.running = False
def pause_present(self, event):
if self.pause_button.GetLabel() == 'Pause':
print "Pause"
self.pause_button.SetLabel("Continue")
self.display_frame.running = False
else:
print "Continue"
self.pause_button.SetLabel("Pause")
self.display_frame.running = True
self.display_frame.next_img()
if __name__ == "__main__":
provider = wx.SimpleHelpProvider()
wx.HelpProvider_Set(provider)
a = wx.App()
SettingsFrame(None).Show()
a.MainLoop()
|
gpl-3.0
|
[
3,
961,
570,
365,
1777,
402,
314,
9101,
1065,
5241,
14,
199,
3,
199,
3,
9101,
1065,
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,
9101,
1065,
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,
9101,
1065,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
2748,
14,
9464,
14,
15325,
199,
646,
4818,
199,
646,
4818,
14,
773,
14,
643,
87,
14,
1609,
14809,
465,
2069,
14809,
199,
646,
747,
199,
646,
900,
199,
646,
10392,
199,
646,
5549,
199,
646,
5145,
199,
504,
1704,
14352,
10273,
14,
10992,
492,
510,
46,
8021,
300,
1409,
199,
646,
15073,
199,
646,
3416,
3561,
5012,
199,
646,
1331,
199,
646,
295,
199,
504,
5055,
492,
8773,
199,
646,
7975,
199,
646,
3473,
199,
199,
533,
12175,
3160,
8,
6323,
14,
3160,
304,
272,
347,
636,
826,
721,
277,
12,
1676,
12,
2538,
12,
522,
275,
334,
7727,
12,
32404,
395,
16639,
275,
488,
12,
4666,
275,
413,
14,
16,
12,
3268,
275,
334,
16,
12,
378,
2298,
267,
4818,
14,
3160,
855,
826,
721,
277,
12,
1676,
275,
1676,
12,
2538,
275,
2538,
12,
1568,
275,
522,
9,
267,
291,
14,
11835,
275,
16639,
267,
291,
14,
2785,
63,
1943,
275,
1676,
267,
291,
14,
12475,
275,
4818,
14,
9278,
16469,
8,
277,
9,
267,
291,
14,
20299,
275,
4818,
14,
4699,
16469,
2031,
470,
9,
267,
291,
14,
66,
20299,
275,
4818,
14,
4699,
16469,
2031,
470,
9,
267,
291,
14,
83,
27975,
275,
283,
20299,
7,
267,
291,
14,
23595,
275,
15580,
267,
12326,
275,
4818,
14,
8628,
5196,
342,
267,
12326,
14,
5446,
1692,
8,
277,
14,
66,
20299,
9,
267,
12326,
14,
1084,
14148,
8,
6323,
14,
17868,
480,
8399,
2237,
267,
12326,
14,
9721,
342,
267,
12326,
14,
5446,
1692,
8,
6323,
14,
8849,
16469,
9,
398,
291,
14,
1084,
14148,
15758,
480,
8399,
531,
267,
291,
14,
12475,
14,
18224,
342,
267,
291,
14,
1084,
7281,
23139,
8,
549,
9,
267,
291,
14,
1084,
5625,
1332,
277,
14,
2785,
63,
1943,
14,
21817,
1252,
88,
12,
378,
430,
267,
291,
14,
6824,
342,
398,
291,
14,
3467,
275,
4666,
267,
291,
14,
1080,
275,
378,
267,
291,
14,
890,
275,
522,
267,
291,
14,
2743,
275,
3268,
267,
291,
14,
5720,
275,
756,
267,
291,
14,
1897,
63,
581,
275,
756,
339,
347,
5436,
63,
1897,
8,
277,
304,
267,
862,
26,
288,
12326,
275,
4818,
14,
8628,
5196,
342,
288,
12326,
14,
5446,
1692,
8,
277,
14,
20299,
9,
288,
12326,
14,
1084,
14148,
8,
6323,
14,
17868,
480,
8399,
2237,
288,
12326,
14,
9721,
342,
288,
291,
14,
12475,
14,
1084,
16469,
8,
277,
14,
20299,
9,
288,
291,
14,
12475,
14,
6824,
342,
288,
291,
14,
18730,
342,
267,
871,
26,
288,
746,
288,
986,
339,
347,
15210,
8,
277,
12,
522,
275,
334,
7727,
12,
32404,
2298,
267,
291,
14,
20299,
275,
4818,
14,
4699,
16469,
2031,
470,
9,
267,
291,
14,
66,
20299,
275,
4818,
14,
4699,
16469,
2031,
470,
9,
267,
12326,
275,
4818,
14,
8628,
5196,
342,
267,
12326,
14,
5446,
1692,
8,
277,
14,
66,
20299,
9,
267,
12326,
14,
1084,
14148,
8,
6323,
14,
17868,
480,
8399,
2237,
267,
12326,
14,
9721,
342,
267,
12326,
14,
5446,
1692,
8,
6323,
14,
8849,
16469,
9,
339,
347,
5954,
63,
1897,
8,
277,
12,
1834,
304,
267,
862,
26,
288,
12326,
275,
4818,
14,
8628,
5196,
342,
288,
12326,
14,
5446,
1692,
8,
277,
14,
20299,
9,
288,
12326,
14,
1084,
14148,
8,
6323,
14,
17868,
480,
8399,
2237,
288,
12326,
14,
9721,
342,
953,
340,
291,
14,
83,
27975,
508,
283,
51,
606,
19,
82,
7,
503,
291,
14,
83,
27975,
508,
283,
51,
415,
262,
16677,
356,
2234,
340,
291,
14,
3467,
1137,
413,
14,
16,
26,
490,
4045,
1574,
275,
1331,
14,
8293,
8,
1569,
9,
490,
4569,
275,
2069,
8,
1897,
1574,
14,
362,
360,
3333,
1959,
1814,
360,
77,
297,
12381,
490,
3462,
275,
2069,
8,
1897,
1574,
14,
362,
360,
2063,
1959,
1814,
360,
77,
297,
12381,
4951,
4045,
1574,
14,
409,
360,
3333,
297,
620,
8,
3333,
627,
291,
14,
3467,
9,
435,
283,
596,
358,
490,
4045,
1574,
14,
409,
360,
2063,
297,
620,
8,
2063,
627,
291,
14,
3467,
9,
435,
283,
596,
358,
490,
4045,
1574,
14,
409,
360,
1345,
3532,
297,
283,
16,
378,
283,
435,
620,
8,
2063,
627,
291,
14,
3467,
9,
435,
283,
283,
435,
620,
8,
3333,
627,
291,
14,
3467,
430,
4951,
486,
275,
4045,
1574,
14,
1623,
13076,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
8269,
15,
10273,
93,
71,
531,
490,
486,
14,
409,
360,
4711,
297,
283,
3467,
360,
435,
620,
8,
277,
14,
3467,
9,
435,
5320,
358,
490,
2547,
275,
15073,
14,
6424,
8,
9060,
8021,
300,
1409,
14,
3916,
8,
23595,
275,
291,
14,
23595,
12,
23888,
275,
2748,
14,
9464,
14,
15325,
14,
14028,
8,
1897,
1574,
1724,
355,
587,
26,
490,
2547,
275,
15073,
14,
6424,
8,
9060,
8021,
300,
1409,
14,
3916,
8,
23595,
275,
291,
14,
23595,
12,
23888,
275,
2748,
14,
9464,
14,
15325,
14,
14028,
8,
1569,
1724,
2234,
25296,
3491,
275,
4818,
14,
3491,
2532,
3296,
8,
1745,
9,
2234,
327,
870,
298,
87,
6783,
25296,
3491,
14,
6216,
12,
3872,
26910,
6783,
291,
14,
23595,
12,
3872,
336,
334,
596,
304,
3872,
8,
4524,
3491,
14,
6216,
1182,
291,
14,
23595
] |
[
961,
570,
365,
1777,
402,
314,
9101,
1065,
5241,
14,
199,
3,
199,
3,
9101,
1065,
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,
9101,
1065,
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,
9101,
1065,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
2748,
14,
9464,
14,
15325,
199,
646,
4818,
199,
646,
4818,
14,
773,
14,
643,
87,
14,
1609,
14809,
465,
2069,
14809,
199,
646,
747,
199,
646,
900,
199,
646,
10392,
199,
646,
5549,
199,
646,
5145,
199,
504,
1704,
14352,
10273,
14,
10992,
492,
510,
46,
8021,
300,
1409,
199,
646,
15073,
199,
646,
3416,
3561,
5012,
199,
646,
1331,
199,
646,
295,
199,
504,
5055,
492,
8773,
199,
646,
7975,
199,
646,
3473,
199,
199,
533,
12175,
3160,
8,
6323,
14,
3160,
304,
272,
347,
636,
826,
721,
277,
12,
1676,
12,
2538,
12,
522,
275,
334,
7727,
12,
32404,
395,
16639,
275,
488,
12,
4666,
275,
413,
14,
16,
12,
3268,
275,
334,
16,
12,
378,
2298,
267,
4818,
14,
3160,
855,
826,
721,
277,
12,
1676,
275,
1676,
12,
2538,
275,
2538,
12,
1568,
275,
522,
9,
267,
291,
14,
11835,
275,
16639,
267,
291,
14,
2785,
63,
1943,
275,
1676,
267,
291,
14,
12475,
275,
4818,
14,
9278,
16469,
8,
277,
9,
267,
291,
14,
20299,
275,
4818,
14,
4699,
16469,
2031,
470,
9,
267,
291,
14,
66,
20299,
275,
4818,
14,
4699,
16469,
2031,
470,
9,
267,
291,
14,
83,
27975,
275,
283,
20299,
7,
267,
291,
14,
23595,
275,
15580,
267,
12326,
275,
4818,
14,
8628,
5196,
342,
267,
12326,
14,
5446,
1692,
8,
277,
14,
66,
20299,
9,
267,
12326,
14,
1084,
14148,
8,
6323,
14,
17868,
480,
8399,
2237,
267,
12326,
14,
9721,
342,
267,
12326,
14,
5446,
1692,
8,
6323,
14,
8849,
16469,
9,
398,
291,
14,
1084,
14148,
15758,
480,
8399,
531,
267,
291,
14,
12475,
14,
18224,
342,
267,
291,
14,
1084,
7281,
23139,
8,
549,
9,
267,
291,
14,
1084,
5625,
1332,
277,
14,
2785,
63,
1943,
14,
21817,
1252,
88,
12,
378,
430,
267,
291,
14,
6824,
342,
398,
291,
14,
3467,
275,
4666,
267,
291,
14,
1080,
275,
378,
267,
291,
14,
890,
275,
522,
267,
291,
14,
2743,
275,
3268,
267,
291,
14,
5720,
275,
756,
267,
291,
14,
1897,
63,
581,
275,
756,
339,
347,
5436,
63,
1897,
8,
277,
304,
267,
862,
26,
288,
12326,
275,
4818,
14,
8628,
5196,
342,
288,
12326,
14,
5446,
1692,
8,
277,
14,
20299,
9,
288,
12326,
14,
1084,
14148,
8,
6323,
14,
17868,
480,
8399,
2237,
288,
12326,
14,
9721,
342,
288,
291,
14,
12475,
14,
1084,
16469,
8,
277,
14,
20299,
9,
288,
291,
14,
12475,
14,
6824,
342,
288,
291,
14,
18730,
342,
267,
871,
26,
288,
746,
288,
986,
339,
347,
15210,
8,
277,
12,
522,
275,
334,
7727,
12,
32404,
2298,
267,
291,
14,
20299,
275,
4818,
14,
4699,
16469,
2031,
470,
9,
267,
291,
14,
66,
20299,
275,
4818,
14,
4699,
16469,
2031,
470,
9,
267,
12326,
275,
4818,
14,
8628,
5196,
342,
267,
12326,
14,
5446,
1692,
8,
277,
14,
66,
20299,
9,
267,
12326,
14,
1084,
14148,
8,
6323,
14,
17868,
480,
8399,
2237,
267,
12326,
14,
9721,
342,
267,
12326,
14,
5446,
1692,
8,
6323,
14,
8849,
16469,
9,
339,
347,
5954,
63,
1897,
8,
277,
12,
1834,
304,
267,
862,
26,
288,
12326,
275,
4818,
14,
8628,
5196,
342,
288,
12326,
14,
5446,
1692,
8,
277,
14,
20299,
9,
288,
12326,
14,
1084,
14148,
8,
6323,
14,
17868,
480,
8399,
2237,
288,
12326,
14,
9721,
342,
953,
340,
291,
14,
83,
27975,
508,
283,
51,
606,
19,
82,
7,
503,
291,
14,
83,
27975,
508,
283,
51,
415,
262,
16677,
356,
2234,
340,
291,
14,
3467,
1137,
413,
14,
16,
26,
490,
4045,
1574,
275,
1331,
14,
8293,
8,
1569,
9,
490,
4569,
275,
2069,
8,
1897,
1574,
14,
362,
360,
3333,
1959,
1814,
360,
77,
297,
12381,
490,
3462,
275,
2069,
8,
1897,
1574,
14,
362,
360,
2063,
1959,
1814,
360,
77,
297,
12381,
4951,
4045,
1574,
14,
409,
360,
3333,
297,
620,
8,
3333,
627,
291,
14,
3467,
9,
435,
283,
596,
358,
490,
4045,
1574,
14,
409,
360,
2063,
297,
620,
8,
2063,
627,
291,
14,
3467,
9,
435,
283,
596,
358,
490,
4045,
1574,
14,
409,
360,
1345,
3532,
297,
283,
16,
378,
283,
435,
620,
8,
2063,
627,
291,
14,
3467,
9,
435,
283,
283,
435,
620,
8,
3333,
627,
291,
14,
3467,
430,
4951,
486,
275,
4045,
1574,
14,
1623,
13076,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
8269,
15,
10273,
93,
71,
531,
490,
486,
14,
409,
360,
4711,
297,
283,
3467,
360,
435,
620,
8,
277,
14,
3467,
9,
435,
5320,
358,
490,
2547,
275,
15073,
14,
6424,
8,
9060,
8021,
300,
1409,
14,
3916,
8,
23595,
275,
291,
14,
23595,
12,
23888,
275,
2748,
14,
9464,
14,
15325,
14,
14028,
8,
1897,
1574,
1724,
355,
587,
26,
490,
2547,
275,
15073,
14,
6424,
8,
9060,
8021,
300,
1409,
14,
3916,
8,
23595,
275,
291,
14,
23595,
12,
23888,
275,
2748,
14,
9464,
14,
15325,
14,
14028,
8,
1569,
1724,
2234,
25296,
3491,
275,
4818,
14,
3491,
2532,
3296,
8,
1745,
9,
2234,
327,
870,
298,
87,
6783,
25296,
3491,
14,
6216,
12,
3872,
26910,
6783,
291,
14,
23595,
12,
3872,
336,
334,
596,
304,
3872,
8,
4524,
3491,
14,
6216,
1182,
291,
14,
23595,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
MDPvis/rlpy
|
examples/uav/q-ifdd.py
|
4
|
1932
|
from rlpy.Domains import PST
from rlpy.Agents import Q_Learning
from rlpy.Representations import *
from rlpy.Policies import eGreedy
from rlpy.Experiments import Experiment
import numpy as np
from hyperopt import hp
param_space = { # 'discretization': hp.quniform("discretization", 5, 50, 1),
'discover_threshold': hp.loguniform("discover_threshold",
np.log(5e1), np.log(1e4)),
#'lambda_': hp.uniform("lambda_", 0., 1.),
'boyan_N0': hp.loguniform("boyan_N0", np.log(1e1), np.log(1e5)),
'initial_learn_rate': hp.loguniform("initial_learn_rate", np.log(5e-2), np.log(1))}
def make_experiment(
exp_id=1, path="./Results/Temp/{domain}/{agent}/{representation}/",
discover_threshold=1204.,
lambda_=0.,
boyan_N0=7353.2,
initial_learn_rate=.9712):
opt = {}
opt["path"] = path
opt["exp_id"] = exp_id
opt["max_steps"] = 500000
opt["num_policy_checks"] = 30
opt["checks_per_policy"] = 10
sparsify = 1
kappa = 1e-7
domain = PST(NUM_UAV=4)
opt["domain"] = domain
initial_rep = IndependentDiscretization(domain)
representation = iFDD(domain, discover_threshold, initial_rep,
sparsify=sparsify,
useCache=True,
iFDDPlus=1 - kappa)
policy = eGreedy(representation, epsilon=0.1)
opt["agent"] = Q_Learning(policy, representation,
discount_factor=domain.discount_factor,
lambda_=lambda_, initial_learn_rate=initial_learn_rate,
learn_rate_decay_mode="boyan", boyan_N0=boyan_N0)
experiment = Experiment(**opt)
return experiment
if __name__ == '__main__':
from rlpy.Tools.run import run_profiled
run_profiled(make_experiment)
#experiment = make_experiment(1)
# experiment.run()
# experiment.plot()
# experiment.save()
|
bsd-3-clause
|
[
504,
25717,
647,
14,
7705,
83,
492,
510,
840,
199,
504,
25717,
647,
14,
7788,
83,
492,
1413,
63,
25519,
199,
504,
25717,
647,
14,
10755,
1298,
492,
627,
199,
504,
25717,
647,
14,
27079,
492,
325,
39,
24737,
199,
504,
25717,
647,
14,
920,
22263,
492,
23997,
199,
646,
2680,
465,
980,
199,
504,
10342,
2992,
492,
20962,
199,
199,
635,
63,
2638,
275,
469,
221,
327,
283,
6409,
264,
280,
13362,
356,
20962,
14,
81,
8830,
480,
6409,
264,
280,
13362,
401,
959,
12,
5238,
12,
413,
395,
272,
283,
18861,
63,
7227,
356,
20962,
14,
793,
8830,
480,
18861,
63,
7227,
401,
3147,
980,
14,
793,
8,
21,
69,
17,
395,
980,
14,
793,
8,
17,
69,
20,
1826,
272,
17384,
2734,
63,
356,
20962,
14,
8830,
480,
2734,
29808,
378,
2020,
413,
15631,
272,
283,
656,
89,
290,
63,
46,
16,
356,
20962,
14,
793,
8830,
480,
656,
89,
290,
63,
46,
16,
401,
980,
14,
793,
8,
17,
69,
17,
395,
980,
14,
793,
8,
17,
69,
21,
1826,
272,
283,
2747,
63,
4643,
63,
1866,
356,
20962,
14,
793,
8830,
480,
2747,
63,
4643,
63,
1866,
401,
980,
14,
793,
8,
21,
69,
13,
18,
395,
980,
14,
793,
8,
17,
430,
93,
421,
199,
318,
1852,
63,
10873,
8,
267,
1437,
63,
344,
29,
17,
12,
931,
628,
13186,
6579,
15,
6530,
5321,
2261,
16152,
4054,
16152,
22903,
5995,
401,
267,
20131,
63,
7227,
29,
713,
966,
2020,
267,
2400,
10683,
16,
2020,
267,
1234,
89,
290,
63,
46,
16,
29,
23,
15355,
14,
18,
12,
267,
2536,
63,
4643,
63,
1866,
15856,
2576,
713,
304,
272,
2450,
275,
1052,
272,
2450,
905,
515,
937,
275,
931,
272,
2450,
905,
1474,
63,
344,
937,
275,
1437,
63,
344,
272,
2450,
905,
988,
63,
5895,
937,
275,
959,
5345,
272,
2450,
905,
1507,
63,
3185,
63,
8625,
937,
275,
4233,
272,
2450,
905,
8625,
63,
529,
63,
3185,
937,
275,
1616,
272,
28668,
338,
1399,
275,
413,
272,
1022,
15999,
275,
413,
69,
13,
23,
272,
2881,
275,
510,
840,
8,
7125,
63,
53,
6087,
29,
20,
9,
272,
2450,
905,
2261,
937,
275,
2881,
272,
2536,
63,
1155,
275,
1010,
7106,
2825,
1353,
280,
13362,
8,
2261,
9,
272,
6025,
275,
284,
38,
5745,
8,
2261,
12,
20131,
63,
7227,
12,
2536,
63,
1155,
12,
2079,
28668,
338,
1399,
29,
22502,
338,
1399,
12,
2079,
675,
4437,
29,
549,
12,
2079,
284,
38,
5745,
25800,
29,
17,
446,
1022,
15999,
9,
272,
4592,
275,
325,
39,
24737,
8,
22903,
12,
14030,
29,
16,
14,
17,
9,
272,
2450,
905,
4054,
937,
275,
1413,
63,
25519,
8,
3185,
12,
6025,
12,
2432,
25309,
63,
4778,
29,
2261,
14,
15446,
63,
4778,
12,
2432,
2400,
10683,
2734,
3131,
2536,
63,
4643,
63,
1866,
29,
2747,
63,
4643,
63,
1866,
12,
2432,
12537,
63,
1866,
63,
16889,
63,
632,
628,
656,
89,
290,
401,
1234,
89,
290,
63,
46,
16,
29,
656,
89,
290,
63,
46,
16,
9,
272,
11805,
275,
23997,
3682,
2992,
9,
272,
372,
11805,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
687,
25717,
647,
14,
11654,
14,
1065,
492,
1255,
63,
2913,
68,
272,
1255,
63,
2913,
68,
8,
1875,
63,
10873,
9,
272,
327,
10873,
275,
1852,
63,
10873,
8,
17,
9,
272,
327,
11805,
14,
1065,
342,
272,
327,
11805,
14,
2798,
342,
272,
327,
11805,
14,
2117,
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
] |
[
25717,
647,
14,
7705,
83,
492,
510,
840,
199,
504,
25717,
647,
14,
7788,
83,
492,
1413,
63,
25519,
199,
504,
25717,
647,
14,
10755,
1298,
492,
627,
199,
504,
25717,
647,
14,
27079,
492,
325,
39,
24737,
199,
504,
25717,
647,
14,
920,
22263,
492,
23997,
199,
646,
2680,
465,
980,
199,
504,
10342,
2992,
492,
20962,
199,
199,
635,
63,
2638,
275,
469,
221,
327,
283,
6409,
264,
280,
13362,
356,
20962,
14,
81,
8830,
480,
6409,
264,
280,
13362,
401,
959,
12,
5238,
12,
413,
395,
272,
283,
18861,
63,
7227,
356,
20962,
14,
793,
8830,
480,
18861,
63,
7227,
401,
3147,
980,
14,
793,
8,
21,
69,
17,
395,
980,
14,
793,
8,
17,
69,
20,
1826,
272,
17384,
2734,
63,
356,
20962,
14,
8830,
480,
2734,
29808,
378,
2020,
413,
15631,
272,
283,
656,
89,
290,
63,
46,
16,
356,
20962,
14,
793,
8830,
480,
656,
89,
290,
63,
46,
16,
401,
980,
14,
793,
8,
17,
69,
17,
395,
980,
14,
793,
8,
17,
69,
21,
1826,
272,
283,
2747,
63,
4643,
63,
1866,
356,
20962,
14,
793,
8830,
480,
2747,
63,
4643,
63,
1866,
401,
980,
14,
793,
8,
21,
69,
13,
18,
395,
980,
14,
793,
8,
17,
430,
93,
421,
199,
318,
1852,
63,
10873,
8,
267,
1437,
63,
344,
29,
17,
12,
931,
628,
13186,
6579,
15,
6530,
5321,
2261,
16152,
4054,
16152,
22903,
5995,
401,
267,
20131,
63,
7227,
29,
713,
966,
2020,
267,
2400,
10683,
16,
2020,
267,
1234,
89,
290,
63,
46,
16,
29,
23,
15355,
14,
18,
12,
267,
2536,
63,
4643,
63,
1866,
15856,
2576,
713,
304,
272,
2450,
275,
1052,
272,
2450,
905,
515,
937,
275,
931,
272,
2450,
905,
1474,
63,
344,
937,
275,
1437,
63,
344,
272,
2450,
905,
988,
63,
5895,
937,
275,
959,
5345,
272,
2450,
905,
1507,
63,
3185,
63,
8625,
937,
275,
4233,
272,
2450,
905,
8625,
63,
529,
63,
3185,
937,
275,
1616,
272,
28668,
338,
1399,
275,
413,
272,
1022,
15999,
275,
413,
69,
13,
23,
272,
2881,
275,
510,
840,
8,
7125,
63,
53,
6087,
29,
20,
9,
272,
2450,
905,
2261,
937,
275,
2881,
272,
2536,
63,
1155,
275,
1010,
7106,
2825,
1353,
280,
13362,
8,
2261,
9,
272,
6025,
275,
284,
38,
5745,
8,
2261,
12,
20131,
63,
7227,
12,
2536,
63,
1155,
12,
2079,
28668,
338,
1399,
29,
22502,
338,
1399,
12,
2079,
675,
4437,
29,
549,
12,
2079,
284,
38,
5745,
25800,
29,
17,
446,
1022,
15999,
9,
272,
4592,
275,
325,
39,
24737,
8,
22903,
12,
14030,
29,
16,
14,
17,
9,
272,
2450,
905,
4054,
937,
275,
1413,
63,
25519,
8,
3185,
12,
6025,
12,
2432,
25309,
63,
4778,
29,
2261,
14,
15446,
63,
4778,
12,
2432,
2400,
10683,
2734,
3131,
2536,
63,
4643,
63,
1866,
29,
2747,
63,
4643,
63,
1866,
12,
2432,
12537,
63,
1866,
63,
16889,
63,
632,
628,
656,
89,
290,
401,
1234,
89,
290,
63,
46,
16,
29,
656,
89,
290,
63,
46,
16,
9,
272,
11805,
275,
23997,
3682,
2992,
9,
272,
372,
11805,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
687,
25717,
647,
14,
11654,
14,
1065,
492,
1255,
63,
2913,
68,
272,
1255,
63,
2913,
68,
8,
1875,
63,
10873,
9,
272,
327,
10873,
275,
1852,
63,
10873,
8,
17,
9,
272,
327,
11805,
14,
1065,
342,
272,
327,
11805,
14,
2798,
342,
272,
327,
11805,
14,
2117,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
timothycrosley/thedom
|
thedom/code_documentation.py
|
1
|
3121
|
'''
CodeDocumentation.py
Contains elements that are used for displaying and documenting code
uses pygments to enable code highlighting
Copyright (C) 2015 Timothy Edmund Crosley
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.
'''
try:
hasPygments = True
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import get_lexer_by_name, get_lexer_for_filename
except ImportError:
hasPygments = False
from . import DOM, Base, DictUtils, Factory
from .Inputs import ValueElement
from .MethodUtils import CallBack
from .MultiplePythonSupport import *
Factory = Factory.Factory("CodeDocumentation")
class CodeSnippet(DOM.Pre):
"""
Enables adding a snippet of code directly to a page.
"""
__slots__ = ('code', 'lexer', 'showLineNumbers', '_textNode')
tagName = "pre"
properties = Base.Node.properties.copy()
properties['code'] = {'action':'classAttribute'}
properties['lexer'] = {'action':'classAttribute'}
properties['showLineNumbers'] = {'action':'classAttribute', 'type':'bool'}
def _create(self, id=None, name=None, parent=None, **kwargs):
DOM.Pre._create(self, id, name, parent, **kwargs)
self._textNode = self.add(Base.TextNode())
self.showLineNumbers = False
self.lexer = "python"
self.code = ""
def _getCode(self):
return self.code.replace("\\n", "\n")
def _getLexer(self):
return get_lexer_by_name(self.lexer)
def _render(self):
"""
Renders the code with pygments if it is available otherwise with a simple pre-tag
"""
DOM.Pre._render(self)
if not hasPygments:
self._textNode.setText(self.code)
return
self._tagName = "span"
formatter = HtmlFormatter(linenos=self.showLineNumbers)
self._textNode.setText(highlight(self._getCode(), self._getLexer(), formatter))
Factory.addProduct(CodeSnippet)
class SourceFile(CodeSnippet):
"""
Enables adding a formatted source file directly to a page.
"""
def _getCode(self):
if self.code:
with open(self.code, "r") as openFile:
return openFile.read()
return ""
def _getLexer(self):
if self.lexer:
return get_lexer_by_name(self.lexer)
return get_lexer_for_filename(self.code)
Factory.addProduct(SourceFile)
|
gpl-2.0
|
[
2344,
272,
5495,
17763,
14,
647,
339,
22493,
4008,
626,
787,
1202,
367,
20589,
436,
29904,
1233,
272,
4440,
13277,
370,
4756,
1233,
22437,
339,
1898,
334,
35,
9,
6900,
221,
377,
73,
573,
273,
89,
662,
6428,
725,
445,
4796,
15515,
339,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
272,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
272,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
272,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
272,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
12,
8217,
14,
199,
2344,
199,
199,
893,
26,
272,
965,
2713,
4664,
275,
715,
272,
687,
13277,
492,
11850,
272,
687,
13277,
14,
24270,
492,
20880,
7772,
272,
687,
13277,
14,
12245,
492,
664,
63,
11729,
63,
991,
63,
354,
12,
664,
63,
11729,
63,
509,
63,
1501,
199,
2590,
3545,
26,
272,
965,
2713,
4664,
275,
756,
199,
199,
504,
1275,
492,
14316,
12,
3523,
12,
7448,
7535,
12,
23616,
199,
504,
1275,
15124,
492,
1594,
2162,
199,
504,
1275,
3767,
7535,
492,
6523,
4540,
199,
504,
1275,
8433,
4718,
11532,
492,
627,
199,
199,
2927,
275,
23616,
14,
2927,
480,
3034,
17763,
531,
421,
199,
533,
5495,
20821,
11088,
8,
10462,
14,
2398,
304,
272,
408,
267,
3447,
5921,
7791,
282,
17440,
402,
1233,
5370,
370,
282,
2034,
14,
272,
408,
272,
636,
7257,
363,
275,
661,
600,
297,
283,
11729,
297,
283,
2384,
3049,
22951,
297,
2513,
505,
1716,
358,
272,
1947,
985,
275,
298,
657,
2,
272,
4382,
275,
3523,
14,
1716,
14,
3282,
14,
1574,
342,
272,
4382,
459,
600,
418,
275,
791,
1287,
5242,
533,
1646,
936,
272,
4382,
459,
11729,
418,
275,
791,
1287,
5242,
533,
1646,
936,
272,
4382,
459,
2384,
3049,
22951,
418,
275,
791,
1287,
5242,
533,
1646,
297,
283,
466,
5242,
2245,
936,
339,
347,
485,
981,
8,
277,
12,
1305,
29,
403,
12,
536,
29,
403,
12,
1676,
29,
403,
12,
1011,
958,
304,
267,
14316,
14,
2398,
423,
981,
8,
277,
12,
1305,
12,
536,
12,
1676,
12,
1011,
958,
9,
398,
291,
423,
505,
1716,
275,
291,
14,
525,
8,
1563,
14,
32540,
1012,
398,
291,
14,
2384,
3049,
22951,
275,
756,
267,
291,
14,
11729,
275,
298,
1548,
2,
267,
291,
14,
600,
275,
3087,
339,
347,
485,
362,
3034,
8,
277,
304,
267,
372,
291,
14,
600,
14,
1814,
23236,
78,
401,
1867,
78,
531,
339,
347,
485,
362,
5838,
8,
277,
304,
267,
372,
664,
63,
11729,
63,
991,
63,
354,
8,
277,
14,
11729,
9,
339,
347,
485,
3352,
8,
277,
304,
267,
408,
1779,
10055,
7735,
314,
1233,
543,
13277,
340,
652,
365,
2808,
4257,
543,
282,
3486,
876,
13,
1450,
267,
408,
267,
14316,
14,
2398,
423,
3352,
8,
277,
9,
267,
340,
440,
965,
2713,
4664,
26,
288,
291,
423,
505,
1716,
14,
8341,
8,
277,
14,
600,
9,
288,
372,
398,
291,
423,
20183,
275,
298,
3751,
2,
267,
9698,
275,
20880,
7772,
8,
2950,
736,
29,
277,
14,
2384,
3049,
22951,
9,
267,
291,
423,
505,
1716,
14,
8341,
8,
14337,
8,
277,
423,
362,
3034,
1062,
291,
423,
362,
5838,
1062,
9698,
430,
199,
199,
2927,
14,
525,
5884,
8,
3034,
20821,
11088,
9,
421,
199,
533,
5800,
1173,
8,
3034,
20821,
11088,
304,
272,
408,
267,
3447,
5921,
7791,
282,
7871,
1350,
570,
5370,
370,
282,
2034,
14,
272,
408,
339,
347,
485,
362,
3034,
8,
277,
304,
267,
340,
291,
14,
600,
26,
288,
543,
1551,
8,
277,
14,
600,
12,
298,
82,
531,
465,
1551,
1173,
26,
355,
372,
1551,
1173,
14,
739,
342,
267,
372,
3087,
339,
347,
485,
362,
5838,
8,
277,
304,
267,
340,
291,
14,
11729,
26,
288,
372,
664,
63,
11729,
63,
991,
63,
354,
8,
277,
14,
11729,
9,
267,
372,
664,
63,
11729,
63,
509,
63,
1501,
8,
277,
14,
600,
9,
199,
199,
2927,
14,
525,
5884,
8,
2980,
1173,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
272,
5495,
17763,
14,
647,
339,
22493,
4008,
626,
787,
1202,
367,
20589,
436,
29904,
1233,
272,
4440,
13277,
370,
4756,
1233,
22437,
339,
1898,
334,
35,
9,
6900,
221,
377,
73,
573,
273,
89,
662,
6428,
725,
445,
4796,
15515,
339,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
272,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
272,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
272,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
272,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
12,
8217,
14,
199,
2344,
199,
199,
893,
26,
272,
965,
2713,
4664,
275,
715,
272,
687,
13277,
492,
11850,
272,
687,
13277,
14,
24270,
492,
20880,
7772,
272,
687,
13277,
14,
12245,
492,
664,
63,
11729,
63,
991,
63,
354,
12,
664,
63,
11729,
63,
509,
63,
1501,
199,
2590,
3545,
26,
272,
965,
2713,
4664,
275,
756,
199,
199,
504,
1275,
492,
14316,
12,
3523,
12,
7448,
7535,
12,
23616,
199,
504,
1275,
15124,
492,
1594,
2162,
199,
504,
1275,
3767,
7535,
492,
6523,
4540,
199,
504,
1275,
8433,
4718,
11532,
492,
627,
199,
199,
2927,
275,
23616,
14,
2927,
480,
3034,
17763,
531,
421,
199,
533,
5495,
20821,
11088,
8,
10462,
14,
2398,
304,
272,
408,
267,
3447,
5921,
7791,
282,
17440,
402,
1233,
5370,
370,
282,
2034,
14,
272,
408,
272,
636,
7257,
363,
275,
661,
600,
297,
283,
11729,
297,
283,
2384,
3049,
22951,
297,
2513,
505,
1716,
358,
272,
1947,
985,
275,
298,
657,
2,
272,
4382,
275,
3523,
14,
1716,
14,
3282,
14,
1574,
342,
272,
4382,
459,
600,
418,
275,
791,
1287,
5242,
533,
1646,
936,
272,
4382,
459,
11729,
418,
275,
791,
1287,
5242,
533,
1646,
936,
272,
4382,
459,
2384,
3049,
22951,
418,
275,
791,
1287,
5242,
533,
1646,
297,
283,
466,
5242,
2245,
936,
339,
347,
485,
981,
8,
277,
12,
1305,
29,
403,
12,
536,
29,
403,
12,
1676,
29,
403,
12,
1011,
958,
304,
267,
14316,
14,
2398,
423,
981,
8,
277,
12,
1305,
12,
536,
12,
1676,
12,
1011,
958,
9,
398,
291,
423,
505,
1716,
275,
291,
14,
525,
8,
1563,
14,
32540,
1012,
398,
291,
14,
2384,
3049,
22951,
275,
756,
267,
291,
14,
11729,
275,
298,
1548,
2,
267,
291,
14,
600,
275,
3087,
339,
347,
485,
362,
3034,
8,
277,
304,
267,
372,
291,
14,
600,
14,
1814,
23236,
78,
401,
1867,
78,
531,
339,
347,
485,
362,
5838,
8,
277,
304,
267,
372,
664,
63,
11729,
63,
991,
63,
354,
8,
277,
14,
11729,
9,
339,
347,
485,
3352,
8,
277,
304,
267,
408,
1779,
10055,
7735,
314,
1233,
543,
13277,
340,
652,
365,
2808,
4257,
543,
282,
3486,
876,
13,
1450,
267,
408,
267,
14316,
14,
2398,
423,
3352,
8,
277,
9,
267,
340,
440,
965,
2713,
4664,
26,
288,
291,
423,
505,
1716,
14,
8341,
8,
277,
14,
600,
9,
288,
372,
398,
291,
423,
20183,
275,
298,
3751,
2,
267,
9698,
275,
20880,
7772,
8,
2950,
736,
29,
277,
14,
2384,
3049,
22951,
9,
267,
291,
423,
505,
1716,
14,
8341,
8,
14337,
8,
277,
423,
362,
3034,
1062,
291,
423,
362,
5838,
1062,
9698,
430,
199,
199,
2927,
14,
525,
5884,
8,
3034,
20821,
11088,
9,
421,
199,
533,
5800,
1173,
8,
3034,
20821,
11088,
304,
272,
408,
267,
3447,
5921,
7791,
282,
7871,
1350,
570,
5370,
370,
282,
2034,
14,
272,
408,
339,
347,
485,
362,
3034,
8,
277,
304,
267,
340,
291,
14,
600,
26,
288,
543,
1551,
8,
277,
14,
600,
12,
298,
82,
531,
465,
1551,
1173,
26,
355,
372,
1551,
1173,
14,
739,
342,
267,
372,
3087,
339,
347,
485,
362,
5838,
8,
277,
304,
267,
340,
291,
14,
11729,
26,
288,
372,
664,
63,
11729,
63,
991,
63,
354,
8,
277,
14,
11729,
9,
267,
372,
664,
63,
11729,
63,
509,
63,
1501,
8,
277,
14,
600,
9,
199,
199,
2927,
14,
525,
5884,
8,
2980,
1173,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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acock.Input.InputFileEditor import InputFileEditor
from peacock.Input.ExecutableInfo import ExecutableInfo
from peacock.utils import Testing
class Tests(Testing.PeacockTester):
def setUp(self):
super(Tests, self).setUp()
self.test_input_file = "../../common/fsp_test.i"
self.block_list_requested = 0
def newWidget(self):
app_info = ExecutableInfo()
app_info.setPath(Testing.find_moose_test_exe())
self.assertTrue(app_info.valid())
w = InputFileEditor()
w.executableInfoChanged(app_info)
w.setInputFile(self.test_input_file)
return w
def testBlockEditor(self):
e = self.newWidget()
mesh = e.tree.getBlockInfo("/Mesh")
self.assertNotEqual(mesh, None)
self.assertEqual(e.block_editor, None)
e._blockEditorRequested(mesh)
self.assertNotEqual(e.block_editor, None)
e.block_editor.close()
self.assertEqual(e.block_editor, None)
def testBlockList(self):
e = self.newWidget()
# this should request variables
u = e.tree.getBlockInfo("/Preconditioning/FSP/u")
self.assertNotEqual(u, None)
e.onNeedBlockList(["/Variables"])
e._blockEditorRequested(u)
e.onNeedBlockList(["/Variables"])
e.closing()
self.assertEqual(e.block_editor, None)
def testWrite(self):
e = self.newWidget()
u = e.tree.getBlockInfo("/Preconditioning/FSP/u")
self.assertNotEqual(u, None)
e._blockEditorRequested(u)
e.block_editor.close()
b = e.tree.getBlockInfo("/BCs/left_u")
self.assertNotEqual(b, None)
e._blockEditorRequested(b)
e.block_editor.close()
e.writeInputFile("fsp_test.i")
self.compareFiles("fsp_test.i", "gold/fsp_test.i")
if __name__ == '__main__':
Testing.run_tests()
|
lgpl-2.1
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
504,
299,
4489,
331,
346,
14,
3205,
14,
3205,
1173,
10423,
492,
6924,
1173,
10423,
199,
504,
299,
4489,
331,
346,
14,
3205,
14,
18039,
2354,
492,
9434,
2964,
2354,
199,
504,
299,
4489,
331,
346,
14,
1208,
492,
11940,
199,
199,
533,
6496,
8,
9029,
14,
48,
4489,
331,
346,
22403,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
2925,
12,
291,
680,
5996,
342,
267,
291,
14,
396,
63,
1210,
63,
493,
275,
298,
9707,
2330,
15,
70,
681,
63,
396,
14,
73,
2,
267,
291,
14,
1457,
63,
513,
63,
11151,
275,
378,
339,
347,
892,
3339,
8,
277,
304,
267,
1145,
63,
815,
275,
9434,
2964,
2354,
342,
267,
1145,
63,
815,
14,
409,
2042,
8,
9029,
14,
1623,
63,
573,
3362,
63,
396,
63,
5803,
1012,
267,
291,
14,
1815,
8,
571,
63,
815,
14,
1078,
1012,
267,
336,
275,
6924,
1173,
10423,
342,
267,
336,
14,
5904,
2354,
6970,
8,
571,
63,
815,
9,
267,
336,
14,
409,
3205,
1173,
8,
277,
14,
396,
63,
1210,
63,
493,
9,
267,
372,
336,
339,
347,
511,
3142,
10423,
8,
277,
304,
267,
325,
275,
291,
14,
1222,
3339,
342,
267,
9364,
275,
325,
14,
2350,
14,
362,
3142,
2354,
4769,
12241,
531,
267,
291,
14,
7418,
8,
6480,
12,
488,
9,
267,
291,
14,
629,
8,
69,
14,
1457,
63,
7515,
12,
488,
9,
267,
325,
423,
1457,
10423,
17935,
8,
6480,
9,
267,
291,
14,
7418,
8,
69,
14,
1457,
63,
7515,
12,
488,
9,
267,
325,
14,
1457,
63,
7515,
14,
1600,
342,
267,
291,
14,
629,
8,
69,
14,
1457,
63,
7515,
12,
488,
9,
339,
347,
511,
3142,
1296,
8,
277,
304,
267,
325,
275,
291,
14,
1222,
3339,
342,
267,
327,
642,
1077,
1056,
2860,
267,
399,
275,
325,
14,
2350,
14,
362,
3142,
2354,
4769,
2398,
5394,
316,
15,
38,
5763,
15,
85,
531,
267,
291,
14,
7418,
8,
85,
12,
488,
9,
267,
325,
14,
265,
17809,
3142,
1296,
5234,
15,
11458,
3135,
267,
325,
423,
1457,
10423,
17935,
8,
85,
9,
267,
325,
14,
265,
17809,
3142,
1296,
5234,
15,
11458,
3135,
267,
325,
14,
11707,
342,
267,
291,
14,
629,
8,
69,
14,
1457,
63,
7515,
12,
488,
9,
339,
347,
511,
3534,
8,
277,
304,
267,
325,
275,
291,
14,
1222,
3339,
342,
267,
399,
275,
325,
14,
2350,
14,
362,
3142,
2354,
4769,
2398,
5394,
316,
15,
38,
5763,
15,
85,
531,
267,
291,
14,
7418,
8,
85,
12,
488,
9,
267,
325,
423,
1457,
10423,
17935,
8,
85,
9,
267,
325,
14,
1457,
63,
7515,
14,
1600,
342,
398,
330,
275,
325,
14,
2350,
14,
362,
3142,
2354,
4769,
6265,
83,
15,
3039,
63,
85,
531,
267,
291,
14,
7418,
8,
66,
12,
488,
9,
267,
325,
423,
1457,
10423,
17935,
8,
66,
9,
267,
325,
14,
1457,
63,
7515,
14,
1600,
342,
267,
325,
14,
952,
3205,
1173,
480,
70,
681,
63,
396,
14,
73,
531,
267,
291,
14,
5785,
5535,
480,
70,
681,
63,
396,
14,
73,
401,
298,
23628,
15,
70,
681,
63,
396,
14,
73,
531,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
11940,
14,
1065,
63,
2219,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
504,
299,
4489,
331,
346,
14,
3205,
14,
3205,
1173,
10423,
492,
6924,
1173,
10423,
199,
504,
299,
4489,
331,
346,
14,
3205,
14,
18039,
2354,
492,
9434,
2964,
2354,
199,
504,
299,
4489,
331,
346,
14,
1208,
492,
11940,
199,
199,
533,
6496,
8,
9029,
14,
48,
4489,
331,
346,
22403,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
2925,
12,
291,
680,
5996,
342,
267,
291,
14,
396,
63,
1210,
63,
493,
275,
298,
9707,
2330,
15,
70,
681,
63,
396,
14,
73,
2,
267,
291,
14,
1457,
63,
513,
63,
11151,
275,
378,
339,
347,
892,
3339,
8,
277,
304,
267,
1145,
63,
815,
275,
9434,
2964,
2354,
342,
267,
1145,
63,
815,
14,
409,
2042,
8,
9029,
14,
1623,
63,
573,
3362,
63,
396,
63,
5803,
1012,
267,
291,
14,
1815,
8,
571,
63,
815,
14,
1078,
1012,
267,
336,
275,
6924,
1173,
10423,
342,
267,
336,
14,
5904,
2354,
6970,
8,
571,
63,
815,
9,
267,
336,
14,
409,
3205,
1173,
8,
277,
14,
396,
63,
1210,
63,
493,
9,
267,
372,
336,
339,
347,
511,
3142,
10423,
8,
277,
304,
267,
325,
275,
291,
14,
1222,
3339,
342,
267,
9364,
275,
325,
14,
2350,
14,
362,
3142,
2354,
4769,
12241,
531,
267,
291,
14,
7418,
8,
6480,
12,
488,
9,
267,
291,
14,
629,
8,
69,
14,
1457,
63,
7515,
12,
488,
9,
267,
325,
423,
1457,
10423,
17935,
8,
6480,
9,
267,
291,
14,
7418,
8,
69,
14,
1457,
63,
7515,
12,
488,
9,
267,
325,
14,
1457,
63,
7515,
14,
1600,
342,
267,
291,
14,
629,
8,
69,
14,
1457,
63,
7515,
12,
488,
9,
339,
347,
511,
3142,
1296,
8,
277,
304,
267,
325,
275,
291,
14,
1222,
3339,
342,
267,
327,
642,
1077,
1056,
2860,
267,
399,
275,
325,
14,
2350,
14,
362,
3142,
2354,
4769,
2398,
5394,
316,
15,
38,
5763,
15,
85,
531,
267,
291,
14,
7418,
8,
85,
12,
488,
9,
267,
325,
14,
265,
17809,
3142,
1296,
5234,
15,
11458,
3135,
267,
325,
423,
1457,
10423,
17935,
8,
85,
9,
267,
325,
14,
265,
17809,
3142,
1296,
5234,
15,
11458,
3135,
267,
325,
14,
11707,
342,
267,
291,
14,
629,
8,
69,
14,
1457,
63,
7515,
12,
488,
9,
339,
347,
511,
3534,
8,
277,
304,
267,
325,
275,
291,
14,
1222,
3339,
342,
267,
399,
275,
325,
14,
2350,
14,
362,
3142,
2354,
4769,
2398,
5394,
316,
15,
38,
5763,
15,
85,
531,
267,
291,
14,
7418,
8,
85,
12,
488,
9,
267,
325,
423,
1457,
10423,
17935,
8,
85,
9,
267,
325,
14,
1457,
63,
7515,
14,
1600,
342,
398,
330,
275,
325,
14,
2350,
14,
362,
3142,
2354,
4769,
6265,
83,
15,
3039,
63,
85,
531,
267,
291,
14,
7418,
8,
66,
12,
488,
9,
267,
325,
423,
1457,
10423,
17935,
8,
66,
9,
267,
325,
14,
1457,
63,
7515,
14,
1600,
342,
267,
325,
14,
952,
3205,
1173,
480,
70,
681,
63,
396,
14,
73,
531,
267,
291,
14,
5785,
5535,
480,
70,
681,
63,
396,
14,
73,
401,
298,
23628,
15,
70,
681,
63,
396,
14,
73,
531,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
11940,
14,
1065,
63,
2219,
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,
0
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,
0
] |
abhattad4/Digi-Menu
|
digimenu2/tests/string_lookup/tests.py
|
290
|
2573
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
from .models import Article, Bar, Base, Child, Foo, Whiz
class StringLookupTests(TestCase):
def test_string_form_referencing(self):
"""
Regression test for #1661 and #1662
Check that string form referencing of
models works, both as pre and post reference, on all RelatedField types.
"""
f1 = Foo(name="Foo1")
f1.save()
f2 = Foo(name="Foo2")
f2.save()
w1 = Whiz(name="Whiz1")
w1.save()
b1 = Bar(name="Bar1", normal=f1, fwd=w1, back=f2)
b1.save()
self.assertEqual(b1.normal, f1)
self.assertEqual(b1.fwd, w1)
self.assertEqual(b1.back, f2)
base1 = Base(name="Base1")
base1.save()
child1 = Child(name="Child1", parent=base1)
child1.save()
self.assertEqual(child1.parent, base1)
def test_unicode_chars_in_queries(self):
"""
Regression tests for #3937
make sure we can use unicode characters in queries.
If these tests fail on MySQL, it's a problem with the test setup.
A properly configured UTF-8 database can handle this.
"""
fx = Foo(name='Bjorn', friend='François')
fx.save()
self.assertEqual(Foo.objects.get(friend__contains='\xe7'), fx)
# We can also do the above query using UTF-8 strings.
self.assertEqual(Foo.objects.get(friend__contains=b'\xc3\xa7'), fx)
def test_queries_on_textfields(self):
"""
Regression tests for #5087
make sure we can perform queries on TextFields.
"""
a = Article(name='Test', text='The quick brown fox jumps over the lazy dog.')
a.save()
self.assertEqual(Article.objects.get(text__exact='The quick brown fox jumps over the lazy dog.'), a)
self.assertEqual(Article.objects.get(text__contains='quick brown fox'), a)
def test_ipaddress_on_postgresql(self):
"""
Regression test for #708
"like" queries on IP address fields require casting with HOST() (on PostgreSQL).
"""
a = Article(name='IP test', text='The body', submitted_from='192.0.2.100')
a.save()
self.assertEqual(repr(Article.objects.filter(submitted_from__contains='192.0.2')),
repr([a]))
# Test that the searches do not match the subnet mask (/32 in this case)
self.assertEqual(Article.objects.filter(submitted_from__contains='32').count(), 0)
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
992,
492,
8281,
12,
12377,
12,
3523,
12,
12988,
12,
8024,
12,
2816,
565,
421,
199,
533,
2624,
7521,
2925,
8,
1746,
304,
339,
347,
511,
63,
875,
63,
964,
63,
264,
21532,
8,
277,
304,
267,
408,
267,
13262,
511,
367,
327,
975,
2976,
436,
327,
975,
2789,
398,
2670,
626,
1059,
1824,
28524,
402,
267,
1709,
5419,
12,
3865,
465,
876,
436,
2963,
3659,
12,
641,
1006,
20116,
792,
2943,
14,
267,
408,
398,
289,
17,
275,
8024,
8,
354,
628,
5686,
17,
531,
267,
289,
17,
14,
2117,
342,
267,
289,
18,
275,
8024,
8,
354,
628,
5686,
18,
531,
267,
289,
18,
14,
2117,
342,
398,
336,
17,
275,
2816,
565,
8,
354,
628,
5879,
565,
17,
531,
267,
336,
17,
14,
2117,
342,
398,
330,
17,
275,
12377,
8,
354,
628,
5281,
17,
401,
3293,
29,
70,
17,
12,
31336,
29,
87,
17,
12,
1771,
29,
70,
18,
9,
267,
330,
17,
14,
2117,
342,
398,
291,
14,
629,
8,
66,
17,
14,
3302,
12,
289,
17,
9,
398,
291,
14,
629,
8,
66,
17,
14,
27912,
12,
336,
17,
9,
398,
291,
14,
629,
8,
66,
17,
14,
894,
12,
289,
18,
9,
398,
1300,
17,
275,
3523,
8,
354,
628,
1563,
17,
531,
267,
1300,
17,
14,
2117,
342,
398,
1982,
17,
275,
12988,
8,
354,
628,
3493,
17,
401,
1676,
29,
1095,
17,
9,
267,
1982,
17,
14,
2117,
342,
398,
291,
14,
629,
8,
1739,
17,
14,
1708,
12,
1300,
17,
9,
339,
347,
511,
63,
2975,
63,
6574,
63,
262,
63,
10590,
8,
277,
304,
267,
408,
267,
13262,
2295,
367,
327,
1355,
1401,
398,
1852,
3238,
781,
883,
675,
2649,
4110,
315,
9212,
14,
267,
982,
3520,
2295,
2449,
641,
11200,
12,
652,
1159,
282,
5160,
543,
314,
511,
3272,
14,
267,
437,
7684,
7526,
9094,
13,
24,
3050,
883,
2429,
642,
14,
267,
408,
398,
28020,
275,
8024,
8,
354,
534,
34,
5857,
78,
297,
32506,
534,
38,
1312,
15368,
79,
374,
358,
267,
28020,
14,
2117,
342,
267,
291,
14,
629,
8,
5686,
14,
1462,
14,
362,
8,
23472,
363,
6134,
17115,
1845,
23,
659,
28020,
9,
398,
327,
2136,
883,
2597,
886,
314,
3432,
1827,
1808,
9094,
13,
24,
3326,
14,
267,
291,
14,
629,
8,
5686,
14,
1462,
14,
362,
8,
23472,
363,
6134,
29,
66,
1154,
1812,
19,
60,
1800,
23,
659,
28020,
9,
339,
347,
511,
63,
10590,
63,
265,
63,
505,
955,
8,
277,
304,
267,
408,
267,
13262,
2295,
367,
327,
1400,
1555,
398,
1852,
3238,
781,
883,
5147,
9212,
641,
4516,
7304,
14,
267,
408,
398,
282,
275,
8281,
8,
354,
534,
774,
297,
1318,
534,
1918,
12530,
330,
18406,
7090,
88,
14882,
83,
1806,
314,
9617,
23454,
2659,
267,
282,
14,
2117,
342,
267,
291,
14,
629,
8,
7221,
14,
1462,
14,
362,
8,
505,
363,
7327,
534,
1918,
12530,
330,
18406,
7090,
88,
14882,
83,
1806,
314,
9617,
23454,
8038,
282,
9,
398,
291,
14,
629,
8,
7221,
14,
1462,
14,
362,
8,
505,
363,
6134,
534,
13239,
330,
18406,
7090,
88,
659,
282,
9,
339,
347,
511,
63,
21809,
63,
265,
63,
15437,
8,
277,
304,
267,
408,
267,
13262,
511,
367,
327,
23,
2036,
398,
298,
2930,
2,
9212,
641,
3531,
2287,
1504,
4409,
22883,
543,
25741,
342,
334,
265,
20175,
680,
267,
408,
267,
282,
275,
8281,
8,
354,
534,
1772,
511,
297,
1318,
534,
1918,
2396,
297,
16930,
63,
504,
534,
5756,
14,
16,
14,
18,
14,
1960,
358,
267,
282,
14,
2117,
342,
267,
291,
14,
629,
8,
2722,
8,
7221,
14,
1462,
14,
1541,
8,
23736,
63,
504,
363,
6134,
534,
5756,
14,
16,
14,
18,
3855,
288,
4700,
779,
65,
2459,
267,
327,
1379,
626,
314,
21858,
886,
440,
1336,
314,
6303,
3656,
334,
15,
708,
315,
642,
1930,
9,
267,
291,
14,
629,
8,
7221,
14,
1462,
14,
1541,
8,
23736,
63,
504,
363,
6134,
534,
708,
1959,
835,
1062,
378,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
992,
492,
8281,
12,
12377,
12,
3523,
12,
12988,
12,
8024,
12,
2816,
565,
421,
199,
533,
2624,
7521,
2925,
8,
1746,
304,
339,
347,
511,
63,
875,
63,
964,
63,
264,
21532,
8,
277,
304,
267,
408,
267,
13262,
511,
367,
327,
975,
2976,
436,
327,
975,
2789,
398,
2670,
626,
1059,
1824,
28524,
402,
267,
1709,
5419,
12,
3865,
465,
876,
436,
2963,
3659,
12,
641,
1006,
20116,
792,
2943,
14,
267,
408,
398,
289,
17,
275,
8024,
8,
354,
628,
5686,
17,
531,
267,
289,
17,
14,
2117,
342,
267,
289,
18,
275,
8024,
8,
354,
628,
5686,
18,
531,
267,
289,
18,
14,
2117,
342,
398,
336,
17,
275,
2816,
565,
8,
354,
628,
5879,
565,
17,
531,
267,
336,
17,
14,
2117,
342,
398,
330,
17,
275,
12377,
8,
354,
628,
5281,
17,
401,
3293,
29,
70,
17,
12,
31336,
29,
87,
17,
12,
1771,
29,
70,
18,
9,
267,
330,
17,
14,
2117,
342,
398,
291,
14,
629,
8,
66,
17,
14,
3302,
12,
289,
17,
9,
398,
291,
14,
629,
8,
66,
17,
14,
27912,
12,
336,
17,
9,
398,
291,
14,
629,
8,
66,
17,
14,
894,
12,
289,
18,
9,
398,
1300,
17,
275,
3523,
8,
354,
628,
1563,
17,
531,
267,
1300,
17,
14,
2117,
342,
398,
1982,
17,
275,
12988,
8,
354,
628,
3493,
17,
401,
1676,
29,
1095,
17,
9,
267,
1982,
17,
14,
2117,
342,
398,
291,
14,
629,
8,
1739,
17,
14,
1708,
12,
1300,
17,
9,
339,
347,
511,
63,
2975,
63,
6574,
63,
262,
63,
10590,
8,
277,
304,
267,
408,
267,
13262,
2295,
367,
327,
1355,
1401,
398,
1852,
3238,
781,
883,
675,
2649,
4110,
315,
9212,
14,
267,
982,
3520,
2295,
2449,
641,
11200,
12,
652,
1159,
282,
5160,
543,
314,
511,
3272,
14,
267,
437,
7684,
7526,
9094,
13,
24,
3050,
883,
2429,
642,
14,
267,
408,
398,
28020,
275,
8024,
8,
354,
534,
34,
5857,
78,
297,
32506,
534,
38,
1312,
15368,
79,
374,
358,
267,
28020,
14,
2117,
342,
267,
291,
14,
629,
8,
5686,
14,
1462,
14,
362,
8,
23472,
363,
6134,
17115,
1845,
23,
659,
28020,
9,
398,
327,
2136,
883,
2597,
886,
314,
3432,
1827,
1808,
9094,
13,
24,
3326,
14,
267,
291,
14,
629,
8,
5686,
14,
1462,
14,
362,
8,
23472,
363,
6134,
29,
66,
1154,
1812,
19,
60,
1800,
23,
659,
28020,
9,
339,
347,
511,
63,
10590,
63,
265,
63,
505,
955,
8,
277,
304,
267,
408,
267,
13262,
2295,
367,
327,
1400,
1555,
398,
1852,
3238,
781,
883,
5147,
9212,
641,
4516,
7304,
14,
267,
408,
398,
282,
275,
8281,
8,
354,
534,
774,
297,
1318,
534,
1918,
12530,
330,
18406,
7090,
88,
14882,
83,
1806,
314,
9617,
23454,
2659,
267,
282,
14,
2117,
342,
267,
291,
14,
629,
8,
7221,
14,
1462,
14,
362,
8,
505,
363,
7327,
534,
1918,
12530,
330,
18406,
7090,
88,
14882,
83,
1806,
314,
9617,
23454,
8038,
282,
9,
398,
291,
14,
629,
8,
7221,
14,
1462,
14,
362,
8,
505,
363,
6134,
534,
13239,
330,
18406,
7090,
88,
659,
282,
9,
339,
347,
511,
63,
21809,
63,
265,
63,
15437,
8,
277,
304,
267,
408,
267,
13262,
511,
367,
327,
23,
2036,
398,
298,
2930,
2,
9212,
641,
3531,
2287,
1504,
4409,
22883,
543,
25741,
342,
334,
265,
20175,
680,
267,
408,
267,
282,
275,
8281,
8,
354,
534,
1772,
511,
297,
1318,
534,
1918,
2396,
297,
16930,
63,
504,
534,
5756,
14,
16,
14,
18,
14,
1960,
358,
267,
282,
14,
2117,
342,
267,
291,
14,
629,
8,
2722,
8,
7221,
14,
1462,
14,
1541,
8,
23736,
63,
504,
363,
6134,
534,
5756,
14,
16,
14,
18,
3855,
288,
4700,
779,
65,
2459,
267,
327,
1379,
626,
314,
21858,
886,
440,
1336,
314,
6303,
3656,
334,
15,
708,
315,
642,
1930,
9,
267,
291,
14,
629,
8,
7221,
14,
1462,
14,
1541,
8,
23736,
63,
504,
363,
6134,
534,
708,
1959,
835,
1062,
378,
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,
32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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
gautam1858/tensorflow
|
tensorflow/python/training/server_lib_multiple_containers_test.py
|
36
|
2495
|
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for tf.GrpcServer."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.python.client import session
from tensorflow.python.framework import errors_impl
from tensorflow.python.framework import ops
from tensorflow.python.framework import test_util
from tensorflow.python.ops import variables
from tensorflow.python.platform import test
from tensorflow.python.training import server_lib
class MultipleContainersTest(test.TestCase):
# Verifies behavior of tf.Session.reset() with multiple containers using
# tf.container.
# TODO(b/34465411): Starting multiple servers with different configurations
# in the same test is flaky. Move this test case back into
# "server_lib_test.py" when this is no longer the case.
@test_util.run_deprecated_v1
def testMultipleContainers(self):
with ops.container("test0"):
v0 = variables.Variable(1.0, name="v0")
with ops.container("test1"):
v1 = variables.Variable(2.0, name="v0")
server = server_lib.Server.create_local_server()
sess = session.Session(server.target)
sess.run(variables.global_variables_initializer())
self.assertAllEqual(1.0, sess.run(v0))
self.assertAllEqual(2.0, sess.run(v1))
# Resets container. Session aborts.
session.Session.reset(server.target, ["test0"])
with self.assertRaises(errors_impl.AbortedError):
sess.run(v1)
# Connects to the same target. Device memory for the v0 would have
# been released, so it will be uninitialized. But v1 should still
# be valid.
sess = session.Session(server.target)
with self.assertRaises(errors_impl.FailedPreconditionError):
sess.run(v0)
self.assertAllEqual(2.0, sess.run(v1))
if __name__ == "__main__":
test.main()
|
apache-2.0
|
[
3,
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
2833,
14,
39,
4354,
3120,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
1258,
492,
2351,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
63,
5472,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
7588,
492,
1654,
63,
773,
421,
199,
533,
14326,
31266,
1192,
774,
8,
396,
14,
1746,
304,
819,
327,
26114,
5953,
402,
2833,
14,
4434,
14,
3958,
342,
543,
3663,
15333,
1808,
523,
327,
2833,
14,
3600,
14,
523,
327,
3254,
8,
66,
15,
1082,
2466,
1477,
845,
304,
24175,
3663,
8037,
543,
3365,
13422,
523,
327,
315,
314,
2011,
511,
365,
17566,
10562,
14,
14171,
642,
511,
1930,
1771,
1901,
523,
327,
298,
1000,
63,
773,
63,
396,
14,
647,
2,
1380,
642,
365,
949,
8088,
314,
1930,
14,
523,
768,
396,
63,
1974,
14,
1065,
63,
6667,
63,
86,
17,
523,
347,
511,
8433,
31266,
1192,
8,
277,
304,
272,
543,
4156,
14,
3600,
480,
396,
16,
2349,
489,
373,
16,
275,
2860,
14,
2773,
8,
17,
14,
16,
12,
536,
628,
86,
16,
531,
272,
543,
4156,
14,
3600,
480,
396,
17,
2349,
489,
373,
17,
275,
2860,
14,
2773,
8,
18,
14,
16,
12,
536,
628,
86,
16,
531,
272,
1654,
275,
1654,
63,
773,
14,
3120,
14,
981,
63,
1832,
63,
1000,
342,
272,
4043,
275,
2351,
14,
4434,
8,
1000,
14,
1375,
9,
272,
4043,
14,
1065,
8,
3669,
14,
2966,
63,
3669,
63,
6498,
1012,
272,
291,
14,
7069,
8,
17,
14,
16,
12,
4043,
14,
1065,
8,
86,
16,
430,
272,
291,
14,
7069,
8,
18,
14,
16,
12,
4043,
14,
1065,
8,
86,
17,
430,
339,
327,
799,
2193,
3970,
14,
8596,
12004,
83,
14,
272,
2351,
14,
4434,
14,
3958,
8,
1000,
14,
1375,
12,
2097,
396,
16,
3135,
272,
543,
291,
14,
1855,
8,
2550,
63,
5472,
14,
5583,
1376,
547,
304,
489,
4043,
14,
1065,
8,
86,
17,
9,
339,
327,
15175,
83,
370,
314,
2011,
1347,
14,
12272,
4402,
367,
314,
373,
16,
3955,
1172,
272,
327,
2757,
14286,
12,
880,
652,
911,
506,
625,
12486,
14,
11017,
373,
17,
1077,
5139,
272,
327,
506,
1686,
14,
272,
4043,
275,
2351,
14,
4434,
8,
1000,
14,
1375,
9,
272,
543,
291,
14,
1855,
8,
2550,
63,
5472,
14,
4276,
2398,
5394,
547,
304,
489,
4043,
14,
1065,
8,
86,
16,
9,
272,
291,
14,
7069,
8,
18,
14,
16,
12,
4043,
14,
1065,
8,
86,
17,
430,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
511,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
2833,
14,
39,
4354,
3120,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
1258,
492,
2351,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
63,
5472,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
7588,
492,
1654,
63,
773,
421,
199,
533,
14326,
31266,
1192,
774,
8,
396,
14,
1746,
304,
819,
327,
26114,
5953,
402,
2833,
14,
4434,
14,
3958,
342,
543,
3663,
15333,
1808,
523,
327,
2833,
14,
3600,
14,
523,
327,
3254,
8,
66,
15,
1082,
2466,
1477,
845,
304,
24175,
3663,
8037,
543,
3365,
13422,
523,
327,
315,
314,
2011,
511,
365,
17566,
10562,
14,
14171,
642,
511,
1930,
1771,
1901,
523,
327,
298,
1000,
63,
773,
63,
396,
14,
647,
2,
1380,
642,
365,
949,
8088,
314,
1930,
14,
523,
768,
396,
63,
1974,
14,
1065,
63,
6667,
63,
86,
17,
523,
347,
511,
8433,
31266,
1192,
8,
277,
304,
272,
543,
4156,
14,
3600,
480,
396,
16,
2349,
489,
373,
16,
275,
2860,
14,
2773,
8,
17,
14,
16,
12,
536,
628,
86,
16,
531,
272,
543,
4156,
14,
3600,
480,
396,
17,
2349,
489,
373,
17,
275,
2860,
14,
2773,
8,
18,
14,
16,
12,
536,
628,
86,
16,
531,
272,
1654,
275,
1654,
63,
773,
14,
3120,
14,
981,
63,
1832,
63,
1000,
342,
272,
4043,
275,
2351,
14,
4434,
8,
1000,
14,
1375,
9,
272,
4043,
14,
1065,
8,
3669,
14,
2966,
63,
3669,
63,
6498,
1012,
272,
291,
14,
7069,
8,
17,
14,
16,
12,
4043,
14,
1065,
8,
86,
16,
430,
272,
291,
14,
7069,
8,
18,
14,
16,
12,
4043,
14,
1065,
8,
86,
17,
430,
339,
327,
799,
2193,
3970,
14,
8596,
12004,
83,
14,
272,
2351,
14,
4434,
14,
3958,
8,
1000,
14,
1375,
12,
2097,
396,
16,
3135,
272,
543,
291,
14,
1855,
8,
2550,
63,
5472,
14,
5583,
1376,
547,
304,
489,
4043,
14,
1065,
8,
86,
17,
9,
339,
327,
15175,
83,
370,
314,
2011,
1347,
14,
12272,
4402,
367,
314,
373,
16,
3955,
1172,
272,
327,
2757,
14286,
12,
880,
652,
911,
506,
625,
12486,
14,
11017,
373,
17,
1077,
5139,
272,
327,
506,
1686,
14,
272,
4043,
275,
2351,
14,
4434,
8,
1000,
14,
1375,
9,
272,
543,
291,
14,
1855,
8,
2550,
63,
5472,
14,
4276,
2398,
5394,
547,
304,
489,
4043,
14,
1065,
8,
86,
16,
9,
272,
291,
14,
7069,
8,
18,
14,
16,
12,
4043,
14,
1065,
8,
86,
17,
430,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
511,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wbinventor/openmc
|
openmc/deplete/atom_number.py
|
3
|
5889
|
"""AtomNumber module.
An ndarray to store atom densities with string, integer, or slice indexing.
"""
from collections import OrderedDict
import numpy as np
class AtomNumber(object):
"""Stores local material compositions (atoms of each nuclide).
Parameters
----------
local_mats : list of str
Material IDs
nuclides : list of str
Nuclides to be tracked
volume : dict
Volume of each material in [cm^3]
n_nuc_burn : int
Number of nuclides to be burned.
Attributes
----------
index_mat : dict
A dictionary mapping material ID as string to index.
index_nuc : dict
A dictionary mapping nuclide name to index.
volume : numpy.ndarray
Volume of each material in [cm^3]. If a volume is not found, it defaults
to 1 so that reading density still works correctly.
number : numpy.ndarray
Array storing total atoms for each material/nuclide
materials : list of str
Material IDs as strings
nuclides : list of str
All nuclide names
burnable_nuclides : list of str
Burnable nuclides names. Used for sorting the simulation.
n_nuc_burn : int
Number of burnable nuclides.
n_nuc : int
Number of nuclides.
"""
def __init__(self, local_mats, nuclides, volume, n_nuc_burn):
self.index_mat = OrderedDict((mat, i) for i, mat in enumerate(local_mats))
self.index_nuc = OrderedDict((nuc, i) for i, nuc in enumerate(nuclides))
self.volume = np.ones(len(local_mats))
for mat, val in volume.items():
if mat in self.index_mat:
ind = self.index_mat[mat]
self.volume[ind] = val
self.n_nuc_burn = n_nuc_burn
self.number = np.zeros((len(local_mats), len(nuclides)))
def __getitem__(self, pos):
"""Retrieves total atom number from AtomNumber.
Parameters
----------
pos : tuple
A two-length tuple containing a material index and a nuc index.
These indexes can be strings (which get converted to integers via
the dictionaries), integers used directly, or slices.
Returns
-------
numpy.ndarray
The value indexed from self.number.
"""
mat, nuc = pos
if isinstance(mat, str):
mat = self.index_mat[mat]
if isinstance(nuc, str):
nuc = self.index_nuc[nuc]
return self.number[mat, nuc]
def __setitem__(self, pos, val):
"""Sets total atom number into AtomNumber.
Parameters
----------
pos : tuple
A two-length tuple containing a material index and a nuc index.
These indexes can be strings (which get converted to integers via
the dictionaries), integers used directly, or slices.
val : float
The value [atom] to set the array to.
"""
mat, nuc = pos
if isinstance(mat, str):
mat = self.index_mat[mat]
if isinstance(nuc, str):
nuc = self.index_nuc[nuc]
self.number[mat, nuc] = val
@property
def materials(self):
return self.index_mat.keys()
@property
def nuclides(self):
return self.index_nuc.keys()
@property
def n_nuc(self):
return len(self.index_nuc)
@property
def burnable_nuclides(self):
return [nuc for nuc, ind in self.index_nuc.items()
if ind < self.n_nuc_burn]
def get_atom_density(self, mat, nuc):
"""Accesses atom density instead of total number.
Parameters
----------
mat : str, int or slice
Material index.
nuc : str, int or slice
Nuclide index.
Returns
-------
numpy.ndarray
Density in [atom/cm^3]
"""
if isinstance(mat, str):
mat = self.index_mat[mat]
if isinstance(nuc, str):
nuc = self.index_nuc[nuc]
return self[mat, nuc] / self.volume[mat]
def set_atom_density(self, mat, nuc, val):
"""Sets atom density instead of total number.
Parameters
----------
mat : str, int or slice
Material index.
nuc : str, int or slice
Nuclide index.
val : numpy.ndarray
Array of densities to set in [atom/cm^3]
"""
if isinstance(mat, str):
mat = self.index_mat[mat]
if isinstance(nuc, str):
nuc = self.index_nuc[nuc]
self[mat, nuc] = val * self.volume[mat]
def get_mat_slice(self, mat):
"""Gets atom quantity indexed by mats for all burned nuclides
Parameters
----------
mat : str, int or slice
Material index.
Returns
-------
numpy.ndarray
The slice requested in [atom].
"""
if isinstance(mat, str):
mat = self.index_mat[mat]
return self[mat, :self.n_nuc_burn]
def set_mat_slice(self, mat, val):
"""Sets atom quantity indexed by mats for all burned nuclides
Parameters
----------
mat : str, int or slice
Material index.
val : numpy.ndarray
The slice to set in [atom]
"""
if isinstance(mat, str):
mat = self.index_mat[mat]
self[mat, :self.n_nuc_burn] = val
def set_density(self, total_density):
"""Sets density.
Sets the density in the exact same order as total_density_list outputs,
allowing for internal consistency
Parameters
----------
total_density : list of numpy.ndarray
Total atoms.
"""
for i, density_slice in enumerate(total_density):
self.set_mat_slice(i, density_slice)
|
mit
|
[
624,
12097,
3259,
859,
14,
199,
199,
2493,
6800,
370,
3877,
6222,
5376,
338,
1417,
543,
1059,
12,
3000,
12,
503,
6014,
16356,
14,
199,
624,
199,
504,
5055,
492,
8773,
199,
199,
646,
2680,
465,
980,
421,
199,
533,
18840,
3259,
8,
785,
304,
272,
408,
4759,
470,
2257,
6285,
11395,
6150,
334,
11521,
402,
1924,
302,
947,
8409,
680,
339,
3897,
272,
4143,
272,
2257,
63,
569,
83,
520,
769,
402,
620,
267,
26570,
11449,
272,
302,
947,
317,
3424,
520,
769,
402,
620,
267,
653,
947,
317,
3424,
370,
506,
23268,
272,
3301,
520,
1211,
267,
15018,
402,
1924,
6285,
315,
359,
4400,
62,
19,
61,
272,
302,
63,
30984,
63,
30736,
520,
1109,
267,
4860,
402,
302,
947,
317,
3424,
370,
506,
330,
349,
379,
14,
339,
9382,
272,
4143,
272,
1478,
63,
569,
520,
1211,
267,
437,
2600,
4412,
6285,
2870,
465,
1059,
370,
1478,
14,
272,
1478,
63,
30984,
520,
1211,
267,
437,
2600,
4412,
302,
947,
8409,
536,
370,
1478,
14,
272,
3301,
520,
2680,
14,
8237,
267,
15018,
402,
1924,
6285,
315,
359,
4400,
62,
19,
1055,
982,
282,
3301,
365,
440,
1911,
12,
652,
4243,
267,
370,
413,
880,
626,
7664,
13650,
5139,
5419,
6657,
14,
272,
1329,
520,
2680,
14,
8237,
267,
8725,
16915,
3141,
14503,
367,
1924,
6285,
15,
30984,
8409,
272,
8418,
520,
769,
402,
620,
267,
26570,
11449,
465,
3326,
272,
302,
947,
317,
3424,
520,
769,
402,
620,
267,
2900,
302,
947,
8409,
1561,
272,
330,
349,
461,
63,
30984,
317,
3424,
520,
769,
402,
620,
267,
699,
349,
461,
302,
947,
317,
3424,
1561,
14,
8051,
367,
13351,
314,
17625,
14,
272,
302,
63,
30984,
63,
30736,
520,
1109,
267,
4860,
402,
330,
349,
461,
302,
947,
317,
3424,
14,
272,
302,
63,
30984,
520,
1109,
267,
4860,
402,
302,
947,
317,
3424,
14,
339,
408,
272,
347,
636,
826,
721,
277,
12,
2257,
63,
569,
83,
12,
302,
947,
317,
3424,
12,
3301,
12,
302,
63,
30984,
63,
30736,
304,
267,
291,
14,
1080,
63,
569,
275,
8773,
1332,
569,
12,
284,
9,
367,
284,
12,
2530,
315,
3874,
8,
1832,
63,
569,
83,
430,
267,
291,
14,
1080,
63,
30984,
275,
8773,
1332,
30984,
12,
284,
9,
367,
284,
12,
302,
947,
315,
3874,
8,
30984,
317,
3424,
430,
398,
291,
14,
2405,
275,
980,
14,
4548,
8,
552,
8,
1832,
63,
569,
83,
430,
267,
367,
2530,
12,
1139,
315,
3301,
14,
1744,
837,
288,
340,
2530,
315,
291,
14,
1080,
63,
569,
26,
355,
7654,
275,
291,
14,
1080,
63,
569,
59,
569,
61,
355,
291,
14,
2405,
59,
688,
61,
275,
1139,
398,
291,
14,
78,
63,
30984,
63,
30736,
275,
302,
63,
30984,
63,
30736,
398,
291,
14,
1955,
275,
980,
14,
4250,
1332,
552,
8,
1832,
63,
569,
83,
395,
822,
8,
30984,
317,
3424,
1724,
339,
347,
636,
6095,
721,
277,
12,
2086,
304,
267,
408,
28112,
3141,
6222,
1329,
687,
18840,
3259,
14,
398,
3897,
267,
4143,
267,
2086,
520,
2008,
288,
437,
2877,
13,
1267,
2008,
3035,
282,
6285,
1478,
436,
282,
302,
947,
1478,
14,
288,
5723,
10507,
883,
506,
3326,
334,
6777,
664,
6702,
370,
9446,
4799,
288,
314,
11196,
395,
9446,
1202,
5370,
12,
503,
17184,
14,
398,
1803,
267,
5514,
267,
2680,
14,
8237,
288,
710,
574,
15235,
687,
291,
14,
1955,
14,
267,
408,
398,
2530,
12,
302,
947,
275,
2086,
267,
340,
1228,
8,
569,
12,
620,
304,
288,
2530,
275,
291,
14,
1080,
63,
569,
59,
569,
61,
267,
340,
1228,
8,
30984,
12,
620,
304,
288,
302,
947,
275,
291,
14,
1080,
63,
30984,
59,
30984,
61,
398,
372,
291,
14,
1955,
59,
569,
12,
302,
947,
61,
339,
347,
636,
8617,
721,
277,
12,
2086,
12,
1139,
304,
267,
408,
9899,
3141,
6222,
1329,
1901,
18840,
3259,
14,
398,
3897,
267,
4143,
267,
2086,
520,
2008,
288,
437,
2877,
13,
1267,
2008,
3035,
282,
6285,
1478,
436,
282,
302,
947,
1478,
14,
288,
5723,
10507,
883,
506,
3326,
334,
6777,
664,
6702,
370,
9446,
4799,
288,
314,
11196,
395,
9446,
1202,
5370,
12,
503,
17184,
14,
267,
1139,
520,
2069,
288,
710,
574,
359,
4188,
61,
370,
663,
314,
1625,
370,
14,
398,
408,
267,
2530,
12,
302,
947,
275,
2086,
267,
340,
1228,
8,
569,
12,
620,
304,
288,
2530,
275,
291,
14,
1080,
63,
569,
59,
569,
61,
267,
340,
1228,
8,
30984,
12,
620,
304,
288,
302,
947,
275,
291,
14,
1080,
63,
30984,
59,
30984,
61,
398,
291,
14,
1955,
59,
569,
12,
302,
947,
61,
275,
1139,
339,
768,
1829,
272,
347,
8418,
8,
277,
304,
267,
372,
291,
14,
1080,
63,
569,
14,
1612,
342,
339,
768,
1829,
272,
347,
302,
947,
317,
3424,
8,
277,
304,
267,
372,
291,
14,
1080,
63,
30984,
14,
1612,
342,
339,
768,
1829,
272,
347,
302,
63,
30984,
8,
277,
304,
267,
372,
822,
8,
277,
14,
1080,
63,
30984,
9,
339,
768,
1829,
272,
347,
330,
349,
461,
63,
30984,
317,
3424,
8,
277,
304,
267,
372,
359,
30984,
367,
302,
947,
12,
7654,
315,
291,
14,
1080,
63,
30984,
14,
1744,
342,
355,
340,
7654,
665,
291,
14,
78,
63,
30984,
63,
30736,
61,
339,
347,
664,
63,
4188,
63,
15669,
8,
277,
12,
2530,
12,
302,
947,
304,
267,
408,
1945,
5804,
6222,
13650,
3140,
402,
3141,
1329,
14,
398,
3897,
267,
4143,
267,
2530,
520,
620,
12,
1109,
503,
6014,
288,
26570,
1478,
14,
267,
302,
947,
520,
620,
12,
1109,
503,
6014,
288,
653,
947,
8409,
1478,
14,
398,
1803,
267,
5514,
267,
2680,
14,
8237,
288,
25187,
3677,
315,
359,
4188,
15,
4400,
62,
19,
61,
398,
408,
267,
340,
1228,
8,
569,
12,
620,
304,
288,
2530,
275,
291,
14,
1080,
63,
569,
59,
569,
61,
267,
340,
1228,
8,
30984,
12,
620,
304,
288,
302,
947,
275,
291,
14,
1080,
63,
30984,
59,
30984,
61,
398,
372,
291,
59,
569,
12,
302,
947,
61,
1182,
291,
14,
2405,
59,
569,
61,
339,
347,
663,
63,
4188,
63,
15669,
8,
277,
12,
2530,
12,
302,
947,
12,
1139,
304,
267
] |
[
12097,
3259,
859,
14,
199,
199,
2493,
6800,
370,
3877,
6222,
5376,
338,
1417,
543,
1059,
12,
3000,
12,
503,
6014,
16356,
14,
199,
624,
199,
504,
5055,
492,
8773,
199,
199,
646,
2680,
465,
980,
421,
199,
533,
18840,
3259,
8,
785,
304,
272,
408,
4759,
470,
2257,
6285,
11395,
6150,
334,
11521,
402,
1924,
302,
947,
8409,
680,
339,
3897,
272,
4143,
272,
2257,
63,
569,
83,
520,
769,
402,
620,
267,
26570,
11449,
272,
302,
947,
317,
3424,
520,
769,
402,
620,
267,
653,
947,
317,
3424,
370,
506,
23268,
272,
3301,
520,
1211,
267,
15018,
402,
1924,
6285,
315,
359,
4400,
62,
19,
61,
272,
302,
63,
30984,
63,
30736,
520,
1109,
267,
4860,
402,
302,
947,
317,
3424,
370,
506,
330,
349,
379,
14,
339,
9382,
272,
4143,
272,
1478,
63,
569,
520,
1211,
267,
437,
2600,
4412,
6285,
2870,
465,
1059,
370,
1478,
14,
272,
1478,
63,
30984,
520,
1211,
267,
437,
2600,
4412,
302,
947,
8409,
536,
370,
1478,
14,
272,
3301,
520,
2680,
14,
8237,
267,
15018,
402,
1924,
6285,
315,
359,
4400,
62,
19,
1055,
982,
282,
3301,
365,
440,
1911,
12,
652,
4243,
267,
370,
413,
880,
626,
7664,
13650,
5139,
5419,
6657,
14,
272,
1329,
520,
2680,
14,
8237,
267,
8725,
16915,
3141,
14503,
367,
1924,
6285,
15,
30984,
8409,
272,
8418,
520,
769,
402,
620,
267,
26570,
11449,
465,
3326,
272,
302,
947,
317,
3424,
520,
769,
402,
620,
267,
2900,
302,
947,
8409,
1561,
272,
330,
349,
461,
63,
30984,
317,
3424,
520,
769,
402,
620,
267,
699,
349,
461,
302,
947,
317,
3424,
1561,
14,
8051,
367,
13351,
314,
17625,
14,
272,
302,
63,
30984,
63,
30736,
520,
1109,
267,
4860,
402,
330,
349,
461,
302,
947,
317,
3424,
14,
272,
302,
63,
30984,
520,
1109,
267,
4860,
402,
302,
947,
317,
3424,
14,
339,
408,
272,
347,
636,
826,
721,
277,
12,
2257,
63,
569,
83,
12,
302,
947,
317,
3424,
12,
3301,
12,
302,
63,
30984,
63,
30736,
304,
267,
291,
14,
1080,
63,
569,
275,
8773,
1332,
569,
12,
284,
9,
367,
284,
12,
2530,
315,
3874,
8,
1832,
63,
569,
83,
430,
267,
291,
14,
1080,
63,
30984,
275,
8773,
1332,
30984,
12,
284,
9,
367,
284,
12,
302,
947,
315,
3874,
8,
30984,
317,
3424,
430,
398,
291,
14,
2405,
275,
980,
14,
4548,
8,
552,
8,
1832,
63,
569,
83,
430,
267,
367,
2530,
12,
1139,
315,
3301,
14,
1744,
837,
288,
340,
2530,
315,
291,
14,
1080,
63,
569,
26,
355,
7654,
275,
291,
14,
1080,
63,
569,
59,
569,
61,
355,
291,
14,
2405,
59,
688,
61,
275,
1139,
398,
291,
14,
78,
63,
30984,
63,
30736,
275,
302,
63,
30984,
63,
30736,
398,
291,
14,
1955,
275,
980,
14,
4250,
1332,
552,
8,
1832,
63,
569,
83,
395,
822,
8,
30984,
317,
3424,
1724,
339,
347,
636,
6095,
721,
277,
12,
2086,
304,
267,
408,
28112,
3141,
6222,
1329,
687,
18840,
3259,
14,
398,
3897,
267,
4143,
267,
2086,
520,
2008,
288,
437,
2877,
13,
1267,
2008,
3035,
282,
6285,
1478,
436,
282,
302,
947,
1478,
14,
288,
5723,
10507,
883,
506,
3326,
334,
6777,
664,
6702,
370,
9446,
4799,
288,
314,
11196,
395,
9446,
1202,
5370,
12,
503,
17184,
14,
398,
1803,
267,
5514,
267,
2680,
14,
8237,
288,
710,
574,
15235,
687,
291,
14,
1955,
14,
267,
408,
398,
2530,
12,
302,
947,
275,
2086,
267,
340,
1228,
8,
569,
12,
620,
304,
288,
2530,
275,
291,
14,
1080,
63,
569,
59,
569,
61,
267,
340,
1228,
8,
30984,
12,
620,
304,
288,
302,
947,
275,
291,
14,
1080,
63,
30984,
59,
30984,
61,
398,
372,
291,
14,
1955,
59,
569,
12,
302,
947,
61,
339,
347,
636,
8617,
721,
277,
12,
2086,
12,
1139,
304,
267,
408,
9899,
3141,
6222,
1329,
1901,
18840,
3259,
14,
398,
3897,
267,
4143,
267,
2086,
520,
2008,
288,
437,
2877,
13,
1267,
2008,
3035,
282,
6285,
1478,
436,
282,
302,
947,
1478,
14,
288,
5723,
10507,
883,
506,
3326,
334,
6777,
664,
6702,
370,
9446,
4799,
288,
314,
11196,
395,
9446,
1202,
5370,
12,
503,
17184,
14,
267,
1139,
520,
2069,
288,
710,
574,
359,
4188,
61,
370,
663,
314,
1625,
370,
14,
398,
408,
267,
2530,
12,
302,
947,
275,
2086,
267,
340,
1228,
8,
569,
12,
620,
304,
288,
2530,
275,
291,
14,
1080,
63,
569,
59,
569,
61,
267,
340,
1228,
8,
30984,
12,
620,
304,
288,
302,
947,
275,
291,
14,
1080,
63,
30984,
59,
30984,
61,
398,
291,
14,
1955,
59,
569,
12,
302,
947,
61,
275,
1139,
339,
768,
1829,
272,
347,
8418,
8,
277,
304,
267,
372,
291,
14,
1080,
63,
569,
14,
1612,
342,
339,
768,
1829,
272,
347,
302,
947,
317,
3424,
8,
277,
304,
267,
372,
291,
14,
1080,
63,
30984,
14,
1612,
342,
339,
768,
1829,
272,
347,
302,
63,
30984,
8,
277,
304,
267,
372,
822,
8,
277,
14,
1080,
63,
30984,
9,
339,
768,
1829,
272,
347,
330,
349,
461,
63,
30984,
317,
3424,
8,
277,
304,
267,
372,
359,
30984,
367,
302,
947,
12,
7654,
315,
291,
14,
1080,
63,
30984,
14,
1744,
342,
355,
340,
7654,
665,
291,
14,
78,
63,
30984,
63,
30736,
61,
339,
347,
664,
63,
4188,
63,
15669,
8,
277,
12,
2530,
12,
302,
947,
304,
267,
408,
1945,
5804,
6222,
13650,
3140,
402,
3141,
1329,
14,
398,
3897,
267,
4143,
267,
2530,
520,
620,
12,
1109,
503,
6014,
288,
26570,
1478,
14,
267,
302,
947,
520,
620,
12,
1109,
503,
6014,
288,
653,
947,
8409,
1478,
14,
398,
1803,
267,
5514,
267,
2680,
14,
8237,
288,
25187,
3677,
315,
359,
4188,
15,
4400,
62,
19,
61,
398,
408,
267,
340,
1228,
8,
569,
12,
620,
304,
288,
2530,
275,
291,
14,
1080,
63,
569,
59,
569,
61,
267,
340,
1228,
8,
30984,
12,
620,
304,
288,
302,
947,
275,
291,
14,
1080,
63,
30984,
59,
30984,
61,
398,
372,
291,
59,
569,
12,
302,
947,
61,
1182,
291,
14,
2405,
59,
569,
61,
339,
347,
663,
63,
4188,
63,
15669,
8,
277,
12,
2530,
12,
302,
947,
12,
1139,
304,
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,
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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
] |
Nervanti/eettee
|
api/taggit/tests/tests.py
|
1
|
24339
|
from __future__ import absolute_import, unicode_literals
from unittest import TestCase as UnitTestCase
import django
from django.contrib.contenttypes.models import ContentType
from django.core import serializers
from django.core.exceptions import ImproperlyConfigured, ValidationError
from django.test import TestCase, TransactionTestCase
from django.utils.encoding import force_text
from .forms import CustomPKFoodForm, DirectFoodForm, FoodForm, OfficialFoodForm
from .models import (Article, Child, CustomManager, CustomPKFood,
CustomPKHousePet, CustomPKPet, DirectFood,
DirectHousePet, DirectPet, Food, HousePet, Movie,
OfficialFood, OfficialHousePet, OfficialPet,
OfficialTag, OfficialThroughModel, Pet, Photo,
TaggedCustomPKFood, TaggedCustomPKPet, TaggedFood,
TaggedPet)
from taggit.managers import _model_name, _TaggableManager, TaggableManager
from taggit.models import Tag, TaggedItem
from taggit.utils import edit_string_for_tags, parse_tags
try:
from unittest import skipIf, skipUnless
except ImportError:
from django.utils.unittest import skipIf, skipUnless
class BaseTaggingTest(object):
def assert_tags_equal(self, qs, tags, sort=True, attr="name"):
got = [getattr(obj, attr) for obj in qs]
if sort:
got.sort()
tags.sort()
self.assertEqual(got, tags)
def _get_form_str(self, form_str):
if django.VERSION >= (1, 3):
form_str %= {
"help_start": '<span class="helptext">',
"help_stop": "</span>"
}
else:
form_str %= {
"help_start": "",
"help_stop": ""
}
return form_str
def assert_form_renders(self, form, html):
self.assertHTMLEqual(str(form), self._get_form_str(html))
class BaseTaggingTestCase(TestCase, BaseTaggingTest):
pass
class BaseTaggingTransactionTestCase(TransactionTestCase, BaseTaggingTest):
pass
class TagModelTestCase(BaseTaggingTransactionTestCase):
food_model = Food
tag_model = Tag
def test_unique_slug(self):
apple = self.food_model.objects.create(name="apple")
apple.tags.add("Red", "red")
def test_update(self):
special = self.tag_model.objects.create(name="special")
special.save()
def test_add(self):
apple = self.food_model.objects.create(name="apple")
yummy = self.tag_model.objects.create(name="yummy")
apple.tags.add(yummy)
def test_slugify(self):
a = Article.objects.create(title="django-taggit 1.0 Released")
a.tags.add("awesome", "release", "AWESOME")
self.assert_tags_equal(a.tags.all(), [
"category-awesome",
"category-release",
"category-awesome-1"
], attr="slug")
def test_integers(self):
"""Adding an integer as a tag should raise a ValueError (#237)."""
apple = self.food_model.objects.create(name="apple")
with self.assertRaisesRegexp(ValueError, (
r"Cannot add 1 \(<(type|class) 'int'>\). "
r"Expected <class 'django.db.models.base.ModelBase'> or str.")):
apple.tags.add(1)
class TagModelDirectTestCase(TagModelTestCase):
food_model = DirectFood
tag_model = Tag
class TagModelCustomPKTestCase(TagModelTestCase):
food_model = CustomPKFood
tag_model = Tag
class TagModelOfficialTestCase(TagModelTestCase):
food_model = OfficialFood
tag_model = OfficialTag
class TaggableManagerTestCase(BaseTaggingTestCase):
food_model = Food
pet_model = Pet
housepet_model = HousePet
taggeditem_model = TaggedItem
tag_model = Tag
def test_add_tag(self):
apple = self.food_model.objects.create(name="apple")
self.assertEqual(list(apple.tags.all()), [])
self.assertEqual(list(self.food_model.tags.all()), [])
apple.tags.add('green')
self.assert_tags_equal(apple.tags.all(), ['green'])
self.assert_tags_equal(self.food_model.tags.all(), ['green'])
pear = self.food_model.objects.create(name="pear")
pear.tags.add('green')
self.assert_tags_equal(pear.tags.all(), ['green'])
self.assert_tags_equal(self.food_model.tags.all(), ['green'])
apple.tags.add('red')
self.assert_tags_equal(apple.tags.all(), ['green', 'red'])
self.assert_tags_equal(self.food_model.tags.all(), ['green', 'red'])
self.assert_tags_equal(
self.food_model.tags.most_common(),
['green', 'red'],
sort=False
)
apple.tags.remove('green')
self.assert_tags_equal(apple.tags.all(), ['red'])
self.assert_tags_equal(self.food_model.tags.all(), ['green', 'red'])
tag = self.tag_model.objects.create(name="delicious")
apple.tags.add(tag)
self.assert_tags_equal(apple.tags.all(), ["red", "delicious"])
apple.delete()
self.assert_tags_equal(self.food_model.tags.all(), ["green"])
def test_add_queries(self):
# Prefill content type cache:
ContentType.objects.get_for_model(self.food_model)
apple = self.food_model.objects.create(name="apple")
# 1 query to see which tags exist
# + 3 queries to create the tags.
# + 6 queries to create the intermediary things (including SELECTs, to
# make sure we don't double create.
# + 12 on Django 1.6 for save points.
queries = 22
if django.VERSION < (1, 6):
queries -= 12
self.assertNumQueries(queries, apple.tags.add, "red", "delicious", "green")
pear = self.food_model.objects.create(name="pear")
# 1 query to see which tags exist
# + 4 queries to create the intermeidary things (including SELECTs, to
# make sure we dont't double create.
# + 4 on Django 1.6 for save points.
queries = 9
if django.VERSION < (1, 6):
queries -= 4
self.assertNumQueries(queries, pear.tags.add, "green", "delicious")
self.assertNumQueries(0, pear.tags.add)
def test_require_pk(self):
food_instance = self.food_model()
self.assertRaises(ValueError, lambda: food_instance.tags.all())
def test_delete_obj(self):
apple = self.food_model.objects.create(name="apple")
apple.tags.add("red")
self.assert_tags_equal(apple.tags.all(), ["red"])
strawberry = self.food_model.objects.create(name="strawberry")
strawberry.tags.add("red")
apple.delete()
self.assert_tags_equal(strawberry.tags.all(), ["red"])
def test_delete_bulk(self):
apple = self.food_model.objects.create(name="apple")
kitty = self.pet_model.objects.create(pk=apple.pk, name="kitty")
apple.tags.add("red", "delicious", "fruit")
kitty.tags.add("feline")
self.food_model.objects.all().delete()
self.assert_tags_equal(kitty.tags.all(), ["feline"])
def test_lookup_by_tag(self):
apple = self.food_model.objects.create(name="apple")
apple.tags.add("red", "green")
pear = self.food_model.objects.create(name="pear")
pear.tags.add("green")
self.assertEqual(
list(self.food_model.objects.filter(tags__name__in=["red"])),
[apple]
)
self.assertEqual(
list(self.food_model.objects.filter(tags__name__in=["green"])),
[apple, pear]
)
kitty = self.pet_model.objects.create(name="kitty")
kitty.tags.add("fuzzy", "red")
dog = self.pet_model.objects.create(name="dog")
dog.tags.add("woof", "red")
self.assertEqual(
list(self.food_model.objects.filter(tags__name__in=["red"]).distinct()),
[apple]
)
tag = self.tag_model.objects.get(name="woof")
self.assertEqual(list(self.pet_model.objects.filter(tags__in=[tag])), [dog])
cat = self.housepet_model.objects.create(name="cat", trained=True)
cat.tags.add("fuzzy")
pks = self.pet_model.objects.filter(tags__name__in=["fuzzy"])
model_name = self.pet_model.__name__
self.assertQuerysetEqual(pks,
['<{0}: kitty>'.format(model_name),
'<{0}: cat>'.format(model_name)],
ordered=False)
def test_lookup_bulk(self):
apple = self.food_model.objects.create(name="apple")
pear = self.food_model.objects.create(name="pear")
apple.tags.add('fruit', 'green')
pear.tags.add('fruit', 'yummie')
def lookup_qs():
# New fix: directly allow WHERE object_id IN (SELECT id FROM ..)
objects = self.food_model.objects.all()
lookup = self.taggeditem_model.bulk_lookup_kwargs(objects)
list(self.taggeditem_model.objects.filter(**lookup))
def lookup_list():
# Simulate old situation: iterate over a list.
objects = list(self.food_model.objects.all())
lookup = self.taggeditem_model.bulk_lookup_kwargs(objects)
list(self.taggeditem_model.objects.filter(**lookup))
self.assertNumQueries(1, lookup_qs)
self.assertNumQueries(2, lookup_list)
def test_exclude(self):
apple = self.food_model.objects.create(name="apple")
apple.tags.add("red", "green", "delicious")
pear = self.food_model.objects.create(name="pear")
pear.tags.add("green", "delicious")
self.food_model.objects.create(name="guava")
pks = self.food_model.objects.exclude(tags__name__in=["red"])
model_name = self.food_model.__name__
self.assertQuerysetEqual(pks,
['<{0}: pear>'.format(model_name),
'<{0}: guava>'.format(model_name)],
ordered=False)
def test_similarity_by_tag(self):
"""Test that pears are more similar to apples than watermelons"""
apple = self.food_model.objects.create(name="apple")
apple.tags.add("green", "juicy", "small", "sour")
pear = self.food_model.objects.create(name="pear")
pear.tags.add("green", "juicy", "small", "sweet")
watermelon = self.food_model.objects.create(name="watermelon")
watermelon.tags.add("green", "juicy", "large", "sweet")
similar_objs = apple.tags.similar_objects()
self.assertEqual(similar_objs, [pear, watermelon])
self.assertEqual([obj.similar_tags for obj in similar_objs],
[3, 2])
def test_tag_reuse(self):
apple = self.food_model.objects.create(name="apple")
apple.tags.add("juicy", "juicy")
self.assert_tags_equal(apple.tags.all(), ['juicy'])
def test_query_traverse(self):
spot = self.pet_model.objects.create(name='Spot')
spike = self.pet_model.objects.create(name='Spike')
spot.tags.add('scary')
spike.tags.add('fluffy')
lookup_kwargs = {
'%s__name' % _model_name(self.pet_model): 'Spot'
}
self.assert_tags_equal(
self.tag_model.objects.filter(**lookup_kwargs),
['scary']
)
def test_taggeditem_unicode(self):
apple = self.food_model.objects.create(name="apple")
apple.tags.add("juicy")
self.assertEqual(
force_text(self.taggeditem_model.objects.all()[0]),
"apple tagged with juicy"
)
def test_abstract_subclasses(self):
p = Photo.objects.create()
p.tags.add("outdoors", "pretty")
self.assert_tags_equal(
p.tags.all(),
["outdoors", "pretty"]
)
m = Movie.objects.create()
m.tags.add("hd")
self.assert_tags_equal(
m.tags.all(),
["hd"],
)
def test_field_api(self):
# Check if tag field, which simulates m2m, has django-like api.
field = self.food_model._meta.get_field('tags')
self.assertTrue(hasattr(field, 'rel'))
self.assertTrue(hasattr(field.rel, 'to'))
self.assertTrue(hasattr(field, 'related'))
# This API has changed in Django 1.8
# https://code.djangoproject.com/ticket/21414
if django.VERSION >= (1, 8):
self.assertEqual(self.food_model, field.model)
self.assertEqual(self.tag_model, field.related.model)
else:
self.assertEqual(self.food_model, field.related.model)
def test_names_method(self):
apple = self.food_model.objects.create(name="apple")
apple.tags.add('green')
apple.tags.add('red')
self.assertEqual(list(apple.tags.names()), ['green', 'red'])
def test_slugs_method(self):
apple = self.food_model.objects.create(name="apple")
apple.tags.add('green and juicy')
apple.tags.add('red')
self.assertEqual(list(apple.tags.slugs()), ['green-and-juicy', 'red'])
def test_serializes(self):
apple = self.food_model.objects.create(name="apple")
serializers.serialize("json", (apple,))
def test_prefetch_related(self):
apple = self.food_model.objects.create(name="apple")
apple.tags.add('1', '2')
orange = self.food_model.objects.create(name="orange")
orange.tags.add('2', '4')
with self.assertNumQueries(2):
l = list(self.food_model.objects.prefetch_related('tags').all())
with self.assertNumQueries(0):
foods = dict((f.name, set(t.name for t in f.tags.all())) for f in l)
self.assertEqual(foods, {
'orange': set(['2', '4']),
'apple': set(['1', '2'])
})
def test_internal_type_is_manytomany(self):
self.assertEqual(
TaggableManager().get_internal_type(), 'ManyToManyField'
)
class TaggableManagerDirectTestCase(TaggableManagerTestCase):
food_model = DirectFood
pet_model = DirectPet
housepet_model = DirectHousePet
taggeditem_model = TaggedFood
class TaggableManagerCustomPKTestCase(TaggableManagerTestCase):
food_model = CustomPKFood
pet_model = CustomPKPet
housepet_model = CustomPKHousePet
taggeditem_model = TaggedCustomPKFood
def test_require_pk(self):
# TODO with a charfield pk, pk is never None, so taggit has no way to
# tell if the instance is saved or not
pass
class TaggableManagerOfficialTestCase(TaggableManagerTestCase):
food_model = OfficialFood
pet_model = OfficialPet
housepet_model = OfficialHousePet
taggeditem_model = OfficialThroughModel
tag_model = OfficialTag
def test_extra_fields(self):
self.tag_model.objects.create(name="red")
self.tag_model.objects.create(name="delicious", official=True)
apple = self.food_model.objects.create(name="apple")
apple.tags.add("delicious", "red")
pear = self.food_model.objects.create(name="Pear")
pear.tags.add("delicious")
self.assertEqual(apple, self.food_model.objects.get(tags__official=False))
class TaggableManagerInitializationTestCase(TaggableManagerTestCase):
"""Make sure manager override defaults and sets correctly."""
food_model = Food
custom_manager_model = CustomManager
def test_default_manager(self):
self.assertEqual(self.food_model.tags.__class__, _TaggableManager)
def test_custom_manager(self):
self.assertEqual(self.custom_manager_model.tags.__class__, CustomManager.Foo)
class TaggableFormTestCase(BaseTaggingTestCase):
form_class = FoodForm
food_model = Food
def test_form(self):
self.assertEqual(list(self.form_class.base_fields), ['name', 'tags'])
f = self.form_class({'name': 'apple', 'tags': 'green, red, yummy'})
self.assert_form_renders(f, """<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>
<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="green, red, yummy" id="id_tags" /><br />%(help_start)sA comma-separated list of tags.%(help_stop)s</td></tr>""")
f.save()
apple = self.food_model.objects.get(name='apple')
self.assert_tags_equal(apple.tags.all(), ['green', 'red', 'yummy'])
f = self.form_class({'name': 'apple', 'tags': 'green, red, yummy, delicious'}, instance=apple)
f.save()
apple = self.food_model.objects.get(name='apple')
self.assert_tags_equal(apple.tags.all(), ['green', 'red', 'yummy', 'delicious'])
self.assertEqual(self.food_model.objects.count(), 1)
f = self.form_class({"name": "raspberry"})
self.assertFalse(f.is_valid())
f = self.form_class(instance=apple)
self.assert_form_renders(f, """<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>
<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="delicious, green, red, yummy" id="id_tags" /><br />%(help_start)sA comma-separated list of tags.%(help_stop)s</td></tr>""")
apple.tags.add('has,comma')
f = self.form_class(instance=apple)
self.assert_form_renders(f, """<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>
<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value=""has,comma", delicious, green, red, yummy" id="id_tags" /><br />%(help_start)sA comma-separated list of tags.%(help_stop)s</td></tr>""")
apple.tags.add('has space')
f = self.form_class(instance=apple)
self.assert_form_renders(f, """<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>
<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value=""has space", "has,comma", delicious, green, red, yummy" id="id_tags" /><br />%(help_start)sA comma-separated list of tags.%(help_stop)s</td></tr>""")
def test_formfield(self):
tm = TaggableManager(verbose_name='categories', help_text='Add some categories', blank=True)
ff = tm.formfield()
self.assertEqual(ff.label, 'Categories')
self.assertEqual(ff.help_text, 'Add some categories')
self.assertEqual(ff.required, False)
self.assertEqual(ff.clean(""), [])
tm = TaggableManager()
ff = tm.formfield()
self.assertRaises(ValidationError, ff.clean, "")
class TaggableFormDirectTestCase(TaggableFormTestCase):
form_class = DirectFoodForm
food_model = DirectFood
class TaggableFormCustomPKTestCase(TaggableFormTestCase):
form_class = CustomPKFoodForm
food_model = CustomPKFood
class TaggableFormOfficialTestCase(TaggableFormTestCase):
form_class = OfficialFoodForm
food_model = OfficialFood
class TagStringParseTestCase(UnitTestCase):
"""
Ported from Jonathan Buchanan's `django-tagging
<http://django-tagging.googlecode.com/>`_
"""
def test_with_simple_space_delimited_tags(self):
"""
Test with simple space-delimited tags.
"""
self.assertEqual(parse_tags('one'), ['one'])
self.assertEqual(parse_tags('one two'), ['one', 'two'])
self.assertEqual(parse_tags('one two three'), ['one', 'three', 'two'])
self.assertEqual(parse_tags('one one two two'), ['one', 'two'])
def test_with_comma_delimited_multiple_words(self):
"""
Test with comma-delimited multiple words.
An unquoted comma in the input will trigger this.
"""
self.assertEqual(parse_tags(',one'), ['one'])
self.assertEqual(parse_tags(',one two'), ['one two'])
self.assertEqual(parse_tags(',one two three'), ['one two three'])
self.assertEqual(parse_tags('a-one, a-two and a-three'),
['a-one', 'a-two and a-three'])
def test_with_double_quoted_multiple_words(self):
"""
Test with double-quoted multiple words.
A completed quote will trigger this. Unclosed quotes are ignored.
"""
self.assertEqual(parse_tags('"one'), ['one'])
self.assertEqual(parse_tags('"one two'), ['one', 'two'])
self.assertEqual(parse_tags('"one two three'), ['one', 'three', 'two'])
self.assertEqual(parse_tags('"one two"'), ['one two'])
self.assertEqual(parse_tags('a-one "a-two and a-three"'),
['a-one', 'a-two and a-three'])
def test_with_no_loose_commas(self):
"""
Test with no loose commas -- split on spaces.
"""
self.assertEqual(parse_tags('one two "thr,ee"'), ['one', 'thr,ee', 'two'])
def test_with_loose_commas(self):
"""
Loose commas - split on commas
"""
self.assertEqual(parse_tags('"one", two three'), ['one', 'two three'])
def test_tags_with_double_quotes_can_contain_commas(self):
"""
Double quotes can contain commas
"""
self.assertEqual(parse_tags('a-one "a-two, and a-three"'),
['a-one', 'a-two, and a-three'])
self.assertEqual(parse_tags('"two", one, one, two, "one"'),
['one', 'two'])
def test_with_naughty_input(self):
"""
Test with naughty input.
"""
# Bad users! Naughty users!
self.assertEqual(parse_tags(None), [])
self.assertEqual(parse_tags(''), [])
self.assertEqual(parse_tags('"'), [])
self.assertEqual(parse_tags('""'), [])
self.assertEqual(parse_tags('"' * 7), [])
self.assertEqual(parse_tags(',,,,,,'), [])
self.assertEqual(parse_tags('",",",",",",","'), [','])
self.assertEqual(parse_tags('a-one "a-two" and "a-three'),
['a-one', 'a-three', 'a-two', 'and'])
def test_recreation_of_tag_list_string_representations(self):
plain = Tag.objects.create(name='plain')
spaces = Tag.objects.create(name='spa ces')
comma = Tag.objects.create(name='com,ma')
self.assertEqual(edit_string_for_tags([plain]), 'plain')
self.assertEqual(edit_string_for_tags([plain, spaces]), '"spa ces", plain')
self.assertEqual(edit_string_for_tags([plain, spaces, comma]), '"com,ma", "spa ces", plain')
self.assertEqual(edit_string_for_tags([plain, comma]), '"com,ma", plain')
self.assertEqual(edit_string_for_tags([comma, spaces]), '"com,ma", "spa ces"')
@skipIf(django.VERSION < (1, 7), "not relevant for Django < 1.7")
class DeconstructTestCase(UnitTestCase):
def test_deconstruct_kwargs_kept(self):
instance = TaggableManager(through=OfficialThroughModel, to='dummy.To')
name, path, args, kwargs = instance.deconstruct()
new_instance = TaggableManager(*args, **kwargs)
self.assertEqual('tests.OfficialThroughModel', new_instance.rel.through)
self.assertEqual('dummy.To', new_instance.rel.to)
@skipUnless(django.VERSION < (1, 7), "test only applies to 1.6 and below")
class SouthSupportTests(TestCase):
def test_import_migrations_module(self):
try:
from taggit.migrations import __doc__ # noqa
except ImproperlyConfigured as e:
exception = e
self.assertIn("SOUTH_MIGRATION_MODULES", exception.args[0])
class InheritedPrefetchTests(TestCase):
def test_inherited_tags_with_prefetch(self):
child = Child()
child.save()
child.tags.add('tag 1', 'tag 2', 'tag 3', 'tag 4')
child = Child.objects.get()
no_prefetch_tags = child.tags.all()
self.assertEquals(4, no_prefetch_tags.count())
child = Child.objects.prefetch_related('tags').get()
prefetch_tags = child.tags.all()
self.assertEquals(4, prefetch_tags.count())
self.assertEquals(set([t.name for t in no_prefetch_tags]),
set([t.name for t in prefetch_tags]))
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
504,
2882,
492,
7640,
465,
12008,
1746,
199,
199,
646,
1639,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
1018,
492,
12506,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
12,
8505,
199,
504,
1639,
14,
396,
492,
7640,
12,
18244,
1746,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
199,
504,
1275,
3351,
492,
8388,
8884,
15563,
364,
2821,
12,
21128,
15563,
364,
2821,
12,
481,
23521,
2821,
12,
24545,
16714,
15563,
364,
2821,
199,
504,
1275,
992,
492,
334,
7221,
12,
12988,
12,
8388,
2988,
12,
8388,
8884,
15563,
364,
12,
2151,
8388,
8884,
40,
7130,
48,
386,
12,
8388,
8884,
48,
386,
12,
21128,
15563,
364,
12,
2151,
21128,
40,
7130,
48,
386,
12,
21128,
48,
386,
12,
481,
23521,
12,
869,
7130,
48,
386,
12,
31248,
12,
2151,
24545,
16714,
15563,
364,
12,
24545,
16714,
40,
7130,
48,
386,
12,
24545,
16714,
48,
386,
12,
2151,
24545,
16714,
1931,
12,
24545,
16714,
26732,
1685,
12,
31449,
12,
30808,
12,
2151,
32121,
7223,
8884,
15563,
364,
12,
32121,
7223,
8884,
48,
386,
12,
32121,
15563,
364,
12,
2151,
32121,
48,
386,
9,
199,
199,
504,
1947,
3187,
14,
16259,
492,
485,
1238,
63,
354,
12,
485,
1931,
16725,
2988,
12,
8053,
16725,
2988,
199,
504,
1947,
3187,
14,
992,
492,
8053,
12,
32121,
2081,
199,
199,
504,
1947,
3187,
14,
1208,
492,
5283,
63,
875,
63,
509,
63,
2969,
12,
2198,
63,
2969,
199,
199,
893,
26,
272,
687,
2882,
492,
3372,
3917,
12,
3372,
5524,
199,
2590,
3545,
26,
272,
687,
1639,
14,
1208,
14,
2796,
492,
3372,
3917,
12,
3372,
5524,
421,
199,
533,
3523,
1931,
1540,
774,
8,
785,
304,
272,
347,
702,
63,
2969,
63,
1452,
8,
277,
12,
6377,
12,
3762,
12,
4069,
29,
549,
12,
1921,
628,
354,
2349,
267,
4788,
275,
359,
5675,
8,
1113,
12,
1921,
9,
367,
1559,
315,
6377,
61,
267,
340,
4069,
26,
288,
4788,
14,
3191,
342,
288,
3762,
14,
3191,
342,
267,
291,
14,
629,
8,
7808,
12,
3762,
9,
339,
347,
485,
362,
63,
964,
63,
495,
8,
277,
12,
1824,
63,
495,
304,
267,
340,
1639,
14,
4612,
2356,
334,
17,
12,
650,
304,
288,
1824,
63,
495,
450,
29,
469,
355,
298,
3437,
63,
928,
582,
2650,
3751,
1021,
628,
3437,
505,
1743,
297,
355,
298,
3437,
63,
2379,
582,
15683,
3751,
4335,
288,
789,
267,
587,
26,
288,
1824,
63,
495,
450,
29,
469,
355,
298,
3437,
63,
928,
582,
4873,
355,
298,
3437,
63,
2379,
582,
3087,
288,
789,
267,
372,
1824,
63,
495,
339,
347,
702,
63,
964,
63,
3352,
83,
8,
277,
12,
1824,
12,
3517,
304,
267,
291,
14,
10190,
8,
495,
8,
964,
395,
291,
423,
362,
63,
964,
63,
495,
8,
1360,
430,
421,
199,
533,
3523,
1931,
1540,
1746,
8,
1746,
12,
3523,
1931,
1540,
774,
304,
272,
986,
421,
199,
533,
3523,
1931,
1540,
10161,
1746,
8,
10161,
1746,
12,
3523,
1931,
1540,
774,
304,
272,
986,
421,
199,
533,
8053,
1685,
1746,
8,
1563,
1931,
1540,
10161,
1746,
304,
272,
7090,
364,
63,
1238,
275,
481,
23521,
272,
1947,
63,
1238,
275,
8053,
339,
347,
511,
63,
3235,
63,
5464,
8,
277,
304,
267,
1145,
274,
275,
291,
14,
22120,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
12820,
531,
267,
1145,
274,
14,
2969,
14,
525,
480,
10858,
401,
298,
581,
531,
339,
347,
511,
63,
873,
8,
277,
304,
267,
4539,
275,
291,
14,
1450,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
6664,
531,
267,
4539,
14,
2117,
342,
339,
347,
511,
63,
525,
8,
277,
304,
267,
1145,
274,
275,
291,
14,
22120,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
12820,
531,
267,
612,
3323,
275,
291,
14,
1450,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
89,
3323,
531,
267,
1145,
274,
14,
2969,
14,
525,
8,
89,
3323,
9,
339,
347,
511,
63,
5464,
2021,
8,
277,
304,
267,
282,
275,
8281,
14,
1462,
14,
981,
8,
1213,
628,
1176,
13,
1450,
3187,
413,
14,
16,
17646,
68,
531,
267,
282,
14,
2969,
14,
525,
480,
10084,
22666,
401,
298,
3221,
401,
298,
15088,
654,
47,
3635,
531,
267,
291,
14,
479,
63,
2969,
63,
1452,
8,
65,
14,
2969,
14,
452,
1062,
359,
288,
298,
3710,
13,
10084,
22666,
401,
288,
298,
3710,
13,
3221,
401,
288,
298,
3710,
13,
10084,
22666,
13,
17,
2,
267,
2156,
1921,
628,
5464,
531,
339,
347,
511,
63,
23931,
8,
277,
304,
267,
408,
20897,
376,
3000,
465,
282,
1947,
1077,
746,
282,
1722,
15196,
10638,
10477,
267,
1145,
274,
275,
291,
14,
22120,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
12820,
531,
267,
543,
291,
14,
10835,
8,
3393,
12,
334,
355,
519,
2,
6612,
1050,
413,
25445,
28,
8,
466,
92,
533,
9,
283,
442,
7,
3072,
680,
298,
355,
519,
2,
6964,
665,
533,
283,
1176,
14,
697,
14,
992,
14,
1095,
14,
1685,
1563,
8423,
503,
620,
2685,
304,
288,
1145,
274,
14,
2969,
14,
525,
8,
17,
9,
199,
199,
533,
8053,
1685,
16281,
1746,
8,
1931,
1685,
1746,
304,
272,
7090,
364,
63,
1238,
275,
21128,
15563,
364,
272,
1947,
63,
1238,
275,
8053,
199,
199,
533,
8053,
1685,
7223,
8884,
1746,
8,
1931,
1685,
1746,
304,
272,
7090,
364,
63,
1238,
275,
8388,
8884,
15563,
364,
272,
1947,
63,
1238,
275,
8053,
199,
199,
533,
8053,
1685,
3466,
16714,
1746,
8,
1931,
1685,
1746,
304,
272,
7090,
364,
63,
1238,
275,
24545,
16714,
15563,
364,
272,
1947,
63,
1238,
275,
24545,
16714,
1931,
199,
199,
533,
8053,
16725,
2988,
1746,
8,
1563,
1931,
1540,
1746,
304,
272,
7090,
364,
63,
1238,
275,
481,
23521,
272,
299,
386,
63,
1238,
275,
31449,
272,
25284,
8096,
63,
1238,
275,
869,
7130,
48,
386,
272,
1947,
303,
328,
563,
63,
1238,
275,
32121,
2081,
272,
1947,
63,
1238,
275,
8053,
339,
347,
511,
63,
525,
63,
1450,
8,
277,
304,
267,
1145,
274,
275
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
504,
2882,
492,
7640,
465,
12008,
1746,
199,
199,
646,
1639,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
1018,
492,
12506,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
12,
8505,
199,
504,
1639,
14,
396,
492,
7640,
12,
18244,
1746,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
199,
504,
1275,
3351,
492,
8388,
8884,
15563,
364,
2821,
12,
21128,
15563,
364,
2821,
12,
481,
23521,
2821,
12,
24545,
16714,
15563,
364,
2821,
199,
504,
1275,
992,
492,
334,
7221,
12,
12988,
12,
8388,
2988,
12,
8388,
8884,
15563,
364,
12,
2151,
8388,
8884,
40,
7130,
48,
386,
12,
8388,
8884,
48,
386,
12,
21128,
15563,
364,
12,
2151,
21128,
40,
7130,
48,
386,
12,
21128,
48,
386,
12,
481,
23521,
12,
869,
7130,
48,
386,
12,
31248,
12,
2151,
24545,
16714,
15563,
364,
12,
24545,
16714,
40,
7130,
48,
386,
12,
24545,
16714,
48,
386,
12,
2151,
24545,
16714,
1931,
12,
24545,
16714,
26732,
1685,
12,
31449,
12,
30808,
12,
2151,
32121,
7223,
8884,
15563,
364,
12,
32121,
7223,
8884,
48,
386,
12,
32121,
15563,
364,
12,
2151,
32121,
48,
386,
9,
199,
199,
504,
1947,
3187,
14,
16259,
492,
485,
1238,
63,
354,
12,
485,
1931,
16725,
2988,
12,
8053,
16725,
2988,
199,
504,
1947,
3187,
14,
992,
492,
8053,
12,
32121,
2081,
199,
199,
504,
1947,
3187,
14,
1208,
492,
5283,
63,
875,
63,
509,
63,
2969,
12,
2198,
63,
2969,
199,
199,
893,
26,
272,
687,
2882,
492,
3372,
3917,
12,
3372,
5524,
199,
2590,
3545,
26,
272,
687,
1639,
14,
1208,
14,
2796,
492,
3372,
3917,
12,
3372,
5524,
421,
199,
533,
3523,
1931,
1540,
774,
8,
785,
304,
272,
347,
702,
63,
2969,
63,
1452,
8,
277,
12,
6377,
12,
3762,
12,
4069,
29,
549,
12,
1921,
628,
354,
2349,
267,
4788,
275,
359,
5675,
8,
1113,
12,
1921,
9,
367,
1559,
315,
6377,
61,
267,
340,
4069,
26,
288,
4788,
14,
3191,
342,
288,
3762,
14,
3191,
342,
267,
291,
14,
629,
8,
7808,
12,
3762,
9,
339,
347,
485,
362,
63,
964,
63,
495,
8,
277,
12,
1824,
63,
495,
304,
267,
340,
1639,
14,
4612,
2356,
334,
17,
12,
650,
304,
288,
1824,
63,
495,
450,
29,
469,
355,
298,
3437,
63,
928,
582,
2650,
3751,
1021,
628,
3437,
505,
1743,
297,
355,
298,
3437,
63,
2379,
582,
15683,
3751,
4335,
288,
789,
267,
587,
26,
288,
1824,
63,
495,
450,
29,
469,
355,
298,
3437,
63,
928,
582,
4873,
355,
298,
3437,
63,
2379,
582,
3087,
288,
789,
267,
372,
1824,
63,
495,
339,
347,
702,
63,
964,
63,
3352,
83,
8,
277,
12,
1824,
12,
3517,
304,
267,
291,
14,
10190,
8,
495,
8,
964,
395,
291,
423,
362,
63,
964,
63,
495,
8,
1360,
430,
421,
199,
533,
3523,
1931,
1540,
1746,
8,
1746,
12,
3523,
1931,
1540,
774,
304,
272,
986,
421,
199,
533,
3523,
1931,
1540,
10161,
1746,
8,
10161,
1746,
12,
3523,
1931,
1540,
774,
304,
272,
986,
421,
199,
533,
8053,
1685,
1746,
8,
1563,
1931,
1540,
10161,
1746,
304,
272,
7090,
364,
63,
1238,
275,
481,
23521,
272,
1947,
63,
1238,
275,
8053,
339,
347,
511,
63,
3235,
63,
5464,
8,
277,
304,
267,
1145,
274,
275,
291,
14,
22120,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
12820,
531,
267,
1145,
274,
14,
2969,
14,
525,
480,
10858,
401,
298,
581,
531,
339,
347,
511,
63,
873,
8,
277,
304,
267,
4539,
275,
291,
14,
1450,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
6664,
531,
267,
4539,
14,
2117,
342,
339,
347,
511,
63,
525,
8,
277,
304,
267,
1145,
274,
275,
291,
14,
22120,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
12820,
531,
267,
612,
3323,
275,
291,
14,
1450,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
89,
3323,
531,
267,
1145,
274,
14,
2969,
14,
525,
8,
89,
3323,
9,
339,
347,
511,
63,
5464,
2021,
8,
277,
304,
267,
282,
275,
8281,
14,
1462,
14,
981,
8,
1213,
628,
1176,
13,
1450,
3187,
413,
14,
16,
17646,
68,
531,
267,
282,
14,
2969,
14,
525,
480,
10084,
22666,
401,
298,
3221,
401,
298,
15088,
654,
47,
3635,
531,
267,
291,
14,
479,
63,
2969,
63,
1452,
8,
65,
14,
2969,
14,
452,
1062,
359,
288,
298,
3710,
13,
10084,
22666,
401,
288,
298,
3710,
13,
3221,
401,
288,
298,
3710,
13,
10084,
22666,
13,
17,
2,
267,
2156,
1921,
628,
5464,
531,
339,
347,
511,
63,
23931,
8,
277,
304,
267,
408,
20897,
376,
3000,
465,
282,
1947,
1077,
746,
282,
1722,
15196,
10638,
10477,
267,
1145,
274,
275,
291,
14,
22120,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
12820,
531,
267,
543,
291,
14,
10835,
8,
3393,
12,
334,
355,
519,
2,
6612,
1050,
413,
25445,
28,
8,
466,
92,
533,
9,
283,
442,
7,
3072,
680,
298,
355,
519,
2,
6964,
665,
533,
283,
1176,
14,
697,
14,
992,
14,
1095,
14,
1685,
1563,
8423,
503,
620,
2685,
304,
288,
1145,
274,
14,
2969,
14,
525,
8,
17,
9,
199,
199,
533,
8053,
1685,
16281,
1746,
8,
1931,
1685,
1746,
304,
272,
7090,
364,
63,
1238,
275,
21128,
15563,
364,
272,
1947,
63,
1238,
275,
8053,
199,
199,
533,
8053,
1685,
7223,
8884,
1746,
8,
1931,
1685,
1746,
304,
272,
7090,
364,
63,
1238,
275,
8388,
8884,
15563,
364,
272,
1947,
63,
1238,
275,
8053,
199,
199,
533,
8053,
1685,
3466,
16714,
1746,
8,
1931,
1685,
1746,
304,
272,
7090,
364,
63,
1238,
275,
24545,
16714,
15563,
364,
272,
1947,
63,
1238,
275,
24545,
16714,
1931,
199,
199,
533,
8053,
16725,
2988,
1746,
8,
1563,
1931,
1540,
1746,
304,
272,
7090,
364,
63,
1238,
275,
481,
23521,
272,
299,
386,
63,
1238,
275,
31449,
272,
25284,
8096,
63,
1238,
275,
869,
7130,
48,
386,
272,
1947,
303,
328,
563,
63,
1238,
275,
32121,
2081,
272,
1947,
63,
1238,
275,
8053,
339,
347,
511,
63,
525,
63,
1450,
8,
277,
304,
267,
1145,
274,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
pbarton666/buzz_bot
|
djangoproj/djangoapp/crawler/django_dbRoutines.py
|
1
|
35782
|
'''
This module contains database routines that may be accessed with or without using a web framework.
'''
###TODO: need to put the project and the app on the python path so these imports work (a copy of settings.py is in the current directory for now)
#I think all we realy need to do is make sure the settings module and the environment variables are correct.
#slam in the djang settings (this takes place of running manage.py
from django.core.management import execute_manager
import settings
import os
import sys
from MySQLdb.connections import IntegrityError
'''This block of code is for running the module in a 'stand-alone' mode for testing
The import statement is very important because django is looking for a "fully specified"
representation of the module 'models' i.e. at least a first- and second-order path.
Here, the object is <module 'djangoproj.djangoapp.models' from some_file_system> If we simply say
"import models", the object is <module 'models'> which django is unable to process.
'''
rootdir = '/home/pat1/workspace/'
if rootdir not in sys.path:
sys.path.append(rootdir)
from djangoproj.djangoapp import models
#standard modules
##from sqlobject import mysql, SQLObject, StringCol, dberrors #change the import to use dbs other than MySQL
from datetime import datetime
import logging
import unittest
import random
import test
#custom modules
import projectSpecs as projectSpecs
#log settings
LOG_NAME = "master.log"
LOG_LEVEL = logging.DEBUG
#return codes
RETURN_SUCCESS = projectSpecs.RETURN_SUCCESS
RETURN_FAIL = projectSpecs.RETURN_FAIL
#database parameters and connection object using specs from an external file; the connection object is global to this modul
###Database Objects###
#import models
#remove the sqlObject flavor; we'll import djangos
###Error Class(es)
class DbError(Exception):
def __init__(self, value):
self.parameter = value
def __str__(self):
return repr(self.parameter)
###Management Classes
class DatabaseMethods():
'''This class adds urls from a list. If doOrder is true, we'll add an "order" parameter to the table to indicate
the search engine's sequence of sites for this search (which we may use as an indicator of authority).
'''
def __init__(self):
pass
def deleteSearchContent(self, searchid):
#deletes all the content bits for all the criteria associated with a search
searchid = int(searchid)
try:
criteriaObjects = self.getParseCriteriaForSearch(searchid)['criteria']
except:
raise DbError("couldn't find filter criteria for search %i" %searchid)
for c in criteriaObjects:
try:
self.deleteContentForCriteria(c.id)
except:
raise DbError("couldn't delete content for search %i, criteria %i" %(searchid, c.id))
return
def deleteSearchContentAndSites(self, searchid):
#deletes the content and urls for a search
searchid=int(searchid)
self.deleteSearchContent(searchid)
self.deleteUrlsForSearch(searchid)
return 1
def cleanUpData(self, searchid):
#placeholder for ad hoc data cleaning routine for use w/ existing database
return 1
def deleteContentForCriteria(self, criteriaid):
criteriaid=int(criteriaid)
try:
deleteList = models.Content.objects.filter(criteriaid=criteriaid)
deleteList.delete()
return 1
except:
raise
def gatherSearchSpecs(self, searchid= None):
#pulls search specifications from db
if searchid:
try: return models.Search.objects.filter(id=searchid)
except: raise DbError("Search requested: %s can't be found"%str(searchid))
def gatherSearchIds(self, urlid = None):
try: return models.UrlSearch.objects.filter(urlid = urlid)
except: raise DbError("Lookup in urlSearch Failed for %i"%urlid)
def addSingleUrl(self, url, deleteme = False, searchid = None, source = 'unknown', depth = 0, order = None, urlIx = 0):
#adds a URL, updating tables Urls and Url_Search; returns the url id or an error
urlobj = None
try:
urlobj = models.Url(url = url, add_date = datetime.now(), delete_me = deleteme)
urlobj.save()
except IntegrityError:
logging.info("Failed to add duplicate url %s"%url)
except Exception, e:
logging.info("addUrls encountered exception: %s while adding url %s"%(e, url))
raise DbError("error inserting url %s"%url)
#If we have added the url succesfully (or it's a duplicate) also update the url_search table (note, 'order' is optional - intended to handle
# record the search engines' idea of the relevance/authority)
if urlobj:
try:
searchObj = models.Search(searchid)
urlSearchObj = models.UrlSearch(urlid = urlobj, source = source, depth = depth, searchid = searchObj, urlorder = order)
urlSearchObj.save()
return urlobj.id
except Exception, e:
logging.info("addUrls encountered exception: %s while adding url %s to the urlSearch table"%(e, url))
raise DbError("error inserting url %s: %s" %(url,e))
def goodUrl(self, url):
#Screens out obviously bad urls by name using a list stored in the BadUrlFragment table. Also insures that they at least look
# legit http*. The table contains strings like .pdf, .doc, .xls to weed out documents, along with names of sites we know we don't want.
badFrags = models.BadUrlFragment.objects.all()
badCount = badFrags.count()
if badCount == 0: #if we don't have any know bad url bits in our db, evaluate the url to be good
return True
if url[:4].lower() <> 'http':
return False
good = True; ix = 0; done = False
while not done:
frag = badFrags[ix].badstring
if url.find(frag) > 0:
return False
ix +=1
if ix >= badCount: done = True
return True
def addUrlsFromList(self, urls, deleteme = False, searchid = None, source = None, depth = 0, order = None):
#add urls from a vetted list to the database
if not isinstance(urls, list): #makes sure a single entry is treated as a short list
urls = [urls]
urlIx = 0
for url in urls:
urlIx=+1
url=url.strip()
if self.goodUrl(url): #screen out urls based on name
try:
ret = self.addSingleUrl(url = url, deleteme = deleteme, searchid = int(searchid), source = source, depth = int(depth), order =urlIx)
except Exception, e:
logging.info("addUrls encountered exception: %s while adding url %s to the urlSearch table"%(e, url))
pass
return RETURN_SUCCESS
def deleteFlaggedUrls(self):
#cleans up the database by deleting the rows with the deleteme flag set (affects both url and url_search)
try:
deleteList = models.Url.objects.filter(delete_me=True)
deleteList.delete()
return RETURN_SUCCESS
except Exception, e:
logging.info("Failed to delete flagged urls. %s"%e)
raise
def deleteFlaggedSearches(self):
#cleans up the database by deleting the rows with the deleteme flag set
try:
deleteList = models.Search.objects.filter(deleteme =True)
deleteList.delete()
return RETURN_SUCCESS
except Exception, e:
logging.info("Failed to delete flagged searches. %s"%e)
raise
def deleteUrlsForSearch(self, searchid):
deletelist = models.UrlSearch.objects.filter(searchid = searchid)
deletelist.delete()
pass
def addCatchFromUrlVisit(self, urlid, searchid, catchDict, urlAddDepth = 2, deleteme = False, criteriaid=None):
'''Parse out the dict from a visit {content, metaData, links} and add to db. We'll try to add dates
to successfully-addded content).
'''
#update both content and contentSearch table
contentSoup = catchDict['contentAsSoupObjects']
contentUnicode = catchDict['polishedCont']
for s, u in zip(contentSoup,contentUnicode ):
try:
shortcont = u[:50]
#try first to add the content; only if we do so will we try to parse out the date
contObj = Content(content = u, shortcont = shortcont, dateacquired = datetime.now(), criteriaid = criteriaid, urlid=urlid)
csObj = ContentSearch(contentid = contObj.id, searchid = searchid, urlid = urlid)
#parse the date
date = None
#logging.info( "trying to find a date in %s"%s)
#date = findObj.findDate_main(s)
if date:
contObj.dateposted = date
logging.info("found date: %s for content %s" %(str(date), shortcont))
else:
logging.info( "no date for content %s"%str(shortcont))
except dberrors.DuplicateEntryError:
#if we already have this content bit
pass
except Exception, e:
msg = "couldn't add content %s for searchid %s and urlid %s"%(u,str(searchid), str(urlid))
logging.info("%s: %s" %(msg, e))
raise
#delete existing metatags for this url then update with today's info
try:
deleteList = models.UrlTags.objects.filter(urlid = urlid)
deleteList.delete()
metaData = catchDict['metaData']
for m in metaData:
name, value = m
urlTagObj = models.UrlTags(urlid =urlid, name = name[:20], value = value[:20])
urlTagObj.save()
except:
msg = "couldn't add tags %s for searchid %s and urlid %s"%(value,str(searchid), str(urlid))
logging.info(msg)
raise
#Add any newly-harvested links to the url table. Their depth will be one more than the initiating url's. The urlAddDepth parameter allows us
# to control the amount of recursion. A url added via google or an upload has a depth=0, urls captured from the initial ones have a depth=1, urls captured
# by following these links have a depth=3, and so on.
urlSearchObj = models.UrlSearch.objects.filter(urlid = urlid, searchid = searchid)
depth = urlSearchObj[0].depth + 1
if depth <= urlAddDepth:
links = catchDict['links']
try:
for link in links:
self.addSingleUrl(url = link, deleteme = deleteme, searchid = searchid, source = str(urlid), depth = depth)
except dberrors.DuplicateEntryError:
pass
except:
logging.info("couldn't add new url %s"%link)
raise
return RETURN_SUCCESS
#"Getters" to return results of queries; all return iterable objects
def getUrl(self, urlid):
#returns a url db object
try: models.URL.objects.filter(id = u.id).all()
except: raise DbError("Url %s doesn't exist in url table"%str(urlid))
def getAllUrls(self):
try: return models.Url.objects.all()
except: raise DbError("getAllUrls failed")
def getAllSearches(self):
try: return models.Search.objects.all()
except: raise DbError("getAllSearches failed")
def getSearchesByUser(self, userid):
try: return models.Search.objects.filter(userid=userid)
except: raise DbError("getAllSearches failed")
def getSearchesPublicOnlyNotUsers(self, userid):
#gets searches that are public but not the user's
try: return models.Search.objects.filter(ispublic=True).exclude(userid=userid)
except: raise DbError("getAllSearches failed")
def getSearchesPublicOnly(self):
#gets searches that are public but not the user's
try: return models.Search.objects.filter(ispublic=True)
except: raise DbError("getAllSearches failed")
def getContentForSearch(self, searchid, limit = None):
ret = []
contSearch = models.ContentSearch.objects.filter(searchid = searchid)[:limit] # a QureySet object
for cont in contSearch:
contlist = models.Content.objects.filter(id = cont.id).all()
for c in contlist:
ret.append(c)
return ret
def getViewCriteriaById(self, criteriaid):
#returns a SearchViewcriteria object
try:
criteriaObj = models.SearchViewcriteria.objects.get(id=int(criteriaid))
return criteriaObj
except:
raise DbError("%s%i" %("couldn't fetch view criteria object ", int(criteriaid)))
def updateViewCriteria(self, updatedict):
'''updates ViewCriteria from a dict returned from views.editCriteria'''
#parse out the dict
searchid = updatedict['searchid']
criteriaid = updatedict['criteriaid']
include = updatedict['include']
exclude = updatedict['exclude']
andor = updatedict['andor']
ispublic = updatedict['ispublic']
title = updatedict['title']
#add new info to the viewCriteria object
vcObject = self.getViewCriteriaById(criteriaid)
vcObject.include = include
vcObject.exclude = exclude
vcObject.andor = andor
vcObject.ispublic = ispublic
vcObject.title = title
#update the database
vcObject.save()
def getViewCriteria(self, onlyPublic=False, limit=None):
#grabs the secondary search criteria for display in web page.
if not onlyPublic:
return models.SearchViewcriteria.objects.all()[:limit]
else:
return models.SearchViewcriteria.objects.filter(isPublic = True)[:limit]
def countContentForCriteria (self, criteriaid):
criteriaid=int(criteriaid)
try:
contentcount = self.getContentForCriteria(criteriaid = criteriaid).count()
except:
raise
return contentcount
def getContentForCriteria(self, criteriaid, limit = None):
criteriaid=int(criteriaid)
ret = []
contlist = models.Content.objects.filter(criteriaid = criteriaid).order_by('-dateposted')[:limit] # a QureySet object
return contlist
def getContentForSearch(self, searchid, limit = None):
ret = []
#'latest' refers to the Content model's meta class variable 'get_latest_by'
contlist = models.ContentSearch.objects.filter(searchid = searchid)[:limit] # a QureySet object
return contlist
def cleanUpOrphanedContent(self):
#cleans up content that belongs to no search
for c in models.Content.object.all():
if models.ContentSearch.objects.filter(contentid = c.id).count() == 0:
models.Content.delete(c.id)
def getUrlsForSearchWithGoodHtml(self, searchid):
ret = []
allUrls = self.getUrlsForSearch(searchid)
for url in allUrls:
htmlSelect = models.UrlHtml.objects.filter(urlid = url.id)
for h in htmlSelect:
if len(h.html) > 10:
ret.append(h)
return ret
def getHtmlForUrl(self, urlid):
#find all content for a search
try: return models.UrlHtml.objects.filter(urlid = urlid)
except: raise DbError("getHtmlForUrl failed")
def getSearchesforUrl(self, urlid):
#find all searches associated with a url
try: return models.UrlSearch.objects.filter(urlid = urlid)
except: raise DbError("UrlSearch failed")
def getScoreMethod(self, id = None):
#find all searches associated with a url; if none provided, returns first method
try:
if not id:
allmethods = models.ScoreMethods.objects.all()
ret = allmethods[0]
else:
ret = models.ScoreMethods.objects.filter(id = id)
return ret
except: raise DbError("UrlSearch failed")
def getScore(self, contentid, methodid):
#find all searches associated with a url; if none provided, returns first method
try:
scoreObj = models.Scores.objects.filterBy(methodid = methodid, contentid = contentid)
score = scoreObj.score
except:
score = "n/a"
return score
def getUrlCountForSearch(self, searchid):
#returns number of urls for this search
try:
return self.getUrlsForSearch(searchid= searchid).count()
except:
raise DbError("UrlCountForSearchFailed")
def getContentCountForSearch(self, searchid):
#returns number of content bits we have for this search
try:
return models.ContentSearch.objects.filter(searchid=searchid).count()
except:
raise DbError("UrlCountForSearchFailed")
def getUrlsForSearch(self, searchid, limit=None):
#find urlSearch objects
try: return models.UrlSearch.objects.filter(searchid = searchid)[:limit]
except: raise DbError("UrlSearch failed")
def getUrlsObjectsForSearch(self, searchid, limit=None):
#find all urlObjects for a search
urlSearchObjects = self.getUrlsForSearch(searchid, limit)
retList = []
for u in urlSearchObjects:
retList.append(u.urlid) #returns URL objects (i.e., the whole db object)
try: return retList
except: raise DbError("getUrlsObjectsForSearch failed")
def getParseCriteriaForSearch(self, searchid):
''''Find the search criterion associated with a search;
return a dict of searchid, object (since content is stored by search we need to keep these together)
#Note: This doesn't really belong here but until we have a wrapper around addition of new searches to force addition of
a serch criteria table entry, we'll add one here. The criteria's exclude/enclude entries will echo the ones used on the
search engine. They can easily be overridden.
'''
criteria = models.SearchViewcriteria.objects.filter(searchid = searchid)
if criteria.count() == 0:
try:
s = models.Search.objects.filter(id = searchid)
#models.SearchViewcriteria.objects.filter(searchid= searchid, exclude = s.exclude, include = s.include)
criteria = models.SearchViewcriteria.objects.filter(searchid = searchid)
except Exception, e:
msg = "getParseCriteriaForSearch couldn't add a SearchViewcriteria object for search %i" %searchid
logging.debug(msg + ' ' + e)
raise DbError("getParseCriteriaForSearch couldn't add a SearchViewcriteria object for search %i" %searchid)
try: return {'searchid': searchid, 'criteria': models.SearchViewcriteria.objects.filter(searchid = searchid)}
except: raise DbError("SearchesCriteria failed")
def getParseCriteriaForUrl(self, urlid):
#find the search criterion associated with a url (there may be many searches associated w/ a url)
# return a list of dict of searchid, object (content is stored by search)
criteria = []
try:
UrlSearchObjs = self.getSearchesforUrl(urlid)
for s in UrlSearchObjs:
criteria.append(self.getParseCriteriaForSearch(s.searchid))
return criteria
except: raise DbError("SearchesCriteria failed")
def getHtmlForSearch(self, searchid):
#find all html for a search
ret = []
try:
urlObjs = self.getUrlsForSearch(searchid)
for u in urlObjs:
#if we've added html for this url, we'll get one item returned; otherwise the return will not have elem[0]
try:
ret.append(models.UrlHtml.objects.filter(urlid=u.id)[0])
except:
pass
except:
raise DbError("Can't find html object")
return ret
def deleteRawHtmlNoParse(self):
urlhtml = self.getUrlHtmlObj()
allrows = urlhtml.select()
for row in allrows:
row.html = ''
def addUrlIdToContent(self, criteriaid, limit=None):
'''one-off fix to add the urlid to the Content table; this due to long
delays in grabbing the url through a chain of lookups
'''
mycont = self.getContentForCriteria(criteriaid)[:limit]
for c in mycont:
try:
url = models.ContentSearch.objects.get(contentid=c.id).urlid.url
cont = models.Content.objects.get(id=c.id)
cont.urlid = models.ContentSearch.objects.get(contentid=c.id).urlid
except:
pass
def getContentAndUrlForCriteria(self, criteriaid, limit=None, first=None, methodid = None):
'''
Finds content bits in db using keywords in the Criteria table. Returns a list of dict
items carrying the content, url. To facilitate the "next" and "back" buttons, the dict
also contains the index of the first record (i.e., the list index, not the id field) and the
number of matching content records found.
'''
allRecords = self.getContentForCriteria(criteriaid)
first = first or 0 #ensures we have an integer to work with
mycont = allRecords[first:first+limit]
totalRecords = allRecords.count()
#if we haven't set a scoring method, we'll use the first one in the database
##TODO allow users to pick scoring method reported
if not methodid:
methodObj = self.getScoreMethod()
methodid = methodObj.id
ret =[]
for c in mycont:
try:
#url = models.ContentSearch.objects.get(contentid=c.id).urlid.url
url = c.urlid.url
score = self.getScore(c.id, methodid)
ret.append({"cont":c, "url": url, "first": first, "totalRecords": totalRecords, "score" : score})
except:
pass
return ret
### This might be overkill, but these simply return database objects to other modules
def getUrlHtmlObj(self):
try: return models.UrlHtml
except: raise DbError("Can't find UrlHtml object")
def getSearchObj(self):
try: return models.Search
except: raise DbError("Can't find Search object")
def getContentObj(self):
try: return models.Content
except: raise DbError("Can't find getContentObj object")
def getUrlSearchObj(self):
try: return models.UrlSearch
except: raise DbError("Can't find UrlSearch object")
def getSearchViewCriteriaObj(self):
try: return models.SearchViewcriteria
except: raise DbError("Can't find SearchViewCriteria object")
def getUrlSearchObj(self):
try: return models.UrlSearch
except: raise DbError("Can't find UrlSearch object")
def addViewCriteria(self, searchid):
#adds new viewCriteria to a search; returns criteria id
include = ''; andor = 'and'
search = self.getSearch(searchid)
try:
vc = models.SearchViewcriteria(searchid = search, include=include, andor = andor)
vc.save()
except:
raise DbError("Can's add new criteria")
return vc.id
def addSearch(self, userid, name):
#adds a search and returns the id
try:
srch = models.Search(userid = userid, name = name)
srch.save()
except Exception, e:
logging.info("addUrls encountered exception: %s while adding url %s"%(e, url))
raise DbError("error creating new search")
return srch.id
def getSearch(self, searchid):
try:
return models.Search.objects.get(id = int(searchid))
except:
logging.info("couldn't return search %i" %searchid)
raise DbError("error retrieving search %i" %searchid)
def deleteSearch(self, searchid):
searchid = int(searchid)
try:
srch = self.getSearch(searchid)
srch.delete()
except:
logging.info("couldn't return search %i" %searchid)
raise DbError("error retrieving search %i" %searchid)
return 1
def deleteCriteriaAndItsContent(self, criteriaid):
criteraid = int(criteriaid)
try:
criteriaObj = models.SearchViewcriteria.objects.get(id=criteriaid)
criteriaObj.delete()
except:
raise DbError("couldn't delete searchViewcriteria db object")
pass
def updateSearch(self, qdict):
'''updates a search based on user input, using the dict returned from editsearch'''
#get a search object
srch = self.getSearch(int(qdict['searchid']))
#inject text from the form
if 'include' in qdict: srch.include = qdict['include'].strip()
if 'exclude' in qdict: srch.exclude = qdict['exclude'].strip()
if 'name' in qdict: srch.name = qdict['name']
#when there are checkboxes on a form, they appear in the qdict object only if checked
if 'andor' in qdict:
srch.andor = 'and'
else:
srch.andor = 'or'
if 'ispublic' in qdict:
srch.ispublic = 1
else:
srch.ispublic = 0
#these aren't used by the editsearch form, buy may eventually be used by other UI forms
if 'clearall' in qdict: srch.clearall = self.to_boolean(qdict['clearall'], 1, 0)
if 'clearnonconform' in qdict: srch.clearnonconform = self.to_boolean(qdict['clearnonconform'], 1, 0)
if 'deleteme' in qdict: srch.deleteme = self.to_boolean(qdict['deleteme'], 1, 0)
try:
srch.save()
except:
logging.warn("search edits not saved for search %i" %srch.id)
return
def to_boolean(self, inp, onval, offval):
#changes a check box value 'on'/'off' to boolean equivalent
if inp == 'on':
return onval
else:
return offval
def _set_logger(self):
#Our friend the logger. Sets up the logging parameters. The log will appear at ./logs/master.log (or whatever is in the settings
# at the top of this module).
LOGDIR = os.path.join(os.path.dirname(__file__), 'logs').replace('\\','/')
log_filename = LOGDIR + '/' + LOG_NAME
logging.basicConfig(level=LOG_LEVEL,
format='%(module)s %(funcName)s %(lineno)d %(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
filename=log_filename,
filemode='w')
def getSearchNumFromName(self, name):
#simply return a search's number if its name is known
allSearches = self.getAllSearches()
found = False
for s in allSearches:
if name.lower() == s.name.lower():
return s.id
#if we're here, we've not found a search by that name
return 0
class testDbRoutines(unittest.TestCase):
def __init__(self):
#some randomized urls (keeps unique constraint from interfering)
self._urls = ["xyz.html"+ str(random.random()), "http://www.dogma.com"+ str(random.random()),
"http://www.dogma.com/test/"+ str(random.random()), "http://www.dogma.com/test?id=123"+ str(random.random())]
self._urls1 = ["xyz.html"+ str(random.random()), "http://www.dogma.com"+ str(random.random()),
"http://www.dogma.com/test/"+ str(random.random()), "http://www.dogma.com/test?id=123"+ str(random.random())]
def testAddUrlsFromList(self):
#add a bunch of urls from a list
clsObj = DatabaseMethods()
ret = clsObj.addUrlsFromList(self._urls, deleteme = True, searchid = 0, source = 'test')
assert ret is RETURN_SUCCESS
def testDeleteUrls(self):
#delete rows with deleteme flag set
clsObj = DatabaseMethods()
ret = clsObj.deleteFlaggedUrls()
assert ret is RETURN_SUCCESS
def testAddCatchFromUrlVisit(self):
#
clsObj = DatabaseMethods()
searchObj = clsObj.getSearchObj()
urlSearchObj = clsObj.getUrlSearchObj()
#add placeholder search, url and urlSearch database entries
fakeSearch = searchObj(include = "michigan, football", exclude = "osu", deleteme = True)
fakeUrlId = clsObj.addSingleUrl(url = "http://fake"+str(random.random()), deleteme = True, searchid = fakeSearch.id, source = 'test')
urlSearchObj(urlid = fakeUrlId, searchid = fakeSearch.id)
#see if we can add a fake return from a url to the content table
fakeCont = ['and a one'+str(random.random()), 'and a two'+str(random.random()), 'and a three'+str(random.random())]
fakeDates= [datetime.now(), datetime.now(), datetime.now()]
fakeLinks= ['http://www.dogma.com'+str(random.random()), 'http://www.karma.com'+str(random.random()), 'http://www.fang.com'+str(random.random())]
fakeMeta = [(u'http-equiv', u'Content-Type'), (u'content', u'text/html; charset=%SOUP-ENCODING%')]
fakeDict = {'polishedCont': fakeCont, 'dates':fakeDates, 'links': fakeLinks, 'metaData':fakeMeta,'contentAsSoupObjects': fakeCont}
ret = clsObj.addCatchFromUrlVisit(urlid = fakeUrlId, searchid = fakeSearch.id, deleteme=True, catchDict = fakeDict)
clsObj.deleteFlaggedSearches()
assert ret == RETURN_SUCCESS
def installSomeFakeRecords(self):
srch = models.Search(include = 'xx', exclude = 'yy, yy, yy', clearall = False, clearnonconform = True, viewcriteriaid = 1, andor = 'or', deleteme = True)
srch.save()
srchview = models.SearchViewcriteria(searchid = srch, include = 'xx', exclude = 'yy', andor = 'and')
srchview.save()
url = models.Url(url = 'http://www.python.org/?'+str(random.random()), add_date = datetime.now(), url_order = 1, delete_me = True, visit_date = datetime.now(), source = 'xxxx')
url.save()
# urlsrch = models.UrlSearch(urlid = url.id, searchid = srch.id)
# urltags = models.UrlTags(urlid = url.id, name = 'xxx', value = 'yyy')
urlsrch = models.UrlSearch(urlid = url, searchid = srch)
urlsrch.save()
urltags = models.UrlTags(urlid = url, name = 'xxx', value = 'yyy')
urltags.save()
urlhtml = models.UrlHtml(urlid = url, html = "test html")
urlhtml.save()
cont = models.Content(content = "mycontent"+str(random.random()), dateacquired = datetime.now(), dateposted = datetime.now(), shortcont = "shortcont"+str(random.random()))
cont.save()
#contsrch = models.ContentSearch(searchid = srch.id, urlid = url.id, contentid = cont.id)
contsrch = models.ContentSearch(searchid = srch, urlid = url, contentid = cont)
contsrch.save()
return {'url': url.id, 'srch': srch.id, 'cont': cont.id}
def testDatabaseReturnObjects(self):
#this module returns a bunch of (sometimes nested) query results; we'll add some fake content then return it
fakeDict = self.installSomeFakeRecords()
url = fakeDict['url']
srch = fakeDict['srch']
cont = fakeDict['cont']
#now return it
methodCls = DatabaseMethods()
logging.debug("results from testDatabaseReturnObjects")
urls4srch =methodCls.getUrlsForSearch(srch)
for u in urls4srch:
logging.debug('urls %s' %str(u))
urls4srch =methodCls.getUrlsForSearch(srch)
for u in urls4srch:
logging.debug('urls with limit %s' %str(u))
cont4srch = methodCls.getContentForSearch(srch)
for u in cont4srch:
logging.debug('cont %s' %str(u))
html4url = methodCls.getHtmlForUrl(url)
for u in html4url:
logging.debug('html for url %s' %str(u))
html4srch = methodCls.getHtmlForSearch(srch)
for u in html4srch:
logging.debug('html for search %s'%str(u))
def testReferentialIntegrity(self):
#tests referential integrity of the database; first by adding a complete set of records then deleting the top level object
# attempts to access dependent objects should fail if the cascading deletes work as expected
clsObj = models()
#
deleteme = True; include = 'michigan, football'; exclude = 'ohio state'; urlname = 'urlname'
search = clsObj.Search(name = 'test', include = include, exclude = exclude, deleteme = True)
criteria = clsObj.SearchViewcriteria(searchid = search.id, include = search.include, exclude = search.exclude, andor = search.andor)
url1 = clsObj.Url(url = urlname + str(random.random()))
urlsrch1 = clsObj.UrlSearch(urlid = url1.id, searchid = search.id)
url2 = clsObj.Url(url = urlname + str(random.random()))
urlsrch2 = clsObj.UrlSearch(urlid = url2.id, searchid = search.id)
cont = clsObj.Content(content = 'cont' + str(random.random()), shortcont = 'short' + str(random.random()))
contsrch1 = clsObj.ContentSearch(urlid = url1.id, contentid = cont.id, searchid = search.id)
clsObj.Url.delete(url1.id)
#These should all fail on the first command of each try block. If not, it should raise an error
try:
clsObj.Url.objects.filter(id = url1.id)
raise WrapperError("DB Integrity failed")
except:
pass
try:
clsObj.UrlSearchUrl.objects.filter(id = urlsrch1.id)
raise WrapperError("DB Integrity failed")
except:
pass
try:
clsObj.ContentSearchUrl.objects.filter(id = contsrch1.id)
raise WrapperError("DB Integrity failed")
except:
pass
try:
clsObj.ContentUrl.objects.filter(id = cont.id)
raise WrapperError("DB Integrity failed")
except:
pass
pass
class testWebMethods():
def __init__(self, methodObj):
self.methodObj = methodObj
def testGetViewCriteria_and_getContentForCriteria(self):
#just make sure we can snag the SerchViewCriteria data
try:
viewCriteriaObj = self.methodObj.getViewCriteria()
viewCriteriaObj = self.methodObj.getViewCriteria(onlyPublic=True)
viewCriteriaObj = self.methodObj.getViewCriteria(onlyPublic=False)
except:
raise DbError("DB method getviewCriteria failed")
#now, make sure we can read it (one way is to ensure that the mandatory 'include' column has something)
for r in viewCriteriaObj:
assert len(r.include) >0
#make a query to the content table to be sure this doesn't blow up
for r in viewCriteriaObj:
mycont = self.methodObj.getContentForCriteria(r.id)
mycont = self.methodObj.getContentForCriteria(r.id, limit = 1)
#make sure we can try to get some content
for c in mycont:
myId = c.id
def testGetContentAndUrlForCriteria(self, criteriaLimit=None, contentLimit=None):
#just make sure we can snag the SerchViewCriteria data
from datetime import datetime
try:
viewCriteriaObj = self.methodObj.getViewCriteria(limit=criteriaLimit)
except:
raise DbError("DB method getviewCriteria failed")
#now, make sure we can read it (one way is to ensure that the mandatory 'include' column has something)
startCont = datetime.now()
mycont = self.methodObj.getContentForCriteria(viewCriteriaObj[0].id)
endCont = datetime.now()
print "time to get content: %s" %str(endCont-startCont)
#make a query to the content table to be sure this doesn't blow up
for r in viewCriteriaObj:
startUrl = datetime.now()
mycont = self.methodObj.getContentAndUrlForCriteria(r.id, limit = contentLimit)
endUrl=datetime.now()
print "time to dig out urls: %s" %str(endUrl-startUrl)
a=1
return "done"
class fixDb():
#adds urlid to existing Content database - one-time fix
def addUrlidToContent(self):
dbMethods = DatabaseMethods()
viewCriteriaObj = dbMethods.getViewCriteria()
for r in viewCriteriaObj:
dbMethods.addUrlIdToContent(criteriaid=r.id)
if __name__=='__main__':
#instansiate the class object
test = testDbRoutines()
#run the tests
#test.testDatabaseReturnObjects()
#test.testAddUrlsFromList()
#test.testAddCatchFromUrlVisit()
#test.testDeleteUrls()
testWeb = testWebMethods(DatabaseMethods())
myret = testWeb.testGetContentAndUrlForCriteria(criteriaLimit=1, contentLimit=None)
#mycont = testWeb.testGetViewCriteria_and_getContentForCriteria()
#a=1
|
mit
|
[
2344,
199,
2765,
859,
3509,
3050,
14975,
626,
1443,
506,
13810,
543,
503,
1928,
1808,
282,
3330,
10059,
14,
9948,
199,
2344,
199,
5680,
11768,
26,
221,
1929,
370,
5324,
314,
2199,
436,
314,
1145,
641,
314,
2366,
931,
880,
3520,
8925,
1736,
334,
65,
1331,
402,
2202,
14,
647,
365,
315,
314,
1453,
2082,
367,
3063,
9,
199,
3,
41,
13516,
1006,
781,
295,
2618,
1929,
370,
886,
365,
1852,
3238,
314,
2202,
859,
436,
314,
3734,
2860,
787,
3211,
14,
199,
3,
83,
17984,
315,
314,
366,
851,
2202,
334,
3749,
6181,
4192,
402,
3879,
9635,
14,
647,
199,
504,
1639,
14,
1018,
14,
8110,
492,
5341,
63,
2609,
199,
646,
2202,
199,
646,
747,
199,
646,
984,
199,
504,
25709,
14,
7995,
492,
26864,
199,
199,
2344,
2765,
1853,
402,
1233,
365,
367,
3879,
314,
859,
315,
282,
283,
7935,
13,
10636,
7,
818,
367,
5343,
2043,
710,
492,
5164,
365,
7437,
11012,
2952,
1639,
365,
10023,
367,
282,
298,
5836,
2013,
2,
2043,
6025,
402,
314,
859,
283,
992,
7,
221,
284,
14,
69,
14,
737,
5210,
282,
1642,
13,
436,
3499,
13,
1648,
931,
14,
2043,
11842,
12,
314,
909,
365,
665,
578,
283,
12816,
11340,
74,
14,
1176,
571,
14,
992,
7,
687,
2005,
63,
493,
63,
2253,
30,
221,
982,
781,
9329,
14722,
2043,
298,
646,
1709,
401,
314,
909,
365,
665,
578,
283,
992,
8423,
1314,
1639,
365,
17329,
370,
2112,
14,
199,
2344,
199,
1231,
694,
275,
1994,
4219,
15,
10853,
17,
15,
13249,
4805,
199,
692,
1738,
694,
440,
315,
984,
14,
515,
26,
272,
984,
14,
515,
14,
740,
8,
1231,
694,
9,
199,
504,
366,
851,
11340,
74,
14,
1176,
571,
492,
1709,
421,
199,
3,
6807,
4621,
199,
309,
504,
5295,
27789,
492,
12896,
12,
428,
49,
30113,
12,
2624,
2001,
12,
366,
605,
451,
83,
221,
327,
1461,
314,
492,
370,
675,
366,
1533,
1163,
2419,
11200,
199,
504,
2197,
492,
2197,
199,
646,
2050,
199,
646,
2882,
199,
646,
2196,
199,
646,
511,
199,
199,
3,
4229,
4621,
199,
646,
2199,
28834,
465,
2199,
28834,
199,
199,
3,
793,
2202,
199,
4947,
63,
2339,
275,
298,
4133,
14,
793,
2,
199,
4947,
63,
11817,
275,
2050,
14,
5287,
199,
199,
3,
1107,
9479,
221,
199,
9677,
63,
12779,
275,
2199,
28834,
14,
9677,
63,
12779,
199,
9677,
63,
8784,
275,
2199,
28834,
14,
9677,
63,
8784,
199,
199,
3,
4659,
2633,
436,
1950,
909,
1808,
15941,
687,
376,
5957,
570,
27,
314,
1950,
909,
365,
2288,
370,
642,
3413,
348,
199,
199,
5680,
7243,
26794,
5680,
199,
3,
646,
1709,
199,
3,
2168,
314,
3875,
1692,
8541,
27,
781,
7171,
492,
366,
851,
736,
199,
199,
5680,
547,
8089,
8,
397,
9,
199,
533,
28822,
547,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
574,
304,
267,
291,
14,
5329,
275,
574,
272,
347,
636,
495,
721,
277,
304,
267,
372,
4700,
8,
277,
14,
5329,
9,
198,
199,
199,
5680,
14552,
27939,
257,
199,
533,
8692,
10385,
837,
272,
1449,
2765,
1021,
9584,
8187,
687,
282,
769,
14,
221,
982,
886,
4738,
365,
2549,
12,
781,
7171,
1050,
376,
298,
1648,
2,
2725,
370,
314,
1817,
370,
6623,
507,
420,
314,
2754,
6869,
1159,
3414,
402,
15424,
367,
642,
2754,
334,
6777,
781,
1443,
675,
465,
376,
16385,
402,
18330,
680,
199,
198,
2344,
198,
23855,
347,
636,
826,
721,
277,
304,
267,
986,
2286,
347,
3145,
5278,
2714,
8,
277,
12,
2754,
344,
304,
199,
198,
3,
26289,
1006,
314,
1564,
5821,
367,
1006,
314,
15647,
4568,
543,
282,
2754,
199,
198,
1733,
344,
275,
1109,
8,
1733,
344,
9,
199,
198,
893,
26,
6722,
15647,
11188,
275,
291,
14,
362,
4003,
35,
7527,
65,
1858,
5278,
8,
1733,
344,
11820,
20525,
418,
199,
198,
2590,
26,
6722,
746,
28822,
547,
480,
15153,
78,
1133,
2342,
2457,
15647,
367,
2754,
450,
73,
2,
450,
1733,
344,
9,
199,
198,
509,
286,
315,
15647,
11188,
26,
6722,
862,
26,
507,
198,
277,
14,
1807,
2714,
1858,
35,
7527,
65,
8,
67,
14,
344,
9,
198,
6722,
871,
26,
507,
198,
3730,
28822,
547,
480,
15153,
78,
1133,
3145,
1564,
367,
2754,
450,
73,
12,
15647,
450,
73,
2,
2818,
1733,
344,
12,
286,
14,
344,
430,
199,
198,
1107,
221,
2286,
347,
3145,
5278,
2714,
3325,
51,
4033,
8,
277,
12,
2754,
344,
304,
199,
198,
3,
26289,
314,
1564,
436,
8187,
367,
282,
2754,
199,
198,
1733,
344,
29,
442,
8,
1733,
344,
9,
199,
198,
277,
14,
1807,
5278,
2714,
8,
1733,
344,
9,
199,
198,
277,
14,
1807,
21867,
478,
1858,
5278,
8,
1733,
344,
9,
199,
198,
1107,
413,
339,
347,
3633,
1721,
1451,
8,
277,
12,
2754,
344,
304,
199,
198,
3,
6199,
367,
1503,
394,
679,
666,
29579,
12981,
367,
675,
336,
15,
3411,
3050,
199,
198,
1107,
413,
257,
2286,
347,
3145,
2714,
1858,
35,
7527,
65,
8,
277,
12,
15647,
344,
304,
199,
198,
20525,
344,
29,
442,
8,
20525,
344,
9,
199,
198,
893,
26,
6722,
3145,
1296,
275,
1709,
14,
2714,
14,
1462,
14,
1541,
8,
20525,
344,
29,
20525,
344,
9,
6722,
3145,
1296,
14,
1807,
342,
6722,
372,
413,
199,
198,
2590,
26,
6722,
746,
2286,
347,
13082,
5278,
28834,
8,
277,
12,
2754,
344,
29,
488,
304,
267,
327,
80,
13072,
2754,
28754,
687,
1592,
267,
340,
2754,
344,
26,
288,
862,
26,
258,
372,
1709,
14,
5278,
14,
1462,
14,
1541,
8,
344,
29,
1733,
344,
9,
288,
871,
26,
221,
746,
28822,
547,
480,
5278,
5839,
26,
450,
83,
883,
1133,
506,
1911,
6808,
495,
8,
1733,
344,
430,
15567,
347,
13082,
5278,
11506,
8,
277,
12,
7629,
7401,
275,
488,
304,
267,
862,
26,
260,
372,
1709,
14,
6417,
5278,
14,
1462,
14,
1541,
8,
300,
7401,
275,
7629,
7401,
9,
267,
871,
26,
420,
746,
28822,
547,
480,
7521,
315,
1166,
5278,
16277,
367,
450,
73,
6808,
300,
7401,
9,
2286,
347,
1050,
7200,
6417,
8,
277,
12,
1166,
12,
3145,
278,
275,
756,
12,
2754,
344,
275,
488,
12,
1350,
275,
283,
5187,
297,
5818,
275,
378,
12
] |
[
199,
2765,
859,
3509,
3050,
14975,
626,
1443,
506,
13810,
543,
503,
1928,
1808,
282,
3330,
10059,
14,
9948,
199,
2344,
199,
5680,
11768,
26,
221,
1929,
370,
5324,
314,
2199,
436,
314,
1145,
641,
314,
2366,
931,
880,
3520,
8925,
1736,
334,
65,
1331,
402,
2202,
14,
647,
365,
315,
314,
1453,
2082,
367,
3063,
9,
199,
3,
41,
13516,
1006,
781,
295,
2618,
1929,
370,
886,
365,
1852,
3238,
314,
2202,
859,
436,
314,
3734,
2860,
787,
3211,
14,
199,
3,
83,
17984,
315,
314,
366,
851,
2202,
334,
3749,
6181,
4192,
402,
3879,
9635,
14,
647,
199,
504,
1639,
14,
1018,
14,
8110,
492,
5341,
63,
2609,
199,
646,
2202,
199,
646,
747,
199,
646,
984,
199,
504,
25709,
14,
7995,
492,
26864,
199,
199,
2344,
2765,
1853,
402,
1233,
365,
367,
3879,
314,
859,
315,
282,
283,
7935,
13,
10636,
7,
818,
367,
5343,
2043,
710,
492,
5164,
365,
7437,
11012,
2952,
1639,
365,
10023,
367,
282,
298,
5836,
2013,
2,
2043,
6025,
402,
314,
859,
283,
992,
7,
221,
284,
14,
69,
14,
737,
5210,
282,
1642,
13,
436,
3499,
13,
1648,
931,
14,
2043,
11842,
12,
314,
909,
365,
665,
578,
283,
12816,
11340,
74,
14,
1176,
571,
14,
992,
7,
687,
2005,
63,
493,
63,
2253,
30,
221,
982,
781,
9329,
14722,
2043,
298,
646,
1709,
401,
314,
909,
365,
665,
578,
283,
992,
8423,
1314,
1639,
365,
17329,
370,
2112,
14,
199,
2344,
199,
1231,
694,
275,
1994,
4219,
15,
10853,
17,
15,
13249,
4805,
199,
692,
1738,
694,
440,
315,
984,
14,
515,
26,
272,
984,
14,
515,
14,
740,
8,
1231,
694,
9,
199,
504,
366,
851,
11340,
74,
14,
1176,
571,
492,
1709,
421,
199,
3,
6807,
4621,
199,
309,
504,
5295,
27789,
492,
12896,
12,
428,
49,
30113,
12,
2624,
2001,
12,
366,
605,
451,
83,
221,
327,
1461,
314,
492,
370,
675,
366,
1533,
1163,
2419,
11200,
199,
504,
2197,
492,
2197,
199,
646,
2050,
199,
646,
2882,
199,
646,
2196,
199,
646,
511,
199,
199,
3,
4229,
4621,
199,
646,
2199,
28834,
465,
2199,
28834,
199,
199,
3,
793,
2202,
199,
4947,
63,
2339,
275,
298,
4133,
14,
793,
2,
199,
4947,
63,
11817,
275,
2050,
14,
5287,
199,
199,
3,
1107,
9479,
221,
199,
9677,
63,
12779,
275,
2199,
28834,
14,
9677,
63,
12779,
199,
9677,
63,
8784,
275,
2199,
28834,
14,
9677,
63,
8784,
199,
199,
3,
4659,
2633,
436,
1950,
909,
1808,
15941,
687,
376,
5957,
570,
27,
314,
1950,
909,
365,
2288,
370,
642,
3413,
348,
199,
199,
5680,
7243,
26794,
5680,
199,
3,
646,
1709,
199,
3,
2168,
314,
3875,
1692,
8541,
27,
781,
7171,
492,
366,
851,
736,
199,
199,
5680,
547,
8089,
8,
397,
9,
199,
533,
28822,
547,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
574,
304,
267,
291,
14,
5329,
275,
574,
272,
347,
636,
495,
721,
277,
304,
267,
372,
4700,
8,
277,
14,
5329,
9,
198,
199,
199,
5680,
14552,
27939,
257,
199,
533,
8692,
10385,
837,
272,
1449,
2765,
1021,
9584,
8187,
687,
282,
769,
14,
221,
982,
886,
4738,
365,
2549,
12,
781,
7171,
1050,
376,
298,
1648,
2,
2725,
370,
314,
1817,
370,
6623,
507,
420,
314,
2754,
6869,
1159,
3414,
402,
15424,
367,
642,
2754,
334,
6777,
781,
1443,
675,
465,
376,
16385,
402,
18330,
680,
199,
198,
2344,
198,
23855,
347,
636,
826,
721,
277,
304,
267,
986,
2286,
347,
3145,
5278,
2714,
8,
277,
12,
2754,
344,
304,
199,
198,
3,
26289,
1006,
314,
1564,
5821,
367,
1006,
314,
15647,
4568,
543,
282,
2754,
199,
198,
1733,
344,
275,
1109,
8,
1733,
344,
9,
199,
198,
893,
26,
6722,
15647,
11188,
275,
291,
14,
362,
4003,
35,
7527,
65,
1858,
5278,
8,
1733,
344,
11820,
20525,
418,
199,
198,
2590,
26,
6722,
746,
28822,
547,
480,
15153,
78,
1133,
2342,
2457,
15647,
367,
2754,
450,
73,
2,
450,
1733,
344,
9,
199,
198,
509,
286,
315,
15647,
11188,
26,
6722,
862,
26,
507,
198,
277,
14,
1807,
2714,
1858,
35,
7527,
65,
8,
67,
14,
344,
9,
198,
6722,
871,
26,
507,
198,
3730,
28822,
547,
480,
15153,
78,
1133,
3145,
1564,
367,
2754,
450,
73,
12,
15647,
450,
73,
2,
2818,
1733,
344,
12,
286,
14,
344,
430,
199,
198,
1107,
221,
2286,
347,
3145,
5278,
2714,
3325,
51,
4033,
8,
277,
12,
2754,
344,
304,
199,
198,
3,
26289,
314,
1564,
436,
8187,
367,
282,
2754,
199,
198,
1733,
344,
29,
442,
8,
1733,
344,
9,
199,
198,
277,
14,
1807,
5278,
2714,
8,
1733,
344,
9,
199,
198,
277,
14,
1807,
21867,
478,
1858,
5278,
8,
1733,
344,
9,
199,
198,
1107,
413,
339,
347,
3633,
1721,
1451,
8,
277,
12,
2754,
344,
304,
199,
198,
3,
6199,
367,
1503,
394,
679,
666,
29579,
12981,
367,
675,
336,
15,
3411,
3050,
199,
198,
1107,
413,
257,
2286,
347,
3145,
2714,
1858,
35,
7527,
65,
8,
277,
12,
15647,
344,
304,
199,
198,
20525,
344,
29,
442,
8,
20525,
344,
9,
199,
198,
893,
26,
6722,
3145,
1296,
275,
1709,
14,
2714,
14,
1462,
14,
1541,
8,
20525,
344,
29,
20525,
344,
9,
6722,
3145,
1296,
14,
1807,
342,
6722,
372,
413,
199,
198,
2590,
26,
6722,
746,
2286,
347,
13082,
5278,
28834,
8,
277,
12,
2754,
344,
29,
488,
304,
267,
327,
80,
13072,
2754,
28754,
687,
1592,
267,
340,
2754,
344,
26,
288,
862,
26,
258,
372,
1709,
14,
5278,
14,
1462,
14,
1541,
8,
344,
29,
1733,
344,
9,
288,
871,
26,
221,
746,
28822,
547,
480,
5278,
5839,
26,
450,
83,
883,
1133,
506,
1911,
6808,
495,
8,
1733,
344,
430,
15567,
347,
13082,
5278,
11506,
8,
277,
12,
7629,
7401,
275,
488,
304,
267,
862,
26,
260,
372,
1709,
14,
6417,
5278,
14,
1462,
14,
1541,
8,
300,
7401,
275,
7629,
7401,
9,
267,
871,
26,
420,
746,
28822,
547,
480,
7521,
315,
1166,
5278,
16277,
367,
450,
73,
6808,
300,
7401,
9,
2286,
347,
1050,
7200,
6417,
8,
277,
12,
1166,
12,
3145,
278,
275,
756,
12,
2754,
344,
275,
488,
12,
1350,
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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
hyOzd/cadquery
|
tests/TestWorkplanes.py
|
4
|
5235
|
"""
Tests basic workplane functionality
"""
#core modules
#my modules
from cadquery import *
from tests import BaseTest,toTuple
xAxis_ = Vector(1, 0, 0)
yAxis_ = Vector(0, 1, 0)
zAxis_ = Vector(0, 0, 1)
xInvAxis_ = Vector(-1, 0, 0)
yInvAxis_ = Vector(0, -1, 0)
zInvAxis_ = Vector(0, 0, -1)
class TestWorkplanes(BaseTest):
def testYZPlaneOrigins(self):
#xy plane-- with origin at x=0.25
base = Vector(0.25,0,0)
p = Plane(base, Vector(0,1,0), Vector(1,0,0))
#origin is always (0,0,0) in local coordinates
self.assertTupleAlmostEquals((0,0,0), p.toLocalCoords(p.origin).toTuple() ,2 )
#(0,0,0) is always the original base in global coordinates
self.assertTupleAlmostEquals(base.toTuple(), p.toWorldCoords((0,0)).toTuple() ,2 )
def testXYPlaneOrigins(self):
base = Vector(0,0,0.25)
p = Plane(base, Vector(1,0,0), Vector(0,0,1))
#origin is always (0,0,0) in local coordinates
self.assertTupleAlmostEquals((0,0,0), p.toLocalCoords(p.origin).toTuple() ,2 )
#(0,0,0) is always the original base in global coordinates
self.assertTupleAlmostEquals(toTuple(base), p.toWorldCoords((0,0)).toTuple() ,2 )
def testXZPlaneOrigins(self):
base = Vector(0,0.25,0)
p = Plane(base, Vector(0,0,1), Vector(0,1,0))
#(0,0,0) is always the original base in global coordinates
self.assertTupleAlmostEquals(toTuple(base), p.toWorldCoords((0,0)).toTuple() ,2 )
#origin is always (0,0,0) in local coordinates
self.assertTupleAlmostEquals((0,0,0), p.toLocalCoords(p.origin).toTuple() ,2 )
def testPlaneBasics(self):
p = Plane.XY()
#local to world
self.assertTupleAlmostEquals((1.0,1.0,0),p.toWorldCoords((1,1)).toTuple(),2 )
self.assertTupleAlmostEquals((-1.0,-1.0,0), p.toWorldCoords((-1,-1)).toTuple(),2 )
#world to local
self.assertTupleAlmostEquals((-1.0,-1.0), p.toLocalCoords(Vector(-1,-1,0)).toTuple() ,2 )
self.assertTupleAlmostEquals((1.0,1.0), p.toLocalCoords(Vector(1,1,0)).toTuple() ,2 )
p = Plane.YZ()
self.assertTupleAlmostEquals((0,1.0,1.0),p.toWorldCoords((1,1)).toTuple() ,2 )
#world to local
self.assertTupleAlmostEquals((1.0,1.0), p.toLocalCoords(Vector(0,1,1)).toTuple() ,2 )
p = Plane.XZ()
r = p.toWorldCoords((1,1)).toTuple()
self.assertTupleAlmostEquals((1.0,0.0,1.0),r ,2 )
#world to local
self.assertTupleAlmostEquals((1.0,1.0), p.toLocalCoords(Vector(1,0,1)).toTuple() ,2 )
def testOffsetPlanes(self):
"Tests that a plane offset from the origin works ok too"
p = Plane.XY(origin=(10.0,10.0,0))
self.assertTupleAlmostEquals((11.0,11.0,0.0),p.toWorldCoords((1.0,1.0)).toTuple(),2 )
self.assertTupleAlmostEquals((2.0,2.0), p.toLocalCoords(Vector(12.0,12.0,0)).toTuple() ,2 )
#TODO test these offsets in the other dimensions too
p = Plane.YZ(origin=(0,2,2))
self.assertTupleAlmostEquals((0.0,5.0,5.0), p.toWorldCoords((3.0,3.0)).toTuple() ,2 )
self.assertTupleAlmostEquals((10,10.0,0.0), p.toLocalCoords(Vector(0.0,12.0,12.0)).toTuple() ,2 )
p = Plane.XZ(origin=(2,0,2))
r = p.toWorldCoords((1.0,1.0)).toTuple()
self.assertTupleAlmostEquals((3.0,0.0,3.0),r ,2 )
self.assertTupleAlmostEquals((10.0,10.0), p.toLocalCoords(Vector(12.0,0.0,12.0)).toTuple() ,2 )
def testXYPlaneBasics(self):
p = Plane.named('XY')
self.assertTupleAlmostEquals(p.zDir.toTuple(), zAxis_.toTuple(), 4)
self.assertTupleAlmostEquals(p.xDir.toTuple(), xAxis_.toTuple(), 4)
self.assertTupleAlmostEquals(p.yDir.toTuple(), yAxis_.toTuple(), 4)
def testYZPlaneBasics(self):
p = Plane.named('YZ')
self.assertTupleAlmostEquals(p.zDir.toTuple(), xAxis_.toTuple(), 4)
self.assertTupleAlmostEquals(p.xDir.toTuple(), yAxis_.toTuple(), 4)
self.assertTupleAlmostEquals(p.yDir.toTuple(), zAxis_.toTuple(), 4)
def testZXPlaneBasics(self):
p = Plane.named('ZX')
self.assertTupleAlmostEquals(p.zDir.toTuple(), yAxis_.toTuple(), 4)
self.assertTupleAlmostEquals(p.xDir.toTuple(), zAxis_.toTuple(), 4)
self.assertTupleAlmostEquals(p.yDir.toTuple(), xAxis_.toTuple(), 4)
def testXZPlaneBasics(self):
p = Plane.named('XZ')
self.assertTupleAlmostEquals(p.zDir.toTuple(), yInvAxis_.toTuple(), 4)
self.assertTupleAlmostEquals(p.xDir.toTuple(), xAxis_.toTuple(), 4)
self.assertTupleAlmostEquals(p.yDir.toTuple(), zAxis_.toTuple(), 4)
def testYXPlaneBasics(self):
p = Plane.named('YX')
self.assertTupleAlmostEquals(p.zDir.toTuple(), zInvAxis_.toTuple(), 4)
self.assertTupleAlmostEquals(p.xDir.toTuple(), yAxis_.toTuple(), 4)
self.assertTupleAlmostEquals(p.yDir.toTuple(), xAxis_.toTuple(), 4)
def testZYPlaneBasics(self):
p = Plane.named('ZY')
self.assertTupleAlmostEquals(p.zDir.toTuple(), xInvAxis_.toTuple(), 4)
self.assertTupleAlmostEquals(p.xDir.toTuple(), zAxis_.toTuple(), 4)
self.assertTupleAlmostEquals(p.yDir.toTuple(), yAxis_.toTuple(), 4)
|
lgpl-3.0
|
[
624,
272,
6496,
5678,
1736,
15365,
9330,
199,
624,
199,
3,
1018,
4621,
199,
199,
3,
1662,
4621,
199,
504,
286,
350,
1131,
492,
627,
199,
504,
2295,
492,
3523,
774,
12,
475,
7075,
199,
199,
7471,
7291,
63,
275,
11388,
8,
17,
12,
378,
12,
378,
9,
199,
89,
11220,
63,
275,
11388,
8,
16,
12,
413,
12,
378,
9,
199,
6353,
7291,
63,
275,
11388,
8,
16,
12,
378,
12,
413,
9,
199,
88,
14883,
11220,
63,
275,
11388,
2801,
17,
12,
378,
12,
378,
9,
199,
89,
14883,
11220,
63,
275,
11388,
8,
16,
12,
446,
17,
12,
378,
9,
199,
90,
14883,
11220,
63,
275,
11388,
8,
16,
12,
378,
12,
446,
17,
9,
199,
199,
533,
1379,
6517,
5140,
397,
8,
23170,
304,
339,
347,
511,
26184,
23363,
12834,
83,
8,
277,
304,
267,
327,
1702,
16388,
306,
543,
6330,
737,
671,
29,
16,
14,
821,
267,
1300,
275,
11388,
8,
16,
14,
821,
12,
16,
12,
16,
9,
267,
299,
275,
510,
24064,
8,
1095,
12,
11388,
8,
16,
12,
17,
12,
16,
395,
11388,
8,
17,
12,
16,
12,
16,
430,
398,
327,
6493,
365,
3544,
334,
16,
12,
16,
12,
16,
9,
315,
2257,
8983,
267,
291,
14,
479,
7075,
7331,
83,
1332,
16,
12,
16,
12,
16,
395,
299,
14,
475,
5339,
29734,
8,
80,
14,
6493,
680,
475,
7075,
342,
2360,
18,
776,
398,
21571,
16,
12,
16,
12,
16,
9,
365,
3544,
314,
3379,
1300,
315,
2288,
8983,
267,
291,
14,
479,
7075,
7331,
83,
8,
1095,
14,
475,
7075,
1062,
299,
14,
475,
15943,
29734,
1332,
16,
12,
16,
4992,
475,
7075,
342,
221,
2360,
18,
776,
339,
347,
511,
56,
7431,
24064,
12834,
83,
8,
277,
304,
267,
1300,
275,
11388,
8,
16,
12,
16,
12,
16,
14,
821,
9,
267,
299,
275,
510,
24064,
8,
1095,
12,
11388,
8,
17,
12,
16,
12,
16,
395,
11388,
8,
16,
12,
16,
12,
17,
430,
398,
327,
6493,
365,
3544,
334,
16,
12,
16,
12,
16,
9,
315,
2257,
8983,
267,
291,
14,
479,
7075,
7331,
83,
1332,
16,
12,
16,
12,
16,
395,
299,
14,
475,
5339,
29734,
8,
80,
14,
6493,
680,
475,
7075,
342,
2360,
18,
776,
398,
21571,
16,
12,
16,
12,
16,
9,
365,
3544,
314,
3379,
1300,
315,
2288,
8983,
267,
291,
14,
479,
7075,
7331,
83,
8,
475,
7075,
8,
1095,
395,
299,
14,
475,
15943,
29734,
1332,
16,
12,
16,
4992,
475,
7075,
342,
2360,
18,
776,
339,
347,
511,
56,
58,
23363,
12834,
83,
8,
277,
304,
267,
1300,
275,
11388,
8,
16,
12,
16,
14,
821,
12,
16,
9,
267,
299,
275,
510,
24064,
8,
1095,
12,
11388,
8,
16,
12,
16,
12,
17,
395,
11388,
8,
16,
12,
17,
12,
16,
430,
398,
21571,
16,
12,
16,
12,
16,
9,
365,
3544,
314,
3379,
1300,
315,
2288,
8983,
267,
291,
14,
479,
7075,
7331,
83,
8,
475,
7075,
8,
1095,
395,
299,
14,
475,
15943,
29734,
1332,
16,
12,
16,
4992,
475,
7075,
342,
2360,
18,
776,
398,
327,
6493,
365,
3544,
334,
16,
12,
16,
12,
16,
9,
315,
2257,
8983,
267,
291,
14,
479,
7075,
7331,
83,
1332,
16,
12,
16,
12,
16,
395,
299,
14,
475,
5339,
29734,
8,
80,
14,
6493,
680,
475,
7075,
342,
2360,
18,
776,
339,
347,
511,
23363,
6845,
83,
8,
277,
304,
267,
299,
275,
510,
24064,
14,
8195,
342,
267,
327,
1832,
370,
6701,
267,
291,
14,
479,
7075,
7331,
83,
1332,
17,
14,
16,
12,
17,
14,
16,
12,
16,
395,
80,
14,
475,
15943,
29734,
1332,
17,
12,
17,
4992,
475,
7075,
1062,
18,
776,
267,
291,
14,
479,
7075,
7331,
83,
18138,
17,
14,
16,
3057,
17,
14,
16,
12,
16,
395,
299,
14,
475,
15943,
29734,
18138,
17,
3057,
17,
4992,
475,
7075,
1062,
18,
776,
398,
327,
7617,
370,
2257,
267,
291,
14,
479,
7075,
7331,
83,
18138,
17,
14,
16,
3057,
17,
14,
16,
395,
299,
14,
475,
5339,
29734,
8,
3646,
2801,
17,
3057,
17,
12,
16,
4992,
475,
7075,
342,
2360,
18,
776,
267,
291,
14,
479,
7075,
7331,
83,
1332,
17,
14,
16,
12,
17,
14,
16,
395,
299,
14,
475,
5339,
29734,
8,
3646,
8,
17,
12,
17,
12,
16,
4992,
475,
7075,
342,
2360,
18,
776,
398,
299,
275,
510,
24064,
14,
26184,
342,
267,
291,
14,
479,
7075,
7331,
83,
1332,
16,
12,
17,
14,
16,
12,
17,
14,
16,
395,
80,
14,
475,
15943,
29734,
1332,
17,
12,
17,
4992,
475,
7075,
342,
2360,
18,
776,
398,
327,
7617,
370,
2257,
267,
291,
14,
479,
7075,
7331,
83,
1332,
17,
14,
16,
12,
17,
14,
16,
395,
299,
14,
475,
5339,
29734,
8,
3646,
8,
16,
12,
17,
12,
17,
4992,
475,
7075,
342,
2360,
18,
776,
398,
299,
275,
510,
24064,
14,
56,
58,
342,
267,
519,
275,
299,
14,
475,
15943,
29734,
1332,
17,
12,
17,
4992,
475,
7075,
342,
267,
291,
14,
479,
7075,
7331,
83,
1332,
17,
14,
16,
12,
16,
14,
16,
12,
17,
14,
16,
395,
82,
2360,
18,
776,
398,
327,
7617,
370,
2257,
267,
291,
14,
479,
7075,
7331,
83,
1332,
17,
14,
16,
12,
17,
14,
16,
395,
299,
14,
475,
5339,
29734,
8,
3646,
8,
17,
12,
16,
12,
17,
4992,
475,
7075,
342,
2360,
18,
776,
339,
347,
511,
6397,
13375,
397,
8,
277,
304,
267,
298,
2925,
626,
282,
16388,
3268,
687,
314,
6330,
5419,
4112,
4634,
2,
267,
299,
275,
510,
24064,
14,
8195,
8,
6493,
2687,
709,
14,
16,
12,
709,
14,
16,
12,
16,
430,
7318,
291,
14,
479,
7075,
7331,
83,
1332,
845,
14,
16,
12,
845,
14,
16,
12,
16,
14,
16,
395,
80,
14,
475,
15943,
29734,
1332,
17,
14,
16,
12,
17,
14,
16,
4992,
475,
7075,
1062,
18,
776,
267,
291,
14,
479,
7075,
7331,
83,
1332,
18,
14,
16,
12,
18,
14,
16,
395,
299,
14,
475,
5339,
29734,
8,
3646,
8,
713,
14,
16,
12,
713,
14,
16,
12,
16,
4992,
475,
7075,
342,
2360,
18,
776,
398,
327,
11768,
511,
3520,
15340,
315,
314,
1163
] |
[
272,
6496,
5678,
1736,
15365,
9330,
199,
624,
199,
3,
1018,
4621,
199,
199,
3,
1662,
4621,
199,
504,
286,
350,
1131,
492,
627,
199,
504,
2295,
492,
3523,
774,
12,
475,
7075,
199,
199,
7471,
7291,
63,
275,
11388,
8,
17,
12,
378,
12,
378,
9,
199,
89,
11220,
63,
275,
11388,
8,
16,
12,
413,
12,
378,
9,
199,
6353,
7291,
63,
275,
11388,
8,
16,
12,
378,
12,
413,
9,
199,
88,
14883,
11220,
63,
275,
11388,
2801,
17,
12,
378,
12,
378,
9,
199,
89,
14883,
11220,
63,
275,
11388,
8,
16,
12,
446,
17,
12,
378,
9,
199,
90,
14883,
11220,
63,
275,
11388,
8,
16,
12,
378,
12,
446,
17,
9,
199,
199,
533,
1379,
6517,
5140,
397,
8,
23170,
304,
339,
347,
511,
26184,
23363,
12834,
83,
8,
277,
304,
267,
327,
1702,
16388,
306,
543,
6330,
737,
671,
29,
16,
14,
821,
267,
1300,
275,
11388,
8,
16,
14,
821,
12,
16,
12,
16,
9,
267,
299,
275,
510,
24064,
8,
1095,
12,
11388,
8,
16,
12,
17,
12,
16,
395,
11388,
8,
17,
12,
16,
12,
16,
430,
398,
327,
6493,
365,
3544,
334,
16,
12,
16,
12,
16,
9,
315,
2257,
8983,
267,
291,
14,
479,
7075,
7331,
83,
1332,
16,
12,
16,
12,
16,
395,
299,
14,
475,
5339,
29734,
8,
80,
14,
6493,
680,
475,
7075,
342,
2360,
18,
776,
398,
21571,
16,
12,
16,
12,
16,
9,
365,
3544,
314,
3379,
1300,
315,
2288,
8983,
267,
291,
14,
479,
7075,
7331,
83,
8,
1095,
14,
475,
7075,
1062,
299,
14,
475,
15943,
29734,
1332,
16,
12,
16,
4992,
475,
7075,
342,
221,
2360,
18,
776,
339,
347,
511,
56,
7431,
24064,
12834,
83,
8,
277,
304,
267,
1300,
275,
11388,
8,
16,
12,
16,
12,
16,
14,
821,
9,
267,
299,
275,
510,
24064,
8,
1095,
12,
11388,
8,
17,
12,
16,
12,
16,
395,
11388,
8,
16,
12,
16,
12,
17,
430,
398,
327,
6493,
365,
3544,
334,
16,
12,
16,
12,
16,
9,
315,
2257,
8983,
267,
291,
14,
479,
7075,
7331,
83,
1332,
16,
12,
16,
12,
16,
395,
299,
14,
475,
5339,
29734,
8,
80,
14,
6493,
680,
475,
7075,
342,
2360,
18,
776,
398,
21571,
16,
12,
16,
12,
16,
9,
365,
3544,
314,
3379,
1300,
315,
2288,
8983,
267,
291,
14,
479,
7075,
7331,
83,
8,
475,
7075,
8,
1095,
395,
299,
14,
475,
15943,
29734,
1332,
16,
12,
16,
4992,
475,
7075,
342,
2360,
18,
776,
339,
347,
511,
56,
58,
23363,
12834,
83,
8,
277,
304,
267,
1300,
275,
11388,
8,
16,
12,
16,
14,
821,
12,
16,
9,
267,
299,
275,
510,
24064,
8,
1095,
12,
11388,
8,
16,
12,
16,
12,
17,
395,
11388,
8,
16,
12,
17,
12,
16,
430,
398,
21571,
16,
12,
16,
12,
16,
9,
365,
3544,
314,
3379,
1300,
315,
2288,
8983,
267,
291,
14,
479,
7075,
7331,
83,
8,
475,
7075,
8,
1095,
395,
299,
14,
475,
15943,
29734,
1332,
16,
12,
16,
4992,
475,
7075,
342,
2360,
18,
776,
398,
327,
6493,
365,
3544,
334,
16,
12,
16,
12,
16,
9,
315,
2257,
8983,
267,
291,
14,
479,
7075,
7331,
83,
1332,
16,
12,
16,
12,
16,
395,
299,
14,
475,
5339,
29734,
8,
80,
14,
6493,
680,
475,
7075,
342,
2360,
18,
776,
339,
347,
511,
23363,
6845,
83,
8,
277,
304,
267,
299,
275,
510,
24064,
14,
8195,
342,
267,
327,
1832,
370,
6701,
267,
291,
14,
479,
7075,
7331,
83,
1332,
17,
14,
16,
12,
17,
14,
16,
12,
16,
395,
80,
14,
475,
15943,
29734,
1332,
17,
12,
17,
4992,
475,
7075,
1062,
18,
776,
267,
291,
14,
479,
7075,
7331,
83,
18138,
17,
14,
16,
3057,
17,
14,
16,
12,
16,
395,
299,
14,
475,
15943,
29734,
18138,
17,
3057,
17,
4992,
475,
7075,
1062,
18,
776,
398,
327,
7617,
370,
2257,
267,
291,
14,
479,
7075,
7331,
83,
18138,
17,
14,
16,
3057,
17,
14,
16,
395,
299,
14,
475,
5339,
29734,
8,
3646,
2801,
17,
3057,
17,
12,
16,
4992,
475,
7075,
342,
2360,
18,
776,
267,
291,
14,
479,
7075,
7331,
83,
1332,
17,
14,
16,
12,
17,
14,
16,
395,
299,
14,
475,
5339,
29734,
8,
3646,
8,
17,
12,
17,
12,
16,
4992,
475,
7075,
342,
2360,
18,
776,
398,
299,
275,
510,
24064,
14,
26184,
342,
267,
291,
14,
479,
7075,
7331,
83,
1332,
16,
12,
17,
14,
16,
12,
17,
14,
16,
395,
80,
14,
475,
15943,
29734,
1332,
17,
12,
17,
4992,
475,
7075,
342,
2360,
18,
776,
398,
327,
7617,
370,
2257,
267,
291,
14,
479,
7075,
7331,
83,
1332,
17,
14,
16,
12,
17,
14,
16,
395,
299,
14,
475,
5339,
29734,
8,
3646,
8,
16,
12,
17,
12,
17,
4992,
475,
7075,
342,
2360,
18,
776,
398,
299,
275,
510,
24064,
14,
56,
58,
342,
267,
519,
275,
299,
14,
475,
15943,
29734,
1332,
17,
12,
17,
4992,
475,
7075,
342,
267,
291,
14,
479,
7075,
7331,
83,
1332,
17,
14,
16,
12,
16,
14,
16,
12,
17,
14,
16,
395,
82,
2360,
18,
776,
398,
327,
7617,
370,
2257,
267,
291,
14,
479,
7075,
7331,
83,
1332,
17,
14,
16,
12,
17,
14,
16,
395,
299,
14,
475,
5339,
29734,
8,
3646,
8,
17,
12,
16,
12,
17,
4992,
475,
7075,
342,
2360,
18,
776,
339,
347,
511,
6397,
13375,
397,
8,
277,
304,
267,
298,
2925,
626,
282,
16388,
3268,
687,
314,
6330,
5419,
4112,
4634,
2,
267,
299,
275,
510,
24064,
14,
8195,
8,
6493,
2687,
709,
14,
16,
12,
709,
14,
16,
12,
16,
430,
7318,
291,
14,
479,
7075,
7331,
83,
1332,
845,
14,
16,
12,
845,
14,
16,
12,
16,
14,
16,
395,
80,
14,
475,
15943,
29734,
1332,
17,
14,
16,
12,
17,
14,
16,
4992,
475,
7075,
1062,
18,
776,
267,
291,
14,
479,
7075,
7331,
83,
1332,
18,
14,
16,
12,
18,
14,
16,
395,
299,
14,
475,
5339,
29734,
8,
3646,
8,
713,
14,
16,
12,
713,
14,
16,
12,
16,
4992,
475,
7075,
342,
2360,
18,
776,
398,
327,
11768,
511,
3520,
15340,
315,
314,
1163,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ktan2020/legacy-automation
|
win/Lib/site-packages/jpype/_refdaemon.py
|
8
|
1084
|
#*****************************************************************************
# Copyright 2004-2008 Steve Menard
#
# 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 thread
import _jpype
def startJava():
_jpype.startReferenceQueue(1)
def startPython():
def _run() :
_jpype.attachThreadToJVM()
_jpype.startReferenceQueue(0)
thread.start_new_thread(_run, tuple())
def stop():
_jpype.stopReferenceQueue()
|
mit
|
[
3,
14355,
1116,
10,
202,
199,
3,
257,
1898,
8353,
13,
9300,
17854,
432,
603,
287,
1005,
202,
199,
3,
202,
199,
3,
257,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
202,
199,
3,
257,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
202,
199,
3,
257,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
202,
199,
3,
202,
199,
3,
755,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
202,
199,
3,
202,
199,
3,
257,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
202,
199,
3,
257,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
202,
199,
3,
257,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
202,
199,
3,
257,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
202,
199,
3,
257,
4204,
1334,
314,
844,
14,
202,
199,
3,
259,
202,
199,
3,
14355,
1116,
10,
202,
199,
646,
2462,
2999,
199,
646,
485,
11538,
514,
2999,
199,
318,
1343,
12576,
837,
1128,
485,
11538,
514,
14,
928,
5083,
3737,
8,
17,
9,
8428,
202,
199,
318,
1343,
4718,
837,
1128,
347,
485,
1065,
342,
520,
8428,
198,
63,
11538,
514,
14,
5040,
4436,
1378,
42,
6849,
342,
1039,
485,
11538,
514,
14,
928,
5083,
3737,
8,
16,
9,
8740,
1223,
198,
2671,
14,
928,
63,
1222,
63,
2671,
1547,
1065,
12,
2008,
1012,
258,
2999,
199,
318,
3631,
837,
1128,
485,
11538,
514,
14,
2379,
5083,
3737,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
14355,
1116,
10,
202,
199,
3,
257,
1898,
8353,
13,
9300,
17854,
432,
603,
287,
1005,
202,
199,
3,
202,
199,
3,
257,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
202,
199,
3,
257,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
202,
199,
3,
257,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
202,
199,
3,
202,
199,
3,
755,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
202,
199,
3,
202,
199,
3,
257,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
202,
199,
3,
257,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
202,
199,
3,
257,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
202,
199,
3,
257,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
202,
199,
3,
257,
4204,
1334,
314,
844,
14,
202,
199,
3,
259,
202,
199,
3,
14355,
1116,
10,
202,
199,
646,
2462,
2999,
199,
646,
485,
11538,
514,
2999,
199,
318,
1343,
12576,
837,
1128,
485,
11538,
514,
14,
928,
5083,
3737,
8,
17,
9,
8428,
202,
199,
318,
1343,
4718,
837,
1128,
347,
485,
1065,
342,
520,
8428,
198,
63,
11538,
514,
14,
5040,
4436,
1378,
42,
6849,
342,
1039,
485,
11538,
514,
14,
928,
5083,
3737,
8,
16,
9,
8740,
1223,
198,
2671,
14,
928,
63,
1222,
63,
2671,
1547,
1065,
12,
2008,
1012,
258,
2999,
199,
318,
3631,
837,
1128,
485,
11538,
514,
14,
2379,
5083,
3737,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
syed/instatnt-press
|
models/db.py
|
7
|
8583
|
# -*- coding: utf-8 -*-
#
# Instant Press. Instant sites. CMS developed in Web2py Framework
# Site: http://www.instant2press.com
#
# Copyright (c) 2010 Mulone, Pablo Martín
#
# License Code: GPL, General Public License v. 2.0
# License Content: Creative Commons Attribution 3.0
#
# Also visit: www.web2py.com
# or Groups: http://groups.google.com/group/web2py
# http://groups.google.com/group/web2py-usuarios
#
#
# 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, see <http://www.gnu.org/licenses/>
def connect_to_db(config):
if request.env.web2py_runtime_gae:
from gluon.contrib.gae_memcache import MemcacheClient
from gluon.contrib.memdb import MEMDB
cache.memcache = MemcacheClient(request)
cache.ram = cache.disk = cache.memcache
db = DAL('gae')
session.connect(request,response,MEMDB(cache.memcache))
else:
db = DAL(config.connect_uri)
return db
def init_mail(config):
from gluon.tools import Mail
mail = Mail() # mailer
mail.settings.server = config.mail_server or 'smtp.gmail.com:587' # your SMTP server
mail.settings.sender = config.mail_sender # your email
mail.settings.login = config.mail_login # your credentials or None
return mail
def init_auth(globals, db, config):
from gluon.tools import Auth
import datetime
#8.1.4 Customizing Auth page 350
auth = Auth(globals,db) #authentication/authorization
auth.settings.hmac_key = config.register_hmac # before define_tables()
if config.register_method in ['Disabled']:
auth.settings.actions_disabled.append('register') #disable register
#Recaptcha (pag349)
if config.register_method in ['Recaptcha']:
from gluon.tools import Recaptcha
auth.settings.captcha = Recaptcha(request, config.recaptcha_public, config.recaptcha_private)
db.define_table(
auth.settings.table_user_name,
Field('first_name', length=128, default=''),
Field('last_name', length=128, default=''),
Field('email', length=128, default='', unique=True),
Field('password', 'password', length=512,
readable=False, label='Password'),
Field('registration_key', length=512,
writable=False, readable=False, default=''),
Field('reset_password_key', length=512,
writable=False, readable=False, default=''),
Field('registration_id', length=512,
writable=False, readable=False, default=''),
Field('created_on', 'datetime', default=datetime.datetime.today(),
writable=False,readable=False),
Field('site_language', length=128,writable=False, readable=False,
default='', label=T('Language')),
migrate=config.is_first_time
)
custom_auth_table = db[auth.settings.table_user_name] # get the custom_auth_table
custom_auth_table.first_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
custom_auth_table.last_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
custom_auth_table.password.requires = [CRYPT(key=auth.settings.hmac_key)]
custom_auth_table.email.requires = [
IS_EMAIL(error_message=auth.messages.invalid_email),
IS_NOT_IN_DB(db, custom_auth_table.email)]
auth.settings.table_user = custom_auth_table
auth.define_tables() # creates all needed tables
auth.settings.mailer = mail # for user email verification
if config.register_method in ['None','Recaptcha','Approval']:
auth.settings.registration_requires_verification = False
else:
auth.settings.registration_requires_verification = True
if config.register_method in ['Approval']:
auth.settings.registration_requires_approval = True
else:
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True
auth.messages.verify_email = 'Click on the link http://'+request.env.http_host+\
URL(r=request,c='default',f='user',args=['verify_email'])+\
'/%(key)s to verify your email'
auth.messages.reset_password = 'Click on the link http://'+request.env.http_host+\
URL(r=request,c='default',f='user',args=['reset_password'])+\
'/%(key)s to reset your password'
return auth
def get_login_panel():
login_panel = ""
if 'auth' in globals():
if not auth.is_logged_in():
link_register_caption = T('Register')
link_register = A(link_register_caption, \
_href=URL(request.application,\
i2p.config.controller_default,\
'user/register'))
link_login_caption = T('Sign in')
link_login = A(link_login_caption, _href=auth.settings.login_url)
caption_notloggin = T('You are not logged in')
login_panel = '''<div id="login-panel">%s %s | %s </div>''' % \
(caption_notloggin, link_login, link_register)
else:
#auth.user.email
link_user = A(T('My Profile'), _href=URL(request.application,\
i2p.config.controller_default,\
'user/profile'))
link_changepass_caption = T('Change password')
link_changepass = A(link_changepass_caption, \
_href=URL(request.application,i2p.config.controller_default,\
'user/change_password'))
link_logout_caption = T('Logout')
link_logout = A(link_logout_caption, _href=URL(request.application,\
i2p.config.controller_default,\
'user/logout'))
login_panel = '<div id="login-panel">%s | %s | %s</div>' % \
(link_user, link_changepass, link_logout)
return login_panel
if i2pConfig.language_force:
T.force(i2pConfig.language)
db = connect_to_db(i2pConfig) #connect to database
mail = init_mail(i2pConfig) #initialize mail
auth = init_auth(globals(), db, i2pConfig) #initialize auth
i2p = Instant2Press(globals(), db, i2pConfig) #main class
#we need some information in the database to work correctly,
#this fill with default information, the first time.
if i2pConfig.is_first_time:
#begin load all base modules
i2p.load_mod_common() #load common modules
i2p.db_definitions() #define tables
#end load all base modules
if i2p.siteinfo.no_info_in_db(): #if there are no info in db, so i think is the first time
#and create default values
i2p.load_mod_filldb()
i2p.filldb.info_default() #if it is the first time then fill with default values
i2p.filldb.required_admin() #we need an admin
i2p.filldb.default_style() #we need a basic style
if i2pConfig.is_demo:
i2p.filldb.test_users() #ok some others guys to test admin users
i2p.filldb.test_articles() #the test article
else:
i2pConfig.set_first_time(False)
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1010,
4715,
23583,
14,
1010,
4715,
15424,
14,
29554,
477,
27813,
315,
6001,
18,
647,
22545,
199,
3,
11666,
26,
1455,
921,
1544,
14,
3615,
867,
18,
2915,
14,
957,
221,
199,
3,
199,
3,
1898,
334,
67,
9,
7129,
22578,
368,
12,
510,
371,
320,
603,
580,
13676,
78,
221,
199,
3,
199,
3,
844,
5495,
26,
14629,
12,
1696,
1684,
844,
373,
14,
499,
14,
16,
199,
3,
844,
6646,
26,
9750,
1905,
7046,
4654,
2854,
15980,
650,
14,
16,
221,
199,
3,
199,
3,
6121,
5684,
26,
20732,
14,
2520,
18,
647,
14,
957,
221,
199,
3,
3777,
503,
25031,
26,
1455,
921,
2634,
14,
3098,
14,
957,
15,
923,
15,
2520,
18,
647,
221,
199,
3,
4483,
1455,
921,
2634,
14,
3098,
14,
957,
15,
923,
15,
2520,
18,
647,
13,
527,
85,
17832,
257,
199,
3,
199,
3,
199,
3,
221,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
221,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
221,
314,
2868,
2290,
2752,
12,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
221,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
221,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
221,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
221,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
3133,
421,
199,
318,
4907,
63,
475,
63,
697,
8,
888,
304,
2286,
340,
1056,
14,
1813,
14,
2520,
18,
647,
63,
7726,
63,
71,
3624,
26,
2728,
687,
26752,
14,
2828,
14,
71,
3624,
63,
25835,
492,
30465,
1637,
3041,
267,
687,
26752,
14,
2828,
14,
5286,
697,
492,
31424,
2846,
267,
2581,
14,
25835,
275,
30465,
1637,
3041,
8,
1069,
9,
267,
2581,
14,
5975,
275,
2581,
14,
4032,
275,
2581,
14,
25835,
2728,
1592,
275,
577,
748,
360,
71,
3624,
358,
267,
2351,
14,
2242,
8,
1069,
12,
1310,
12,
10293,
2846,
8,
1637,
14,
25835,
430,
258,
5493,
587,
26,
19242,
2728,
1592,
275,
577,
748,
8,
888,
14,
2242,
63,
2302,
9,
2286,
372,
1592,
421,
199,
318,
4205,
63,
1198,
8,
888,
304,
2286,
687,
26752,
14,
2537,
492,
18027,
2286,
6016,
275,
18027,
342,
22456,
327,
610,
3566,
272,
6016,
14,
1751,
14,
1000,
275,
1101,
14,
1198,
63,
1000,
503,
283,
15592,
14,
6799,
14,
957,
26,
29071,
7,
221,
327,
2195,
19810,
1654,
272,
6016,
14,
1751,
14,
8114,
275,
1101,
14,
1198,
63,
8114,
260,
327,
2195,
3031,
272,
6016,
14,
1751,
14,
2886,
275,
1101,
14,
1198,
63,
2886,
420,
327,
2195,
6235,
503,
488,
2286,
372,
6016,
421,
199,
318,
4205,
63,
1178,
8,
8473,
12,
1592,
12,
1101,
304,
2286,
687,
26752,
14,
2537,
492,
3590,
14821,
492,
2197,
2286,
327,
24,
14,
17,
14,
20,
8388,
9147,
3590,
2034,
31921,
272,
1790,
275,
3590,
8,
8473,
12,
697,
9,
420,
327,
11725,
15,
15846,
272,
1790,
14,
1751,
14,
18537,
63,
498,
275,
1101,
14,
2683,
63,
18537,
221,
327,
2544,
5627,
63,
5987,
342,
2286,
340,
1101,
14,
2683,
63,
765,
315,
788,
15049,
2565,
267,
1790,
14,
1751,
14,
3723,
63,
7011,
14,
740,
360,
2683,
358,
327,
5993,
2274,
2286,
327,
497,
20559,
334,
15351,
11991,
9,
272,
340,
1101,
14,
2683,
63,
765,
315,
788,
497,
20559,
2565,
267,
687,
26752,
14,
2537,
492,
799,
20559,
267,
1790,
14,
1751,
14,
20559,
275,
799,
20559,
8,
1069,
12,
1101,
14,
2761,
6182,
9518,
63,
3455,
12,
1101,
14,
2761,
6182,
9518,
63,
4239,
9,
258,
25979,
1592,
14,
4640,
63,
1224,
8,
267,
1790,
14,
1751,
14,
1224,
63,
751,
63,
354,
12,
267,
5024,
360,
2246,
63,
354,
297,
2582,
29,
3933,
12,
849,
534,
659,
267,
5024,
360,
2019,
63,
354,
297,
2582,
29,
3933,
12,
849,
534,
659,
267,
5024,
360,
2123,
297,
2582,
29,
3933,
12,
849,
4581,
3747,
29,
549,
395,
267,
5024,
360,
2060,
297,
283,
2060,
297,
2582,
29,
7736,
12,
1598,
12701,
29,
797,
12,
1768,
534,
6139,
659,
267,
5024,
360,
8054,
63,
498,
297,
2582,
29,
7736,
12,
1598,
17267,
29,
797,
12,
12701,
29,
797,
12,
849,
534,
659,
267,
5024,
360,
3958,
63,
2060,
63,
498,
297,
2582,
29,
7736,
12,
1598,
17267,
29,
797,
12,
12701,
29,
797,
12,
849,
534,
659,
267,
5024,
360,
8054,
63,
344,
297,
2582,
29,
7736,
12,
1598,
17267,
29,
797,
12,
12701,
29,
797,
12,
849,
534,
659,
267,
5024,
360,
3966,
63,
265,
297,
283,
2083,
297,
849,
29,
2083,
14,
2083,
14,
8136,
1062,
2116,
17267,
29,
797,
12,
11875,
29,
797,
395,
463,
267,
5024,
360,
2124,
63,
3671,
297,
2582,
29,
3933,
12,
15053,
29,
797,
12,
12701,
29,
797,
12,
221,
1598,
849,
4581,
1768,
29,
52,
360,
8493,
3855,
6208,
2476,
3777,
267,
12810,
29,
888,
14,
374,
63,
2246,
63,
521,
4960,
776,
2286,
3537,
63,
1178,
63,
1224,
275,
1592,
59,
1178,
14,
1751,
14,
1224,
63,
751,
63,
354,
61,
327,
664,
314,
3537,
63,
1178,
63,
1224,
272,
3537,
63,
1178,
63,
1224,
14,
2246,
63,
354,
14,
6537,
275,
2281,
63,
4609,
63,
13993,
8,
705,
63,
1188,
29,
1178,
14,
3431,
14,
374,
63,
1667,
9,
272,
3537,
63,
1178,
63,
1224,
14,
2019,
63,
354,
14,
6537,
275,
221,
2281,
63,
4609,
63,
13993,
8,
705,
63,
1188,
29,
1178,
14,
3431,
14,
374,
63,
1667,
9,
272,
3537,
63,
1178,
63,
1224,
14,
2060,
14,
6537,
275,
359,
19079,
8,
498,
29,
1178,
14,
1751,
14,
18537,
63,
498,
1874,
272,
3537,
63,
1178,
63,
1224,
14,
2123,
14
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1010,
4715,
23583,
14,
1010,
4715,
15424,
14,
29554,
477,
27813,
315,
6001,
18,
647,
22545,
199,
3,
11666,
26,
1455,
921,
1544,
14,
3615,
867,
18,
2915,
14,
957,
221,
199,
3,
199,
3,
1898,
334,
67,
9,
7129,
22578,
368,
12,
510,
371,
320,
603,
580,
13676,
78,
221,
199,
3,
199,
3,
844,
5495,
26,
14629,
12,
1696,
1684,
844,
373,
14,
499,
14,
16,
199,
3,
844,
6646,
26,
9750,
1905,
7046,
4654,
2854,
15980,
650,
14,
16,
221,
199,
3,
199,
3,
6121,
5684,
26,
20732,
14,
2520,
18,
647,
14,
957,
221,
199,
3,
3777,
503,
25031,
26,
1455,
921,
2634,
14,
3098,
14,
957,
15,
923,
15,
2520,
18,
647,
221,
199,
3,
4483,
1455,
921,
2634,
14,
3098,
14,
957,
15,
923,
15,
2520,
18,
647,
13,
527,
85,
17832,
257,
199,
3,
199,
3,
199,
3,
221,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
221,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
221,
314,
2868,
2290,
2752,
12,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
221,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
221,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
221,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
221,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
3133,
421,
199,
318,
4907,
63,
475,
63,
697,
8,
888,
304,
2286,
340,
1056,
14,
1813,
14,
2520,
18,
647,
63,
7726,
63,
71,
3624,
26,
2728,
687,
26752,
14,
2828,
14,
71,
3624,
63,
25835,
492,
30465,
1637,
3041,
267,
687,
26752,
14,
2828,
14,
5286,
697,
492,
31424,
2846,
267,
2581,
14,
25835,
275,
30465,
1637,
3041,
8,
1069,
9,
267,
2581,
14,
5975,
275,
2581,
14,
4032,
275,
2581,
14,
25835,
2728,
1592,
275,
577,
748,
360,
71,
3624,
358,
267,
2351,
14,
2242,
8,
1069,
12,
1310,
12,
10293,
2846,
8,
1637,
14,
25835,
430,
258,
5493,
587,
26,
19242,
2728,
1592,
275,
577,
748,
8,
888,
14,
2242,
63,
2302,
9,
2286,
372,
1592,
421,
199,
318,
4205,
63,
1198,
8,
888,
304,
2286,
687,
26752,
14,
2537,
492,
18027,
2286,
6016,
275,
18027,
342,
22456,
327,
610,
3566,
272,
6016,
14,
1751,
14,
1000,
275,
1101,
14,
1198,
63,
1000,
503,
283,
15592,
14,
6799,
14,
957,
26,
29071,
7,
221,
327,
2195,
19810,
1654,
272,
6016,
14,
1751,
14,
8114,
275,
1101,
14,
1198,
63,
8114,
260,
327,
2195,
3031,
272,
6016,
14,
1751,
14,
2886,
275,
1101,
14,
1198,
63,
2886,
420,
327,
2195,
6235,
503,
488,
2286,
372,
6016,
421,
199,
318,
4205,
63,
1178,
8,
8473,
12,
1592,
12,
1101,
304,
2286,
687,
26752,
14,
2537,
492,
3590,
14821,
492,
2197,
2286,
327,
24,
14,
17,
14,
20,
8388,
9147,
3590,
2034,
31921,
272,
1790,
275,
3590,
8,
8473,
12,
697,
9,
420,
327,
11725,
15,
15846,
272,
1790,
14,
1751,
14,
18537,
63,
498,
275,
1101,
14,
2683,
63,
18537,
221,
327,
2544,
5627,
63,
5987,
342,
2286,
340,
1101,
14,
2683,
63,
765,
315,
788,
15049,
2565,
267,
1790,
14,
1751,
14,
3723,
63,
7011,
14,
740,
360,
2683,
358,
327,
5993,
2274,
2286,
327,
497,
20559,
334,
15351,
11991,
9,
272,
340,
1101,
14,
2683,
63,
765,
315,
788,
497,
20559,
2565,
267,
687,
26752,
14,
2537,
492,
799,
20559,
267,
1790,
14,
1751,
14,
20559,
275,
799,
20559,
8,
1069,
12,
1101,
14,
2761,
6182,
9518,
63,
3455,
12,
1101,
14,
2761,
6182,
9518,
63,
4239,
9,
258,
25979,
1592,
14,
4640,
63,
1224,
8,
267,
1790,
14,
1751,
14,
1224,
63,
751,
63,
354,
12,
267,
5024,
360,
2246,
63,
354,
297,
2582,
29,
3933,
12,
849,
534,
659,
267,
5024,
360,
2019,
63,
354,
297,
2582,
29,
3933,
12,
849,
534,
659,
267,
5024,
360,
2123,
297,
2582,
29,
3933,
12,
849,
4581,
3747,
29,
549,
395,
267,
5024,
360,
2060,
297,
283,
2060,
297,
2582,
29,
7736,
12,
1598,
12701,
29,
797,
12,
1768,
534,
6139,
659,
267,
5024,
360,
8054,
63,
498,
297,
2582,
29,
7736,
12,
1598,
17267,
29,
797,
12,
12701,
29,
797,
12,
849,
534,
659,
267,
5024,
360,
3958,
63,
2060,
63,
498,
297,
2582,
29,
7736,
12,
1598,
17267,
29,
797,
12,
12701,
29,
797,
12,
849,
534,
659,
267,
5024,
360,
8054,
63,
344,
297,
2582,
29,
7736,
12,
1598,
17267,
29,
797,
12,
12701,
29,
797,
12,
849,
534,
659,
267,
5024,
360,
3966,
63,
265,
297,
283,
2083,
297,
849,
29,
2083,
14,
2083,
14,
8136,
1062,
2116,
17267,
29,
797,
12,
11875,
29,
797,
395,
463,
267,
5024,
360,
2124,
63,
3671,
297,
2582,
29,
3933,
12,
15053,
29,
797,
12,
12701,
29,
797,
12,
221,
1598,
849,
4581,
1768,
29,
52,
360,
8493,
3855,
6208,
2476,
3777,
267,
12810,
29,
888,
14,
374,
63,
2246,
63,
521,
4960,
776,
2286,
3537,
63,
1178,
63,
1224,
275,
1592,
59,
1178,
14,
1751,
14,
1224,
63,
751,
63,
354,
61,
327,
664,
314,
3537,
63,
1178,
63,
1224,
272,
3537,
63,
1178,
63,
1224,
14,
2246,
63,
354,
14,
6537,
275,
2281,
63,
4609,
63,
13993,
8,
705,
63,
1188,
29,
1178,
14,
3431,
14,
374,
63,
1667,
9,
272,
3537,
63,
1178,
63,
1224,
14,
2019,
63,
354,
14,
6537,
275,
221,
2281,
63,
4609,
63,
13993,
8,
705,
63,
1188,
29,
1178,
14,
3431,
14,
374,
63,
1667,
9,
272,
3537,
63,
1178,
63,
1224,
14,
2060,
14,
6537,
275,
359,
19079,
8,
498,
29,
1178,
14,
1751,
14,
18537,
63,
498,
1874,
272,
3537,
63,
1178,
63,
1224,
14,
2123,
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,
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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
] |
aveshagarwal/openshift-ansible
|
roles/lib_openshift/library/oc_route.py
|
18
|
65753
|
#!/usr/bin/env python
# pylint: disable=missing-docstring
# flake8: noqa: T001
# ___ ___ _ _ ___ ___ _ _____ ___ ___
# / __| __| \| | __| _ \ /_\_ _| __| \
# | (_ | _|| .` | _|| / / _ \| | | _|| |) |
# \___|___|_|\_|___|_|_\/_/_\_\_|_|___|___/_ _____
# | \ / _ \ | \| |/ _ \_ _| | __| \_ _|_ _|
# | |) | (_) | | .` | (_) || | | _|| |) | | | |
# |___/ \___/ |_|\_|\___/ |_| |___|___/___| |_|
#
# Copyright 2016 Red Hat, Inc. and/or its affiliates
# and other contributors as indicated by the @author tags.
#
# 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.
#
# -*- -*- -*- Begin included fragment: lib/import.py -*- -*- -*-
'''
OpenShiftCLI class that wraps the oc commands in a subprocess
'''
# pylint: disable=too-many-lines
from __future__ import print_function
import atexit
import copy
import fcntl
import json
import time
import os
import re
import shutil
import subprocess
import tempfile
# pylint: disable=import-error
try:
import ruamel.yaml as yaml
except ImportError:
import yaml
from ansible.module_utils.basic import AnsibleModule
# -*- -*- -*- End included fragment: lib/import.py -*- -*- -*-
# -*- -*- -*- Begin included fragment: doc/route -*- -*- -*-
DOCUMENTATION = '''
---
module: oc_route
short_description: Create, modify, and idempotently manage openshift routes.
description:
- Manage openshift route objects programmatically.
options:
state:
description:
- State represents whether to create, modify, delete, or list
required: true
default: present
choices: ["present", "absent", "list"]
aliases: []
kubeconfig:
description:
- The path for the kubeconfig file to use for authentication
required: false
default: /etc/origin/master/admin.kubeconfig
aliases: []
debug:
description:
- Turn on debug output.
required: false
default: False
aliases: []
name:
description:
- Name of the object that is being queried.
required: false
default: None
aliases: []
namespace:
description:
- The namespace where the object lives.
required: false
default: str
aliases: []
labels:
description:
- The labels to apply on the route
required: false
default: None
aliases: []
tls_termination:
description:
- The options for termination. e.g. reencrypt
required: false
default: None
aliases: []
dest_cacert_path:
description:
- The path to the dest_cacert
required: false
default: None
aliases: []
cacert_path:
description:
- The path to the cacert
required: false
default: None
aliases: []
cert_path:
description:
- The path to the cert
required: false
default: None
aliases: []
key_path:
description:
- The path to the key
required: false
default: None
aliases: []
dest_cacert_content:
description:
- The dest_cacert content
required: false
default: None
aliases: []
cacert_content:
description:
- The cacert content
required: false
default: None
aliases: []
cert_content:
description:
- The cert content
required: false
default: None
aliases: []
service_name:
description:
- The name of the service that this route points to.
required: false
default: None
aliases: []
host:
description:
- The host that the route will use. e.g. myapp.x.y.z
required: false
default: None
aliases: []
port:
description:
- The Name of the service port or number of the container port the route will route traffic to
required: false
default: None
aliases: []
author:
- "Kenny Woodson <kwoodson@redhat.com>"
extends_documentation_fragment: []
'''
EXAMPLES = '''
- name: Configure certificates for reencrypt route
oc_route:
name: myapproute
namespace: awesomeapp
cert_path: "/etc/origin/master/named_certificates/myapp_cert
key_path: "/etc/origin/master/named_certificates/myapp_key
cacert_path: "/etc/origin/master/named_certificates/myapp_cacert
dest_cacert_content: "{{ dest_cacert_content }}"
service_name: myapp_php
host: myapp.awesomeapp.openshift.com
tls_termination: reencrypt
run_once: true
'''
# -*- -*- -*- End included fragment: doc/route -*- -*- -*-
# -*- -*- -*- Begin included fragment: ../../lib_utils/src/class/yedit.py -*- -*- -*-
class YeditException(Exception): # pragma: no cover
''' Exception class for Yedit '''
pass
# pylint: disable=too-many-public-methods,too-many-instance-attributes
class Yedit(object): # pragma: no cover
''' Class to modify yaml files '''
re_valid_key = r"(((\[-?\d+\])|([0-9a-zA-Z%s/_-]+)).?)+$"
re_key = r"(?:\[(-?\d+)\])|([0-9a-zA-Z{}/_-]+)"
com_sep = set(['.', '#', '|', ':'])
# pylint: disable=too-many-arguments
def __init__(self,
filename=None,
content=None,
content_type='yaml',
separator='.',
backup_ext=None,
backup=False):
self.content = content
self._separator = separator
self.filename = filename
self.__yaml_dict = content
self.content_type = content_type
self.backup = backup
if backup_ext is None:
self.backup_ext = ".{}".format(time.strftime("%Y%m%dT%H%M%S"))
else:
self.backup_ext = backup_ext
self.load(content_type=self.content_type)
if self.__yaml_dict is None:
self.__yaml_dict = {}
@property
def separator(self):
''' getter method for separator '''
return self._separator
@separator.setter
def separator(self, inc_sep):
''' setter method for separator '''
self._separator = inc_sep
@property
def yaml_dict(self):
''' getter method for yaml_dict '''
return self.__yaml_dict
@yaml_dict.setter
def yaml_dict(self, value):
''' setter method for yaml_dict '''
self.__yaml_dict = value
@staticmethod
def parse_key(key, sep='.'):
'''parse the key allowing the appropriate separator'''
common_separators = list(Yedit.com_sep - set([sep]))
return re.findall(Yedit.re_key.format(''.join(common_separators)), key)
@staticmethod
def valid_key(key, sep='.'):
'''validate the incoming key'''
common_separators = list(Yedit.com_sep - set([sep]))
if not re.match(Yedit.re_valid_key.format(''.join(common_separators)), key):
return False
return True
# pylint: disable=too-many-return-statements,too-many-branches
@staticmethod
def remove_entry(data, key, index=None, value=None, sep='.'):
''' remove data at location key '''
if key == '' and isinstance(data, dict):
if value is not None:
data.pop(value)
elif index is not None:
raise YeditException("remove_entry for a dictionary does not have an index {}".format(index))
else:
data.clear()
return True
elif key == '' and isinstance(data, list):
ind = None
if value is not None:
try:
ind = data.index(value)
except ValueError:
return False
elif index is not None:
ind = index
else:
del data[:]
if ind is not None:
data.pop(ind)
return True
if not (key and Yedit.valid_key(key, sep)) and \
isinstance(data, (list, dict)):
return None
key_indexes = Yedit.parse_key(key, sep)
for arr_ind, dict_key in key_indexes[:-1]:
if dict_key and isinstance(data, dict):
data = data.get(dict_key)
elif (arr_ind and isinstance(data, list) and
int(arr_ind) <= len(data) - 1):
data = data[int(arr_ind)]
else:
return None
# process last index for remove
# expected list entry
if key_indexes[-1][0]:
if isinstance(data, list) and int(key_indexes[-1][0]) <= len(data) - 1: # noqa: E501
del data[int(key_indexes[-1][0])]
return True
# expected dict entry
elif key_indexes[-1][1]:
if isinstance(data, dict):
del data[key_indexes[-1][1]]
return True
@staticmethod
def add_entry(data, key, item=None, sep='.'):
''' Get an item from a dictionary with key notation a.b.c
d = {'a': {'b': 'c'}}}
key = a#b
return c
'''
if key == '':
pass
elif (not (key and Yedit.valid_key(key, sep)) and
isinstance(data, (list, dict))):
return None
key_indexes = Yedit.parse_key(key, sep)
for arr_ind, dict_key in key_indexes[:-1]:
if dict_key:
if isinstance(data, dict) and dict_key in data and data[dict_key]: # noqa: E501
data = data[dict_key]
continue
elif data and not isinstance(data, dict):
raise YeditException("Unexpected item type found while going through key " +
"path: {} (at key: {})".format(key, dict_key))
data[dict_key] = {}
data = data[dict_key]
elif (arr_ind and isinstance(data, list) and
int(arr_ind) <= len(data) - 1):
data = data[int(arr_ind)]
else:
raise YeditException("Unexpected item type found while going through key path: {}".format(key))
if key == '':
data = item
# process last index for add
# expected list entry
elif key_indexes[-1][0] and isinstance(data, list) and int(key_indexes[-1][0]) <= len(data) - 1: # noqa: E501
data[int(key_indexes[-1][0])] = item
# expected dict entry
elif key_indexes[-1][1] and isinstance(data, dict):
data[key_indexes[-1][1]] = item
# didn't add/update to an existing list, nor add/update key to a dict
# so we must have been provided some syntax like a.b.c[<int>] = "data" for a
# non-existent array
else:
raise YeditException("Error adding to object at path: {}".format(key))
return data
@staticmethod
def get_entry(data, key, sep='.'):
''' Get an item from a dictionary with key notation a.b.c
d = {'a': {'b': 'c'}}}
key = a.b
return c
'''
if key == '':
pass
elif (not (key and Yedit.valid_key(key, sep)) and
isinstance(data, (list, dict))):
return None
key_indexes = Yedit.parse_key(key, sep)
for arr_ind, dict_key in key_indexes:
if dict_key and isinstance(data, dict):
data = data.get(dict_key)
elif (arr_ind and isinstance(data, list) and
int(arr_ind) <= len(data) - 1):
data = data[int(arr_ind)]
else:
return None
return data
@staticmethod
def _write(filename, contents):
''' Actually write the file contents to disk. This helps with mocking. '''
tmp_filename = filename + '.yedit'
with open(tmp_filename, 'w') as yfd:
fcntl.flock(yfd, fcntl.LOCK_EX | fcntl.LOCK_NB)
yfd.write(contents)
fcntl.flock(yfd, fcntl.LOCK_UN)
os.rename(tmp_filename, filename)
def write(self):
''' write to file '''
if not self.filename:
raise YeditException('Please specify a filename.')
if self.backup and self.file_exists():
shutil.copy(self.filename, '{}{}'.format(self.filename, self.backup_ext))
# Try to set format attributes if supported
try:
self.yaml_dict.fa.set_block_style()
except AttributeError:
pass
# Try to use RoundTripDumper if supported.
if self.content_type == 'yaml':
try:
Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
except AttributeError:
Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False))
elif self.content_type == 'json':
Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True))
else:
raise YeditException('Unsupported content_type: {}.'.format(self.content_type) +
'Please specify a content_type of yaml or json.')
return (True, self.yaml_dict)
def read(self):
''' read from file '''
# check if it exists
if self.filename is None or not self.file_exists():
return None
contents = None
with open(self.filename) as yfd:
contents = yfd.read()
return contents
def file_exists(self):
''' return whether file exists '''
if os.path.exists(self.filename):
return True
return False
def load(self, content_type='yaml'):
''' return yaml file '''
contents = self.read()
if not contents and not self.content:
return None
if self.content:
if isinstance(self.content, dict):
self.yaml_dict = self.content
return self.yaml_dict
elif isinstance(self.content, str):
contents = self.content
# check if it is yaml
try:
if content_type == 'yaml' and contents:
# Try to set format attributes if supported
try:
self.yaml_dict.fa.set_block_style()
except AttributeError:
pass
# Try to use RoundTripLoader if supported.
try:
self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
except AttributeError:
self.yaml_dict = yaml.safe_load(contents)
# Try to set format attributes if supported
try:
self.yaml_dict.fa.set_block_style()
except AttributeError:
pass
elif content_type == 'json' and contents:
self.yaml_dict = json.loads(contents)
except yaml.YAMLError as err:
# Error loading yaml or json
raise YeditException('Problem with loading yaml file. {}'.format(err))
return self.yaml_dict
def get(self, key):
''' get a specified key'''
try:
entry = Yedit.get_entry(self.yaml_dict, key, self.separator)
except KeyError:
entry = None
return entry
def pop(self, path, key_or_item):
''' remove a key, value pair from a dict or an item for a list'''
try:
entry = Yedit.get_entry(self.yaml_dict, path, self.separator)
except KeyError:
entry = None
if entry is None:
return (False, self.yaml_dict)
if isinstance(entry, dict):
# AUDIT:maybe-no-member makes sense due to fuzzy types
# pylint: disable=maybe-no-member
if key_or_item in entry:
entry.pop(key_or_item)
return (True, self.yaml_dict)
return (False, self.yaml_dict)
elif isinstance(entry, list):
# AUDIT:maybe-no-member makes sense due to fuzzy types
# pylint: disable=maybe-no-member
ind = None
try:
ind = entry.index(key_or_item)
except ValueError:
return (False, self.yaml_dict)
entry.pop(ind)
return (True, self.yaml_dict)
return (False, self.yaml_dict)
def delete(self, path, index=None, value=None):
''' remove path from a dict'''
try:
entry = Yedit.get_entry(self.yaml_dict, path, self.separator)
except KeyError:
entry = None
if entry is None:
return (False, self.yaml_dict)
result = Yedit.remove_entry(self.yaml_dict, path, index, value, self.separator)
if not result:
return (False, self.yaml_dict)
return (True, self.yaml_dict)
def exists(self, path, value):
''' check if value exists at path'''
try:
entry = Yedit.get_entry(self.yaml_dict, path, self.separator)
except KeyError:
entry = None
if isinstance(entry, list):
if value in entry:
return True
return False
elif isinstance(entry, dict):
if isinstance(value, dict):
rval = False
for key, val in value.items():
if entry[key] != val:
rval = False
break
else:
rval = True
return rval
return value in entry
return entry == value
def append(self, path, value):
'''append value to a list'''
try:
entry = Yedit.get_entry(self.yaml_dict, path, self.separator)
except KeyError:
entry = None
if entry is None:
self.put(path, [])
entry = Yedit.get_entry(self.yaml_dict, path, self.separator)
if not isinstance(entry, list):
return (False, self.yaml_dict)
# AUDIT:maybe-no-member makes sense due to loading data from
# a serialized format.
# pylint: disable=maybe-no-member
entry.append(value)
return (True, self.yaml_dict)
# pylint: disable=too-many-arguments
def update(self, path, value, index=None, curr_value=None):
''' put path, value into a dict '''
try:
entry = Yedit.get_entry(self.yaml_dict, path, self.separator)
except KeyError:
entry = None
if isinstance(entry, dict):
# AUDIT:maybe-no-member makes sense due to fuzzy types
# pylint: disable=maybe-no-member
if not isinstance(value, dict):
raise YeditException('Cannot replace key, value entry in dict with non-dict type. ' +
'value=[{}] type=[{}]'.format(value, type(value)))
entry.update(value)
return (True, self.yaml_dict)
elif isinstance(entry, list):
# AUDIT:maybe-no-member makes sense due to fuzzy types
# pylint: disable=maybe-no-member
ind = None
if curr_value:
try:
ind = entry.index(curr_value)
except ValueError:
return (False, self.yaml_dict)
elif index is not None:
ind = index
if ind is not None and entry[ind] != value:
entry[ind] = value
return (True, self.yaml_dict)
# see if it exists in the list
try:
ind = entry.index(value)
except ValueError:
# doesn't exist, append it
entry.append(value)
return (True, self.yaml_dict)
# already exists, return
if ind is not None:
return (False, self.yaml_dict)
return (False, self.yaml_dict)
def put(self, path, value):
''' put path, value into a dict '''
try:
entry = Yedit.get_entry(self.yaml_dict, path, self.separator)
except KeyError:
entry = None
if entry == value:
return (False, self.yaml_dict)
# deepcopy didn't work
# Try to use ruamel.yaml and fallback to pyyaml
try:
tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
default_flow_style=False),
yaml.RoundTripLoader)
except AttributeError:
tmp_copy = copy.deepcopy(self.yaml_dict)
# set the format attributes if available
try:
tmp_copy.fa.set_block_style()
except AttributeError:
pass
result = Yedit.add_entry(tmp_copy, path, value, self.separator)
if result is None:
return (False, self.yaml_dict)
# When path equals "" it is a special case.
# "" refers to the root of the document
# Only update the root path (entire document) when its a list or dict
if path == '':
if isinstance(result, list) or isinstance(result, dict):
self.yaml_dict = result
return (True, self.yaml_dict)
return (False, self.yaml_dict)
self.yaml_dict = tmp_copy
return (True, self.yaml_dict)
def create(self, path, value):
''' create a yaml file '''
if not self.file_exists():
# deepcopy didn't work
# Try to use ruamel.yaml and fallback to pyyaml
try:
tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
default_flow_style=False),
yaml.RoundTripLoader)
except AttributeError:
tmp_copy = copy.deepcopy(self.yaml_dict)
# set the format attributes if available
try:
tmp_copy.fa.set_block_style()
except AttributeError:
pass
result = Yedit.add_entry(tmp_copy, path, value, self.separator)
if result is not None:
self.yaml_dict = tmp_copy
return (True, self.yaml_dict)
return (False, self.yaml_dict)
@staticmethod
def get_curr_value(invalue, val_type):
'''return the current value'''
if invalue is None:
return None
curr_value = invalue
if val_type == 'yaml':
curr_value = yaml.safe_load(str(invalue))
elif val_type == 'json':
curr_value = json.loads(invalue)
return curr_value
@staticmethod
def parse_value(inc_value, vtype=''):
'''determine value type passed'''
true_bools = ['y', 'Y', 'yes', 'Yes', 'YES', 'true', 'True', 'TRUE',
'on', 'On', 'ON', ]
false_bools = ['n', 'N', 'no', 'No', 'NO', 'false', 'False', 'FALSE',
'off', 'Off', 'OFF']
# It came in as a string but you didn't specify value_type as string
# we will convert to bool if it matches any of the above cases
if isinstance(inc_value, str) and 'bool' in vtype:
if inc_value not in true_bools and inc_value not in false_bools:
raise YeditException('Not a boolean type. str=[{}] vtype=[{}]'.format(inc_value, vtype))
elif isinstance(inc_value, bool) and 'str' in vtype:
inc_value = str(inc_value)
# There is a special case where '' will turn into None after yaml loading it so skip
if isinstance(inc_value, str) and inc_value == '':
pass
# If vtype is not str then go ahead and attempt to yaml load it.
elif isinstance(inc_value, str) and 'str' not in vtype:
try:
inc_value = yaml.safe_load(inc_value)
except Exception:
raise YeditException('Could not determine type of incoming value. ' +
'value=[{}] vtype=[{}]'.format(type(inc_value), vtype))
return inc_value
@staticmethod
def process_edits(edits, yamlfile):
'''run through a list of edits and process them one-by-one'''
results = []
for edit in edits:
value = Yedit.parse_value(edit['value'], edit.get('value_type', ''))
if edit.get('action') == 'update':
# pylint: disable=line-too-long
curr_value = Yedit.get_curr_value(
Yedit.parse_value(edit.get('curr_value')),
edit.get('curr_value_format'))
rval = yamlfile.update(edit['key'],
value,
edit.get('index'),
curr_value)
elif edit.get('action') == 'append':
rval = yamlfile.append(edit['key'], value)
else:
rval = yamlfile.put(edit['key'], value)
if rval[0]:
results.append({'key': edit['key'], 'edit': rval[1]})
return {'changed': len(results) > 0, 'results': results}
# pylint: disable=too-many-return-statements,too-many-branches
@staticmethod
def run_ansible(params):
'''perform the idempotent crud operations'''
yamlfile = Yedit(filename=params['src'],
backup=params['backup'],
content_type=params['content_type'],
backup_ext=params['backup_ext'],
separator=params['separator'])
state = params['state']
if params['src']:
rval = yamlfile.load()
if yamlfile.yaml_dict is None and state != 'present':
return {'failed': True,
'msg': 'Error opening file [{}]. Verify that the '.format(params['src']) +
'file exists, that it is has correct permissions, and is valid yaml.'}
if state == 'list':
if params['content']:
content = Yedit.parse_value(params['content'], params['content_type'])
yamlfile.yaml_dict = content
if params['key']:
rval = yamlfile.get(params['key'])
return {'changed': False, 'result': rval, 'state': state}
elif state == 'absent':
if params['content']:
content = Yedit.parse_value(params['content'], params['content_type'])
yamlfile.yaml_dict = content
if params['update']:
rval = yamlfile.pop(params['key'], params['value'])
else:
rval = yamlfile.delete(params['key'], params['index'], params['value'])
if rval[0] and params['src']:
yamlfile.write()
return {'changed': rval[0], 'result': rval[1], 'state': state}
elif state == 'present':
# check if content is different than what is in the file
if params['content']:
content = Yedit.parse_value(params['content'], params['content_type'])
# We had no edits to make and the contents are the same
if yamlfile.yaml_dict == content and \
params['value'] is None:
return {'changed': False, 'result': yamlfile.yaml_dict, 'state': state}
yamlfile.yaml_dict = content
# If we were passed a key, value then
# we enapsulate it in a list and process it
# Key, Value passed to the module : Converted to Edits list #
edits = []
_edit = {}
if params['value'] is not None:
_edit['value'] = params['value']
_edit['value_type'] = params['value_type']
_edit['key'] = params['key']
if params['update']:
_edit['action'] = 'update'
_edit['curr_value'] = params['curr_value']
_edit['curr_value_format'] = params['curr_value_format']
_edit['index'] = params['index']
elif params['append']:
_edit['action'] = 'append'
edits.append(_edit)
elif params['edits'] is not None:
edits = params['edits']
if edits:
results = Yedit.process_edits(edits, yamlfile)
# if there were changes and a src provided to us we need to write
if results['changed'] and params['src']:
yamlfile.write()
return {'changed': results['changed'], 'result': results['results'], 'state': state}
# no edits to make
if params['src']:
# pylint: disable=redefined-variable-type
rval = yamlfile.write()
return {'changed': rval[0],
'result': rval[1],
'state': state}
# We were passed content but no src, key or value, or edits. Return contents in memory
return {'changed': False, 'result': yamlfile.yaml_dict, 'state': state}
return {'failed': True, 'msg': 'Unkown state passed'}
# -*- -*- -*- End included fragment: ../../lib_utils/src/class/yedit.py -*- -*- -*-
# -*- -*- -*- Begin included fragment: lib/base.py -*- -*- -*-
# pylint: disable=too-many-lines
# noqa: E301,E302,E303,T001
class OpenShiftCLIError(Exception):
'''Exception class for openshiftcli'''
pass
ADDITIONAL_PATH_LOOKUPS = ['/usr/local/bin', os.path.expanduser('~/bin')]
def locate_oc_binary():
''' Find and return oc binary file '''
# https://github.com/openshift/openshift-ansible/issues/3410
# oc can be in /usr/local/bin in some cases, but that may not
# be in $PATH due to ansible/sudo
paths = os.environ.get("PATH", os.defpath).split(os.pathsep) + ADDITIONAL_PATH_LOOKUPS
oc_binary = 'oc'
# Use shutil.which if it is available, otherwise fallback to a naive path search
try:
which_result = shutil.which(oc_binary, path=os.pathsep.join(paths))
if which_result is not None:
oc_binary = which_result
except AttributeError:
for path in paths:
if os.path.exists(os.path.join(path, oc_binary)):
oc_binary = os.path.join(path, oc_binary)
break
return oc_binary
# pylint: disable=too-few-public-methods
class OpenShiftCLI(object):
''' Class to wrap the command line tools '''
def __init__(self,
namespace,
kubeconfig='/etc/origin/master/admin.kubeconfig',
verbose=False,
all_namespaces=False):
''' Constructor for OpenshiftCLI '''
self.namespace = namespace
self.verbose = verbose
self.kubeconfig = Utils.create_tmpfile_copy(kubeconfig)
self.all_namespaces = all_namespaces
self.oc_binary = locate_oc_binary()
# Pylint allows only 5 arguments to be passed.
# pylint: disable=too-many-arguments
def _replace_content(self, resource, rname, content, edits=None, force=False, sep='.'):
''' replace the current object with the content '''
res = self._get(resource, rname)
if not res['results']:
return res
fname = Utils.create_tmpfile(rname + '-')
yed = Yedit(fname, res['results'][0], separator=sep)
updated = False
if content is not None:
changes = []
for key, value in content.items():
changes.append(yed.put(key, value))
if any([change[0] for change in changes]):
updated = True
elif edits is not None:
results = Yedit.process_edits(edits, yed)
if results['changed']:
updated = True
if updated:
yed.write()
atexit.register(Utils.cleanup, [fname])
return self._replace(fname, force)
return {'returncode': 0, 'updated': False}
def _replace(self, fname, force=False):
'''replace the current object with oc replace'''
# We are removing the 'resourceVersion' to handle
# a race condition when modifying oc objects
yed = Yedit(fname)
results = yed.delete('metadata.resourceVersion')
if results[0]:
yed.write()
cmd = ['replace', '-f', fname]
if force:
cmd.append('--force')
return self.openshift_cmd(cmd)
def _create_from_content(self, rname, content):
'''create a temporary file and then call oc create on it'''
fname = Utils.create_tmpfile(rname + '-')
yed = Yedit(fname, content=content)
yed.write()
atexit.register(Utils.cleanup, [fname])
return self._create(fname)
def _create(self, fname):
'''call oc create on a filename'''
return self.openshift_cmd(['create', '-f', fname])
def _delete(self, resource, name=None, selector=None):
'''call oc delete on a resource'''
cmd = ['delete', resource]
if selector is not None:
cmd.append('--selector={}'.format(selector))
elif name is not None:
cmd.append(name)
else:
raise OpenShiftCLIError('Either name or selector is required when calling delete.')
return self.openshift_cmd(cmd)
def _process(self, template_name, create=False, params=None, template_data=None): # noqa: E501
'''process a template
template_name: the name of the template to process
create: whether to send to oc create after processing
params: the parameters for the template
template_data: the incoming template's data; instead of a file
'''
cmd = ['process']
if template_data:
cmd.extend(['-f', '-'])
else:
cmd.append(template_name)
if params:
param_str = ["{}={}".format(key, str(value).replace("'", r'"')) for key, value in params.items()]
cmd.append('-p')
cmd.extend(param_str)
results = self.openshift_cmd(cmd, output=True, input_data=template_data)
if results['returncode'] != 0 or not create:
return results
fname = Utils.create_tmpfile(template_name + '-')
yed = Yedit(fname, results['results'])
yed.write()
atexit.register(Utils.cleanup, [fname])
return self.openshift_cmd(['create', '-f', fname])
def _get(self, resource, name=None, selector=None, field_selector=None):
'''return a resource by name '''
cmd = ['get', resource]
if selector is not None:
cmd.append('--selector={}'.format(selector))
if field_selector is not None:
cmd.append('--field-selector={}'.format(field_selector))
# Name cannot be used with selector or field_selector.
if selector is None and field_selector is None and name is not None:
cmd.append(name)
cmd.extend(['-o', 'json'])
rval = self.openshift_cmd(cmd, output=True)
# Ensure results are retuned in an array
if 'items' in rval:
rval['results'] = rval['items']
elif not isinstance(rval['results'], list):
rval['results'] = [rval['results']]
return rval
def _schedulable(self, node=None, selector=None, schedulable=True):
''' perform oadm manage-node scheduable '''
cmd = ['manage-node']
if node:
cmd.extend(node)
else:
cmd.append('--selector={}'.format(selector))
cmd.append('--schedulable={}'.format(schedulable))
return self.openshift_cmd(cmd, oadm=True, output=True, output_type='raw') # noqa: E501
def _list_pods(self, node=None, selector=None, pod_selector=None):
''' perform oadm list pods
node: the node in which to list pods
selector: the label selector filter if provided
pod_selector: the pod selector filter if provided
'''
cmd = ['manage-node']
if node:
cmd.extend(node)
else:
cmd.append('--selector={}'.format(selector))
if pod_selector:
cmd.append('--pod-selector={}'.format(pod_selector))
cmd.extend(['--list-pods', '-o', 'json'])
return self.openshift_cmd(cmd, oadm=True, output=True, output_type='raw')
# pylint: disable=too-many-arguments
def _evacuate(self, node=None, selector=None, pod_selector=None, dry_run=False, grace_period=None, force=False):
''' perform oadm manage-node evacuate '''
cmd = ['manage-node']
if node:
cmd.extend(node)
else:
cmd.append('--selector={}'.format(selector))
if dry_run:
cmd.append('--dry-run')
if pod_selector:
cmd.append('--pod-selector={}'.format(pod_selector))
if grace_period:
cmd.append('--grace-period={}'.format(int(grace_period)))
if force:
cmd.append('--force')
cmd.append('--evacuate')
return self.openshift_cmd(cmd, oadm=True, output=True, output_type='raw')
def _version(self):
''' return the openshift version'''
return self.openshift_cmd(['version'], output=True, output_type='raw')
def _import_image(self, url=None, name=None, tag=None):
''' perform image import '''
cmd = ['import-image']
image = '{0}'.format(name)
if tag:
image += ':{0}'.format(tag)
cmd.append(image)
if url:
cmd.append('--from={0}/{1}'.format(url, image))
cmd.append('-n{0}'.format(self.namespace))
cmd.append('--confirm')
return self.openshift_cmd(cmd)
def _run(self, cmds, input_data):
''' Actually executes the command. This makes mocking easier. '''
curr_env = os.environ.copy()
curr_env.update({'KUBECONFIG': self.kubeconfig})
proc = subprocess.Popen(cmds,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=curr_env)
stdout, stderr = proc.communicate(input_data)
return proc.returncode, stdout.decode('utf-8'), stderr.decode('utf-8')
# pylint: disable=too-many-arguments,too-many-branches
def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None):
'''Base command for oc '''
cmds = [self.oc_binary]
if oadm:
cmds.append('adm')
cmds.extend(cmd)
if self.all_namespaces:
cmds.extend(['--all-namespaces'])
elif self.namespace is not None and self.namespace.lower() not in ['none', 'emtpy']: # E501
cmds.extend(['-n', self.namespace])
if self.verbose:
print(' '.join(cmds))
try:
returncode, stdout, stderr = self._run(cmds, input_data)
except OSError as ex:
returncode, stdout, stderr = 1, '', 'Failed to execute {}: {}'.format(subprocess.list2cmdline(cmds), ex)
rval = {"returncode": returncode,
"cmd": ' '.join(cmds)}
if output_type == 'json':
rval['results'] = {}
if output and stdout:
try:
rval['results'] = json.loads(stdout)
except ValueError as verr:
if "No JSON object could be decoded" in verr.args:
rval['err'] = verr.args
elif output_type == 'raw':
rval['results'] = stdout if output else ''
if self.verbose:
print("STDOUT: {0}".format(stdout))
print("STDERR: {0}".format(stderr))
if 'err' in rval or returncode != 0:
rval.update({"stderr": stderr,
"stdout": stdout})
return rval
class Utils(object): # pragma: no cover
''' utilities for openshiftcli modules '''
@staticmethod
def _write(filename, contents):
''' Actually write the file contents to disk. This helps with mocking. '''
with open(filename, 'w') as sfd:
sfd.write(str(contents))
@staticmethod
def create_tmp_file_from_contents(rname, data, ftype='yaml'):
''' create a file in tmp with name and contents'''
tmp = Utils.create_tmpfile(prefix=rname)
if ftype == 'yaml':
# AUDIT:no-member makes sense here due to ruamel.YAML/PyYAML usage
# pylint: disable=no-member
if hasattr(yaml, 'RoundTripDumper'):
Utils._write(tmp, yaml.dump(data, Dumper=yaml.RoundTripDumper))
else:
Utils._write(tmp, yaml.safe_dump(data, default_flow_style=False))
elif ftype == 'json':
Utils._write(tmp, json.dumps(data))
else:
Utils._write(tmp, data)
# Register cleanup when module is done
atexit.register(Utils.cleanup, [tmp])
return tmp
@staticmethod
def create_tmpfile_copy(inc_file):
'''create a temporary copy of a file'''
tmpfile = Utils.create_tmpfile('lib_openshift-')
Utils._write(tmpfile, open(inc_file).read())
# Cleanup the tmpfile
atexit.register(Utils.cleanup, [tmpfile])
return tmpfile
@staticmethod
def create_tmpfile(prefix='tmp'):
''' Generates and returns a temporary file name '''
with tempfile.NamedTemporaryFile(prefix=prefix, delete=False) as tmp:
return tmp.name
@staticmethod
def create_tmp_files_from_contents(content, content_type=None):
'''Turn an array of dict: filename, content into a files array'''
if not isinstance(content, list):
content = [content]
files = []
for item in content:
path = Utils.create_tmp_file_from_contents(item['path'] + '-',
item['data'],
ftype=content_type)
files.append({'name': os.path.basename(item['path']),
'path': path})
return files
@staticmethod
def cleanup(files):
'''Clean up on exit '''
for sfile in files:
if os.path.exists(sfile):
if os.path.isdir(sfile):
shutil.rmtree(sfile)
elif os.path.isfile(sfile):
os.remove(sfile)
@staticmethod
def exists(results, _name):
''' Check to see if the results include the name '''
if not results:
return False
if Utils.find_result(results, _name):
return True
return False
@staticmethod
def find_result(results, _name):
''' Find the specified result by name'''
rval = None
for result in results:
if 'metadata' in result and result['metadata']['name'] == _name:
rval = result
break
return rval
@staticmethod
def get_resource_file(sfile, sfile_type='yaml'):
''' return the service file '''
contents = None
with open(sfile) as sfd:
contents = sfd.read()
if sfile_type == 'yaml':
# AUDIT:no-member makes sense here due to ruamel.YAML/PyYAML usage
# pylint: disable=no-member
if hasattr(yaml, 'RoundTripLoader'):
contents = yaml.load(contents, yaml.RoundTripLoader)
else:
contents = yaml.safe_load(contents)
elif sfile_type == 'json':
contents = json.loads(contents)
return contents
@staticmethod
def filter_versions(stdout):
''' filter the oc version output '''
version_dict = {}
version_search = ['oc', 'openshift', 'kubernetes']
for line in stdout.strip().split('\n'):
for term in version_search:
if not line:
continue
if line.startswith(term):
version_dict[term] = line.split()[-1]
# horrible hack to get openshift version in Openshift 3.2
# By default "oc version in 3.2 does not return an "openshift" version
if "openshift" not in version_dict:
version_dict["openshift"] = version_dict["oc"]
return version_dict
@staticmethod
def add_custom_versions(versions):
''' create custom versions strings '''
versions_dict = {}
for tech, version in versions.items():
# clean up "-" from version
if "-" in version:
version = version.split("-")[0]
if version.startswith('v'):
version = version[1:] # Remove the 'v' prefix
versions_dict[tech + '_numeric'] = version.split('+')[0]
# "3.3.0.33" is what we have, we want "3.3"
versions_dict[tech + '_short'] = "{}.{}".format(*version.split('.'))
return versions_dict
@staticmethod
def openshift_installed():
''' check if openshift is installed '''
import rpm
transaction_set = rpm.TransactionSet()
rpmquery = transaction_set.dbMatch("name", "atomic-openshift")
return rpmquery.count() > 0
# Disabling too-many-branches. This is a yaml dictionary comparison function
# pylint: disable=too-many-branches,too-many-return-statements,too-many-statements
@staticmethod
def check_def_equal(user_def, result_def, skip_keys=None, debug=False):
''' Given a user defined definition, compare it with the results given back by our query. '''
# Currently these values are autogenerated and we do not need to check them
skip = ['metadata', 'status']
if skip_keys:
skip.extend(skip_keys)
for key, value in result_def.items():
if key in skip:
continue
# Both are lists
if isinstance(value, list):
if key not in user_def:
if debug:
print('User data does not have key [%s]' % key)
print('User data: %s' % user_def)
return False
if not isinstance(user_def[key], list):
if debug:
print('user_def[key] is not a list key=[%s] user_def[key]=%s' % (key, user_def[key]))
return False
if len(user_def[key]) != len(value):
if debug:
print("List lengths are not equal.")
print("key=[%s]: user_def[%s] != value[%s]" % (key, len(user_def[key]), len(value)))
print("user_def: %s" % user_def[key])
print("value: %s" % value)
return False
for values in zip(user_def[key], value):
if isinstance(values[0], dict) and isinstance(values[1], dict):
if debug:
print('sending list - list')
print(type(values[0]))
print(type(values[1]))
result = Utils.check_def_equal(values[0], values[1], skip_keys=skip_keys, debug=debug)
if not result:
print('list compare returned false')
return False
elif value != user_def[key]:
if debug:
print('value should be identical')
print(user_def[key])
print(value)
return False
# recurse on a dictionary
elif isinstance(value, dict):
if key not in user_def:
if debug:
print("user_def does not have key [%s]" % key)
return False
if not isinstance(user_def[key], dict):
if debug:
print("dict returned false: not instance of dict")
return False
# before passing ensure keys match
api_values = set(value.keys()) - set(skip)
user_values = set(user_def[key].keys()) - set(skip)
if api_values != user_values:
if debug:
print("keys are not equal in dict")
print(user_values)
print(api_values)
return False
result = Utils.check_def_equal(user_def[key], value, skip_keys=skip_keys, debug=debug)
if not result:
if debug:
print("dict returned false")
print(result)
return False
# Verify each key, value pair is the same
else:
if key not in user_def or value != user_def[key]:
if debug:
print("value not equal; user_def does not have key")
print(key)
print(value)
if key in user_def:
print(user_def[key])
return False
if debug:
print('returning true')
return True
class OpenShiftCLIConfig(object):
'''Generic Config'''
def __init__(self, rname, namespace, kubeconfig, options):
self.kubeconfig = kubeconfig
self.name = rname
self.namespace = namespace
self._options = options
@property
def config_options(self):
''' return config options '''
return self._options
def to_option_list(self, ascommalist=''):
'''return all options as a string
if ascommalist is set to the name of a key, and
the value of that key is a dict, format the dict
as a list of comma delimited key=value pairs'''
return self.stringify(ascommalist)
def stringify(self, ascommalist=''):
''' return the options hash as cli params in a string
if ascommalist is set to the name of a key, and
the value of that key is a dict, format the dict
as a list of comma delimited key=value pairs '''
rval = []
for key in sorted(self.config_options.keys()):
data = self.config_options[key]
if data['include'] \
and (data['value'] is not None or isinstance(data['value'], int)):
if key == ascommalist:
val = ','.join(['{}={}'.format(kk, vv) for kk, vv in sorted(data['value'].items())])
else:
val = data['value']
rval.append('--{}={}'.format(key.replace('_', '-'), val))
return rval
# -*- -*- -*- End included fragment: lib/base.py -*- -*- -*-
# -*- -*- -*- Begin included fragment: lib/route.py -*- -*- -*-
# noqa: E302,E301
# pylint: disable=too-many-instance-attributes
class RouteConfig(object):
''' Handle route options '''
# pylint: disable=too-many-arguments
def __init__(self,
sname,
namespace,
kubeconfig,
labels=None,
destcacert=None,
cacert=None,
cert=None,
key=None,
host=None,
tls_termination=None,
service_name=None,
wildcard_policy=None,
weight=None,
port=None):
''' constructor for handling route options '''
self.kubeconfig = kubeconfig
self.name = sname
self.namespace = namespace
self.labels = labels
self.host = host
self.tls_termination = tls_termination
self.destcacert = destcacert
self.cacert = cacert
self.cert = cert
self.key = key
self.service_name = service_name
self.port = port
self.data = {}
self.wildcard_policy = wildcard_policy
if wildcard_policy is None:
self.wildcard_policy = 'None'
self.weight = weight
if weight is None:
self.weight = 100
self.create_dict()
def create_dict(self):
''' return a service as a dict '''
self.data['apiVersion'] = 'v1'
self.data['kind'] = 'Route'
self.data['metadata'] = {}
self.data['metadata']['name'] = self.name
self.data['metadata']['namespace'] = self.namespace
if self.labels:
self.data['metadata']['labels'] = self.labels
self.data['spec'] = {}
self.data['spec']['host'] = self.host
if self.tls_termination:
self.data['spec']['tls'] = {}
self.data['spec']['tls']['termination'] = self.tls_termination
if self.tls_termination != 'passthrough':
self.data['spec']['tls']['key'] = self.key
self.data['spec']['tls']['caCertificate'] = self.cacert
self.data['spec']['tls']['certificate'] = self.cert
if self.tls_termination == 'reencrypt':
self.data['spec']['tls']['destinationCACertificate'] = self.destcacert
self.data['spec']['to'] = {'kind': 'Service',
'name': self.service_name,
'weight': self.weight}
self.data['spec']['wildcardPolicy'] = self.wildcard_policy
if self.port:
self.data['spec']['port'] = {}
self.data['spec']['port']['targetPort'] = self.port
# pylint: disable=too-many-instance-attributes,too-many-public-methods
class Route(Yedit):
''' Class to wrap the oc command line tools '''
wildcard_policy = "spec.wildcardPolicy"
host_path = "spec.host"
port_path = "spec.port.targetPort"
service_path = "spec.to.name"
weight_path = "spec.to.weight"
cert_path = "spec.tls.certificate"
cacert_path = "spec.tls.caCertificate"
destcacert_path = "spec.tls.destinationCACertificate"
termination_path = "spec.tls.termination"
key_path = "spec.tls.key"
kind = 'route'
def __init__(self, content):
'''Route constructor'''
super(Route, self).__init__(content=content)
def get_destcacert(self):
''' return cert '''
return self.get(Route.destcacert_path)
def get_cert(self):
''' return cert '''
return self.get(Route.cert_path)
def get_key(self):
''' return key '''
return self.get(Route.key_path)
def get_cacert(self):
''' return cacert '''
return self.get(Route.cacert_path)
def get_service(self):
''' return service name '''
return self.get(Route.service_path)
def get_weight(self):
''' return service weight '''
return self.get(Route.weight_path)
def get_termination(self):
''' return tls termination'''
return self.get(Route.termination_path)
def get_host(self):
''' return host '''
return self.get(Route.host_path)
def get_port(self):
''' return port '''
return self.get(Route.port_path)
def get_wildcard_policy(self):
''' return wildcardPolicy '''
return self.get(Route.wildcard_policy)
# -*- -*- -*- End included fragment: lib/route.py -*- -*- -*-
# -*- -*- -*- Begin included fragment: class/oc_route.py -*- -*- -*-
# pylint: disable=too-many-instance-attributes
class OCRoute(OpenShiftCLI):
''' Class to wrap the oc command line tools '''
kind = 'route'
def __init__(self,
config,
verbose=False):
''' Constructor for OCVolume '''
super(OCRoute, self).__init__(config.namespace, kubeconfig=config.kubeconfig, verbose=verbose)
self.config = config
self._route = None
@property
def route(self):
''' property function for route'''
if not self._route:
self.get()
return self._route
@route.setter
def route(self, data):
''' setter function for route '''
self._route = data
def exists(self):
''' return whether a route exists '''
if self.route:
return True
return False
def get(self):
'''return route information '''
result = self._get(self.kind, self.config.name)
if result['returncode'] == 0:
self.route = Route(content=result['results'][0])
elif 'routes \"%s\" not found' % self.config.name in result['stderr']:
result['returncode'] = 0
result['results'] = [{}]
elif 'namespaces \"%s\" not found' % self.config.namespace in result['stderr']:
result['returncode'] = 0
result['results'] = [{}]
return result
def delete(self):
'''delete the object'''
return self._delete(self.kind, self.config.name)
def create(self):
'''create the object'''
return self._create_from_content(self.config.name, self.config.data)
def update(self):
'''update the object'''
return self._replace_content(self.kind,
self.config.name,
self.config.data,
force=(self.config.host != self.route.get_host()))
def needs_update(self):
''' verify an update is needed '''
skip = []
return not Utils.check_def_equal(self.config.data, self.route.yaml_dict, skip_keys=skip, debug=self.verbose)
@staticmethod
def get_cert_data(path, content):
'''get the data for a particular value'''
rval = None
if path and os.path.exists(path) and os.access(path, os.R_OK):
rval = open(path).read()
elif content:
rval = content
return rval
# pylint: disable=too-many-return-statements,too-many-branches
@staticmethod
def run_ansible(params, check_mode=False):
''' run the oc_route module
params comes from the ansible portion for this module
files: a dictionary for the certificates
{'cert': {'path': '',
'content': '',
'value': ''
}
}
check_mode: does the module support check mode. (module.check_mode)
'''
files = {'destcacert': {'path': params['dest_cacert_path'],
'content': params['dest_cacert_content'],
'value': None, },
'cacert': {'path': params['cacert_path'],
'content': params['cacert_content'],
'value': None, },
'cert': {'path': params['cert_path'],
'content': params['cert_content'],
'value': None, },
'key': {'path': params['key_path'],
'content': params['key_content'],
'value': None, }, }
if params['tls_termination'] and params['tls_termination'].lower() != 'passthrough': # E501
for key, option in files.items():
if not option['path'] and not option['content']:
continue
option['value'] = OCRoute.get_cert_data(option['path'], option['content']) # E501
if not option['value']:
return {'failed': True,
'msg': 'Verify that you pass a correct value for %s' % key}
rconfig = RouteConfig(params['name'],
params['namespace'],
params['kubeconfig'],
params['labels'],
files['destcacert']['value'],
files['cacert']['value'],
files['cert']['value'],
files['key']['value'],
params['host'],
params['tls_termination'],
params['service_name'],
params['wildcard_policy'],
params['weight'],
params['port'])
oc_route = OCRoute(rconfig, verbose=params['debug'])
state = params['state']
api_rval = oc_route.get()
#####
# Get
#####
if state == 'list':
return {'changed': False,
'results': api_rval['results'],
'state': 'list'}
########
# Delete
########
if state == 'absent':
if oc_route.exists():
if check_mode:
return {'changed': False, 'msg': 'CHECK_MODE: Would have performed a delete.'} # noqa: E501
api_rval = oc_route.delete()
return {'changed': True, 'results': api_rval, 'state': "absent"} # noqa: E501
return {'changed': False, 'state': 'absent'}
if state == 'present':
########
# Create
########
if not oc_route.exists():
if check_mode:
return {'changed': True, 'msg': 'CHECK_MODE: Would have performed a create.'} # noqa: E501
# Create it here
api_rval = oc_route.create()
if api_rval['returncode'] != 0:
return {'failed': True, 'msg': api_rval, 'state': "present"} # noqa: E501
# return the created object
api_rval = oc_route.get()
if api_rval['returncode'] != 0:
return {'failed': True, 'msg': api_rval, 'state': "present"} # noqa: E501
return {'changed': True, 'results': api_rval, 'state': "present"} # noqa: E501
########
# Update
########
if oc_route.needs_update():
if check_mode:
return {'changed': True, 'msg': 'CHECK_MODE: Would have performed an update.'} # noqa: E501
api_rval = oc_route.update()
if api_rval['returncode'] != 0:
return {'failed': True, 'msg': api_rval, 'state': "present"} # noqa: E501
# return the created object
api_rval = oc_route.get()
if api_rval['returncode'] != 0:
return {'failed': True, 'msg': api_rval, 'state': "present"} # noqa: E501
return {'changed': True, 'results': api_rval, 'state': "present"} # noqa: E501
return {'changed': False, 'results': api_rval, 'state': "present"}
# catch all
return {'failed': True, 'msg': "Unknown State passed"}
# -*- -*- -*- End included fragment: class/oc_route.py -*- -*- -*-
# -*- -*- -*- Begin included fragment: ansible/oc_route.py -*- -*- -*-
# pylint: disable=too-many-branches
def main():
'''
ansible oc module for route
'''
module = AnsibleModule(
argument_spec=dict(
kubeconfig=dict(default='/etc/origin/master/admin.kubeconfig', type='str'),
state=dict(default='present', type='str',
choices=['present', 'absent', 'list']),
debug=dict(default=False, type='bool'),
labels=dict(default=None, type='dict'),
name=dict(default=None, required=True, type='str'),
namespace=dict(default=None, required=True, type='str'),
tls_termination=dict(default=None, type='str'),
dest_cacert_path=dict(default=None, type='str'),
cacert_path=dict(default=None, type='str'),
cert_path=dict(default=None, type='str'),
key_path=dict(default=None, type='str'),
dest_cacert_content=dict(default=None, type='str'),
cacert_content=dict(default=None, type='str'),
cert_content=dict(default=None, type='str'),
key_content=dict(default=None, type='str'),
service_name=dict(default=None, type='str'),
host=dict(default=None, type='str'),
wildcard_policy=dict(default=None, type='str'),
weight=dict(default=None, type='int'),
port=dict(default=None, type='int'),
),
mutually_exclusive=[('dest_cacert_path', 'dest_cacert_content'),
('cacert_path', 'cacert_content'),
('cert_path', 'cert_content'),
('key_path', 'key_content'), ],
supports_check_mode=True,
)
results = OCRoute.run_ansible(module.params, module.check_mode)
if 'failed' in results:
module.fail_json(**results)
module.exit_json(**results)
if __name__ == '__main__':
main()
# -*- -*- -*- End included fragment: ansible/oc_route.py -*- -*- -*-
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
4287,
26,
3507,
29,
4752,
13,
12485,
199,
3,
27510,
24,
26,
8151,
26,
377,
4587,
199,
3,
258,
31111,
31111,
485,
221,
485,
31111,
31111,
259,
485,
636,
8989,
31111,
31111,
199,
3,
259,
1182,
636,
92,
636,
92,
971,
92,
1204,
636,
92,
485,
971,
221,
1182,
18005,
63,
257,
485,
92,
636,
92,
257,
971,
199,
3,
257,
1204,
6110,
1204,
485,
10644,
1275,
64,
1204,
485,
10644,
257,
1182,
1182,
485,
971,
92,
1204,
1204,
485,
10644,
1204,
9,
1204,
199,
3,
259,
971,
8989,
92,
8989,
30007,
6113,
63,
92,
8989,
30007,
92,
18005,
15607,
15607,
60,
18005,
63,
30007,
92,
8989,
92,
8989,
15607,
636,
8989,
199,
3,
257,
1204,
257,
971,
1182,
485,
971,
221,
1204,
971,
92,
1204,
15,
485,
971,
63,
257,
485,
92,
1204,
636,
92,
257,
971,
63,
485,
30007,
257,
485,
92,
199,
3,
257,
1204,
1204,
9,
1204,
334,
4602,
1204,
1204,
1275,
64,
1204,
334,
4602,
12208,
1204,
257,
1204,
485,
10644,
1204,
9,
1204,
1204,
221,
1204,
1204,
199,
3,
257,
1204,
8989,
15,
971,
8989,
15,
221,
1204,
63,
6113,
63,
6113,
8989,
15,
1204,
63,
92,
257,
1204,
8989,
92,
8989,
15,
8989,
92,
1204,
63,
92,
199,
3,
199,
3,
1898,
7800,
9572,
13002,
12,
3277,
14,
436,
15,
269,
2399,
29172,
2335,
199,
3,
436,
1163,
8417,
465,
22141,
701,
314,
768,
2502,
3762,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
3,
1882,
1882,
1882,
25754,
5120,
7956,
26,
1973,
15,
646,
14,
647,
1882,
1882,
1882,
199,
2344,
2043,
3232,
14379,
7802,
1021,
626,
14018,
314,
4244,
3718,
315,
282,
3873,
199,
2344,
199,
3,
4287,
26,
3507,
29,
7354,
13,
3479,
13,
1278,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
19840,
199,
646,
1331,
199,
646,
12871,
199,
646,
2022,
199,
646,
900,
199,
646,
747,
199,
646,
295,
199,
646,
5145,
199,
646,
3873,
199,
646,
5549,
199,
3,
4287,
26,
3507,
29,
646,
13,
705,
199,
893,
26,
272,
492,
519,
85,
14868,
14,
5963,
465,
8864,
199,
2590,
3545,
26,
272,
492,
8864,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
199,
3,
1882,
1882,
1882,
9599,
5120,
7956,
26,
1973,
15,
646,
14,
647,
1882,
1882,
1882,
199,
199,
3,
1882,
1882,
1882,
25754,
5120,
7956,
26,
1382,
15,
4449,
1882,
1882,
1882,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
4244,
63,
4449,
199,
3612,
63,
1802,
26,
2790,
12,
2811,
12,
436,
32122,
590,
9635,
1551,
4723,
15777,
14,
199,
1802,
26,
523,
446,
14944,
1551,
4723,
7475,
2251,
2240,
17174,
14,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
272,
446,
8511,
8469,
3775,
370,
1218,
12,
2811,
12,
3145,
12,
503,
769,
272,
1415,
26,
2549,
272,
849,
26,
3451,
272,
3415,
26,
2097,
1881,
401,
298,
5575,
401,
298,
513,
937,
272,
5481,
26,
942,
523,
23091,
888,
26,
272,
1369,
26,
272,
446,
710,
931,
367,
314,
23091,
888,
570,
370,
675,
367,
6299,
272,
1415,
26,
3055,
272,
849,
26,
1182,
6839,
15,
6493,
15,
4133,
15,
2113,
14,
29192,
272,
5481,
26,
942,
523,
3105,
26,
272,
1369,
26,
272,
446,
16147,
641,
3105,
1072,
14,
272,
1415,
26,
3055,
272,
849,
26,
756,
272,
5481,
26,
942,
523,
536,
26,
272,
1369,
26,
272,
446,
2812,
402,
314,
909,
626,
365,
3769,
30081,
14,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
3231,
26,
272,
1369,
26,
272,
446,
710,
3231,
2382,
314,
909,
27576,
14,
272,
1415,
26,
3055,
272,
849,
26,
620,
272,
5481,
26,
942,
523,
3628,
26,
272,
1369,
26,
272,
446,
710,
3628,
370,
4838,
641,
314,
7475,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
15142,
63,
20667,
26,
272,
1369,
26,
272,
446,
710,
1511,
367,
23868,
14,
325,
14,
71,
14,
295,
11929,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
2053,
63,
11055,
15299,
63,
515,
26,
272,
1369,
26,
272,
446,
710,
931,
370,
314,
2053,
63,
11055,
15299,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
286,
645,
15299,
63,
515,
26,
272,
1369,
26,
272,
446,
710,
931,
370,
314,
286,
645,
15299,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
6250,
63,
515,
26,
272,
1369,
26,
272,
446,
710,
931,
370,
314,
6250,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
790,
63,
515,
26,
272,
1369,
26,
272,
446,
710,
931,
370,
314,
790,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
2053,
63,
11055,
15299,
63,
1317,
26,
272,
1369,
26,
272,
446,
710,
2053,
63,
11055,
15299,
1564,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
286,
645,
15299,
63,
1317,
26,
272,
1369,
26,
272,
446,
710,
286,
645,
15299,
1564,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
6250,
63,
1317,
26,
272,
1369,
26,
272,
446,
710,
6250,
1564,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
2435,
63,
354,
26,
272,
1369,
26,
272,
446,
710,
536,
402
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
4287,
26,
3507,
29,
4752,
13,
12485,
199,
3,
27510,
24,
26,
8151,
26,
377,
4587,
199,
3,
258,
31111,
31111,
485,
221,
485,
31111,
31111,
259,
485,
636,
8989,
31111,
31111,
199,
3,
259,
1182,
636,
92,
636,
92,
971,
92,
1204,
636,
92,
485,
971,
221,
1182,
18005,
63,
257,
485,
92,
636,
92,
257,
971,
199,
3,
257,
1204,
6110,
1204,
485,
10644,
1275,
64,
1204,
485,
10644,
257,
1182,
1182,
485,
971,
92,
1204,
1204,
485,
10644,
1204,
9,
1204,
199,
3,
259,
971,
8989,
92,
8989,
30007,
6113,
63,
92,
8989,
30007,
92,
18005,
15607,
15607,
60,
18005,
63,
30007,
92,
8989,
92,
8989,
15607,
636,
8989,
199,
3,
257,
1204,
257,
971,
1182,
485,
971,
221,
1204,
971,
92,
1204,
15,
485,
971,
63,
257,
485,
92,
1204,
636,
92,
257,
971,
63,
485,
30007,
257,
485,
92,
199,
3,
257,
1204,
1204,
9,
1204,
334,
4602,
1204,
1204,
1275,
64,
1204,
334,
4602,
12208,
1204,
257,
1204,
485,
10644,
1204,
9,
1204,
1204,
221,
1204,
1204,
199,
3,
257,
1204,
8989,
15,
971,
8989,
15,
221,
1204,
63,
6113,
63,
6113,
8989,
15,
1204,
63,
92,
257,
1204,
8989,
92,
8989,
15,
8989,
92,
1204,
63,
92,
199,
3,
199,
3,
1898,
7800,
9572,
13002,
12,
3277,
14,
436,
15,
269,
2399,
29172,
2335,
199,
3,
436,
1163,
8417,
465,
22141,
701,
314,
768,
2502,
3762,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
3,
1882,
1882,
1882,
25754,
5120,
7956,
26,
1973,
15,
646,
14,
647,
1882,
1882,
1882,
199,
2344,
2043,
3232,
14379,
7802,
1021,
626,
14018,
314,
4244,
3718,
315,
282,
3873,
199,
2344,
199,
3,
4287,
26,
3507,
29,
7354,
13,
3479,
13,
1278,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
19840,
199,
646,
1331,
199,
646,
12871,
199,
646,
2022,
199,
646,
900,
199,
646,
747,
199,
646,
295,
199,
646,
5145,
199,
646,
3873,
199,
646,
5549,
199,
3,
4287,
26,
3507,
29,
646,
13,
705,
199,
893,
26,
272,
492,
519,
85,
14868,
14,
5963,
465,
8864,
199,
2590,
3545,
26,
272,
492,
8864,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
199,
3,
1882,
1882,
1882,
9599,
5120,
7956,
26,
1973,
15,
646,
14,
647,
1882,
1882,
1882,
199,
199,
3,
1882,
1882,
1882,
25754,
5120,
7956,
26,
1382,
15,
4449,
1882,
1882,
1882,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
4244,
63,
4449,
199,
3612,
63,
1802,
26,
2790,
12,
2811,
12,
436,
32122,
590,
9635,
1551,
4723,
15777,
14,
199,
1802,
26,
523,
446,
14944,
1551,
4723,
7475,
2251,
2240,
17174,
14,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
272,
446,
8511,
8469,
3775,
370,
1218,
12,
2811,
12,
3145,
12,
503,
769,
272,
1415,
26,
2549,
272,
849,
26,
3451,
272,
3415,
26,
2097,
1881,
401,
298,
5575,
401,
298,
513,
937,
272,
5481,
26,
942,
523,
23091,
888,
26,
272,
1369,
26,
272,
446,
710,
931,
367,
314,
23091,
888,
570,
370,
675,
367,
6299,
272,
1415,
26,
3055,
272,
849,
26,
1182,
6839,
15,
6493,
15,
4133,
15,
2113,
14,
29192,
272,
5481,
26,
942,
523,
3105,
26,
272,
1369,
26,
272,
446,
16147,
641,
3105,
1072,
14,
272,
1415,
26,
3055,
272,
849,
26,
756,
272,
5481,
26,
942,
523,
536,
26,
272,
1369,
26,
272,
446,
2812,
402,
314,
909,
626,
365,
3769,
30081,
14,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
3231,
26,
272,
1369,
26,
272,
446,
710,
3231,
2382,
314,
909,
27576,
14,
272,
1415,
26,
3055,
272,
849,
26,
620,
272,
5481,
26,
942,
523,
3628,
26,
272,
1369,
26,
272,
446,
710,
3628,
370,
4838,
641,
314,
7475,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
15142,
63,
20667,
26,
272,
1369,
26,
272,
446,
710,
1511,
367,
23868,
14,
325,
14,
71,
14,
295,
11929,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
2053,
63,
11055,
15299,
63,
515,
26,
272,
1369,
26,
272,
446,
710,
931,
370,
314,
2053,
63,
11055,
15299,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
286,
645,
15299,
63,
515,
26,
272,
1369,
26,
272,
446,
710,
931,
370,
314,
286,
645,
15299,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
6250,
63,
515,
26,
272,
1369,
26,
272,
446,
710,
931,
370,
314,
6250,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
790,
63,
515,
26,
272,
1369,
26,
272,
446,
710,
931,
370,
314,
790,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
2053,
63,
11055,
15299,
63,
1317,
26,
272,
1369,
26,
272,
446,
710,
2053,
63,
11055,
15299,
1564,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
286,
645,
15299,
63,
1317,
26,
272,
1369,
26,
272,
446,
710,
286,
645,
15299,
1564,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
6250,
63,
1317,
26,
272,
1369,
26,
272,
446,
710,
6250,
1564,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
2435,
63,
354,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
helenst/django-extensions
|
django_extensions/management/commands/graph_models.py
|
28
|
7350
|
import sys
from optparse import NO_DEFAULT, make_option
import six
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django_extensions.management.modelviz import generate_dot
from django_extensions.management.utils import signalcommand
try:
import pygraphviz
HAS_PYGRAPHVIZ = True
except ImportError:
HAS_PYGRAPHVIZ = False
try:
import pydot
HAS_PYDOT = True
except ImportError:
HAS_PYDOT = False
class Command(BaseCommand):
graph_models_options = (
make_option('--pygraphviz', action='store_true', dest='pygraphviz',
help='Use PyGraphViz to generate the image.'),
make_option('--pydot', action='store_true', dest='pydot',
help='Use PyDot to generate the image.'),
make_option('--disable-fields', '-d', action='store_true', dest='disable_fields',
help='Do not show the class member fields'),
make_option('--group-models', '-g', action='store_true', dest='group_models',
help='Group models together respective to their application'),
make_option('--all-applications', '-a', action='store_true', dest='all_applications',
help='Automatically include all applications from INSTALLED_APPS'),
make_option('--output', '-o', action='store', dest='outputfile',
help='Render output file. Type of output dependend on file extensions. Use png or jpg to render graph to image.'),
make_option('--layout', '-l', action='store', dest='layout', default='dot',
help='Layout to be used by GraphViz for visualization. Layouts: circo dot fdp neato nop nop1 nop2 twopi'),
make_option('--verbose-names', '-n', action='store_true', dest='verbose_names',
help='Use verbose_name of models and fields'),
make_option('--language', '-L', action='store', dest='language',
help='Specify language used for verbose_name localization'),
make_option('--exclude-columns', '-x', action='store', dest='exclude_columns',
help='Exclude specific column(s) from the graph. Can also load exclude list from file.'),
make_option('--exclude-models', '-X', action='store', dest='exclude_models',
help='Exclude specific model(s) from the graph. Can also load exclude list from file.'),
make_option('--include-models', '-I', action='store', dest='include_models',
help='Restrict the graph to specified models.'),
make_option('--inheritance', '-e', action='store_true', dest='inheritance', default=True,
help='Include inheritance arrows (default)'),
make_option('--no-inheritance', '-E', action='store_false', dest='inheritance',
help='Do not include inheritance arrows'),
make_option('--hide-relations-from-fields', '-R', action='store_false', dest="relations_as_fields",
default=True, help="Do not show relations as fields in the graph."),
make_option('--disable-sort-fields', '-S', action="store_false", dest="sort_fields",
default=True, help="Do not sort fields"),
)
option_list = BaseCommand.option_list + graph_models_options
help = "Creates a GraphViz dot file for the specified app names. You can pass multiple app names and they will all be combined into a single model. Output is usually directed to a dot file."
args = "[appname]"
label = 'application name'
can_import_settings = True
@signalcommand
def handle(self, *args, **options):
self.options_from_settings(options)
if len(args) < 1 and not options['all_applications']:
raise CommandError("need one or more arguments for appname")
use_pygraphviz = options.get('pygraphviz', False)
use_pydot = options.get('pydot', False)
cli_options = ' '.join(sys.argv[2:])
dotdata = generate_dot(args, cli_options=cli_options, **options)
if not six.PY3:
dotdata = dotdata.encode('utf-8')
if options['outputfile']:
if not use_pygraphviz and not use_pydot:
if HAS_PYGRAPHVIZ:
use_pygraphviz = True
elif HAS_PYDOT:
use_pydot = True
if use_pygraphviz:
self.render_output_pygraphviz(dotdata, **options)
elif use_pydot:
self.render_output_pydot(dotdata, **options)
else:
raise CommandError("Neither pygraphviz nor pydot could be found to generate the image")
else:
self.print_output(dotdata)
def options_from_settings(self, options):
defaults = getattr(settings, 'GRAPH_MODELS', None)
if defaults:
for option in self.graph_models_options:
long_opt = option._long_opts[0]
if long_opt:
long_opt = long_opt.lstrip("-").replace("-", "_")
if long_opt in defaults:
default_value = None
if not option.default == NO_DEFAULT:
default_value = option.default
if options[option.dest] == default_value:
options[option.dest] = defaults[long_opt]
def print_output(self, dotdata):
if six.PY3 and isinstance(dotdata, six.binary_type):
dotdata = dotdata.decode()
print(dotdata)
def render_output_pygraphviz(self, dotdata, **kwargs):
"""Renders the image using pygraphviz"""
if not HAS_PYGRAPHVIZ:
raise CommandError("You need to install pygraphviz python module")
version = pygraphviz.__version__.rstrip("-svn")
try:
if tuple(int(v) for v in version.split('.')) < (0, 36):
# HACK around old/broken AGraph before version 0.36 (ubuntu ships with this old version)
import tempfile
tmpfile = tempfile.NamedTemporaryFile()
tmpfile.write(dotdata)
tmpfile.seek(0)
dotdata = tmpfile.name
except ValueError:
pass
graph = pygraphviz.AGraph(dotdata)
graph.layout(prog=kwargs['layout'])
graph.draw(kwargs['outputfile'])
def render_output_pydot(self, dotdata, **kwargs):
"""Renders the image using pydot"""
if not HAS_PYDOT:
raise CommandError("You need to install pydot python module")
graph = pydot.graph_from_dot_data(dotdata)
if not graph:
raise CommandError("pydot returned an error")
output_file = kwargs['outputfile']
formats = ['bmp', 'canon', 'cmap', 'cmapx', 'cmapx_np', 'dot', 'dia', 'emf',
'em', 'fplus', 'eps', 'fig', 'gd', 'gd2', 'gif', 'gv', 'imap',
'imap_np', 'ismap', 'jpe', 'jpeg', 'jpg', 'metafile', 'pdf',
'pic', 'plain', 'plain-ext', 'png', 'pov', 'ps', 'ps2', 'svg',
'svgz', 'tif', 'tiff', 'tk', 'vml', 'vmlz', 'vrml', 'wbmp', 'xdot']
ext = output_file[output_file.rfind('.') + 1:]
format = ext if ext in formats else 'raw'
graph.write(output_file, format=format)
|
mit
|
[
646,
984,
199,
504,
8691,
492,
4825,
63,
3472,
12,
1852,
63,
1422,
199,
199,
646,
3816,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
199,
504,
1639,
63,
5359,
14,
8110,
14,
1238,
17249,
492,
3550,
63,
3287,
199,
504,
1639,
63,
5359,
14,
8110,
14,
1208,
492,
4673,
1531,
199,
199,
893,
26,
272,
492,
1134,
2180,
17249,
272,
7509,
63,
4521,
3975,
1282,
16566,
5357,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
4521,
3975,
1282,
16566,
5357,
275,
756,
199,
199,
893,
26,
272,
492,
1134,
3287,
272,
7509,
63,
4521,
13203,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
4521,
13203,
275,
756,
421,
199,
533,
5817,
8,
25150,
304,
272,
3343,
63,
992,
63,
1419,
275,
334,
267,
1852,
63,
1422,
4517,
647,
2180,
17249,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
647,
2180,
17249,
297,
490,
1720,
534,
6119,
1611,
4578,
32068,
370,
3550,
314,
1834,
8038,
267,
1852,
63,
1422,
4517,
647,
3287,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
647,
3287,
297,
490,
1720,
534,
6119,
1611,
14004,
370,
3550,
314,
1834,
8038,
267,
1852,
63,
1422,
4517,
5993,
13,
955,
297,
2475,
68,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
5993,
63,
955,
297,
490,
1720,
534,
2585,
440,
2498,
314,
1021,
3653,
1504,
659,
267,
1852,
63,
1422,
4517,
923,
13,
992,
297,
2475,
71,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
923,
63,
992,
297,
490,
1720,
534,
2448,
1709,
10451,
26820,
370,
3932,
4223,
659,
267,
1852,
63,
1422,
4517,
452,
13,
15853,
297,
2475,
65,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
452,
63,
15853,
297,
490,
1720,
534,
3358,
17174,
2387,
1006,
13103,
687,
31061,
63,
14219,
659,
267,
1852,
63,
1422,
4517,
1199,
297,
2475,
79,
297,
1595,
534,
1617,
297,
2053,
534,
1199,
493,
297,
490,
1720,
534,
9216,
1072,
570,
14,
2434,
402,
1072,
477,
2230,
68,
641,
570,
5478,
14,
3645,
25296,
503,
1335,
4198,
370,
3795,
3343,
370,
1834,
8038,
267,
1852,
63,
1422,
4517,
4209,
297,
2475,
76,
297,
1595,
534,
1617,
297,
2053,
534,
4209,
297,
849,
534,
3287,
297,
490,
1720,
534,
4798,
370,
506,
1202,
701,
11513,
32068,
367,
13104,
2072,
14,
9366,
16816,
26,
286,
723,
331,
6308,
289,
5780,
1279,
11318,
302,
411,
302,
411,
17,
302,
411,
18,
8900,
411,
73,
659,
267,
1852,
63,
1422,
4517,
3832,
13,
1247,
297,
2475,
78,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
3832,
63,
1247,
297,
490,
1720,
534,
6119,
3376,
63,
354,
402,
1709,
436,
1504,
659,
267,
1852,
63,
1422,
4517,
3671,
297,
2475,
44,
297,
1595,
534,
1617,
297,
2053,
534,
3671,
297,
490,
1720,
534,
17768,
2637,
1202,
367,
3376,
63,
354,
2257,
2072,
659,
267,
1852,
63,
1422,
4517,
5473,
13,
3406,
297,
2475,
88,
297,
1595,
534,
1617,
297,
2053,
534,
5473,
63,
3406,
297,
490,
1720,
534,
29448,
2488,
2763,
8,
83,
9,
687,
314,
3343,
14,
6855,
2597,
2248,
5760,
769,
687,
570,
8038,
267,
1852,
63,
1422,
4517,
5473,
13,
992,
297,
2475,
56,
297,
1595,
534,
1617,
297,
2053,
534,
5473,
63,
992,
297,
490,
1720,
534,
29448,
2488,
1402,
8,
83,
9,
687,
314,
3343,
14,
6855,
2597,
2248,
5760,
769,
687,
570,
8038,
267,
1852,
63,
1422,
4517,
2613,
13,
992,
297,
2475,
41,
297,
1595,
534,
1617,
297,
2053,
534,
2613,
63,
992,
297,
490,
1720,
534,
497,
4768,
314,
3343,
370,
2013,
1709,
8038,
267,
1852,
63,
1422,
4517,
13136,
297,
2475,
69,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
13136,
297,
849,
29,
549,
12,
490,
1720,
534,
7826,
15433,
601,
3838,
334,
885,
11218,
267,
1852,
63,
1422,
4517,
889,
13,
13136,
297,
2475,
37,
297,
1595,
534,
1617,
63,
3910,
297,
2053,
534,
13136,
297,
490,
1720,
534,
2585,
440,
2387,
15433,
601,
3838,
659,
267,
1852,
63,
1422,
4517,
8191,
13,
15741,
13,
504,
13,
955,
297,
2475,
50,
297,
1595,
534,
1617,
63,
3910,
297,
2053,
628,
15741,
63,
305,
63,
955,
401,
490,
849,
29,
549,
12,
1720,
628,
2585,
440,
2498,
16109,
465,
1504,
315,
314,
3343,
7651,
267,
1852,
63,
1422,
4517,
5993,
13,
3191,
13,
955,
297,
2475,
51,
297,
1595,
628,
1617,
63,
3910,
401,
2053,
628,
3191,
63,
955,
401,
490,
849,
29,
549,
12,
1720,
628,
2585,
440,
4069,
1504,
1288,
272,
776,
272,
945,
63,
513,
275,
22239,
14,
1422,
63,
513,
435,
3343,
63,
992,
63,
1419,
339,
1720,
275,
298,
10607,
282,
11513,
32068,
6308,
570,
367,
314,
2013,
1145,
1561,
14,
221,
2047,
883,
986,
3663,
1145,
1561,
436,
2985,
911,
1006,
506,
12149,
1901,
282,
2849,
1402,
14,
221,
7242,
365,
9987,
23667,
370,
282,
6308,
570,
2122,
272,
1249,
275,
7369,
21653,
8480,
272,
1768,
275,
283,
3578,
536,
7,
339,
883,
63,
646,
63,
1751,
275,
715,
339,
768,
4653,
1531,
272,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
267,
291,
14,
1419,
63,
504,
63,
1751,
8,
1419,
9,
398,
340,
822,
8,
589,
9,
665,
413,
436,
440,
1511,
459,
452,
63,
15853,
2565,
288,
746,
14393,
480,
9321,
1373,
503,
1655,
2368,
367,
20268,
531,
398,
675,
63,
647,
2180,
17249,
275,
1511,
14,
362,
360,
647,
2180,
17249,
297,
756,
9,
267,
675,
63,
647,
3287,
275,
1511,
14,
362,
360,
647,
3287,
297,
756,
9,
267,
5053,
63,
1419,
275,
283,
1987,
904,
8,
1274,
14,
3020,
59,
18,
5728,
267,
6308,
576,
275,
3550,
63,
3287,
8,
589,
12,
5053,
63,
1419,
29,
2764,
63,
1419,
12,
1011,
1419,
9,
267,
340,
440,
3816,
14,
4521,
19,
26,
288,
6308,
576,
275,
6308,
576,
14,
2143,
360,
1624,
13,
24,
358,
267,
340,
1511,
459,
1199,
493,
2565,
288,
340,
440,
675,
63,
647,
2180,
17249,
436,
440,
675,
63,
647,
3287,
26,
355,
340,
7509,
63,
4521,
3975,
1282,
16566,
5357,
26,
490,
675,
63,
647,
2180,
17249,
275,
715,
355,
916,
7509,
63,
4521,
13203
] |
[
984,
199,
504,
8691,
492,
4825,
63,
3472,
12,
1852,
63,
1422,
199,
199,
646,
3816,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
199,
504,
1639,
63,
5359,
14,
8110,
14,
1238,
17249,
492,
3550,
63,
3287,
199,
504,
1639,
63,
5359,
14,
8110,
14,
1208,
492,
4673,
1531,
199,
199,
893,
26,
272,
492,
1134,
2180,
17249,
272,
7509,
63,
4521,
3975,
1282,
16566,
5357,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
4521,
3975,
1282,
16566,
5357,
275,
756,
199,
199,
893,
26,
272,
492,
1134,
3287,
272,
7509,
63,
4521,
13203,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
4521,
13203,
275,
756,
421,
199,
533,
5817,
8,
25150,
304,
272,
3343,
63,
992,
63,
1419,
275,
334,
267,
1852,
63,
1422,
4517,
647,
2180,
17249,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
647,
2180,
17249,
297,
490,
1720,
534,
6119,
1611,
4578,
32068,
370,
3550,
314,
1834,
8038,
267,
1852,
63,
1422,
4517,
647,
3287,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
647,
3287,
297,
490,
1720,
534,
6119,
1611,
14004,
370,
3550,
314,
1834,
8038,
267,
1852,
63,
1422,
4517,
5993,
13,
955,
297,
2475,
68,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
5993,
63,
955,
297,
490,
1720,
534,
2585,
440,
2498,
314,
1021,
3653,
1504,
659,
267,
1852,
63,
1422,
4517,
923,
13,
992,
297,
2475,
71,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
923,
63,
992,
297,
490,
1720,
534,
2448,
1709,
10451,
26820,
370,
3932,
4223,
659,
267,
1852,
63,
1422,
4517,
452,
13,
15853,
297,
2475,
65,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
452,
63,
15853,
297,
490,
1720,
534,
3358,
17174,
2387,
1006,
13103,
687,
31061,
63,
14219,
659,
267,
1852,
63,
1422,
4517,
1199,
297,
2475,
79,
297,
1595,
534,
1617,
297,
2053,
534,
1199,
493,
297,
490,
1720,
534,
9216,
1072,
570,
14,
2434,
402,
1072,
477,
2230,
68,
641,
570,
5478,
14,
3645,
25296,
503,
1335,
4198,
370,
3795,
3343,
370,
1834,
8038,
267,
1852,
63,
1422,
4517,
4209,
297,
2475,
76,
297,
1595,
534,
1617,
297,
2053,
534,
4209,
297,
849,
534,
3287,
297,
490,
1720,
534,
4798,
370,
506,
1202,
701,
11513,
32068,
367,
13104,
2072,
14,
9366,
16816,
26,
286,
723,
331,
6308,
289,
5780,
1279,
11318,
302,
411,
302,
411,
17,
302,
411,
18,
8900,
411,
73,
659,
267,
1852,
63,
1422,
4517,
3832,
13,
1247,
297,
2475,
78,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
3832,
63,
1247,
297,
490,
1720,
534,
6119,
3376,
63,
354,
402,
1709,
436,
1504,
659,
267,
1852,
63,
1422,
4517,
3671,
297,
2475,
44,
297,
1595,
534,
1617,
297,
2053,
534,
3671,
297,
490,
1720,
534,
17768,
2637,
1202,
367,
3376,
63,
354,
2257,
2072,
659,
267,
1852,
63,
1422,
4517,
5473,
13,
3406,
297,
2475,
88,
297,
1595,
534,
1617,
297,
2053,
534,
5473,
63,
3406,
297,
490,
1720,
534,
29448,
2488,
2763,
8,
83,
9,
687,
314,
3343,
14,
6855,
2597,
2248,
5760,
769,
687,
570,
8038,
267,
1852,
63,
1422,
4517,
5473,
13,
992,
297,
2475,
56,
297,
1595,
534,
1617,
297,
2053,
534,
5473,
63,
992,
297,
490,
1720,
534,
29448,
2488,
1402,
8,
83,
9,
687,
314,
3343,
14,
6855,
2597,
2248,
5760,
769,
687,
570,
8038,
267,
1852,
63,
1422,
4517,
2613,
13,
992,
297,
2475,
41,
297,
1595,
534,
1617,
297,
2053,
534,
2613,
63,
992,
297,
490,
1720,
534,
497,
4768,
314,
3343,
370,
2013,
1709,
8038,
267,
1852,
63,
1422,
4517,
13136,
297,
2475,
69,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
13136,
297,
849,
29,
549,
12,
490,
1720,
534,
7826,
15433,
601,
3838,
334,
885,
11218,
267,
1852,
63,
1422,
4517,
889,
13,
13136,
297,
2475,
37,
297,
1595,
534,
1617,
63,
3910,
297,
2053,
534,
13136,
297,
490,
1720,
534,
2585,
440,
2387,
15433,
601,
3838,
659,
267,
1852,
63,
1422,
4517,
8191,
13,
15741,
13,
504,
13,
955,
297,
2475,
50,
297,
1595,
534,
1617,
63,
3910,
297,
2053,
628,
15741,
63,
305,
63,
955,
401,
490,
849,
29,
549,
12,
1720,
628,
2585,
440,
2498,
16109,
465,
1504,
315,
314,
3343,
7651,
267,
1852,
63,
1422,
4517,
5993,
13,
3191,
13,
955,
297,
2475,
51,
297,
1595,
628,
1617,
63,
3910,
401,
2053,
628,
3191,
63,
955,
401,
490,
849,
29,
549,
12,
1720,
628,
2585,
440,
4069,
1504,
1288,
272,
776,
272,
945,
63,
513,
275,
22239,
14,
1422,
63,
513,
435,
3343,
63,
992,
63,
1419,
339,
1720,
275,
298,
10607,
282,
11513,
32068,
6308,
570,
367,
314,
2013,
1145,
1561,
14,
221,
2047,
883,
986,
3663,
1145,
1561,
436,
2985,
911,
1006,
506,
12149,
1901,
282,
2849,
1402,
14,
221,
7242,
365,
9987,
23667,
370,
282,
6308,
570,
2122,
272,
1249,
275,
7369,
21653,
8480,
272,
1768,
275,
283,
3578,
536,
7,
339,
883,
63,
646,
63,
1751,
275,
715,
339,
768,
4653,
1531,
272,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
267,
291,
14,
1419,
63,
504,
63,
1751,
8,
1419,
9,
398,
340,
822,
8,
589,
9,
665,
413,
436,
440,
1511,
459,
452,
63,
15853,
2565,
288,
746,
14393,
480,
9321,
1373,
503,
1655,
2368,
367,
20268,
531,
398,
675,
63,
647,
2180,
17249,
275,
1511,
14,
362,
360,
647,
2180,
17249,
297,
756,
9,
267,
675,
63,
647,
3287,
275,
1511,
14,
362,
360,
647,
3287,
297,
756,
9,
267,
5053,
63,
1419,
275,
283,
1987,
904,
8,
1274,
14,
3020,
59,
18,
5728,
267,
6308,
576,
275,
3550,
63,
3287,
8,
589,
12,
5053,
63,
1419,
29,
2764,
63,
1419,
12,
1011,
1419,
9,
267,
340,
440,
3816,
14,
4521,
19,
26,
288,
6308,
576,
275,
6308,
576,
14,
2143,
360,
1624,
13,
24,
358,
267,
340,
1511,
459,
1199,
493,
2565,
288,
340,
440,
675,
63,
647,
2180,
17249,
436,
440,
675,
63,
647,
3287,
26,
355,
340,
7509,
63,
4521,
3975,
1282,
16566,
5357,
26,
490,
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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
asgardproject/django-kudos
|
setup.py
|
2
|
2100
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, sys
from setuptools import setup, find_packages
from distutils.command.install_data import install_data
from distutils.command.install import INSTALL_SCHEMES
def read(*path):
return open(os.path.join(os.path.abspath(os.path.dirname(__file__)), *path)).read()
kudos = __import__('kudos', {}, {}, [''])
packages, data_files = [], []
root_dir = os.path.dirname(__file__)
if root_dir != '':
os.chdir(root_dir)
kudos_dir = "kudos"
def osx_install_data(install_data):
def finalize_options(self):
self.set_undefined_options("install", ("install_lib", "install_dir"))
install_data.finalize_options(self)
def fullsplit(path, result=None):
if result is None:
result = []
head, tail = os.path.split(path)
if head == '':
return [tail] + result
if head == path:
return result
return fullsplit(head, [tail] + result)
for scheme in INSTALL_SCHEMES.values():
scheme['data'] = scheme['purelib']
for dirpath, dirnames, filenames in os.walk(kudos_dir):
# Ignore dirnames that start with '.'
for i, dirname in enumerate(dirnames):
if dirname.startswith("."): del dirnames[i]
for filename in filenames:
if filename.endswith(".py"):
packages.append('.'.join(fullsplit(dirpath)))
else:
data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
setup(
name = 'asgard-kudos',
version = kudos.__version__,
url = 'http://asgardproject.org/apps/kudos.html',
author = 'Myles Braithwaite',
author_email = 'me@mylesbraithwaite.com',
description = 'A simple kudos application for the Asgard CMS system.',
long_description = read('README.rst'),
license = 'BSD License',
packages = packages,
data_files = data_files,
zip_safe = False,
install_requires = [
'distribute',
],
classifiers = [
'Development Status :: 4 - Beta',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Framework :: Django',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python',
'Topic :: Internet :: WWW/HTTP',
],
)
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
747,
12,
984,
199,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
199,
199,
504,
7065,
14,
1531,
14,
3174,
63,
576,
492,
3907,
63,
576,
199,
504,
7065,
14,
1531,
14,
3174,
492,
20514,
1761,
63,
17859,
654,
199,
199,
318,
1586,
2031,
515,
304,
199,
198,
1107,
1551,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
22159,
627,
515,
4992,
739,
342,
199,
199,
75,
1181,
736,
275,
636,
646,
19734,
75,
1181,
736,
297,
5479,
5479,
788,
1105,
199,
199,
5154,
12,
666,
63,
1725,
275,
990,
942,
199,
199,
1231,
63,
694,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
692,
1738,
63,
694,
1137,
8061,
199,
198,
736,
14,
8563,
8,
1231,
63,
694,
9,
199,
199,
75,
1181,
736,
63,
694,
275,
298,
75,
1181,
736,
2,
199,
199,
318,
747,
88,
63,
3174,
63,
576,
8,
3174,
63,
576,
304,
199,
198,
318,
17284,
63,
1419,
8,
277,
304,
507,
198,
277,
14,
409,
63,
10705,
63,
1419,
480,
3174,
401,
1689,
3174,
63,
773,
401,
298,
3174,
63,
694,
2237,
507,
198,
3174,
63,
576,
14,
14450,
63,
1419,
8,
277,
9,
199,
199,
318,
289,
13072,
16381,
8,
515,
12,
754,
29,
403,
304,
199,
198,
692,
754,
365,
488,
26,
507,
198,
1099,
275,
942,
199,
198,
2993,
12,
9483,
275,
747,
14,
515,
14,
1294,
8,
515,
9,
199,
198,
692,
4854,
508,
8061,
507,
198,
1107,
359,
1521,
61,
435,
754,
199,
198,
692,
4854,
508,
931,
26,
507,
198,
1107,
754,
199,
198,
1107,
289,
13072,
16381,
8,
2993,
12,
359,
1521,
61,
435,
754,
9,
199,
199,
509,
5687,
315,
20514,
1761,
63,
17859,
654,
14,
1459,
837,
199,
198,
5512,
459,
576,
418,
275,
5687,
459,
31882,
418,
421,
199,
509,
20648,
12,
22310,
12,
6203,
315,
747,
14,
7757,
8,
75,
1181,
736,
63,
694,
304,
199,
198,
3,
14092,
22310,
626,
1343,
543,
7815,
199,
198,
509,
284,
12,
9017,
315,
3874,
8,
694,
1247,
304,
507,
198,
692,
9017,
14,
2460,
480,
30946,
2150,
22310,
59,
73,
61,
199,
198,
509,
1788,
315,
6203,
26,
507,
198,
692,
1788,
14,
4130,
9520,
647,
2349,
686,
198,
5154,
14,
740,
5175,
1370,
904,
8,
28418,
16381,
8,
17254,
1724,
507,
198,
2836,
26,
686,
198,
576,
63,
1725,
14,
740,
779,
17254,
12,
359,
736,
14,
515,
14,
904,
8,
17254,
12,
289,
9,
367,
289,
315,
6203,
3934,
199,
199,
2758,
8,
199,
198,
354,
275,
283,
305,
71,
1005,
13,
75,
1181,
736,
297,
199,
198,
1023,
275,
1022,
1181,
736,
855,
1023,
3108,
199,
198,
633,
275,
283,
1014,
921,
305,
71,
1005,
1715,
14,
1308,
15,
5181,
15,
75,
1181,
736,
14,
1360,
297,
8299,
198,
2502,
275,
283,
45,
1775,
83,
32377,
448,
758,
1175,
297,
199,
198,
2502,
63,
2123,
275,
283,
278,
32,
1662,
2978,
7828,
448,
758,
1175,
14,
957,
297,
8299,
198,
1802,
275,
283,
33,
3486,
1022,
1181,
736,
4223,
367,
314,
437,
1226,
1005,
29554,
2656,
3130,
199,
198,
2809,
63,
1802,
275,
1586,
360,
18195,
14,
8332,
659,
8299,
198,
1682,
275,
283,
15400,
844,
297,
8299,
198,
5154,
275,
6117,
12,
199,
198,
576,
63,
1725,
275,
666,
63,
1725,
12,
199,
198,
3065,
63,
3489,
275,
756,
12,
8299,
198,
3174,
63,
6537,
275,
359,
507,
198,
5121,
5414,
266,
297,
199,
198,
467,
8299,
198,
27628,
275,
359,
507,
198,
7,
23753,
9795,
3800,
841,
446,
29521,
297,
507,
198,
7,
8263,
3800,
6001,
9711,
297,
507,
198,
7,
23910,
23975,
3800,
23493,
297,
507,
198,
7,
23699,
6187,
3800,
4403,
1010,
7106,
297,
507,
198,
7,
16442,
3800,
5634,
297,
507,
198,
7,
3761,
3800,
25718,
26330,
3800,
6289,
844,
297,
507,
198,
7,
11411,
8466,
3800,
2018,
297,
507,
198,
7,
12157,
3800,
22026,
3800,
644,
11178,
15,
2856,
297,
199,
198,
467,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
747,
12,
984,
199,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
199,
199,
504,
7065,
14,
1531,
14,
3174,
63,
576,
492,
3907,
63,
576,
199,
504,
7065,
14,
1531,
14,
3174,
492,
20514,
1761,
63,
17859,
654,
199,
199,
318,
1586,
2031,
515,
304,
199,
198,
1107,
1551,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
22159,
627,
515,
4992,
739,
342,
199,
199,
75,
1181,
736,
275,
636,
646,
19734,
75,
1181,
736,
297,
5479,
5479,
788,
1105,
199,
199,
5154,
12,
666,
63,
1725,
275,
990,
942,
199,
199,
1231,
63,
694,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
692,
1738,
63,
694,
1137,
8061,
199,
198,
736,
14,
8563,
8,
1231,
63,
694,
9,
199,
199,
75,
1181,
736,
63,
694,
275,
298,
75,
1181,
736,
2,
199,
199,
318,
747,
88,
63,
3174,
63,
576,
8,
3174,
63,
576,
304,
199,
198,
318,
17284,
63,
1419,
8,
277,
304,
507,
198,
277,
14,
409,
63,
10705,
63,
1419,
480,
3174,
401,
1689,
3174,
63,
773,
401,
298,
3174,
63,
694,
2237,
507,
198,
3174,
63,
576,
14,
14450,
63,
1419,
8,
277,
9,
199,
199,
318,
289,
13072,
16381,
8,
515,
12,
754,
29,
403,
304,
199,
198,
692,
754,
365,
488,
26,
507,
198,
1099,
275,
942,
199,
198,
2993,
12,
9483,
275,
747,
14,
515,
14,
1294,
8,
515,
9,
199,
198,
692,
4854,
508,
8061,
507,
198,
1107,
359,
1521,
61,
435,
754,
199,
198,
692,
4854,
508,
931,
26,
507,
198,
1107,
754,
199,
198,
1107,
289,
13072,
16381,
8,
2993,
12,
359,
1521,
61,
435,
754,
9,
199,
199,
509,
5687,
315,
20514,
1761,
63,
17859,
654,
14,
1459,
837,
199,
198,
5512,
459,
576,
418,
275,
5687,
459,
31882,
418,
421,
199,
509,
20648,
12,
22310,
12,
6203,
315,
747,
14,
7757,
8,
75,
1181,
736,
63,
694,
304,
199,
198,
3,
14092,
22310,
626,
1343,
543,
7815,
199,
198,
509,
284,
12,
9017,
315,
3874,
8,
694,
1247,
304,
507,
198,
692,
9017,
14,
2460,
480,
30946,
2150,
22310,
59,
73,
61,
199,
198,
509,
1788,
315,
6203,
26,
507,
198,
692,
1788,
14,
4130,
9520,
647,
2349,
686,
198,
5154,
14,
740,
5175,
1370,
904,
8,
28418,
16381,
8,
17254,
1724,
507,
198,
2836,
26,
686,
198,
576,
63,
1725,
14,
740,
779,
17254,
12,
359,
736,
14,
515,
14,
904,
8,
17254,
12,
289,
9,
367,
289,
315,
6203,
3934,
199,
199,
2758,
8,
199,
198,
354,
275,
283,
305,
71,
1005,
13,
75,
1181,
736,
297,
199,
198,
1023,
275,
1022,
1181,
736,
855,
1023,
3108,
199,
198,
633,
275,
283,
1014,
921,
305,
71,
1005,
1715,
14,
1308,
15,
5181,
15,
75,
1181,
736,
14,
1360,
297,
8299,
198,
2502,
275,
283,
45,
1775,
83,
32377,
448,
758,
1175,
297,
199,
198,
2502,
63,
2123,
275,
283,
278,
32,
1662,
2978,
7828,
448,
758,
1175,
14,
957,
297,
8299,
198,
1802,
275,
283,
33,
3486,
1022,
1181,
736,
4223,
367,
314,
437,
1226,
1005,
29554,
2656,
3130,
199,
198,
2809,
63,
1802,
275,
1586,
360,
18195,
14,
8332,
659,
8299,
198,
1682,
275,
283,
15400,
844,
297,
8299,
198,
5154,
275,
6117,
12,
199,
198,
576,
63,
1725,
275,
666,
63,
1725,
12,
199,
198,
3065,
63,
3489,
275,
756,
12,
8299,
198,
3174,
63,
6537,
275,
359,
507,
198,
5121,
5414,
266,
297,
199,
198,
467,
8299,
198,
27628,
275,
359,
507,
198,
7,
23753,
9795,
3800,
841,
446,
29521,
297,
507,
198,
7,
8263,
3800,
6001,
9711,
297,
507,
198,
7,
23910,
23975,
3800,
23493,
297,
507,
198,
7,
23699,
6187,
3800,
4403,
1010,
7106,
297,
507,
198,
7,
16442,
3800,
5634,
297,
507,
198,
7,
3761,
3800,
25718,
26330,
3800,
6289,
844,
297,
507,
198,
7,
11411,
8466,
3800,
2018,
297,
507,
198,
7,
12157,
3800,
22026,
3800,
644,
11178,
15,
2856,
297,
199,
198,
467,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
40223114/w16-
|
static/Brython3.1.1-20150328-091302/Lib/posix.py
|
603
|
20904
|
"""This module provides access to operating system functionality that is
standardized by the C Standard and the POSIX standard (a thinly
disguised Unix interface). Refer to the library manual and
corresponding Unix manual entries for more information on calls."""
import datetime
from browser import window
def _randint(a, b):
return int(window.Math.random()*(b-a+1)+a)
F_OK = 0
O_APPEND = 8
O_BINARY = 32768
O_CREAT = 256
O_EXCL = 1024
O_NOINHERIT = 128
O_RANDOM = 16
O_RDONLY = 0
O_RDWR = 2
O_SEQUENTIAL = 32
O_SHORT_LIVED = 4096
O_TEMPORARY = 64
O_TEXT = 16384
O_TRUNC = 512
O_WRONLY = 1
P_DETACH = 4
P_NOWAIT = 1
P_NOWAITO = 3
P_OVERLAY = 2
P_WAIT = 0
R_OK = 4
TMP_MAX = 32767
W_OK = 2
X_OK = 1
class __loader__:
pass
def _exit(*args,**kw):
"""_exit(status)
Exit to the system with specified status, without normal exit processing."""
pass
def _getdiskusage(*args,**kw):
"""_getdiskusage(path) -> (total, free)
Return disk usage statistics about the given path as (total, free) tuple."""
pass
def _getfileinformation(*args,**kw):
pass
def _getfinalpathname(*args,**kw):
pass
def _getfullpathname(*args,**kw):
pass
_have_functions = ['MS_WINDOWS']
def _isdir(*args,**kw):
"""Return true if the pathname refers to an existing directory."""
pass
def abort(*args,**kw):
"""abort() -> does not return!
Abort the interpreter immediately. This 'dumps core' or otherwise fails
in the hardest way possible on the hosting operating system."""
pass
def access(*args,**kw):
"""access(path, mode, *, dir_fd=None, effective_ids=False, follow_symlinks=True)
Use the real uid/gid to test for access to a path. Returns True if granted,
False otherwise.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
If effective_ids is True, access will use the effective uid/gid instead of
the real uid/gid.
If follow_symlinks is False, and the last element of the path is a symbolic
link, access will examine the symbolic link itself instead of the file the
link points to.
dir_fd, effective_ids, and follow_symlinks may not be implemented
on your platform. If they are unavailable, using them will raise a
NotImplementedError.
Note that most operations will use the effective uid/gid, therefore this
routine can be used in a suid/sgid environment to test if the invoking user
has the specified access to the path.
The mode argument can be F_OK to test existence, or the inclusive-OR
of R_OK, W_OK, and X_OK."""
pass
def chdir(*args,**kw):
"""chdir(path)
Change the current working directory to the specified path.
path may always be specified as a string.
On some platforms, path may also be specified as an open file descriptor.
If this functionality is unavailable, using it raises an exception."""
pass
def chmod(*args,**kw):
"""chmod(path, mode, *, dir_fd=None, follow_symlinks=True)
Change the access permissions of a file.
path may always be specified as a string.
On some platforms, path may also be specified as an open file descriptor.
If this functionality is unavailable, using it raises an exception.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
If follow_symlinks is False, and the last element of the path is a symbolic
link, chmod will modify the symbolic link itself instead of the file the
link points to.
It is an error to use dir_fd or follow_symlinks when specifying path as
an open file descriptor.
dir_fd and follow_symlinks may not be implemented on your platform.
If they are unavailable, using them will raise a NotImplementedError."""
pass
def close(*args,**kw):
"""close(fd)
Close a file descriptor (for low level IO)."""
pass
def closerange(*args,**kw):
"""closerange(fd_low, fd_high)
Closes all file descriptors in [fd_low, fd_high), ignoring errors."""
pass
def device_encoding(*args,**kw):
"""device_encoding(fd) -> str
Return a string describing the encoding of the device
if the output is a terminal; else return None."""
pass
def dup(*args,**kw):
"""dup(fd) -> fd2
Return a duplicate of a file descriptor."""
pass
def dup2(*args,**kw):
"""dup2(old_fd, new_fd)
Duplicate file descriptor."""
pass
environ = {'PYTHONUSERBASE': ' '}
error = OSError
def execv(*args,**kw):
"""execv(path, args)
Execute an executable path with arguments, replacing current process.
path: path of executable file
args: tuple or list of strings"""
pass
def execve(*args,**kw):
"""execve(path, args, env)
Execute a path with arguments and environment, replacing current process.
path: path of executable file
args: tuple or list of arguments
env: dictionary of strings mapping to strings
On some platforms, you may specify an open file descriptor for path;
execve will execute the program the file descriptor is open to.
If this functionality is unavailable, using it raises NotImplementedError."""
pass
def fstat(*args,**kw):
"""fstat(fd) -> stat result
Like stat(), but for an open file descriptor.
Equivalent to stat(fd=fd)."""
pass
def fsync(*args,**kw):
"""fsync(fildes)
force write of file with filedescriptor to disk."""
pass
def get_terminal_size(*args,**kw):
"""Return the size of the terminal window as (columns, lines).
The optional argument fd (default standard output) specifies
which file descriptor should be queried.
If the file descriptor is not connected to a terminal, an OSError
is thrown.
This function will only be defined if an implementation is
available for this system.
shutil.get_terminal_size is the high-level function which should
normally be used, os.get_terminal_size is the low-level implementation."""
pass
def getcwd(*args,**kw):
"""getcwd() -> path
Return a unicode string representing the current working directory."""
return __BRYTHON__.brython_path # XXX fix me
def getcwdb(*args,**kw):
"""getcwdb() -> path
Return a bytes string representing the current working directory."""
pass
def getlogin(*args,**kw):
"""getlogin() -> string
Return the actual login name."""
pass
def getpid(*args,**kw):
"""getpid() -> pid
Return the current process id"""
return 0
def getppid(*args,**kw):
"""getppid() -> ppid
Return the parent's process id. If the parent process has already exited,
Windows machines will still return its id; others systems will return the id
of the 'init' process (1)."""
pass
def isatty(*args,**kw):
"""isatty(fd) -> bool
Return True if the file descriptor 'fd' is an open file descriptor
connected to the slave end of a terminal."""
pass
def kill(*args,**kw):
"""kill(pid, sig)
Kill a process with a signal."""
pass
def link(*args,**kw):
"""link(src, dst, *, src_dir_fd=None, dst_dir_fd=None, follow_symlinks=True)
Create a hard link to a file.
If either src_dir_fd or dst_dir_fd is not None, it should be a file
descriptor open to a directory, and the respective path string (src or dst)
should be relative; the path will then be relative to that directory.
If follow_symlinks is False, and the last element of src is a symbolic
link, link will create a link to the symbolic link itself instead of the
file the link points to.
src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your
platform. If they are unavailable, using them will raise a
NotImplementedError."""
pass
def listdir(*args,**kw):
"""listdir(path='.') -> list_of_filenames
Return a list containing the names of the files in the directory.
The list is in arbitrary order. It does not include the special
entries '.' and '..' even if they are present in the directory.
path can be specified as either str or bytes. If path is bytes,
the filenames returned will also be bytes; in all other circumstances
the filenames returned will be str.
On some platforms, path may also be specified as an open file descriptor;
the file descriptor must refer to a directory.
If this functionality is unavailable, using it raises NotImplementedError."""
pass
def lseek(*args,**kw):
"""lseek(fd, pos, how) -> newpos
Set the current position of a file descriptor.
Return the new cursor position in bytes, starting from the beginning."""
pass
def lstat(*args,**kw):
"""lstat(path, *, dir_fd=None) -> stat result
Like stat(), but do not follow symbolic links.
Equivalent to stat(path, follow_symlinks=False)."""
return stat_result()
def mkdir(*args,**kw):
"""mkdir(path, mode=0o777, *, dir_fd=None)
Create a directory.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError.
The mode argument is ignored on Windows."""
pass
def open(*args,**kw):
"""open(path, flags, mode=0o777, *, dir_fd=None)
Open a file for low level IO. Returns a file handle (integer).
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError."""
pass
def pipe(*args,**kw):
"""pipe() -> (read_end, write_end)
Create a pipe."""
pass
def putenv(*args,**kw):
"""putenv(key, value)
Change or add an environment variable."""
pass
def read(*args,**kw):
"""read(fd, buffersize) -> string
Read a file descriptor."""
pass
def readlink(*args,**kw):
"""readlink(path, *, dir_fd=None) -> path
Return a string representing the path to which the symbolic link points.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError."""
pass
def remove(*args,**kw):
"""remove(path, *, dir_fd=None)
Remove a file (same as unlink()).
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError."""
pass
def rename(*args,**kw):
"""rename(src, dst, *, src_dir_fd=None, dst_dir_fd=None)
Rename a file or directory.
If either src_dir_fd or dst_dir_fd is not None, it should be a file
descriptor open to a directory, and the respective path string (src or dst)
should be relative; the path will then be relative to that directory.
src_dir_fd and dst_dir_fd, may not be implemented on your platform.
If they are unavailable, using them will raise a NotImplementedError."""
pass
def replace(*args,**kw):
"""replace(src, dst, *, src_dir_fd=None, dst_dir_fd=None)
Rename a file or directory, overwriting the destination.
If either src_dir_fd or dst_dir_fd is not None, it should be a file
descriptor open to a directory, and the respective path string (src or dst)
should be relative; the path will then be relative to that directory.
src_dir_fd and dst_dir_fd, may not be implemented on your platform.
If they are unavailable, using them will raise a NotImplementedError."""
pass
def rmdir(*args,**kw):
"""rmdir(path, *, dir_fd=None)
Remove a directory.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError."""
pass
def spawnv(*args,**kw):
"""spawnv(mode, path, args)
Execute the program 'path' in a new process.
mode: mode of process creation
path: path of executable file
args: tuple or list of strings"""
pass
def spawnve(*args,**kw):
"""spawnve(mode, path, args, env)
Execute the program 'path' in a new process.
mode: mode of process creation
path: path of executable file
args: tuple or list of arguments
env: dictionary of strings mapping to strings"""
pass
def startfile(*args,**kw):
"""startfile(filepath [, operation]) - Start a file with its associated application.
When "operation" is not specified or "open", this acts like
double-clicking the file in Explorer, or giving the file name as an
argument to the DOS "start" command: the file is opened with whatever
application (if any) its extension is associated.
When another "operation" is given, it specifies what should be done with
the file. A typical operation is "print".
startfile returns as soon as the associated application is launched.
There is no option to wait for the application to close, and no way
to retrieve the application's exit status.
The filepath is relative to the current directory. If you want to use
an absolute path, make sure the first character is not a slash ("/");
the underlying Win32 ShellExecute function doesn't work if it is."""
pass
def stat(*args,**kw):
"""stat(path, *, dir_fd=None, follow_symlinks=True) -> stat result
Perform a stat system call on the given path.
path may be specified as either a string or as an open file descriptor.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be supported on your platform; if it is unavailable, using
it will raise a NotImplementedError.
If follow_symlinks is False, and the last element of the path is a symbolic
link, stat will examine the symbolic link itself instead of the file the
link points to.
It is an error to use dir_fd or follow_symlinks when specifying path as
an open file descriptor."""
return stat_result()
def stat_float_times(*args,**kw):
"""stat_float_times([newval]) -> oldval
Determine whether os.[lf]stat represents time stamps as float objects.
If newval is True, future calls to stat() return floats, if it is False,
future calls return ints.
If newval is omitted, return the current setting.
"""
pass
class stat_result:
def __init__(self):
"""st_mode - protection bits,
st_ino - inode number,
st_dev - device,
st_nlink - number of hard links,
st_uid - user id of owner,
st_gid - group id of owner,
st_size - size of file, in bytes,
st_atime - time of most recent access expressed in seconds,
st_mtime - time of most recent content modification expressed in
seconds,
st_ctime - platform dependent; time of most recent metadata change on
Unix, or the time of creation on Windows, expressed in seconds
st_atime_ns - time of most recent access expressed in nanoseconds as an
integer,
st_mtime_ns - time of most recent content modification expressed in
nanoseconds as an integer,
st_ctime_ns - platform dependent; time of most recent metadata change
on Unix, or the time of creation on Windows, expressed in
nanoseconds as an integer """
# Brython : fake values
self.st_atime = datetime.datetime.now()
self.st_mtime = self.st_ctime = self.st_atime_ns = \
self.st_mtime_ns = self.st_ctime_ns = self.st_atime
self.st_uid = self.st_gid = self.st_ino = -1
self.st_mode = 0
self.st_size = 1
class statvfs_result:
pass
def strerror(*args,**kw):
"""strerror(code) -> string
Translate an error code to a message string."""
pass
def symlink(*args,**kw):
"""symlink(src, dst, target_is_directory=False, *, dir_fd=None)
Create a symbolic link pointing to src named dst.
target_is_directory is required on Windows if the target is to be
interpreted as a directory. (On Windows, symlink requires
Windows 6.0 or greater, and raises a NotImplementedError otherwise.)
target_is_directory is ignored on non-Windows platforms.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError."""
pass
def system(*args,**kw):
"""system(command) -> exit_status
Execute the command (a string) in a subshell."""
pass
class terminal_size:
pass
def times(*args,**kw):
"""times() -> times_result
Return an object containing floating point numbers indicating process
times. The object behaves like a named tuple with these fields:
(utime, stime, cutime, cstime, elapsed_time)"""
pass
class times_result:
pass
def umask(*args,**kw):
"""umask(new_mask) -> old_mask
Set the current numeric umask and return the previous umask."""
pass
class uname_result:
pass
def unlink(*args,**kw):
"""unlink(path, *, dir_fd=None)
Remove a file (same as remove()).
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
If it is unavailable, using it will raise a NotImplementedError."""
pass
def urandom(n):
"""urandom(n) -> str
Return n random bytes suitable for cryptographic use."""
randbytes= [_randint(0,255) for i in range(n)]
return bytes(randbytes)
def utime(*args,**kw):
"""utime(path, times=None, *, ns=None, dir_fd=None, follow_symlinks=True) Set the access and modified time of path.
path may always be specified as a string.
On some platforms, path may also be specified as an open file descriptor.
If this functionality is unavailable, using it raises an exception.
If times is not None, it must be a tuple (atime, mtime);
atime and mtime should be expressed as float seconds since the epoch.
If ns is not None, it must be a tuple (atime_ns, mtime_ns);
atime_ns and mtime_ns should be expressed as integer nanoseconds
since the epoch.
If both times and ns are None, utime uses the current time.
Specifying tuples for both times and ns is an error.
If dir_fd is not None, it should be a file descriptor open to a directory,
and path should be relative; path will then be relative to that directory.
If follow_symlinks is False, and the last element of the path is a symbolic
link, utime will modify the symbolic link itself instead of the file the
link points to.
It is an error to use dir_fd or follow_symlinks when specifying path
as an open file descriptor.
dir_fd and follow_symlinks may not be available on your platform.
If they are unavailable, using them will raise a NotImplementedError."""
pass
def waitpid(*args,**kw):
"""waitpid(pid, options) -> (pid, status << 8)
Wait for completion of a given process. options is ignored on Windows."""
pass
def write(*args,**kw):
"""write(fd, string) -> byteswritten
Write a string to a file descriptor."""
pass
## put WIFSIGNALED here. its needed by os module, and os module imports all
## functions in this module
def WIFSIGNALED(a):
return False
def WTERMSIG(status):
return 0
def WIFSIGNALED(status):
"Return True if the process exited due to a signal, otherwise return False"
return False
def WIFEXITED(status):
return False
def WEXITSTATUS(status):
pass
def WNOHANG():
return (0,0)
|
gpl-3.0
|
[
624,
2765,
859,
6571,
2879,
370,
17406,
2656,
9330,
626,
365,
199,
7935,
18980,
7068,
701,
314,
445,
9739,
436,
314,
18169,
4465,
334,
65,
30758,
590,
199,
328,
1226,
85,
9096,
13074,
3217,
680,
221,
21751,
370,
314,
3555,
8722,
436,
199,
989,
31137,
13074,
8722,
4811,
367,
1655,
2556,
641,
4882,
1041,
199,
199,
646,
2197,
199,
199,
504,
7042,
492,
4353,
199,
199,
318,
485,
8393,
8,
65,
12,
330,
304,
272,
372,
1109,
8,
3806,
14,
18568,
14,
2355,
342,
5830,
66,
13,
65,
11,
17,
6393,
65,
9,
1362,
199,
38,
63,
3593,
275,
378,
199,
199,
47,
63,
25248,
275,
1695,
199,
199,
47,
63,
13246,
275,
20939,
2333,
199,
199,
47,
63,
32120,
275,
7633,
199,
199,
47,
63,
29647,
275,
6619,
199,
199,
47,
63,
2826,
568,
3452,
649,
275,
7960,
199,
199,
47,
63,
27644,
10462,
275,
3193,
199,
199,
47,
63,
15543,
10452,
275,
378,
199,
199,
47,
63,
15543,
6524,
275,
499,
199,
199,
47,
63,
9020,
275,
4337,
199,
199,
47,
63,
13003,
63,
2673,
14112,
275,
17125,
199,
199,
47,
63,
12510,
726,
4392,
275,
5049,
199,
199,
47,
63,
3876,
275,
24619,
1349,
199,
199,
47,
63,
22346,
275,
10574,
199,
199,
47,
63,
6524,
10452,
275,
413,
199,
199,
48,
63,
36,
15808,
1244,
275,
841,
199,
199,
48,
63,
2826,
12458,
275,
413,
199,
199,
48,
63,
2826,
12458,
47,
275,
650,
199,
199,
48,
63,
14336,
16897,
275,
499,
199,
199,
48,
63,
12458,
275,
378,
199,
199,
50,
63,
3593,
275,
841,
199,
199,
17983,
63,
4283,
275,
20939,
1822,
199,
199,
55,
63,
3593,
275,
499,
199,
199,
56,
63,
3593,
275,
413,
199,
199,
533,
636,
3422,
10651,
272,
986,
199,
199,
318,
485,
2224,
2031,
589,
12663,
829,
304,
272,
408,
63,
2224,
8,
1205,
9,
14821,
18704,
370,
314,
2656,
543,
2013,
2004,
12,
1928,
3293,
4458,
6661,
1041,
272,
986,
199,
199,
318,
485,
362,
4032,
3807,
2031,
589,
12663,
829,
304,
272,
408,
63,
362,
4032,
3807,
8,
515,
9,
1035,
334,
2923,
12,
2867,
9,
14821,
1432,
4543,
4503,
11076,
3595,
314,
1627,
931,
465,
334,
2923,
12,
2867,
9,
2008,
1041,
272,
986,
199,
199,
318,
485,
23462,
11697,
2031,
589,
12663,
829,
304,
272,
986,
199,
199,
318,
485,
362,
5094,
12445,
2031,
589,
12663,
829,
304,
272,
986,
199,
199,
318,
485,
362,
2861,
12445,
2031,
589,
12663,
829,
304,
272,
986,
199,
199,
63,
7804,
63,
5777,
275,
788,
3053,
63,
20509,
418,
199,
199,
318,
485,
6027,
2031,
589,
12663,
829,
304,
272,
408,
1767,
2549,
340,
314,
11776,
15724,
370,
376,
3411,
2082,
1041,
272,
986,
199,
199,
318,
12004,
2031,
589,
12663,
829,
304,
272,
408,
13845,
342,
1035,
1630,
440,
372,
1,
14821,
31455,
314,
12693,
9939,
14,
221,
961,
283,
4180,
6170,
7,
503,
4257,
6918,
272,
315,
314,
12159,
2614,
4340,
3962,
641,
314,
1591,
316,
17406,
2656,
1041,
272,
986,
199,
199,
318,
2879,
2031,
589,
12663,
829,
304,
272,
408,
2732,
8,
515,
12,
818,
12,
9889,
2935,
63,
2592,
29,
403,
12,
15826,
63,
1580,
29,
797,
12,
2035,
63,
19522,
29,
549,
9,
14821,
3645,
314,
3363,
1747,
15,
8787,
370,
511,
367,
2879,
370,
282,
931,
14,
221,
1803,
715,
340,
10009,
12,
272,
756,
4257,
14,
2286,
982,
2935,
63,
2592,
365,
440,
488,
12,
652,
1077,
506,
282,
570,
5872,
1551,
370,
282,
2082,
12,
489,
436,
931,
1077,
506,
3847,
27,
931,
911,
2066,
506,
3847,
370,
626,
2082,
14,
272,
982,
15826,
63,
1580,
365,
715,
12,
2879,
911,
675,
314,
15826,
1747,
15,
8787,
3140,
402,
489,
314,
3363,
1747,
15,
8787,
14,
272,
982,
2035,
63,
19522,
365,
756,
12,
436,
314,
2061,
1819,
402,
314,
931,
365,
282,
13673,
489,
2142,
12,
2879,
911,
31758,
314,
13673,
2142,
6337,
3140,
402,
314,
570,
314,
489,
2142,
4501,
370,
14,
272,
2935,
63,
2592,
12,
15826,
63,
1580,
12,
436,
2035,
63,
19522,
1443,
440,
506,
6366,
489,
641,
2195,
4298,
14,
221,
982,
2985,
787,
18735,
12,
1808,
3062,
911,
746,
282,
489,
4279,
14,
2286,
3390,
626,
4750,
5331,
911,
675,
314,
15826,
1747,
15,
8787,
12,
16119,
642,
489,
12981,
883,
506,
1202,
315,
282,
308,
1535,
15,
1226,
344,
3734,
370,
511,
340,
314,
26750,
922,
489,
965,
314,
2013,
2879,
370,
314,
931,
14,
272,
710,
818,
1423,
883,
506,
481,
63,
3593,
370,
511,
23780,
12,
503,
314,
20728,
13,
726,
489,
402,
820,
63,
3593,
12,
644,
63,
3593,
12,
436,
1323,
63,
3593,
1041,
272,
986,
199,
199,
318,
13097,
2031,
589,
12663,
829,
304,
272,
408,
8563,
8,
515,
9,
14821,
7743,
314,
1453,
6449,
2082,
370,
314,
2013,
931,
14,
2286,
931,
1443,
3544,
506,
2013,
465,
282,
1059,
14,
272,
4068,
2005,
10677,
12,
931,
1443,
2597,
506,
2013,
465,
376,
1551,
570,
5872,
14,
489,
982,
642,
9330,
365,
18735,
12,
1808,
652,
6534,
376,
1919,
1041,
272,
986,
199,
199,
318,
30106,
2031,
589,
12663,
829,
304,
272,
408,
11693,
8,
515,
12,
818,
12,
9889,
2935,
63,
2592,
29,
403,
12,
2035,
63,
19522,
29,
549,
9,
14821,
7743,
314,
2879,
3443,
402,
282,
570,
14,
2286,
931,
1443,
3544,
506,
2013,
465,
282,
1059,
14,
272,
4068,
2005,
10677,
12,
931,
1443,
2597,
506,
2013,
465,
376,
1551,
570,
5872,
14,
489,
982,
642,
9330,
365,
18735,
12,
1808,
652,
6534,
376,
1919,
14,
272,
982,
2935,
63,
2592,
365,
440,
488,
12,
652,
1077,
506,
282,
570,
5872,
1551,
370,
282,
2082,
12,
489,
436,
931,
1077,
506,
3847,
27,
931,
911,
2066,
506,
3847,
370,
626,
2082,
14,
272,
982,
2035,
63,
19522,
365,
756,
12,
436,
314,
2061,
1819,
402,
314,
931,
365,
282,
13673,
489,
2142,
12,
30106,
911,
2811,
314,
13673,
2142,
6337,
3140,
402,
314,
570,
314,
489,
2142,
4501,
370,
14,
272,
2779,
365,
376,
1125,
370,
675,
2935,
63,
2592,
503,
2035,
63,
19522,
1380,
9176,
931,
465,
489,
376,
1551,
570,
5872,
14,
272,
2935,
63,
2592,
436,
2035,
63,
19522,
1443,
440,
506
] |
[
2765,
859,
6571,
2879,
370,
17406,
2656,
9330,
626,
365,
199,
7935,
18980,
7068,
701,
314,
445,
9739,
436,
314,
18169,
4465,
334,
65,
30758,
590,
199,
328,
1226,
85,
9096,
13074,
3217,
680,
221,
21751,
370,
314,
3555,
8722,
436,
199,
989,
31137,
13074,
8722,
4811,
367,
1655,
2556,
641,
4882,
1041,
199,
199,
646,
2197,
199,
199,
504,
7042,
492,
4353,
199,
199,
318,
485,
8393,
8,
65,
12,
330,
304,
272,
372,
1109,
8,
3806,
14,
18568,
14,
2355,
342,
5830,
66,
13,
65,
11,
17,
6393,
65,
9,
1362,
199,
38,
63,
3593,
275,
378,
199,
199,
47,
63,
25248,
275,
1695,
199,
199,
47,
63,
13246,
275,
20939,
2333,
199,
199,
47,
63,
32120,
275,
7633,
199,
199,
47,
63,
29647,
275,
6619,
199,
199,
47,
63,
2826,
568,
3452,
649,
275,
7960,
199,
199,
47,
63,
27644,
10462,
275,
3193,
199,
199,
47,
63,
15543,
10452,
275,
378,
199,
199,
47,
63,
15543,
6524,
275,
499,
199,
199,
47,
63,
9020,
275,
4337,
199,
199,
47,
63,
13003,
63,
2673,
14112,
275,
17125,
199,
199,
47,
63,
12510,
726,
4392,
275,
5049,
199,
199,
47,
63,
3876,
275,
24619,
1349,
199,
199,
47,
63,
22346,
275,
10574,
199,
199,
47,
63,
6524,
10452,
275,
413,
199,
199,
48,
63,
36,
15808,
1244,
275,
841,
199,
199,
48,
63,
2826,
12458,
275,
413,
199,
199,
48,
63,
2826,
12458,
47,
275,
650,
199,
199,
48,
63,
14336,
16897,
275,
499,
199,
199,
48,
63,
12458,
275,
378,
199,
199,
50,
63,
3593,
275,
841,
199,
199,
17983,
63,
4283,
275,
20939,
1822,
199,
199,
55,
63,
3593,
275,
499,
199,
199,
56,
63,
3593,
275,
413,
199,
199,
533,
636,
3422,
10651,
272,
986,
199,
199,
318,
485,
2224,
2031,
589,
12663,
829,
304,
272,
408,
63,
2224,
8,
1205,
9,
14821,
18704,
370,
314,
2656,
543,
2013,
2004,
12,
1928,
3293,
4458,
6661,
1041,
272,
986,
199,
199,
318,
485,
362,
4032,
3807,
2031,
589,
12663,
829,
304,
272,
408,
63,
362,
4032,
3807,
8,
515,
9,
1035,
334,
2923,
12,
2867,
9,
14821,
1432,
4543,
4503,
11076,
3595,
314,
1627,
931,
465,
334,
2923,
12,
2867,
9,
2008,
1041,
272,
986,
199,
199,
318,
485,
23462,
11697,
2031,
589,
12663,
829,
304,
272,
986,
199,
199,
318,
485,
362,
5094,
12445,
2031,
589,
12663,
829,
304,
272,
986,
199,
199,
318,
485,
362,
2861,
12445,
2031,
589,
12663,
829,
304,
272,
986,
199,
199,
63,
7804,
63,
5777,
275,
788,
3053,
63,
20509,
418,
199,
199,
318,
485,
6027,
2031,
589,
12663,
829,
304,
272,
408,
1767,
2549,
340,
314,
11776,
15724,
370,
376,
3411,
2082,
1041,
272,
986,
199,
199,
318,
12004,
2031,
589,
12663,
829,
304,
272,
408,
13845,
342,
1035,
1630,
440,
372,
1,
14821,
31455,
314,
12693,
9939,
14,
221,
961,
283,
4180,
6170,
7,
503,
4257,
6918,
272,
315,
314,
12159,
2614,
4340,
3962,
641,
314,
1591,
316,
17406,
2656,
1041,
272,
986,
199,
199,
318,
2879,
2031,
589,
12663,
829,
304,
272,
408,
2732,
8,
515,
12,
818,
12,
9889,
2935,
63,
2592,
29,
403,
12,
15826,
63,
1580,
29,
797,
12,
2035,
63,
19522,
29,
549,
9,
14821,
3645,
314,
3363,
1747,
15,
8787,
370,
511,
367,
2879,
370,
282,
931,
14,
221,
1803,
715,
340,
10009,
12,
272,
756,
4257,
14,
2286,
982,
2935,
63,
2592,
365,
440,
488,
12,
652,
1077,
506,
282,
570,
5872,
1551,
370,
282,
2082,
12,
489,
436,
931,
1077,
506,
3847,
27,
931,
911,
2066,
506,
3847,
370,
626,
2082,
14,
272,
982,
15826,
63,
1580,
365,
715,
12,
2879,
911,
675,
314,
15826,
1747,
15,
8787,
3140,
402,
489,
314,
3363,
1747,
15,
8787,
14,
272,
982,
2035,
63,
19522,
365,
756,
12,
436,
314,
2061,
1819,
402,
314,
931,
365,
282,
13673,
489,
2142,
12,
2879,
911,
31758,
314,
13673,
2142,
6337,
3140,
402,
314,
570,
314,
489,
2142,
4501,
370,
14,
272,
2935,
63,
2592,
12,
15826,
63,
1580,
12,
436,
2035,
63,
19522,
1443,
440,
506,
6366,
489,
641,
2195,
4298,
14,
221,
982,
2985,
787,
18735,
12,
1808,
3062,
911,
746,
282,
489,
4279,
14,
2286,
3390,
626,
4750,
5331,
911,
675,
314,
15826,
1747,
15,
8787,
12,
16119,
642,
489,
12981,
883,
506,
1202,
315,
282,
308,
1535,
15,
1226,
344,
3734,
370,
511,
340,
314,
26750,
922,
489,
965,
314,
2013,
2879,
370,
314,
931,
14,
272,
710,
818,
1423,
883,
506,
481,
63,
3593,
370,
511,
23780,
12,
503,
314,
20728,
13,
726,
489,
402,
820,
63,
3593,
12,
644,
63,
3593,
12,
436,
1323,
63,
3593,
1041,
272,
986,
199,
199,
318,
13097,
2031,
589,
12663,
829,
304,
272,
408,
8563,
8,
515,
9,
14821,
7743,
314,
1453,
6449,
2082,
370,
314,
2013,
931,
14,
2286,
931,
1443,
3544,
506,
2013,
465,
282,
1059,
14,
272,
4068,
2005,
10677,
12,
931,
1443,
2597,
506,
2013,
465,
376,
1551,
570,
5872,
14,
489,
982,
642,
9330,
365,
18735,
12,
1808,
652,
6534,
376,
1919,
1041,
272,
986,
199,
199,
318,
30106,
2031,
589,
12663,
829,
304,
272,
408,
11693,
8,
515,
12,
818,
12,
9889,
2935,
63,
2592,
29,
403,
12,
2035,
63,
19522,
29,
549,
9,
14821,
7743,
314,
2879,
3443,
402,
282,
570,
14,
2286,
931,
1443,
3544,
506,
2013,
465,
282,
1059,
14,
272,
4068,
2005,
10677,
12,
931,
1443,
2597,
506,
2013,
465,
376,
1551,
570,
5872,
14,
489,
982,
642,
9330,
365,
18735,
12,
1808,
652,
6534,
376,
1919,
14,
272,
982,
2935,
63,
2592,
365,
440,
488,
12,
652,
1077,
506,
282,
570,
5872,
1551,
370,
282,
2082,
12,
489,
436,
931,
1077,
506,
3847,
27,
931,
911,
2066,
506,
3847,
370,
626,
2082,
14,
272,
982,
2035,
63,
19522,
365,
756,
12,
436,
314,
2061,
1819,
402,
314,
931,
365,
282,
13673,
489,
2142,
12,
30106,
911,
2811,
314,
13673,
2142,
6337,
3140,
402,
314,
570,
314,
489,
2142,
4501,
370,
14,
272,
2779,
365,
376,
1125,
370,
675,
2935,
63,
2592,
503,
2035,
63,
19522,
1380,
9176,
931,
465,
489,
376,
1551,
570,
5872,
14,
272,
2935,
63,
2592,
436,
2035,
63,
19522,
1443,
440,
506,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hectord/lettuce
|
tests/integration/lib/Django-1.3/django/conf/locale/nn/formats.py
|
685
|
1657
|
# -*- encoding: utf-8 -*-
# This file is distributed under the same license as the Django package.
#
# The *_FORMAT strings use the Django date format syntax,
# see http://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 http://docs.python.org/library/datetime.html#strftime-strptime-behavior
DATE_INPUT_FORMATS = (
'%Y-%m-%d', '%d.%m.%Y', '%d.%m.%y', # '2006-10-25', '25.10.2006', '25.10.06'
'%Y-%m-%d', # '2006-10-25',
# '%d. %b %Y', '%d %b %Y', # '25. okt 2006', '25 okt 2006'
# '%d. %b. %Y', '%d %b. %Y', # '25. okt. 2006', '25 okt. 2006'
# '%d. %B %Y', '%d %B %Y', # '25. oktober 2006', '25 oktober 2006'
)
TIME_INPUT_FORMATS = (
'%H:%M:%S', # '14:30:59'
'%H:%M', # '14:30'
)
DATETIME_INPUT_FORMATS = (
'%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59'
'%Y-%m-%d %H:%M', # '2006-10-25 14:30'
'%Y-%m-%d', # '2006-10-25'
'%Y-%m-%d', # '2006-10-25'
'%d.%m.%Y %H:%M:%S', # '25.10.2006 14:30:59'
'%d.%m.%Y %H:%M', # '25.10.2006 14:30'
'%d.%m.%Y', # '25.10.2006'
'%d.%m.%y %H:%M:%S', # '25.10.06 14:30:59'
'%d.%m.%y %H:%M', # '25.10.06 14:30'
'%d.%m.%y', # '25.10.06'
)
DECIMAL_SEPARATOR = ','
THOUSAND_SEPARATOR = ' '
NUMBER_GROUPING = 3
|
gpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
961,
570,
365,
1854,
1334,
314,
2011,
4190,
465,
314,
5634,
2559,
14,
199,
3,
199,
199,
3,
710,
20841,
4807,
3326,
675,
314,
5634,
1434,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
10372,
12645,
602,
199,
5390,
63,
4807,
275,
283,
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,
327,
32740,
199,
199,
3,
710,
20841,
7321,
63,
14019,
3326,
675,
314,
2018,
14053,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
1548,
14,
1308,
15,
4342,
15,
2083,
14,
1360,
3,
6205,
13,
9866,
13,
17537,
199,
5390,
63,
7321,
63,
14019,
275,
334,
272,
1543,
57,
3295,
77,
3295,
68,
297,
1543,
68,
4111,
77,
4111,
57,
297,
1543,
68,
4111,
77,
4111,
89,
297,
327,
283,
7968,
13,
709,
13,
821,
297,
283,
821,
14,
709,
14,
7968,
297,
283,
821,
14,
709,
14,
1690,
7,
272,
1543,
57,
3295,
77,
3295,
68,
297,
12793,
327,
283,
7968,
13,
709,
13,
821,
297,
272,
327,
1543,
68,
14,
450,
66,
450,
57,
297,
1543,
68,
450,
66,
450,
57,
297,
3322,
327,
283,
821,
14,
4112,
84,
8315,
297,
283,
821,
4112,
84,
8315,
7,
272,
327,
1543,
68,
14,
450,
66,
14,
450,
57,
297,
1543,
68,
450,
66,
14,
450,
57,
297,
3515,
327,
283,
821,
14,
4112,
84,
14,
8315,
297,
283,
821,
4112,
84,
14,
8315,
7,
272,
327,
1543,
68,
14,
450,
34,
450,
57,
297,
1543,
68,
450,
34,
450,
57,
297,
3322,
327,
283,
821,
14,
4112,
475,
605,
8315,
297,
283,
821,
4112,
475,
605,
8315,
7,
199,
9,
199,
4961,
63,
7321,
63,
14019,
275,
334,
272,
1543,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
1079,
26,
1216,
26,
1427,
7,
272,
1543,
40,
2689,
45,
297,
258,
327,
283,
1079,
26,
1216,
7,
199,
9,
199,
12488,
63,
7321,
63,
14019,
275,
334,
272,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
7968,
13,
709,
13,
821,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
297,
263,
327,
283,
7968,
13,
709,
13,
821,
4329,
26,
1216,
7,
272,
1543,
57,
3295,
77,
3295,
68,
297,
4519,
327,
283,
7968,
13,
709,
13,
821,
7,
272,
1543,
57,
3295,
77,
3295,
68,
297,
4519,
327,
283,
7968,
13,
709,
13,
821,
7,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
297,
263,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
7,
272,
1543,
68,
4111,
77,
4111,
57,
297,
4519,
327,
283,
821,
14,
709,
14,
7968,
7,
272,
1543,
68,
4111,
77,
4111,
89,
450,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
4111,
77,
4111,
89,
450,
40,
2689,
45,
297,
263,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
7,
272,
1543,
68,
4111,
77,
4111,
89,
297,
4519,
327,
283,
821,
14,
709,
14,
1690,
7,
199,
9,
199,
23925,
63,
15828,
275,
13647,
199,
28714,
63,
15828,
275,
283,
283,
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
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
961,
570,
365,
1854,
1334,
314,
2011,
4190,
465,
314,
5634,
2559,
14,
199,
3,
199,
199,
3,
710,
20841,
4807,
3326,
675,
314,
5634,
1434,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
10372,
12645,
602,
199,
5390,
63,
4807,
275,
283,
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,
327,
32740,
199,
199,
3,
710,
20841,
7321,
63,
14019,
3326,
675,
314,
2018,
14053,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
1548,
14,
1308,
15,
4342,
15,
2083,
14,
1360,
3,
6205,
13,
9866,
13,
17537,
199,
5390,
63,
7321,
63,
14019,
275,
334,
272,
1543,
57,
3295,
77,
3295,
68,
297,
1543,
68,
4111,
77,
4111,
57,
297,
1543,
68,
4111,
77,
4111,
89,
297,
327,
283,
7968,
13,
709,
13,
821,
297,
283,
821,
14,
709,
14,
7968,
297,
283,
821,
14,
709,
14,
1690,
7,
272,
1543,
57,
3295,
77,
3295,
68,
297,
12793,
327,
283,
7968,
13,
709,
13,
821,
297,
272,
327,
1543,
68,
14,
450,
66,
450,
57,
297,
1543,
68,
450,
66,
450,
57,
297,
3322,
327,
283,
821,
14,
4112,
84,
8315,
297,
283,
821,
4112,
84,
8315,
7,
272,
327,
1543,
68,
14,
450,
66,
14,
450,
57,
297,
1543,
68,
450,
66,
14,
450,
57,
297,
3515,
327,
283,
821,
14,
4112,
84,
14,
8315,
297,
283,
821,
4112,
84,
14,
8315,
7,
272,
327,
1543,
68,
14,
450,
34,
450,
57,
297,
1543,
68,
450,
34,
450,
57,
297,
3322,
327,
283,
821,
14,
4112,
475,
605,
8315,
297,
283,
821,
4112,
475,
605,
8315,
7,
199,
9,
199,
4961,
63,
7321,
63,
14019,
275,
334,
272,
1543,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
1079,
26,
1216,
26,
1427,
7,
272,
1543,
40,
2689,
45,
297,
258,
327,
283,
1079,
26,
1216,
7,
199,
9,
199,
12488,
63,
7321,
63,
14019,
275,
334,
272,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
7968,
13,
709,
13,
821,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
297,
263,
327,
283,
7968,
13,
709,
13,
821,
4329,
26,
1216,
7,
272,
1543,
57,
3295,
77,
3295,
68,
297,
4519,
327,
283,
7968,
13,
709,
13,
821,
7,
272,
1543,
57,
3295,
77,
3295,
68,
297,
4519,
327,
283,
7968,
13,
709,
13,
821,
7,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
297,
263,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
7,
272,
1543,
68,
4111,
77,
4111,
57,
297,
4519,
327,
283,
821,
14,
709,
14,
7968,
7,
272,
1543,
68,
4111,
77,
4111,
89,
450,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
4111,
77,
4111,
89,
450,
40,
2689,
45,
297,
263,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
7,
272,
1543,
68,
4111,
77,
4111,
89,
297,
4519,
327,
283,
821,
14,
709,
14,
1690,
7,
199,
9,
199,
23925,
63,
15828,
275,
13647,
199,
28714,
63,
15828,
275,
283,
283,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
codeworkx/android_kernel_rockchip_rk30xx
|
tools/perf/scripts/python/syscall-counts.py
|
11181
|
1522
|
# system call counts
# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Displays system-wide system call totals, broken down by syscall.
# If a [comm] arg is specified, only syscalls called by [comm] are displayed.
import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
from Util import syscall_name
usage = "perf script -s syscall-counts.py [comm]\n";
for_comm = None
if len(sys.argv) > 2:
sys.exit(usage)
if len(sys.argv) > 1:
for_comm = sys.argv[1]
syscalls = autodict()
def trace_begin():
print "Press control+C to stop and show the summary"
def trace_end():
print_syscall_totals()
def raw_syscalls__sys_enter(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
id, args):
if for_comm is not None:
if common_comm != for_comm:
return
try:
syscalls[id] += 1
except TypeError:
syscalls[id] = 1
def print_syscall_totals():
if for_comm is not None:
print "\nsyscall events for %s:\n\n" % (for_comm),
else:
print "\nsyscall events:\n\n",
print "%-40s %10s\n" % ("event", "count"),
print "%-40s %10s\n" % ("----------------------------------------", \
"-----------"),
for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
reverse = True):
print "%-40s %10d\n" % (syscall_name(id), val),
|
gpl-2.0
|
[
3,
2656,
1240,
8242,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
18901,
63,
354,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
199,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
507,
198,
692,
2863,
63,
1404,
1137,
367,
63,
1404,
26,
686,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
13715,
1288,
339,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
14,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
971,
1871,
221,
3837,
275,
715,
304,
6722,
870,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2656,
1240,
8242,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
18901,
63,
354,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
199,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
507,
198,
692,
2863,
63,
1404,
1137,
367,
63,
1404,
26,
686,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
13715,
1288,
339,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
14,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
971,
1871,
221,
3837,
275,
715,
304,
6722,
870,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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clone
from ..base import BaseEstimator
from ..base import MetaEstimatorMixin
from ..utils import _get_n_jobs
class BaseEnsemble(BaseEstimator, MetaEstimatorMixin):
"""Base class for all ensemble classes.
Warning: This class should not be used directly. Use derived classes
instead.
Parameters
----------
base_estimator : object, optional (default=None)
The base estimator from which the ensemble is built.
n_estimators : integer
The number of estimators in the ensemble.
estimator_params : list of strings
The list of attributes to use as parameters when instantiating a
new base estimator. If none are given, default parameters are used.
Attributes
----------
base_estimator_ : estimator
The base estimator from which the ensemble is grown.
estimators_ : list of estimators
The collection of fitted base estimators.
"""
def __init__(self, base_estimator, n_estimators=10,
estimator_params=tuple()):
# Set parameters
self.base_estimator = base_estimator
self.n_estimators = n_estimators
self.estimator_params = estimator_params
# Don't instantiate estimators now! Parameters of base_estimator might
# still change. Eg., when grid-searching with the nested object syntax.
# This needs to be filled by the derived classes.
self.estimators_ = []
def _validate_estimator(self, default=None):
"""Check the estimator and the n_estimator attribute, set the
`base_estimator_` attribute."""
if self.n_estimators <= 0:
raise ValueError("n_estimators must be greater than zero, "
"got {0}.".format(self.n_estimators))
if self.base_estimator is not None:
self.base_estimator_ = self.base_estimator
else:
self.base_estimator_ = default
if self.base_estimator_ is None:
raise ValueError("base_estimator cannot be None")
def _make_estimator(self, append=True):
"""Make and configure a copy of the `base_estimator_` attribute.
Warning: This method should be used to properly instantiate new
sub-estimators.
"""
estimator = clone(self.base_estimator_)
estimator.set_params(**dict((p, getattr(self, p))
for p in self.estimator_params))
if append:
self.estimators_.append(estimator)
return estimator
def __len__(self):
"""Returns the number of estimators in the ensemble."""
return len(self.estimators_)
def __getitem__(self, index):
"""Returns the index'th estimator in the ensemble."""
return self.estimators_[index]
def __iter__(self):
"""Returns iterator over estimators in the ensemble."""
return iter(self.estimators_)
def _partition_estimators(n_estimators, n_jobs):
"""Private function used to partition estimators between jobs."""
# Compute the number of jobs
n_jobs = min(_get_n_jobs(n_jobs), n_estimators)
# Partition estimators between jobs
n_estimators_per_job = (n_estimators // n_jobs) * np.ones(n_jobs,
dtype=np.int)
n_estimators_per_job[:n_estimators % n_jobs] += 1
starts = np.cumsum(n_estimators_per_job)
return n_jobs, n_estimators_per_job.tolist(), [0] + starts.tolist()
|
bsd-3-clause
|
[
624,
199,
1563,
1021,
367,
19965,
13,
6788,
23155,
14,
199,
624,
199,
199,
3,
6642,
26,
598,
382,
2978,
3835,
384,
321,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
2508,
1095,
492,
7289,
199,
504,
2508,
1095,
492,
3523,
13183,
199,
504,
2508,
1095,
492,
6288,
13183,
4256,
199,
504,
2508,
1208,
492,
485,
362,
63,
78,
63,
6920,
421,
199,
533,
3523,
1327,
8834,
8,
1563,
13183,
12,
6288,
13183,
4256,
304,
272,
408,
1563,
1021,
367,
1006,
19965,
3992,
14,
339,
15902,
26,
961,
1021,
1077,
440,
506,
1202,
5370,
14,
3645,
7131,
3992,
272,
3140,
14,
339,
3897,
272,
4143,
272,
1300,
63,
8627,
520,
909,
12,
2716,
334,
885,
29,
403,
9,
267,
710,
1300,
8943,
687,
1314,
314,
19965,
365,
6137,
14,
339,
302,
63,
10646,
520,
3000,
267,
710,
1329,
402,
23155,
315,
314,
19965,
14,
339,
8943,
63,
1162,
520,
769,
402,
3326,
267,
710,
769,
402,
3004,
370,
675,
465,
2633,
1380,
9034,
1958,
282,
267,
892,
1300,
8943,
14,
982,
7179,
787,
1627,
12,
849,
2633,
787,
1202,
14,
339,
9382,
272,
4143,
272,
1300,
63,
8627,
63,
520,
8943,
267,
710,
1300,
8943,
687,
1314,
314,
19965,
365,
486,
18406,
14,
339,
23155,
63,
520,
769,
402,
23155,
267,
710,
3245,
402,
26093,
1300,
23155,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1300,
63,
8627,
12,
302,
63,
10646,
29,
709,
12,
326,
8943,
63,
1162,
29,
2960,
5109,
267,
327,
2494,
2633,
267,
291,
14,
1095,
63,
8627,
275,
1300,
63,
8627,
267,
291,
14,
78,
63,
10646,
275,
302,
63,
10646,
267,
291,
14,
8627,
63,
1162,
275,
8943,
63,
1162,
398,
327,
7529,
1133,
17321,
23155,
3063,
1,
3897,
402,
1300,
63,
8627,
5594,
267,
327,
5139,
1570,
14,
662,
71,
2020,
1380,
6068,
13,
1733,
316,
543,
314,
6032,
909,
6302,
14,
267,
327,
961,
4839,
370,
506,
13457,
701,
314,
7131,
3992,
14,
267,
291,
14,
10646,
63,
275,
942,
339,
347,
485,
3502,
63,
8627,
8,
277,
12,
849,
29,
403,
304,
267,
408,
1799,
314,
8943,
436,
314,
302,
63,
8627,
2225,
12,
663,
314,
267,
658,
1095,
63,
8627,
28116,
2225,
1041,
267,
340,
291,
14,
78,
63,
10646,
2695,
378,
26,
288,
746,
1722,
480,
78,
63,
10646,
1471,
506,
8932,
2419,
4697,
12,
298,
2490,
298,
7808,
469,
16,
5565,
1674,
908,
8,
277,
14,
78,
63,
10646,
430,
398,
340,
291,
14,
1095,
63,
8627,
365,
440,
488,
26,
288,
291,
14,
1095,
63,
8627,
63,
275,
291,
14,
1095,
63,
8627,
267,
587,
26,
288,
291,
14,
1095,
63,
8627,
63,
275,
849,
398,
340,
291,
14,
1095,
63,
8627,
63,
365,
488,
26,
288,
746,
1722,
480,
1095,
63,
8627,
3913,
506,
488,
531,
339,
347,
485,
1875,
63,
8627,
8,
277,
12,
5666,
29,
549,
304,
267,
408,
5483,
436,
7908,
282,
1331,
402,
314,
658,
1095,
63,
8627,
28116,
2225,
14,
398,
15902,
26,
961,
1083,
1077,
506,
1202,
370,
7684,
17321,
892,
267,
1007,
13,
10646,
14,
267,
408,
267,
8943,
275,
7289,
8,
277,
14,
1095,
63,
8627,
4602,
267,
8943,
14,
409,
63,
1162,
3682,
807,
1332,
80,
12,
2519,
8,
277,
12,
299,
430,
2511,
367,
299,
315,
291,
14,
8627,
63,
1162,
430,
398,
340,
5666,
26,
288,
291,
14,
10646,
3754,
740,
8,
8627,
9,
398,
372,
8943,
339,
347,
636,
552,
721,
277,
304,
267,
408,
3407,
314,
1329,
402,
23155,
315,
314,
19965,
1041,
267,
372,
822,
8,
277,
14,
10646,
4602,
339,
347,
636,
6095,
721,
277,
12,
1478,
304,
267,
408,
3407,
314,
1478,
1133,
72,
8943,
315,
314,
19965,
1041,
267,
372,
291,
14,
10646,
9925,
1080,
61,
339,
347,
636,
1661,
721,
277,
304,
267,
408,
3407,
6122,
1806,
23155,
315,
314,
19965,
1041,
267,
372,
2740,
8,
277,
14,
10646,
4602,
421,
199,
318,
485,
5312,
63,
10646,
8,
78,
63,
10646,
12,
302,
63,
6920,
304,
272,
408,
12185,
805,
1202,
370,
6484,
23155,
3382,
9643,
1041,
272,
327,
8354,
314,
1329,
402,
9643,
272,
302,
63,
6920,
275,
1748,
1547,
362,
63,
78,
63,
6920,
8,
78,
63,
6920,
395,
302,
63,
10646,
9,
339,
327,
27353,
23155,
3382,
9643,
272,
302,
63,
10646,
63,
529,
63,
2423,
275,
334,
78,
63,
10646,
5001,
302,
63,
6920,
9,
627,
980,
14,
4548,
8,
78,
63,
6920,
12,
16854,
2152,
29,
1590,
14,
442,
9,
272,
302,
63,
10646,
63,
529,
63,
2423,
1491,
78,
63,
10646,
450,
302,
63,
6920,
61,
847,
413,
272,
9174,
275,
980,
14,
23916,
8,
78,
63,
10646,
63,
529,
63,
2423,
9,
339,
372,
302,
63,
6920,
12,
302,
63,
10646,
63,
529,
63,
2423,
14,
13633,
1062,
359,
16,
61,
435,
9174,
14,
13633,
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
] |
[
199,
1563,
1021,
367,
19965,
13,
6788,
23155,
14,
199,
624,
199,
199,
3,
6642,
26,
598,
382,
2978,
3835,
384,
321,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
2508,
1095,
492,
7289,
199,
504,
2508,
1095,
492,
3523,
13183,
199,
504,
2508,
1095,
492,
6288,
13183,
4256,
199,
504,
2508,
1208,
492,
485,
362,
63,
78,
63,
6920,
421,
199,
533,
3523,
1327,
8834,
8,
1563,
13183,
12,
6288,
13183,
4256,
304,
272,
408,
1563,
1021,
367,
1006,
19965,
3992,
14,
339,
15902,
26,
961,
1021,
1077,
440,
506,
1202,
5370,
14,
3645,
7131,
3992,
272,
3140,
14,
339,
3897,
272,
4143,
272,
1300,
63,
8627,
520,
909,
12,
2716,
334,
885,
29,
403,
9,
267,
710,
1300,
8943,
687,
1314,
314,
19965,
365,
6137,
14,
339,
302,
63,
10646,
520,
3000,
267,
710,
1329,
402,
23155,
315,
314,
19965,
14,
339,
8943,
63,
1162,
520,
769,
402,
3326,
267,
710,
769,
402,
3004,
370,
675,
465,
2633,
1380,
9034,
1958,
282,
267,
892,
1300,
8943,
14,
982,
7179,
787,
1627,
12,
849,
2633,
787,
1202,
14,
339,
9382,
272,
4143,
272,
1300,
63,
8627,
63,
520,
8943,
267,
710,
1300,
8943,
687,
1314,
314,
19965,
365,
486,
18406,
14,
339,
23155,
63,
520,
769,
402,
23155,
267,
710,
3245,
402,
26093,
1300,
23155,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1300,
63,
8627,
12,
302,
63,
10646,
29,
709,
12,
326,
8943,
63,
1162,
29,
2960,
5109,
267,
327,
2494,
2633,
267,
291,
14,
1095,
63,
8627,
275,
1300,
63,
8627,
267,
291,
14,
78,
63,
10646,
275,
302,
63,
10646,
267,
291,
14,
8627,
63,
1162,
275,
8943,
63,
1162,
398,
327,
7529,
1133,
17321,
23155,
3063,
1,
3897,
402,
1300,
63,
8627,
5594,
267,
327,
5139,
1570,
14,
662,
71,
2020,
1380,
6068,
13,
1733,
316,
543,
314,
6032,
909,
6302,
14,
267,
327,
961,
4839,
370,
506,
13457,
701,
314,
7131,
3992,
14,
267,
291,
14,
10646,
63,
275,
942,
339,
347,
485,
3502,
63,
8627,
8,
277,
12,
849,
29,
403,
304,
267,
408,
1799,
314,
8943,
436,
314,
302,
63,
8627,
2225,
12,
663,
314,
267,
658,
1095,
63,
8627,
28116,
2225,
1041,
267,
340,
291,
14,
78,
63,
10646,
2695,
378,
26,
288,
746,
1722,
480,
78,
63,
10646,
1471,
506,
8932,
2419,
4697,
12,
298,
2490,
298,
7808,
469,
16,
5565,
1674,
908,
8,
277,
14,
78,
63,
10646,
430,
398,
340,
291,
14,
1095,
63,
8627,
365,
440,
488,
26,
288,
291,
14,
1095,
63,
8627,
63,
275,
291,
14,
1095,
63,
8627,
267,
587,
26,
288,
291,
14,
1095,
63,
8627,
63,
275,
849,
398,
340,
291,
14,
1095,
63,
8627,
63,
365,
488,
26,
288,
746,
1722,
480,
1095,
63,
8627,
3913,
506,
488,
531,
339,
347,
485,
1875,
63,
8627,
8,
277,
12,
5666,
29,
549,
304,
267,
408,
5483,
436,
7908,
282,
1331,
402,
314,
658,
1095,
63,
8627,
28116,
2225,
14,
398,
15902,
26,
961,
1083,
1077,
506,
1202,
370,
7684,
17321,
892,
267,
1007,
13,
10646,
14,
267,
408,
267,
8943,
275,
7289,
8,
277,
14,
1095,
63,
8627,
4602,
267,
8943,
14,
409,
63,
1162,
3682,
807,
1332,
80,
12,
2519,
8,
277,
12,
299,
430,
2511,
367,
299,
315,
291,
14,
8627,
63,
1162,
430,
398,
340,
5666,
26,
288,
291,
14,
10646,
3754,
740,
8,
8627,
9,
398,
372,
8943,
339,
347,
636,
552,
721,
277,
304,
267,
408,
3407,
314,
1329,
402,
23155,
315,
314,
19965,
1041,
267,
372,
822,
8,
277,
14,
10646,
4602,
339,
347,
636,
6095,
721,
277,
12,
1478,
304,
267,
408,
3407,
314,
1478,
1133,
72,
8943,
315,
314,
19965,
1041,
267,
372,
291,
14,
10646,
9925,
1080,
61,
339,
347,
636,
1661,
721,
277,
304,
267,
408,
3407,
6122,
1806,
23155,
315,
314,
19965,
1041,
267,
372,
2740,
8,
277,
14,
10646,
4602,
421,
199,
318,
485,
5312,
63,
10646,
8,
78,
63,
10646,
12,
302,
63,
6920,
304,
272,
408,
12185,
805,
1202,
370,
6484,
23155,
3382,
9643,
1041,
272,
327,
8354,
314,
1329,
402,
9643,
272,
302,
63,
6920,
275,
1748,
1547,
362,
63,
78,
63,
6920,
8,
78,
63,
6920,
395,
302,
63,
10646,
9,
339,
327,
27353,
23155,
3382,
9643,
272,
302,
63,
10646,
63,
529,
63,
2423,
275,
334,
78,
63,
10646,
5001,
302,
63,
6920,
9,
627,
980,
14,
4548,
8,
78,
63,
6920,
12,
16854,
2152,
29,
1590,
14,
442,
9,
272,
302,
63,
10646,
63,
529,
63,
2423,
1491,
78,
63,
10646,
450,
302,
63,
6920,
61,
847,
413,
272,
9174,
275,
980,
14,
23916,
8,
78,
63,
10646,
63,
529,
63,
2423,
9,
339,
372,
302,
63,
6920,
12,
302,
63,
10646,
63,
529,
63,
2423,
14,
13633,
1062,
359,
16,
61,
435,
9174,
14,
13633,
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,
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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
] |
kenshay/ImageScript
|
Script_Runner/PYTHON/Lib/site-packages/paramiko/packet.py
|
3
|
20247
|
# Copyright (C) 2003-2007 Robey Pointer <robeypointer@gmail.com>
#
# This file is part of paramiko.
#
# Paramiko 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.
#
# Paramiko 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 Paramiko; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
"""
Packet handling
"""
import errno
import os
import socket
import struct
import threading
import time
from hmac import HMAC
from paramiko import util
from paramiko.common import (
linefeed_byte,
cr_byte_value,
asbytes,
MSG_NAMES,
DEBUG,
xffffffff,
zero_byte,
)
from paramiko.py3compat import u, byte_ord
from paramiko.ssh_exception import SSHException, ProxyCommandFailure
from paramiko.message import Message
def compute_hmac(key, message, digest_class):
return HMAC(key, message, digest_class).digest()
class NeedRekeyException(Exception):
"""
Exception indicating a rekey is needed.
"""
pass
def first_arg(e):
arg = None
if type(e.args) is tuple and len(e.args) > 0:
arg = e.args[0]
return arg
class Packetizer(object):
"""
Implementation of the base SSH packet protocol.
"""
# READ the secsh RFC's before raising these values. if anything,
# they should probably be lower.
REKEY_PACKETS = pow(2, 29)
REKEY_BYTES = pow(2, 29)
# Allow receiving this many packets after a re-key request before
# terminating
REKEY_PACKETS_OVERFLOW_MAX = pow(2, 29)
# Allow receiving this many bytes after a re-key request before terminating
REKEY_BYTES_OVERFLOW_MAX = pow(2, 29)
def __init__(self, socket):
self.__socket = socket
self.__logger = None
self.__closed = False
self.__dump_packets = False
self.__need_rekey = False
self.__init_count = 0
self.__remainder = bytes()
# used for noticing when to re-key:
self.__sent_bytes = 0
self.__sent_packets = 0
self.__received_bytes = 0
self.__received_packets = 0
self.__received_bytes_overflow = 0
self.__received_packets_overflow = 0
# current inbound/outbound ciphering:
self.__block_size_out = 8
self.__block_size_in = 8
self.__mac_size_out = 0
self.__mac_size_in = 0
self.__block_engine_out = None
self.__block_engine_in = None
self.__sdctr_out = False
self.__mac_engine_out = None
self.__mac_engine_in = None
self.__mac_key_out = bytes()
self.__mac_key_in = bytes()
self.__compress_engine_out = None
self.__compress_engine_in = None
self.__sequence_number_out = 0
self.__sequence_number_in = 0
# lock around outbound writes (packet computation)
self.__write_lock = threading.RLock()
# keepalives:
self.__keepalive_interval = 0
self.__keepalive_last = time.time()
self.__keepalive_callback = None
self.__timer = None
self.__handshake_complete = False
self.__timer_expired = False
@property
def closed(self):
return self.__closed
def set_log(self, log):
"""
Set the Python log object to use for logging.
"""
self.__logger = log
def set_outbound_cipher(
self,
block_engine,
block_size,
mac_engine,
mac_size,
mac_key,
sdctr=False,
):
"""
Switch outbound data cipher.
"""
self.__block_engine_out = block_engine
self.__sdctr_out = sdctr
self.__block_size_out = block_size
self.__mac_engine_out = mac_engine
self.__mac_size_out = mac_size
self.__mac_key_out = mac_key
self.__sent_bytes = 0
self.__sent_packets = 0
# wait until the reset happens in both directions before clearing
# rekey flag
self.__init_count |= 1
if self.__init_count == 3:
self.__init_count = 0
self.__need_rekey = False
def set_inbound_cipher(
self, block_engine, block_size, mac_engine, mac_size, mac_key
):
"""
Switch inbound data cipher.
"""
self.__block_engine_in = block_engine
self.__block_size_in = block_size
self.__mac_engine_in = mac_engine
self.__mac_size_in = mac_size
self.__mac_key_in = mac_key
self.__received_bytes = 0
self.__received_packets = 0
self.__received_bytes_overflow = 0
self.__received_packets_overflow = 0
# wait until the reset happens in both directions before clearing
# rekey flag
self.__init_count |= 2
if self.__init_count == 3:
self.__init_count = 0
self.__need_rekey = False
def set_outbound_compressor(self, compressor):
self.__compress_engine_out = compressor
def set_inbound_compressor(self, compressor):
self.__compress_engine_in = compressor
def close(self):
self.__closed = True
self.__socket.close()
def set_hexdump(self, hexdump):
self.__dump_packets = hexdump
def get_hexdump(self):
return self.__dump_packets
def get_mac_size_in(self):
return self.__mac_size_in
def get_mac_size_out(self):
return self.__mac_size_out
def need_rekey(self):
"""
Returns ``True`` if a new set of keys needs to be negotiated. This
will be triggered during a packet read or write, so it should be
checked after every read or write, or at least after every few.
"""
return self.__need_rekey
def set_keepalive(self, interval, callback):
"""
Turn on/off the callback keepalive. If ``interval`` seconds pass with
no data read from or written to the socket, the callback will be
executed and the timer will be reset.
"""
self.__keepalive_interval = interval
self.__keepalive_callback = callback
self.__keepalive_last = time.time()
def read_timer(self):
self.__timer_expired = True
def start_handshake(self, timeout):
"""
Tells `Packetizer` that the handshake process started.
Starts a book keeping timer that can signal a timeout in the
handshake process.
:param float timeout: amount of seconds to wait before timing out
"""
if not self.__timer:
self.__timer = threading.Timer(float(timeout), self.read_timer)
self.__timer.start()
def handshake_timed_out(self):
"""
Checks if the handshake has timed out.
If `start_handshake` wasn't called before the call to this function,
the return value will always be `False`. If the handshake completed
before a timeout was reached, the return value will be `False`
:return: handshake time out status, as a `bool`
"""
if not self.__timer:
return False
if self.__handshake_complete:
return False
return self.__timer_expired
def complete_handshake(self):
"""
Tells `Packetizer` that the handshake has completed.
"""
if self.__timer:
self.__timer.cancel()
self.__timer_expired = False
self.__handshake_complete = True
def read_all(self, n, check_rekey=False):
"""
Read as close to N bytes as possible, blocking as long as necessary.
:param int n: number of bytes to read
:return: the data read, as a `str`
:raises:
``EOFError`` -- if the socket was closed before all the bytes could
be read
"""
out = bytes()
# handle over-reading from reading the banner line
if len(self.__remainder) > 0:
out = self.__remainder[:n]
self.__remainder = self.__remainder[n:]
n -= len(out)
while n > 0:
got_timeout = False
if self.handshake_timed_out():
raise EOFError()
try:
x = self.__socket.recv(n)
if len(x) == 0:
raise EOFError()
out += x
n -= len(x)
except socket.timeout:
got_timeout = True
except socket.error as e:
# on Linux, sometimes instead of socket.timeout, we get
# EAGAIN. this is a bug in recent (> 2.6.9) kernels but
# we need to work around it.
arg = first_arg(e)
if arg == errno.EAGAIN:
got_timeout = True
elif arg == errno.EINTR:
# syscall interrupted; try again
pass
elif self.__closed:
raise EOFError()
else:
raise
if got_timeout:
if self.__closed:
raise EOFError()
if check_rekey and (len(out) == 0) and self.__need_rekey:
raise NeedRekeyException()
self._check_keepalive()
return out
def write_all(self, out):
self.__keepalive_last = time.time()
iteration_with_zero_as_return_value = 0
while len(out) > 0:
retry_write = False
try:
n = self.__socket.send(out)
except socket.timeout:
retry_write = True
except socket.error as e:
arg = first_arg(e)
if arg == errno.EAGAIN:
retry_write = True
elif arg == errno.EINTR:
# syscall interrupted; try again
retry_write = True
else:
n = -1
except ProxyCommandFailure:
raise # so it doesn't get swallowed by the below catchall
except Exception:
# could be: (32, 'Broken pipe')
n = -1
if retry_write:
n = 0
if self.__closed:
n = -1
else:
if n == 0 and iteration_with_zero_as_return_value > 10:
# We shouldn't retry the write, but we didn't
# manage to send anything over the socket. This might be an
# indication that we have lost contact with the remote
# side, but are yet to receive an EOFError or other socket
# errors. Let's give it some iteration to try and catch up.
n = -1
iteration_with_zero_as_return_value += 1
if n < 0:
raise EOFError()
if n == len(out):
break
out = out[n:]
return
def readline(self, timeout):
"""
Read a line from the socket. We assume no data is pending after the
line, so it's okay to attempt large reads.
"""
buf = self.__remainder
while linefeed_byte not in buf:
buf += self._read_timeout(timeout)
n = buf.index(linefeed_byte)
self.__remainder = buf[n + 1 :]
buf = buf[:n]
if (len(buf) > 0) and (buf[-1] == cr_byte_value):
buf = buf[:-1]
return u(buf)
def send_message(self, data):
"""
Write a block of data using the current cipher, as an SSH block.
"""
# encrypt this sucka
data = asbytes(data)
cmd = byte_ord(data[0])
if cmd in MSG_NAMES:
cmd_name = MSG_NAMES[cmd]
else:
cmd_name = "${:x}".format(cmd)
orig_len = len(data)
self.__write_lock.acquire()
try:
if self.__compress_engine_out is not None:
data = self.__compress_engine_out(data)
packet = self._build_packet(data)
if self.__dump_packets:
self._log(
DEBUG,
"Write packet <{}>, length {}".format(cmd_name, orig_len),
)
self._log(DEBUG, util.format_binary(packet, "OUT: "))
if self.__block_engine_out is not None:
out = self.__block_engine_out.update(packet)
else:
out = packet
# + mac
if self.__block_engine_out is not None:
payload = (
struct.pack(">I", self.__sequence_number_out) + packet
)
out += compute_hmac(
self.__mac_key_out, payload, self.__mac_engine_out
)[: self.__mac_size_out]
self.__sequence_number_out = (
self.__sequence_number_out + 1
) & xffffffff
self.write_all(out)
self.__sent_bytes += len(out)
self.__sent_packets += 1
sent_too_much = (
self.__sent_packets >= self.REKEY_PACKETS
or self.__sent_bytes >= self.REKEY_BYTES
)
if sent_too_much and not self.__need_rekey:
# only ask once for rekeying
msg = "Rekeying (hit {} packets, {} bytes sent)"
self._log(
DEBUG, msg.format(self.__sent_packets, self.__sent_bytes)
)
self.__received_bytes_overflow = 0
self.__received_packets_overflow = 0
self._trigger_rekey()
finally:
self.__write_lock.release()
def read_message(self):
"""
Only one thread should ever be in this function (no other locking is
done).
:raises: `.SSHException` -- if the packet is mangled
:raises: `.NeedRekeyException` -- if the transport should rekey
"""
header = self.read_all(self.__block_size_in, check_rekey=True)
if self.__block_engine_in is not None:
header = self.__block_engine_in.update(header)
if self.__dump_packets:
self._log(DEBUG, util.format_binary(header, "IN: "))
packet_size = struct.unpack(">I", header[:4])[0]
# leftover contains decrypted bytes from the first block (after the
# length field)
leftover = header[4:]
if (packet_size - len(leftover)) % self.__block_size_in != 0:
raise SSHException("Invalid packet blocking")
buf = self.read_all(packet_size + self.__mac_size_in - len(leftover))
packet = buf[: packet_size - len(leftover)]
post_packet = buf[packet_size - len(leftover) :]
if self.__block_engine_in is not None:
packet = self.__block_engine_in.update(packet)
if self.__dump_packets:
self._log(DEBUG, util.format_binary(packet, "IN: "))
packet = leftover + packet
if self.__mac_size_in > 0:
mac = post_packet[: self.__mac_size_in]
mac_payload = (
struct.pack(">II", self.__sequence_number_in, packet_size)
+ packet
)
my_mac = compute_hmac(
self.__mac_key_in, mac_payload, self.__mac_engine_in
)[: self.__mac_size_in]
if not util.constant_time_bytes_eq(my_mac, mac):
raise SSHException("Mismatched MAC")
padding = byte_ord(packet[0])
payload = packet[1 : packet_size - padding]
if self.__dump_packets:
self._log(
DEBUG,
"Got payload ({} bytes, {} padding)".format(
packet_size, padding
),
)
if self.__compress_engine_in is not None:
payload = self.__compress_engine_in(payload)
msg = Message(payload[1:])
msg.seqno = self.__sequence_number_in
self.__sequence_number_in = (self.__sequence_number_in + 1) & xffffffff
# check for rekey
raw_packet_size = packet_size + self.__mac_size_in + 4
self.__received_bytes += raw_packet_size
self.__received_packets += 1
if self.__need_rekey:
# we've asked to rekey -- give them some packets to comply before
# dropping the connection
self.__received_bytes_overflow += raw_packet_size
self.__received_packets_overflow += 1
if (
self.__received_packets_overflow
>= self.REKEY_PACKETS_OVERFLOW_MAX
) or (
self.__received_bytes_overflow >= self.REKEY_BYTES_OVERFLOW_MAX
):
raise SSHException(
"Remote transport is ignoring rekey requests"
)
elif (self.__received_packets >= self.REKEY_PACKETS) or (
self.__received_bytes >= self.REKEY_BYTES
):
# only ask once for rekeying
err = "Rekeying (hit {} packets, {} bytes received)"
self._log(
DEBUG,
err.format(self.__received_packets, self.__received_bytes),
)
self.__received_bytes_overflow = 0
self.__received_packets_overflow = 0
self._trigger_rekey()
cmd = byte_ord(payload[0])
if cmd in MSG_NAMES:
cmd_name = MSG_NAMES[cmd]
else:
cmd_name = "${:x}".format(cmd)
if self.__dump_packets:
self._log(
DEBUG,
"Read packet <{}>, length {}".format(cmd_name, len(payload)),
)
return cmd, msg
# ...protected...
def _log(self, level, msg):
if self.__logger is None:
return
if issubclass(type(msg), list):
for m in msg:
self.__logger.log(level, m)
else:
self.__logger.log(level, msg)
def _check_keepalive(self):
if (
not self.__keepalive_interval
or not self.__block_engine_out
or self.__need_rekey
):
# wait till we're encrypting, and not in the middle of rekeying
return
now = time.time()
if now > self.__keepalive_last + self.__keepalive_interval:
self.__keepalive_callback()
self.__keepalive_last = now
def _read_timeout(self, timeout):
start = time.time()
while True:
try:
x = self.__socket.recv(128)
if len(x) == 0:
raise EOFError()
break
except socket.timeout:
pass
except EnvironmentError as e:
if first_arg(e) == errno.EINTR:
pass
else:
raise
if self.__closed:
raise EOFError()
now = time.time()
if now - start >= timeout:
raise socket.timeout()
return x
def _build_packet(self, payload):
# pad up at least 4 bytes, to nearest block-size (usually 8)
bsize = self.__block_size_out
padding = 3 + bsize - ((len(payload) + 8) % bsize)
packet = struct.pack(">IB", len(payload) + padding + 1, padding)
packet += payload
if self.__sdctr_out or self.__block_engine_out is None:
# cute trick i caught openssh doing: if we're not encrypting or
# SDCTR mode (RFC4344),
# don't waste random bytes for the padding
packet += zero_byte * padding
else:
packet += os.urandom(padding)
return packet
def _trigger_rekey(self):
# outside code should check for this flag
self.__need_rekey = True
|
gpl-3.0
|
[
3,
1898,
334,
35,
9,
13004,
13,
9488,
221,
6848,
32236,
28833,
665,
293,
32236,
3929,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
26162,
14,
199,
3,
199,
3,
12608,
16625,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
199,
3,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
199,
3,
2290,
2752,
27,
1902,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12608,
16625,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
199,
3,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
2381,
199,
3,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
199,
3,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
12608,
16625,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
14,
199,
199,
624,
199,
2726,
7252,
199,
624,
199,
199,
646,
7554,
199,
646,
747,
199,
646,
2838,
199,
646,
2702,
199,
646,
5796,
199,
646,
900,
199,
504,
20330,
492,
29817,
199,
199,
504,
26162,
492,
4884,
199,
504,
26162,
14,
2330,
492,
334,
272,
1004,
3871,
63,
4414,
12,
272,
2467,
63,
4414,
63,
585,
12,
272,
28217,
12,
272,
23620,
63,
14546,
12,
272,
10990,
12,
272,
671,
15798,
12,
272,
4697,
63,
4414,
12,
199,
9,
199,
504,
26162,
14,
647,
19,
5819,
492,
399,
12,
3696,
63,
2181,
199,
504,
26162,
14,
5510,
63,
1971,
492,
12027,
1726,
12,
12373,
3110,
6782,
199,
504,
26162,
14,
1188,
492,
6430,
421,
199,
318,
4526,
63,
18537,
8,
498,
12,
1245,
12,
10017,
63,
533,
304,
272,
372,
29817,
8,
498,
12,
1245,
12,
10017,
63,
533,
680,
5671,
342,
421,
199,
533,
14012,
497,
498,
1726,
8,
1726,
304,
272,
408,
272,
2186,
9297,
282,
295,
498,
365,
4346,
14,
272,
408,
339,
986,
421,
199,
318,
1642,
63,
1273,
8,
69,
304,
272,
1680,
275,
488,
272,
340,
730,
8,
69,
14,
589,
9,
365,
2008,
436,
822,
8,
69,
14,
589,
9,
690,
378,
26,
267,
1680,
275,
325,
14,
589,
59,
16,
61,
272,
372,
1680,
421,
199,
533,
9954,
69,
280,
2282,
8,
785,
304,
272,
408,
272,
24425,
402,
314,
1300,
12027,
3644,
4113,
14,
272,
408,
339,
327,
16767,
314,
6513,
609,
7329,
1159,
2544,
17026,
3520,
1338,
14,
221,
340,
7003,
12,
272,
327,
2985,
1077,
8646,
506,
5117,
14,
272,
5363,
3078,
63,
18058,
51,
275,
13131,
8,
18,
12,
7349,
9,
272,
5363,
3078,
63,
20352,
275,
13131,
8,
18,
12,
7349,
9,
339,
327,
9812,
18390,
642,
5002,
14593,
2410,
282,
295,
13,
498,
1056,
2544,
272,
327,
5537,
1958,
272,
5363,
3078,
63,
18058,
51,
63,
14336,
17114,
63,
4283,
275,
13131,
8,
18,
12,
7349,
9,
272,
327,
9812,
18390,
642,
5002,
2783,
2410,
282,
295,
13,
498,
1056,
2544,
5537,
1958,
272,
5363,
3078,
63,
20352,
63,
14336,
17114,
63,
4283,
275,
13131,
8,
18,
12,
7349,
9,
339,
347,
636,
826,
721,
277,
12,
2838,
304,
267,
291,
855,
3450,
275,
2838,
267,
291,
855,
2921,
275,
488,
267,
291,
855,
5938,
275,
756,
267,
291,
855,
2724,
63,
18853,
275,
756,
267,
291,
855,
9321,
63,
264,
498,
275,
756,
267,
291,
855,
826,
63,
835,
275,
378,
267,
291,
855,
23850,
275,
2783,
342,
398,
327,
1202,
367,
949,
764,
316,
1380,
370,
295,
13,
498,
26,
267,
291,
855,
1150,
63,
2394,
275,
378,
267,
291,
855,
1150,
63,
18853,
275,
378,
267,
291,
855,
9226,
63,
2394,
275,
378,
267,
291,
855,
9226,
63,
18853,
275,
378,
267,
291,
855,
9226,
63,
2394,
63,
14108,
275,
378,
267,
291,
855,
9226,
63,
18853,
63,
14108,
275,
378,
398,
327,
1453,
30819,
15,
548,
3556,
10830,
316,
26,
267,
291,
855,
1457,
63,
890,
63,
548,
275,
1695,
267,
291,
855,
1457,
63,
890,
63,
262,
275,
1695,
267,
291,
855,
3088,
63,
890,
63,
548,
275,
378,
267,
291,
855,
3088,
63,
890,
63,
262,
275,
378,
267,
291,
855,
1457,
63,
3908,
63,
548,
275,
488,
267,
291,
855,
1457,
63,
3908,
63,
262,
275,
488,
267,
291,
855,
3893,
18548,
63,
548,
275,
756,
267,
291,
855,
3088,
63,
3908,
63,
548,
275,
488,
267,
291,
855,
3088,
63,
3908,
63,
262,
275,
488,
267,
291,
855,
3088,
63,
498,
63,
548,
275,
2783,
342,
267,
291,
855,
3088,
63,
498,
63,
262,
275,
2783,
342,
267,
291,
855,
6447,
63,
3908,
63,
548,
275,
488,
267,
291,
855,
6447,
63,
3908,
63,
262,
275,
488,
267,
291,
855,
4041,
63,
1955,
63,
548,
275,
378,
267,
291,
855,
4041,
63,
1955,
63,
262,
275,
378,
398,
327,
4650,
6818,
734,
3556,
14511,
334,
6253,
14009,
9,
267,
291,
855,
952,
63,
831,
275,
5796,
14,
30550,
342,
398,
327,
4215,
279,
7602,
26,
267,
291,
855,
28227,
63,
4284,
275,
378,
267,
291,
855,
28227,
63,
2019,
275,
900,
14,
521,
342,
267,
291,
855,
28227,
63,
3058,
275,
488,
398,
291,
855,
7414,
275,
488,
267,
291,
855,
11913,
63,
4883,
275,
756,
267,
291,
855,
7414,
63,
16340,
275,
756,
339,
768,
1829,
272,
347,
6876,
8,
277,
304,
267,
372,
291,
855,
5938,
339,
347,
663,
63,
793,
8,
277,
12,
943,
304,
267,
408,
267,
2494,
314,
2018,
943,
909,
370,
675,
367,
2050,
14,
267,
408,
267,
291,
855,
2921,
275,
943,
339,
347,
663,
63,
548,
3556,
63,
9231,
8,
267,
291,
12,
267,
1853,
63,
3908,
12,
267,
1853,
63,
890,
12,
267,
4497,
63,
3908,
12,
267,
4497,
63,
890,
12,
267,
4497,
63,
498,
12,
267,
14613,
18548,
29,
797,
12,
272,
3461,
267,
408,
267,
17711,
734,
3556,
666,
10830,
14,
267,
408,
267,
291,
855
] |
[
1898,
334,
35,
9,
13004,
13,
9488,
221,
6848,
32236,
28833,
665,
293,
32236,
3929,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
26162,
14,
199,
3,
199,
3,
12608,
16625,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
199,
3,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
199,
3,
2290,
2752,
27,
1902,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12608,
16625,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
199,
3,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
2381,
199,
3,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
199,
3,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
12608,
16625,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
14,
199,
199,
624,
199,
2726,
7252,
199,
624,
199,
199,
646,
7554,
199,
646,
747,
199,
646,
2838,
199,
646,
2702,
199,
646,
5796,
199,
646,
900,
199,
504,
20330,
492,
29817,
199,
199,
504,
26162,
492,
4884,
199,
504,
26162,
14,
2330,
492,
334,
272,
1004,
3871,
63,
4414,
12,
272,
2467,
63,
4414,
63,
585,
12,
272,
28217,
12,
272,
23620,
63,
14546,
12,
272,
10990,
12,
272,
671,
15798,
12,
272,
4697,
63,
4414,
12,
199,
9,
199,
504,
26162,
14,
647,
19,
5819,
492,
399,
12,
3696,
63,
2181,
199,
504,
26162,
14,
5510,
63,
1971,
492,
12027,
1726,
12,
12373,
3110,
6782,
199,
504,
26162,
14,
1188,
492,
6430,
421,
199,
318,
4526,
63,
18537,
8,
498,
12,
1245,
12,
10017,
63,
533,
304,
272,
372,
29817,
8,
498,
12,
1245,
12,
10017,
63,
533,
680,
5671,
342,
421,
199,
533,
14012,
497,
498,
1726,
8,
1726,
304,
272,
408,
272,
2186,
9297,
282,
295,
498,
365,
4346,
14,
272,
408,
339,
986,
421,
199,
318,
1642,
63,
1273,
8,
69,
304,
272,
1680,
275,
488,
272,
340,
730,
8,
69,
14,
589,
9,
365,
2008,
436,
822,
8,
69,
14,
589,
9,
690,
378,
26,
267,
1680,
275,
325,
14,
589,
59,
16,
61,
272,
372,
1680,
421,
199,
533,
9954,
69,
280,
2282,
8,
785,
304,
272,
408,
272,
24425,
402,
314,
1300,
12027,
3644,
4113,
14,
272,
408,
339,
327,
16767,
314,
6513,
609,
7329,
1159,
2544,
17026,
3520,
1338,
14,
221,
340,
7003,
12,
272,
327,
2985,
1077,
8646,
506,
5117,
14,
272,
5363,
3078,
63,
18058,
51,
275,
13131,
8,
18,
12,
7349,
9,
272,
5363,
3078,
63,
20352,
275,
13131,
8,
18,
12,
7349,
9,
339,
327,
9812,
18390,
642,
5002,
14593,
2410,
282,
295,
13,
498,
1056,
2544,
272,
327,
5537,
1958,
272,
5363,
3078,
63,
18058,
51,
63,
14336,
17114,
63,
4283,
275,
13131,
8,
18,
12,
7349,
9,
272,
327,
9812,
18390,
642,
5002,
2783,
2410,
282,
295,
13,
498,
1056,
2544,
5537,
1958,
272,
5363,
3078,
63,
20352,
63,
14336,
17114,
63,
4283,
275,
13131,
8,
18,
12,
7349,
9,
339,
347,
636,
826,
721,
277,
12,
2838,
304,
267,
291,
855,
3450,
275,
2838,
267,
291,
855,
2921,
275,
488,
267,
291,
855,
5938,
275,
756,
267,
291,
855,
2724,
63,
18853,
275,
756,
267,
291,
855,
9321,
63,
264,
498,
275,
756,
267,
291,
855,
826,
63,
835,
275,
378,
267,
291,
855,
23850,
275,
2783,
342,
398,
327,
1202,
367,
949,
764,
316,
1380,
370,
295,
13,
498,
26,
267,
291,
855,
1150,
63,
2394,
275,
378,
267,
291,
855,
1150,
63,
18853,
275,
378,
267,
291,
855,
9226,
63,
2394,
275,
378,
267,
291,
855,
9226,
63,
18853,
275,
378,
267,
291,
855,
9226,
63,
2394,
63,
14108,
275,
378,
267,
291,
855,
9226,
63,
18853,
63,
14108,
275,
378,
398,
327,
1453,
30819,
15,
548,
3556,
10830,
316,
26,
267,
291,
855,
1457,
63,
890,
63,
548,
275,
1695,
267,
291,
855,
1457,
63,
890,
63,
262,
275,
1695,
267,
291,
855,
3088,
63,
890,
63,
548,
275,
378,
267,
291,
855,
3088,
63,
890,
63,
262,
275,
378,
267,
291,
855,
1457,
63,
3908,
63,
548,
275,
488,
267,
291,
855,
1457,
63,
3908,
63,
262,
275,
488,
267,
291,
855,
3893,
18548,
63,
548,
275,
756,
267,
291,
855,
3088,
63,
3908,
63,
548,
275,
488,
267,
291,
855,
3088,
63,
3908,
63,
262,
275,
488,
267,
291,
855,
3088,
63,
498,
63,
548,
275,
2783,
342,
267,
291,
855,
3088,
63,
498,
63,
262,
275,
2783,
342,
267,
291,
855,
6447,
63,
3908,
63,
548,
275,
488,
267,
291,
855,
6447,
63,
3908,
63,
262,
275,
488,
267,
291,
855,
4041,
63,
1955,
63,
548,
275,
378,
267,
291,
855,
4041,
63,
1955,
63,
262,
275,
378,
398,
327,
4650,
6818,
734,
3556,
14511,
334,
6253,
14009,
9,
267,
291,
855,
952,
63,
831,
275,
5796,
14,
30550,
342,
398,
327,
4215,
279,
7602,
26,
267,
291,
855,
28227,
63,
4284,
275,
378,
267,
291,
855,
28227,
63,
2019,
275,
900,
14,
521,
342,
267,
291,
855,
28227,
63,
3058,
275,
488,
398,
291,
855,
7414,
275,
488,
267,
291,
855,
11913,
63,
4883,
275,
756,
267,
291,
855,
7414,
63,
16340,
275,
756,
339,
768,
1829,
272,
347,
6876,
8,
277,
304,
267,
372,
291,
855,
5938,
339,
347,
663,
63,
793,
8,
277,
12,
943,
304,
267,
408,
267,
2494,
314,
2018,
943,
909,
370,
675,
367,
2050,
14,
267,
408,
267,
291,
855,
2921,
275,
943,
339,
347,
663,
63,
548,
3556,
63,
9231,
8,
267,
291,
12,
267,
1853,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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
] |
rkawale/Internalhr-frappe
|
frappe/templates/website_group/settings.py
|
3
|
3491
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.website.permissions import get_access, clear_permissions
from frappe.templates.generators.website_group import get_pathname
from frappe.utils.email_lib.bulk import send
@frappe.whitelist()
def suggest_user(term, group):
pathname = get_pathname(group)
if not get_access(pathname).get("admin"):
raise frappe.PermissionError
users = frappe.db.sql("""select pr.name, pr.first_name, pr.last_name,
pr.user_image, pr.location
from `tabUser` pr
where (pr.first_name like %(term)s or pr.last_name like %(term)s)
and pr.user_type = "Website User"
and pr.user_image is not null and pr.enabled=1
and not exists(select wsp.name from `tabWebsite Route Permission` wsp
where wsp.website_route=%(group)s and wsp.user=pr.name)""",
{"term": "%{}%".format(term), "group": pathname}, as_dict=True)
template = frappe.get_template("templates/includes/user_display.html")
return [{
"value": "{} {}".format(pr.first_name or "", pr.last_name or ""),
"user_html": template.render({"user": pr}),
"user": pr.name
} for pr in users]
@frappe.whitelist()
def add_sitemap_permission(group, user):
pathname = get_pathname(group)
if not get_access(pathname).get("admin"):
raise frappe.PermissionError
permission = frappe.get_doc({
"doctype": "Website Route Permission",
"website_route": pathname,
"user": user,
"read": 1
})
permission.insert(ignore_permissions=True)
user = permission.as_dict()
user.update(frappe.db.get_value("User", user.user,
["name", "first_name", "last_name", "user_image", "location"], as_dict=True))
return frappe.get_template("templates/includes/sitemap_permission.html").render({
"user": user
})
@frappe.whitelist()
def update_permission(group, user, perm, value):
pathname = get_pathname(group)
if not get_access(pathname).get("admin"):
raise frappe.PermissionError
permission = frappe.get_doc("Website Route Permission", {"website_route": pathname, "user": user})
permission.set(perm, int(value))
permission.save(ignore_permissions=True)
# send email
if perm=="admin" and int(value):
group_title = frappe.db.get_value("Website Route", pathname, "page_title")
subject = "You have been made Administrator of Group " + group_title
send(recipients=[user],
subject= subject, add_unsubscribe_link=False,
message="""<h3>Group Notification<h3>\
<p>%s</p>\
<p style="color: #888">This is just for your information.</p>""" % subject)
@frappe.whitelist()
def update_description(group, description):
if not get_access(get_pathname(group)).get("admin"):
raise frappe.PermissionError
group = frappe.get_doc("Website Group", group)
group.group_description = description
group.save(ignore_permissions=True)
@frappe.whitelist()
def add_website_group(group, new_group, public_read, public_write, group_type="Forum"):
if not get_access(get_pathname(group)).get("admin"):
raise frappe.PermissionError
parent_website_route = frappe.db.get_value("Website Route",
{"ref_doctype": "Website Group", "docname": group})
frappe.get_doc({
"doctype": "Website Group",
"group_name": group + "-" + new_group,
"group_title": new_group,
"parent_website_route": parent_website_route,
"group_type": group_type,
"public_read": int(public_read),
"public_write": int(public_write)
}).insert(ignore_permissions=True)
|
mit
|
[
3,
1898,
334,
67,
9,
6171,
12,
6001,
8144,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
10697,
844,
14,
1666,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
504,
6950,
14,
7360,
14,
6060,
492,
664,
63,
2732,
12,
5436,
63,
6060,
199,
504,
6950,
14,
5876,
14,
20748,
14,
7360,
63,
923,
492,
664,
63,
12445,
199,
504,
6950,
14,
1208,
14,
2123,
63,
773,
14,
9377,
492,
3222,
199,
199,
32,
9098,
14,
14189,
342,
199,
318,
18453,
63,
751,
8,
5125,
12,
1572,
304,
199,
198,
12445,
275,
664,
63,
12445,
8,
923,
9,
199,
198,
692,
440,
664,
63,
2732,
8,
12445,
680,
362,
480,
2113,
2349,
507,
198,
3730,
6950,
14,
7980,
547,
18118,
198,
3707,
275,
6950,
14,
697,
14,
3009,
4852,
2416,
5448,
14,
354,
12,
5448,
14,
2246,
63,
354,
12,
5448,
14,
2019,
63,
354,
12,
11083,
198,
2700,
14,
751,
63,
1569,
12,
5448,
14,
1985,
507,
198,
504,
658,
2902,
1899,
64,
5448,
11083,
198,
4509,
334,
2700,
14,
2246,
63,
354,
2839,
2818,
5125,
9,
83,
503,
5448,
14,
2019,
63,
354,
2839,
2818,
5125,
9,
83,
9,
507,
198,
460,
5448,
14,
751,
63,
466,
275,
298,
26354,
2876,
2,
507,
198,
460,
5448,
14,
751,
63,
1569,
365,
440,
2973,
436,
5448,
14,
3827,
29,
17,
507,
198,
460,
440,
3495,
8,
2416,
336,
681,
14,
354,
687,
658,
2902,
26354,
24244,
8779,
64,
336,
681,
20866,
198,
4509,
336,
681,
14,
7360,
63,
4449,
15438,
923,
9,
83,
436,
336,
681,
14,
751,
29,
2700,
14,
354,
9,
7208,
11083,
198,
6641,
5125,
582,
2071,
2440,
5,
1674,
908,
8,
5125,
395,
298,
923,
582,
11776,
1386,
465,
63,
807,
29,
549,
9,
8299,
198,
1160,
275,
6950,
14,
362,
63,
1160,
480,
5876,
15,
9441,
15,
751,
63,
2918,
14,
1360,
531,
199,
198,
1107,
8910,
507,
198,
2,
585,
582,
11491,
8352,
908,
8,
2700,
14,
2246,
63,
354,
503,
4873,
5448,
14,
2019,
63,
354,
503,
16241,
507,
198,
2,
751,
63,
1360,
582,
1978,
14,
3352,
6333,
751,
582,
5448,
8688,
507,
198,
2,
751,
582,
5448,
14,
354,
199,
198,
93,
367,
5448,
315,
4390,
61,
199,
199,
32,
9098,
14,
14189,
342,
199,
318,
1050,
63,
17205,
63,
5693,
8,
923,
12,
922,
304,
199,
198,
12445,
275,
664,
63,
12445,
8,
923,
9,
199,
198,
692,
440,
664,
63,
2732,
8,
12445,
680,
362,
480,
2113,
2349,
507,
198,
3730,
6950,
14,
7980,
547,
18118,
198,
5693,
275,
6950,
14,
362,
63,
1301,
2561,
507,
198,
2,
6356,
582,
298,
26354,
24244,
8779,
401,
507,
198,
2,
7360,
63,
4449,
582,
11776,
12,
507,
198,
2,
751,
582,
922,
12,
507,
198,
2,
739,
582,
413,
199,
198,
1552,
199,
198,
5693,
14,
3176,
8,
4247,
63,
6060,
29,
549,
9,
8299,
198,
751,
275,
4983,
14,
305,
63,
807,
342,
199,
198,
751,
14,
873,
8,
9098,
14,
697,
14,
362,
63,
585,
480,
1899,
401,
922,
14,
751,
12,
11083,
198,
905,
354,
401,
298,
2246,
63,
354,
401,
298,
2019,
63,
354,
401,
298,
751,
63,
1569,
401,
298,
1985,
2255,
465,
63,
807,
29,
549,
430,
8299,
198,
1107,
6950,
14,
362,
63,
1160,
480,
5876,
15,
9441,
15,
17205,
63,
5693,
14,
1360,
3471,
3352,
2561,
507,
198,
2,
751,
582,
922,
199,
198,
1552,
199,
199,
32,
9098,
14,
14189,
342,
199,
318,
1678,
63,
5693,
8,
923,
12,
922,
12,
10869,
12,
574,
304,
199,
198,
12445,
275,
664,
63,
12445,
8,
923,
9,
199,
198,
692,
440,
664,
63,
2732,
8,
12445,
680,
362,
480,
2113,
2349,
507,
198,
3730,
6950,
14,
7980,
547,
18118,
198,
5693,
275,
6950,
14,
362,
63,
1301,
480,
26354,
24244,
8779,
401,
2420,
7360,
63,
4449,
582,
11776,
12,
298,
751,
582,
922,
1552,
199,
198,
5693,
14,
409,
8,
8220,
12,
1109,
8,
585,
430,
199,
198,
5693,
14,
2117,
8,
4247,
63,
6060,
29,
549,
9,
8299,
198,
3,
3222,
3031,
199,
198,
692,
10869,
11800,
2113,
2,
436,
1109,
8,
585,
304,
507,
198,
923,
63,
1213,
275,
6950,
14,
697,
14,
362,
63,
585,
480,
26354,
24244,
401,
11776,
12,
298,
1606,
63,
1213,
531,
9068,
198,
5875,
275,
298,
5556,
1172,
2757,
6326,
30660,
402,
5611,
298,
435,
1572,
63,
1213,
9068,
198,
2254,
8,
18323,
1524,
751,
467,
20866,
198,
5875,
29,
5420,
12,
1050,
63,
25592,
63,
1073,
29,
797,
12,
686,
198,
1188,
11916,
28,
72,
19,
30,
2448,
23362,
28,
72,
19,
3072,
686,
198,
28,
80,
6598,
83,
1108,
80,
3072,
686,
198,
28,
80,
3449,
628,
2326,
26,
327,
13997,
1743,
2765,
365,
2951,
367,
2195,
2556,
9758,
80,
11193,
450,
5420,
9,
199,
199,
32,
9098,
14,
14189,
342,
199,
318,
1678,
63,
1802,
8,
923,
12,
1369,
304,
199,
198,
692,
440,
664,
63,
2732,
8,
362,
63,
12445,
8,
923,
4992,
362,
480,
2113,
2349,
507,
198,
3730,
6950,
14,
7980,
547,
421,
198,
923,
275,
6950,
14,
362,
63,
1301,
480,
26354,
5611,
401,
1572,
9,
199,
198,
923,
14,
923,
63,
1802,
275,
1369,
199,
198,
923,
14,
2117,
8,
4247,
63,
6060,
29,
549,
9,
507,
199,
32,
9098,
14,
14189,
342,
199,
318,
1050,
63,
7360,
63,
923,
8,
923,
12,
892,
63,
923,
12,
4575,
63,
739,
12,
4575,
63,
952,
12,
1572,
63,
466,
628,
1858,
453,
2349,
199,
198,
692,
440,
664,
63,
2732,
8,
362,
63,
12445,
8,
923,
4992,
362,
480,
2113,
2349,
507,
198,
3730,
6950,
14,
7980,
547,
18118,
198,
1708,
63,
7360,
63,
4449,
275,
6950,
14,
697,
14,
362,
63,
585,
480,
26354,
24244,
401,
11083,
198,
6641,
1121,
63,
6356,
582,
298,
26354,
5611,
401,
298,
21828,
582,
1572,
1552,
8299,
198,
9098,
14,
362,
63,
1301,
2561,
507,
198,
2,
6356,
582,
298,
26354,
5611,
401,
507,
198,
2,
923,
63,
354,
582,
1572,
435,
17155,
435,
892,
63,
923,
12,
507,
198,
2,
923,
63,
1213,
582,
892,
63,
923,
12,
507,
198,
2,
1708,
63,
7360
] |
[
1898,
334,
67,
9,
6171,
12,
6001,
8144,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
10697,
844,
14,
1666,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
504,
6950,
14,
7360,
14,
6060,
492,
664,
63,
2732,
12,
5436,
63,
6060,
199,
504,
6950,
14,
5876,
14,
20748,
14,
7360,
63,
923,
492,
664,
63,
12445,
199,
504,
6950,
14,
1208,
14,
2123,
63,
773,
14,
9377,
492,
3222,
199,
199,
32,
9098,
14,
14189,
342,
199,
318,
18453,
63,
751,
8,
5125,
12,
1572,
304,
199,
198,
12445,
275,
664,
63,
12445,
8,
923,
9,
199,
198,
692,
440,
664,
63,
2732,
8,
12445,
680,
362,
480,
2113,
2349,
507,
198,
3730,
6950,
14,
7980,
547,
18118,
198,
3707,
275,
6950,
14,
697,
14,
3009,
4852,
2416,
5448,
14,
354,
12,
5448,
14,
2246,
63,
354,
12,
5448,
14,
2019,
63,
354,
12,
11083,
198,
2700,
14,
751,
63,
1569,
12,
5448,
14,
1985,
507,
198,
504,
658,
2902,
1899,
64,
5448,
11083,
198,
4509,
334,
2700,
14,
2246,
63,
354,
2839,
2818,
5125,
9,
83,
503,
5448,
14,
2019,
63,
354,
2839,
2818,
5125,
9,
83,
9,
507,
198,
460,
5448,
14,
751,
63,
466,
275,
298,
26354,
2876,
2,
507,
198,
460,
5448,
14,
751,
63,
1569,
365,
440,
2973,
436,
5448,
14,
3827,
29,
17,
507,
198,
460,
440,
3495,
8,
2416,
336,
681,
14,
354,
687,
658,
2902,
26354,
24244,
8779,
64,
336,
681,
20866,
198,
4509,
336,
681,
14,
7360,
63,
4449,
15438,
923,
9,
83,
436,
336,
681,
14,
751,
29,
2700,
14,
354,
9,
7208,
11083,
198,
6641,
5125,
582,
2071,
2440,
5,
1674,
908,
8,
5125,
395,
298,
923,
582,
11776,
1386,
465,
63,
807,
29,
549,
9,
8299,
198,
1160,
275,
6950,
14,
362,
63,
1160,
480,
5876,
15,
9441,
15,
751,
63,
2918,
14,
1360,
531,
199,
198,
1107,
8910,
507,
198,
2,
585,
582,
11491,
8352,
908,
8,
2700,
14,
2246,
63,
354,
503,
4873,
5448,
14,
2019,
63,
354,
503,
16241,
507,
198,
2,
751,
63,
1360,
582,
1978,
14,
3352,
6333,
751,
582,
5448,
8688,
507,
198,
2,
751,
582,
5448,
14,
354,
199,
198,
93,
367,
5448,
315,
4390,
61,
199,
199,
32,
9098,
14,
14189,
342,
199,
318,
1050,
63,
17205,
63,
5693,
8,
923,
12,
922,
304,
199,
198,
12445,
275,
664,
63,
12445,
8,
923,
9,
199,
198,
692,
440,
664,
63,
2732,
8,
12445,
680,
362,
480,
2113,
2349,
507,
198,
3730,
6950,
14,
7980,
547,
18118,
198,
5693,
275,
6950,
14,
362,
63,
1301,
2561,
507,
198,
2,
6356,
582,
298,
26354,
24244,
8779,
401,
507,
198,
2,
7360,
63,
4449,
582,
11776,
12,
507,
198,
2,
751,
582,
922,
12,
507,
198,
2,
739,
582,
413,
199,
198,
1552,
199,
198,
5693,
14,
3176,
8,
4247,
63,
6060,
29,
549,
9,
8299,
198,
751,
275,
4983,
14,
305,
63,
807,
342,
199,
198,
751,
14,
873,
8,
9098,
14,
697,
14,
362,
63,
585,
480,
1899,
401,
922,
14,
751,
12,
11083,
198,
905,
354,
401,
298,
2246,
63,
354,
401,
298,
2019,
63,
354,
401,
298,
751,
63,
1569,
401,
298,
1985,
2255,
465,
63,
807,
29,
549,
430,
8299,
198,
1107,
6950,
14,
362,
63,
1160,
480,
5876,
15,
9441,
15,
17205,
63,
5693,
14,
1360,
3471,
3352,
2561,
507,
198,
2,
751,
582,
922,
199,
198,
1552,
199,
199,
32,
9098,
14,
14189,
342,
199,
318,
1678,
63,
5693,
8,
923,
12,
922,
12,
10869,
12,
574,
304,
199,
198,
12445,
275,
664,
63,
12445,
8,
923,
9,
199,
198,
692,
440,
664,
63,
2732,
8,
12445,
680,
362,
480,
2113,
2349,
507,
198,
3730,
6950,
14,
7980,
547,
18118,
198,
5693,
275,
6950,
14,
362,
63,
1301,
480,
26354,
24244,
8779,
401,
2420,
7360,
63,
4449,
582,
11776,
12,
298,
751,
582,
922,
1552,
199,
198,
5693,
14,
409,
8,
8220,
12,
1109,
8,
585,
430,
199,
198,
5693,
14,
2117,
8,
4247,
63,
6060,
29,
549,
9,
8299,
198,
3,
3222,
3031,
199,
198,
692,
10869,
11800,
2113,
2,
436,
1109,
8,
585,
304,
507,
198,
923,
63,
1213,
275,
6950,
14,
697,
14,
362,
63,
585,
480,
26354,
24244,
401,
11776,
12,
298,
1606,
63,
1213,
531,
9068,
198,
5875,
275,
298,
5556,
1172,
2757,
6326,
30660,
402,
5611,
298,
435,
1572,
63,
1213,
9068,
198,
2254,
8,
18323,
1524,
751,
467,
20866,
198,
5875,
29,
5420,
12,
1050,
63,
25592,
63,
1073,
29,
797,
12,
686,
198,
1188,
11916,
28,
72,
19,
30,
2448,
23362,
28,
72,
19,
3072,
686,
198,
28,
80,
6598,
83,
1108,
80,
3072,
686,
198,
28,
80,
3449,
628,
2326,
26,
327,
13997,
1743,
2765,
365,
2951,
367,
2195,
2556,
9758,
80,
11193,
450,
5420,
9,
199,
199,
32,
9098,
14,
14189,
342,
199,
318,
1678,
63,
1802,
8,
923,
12,
1369,
304,
199,
198,
692,
440,
664,
63,
2732,
8,
362,
63,
12445,
8,
923,
4992,
362,
480,
2113,
2349,
507,
198,
3730,
6950,
14,
7980,
547,
421,
198,
923,
275,
6950,
14,
362,
63,
1301,
480,
26354,
5611,
401,
1572,
9,
199,
198,
923,
14,
923,
63,
1802,
275,
1369,
199,
198,
923,
14,
2117,
8,
4247,
63,
6060,
29,
549,
9,
507,
199,
32,
9098,
14,
14189,
342,
199,
318,
1050,
63,
7360,
63,
923,
8,
923,
12,
892,
63,
923,
12,
4575,
63,
739,
12,
4575,
63,
952,
12,
1572,
63,
466,
628,
1858,
453,
2349,
199,
198,
692,
440,
664,
63,
2732,
8,
362,
63,
12445,
8,
923,
4992,
362,
480,
2113,
2349,
507,
198,
3730,
6950,
14,
7980,
547,
18118,
198,
1708,
63,
7360,
63,
4449,
275,
6950,
14,
697,
14,
362,
63,
585,
480,
26354,
24244,
401,
11083,
198,
6641,
1121,
63,
6356,
582,
298,
26354,
5611,
401,
298,
21828,
582,
1572,
1552,
8299,
198,
9098,
14,
362,
63,
1301,
2561,
507,
198,
2,
6356,
582,
298,
26354,
5611,
401,
507,
198,
2,
923,
63,
354,
582,
1572,
435,
17155,
435,
892,
63,
923,
12,
507,
198,
2,
923,
63,
1213,
582,
892,
63,
923,
12,
507,
198,
2,
1708,
63,
7360,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dsjohns2/CS-241-Honors-Project
|
File_Encoder/yacctab.py
|
34
|
130122
|
# yacctab.py
# This file is automatically generated. Do not edit.
_tabversion = '3.8'
_lr_method = 'LALR'
_lr_signature = '5B6B33CB64AC0388290E0F1204699060'
_lr_action_items = {'VOID':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,68,80,82,84,89,91,92,93,94,95,96,97,98,99,100,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[6,6,-67,-78,-77,-64,-60,-61,-35,-31,-65,6,-37,-59,-74,-69,-36,-58,6,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,6,-73,6,-76,-80,6,-39,-63,-90,-269,-89,6,-118,-117,-32,-107,-106,6,6,6,-51,-52,6,-40,-120,6,6,6,6,-100,-96,6,6,6,6,-41,6,-53,6,6,-91,-97,-270,-108,-126,-125,6,6,6,6,6,-42,-44,-47,-43,-45,6,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,6,-180,-179,6,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'LBRACKET':([1,2,3,5,6,9,10,13,14,17,18,19,22,24,26,27,28,29,30,31,33,34,36,38,40,41,43,44,45,46,47,51,52,53,54,56,57,58,60,62,64,65,69,70,71,72,76,80,83,85,86,88,93,97,100,101,114,116,119,120,122,125,126,127,128,129,130,133,134,142,144,147,149,150,152,153,157,159,170,171,178,180,181,182,183,184,195,201,202,222,225,226,228,232,239,243,266,271,273,274,305,307,308,315,316,319,320,328,329,330,331,334,339,343,344,365,367,369,371,372,373,393,394,396,397,404,406,422,423,434,437,438,445,447,452,],[-271,-67,-78,-77,-64,-60,-61,-65,-271,-59,-74,-69,-58,-62,-183,67,-72,-271,-75,74,-79,-119,-70,-66,-68,-71,-271,-73,-271,-76,-80,-63,-56,-9,-10,-90,-269,-89,-55,67,-107,-106,-28,-127,-129,-27,74,74,168,-54,-57,74,-120,-271,-271,74,74,-256,-130,-128,-260,-248,-263,-267,-264,-261,-246,-247,230,-259,-233,-265,-257,-245,-262,-258,168,268,74,74,-91,-270,-23,-88,-24,-87,-108,-126,-125,-268,-266,-242,-241,-155,-157,74,-145,268,-159,-153,-256,-93,-92,-110,-109,-121,-124,-240,-239,-238,-237,-236,-249,74,74,-148,268,-146,-154,-156,-158,-123,-122,-234,-235,268,-147,436,-251,-250,268,-243,-252,-244,-253,]),'WCHAR_CONST':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,119,123,131,132,138,139,141,143,145,146,148,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,314,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,398,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,436,437,440,441,442,444,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,128,128,-51,-40,128,-28,-271,-130,-232,128,-230,128,-229,128,-228,128,128,-227,-231,-271,-228,128,128,128,-270,128,128,-228,128,128,-189,-192,-190,-186,-187,-191,-193,128,-195,-196,-188,-194,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,-12,128,128,-11,-228,-44,-47,-43,128,-45,128,128,-49,-161,-160,-48,-162,128,-46,128,128,128,-271,-144,-180,-179,128,-177,128,128,-163,128,-176,-164,128,128,128,128,-271,128,128,-11,-175,-178,128,-167,128,-165,128,128,-166,128,128,128,128,-271,128,-171,-170,-168,128,128,128,-172,-169,128,-174,-173,]),'FLOAT_CONST':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,119,123,131,132,138,139,141,143,145,146,148,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,314,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,398,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,436,437,440,441,442,444,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,129,129,-51,-40,129,-28,-271,-130,-232,129,-230,129,-229,129,-228,129,129,-227,-231,-271,-228,129,129,129,-270,129,129,-228,129,129,-189,-192,-190,-186,-187,-191,-193,129,-195,-196,-188,-194,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,-12,129,129,-11,-228,-44,-47,-43,129,-45,129,129,-49,-161,-160,-48,-162,129,-46,129,129,129,-271,-144,-180,-179,129,-177,129,129,-163,129,-176,-164,129,129,129,129,-271,129,129,-11,-175,-178,129,-167,129,-165,129,129,-166,129,129,129,129,-271,129,-171,-170,-168,129,129,129,-172,-169,129,-174,-173,]),'MINUS':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,116,119,122,123,124,125,126,127,128,129,130,131,132,133,134,136,138,139,141,142,143,144,145,146,147,148,149,150,151,152,153,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,228,230,231,234,235,236,237,238,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,305,314,328,329,330,331,334,339,340,341,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,367,370,375,376,378,379,380,381,384,385,386,388,389,390,395,396,397,398,400,403,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,434,436,437,438,440,441,442,444,447,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,132,132,-51,-40,132,-28,-271,-256,-130,-260,-232,-219,-248,-263,-267,-264,-261,-246,132,-230,-247,-221,-200,132,-229,132,-259,-228,-233,132,132,-265,-227,-257,-245,248,-262,-258,-231,-271,-228,132,132,132,-270,132,132,-228,132,132,-189,-192,-190,-186,-187,-191,-193,132,-195,-196,-188,-194,-268,132,-225,-266,-242,-241,132,132,132,-219,-224,132,-222,-223,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,-12,132,132,-11,-228,-44,-47,-43,132,-45,132,132,-49,-161,-160,-48,-162,132,-46,-256,132,-240,-239,-238,-237,-236,-249,132,132,248,248,248,-205,248,248,248,-204,248,248,-202,-201,248,248,248,248,248,-203,-271,-144,-180,-179,132,-177,132,132,-163,132,-176,-164,132,132,-226,-234,-235,132,132,-220,-271,132,132,-11,-175,-178,132,-167,132,-165,132,132,-166,132,132,132,-250,132,-271,-243,132,-171,-170,-168,-244,132,132,132,-172,-169,132,-174,-173,]),'RPAREN':([1,2,3,5,6,9,10,13,14,17,18,19,22,24,26,27,28,29,30,33,34,36,38,40,41,43,44,45,46,47,51,52,53,54,55,56,58,60,61,62,64,65,68,69,70,71,72,76,80,83,85,86,93,97,100,110,111,112,113,114,115,116,117,118,119,120,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,155,157,162,163,164,165,169,170,171,178,180,181,182,183,184,195,201,202,203,204,205,206,222,224,225,226,228,231,232,235,236,238,239,240,241,242,243,244,273,274,279,289,307,308,315,316,319,320,323,324,325,326,327,328,329,330,331,333,334,335,337,338,339,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,371,372,373,383,393,394,395,396,397,402,403,415,417,420,421,422,423,425,434,438,440,443,445,447,448,449,452,453,],[-271,-67,-78,-77,-64,-60,-61,-65,-271,-59,-74,-69,-58,-62,-183,-116,-72,-271,-75,-79,-119,-70,-66,-68,-71,-271,-73,-271,-76,-80,-63,-56,-9,-10,93,-90,-89,-55,-118,-117,-107,-106,-271,-28,-127,-129,-27,-150,-271,-152,-54,-57,-120,-271,-271,201,-15,202,-133,-271,-16,-256,-131,-137,-130,-128,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,-198,-262,-258,-184,-151,-21,-22,273,274,-271,-150,-271,-91,-270,-23,-88,-24,-87,-108,-126,-125,-136,-1,-2,-135,-268,-225,-266,-242,-241,334,-155,-219,-224,-222,-157,339,341,-181,-271,-223,-159,-153,373,-14,-93,-92,-110,-109,-121,-124,-138,-132,-134,-185,395,-240,-239,-238,-237,-254,-236,397,400,401,-249,-149,-271,-150,-206,-218,-207,-205,-209,-213,-208,-204,-211,-216,-202,-201,-210,-217,-212,-214,-215,-203,-154,-156,-158,-13,-123,-122,-226,-234,-235,-182,-220,429,431,433,-255,434,-251,-199,-250,-243,-271,450,-252,-244,-271,454,-253,457,]),'LONG':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,68,80,82,84,89,91,92,93,94,95,96,97,98,99,100,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[19,19,-67,-78,-77,-64,-60,-61,-35,-31,-65,19,-37,-59,-74,-69,-36,-58,19,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,19,-73,19,-76,-80,19,-39,-63,-90,-269,-89,19,-118,-117,-32,-107,-106,19,19,19,-51,-52,19,-40,-120,19,19,19,19,-100,-96,19,19,19,19,-41,19,-53,19,19,-91,-97,-270,-108,-126,-125,19,19,19,19,19,-42,-44,-47,-43,-45,19,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,19,-180,-179,19,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'PLUS':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,116,119,122,123,124,125,126,127,128,129,130,131,132,133,134,136,138,139,141,142,143,144,145,146,147,148,149,150,151,152,153,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,228,230,231,234,235,236,237,238,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,305,314,328,329,330,331,334,339,340,341,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,367,370,375,376,378,379,380,381,384,385,386,388,389,390,395,396,397,398,400,403,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,434,436,437,438,440,441,442,444,447,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,139,139,-51,-40,139,-28,-271,-256,-130,-260,-232,-219,-248,-263,-267,-264,-261,-246,139,-230,-247,-221,-200,139,-229,139,-259,-228,-233,139,139,-265,-227,-257,-245,252,-262,-258,-231,-271,-228,139,139,139,-270,139,139,-228,139,139,-189,-192,-190,-186,-187,-191,-193,139,-195,-196,-188,-194,-268,139,-225,-266,-242,-241,139,139,139,-219,-224,139,-222,-223,139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,-12,139,139,-11,-228,-44,-47,-43,139,-45,139,139,-49,-161,-160,-48,-162,139,-46,-256,139,-240,-239,-238,-237,-236,-249,139,139,252,252,252,-205,252,252,252,-204,252,252,-202,-201,252,252,252,252,252,-203,-271,-144,-180,-179,139,-177,139,139,-163,139,-176,-164,139,139,-226,-234,-235,139,139,-220,-271,139,139,-11,-175,-178,139,-167,139,-165,139,139,-166,139,139,139,-250,139,-271,-243,139,-171,-170,-168,-244,139,139,139,-172,-169,139,-174,-173,]),'ELLIPSIS':([208,],[324,]),'GT':([116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,395,396,397,403,434,438,447,],[-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,253,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-206,253,-207,-205,-209,253,-208,-204,-211,253,-202,-201,-210,253,253,253,253,-203,-226,-234,-235,-220,-250,-243,-244,]),'GOTO':([50,57,84,92,174,180,280,281,284,286,293,295,296,297,298,300,302,303,375,376,379,380,384,386,388,389,410,411,414,416,419,429,430,431,433,441,442,444,451,454,455,456,457,458,459,],[-39,-269,-51,-40,282,-270,-44,-47,-43,-45,282,-49,-161,-160,-48,-162,282,-46,-180,-179,-177,282,-163,-176,-164,282,-175,-178,-167,282,-165,282,-166,282,282,-171,-170,-168,282,282,-172,-169,282,-174,-173,]),'ENUM':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,68,80,82,84,89,91,92,93,94,95,96,97,98,99,100,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[25,25,-67,-78,-77,-64,-60,-61,-35,-31,-65,25,-37,-59,-74,-69,-36,-58,25,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,25,-73,25,-76,-80,25,-39,-63,-90,-269,-89,25,-118,-117,-32,-107,-106,25,25,25,-51,-52,25,-40,-120,25,25,25,25,-100,-96,25,25,25,25,-41,25,-53,25,25,-91,-97,-270,-108,-126,-125,25,25,25,25,25,-42,-44,-47,-43,-45,25,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,25,-180,-179,25,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'PERIOD':([57,116,122,125,126,127,128,129,130,133,134,142,144,147,149,150,152,153,159,180,222,225,226,228,266,271,305,328,329,330,331,334,339,365,367,369,396,397,404,406,422,423,434,437,438,445,447,452,],[-269,-256,-260,-248,-263,-267,-264,-261,-246,-247,229,-259,-233,-265,-257,-245,-262,-258,267,-270,-268,-266,-242,-241,-145,267,-256,-240,-239,-238,-237,-236,-249,-148,267,-146,-234,-235,267,-147,435,-251,-250,267,-243,-252,-244,-253,]),'GE':([116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,395,396,397,403,434,438,447,],[-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,257,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-206,257,-207,-205,-209,257,-208,-204,-211,257,-202,-201,-210,257,257,257,257,-203,-226,-234,-235,-220,-250,-243,-244,]),'INT_CONST_DEC':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,119,123,131,132,138,139,141,143,145,146,148,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,314,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,398,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,436,437,440,441,442,444,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,149,149,-51,-40,149,-28,-271,-130,-232,149,-230,149,-229,149,-228,149,149,-227,-231,-271,-228,149,149,149,-270,149,149,-228,149,149,-189,-192,-190,-186,-187,-191,-193,149,-195,-196,-188,-194,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,-12,149,149,-11,-228,-44,-47,-43,149,-45,149,149,-49,-161,-160,-48,-162,149,-46,149,149,149,-271,-144,-180,-179,149,-177,149,149,-163,149,-176,-164,149,149,149,149,-271,149,149,-11,-175,-178,149,-167,149,-165,149,149,-166,149,149,149,149,-271,149,-171,-170,-168,149,149,149,-172,-169,149,-174,-173,]),'ARROW':([116,122,125,126,127,128,129,130,133,134,142,144,147,149,150,152,153,180,222,225,226,228,305,328,329,330,331,334,339,396,397,434,438,447,],[-256,-260,-248,-263,-267,-264,-261,-246,-247,227,-259,-233,-265,-257,-245,-262,-258,-270,-268,-266,-242,-241,-256,-240,-239,-238,-237,-236,-249,-234,-235,-250,-243,-244,]),'HEX_FLOAT_CONST':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,119,123,131,132,138,139,141,143,145,146,148,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,314,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,398,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,436,437,440,441,442,444,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,152,152,-51,-40,152,-28,-271,-130,-232,152,-230,152,-229,152,-228,152,152,-227,-231,-271,-228,152,152,152,-270,152,152,-228,152,152,-189,-192,-190,-186,-187,-191,-193,152,-195,-196,-188,-194,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,-12,152,152,-11,-228,-44,-47,-43,152,-45,152,152,-49,-161,-160,-48,-162,152,-46,152,152,152,-271,-144,-180,-179,152,-177,152,152,-163,152,-176,-164,152,152,152,152,-271,152,152,-11,-175,-178,152,-167,152,-165,152,152,-166,152,152,152,152,-271,152,-171,-170,-168,152,152,152,-172,-169,152,-174,-173,]),'DOUBLE':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,68,80,82,84,89,91,92,93,94,95,96,97,98,99,100,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[41,41,-67,-78,-77,-64,-60,-61,-35,-31,-65,41,-37,-59,-74,-69,-36,-58,41,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,41,-73,41,-76,-80,41,-39,-63,-90,-269,-89,41,-118,-117,-32,-107,-106,41,41,41,-51,-52,41,-40,-120,41,41,41,41,-100,-96,41,41,41,41,-41,41,-53,41,41,-91,-97,-270,-108,-126,-125,41,41,41,41,41,-42,-44,-47,-43,-45,41,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,41,-180,-179,41,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'MINUSEQUAL':([116,122,124,125,126,127,128,129,130,133,134,142,144,147,149,150,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,395,396,397,403,434,438,447,],[-256,-260,211,-248,-263,-267,-264,-261,-246,-247,-221,-259,-233,-265,-257,-245,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-226,-234,-235,-220,-250,-243,-244,]),'INT_CONST_OCT':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,119,123,131,132,138,139,141,143,145,146,148,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,314,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,398,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,436,437,440,441,442,444,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,153,153,-51,-40,153,-28,-271,-130,-232,153,-230,153,-229,153,-228,153,153,-227,-231,-271,-228,153,153,153,-270,153,153,-228,153,153,-189,-192,-190,-186,-187,-191,-193,153,-195,-196,-188,-194,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,-12,153,153,-11,-228,-44,-47,-43,153,-45,153,153,-49,-161,-160,-48,-162,153,-46,153,153,153,-271,-144,-180,-179,153,-177,153,153,-163,153,-176,-164,153,153,153,153,-271,153,153,-11,-175,-178,153,-167,153,-165,153,153,-166,153,153,153,153,-271,153,-171,-170,-168,153,153,153,-172,-169,153,-174,-173,]),'TIMESEQUAL':([116,122,124,125,126,127,128,129,130,133,134,142,144,147,149,150,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,395,396,397,403,434,438,447,],[-256,-260,220,-248,-263,-267,-264,-261,-246,-247,-221,-259,-233,-265,-257,-245,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-226,-234,-235,-220,-250,-243,-244,]),'OR':([116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,395,396,397,403,434,438,447,],[-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,262,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-206,262,-207,-205,-209,-213,-208,-204,-211,-216,-202,-201,-210,262,-212,-214,-215,-203,-226,-234,-235,-220,-250,-243,-244,]),'SHORT':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,68,80,82,84,89,91,92,93,94,95,96,97,98,99,100,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[2,2,-67,-78,-77,-64,-60,-61,-35,-31,-65,2,-37,-59,-74,-69,-36,-58,2,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,2,-73,2,-76,-80,2,-39,-63,-90,-269,-89,2,-118,-117,-32,-107,-106,2,2,2,-51,-52,2,-40,-120,2,2,2,2,-100,-96,2,2,2,2,-41,2,-53,2,2,-91,-97,-270,-108,-126,-125,2,2,2,2,2,-42,-44,-47,-43,-45,2,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,2,-180,-179,2,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'RETURN':([50,57,84,92,174,180,280,281,284,286,293,295,296,297,298,300,302,303,375,376,379,380,384,386,388,389,410,411,414,416,419,429,430,431,433,441,442,444,451,454,455,456,457,458,459,],[-39,-269,-51,-40,285,-270,-44,-47,-43,-45,285,-49,-161,-160,-48,-162,285,-46,-180,-179,-177,285,-163,-176,-164,285,-175,-178,-167,285,-165,285,-166,285,285,-171,-170,-168,285,285,-172,-169,285,-174,-173,]),'RSHIFTEQUAL':([116,122,124,125,126,127,128,129,130,133,134,142,144,147,149,150,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,395,396,397,403,434,438,447,],[-256,-260,221,-248,-263,-267,-264,-261,-246,-247,-221,-259,-233,-265,-257,-245,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-226,-234,-235,-220,-250,-243,-244,]),'RESTRICT':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,29,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,67,68,69,71,80,82,84,89,91,92,93,94,95,96,97,98,99,100,108,109,119,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[33,33,-67,-78,-77,-64,-60,-61,-35,-31,-65,33,-37,-59,-74,-69,-36,-58,33,-62,-183,-116,-72,33,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,33,-73,33,-76,-80,33,-39,-63,-90,-269,-89,33,-118,-117,-32,-107,-106,33,33,33,-129,33,33,-51,-52,33,-40,-120,33,33,33,33,-100,-96,33,33,33,-130,33,33,33,-41,33,-53,33,33,-91,-97,-270,-108,-126,-125,33,33,33,33,33,-42,-44,-47,-43,-45,33,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,33,-180,-179,33,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'STATIC':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,61,62,63,64,65,67,68,71,80,82,84,89,91,92,93,108,119,169,171,173,174,175,178,180,195,201,202,208,276,280,281,284,286,293,295,296,297,298,300,303,307,308,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[9,9,-67,-78,-77,-64,-60,-61,-35,-31,-65,9,-37,-59,-74,-69,-36,-58,9,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,9,-73,9,-76,-80,9,-39,-63,-90,-269,-89,-118,-117,-32,-107,-106,109,9,-129,9,9,-51,-52,9,-40,-120,199,-130,9,9,-41,9,-53,-91,-270,-108,-126,-125,9,-42,-44,-47,-43,-45,9,-49,-161,-160,-48,-162,-46,-93,-92,-110,-109,-121,-124,9,-180,-179,9,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'SIZEOF':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,119,123,131,132,138,139,141,143,145,146,148,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,314,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,398,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,436,437,440,441,442,444,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,131,131,-51,-40,131,-28,-271,-130,-232,131,-230,131,-229,131,-228,131,131,-227,-231,-271,-228,131,131,131,-270,131,131,-228,131,131,-189,-192,-190,-186,-187,-191,-193,131,-195,-196,-188,-194,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,-12,131,131,-11,-228,-44,-47,-43,131,-45,131,131,-49,-161,-160,-48,-162,131,-46,131,131,131,-271,-144,-180,-179,131,-177,131,131,-163,131,-176,-164,131,131,131,131,-271,131,131,-11,-175,-178,131,-167,131,-165,131,131,-166,131,131,131,131,-271,131,-171,-170,-168,131,131,131,-172,-169,131,-174,-173,]),'UNSIGNED':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,68,80,82,84,89,91,92,93,94,95,96,97,98,99,100,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[18,18,-67,-78,-77,-64,-60,-61,-35,-31,-65,18,-37,-59,-74,-69,-36,-58,18,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,18,-73,18,-76,-80,18,-39,-63,-90,-269,-89,18,-118,-117,-32,-107,-106,18,18,18,-51,-52,18,-40,-120,18,18,18,18,-100,-96,18,18,18,18,-41,18,-53,18,18,-91,-97,-270,-108,-126,-125,18,18,18,18,18,-42,-44,-47,-43,-45,18,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,18,-180,-179,18,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'UNION':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,68,80,82,84,89,91,92,93,94,95,96,97,98,99,100,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[20,20,-67,-78,-77,-64,-60,-61,-35,-31,-65,20,-37,-59,-74,-69,-36,-58,20,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,20,-73,20,-76,-80,20,-39,-63,-90,-269,-89,20,-118,-117,-32,-107,-106,20,20,20,-51,-52,20,-40,-120,20,20,20,20,-100,-96,20,20,20,20,-41,20,-53,20,20,-91,-97,-270,-108,-126,-125,20,20,20,20,20,-42,-44,-47,-43,-45,20,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,20,-180,-179,20,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'COLON':([2,3,5,6,13,18,19,26,27,28,30,33,34,36,38,40,41,44,46,47,56,58,61,62,64,65,93,97,100,101,116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,155,178,180,181,182,183,184,191,195,201,202,222,224,225,226,228,235,236,238,242,244,290,305,307,308,310,311,315,316,319,320,326,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,382,393,394,395,396,397,402,403,425,434,438,447,],[-67,-78,-77,-64,-65,-74,-69,-183,-116,-72,-75,-79,-119,-70,-66,-68,-71,-73,-76,-80,-90,-89,-118,-117,-107,-106,-120,-271,-271,185,-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,-198,-262,-258,-184,-91,-270,-23,-88,-24,-87,314,-108,-126,-125,-268,-225,-266,-242,-241,-219,-224,-222,-181,-223,380,389,-93,-92,-197,185,-110,-109,-121,-124,-185,-240,-239,-238,-237,-236,-249,-206,-218,-207,-205,-209,-213,-208,-204,-211,-216,-202,-201,-210,-217,-212,-214,405,-215,-203,416,-123,-122,-226,-234,-235,-182,-220,-199,-250,-243,-244,]),'$end':([0,8,11,12,15,21,23,32,37,39,48,50,63,84,92,173,180,276,388,],[-271,0,-35,-31,-37,-36,-29,-34,-33,-38,-30,-39,-32,-51,-40,-41,-270,-42,-164,]),'WSTRING_LITERAL':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,119,123,125,127,131,132,138,139,141,143,145,146,148,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,222,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,314,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,398,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,436,437,440,441,442,444,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,127,127,-51,-40,127,-28,-271,-130,-232,222,-267,127,-230,127,-229,127,-228,127,127,-227,-231,-271,-228,127,127,127,-270,127,127,-228,127,127,-189,-192,-190,-186,-187,-191,-193,127,-195,-196,-188,-194,-268,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,-12,127,127,-11,-228,-44,-47,-43,127,-45,127,127,-49,-161,-160,-48,-162,127,-46,127,127,127,-271,-144,-180,-179,127,-177,127,127,-163,127,-176,-164,127,127,127,127,-271,127,127,-11,-175,-178,127,-167,127,-165,127,127,-166,127,127,127,127,-271,127,-171,-170,-168,127,127,127,-172,-169,127,-174,-173,]),'DIVIDE':([116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,395,396,397,403,434,438,447,],[-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,255,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,255,255,255,255,255,255,255,255,255,255,-202,-201,255,255,255,255,255,-203,-226,-234,-235,-220,-250,-243,-244,]),'FOR':([50,57,84,92,174,180,280,281,284,286,293,295,296,297,298,300,302,303,375,376,379,380,384,386,388,389,410,411,414,416,419,429,430,431,433,441,442,444,451,454,455,456,457,458,459,],[-39,-269,-51,-40,287,-270,-44,-47,-43,-45,287,-49,-161,-160,-48,-162,287,-46,-180,-179,-177,287,-163,-176,-164,287,-175,-178,-167,287,-165,287,-166,287,287,-171,-170,-168,287,287,-172,-169,287,-174,-173,]),'PLUSPLUS':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,116,119,122,123,125,126,127,128,129,130,131,132,133,134,138,139,141,142,143,144,145,146,147,148,149,150,152,153,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,222,223,225,226,228,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,305,314,328,329,330,331,334,339,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,396,397,398,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,434,436,437,438,440,441,442,444,447,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,141,141,-51,-40,141,-28,-271,-256,-130,-260,-232,-248,-263,-267,-264,-261,-246,141,-230,-247,228,141,-229,141,-259,-228,-233,141,141,-265,-227,-257,-245,-262,-258,-231,-271,-228,141,141,141,-270,141,141,-228,141,141,-189,-192,-190,-186,-187,-191,-193,141,-195,-196,-188,-194,-268,141,-266,-242,-241,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,-12,141,141,-11,-228,-44,-47,-43,141,-45,141,141,-49,-161,-160,-48,-162,141,-46,-256,141,-240,-239,-238,-237,-236,-249,141,141,-271,-144,-180,-179,141,-177,141,141,-163,141,-176,-164,141,141,-234,-235,141,141,-271,141,141,-11,-175,-178,141,-167,141,-165,141,141,-166,141,141,141,-250,141,-271,-243,141,-171,-170,-168,-244,141,141,141,-172,-169,141,-174,-173,]),'EQUALS':([1,2,3,5,6,9,10,13,14,17,18,19,22,24,26,27,28,30,31,33,34,36,38,40,41,43,44,45,46,47,51,52,53,54,56,58,60,61,62,64,65,82,85,86,88,93,106,116,122,124,125,126,127,128,129,130,133,134,142,144,147,149,150,152,153,172,178,180,195,201,202,222,224,225,226,228,235,236,238,244,266,271,305,307,308,315,316,319,320,328,329,330,331,334,339,365,369,393,394,395,396,397,403,406,434,438,447,],[-271,-67,-78,-77,-64,-60,-61,-65,-271,-59,-74,-69,-58,-62,-183,-116,-72,-75,79,-79,-119,-70,-66,-68,-71,-271,-73,-271,-76,-80,-63,-56,-9,-10,-90,-89,-55,-118,-117,-107,-106,166,-54,-57,79,-120,196,-256,-260,213,-248,-263,-267,-264,-261,-246,-247,-221,-259,-233,-265,-257,-245,-262,-258,166,-91,-270,-108,-126,-125,-268,-225,-266,-242,-241,-219,-224,-222,-223,-145,370,-256,-93,-92,-110,-109,-121,-124,-240,-239,-238,-237,-236,-249,-148,-146,-123,-122,-226,-234,-235,-220,-147,-250,-243,-244,]),'ELSE':([50,92,180,280,281,284,286,295,298,303,375,376,379,386,388,410,411,414,419,430,441,442,444,455,456,458,459,],[-39,-40,-270,-44,-47,-43,-45,-49,-48,-46,-180,-179,-177,-176,-164,-175,-178,-167,-165,-166,-171,-170,451,-172,-169,-174,-173,]),'ANDEQUAL':([116,122,124,125,126,127,128,129,130,133,134,142,144,147,149,150,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,395,396,397,403,434,438,447,],[-256,-260,218,-248,-263,-267,-264,-261,-246,-247,-221,-259,-233,-265,-257,-245,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-226,-234,-235,-220,-250,-243,-244,]),'EQ':([116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,395,396,397,403,434,438,447,],[-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,259,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-206,259,-207,-205,-209,-213,-208,-204,-211,259,-202,-201,-210,259,-212,259,259,-203,-226,-234,-235,-220,-250,-243,-244,]),'AND':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,116,119,122,123,124,125,126,127,128,129,130,131,132,133,134,136,138,139,141,142,143,144,145,146,147,148,149,150,151,152,153,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,228,230,231,234,235,236,237,238,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,305,314,328,329,330,331,334,339,340,341,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,367,370,375,376,378,379,380,381,384,385,386,388,389,390,395,396,397,398,400,403,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,434,436,437,438,440,441,442,444,447,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,148,148,-51,-40,148,-28,-271,-256,-130,-260,-232,-219,-248,-263,-267,-264,-261,-246,148,-230,-247,-221,-200,148,-229,148,-259,-228,-233,148,148,-265,-227,-257,-245,260,-262,-258,-231,-271,-228,148,148,148,-270,148,148,-228,148,148,-189,-192,-190,-186,-187,-191,-193,148,-195,-196,-188,-194,-268,148,-225,-266,-242,-241,148,148,148,-219,-224,148,-222,-223,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,-12,148,148,-11,-228,-44,-47,-43,148,-45,148,148,-49,-161,-160,-48,-162,148,-46,-256,148,-240,-239,-238,-237,-236,-249,148,148,-206,260,-207,-205,-209,-213,-208,-204,-211,260,-202,-201,-210,260,-212,-214,260,-203,-271,-144,-180,-179,148,-177,148,148,-163,148,-176,-164,148,148,-226,-234,-235,148,148,-220,-271,148,148,-11,-175,-178,148,-167,148,-165,148,148,-166,148,148,148,-250,148,-271,-243,148,-171,-170,-168,-244,148,148,148,-172,-169,148,-174,-173,]),'TYPEID':([0,1,2,3,5,6,7,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,32,33,34,35,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,68,69,70,71,72,76,80,82,84,89,91,92,93,94,95,96,97,98,99,100,119,120,145,169,170,171,173,174,175,176,177,178,179,180,195,201,202,208,223,227,229,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[26,26,-67,-78,-77,-64,56,-60,-61,-35,-31,-65,26,-37,61,-59,-74,-69,-95,-36,-58,26,-62,64,-183,-116,-72,-271,-75,-34,-79,-119,-94,-70,-33,-66,-38,-68,-71,26,-73,26,-76,-80,26,-39,-63,-90,-269,-89,26,-118,-117,-32,-107,-106,26,-28,-127,-129,-27,61,26,26,-51,-52,26,-40,-120,26,26,26,26,-100,-96,26,-130,-128,26,26,61,26,-41,26,-53,26,26,-91,-97,-270,-108,-126,-125,26,26,328,330,26,26,26,-42,-44,-47,-43,-45,26,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,26,-180,-179,26,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'LBRACE':([7,20,25,27,34,35,49,50,56,57,58,61,62,64,65,79,82,84,87,89,90,91,92,93,159,166,167,174,175,180,201,202,264,270,272,280,281,284,286,293,295,296,297,298,300,302,303,319,320,341,367,370,375,376,379,380,384,386,388,389,393,394,395,400,401,404,407,408,410,411,414,416,419,429,430,431,433,437,441,442,444,451,454,455,456,457,458,459,],[57,-95,57,-116,-119,-94,-271,-39,57,-269,57,-118,-117,57,57,57,-271,-51,-7,-52,57,-8,-40,-120,-271,57,57,57,-53,-270,-126,-125,-12,57,-11,-44,-47,-43,-45,57,-49,-161,-160,-48,-162,57,-46,-121,-124,57,-271,-144,-180,-179,-177,57,-163,-176,-164,57,-123,-122,57,57,57,-271,57,-11,-175,-178,-167,57,-165,57,-166,57,57,-271,-171,-170,-168,57,57,-172,-169,57,-174,-173,]),'PPHASH':([0,11,12,15,21,23,32,37,39,50,63,84,92,173,180,276,388,],[39,-35,-31,-37,-36,39,-34,-33,-38,-39,-32,-51,-40,-41,-270,-42,-164,]),'INT':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,68,80,82,84,89,91,92,93,94,95,96,97,98,99,100,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[40,40,-67,-78,-77,-64,-60,-61,-35,-31,-65,40,-37,-59,-74,-69,-36,-58,40,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,40,-73,40,-76,-80,40,-39,-63,-90,-269,-89,40,-118,-117,-32,-107,-106,40,40,40,-51,-52,40,-40,-120,40,40,40,40,-100,-96,40,40,40,40,-41,40,-53,40,40,-91,-97,-270,-108,-126,-125,40,40,40,40,40,-42,-44,-47,-43,-45,40,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,40,-180,-179,40,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'SIGNED':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,68,80,82,84,89,91,92,93,94,95,96,97,98,99,100,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[44,44,-67,-78,-77,-64,-60,-61,-35,-31,-65,44,-37,-59,-74,-69,-36,-58,44,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,44,-73,44,-76,-80,44,-39,-63,-90,-269,-89,44,-118,-117,-32,-107,-106,44,44,44,-51,-52,44,-40,-120,44,44,44,44,-100,-96,44,44,44,44,-41,44,-53,44,44,-91,-97,-270,-108,-126,-125,44,44,44,44,44,-42,-44,-47,-43,-45,44,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,44,-180,-179,44,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'CONTINUE':([50,57,84,92,174,180,280,281,284,286,293,295,296,297,298,300,302,303,375,376,379,380,384,386,388,389,410,411,414,416,419,429,430,431,433,441,442,444,451,454,455,456,457,458,459,],[-39,-269,-51,-40,288,-270,-44,-47,-43,-45,288,-49,-161,-160,-48,-162,288,-46,-180,-179,-177,288,-163,-176,-164,288,-175,-178,-167,288,-165,288,-166,288,288,-171,-170,-168,288,288,-172,-169,288,-174,-173,]),'NOT':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,119,123,131,132,138,139,141,143,145,146,148,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,314,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,398,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,436,437,440,441,442,444,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,156,156,-51,-40,156,-28,-271,-130,-232,156,-230,156,-229,156,-228,156,156,-227,-231,-271,-228,156,156,156,-270,156,156,-228,156,156,-189,-192,-190,-186,-187,-191,-193,156,-195,-196,-188,-194,156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,-12,156,156,-11,-228,-44,-47,-43,156,-45,156,156,-49,-161,-160,-48,-162,156,-46,156,156,156,-271,-144,-180,-179,156,-177,156,156,-163,156,-176,-164,156,156,156,156,-271,156,156,-11,-175,-178,156,-167,156,-165,156,156,-166,156,156,156,156,-271,156,-171,-170,-168,156,156,156,-172,-169,156,-174,-173,]),'OREQUAL':([116,122,124,125,126,127,128,129,130,133,134,142,144,147,149,150,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,395,396,397,403,434,438,447,],[-256,-260,219,-248,-263,-267,-264,-261,-246,-247,-221,-259,-233,-265,-257,-245,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-226,-234,-235,-220,-250,-243,-244,]),'MOD':([116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,395,396,397,403,434,438,447,],[-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,263,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,263,263,263,263,263,263,263,263,263,263,-202,-201,263,263,263,263,263,-203,-226,-234,-235,-220,-250,-243,-244,]),'RSHIFT':([116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,395,396,397,403,434,438,447,],[-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,245,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-206,245,-207,-205,245,245,245,-204,245,245,-202,-201,245,245,245,245,245,-203,-226,-234,-235,-220,-250,-243,-244,]),'DEFAULT':([50,57,84,92,174,180,280,281,284,286,293,295,296,297,298,300,302,303,375,376,379,380,384,386,388,389,410,411,414,416,419,429,430,431,433,441,442,444,451,454,455,456,457,458,459,],[-39,-269,-51,-40,290,-270,-44,-47,-43,-45,290,-49,-161,-160,-48,-162,290,-46,-180,-179,-177,290,-163,-176,-164,290,-175,-178,-167,290,-165,290,-166,290,290,-171,-170,-168,290,290,-172,-169,290,-174,-173,]),'CHAR':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,68,80,82,84,89,91,92,93,94,95,96,97,98,99,100,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[38,38,-67,-78,-77,-64,-60,-61,-35,-31,-65,38,-37,-59,-74,-69,-36,-58,38,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,38,-73,38,-76,-80,38,-39,-63,-90,-269,-89,38,-118,-117,-32,-107,-106,38,38,38,-51,-52,38,-40,-120,38,38,38,38,-100,-96,38,38,38,38,-41,38,-53,38,38,-91,-97,-270,-108,-126,-125,38,38,38,38,38,-42,-44,-47,-43,-45,38,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,38,-180,-179,38,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'WHILE':([50,57,84,92,174,180,280,281,284,286,293,295,296,297,298,300,302,303,375,376,379,380,384,386,387,388,389,410,411,414,416,419,429,430,431,433,441,442,444,451,454,455,456,457,458,459,],[-39,-269,-51,-40,291,-270,-44,-47,-43,-45,291,-49,-161,-160,-48,-162,291,-46,-180,-179,-177,291,-163,-176,418,-164,291,-175,-178,-167,291,-165,291,-166,291,291,-171,-170,-168,291,291,-172,-169,291,-174,-173,]),'DIVEQUAL':([116,122,124,125,126,127,128,129,130,133,134,142,144,147,149,150,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,395,396,397,403,434,438,447,],[-256,-260,210,-248,-263,-267,-264,-261,-246,-247,-221,-259,-233,-265,-257,-245,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-226,-234,-235,-220,-250,-243,-244,]),'EXTERN':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,61,62,63,64,65,68,80,82,84,89,91,92,93,169,171,173,174,175,178,180,195,201,202,208,276,280,281,284,286,293,295,296,297,298,300,303,307,308,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[10,10,-67,-78,-77,-64,-60,-61,-35,-31,-65,10,-37,-59,-74,-69,-36,-58,10,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,10,-73,10,-76,-80,10,-39,-63,-90,-269,-89,-118,-117,-32,-107,-106,10,10,10,-51,-52,10,-40,-120,10,10,-41,10,-53,-91,-270,-108,-126,-125,10,-42,-44,-47,-43,-45,10,-49,-161,-160,-48,-162,-46,-93,-92,-110,-109,-121,-124,10,-180,-179,10,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'CASE':([50,57,84,92,174,180,280,281,284,286,293,295,296,297,298,300,302,303,375,376,379,380,384,386,388,389,410,411,414,416,419,429,430,431,433,441,442,444,451,454,455,456,457,458,459,],[-39,-269,-51,-40,292,-270,-44,-47,-43,-45,292,-49,-161,-160,-48,-162,292,-46,-180,-179,-177,292,-163,-176,-164,292,-175,-178,-167,292,-165,292,-166,292,292,-171,-170,-168,292,292,-172,-169,292,-174,-173,]),'LAND':([116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,395,396,397,403,434,438,447,],[-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,258,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-206,258,-207,-205,-209,-213,-208,-204,-211,-216,-202,-201,-210,-217,-212,-214,-215,-203,-226,-234,-235,-220,-250,-243,-244,]),'REGISTER':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,61,62,63,64,65,68,80,82,84,89,91,92,93,169,171,173,174,175,178,180,195,201,202,208,276,280,281,284,286,293,295,296,297,298,300,303,307,308,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[17,17,-67,-78,-77,-64,-60,-61,-35,-31,-65,17,-37,-59,-74,-69,-36,-58,17,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,17,-73,17,-76,-80,17,-39,-63,-90,-269,-89,-118,-117,-32,-107,-106,17,17,17,-51,-52,17,-40,-120,17,17,-41,17,-53,-91,-270,-108,-126,-125,17,-42,-44,-47,-43,-45,17,-49,-161,-160,-48,-162,-46,-93,-92,-110,-109,-121,-124,17,-180,-179,17,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'MODEQUAL':([116,122,124,125,126,127,128,129,130,133,134,142,144,147,149,150,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,395,396,397,403,434,438,447,],[-256,-260,212,-248,-263,-267,-264,-261,-246,-247,-221,-259,-233,-265,-257,-245,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-226,-234,-235,-220,-250,-243,-244,]),'NE':([116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,395,396,397,403,434,438,447,],[-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,250,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-206,250,-207,-205,-209,-213,-208,-204,-211,250,-202,-201,-210,250,-212,250,250,-203,-226,-234,-235,-220,-250,-243,-244,]),'SWITCH':([50,57,84,92,174,180,280,281,284,286,293,295,296,297,298,300,302,303,375,376,379,380,384,386,388,389,410,411,414,416,419,429,430,431,433,441,442,444,451,454,455,456,457,458,459,],[-39,-269,-51,-40,294,-270,-44,-47,-43,-45,294,-49,-161,-160,-48,-162,294,-46,-180,-179,-177,294,-163,-176,-164,294,-175,-178,-167,294,-165,294,-166,294,294,-171,-170,-168,294,294,-172,-169,294,-174,-173,]),'INT_CONST_HEX':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,119,123,131,132,138,139,141,143,145,146,148,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,314,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,398,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,436,437,440,441,442,444,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,142,142,-51,-40,142,-28,-271,-130,-232,142,-230,142,-229,142,-228,142,142,-227,-231,-271,-228,142,142,142,-270,142,142,-228,142,142,-189,-192,-190,-186,-187,-191,-193,142,-195,-196,-188,-194,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,-12,142,142,-11,-228,-44,-47,-43,142,-45,142,142,-49,-161,-160,-48,-162,142,-46,142,142,142,-271,-144,-180,-179,142,-177,142,142,-163,142,-176,-164,142,142,142,142,-271,142,142,-11,-175,-178,142,-167,142,-165,142,142,-166,142,142,142,142,-271,142,-171,-170,-168,142,142,142,-172,-169,142,-174,-173,]),'_COMPLEX':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,68,80,82,84,89,91,92,93,94,95,96,97,98,99,100,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[28,28,-67,-78,-77,-64,-60,-61,-35,-31,-65,28,-37,-59,-74,-69,-36,-58,28,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,28,-73,28,-76,-80,28,-39,-63,-90,-269,-89,28,-118,-117,-32,-107,-106,28,28,28,-51,-52,28,-40,-120,28,28,28,28,-100,-96,28,28,28,28,-41,28,-53,28,28,-91,-97,-270,-108,-126,-125,28,28,28,28,28,-42,-44,-47,-43,-45,28,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,28,-180,-179,28,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'PPPRAGMASTR':([50,],[92,]),'PLUSEQUAL':([116,122,124,125,126,127,128,129,130,133,134,142,144,147,149,150,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,395,396,397,403,434,438,447,],[-256,-260,215,-248,-263,-267,-264,-261,-246,-247,-221,-259,-233,-265,-257,-245,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-226,-234,-235,-220,-250,-243,-244,]),'STRUCT':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,68,80,82,84,89,91,92,93,94,95,96,97,98,99,100,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[35,35,-67,-78,-77,-64,-60,-61,-35,-31,-65,35,-37,-59,-74,-69,-36,-58,35,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,35,-73,35,-76,-80,35,-39,-63,-90,-269,-89,35,-118,-117,-32,-107,-106,35,35,35,-51,-52,35,-40,-120,35,35,35,35,-100,-96,35,35,35,35,-41,35,-53,35,35,-91,-97,-270,-108,-126,-125,35,35,35,35,35,-42,-44,-47,-43,-45,35,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,35,-180,-179,35,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'CONDOP':([116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,395,396,397,403,434,438,447,],[-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,261,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-206,-218,-207,-205,-209,-213,-208,-204,-211,-216,-202,-201,-210,-217,-212,-214,-215,-203,-226,-234,-235,-220,-250,-243,-244,]),'BREAK':([50,57,84,92,174,180,280,281,284,286,293,295,296,297,298,300,302,303,375,376,379,380,384,386,388,389,410,411,414,416,419,429,430,431,433,441,442,444,451,454,455,456,457,458,459,],[-39,-269,-51,-40,299,-270,-44,-47,-43,-45,299,-49,-161,-160,-48,-162,299,-46,-180,-179,-177,299,-163,-176,-164,299,-175,-178,-167,299,-165,299,-166,299,299,-171,-170,-168,299,299,-172,-169,299,-174,-173,]),'VOLATILE':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,29,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,67,68,69,71,80,82,84,89,91,92,93,94,95,96,97,98,99,100,108,109,119,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[47,47,-67,-78,-77,-64,-60,-61,-35,-31,-65,47,-37,-59,-74,-69,-36,-58,47,-62,-183,-116,-72,47,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,47,-73,47,-76,-80,47,-39,-63,-90,-269,-89,47,-118,-117,-32,-107,-106,47,47,47,-129,47,47,-51,-52,47,-40,-120,47,47,47,47,-100,-96,47,47,47,-130,47,47,47,-41,47,-53,47,47,-91,-97,-270,-108,-126,-125,47,47,47,47,47,-42,-44,-47,-43,-45,47,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,47,-180,-179,47,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'PPPRAGMA':([0,11,12,15,21,23,32,37,39,50,57,63,84,92,173,174,180,276,280,281,284,286,293,295,296,297,298,300,302,303,375,376,379,380,384,386,388,389,410,411,414,416,419,429,430,431,433,441,442,444,451,454,455,456,457,458,459,],[50,-35,-31,-37,-36,50,-34,-33,-38,-39,-269,-32,-51,-40,-41,50,-270,-42,-44,-47,-43,-45,50,-49,-161,-160,-48,-162,50,-46,-180,-179,-177,50,-163,-176,-164,50,-175,-178,-167,50,-165,50,-166,50,50,-171,-170,-168,50,50,-172,-169,50,-174,-173,]),'INLINE':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,61,62,63,64,65,68,80,82,84,89,91,92,93,169,171,173,174,175,178,180,195,201,202,208,276,280,281,284,286,293,295,296,297,298,300,303,307,308,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[51,51,-67,-78,-77,-64,-60,-61,-35,-31,-65,51,-37,-59,-74,-69,-36,-58,51,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,51,-73,51,-76,-80,51,-39,-63,-90,-269,-89,-118,-117,-32,-107,-106,51,51,51,-51,-52,51,-40,-120,51,51,-41,51,-53,-91,-270,-108,-126,-125,51,-42,-44,-47,-43,-45,51,-49,-161,-160,-48,-162,-46,-93,-92,-110,-109,-121,-124,51,-180,-179,51,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'INT_CONST_BIN':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,119,123,131,132,138,139,141,143,145,146,148,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,314,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,398,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,436,437,440,441,442,444,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,122,122,-51,-40,122,-28,-271,-130,-232,122,-230,122,-229,122,-228,122,122,-227,-231,-271,-228,122,122,122,-270,122,122,-228,122,122,-189,-192,-190,-186,-187,-191,-193,122,-195,-196,-188,-194,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,-12,122,122,-11,-228,-44,-47,-43,122,-45,122,122,-49,-161,-160,-48,-162,122,-46,122,122,122,-271,-144,-180,-179,122,-177,122,122,-163,122,-176,-164,122,122,122,122,-271,122,122,-11,-175,-178,122,-167,122,-165,122,122,-166,122,122,122,122,-271,122,-171,-170,-168,122,122,122,-172,-169,122,-174,-173,]),'DO':([50,57,84,92,174,180,280,281,284,286,293,295,296,297,298,300,302,303,375,376,379,380,384,386,388,389,410,411,414,416,419,429,430,431,433,441,442,444,451,454,455,456,457,458,459,],[-39,-269,-51,-40,302,-270,-44,-47,-43,-45,302,-49,-161,-160,-48,-162,302,-46,-180,-179,-177,302,-163,-176,-164,302,-175,-178,-167,302,-165,302,-166,302,302,-171,-170,-168,302,302,-172,-169,302,-174,-173,]),'LNOT':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,119,123,131,132,138,139,141,143,145,146,148,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,314,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,398,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,436,437,440,441,442,444,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,123,123,-51,-40,123,-28,-271,-130,-232,123,-230,123,-229,123,-228,123,123,-227,-231,-271,-228,123,123,123,-270,123,123,-228,123,123,-189,-192,-190,-186,-187,-191,-193,123,-195,-196,-188,-194,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,-12,123,123,-11,-228,-44,-47,-43,123,-45,123,123,-49,-161,-160,-48,-162,123,-46,123,123,123,-271,-144,-180,-179,123,-177,123,123,-163,123,-176,-164,123,123,123,123,-271,123,123,-11,-175,-178,123,-167,123,-165,123,123,-166,123,123,123,123,-271,123,-171,-170,-168,123,123,123,-172,-169,123,-174,-173,]),'CONST':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,29,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,67,68,69,71,80,82,84,89,91,92,93,94,95,96,97,98,99,100,108,109,119,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[3,3,-67,-78,-77,-64,-60,-61,-35,-31,-65,3,-37,-59,-74,-69,-36,-58,3,-62,-183,-116,-72,3,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,3,-73,3,-76,-80,3,-39,-63,-90,-269,-89,3,-118,-117,-32,-107,-106,3,3,3,-129,3,3,-51,-52,3,-40,-120,3,3,3,3,-100,-96,3,3,3,-130,3,3,3,-41,3,-53,3,3,-91,-97,-270,-108,-126,-125,3,3,3,3,3,-42,-44,-47,-43,-45,3,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,3,-180,-179,3,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'LOR':([116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,395,396,397,403,434,438,447,],[-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,246,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-206,-218,-207,-205,-209,-213,-208,-204,-211,-216,-202,-201,-210,-217,-212,-214,-215,-203,-226,-234,-235,-220,-250,-243,-244,]),'CHAR_CONST':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,119,123,131,132,138,139,141,143,145,146,148,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,314,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,398,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,436,437,440,441,442,444,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,126,126,-51,-40,126,-28,-271,-130,-232,126,-230,126,-229,126,-228,126,126,-227,-231,-271,-228,126,126,126,-270,126,126,-228,126,126,-189,-192,-190,-186,-187,-191,-193,126,-195,-196,-188,-194,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,-12,126,126,-11,-228,-44,-47,-43,126,-45,126,126,-49,-161,-160,-48,-162,126,-46,126,126,126,-271,-144,-180,-179,126,-177,126,126,-163,126,-176,-164,126,126,126,126,-271,126,126,-11,-175,-178,126,-167,126,-165,126,126,-166,126,126,126,126,-271,126,-171,-170,-168,126,126,126,-172,-169,126,-174,-173,]),'LSHIFT':([116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,395,396,397,403,434,438,447,],[-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,247,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-206,247,-207,-205,247,247,247,-204,247,247,-202,-201,247,247,247,247,247,-203,-226,-234,-235,-220,-250,-243,-244,]),'RBRACE':([50,57,84,92,96,98,99,104,105,106,116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,155,159,160,174,176,177,179,180,192,193,194,222,224,225,226,228,235,236,238,244,265,269,272,280,281,284,286,293,295,296,297,298,300,301,303,304,310,312,313,317,318,326,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,364,367,368,375,376,379,384,386,388,395,396,397,403,409,410,411,414,419,424,425,426,430,434,437,438,441,442,444,447,455,456,458,459,],[-39,-269,-51,-40,180,-100,-96,-111,180,-114,-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,-198,-262,-258,-184,-271,-139,-271,180,180,-97,-270,180,180,-112,-268,-225,-266,-242,-241,-219,-224,-222,-223,180,-20,-19,-44,-47,-43,-45,-6,-49,-161,-160,-48,-162,-5,-46,180,-197,-98,-99,-113,-115,-185,-240,-239,-238,-237,-236,-249,-206,-218,-207,-205,-209,-213,-208,-204,-211,-216,-202,-201,-210,-217,-212,-214,-215,-203,-140,180,-142,-180,-179,-177,-163,-176,-164,-226,-234,-235,-220,-141,-175,-178,-167,-165,180,-199,-143,-166,-250,180,-243,-171,-170,-168,-244,-172,-169,-174,-173,]),'_BOOL':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,68,80,82,84,89,91,92,93,94,95,96,97,98,99,100,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[13,13,-67,-78,-77,-64,-60,-61,-35,-31,-65,13,-37,-59,-74,-69,-36,-58,13,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,13,-73,13,-76,-80,13,-39,-63,-90,-269,-89,13,-118,-117,-32,-107,-106,13,13,13,-51,-52,13,-40,-120,13,13,13,13,-100,-96,13,13,13,13,-41,13,-53,13,13,-91,-97,-270,-108,-126,-125,13,13,13,13,13,-42,-44,-47,-43,-45,13,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,13,-180,-179,13,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'LE':([116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,395,396,397,403,434,438,447,],[-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,249,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-206,249,-207,-205,-209,249,-208,-204,-211,249,-202,-201,-210,249,249,249,249,-203,-226,-234,-235,-220,-250,-243,-244,]),'SEMI':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,29,30,31,32,33,34,36,37,38,39,40,41,42,43,44,45,46,47,50,51,52,53,54,56,57,58,59,60,61,62,63,64,65,69,70,71,72,73,75,76,77,78,81,82,83,84,85,86,88,92,93,94,95,96,97,98,99,100,101,116,119,120,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,155,157,158,160,170,172,173,174,176,177,178,179,180,181,182,183,184,186,187,188,189,190,191,195,201,202,209,222,224,225,226,228,232,235,236,238,239,242,244,273,274,275,276,280,281,283,284,285,286,288,289,293,295,296,297,298,299,300,301,302,303,305,307,308,309,310,312,313,315,316,319,320,326,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,364,371,372,373,374,375,376,377,378,379,380,383,384,386,388,389,391,392,393,394,395,396,397,402,403,409,410,411,412,413,414,416,419,425,427,428,429,430,431,433,434,438,439,441,442,444,447,450,451,454,455,456,457,458,459,],[15,-271,-67,-78,-77,-64,-60,-61,-35,-31,-65,-271,-37,-59,-74,-69,-36,-58,15,-62,-183,-116,-72,-271,-75,-271,-34,-79,-119,-70,-33,-66,-38,-68,-71,84,-271,-73,-271,-76,-80,-39,-63,-56,-9,-10,-90,-269,-89,98,-55,-118,-117,-32,-107,-106,-28,-127,-129,-27,-18,-50,-150,-81,-17,-84,-85,-152,-51,-54,-57,-271,-40,-120,98,98,98,-271,-100,-96,-271,-271,-256,-130,-128,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,-198,-262,-258,-184,-151,-83,-139,-150,-85,-41,-271,98,98,-91,-97,-270,-23,-88,-24,-87,-26,312,-101,313,-25,-103,-108,-126,-125,-82,-268,-225,-266,-242,-241,-155,-219,-224,-222,-157,-181,-223,-159,-153,-86,-42,-44,-47,375,-43,376,-45,379,-14,-271,-49,-161,-160,-48,386,-162,-13,-271,-46,-256,-93,-92,-105,-197,-98,-99,-110,-109,-121,-124,-185,-240,-239,-238,-237,-236,-249,-206,-218,-207,-205,-209,-213,-208,-204,-211,-216,-202,-201,-210,-217,-212,-214,-215,-203,-140,-154,-156,-158,410,-180,-179,411,-271,-177,-271,-13,-163,-176,-164,-271,-102,-104,-123,-122,-226,-234,-235,-182,-220,-141,-175,-178,427,-271,-167,-271,-165,-199,-271,440,-271,-166,-271,-271,-250,-243,448,-171,-170,-168,-244,455,-271,-271,-172,-169,-271,-174,-173,]),'LT':([116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,395,396,397,403,434,438,447,],[-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,251,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-206,251,-207,-205,-209,251,-208,-204,-211,251,-202,-201,-210,251,251,251,251,-203,-226,-234,-235,-220,-250,-243,-244,]),'COMMA':([1,2,3,5,6,9,10,13,14,17,18,19,22,24,26,27,28,29,30,33,34,36,38,40,41,43,44,45,46,47,51,52,53,54,56,58,60,61,62,64,65,69,70,71,72,73,76,77,81,82,83,85,86,93,97,100,104,105,106,113,114,115,116,117,118,119,120,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,155,157,158,160,170,172,178,180,181,182,183,184,186,188,191,192,193,194,195,201,202,203,204,205,206,209,222,224,225,226,228,232,235,236,238,239,240,242,243,244,269,273,274,275,289,305,307,308,309,310,315,316,317,318,319,320,323,325,326,328,329,330,331,332,333,334,335,336,339,342,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,368,371,372,373,377,391,392,393,394,395,396,397,402,403,409,415,417,420,421,424,425,426,434,438,443,446,447,],[-271,-67,-78,-77,-64,-60,-61,-65,-271,-59,-74,-69,-58,-62,-183,-116,-72,-271,-75,-79,-119,-70,-66,-68,-71,-271,-73,-271,-76,-80,-63,-56,-9,-10,-90,-89,-55,-118,-117,-107,-106,-28,-127,-129,-27,121,-150,-81,-84,-85,-152,-54,-57,-120,-271,-271,-111,194,-114,-133,-271,207,-256,208,-137,-130,-128,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,-198,-262,-258,-184,-151,-83,-139,-150,-85,-91,-270,-23,-88,-24,-87,311,-101,-103,194,194,-112,-108,-126,-125,-136,-1,-2,-135,-82,-268,-225,-266,-242,-241,-155,-219,-224,-222,-157,340,-181,-271,-223,367,-159,-153,-86,340,-256,-93,-92,-105,-197,-110,-109,-113,-115,-121,-124,-138,-134,-185,-240,-239,-238,-237,340,-254,-236,398,399,-249,-149,-150,-206,-218,-207,-205,-209,-213,-208,-204,-211,-216,-202,-201,-210,-217,-212,-214,340,-215,-203,-140,-142,-154,-156,-158,340,-102,-104,-123,-122,-226,-234,-235,-182,-220,-141,340,340,340,-255,437,-199,-143,-250,-243,340,340,-244,]),'OFFSETOF':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,119,123,131,132,138,139,141,143,145,146,148,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,314,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,398,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,436,437,440,441,442,444,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,137,137,-51,-40,137,-28,-271,-130,-232,137,-230,137,-229,137,-228,137,137,-227,-231,-271,-228,137,137,137,-270,137,137,-228,137,137,-189,-192,-190,-186,-187,-191,-193,137,-195,-196,-188,-194,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,-12,137,137,-11,-228,-44,-47,-43,137,-45,137,137,-49,-161,-160,-48,-162,137,-46,137,137,137,-271,-144,-180,-179,137,-177,137,137,-163,137,-176,-164,137,137,137,137,-271,137,137,-11,-175,-178,137,-167,137,-165,137,137,-166,137,137,137,137,-271,137,-171,-170,-168,137,137,137,-172,-169,137,-174,-173,]),'TYPEDEF':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,61,62,63,64,65,68,80,82,84,89,91,92,93,169,171,173,174,175,178,180,195,201,202,208,276,280,281,284,286,293,295,296,297,298,300,303,307,308,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[24,24,-67,-78,-77,-64,-60,-61,-35,-31,-65,24,-37,-59,-74,-69,-36,-58,24,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,24,-73,24,-76,-80,24,-39,-63,-90,-269,-89,-118,-117,-32,-107,-106,24,24,24,-51,-52,24,-40,-120,24,24,-41,24,-53,-91,-270,-108,-126,-125,24,-42,-44,-47,-43,-45,24,-49,-161,-160,-48,-162,-46,-93,-92,-110,-109,-121,-124,24,-180,-179,24,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'XOR':([116,122,124,125,126,127,128,129,130,133,134,136,142,144,147,149,150,151,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,395,396,397,403,434,438,447,],[-256,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,-200,-259,-233,-265,-257,-245,254,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-206,254,-207,-205,-209,-213,-208,-204,-211,-216,-202,-201,-210,254,-212,-214,254,-203,-226,-234,-235,-220,-250,-243,-244,]),'AUTO':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,61,62,63,64,65,68,80,82,84,89,91,92,93,169,171,173,174,175,178,180,195,201,202,208,276,280,281,284,286,293,295,296,297,298,300,303,307,308,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[22,22,-67,-78,-77,-64,-60,-61,-35,-31,-65,22,-37,-59,-74,-69,-36,-58,22,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,22,-73,22,-76,-80,22,-39,-63,-90,-269,-89,-118,-117,-32,-107,-106,22,22,22,-51,-52,22,-40,-120,22,22,-41,22,-53,-91,-270,-108,-126,-125,22,-42,-44,-47,-43,-45,22,-49,-161,-160,-48,-162,-46,-93,-92,-110,-109,-121,-124,22,-180,-179,22,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'TIMES':([0,1,2,3,4,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,28,29,30,31,32,33,36,37,38,39,40,41,43,44,45,46,47,50,51,52,53,54,56,57,58,60,63,64,65,67,69,70,71,72,74,79,80,84,85,86,88,92,97,100,101,107,108,109,114,116,119,121,122,123,124,125,126,127,128,129,130,131,132,133,134,136,138,139,141,142,143,144,145,146,147,148,149,150,151,152,153,156,159,161,166,168,171,173,174,178,180,181,182,183,184,185,195,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,228,230,231,234,235,236,237,238,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,276,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,305,307,308,311,314,315,316,328,329,330,331,334,339,340,341,343,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,367,370,375,376,378,379,380,381,384,385,386,388,389,390,395,396,397,398,400,403,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,434,436,437,438,440,441,442,444,447,448,451,454,455,456,457,458,459,],[29,-271,-67,-78,29,-77,-64,-60,-61,-35,-31,-65,-271,-37,-59,-74,-69,-36,-58,29,-62,-183,-72,-271,-75,29,-34,-79,-70,-33,-66,-38,-68,-71,-271,-73,-271,-76,-80,-39,-63,-56,-9,-10,-90,-269,-89,-55,-32,-107,-106,-271,-28,29,-129,-27,143,161,29,-51,-54,-57,29,-40,-271,-271,29,198,-28,-271,29,-256,-130,29,-260,-232,-219,-248,-263,-267,-264,-261,-246,161,-230,-247,-221,-200,161,-229,161,-259,-228,-233,161,161,-265,-227,-257,-245,256,-262,-258,-231,-271,-228,161,278,29,-41,161,-91,-270,-23,-88,-24,-87,161,-108,161,-228,161,161,-189,-192,-190,-186,-187,-191,-193,161,-195,-196,-188,-194,-268,161,-225,-266,-242,-241,161,161,161,-219,-224,161,-222,29,-223,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,-12,161,161,-11,-42,-228,-44,-47,-43,161,-45,161,161,-49,-161,-160,-48,-162,161,-46,-256,-93,-92,29,161,-110,-109,-240,-239,-238,-237,-236,-249,161,161,29,256,256,256,256,256,256,256,256,256,256,-202,-201,256,256,256,256,256,-203,-271,-144,-180,-179,161,-177,161,161,-163,161,-176,-164,161,161,-226,-234,-235,161,161,-220,-271,161,161,-11,-175,-178,161,-167,161,-165,161,161,-166,161,161,161,-250,161,-271,-243,161,-171,-170,-168,-244,161,161,161,-172,-169,161,-174,-173,]),'LPAREN':([0,1,2,3,4,5,6,9,10,11,12,13,14,15,16,17,18,19,21,22,23,24,26,27,28,29,30,31,32,33,34,36,37,38,39,40,41,43,44,45,46,47,50,51,52,53,54,56,57,58,60,62,63,64,65,67,69,70,71,72,74,76,79,80,83,84,85,86,88,92,93,97,100,101,107,108,109,114,116,119,120,121,122,123,125,126,127,128,129,130,131,132,133,134,137,138,139,141,142,143,144,145,146,147,148,149,150,152,153,156,157,159,161,166,168,170,171,173,174,178,180,181,182,183,184,185,195,196,198,199,200,201,202,210,211,212,213,214,215,216,217,218,219,220,221,222,223,225,226,228,230,231,232,234,237,239,243,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,273,274,276,278,280,281,284,285,286,287,291,292,293,294,295,296,297,298,300,302,303,305,306,307,308,311,314,315,316,319,320,328,329,330,331,334,339,340,341,343,344,367,370,371,372,373,375,376,378,379,380,381,384,385,386,388,389,390,393,394,396,397,398,400,404,405,407,408,410,411,413,414,416,418,419,427,429,430,431,432,433,434,436,437,438,440,441,442,444,447,448,451,454,455,456,457,458,459,],[4,-271,-67,-78,4,-77,-64,-60,-61,-35,-31,-65,-271,-37,4,-59,-74,-69,-36,-58,4,-62,-183,68,-72,-271,-75,80,-34,-79,-119,-70,-33,-66,-38,-68,-71,-271,-73,-271,-76,-80,-39,-63,-56,-9,-10,-90,-269,-89,-55,68,-32,-107,-106,-271,-28,-127,-129,-27,145,80,145,80,169,-51,-54,-57,171,-40,-120,-271,-271,171,145,-28,-271,80,-256,-130,-128,4,-260,-232,-248,-263,-267,-264,-261,-246,223,-230,-247,231,233,234,-229,237,-259,-228,-233,145,237,-265,-227,-257,-245,-262,-258,-231,169,-271,-228,145,145,171,171,-41,145,-91,-270,-23,-88,-24,-87,234,-108,234,-228,145,145,-126,-125,-189,-192,-190,-186,-187,-191,-193,145,-195,-196,-188,-194,-268,145,-266,-242,-241,145,145,-155,145,145,-157,343,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,145,234,234,-12,234,145,-11,-159,-153,-42,-228,-44,-47,-43,145,-45,378,381,234,145,385,-49,-161,-160,-48,-162,145,-46,-256,390,-93,-92,4,234,-110,-109,-121,-124,-240,-239,-238,-237,-236,-249,145,234,343,343,-271,-144,-154,-156,-158,-180,-179,145,-177,145,145,-163,145,-176,-164,145,145,-123,-122,-234,-235,145,234,-271,234,145,-11,-175,-178,145,-167,145,432,-165,145,145,-166,145,145,145,-250,145,-271,-243,145,-171,-170,-168,-244,145,145,145,-172,-169,145,-174,-173,]),'MINUSMINUS':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,116,119,122,123,125,126,127,128,129,130,131,132,133,134,138,139,141,142,143,144,145,146,147,148,149,150,152,153,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,222,223,225,226,228,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,305,314,328,329,330,331,334,339,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,396,397,398,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,434,436,437,438,440,441,442,444,447,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,146,146,-51,-40,146,-28,-271,-256,-130,-260,-232,-248,-263,-267,-264,-261,-246,146,-230,-247,226,146,-229,146,-259,-228,-233,146,146,-265,-227,-257,-245,-262,-258,-231,-271,-228,146,146,146,-270,146,146,-228,146,146,-189,-192,-190,-186,-187,-191,-193,146,-195,-196,-188,-194,-268,146,-266,-242,-241,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,-12,146,146,-11,-228,-44,-47,-43,146,-45,146,146,-49,-161,-160,-48,-162,146,-46,-256,146,-240,-239,-238,-237,-236,-249,146,146,-271,-144,-180,-179,146,-177,146,146,-163,146,-176,-164,146,146,-234,-235,146,146,-271,146,146,-11,-175,-178,146,-167,146,-165,146,146,-166,146,146,146,-250,146,-271,-243,146,-171,-170,-168,-244,146,146,146,-172,-169,146,-174,-173,]),'ID':([0,1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,28,29,30,31,32,33,35,36,37,38,39,40,41,43,44,45,46,47,50,51,52,53,54,56,57,58,60,63,64,65,66,67,68,69,70,71,72,74,76,79,80,84,85,86,88,92,97,100,101,102,103,107,108,109,114,119,120,121,123,131,132,138,139,141,143,145,146,148,156,159,161,166,168,170,171,173,174,178,180,181,182,183,184,185,194,195,196,198,199,200,207,210,211,212,213,214,215,216,217,218,219,220,221,223,227,229,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,267,268,270,272,276,278,280,281,282,284,285,286,292,293,295,296,297,298,300,302,303,307,308,311,314,315,316,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,398,399,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,435,436,437,440,441,442,444,448,451,454,455,456,457,458,459,],[34,-271,-67,-78,34,-77,-64,58,-60,-61,-35,-31,-65,-271,-37,34,-59,-74,-69,-95,-36,-58,34,-62,65,-183,-72,-271,-75,34,-34,-79,-94,-70,-33,-66,-38,-68,-71,-271,-73,-271,-76,-80,-39,-63,-56,-9,-10,-90,-269,-89,-55,-32,-107,-106,106,-271,116,-28,-127,-129,-27,116,34,116,34,-51,-54,-57,34,-40,-271,-271,34,106,106,116,-28,-271,34,-130,-128,34,-232,116,-230,116,-229,116,-228,116,116,-227,-231,-271,-228,116,116,34,34,-41,305,-91,-270,-23,-88,-24,-87,116,106,-108,116,-228,116,116,116,-189,-192,-190,-186,-187,-191,-193,116,-195,-196,-188,-194,116,329,331,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,-12,116,116,116,-11,-42,-228,-44,-47,374,-43,116,-45,116,305,-49,-161,-160,-48,-162,305,-46,-93,-92,34,116,-110,-109,116,116,-271,-144,-180,-179,116,-177,305,116,-163,116,-176,-164,305,116,116,116,116,-271,116,116,-11,-175,-178,116,-167,305,-165,116,305,-166,305,116,305,116,116,-271,116,-171,-170,-168,116,305,305,-172,-169,305,-174,-173,]),'IF':([50,57,84,92,174,180,280,281,284,286,293,295,296,297,298,300,302,303,375,376,379,380,384,386,388,389,410,411,414,416,419,429,430,431,433,441,442,444,451,454,455,456,457,458,459,],[-39,-269,-51,-40,306,-270,-44,-47,-43,-45,306,-49,-161,-160,-48,-162,306,-46,-180,-179,-177,306,-163,-176,-164,306,-175,-178,-167,306,-165,306,-166,306,306,-171,-170,-168,306,306,-172,-169,306,-174,-173,]),'STRING_LITERAL':([3,33,47,50,57,67,69,71,72,74,79,84,92,107,108,109,119,123,131,132,133,138,139,141,143,145,146,147,148,156,159,161,166,168,174,180,185,196,198,199,200,210,211,212,213,214,215,216,217,218,219,220,221,223,225,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,268,270,272,278,280,281,284,285,286,292,293,295,296,297,298,300,302,303,314,340,341,367,370,375,376,378,379,380,381,384,385,386,388,389,390,398,400,404,405,407,408,410,411,413,414,416,419,427,429,430,431,432,433,436,437,440,441,442,444,448,451,454,455,456,457,458,459,],[-78,-79,-80,-39,-269,-271,-28,-129,-27,147,147,-51,-40,147,-28,-271,-130,-232,147,-230,225,147,-229,147,-228,147,147,-265,-227,-231,-271,-228,147,147,147,-270,147,147,-228,147,147,-189,-192,-190,-186,-187,-191,-193,147,-195,-196,-188,-194,147,-266,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,-12,147,147,-11,-228,-44,-47,-43,147,-45,147,147,-49,-161,-160,-48,-162,147,-46,147,147,147,-271,-144,-180,-179,147,-177,147,147,-163,147,-176,-164,147,147,147,147,-271,147,147,-11,-175,-178,147,-167,147,-165,147,147,-166,147,147,147,147,-271,147,-171,-170,-168,147,147,147,-172,-169,147,-174,-173,]),'FLOAT':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,24,26,27,28,30,32,33,34,36,37,38,39,40,41,43,44,45,46,47,49,50,51,56,57,58,59,61,62,63,64,65,68,80,82,84,89,91,92,93,94,95,96,97,98,99,100,145,169,171,173,174,175,176,177,178,179,180,195,201,202,208,223,233,234,237,276,280,281,284,286,293,295,296,297,298,300,303,307,308,312,313,315,316,319,320,343,375,376,378,379,384,386,388,393,394,410,411,414,419,430,441,442,444,455,456,458,459,],[36,36,-67,-78,-77,-64,-60,-61,-35,-31,-65,36,-37,-59,-74,-69,-36,-58,36,-62,-183,-116,-72,-75,-34,-79,-119,-70,-33,-66,-38,-68,-71,36,-73,36,-76,-80,36,-39,-63,-90,-269,-89,36,-118,-117,-32,-107,-106,36,36,36,-51,-52,36,-40,-120,36,36,36,36,-100,-96,36,36,36,36,-41,36,-53,36,36,-91,-97,-270,-108,-126,-125,36,36,36,36,36,-42,-44,-47,-43,-45,36,-49,-161,-160,-48,-162,-46,-93,-92,-98,-99,-110,-109,-121,-124,36,-180,-179,36,-177,-163,-176,-164,-123,-122,-175,-178,-167,-165,-166,-171,-170,-168,-172,-169,-174,-173,]),'XOREQUAL':([116,122,124,125,126,127,128,129,130,133,134,142,144,147,149,150,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,395,396,397,403,434,438,447,],[-256,-260,214,-248,-263,-267,-264,-261,-246,-247,-221,-259,-233,-265,-257,-245,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-226,-234,-235,-220,-250,-243,-244,]),'LSHIFTEQUAL':([116,122,124,125,126,127,128,129,130,133,134,142,144,147,149,150,152,153,180,222,224,225,226,228,235,236,238,244,305,328,329,330,331,334,339,395,396,397,403,434,438,447,],[-256,-260,216,-248,-263,-267,-264,-261,-246,-247,-221,-259,-233,-265,-257,-245,-262,-258,-270,-268,-225,-266,-242,-241,-219,-224,-222,-223,-256,-240,-239,-238,-237,-236,-249,-226,-234,-235,-220,-250,-243,-244,]),'RBRACKET':([3,33,47,67,71,72,74,107,108,116,119,122,124,125,126,127,128,129,130,133,134,135,136,140,142,143,144,147,149,150,151,152,153,154,155,168,180,197,198,222,224,225,226,228,235,236,238,242,244,277,278,310,321,322,326,328,329,330,331,332,334,339,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,362,363,366,395,396,397,402,403,425,434,438,446,447,],[-78,-79,-80,-271,-129,-27,-271,-271,-28,-256,-130,-260,-219,-248,-263,-267,-264,-261,-246,-247,-221,232,-200,-4,-259,239,-233,-265,-257,-245,-198,-262,-258,-3,-184,-271,-270,319,320,-268,-225,-266,-242,-241,-219,-224,-222,-181,-223,371,372,-197,393,394,-185,-240,-239,-238,-237,396,-236,-249,-206,-218,-207,-205,-209,-213,-208,-204,-211,-216,-202,-201,-210,-217,-212,-214,-215,-203,406,-226,-234,-235,-182,-220,-199,-250,-243,452,-244,]),}
_lr_action = {}
for _k, _v in _lr_action_items.items():
for _x,_y in zip(_v[0],_v[1]):
if not _x in _lr_action: _lr_action[_x] = {}
_lr_action[_x][_k] = _y
del _lr_action_items
_lr_goto_items = {'expression_statement':([174,293,302,380,389,416,429,431,433,451,454,457,],[280,280,280,280,280,280,280,280,280,280,280,280,]),'struct_or_union_specifier':([0,1,14,23,43,45,49,59,68,80,82,91,94,95,96,97,100,145,169,171,174,176,177,208,223,233,234,237,293,343,378,],[5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,]),'init_declarator_list':([31,88,],[73,73,]),'init_declarator_list_opt':([31,88,],[75,75,]),'iteration_statement':([174,293,302,380,389,416,429,431,433,451,454,457,],[281,281,281,281,281,281,281,281,281,281,281,281,]),'unified_string_literal':([74,79,107,131,138,141,145,146,166,168,174,185,196,199,200,217,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,268,270,285,292,293,302,314,340,341,378,380,381,385,389,390,398,400,405,407,413,416,427,429,431,432,433,436,440,448,451,454,457,],[133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,]),'assignment_expression_opt':([74,107,168,],[135,197,277,]),'brace_open':([7,25,56,58,64,65,79,90,166,167,174,270,293,302,341,380,389,395,400,401,407,416,429,431,433,451,454,457,],[59,66,94,95,102,103,159,174,159,174,174,159,174,174,404,174,174,404,404,404,159,174,174,174,174,174,174,174,]),'enumerator':([66,102,103,194,],[104,104,104,317,]),'type_qualifier_list_opt':([29,67,109,],[70,107,200,]),'expression_opt':([174,293,302,378,380,389,413,416,427,429,431,433,440,448,451,454,457,],[283,283,283,412,283,283,428,283,439,283,283,283,449,453,283,283,283,]),'parameter_list':([68,80,169,171,343,],[117,117,117,117,117,]),'designation':([159,367,404,437,],[264,264,264,264,]),'labeled_statement':([174,293,302,380,389,416,429,431,433,451,454,457,],[284,284,284,284,284,284,284,284,284,284,284,284,]),'abstract_declarator':([31,80,88,101,114,171,243,343,],[81,165,81,189,205,165,205,165,]),'init_declarator':([31,88,121,],[77,77,209,]),'direct_abstract_declarator':([31,76,80,88,101,114,170,171,243,343,344,],[83,157,83,83,83,83,157,83,83,83,157,]),'designator_list':([159,367,404,437,],[271,271,271,271,]),'identifier':([68,74,79,107,131,138,141,145,146,166,168,174,185,196,199,200,207,217,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,267,268,270,285,292,293,302,314,340,341,378,380,381,385,389,390,398,399,400,405,407,413,416,427,429,431,432,433,435,436,440,448,451,454,457,],[118,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,323,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,365,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,423,150,150,150,150,150,150,150,150,150,150,445,150,150,150,150,150,150,]),'offsetof_member_designator':([399,],[422,]),'unary_expression':([74,79,107,131,138,141,145,146,166,168,174,185,196,199,200,217,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,268,270,285,292,293,302,314,340,341,378,380,381,385,389,390,398,400,405,407,413,416,427,429,431,432,433,436,440,448,451,454,457,],[124,124,124,224,235,238,124,244,124,124,124,235,235,124,124,124,124,124,124,124,124,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,124,235,235,235,124,124,235,124,124,235,124,235,124,124,124,124,124,124,124,235,235,124,124,124,124,124,124,124,124,124,124,124,124,124,124,]),'abstract_declarator_opt':([114,243,],[203,342,]),'initializer':([79,166,270,407,],[158,275,368,426,]),'struct_declaration_list':([59,94,95,],[96,176,177,]),'pp_directive':([0,23,],[11,11,]),'declaration_list':([49,82,],[91,91,]),'type_specifier':([0,1,14,23,43,45,49,59,68,80,82,91,94,95,96,97,100,145,169,171,174,176,177,208,223,233,234,237,293,343,378,],[14,14,14,14,14,14,14,97,14,14,14,14,97,97,97,97,97,97,14,14,14,97,97,14,97,97,97,97,14,14,14,]),'compound_statement':([90,167,174,293,302,380,389,416,429,431,433,451,454,457,],[173,276,286,286,286,286,286,286,286,286,286,286,286,286,]),'pointer':([0,4,23,31,70,80,88,101,114,121,171,243,311,343,],[16,16,16,76,120,76,170,170,76,16,170,344,16,344,]),'translation_unit':([0,],[23,]),'direct_declarator':([0,4,16,23,31,76,80,88,101,114,121,170,171,311,],[27,27,62,27,27,62,27,27,27,27,27,62,27,27,]),'initializer_list':([159,404,],[269,424,]),'argument_expression_list':([231,],[335,]),'specifier_qualifier_list_opt':([97,100,],[182,184,]),'declarator':([0,4,23,31,80,88,101,114,121,171,311,],[49,55,49,82,55,172,191,206,172,55,191,]),'typedef_name':([0,1,14,23,43,45,49,59,68,80,82,91,94,95,96,97,100,145,169,171,174,176,177,208,223,233,234,237,293,343,378,],[30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,]),'parameter_type_list_opt':([80,169,171,343,],[164,279,164,164,]),'struct_declarator':([101,311,],[188,391,]),'type_qualifier':([0,1,14,23,29,43,45,49,59,67,68,69,80,82,91,94,95,96,97,100,108,109,145,169,171,174,176,177,208,223,233,234,237,293,343,378,],[43,43,43,43,71,43,43,43,100,71,43,119,43,43,43,100,100,100,100,100,119,71,100,43,43,43,100,100,43,100,100,100,100,43,43,43,]),'struct_declarator_list_opt':([101,],[187,]),'assignment_operator':([124,],[217,]),'expression':([145,174,223,230,234,237,261,285,293,302,378,380,381,385,389,390,413,416,427,429,431,432,433,436,440,448,451,454,457,],[240,289,240,332,240,240,361,377,289,289,289,289,415,417,289,420,289,289,289,289,289,443,289,446,289,289,289,289,289,]),'storage_class_specifier':([0,1,14,23,43,45,49,68,80,82,91,169,171,174,208,293,343,378,],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,]),'unified_wstring_literal':([74,79,107,131,138,141,145,146,166,168,174,185,196,199,200,217,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,268,270,285,292,293,302,314,340,341,378,380,381,385,389,390,398,400,405,407,413,416,427,429,431,432,433,436,440,448,451,454,457,],[125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,]),'translation_unit_or_empty':([0,],[8,]),'initializer_list_opt':([159,],[265,]),'brace_close':([96,105,176,177,192,193,265,304,367,424,437,],[178,195,307,308,315,316,364,388,409,438,447,]),'declaration_specifiers_opt':([1,14,43,45,],[52,60,85,86,]),'external_declaration':([0,23,],[12,63,]),'type_name':([145,223,233,234,237,],[241,327,336,337,338,]),'block_item_list':([174,],[293,]),'pppragma_directive':([0,23,174,293,302,380,389,416,429,431,433,451,454,457,],[21,21,295,295,295,295,295,295,295,295,295,295,295,295,]),'statement':([174,293,302,380,389,416,429,431,433,451,454,457,],[296,296,387,414,419,430,441,442,444,456,458,459,]),'cast_expression':([74,79,107,138,145,166,168,174,185,196,199,200,217,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,268,270,285,292,293,302,314,340,341,378,380,381,385,389,390,398,400,405,407,413,416,427,429,431,432,433,436,440,448,451,454,457,],[136,136,136,236,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,403,136,136,136,136,136,136,136,403,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,]),'struct_declarator_list':([101,],[186,]),'constant_expression':([185,196,268,292,314,],[309,318,366,382,392,]),'parameter_declaration':([68,80,169,171,208,343,],[113,113,113,113,325,113,]),'primary_expression':([74,79,107,131,138,141,145,146,166,168,174,185,196,199,200,217,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,268,270,285,292,293,302,314,340,341,378,380,381,385,389,390,398,400,405,407,413,416,427,429,431,432,433,436,440,448,451,454,457,],[144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,]),'declaration':([0,23,49,82,91,174,293,378,],[32,32,89,89,175,297,297,413,]),'jump_statement':([174,293,302,380,389,416,429,431,433,451,454,457,],[298,298,298,298,298,298,298,298,298,298,298,298,]),'enumerator_list':([66,102,103,],[105,192,193,]),'block_item':([174,293,],[300,384,]),'empty':([0,1,14,29,31,43,45,49,67,68,74,80,82,88,97,100,101,107,109,114,159,168,169,171,174,243,293,302,343,367,378,380,389,404,413,416,427,429,431,433,437,440,448,451,454,457,],[48,53,53,72,78,53,53,87,72,111,154,162,87,78,181,181,190,154,72,204,272,154,162,162,301,204,383,383,162,408,383,383,383,408,383,383,383,383,383,383,408,383,383,383,383,383,]),'identifier_list_opt':([68,],[110,]),'constant':([74,79,107,131,138,141,145,146,166,168,174,185,196,199,200,217,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,268,270,285,292,293,302,314,340,341,378,380,381,385,389,390,398,400,405,407,413,416,427,429,431,432,433,436,440,448,451,454,457,],[130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,]),'struct_declaration':([59,94,95,96,176,177,],[99,99,99,179,179,179,]),'selection_statement':([174,293,302,380,389,416,429,431,433,451,454,457,],[303,303,303,303,303,303,303,303,303,303,303,303,]),'postfix_expression':([74,79,107,131,138,141,145,146,166,168,174,185,196,199,200,217,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,268,270,285,292,293,302,314,340,341,378,380,381,385,389,390,398,400,405,407,413,416,427,429,431,432,433,436,440,448,451,454,457,],[134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,]),'unary_operator':([74,79,107,131,138,141,145,146,166,168,174,185,196,199,200,217,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,268,270,285,292,293,302,314,340,341,378,380,381,385,389,390,398,400,405,407,413,416,427,429,431,432,433,436,440,448,451,454,457,],[138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,]),'struct_or_union':([0,1,14,23,43,45,49,59,68,80,82,91,94,95,96,97,100,145,169,171,174,176,177,208,223,233,234,237,293,343,378,],[7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,]),'block_item_list_opt':([174,],[304,]),'assignment_expression':([74,79,107,145,166,168,174,199,200,217,223,230,231,234,237,261,270,285,293,302,340,378,380,381,385,389,390,398,407,413,416,427,429,431,432,433,436,440,448,451,454,457,],[140,160,140,242,160,140,242,321,322,326,242,242,333,242,242,242,160,242,242,242,402,242,242,242,242,242,242,421,160,242,242,242,242,242,242,242,242,242,242,242,242,242,]),'designation_opt':([159,367,404,437,],[270,407,270,407,]),'parameter_type_list':([68,80,169,171,343,],[112,163,163,163,163,]),'type_qualifier_list':([29,67,109,],[69,108,69,]),'designator':([159,271,367,404,437,],[266,369,266,266,266,]),'declaration_specifiers':([0,1,14,23,43,45,49,68,80,82,91,169,171,174,208,293,343,378,],[31,54,54,31,54,54,88,114,114,88,88,114,114,88,114,88,114,88,]),'identifier_list':([68,],[115,]),'declaration_list_opt':([49,82,],[90,167,]),'function_definition':([0,23,],[37,37,]),'binary_expression':([74,79,107,145,166,168,174,185,196,199,200,217,223,230,231,234,237,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,268,270,285,292,293,302,314,340,378,380,381,385,389,390,398,405,407,413,416,427,429,431,432,433,436,440,448,451,454,457,],[151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,151,362,363,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,]),'enum_specifier':([0,1,14,23,43,45,49,59,68,80,82,91,94,95,96,97,100,145,169,171,174,176,177,208,223,233,234,237,293,343,378,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'decl_body':([0,23,49,82,91,174,293,378,],[42,42,42,42,42,42,42,42,]),'function_specifier':([0,1,14,23,43,45,49,68,80,82,91,169,171,174,208,293,343,378,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'specifier_qualifier_list':([59,94,95,96,97,100,145,176,177,223,233,234,237,],[101,101,101,101,183,183,243,101,101,243,243,243,243,]),'conditional_expression':([74,79,107,145,166,168,174,185,196,199,200,217,223,230,231,234,237,261,268,270,285,292,293,302,314,340,378,380,381,385,389,390,398,405,407,413,416,427,429,431,432,433,436,440,448,451,454,457,],[155,155,155,155,155,155,155,310,310,155,155,155,155,155,155,155,155,155,310,155,155,310,155,155,310,155,155,155,155,155,155,155,155,425,155,155,155,155,155,155,155,155,155,155,155,155,155,155,]),}
_lr_goto = {}
for _k, _v in _lr_goto_items.items():
for _x, _y in zip(_v[0], _v[1]):
if not _x in _lr_goto: _lr_goto[_x] = {}
_lr_goto[_x][_k] = _y
del _lr_goto_items
_lr_productions = [
("S' -> translation_unit_or_empty","S'",1,None,None,None),
('abstract_declarator_opt -> empty','abstract_declarator_opt',1,'p_abstract_declarator_opt','plyparser.py',42),
('abstract_declarator_opt -> abstract_declarator','abstract_declarator_opt',1,'p_abstract_declarator_opt','plyparser.py',43),
('assignment_expression_opt -> empty','assignment_expression_opt',1,'p_assignment_expression_opt','plyparser.py',42),
('assignment_expression_opt -> assignment_expression','assignment_expression_opt',1,'p_assignment_expression_opt','plyparser.py',43),
('block_item_list_opt -> empty','block_item_list_opt',1,'p_block_item_list_opt','plyparser.py',42),
('block_item_list_opt -> block_item_list','block_item_list_opt',1,'p_block_item_list_opt','plyparser.py',43),
('declaration_list_opt -> empty','declaration_list_opt',1,'p_declaration_list_opt','plyparser.py',42),
('declaration_list_opt -> declaration_list','declaration_list_opt',1,'p_declaration_list_opt','plyparser.py',43),
('declaration_specifiers_opt -> empty','declaration_specifiers_opt',1,'p_declaration_specifiers_opt','plyparser.py',42),
('declaration_specifiers_opt -> declaration_specifiers','declaration_specifiers_opt',1,'p_declaration_specifiers_opt','plyparser.py',43),
('designation_opt -> empty','designation_opt',1,'p_designation_opt','plyparser.py',42),
('designation_opt -> designation','designation_opt',1,'p_designation_opt','plyparser.py',43),
('expression_opt -> empty','expression_opt',1,'p_expression_opt','plyparser.py',42),
('expression_opt -> expression','expression_opt',1,'p_expression_opt','plyparser.py',43),
('identifier_list_opt -> empty','identifier_list_opt',1,'p_identifier_list_opt','plyparser.py',42),
('identifier_list_opt -> identifier_list','identifier_list_opt',1,'p_identifier_list_opt','plyparser.py',43),
('init_declarator_list_opt -> empty','init_declarator_list_opt',1,'p_init_declarator_list_opt','plyparser.py',42),
('init_declarator_list_opt -> init_declarator_list','init_declarator_list_opt',1,'p_init_declarator_list_opt','plyparser.py',43),
('initializer_list_opt -> empty','initializer_list_opt',1,'p_initializer_list_opt','plyparser.py',42),
('initializer_list_opt -> initializer_list','initializer_list_opt',1,'p_initializer_list_opt','plyparser.py',43),
('parameter_type_list_opt -> empty','parameter_type_list_opt',1,'p_parameter_type_list_opt','plyparser.py',42),
('parameter_type_list_opt -> parameter_type_list','parameter_type_list_opt',1,'p_parameter_type_list_opt','plyparser.py',43),
('specifier_qualifier_list_opt -> empty','specifier_qualifier_list_opt',1,'p_specifier_qualifier_list_opt','plyparser.py',42),
('specifier_qualifier_list_opt -> specifier_qualifier_list','specifier_qualifier_list_opt',1,'p_specifier_qualifier_list_opt','plyparser.py',43),
('struct_declarator_list_opt -> empty','struct_declarator_list_opt',1,'p_struct_declarator_list_opt','plyparser.py',42),
('struct_declarator_list_opt -> struct_declarator_list','struct_declarator_list_opt',1,'p_struct_declarator_list_opt','plyparser.py',43),
('type_qualifier_list_opt -> empty','type_qualifier_list_opt',1,'p_type_qualifier_list_opt','plyparser.py',42),
('type_qualifier_list_opt -> type_qualifier_list','type_qualifier_list_opt',1,'p_type_qualifier_list_opt','plyparser.py',43),
('translation_unit_or_empty -> translation_unit','translation_unit_or_empty',1,'p_translation_unit_or_empty','c_parser.py',506),
('translation_unit_or_empty -> empty','translation_unit_or_empty',1,'p_translation_unit_or_empty','c_parser.py',507),
('translation_unit -> external_declaration','translation_unit',1,'p_translation_unit_1','c_parser.py',515),
('translation_unit -> translation_unit external_declaration','translation_unit',2,'p_translation_unit_2','c_parser.py',522),
('external_declaration -> function_definition','external_declaration',1,'p_external_declaration_1','c_parser.py',534),
('external_declaration -> declaration','external_declaration',1,'p_external_declaration_2','c_parser.py',539),
('external_declaration -> pp_directive','external_declaration',1,'p_external_declaration_3','c_parser.py',544),
('external_declaration -> pppragma_directive','external_declaration',1,'p_external_declaration_3','c_parser.py',545),
('external_declaration -> SEMI','external_declaration',1,'p_external_declaration_4','c_parser.py',550),
('pp_directive -> PPHASH','pp_directive',1,'p_pp_directive','c_parser.py',555),
('pppragma_directive -> PPPRAGMA','pppragma_directive',1,'p_pppragma_directive','c_parser.py',561),
('pppragma_directive -> PPPRAGMA PPPRAGMASTR','pppragma_directive',2,'p_pppragma_directive','c_parser.py',562),
('function_definition -> declarator declaration_list_opt compound_statement','function_definition',3,'p_function_definition_1','c_parser.py',573),
('function_definition -> declaration_specifiers declarator declaration_list_opt compound_statement','function_definition',4,'p_function_definition_2','c_parser.py',590),
('statement -> labeled_statement','statement',1,'p_statement','c_parser.py',601),
('statement -> expression_statement','statement',1,'p_statement','c_parser.py',602),
('statement -> compound_statement','statement',1,'p_statement','c_parser.py',603),
('statement -> selection_statement','statement',1,'p_statement','c_parser.py',604),
('statement -> iteration_statement','statement',1,'p_statement','c_parser.py',605),
('statement -> jump_statement','statement',1,'p_statement','c_parser.py',606),
('statement -> pppragma_directive','statement',1,'p_statement','c_parser.py',607),
('decl_body -> declaration_specifiers init_declarator_list_opt','decl_body',2,'p_decl_body','c_parser.py',621),
('declaration -> decl_body SEMI','declaration',2,'p_declaration','c_parser.py',680),
('declaration_list -> declaration','declaration_list',1,'p_declaration_list','c_parser.py',689),
('declaration_list -> declaration_list declaration','declaration_list',2,'p_declaration_list','c_parser.py',690),
('declaration_specifiers -> type_qualifier declaration_specifiers_opt','declaration_specifiers',2,'p_declaration_specifiers_1','c_parser.py',695),
('declaration_specifiers -> type_specifier declaration_specifiers_opt','declaration_specifiers',2,'p_declaration_specifiers_2','c_parser.py',700),
('declaration_specifiers -> storage_class_specifier declaration_specifiers_opt','declaration_specifiers',2,'p_declaration_specifiers_3','c_parser.py',705),
('declaration_specifiers -> function_specifier declaration_specifiers_opt','declaration_specifiers',2,'p_declaration_specifiers_4','c_parser.py',710),
('storage_class_specifier -> AUTO','storage_class_specifier',1,'p_storage_class_specifier','c_parser.py',715),
('storage_class_specifier -> REGISTER','storage_class_specifier',1,'p_storage_class_specifier','c_parser.py',716),
('storage_class_specifier -> STATIC','storage_class_specifier',1,'p_storage_class_specifier','c_parser.py',717),
('storage_class_specifier -> EXTERN','storage_class_specifier',1,'p_storage_class_specifier','c_parser.py',718),
('storage_class_specifier -> TYPEDEF','storage_class_specifier',1,'p_storage_class_specifier','c_parser.py',719),
('function_specifier -> INLINE','function_specifier',1,'p_function_specifier','c_parser.py',724),
('type_specifier -> VOID','type_specifier',1,'p_type_specifier_1','c_parser.py',729),
('type_specifier -> _BOOL','type_specifier',1,'p_type_specifier_1','c_parser.py',730),
('type_specifier -> CHAR','type_specifier',1,'p_type_specifier_1','c_parser.py',731),
('type_specifier -> SHORT','type_specifier',1,'p_type_specifier_1','c_parser.py',732),
('type_specifier -> INT','type_specifier',1,'p_type_specifier_1','c_parser.py',733),
('type_specifier -> LONG','type_specifier',1,'p_type_specifier_1','c_parser.py',734),
('type_specifier -> FLOAT','type_specifier',1,'p_type_specifier_1','c_parser.py',735),
('type_specifier -> DOUBLE','type_specifier',1,'p_type_specifier_1','c_parser.py',736),
('type_specifier -> _COMPLEX','type_specifier',1,'p_type_specifier_1','c_parser.py',737),
('type_specifier -> SIGNED','type_specifier',1,'p_type_specifier_1','c_parser.py',738),
('type_specifier -> UNSIGNED','type_specifier',1,'p_type_specifier_1','c_parser.py',739),
('type_specifier -> typedef_name','type_specifier',1,'p_type_specifier_2','c_parser.py',744),
('type_specifier -> enum_specifier','type_specifier',1,'p_type_specifier_2','c_parser.py',745),
('type_specifier -> struct_or_union_specifier','type_specifier',1,'p_type_specifier_2','c_parser.py',746),
('type_qualifier -> CONST','type_qualifier',1,'p_type_qualifier','c_parser.py',751),
('type_qualifier -> RESTRICT','type_qualifier',1,'p_type_qualifier','c_parser.py',752),
('type_qualifier -> VOLATILE','type_qualifier',1,'p_type_qualifier','c_parser.py',753),
('init_declarator_list -> init_declarator','init_declarator_list',1,'p_init_declarator_list_1','c_parser.py',758),
('init_declarator_list -> init_declarator_list COMMA init_declarator','init_declarator_list',3,'p_init_declarator_list_1','c_parser.py',759),
('init_declarator_list -> EQUALS initializer','init_declarator_list',2,'p_init_declarator_list_2','c_parser.py',769),
('init_declarator_list -> abstract_declarator','init_declarator_list',1,'p_init_declarator_list_3','c_parser.py',777),
('init_declarator -> declarator','init_declarator',1,'p_init_declarator','c_parser.py',785),
('init_declarator -> declarator EQUALS initializer','init_declarator',3,'p_init_declarator','c_parser.py',786),
('specifier_qualifier_list -> type_qualifier specifier_qualifier_list_opt','specifier_qualifier_list',2,'p_specifier_qualifier_list_1','c_parser.py',791),
('specifier_qualifier_list -> type_specifier specifier_qualifier_list_opt','specifier_qualifier_list',2,'p_specifier_qualifier_list_2','c_parser.py',796),
('struct_or_union_specifier -> struct_or_union ID','struct_or_union_specifier',2,'p_struct_or_union_specifier_1','c_parser.py',804),
('struct_or_union_specifier -> struct_or_union TYPEID','struct_or_union_specifier',2,'p_struct_or_union_specifier_1','c_parser.py',805),
('struct_or_union_specifier -> struct_or_union brace_open struct_declaration_list brace_close','struct_or_union_specifier',4,'p_struct_or_union_specifier_2','c_parser.py',814),
('struct_or_union_specifier -> struct_or_union ID brace_open struct_declaration_list brace_close','struct_or_union_specifier',5,'p_struct_or_union_specifier_3','c_parser.py',823),
('struct_or_union_specifier -> struct_or_union TYPEID brace_open struct_declaration_list brace_close','struct_or_union_specifier',5,'p_struct_or_union_specifier_3','c_parser.py',824),
('struct_or_union -> STRUCT','struct_or_union',1,'p_struct_or_union','c_parser.py',833),
('struct_or_union -> UNION','struct_or_union',1,'p_struct_or_union','c_parser.py',834),
('struct_declaration_list -> struct_declaration','struct_declaration_list',1,'p_struct_declaration_list','c_parser.py',841),
('struct_declaration_list -> struct_declaration_list struct_declaration','struct_declaration_list',2,'p_struct_declaration_list','c_parser.py',842),
('struct_declaration -> specifier_qualifier_list struct_declarator_list_opt SEMI','struct_declaration',3,'p_struct_declaration_1','c_parser.py',850),
('struct_declaration -> specifier_qualifier_list abstract_declarator SEMI','struct_declaration',3,'p_struct_declaration_2','c_parser.py',888),
('struct_declaration -> SEMI','struct_declaration',1,'p_struct_declaration_3','c_parser.py',902),
('struct_declarator_list -> struct_declarator','struct_declarator_list',1,'p_struct_declarator_list','c_parser.py',907),
('struct_declarator_list -> struct_declarator_list COMMA struct_declarator','struct_declarator_list',3,'p_struct_declarator_list','c_parser.py',908),
('struct_declarator -> declarator','struct_declarator',1,'p_struct_declarator_1','c_parser.py',916),
('struct_declarator -> declarator COLON constant_expression','struct_declarator',3,'p_struct_declarator_2','c_parser.py',921),
('struct_declarator -> COLON constant_expression','struct_declarator',2,'p_struct_declarator_2','c_parser.py',922),
('enum_specifier -> ENUM ID','enum_specifier',2,'p_enum_specifier_1','c_parser.py',930),
('enum_specifier -> ENUM TYPEID','enum_specifier',2,'p_enum_specifier_1','c_parser.py',931),
('enum_specifier -> ENUM brace_open enumerator_list brace_close','enum_specifier',4,'p_enum_specifier_2','c_parser.py',936),
('enum_specifier -> ENUM ID brace_open enumerator_list brace_close','enum_specifier',5,'p_enum_specifier_3','c_parser.py',941),
('enum_specifier -> ENUM TYPEID brace_open enumerator_list brace_close','enum_specifier',5,'p_enum_specifier_3','c_parser.py',942),
('enumerator_list -> enumerator','enumerator_list',1,'p_enumerator_list','c_parser.py',947),
('enumerator_list -> enumerator_list COMMA','enumerator_list',2,'p_enumerator_list','c_parser.py',948),
('enumerator_list -> enumerator_list COMMA enumerator','enumerator_list',3,'p_enumerator_list','c_parser.py',949),
('enumerator -> ID','enumerator',1,'p_enumerator','c_parser.py',960),
('enumerator -> ID EQUALS constant_expression','enumerator',3,'p_enumerator','c_parser.py',961),
('declarator -> direct_declarator','declarator',1,'p_declarator_1','c_parser.py',976),
('declarator -> pointer direct_declarator','declarator',2,'p_declarator_2','c_parser.py',981),
('declarator -> pointer TYPEID','declarator',2,'p_declarator_3','c_parser.py',990),
('direct_declarator -> ID','direct_declarator',1,'p_direct_declarator_1','c_parser.py',1001),
('direct_declarator -> LPAREN declarator RPAREN','direct_declarator',3,'p_direct_declarator_2','c_parser.py',1010),
('direct_declarator -> direct_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET','direct_declarator',5,'p_direct_declarator_3','c_parser.py',1015),
('direct_declarator -> direct_declarator LBRACKET STATIC type_qualifier_list_opt assignment_expression RBRACKET','direct_declarator',6,'p_direct_declarator_4','c_parser.py',1029),
('direct_declarator -> direct_declarator LBRACKET type_qualifier_list STATIC assignment_expression RBRACKET','direct_declarator',6,'p_direct_declarator_4','c_parser.py',1030),
('direct_declarator -> direct_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET','direct_declarator',5,'p_direct_declarator_5','c_parser.py',1050),
('direct_declarator -> direct_declarator LPAREN parameter_type_list RPAREN','direct_declarator',4,'p_direct_declarator_6','c_parser.py',1061),
('direct_declarator -> direct_declarator LPAREN identifier_list_opt RPAREN','direct_declarator',4,'p_direct_declarator_6','c_parser.py',1062),
('pointer -> TIMES type_qualifier_list_opt','pointer',2,'p_pointer','c_parser.py',1089),
('pointer -> TIMES type_qualifier_list_opt pointer','pointer',3,'p_pointer','c_parser.py',1090),
('type_qualifier_list -> type_qualifier','type_qualifier_list',1,'p_type_qualifier_list','c_parser.py',1119),
('type_qualifier_list -> type_qualifier_list type_qualifier','type_qualifier_list',2,'p_type_qualifier_list','c_parser.py',1120),
('parameter_type_list -> parameter_list','parameter_type_list',1,'p_parameter_type_list','c_parser.py',1125),
('parameter_type_list -> parameter_list COMMA ELLIPSIS','parameter_type_list',3,'p_parameter_type_list','c_parser.py',1126),
('parameter_list -> parameter_declaration','parameter_list',1,'p_parameter_list','c_parser.py',1134),
('parameter_list -> parameter_list COMMA parameter_declaration','parameter_list',3,'p_parameter_list','c_parser.py',1135),
('parameter_declaration -> declaration_specifiers declarator','parameter_declaration',2,'p_parameter_declaration_1','c_parser.py',1144),
('parameter_declaration -> declaration_specifiers abstract_declarator_opt','parameter_declaration',2,'p_parameter_declaration_2','c_parser.py',1155),
('identifier_list -> identifier','identifier_list',1,'p_identifier_list','c_parser.py',1186),
('identifier_list -> identifier_list COMMA identifier','identifier_list',3,'p_identifier_list','c_parser.py',1187),
('initializer -> assignment_expression','initializer',1,'p_initializer_1','c_parser.py',1196),
('initializer -> brace_open initializer_list_opt brace_close','initializer',3,'p_initializer_2','c_parser.py',1201),
('initializer -> brace_open initializer_list COMMA brace_close','initializer',4,'p_initializer_2','c_parser.py',1202),
('initializer_list -> designation_opt initializer','initializer_list',2,'p_initializer_list','c_parser.py',1210),
('initializer_list -> initializer_list COMMA designation_opt initializer','initializer_list',4,'p_initializer_list','c_parser.py',1211),
('designation -> designator_list EQUALS','designation',2,'p_designation','c_parser.py',1222),
('designator_list -> designator','designator_list',1,'p_designator_list','c_parser.py',1230),
('designator_list -> designator_list designator','designator_list',2,'p_designator_list','c_parser.py',1231),
('designator -> LBRACKET constant_expression RBRACKET','designator',3,'p_designator','c_parser.py',1236),
('designator -> PERIOD identifier','designator',2,'p_designator','c_parser.py',1237),
('type_name -> specifier_qualifier_list abstract_declarator_opt','type_name',2,'p_type_name','c_parser.py',1242),
('abstract_declarator -> pointer','abstract_declarator',1,'p_abstract_declarator_1','c_parser.py',1259),
('abstract_declarator -> pointer direct_abstract_declarator','abstract_declarator',2,'p_abstract_declarator_2','c_parser.py',1267),
('abstract_declarator -> direct_abstract_declarator','abstract_declarator',1,'p_abstract_declarator_3','c_parser.py',1272),
('direct_abstract_declarator -> LPAREN abstract_declarator RPAREN','direct_abstract_declarator',3,'p_direct_abstract_declarator_1','c_parser.py',1282),
('direct_abstract_declarator -> direct_abstract_declarator LBRACKET assignment_expression_opt RBRACKET','direct_abstract_declarator',4,'p_direct_abstract_declarator_2','c_parser.py',1286),
('direct_abstract_declarator -> LBRACKET assignment_expression_opt RBRACKET','direct_abstract_declarator',3,'p_direct_abstract_declarator_3','c_parser.py',1297),
('direct_abstract_declarator -> direct_abstract_declarator LBRACKET TIMES RBRACKET','direct_abstract_declarator',4,'p_direct_abstract_declarator_4','c_parser.py',1306),
('direct_abstract_declarator -> LBRACKET TIMES RBRACKET','direct_abstract_declarator',3,'p_direct_abstract_declarator_5','c_parser.py',1317),
('direct_abstract_declarator -> direct_abstract_declarator LPAREN parameter_type_list_opt RPAREN','direct_abstract_declarator',4,'p_direct_abstract_declarator_6','c_parser.py',1326),
('direct_abstract_declarator -> LPAREN parameter_type_list_opt RPAREN','direct_abstract_declarator',3,'p_direct_abstract_declarator_7','c_parser.py',1336),
('block_item -> declaration','block_item',1,'p_block_item','c_parser.py',1347),
('block_item -> statement','block_item',1,'p_block_item','c_parser.py',1348),
('block_item_list -> block_item','block_item_list',1,'p_block_item_list','c_parser.py',1355),
('block_item_list -> block_item_list block_item','block_item_list',2,'p_block_item_list','c_parser.py',1356),
('compound_statement -> brace_open block_item_list_opt brace_close','compound_statement',3,'p_compound_statement_1','c_parser.py',1362),
('labeled_statement -> ID COLON statement','labeled_statement',3,'p_labeled_statement_1','c_parser.py',1368),
('labeled_statement -> CASE constant_expression COLON statement','labeled_statement',4,'p_labeled_statement_2','c_parser.py',1372),
('labeled_statement -> DEFAULT COLON statement','labeled_statement',3,'p_labeled_statement_3','c_parser.py',1376),
('selection_statement -> IF LPAREN expression RPAREN statement','selection_statement',5,'p_selection_statement_1','c_parser.py',1380),
('selection_statement -> IF LPAREN expression RPAREN statement ELSE statement','selection_statement',7,'p_selection_statement_2','c_parser.py',1384),
('selection_statement -> SWITCH LPAREN expression RPAREN statement','selection_statement',5,'p_selection_statement_3','c_parser.py',1388),
('iteration_statement -> WHILE LPAREN expression RPAREN statement','iteration_statement',5,'p_iteration_statement_1','c_parser.py',1393),
('iteration_statement -> DO statement WHILE LPAREN expression RPAREN SEMI','iteration_statement',7,'p_iteration_statement_2','c_parser.py',1397),
('iteration_statement -> FOR LPAREN expression_opt SEMI expression_opt SEMI expression_opt RPAREN statement','iteration_statement',9,'p_iteration_statement_3','c_parser.py',1401),
('iteration_statement -> FOR LPAREN declaration expression_opt SEMI expression_opt RPAREN statement','iteration_statement',8,'p_iteration_statement_4','c_parser.py',1405),
('jump_statement -> GOTO ID SEMI','jump_statement',3,'p_jump_statement_1','c_parser.py',1410),
('jump_statement -> BREAK SEMI','jump_statement',2,'p_jump_statement_2','c_parser.py',1414),
('jump_statement -> CONTINUE SEMI','jump_statement',2,'p_jump_statement_3','c_parser.py',1418),
('jump_statement -> RETURN expression SEMI','jump_statement',3,'p_jump_statement_4','c_parser.py',1422),
('jump_statement -> RETURN SEMI','jump_statement',2,'p_jump_statement_4','c_parser.py',1423),
('expression_statement -> expression_opt SEMI','expression_statement',2,'p_expression_statement','c_parser.py',1428),
('expression -> assignment_expression','expression',1,'p_expression','c_parser.py',1435),
('expression -> expression COMMA assignment_expression','expression',3,'p_expression','c_parser.py',1436),
('typedef_name -> TYPEID','typedef_name',1,'p_typedef_name','c_parser.py',1448),
('assignment_expression -> conditional_expression','assignment_expression',1,'p_assignment_expression','c_parser.py',1452),
('assignment_expression -> unary_expression assignment_operator assignment_expression','assignment_expression',3,'p_assignment_expression','c_parser.py',1453),
('assignment_operator -> EQUALS','assignment_operator',1,'p_assignment_operator','c_parser.py',1466),
('assignment_operator -> XOREQUAL','assignment_operator',1,'p_assignment_operator','c_parser.py',1467),
('assignment_operator -> TIMESEQUAL','assignment_operator',1,'p_assignment_operator','c_parser.py',1468),
('assignment_operator -> DIVEQUAL','assignment_operator',1,'p_assignment_operator','c_parser.py',1469),
('assignment_operator -> MODEQUAL','assignment_operator',1,'p_assignment_operator','c_parser.py',1470),
('assignment_operator -> PLUSEQUAL','assignment_operator',1,'p_assignment_operator','c_parser.py',1471),
('assignment_operator -> MINUSEQUAL','assignment_operator',1,'p_assignment_operator','c_parser.py',1472),
('assignment_operator -> LSHIFTEQUAL','assignment_operator',1,'p_assignment_operator','c_parser.py',1473),
('assignment_operator -> RSHIFTEQUAL','assignment_operator',1,'p_assignment_operator','c_parser.py',1474),
('assignment_operator -> ANDEQUAL','assignment_operator',1,'p_assignment_operator','c_parser.py',1475),
('assignment_operator -> OREQUAL','assignment_operator',1,'p_assignment_operator','c_parser.py',1476),
('constant_expression -> conditional_expression','constant_expression',1,'p_constant_expression','c_parser.py',1481),
('conditional_expression -> binary_expression','conditional_expression',1,'p_conditional_expression','c_parser.py',1485),
('conditional_expression -> binary_expression CONDOP expression COLON conditional_expression','conditional_expression',5,'p_conditional_expression','c_parser.py',1486),
('binary_expression -> cast_expression','binary_expression',1,'p_binary_expression','c_parser.py',1494),
('binary_expression -> binary_expression TIMES binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1495),
('binary_expression -> binary_expression DIVIDE binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1496),
('binary_expression -> binary_expression MOD binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1497),
('binary_expression -> binary_expression PLUS binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1498),
('binary_expression -> binary_expression MINUS binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1499),
('binary_expression -> binary_expression RSHIFT binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1500),
('binary_expression -> binary_expression LSHIFT binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1501),
('binary_expression -> binary_expression LT binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1502),
('binary_expression -> binary_expression LE binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1503),
('binary_expression -> binary_expression GE binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1504),
('binary_expression -> binary_expression GT binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1505),
('binary_expression -> binary_expression EQ binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1506),
('binary_expression -> binary_expression NE binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1507),
('binary_expression -> binary_expression AND binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1508),
('binary_expression -> binary_expression OR binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1509),
('binary_expression -> binary_expression XOR binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1510),
('binary_expression -> binary_expression LAND binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1511),
('binary_expression -> binary_expression LOR binary_expression','binary_expression',3,'p_binary_expression','c_parser.py',1512),
('cast_expression -> unary_expression','cast_expression',1,'p_cast_expression_1','c_parser.py',1520),
('cast_expression -> LPAREN type_name RPAREN cast_expression','cast_expression',4,'p_cast_expression_2','c_parser.py',1524),
('unary_expression -> postfix_expression','unary_expression',1,'p_unary_expression_1','c_parser.py',1528),
('unary_expression -> PLUSPLUS unary_expression','unary_expression',2,'p_unary_expression_2','c_parser.py',1532),
('unary_expression -> MINUSMINUS unary_expression','unary_expression',2,'p_unary_expression_2','c_parser.py',1533),
('unary_expression -> unary_operator cast_expression','unary_expression',2,'p_unary_expression_2','c_parser.py',1534),
('unary_expression -> SIZEOF unary_expression','unary_expression',2,'p_unary_expression_3','c_parser.py',1539),
('unary_expression -> SIZEOF LPAREN type_name RPAREN','unary_expression',4,'p_unary_expression_3','c_parser.py',1540),
('unary_operator -> AND','unary_operator',1,'p_unary_operator','c_parser.py',1548),
('unary_operator -> TIMES','unary_operator',1,'p_unary_operator','c_parser.py',1549),
('unary_operator -> PLUS','unary_operator',1,'p_unary_operator','c_parser.py',1550),
('unary_operator -> MINUS','unary_operator',1,'p_unary_operator','c_parser.py',1551),
('unary_operator -> NOT','unary_operator',1,'p_unary_operator','c_parser.py',1552),
('unary_operator -> LNOT','unary_operator',1,'p_unary_operator','c_parser.py',1553),
('postfix_expression -> primary_expression','postfix_expression',1,'p_postfix_expression_1','c_parser.py',1558),
('postfix_expression -> postfix_expression LBRACKET expression RBRACKET','postfix_expression',4,'p_postfix_expression_2','c_parser.py',1562),
('postfix_expression -> postfix_expression LPAREN argument_expression_list RPAREN','postfix_expression',4,'p_postfix_expression_3','c_parser.py',1566),
('postfix_expression -> postfix_expression LPAREN RPAREN','postfix_expression',3,'p_postfix_expression_3','c_parser.py',1567),
('postfix_expression -> postfix_expression PERIOD ID','postfix_expression',3,'p_postfix_expression_4','c_parser.py',1572),
('postfix_expression -> postfix_expression PERIOD TYPEID','postfix_expression',3,'p_postfix_expression_4','c_parser.py',1573),
('postfix_expression -> postfix_expression ARROW ID','postfix_expression',3,'p_postfix_expression_4','c_parser.py',1574),
('postfix_expression -> postfix_expression ARROW TYPEID','postfix_expression',3,'p_postfix_expression_4','c_parser.py',1575),
('postfix_expression -> postfix_expression PLUSPLUS','postfix_expression',2,'p_postfix_expression_5','c_parser.py',1581),
('postfix_expression -> postfix_expression MINUSMINUS','postfix_expression',2,'p_postfix_expression_5','c_parser.py',1582),
('postfix_expression -> LPAREN type_name RPAREN brace_open initializer_list brace_close','postfix_expression',6,'p_postfix_expression_6','c_parser.py',1587),
('postfix_expression -> LPAREN type_name RPAREN brace_open initializer_list COMMA brace_close','postfix_expression',7,'p_postfix_expression_6','c_parser.py',1588),
('primary_expression -> identifier','primary_expression',1,'p_primary_expression_1','c_parser.py',1593),
('primary_expression -> constant','primary_expression',1,'p_primary_expression_2','c_parser.py',1597),
('primary_expression -> unified_string_literal','primary_expression',1,'p_primary_expression_3','c_parser.py',1601),
('primary_expression -> unified_wstring_literal','primary_expression',1,'p_primary_expression_3','c_parser.py',1602),
('primary_expression -> LPAREN expression RPAREN','primary_expression',3,'p_primary_expression_4','c_parser.py',1607),
('primary_expression -> OFFSETOF LPAREN type_name COMMA offsetof_member_designator RPAREN','primary_expression',6,'p_primary_expression_5','c_parser.py',1611),
('offsetof_member_designator -> identifier','offsetof_member_designator',1,'p_offsetof_member_designator','c_parser.py',1619),
('offsetof_member_designator -> offsetof_member_designator PERIOD identifier','offsetof_member_designator',3,'p_offsetof_member_designator','c_parser.py',1620),
('offsetof_member_designator -> offsetof_member_designator LBRACKET expression RBRACKET','offsetof_member_designator',4,'p_offsetof_member_designator','c_parser.py',1621),
('argument_expression_list -> assignment_expression','argument_expression_list',1,'p_argument_expression_list','c_parser.py',1634),
('argument_expression_list -> argument_expression_list COMMA assignment_expression','argument_expression_list',3,'p_argument_expression_list','c_parser.py',1635),
('identifier -> ID','identifier',1,'p_identifier','c_parser.py',1644),
('constant -> INT_CONST_DEC','constant',1,'p_constant_1','c_parser.py',1648),
('constant -> INT_CONST_OCT','constant',1,'p_constant_1','c_parser.py',1649),
('constant -> INT_CONST_HEX','constant',1,'p_constant_1','c_parser.py',1650),
('constant -> INT_CONST_BIN','constant',1,'p_constant_1','c_parser.py',1651),
('constant -> FLOAT_CONST','constant',1,'p_constant_2','c_parser.py',1657),
('constant -> HEX_FLOAT_CONST','constant',1,'p_constant_2','c_parser.py',1658),
('constant -> CHAR_CONST','constant',1,'p_constant_3','c_parser.py',1664),
('constant -> WCHAR_CONST','constant',1,'p_constant_3','c_parser.py',1665),
('unified_string_literal -> STRING_LITERAL','unified_string_literal',1,'p_unified_string_literal','c_parser.py',1676),
('unified_string_literal -> unified_string_literal STRING_LITERAL','unified_string_literal',2,'p_unified_string_literal','c_parser.py',1677),
('unified_wstring_literal -> WSTRING_LITERAL','unified_wstring_literal',1,'p_unified_wstring_literal','c_parser.py',1687),
('unified_wstring_literal -> unified_wstring_literal WSTRING_LITERAL','unified_wstring_literal',2,'p_unified_wstring_literal','c_parser.py',1688),
('brace_open -> LBRACE','brace_open',1,'p_brace_open','c_parser.py',1698),
('brace_close -> RBRACE','brace_close',1,'p_brace_close','c_parser.py',1704),
('empty -> <empty>','empty',0,'p_empty','c_parser.py',1710),
]
|
mit
|
[
199,
3,
612,
23015,
371,
14,
647,
199,
3,
961,
570,
365,
5847,
4046,
14,
4226,
440,
5283,
14,
199,
63,
2902,
1023,
275,
283,
19,
14,
24,
7,
199,
199,
63,
7493,
63,
765,
275,
283,
44,
748,
50,
7,
199,
199,
63,
7493,
63,
5233,
275,
283,
21,
34,
22,
34,
1153,
9956,
772,
1348,
1644,
1299,
15117,
37,
16,
38,
713,
13702,
1020,
18857,
7,
1362,
199,
63,
7493,
63,
1287,
63,
1744,
275,
791,
17510,
356,
779,
16,
12,
17,
12,
18,
12,
19,
12,
21,
12,
22,
12,
25,
12,
709,
12,
845,
12,
713,
12,
969,
12,
1079,
12,
1046,
12,
1196,
12,
1085,
12,
1167,
12,
2025,
12,
1081,
12,
1789,
12,
1194,
12,
1479,
12,
1465,
12,
1651,
12,
1216,
12,
708,
12,
1153,
12,
1082,
12,
1344,
12,
1401,
12,
1703,
12,
1355,
12,
2167,
12,
2953,
12,
2824,
12,
1602,
12,
2322,
12,
2466,
12,
2417,
12,
1887,
12,
1400,
12,
2869,
12,
1367,
12,
1641,
12,
2010,
12,
1427,
12,
2976,
12,
2789,
12,
2766,
12,
772,
12,
2182,
12,
2333,
12,
1257,
12,
2564,
12,
1349,
12,
1407,
12,
3328,
12,
2942,
12,
3129,
12,
2635,
12,
2720,
12,
2534,
12,
2576,
12,
2905,
12,
1020,
12,
1960,
12,
11731,
12,
10143,
12,
13593,
12,
12478,
12,
9892,
12,
10848,
12,
10216,
12,
8881,
12,
11175,
12,
10699,
12,
7663,
12,
11874,
12,
1797,
12,
4999,
12,
10630,
12,
11583,
12,
10034,
12,
5533,
12,
10638,
12,
13319,
12,
18520,
12,
16263,
12,
10681,
12,
11125,
12,
16417,
12,
11405,
12,
11700,
12,
12615,
12,
12877,
12,
5863,
12,
11810,
12,
11516,
12,
12127,
12,
16683,
12,
19455,
12,
9927,
12,
21376,
12,
23538,
12,
12122,
12,
14761,
12,
9946,
12,
11452,
12,
12046,
12,
12015,
12,
8188,
12,
8040,
12,
11403,
12,
15490,
12,
13549,
12,
24781,
12,
25390,
12,
25250,
12,
25230,
12,
25473,
12,
24284,
12,
24338,
12,
18078,
12,
13267,
12,
11419,
12,
28645,
12,
28976,
12,
6922,
22,
12,
22,
3057,
1822,
3057,
2277,
3057,
1138,
3057,
772,
3057,
2259,
3057,
2976,
3057,
1276,
3057,
2192,
3057,
2182,
12,
22,
3057,
1401,
3057,
1427,
3057,
1342,
3057,
1876,
3057,
1344,
3057,
2010,
12,
22,
3057,
2789,
3057,
12363,
3057,
7524,
3057,
2819,
3057,
2194,
3057,
1082,
3057,
1965,
3057,
7119,
3057,
2760,
3057,
1153,
3057,
1272,
3057,
1703,
3057,
2333,
3057,
3172,
12,
22,
3057,
2898,
12,
22,
3057,
2114,
3057,
1257,
12,
22,
3057,
1355,
3057,
2766,
3057,
2710,
3057,
12442,
3057,
1407,
12,
22,
3057,
7906,
3057,
7362,
3057,
708,
3057,
7555,
3057,
7357,
12,
22,
12,
22,
12,
22,
3057,
2869,
3057,
2528,
12,
22,
3057,
2167,
3057,
6708,
12,
22,
12,
22,
12,
22,
12,
22,
3057,
1960,
3057,
2534,
12,
22,
12,
22,
12,
22,
12,
22,
3057,
2953,
12,
22,
3057,
2481,
12,
22,
12,
22,
3057,
3328,
3057,
2576,
3057,
13299,
3057,
8079,
3057,
7957,
3057,
6889,
12,
22,
12,
22,
12,
22,
12,
22,
12,
22,
3057,
2260,
3057,
1602,
3057,
2417,
3057,
2824,
3057,
2322,
12,
22,
3057,
1887,
3057,
12285,
3057,
8488,
3057,
2006,
3057,
12438,
3057,
2466,
3057,
3129,
3057,
2942,
3057,
2905,
3057,
1020,
3057,
6019,
3057,
6996,
3057,
10753,
3057,
7214,
12,
22,
3057,
7663,
3057,
10699,
12,
22,
3057,
8881,
3057,
11931,
3057,
10216,
3057,
8982,
3057,
4288,
3057,
7507,
3057,
10848,
3057,
11175,
3057,
10806,
3057,
10355,
3057,
10642,
3057,
13593,
3057,
11010,
3057,
6568,
3057,
10419,
3057,
10143,
3057,
9892,
3057,
12478,
12,
32058,
44,
25950,
356,
779,
17,
12,
18,
12,
19,
12,
21,
12,
22,
12,
25,
12,
709,
12,
969,
12,
1079,
12,
1196,
12,
1085,
12,
1167,
12,
1081,
12,
1194,
12,
1479,
12,
1465,
12,
1651,
12,
1398,
12,
1216,
12,
2192,
12,
1153,
12,
1082,
12,
1344,
12,
1703,
12,
2167,
12,
2953,
12,
2824,
12,
1602,
12,
2322,
12,
2466,
12,
2417,
12,
2869,
12,
2528,
12,
2481,
12,
1477,
12,
1367,
12,
1641,
12,
2010,
12,
2259,
12,
2789,
12,
772,
12,
2182,
12,
1876,
12,
2760,
12,
3172,
12,
2819,
12,
2114,
12,
1257,
12,
2658,
12,
2426,
12,
1184,
12,
1299,
12,
3129,
12,
2576,
12,
1960,
12,
4893,
12,
7636,
12,
7524,
12,
7119,
12,
6708,
12,
7507,
12,
6889,
12,
7957,
12,
4195,
12,
3933,
12,
7263,
12,
9056,
12,
10456,
12,
7582,
12,
12199,
12,
9862,
12,
11160,
12,
10721,
12,
8251,
12,
11024,
12,
12034,
12,
10823,
12,
9327,
12,
11010,
12,
13593,
12,
11175,
12,
7663,
12,
12851,
12,
12894,
12,
12363,
12,
10078,
12,
11874,
12,
1797,
12,
4999,
12,
9485,
12,
10932,
12,
11085,
12,
12048,
12,
8001,
12,
9803,
12,
13440,
12,
9969,
12,
16344,
12,
15000,
12,
9014,
12,
11565,
12,
11516,
12,
12127,
12,
9927,
12,
21376,
12,
23538,
12,
12122,
12,
12870,
12,
11685,
12,
14137,
12,
15638,
12,
8425,
12,
11870,
12,
14761,
12,
10875,
12,
12664,
12,
12684,
12,
11939,
12,
16124,
12,
15541,
12,
14539,
12,
15490,
12,
13549,
12,
13443,
12,
13145,
12,
5188,
12,
13344,
12,
23814,
12,
30813,
12,
26274,
12,
21717,
12,
31352,
12,
20761,
12,
20773,
12,
24049,
12,
467,
1988,
16344,
3057,
1822,
3057,
2277,
3057,
1138,
3057,
772,
3057,
2259,
3057,
2976,
3057,
2182,
3057,
16344,
3057,
1427,
3057,
1342,
3057,
1876,
3057,
2010,
3057,
2789,
3057,
12363,
12,
1822,
3057,
2819,
3057,
16344,
3057,
2194,
12,
1342,
3057,
1965,
3057,
7119,
3057,
2760,
3057,
1272,
3057,
2333,
3057,
3172,
3057,
16344,
3057,
2898,
3057,
16344,
3057,
2114,
3057,
1257,
3057,
2766,
3057,
1367,
3057,
25,
3057,
709,
3057,
2710,
3057,
12442,
3057,
1407,
3057,
1229,
12,
1822,
3057,
7555,
3057,
7357,
3057,
1651,
3057,
4195,
3057,
7263,
3057,
1465,
12,
1342,
12,
1342,
12,
6568,
3057,
1477,
3057,
1641,
12,
1342,
3057,
6708,
3057,
16344,
3057,
16344,
12,
1342,
12,
1342,
3057,
3912,
3057,
9056,
3057,
3933,
3057,
13085,
3057,
11242,
3057,
14622,
3057,
13406,
3057,
9408,
3057,
15128,
3057,
11440,
3057,
11717,
12,
9687,
3057,
11990,
3057,
10034,
3057,
13730,
3057,
11551,
3057,
11677,
3057,
14820,
3057,
12234,
12,
6568,
12,
13731,
12,
1342,
12,
1342,
3057,
3328
] |
[
3,
612,
23015,
371,
14,
647,
199,
3,
961,
570,
365,
5847,
4046,
14,
4226,
440,
5283,
14,
199,
63,
2902,
1023,
275,
283,
19,
14,
24,
7,
199,
199,
63,
7493,
63,
765,
275,
283,
44,
748,
50,
7,
199,
199,
63,
7493,
63,
5233,
275,
283,
21,
34,
22,
34,
1153,
9956,
772,
1348,
1644,
1299,
15117,
37,
16,
38,
713,
13702,
1020,
18857,
7,
1362,
199,
63,
7493,
63,
1287,
63,
1744,
275,
791,
17510,
356,
779,
16,
12,
17,
12,
18,
12,
19,
12,
21,
12,
22,
12,
25,
12,
709,
12,
845,
12,
713,
12,
969,
12,
1079,
12,
1046,
12,
1196,
12,
1085,
12,
1167,
12,
2025,
12,
1081,
12,
1789,
12,
1194,
12,
1479,
12,
1465,
12,
1651,
12,
1216,
12,
708,
12,
1153,
12,
1082,
12,
1344,
12,
1401,
12,
1703,
12,
1355,
12,
2167,
12,
2953,
12,
2824,
12,
1602,
12,
2322,
12,
2466,
12,
2417,
12,
1887,
12,
1400,
12,
2869,
12,
1367,
12,
1641,
12,
2010,
12,
1427,
12,
2976,
12,
2789,
12,
2766,
12,
772,
12,
2182,
12,
2333,
12,
1257,
12,
2564,
12,
1349,
12,
1407,
12,
3328,
12,
2942,
12,
3129,
12,
2635,
12,
2720,
12,
2534,
12,
2576,
12,
2905,
12,
1020,
12,
1960,
12,
11731,
12,
10143,
12,
13593,
12,
12478,
12,
9892,
12,
10848,
12,
10216,
12,
8881,
12,
11175,
12,
10699,
12,
7663,
12,
11874,
12,
1797,
12,
4999,
12,
10630,
12,
11583,
12,
10034,
12,
5533,
12,
10638,
12,
13319,
12,
18520,
12,
16263,
12,
10681,
12,
11125,
12,
16417,
12,
11405,
12,
11700,
12,
12615,
12,
12877,
12,
5863,
12,
11810,
12,
11516,
12,
12127,
12,
16683,
12,
19455,
12,
9927,
12,
21376,
12,
23538,
12,
12122,
12,
14761,
12,
9946,
12,
11452,
12,
12046,
12,
12015,
12,
8188,
12,
8040,
12,
11403,
12,
15490,
12,
13549,
12,
24781,
12,
25390,
12,
25250,
12,
25230,
12,
25473,
12,
24284,
12,
24338,
12,
18078,
12,
13267,
12,
11419,
12,
28645,
12,
28976,
12,
6922,
22,
12,
22,
3057,
1822,
3057,
2277,
3057,
1138,
3057,
772,
3057,
2259,
3057,
2976,
3057,
1276,
3057,
2192,
3057,
2182,
12,
22,
3057,
1401,
3057,
1427,
3057,
1342,
3057,
1876,
3057,
1344,
3057,
2010,
12,
22,
3057,
2789,
3057,
12363,
3057,
7524,
3057,
2819,
3057,
2194,
3057,
1082,
3057,
1965,
3057,
7119,
3057,
2760,
3057,
1153,
3057,
1272,
3057,
1703,
3057,
2333,
3057,
3172,
12,
22,
3057,
2898,
12,
22,
3057,
2114,
3057,
1257,
12,
22,
3057,
1355,
3057,
2766,
3057,
2710,
3057,
12442,
3057,
1407,
12,
22,
3057,
7906,
3057,
7362,
3057,
708,
3057,
7555,
3057,
7357,
12,
22,
12,
22,
12,
22,
3057,
2869,
3057,
2528,
12,
22,
3057,
2167,
3057,
6708,
12,
22,
12,
22,
12,
22,
12,
22,
3057,
1960,
3057,
2534,
12,
22,
12,
22,
12,
22,
12,
22,
3057,
2953,
12,
22,
3057,
2481,
12,
22,
12,
22,
3057,
3328,
3057,
2576,
3057,
13299,
3057,
8079,
3057,
7957,
3057,
6889,
12,
22,
12,
22,
12,
22,
12,
22,
12,
22,
3057,
2260,
3057,
1602,
3057,
2417,
3057,
2824,
3057,
2322,
12,
22,
3057,
1887,
3057,
12285,
3057,
8488,
3057,
2006,
3057,
12438,
3057,
2466,
3057,
3129,
3057,
2942,
3057,
2905,
3057,
1020,
3057,
6019,
3057,
6996,
3057,
10753,
3057,
7214,
12,
22,
3057,
7663,
3057,
10699,
12,
22,
3057,
8881,
3057,
11931,
3057,
10216,
3057,
8982,
3057,
4288,
3057,
7507,
3057,
10848,
3057,
11175,
3057,
10806,
3057,
10355,
3057,
10642,
3057,
13593,
3057,
11010,
3057,
6568,
3057,
10419,
3057,
10143,
3057,
9892,
3057,
12478,
12,
32058,
44,
25950,
356,
779,
17,
12,
18,
12,
19,
12,
21,
12,
22,
12,
25,
12,
709,
12,
969,
12,
1079,
12,
1196,
12,
1085,
12,
1167,
12,
1081,
12,
1194,
12,
1479,
12,
1465,
12,
1651,
12,
1398,
12,
1216,
12,
2192,
12,
1153,
12,
1082,
12,
1344,
12,
1703,
12,
2167,
12,
2953,
12,
2824,
12,
1602,
12,
2322,
12,
2466,
12,
2417,
12,
2869,
12,
2528,
12,
2481,
12,
1477,
12,
1367,
12,
1641,
12,
2010,
12,
2259,
12,
2789,
12,
772,
12,
2182,
12,
1876,
12,
2760,
12,
3172,
12,
2819,
12,
2114,
12,
1257,
12,
2658,
12,
2426,
12,
1184,
12,
1299,
12,
3129,
12,
2576,
12,
1960,
12,
4893,
12,
7636,
12,
7524,
12,
7119,
12,
6708,
12,
7507,
12,
6889,
12,
7957,
12,
4195,
12,
3933,
12,
7263,
12,
9056,
12,
10456,
12,
7582,
12,
12199,
12,
9862,
12,
11160,
12,
10721,
12,
8251,
12,
11024,
12,
12034,
12,
10823,
12,
9327,
12,
11010,
12,
13593,
12,
11175,
12,
7663,
12,
12851,
12,
12894,
12,
12363,
12,
10078,
12,
11874,
12,
1797,
12,
4999,
12,
9485,
12,
10932,
12,
11085,
12,
12048,
12,
8001,
12,
9803,
12,
13440,
12,
9969,
12,
16344,
12,
15000,
12,
9014,
12,
11565,
12,
11516,
12,
12127,
12,
9927,
12,
21376,
12,
23538,
12,
12122,
12,
12870,
12,
11685,
12,
14137,
12,
15638,
12,
8425,
12,
11870,
12,
14761,
12,
10875,
12,
12664,
12,
12684,
12,
11939,
12,
16124,
12,
15541,
12,
14539,
12,
15490,
12,
13549,
12,
13443,
12,
13145,
12,
5188,
12,
13344,
12,
23814,
12,
30813,
12,
26274,
12,
21717,
12,
31352,
12,
20761,
12,
20773,
12,
24049,
12,
467,
1988,
16344,
3057,
1822,
3057,
2277,
3057,
1138,
3057,
772,
3057,
2259,
3057,
2976,
3057,
2182,
3057,
16344,
3057,
1427,
3057,
1342,
3057,
1876,
3057,
2010,
3057,
2789,
3057,
12363,
12,
1822,
3057,
2819,
3057,
16344,
3057,
2194,
12,
1342,
3057,
1965,
3057,
7119,
3057,
2760,
3057,
1272,
3057,
2333,
3057,
3172,
3057,
16344,
3057,
2898,
3057,
16344,
3057,
2114,
3057,
1257,
3057,
2766,
3057,
1367,
3057,
25,
3057,
709,
3057,
2710,
3057,
12442,
3057,
1407,
3057,
1229,
12,
1822,
3057,
7555,
3057,
7357,
3057,
1651,
3057,
4195,
3057,
7263,
3057,
1465,
12,
1342,
12,
1342,
12,
6568,
3057,
1477,
3057,
1641,
12,
1342,
3057,
6708,
3057,
16344,
3057,
16344,
12,
1342,
12,
1342,
3057,
3912,
3057,
9056,
3057,
3933,
3057,
13085,
3057,
11242,
3057,
14622,
3057,
13406,
3057,
9408,
3057,
15128,
3057,
11440,
3057,
11717,
12,
9687,
3057,
11990,
3057,
10034,
3057,
13730,
3057,
11551,
3057,
11677,
3057,
14820,
3057,
12234,
12,
6568,
12,
13731,
12,
1342,
12,
1342,
3057,
3328,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
NetApp/cinder
|
cinder/objects/group.py
|
4
|
7851
|
# Copyright 2016 EMC Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from cinder import db
from cinder import exception
from cinder.i18n import _
from cinder import objects
from cinder.objects import base
from cinder.objects import fields as c_fields
from oslo_versionedobjects import fields
@base.CinderObjectRegistry.register
class Group(base.CinderPersistentObject, base.CinderObject,
base.CinderObjectDictCompat):
# Version 1.0: Initial version
# Version 1.1: Added group_snapshots, group_snapshot_id, and
# source_group_id
VERSION = '1.1'
OPTIONAL_FIELDS = ['volumes', 'volume_types', 'group_snapshots']
fields = {
'id': fields.UUIDField(),
'user_id': fields.StringField(),
'project_id': fields.StringField(),
'cluster_name': fields.StringField(nullable=True),
'host': fields.StringField(nullable=True),
'availability_zone': fields.StringField(nullable=True),
'name': fields.StringField(nullable=True),
'description': fields.StringField(nullable=True),
'group_type_id': fields.StringField(),
'volume_type_ids': fields.ListOfStringsField(nullable=True),
'status': c_fields.GroupStatusField(nullable=True),
'group_snapshot_id': fields.UUIDField(nullable=True),
'source_group_id': fields.UUIDField(nullable=True),
'volumes': fields.ObjectField('VolumeList', nullable=True),
'volume_types': fields.ObjectField('VolumeTypeList',
nullable=True),
'group_snapshots': fields.ObjectField('GroupSnapshotList',
nullable=True),
}
@staticmethod
def _from_db_object(context, group, db_group,
expected_attrs=None):
if expected_attrs is None:
expected_attrs = []
for name, field in group.fields.items():
if name in Group.OPTIONAL_FIELDS:
continue
value = db_group.get(name)
setattr(group, name, value)
if 'volumes' in expected_attrs:
volumes = base.obj_make_list(
context, objects.VolumeList(context),
objects.Volume,
db_group['volumes'])
group.volumes = volumes
if 'volume_types' in expected_attrs:
volume_types = base.obj_make_list(
context, objects.VolumeTypeList(context),
objects.VolumeType,
db_group['volume_types'])
group.volume_types = volume_types
if 'group_snapshots' in expected_attrs:
group_snapshots = base.obj_make_list(
context, objects.GroupSnapshotList(context),
objects.GroupSnapshot,
db_group['group_snapshots'])
group.group_snapshots = group_snapshots
group._context = context
group.obj_reset_changes()
return group
def create(self, group_snapshot_id=None, source_group_id=None):
if self.obj_attr_is_set('id'):
raise exception.ObjectActionError(action='create',
reason=_('already_created'))
updates = self.cinder_obj_get_changes()
if 'volume_types' in updates:
raise exception.ObjectActionError(
action='create',
reason=_('volume_types assigned'))
if 'volumes' in updates:
raise exception.ObjectActionError(action='create',
reason=_('volumes assigned'))
if 'group_snapshots' in updates:
raise exception.ObjectActionError(
action='create',
reason=_('group_snapshots assigned'))
db_groups = db.group_create(self._context,
updates,
group_snapshot_id,
source_group_id)
self._from_db_object(self._context, self, db_groups)
def obj_load_attr(self, attrname):
if attrname not in Group.OPTIONAL_FIELDS:
raise exception.ObjectActionError(
action='obj_load_attr',
reason=_('attribute %s not lazy-loadable') % attrname)
if not self._context:
raise exception.OrphanedObjectError(method='obj_load_attr',
objtype=self.obj_name())
if attrname == 'volume_types':
self.volume_types = objects.VolumeTypeList.get_all_by_group(
self._context, self.id)
if attrname == 'volumes':
self.volumes = objects.VolumeList.get_all_by_generic_group(
self._context, self.id)
if attrname == 'group_snapshots':
self.group_snapshots = objects.GroupSnapshotList.get_all_by_group(
self._context, self.id)
self.obj_reset_changes(fields=[attrname])
def save(self):
updates = self.cinder_obj_get_changes()
if updates:
if 'volume_types' in updates:
msg = _('Cannot save volume_types changes in group object '
'update.')
raise exception.ObjectActionError(
action='save', reason=msg)
if 'volumes' in updates:
msg = _('Cannot save volumes changes in group object update.')
raise exception.ObjectActionError(
action='save', reason=msg)
if 'group_snapshots' in updates:
msg = _('Cannot save group_snapshots changes in group object '
'update.')
raise exception.ObjectActionError(
action='save', reason=msg)
db.group_update(self._context, self.id, updates)
self.obj_reset_changes()
def destroy(self):
with self.obj_as_admin():
db.group_destroy(self._context, self.id)
@base.CinderObjectRegistry.register
class GroupList(base.ObjectListBase, base.CinderObject):
# Version 1.0: Initial version
VERSION = '1.0'
fields = {
'objects': fields.ListOfObjectsField('Group')
}
child_version = {
'1.0': '1.0',
}
@classmethod
def get_all(cls, context, filters=None, marker=None, limit=None,
offset=None, sort_keys=None, sort_dirs=None):
groups = db.group_get_all(
context, filters=filters, marker=marker, limit=limit,
offset=offset, sort_keys=sort_keys, sort_dirs=sort_dirs)
return base.obj_make_list(context, cls(context),
objects.Group,
groups)
@classmethod
def get_all_by_project(cls, context, project_id, filters=None, marker=None,
limit=None, offset=None, sort_keys=None,
sort_dirs=None):
groups = db.group_get_all_by_project(
context, project_id, filters=filters, marker=marker, limit=limit,
offset=offset, sort_keys=sort_keys, sort_dirs=sort_dirs)
return base.obj_make_list(context, cls(context),
objects.Group,
groups)
|
apache-2.0
|
[
3,
259,
1898,
7800,
662,
7608,
11098,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
13069,
492,
1592,
199,
504,
13069,
492,
1919,
199,
504,
13069,
14,
73,
1085,
78,
492,
485,
199,
504,
13069,
492,
2251,
199,
504,
13069,
14,
1462,
492,
1300,
199,
504,
13069,
14,
1462,
492,
1504,
465,
286,
63,
955,
199,
504,
11258,
63,
24155,
1462,
492,
1504,
421,
199,
32,
1095,
14,
35,
5755,
1692,
10899,
14,
2683,
199,
533,
5611,
8,
1095,
14,
35,
5755,
31966,
1692,
12,
1300,
14,
35,
5755,
1692,
12,
288,
1300,
14,
35,
5755,
1692,
2141,
2404,
292,
304,
272,
327,
3394,
413,
14,
16,
26,
6026,
1015,
272,
327,
3394,
413,
14,
17,
26,
16230,
1572,
63,
15331,
12,
1572,
63,
4753,
63,
344,
12,
436,
272,
327,
4519,
1350,
63,
923,
63,
344,
272,
15945,
275,
283,
17,
14,
17,
7,
339,
30953,
63,
12767,
275,
788,
8838,
297,
283,
2405,
63,
1313,
297,
283,
923,
63,
15331,
418,
339,
1504,
275,
469,
267,
283,
344,
356,
1504,
14,
8757,
792,
1062,
267,
283,
751,
63,
344,
356,
1504,
14,
14912,
1062,
267,
283,
1715,
63,
344,
356,
1504,
14,
14912,
1062,
267,
283,
4201,
63,
354,
356,
1504,
14,
14912,
8,
16375,
29,
549,
395,
267,
283,
1102,
356,
1504,
14,
14912,
8,
16375,
29,
549,
395,
267,
283,
11856,
63,
2619,
356,
1504,
14,
14912,
8,
16375,
29,
549,
395,
267,
283,
354,
356,
1504,
14,
14912,
8,
16375,
29,
549,
395,
267,
283,
1802,
356,
1504,
14,
14912,
8,
16375,
29,
549,
395,
267,
283,
923,
63,
466,
63,
344,
356,
1504,
14,
14912,
1062,
267,
283,
2405,
63,
466,
63,
1580,
356,
1504,
14,
30210,
12672,
792,
8,
16375,
29,
549,
395,
267,
283,
1205,
356,
286,
63,
955,
14,
2448,
3694,
792,
8,
16375,
29,
549,
395,
267,
283,
923,
63,
4753,
63,
344,
356,
1504,
14,
8757,
792,
8,
16375,
29,
549,
395,
267,
283,
1365,
63,
923,
63,
344,
356,
1504,
14,
8757,
792,
8,
16375,
29,
549,
395,
267,
283,
8838,
356,
1504,
14,
1692,
792,
360,
6464,
1296,
297,
7854,
29,
549,
395,
267,
283,
2405,
63,
1313,
356,
1504,
14,
1692,
792,
360,
6464,
804,
1296,
297,
5644,
7854,
29,
549,
395,
267,
283,
923,
63,
15331,
356,
1504,
14,
1692,
792,
360,
2448,
12038,
1296,
297,
6343,
7854,
29,
549,
395,
272,
789,
339,
768,
4639,
272,
347,
485,
504,
63,
697,
63,
785,
8,
1100,
12,
1572,
12,
1592,
63,
923,
12,
717,
1420,
63,
3288,
29,
403,
304,
267,
340,
1420,
63,
3288,
365,
488,
26,
288,
1420,
63,
3288,
275,
942,
267,
367,
536,
12,
901,
315,
1572,
14,
955,
14,
1744,
837,
288,
340,
536,
315,
5611,
14,
21008,
63,
12767,
26,
355,
1980,
288,
574,
275,
1592,
63,
923,
14,
362,
8,
354,
9,
288,
5371,
8,
923,
12,
536,
12,
574,
9,
398,
340,
283,
8838,
7,
315,
1420,
63,
3288,
26,
288,
12158,
275,
1300,
14,
1113,
63,
1875,
63,
513,
8,
355,
1067,
12,
2251,
14,
6464,
1296,
8,
1100,
395,
355,
2251,
14,
6464,
12,
355,
1592,
63,
923,
459,
8838,
1105,
288,
1572,
14,
8838,
275,
12158,
398,
340,
283,
2405,
63,
1313,
7,
315,
1420,
63,
3288,
26,
288,
3301,
63,
1313,
275,
1300,
14,
1113,
63,
1875,
63,
513,
8,
355,
1067,
12,
2251,
14,
6464,
804,
1296,
8,
1100,
395,
355,
2251,
14,
6464,
804,
12,
355,
1592,
63,
923,
459,
2405,
63,
1313,
1105,
288,
1572,
14,
2405,
63,
1313,
275,
3301,
63,
1313,
398,
340,
283,
923,
63,
15331,
7,
315,
1420,
63,
3288,
26,
288,
1572,
63,
15331,
275,
1300,
14,
1113,
63,
1875,
63,
513,
8,
355,
1067,
12,
2251,
14,
2448,
12038,
1296,
8,
1100,
395,
355,
2251,
14,
2448,
12038,
12,
355,
1592,
63,
923,
459,
923,
63,
15331,
1105,
288,
1572,
14,
923,
63,
15331,
275,
1572,
63,
15331,
398,
1572,
423,
1100,
275,
1067,
267,
1572,
14,
1113,
63,
3958,
63,
6627,
342,
267,
372,
1572,
339,
347,
1218,
8,
277,
12,
1572,
63,
4753,
63,
344,
29,
403,
12,
1350,
63,
923,
63,
344,
29,
403,
304,
267,
340,
291,
14,
1113,
63,
962,
63,
374,
63,
409,
360,
344,
735,
288,
746,
1919,
14,
1692,
3310,
547,
8,
1287,
534,
981,
297,
6343,
4499,
12397,
14039,
63,
3966,
1333,
267,
7029,
275,
291,
14,
12372,
63,
1113,
63,
362,
63,
6627,
342,
398,
340,
283,
2405,
63,
1313,
7,
315,
7029,
26,
288,
746,
1919,
14,
1692,
3310,
547,
8,
355,
1595,
534,
981,
297,
355,
4499,
12397,
2405,
63,
1313,
7943,
1333,
398,
340,
283,
8838,
7,
315,
7029,
26,
288,
746,
1919,
14,
1692,
3310,
547,
8,
1287,
534,
981,
297,
6343,
4499,
12397,
8838,
7943,
1333,
398,
340,
283,
923,
63,
15331,
7,
315,
7029,
26,
288,
746,
1919,
14,
1692,
3310,
547,
8,
355,
1595,
534,
981,
297,
355,
4499,
12397,
923,
63,
15331,
7943,
1333,
398,
1592,
63,
2634,
275,
1592,
14,
923,
63,
981,
8,
277,
423,
1100,
12,
2511,
7029,
12,
2511,
1572,
63,
4753,
63,
344,
12,
2511,
1350,
63,
923,
63,
344,
9,
267,
291,
423,
504,
63,
697,
63,
785,
8,
277,
423,
1100,
12,
291,
12,
1592,
63,
2634,
9,
339,
347,
1559,
63,
912,
63,
962,
8,
277,
12,
26367
] |
[
259,
1898,
7800,
662,
7608,
11098,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
13069,
492,
1592,
199,
504,
13069,
492,
1919,
199,
504,
13069,
14,
73,
1085,
78,
492,
485,
199,
504,
13069,
492,
2251,
199,
504,
13069,
14,
1462,
492,
1300,
199,
504,
13069,
14,
1462,
492,
1504,
465,
286,
63,
955,
199,
504,
11258,
63,
24155,
1462,
492,
1504,
421,
199,
32,
1095,
14,
35,
5755,
1692,
10899,
14,
2683,
199,
533,
5611,
8,
1095,
14,
35,
5755,
31966,
1692,
12,
1300,
14,
35,
5755,
1692,
12,
288,
1300,
14,
35,
5755,
1692,
2141,
2404,
292,
304,
272,
327,
3394,
413,
14,
16,
26,
6026,
1015,
272,
327,
3394,
413,
14,
17,
26,
16230,
1572,
63,
15331,
12,
1572,
63,
4753,
63,
344,
12,
436,
272,
327,
4519,
1350,
63,
923,
63,
344,
272,
15945,
275,
283,
17,
14,
17,
7,
339,
30953,
63,
12767,
275,
788,
8838,
297,
283,
2405,
63,
1313,
297,
283,
923,
63,
15331,
418,
339,
1504,
275,
469,
267,
283,
344,
356,
1504,
14,
8757,
792,
1062,
267,
283,
751,
63,
344,
356,
1504,
14,
14912,
1062,
267,
283,
1715,
63,
344,
356,
1504,
14,
14912,
1062,
267,
283,
4201,
63,
354,
356,
1504,
14,
14912,
8,
16375,
29,
549,
395,
267,
283,
1102,
356,
1504,
14,
14912,
8,
16375,
29,
549,
395,
267,
283,
11856,
63,
2619,
356,
1504,
14,
14912,
8,
16375,
29,
549,
395,
267,
283,
354,
356,
1504,
14,
14912,
8,
16375,
29,
549,
395,
267,
283,
1802,
356,
1504,
14,
14912,
8,
16375,
29,
549,
395,
267,
283,
923,
63,
466,
63,
344,
356,
1504,
14,
14912,
1062,
267,
283,
2405,
63,
466,
63,
1580,
356,
1504,
14,
30210,
12672,
792,
8,
16375,
29,
549,
395,
267,
283,
1205,
356,
286,
63,
955,
14,
2448,
3694,
792,
8,
16375,
29,
549,
395,
267,
283,
923,
63,
4753,
63,
344,
356,
1504,
14,
8757,
792,
8,
16375,
29,
549,
395,
267,
283,
1365,
63,
923,
63,
344,
356,
1504,
14,
8757,
792,
8,
16375,
29,
549,
395,
267,
283,
8838,
356,
1504,
14,
1692,
792,
360,
6464,
1296,
297,
7854,
29,
549,
395,
267,
283,
2405,
63,
1313,
356,
1504,
14,
1692,
792,
360,
6464,
804,
1296,
297,
5644,
7854,
29,
549,
395,
267,
283,
923,
63,
15331,
356,
1504,
14,
1692,
792,
360,
2448,
12038,
1296,
297,
6343,
7854,
29,
549,
395,
272,
789,
339,
768,
4639,
272,
347,
485,
504,
63,
697,
63,
785,
8,
1100,
12,
1572,
12,
1592,
63,
923,
12,
717,
1420,
63,
3288,
29,
403,
304,
267,
340,
1420,
63,
3288,
365,
488,
26,
288,
1420,
63,
3288,
275,
942,
267,
367,
536,
12,
901,
315,
1572,
14,
955,
14,
1744,
837,
288,
340,
536,
315,
5611,
14,
21008,
63,
12767,
26,
355,
1980,
288,
574,
275,
1592,
63,
923,
14,
362,
8,
354,
9,
288,
5371,
8,
923,
12,
536,
12,
574,
9,
398,
340,
283,
8838,
7,
315,
1420,
63,
3288,
26,
288,
12158,
275,
1300,
14,
1113,
63,
1875,
63,
513,
8,
355,
1067,
12,
2251,
14,
6464,
1296,
8,
1100,
395,
355,
2251,
14,
6464,
12,
355,
1592,
63,
923,
459,
8838,
1105,
288,
1572,
14,
8838,
275,
12158,
398,
340,
283,
2405,
63,
1313,
7,
315,
1420,
63,
3288,
26,
288,
3301,
63,
1313,
275,
1300,
14,
1113,
63,
1875,
63,
513,
8,
355,
1067,
12,
2251,
14,
6464,
804,
1296,
8,
1100,
395,
355,
2251,
14,
6464,
804,
12,
355,
1592,
63,
923,
459,
2405,
63,
1313,
1105,
288,
1572,
14,
2405,
63,
1313,
275,
3301,
63,
1313,
398,
340,
283,
923,
63,
15331,
7,
315,
1420,
63,
3288,
26,
288,
1572,
63,
15331,
275,
1300,
14,
1113,
63,
1875,
63,
513,
8,
355,
1067,
12,
2251,
14,
2448,
12038,
1296,
8,
1100,
395,
355,
2251,
14,
2448,
12038,
12,
355,
1592,
63,
923,
459,
923,
63,
15331,
1105,
288,
1572,
14,
923,
63,
15331,
275,
1572,
63,
15331,
398,
1572,
423,
1100,
275,
1067,
267,
1572,
14,
1113,
63,
3958,
63,
6627,
342,
267,
372,
1572,
339,
347,
1218,
8,
277,
12,
1572,
63,
4753,
63,
344,
29,
403,
12,
1350,
63,
923,
63,
344,
29,
403,
304,
267,
340,
291,
14,
1113,
63,
962,
63,
374,
63,
409,
360,
344,
735,
288,
746,
1919,
14,
1692,
3310,
547,
8,
1287,
534,
981,
297,
6343,
4499,
12397,
14039,
63,
3966,
1333,
267,
7029,
275,
291,
14,
12372,
63,
1113,
63,
362,
63,
6627,
342,
398,
340,
283,
2405,
63,
1313,
7,
315,
7029,
26,
288,
746,
1919,
14,
1692,
3310,
547,
8,
355,
1595,
534,
981,
297,
355,
4499,
12397,
2405,
63,
1313,
7943,
1333,
398,
340,
283,
8838,
7,
315,
7029,
26,
288,
746,
1919,
14,
1692,
3310,
547,
8,
1287,
534,
981,
297,
6343,
4499,
12397,
8838,
7943,
1333,
398,
340,
283,
923,
63,
15331,
7,
315,
7029,
26,
288,
746,
1919,
14,
1692,
3310,
547,
8,
355,
1595,
534,
981,
297,
355,
4499,
12397,
923,
63,
15331,
7943,
1333,
398,
1592,
63,
2634,
275,
1592,
14,
923,
63,
981,
8,
277,
423,
1100,
12,
2511,
7029,
12,
2511,
1572,
63,
4753,
63,
344,
12,
2511,
1350,
63,
923,
63,
344,
9,
267,
291,
423,
504,
63,
697,
63,
785,
8,
277,
423,
1100,
12,
291,
12,
1592,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
dkroy/luigi
|
test/test_sigpipe.py
|
95
|
2848
|
# -*- coding: utf-8 -*-
#
# Copyright 2012-2015 Spotify AB
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
from helpers import unittest
from luigi.format import InputPipeProcessWrapper
BASH_SCRIPT = """
#!/bin/bash
trap "touch /tmp/luigi_sigpipe.marker; exit 141" SIGPIPE
for i in {1..3}
do
sleep 0.1
echo "Welcome $i times"
done
"""
FAIL_SCRIPT = BASH_SCRIPT + """
exit 1
"""
class TestSigpipe(unittest.TestCase):
def setUp(self):
with open("/tmp/luigi_test_sigpipe.sh", "w") as fp:
fp.write(BASH_SCRIPT)
def tearDown(self):
os.remove("/tmp/luigi_test_sigpipe.sh")
if os.path.exists("/tmp/luigi_sigpipe.marker"):
os.remove("/tmp/luigi_sigpipe.marker")
def test_partial_read(self):
p1 = InputPipeProcessWrapper(["bash", "/tmp/luigi_test_sigpipe.sh"])
self.assertEqual(p1.readline().decode('utf8'), "Welcome 1 times\n")
p1.close()
self.assertTrue(os.path.exists("/tmp/luigi_sigpipe.marker"))
def test_full_read(self):
p1 = InputPipeProcessWrapper(["bash", "/tmp/luigi_test_sigpipe.sh"])
counter = 1
for line in p1:
self.assertEqual(line.decode('utf8'), "Welcome %i times\n" % counter)
counter += 1
p1.close()
self.assertFalse(os.path.exists("/tmp/luigi_sigpipe.marker"))
class TestSubprocessException(unittest.TestCase):
def setUp(self):
with open("/tmp/luigi_test_sigpipe.sh", "w") as fp:
fp.write(FAIL_SCRIPT)
def tearDown(self):
os.remove("/tmp/luigi_test_sigpipe.sh")
if os.path.exists("/tmp/luigi_sigpipe.marker"):
os.remove("/tmp/luigi_sigpipe.marker")
def test_partial_read(self):
p1 = InputPipeProcessWrapper(["bash", "/tmp/luigi_test_sigpipe.sh"])
self.assertEqual(p1.readline().decode('utf8'), "Welcome 1 times\n")
p1.close()
self.assertTrue(os.path.exists("/tmp/luigi_sigpipe.marker"))
def test_full_read(self):
def run():
p1 = InputPipeProcessWrapper(["bash", "/tmp/luigi_test_sigpipe.sh"])
counter = 1
for line in p1:
self.assertEqual(line.decode('utf8'), "Welcome %i times\n" % counter)
counter += 1
p1.close()
self.assertRaises(RuntimeError, run)
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6029,
13,
7806,
428,
555,
3338,
14840,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
646,
747,
199,
504,
10897,
492,
2882,
199,
199,
504,
19485,
14,
908,
492,
6924,
11867,
3498,
4590,
421,
199,
34,
8100,
63,
10484,
275,
408,
199,
3381,
1393,
15,
16408,
199,
199,
19510,
298,
12376,
1182,
2791,
15,
26795,
63,
4093,
4990,
14,
4211,
27,
4458,
413,
2953,
2,
15522,
6089,
421,
199,
509,
284,
315,
469,
17,
703,
19,
93,
199,
1117,
272,
9435,
378,
14,
17,
272,
11343,
298,
24679,
2672,
73,
5431,
2,
199,
4456,
199,
624,
199,
199,
8784,
63,
10484,
275,
4147,
40,
63,
10484,
435,
408,
199,
2224,
413,
199,
624,
421,
199,
533,
1379,
11575,
4990,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
543,
1551,
4769,
2791,
15,
26795,
63,
396,
63,
4093,
4990,
14,
609,
401,
298,
87,
531,
465,
4090,
26,
288,
4090,
14,
952,
8,
34,
8100,
63,
10484,
9,
339,
347,
6766,
8,
277,
304,
267,
747,
14,
2168,
4769,
2791,
15,
26795,
63,
396,
63,
4093,
4990,
14,
609,
531,
267,
340,
747,
14,
515,
14,
2444,
4769,
2791,
15,
26795,
63,
4093,
4990,
14,
4211,
2349,
288,
747,
14,
2168,
4769,
2791,
15,
26795,
63,
4093,
4990,
14,
4211,
531,
339,
347,
511,
63,
6672,
63,
739,
8,
277,
304,
267,
299,
17,
275,
6924,
11867,
3498,
4590,
5234,
16408,
401,
3286,
2791,
15,
26795,
63,
396,
63,
4093,
4990,
14,
609,
3135,
267,
291,
14,
629,
8,
80,
17,
14,
6407,
1252,
2708,
360,
1624,
24,
659,
298,
24679,
413,
5431,
60,
78,
531,
267,
299,
17,
14,
1600,
342,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
4769,
2791,
15,
26795,
63,
4093,
4990,
14,
4211,
2237,
339,
347,
511,
63,
2861,
63,
739,
8,
277,
304,
267,
299,
17,
275,
6924,
11867,
3498,
4590,
5234,
16408,
401,
3286,
2791,
15,
26795,
63,
396,
63,
4093,
4990,
14,
609,
3135,
267,
7055,
275,
413,
267,
367,
1004,
315,
299,
17,
26,
288,
291,
14,
629,
8,
604,
14,
2708,
360,
1624,
24,
659,
298,
24679,
450,
73,
5431,
60,
78,
2,
450,
7055,
9,
288,
7055,
847,
413,
267,
299,
17,
14,
1600,
342,
267,
291,
14,
3334,
8,
736,
14,
515,
14,
2444,
4769,
2791,
15,
26795,
63,
4093,
4990,
14,
4211,
2237,
421,
199,
533,
1379,
22299,
1726,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
543,
1551,
4769,
2791,
15,
26795,
63,
396,
63,
4093,
4990,
14,
609,
401,
298,
87,
531,
465,
4090,
26,
288,
4090,
14,
952,
8,
8784,
63,
10484,
9,
339,
347,
6766,
8,
277,
304,
267,
747,
14,
2168,
4769,
2791,
15,
26795,
63,
396,
63,
4093,
4990,
14,
609,
531,
267,
340,
747,
14,
515,
14,
2444,
4769,
2791,
15,
26795,
63,
4093,
4990,
14,
4211,
2349,
288,
747,
14,
2168,
4769,
2791,
15,
26795,
63,
4093,
4990,
14,
4211,
531,
339,
347,
511,
63,
6672,
63,
739,
8,
277,
304,
267,
299,
17,
275,
6924,
11867,
3498,
4590,
5234,
16408,
401,
3286,
2791,
15,
26795,
63,
396,
63,
4093,
4990,
14,
609,
3135,
267,
291,
14,
629,
8,
80,
17,
14,
6407,
1252,
2708,
360,
1624,
24,
659,
298,
24679,
413,
5431,
60,
78,
531,
267,
299,
17,
14,
1600,
342,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
4769,
2791,
15,
26795,
63,
4093,
4990,
14,
4211,
2237,
339,
347,
511,
63,
2861,
63,
739,
8,
277,
304,
267,
347,
1255,
837,
288,
299,
17,
275,
6924,
11867,
3498,
4590,
5234,
16408,
401,
3286,
2791,
15,
26795,
63,
396,
63,
4093,
4990,
14,
609,
3135,
288,
7055,
275,
413,
288,
367,
1004,
315,
299,
17,
26,
355,
291,
14,
629,
8,
604,
14,
2708,
360,
1624,
24,
659,
298,
24679,
450,
73,
5431,
60,
78,
2,
450,
7055,
9,
355,
7055,
847,
413,
288,
299,
17,
14,
1600,
342,
398,
291,
14,
1855,
8,
13281,
12,
1255,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6029,
13,
7806,
428,
555,
3338,
14840,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
646,
747,
199,
504,
10897,
492,
2882,
199,
199,
504,
19485,
14,
908,
492,
6924,
11867,
3498,
4590,
421,
199,
34,
8100,
63,
10484,
275,
408,
199,
3381,
1393,
15,
16408,
199,
199,
19510,
298,
12376,
1182,
2791,
15,
26795,
63,
4093,
4990,
14,
4211,
27,
4458,
413,
2953,
2,
15522,
6089,
421,
199,
509,
284,
315,
469,
17,
703,
19,
93,
199,
1117,
272,
9435,
378,
14,
17,
272,
11343,
298,
24679,
2672,
73,
5431,
2,
199,
4456,
199,
624,
199,
199,
8784,
63,
10484,
275,
4147,
40,
63,
10484,
435,
408,
199,
2224,
413,
199,
624,
421,
199,
533,
1379,
11575,
4990,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
543,
1551,
4769,
2791,
15,
26795,
63,
396,
63,
4093,
4990,
14,
609,
401,
298,
87,
531,
465,
4090,
26,
288,
4090,
14,
952,
8,
34,
8100,
63,
10484,
9,
339,
347,
6766,
8,
277,
304,
267,
747,
14,
2168,
4769,
2791,
15,
26795,
63,
396,
63,
4093,
4990,
14,
609,
531,
267,
340,
747,
14,
515,
14,
2444,
4769,
2791,
15,
26795,
63,
4093,
4990,
14,
4211,
2349,
288,
747,
14,
2168,
4769,
2791,
15,
26795,
63,
4093,
4990,
14,
4211,
531,
339,
347,
511,
63,
6672,
63,
739,
8,
277,
304,
267,
299,
17,
275,
6924,
11867,
3498,
4590,
5234,
16408,
401,
3286,
2791,
15,
26795,
63,
396,
63,
4093,
4990,
14,
609,
3135,
267,
291,
14,
629,
8,
80,
17,
14,
6407,
1252,
2708,
360,
1624,
24,
659,
298,
24679,
413,
5431,
60,
78,
531,
267,
299,
17,
14,
1600,
342,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
4769,
2791,
15,
26795,
63,
4093,
4990,
14,
4211,
2237,
339,
347,
511,
63,
2861,
63,
739,
8,
277,
304,
267,
299,
17,
275,
6924,
11867,
3498,
4590,
5234,
16408,
401,
3286,
2791,
15,
26795,
63,
396,
63,
4093,
4990,
14,
609,
3135,
267,
7055,
275,
413,
267,
367,
1004,
315,
299,
17,
26,
288,
291,
14,
629,
8,
604,
14,
2708,
360,
1624,
24,
659,
298,
24679,
450,
73,
5431,
60,
78,
2,
450,
7055,
9,
288,
7055,
847,
413,
267,
299,
17,
14,
1600,
342,
267,
291,
14,
3334,
8,
736,
14,
515,
14,
2444,
4769,
2791,
15,
26795,
63,
4093,
4990,
14,
4211,
2237,
421,
199,
533,
1379,
22299,
1726,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
543,
1551,
4769,
2791,
15,
26795,
63,
396,
63,
4093,
4990,
14,
609,
401,
298,
87,
531,
465,
4090,
26,
288,
4090,
14,
952,
8,
8784,
63,
10484,
9,
339,
347,
6766,
8,
277,
304,
267,
747,
14,
2168,
4769,
2791,
15,
26795,
63,
396,
63,
4093,
4990,
14,
609,
531,
267,
340,
747,
14,
515,
14,
2444,
4769,
2791,
15,
26795,
63,
4093,
4990,
14,
4211,
2349,
288,
747,
14,
2168,
4769,
2791,
15,
26795,
63,
4093,
4990,
14,
4211,
531,
339,
347,
511,
63,
6672,
63,
739,
8,
277,
304,
267,
299,
17,
275,
6924,
11867,
3498,
4590,
5234,
16408,
401,
3286,
2791,
15,
26795,
63,
396,
63,
4093,
4990,
14,
609,
3135,
267,
291,
14,
629,
8,
80,
17,
14,
6407,
1252,
2708,
360,
1624,
24,
659,
298,
24679,
413,
5431,
60,
78,
531,
267,
299,
17,
14,
1600,
342,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
4769,
2791,
15,
26795,
63,
4093,
4990,
14,
4211,
2237,
339,
347,
511,
63,
2861,
63,
739,
8,
277,
304,
267,
347,
1255,
837,
288,
299,
17,
275,
6924,
11867,
3498,
4590,
5234,
16408,
401,
3286,
2791,
15,
26795,
63,
396,
63,
4093,
4990,
14,
609,
3135,
288,
7055,
275,
413,
288,
367,
1004,
315,
299,
17,
26,
355,
291,
14,
629,
8,
604,
14,
2708,
360,
1624,
24,
659,
298,
24679,
450,
73,
5431,
60,
78,
2,
450,
7055,
9,
355,
7055,
847,
413,
288,
299,
17,
14,
1600,
342,
398,
291,
14,
1855,
8,
13281,
12,
1255,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
suranap/qiime
|
qiime/parallel/pick_otus.py
|
15
|
25920
|
#!/usr/bin/env python
# File created on 07 Jul 2012
from __future__ import division
__author__ = "Greg Caporaso"
__copyright__ = "Copyright 2011, The QIIME project"
__credits__ = ["Greg Caporaso", "Jens Reeder", "Jai Ram Rideout"]
__license__ = "GPL"
__version__ = "1.9.1-dev"
__maintainer__ = "Greg Caporaso"
__email__ = "gregcaporaso@gmail.com"
from math import ceil
from os.path import basename, join
from os import mkdir
from re import compile
from bfillings.formatdb import build_blast_db_from_fasta_path
from bfillings.sortmerna_v2 import build_database_sortmerna
from skbio.parse.sequences import parse_fasta
from qiime.parallel.util import ParallelWrapper, BufferedWriter
from qiime.parallel.poller import basic_process_run_results_f
class ParallelPickOtus(ParallelWrapper):
_script_name = "pick_otus.py"
_job_prefix = 'POTU'
_input_splitter = ParallelWrapper._split_fasta
_process_run_results_f =\
'qiime.parallel.pick_otus.parallel_pick_otus_process_run_results_f'
def _get_poller_command(self,
expected_files_filepath,
merge_map_filepath,
deletion_list_filepath,
command_prefix='/bin/bash; ',
command_suffix='; exit'):
"""Generate command to initiate a poller to monitior/process completed runs
"""
result = '%s poller.py -f %s -p %s -m %s -d %s -t %d %s' % \
(command_prefix,
expected_files_filepath,
self._process_run_results_f,
merge_map_filepath,
deletion_list_filepath,
self._seconds_to_sleep,
command_suffix)
return result, []
def _write_merge_map_file(self,
input_file_basename,
job_result_filepaths,
params,
output_dir,
merge_map_filepath):
"""
"""
f = open(merge_map_filepath, 'w')
otus_fps = []
log_fps = []
failures_fps = []
# determine if the otu picking method generates
# failures files
failures = False
for fp in job_result_filepaths:
if fp.endswith('_failures.txt'):
failures = True
break
if not failures:
out_filepaths = [
'%s/%s_otus.txt' % (output_dir, input_file_basename),
'%s/%s_otus.log' % (output_dir, input_file_basename)]
in_filepaths = [otus_fps, log_fps]
else:
out_filepaths = [
'%s/%s_otus.txt' % (output_dir, input_file_basename),
'%s/%s_otus.log' % (output_dir, input_file_basename),
'%s/%s_failures.txt' % (output_dir, input_file_basename)]
in_filepaths = [otus_fps, log_fps, failures_fps]
for fp in job_result_filepaths:
if fp.endswith('_otus.txt'):
otus_fps.append(fp)
elif fp.endswith('_otus.log'):
log_fps.append(fp)
elif fp.endswith('_failures.txt'):
failures_fps.append(fp)
else:
pass
for in_files, out_file in\
zip(in_filepaths, out_filepaths):
f.write('\t'.join(in_files + [out_file]))
f.write('\n')
f.close()
class ParallelPickOtusSortMeRNA(ParallelPickOtus):
""" Run pick_otus.py in parallel for SortMeRNA
"""
def _precommand_initiation(
self, input_fp, output_dir, working_dir, params):
if not params['sortmerna_db']:
# Build the sortmerna database from the reference_seqs_fp
sortmerna_db, db_files_to_remove = \
build_database_sortmerna(params['refseqs_fp'],
max_pos=params['sortmerna_max_pos'],
output_dir=working_dir)
self.files_to_remove += db_files_to_remove
params['sortmerna_db'] = sortmerna_db
def _get_job_commands(self,
fasta_fps,
output_dir,
params,
job_prefix,
working_dir,
command_prefix='/bin/bash; ',
command_suffix='; exit'):
"""Generate pick_otus commands which should be submitted to cluster
"""
# Create basenames for each of the output files. These will be filled
# in to create the full list of files created by all of the runs.
out_filenames = [job_prefix + '.%d_otus.log',
job_prefix + '.%d_otus.txt',
job_prefix + '.%d_failures.txt']
# Create lists to store the results
commands = []
result_filepaths = []
# Iterate over the input files
for i, fasta_fp in enumerate(fasta_fps):
# temporary working directory for sortmerna per job
working_dir_t = join(working_dir, "%d" % i)
mkdir(working_dir_t)
# Each run ends with moving the output file from the tmp dir to
# the output_dir. Build the command to perform the move here.
rename_command, current_result_filepaths = self._get_rename_command(
[fn % i for fn in out_filenames], working_dir_t, output_dir)
result_filepaths += current_result_filepaths
command = \
'%s %s -m sortmerna -i %s -r %s --sortmerna_db %s -o %s --sortmerna_e_value %s -s %s --threads %s %s %s' %\
(command_prefix,
self._script_name,
fasta_fp,
params['refseqs_fp'],
params['sortmerna_db'],
working_dir_t,
params['sortmerna_e_value'],
params['similarity'],
params['threads'],
rename_command,
command_suffix)
commands.append(command)
return commands, result_filepaths
class ParallelPickOtusUclustRef(ParallelPickOtus):
def _identify_files_to_remove(self, job_result_filepaths, params):
""" Select the files to remove: by default remove all files
"""
if params['save_uc_files']:
# keep any .uc files that get created
result =\
[fp for fp in job_result_filepaths if not fp.endswith('.uc')]
else:
result = [job_result_filepaths]
return result
def _get_job_commands(self,
fasta_fps,
output_dir,
params,
job_prefix,
working_dir,
command_prefix='/bin/bash; ',
command_suffix='; exit'):
"""Generate pick_otus commands which should be run
"""
# Create basenames for each of the output files. These will be filled
# in to create the full list of files created by all of the runs.
out_filenames = [job_prefix + '.%d_otus.log',
job_prefix + '.%d_otus.txt',
job_prefix + '.%s_failures.txt']
# Create lists to store the results
commands = []
result_filepaths = []
if params['enable_rev_strand_match']:
enable_rev_strand_match_str = '-z'
else:
enable_rev_strand_match_str = ''
if params['optimal_uclust']:
optimal_uclust_str = '-A'
else:
optimal_uclust_str = ''
if params['exact_uclust']:
exact_uclust_str = '-E'
else:
exact_uclust_str = ''
if params['stable_sort']:
stable_sort_str = ''
else:
stable_sort_str = '--suppress_uclust_stable_sort'
if params['save_uc_files']:
save_uc_files_str = ''
out_filenames += [job_prefix + '.%d_clusters.uc']
else:
save_uc_files_str = '-d'
# Iterate over the input files
for i, fasta_fp in enumerate(fasta_fps):
# Each run ends with moving the output file from the tmp dir to
# the output_dir. Build the command to perform the move here.
rename_command, current_result_filepaths = self._get_rename_command(
[fn % i for fn in out_filenames],
working_dir,
output_dir)
result_filepaths += current_result_filepaths
command = \
'%s %s -i %s -r %s -m uclust_ref --suppress_new_clusters -o %s -s %s %s %s %s --max_accepts %s --max_rejects %s --stepwords %d --w %d %s %s %s %s' %\
(command_prefix,
self._script_name,
fasta_fp,
params['refseqs_fp'],
working_dir,
params['similarity'],
enable_rev_strand_match_str,
optimal_uclust_str,
exact_uclust_str,
params['max_accepts'],
params['max_rejects'],
params['stepwords'],
params['word_length'],
stable_sort_str,
save_uc_files_str,
rename_command,
command_suffix)
commands.append(command)
return commands, result_filepaths
class ParallelPickOtusUsearch61Ref(ParallelPickOtus):
def _get_job_commands(self,
fasta_fps,
output_dir,
params,
job_prefix,
working_dir,
command_prefix='/bin/bash; ',
command_suffix='; exit'):
"""Generate pick_otus commands which should be run
"""
# Create basenames for each of the output files. These will be filled
# in to create the full list of files created by all of the runs.
out_filenames = [job_prefix + '.%d_otus.log',
job_prefix + '.%d_otus.txt',
job_prefix + '.%s_failures.txt']
# Create lists to store the results
commands = []
result_filepaths = []
# Generate the parameters to pass to pick_otus.py. This must exclude
# parameters that get passed only to the parallel version
# (e.g jobs_to_start) and values that get overwritten (e.g.,
# input_fasta_fp)
param_fields = []
ignored_params = set(["input_fasta_fp", "output_dir", "jobs_to_start",
"retain_temp_files", "suppress_submit_jobs", "poll_directly",
"cluster_jobs_fp", "suppress_polling", "job_prefix",
"seconds_to_sleep"])
for name, value in params.items():
if name in ignored_params or value == False:
pass
elif value == 'True':
param_fields.append('--%s' % name)
else:
param_fields.append('--%s %s' % (name, value))
params_str = ' '.join(param_fields)
# Iterate over the input files
for i, fasta_fp in enumerate(fasta_fps):
# Each run ends with moving the output file from the tmp dir to
# the output_dir. Build the command to perform the move here.
iteration_working_dir = join(working_dir, str(i))
rename_command, current_result_filepaths = self._get_rename_command(
[fn % i for fn in out_filenames],
iteration_working_dir,
output_dir)
result_filepaths += current_result_filepaths
command = \
'%s %s -i %s -m usearch61_ref --suppress_new_clusters -o %s %s %s %s' %\
(command_prefix,
self._script_name,
fasta_fp,
iteration_working_dir,
params_str,
rename_command,
command_suffix)
commands.append(command)
return commands, result_filepaths
class ParallelPickOtusBlast(ParallelPickOtus):
def _precommand_initiation(
self, input_fp, output_dir, working_dir, params):
if not params['blast_db']:
# Build the blast database from the reference_seqs_fp -- all procs
# will then access one db rather than create one per proc
blast_db, db_files_to_remove = \
build_blast_db_from_fasta_path(params['refseqs_fp'])
self.files_to_remove += db_files_to_remove
params['blast_db'] = blast_db
def _get_job_commands(self,
fasta_fps,
output_dir,
params,
job_prefix,
working_dir,
command_prefix='/bin/bash; ',
command_suffix='; exit'):
"""Generate pick_otus commands which should be submitted to cluster
"""
# Create basenames for each of the output files. These will be filled
# in to create the full list of files created by all of the runs.
out_filenames = [job_prefix + '.%d_otus.log',
job_prefix + '.%d_otus.txt']
# Create lists to store the results
commands = []
result_filepaths = []
# Iterate over the input files
for i, fasta_fp in enumerate(fasta_fps):
# Each run ends with moving the output file from the tmp dir to
# the output_dir. Build the command to perform the move here.
rename_command, current_result_filepaths = self._get_rename_command(
[fn % i for fn in out_filenames], working_dir, output_dir)
result_filepaths += current_result_filepaths
command = \
'%s %s -i %s -b %s -m blast -o %s -e %s -s %s --min_aligned_percent %s %s %s' %\
(command_prefix,
self._script_name,
fasta_fp,
params['blast_db'],
working_dir,
params['max_e_value'],
params['similarity'],
params['min_aligned_percent'],
rename_command,
command_suffix)
commands.append(command)
return commands, result_filepaths
def parallel_pick_otus_process_run_results_f(f):
""" Copy each list of infiles to each outfile and delete infiles
f: file containing one set of mapping instructions per line
example f:
f1.txt f2.txt f3.txt f_combined.txt
f1.log f2.log f3.log f_combined.log
f1_failures.txt f2_failures.txt f3_failures.txt f_failires.txt
If f contained the two lines above, this function would
concatenate f1.txt, f2.txt, and f3.txt into f_combined.txt
and f1.log, f2.log, and f3.log into f_combined.log
"""
lines = list(f)
# handle catting of log files and failure files
basic_process_run_results_f([lines[1]])
try:
basic_process_run_results_f([lines[2]])
basic_process_run_results_f([lines[3]])
except IndexError:
# no failures files or blast6 were generated (BLAST
# doesn't create these)
pass
# handle merging of otu maps
fields = lines[0].strip().split()
infiles_list = fields[:-1]
out_filepath = fields[-1]
try:
of = open(out_filepath, 'w')
except IOError:
raise IOError("Poller can't open final output file: %s" % out_filepath +
"\nLeaving individual jobs output.\n Do you have write access?")
unique_otu_map = {}
for fp in infiles_list:
for line in open(fp):
fields = line.strip().split()
try:
# current otu_id already exists, so append this
# set of seq_ids
unique_otu_map[fields[0]] += fields[1:]
except KeyError:
# current otu_id has not been seen yet, so
# create it with the current set of otus
unique_otu_map[fields[0]] = fields[1:]
for otu_id, seq_ids in unique_otu_map.items():
of.write('\t'.join([otu_id] + seq_ids))
of.write('\n')
of.close()
# It is a good idea to have your clean_up_callback return True.
# That way, if you get mixed up and pass it as check_run_complete_callback,
# you'll get an error right away rather than going into an infinite loop
return True
class ParallelPickOtusTrie(ParallelPickOtus):
"""Picking Otus using a trie the parallel way
We parallelize the Trie OTU picker using this scheme:
1. use the exact prefix filter with a short wordlength (say 5)
to sort all reads into buckets according to their first 5 nucs.
2. Run trie otupicker an each bucket separately, distribute over cluster
3. Combine mappings of 2, Since each bucket is independent fro the rest,
a simple cat with incrementing OTU ids should do it.
"""
_process_run_results_f =\
'qiime.parallel.pick_otus.parallel_pick_otus_trie_process_run_results_f'
def _call_initialization(self,
input_fp,
output_dir,
params,
job_prefix,
poll_directly,
suppress_submit_jobs):
""" Called as the first step in __call__.
"""
self.prefix_counts = {}
def _split_along_prefix(self,
input_fp,
params,
jobs_to_start,
job_prefix,
output_dir):
""" Split input sequences into sets with identical prefix"""
out_files = []
buffered_handles = {}
prefix_length = params['prefix_length'] or 1
for seq_id, seq in parse_fasta(open(input_fp)):
if(len(seq) < prefix_length):
raise ValueError("Prefix length must be equal or longer than sequence.\n"
+ " Found seq %s with length %d" % (seq_id, len(seq)))
prefix = seq[:prefix_length]
if (prefix not in buffered_handles):
# never seen this prefix before
out_fp = "%s/%s%s" % (output_dir, job_prefix, prefix)
buffered_handles[prefix] = BufferedWriter(out_fp)
out_files.append(out_fp)
self.prefix_counts[prefix] = 0
self.prefix_counts[prefix] += 1
buffered_handles[prefix].write('>%s\n%s\n' % (seq_id, seq))
# make sure all buffers are closed and flushed
for buf_fh in buffered_handles.itervalues():
buf_fh.close()
remove_files = True
return out_files, remove_files
_input_splitter = _split_along_prefix
def _get_job_commands(self,
fasta_fps,
output_dir,
params,
job_prefix,
working_dir,
command_prefix='/bin/bash; ',
command_suffix='; exit'):
"""Generate pick_otus commands which should be run
"""
# Create basenames for each of the output files. These will be filled
# in to create the full list of files created by all of the runs.
out_filenames = ['%s_otus.log',
'%s_otus.txt']
# Create lists to store the results
commands = {}
result_filepaths = []
# Iterate over the input files
for i, fasta_fp in enumerate(fasta_fps):
# Each run ends with moving the output file from the tmp dir to
# the output_dir. Build the command to perform the move here.
rename_command, current_result_filepaths = self._get_rename_command(
[fn % basename(fasta_fp) for fn in out_filenames],
working_dir,
output_dir)
result_filepaths += current_result_filepaths
command = \
'%s -i %s -m trie -o %s %s' %\
(self._script_name,
fasta_fp,
working_dir,
rename_command)
re = compile("POTU_\w+_(\w+)")
prefix = (re.search(fasta_fp)).group(1)
commands[prefix] = command
commands = self._merge_to_n_commands(commands,
params['jobs_to_start'],
command_prefix=command_prefix,
command_suffix=command_suffix)
return commands, result_filepaths
def _merge_to_n_commands(self,
commands,
n,
delimiter=' ; ',
command_prefix=None,
command_suffix=None):
""" merge a list of commands into n commands
Uses the size of each jobs to estimate an even distribution
of commands ofver the n jobs.
commands: dict of commands keyed by prefix
n: number of jobs
"""
if n < 1:
raise ValueError("number of commands (n) must be an integer >= 1")
# Distribute jobs according to their load
grouped_prefixe, levels = greedy_partition(self.prefix_counts, n)
# TODO: remove after profiling or maybe move to log file
# print levels
# print ("Maximal theoretical speed up: %f" % (sum(levels)/max(levels)))
result = []
# begin iterating through the commands
current_cmds = []
for bucket in grouped_prefixe:
for prefix in bucket:
command = commands[prefix]
subcommands = [c.strip() for c in command.split(';')]
current_cmds.append(delimiter.join(subcommands))
result.append(delimiter.join(current_cmds))
current_cmds = []
for i, r in enumerate(result):
r = '%s %s %s' % (command_prefix, r, command_suffix)
result[i] = r.strip()
return result
def parallel_pick_otus_trie_process_run_results_f(f):
""" Copy each list of infiles to each outfile and delete infiles
f: file containing one set of mapping instructions per line
example f:
f1.txt f2.txt f3.txt f_combined.txt
f1.log f2.log f3.log f_combined.log
f1_failures.txt f2_failures.txt f3_failures.txt f_failires.txt
If f contained the two lines above, this function would
concatenate f1.txt, f2.txt, and f3.txt into f_combined.txt
and f1.log, f2.log, and f3.log into f_combined.log
Note: this is mostly copied from
parallel_pick_otus_process_run_results_f
The only difference is the way how otu_maps are combined.
Since each otu_map for the parallel trie otu pickers yields disjoint
sets, we have to make the otu_ids disjoint as well.
"""
lines = list(f)
# handle catting of log files and failure files
basic_process_run_results_f([lines[1]])
try:
basic_process_run_results_f([lines[2]])
basic_process_run_results_f([lines[3]])
except IndexError:
# no failures files or blast6 were generated (BLAST
# doesn't create these)
pass
# handle merging of otu maps
fields = lines[0].strip().split()
infiles_list = fields[:-1]
out_filepath = fields[-1]
try:
of = open(out_filepath, 'w')
except IOError:
raise IOError("Poller can't open final output file: %s" % out_filepath +
"\nLeaving individual jobs output.\n Do you have write access?")
unique_otu_map = {}
otu_id = 0
for fp in infiles_list:
for line in open(fp):
fields = line.strip().split()
of.write('\t'.join(["%d" % otu_id] + fields[1:]))
of.write('\n')
otu_id += 1
of.close()
# It is a good idea to have your clean_up_callback return True.
# That way, if you get mixed up and pass it as check_run_complete_callback,
# you'll get an error right away rather than going into an infinite loop
return True
def greedy_partition(counts, n):
"""Distribute k counts evenly across n buckets,
counts: dict of key, counts pairs
n: number of buckets that the counts should be distributed over
"""
buckets = [[] for i in range(n)]
fill_levels = [0 for i in range(n)]
for key in sorted(counts, reverse=True,
key=lambda c: counts[c]):
smallest = fill_levels.index(min(fill_levels))
buckets[smallest].append(key)
fill_levels[smallest] += counts[key]
return buckets, fill_levels
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
3814,
2737,
641,
24937,
1603,
348,
6029,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
363,
2502,
363,
275,
298,
39,
1135,
22516,
269,
305,
79,
2,
199,
363,
7307,
363,
275,
298,
7384,
7760,
12,
710,
1413,
41,
3465,
2199,
2,
199,
363,
22461,
363,
275,
2097,
39,
1135,
22516,
269,
305,
79,
401,
298,
42,
8764,
799,
69,
424,
401,
298,
42,
5789,
820,
455,
820,
2655,
548,
937,
199,
363,
1682,
363,
275,
298,
12006,
2,
199,
363,
1023,
363,
275,
298,
17,
14,
25,
14,
17,
13,
2374,
2,
199,
363,
26665,
363,
275,
298,
39,
1135,
22516,
269,
305,
79,
2,
199,
363,
2123,
363,
275,
298,
3939,
2874,
269,
305,
79,
32,
6799,
14,
957,
2,
199,
199,
504,
3473,
492,
30449,
199,
504,
747,
14,
515,
492,
9593,
12,
4263,
199,
504,
747,
492,
20366,
199,
504,
295,
492,
6555,
199,
199,
504,
330,
4498,
780,
14,
908,
697,
492,
1900,
63,
66,
2019,
63,
697,
63,
504,
63,
20309,
63,
515,
199,
504,
330,
4498,
780,
14,
3191,
2626,
3540,
63,
86,
18,
492,
1900,
63,
4659,
63,
3191,
2626,
3540,
199,
199,
504,
11448,
2308,
14,
1122,
14,
13436,
492,
2198,
63,
20309,
199,
199,
504,
31402,
1036,
14,
11887,
14,
1974,
492,
27311,
4590,
12,
26832,
6261,
199,
504,
31402,
1036,
14,
11887,
14,
26746,
492,
5678,
63,
1412,
63,
1065,
63,
2604,
63,
70,
421,
199,
533,
27311,
8587,
47,
84,
527,
8,
25721,
4590,
304,
272,
485,
1579,
63,
354,
275,
298,
4510,
63,
357,
527,
14,
647,
2,
272,
485,
2423,
63,
1861,
275,
283,
48,
1387,
53,
7,
272,
485,
1210,
63,
25234,
275,
27311,
4590,
423,
1294,
63,
20309,
272,
485,
1412,
63,
1065,
63,
2604,
63,
70,
26447,
267,
283,
23104,
1036,
14,
11887,
14,
4510,
63,
357,
527,
14,
11887,
63,
4510,
63,
357,
527,
63,
1412,
63,
1065,
63,
2604,
63,
70,
7,
339,
347,
485,
362,
63,
26746,
63,
1531,
8,
277,
12,
1169,
1420,
63,
1725,
63,
7218,
12,
1169,
5389,
63,
1130,
63,
7218,
12,
1169,
14068,
63,
513,
63,
7218,
12,
1169,
1414,
63,
1861,
8805,
1393,
15,
16408,
27,
1656,
1169,
1414,
63,
4511,
534,
27,
4458,
735,
267,
408,
6864,
1414,
370,
11023,
323,
282,
28073,
370,
3485,
5277,
269,
15,
1412,
9709,
7858,
267,
408,
398,
754,
275,
1543,
83,
28073,
14,
647,
446,
70,
450,
83,
446,
80,
450,
83,
446,
77,
450,
83,
446,
68,
450,
83,
446,
84,
450,
68,
450,
83,
7,
450,
971,
288,
334,
1531,
63,
1861,
12,
1467,
1420,
63,
1725,
63,
7218,
12,
1467,
291,
423,
1412,
63,
1065,
63,
2604,
63,
70,
12,
1467,
5389,
63,
1130,
63,
7218,
12,
1467,
14068,
63,
513,
63,
7218,
12,
1467,
291,
423,
4515,
63,
475,
63,
4532,
12,
1467,
1414,
63,
4511,
9,
398,
372,
754,
12,
942,
339,
347,
485,
952,
63,
5628,
63,
1130,
63,
493,
8,
277,
12,
2892,
1324,
63,
493,
63,
4846,
12,
2892,
3906,
63,
1099,
63,
493,
3771,
12,
2892,
1862,
12,
2892,
1072,
63,
694,
12,
2892,
5389,
63,
1130,
63,
7218,
304,
267,
408,
267,
408,
267,
289,
275,
1551,
8,
5628,
63,
1130,
63,
7218,
12,
283,
87,
358,
398,
312,
84,
527,
63,
24709,
275,
942,
267,
943,
63,
24709,
275,
942,
267,
9081,
63,
24709,
275,
942,
398,
327,
6705,
340,
314,
312,
10963,
12433,
1083,
12821,
267,
327,
9081,
1584,
267,
9081,
275,
756,
267,
367,
4090,
315,
3906,
63,
1099,
63,
493,
3771,
26,
288,
340,
4090,
14,
4130,
6412,
9968,
14,
2424,
735,
355,
9081,
275,
715,
355,
2059,
398,
340,
440,
9081,
26,
288,
734,
63,
493,
3771,
275,
359,
355,
1543,
83,
3149,
83,
63,
357,
527,
14,
2424,
7,
450,
334,
1199,
63,
694,
12,
1324,
63,
493,
63,
4846,
395,
355,
1543,
83,
3149,
83,
63,
357,
527,
14,
793,
7,
450,
334,
1199,
63,
694,
12,
1324,
63,
493,
63,
4846,
1874,
288,
315,
63,
493,
3771,
275,
359,
357,
527,
63,
24709,
12,
943,
63,
24709,
61,
267,
587,
26,
288,
734,
63,
493,
3771,
275,
359,
355,
1543,
83,
3149,
83,
63,
357,
527,
14,
2424,
7,
450,
334,
1199,
63,
694,
12,
1324,
63,
493,
63,
4846,
395,
355,
1543,
83,
3149,
83,
63,
357,
527,
14,
793,
7,
450,
334,
1199,
63,
694,
12,
1324,
63,
493,
63,
4846,
395,
355,
1543,
83,
3149,
83,
63,
9968,
14,
2424,
7,
450,
334,
1199,
63,
694,
12,
1324,
63,
493,
63,
4846,
1874,
288,
315,
63,
493,
3771,
275,
359,
357,
527,
63,
24709,
12,
943,
63,
24709,
12,
9081,
63,
24709,
61,
398,
367,
4090,
315,
3906,
63,
1099,
63,
493,
3771,
26,
288,
340,
4090,
14,
4130,
6412,
357,
527,
14,
2424,
735,
355,
312,
84,
527,
63,
24709,
14,
740,
8,
3997,
9,
288,
916,
4090,
14,
4130,
6412,
357,
527,
14,
793,
735,
355,
943,
63,
24709,
14,
740,
8,
3997,
9,
288,
916,
4090,
14,
4130,
6412,
9968,
14,
2424,
735,
355,
9081,
63,
24709,
14,
740,
8,
3997,
9,
288,
587,
26,
355,
986,
398,
367,
315,
63,
1725,
12,
734,
63,
493,
315,
60,
355,
3482,
8,
262,
63,
493,
3771,
12,
734,
63,
493,
3771,
304,
288,
289,
14,
952,
2258,
84,
1370,
904,
8,
262,
63,
1725,
435,
359,
548,
63,
493,
2459,
288,
289,
14,
952,
2258,
78,
358,
267,
289,
14,
1600,
342,
421,
199,
533,
27311,
8587,
47,
84,
527,
14376,
1352,
25179,
8,
25721,
8587,
47,
84,
527,
304,
272,
408,
3378,
3732,
63,
357,
527,
14,
647,
315,
9861,
367,
16722,
1352,
25179,
272,
408,
339,
347,
485,
657,
1531,
63,
14188,
425,
8,
288,
291,
12,
1324,
63,
3997,
12,
1072,
63,
694,
12,
6449,
63,
694,
12,
1862,
304,
267,
340,
440,
1862,
459,
3191,
2626,
3540,
63,
697,
2565,
288,
327,
6516,
314,
4069,
2626,
3540,
3050,
687,
314,
3659,
63,
19467,
63,
3997,
288,
4069,
2626,
3540,
63,
697,
12,
1592,
63,
1725,
63,
475,
63,
2168,
275,
971,
355,
1900
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
3814,
2737,
641,
24937,
1603,
348,
6029,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
363,
2502,
363,
275,
298,
39,
1135,
22516,
269,
305,
79,
2,
199,
363,
7307,
363,
275,
298,
7384,
7760,
12,
710,
1413,
41,
3465,
2199,
2,
199,
363,
22461,
363,
275,
2097,
39,
1135,
22516,
269,
305,
79,
401,
298,
42,
8764,
799,
69,
424,
401,
298,
42,
5789,
820,
455,
820,
2655,
548,
937,
199,
363,
1682,
363,
275,
298,
12006,
2,
199,
363,
1023,
363,
275,
298,
17,
14,
25,
14,
17,
13,
2374,
2,
199,
363,
26665,
363,
275,
298,
39,
1135,
22516,
269,
305,
79,
2,
199,
363,
2123,
363,
275,
298,
3939,
2874,
269,
305,
79,
32,
6799,
14,
957,
2,
199,
199,
504,
3473,
492,
30449,
199,
504,
747,
14,
515,
492,
9593,
12,
4263,
199,
504,
747,
492,
20366,
199,
504,
295,
492,
6555,
199,
199,
504,
330,
4498,
780,
14,
908,
697,
492,
1900,
63,
66,
2019,
63,
697,
63,
504,
63,
20309,
63,
515,
199,
504,
330,
4498,
780,
14,
3191,
2626,
3540,
63,
86,
18,
492,
1900,
63,
4659,
63,
3191,
2626,
3540,
199,
199,
504,
11448,
2308,
14,
1122,
14,
13436,
492,
2198,
63,
20309,
199,
199,
504,
31402,
1036,
14,
11887,
14,
1974,
492,
27311,
4590,
12,
26832,
6261,
199,
504,
31402,
1036,
14,
11887,
14,
26746,
492,
5678,
63,
1412,
63,
1065,
63,
2604,
63,
70,
421,
199,
533,
27311,
8587,
47,
84,
527,
8,
25721,
4590,
304,
272,
485,
1579,
63,
354,
275,
298,
4510,
63,
357,
527,
14,
647,
2,
272,
485,
2423,
63,
1861,
275,
283,
48,
1387,
53,
7,
272,
485,
1210,
63,
25234,
275,
27311,
4590,
423,
1294,
63,
20309,
272,
485,
1412,
63,
1065,
63,
2604,
63,
70,
26447,
267,
283,
23104,
1036,
14,
11887,
14,
4510,
63,
357,
527,
14,
11887,
63,
4510,
63,
357,
527,
63,
1412,
63,
1065,
63,
2604,
63,
70,
7,
339,
347,
485,
362,
63,
26746,
63,
1531,
8,
277,
12,
1169,
1420,
63,
1725,
63,
7218,
12,
1169,
5389,
63,
1130,
63,
7218,
12,
1169,
14068,
63,
513,
63,
7218,
12,
1169,
1414,
63,
1861,
8805,
1393,
15,
16408,
27,
1656,
1169,
1414,
63,
4511,
534,
27,
4458,
735,
267,
408,
6864,
1414,
370,
11023,
323,
282,
28073,
370,
3485,
5277,
269,
15,
1412,
9709,
7858,
267,
408,
398,
754,
275,
1543,
83,
28073,
14,
647,
446,
70,
450,
83,
446,
80,
450,
83,
446,
77,
450,
83,
446,
68,
450,
83,
446,
84,
450,
68,
450,
83,
7,
450,
971,
288,
334,
1531,
63,
1861,
12,
1467,
1420,
63,
1725,
63,
7218,
12,
1467,
291,
423,
1412,
63,
1065,
63,
2604,
63,
70,
12,
1467,
5389,
63,
1130,
63,
7218,
12,
1467,
14068,
63,
513,
63,
7218,
12,
1467,
291,
423,
4515,
63,
475,
63,
4532,
12,
1467,
1414,
63,
4511,
9,
398,
372,
754,
12,
942,
339,
347,
485,
952,
63,
5628,
63,
1130,
63,
493,
8,
277,
12,
2892,
1324,
63,
493,
63,
4846,
12,
2892,
3906,
63,
1099,
63,
493,
3771,
12,
2892,
1862,
12,
2892,
1072,
63,
694,
12,
2892,
5389,
63,
1130,
63,
7218,
304,
267,
408,
267,
408,
267,
289,
275,
1551,
8,
5628,
63,
1130,
63,
7218,
12,
283,
87,
358,
398,
312,
84,
527,
63,
24709,
275,
942,
267,
943,
63,
24709,
275,
942,
267,
9081,
63,
24709,
275,
942,
398,
327,
6705,
340,
314,
312,
10963,
12433,
1083,
12821,
267,
327,
9081,
1584,
267,
9081,
275,
756,
267,
367,
4090,
315,
3906,
63,
1099,
63,
493,
3771,
26,
288,
340,
4090,
14,
4130,
6412,
9968,
14,
2424,
735,
355,
9081,
275,
715,
355,
2059,
398,
340,
440,
9081,
26,
288,
734,
63,
493,
3771,
275,
359,
355,
1543,
83,
3149,
83,
63,
357,
527,
14,
2424,
7,
450,
334,
1199,
63,
694,
12,
1324,
63,
493,
63,
4846,
395,
355,
1543,
83,
3149,
83,
63,
357,
527,
14,
793,
7,
450,
334,
1199,
63,
694,
12,
1324,
63,
493,
63,
4846,
1874,
288,
315,
63,
493,
3771,
275,
359,
357,
527,
63,
24709,
12,
943,
63,
24709,
61,
267,
587,
26,
288,
734,
63,
493,
3771,
275,
359,
355,
1543,
83,
3149,
83,
63,
357,
527,
14,
2424,
7,
450,
334,
1199,
63,
694,
12,
1324,
63,
493,
63,
4846,
395,
355,
1543,
83,
3149,
83,
63,
357,
527,
14,
793,
7,
450,
334,
1199,
63,
694,
12,
1324,
63,
493,
63,
4846,
395,
355,
1543,
83,
3149,
83,
63,
9968,
14,
2424,
7,
450,
334,
1199,
63,
694,
12,
1324,
63,
493,
63,
4846,
1874,
288,
315,
63,
493,
3771,
275,
359,
357,
527,
63,
24709,
12,
943,
63,
24709,
12,
9081,
63,
24709,
61,
398,
367,
4090,
315,
3906,
63,
1099,
63,
493,
3771,
26,
288,
340,
4090,
14,
4130,
6412,
357,
527,
14,
2424,
735,
355,
312,
84,
527,
63,
24709,
14,
740,
8,
3997,
9,
288,
916,
4090,
14,
4130,
6412,
357,
527,
14,
793,
735,
355,
943,
63,
24709,
14,
740,
8,
3997,
9,
288,
916,
4090,
14,
4130,
6412,
9968,
14,
2424,
735,
355,
9081,
63,
24709,
14,
740,
8,
3997,
9,
288,
587,
26,
355,
986,
398,
367,
315,
63,
1725,
12,
734,
63,
493,
315,
60,
355,
3482,
8,
262,
63,
493,
3771,
12,
734,
63,
493,
3771,
304,
288,
289,
14,
952,
2258,
84,
1370,
904,
8,
262,
63,
1725,
435,
359,
548,
63,
493,
2459,
288,
289,
14,
952,
2258,
78,
358,
267,
289,
14,
1600,
342,
421,
199,
533,
27311,
8587,
47,
84,
527,
14376,
1352,
25179,
8,
25721,
8587,
47,
84,
527,
304,
272,
408,
3378,
3732,
63,
357,
527,
14,
647,
315,
9861,
367,
16722,
1352,
25179,
272,
408,
339,
347,
485,
657,
1531,
63,
14188,
425,
8,
288,
291,
12,
1324,
63,
3997,
12,
1072,
63,
694,
12,
6449,
63,
694,
12,
1862,
304,
267,
340,
440,
1862,
459,
3191,
2626,
3540,
63,
697,
2565,
288,
327,
6516,
314,
4069,
2626,
3540,
3050,
687,
314,
3659,
63,
19467,
63,
3997,
288,
4069,
2626,
3540,
63,
697,
12,
1592,
63,
1725,
63,
475,
63,
2168,
275,
971,
355,
1900,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
chouseknecht/ansible
|
lib/ansible/plugins/doc_fragments/oneview.py
|
43
|
2374
|
# -*- coding: utf-8 -*-
#
# Copyright: (c) 2016-2017, Hewlett Packard Enterprise Development LP
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
class ModuleDocFragment(object):
# OneView doc fragment
DOCUMENTATION = r'''
options:
config:
description:
- Path to a .json configuration file containing the OneView client configuration.
The configuration file is optional and when used should be present in the host running the ansible commands.
If the file path is not provided, the configuration will be loaded from environment variables.
For links to example configuration files or how to use the environment variables verify the notes section.
type: path
requirements:
- python >= 2.7.9
notes:
- "A sample configuration file for the config parameter can be found at:
U(https://github.com/HewlettPackard/oneview-ansible/blob/master/examples/oneview_config-rename.json)"
- "Check how to use environment variables for configuration at:
U(https://github.com/HewlettPackard/oneview-ansible#environment-variables)"
- "Additional Playbooks for the HPE OneView Ansible modules can be found at:
U(https://github.com/HewlettPackard/oneview-ansible/tree/master/examples)"
- "The OneView API version used will directly affect returned and expected fields in resources.
Information on setting the desired API version and can be found at:
U(https://github.com/HewlettPackard/oneview-ansible#setting-your-oneview-version)"
'''
VALIDATEETAG = r'''
options:
validate_etag:
description:
- When the ETag Validation is enabled, the request will be conditionally processed only if the current ETag
for the resource matches the ETag provided in the data.
type: bool
default: yes
'''
FACTSPARAMS = r'''
options:
params:
description:
- List of params to delimit, filter and sort the list of resources.
- "params allowed:
- C(start): The first item to return, using 0-based indexing.
- C(count): The number of resources to return.
- C(filter): A general filter/query string to narrow the list of items returned.
- C(sort): The sort order of the returned data set."
type: dict
'''
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
26,
334,
67,
9,
7800,
13,
10680,
12,
27849,
9954,
1005,
29949,
15290,
21738,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
421,
199,
533,
5673,
3768,
11080,
8,
785,
304,
339,
327,
7309,
2768,
1382,
7956,
272,
29970,
2594,
275,
519,
2344,
199,
1419,
26,
272,
1101,
26,
489,
1369,
26,
267,
446,
6912,
370,
282,
1275,
1001,
2897,
570,
3035,
314,
7309,
2768,
1890,
2897,
14,
881,
710,
2897,
570,
365,
2716,
436,
1380,
1202,
1077,
506,
3451,
315,
314,
1591,
3879,
314,
3242,
3718,
14,
881,
982,
314,
570,
931,
365,
440,
2741,
12,
314,
2897,
911,
506,
6511,
687,
3734,
2860,
14,
881,
2104,
6220,
370,
2893,
2897,
1584,
503,
4212,
370,
675,
314,
3734,
2860,
4911,
314,
12681,
3420,
14,
489,
730,
26,
931,
199,
199,
7538,
26,
523,
446,
2366,
2356,
499,
14,
23,
14,
25,
199,
199,
5983,
26,
272,
446,
298,
33,
2690,
2897,
570,
367,
314,
1101,
2725,
883,
506,
1911,
737,
26,
2126,
738,
8,
2859,
921,
5031,
14,
957,
15,
40,
26911,
29471,
15,
368,
1345,
13,
4853,
15,
6582,
15,
4133,
15,
8589,
15,
368,
1345,
63,
888,
13,
8165,
14,
1001,
2924,
272,
446,
298,
1799,
4212,
370,
675,
3734,
2860,
367,
2897,
737,
26,
2126,
738,
8,
2859,
921,
5031,
14,
957,
15,
40,
26911,
29471,
15,
368,
1345,
13,
4853,
3,
5418,
13,
3669,
2924,
272,
446,
298,
8824,
16527,
8858,
367,
314,
869,
1510,
7309,
2768,
2622,
4621,
883,
506,
1911,
737,
26,
2126,
738,
8,
2859,
921,
5031,
14,
957,
15,
40,
26911,
29471,
15,
368,
1345,
13,
4853,
15,
2350,
15,
4133,
15,
8589,
2924,
272,
446,
298,
1918,
7309,
2768,
3261,
1015,
1202,
911,
5370,
12787,
2138,
436,
1420,
1504,
315,
5944,
14,
2126,
17064,
641,
4260,
314,
6387,
3261,
1015,
436,
883,
506,
1911,
737,
26,
2126,
738,
8,
2859,
921,
5031,
14,
957,
15,
40,
26911,
29471,
15,
368,
1345,
13,
4853,
3,
6031,
13,
12695,
13,
368,
1345,
13,
1023,
2924,
272,
1449,
339,
22049,
1951,
775,
1254,
275,
519,
2344,
199,
1419,
26,
272,
4107,
63,
11304,
26,
267,
1369,
26,
288,
446,
3979,
314,
662,
1931,
19381,
365,
5223,
12,
314,
1056,
911,
506,
5558,
1183,
7686,
1454,
340,
314,
1453,
662,
1931,
355,
367,
314,
2073,
4450,
314,
662,
1931,
2741,
315,
314,
666,
14,
267,
730,
26,
2155,
267,
849,
26,
9456,
199,
2344,
339,
481,
3036,
51,
17978,
275,
519,
2344,
199,
1419,
26,
272,
1862,
26,
267,
1369,
26,
267,
446,
3820,
402,
1862,
370,
477,
3097,
12,
2457,
436,
4069,
314,
769,
402,
5944,
14,
267,
446,
298,
1162,
4370,
26,
288,
446,
445,
8,
928,
304,
710,
1642,
1242,
370,
372,
12,
1808,
378,
13,
6788,
16356,
14,
288,
446,
445,
8,
835,
304,
710,
1329,
402,
5944,
370,
372,
14,
288,
446,
445,
8,
1541,
304,
437,
8605,
2457,
15,
1131,
1059,
370,
31530,
314,
769,
402,
2974,
2138,
14,
288,
446,
445,
8,
3191,
304,
710,
4069,
1865,
402,
314,
2138,
666,
663,
2122,
267,
730,
26,
1211,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
26,
334,
67,
9,
7800,
13,
10680,
12,
27849,
9954,
1005,
29949,
15290,
21738,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
421,
199,
533,
5673,
3768,
11080,
8,
785,
304,
339,
327,
7309,
2768,
1382,
7956,
272,
29970,
2594,
275,
519,
2344,
199,
1419,
26,
272,
1101,
26,
489,
1369,
26,
267,
446,
6912,
370,
282,
1275,
1001,
2897,
570,
3035,
314,
7309,
2768,
1890,
2897,
14,
881,
710,
2897,
570,
365,
2716,
436,
1380,
1202,
1077,
506,
3451,
315,
314,
1591,
3879,
314,
3242,
3718,
14,
881,
982,
314,
570,
931,
365,
440,
2741,
12,
314,
2897,
911,
506,
6511,
687,
3734,
2860,
14,
881,
2104,
6220,
370,
2893,
2897,
1584,
503,
4212,
370,
675,
314,
3734,
2860,
4911,
314,
12681,
3420,
14,
489,
730,
26,
931,
199,
199,
7538,
26,
523,
446,
2366,
2356,
499,
14,
23,
14,
25,
199,
199,
5983,
26,
272,
446,
298,
33,
2690,
2897,
570,
367,
314,
1101,
2725,
883,
506,
1911,
737,
26,
2126,
738,
8,
2859,
921,
5031,
14,
957,
15,
40,
26911,
29471,
15,
368,
1345,
13,
4853,
15,
6582,
15,
4133,
15,
8589,
15,
368,
1345,
63,
888,
13,
8165,
14,
1001,
2924,
272,
446,
298,
1799,
4212,
370,
675,
3734,
2860,
367,
2897,
737,
26,
2126,
738,
8,
2859,
921,
5031,
14,
957,
15,
40,
26911,
29471,
15,
368,
1345,
13,
4853,
3,
5418,
13,
3669,
2924,
272,
446,
298,
8824,
16527,
8858,
367,
314,
869,
1510,
7309,
2768,
2622,
4621,
883,
506,
1911,
737,
26,
2126,
738,
8,
2859,
921,
5031,
14,
957,
15,
40,
26911,
29471,
15,
368,
1345,
13,
4853,
15,
2350,
15,
4133,
15,
8589,
2924,
272,
446,
298,
1918,
7309,
2768,
3261,
1015,
1202,
911,
5370,
12787,
2138,
436,
1420,
1504,
315,
5944,
14,
2126,
17064,
641,
4260,
314,
6387,
3261,
1015,
436,
883,
506,
1911,
737,
26,
2126,
738,
8,
2859,
921,
5031,
14,
957,
15,
40,
26911,
29471,
15,
368,
1345,
13,
4853,
3,
6031,
13,
12695,
13,
368,
1345,
13,
1023,
2924,
272,
1449,
339,
22049,
1951,
775,
1254,
275,
519,
2344,
199,
1419,
26,
272,
4107,
63,
11304,
26,
267,
1369,
26,
288,
446,
3979,
314,
662,
1931,
19381,
365,
5223,
12,
314,
1056,
911,
506,
5558,
1183,
7686,
1454,
340,
314,
1453,
662,
1931,
355,
367,
314,
2073,
4450,
314,
662,
1931,
2741,
315,
314,
666,
14,
267,
730,
26,
2155,
267,
849,
26,
9456,
199,
2344,
339,
481,
3036,
51,
17978,
275,
519,
2344,
199,
1419,
26,
272,
1862,
26,
267,
1369,
26,
267,
446,
3820,
402,
1862,
370,
477,
3097,
12,
2457,
436,
4069,
314,
769,
402,
5944,
14,
267,
446,
298,
1162,
4370,
26,
288,
446,
445,
8,
928,
304,
710,
1642,
1242,
370,
372,
12,
1808,
378,
13,
6788,
16356,
14,
288,
446,
445,
8,
835,
304,
710,
1329,
402,
5944,
370,
372,
14,
288,
446,
445,
8,
1541,
304,
437,
8605,
2457,
15,
1131,
1059,
370,
31530,
314,
769,
402,
2974,
2138,
14,
288,
446,
445,
8,
3191,
304,
710,
4069,
1865,
402,
314,
2138,
666,
663,
2122,
267,
730,
26,
1211,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
total-impact/total-impact-core
|
extras/db_housekeeping/migrate_user_docs.py
|
2
|
5507
|
import couchdb, os, logging, sys, collections
from pprint import pprint
import time
import requests
import copy
import random
import datetime
from werkzeug.security import generate_password_hash
from totalimpact import dao
import psycopg2
# run in heroku by a) commiting, b) pushing to heroku, and c) running
# heroku run python extras/db_housekeeping/migrate_user_docs.py
logging.basicConfig(
stream=sys.stdout,
level=logging.DEBUG,
format='[%(process)d] %(levelname)8s %(threadName)30s %(name)s - %(message)s'
)
logger = logging.getLogger("merge_collections")
# set up couchdb
cloudant_db = os.getenv("CLOUDANT_DB")
cloudant_url = os.getenv("CLOUDANT_URL")
couch = couchdb.Server(url=cloudant_url)
db = couch[cloudant_db]
logger.info("connected to couch at " + cloudant_url + " / " + cloudant_db)
# set up postgres
mypostgresdao = dao.PostgresDao(os.environ["POSTGRESQL_URL"])
cur = mypostgresdao.get_cursor()
logger.info("connected to postgres")
default_password = "welcome"
default_password_hash = generate_password_hash(default_password)
def insert_unless_error(select_statement, save_list):
#print "try to insert"
#cur.executemany(select_statement, save_list)
for l in save_list:
print cur.mogrify(select_statement, l)
try:
#cur.execute(select_statement, l)
pass
except psycopg2.IntegrityError:
print "insert already exists"
def insert_string(tablename, colnames):
colnames_string = ", ".join(colnames)
percent_colnames_string = ", ".join(["%("+col+")s" for col in colnames])
insert = "INSERT INTO {tablename} ({colnames_string}) VALUES ({percent_colnames_string});\t".format(
tablename=tablename,
colnames_string=colnames_string,
percent_colnames_string=percent_colnames_string)
return insert
def merge_collections_for_profile():
from totalimpact import item, tiredis
view_name = "queues/by_type_and_id"
view_rows = db.view(view_name, include_docs=True)
row_count = 0
sql_statement_count = 0
page_size = 500
start_key = ["user", "00000000000"]
end_key = ["user", "zzzzzzzzz"]
from couch_paginator import CouchPaginator
page = CouchPaginator(db, view_name, page_size, include_docs=True, start_key=start_key, end_key=end_key)
email_data_strings = []
while page:
for row in page:
row_count += 1
user_doc = row.doc
rowdata = {}
rowdata["email"] = user_doc["_id"]
if not user_doc["profile_collection"]:
#print "not migrating this doc because it has no collections"
continue
rowdata["collection_id"] = user_doc["profile_collection"]
try:
rowdata["created"] = user_doc["created"]
except KeyError:
rowdata["created"] = datetime.datetime(2013, 1, 1).isoformat()
rowdata["password_hash"] = default_password_hash
rowdata["url_slug"] = "user" + str(50000 + row_count)
rowdata["given_name"] = "Firstname"
rowdata["surname"] = "Lastname"
insert_unless_error(insert_string('"user"', rowdata.keys()), [rowdata])
sql_statement_count += 1
# pull information together to send out surveymonkey email
profile_id = user_doc["profile_collection"]
email = user_doc["_id"]
profile_doc = db.get(profile_id)
my_collections = user_doc["colls"]
title = profile_doc["title"]
if (len(my_collections) > 1):
title = ""
for cid in my_collections:
coll_doc = db.get(cid)
collection_title = coll_doc["title"]
if collection_title != "My Collection":
title += "*" + collection_title
try:
collections_string = str(";".join(my_collections.keys()))
except UnicodeEncodeError:
print "UnicodeEncodeError on ", email, "so setting collections to blank"
collections_string = ""
email_data_strings += [u"{url_slug}|{profile_id}|{len_profile}|{email}|{created}|{title}|{collections_string}".format(
url_slug=rowdata["url_slug"],
profile_id=profile_id,
email=email,
len_profile=len(profile_doc["alias_tiids"]),
created=rowdata["created"],
title=title,
collections_string=collections_string)]
logger.info("%i. getting new page, last id was %s" %(row_count, row.id))
if page.has_next:
page = CouchPaginator(db, view_name, page_size, start_key=page.next, end_key=end_key, include_docs=True)
else:
page = None
print "Number of rows: ", row_count
print "Number of sql statements: ", sql_statement_count
print "\n\n\n"
for line in email_data_strings:
print line
if (cloudant_db == "ti"):
print "\n\nTHIS MAY BE THE PRODUCTION DATABASE!!!"
else:
print "\n\nThis doesn't appear to be the production database"
# remove check so can pipe output to a file: this script does not change the db so it is safe!
# confirm = None
# confirm = raw_input("\nType YES if you are sure you want to run this test:")
##if confirm=="YES":
### call the function here
merge_collections_for_profile()
#else:
# print "nevermind, then."
|
mit
|
[
646,
28877,
697,
12,
747,
12,
2050,
12,
984,
12,
5055,
199,
504,
10933,
492,
10933,
199,
646,
900,
199,
646,
4145,
199,
646,
1331,
199,
646,
2196,
199,
646,
2197,
199,
504,
10380,
14,
4416,
492,
3550,
63,
2060,
63,
2227,
199,
199,
504,
3141,
31822,
492,
32265,
199,
646,
15492,
18,
199,
199,
3,
1255,
315,
14737,
745,
85,
701,
282,
9,
5532,
316,
12,
330,
9,
6675,
316,
370,
14737,
745,
85,
12,
436,
286,
9,
3879,
199,
3,
14737,
745,
85,
1255,
2366,
13751,
15,
697,
63,
6740,
3250,
316,
15,
8462,
63,
751,
63,
4757,
14,
647,
199,
199,
4806,
14,
19602,
8,
272,
2547,
29,
1274,
14,
2703,
12,
272,
2166,
29,
4806,
14,
5287,
12,
272,
1475,
30845,
2840,
1412,
9,
68,
61,
2818,
20056,
9,
24,
83,
2818,
2671,
985,
9,
1216,
83,
2818,
354,
9,
83,
446,
2818,
1188,
9,
83,
7,
199,
9,
199,
199,
2921,
275,
2050,
14,
5572,
480,
5628,
63,
7882,
531,
523,
199,
3,
663,
1536,
28877,
697,
199,
4091,
867,
63,
697,
275,
747,
14,
12959,
480,
29495,
1441,
63,
2846,
531,
199,
4091,
867,
63,
633,
275,
747,
14,
12959,
480,
29495,
1441,
63,
2632,
531,
199,
331,
2133,
275,
28877,
697,
14,
3120,
8,
633,
29,
4091,
867,
63,
633,
9,
199,
697,
275,
28877,
59,
4091,
867,
63,
697,
61,
199,
2921,
14,
815,
480,
7113,
370,
28877,
737,
298,
435,
8002,
867,
63,
633,
435,
298,
1182,
298,
435,
8002,
867,
63,
697,
9,
199,
199,
3,
663,
1536,
19533,
199,
1662,
10675,
20431,
275,
32265,
14,
6564,
7266,
27361,
8,
736,
14,
2314,
905,
4030,
39,
3830,
2940,
63,
2632,
3135,
199,
895,
275,
3002,
10675,
20431,
14,
362,
63,
3937,
342,
199,
2921,
14,
815,
480,
7113,
370,
19533,
531,
421,
199,
885,
63,
2060,
275,
298,
28508,
2,
199,
885,
63,
2060,
63,
2227,
275,
3550,
63,
2060,
63,
2227,
8,
885,
63,
2060,
9,
199,
199,
318,
5518,
63,
18447,
63,
705,
8,
2416,
63,
6242,
12,
3354,
63,
513,
304,
272,
327,
1361,
298,
893,
370,
5518,
2,
272,
327,
895,
14,
31162,
8,
2416,
63,
6242,
12,
3354,
63,
513,
9,
272,
367,
634,
315,
3354,
63,
513,
26,
267,
870,
1094,
14,
573,
7928,
1399,
8,
2416,
63,
6242,
12,
634,
9,
267,
862,
26,
288,
327,
895,
14,
2526,
8,
2416,
63,
6242,
12,
634,
9,
288,
986,
267,
871,
15492,
18,
14,
24823,
26,
288,
870,
298,
3176,
2575,
3495,
2,
199,
199,
318,
5518,
63,
875,
8,
10983,
12,
1048,
1247,
304,
272,
1048,
1247,
63,
875,
275,
3872,
3680,
904,
8,
761,
1247,
9,
272,
8878,
63,
761,
1247,
63,
875,
275,
3872,
3680,
904,
30387,
28819,
761,
21425,
83,
2,
367,
1048,
315,
1048,
1247,
566,
272,
5518,
275,
298,
10258,
12872,
469,
10983,
93,
11459,
761,
1247,
63,
875,
1552,
13992,
11459,
7045,
63,
761,
1247,
63,
875,
1552,
3779,
84,
1674,
908,
8,
267,
20283,
29,
10983,
12,
4960,
1048,
1247,
63,
875,
29,
761,
1247,
63,
875,
12,
4960,
8878,
63,
761,
1247,
63,
875,
29,
7045,
63,
761,
1247,
63,
875,
9,
272,
372,
5518,
421,
199,
318,
5389,
63,
7882,
63,
509,
63,
2913,
837,
272,
687,
3141,
31822,
492,
1242,
12,
3367,
15369,
339,
2455,
63,
354,
275,
298,
18849,
15,
991,
63,
466,
63,
460,
63,
344,
2,
272,
2455,
63,
3838,
275,
1592,
14,
1345,
8,
1345,
63,
354,
12,
2387,
63,
4757,
29,
549,
9,
272,
1962,
63,
835,
275,
378,
272,
3875,
63,
6242,
63,
835,
275,
378,
272,
2034,
63,
890,
275,
6891,
272,
1343,
63,
498,
275,
2097,
751,
401,
298,
3607,
1493,
937,
272,
1284,
63,
498,
275,
2097,
751,
401,
298,
18113,
90,
937,
339,
687,
28877,
63,
22073,
492,
445,
13087,
23862,
8566,
272,
2034,
275,
445,
13087,
23862,
8566,
8,
697,
12,
2455,
63,
354,
12,
2034,
63,
890,
12,
2387,
63,
4757,
29,
549,
12,
1343,
63,
498,
29,
928,
63,
498,
12,
1284,
63,
498,
29,
500,
63,
498,
9,
339,
3031,
63,
576,
63,
5465,
275,
942,
339,
1830,
2034,
26,
267,
367,
1962,
315,
2034,
26,
953,
1962,
63,
835,
847,
413,
288,
922,
63,
1301,
275,
1962,
14,
1301,
953,
1962,
576,
275,
1052,
288,
1962,
576,
905,
2123,
937,
275,
922,
63,
1301,
18524,
344,
937,
288,
340,
440,
922,
63,
1301,
905,
2913,
63,
3627,
6229,
355,
327,
1361,
298,
1397,
3952,
10417,
642,
1382,
2952,
652,
965,
949,
5055,
2,
355,
1980,
288,
1962,
576,
905,
3627,
63,
344,
937,
275,
922,
63,
1301,
905,
2913,
63,
3627,
937,
288,
862,
26,
355,
1962,
576,
905,
3966,
937,
275,
922,
63,
1301,
905,
3966,
937,
288,
871,
4067,
26,
355,
1962,
576,
905,
3966,
937,
275,
2197,
14,
2083,
8,
6965,
12,
413,
12,
413,
680,
17070,
342,
463,
288,
1962,
576,
905,
2060,
63,
2227,
937,
275,
849,
63,
2060,
63,
2227,
288,
1962,
576,
905,
633,
63,
5464,
937,
275,
298,
751,
2,
435,
620,
8,
21,
993,
435,
1962,
63,
835,
9,
288,
1962,
576,
905,
11809,
63,
354,
937,
275,
298,
7147,
354,
2,
288,
1962,
576,
905,
30959,
937,
275,
298,
6090,
354,
2,
953,
5518,
63,
18447,
63,
705,
8,
3176,
63,
875,
14088,
751,
6949,
1962,
576,
14,
1612,
4000,
359,
1143,
576,
566,
288,
3875,
63,
6242,
63,
835,
847,
413,
953,
327,
10299,
2556,
10451,
370,
3222,
734,
16576,
20372,
3031,
288,
4690,
63,
344,
275,
922,
63,
1301,
905,
2913,
63,
3627,
937,
288,
3031,
275,
922,
63,
1301,
18524,
344,
937,
288,
4690,
63,
1301,
275,
1592,
14,
362,
8,
2913,
63,
344,
9,
288,
3002,
63,
7882,
275,
922,
63,
1301,
905,
761,
478,
937,
953,
2538,
275,
4690,
63,
1301,
905,
1213,
937,
288,
340,
334,
552,
8,
1662,
63,
7882,
9,
690,
413,
304,
355,
2538,
275,
3087,
355,
367,
12229,
315,
3002,
63,
7882,
26,
490,
23721,
63,
1301,
275,
1592,
14,
362,
8,
7504,
9,
490,
3245,
63,
1213,
275,
23721,
63,
1301,
905,
1213,
937,
490,
340,
3245,
63,
1213,
1137,
298
] |
[
28877,
697,
12,
747,
12,
2050,
12,
984,
12,
5055,
199,
504,
10933,
492,
10933,
199,
646,
900,
199,
646,
4145,
199,
646,
1331,
199,
646,
2196,
199,
646,
2197,
199,
504,
10380,
14,
4416,
492,
3550,
63,
2060,
63,
2227,
199,
199,
504,
3141,
31822,
492,
32265,
199,
646,
15492,
18,
199,
199,
3,
1255,
315,
14737,
745,
85,
701,
282,
9,
5532,
316,
12,
330,
9,
6675,
316,
370,
14737,
745,
85,
12,
436,
286,
9,
3879,
199,
3,
14737,
745,
85,
1255,
2366,
13751,
15,
697,
63,
6740,
3250,
316,
15,
8462,
63,
751,
63,
4757,
14,
647,
199,
199,
4806,
14,
19602,
8,
272,
2547,
29,
1274,
14,
2703,
12,
272,
2166,
29,
4806,
14,
5287,
12,
272,
1475,
30845,
2840,
1412,
9,
68,
61,
2818,
20056,
9,
24,
83,
2818,
2671,
985,
9,
1216,
83,
2818,
354,
9,
83,
446,
2818,
1188,
9,
83,
7,
199,
9,
199,
199,
2921,
275,
2050,
14,
5572,
480,
5628,
63,
7882,
531,
523,
199,
3,
663,
1536,
28877,
697,
199,
4091,
867,
63,
697,
275,
747,
14,
12959,
480,
29495,
1441,
63,
2846,
531,
199,
4091,
867,
63,
633,
275,
747,
14,
12959,
480,
29495,
1441,
63,
2632,
531,
199,
331,
2133,
275,
28877,
697,
14,
3120,
8,
633,
29,
4091,
867,
63,
633,
9,
199,
697,
275,
28877,
59,
4091,
867,
63,
697,
61,
199,
2921,
14,
815,
480,
7113,
370,
28877,
737,
298,
435,
8002,
867,
63,
633,
435,
298,
1182,
298,
435,
8002,
867,
63,
697,
9,
199,
199,
3,
663,
1536,
19533,
199,
1662,
10675,
20431,
275,
32265,
14,
6564,
7266,
27361,
8,
736,
14,
2314,
905,
4030,
39,
3830,
2940,
63,
2632,
3135,
199,
895,
275,
3002,
10675,
20431,
14,
362,
63,
3937,
342,
199,
2921,
14,
815,
480,
7113,
370,
19533,
531,
421,
199,
885,
63,
2060,
275,
298,
28508,
2,
199,
885,
63,
2060,
63,
2227,
275,
3550,
63,
2060,
63,
2227,
8,
885,
63,
2060,
9,
199,
199,
318,
5518,
63,
18447,
63,
705,
8,
2416,
63,
6242,
12,
3354,
63,
513,
304,
272,
327,
1361,
298,
893,
370,
5518,
2,
272,
327,
895,
14,
31162,
8,
2416,
63,
6242,
12,
3354,
63,
513,
9,
272,
367,
634,
315,
3354,
63,
513,
26,
267,
870,
1094,
14,
573,
7928,
1399,
8,
2416,
63,
6242,
12,
634,
9,
267,
862,
26,
288,
327,
895,
14,
2526,
8,
2416,
63,
6242,
12,
634,
9,
288,
986,
267,
871,
15492,
18,
14,
24823,
26,
288,
870,
298,
3176,
2575,
3495,
2,
199,
199,
318,
5518,
63,
875,
8,
10983,
12,
1048,
1247,
304,
272,
1048,
1247,
63,
875,
275,
3872,
3680,
904,
8,
761,
1247,
9,
272,
8878,
63,
761,
1247,
63,
875,
275,
3872,
3680,
904,
30387,
28819,
761,
21425,
83,
2,
367,
1048,
315,
1048,
1247,
566,
272,
5518,
275,
298,
10258,
12872,
469,
10983,
93,
11459,
761,
1247,
63,
875,
1552,
13992,
11459,
7045,
63,
761,
1247,
63,
875,
1552,
3779,
84,
1674,
908,
8,
267,
20283,
29,
10983,
12,
4960,
1048,
1247,
63,
875,
29,
761,
1247,
63,
875,
12,
4960,
8878,
63,
761,
1247,
63,
875,
29,
7045,
63,
761,
1247,
63,
875,
9,
272,
372,
5518,
421,
199,
318,
5389,
63,
7882,
63,
509,
63,
2913,
837,
272,
687,
3141,
31822,
492,
1242,
12,
3367,
15369,
339,
2455,
63,
354,
275,
298,
18849,
15,
991,
63,
466,
63,
460,
63,
344,
2,
272,
2455,
63,
3838,
275,
1592,
14,
1345,
8,
1345,
63,
354,
12,
2387,
63,
4757,
29,
549,
9,
272,
1962,
63,
835,
275,
378,
272,
3875,
63,
6242,
63,
835,
275,
378,
272,
2034,
63,
890,
275,
6891,
272,
1343,
63,
498,
275,
2097,
751,
401,
298,
3607,
1493,
937,
272,
1284,
63,
498,
275,
2097,
751,
401,
298,
18113,
90,
937,
339,
687,
28877,
63,
22073,
492,
445,
13087,
23862,
8566,
272,
2034,
275,
445,
13087,
23862,
8566,
8,
697,
12,
2455,
63,
354,
12,
2034,
63,
890,
12,
2387,
63,
4757,
29,
549,
12,
1343,
63,
498,
29,
928,
63,
498,
12,
1284,
63,
498,
29,
500,
63,
498,
9,
339,
3031,
63,
576,
63,
5465,
275,
942,
339,
1830,
2034,
26,
267,
367,
1962,
315,
2034,
26,
953,
1962,
63,
835,
847,
413,
288,
922,
63,
1301,
275,
1962,
14,
1301,
953,
1962,
576,
275,
1052,
288,
1962,
576,
905,
2123,
937,
275,
922,
63,
1301,
18524,
344,
937,
288,
340,
440,
922,
63,
1301,
905,
2913,
63,
3627,
6229,
355,
327,
1361,
298,
1397,
3952,
10417,
642,
1382,
2952,
652,
965,
949,
5055,
2,
355,
1980,
288,
1962,
576,
905,
3627,
63,
344,
937,
275,
922,
63,
1301,
905,
2913,
63,
3627,
937,
288,
862,
26,
355,
1962,
576,
905,
3966,
937,
275,
922,
63,
1301,
905,
3966,
937,
288,
871,
4067,
26,
355,
1962,
576,
905,
3966,
937,
275,
2197,
14,
2083,
8,
6965,
12,
413,
12,
413,
680,
17070,
342,
463,
288,
1962,
576,
905,
2060,
63,
2227,
937,
275,
849,
63,
2060,
63,
2227,
288,
1962,
576,
905,
633,
63,
5464,
937,
275,
298,
751,
2,
435,
620,
8,
21,
993,
435,
1962,
63,
835,
9,
288,
1962,
576,
905,
11809,
63,
354,
937,
275,
298,
7147,
354,
2,
288,
1962,
576,
905,
30959,
937,
275,
298,
6090,
354,
2,
953,
5518,
63,
18447,
63,
705,
8,
3176,
63,
875,
14088,
751,
6949,
1962,
576,
14,
1612,
4000,
359,
1143,
576,
566,
288,
3875,
63,
6242,
63,
835,
847,
413,
953,
327,
10299,
2556,
10451,
370,
3222,
734,
16576,
20372,
3031,
288,
4690,
63,
344,
275,
922,
63,
1301,
905,
2913,
63,
3627,
937,
288,
3031,
275,
922,
63,
1301,
18524,
344,
937,
288,
4690,
63,
1301,
275,
1592,
14,
362,
8,
2913,
63,
344,
9,
288,
3002,
63,
7882,
275,
922,
63,
1301,
905,
761,
478,
937,
953,
2538,
275,
4690,
63,
1301,
905,
1213,
937,
288,
340,
334,
552,
8,
1662,
63,
7882,
9,
690,
413,
304,
355,
2538,
275,
3087,
355,
367,
12229,
315,
3002,
63,
7882,
26,
490,
23721,
63,
1301,
275,
1592,
14,
362,
8,
7504,
9,
490,
3245,
63,
1213,
275,
23721,
63,
1301,
905,
1213,
937,
490,
340,
3245,
63,
1213,
1137,
298,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
aeron15/ruffus
|
ruffus/test/test_files_decorator.py
|
5
|
4552
|
#!/usr/bin/env python
from __future__ import print_function
"""
test_files_decorator.py
test @files which take single files forwards arguments as single files rather
than as lists
"""
import os
tempdir = os.path.relpath(os.path.abspath(os.path.splitext(__file__)[0])) + "/"
import sys
# add grandparent to search path for testing
grandparent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
sys.path.insert(0, grandparent_dir)
# module name = script name without extension
module_name = os.path.splitext(os.path.basename(__file__))[0]
import ruffus
from ruffus import transform, follows, pipeline_run, Pipeline, regex, mkdir, files
#from ruffus.file_name_parameters import
#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
# imports
#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
import json
# use simplejson in place of json for python < 2.6
#try:
#except ImportError:
# import simplejson
# json = simplejson
#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
# Tasks
#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
def test_job_io(infiles, outfiles, extra_params):
"""
cat input files content to output files
after writing out job parameters
"""
# dump parameters
params = (infiles, outfiles) + extra_params
if isinstance(infiles, str):
infile_names = [infiles]
elif infiles is None:
infile_names = []
else:
infile_names = infiles
if isinstance(outfiles, str):
outfile_names = [outfiles]
else:
outfile_names = outfiles
output_text = list()
for f in infile_names:
with open(f) as ii:
output_text.append(ii.read())
output_text = "".join(sorted(output_text))
output_text += json.dumps(infiles) + " -> " + json.dumps(outfiles) + "\n"
for f in outfile_names:
with open(f, "w") as oo:
oo.write(output_text)
#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
# Tasks
#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
@follows(mkdir(tempdir))
#
# task1
#
@files(None, tempdir + 'a.1')
def task1(infiles, outfiles, *extra_params):
"""
First task
"""
test_job_io(infiles, outfiles, extra_params)
#
# task2
#
@transform(task1, regex(r".*"), tempdir + 'b.1')
def task2(infiles, outfiles, *extra_params):
"""
Second task
"""
test_job_io(infiles, outfiles, extra_params)
assert(infiles == tempdir + "a.1")
#
# task3
#
@files(task2, tempdir + 'c.1')
def task3(infiles, outfiles, *extra_params):
"""
Second task
"""
test_job_io(infiles, outfiles, extra_params)
assert(infiles == tempdir + "b.1")
#
# task4
#
@follows(task3)
@files([[None, tempdir + 'd.1'], [None, tempdir + 'e.1']])
def task4(infiles, outfiles, *extra_params):
"""
Second task
"""
test_job_io(infiles, outfiles, extra_params)
#
# task5
#
@files(task4, tempdir + "f.1")
def task5(infiles, outfiles, *extra_params):
"""
Second task
"""
test_job_io(infiles, outfiles, extra_params)
assert(infiles == [tempdir + "d.1", tempdir + "e.1"])
import unittest
class Test_task(unittest.TestCase):
def tearDown (self):
"""
"""
import glob
for f in glob.glob(tempdir + "*"):
os.unlink(f)
os.rmdir(tempdir)
def test_task (self):
pipeline_run(multiprocess = 10, verbose = 0, pipeline= "main")
def test_newstyle_task (self):
"""
Same as above but construct a new pipeline on the fly without decorators
"""
test_pipeline = Pipeline("test")
test_pipeline.files(task1, None, tempdir + 'a.1')\
.follows(mkdir(tempdir))
test_pipeline.transform(task_func = task2,
input = task1,
filter = regex(r".*"),
output = tempdir + 'b.1')
test_pipeline.files(task3, task2, tempdir + 'c.1')
test_pipeline.files(task4, [[None, tempdir + 'd.1'], [None, tempdir + 'e.1']])\
.follows(task3)
test_pipeline.files(task5, task4, tempdir + "f.1")
test_pipeline.run(multiprocess = 10, verbose = 0)
if __name__ == '__main__':
unittest.main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
624,
339,
511,
63,
1725,
63,
11547,
14,
647,
398,
511,
768,
1725,
1314,
5452,
2849,
1584,
17465,
2368,
465,
2849,
1584,
7830,
267,
2419,
465,
5548,
199,
199,
624,
199,
199,
646,
747,
199,
11567,
275,
747,
14,
515,
14,
12405,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
7973,
3460,
493,
363,
2788,
16,
2459,
435,
10609,
199,
646,
984,
199,
199,
3,
1050,
26881,
1708,
370,
2754,
931,
367,
5343,
199,
22655,
1708,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
21777,
401,
21777,
2237,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
26881,
1708,
63,
694,
9,
199,
199,
3,
859,
536,
275,
2884,
536,
1928,
3329,
199,
578,
63,
354,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
4846,
3460,
493,
8964,
59,
16,
61,
199,
199,
646,
519,
3043,
527,
199,
504,
519,
3043,
527,
492,
5793,
12,
11924,
12,
7679,
63,
1065,
12,
19090,
12,
5163,
12,
20366,
12,
1584,
199,
199,
3,
504,
519,
3043,
527,
14,
493,
63,
354,
63,
3214,
492,
421,
199,
3,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
14871,
1299,
13997,
199,
199,
3,
257,
8925,
421,
199,
3,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
14871,
1299,
13997,
199,
199,
646,
2022,
199,
3,
675,
13804,
315,
4192,
402,
2022,
367,
2366,
665,
499,
14,
22,
199,
3,
893,
26,
199,
3,
2590,
3545,
26,
199,
3,
259,
492,
13804,
199,
3,
259,
2022,
275,
13804,
199,
199,
3,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
14871,
1299,
13997,
199,
199,
3,
257,
8495,
83,
421,
199,
3,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
14871,
1299,
13997,
199,
199,
318,
511,
63,
2423,
63,
2308,
8,
262,
1725,
12,
734,
1725,
12,
2402,
63,
1162,
304,
272,
408,
272,
6230,
1324,
1584,
1564,
370,
1072,
1584,
267,
2410,
3575,
734,
3906,
2633,
272,
408,
272,
327,
5461,
2633,
272,
1862,
275,
334,
262,
1725,
12,
734,
1725,
9,
435,
2402,
63,
1162,
339,
340,
1228,
8,
262,
1725,
12,
620,
304,
267,
14734,
63,
1247,
275,
359,
262,
1725,
61,
272,
916,
315,
1725,
365,
488,
26,
267,
14734,
63,
1247,
275,
942,
272,
587,
26,
267,
14734,
63,
1247,
275,
315,
1725,
339,
340,
1228,
8,
548,
1725,
12,
620,
304,
267,
4386,
63,
1247,
275,
359,
548,
1725,
61,
272,
587,
26,
267,
4386,
63,
1247,
275,
734,
1725,
2378,
1072,
63,
505,
275,
769,
342,
272,
367,
289,
315,
14734,
63,
1247,
26,
267,
543,
1551,
8,
70,
9,
465,
15393,
26,
288,
1072,
63,
505,
14,
740,
8,
5908,
14,
739,
1012,
272,
1072,
63,
505,
275,
10587,
904,
8,
5917,
8,
1199,
63,
505,
430,
272,
1072,
63,
505,
847,
2022,
14,
4180,
8,
262,
1725,
9,
435,
298,
1035,
298,
435,
2022,
14,
4180,
8,
548,
1725,
9,
435,
1867,
78,
2,
272,
367,
289,
315,
4386,
63,
1247,
26,
267,
543,
1551,
8,
70,
12,
298,
87,
531,
465,
16390,
26,
288,
16390,
14,
952,
8,
1199,
63,
505,
9,
4388,
199,
3,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
14871,
1299,
13997,
199,
199,
3,
257,
8495,
83,
421,
199,
3,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
14871,
1299,
13997,
199,
199,
32,
7207,
83,
8,
8215,
8,
11567,
430,
199,
3,
199,
3,
259,
2120,
17,
199,
3,
199,
32,
1725,
8,
403,
12,
21628,
435,
283,
65,
14,
17,
358,
199,
318,
2120,
17,
8,
262,
1725,
12,
734,
1725,
12,
627,
2911,
63,
1162,
304,
272,
408,
272,
7758,
2120,
272,
408,
272,
511,
63,
2423,
63,
2308,
8,
262,
1725,
12,
734,
1725,
12,
2402,
63,
1162,
9,
4388,
199,
3,
199,
3,
259,
2120,
18,
199,
3,
199,
32,
4711,
8,
1765,
17,
12,
5163,
8,
82,
1674,
10,
1288,
21628,
435,
283,
66,
14,
17,
358,
199,
318,
2120,
18,
8,
262,
1725,
12,
734,
1725,
12,
627,
2911,
63,
1162,
304,
272,
408,
272,
16707,
2120,
272,
408,
272,
511,
63,
2423,
63,
2308,
8,
262,
1725,
12,
734,
1725,
12,
2402,
63,
1162,
9,
272,
702,
8,
262,
1725,
508,
21628,
435,
298,
65,
14,
17,
531,
4388,
199,
3,
199,
3,
259,
2120,
19,
199,
3,
199,
32,
1725,
8,
1765,
18,
12,
21628,
435,
283,
67,
14,
17,
358,
199,
318,
2120,
19,
8,
262,
1725,
12,
734,
1725,
12,
627,
2911,
63,
1162,
304,
272,
408,
272,
16707,
2120,
272,
408,
272,
511,
63,
2423,
63,
2308,
8,
262,
1725,
12,
734,
1725,
12,
2402,
63,
1162,
9,
272,
702,
8,
262,
1725,
508,
21628,
435,
298,
66,
14,
17,
531,
199,
199,
3,
199,
3,
259,
2120,
20,
199,
3,
199,
32,
7207,
83,
8,
1765,
19,
9,
199,
32,
1725,
4038,
403,
12,
21628,
435,
283,
68,
14,
17,
995,
359,
403,
12,
21628,
435,
283,
69,
14,
17,
12121,
199,
318,
2120,
20,
8,
262,
1725,
12,
734,
1725,
12,
627,
2911,
63,
1162,
304,
272,
408,
272,
16707,
2120,
272,
408,
272,
511,
63,
2423,
63,
2308,
8,
262,
1725,
12,
734,
1725,
12,
2402,
63,
1162,
9,
199,
199,
3,
199,
3,
259,
2120,
21,
199,
3,
199,
32,
1725,
8,
1765,
20,
12,
21628,
435,
298,
70,
14,
17,
531,
199,
318,
2120,
21,
8,
262,
1725,
12,
734,
1725,
12,
627,
2911,
63,
1162,
304,
272,
408,
272,
16707,
2120,
272,
408,
272,
511,
63,
2423,
63,
2308,
8,
262,
1725,
12,
734,
1725,
12,
2402,
63,
1162,
9,
272,
702,
8,
262,
1725,
508,
359,
11567,
435,
298,
68,
14,
17,
401,
21628,
435,
298,
69,
14,
17,
3135,
199,
199,
646,
2882,
199,
199,
533,
1379,
63,
1765,
8,
2796,
14,
1746,
304,
339,
347,
6766,
334,
277,
304,
267,
408,
267,
408,
267,
492,
5739,
267,
367,
289,
315,
5739,
14,
6463
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
624,
339,
511,
63,
1725,
63,
11547,
14,
647,
398,
511,
768,
1725,
1314,
5452,
2849,
1584,
17465,
2368,
465,
2849,
1584,
7830,
267,
2419,
465,
5548,
199,
199,
624,
199,
199,
646,
747,
199,
11567,
275,
747,
14,
515,
14,
12405,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
7973,
3460,
493,
363,
2788,
16,
2459,
435,
10609,
199,
646,
984,
199,
199,
3,
1050,
26881,
1708,
370,
2754,
931,
367,
5343,
199,
22655,
1708,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
21777,
401,
21777,
2237,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
26881,
1708,
63,
694,
9,
199,
199,
3,
859,
536,
275,
2884,
536,
1928,
3329,
199,
578,
63,
354,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
4846,
3460,
493,
8964,
59,
16,
61,
199,
199,
646,
519,
3043,
527,
199,
504,
519,
3043,
527,
492,
5793,
12,
11924,
12,
7679,
63,
1065,
12,
19090,
12,
5163,
12,
20366,
12,
1584,
199,
199,
3,
504,
519,
3043,
527,
14,
493,
63,
354,
63,
3214,
492,
421,
199,
3,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
14871,
1299,
13997,
199,
199,
3,
257,
8925,
421,
199,
3,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
14871,
1299,
13997,
199,
199,
646,
2022,
199,
3,
675,
13804,
315,
4192,
402,
2022,
367,
2366,
665,
499,
14,
22,
199,
3,
893,
26,
199,
3,
2590,
3545,
26,
199,
3,
259,
492,
13804,
199,
3,
259,
2022,
275,
13804,
199,
199,
3,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
14871,
1299,
13997,
199,
199,
3,
257,
8495,
83,
421,
199,
3,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
14871,
1299,
13997,
199,
199,
318,
511,
63,
2423,
63,
2308,
8,
262,
1725,
12,
734,
1725,
12,
2402,
63,
1162,
304,
272,
408,
272,
6230,
1324,
1584,
1564,
370,
1072,
1584,
267,
2410,
3575,
734,
3906,
2633,
272,
408,
272,
327,
5461,
2633,
272,
1862,
275,
334,
262,
1725,
12,
734,
1725,
9,
435,
2402,
63,
1162,
339,
340,
1228,
8,
262,
1725,
12,
620,
304,
267,
14734,
63,
1247,
275,
359,
262,
1725,
61,
272,
916,
315,
1725,
365,
488,
26,
267,
14734,
63,
1247,
275,
942,
272,
587,
26,
267,
14734,
63,
1247,
275,
315,
1725,
339,
340,
1228,
8,
548,
1725,
12,
620,
304,
267,
4386,
63,
1247,
275,
359,
548,
1725,
61,
272,
587,
26,
267,
4386,
63,
1247,
275,
734,
1725,
2378,
1072,
63,
505,
275,
769,
342,
272,
367,
289,
315,
14734,
63,
1247,
26,
267,
543,
1551,
8,
70,
9,
465,
15393,
26,
288,
1072,
63,
505,
14,
740,
8,
5908,
14,
739,
1012,
272,
1072,
63,
505,
275,
10587,
904,
8,
5917,
8,
1199,
63,
505,
430,
272,
1072,
63,
505,
847,
2022,
14,
4180,
8,
262,
1725,
9,
435,
298,
1035,
298,
435,
2022,
14,
4180,
8,
548,
1725,
9,
435,
1867,
78,
2,
272,
367,
289,
315,
4386,
63,
1247,
26,
267,
543,
1551,
8,
70,
12,
298,
87,
531,
465,
16390,
26,
288,
16390,
14,
952,
8,
1199,
63,
505,
9,
4388,
199,
3,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
14871,
1299,
13997,
199,
199,
3,
257,
8495,
83,
421,
199,
3,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
32412,
14871,
1299,
13997,
199,
199,
32,
7207,
83,
8,
8215,
8,
11567,
430,
199,
3,
199,
3,
259,
2120,
17,
199,
3,
199,
32,
1725,
8,
403,
12,
21628,
435,
283,
65,
14,
17,
358,
199,
318,
2120,
17,
8,
262,
1725,
12,
734,
1725,
12,
627,
2911,
63,
1162,
304,
272,
408,
272,
7758,
2120,
272,
408,
272,
511,
63,
2423,
63,
2308,
8,
262,
1725,
12,
734,
1725,
12,
2402,
63,
1162,
9,
4388,
199,
3,
199,
3,
259,
2120,
18,
199,
3,
199,
32,
4711,
8,
1765,
17,
12,
5163,
8,
82,
1674,
10,
1288,
21628,
435,
283,
66,
14,
17,
358,
199,
318,
2120,
18,
8,
262,
1725,
12,
734,
1725,
12,
627,
2911,
63,
1162,
304,
272,
408,
272,
16707,
2120,
272,
408,
272,
511,
63,
2423,
63,
2308,
8,
262,
1725,
12,
734,
1725,
12,
2402,
63,
1162,
9,
272,
702,
8,
262,
1725,
508,
21628,
435,
298,
65,
14,
17,
531,
4388,
199,
3,
199,
3,
259,
2120,
19,
199,
3,
199,
32,
1725,
8,
1765,
18,
12,
21628,
435,
283,
67,
14,
17,
358,
199,
318,
2120,
19,
8,
262,
1725,
12,
734,
1725,
12,
627,
2911,
63,
1162,
304,
272,
408,
272,
16707,
2120,
272,
408,
272,
511,
63,
2423,
63,
2308,
8,
262,
1725,
12,
734,
1725,
12,
2402,
63,
1162,
9,
272,
702,
8,
262,
1725,
508,
21628,
435,
298,
66,
14,
17,
531,
199,
199,
3,
199,
3,
259,
2120,
20,
199,
3,
199,
32,
7207,
83,
8,
1765,
19,
9,
199,
32,
1725,
4038,
403,
12,
21628,
435,
283,
68,
14,
17,
995,
359,
403,
12,
21628,
435,
283,
69,
14,
17,
12121,
199,
318,
2120,
20,
8,
262,
1725,
12,
734,
1725,
12,
627,
2911,
63,
1162,
304,
272,
408,
272,
16707,
2120,
272,
408,
272,
511,
63,
2423,
63,
2308,
8,
262,
1725,
12,
734,
1725,
12,
2402,
63,
1162,
9,
199,
199,
3,
199,
3,
259,
2120,
21,
199,
3,
199,
32,
1725,
8,
1765,
20,
12,
21628,
435,
298,
70,
14,
17,
531,
199,
318,
2120,
21,
8,
262,
1725,
12,
734,
1725,
12,
627,
2911,
63,
1162,
304,
272,
408,
272,
16707,
2120,
272,
408,
272,
511,
63,
2423,
63,
2308,
8,
262,
1725,
12,
734,
1725,
12,
2402,
63,
1162,
9,
272,
702,
8,
262,
1725,
508,
359,
11567,
435,
298,
68,
14,
17,
401,
21628,
435,
298,
69,
14,
17,
3135,
199,
199,
646,
2882,
199,
199,
533,
1379,
63,
1765,
8,
2796,
14,
1746,
304,
339,
347,
6766,
334,
277,
304,
267,
408,
267,
408,
267,
492,
5739,
267,
367,
289,
315,
5739,
14,
6463,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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en
from Components.ActionMap import ActionMap
from Components.Sources.StaticText import StaticText
from Components.Pixmap import Pixmap
from enigma import ePicLoad
from Components.config import config, getConfigListEntry, ConfigInteger
from Components.ConfigList import ConfigListScreen
from Components.AVSwitch import AVSwitch
import Title
class TitleProperties(Screen,ConfigListScreen):
skin = """
<screen name="TitleProperties" position="center,center" size="560,445" title="Properties of current title" >
<ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
<ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
<ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
<ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
<widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
<widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
<widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
<widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
<widget source="serviceinfo" render="Label" position="10,46" size="350,144" font="Regular;18" />
<widget name="thumbnail" position="370,46" size="180,144" alphatest="on" />
<widget name="config" position="10,206" size="540,228" scrollbarMode="showOnDemand" />
</screen>"""
def __init__(self, session, parent, project, title_idx):
Screen.__init__(self, session)
self.parent = parent
self.project = project
self.title_idx = title_idx
self["key_red"] = StaticText(_("Cancel"))
self["key_green"] = StaticText(_("OK"))
self["key_yellow"] = StaticText(_("Edit Title"))
self["key_blue"] = StaticText()
self["serviceinfo"] = StaticText()
self["thumbnail"] = Pixmap()
self.picload = ePicLoad()
self.picload.PictureData.get().append(self.paintThumbPixmapCB)
self.properties = project.titles[title_idx].properties
ConfigListScreen.__init__(self, [])
self.properties.crop = Title.ConfigFixedText("crop")
self.properties.autochapter.addNotifier(self.initConfigList)
self.properties.aspect.addNotifier(self.initConfigList)
for audiotrack in self.properties.audiotracks:
audiotrack.active.addNotifier(self.initConfigList)
self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
{
"green": self.exit,
"red": self.cancel,
"yellow": self.editTitle,
"cancel": self.cancel,
"ok": self.ok,
}, -2)
self.onShown.append(self.update)
self.onLayoutFinish.append(self.layoutFinished)
def layoutFinished(self):
self.setTitle(_("Properties of current title"))
def initConfigList(self, element=None):
try:
self.properties.position = ConfigInteger(default = self.title_idx+1, limits = (1, len(self.project.titles)))
title = self.project.titles[self.title_idx]
self.list = []
self.list.append(getConfigListEntry("DVD " + _("Track"), self.properties.position))
self.list.append(getConfigListEntry("DVD " + _("Title"), self.properties.menutitle))
self.list.append(getConfigListEntry("DVD " + _("Description"), self.properties.menusubtitle))
if config.usage.setup_level.index >= 2: # expert+
for audiotrack in self.properties.audiotracks:
DVB_aud = audiotrack.DVB_lang.getValue() or audiotrack.pid.getValue()
self.list.append(getConfigListEntry(_("burn audio track (%s)") % DVB_aud, audiotrack.active))
if audiotrack.active.getValue():
self.list.append(getConfigListEntry(_("audio track (%s) format") % DVB_aud, audiotrack.format))
self.list.append(getConfigListEntry(_("audio track (%s) language") % DVB_aud, audiotrack.language))
self.list.append(getConfigListEntry("DVD " + _("Aspect Ratio"), self.properties.aspect))
if self.properties.aspect.getValue() == "16:9":
self.list.append(getConfigListEntry("DVD " + "widescreen", self.properties.widescreen))
else:
self.list.append(getConfigListEntry("DVD " + "widescreen", self.properties.crop))
if len(title.chaptermarks) == 0:
self.list.append(getConfigListEntry(_("Auto chapter split every ? minutes (0=never)"), self.properties.autochapter))
infotext = "DVB " + _("Title") + ': ' + title.DVBname + "\n" + _("Description") + ': ' + title.DVBdescr + "\n" + _("Channel") + ': ' + title.DVBchannel + '\n' + _("Begin time") + title.formatDVDmenuText(": $D.$M.$Y, $T\n", self.title_idx+1)
chaptermarks = title.getChapterMarks(template="$h:$m:$s")
chapters_count = len(chaptermarks)
if chapters_count >= 1:
infotext += str(chapters_count+1) + ' ' + _("chapters") + ': '
infotext += ' / '.join(chaptermarks)
self["serviceinfo"].setText(infotext)
self["config"].setList(self.list)
except AttributeError:
pass
def editTitle(self):
self.parent.editTitle()
def update(self):
print "[onShown]"
self.initConfigList()
self.loadThumb()
def loadThumb(self):
thumbfile = self.project.titles[self.title_idx].inputfile.rsplit('.',1)[0] + ".png"
sc = AVSwitch().getFramebufferScale()
self.picload.setPara((self["thumbnail"].instance.size().width(), self["thumbnail"].instance.size().height(), sc[0], sc[1], False, 1, "#00000000"))
self.picload.startDecode(thumbfile)
def paintThumbPixmapCB(self, picInfo=None):
ptr = self.picload.getData()
if ptr != None:
self["thumbnail"].instance.setPixmap(ptr)
def changedConfigList(self):
self.initConfigList()
def exit(self):
self.applySettings()
self.close()
def applySettings(self):
for x in self["config"].list:
x[1].save()
current_pos = self.title_idx+1
new_pos = self.properties.position.getValue()
if new_pos != current_pos:
print "title got repositioned from ", current_pos, "to", new_pos
swaptitle = self.project.titles.pop(current_pos-1)
self.project.titles.insert(new_pos-1, swaptitle)
def ok(self):
#key = self.keydict[self["config"].getCurrent()[1]]
#if key in self.project.filekeys:
#self.session.openWithCallback(self.FileBrowserClosed, FileBrowser, key, self.settings)
pass
def cancel(self):
self.close()
|
gpl-2.0
|
[
504,
29372,
14,
9616,
492,
17804,
199,
504,
17823,
14,
3310,
2956,
492,
10033,
2956,
199,
504,
17823,
14,
13959,
14,
25289,
492,
13599,
1872,
199,
504,
17823,
14,
16049,
492,
510,
12879,
199,
504,
655,
27021,
492,
325,
48,
530,
6200,
199,
504,
17823,
14,
888,
492,
1101,
12,
664,
2028,
16934,
12,
4094,
2674,
199,
504,
17823,
14,
2028,
1296,
492,
4094,
1296,
9616,
199,
504,
17823,
14,
6087,
10167,
492,
437,
7428,
3111,
199,
646,
16881,
199,
199,
533,
16881,
8516,
8,
9616,
12,
2028,
1296,
9616,
304,
199,
198,
16409,
275,
408,
507,
198,
28,
5410,
536,
628,
6888,
8516,
2,
3421,
628,
4218,
12,
4218,
2,
1568,
628,
15789,
12,
20761,
2,
2538,
628,
8516,
402,
1453,
2538,
2,
690,
686,
198,
28,
69,
16049,
29876,
628,
16409,
63,
885,
15,
15687,
15,
581,
14,
4524,
2,
3421,
628,
16,
12,
16,
2,
1568,
628,
10037,
12,
2167,
2,
9797,
27126,
628,
265,
2,
7082,
686,
198,
28,
69,
16049,
29876,
628,
16409,
63,
885,
15,
15687,
15,
7731,
14,
4524,
2,
3421,
628,
10037,
12,
16,
2,
1568,
628,
10037,
12,
2167,
2,
9797,
27126,
628,
265,
2,
7082,
686,
198,
28,
69,
16049,
29876,
628,
16409,
63,
885,
15,
15687,
15,
14514,
14,
4524,
2,
3421,
628,
18520,
12,
16,
2,
1568,
628,
10037,
12,
2167,
2,
9797,
27126,
628,
265,
2,
7082,
686,
198,
28,
69,
16049,
29876,
628,
16409,
63,
885,
15,
15687,
15,
6304,
14,
4524,
2,
3421,
628,
25102,
12,
16,
2,
1568,
628,
10037,
12,
2167,
2,
9797,
27126,
628,
265,
2,
7082,
686,
198,
28,
3440,
1350,
628,
498,
63,
581,
2,
3795,
628,
4314,
2,
3421,
628,
16,
12,
16,
2,
1315,
5625,
628,
17,
2,
1568,
628,
10037,
12,
2167,
2,
5023,
628,
16038,
27,
1167,
2,
394,
5743,
628,
4218,
2,
27554,
628,
4218,
2,
8020,
4117,
13476,
25,
70,
969,
969,
2,
17265,
628,
17,
2,
7082,
686,
198,
28,
3440,
1350,
628,
498,
63,
7731,
2,
3795,
628,
4314,
2,
3421,
628,
10037,
12,
16,
2,
1315,
5625,
628,
17,
2,
1568,
628,
10037,
12,
2167,
2,
5023,
628,
16038,
27,
1167,
2,
394,
5743,
628,
4218,
2,
27554,
628,
4218,
2,
8020,
4117,
13476,
17,
70,
19371,
70,
2,
17265,
628,
17,
2,
7082,
686,
198,
28,
3440,
1350,
628,
498,
63,
14514,
2,
3795,
628,
4314,
2,
3421,
628,
18520,
12,
16,
2,
1315,
5625,
628,
17,
2,
1568,
628,
10037,
12,
2167,
2,
5023,
628,
16038,
27,
1167,
2,
394,
5743,
628,
4218,
2,
27554,
628,
4218,
2,
8020,
4117,
13476,
65,
2036,
5783,
2,
17265,
628,
17,
2,
7082,
686,
198,
28,
3440,
1350,
628,
498,
63,
6304,
2,
3795,
628,
4314,
2,
3421,
628,
25102,
12,
16,
2,
1315,
5625,
628,
17,
2,
1568,
628,
10037,
12,
2167,
2,
5023,
628,
16038,
27,
1167,
2,
394,
5743,
628,
4218,
2,
27554,
628,
4218,
2,
8020,
4117,
13476,
1085,
11501,
66,
2,
17265,
628,
17,
2,
7082,
686,
198,
28,
3440,
1350,
628,
1364,
815,
2,
3795,
628,
4314,
2,
3421,
628,
709,
12,
2466,
2,
1568,
628,
13595,
12,
9862,
2,
5023,
628,
16038,
27,
1085,
2,
7082,
686,
198,
28,
3440,
536,
628,
8311,
2,
3421,
628,
13812,
12,
2466,
2,
1568,
628,
7663,
12,
9862,
2,
9797,
27126,
628,
265,
2,
7082,
686,
198,
28,
3440,
536,
628,
888,
2,
3421,
628,
709,
12,
11089,
2,
1568,
628,
17814,
12,
12048,
2,
13704,
1700,
1385,
628,
2384,
3314,
872,
10333,
2,
7082,
507,
198,
1108,
5410,
11193,
421,
198,
318,
636,
826,
721,
277,
12,
2351,
12,
1676,
12,
2199,
12,
2538,
63,
2996,
304,
507,
198,
9616,
855,
826,
721,
277,
12,
2351,
9,
507,
198,
277,
14,
1708,
275,
1676,
507,
198,
277,
14,
1715,
275,
2199,
507,
198,
277,
14,
1213,
63,
2996,
275,
2538,
63,
2996,
2742,
198,
277,
905,
498,
63,
581,
937,
275,
13599,
1872,
6115,
9083,
2237,
507,
198,
277,
905,
498,
63,
7731,
937,
275,
13599,
1872,
6115,
3593,
2237,
507,
198,
277,
905,
498,
63,
14514,
937,
275,
13599,
1872,
6115,
4685,
16881,
2237,
507,
198,
277,
905,
498,
63,
6304,
937,
275,
13599,
1872,
342,
507,
198,
277,
905,
1364,
815,
937,
275,
13599,
1872,
342,
2742,
198,
277,
905,
8311,
937,
275,
510,
12879,
342,
507,
198,
277,
14,
12475,
912,
275,
325,
48,
530,
6200,
342,
507,
198,
277,
14,
12475,
912,
14,
29439,
1451,
14,
362,
1252,
740,
8,
277,
14,
17486,
2719,
4295,
16049,
9956,
9,
2742,
198,
277,
14,
3282,
275,
2199,
14,
8916,
59,
1213,
63,
2996,
1055,
3282,
507,
198,
2028,
1296,
9616,
855,
826,
721,
277,
12,
3073,
507,
198,
277,
14,
3282,
14,
15816,
275,
16881,
14,
2028,
9515,
1872,
480,
15816,
531,
507,
198,
277,
14,
3282,
14,
2495,
11316,
14,
525,
26884,
8,
277,
14,
826,
2028,
1296,
9,
507,
198,
277,
14,
3282,
14,
18658,
14,
525,
26884,
8,
277,
14,
826,
2028,
1296,
9,
507,
198,
509,
10576,
328,
357,
8085,
315,
291,
14,
3282,
14,
23577,
357,
345,
5618,
26,
686,
198,
23577,
357,
8085,
14,
2682,
14,
525,
26884,
8,
277,
14,
826,
2028,
1296,
9,
2742,
198,
277,
905,
2758,
9303,
937,
275,
10033,
2956,
5234,
8555,
9303,
401,
298,
4117,
9303,
2255,
507,
198,
91,
15075,
298,
7731,
582,
291,
14,
2224,
12,
15075,
298,
581,
582,
291,
14,
6406,
12,
15075,
298,
14514,
582,
291,
14,
3773,
6888,
12,
15075,
298,
6406,
582,
291,
14,
6406,
12,
15075,
298,
745,
582,
291,
14,
745,
12,
507,
198,
1386,
446,
18,
9,
9068,
198,
277,
14,
265,
6824,
78,
14,
740,
8,
277,
14,
873,
9,
507,
198,
277,
14,
265,
4798,
22084,
14,
740,
8,
277,
14,
4209,
13430,
9,
421,
198,
318,
7054,
13430,
8,
277,
304,
507,
198,
277,
14,
31675,
6115,
8516,
402,
1453,
2538,
2237,
421,
198,
318,
4205,
2028,
1296,
8,
277,
12,
1819,
29,
403,
304,
507,
198,
893,
26,
686,
198,
277,
14,
3282,
14,
3124,
275,
4094,
2674,
8,
885,
275,
291,
14,
1213,
63,
2996,
11,
17,
12,
10976,
275,
334,
17
] |
[
29372,
14,
9616,
492,
17804,
199,
504,
17823,
14,
3310,
2956,
492,
10033,
2956,
199,
504,
17823,
14,
13959,
14,
25289,
492,
13599,
1872,
199,
504,
17823,
14,
16049,
492,
510,
12879,
199,
504,
655,
27021,
492,
325,
48,
530,
6200,
199,
504,
17823,
14,
888,
492,
1101,
12,
664,
2028,
16934,
12,
4094,
2674,
199,
504,
17823,
14,
2028,
1296,
492,
4094,
1296,
9616,
199,
504,
17823,
14,
6087,
10167,
492,
437,
7428,
3111,
199,
646,
16881,
199,
199,
533,
16881,
8516,
8,
9616,
12,
2028,
1296,
9616,
304,
199,
198,
16409,
275,
408,
507,
198,
28,
5410,
536,
628,
6888,
8516,
2,
3421,
628,
4218,
12,
4218,
2,
1568,
628,
15789,
12,
20761,
2,
2538,
628,
8516,
402,
1453,
2538,
2,
690,
686,
198,
28,
69,
16049,
29876,
628,
16409,
63,
885,
15,
15687,
15,
581,
14,
4524,
2,
3421,
628,
16,
12,
16,
2,
1568,
628,
10037,
12,
2167,
2,
9797,
27126,
628,
265,
2,
7082,
686,
198,
28,
69,
16049,
29876,
628,
16409,
63,
885,
15,
15687,
15,
7731,
14,
4524,
2,
3421,
628,
10037,
12,
16,
2,
1568,
628,
10037,
12,
2167,
2,
9797,
27126,
628,
265,
2,
7082,
686,
198,
28,
69,
16049,
29876,
628,
16409,
63,
885,
15,
15687,
15,
14514,
14,
4524,
2,
3421,
628,
18520,
12,
16,
2,
1568,
628,
10037,
12,
2167,
2,
9797,
27126,
628,
265,
2,
7082,
686,
198,
28,
69,
16049,
29876,
628,
16409,
63,
885,
15,
15687,
15,
6304,
14,
4524,
2,
3421,
628,
25102,
12,
16,
2,
1568,
628,
10037,
12,
2167,
2,
9797,
27126,
628,
265,
2,
7082,
686,
198,
28,
3440,
1350,
628,
498,
63,
581,
2,
3795,
628,
4314,
2,
3421,
628,
16,
12,
16,
2,
1315,
5625,
628,
17,
2,
1568,
628,
10037,
12,
2167,
2,
5023,
628,
16038,
27,
1167,
2,
394,
5743,
628,
4218,
2,
27554,
628,
4218,
2,
8020,
4117,
13476,
25,
70,
969,
969,
2,
17265,
628,
17,
2,
7082,
686,
198,
28,
3440,
1350,
628,
498,
63,
7731,
2,
3795,
628,
4314,
2,
3421,
628,
10037,
12,
16,
2,
1315,
5625,
628,
17,
2,
1568,
628,
10037,
12,
2167,
2,
5023,
628,
16038,
27,
1167,
2,
394,
5743,
628,
4218,
2,
27554,
628,
4218,
2,
8020,
4117,
13476,
17,
70,
19371,
70,
2,
17265,
628,
17,
2,
7082,
686,
198,
28,
3440,
1350,
628,
498,
63,
14514,
2,
3795,
628,
4314,
2,
3421,
628,
18520,
12,
16,
2,
1315,
5625,
628,
17,
2,
1568,
628,
10037,
12,
2167,
2,
5023,
628,
16038,
27,
1167,
2,
394,
5743,
628,
4218,
2,
27554,
628,
4218,
2,
8020,
4117,
13476,
65,
2036,
5783,
2,
17265,
628,
17,
2,
7082,
686,
198,
28,
3440,
1350,
628,
498,
63,
6304,
2,
3795,
628,
4314,
2,
3421,
628,
25102,
12,
16,
2,
1315,
5625,
628,
17,
2,
1568,
628,
10037,
12,
2167,
2,
5023,
628,
16038,
27,
1167,
2,
394,
5743,
628,
4218,
2,
27554,
628,
4218,
2,
8020,
4117,
13476,
1085,
11501,
66,
2,
17265,
628,
17,
2,
7082,
686,
198,
28,
3440,
1350,
628,
1364,
815,
2,
3795,
628,
4314,
2,
3421,
628,
709,
12,
2466,
2,
1568,
628,
13595,
12,
9862,
2,
5023,
628,
16038,
27,
1085,
2,
7082,
686,
198,
28,
3440,
536,
628,
8311,
2,
3421,
628,
13812,
12,
2466,
2,
1568,
628,
7663,
12,
9862,
2,
9797,
27126,
628,
265,
2,
7082,
686,
198,
28,
3440,
536,
628,
888,
2,
3421,
628,
709,
12,
11089,
2,
1568,
628,
17814,
12,
12048,
2,
13704,
1700,
1385,
628,
2384,
3314,
872,
10333,
2,
7082,
507,
198,
1108,
5410,
11193,
421,
198,
318,
636,
826,
721,
277,
12,
2351,
12,
1676,
12,
2199,
12,
2538,
63,
2996,
304,
507,
198,
9616,
855,
826,
721,
277,
12,
2351,
9,
507,
198,
277,
14,
1708,
275,
1676,
507,
198,
277,
14,
1715,
275,
2199,
507,
198,
277,
14,
1213,
63,
2996,
275,
2538,
63,
2996,
2742,
198,
277,
905,
498,
63,
581,
937,
275,
13599,
1872,
6115,
9083,
2237,
507,
198,
277,
905,
498,
63,
7731,
937,
275,
13599,
1872,
6115,
3593,
2237,
507,
198,
277,
905,
498,
63,
14514,
937,
275,
13599,
1872,
6115,
4685,
16881,
2237,
507,
198,
277,
905,
498,
63,
6304,
937,
275,
13599,
1872,
342,
507,
198,
277,
905,
1364,
815,
937,
275,
13599,
1872,
342,
2742,
198,
277,
905,
8311,
937,
275,
510,
12879,
342,
507,
198,
277,
14,
12475,
912,
275,
325,
48,
530,
6200,
342,
507,
198,
277,
14,
12475,
912,
14,
29439,
1451,
14,
362,
1252,
740,
8,
277,
14,
17486,
2719,
4295,
16049,
9956,
9,
2742,
198,
277,
14,
3282,
275,
2199,
14,
8916,
59,
1213,
63,
2996,
1055,
3282,
507,
198,
2028,
1296,
9616,
855,
826,
721,
277,
12,
3073,
507,
198,
277,
14,
3282,
14,
15816,
275,
16881,
14,
2028,
9515,
1872,
480,
15816,
531,
507,
198,
277,
14,
3282,
14,
2495,
11316,
14,
525,
26884,
8,
277,
14,
826,
2028,
1296,
9,
507,
198,
277,
14,
3282,
14,
18658,
14,
525,
26884,
8,
277,
14,
826,
2028,
1296,
9,
507,
198,
509,
10576,
328,
357,
8085,
315,
291,
14,
3282,
14,
23577,
357,
345,
5618,
26,
686,
198,
23577,
357,
8085,
14,
2682,
14,
525,
26884,
8,
277,
14,
826,
2028,
1296,
9,
2742,
198,
277,
905,
2758,
9303,
937,
275,
10033,
2956,
5234,
8555,
9303,
401,
298,
4117,
9303,
2255,
507,
198,
91,
15075,
298,
7731,
582,
291,
14,
2224,
12,
15075,
298,
581,
582,
291,
14,
6406,
12,
15075,
298,
14514,
582,
291,
14,
3773,
6888,
12,
15075,
298,
6406,
582,
291,
14,
6406,
12,
15075,
298,
745,
582,
291,
14,
745,
12,
507,
198,
1386,
446,
18,
9,
9068,
198,
277,
14,
265,
6824,
78,
14,
740,
8,
277,
14,
873,
9,
507,
198,
277,
14,
265,
4798,
22084,
14,
740,
8,
277,
14,
4209,
13430,
9,
421,
198,
318,
7054,
13430,
8,
277,
304,
507,
198,
277,
14,
31675,
6115,
8516,
402,
1453,
2538,
2237,
421,
198,
318,
4205,
2028,
1296,
8,
277,
12,
1819,
29,
403,
304,
507,
198,
893,
26,
686,
198,
277,
14,
3282,
14,
3124,
275,
4094,
2674,
8,
885,
275,
291,
14,
1213,
63,
2996,
11,
17,
12,
10976,
275,
334,
17,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
abhattad4/Digi-Menu
|
django/contrib/auth/context_processors.py
|
514
|
1938
|
# PermWrapper and PermLookupDict proxy the permissions system into objects that
# the template system can understand.
class PermLookupDict(object):
def __init__(self, user, app_label):
self.user, self.app_label = user, app_label
def __repr__(self):
return str(self.user.get_all_permissions())
def __getitem__(self, perm_name):
return self.user.has_perm("%s.%s" % (self.app_label, perm_name))
def __iter__(self):
# To fix 'item in perms.someapp' and __getitem__ iteraction we need to
# define __iter__. See #18979 for details.
raise TypeError("PermLookupDict is not iterable.")
def __bool__(self):
return self.user.has_module_perms(self.app_label)
def __nonzero__(self): # Python 2 compatibility
return type(self).__bool__(self)
class PermWrapper(object):
def __init__(self, user):
self.user = user
def __getitem__(self, app_label):
return PermLookupDict(self.user, app_label)
def __iter__(self):
# I am large, I contain multitudes.
raise TypeError("PermWrapper is not iterable.")
def __contains__(self, perm_name):
"""
Lookup by "someapp" or "someapp.someperm" in perms.
"""
if '.' not in perm_name:
# The name refers to module.
return bool(self[perm_name])
app_label, perm_name = perm_name.split('.', 1)
return self[app_label][perm_name]
def auth(request):
"""
Returns context variables required by apps that use Django's authentication
system.
If there is no 'user' attribute in the request, uses AnonymousUser (from
django.contrib.auth).
"""
if hasattr(request, 'user'):
user = request.user
else:
from django.contrib.auth.models import AnonymousUser
user = AnonymousUser()
return {
'user': user,
'perms': PermWrapper(user),
}
|
bsd-3-clause
|
[
3,
3492,
77,
4590,
436,
3492,
77,
7521,
2141,
4566,
314,
3443,
2656,
1901,
2251,
626,
199,
3,
314,
1978,
2656,
883,
20647,
14,
421,
199,
533,
3492,
77,
7521,
2141,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
922,
12,
1145,
63,
1302,
304,
267,
291,
14,
751,
12,
291,
14,
571,
63,
1302,
275,
922,
12,
1145,
63,
1302,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
620,
8,
277,
14,
751,
14,
362,
63,
452,
63,
6060,
1012,
339,
347,
636,
6095,
721,
277,
12,
10869,
63,
354,
304,
267,
372,
291,
14,
751,
14,
1989,
63,
8220,
3647,
83,
4111,
83,
2,
450,
334,
277,
14,
571,
63,
1302,
12,
10869,
63,
354,
430,
339,
347,
636,
1661,
721,
277,
304,
267,
327,
4005,
5325,
283,
1053,
315,
17340,
14,
3972,
571,
7,
436,
636,
6095,
363,
4826,
414,
781,
1929,
370,
267,
327,
5627,
636,
1661,
4343,
1666,
327,
11370,
1965,
367,
2436,
14,
267,
746,
3146,
480,
23554,
7521,
2141,
365,
440,
6076,
2685,
339,
347,
636,
2245,
721,
277,
304,
267,
372,
291,
14,
751,
14,
1989,
63,
578,
63,
12068,
8,
277,
14,
571,
63,
1302,
9,
339,
347,
636,
10262,
721,
277,
304,
420,
327,
2018,
499,
7163,
267,
372,
730,
8,
277,
2843,
2245,
721,
277,
9,
421,
199,
533,
3492,
77,
4590,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
922,
304,
267,
291,
14,
751,
275,
922,
339,
347,
636,
6095,
721,
277,
12,
1145,
63,
1302,
304,
267,
372,
3492,
77,
7521,
2141,
8,
277,
14,
751,
12,
1145,
63,
1302,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
327,
473,
8140,
7031,
12,
473,
1395,
3510,
10963,
3424,
14,
267,
746,
3146,
480,
23554,
4590,
365,
440,
6076,
2685,
339,
347,
636,
6134,
721,
277,
12,
10869,
63,
354,
304,
267,
408,
267,
12785,
701,
298,
3972,
571,
2,
503,
298,
3972,
571,
14,
3972,
8220,
2,
315,
17340,
14,
267,
408,
267,
340,
7815,
440,
315,
10869,
63,
354,
26,
288,
327,
710,
536,
15724,
370,
859,
14,
288,
372,
2155,
8,
277,
59,
8220,
63,
354,
566,
267,
1145,
63,
1302,
12,
10869,
63,
354,
275,
10869,
63,
354,
14,
1294,
14078,
413,
9,
267,
372,
291,
59,
571,
63,
1302,
1527,
8220,
63,
354,
61,
421,
199,
318,
1790,
8,
1069,
304,
272,
408,
272,
1803,
1067,
2860,
1415,
701,
8686,
626,
675,
5634,
1159,
6299,
272,
2656,
14,
339,
982,
2337,
365,
949,
283,
751,
7,
2225,
315,
314,
1056,
12,
4440,
29952,
334,
504,
272,
1639,
14,
2828,
14,
1178,
680,
272,
408,
272,
340,
2688,
8,
1069,
12,
283,
751,
735,
267,
922,
275,
1056,
14,
751,
272,
587,
26,
267,
687,
1639,
14,
2828,
14,
1178,
14,
992,
492,
29952,
267,
922,
275,
29952,
342,
339,
372,
469,
267,
283,
751,
356,
922,
12,
267,
283,
12068,
356,
3492,
77,
4590,
8,
751,
395,
272,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3492,
77,
4590,
436,
3492,
77,
7521,
2141,
4566,
314,
3443,
2656,
1901,
2251,
626,
199,
3,
314,
1978,
2656,
883,
20647,
14,
421,
199,
533,
3492,
77,
7521,
2141,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
922,
12,
1145,
63,
1302,
304,
267,
291,
14,
751,
12,
291,
14,
571,
63,
1302,
275,
922,
12,
1145,
63,
1302,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
620,
8,
277,
14,
751,
14,
362,
63,
452,
63,
6060,
1012,
339,
347,
636,
6095,
721,
277,
12,
10869,
63,
354,
304,
267,
372,
291,
14,
751,
14,
1989,
63,
8220,
3647,
83,
4111,
83,
2,
450,
334,
277,
14,
571,
63,
1302,
12,
10869,
63,
354,
430,
339,
347,
636,
1661,
721,
277,
304,
267,
327,
4005,
5325,
283,
1053,
315,
17340,
14,
3972,
571,
7,
436,
636,
6095,
363,
4826,
414,
781,
1929,
370,
267,
327,
5627,
636,
1661,
4343,
1666,
327,
11370,
1965,
367,
2436,
14,
267,
746,
3146,
480,
23554,
7521,
2141,
365,
440,
6076,
2685,
339,
347,
636,
2245,
721,
277,
304,
267,
372,
291,
14,
751,
14,
1989,
63,
578,
63,
12068,
8,
277,
14,
571,
63,
1302,
9,
339,
347,
636,
10262,
721,
277,
304,
420,
327,
2018,
499,
7163,
267,
372,
730,
8,
277,
2843,
2245,
721,
277,
9,
421,
199,
533,
3492,
77,
4590,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
922,
304,
267,
291,
14,
751,
275,
922,
339,
347,
636,
6095,
721,
277,
12,
1145,
63,
1302,
304,
267,
372,
3492,
77,
7521,
2141,
8,
277,
14,
751,
12,
1145,
63,
1302,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
327,
473,
8140,
7031,
12,
473,
1395,
3510,
10963,
3424,
14,
267,
746,
3146,
480,
23554,
4590,
365,
440,
6076,
2685,
339,
347,
636,
6134,
721,
277,
12,
10869,
63,
354,
304,
267,
408,
267,
12785,
701,
298,
3972,
571,
2,
503,
298,
3972,
571,
14,
3972,
8220,
2,
315,
17340,
14,
267,
408,
267,
340,
7815,
440,
315,
10869,
63,
354,
26,
288,
327,
710,
536,
15724,
370,
859,
14,
288,
372,
2155,
8,
277,
59,
8220,
63,
354,
566,
267,
1145,
63,
1302,
12,
10869,
63,
354,
275,
10869,
63,
354,
14,
1294,
14078,
413,
9,
267,
372,
291,
59,
571,
63,
1302,
1527,
8220,
63,
354,
61,
421,
199,
318,
1790,
8,
1069,
304,
272,
408,
272,
1803,
1067,
2860,
1415,
701,
8686,
626,
675,
5634,
1159,
6299,
272,
2656,
14,
339,
982,
2337,
365,
949,
283,
751,
7,
2225,
315,
314,
1056,
12,
4440,
29952,
334,
504,
272,
1639,
14,
2828,
14,
1178,
680,
272,
408,
272,
340,
2688,
8,
1069,
12,
283,
751,
735,
267,
922,
275,
1056,
14,
751,
272,
587,
26,
267,
687,
1639,
14,
2828,
14,
1178,
14,
992,
492,
29952,
267,
922,
275,
29952,
342,
339,
372,
469,
267,
283,
751,
356,
922,
12,
267,
283,
12068,
356,
3492,
77,
4590,
8,
751,
395,
272,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
Kalashnikitty/ville-kernel
|
scripts/build-all.py
|
1250
|
9474
|
#! /usr/bin/env python
# Copyright (c) 2009-2011, Code Aurora Forum. 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 Code Aurora nor
# the names of its contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Build the kernel for all targets using the Android build environment.
#
# TODO: Accept arguments to indicate what to build.
import glob
from optparse import OptionParser
import subprocess
import os
import os.path
import shutil
import sys
version = 'build-all.py, version 0.01'
build_dir = '../all-kernels'
make_command = ["vmlinux", "modules"]
make_env = os.environ
make_env.update({
'ARCH': 'arm',
'CROSS_COMPILE': 'arm-none-linux-gnueabi-',
'KCONFIG_NOTIMESTAMP': 'true' })
all_options = {}
def error(msg):
sys.stderr.write("error: %s\n" % msg)
def fail(msg):
"""Fail with a user-printed message"""
error(msg)
sys.exit(1)
def check_kernel():
"""Ensure that PWD is a kernel directory"""
if (not os.path.isfile('MAINTAINERS') or
not os.path.isfile('arch/arm/mach-msm/Kconfig')):
fail("This doesn't seem to be an MSM kernel dir")
def check_build():
"""Ensure that the build directory is present."""
if not os.path.isdir(build_dir):
try:
os.makedirs(build_dir)
except OSError as exc:
if exc.errno == errno.EEXIST:
pass
else:
raise
def update_config(file, str):
print 'Updating %s with \'%s\'\n' % (file, str)
defconfig = open(file, 'a')
defconfig.write(str + '\n')
defconfig.close()
def scan_configs():
"""Get the full list of defconfigs appropriate for this tree."""
names = {}
for n in glob.glob('arch/arm/configs/[fm]sm[0-9-]*_defconfig'):
names[os.path.basename(n)[:-10]] = n
for n in glob.glob('arch/arm/configs/qsd*_defconfig'):
names[os.path.basename(n)[:-10]] = n
for n in glob.glob('arch/arm/configs/apq*_defconfig'):
names[os.path.basename(n)[:-10]] = n
return names
class Builder:
def __init__(self, logname):
self.logname = logname
self.fd = open(logname, 'w')
def run(self, args):
devnull = open('/dev/null', 'r')
proc = subprocess.Popen(args, stdin=devnull,
env=make_env,
bufsize=0,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
count = 0
# for line in proc.stdout:
rawfd = proc.stdout.fileno()
while True:
line = os.read(rawfd, 1024)
if not line:
break
self.fd.write(line)
self.fd.flush()
if all_options.verbose:
sys.stdout.write(line)
sys.stdout.flush()
else:
for i in range(line.count('\n')):
count += 1
if count == 64:
count = 0
print
sys.stdout.write('.')
sys.stdout.flush()
print
result = proc.wait()
self.fd.close()
return result
failed_targets = []
def build(target):
dest_dir = os.path.join(build_dir, target)
log_name = '%s/log-%s.log' % (build_dir, target)
print 'Building %s in %s log %s' % (target, dest_dir, log_name)
if not os.path.isdir(dest_dir):
os.mkdir(dest_dir)
defconfig = 'arch/arm/configs/%s_defconfig' % target
dotconfig = '%s/.config' % dest_dir
savedefconfig = '%s/defconfig' % dest_dir
shutil.copyfile(defconfig, dotconfig)
devnull = open('/dev/null', 'r')
subprocess.check_call(['make', 'O=%s' % dest_dir,
'%s_defconfig' % target], env=make_env, stdin=devnull)
devnull.close()
if not all_options.updateconfigs:
build = Builder(log_name)
result = build.run(['make', 'O=%s' % dest_dir] + make_command)
if result != 0:
if all_options.keep_going:
failed_targets.append(target)
fail_or_error = error
else:
fail_or_error = fail
fail_or_error("Failed to build %s, see %s" % (target, build.logname))
# Copy the defconfig back.
if all_options.configs or all_options.updateconfigs:
devnull = open('/dev/null', 'r')
subprocess.check_call(['make', 'O=%s' % dest_dir,
'savedefconfig'], env=make_env, stdin=devnull)
devnull.close()
shutil.copyfile(savedefconfig, defconfig)
def build_many(allconf, targets):
print "Building %d target(s)" % len(targets)
for target in targets:
if all_options.updateconfigs:
update_config(allconf[target], all_options.updateconfigs)
build(target)
if failed_targets:
fail('\n '.join(["Failed targets:"] +
[target for target in failed_targets]))
def main():
global make_command
check_kernel()
check_build()
configs = scan_configs()
usage = ("""
%prog [options] all -- Build all targets
%prog [options] target target ... -- List specific targets
%prog [options] perf -- Build all perf targets
%prog [options] noperf -- Build all non-perf targets""")
parser = OptionParser(usage=usage, version=version)
parser.add_option('--configs', action='store_true',
dest='configs',
help="Copy configs back into tree")
parser.add_option('--list', action='store_true',
dest='list',
help='List available targets')
parser.add_option('-v', '--verbose', action='store_true',
dest='verbose',
help='Output to stdout in addition to log file')
parser.add_option('--oldconfig', action='store_true',
dest='oldconfig',
help='Only process "make oldconfig"')
parser.add_option('--updateconfigs',
dest='updateconfigs',
help="Update defconfigs with provided option setting, "
"e.g. --updateconfigs=\'CONFIG_USE_THING=y\'")
parser.add_option('-j', '--jobs', type='int', dest="jobs",
help="Number of simultaneous jobs")
parser.add_option('-l', '--load-average', type='int',
dest='load_average',
help="Don't start multiple jobs unless load is below LOAD_AVERAGE")
parser.add_option('-k', '--keep-going', action='store_true',
dest='keep_going', default=False,
help="Keep building other targets if a target fails")
parser.add_option('-m', '--make-target', action='append',
help='Build the indicated make target (default: %s)' %
' '.join(make_command))
(options, args) = parser.parse_args()
global all_options
all_options = options
if options.list:
print "Available targets:"
for target in configs.keys():
print " %s" % target
sys.exit(0)
if options.oldconfig:
make_command = ["oldconfig"]
elif options.make_target:
make_command = options.make_target
if options.jobs:
make_command.append("-j%d" % options.jobs)
if options.load_average:
make_command.append("-l%d" % options.load_average)
if args == ['all']:
build_many(configs, configs.keys())
elif args == ['perf']:
targets = []
for t in configs.keys():
if "perf" in t:
targets.append(t)
build_many(configs, targets)
elif args == ['noperf']:
targets = []
for t in configs.keys():
if "perf" not in t:
targets.append(t)
build_many(configs, targets)
elif len(args) > 0:
targets = []
for t in args:
if t not in configs.keys():
parser.error("Target '%s' not one of %s" % (t, configs.keys()))
targets.append(t)
build_many(configs, targets)
else:
parser.error("Must specify a target to build, or 'all'")
if __name__ == "__main__":
main()
|
gpl-2.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
8937,
13,
8128,
12,
5495,
437,
300,
11131,
2104,
453,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
755,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
5495,
437,
300,
11131,
6590,
199,
3,
755,
314,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
199,
3,
755,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
199,
3,
755,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
11214,
13,
12799,
9315,
9706,
14,
221,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
199,
3,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
199,
3,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
199,
3,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
199,
3,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
199,
3,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
3,
6516,
314,
5114,
367,
1006,
4545,
1808,
314,
14694,
1900,
3734,
14,
199,
3,
199,
3,
3254,
26,
15506,
2368,
370,
6623,
4052,
370,
1900,
14,
199,
199,
646,
5739,
199,
504,
8691,
492,
13491,
199,
646,
3873,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
5145,
199,
646,
984,
199,
199,
1023,
275,
283,
1506,
13,
452,
14,
647,
12,
1015,
378,
14,
614,
7,
199,
199,
1506,
63,
694,
275,
20644,
452,
13,
29824,
7,
199,
1875,
63,
1531,
275,
2097,
2611,
5135,
401,
298,
3112,
937,
199,
1875,
63,
1813,
275,
747,
14,
2314,
199,
1875,
63,
1813,
14,
873,
2561,
267,
283,
7762,
356,
283,
5362,
297,
267,
283,
28368,
63,
29911,
356,
283,
5362,
13,
3592,
13,
5135,
13,
784,
310,
14677,
14382,
267,
283,
43,
5569,
63,
4609,
1469,
16260,
356,
283,
2052,
7,
3828,
199,
452,
63,
1419,
275,
1052,
199,
199,
318,
1125,
8,
1328,
304,
272,
984,
14,
3083,
14,
952,
480,
705,
26,
450,
83,
60,
78,
2,
450,
1499,
9,
199,
199,
318,
2449,
8,
1328,
304,
272,
408,
4874,
543,
282,
922,
13,
27131,
1245,
624,
272,
1125,
8,
1328,
9,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
318,
1104,
63,
4989,
837,
272,
408,
13913,
626,
510,
16698,
365,
282,
5114,
2082,
624,
272,
340,
334,
1397,
747,
14,
515,
14,
6292,
360,
2054,
2919,
9021,
3960,
358,
503,
267,
440,
747,
14,
515,
14,
6292,
360,
1047,
15,
5362,
15,
14121,
13,
706,
77,
15,
28033,
8109,
267,
2449,
480,
2765,
3181,
1133,
17021,
370,
506,
376,
603,
4029,
5114,
2935,
531,
199,
199,
318,
1104,
63,
1506,
837,
272,
408,
13913,
626,
314,
1900,
2082,
365,
3451,
1041,
272,
340,
440,
747,
14,
515,
14,
6027,
8,
1506,
63,
694,
304,
267,
862,
26,
288,
747,
14,
8347,
8,
1506,
63,
694,
9,
267,
871,
6440,
465,
3178,
26,
288,
340,
3178,
14,
7931,
508,
7554,
14,
28596,
26,
355,
986,
288,
587,
26,
355,
746,
199,
199,
318,
1678,
63,
888,
8,
493,
12,
620,
304,
272,
870,
283,
24993,
450,
83,
543,
19095,
83,
24908,
78,
7,
450,
334,
493,
12,
620,
9,
272,
347,
888,
275,
1551,
8,
493,
12,
283,
65,
358,
272,
347,
888,
14,
952,
8,
495,
435,
1557,
78,
358,
272,
347,
888,
14,
1600,
342,
199,
199,
318,
8000,
63,
7532,
837,
272,
408,
1002,
314,
2615,
769,
402,
347,
7532,
5827,
367,
642,
3123,
1041,
272,
1561,
275,
1052,
272,
367,
302,
315,
5739,
14,
6463,
360,
1047,
15,
5362,
15,
7532,
32418,
10886,
61,
3300,
59,
16,
13,
25,
13,
3672,
63,
26022,
735,
267,
1561,
59,
736,
14,
515,
14,
4846,
8,
78,
31280,
709,
2677,
275,
302,
272,
367,
302,
315,
5739,
14,
6463,
360,
1047,
15,
5362,
15,
7532,
15,
81,
3893,
10,
63,
26022,
735,
267,
1561,
59,
736,
14,
515,
14,
4846,
8,
78,
31280,
709,
2677,
275,
302,
272,
367,
302,
315,
5739,
14,
6463,
360,
1047,
15,
5362,
15,
7532,
15,
439,
81,
10,
63,
26022,
735,
267,
1561,
59,
736,
14,
515,
14,
4846,
8,
78,
31280,
709,
2677,
275,
302,
272,
372,
1561,
199,
199,
533,
19286,
26,
272,
347,
636,
826,
721,
277,
12,
943,
354,
304,
267,
291,
14,
793,
354,
275,
943,
354,
267,
291,
14,
2592,
275,
1551,
8,
793,
354,
12,
283,
87,
358,
339,
347,
1255,
8,
277,
12,
1249,
304,
267,
4866,
2307,
275,
1551,
2336,
2374,
15,
2307,
297,
283,
82,
358,
267,
6499,
275,
3873,
14,
7942,
8,
589,
12,
9009,
29,
19778,
12,
355,
2589,
29,
1875,
63,
1813,
12,
355,
17080,
29,
16,
12,
355,
3839,
29,
5781,
14,
6089,
12,
355,
4635,
29,
5781,
14,
13850,
9,
267,
2338,
275,
378,
267,
327,
367,
1004,
315,
6499,
14,
2703,
26,
267,
3066,
2592,
275,
6499,
14,
2703,
14,
9843,
342,
267,
1830,
715,
26,
288,
1004,
275,
747,
14,
739,
8,
1773,
2592,
12,
6619,
9,
288,
340,
440,
1004,
26,
355,
2059,
288,
291,
14
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
8937,
13,
8128,
12,
5495,
437,
300,
11131,
2104,
453,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
755,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
5495,
437,
300,
11131,
6590,
199,
3,
755,
314,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
199,
3,
755,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
199,
3,
755,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
11214,
13,
12799,
9315,
9706,
14,
221,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
199,
3,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
199,
3,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
199,
3,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
199,
3,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
199,
3,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
3,
6516,
314,
5114,
367,
1006,
4545,
1808,
314,
14694,
1900,
3734,
14,
199,
3,
199,
3,
3254,
26,
15506,
2368,
370,
6623,
4052,
370,
1900,
14,
199,
199,
646,
5739,
199,
504,
8691,
492,
13491,
199,
646,
3873,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
5145,
199,
646,
984,
199,
199,
1023,
275,
283,
1506,
13,
452,
14,
647,
12,
1015,
378,
14,
614,
7,
199,
199,
1506,
63,
694,
275,
20644,
452,
13,
29824,
7,
199,
1875,
63,
1531,
275,
2097,
2611,
5135,
401,
298,
3112,
937,
199,
1875,
63,
1813,
275,
747,
14,
2314,
199,
1875,
63,
1813,
14,
873,
2561,
267,
283,
7762,
356,
283,
5362,
297,
267,
283,
28368,
63,
29911,
356,
283,
5362,
13,
3592,
13,
5135,
13,
784,
310,
14677,
14382,
267,
283,
43,
5569,
63,
4609,
1469,
16260,
356,
283,
2052,
7,
3828,
199,
452,
63,
1419,
275,
1052,
199,
199,
318,
1125,
8,
1328,
304,
272,
984,
14,
3083,
14,
952,
480,
705,
26,
450,
83,
60,
78,
2,
450,
1499,
9,
199,
199,
318,
2449,
8,
1328,
304,
272,
408,
4874,
543,
282,
922,
13,
27131,
1245,
624,
272,
1125,
8,
1328,
9,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
318,
1104,
63,
4989,
837,
272,
408,
13913,
626,
510,
16698,
365,
282,
5114,
2082,
624,
272,
340,
334,
1397,
747,
14,
515,
14,
6292,
360,
2054,
2919,
9021,
3960,
358,
503,
267,
440,
747,
14,
515,
14,
6292,
360,
1047,
15,
5362,
15,
14121,
13,
706,
77,
15,
28033,
8109,
267,
2449,
480,
2765,
3181,
1133,
17021,
370,
506,
376,
603,
4029,
5114,
2935,
531,
199,
199,
318,
1104,
63,
1506,
837,
272,
408,
13913,
626,
314,
1900,
2082,
365,
3451,
1041,
272,
340,
440,
747,
14,
515,
14,
6027,
8,
1506,
63,
694,
304,
267,
862,
26,
288,
747,
14,
8347,
8,
1506,
63,
694,
9,
267,
871,
6440,
465,
3178,
26,
288,
340,
3178,
14,
7931,
508,
7554,
14,
28596,
26,
355,
986,
288,
587,
26,
355,
746,
199,
199,
318,
1678,
63,
888,
8,
493,
12,
620,
304,
272,
870,
283,
24993,
450,
83,
543,
19095,
83,
24908,
78,
7,
450,
334,
493,
12,
620,
9,
272,
347,
888,
275,
1551,
8,
493,
12,
283,
65,
358,
272,
347,
888,
14,
952,
8,
495,
435,
1557,
78,
358,
272,
347,
888,
14,
1600,
342,
199,
199,
318,
8000,
63,
7532,
837,
272,
408,
1002,
314,
2615,
769,
402,
347,
7532,
5827,
367,
642,
3123,
1041,
272,
1561,
275,
1052,
272,
367,
302,
315,
5739,
14,
6463,
360,
1047,
15,
5362,
15,
7532,
32418,
10886,
61,
3300,
59,
16,
13,
25,
13,
3672,
63,
26022,
735,
267,
1561,
59,
736,
14,
515,
14,
4846,
8,
78,
31280,
709,
2677,
275,
302,
272,
367,
302,
315,
5739,
14,
6463,
360,
1047,
15,
5362,
15,
7532,
15,
81,
3893,
10,
63,
26022,
735,
267,
1561,
59,
736,
14,
515,
14,
4846,
8,
78,
31280,
709,
2677,
275,
302,
272,
367,
302,
315,
5739,
14,
6463,
360,
1047,
15,
5362,
15,
7532,
15,
439,
81,
10,
63,
26022,
735,
267,
1561,
59,
736,
14,
515,
14,
4846,
8,
78,
31280,
709,
2677,
275,
302,
272,
372,
1561,
199,
199,
533,
19286,
26,
272,
347,
636,
826,
721,
277,
12,
943,
354,
304,
267,
291,
14,
793,
354,
275,
943,
354,
267,
291,
14,
2592,
275,
1551,
8,
793,
354,
12,
283,
87,
358,
339,
347,
1255,
8,
277,
12,
1249,
304,
267,
4866,
2307,
275,
1551,
2336,
2374,
15,
2307,
297,
283,
82,
358,
267,
6499,
275,
3873,
14,
7942,
8,
589,
12,
9009,
29,
19778,
12,
355,
2589,
29,
1875,
63,
1813,
12,
355,
17080,
29,
16,
12,
355,
3839,
29,
5781,
14,
6089,
12,
355,
4635,
29,
5781,
14,
13850,
9,
267,
2338,
275,
378,
267,
327,
367,
1004,
315,
6499,
14,
2703,
26,
267,
3066,
2592,
275,
6499,
14,
2703,
14,
9843,
342,
267,
1830,
715,
26,
288,
1004,
275,
747,
14,
739,
8,
1773,
2592,
12,
6619,
9,
288,
340,
440,
1004,
26,
355,
2059,
288,
291,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
s40523137/2017springwcm_g5
|
plugin/render_math/math.py
|
30
|
14555
|
# -*- coding: utf-8 -*-
"""
Math Render Plugin for Pelican
==============================
This plugin allows your site to render Math. It uses
the MathJax JavaScript engine.
For markdown, the plugin works by creating a Markdown
extension which is used during the markdown compilation
stage. Math therefore gets treated like a "first class
citizen" in Pelican
For reStructuredText, the plugin instructs the rst engine
to output Mathjax for all math.
The mathjax script is by default automatically inserted
into the HTML.
Typogrify Compatibility
-----------------------
This plugin now plays nicely with Typogrify, but it
requires Typogrify version 2.07 or above.
User Settings
-------------
Users are also able to pass a dictionary of settings
in the settings file which will control how the MathJax
library renders things. This could be very useful for
template builders that want to adjust the look and feel of
the math. See README for more details.
"""
import os
import sys
from pelican import signals, generators
try:
from bs4 import BeautifulSoup
except ImportError as e:
BeautifulSoup = None
try:
from . pelican_mathjax_markdown_extension import PelicanMathJaxExtension
except ImportError as e:
PelicanMathJaxExtension = None
def process_settings(pelicanobj):
"""Sets user specified MathJax settings (see README for more details)"""
mathjax_settings = {}
# NOTE TO FUTURE DEVELOPERS: Look at the README and what is happening in
# this function if any additional changes to the mathjax settings need to
# be incorporated. Also, please inline comment what the variables
# will be used for
# Default settings
mathjax_settings['auto_insert'] = True # if set to true, it will insert mathjax script automatically into content without needing to alter the template.
mathjax_settings['align'] = 'center' # controls alignment of of displayed equations (values can be: left, right, center)
mathjax_settings['indent'] = '0em' # if above is not set to 'center', then this setting acts as an indent
mathjax_settings['show_menu'] = 'true' # controls whether to attach mathjax contextual menu
mathjax_settings['process_escapes'] = 'true' # controls whether escapes are processed
mathjax_settings['latex_preview'] = 'TeX' # controls what user sees while waiting for LaTex to render
mathjax_settings['color'] = 'inherit' # controls color math is rendered in
mathjax_settings['linebreak_automatic'] = 'false' # Set to false by default for performance reasons (see http://docs.mathjax.org/en/latest/output.html#automatic-line-breaking)
mathjax_settings['tex_extensions'] = '' # latex extensions that can be embedded inside mathjax (see http://docs.mathjax.org/en/latest/tex.html#tex-and-latex-extensions)
mathjax_settings['responsive'] = 'false' # Tries to make displayed math responsive
mathjax_settings['responsive_break'] = '768' # The break point at which it math is responsively aligned (in pixels)
mathjax_settings['mathjax_font'] = 'default' # forces mathjax to use the specified font.
mathjax_settings['process_summary'] = BeautifulSoup is not None # will fix up summaries if math is cut off. Requires beautiful soup
mathjax_settings['force_tls'] = 'false' # will force mathjax to be served by https - if set as False, it will only use https if site is served using https
mathjax_settings['message_style'] = 'normal' # This value controls the verbosity of the messages in the lower left-hand corner. Set it to "none" to eliminate all messages
# Source for MathJax
mathjax_settings['source'] = "'//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'"
# Get the user specified settings
try:
settings = pelicanobj.settings['MATH_JAX']
except:
settings = None
# If no settings have been specified, then return the defaults
if not isinstance(settings, dict):
return mathjax_settings
# The following mathjax settings can be set via the settings dictionary
for key, value in ((key, settings[key]) for key in settings):
# Iterate over dictionary in a way that is compatible with both version 2
# and 3 of python
if key == 'align':
try:
typeVal = isinstance(value, basestring)
except NameError:
typeVal = isinstance(value, str)
if not typeVal:
continue
if value == 'left' or value == 'right' or value == 'center':
mathjax_settings[key] = value
else:
mathjax_settings[key] = 'center'
if key == 'indent':
mathjax_settings[key] = value
if key == 'show_menu' and isinstance(value, bool):
mathjax_settings[key] = 'true' if value else 'false'
if key == 'message_style':
mathjax_settings[key] = value if value is not None else 'none'
if key == 'auto_insert' and isinstance(value, bool):
mathjax_settings[key] = value
if key == 'process_escapes' and isinstance(value, bool):
mathjax_settings[key] = 'true' if value else 'false'
if key == 'latex_preview':
try:
typeVal = isinstance(value, basestring)
except NameError:
typeVal = isinstance(value, str)
if not typeVal:
continue
mathjax_settings[key] = value
if key == 'color':
try:
typeVal = isinstance(value, basestring)
except NameError:
typeVal = isinstance(value, str)
if not typeVal:
continue
mathjax_settings[key] = value
if key == 'linebreak_automatic' and isinstance(value, bool):
mathjax_settings[key] = 'true' if value else 'false'
if key == 'process_summary' and isinstance(value, bool):
if value and BeautifulSoup is None:
print("BeautifulSoup4 is needed for summaries to be processed by render_math\nPlease install it")
value = False
mathjax_settings[key] = value
if key == 'responsive' and isinstance(value, bool):
mathjax_settings[key] = 'true' if value else 'false'
if key == 'force_tls' and isinstance(value, bool):
mathjax_settings[key] = 'true' if value else 'false'
if key == 'responsive_break' and isinstance(value, int):
mathjax_settings[key] = str(value)
if key == 'tex_extensions' and isinstance(value, list):
# filter string values, then add '' to them
try:
value = filter(lambda string: isinstance(string, basestring), value)
except NameError:
value = filter(lambda string: isinstance(string, str), value)
value = map(lambda string: "'%s'" % string, value)
mathjax_settings[key] = ',' + ','.join(value)
if key == 'mathjax_font':
try:
typeVal = isinstance(value, basestring)
except NameError:
typeVal = isinstance(value, str)
if not typeVal:
continue
value = value.lower()
if value == 'sanserif':
value = 'SansSerif'
elif value == 'fraktur':
value = 'Fraktur'
elif value == 'typewriter':
value = 'Typewriter'
else:
value = 'default'
mathjax_settings[key] = value
return mathjax_settings
def process_summary(article):
"""Ensures summaries are not cut off. Also inserts
mathjax script so that math will be rendered"""
summary = article._get_summary()
summary_parsed = BeautifulSoup(summary, 'html.parser')
math = summary_parsed.find_all(class_='math')
if len(math) > 0:
last_math_text = math[-1].get_text()
if len(last_math_text) > 3 and last_math_text[-3:] == '...':
content_parsed = BeautifulSoup(article._content, 'html.parser')
full_text = content_parsed.find_all(class_='math')[len(math)-1].get_text()
math[-1].string = "%s ..." % full_text
summary = summary_parsed.decode()
article._summary = "%s<script type='text/javascript'>%s</script>" % (summary, process_summary.mathjax_script)
def configure_typogrify(pelicanobj, mathjax_settings):
"""Instructs Typogrify to ignore math tags - which allows Typogrify
to play nicely with math related content"""
# If Typogrify is not being used, then just exit
if not pelicanobj.settings.get('TYPOGRIFY', False):
return
try:
import typogrify
from distutils.version import LooseVersion
if LooseVersion(typogrify.__version__) < LooseVersion('2.0.7'):
raise TypeError('Incorrect version of Typogrify')
from typogrify.filters import typogrify
# At this point, we are happy to use Typogrify, meaning
# it is installed and it is a recent enough version
# that can be used to ignore all math
# Instantiate markdown extension and append it to the current extensions
pelicanobj.settings['TYPOGRIFY_IGNORE_TAGS'].extend(['.math', 'script']) # ignore math class and script
except (ImportError, TypeError) as e:
pelicanobj.settings['TYPOGRIFY'] = False # disable Typogrify
if isinstance(e, ImportError):
print("\nTypogrify is not installed, so it is being ignored.\nIf you want to use it, please install via: pip install typogrify\n")
if isinstance(e, TypeError):
print("\nA more recent version of Typogrify is needed for the render_math module.\nPlease upgrade Typogrify to the latest version (anything equal or above version 2.0.7 is okay).\nTypogrify will be turned off due to this reason.\n")
def process_mathjax_script(mathjax_settings):
"""Load the mathjax script template from file, and render with the settings"""
# Read the mathjax javascript template from file
with open (os.path.dirname(os.path.realpath(__file__))
+ '/mathjax_script_template', 'r') as mathjax_script_template:
mathjax_template = mathjax_script_template.read()
return mathjax_template.format(**mathjax_settings)
def mathjax_for_markdown(pelicanobj, mathjax_script, mathjax_settings):
"""Instantiates a customized markdown extension for handling mathjax
related content"""
# Create the configuration for the markdown template
config = {}
config['mathjax_script'] = mathjax_script
config['math_tag_class'] = 'math'
config['auto_insert'] = mathjax_settings['auto_insert']
# Instantiate markdown extension and append it to the current extensions
try:
pelicanobj.settings['MD_EXTENSIONS'].append(PelicanMathJaxExtension(config))
except:
sys.excepthook(*sys.exc_info())
sys.stderr.write("\nError - the pelican mathjax markdown extension failed to configure. MathJax is non-functional.\n")
sys.stderr.flush()
def mathjax_for_rst(pelicanobj, mathjax_script):
"""Setup math for RST"""
docutils_settings = pelicanobj.settings.get('DOCUTILS_SETTINGS', {})
docutils_settings['math_output'] = 'MathJax'
pelicanobj.settings['DOCUTILS_SETTINGS'] = docutils_settings
rst_add_mathjax.mathjax_script = mathjax_script
def pelican_init(pelicanobj):
"""
Loads the mathjax script according to the settings.
Instantiate the Python markdown extension, passing in the mathjax
script as config parameter.
"""
# Process settings, and set global var
mathjax_settings = process_settings(pelicanobj)
# Generate mathjax script
mathjax_script = process_mathjax_script(mathjax_settings)
# Configure Typogrify
configure_typogrify(pelicanobj, mathjax_settings)
# Configure Mathjax For Markdown
if PelicanMathJaxExtension:
mathjax_for_markdown(pelicanobj, mathjax_script, mathjax_settings)
# Configure Mathjax For RST
mathjax_for_rst(pelicanobj, mathjax_script)
# Set process_summary's mathjax_script variable
process_summary.mathjax_script = None
if mathjax_settings['process_summary']:
process_summary.mathjax_script = mathjax_script
def rst_add_mathjax(content):
"""Adds mathjax script for reStructuredText"""
# .rst is the only valid extension for reStructuredText files
_, ext = os.path.splitext(os.path.basename(content.source_path))
if ext != '.rst':
return
# If math class is present in text, add the javascript
# note that RST hardwires mathjax to be class "math"
if 'class="math"' in content._content:
content._content += "<script type='text/javascript'>%s</script>" % rst_add_mathjax.mathjax_script
def process_rst_and_summaries(content_generators):
"""
Ensure mathjax script is applied to RST and summaries are
corrected if specified in user settings.
Handles content attached to ArticleGenerator and PageGenerator objects,
since the plugin doesn't know how to handle other Generator types.
For reStructuredText content, examine both articles and pages.
If article or page is reStructuredText and there is math present,
append the mathjax script.
Also process summaries if present (only applies to articles)
and user wants summaries processed (via user settings)
"""
for generator in content_generators:
if isinstance(generator, generators.ArticlesGenerator):
for article in generator.articles + generator.translations:
rst_add_mathjax(article)
#optionally fix truncated formulae in summaries.
if process_summary.mathjax_script is not None:
process_summary(article)
elif isinstance(generator, generators.PagesGenerator):
for page in generator.pages:
rst_add_mathjax(page)
def register():
"""Plugin registration"""
signals.initialized.connect(pelican_init)
signals.all_generators_finalized.connect(process_rst_and_summaries)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
202,
199,
624,
202,
199,
18568,
17769,
11349,
367,
11379,
28091,
202,
199,
1280,
17224,
202,
199,
2765,
3589,
6127,
2195,
4770,
370,
3795,
21066,
14,
2779,
4440,
202,
199,
1589,
21066,
42,
1219,
15250,
6869,
14,
2999,
199,
1858,
18502,
12,
314,
3589,
5419,
701,
6425,
282,
24537,
202,
199,
3435,
1314,
365,
1202,
5309,
314,
18502,
18653,
202,
199,
8614,
14,
221,
21066,
16119,
7545,
10184,
2839,
282,
298,
2246,
1021,
202,
199,
559,
280,
5193,
2,
315,
11379,
28091,
2999,
199,
1858,
295,
27486,
1872,
12,
314,
3589,
315,
23253,
314,
23720,
6869,
202,
199,
475,
1072,
21066,
15863,
367,
1006,
3473,
14,
2999,
199,
1918,
3473,
15863,
2884,
365,
701,
849,
5847,
11788,
202,
199,
9924,
314,
4163,
14,
2999,
199,
32603,
555,
7928,
1399,
3599,
5880,
202,
199,
777,
12797,
202,
199,
2765,
3589,
3063,
299,
9316,
14213,
590,
543,
377,
89,
555,
7928,
1399,
12,
1325,
652,
202,
199,
6537,
377,
89,
555,
7928,
1399,
1015,
499,
14,
1780,
503,
3432,
14,
2999,
199,
1899,
13303,
202,
199,
8684,
202,
199,
12117,
787,
2597,
7688,
370,
986,
282,
2600,
402,
2202,
202,
199,
262,
314,
2202,
570,
1314,
911,
3304,
4212,
314,
21066,
42,
1219,
202,
199,
4342,
3795,
83,
7645,
14,
961,
4293,
506,
7437,
2997,
367,
202,
199,
1160,
27378,
626,
2934,
370,
11311,
314,
3648,
436,
23109,
402,
202,
199,
1589,
3473,
14,
221,
1666,
27781,
367,
1655,
2436,
14,
202,
199,
624,
2999,
199,
646,
747,
202,
199,
646,
984,
2999,
199,
504,
4837,
28091,
492,
10166,
12,
16952,
2999,
199,
893,
26,
1128,
687,
9922,
20,
492,
17132,
202,
199,
2590,
3545,
465,
325,
26,
1128,
17132,
275,
488,
2999,
199,
893,
26,
1128,
687,
1275,
4837,
28091,
63,
3442,
15863,
63,
15653,
63,
3435,
492,
11379,
28091,
18568,
42,
1219,
6382,
202,
199,
2590,
3545,
465,
325,
26,
1128,
11379,
28091,
18568,
42,
1219,
6382,
275,
488,
2999,
199,
318,
2112,
63,
1751,
8,
321,
28091,
1113,
304,
1128,
408,
9899,
922,
2013,
21066,
42,
1219,
2202,
334,
3239,
27781,
367,
1655,
2436,
9471,
2958,
3473,
15863,
63,
1751,
275,
1052,
2958,
327,
6944,
2296,
481,
934,
3942,
3265,
2524,
26515,
3960,
26,
12077,
737,
314,
27781,
436,
4052,
365,
5992,
316,
315,
1128,
327,
642,
805,
340,
1263,
4722,
4493,
370,
314,
3473,
15863,
2202,
1929,
370,
1128,
327,
506,
30147,
972,
14,
6121,
12,
8749,
8308,
3721,
4052,
314,
2860,
1128,
327,
911,
506,
1202,
367,
2958,
327,
3758,
2202,
1128,
3473,
15863,
63,
1751,
459,
2495,
63,
3176,
418,
275,
715,
221,
327,
340,
663,
370,
2549,
12,
652,
911,
5518,
3473,
15863,
2884,
5847,
1901,
1564,
1928,
1929,
316,
370,
17355,
314,
1978,
14,
1128,
3473,
15863,
63,
1751,
459,
5743,
418,
275,
283,
4218,
7,
221,
327,
13467,
13177,
402,
402,
9080,
26426,
334,
1459,
883,
506,
26,
3602,
12,
2451,
12,
8126,
9,
1128,
3473,
15863,
63,
1751,
459,
3724,
418,
275,
283,
16,
5633,
7,
221,
327,
340,
3432,
365,
440,
663,
370,
283,
4218,
297,
2066,
642,
4260,
17795,
465,
376,
4363,
1128,
3473,
15863,
63,
1751,
459,
2384,
63,
4470,
418,
275,
283,
2052,
7,
221,
327,
13467,
3775,
370,
6554,
3473,
15863,
1067,
1061,
6269,
1128,
3473,
15863,
63,
1751,
459,
1412,
63,
3765,
83,
418,
275,
283,
2052,
7,
221,
327,
13467,
3775,
24644,
787,
7686,
1128,
3473,
15863,
63,
1751,
459,
7572,
63,
7780,
418,
275,
283,
12589,
7,
221,
327,
13467,
4052,
922,
542,
397,
1830,
10923,
367,
7964,
13999,
370,
3795,
1128,
3473,
15863,
63,
1751,
459,
2326,
418,
275,
283,
6486,
7,
221,
327,
13467,
3164,
3473,
365,
8018,
315,
1128,
3473,
15863,
63,
1751,
459,
604,
4785,
63,
23292,
418,
275,
283,
3910,
7,
221,
327,
2494,
370,
3055,
701,
849,
367,
10238,
14872,
334,
3239,
1455,
921,
4757,
14,
3442,
15863,
14,
1308,
15,
287,
15,
7410,
15,
1199,
14,
1360,
3,
23292,
13,
604,
13,
4785,
316,
9,
1128,
3473,
15863,
63,
1751,
459,
3858,
63,
5359,
418,
275,
2125,
221,
327,
15571,
5478,
626,
883,
506,
12169,
6272,
3473,
15863,
334,
3239,
1455,
921,
4757,
14,
3442,
15863,
14,
1308,
15,
287,
15,
7410,
15,
3858,
14,
1360,
3,
3858,
13,
460,
13,
7572,
13,
5359,
9,
1128,
3473,
15863,
63,
1751,
459,
3853,
3398,
418,
275,
283,
3910,
7,
221,
327,
377,
1996,
370,
1852,
9080,
3473,
9163,
3398,
1128,
3473,
15863,
63,
1751,
459,
3853,
3398,
63,
4785,
418,
275,
283,
14408,
7,
221,
327,
710,
2059,
2376,
737,
1314,
652,
3473,
365,
9163,
9840,
22569,
334,
262,
11094,
9,
1128,
3473,
15863,
63,
1751,
459,
3442,
15863,
63,
4246,
418,
275,
283,
885,
7,
221,
327,
25983,
3473,
15863,
370,
675,
314,
2013,
5023,
14,
1128,
3473,
15863,
63,
1751,
459,
1412,
63,
4705,
418,
275,
17132,
365,
440,
488,
221,
327,
911,
5325,
1536,
23747,
340,
3473,
365,
10415,
2331,
14,
15127,
506,
25146,
9108,
1128,
3473,
15863,
63,
1751,
459,
3990,
63,
9945,
418,
275,
283,
3910,
7,
221,
327,
911,
3542,
3473,
15863,
370,
506,
19733,
701,
4178,
446,
340,
663,
465,
756,
12,
652,
911,
1454,
675,
4178,
340,
4770,
365,
19733,
1808,
4178,
1128,
3473,
15863,
63,
1751,
459,
1188,
63,
2487,
418,
275,
283,
3302,
7,
221,
327,
961,
574,
13467,
314,
8661,
402,
314,
3788,
315,
314,
5117,
3602,
13,
6868,
17703,
14,
2494,
652,
370,
298,
3592,
2,
370,
20714,
323,
1006,
3788,
2958,
327,
5800,
367,
21066,
42,
1219,
1128,
3473,
15863,
63,
1751,
459,
1365,
418,
275,
3546,
501,
23982,
14,
3442,
15863,
14,
1308,
15,
3442,
15863,
15,
7410,
15,
18568,
42,
1219,
14,
3596,
31,
888,
29,
12589,
13,
1156,
51,
13,
45,
1698,
63,
4943,
269,
45,
1698,
4065,
2958,
327,
2372,
314,
922,
2013,
2202,
1128,
862,
26,
1039,
2202,
275,
4837,
28091,
1113,
14,
1751,
459,
45,
11695,
63,
42,
9839,
418,
1128,
871,
26,
1039,
2202,
275,
488,
2958,
327,
982,
949,
2202,
1172,
2757,
2013,
12,
2066,
372,
314,
4243,
1128,
340,
440,
1228,
8,
1751,
12,
1211,
304,
1039,
372,
3473,
15863,
63,
1751
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
202,
199,
624,
202,
199,
18568,
17769,
11349,
367,
11379,
28091,
202,
199,
1280,
17224,
202,
199,
2765,
3589,
6127,
2195,
4770,
370,
3795,
21066,
14,
2779,
4440,
202,
199,
1589,
21066,
42,
1219,
15250,
6869,
14,
2999,
199,
1858,
18502,
12,
314,
3589,
5419,
701,
6425,
282,
24537,
202,
199,
3435,
1314,
365,
1202,
5309,
314,
18502,
18653,
202,
199,
8614,
14,
221,
21066,
16119,
7545,
10184,
2839,
282,
298,
2246,
1021,
202,
199,
559,
280,
5193,
2,
315,
11379,
28091,
2999,
199,
1858,
295,
27486,
1872,
12,
314,
3589,
315,
23253,
314,
23720,
6869,
202,
199,
475,
1072,
21066,
15863,
367,
1006,
3473,
14,
2999,
199,
1918,
3473,
15863,
2884,
365,
701,
849,
5847,
11788,
202,
199,
9924,
314,
4163,
14,
2999,
199,
32603,
555,
7928,
1399,
3599,
5880,
202,
199,
777,
12797,
202,
199,
2765,
3589,
3063,
299,
9316,
14213,
590,
543,
377,
89,
555,
7928,
1399,
12,
1325,
652,
202,
199,
6537,
377,
89,
555,
7928,
1399,
1015,
499,
14,
1780,
503,
3432,
14,
2999,
199,
1899,
13303,
202,
199,
8684,
202,
199,
12117,
787,
2597,
7688,
370,
986,
282,
2600,
402,
2202,
202,
199,
262,
314,
2202,
570,
1314,
911,
3304,
4212,
314,
21066,
42,
1219,
202,
199,
4342,
3795,
83,
7645,
14,
961,
4293,
506,
7437,
2997,
367,
202,
199,
1160,
27378,
626,
2934,
370,
11311,
314,
3648,
436,
23109,
402,
202,
199,
1589,
3473,
14,
221,
1666,
27781,
367,
1655,
2436,
14,
202,
199,
624,
2999,
199,
646,
747,
202,
199,
646,
984,
2999,
199,
504,
4837,
28091,
492,
10166,
12,
16952,
2999,
199,
893,
26,
1128,
687,
9922,
20,
492,
17132,
202,
199,
2590,
3545,
465,
325,
26,
1128,
17132,
275,
488,
2999,
199,
893,
26,
1128,
687,
1275,
4837,
28091,
63,
3442,
15863,
63,
15653,
63,
3435,
492,
11379,
28091,
18568,
42,
1219,
6382,
202,
199,
2590,
3545,
465,
325,
26,
1128,
11379,
28091,
18568,
42,
1219,
6382,
275,
488,
2999,
199,
318,
2112,
63,
1751,
8,
321,
28091,
1113,
304,
1128,
408,
9899,
922,
2013,
21066,
42,
1219,
2202,
334,
3239,
27781,
367,
1655,
2436,
9471,
2958,
3473,
15863,
63,
1751,
275,
1052,
2958,
327,
6944,
2296,
481,
934,
3942,
3265,
2524,
26515,
3960,
26,
12077,
737,
314,
27781,
436,
4052,
365,
5992,
316,
315,
1128,
327,
642,
805,
340,
1263,
4722,
4493,
370,
314,
3473,
15863,
2202,
1929,
370,
1128,
327,
506,
30147,
972,
14,
6121,
12,
8749,
8308,
3721,
4052,
314,
2860,
1128,
327,
911,
506,
1202,
367,
2958,
327,
3758,
2202,
1128,
3473,
15863,
63,
1751,
459,
2495,
63,
3176,
418,
275,
715,
221,
327,
340,
663,
370,
2549,
12,
652,
911,
5518,
3473,
15863,
2884,
5847,
1901,
1564,
1928,
1929,
316,
370,
17355,
314,
1978,
14,
1128,
3473,
15863,
63,
1751,
459,
5743,
418,
275,
283,
4218,
7,
221,
327,
13467,
13177,
402,
402,
9080,
26426,
334,
1459,
883,
506,
26,
3602,
12,
2451,
12,
8126,
9,
1128,
3473,
15863,
63,
1751,
459,
3724,
418,
275,
283,
16,
5633,
7,
221,
327,
340,
3432,
365,
440,
663,
370,
283,
4218,
297,
2066,
642,
4260,
17795,
465,
376,
4363,
1128,
3473,
15863,
63,
1751,
459,
2384,
63,
4470,
418,
275,
283,
2052,
7,
221,
327,
13467,
3775,
370,
6554,
3473,
15863,
1067,
1061,
6269,
1128,
3473,
15863,
63,
1751,
459,
1412,
63,
3765,
83,
418,
275,
283,
2052,
7,
221,
327,
13467,
3775,
24644,
787,
7686,
1128,
3473,
15863,
63,
1751,
459,
7572,
63,
7780,
418,
275,
283,
12589,
7,
221,
327,
13467,
4052,
922,
542,
397,
1830,
10923,
367,
7964,
13999,
370,
3795,
1128,
3473,
15863,
63,
1751,
459,
2326,
418,
275,
283,
6486,
7,
221,
327,
13467,
3164,
3473,
365,
8018,
315,
1128,
3473,
15863,
63,
1751,
459,
604,
4785,
63,
23292,
418,
275,
283,
3910,
7,
221,
327,
2494,
370,
3055,
701,
849,
367,
10238,
14872,
334,
3239,
1455,
921,
4757,
14,
3442,
15863,
14,
1308,
15,
287,
15,
7410,
15,
1199,
14,
1360,
3,
23292,
13,
604,
13,
4785,
316,
9,
1128,
3473,
15863,
63,
1751,
459,
3858,
63,
5359,
418,
275,
2125,
221,
327,
15571,
5478,
626,
883,
506,
12169,
6272,
3473,
15863,
334,
3239,
1455,
921,
4757,
14,
3442,
15863,
14,
1308,
15,
287,
15,
7410,
15,
3858,
14,
1360,
3,
3858,
13,
460,
13,
7572,
13,
5359,
9,
1128,
3473,
15863,
63,
1751,
459,
3853,
3398,
418,
275,
283,
3910,
7,
221,
327,
377,
1996,
370,
1852,
9080,
3473,
9163,
3398,
1128,
3473,
15863,
63,
1751,
459,
3853,
3398,
63,
4785,
418,
275,
283,
14408,
7,
221,
327,
710,
2059,
2376,
737,
1314,
652,
3473,
365,
9163,
9840,
22569,
334,
262,
11094,
9,
1128,
3473,
15863,
63,
1751,
459,
3442,
15863,
63,
4246,
418,
275,
283,
885,
7,
221,
327,
25983,
3473,
15863,
370,
675,
314,
2013,
5023,
14,
1128,
3473,
15863,
63,
1751,
459,
1412,
63,
4705,
418,
275,
17132,
365,
440,
488,
221,
327,
911,
5325,
1536,
23747,
340,
3473,
365,
10415,
2331,
14,
15127,
506,
25146,
9108,
1128,
3473,
15863,
63,
1751,
459,
3990,
63,
9945,
418,
275,
283,
3910,
7,
221,
327,
911,
3542,
3473,
15863,
370,
506,
19733,
701,
4178,
446,
340,
663,
465,
756,
12,
652,
911,
1454,
675,
4178,
340,
4770,
365,
19733,
1808,
4178,
1128,
3473,
15863,
63,
1751,
459,
1188,
63,
2487,
418,
275,
283,
3302,
7,
221,
327,
961,
574,
13467,
314,
8661,
402,
314,
3788,
315,
314,
5117,
3602,
13,
6868,
17703,
14,
2494,
652,
370,
298,
3592,
2,
370,
20714,
323,
1006,
3788,
2958,
327,
5800,
367,
21066,
42,
1219,
1128,
3473,
15863,
63,
1751,
459,
1365,
418,
275,
3546,
501,
23982,
14,
3442,
15863,
14,
1308,
15,
3442,
15863,
15,
7410,
15,
18568,
42,
1219,
14,
3596,
31,
888,
29,
12589,
13,
1156,
51,
13,
45,
1698,
63,
4943,
269,
45,
1698,
4065,
2958,
327,
2372,
314,
922,
2013,
2202,
1128,
862,
26,
1039,
2202,
275,
4837,
28091,
1113,
14,
1751,
459,
45,
11695,
63,
42,
9839,
418,
1128,
871,
26,
1039,
2202,
275,
488,
2958,
327,
982,
949,
2202,
1172,
2757,
2013,
12,
2066,
372,
314,
4243,
1128,
340,
440,
1228,
8,
1751,
12,
1211,
304,
1039,
372,
3473,
15863,
63,
1751,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
vbannai/disk-qos-horizon
|
horizon/dashboards/syspanel/networks/ports/forms.py
|
2
|
3858
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 NEC Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from horizon import api
from horizon import exceptions
from horizon import forms
from horizon import messages
LOG = logging.getLogger(__name__)
class CreatePort(forms.SelfHandlingForm):
network_name = forms.CharField(label=_("Network Name"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
network_id = forms.CharField(label=_("Network ID"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
name = forms.CharField(max_length=255,
label=_("Name"),
required=False)
device_id = forms.CharField(max_length=100, label=_("Device ID"),
help_text='Device ID attached to the port',
required=False)
def handle(self, request, data):
try:
# We must specify tenant_id of the network which a subnet is
# created for if admin user does not belong to the tenant.
network = api.quantum.network_get(request, data['network_id'])
data['tenant_id'] = network.tenant_id
port = api.quantum.port_create(request, **data)
msg = _('Port %s was successfully created.') % port['id']
LOG.debug(msg)
messages.success(request, msg)
return port
except:
msg = _('Failed to create a port for network %s') \
% data['network_id']
LOG.info(msg)
redirect = reverse('horizon:syspanel:networks:detail',
args=(data['network_id'],))
exceptions.handle(request, msg, redirect=redirect)
class UpdatePort(forms.SelfHandlingForm):
network_id = forms.CharField(widget=forms.HiddenInput())
tenant_id = forms.CharField(widget=forms.HiddenInput())
port_id = forms.CharField(widget=forms.HiddenInput())
name = forms.CharField(max_length=255,
label=_("Name"),
required=False)
device_id = forms.CharField(max_length=100, label=_("Device ID"),
help_text='Device ID attached to the port',
required=False)
def handle(self, request, data):
try:
LOG.debug('params = %s' % data)
port = api.quantum.port_modify(request, data['port_id'],
name=data['name'],
device_id=data['device_id'])
msg = _('Port %s was successfully updated.') % data['port_id']
LOG.debug(msg)
messages.success(request, msg)
return port
except Exception:
msg = _('Failed to update port %s') % data['port_id']
LOG.info(msg)
redirect = reverse('horizon:syspanel:networks:detail',
args=[data['network_id']])
exceptions.handle(request, msg, redirect=redirect)
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
6029,
653,
4220,
11098,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
2050,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
21726,
492,
2986,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
4513,
199,
504,
21726,
492,
3788,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
2790,
4313,
8,
3351,
14,
12887,
26443,
2821,
304,
272,
2784,
63,
354,
275,
4513,
14,
2183,
8,
1302,
9384,
4491,
2812,
1288,
3521,
3938,
29,
3351,
14,
18362,
8,
4318,
3290,
3713,
6753,
356,
283,
6753,
20219,
272,
2784,
63,
344,
275,
4513,
14,
2183,
8,
1302,
9384,
4491,
2870,
1288,
639,
3938,
29,
3351,
14,
18362,
8,
3660,
3290,
3713,
6753,
356,
283,
6753,
20219,
272,
536,
275,
4513,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
2574,
1768,
9384,
985,
1288,
2574,
1415,
29,
797,
9,
272,
2243,
63,
344,
275,
4513,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
1768,
9384,
2510,
2870,
1288,
1816,
1720,
63,
505,
534,
2510,
2870,
10102,
370,
314,
1844,
297,
1816,
1415,
29,
797,
9,
339,
347,
2429,
8,
277,
12,
1056,
12,
666,
304,
267,
862,
26,
288,
327,
2136,
1471,
4165,
8261,
63,
344,
402,
314,
2784,
1314,
282,
6303,
365,
288,
327,
2737,
367,
340,
4628,
922,
1630,
440,
13511,
370,
314,
8261,
14,
288,
2784,
275,
2986,
14,
25999,
14,
1200,
63,
362,
8,
1069,
12,
666,
459,
1200,
63,
344,
1105,
288,
666,
459,
4647,
63,
344,
418,
275,
2784,
14,
4647,
63,
344,
953,
1844,
275,
2986,
14,
25999,
14,
719,
63,
981,
8,
1069,
12,
1011,
576,
9,
288,
1499,
275,
4018,
4313,
450,
83,
1990,
8792,
2737,
2659,
450,
1844,
459,
344,
418,
288,
5051,
14,
1757,
8,
1328,
9,
288,
3788,
14,
3742,
8,
1069,
12,
1499,
9,
288,
372,
1844,
267,
871,
26,
288,
1499,
275,
4018,
4276,
370,
1218,
282,
1844,
367,
2784,
450,
83,
358,
971,
2116,
450,
666,
459,
1200,
63,
344,
418,
288,
5051,
14,
815,
8,
1328,
9,
288,
4660,
275,
3837,
360,
16561,
26,
1274,
7885,
26,
7642,
26,
5506,
297,
3044,
1249,
2687,
576,
459,
1200,
63,
344,
995,
430,
288,
4967,
14,
2479,
8,
1069,
12,
1499,
12,
4660,
29,
4876,
9,
421,
199,
533,
6162,
4313,
8,
3351,
14,
12887,
26443,
2821,
304,
272,
2784,
63,
344,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
25419,
1012,
272,
8261,
63,
344,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
25419,
1012,
272,
1844,
63,
344,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
25419,
1012,
272,
536,
275,
4513,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
2574,
1768,
9384,
985,
1288,
2574,
1415,
29,
797,
9,
272,
2243,
63,
344,
275,
4513,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
1768,
9384,
2510,
2870,
1288,
1816,
1720,
63,
505,
534,
2510,
2870,
10102,
370,
314,
1844,
297,
1816,
1415,
29,
797,
9,
339,
347,
2429,
8,
277,
12,
1056,
12,
666,
304,
267,
862,
26,
288,
5051,
14,
1757,
360,
1162,
275,
450,
83,
7,
450,
666,
9,
288,
1844,
275,
2986,
14,
25999,
14,
719,
63,
8951,
8,
1069,
12,
666,
459,
719,
63,
344,
995,
5644,
536,
29,
576,
459,
354,
995,
5644,
2243,
63,
344,
29,
576,
459,
1782,
63,
344,
1105,
288,
1499,
275,
4018,
4313,
450,
83,
1990,
8792,
4588,
2659,
450,
666,
459,
719,
63,
344,
418,
288,
5051,
14,
1757,
8,
1328,
9,
288,
3788,
14,
3742,
8,
1069,
12,
1499,
9,
288,
372,
1844,
267,
871,
2186,
26,
288,
1499,
275,
4018,
4276,
370,
1678,
1844,
450,
83,
358,
450,
666,
459,
719,
63,
344,
418,
288,
5051,
14,
815,
8,
1328,
9,
288,
4660,
275,
3837,
360,
16561,
26,
1274,
7885,
26,
7642,
26,
5506,
297,
3044,
1249,
1524,
576,
459,
1200,
63,
344,
12121,
288,
4967,
14,
2479,
8,
1069,
12,
1499,
12,
4660,
29,
4876,
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
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
6029,
653,
4220,
11098,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
2050,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
21726,
492,
2986,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
4513,
199,
504,
21726,
492,
3788,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
2790,
4313,
8,
3351,
14,
12887,
26443,
2821,
304,
272,
2784,
63,
354,
275,
4513,
14,
2183,
8,
1302,
9384,
4491,
2812,
1288,
3521,
3938,
29,
3351,
14,
18362,
8,
4318,
3290,
3713,
6753,
356,
283,
6753,
20219,
272,
2784,
63,
344,
275,
4513,
14,
2183,
8,
1302,
9384,
4491,
2870,
1288,
639,
3938,
29,
3351,
14,
18362,
8,
3660,
3290,
3713,
6753,
356,
283,
6753,
20219,
272,
536,
275,
4513,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
2574,
1768,
9384,
985,
1288,
2574,
1415,
29,
797,
9,
272,
2243,
63,
344,
275,
4513,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
1768,
9384,
2510,
2870,
1288,
1816,
1720,
63,
505,
534,
2510,
2870,
10102,
370,
314,
1844,
297,
1816,
1415,
29,
797,
9,
339,
347,
2429,
8,
277,
12,
1056,
12,
666,
304,
267,
862,
26,
288,
327,
2136,
1471,
4165,
8261,
63,
344,
402,
314,
2784,
1314,
282,
6303,
365,
288,
327,
2737,
367,
340,
4628,
922,
1630,
440,
13511,
370,
314,
8261,
14,
288,
2784,
275,
2986,
14,
25999,
14,
1200,
63,
362,
8,
1069,
12,
666,
459,
1200,
63,
344,
1105,
288,
666,
459,
4647,
63,
344,
418,
275,
2784,
14,
4647,
63,
344,
953,
1844,
275,
2986,
14,
25999,
14,
719,
63,
981,
8,
1069,
12,
1011,
576,
9,
288,
1499,
275,
4018,
4313,
450,
83,
1990,
8792,
2737,
2659,
450,
1844,
459,
344,
418,
288,
5051,
14,
1757,
8,
1328,
9,
288,
3788,
14,
3742,
8,
1069,
12,
1499,
9,
288,
372,
1844,
267,
871,
26,
288,
1499,
275,
4018,
4276,
370,
1218,
282,
1844,
367,
2784,
450,
83,
358,
971,
2116,
450,
666,
459,
1200,
63,
344,
418,
288,
5051,
14,
815,
8,
1328,
9,
288,
4660,
275,
3837,
360,
16561,
26,
1274,
7885,
26,
7642,
26,
5506,
297,
3044,
1249,
2687,
576,
459,
1200,
63,
344,
995,
430,
288,
4967,
14,
2479,
8,
1069,
12,
1499,
12,
4660,
29,
4876,
9,
421,
199,
533,
6162,
4313,
8,
3351,
14,
12887,
26443,
2821,
304,
272,
2784,
63,
344,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
25419,
1012,
272,
8261,
63,
344,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
25419,
1012,
272,
1844,
63,
344,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
25419,
1012,
272,
536,
275,
4513,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
2574,
1768,
9384,
985,
1288,
2574,
1415,
29,
797,
9,
272,
2243,
63,
344,
275,
4513,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
1768,
9384,
2510,
2870,
1288,
1816,
1720,
63,
505,
534,
2510,
2870,
10102,
370,
314,
1844,
297,
1816,
1415,
29,
797,
9,
339,
347,
2429,
8,
277,
12,
1056,
12,
666,
304,
267,
862,
26,
288,
5051,
14,
1757,
360,
1162,
275,
450,
83,
7,
450,
666,
9,
288,
1844,
275,
2986,
14,
25999,
14,
719,
63,
8951,
8,
1069,
12,
666,
459,
719,
63,
344,
995,
5644,
536,
29,
576,
459,
354,
995,
5644,
2243,
63,
344,
29,
576,
459,
1782,
63,
344,
1105,
288,
1499,
275,
4018,
4313,
450,
83,
1990,
8792,
4588,
2659,
450,
666,
459,
719,
63,
344,
418,
288,
5051,
14,
1757,
8,
1328,
9,
288,
3788,
14,
3742,
8,
1069,
12,
1499,
9,
288,
372,
1844,
267,
871,
2186,
26,
288,
1499,
275,
4018,
4276,
370,
1678,
1844,
450,
83,
358,
450,
666,
459,
719,
63,
344,
418,
288,
5051,
14,
815,
8,
1328,
9,
288,
4660,
275,
3837,
360,
16561,
26,
1274,
7885,
26,
7642,
26,
5506,
297,
3044,
1249,
1524,
576,
459,
1200,
63,
344,
12121,
288,
4967,
14,
2479,
8,
1069,
12,
1499,
12,
4660,
29,
4876,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
nttdata-osscloud/ceilometer
|
ceilometer/tests/alarm/evaluator/test_combination.py
|
2
|
17579
|
# -*- encoding: utf-8 -*-
#
# Copyright © 2013 eNovance <licensing@enovance.com>
#
# Authors: Mehdi Abaakouk <mehdi.abaakouk@enovance.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Tests for ceilometer/alarm/threshold_evaluation.py
"""
import datetime
import mock
import pytz
import uuid
from ceilometer.alarm.evaluator import combination
from ceilometer.openstack.common import timeutils
from ceilometer.storage import models
from ceilometer.tests.alarm.evaluator import base
from ceilometerclient import exc
from ceilometerclient.v2 import alarms
class TestEvaluate(base.TestEvaluatorBase):
EVALUATOR = combination.CombinationEvaluator
def prepare_alarms(self):
self.alarms = [
models.Alarm(name='or-alarm',
description='the or alarm',
type='combination',
enabled=True,
user_id='foobar',
project_id='snafu',
alarm_id=str(uuid.uuid4()),
state='insufficient data',
state_timestamp=None,
timestamp=None,
insufficient_data_actions=[],
ok_actions=[],
alarm_actions=[],
repeat_actions=False,
time_constraints=[],
rule=dict(
alarm_ids=[
'9cfc3e51-2ff1-4b1d-ac01-c1bd4c6d0d1e',
'1d441595-d069-4e05-95ab-8693ba6a8302'],
operator='or',
)),
models.Alarm(name='and-alarm',
description='the and alarm',
type='combination',
enabled=True,
user_id='foobar',
project_id='snafu',
alarm_id=str(uuid.uuid4()),
state='insufficient data',
state_timestamp=None,
timestamp=None,
insufficient_data_actions=[],
ok_actions=[],
alarm_actions=[],
repeat_actions=False,
time_constraints=[],
rule=dict(
alarm_ids=[
'b82734f4-9d06-48f3-8a86-fa59a0c99dc8',
'15a700e5-2fe8-4b3d-8c55-9e92831f6a2b'],
operator='and',
))
]
@staticmethod
def _get_alarm(state):
return alarms.Alarm(None, {'state': state})
@staticmethod
def _reason_data(alarm_ids):
return {'type': 'combination', 'alarm_ids': alarm_ids}
def _combination_transition_reason(self, state, alarm_ids1, alarm_ids2):
return ([('Transition to %(state)s due to alarms %(alarm_ids)s'
' in state %(state)s')
% {'state': state, 'alarm_ids': ",".join(alarm_ids1)},
('Transition to %(state)s due to alarms %(alarm_ids)s'
' in state %(state)s')
% {'state': state, 'alarm_ids': ",".join(alarm_ids2)}],
[self._reason_data(alarm_ids1), self._reason_data(alarm_ids2)])
def _combination_remaining_reason(self, state, alarm_ids1, alarm_ids2):
return ([('Remaining as %(state)s due to alarms %(alarm_ids)s'
' in state %(state)s')
% {'state': state, 'alarm_ids': ",".join(alarm_ids1)},
('Remaining as %(state)s due to alarms %(alarm_ids)s'
' in state %(state)s')
% {'state': state, 'alarm_ids': ",".join(alarm_ids2)}],
[self._reason_data(alarm_ids1), self._reason_data(alarm_ids2)])
def test_retry_transient_api_failure(self):
with mock.patch('ceilometerclient.client.get_client',
return_value=self.api_client):
broken = exc.CommunicationError(message='broken')
self.api_client.alarms.get.side_effect = [
broken,
broken,
broken,
broken,
self._get_alarm('ok'),
self._get_alarm('ok'),
self._get_alarm('ok'),
self._get_alarm('ok'),
]
self._evaluate_all_alarms()
self._assert_all_alarms('insufficient data')
self._evaluate_all_alarms()
self._assert_all_alarms('ok')
def test_simple_insufficient(self):
self._set_all_alarms('ok')
with mock.patch('ceilometerclient.client.get_client',
return_value=self.api_client):
broken = exc.CommunicationError(message='broken')
self.api_client.alarms.get.side_effect = broken
self._evaluate_all_alarms()
self._assert_all_alarms('insufficient data')
expected = [mock.call(alarm.alarm_id, state='insufficient data')
for alarm in self.alarms]
update_calls = self.api_client.alarms.set_state.call_args_list
self.assertEqual(expected, update_calls)
expected = [mock.call(
alarm,
'ok',
('Alarms %s are in unknown state' %
(",".join(alarm.rule['alarm_ids']))),
self._reason_data(alarm.rule['alarm_ids']))
for alarm in self.alarms]
self.assertEqual(expected, self.notifier.notify.call_args_list)
def test_to_ok_with_all_ok(self):
self._set_all_alarms('insufficient data')
with mock.patch('ceilometerclient.client.get_client',
return_value=self.api_client):
self.api_client.alarms.get.side_effect = [
self._get_alarm('ok'),
self._get_alarm('ok'),
self._get_alarm('ok'),
self._get_alarm('ok'),
]
self._evaluate_all_alarms()
expected = [mock.call(alarm.alarm_id, state='ok')
for alarm in self.alarms]
update_calls = self.api_client.alarms.set_state.call_args_list
self.assertEqual(expected, update_calls)
reasons, reason_datas = self._combination_transition_reason(
'ok',
self.alarms[0].rule['alarm_ids'],
self.alarms[1].rule['alarm_ids'])
expected = [mock.call(alarm, 'insufficient data',
reason, reason_data)
for alarm, reason, reason_data
in zip(self.alarms, reasons, reason_datas)]
self.assertEqual(expected, self.notifier.notify.call_args_list)
def test_to_ok_with_one_alarm(self):
self._set_all_alarms('alarm')
with mock.patch('ceilometerclient.client.get_client',
return_value=self.api_client):
self.api_client.alarms.get.side_effect = [
self._get_alarm('ok'),
self._get_alarm('ok'),
self._get_alarm('alarm'),
self._get_alarm('ok'),
]
self._evaluate_all_alarms()
expected = [mock.call(alarm.alarm_id, state='ok')
for alarm in self.alarms]
update_calls = self.api_client.alarms.set_state.call_args_list
self.assertEqual(expected, update_calls)
reasons, reason_datas = self._combination_transition_reason(
'ok',
self.alarms[0].rule['alarm_ids'],
[self.alarms[1].rule['alarm_ids'][1]])
expected = [mock.call(alarm, 'alarm', reason, reason_data)
for alarm, reason, reason_data
in zip(self.alarms, reasons, reason_datas)]
self.assertEqual(expected, self.notifier.notify.call_args_list)
def test_to_alarm_with_all_alarm(self):
self._set_all_alarms('ok')
with mock.patch('ceilometerclient.client.get_client',
return_value=self.api_client):
self.api_client.alarms.get.side_effect = [
self._get_alarm('alarm'),
self._get_alarm('alarm'),
self._get_alarm('alarm'),
self._get_alarm('alarm'),
]
self._evaluate_all_alarms()
expected = [mock.call(alarm.alarm_id, state='alarm')
for alarm in self.alarms]
update_calls = self.api_client.alarms.set_state.call_args_list
self.assertEqual(expected, update_calls)
reasons, reason_datas = self._combination_transition_reason(
'alarm',
self.alarms[0].rule['alarm_ids'],
self.alarms[1].rule['alarm_ids'])
expected = [mock.call(alarm, 'ok', reason, reason_data)
for alarm, reason, reason_data
in zip(self.alarms, reasons, reason_datas)]
self.assertEqual(expected, self.notifier.notify.call_args_list)
def test_to_alarm_with_one_ok(self):
self._set_all_alarms('ok')
with mock.patch('ceilometerclient.client.get_client',
return_value=self.api_client):
self.api_client.alarms.get.side_effect = [
self._get_alarm('ok'),
self._get_alarm('alarm'),
self._get_alarm('alarm'),
self._get_alarm('alarm'),
]
self._evaluate_all_alarms()
expected = [mock.call(alarm.alarm_id, state='alarm')
for alarm in self.alarms]
update_calls = self.api_client.alarms.set_state.call_args_list
self.assertEqual(expected, update_calls)
reasons, reason_datas = self._combination_transition_reason(
'alarm',
[self.alarms[0].rule['alarm_ids'][1]],
self.alarms[1].rule['alarm_ids'])
expected = [mock.call(alarm, 'ok', reason, reason_data)
for alarm, reason, reason_data
in zip(self.alarms, reasons, reason_datas)]
self.assertEqual(expected, self.notifier.notify.call_args_list)
def test_to_unknown(self):
self._set_all_alarms('ok')
with mock.patch('ceilometerclient.client.get_client',
return_value=self.api_client):
broken = exc.CommunicationError(message='broken')
self.api_client.alarms.get.side_effect = [
broken,
self._get_alarm('ok'),
self._get_alarm('insufficient data'),
self._get_alarm('ok'),
]
self._evaluate_all_alarms()
expected = [mock.call(alarm.alarm_id, state='insufficient data')
for alarm in self.alarms]
update_calls = self.api_client.alarms.set_state.call_args_list
self.assertEqual(expected, update_calls)
reasons = ['Alarms %s are in unknown state'
% self.alarms[0].rule['alarm_ids'][0],
'Alarms %s are in unknown state'
% self.alarms[1].rule['alarm_ids'][0]]
reason_datas = [
self._reason_data([self.alarms[0].rule['alarm_ids'][0]]),
self._reason_data([self.alarms[1].rule['alarm_ids'][0]])]
expected = [mock.call(alarm, 'ok', reason, reason_data)
for alarm, reason, reason_data
in zip(self.alarms, reasons, reason_datas)]
self.assertEqual(expected, self.notifier.notify.call_args_list)
def test_no_state_change(self):
self._set_all_alarms('ok')
with mock.patch('ceilometerclient.client.get_client',
return_value=self.api_client):
self.api_client.alarms.get.side_effect = [
self._get_alarm('ok'),
self._get_alarm('ok'),
self._get_alarm('ok'),
self._get_alarm('ok'),
]
self._evaluate_all_alarms()
update_calls = self.api_client.alarms.set_state.call_args_list
self.assertEqual([], update_calls)
self.assertEqual([], self.notifier.notify.call_args_list)
def test_no_state_change_and_repeat_actions(self):
self.alarms[0].repeat_actions = True
self.alarms[1].repeat_actions = True
self._set_all_alarms('ok')
with mock.patch('ceilometerclient.client.get_client',
return_value=self.api_client):
self.api_client.alarms.get.side_effect = [
self._get_alarm('ok'),
self._get_alarm('ok'),
self._get_alarm('ok'),
self._get_alarm('ok'),
]
self._evaluate_all_alarms()
update_calls = self.api_client.alarms.set_state.call_args_list
self.assertEqual([], update_calls)
reasons, reason_datas = self._combination_remaining_reason(
'ok',
self.alarms[0].rule['alarm_ids'],
self.alarms[1].rule['alarm_ids'])
expected = [mock.call(alarm, 'ok', reason, reason_data)
for alarm, reason, reason_data
in zip(self.alarms, reasons, reason_datas)]
self.assertEqual(expected, self.notifier.notify.call_args_list)
@mock.patch.object(timeutils, 'utcnow')
def test_state_change_inside_time_constraint(self, mock_utcnow):
self._set_all_alarms('insufficient data')
self.alarms[0].time_constraints = [
{'name': 'test',
'description': 'test',
'start': '0 11 * * *', # daily at 11:00
'duration': 10800, # 3 hours
'timezone': 'Europe/Ljubljana'}
]
self.alarms[1].time_constraints = self.alarms[0].time_constraints
dt = datetime.datetime(2014, 1, 1, 12, 0, 0,
tzinfo=pytz.timezone('Europe/Ljubljana'))
mock_utcnow.return_value = dt.astimezone(pytz.UTC)
with mock.patch('ceilometerclient.client.get_client',
return_value=self.api_client):
self.api_client.alarms.get.side_effect = [
self._get_alarm('ok'),
self._get_alarm('ok'),
self._get_alarm('ok'),
self._get_alarm('ok'),
]
self._evaluate_all_alarms()
expected = [mock.call(alarm.alarm_id, state='ok')
for alarm in self.alarms]
update_calls = self.api_client.alarms.set_state.call_args_list
self.assertEqual(expected, update_calls,
"Alarm should change state if the current "
"time is inside its time constraint.")
reasons, reason_datas = self._combination_transition_reason(
'ok',
self.alarms[0].rule['alarm_ids'],
self.alarms[1].rule['alarm_ids'])
expected = [mock.call(alarm, 'insufficient data',
reason, reason_data)
for alarm, reason, reason_data
in zip(self.alarms, reasons, reason_datas)]
self.assertEqual(expected, self.notifier.notify.call_args_list)
@mock.patch.object(timeutils, 'utcnow')
def test_no_state_change_outside_time_constraint(self, mock_utcnow):
self._set_all_alarms('insufficient data')
self.alarms[0].time_constraints = [
{'name': 'test',
'description': 'test',
'start': '0 11 * * *', # daily at 11:00
'duration': 10800, # 3 hours
'timezone': 'Europe/Ljubljana'}
]
self.alarms[1].time_constraints = self.alarms[0].time_constraints
dt = datetime.datetime(2014, 1, 1, 15, 0, 0,
tzinfo=pytz.timezone('Europe/Ljubljana'))
mock_utcnow.return_value = dt.astimezone(pytz.UTC)
with mock.patch('ceilometerclient.client.get_client',
return_value=self.api_client):
self.api_client.alarms.get.side_effect = [
self._get_alarm('ok'),
self._get_alarm('ok'),
self._get_alarm('ok'),
self._get_alarm('ok'),
]
self._evaluate_all_alarms()
update_calls = self.api_client.alarms.set_state.call_args_list
self.assertEqual([], update_calls,
"Alarm should not change state if the current "
" time is outside its time constraint.")
self.assertEqual([], self.notifier.notify.call_args_list)
|
apache-2.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
22405,
103,
6171,
325,
1944,
6278,
665,
606,
25843,
32,
287,
79,
6278,
14,
957,
30,
199,
3,
199,
3,
6642,
26,
3194,
72,
328,
437,
2470,
1151,
810,
75,
665,
278,
72,
328,
14,
20338,
1151,
810,
75,
32,
287,
79,
6278,
14,
957,
30,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
624,
2925,
367,
10142,
25617,
15,
14160,
15,
7227,
63,
19154,
14,
647,
199,
624,
199,
646,
2197,
199,
646,
1683,
199,
646,
15444,
199,
646,
5377,
199,
199,
504,
10142,
25617,
14,
14160,
14,
27406,
492,
14665,
199,
504,
10142,
25617,
14,
8512,
14,
2330,
492,
23011,
199,
504,
10142,
25617,
14,
3494,
492,
1709,
199,
504,
10142,
25617,
14,
2219,
14,
14160,
14,
27406,
492,
1300,
199,
504,
10142,
25617,
1258,
492,
3178,
199,
504,
10142,
25617,
1258,
14,
86,
18,
492,
741,
25005,
421,
199,
533,
1379,
25002,
8,
1095,
14,
774,
10006,
16530,
1563,
304,
272,
662,
3204,
53,
6467,
275,
14665,
14,
17039,
425,
10006,
16530,
339,
347,
9275,
63,
279,
25005,
8,
277,
304,
267,
291,
14,
279,
25005,
275,
359,
288,
1709,
14,
30655,
8,
354,
534,
269,
13,
14160,
297,
586,
1369,
534,
1589,
503,
17987,
297,
586,
730,
534,
6560,
3155,
297,
586,
5223,
29,
549,
12,
586,
922,
63,
344,
534,
9664,
297,
586,
2199,
63,
344,
534,
5167,
2756,
85,
297,
586,
17987,
63,
344,
29,
495,
8,
2580,
14,
2580,
20,
4000,
586,
1174,
534,
3617,
12983,
666,
297,
586,
1174,
63,
3954,
29,
403,
12,
586,
4913,
29,
403,
12,
586,
5261,
12983,
63,
576,
63,
3723,
6034,
586,
4112,
63,
3723,
6034,
586,
17987,
63,
3723,
6034,
586,
11982,
63,
3723,
29,
797,
12,
586,
900,
63,
9882,
6034,
586,
2332,
29,
807,
8,
2490,
17987,
63,
1580,
1524,
639,
283,
25,
2177,
67,
19,
69,
2869,
13,
18,
556,
17,
13,
20,
66,
17,
68,
13,
645,
614,
13,
67,
17,
3691,
20,
67,
22,
68,
16,
68,
17,
69,
297,
639,
283,
17,
68,
1602,
1046,
2720,
13,
68,
18264,
13,
20,
69,
1717,
13,
2720,
371,
13,
1184,
3129,
2470,
22,
65,
2658,
996,
995,
2490,
4182,
534,
269,
297,
586,
22583,
288,
1709,
14,
30655,
8,
354,
534,
460,
13,
14160,
297,
586,
1369,
534,
1589,
436,
17987,
297,
586,
730,
534,
6560,
3155,
297,
586,
5223,
29,
549,
12,
586,
922,
63,
344,
534,
9664,
297,
586,
2199,
63,
344,
534,
5167,
2756,
85,
297,
586,
17987,
63,
344,
29,
495,
8,
2580,
14,
2580,
20,
4000,
586,
1174,
534,
3617,
12983,
666,
297,
586,
1174,
63,
3954,
29,
403,
12,
586,
4913,
29,
403,
12,
586,
5261,
12983,
63,
576,
63,
3723,
6034,
586,
4112,
63,
3723,
6034,
586,
17987,
63,
3723,
6034,
586,
11982,
63,
3723,
29,
797,
12,
586,
900,
63,
9882,
6034,
586,
2332,
29,
807,
8,
2490,
17987,
63,
1580,
1524,
639,
283,
66,
32096,
1082,
70,
20,
13,
25,
68,
1690,
13,
2006,
70,
19,
13,
24,
65,
1184,
13,
667,
1427,
65,
16,
67,
1020,
3833,
24,
297,
639,
283,
1046,
65,
15946,
69,
21,
13,
18,
771,
24,
13,
20,
66,
19,
68,
13,
24,
67,
1229,
13,
25,
69,
25,
1651,
2192,
70,
22,
65,
18,
66,
995,
2490,
4182,
534,
460,
297,
586,
5082,
267,
1622,
339,
768,
4639,
272,
347,
485,
362,
63,
14160,
8,
929,
304,
267,
372,
741,
25005,
14,
30655,
8,
403,
12,
791,
929,
356,
1174,
1552,
339,
768,
4639,
272,
347,
485,
5764,
63,
576,
8,
14160,
63,
1580,
304,
267,
372,
791,
466,
356,
283,
6560,
3155,
297,
283,
14160,
63,
1580,
356,
17987,
63,
1580,
93,
339,
347,
485,
6560,
3155,
63,
14143,
63,
5764,
8,
277,
12,
1174,
12,
17987,
63,
1580,
17,
12,
17987,
63,
1580,
18,
304,
267,
372,
26236,
21881,
370,
2818,
929,
9,
83,
7037,
370,
741,
25005,
2818,
14160,
63,
1580,
9,
83,
7,
355,
283,
315,
1174,
2818,
929,
9,
83,
358,
355,
450,
791,
929,
356,
1174,
12,
283,
14160,
63,
1580,
356,
19089,
904,
8,
14160,
63,
1580,
17,
16658,
355,
661,
21881,
370,
2818,
929,
9,
83,
7037,
370,
741,
25005,
2818,
14160,
63,
1580,
9,
83,
7,
355,
283,
315,
1174,
2818,
929,
9,
83,
358,
355,
450,
791,
929,
356,
1174,
12,
283,
14160,
63,
1580,
356,
19089,
904,
8,
14160,
63,
1580,
18,
6769,
467,
355,
359,
277,
423,
5764,
63,
576,
8,
14160,
63,
1580,
17,
395,
291,
423,
5764,
63,
576,
8,
14160,
63,
1580,
18,
3948,
339,
347,
485,
6560,
3155,
63,
11266,
63,
5764,
8,
277,
12,
1174,
12,
17987,
63,
1580,
17,
12,
17987,
63,
1580,
18,
304,
267,
372,
26236,
31109,
465,
2818,
929,
9,
83,
7037,
370,
741,
25005,
2818,
14160,
63,
1580,
9,
83,
7,
326,
283,
315,
1174,
2818,
929,
9,
83,
358,
355,
450,
791,
929,
356,
1174,
12,
283,
14160,
63,
1580,
356,
19089,
904,
8,
14160,
63,
1580,
17,
16658,
355,
661,
31109,
465,
2818,
929,
9,
83,
7037,
370,
741,
25005,
2818,
14160,
63,
1580,
9,
83,
7,
326,
283,
315,
1174,
2818,
929,
9,
83,
358,
355,
450,
791,
929,
356,
1174,
12,
283,
14160,
63,
1580,
356,
19089,
904,
8,
14160,
63,
1580,
18,
6769,
467,
355,
359,
277,
423,
5764,
63,
576,
8,
14160,
63,
1580,
17
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
22405,
103,
6171,
325,
1944,
6278,
665,
606,
25843,
32,
287,
79,
6278,
14,
957,
30,
199,
3,
199,
3,
6642,
26,
3194,
72,
328,
437,
2470,
1151,
810,
75,
665,
278,
72,
328,
14,
20338,
1151,
810,
75,
32,
287,
79,
6278,
14,
957,
30,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
624,
2925,
367,
10142,
25617,
15,
14160,
15,
7227,
63,
19154,
14,
647,
199,
624,
199,
646,
2197,
199,
646,
1683,
199,
646,
15444,
199,
646,
5377,
199,
199,
504,
10142,
25617,
14,
14160,
14,
27406,
492,
14665,
199,
504,
10142,
25617,
14,
8512,
14,
2330,
492,
23011,
199,
504,
10142,
25617,
14,
3494,
492,
1709,
199,
504,
10142,
25617,
14,
2219,
14,
14160,
14,
27406,
492,
1300,
199,
504,
10142,
25617,
1258,
492,
3178,
199,
504,
10142,
25617,
1258,
14,
86,
18,
492,
741,
25005,
421,
199,
533,
1379,
25002,
8,
1095,
14,
774,
10006,
16530,
1563,
304,
272,
662,
3204,
53,
6467,
275,
14665,
14,
17039,
425,
10006,
16530,
339,
347,
9275,
63,
279,
25005,
8,
277,
304,
267,
291,
14,
279,
25005,
275,
359,
288,
1709,
14,
30655,
8,
354,
534,
269,
13,
14160,
297,
586,
1369,
534,
1589,
503,
17987,
297,
586,
730,
534,
6560,
3155,
297,
586,
5223,
29,
549,
12,
586,
922,
63,
344,
534,
9664,
297,
586,
2199,
63,
344,
534,
5167,
2756,
85,
297,
586,
17987,
63,
344,
29,
495,
8,
2580,
14,
2580,
20,
4000,
586,
1174,
534,
3617,
12983,
666,
297,
586,
1174,
63,
3954,
29,
403,
12,
586,
4913,
29,
403,
12,
586,
5261,
12983,
63,
576,
63,
3723,
6034,
586,
4112,
63,
3723,
6034,
586,
17987,
63,
3723,
6034,
586,
11982,
63,
3723,
29,
797,
12,
586,
900,
63,
9882,
6034,
586,
2332,
29,
807,
8,
2490,
17987,
63,
1580,
1524,
639,
283,
25,
2177,
67,
19,
69,
2869,
13,
18,
556,
17,
13,
20,
66,
17,
68,
13,
645,
614,
13,
67,
17,
3691,
20,
67,
22,
68,
16,
68,
17,
69,
297,
639,
283,
17,
68,
1602,
1046,
2720,
13,
68,
18264,
13,
20,
69,
1717,
13,
2720,
371,
13,
1184,
3129,
2470,
22,
65,
2658,
996,
995,
2490,
4182,
534,
269,
297,
586,
22583,
288,
1709,
14,
30655,
8,
354,
534,
460,
13,
14160,
297,
586,
1369,
534,
1589,
436,
17987,
297,
586,
730,
534,
6560,
3155,
297,
586,
5223,
29,
549,
12,
586,
922,
63,
344,
534,
9664,
297,
586,
2199,
63,
344,
534,
5167,
2756,
85,
297,
586,
17987,
63,
344,
29,
495,
8,
2580,
14,
2580,
20,
4000,
586,
1174,
534,
3617,
12983,
666,
297,
586,
1174,
63,
3954,
29,
403,
12,
586,
4913,
29,
403,
12,
586,
5261,
12983,
63,
576,
63,
3723,
6034,
586,
4112,
63,
3723,
6034,
586,
17987,
63,
3723,
6034,
586,
11982,
63,
3723,
29,
797,
12,
586,
900,
63,
9882,
6034,
586,
2332,
29,
807,
8,
2490,
17987,
63,
1580,
1524,
639,
283,
66,
32096,
1082,
70,
20,
13,
25,
68,
1690,
13,
2006,
70,
19,
13,
24,
65,
1184,
13,
667,
1427,
65,
16,
67,
1020,
3833,
24,
297,
639,
283,
1046,
65,
15946,
69,
21,
13,
18,
771,
24,
13,
20,
66,
19,
68,
13,
24,
67,
1229,
13,
25,
69,
25,
1651,
2192,
70,
22,
65,
18,
66,
995,
2490,
4182,
534,
460,
297,
586,
5082,
267,
1622,
339,
768,
4639,
272,
347,
485,
362,
63,
14160,
8,
929,
304,
267,
372,
741,
25005,
14,
30655,
8,
403,
12,
791,
929,
356,
1174,
1552,
339,
768,
4639,
272,
347,
485,
5764,
63,
576,
8,
14160,
63,
1580,
304,
267,
372,
791,
466,
356,
283,
6560,
3155,
297,
283,
14160,
63,
1580,
356,
17987,
63,
1580,
93,
339,
347,
485,
6560,
3155,
63,
14143,
63,
5764,
8,
277,
12,
1174,
12,
17987,
63,
1580,
17,
12,
17987,
63,
1580,
18,
304,
267,
372,
26236,
21881,
370,
2818,
929,
9,
83,
7037,
370,
741,
25005,
2818,
14160,
63,
1580,
9,
83,
7,
355,
283,
315,
1174,
2818,
929,
9,
83,
358,
355,
450,
791,
929,
356,
1174,
12,
283,
14160,
63,
1580,
356,
19089,
904,
8,
14160,
63,
1580,
17,
16658,
355,
661,
21881,
370,
2818,
929,
9,
83,
7037,
370,
741,
25005,
2818,
14160,
63,
1580,
9,
83,
7,
355,
283,
315,
1174,
2818,
929,
9,
83,
358,
355,
450,
791,
929,
356,
1174,
12,
283,
14160,
63,
1580,
356,
19089,
904,
8,
14160,
63,
1580,
18,
6769,
467,
355,
359,
277,
423,
5764,
63,
576,
8,
14160,
63,
1580,
17,
395,
291,
423,
5764,
63,
576,
8,
14160,
63,
1580,
18,
3948,
339,
347,
485,
6560,
3155,
63,
11266,
63,
5764,
8,
277,
12,
1174,
12,
17987,
63,
1580,
17,
12,
17987,
63,
1580,
18,
304,
267,
372,
26236,
31109,
465,
2818,
929,
9,
83,
7037,
370,
741,
25005,
2818,
14160,
63,
1580,
9,
83,
7,
326,
283,
315,
1174,
2818,
929,
9,
83,
358,
355,
450,
791,
929,
356,
1174,
12,
283,
14160,
63,
1580,
356,
19089,
904,
8,
14160,
63,
1580,
17,
16658,
355,
661,
31109,
465,
2818,
929,
9,
83,
7037,
370,
741,
25005,
2818,
14160,
63,
1580,
9,
83,
7,
326,
283,
315,
1174,
2818,
929,
9,
83,
358,
355,
450,
791,
929,
356,
1174,
12,
283,
14160,
63,
1580,
356,
19089,
904,
8,
14160,
63,
1580,
18,
6769,
467,
355,
359,
277,
423,
5764,
63,
576,
8,
14160,
63,
1580,
17,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
quantifiedcode-bot/invenio-deposit
|
invenio_deposit/fields/pages_number.py
|
7
|
1526
|
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2012, 2013, 2014, 2015 CERN.
#
# Invenio 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.
#
# Invenio 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 Invenio; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""Deprecated."""
from wtforms import StringField
from ..field_base import WebDepositField
# from ..validation_utils import number_validate
__all__ = ['PagesNumberField']
class PagesNumberField(WebDepositField, StringField):
"""Deprecated."""
def __init__(self, **kwargs):
"""Deprecated."""
import warnings
warnings.warn("Field has been deprecated",
PendingDeprecationWarning)
defaults = dict(
icon='th',
widget_classes="form-control"
# FIXME validators=[
# number_validate(error_message='Pages must be a number!')]
)
defaults.update(kwargs)
super(PagesNumberField, self).__init__(**defaults)
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
6029,
12,
6171,
12,
6927,
12,
6900,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
19727,
1041,
199,
199,
504,
24756,
3351,
492,
21409,
199,
199,
504,
2508,
698,
63,
1095,
492,
6001,
872,
21759,
792,
199,
199,
3,
687,
2508,
6136,
63,
1208,
492,
1329,
63,
3502,
199,
199,
363,
452,
363,
275,
788,
17773,
3259,
792,
418,
421,
199,
533,
510,
7441,
3259,
792,
8,
5926,
872,
21759,
792,
12,
21409,
304,
339,
408,
19727,
1041,
339,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
408,
19727,
1041,
267,
492,
3598,
267,
3598,
14,
4050,
480,
792,
965,
2757,
5906,
401,
1993,
29216,
15561,
9,
267,
4243,
275,
1211,
8,
288,
7016,
534,
273,
297,
288,
3938,
63,
2888,
628,
964,
13,
2785,
2,
288,
327,
7600,
14370,
1524,
288,
327,
1329,
63,
3502,
8,
705,
63,
1188,
534,
17773,
1471,
506,
282,
1329,
1,
5440,
267,
776,
267,
4243,
14,
873,
8,
958,
9,
267,
1613,
8,
17773,
3259,
792,
12,
291,
2843,
826,
14155,
4322,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
6029,
12,
6171,
12,
6927,
12,
6900,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
19727,
1041,
199,
199,
504,
24756,
3351,
492,
21409,
199,
199,
504,
2508,
698,
63,
1095,
492,
6001,
872,
21759,
792,
199,
199,
3,
687,
2508,
6136,
63,
1208,
492,
1329,
63,
3502,
199,
199,
363,
452,
363,
275,
788,
17773,
3259,
792,
418,
421,
199,
533,
510,
7441,
3259,
792,
8,
5926,
872,
21759,
792,
12,
21409,
304,
339,
408,
19727,
1041,
339,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
408,
19727,
1041,
267,
492,
3598,
267,
3598,
14,
4050,
480,
792,
965,
2757,
5906,
401,
1993,
29216,
15561,
9,
267,
4243,
275,
1211,
8,
288,
7016,
534,
273,
297,
288,
3938,
63,
2888,
628,
964,
13,
2785,
2,
288,
327,
7600,
14370,
1524,
288,
327,
1329,
63,
3502,
8,
705,
63,
1188,
534,
17773,
1471,
506,
282,
1329,
1,
5440,
267,
776,
267,
4243,
14,
873,
8,
958,
9,
267,
1613,
8,
17773,
3259,
792,
12,
291,
2843,
826,
14155,
4322,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
openmicroscopy/openmicroscopy
|
examples/Training/python/Advanced/Write_data_advanced.py
|
3
|
1817
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 University of Dundee & Open Microscopy Environment.
# All Rights Reserved.
# Use is subject to license terms supplied in LICENSE.txt
#
"""
FOR TRAINING PURPOSES ONLY!
"""
from __future__ import print_function
import omero
from omero.rtypes import rstring
from omero.gateway import BlitzGateway
from Parse_OMERO_Properties import USERNAME, PASSWORD, HOST, PORT
# Create a connection
# =================================================================
conn = BlitzGateway(USERNAME, PASSWORD, host=HOST, port=PORT)
conn.connect()
# Create a new Dataset
# =================================================================
dataset = omero.model.DatasetI()
dataset.setName(rstring("New Dataset"))
dataset = conn.getUpdateService().saveAndReturnObject(dataset)
print("New dataset, Id:", dataset.getId().getValue())
dataset2 = omero.model.DatasetI()
dataset2.setName(rstring("New Dataset2"))
dataset2 = conn.getUpdateService().saveAndReturnObject(dataset2)
print("New dataset 2, Id:", dataset2.getId().getValue())
# How to annotate multiple Datasets
# =================================================================
# 1. you define objects you want to tag
dataset_list = [dataset, dataset2]
# 2. create a tag
tag = omero.model.TagAnnotationI()
tag.setTextValue(rstring("new tag"))
# 3. build a list of links
link_list = list()
for ds in dataset_list:
link = omero.model.DatasetAnnotationLinkI()
link.setParent(ds)
link.setChild(tag)
link_list.append(link)
# 4. save the links to the server
conn.getUpdateService().saveArray(link_list)
# Close connection:
# =================================================================
# When you are done, close the session to free up server resources.
conn.close()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
199,
3,
1898,
334,
35,
9,
7760,
15904,
402,
577,
324,
11192,
1253,
3232,
27022,
83,
1574,
9711,
14,
199,
3,
8540,
2900,
5924,
5702,
14,
199,
3,
3645,
365,
5420,
370,
4190,
2895,
6841,
315,
5113,
14,
2424,
199,
3,
199,
199,
624,
199,
2707,
377,
21715,
1206,
3084,
9263,
654,
5258,
6084,
1,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
27122,
199,
504,
27122,
14,
82,
1313,
492,
519,
875,
199,
504,
27122,
14,
7019,
492,
699,
29382,
12455,
199,
504,
6077,
63,
7474,
12960,
63,
8516,
492,
13044,
2339,
12,
21705,
5172,
12,
25741,
12,
25562,
421,
199,
3,
2790,
282,
1950,
199,
3,
7819,
199,
1631,
275,
699,
29382,
12455,
8,
11958,
12,
21705,
5172,
12,
1591,
29,
5449,
12,
1844,
29,
3657,
9,
199,
1631,
14,
2242,
342,
199,
199,
3,
2790,
282,
892,
20284,
199,
3,
7819,
199,
5214,
275,
27122,
14,
1238,
14,
9271,
41,
342,
199,
5214,
14,
18347,
8,
82,
875,
480,
4665,
20284,
2237,
199,
5214,
275,
2557,
14,
362,
4152,
3167,
1252,
2117,
8572,
1692,
8,
5214,
9,
199,
1361,
480,
4665,
4789,
12,
15418,
6783,
4789,
14,
362,
1304,
1252,
17186,
1012,
199,
199,
5214,
18,
275,
27122,
14,
1238,
14,
9271,
41,
342,
199,
5214,
18,
14,
18347,
8,
82,
875,
480,
4665,
20284,
18,
2237,
199,
5214,
18,
275,
2557,
14,
362,
4152,
3167,
1252,
2117,
8572,
1692,
8,
5214,
18,
9,
199,
1361,
480,
4665,
4789,
499,
12,
15418,
6783,
4789,
18,
14,
362,
1304,
1252,
17186,
1012,
421,
199,
3,
7494,
370,
28987,
3663,
3918,
2193,
199,
3,
7819,
199,
3,
413,
14,
1265,
5627,
2251,
1265,
2934,
370,
1947,
199,
5214,
63,
513,
275,
359,
5214,
12,
4789,
18,
61,
199,
199,
3,
499,
14,
1218,
282,
1947,
199,
1450,
275,
27122,
14,
1238,
14,
1931,
16768,
41,
342,
199,
1450,
14,
8341,
1110,
8,
82,
875,
480,
1222,
1947,
2237,
199,
199,
3,
650,
14,
1900,
282,
769,
402,
6220,
199,
1073,
63,
513,
275,
769,
342,
199,
509,
6364,
315,
4789,
63,
513,
26,
272,
2142,
275,
27122,
14,
1238,
14,
9271,
16768,
3834,
41,
342,
272,
2142,
14,
409,
6652,
8,
795,
9,
272,
2142,
14,
409,
3493,
8,
1450,
9,
272,
2142,
63,
513,
14,
740,
8,
1073,
9,
199,
199,
3,
841,
14,
3354,
314,
6220,
370,
314,
1654,
199,
1631,
14,
362,
4152,
3167,
1252,
2117,
3836,
8,
1073,
63,
513,
9,
421,
199,
3,
15524,
1950,
26,
199,
3,
7819,
199,
3,
3979,
1265,
787,
4224,
12,
4002,
314,
2351,
370,
2867,
1536,
1654,
5944,
14,
199,
1631,
14,
1600,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
199,
3,
1898,
334,
35,
9,
7760,
15904,
402,
577,
324,
11192,
1253,
3232,
27022,
83,
1574,
9711,
14,
199,
3,
8540,
2900,
5924,
5702,
14,
199,
3,
3645,
365,
5420,
370,
4190,
2895,
6841,
315,
5113,
14,
2424,
199,
3,
199,
199,
624,
199,
2707,
377,
21715,
1206,
3084,
9263,
654,
5258,
6084,
1,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
27122,
199,
504,
27122,
14,
82,
1313,
492,
519,
875,
199,
504,
27122,
14,
7019,
492,
699,
29382,
12455,
199,
504,
6077,
63,
7474,
12960,
63,
8516,
492,
13044,
2339,
12,
21705,
5172,
12,
25741,
12,
25562,
421,
199,
3,
2790,
282,
1950,
199,
3,
7819,
199,
1631,
275,
699,
29382,
12455,
8,
11958,
12,
21705,
5172,
12,
1591,
29,
5449,
12,
1844,
29,
3657,
9,
199,
1631,
14,
2242,
342,
199,
199,
3,
2790,
282,
892,
20284,
199,
3,
7819,
199,
5214,
275,
27122,
14,
1238,
14,
9271,
41,
342,
199,
5214,
14,
18347,
8,
82,
875,
480,
4665,
20284,
2237,
199,
5214,
275,
2557,
14,
362,
4152,
3167,
1252,
2117,
8572,
1692,
8,
5214,
9,
199,
1361,
480,
4665,
4789,
12,
15418,
6783,
4789,
14,
362,
1304,
1252,
17186,
1012,
199,
199,
5214,
18,
275,
27122,
14,
1238,
14,
9271,
41,
342,
199,
5214,
18,
14,
18347,
8,
82,
875,
480,
4665,
20284,
18,
2237,
199,
5214,
18,
275,
2557,
14,
362,
4152,
3167,
1252,
2117,
8572,
1692,
8,
5214,
18,
9,
199,
1361,
480,
4665,
4789,
499,
12,
15418,
6783,
4789,
18,
14,
362,
1304,
1252,
17186,
1012,
421,
199,
3,
7494,
370,
28987,
3663,
3918,
2193,
199,
3,
7819,
199,
3,
413,
14,
1265,
5627,
2251,
1265,
2934,
370,
1947,
199,
5214,
63,
513,
275,
359,
5214,
12,
4789,
18,
61,
199,
199,
3,
499,
14,
1218,
282,
1947,
199,
1450,
275,
27122,
14,
1238,
14,
1931,
16768,
41,
342,
199,
1450,
14,
8341,
1110,
8,
82,
875,
480,
1222,
1947,
2237,
199,
199,
3,
650,
14,
1900,
282,
769,
402,
6220,
199,
1073,
63,
513,
275,
769,
342,
199,
509,
6364,
315,
4789,
63,
513,
26,
272,
2142,
275,
27122,
14,
1238,
14,
9271,
16768,
3834,
41,
342,
272,
2142,
14,
409,
6652,
8,
795,
9,
272,
2142,
14,
409,
3493,
8,
1450,
9,
272,
2142,
63,
513,
14,
740,
8,
1073,
9,
199,
199,
3,
841,
14,
3354,
314,
6220,
370,
314,
1654,
199,
1631,
14,
362,
4152,
3167,
1252,
2117,
3836,
8,
1073,
63,
513,
9,
421,
199,
3,
15524,
1950,
26,
199,
3,
7819,
199,
3,
3979,
1265,
787,
4224,
12,
4002,
314,
2351,
370,
2867,
1536,
1654,
5944,
14,
199,
1631,
14,
1600,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
flavoi/diventi
|
diventi/blog/models.py
|
1
|
4236
|
from functools import reduce
import operator
from django.db import models
from django.db.models import Q
from django.conf import settings
from django.utils import timezone
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from ckeditor.fields import RichTextField
from cuser.middleware import CuserMiddleware
from diventi.core.models import (
TimeStampedModel,
PromotableModel,
PublishableModel,
PublishableModelQuerySet,
Category,
DiventiImageModel,
DiventiCoverModel,
Element,
DiventiColModel,
)
class BlogCover(DiventiCoverModel, Element):
"""
Stores cover images for the blog page.
"""
class Meta:
verbose_name = _('Blog Cover')
verbose_name_plural = _('Blog Covers')
class ArticleCategory(Category):
"""
Defines the main argument of any article.
"""
pass
class ArticleQuerySet(PublishableModelQuerySet):
# Selet articles' related objects
def prefetch(self):
articles = self.select_related('category')
articles = articles.select_related('author')
articles = articles.prefetch_related('related_articles')
articles = articles.prefetch_related('promotions')
return articles
# Get the list of published articles from the most recent to the least
def history(self):
articles = self.published()
articles = articles.order_by('-publication_date')
return articles
# Get the list of published articles of a certain category
def category(self, category_title):
articles = self.history().filter(category__title=category_title)
return articles
# Get the featured articles
def hot(self):
articles = self.history().filter(hot=True)
return articles
# Get the hottest article
def hottest(self):
article = self.hot().latest('publication_date')
return article
# Fetch all the promotions related to the article
def promotions(self):
article = self.prefetch_related('promotions')
return article
# Get the most recent article
def current(self):
try:
article = self.hottest()
except Article.DoesNotExist:
article = self.published().latest('publication_date')
return article
class Article(TimeStampedModel, PromotableModel, PublishableModel, DiventiImageModel, DiventiColModel, Element):
"""
Blog posts are built upon a specific category and are always
introduced by a nice heading picture.
"""
category = models.ForeignKey(ArticleCategory, null=True, verbose_name=_('category'), on_delete=models.SET_NULL)
content = RichTextField(verbose_name=_('content'))
hot = models.BooleanField(default=False, verbose_name=_('hot'))
slug = models.SlugField(unique=True, verbose_name=_('slug'))
author = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, related_name='articles', verbose_name=_('author'), on_delete=models.SET_NULL)
related_articles = models.ManyToManyField(
'self',
related_name='related_articles',
blank=True,
verbose_name=_('related articles'),
) # Connect this article to others
objects = ArticleQuerySet.as_manager()
class Meta:
verbose_name = _('article')
verbose_name_plural = _('articles')
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('blog:detail', args=[str(self.slug)])
def search(self, query, *args, **kwargs):
results = Article.objects.history()
query_list = query.split()
results = results.filter(
reduce(operator.and_,
(Q(title__icontains=q) for q in query_list)) |
reduce(operator.and_,
(Q(description__icontains=q) for q in query_list))
)
return results
def reporting(self, *args, **kwargs):
results = Article.objects.none()
return results
def class_name(self):
return _('article')
|
apache-2.0
|
[
504,
9143,
492,
7114,
202,
199,
646,
4182,
2999,
199,
504,
1639,
14,
697,
492,
1709,
202,
199,
504,
1639,
14,
697,
14,
992,
492,
1413,
202,
199,
504,
1639,
14,
2190,
492,
2202,
202,
199,
504,
1639,
14,
1208,
492,
7137,
202,
199,
504,
1639,
14,
3603,
492,
3837,
202,
199,
504,
1639,
14,
1208,
14,
6893,
492,
9796,
63,
6395,
465,
485,
2999,
199,
504,
286,
415,
27050,
14,
955,
492,
30846,
6254,
202,
199,
504,
286,
751,
14,
5754,
492,
445,
751,
6608,
2999,
199,
504,
487,
1856,
280,
14,
1018,
14,
992,
492,
334,
1128,
4703,
16649,
379,
1685,
12,
26259,
27724,
357,
461,
1685,
12,
26259,
19952,
461,
1685,
12,
1128,
19952,
461,
1685,
13689,
12,
1128,
13573,
12,
26259,
577,
1496,
280,
3491,
1685,
12,
26259,
577,
1496,
280,
31048,
1685,
12,
26259,
6566,
12,
1128,
577,
1496,
280,
2001,
1685,
12,
202,
199,
9,
8065,
199,
533,
29775,
31048,
8,
36,
1496,
280,
31048,
1685,
12,
6566,
304,
1128,
408,
1039,
31299,
8486,
5935,
367,
314,
19936,
2034,
14,
1128,
408,
2958,
1021,
6288,
26,
1039,
3376,
63,
354,
275,
4018,
26081,
1849,
422,
358,
1039,
3376,
63,
354,
63,
10019,
275,
4018,
26081,
1849,
14895,
358,
8065,
199,
533,
8281,
7841,
8,
7841,
304,
1128,
408,
1039,
25022,
314,
2446,
1423,
402,
1263,
9772,
14,
1128,
408,
1128,
986,
8065,
199,
533,
8281,
13689,
8,
13956,
461,
1685,
13689,
304,
11787,
327,
3240,
2723,
23242,
7,
4048,
2251,
1128,
347,
21544,
8,
277,
304,
1039,
23242,
275,
291,
14,
2416,
63,
2407,
360,
3710,
358,
1039,
23242,
275,
23242,
14,
2416,
63,
2407,
360,
2502,
358,
1039,
23242,
275,
23242,
14,
15576,
63,
2407,
360,
2407,
63,
19813,
358,
1039,
23242,
275,
23242,
14,
15576,
63,
2407,
360,
12741,
79,
852,
358,
1039,
372,
23242,
2958,
327,
2372,
314,
769,
402,
3267,
23242,
687,
314,
4750,
8058,
370,
314,
5210,
26259,
347,
7994,
8,
277,
304,
1039,
23242,
275,
291,
14,
8987,
342,
1039,
23242,
275,
23242,
14,
1648,
63,
991,
3654,
22678,
63,
602,
358,
1039,
372,
23242,
2958,
327,
2372,
314,
769,
402,
3267,
23242,
402,
282,
9842,
4637,
1128,
347,
4637,
8,
277,
12,
4637,
63,
1213,
304,
1039,
23242,
275,
291,
14,
5570,
1252,
1541,
8,
3710,
363,
1213,
29,
3710,
63,
1213,
9,
1039,
372,
23242,
2958,
327,
2372,
314,
13953,
3297,
23242,
1128,
347,
18469,
8,
277,
304,
1039,
23242,
275,
291,
14,
5570,
1252,
1541,
8,
8885,
29,
549,
9,
1039,
372,
23242,
2958,
327,
2372,
314,
18469,
396,
9772,
1128,
347,
18469,
396,
8,
277,
304,
1039,
9772,
275,
291,
14,
8885,
1252,
7410,
360,
22678,
63,
602,
358,
1039,
372,
9772,
2958,
327,
10619,
11135,
1006,
314,
8023,
79,
852,
4048,
370,
314,
9772,
1128,
347,
8023,
79,
852,
8,
277,
304,
1039,
9772,
275,
291,
14,
15576,
63,
2407,
360,
12741,
79,
852,
358,
1039,
372,
9772,
2958,
327,
2372,
314,
4750,
8058,
9772,
1128,
347,
1453,
8,
277,
304,
1039,
862,
26,
1675,
9772,
275,
291,
14,
8885,
396,
342,
1039,
871,
8281,
14,
7400,
26,
1675,
9772,
275,
291,
14,
8987,
1252,
7410,
360,
22678,
63,
602,
358,
1039,
372,
9772,
8065,
199,
533,
8281,
8,
27335,
379,
1685,
12,
27724,
357,
461,
1685,
12,
19952,
461,
1685,
12,
577,
1496,
280,
3491,
1685,
12,
577,
1496,
280,
2001,
1685,
12,
6566,
304,
1128,
408,
1039,
29775,
22238,
787,
6137,
12188,
282,
2488,
4637,
436,
787,
3544,
30199,
21399,
701,
282,
14213,
16631,
24945,
14,
1128,
408,
1128,
4637,
275,
1709,
14,
3190,
8,
7221,
7841,
12,
2973,
29,
549,
12,
3376,
63,
354,
12397,
3710,
659,
641,
63,
1807,
29,
992,
14,
3597,
63,
8084,
9,
258,
1128,
1564,
275,
30846,
6254,
8,
3832,
63,
354,
12397,
1317,
1333,
1128,
18469,
275,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
12397,
8885,
1333,
1128,
8889,
275,
1709,
14,
17315,
8,
3235,
29,
549,
12,
3376,
63,
354,
12397,
5464,
1333,
1128,
4132,
275,
1709,
14,
3190,
8,
1751,
14,
5580,
63,
3791,
63,
11429,
12,
2973,
29,
549,
12,
4048,
63,
354,
534,
19813,
297,
3376,
63,
354,
12397,
2502,
659,
641,
63,
1807,
29,
992,
14,
3597,
63,
8084,
9,
1128,
4048,
63,
19813,
275,
1709,
14,
7624,
8,
1039,
283,
277,
297,
1039,
4048,
63,
354,
534,
2407,
63,
19813,
297,
30199,
4596,
29,
549,
12,
30199,
3376,
63,
354,
12397,
2407,
23242,
659,
1128,
776,
327,
15175,
642,
9772,
370,
11789,
2958,
2251,
275,
8281,
13689,
14,
305,
63,
2609,
342,
2958,
1021,
6288,
26,
1039,
3376,
63,
354,
275,
4018,
6934,
358,
1039,
3376,
63,
354,
63,
10019,
275,
4018,
19813,
358,
11787,
347,
636,
495,
721,
277,
304,
1039,
372,
291,
14,
1213,
2958,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
1039,
372,
3837,
360,
11486,
26,
5506,
297,
1249,
1524,
495,
8,
277,
14,
5464,
3948,
2958,
347,
2754,
8,
277,
12,
1827,
12,
627,
589,
12,
1011,
958,
304,
1039,
2058,
275,
8281,
14,
1462,
14,
5570,
342,
1039,
1827,
63,
513,
275,
1827,
14,
1294,
342,
1039,
2058,
275,
2058,
14,
1541,
8,
1675,
7114,
8,
3856,
14,
460,
3131,
202,
673,
334,
49,
8,
1213,
363,
30314,
29,
81,
9,
367,
1894,
315,
1827,
63,
513,
430,
1204,
1675,
7114,
8,
3856,
14,
460,
3131,
202,
673,
334,
49,
8,
1802,
363,
30314,
29,
81,
9,
367,
1894,
315,
1827,
63,
513,
430,
1039,
776,
1039,
372,
2058,
2958,
347,
17290,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
1039,
2058,
275,
8281,
14,
1462,
14,
3592,
342,
1039,
372,
2058,
2958,
347,
1021,
63,
354,
8,
277,
304,
1039,
372,
4018,
6934,
358,
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
] |
[
9143,
492,
7114,
202,
199,
646,
4182,
2999,
199,
504,
1639,
14,
697,
492,
1709,
202,
199,
504,
1639,
14,
697,
14,
992,
492,
1413,
202,
199,
504,
1639,
14,
2190,
492,
2202,
202,
199,
504,
1639,
14,
1208,
492,
7137,
202,
199,
504,
1639,
14,
3603,
492,
3837,
202,
199,
504,
1639,
14,
1208,
14,
6893,
492,
9796,
63,
6395,
465,
485,
2999,
199,
504,
286,
415,
27050,
14,
955,
492,
30846,
6254,
202,
199,
504,
286,
751,
14,
5754,
492,
445,
751,
6608,
2999,
199,
504,
487,
1856,
280,
14,
1018,
14,
992,
492,
334,
1128,
4703,
16649,
379,
1685,
12,
26259,
27724,
357,
461,
1685,
12,
26259,
19952,
461,
1685,
12,
1128,
19952,
461,
1685,
13689,
12,
1128,
13573,
12,
26259,
577,
1496,
280,
3491,
1685,
12,
26259,
577,
1496,
280,
31048,
1685,
12,
26259,
6566,
12,
1128,
577,
1496,
280,
2001,
1685,
12,
202,
199,
9,
8065,
199,
533,
29775,
31048,
8,
36,
1496,
280,
31048,
1685,
12,
6566,
304,
1128,
408,
1039,
31299,
8486,
5935,
367,
314,
19936,
2034,
14,
1128,
408,
2958,
1021,
6288,
26,
1039,
3376,
63,
354,
275,
4018,
26081,
1849,
422,
358,
1039,
3376,
63,
354,
63,
10019,
275,
4018,
26081,
1849,
14895,
358,
8065,
199,
533,
8281,
7841,
8,
7841,
304,
1128,
408,
1039,
25022,
314,
2446,
1423,
402,
1263,
9772,
14,
1128,
408,
1128,
986,
8065,
199,
533,
8281,
13689,
8,
13956,
461,
1685,
13689,
304,
11787,
327,
3240,
2723,
23242,
7,
4048,
2251,
1128,
347,
21544,
8,
277,
304,
1039,
23242,
275,
291,
14,
2416,
63,
2407,
360,
3710,
358,
1039,
23242,
275,
23242,
14,
2416,
63,
2407,
360,
2502,
358,
1039,
23242,
275,
23242,
14,
15576,
63,
2407,
360,
2407,
63,
19813,
358,
1039,
23242,
275,
23242,
14,
15576,
63,
2407,
360,
12741,
79,
852,
358,
1039,
372,
23242,
2958,
327,
2372,
314,
769,
402,
3267,
23242,
687,
314,
4750,
8058,
370,
314,
5210,
26259,
347,
7994,
8,
277,
304,
1039,
23242,
275,
291,
14,
8987,
342,
1039,
23242,
275,
23242,
14,
1648,
63,
991,
3654,
22678,
63,
602,
358,
1039,
372,
23242,
2958,
327,
2372,
314,
769,
402,
3267,
23242,
402,
282,
9842,
4637,
1128,
347,
4637,
8,
277,
12,
4637,
63,
1213,
304,
1039,
23242,
275,
291,
14,
5570,
1252,
1541,
8,
3710,
363,
1213,
29,
3710,
63,
1213,
9,
1039,
372,
23242,
2958,
327,
2372,
314,
13953,
3297,
23242,
1128,
347,
18469,
8,
277,
304,
1039,
23242,
275,
291,
14,
5570,
1252,
1541,
8,
8885,
29,
549,
9,
1039,
372,
23242,
2958,
327,
2372,
314,
18469,
396,
9772,
1128,
347,
18469,
396,
8,
277,
304,
1039,
9772,
275,
291,
14,
8885,
1252,
7410,
360,
22678,
63,
602,
358,
1039,
372,
9772,
2958,
327,
10619,
11135,
1006,
314,
8023,
79,
852,
4048,
370,
314,
9772,
1128,
347,
8023,
79,
852,
8,
277,
304,
1039,
9772,
275,
291,
14,
15576,
63,
2407,
360,
12741,
79,
852,
358,
1039,
372,
9772,
2958,
327,
2372,
314,
4750,
8058,
9772,
1128,
347,
1453,
8,
277,
304,
1039,
862,
26,
1675,
9772,
275,
291,
14,
8885,
396,
342,
1039,
871,
8281,
14,
7400,
26,
1675,
9772,
275,
291,
14,
8987,
1252,
7410,
360,
22678,
63,
602,
358,
1039,
372,
9772,
8065,
199,
533,
8281,
8,
27335,
379,
1685,
12,
27724,
357,
461,
1685,
12,
19952,
461,
1685,
12,
577,
1496,
280,
3491,
1685,
12,
577,
1496,
280,
2001,
1685,
12,
6566,
304,
1128,
408,
1039,
29775,
22238,
787,
6137,
12188,
282,
2488,
4637,
436,
787,
3544,
30199,
21399,
701,
282,
14213,
16631,
24945,
14,
1128,
408,
1128,
4637,
275,
1709,
14,
3190,
8,
7221,
7841,
12,
2973,
29,
549,
12,
3376,
63,
354,
12397,
3710,
659,
641,
63,
1807,
29,
992,
14,
3597,
63,
8084,
9,
258,
1128,
1564,
275,
30846,
6254,
8,
3832,
63,
354,
12397,
1317,
1333,
1128,
18469,
275,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
12397,
8885,
1333,
1128,
8889,
275,
1709,
14,
17315,
8,
3235,
29,
549,
12,
3376,
63,
354,
12397,
5464,
1333,
1128,
4132,
275,
1709,
14,
3190,
8,
1751,
14,
5580,
63,
3791,
63,
11429,
12,
2973,
29,
549,
12,
4048,
63,
354,
534,
19813,
297,
3376,
63,
354,
12397,
2502,
659,
641,
63,
1807,
29,
992,
14,
3597,
63,
8084,
9,
1128,
4048,
63,
19813,
275,
1709,
14,
7624,
8,
1039,
283,
277,
297,
1039,
4048,
63,
354,
534,
2407,
63,
19813,
297,
30199,
4596,
29,
549,
12,
30199,
3376,
63,
354,
12397,
2407,
23242,
659,
1128,
776,
327,
15175,
642,
9772,
370,
11789,
2958,
2251,
275,
8281,
13689,
14,
305,
63,
2609,
342,
2958,
1021,
6288,
26,
1039,
3376,
63,
354,
275,
4018,
6934,
358,
1039,
3376,
63,
354,
63,
10019,
275,
4018,
19813,
358,
11787,
347,
636,
495,
721,
277,
304,
1039,
372,
291,
14,
1213,
2958,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
1039,
372,
3837,
360,
11486,
26,
5506,
297,
1249,
1524,
495,
8,
277,
14,
5464,
3948,
2958,
347,
2754,
8,
277,
12,
1827,
12,
627,
589,
12,
1011,
958,
304,
1039,
2058,
275,
8281,
14,
1462,
14,
5570,
342,
1039,
1827,
63,
513,
275,
1827,
14,
1294,
342,
1039,
2058,
275,
2058,
14,
1541,
8,
1675,
7114,
8,
3856,
14,
460,
3131,
202,
673,
334,
49,
8,
1213,
363,
30314,
29,
81,
9,
367,
1894,
315,
1827,
63,
513,
430,
1204,
1675,
7114,
8,
3856,
14,
460,
3131,
202,
673,
334,
49,
8,
1802,
363,
30314,
29,
81,
9,
367,
1894,
315,
1827,
63,
513,
430,
1039,
776,
1039,
372,
2058,
2958,
347,
17290,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
1039,
2058,
275,
8281,
14,
1462,
14,
3592,
342,
1039,
372,
2058,
2958,
347,
1021,
63,
354,
8,
277,
304,
1039,
372,
4018,
6934,
358,
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,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
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
akuseru/zulip
|
zerver/models.py
|
113
|
49724
|
from __future__ import absolute_import
from django.db import models
from django.conf import settings
from django.contrib.auth.models import AbstractBaseUser, UserManager, \
PermissionsMixin
from django.dispatch import receiver
from zerver.lib.cache import cache_with_key, flush_user_profile, flush_realm, \
user_profile_by_id_cache_key, user_profile_by_email_cache_key, \
generic_bulk_cached_fetch, cache_set, flush_stream, \
display_recipient_cache_key, cache_delete, \
get_stream_cache_key, active_user_dicts_in_realm_cache_key, \
active_bot_dicts_in_realm_cache_key
from zerver.lib.utils import make_safe_digest, generate_random_token
from django.db import transaction, IntegrityError
from zerver.lib.avatar import gravatar_hash, get_avatar_url
from django.utils import timezone
from django.contrib.sessions.models import Session
from zerver.lib.timestamp import datetime_to_timestamp
from django.db.models.signals import pre_save, post_save, post_delete
from guardian.shortcuts import get_users_with_perms
import zlib
from bitfield import BitField
from collections import defaultdict
from datetime import timedelta
import pylibmc
import re
import ujson
import logging
bugdown = None
MAX_SUBJECT_LENGTH = 60
MAX_MESSAGE_LENGTH = 10000
# Doing 1000 memcached requests to get_display_recipient is quite slow,
# so add a local cache as well as the memcached cache.
per_request_display_recipient_cache = {}
def get_display_recipient_by_id(recipient_id, recipient_type, recipient_type_id):
if recipient_id not in per_request_display_recipient_cache:
result = get_display_recipient_memcached(recipient_id, recipient_type, recipient_type_id)
per_request_display_recipient_cache[recipient_id] = result
return per_request_display_recipient_cache[recipient_id]
def get_display_recipient(recipient):
return get_display_recipient_by_id(
recipient.id,
recipient.type,
recipient.type_id
)
def flush_per_request_caches():
global per_request_display_recipient_cache
per_request_display_recipient_cache = {}
global per_request_realm_filters_cache
per_request_realm_filters_cache = {}
@cache_with_key(lambda *args: display_recipient_cache_key(args[0]),
timeout=3600*24*7)
def get_display_recipient_memcached(recipient_id, recipient_type, recipient_type_id):
"""
returns: an appropriate object describing the recipient. For a
stream this will be the stream name as a string. For a huddle or
personal, it will be an array of dicts about each recipient.
"""
if recipient_type == Recipient.STREAM:
stream = Stream.objects.get(id=recipient_type_id)
return stream.name
# We don't really care what the ordering is, just that it's deterministic.
user_profile_list = (UserProfile.objects.filter(subscription__recipient_id=recipient_id)
.select_related()
.order_by('email'))
return [{'email': user_profile.email,
'domain': user_profile.realm.domain,
'full_name': user_profile.full_name,
'short_name': user_profile.short_name,
'id': user_profile.id,
'is_mirror_dummy': user_profile.is_mirror_dummy,} for user_profile in user_profile_list]
def completely_open(domain):
# This domain is completely open to everyone on the internet to
# join. E-mail addresses do not need to match the domain and
# an invite from an existing user is not required.
realm = get_realm(domain)
if not realm:
return False
return not realm.invite_required and not realm.restricted_to_domain
def get_unique_open_realm():
# We only return a realm if there is a unique realm and it is completely open.
realms = Realm.objects.filter(deactivated=False)
if len(realms) != 1:
return None
realm = realms[0]
if realm.invite_required or realm.restricted_to_domain:
return None
return realm
def get_realm_emoji_cache_key(realm):
return 'realm_emoji:%s' % (realm.id,)
class Realm(models.Model):
# domain is a domain in the Internet sense. It must be structured like a
# valid email domain. We use is to restrict access, identify bots, etc.
domain = models.CharField(max_length=40, db_index=True, unique=True)
# name is the user-visible identifier for the realm. It has no required
# structure.
name = models.CharField(max_length=40, null=True)
restricted_to_domain = models.BooleanField(default=True)
invite_required = models.BooleanField(default=False)
invite_by_admins_only = models.BooleanField(default=False)
mandatory_topics = models.BooleanField(default=False)
show_digest_email = models.BooleanField(default=True)
name_changes_disabled = models.BooleanField(default=False)
date_created = models.DateTimeField(default=timezone.now)
notifications_stream = models.ForeignKey('Stream', related_name='+', null=True, blank=True)
deactivated = models.BooleanField(default=False)
NOTIFICATION_STREAM_NAME = 'zulip'
def __repr__(self):
return (u"<Realm: %s %s>" % (self.domain, self.id)).encode("utf-8")
def __str__(self):
return self.__repr__()
@cache_with_key(get_realm_emoji_cache_key, timeout=3600*24*7)
def get_emoji(self):
return get_realm_emoji_uncached(self)
@property
def deployment(self):
try:
return self._deployments.all()[0]
except IndexError:
return None
@deployment.setter
def set_deployments(self, value):
self._deployments = [value]
def get_admin_users(self):
# This method is kind of expensive, due to our complex permissions model.
candidates = get_users_with_perms(self, only_with_perms=['administer'])
return candidates
def get_active_users(self):
return UserProfile.objects.filter(realm=self, is_active=True).select_related()
class Meta:
permissions = (
('administer', "Administer a realm"),
('api_super_user', "Can send messages as other users for mirroring"),
)
post_save.connect(flush_realm, sender=Realm)
class RealmAlias(models.Model):
realm = models.ForeignKey(Realm, null=True)
domain = models.CharField(max_length=80, db_index=True, unique=True)
# These functions should only be used on email addresses that have
# been validated via django.core.validators.validate_email
#
# Note that we need to use some care, since can you have multiple @-signs; e.g.
# "tabbott@test"@zulip.com
# is valid email address
def email_to_username(email):
return "@".join(email.split("@")[:-1]).lower()
# Returns the raw domain portion of the desired email address
def split_email_to_domain(email):
return email.split("@")[-1].lower()
# Returns the domain, potentually de-aliased, for the realm
# that this user's email is in
def resolve_email_to_domain(email):
domain = split_email_to_domain(email)
alias = alias_for_realm(domain)
if alias is not None:
domain = alias.realm.domain
return domain
def alias_for_realm(domain):
try:
return RealmAlias.objects.get(domain=domain)
except RealmAlias.DoesNotExist:
return None
def remote_user_to_email(remote_user):
if settings.SSO_APPEND_DOMAIN is not None:
remote_user += "@" + settings.SSO_APPEND_DOMAIN
return remote_user
class RealmEmoji(models.Model):
realm = models.ForeignKey(Realm)
name = models.TextField()
img_url = models.TextField()
class Meta:
unique_together = ("realm", "name")
def __str__(self):
return "<RealmEmoji(%s): %s %s>" % (self.realm.domain, self.name, self.img_url)
def get_realm_emoji_uncached(realm):
d = {}
for row in RealmEmoji.objects.filter(realm=realm):
d[row.name] = row.img_url
return d
def flush_realm_emoji(sender, **kwargs):
realm = kwargs['instance'].realm
cache_set(get_realm_emoji_cache_key(realm),
get_realm_emoji_uncached(realm),
timeout=3600*24*7)
post_save.connect(flush_realm_emoji, sender=RealmEmoji)
post_delete.connect(flush_realm_emoji, sender=RealmEmoji)
class RealmFilter(models.Model):
realm = models.ForeignKey(Realm)
pattern = models.TextField()
url_format_string = models.TextField()
class Meta:
unique_together = ("realm", "pattern")
def __str__(self):
return "<RealmFilter(%s): %s %s>" % (self.realm.domain, self.pattern, self.url_format_string)
def get_realm_filters_cache_key(domain):
return 'all_realm_filters:%s' % (domain,)
# We have a per-process cache to avoid doing 1000 memcached queries during page load
per_request_realm_filters_cache = {}
def realm_filters_for_domain(domain):
domain = domain.lower()
if domain not in per_request_realm_filters_cache:
per_request_realm_filters_cache[domain] = realm_filters_for_domain_memcached(domain)
return per_request_realm_filters_cache[domain]
@cache_with_key(get_realm_filters_cache_key, timeout=3600*24*7)
def realm_filters_for_domain_memcached(domain):
filters = []
for realm_filter in RealmFilter.objects.filter(realm=get_realm(domain)):
filters.append((realm_filter.pattern, realm_filter.url_format_string))
return filters
def all_realm_filters():
filters = defaultdict(list)
for realm_filter in RealmFilter.objects.all():
filters[realm_filter.realm.domain].append((realm_filter.pattern, realm_filter.url_format_string))
return filters
def flush_realm_filter(sender, **kwargs):
realm = kwargs['instance'].realm
cache_delete(get_realm_filters_cache_key(realm.domain))
try:
per_request_realm_filters_cache.pop(realm.domain.lower())
except KeyError:
pass
post_save.connect(flush_realm_filter, sender=RealmFilter)
post_delete.connect(flush_realm_filter, sender=RealmFilter)
class UserProfile(AbstractBaseUser, PermissionsMixin):
# Fields from models.AbstractUser minus last_name and first_name,
# which we don't use; email is modified to make it indexed and unique.
email = models.EmailField(blank=False, db_index=True, unique=True)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
is_bot = models.BooleanField(default=False)
date_joined = models.DateTimeField(default=timezone.now)
is_mirror_dummy = models.BooleanField(default=False)
bot_owner = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
USERNAME_FIELD = 'email'
MAX_NAME_LENGTH = 100
# Our custom site-specific fields
full_name = models.CharField(max_length=MAX_NAME_LENGTH)
short_name = models.CharField(max_length=MAX_NAME_LENGTH)
# pointer points to Message.id, NOT UserMessage.id.
pointer = models.IntegerField()
last_pointer_updater = models.CharField(max_length=64)
realm = models.ForeignKey(Realm)
api_key = models.CharField(max_length=32)
### Notifications settings. ###
# Stream notifications.
enable_stream_desktop_notifications = models.BooleanField(default=True)
enable_stream_sounds = models.BooleanField(default=True)
# PM + @-mention notifications.
enable_desktop_notifications = models.BooleanField(default=True)
enable_sounds = models.BooleanField(default=True)
enable_offline_email_notifications = models.BooleanField(default=True)
enable_offline_push_notifications = models.BooleanField(default=True)
enable_digest_emails = models.BooleanField(default=True)
# Old notification field superseded by existence of stream notification
# settings.
default_desktop_notifications = models.BooleanField(default=True)
###
last_reminder = models.DateTimeField(default=timezone.now, null=True)
rate_limits = models.CharField(default="", max_length=100) # comma-separated list of range:max pairs
# Default streams
default_sending_stream = models.ForeignKey('zerver.Stream', null=True, related_name='+')
default_events_register_stream = models.ForeignKey('zerver.Stream', null=True, related_name='+')
default_all_public_streams = models.BooleanField(default=False)
# UI vars
enter_sends = models.NullBooleanField(default=True)
autoscroll_forever = models.BooleanField(default=False)
left_side_userlist = models.BooleanField(default=False)
# display settings
twenty_four_hour_time = models.BooleanField(default=False)
# Hours to wait before sending another email to a user
EMAIL_REMINDER_WAITPERIOD = 24
# Minutes to wait before warning a bot owner that her bot sent a message
# to a nonexistent stream
BOT_OWNER_STREAM_ALERT_WAITPERIOD = 1
AVATAR_FROM_GRAVATAR = 'G'
AVATAR_FROM_USER = 'U'
AVATAR_FROM_SYSTEM = 'S'
AVATAR_SOURCES = (
(AVATAR_FROM_GRAVATAR, 'Hosted by Gravatar'),
(AVATAR_FROM_USER, 'Uploaded by user'),
(AVATAR_FROM_SYSTEM, 'System generated'),
)
avatar_source = models.CharField(default=AVATAR_FROM_GRAVATAR, choices=AVATAR_SOURCES, max_length=1)
TUTORIAL_WAITING = 'W'
TUTORIAL_STARTED = 'S'
TUTORIAL_FINISHED = 'F'
TUTORIAL_STATES = ((TUTORIAL_WAITING, "Waiting"),
(TUTORIAL_STARTED, "Started"),
(TUTORIAL_FINISHED, "Finished"))
tutorial_status = models.CharField(default=TUTORIAL_WAITING, choices=TUTORIAL_STATES, max_length=1)
# Contains serialized JSON of the form:
# [("step 1", true), ("step 2", false)]
# where the second element of each tuple is if the step has been
# completed.
onboarding_steps = models.TextField(default=ujson.dumps([]))
invites_granted = models.IntegerField(default=0)
invites_used = models.IntegerField(default=0)
alert_words = models.TextField(default=ujson.dumps([])) # json-serialized list of strings
# Contains serialized JSON of the form:
# [["social", "mit"], ["devel", "ios"]]
muted_topics = models.TextField(default=ujson.dumps([]))
objects = UserManager()
def can_admin_user(self, target_user):
"""Returns whether this user has permission to modify target_user"""
if target_user.bot_owner == self:
return True
elif self.has_perm('administer', target_user.realm):
return True
else:
return False
def is_admin(self):
return self.has_perm('administer', self.realm)
def is_api_super_user(self):
# TODO: Remove API_SUPER_USERS hack; fixing this will require
# setting the email bot as a super user in the provision process.
return self.has_perm('api_super_user', self.realm) or self.email in settings.API_SUPER_USERS
def last_reminder_tzaware(self):
if self.last_reminder is not None and timezone.is_naive(self.last_reminder):
logging.warning("Loaded a user_profile.last_reminder for user %s that's not tz-aware: %s"
% (self.email, self.last_reminder))
return self.last_reminder.replace(tzinfo=timezone.utc)
return self.last_reminder
def __repr__(self):
return (u"<UserProfile: %s %s>" % (self.email, self.realm)).encode("utf-8")
def __str__(self):
return self.__repr__()
@staticmethod
def emails_from_ids(user_ids):
rows = UserProfile.objects.filter(id__in=user_ids).values('id', 'email')
return {row['id']: row['email'] for row in rows}
def can_create_streams(self):
# Long term this might be an actual DB attribute. Short term and long term, we want
# this to be conceptually a property of the user, although it may actually be administered
# in a more complicated way, like certain realms may allow only admins to create streams.
return True
def receives_offline_notifications(user_profile):
return ((user_profile.enable_offline_email_notifications or
user_profile.enable_offline_push_notifications) and
not user_profile.is_bot)
# Make sure we flush the UserProfile object from our memcached
# whenever we save it.
post_save.connect(flush_user_profile, sender=UserProfile)
class PreregistrationUser(models.Model):
email = models.EmailField()
referred_by = models.ForeignKey(UserProfile, null=True)
streams = models.ManyToManyField('Stream')
invited_at = models.DateTimeField(auto_now=True)
# status: whether an object has been confirmed.
# if confirmed, set to confirmation.settings.STATUS_ACTIVE
status = models.IntegerField(default=0)
realm = models.ForeignKey(Realm, null=True)
# Deprecated. Drop this table once prod uses PushDeviceToken and the data has
# been copied there.
class AppleDeviceToken(models.Model):
# The token is a unique device-specific token that is
# sent to us from each iOS device, after registering with
# the APNS service
token = models.CharField(max_length=255, unique=True)
last_updated = models.DateTimeField(auto_now=True)
# The user who's device this is
user = models.ForeignKey(UserProfile, db_index=True)
class PushDeviceToken(models.Model):
APNS = 1
GCM = 2
KINDS = (
(APNS, 'apns'),
(GCM, 'gcm'),
)
kind = models.PositiveSmallIntegerField(choices=KINDS)
# The token is a unique device-specific token that is
# sent to us from each device:
# - APNS token if kind == APNS
# - GCM registration id if kind == GCM
token = models.CharField(max_length=4096, unique=True)
last_updated = models.DateTimeField(auto_now=True)
# The user who's device this is
user = models.ForeignKey(UserProfile, db_index=True)
# [optional] Contains the app id of the device if it is an iOS device
ios_app_id = models.TextField(null=True)
class MitUser(models.Model):
email = models.EmailField(unique=True)
# status: whether an object has been confirmed.
# if confirmed, set to confirmation.settings.STATUS_ACTIVE
status = models.IntegerField(default=0)
def generate_email_token_for_stream():
return generate_random_token(32)
class Stream(models.Model):
MAX_NAME_LENGTH = 60
name = models.CharField(max_length=MAX_NAME_LENGTH, db_index=True)
realm = models.ForeignKey(Realm, db_index=True)
invite_only = models.NullBooleanField(default=False)
# Used by the e-mail forwarder. The e-mail RFC specifies a maximum
# e-mail length of 254, and our max stream length is 30, so we
# have plenty of room for the token.
email_token = models.CharField(
max_length=32, default=generate_email_token_for_stream)
description = models.CharField(max_length=1024, default='')
date_created = models.DateTimeField(default=timezone.now)
deactivated = models.BooleanField(default=False)
def __repr__(self):
return (u"<Stream: %s>" % (self.name,)).encode("utf-8")
def __str__(self):
return self.__repr__()
def is_public(self):
# All streams are private at MIT.
return self.realm.domain != "mit.edu" and not self.invite_only
class Meta:
unique_together = ("name", "realm")
@classmethod
def create(cls, name, realm):
stream = cls(name=name, realm=realm)
stream.save()
recipient = Recipient.objects.create(type_id=stream.id,
type=Recipient.STREAM)
return (stream, recipient)
def num_subscribers(self):
return Subscription.objects.filter(
recipient__type=Recipient.STREAM,
recipient__type_id=self.id,
user_profile__is_active=True,
active=True
).count()
# This is stream information that is sent to clients
def to_dict(self):
return dict(name=self.name,
stream_id=self.id,
description=self.description,
invite_only=self.invite_only)
post_save.connect(flush_stream, sender=Stream)
post_delete.connect(flush_stream, sender=Stream)
def valid_stream_name(name):
return name != ""
class Recipient(models.Model):
type_id = models.IntegerField(db_index=True)
type = models.PositiveSmallIntegerField(db_index=True)
# Valid types are {personal, stream, huddle}
PERSONAL = 1
STREAM = 2
HUDDLE = 3
class Meta:
unique_together = ("type", "type_id")
# N.B. If we used Django's choice=... we would get this for free (kinda)
_type_names = {
PERSONAL: 'personal',
STREAM: 'stream',
HUDDLE: 'huddle' }
def type_name(self):
# Raises KeyError if invalid
return self._type_names[self.type]
def __repr__(self):
display_recipient = get_display_recipient(self)
return (u"<Recipient: %s (%d, %s)>" % (display_recipient, self.type_id, self.type)).encode("utf-8")
class Client(models.Model):
name = models.CharField(max_length=30, db_index=True, unique=True)
get_client_cache = {}
def get_client(name):
if name not in get_client_cache:
result = get_client_memcached(name)
get_client_cache[name] = result
return get_client_cache[name]
def get_client_cache_key(name):
return 'get_client:%s' % (make_safe_digest(name),)
@cache_with_key(get_client_cache_key, timeout=3600*24*7)
def get_client_memcached(name):
(client, _) = Client.objects.get_or_create(name=name)
return client
# get_stream_backend takes either a realm id or a realm
@cache_with_key(get_stream_cache_key, timeout=3600*24*7)
def get_stream_backend(stream_name, realm):
if isinstance(realm, Realm):
realm_id = realm.id
else:
realm_id = realm
return Stream.objects.select_related("realm").get(
name__iexact=stream_name.strip(), realm_id=realm_id)
def get_active_streams(realm):
"""
Return all streams (including invite-only streams) that have not been deactivated.
"""
return Stream.objects.filter(realm=realm, deactivated=False)
# get_stream takes either a realm id or a realm
def get_stream(stream_name, realm):
try:
return get_stream_backend(stream_name, realm)
except Stream.DoesNotExist:
return None
def bulk_get_streams(realm, stream_names):
if isinstance(realm, Realm):
realm_id = realm.id
else:
realm_id = realm
def fetch_streams_by_name(stream_names):
# This should be just
#
# Stream.objects.select_related("realm").filter(name__iexact__in=stream_names,
# realm_id=realm_id)
#
# But chaining __in and __iexact doesn't work with Django's
# ORM, so we have the following hack to construct the relevant where clause
if len(stream_names) == 0:
return []
upper_list = ", ".join(["UPPER(%s)"] * len(stream_names))
where_clause = "UPPER(zerver_stream.name::text) IN (%s)" % (upper_list,)
return get_active_streams(realm_id).select_related("realm").extra(
where=[where_clause],
params=stream_names)
return generic_bulk_cached_fetch(lambda stream_name: get_stream_cache_key(stream_name, realm),
fetch_streams_by_name,
[stream_name.lower() for stream_name in stream_names],
id_fetcher=lambda stream: stream.name.lower())
def get_recipient_cache_key(type, type_id):
return "get_recipient:%s:%s" % (type, type_id,)
@cache_with_key(get_recipient_cache_key, timeout=3600*24*7)
def get_recipient(type, type_id):
return Recipient.objects.get(type_id=type_id, type=type)
def bulk_get_recipients(type, type_ids):
def cache_key_function(type_id):
return get_recipient_cache_key(type, type_id)
def query_function(type_ids):
return Recipient.objects.filter(type=type, type_id__in=type_ids)
return generic_bulk_cached_fetch(cache_key_function, query_function, type_ids,
id_fetcher=lambda recipient: recipient.type_id)
# NB: This function is currently unused, but may come in handy.
def linebreak(string):
return string.replace('\n\n', '<p/>').replace('\n', '<br/>')
def extract_message_dict(message_str):
return ujson.loads(zlib.decompress(message_str))
def stringify_message_dict(message_dict):
return zlib.compress(ujson.dumps(message_dict))
def to_dict_cache_key_id(message_id, apply_markdown):
return 'message_dict:%d:%d' % (message_id, apply_markdown)
def to_dict_cache_key(message, apply_markdown):
return to_dict_cache_key_id(message.id, apply_markdown)
class Message(models.Model):
sender = models.ForeignKey(UserProfile)
recipient = models.ForeignKey(Recipient)
subject = models.CharField(max_length=MAX_SUBJECT_LENGTH, db_index=True)
content = models.TextField()
rendered_content = models.TextField(null=True)
rendered_content_version = models.IntegerField(null=True)
pub_date = models.DateTimeField('date published', db_index=True)
sending_client = models.ForeignKey(Client)
last_edit_time = models.DateTimeField(null=True)
edit_history = models.TextField(null=True)
has_attachment = models.BooleanField(default=False, db_index=True)
has_image = models.BooleanField(default=False, db_index=True)
has_link = models.BooleanField(default=False, db_index=True)
def __repr__(self):
display_recipient = get_display_recipient(self.recipient)
return (u"<Message: %s / %s / %r>" % (display_recipient, self.subject, self.sender)).encode("utf-8")
def __str__(self):
return self.__repr__()
def get_realm(self):
return self.sender.realm
def render_markdown(self, content, domain=None):
"""Return HTML for given markdown. Bugdown may add properties to the
message object such as `mentions_user_ids` and `mentions_wildcard`.
These are only on this Django object and are not saved in the
database.
"""
global bugdown
if bugdown is None:
from zerver.lib import bugdown
self.mentions_wildcard = False
self.is_me_message = False
self.mentions_user_ids = set()
self.user_ids_with_alert_words = set()
if not domain:
domain = self.sender.realm.domain
if self.sending_client.name == "zephyr_mirror" and domain == "mit.edu":
# Use slightly customized Markdown processor for content
# delivered via zephyr_mirror
domain = "mit.edu/zephyr_mirror"
rendered_content = bugdown.convert(content, domain, self)
# For /me syntax, JS can detect the is_me_message flag
# and do special rendering.
if content.startswith('/me ') and '\n' not in content:
if rendered_content.startswith('<p>') and rendered_content.endswith('</p>'):
self.is_me_message = True
return rendered_content
def set_rendered_content(self, rendered_content, save = False):
"""Set the content on the message.
"""
global bugdown
if bugdown is None:
from zerver.lib import bugdown
self.rendered_content = rendered_content
self.rendered_content_version = bugdown.version
if self.rendered_content is not None:
if save:
self.save_rendered_content()
return True
else:
return False
def save_rendered_content(self):
self.save(update_fields=["rendered_content", "rendered_content_version"])
def maybe_render_content(self, domain, save = False):
"""Render the markdown if there is no existing rendered_content"""
global bugdown
if bugdown is None:
from zerver.lib import bugdown
if Message.need_to_render_content(self.rendered_content, self.rendered_content_version):
return self.set_rendered_content(self.render_markdown(self.content, domain), save)
else:
return True
@staticmethod
def need_to_render_content(rendered_content, rendered_content_version):
return rendered_content_version < bugdown.version or rendered_content is None
def to_dict(self, apply_markdown):
return extract_message_dict(self.to_dict_json(apply_markdown))
@cache_with_key(to_dict_cache_key, timeout=3600*24)
def to_dict_json(self, apply_markdown):
return stringify_message_dict(self.to_dict_uncached(apply_markdown))
def to_dict_uncached(self, apply_markdown):
return Message.build_message_dict(
apply_markdown = apply_markdown,
message = self,
message_id = self.id,
last_edit_time = self.last_edit_time,
edit_history = self.edit_history,
content = self.content,
subject = self.subject,
pub_date = self.pub_date,
rendered_content = self.rendered_content,
rendered_content_version = self.rendered_content_version,
sender_id = self.sender.id,
sender_email = self.sender.email,
sender_realm_domain = self.sender.realm.domain,
sender_full_name = self.sender.full_name,
sender_short_name = self.sender.short_name,
sender_avatar_source = self.sender.avatar_source,
sender_is_mirror_dummy = self.sender.is_mirror_dummy,
sending_client_name = self.sending_client.name,
recipient_id = self.recipient.id,
recipient_type = self.recipient.type,
recipient_type_id = self.recipient.type_id,
)
@staticmethod
def build_dict_from_raw_db_row(row, apply_markdown):
'''
row is a row from a .values() call, and it needs to have
all the relevant fields populated
'''
return Message.build_message_dict(
apply_markdown = apply_markdown,
message = None,
message_id = row['id'],
last_edit_time = row['last_edit_time'],
edit_history = row['edit_history'],
content = row['content'],
subject = row['subject'],
pub_date = row['pub_date'],
rendered_content = row['rendered_content'],
rendered_content_version = row['rendered_content_version'],
sender_id = row['sender_id'],
sender_email = row['sender__email'],
sender_realm_domain = row['sender__realm__domain'],
sender_full_name = row['sender__full_name'],
sender_short_name = row['sender__short_name'],
sender_avatar_source = row['sender__avatar_source'],
sender_is_mirror_dummy = row['sender__is_mirror_dummy'],
sending_client_name = row['sending_client__name'],
recipient_id = row['recipient_id'],
recipient_type = row['recipient__type'],
recipient_type_id = row['recipient__type_id'],
)
@staticmethod
def build_message_dict(
apply_markdown,
message,
message_id,
last_edit_time,
edit_history,
content,
subject,
pub_date,
rendered_content,
rendered_content_version,
sender_id,
sender_email,
sender_realm_domain,
sender_full_name,
sender_short_name,
sender_avatar_source,
sender_is_mirror_dummy,
sending_client_name,
recipient_id,
recipient_type,
recipient_type_id,
):
global bugdown
if bugdown is None:
from zerver.lib import bugdown
avatar_url = get_avatar_url(sender_avatar_source, sender_email)
display_recipient = get_display_recipient_by_id(
recipient_id,
recipient_type,
recipient_type_id
)
if recipient_type == Recipient.STREAM:
display_type = "stream"
elif recipient_type in (Recipient.HUDDLE, Recipient.PERSONAL):
display_type = "private"
if len(display_recipient) == 1:
# add the sender in if this isn't a message between
# someone and his self, preserving ordering
recip = {'email': sender_email,
'domain': sender_realm_domain,
'full_name': sender_full_name,
'short_name': sender_short_name,
'id': sender_id,
'is_mirror_dummy': sender_is_mirror_dummy}
if recip['email'] < display_recipient[0]['email']:
display_recipient = [recip, display_recipient[0]]
elif recip['email'] > display_recipient[0]['email']:
display_recipient = [display_recipient[0], recip]
obj = dict(
id = message_id,
sender_email = sender_email,
sender_full_name = sender_full_name,
sender_short_name = sender_short_name,
sender_domain = sender_realm_domain,
sender_id = sender_id,
type = display_type,
display_recipient = display_recipient,
recipient_id = recipient_id,
subject = subject,
timestamp = datetime_to_timestamp(pub_date),
gravatar_hash = gravatar_hash(sender_email), # Deprecated June 2013
avatar_url = avatar_url,
client = sending_client_name)
obj['subject_links'] = bugdown.subject_links(sender_realm_domain.lower(), subject)
if last_edit_time != None:
obj['last_edit_timestamp'] = datetime_to_timestamp(last_edit_time)
obj['edit_history'] = ujson.loads(edit_history)
if apply_markdown:
if Message.need_to_render_content(rendered_content, rendered_content_version):
if message is None:
# We really shouldn't be rendering objects in this method, but there is
# a scenario where we upgrade the version of bugdown and fail to run
# management commands to re-render historical messages, and then we
# need to have side effects. This method is optimized to not need full
# blown ORM objects, but the bugdown renderer is unfortunately highly
# coupled to Message, and we also need to persist the new rendered content.
# If we don't have a message object passed in, we get one here. The cost
# of going to the DB here should be overshadowed by the cost of rendering
# and updating the row.
message = Message.objects.select_related().get(id=message_id)
# It's unfortunate that we need to have side effects on the message
# in some cases.
rendered_content = message.render_markdown(content, sender_realm_domain)
message.set_rendered_content(rendered_content, True)
if rendered_content is not None:
obj['content'] = rendered_content
else:
obj['content'] = '<p>[Zulip note: Sorry, we could not understand the formatting of your message]</p>'
obj['content_type'] = 'text/html'
else:
obj['content'] = content
obj['content_type'] = 'text/x-markdown'
return obj
def to_log_dict(self):
return dict(
id = self.id,
sender_email = self.sender.email,
sender_domain = self.sender.realm.domain,
sender_full_name = self.sender.full_name,
sender_short_name = self.sender.short_name,
sending_client = self.sending_client.name,
type = self.recipient.type_name(),
recipient = get_display_recipient(self.recipient),
subject = self.subject,
content = self.content,
timestamp = datetime_to_timestamp(self.pub_date))
@staticmethod
def get_raw_db_rows(needed_ids):
# This is a special purpose function optimized for
# callers like get_old_messages_backend().
fields = [
'id',
'subject',
'pub_date',
'last_edit_time',
'edit_history',
'content',
'rendered_content',
'rendered_content_version',
'recipient_id',
'recipient__type',
'recipient__type_id',
'sender_id',
'sending_client__name',
'sender__email',
'sender__full_name',
'sender__short_name',
'sender__realm__id',
'sender__realm__domain',
'sender__avatar_source',
'sender__is_mirror_dummy',
]
return Message.objects.filter(id__in=needed_ids).values(*fields)
@classmethod
def remove_unreachable(cls):
"""Remove all Messages that are not referred to by any UserMessage."""
cls.objects.exclude(id__in = UserMessage.objects.values('message_id')).delete()
def sent_by_human(self):
sending_client = self.sending_client.name.lower()
return (sending_client in ('zulipandroid', 'zulipios', 'zulipdesktop',
'website', 'ios', 'android')) or \
('desktop app' in sending_client)
@staticmethod
def content_has_attachment(content):
return re.search('[/\-]user[\-_]uploads[/\.-]', content)
@staticmethod
def content_has_image(content):
return bool(re.search('[/\-]user[\-_]uploads[/\.-]\S+\.(bmp|gif|jpg|jpeg|png|webp)', content, re.IGNORECASE))
@staticmethod
def content_has_link(content):
return 'http://' in content or 'https://' in content or '/user_uploads' in content
def update_calculated_fields(self):
# TODO: rendered_content could also be considered a calculated field
content = self.content
self.has_attachment = bool(Message.content_has_attachment(content))
self.has_image = bool(Message.content_has_image(content))
self.has_link = bool(Message.content_has_link(content))
@receiver(pre_save, sender=Message)
def pre_save_message(sender, **kwargs):
if kwargs['update_fields'] is None or "content" in kwargs['update_fields']:
message = kwargs['instance']
message.update_calculated_fields()
def get_context_for_message(message):
return Message.objects.filter(
recipient_id=message.recipient_id,
subject=message.subject,
id__lt=message.id,
pub_date__gt=message.pub_date - timedelta(minutes=15),
).order_by('-id')[:10]
class UserMessage(models.Model):
user_profile = models.ForeignKey(UserProfile)
message = models.ForeignKey(Message)
# We're not using the archived field for now, but create it anyway
# since this table will be an unpleasant one to do schema changes
# on later
ALL_FLAGS = ['read', 'starred', 'collapsed', 'mentioned', 'wildcard_mentioned',
'summarize_in_home', 'summarize_in_stream', 'force_expand', 'force_collapse',
'has_alert_word', "historical", 'is_me_message']
flags = BitField(flags=ALL_FLAGS, default=0)
class Meta:
unique_together = ("user_profile", "message")
def __repr__(self):
display_recipient = get_display_recipient(self.message.recipient)
return (u"<UserMessage: %s / %s (%s)>" % (display_recipient, self.user_profile.email, self.flags_list())).encode("utf-8")
def flags_list(self):
return [flag for flag in self.flags.keys() if getattr(self.flags, flag).is_set]
def parse_usermessage_flags(val):
flags = []
mask = 1
for flag in UserMessage.ALL_FLAGS:
if val & mask:
flags.append(flag)
mask <<= 1
return flags
class Subscription(models.Model):
user_profile = models.ForeignKey(UserProfile)
recipient = models.ForeignKey(Recipient)
active = models.BooleanField(default=True)
in_home_view = models.NullBooleanField(default=True)
DEFAULT_STREAM_COLOR = "#c2c2c2"
color = models.CharField(max_length=10, default=DEFAULT_STREAM_COLOR)
desktop_notifications = models.BooleanField(default=True)
audible_notifications = models.BooleanField(default=True)
# Combination desktop + audible notifications superseded by the
# above.
notifications = models.BooleanField(default=False)
class Meta:
unique_together = ("user_profile", "recipient")
def __repr__(self):
return (u"<Subscription: %r -> %s>" % (self.user_profile, self.recipient)).encode("utf-8")
def __str__(self):
return self.__repr__()
@cache_with_key(user_profile_by_id_cache_key, timeout=3600*24*7)
def get_user_profile_by_id(uid):
return UserProfile.objects.select_related().get(id=uid)
@cache_with_key(user_profile_by_email_cache_key, timeout=3600*24*7)
def get_user_profile_by_email(email):
return UserProfile.objects.select_related().get(email__iexact=email.strip())
@cache_with_key(active_user_dicts_in_realm_cache_key, timeout=3600*24*7)
def get_active_user_dicts_in_realm(realm):
return UserProfile.objects.filter(realm=realm, is_active=True) \
.values('id', 'full_name', 'short_name', 'email', 'is_bot')
@cache_with_key(active_bot_dicts_in_realm_cache_key, timeout=3600*24*7)
def get_active_bot_dicts_in_realm(realm):
return UserProfile.objects.filter(realm=realm, is_active=True, is_bot=True) \
.values('id', 'full_name', 'short_name',
'email', 'default_sending_stream__name',
'default_events_register_stream__name',
'default_all_public_streams', 'api_key',
'bot_owner__email', 'avatar_source')
def get_prereg_user_by_email(email):
# A user can be invited many times, so only return the result of the latest
# invite.
return PreregistrationUser.objects.filter(email__iexact=email.strip()).latest("invited_at")
class Huddle(models.Model):
# TODO: We should consider whether using
# CommaSeparatedIntegerField would be better.
huddle_hash = models.CharField(max_length=40, db_index=True, unique=True)
def get_huddle_hash(id_list):
id_list = sorted(set(id_list))
hash_key = ",".join(str(x) for x in id_list)
return make_safe_digest(hash_key)
def huddle_hash_cache_key(huddle_hash):
return "huddle_by_hash:%s" % (huddle_hash,)
def get_huddle(id_list):
huddle_hash = get_huddle_hash(id_list)
return get_huddle_backend(huddle_hash, id_list)
@cache_with_key(lambda huddle_hash, id_list: huddle_hash_cache_key(huddle_hash), timeout=3600*24*7)
def get_huddle_backend(huddle_hash, id_list):
(huddle, created) = Huddle.objects.get_or_create(huddle_hash=huddle_hash)
if created:
with transaction.atomic():
recipient = Recipient.objects.create(type_id=huddle.id,
type=Recipient.HUDDLE)
subs_to_create = [Subscription(recipient=recipient,
user_profile=get_user_profile_by_id(user_profile_id))
for user_profile_id in id_list]
Subscription.objects.bulk_create(subs_to_create)
return huddle
def get_realm(domain):
if not domain:
return None
try:
return Realm.objects.get(domain__iexact=domain.strip())
except Realm.DoesNotExist:
return None
def clear_database():
pylibmc.Client(['127.0.0.1']).flush_all()
for model in [Message, Stream, UserProfile, Recipient,
Realm, Subscription, Huddle, UserMessage, Client,
DefaultStream]:
model.objects.all().delete()
Session.objects.all().delete()
class UserActivity(models.Model):
user_profile = models.ForeignKey(UserProfile)
client = models.ForeignKey(Client)
query = models.CharField(max_length=50, db_index=True)
count = models.IntegerField()
last_visit = models.DateTimeField('last visit')
class Meta:
unique_together = ("user_profile", "client", "query")
class UserActivityInterval(models.Model):
user_profile = models.ForeignKey(UserProfile)
start = models.DateTimeField('start time', db_index=True)
end = models.DateTimeField('end time', db_index=True)
class UserPresence(models.Model):
user_profile = models.ForeignKey(UserProfile)
client = models.ForeignKey(Client)
# Valid statuses
ACTIVE = 1
IDLE = 2
timestamp = models.DateTimeField('presence changed')
status = models.PositiveSmallIntegerField(default=ACTIVE)
@staticmethod
def status_to_string(status):
if status == UserPresence.ACTIVE:
return 'active'
elif status == UserPresence.IDLE:
return 'idle'
@staticmethod
def get_status_dict_by_realm(realm_id):
user_statuses = defaultdict(dict)
query = UserPresence.objects.filter(
user_profile__realm_id=realm_id,
user_profile__is_active=True,
user_profile__is_bot=False
).values(
'client__name',
'status',
'timestamp',
'user_profile__email',
'user_profile__id',
'user_profile__enable_offline_push_notifications',
'user_profile__is_mirror_dummy',
)
mobile_user_ids = [row['user'] for row in PushDeviceToken.objects.filter(
user__realm_id=1,
user__is_active=True,
user__is_bot=False,
).distinct("user").values("user")]
for row in query:
info = UserPresence.to_presence_dict(
client_name=row['client__name'],
status=row['status'],
timestamp=row['timestamp'],
push_enabled=row['user_profile__enable_offline_push_notifications'],
has_push_devices=row['user_profile__id'] in mobile_user_ids,
is_mirror_dummy=row['user_profile__is_mirror_dummy'],
)
user_statuses[row['user_profile__email']][row['client__name']] = info
return user_statuses
@staticmethod
def to_presence_dict(client_name=None, status=None, timestamp=None, push_enabled=None,
has_push_devices=None, is_mirror_dummy=None):
presence_val = UserPresence.status_to_string(status)
timestamp = datetime_to_timestamp(timestamp)
return dict(
client=client_name,
status=presence_val,
timestamp=timestamp,
pushable=(push_enabled and has_push_devices),
)
def to_dict(self):
return UserPresence.to_presence_dict(
client_name=self.client.name,
status=self.status,
timestamp=self.timestamp
)
@staticmethod
def status_from_string(status):
if status == 'active':
status_val = UserPresence.ACTIVE
elif status == 'idle':
status_val = UserPresence.IDLE
else:
status_val = None
return status_val
class Meta:
unique_together = ("user_profile", "client")
class DefaultStream(models.Model):
realm = models.ForeignKey(Realm)
stream = models.ForeignKey(Stream)
class Meta:
unique_together = ("realm", "stream")
# FIXME: The foreign key relationship here is backwards.
#
# We can't easily get a list of streams and their associated colors (if any) in
# a single query. See zerver.views.gather_subscriptions for an example.
#
# We should change things around so that is possible. Probably this should
# just be a column on Subscription.
class StreamColor(models.Model):
DEFAULT_STREAM_COLOR = "#c2c2c2"
subscription = models.ForeignKey(Subscription)
color = models.CharField(max_length=10)
class Referral(models.Model):
user_profile = models.ForeignKey(UserProfile)
email = models.EmailField(blank=False, null=False)
timestamp = models.DateTimeField(auto_now_add=True, null=False)
# This table only gets used on Zulip Voyager instances
# For reasons of deliverability (and sending from multiple email addresses),
# we will still send from mandrill when we send things from the (staging.)zulip.com install
class ScheduledJob(models.Model):
scheduled_timestamp = models.DateTimeField(auto_now_add=False, null=False)
type = models.PositiveSmallIntegerField()
# Valid types are {email}
# for EMAIL, filter_string is recipient_email
EMAIL = 1
# JSON representation of the job's data. Be careful, as we are not relying on Django to do validation
data = models.TextField()
# Kind if like a ForeignKey, but table is determined by type.
filter_id = models.IntegerField(null=True)
filter_string = models.CharField(max_length=100)
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
11836,
1563,
1899,
12,
2876,
2988,
12,
971,
272,
28260,
4256,
199,
504,
1639,
14,
6052,
492,
13035,
199,
504,
19959,
14,
773,
14,
1637,
492,
2581,
63,
1045,
63,
498,
12,
8976,
63,
751,
63,
2913,
12,
8976,
63,
7728,
12,
971,
272,
922,
63,
2913,
63,
991,
63,
344,
63,
1637,
63,
498,
12,
922,
63,
2913,
63,
991,
63,
2123,
63,
1637,
63,
498,
12,
971,
272,
7809,
63,
9377,
63,
5245,
63,
3535,
12,
2581,
63,
409,
12,
8976,
63,
1745,
12,
971,
272,
2929,
63,
10043,
63,
1637,
63,
498,
12,
2581,
63,
1807,
12,
971,
272,
664,
63,
1745,
63,
1637,
63,
498,
12,
4702,
63,
751,
63,
7892,
63,
262,
63,
7728,
63,
1637,
63,
498,
12,
971,
272,
4702,
63,
3018,
63,
7892,
63,
262,
63,
7728,
63,
1637,
63,
498,
199,
504,
19959,
14,
773,
14,
1208,
492,
1852,
63,
3489,
63,
5671,
12,
3550,
63,
2355,
63,
1418,
199,
504,
1639,
14,
697,
492,
6008,
12,
26864,
199,
504,
19959,
14,
773,
14,
14584,
492,
1999,
28694,
63,
2227,
12,
664,
63,
14584,
63,
633,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
2828,
14,
11676,
14,
992,
492,
8596,
199,
504,
19959,
14,
773,
14,
3954,
492,
2197,
63,
475,
63,
3954,
199,
504,
1639,
14,
697,
14,
992,
14,
10458,
492,
876,
63,
2117,
12,
2963,
63,
2117,
12,
2963,
63,
1807,
199,
504,
8129,
31186,
14,
17469,
492,
664,
63,
3707,
63,
1045,
63,
12068,
199,
646,
12472,
199,
199,
504,
4546,
698,
492,
10199,
792,
199,
504,
5055,
492,
10018,
199,
504,
2197,
492,
6871,
199,
646,
29219,
5466,
199,
646,
295,
199,
646,
399,
1001,
199,
646,
2050,
199,
199,
1266,
2110,
275,
488,
199,
199,
4283,
63,
6348,
5550,
63,
9127,
275,
5212,
199,
4283,
63,
8272,
63,
9127,
275,
11630,
199,
199,
3,
4226,
316,
5198,
7573,
5245,
4145,
370,
664,
63,
2918,
63,
10043,
365,
18794,
11999,
12,
199,
3,
880,
1050,
282,
2257,
2581,
465,
5521,
465,
314,
7573,
5245,
2581,
14,
199,
529,
63,
1069,
63,
2918,
63,
10043,
63,
1637,
275,
1052,
199,
318,
664,
63,
2918,
63,
10043,
63,
991,
63,
344,
8,
10043,
63,
344,
12,
10318,
63,
466,
12,
10318,
63,
466,
63,
344,
304,
272,
340,
10318,
63,
344,
440,
315,
1126,
63,
1069,
63,
2918,
63,
10043,
63,
1637,
26,
267,
754,
275,
664,
63,
2918,
63,
10043,
63,
32567,
8,
10043,
63,
344,
12,
10318,
63,
466,
12,
10318,
63,
466,
63,
344,
9,
267,
1126,
63,
1069,
63,
2918,
63,
10043,
63,
1637,
59,
10043,
63,
344,
61,
275,
754,
272,
372,
1126,
63,
1069,
63,
2918,
63,
10043,
63,
1637,
59,
10043,
63,
344,
61,
199,
199,
318,
664,
63,
2918,
63,
10043,
8,
10043,
304,
272,
372,
664,
63,
2918,
63,
10043,
63,
991,
63,
344,
8,
288,
10318,
14,
344,
12,
288,
10318,
14,
466,
12,
288,
10318,
14,
466,
63,
344,
272,
776,
199,
199,
318,
8976,
63,
529,
63,
1069,
63,
17595,
837,
272,
2288,
1126,
63,
1069,
63,
2918,
63,
10043,
63,
1637,
272,
1126,
63,
1069,
63,
2918,
63,
10043,
63,
1637,
275,
1052,
272,
2288,
1126,
63,
1069,
63,
7728,
63,
4273,
63,
1637,
272,
1126,
63,
1069,
63,
7728,
63,
4273,
63,
1637,
275,
1052,
199,
199,
32,
1637,
63,
1045,
63,
498,
8,
2734,
627,
589,
26,
2929,
63,
10043,
63,
1637,
63,
498,
8,
589,
59,
16,
2522,
355,
2653,
29,
11035,
10,
1194,
10,
23,
9,
199,
318,
664,
63,
2918,
63,
10043,
63,
32567,
8,
10043,
63,
344,
12,
10318,
63,
466,
12,
10318,
63,
466,
63,
344,
304,
272,
408,
272,
2529,
26,
376,
5827,
909,
13660,
314,
10318,
14,
221,
2104,
282,
272,
2547,
642,
911,
506,
314,
2547,
536,
465,
282,
1059,
14,
221,
2104,
282,
394,
8615,
274,
503,
272,
25994,
12,
652,
911,
506,
376,
1625,
402,
10809,
3595,
1924,
10318,
14,
272,
408,
272,
340,
10318,
63,
466,
508,
799,
6157,
14,
9484,
26,
267,
2547,
275,
8271,
14,
1462,
14,
362,
8,
344,
29,
10043,
63,
466,
63,
344,
9,
267,
372,
2547,
14,
354,
339,
327,
2136,
2793,
1133,
7710,
10296,
4052,
314,
7794,
365,
12,
2951,
626,
652,
1159,
25286,
14,
272,
922,
63,
2913,
63,
513,
275,
334,
23544,
14,
1462,
14,
1541,
8,
6645,
363,
10043,
63,
344,
29,
10043,
63,
344,
9,
4490,
1275,
2416,
63,
2407,
342,
4490,
1275,
1648,
63,
991,
360,
2123,
1333,
272,
372,
9016,
2123,
356,
922,
63,
2913,
14,
2123,
12,
1467,
283,
2261,
356,
922,
63,
2913,
14,
7728,
14,
2261,
12,
1467,
283,
2861,
63,
354,
356,
922,
63,
2913,
14,
2861,
63,
354,
12,
1467,
283,
3612,
63,
354,
356,
922,
63,
2913,
14,
3612,
63,
354,
12,
1467,
283,
344,
356,
922,
63,
2913,
14,
344,
12,
1467,
283,
374,
63,
12324,
63,
5869,
356,
922,
63,
2913,
14,
374,
63,
12324,
63,
5869,
28209,
367,
922,
63,
2913,
315,
922,
63,
2913,
63,
513,
61,
199,
199,
318,
14793,
63,
1490,
8,
2261,
304,
272,
327,
961,
2881,
365,
14793,
1551,
370,
4036,
368,
641,
314,
21408,
370,
272,
327,
4263,
14,
662,
13,
1198,
7149,
886,
440,
1929,
370,
1336,
314,
2881,
436,
272,
327,
376,
24542,
687,
376,
3411,
922,
365,
440,
1415,
14,
272,
10482,
275,
664,
63,
7728,
8,
2261,
9,
272,
340,
440,
10482,
26,
267,
372,
756,
272,
372,
440,
10482,
14,
19061,
63,
2427,
436,
440,
10482,
14,
17973,
63,
475,
63,
2261,
199,
199,
318,
664,
63,
3235,
63,
1490,
63,
7728,
837,
272,
327,
2136,
1454,
372,
282,
10482,
340,
2337,
365,
282,
3747,
10482,
436,
652,
365,
14793,
1551,
14,
272,
3363,
706,
275,
27715,
14,
1462,
14,
1541,
8,
271,
18218,
29,
797,
9,
272,
340,
822,
8,
3093,
706,
9,
1137,
413,
26,
267,
372,
488,
272,
10482,
275,
3363,
706,
59
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
11836,
1563,
1899,
12,
2876,
2988,
12,
971,
272,
28260,
4256,
199,
504,
1639,
14,
6052,
492,
13035,
199,
504,
19959,
14,
773,
14,
1637,
492,
2581,
63,
1045,
63,
498,
12,
8976,
63,
751,
63,
2913,
12,
8976,
63,
7728,
12,
971,
272,
922,
63,
2913,
63,
991,
63,
344,
63,
1637,
63,
498,
12,
922,
63,
2913,
63,
991,
63,
2123,
63,
1637,
63,
498,
12,
971,
272,
7809,
63,
9377,
63,
5245,
63,
3535,
12,
2581,
63,
409,
12,
8976,
63,
1745,
12,
971,
272,
2929,
63,
10043,
63,
1637,
63,
498,
12,
2581,
63,
1807,
12,
971,
272,
664,
63,
1745,
63,
1637,
63,
498,
12,
4702,
63,
751,
63,
7892,
63,
262,
63,
7728,
63,
1637,
63,
498,
12,
971,
272,
4702,
63,
3018,
63,
7892,
63,
262,
63,
7728,
63,
1637,
63,
498,
199,
504,
19959,
14,
773,
14,
1208,
492,
1852,
63,
3489,
63,
5671,
12,
3550,
63,
2355,
63,
1418,
199,
504,
1639,
14,
697,
492,
6008,
12,
26864,
199,
504,
19959,
14,
773,
14,
14584,
492,
1999,
28694,
63,
2227,
12,
664,
63,
14584,
63,
633,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
2828,
14,
11676,
14,
992,
492,
8596,
199,
504,
19959,
14,
773,
14,
3954,
492,
2197,
63,
475,
63,
3954,
199,
504,
1639,
14,
697,
14,
992,
14,
10458,
492,
876,
63,
2117,
12,
2963,
63,
2117,
12,
2963,
63,
1807,
199,
504,
8129,
31186,
14,
17469,
492,
664,
63,
3707,
63,
1045,
63,
12068,
199,
646,
12472,
199,
199,
504,
4546,
698,
492,
10199,
792,
199,
504,
5055,
492,
10018,
199,
504,
2197,
492,
6871,
199,
646,
29219,
5466,
199,
646,
295,
199,
646,
399,
1001,
199,
646,
2050,
199,
199,
1266,
2110,
275,
488,
199,
199,
4283,
63,
6348,
5550,
63,
9127,
275,
5212,
199,
4283,
63,
8272,
63,
9127,
275,
11630,
199,
199,
3,
4226,
316,
5198,
7573,
5245,
4145,
370,
664,
63,
2918,
63,
10043,
365,
18794,
11999,
12,
199,
3,
880,
1050,
282,
2257,
2581,
465,
5521,
465,
314,
7573,
5245,
2581,
14,
199,
529,
63,
1069,
63,
2918,
63,
10043,
63,
1637,
275,
1052,
199,
318,
664,
63,
2918,
63,
10043,
63,
991,
63,
344,
8,
10043,
63,
344,
12,
10318,
63,
466,
12,
10318,
63,
466,
63,
344,
304,
272,
340,
10318,
63,
344,
440,
315,
1126,
63,
1069,
63,
2918,
63,
10043,
63,
1637,
26,
267,
754,
275,
664,
63,
2918,
63,
10043,
63,
32567,
8,
10043,
63,
344,
12,
10318,
63,
466,
12,
10318,
63,
466,
63,
344,
9,
267,
1126,
63,
1069,
63,
2918,
63,
10043,
63,
1637,
59,
10043,
63,
344,
61,
275,
754,
272,
372,
1126,
63,
1069,
63,
2918,
63,
10043,
63,
1637,
59,
10043,
63,
344,
61,
199,
199,
318,
664,
63,
2918,
63,
10043,
8,
10043,
304,
272,
372,
664,
63,
2918,
63,
10043,
63,
991,
63,
344,
8,
288,
10318,
14,
344,
12,
288,
10318,
14,
466,
12,
288,
10318,
14,
466,
63,
344,
272,
776,
199,
199,
318,
8976,
63,
529,
63,
1069,
63,
17595,
837,
272,
2288,
1126,
63,
1069,
63,
2918,
63,
10043,
63,
1637,
272,
1126,
63,
1069,
63,
2918,
63,
10043,
63,
1637,
275,
1052,
272,
2288,
1126,
63,
1069,
63,
7728,
63,
4273,
63,
1637,
272,
1126,
63,
1069,
63,
7728,
63,
4273,
63,
1637,
275,
1052,
199,
199,
32,
1637,
63,
1045,
63,
498,
8,
2734,
627,
589,
26,
2929,
63,
10043,
63,
1637,
63,
498,
8,
589,
59,
16,
2522,
355,
2653,
29,
11035,
10,
1194,
10,
23,
9,
199,
318,
664,
63,
2918,
63,
10043,
63,
32567,
8,
10043,
63,
344,
12,
10318,
63,
466,
12,
10318,
63,
466,
63,
344,
304,
272,
408,
272,
2529,
26,
376,
5827,
909,
13660,
314,
10318,
14,
221,
2104,
282,
272,
2547,
642,
911,
506,
314,
2547,
536,
465,
282,
1059,
14,
221,
2104,
282,
394,
8615,
274,
503,
272,
25994,
12,
652,
911,
506,
376,
1625,
402,
10809,
3595,
1924,
10318,
14,
272,
408,
272,
340,
10318,
63,
466,
508,
799,
6157,
14,
9484,
26,
267,
2547,
275,
8271,
14,
1462,
14,
362,
8,
344,
29,
10043,
63,
466,
63,
344,
9,
267,
372,
2547,
14,
354,
339,
327,
2136,
2793,
1133,
7710,
10296,
4052,
314,
7794,
365,
12,
2951,
626,
652,
1159,
25286,
14,
272,
922,
63,
2913,
63,
513,
275,
334,
23544,
14,
1462,
14,
1541,
8,
6645,
363,
10043,
63,
344,
29,
10043,
63,
344,
9,
4490,
1275,
2416,
63,
2407,
342,
4490,
1275,
1648,
63,
991,
360,
2123,
1333,
272,
372,
9016,
2123,
356,
922,
63,
2913,
14,
2123,
12,
1467,
283,
2261,
356,
922,
63,
2913,
14,
7728,
14,
2261,
12,
1467,
283,
2861,
63,
354,
356,
922,
63,
2913,
14,
2861,
63,
354,
12,
1467,
283,
3612,
63,
354,
356,
922,
63,
2913,
14,
3612,
63,
354,
12,
1467,
283,
344,
356,
922,
63,
2913,
14,
344,
12,
1467,
283,
374,
63,
12324,
63,
5869,
356,
922,
63,
2913,
14,
374,
63,
12324,
63,
5869,
28209,
367,
922,
63,
2913,
315,
922,
63,
2913,
63,
513,
61,
199,
199,
318,
14793,
63,
1490,
8,
2261,
304,
272,
327,
961,
2881,
365,
14793,
1551,
370,
4036,
368,
641,
314,
21408,
370,
272,
327,
4263,
14,
662,
13,
1198,
7149,
886,
440,
1929,
370,
1336,
314,
2881,
436,
272,
327,
376,
24542,
687,
376,
3411,
922,
365,
440,
1415,
14,
272,
10482,
275,
664,
63,
7728,
8,
2261,
9,
272,
340,
440,
10482,
26,
267,
372,
756,
272,
372,
440,
10482,
14,
19061,
63,
2427,
436,
440,
10482,
14,
17973,
63,
475,
63,
2261,
199,
199,
318,
664,
63,
3235,
63,
1490,
63,
7728,
837,
272,
327,
2136,
1454,
372,
282,
10482,
340,
2337,
365,
282,
3747,
10482,
436,
652,
365,
14793,
1551,
14,
272,
3363,
706,
275,
27715,
14,
1462,
14,
1541,
8,
271,
18218,
29,
797,
9,
272,
340,
822,
8,
3093,
706,
9,
1137,
413,
26,
267,
372,
488,
272,
10482,
275,
3363,
706,
59,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
washort/zamboni
|
mkt/feed/fields.py
|
6
|
5042
|
from rest_framework import serializers
from mkt.fireplace.serializers import FeedFireplaceESAppSerializer
from mkt.webapps.serializers import (AppSerializer, ESAppFeedSerializer,
ESAppFeedCollectionSerializer,
ESAppSerializer)
class FeedCollectionMembershipField(serializers.PrimaryKeyRelatedField):
"""
Serializer field to be used with M2M model fields to Webapps, replacing
instances of the Membership instances with serializations of the Webapps
that they correspond to.
"""
def to_representation(self, qs, use_es=False):
return AppSerializer(qs, context=self.context).data
class AppESField(serializers.Field):
"""
Deserialize an app id using ESAppSerializer.
For object-to-app relations in ES, we store app IDs as a property of the
object. Since we want to limit ES queries, we batch-query for objects,
and then batch-query for apps. Afterwards, we set up app_map which is
used to deserialize app IDs to app ES data. This class helps deserialize
using that map and expects app IDs (i.e., passed through source).
If the app does not exist in the app map, we consider that the app was
filtered out (as a result of status, region, device filtering). In that
case, we just return None or exclude it.
self.context['app_map'] -- mapping from app ID to app ES object
"""
app_serializer_classes = {
'fireplace': FeedFireplaceESAppSerializer,
}
@property
def serializer_class(self):
request = self.context['request']
app_serializer = request.GET.get('app_serializer')
# TODO: remove once fireplace is using
# /consumer/feed/...?app_serializer=fireplace.
if app_serializer is None and '/fireplace/' in request.path:
app_serializer = 'fireplace'
return self.app_serializer_classes.get(app_serializer, ESAppSerializer)
def __init__(self, *args, **kwargs):
self.many = kwargs.pop('many', False)
self.limit = kwargs.pop('limit', None)
super(AppESField, self).__init__(*args, **kwargs)
def _attach_group(self, app):
"""
Attach feed collection grouped apps (for 'mega collection').
Sets app.group_translations to something like
[{'lang': 'en-US', 'string': 'My Group'}].
"""
if self.context.get('group_apps'):
group_index = self.context['group_apps'].get(unicode(app['id']))
if group_index is None:
# ES seems to sometimes return ID keyed on string and integer.
group_index = self.context['group_apps'].get(app['id'])
if group_index is not None:
if isinstance(app, dict):
app.update(self.context['group_names'][group_index])
else:
setattr(app, 'group_translations',
self.context['group_names'][group_index]
['group_translations'])
return app
def to_representation(self, app_ids):
"""App ID to serialized app."""
app_map = self.context['app_map']
if self.context.get('group_apps'):
# Attach groups.
app_map = dict(self.context['app_map'])
for app_id, app in app_map.items():
app = self._attach_group(app)
if self.many:
# Deserialize app ID to ES app data.
partially_deserialized_apps = [
app_map[app_id] for app_id in app_ids if app_map.get(app_id)]
# Deserialize ES app data to full data.
apps = self.serializer_class(
partially_deserialized_apps, many=True,
context=self.context).data
# If limit is specified, limit the number of apps.
if self.limit is not None:
apps = apps[:self.limit]
return apps
else:
# Single object, app_ids is only one app ID.
if not app_map.get(app_ids):
return None
return self.serializer_class(app_map[app_ids],
context=self.context).data
def to_internal_value(self, data):
if self.many:
return [app['id'] for app in data['apps']]
else:
return data['id']
class AppESHomeField(AppESField):
"""
Like AppESField, except using ESAppFeedSerializer instead of
ESAppSerializer. For a slimmer homepage since apps/brands only need
enough to render the market tile.
"""
@property
def serializer_class(self):
return ESAppFeedSerializer
class AppESHomePromoCollectionField(AppESField):
"""
Like AppESField, except using ESAppFeedCollectionSerializer instead of
ESAppSerializer. For a slimmer homepage since collection/shelves only
need icons.
"""
@property
def serializer_class(self):
return ESAppFeedCollectionSerializer
|
bsd-3-clause
|
[
504,
4618,
63,
4857,
492,
12506,
199,
199,
504,
21825,
14,
329,
1814,
14,
12844,
492,
16261,
9047,
1814,
654,
2640,
7299,
199,
504,
21825,
14,
2520,
5181,
14,
12844,
492,
334,
2640,
7299,
12,
10427,
2640,
7658,
7299,
12,
3660,
10427,
2640,
7658,
7768,
7299,
12,
3660,
10427,
2640,
7299,
9,
421,
199,
533,
16261,
7768,
19480,
792,
8,
12844,
14,
29457,
13885,
792,
304,
272,
408,
272,
25555,
901,
370,
506,
1202,
543,
603,
18,
45,
1402,
1504,
370,
6001,
5181,
12,
15810,
272,
4454,
402,
314,
24326,
4454,
543,
3012,
12270,
402,
314,
6001,
5181,
272,
626,
2985,
17118,
370,
14,
272,
408,
339,
347,
370,
63,
22903,
8,
277,
12,
6377,
12,
675,
63,
397,
29,
797,
304,
267,
372,
4693,
7299,
8,
6177,
12,
1067,
29,
277,
14,
1100,
680,
576,
421,
199,
533,
4693,
654,
792,
8,
12844,
14,
792,
304,
272,
408,
272,
1487,
3549,
376,
1145,
1305,
1808,
10427,
2640,
7299,
14,
339,
2104,
909,
13,
475,
13,
571,
16109,
315,
10427,
12,
781,
3877,
1145,
11449,
465,
282,
3324,
402,
314,
272,
909,
14,
9336,
781,
2934,
370,
2304,
10427,
9212,
12,
781,
3522,
13,
1131,
367,
2251,
12,
272,
436,
2066,
3522,
13,
1131,
367,
8686,
14,
12836,
4751,
12,
781,
663,
1536,
1145,
63,
1130,
1314,
365,
272,
1202,
370,
22920,
1145,
11449,
370,
1145,
10427,
666,
14,
961,
1021,
22577,
22920,
272,
1808,
626,
2341,
436,
14292,
1145,
11449,
334,
73,
14,
69,
2020,
3032,
4012,
1350,
680,
339,
982,
314,
1145,
1630,
440,
2187,
315,
314,
1145,
2341,
12,
781,
11201,
626,
314,
1145,
1990,
272,
9806,
734,
334,
305,
282,
754,
402,
2004,
12,
4897,
12,
2243,
14545,
680,
1010,
626,
272,
1930,
12,
781,
2951,
372,
488,
503,
5760,
652,
14,
339,
291,
14,
1100,
459,
571,
63,
1130,
418,
1553,
4412,
687,
1145,
2870,
370,
1145,
10427,
909,
272,
408,
272,
1145,
63,
8349,
63,
2888,
275,
469,
267,
283,
329,
1814,
356,
16261,
9047,
1814,
654,
2640,
7299,
12,
272,
789,
339,
768,
1829,
272,
347,
9146,
63,
533,
8,
277,
304,
267,
1056,
275,
291,
14,
1100,
459,
1069,
418,
267,
1145,
63,
8349,
275,
1056,
14,
2970,
14,
362,
360,
571,
63,
8349,
358,
398,
327,
3254,
26,
2813,
5403,
5883,
1814,
365,
1808,
267,
327,
1182,
8542,
15,
3871,
15,
1396,
31,
571,
63,
8349,
29,
329,
1814,
14,
267,
340,
1145,
63,
8349,
365,
488,
436,
1994,
329,
1814,
4805,
315,
1056,
14,
515,
26,
288,
1145,
63,
8349,
275,
283,
329,
1814,
7,
398,
372,
291,
14,
571,
63,
8349,
63,
2888,
14,
362,
8,
571,
63,
8349,
12,
10427,
2640,
7299,
9,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
3479,
275,
2074,
14,
1935,
360,
3479,
297,
756,
9,
267,
291,
14,
3097,
275,
2074,
14,
1935,
360,
3097,
297,
488,
9,
267,
1613,
8,
2640,
654,
792,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
485,
5040,
63,
923,
8,
277,
12,
1145,
304,
267,
408,
267,
21328,
4733,
3245,
16251,
8686,
334,
509,
283,
29073,
3245,
1959,
267,
10729,
1145,
14,
923,
63,
13982,
370,
6020,
2839,
288,
9016,
4159,
356,
283,
287,
13,
1668,
297,
283,
875,
356,
283,
5713,
5611,
936,
1055,
267,
408,
267,
340,
291,
14,
1100,
14,
362,
360,
923,
63,
5181,
735,
288,
1572,
63,
1080,
275,
291,
14,
1100,
459,
923,
63,
5181,
2278,
362,
8,
2975,
8,
571,
459,
344,
5156,
288,
340,
1572,
63,
1080,
365,
488,
26,
355,
327,
10427,
12237,
370,
15026,
372,
2870,
19272,
641,
1059,
436,
3000,
14,
355,
1572,
63,
1080,
275,
291,
14,
1100,
459,
923,
63,
5181,
2278,
362,
8,
571,
459,
344,
1105,
288,
340,
1572,
63,
1080,
365,
440,
488,
26,
355,
340,
1228,
8,
571,
12,
1211,
304,
490,
1145,
14,
873,
8,
277,
14,
1100,
459,
923,
63,
1247,
3488,
923,
63,
1080,
566,
355,
587,
26,
490,
5371,
8,
571,
12,
283,
923,
63,
13982,
297,
1169,
291,
14,
1100,
459,
923,
63,
1247,
3488,
923,
63,
1080,
61,
3147,
788,
923,
63,
13982,
1105,
267,
372,
1145,
339,
347,
370,
63,
22903,
8,
277,
12,
1145,
63,
1580,
304,
267,
408,
2640,
2870,
370,
6380,
1145,
1041,
267,
1145,
63,
1130,
275,
291,
14,
1100,
459,
571,
63,
1130,
418,
267,
340,
291,
14,
1100,
14,
362,
360,
923,
63,
5181,
735,
288,
327,
21328,
4652,
14,
288,
1145,
63,
1130,
275,
1211,
8,
277,
14,
1100,
459,
571,
63,
1130,
1105,
288,
367,
1145,
63,
344,
12,
1145,
315,
1145,
63,
1130,
14,
1744,
837,
355,
1145,
275,
291,
423,
5040,
63,
923,
8,
571,
9,
398,
340,
291,
14,
3479,
26,
288,
327,
1487,
3549,
1145,
2870,
370,
10427,
1145,
666,
14,
288,
25172,
63,
271,
8397,
63,
5181,
275,
359,
355,
1145,
63,
1130,
59,
571,
63,
344,
61,
367,
1145,
63,
344,
315,
1145,
63,
1580,
340,
1145,
63,
1130,
14,
362,
8,
571,
63,
344,
1874,
953,
327,
1487,
3549,
10427,
1145,
666,
370,
2615,
666,
14,
288,
8686,
275,
291,
14,
8349,
63,
533,
8,
355,
25172,
63,
271,
8397,
63,
5181,
12,
5002,
29,
549,
12,
355,
1067,
29,
277,
14,
1100,
680,
576,
953,
327,
982,
2304,
365,
2013,
12,
2304,
314,
1329,
402,
8686,
14,
288,
340,
291,
14,
3097,
365,
440,
488,
26,
355,
8686,
275,
8686,
1491,
277,
14,
3097,
61,
953,
372,
8686,
267,
587,
26,
288,
327,
13050,
909,
12,
1145,
63,
1580,
365,
1454,
1373,
1145,
2870,
14,
288,
340,
440,
1145,
63,
1130,
14,
362,
8,
571,
63,
1580,
304,
355,
372,
488,
953,
372,
291,
14,
8349,
63,
533,
8,
571,
63,
1130,
59,
571,
63,
1580,
467,
1460,
1067,
29,
277,
14,
1100,
680,
576,
339,
347,
370,
63,
4672,
63,
585,
8,
277,
12,
666,
304,
267,
340,
291,
14,
3479,
26,
288,
372,
359,
571,
459,
344,
418,
367,
1145,
315,
666,
459,
5181,
6538,
267,
587,
26,
288,
372,
666,
459,
344,
418,
421,
199,
533,
4693,
654,
12054,
792,
8,
2640,
654,
792
] |
[
4618,
63,
4857,
492,
12506,
199,
199,
504,
21825,
14,
329,
1814,
14,
12844,
492,
16261,
9047,
1814,
654,
2640,
7299,
199,
504,
21825,
14,
2520,
5181,
14,
12844,
492,
334,
2640,
7299,
12,
10427,
2640,
7658,
7299,
12,
3660,
10427,
2640,
7658,
7768,
7299,
12,
3660,
10427,
2640,
7299,
9,
421,
199,
533,
16261,
7768,
19480,
792,
8,
12844,
14,
29457,
13885,
792,
304,
272,
408,
272,
25555,
901,
370,
506,
1202,
543,
603,
18,
45,
1402,
1504,
370,
6001,
5181,
12,
15810,
272,
4454,
402,
314,
24326,
4454,
543,
3012,
12270,
402,
314,
6001,
5181,
272,
626,
2985,
17118,
370,
14,
272,
408,
339,
347,
370,
63,
22903,
8,
277,
12,
6377,
12,
675,
63,
397,
29,
797,
304,
267,
372,
4693,
7299,
8,
6177,
12,
1067,
29,
277,
14,
1100,
680,
576,
421,
199,
533,
4693,
654,
792,
8,
12844,
14,
792,
304,
272,
408,
272,
1487,
3549,
376,
1145,
1305,
1808,
10427,
2640,
7299,
14,
339,
2104,
909,
13,
475,
13,
571,
16109,
315,
10427,
12,
781,
3877,
1145,
11449,
465,
282,
3324,
402,
314,
272,
909,
14,
9336,
781,
2934,
370,
2304,
10427,
9212,
12,
781,
3522,
13,
1131,
367,
2251,
12,
272,
436,
2066,
3522,
13,
1131,
367,
8686,
14,
12836,
4751,
12,
781,
663,
1536,
1145,
63,
1130,
1314,
365,
272,
1202,
370,
22920,
1145,
11449,
370,
1145,
10427,
666,
14,
961,
1021,
22577,
22920,
272,
1808,
626,
2341,
436,
14292,
1145,
11449,
334,
73,
14,
69,
2020,
3032,
4012,
1350,
680,
339,
982,
314,
1145,
1630,
440,
2187,
315,
314,
1145,
2341,
12,
781,
11201,
626,
314,
1145,
1990,
272,
9806,
734,
334,
305,
282,
754,
402,
2004,
12,
4897,
12,
2243,
14545,
680,
1010,
626,
272,
1930,
12,
781,
2951,
372,
488,
503,
5760,
652,
14,
339,
291,
14,
1100,
459,
571,
63,
1130,
418,
1553,
4412,
687,
1145,
2870,
370,
1145,
10427,
909,
272,
408,
272,
1145,
63,
8349,
63,
2888,
275,
469,
267,
283,
329,
1814,
356,
16261,
9047,
1814,
654,
2640,
7299,
12,
272,
789,
339,
768,
1829,
272,
347,
9146,
63,
533,
8,
277,
304,
267,
1056,
275,
291,
14,
1100,
459,
1069,
418,
267,
1145,
63,
8349,
275,
1056,
14,
2970,
14,
362,
360,
571,
63,
8349,
358,
398,
327,
3254,
26,
2813,
5403,
5883,
1814,
365,
1808,
267,
327,
1182,
8542,
15,
3871,
15,
1396,
31,
571,
63,
8349,
29,
329,
1814,
14,
267,
340,
1145,
63,
8349,
365,
488,
436,
1994,
329,
1814,
4805,
315,
1056,
14,
515,
26,
288,
1145,
63,
8349,
275,
283,
329,
1814,
7,
398,
372,
291,
14,
571,
63,
8349,
63,
2888,
14,
362,
8,
571,
63,
8349,
12,
10427,
2640,
7299,
9,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
3479,
275,
2074,
14,
1935,
360,
3479,
297,
756,
9,
267,
291,
14,
3097,
275,
2074,
14,
1935,
360,
3097,
297,
488,
9,
267,
1613,
8,
2640,
654,
792,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
485,
5040,
63,
923,
8,
277,
12,
1145,
304,
267,
408,
267,
21328,
4733,
3245,
16251,
8686,
334,
509,
283,
29073,
3245,
1959,
267,
10729,
1145,
14,
923,
63,
13982,
370,
6020,
2839,
288,
9016,
4159,
356,
283,
287,
13,
1668,
297,
283,
875,
356,
283,
5713,
5611,
936,
1055,
267,
408,
267,
340,
291,
14,
1100,
14,
362,
360,
923,
63,
5181,
735,
288,
1572,
63,
1080,
275,
291,
14,
1100,
459,
923,
63,
5181,
2278,
362,
8,
2975,
8,
571,
459,
344,
5156,
288,
340,
1572,
63,
1080,
365,
488,
26,
355,
327,
10427,
12237,
370,
15026,
372,
2870,
19272,
641,
1059,
436,
3000,
14,
355,
1572,
63,
1080,
275,
291,
14,
1100,
459,
923,
63,
5181,
2278,
362,
8,
571,
459,
344,
1105,
288,
340,
1572,
63,
1080,
365,
440,
488,
26,
355,
340,
1228,
8,
571,
12,
1211,
304,
490,
1145,
14,
873,
8,
277,
14,
1100,
459,
923,
63,
1247,
3488,
923,
63,
1080,
566,
355,
587,
26,
490,
5371,
8,
571,
12,
283,
923,
63,
13982,
297,
1169,
291,
14,
1100,
459,
923,
63,
1247,
3488,
923,
63,
1080,
61,
3147,
788,
923,
63,
13982,
1105,
267,
372,
1145,
339,
347,
370,
63,
22903,
8,
277,
12,
1145,
63,
1580,
304,
267,
408,
2640,
2870,
370,
6380,
1145,
1041,
267,
1145,
63,
1130,
275,
291,
14,
1100,
459,
571,
63,
1130,
418,
267,
340,
291,
14,
1100,
14,
362,
360,
923,
63,
5181,
735,
288,
327,
21328,
4652,
14,
288,
1145,
63,
1130,
275,
1211,
8,
277,
14,
1100,
459,
571,
63,
1130,
1105,
288,
367,
1145,
63,
344,
12,
1145,
315,
1145,
63,
1130,
14,
1744,
837,
355,
1145,
275,
291,
423,
5040,
63,
923,
8,
571,
9,
398,
340,
291,
14,
3479,
26,
288,
327,
1487,
3549,
1145,
2870,
370,
10427,
1145,
666,
14,
288,
25172,
63,
271,
8397,
63,
5181,
275,
359,
355,
1145,
63,
1130,
59,
571,
63,
344,
61,
367,
1145,
63,
344,
315,
1145,
63,
1580,
340,
1145,
63,
1130,
14,
362,
8,
571,
63,
344,
1874,
953,
327,
1487,
3549,
10427,
1145,
666,
370,
2615,
666,
14,
288,
8686,
275,
291,
14,
8349,
63,
533,
8,
355,
25172,
63,
271,
8397,
63,
5181,
12,
5002,
29,
549,
12,
355,
1067,
29,
277,
14,
1100,
680,
576,
953,
327,
982,
2304,
365,
2013,
12,
2304,
314,
1329,
402,
8686,
14,
288,
340,
291,
14,
3097,
365,
440,
488,
26,
355,
8686,
275,
8686,
1491,
277,
14,
3097,
61,
953,
372,
8686,
267,
587,
26,
288,
327,
13050,
909,
12,
1145,
63,
1580,
365,
1454,
1373,
1145,
2870,
14,
288,
340,
440,
1145,
63,
1130,
14,
362,
8,
571,
63,
1580,
304,
355,
372,
488,
953,
372,
291,
14,
8349,
63,
533,
8,
571,
63,
1130,
59,
571,
63,
1580,
467,
1460,
1067,
29,
277,
14,
1100,
680,
576,
339,
347,
370,
63,
4672,
63,
585,
8,
277,
12,
666,
304,
267,
340,
291,
14,
3479,
26,
288,
372,
359,
571,
459,
344,
418,
367,
1145,
315,
666,
459,
5181,
6538,
267,
587,
26,
288,
372,
666,
459,
344,
418,
421,
199,
533,
4693,
654,
12054,
792,
8,
2640,
654,
792,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
prasadvagdargi/med_image_analysis
|
Testing/Unit/sitkGetArrayViewFromImageTest.py
|
2
|
6220
|
#==========================================================================
#
# Copyright Insight Software Consortium
#
# 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.txt
#
# 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 print_function
import sys
import unittest
import datetime as dt
import timeit
import SimpleITK as sitk
import numpy as np
sizeX = 4
sizeY = 5
sizeZ = 3
newSimpleITKPixelValueInt32 = -3000
newNumPyElementValueInt32 = 200
class TestNumpySimpleITKMemoryviewInterface(unittest.TestCase):
""" This tests numpy array <-> SimpleITK Image conversion. """
def setUp(self):
pass
def _helper_check_sitk_to_numpy_type(self, sitkType, numpyType):
if sitkType == sitk.sitkUnknown:
return
image = sitk.Image((9, 10), sitkType, 1)
a = sitk.GetArrayViewFromImage(image)
self.assertEqual(numpyType, a.dtype)
self.assertEqual((10, 9), a.shape)
def test_type_to_numpy(self):
"try all sitk pixel types to convert to NumPy array view"
self._helper_check_sitk_to_numpy_type(sitk.sitkUInt8, np.uint8)
self._helper_check_sitk_to_numpy_type(sitk.sitkUInt16, np.uint16)
self._helper_check_sitk_to_numpy_type(sitk.sitkUInt32, np.uint32)
self._helper_check_sitk_to_numpy_type(sitk.sitkUInt64, np.uint64)
self._helper_check_sitk_to_numpy_type(sitk.sitkInt8, np.int8)
self._helper_check_sitk_to_numpy_type(sitk.sitkInt16, np.int16)
self._helper_check_sitk_to_numpy_type(sitk.sitkInt32, np.int32)
self._helper_check_sitk_to_numpy_type(sitk.sitkInt64, np.int64)
self._helper_check_sitk_to_numpy_type(sitk.sitkFloat32, np.float32)
self._helper_check_sitk_to_numpy_type(sitk.sitkFloat64, np.float64)
self._helper_check_sitk_to_numpy_type(sitk.sitkVectorUInt8, np.uint8)
self._helper_check_sitk_to_numpy_type(sitk.sitkVectorInt8, np.int8)
self._helper_check_sitk_to_numpy_type(sitk.sitkVectorUInt16, np.uint16)
self._helper_check_sitk_to_numpy_type(sitk.sitkVectorInt16, np.int16)
self._helper_check_sitk_to_numpy_type(sitk.sitkVectorUInt32, np.uint32)
self._helper_check_sitk_to_numpy_type(sitk.sitkVectorInt32, np.int32)
self._helper_check_sitk_to_numpy_type(sitk.sitkVectorUInt64, np.uint64)
self._helper_check_sitk_to_numpy_type(sitk.sitkVectorInt64, np.int64)
self._helper_check_sitk_to_numpy_type(sitk.sitkVectorFloat32, np.float32)
self._helper_check_sitk_to_numpy_type(sitk.sitkVectorFloat64, np.float64)
def test_to_numpy_and_back(self):
"""Test converting an image to NumPy array view and back"""
img = sitk.GaussianSource( sitk.sitkFloat32, [100,100], sigma=[10]*3, mean=[50,50] )
h = sitk.Hash( img )
img2 = sitk.GetImageFromArray( sitk.GetArrayViewFromImage(img))
self.assertEqual( h, sitk.Hash( img2 ))
def test_vector_image_to_numpy(self):
"""Test converting back and forth between NumPy array view and SimpleITK
images where the SimpleITK image has multiple components and
stored as a VectorImage."""
# Check 2D
img = sitk.PhysicalPointSource(sitk.sitkVectorFloat32, [3,4])
h = sitk.Hash( img )
nda = sitk.GetArrayViewFromImage(img)
self.assertEqual(nda.shape, (4,3,2))
self.assertEqual(nda[0,0].tolist(), [0,0])
self.assertEqual(nda[2,1].tolist(), [1,2])
self.assertEqual(nda[0,:,0].tolist(), [0,1,2])
img2 = sitk.GetImageFromArray(nda, isVector=True)
self.assertEqual(h, sitk.Hash(img2))
# check 3D
img = sitk.PhysicalPointSource(sitk.sitkVectorFloat32, [3,4,5])
h = sitk.Hash(img)
nda = sitk.GetArrayViewFromImage(img)
self.assertEqual(nda.shape, (5,4,3,3))
self.assertEqual(nda[0,0,0].tolist(), [0,0,0])
self.assertEqual(nda[0,0,:,0].tolist(), [0,1,2])
self.assertEqual(nda[0,:,1,1].tolist(), [0,1,2,3])
img2 = sitk.GetImageFromArray(nda)
self.assertEqual(img2.GetSize(), img.GetSize())
self.assertEqual(img2.GetNumberOfComponentsPerPixel(), img.GetNumberOfComponentsPerPixel())
self.assertEqual(h, sitk.Hash(img2))
def test_arrayview_writable(self):
"""Test correct behavior of writablity to the returned array view."""
img = sitk.Image((9, 10), sitk.sitkFloat32, 1)
a = sitk.GetArrayViewFromImage(img)
with self.assertRaises(ValueError):
a.fill(0)
def test_processing_time(self):
"""Check the processing time the conversions from SimpleITK Image
to numpy array (GetArrayViewFromImage) and
numpy memoryview (GetArrayViewFromImage)."""
# Performance test for SimpleITK Image -> NumPy array
img = sitk.GaussianSource(sitk.sitkFloat32, [3000,3000], sigma=[10]*3, mean=[50,50])
print("\nGet NumPy array from 3000x3000 SimpleITK Image")
nparray_time_elapsed = min(timeit.repeat(lambda: sitk.GetArrayFromImage(img), repeat=5, number=1))
print ("Processing time of GetArrayFromImage (Copy operation) :: {0} (us)".format(nparray_time_elapsed*1e6))
npview_time_elapsed = min(timeit.repeat(lambda: sitk.GetArrayViewFromImage(img), repeat=5, number=1))
print ("Processing time of GetArrayViewFromImage (Array view) :: {0} (us)".format(npview_time_elapsed*1e6))
self.assertTrue( nparray_time_elapsed > npview_time_elapsed)
# Performance test for NumPy array -> SimpleITK Image
Big_nparray = np.zeros((3000,3000), dtype=np.int64);
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
14813,
17575,
199,
3,
199,
3,
257,
1898,
1010,
22727,
2290,
1448,
1509,
280,
453,
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,
3515,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
14,
2424,
199,
3,
199,
3,
257,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
257,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
257,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
257,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
257,
4204,
1334,
314,
844,
14,
199,
3,
199,
14813,
17575,
15870,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
984,
199,
646,
2882,
199,
646,
2197,
465,
4487,
199,
646,
900,
390,
421,
199,
646,
5870,
649,
43,
465,
13867,
75,
199,
646,
2680,
465,
980,
199,
199,
890,
56,
275,
841,
199,
890,
57,
275,
959,
199,
890,
58,
275,
650,
199,
1222,
3184,
649,
43,
14383,
1110,
3241,
708,
275,
446,
19962,
199,
1222,
5667,
2713,
2162,
1110,
3241,
708,
257,
275,
1926,
4388,
199,
533,
1379,
25218,
3184,
649,
43,
8628,
1345,
4267,
8,
2796,
14,
1746,
304,
272,
408,
961,
2295,
2680,
1625,
665,
5118,
5870,
649,
43,
6047,
8603,
14,
408,
339,
347,
3613,
8,
277,
304,
267,
986,
339,
347,
485,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
277,
12,
13867,
75,
804,
12,
2680,
804,
304,
267,
340,
13867,
75,
804,
508,
13867,
75,
14,
2221,
75,
5912,
26,
288,
372,
267,
1834,
275,
13867,
75,
14,
3491,
1332,
25,
12,
1616,
395,
13867,
75,
804,
12,
413,
9,
267,
282,
275,
13867,
75,
14,
1002,
3836,
2768,
2532,
3491,
8,
1569,
9,
267,
291,
14,
629,
8,
4714,
804,
12,
282,
14,
2271,
9,
267,
291,
14,
629,
1332,
709,
12,
1749,
395,
282,
14,
1392,
9,
339,
347,
511,
63,
466,
63,
475,
63,
4714,
8,
277,
304,
267,
298,
893,
1006,
13867,
75,
7148,
2943,
370,
3957,
370,
20602,
1625,
2455,
2,
398,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
13304,
24,
12,
980,
14,
1635,
24,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
13304,
975,
12,
980,
14,
1635,
975,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
13304,
708,
12,
980,
14,
1635,
708,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
13304,
772,
12,
980,
14,
1635,
772,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3241,
24,
12,
980,
14,
442,
24,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3241,
975,
12,
980,
14,
442,
975,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3241,
708,
12,
980,
14,
442,
708,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3241,
772,
12,
980,
14,
442,
772,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
5136,
708,
12,
980,
14,
1609,
708,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
5136,
772,
12,
980,
14,
1609,
772,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
13304,
24,
12,
980,
14,
1635,
24,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
3241,
24,
12,
980,
14,
442,
24,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
13304,
975,
12,
980,
14,
1635,
975,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
3241,
975,
12,
980,
14,
442,
975,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
13304,
708,
12,
980,
14,
1635,
708,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
3241,
708,
12,
980,
14,
442,
708,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
13304,
772,
12,
980,
14,
1635,
772,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
3241,
772,
12,
980,
14,
442,
772,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
5136,
708,
12,
980,
14,
1609,
708,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
5136,
772,
12,
980,
14,
1609,
772,
9,
339,
347,
511,
63,
475,
63,
4714,
63,
460,
63,
894,
8,
277,
304,
267,
408,
774,
13806,
376,
1834,
370,
20602,
1625,
2455,
436,
1771,
624,
398,
6050,
275,
13867,
75
] |
[
17575,
199,
3,
199,
3,
257,
1898,
1010,
22727,
2290,
1448,
1509,
280,
453,
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,
3515,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
14,
2424,
199,
3,
199,
3,
257,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
257,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
257,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
257,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
257,
4204,
1334,
314,
844,
14,
199,
3,
199,
14813,
17575,
15870,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
984,
199,
646,
2882,
199,
646,
2197,
465,
4487,
199,
646,
900,
390,
421,
199,
646,
5870,
649,
43,
465,
13867,
75,
199,
646,
2680,
465,
980,
199,
199,
890,
56,
275,
841,
199,
890,
57,
275,
959,
199,
890,
58,
275,
650,
199,
1222,
3184,
649,
43,
14383,
1110,
3241,
708,
275,
446,
19962,
199,
1222,
5667,
2713,
2162,
1110,
3241,
708,
257,
275,
1926,
4388,
199,
533,
1379,
25218,
3184,
649,
43,
8628,
1345,
4267,
8,
2796,
14,
1746,
304,
272,
408,
961,
2295,
2680,
1625,
665,
5118,
5870,
649,
43,
6047,
8603,
14,
408,
339,
347,
3613,
8,
277,
304,
267,
986,
339,
347,
485,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
277,
12,
13867,
75,
804,
12,
2680,
804,
304,
267,
340,
13867,
75,
804,
508,
13867,
75,
14,
2221,
75,
5912,
26,
288,
372,
267,
1834,
275,
13867,
75,
14,
3491,
1332,
25,
12,
1616,
395,
13867,
75,
804,
12,
413,
9,
267,
282,
275,
13867,
75,
14,
1002,
3836,
2768,
2532,
3491,
8,
1569,
9,
267,
291,
14,
629,
8,
4714,
804,
12,
282,
14,
2271,
9,
267,
291,
14,
629,
1332,
709,
12,
1749,
395,
282,
14,
1392,
9,
339,
347,
511,
63,
466,
63,
475,
63,
4714,
8,
277,
304,
267,
298,
893,
1006,
13867,
75,
7148,
2943,
370,
3957,
370,
20602,
1625,
2455,
2,
398,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
13304,
24,
12,
980,
14,
1635,
24,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
13304,
975,
12,
980,
14,
1635,
975,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
13304,
708,
12,
980,
14,
1635,
708,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
13304,
772,
12,
980,
14,
1635,
772,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3241,
24,
12,
980,
14,
442,
24,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3241,
975,
12,
980,
14,
442,
975,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3241,
708,
12,
980,
14,
442,
708,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3241,
772,
12,
980,
14,
442,
772,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
5136,
708,
12,
980,
14,
1609,
708,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
5136,
772,
12,
980,
14,
1609,
772,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
13304,
24,
12,
980,
14,
1635,
24,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
3241,
24,
12,
980,
14,
442,
24,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
13304,
975,
12,
980,
14,
1635,
975,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
3241,
975,
12,
980,
14,
442,
975,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
13304,
708,
12,
980,
14,
1635,
708,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
3241,
708,
12,
980,
14,
442,
708,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
13304,
772,
12,
980,
14,
1635,
772,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
3241,
772,
12,
980,
14,
442,
772,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,
2221,
75,
14,
2221,
75,
3646,
5136,
708,
12,
980,
14,
1609,
708,
9,
267,
291,
423,
3676,
63,
1074,
63,
2221,
75,
63,
475,
63,
4714,
63,
466,
8,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