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
|
|---|---|---|---|---|---|---|---|---|
a-buck/airmozilla
|
mysql2postgres/py-mysql2pgsql-0.1.5/mysql2pgsql/mysql2pgsql.py
|
17
|
1196
|
from __future__ import absolute_import
import codecs
from .lib import print_red
from .lib.mysql_reader import MysqlReader
from .lib.postgres_file_writer import PostgresFileWriter
from .lib.postgres_db_writer import PostgresDbWriter
from .lib.converter import Converter
from .lib.config import Config
from .lib.errors import ConfigurationFileInitialized
class Mysql2Pgsql(object):
def __init__(self, options):
self.run_options = options
try:
self.file_options = Config(options.file, True).options
except ConfigurationFileInitialized, e:
print_red(e.message)
raise e
def convert(self):
reader = MysqlReader(self.file_options['mysql'])
if self.file_options['destination']['file']:
writer = PostgresFileWriter(self._get_file(self.file_options['destination']['file']), self.run_options.verbose)
else:
writer = PostgresDbWriter(self.file_options['destination']['postgres'], self.run_options.verbose)
Converter(reader, writer, self.file_options, self.run_options.verbose).convert()
def _get_file(self, file_path):
return codecs.open(file_path, 'wb', 'utf-8')
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
6010,
199,
199,
504,
1275,
773,
492,
870,
63,
581,
199,
504,
1275,
773,
14,
8644,
63,
5503,
492,
603,
6398,
5929,
199,
504,
1275,
773,
14,
10675,
63,
493,
63,
5491,
492,
7711,
7266,
28199,
199,
504,
1275,
773,
14,
10675,
63,
697,
63,
5491,
492,
7711,
7266,
8882,
6261,
199,
504,
1275,
773,
14,
11256,
492,
11801,
351,
199,
504,
1275,
773,
14,
888,
492,
4094,
199,
504,
1275,
773,
14,
2550,
492,
11595,
1173,
23031,
421,
199,
533,
603,
6398,
18,
48,
458,
1710,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1511,
304,
267,
291,
14,
1065,
63,
1419,
275,
1511,
267,
862,
26,
288,
291,
14,
493,
63,
1419,
275,
4094,
8,
1419,
14,
493,
12,
715,
680,
1419,
267,
871,
11595,
1173,
23031,
12,
325,
26,
288,
870,
63,
581,
8,
69,
14,
1188,
9,
288,
746,
325,
339,
347,
3957,
8,
277,
304,
267,
7002,
275,
603,
6398,
5929,
8,
277,
14,
493,
63,
1419,
459,
8644,
1105,
398,
340,
291,
14,
493,
63,
1419,
459,
6881,
2545,
493,
2565,
288,
7060,
275,
7711,
7266,
28199,
8,
277,
423,
362,
63,
493,
8,
277,
14,
493,
63,
1419,
459,
6881,
2545,
493,
3815,
291,
14,
1065,
63,
1419,
14,
3832,
9,
267,
587,
26,
288,
7060,
275,
7711,
7266,
8882,
6261,
8,
277,
14,
493,
63,
1419,
459,
6881,
2545,
10675,
995,
291,
14,
1065,
63,
1419,
14,
3832,
9,
398,
11801,
351,
8,
5503,
12,
7060,
12,
291,
14,
493,
63,
1419,
12,
291,
14,
1065,
63,
1419,
14,
3832,
680,
3916,
342,
339,
347,
485,
362,
63,
493,
8,
277,
12,
570,
63,
515,
304,
267,
372,
6010,
14,
1490,
8,
493,
63,
515,
12,
283,
6603,
297,
283,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
6010,
199,
199,
504,
1275,
773,
492,
870,
63,
581,
199,
504,
1275,
773,
14,
8644,
63,
5503,
492,
603,
6398,
5929,
199,
504,
1275,
773,
14,
10675,
63,
493,
63,
5491,
492,
7711,
7266,
28199,
199,
504,
1275,
773,
14,
10675,
63,
697,
63,
5491,
492,
7711,
7266,
8882,
6261,
199,
504,
1275,
773,
14,
11256,
492,
11801,
351,
199,
504,
1275,
773,
14,
888,
492,
4094,
199,
504,
1275,
773,
14,
2550,
492,
11595,
1173,
23031,
421,
199,
533,
603,
6398,
18,
48,
458,
1710,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1511,
304,
267,
291,
14,
1065,
63,
1419,
275,
1511,
267,
862,
26,
288,
291,
14,
493,
63,
1419,
275,
4094,
8,
1419,
14,
493,
12,
715,
680,
1419,
267,
871,
11595,
1173,
23031,
12,
325,
26,
288,
870,
63,
581,
8,
69,
14,
1188,
9,
288,
746,
325,
339,
347,
3957,
8,
277,
304,
267,
7002,
275,
603,
6398,
5929,
8,
277,
14,
493,
63,
1419,
459,
8644,
1105,
398,
340,
291,
14,
493,
63,
1419,
459,
6881,
2545,
493,
2565,
288,
7060,
275,
7711,
7266,
28199,
8,
277,
423,
362,
63,
493,
8,
277,
14,
493,
63,
1419,
459,
6881,
2545,
493,
3815,
291,
14,
1065,
63,
1419,
14,
3832,
9,
267,
587,
26,
288,
7060,
275,
7711,
7266,
8882,
6261,
8,
277,
14,
493,
63,
1419,
459,
6881,
2545,
10675,
995,
291,
14,
1065,
63,
1419,
14,
3832,
9,
398,
11801,
351,
8,
5503,
12,
7060,
12,
291,
14,
493,
63,
1419,
12,
291,
14,
1065,
63,
1419,
14,
3832,
680,
3916,
342,
339,
347,
485,
362,
63,
493,
8,
277,
12,
570,
63,
515,
304,
267,
372,
6010,
14,
1490,
8,
493,
63,
515,
12,
283,
6603,
297,
283,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
no-net/gr-winelo
|
python/qa_winelo_mpc_channel_cc.py
|
1
|
2465
|
#!/usr/bin/env python
#
# Copyright 2012 <+YOU OR YOUR COMPANY+>.
#
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
#
from gnuradio import gr, gr_unittest
import winelo_swig
class qa_mpc_channel_cc(gr_unittest.TestCase):
def setUp(self):
self.tb = gr.top_block()
def tearDown(self):
self.tb = None
def test_001(self):
src_data = (1, 2, 3, 4, 5)
src_gauss_ch1 = (2, 2, 1, 1, 2)
expected_result = (2, 4, 3, 4, 10)
src0 = gr.vector_source_c(src_data)
src1 = gr.vector_source_c(src_gauss_ch1)
mpc_channel = winelo_swig.mpc_channel_cc((0,), (1,))
sink = gr.vector_sink_c()
# set up fg
self.tb.connect(src0, (mpc_channel, 0))
self.tb.connect(src1, (mpc_channel, 1))
self.tb.connect(mpc_channel, sink)
self.tb.run()
# check data
result_data = sink.data()
self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6)
def test_002(self):
src_data = (1, 0, 0, 0, 0)
src_gauss_ch1 = (1, 1, 1, 1, 1)
src_gauss_ch2 = (1, 1, 1, 1, 1)
expected_result = (1, 0, 0, 0.707106781, 0)
src0 = gr.vector_source_c(src_data)
src1 = gr.vector_source_c(src_gauss_ch1)
src2 = gr.vector_source_c(src_gauss_ch2)
mpc_channel = winelo_swig.mpc_channel_cc((0, 3), (1, 0.5))
sink = gr.vector_sink_c()
# set up fg
self.tb.connect(src0, (mpc_channel, 0))
self.tb.connect(src1, (mpc_channel, 1))
self.tb.connect(src2, (mpc_channel, 2))
self.tb.connect(mpc_channel, sink)
self.tb.run()
# check data
result_data = sink.data()
self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6)
if __name__ == '__main__':
gr_unittest.main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
6029,
665,
11,
57,
22050,
1549,
1488,
11237,
16503,
8974,
11,
10827,
199,
3,
199,
3,
961,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2032,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2032,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
3,
199,
199,
504,
24526,
492,
7192,
12,
7192,
63,
2796,
199,
646,
336,
1132,
320,
63,
9676,
421,
199,
533,
31879,
63,
311,
67,
63,
2775,
63,
2055,
8,
2587,
63,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
5842,
275,
7192,
14,
2119,
63,
1457,
342,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
5842,
275,
488,
339,
347,
511,
63,
4587,
8,
277,
304,
267,
2928,
63,
576,
275,
334,
17,
12,
499,
12,
650,
12,
841,
12,
959,
9,
267,
2928,
63,
25898,
63,
335,
17,
275,
334,
18,
12,
499,
12,
413,
12,
413,
12,
499,
9,
267,
1420,
63,
1099,
275,
334,
18,
12,
841,
12,
650,
12,
841,
12,
1616,
9,
267,
2928,
16,
275,
7192,
14,
4106,
63,
1365,
63,
67,
8,
2164,
63,
576,
9,
267,
2928,
17,
275,
7192,
14,
4106,
63,
1365,
63,
67,
8,
2164,
63,
25898,
63,
335,
17,
9,
267,
6118,
67,
63,
2775,
275,
336,
1132,
320,
63,
9676,
14,
311,
67,
63,
2775,
63,
2055,
1332,
16,
4706,
334,
17,
4641,
267,
19241,
275,
7192,
14,
4106,
63,
11279,
63,
67,
342,
267,
327,
663,
1536,
16587,
267,
291,
14,
5842,
14,
2242,
8,
2164,
16,
12,
334,
311,
67,
63,
2775,
12,
378,
430,
267,
291,
14,
5842,
14,
2242,
8,
2164,
17,
12,
334,
311,
67,
63,
2775,
12,
413,
430,
267,
291,
14,
5842,
14,
2242,
8,
311,
67,
63,
2775,
12,
19241,
9,
267,
291,
14,
5842,
14,
1065,
342,
267,
327,
1104,
666,
267,
754,
63,
576,
275,
19241,
14,
576,
342,
267,
291,
14,
479,
5136,
7075,
83,
7331,
8,
2062,
63,
1099,
12,
754,
63,
576,
12,
1227,
9,
339,
347,
511,
63,
7432,
8,
277,
304,
267,
2928,
63,
576,
275,
334,
17,
12,
378,
12,
378,
12,
378,
12,
378,
9,
267,
2928,
63,
25898,
63,
335,
17,
275,
334,
17,
12,
413,
12,
413,
12,
413,
12,
413,
9,
267,
2928,
63,
25898,
63,
335,
18,
275,
334,
17,
12,
413,
12,
413,
12,
413,
12,
413,
9,
267,
1420,
63,
1099,
275,
334,
17,
12,
378,
12,
378,
12,
378,
14,
15378,
709,
1822,
2835,
12,
378,
9,
267,
2928,
16,
275,
7192,
14,
4106,
63,
1365,
63,
67,
8,
2164,
63,
576,
9,
267,
2928,
17,
275,
7192,
14,
4106,
63,
1365,
63,
67,
8,
2164,
63,
25898,
63,
335,
17,
9,
267,
2928,
18,
275,
7192,
14,
4106,
63,
1365,
63,
67,
8,
2164,
63,
25898,
63,
335,
18,
9,
267,
6118,
67,
63,
2775,
275,
336,
1132,
320,
63,
9676,
14,
311,
67,
63,
2775,
63,
2055,
1332,
16,
12,
650,
395,
334,
17,
12,
378,
14,
21,
430,
267,
19241,
275,
7192,
14,
4106,
63,
11279,
63,
67,
342,
267,
327,
663,
1536,
16587,
267,
291,
14,
5842,
14,
2242,
8,
2164,
16,
12,
334,
311,
67,
63,
2775,
12,
378,
430,
267,
291,
14,
5842,
14,
2242,
8,
2164,
17,
12,
334,
311,
67,
63,
2775,
12,
413,
430,
267,
291,
14,
5842,
14,
2242,
8,
2164,
18,
12,
334,
311,
67,
63,
2775,
12,
499,
430,
267,
291,
14,
5842,
14,
2242,
8,
311,
67,
63,
2775,
12,
19241,
9,
267,
291,
14,
5842,
14,
1065,
342,
267,
327,
1104,
666,
267,
754,
63,
576,
275,
19241,
14,
576,
342,
267,
291,
14,
479,
5136,
7075,
83,
7331,
8,
2062,
63,
1099,
12,
754,
63,
576,
12,
1227,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
7192,
63,
2796,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
6029,
665,
11,
57,
22050,
1549,
1488,
11237,
16503,
8974,
11,
10827,
199,
3,
199,
3,
961,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2032,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2032,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
3,
199,
199,
504,
24526,
492,
7192,
12,
7192,
63,
2796,
199,
646,
336,
1132,
320,
63,
9676,
421,
199,
533,
31879,
63,
311,
67,
63,
2775,
63,
2055,
8,
2587,
63,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
5842,
275,
7192,
14,
2119,
63,
1457,
342,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
5842,
275,
488,
339,
347,
511,
63,
4587,
8,
277,
304,
267,
2928,
63,
576,
275,
334,
17,
12,
499,
12,
650,
12,
841,
12,
959,
9,
267,
2928,
63,
25898,
63,
335,
17,
275,
334,
18,
12,
499,
12,
413,
12,
413,
12,
499,
9,
267,
1420,
63,
1099,
275,
334,
18,
12,
841,
12,
650,
12,
841,
12,
1616,
9,
267,
2928,
16,
275,
7192,
14,
4106,
63,
1365,
63,
67,
8,
2164,
63,
576,
9,
267,
2928,
17,
275,
7192,
14,
4106,
63,
1365,
63,
67,
8,
2164,
63,
25898,
63,
335,
17,
9,
267,
6118,
67,
63,
2775,
275,
336,
1132,
320,
63,
9676,
14,
311,
67,
63,
2775,
63,
2055,
1332,
16,
4706,
334,
17,
4641,
267,
19241,
275,
7192,
14,
4106,
63,
11279,
63,
67,
342,
267,
327,
663,
1536,
16587,
267,
291,
14,
5842,
14,
2242,
8,
2164,
16,
12,
334,
311,
67,
63,
2775,
12,
378,
430,
267,
291,
14,
5842,
14,
2242,
8,
2164,
17,
12,
334,
311,
67,
63,
2775,
12,
413,
430,
267,
291,
14,
5842,
14,
2242,
8,
311,
67,
63,
2775,
12,
19241,
9,
267,
291,
14,
5842,
14,
1065,
342,
267,
327,
1104,
666,
267,
754,
63,
576,
275,
19241,
14,
576,
342,
267,
291,
14,
479,
5136,
7075,
83,
7331,
8,
2062,
63,
1099,
12,
754,
63,
576,
12,
1227,
9,
339,
347,
511,
63,
7432,
8,
277,
304,
267,
2928,
63,
576,
275,
334,
17,
12,
378,
12,
378,
12,
378,
12,
378,
9,
267,
2928,
63,
25898,
63,
335,
17,
275,
334,
17,
12,
413,
12,
413,
12,
413,
12,
413,
9,
267,
2928,
63,
25898,
63,
335,
18,
275,
334,
17,
12,
413,
12,
413,
12,
413,
12,
413,
9,
267,
1420,
63,
1099,
275,
334,
17,
12,
378,
12,
378,
12,
378,
14,
15378,
709,
1822,
2835,
12,
378,
9,
267,
2928,
16,
275,
7192,
14,
4106,
63,
1365,
63,
67,
8,
2164,
63,
576,
9,
267,
2928,
17,
275,
7192,
14,
4106,
63,
1365,
63,
67,
8,
2164,
63,
25898,
63,
335,
17,
9,
267,
2928,
18,
275,
7192,
14,
4106,
63,
1365,
63,
67,
8,
2164,
63,
25898,
63,
335,
18,
9,
267,
6118,
67,
63,
2775,
275,
336,
1132,
320,
63,
9676,
14,
311,
67,
63,
2775,
63,
2055,
1332,
16,
12,
650,
395,
334,
17,
12,
378,
14,
21,
430,
267,
19241,
275,
7192,
14,
4106,
63,
11279,
63,
67,
342,
267,
327,
663,
1536,
16587,
267,
291,
14,
5842,
14,
2242,
8,
2164,
16,
12,
334,
311,
67,
63,
2775,
12,
378,
430,
267,
291,
14,
5842,
14,
2242,
8,
2164,
17,
12,
334,
311,
67,
63,
2775,
12,
413,
430,
267,
291,
14,
5842,
14,
2242,
8,
2164,
18,
12,
334,
311,
67,
63,
2775,
12,
499,
430,
267,
291,
14,
5842,
14,
2242,
8,
311,
67,
63,
2775,
12,
19241,
9,
267,
291,
14,
5842,
14,
1065,
342,
267,
327,
1104,
666,
267,
754,
63,
576,
275,
19241,
14,
576,
342,
267,
291,
14,
479,
5136,
7075,
83,
7331,
8,
2062,
63,
1099,
12,
754,
63,
576,
12,
1227,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
7192,
63,
2796,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
iamjake648/jasper-dictionary
|
Define.py
|
1
|
1593
|
#Written by Jake Schultz
#TODO Add more lang support, limit number of results returned
import re
from urllib2 import Request, urlopen, URLError
import json
WORDS = ["DEFINE","WHAT DOES %S MEAN","DEFINITION", "WHAT IS [A|AN]? %S"]
PRIORITY = 1
def handle(text, mic, profile, recursive=False):
text = re.sub(r"(?i)(define|(what is the\s)?definition of|what does|mean|what is (a|an)?)\b","", text ).strip()
if len(text) != 0:
#Yandex Dictionary API Key
dict_key = profile['keys']['YANDEX_DICT']
#method to get the def
get_def(text,mic,dict_key)
elif not recursive:
mic.say("What word would you like to define?")
handle(mic.activeListen(), mic, profile, True)
def get_def(text,mic,key):
#make a call to the API
request = Request('https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key='+key+'&lang=en-en&text='+text)
try:
response = urlopen(request)
data = json.load(response)
if len(data["def"]) == 0:
mic.say("I could not find a definition for " + str(text))
else:
#get the word type (noun, verb, ect)
word_type = data["def"][0]["pos"]
mic.say("The word is a " + word_type)
defs = data["def"][0]["tr"]
#loop through the definitions
for text in defs:
mic.say(text["text"])
except URLError, e:
mic.say("Unable to reach dictionary API.")
def isValid(text):
return bool(re.search(r'\Define|what does\s(.*?)\smean|Definition|what is\s\w+\b',text, re.IGNORECASE))
|
gpl-2.0
|
[
3,
32329,
701,
1603,
1728,
22985,
427,
90,
199,
3,
11768,
2654,
1655,
6339,
2291,
12,
2304,
1329,
402,
2058,
2138,
199,
646,
295,
199,
504,
4011,
18,
492,
4784,
12,
18279,
12,
30794,
199,
646,
2022,
199,
199,
19984,
275,
2097,
14603,
2266,
9792,
619,
3506,
654,
450,
51,
603,
37,
879,
2266,
5638,
8727,
1075,
401,
298,
9792,
619,
2281,
359,
33,
92,
879,
11843,
450,
51,
937,
199,
199,
25144,
275,
413,
421,
199,
318,
2429,
8,
505,
12,
333,
530,
12,
4690,
12,
9133,
29,
797,
304,
272,
1318,
275,
295,
14,
954,
8,
82,
24726,
73,
5130,
4640,
92,
8,
10058,
365,
314,
60,
83,
5547,
7463,
402,
92,
10058,
1630,
92,
3670,
92,
10058,
365,
334,
65,
92,
290,
5547,
2862,
66,
401,
5151,
1318,
7092,
1913,
342,
272,
340,
822,
8,
505,
9,
1137,
378,
26,
267,
327,
26797,
731,
11932,
3261,
2606,
267,
1211,
63,
498,
275,
4690,
459,
1612,
2545,
57,
879,
7746,
63,
12511,
418,
267,
327,
765,
370,
664,
314,
347,
267,
664,
63,
318,
8,
505,
12,
15003,
12,
807,
63,
498,
9,
272,
916,
440,
9133,
26,
267,
333,
530,
14,
19787,
480,
21015,
4349,
3955,
1265,
2839,
370,
5627,
18582,
267,
2429,
8,
15003,
14,
2682,
8687,
1062,
333,
530,
12,
4690,
12,
715,
9,
421,
199,
318,
664,
63,
318,
8,
505,
12,
15003,
12,
498,
304,
272,
327,
1875,
282,
1240,
370,
314,
3261,
272,
1056,
275,
4784,
360,
2859,
921,
9086,
14,
89,
290,
731,
14,
846,
15,
1246,
15,
86,
17,
15,
5000,
1364,
14,
1001,
15,
3892,
31,
498,
22078,
498,
4786,
6,
4159,
29,
287,
13,
287,
6,
505,
22078,
505,
9,
272,
862,
26,
267,
1177,
275,
18279,
8,
1069,
9,
267,
666,
275,
2022,
14,
912,
8,
1310,
9,
267,
340,
822,
8,
576,
905,
318,
3135,
508,
378,
26,
288,
333,
530,
14,
19787,
480,
41,
4293,
440,
2342,
282,
5492,
367,
298,
435,
620,
8,
505,
430,
267,
587,
26,
288,
327,
362,
314,
4349,
730,
334,
889,
324,
12,
16041,
12,
325,
319,
9,
288,
4349,
63,
466,
275,
666,
905,
318,
9210,
16,
7541,
1712,
937,
288,
333,
530,
14,
19787,
480,
1918,
4349,
365,
282,
298,
435,
4349,
63,
466,
9,
288,
22603,
275,
666,
905,
318,
9210,
16,
7541,
454,
937,
288,
327,
3813,
4012,
314,
10269,
288,
367,
1318,
315,
22603,
26,
355,
333,
530,
14,
19787,
8,
505,
905,
505,
3135,
272,
871,
30794,
12,
325,
26,
267,
333,
530,
14,
19787,
480,
6005,
370,
12276,
2600,
3261,
2685,
421,
199,
318,
365,
3490,
8,
505,
304,
272,
372,
2155,
8,
264,
14,
1733,
8,
82,
1154,
16213,
92,
10058,
1630,
60,
83,
17140,
2862,
83,
3670,
92,
10701,
92,
10058,
365,
60,
83,
60,
87,
7896,
66,
297,
505,
12,
295,
14,
15434,
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
] |
[
32329,
701,
1603,
1728,
22985,
427,
90,
199,
3,
11768,
2654,
1655,
6339,
2291,
12,
2304,
1329,
402,
2058,
2138,
199,
646,
295,
199,
504,
4011,
18,
492,
4784,
12,
18279,
12,
30794,
199,
646,
2022,
199,
199,
19984,
275,
2097,
14603,
2266,
9792,
619,
3506,
654,
450,
51,
603,
37,
879,
2266,
5638,
8727,
1075,
401,
298,
9792,
619,
2281,
359,
33,
92,
879,
11843,
450,
51,
937,
199,
199,
25144,
275,
413,
421,
199,
318,
2429,
8,
505,
12,
333,
530,
12,
4690,
12,
9133,
29,
797,
304,
272,
1318,
275,
295,
14,
954,
8,
82,
24726,
73,
5130,
4640,
92,
8,
10058,
365,
314,
60,
83,
5547,
7463,
402,
92,
10058,
1630,
92,
3670,
92,
10058,
365,
334,
65,
92,
290,
5547,
2862,
66,
401,
5151,
1318,
7092,
1913,
342,
272,
340,
822,
8,
505,
9,
1137,
378,
26,
267,
327,
26797,
731,
11932,
3261,
2606,
267,
1211,
63,
498,
275,
4690,
459,
1612,
2545,
57,
879,
7746,
63,
12511,
418,
267,
327,
765,
370,
664,
314,
347,
267,
664,
63,
318,
8,
505,
12,
15003,
12,
807,
63,
498,
9,
272,
916,
440,
9133,
26,
267,
333,
530,
14,
19787,
480,
21015,
4349,
3955,
1265,
2839,
370,
5627,
18582,
267,
2429,
8,
15003,
14,
2682,
8687,
1062,
333,
530,
12,
4690,
12,
715,
9,
421,
199,
318,
664,
63,
318,
8,
505,
12,
15003,
12,
498,
304,
272,
327,
1875,
282,
1240,
370,
314,
3261,
272,
1056,
275,
4784,
360,
2859,
921,
9086,
14,
89,
290,
731,
14,
846,
15,
1246,
15,
86,
17,
15,
5000,
1364,
14,
1001,
15,
3892,
31,
498,
22078,
498,
4786,
6,
4159,
29,
287,
13,
287,
6,
505,
22078,
505,
9,
272,
862,
26,
267,
1177,
275,
18279,
8,
1069,
9,
267,
666,
275,
2022,
14,
912,
8,
1310,
9,
267,
340,
822,
8,
576,
905,
318,
3135,
508,
378,
26,
288,
333,
530,
14,
19787,
480,
41,
4293,
440,
2342,
282,
5492,
367,
298,
435,
620,
8,
505,
430,
267,
587,
26,
288,
327,
362,
314,
4349,
730,
334,
889,
324,
12,
16041,
12,
325,
319,
9,
288,
4349,
63,
466,
275,
666,
905,
318,
9210,
16,
7541,
1712,
937,
288,
333,
530,
14,
19787,
480,
1918,
4349,
365,
282,
298,
435,
4349,
63,
466,
9,
288,
22603,
275,
666,
905,
318,
9210,
16,
7541,
454,
937,
288,
327,
3813,
4012,
314,
10269,
288,
367,
1318,
315,
22603,
26,
355,
333,
530,
14,
19787,
8,
505,
905,
505,
3135,
272,
871,
30794,
12,
325,
26,
267,
333,
530,
14,
19787,
480,
6005,
370,
12276,
2600,
3261,
2685,
421,
199,
318,
365,
3490,
8,
505,
304,
272,
372,
2155,
8,
264,
14,
1733,
8,
82,
1154,
16213,
92,
10058,
1630,
60,
83,
17140,
2862,
83,
3670,
92,
10701,
92,
10058,
365,
60,
83,
60,
87,
7896,
66,
297,
505,
12,
295,
14,
15434,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Peddle/hue
|
desktop/core/ext-py/pysaml2-2.4.0/src/saml2/soap.py
|
32
|
8590
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
"""
Suppport for the client part of the SAML2.0 SOAP binding.
"""
import logging
from saml2 import create_class_from_element_tree
from saml2.samlp import NAMESPACE as SAMLP_NAMESPACE
from saml2.schema import soapenv
try:
from xml.etree import cElementTree as ElementTree
except ImportError:
try:
import cElementTree as ElementTree
except ImportError:
#noinspection PyUnresolvedReferences
from elementtree import ElementTree
logger = logging.getLogger(__name__)
class XmlParseError(Exception):
pass
class WrongMessageType(Exception):
pass
def parse_soap_enveloped_saml_response(text):
tags = ['{%s}Response' % SAMLP_NAMESPACE,
'{%s}LogoutResponse' % SAMLP_NAMESPACE]
return parse_soap_enveloped_saml_thingy(text, tags)
def parse_soap_enveloped_saml_logout_response(text):
tags = ['{%s}Response' % SAMLP_NAMESPACE,
'{%s}LogoutResponse' % SAMLP_NAMESPACE]
return parse_soap_enveloped_saml_thingy(text, tags)
def parse_soap_enveloped_saml_attribute_query(text):
expected_tag = '{%s}AttributeQuery' % SAMLP_NAMESPACE
return parse_soap_enveloped_saml_thingy(text, [expected_tag])
def parse_soap_enveloped_saml_attribute_response(text):
tags = ['{%s}Response' % SAMLP_NAMESPACE,
'{%s}AttributeResponse' % SAMLP_NAMESPACE]
return parse_soap_enveloped_saml_thingy(text, tags)
def parse_soap_enveloped_saml_logout_request(text):
expected_tag = '{%s}LogoutRequest' % SAMLP_NAMESPACE
return parse_soap_enveloped_saml_thingy(text, [expected_tag])
def parse_soap_enveloped_saml_authn_request(text):
expected_tag = '{%s}AuthnRequest' % SAMLP_NAMESPACE
return parse_soap_enveloped_saml_thingy(text, [expected_tag])
def parse_soap_enveloped_saml_artifact_resolve(text):
expected_tag = '{%s}ArtifactResolve' % SAMLP_NAMESPACE
return parse_soap_enveloped_saml_thingy(text, [expected_tag])
def parse_soap_enveloped_saml_artifact_response(text):
expected_tag = '{%s}ArtifactResponse' % SAMLP_NAMESPACE
return parse_soap_enveloped_saml_thingy(text, [expected_tag])
def parse_soap_enveloped_saml_name_id_mapping_request(text):
expected_tag = '{%s}NameIDMappingRequest' % SAMLP_NAMESPACE
return parse_soap_enveloped_saml_thingy(text, [expected_tag])
def parse_soap_enveloped_saml_name_id_mapping_response(text):
expected_tag = '{%s}NameIDMappingResponse' % SAMLP_NAMESPACE
return parse_soap_enveloped_saml_thingy(text, [expected_tag])
def parse_soap_enveloped_saml_manage_name_id_request(text):
expected_tag = '{%s}ManageNameIDRequest' % SAMLP_NAMESPACE
return parse_soap_enveloped_saml_thingy(text, [expected_tag])
def parse_soap_enveloped_saml_manage_name_id_response(text):
expected_tag = '{%s}ManageNameIDResponse' % SAMLP_NAMESPACE
return parse_soap_enveloped_saml_thingy(text, [expected_tag])
def parse_soap_enveloped_saml_assertion_id_request(text):
expected_tag = '{%s}AssertionIDRequest' % SAMLP_NAMESPACE
return parse_soap_enveloped_saml_thingy(text, [expected_tag])
def parse_soap_enveloped_saml_assertion_id_response(text):
tags = ['{%s}Response' % SAMLP_NAMESPACE,
'{%s}AssertionIDResponse' % SAMLP_NAMESPACE]
return parse_soap_enveloped_saml_thingy(text, tags)
def parse_soap_enveloped_saml_authn_query(text):
expected_tag = '{%s}AuthnQuery' % SAMLP_NAMESPACE
return parse_soap_enveloped_saml_thingy(text, [expected_tag])
def parse_soap_enveloped_saml_authn_query_response(text):
tags = ['{%s}Response' % SAMLP_NAMESPACE]
return parse_soap_enveloped_saml_thingy(text, tags)
def parse_soap_enveloped_saml_authn_response(text):
tags = ['{%s}Response' % SAMLP_NAMESPACE]
return parse_soap_enveloped_saml_thingy(text, tags)
#def parse_soap_enveloped_saml_logout_response(text):
# expected_tag = '{%s}LogoutResponse' % SAMLP_NAMESPACE
# return parse_soap_enveloped_saml_thingy(text, [expected_tag])
def parse_soap_enveloped_saml_thingy(text, expected_tags):
"""Parses a SOAP enveloped SAML thing and returns the thing as
a string.
:param text: The SOAP object as XML string
:param expected_tags: What the tag of the SAML thingy is expected to be.
:return: SAML thingy as a string
"""
envelope = ElementTree.fromstring(text)
# Make sure it's a SOAP message
assert envelope.tag == '{%s}Envelope' % soapenv.NAMESPACE
assert len(envelope) >= 1
body = None
for part in envelope:
if part.tag == '{%s}Body' % soapenv.NAMESPACE:
assert len(part) == 1
body = part
break
if body is None:
return ""
saml_part = body[0]
if saml_part.tag in expected_tags:
return ElementTree.tostring(saml_part, encoding="UTF-8")
else:
raise WrongMessageType("Was '%s' expected one of %s" % (saml_part.tag,
expected_tags))
import re
NS_AND_TAG = re.compile("\{([^}]+)\}(.*)")
def instanciate_class(item, modules):
m = NS_AND_TAG.match(item.tag)
ns, tag = m.groups()
for module in modules:
if module.NAMESPACE == ns:
try:
target = module.ELEMENT_BY_TAG[tag]
return create_class_from_element_tree(target, item)
except KeyError:
continue
raise Exception("Unknown class: ns='%s', tag='%s'" % (ns, tag))
def class_instances_from_soap_enveloped_saml_thingies(text, modules):
"""Parses a SOAP enveloped header and body SAML thing and returns the
thing as a dictionary class instance.
:param text: The SOAP object as XML
:param modules: modules representing xsd schemas
:return: The body and headers as class instances
"""
try:
envelope = ElementTree.fromstring(text)
except Exception, exc:
raise XmlParseError("%s" % exc)
assert envelope.tag == '{%s}Envelope' % soapenv.NAMESPACE
assert len(envelope) >= 1
env = {"header": [], "body": None}
for part in envelope:
if part.tag == '{%s}Body' % soapenv.NAMESPACE:
assert len(part) == 1
env["body"] = instanciate_class(part[0], modules)
elif part.tag == "{%s}Header" % soapenv.NAMESPACE:
for item in part:
env["header"].append(instanciate_class(item, modules))
return env
def open_soap_envelope(text):
"""
:param text: SOAP message
:return: dictionary with two keys "body"/"header"
"""
try:
envelope = ElementTree.fromstring(text)
except Exception, exc:
raise XmlParseError("%s" % exc)
assert envelope.tag == '{%s}Envelope' % soapenv.NAMESPACE
assert len(envelope) >= 1
content = {"header": [], "body": None}
for part in envelope:
if part.tag == '{%s}Body' % soapenv.NAMESPACE:
assert len(part) == 1
content["body"] = ElementTree.tostring(part[0], encoding="UTF-8")
elif part.tag == "{%s}Header" % soapenv.NAMESPACE:
for item in part:
_str = ElementTree.tostring(item, encoding="UTF-8")
content["header"].append(_str)
return content
def make_soap_enveloped_saml_thingy(thingy, headers=None):
""" Returns a soap envelope containing a SAML request
as a text string.
:param thingy: The SAML thingy
:return: The SOAP envelope as a string
"""
soap_envelope = soapenv.Envelope()
if headers:
_header = soapenv.Header()
_header.add_extension_elements(headers)
soap_envelope.header = _header
soap_envelope.body = soapenv.Body()
soap_envelope.body.add_extension_element(thingy)
return "%s" % soap_envelope
def soap_fault(message=None, actor=None, code=None, detail=None):
""" Create a SOAP Fault message
:param message: Human readable error message
:param actor: Who discovered the error
:param code: Error code
:param detail: More specific error message
:return: A SOAP Fault message as a string
"""
_string = _actor = _code = _detail = None
if message:
_string = soapenv.Fault_faultstring(text=message)
if actor:
_actor = soapenv.Fault_faultactor(text=actor)
if code:
_code = soapenv.Fault_faultcode(text=code)
if detail:
_detail = soapenv.Fault_detail(text=detail)
fault = soapenv.Fault(
faultcode=_code,
faultstring=_string,
faultactor=_actor,
detail=_detail,
)
return "%s" % fault
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
199,
624,
199,
17127,
719,
367,
314,
1890,
1777,
402,
314,
428,
10107,
18,
14,
16,
26805,
11696,
14,
199,
624,
199,
646,
2050,
199,
199,
504,
25607,
18,
492,
1218,
63,
533,
63,
504,
63,
2108,
63,
2350,
199,
504,
25607,
18,
14,
29338,
80,
492,
26149,
9136,
465,
428,
1156,
9257,
63,
13001,
199,
504,
25607,
18,
14,
3629,
492,
880,
439,
1813,
199,
199,
893,
26,
272,
687,
2748,
14,
9464,
492,
286,
15325,
465,
13139,
199,
2590,
3545,
26,
272,
862,
26,
267,
492,
286,
15325,
465,
13139,
272,
871,
3545,
26,
267,
327,
889,
25098,
1611,
1358,
13697,
15242,
267,
687,
1819,
2350,
492,
13139,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
24881,
9123,
8,
1726,
304,
272,
986,
421,
199,
533,
30801,
12091,
8,
1726,
304,
272,
986,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
1310,
8,
505,
304,
272,
3762,
275,
788,
3996,
83,
93,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
12,
288,
12100,
83,
93,
2445,
548,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
61,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
3762,
9,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
11646,
63,
1310,
8,
505,
304,
272,
3762,
275,
788,
3996,
83,
93,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
12,
288,
12100,
83,
93,
2445,
548,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
61,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
3762,
9,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
3215,
63,
1131,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
1646,
3227,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
3215,
63,
1310,
8,
505,
304,
272,
3762,
275,
788,
3996,
83,
93,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
12,
288,
12100,
83,
93,
1646,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
61,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
3762,
9,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
11646,
63,
1069,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
2445,
548,
2017,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
1178,
78,
63,
1069,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
2817,
78,
2017,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
16154,
63,
6983,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
1596,
10048,
27459,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
16154,
63,
1310,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
1596,
10048,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
354,
63,
344,
63,
4745,
63,
1069,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
985,
998,
7674,
2017,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
354,
63,
344,
63,
4745,
63,
1310,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
985,
998,
7674,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
9053,
63,
354,
63,
344,
63,
1069,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
20588,
985,
998,
2017,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
9053,
63,
354,
63,
344,
63,
1310,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
20588,
985,
998,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
18487,
63,
344,
63,
1069,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
26860,
998,
2017,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
18487,
63,
344,
63,
1310,
8,
505,
304,
272,
3762,
275,
788,
3996,
83,
93,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
12,
288,
12100,
83,
93,
26860,
998,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
61,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
3762,
9,
421,
199,
318,
2198,
63,
21818
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
199,
624,
199,
17127,
719,
367,
314,
1890,
1777,
402,
314,
428,
10107,
18,
14,
16,
26805,
11696,
14,
199,
624,
199,
646,
2050,
199,
199,
504,
25607,
18,
492,
1218,
63,
533,
63,
504,
63,
2108,
63,
2350,
199,
504,
25607,
18,
14,
29338,
80,
492,
26149,
9136,
465,
428,
1156,
9257,
63,
13001,
199,
504,
25607,
18,
14,
3629,
492,
880,
439,
1813,
199,
199,
893,
26,
272,
687,
2748,
14,
9464,
492,
286,
15325,
465,
13139,
199,
2590,
3545,
26,
272,
862,
26,
267,
492,
286,
15325,
465,
13139,
272,
871,
3545,
26,
267,
327,
889,
25098,
1611,
1358,
13697,
15242,
267,
687,
1819,
2350,
492,
13139,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
24881,
9123,
8,
1726,
304,
272,
986,
421,
199,
533,
30801,
12091,
8,
1726,
304,
272,
986,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
1310,
8,
505,
304,
272,
3762,
275,
788,
3996,
83,
93,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
12,
288,
12100,
83,
93,
2445,
548,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
61,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
3762,
9,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
11646,
63,
1310,
8,
505,
304,
272,
3762,
275,
788,
3996,
83,
93,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
12,
288,
12100,
83,
93,
2445,
548,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
61,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
3762,
9,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
3215,
63,
1131,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
1646,
3227,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
3215,
63,
1310,
8,
505,
304,
272,
3762,
275,
788,
3996,
83,
93,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
12,
288,
12100,
83,
93,
1646,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
61,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
3762,
9,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
11646,
63,
1069,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
2445,
548,
2017,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
1178,
78,
63,
1069,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
2817,
78,
2017,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
16154,
63,
6983,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
1596,
10048,
27459,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
16154,
63,
1310,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
1596,
10048,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
354,
63,
344,
63,
4745,
63,
1069,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
985,
998,
7674,
2017,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
354,
63,
344,
63,
4745,
63,
1310,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
985,
998,
7674,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
9053,
63,
354,
63,
344,
63,
1069,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
20588,
985,
998,
2017,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
9053,
63,
354,
63,
344,
63,
1310,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
20588,
985,
998,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
18487,
63,
344,
63,
1069,
8,
505,
304,
272,
1420,
63,
1450,
275,
12100,
83,
93,
26860,
998,
2017,
7,
450,
428,
1156,
9257,
63,
13001,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
359,
2062,
63,
1450,
566,
421,
199,
318,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
18487,
63,
344,
63,
1310,
8,
505,
304,
272,
3762,
275,
788,
3996,
83,
93,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
12,
288,
12100,
83,
93,
26860,
998,
2364,
7,
450,
428,
1156,
9257,
63,
13001,
61,
272,
372,
2198,
63,
21818,
63,
287,
27813,
63,
29338,
63,
2127,
89,
8,
505,
12,
3762,
9,
421,
199,
318,
2198,
63,
21818,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
verdurin/bcbio-nextgen
|
bcbio/distributed/resources.py
|
3
|
8077
|
"""Estimate resources required for processing a set of tasks.
Uses annotations provided in multitasks.py for each function to identify utilized
programs, then extracts resource requirements from the input bcbio_system file.
"""
import copy
import math
from bcbio.pipeline import config_utils
from bcbio.log import logger
def _get_resource_programs(progs, algs):
"""Retrieve programs used in analysis based on algorithm configurations.
Handles special cases like aligners and variant callers.
"""
checks = {"gatk-vqsr": config_utils.use_vqsr,
"snpeff": config_utils.use_snpeff,
"bcbio-variation-recall": config_utils.use_bcbio_variation_recall}
parent_child = {"vardict": _parent_prefix("vardict")}
out = set([])
for p in progs:
if p == "aligner":
for alg in algs:
aligner = alg.get("aligner")
if aligner:
out.add(aligner)
elif p == "variantcaller":
for key, fn in parent_child.items():
if fn(algs):
out.add(key)
for alg in algs:
vc = alg.get("variantcaller")
if vc:
if isinstance(vc, (list, tuple)):
for x in vc:
out.add(x)
else:
out.add(vc)
elif p in checks:
if checks[p](algs):
out.add(p)
else:
out.add(p)
return sorted(list(out))
def _parent_prefix(prefix):
"""Identify a parent prefix we should add to resources if present in a caller name.
"""
def run(algs):
for alg in algs:
vcs = alg.get("variantcaller")
if vcs:
if not isinstance(vcs, (list, tuple)):
vcs = [vcs]
return any(vc.startswith(prefix) for vc in vcs)
return run
def _ensure_min_resources(progs, cores, memory, min_memory):
"""Ensure setting match minimum resources required for used programs.
"""
for p in progs:
if p in min_memory:
if not memory or cores * memory < min_memory[p]:
memory = float(min_memory[p]) / cores
return cores, memory
def _str_memory_to_gb(memory):
val = float(memory[:-1])
units = memory[-1]
if units.lower() == "m":
val = val / 1000.0
else:
assert units.lower() == "g", "Unexpected memory units: %s" % memory
return val
def _get_prog_memory(resources, cores_per_job):
"""Get expected memory usage, in Gb per core, for a program from resource specification.
"""
out = None
for jvm_opt in resources.get("jvm_opts", []):
if jvm_opt.startswith("-Xmx"):
out = _str_memory_to_gb(jvm_opt[4:])
memory = resources.get("memory")
if memory:
out = _str_memory_to_gb(memory)
prog_cores = resources.get("cores", 1)
# if a single core with memory is requested for the job
# and we run multiple cores, scale down to avoid overscheduling
if out and prog_cores == 1 and cores_per_job > prog_cores:
out = out / float(cores_per_job)
return out
def _scale_cores_to_memory(cores, mem_per_core, sysinfo, system_memory):
"""Scale multicore usage to avoid excessive memory usage based on system information.
"""
total_mem = "%.2f" % (cores * mem_per_core + system_memory)
if "cores" not in sysinfo:
return cores, total_mem, 1.0
total_mem = min(float(total_mem), float(sysinfo["memory"]) - system_memory)
cores = min(cores, int(sysinfo["cores"]))
mem_cores = int(math.floor(float(total_mem) / mem_per_core)) # cores based on available memory
if mem_cores < 1:
out_cores = 1
elif mem_cores < cores:
out_cores = mem_cores
else:
out_cores = cores
mem_pct = float(out_cores) / float(cores)
return out_cores, total_mem, mem_pct
def _scale_jobs_to_memory(jobs, mem_per_core, sysinfo):
"""When scheduling jobs with single cores, avoid overscheduling due to memory.
"""
if "cores" not in sysinfo:
return jobs, 1.0
sys_mem_per_core = float(sysinfo["memory"]) / float(sysinfo["cores"])
if sys_mem_per_core < mem_per_core:
pct = sys_mem_per_core / float(mem_per_core)
target_jobs = int(math.floor(jobs * pct))
return max(target_jobs, 1), pct
else:
return jobs, 1.0
def calculate(parallel, items, sysinfo, config, multiplier=1,
max_multicore=None):
"""Determine cores and workers to use for this stage based on used programs.
multiplier specifies the number of regions items will be split into during
processing.
max_multicore specifies an optional limit on the maximum cores. Can use to
force single core processing during specific tasks.
sysinfo specifies cores and memory on processing nodes, allowing us to tailor
jobs for available resources.
"""
assert len(items) > 0, "Finding job resources but no items to process"
all_cores = []
all_memory = []
# Provide 100Mb of additional memory for the system
system_memory = 0.10
algs = [config_utils.get_algorithm_config(x) for x in items]
progs = _get_resource_programs(parallel.get("progs", []), algs)
# Calculate cores
for prog in progs:
resources = config_utils.get_resources(prog, config)
all_cores.append(resources.get("cores", 1))
if len(all_cores) == 0:
all_cores.append(1)
cores_per_job = max(all_cores)
if max_multicore:
cores_per_job = min(cores_per_job, max_multicore)
if "cores" in sysinfo:
cores_per_job = min(cores_per_job, int(sysinfo["cores"]))
total = parallel["cores"]
if total > cores_per_job:
num_jobs = total // cores_per_job
else:
num_jobs, cores_per_job = 1, total
# Calculate memory. Use 1Gb memory usage per core as min baseline if not specified
for prog in progs:
resources = config_utils.get_resources(prog, config)
memory = _get_prog_memory(resources, cores_per_job)
if memory:
all_memory.append(memory)
if len(all_memory) == 0:
all_memory.append(1)
memory_per_core = max(all_memory)
logger.debug("Resource requests: {progs}; memory: {memory}; cores: {cores}".format(
progs=", ".join(progs), memory=", ".join("%.2f" % x for x in all_memory),
cores=", ".join(str(x) for x in all_cores)))
cores_per_job, memory_per_core = _ensure_min_resources(progs, cores_per_job, memory_per_core,
min_memory=parallel.get("ensure_mem", {}))
if cores_per_job == 1:
memory_per_job = "%.2f" % memory_per_core
num_jobs, mem_pct = _scale_jobs_to_memory(num_jobs, memory_per_core, sysinfo)
else:
cores_per_job, memory_per_job, mem_pct = _scale_cores_to_memory(cores_per_job,
memory_per_core, sysinfo,
system_memory)
# For local runs with multiple jobs and multiple cores, potentially scale jobs down
if num_jobs > 1 and parallel.get("type") == "local":
memory_per_core = float(memory_per_job) / cores_per_job
num_jobs, _ = _scale_jobs_to_memory(num_jobs, memory_per_core, sysinfo)
# do not overschedule if we don't have extra items to process
num_jobs = min(num_jobs, len(items) * multiplier)
logger.debug("Configuring %d jobs to run, using %d cores each with %sg of "
"memory reserved for each job" % (num_jobs, cores_per_job,
str(memory_per_job)))
parallel = copy.deepcopy(parallel)
parallel["cores_per_job"] = cores_per_job
parallel["num_jobs"] = num_jobs
parallel["mem"] = str(memory_per_job)
parallel["mem_pct"] = "%.2f" % mem_pct
parallel["system_cores"] = sysinfo.get("cores", 1)
return parallel
|
mit
|
[
624,
31020,
5944,
1415,
367,
6661,
282,
663,
402,
6527,
14,
199,
199,
21896,
15538,
2741,
315,
3510,
5054,
14,
647,
367,
1924,
805,
370,
10405,
7678,
317,
7068,
199,
28464,
12,
2066,
5536,
83,
2073,
9760,
687,
314,
1324,
330,
2894,
2308,
63,
2253,
570,
14,
199,
624,
199,
646,
1331,
199,
646,
3473,
199,
199,
504,
330,
2894,
2308,
14,
7379,
492,
1101,
63,
1208,
199,
504,
330,
2894,
2308,
14,
793,
492,
2512,
199,
199,
318,
485,
362,
63,
1927,
63,
28464,
8,
496,
458,
12,
741,
458,
304,
272,
408,
15310,
18572,
1202,
315,
11284,
4079,
641,
5563,
13422,
14,
272,
23873,
4539,
5560,
2839,
6998,
1192,
436,
9854,
24194,
14,
272,
408,
272,
5920,
275,
2420,
71,
292,
75,
13,
86,
81,
5474,
582,
1101,
63,
1208,
14,
1180,
63,
86,
81,
5474,
12,
1598,
298,
5167,
321,
556,
582,
1101,
63,
1208,
14,
1180,
63,
5167,
321,
556,
12,
1598,
298,
66,
2894,
2308,
13,
3808,
425,
13,
19183,
582,
1101,
63,
1208,
14,
1180,
63,
66,
2894,
2308,
63,
3808,
425,
63,
19183,
93,
272,
1676,
63,
1739,
275,
2420,
1391,
807,
582,
485,
1708,
63,
1861,
480,
1391,
807,
531,
93,
272,
734,
275,
663,
4157,
272,
367,
299,
315,
557,
458,
26,
267,
340,
299,
508,
298,
5743,
281,
582,
288,
367,
15760,
315,
741,
458,
26,
355,
6998,
281,
275,
15760,
14,
362,
480,
5743,
281,
531,
355,
340,
6998,
281,
26,
490,
734,
14,
525,
8,
5743,
281,
9,
267,
916,
299,
508,
298,
8759,
11219,
582,
288,
367,
790,
12,
4325,
315,
1676,
63,
1739,
14,
1744,
837,
355,
340,
4325,
8,
31128,
304,
490,
734,
14,
525,
8,
498,
9,
288,
367,
15760,
315,
741,
458,
26,
355,
16548,
275,
15760,
14,
362,
480,
8759,
11219,
531,
355,
340,
16548,
26,
490,
340,
1228,
8,
6737,
12,
334,
513,
12,
2008,
2298,
717,
367,
671,
315,
16548,
26,
1169,
734,
14,
525,
8,
88,
9,
490,
587,
26,
717,
734,
14,
525,
8,
6737,
9,
267,
916,
299,
315,
5920,
26,
288,
340,
5920,
59,
80,
8738,
31128,
304,
355,
734,
14,
525,
8,
80,
9,
267,
587,
26,
288,
734,
14,
525,
8,
80,
9,
272,
372,
3355,
8,
513,
8,
548,
430,
199,
199,
318,
485,
1708,
63,
1861,
8,
1861,
304,
272,
408,
17062,
3338,
282,
1676,
2403,
781,
1077,
1050,
370,
5944,
340,
3451,
315,
282,
8025,
536,
14,
272,
408,
272,
347,
1255,
8,
31128,
304,
267,
367,
15760,
315,
741,
458,
26,
288,
19827,
275,
15760,
14,
362,
480,
8759,
11219,
531,
288,
340,
19827,
26,
355,
340,
440,
1228,
8,
15525,
12,
334,
513,
12,
2008,
2298,
490,
19827,
275,
359,
15525,
61,
355,
372,
1263,
8,
6737,
14,
2460,
8,
1861,
9,
367,
16548,
315,
19827,
9,
272,
372,
1255,
199,
199,
318,
485,
7505,
63,
827,
63,
4435,
8,
496,
458,
12,
23857,
12,
4402,
12,
1748,
63,
4844,
304,
272,
408,
13913,
4260,
1336,
7481,
5944,
1415,
367,
1202,
18572,
14,
272,
408,
272,
367,
299,
315,
557,
458,
26,
267,
340,
299,
315,
1748,
63,
4844,
26,
288,
340,
440,
4402,
503,
23857,
627,
4402,
665,
1748,
63,
4844,
59,
80,
2189,
355,
4402,
275,
2069,
8,
827,
63,
4844,
59,
80,
566,
1182,
23857,
272,
372,
23857,
12,
4402,
199,
199,
318,
485,
495,
63,
4844,
63,
475,
63,
4908,
8,
4844,
304,
272,
1139,
275,
2069,
8,
4844,
4439,
17,
566,
272,
6204,
275,
4402,
1988,
17,
61,
272,
340,
6204,
14,
2325,
342,
508,
298,
77,
582,
267,
1139,
275,
1139,
1182,
5198,
14,
16,
272,
587,
26,
267,
702,
6204,
14,
2325,
342,
508,
298,
71,
401,
298,
8708,
4402,
6204,
26,
450,
83,
2,
450,
4402,
272,
372,
1139,
199,
199,
318,
485,
362,
63,
6595,
63,
4844,
8,
4435,
12,
23857,
63,
529,
63,
2423,
304,
272,
408,
1002,
1420,
4402,
4503,
12,
315,
598,
66,
1126,
6170,
12,
367,
282,
2240,
687,
2073,
8929,
14,
272,
408,
272,
734,
275,
488,
272,
367,
1335,
2611,
63,
2992,
315,
5944,
14,
362,
480,
15813,
63,
3291,
401,
12319,
267,
340,
1335,
2611,
63,
2992,
14,
2460,
6096,
56,
9457,
2349,
288,
734,
275,
485,
495,
63,
4844,
63,
475,
63,
4908,
8,
15813,
63,
2992,
59,
20,
5728,
272,
4402,
275,
5944,
14,
362,
480,
4844,
531,
272,
340,
4402,
26,
267,
734,
275,
485,
495,
63,
4844,
63,
475,
63,
4908,
8,
4844,
9,
272,
13205,
63,
4630,
275,
5944,
14,
362,
480,
4630,
401,
413,
9,
272,
327,
340,
282,
2849,
6170,
543,
4402,
365,
5839,
367,
314,
3906,
272,
327,
436,
781,
1255,
3663,
23857,
12,
4666,
3224,
370,
5126,
1806,
10487,
15633,
272,
340,
734,
436,
13205,
63,
4630,
508,
413,
436,
23857,
63,
529,
63,
2423,
690,
13205,
63,
4630,
26,
267,
734,
275,
734,
1182,
2069,
8,
4630,
63,
529,
63,
2423,
9,
272,
372,
734,
199,
199,
318,
485,
3467,
63,
4630,
63,
475,
63,
4844,
8,
4630,
12,
7573,
63,
529,
63,
1018,
12,
984,
815,
12,
2656,
63,
4844,
304,
272,
408,
9944,
3510,
1018,
4503,
370,
5126,
444,
823,
3398,
4402,
4503,
4079,
641,
2656,
2556,
14,
272,
408,
272,
3141,
63,
5286,
275,
31681,
18,
70,
2,
450,
334,
4630,
627,
7573,
63,
529,
63,
1018,
435,
2656,
63,
4844,
9,
272,
340,
298,
4630,
2,
440,
315,
984,
815,
26,
267,
372,
23857,
12,
3141,
63,
5286,
12,
413,
14,
16,
339,
3141,
63,
5286,
275,
1748,
8,
1609,
8,
2923,
63,
5286,
395,
2069,
8,
1274,
815,
905,
4844,
3135,
446,
2656,
63,
4844,
9,
272,
23857,
275,
1748,
8,
4630,
12,
1109,
8,
1274,
815,
905,
4630,
13045,
272,
7573,
63,
4630,
275,
1109,
8,
3442,
14,
11289,
8,
1609,
8,
2923,
63,
5286,
9,
1182,
7573,
63,
529,
63,
1018,
430,
221,
327,
23857,
4079,
641,
2808,
4402,
272,
340,
7573,
63,
4630,
665,
413,
26,
267,
734,
63,
4630,
275,
413,
272,
916,
7573,
63,
4630,
665,
23857,
26,
267,
734,
63,
4630,
275,
7573,
63,
4630,
272,
587,
26,
267,
734,
63,
4630,
275,
23857,
272,
7573
] |
[
31020,
5944,
1415,
367,
6661,
282,
663,
402,
6527,
14,
199,
199,
21896,
15538,
2741,
315,
3510,
5054,
14,
647,
367,
1924,
805,
370,
10405,
7678,
317,
7068,
199,
28464,
12,
2066,
5536,
83,
2073,
9760,
687,
314,
1324,
330,
2894,
2308,
63,
2253,
570,
14,
199,
624,
199,
646,
1331,
199,
646,
3473,
199,
199,
504,
330,
2894,
2308,
14,
7379,
492,
1101,
63,
1208,
199,
504,
330,
2894,
2308,
14,
793,
492,
2512,
199,
199,
318,
485,
362,
63,
1927,
63,
28464,
8,
496,
458,
12,
741,
458,
304,
272,
408,
15310,
18572,
1202,
315,
11284,
4079,
641,
5563,
13422,
14,
272,
23873,
4539,
5560,
2839,
6998,
1192,
436,
9854,
24194,
14,
272,
408,
272,
5920,
275,
2420,
71,
292,
75,
13,
86,
81,
5474,
582,
1101,
63,
1208,
14,
1180,
63,
86,
81,
5474,
12,
1598,
298,
5167,
321,
556,
582,
1101,
63,
1208,
14,
1180,
63,
5167,
321,
556,
12,
1598,
298,
66,
2894,
2308,
13,
3808,
425,
13,
19183,
582,
1101,
63,
1208,
14,
1180,
63,
66,
2894,
2308,
63,
3808,
425,
63,
19183,
93,
272,
1676,
63,
1739,
275,
2420,
1391,
807,
582,
485,
1708,
63,
1861,
480,
1391,
807,
531,
93,
272,
734,
275,
663,
4157,
272,
367,
299,
315,
557,
458,
26,
267,
340,
299,
508,
298,
5743,
281,
582,
288,
367,
15760,
315,
741,
458,
26,
355,
6998,
281,
275,
15760,
14,
362,
480,
5743,
281,
531,
355,
340,
6998,
281,
26,
490,
734,
14,
525,
8,
5743,
281,
9,
267,
916,
299,
508,
298,
8759,
11219,
582,
288,
367,
790,
12,
4325,
315,
1676,
63,
1739,
14,
1744,
837,
355,
340,
4325,
8,
31128,
304,
490,
734,
14,
525,
8,
498,
9,
288,
367,
15760,
315,
741,
458,
26,
355,
16548,
275,
15760,
14,
362,
480,
8759,
11219,
531,
355,
340,
16548,
26,
490,
340,
1228,
8,
6737,
12,
334,
513,
12,
2008,
2298,
717,
367,
671,
315,
16548,
26,
1169,
734,
14,
525,
8,
88,
9,
490,
587,
26,
717,
734,
14,
525,
8,
6737,
9,
267,
916,
299,
315,
5920,
26,
288,
340,
5920,
59,
80,
8738,
31128,
304,
355,
734,
14,
525,
8,
80,
9,
267,
587,
26,
288,
734,
14,
525,
8,
80,
9,
272,
372,
3355,
8,
513,
8,
548,
430,
199,
199,
318,
485,
1708,
63,
1861,
8,
1861,
304,
272,
408,
17062,
3338,
282,
1676,
2403,
781,
1077,
1050,
370,
5944,
340,
3451,
315,
282,
8025,
536,
14,
272,
408,
272,
347,
1255,
8,
31128,
304,
267,
367,
15760,
315,
741,
458,
26,
288,
19827,
275,
15760,
14,
362,
480,
8759,
11219,
531,
288,
340,
19827,
26,
355,
340,
440,
1228,
8,
15525,
12,
334,
513,
12,
2008,
2298,
490,
19827,
275,
359,
15525,
61,
355,
372,
1263,
8,
6737,
14,
2460,
8,
1861,
9,
367,
16548,
315,
19827,
9,
272,
372,
1255,
199,
199,
318,
485,
7505,
63,
827,
63,
4435,
8,
496,
458,
12,
23857,
12,
4402,
12,
1748,
63,
4844,
304,
272,
408,
13913,
4260,
1336,
7481,
5944,
1415,
367,
1202,
18572,
14,
272,
408,
272,
367,
299,
315,
557,
458,
26,
267,
340,
299,
315,
1748,
63,
4844,
26,
288,
340,
440,
4402,
503,
23857,
627,
4402,
665,
1748,
63,
4844,
59,
80,
2189,
355,
4402,
275,
2069,
8,
827,
63,
4844,
59,
80,
566,
1182,
23857,
272,
372,
23857,
12,
4402,
199,
199,
318,
485,
495,
63,
4844,
63,
475,
63,
4908,
8,
4844,
304,
272,
1139,
275,
2069,
8,
4844,
4439,
17,
566,
272,
6204,
275,
4402,
1988,
17,
61,
272,
340,
6204,
14,
2325,
342,
508,
298,
77,
582,
267,
1139,
275,
1139,
1182,
5198,
14,
16,
272,
587,
26,
267,
702,
6204,
14,
2325,
342,
508,
298,
71,
401,
298,
8708,
4402,
6204,
26,
450,
83,
2,
450,
4402,
272,
372,
1139,
199,
199,
318,
485,
362,
63,
6595,
63,
4844,
8,
4435,
12,
23857,
63,
529,
63,
2423,
304,
272,
408,
1002,
1420,
4402,
4503,
12,
315,
598,
66,
1126,
6170,
12,
367,
282,
2240,
687,
2073,
8929,
14,
272,
408,
272,
734,
275,
488,
272,
367,
1335,
2611,
63,
2992,
315,
5944,
14,
362,
480,
15813,
63,
3291,
401,
12319,
267,
340,
1335,
2611,
63,
2992,
14,
2460,
6096,
56,
9457,
2349,
288,
734,
275,
485,
495,
63,
4844,
63,
475,
63,
4908,
8,
15813,
63,
2992,
59,
20,
5728,
272,
4402,
275,
5944,
14,
362,
480,
4844,
531,
272,
340,
4402,
26,
267,
734,
275,
485,
495,
63,
4844,
63,
475,
63,
4908,
8,
4844,
9,
272,
13205,
63,
4630,
275,
5944,
14,
362,
480,
4630,
401,
413,
9,
272,
327,
340,
282,
2849,
6170,
543,
4402,
365,
5839,
367,
314,
3906,
272,
327,
436,
781,
1255,
3663,
23857,
12,
4666,
3224,
370,
5126,
1806,
10487,
15633,
272,
340,
734,
436,
13205,
63,
4630,
508,
413,
436,
23857,
63,
529,
63,
2423,
690,
13205,
63,
4630,
26,
267,
734,
275,
734,
1182,
2069,
8,
4630,
63,
529,
63,
2423,
9,
272,
372,
734,
199,
199,
318,
485,
3467,
63,
4630,
63,
475,
63,
4844,
8,
4630,
12,
7573,
63,
529,
63,
1018,
12,
984,
815,
12,
2656,
63,
4844,
304,
272,
408,
9944,
3510,
1018,
4503,
370,
5126,
444,
823,
3398,
4402,
4503,
4079,
641,
2656,
2556,
14,
272,
408,
272,
3141,
63,
5286,
275,
31681,
18,
70,
2,
450,
334,
4630,
627,
7573,
63,
529,
63,
1018,
435,
2656,
63,
4844,
9,
272,
340,
298,
4630,
2,
440,
315,
984,
815,
26,
267,
372,
23857,
12,
3141,
63,
5286,
12,
413,
14,
16,
339,
3141,
63,
5286,
275,
1748,
8,
1609,
8,
2923,
63,
5286,
395,
2069,
8,
1274,
815,
905,
4844,
3135,
446,
2656,
63,
4844,
9,
272,
23857,
275,
1748,
8,
4630,
12,
1109,
8,
1274,
815,
905,
4630,
13045,
272,
7573,
63,
4630,
275,
1109,
8,
3442,
14,
11289,
8,
1609,
8,
2923,
63,
5286,
9,
1182,
7573,
63,
529,
63,
1018,
430,
221,
327,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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
] |
giorgiop/scikit-learn
|
sklearn/linear_model/__init__.py
|
83
|
3139
|
"""
The :mod:`sklearn.linear_model` module implements generalized linear models. It
includes Ridge regression, Bayesian Regression, Lasso and Elastic Net
estimators computed with Least Angle Regression and coordinate descent. It also
implements Stochastic Gradient Descent related algorithms.
"""
# See http://scikit-learn.sourceforge.net/modules/sgd.html and
# http://scikit-learn.sourceforge.net/modules/linear_model.html for
# complete documentation.
from .base import LinearRegression
from .bayes import BayesianRidge, ARDRegression
from .least_angle import (Lars, LassoLars, lars_path, LarsCV, LassoLarsCV,
LassoLarsIC)
from .coordinate_descent import (Lasso, ElasticNet, LassoCV, ElasticNetCV,
lasso_path, enet_path, MultiTaskLasso,
MultiTaskElasticNet, MultiTaskElasticNetCV,
MultiTaskLassoCV)
from .huber import HuberRegressor
from .sgd_fast import Hinge, Log, ModifiedHuber, SquaredLoss, Huber
from .stochastic_gradient import SGDClassifier, SGDRegressor
from .ridge import (Ridge, RidgeCV, RidgeClassifier, RidgeClassifierCV,
ridge_regression)
from .logistic import (LogisticRegression, LogisticRegressionCV,
logistic_regression_path)
from .omp import (orthogonal_mp, orthogonal_mp_gram, OrthogonalMatchingPursuit,
OrthogonalMatchingPursuitCV)
from .passive_aggressive import PassiveAggressiveClassifier
from .passive_aggressive import PassiveAggressiveRegressor
from .perceptron import Perceptron
from .randomized_l1 import (RandomizedLasso, RandomizedLogisticRegression,
lasso_stability_path)
from .ransac import RANSACRegressor
from .theil_sen import TheilSenRegressor
__all__ = ['ARDRegression',
'BayesianRidge',
'ElasticNet',
'ElasticNetCV',
'Hinge',
'HuberRegressor',
'Lars',
'LarsCV',
'Lasso',
'LassoCV',
'LassoLars',
'LassoLarsCV',
'LassoLarsIC',
'LinearRegression',
'Log',
'LogisticRegression',
'LogisticRegressionCV',
'ModifiedHuber',
'MultiTaskElasticNet',
'MultiTaskElasticNetCV',
'MultiTaskLasso',
'MultiTaskLassoCV',
'OrthogonalMatchingPursuit',
'OrthogonalMatchingPursuitCV',
'PassiveAggressiveClassifier',
'PassiveAggressiveRegressor',
'Perceptron',
'RandomizedLasso',
'RandomizedLogisticRegression',
'Ridge',
'RidgeCV',
'RidgeClassifier',
'RidgeClassifierCV',
'SGDClassifier',
'SGDRegressor',
'SquaredLoss',
'TheilSenRegressor',
'enet_path',
'lars_path',
'lasso_path',
'lasso_stability_path',
'logistic_regression_path',
'orthogonal_mp',
'orthogonal_mp_gram',
'ridge_regression',
'RANSACRegressor']
|
bsd-3-clause
|
[
624,
199,
1918,
520,
1494,
1705,
27993,
14,
6676,
63,
1238,
64,
859,
9031,
8605,
1759,
7798,
1709,
14,
2779,
199,
9441,
31196,
10864,
12,
29434,
69,
6214,
13262,
12,
29029,
436,
19509,
5365,
199,
10646,
9235,
543,
7005,
1810,
1626,
3845,
13262,
436,
10021,
31518,
14,
2779,
2597,
199,
24900,
9785,
21913,
19603,
8055,
2946,
4048,
18036,
14,
199,
624,
199,
199,
3,
1666,
1455,
921,
551,
3258,
390,
13,
4643,
14,
22943,
14,
846,
15,
3112,
15,
1226,
68,
14,
1360,
436,
199,
3,
1455,
921,
551,
3258,
390,
13,
4643,
14,
22943,
14,
846,
15,
3112,
15,
6676,
63,
1238,
14,
1360,
367,
199,
3,
4890,
3794,
14,
199,
199,
504,
1275,
1095,
492,
12489,
13013,
199,
199,
504,
1275,
19558,
397,
492,
29434,
69,
6214,
50,
22642,
12,
4160,
36,
13013,
199,
504,
1275,
11790,
63,
4593,
492,
334,
44,
4291,
12,
29029,
44,
4291,
12,
634,
4291,
63,
515,
12,
491,
4291,
12847,
12,
29029,
44,
4291,
12847,
12,
2079,
29029,
44,
4291,
948,
9,
199,
504,
1275,
20493,
63,
26269,
492,
334,
27537,
12,
19509,
2480,
12,
29029,
12847,
12,
19509,
2480,
12847,
12,
639,
634,
15923,
63,
515,
12,
655,
386,
63,
515,
12,
6879,
4476,
27537,
12,
639,
6879,
4476,
27822,
2480,
12,
6879,
4476,
27822,
2480,
12847,
12,
639,
6879,
4476,
27537,
12847,
9,
199,
504,
1275,
72,
10400,
492,
869,
10400,
15155,
199,
504,
1275,
1226,
68,
63,
7015,
492,
869,
17081,
12,
5297,
12,
22016,
40,
10400,
12,
428,
30458,
8610,
12,
869,
10400,
199,
504,
1275,
14308,
21913,
63,
7490,
492,
18868,
36,
8508,
12,
18868,
36,
15155,
199,
504,
1275,
5562,
492,
334,
50,
22642,
12,
31196,
12847,
12,
31196,
8508,
12,
31196,
8508,
12847,
12,
490,
31285,
63,
12513,
9,
199,
504,
1275,
23452,
492,
334,
2445,
23032,
12,
27903,
12847,
12,
2432,
30360,
63,
12513,
63,
515,
9,
199,
504,
1275,
22527,
492,
334,
11297,
19133,
63,
311,
12,
29069,
63,
311,
63,
1679,
12,
4236,
273,
19133,
14215,
14959,
83,
4993,
12,
2116,
4236,
273,
19133,
14215,
14959,
83,
4993,
12847,
9,
199,
504,
1275,
25166,
63,
643,
25787,
492,
510,
13202,
7248,
470,
3398,
8508,
199,
504,
1275,
25166,
63,
643,
25787,
492,
510,
13202,
7248,
470,
3398,
15155,
199,
504,
1275,
529,
301,
4695,
265,
492,
3492,
301,
4695,
265,
199,
504,
1275,
2355,
1759,
63,
76,
17,
492,
334,
3883,
1759,
27537,
12,
9571,
1759,
2445,
23032,
12,
1169,
634,
15923,
63,
270,
3616,
63,
515,
9,
199,
504,
1275,
1320,
645,
492,
820,
5622,
1348,
15155,
199,
504,
1275,
1589,
382,
63,
2464,
492,
710,
382,
18569,
15155,
199,
199,
363,
452,
363,
275,
788,
7816,
13013,
297,
1779,
283,
29115,
69,
6214,
50,
22642,
297,
1779,
283,
27822,
2480,
297,
1779,
283,
27822,
2480,
12847,
297,
1779,
283,
40,
17081,
297,
1779,
283,
40,
10400,
15155,
297,
1779,
283,
44,
4291,
297,
1779,
283,
44,
4291,
12847,
297,
1779,
283,
27537,
297,
1779,
283,
27537,
12847,
297,
1779,
283,
27537,
44,
4291,
297,
1779,
283,
27537,
44,
4291,
12847,
297,
1779,
283,
27537,
44,
4291,
948,
297,
1779,
283,
10608,
13013,
297,
1779,
283,
2445,
297,
1779,
283,
2445,
23032,
297,
1779,
283,
2445,
23032,
12847,
297,
1779,
283,
11911,
40,
10400,
297,
1779,
283,
3947,
4476,
27822,
2480,
297,
1779,
283,
3947,
4476,
27822,
2480,
12847,
297,
1779,
283,
3947,
4476,
27537,
297,
1779,
283,
3947,
4476,
27537,
12847,
297,
1779,
283,
2844,
273,
19133,
14215,
14959,
83,
4993,
297,
1779,
283,
2844,
273,
19133,
14215,
14959,
83,
4993,
12847,
297,
1779,
283,
48,
13202,
7248,
470,
3398,
8508,
297,
1779,
283,
48,
13202,
7248,
470,
3398,
15155,
297,
1779,
283,
2623,
301,
4695,
265,
297,
1779,
283,
3883,
1759,
27537,
297,
1779,
283,
3883,
1759,
2445,
23032,
297,
1779,
283,
50,
22642,
297,
1779,
283,
50,
22642,
12847,
297,
1779,
283,
50,
22642,
8508,
297,
1779,
283,
50,
22642,
8508,
12847,
297,
1779,
283,
4254,
36,
8508,
297,
1779,
283,
4254,
36,
15155,
297,
1779,
283,
51,
30458,
8610,
297,
1779,
283,
1918,
382,
18569,
15155,
297,
1779,
283,
287,
386,
63,
515,
297,
1779,
283,
31590,
63,
515,
297,
1779,
283,
18412,
63,
515,
297,
1779,
283,
18412,
63,
270,
3616,
63,
515,
297,
1779,
283,
23452,
63,
12513,
63,
515,
297,
1779,
283,
11297,
19133,
63,
311,
297,
1779,
283,
11297,
19133,
63,
311,
63,
1679,
297,
1779,
283,
5562,
63,
12513,
297,
1779,
283,
50,
5622,
1348,
15155,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
1918,
520,
1494,
1705,
27993,
14,
6676,
63,
1238,
64,
859,
9031,
8605,
1759,
7798,
1709,
14,
2779,
199,
9441,
31196,
10864,
12,
29434,
69,
6214,
13262,
12,
29029,
436,
19509,
5365,
199,
10646,
9235,
543,
7005,
1810,
1626,
3845,
13262,
436,
10021,
31518,
14,
2779,
2597,
199,
24900,
9785,
21913,
19603,
8055,
2946,
4048,
18036,
14,
199,
624,
199,
199,
3,
1666,
1455,
921,
551,
3258,
390,
13,
4643,
14,
22943,
14,
846,
15,
3112,
15,
1226,
68,
14,
1360,
436,
199,
3,
1455,
921,
551,
3258,
390,
13,
4643,
14,
22943,
14,
846,
15,
3112,
15,
6676,
63,
1238,
14,
1360,
367,
199,
3,
4890,
3794,
14,
199,
199,
504,
1275,
1095,
492,
12489,
13013,
199,
199,
504,
1275,
19558,
397,
492,
29434,
69,
6214,
50,
22642,
12,
4160,
36,
13013,
199,
504,
1275,
11790,
63,
4593,
492,
334,
44,
4291,
12,
29029,
44,
4291,
12,
634,
4291,
63,
515,
12,
491,
4291,
12847,
12,
29029,
44,
4291,
12847,
12,
2079,
29029,
44,
4291,
948,
9,
199,
504,
1275,
20493,
63,
26269,
492,
334,
27537,
12,
19509,
2480,
12,
29029,
12847,
12,
19509,
2480,
12847,
12,
639,
634,
15923,
63,
515,
12,
655,
386,
63,
515,
12,
6879,
4476,
27537,
12,
639,
6879,
4476,
27822,
2480,
12,
6879,
4476,
27822,
2480,
12847,
12,
639,
6879,
4476,
27537,
12847,
9,
199,
504,
1275,
72,
10400,
492,
869,
10400,
15155,
199,
504,
1275,
1226,
68,
63,
7015,
492,
869,
17081,
12,
5297,
12,
22016,
40,
10400,
12,
428,
30458,
8610,
12,
869,
10400,
199,
504,
1275,
14308,
21913,
63,
7490,
492,
18868,
36,
8508,
12,
18868,
36,
15155,
199,
504,
1275,
5562,
492,
334,
50,
22642,
12,
31196,
12847,
12,
31196,
8508,
12,
31196,
8508,
12847,
12,
490,
31285,
63,
12513,
9,
199,
504,
1275,
23452,
492,
334,
2445,
23032,
12,
27903,
12847,
12,
2432,
30360,
63,
12513,
63,
515,
9,
199,
504,
1275,
22527,
492,
334,
11297,
19133,
63,
311,
12,
29069,
63,
311,
63,
1679,
12,
4236,
273,
19133,
14215,
14959,
83,
4993,
12,
2116,
4236,
273,
19133,
14215,
14959,
83,
4993,
12847,
9,
199,
504,
1275,
25166,
63,
643,
25787,
492,
510,
13202,
7248,
470,
3398,
8508,
199,
504,
1275,
25166,
63,
643,
25787,
492,
510,
13202,
7248,
470,
3398,
15155,
199,
504,
1275,
529,
301,
4695,
265,
492,
3492,
301,
4695,
265,
199,
504,
1275,
2355,
1759,
63,
76,
17,
492,
334,
3883,
1759,
27537,
12,
9571,
1759,
2445,
23032,
12,
1169,
634,
15923,
63,
270,
3616,
63,
515,
9,
199,
504,
1275,
1320,
645,
492,
820,
5622,
1348,
15155,
199,
504,
1275,
1589,
382,
63,
2464,
492,
710,
382,
18569,
15155,
199,
199,
363,
452,
363,
275,
788,
7816,
13013,
297,
1779,
283,
29115,
69,
6214,
50,
22642,
297,
1779,
283,
27822,
2480,
297,
1779,
283,
27822,
2480,
12847,
297,
1779,
283,
40,
17081,
297,
1779,
283,
40,
10400,
15155,
297,
1779,
283,
44,
4291,
297,
1779,
283,
44,
4291,
12847,
297,
1779,
283,
27537,
297,
1779,
283,
27537,
12847,
297,
1779,
283,
27537,
44,
4291,
297,
1779,
283,
27537,
44,
4291,
12847,
297,
1779,
283,
27537,
44,
4291,
948,
297,
1779,
283,
10608,
13013,
297,
1779,
283,
2445,
297,
1779,
283,
2445,
23032,
297,
1779,
283,
2445,
23032,
12847,
297,
1779,
283,
11911,
40,
10400,
297,
1779,
283,
3947,
4476,
27822,
2480,
297,
1779,
283,
3947,
4476,
27822,
2480,
12847,
297,
1779,
283,
3947,
4476,
27537,
297,
1779,
283,
3947,
4476,
27537,
12847,
297,
1779,
283,
2844,
273,
19133,
14215,
14959,
83,
4993,
297,
1779,
283,
2844,
273,
19133,
14215,
14959,
83,
4993,
12847,
297,
1779,
283,
48,
13202,
7248,
470,
3398,
8508,
297,
1779,
283,
48,
13202,
7248,
470,
3398,
15155,
297,
1779,
283,
2623,
301,
4695,
265,
297,
1779,
283,
3883,
1759,
27537,
297,
1779,
283,
3883,
1759,
2445,
23032,
297,
1779,
283,
50,
22642,
297,
1779,
283,
50,
22642,
12847,
297,
1779,
283,
50,
22642,
8508,
297,
1779,
283,
50,
22642,
8508,
12847,
297,
1779,
283,
4254,
36,
8508,
297,
1779,
283,
4254,
36,
15155,
297,
1779,
283,
51,
30458,
8610,
297,
1779,
283,
1918,
382,
18569,
15155,
297,
1779,
283,
287,
386,
63,
515,
297,
1779,
283,
31590,
63,
515,
297,
1779,
283,
18412,
63,
515,
297,
1779,
283,
18412,
63,
270,
3616,
63,
515,
297,
1779,
283,
23452,
63,
12513,
63,
515,
297,
1779,
283,
11297,
19133,
63,
311,
297,
1779,
283,
11297,
19133,
63,
311,
63,
1679,
297,
1779,
283,
5562,
63,
12513,
297,
1779,
283,
50,
5622,
1348,
15155,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
luhanhan/horizon
|
openstack_dashboard/test/integration_tests/basewebobject.py
|
26
|
3446
|
# 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 selenium.common.exceptions as Exceptions
import selenium.webdriver.support.ui as Support
from selenium.webdriver.support import wait
import unittest
class BaseWebObject(unittest.TestCase):
"""Base class for all web objects."""
def __init__(self, driver, conf):
self.driver = driver
self.conf = conf
self.explicit_wait = self.conf.selenium.explicit_wait
def _is_element_present(self, *locator):
try:
self._get_element(*locator)
return True
except Exceptions.NoSuchElementException:
return False
def _is_element_visible(self, *locator):
try:
return self._get_element(*locator).is_displayed()
except (Exceptions.NoSuchElementException,
Exceptions.ElementNotVisibleException):
return False
def _is_element_displayed(self, element):
try:
return element.is_displayed()
except Exception:
return False
def _is_text_visible(self, element, text):
try:
return element.text == text
except Exception:
return False
def _get_element(self, *locator):
return self.driver.find_element(*locator)
def _get_elements(self, *locator):
return self.driver.find_elements(*locator)
def _fill_field_element(self, data, field_element):
field_element.clear()
field_element.send_keys(data)
return field_element
def _select_dropdown(self, value, element):
select = Support.Select(element)
select.select_by_visible_text(value)
def _select_dropdown_by_value(self, value, element):
select = Support.Select(element)
select.select_by_value(value)
def _turn_off_implicit_wait(self):
self.driver.implicitly_wait(0)
def _turn_on_implicit_wait(self):
self.driver.implicitly_wait(self.conf.selenium.page_timeout)
def _wait_until(self, predicate, timeout=None, poll_frequency=0.5):
"""Wait until the value returned by predicate is not False or
the timeout is elapsed.
'predicate' takes the driver as argument.
"""
if not timeout:
timeout = self.explicit_wait
wait.WebDriverWait(self.driver, timeout, poll_frequency).until(
predicate)
def _wait_till_text_present_in_element(self, element, text, timeout=None):
self._wait_until(lambda x: self._is_text_visible(element, text),
timeout)
def _wait_till_element_visible(self, element, timeout=None):
self._wait_until(lambda x: self._is_element_displayed(element),
timeout)
def _wait_till_element_disappears(self, element, timeout=None):
self._wait_until(lambda x: self._is_element_displayed(element),
timeout)
|
apache-2.0
|
[
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
646,
19481,
14,
2330,
14,
3924,
465,
24873,
199,
646,
19481,
14,
17946,
14,
4058,
14,
1907,
465,
12502,
199,
504,
19481,
14,
17946,
14,
4058,
492,
3618,
199,
646,
2882,
421,
199,
533,
3523,
5926,
1692,
8,
2796,
14,
1746,
304,
272,
408,
1563,
1021,
367,
1006,
3330,
2251,
1041,
272,
347,
636,
826,
721,
277,
12,
5253,
12,
3743,
304,
267,
291,
14,
3090,
275,
5253,
267,
291,
14,
2190,
275,
3743,
267,
291,
14,
10306,
63,
2573,
275,
291,
14,
2190,
14,
15041,
14,
10306,
63,
2573,
339,
347,
485,
374,
63,
2108,
63,
1881,
8,
277,
12,
627,
6354,
304,
267,
862,
26,
288,
291,
423,
362,
63,
2108,
2031,
6354,
9,
288,
372,
715,
267,
871,
24873,
14,
30049,
2162,
1726,
26,
288,
372,
756,
339,
347,
485,
374,
63,
2108,
63,
6604,
8,
277,
12,
627,
6354,
304,
267,
862,
26,
288,
372,
291,
423,
362,
63,
2108,
2031,
6354,
680,
374,
63,
22283,
342,
267,
871,
334,
16836,
14,
30049,
2162,
1726,
12,
355,
24873,
14,
2162,
1763,
14917,
1726,
304,
288,
372,
756,
339,
347,
485,
374,
63,
2108,
63,
22283,
8,
277,
12,
1819,
304,
267,
862,
26,
288,
372,
1819,
14,
374,
63,
22283,
342,
267,
871,
2186,
26,
288,
372,
756,
339,
347,
485,
374,
63,
505,
63,
6604,
8,
277,
12,
1819,
12,
1318,
304,
267,
862,
26,
288,
372,
1819,
14,
505,
508,
1318,
267,
871,
2186,
26,
288,
372,
756,
339,
347,
485,
362,
63,
2108,
8,
277,
12,
627,
6354,
304,
267,
372,
291,
14,
3090,
14,
1623,
63,
2108,
2031,
6354,
9,
339,
347,
485,
362,
63,
5527,
8,
277,
12,
627,
6354,
304,
267,
372,
291,
14,
3090,
14,
1623,
63,
5527,
2031,
6354,
9,
339,
347,
485,
4498,
63,
698,
63,
2108,
8,
277,
12,
666,
12,
901,
63,
2108,
304,
267,
901,
63,
2108,
14,
3584,
342,
267,
901,
63,
2108,
14,
2254,
63,
1612,
8,
576,
9,
267,
372,
901,
63,
2108,
339,
347,
485,
2416,
63,
29595,
8,
277,
12,
574,
12,
1819,
304,
267,
3504,
275,
12502,
14,
5446,
8,
2108,
9,
267,
3504,
14,
2416,
63,
991,
63,
6604,
63,
505,
8,
585,
9,
339,
347,
485,
2416,
63,
29595,
63,
991,
63,
585,
8,
277,
12,
574,
12,
1819,
304,
267,
3504,
275,
12502,
14,
5446,
8,
2108,
9,
267,
3504,
14,
2416,
63,
991,
63,
585,
8,
585,
9,
339,
347,
485,
353,
63,
1997,
63,
11886,
63,
2573,
8,
277,
304,
267,
291,
14,
3090,
14,
31120,
63,
2573,
8,
16,
9,
339,
347,
485,
353,
63,
265,
63,
11886,
63,
2573,
8,
277,
304,
267,
291,
14,
3090,
14,
31120,
63,
2573,
8,
277,
14,
2190,
14,
15041,
14,
1606,
63,
2593,
9,
339,
347,
485,
2573,
63,
8111,
8,
277,
12,
11944,
12,
2653,
29,
403,
12,
11271,
63,
11132,
29,
16,
14,
21,
304,
267,
408,
7536,
5133,
314,
574,
2138,
701,
11944,
365,
440,
756,
503,
267,
314,
2653,
365,
14439,
14,
267,
283,
14463,
7,
6181,
314,
5253,
465,
1423,
14,
267,
408,
267,
340,
440,
2653,
26,
288,
2653,
275,
291,
14,
10306,
63,
2573,
267,
3618,
14,
27009,
7536,
8,
277,
14,
3090,
12,
2653,
12,
11271,
63,
11132,
680,
8111,
8,
288,
11944,
9,
339,
347,
485,
2573,
63,
12587,
63,
505,
63,
1881,
63,
262,
63,
2108,
8,
277,
12,
1819,
12,
1318,
12,
2653,
29,
403,
304,
267,
291,
423,
2573,
63,
8111,
8,
2734,
671,
26,
291,
423,
374,
63,
505,
63,
6604,
8,
2108,
12,
1318,
395,
586,
2653,
9,
339,
347,
485,
2573,
63,
12587,
63,
2108,
63,
6604,
8,
277,
12,
1819,
12,
2653,
29,
403,
304,
267,
291,
423,
2573,
63,
8111,
8,
2734,
671,
26,
291,
423,
374,
63,
2108,
63,
22283,
8,
2108,
395,
586,
2653,
9,
339,
347,
485,
2573,
63,
12587,
63,
2108,
63,
2297,
31711,
4291,
8,
277,
12,
1819,
12,
2653,
29,
403,
304,
267,
291,
423,
2573,
63,
8111,
8,
2734,
671,
26,
291,
423,
374,
63,
2108,
63,
22283,
8,
2108,
395,
586,
2653,
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
] |
[
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,
19481,
14,
2330,
14,
3924,
465,
24873,
199,
646,
19481,
14,
17946,
14,
4058,
14,
1907,
465,
12502,
199,
504,
19481,
14,
17946,
14,
4058,
492,
3618,
199,
646,
2882,
421,
199,
533,
3523,
5926,
1692,
8,
2796,
14,
1746,
304,
272,
408,
1563,
1021,
367,
1006,
3330,
2251,
1041,
272,
347,
636,
826,
721,
277,
12,
5253,
12,
3743,
304,
267,
291,
14,
3090,
275,
5253,
267,
291,
14,
2190,
275,
3743,
267,
291,
14,
10306,
63,
2573,
275,
291,
14,
2190,
14,
15041,
14,
10306,
63,
2573,
339,
347,
485,
374,
63,
2108,
63,
1881,
8,
277,
12,
627,
6354,
304,
267,
862,
26,
288,
291,
423,
362,
63,
2108,
2031,
6354,
9,
288,
372,
715,
267,
871,
24873,
14,
30049,
2162,
1726,
26,
288,
372,
756,
339,
347,
485,
374,
63,
2108,
63,
6604,
8,
277,
12,
627,
6354,
304,
267,
862,
26,
288,
372,
291,
423,
362,
63,
2108,
2031,
6354,
680,
374,
63,
22283,
342,
267,
871,
334,
16836,
14,
30049,
2162,
1726,
12,
355,
24873,
14,
2162,
1763,
14917,
1726,
304,
288,
372,
756,
339,
347,
485,
374,
63,
2108,
63,
22283,
8,
277,
12,
1819,
304,
267,
862,
26,
288,
372,
1819,
14,
374,
63,
22283,
342,
267,
871,
2186,
26,
288,
372,
756,
339,
347,
485,
374,
63,
505,
63,
6604,
8,
277,
12,
1819,
12,
1318,
304,
267,
862,
26,
288,
372,
1819,
14,
505,
508,
1318,
267,
871,
2186,
26,
288,
372,
756,
339,
347,
485,
362,
63,
2108,
8,
277,
12,
627,
6354,
304,
267,
372,
291,
14,
3090,
14,
1623,
63,
2108,
2031,
6354,
9,
339,
347,
485,
362,
63,
5527,
8,
277,
12,
627,
6354,
304,
267,
372,
291,
14,
3090,
14,
1623,
63,
5527,
2031,
6354,
9,
339,
347,
485,
4498,
63,
698,
63,
2108,
8,
277,
12,
666,
12,
901,
63,
2108,
304,
267,
901,
63,
2108,
14,
3584,
342,
267,
901,
63,
2108,
14,
2254,
63,
1612,
8,
576,
9,
267,
372,
901,
63,
2108,
339,
347,
485,
2416,
63,
29595,
8,
277,
12,
574,
12,
1819,
304,
267,
3504,
275,
12502,
14,
5446,
8,
2108,
9,
267,
3504,
14,
2416,
63,
991,
63,
6604,
63,
505,
8,
585,
9,
339,
347,
485,
2416,
63,
29595,
63,
991,
63,
585,
8,
277,
12,
574,
12,
1819,
304,
267,
3504,
275,
12502,
14,
5446,
8,
2108,
9,
267,
3504,
14,
2416,
63,
991,
63,
585,
8,
585,
9,
339,
347,
485,
353,
63,
1997,
63,
11886,
63,
2573,
8,
277,
304,
267,
291,
14,
3090,
14,
31120,
63,
2573,
8,
16,
9,
339,
347,
485,
353,
63,
265,
63,
11886,
63,
2573,
8,
277,
304,
267,
291,
14,
3090,
14,
31120,
63,
2573,
8,
277,
14,
2190,
14,
15041,
14,
1606,
63,
2593,
9,
339,
347,
485,
2573,
63,
8111,
8,
277,
12,
11944,
12,
2653,
29,
403,
12,
11271,
63,
11132,
29,
16,
14,
21,
304,
267,
408,
7536,
5133,
314,
574,
2138,
701,
11944,
365,
440,
756,
503,
267,
314,
2653,
365,
14439,
14,
267,
283,
14463,
7,
6181,
314,
5253,
465,
1423,
14,
267,
408,
267,
340,
440,
2653,
26,
288,
2653,
275,
291,
14,
10306,
63,
2573,
267,
3618,
14,
27009,
7536,
8,
277,
14,
3090,
12,
2653,
12,
11271,
63,
11132,
680,
8111,
8,
288,
11944,
9,
339,
347,
485,
2573,
63,
12587,
63,
505,
63,
1881,
63,
262,
63,
2108,
8,
277,
12,
1819,
12,
1318,
12,
2653,
29,
403,
304,
267,
291,
423,
2573,
63,
8111,
8,
2734,
671,
26,
291,
423,
374,
63,
505,
63,
6604,
8,
2108,
12,
1318,
395,
586,
2653,
9,
339,
347,
485,
2573,
63,
12587,
63,
2108,
63,
6604,
8,
277,
12,
1819,
12,
2653,
29,
403,
304,
267,
291,
423,
2573,
63,
8111,
8,
2734,
671,
26,
291,
423,
374,
63,
2108,
63,
22283,
8,
2108,
395,
586,
2653,
9,
339,
347,
485,
2573,
63,
12587,
63,
2108,
63,
2297,
31711,
4291,
8,
277,
12,
1819,
12,
2653,
29,
403,
304,
267,
291,
423,
2573,
63,
8111,
8,
2734,
671,
26,
291,
423,
374,
63,
2108,
63,
22283,
8,
2108,
395,
586,
2653,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
perkinslr/pypyjs
|
addedLibraries/nevow/taglibrary/livetags.py
|
2
|
3045
|
"""
This module provides helpers to define and manage live components, that
is taglibrary components whose instances are client-side JS objects.
Each component must have a unique name in the livepage context. This
name is usually the same as (or derived from) the 'name' field in the
data given to the tag renderer. The 'livetags' object on the client
side is used as a mapping between those names and the underlying
object. The server will rely on this mapping to 'access' the
javascript objects. To make use of the livetags framework, the
livepage must include the component glue, by injecting
"componentGlue.inlineGlue" or "componentGlue.fileGlue" in the stan tree.
Component-specific glue (usually object definitions) must also
be added as needed.
"component" is a special object used to create javascript literals for
dealing with client components::
component.<name>.init(<initializer>)
Generate the JS command to associate <name> to the object
designated by the initializer literal. This sequence is usually
put in the stan tree by the live component renderer, after
having constructed the widget. The initializer is supposed to
construct a controller bound to the widget.
component.<name>.delete
Generate the JS command to remove the given component.
If the controller has a del method, it will be called.
The name is then removed from the mapping.
All other uses construct normal livepage literals:
component.<name>.<attribute>
Generate the JS command to retrieve the given attribute on the
named object.
component.<name>.<method>(...)
Generate the JS command to call the given method on the object.
Note that the <name>, <attribute>, <method> can also be retrieved using
the getitem notation. (e.g. component['foo'])
"""
from nevow import livepage, tags as t, static
class _livetag(object):
def __init__(self, name):
self.name = name
def __getitem__(self, key):
if key == 'init':
def _init(value):
return livepage.js("livetags[%r] = %s;"%(self.name,value))
return _init
if key == 'delete':
return livepage.js("delComponent(%r);"%self.name)
return livepage.js("livetags[%r].%s"%(self.name, key))
__getattr__ = __getitem__
class _component(object):
"""This object provides a wrapper to manage live components"""
def __getitem__(self, name):
return _livetag(name)
__getattr__ = __getitem__
component = _component()
class componentGlue(object):
_js = """
livetags = new Object();
function delComponent(name) {
o = livetags[name];
if(o) {
if(o.del) {
o.del();
}
livetags[name] = null;
}
}
"""
fileJS = static.Data(_js, 'text/javascript')
inlineGlue = t.script(type_='text/javascript')[ t.xml(_js) ]
fileGlue = t.script(type_='text/javascript', src='/componentGlue.js')
__all__ = [ 'component', 'componentGlue' ]
|
mit
|
[
624,
199,
2765,
859,
6571,
10897,
370,
5627,
436,
9635,
12166,
7323,
12,
626,
199,
374,
1947,
4342,
7323,
7447,
4454,
787,
1890,
13,
2441,
18001,
2251,
14,
199,
199,
22321,
3931,
1471,
1172,
282,
3747,
536,
315,
314,
12166,
1606,
1067,
14,
221,
961,
199,
354,
365,
9987,
314,
2011,
465,
334,
269,
7131,
687,
9,
314,
283,
354,
7,
901,
315,
314,
199,
576,
1627,
370,
314,
1947,
11889,
14,
221,
710,
283,
317,
86,
1841,
458,
7,
909,
641,
314,
1890,
199,
2441,
365,
1202,
465,
282,
4412,
3382,
5204,
1561,
436,
314,
8793,
199,
785,
14,
221,
710,
1654,
911,
19687,
641,
642,
4412,
370,
283,
2732,
7,
314,
199,
9554,
2251,
14,
221,
4005,
1852,
675,
402,
314,
1212,
86,
1841,
458,
10059,
12,
314,
199,
6442,
1606,
1471,
2387,
314,
3931,
6482,
310,
12,
701,
16182,
316,
199,
2,
3173,
39,
11322,
14,
6460,
39,
11322,
2,
503,
298,
3173,
39,
11322,
14,
493,
39,
11322,
2,
315,
314,
410,
290,
3123,
14,
199,
7004,
13,
6100,
6482,
310,
334,
25118,
909,
10269,
9,
1471,
2597,
199,
1235,
3483,
465,
4346,
14,
199,
199,
2,
3173,
2,
365,
282,
4539,
909,
1202,
370,
1218,
18910,
18041,
367,
199,
21245,
316,
543,
1890,
7323,
447,
8410,
3931,
21455,
354,
10827,
826,
27530,
6498,
18956,
272,
489,
7958,
314,
18001,
1414,
370,
20133,
665,
354,
30,
370,
314,
909,
489,
12899,
972,
701,
314,
11130,
8785,
14,
221,
961,
3414,
365,
9987,
489,
5324,
315,
314,
410,
290,
3123,
701,
314,
12166,
3931,
11889,
12,
2410,
489,
9445,
14701,
314,
3938,
14,
221,
710,
11130,
365,
20042,
370,
489,
6982,
282,
7614,
3914,
370,
314,
3938,
14,
272,
2043,
3931,
21455,
354,
10827,
1807,
272,
489,
7958,
314,
18001,
1414,
370,
2813,
314,
1627,
3931,
14,
489,
982,
314,
7614,
965,
282,
2150,
1083,
12,
652,
911,
506,
2797,
14,
489,
710,
536,
365,
2066,
4829,
687,
314,
4412,
14,
8410,
2900,
1163,
4440,
6982,
3293,
12166,
1606,
18041,
26,
272,
2043,
3931,
21455,
354,
10827,
28,
3215,
30,
2541,
7958,
314,
18001,
1414,
370,
8044,
314,
1627,
2225,
641,
314,
489,
4310,
909,
14,
8410,
3931,
21455,
354,
10827,
28,
765,
13661,
11965,
272,
489,
7958,
314,
18001,
1414,
370,
1240,
314,
1627,
1083,
641,
314,
909,
14,
199,
199,
7443,
626,
314,
665,
354,
6244,
665,
3215,
6244,
665,
765,
30,
883,
2597,
506,
12396,
1808,
199,
1589,
2312,
4484,
15843,
14,
334,
69,
14,
71,
14,
3931,
459,
1421,
1105,
199,
624,
199,
199,
504,
1279,
86,
583,
492,
12166,
1606,
12,
3762,
465,
307,
12,
2955,
199,
199,
533,
485,
317,
86,
11304,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
536,
304,
267,
291,
14,
354,
275,
536,
272,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
340,
790,
508,
283,
826,
356,
288,
347,
485,
826,
8,
585,
304,
355,
372,
12166,
1606,
14,
3596,
480,
317,
86,
1841,
458,
9722,
82,
61,
275,
450,
83,
9426,
2840,
277,
14,
354,
12,
585,
430,
288,
372,
485,
826,
267,
340,
790,
508,
283,
1807,
356,
288,
372,
12166,
1606,
14,
3596,
480,
2264,
7004,
4042,
82,
2736,
6808,
277,
14,
354,
9,
267,
372,
12166,
1606,
14,
3596,
480,
317,
86,
1841,
458,
9722,
82,
1055,
5,
83,
14007,
277,
14,
354,
12,
790,
430,
272,
636,
5675,
363,
275,
636,
6095,
363,
1362,
199,
533,
485,
3173,
8,
785,
304,
272,
408,
2765,
909,
6571,
282,
4975,
370,
9635,
12166,
7323,
624,
2286,
347,
636,
6095,
721,
277,
12,
536,
304,
267,
372,
485,
317,
86,
11304,
8,
354,
9,
272,
636,
5675,
363,
275,
636,
6095,
363,
199,
199,
3173,
275,
485,
3173,
342,
199,
199,
533,
3931,
39,
11322,
8,
785,
304,
2286,
485,
3596,
275,
408,
199,
317,
86,
1841,
458,
275,
892,
6935,
7303,
199,
199,
1593,
2150,
7004,
8,
354,
9,
469,
272,
312,
275,
1212,
86,
1841,
458,
59,
354,
11566,
272,
340,
8,
79,
9,
469,
267,
340,
8,
79,
14,
2264,
9,
469,
288,
312,
14,
2264,
7303,
267,
789,
267,
1212,
86,
1841,
458,
59,
354,
61,
275,
2973,
27,
272,
789,
199,
93,
199,
624,
272,
570,
11378,
258,
275,
2955,
14,
1451,
1547,
3596,
12,
283,
505,
15,
9554,
358,
2286,
8308,
39,
11322,
275,
307,
14,
1579,
8,
466,
7993,
505,
15,
9554,
5832,
307,
14,
1652,
1547,
3596,
9,
1622,
272,
570,
39,
11322,
257,
275,
307,
14,
1579,
8,
466,
7993,
505,
15,
9554,
297,
2928,
8805,
3173,
39,
11322,
14,
3596,
358,
421,
199,
363,
452,
363,
275,
359,
283,
3173,
297,
283,
3173,
39,
11322,
7,
221,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
2765,
859,
6571,
10897,
370,
5627,
436,
9635,
12166,
7323,
12,
626,
199,
374,
1947,
4342,
7323,
7447,
4454,
787,
1890,
13,
2441,
18001,
2251,
14,
199,
199,
22321,
3931,
1471,
1172,
282,
3747,
536,
315,
314,
12166,
1606,
1067,
14,
221,
961,
199,
354,
365,
9987,
314,
2011,
465,
334,
269,
7131,
687,
9,
314,
283,
354,
7,
901,
315,
314,
199,
576,
1627,
370,
314,
1947,
11889,
14,
221,
710,
283,
317,
86,
1841,
458,
7,
909,
641,
314,
1890,
199,
2441,
365,
1202,
465,
282,
4412,
3382,
5204,
1561,
436,
314,
8793,
199,
785,
14,
221,
710,
1654,
911,
19687,
641,
642,
4412,
370,
283,
2732,
7,
314,
199,
9554,
2251,
14,
221,
4005,
1852,
675,
402,
314,
1212,
86,
1841,
458,
10059,
12,
314,
199,
6442,
1606,
1471,
2387,
314,
3931,
6482,
310,
12,
701,
16182,
316,
199,
2,
3173,
39,
11322,
14,
6460,
39,
11322,
2,
503,
298,
3173,
39,
11322,
14,
493,
39,
11322,
2,
315,
314,
410,
290,
3123,
14,
199,
7004,
13,
6100,
6482,
310,
334,
25118,
909,
10269,
9,
1471,
2597,
199,
1235,
3483,
465,
4346,
14,
199,
199,
2,
3173,
2,
365,
282,
4539,
909,
1202,
370,
1218,
18910,
18041,
367,
199,
21245,
316,
543,
1890,
7323,
447,
8410,
3931,
21455,
354,
10827,
826,
27530,
6498,
18956,
272,
489,
7958,
314,
18001,
1414,
370,
20133,
665,
354,
30,
370,
314,
909,
489,
12899,
972,
701,
314,
11130,
8785,
14,
221,
961,
3414,
365,
9987,
489,
5324,
315,
314,
410,
290,
3123,
701,
314,
12166,
3931,
11889,
12,
2410,
489,
9445,
14701,
314,
3938,
14,
221,
710,
11130,
365,
20042,
370,
489,
6982,
282,
7614,
3914,
370,
314,
3938,
14,
272,
2043,
3931,
21455,
354,
10827,
1807,
272,
489,
7958,
314,
18001,
1414,
370,
2813,
314,
1627,
3931,
14,
489,
982,
314,
7614,
965,
282,
2150,
1083,
12,
652,
911,
506,
2797,
14,
489,
710,
536,
365,
2066,
4829,
687,
314,
4412,
14,
8410,
2900,
1163,
4440,
6982,
3293,
12166,
1606,
18041,
26,
272,
2043,
3931,
21455,
354,
10827,
28,
3215,
30,
2541,
7958,
314,
18001,
1414,
370,
8044,
314,
1627,
2225,
641,
314,
489,
4310,
909,
14,
8410,
3931,
21455,
354,
10827,
28,
765,
13661,
11965,
272,
489,
7958,
314,
18001,
1414,
370,
1240,
314,
1627,
1083,
641,
314,
909,
14,
199,
199,
7443,
626,
314,
665,
354,
6244,
665,
3215,
6244,
665,
765,
30,
883,
2597,
506,
12396,
1808,
199,
1589,
2312,
4484,
15843,
14,
334,
69,
14,
71,
14,
3931,
459,
1421,
1105,
199,
624,
199,
199,
504,
1279,
86,
583,
492,
12166,
1606,
12,
3762,
465,
307,
12,
2955,
199,
199,
533,
485,
317,
86,
11304,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
536,
304,
267,
291,
14,
354,
275,
536,
272,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
340,
790,
508,
283,
826,
356,
288,
347,
485,
826,
8,
585,
304,
355,
372,
12166,
1606,
14,
3596,
480,
317,
86,
1841,
458,
9722,
82,
61,
275,
450,
83,
9426,
2840,
277,
14,
354,
12,
585,
430,
288,
372,
485,
826,
267,
340,
790,
508,
283,
1807,
356,
288,
372,
12166,
1606,
14,
3596,
480,
2264,
7004,
4042,
82,
2736,
6808,
277,
14,
354,
9,
267,
372,
12166,
1606,
14,
3596,
480,
317,
86,
1841,
458,
9722,
82,
1055,
5,
83,
14007,
277,
14,
354,
12,
790,
430,
272,
636,
5675,
363,
275,
636,
6095,
363,
1362,
199,
533,
485,
3173,
8,
785,
304,
272,
408,
2765,
909,
6571,
282,
4975,
370,
9635,
12166,
7323,
624,
2286,
347,
636,
6095,
721,
277,
12,
536,
304,
267,
372,
485,
317,
86,
11304,
8,
354,
9,
272,
636,
5675,
363,
275,
636,
6095,
363,
199,
199,
3173,
275,
485,
3173,
342,
199,
199,
533,
3931,
39,
11322,
8,
785,
304,
2286,
485,
3596,
275,
408,
199,
317,
86,
1841,
458,
275,
892,
6935,
7303,
199,
199,
1593,
2150,
7004,
8,
354,
9,
469,
272,
312,
275,
1212,
86,
1841,
458,
59,
354,
11566,
272,
340,
8,
79,
9,
469,
267,
340,
8,
79,
14,
2264,
9,
469,
288,
312,
14,
2264,
7303,
267,
789,
267,
1212,
86,
1841,
458,
59,
354,
61,
275,
2973,
27,
272,
789,
199,
93,
199,
624,
272,
570,
11378,
258,
275,
2955,
14,
1451,
1547,
3596,
12,
283,
505,
15,
9554,
358,
2286,
8308,
39,
11322,
275,
307,
14,
1579,
8,
466,
7993,
505,
15,
9554,
5832,
307,
14,
1652,
1547,
3596,
9,
1622,
272,
570,
39,
11322,
257,
275,
307,
14,
1579,
8,
466,
7993,
505,
15,
9554,
297,
2928,
8805,
3173,
39,
11322,
14,
3596,
358,
421,
199,
363,
452,
363,
275,
359,
283,
3173,
297,
283,
3173,
39,
11322,
7,
221,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
felipenaselva/repo.felipe
|
plugin.video.uwc/k18.py
|
1
|
2513
|
'''
Ultimate Whitecream
Copyright (C) 2015 mortael
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import urllib, urllib2, re, cookielib, os.path, sys, socket
import xbmc, xbmcplugin, xbmcgui, xbmcaddon
import utils
#230: k18.Main()
#231: k18.List(url)
#232: k18.Playvid(url, name, download)
#233: k18.Cat(url)
#234: k18.Search(url, keyword)
progress = utils.progress
def Main():
utils.addDir('[COLOR hotpink]Categories[/COLOR]','http://k18.co/',233,'','')
utils.addDir('[COLOR hotpink]Search[/COLOR]','http://k18.co/?s=',234,'','')
List('http://k18.co/page/1/')
xbmcplugin.endOfDirectory(utils.addon_handle)
def List(url):
listhtml = utils.getHtml(url, '')
match = re.compile(r'class="content-list-thumb">\s+<a href="([^"]+)" title="([^"]+)">.*?src="([^"]+)"', re.DOTALL | re.IGNORECASE).findall(listhtml)
for videopage, name, img in match:
name = utils.cleantext(name)
utils.addDownLink(name, videopage, 232, img, '')
try:
nextp=re.compile('next page-numbers" href="([^"]+)">»', re.DOTALL | re.IGNORECASE).findall(listhtml)[0]
utils.addDir('Next Page', nextp, 231,'')
except: pass
xbmcplugin.endOfDirectory(utils.addon_handle)
def Search(url, keyword=None):
searchUrl = url
if not keyword:
utils.searchDir(url, 234)
else:
title = keyword.replace(' ','+')
searchUrl = searchUrl + title
print "Searching URL: " + searchUrl
List(searchUrl)
def Cat(url):
cathtml = utils.getHtml(url, '')
match = re.compile('0" value="([^"]+)">([^<]+)<', re.DOTALL | re.IGNORECASE).findall(cathtml)
for catpage, name in match:
catpage = 'http://k18.co/?cat=' + catpage
utils.addDir(name, catpage, 231, '')
xbmcplugin.endOfDirectory(utils.addon_handle)
def Playvid(url, name, download=None):
utils.PLAYVIDEO(url, name, download)
|
gpl-2.0
|
[
2344,
272,
738,
76,
2906,
323,
2816,
1175,
67,
1091,
272,
1898,
334,
35,
9,
6900,
333,
361,
10643,
339,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
2344,
199,
199,
646,
4011,
12,
4011,
18,
12,
295,
12,
26234,
12,
747,
14,
515,
12,
984,
12,
2838,
199,
646,
11709,
12,
11709,
2718,
12,
26418,
12,
11709,
9291,
199,
199,
646,
3778,
199,
199,
3,
9687,
26,
1022,
1085,
14,
6756,
342,
199,
3,
11921,
26,
1022,
1085,
14,
1296,
8,
633,
9,
199,
3,
8001,
26,
1022,
1085,
14,
9651,
5017,
8,
633,
12,
536,
12,
5235,
9,
199,
3,
10034,
26,
1022,
1085,
14,
21548,
8,
633,
9,
199,
3,
5533,
26,
1022,
1085,
14,
5278,
8,
633,
12,
4252,
9,
199,
199,
5734,
275,
3778,
14,
5734,
199,
199,
318,
11298,
837,
272,
3778,
14,
525,
3567,
11894,
7134,
18469,
26591,
61,
28731,
28787,
7134,
61,
1673,
1014,
921,
75,
1085,
14,
331,
3678,
10034,
2584,
20944,
272,
3778,
14,
525,
3567,
11894,
7134,
18469,
26591,
61,
5278,
28787,
7134,
61,
1673,
1014,
921,
75,
1085,
14,
331,
10197,
83,
4009,
5533,
2584,
20944,
272,
3820,
360,
1014,
921,
75,
1085,
14,
331,
15,
1606,
15,
17,
6217,
272,
11709,
2718,
14,
500,
3466,
6231,
8,
1208,
14,
9291,
63,
2479,
9,
421,
199,
318,
3820,
8,
633,
304,
272,
769,
1360,
275,
3778,
14,
362,
12957,
8,
633,
12,
4074,
272,
1336,
275,
295,
14,
2014,
8,
82,
7,
533,
628,
1317,
13,
513,
13,
16534,
14559,
83,
11,
28,
65,
4369,
32391,
2538,
24296,
8771,
1743,
6697,
2164,
32391,
297,
295,
14,
16504,
1204,
295,
14,
15434,
680,
6452,
8,
513,
1360,
9,
272,
367,
3991,
1606,
12,
536,
12,
6050,
315,
1336,
26,
267,
536,
275,
3778,
14,
3118,
505,
8,
354,
9,
267,
3778,
14,
525,
3514,
3834,
8,
354,
12,
3991,
1606,
12,
499,
708,
12,
6050,
12,
4074,
272,
862,
26,
267,
2163,
80,
29,
264,
14,
2014,
360,
2184,
2034,
13,
10548,
2,
4369,
24296,
8771,
21608,
345,
14209,
10805,
295,
14,
16504,
1204,
295,
14,
15434,
680,
6452,
8,
513,
1360,
2788,
16,
61,
267,
3778,
14,
525,
3567,
360,
5765,
10331,
297,
2163,
80,
12,
499,
2192,
2584,
358,
272,
871,
26,
986,
272,
11709,
2718,
14,
500,
3466,
6231,
8,
1208,
14,
9291,
63,
2479,
9,
10813,
199,
318,
8730,
8,
633,
12,
4252,
29,
403,
304,
272,
2754,
6417,
275,
1166,
272,
340,
440,
4252,
26,
267,
3778,
14,
1733,
3567,
8,
633,
12,
26569,
9,
272,
587,
26,
267,
2538,
275,
4252,
14,
1814,
360,
1656,
6828,
358,
267,
2754,
6417,
275,
2754,
6417,
435,
2538,
267,
870,
298,
5278,
316,
2851,
26,
298,
435,
2754,
6417,
267,
3820,
8,
1733,
6417,
9,
421,
199,
318,
445,
292,
8,
633,
304,
272,
286,
1619,
18866,
275,
3778,
14,
362,
12957,
8,
633,
12,
4074,
272,
1336,
275,
295,
14,
2014,
360,
16,
2,
574,
24296,
8771,
1743,
31204,
11896,
28,
297,
295,
14,
16504,
1204,
295,
14,
15434,
680,
6452,
8,
696,
273,
18866,
9,
272,
367,
6230,
1606,
12,
536,
315,
1336,
26,
267,
6230,
1606,
275,
283,
1014,
921,
75,
1085,
14,
331,
10197,
3385,
534,
435,
6230,
1606,
267,
3778,
14,
525,
3567,
8,
354,
12,
6230,
1606,
12,
499,
2192,
12,
4074,
272,
11709,
2718,
14,
500,
3466,
6231,
8,
1208,
14,
9291,
63,
2479,
9,
259,
421,
199,
318,
16527,
5017,
8,
633,
12,
536,
12,
5235,
29,
403,
304,
272,
3778,
14,
11625,
20142,
8,
633,
12,
536,
12,
5235,
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
] |
[
272,
738,
76,
2906,
323,
2816,
1175,
67,
1091,
272,
1898,
334,
35,
9,
6900,
333,
361,
10643,
339,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
2344,
199,
199,
646,
4011,
12,
4011,
18,
12,
295,
12,
26234,
12,
747,
14,
515,
12,
984,
12,
2838,
199,
646,
11709,
12,
11709,
2718,
12,
26418,
12,
11709,
9291,
199,
199,
646,
3778,
199,
199,
3,
9687,
26,
1022,
1085,
14,
6756,
342,
199,
3,
11921,
26,
1022,
1085,
14,
1296,
8,
633,
9,
199,
3,
8001,
26,
1022,
1085,
14,
9651,
5017,
8,
633,
12,
536,
12,
5235,
9,
199,
3,
10034,
26,
1022,
1085,
14,
21548,
8,
633,
9,
199,
3,
5533,
26,
1022,
1085,
14,
5278,
8,
633,
12,
4252,
9,
199,
199,
5734,
275,
3778,
14,
5734,
199,
199,
318,
11298,
837,
272,
3778,
14,
525,
3567,
11894,
7134,
18469,
26591,
61,
28731,
28787,
7134,
61,
1673,
1014,
921,
75,
1085,
14,
331,
3678,
10034,
2584,
20944,
272,
3778,
14,
525,
3567,
11894,
7134,
18469,
26591,
61,
5278,
28787,
7134,
61,
1673,
1014,
921,
75,
1085,
14,
331,
10197,
83,
4009,
5533,
2584,
20944,
272,
3820,
360,
1014,
921,
75,
1085,
14,
331,
15,
1606,
15,
17,
6217,
272,
11709,
2718,
14,
500,
3466,
6231,
8,
1208,
14,
9291,
63,
2479,
9,
421,
199,
318,
3820,
8,
633,
304,
272,
769,
1360,
275,
3778,
14,
362,
12957,
8,
633,
12,
4074,
272,
1336,
275,
295,
14,
2014,
8,
82,
7,
533,
628,
1317,
13,
513,
13,
16534,
14559,
83,
11,
28,
65,
4369,
32391,
2538,
24296,
8771,
1743,
6697,
2164,
32391,
297,
295,
14,
16504,
1204,
295,
14,
15434,
680,
6452,
8,
513,
1360,
9,
272,
367,
3991,
1606,
12,
536,
12,
6050,
315,
1336,
26,
267,
536,
275,
3778,
14,
3118,
505,
8,
354,
9,
267,
3778,
14,
525,
3514,
3834,
8,
354,
12,
3991,
1606,
12,
499,
708,
12,
6050,
12,
4074,
272,
862,
26,
267,
2163,
80,
29,
264,
14,
2014,
360,
2184,
2034,
13,
10548,
2,
4369,
24296,
8771,
21608,
345,
14209,
10805,
295,
14,
16504,
1204,
295,
14,
15434,
680,
6452,
8,
513,
1360,
2788,
16,
61,
267,
3778,
14,
525,
3567,
360,
5765,
10331,
297,
2163,
80,
12,
499,
2192,
2584,
358,
272,
871,
26,
986,
272,
11709,
2718,
14,
500,
3466,
6231,
8,
1208,
14,
9291,
63,
2479,
9,
10813,
199,
318,
8730,
8,
633,
12,
4252,
29,
403,
304,
272,
2754,
6417,
275,
1166,
272,
340,
440,
4252,
26,
267,
3778,
14,
1733,
3567,
8,
633,
12,
26569,
9,
272,
587,
26,
267,
2538,
275,
4252,
14,
1814,
360,
1656,
6828,
358,
267,
2754,
6417,
275,
2754,
6417,
435,
2538,
267,
870,
298,
5278,
316,
2851,
26,
298,
435,
2754,
6417,
267,
3820,
8,
1733,
6417,
9,
421,
199,
318,
445,
292,
8,
633,
304,
272,
286,
1619,
18866,
275,
3778,
14,
362,
12957,
8,
633,
12,
4074,
272,
1336,
275,
295,
14,
2014,
360,
16,
2,
574,
24296,
8771,
1743,
31204,
11896,
28,
297,
295,
14,
16504,
1204,
295,
14,
15434,
680,
6452,
8,
696,
273,
18866,
9,
272,
367,
6230,
1606,
12,
536,
315,
1336,
26,
267,
6230,
1606,
275,
283,
1014,
921,
75,
1085,
14,
331,
10197,
3385,
534,
435,
6230,
1606,
267,
3778,
14,
525,
3567,
8,
354,
12,
6230,
1606,
12,
499,
2192,
12,
4074,
272,
11709,
2718,
14,
500,
3466,
6231,
8,
1208,
14,
9291,
63,
2479,
9,
259,
421,
199,
318,
16527,
5017,
8,
633,
12,
536,
12,
5235,
29,
403,
304,
272,
3778,
14,
11625,
20142,
8,
633,
12,
536,
12,
5235,
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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,
0,
0,
0,
0,
0
] |
intelie/pycollector
|
src/third/sqlalchemy/orm/exc.py
|
14
|
5224
|
# orm/exc.py
# Copyright (C) 2005-2011 the SQLAlchemy authors and contributors <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""SQLAlchemy ORM exceptions."""
import sqlalchemy as sa
orm_util = sa.util.importlater('sqlalchemy.orm', 'util')
NO_STATE = (AttributeError, KeyError)
"""Exception types that may be raised by instrumentation implementations."""
class StaleDataError(sa.exc.SQLAlchemyError):
"""An operation encountered database state that is unaccounted for.
Conditions which cause this to happen include:
* A flush may have attempted to update or delete rows
and an unexpected number of rows were matched during
the UPDATE or DELETE statement. Note that when
version_id_col is used, rows in UPDATE or DELETE statements
are also matched against the current known version
identifier.
* A mapped object with version_id_col was refreshed,
and the version number coming back from the database does
not match that of the object itself.
* A object is detached from its parent object, however
the object was previously attached to a different parent
identity which was garbage collected, and a decision
cannot be made if the new parent was really the most
recent "parent" (new in 0.7.4).
"""
ConcurrentModificationError = StaleDataError
class FlushError(sa.exc.SQLAlchemyError):
"""A invalid condition was detected during flush()."""
class UnmappedError(sa.exc.InvalidRequestError):
"""Base for exceptions that involve expected mappings not present."""
class ObjectDereferencedError(sa.exc.SQLAlchemyError):
"""An operation cannot complete due to an object being garbage collected."""
class DetachedInstanceError(sa.exc.SQLAlchemyError):
"""An attempt to access unloaded attributes on a
mapped instance that is detached."""
class UnmappedInstanceError(UnmappedError):
"""An mapping operation was requested for an unknown instance."""
def __init__(self, obj, msg=None):
if not msg:
try:
mapper = sa.orm.class_mapper(type(obj))
name = _safe_cls_name(type(obj))
msg = ("Class %r is mapped, but this instance lacks "
"instrumentation. This occurs when the instance is created "
"before sqlalchemy.orm.mapper(%s) was called." % (name, name))
except UnmappedClassError:
msg = _default_unmapped(type(obj))
if isinstance(obj, type):
msg += (
'; was a class (%s) supplied where an instance was '
'required?' % _safe_cls_name(obj))
UnmappedError.__init__(self, msg)
class UnmappedClassError(UnmappedError):
"""An mapping operation was requested for an unknown class."""
def __init__(self, cls, msg=None):
if not msg:
msg = _default_unmapped(cls)
UnmappedError.__init__(self, msg)
class ObjectDeletedError(sa.exc.InvalidRequestError):
"""A refresh operation failed to retrieve the database
row corresponding to an object's known primary key identity.
A refresh operation proceeds when an expired attribute is
accessed on an object, or when :meth:`.Query.get` is
used to retrieve an object which is, upon retrieval, detected
as expired. A SELECT is emitted for the target row
based on primary key; if no row is returned, this
exception is raised.
The true meaning of this exception is simply that
no row exists for the primary key identifier associated
with a persistent object. The row may have been
deleted, or in some cases the primary key updated
to a new value, outside of the ORM's management of the target
object.
"""
def __init__(self, state):
sa.exc.InvalidRequestError.__init__(
self,
"Instance '%s' has been deleted, or its "
"row is otherwise not present." % orm_util.state_str(state)
)
class UnmappedColumnError(sa.exc.InvalidRequestError):
"""Mapping operation was requested on an unknown column."""
class NoResultFound(sa.exc.InvalidRequestError):
"""A database result was required but none was found."""
class MultipleResultsFound(sa.exc.InvalidRequestError):
"""A single database result was required but more than one were found."""
# Legacy compat until 0.6.
sa.exc.ConcurrentModificationError = ConcurrentModificationError
sa.exc.FlushError = FlushError
sa.exc.UnmappedColumnError
def _safe_cls_name(cls):
try:
cls_name = '.'.join((cls.__module__, cls.__name__))
except AttributeError:
cls_name = getattr(cls, '__name__', None)
if cls_name is None:
cls_name = repr(cls)
return cls_name
def _default_unmapped(cls):
try:
mappers = sa.orm.attributes.manager_of_class(cls).mappers
except NO_STATE:
mappers = {}
except TypeError:
mappers = {}
name = _safe_cls_name(cls)
if not mappers:
return "Class '%s' is not mapped" % name
|
bsd-3-clause
|
[
3,
9813,
15,
2804,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
8128,
314,
14303,
11462,
436,
8417,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
4657,
12800,
23383,
4967,
1041,
199,
199,
646,
8335,
465,
2937,
199,
1025,
63,
1974,
275,
2937,
14,
1974,
14,
646,
18103,
360,
14536,
14,
1025,
297,
283,
1974,
358,
199,
199,
2826,
63,
6689,
275,
334,
10227,
12,
4067,
9,
199,
624,
1726,
2943,
626,
1443,
506,
4915,
701,
14498,
425,
12591,
1041,
199,
199,
533,
7083,
274,
1451,
547,
8,
2231,
14,
2804,
14,
4657,
12800,
547,
304,
272,
408,
2493,
3439,
14556,
3050,
1174,
626,
365,
625,
645,
3094,
471,
367,
14,
339,
1448,
3138,
1314,
7675,
642,
370,
5992,
2387,
26,
339,
627,
437,
8976,
1443,
1172,
22040,
370,
1678,
503,
3145,
4730,
489,
436,
376,
10537,
1329,
402,
4730,
4898,
7838,
5309,
15166,
314,
17148,
503,
15137,
5164,
14,
257,
3390,
626,
1380,
15166,
1015,
63,
344,
63,
761,
365,
1202,
12,
4730,
315,
17148,
503,
15137,
9834,
489,
787,
2597,
7838,
6169,
314,
1453,
6040,
1015,
489,
5148,
14,
339,
627,
437,
9994,
909,
543,
1015,
63,
344,
63,
761,
1990,
9236,
379,
12,
15166,
436,
314,
1015,
1329,
17262,
1771,
687,
314,
3050,
1630,
489,
440,
1336,
626,
402,
314,
909,
6337,
14,
2126,
272,
627,
437,
909,
365,
32348,
687,
2399,
1676,
909,
12,
13432,
489,
314,
909,
1990,
10889,
10102,
370,
282,
3365,
1676,
489,
8503,
1314,
1990,
17516,
13736,
12,
436,
282,
14692,
489,
3913,
506,
6326,
340,
314,
892,
1676,
1990,
7710,
314,
4750,
489,
8058,
298,
1708,
2,
334,
1222,
315,
378,
14,
23,
14,
20,
680,
339,
408,
199,
199,
714,
1818,
29188,
547,
275,
7083,
274,
1451,
547,
421,
199,
533,
11040,
2084,
547,
8,
2231,
14,
2804,
14,
4657,
12800,
547,
304,
272,
408,
33,
3866,
5558,
1990,
10501,
5309,
8976,
20693,
421,
199,
533,
1910,
11663,
547,
8,
2231,
14,
2804,
14,
26585,
304,
272,
408,
1563,
367,
4967,
626,
4572,
3344,
1420,
13546,
440,
3451,
1041,
199,
199,
533,
6935,
872,
22355,
547,
8,
2231,
14,
2804,
14,
4657,
12800,
547,
304,
272,
408,
2493,
3439,
3913,
4890,
7037,
370,
376,
909,
3769,
17516,
13736,
1041,
199,
199,
533,
577,
386,
4583,
3244,
547,
8,
2231,
14,
2804,
14,
4657,
12800,
547,
304,
272,
408,
2493,
7427,
370,
2879,
625,
4591,
3004,
641,
282,
5591,
9994,
1256,
626,
365,
32348,
1041,
199,
199,
533,
1910,
11663,
3244,
547,
8,
1358,
11663,
547,
304,
272,
408,
2493,
4412,
3439,
1990,
5839,
367,
376,
5809,
1256,
1041,
339,
347,
636,
826,
721,
277,
12,
1559,
12,
1499,
29,
403,
304,
267,
340,
440,
1499,
26,
288,
862,
26,
355,
7796,
275,
2937,
14,
1025,
14,
533,
63,
7153,
8,
466,
8,
1113,
430,
355,
536,
275,
485,
3489,
63,
1886,
63,
354,
8,
466,
8,
1113,
430,
355,
1499,
275,
1689,
2543,
450,
82,
365,
9994,
12,
1325,
642,
1256,
1127,
5618,
298,
2432,
298,
13321,
425,
14,
221,
961,
11058,
1380,
314,
1256,
365,
2737,
298,
2432,
298,
5182,
8335,
14,
1025,
14,
7153,
4042,
83,
9,
1990,
2797,
2122,
450,
334,
354,
12,
536,
430,
288,
871,
1910,
11663,
2543,
547,
26,
355,
1499,
275,
485,
885,
63,
324,
11663,
8,
466,
8,
1113,
430,
355,
340,
1228,
8,
1113,
12,
730,
304,
490,
1499,
847,
334,
717,
14289,
1990,
282,
1021,
4366,
83,
9,
6841,
2382,
376,
1256,
1990,
283,
717,
283,
2427,
14069,
450,
485,
3489,
63,
1886,
63,
354,
8,
1113,
430,
267,
1910,
11663,
547,
855,
826,
721,
277,
12,
1499,
9,
421,
199,
533,
1910,
11663,
2543,
547,
8,
1358,
11663,
547,
304,
272,
408,
2493,
4412,
3439,
1990,
5839,
367,
376,
5809,
1021,
1041,
339,
347,
636,
826,
721,
277,
12,
843,
12,
1499,
29,
403,
304,
267,
340,
440,
1499,
26,
288,
1499,
275,
485,
885,
63,
324,
11663,
8,
1886,
9,
267,
1910,
11663,
547,
855,
826,
721,
277,
12,
1499,
9,
421,
199,
533,
6935,
17735,
547,
8,
2231,
14,
2804,
14,
26585,
304,
272,
408,
33,
9236,
3439,
3405,
370,
8044,
314,
3050,
272,
1962,
5226,
370,
376,
909,
1159,
6040,
5062,
790,
8503,
14,
2286,
437,
9236,
3439,
557,
301,
5923,
1380,
376,
14721,
2225,
365,
5591,
13810,
641,
376,
909,
12,
503,
1380,
520,
5247,
5026,
3227,
14,
362,
64,
365,
272,
1202,
370,
8044,
376,
909,
1314,
365,
12,
12188,
27157,
12,
10501,
272,
465,
14721,
14,
257,
437,
10468,
365,
19515,
367,
314,
1347,
1962,
272,
4079,
641,
5062,
790,
27,
340,
949,
1962,
365,
2138,
12,
642,
272,
1919,
365,
4915,
14,
2286,
710,
2549,
11150,
402,
642,
1919,
365,
9329,
626,
5591,
949,
1962,
3495,
367,
314,
5062,
790,
5148,
4568,
272,
543,
282,
16149,
909,
14,
257,
710,
1962,
1443,
1172,
2757,
5591,
5463,
12,
503,
315,
2005,
5560,
314,
5062,
790,
4588,
272,
370,
282,
892,
574,
12,
9682,
402,
314,
23383,
1159,
10041,
402,
314,
1347,
272,
909,
14,
259,
2286,
408,
272,
347,
636,
826,
721,
277,
12,
1174,
304,
267,
2937,
14,
2804,
14,
26585,
855,
826,
721,
1467,
291,
12,
1467,
298,
3244,
1543,
83,
7,
965,
2757,
5463,
12,
503,
2399,
298,
1467,
298,
1143,
365,
4257,
440,
3451,
2122,
450,
9813,
63,
1974,
14,
929,
63,
495,
8,
929,
9,
267,
776,
199,
199,
533,
1910,
11663,
4547,
547,
8,
2231,
14,
2804,
14,
26585,
304,
272,
408,
7674,
3439,
1990,
5839,
641,
376,
5809,
2763,
1041,
421,
199,
533,
3091,
2889,
3601,
8,
2231,
14,
2804,
14,
26585,
304,
272,
408,
33,
3050,
754,
1990,
1415,
1325,
7179,
1990,
1911,
1041,
421,
199,
533,
14326,
6579,
3601,
8,
2231,
14,
2804,
14,
26585,
304,
272,
408,
33,
2849,
3050,
754,
1990,
1415,
1325,
1655,
2419,
1373,
4898,
1911,
1041,
421,
199,
3,
26251,
8434,
5133,
378,
14,
22,
14,
199,
2231,
14,
2804,
14,
714,
1818,
29188,
547,
275
] |
[
9813,
15,
2804,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
8128,
314,
14303,
11462,
436,
8417,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
4657,
12800,
23383,
4967,
1041,
199,
199,
646,
8335,
465,
2937,
199,
1025,
63,
1974,
275,
2937,
14,
1974,
14,
646,
18103,
360,
14536,
14,
1025,
297,
283,
1974,
358,
199,
199,
2826,
63,
6689,
275,
334,
10227,
12,
4067,
9,
199,
624,
1726,
2943,
626,
1443,
506,
4915,
701,
14498,
425,
12591,
1041,
199,
199,
533,
7083,
274,
1451,
547,
8,
2231,
14,
2804,
14,
4657,
12800,
547,
304,
272,
408,
2493,
3439,
14556,
3050,
1174,
626,
365,
625,
645,
3094,
471,
367,
14,
339,
1448,
3138,
1314,
7675,
642,
370,
5992,
2387,
26,
339,
627,
437,
8976,
1443,
1172,
22040,
370,
1678,
503,
3145,
4730,
489,
436,
376,
10537,
1329,
402,
4730,
4898,
7838,
5309,
15166,
314,
17148,
503,
15137,
5164,
14,
257,
3390,
626,
1380,
15166,
1015,
63,
344,
63,
761,
365,
1202,
12,
4730,
315,
17148,
503,
15137,
9834,
489,
787,
2597,
7838,
6169,
314,
1453,
6040,
1015,
489,
5148,
14,
339,
627,
437,
9994,
909,
543,
1015,
63,
344,
63,
761,
1990,
9236,
379,
12,
15166,
436,
314,
1015,
1329,
17262,
1771,
687,
314,
3050,
1630,
489,
440,
1336,
626,
402,
314,
909,
6337,
14,
2126,
272,
627,
437,
909,
365,
32348,
687,
2399,
1676,
909,
12,
13432,
489,
314,
909,
1990,
10889,
10102,
370,
282,
3365,
1676,
489,
8503,
1314,
1990,
17516,
13736,
12,
436,
282,
14692,
489,
3913,
506,
6326,
340,
314,
892,
1676,
1990,
7710,
314,
4750,
489,
8058,
298,
1708,
2,
334,
1222,
315,
378,
14,
23,
14,
20,
680,
339,
408,
199,
199,
714,
1818,
29188,
547,
275,
7083,
274,
1451,
547,
421,
199,
533,
11040,
2084,
547,
8,
2231,
14,
2804,
14,
4657,
12800,
547,
304,
272,
408,
33,
3866,
5558,
1990,
10501,
5309,
8976,
20693,
421,
199,
533,
1910,
11663,
547,
8,
2231,
14,
2804,
14,
26585,
304,
272,
408,
1563,
367,
4967,
626,
4572,
3344,
1420,
13546,
440,
3451,
1041,
199,
199,
533,
6935,
872,
22355,
547,
8,
2231,
14,
2804,
14,
4657,
12800,
547,
304,
272,
408,
2493,
3439,
3913,
4890,
7037,
370,
376,
909,
3769,
17516,
13736,
1041,
199,
199,
533,
577,
386,
4583,
3244,
547,
8,
2231,
14,
2804,
14,
4657,
12800,
547,
304,
272,
408,
2493,
7427,
370,
2879,
625,
4591,
3004,
641,
282,
5591,
9994,
1256,
626,
365,
32348,
1041,
199,
199,
533,
1910,
11663,
3244,
547,
8,
1358,
11663,
547,
304,
272,
408,
2493,
4412,
3439,
1990,
5839,
367,
376,
5809,
1256,
1041,
339,
347,
636,
826,
721,
277,
12,
1559,
12,
1499,
29,
403,
304,
267,
340,
440,
1499,
26,
288,
862,
26,
355,
7796,
275,
2937,
14,
1025,
14,
533,
63,
7153,
8,
466,
8,
1113,
430,
355,
536,
275,
485,
3489,
63,
1886,
63,
354,
8,
466,
8,
1113,
430,
355,
1499,
275,
1689,
2543,
450,
82,
365,
9994,
12,
1325,
642,
1256,
1127,
5618,
298,
2432,
298,
13321,
425,
14,
221,
961,
11058,
1380,
314,
1256,
365,
2737,
298,
2432,
298,
5182,
8335,
14,
1025,
14,
7153,
4042,
83,
9,
1990,
2797,
2122,
450,
334,
354,
12,
536,
430,
288,
871,
1910,
11663,
2543,
547,
26,
355,
1499,
275,
485,
885,
63,
324,
11663,
8,
466,
8,
1113,
430,
355,
340,
1228,
8,
1113,
12,
730,
304,
490,
1499,
847,
334,
717,
14289,
1990,
282,
1021,
4366,
83,
9,
6841,
2382,
376,
1256,
1990,
283,
717,
283,
2427,
14069,
450,
485,
3489,
63,
1886,
63,
354,
8,
1113,
430,
267,
1910,
11663,
547,
855,
826,
721,
277,
12,
1499,
9,
421,
199,
533,
1910,
11663,
2543,
547,
8,
1358,
11663,
547,
304,
272,
408,
2493,
4412,
3439,
1990,
5839,
367,
376,
5809,
1021,
1041,
339,
347,
636,
826,
721,
277,
12,
843,
12,
1499,
29,
403,
304,
267,
340,
440,
1499,
26,
288,
1499,
275,
485,
885,
63,
324,
11663,
8,
1886,
9,
267,
1910,
11663,
547,
855,
826,
721,
277,
12,
1499,
9,
421,
199,
533,
6935,
17735,
547,
8,
2231,
14,
2804,
14,
26585,
304,
272,
408,
33,
9236,
3439,
3405,
370,
8044,
314,
3050,
272,
1962,
5226,
370,
376,
909,
1159,
6040,
5062,
790,
8503,
14,
2286,
437,
9236,
3439,
557,
301,
5923,
1380,
376,
14721,
2225,
365,
5591,
13810,
641,
376,
909,
12,
503,
1380,
520,
5247,
5026,
3227,
14,
362,
64,
365,
272,
1202,
370,
8044,
376,
909,
1314,
365,
12,
12188,
27157,
12,
10501,
272,
465,
14721,
14,
257,
437,
10468,
365,
19515,
367,
314,
1347,
1962,
272,
4079,
641,
5062,
790,
27,
340,
949,
1962,
365,
2138,
12,
642,
272,
1919,
365,
4915,
14,
2286,
710,
2549,
11150,
402,
642,
1919,
365,
9329,
626,
5591,
949,
1962,
3495,
367,
314,
5062,
790,
5148,
4568,
272,
543,
282,
16149,
909,
14,
257,
710,
1962,
1443,
1172,
2757,
5591,
5463,
12,
503,
315,
2005,
5560,
314,
5062,
790,
4588,
272,
370,
282,
892,
574,
12,
9682,
402,
314,
23383,
1159,
10041,
402,
314,
1347,
272,
909,
14,
259,
2286,
408,
272,
347,
636,
826,
721,
277,
12,
1174,
304,
267,
2937,
14,
2804,
14,
26585,
855,
826,
721,
1467,
291,
12,
1467,
298,
3244,
1543,
83,
7,
965,
2757,
5463,
12,
503,
2399,
298,
1467,
298,
1143,
365,
4257,
440,
3451,
2122,
450,
9813,
63,
1974,
14,
929,
63,
495,
8,
929,
9,
267,
776,
199,
199,
533,
1910,
11663,
4547,
547,
8,
2231,
14,
2804,
14,
26585,
304,
272,
408,
7674,
3439,
1990,
5839,
641,
376,
5809,
2763,
1041,
421,
199,
533,
3091,
2889,
3601,
8,
2231,
14,
2804,
14,
26585,
304,
272,
408,
33,
3050,
754,
1990,
1415,
1325,
7179,
1990,
1911,
1041,
421,
199,
533,
14326,
6579,
3601,
8,
2231,
14,
2804,
14,
26585,
304,
272,
408,
33,
2849,
3050,
754,
1990,
1415,
1325,
1655,
2419,
1373,
4898,
1911,
1041,
421,
199,
3,
26251,
8434,
5133,
378,
14,
22,
14,
199,
2231,
14,
2804,
14,
714,
1818,
29188,
547,
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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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
] |
jralls/gramps
|
gramps/gen/merge/mergeplacequery.py
|
10
|
3939
|
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2010 Michiel D. Nauta
#
# 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.
#
"""
Provide merge capabilities for places.
"""
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
from ..lib import Person, Family, Event, Place
from ..db import DbTxn
from ..const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext
from ..errors import MergeError
#-------------------------------------------------------------------------
#
# MergePlaceQuery
#
#-------------------------------------------------------------------------
class MergePlaceQuery:
"""
Create database query to merge two places.
"""
def __init__(self, dbstate, phoenix, titanic):
self.database = dbstate.db
self.phoenix = phoenix
self.titanic = titanic
def execute(self):
"""
Merges to places into a single place.
"""
new_handle = self.phoenix.get_handle()
old_handle = self.titanic.get_handle()
self.phoenix.merge(self.titanic)
with DbTxn(_("Merge Places"), self.database) as trans:
self.database.commit_place(self.phoenix, trans)
for (class_name, handle) in self.database.find_backlink_handles(
old_handle):
if class_name == Person.__name__:
person = self.database.get_person_from_handle(handle)
assert(person.has_handle_reference('Place', old_handle))
person.replace_handle_reference('Place', old_handle,
new_handle)
self.database.commit_person(person, trans)
elif class_name == Family.__name__:
family = self.database.get_family_from_handle(handle)
assert(family.has_handle_reference('Place', old_handle))
family.replace_handle_reference('Place', old_handle,
new_handle)
self.database.commit_family(family, trans)
elif class_name == Event.__name__:
event = self.database.get_event_from_handle(handle)
assert(event.has_handle_reference('Place', old_handle))
event.replace_handle_reference('Place', old_handle,
new_handle)
self.database.commit_event(event, trans)
elif class_name == Place.__name__:
place = self.database.get_place_from_handle(handle)
assert(place.has_handle_reference('Place', old_handle))
place.replace_handle_reference('Place', old_handle,
new_handle)
self.database.commit_place(place, trans)
else:
raise MergeError("Encounter an object of type %s that has "
"a place reference." % class_name)
self.database.remove_place(old_handle, trans)
|
gpl-2.0
|
[
3,
199,
3,
10268,
13408,
446,
282,
598,
15263,
19616,
39,
2826,
3635,
4079,
15599,
2548,
89,
2240,
199,
3,
199,
3,
1898,
334,
35,
9,
12293,
13,
9488,
221,
7529,
27075,
653,
14,
2900,
316,
10670,
199,
3,
1898,
334,
35,
9,
7129,
755,
603,
1158,
14769,
577,
14,
653,
6898,
65,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
199,
199,
624,
199,
25107,
5389,
14918,
367,
9825,
14,
199,
624,
199,
199,
25812,
199,
3,
199,
3,
10268,
13408,
4621,
199,
3,
199,
25812,
199,
504,
2508,
773,
492,
8028,
12,
481,
4632,
12,
6763,
12,
10902,
199,
504,
2508,
697,
492,
28822,
52,
5032,
199,
504,
2508,
1297,
492,
21772,
1156,
5067,
63,
20828,
465,
486,
5508,
199,
63,
275,
486,
5508,
14,
6893,
14,
83,
5152,
199,
504,
2508,
2550,
492,
14076,
547,
199,
199,
25812,
199,
3,
199,
3,
14076,
11613,
3227,
199,
3,
199,
25812,
199,
533,
14076,
11613,
3227,
26,
272,
408,
272,
2790,
3050,
1827,
370,
5389,
2877,
9825,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1592,
929,
12,
299,
526,
287,
1148,
12,
3367,
12990,
530,
304,
267,
291,
14,
4659,
275,
1592,
929,
14,
697,
267,
291,
14,
21936,
287,
1148,
275,
299,
526,
287,
1148,
267,
291,
14,
6403,
290,
530,
275,
3367,
12990,
530,
339,
347,
5341,
8,
277,
304,
267,
408,
267,
18880,
3389,
370,
9825,
1901,
282,
2849,
4192,
14,
267,
408,
267,
892,
63,
2479,
275,
291,
14,
21936,
287,
1148,
14,
362,
63,
2479,
342,
267,
2269,
63,
2479,
275,
291,
14,
6403,
290,
530,
14,
362,
63,
2479,
342,
398,
291,
14,
21936,
287,
1148,
14,
5628,
8,
277,
14,
6403,
290,
530,
9,
398,
543,
28822,
52,
5032,
6115,
11359,
510,
5862,
1288,
291,
14,
4659,
9,
465,
1752,
26,
288,
291,
14,
4659,
14,
3543,
63,
2778,
8,
277,
14,
21936,
287,
1148,
12,
1752,
9,
288,
367,
334,
533,
63,
354,
12,
2429,
9,
315,
291,
14,
4659,
14,
1623,
63,
894,
1073,
63,
16947,
8,
490,
2269,
63,
2479,
304,
355,
340,
1021,
63,
354,
508,
8028,
855,
354,
10651,
490,
4954,
275,
291,
14,
4659,
14,
362,
63,
5484,
63,
504,
63,
2479,
8,
2479,
9,
490,
702,
8,
5484,
14,
1989,
63,
2479,
63,
4443,
360,
11613,
297,
2269,
63,
2479,
430,
490,
4954,
14,
1814,
63,
2479,
63,
4443,
360,
11613,
297,
2269,
63,
2479,
12,
8105,
892,
63,
2479,
9,
490,
291,
14,
4659,
14,
3543,
63,
5484,
8,
5484,
12,
1752,
9,
355,
916,
1021,
63,
354,
508,
481,
4632,
855,
354,
10651,
490,
9614,
275,
291,
14,
4659,
14,
362,
63,
6606,
63,
504,
63,
2479,
8,
2479,
9,
490,
702,
8,
6606,
14,
1989,
63,
2479,
63,
4443,
360,
11613,
297,
2269,
63,
2479,
430,
490,
9614,
14,
1814,
63,
2479,
63,
4443,
360,
11613,
297,
2269,
63,
2479,
12,
8105,
892,
63,
2479,
9,
490,
291,
14,
4659,
14,
3543,
63,
6606,
8,
6606,
12,
1752,
9,
355,
916,
1021,
63,
354,
508,
6763,
855,
354,
10651,
490,
1566,
275,
291,
14,
4659,
14,
362,
63,
1430,
63,
504,
63,
2479,
8,
2479,
9,
490,
702,
8,
1430,
14,
1989,
63,
2479,
63,
4443,
360,
11613,
297,
2269,
63,
2479,
430,
490,
1566,
14,
1814,
63,
2479,
63,
4443,
360,
11613,
297,
2269,
63,
2479,
12,
8962,
892,
63,
2479,
9,
490,
291,
14,
4659,
14,
3543,
63,
1430,
8,
1430,
12,
1752,
9,
355,
916,
1021,
63,
354,
508,
10902,
855,
354,
10651,
490,
4192,
275,
291,
14,
4659,
14,
362,
63,
2778,
63,
504,
63,
2479,
8,
2479,
9,
490,
702,
8,
2778,
14,
1989,
63,
2479,
63,
4443,
360,
11613,
297,
2269,
63,
2479,
430,
490,
4192,
14,
1814,
63,
2479,
63,
4443,
360,
11613,
297,
2269,
63,
2479,
12,
8962,
892,
63,
2479,
9,
490,
291,
14,
4659,
14,
3543,
63,
2778,
8,
2778,
12,
1752,
9,
355,
587,
26,
490,
746,
14076,
547,
480,
1327,
5337,
376,
909,
402,
730,
450,
83,
626,
965,
298,
1169,
298,
65,
4192,
3659,
2122,
450,
1021,
63,
354,
9,
288,
291,
14,
4659,
14,
2168,
63,
2778,
8,
1753,
63,
2479,
12,
1752,
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
] |
[
199,
3,
10268,
13408,
446,
282,
598,
15263,
19616,
39,
2826,
3635,
4079,
15599,
2548,
89,
2240,
199,
3,
199,
3,
1898,
334,
35,
9,
12293,
13,
9488,
221,
7529,
27075,
653,
14,
2900,
316,
10670,
199,
3,
1898,
334,
35,
9,
7129,
755,
603,
1158,
14769,
577,
14,
653,
6898,
65,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
199,
199,
624,
199,
25107,
5389,
14918,
367,
9825,
14,
199,
624,
199,
199,
25812,
199,
3,
199,
3,
10268,
13408,
4621,
199,
3,
199,
25812,
199,
504,
2508,
773,
492,
8028,
12,
481,
4632,
12,
6763,
12,
10902,
199,
504,
2508,
697,
492,
28822,
52,
5032,
199,
504,
2508,
1297,
492,
21772,
1156,
5067,
63,
20828,
465,
486,
5508,
199,
63,
275,
486,
5508,
14,
6893,
14,
83,
5152,
199,
504,
2508,
2550,
492,
14076,
547,
199,
199,
25812,
199,
3,
199,
3,
14076,
11613,
3227,
199,
3,
199,
25812,
199,
533,
14076,
11613,
3227,
26,
272,
408,
272,
2790,
3050,
1827,
370,
5389,
2877,
9825,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1592,
929,
12,
299,
526,
287,
1148,
12,
3367,
12990,
530,
304,
267,
291,
14,
4659,
275,
1592,
929,
14,
697,
267,
291,
14,
21936,
287,
1148,
275,
299,
526,
287,
1148,
267,
291,
14,
6403,
290,
530,
275,
3367,
12990,
530,
339,
347,
5341,
8,
277,
304,
267,
408,
267,
18880,
3389,
370,
9825,
1901,
282,
2849,
4192,
14,
267,
408,
267,
892,
63,
2479,
275,
291,
14,
21936,
287,
1148,
14,
362,
63,
2479,
342,
267,
2269,
63,
2479,
275,
291,
14,
6403,
290,
530,
14,
362,
63,
2479,
342,
398,
291,
14,
21936,
287,
1148,
14,
5628,
8,
277,
14,
6403,
290,
530,
9,
398,
543,
28822,
52,
5032,
6115,
11359,
510,
5862,
1288,
291,
14,
4659,
9,
465,
1752,
26,
288,
291,
14,
4659,
14,
3543,
63,
2778,
8,
277,
14,
21936,
287,
1148,
12,
1752,
9,
288,
367,
334,
533,
63,
354,
12,
2429,
9,
315,
291,
14,
4659,
14,
1623,
63,
894,
1073,
63,
16947,
8,
490,
2269,
63,
2479,
304,
355,
340,
1021,
63,
354,
508,
8028,
855,
354,
10651,
490,
4954,
275,
291,
14,
4659,
14,
362,
63,
5484,
63,
504,
63,
2479,
8,
2479,
9,
490,
702,
8,
5484,
14,
1989,
63,
2479,
63,
4443,
360,
11613,
297,
2269,
63,
2479,
430,
490,
4954,
14,
1814,
63,
2479,
63,
4443,
360,
11613,
297,
2269,
63,
2479,
12,
8105,
892,
63,
2479,
9,
490,
291,
14,
4659,
14,
3543,
63,
5484,
8,
5484,
12,
1752,
9,
355,
916,
1021,
63,
354,
508,
481,
4632,
855,
354,
10651,
490,
9614,
275,
291,
14,
4659,
14,
362,
63,
6606,
63,
504,
63,
2479,
8,
2479,
9,
490,
702,
8,
6606,
14,
1989,
63,
2479,
63,
4443,
360,
11613,
297,
2269,
63,
2479,
430,
490,
9614,
14,
1814,
63,
2479,
63,
4443,
360,
11613,
297,
2269,
63,
2479,
12,
8105,
892,
63,
2479,
9,
490,
291,
14,
4659,
14,
3543,
63,
6606,
8,
6606,
12,
1752,
9,
355,
916,
1021,
63,
354,
508,
6763,
855,
354,
10651,
490,
1566,
275,
291,
14,
4659,
14,
362,
63,
1430,
63,
504,
63,
2479,
8,
2479,
9,
490,
702,
8,
1430,
14,
1989,
63,
2479,
63,
4443,
360,
11613,
297,
2269,
63,
2479,
430,
490,
1566,
14,
1814,
63,
2479,
63,
4443,
360,
11613,
297,
2269,
63,
2479,
12,
8962,
892,
63,
2479,
9,
490,
291,
14,
4659,
14,
3543,
63,
1430,
8,
1430,
12,
1752,
9,
355,
916,
1021,
63,
354,
508,
10902,
855,
354,
10651,
490,
4192,
275,
291,
14,
4659,
14,
362,
63,
2778,
63,
504,
63,
2479,
8,
2479,
9,
490,
702,
8,
2778,
14,
1989,
63,
2479,
63,
4443,
360,
11613,
297,
2269,
63,
2479,
430,
490,
4192,
14,
1814,
63,
2479,
63,
4443,
360,
11613,
297,
2269,
63,
2479,
12,
8962,
892,
63,
2479,
9,
490,
291,
14,
4659,
14,
3543,
63,
2778,
8,
2778,
12,
1752,
9,
355,
587,
26,
490,
746,
14076,
547,
480,
1327,
5337,
376,
909,
402,
730,
450,
83,
626,
965,
298,
1169,
298,
65,
4192,
3659,
2122,
450,
1021,
63,
354,
9,
288,
291,
14,
4659,
14,
2168,
63,
2778,
8,
1753,
63,
2479,
12,
1752,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
AutorestCI/azure-sdk-for-python
|
azure-mgmt-network/azure/mgmt/network/v2017_09_01/models/application_gateway_url_path_map.py
|
1
|
3397
|
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from .sub_resource import SubResource
class ApplicationGatewayUrlPathMap(SubResource):
"""UrlPathMaps give a url path to the backend mapping information for
PathBasedRouting.
:param id: Resource ID.
:type id: str
:param default_backend_address_pool: Default backend address pool resource
of URL path map.
:type default_backend_address_pool:
~azure.mgmt.network.v2017_09_01.models.SubResource
:param default_backend_http_settings: Default backend http settings
resource of URL path map.
:type default_backend_http_settings:
~azure.mgmt.network.v2017_09_01.models.SubResource
:param default_redirect_configuration: Default redirect configuration
resource of URL path map.
:type default_redirect_configuration:
~azure.mgmt.network.v2017_09_01.models.SubResource
:param path_rules: Path rule of URL path map resource.
:type path_rules:
list[~azure.mgmt.network.v2017_09_01.models.ApplicationGatewayPathRule]
:param provisioning_state: Provisioning state of the backend http settings
resource. Possible values are: 'Updating', 'Deleting', and 'Failed'.
:type provisioning_state: str
:param name: Name of the resource that is unique within a resource group.
This name can be used to access the resource.
:type name: str
:param etag: A unique read-only string that changes whenever the resource
is updated.
:type etag: str
:param type: Type of the resource.
:type type: str
"""
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'default_backend_address_pool': {'key': 'properties.defaultBackendAddressPool', 'type': 'SubResource'},
'default_backend_http_settings': {'key': 'properties.defaultBackendHttpSettings', 'type': 'SubResource'},
'default_redirect_configuration': {'key': 'properties.defaultRedirectConfiguration', 'type': 'SubResource'},
'path_rules': {'key': 'properties.pathRules', 'type': '[ApplicationGatewayPathRule]'},
'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'},
'name': {'key': 'name', 'type': 'str'},
'etag': {'key': 'etag', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
}
def __init__(self, id=None, default_backend_address_pool=None, default_backend_http_settings=None, default_redirect_configuration=None, path_rules=None, provisioning_state=None, name=None, etag=None, type=None):
super(ApplicationGatewayUrlPathMap, self).__init__(id=id)
self.default_backend_address_pool = default_backend_address_pool
self.default_backend_http_settings = default_backend_http_settings
self.default_redirect_configuration = default_redirect_configuration
self.path_rules = path_rules
self.provisioning_state = provisioning_state
self.name = name
self.etag = etag
self.type = type
|
mit
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
24775,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
199,
3,
4190,
2556,
14,
199,
3,
199,
3,
5495,
4046,
701,
15332,
334,
50,
9,
9195,
13726,
5495,
15042,
14,
199,
3,
18784,
1443,
7675,
8927,
5953,
436,
911,
506,
14669,
340,
314,
1233,
365,
199,
3,
31904,
14,
199,
3,
24775,
199,
199,
504,
1275,
954,
63,
1927,
492,
4804,
4031,
421,
199,
533,
13515,
12455,
6417,
2042,
2956,
8,
2610,
4031,
304,
272,
408,
6417,
2042,
24995,
8120,
282,
1166,
931,
370,
314,
4865,
4412,
2556,
367,
272,
6912,
20409,
8056,
14,
339,
520,
635,
1305,
26,
7337,
2870,
14,
272,
520,
466,
1305,
26,
620,
272,
520,
635,
849,
63,
4620,
63,
1562,
63,
2293,
26,
3758,
4865,
2287,
4203,
2073,
1362,
402,
2851,
931,
2341,
14,
272,
520,
466,
849,
63,
4620,
63,
1562,
63,
2293,
26,
1362,
6146,
9078,
14,
9752,
14,
1200,
14,
86,
10680,
63,
1643,
63,
614,
14,
992,
14,
2610,
4031,
272,
520,
635,
849,
63,
4620,
63,
1014,
63,
1751,
26,
3758,
4865,
1455,
2202,
1362,
2073,
402,
2851,
931,
2341,
14,
272,
520,
466,
849,
63,
4620,
63,
1014,
63,
1751,
26,
1362,
6146,
9078,
14,
9752,
14,
1200,
14,
86,
10680,
63,
1643,
63,
614,
14,
992,
14,
2610,
4031,
272,
520,
635,
849,
63,
4876,
63,
4758,
26,
3758,
4660,
2897,
1362,
2073,
402,
2851,
931,
2341,
14,
272,
520,
466,
849,
63,
4876,
63,
4758,
26,
1362,
6146,
9078,
14,
9752,
14,
1200,
14,
86,
10680,
63,
1643,
63,
614,
14,
992,
14,
2610,
4031,
272,
520,
635,
931,
63,
4423,
26,
6912,
2332,
402,
2851,
931,
2341,
2073,
14,
272,
520,
466,
931,
63,
4423,
26,
1362,
769,
19911,
9078,
14,
9752,
14,
1200,
14,
86,
10680,
63,
1643,
63,
614,
14,
992,
14,
5039,
12455,
2042,
5065,
61,
272,
520,
635,
20118,
63,
929,
26,
2165,
2317,
316,
1174,
402,
314,
4865,
1455,
2202,
1362,
2073,
14,
18558,
1338,
787,
26,
283,
24993,
297,
283,
22001,
297,
436,
283,
4276,
1370,
272,
520,
466,
20118,
63,
929,
26,
620,
272,
520,
635,
536,
26,
2812,
402,
314,
2073,
626,
365,
3747,
4453,
282,
2073,
1572,
14,
1362,
961,
536,
883,
506,
1202,
370,
2879,
314,
2073,
14,
272,
520,
466,
536,
26,
620,
272,
520,
635,
13677,
26,
437,
3747,
1586,
13,
2118,
1059,
626,
4493,
18119,
314,
2073,
1362,
365,
4588,
14,
272,
520,
466,
13677,
26,
620,
272,
520,
635,
730,
26,
2434,
402,
314,
2073,
14,
272,
520,
466,
730,
26,
620,
272,
408,
339,
485,
3215,
63,
1130,
275,
469,
267,
283,
344,
356,
791,
498,
356,
283,
344,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
885,
63,
4620,
63,
1562,
63,
2293,
356,
791,
498,
356,
283,
3282,
14,
885,
8447,
1476,
5453,
297,
283,
466,
356,
283,
2610,
4031,
2267,
267,
283,
885,
63,
4620,
63,
1014,
63,
1751,
356,
791,
498,
356,
283,
3282,
14,
885,
8447,
5779,
5268,
297,
283,
466,
356,
283,
2610,
4031,
2267,
267,
283,
885,
63,
4876,
63,
4758,
356,
791,
498,
356,
283,
3282,
14,
885,
7071,
5688,
297,
283,
466,
356,
283,
2610,
4031,
2267,
267,
283,
515,
63,
4423,
356,
791,
498,
356,
283,
3282,
14,
515,
12920,
297,
283,
466,
356,
6730,
5039,
12455,
2042,
5065,
30375,
267,
283,
19639,
63,
929,
356,
791,
498,
356,
283,
3282,
14,
19639,
2223,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
354,
356,
791,
498,
356,
283,
354,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
11304,
356,
791,
498,
356,
283,
11304,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
466,
356,
791,
498,
356,
283,
466,
297,
283,
466,
356,
283,
495,
2267,
272,
789,
339,
347,
636,
826,
721,
277,
12,
1305,
29,
403,
12,
849,
63,
4620,
63,
1562,
63,
2293,
29,
403,
12,
849,
63,
4620,
63,
1014,
63,
1751,
29,
403,
12,
849,
63,
4876,
63,
4758,
29,
403,
12,
931,
63,
4423,
29,
403,
12,
20118,
63,
929,
29,
403,
12,
536,
29,
403,
12,
13677,
29,
403,
12,
730,
29,
403,
304,
267,
1613,
8,
5039,
12455,
6417,
2042,
2956,
12,
291,
2843,
826,
721,
344,
29,
344,
9,
267,
291,
14,
885,
63,
4620,
63,
1562,
63,
2293,
275,
849,
63,
4620,
63,
1562,
63,
2293,
267,
291,
14,
885,
63,
4620,
63,
1014,
63,
1751,
275,
849,
63,
4620,
63,
1014,
63,
1751,
267,
291,
14,
885,
63,
4876,
63,
4758,
275,
849,
63,
4876,
63,
4758,
267,
291,
14,
515,
63,
4423,
275,
931,
63,
4423,
267,
291,
14,
19639,
63,
929,
275,
20118,
63,
929,
267,
291,
14,
354,
275,
536,
267,
291,
14,
11304,
275,
13677,
267,
291,
14,
466,
275,
730,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
29,
1624,
13,
24,
199,
3,
24775,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
199,
3,
4190,
2556,
14,
199,
3,
199,
3,
5495,
4046,
701,
15332,
334,
50,
9,
9195,
13726,
5495,
15042,
14,
199,
3,
18784,
1443,
7675,
8927,
5953,
436,
911,
506,
14669,
340,
314,
1233,
365,
199,
3,
31904,
14,
199,
3,
24775,
199,
199,
504,
1275,
954,
63,
1927,
492,
4804,
4031,
421,
199,
533,
13515,
12455,
6417,
2042,
2956,
8,
2610,
4031,
304,
272,
408,
6417,
2042,
24995,
8120,
282,
1166,
931,
370,
314,
4865,
4412,
2556,
367,
272,
6912,
20409,
8056,
14,
339,
520,
635,
1305,
26,
7337,
2870,
14,
272,
520,
466,
1305,
26,
620,
272,
520,
635,
849,
63,
4620,
63,
1562,
63,
2293,
26,
3758,
4865,
2287,
4203,
2073,
1362,
402,
2851,
931,
2341,
14,
272,
520,
466,
849,
63,
4620,
63,
1562,
63,
2293,
26,
1362,
6146,
9078,
14,
9752,
14,
1200,
14,
86,
10680,
63,
1643,
63,
614,
14,
992,
14,
2610,
4031,
272,
520,
635,
849,
63,
4620,
63,
1014,
63,
1751,
26,
3758,
4865,
1455,
2202,
1362,
2073,
402,
2851,
931,
2341,
14,
272,
520,
466,
849,
63,
4620,
63,
1014,
63,
1751,
26,
1362,
6146,
9078,
14,
9752,
14,
1200,
14,
86,
10680,
63,
1643,
63,
614,
14,
992,
14,
2610,
4031,
272,
520,
635,
849,
63,
4876,
63,
4758,
26,
3758,
4660,
2897,
1362,
2073,
402,
2851,
931,
2341,
14,
272,
520,
466,
849,
63,
4876,
63,
4758,
26,
1362,
6146,
9078,
14,
9752,
14,
1200,
14,
86,
10680,
63,
1643,
63,
614,
14,
992,
14,
2610,
4031,
272,
520,
635,
931,
63,
4423,
26,
6912,
2332,
402,
2851,
931,
2341,
2073,
14,
272,
520,
466,
931,
63,
4423,
26,
1362,
769,
19911,
9078,
14,
9752,
14,
1200,
14,
86,
10680,
63,
1643,
63,
614,
14,
992,
14,
5039,
12455,
2042,
5065,
61,
272,
520,
635,
20118,
63,
929,
26,
2165,
2317,
316,
1174,
402,
314,
4865,
1455,
2202,
1362,
2073,
14,
18558,
1338,
787,
26,
283,
24993,
297,
283,
22001,
297,
436,
283,
4276,
1370,
272,
520,
466,
20118,
63,
929,
26,
620,
272,
520,
635,
536,
26,
2812,
402,
314,
2073,
626,
365,
3747,
4453,
282,
2073,
1572,
14,
1362,
961,
536,
883,
506,
1202,
370,
2879,
314,
2073,
14,
272,
520,
466,
536,
26,
620,
272,
520,
635,
13677,
26,
437,
3747,
1586,
13,
2118,
1059,
626,
4493,
18119,
314,
2073,
1362,
365,
4588,
14,
272,
520,
466,
13677,
26,
620,
272,
520,
635,
730,
26,
2434,
402,
314,
2073,
14,
272,
520,
466,
730,
26,
620,
272,
408,
339,
485,
3215,
63,
1130,
275,
469,
267,
283,
344,
356,
791,
498,
356,
283,
344,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
885,
63,
4620,
63,
1562,
63,
2293,
356,
791,
498,
356,
283,
3282,
14,
885,
8447,
1476,
5453,
297,
283,
466,
356,
283,
2610,
4031,
2267,
267,
283,
885,
63,
4620,
63,
1014,
63,
1751,
356,
791,
498,
356,
283,
3282,
14,
885,
8447,
5779,
5268,
297,
283,
466,
356,
283,
2610,
4031,
2267,
267,
283,
885,
63,
4876,
63,
4758,
356,
791,
498,
356,
283,
3282,
14,
885,
7071,
5688,
297,
283,
466,
356,
283,
2610,
4031,
2267,
267,
283,
515,
63,
4423,
356,
791,
498,
356,
283,
3282,
14,
515,
12920,
297,
283,
466,
356,
6730,
5039,
12455,
2042,
5065,
30375,
267,
283,
19639,
63,
929,
356,
791,
498,
356,
283,
3282,
14,
19639,
2223,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
354,
356,
791,
498,
356,
283,
354,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
11304,
356,
791,
498,
356,
283,
11304,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
466,
356,
791,
498,
356,
283,
466,
297,
283,
466,
356,
283,
495,
2267,
272,
789,
339,
347,
636,
826,
721,
277,
12,
1305,
29,
403,
12,
849,
63,
4620,
63,
1562,
63,
2293,
29,
403,
12,
849,
63,
4620,
63,
1014,
63,
1751,
29,
403,
12,
849,
63,
4876,
63,
4758,
29,
403,
12,
931,
63,
4423,
29,
403,
12,
20118,
63,
929,
29,
403,
12,
536,
29,
403,
12,
13677,
29,
403,
12,
730,
29,
403,
304,
267,
1613,
8,
5039,
12455,
6417,
2042,
2956,
12,
291,
2843,
826,
721,
344,
29,
344,
9,
267,
291,
14,
885,
63,
4620,
63,
1562,
63,
2293,
275,
849,
63,
4620,
63,
1562,
63,
2293,
267,
291,
14,
885,
63,
4620,
63,
1014,
63,
1751,
275,
849,
63,
4620,
63,
1014,
63,
1751,
267,
291,
14,
885,
63,
4876,
63,
4758,
275,
849,
63,
4876,
63,
4758,
267,
291,
14,
515,
63,
4423,
275,
931,
63,
4423,
267,
291,
14,
19639,
63,
929,
275,
20118,
63,
929,
267,
291,
14,
354,
275,
536,
267,
291,
14,
11304,
275,
13677,
267,
291,
14,
466,
275,
730,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
knych/u-boot-sunxi
|
tools/patman/get_maintainer.py
|
38
|
1977
|
# Copyright (c) 2012 The Chromium OS Authors.
#
# See file CREDITS for list of people who contributed to this
# project.
#
# 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., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
import command
import gitutil
import os
def FindGetMaintainer():
"""Look for the get_maintainer.pl script.
Returns:
If the script is found we'll return a path to it; else None.
"""
try_list = [
os.path.join(gitutil.GetTopLevel(), 'scripts'),
]
# Look in the list
for path in try_list:
fname = os.path.join(path, 'get_maintainer.pl')
if os.path.isfile(fname):
return fname
return None
def GetMaintainer(fname, verbose=False):
"""Run get_maintainer.pl on a file if we find it.
We look for get_maintainer.pl in the 'scripts' directory at the top of
git. If we find it we'll run it. If we don't find get_maintainer.pl
then we fail silently.
Args:
fname: Path to the patch file to run get_maintainer.pl on.
Returns:
A list of email addresses to CC to.
"""
get_maintainer = FindGetMaintainer()
if not get_maintainer:
if verbose:
print "WARNING: Couldn't find get_maintainer.pl"
return []
stdout = command.Output(get_maintainer, '--norolestats', fname)
return stdout.splitlines()
|
gpl-2.0
|
[
3,
1898,
334,
67,
9,
6029,
710,
12051,
4403,
6642,
14,
199,
3,
199,
3,
1666,
570,
15654,
3841,
51,
367,
769,
402,
13135,
3963,
406,
24855,
370,
642,
199,
3,
2199,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
199,
3,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
199,
3,
4828,
15673,
13,
13421,
8217,
199,
3,
199,
199,
646,
1414,
199,
646,
6135,
1974,
199,
646,
747,
199,
199,
318,
6668,
1002,
11903,
8368,
281,
837,
272,
408,
20926,
367,
314,
664,
63,
26665,
14,
1168,
2884,
14,
339,
1803,
26,
267,
982,
314,
2884,
365,
1911,
781,
7171,
372,
282,
931,
370,
652,
27,
587,
488,
14,
272,
408,
272,
862,
63,
513,
275,
359,
267,
747,
14,
515,
14,
904,
8,
3187,
1974,
14,
1002,
6105,
4670,
1062,
283,
6429,
659,
267,
1622,
272,
327,
12077,
315,
314,
769,
272,
367,
931,
315,
862,
63,
513,
26,
267,
6748,
275,
747,
14,
515,
14,
904,
8,
515,
12,
283,
362,
63,
26665,
14,
1168,
358,
267,
340,
747,
14,
515,
14,
6292,
8,
5252,
304,
288,
372,
6748,
339,
372,
488,
199,
199,
318,
2372,
11903,
8368,
281,
8,
5252,
12,
3376,
29,
797,
304,
272,
408,
2540,
664,
63,
26665,
14,
1168,
641,
282,
570,
340,
781,
2342,
652,
14,
339,
2136,
3648,
367,
664,
63,
26665,
14,
1168,
315,
314,
283,
6429,
7,
2082,
737,
314,
2746,
402,
272,
6135,
14,
221,
982,
781,
2342,
652,
781,
7171,
1255,
652,
14,
221,
982,
781,
2793,
1133,
2342,
664,
63,
26665,
14,
1168,
272,
2066,
781,
2449,
18030,
14,
339,
3033,
26,
267,
6748,
26,
6912,
370,
314,
3371,
570,
370,
1255,
664,
63,
26665,
14,
1168,
641,
14,
339,
1803,
26,
267,
437,
769,
402,
3031,
7149,
370,
17586,
370,
14,
272,
408,
272,
664,
63,
26665,
275,
6668,
1002,
11903,
8368,
281,
342,
272,
340,
440,
664,
63,
26665,
26,
267,
340,
3376,
26,
288,
870,
298,
9171,
26,
18615,
78,
1133,
2342,
664,
63,
26665,
14,
1168,
2,
267,
372,
942,
339,
3839,
275,
1414,
14,
2959,
8,
362,
63,
26665,
12,
2850,
6505,
16721,
3200,
297,
6748,
9,
272,
372,
3839,
14,
7644,
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
] |
[
1898,
334,
67,
9,
6029,
710,
12051,
4403,
6642,
14,
199,
3,
199,
3,
1666,
570,
15654,
3841,
51,
367,
769,
402,
13135,
3963,
406,
24855,
370,
642,
199,
3,
2199,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
199,
3,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
199,
3,
4828,
15673,
13,
13421,
8217,
199,
3,
199,
199,
646,
1414,
199,
646,
6135,
1974,
199,
646,
747,
199,
199,
318,
6668,
1002,
11903,
8368,
281,
837,
272,
408,
20926,
367,
314,
664,
63,
26665,
14,
1168,
2884,
14,
339,
1803,
26,
267,
982,
314,
2884,
365,
1911,
781,
7171,
372,
282,
931,
370,
652,
27,
587,
488,
14,
272,
408,
272,
862,
63,
513,
275,
359,
267,
747,
14,
515,
14,
904,
8,
3187,
1974,
14,
1002,
6105,
4670,
1062,
283,
6429,
659,
267,
1622,
272,
327,
12077,
315,
314,
769,
272,
367,
931,
315,
862,
63,
513,
26,
267,
6748,
275,
747,
14,
515,
14,
904,
8,
515,
12,
283,
362,
63,
26665,
14,
1168,
358,
267,
340,
747,
14,
515,
14,
6292,
8,
5252,
304,
288,
372,
6748,
339,
372,
488,
199,
199,
318,
2372,
11903,
8368,
281,
8,
5252,
12,
3376,
29,
797,
304,
272,
408,
2540,
664,
63,
26665,
14,
1168,
641,
282,
570,
340,
781,
2342,
652,
14,
339,
2136,
3648,
367,
664,
63,
26665,
14,
1168,
315,
314,
283,
6429,
7,
2082,
737,
314,
2746,
402,
272,
6135,
14,
221,
982,
781,
2342,
652,
781,
7171,
1255,
652,
14,
221,
982,
781,
2793,
1133,
2342,
664,
63,
26665,
14,
1168,
272,
2066,
781,
2449,
18030,
14,
339,
3033,
26,
267,
6748,
26,
6912,
370,
314,
3371,
570,
370,
1255,
664,
63,
26665,
14,
1168,
641,
14,
339,
1803,
26,
267,
437,
769,
402,
3031,
7149,
370,
17586,
370,
14,
272,
408,
272,
664,
63,
26665,
275,
6668,
1002,
11903,
8368,
281,
342,
272,
340,
440,
664,
63,
26665,
26,
267,
340,
3376,
26,
288,
870,
298,
9171,
26,
18615,
78,
1133,
2342,
664,
63,
26665,
14,
1168,
2,
267,
372,
942,
339,
3839,
275,
1414,
14,
2959,
8,
362,
63,
26665,
12,
2850,
6505,
16721,
3200,
297,
6748,
9,
272,
372,
3839,
14,
7644,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
zbraniecki/translate
|
translate/lang/dz.py
|
29
|
1044
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2013 Zuza Software Foundation
#
# This file is part of translate.
#
# translate 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.
#
# translate 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/>.
"""This module represents the Dzongkha language.
.. seealso:: http://en.wikipedia.org/wiki/Dzongkha_language
"""
from translate.lang import common
class dz(common.Common):
"""This class represents Dzongkha."""
mozilla_nplurals = 2
mozilla_pluralequation = "n!=1 ? 1 : 0"
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6171,
3107,
85,
8076,
2290,
2752,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
9028,
14,
199,
3,
199,
3,
9028,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
9028,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
2765,
859,
8469,
314,
577,
90,
951,
75,
2411,
2637,
14,
199,
199,
703,
19352,
447,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
36,
90,
951,
75,
2411,
63,
3671,
199,
624,
199,
199,
504,
9028,
14,
4159,
492,
2863,
421,
199,
533,
366,
90,
8,
2330,
14,
7844,
304,
272,
408,
2765,
1021,
8469,
577,
90,
951,
75,
2411,
1041,
339,
1303,
6956,
63,
78,
1168,
300,
2551,
275,
499,
272,
1303,
6956,
63,
1168,
300,
1895,
392,
425,
275,
298,
78,
1111,
17,
5805,
413,
520,
378,
2,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6171,
3107,
85,
8076,
2290,
2752,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
9028,
14,
199,
3,
199,
3,
9028,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
9028,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
2765,
859,
8469,
314,
577,
90,
951,
75,
2411,
2637,
14,
199,
199,
703,
19352,
447,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
36,
90,
951,
75,
2411,
63,
3671,
199,
624,
199,
199,
504,
9028,
14,
4159,
492,
2863,
421,
199,
533,
366,
90,
8,
2330,
14,
7844,
304,
272,
408,
2765,
1021,
8469,
577,
90,
951,
75,
2411,
1041,
339,
1303,
6956,
63,
78,
1168,
300,
2551,
275,
499,
272,
1303,
6956,
63,
1168,
300,
1895,
392,
425,
275,
298,
78,
1111,
17,
5805,
413,
520,
378,
2,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
chengdh/openerp-ktv
|
openerp/addons/ktv_sale/room_operate.py
|
1
|
3418
|
# -*- coding: utf-8 -*-
from osv import osv,fields
from room import room
class room_operate(osv.osv):
'''
包厢操作类:
以下操作都属于包厢操作:
1 预定
2 正常开房
3 买钟
4 买断
5 续钟
6 退钟
7 换房
8 并房
包厢通过cur_room_operate_id与room_operate相关联,用于标示当前包厢所对应的操作
room_operate与以上各个操作是one2many的关系,这样通过一个room_operate可以获取所有包厢在开房过程中所进行的操作,结账时遍历所有的操作并进行计算即可
'''
_name = "ktv.room_operate"
#由于在其他地方需要引用该对象,所有将name定义为bill_no
_rec_name = "bill_no"
_description = "包厢操作类,与包厢是many2one的关系"
_columns = {
"operate_date" : fields.datetime('operate_datetime',required = True),
"room_id" : fields.many2one('ktv.room','room_id',required = True),
"bill_no" : fields.char("bill_no",size = 64,required = True,help = "账单号"),
"room_scheduled_ids" : fields.one2many("ktv.room_scheduled","room_operate_id",help="预定信息列表"),
"room_opens_ids" : fields.one2many("ktv.room_opens","room_operate_id",help="开房信息列表"),
}
_defaults = {
'operate_date' : fields.datetime.now,
'bill_no': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'ktv.room_operate'),
}
def process_operate(self,cr,uid,operate_values):
"""
包厢操作统一入口,调用不同业务类的操作
这样设计的好处是隔离了变化,如果需要修改服务端的逻辑,客户端的调用逻辑不用做任何修改
在客户端新增了业务实体调用,只用增加新的实体即可,其他不用做修改
在js端也需要封装同样的调用接口来隔离变化
:params room_id integer 包厢编码
:operate_values 前端传入的业务操作数据
:operate[osv_name] 要调用的实体业务对象名称,比如ktv.room_checkout
调用示例:
开房操作,返回三个参数 1 操作成功的实体对象 2 包厢应修改的状态 3 cron对象,用于处理对包厢的定时操作:
(operate_obj,room_state,cron) = self.pool.get(operate_values['osv_name']).process_operate(cr,uid,opeate_values)
更新当前包厢状态,添加cron对象,返回处理结果
"""
room_id = operate_values['room_id']
(operate_obj,room_state,cron) = self.pool.get(operate_values['osv_name']).process_operate(cr,uid,operate_values)
#更新包厢状态
self.pool.get('ktv.room').write(cr,uid,room_id,{'state' : room_state})
#TODO 添加cron对象
if cron:
self._create_operate_cron(cr,uid,cron)
room_fields = self.pool.get('ktv.room').fields_get(cr,uid).keys()
room = self.pool.get('ktv.room').read(cr,uid,room_id,room_fields)
#返回两个对象room和room_operate
return {'room' : room,'room_operate' : operate_obj}
def _create_operate_cron(self,cr,uid,cron_vals):
"""
创建cron定时执行任务,在需要定时执行关房任务时,需要执行
:params dict cron_vals 定时任务相关属性
"""
return self.pool.get('ir.cron').create(cr,uid,cron_vals)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
9506,
492,
9506,
12,
955,
199,
504,
14726,
492,
14726,
199,
199,
533,
14726,
63,
2262,
323,
8,
4795,
14,
4795,
304,
272,
1449,
272,
7094,
235,
228,
29708,
96,
30348,
9474,
120,
26,
272,
221,
23681,
24233,
30348,
166,
25315,
27289,
253,
6923,
237,
21018,
228,
29708,
96,
30348,
25742,
272,
413,
10469,
96,
227,
20766,
272,
499,
8853,
256,
97,
15280,
117,
26683,
9077,
124,
272,
650,
221,
32677,
166,
241,
254,
272,
841,
221,
32677,
10310,
256,
272,
959,
9112,
120,
256,
166,
241,
254,
272,
1227,
10469,
223,
223,
166,
241,
254,
272,
1520,
8853,
236,
96,
9077,
124,
272,
1695,
7094,
118,
115,
9077,
124,
272,
7094,
235,
228,
29708,
96,
14333,
249,
13201,
230,
895,
63,
11245,
63,
2262,
323,
63,
344,
4344,
237,
11245,
63,
2262,
323,
15545,
117,
8379,
112,
165,
224,
243,
12,
11428,
6923,
237,
20767,
29875,
119,
22918,
242,
27284,
21018,
228,
29708,
96,
16570,
26604,
15013,
243,
8106,
30348,
272,
14726,
63,
2262,
323,
4344,
237,
23681,
22661,
8197,
227,
10722,
30348,
9729,
368,
18,
3479,
8106,
8379,
112,
27842,
120,
12,
13201,
248,
13750,
116,
14333,
249,
13201,
230,
12033,
11245,
63,
2262,
323,
25521,
23681,
165,
237,
116,
22924,
16570,
20916,
21018,
228,
29708,
96,
21448,
26683,
9077,
124,
13201,
230,
30664,
17088,
16570,
13201,
250,
12609,
8106,
30348,
12,
21872,
30371,
20494,
24744,
236,
29708,
229,
16570,
20916,
8106,
30348,
16322,
115,
13201,
250,
12609,
14082,
95,
21895,
10450,
112,
25521,
272,
1449,
272,
485,
354,
275,
298,
5973,
86,
14,
11245,
63,
2262,
323,
2,
272,
327,
8383,
110,
6923,
237,
21448,
8379,
115,
5498,
245,
27340,
24302,
166,
251,
223,
22274,
12586,
244,
11428,
8400,
99,
26604,
165,
110,
95,
12,
16570,
20916,
15348,
229,
354,
20766,
17837,
232,
24971,
19815,
63,
889,
272,
485,
2761,
63,
354,
275,
298,
19815,
63,
889,
2,
339,
485,
1802,
275,
298,
21018,
228,
29708,
96,
30348,
9474,
120,
12,
4344,
237,
21018,
228,
29708,
96,
9729,
3479,
18,
368,
8106,
8379,
112,
27842,
120,
2,
339,
485,
3406,
275,
469,
288,
298,
2262,
323,
63,
602,
2,
520,
1504,
14,
2083,
360,
2262,
323,
63,
2083,
297,
2427,
275,
715,
395,
288,
298,
11245,
63,
344,
2,
520,
1504,
14,
3479,
18,
368,
360,
5973,
86,
14,
11245,
1673,
11245,
63,
344,
297,
2427,
275,
715,
395,
288,
298,
19815,
63,
889,
2,
520,
1504,
14,
1560,
480,
19815,
63,
889,
401,
890,
275,
5049,
12,
2427,
275,
715,
12,
3437,
275,
298,
30371,
15582,
12937,
1288,
288,
298,
11245,
63,
19274,
63,
1580,
2,
520,
1504,
14,
368,
18,
3479,
480,
5973,
86,
14,
11245,
63,
19274,
2266,
11245,
63,
2262,
323,
63,
344,
401,
3437,
628,
21262,
227,
20766,
27328,
32551,
23243,
1288,
288,
298,
11245,
63,
1490,
83,
63,
1580,
2,
520,
1504,
14,
368,
18,
3479,
480,
5973,
86,
14,
11245,
63,
1490,
83,
2266,
11245,
63,
2262,
323,
63,
344,
401,
3437,
628,
26683,
9077,
124,
27328,
32551,
23243,
1288,
288,
789,
339,
485,
4322,
275,
469,
288,
283,
2262,
323,
63,
602,
7,
520,
1504,
14,
2083,
14,
2131,
12,
288,
283,
19815,
63,
889,
356,
2400,
1559,
12,
2467,
12,
1747,
12,
1067,
26,
1559,
14,
2293,
14,
362,
360,
723,
14,
4041,
1959,
362,
8,
1556,
12,
1747,
12,
283,
5973,
86,
14,
11245,
63,
2262,
323,
659,
288,
789,
339,
347,
2112,
63,
2262,
323,
8,
277,
12,
1556,
12,
1535,
12,
2262,
323,
63,
1459,
304,
267,
408,
267,
7094,
235,
228,
29708,
96,
30348,
9360,
254,
9372,
18236,
6075,
97,
12,
165,
109,
226,
11428,
19594,
28956,
4344,
249,
30521,
9474,
120,
8106,
30348,
267,
9065,
124,
248,
13750,
116,
14082,
123,
14082,
95,
8106,
25440,
122,
11546,
227,
9729,
166,
249,
243,
164,
100,
120,
30998,
6075,
247,
21018,
245,
12,
162,
100,
225,
19349,
251,
166,
251,
223,
22274,
13764,
107,
17130,
118,
6587,
236,
30521,
21341,
108,
8106,
14333,
120,
27252,
240,
12,
32041,
21341,
108,
8106,
165,
109,
226,
11428,
14333,
120,
27252,
240,
19594,
11428,
162,
224,
249,
5498,
120,
11046,
244,
13764,
107,
17130,
118,
267,
7094,
251,
102,
32041,
21341,
108,
22737,
162,
96,
253,
30998,
4344,
249,
30521,
10270,
253,
11046,
242,
165,
109,
226,
11428,
12,
6075,
104,
11428,
162,
96,
253,
28990,
22737,
8106,
10270,
253,
11046,
242,
10450,
112,
25521,
12,
8379,
115,
5498,
245,
19594,
11428,
162,
224,
249,
13764,
107,
17130,
118,
267,
7094,
251,
102,
3596,
21341,
108,
17837,
254,
166,
251,
223,
22274,
15348,
224,
29655,
228,
28956,
13750,
116,
8106,
165,
109,
226,
11428,
24586,
6075,
97,
15771,
99,
166,
249,
243,
164,
100,
120,
6075,
247,
21018,
245,
267,
520,
1162,
14726,
63,
344,
3000,
7094,
235,
228,
29708,
96,
17637,
8967,
267,
520,
2262,
323,
63,
1459,
7094,
232,
236,
21341,
108,
17848,
255,
18236,
8106,
4344,
249,
30521,
30348,
22730,
267,
520,
2262,
323,
59,
4795,
63,
354,
61,
9065,
100,
224,
165,
109,
226,
11428,
8106,
10270,
253,
11046,
242,
4344,
249,
30521,
26604,
165,
110,
95,
21434,
19012,
109,
12,
28285,
243,
162,
100,
225,
5973,
86,
14,
11245,
63,
12891,
267,
9065,
109,
226,
11428,
29875,
119,
25439,
234,
26,
267,
7094,
121,
223,
9077,
124,
30348,
12,
13201,
243,
22234,
4344,
232,
10722,
32549,
12211,
413,
8853,
242,
29462,
16888,
12163,
254,
8106,
10270,
253,
11046,
242,
26604,
165,
110,
95,
499,
7094,
235,
228,
29708,
96,
15013,
243,
13764,
107,
17130,
118,
8106,
30729,
650,
19818,
26604,
165,
110,
95,
12,
11428,
6923,
237,
11546,
227,
24946,
26604,
21018,
228,
29708,
96,
8106,
20766,
20494,
30348,
25742,
267,
334,
2262,
323,
63,
1113,
12,
11245,
63,
929,
12,
14829,
9,
275,
291,
14,
2293,
14,
362,
8,
2262,
323,
63,
1459,
459,
4795,
63,
354,
13227,
1412,
63,
2262,
323,
8,
1556,
12,
1535,
12,
13458,
323,
63,
1459,
9,
267,
8853,
250,
113,
22737,
22918,
242,
27284,
21018,
228,
29708,
96,
30729,
12,
163,
116,
8698,
233,
255,
14829,
26604,
165,
110,
95,
12,
13201,
243,
22234,
11546,
227,
24946,
21872,
19349,
251
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
9506,
492,
9506,
12,
955,
199,
504,
14726,
492,
14726,
199,
199,
533,
14726,
63,
2262,
323,
8,
4795,
14,
4795,
304,
272,
1449,
272,
7094,
235,
228,
29708,
96,
30348,
9474,
120,
26,
272,
221,
23681,
24233,
30348,
166,
25315,
27289,
253,
6923,
237,
21018,
228,
29708,
96,
30348,
25742,
272,
413,
10469,
96,
227,
20766,
272,
499,
8853,
256,
97,
15280,
117,
26683,
9077,
124,
272,
650,
221,
32677,
166,
241,
254,
272,
841,
221,
32677,
10310,
256,
272,
959,
9112,
120,
256,
166,
241,
254,
272,
1227,
10469,
223,
223,
166,
241,
254,
272,
1520,
8853,
236,
96,
9077,
124,
272,
1695,
7094,
118,
115,
9077,
124,
272,
7094,
235,
228,
29708,
96,
14333,
249,
13201,
230,
895,
63,
11245,
63,
2262,
323,
63,
344,
4344,
237,
11245,
63,
2262,
323,
15545,
117,
8379,
112,
165,
224,
243,
12,
11428,
6923,
237,
20767,
29875,
119,
22918,
242,
27284,
21018,
228,
29708,
96,
16570,
26604,
15013,
243,
8106,
30348,
272,
14726,
63,
2262,
323,
4344,
237,
23681,
22661,
8197,
227,
10722,
30348,
9729,
368,
18,
3479,
8106,
8379,
112,
27842,
120,
12,
13201,
248,
13750,
116,
14333,
249,
13201,
230,
12033,
11245,
63,
2262,
323,
25521,
23681,
165,
237,
116,
22924,
16570,
20916,
21018,
228,
29708,
96,
21448,
26683,
9077,
124,
13201,
230,
30664,
17088,
16570,
13201,
250,
12609,
8106,
30348,
12,
21872,
30371,
20494,
24744,
236,
29708,
229,
16570,
20916,
8106,
30348,
16322,
115,
13201,
250,
12609,
14082,
95,
21895,
10450,
112,
25521,
272,
1449,
272,
485,
354,
275,
298,
5973,
86,
14,
11245,
63,
2262,
323,
2,
272,
327,
8383,
110,
6923,
237,
21448,
8379,
115,
5498,
245,
27340,
24302,
166,
251,
223,
22274,
12586,
244,
11428,
8400,
99,
26604,
165,
110,
95,
12,
16570,
20916,
15348,
229,
354,
20766,
17837,
232,
24971,
19815,
63,
889,
272,
485,
2761,
63,
354,
275,
298,
19815,
63,
889,
2,
339,
485,
1802,
275,
298,
21018,
228,
29708,
96,
30348,
9474,
120,
12,
4344,
237,
21018,
228,
29708,
96,
9729,
3479,
18,
368,
8106,
8379,
112,
27842,
120,
2,
339,
485,
3406,
275,
469,
288,
298,
2262,
323,
63,
602,
2,
520,
1504,
14,
2083,
360,
2262,
323,
63,
2083,
297,
2427,
275,
715,
395,
288,
298,
11245,
63,
344,
2,
520,
1504,
14,
3479,
18,
368,
360,
5973,
86,
14,
11245,
1673,
11245,
63,
344,
297,
2427,
275,
715,
395,
288,
298,
19815,
63,
889,
2,
520,
1504,
14,
1560,
480,
19815,
63,
889,
401,
890,
275,
5049,
12,
2427,
275,
715,
12,
3437,
275,
298,
30371,
15582,
12937,
1288,
288,
298,
11245,
63,
19274,
63,
1580,
2,
520,
1504,
14,
368,
18,
3479,
480,
5973,
86,
14,
11245,
63,
19274,
2266,
11245,
63,
2262,
323,
63,
344,
401,
3437,
628,
21262,
227,
20766,
27328,
32551,
23243,
1288,
288,
298,
11245,
63,
1490,
83,
63,
1580,
2,
520,
1504,
14,
368,
18,
3479,
480,
5973,
86,
14,
11245,
63,
1490,
83,
2266,
11245,
63,
2262,
323,
63,
344,
401,
3437,
628,
26683,
9077,
124,
27328,
32551,
23243,
1288,
288,
789,
339,
485,
4322,
275,
469,
288,
283,
2262,
323,
63,
602,
7,
520,
1504,
14,
2083,
14,
2131,
12,
288,
283,
19815,
63,
889,
356,
2400,
1559,
12,
2467,
12,
1747,
12,
1067,
26,
1559,
14,
2293,
14,
362,
360,
723,
14,
4041,
1959,
362,
8,
1556,
12,
1747,
12,
283,
5973,
86,
14,
11245,
63,
2262,
323,
659,
288,
789,
339,
347,
2112,
63,
2262,
323,
8,
277,
12,
1556,
12,
1535,
12,
2262,
323,
63,
1459,
304,
267,
408,
267,
7094,
235,
228,
29708,
96,
30348,
9360,
254,
9372,
18236,
6075,
97,
12,
165,
109,
226,
11428,
19594,
28956,
4344,
249,
30521,
9474,
120,
8106,
30348,
267,
9065,
124,
248,
13750,
116,
14082,
123,
14082,
95,
8106,
25440,
122,
11546,
227,
9729,
166,
249,
243,
164,
100,
120,
30998,
6075,
247,
21018,
245,
12,
162,
100,
225,
19349,
251,
166,
251,
223,
22274,
13764,
107,
17130,
118,
6587,
236,
30521,
21341,
108,
8106,
14333,
120,
27252,
240,
12,
32041,
21341,
108,
8106,
165,
109,
226,
11428,
14333,
120,
27252,
240,
19594,
11428,
162,
224,
249,
5498,
120,
11046,
244,
13764,
107,
17130,
118,
267,
7094,
251,
102,
32041,
21341,
108,
22737,
162,
96,
253,
30998,
4344,
249,
30521,
10270,
253,
11046,
242,
165,
109,
226,
11428,
12,
6075,
104,
11428,
162,
96,
253,
28990,
22737,
8106,
10270,
253,
11046,
242,
10450,
112,
25521,
12,
8379,
115,
5498,
245,
19594,
11428,
162,
224,
249,
13764,
107,
17130,
118,
267,
7094,
251,
102,
3596,
21341,
108,
17837,
254,
166,
251,
223,
22274,
15348,
224,
29655,
228,
28956,
13750,
116,
8106,
165,
109,
226,
11428,
24586,
6075,
97,
15771,
99,
166,
249,
243,
164,
100,
120,
6075,
247,
21018,
245,
267,
520,
1162,
14726,
63,
344,
3000,
7094,
235,
228,
29708,
96,
17637,
8967,
267,
520,
2262,
323,
63,
1459,
7094,
232,
236,
21341,
108,
17848,
255,
18236,
8106,
4344,
249,
30521,
30348,
22730,
267,
520,
2262,
323,
59,
4795,
63,
354,
61,
9065,
100,
224,
165,
109,
226,
11428,
8106,
10270,
253,
11046,
242,
4344,
249,
30521,
26604,
165,
110,
95,
21434,
19012,
109,
12,
28285,
243,
162,
100,
225,
5973,
86,
14,
11245,
63,
12891,
267,
9065,
109,
226,
11428,
29875,
119,
25439,
234,
26,
267,
7094,
121,
223,
9077,
124,
30348,
12,
13201,
243,
22234,
4344,
232,
10722,
32549,
12211,
413,
8853,
242,
29462,
16888,
12163,
254,
8106,
10270,
253,
11046,
242,
26604,
165,
110,
95,
499,
7094,
235,
228,
29708,
96,
15013,
243,
13764,
107,
17130,
118,
8106,
30729,
650,
19818,
26604,
165,
110,
95,
12,
11428,
6923,
237,
11546,
227,
24946,
26604,
21018,
228,
29708,
96,
8106,
20766,
20494,
30348,
25742,
267,
334,
2262,
323,
63,
1113,
12,
11245,
63,
929,
12,
14829,
9,
275,
291,
14,
2293,
14,
362,
8,
2262,
323,
63,
1459,
459,
4795,
63,
354,
13227,
1412,
63,
2262,
323,
8,
1556,
12,
1535,
12,
13458,
323,
63,
1459,
9,
267,
8853,
250,
113,
22737,
22918,
242,
27284,
21018,
228,
29708,
96,
30729,
12,
163,
116,
8698,
233,
255,
14829,
26604,
165,
110,
95,
12,
13201,
243,
22234,
11546,
227,
24946,
21872,
19349,
251,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Kniyl/mezzanine
|
mezzanine/blog/defaults.py
|
55
|
2363
|
"""
Default settings for the ``mezzanine.blog`` app. Each of these can be
overridden in your project's settings module, just like regular
Django settings. The ``editable`` argument for each controls whether
the setting is editable via Django's admin.
Thought should be given to how a setting is actually used before
making it editable, as it may be inappropriate - for example settings
that are only read during startup shouldn't be editable, since changing
them would require an application reload.
"""
from __future__ import unicode_literals
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from mezzanine.conf import register_setting
register_setting(
name="BLOG_USE_FEATURED_IMAGE",
description=_("Enable featured images in blog posts"),
editable=False,
default=False,
)
_BLOG_URLS_DATE_FORMAT = ""
if getattr(settings, "BLOG_URLS_USE_DATE", False):
_BLOG_URLS_DATE_FORMAT = "day"
from warnings import warn
warn("BLOG_URLS_USE_DATE setting is deprecated, please use the "
"BLOG_URLS_DATE_FORMAT setting with a value of 'year', 'month', "
"or 'day'.")
register_setting(
name="BLOG_URLS_DATE_FORMAT",
label=_("Blog post URL date format"),
description=_("A string containing the value ``year``, ``month``, or "
"``day``, which controls the granularity of the date portion in the "
"URL for each blog post. Eg: ``year`` will define URLs in the format "
"/blog/yyyy/slug/, while ``day`` will define URLs with the format "
"/blog/yyyy/mm/dd/slug/. An empty string means the URLs will only "
"use the slug, and not contain any portion of the date at all."),
editable=False,
default=_BLOG_URLS_DATE_FORMAT,
)
register_setting(
name="BLOG_POST_PER_PAGE",
label=_("Blog posts per page"),
description=_("Number of blog posts shown on a blog listing page."),
editable=True,
default=5,
)
register_setting(
name="BLOG_RSS_LIMIT",
label=_("Blog posts RSS limit"),
description=_("Number of most recent blog posts shown in the RSS feed. "
"Set to ``None`` to display all blog posts in the RSS feed."),
editable=False,
default=20,
)
register_setting(
name="BLOG_SLUG",
description=_("Slug of the page object for the blog."),
editable=False,
default="blog",
)
|
bsd-2-clause
|
[
624,
199,
2698,
2202,
367,
314,
1124,
278,
4348,
290,
1132,
14,
11486,
1040,
1145,
14,
7048,
402,
3520,
883,
506,
199,
30769,
315,
2195,
2199,
1159,
2202,
859,
12,
2951,
2839,
5578,
199,
9323,
2202,
14,
710,
1124,
10820,
1040,
1423,
367,
1924,
13467,
3775,
199,
1589,
4260,
365,
14783,
4799,
5634,
1159,
4628,
14,
199,
199,
52,
526,
10846,
1077,
506,
1627,
370,
4212,
282,
4260,
365,
5965,
1202,
2544,
199,
391,
17443,
652,
14783,
12,
465,
652,
1443,
506,
315,
11227,
5655,
446,
367,
2893,
2202,
199,
9099,
787,
1454,
1586,
5309,
14210,
9296,
1133,
506,
14783,
12,
3967,
13729,
199,
1589,
77,
3955,
4409,
376,
4223,
13101,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
562,
4348,
290,
1132,
14,
2190,
492,
2274,
63,
6031,
421,
199,
2683,
63,
6031,
8,
272,
536,
628,
34,
4947,
63,
4701,
63,
22884,
36,
63,
9438,
401,
272,
1369,
9384,
6476,
13953,
3297,
5935,
315,
19936,
22238,
1288,
272,
14783,
29,
797,
12,
272,
849,
29,
797,
12,
199,
9,
199,
199,
63,
34,
4947,
63,
31582,
63,
5390,
63,
4807,
275,
3087,
199,
692,
2519,
8,
1751,
12,
298,
34,
4947,
63,
31582,
63,
4701,
63,
5390,
401,
756,
304,
272,
485,
34,
4947,
63,
31582,
63,
5390,
63,
4807,
275,
298,
2977,
2,
272,
687,
3598,
492,
7987,
272,
7987,
480,
34,
4947,
63,
31582,
63,
4701,
63,
5390,
4260,
365,
5906,
12,
8749,
675,
314,
298,
267,
298,
34,
4947,
63,
31582,
63,
5390,
63,
4807,
4260,
543,
282,
574,
402,
283,
3403,
297,
283,
4482,
297,
298,
267,
298,
269,
283,
2977,
29435,
199,
199,
2683,
63,
6031,
8,
272,
536,
628,
34,
4947,
63,
31582,
63,
5390,
63,
4807,
401,
272,
1768,
9384,
26081,
2963,
2851,
1434,
1475,
1288,
272,
1369,
9384,
33,
1059,
3035,
314,
574,
1124,
3403,
4542,
1124,
4482,
4542,
503,
298,
267,
298,
1040,
2977,
4542,
1314,
13467,
314,
9202,
22504,
402,
314,
1434,
18046,
315,
314,
298,
267,
298,
2632,
367,
1924,
19936,
2963,
14,
662,
71,
26,
1124,
3403,
1040,
911,
5627,
10867,
315,
314,
1475,
298,
267,
3286,
11486,
15,
18322,
15,
5464,
15,
12,
1830,
1124,
2977,
1040,
911,
5627,
10867,
543,
314,
1475,
298,
267,
3286,
11486,
15,
18322,
15,
596,
15,
617,
15,
5464,
8083,
1626,
2701,
1059,
4910,
314,
10867,
911,
1454,
298,
267,
298,
1180,
314,
8889,
12,
436,
440,
1395,
1263,
18046,
402,
314,
1434,
737,
1006,
7651,
272,
14783,
29,
797,
12,
272,
849,
3699,
34,
4947,
63,
31582,
63,
5390,
63,
4807,
12,
199,
9,
199,
199,
2683,
63,
6031,
8,
272,
536,
628,
34,
4947,
63,
4030,
63,
4227,
63,
12898,
401,
272,
1768,
9384,
26081,
22238,
1126,
2034,
1288,
272,
1369,
9384,
3259,
402,
19936,
22238,
9164,
641,
282,
19936,
13778,
2034,
7651,
272,
14783,
29,
549,
12,
272,
849,
29,
21,
12,
199,
9,
199,
199,
2683,
63,
6031,
8,
272,
536,
628,
34,
4947,
63,
22786,
63,
13387,
401,
272,
1768,
9384,
26081,
22238,
30331,
2304,
1288,
272,
1369,
9384,
3259,
402,
4750,
8058,
19936,
22238,
9164,
315,
314,
30331,
4733,
14,
298,
267,
298,
1084,
370,
1124,
403,
1040,
370,
2929,
1006,
19936,
22238,
315,
314,
30331,
4733,
7651,
272,
14783,
29,
797,
12,
272,
849,
29,
1165,
12,
199,
9,
199,
199,
2683,
63,
6031,
8,
272,
536,
628,
34,
4947,
63,
4929,
10134,
401,
272,
1369,
9384,
15554,
402,
314,
2034,
909,
367,
314,
19936,
7651,
272,
14783,
29,
797,
12,
272,
849,
628,
11486,
401,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
2698,
2202,
367,
314,
1124,
278,
4348,
290,
1132,
14,
11486,
1040,
1145,
14,
7048,
402,
3520,
883,
506,
199,
30769,
315,
2195,
2199,
1159,
2202,
859,
12,
2951,
2839,
5578,
199,
9323,
2202,
14,
710,
1124,
10820,
1040,
1423,
367,
1924,
13467,
3775,
199,
1589,
4260,
365,
14783,
4799,
5634,
1159,
4628,
14,
199,
199,
52,
526,
10846,
1077,
506,
1627,
370,
4212,
282,
4260,
365,
5965,
1202,
2544,
199,
391,
17443,
652,
14783,
12,
465,
652,
1443,
506,
315,
11227,
5655,
446,
367,
2893,
2202,
199,
9099,
787,
1454,
1586,
5309,
14210,
9296,
1133,
506,
14783,
12,
3967,
13729,
199,
1589,
77,
3955,
4409,
376,
4223,
13101,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
562,
4348,
290,
1132,
14,
2190,
492,
2274,
63,
6031,
421,
199,
2683,
63,
6031,
8,
272,
536,
628,
34,
4947,
63,
4701,
63,
22884,
36,
63,
9438,
401,
272,
1369,
9384,
6476,
13953,
3297,
5935,
315,
19936,
22238,
1288,
272,
14783,
29,
797,
12,
272,
849,
29,
797,
12,
199,
9,
199,
199,
63,
34,
4947,
63,
31582,
63,
5390,
63,
4807,
275,
3087,
199,
692,
2519,
8,
1751,
12,
298,
34,
4947,
63,
31582,
63,
4701,
63,
5390,
401,
756,
304,
272,
485,
34,
4947,
63,
31582,
63,
5390,
63,
4807,
275,
298,
2977,
2,
272,
687,
3598,
492,
7987,
272,
7987,
480,
34,
4947,
63,
31582,
63,
4701,
63,
5390,
4260,
365,
5906,
12,
8749,
675,
314,
298,
267,
298,
34,
4947,
63,
31582,
63,
5390,
63,
4807,
4260,
543,
282,
574,
402,
283,
3403,
297,
283,
4482,
297,
298,
267,
298,
269,
283,
2977,
29435,
199,
199,
2683,
63,
6031,
8,
272,
536,
628,
34,
4947,
63,
31582,
63,
5390,
63,
4807,
401,
272,
1768,
9384,
26081,
2963,
2851,
1434,
1475,
1288,
272,
1369,
9384,
33,
1059,
3035,
314,
574,
1124,
3403,
4542,
1124,
4482,
4542,
503,
298,
267,
298,
1040,
2977,
4542,
1314,
13467,
314,
9202,
22504,
402,
314,
1434,
18046,
315,
314,
298,
267,
298,
2632,
367,
1924,
19936,
2963,
14,
662,
71,
26,
1124,
3403,
1040,
911,
5627,
10867,
315,
314,
1475,
298,
267,
3286,
11486,
15,
18322,
15,
5464,
15,
12,
1830,
1124,
2977,
1040,
911,
5627,
10867,
543,
314,
1475,
298,
267,
3286,
11486,
15,
18322,
15,
596,
15,
617,
15,
5464,
8083,
1626,
2701,
1059,
4910,
314,
10867,
911,
1454,
298,
267,
298,
1180,
314,
8889,
12,
436,
440,
1395,
1263,
18046,
402,
314,
1434,
737,
1006,
7651,
272,
14783,
29,
797,
12,
272,
849,
3699,
34,
4947,
63,
31582,
63,
5390,
63,
4807,
12,
199,
9,
199,
199,
2683,
63,
6031,
8,
272,
536,
628,
34,
4947,
63,
4030,
63,
4227,
63,
12898,
401,
272,
1768,
9384,
26081,
22238,
1126,
2034,
1288,
272,
1369,
9384,
3259,
402,
19936,
22238,
9164,
641,
282,
19936,
13778,
2034,
7651,
272,
14783,
29,
549,
12,
272,
849,
29,
21,
12,
199,
9,
199,
199,
2683,
63,
6031,
8,
272,
536,
628,
34,
4947,
63,
22786,
63,
13387,
401,
272,
1768,
9384,
26081,
22238,
30331,
2304,
1288,
272,
1369,
9384,
3259,
402,
4750,
8058,
19936,
22238,
9164,
315,
314,
30331,
4733,
14,
298,
267,
298,
1084,
370,
1124,
403,
1040,
370,
2929,
1006,
19936,
22238,
315,
314,
30331,
4733,
7651,
272,
14783,
29,
797,
12,
272,
849,
29,
1165,
12,
199,
9,
199,
199,
2683,
63,
6031,
8,
272,
536,
628,
34,
4947,
63,
4929,
10134,
401,
272,
1369,
9384,
15554,
402,
314,
2034,
909,
367,
314,
19936,
7651,
272,
14783,
29,
797,
12,
272,
849,
628,
11486,
401,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Yonnick/userinfuser
|
serverside/tools/xss.py
|
14
|
5374
|
# Copyright (C) 2011, CloudCaptive
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from htmllib import HTMLParser
from cgi import escape
from urlparse import urlparse
from formatter import AbstractFormatter
from htmlentitydefs import entitydefs
from xml.sax.saxutils import quoteattr
def xssescape(text):
"""Gets rid of < and > and & and, for good measure, :"""
return escape(text, quote=True).replace(':',':')
class XssCleaner(HTMLParser):
def __init__(self, fmt = AbstractFormatter):
HTMLParser.__init__(self, fmt)
self.result = ""
self.open_tags = []
# A list of the only tags allowed. Be careful adding to this. Adding
# "script," for example, would not be smart. 'img' is out by default
# because of the danger of IMG embedded commands, and/or web bugs.
self.permitted_tags = ['a', 'b', 'blockquote', 'br', 'i',
'li', 'ol', 'ul', 'p', 'cite']
# A list of tags that require no closing tag.
self.requires_no_close = ['img', 'br']
# A dictionary showing the only attributes allowed for particular tags.
# If a tag is not listed here, it is allowed no attributes. Adding
# "on" tags, like "onhover," would not be smart. Also be very careful
# of "background" and "style."
self.allowed_attributes = \
{'a':['href','title'],
'img':['src','alt'],
'blockquote':['type']}
# The only schemes allowed in URLs (for href and src attributes).
# Adding "javascript" or "vbscript" to this list would not be smart.
self.allowed_schemes = ['http','https','ftp']
def handle_data(self, data):
if data:
self.result += xssescape(data)
def handle_charref(self, ref):
if len(ref) < 7 and ref.isdigit():
self.result += '&#%s;' % ref
else:
self.result += xssescape('&#%s' % ref)
def handle_entityref(self, ref):
if ref in entitydefs:
self.result += '&%s;' % ref
else:
self.result += xssescape('&%s' % ref)
def handle_comment(self, comment):
if comment:
self.result += xssescape("<!--%s-->" % comment)
def handle_starttag(self, tag, method, attrs):
if tag not in self.permitted_tags:
self.result += xssescape("<%s>" % tag)
else:
bt = "<" + tag
if tag in self.allowed_attributes:
attrs = dict(attrs)
self.allowed_attributes_here = \
[x for x in self.allowed_attributes[tag] if x in attrs \
and len(attrs[x]) > 0]
for attribute in self.allowed_attributes_here:
if attribute in ['href', 'src', 'background']:
if self.url_is_acceptable(attrs[attribute]):
bt += ' %s="%s"' % (attribute, attrs[attribute])
else:
bt += ' %s=%s' % \
(xssescape(attribute), quoteattr(attrs[attribute]))
if bt == "<a" or bt == "<img":
return
if tag in self.requires_no_close:
bt += "/"
bt += ">"
self.result += bt
self.open_tags.insert(0, tag)
def handle_endtag(self, tag, attrs):
bracketed = "</%s>" % tag
if tag not in self.permitted_tags:
self.result += xssescape(bracketed)
elif tag in self.open_tags:
self.result += bracketed
self.open_tags.remove(tag)
def unknown_starttag(self, tag, attributes):
self.handle_starttag(tag, None, attributes)
def unknown_endtag(self, tag):
self.handle_endtag(tag, None)
def url_is_acceptable(self,url):
### Requires all URLs to be "absolute."
parsed = urlparse(url)
return parsed[0] in self.allowed_schemes and '.' in parsed[1]
def strip(self, rawstring):
"""Returns the argument stripped of potentially harmful HTML or Javascript code"""
self.result = ""
self.feed(rawstring)
for endtag in self.open_tags:
if endtag not in self.requires_no_close:
self.result += "</%s>" % endtag
return self.result
def xtags(self):
"""Returns a printable string informing the user which tags are allowed"""
self.permitted_tags.sort()
tg = ""
for x in self.permitted_tags:
tg += "<" + x
if x in self.allowed_attributes:
for y in self.allowed_attributes[x]:
tg += ' %s=""' % y
tg += "> "
return xssescape(tg.strip())
|
gpl-3.0
|
[
3,
1898,
334,
35,
9,
7760,
12,
8142,
9155,
857,
199,
3,
221,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
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,
221,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
504,
3517,
773,
492,
24581,
199,
504,
16004,
492,
4772,
199,
504,
7097,
492,
7097,
199,
504,
9698,
492,
11836,
7772,
199,
504,
30010,
552,
1701,
8710,
492,
4642,
8710,
199,
504,
2748,
14,
14338,
14,
14338,
1208,
492,
6313,
962,
199,
199,
318,
12965,
261,
3588,
8,
505,
304,
272,
408,
14426,
16146,
402,
665,
436,
690,
436,
1253,
436,
12,
367,
6954,
9775,
12,
520,
624,
272,
372,
4772,
8,
505,
12,
6313,
29,
549,
680,
1814,
6176,
1673,
7997,
2010,
10784,
199,
199,
533,
1323,
385,
6580,
281,
8,
27375,
304,
272,
347,
636,
826,
721,
277,
12,
7104,
275,
11836,
7772,
304,
267,
24581,
855,
826,
721,
277,
12,
7104,
9,
267,
291,
14,
1099,
275,
3087,
267,
291,
14,
1490,
63,
2969,
275,
942,
267,
327,
437,
769,
402,
314,
1454,
3762,
4370,
14,
221,
6423,
25082,
7791,
370,
642,
14,
221,
12934,
267,
327,
298,
1579,
4589,
367,
2893,
12,
3955,
440,
506,
11179,
14,
221,
283,
4060,
7,
365,
734,
701,
849,
4960,
327,
2952,
402,
314,
366,
12974,
402,
18211,
39,
12169,
3718,
12,
436,
15,
269,
3330,
18227,
14,
267,
291,
14,
28843,
63,
2969,
275,
788,
65,
297,
283,
66,
297,
283,
28623,
297,
283,
3289,
297,
283,
73,
297,
221,
2079,
283,
317,
297,
283,
393,
297,
283,
348,
297,
283,
80,
297,
283,
25171,
418,
398,
327,
437,
769,
402,
3762,
626,
4409,
949,
11261,
1947,
14,
267,
291,
14,
6537,
63,
889,
63,
1600,
275,
788,
4060,
297,
283,
3289,
418,
398,
327,
437,
2600,
21207,
314,
1454,
3004,
4370,
367,
6770,
3762,
14,
267,
327,
982,
282,
1947,
365,
440,
10532,
2348,
12,
652,
365,
4370,
949,
3004,
14,
221,
12934,
267,
327,
298,
265,
2,
3762,
12,
2839,
298,
265,
22797,
4589,
3955,
440,
506,
11179,
14,
221,
6121,
506,
7437,
25082,
267,
327,
402,
298,
7451,
2,
436,
298,
2487,
2122,
267,
291,
14,
6541,
63,
2987,
275,
971,
288,
791,
65,
21662,
6399,
1673,
1213,
995,
1467,
283,
4060,
21662,
2164,
1673,
4478,
995,
1467,
283,
28623,
21662,
466,
12074,
398,
327,
710,
1454,
21149,
4370,
315,
10867,
334,
509,
4369,
436,
2928,
3004,
680,
267,
327,
12934,
298,
9554,
2,
503,
298,
18708,
1579,
2,
370,
642,
769,
3955,
440,
506,
11179,
14,
267,
291,
14,
6541,
63,
26818,
275,
788,
1014,
1673,
2859,
1673,
8915,
418,
272,
347,
2429,
63,
576,
8,
277,
12,
666,
304,
267,
340,
666,
26,
288,
291,
14,
1099,
847,
12965,
261,
3588,
8,
576,
9,
272,
347,
2429,
63,
24253,
8,
277,
12,
2984,
304,
267,
340,
822,
8,
1121,
9,
665,
1520,
436,
2984,
14,
13896,
837,
288,
291,
14,
1099,
847,
7673,
25745,
83,
8942,
450,
2984,
267,
587,
26,
288,
291,
14,
1099,
847,
12965,
261,
3588,
360,
7997,
5,
83,
7,
450,
2984,
9,
272,
347,
2429,
63,
4502,
1121,
8,
277,
12,
2984,
304,
267,
340,
2984,
315,
4642,
8710,
26,
288,
291,
14,
1099,
847,
7673,
5,
83,
8942,
450,
2984,
267,
587,
26,
288,
291,
14,
1099,
847,
12965,
261,
3588,
20040,
5,
83,
7,
450,
2984,
9,
272,
347,
2429,
63,
3349,
8,
277,
12,
3721,
304,
267,
340,
3721,
26,
288,
291,
14,
1099,
847,
12965,
261,
3588,
6757,
17722,
5,
83,
306,
4335,
450,
3721,
9,
339,
347,
2429,
63,
15234,
8,
277,
12,
1947,
12,
1083,
12,
3290,
304,
267,
340,
1947,
440,
315,
291,
14,
28843,
63,
2969,
26,
288,
291,
14,
1099,
847,
12965,
261,
3588,
6757,
5,
83,
4335,
450,
221,
1947,
9,
267,
587,
26,
288,
22342,
275,
3886,
2,
435,
1947,
288,
340,
1947,
315,
291,
14,
6541,
63,
2987,
26,
355,
3290,
275,
1211,
8,
3288,
9,
355,
291,
14,
6541,
63,
2987,
63,
1681,
275,
971,
2116,
359,
88,
367,
671,
315,
291,
14,
6541,
63,
2987,
59,
1450,
61,
340,
671,
315,
3290,
971,
673,
436,
822,
8,
3288,
59,
88,
566,
690,
378,
61,
355,
367,
2225,
315,
291,
14,
6541,
63,
2987,
63,
1681,
26,
490,
340,
2225,
315,
788,
6399,
297,
283,
2164,
297,
283,
7451,
2565,
717,
340,
291,
14,
633,
63,
374,
63,
28751,
8,
3288,
59,
3215,
4682,
1169,
22342,
847,
283,
450,
83,
5961,
83,
4507,
450,
334,
3215,
12,
3290,
59,
3215,
566,
490,
587,
26,
717,
22342,
847,
283,
450,
83,
2458,
83,
7,
450,
971,
2574,
334,
7977,
261,
3588,
8,
3215,
395,
6313,
962,
8,
3288,
59,
3215,
2459,
288,
340,
22342,
508,
3886,
65,
2,
503,
22342,
508,
3886,
4060,
582,
355,
372,
288,
340,
1947,
315,
291,
14,
6537,
63,
889,
63,
1600,
26,
355,
22342,
847,
10609,
288,
22342,
847,
28192,
10473,
288,
291,
14,
1099,
847,
22342,
288,
291,
14,
1490,
63,
2969,
14,
3176,
8,
16,
12,
1947,
9,
15567,
347,
2429,
63,
25765,
8,
277,
12,
1947,
12,
3290,
304,
267,
330,
8085,
69,
471,
275,
15683,
5,
83,
4335,
450,
1947,
267,
340,
1947,
440,
315,
291,
14,
28843,
63,
2969,
26,
288,
291,
14,
1099,
847,
12965,
261,
3588,
8,
7828,
21531,
471,
9,
267,
916,
1947,
315,
291,
14,
1490,
63,
2969,
26
] |
[
1898,
334,
35,
9,
7760,
12,
8142,
9155,
857,
199,
3,
221,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
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,
221,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
504,
3517,
773,
492,
24581,
199,
504,
16004,
492,
4772,
199,
504,
7097,
492,
7097,
199,
504,
9698,
492,
11836,
7772,
199,
504,
30010,
552,
1701,
8710,
492,
4642,
8710,
199,
504,
2748,
14,
14338,
14,
14338,
1208,
492,
6313,
962,
199,
199,
318,
12965,
261,
3588,
8,
505,
304,
272,
408,
14426,
16146,
402,
665,
436,
690,
436,
1253,
436,
12,
367,
6954,
9775,
12,
520,
624,
272,
372,
4772,
8,
505,
12,
6313,
29,
549,
680,
1814,
6176,
1673,
7997,
2010,
10784,
199,
199,
533,
1323,
385,
6580,
281,
8,
27375,
304,
272,
347,
636,
826,
721,
277,
12,
7104,
275,
11836,
7772,
304,
267,
24581,
855,
826,
721,
277,
12,
7104,
9,
267,
291,
14,
1099,
275,
3087,
267,
291,
14,
1490,
63,
2969,
275,
942,
267,
327,
437,
769,
402,
314,
1454,
3762,
4370,
14,
221,
6423,
25082,
7791,
370,
642,
14,
221,
12934,
267,
327,
298,
1579,
4589,
367,
2893,
12,
3955,
440,
506,
11179,
14,
221,
283,
4060,
7,
365,
734,
701,
849,
4960,
327,
2952,
402,
314,
366,
12974,
402,
18211,
39,
12169,
3718,
12,
436,
15,
269,
3330,
18227,
14,
267,
291,
14,
28843,
63,
2969,
275,
788,
65,
297,
283,
66,
297,
283,
28623,
297,
283,
3289,
297,
283,
73,
297,
221,
2079,
283,
317,
297,
283,
393,
297,
283,
348,
297,
283,
80,
297,
283,
25171,
418,
398,
327,
437,
769,
402,
3762,
626,
4409,
949,
11261,
1947,
14,
267,
291,
14,
6537,
63,
889,
63,
1600,
275,
788,
4060,
297,
283,
3289,
418,
398,
327,
437,
2600,
21207,
314,
1454,
3004,
4370,
367,
6770,
3762,
14,
267,
327,
982,
282,
1947,
365,
440,
10532,
2348,
12,
652,
365,
4370,
949,
3004,
14,
221,
12934,
267,
327,
298,
265,
2,
3762,
12,
2839,
298,
265,
22797,
4589,
3955,
440,
506,
11179,
14,
221,
6121,
506,
7437,
25082,
267,
327,
402,
298,
7451,
2,
436,
298,
2487,
2122,
267,
291,
14,
6541,
63,
2987,
275,
971,
288,
791,
65,
21662,
6399,
1673,
1213,
995,
1467,
283,
4060,
21662,
2164,
1673,
4478,
995,
1467,
283,
28623,
21662,
466,
12074,
398,
327,
710,
1454,
21149,
4370,
315,
10867,
334,
509,
4369,
436,
2928,
3004,
680,
267,
327,
12934,
298,
9554,
2,
503,
298,
18708,
1579,
2,
370,
642,
769,
3955,
440,
506,
11179,
14,
267,
291,
14,
6541,
63,
26818,
275,
788,
1014,
1673,
2859,
1673,
8915,
418,
272,
347,
2429,
63,
576,
8,
277,
12,
666,
304,
267,
340,
666,
26,
288,
291,
14,
1099,
847,
12965,
261,
3588,
8,
576,
9,
272,
347,
2429,
63,
24253,
8,
277,
12,
2984,
304,
267,
340,
822,
8,
1121,
9,
665,
1520,
436,
2984,
14,
13896,
837,
288,
291,
14,
1099,
847,
7673,
25745,
83,
8942,
450,
2984,
267,
587,
26,
288,
291,
14,
1099,
847,
12965,
261,
3588,
360,
7997,
5,
83,
7,
450,
2984,
9,
272,
347,
2429,
63,
4502,
1121,
8,
277,
12,
2984,
304,
267,
340,
2984,
315,
4642,
8710,
26,
288,
291,
14,
1099,
847,
7673,
5,
83,
8942,
450,
2984,
267,
587,
26,
288,
291,
14,
1099,
847,
12965,
261,
3588,
20040,
5,
83,
7,
450,
2984,
9,
272,
347,
2429,
63,
3349,
8,
277,
12,
3721,
304,
267,
340,
3721,
26,
288,
291,
14,
1099,
847,
12965,
261,
3588,
6757,
17722,
5,
83,
306,
4335,
450,
3721,
9,
339,
347,
2429,
63,
15234,
8,
277,
12,
1947,
12,
1083,
12,
3290,
304,
267,
340,
1947,
440,
315,
291,
14,
28843,
63,
2969,
26,
288,
291,
14,
1099,
847,
12965,
261,
3588,
6757,
5,
83,
4335,
450,
221,
1947,
9,
267,
587,
26,
288,
22342,
275,
3886,
2,
435,
1947,
288,
340,
1947,
315,
291,
14,
6541,
63,
2987,
26,
355,
3290,
275,
1211,
8,
3288,
9,
355,
291,
14,
6541,
63,
2987,
63,
1681,
275,
971,
2116,
359,
88,
367,
671,
315,
291,
14,
6541,
63,
2987,
59,
1450,
61,
340,
671,
315,
3290,
971,
673,
436,
822,
8,
3288,
59,
88,
566,
690,
378,
61,
355,
367,
2225,
315,
291,
14,
6541,
63,
2987,
63,
1681,
26,
490,
340,
2225,
315,
788,
6399,
297,
283,
2164,
297,
283,
7451,
2565,
717,
340,
291,
14,
633,
63,
374,
63,
28751,
8,
3288,
59,
3215,
4682,
1169,
22342,
847,
283,
450,
83,
5961,
83,
4507,
450,
334,
3215,
12,
3290,
59,
3215,
566,
490,
587,
26,
717,
22342,
847,
283,
450,
83,
2458,
83,
7,
450,
971,
2574,
334,
7977,
261,
3588,
8,
3215,
395,
6313,
962,
8,
3288,
59,
3215,
2459,
288,
340,
22342,
508,
3886,
65,
2,
503,
22342,
508,
3886,
4060,
582,
355,
372,
288,
340,
1947,
315,
291,
14,
6537,
63,
889,
63,
1600,
26,
355,
22342,
847,
10609,
288,
22342,
847,
28192,
10473,
288,
291,
14,
1099,
847,
22342,
288,
291,
14,
1490,
63,
2969,
14,
3176,
8,
16,
12,
1947,
9,
15567,
347,
2429,
63,
25765,
8,
277,
12,
1947,
12,
3290,
304,
267,
330,
8085,
69,
471,
275,
15683,
5,
83,
4335,
450,
1947,
267,
340,
1947,
440,
315,
291,
14,
28843,
63,
2969,
26,
288,
291,
14,
1099,
847,
12965,
261,
3588,
8,
7828,
21531,
471,
9,
267,
916,
1947,
315,
291,
14,
1490,
63,
2969,
26,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
aitormf/JdeRobot
|
src/tools/visualStates/gui/treenode.py
|
3
|
2100
|
'''
Copyright (C) 1997-2017 JDERobot Developers Team
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 Library 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/>.
Authors : Okan Asik (asik.okan@gmail.com)
'''
from PyQt5.QtWidgets import QTreeWidgetItem
from PyQt5.QtGui import QColor
class TreeNode(QTreeWidgetItem):
def __init__(self, id, name, color, parent=None):
super(QTreeWidgetItem, self).__init__(parent)
self.parentItem = parent
self.id = id
self.name = name
self.color = color
self.childItems = []
def background(self):
background = QColor(self.color)
return background
def appendChild(self, item):
self.childItems.append(item)
def removeChild(self, item):
self.childItems.remove(item)
def child(self, row):
return self.childItems[row]
def childCount(self):
return len(self.childItems)
def columnCount(self):
return 2
def data(self, column):
if column == 0:
return self.id
if column == 1:
return self.name
def parent(self):
return self.parentItem
def row(self):
if self.parentItem:
return self.parentItem.childItems.index(self)
return 0
def getChildren(self):
return self.childItems
def setColor(self, color):
self.color = color
def removeChildren(self):
del self.childItems[:]
def myClicked(self, item, column):
# print('clicked:' + str(item))
pass
|
gpl-3.0
|
[
2344,
2043,
1898,
334,
35,
9,
9013,
23,
13,
10680,
1603,
11733,
17800,
23493,
11682,
8410,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
2043,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
2043,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
2043,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
8410,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
2043,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
2043,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
2043,
1664,
11243,
1696,
1684,
844,
367,
1655,
2436,
14,
8410,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
2043,
3180,
543,
642,
2240,
27,
340,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
8410,
6642,
520,
20049,
290,
437,
338,
75,
334,
305,
3258,
14,
745,
290,
32,
6799,
14,
957,
9,
819,
1449,
199,
504,
14084,
21,
14,
29081,
492,
1413,
3987,
29035,
199,
504,
14084,
21,
14,
10604,
492,
32495,
199,
199,
533,
12178,
1716,
8,
49,
3987,
29035,
304,
272,
347,
636,
826,
721,
277,
12,
1305,
12,
536,
12,
3164,
12,
1676,
29,
403,
304,
267,
1613,
8,
49,
3987,
29035,
12,
291,
2843,
826,
721,
1708,
9,
398,
291,
14,
1708,
2081,
275,
1676,
267,
291,
14,
344,
275,
1305,
267,
291,
14,
354,
275,
536,
267,
291,
14,
2326,
275,
3164,
267,
291,
14,
1739,
7412,
275,
942,
339,
347,
8020,
8,
277,
304,
267,
8020,
275,
32495,
8,
277,
14,
2326,
9,
267,
372,
8020,
339,
347,
5666,
3493,
8,
277,
12,
1242,
304,
267,
291,
14,
1739,
7412,
14,
740,
8,
1053,
9,
339,
347,
2813,
3493,
8,
277,
12,
1242,
304,
267,
291,
14,
1739,
7412,
14,
2168,
8,
1053,
9,
339,
347,
1982,
8,
277,
12,
1962,
304,
267,
372,
291,
14,
1739,
7412,
59,
1143,
61,
339,
347,
1982,
2353,
8,
277,
304,
267,
372,
822,
8,
277,
14,
1739,
7412,
9,
339,
347,
2763,
2353,
8,
277,
304,
267,
372,
499,
339,
347,
666,
8,
277,
12,
2763,
304,
267,
340,
2763,
508,
378,
26,
288,
372,
291,
14,
344,
267,
340,
2763,
508,
413,
26,
288,
372,
291,
14,
354,
339,
347,
1676,
8,
277,
304,
267,
372,
291,
14,
1708,
2081,
339,
347,
1962,
8,
277,
304,
267,
340,
291,
14,
1708,
2081,
26,
288,
372,
291,
14,
1708,
2081,
14,
1739,
7412,
14,
1080,
8,
277,
9,
267,
372,
378,
339,
347,
664,
7139,
8,
277,
304,
267,
372,
291,
14,
1739,
7412,
339,
347,
663,
4117,
8,
277,
12,
3164,
304,
267,
291,
14,
2326,
275,
3164,
339,
347,
2813,
7139,
8,
277,
304,
267,
2150,
291,
14,
1739,
7412,
5873,
339,
347,
3002,
31483,
8,
277,
12,
1242,
12,
2763,
304,
267,
327,
870,
360,
11276,
4881,
435,
620,
8,
1053,
430,
267,
986,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2043,
1898,
334,
35,
9,
9013,
23,
13,
10680,
1603,
11733,
17800,
23493,
11682,
8410,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
2043,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
2043,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
2043,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
8410,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
2043,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
2043,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
2043,
1664,
11243,
1696,
1684,
844,
367,
1655,
2436,
14,
8410,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
2043,
3180,
543,
642,
2240,
27,
340,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
8410,
6642,
520,
20049,
290,
437,
338,
75,
334,
305,
3258,
14,
745,
290,
32,
6799,
14,
957,
9,
819,
1449,
199,
504,
14084,
21,
14,
29081,
492,
1413,
3987,
29035,
199,
504,
14084,
21,
14,
10604,
492,
32495,
199,
199,
533,
12178,
1716,
8,
49,
3987,
29035,
304,
272,
347,
636,
826,
721,
277,
12,
1305,
12,
536,
12,
3164,
12,
1676,
29,
403,
304,
267,
1613,
8,
49,
3987,
29035,
12,
291,
2843,
826,
721,
1708,
9,
398,
291,
14,
1708,
2081,
275,
1676,
267,
291,
14,
344,
275,
1305,
267,
291,
14,
354,
275,
536,
267,
291,
14,
2326,
275,
3164,
267,
291,
14,
1739,
7412,
275,
942,
339,
347,
8020,
8,
277,
304,
267,
8020,
275,
32495,
8,
277,
14,
2326,
9,
267,
372,
8020,
339,
347,
5666,
3493,
8,
277,
12,
1242,
304,
267,
291,
14,
1739,
7412,
14,
740,
8,
1053,
9,
339,
347,
2813,
3493,
8,
277,
12,
1242,
304,
267,
291,
14,
1739,
7412,
14,
2168,
8,
1053,
9,
339,
347,
1982,
8,
277,
12,
1962,
304,
267,
372,
291,
14,
1739,
7412,
59,
1143,
61,
339,
347,
1982,
2353,
8,
277,
304,
267,
372,
822,
8,
277,
14,
1739,
7412,
9,
339,
347,
2763,
2353,
8,
277,
304,
267,
372,
499,
339,
347,
666,
8,
277,
12,
2763,
304,
267,
340,
2763,
508,
378,
26,
288,
372,
291,
14,
344,
267,
340,
2763,
508,
413,
26,
288,
372,
291,
14,
354,
339,
347,
1676,
8,
277,
304,
267,
372,
291,
14,
1708,
2081,
339,
347,
1962,
8,
277,
304,
267,
340,
291,
14,
1708,
2081,
26,
288,
372,
291,
14,
1708,
2081,
14,
1739,
7412,
14,
1080,
8,
277,
9,
267,
372,
378,
339,
347,
664,
7139,
8,
277,
304,
267,
372,
291,
14,
1739,
7412,
339,
347,
663,
4117,
8,
277,
12,
3164,
304,
267,
291,
14,
2326,
275,
3164,
339,
347,
2813,
7139,
8,
277,
304,
267,
2150,
291,
14,
1739,
7412,
5873,
339,
347,
3002,
31483,
8,
277,
12,
1242,
12,
2763,
304,
267,
327,
870,
360,
11276,
4881,
435,
620,
8,
1053,
430,
267,
986,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
dhimmel/hetio
|
hetnetpy/permute.py
|
1
|
9110
|
import collections
import random
import logging
from hetnetpy.hetnet import Graph
def permute_graph(graph, multiplier=10, seed=0, metaedge_to_excluded=dict(), log=False):
"""
Derive a permuted hetnet from an input hetnet. This method applies the
XSwap algorithm separately for each metaedge. Hence, node degree is
preserved for each type of edge. However, edges are randomized / shuffled.
Users are recommended to interrogate the reported statistics to ensure that
edges appear to be sufficiently randomized. Primarily, the number of edges
of a given metaedge that remain unchanged from the original hetnet should
have reached an assymptote. If the number of unchanged edges has not yet
stabalized, further randomization is possible with this approach.
Parameters
----------
graph : hetnetpy.hetnet.Graph
Input hetnet to create a permuted derivative from
multiplier : int or float
This is multiplied by the number of edges for each metaedge to
determine the number of swaps to attempt.
seed : int
Seed to initialize Python random number generator. When creating many
permuted hetnets, it's recommended to increment this number, such that
each round of permutation shuffles edges in a different order.
metaedge_to_excluded : dict (metaedge -> set)
Edges to exclude. This argument has not been extensively used in
practice.
log : bool
Whether to log diagnostic INFO via python's logging module.
Returns
-------
permuted_graph : hetnetpy.hetnet.Graph
A permuted hetnet derived from the input graph.
stats : list of dicts
A list where each item is a dictionary of permutation statistics at a
checkpoint for a specific metaedge. These statistics allow tracking the
progress of the permutation as the number of attempted swaps increases.
"""
if log:
logging.info("Creating permuted graph template")
permuted_graph = Graph(graph.metagraph)
for (metanode_identifier, node_identifier), node in graph.node_dict.items():
permuted_graph.add_node(
metanode_identifier, node_identifier, name=node.name, data=node.data
)
if log:
logging.info("Retrieving graph edges")
metaedge_to_edges = graph.get_metaedge_to_edges(exclude_inverts=True)
if log:
logging.info("Adding permuted edges")
all_stats = list()
for metaedge, edges in metaedge_to_edges.items():
if log:
logging.info(metaedge)
excluded_pair_set = metaedge_to_excluded.get(metaedge, set())
pair_list = [(edge.source.get_id(), edge.target.get_id()) for edge in edges]
directed = metaedge.direction != "both"
permuted_pair_list, stats = permute_pair_list(
pair_list,
directed=directed,
multiplier=multiplier,
excluded_pair_set=excluded_pair_set,
seed=seed,
log=log,
)
for stat in stats:
stat["metaedge"] = metaedge
stat["abbrev"] = metaedge.abbrev
all_stats.extend(stats)
for pair in permuted_pair_list:
permuted_graph.add_edge(pair[0], pair[1], metaedge.kind, metaedge.direction)
return permuted_graph, all_stats
def permute_pair_list(
pair_list,
directed=False,
multiplier=10,
excluded_pair_set=set(),
seed=0,
log=False,
inplace=False,
):
"""
Permute edges (of a single type) in a graph according to the XSwap function
described in https://doi.org/f3mn58. This method selects two edges and
attempts to swap their endpoints. If the swap would result in a valid edge,
the swap proceeds. Otherwise, the swap is skipped. The end result is that
node degree is preserved, but edges are shuffled, thereby losing their
original meaning.
Parameters
----------
pair_list : list of tuples
List of edges to permute. Each edge is represented as a (source,
target) tuple. source and target represent nodes and can be any Python
objects that define __eq__. In other words, this function does not
assume any specific format for nodes. If the edges are from a bipartite
or directed graph, then all tuples must have the same alignment. For
example, if the edges represent the bipartite Compound-binds-Gene
relationship, all tuples should be of the form (compound, gene) and not
intermixed with (gene, compound) tuples. The only instance where order
of the source and target is not important is for an undirected edge
type where the source and target nodes are of the same type, such as
Gene-interacts-Gene.
directed : bool
Whether the edge should be considered directed. If False, a swap that
creates an a-b edge will be invalid if a b-a edge already exists.
multiplier : int or float
This is multiplied by the number of edges in pair_list to determine the
number of swaps to attempt.
excluded_pair_set : set of tuples:
Set of possible edges to forbid. If a swap would create an edge in this
set, it would be considered invalid and hence skipped.
seed : int
Seed to initialize Python random number generator.
log : bool
Whether to log diagnostic INFO via python's logging module.
inplace : bool
Whether to modify the edge list in place.
Returns
-------
pair_list : list of tuples
The permuted edges, derived from the input pair_list.
stats : list of dicts
A list where each item is a dictionary of permutation statistics at a
checkpoint. Statistics are collected at 10 checkpoints, spaced evenly
by the number of attempts.
"""
random.seed(seed)
if not inplace:
pair_list = pair_list.copy()
pair_set = set(pair_list)
assert len(pair_set) == len(pair_list)
edge_number = len(pair_list)
n_perm = int(edge_number * multiplier)
count_same_edge = 0
count_self_loop = 0
count_duplicate = 0
count_undir_dup = 0
count_excluded = 0
if log:
logging.info(
"{} edges, {} permutations (seed = {}, directed = {}, {} excluded_edges)".format(
edge_number, n_perm, seed, directed, len(excluded_pair_set)
)
)
orig_pair_set = pair_set.copy()
step = max(1, n_perm // 10)
print_at = list(range(step, n_perm, step)) + [n_perm - 1]
stats = list()
for i in range(n_perm):
# Same two random edges
i_0 = random.randrange(edge_number)
i_1 = random.randrange(edge_number)
# Same edge selected twice
if i_0 == i_1:
count_same_edge += 1
continue
pair_0 = pair_list.pop(i_0)
pair_1 = pair_list.pop(i_1 - 1 if i_0 < i_1 else i_1)
new_pair_0 = pair_0[0], pair_1[1]
new_pair_1 = pair_1[0], pair_0[1]
valid = False
for pair in new_pair_0, new_pair_1:
if pair[0] == pair[1]:
count_self_loop += 1
break # edge is a self-loop
if pair in pair_set:
count_duplicate += 1
break # edge is a duplicate
if not directed and (pair[1], pair[0]) in pair_set:
count_undir_dup += 1
break # edge is a duplicate
if pair in excluded_pair_set:
count_excluded += 1
break # edge is excluded
else:
# edge passed all validity conditions
valid = True
# If new edges are invalid
if not valid:
for pair in pair_0, pair_1:
pair_list.append(pair)
# If new edges are valid
else:
for pair in pair_0, pair_1:
pair_set.remove(pair)
for pair in new_pair_0, new_pair_1:
pair_set.add(pair)
pair_list.append(pair)
if i in print_at:
stat = collections.OrderedDict()
stat["cumulative_attempts"] = i
index = print_at.index(i)
stat["attempts"] = (
print_at[index] + 1
if index == 0
else print_at[index] - print_at[index - 1]
)
stat["complete"] = (i + 1) / n_perm
stat["unchanged"] = len(orig_pair_set & pair_set) / len(pair_set)
stat["same_edge"] = count_same_edge / stat["attempts"]
stat["self_loop"] = count_self_loop / stat["attempts"]
stat["duplicate"] = count_duplicate / stat["attempts"]
stat["undirected_duplicate"] = count_undir_dup / stat["attempts"]
stat["excluded"] = count_excluded / stat["attempts"]
stats.append(stat)
count_same_edge = 0
count_self_loop = 0
count_duplicate = 0
count_undir_dup = 0
count_excluded = 0
assert len(pair_set) == edge_number
return pair_list, stats
|
cc0-1.0
|
[
646,
5055,
199,
646,
2196,
199,
646,
2050,
199,
199,
504,
394,
386,
846,
647,
14,
72,
386,
846,
492,
11513,
421,
199,
318,
10869,
938,
63,
2180,
8,
2180,
12,
22215,
29,
709,
12,
6347,
29,
16,
12,
3404,
5173,
63,
475,
63,
12144,
29,
807,
1062,
943,
29,
797,
304,
272,
408,
272,
18674,
1912,
282,
10869,
4241,
394,
386,
846,
687,
376,
1324,
394,
386,
846,
14,
961,
1083,
12966,
314,
272,
1323,
18385,
5563,
18159,
367,
1924,
3404,
5173,
14,
869,
4894,
12,
1031,
13666,
365,
272,
17731,
367,
1924,
730,
402,
6275,
14,
9738,
12,
8207,
787,
2196,
1759,
1182,
28126,
1146,
14,
339,
20123,
787,
14318,
370,
1640,
13095,
314,
14581,
11076,
370,
4868,
626,
272,
8207,
7468,
370,
506,
19258,
590,
2196,
1759,
14,
8538,
30468,
12,
314,
1329,
402,
8207,
272,
402,
282,
1627,
3404,
5173,
626,
5706,
14874,
687,
314,
3379,
394,
386,
846,
1077,
272,
1172,
13075,
376,
2661,
89,
311,
475,
266,
14,
982,
314,
1329,
402,
14874,
8207,
965,
440,
5966,
272,
410,
371,
279,
1759,
12,
9848,
2196,
2072,
365,
3962,
543,
642,
18140,
14,
339,
3897,
272,
4143,
272,
3343,
520,
394,
386,
846,
647,
14,
72,
386,
846,
14,
4578,
267,
6924,
394,
386,
846,
370,
1218,
282,
10869,
4241,
18883,
687,
272,
22215,
520,
1109,
503,
2069,
267,
961,
365,
29597,
701,
314,
1329,
402,
8207,
367,
1924,
3404,
5173,
370,
267,
6705,
314,
1329,
402,
5584,
7461,
370,
7427,
14,
272,
6347,
520,
1109,
267,
3240,
379,
370,
8265,
2018,
2196,
1329,
4306,
14,
3979,
6425,
5002,
267,
10869,
4241,
394,
386,
20490,
12,
652,
1159,
14318,
370,
11609,
642,
1329,
12,
4066,
626,
267,
1924,
6168,
402,
22966,
28126,
2978,
8207,
315,
282,
3365,
1865,
14,
272,
3404,
5173,
63,
475,
63,
12144,
520,
1211,
334,
2024,
5173,
1035,
663,
9,
267,
17379,
3389,
370,
5760,
14,
961,
1423,
965,
440,
2757,
2178,
9840,
1202,
315,
267,
24471,
14,
272,
943,
520,
2155,
267,
7480,
370,
943,
8348,
19075,
24008,
4799,
2366,
1159,
2050,
859,
14,
339,
1803,
272,
5514,
272,
10869,
4241,
63,
2180,
520,
394,
386,
846,
647,
14,
72,
386,
846,
14,
4578,
267,
437,
10869,
4241,
394,
386,
846,
7131,
687,
314,
1324,
3343,
14,
272,
5020,
520,
769,
402,
10809,
267,
437,
769,
2382,
1924,
1242,
365,
282,
2600,
402,
22966,
11076,
737,
282,
267,
9997,
367,
282,
2488,
3404,
5173,
14,
5723,
11076,
2040,
15161,
314,
267,
6696,
402,
314,
22966,
465,
314,
1329,
402,
22040,
5584,
7461,
10035,
3274,
14,
272,
408,
339,
340,
943,
26,
267,
2050,
14,
815,
480,
14380,
10869,
4241,
3343,
1978,
531,
272,
10869,
4241,
63,
2180,
275,
11513,
8,
2180,
14,
2024,
2180,
9,
272,
367,
334,
10207,
290,
380,
63,
5364,
12,
1031,
63,
5364,
395,
1031,
315,
3343,
14,
932,
63,
807,
14,
1744,
837,
267,
10869,
4241,
63,
2180,
14,
525,
63,
932,
8,
288,
7647,
290,
380,
63,
5364,
12,
1031,
63,
5364,
12,
536,
29,
932,
14,
354,
12,
666,
29,
932,
14,
576,
267,
776,
339,
340,
943,
26,
267,
2050,
14,
815,
480,
6816,
11317,
4007,
3343,
8207,
531,
272,
3404,
5173,
63,
475,
63,
6929,
275,
3343,
14,
362,
63,
2024,
5173,
63,
475,
63,
6929,
8,
5473,
63,
262,
21505,
29,
549,
9,
339,
340,
943,
26,
267,
2050,
14,
815,
480,
20897,
10869,
4241,
8207,
531,
339,
1006,
63,
3200,
275,
769,
342,
272,
367,
3404,
5173,
12,
8207,
315,
3404,
5173,
63,
475,
63,
6929,
14,
1744,
837,
267,
340,
943,
26,
288,
2050,
14,
815,
8,
2024,
5173,
9,
398,
8789,
63,
3852,
63,
409,
275,
3404,
5173,
63,
475,
63,
12144,
14,
362,
8,
2024,
5173,
12,
663,
1012,
267,
4092,
63,
513,
275,
3842,
5173,
14,
1365,
14,
362,
63,
344,
1062,
6275,
14,
1375,
14,
362,
63,
344,
1012,
367,
6275,
315,
8207,
61,
267,
23667,
275,
3404,
5173,
14,
6874,
1137,
298,
10727,
2,
267,
10869,
4241,
63,
3852,
63,
513,
12,
5020,
275,
10869,
938,
63,
3852,
63,
513,
8,
288,
4092,
63,
513,
12,
288,
23667,
29,
12080,
12,
288,
22215,
29,
15812,
12,
288,
8789,
63,
3852,
63,
409,
29,
12144,
63,
3852,
63,
409,
12,
288,
6347,
29,
5176,
12,
288,
943,
29,
793,
12,
267,
776,
267,
367,
5672,
315,
5020,
26,
288,
5672,
905,
2024,
5173,
937,
275,
3404,
5173,
288,
5672,
905,
31349,
937,
275,
3404,
5173,
14,
31349,
267,
1006,
63,
3200,
14,
2880,
8,
3200,
9,
398,
367,
4092,
315,
10869,
4241,
63,
3852,
63,
513,
26,
288,
10869,
4241,
63,
2180,
14,
525,
63,
5173,
8,
3852,
59,
16,
467,
4092,
59,
17,
467,
3404,
5173,
14,
5091,
12,
3404,
5173,
14,
6874,
9,
339,
372,
10869,
4241,
63,
2180,
12,
1006,
63,
3200,
421,
199,
318,
10869,
938,
63,
3852,
63,
513,
8,
272,
4092,
63,
513,
12,
272,
23667,
29,
797,
12,
272,
22215,
29,
709,
12,
272,
8789,
63,
3852,
63,
409,
29,
409,
1062,
272,
6347,
29,
16,
12,
272,
943,
29,
797,
12,
272,
16304,
29,
797,
12,
199,
304,
272,
408,
272,
3492,
12423,
8207,
334,
1618,
282,
2849,
730,
9,
315,
282,
3343,
7182,
370,
314,
1323,
18385,
805,
272,
11736,
315,
4178,
921,
27334,
14,
1308,
15,
70,
19,
10344,
2010,
14,
961,
1083,
24750,
2877,
8207,
436,
272,
12454,
370,
11413,
3932,
16173,
14,
982,
314,
11413,
3955,
754,
315,
282,
1686,
6275,
12,
272,
314,
11413,
557,
301,
5923,
14,
6630,
12,
314,
11413,
365,
9645,
14,
710,
1284,
754,
365,
626,
272,
1031,
13666,
365,
17731,
12,
1325,
8207,
787,
28126,
1146,
12,
2337,
991,
560,
1044,
3932,
272,
3379,
11150,
14,
339,
3897,
272,
4143,
272,
4092,
63,
513,
520,
769,
402,
6346,
267,
3820,
402,
8207,
370,
10869,
938,
14,
7048,
6275,
365,
11159,
465,
282,
334,
1365,
12,
267,
1347,
9,
2008,
14,
1350,
436,
1347,
2954,
3380,
436,
883,
506,
1263,
2018,
267,
2251,
626,
5627,
636,
4077,
4343,
1010,
1163,
5932,
12,
642,
805,
1630,
440,
267,
5534,
1263,
2488,
1475,
367,
3380,
14,
982,
314,
8207,
787,
687,
282,
12111
] |
[
5055,
199,
646,
2196,
199,
646,
2050,
199,
199,
504,
394,
386,
846,
647,
14,
72,
386,
846,
492,
11513,
421,
199,
318,
10869,
938,
63,
2180,
8,
2180,
12,
22215,
29,
709,
12,
6347,
29,
16,
12,
3404,
5173,
63,
475,
63,
12144,
29,
807,
1062,
943,
29,
797,
304,
272,
408,
272,
18674,
1912,
282,
10869,
4241,
394,
386,
846,
687,
376,
1324,
394,
386,
846,
14,
961,
1083,
12966,
314,
272,
1323,
18385,
5563,
18159,
367,
1924,
3404,
5173,
14,
869,
4894,
12,
1031,
13666,
365,
272,
17731,
367,
1924,
730,
402,
6275,
14,
9738,
12,
8207,
787,
2196,
1759,
1182,
28126,
1146,
14,
339,
20123,
787,
14318,
370,
1640,
13095,
314,
14581,
11076,
370,
4868,
626,
272,
8207,
7468,
370,
506,
19258,
590,
2196,
1759,
14,
8538,
30468,
12,
314,
1329,
402,
8207,
272,
402,
282,
1627,
3404,
5173,
626,
5706,
14874,
687,
314,
3379,
394,
386,
846,
1077,
272,
1172,
13075,
376,
2661,
89,
311,
475,
266,
14,
982,
314,
1329,
402,
14874,
8207,
965,
440,
5966,
272,
410,
371,
279,
1759,
12,
9848,
2196,
2072,
365,
3962,
543,
642,
18140,
14,
339,
3897,
272,
4143,
272,
3343,
520,
394,
386,
846,
647,
14,
72,
386,
846,
14,
4578,
267,
6924,
394,
386,
846,
370,
1218,
282,
10869,
4241,
18883,
687,
272,
22215,
520,
1109,
503,
2069,
267,
961,
365,
29597,
701,
314,
1329,
402,
8207,
367,
1924,
3404,
5173,
370,
267,
6705,
314,
1329,
402,
5584,
7461,
370,
7427,
14,
272,
6347,
520,
1109,
267,
3240,
379,
370,
8265,
2018,
2196,
1329,
4306,
14,
3979,
6425,
5002,
267,
10869,
4241,
394,
386,
20490,
12,
652,
1159,
14318,
370,
11609,
642,
1329,
12,
4066,
626,
267,
1924,
6168,
402,
22966,
28126,
2978,
8207,
315,
282,
3365,
1865,
14,
272,
3404,
5173,
63,
475,
63,
12144,
520,
1211,
334,
2024,
5173,
1035,
663,
9,
267,
17379,
3389,
370,
5760,
14,
961,
1423,
965,
440,
2757,
2178,
9840,
1202,
315,
267,
24471,
14,
272,
943,
520,
2155,
267,
7480,
370,
943,
8348,
19075,
24008,
4799,
2366,
1159,
2050,
859,
14,
339,
1803,
272,
5514,
272,
10869,
4241,
63,
2180,
520,
394,
386,
846,
647,
14,
72,
386,
846,
14,
4578,
267,
437,
10869,
4241,
394,
386,
846,
7131,
687,
314,
1324,
3343,
14,
272,
5020,
520,
769,
402,
10809,
267,
437,
769,
2382,
1924,
1242,
365,
282,
2600,
402,
22966,
11076,
737,
282,
267,
9997,
367,
282,
2488,
3404,
5173,
14,
5723,
11076,
2040,
15161,
314,
267,
6696,
402,
314,
22966,
465,
314,
1329,
402,
22040,
5584,
7461,
10035,
3274,
14,
272,
408,
339,
340,
943,
26,
267,
2050,
14,
815,
480,
14380,
10869,
4241,
3343,
1978,
531,
272,
10869,
4241,
63,
2180,
275,
11513,
8,
2180,
14,
2024,
2180,
9,
272,
367,
334,
10207,
290,
380,
63,
5364,
12,
1031,
63,
5364,
395,
1031,
315,
3343,
14,
932,
63,
807,
14,
1744,
837,
267,
10869,
4241,
63,
2180,
14,
525,
63,
932,
8,
288,
7647,
290,
380,
63,
5364,
12,
1031,
63,
5364,
12,
536,
29,
932,
14,
354,
12,
666,
29,
932,
14,
576,
267,
776,
339,
340,
943,
26,
267,
2050,
14,
815,
480,
6816,
11317,
4007,
3343,
8207,
531,
272,
3404,
5173,
63,
475,
63,
6929,
275,
3343,
14,
362,
63,
2024,
5173,
63,
475,
63,
6929,
8,
5473,
63,
262,
21505,
29,
549,
9,
339,
340,
943,
26,
267,
2050,
14,
815,
480,
20897,
10869,
4241,
8207,
531,
339,
1006,
63,
3200,
275,
769,
342,
272,
367,
3404,
5173,
12,
8207,
315,
3404,
5173,
63,
475,
63,
6929,
14,
1744,
837,
267,
340,
943,
26,
288,
2050,
14,
815,
8,
2024,
5173,
9,
398,
8789,
63,
3852,
63,
409,
275,
3404,
5173,
63,
475,
63,
12144,
14,
362,
8,
2024,
5173,
12,
663,
1012,
267,
4092,
63,
513,
275,
3842,
5173,
14,
1365,
14,
362,
63,
344,
1062,
6275,
14,
1375,
14,
362,
63,
344,
1012,
367,
6275,
315,
8207,
61,
267,
23667,
275,
3404,
5173,
14,
6874,
1137,
298,
10727,
2,
267,
10869,
4241,
63,
3852,
63,
513,
12,
5020,
275,
10869,
938,
63,
3852,
63,
513,
8,
288,
4092,
63,
513,
12,
288,
23667,
29,
12080,
12,
288,
22215,
29,
15812,
12,
288,
8789,
63,
3852,
63,
409,
29,
12144,
63,
3852,
63,
409,
12,
288,
6347,
29,
5176,
12,
288,
943,
29,
793,
12,
267,
776,
267,
367,
5672,
315,
5020,
26,
288,
5672,
905,
2024,
5173,
937,
275,
3404,
5173,
288,
5672,
905,
31349,
937,
275,
3404,
5173,
14,
31349,
267,
1006,
63,
3200,
14,
2880,
8,
3200,
9,
398,
367,
4092,
315,
10869,
4241,
63,
3852,
63,
513,
26,
288,
10869,
4241,
63,
2180,
14,
525,
63,
5173,
8,
3852,
59,
16,
467,
4092,
59,
17,
467,
3404,
5173,
14,
5091,
12,
3404,
5173,
14,
6874,
9,
339,
372,
10869,
4241,
63,
2180,
12,
1006,
63,
3200,
421,
199,
318,
10869,
938,
63,
3852,
63,
513,
8,
272,
4092,
63,
513,
12,
272,
23667,
29,
797,
12,
272,
22215,
29,
709,
12,
272,
8789,
63,
3852,
63,
409,
29,
409,
1062,
272,
6347,
29,
16,
12,
272,
943,
29,
797,
12,
272,
16304,
29,
797,
12,
199,
304,
272,
408,
272,
3492,
12423,
8207,
334,
1618,
282,
2849,
730,
9,
315,
282,
3343,
7182,
370,
314,
1323,
18385,
805,
272,
11736,
315,
4178,
921,
27334,
14,
1308,
15,
70,
19,
10344,
2010,
14,
961,
1083,
24750,
2877,
8207,
436,
272,
12454,
370,
11413,
3932,
16173,
14,
982,
314,
11413,
3955,
754,
315,
282,
1686,
6275,
12,
272,
314,
11413,
557,
301,
5923,
14,
6630,
12,
314,
11413,
365,
9645,
14,
710,
1284,
754,
365,
626,
272,
1031,
13666,
365,
17731,
12,
1325,
8207,
787,
28126,
1146,
12,
2337,
991,
560,
1044,
3932,
272,
3379,
11150,
14,
339,
3897,
272,
4143,
272,
4092,
63,
513,
520,
769,
402,
6346,
267,
3820,
402,
8207,
370,
10869,
938,
14,
7048,
6275,
365,
11159,
465,
282,
334,
1365,
12,
267,
1347,
9,
2008,
14,
1350,
436,
1347,
2954,
3380,
436,
883,
506,
1263,
2018,
267,
2251,
626,
5627,
636,
4077,
4343,
1010,
1163,
5932,
12,
642,
805,
1630,
440,
267,
5534,
1263,
2488,
1475,
367,
3380,
14,
982,
314,
8207,
787,
687,
282,
12111,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
coetzeevs/chiron
|
mysite/polls/views.py
|
1
|
1976
|
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse, HttpResponseRedirect
from django.template import loader
from .models import Question, Choice
from django.urls import reverse
from django.views import generic
from django.utils import timezone
from django.core.mail import EmailMessage
from django.conf import settings
class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_question_list'
def get_queryset(self):
"""
Return the last five published questions (not including those set to be
published in the future).
"""
return Question.objects.filter(
pub_date__lte=timezone.now()
).order_by('-pub_date')[:5]
class DetailView(generic.DetailView):
model = Question
template_name = 'polls/detail.html'
def get_queryset(self):
"""
Excludes any questions that aren't published yet.
"""
return Question.objects.filter(pub_date__lte=timezone.now())
class ResultsView(generic.DetailView):
model = Question
template_name = 'polls/results.html'
def email(request):
email = EmailMessage('hello', 'Hello Johan, Minder OLX en meer ChiChi',settings.EMAIL_HOST_USER, to=['johan.duplessis@olx.com'])
email.send()
return HttpResponse("Hello, world. You're at the polls index.")
def vote(request, question_id):
question = get_object_or_404(Question, pk=question_id)
try:
selected_choice = question.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist):
# Redisplay the question voting form.
return render(request, 'polls/detail.html', {
'question': question,
'error_message': "You didn't select a choice.",
})
else:
selected_choice.votes += 1
selected_choice.save()
# Always return an HttpResponseRedirect after successfully dealing
# with POST data. This prevents data from being posted twice if a
# user hits the Back button.
return HttpResponseRedirect(reverse('polls:results', args=(question.id,)))
|
mit
|
[
504,
1639,
14,
17469,
492,
3795,
12,
664,
63,
785,
63,
269,
63,
5188,
199,
504,
1639,
14,
1014,
492,
6183,
12,
14935,
199,
504,
1639,
14,
1160,
492,
5077,
199,
504,
1275,
992,
492,
21421,
12,
16053,
199,
504,
1639,
14,
3603,
492,
3837,
199,
504,
1639,
14,
4196,
492,
7809,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
1018,
14,
1198,
492,
11426,
2209,
199,
504,
1639,
14,
2190,
492,
2202,
421,
199,
533,
5499,
2768,
8,
6767,
14,
23239,
304,
199,
198,
1160,
63,
354,
275,
283,
2515,
478,
15,
1080,
14,
1360,
7,
199,
198,
1100,
63,
785,
63,
354,
275,
283,
7410,
63,
4790,
63,
513,
7,
4388,
198,
318,
664,
63,
7924,
8,
277,
304,
507,
198,
624,
507,
198,
1767,
314,
2061,
24187,
3267,
23071,
334,
1397,
5893,
5204,
663,
370,
506,
507,
198,
8987,
315,
314,
6466,
680,
507,
198,
624,
507,
198,
1107,
21421,
14,
1462,
14,
1541,
8,
15075,
7974,
63,
602,
363,
20740,
29,
7145,
14,
2131,
342,
507,
198,
680,
1648,
63,
991,
3654,
5645,
63,
602,
358,
1491,
21,
61,
421,
199,
533,
13302,
2768,
8,
6767,
14,
28539,
304,
199,
198,
1238,
275,
21421,
199,
198,
1160,
63,
354,
275,
283,
2515,
478,
15,
5506,
14,
1360,
7,
199,
198,
318,
664,
63,
7924,
8,
277,
304,
507,
198,
624,
507,
198,
29448,
83,
1263,
23071,
626,
10621,
1133,
3267,
5966,
14,
507,
198,
624,
507,
198,
1107,
21421,
14,
1462,
14,
1541,
8,
5645,
63,
602,
363,
20740,
29,
7145,
14,
2131,
1012,
421,
199,
533,
24288,
2768,
8,
6767,
14,
28539,
304,
199,
198,
1238,
275,
21421,
199,
198,
1160,
63,
354,
275,
283,
2515,
478,
15,
2604,
14,
1360,
7,
421,
199,
318,
3031,
8,
1069,
304,
199,
198,
2123,
275,
11426,
2209,
360,
5006,
297,
283,
6257,
7135,
19262,
12,
603,
5755,
593,
44,
56,
655,
562,
281,
2799,
73,
29218,
297,
1751,
14,
10089,
63,
5449,
63,
3791,
12,
221,
370,
2968,
743,
19262,
14,
68,
1363,
83,
2316,
32,
393,
88,
14,
957,
1105,
199,
198,
2123,
14,
2254,
342,
199,
198,
1107,
6183,
480,
6257,
12,
6701,
14,
2047,
3984,
737,
314,
3708,
478,
1478,
2685,
199,
199,
318,
24337,
8,
1069,
12,
7894,
63,
344,
304,
199,
198,
4790,
275,
664,
63,
785,
63,
269,
63,
5188,
8,
16778,
12,
3803,
29,
4790,
63,
344,
9,
199,
198,
893,
26,
507,
198,
5511,
63,
5095,
275,
7894,
14,
5095,
63,
409,
14,
362,
8,
2051,
29,
1069,
14,
4030,
459,
5095,
1105,
199,
198,
2590,
334,
10230,
12,
16053,
14,
7400,
304,
507,
198,
3,
799,
2918,
314,
7894,
373,
15866,
1824,
14,
507,
198,
1107,
3795,
8,
1069,
12,
283,
2515,
478,
15,
5506,
14,
1360,
297,
469,
686,
198,
7,
4790,
356,
7894,
12,
686,
198,
7,
705,
63,
1188,
356,
298,
5556,
9980,
1133,
3504,
282,
7141,
4765,
507,
198,
1552,
199,
198,
2836,
26,
507,
198,
5511,
63,
5095,
14,
16660,
847,
413,
507,
198,
5511,
63,
5095,
14,
2117,
342,
507,
198,
3,
16763,
372,
376,
14935,
2410,
8792,
23654,
507,
198,
3,
543,
8761,
666,
14,
961,
21925,
666,
687,
3769,
22752,
13373,
340,
282,
507,
198,
3,
922,
19745,
314,
10257,
5528,
14,
507,
198,
1107,
14935,
8,
4471,
360,
2515,
478,
26,
2604,
297,
1249,
2687,
4790,
14,
344,
20097,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
17469,
492,
3795,
12,
664,
63,
785,
63,
269,
63,
5188,
199,
504,
1639,
14,
1014,
492,
6183,
12,
14935,
199,
504,
1639,
14,
1160,
492,
5077,
199,
504,
1275,
992,
492,
21421,
12,
16053,
199,
504,
1639,
14,
3603,
492,
3837,
199,
504,
1639,
14,
4196,
492,
7809,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
1018,
14,
1198,
492,
11426,
2209,
199,
504,
1639,
14,
2190,
492,
2202,
421,
199,
533,
5499,
2768,
8,
6767,
14,
23239,
304,
199,
198,
1160,
63,
354,
275,
283,
2515,
478,
15,
1080,
14,
1360,
7,
199,
198,
1100,
63,
785,
63,
354,
275,
283,
7410,
63,
4790,
63,
513,
7,
4388,
198,
318,
664,
63,
7924,
8,
277,
304,
507,
198,
624,
507,
198,
1767,
314,
2061,
24187,
3267,
23071,
334,
1397,
5893,
5204,
663,
370,
506,
507,
198,
8987,
315,
314,
6466,
680,
507,
198,
624,
507,
198,
1107,
21421,
14,
1462,
14,
1541,
8,
15075,
7974,
63,
602,
363,
20740,
29,
7145,
14,
2131,
342,
507,
198,
680,
1648,
63,
991,
3654,
5645,
63,
602,
358,
1491,
21,
61,
421,
199,
533,
13302,
2768,
8,
6767,
14,
28539,
304,
199,
198,
1238,
275,
21421,
199,
198,
1160,
63,
354,
275,
283,
2515,
478,
15,
5506,
14,
1360,
7,
199,
198,
318,
664,
63,
7924,
8,
277,
304,
507,
198,
624,
507,
198,
29448,
83,
1263,
23071,
626,
10621,
1133,
3267,
5966,
14,
507,
198,
624,
507,
198,
1107,
21421,
14,
1462,
14,
1541,
8,
5645,
63,
602,
363,
20740,
29,
7145,
14,
2131,
1012,
421,
199,
533,
24288,
2768,
8,
6767,
14,
28539,
304,
199,
198,
1238,
275,
21421,
199,
198,
1160,
63,
354,
275,
283,
2515,
478,
15,
2604,
14,
1360,
7,
421,
199,
318,
3031,
8,
1069,
304,
199,
198,
2123,
275,
11426,
2209,
360,
5006,
297,
283,
6257,
7135,
19262,
12,
603,
5755,
593,
44,
56,
655,
562,
281,
2799,
73,
29218,
297,
1751,
14,
10089,
63,
5449,
63,
3791,
12,
221,
370,
2968,
743,
19262,
14,
68,
1363,
83,
2316,
32,
393,
88,
14,
957,
1105,
199,
198,
2123,
14,
2254,
342,
199,
198,
1107,
6183,
480,
6257,
12,
6701,
14,
2047,
3984,
737,
314,
3708,
478,
1478,
2685,
199,
199,
318,
24337,
8,
1069,
12,
7894,
63,
344,
304,
199,
198,
4790,
275,
664,
63,
785,
63,
269,
63,
5188,
8,
16778,
12,
3803,
29,
4790,
63,
344,
9,
199,
198,
893,
26,
507,
198,
5511,
63,
5095,
275,
7894,
14,
5095,
63,
409,
14,
362,
8,
2051,
29,
1069,
14,
4030,
459,
5095,
1105,
199,
198,
2590,
334,
10230,
12,
16053,
14,
7400,
304,
507,
198,
3,
799,
2918,
314,
7894,
373,
15866,
1824,
14,
507,
198,
1107,
3795,
8,
1069,
12,
283,
2515,
478,
15,
5506,
14,
1360,
297,
469,
686,
198,
7,
4790,
356,
7894,
12,
686,
198,
7,
705,
63,
1188,
356,
298,
5556,
9980,
1133,
3504,
282,
7141,
4765,
507,
198,
1552,
199,
198,
2836,
26,
507,
198,
5511,
63,
5095,
14,
16660,
847,
413,
507,
198,
5511,
63,
5095,
14,
2117,
342,
507,
198,
3,
16763,
372,
376,
14935,
2410,
8792,
23654,
507,
198,
3,
543,
8761,
666,
14,
961,
21925,
666,
687,
3769,
22752,
13373,
340,
282,
507,
198,
3,
922,
19745,
314,
10257,
5528,
14,
507,
198,
1107,
14935,
8,
4471,
360,
2515,
478,
26,
2604,
297,
1249,
2687,
4790,
14,
344,
20097,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
yvesalexandre/bandicoot
|
bandicoot/__init__.py
|
1
|
1498
|
# The MIT License (MIT)
#
# Copyright (c) 2015-2016 Massachusetts Institute of Technology.
#
# 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.
__all__ = ['core', 'individual', 'spatial', 'recharge', 'network', 'helper', 'io', 'utils', 'tests']
from .io import read_csv, to_json, to_csv
from .core import User, Record, Recharge, Position
from . import individual, spatial, recharge, network, helper, utils, io, tests, core, visualization
import bandicoot.helper.tools
__version__ = "0.6.0"
|
mit
|
[
3,
710,
10697,
844,
334,
13965,
9,
199,
3,
199,
3,
1898,
334,
67,
9,
6900,
13,
9261,
603,
405,
1225,
29589,
1086,
1010,
25585,
402,
21580,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
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,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
199,
363,
452,
363,
275,
788,
1018,
297,
283,
23001,
297,
283,
11679,
297,
283,
264,
16441,
297,
283,
1200,
297,
283,
3676,
297,
283,
2308,
297,
283,
1208,
297,
283,
2219,
418,
199,
199,
504,
1275,
2308,
492,
1586,
63,
4737,
12,
370,
63,
1001,
12,
370,
63,
4737,
199,
504,
1275,
1018,
492,
2876,
12,
12651,
12,
799,
16441,
12,
15483,
199,
504,
1275,
492,
8212,
12,
11469,
12,
295,
16441,
12,
2784,
12,
5922,
12,
3778,
12,
5890,
12,
2295,
12,
6170,
12,
13104,
2072,
199,
199,
646,
30354,
27347,
357,
14,
3676,
14,
2537,
199,
199,
363,
1023,
363,
275,
298,
16,
14,
22,
14,
16,
2,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
710,
10697,
844,
334,
13965,
9,
199,
3,
199,
3,
1898,
334,
67,
9,
6900,
13,
9261,
603,
405,
1225,
29589,
1086,
1010,
25585,
402,
21580,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
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,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
199,
363,
452,
363,
275,
788,
1018,
297,
283,
23001,
297,
283,
11679,
297,
283,
264,
16441,
297,
283,
1200,
297,
283,
3676,
297,
283,
2308,
297,
283,
1208,
297,
283,
2219,
418,
199,
199,
504,
1275,
2308,
492,
1586,
63,
4737,
12,
370,
63,
1001,
12,
370,
63,
4737,
199,
504,
1275,
1018,
492,
2876,
12,
12651,
12,
799,
16441,
12,
15483,
199,
504,
1275,
492,
8212,
12,
11469,
12,
295,
16441,
12,
2784,
12,
5922,
12,
3778,
12,
5890,
12,
2295,
12,
6170,
12,
13104,
2072,
199,
199,
646,
30354,
27347,
357,
14,
3676,
14,
2537,
199,
199,
363,
1023,
363,
275,
298,
16,
14,
22,
14,
16,
2,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
sphaero/appie
|
appie/appie.py
|
1
|
10447
|
#!/usr/bin/python3
#
# Copyright (c) 2013, Arnaud Loonstra, All rights reserved.
# Copyright (c) 2013, Stichting z25.org, All rights reserved.
#
# This library 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.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License v3 for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
import os
import shutil
from functools import reduce
import textile
import json
import logging
import pprint
# for pre 3.5 python versions
try:
os.scandir
except AttributeError:
import scandir
os.scandir = scandir.scandir
logger = logging.getLogger(__name__)
config = {
'target': "./build",
'src': "./site_src"
}
def mergedicts(dict1, dict2):
for k in set(dict1.keys()).union(dict2.keys()):
if k in dict1 and k in dict2:
if isinstance(dict1[k], dict) and isinstance(dict2[k], dict):
yield (k, dict(mergedicts(dict1[k], dict2[k])))
else:
# If one of the values is not a dict, you can't continue merging it.
# Value from second dict overrides one in first and we move on.
yield (k, dict2[k])
# Alternatively, replace this with exception raiser to alert you of value conflicts
elif k in dict1:
yield (k, dict1[k])
else:
yield (k, dict2[k])
class AppieDirParser(object):
"""
The default dir parser. Searches for parsers matching file or
directory parsers. If none found it recurses into subdirs and
loads files prepended with '_'(underscore).
Files are copied to the build root.
A file is represented by a dictionary with at least the following keys
* content: file content if applicable
* path: filepath ( in the build dir )
* mtime: modification time
"""
def match(self, name):
"""
Test if this parser matches for a name
:param str name: file or directory name
"""
return False
def is_modified(self, dirobj, prev_dict):
"""
Check file's mtime and compares it to the previous run value
Returns true if newer
"""
if not prev_dict or not prev_dict.get(dirobj.name):
return True # no previous data found so modified
return dirobj.stat().st_mtime > prev_dict.get(dirobj.name)[ 'mtime' ]
def parse_dir(self, path, dest_path, prev_dict=None):
"""
Parse a directory. Will search parser to match file or directory names
:param str path: path of the directory
:param str dest_path: path of the destination directory
:param dict prev_dict: the dictionary belonging to this directory loaded
from a previous run
Returns the dictionary with contents of the directory
"""
prev_dict = prev_dict or {}
d = {}
for item in os.scandir(path):
# save the relative! path in the buildroot instead of the original
web_path = dest_path.split(config['target'])[1][1:]
if item.is_dir():
d[item.name] = self.parse_subdir( item, dest_path, prev_dict, web_path)
elif self.is_modified( item, prev_dict ):
# find a parser for this file
parser = Appie.match_file_parsers(item.name)
d[item.name] = parser.parse_file( item.path, item.name, dest_path )
d[item.name]['path'] = web_path
d[item.name]['mtime'] = item.stat().st_mtime
# copy file to dest if no content key
if not d[item.name].get( 'content' ) and parser.copyfile:
logging.debug("Copy file {0} to the directory {1}"\
.format(path, dest_path))
shutil.copy(item.path, dest_path)
else:
d[item.name] = prev_dict[item.name]
return d
def parse_subdir(self, diritem, dest_path, prev_dict, web_path):
ret = {}
new_dest_path = os.path.join(dest_path, diritem.name)
# first create its dir
try:
os.makedirs(new_dest_path)
except FileExistsError:
pass
# find a parser for this dir
parser = Appie.match_dir_parsers(diritem.name)
content = parser.parse_dir( diritem.path, new_dest_path, prev_dict.get( diritem.name ))
# add meta information if the parser returned content
if content:
content['path'] = web_path
content['mtime'] = diritem.stat().st_mtime
else:
# if not we can remove the dir TODO: does this hold?
# will error if new_dest_path not empty
os.remove(new_dest_path)
return content
class AppieFileParser(object):
"""
Appie default file parser. Loads the content of a file if
it starts with _ (underscore).
"""
def __init__(self, *args, **kwargs):
self.copyfile = True # use the flag to tell the dirparser
# to copy the file or not
def match(self, name):
"""
Matches on files with the extension .textile
"""
if name[0] == '_':
return True
def parse_file(self, path, filename, dest_path):
"""
Parse file. If it starts with '_' (underscore) it will be loaded
and returned as the content key in a dictionary
Override this method in a custom parser class and add any data you
need.
:param str path: Path to the file
:param str filename: The name of the file
"""
if self.match(filename): # we only test again because the FileParser is always returned if
return { 'content': self.load_file(path) } # no other parser matches but we only want to load if starting with _
return {}
def load_file(self, path, mode='r'):
"""
parse the file and return the content for the dict
:param str file: the path to the file
"""
with open(path, mode, encoding="utf8") as f:
data = f.read()
f.close()
return data
class AppieTextileParser(AppieFileParser):
"""
Simple textile file to html parser
"""
def match(self, name):
"""
Matches on files with the extension .textile
"""
logging.debug('Matching AppieTextileParser to {0}'.format(name))
if name.endswith('.textile'):
return True
def parse_file(self, path, filename, dest_path):
"""
Parses textile files to html.
:param path: full path of the file
:param filename: the name of the file
Returns a dictionary with the content of the file in the content
key!
"""
logging.debug("TextileParser parsing {0}".format(filename))
t = textile.textile(self.load_file(path))
return { 'content': t }
class Appie(object):
dir_parsers = []
file_parsers = []
def __init__(self, *args, **kwargs):
# check if string and convert to list if so
if isinstance(config["src"], str):
config["src"] = [config["src"]]
self._buildwd = os.path.abspath(config["target"])
def add_directory_parser(self, inst):
"""
Adds a parser instance to match on directory names
:param instance inst: parser instance
"""
Appie.dir_parsers.insert(0, inst)
def add_file_parser(self, inst):
"""
Adds a parser instance to match on filenames
:param instance inst: parser instance
"""
Appie.file_parsers.insert(0, inst)
@staticmethod
def match_dir_parsers(dirname):
"""
Returns the parser for the directory
:params str dirname: directory name to match on
"""
for p in Appie.dir_parsers:
if p.match(dirname):
return p
return AppieDirParser() # default is self
@staticmethod
def match_file_parsers(filename):
"""
Returns the parser for the file
:params str filename: filename to match on
"""
for p in Appie.file_parsers:
if p.match(filename):
return p
return AppieFileParser() # default is AppieFileParser
def parse(self):
"""
Parse the all source directories
"""
# create the buildroot
prev = None # previous all.json container
try:
os.makedirs(self._buildwd)
except FileExistsError:
# try to load previous run
try:
prev = self.load_dict( os.path.join(self._buildwd, 'all.json' ) )
except FileNotFoundError:
prev = None
final = {}
for src in config["src"]:
d = AppieDirParser().parse_dir( src, config["target"], prev )
final = dict(mergedicts(final, d))
#return final
self.save_dict(final, os.path.join(config["target"], 'all.json'))
def save_dict(self, d, filepath):
"""
Save dictionary to json file
:param dict d: the dictionary to save
:param string filepath: string containing the full target filepath
"""
with open(filepath, 'w') as f:
json.dump(d, f)
def load_dict(self, filepath):
"""
load json file
:param dict d: the dictionary to save
:param string filepath: string containing the full target filepath
"""
with open(filepath, 'r') as f:
d = json.load(f)
return d
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
config["src"] = '../tests/site_src'
a = Appie()
a.add_file_parser(AppieTextileParser())
a.parse()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
19,
199,
3,
221,
199,
3,
1898,
334,
67,
9,
6171,
12,
1952,
3540,
1181,
3835,
265,
14183,
12,
2900,
4481,
4644,
14,
199,
3,
1898,
334,
67,
9,
6171,
12,
428,
280,
335,
1337,
1315,
821,
14,
1308,
12,
2900,
4481,
4644,
14,
199,
3,
221,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
650,
14,
16,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
373,
19,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
14,
199,
199,
646,
747,
199,
646,
5145,
199,
504,
9143,
492,
7114,
199,
646,
14709,
7172,
199,
646,
2022,
199,
646,
2050,
199,
199,
646,
10933,
199,
199,
3,
367,
876,
650,
14,
21,
2366,
5459,
221,
199,
893,
26,
272,
747,
14,
6282,
694,
199,
2590,
4281,
26,
272,
492,
8000,
694,
272,
747,
14,
6282,
694,
275,
8000,
694,
14,
6282,
694,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
888,
275,
469,
272,
283,
1375,
356,
26069,
1506,
401,
5591,
283,
2164,
356,
26069,
2124,
63,
2164,
2,
221,
199,
93,
9948,
199,
318,
5389,
7892,
8,
807,
17,
12,
1211,
18,
304,
272,
367,
1022,
315,
663,
8,
807,
17,
14,
1612,
8801,
8888,
8,
807,
18,
14,
1612,
5109,
267,
340,
1022,
315,
1211,
17,
436,
1022,
315,
1211,
18,
26,
288,
340,
1228,
8,
807,
17,
59,
75,
467,
1211,
9,
436,
1228,
8,
807,
18,
59,
75,
467,
1211,
304,
355,
1995,
334,
75,
12,
1211,
8,
5628,
7892,
8,
807,
17,
59,
75,
467,
1211,
18,
59,
75,
11845,
288,
587,
26,
355,
327,
982,
1373,
402,
314,
1338,
365,
440,
282,
1211,
12,
1265,
883,
1133,
1980,
22537,
652,
14,
355,
327,
1594,
687,
3499,
1211,
10580,
1373,
315,
1642,
436,
781,
4057,
641,
14,
355,
1995,
334,
75,
12,
1211,
18,
59,
75,
566,
355,
327,
26776,
12,
3350,
642,
543,
1919,
660,
25696,
370,
10459,
1265,
402,
574,
18511,
267,
916,
1022,
315,
1211,
17,
26,
288,
1995,
334,
75,
12,
1211,
17,
59,
75,
566,
267,
587,
26,
288,
1995,
334,
75,
12,
1211,
18,
59,
75,
566,
421,
199,
533,
4693,
1873,
3567,
2842,
8,
785,
304,
272,
408,
272,
710,
849,
2935,
1798,
14,
8730,
397,
367,
21295,
4877,
570,
503,
5591,
2082,
21295,
14,
982,
7179,
1911,
652,
5344,
874,
1901,
31396,
436,
5591,
14404,
1584,
20247,
543,
2513,
6774,
21831,
680,
5591,
16920,
787,
8876,
370,
314,
1900,
1738,
14,
2286,
437,
570,
365,
11159,
701,
282,
2600,
543,
737,
5210,
314,
2569,
2883,
272,
627,
1564,
26,
570,
1564,
340,
3964,
272,
627,
931,
26,
9911,
334,
315,
314,
1900,
2935,
776,
272,
627,
15005,
26,
7100,
900,
272,
408,
14821,
347,
1336,
8,
277,
12,
536,
304,
267,
408,
267,
1379,
340,
642,
1798,
4450,
367,
282,
536,
2728,
520,
635,
620,
536,
26,
570,
503,
2082,
536,
267,
408,
4960,
372,
756,
5493,
347,
365,
63,
5540,
8,
277,
12,
487,
25327,
12,
5071,
63,
807,
304,
267,
408,
267,
2670,
570,
1159,
15005,
436,
30827,
652,
370,
314,
4136,
1255,
574,
2728,
1803,
2549,
340,
15666,
267,
408,
267,
340,
440,
5071,
63,
807,
503,
440,
5071,
63,
807,
14,
362,
8,
328,
25327,
14,
354,
304,
288,
372,
715,
257,
327,
949,
4136,
666,
1911,
880,
6042,
267,
372,
487,
25327,
14,
3736,
1252,
270,
63,
8180,
690,
5071,
63,
807,
14,
362,
8,
328,
25327,
14,
354,
2788,
283,
8180,
7,
1622,
18407,
347,
2198,
63,
694,
8,
277,
12,
931,
12,
2053,
63,
515,
12,
5071,
63,
807,
29,
403,
304,
267,
408,
267,
6077,
282,
2082,
14,
12823,
2754,
1798,
370,
1336,
570,
503,
2082,
1561,
2728,
520,
635,
620,
931,
26,
931,
402,
314,
2082,
267,
520,
635,
620,
2053,
63,
515,
26,
931,
402,
314,
5724,
2082,
267,
520,
635,
1211,
5071,
63,
807,
26,
314,
2600,
30226,
370,
642,
2082,
6511,
3044,
687,
282,
4136,
1255,
267,
1803,
314,
2600,
543,
4072,
402,
314,
2082,
267,
408,
267,
5071,
63,
807,
275,
5071,
63,
807,
503,
1052,
267,
366,
275,
1052,
267,
367,
1242,
315,
747,
14,
6282,
694,
8,
515,
304,
288,
327,
3354,
314,
3847,
1,
931,
315,
314,
1900,
1231,
3140,
402,
314,
3379,
288,
3330,
63,
515,
275,
2053,
63,
515,
14,
1294,
8,
888,
459,
1375,
25945,
17,
1527,
17,
2938,
288,
340,
1242,
14,
374,
63,
694,
837,
355,
366,
59,
1053,
14,
354,
61,
275,
291,
14,
1122,
63,
10622,
8,
1242,
12,
2053,
63,
515,
12,
5071,
63,
807,
12,
3330,
63,
515,
9,
288,
916,
291,
14,
374,
63,
5540,
8,
1242,
12,
5071,
63,
807,
3461,
355,
327,
2342,
282,
1798,
367,
642,
570,
355,
1798,
275,
4693,
1873,
14,
1431,
63,
493,
63,
11531,
8,
1053,
14,
354,
9,
355,
366,
59,
1053,
14,
354,
61,
275,
1798,
14,
1122,
63,
493,
8,
1242,
14,
515,
12,
1242,
14,
354,
12,
2053,
63,
515,
776,
355,
366,
59,
1053,
14,
354,
2733,
515,
418,
275,
3330,
63,
515,
355,
366,
59,
1053,
14,
354,
2733,
8180,
418,
275,
1242,
14,
3736,
1252,
270,
63,
8180,
355,
327,
1331,
570,
370,
2053,
340,
949,
1564,
790,
355,
340,
440,
366,
59,
1053,
14,
354,
1055,
362,
8,
283,
1317,
7,
776,
436,
1798,
14,
21997,
26,
490,
2050,
14,
1757,
480,
5116,
570,
469,
16,
93,
370,
314,
2082,
469,
17,
93,
3212,
2511,
1275,
908,
8,
515,
12,
2053,
63
] |
[
2647,
15,
1393,
15,
1548,
19,
199,
3,
221,
199,
3,
1898,
334,
67,
9,
6171,
12,
1952,
3540,
1181,
3835,
265,
14183,
12,
2900,
4481,
4644,
14,
199,
3,
1898,
334,
67,
9,
6171,
12,
428,
280,
335,
1337,
1315,
821,
14,
1308,
12,
2900,
4481,
4644,
14,
199,
3,
221,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
650,
14,
16,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
373,
19,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
14,
199,
199,
646,
747,
199,
646,
5145,
199,
504,
9143,
492,
7114,
199,
646,
14709,
7172,
199,
646,
2022,
199,
646,
2050,
199,
199,
646,
10933,
199,
199,
3,
367,
876,
650,
14,
21,
2366,
5459,
221,
199,
893,
26,
272,
747,
14,
6282,
694,
199,
2590,
4281,
26,
272,
492,
8000,
694,
272,
747,
14,
6282,
694,
275,
8000,
694,
14,
6282,
694,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
888,
275,
469,
272,
283,
1375,
356,
26069,
1506,
401,
5591,
283,
2164,
356,
26069,
2124,
63,
2164,
2,
221,
199,
93,
9948,
199,
318,
5389,
7892,
8,
807,
17,
12,
1211,
18,
304,
272,
367,
1022,
315,
663,
8,
807,
17,
14,
1612,
8801,
8888,
8,
807,
18,
14,
1612,
5109,
267,
340,
1022,
315,
1211,
17,
436,
1022,
315,
1211,
18,
26,
288,
340,
1228,
8,
807,
17,
59,
75,
467,
1211,
9,
436,
1228,
8,
807,
18,
59,
75,
467,
1211,
304,
355,
1995,
334,
75,
12,
1211,
8,
5628,
7892,
8,
807,
17,
59,
75,
467,
1211,
18,
59,
75,
11845,
288,
587,
26,
355,
327,
982,
1373,
402,
314,
1338,
365,
440,
282,
1211,
12,
1265,
883,
1133,
1980,
22537,
652,
14,
355,
327,
1594,
687,
3499,
1211,
10580,
1373,
315,
1642,
436,
781,
4057,
641,
14,
355,
1995,
334,
75,
12,
1211,
18,
59,
75,
566,
355,
327,
26776,
12,
3350,
642,
543,
1919,
660,
25696,
370,
10459,
1265,
402,
574,
18511,
267,
916,
1022,
315,
1211,
17,
26,
288,
1995,
334,
75,
12,
1211,
17,
59,
75,
566,
267,
587,
26,
288,
1995,
334,
75,
12,
1211,
18,
59,
75,
566,
421,
199,
533,
4693,
1873,
3567,
2842,
8,
785,
304,
272,
408,
272,
710,
849,
2935,
1798,
14,
8730,
397,
367,
21295,
4877,
570,
503,
5591,
2082,
21295,
14,
982,
7179,
1911,
652,
5344,
874,
1901,
31396,
436,
5591,
14404,
1584,
20247,
543,
2513,
6774,
21831,
680,
5591,
16920,
787,
8876,
370,
314,
1900,
1738,
14,
2286,
437,
570,
365,
11159,
701,
282,
2600,
543,
737,
5210,
314,
2569,
2883,
272,
627,
1564,
26,
570,
1564,
340,
3964,
272,
627,
931,
26,
9911,
334,
315,
314,
1900,
2935,
776,
272,
627,
15005,
26,
7100,
900,
272,
408,
14821,
347,
1336,
8,
277,
12,
536,
304,
267,
408,
267,
1379,
340,
642,
1798,
4450,
367,
282,
536,
2728,
520,
635,
620,
536,
26,
570,
503,
2082,
536,
267,
408,
4960,
372,
756,
5493,
347,
365,
63,
5540,
8,
277,
12,
487,
25327,
12,
5071,
63,
807,
304,
267,
408,
267,
2670,
570,
1159,
15005,
436,
30827,
652,
370,
314,
4136,
1255,
574,
2728,
1803,
2549,
340,
15666,
267,
408,
267,
340,
440,
5071,
63,
807,
503,
440,
5071,
63,
807,
14,
362,
8,
328,
25327,
14,
354,
304,
288,
372,
715,
257,
327,
949,
4136,
666,
1911,
880,
6042,
267,
372,
487,
25327,
14,
3736,
1252,
270,
63,
8180,
690,
5071,
63,
807,
14,
362,
8,
328,
25327,
14,
354,
2788,
283,
8180,
7,
1622,
18407,
347,
2198,
63,
694,
8,
277,
12,
931,
12,
2053,
63,
515,
12,
5071,
63,
807,
29,
403,
304,
267,
408,
267,
6077,
282,
2082,
14,
12823,
2754,
1798,
370,
1336,
570,
503,
2082,
1561,
2728,
520,
635,
620,
931,
26,
931,
402,
314,
2082,
267,
520,
635,
620,
2053,
63,
515,
26,
931,
402,
314,
5724,
2082,
267,
520,
635,
1211,
5071,
63,
807,
26,
314,
2600,
30226,
370,
642,
2082,
6511,
3044,
687,
282,
4136,
1255,
267,
1803,
314,
2600,
543,
4072,
402,
314,
2082,
267,
408,
267,
5071,
63,
807,
275,
5071,
63,
807,
503,
1052,
267,
366,
275,
1052,
267,
367,
1242,
315,
747,
14,
6282,
694,
8,
515,
304,
288,
327,
3354,
314,
3847,
1,
931,
315,
314,
1900,
1231,
3140,
402,
314,
3379,
288,
3330,
63,
515,
275,
2053,
63,
515,
14,
1294,
8,
888,
459,
1375,
25945,
17,
1527,
17,
2938,
288,
340,
1242,
14,
374,
63,
694,
837,
355,
366,
59,
1053,
14,
354,
61,
275,
291,
14,
1122,
63,
10622,
8,
1242,
12,
2053,
63,
515,
12,
5071,
63,
807,
12,
3330,
63,
515,
9,
288,
916,
291,
14,
374,
63,
5540,
8,
1242,
12,
5071,
63,
807,
3461,
355,
327,
2342,
282,
1798,
367,
642,
570,
355,
1798,
275,
4693,
1873,
14,
1431,
63,
493,
63,
11531,
8,
1053,
14,
354,
9,
355,
366,
59,
1053,
14,
354,
61,
275,
1798,
14,
1122,
63,
493,
8,
1242,
14,
515,
12,
1242,
14,
354,
12,
2053,
63,
515,
776,
355,
366,
59,
1053,
14,
354,
2733,
515,
418,
275,
3330,
63,
515,
355,
366,
59,
1053,
14,
354,
2733,
8180,
418,
275,
1242,
14,
3736,
1252,
270,
63,
8180,
355,
327,
1331,
570,
370,
2053,
340,
949,
1564,
790,
355,
340,
440,
366,
59,
1053,
14,
354,
1055,
362,
8,
283,
1317,
7,
776,
436,
1798,
14,
21997,
26,
490,
2050,
14,
1757,
480,
5116,
570,
469,
16,
93,
370,
314,
2082,
469,
17,
93,
3212,
2511,
1275,
908,
8,
515,
12,
2053,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
kobejean/tensorflow
|
tensorflow/python/data/kernel_tests/cache_dataset_op_test.py
|
9
|
11862
|
# 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 the experimental input pipeline ops."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from os import path
import shutil
import tempfile
import numpy as np
from tensorflow.python.data.kernel_tests import test_base
from tensorflow.python.data.ops import dataset_ops
from tensorflow.python.data.ops import iterator_ops
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import errors
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import variables
from tensorflow.python.platform import test
class FileCacheDatasetTest(test_base.DatasetTestBase):
def setUp(self):
self.tmp_dir = tempfile.mkdtemp()
self.cache_prefix = path.join(self.tmp_dir, "cache")
def tearDown(self):
if self.tmp_dir:
shutil.rmtree(self.tmp_dir, ignore_errors=True)
def testCacheDatasetPassthrough(self):
components = (np.array([1, 2, 3, 4]), np.array([5, 6, 7, 8]),
np.array([9.0, 10.0, 11.0, 12.0]))
count_placeholder = array_ops.placeholder_with_default(
constant_op.constant(5, dtypes.int64), shape=[])
filename_placeholder = array_ops.placeholder(dtypes.string, shape=[])
repeat_dataset = (dataset_ops.Dataset.from_tensor_slices(components)
.repeat(count_placeholder))
cache_dataset = repeat_dataset.cache(filename_placeholder)
self.assertEqual(
tuple([c.shape[1:] for c in components]), cache_dataset.output_shapes)
# Create initialization ops for iterators without and with
# caching, respectively.
iterator = iterator_ops.Iterator.from_structure(cache_dataset.output_types,
cache_dataset.output_shapes)
init_fifo_op = iterator.make_initializer(repeat_dataset)
init_cache_op = iterator.make_initializer(cache_dataset)
get_next = iterator.get_next()
with self.cached_session() as sess:
# First run without caching to collect the "ground truth".
sess.run(init_fifo_op)
elements = []
for _ in range(20):
elements.append(sess.run(get_next))
with self.assertRaises(errors.OutOfRangeError):
sess.run(get_next)
# Assert that the cached dataset has the same elements as the
# "ground truth".
sess.run(
init_cache_op, feed_dict={filename_placeholder: self.cache_prefix})
cached_elements = []
for _ in range(20):
cached_elements.append(sess.run(get_next))
with self.assertRaises(errors.OutOfRangeError):
sess.run(get_next)
self.assertAllEqual(elements, cached_elements)
# Re-initialize with an empty upstream (to throw errors.OutOfRangeError
# if we didn't use the cache).
sess.run(
init_cache_op,
feed_dict={
count_placeholder: 0,
filename_placeholder: self.cache_prefix
})
replayed_elements = []
for _ in range(20):
replayed_elements.append(sess.run(get_next))
with self.assertRaises(errors.OutOfRangeError):
sess.run(get_next)
self.assertEqual(cached_elements, replayed_elements)
# Re-initialize with an empty upstream and a missing cache file (should
# throw errors.OutOfRangeError immediately).
sess.run(
init_cache_op,
feed_dict={
count_placeholder: 0,
filename_placeholder: self.cache_prefix + "nonsense"
})
with self.assertRaises(errors.OutOfRangeError):
sess.run(get_next)
def testConcurrentWriters(self):
components = (np.array([1, 2, 3, 4]), np.array([5, 6, 7, 8]),
np.array([9.0, 10.0, 11.0, 12.0]))
filename_placeholder = array_ops.placeholder(dtypes.string, shape=[])
cache_dataset1 = (dataset_ops.Dataset.from_tensor_slices(components)
.cache(filename_placeholder))
cache_dataset2 = (dataset_ops.Dataset.from_tensor_slices(components)
.cache(filename_placeholder))
iterator1 = cache_dataset1.make_initializable_iterator()
iterator2 = cache_dataset2.make_initializable_iterator()
init_cache_op1 = iterator1.initializer
init_cache_op2 = iterator2.initializer
get_next1 = iterator1.get_next()
get_next2 = iterator2.get_next()
with self.cached_session() as sess:
sess.run(
init_cache_op1, feed_dict={filename_placeholder: self.cache_prefix})
sess.run(get_next1) # this should succeed
sess.run(
init_cache_op2, feed_dict={filename_placeholder: self.cache_prefix})
with self.assertRaises(errors.AlreadyExistsError):
sess.run(get_next2)
sess.run(get_next1) # this should continue to succeed
def testConcurrentReaders(self):
components = (np.array([1, 2, 3, 4]), np.array([5, 6, 7, 8]),
np.array([9.0, 10.0, 11.0, 12.0]))
filename_placeholder = array_ops.placeholder(dtypes.string, shape=[])
cache_dataset1 = (dataset_ops.Dataset.from_tensor_slices(components)
.cache(filename_placeholder))
cache_dataset2 = (dataset_ops.Dataset.from_tensor_slices(components)
.cache(filename_placeholder))
iterator1 = cache_dataset1.make_initializable_iterator()
iterator2 = cache_dataset2.make_initializable_iterator()
init_cache_op1 = iterator1.initializer
init_cache_op2 = iterator2.initializer
get_next1 = iterator1.get_next()
get_next2 = iterator2.get_next()
with self.cached_session() as sess:
sess.run(
init_cache_op1, feed_dict={filename_placeholder: self.cache_prefix})
elements = []
for _ in range(4):
elements.append(sess.run(get_next1))
with self.assertRaises(errors.OutOfRangeError):
sess.run(get_next1)
# Re-initialize
sess.run(
init_cache_op1, feed_dict={filename_placeholder: self.cache_prefix})
sess.run(
init_cache_op2, feed_dict={filename_placeholder: self.cache_prefix})
# Reading concurrently should succeed.
elements_itr1 = []
elements_itr2 = []
elements_itr2.append(sess.run(get_next2))
elements_itr1.append(sess.run(get_next1))
elements_itr2.append(sess.run(get_next2))
elements_itr1.append(sess.run(get_next1))
# Intentionally reversing the order
elements_itr1.append(sess.run(get_next1))
elements_itr2.append(sess.run(get_next2))
elements_itr1.append(sess.run(get_next1))
elements_itr2.append(sess.run(get_next2))
with self.assertRaises(errors.OutOfRangeError):
sess.run(get_next2)
with self.assertRaises(errors.OutOfRangeError):
sess.run(get_next1)
self.assertAllEqual(elements, elements_itr1)
self.assertAllEqual(elements, elements_itr2)
class MemoryCacheDatasetTest(test_base.DatasetTestBase):
def testCacheDatasetPassthrough(self):
with ops.device("cpu:0"):
repeat_count = variables.Variable(constant_op.constant(10, dtypes.int64))
dataset = dataset_ops.Dataset.range(3).flat_map(
lambda x: dataset_ops.Dataset.from_tensors(x).repeat(repeat_count))
cached_dataset = dataset.cache().repeat(2)
uncached_dataset = dataset.repeat(2)
# Needs to be initializable to capture the variable.
cached_iterator = cached_dataset.make_initializable_iterator()
cached_next = cached_iterator.get_next()
uncached_iterator = uncached_dataset.make_initializable_iterator()
uncached_next = uncached_iterator.get_next()
with self.cached_session() as sess:
sess.run(repeat_count.initializer)
sess.run(cached_iterator.initializer)
sess.run(uncached_iterator.initializer)
for i in range(3):
for _ in range(10):
self.assertEqual(sess.run(cached_next), i)
self.assertEqual(sess.run(uncached_next), i)
sess.run(repeat_count.assign(0))
# The uncached iterator should now be empty.
with self.assertRaises(errors.OutOfRangeError):
sess.run(uncached_next)
# The cached iterator replays from cache.
for i in range(3):
for _ in range(10):
self.assertEqual(sess.run(cached_next), i)
# The cached iterator should now be empty.
with self.assertRaises(errors.OutOfRangeError):
sess.run(cached_next)
def testEmptyCacheReading(self):
components = (np.array([1, 2, 3, 4]), np.array([5, 6, 7, 8]),
np.array([9.0, 10.0, 11.0, 12.0]))
count_placeholder = array_ops.placeholder_with_default(
constant_op.constant(5, dtypes.int64), shape=[])
repeat_dataset = (dataset_ops.Dataset.from_tensor_slices(components)
.repeat(count_placeholder))
cache_dataset = repeat_dataset.cache()
# Create initialization ops for iterators without and with
# caching, respectively.
iterator = cache_dataset.make_initializable_iterator()
init_cache_op = iterator.initializer
get_next = iterator.get_next()
with self.cached_session() as sess:
# Initialize with an empty upstream and a missing cache file (should
# throw errors.OutOfRangeError immediately).
sess.run(init_cache_op, feed_dict={count_placeholder: 0})
with self.assertRaises(errors.OutOfRangeError):
sess.run(get_next)
def testConcurrentReaders(self):
count_placeholder = array_ops.placeholder_with_default(
constant_op.constant(5, dtypes.int64), shape=[])
dataset = dataset_ops.Dataset.range(count_placeholder).cache()
d1 = dataset.map(lambda x: x + 1)
d2 = dataset.map(lambda x: x + 6)
i1 = d1.make_initializable_iterator()
i2 = d2.make_initializable_iterator()
with self.cached_session() as sess:
sess.run(i1.initializer)
self.assertEqual(1, sess.run(i1.get_next()))
self.assertEqual(2, sess.run(i1.get_next()))
self.assertEqual(3, sess.run(i1.get_next()))
sess.run(i2.initializer, feed_dict={count_placeholder: 3})
self.assertEqual(6, sess.run(i2.get_next()))
self.assertEqual(7, sess.run(i2.get_next()))
self.assertEqual(4, sess.run(i1.get_next())) # interleave execution
self.assertEqual([8, 5], sess.run([i2.get_next(), i1.get_next()]))
with self.assertRaises(errors.OutOfRangeError):
sess.run(i1.get_next())
with self.assertRaises(errors.OutOfRangeError):
sess.run(i2.get_next())
def testCacheTakeRepeat(self):
dataset = dataset_ops.Dataset.range(10).cache().take(5).repeat(2)
itr = dataset.make_one_shot_iterator()
n = itr.get_next()
expected_values = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4]
with self.cached_session() as sess:
for i, expected in enumerate(expected_values):
self.assertEqual(expected, sess.run(n),
"Unexpected value at index %s" % i)
with self.assertRaises(errors.OutOfRangeError):
sess.run(itr.get_next())
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,
314,
22820,
1324,
7679,
4156,
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,
747,
492,
931,
199,
646,
5145,
199,
646,
5549,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
576,
14,
4989,
63,
2219,
492,
511,
63,
1095,
199,
504,
3228,
14,
1548,
14,
576,
14,
1483,
492,
4789,
63,
1483,
199,
504,
3228,
14,
1548,
14,
576,
14,
1483,
492,
6122,
63,
1483,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
3814,
4437,
9271,
774,
8,
396,
63,
1095,
14,
9271,
14440,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
2791,
63,
694,
275,
5549,
14,
11983,
342,
272,
291,
14,
1637,
63,
1861,
275,
931,
14,
904,
8,
277,
14,
2791,
63,
694,
12,
298,
1637,
531,
819,
347,
6766,
8,
277,
304,
272,
340,
291,
14,
2791,
63,
694,
26,
489,
5145,
14,
9242,
8,
277,
14,
2791,
63,
694,
12,
3686,
63,
2550,
29,
549,
9,
819,
347,
511,
4437,
9271,
48,
305,
20887,
8,
277,
304,
272,
7323,
275,
334,
1590,
14,
1144,
779,
17,
12,
499,
12,
650,
12,
841,
2522,
980,
14,
1144,
779,
21,
12,
1227,
12,
1520,
12,
1695,
2522,
2116,
980,
14,
1144,
779,
25,
14,
16,
12,
1616,
14,
16,
12,
4119,
14,
16,
12,
3144,
14,
16,
2459,
272,
2338,
63,
6199,
275,
1625,
63,
1483,
14,
6199,
63,
1045,
63,
885,
8,
267,
4413,
63,
411,
14,
4083,
8,
21,
12,
6674,
14,
442,
772,
395,
2215,
14285,
272,
1788,
63,
6199,
275,
1625,
63,
1483,
14,
6199,
8,
5717,
14,
875,
12,
2215,
14285,
339,
11982,
63,
5214,
275,
334,
5214,
63,
1483,
14,
9271,
14,
504,
63,
3128,
63,
14865,
8,
4608,
9,
1993,
1275,
8755,
8,
835,
63,
6199,
430,
339,
2581,
63,
5214,
275,
11982,
63,
5214,
14,
1637,
8,
1501,
63,
6199,
9,
339,
291,
14,
629,
8,
267,
2008,
779,
67,
14,
1392,
59,
17,
2938,
367,
286,
315,
7323,
2522,
2581,
63,
5214,
14,
1199,
63,
9069,
9,
339,
327,
2790,
11097,
4156,
367,
28241,
1928,
436,
543,
272,
327,
13627,
12,
17342,
14,
272,
6122,
275,
6122,
63,
1483,
14,
3585,
14,
504,
63,
6976,
8,
1637,
63,
5214,
14,
1199,
63,
1313,
12,
8105,
2581,
63,
5214,
14,
1199,
63,
9069,
9,
272,
4205,
63,
22976,
63,
411,
275,
6122,
14,
1875,
63,
6498,
8,
8755,
63,
5214,
9,
272,
4205,
63,
1637,
63,
411,
275,
6122,
14,
1875,
63,
6498,
8,
1637,
63,
5214,
9,
339,
664,
63,
2184,
275,
6122,
14,
362,
63,
2184,
342,
339,
543,
291,
14,
5245,
63,
1730,
342,
465,
4043,
26,
489,
327,
7758,
1255,
1928,
13627,
370,
8775,
314,
298,
3928,
16865,
1674,
489,
4043,
14,
1065,
8,
826,
63,
22976,
63,
411,
9,
489,
4008,
275,
942,
489,
367,
485,
315,
1425,
8,
1165,
304,
267,
4008,
14,
740,
8,
5480,
14,
1065,
8,
362,
63,
2184,
430,
489,
543,
291,
14,
1855,
8,
2550,
14,
30523,
304,
267,
4043,
14,
1065,
8,
362,
63,
2184,
9,
2541,
327,
10716,
626,
314,
6328,
4789,
965,
314,
2011,
4008,
465,
314,
489,
327,
298,
3928,
16865,
1674,
489,
4043,
14,
1065,
8,
881,
4205,
63,
1637,
63,
411,
12,
4733,
63,
807,
3126,
1501,
63,
6199,
26,
291,
14,
1637,
63,
1861,
1552,
489,
6328,
63,
5527,
275,
942,
489,
367,
485,
315,
1425,
8,
1165,
304,
267,
6328,
63,
5527,
14,
740,
8,
5480,
14,
1065,
8,
362,
63,
2184,
430,
489,
543,
291,
14,
1855,
8,
2550,
14,
30523,
304,
267,
4043,
14,
1065,
8,
362,
63,
2184,
9,
489,
291,
14,
7069,
8,
5527,
12,
6328,
63,
5527,
9,
2541,
327,
799,
13,
8489,
543,
376,
2701,
18932,
334,
475,
7978,
2552,
14,
30523,
489,
327,
340,
781,
9980,
1133,
675,
314,
2581,
680,
489,
4043,
14,
1065,
8,
881,
4205,
63,
1637,
63,
411,
12,
881,
4733,
63,
807,
3126,
1598,
2338,
63,
6199,
26,
378,
12,
1598,
1788,
63,
6199,
26,
291,
14,
1637,
63,
1861,
881,
3828,
489,
24331,
379,
63,
5527,
275,
942,
489,
367,
485,
315,
1425,
8,
1165,
304,
267,
24331,
379,
63,
5527,
14,
740,
8,
5480,
14,
1065,
8,
362,
63,
2184,
430,
489,
543,
291,
14,
1855,
8,
2550,
14,
30523,
304,
267,
4043,
14,
1065,
8,
362,
63,
2184,
9,
489,
291,
14,
629,
8,
5245,
63,
5527,
12,
24331,
379,
63,
5527,
9,
2541,
327,
799,
13,
8489,
543,
376,
2701,
18932,
436,
282,
4124,
2581,
570,
334,
5626,
489,
327,
7978,
2552,
14,
30523,
9939,
680,
489,
4043,
14,
1065,
8,
881,
4205,
63,
1637,
63,
411,
12,
881,
4733,
63,
807,
3126,
1598,
2338,
63,
6199,
26,
378,
12,
1598,
1788,
63,
6199,
26,
291,
14,
1637,
63
] |
[
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,
314,
22820,
1324,
7679,
4156,
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,
747,
492,
931,
199,
646,
5145,
199,
646,
5549,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
576,
14,
4989,
63,
2219,
492,
511,
63,
1095,
199,
504,
3228,
14,
1548,
14,
576,
14,
1483,
492,
4789,
63,
1483,
199,
504,
3228,
14,
1548,
14,
576,
14,
1483,
492,
6122,
63,
1483,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
3814,
4437,
9271,
774,
8,
396,
63,
1095,
14,
9271,
14440,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
2791,
63,
694,
275,
5549,
14,
11983,
342,
272,
291,
14,
1637,
63,
1861,
275,
931,
14,
904,
8,
277,
14,
2791,
63,
694,
12,
298,
1637,
531,
819,
347,
6766,
8,
277,
304,
272,
340,
291,
14,
2791,
63,
694,
26,
489,
5145,
14,
9242,
8,
277,
14,
2791,
63,
694,
12,
3686,
63,
2550,
29,
549,
9,
819,
347,
511,
4437,
9271,
48,
305,
20887,
8,
277,
304,
272,
7323,
275,
334,
1590,
14,
1144,
779,
17,
12,
499,
12,
650,
12,
841,
2522,
980,
14,
1144,
779,
21,
12,
1227,
12,
1520,
12,
1695,
2522,
2116,
980,
14,
1144,
779,
25,
14,
16,
12,
1616,
14,
16,
12,
4119,
14,
16,
12,
3144,
14,
16,
2459,
272,
2338,
63,
6199,
275,
1625,
63,
1483,
14,
6199,
63,
1045,
63,
885,
8,
267,
4413,
63,
411,
14,
4083,
8,
21,
12,
6674,
14,
442,
772,
395,
2215,
14285,
272,
1788,
63,
6199,
275,
1625,
63,
1483,
14,
6199,
8,
5717,
14,
875,
12,
2215,
14285,
339,
11982,
63,
5214,
275,
334,
5214,
63,
1483,
14,
9271,
14,
504,
63,
3128,
63,
14865,
8,
4608,
9,
1993,
1275,
8755,
8,
835,
63,
6199,
430,
339,
2581,
63,
5214,
275,
11982,
63,
5214,
14,
1637,
8,
1501,
63,
6199,
9,
339,
291,
14,
629,
8,
267,
2008,
779,
67,
14,
1392,
59,
17,
2938,
367,
286,
315,
7323,
2522,
2581,
63,
5214,
14,
1199,
63,
9069,
9,
339,
327,
2790,
11097,
4156,
367,
28241,
1928,
436,
543,
272,
327,
13627,
12,
17342,
14,
272,
6122,
275,
6122,
63,
1483,
14,
3585,
14,
504,
63,
6976,
8,
1637,
63,
5214,
14,
1199,
63,
1313,
12,
8105,
2581,
63,
5214,
14,
1199,
63,
9069,
9,
272,
4205,
63,
22976,
63,
411,
275,
6122,
14,
1875,
63,
6498,
8,
8755,
63,
5214,
9,
272,
4205,
63,
1637,
63,
411,
275,
6122,
14,
1875,
63,
6498,
8,
1637,
63,
5214,
9,
339,
664,
63,
2184,
275,
6122,
14,
362,
63,
2184,
342,
339,
543,
291,
14,
5245,
63,
1730,
342,
465,
4043,
26,
489,
327,
7758,
1255,
1928,
13627,
370,
8775,
314,
298,
3928,
16865,
1674,
489,
4043,
14,
1065,
8,
826,
63,
22976,
63,
411,
9,
489,
4008,
275,
942,
489,
367,
485,
315,
1425,
8,
1165,
304,
267,
4008,
14,
740,
8,
5480,
14,
1065,
8,
362,
63,
2184,
430,
489,
543,
291,
14,
1855,
8,
2550,
14,
30523,
304,
267,
4043,
14,
1065,
8,
362,
63,
2184,
9,
2541,
327,
10716,
626,
314,
6328,
4789,
965,
314,
2011,
4008,
465,
314,
489,
327,
298,
3928,
16865,
1674,
489,
4043,
14,
1065,
8,
881,
4205,
63,
1637,
63,
411,
12,
4733,
63,
807,
3126,
1501,
63,
6199,
26,
291,
14,
1637,
63,
1861,
1552,
489,
6328,
63,
5527,
275,
942,
489,
367,
485,
315,
1425,
8,
1165,
304,
267,
6328,
63,
5527,
14,
740,
8,
5480,
14,
1065,
8,
362,
63,
2184,
430,
489,
543,
291,
14,
1855,
8,
2550,
14,
30523,
304,
267,
4043,
14,
1065,
8,
362,
63,
2184,
9,
489,
291,
14,
7069,
8,
5527,
12,
6328,
63,
5527,
9,
2541,
327,
799,
13,
8489,
543,
376,
2701,
18932,
334,
475,
7978,
2552,
14,
30523,
489,
327,
340,
781,
9980,
1133,
675,
314,
2581,
680,
489,
4043,
14,
1065,
8,
881,
4205,
63,
1637,
63,
411,
12,
881,
4733,
63,
807,
3126,
1598,
2338,
63,
6199,
26,
378,
12,
1598,
1788,
63,
6199,
26,
291,
14,
1637,
63,
1861,
881,
3828,
489,
24331,
379,
63,
5527,
275,
942,
489,
367,
485,
315,
1425,
8,
1165,
304,
267,
24331,
379,
63,
5527,
14,
740,
8,
5480,
14,
1065,
8,
362,
63,
2184,
430,
489,
543,
291,
14,
1855,
8,
2550,
14,
30523,
304,
267,
4043,
14,
1065,
8,
362,
63,
2184,
9,
489,
291,
14,
629,
8,
5245,
63,
5527,
12,
24331,
379,
63,
5527,
9,
2541,
327,
799,
13,
8489,
543,
376,
2701,
18932,
436,
282,
4124,
2581,
570,
334,
5626,
489,
327,
7978,
2552,
14,
30523,
9939,
680,
489,
4043,
14,
1065,
8,
881,
4205,
63,
1637,
63,
411,
12,
881,
4733,
63,
807,
3126,
1598,
2338,
63,
6199,
26,
378,
12,
1598,
1788,
63,
6199,
26,
291,
14,
1637,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
jajberni/pcse_web
|
main/control/index.py
|
5
|
1922
|
# coding: utf-8
"""
Provides logic for rendering index template
"""
import flask
from main import app
import auth
import config
from model import User, UserValidator, Config
from api.helpers import ArgumentValidator
@app.route('/')
def index():
"""Render index template"""
return flask.render_template('index.html')
@app.context_processor
def inject_user():
"""Injects 'user' variable into jinja template, so it can be passed into angular. See base.html"""
user = False
if auth.is_logged_in():
user = auth.current_user_db().to_dict(include=User.get_private_properties())
return {
'user': user
}
@app.context_processor
def inject_config():
"""Injects 'app_config' variable into jinja template, so it can be passed into angular. See base.html"""
config_properties = Config.get_all_properties() if auth.is_admin() else Config.get_public_properties()
app_config = config.CONFIG_DB.to_dict(include=config_properties)
app_config['development'] = config.DEVELOPMENT
return {
'app_config': app_config
}
@app.context_processor
def inject_validators():
"""Injects 'validators' variable into jinja template, so it can be passed into angular. See base.html
Model validators are passed to angular so it can be used for frontend input validation as well
This prevents code repetition, as we e.g we change property of UserValidator.name to [5, 20]
and the same validation of user's name (length between 5-20 characters) will be performed in frontend
as well as in backend
"""
return {
'validators': {
'arg': ArgumentValidator.to_dict(),
'user': UserValidator.to_dict()
}
}
@app.route('/_ah/warmup')
def warmup():
"""Warmup requests load application code into a new instance before any live requests reach that instance.
For more info see GAE docs"""
return 'success'
|
apache-2.0
|
[
3,
2803,
26,
2774,
13,
24,
199,
624,
199,
17473,
9661,
367,
14066,
1478,
1978,
199,
624,
199,
646,
7209,
199,
199,
504,
2446,
492,
1145,
199,
646,
1790,
199,
646,
1101,
199,
504,
1402,
492,
2876,
12,
2876,
8640,
12,
4094,
199,
504,
2986,
14,
7546,
492,
5886,
8640,
199,
199,
32,
571,
14,
4449,
7825,
199,
318,
1478,
837,
272,
408,
9216,
1478,
1978,
624,
272,
372,
7209,
14,
3352,
63,
1160,
360,
1080,
14,
1360,
358,
421,
199,
32,
571,
14,
1100,
63,
6459,
199,
318,
16182,
63,
751,
837,
272,
408,
607,
963,
83,
283,
751,
7,
1750,
1901,
10321,
1978,
12,
880,
652,
883,
506,
3032,
1901,
30921,
14,
1666,
1300,
14,
1360,
624,
272,
922,
275,
756,
272,
340,
1790,
14,
374,
63,
12419,
63,
262,
837,
267,
922,
275,
1790,
14,
1818,
63,
751,
63,
697,
1252,
475,
63,
807,
8,
2613,
29,
1899,
14,
362,
63,
4239,
63,
3282,
1012,
272,
372,
469,
267,
283,
751,
356,
922,
272,
789,
421,
199,
32,
571,
14,
1100,
63,
6459,
199,
318,
16182,
63,
888,
837,
272,
408,
607,
963,
83,
283,
571,
63,
888,
7,
1750,
1901,
10321,
1978,
12,
880,
652,
883,
506,
3032,
1901,
30921,
14,
1666,
1300,
14,
1360,
624,
272,
1101,
63,
3282,
275,
4094,
14,
362,
63,
452,
63,
3282,
342,
340,
1790,
14,
374,
63,
2113,
342,
587,
4094,
14,
362,
63,
3455,
63,
3282,
342,
272,
1145,
63,
888,
275,
1101,
14,
5569,
63,
2846,
14,
475,
63,
807,
8,
2613,
29,
888,
63,
3282,
9,
272,
1145,
63,
888,
459,
31688,
418,
275,
1101,
14,
1093,
2524,
26515,
4479,
272,
372,
469,
267,
283,
571,
63,
888,
356,
1145,
63,
888,
272,
789,
421,
199,
32,
571,
14,
1100,
63,
6459,
199,
318,
16182,
63,
11346,
837,
272,
408,
607,
963,
83,
283,
11346,
7,
1750,
1901,
10321,
1978,
12,
880,
652,
883,
506,
3032,
1901,
30921,
14,
1666,
1300,
14,
1360,
272,
5822,
14370,
787,
3032,
370,
30921,
880,
652,
883,
506,
1202,
367,
22523,
1324,
6411,
465,
5521,
272,
961,
21925,
1233,
6375,
3348,
12,
465,
781,
325,
14,
71,
781,
1570,
3324,
402,
2876,
8640,
14,
354,
370,
359,
21,
12,
3388,
61,
272,
436,
314,
2011,
6411,
402,
922,
1159,
536,
334,
1267,
3382,
959,
13,
1165,
4110,
9,
911,
506,
10585,
315,
22523,
272,
465,
5521,
465,
315,
4865,
272,
408,
272,
372,
469,
267,
283,
11346,
356,
469,
288,
283,
1273,
356,
5886,
8640,
14,
475,
63,
807,
1062,
288,
283,
751,
356,
2876,
8640,
14,
475,
63,
807,
342,
267,
789,
272,
789,
421,
199,
32,
571,
14,
4449,
2336,
63,
11326,
15,
10669,
384,
358,
199,
318,
20060,
384,
837,
272,
408,
55,
5362,
384,
4145,
2248,
4223,
1233,
1901,
282,
892,
1256,
2544,
1263,
12166,
4145,
12276,
626,
1256,
14,
272,
2104,
1655,
2256,
1937,
598,
12500,
9149,
624,
272,
372,
283,
3742,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
26,
2774,
13,
24,
199,
624,
199,
17473,
9661,
367,
14066,
1478,
1978,
199,
624,
199,
646,
7209,
199,
199,
504,
2446,
492,
1145,
199,
646,
1790,
199,
646,
1101,
199,
504,
1402,
492,
2876,
12,
2876,
8640,
12,
4094,
199,
504,
2986,
14,
7546,
492,
5886,
8640,
199,
199,
32,
571,
14,
4449,
7825,
199,
318,
1478,
837,
272,
408,
9216,
1478,
1978,
624,
272,
372,
7209,
14,
3352,
63,
1160,
360,
1080,
14,
1360,
358,
421,
199,
32,
571,
14,
1100,
63,
6459,
199,
318,
16182,
63,
751,
837,
272,
408,
607,
963,
83,
283,
751,
7,
1750,
1901,
10321,
1978,
12,
880,
652,
883,
506,
3032,
1901,
30921,
14,
1666,
1300,
14,
1360,
624,
272,
922,
275,
756,
272,
340,
1790,
14,
374,
63,
12419,
63,
262,
837,
267,
922,
275,
1790,
14,
1818,
63,
751,
63,
697,
1252,
475,
63,
807,
8,
2613,
29,
1899,
14,
362,
63,
4239,
63,
3282,
1012,
272,
372,
469,
267,
283,
751,
356,
922,
272,
789,
421,
199,
32,
571,
14,
1100,
63,
6459,
199,
318,
16182,
63,
888,
837,
272,
408,
607,
963,
83,
283,
571,
63,
888,
7,
1750,
1901,
10321,
1978,
12,
880,
652,
883,
506,
3032,
1901,
30921,
14,
1666,
1300,
14,
1360,
624,
272,
1101,
63,
3282,
275,
4094,
14,
362,
63,
452,
63,
3282,
342,
340,
1790,
14,
374,
63,
2113,
342,
587,
4094,
14,
362,
63,
3455,
63,
3282,
342,
272,
1145,
63,
888,
275,
1101,
14,
5569,
63,
2846,
14,
475,
63,
807,
8,
2613,
29,
888,
63,
3282,
9,
272,
1145,
63,
888,
459,
31688,
418,
275,
1101,
14,
1093,
2524,
26515,
4479,
272,
372,
469,
267,
283,
571,
63,
888,
356,
1145,
63,
888,
272,
789,
421,
199,
32,
571,
14,
1100,
63,
6459,
199,
318,
16182,
63,
11346,
837,
272,
408,
607,
963,
83,
283,
11346,
7,
1750,
1901,
10321,
1978,
12,
880,
652,
883,
506,
3032,
1901,
30921,
14,
1666,
1300,
14,
1360,
272,
5822,
14370,
787,
3032,
370,
30921,
880,
652,
883,
506,
1202,
367,
22523,
1324,
6411,
465,
5521,
272,
961,
21925,
1233,
6375,
3348,
12,
465,
781,
325,
14,
71,
781,
1570,
3324,
402,
2876,
8640,
14,
354,
370,
359,
21,
12,
3388,
61,
272,
436,
314,
2011,
6411,
402,
922,
1159,
536,
334,
1267,
3382,
959,
13,
1165,
4110,
9,
911,
506,
10585,
315,
22523,
272,
465,
5521,
465,
315,
4865,
272,
408,
272,
372,
469,
267,
283,
11346,
356,
469,
288,
283,
1273,
356,
5886,
8640,
14,
475,
63,
807,
1062,
288,
283,
751,
356,
2876,
8640,
14,
475,
63,
807,
342,
267,
789,
272,
789,
421,
199,
32,
571,
14,
4449,
2336,
63,
11326,
15,
10669,
384,
358,
199,
318,
20060,
384,
837,
272,
408,
55,
5362,
384,
4145,
2248,
4223,
1233,
1901,
282,
892,
1256,
2544,
1263,
12166,
4145,
12276,
626,
1256,
14,
272,
2104,
1655,
2256,
1937,
598,
12500,
9149,
624,
272,
372,
283,
3742,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
KaiyuWang16/xml2json-1
|
xml2json.py
|
9
|
7428
|
#!/usr/bin/env python
"""xml2json.py Convert XML to JSON
Relies on ElementTree for the XML parsing. This is based on
pesterfish.py but uses a different XML->JSON mapping.
The XML->JSON mapping is described at
http://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html
Rewritten to a command line utility by Hay Kranen < github.com/hay > with
contributions from George Hamilton (gmh04) and Dan Brown (jdanbrown)
XML JSON
<e/> "e": null
<e>text</e> "e": "text"
<e name="value" /> "e": { "@name": "value" }
<e name="value">text</e> "e": { "@name": "value", "#text": "text" }
<e> <a>text</a ><b>text</b> </e> "e": { "a": "text", "b": "text" }
<e> <a>text</a> <a>text</a> </e> "e": { "a": ["text", "text"] }
<e> text <a>text</a> </e> "e": { "#text": "text", "a": "text" }
This is very similar to the mapping used for Yahoo Web Services
(http://developer.yahoo.com/common/json.html#xml).
This is a mess in that it is so unpredictable -- it requires lots of testing
(e.g. to see if values are lists or strings or dictionaries). For use
in Python this could be vastly cleaner. Think about whether the internal
form can be more self-consistent while maintaining good external
characteristics for the JSON.
Look at the Yahoo version closely to see how it works. Maybe can adopt
that completely if it makes more sense...
R. White, 2006 November 6
"""
import json
import optparse
import sys
import os
import xml.etree.cElementTree as ET
def strip_tag(tag):
strip_ns_tag = tag
split_array = tag.split('}')
if len(split_array) > 1:
strip_ns_tag = split_array[1]
tag = strip_ns_tag
return tag
def elem_to_internal(elem, strip_ns=1, strip=1):
"""Convert an Element into an internal dictionary (not JSON!)."""
d = {}
elem_tag = elem.tag
if strip_ns:
elem_tag = strip_tag(elem.tag)
else:
for key, value in list(elem.attrib.items()):
d['@' + key] = value
# loop over subelements to merge them
for subelem in elem:
v = elem_to_internal(subelem, strip_ns=strip_ns, strip=strip)
tag = subelem.tag
if strip_ns:
tag = strip_tag(subelem.tag)
value = v[tag]
try:
# add to existing list for this tag
d[tag].append(value)
except AttributeError:
# turn existing entry into a list
d[tag] = [d[tag], value]
except KeyError:
# add a new non-list entry
d[tag] = value
text = elem.text
tail = elem.tail
if strip:
# ignore leading and trailing whitespace
if text:
text = text.strip()
if tail:
tail = tail.strip()
if tail:
d['#tail'] = tail
if d:
# use #text element if other attributes exist
if text:
d["#text"] = text
else:
# text is the value if no attributes
d = text or None
return {elem_tag: d}
def internal_to_elem(pfsh, factory=ET.Element):
"""Convert an internal dictionary (not JSON!) into an Element.
Whatever Element implementation we could import will be
used by default; if you want to use something else, pass the
Element class as the factory parameter.
"""
attribs = {}
text = None
tail = None
sublist = []
tag = list(pfsh.keys())
if len(tag) != 1:
raise ValueError("Illegal structure with multiple tags: %s" % tag)
tag = tag[0]
value = pfsh[tag]
if isinstance(value, dict):
for k, v in list(value.items()):
if k[:1] == "@":
attribs[k[1:]] = v
elif k == "#text":
text = v
elif k == "#tail":
tail = v
elif isinstance(v, list):
for v2 in v:
sublist.append(internal_to_elem({k: v2}, factory=factory))
else:
sublist.append(internal_to_elem({k: v}, factory=factory))
else:
text = value
e = factory(tag, attribs)
for sub in sublist:
e.append(sub)
e.text = text
e.tail = tail
return e
def elem2json(elem, options, strip_ns=1, strip=1):
"""Convert an ElementTree or Element into a JSON string."""
if hasattr(elem, 'getroot'):
elem = elem.getroot()
if options.pretty:
return json.dumps(elem_to_internal(elem, strip_ns=strip_ns, strip=strip), sort_keys=True, indent=4, separators=(',', ': '))
else:
return json.dumps(elem_to_internal(elem, strip_ns=strip_ns, strip=strip))
def json2elem(json_data, factory=ET.Element):
"""Convert a JSON string into an Element.
Whatever Element implementation we could import will be used by
default; if you want to use something else, pass the Element class
as the factory parameter.
"""
return internal_to_elem(json.loads(json_data), factory)
def xml2json(xmlstring, options, strip_ns=1, strip=1):
"""Convert an XML string into a JSON string."""
elem = ET.fromstring(xmlstring)
return elem2json(elem, options, strip_ns=strip_ns, strip=strip)
def json2xml(json_data, factory=ET.Element):
"""Convert a JSON string into an XML string.
Whatever Element implementation we could import will be used by
default; if you want to use something else, pass the Element class
as the factory parameter.
"""
if not isinstance(json_data, dict):
json_data = json.loads(json_data)
elem = internal_to_elem(json_data, factory)
return ET.tostring(elem)
def main():
p = optparse.OptionParser(
description='Converts XML to JSON or the other way around. Reads from standard input by default, or from file if given.',
prog='xml2json',
usage='%prog -t xml2json -o file.json [file]'
)
p.add_option('--type', '-t', help="'xml2json' or 'json2xml'", default="xml2json")
p.add_option('--out', '-o', help="Write to OUT instead of stdout")
p.add_option(
'--strip_text', action="store_true",
dest="strip_text", help="Strip text for xml2json")
p.add_option(
'--pretty', action="store_true",
dest="pretty", help="Format JSON output so it is easier to read")
p.add_option(
'--strip_namespace', action="store_true",
dest="strip_ns", help="Strip namespace for xml2json")
p.add_option(
'--strip_newlines', action="store_true",
dest="strip_nl", help="Strip newlines for xml2json")
options, arguments = p.parse_args()
inputstream = sys.stdin
if len(arguments) == 1:
try:
inputstream = open(arguments[0])
except:
sys.stderr.write("Problem reading '{0}'\n".format(arguments[0]))
p.print_help()
sys.exit(-1)
input = inputstream.read()
strip = 0
strip_ns = 0
if options.strip_text:
strip = 1
if options.strip_ns:
strip_ns = 1
if options.strip_nl:
input = input.replace('\n', '').replace('\r','')
if (options.type == "xml2json"):
out = xml2json(input, options, strip_ns, strip)
else:
out = json2xml(input)
if (options.out):
file = open(options.out, 'w')
file.write(out)
file.close()
else:
print(out)
if __name__ == "__main__":
main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
1652,
18,
1001,
14,
647,
221,
7905,
4692,
370,
4840,
199,
199,
497,
6528,
641,
13139,
367,
314,
4692,
6057,
14,
221,
961,
365,
4079,
641,
199,
321,
11652,
16056,
14,
647,
1325,
4440,
282,
3365,
4692,
5118,
6243,
4412,
14,
199,
1918,
4692,
5118,
6243,
4412,
365,
11736,
737,
199,
1014,
921,
1544,
14,
1652,
14,
957,
15,
5645,
15,
65,
15,
7968,
15,
1717,
15,
2192,
15,
6435,
1337,
13,
13007,
13,
1652,
13,
460,
13,
1001,
14,
1360,
199,
199,
497,
8938,
370,
282,
1414,
1004,
11420,
701,
869,
1187,
1804,
1312,
287,
665,
12869,
14,
957,
15,
72,
1187,
690,
543,
199,
388,
26675,
687,
5346,
24591,
869,
455,
382,
1860,
334,
13844,
72,
966,
9,
436,
24747,
699,
18406,
334,
17694,
290,
27133,
9,
199,
199,
4317,
19242,
4840,
199,
28,
69,
3133,
17907,
298,
69,
582,
2973,
199,
28,
69,
30,
505,
1108,
69,
30,
10473,
298,
69,
582,
298,
505,
2,
199,
28,
69,
536,
628,
585,
2,
7082,
5185,
298,
69,
582,
469,
9244,
354,
582,
298,
585,
2,
789,
199,
28,
69,
536,
628,
585,
1743,
505,
1108,
69,
30,
260,
298,
69,
582,
469,
9244,
354,
582,
298,
585,
401,
5426,
505,
582,
298,
505,
2,
789,
199,
28,
69,
30,
665,
65,
30,
505,
1108,
65,
690,
28,
66,
30,
505,
1108,
66,
30,
3068,
69,
30,
298,
69,
582,
469,
298,
65,
582,
298,
505,
401,
298,
66,
582,
298,
505,
2,
789,
199,
28,
69,
30,
665,
65,
30,
505,
1108,
65,
30,
665,
65,
30,
505,
1108,
65,
30,
3068,
69,
30,
298,
69,
582,
469,
298,
65,
582,
2097,
505,
401,
298,
505,
937,
789,
199,
28,
69,
30,
1318,
665,
65,
30,
505,
1108,
65,
30,
3068,
69,
30,
263,
298,
69,
582,
469,
5426,
505,
582,
298,
505,
401,
298,
65,
582,
298,
505,
2,
789,
199,
199,
2765,
365,
7437,
8545,
370,
314,
4412,
1202,
367,
1488,
65,
19112,
6001,
21813,
199,
8,
1014,
921,
11071,
14,
27231,
14,
957,
15,
2330,
15,
1001,
14,
1360,
3,
1652,
680,
199,
199,
2765,
365,
282,
15634,
315,
626,
652,
365,
880,
625,
6892,
461,
1553,
652,
5074,
24213,
402,
5343,
199,
8,
69,
14,
71,
14,
370,
1937,
340,
1338,
787,
5548,
503,
3326,
503,
11196,
680,
221,
2104,
675,
199,
262,
2018,
642,
4293,
506,
373,
1810,
590,
3633,
281,
14,
221,
3868,
2292,
3595,
3775,
314,
5007,
199,
964,
883,
506,
1655,
291,
13,
15478,
1830,
11075,
316,
6954,
5957,
199,
1560,
29867,
367,
314,
4840,
14,
199,
199,
20926,
737,
314,
1488,
65,
19112,
1015,
4002,
590,
370,
1937,
4212,
652,
5419,
14,
221,
23038,
883,
1503,
2992,
199,
9099,
14793,
340,
652,
7704,
1655,
12249,
1396,
199,
199,
50,
14,
2816,
1175,
12,
8315,
3091,
432,
976,
1227,
199,
624,
199,
199,
646,
2022,
199,
646,
8691,
199,
646,
984,
199,
646,
747,
199,
199,
646,
2748,
14,
9464,
14,
67,
15325,
465,
12265,
421,
199,
318,
6202,
63,
1450,
8,
1450,
304,
272,
6202,
63,
561,
63,
1450,
275,
1947,
272,
3715,
63,
1144,
275,
1947,
14,
1294,
31358,
272,
340,
822,
8,
1294,
63,
1144,
9,
690,
413,
26,
267,
6202,
63,
561,
63,
1450,
275,
3715,
63,
1144,
59,
17,
61,
267,
1947,
275,
6202,
63,
561,
63,
1450,
272,
372,
1947,
421,
199,
318,
6193,
63,
475,
63,
4672,
8,
6086,
12,
6202,
63,
561,
29,
17,
12,
6202,
29,
17,
304,
272,
408,
7306,
376,
6566,
1901,
376,
5007,
2600,
334,
1397,
4840,
1,
10477,
339,
366,
275,
1052,
272,
6193,
63,
1450,
275,
6193,
14,
1450,
272,
340,
6202,
63,
561,
26,
267,
6193,
63,
1450,
275,
6202,
63,
1450,
8,
6086,
14,
1450,
9,
272,
587,
26,
267,
367,
790,
12,
574,
315,
769,
8,
6086,
14,
6640,
14,
1744,
5109,
288,
366,
459,
32,
7,
435,
790,
61,
275,
574,
339,
327,
4438,
1806,
1007,
5527,
370,
5389,
3062,
272,
367,
1007,
6086,
315,
6193,
26,
267,
373,
275,
6193,
63,
475,
63,
4672,
8,
954,
6086,
12,
6202,
63,
561,
29,
1913,
63,
561,
12,
6202,
29,
1913,
9,
398,
1947,
275,
1007,
6086,
14,
1450,
267,
340,
6202,
63,
561,
26,
288,
1947,
275,
6202,
63,
1450,
8,
954,
6086,
14,
1450,
9,
398,
574,
275,
373,
59,
1450,
61,
398,
862,
26,
288,
327,
1050,
370,
3411,
769,
367,
642,
1947,
288,
366,
59,
1450,
1055,
740,
8,
585,
9,
267,
871,
4281,
26,
288,
327,
7485,
3411,
2397,
1901,
282,
769,
288,
366,
59,
1450,
61,
275,
359,
68,
59,
1450,
467,
574,
61,
267,
871,
4067,
26,
288,
327,
1050,
282,
892,
2222,
13,
513,
2397,
288,
366,
59,
1450,
61,
275,
574,
272,
1318,
275,
6193,
14,
505,
272,
9483,
275,
6193,
14,
1521,
272,
340,
6202,
26,
267,
327,
3686,
9186,
436,
8520,
8139,
267,
340,
1318,
26,
288,
1318,
275,
1318,
14,
1913,
342,
267,
340,
9483,
26,
288,
9483,
275,
9483,
14,
1913,
342,
339,
340,
9483,
26,
267,
366,
459,
3,
1521,
418,
275,
9483,
339,
340,
366,
26,
267,
327,
675,
327,
505,
1819,
340,
1163,
3004,
2187,
267,
340,
1318,
26,
288,
366,
905,
3,
505,
937,
275,
1318,
272,
587,
26,
267,
327,
1318,
365,
314,
574,
340,
949,
3004,
267,
366,
275,
1318,
503,
488,
272,
372,
469,
6086,
63,
1450,
26,
366,
93,
421,
199,
318,
5007,
63,
475,
63,
6086,
8,
9928,
609,
12,
6434,
29,
775,
14,
2162,
304,
339,
408,
7306,
376,
5007,
2600,
334,
1397,
4840,
21866,
1901,
376,
6566,
14,
339,
2816,
12359,
6566,
4514,
781,
4293,
492,
911,
506,
272,
1202,
701,
849,
27,
340,
1265,
2934,
370,
675,
6020,
587,
12,
986,
314,
272,
6566,
1021,
465,
314,
6434,
2725,
14,
272,
408,
339,
737,
19577,
275,
1052,
272,
1318,
275,
488,
272,
9483,
275,
488,
272,
27007,
275,
942,
272,
1947,
275,
769,
8,
9928,
609,
14,
1612,
1012,
272,
340,
822,
8,
1450,
9,
1137,
413,
26,
267,
746,
1722,
480,
25501,
5523,
543,
3663,
3762,
26,
450,
83,
2,
450
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
1652,
18,
1001,
14,
647,
221,
7905,
4692,
370,
4840,
199,
199,
497,
6528,
641,
13139,
367,
314,
4692,
6057,
14,
221,
961,
365,
4079,
641,
199,
321,
11652,
16056,
14,
647,
1325,
4440,
282,
3365,
4692,
5118,
6243,
4412,
14,
199,
1918,
4692,
5118,
6243,
4412,
365,
11736,
737,
199,
1014,
921,
1544,
14,
1652,
14,
957,
15,
5645,
15,
65,
15,
7968,
15,
1717,
15,
2192,
15,
6435,
1337,
13,
13007,
13,
1652,
13,
460,
13,
1001,
14,
1360,
199,
199,
497,
8938,
370,
282,
1414,
1004,
11420,
701,
869,
1187,
1804,
1312,
287,
665,
12869,
14,
957,
15,
72,
1187,
690,
543,
199,
388,
26675,
687,
5346,
24591,
869,
455,
382,
1860,
334,
13844,
72,
966,
9,
436,
24747,
699,
18406,
334,
17694,
290,
27133,
9,
199,
199,
4317,
19242,
4840,
199,
28,
69,
3133,
17907,
298,
69,
582,
2973,
199,
28,
69,
30,
505,
1108,
69,
30,
10473,
298,
69,
582,
298,
505,
2,
199,
28,
69,
536,
628,
585,
2,
7082,
5185,
298,
69,
582,
469,
9244,
354,
582,
298,
585,
2,
789,
199,
28,
69,
536,
628,
585,
1743,
505,
1108,
69,
30,
260,
298,
69,
582,
469,
9244,
354,
582,
298,
585,
401,
5426,
505,
582,
298,
505,
2,
789,
199,
28,
69,
30,
665,
65,
30,
505,
1108,
65,
690,
28,
66,
30,
505,
1108,
66,
30,
3068,
69,
30,
298,
69,
582,
469,
298,
65,
582,
298,
505,
401,
298,
66,
582,
298,
505,
2,
789,
199,
28,
69,
30,
665,
65,
30,
505,
1108,
65,
30,
665,
65,
30,
505,
1108,
65,
30,
3068,
69,
30,
298,
69,
582,
469,
298,
65,
582,
2097,
505,
401,
298,
505,
937,
789,
199,
28,
69,
30,
1318,
665,
65,
30,
505,
1108,
65,
30,
3068,
69,
30,
263,
298,
69,
582,
469,
5426,
505,
582,
298,
505,
401,
298,
65,
582,
298,
505,
2,
789,
199,
199,
2765,
365,
7437,
8545,
370,
314,
4412,
1202,
367,
1488,
65,
19112,
6001,
21813,
199,
8,
1014,
921,
11071,
14,
27231,
14,
957,
15,
2330,
15,
1001,
14,
1360,
3,
1652,
680,
199,
199,
2765,
365,
282,
15634,
315,
626,
652,
365,
880,
625,
6892,
461,
1553,
652,
5074,
24213,
402,
5343,
199,
8,
69,
14,
71,
14,
370,
1937,
340,
1338,
787,
5548,
503,
3326,
503,
11196,
680,
221,
2104,
675,
199,
262,
2018,
642,
4293,
506,
373,
1810,
590,
3633,
281,
14,
221,
3868,
2292,
3595,
3775,
314,
5007,
199,
964,
883,
506,
1655,
291,
13,
15478,
1830,
11075,
316,
6954,
5957,
199,
1560,
29867,
367,
314,
4840,
14,
199,
199,
20926,
737,
314,
1488,
65,
19112,
1015,
4002,
590,
370,
1937,
4212,
652,
5419,
14,
221,
23038,
883,
1503,
2992,
199,
9099,
14793,
340,
652,
7704,
1655,
12249,
1396,
199,
199,
50,
14,
2816,
1175,
12,
8315,
3091,
432,
976,
1227,
199,
624,
199,
199,
646,
2022,
199,
646,
8691,
199,
646,
984,
199,
646,
747,
199,
199,
646,
2748,
14,
9464,
14,
67,
15325,
465,
12265,
421,
199,
318,
6202,
63,
1450,
8,
1450,
304,
272,
6202,
63,
561,
63,
1450,
275,
1947,
272,
3715,
63,
1144,
275,
1947,
14,
1294,
31358,
272,
340,
822,
8,
1294,
63,
1144,
9,
690,
413,
26,
267,
6202,
63,
561,
63,
1450,
275,
3715,
63,
1144,
59,
17,
61,
267,
1947,
275,
6202,
63,
561,
63,
1450,
272,
372,
1947,
421,
199,
318,
6193,
63,
475,
63,
4672,
8,
6086,
12,
6202,
63,
561,
29,
17,
12,
6202,
29,
17,
304,
272,
408,
7306,
376,
6566,
1901,
376,
5007,
2600,
334,
1397,
4840,
1,
10477,
339,
366,
275,
1052,
272,
6193,
63,
1450,
275,
6193,
14,
1450,
272,
340,
6202,
63,
561,
26,
267,
6193,
63,
1450,
275,
6202,
63,
1450,
8,
6086,
14,
1450,
9,
272,
587,
26,
267,
367,
790,
12,
574,
315,
769,
8,
6086,
14,
6640,
14,
1744,
5109,
288,
366,
459,
32,
7,
435,
790,
61,
275,
574,
339,
327,
4438,
1806,
1007,
5527,
370,
5389,
3062,
272,
367,
1007,
6086,
315,
6193,
26,
267,
373,
275,
6193,
63,
475,
63,
4672,
8,
954,
6086,
12,
6202,
63,
561,
29,
1913,
63,
561,
12,
6202,
29,
1913,
9,
398,
1947,
275,
1007,
6086,
14,
1450,
267,
340,
6202,
63,
561,
26,
288,
1947,
275,
6202,
63,
1450,
8,
954,
6086,
14,
1450,
9,
398,
574,
275,
373,
59,
1450,
61,
398,
862,
26,
288,
327,
1050,
370,
3411,
769,
367,
642,
1947,
288,
366,
59,
1450,
1055,
740,
8,
585,
9,
267,
871,
4281,
26,
288,
327,
7485,
3411,
2397,
1901,
282,
769,
288,
366,
59,
1450,
61,
275,
359,
68,
59,
1450,
467,
574,
61,
267,
871,
4067,
26,
288,
327,
1050,
282,
892,
2222,
13,
513,
2397,
288,
366,
59,
1450,
61,
275,
574,
272,
1318,
275,
6193,
14,
505,
272,
9483,
275,
6193,
14,
1521,
272,
340,
6202,
26,
267,
327,
3686,
9186,
436,
8520,
8139,
267,
340,
1318,
26,
288,
1318,
275,
1318,
14,
1913,
342,
267,
340,
9483,
26,
288,
9483,
275,
9483,
14,
1913,
342,
339,
340,
9483,
26,
267,
366,
459,
3,
1521,
418,
275,
9483,
339,
340,
366,
26,
267,
327,
675,
327,
505,
1819,
340,
1163,
3004,
2187,
267,
340,
1318,
26,
288,
366,
905,
3,
505,
937,
275,
1318,
272,
587,
26,
267,
327,
1318,
365,
314,
574,
340,
949,
3004,
267,
366,
275,
1318,
503,
488,
272,
372,
469,
6086,
63,
1450,
26,
366,
93,
421,
199,
318,
5007,
63,
475,
63,
6086,
8,
9928,
609,
12,
6434,
29,
775,
14,
2162,
304,
339,
408,
7306,
376,
5007,
2600,
334,
1397,
4840,
21866,
1901,
376,
6566,
14,
339,
2816,
12359,
6566,
4514,
781,
4293,
492,
911,
506,
272,
1202,
701,
849,
27,
340,
1265,
2934,
370,
675,
6020,
587,
12,
986,
314,
272,
6566,
1021,
465,
314,
6434,
2725,
14,
272,
408,
339,
737,
19577,
275,
1052,
272,
1318,
275,
488,
272,
9483,
275,
488,
272,
27007,
275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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
CuonDeveloper/cuon
|
cuon_client/cuon/Databases/SingleDataTreeModel.py
|
3
|
2386
|
# -*- coding: utf-8 -*-
##Copyright (C) [2003] [Juergen Hamel, D-32584 Loehne]
##This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
##published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
##This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
##warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
##for more details.
##You should have received a copy of the GNU General Public License along with this program; if not, write to the
##Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
import sys
from types import *
try:
import pygtk
pygtk.require('2.0')
import gtk
import gobject
#from gtk import True, FALSE
except:
pass
COLUMN_NAME = 0
COLUMN_ZIPCODE = 1
COLUMN_CITY = 2
COLUMN_STREET= 3
COLUMN_ID = 4
class SingleDataTreeModel:
def __init__(self):
print 'new TreeModel'
self.store = None
def createModel(self, data):
self.store.clear()
for item in data:
iter = self.store.append()
# store.set(iter, COLUMN_NAME, item[0], COLUMN_ZIPCODE, item[1], COLUMN_CITY, item[2], COLUMN_STREET, item[3], COLUMN_ID, item[4] )
iLen = len(item)
for i in xrange(iLen):
self.store.set(iter,i, item[i] )
self.store.connect("rows-reordered", self.store_reordered)
return self.store
def setColumns(self, tree1, listHeader):
t1 = 0
columns = tree1.get_columns()
for i in columns:
tree1.remove_column(i)
sortID = 0
for i in listHeader['names']:
column = gtk.TreeViewColumn(i, gtk.CellRendererText(), text=t1)
# column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
# column.set_fixed_width(30)
column.set_clickable(True)
column.set_sort_column_id(sortID)
sortID += 1
tree1.append_column(column)
t1 = t1 +1
def setStore(self, store):
self.store = store
def store_reordered(self):
print 'store reordered'
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
309,
7384,
334,
35,
9,
359,
17919,
61,
221,
359,
42,
14262,
2268,
869,
14868,
12,
577,
13,
708,
12248,
3835,
24528,
685,
61,
199,
199,
309,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
8987,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
309,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
199,
309,
3281,
1312,
369,
402,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
1696,
1684,
844,
199,
309,
509,
1655,
2436,
14,
199,
199,
309,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
199,
309,
10146,
2290,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
9948,
199,
646,
984,
199,
504,
2943,
492,
627,
199,
893,
26,
272,
492,
1134,
12275,
272,
1134,
12275,
14,
4365,
360,
18,
14,
16,
358,
272,
492,
8116,
272,
492,
25595,
199,
3,
504,
8116,
492,
715,
12,
481,
17361,
199,
2590,
26,
272,
986,
421,
199,
21436,
63,
2339,
755,
275,
378,
199,
21436,
63,
16977,
6012,
420,
275,
413,
199,
21436,
63,
35,
1922,
259,
275,
499,
199,
21436,
63,
840,
907,
775,
29,
650,
199,
21436,
63,
998,
275,
841,
421,
199,
533,
13050,
1451,
3987,
1685,
26,
272,
347,
636,
826,
721,
277,
304,
267,
870,
283,
1222,
12178,
1685,
7,
267,
291,
14,
1617,
275,
488,
18407,
347,
1218,
1685,
8,
277,
12,
666,
304,
2728,
291,
14,
1617,
14,
3584,
342,
420,
267,
367,
1242,
315,
666,
26,
288,
2740,
275,
291,
14,
1617,
14,
740,
342,
288,
327,
3322,
3877,
14,
409,
8,
1661,
12,
29955,
63,
2339,
12,
1242,
59,
16,
467,
29955,
63,
16977,
6012,
12,
1242,
59,
17,
467,
29955,
63,
35,
1922,
12,
1242,
59,
18,
467,
29955,
63,
840,
907,
775,
12,
1242,
59,
19,
467,
29955,
63,
998,
12,
1242,
59,
20,
61,
776,
288,
284,
3166,
275,
822,
8,
1053,
9,
288,
367,
284,
315,
4945,
8,
73,
3166,
304,
355,
291,
14,
1617,
14,
409,
8,
1661,
12,
73,
12,
1242,
59,
73,
61,
776,
2490,
267,
291,
14,
1617,
14,
2242,
480,
3838,
13,
264,
8235,
401,
291,
14,
1617,
63,
264,
8235,
9,
398,
372,
291,
14,
1617,
339,
347,
663,
15086,
8,
277,
12,
3123,
17,
12,
769,
2567,
304,
267,
307,
17,
275,
378,
267,
4362,
275,
3123,
17,
14,
362,
63,
3406,
342,
267,
367,
284,
315,
4362,
26,
288,
3123,
17,
14,
2168,
63,
2301,
8,
73,
9,
267,
4069,
998,
275,
378,
267,
367,
284,
315,
769,
2567,
459,
1247,
2565,
288,
2763,
275,
8116,
14,
32656,
4547,
8,
73,
12,
8116,
14,
8108,
11355,
1872,
1062,
1318,
29,
84,
17,
9,
199,
3,
3322,
2763,
14,
409,
63,
30639,
8,
12275,
14,
22841,
63,
12058,
63,
21436,
63,
23837,
9,
199,
3,
3322,
2763,
14,
409,
63,
5964,
63,
2063,
8,
1216,
9,
288,
2763,
14,
409,
63,
4891,
461,
8,
549,
9,
288,
2763,
14,
409,
63,
3191,
63,
2301,
63,
344,
8,
3191,
998,
9,
288,
4069,
998,
847,
413,
288,
3123,
17,
14,
740,
63,
2301,
8,
2301,
9,
288,
307,
17,
275,
307,
17,
435,
17,
1467,
339,
347,
663,
5502,
8,
277,
12,
3877,
304,
267,
291,
14,
1617,
275,
3877,
326,
272,
347,
3877,
63,
264,
8235,
8,
277,
304,
267,
870,
283,
1617,
295,
8235,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
309,
7384,
334,
35,
9,
359,
17919,
61,
221,
359,
42,
14262,
2268,
869,
14868,
12,
577,
13,
708,
12248,
3835,
24528,
685,
61,
199,
199,
309,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
8987,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
309,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
199,
309,
3281,
1312,
369,
402,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
1696,
1684,
844,
199,
309,
509,
1655,
2436,
14,
199,
199,
309,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
199,
309,
10146,
2290,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
9948,
199,
646,
984,
199,
504,
2943,
492,
627,
199,
893,
26,
272,
492,
1134,
12275,
272,
1134,
12275,
14,
4365,
360,
18,
14,
16,
358,
272,
492,
8116,
272,
492,
25595,
199,
3,
504,
8116,
492,
715,
12,
481,
17361,
199,
2590,
26,
272,
986,
421,
199,
21436,
63,
2339,
755,
275,
378,
199,
21436,
63,
16977,
6012,
420,
275,
413,
199,
21436,
63,
35,
1922,
259,
275,
499,
199,
21436,
63,
840,
907,
775,
29,
650,
199,
21436,
63,
998,
275,
841,
421,
199,
533,
13050,
1451,
3987,
1685,
26,
272,
347,
636,
826,
721,
277,
304,
267,
870,
283,
1222,
12178,
1685,
7,
267,
291,
14,
1617,
275,
488,
18407,
347,
1218,
1685,
8,
277,
12,
666,
304,
2728,
291,
14,
1617,
14,
3584,
342,
420,
267,
367,
1242,
315,
666,
26,
288,
2740,
275,
291,
14,
1617,
14,
740,
342,
288,
327,
3322,
3877,
14,
409,
8,
1661,
12,
29955,
63,
2339,
12,
1242,
59,
16,
467,
29955,
63,
16977,
6012,
12,
1242,
59,
17,
467,
29955,
63,
35,
1922,
12,
1242,
59,
18,
467,
29955,
63,
840,
907,
775,
12,
1242,
59,
19,
467,
29955,
63,
998,
12,
1242,
59,
20,
61,
776,
288,
284,
3166,
275,
822,
8,
1053,
9,
288,
367,
284,
315,
4945,
8,
73,
3166,
304,
355,
291,
14,
1617,
14,
409,
8,
1661,
12,
73,
12,
1242,
59,
73,
61,
776,
2490,
267,
291,
14,
1617,
14,
2242,
480,
3838,
13,
264,
8235,
401,
291,
14,
1617,
63,
264,
8235,
9,
398,
372,
291,
14,
1617,
339,
347,
663,
15086,
8,
277,
12,
3123,
17,
12,
769,
2567,
304,
267,
307,
17,
275,
378,
267,
4362,
275,
3123,
17,
14,
362,
63,
3406,
342,
267,
367,
284,
315,
4362,
26,
288,
3123,
17,
14,
2168,
63,
2301,
8,
73,
9,
267,
4069,
998,
275,
378,
267,
367,
284,
315,
769,
2567,
459,
1247,
2565,
288,
2763,
275,
8116,
14,
32656,
4547,
8,
73,
12,
8116,
14,
8108,
11355,
1872,
1062,
1318,
29,
84,
17,
9,
199,
3,
3322,
2763,
14,
409,
63,
30639,
8,
12275,
14,
22841,
63,
12058,
63,
21436,
63,
23837,
9,
199,
3,
3322,
2763,
14,
409,
63,
5964,
63,
2063,
8,
1216,
9,
288,
2763,
14,
409,
63,
4891,
461,
8,
549,
9,
288,
2763,
14,
409,
63,
3191,
63,
2301,
63,
344,
8,
3191,
998,
9,
288,
4069,
998,
847,
413,
288,
3123,
17,
14,
740,
63,
2301,
8,
2301,
9,
288,
307,
17,
275,
307,
17,
435,
17,
1467,
339,
347,
663,
5502,
8,
277,
12,
3877,
304,
267,
291,
14,
1617,
275,
3877,
326,
272,
347,
3877,
63,
264,
8235,
8,
277,
304,
267,
870,
283,
1617,
295,
8235,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Senseg/Py4A
|
python-modules/twisted/twisted/conch/test/test_manhole.py
|
59
|
10507
|
# -*- test-case-name: twisted.conch.test.test_manhole -*-
# Copyright (c) 2001-2007 Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Tests for L{twisted.conch.manhole}.
"""
import traceback
from twisted.trial import unittest
from twisted.internet import error, defer
from twisted.test.proto_helpers import StringTransport
from twisted.conch.test.test_recvline import _TelnetMixin, _SSHMixin, _StdioMixin, stdio, ssh
from twisted.conch import manhole
from twisted.conch.insults import insults
def determineDefaultFunctionName():
"""
Return the string used by Python as the name for code objects which are
compiled from interactive input or at the top-level of modules.
"""
try:
1 / 0
except:
# The last frame is this function. The second to last frame is this
# function's caller, which is module-scope, which is what we want,
# so -2.
return traceback.extract_stack()[-2][2]
defaultFunctionName = determineDefaultFunctionName()
class ManholeInterpreterTests(unittest.TestCase):
"""
Tests for L{manhole.ManholeInterpreter}.
"""
def test_resetBuffer(self):
"""
L{ManholeInterpreter.resetBuffer} should empty the input buffer.
"""
interpreter = manhole.ManholeInterpreter(None)
interpreter.buffer.extend(["1", "2"])
interpreter.resetBuffer()
self.assertFalse(interpreter.buffer)
class ManholeProtocolTests(unittest.TestCase):
"""
Tests for L{manhole.Manhole}.
"""
def test_interruptResetsInterpreterBuffer(self):
"""
L{manhole.Manhole.handle_INT} should cause the interpreter input buffer
to be reset.
"""
transport = StringTransport()
terminal = insults.ServerProtocol(manhole.Manhole)
terminal.makeConnection(transport)
protocol = terminal.terminalProtocol
interpreter = protocol.interpreter
interpreter.buffer.extend(["1", "2"])
protocol.handle_INT()
self.assertFalse(interpreter.buffer)
class WriterTestCase(unittest.TestCase):
def testInteger(self):
manhole.lastColorizedLine("1")
def testDoubleQuoteString(self):
manhole.lastColorizedLine('"1"')
def testSingleQuoteString(self):
manhole.lastColorizedLine("'1'")
def testTripleSingleQuotedString(self):
manhole.lastColorizedLine("'''1'''")
def testTripleDoubleQuotedString(self):
manhole.lastColorizedLine('"""1"""')
def testFunctionDefinition(self):
manhole.lastColorizedLine("def foo():")
def testClassDefinition(self):
manhole.lastColorizedLine("class foo:")
class ManholeLoopbackMixin:
serverProtocol = manhole.ColoredManhole
def wfd(self, d):
return defer.waitForDeferred(d)
def testSimpleExpression(self):
done = self.recvlineClient.expect("done")
self._testwrite(
"1 + 1\n"
"done")
def finished(ign):
self._assertBuffer(
[">>> 1 + 1",
"2",
">>> done"])
return done.addCallback(finished)
def testTripleQuoteLineContinuation(self):
done = self.recvlineClient.expect("done")
self._testwrite(
"'''\n'''\n"
"done")
def finished(ign):
self._assertBuffer(
[">>> '''",
"... '''",
"'\\n'",
">>> done"])
return done.addCallback(finished)
def testFunctionDefinition(self):
done = self.recvlineClient.expect("done")
self._testwrite(
"def foo(bar):\n"
"\tprint bar\n\n"
"foo(42)\n"
"done")
def finished(ign):
self._assertBuffer(
[">>> def foo(bar):",
"... print bar",
"... ",
">>> foo(42)",
"42",
">>> done"])
return done.addCallback(finished)
def testClassDefinition(self):
done = self.recvlineClient.expect("done")
self._testwrite(
"class Foo:\n"
"\tdef bar(self):\n"
"\t\tprint 'Hello, world!'\n\n"
"Foo().bar()\n"
"done")
def finished(ign):
self._assertBuffer(
[">>> class Foo:",
"... def bar(self):",
"... print 'Hello, world!'",
"... ",
">>> Foo().bar()",
"Hello, world!",
">>> done"])
return done.addCallback(finished)
def testException(self):
done = self.recvlineClient.expect("done")
self._testwrite(
"raise Exception('foo bar baz')\n"
"done")
def finished(ign):
self._assertBuffer(
[">>> raise Exception('foo bar baz')",
"Traceback (most recent call last):",
' File "<console>", line 1, in ' + defaultFunctionName,
"Exception: foo bar baz",
">>> done"])
return done.addCallback(finished)
def testControlC(self):
done = self.recvlineClient.expect("done")
self._testwrite(
"cancelled line" + manhole.CTRL_C +
"done")
def finished(ign):
self._assertBuffer(
[">>> cancelled line",
"KeyboardInterrupt",
">>> done"])
return done.addCallback(finished)
def test_interruptDuringContinuation(self):
"""
Sending ^C to Manhole while in a state where more input is required to
complete a statement should discard the entire ongoing statement and
reset the input prompt to the non-continuation prompt.
"""
continuing = self.recvlineClient.expect("things")
self._testwrite("(\nthings")
def gotContinuation(ignored):
self._assertBuffer(
[">>> (",
"... things"])
interrupted = self.recvlineClient.expect(">>> ")
self._testwrite(manhole.CTRL_C)
return interrupted
continuing.addCallback(gotContinuation)
def gotInterruption(ignored):
self._assertBuffer(
[">>> (",
"... things",
"KeyboardInterrupt",
">>> "])
continuing.addCallback(gotInterruption)
return continuing
def testControlBackslash(self):
self._testwrite("cancelled line")
partialLine = self.recvlineClient.expect("cancelled line")
def gotPartialLine(ign):
self._assertBuffer(
[">>> cancelled line"])
self._testwrite(manhole.CTRL_BACKSLASH)
d = self.recvlineClient.onDisconnection
return self.assertFailure(d, error.ConnectionDone)
def gotClearedLine(ign):
self._assertBuffer(
[""])
return partialLine.addCallback(gotPartialLine).addCallback(gotClearedLine)
def testControlD(self):
self._testwrite("1 + 1")
helloWorld = self.wfd(self.recvlineClient.expect(r"\+ 1"))
yield helloWorld
helloWorld.getResult()
self._assertBuffer([">>> 1 + 1"])
self._testwrite(manhole.CTRL_D + " + 1")
cleared = self.wfd(self.recvlineClient.expect(r"\+ 1"))
yield cleared
cleared.getResult()
self._assertBuffer([">>> 1 + 1 + 1"])
self._testwrite("\n")
printed = self.wfd(self.recvlineClient.expect("3\n>>> "))
yield printed
printed.getResult()
self._testwrite(manhole.CTRL_D)
d = self.recvlineClient.onDisconnection
disconnected = self.wfd(self.assertFailure(d, error.ConnectionDone))
yield disconnected
disconnected.getResult()
testControlD = defer.deferredGenerator(testControlD)
def testControlL(self):
"""
CTRL+L is generally used as a redraw-screen command in terminal
applications. Manhole doesn't currently respect this usage of it,
but it should at least do something reasonable in response to this
event (rather than, say, eating your face).
"""
# Start off with a newline so that when we clear the display we can
# tell by looking for the missing first empty prompt line.
self._testwrite("\n1 + 1")
helloWorld = self.wfd(self.recvlineClient.expect(r"\+ 1"))
yield helloWorld
helloWorld.getResult()
self._assertBuffer([">>> ", ">>> 1 + 1"])
self._testwrite(manhole.CTRL_L + " + 1")
redrew = self.wfd(self.recvlineClient.expect(r"1 \+ 1 \+ 1"))
yield redrew
redrew.getResult()
self._assertBuffer([">>> 1 + 1 + 1"])
testControlL = defer.deferredGenerator(testControlL)
def testDeferred(self):
self._testwrite(
"from twisted.internet import defer, reactor\n"
"d = defer.Deferred()\n"
"d\n")
deferred = self.wfd(self.recvlineClient.expect("<Deferred #0>"))
yield deferred
deferred.getResult()
self._testwrite(
"c = reactor.callLater(0.1, d.callback, 'Hi!')\n")
delayed = self.wfd(self.recvlineClient.expect(">>> "))
yield delayed
delayed.getResult()
called = self.wfd(self.recvlineClient.expect("Deferred #0 called back: 'Hi!'\n>>> "))
yield called
called.getResult()
self._assertBuffer(
[">>> from twisted.internet import defer, reactor",
">>> d = defer.Deferred()",
">>> d",
"<Deferred #0>",
">>> c = reactor.callLater(0.1, d.callback, 'Hi!')",
"Deferred #0 called back: 'Hi!'",
">>> "])
testDeferred = defer.deferredGenerator(testDeferred)
class ManholeLoopbackTelnet(_TelnetMixin, unittest.TestCase, ManholeLoopbackMixin):
pass
class ManholeLoopbackSSH(_SSHMixin, unittest.TestCase, ManholeLoopbackMixin):
if ssh is None:
skip = "Crypto requirements missing, can't run manhole tests over ssh"
class ManholeLoopbackStdio(_StdioMixin, unittest.TestCase, ManholeLoopbackMixin):
if stdio is None:
skip = "Terminal requirements missing, can't run manhole tests over stdio"
else:
serverProtocol = stdio.ConsoleManhole
|
apache-2.0
|
[
3,
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
388,
335,
14,
396,
14,
396,
63,
1237,
16668,
1882,
199,
3,
1898,
334,
67,
9,
12521,
13,
9488,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
2925,
367,
491,
91,
12145,
14,
388,
335,
14,
1237,
16668,
5565,
199,
624,
199,
199,
646,
5190,
199,
199,
504,
7390,
14,
14443,
492,
2882,
199,
504,
7390,
14,
4901,
492,
1125,
12,
10133,
199,
504,
7390,
14,
396,
14,
2625,
63,
7546,
492,
2624,
7836,
199,
504,
7390,
14,
388,
335,
14,
396,
14,
396,
63,
7637,
604,
492,
485,
52,
352,
846,
4256,
12,
485,
13716,
4256,
12,
485,
933,
3006,
4256,
12,
410,
3006,
12,
8635,
199,
504,
7390,
14,
388,
335,
492,
2169,
16668,
199,
504,
7390,
14,
388,
335,
14,
3617,
427,
83,
492,
5261,
427,
83,
421,
199,
318,
6705,
2698,
3481,
985,
837,
272,
408,
272,
1432,
314,
1059,
1202,
701,
2018,
465,
314,
536,
367,
1233,
2251,
1314,
787,
272,
10311,
687,
12777,
1324,
503,
737,
314,
2746,
13,
1896,
402,
4621,
14,
272,
408,
272,
862,
26,
267,
413,
1182,
378,
272,
871,
26,
267,
327,
710,
2061,
2787,
365,
642,
805,
14,
221,
710,
3499,
370,
2061,
2787,
365,
642,
267,
327,
805,
1159,
8025,
12,
1314,
365,
859,
13,
2645,
12,
1314,
365,
4052,
781,
2934,
12,
267,
327,
880,
446,
18,
14,
267,
372,
5190,
14,
5005,
63,
2340,
19105,
18,
1527,
18,
61,
199,
885,
3481,
985,
275,
6705,
2698,
3481,
985,
342,
4388,
199,
533,
4688,
16668,
2620,
26499,
2925,
8,
2796,
14,
1746,
304,
272,
408,
272,
6496,
367,
491,
91,
1237,
16668,
14,
2395,
16668,
2620,
26499,
5565,
272,
408,
272,
347,
511,
63,
3958,
3299,
8,
277,
304,
267,
408,
267,
491,
91,
2395,
16668,
2620,
26499,
14,
3958,
3299,
93,
1077,
2701,
314,
1324,
3335,
14,
267,
408,
267,
12693,
275,
2169,
16668,
14,
2395,
16668,
2620,
26499,
8,
403,
9,
267,
12693,
14,
2738,
14,
2880,
5234,
17,
401,
298,
18,
3135,
267,
12693,
14,
3958,
3299,
342,
267,
291,
14,
3334,
8,
20244,
14,
2738,
9,
4388,
199,
533,
4688,
16668,
3658,
2925,
8,
2796,
14,
1746,
304,
272,
408,
272,
6496,
367,
491,
91,
1237,
16668,
14,
2395,
16668,
5565,
272,
408,
272,
347,
511,
63,
20172,
497,
2193,
2620,
26499,
3299,
8,
277,
304,
267,
408,
267,
491,
91,
1237,
16668,
14,
2395,
16668,
14,
2479,
63,
2919,
93,
1077,
7675,
314,
12693,
1324,
3335,
267,
370,
506,
5305,
14,
267,
408,
267,
7773,
275,
2624,
7836,
342,
267,
11167,
275,
5261,
427,
83,
14,
3120,
3658,
8,
1237,
16668,
14,
2395,
16668,
9,
267,
11167,
14,
1875,
3225,
8,
5545,
9,
267,
4113,
275,
11167,
14,
12010,
3658,
267,
12693,
275,
4113,
14,
20244,
267,
12693,
14,
2738,
14,
2880,
5234,
17,
401,
298,
18,
3135,
267,
4113,
14,
2479,
63,
2919,
342,
267,
291,
14,
3334,
8,
20244,
14,
2738,
9,
4388,
199,
533,
24441,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
2674,
8,
277,
304,
267,
2169,
16668,
14,
2019,
4117,
1759,
3049,
480,
17,
531,
2378,
347,
511,
7281,
12838,
1558,
8,
277,
304,
267,
2169,
16668,
14,
2019,
4117,
1759,
3049,
14088,
17,
9008,
2378,
347,
511,
7200,
12838,
1558,
8,
277,
304,
267,
2169,
16668,
14,
2019,
4117,
1759,
3049,
15587,
17,
9859,
2378,
347,
511,
6948,
11045,
7200,
24115,
1558,
8,
277,
304,
267,
2169,
16668,
14,
2019,
4117,
1759,
3049,
480,
2344,
17,
2344,
531,
2378,
347,
511,
6948,
11045,
7281,
24115,
1558,
8,
277,
304,
267,
2169,
16668,
14,
2019,
4117,
1759,
3049,
360,
624,
17,
624,
358,
2378,
347,
511,
3481,
10701,
8,
277,
304,
267,
2169,
16668,
14,
2019,
4117,
1759,
3049,
480,
318,
3925,
837,
531,
2378,
347,
511,
2543,
10701,
8,
277,
304,
267,
2169,
16668,
14,
2019,
4117,
1759,
3049,
480,
533,
3925,
9107,
421,
199,
533,
4688,
16668,
19690,
4256,
26,
272,
1654,
3658,
275,
2169,
16668,
14,
967,
21252,
2395,
16668,
339,
347,
336,
2592,
8,
277,
12,
366,
304,
267,
372,
10133,
14,
2573,
1858,
9937,
8,
68,
9,
339,
347,
511,
3184,
9093,
8,
277,
304,
267,
4224,
275,
291,
14,
7637,
604,
3041,
14,
4921,
480,
4456,
531,
398,
291,
423,
396,
952,
8,
288,
298,
17,
435,
413,
60,
78,
2,
288,
298,
4456,
531,
398,
347,
9158,
8,
1030,
304,
288,
291,
423,
479,
3299,
8,
355,
2097,
6071,
413,
435,
413,
401,
326,
298,
18,
401,
326,
298,
6071,
4224,
3135,
398,
372,
4224,
14,
10053,
8,
8669,
9,
339,
347,
511,
6948,
11045,
12838,
3049,
24593,
4086,
8,
277,
304,
267,
4224,
275,
291,
14,
7637,
604,
3041,
14,
4921,
480,
4456,
531,
398,
291,
423,
396,
952,
8,
288,
17172,
1154,
78,
891,
1154,
78,
2,
288,
298,
4456,
531,
398,
347,
9158,
8,
1030,
304,
288,
291,
423,
479,
3299,
8,
355,
2097,
6071,
1449,
401,
326,
298,
1396,
1449,
401,
326,
3546,
1103,
78,
4662,
326,
298,
6071,
4224,
3135,
398,
372,
4224,
14,
10053,
8,
8669,
9,
339,
347,
511,
3481,
10701,
8,
277,
304,
267,
4224,
275,
291,
14,
7637,
604,
3041,
14,
4921,
480,
4456,
531,
398,
291,
423,
396,
952,
8,
288,
298,
318,
3925,
8,
1700,
17211,
78,
2,
288,
1867,
683,
672,
4681,
60,
78,
60,
78,
2,
288,
298,
1421,
8,
2260,
2862,
78,
2,
288,
298,
4456,
531,
398,
347,
9158,
8,
1030,
304,
288,
291,
423,
479,
3299,
8,
355,
2097,
6071,
347,
3925,
8,
1700,
304,
401,
326,
298,
1396,
258,
870,
4681,
401,
326,
298,
1396,
3872,
326,
298,
6071,
3925,
8,
2260,
4186,
326,
298,
2260,
401,
326,
298,
6071,
4224,
3135,
398,
372,
4224,
14,
10053,
8,
8669,
9,
339,
347,
511,
2543,
10701,
8,
277,
304,
267,
4224,
275,
291,
14,
7637,
604,
3041,
14,
4921,
480,
4456,
531,
398,
291,
423,
396,
952,
8,
288,
298,
533,
8024,
3427,
78,
2,
288,
1867,
84,
318,
4681,
8,
277,
17211,
78,
2,
288,
1867,
84,
60,
683,
672,
283,
6257,
12,
6701,
1,
1154,
78
] |
[
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
388,
335,
14,
396,
14,
396,
63,
1237,
16668,
1882,
199,
3,
1898,
334,
67,
9,
12521,
13,
9488,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
2925,
367,
491,
91,
12145,
14,
388,
335,
14,
1237,
16668,
5565,
199,
624,
199,
199,
646,
5190,
199,
199,
504,
7390,
14,
14443,
492,
2882,
199,
504,
7390,
14,
4901,
492,
1125,
12,
10133,
199,
504,
7390,
14,
396,
14,
2625,
63,
7546,
492,
2624,
7836,
199,
504,
7390,
14,
388,
335,
14,
396,
14,
396,
63,
7637,
604,
492,
485,
52,
352,
846,
4256,
12,
485,
13716,
4256,
12,
485,
933,
3006,
4256,
12,
410,
3006,
12,
8635,
199,
504,
7390,
14,
388,
335,
492,
2169,
16668,
199,
504,
7390,
14,
388,
335,
14,
3617,
427,
83,
492,
5261,
427,
83,
421,
199,
318,
6705,
2698,
3481,
985,
837,
272,
408,
272,
1432,
314,
1059,
1202,
701,
2018,
465,
314,
536,
367,
1233,
2251,
1314,
787,
272,
10311,
687,
12777,
1324,
503,
737,
314,
2746,
13,
1896,
402,
4621,
14,
272,
408,
272,
862,
26,
267,
413,
1182,
378,
272,
871,
26,
267,
327,
710,
2061,
2787,
365,
642,
805,
14,
221,
710,
3499,
370,
2061,
2787,
365,
642,
267,
327,
805,
1159,
8025,
12,
1314,
365,
859,
13,
2645,
12,
1314,
365,
4052,
781,
2934,
12,
267,
327,
880,
446,
18,
14,
267,
372,
5190,
14,
5005,
63,
2340,
19105,
18,
1527,
18,
61,
199,
885,
3481,
985,
275,
6705,
2698,
3481,
985,
342,
4388,
199,
533,
4688,
16668,
2620,
26499,
2925,
8,
2796,
14,
1746,
304,
272,
408,
272,
6496,
367,
491,
91,
1237,
16668,
14,
2395,
16668,
2620,
26499,
5565,
272,
408,
272,
347,
511,
63,
3958,
3299,
8,
277,
304,
267,
408,
267,
491,
91,
2395,
16668,
2620,
26499,
14,
3958,
3299,
93,
1077,
2701,
314,
1324,
3335,
14,
267,
408,
267,
12693,
275,
2169,
16668,
14,
2395,
16668,
2620,
26499,
8,
403,
9,
267,
12693,
14,
2738,
14,
2880,
5234,
17,
401,
298,
18,
3135,
267,
12693,
14,
3958,
3299,
342,
267,
291,
14,
3334,
8,
20244,
14,
2738,
9,
4388,
199,
533,
4688,
16668,
3658,
2925,
8,
2796,
14,
1746,
304,
272,
408,
272,
6496,
367,
491,
91,
1237,
16668,
14,
2395,
16668,
5565,
272,
408,
272,
347,
511,
63,
20172,
497,
2193,
2620,
26499,
3299,
8,
277,
304,
267,
408,
267,
491,
91,
1237,
16668,
14,
2395,
16668,
14,
2479,
63,
2919,
93,
1077,
7675,
314,
12693,
1324,
3335,
267,
370,
506,
5305,
14,
267,
408,
267,
7773,
275,
2624,
7836,
342,
267,
11167,
275,
5261,
427,
83,
14,
3120,
3658,
8,
1237,
16668,
14,
2395,
16668,
9,
267,
11167,
14,
1875,
3225,
8,
5545,
9,
267,
4113,
275,
11167,
14,
12010,
3658,
267,
12693,
275,
4113,
14,
20244,
267,
12693,
14,
2738,
14,
2880,
5234,
17,
401,
298,
18,
3135,
267,
4113,
14,
2479,
63,
2919,
342,
267,
291,
14,
3334,
8,
20244,
14,
2738,
9,
4388,
199,
533,
24441,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
2674,
8,
277,
304,
267,
2169,
16668,
14,
2019,
4117,
1759,
3049,
480,
17,
531,
2378,
347,
511,
7281,
12838,
1558,
8,
277,
304,
267,
2169,
16668,
14,
2019,
4117,
1759,
3049,
14088,
17,
9008,
2378,
347,
511,
7200,
12838,
1558,
8,
277,
304,
267,
2169,
16668,
14,
2019,
4117,
1759,
3049,
15587,
17,
9859,
2378,
347,
511,
6948,
11045,
7200,
24115,
1558,
8,
277,
304,
267,
2169,
16668,
14,
2019,
4117,
1759,
3049,
480,
2344,
17,
2344,
531,
2378,
347,
511,
6948,
11045,
7281,
24115,
1558,
8,
277,
304,
267,
2169,
16668,
14,
2019,
4117,
1759,
3049,
360,
624,
17,
624,
358,
2378,
347,
511,
3481,
10701,
8,
277,
304,
267,
2169,
16668,
14,
2019,
4117,
1759,
3049,
480,
318,
3925,
837,
531,
2378,
347,
511,
2543,
10701,
8,
277,
304,
267,
2169,
16668,
14,
2019,
4117,
1759,
3049,
480,
533,
3925,
9107,
421,
199,
533,
4688,
16668,
19690,
4256,
26,
272,
1654,
3658,
275,
2169,
16668,
14,
967,
21252,
2395,
16668,
339,
347,
336,
2592,
8,
277,
12,
366,
304,
267,
372,
10133,
14,
2573,
1858,
9937,
8,
68,
9,
339,
347,
511,
3184,
9093,
8,
277,
304,
267,
4224,
275,
291,
14,
7637,
604,
3041,
14,
4921,
480,
4456,
531,
398,
291,
423,
396,
952,
8,
288,
298,
17,
435,
413,
60,
78,
2,
288,
298,
4456,
531,
398,
347,
9158,
8,
1030,
304,
288,
291,
423,
479,
3299,
8,
355,
2097,
6071,
413,
435,
413,
401,
326,
298,
18,
401,
326,
298,
6071,
4224,
3135,
398,
372,
4224,
14,
10053,
8,
8669,
9,
339,
347,
511,
6948,
11045,
12838,
3049,
24593,
4086,
8,
277,
304,
267,
4224,
275,
291,
14,
7637,
604,
3041,
14,
4921,
480,
4456,
531,
398,
291,
423,
396,
952,
8,
288,
17172,
1154,
78,
891,
1154,
78,
2,
288,
298,
4456,
531,
398,
347,
9158,
8,
1030,
304,
288,
291,
423,
479,
3299,
8,
355,
2097,
6071,
1449,
401,
326,
298,
1396,
1449,
401,
326,
3546,
1103,
78,
4662,
326,
298,
6071,
4224,
3135,
398,
372,
4224,
14,
10053,
8,
8669,
9,
339,
347,
511,
3481,
10701,
8,
277,
304,
267,
4224,
275,
291,
14,
7637,
604,
3041,
14,
4921,
480,
4456,
531,
398,
291,
423,
396,
952,
8,
288,
298,
318,
3925,
8,
1700,
17211,
78,
2,
288,
1867,
683,
672,
4681,
60,
78,
60,
78,
2,
288,
298,
1421,
8,
2260,
2862,
78,
2,
288,
298,
4456,
531,
398,
347,
9158,
8,
1030,
304,
288,
291,
423,
479,
3299,
8,
355,
2097,
6071,
347,
3925,
8,
1700,
304,
401,
326,
298,
1396,
258,
870,
4681,
401,
326,
298,
1396,
3872,
326,
298,
6071,
3925,
8,
2260,
4186,
326,
298,
2260,
401,
326,
298,
6071,
4224,
3135,
398,
372,
4224,
14,
10053,
8,
8669,
9,
339,
347,
511,
2543,
10701,
8,
277,
304,
267,
4224,
275,
291,
14,
7637,
604,
3041,
14,
4921,
480,
4456,
531,
398,
291,
423,
396,
952,
8,
288,
298,
533,
8024,
3427,
78,
2,
288,
1867,
84,
318,
4681,
8,
277,
17211,
78,
2,
288,
1867,
84,
60,
683,
672,
283,
6257,
12,
6701,
1,
1154,
78,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ravindrapanda/tensorflow
|
tensorflow/contrib/mpi_collectives/__init__.py
|
51
|
11468
|
# 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.
# ==============================================================================
# pylint: disable=g-short-docstring-punctuation
"""## Communicating Between Processes with MPI
TensorFlow natively provides inter-device communication through send and
receive ops and inter-node communication through Distributed TensorFlow, based
on the same send and receive abstractions. On HPC clusters where Infiniband or
other high-speed node interconnects are available, these can end up being
insufficient for synchronous data-parallel training (without asynchronous
gradient descent). This module implements a variety of MPI ops which can take
advantage of hardware-specific MPI libraries for efficient communication.
In order to use this module, TensorFlow must be built with an MPI library,
which can be provided to the `./configure` script at build time. As a user of
TensorFlow, you will need to build TensorFlow yourself to select the MPI
library to use; to do so, follow the [instructions for building TensorFlow from
source](https://www.tensorflow.org/get_started/os_setup#installing_from_sources).
### Utility Ops
In addition to reductions and gathers, this module provides utility operations
for detecting the running MPI configuration.
Example:
```python
import tensorflow.contrib.mpi_collectives as mpi
# Use `mpi.Session` instead of `tf.Session`
with mpi.Session() as session:
rank = session.run(mpi.rank())
print("My MPI Rank:", rank)
if rank == 0:
print("MPI Size:", session.run(mpi.size()))
```
@@init
@@size
@@rank
@@local_rank
### Ring Allreduce and Allgather
When summing or averaging tensors across many processes, communication can
easily become a bottleneck. A naive implementation will send all the tensor
values to the same process, perform the reduction, and then broadcast the
values back to all other processes, effectively creating a synchronous
parameter server in one process. However, the process responsible for
performing the reduction will have to receive and send a massive amount of data
which scales with the number of processes *and* the number of parameters in the
model.
Instead of centralizing the reduction and having one primary reducer, we can
implement a distributed allreduce or allgather. A bandwidth-optimal allreduce
will end up sending 2(N - 1) values for every value in the input tensor,
and can be implemented with a ring allreduce [1]. (Intuitively, a linear reduce
requires at least (N - 1) sends between the different nodes, and a broadcast of
the result also requires (N - 1) sends, for a total of 2 (N - 1); these two
steps cannot be combined in a clever way to reduce the number of required
sends.) This module implements bandwidth-optimal ring allreduce and ring
allgather operations using MPI; by choosing a hardware-appropriate MPI
implementation (such as OpenMPI with CUDA-IPC support), you can train large
models with synchronous gradient descent with minimal communication overhead.
In addition to the `allreduce` and `allgather` functions, a convenience
`DistributedOptimizer` wrapper is provided to simplify using these functions
for reducing model gradients.
Example:
```python
import tensorflow as tf
from tensorflow.contrib import mpi_collectives as mpi
# Construct a simple linear regression model to optimize
W = tf.get_variable("W", shape=[20, 1], dtype=tf.float32)
B = tf.get_variable("B", shape=[1, 1], dtype=tf.float32)
inputs = tf.placeholder("Inputs", shape=[None, 20])
outputs = tf.placeholder("Outputs", shape=[None, 1])
loss = tf.nn.l2_loss(tf.matmul(inputs, W) + B - outputs)
# Training using MPI allreduce with DistributedOptimizer
optimizer = mpi.DistributedOptimizer(tf.train.AdamOptimizer())
train = optimizer.minimize(loss)
# Average loss over all ranks, for printing.
# Do not pass this to an optimizer!
avg_loss = mpi.allreduce(loss)
# On different ranks, feed different input data.
with mpi.Session() as session:
rank = session.run(mpi.rank())
batch_inputs, batch_outputs = construct_batch_for_rank(rank)
feed_dict = {inputs: batch_inputs, outputs: batch_outputs}
_, l = session.run([train, avg_loss], feed_dict=feed_dict)
print("Average Loss:", l)
```
[1] Patarasuk, Pitch and Yuan, Xin. "Bandwidth Optimal All-reduce Algorithms
for Clusters of Workstations".
@@Session
@@DistributedOptimizer
@@allreduce
@@allgather
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
from tensorflow.contrib.mpi_collectives.python.ops.mpi_ops import init
from tensorflow.contrib.mpi_collectives.python.ops.mpi_ops import size
from tensorflow.contrib.mpi_collectives.python.ops.mpi_ops import rank
from tensorflow.contrib.mpi_collectives.python.ops.mpi_ops import local_rank
from tensorflow.contrib.mpi_collectives.python.ops.mpi_ops import allgather
from tensorflow.contrib.mpi_collectives.python.ops.mpi_ops import _allreduce
def allreduce(tensor, average=True):
"""Perform an MPI allreduce on a tf.Tensor or tf.IndexedSlices.
Arguments:
tensor: tf.Tensor, tf.Variable, or tf.IndexedSlices to reduce.
The shape of the input must be identical across all ranks.
average: If True, computes the average over all ranks.
Otherwise, computes the sum over all ranks.
This function performs a bandwidth-optimal ring allreduce on the input
tensor. If the input is an tf.IndexedSlices, the function instead does an
allgather on the values and the indices, effectively doing an allreduce on
the represented tensor.
"""
if isinstance(tensor, tf.IndexedSlices):
# For IndexedSlices, do two allgathers intead of an allreduce.
mpi_size = tf.cast(size(), tensor.values.dtype)
values = allgather(tensor.values)
indices = allgather(tensor.indices)
# To make this operation into an average, divide all gathered values by
# the MPI size.
new_values = tf.div(values, mpi_size) if average else values
return tf.IndexedSlices(new_values, indices,
dense_shape=tensor.dense_shape)
else:
mpi_size = tf.cast(size(), tensor.dtype)
summed_tensor = _allreduce(tensor)
new_tensor = (tf.div(summed_tensor, mpi_size)
if average else summed_tensor)
return new_tensor
class DistributedOptimizer(tf.train.Optimizer):
"""An optimizer that wraps another tf.Optimizer, using an MPI allreduce to
average gradient values before applying gradients to model weights."""
def __init__(self, optimizer, name=None, use_locking=False):
"""Construct a new DistributedOptimizer, which uses another optimizer
under the hood for computing single-process gradient values and
applying gradient updates after the gradient values have been averaged
across all the MPI ranks.
Args:
optimizer: Optimizer to use for computing gradients and applying updates.
name: Optional name prefix for the operations created when applying
gradients. Defaults to "Distributed" followed by the provided
optimizer type.
use_locking: Whether to use locking when updating variables. See
Optimizer.__init__ for more info.
"""
if name is None:
name = "Distributed{}".format(type(optimizer).__name__)
self._optimizer = optimizer
super(DistributedOptimizer, self).__init__(
name=name, use_locking=use_locking)
def compute_gradients(self, *args, **kwargs):
"""Compute gradients of all trainable variables.
See Optimizer.compute_gradients() for more info.
In DistributedOptimizer, compute_gradients() is overridden to also
allreduce the gradients before returning them.
"""
gradients = (super(DistributedOptimizer, self)
.compute_gradients(*args, **kwargs))
return [(allreduce(gradient), var) for (gradient, var) in gradients]
def _apply_dense(self, *args, **kwargs):
"""Calls this same method on the underlying optimizer."""
return self._optimizer._apply_dense(*args, **kwargs)
def _apply_sparse(self, *args, **kwargs):
"""Calls this same method on the underlying optimizer."""
return self._optimizer._apply_sparse(*args, **kwargs)
def _apply_sparse_duplicate_indices(self, *args, **kwargs):
"""Calls this same method on the underlying optimizer."""
return self._optimizer._apply_sparse_duplicate_indices(*args,
**kwargs)
def _prepare(self, *args, **kwargs):
"""Calls this same method on the underlying optimizer."""
return self._optimizer._prepare(*args, **kwargs)
def _create_slots(self, *args, **kwargs):
"""Calls this same method on the underlying optimizer."""
return self._optimizer._create_slots(*args, **kwargs)
def _valid_dtypes(self, *args, **kwargs):
"""Calls this same method on the underlying optimizer."""
return self._optimizer._valid_dtypes(*args, **kwargs)
def _finish(self, *args, **kwargs):
"""Calls this same method on the underlying optimizer."""
return self._optimizer._finish(*args, **kwargs)
class Session(tf.Session):
"""A class for running TensorFlow operations, with copies of the same graph
running distributed across different MPI nodes.
The primary difference between `tf.Session` and
`tf.contrib.mpi_collectives.Session` is that the MPI `Session` ensures that
the `Session` options are correct for use with `tf.contrib.mpi`, and
initializes MPI immediately upon the start of the session.
"""
def __init__(self, target='', graph=None, config=None):
"""Creates a new TensorFlow MPI session.
Unlike a normal `tf.Session`, an MPI Session may only use a single GPU,
which must be specified in advance before the session is initialized.
In addition, it only uses a single graph evaluation thread, and
initializes MPI immediately upon starting.
If no `graph` argument is specified when constructing the session,
the default graph will be launched in the session. If you are
using more than one graph (created with `tf.Graph()` in the same
process, you will have to use different sessions for each graph,
but each graph can be used in multiple sessions. In this case, it
is often clearer to pass the graph to be launched explicitly to
the session constructor.
Args:
target: (Optional.) The execution engine to connect to.
graph: (Optional.) The `Graph` to be launched (described above).
config: (Optional.) A `ConfigProto` protocol buffer with configuration
options for the session.
"""
super(Session, self).__init__(target, graph, config=config)
# Initialize MPI on the relevant device.
# TODO: Move this to library load and eliminate mpi.Session()
if graph is None:
graph = tf.get_default_graph()
with graph.as_default():
self.run(init())
|
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,
3,
4287,
26,
3507,
29,
71,
13,
3612,
13,
12485,
13,
25181,
199,
624,
309,
13338,
1958,
31535,
3109,
2165,
5804,
543,
26024,
199,
199,
26998,
302,
17330,
6571,
1640,
13,
1782,
23506,
4012,
3222,
436,
199,
9391,
4156,
436,
1640,
13,
932,
23506,
4012,
17484,
9134,
12,
4079,
199,
265,
314,
2011,
3222,
436,
9128,
2236,
14183,
2452,
14,
4068,
869,
4222,
13865,
2382,
1010,
2408,
1892,
460,
503,
199,
1848,
4721,
13,
7625,
1031,
1640,
2242,
83,
787,
2808,
12,
3520,
883,
1284,
1536,
3769,
199,
3617,
12983,
367,
24248,
666,
13,
11887,
6093,
334,
7395,
15608,
199,
7490,
31518,
680,
961,
859,
9031,
282,
32246,
402,
26024,
4156,
1314,
883,
5452,
199,
21650,
25331,
402,
14991,
13,
6100,
26024,
8363,
367,
13402,
23506,
14,
199,
199,
607,
1865,
370,
675,
642,
859,
12,
9134,
1471,
506,
6137,
543,
376,
26024,
3555,
12,
199,
6777,
883,
506,
2741,
370,
314,
658,
13186,
6472,
64,
2884,
737,
1900,
900,
14,
3709,
282,
922,
402,
199,
26998,
12,
1265,
911,
1929,
370,
1900,
9134,
28225,
370,
3504,
314,
26024,
199,
4342,
370,
675,
27,
370,
886,
880,
12,
2035,
314,
359,
20718,
367,
10015,
9134,
687,
199,
1365,
8738,
2859,
921,
1544,
14,
16008,
14,
1308,
15,
362,
63,
8924,
15,
736,
63,
2758,
3,
3174,
316,
63,
504,
63,
4553,
680,
199,
199,
5680,
20511,
593,
1190,
199,
199,
607,
10234,
370,
295,
18311,
436,
13082,
83,
12,
642,
859,
6571,
11420,
5331,
199,
509,
9696,
316,
314,
3879,
26024,
2897,
14,
199,
199,
9846,
26,
199,
199,
32323,
1548,
199,
646,
3228,
14,
2828,
14,
13213,
63,
761,
10251,
7301,
465,
26806,
199,
199,
3,
3645,
658,
13213,
14,
4434,
64,
3140,
402,
658,
3249,
14,
4434,
64,
199,
1045,
26806,
14,
4434,
342,
465,
2351,
26,
272,
6915,
275,
2351,
14,
1065,
8,
13213,
14,
4648,
1012,
272,
870,
480,
5713,
26024,
31536,
6783,
6915,
9,
339,
340,
6915,
508,
378,
26,
267,
870,
480,
28983,
14579,
6783,
2351,
14,
1065,
8,
13213,
14,
890,
4059,
199,
32323,
199,
199,
7492,
826,
199,
7492,
890,
199,
7492,
4648,
199,
7492,
1832,
63,
4648,
199,
199,
5680,
820,
316,
2900,
5270,
436,
2900,
13737,
199,
199,
11423,
3089,
14566,
503,
282,
422,
7407,
10519,
9371,
5002,
10358,
12,
23506,
883,
199,
69,
305,
3444,
8649,
282,
5888,
27412,
14,
437,
19995,
4514,
911,
3222,
1006,
314,
2345,
199,
1459,
370,
314,
2011,
2112,
12,
5147,
314,
16773,
12,
436,
2066,
11180,
314,
199,
1459,
1771,
370,
1006,
1163,
10358,
12,
27881,
6425,
282,
24248,
199,
5329,
1654,
315,
1373,
2112,
14,
9738,
12,
314,
2112,
17845,
367,
199,
15795,
316,
314,
16773,
911,
1172,
370,
9128,
436,
3222,
282,
333,
13202,
5982,
402,
666,
199,
6777,
29823,
543,
314,
1329,
402,
10358,
627,
460,
10,
314,
1329,
402,
2633,
315,
314,
199,
1238,
14,
199,
199,
13962,
13558,
402,
18796,
9147,
314,
16773,
436,
9445,
1373,
5062,
295,
7610,
12,
781,
883,
199,
21463,
282,
1854,
1006,
5270,
503,
1006,
13737,
14,
437,
20434,
13,
411,
16757,
1006,
5270,
199,
14117,
1284,
1536,
10209,
499,
8,
46,
446,
413,
9,
1338,
367,
4036,
574,
315,
314,
1324,
2345,
12,
199,
460,
883,
506,
6366,
543,
282,
12133,
1006,
5270,
359,
17,
1055,
334,
3241,
1907,
9462,
12,
282,
7798,
7114,
199,
6537,
737,
5210,
334,
46,
446,
413,
9,
16178,
3382,
314,
3365,
3380,
12,
436,
282,
11180,
402,
199,
1589,
754,
2597,
5074,
334,
46,
446,
413,
9,
16178,
12,
367,
282,
3141,
402,
499,
334,
46,
446,
413,
2736,
3520,
2877,
199,
5895,
3913,
506,
12149,
315,
282,
15158,
422,
4340,
370,
7114,
314,
1329,
402,
1415,
199,
2464,
795,
4959,
961,
859,
9031,
20434,
13,
411,
16757,
12133,
1006,
5270,
436,
12133,
199,
452,
13737,
5331,
1808,
26024,
27,
701,
2468,
26056,
282,
14991,
13,
11227,
5655,
26024,
199,
12236,
334,
10180,
465,
3232,
28983,
543,
445,
3383,
33,
13,
31472,
2291,
395,
1265,
883,
3560,
7031,
199,
992,
543,
24248,
6709,
31518,
543,
13460,
23506,
24075,
14,
199,
199,
607,
10234,
370,
314,
658,
452,
5270,
64,
436,
658,
452,
13737,
64,
3423,
12,
282,
16777,
199,
64,
27398,
13946,
64,
4975,
365,
2741,
370,
15037,
1808,
3520,
3423,
199,
509,
295,
14713,
1402,
12661,
14,
199,
199,
9846,
26,
199,
199,
32323,
1548,
199,
646,
3228,
465,
2833,
199,
504,
3228,
14,
2828,
492,
26806,
63,
761,
10251,
7301,
465,
26806,
199,
199,
3,
9215,
282,
3486,
7798,
10864,
1402,
370,
13497,
199,
55,
275,
2833,
14,
362,
63,
1975,
480,
55,
401,
2215,
1524,
1165,
12,
413,
467,
2152,
29,
3249,
14,
1609,
708,
9,
199,
34,
275,
2833,
14,
362,
63,
1975,
480,
34,
401,
2215,
1524,
17,
12,
413,
467,
2152,
29,
3249,
14,
1609,
708,
9,
199,
3711,
275,
2833,
14,
6199,
480,
15124,
401,
2215,
1524,
403,
12,
3388,
566,
199,
4467,
275,
2833,
14,
6199,
480,
18669,
401,
2215,
1524,
403,
12,
413,
566,
199,
4358,
275,
2833,
14,
4411,
14,
76,
18,
63,
4358,
8,
3249,
14,
14465,
8,
3711,
12,
644,
9,
435,
699,
446,
4704,
9,
199,
199,
3,
22859,
1808,
26024,
1006,
5270,
543,
17484,
13946,
199,
12290,
275,
26806,
14,
27398,
13946,
8,
3249,
14,
2834,
14,
32408,
13946,
1012
] |
[
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,
3,
4287,
26,
3507,
29,
71,
13,
3612,
13,
12485,
13,
25181,
199,
624,
309,
13338,
1958,
31535,
3109,
2165,
5804,
543,
26024,
199,
199,
26998,
302,
17330,
6571,
1640,
13,
1782,
23506,
4012,
3222,
436,
199,
9391,
4156,
436,
1640,
13,
932,
23506,
4012,
17484,
9134,
12,
4079,
199,
265,
314,
2011,
3222,
436,
9128,
2236,
14183,
2452,
14,
4068,
869,
4222,
13865,
2382,
1010,
2408,
1892,
460,
503,
199,
1848,
4721,
13,
7625,
1031,
1640,
2242,
83,
787,
2808,
12,
3520,
883,
1284,
1536,
3769,
199,
3617,
12983,
367,
24248,
666,
13,
11887,
6093,
334,
7395,
15608,
199,
7490,
31518,
680,
961,
859,
9031,
282,
32246,
402,
26024,
4156,
1314,
883,
5452,
199,
21650,
25331,
402,
14991,
13,
6100,
26024,
8363,
367,
13402,
23506,
14,
199,
199,
607,
1865,
370,
675,
642,
859,
12,
9134,
1471,
506,
6137,
543,
376,
26024,
3555,
12,
199,
6777,
883,
506,
2741,
370,
314,
658,
13186,
6472,
64,
2884,
737,
1900,
900,
14,
3709,
282,
922,
402,
199,
26998,
12,
1265,
911,
1929,
370,
1900,
9134,
28225,
370,
3504,
314,
26024,
199,
4342,
370,
675,
27,
370,
886,
880,
12,
2035,
314,
359,
20718,
367,
10015,
9134,
687,
199,
1365,
8738,
2859,
921,
1544,
14,
16008,
14,
1308,
15,
362,
63,
8924,
15,
736,
63,
2758,
3,
3174,
316,
63,
504,
63,
4553,
680,
199,
199,
5680,
20511,
593,
1190,
199,
199,
607,
10234,
370,
295,
18311,
436,
13082,
83,
12,
642,
859,
6571,
11420,
5331,
199,
509,
9696,
316,
314,
3879,
26024,
2897,
14,
199,
199,
9846,
26,
199,
199,
32323,
1548,
199,
646,
3228,
14,
2828,
14,
13213,
63,
761,
10251,
7301,
465,
26806,
199,
199,
3,
3645,
658,
13213,
14,
4434,
64,
3140,
402,
658,
3249,
14,
4434,
64,
199,
1045,
26806,
14,
4434,
342,
465,
2351,
26,
272,
6915,
275,
2351,
14,
1065,
8,
13213,
14,
4648,
1012,
272,
870,
480,
5713,
26024,
31536,
6783,
6915,
9,
339,
340,
6915,
508,
378,
26,
267,
870,
480,
28983,
14579,
6783,
2351,
14,
1065,
8,
13213,
14,
890,
4059,
199,
32323,
199,
199,
7492,
826,
199,
7492,
890,
199,
7492,
4648,
199,
7492,
1832,
63,
4648,
199,
199,
5680,
820,
316,
2900,
5270,
436,
2900,
13737,
199,
199,
11423,
3089,
14566,
503,
282,
422,
7407,
10519,
9371,
5002,
10358,
12,
23506,
883,
199,
69,
305,
3444,
8649,
282,
5888,
27412,
14,
437,
19995,
4514,
911,
3222,
1006,
314,
2345,
199,
1459,
370,
314,
2011,
2112,
12,
5147,
314,
16773,
12,
436,
2066,
11180,
314,
199,
1459,
1771,
370,
1006,
1163,
10358,
12,
27881,
6425,
282,
24248,
199,
5329,
1654,
315,
1373,
2112,
14,
9738,
12,
314,
2112,
17845,
367,
199,
15795,
316,
314,
16773,
911,
1172,
370,
9128,
436,
3222,
282,
333,
13202,
5982,
402,
666,
199,
6777,
29823,
543,
314,
1329,
402,
10358,
627,
460,
10,
314,
1329,
402,
2633,
315,
314,
199,
1238,
14,
199,
199,
13962,
13558,
402,
18796,
9147,
314,
16773,
436,
9445,
1373,
5062,
295,
7610,
12,
781,
883,
199,
21463,
282,
1854,
1006,
5270,
503,
1006,
13737,
14,
437,
20434,
13,
411,
16757,
1006,
5270,
199,
14117,
1284,
1536,
10209,
499,
8,
46,
446,
413,
9,
1338,
367,
4036,
574,
315,
314,
1324,
2345,
12,
199,
460,
883,
506,
6366,
543,
282,
12133,
1006,
5270,
359,
17,
1055,
334,
3241,
1907,
9462,
12,
282,
7798,
7114,
199,
6537,
737,
5210,
334,
46,
446,
413,
9,
16178,
3382,
314,
3365,
3380,
12,
436,
282,
11180,
402,
199,
1589,
754,
2597,
5074,
334,
46,
446,
413,
9,
16178,
12,
367,
282,
3141,
402,
499,
334,
46,
446,
413,
2736,
3520,
2877,
199,
5895,
3913,
506,
12149,
315,
282,
15158,
422,
4340,
370,
7114,
314,
1329,
402,
1415,
199,
2464,
795,
4959,
961,
859,
9031,
20434,
13,
411,
16757,
12133,
1006,
5270,
436,
12133,
199,
452,
13737,
5331,
1808,
26024,
27,
701,
2468,
26056,
282,
14991,
13,
11227,
5655,
26024,
199,
12236,
334,
10180,
465,
3232,
28983,
543,
445,
3383,
33,
13,
31472,
2291,
395,
1265,
883,
3560,
7031,
199,
992,
543,
24248,
6709,
31518,
543,
13460,
23506,
24075,
14,
199,
199,
607,
10234,
370,
314,
658,
452,
5270,
64,
436,
658,
452,
13737,
64,
3423,
12,
282,
16777,
199,
64,
27398,
13946,
64,
4975,
365,
2741,
370,
15037,
1808,
3520,
3423,
199,
509,
295,
14713,
1402,
12661,
14,
199,
199,
9846,
26,
199,
199,
32323,
1548,
199,
646,
3228,
465,
2833,
199,
504,
3228,
14,
2828,
492,
26806,
63,
761,
10251,
7301,
465,
26806,
199,
199,
3,
9215,
282,
3486,
7798,
10864,
1402,
370,
13497,
199,
55,
275,
2833,
14,
362,
63,
1975,
480,
55,
401,
2215,
1524,
1165,
12,
413,
467,
2152,
29,
3249,
14,
1609,
708,
9,
199,
34,
275,
2833,
14,
362,
63,
1975,
480,
34,
401,
2215,
1524,
17,
12,
413,
467,
2152,
29,
3249,
14,
1609,
708,
9,
199,
3711,
275,
2833,
14,
6199,
480,
15124,
401,
2215,
1524,
403,
12,
3388,
566,
199,
4467,
275,
2833,
14,
6199,
480,
18669,
401,
2215,
1524,
403,
12,
413,
566,
199,
4358,
275,
2833,
14,
4411,
14,
76,
18,
63,
4358,
8,
3249,
14,
14465,
8,
3711,
12,
644,
9,
435,
699,
446,
4704,
9,
199,
199,
3,
22859,
1808,
26024,
1006,
5270,
543,
17484,
13946,
199,
12290,
275,
26806,
14,
27398,
13946,
8,
3249,
14,
2834,
14,
32408,
13946,
1012,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
LACNIC/simon
|
simon-web/simon_app/templatetags/simon_extras.py
|
1
|
2401
|
from django import template
from datetime import datetime
from simon_app.functions import GMTUY
import operator
"""
Module that holds the Simon
"""
register = template.Library()
@register.filter(name="substract")
def substract(value, arg):
"""
Substract
"""
return value - arg
@register.filter(name="divide")
def divide(value, arg):
"""
Float division
"""
return float(value) / float(arg)
@register.filter(name="percentage")
def percentage(value, arg):
"""
Percentage
"""
return 100.0 * divide(value, arg)
@register.filter(name="unit_shortener")
def unit_shortener(value):
"""
Unit converter
"""
try:
int(value)
float(value)
except:
return "N/A"
K = 1000
M = K * K
G = K * M
T = K * G
if value > T:
return "%.1f %s" % (1.0 * value / T, 'T')
if value > G:
return "%.1f %s" % (1.0 * value / G, 'G')
if value > M:
return "%.1f %s" % (1.0 * value / M, 'M')
if value > K:
return "%.1f %s" % (1.0 * value / K, 'K')
return value
@register.filter(name="time_since")
def time_since(value):
"""
:param now:
:return:
"""
td = datetime.now(GMTUY()) - value
print td
if td.days > 1:
return "mas de un dia"
elif td.seconds > 3600:
mins = "%.0f minutos" % ((td.seconds % 3600) / 60)
horas = "%.0f %s" % (td.seconds / 3600, "horas" if td.seconds / 3600 > 1 else "hora")
return "%s %s" % (horas, mins)
elif td.seconds > 60:
return "%.0f minutos" % (td.seconds / 60)
else:
return "%.0f segundos" % td.seconds
@register.filter(name="max")
def max_(value, arg):
"""
:param value:
:param arg:
:return:
"""
if arg == 'v6_rate':
return str(max([v.v6_rate for v in value]))
return "%s %s" % (value, arg)
@register.filter(name="get_by_attribute")
def get_by_attribute(objects, raw_args):
print raw_args
key, value = raw_args.split(' ')
print key, value
func = operator.attrgetter(key)
for o in objects:
if func(o) == value:
return o
class Object():
pass
a = Object()
setattr(a, key, 0)
return a
@register.filter(name="get_attribute")
def get_attribute(object, attr):
func = operator.attrgetter(attr)
return func(object)
|
gpl-2.0
|
[
504,
1639,
492,
1978,
199,
504,
2197,
492,
2197,
199,
504,
4389,
265,
63,
571,
14,
5777,
492,
19152,
53,
57,
199,
646,
4182,
199,
199,
624,
272,
5673,
626,
15164,
314,
10751,
265,
199,
624,
199,
199,
2683,
275,
1978,
14,
7424,
342,
421,
199,
32,
2683,
14,
1541,
8,
354,
628,
954,
3525,
531,
199,
318,
1007,
3525,
8,
585,
12,
1680,
304,
272,
408,
267,
4804,
3525,
272,
408,
272,
372,
574,
446,
1680,
421,
199,
32,
2683,
14,
1541,
8,
354,
628,
16081,
531,
199,
318,
23003,
8,
585,
12,
1680,
304,
272,
408,
267,
11140,
4629,
272,
408,
272,
372,
2069,
8,
585,
9,
1182,
2069,
8,
1273,
9,
421,
199,
32,
2683,
14,
1541,
8,
354,
628,
14200,
531,
199,
318,
16327,
8,
585,
12,
1680,
304,
272,
408,
267,
3492,
2946,
474,
272,
408,
272,
372,
2948,
14,
16,
627,
23003,
8,
585,
12,
1680,
9,
421,
199,
32,
2683,
14,
1541,
8,
354,
628,
3248,
63,
30686,
281,
531,
199,
318,
4137,
63,
30686,
281,
8,
585,
304,
272,
408,
267,
12008,
11109,
272,
408,
339,
862,
26,
267,
1109,
8,
585,
9,
267,
2069,
8,
585,
9,
272,
871,
26,
267,
372,
298,
46,
15,
33,
2,
339,
1804,
275,
5198,
272,
603,
275,
1804,
627,
1804,
272,
598,
275,
1804,
627,
603,
272,
377,
275,
1804,
627,
598,
339,
340,
574,
690,
377,
26,
267,
372,
31681,
17,
70,
450,
83,
2,
450,
334,
17,
14,
16,
627,
574,
1182,
377,
12,
283,
52,
358,
272,
340,
574,
690,
598,
26,
267,
372,
31681,
17,
70,
450,
83,
2,
450,
334,
17,
14,
16,
627,
574,
1182,
598,
12,
283,
39,
358,
272,
340,
574,
690,
603,
26,
267,
372,
31681,
17,
70,
450,
83,
2,
450,
334,
17,
14,
16,
627,
574,
1182,
603,
12,
283,
45,
358,
272,
340,
574,
690,
1804,
26,
267,
372,
31681,
17,
70,
450,
83,
2,
450,
334,
17,
14,
16,
627,
574,
1182,
1804,
12,
283,
43,
358,
272,
372,
574,
421,
199,
32,
2683,
14,
1541,
8,
354,
628,
521,
63,
8585,
531,
199,
318,
900,
63,
8585,
8,
585,
304,
272,
408,
272,
520,
635,
3063,
26,
272,
520,
1107,
26,
272,
408,
272,
12749,
275,
2197,
14,
2131,
8,
17274,
53,
57,
1012,
446,
574,
339,
870,
12749,
339,
340,
12749,
14,
4899,
690,
413,
26,
267,
372,
298,
5892,
477,
625,
487,
65,
2,
272,
916,
12749,
14,
4515,
690,
15751,
26,
267,
1748,
83,
275,
31681,
16,
70,
1748,
337,
736,
2,
450,
3666,
2076,
14,
4515,
450,
15751,
9,
1182,
5212,
9,
267,
394,
269,
305,
275,
31681,
16,
70,
450,
83,
2,
450,
334,
2076,
14,
4515,
1182,
15751,
12,
298,
23991,
305,
2,
340,
12749,
14,
4515,
1182,
15751,
690,
413,
587,
298,
72,
11131,
531,
267,
372,
2071,
83,
450,
83,
2,
450,
334,
23991,
305,
12,
1748,
83,
9,
272,
916,
12749,
14,
4515,
690,
5212,
26,
267,
372,
31681,
16,
70,
1748,
337,
736,
2,
450,
334,
2076,
14,
4515,
1182,
5212,
9,
272,
587,
26,
267,
372,
31681,
16,
70,
8812,
725,
736,
2,
450,
12749,
14,
4515,
421,
199,
32,
2683,
14,
1541,
8,
354,
628,
988,
531,
199,
318,
1390,
2531,
585,
12,
1680,
304,
272,
408,
272,
520,
635,
574,
26,
272,
520,
635,
1680,
26,
272,
520,
1107,
26,
272,
408,
272,
340,
1680,
508,
283,
86,
22,
63,
1866,
356,
267,
372,
620,
8,
988,
779,
86,
14,
86,
22,
63,
1866,
367,
373,
315,
574,
2459,
272,
372,
2071,
83,
450,
83,
2,
450,
334,
585,
12,
1680,
9,
421,
199,
32,
2683,
14,
1541,
8,
354,
628,
362,
63,
991,
63,
3215,
531,
199,
318,
664,
63,
991,
63,
3215,
8,
1462,
12,
3066,
63,
589,
304,
339,
870,
3066,
63,
589,
339,
790,
12,
574,
275,
3066,
63,
589,
14,
1294,
360,
5320,
339,
870,
790,
12,
574,
339,
2562,
275,
4182,
14,
18600,
8,
498,
9,
339,
367,
312,
315,
2251,
26,
267,
340,
2562,
8,
79,
9,
508,
574,
26,
288,
372,
312,
339,
1021,
6935,
837,
267,
986,
339,
282,
275,
6935,
342,
272,
5371,
8,
65,
12,
790,
12,
378,
9,
272,
372,
282,
421,
199,
32,
2683,
14,
1541,
8,
354,
628,
362,
63,
3215,
531,
199,
318,
664,
63,
3215,
8,
785,
12,
1921,
304,
272,
2562,
275,
4182,
14,
18600,
8,
962,
9,
272,
372,
2562,
8,
785,
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
] |
[
1639,
492,
1978,
199,
504,
2197,
492,
2197,
199,
504,
4389,
265,
63,
571,
14,
5777,
492,
19152,
53,
57,
199,
646,
4182,
199,
199,
624,
272,
5673,
626,
15164,
314,
10751,
265,
199,
624,
199,
199,
2683,
275,
1978,
14,
7424,
342,
421,
199,
32,
2683,
14,
1541,
8,
354,
628,
954,
3525,
531,
199,
318,
1007,
3525,
8,
585,
12,
1680,
304,
272,
408,
267,
4804,
3525,
272,
408,
272,
372,
574,
446,
1680,
421,
199,
32,
2683,
14,
1541,
8,
354,
628,
16081,
531,
199,
318,
23003,
8,
585,
12,
1680,
304,
272,
408,
267,
11140,
4629,
272,
408,
272,
372,
2069,
8,
585,
9,
1182,
2069,
8,
1273,
9,
421,
199,
32,
2683,
14,
1541,
8,
354,
628,
14200,
531,
199,
318,
16327,
8,
585,
12,
1680,
304,
272,
408,
267,
3492,
2946,
474,
272,
408,
272,
372,
2948,
14,
16,
627,
23003,
8,
585,
12,
1680,
9,
421,
199,
32,
2683,
14,
1541,
8,
354,
628,
3248,
63,
30686,
281,
531,
199,
318,
4137,
63,
30686,
281,
8,
585,
304,
272,
408,
267,
12008,
11109,
272,
408,
339,
862,
26,
267,
1109,
8,
585,
9,
267,
2069,
8,
585,
9,
272,
871,
26,
267,
372,
298,
46,
15,
33,
2,
339,
1804,
275,
5198,
272,
603,
275,
1804,
627,
1804,
272,
598,
275,
1804,
627,
603,
272,
377,
275,
1804,
627,
598,
339,
340,
574,
690,
377,
26,
267,
372,
31681,
17,
70,
450,
83,
2,
450,
334,
17,
14,
16,
627,
574,
1182,
377,
12,
283,
52,
358,
272,
340,
574,
690,
598,
26,
267,
372,
31681,
17,
70,
450,
83,
2,
450,
334,
17,
14,
16,
627,
574,
1182,
598,
12,
283,
39,
358,
272,
340,
574,
690,
603,
26,
267,
372,
31681,
17,
70,
450,
83,
2,
450,
334,
17,
14,
16,
627,
574,
1182,
603,
12,
283,
45,
358,
272,
340,
574,
690,
1804,
26,
267,
372,
31681,
17,
70,
450,
83,
2,
450,
334,
17,
14,
16,
627,
574,
1182,
1804,
12,
283,
43,
358,
272,
372,
574,
421,
199,
32,
2683,
14,
1541,
8,
354,
628,
521,
63,
8585,
531,
199,
318,
900,
63,
8585,
8,
585,
304,
272,
408,
272,
520,
635,
3063,
26,
272,
520,
1107,
26,
272,
408,
272,
12749,
275,
2197,
14,
2131,
8,
17274,
53,
57,
1012,
446,
574,
339,
870,
12749,
339,
340,
12749,
14,
4899,
690,
413,
26,
267,
372,
298,
5892,
477,
625,
487,
65,
2,
272,
916,
12749,
14,
4515,
690,
15751,
26,
267,
1748,
83,
275,
31681,
16,
70,
1748,
337,
736,
2,
450,
3666,
2076,
14,
4515,
450,
15751,
9,
1182,
5212,
9,
267,
394,
269,
305,
275,
31681,
16,
70,
450,
83,
2,
450,
334,
2076,
14,
4515,
1182,
15751,
12,
298,
23991,
305,
2,
340,
12749,
14,
4515,
1182,
15751,
690,
413,
587,
298,
72,
11131,
531,
267,
372,
2071,
83,
450,
83,
2,
450,
334,
23991,
305,
12,
1748,
83,
9,
272,
916,
12749,
14,
4515,
690,
5212,
26,
267,
372,
31681,
16,
70,
1748,
337,
736,
2,
450,
334,
2076,
14,
4515,
1182,
5212,
9,
272,
587,
26,
267,
372,
31681,
16,
70,
8812,
725,
736,
2,
450,
12749,
14,
4515,
421,
199,
32,
2683,
14,
1541,
8,
354,
628,
988,
531,
199,
318,
1390,
2531,
585,
12,
1680,
304,
272,
408,
272,
520,
635,
574,
26,
272,
520,
635,
1680,
26,
272,
520,
1107,
26,
272,
408,
272,
340,
1680,
508,
283,
86,
22,
63,
1866,
356,
267,
372,
620,
8,
988,
779,
86,
14,
86,
22,
63,
1866,
367,
373,
315,
574,
2459,
272,
372,
2071,
83,
450,
83,
2,
450,
334,
585,
12,
1680,
9,
421,
199,
32,
2683,
14,
1541,
8,
354,
628,
362,
63,
991,
63,
3215,
531,
199,
318,
664,
63,
991,
63,
3215,
8,
1462,
12,
3066,
63,
589,
304,
339,
870,
3066,
63,
589,
339,
790,
12,
574,
275,
3066,
63,
589,
14,
1294,
360,
5320,
339,
870,
790,
12,
574,
339,
2562,
275,
4182,
14,
18600,
8,
498,
9,
339,
367,
312,
315,
2251,
26,
267,
340,
2562,
8,
79,
9,
508,
574,
26,
288,
372,
312,
339,
1021,
6935,
837,
267,
986,
339,
282,
275,
6935,
342,
272,
5371,
8,
65,
12,
790,
12,
378,
9,
272,
372,
282,
421,
199,
32,
2683,
14,
1541,
8,
354,
628,
362,
63,
3215,
531,
199,
318,
664,
63,
3215,
8,
785,
12,
1921,
304,
272,
2562,
275,
4182,
14,
18600,
8,
962,
9,
272,
372,
2562,
8,
785,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
indictranstech/focal-erpnext
|
stock/get_item_details.py
|
4
|
12465
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe import _, throw
from frappe.utils import flt, cint, add_days
import json
from erpnext.accounts.doctype.pricing_rule.pricing_rule import get_pricing_rule_for_item
from erpnext.setup.utils import get_exchange_rate
@frappe.whitelist()
def get_item_details(args):
"""
args = {
"item_code": "",
"warehouse": None,
"customer": "",
"conversion_rate": 1.0,
"selling_price_list": None,
"price_list_currency": None,
"plc_conversion_rate": 1.0,
"parenttype": "",
"parent": "",
"supplier": None,
"transaction_date": None,
"conversion_rate": 1.0,
"buying_price_list": None,
"is_subcontracted": "Yes" / "No",
"transaction_type": "selling",
"ignore_pricing_rule": 0/1
"project_name": "",
}
"""
args = process_args(args)
item_doc = frappe.get_doc("Item", args.item_code)
item = item_doc
validate_item_details(args, item)
out = get_basic_details(args, item_doc)
get_party_item_code(args, item_doc, out)
if out.get("warehouse"):
out.update(get_available_qty(args.item_code, out.warehouse))
out.update(get_projected_qty(item.name, out.warehouse))
get_price_list_rate(args, item_doc, out)
if args.transaction_type == "selling" and cint(args.is_pos):
out.update(get_pos_settings_item_details(args.company, args))
# update args with out, if key or value not exists
for key, value in out.iteritems():
if args.get(key) is None:
args[key] = value
out.update(get_pricing_rule_for_item(args))
if args.get("parenttype") in ("Sales Invoice", "Delivery Note"):
if item_doc.has_serial_no == "Yes" and not args.serial_no:
out.serial_no = get_serial_nos_by_fifo(args, item_doc)
if args.transaction_date and item.lead_time_days:
out.schedule_date = out.lead_time_date = add_days(args.transaction_date,
item.lead_time_days)
# frappe.errprint(out)
return out
def process_args(args):
if isinstance(args, basestring):
args = json.loads(args)
args = frappe._dict(args)
if not args.get("transaction_type"):
if args.get("parenttype")=="Material Request" or \
frappe.get_meta(args.get("parenttype")).get_field("supplier"):
args.transaction_type = "buying"
else:
args.transaction_type = "selling"
if not args.get("price_list"):
args.price_list = args.get("selling_price_list") or args.get("buying_price_list")
if args.barcode:
args.item_code = get_item_code(barcode=args.barcode)
elif not args.item_code and args.serial_no:
args.item_code = get_item_code(serial_no=args.serial_no)
return args
def get_item_code(barcode=None, serial_no=None):
if barcode:
item_code = frappe.db.get_value("Item", {"barcode": barcode})
if not item_code:
frappe.throw(_("No Item with Barcode {0}").format(barcode))
elif serial_no:
item_code = frappe.db.get_value("Serial No", serial_no, "item_code")
if not item_code:
frappe.throw(_("No Item with Serial No {0}").format(serial_no))
return item_code
def validate_item_details(args, item):
if not args.company:
throw(_("Please specify Company"))
from erpnext.stock.doctype.item.item import validate_end_of_life
validate_end_of_life(item.name, item.end_of_life)
if args.transaction_type == "selling":
# validate if sales item or service item
if args.get("order_type") == "Maintenance":
if item.is_service_item != "Yes":
throw(_("Item {0} must be a Service Item.").format(item.name))
elif item.is_sales_item != "Yes":
throw(_("Item {0} must be a Sales Item").format(item.name))
elif args.transaction_type == "buying" and args.parenttype != "Material Request":
# validate if purchase item or subcontracted item
if item.is_purchase_item != "Yes":
throw(_("Item {0} must be a Purchase Item").format(item.name))
if args.get("is_subcontracted") == "Yes" and item.is_sub_contracted_item != "Yes":
throw(_("Item {0} must be a Sub-contracted Item").format(item.name))
def get_basic_details(args, item_doc):
item = item_doc
from frappe.defaults import get_user_default_as_list
user_default_warehouse_list = get_user_default_as_list('warehouse')
user_default_warehouse = user_default_warehouse_list[0] \
if len(user_default_warehouse_list)==1 else ""
out = frappe._dict({
"item_code": item.name,
"item_name": item.item_name,
"description": item.description_html or item.description,
"warehouse": user_default_warehouse or args.warehouse or item.default_warehouse,
"part_number":item.part_number,
"income_account": (item.income_account
or args.income_account
or frappe.db.get_value("Item Group", item.item_group, "default_income_account")
or frappe.db.get_value("Company", args.company, "default_income_account")),
"expense_account": (item.expense_account
or args.expense_account
or frappe.db.get_value("Item Group", item.item_group, "default_expense_account")
or frappe.db.get_value("Company", args.company, "default_expense_account")),
"cost_center": (frappe.db.get_value("Project", args.project_name, "cost_center")
or (item.selling_cost_center if args.transaction_type == "selling" else item.buying_cost_center)
or frappe.db.get_value("Item Group", item.item_group, "default_cost_center")
or frappe.db.get_value("Company", args.company, "cost_center")),
"batch_no": None,
"item_tax_rate": json.dumps(dict(([d.tax_type, d.tax_rate] for d in
item_doc.get("item_tax")))),
"uom": item.stock_uom,
"min_order_qty": flt(item.min_order_qty) if args.parenttype == "Material Request" else "",
"conversion_factor": 1.0,
"qty": 1.0,
"stock_qty": 1.0,
"price_list_rate": 0.0,
"base_price_list_rate": 0.0,
"rate": 0.0,
"base_rate": 0.0,
"amount": 0.0,
"base_amount": 0.0,
"discount_percentage": 0.0
})
if args.doctype=='Sales Order Item':
out['qty']=args.get('qty') or 0.0 #Rohit
for fieldname in ("item_name", "item_group", "barcode", "brand", "stock_uom"):
out[fieldname] = item.get(fieldname)
return out
def get_price_list_rate(args, item_doc, out):
meta = frappe.get_meta(args.parenttype)
if meta.get_field("currency"):
validate_price_list(args)
validate_conversion_rate(args, meta)
if args.doctype=='Sales Order Item' and args.qty_label: # Rohit
from erpnext.selling.custom_methods import get_so_price_list
so_rate=get_so_price_list(args, item_doc, out)
price_list_rate=so_rate
else:
price_list_rate = frappe.db.get_value("Item Price",
{"price_list": args.price_list, "item_code": args.item_code}, "price_list_rate")
if not price_list_rate: return {}
out.price_list_rate = flt(price_list_rate) * flt(args.plc_conversion_rate) \
/ flt(args.conversion_rate)
if not out.price_list_rate and args.transaction_type == "buying":
from erpnext.stock.doctype.item.item import get_last_purchase_details
out.update(get_last_purchase_details(item_doc.name,
args.parent, args.conversion_rate))
def validate_price_list(args):
if args.get("price_list"):
if not frappe.db.get_value("Price List",
{"name": args.price_list, args.transaction_type: 1, "enabled": 1}):
throw(_("Price List {0} is disabled").format(args.price_list))
else:
throw(_("Price List not selected"))
def validate_conversion_rate(args, meta):
from erpnext.setup.doctype.currency.currency import validate_conversion_rate
from frappe.model.meta import get_field_precision
# validate currency conversion rate
validate_conversion_rate(args.currency, args.conversion_rate,
meta.get_label("conversion_rate"), args.company)
args.conversion_rate = flt(args.conversion_rate,
get_field_precision(meta.get_field("conversion_rate"),
frappe._dict({"fields": args})))
# validate price list currency conversion rate
if not args.get("price_list_currency"):
throw(_("Price List Currency not selected"))
else:
validate_conversion_rate(args.price_list_currency, args.plc_conversion_rate,
meta.get_label("plc_conversion_rate"), args.company)
args.plc_conversion_rate = flt(args.plc_conversion_rate,
get_field_precision(meta.get_field("plc_conversion_rate"),
frappe._dict({"fields": args})))
def get_party_item_code(args, item_doc, out):
if args.transaction_type == "selling":
customer_item_code = item_doc.get("item_customer_details", {"customer_name": args.customer})
out.customer_item_code = customer_item_code[0].ref_code if customer_item_code else None
else:
item_supplier = item_doc.get("item_supplier_details", {"supplier": args.supplier})
out.supplier_part_no = item_supplier[0].supplier_part_no if item_supplier else None
def get_pos_settings_item_details(company, args, pos_settings=None):
res = frappe._dict()
if not pos_settings:
pos_settings = get_pos_settings(company)
if pos_settings:
for fieldname in ("income_account", "cost_center", "warehouse", "expense_account"):
if not args.get(fieldname) and pos_settings.get(fieldname):
res[fieldname] = pos_settings.get(fieldname)
if res.get("warehouse"):
res.actual_qty = get_available_qty(args.item_code,
res.warehouse).get("actual_qty")
return res
def get_pos_settings(company):
pos_settings = frappe.db.sql("""select * from `tabPOS Setting` where user = %s
and company = %s""", (frappe.session['user'], company), as_dict=1)
if not pos_settings:
pos_settings = frappe.db.sql("""select * from `tabPOS Setting`
where ifnull(user,'') = '' and company = %s""", company, as_dict=1)
return pos_settings and pos_settings[0] or None
def get_serial_nos_by_fifo(args, item_doc):
return "\n".join(frappe.db.sql_list("""select name from `tabSerial No`
where item_code=%(item_code)s and warehouse=%(warehouse)s and status='Available'
order by timestamp(purchase_date, purchase_time) asc limit %(qty)s""", {
"item_code": args.item_code,
"warehouse": args.warehouse,
"qty": cint(args.qty)
}))
@frappe.whitelist()
def get_conversion_factor(item_code, uom):
return {"conversion_factor": frappe.db.get_value("UOM Conversion Detail",
{"parent": item_code, "uom": uom}, "conversion_factor")}
@frappe.whitelist()
def get_projected_qty(item_code, warehouse):
return {"projected_qty": frappe.db.get_value("Bin",
{"item_code": item_code, "warehouse": warehouse}, "projected_qty")}
@frappe.whitelist()
def get_available_qty(item_code, warehouse):
return frappe.db.get_value("Bin", {"item_code": item_code, "warehouse": warehouse},
["projected_qty", "actual_qty"], as_dict=True) or {}
@frappe.whitelist()
def apply_price_list(args):
"""
args = {
"item_list": [{"doctype": "", "name": "", "item_code": "", "brand": "", "item_group": ""}, ...],
"conversion_rate": 1.0,
"selling_price_list": None,
"price_list_currency": None,
"plc_conversion_rate": 1.0,
"parenttype": "",
"parent": "",
"supplier": None,
"transaction_date": None,
"conversion_rate": 1.0,
"buying_price_list": None,
"transaction_type": "selling",
"ignore_pricing_rule": 0/1
}
"""
args = process_args(args)
parent = get_price_list_currency_and_exchange_rate(args)
children = []
if "item_list" in args:
item_list = args.get("item_list")
del args["item_list"]
args.update(parent)
for item in item_list:
args_copy = frappe._dict(args.copy())
args_copy.update(item)
item_details = apply_price_list_on_item(args_copy)
children.append(item_details)
return {
"parent": parent,
"children": children
}
def apply_price_list_on_item(args):
item_details = frappe._dict()
item_doc = frappe.get_doc("Item", args.item_code)
get_price_list_rate(args, item_doc, item_details)
item_details.discount_percentage = 0.0
item_details.update(get_pricing_rule_for_item(args))
return item_details
def get_price_list_currency(price_list):
result = frappe.db.get_value("Price List", {"name": price_list,
"enabled": 1}, ["name", "currency"], as_dict=True)
if not result:
throw(_("Price List {0} is disabled").format(price_list))
return result.currency
def get_price_list_currency_and_exchange_rate(args):
price_list_currency = get_price_list_currency(args.price_list)
plc_conversion_rate = args.plc_conversion_rate
if (not plc_conversion_rate) or (price_list_currency != args.price_list_currency):
plc_conversion_rate = get_exchange_rate(price_list_currency, args.currency) \
or plc_conversion_rate
return {
"price_list_currency": price_list_currency,
"plc_conversion_rate": plc_conversion_rate
}
|
agpl-3.0
|
[
3,
1898,
334,
67,
9,
6171,
12,
6001,
8144,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
504,
6950,
492,
5501,
7978,
199,
504,
6950,
14,
1208,
492,
17166,
12,
286,
442,
12,
1050,
63,
4899,
199,
646,
2022,
199,
504,
29106,
14,
8370,
14,
6356,
14,
1359,
4477,
63,
2200,
14,
1359,
4477,
63,
2200,
492,
664,
63,
1359,
4477,
63,
2200,
63,
509,
63,
1053,
199,
504,
29106,
14,
2758,
14,
1208,
492,
664,
63,
14197,
63,
1866,
199,
199,
32,
9098,
14,
14189,
342,
199,
318,
664,
63,
1053,
63,
5087,
8,
589,
304,
199,
198,
624,
507,
198,
589,
275,
469,
686,
198,
2,
1053,
63,
600,
582,
4873,
686,
198,
2,
12806,
582,
488,
12,
686,
198,
2,
10178,
582,
4873,
686,
198,
2,
15083,
63,
1866,
582,
413,
14,
16,
12,
686,
198,
2,
261,
10564,
63,
4777,
63,
513,
582,
488,
12,
686,
198,
2,
4777,
63,
513,
63,
4968,
582,
488,
12,
686,
198,
2,
1168,
67,
63,
15083,
63,
1866,
582,
413,
14,
16,
12,
686,
198,
2,
1708,
466,
582,
4873,
686,
198,
2,
1708,
582,
4873,
686,
198,
2,
17294,
582,
488,
12,
686,
198,
2,
5945,
63,
602,
582,
488,
12,
686,
198,
2,
15083,
63,
1866,
582,
413,
14,
16,
12,
686,
198,
2,
464,
22440,
63,
4777,
63,
513,
582,
488,
12,
686,
198,
2,
374,
63,
954,
17926,
1522,
582,
298,
12555,
2,
1182,
298,
1944,
401,
686,
198,
2,
5945,
63,
466,
582,
298,
261,
10564,
401,
686,
198,
2,
4247,
63,
1359,
4477,
63,
2200,
582,
378,
15,
17,
686,
198,
2,
1715,
63,
354,
582,
4873,
507,
198,
93,
199,
198,
624,
199,
198,
589,
275,
2112,
63,
589,
8,
589,
9,
199,
198,
1053,
63,
1301,
275,
6950,
14,
362,
63,
1301,
480,
2081,
401,
1249,
14,
1053,
63,
600,
9,
199,
198,
1053,
275,
1242,
63,
1301,
4388,
198,
3502,
63,
1053,
63,
5087,
8,
589,
12,
1242,
9,
421,
198,
548,
275,
664,
63,
4316,
63,
5087,
8,
589,
12,
1242,
63,
1301,
9,
421,
198,
362,
63,
7522,
63,
1053,
63,
600,
8,
589,
12,
1242,
63,
1301,
12,
734,
9,
421,
198,
692,
734,
14,
362,
480,
12806,
2349,
507,
198,
548,
14,
873,
8,
362,
63,
4561,
63,
5643,
8,
589,
14,
1053,
63,
600,
12,
734,
14,
12806,
430,
507,
198,
548,
14,
873,
8,
362,
63,
25554,
63,
5643,
8,
1053,
14,
354,
12,
734,
14,
12806,
430,
421,
198,
362,
63,
4777,
63,
513,
63,
1866,
8,
589,
12,
1242,
63,
1301,
12,
734,
9,
421,
198,
692,
1249,
14,
5945,
63,
466,
508,
298,
261,
10564,
2,
436,
286,
442,
8,
589,
14,
374,
63,
1712,
304,
507,
198,
548,
14,
873,
8,
362,
63,
1712,
63,
1751,
63,
1053,
63,
5087,
8,
589,
14,
4627,
12,
1249,
430,
421,
198,
3,
1678,
1249,
543,
734,
12,
340,
790,
503,
574,
440,
3495,
199,
198,
509,
790,
12,
574,
315,
734,
14,
4611,
837,
507,
198,
692,
1249,
14,
362,
8,
498,
9,
365,
488,
26,
686,
198,
589,
59,
498,
61,
275,
574,
421,
198,
548,
14,
873,
8,
362,
63,
1359,
4477,
63,
2200,
63,
509,
63,
1053,
8,
589,
430,
421,
198,
692,
1249,
14,
362,
480,
1708,
466,
531,
315,
1689,
18220,
19868,
401,
298,
24640,
3390,
2349,
507,
198,
692,
1242,
63,
1301,
14,
1989,
63,
2171,
63,
889,
508,
298,
12555,
2,
436,
440,
1249,
14,
2171,
63,
889,
26,
686,
198,
548,
14,
2171,
63,
889,
275,
664,
63,
2171,
63,
12712,
63,
991,
63,
22976,
8,
589,
12,
1242,
63,
1301,
9,
421,
198,
692,
1249,
14,
5945,
63,
602,
436,
1242,
14,
13799,
63,
521,
63,
4899,
26,
507,
198,
548,
14,
7211,
63,
602,
275,
734,
14,
13799,
63,
521,
63,
602,
275,
1050,
63,
4899,
8,
589,
14,
5945,
63,
602,
12,
686,
198,
1053,
14,
13799,
63,
521,
63,
4899,
9,
199,
198,
3,
6950,
14,
1508,
1361,
8,
548,
9,
199,
198,
1107,
734,
199,
199,
318,
2112,
63,
589,
8,
589,
304,
199,
198,
692,
1228,
8,
589,
12,
7116,
304,
507,
198,
589,
275,
2022,
14,
3640,
8,
589,
9,
421,
198,
589,
275,
6950,
423,
807,
8,
589,
9,
421,
198,
692,
440,
1249,
14,
362,
480,
5945,
63,
466,
2349,
507,
198,
692,
1249,
14,
362,
480,
1708,
466,
531,
11800,
15787,
4784,
2,
503,
971,
1585,
198,
9098,
14,
362,
63,
2024,
8,
589,
14,
362,
480,
1708,
466,
21688,
362,
63,
698,
480,
17294,
2349,
686,
198,
589,
14,
5945,
63,
466,
275,
298,
464,
22440,
2,
507,
198,
2836,
26,
686,
198,
589,
14,
5945,
63,
466,
275,
298,
261,
10564,
2,
421,
198,
692,
440,
1249,
14,
362,
480,
4777,
63,
513,
2349,
507,
198,
589,
14,
4777,
63,
513,
275,
1249,
14,
362,
480,
261,
10564,
63,
4777,
63,
513,
531,
503,
1249,
14,
362,
480,
464,
22440,
63,
4777,
63,
513,
531,
421,
198,
692,
1249,
14,
22091,
26,
507,
198,
589,
14,
1053,
63,
600,
275,
664,
63,
1053,
63,
600,
8,
22091,
29,
589,
14,
22091,
9,
199,
198,
4164,
440,
1249,
14,
1053,
63,
600,
436,
1249,
14,
2171,
63,
889,
26,
507,
198,
589,
14,
1053,
63,
600,
275,
664,
63,
1053,
63,
600,
8,
2171,
63,
889,
29,
589,
14,
2171,
63,
889,
9,
421,
198,
1107,
1249,
199,
199,
318,
664,
63,
1053,
63,
600,
8,
22091,
29,
403,
12,
3012,
63,
889,
29,
403,
304,
199,
198,
692,
24323,
26,
507,
198,
1053,
63,
600,
275,
6950,
14,
697,
14,
362,
63,
585,
480,
2081,
401,
2420,
22091,
582,
24323,
1552,
507,
198,
692,
440,
1242,
63,
600,
26,
686,
198,
9098,
14,
11964,
6115,
1944,
7020,
543,
12377,
600,
469,
16,
30273,
908,
8,
22091,
430,
199,
198,
4164,
3012,
63,
889,
26,
507,
198,
1053,
63,
600,
275,
6950,
14,
697,
14,
362,
63,
585,
480
] |
[
1898,
334,
67,
9,
6171,
12,
6001,
8144,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
504,
6950,
492,
5501,
7978,
199,
504,
6950,
14,
1208,
492,
17166,
12,
286,
442,
12,
1050,
63,
4899,
199,
646,
2022,
199,
504,
29106,
14,
8370,
14,
6356,
14,
1359,
4477,
63,
2200,
14,
1359,
4477,
63,
2200,
492,
664,
63,
1359,
4477,
63,
2200,
63,
509,
63,
1053,
199,
504,
29106,
14,
2758,
14,
1208,
492,
664,
63,
14197,
63,
1866,
199,
199,
32,
9098,
14,
14189,
342,
199,
318,
664,
63,
1053,
63,
5087,
8,
589,
304,
199,
198,
624,
507,
198,
589,
275,
469,
686,
198,
2,
1053,
63,
600,
582,
4873,
686,
198,
2,
12806,
582,
488,
12,
686,
198,
2,
10178,
582,
4873,
686,
198,
2,
15083,
63,
1866,
582,
413,
14,
16,
12,
686,
198,
2,
261,
10564,
63,
4777,
63,
513,
582,
488,
12,
686,
198,
2,
4777,
63,
513,
63,
4968,
582,
488,
12,
686,
198,
2,
1168,
67,
63,
15083,
63,
1866,
582,
413,
14,
16,
12,
686,
198,
2,
1708,
466,
582,
4873,
686,
198,
2,
1708,
582,
4873,
686,
198,
2,
17294,
582,
488,
12,
686,
198,
2,
5945,
63,
602,
582,
488,
12,
686,
198,
2,
15083,
63,
1866,
582,
413,
14,
16,
12,
686,
198,
2,
464,
22440,
63,
4777,
63,
513,
582,
488,
12,
686,
198,
2,
374,
63,
954,
17926,
1522,
582,
298,
12555,
2,
1182,
298,
1944,
401,
686,
198,
2,
5945,
63,
466,
582,
298,
261,
10564,
401,
686,
198,
2,
4247,
63,
1359,
4477,
63,
2200,
582,
378,
15,
17,
686,
198,
2,
1715,
63,
354,
582,
4873,
507,
198,
93,
199,
198,
624,
199,
198,
589,
275,
2112,
63,
589,
8,
589,
9,
199,
198,
1053,
63,
1301,
275,
6950,
14,
362,
63,
1301,
480,
2081,
401,
1249,
14,
1053,
63,
600,
9,
199,
198,
1053,
275,
1242,
63,
1301,
4388,
198,
3502,
63,
1053,
63,
5087,
8,
589,
12,
1242,
9,
421,
198,
548,
275,
664,
63,
4316,
63,
5087,
8,
589,
12,
1242,
63,
1301,
9,
421,
198,
362,
63,
7522,
63,
1053,
63,
600,
8,
589,
12,
1242,
63,
1301,
12,
734,
9,
421,
198,
692,
734,
14,
362,
480,
12806,
2349,
507,
198,
548,
14,
873,
8,
362,
63,
4561,
63,
5643,
8,
589,
14,
1053,
63,
600,
12,
734,
14,
12806,
430,
507,
198,
548,
14,
873,
8,
362,
63,
25554,
63,
5643,
8,
1053,
14,
354,
12,
734,
14,
12806,
430,
421,
198,
362,
63,
4777,
63,
513,
63,
1866,
8,
589,
12,
1242,
63,
1301,
12,
734,
9,
421,
198,
692,
1249,
14,
5945,
63,
466,
508,
298,
261,
10564,
2,
436,
286,
442,
8,
589,
14,
374,
63,
1712,
304,
507,
198,
548,
14,
873,
8,
362,
63,
1712,
63,
1751,
63,
1053,
63,
5087,
8,
589,
14,
4627,
12,
1249,
430,
421,
198,
3,
1678,
1249,
543,
734,
12,
340,
790,
503,
574,
440,
3495,
199,
198,
509,
790,
12,
574,
315,
734,
14,
4611,
837,
507,
198,
692,
1249,
14,
362,
8,
498,
9,
365,
488,
26,
686,
198,
589,
59,
498,
61,
275,
574,
421,
198,
548,
14,
873,
8,
362,
63,
1359,
4477,
63,
2200,
63,
509,
63,
1053,
8,
589,
430,
421,
198,
692,
1249,
14,
362,
480,
1708,
466,
531,
315,
1689,
18220,
19868,
401,
298,
24640,
3390,
2349,
507,
198,
692,
1242,
63,
1301,
14,
1989,
63,
2171,
63,
889,
508,
298,
12555,
2,
436,
440,
1249,
14,
2171,
63,
889,
26,
686,
198,
548,
14,
2171,
63,
889,
275,
664,
63,
2171,
63,
12712,
63,
991,
63,
22976,
8,
589,
12,
1242,
63,
1301,
9,
421,
198,
692,
1249,
14,
5945,
63,
602,
436,
1242,
14,
13799,
63,
521,
63,
4899,
26,
507,
198,
548,
14,
7211,
63,
602,
275,
734,
14,
13799,
63,
521,
63,
602,
275,
1050,
63,
4899,
8,
589,
14,
5945,
63,
602,
12,
686,
198,
1053,
14,
13799,
63,
521,
63,
4899,
9,
199,
198,
3,
6950,
14,
1508,
1361,
8,
548,
9,
199,
198,
1107,
734,
199,
199,
318,
2112,
63,
589,
8,
589,
304,
199,
198,
692,
1228,
8,
589,
12,
7116,
304,
507,
198,
589,
275,
2022,
14,
3640,
8,
589,
9,
421,
198,
589,
275,
6950,
423,
807,
8,
589,
9,
421,
198,
692,
440,
1249,
14,
362,
480,
5945,
63,
466,
2349,
507,
198,
692,
1249,
14,
362,
480,
1708,
466,
531,
11800,
15787,
4784,
2,
503,
971,
1585,
198,
9098,
14,
362,
63,
2024,
8,
589,
14,
362,
480,
1708,
466,
21688,
362,
63,
698,
480,
17294,
2349,
686,
198,
589,
14,
5945,
63,
466,
275,
298,
464,
22440,
2,
507,
198,
2836,
26,
686,
198,
589,
14,
5945,
63,
466,
275,
298,
261,
10564,
2,
421,
198,
692,
440,
1249,
14,
362,
480,
4777,
63,
513,
2349,
507,
198,
589,
14,
4777,
63,
513,
275,
1249,
14,
362,
480,
261,
10564,
63,
4777,
63,
513,
531,
503,
1249,
14,
362,
480,
464,
22440,
63,
4777,
63,
513,
531,
421,
198,
692,
1249,
14,
22091,
26,
507,
198,
589,
14,
1053,
63,
600,
275,
664,
63,
1053,
63,
600,
8,
22091,
29,
589,
14,
22091,
9,
199,
198,
4164,
440,
1249,
14,
1053,
63,
600,
436,
1249,
14,
2171,
63,
889,
26,
507,
198,
589,
14,
1053,
63,
600,
275,
664,
63,
1053,
63,
600,
8,
2171,
63,
889,
29,
589,
14,
2171,
63,
889,
9,
421,
198,
1107,
1249,
199,
199,
318,
664,
63,
1053,
63,
600,
8,
22091,
29,
403,
12,
3012,
63,
889,
29,
403,
304,
199,
198,
692,
24323,
26,
507,
198,
1053,
63,
600,
275,
6950,
14,
697,
14,
362,
63,
585,
480,
2081,
401,
2420,
22091,
582,
24323,
1552,
507,
198,
692,
440,
1242,
63,
600,
26,
686,
198,
9098,
14,
11964,
6115,
1944,
7020,
543,
12377,
600,
469,
16,
30273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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
] |
0x0all/nupic
|
examples/opf/experiments/anomaly/spatial/10field_few_skewed/description.py
|
3
|
16833
|
# ----------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2013, Numenta, Inc. Unless you have an agreement
# with Numenta, Inc., for a separate license for this software code, the
# following terms and conditions apply:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
# ----------------------------------------------------------------------
"""
Template file used by the OPF Experiment Generator to generate the actual
description.py file by replacing $XXXXXXXX tokens with desired values.
This description.py file was generated by:
'~/nta/eng/lib/python2.6/site-packages/nupic/frameworks/opf/expGenerator/ExpGenerator.py'
"""
from nupic.frameworks.opf.expdescriptionapi import ExperimentDescriptionAPI
from nupic.frameworks.opf.expdescriptionhelpers import (
updateConfigFromSubConfig,
applyValueGettersToContainer,
DeferredDictLookup)
from nupic.frameworks.opf.clamodelcallbacks import *
from nupic.frameworks.opf.metrics import MetricSpec
from nupic.frameworks.opf.opfutils import (InferenceType,
InferenceElement)
from nupic.support import aggregationDivide
from nupic.frameworks.opf.opftaskdriver import (
IterationPhaseSpecLearnOnly,
IterationPhaseSpecInferOnly,
IterationPhaseSpecLearnAndInfer)
# Model Configuration Dictionary:
#
# Define the model parameters and adjust for any modifications if imported
# from a sub-experiment.
#
# These fields might be modified by a sub-experiment; this dict is passed
# between the sub-experiment and base experiment
#
#
# NOTE: Use of DEFERRED VALUE-GETTERs: dictionary fields and list elements
# within the config dictionary may be assigned futures derived from the
# ValueGetterBase class, such as DeferredDictLookup.
# This facility is particularly handy for enabling substitution of values in
# the config dictionary from other values in the config dictionary, which is
# needed by permutation.py-based experiments. These values will be resolved
# during the call to applyValueGettersToContainer(),
# which we call after the base experiment's config dictionary is updated from
# the sub-experiment. See ValueGetterBase and
# DeferredDictLookup for more details about value-getters.
#
# For each custom encoder parameter to be exposed to the sub-experiment/
# permutation overrides, define a variable in this section, using key names
# beginning with a single underscore character to avoid collisions with
# pre-defined keys (e.g., _dsEncoderFieldName2_N).
#
# Example:
# config = dict(
# _dsEncoderFieldName2_N = 70,
# _dsEncoderFieldName2_W = 5,
# dsEncoderSchema = [
# base=dict(
# fieldname='Name2', type='ScalarEncoder',
# name='Name2', minval=0, maxval=270, clipInput=True,
# n=DeferredDictLookup('_dsEncoderFieldName2_N'),
# w=DeferredDictLookup('_dsEncoderFieldName2_W')),
# ],
# )
# updateConfigFromSubConfig(config)
# applyValueGettersToContainer(config)
config = {
# Type of model that the rest of these parameters apply to.
'model': "CLA",
# Version that specifies the format of the config.
'version': 1,
# Intermediate variables used to compute fields in modelParams and also
# referenced from the control section.
'aggregationInfo': { 'fields': [ ('numericFieldNameA', 'mean'),
('numericFieldNameB', 'sum'),
('categoryFieldNameC', 'first')],
'hours': 0},
'predictAheadTime': None,
# Model parameter dictionary.
'modelParams': {
# The type of inference that this model will perform
'inferenceType': 'NontemporalAnomaly',
'sensorParams': {
# Sensor diagnostic output verbosity control;
# if > 0: sensor region will print out on screen what it's sensing
# at each step 0: silent; >=1: some info; >=2: more info;
# >=3: even more info (see compute() in py/regions/RecordSensor.py)
'verbosity' : 0,
# Example:
# dsEncoderSchema = [
# DeferredDictLookup('__field_name_encoder'),
# ],
#
# (value generated from DS_ENCODER_SCHEMA)
'encoders': {
'f0': dict(fieldname='f0', n=100, name='f0', type='SDRCategoryEncoder', w=21),
'f1': dict(fieldname='f1', n=100, name='f1', type='SDRCategoryEncoder', w=21),
'f2': dict(fieldname='f2', n=100, name='f2', type='SDRCategoryEncoder', w=21),
'f3': dict(fieldname='f3', n=100, name='f3', type='SDRCategoryEncoder', w=21),
'f4': dict(fieldname='f4', n=100, name='f4', type='SDRCategoryEncoder', w=21),
'f5': dict(fieldname='f5', n=100, name='f5', type='SDRCategoryEncoder', w=21),
'f6': dict(fieldname='f6', n=100, name='f6', type='SDRCategoryEncoder', w=21),
'f7': dict(fieldname='f7', n=100, name='f7', type='SDRCategoryEncoder', w=21),
'f8': dict(fieldname='f8', n=100, name='f8', type='SDRCategoryEncoder', w=21),
'f9': dict(fieldname='f9', n=100, name='f9', type='SDRCategoryEncoder', w=21),
},
# A dictionary specifying the period for automatically-generated
# resets from a RecordSensor;
#
# None = disable automatically-generated resets (also disabled if
# all of the specified values evaluate to 0).
# Valid keys is the desired combination of the following:
# days, hours, minutes, seconds, milliseconds, microseconds, weeks
#
# Example for 1.5 days: sensorAutoReset = dict(days=1,hours=12),
#
# (value generated from SENSOR_AUTO_RESET)
'sensorAutoReset' : None,
},
'spEnable': True,
'spParams': {
# SP diagnostic output verbosity control;
# 0: silent; >=1: some info; >=2: more info;
'spVerbosity' : 0,
'globalInhibition': 1,
# Number of cell columns in the cortical region (same number for
# SP and TP)
# (see also tpNCellsPerCol)
'columnCount': 2048,
'inputWidth': 0,
# SP inhibition control (absolute value);
# Maximum number of active columns in the SP region's output (when
# there are more, the weaker ones are suppressed)
'numActivePerInhArea': 40,
'seed': 1956,
# coincInputPoolPct
# What percent of the columns's receptive field is available
# for potential synapses. At initialization time, we will
# choose coincInputPoolPct * (2*coincInputRadius+1)^2
'coincInputPoolPct': 0.5,
# The default connected threshold. Any synapse whose
# permanence value is above the connected threshold is
# a "connected synapse", meaning it can contribute to the
# cell's firing. Typical value is 0.10. Cells whose activity
# level before inhibition falls below minDutyCycleBeforeInh
# will have their own internal synPermConnectedCell
# threshold set below this default value.
# (This concept applies to both SP and TP and so 'cells'
# is correct here as opposed to 'columns')
'synPermConnected': 0.1,
'synPermActiveInc': 0.1,
'synPermInactiveDec': 0.01,
},
# Controls whether TP is enabled or disabled;
# TP is necessary for making temporal predictions, such as predicting
# the next inputs. Without TP, the model is only capable of
# reconstructing missing sensor inputs (via SP).
'tpEnable' : True,
'tpParams': {
# TP diagnostic output verbosity control;
# 0: silent; [1..6]: increasing levels of verbosity
# (see verbosity in nta/trunk/py/nupic/research/TP.py and TP10X*.py)
'verbosity': 0,
# Number of cell columns in the cortical region (same number for
# SP and TP)
# (see also tpNCellsPerCol)
'columnCount': 2048,
# The number of cells (i.e., states), allocated per column.
'cellsPerColumn': 32,
'inputWidth': 2048,
'seed': 1960,
# Temporal Pooler implementation selector (see _getTPClass in
# CLARegion.py).
'temporalImp': 'cpp',
# New Synapse formation count
# NOTE: If None, use spNumActivePerInhArea
#
# TODO: need better explanation
'newSynapseCount': 20,
# Maximum number of synapses per segment
# > 0 for fixed-size CLA
# -1 for non-fixed-size CLA
#
# TODO: for Ron: once the appropriate value is placed in TP
# constructor, see if we should eliminate this parameter from
# description.py.
'maxSynapsesPerSegment': 32,
# Maximum number of segments per cell
# > 0 for fixed-size CLA
# -1 for non-fixed-size CLA
#
# TODO: for Ron: once the appropriate value is placed in TP
# constructor, see if we should eliminate this parameter from
# description.py.
'maxSegmentsPerCell': 128,
# Initial Permanence
# TODO: need better explanation
'initialPerm': 0.21,
# Permanence Increment
'permanenceInc': 0.1,
# Permanence Decrement
# If set to None, will automatically default to tpPermanenceInc
# value.
'permanenceDec' : 0.1,
'globalDecay': 0.0,
'maxAge': 0,
# Minimum number of active synapses for a segment to be considered
# during search for the best-matching segments.
# None=use default
# Replaces: tpMinThreshold
'minThreshold': 12,
# Segment activation threshold.
# A segment is active if it has >= tpSegmentActivationThreshold
# connected synapses that are active due to infActiveState
# None=use default
# Replaces: tpActivationThreshold
'activationThreshold': 16,
'outputType': 'normal',
# "Pay Attention Mode" length. This tells the TP how many new
# elements to append to the end of a learned sequence at a time.
# Smaller values are better for datasets with short sequences,
# higher values are better for datasets with long sequences.
'pamLength': 1,
},
'clParams': {
# Classifier implementation selection.
'implementation': 'cpp',
'regionName' : 'CLAClassifierRegion',
# Classifier diagnostic output verbosity control;
# 0: silent; [1..6]: increasing levels of verbosity
'clVerbosity' : 0,
# This controls how fast the classifier learns/forgets. Higher values
# make it adapt faster and forget older patterns faster.
'alpha': 0.001,
# This is set after the call to updateConfigFromSubConfig and is
# computed from the aggregationInfo and predictAheadTime.
'steps': '1',
},
'trainSPNetOnlyIfRequested': False,
},
}
# end of config dictionary
# Adjust base config dictionary for any modifications if imported from a
# sub-experiment
updateConfigFromSubConfig(config)
# Compute predictionSteps based on the predictAheadTime and the aggregation
# period, which may be permuted over.
if config['predictAheadTime'] is not None:
predictionSteps = int(round(aggregationDivide(
config['predictAheadTime'], config['aggregationInfo'])))
assert (predictionSteps >= 1)
config['modelParams']['clParams']['steps'] = str(predictionSteps)
# Adjust config by applying ValueGetterBase-derived
# futures. NOTE: this MUST be called after updateConfigFromSubConfig() in order
# to support value-getter-based substitutions from the sub-experiment (if any)
applyValueGettersToContainer(config)
################################################################################
# [optional] A sequence of one or more tasks that describe what to do with the
# model. Each task consists of a task label, an input spec., iteration count,
# and a task-control spec per opfTaskSchema.json
#
# NOTE: The tasks are intended for OPF clients that make use of OPFTaskDriver.
# Clients that interact with OPFExperiment directly do not make use of
# the tasks specification.
#
control = dict(
environment='opfExperiment',
tasks = [
{
# Task label; this label string may be used for diagnostic logging and for
# constructing filenames or directory pathnames for task-specific files, etc.
'taskLabel' : "Anomaly",
# Input stream specification per py/nupic/cluster/database/StreamDef.json.
#
'dataset' : {
'info': 'test_NoProviders',
'version': 1,
'streams': [
{
'columns': ['*'],
'info': 'my simple dataset',
'source': 'file://'+os.path.join(os.path.dirname(__file__), 'data.csv'),
}
],
# TODO: Aggregation is not supported yet by OpfRunExperiment.py
#'aggregation' : config['aggregationInfo']
},
# Iteration count: maximum number of iterations. Each iteration corresponds
# to one record from the (possibly aggregated) dataset. The task is
# terminated when either number of iterations reaches iterationCount or
# all records in the (possibly aggregated) database have been processed,
# whichever occurs first.
#
# iterationCount of -1 = iterate over the entire dataset
'iterationCount' : -1,
# Task Control parameters for OPFTaskDriver (per opfTaskControlSchema.json)
'taskControl' : {
# Iteration cycle list consisting of opftaskdriver.IterationPhaseSpecXXXXX
# instances.
'iterationCycle' : [
#IterationPhaseSpecLearnOnly(1000),
IterationPhaseSpecLearnAndInfer(1000, inferenceArgs=None),
#IterationPhaseSpecInferOnly(10, inferenceArgs=None),
],
'metrics' : [
],
# Logged Metrics: A sequence of regular expressions that specify which of
# the metrics from the Inference Specifications section MUST be logged for
# every prediction. The regex's correspond to the automatically generated
# metric labels. This is similar to the way the optimization metric is
# specified in permutations.py.
'loggedMetrics': ['.*grokScore.*'],
# Callbacks for experimentation/research (optional)
'callbacks' : {
# Callbacks to be called at the beginning of a task, before model iterations.
# Signature: callback(<reference to OPFExperiment>); returns nothing
# 'setup' : [claModelControlEnableSPLearningCb, claModelControlEnableTPLearningCb],
# 'setup' : [claModelControlDisableTPLearningCb],
'setup' : [],
# Callbacks to be called after every learning/inference iteration
# Signature: callback(<reference to OPFExperiment>); returns nothing
'postIter' : [],
# Callbacks to be called when the experiment task is finished
# Signature: callback(<reference to OPFExperiment>); returns nothing
'finish' : []
}
} # End of taskControl
}, # End of task
]
)
################################################################################
################################################################################
descriptionInterface = ExperimentDescriptionAPI(modelConfig=config,
control=control)
|
gpl-3.0
|
[
3,
20359,
199,
3,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
1898,
334,
35,
9,
6171,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
376,
25025,
199,
3,
543,
22783,
12,
3277,
2020,
367,
282,
7396,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
20359,
199,
199,
624,
199,
4231,
570,
1202,
701,
314,
9827,
38,
23997,
15042,
370,
3550,
314,
3503,
199,
1802,
14,
647,
570,
701,
15810,
2672,
13312,
4645,
543,
6387,
1338,
14,
199,
199,
2765,
1369,
14,
647,
570,
1990,
4046,
701,
26,
199,
27547,
15,
343,
65,
15,
7420,
15,
773,
15,
1548,
18,
14,
22,
15,
2124,
13,
5154,
15,
14596,
530,
15,
32037,
15,
16893,
15,
1474,
7599,
15,
4527,
7599,
14,
647,
7,
199,
624,
199,
199,
504,
26084,
14,
32037,
14,
16893,
14,
1474,
1802,
1246,
492,
23997,
5831,
3735,
199,
199,
504,
26084,
14,
32037,
14,
16893,
14,
1474,
1802,
7546,
492,
334,
523,
1678,
2028,
2532,
2610,
2028,
12,
523,
4838,
1110,
1002,
878,
1378,
4076,
12,
523,
17448,
2141,
7521,
9,
199,
199,
504,
26084,
14,
32037,
14,
16893,
14,
3995,
1238,
11948,
492,
627,
199,
504,
26084,
14,
32037,
14,
16893,
14,
6759,
492,
22465,
5307,
199,
504,
26084,
14,
32037,
14,
16893,
14,
16893,
1208,
492,
334,
29731,
804,
12,
5644,
1010,
1769,
2162,
9,
199,
504,
26084,
14,
4058,
492,
18384,
1341,
5624,
199,
199,
504,
26084,
14,
32037,
14,
16893,
14,
411,
856,
813,
3090,
492,
334,
4490,
473,
5388,
10521,
5307,
21424,
5903,
12,
4490,
473,
5388,
10521,
5307,
607,
2412,
5903,
12,
4490,
473,
5388,
10521,
5307,
21424,
3325,
607,
2412,
9,
421,
199,
3,
5822,
11595,
11932,
26,
199,
3,
199,
3,
13930,
314,
1402,
2633,
436,
11311,
367,
1263,
23070,
340,
8439,
199,
3,
687,
282,
1007,
13,
10873,
14,
199,
3,
199,
3,
5723,
1504,
5594,
506,
6042,
701,
282,
1007,
13,
10873,
27,
642,
1211,
365,
3032,
199,
3,
3382,
314,
1007,
13,
10873,
436,
1300,
11805,
199,
3,
199,
3,
199,
3,
6944,
26,
3645,
402,
3265,
15849,
7387,
21170,
13,
39,
1573,
83,
26,
2600,
1504,
436,
769,
4008,
199,
3,
257,
4453,
314,
1101,
2600,
1443,
506,
7943,
27471,
7131,
687,
314,
199,
3,
257,
1594,
22038,
1563,
1021,
12,
4066,
465,
17448,
2141,
7521,
14,
199,
3,
257,
961,
21395,
365,
6770,
590,
4926,
89,
367,
29310,
20584,
402,
1338,
315,
199,
3,
257,
314,
1101,
2600,
687,
1163,
1338,
315,
314,
1101,
2600,
12,
1314,
365,
199,
3,
257,
4346,
701,
22966,
14,
647,
13,
6788,
444,
22263,
14,
5723,
1338,
911,
506,
12152,
199,
3,
257,
5309,
314,
1240,
370,
4838,
1110,
1002,
878,
1378,
4076,
1062,
199,
3,
257,
1314,
781,
1240,
2410,
314,
1300,
11805,
1159,
1101,
2600,
365,
4588,
687,
199,
3,
257,
314,
1007,
13,
10873,
14,
1666,
1594,
22038,
1563,
436,
199,
3,
257,
17448,
2141,
7521,
367,
1655,
2436,
3595,
574,
13,
362,
878,
14,
199,
3,
199,
3,
257,
2104,
1924,
3537,
10295,
2725,
370,
506,
19282,
370,
314,
1007,
13,
10873,
15,
199,
3,
257,
22966,
10580,
12,
5627,
282,
1750,
315,
642,
3420,
12,
1808,
790,
1561,
199,
3,
257,
9608,
543,
282,
2849,
18888,
4528,
370,
5126,
30063,
543,
199,
3,
257,
876,
13,
4037,
2883,
334,
69,
14,
71,
2020,
485,
795,
6679,
792,
985,
18,
63,
46,
680,
199,
3,
199,
3,
257,
5679,
26,
199,
3,
420,
1101,
275,
1211,
8,
199,
3,
263,
485,
795,
6679,
792,
985,
18,
63,
46,
275,
10045,
12,
199,
3,
263,
485,
795,
6679,
792,
985,
18,
63,
55,
275,
959,
12,
199,
3,
263,
6364,
6679,
6700,
275,
359,
199,
3,
3515,
1300,
29,
807,
8,
199,
3,
3322,
18887,
534,
985,
18,
297,
730,
534,
13090,
6679,
297,
199,
3,
3322,
536,
534,
985,
18,
297,
30135,
29,
16,
12,
23291,
29,
13299,
12,
11353,
3205,
29,
549,
12,
199,
3,
3322,
302,
29,
9937,
2141,
7521,
6412,
795,
6679,
792,
985,
18,
63,
46,
659,
199,
3,
3322,
336,
29,
9937,
2141,
7521,
6412,
795,
6679,
792,
985,
18,
63,
55,
3855,
199,
3,
263,
2156,
199,
3,
420,
776,
199,
3,
420,
1678,
2028,
2532,
2610,
2028,
8,
888,
9,
199,
3,
420,
4838,
1110,
1002,
878,
1378,
4076,
8,
888,
9,
199,
888,
275,
469,
272,
327,
2434,
402,
1402,
626,
314,
4618,
402,
3520,
2633,
4838,
370,
14,
272,
283,
1238,
356,
298,
8576,
401,
339,
327,
3394,
626,
9314,
314,
1475,
402,
314,
1101,
14,
272,
283,
1023,
356,
413,
12,
339,
327,
6551,
5050,
2860,
1202,
370,
4526,
1504,
315,
1402,
6007,
436,
2597,
272,
327,
11812,
687,
314,
3304,
3420,
14,
272,
283,
21016,
2354,
356,
469,
257,
283,
955,
356,
359,
257,
661,
6677,
792,
985,
33,
297,
283,
3670,
659,
1993,
661,
6677,
792,
985,
34,
297,
283,
1838,
659,
1993,
661,
3710,
792,
985,
35,
297,
283,
2246,
2665,
267,
283,
8419,
356,
378,
1386,
2286,
283,
6892,
33,
2993,
1366,
356,
488,
12,
339,
327,
5822,
2725,
2600,
14,
272,
283,
1238,
6007,
356,
469,
267,
327,
710,
730,
402,
17353,
626,
642,
1402,
911,
5147,
267,
283,
20580,
804,
356,
283,
6932
] |
[
20359,
199,
3,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
1898,
334,
35,
9,
6171,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
376,
25025,
199,
3,
543,
22783,
12,
3277,
2020,
367,
282,
7396,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
20359,
199,
199,
624,
199,
4231,
570,
1202,
701,
314,
9827,
38,
23997,
15042,
370,
3550,
314,
3503,
199,
1802,
14,
647,
570,
701,
15810,
2672,
13312,
4645,
543,
6387,
1338,
14,
199,
199,
2765,
1369,
14,
647,
570,
1990,
4046,
701,
26,
199,
27547,
15,
343,
65,
15,
7420,
15,
773,
15,
1548,
18,
14,
22,
15,
2124,
13,
5154,
15,
14596,
530,
15,
32037,
15,
16893,
15,
1474,
7599,
15,
4527,
7599,
14,
647,
7,
199,
624,
199,
199,
504,
26084,
14,
32037,
14,
16893,
14,
1474,
1802,
1246,
492,
23997,
5831,
3735,
199,
199,
504,
26084,
14,
32037,
14,
16893,
14,
1474,
1802,
7546,
492,
334,
523,
1678,
2028,
2532,
2610,
2028,
12,
523,
4838,
1110,
1002,
878,
1378,
4076,
12,
523,
17448,
2141,
7521,
9,
199,
199,
504,
26084,
14,
32037,
14,
16893,
14,
3995,
1238,
11948,
492,
627,
199,
504,
26084,
14,
32037,
14,
16893,
14,
6759,
492,
22465,
5307,
199,
504,
26084,
14,
32037,
14,
16893,
14,
16893,
1208,
492,
334,
29731,
804,
12,
5644,
1010,
1769,
2162,
9,
199,
504,
26084,
14,
4058,
492,
18384,
1341,
5624,
199,
199,
504,
26084,
14,
32037,
14,
16893,
14,
411,
856,
813,
3090,
492,
334,
4490,
473,
5388,
10521,
5307,
21424,
5903,
12,
4490,
473,
5388,
10521,
5307,
607,
2412,
5903,
12,
4490,
473,
5388,
10521,
5307,
21424,
3325,
607,
2412,
9,
421,
199,
3,
5822,
11595,
11932,
26,
199,
3,
199,
3,
13930,
314,
1402,
2633,
436,
11311,
367,
1263,
23070,
340,
8439,
199,
3,
687,
282,
1007,
13,
10873,
14,
199,
3,
199,
3,
5723,
1504,
5594,
506,
6042,
701,
282,
1007,
13,
10873,
27,
642,
1211,
365,
3032,
199,
3,
3382,
314,
1007,
13,
10873,
436,
1300,
11805,
199,
3,
199,
3,
199,
3,
6944,
26,
3645,
402,
3265,
15849,
7387,
21170,
13,
39,
1573,
83,
26,
2600,
1504,
436,
769,
4008,
199,
3,
257,
4453,
314,
1101,
2600,
1443,
506,
7943,
27471,
7131,
687,
314,
199,
3,
257,
1594,
22038,
1563,
1021,
12,
4066,
465,
17448,
2141,
7521,
14,
199,
3,
257,
961,
21395,
365,
6770,
590,
4926,
89,
367,
29310,
20584,
402,
1338,
315,
199,
3,
257,
314,
1101,
2600,
687,
1163,
1338,
315,
314,
1101,
2600,
12,
1314,
365,
199,
3,
257,
4346,
701,
22966,
14,
647,
13,
6788,
444,
22263,
14,
5723,
1338,
911,
506,
12152,
199,
3,
257,
5309,
314,
1240,
370,
4838,
1110,
1002,
878,
1378,
4076,
1062,
199,
3,
257,
1314,
781,
1240,
2410,
314,
1300,
11805,
1159,
1101,
2600,
365,
4588,
687,
199,
3,
257,
314,
1007,
13,
10873,
14,
1666,
1594,
22038,
1563,
436,
199,
3,
257,
17448,
2141,
7521,
367,
1655,
2436,
3595,
574,
13,
362,
878,
14,
199,
3,
199,
3,
257,
2104,
1924,
3537,
10295,
2725,
370,
506,
19282,
370,
314,
1007,
13,
10873,
15,
199,
3,
257,
22966,
10580,
12,
5627,
282,
1750,
315,
642,
3420,
12,
1808,
790,
1561,
199,
3,
257,
9608,
543,
282,
2849,
18888,
4528,
370,
5126,
30063,
543,
199,
3,
257,
876,
13,
4037,
2883,
334,
69,
14,
71,
2020,
485,
795,
6679,
792,
985,
18,
63,
46,
680,
199,
3,
199,
3,
257,
5679,
26,
199,
3,
420,
1101,
275,
1211,
8,
199,
3,
263,
485,
795,
6679,
792,
985,
18,
63,
46,
275,
10045,
12,
199,
3,
263,
485,
795,
6679,
792,
985,
18,
63,
55,
275,
959,
12,
199,
3,
263,
6364,
6679,
6700,
275,
359,
199,
3,
3515,
1300,
29,
807,
8,
199,
3,
3322,
18887,
534,
985,
18,
297,
730,
534,
13090,
6679,
297,
199,
3,
3322,
536,
534,
985,
18,
297,
30135,
29,
16,
12,
23291,
29,
13299,
12,
11353,
3205,
29,
549,
12,
199,
3,
3322,
302,
29,
9937,
2141,
7521,
6412,
795,
6679,
792,
985,
18,
63,
46,
659,
199,
3,
3322,
336,
29,
9937,
2141,
7521,
6412,
795,
6679,
792,
985,
18,
63,
55,
3855,
199,
3,
263,
2156,
199,
3,
420,
776,
199,
3,
420,
1678,
2028,
2532,
2610,
2028,
8,
888,
9,
199,
3,
420,
4838,
1110,
1002,
878,
1378,
4076,
8,
888,
9,
199,
888,
275,
469,
272,
327,
2434,
402,
1402,
626,
314,
4618,
402,
3520,
2633,
4838,
370,
14,
272,
283,
1238,
356,
298,
8576,
401,
339,
327,
3394,
626,
9314,
314,
1475,
402,
314,
1101,
14,
272,
283,
1023,
356,
413,
12,
339,
327,
6551,
5050,
2860,
1202,
370,
4526,
1504,
315,
1402,
6007,
436,
2597,
272,
327,
11812,
687,
314,
3304,
3420,
14,
272,
283,
21016,
2354,
356,
469,
257,
283,
955,
356,
359,
257,
661,
6677,
792,
985,
33,
297,
283,
3670,
659,
1993,
661,
6677,
792,
985,
34,
297,
283,
1838,
659,
1993,
661,
3710,
792,
985,
35,
297,
283,
2246,
2665,
267,
283,
8419,
356,
378,
1386,
2286,
283,
6892,
33,
2993,
1366,
356,
488,
12,
339,
327,
5822,
2725,
2600,
14,
272,
283,
1238,
6007,
356,
469,
267,
327,
710,
730,
402,
17353,
626,
642,
1402,
911,
5147,
267,
283,
20580,
804,
356,
283,
6932,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
gpailler/AtlassianBot
|
plugins/stash.py
|
1
|
1971
|
# coding: utf-8
import requests
from utils import rest
class Stash(object):
def __init__(self, server):
self.__server = server
def get_stash_branches(self, repos, project, filter):
results = []
for repo in repos:
path = '/rest/api/1.0/projects/{project}/repos/{repo}/branches'\
.format(project=project, repo=repo)
data = {
'filterText': filter,
'details': True,
'limit': 100
}
request = rest.get(self.__server, path, data)
for result in request.json()['values']:
results.append((
repo,
result['id'],
result['displayId'],
result['latestChangeset']))
return results
def branch_merged(self, project, basebranches, repo, branch):
for to in basebranches:
path = ('/rest/api/1.0/projects/{project}/repos/{repo}/'
'compare/changes/').format(project=project, repo=repo)
data = {
'from': branch,
'to': to,
'limit': 1
}
request = rest.get(self.__server, path, data)
if request.status_code != requests.codes.ok:
raise Exception(request.text)
else:
if request.json()['size'] == 0:
return True
return False
def remove_git_branches(self, project, repo, branchkey, changeset):
path = ('/rest/branch-utils/1.0/projects/{project}/repos/{repo}/'
'branches').format(project=project, repo=repo)
data = {
'name': branchkey,
'endPoint': changeset,
'dryRun': False
}
request = rest.delete(self.__server, path, data)
if request.status_code != requests.codes.no_content:
raise Exception(request.text)
|
mit
|
[
3,
2803,
26,
2774,
13,
24,
199,
199,
646,
4145,
199,
504,
3778,
492,
4618,
421,
199,
533,
10126,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1654,
304,
267,
291,
855,
1000,
275,
1654,
339,
347,
664,
63,
27145,
63,
16896,
8,
277,
12,
20416,
12,
2199,
12,
2457,
304,
267,
2058,
275,
942,
267,
367,
3831,
315,
20416,
26,
288,
931,
275,
1994,
3911,
15,
1246,
15,
17,
14,
16,
15,
6776,
5321,
1715,
5995,
11857,
5321,
3417,
5995,
16896,
1154,
490,
1275,
908,
8,
1715,
29,
1715,
12,
3831,
29,
3417,
9,
288,
666,
275,
469,
355,
283,
1541,
1872,
356,
2457,
12,
355,
283,
5087,
356,
715,
12,
355,
283,
3097,
356,
2948,
288,
789,
953,
1056,
275,
4618,
14,
362,
8,
277,
855,
1000,
12,
931,
12,
666,
9,
288,
367,
754,
315,
1056,
14,
1001,
12047,
1459,
2565,
355,
2058,
14,
740,
1332,
490,
3831,
12,
490,
754,
459,
344,
995,
490,
754,
459,
2918,
1304,
995,
490,
754,
459,
7410,
4001,
409,
5156,
398,
372,
2058,
339,
347,
5246,
63,
15269,
8,
277,
12,
2199,
12,
1300,
16896,
12,
3831,
12,
5246,
304,
267,
367,
370,
315,
1300,
16896,
26,
288,
931,
275,
14606,
3911,
15,
1246,
15,
17,
14,
16,
15,
6776,
5321,
1715,
5995,
11857,
5321,
3417,
93,
4805,
490,
283,
5785,
15,
6627,
15,
1959,
908,
8,
1715,
29,
1715,
12,
3831,
29,
3417,
9,
288,
666,
275,
469,
355,
283,
504,
356,
5246,
12,
355,
283,
475,
356,
370,
12,
355,
283,
3097,
356,
413,
288,
789,
953,
1056,
275,
4618,
14,
362,
8,
277,
855,
1000,
12,
931,
12,
666,
9,
288,
340,
1056,
14,
1205,
63,
600,
1137,
4145,
14,
6021,
14,
745,
26,
355,
746,
2186,
8,
1069,
14,
505,
9,
288,
587,
26,
355,
340,
1056,
14,
1001,
12047,
890,
418,
508,
378,
26,
490,
372,
715,
398,
372,
756,
339,
347,
2813,
63,
3187,
63,
16896,
8,
277,
12,
2199,
12,
3831,
12,
5246,
498,
12,
23316,
304,
267,
931,
275,
14606,
3911,
15,
4694,
13,
1208,
15,
17,
14,
16,
15,
6776,
5321,
1715,
5995,
11857,
5321,
3417,
93,
4805,
355,
283,
16896,
1959,
908,
8,
1715,
29,
1715,
12,
3831,
29,
3417,
9,
267,
666,
275,
469,
288,
283,
354,
356,
5246,
498,
12,
288,
283,
500,
3428,
356,
23316,
12,
288,
283,
10481,
2540,
356,
756,
267,
789,
398,
1056,
275,
4618,
14,
1807,
8,
277,
855,
1000,
12,
931,
12,
666,
9,
267,
340,
1056,
14,
1205,
63,
600,
1137,
4145,
14,
6021,
14,
889,
63,
1317,
26,
288,
746,
2186,
8,
1069,
14,
505,
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
] |
[
2803,
26,
2774,
13,
24,
199,
199,
646,
4145,
199,
504,
3778,
492,
4618,
421,
199,
533,
10126,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1654,
304,
267,
291,
855,
1000,
275,
1654,
339,
347,
664,
63,
27145,
63,
16896,
8,
277,
12,
20416,
12,
2199,
12,
2457,
304,
267,
2058,
275,
942,
267,
367,
3831,
315,
20416,
26,
288,
931,
275,
1994,
3911,
15,
1246,
15,
17,
14,
16,
15,
6776,
5321,
1715,
5995,
11857,
5321,
3417,
5995,
16896,
1154,
490,
1275,
908,
8,
1715,
29,
1715,
12,
3831,
29,
3417,
9,
288,
666,
275,
469,
355,
283,
1541,
1872,
356,
2457,
12,
355,
283,
5087,
356,
715,
12,
355,
283,
3097,
356,
2948,
288,
789,
953,
1056,
275,
4618,
14,
362,
8,
277,
855,
1000,
12,
931,
12,
666,
9,
288,
367,
754,
315,
1056,
14,
1001,
12047,
1459,
2565,
355,
2058,
14,
740,
1332,
490,
3831,
12,
490,
754,
459,
344,
995,
490,
754,
459,
2918,
1304,
995,
490,
754,
459,
7410,
4001,
409,
5156,
398,
372,
2058,
339,
347,
5246,
63,
15269,
8,
277,
12,
2199,
12,
1300,
16896,
12,
3831,
12,
5246,
304,
267,
367,
370,
315,
1300,
16896,
26,
288,
931,
275,
14606,
3911,
15,
1246,
15,
17,
14,
16,
15,
6776,
5321,
1715,
5995,
11857,
5321,
3417,
93,
4805,
490,
283,
5785,
15,
6627,
15,
1959,
908,
8,
1715,
29,
1715,
12,
3831,
29,
3417,
9,
288,
666,
275,
469,
355,
283,
504,
356,
5246,
12,
355,
283,
475,
356,
370,
12,
355,
283,
3097,
356,
413,
288,
789,
953,
1056,
275,
4618,
14,
362,
8,
277,
855,
1000,
12,
931,
12,
666,
9,
288,
340,
1056,
14,
1205,
63,
600,
1137,
4145,
14,
6021,
14,
745,
26,
355,
746,
2186,
8,
1069,
14,
505,
9,
288,
587,
26,
355,
340,
1056,
14,
1001,
12047,
890,
418,
508,
378,
26,
490,
372,
715,
398,
372,
756,
339,
347,
2813,
63,
3187,
63,
16896,
8,
277,
12,
2199,
12,
3831,
12,
5246,
498,
12,
23316,
304,
267,
931,
275,
14606,
3911,
15,
4694,
13,
1208,
15,
17,
14,
16,
15,
6776,
5321,
1715,
5995,
11857,
5321,
3417,
93,
4805,
355,
283,
16896,
1959,
908,
8,
1715,
29,
1715,
12,
3831,
29,
3417,
9,
267,
666,
275,
469,
288,
283,
354,
356,
5246,
498,
12,
288,
283,
500,
3428,
356,
23316,
12,
288,
283,
10481,
2540,
356,
756,
267,
789,
398,
1056,
275,
4618,
14,
1807,
8,
277,
855,
1000,
12,
931,
12,
666,
9,
267,
340,
1056,
14,
1205,
63,
600,
1137,
4145,
14,
6021,
14,
889,
63,
1317,
26,
288,
746,
2186,
8,
1069,
14,
505,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nwalters512/the-blue-alliance
|
controllers/api_controller.py
|
8
|
5197
|
import csv
import json
import logging
import StringIO
import os
import urllib
import uuid
import webapp2
from datetime import datetime
from google.appengine.api import memcache, urlfetch
from google.appengine.ext import deferred, ndb
from google.appengine.ext.webapp import template
import tba_config
from helpers.api_helper import ApiHelper
from models.event import Event
from models.sitevar import Sitevar
from models.team import Team
# used for deferred call
def track_call(api_action, api_details, x_tba_app_id):
analytics_id = Sitevar.get_by_id("google_analytics.id")
if analytics_id is None:
logging.warning("Missing sitevar: google_analytics.id. Can't track API usage.")
else:
GOOGLE_ANALYTICS_ID = analytics_id.contents['GOOGLE_ANALYTICS_ID']
params = urllib.urlencode({
'v': 1,
'tid': GOOGLE_ANALYTICS_ID,
'cid': uuid.uuid3(uuid.NAMESPACE_X500, str(x_tba_app_id)),
't': 'event',
'ec': 'api',
'ea': api_action,
'el': api_details,
'cd1': x_tba_app_id, # custom dimension 1
'ni': 1,
'sc': 'end', # forces tracking session to end
})
# Sets up the call
analytics_url = 'http://www.google-analytics.com/collect?%s' % params
urlfetch.fetch(
url=analytics_url,
method=urlfetch.GET,
deadline=10,
)
class ApiDeprecatedController(webapp2.RequestHandler):
def __init__(self, request, response):
self.initialize(request, response)
self.response.headers.add_header("content-type", "application/json")
def get(self, _):
self.response.out.write(json.dumps({"Error": "As of Jan. 2 2015, v1 of the TBA API has been deprecated. Please see http://www.thebluealliance.com/apidocs for more info."}))
self.response.headers['Cache-Control'] = "public, max-age=%d" % (60*60*24*7) # 1 week
self.response.headers['Pragma'] = 'Public'
# Note: generally caching for the API happens in ApiHelper
class MainApiHandler(webapp2.RequestHandler):
def __init__(self, request, response):
# Need to initialize a webapp2 instance
self.initialize(request, response)
self.response.headers.add_header("content-type", "application/json")
self.response.headers['Access-Control-Allow-Origin'] = '*'
def handle_exception(self, exception, debug):
"""
Handle an HTTP exception and actually write out a response.
Called by webapp when abort() is called, stops code excution.
"""
logging.info(exception)
if isinstance(exception, webapp2.HTTPException):
self.response.set_status(exception.code)
self.response.out.write(self._errors)
else:
self.response.set_status(500)
def _track_call_defer(self, api_action, api_details=''):
deferred.defer(track_call, api_action, api_details, self.x_tba_app_id, _queue="api-track-call")
def _validate_tba_app_id(self):
"""
Tests the presence of a X-TBA-App-Id header or URL param.
"""
self.x_tba_app_id = self.request.headers.get("X-TBA-App-Id")
if self.x_tba_app_id is None:
self.x_tba_app_id = self.request.get('X-TBA-App-Id')
logging.info("X-TBA-App-ID: {}".format(self.x_tba_app_id))
if not self.x_tba_app_id:
self._errors = json.dumps({"Error": "X-TBA-App-Id is a required header or URL param. Please see http://www.thebluealliance.com/apidocs for more info."})
self.abort(400)
x_tba_app_id_parts = self.x_tba_app_id.split(':')
if len(x_tba_app_id_parts) != 3 or any(len(part) == 0 for part in x_tba_app_id_parts):
self._errors = json.dumps({"Error": "X-TBA-App-Id must follow a specific format. Please see http://www.thebluealliance.com/apidocs for more info."})
self.abort(400)
class CsvTeamsAll(MainApiHandler):
"""
Outputs a CSV of all team information in the database, designed for other apps to bulk-import data.
"""
def get(self):
self._validate_tba_app_id()
memcache_key = "csv_teams_all"
output = memcache.get(memcache_key)
if output is None:
team_keys = Team.query().order(Team.team_number).fetch(10000, keys_only=True)
team_futures = ndb.get_multi_async(team_keys)
sio = StringIO.StringIO()
writer = csv.writer(sio, delimiter=',')
writer.writerow(['team_number','name','nickname','location','website'])
for team_future in team_futures:
team = team_future.get_result()
row = [team.team_number, team.name, team.nickname, team.location, team.website]
row_utf8 = [unicode(e).encode('utf-8') for e in row]
writer.writerow(row_utf8)
output = sio.getvalue()
if tba_config.CONFIG["memcache"]:
memcache.set(memcache_key, output, 86400)
self.response.headers["content-type"] = "text/csv"
self.response.out.write(output)
self._track_call_defer('teams/list')
|
mit
|
[
646,
7392,
199,
646,
2022,
199,
646,
2050,
199,
646,
5228,
199,
646,
747,
199,
646,
4011,
199,
646,
5377,
199,
646,
24812,
18,
199,
199,
504,
2197,
492,
2197,
199,
199,
504,
6233,
14,
15358,
14,
1246,
492,
21598,
12,
7629,
29429,
199,
504,
6233,
14,
15358,
14,
832,
492,
12309,
12,
23788,
199,
504,
6233,
14,
15358,
14,
832,
14,
22632,
492,
1978,
421,
199,
646,
307,
2470,
63,
888,
199,
504,
10897,
14,
1246,
63,
3676,
492,
13986,
4433,
199,
199,
504,
1709,
14,
1430,
492,
6763,
199,
504,
1709,
14,
2124,
1391,
492,
11666,
1391,
199,
504,
1709,
14,
5969,
492,
11682,
421,
199,
3,
1202,
367,
12309,
1240,
199,
318,
4426,
63,
1250,
8,
1246,
63,
1287,
12,
2986,
63,
5087,
12,
671,
63,
84,
2470,
63,
571,
63,
344,
304,
272,
30159,
63,
344,
275,
11666,
1391,
14,
362,
63,
991,
63,
344,
480,
3098,
63,
20211,
14,
344,
531,
272,
340,
30159,
63,
344,
365,
488,
26,
267,
2050,
14,
3764,
480,
7718,
4770,
1391,
26,
6233,
63,
20211,
14,
344,
14,
6855,
1133,
4426,
3261,
4503,
2685,
272,
587,
26,
267,
9173,
12827,
63,
31158,
28267,
21174,
63,
998,
275,
30159,
63,
344,
14,
4407,
459,
24243,
63,
31158,
28267,
21174,
63,
998,
418,
267,
1862,
275,
4011,
14,
10738,
2561,
288,
283,
86,
356,
413,
12,
288,
283,
5700,
356,
9173,
12827,
63,
31158,
28267,
21174,
63,
998,
12,
288,
283,
7504,
356,
5377,
14,
2580,
19,
8,
2580,
14,
13001,
63,
56,
5783,
12,
620,
8,
88,
63,
84,
2470,
63,
571,
63,
344,
1826,
288,
283,
84,
356,
283,
1430,
297,
288,
283,
825,
356,
283,
1246,
297,
288,
283,
4489,
356,
2986,
63,
1287,
12,
288,
283,
352,
356,
2986,
63,
5087,
12,
288,
283,
2866,
17,
356,
671,
63,
84,
2470,
63,
571,
63,
344,
12,
221,
327,
3537,
6240,
413,
288,
283,
8445,
356,
413,
12,
288,
283,
551,
356,
283,
500,
297,
221,
327,
25983,
15161,
2351,
370,
1284,
267,
3828,
398,
327,
10729,
1536,
314,
1240,
267,
30159,
63,
633,
275,
283,
1014,
921,
1544,
14,
3098,
13,
20211,
14,
957,
15,
7112,
25790,
83,
7,
450,
1862,
267,
7629,
29429,
14,
3535,
8,
288,
1166,
29,
20211,
63,
633,
12,
288,
1083,
29,
300,
29429,
14,
2970,
12,
288,
23081,
29,
709,
12,
267,
776,
421,
199,
533,
13986,
19727,
7506,
8,
22632,
18,
14,
11149,
304,
339,
347,
636,
826,
721,
277,
12,
1056,
12,
1177,
304,
267,
291,
14,
8489,
8,
1069,
12,
1177,
9,
267,
291,
14,
1310,
14,
2139,
14,
525,
63,
1291,
480,
1317,
13,
466,
401,
298,
3578,
15,
1001,
531,
339,
347,
664,
8,
277,
12,
27574,
267,
291,
14,
1310,
14,
548,
14,
952,
8,
1001,
14,
4180,
6333,
547,
582,
298,
2822,
402,
17474,
14,
499,
6900,
12,
373,
17,
402,
314,
377,
4134,
3261,
965,
2757,
5906,
14,
7754,
1937,
1455,
921,
1544,
14,
1589,
6304,
279,
3636,
14,
957,
15,
27703,
14851,
367,
1655,
2256,
2122,
12466,
267,
291,
14,
1310,
14,
2139,
459,
4437,
13,
3717,
418,
275,
298,
3455,
12,
1390,
13,
474,
2458,
68,
2,
450,
334,
2259,
10,
2259,
10,
1194,
10,
23,
9,
221,
327,
413,
8620,
267,
291,
14,
1310,
14,
2139,
459,
48,
9717,
418,
275,
283,
9885,
7,
421,
199,
3,
3390,
26,
16711,
13627,
367,
314,
3261,
10986,
315,
13986,
4433,
199,
533,
11298,
7394,
2461,
8,
22632,
18,
14,
11149,
304,
339,
347,
636,
826,
721,
277,
12,
1056,
12,
1177,
304,
267,
327,
14012,
370,
8265,
282,
24812,
18,
1256,
267,
291,
14,
8489,
8,
1069,
12,
1177,
9,
267,
291,
14,
1310,
14,
2139,
14,
525,
63,
1291,
480,
1317,
13,
466,
401,
298,
3578,
15,
1001,
531,
267,
291,
14,
1310,
14,
2139,
459,
3946,
13,
3717,
13,
7852,
13,
12834,
418,
275,
13626,
339,
347,
2429,
63,
1971,
8,
277,
12,
1919,
12,
3105,
304,
267,
408,
267,
8690,
376,
3101,
1919,
436,
5965,
2218,
734,
282,
1177,
14,
267,
12295,
701,
24812,
1380,
12004,
342,
365,
2797,
12,
20922,
1233,
3178,
2206,
14,
267,
408,
267,
2050,
14,
815,
8,
1971,
9,
267,
340,
1228,
8,
1971,
12,
24812,
18,
14,
26871,
304,
288,
291,
14,
1310,
14,
409,
63,
1205,
8,
1971,
14,
600,
9,
288,
291,
14,
1310,
14,
548,
14,
952,
8,
277,
423,
2550,
9,
267,
587,
26,
288,
291,
14,
1310,
14,
409,
63,
1205,
8,
5783,
9,
339,
347,
485,
3885,
63,
1250,
63,
11610,
8,
277,
12,
2986,
63,
1287,
12,
2986,
63,
5087,
9280,
267,
12309,
14,
11610,
8,
3885,
63,
1250,
12,
2986,
63,
1287,
12,
2986,
63,
5087,
12,
291,
14,
88,
63,
84,
2470,
63,
571,
63,
344,
12,
485,
1825,
628,
1246,
13,
3885,
13,
1250,
531,
339,
347,
485,
3502,
63,
84,
2470,
63,
571,
63,
344,
8,
277,
304,
267,
408,
267,
6496,
314,
20024,
402,
282,
1323,
13,
52,
4134,
13,
2640,
13,
1304,
1406,
503,
2851,
1215,
14,
267,
408,
267,
291,
14,
88,
63,
84,
2470,
63,
571,
63,
344,
275,
291,
14,
1069,
14,
2139,
14,
362,
480,
56,
13,
52,
4134,
13,
2640,
13,
1304,
531,
267,
340,
291,
14,
88,
63,
84,
2470,
63,
571,
63,
344,
365,
488,
26,
288,
291,
14,
88,
63,
84,
2470,
63,
571,
63,
344,
275,
291,
14,
1069,
14,
362,
360,
56,
13,
52,
4134,
13,
2640,
13,
1304,
358,
398,
2050,
14,
815,
480,
56,
13,
52,
4134,
13,
2640,
13,
998,
26,
8352,
908,
8,
277,
14,
88,
63,
84,
2470,
63,
571,
63,
344,
430,
267,
340,
440,
291,
14,
88,
63,
84,
2470,
63,
571,
63,
344,
26,
288,
291,
423,
2550,
275,
2022,
14,
4180,
6333,
547,
582,
298,
56,
13,
52,
4134,
13,
2640,
13,
1304,
365,
282,
1415,
1406,
503,
2851,
1215,
14,
7754,
1937,
1455,
921,
1544,
14,
1589,
6304,
279,
3636,
14,
957,
15,
27703,
14851,
367,
1655,
2256,
2122,
1552,
288,
291,
14,
13845,
8,
5303,
9,
398,
671,
63,
84,
2470,
63,
571,
63,
344,
63,
4181,
275,
291,
14,
88,
63,
84
] |
[
7392,
199,
646,
2022,
199,
646,
2050,
199,
646,
5228,
199,
646,
747,
199,
646,
4011,
199,
646,
5377,
199,
646,
24812,
18,
199,
199,
504,
2197,
492,
2197,
199,
199,
504,
6233,
14,
15358,
14,
1246,
492,
21598,
12,
7629,
29429,
199,
504,
6233,
14,
15358,
14,
832,
492,
12309,
12,
23788,
199,
504,
6233,
14,
15358,
14,
832,
14,
22632,
492,
1978,
421,
199,
646,
307,
2470,
63,
888,
199,
504,
10897,
14,
1246,
63,
3676,
492,
13986,
4433,
199,
199,
504,
1709,
14,
1430,
492,
6763,
199,
504,
1709,
14,
2124,
1391,
492,
11666,
1391,
199,
504,
1709,
14,
5969,
492,
11682,
421,
199,
3,
1202,
367,
12309,
1240,
199,
318,
4426,
63,
1250,
8,
1246,
63,
1287,
12,
2986,
63,
5087,
12,
671,
63,
84,
2470,
63,
571,
63,
344,
304,
272,
30159,
63,
344,
275,
11666,
1391,
14,
362,
63,
991,
63,
344,
480,
3098,
63,
20211,
14,
344,
531,
272,
340,
30159,
63,
344,
365,
488,
26,
267,
2050,
14,
3764,
480,
7718,
4770,
1391,
26,
6233,
63,
20211,
14,
344,
14,
6855,
1133,
4426,
3261,
4503,
2685,
272,
587,
26,
267,
9173,
12827,
63,
31158,
28267,
21174,
63,
998,
275,
30159,
63,
344,
14,
4407,
459,
24243,
63,
31158,
28267,
21174,
63,
998,
418,
267,
1862,
275,
4011,
14,
10738,
2561,
288,
283,
86,
356,
413,
12,
288,
283,
5700,
356,
9173,
12827,
63,
31158,
28267,
21174,
63,
998,
12,
288,
283,
7504,
356,
5377,
14,
2580,
19,
8,
2580,
14,
13001,
63,
56,
5783,
12,
620,
8,
88,
63,
84,
2470,
63,
571,
63,
344,
1826,
288,
283,
84,
356,
283,
1430,
297,
288,
283,
825,
356,
283,
1246,
297,
288,
283,
4489,
356,
2986,
63,
1287,
12,
288,
283,
352,
356,
2986,
63,
5087,
12,
288,
283,
2866,
17,
356,
671,
63,
84,
2470,
63,
571,
63,
344,
12,
221,
327,
3537,
6240,
413,
288,
283,
8445,
356,
413,
12,
288,
283,
551,
356,
283,
500,
297,
221,
327,
25983,
15161,
2351,
370,
1284,
267,
3828,
398,
327,
10729,
1536,
314,
1240,
267,
30159,
63,
633,
275,
283,
1014,
921,
1544,
14,
3098,
13,
20211,
14,
957,
15,
7112,
25790,
83,
7,
450,
1862,
267,
7629,
29429,
14,
3535,
8,
288,
1166,
29,
20211,
63,
633,
12,
288,
1083,
29,
300,
29429,
14,
2970,
12,
288,
23081,
29,
709,
12,
267,
776,
421,
199,
533,
13986,
19727,
7506,
8,
22632,
18,
14,
11149,
304,
339,
347,
636,
826,
721,
277,
12,
1056,
12,
1177,
304,
267,
291,
14,
8489,
8,
1069,
12,
1177,
9,
267,
291,
14,
1310,
14,
2139,
14,
525,
63,
1291,
480,
1317,
13,
466,
401,
298,
3578,
15,
1001,
531,
339,
347,
664,
8,
277,
12,
27574,
267,
291,
14,
1310,
14,
548,
14,
952,
8,
1001,
14,
4180,
6333,
547,
582,
298,
2822,
402,
17474,
14,
499,
6900,
12,
373,
17,
402,
314,
377,
4134,
3261,
965,
2757,
5906,
14,
7754,
1937,
1455,
921,
1544,
14,
1589,
6304,
279,
3636,
14,
957,
15,
27703,
14851,
367,
1655,
2256,
2122,
12466,
267,
291,
14,
1310,
14,
2139,
459,
4437,
13,
3717,
418,
275,
298,
3455,
12,
1390,
13,
474,
2458,
68,
2,
450,
334,
2259,
10,
2259,
10,
1194,
10,
23,
9,
221,
327,
413,
8620,
267,
291,
14,
1310,
14,
2139,
459,
48,
9717,
418,
275,
283,
9885,
7,
421,
199,
3,
3390,
26,
16711,
13627,
367,
314,
3261,
10986,
315,
13986,
4433,
199,
533,
11298,
7394,
2461,
8,
22632,
18,
14,
11149,
304,
339,
347,
636,
826,
721,
277,
12,
1056,
12,
1177,
304,
267,
327,
14012,
370,
8265,
282,
24812,
18,
1256,
267,
291,
14,
8489,
8,
1069,
12,
1177,
9,
267,
291,
14,
1310,
14,
2139,
14,
525,
63,
1291,
480,
1317,
13,
466,
401,
298,
3578,
15,
1001,
531,
267,
291,
14,
1310,
14,
2139,
459,
3946,
13,
3717,
13,
7852,
13,
12834,
418,
275,
13626,
339,
347,
2429,
63,
1971,
8,
277,
12,
1919,
12,
3105,
304,
267,
408,
267,
8690,
376,
3101,
1919,
436,
5965,
2218,
734,
282,
1177,
14,
267,
12295,
701,
24812,
1380,
12004,
342,
365,
2797,
12,
20922,
1233,
3178,
2206,
14,
267,
408,
267,
2050,
14,
815,
8,
1971,
9,
267,
340,
1228,
8,
1971,
12,
24812,
18,
14,
26871,
304,
288,
291,
14,
1310,
14,
409,
63,
1205,
8,
1971,
14,
600,
9,
288,
291,
14,
1310,
14,
548,
14,
952,
8,
277,
423,
2550,
9,
267,
587,
26,
288,
291,
14,
1310,
14,
409,
63,
1205,
8,
5783,
9,
339,
347,
485,
3885,
63,
1250,
63,
11610,
8,
277,
12,
2986,
63,
1287,
12,
2986,
63,
5087,
9280,
267,
12309,
14,
11610,
8,
3885,
63,
1250,
12,
2986,
63,
1287,
12,
2986,
63,
5087,
12,
291,
14,
88,
63,
84,
2470,
63,
571,
63,
344,
12,
485,
1825,
628,
1246,
13,
3885,
13,
1250,
531,
339,
347,
485,
3502,
63,
84,
2470,
63,
571,
63,
344,
8,
277,
304,
267,
408,
267,
6496,
314,
20024,
402,
282,
1323,
13,
52,
4134,
13,
2640,
13,
1304,
1406,
503,
2851,
1215,
14,
267,
408,
267,
291,
14,
88,
63,
84,
2470,
63,
571,
63,
344,
275,
291,
14,
1069,
14,
2139,
14,
362,
480,
56,
13,
52,
4134,
13,
2640,
13,
1304,
531,
267,
340,
291,
14,
88,
63,
84,
2470,
63,
571,
63,
344,
365,
488,
26,
288,
291,
14,
88,
63,
84,
2470,
63,
571,
63,
344,
275,
291,
14,
1069,
14,
362,
360,
56,
13,
52,
4134,
13,
2640,
13,
1304,
358,
398,
2050,
14,
815,
480,
56,
13,
52,
4134,
13,
2640,
13,
998,
26,
8352,
908,
8,
277,
14,
88,
63,
84,
2470,
63,
571,
63,
344,
430,
267,
340,
440,
291,
14,
88,
63,
84,
2470,
63,
571,
63,
344,
26,
288,
291,
423,
2550,
275,
2022,
14,
4180,
6333,
547,
582,
298,
56,
13,
52,
4134,
13,
2640,
13,
1304,
365,
282,
1415,
1406,
503,
2851,
1215,
14,
7754,
1937,
1455,
921,
1544,
14,
1589,
6304,
279,
3636,
14,
957,
15,
27703,
14851,
367,
1655,
2256,
2122,
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
] |
mfraezz/osf.io
|
api/actions/serializers.py
|
5
|
8933
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from rest_framework import generics
from rest_framework import serializers as ser
from api.base import utils
from api.base.exceptions import Conflict
from api.base.exceptions import JSONAPIAttributeException
from api.base.serializers import get_meta_type
from api.base.serializers import JSONAPISerializer
from api.base.serializers import LinksField
from api.base.serializers import RelationshipField
from api.base.serializers import HideIfProviderCommentsAnonymous
from api.base.serializers import HideIfProviderCommentsPrivate
from api.requests.serializers import PreprintRequestSerializer
from osf.exceptions import InvalidTriggerError
from osf.models import Preprint, NodeRequest, PreprintRequest
from osf.utils.workflows import DefaultStates, DefaultTriggers, ReviewStates, ReviewTriggers
from osf.utils import permissions
class ReviewableCountsRelationshipField(RelationshipField):
def __init__(self, *args, **kwargs):
kwargs['related_meta'] = kwargs.get('related_meta') or {}
if 'include_state_counts' not in kwargs['related_meta']:
kwargs['related_meta']['include_state_counts'] = True
super(ReviewableCountsRelationshipField, self).__init__(*args, **kwargs)
def get_meta_information(self, metadata, provider):
# Clone metadata because its mutability is questionable
metadata = dict(metadata or {})
# Make counts opt-in
show_counts = utils.is_truthy(self.context['request'].query_params.get('related_counts', False))
# Only include counts on detail routes
is_detail = self.context.get('view') and not isinstance(self.context['view'], generics.ListAPIView)
# Weird hack to avoid being called twice
# get_meta_information is called with both self.related_meta and self.self_meta.
# `is` could probably be used here but this seems more comprehensive.
is_related_meta = metadata.pop('include_state_counts', False)
if show_counts and is_detail and is_related_meta:
# Finally, require users to have view_actions permissions
auth = utils.get_user_auth(self.context['request'])
if auth and auth.logged_in and auth.user.has_perm('view_actions', provider):
metadata.update(provider.get_reviewable_state_counts())
return super(ReviewableCountsRelationshipField, self).get_meta_information(metadata, provider)
class TargetRelationshipField(RelationshipField):
_target_class = None
def __init__(self, *args, **kwargs):
self._target_class = kwargs.pop('target_class', None)
super(TargetRelationshipField, self).__init__(*args, **kwargs)
@property
def TargetClass(self):
if self._target_class:
return self._target_class
raise NotImplementedError()
def get_object(self, object_id):
return self.TargetClass.load(object_id)
def to_internal_value(self, data):
target = self.get_object(data)
return {'target': target}
class PreprintRequestTargetRelationshipField(TargetRelationshipField):
def to_representation(self, value):
ret = super(TargetRelationshipField, self).to_representation(value)
ret['data']['type'] = get_meta_type(
PreprintRequestSerializer,
self.context.get('request'),
)
return ret
class BaseActionSerializer(JSONAPISerializer):
filterable_fields = frozenset([
'id',
'trigger',
'from_state',
'to_state',
'date_created',
'date_modified',
'target',
])
id = ser.CharField(source='_id', read_only=True)
trigger = ser.ChoiceField(choices=DefaultTriggers.choices())
comment = ser.CharField(max_length=65535, required=False)
from_state = ser.ChoiceField(choices=DefaultStates.choices(), read_only=True)
to_state = ser.ChoiceField(choices=DefaultStates.choices(), read_only=True)
date_created = ser.DateTimeField(source='created', read_only=True)
date_modified = ser.DateTimeField(source='modified', read_only=True)
auto = ser.BooleanField(read_only=True)
creator = RelationshipField(
read_only=True,
related_view='users:user-detail',
related_view_kwargs={'user_id': '<creator._id>'},
filter_key='creator__guids___id',
always_embed=True,
)
links = LinksField(
{
'self': 'get_action_url',
},
)
def get_absolute_url(self, obj):
return self.get_action_url(obj)
def get_action_url(self, obj):
return utils.absolute_reverse('actions:action-detail', kwargs={'action_id': obj._id, 'version': self.context['request'].parser_context['kwargs']['version']})
def create(self, validated_data):
trigger = validated_data.pop('trigger')
user = validated_data.pop('user')
target = validated_data.pop('target')
comment = validated_data.pop('comment', '')
permissions = validated_data.pop('permissions', '')
visible = validated_data.pop('visible', '')
try:
if trigger == DefaultTriggers.ACCEPT.value:
return target.run_accept(user=user, comment=comment, permissions=permissions, visible=visible)
if trigger == DefaultTriggers.REJECT.value:
return target.run_reject(user, comment)
if trigger == DefaultTriggers.EDIT_COMMENT.value:
return target.run_edit_comment(user, comment)
if trigger == DefaultTriggers.SUBMIT.value:
return target.run_submit(user)
except InvalidTriggerError as e:
# Invalid transition from the current state
raise Conflict(str(e))
else:
raise JSONAPIAttributeException(attribute='trigger', detail='Invalid trigger.')
class Meta:
type_ = 'actions'
abstract = True
class ReviewActionSerializer(BaseActionSerializer):
class Meta:
type_ = 'review-actions'
filterable_fields = frozenset([
'id',
'trigger',
'from_state',
'to_state',
'date_created',
'date_modified',
'provider',
'target',
])
comment = HideIfProviderCommentsPrivate(ser.CharField(max_length=65535, required=False))
trigger = ser.ChoiceField(choices=ReviewTriggers.choices())
from_state = ser.ChoiceField(choices=ReviewStates.choices(), read_only=True)
to_state = ser.ChoiceField(choices=ReviewStates.choices(), read_only=True)
provider = RelationshipField(
read_only=True,
related_view='providers:preprint-providers:preprint-provider-detail',
related_view_kwargs={'provider_id': '<target.provider._id>'},
filter_key='target__provider___id',
)
creator = HideIfProviderCommentsAnonymous(RelationshipField(
read_only=True,
related_view='users:user-detail',
related_view_kwargs={'user_id': '<creator._id>'},
filter_key='creator__guids___id',
always_embed=True,
))
target = TargetRelationshipField(
target_class=Preprint,
read_only=False,
required=True,
related_view='preprints:preprint-detail',
related_view_kwargs={'preprint_id': '<target._id>'},
filter_key='target__guids___id',
)
def create(self, validated_data):
trigger = validated_data.get('trigger')
if trigger != ReviewTriggers.WITHDRAW.value:
return super(ReviewActionSerializer, self).create(validated_data)
user = validated_data.pop('user')
target = validated_data.pop('target')
comment = validated_data.pop('comment', '')
try:
return target.run_withdraw(user=user, comment=comment)
except InvalidTriggerError as e:
# Invalid transition from the current state
raise Conflict(str(e))
else:
raise JSONAPIAttributeException(attribute='trigger', detail='Invalid trigger.')
class NodeRequestActionSerializer(BaseActionSerializer):
class Meta:
type_ = 'node-request-actions'
target = TargetRelationshipField(
target_class=NodeRequest,
read_only=False,
required=True,
related_view='requests:request-detail',
related_view_kwargs={'request_id': '<target._id>'},
)
permissions = ser.ChoiceField(choices=permissions.API_CONTRIBUTOR_PERMISSIONS, required=False)
visible = ser.BooleanField(default=True, required=False)
class PreprintRequestActionSerializer(BaseActionSerializer):
class Meta:
type_ = 'preprint-request-actions'
target = PreprintRequestTargetRelationshipField(
target_class=PreprintRequest,
read_only=False,
required=True,
related_view='requests:request-detail',
related_view_kwargs={'request_id': '<target._id>'},
)
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
4618,
63,
4857,
492,
1519,
2932,
199,
504,
4618,
63,
4857,
492,
12506,
465,
8926,
199,
199,
504,
2986,
14,
1095,
492,
3778,
199,
504,
2986,
14,
1095,
14,
3924,
492,
32539,
6960,
199,
504,
2986,
14,
1095,
14,
3924,
492,
4840,
3735,
1646,
1726,
199,
504,
2986,
14,
1095,
14,
12844,
492,
664,
63,
2024,
63,
466,
199,
504,
2986,
14,
1095,
14,
12844,
492,
4840,
1282,
1311,
281,
2380,
1793,
199,
504,
2986,
14,
1095,
14,
12844,
492,
10967,
83,
792,
199,
504,
2986,
14,
1095,
14,
12844,
492,
23230,
3319,
792,
199,
504,
2986,
14,
1095,
14,
12844,
492,
869,
2655,
3917,
6663,
18929,
23902,
199,
504,
2986,
14,
1095,
14,
12844,
492,
869,
2655,
3917,
6663,
18929,
12185,
199,
504,
2986,
14,
6615,
14,
12844,
492,
510,
1155,
672,
2017,
7299,
199,
504,
747,
70,
14,
3924,
492,
6378,
16276,
547,
199,
504,
747,
70,
14,
992,
492,
510,
1155,
672,
12,
5013,
2017,
12,
510,
1155,
672,
2017,
199,
504,
747,
70,
14,
1208,
14,
25964,
492,
3758,
18010,
12,
3758,
16276,
83,
12,
26705,
18010,
12,
26705,
16276,
83,
199,
504,
747,
70,
14,
1208,
492,
3443,
421,
199,
533,
26705,
461,
23209,
21096,
792,
8,
21096,
792,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
2074,
459,
2407,
63,
2024,
418,
275,
2074,
14,
362,
360,
2407,
63,
2024,
358,
503,
1052,
267,
340,
283,
2613,
63,
929,
63,
6851,
7,
440,
315,
2074,
459,
2407,
63,
2024,
2565,
288,
2074,
459,
2407,
63,
2024,
2545,
2613,
63,
929,
63,
6851,
418,
275,
715,
267,
1613,
8,
21000,
461,
23209,
21096,
792,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
664,
63,
2024,
63,
11697,
8,
277,
12,
3341,
12,
5022,
304,
267,
327,
8465,
368,
3341,
2952,
2399,
8567,
3616,
365,
7894,
461,
267,
3341,
275,
1211,
8,
2343,
503,
5009,
398,
327,
4155,
8242,
2450,
13,
262,
267,
2498,
63,
6851,
275,
3778,
14,
374,
63,
17167,
89,
8,
277,
14,
1100,
459,
1069,
2278,
1131,
63,
1162,
14,
362,
360,
2407,
63,
6851,
297,
756,
430,
267,
327,
5972,
2387,
8242,
641,
10093,
15777,
267,
365,
63,
5506,
275,
291,
14,
1100,
14,
362,
360,
1345,
358,
436,
440,
1228,
8,
277,
14,
1100,
459,
1345,
995,
1519,
2932,
14,
1296,
25778,
9,
267,
327,
2136,
5428,
11176,
370,
5126,
3769,
2797,
13373,
267,
327,
664,
63,
2024,
63,
11697,
365,
2797,
543,
3865,
291,
14,
2407,
63,
2024,
436,
291,
14,
277,
63,
2024,
14,
267,
327,
658,
374,
64,
4293,
8646,
506,
1202,
2348,
1325,
642,
12237,
1655,
1013,
22868,
3398,
14,
267,
365,
63,
2407,
63,
2024,
275,
3341,
14,
1935,
360,
2613,
63,
929,
63,
6851,
297,
756,
9,
398,
340,
2498,
63,
6851,
436,
365,
63,
5506,
436,
365,
63,
2407,
63,
2024,
26,
288,
327,
19177,
12,
4409,
4390,
370,
1172,
2455,
63,
3723,
3443,
288,
1790,
275,
3778,
14,
362,
63,
751,
63,
1178,
8,
277,
14,
1100,
459,
1069,
1105,
288,
340,
1790,
436,
1790,
14,
12419,
63,
262,
436,
1790,
14,
751,
14,
1989,
63,
8220,
360,
1345,
63,
3723,
297,
5022,
304,
355,
3341,
14,
873,
8,
3780,
14,
362,
63,
8578,
461,
63,
929,
63,
6851,
1012,
398,
372,
1613,
8,
21000,
461,
23209,
21096,
792,
12,
291,
680,
362,
63,
2024,
63,
11697,
8,
2343,
12,
5022,
9,
421,
199,
533,
10256,
21096,
792,
8,
21096,
792,
304,
272,
485,
1375,
63,
533,
275,
488,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
423,
1375,
63,
533,
275,
2074,
14,
1935,
360,
1375,
63,
533,
297,
488,
9,
267,
1613,
8,
4277,
21096,
792,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
768,
1829,
272,
347,
10256,
2543,
8,
277,
304,
267,
340,
291,
423,
1375,
63,
533,
26,
288,
372,
291,
423,
1375,
63,
533,
267,
746,
4279,
342,
339,
347,
664,
63,
785,
8,
277,
12,
909,
63,
344,
304,
267,
372,
291,
14,
4277,
2543,
14,
912,
8,
785,
63,
344,
9,
339,
347,
370,
63,
4672,
63,
585,
8,
277,
12,
666,
304,
267,
1347,
275,
291,
14,
362,
63,
785,
8,
576,
9,
267,
372,
791,
1375,
356,
1347,
93,
421,
199,
533,
510,
1155,
672,
2017,
4277,
21096,
792,
8,
4277,
21096,
792,
304,
272,
347,
370,
63,
22903,
8,
277,
12,
574,
304,
267,
2203,
275,
1613,
8,
4277,
21096,
792,
12,
291,
680,
475,
63,
22903,
8,
585,
9,
267,
2203,
459,
576,
2545,
466,
418,
275,
664,
63,
2024,
63,
466,
8,
288,
510,
1155,
672,
2017,
7299,
12,
288,
291,
14,
1100,
14,
362,
360,
1069,
659,
267,
776,
267,
372,
2203,
199,
199,
533,
3523,
3310,
7299,
8,
6243,
1282,
1311,
281,
2380,
1793,
304,
272,
1794,
13048,
63,
955,
275,
9522,
779,
267,
283,
344,
297,
267,
283,
7631,
297,
267,
283,
504,
63,
929,
297,
267,
283,
475,
63,
929,
297,
267,
283,
602,
63,
3966,
297,
267,
283,
602,
63,
5540,
297,
267,
283,
1375,
297,
272,
4794,
339,
1305,
275,
8926,
14,
2183,
8,
1365,
17574,
344,
297,
1586,
63,
2118,
29,
549,
9,
339,
6804,
275,
8926,
14,
15792,
8,
4577,
29,
2698,
16276,
83,
14,
4577,
1012,
339,
3721,
275,
8926,
14,
2183,
8,
988,
63,
1267,
29,
26439,
12,
1415,
29,
797,
9,
339,
687,
63,
929,
275,
8926,
14,
15792,
8,
4577,
29,
2698,
18010,
14,
4577,
1062,
1586,
63,
2118,
29,
549,
9,
272,
370,
63,
929,
275,
8926,
14,
15792,
8,
4577,
29,
2698,
18010,
14,
4577,
1062,
1586,
63,
2118,
29,
549,
9,
339,
1434,
63,
3966,
275,
8926,
14,
4626,
8,
1365,
534,
3966,
297,
1586,
63,
2118,
29,
549,
9,
272,
1434,
63,
5540,
275,
8926,
14,
4626,
8,
1365,
534,
5540,
297,
1586,
63,
2118,
29,
549,
9,
272,
2599,
275,
8926,
14,
5036,
8,
739,
63,
2118,
29,
549,
9,
339,
14875,
275,
23230,
3319
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
4618,
63,
4857,
492,
1519,
2932,
199,
504,
4618,
63,
4857,
492,
12506,
465,
8926,
199,
199,
504,
2986,
14,
1095,
492,
3778,
199,
504,
2986,
14,
1095,
14,
3924,
492,
32539,
6960,
199,
504,
2986,
14,
1095,
14,
3924,
492,
4840,
3735,
1646,
1726,
199,
504,
2986,
14,
1095,
14,
12844,
492,
664,
63,
2024,
63,
466,
199,
504,
2986,
14,
1095,
14,
12844,
492,
4840,
1282,
1311,
281,
2380,
1793,
199,
504,
2986,
14,
1095,
14,
12844,
492,
10967,
83,
792,
199,
504,
2986,
14,
1095,
14,
12844,
492,
23230,
3319,
792,
199,
504,
2986,
14,
1095,
14,
12844,
492,
869,
2655,
3917,
6663,
18929,
23902,
199,
504,
2986,
14,
1095,
14,
12844,
492,
869,
2655,
3917,
6663,
18929,
12185,
199,
504,
2986,
14,
6615,
14,
12844,
492,
510,
1155,
672,
2017,
7299,
199,
504,
747,
70,
14,
3924,
492,
6378,
16276,
547,
199,
504,
747,
70,
14,
992,
492,
510,
1155,
672,
12,
5013,
2017,
12,
510,
1155,
672,
2017,
199,
504,
747,
70,
14,
1208,
14,
25964,
492,
3758,
18010,
12,
3758,
16276,
83,
12,
26705,
18010,
12,
26705,
16276,
83,
199,
504,
747,
70,
14,
1208,
492,
3443,
421,
199,
533,
26705,
461,
23209,
21096,
792,
8,
21096,
792,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
2074,
459,
2407,
63,
2024,
418,
275,
2074,
14,
362,
360,
2407,
63,
2024,
358,
503,
1052,
267,
340,
283,
2613,
63,
929,
63,
6851,
7,
440,
315,
2074,
459,
2407,
63,
2024,
2565,
288,
2074,
459,
2407,
63,
2024,
2545,
2613,
63,
929,
63,
6851,
418,
275,
715,
267,
1613,
8,
21000,
461,
23209,
21096,
792,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
664,
63,
2024,
63,
11697,
8,
277,
12,
3341,
12,
5022,
304,
267,
327,
8465,
368,
3341,
2952,
2399,
8567,
3616,
365,
7894,
461,
267,
3341,
275,
1211,
8,
2343,
503,
5009,
398,
327,
4155,
8242,
2450,
13,
262,
267,
2498,
63,
6851,
275,
3778,
14,
374,
63,
17167,
89,
8,
277,
14,
1100,
459,
1069,
2278,
1131,
63,
1162,
14,
362,
360,
2407,
63,
6851,
297,
756,
430,
267,
327,
5972,
2387,
8242,
641,
10093,
15777,
267,
365,
63,
5506,
275,
291,
14,
1100,
14,
362,
360,
1345,
358,
436,
440,
1228,
8,
277,
14,
1100,
459,
1345,
995,
1519,
2932,
14,
1296,
25778,
9,
267,
327,
2136,
5428,
11176,
370,
5126,
3769,
2797,
13373,
267,
327,
664,
63,
2024,
63,
11697,
365,
2797,
543,
3865,
291,
14,
2407,
63,
2024,
436,
291,
14,
277,
63,
2024,
14,
267,
327,
658,
374,
64,
4293,
8646,
506,
1202,
2348,
1325,
642,
12237,
1655,
1013,
22868,
3398,
14,
267,
365,
63,
2407,
63,
2024,
275,
3341,
14,
1935,
360,
2613,
63,
929,
63,
6851,
297,
756,
9,
398,
340,
2498,
63,
6851,
436,
365,
63,
5506,
436,
365,
63,
2407,
63,
2024,
26,
288,
327,
19177,
12,
4409,
4390,
370,
1172,
2455,
63,
3723,
3443,
288,
1790,
275,
3778,
14,
362,
63,
751,
63,
1178,
8,
277,
14,
1100,
459,
1069,
1105,
288,
340,
1790,
436,
1790,
14,
12419,
63,
262,
436,
1790,
14,
751,
14,
1989,
63,
8220,
360,
1345,
63,
3723,
297,
5022,
304,
355,
3341,
14,
873,
8,
3780,
14,
362,
63,
8578,
461,
63,
929,
63,
6851,
1012,
398,
372,
1613,
8,
21000,
461,
23209,
21096,
792,
12,
291,
680,
362,
63,
2024,
63,
11697,
8,
2343,
12,
5022,
9,
421,
199,
533,
10256,
21096,
792,
8,
21096,
792,
304,
272,
485,
1375,
63,
533,
275,
488,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
423,
1375,
63,
533,
275,
2074,
14,
1935,
360,
1375,
63,
533,
297,
488,
9,
267,
1613,
8,
4277,
21096,
792,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
768,
1829,
272,
347,
10256,
2543,
8,
277,
304,
267,
340,
291,
423,
1375,
63,
533,
26,
288,
372,
291,
423,
1375,
63,
533,
267,
746,
4279,
342,
339,
347,
664,
63,
785,
8,
277,
12,
909,
63,
344,
304,
267,
372,
291,
14,
4277,
2543,
14,
912,
8,
785,
63,
344,
9,
339,
347,
370,
63,
4672,
63,
585,
8,
277,
12,
666,
304,
267,
1347,
275,
291,
14,
362,
63,
785,
8,
576,
9,
267,
372,
791,
1375,
356,
1347,
93,
421,
199,
533,
510,
1155,
672,
2017,
4277,
21096,
792,
8,
4277,
21096,
792,
304,
272,
347,
370,
63,
22903,
8,
277,
12,
574,
304,
267,
2203,
275,
1613,
8,
4277,
21096,
792,
12,
291,
680,
475,
63,
22903,
8,
585,
9,
267,
2203,
459,
576,
2545,
466,
418,
275,
664,
63,
2024,
63,
466,
8,
288,
510,
1155,
672,
2017,
7299,
12,
288,
291,
14,
1100,
14,
362,
360,
1069,
659,
267,
776,
267,
372,
2203,
199,
199,
533,
3523,
3310,
7299,
8,
6243,
1282,
1311,
281,
2380,
1793,
304,
272,
1794,
13048,
63,
955,
275,
9522,
779,
267,
283,
344,
297,
267,
283,
7631,
297,
267,
283,
504,
63,
929,
297,
267,
283,
475,
63,
929,
297,
267,
283,
602,
63,
3966,
297,
267,
283,
602,
63,
5540,
297,
267,
283,
1375,
297,
272,
4794,
339,
1305,
275,
8926,
14,
2183,
8,
1365,
17574,
344,
297,
1586,
63,
2118,
29,
549,
9,
339,
6804,
275,
8926,
14,
15792,
8,
4577,
29,
2698,
16276,
83,
14,
4577,
1012,
339,
3721,
275,
8926,
14,
2183,
8,
988,
63,
1267,
29,
26439,
12,
1415,
29,
797,
9,
339,
687,
63,
929,
275,
8926,
14,
15792,
8,
4577,
29,
2698,
18010,
14,
4577,
1062,
1586,
63,
2118,
29,
549,
9,
272,
370,
63,
929,
275,
8926,
14,
15792,
8,
4577,
29,
2698,
18010,
14,
4577,
1062,
1586,
63,
2118,
29,
549,
9,
339,
1434,
63,
3966,
275,
8926,
14,
4626,
8,
1365,
534,
3966,
297,
1586,
63,
2118,
29,
549,
9,
272,
1434,
63,
5540,
275,
8926,
14,
4626,
8,
1365,
534,
5540,
297,
1586,
63,
2118,
29,
549,
9,
272,
2599,
275,
8926,
14,
5036,
8,
739,
63,
2118,
29,
549,
9,
339,
14875,
275,
23230,
3319,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
supriyasawant/gstudio
|
gnowsys-ndf/gnowsys_ndf/benchmarker/benchmarkreport.py
|
2
|
3116
|
from gnowsys_ndf.ndf.models import *
from django.http import HttpResponse
import random
from django.template import RequestContext
from django.shortcuts import render_to_response, render
from datetime import date,time,timedelta
import json
'''
The First method to get called.
'''
db = get_database()
col = db[Benchmark.collection_name]
def report(request):
date1=datetime.date.today()
ti=time(0,0)
listofmethods = []
Today=datetime.datetime.combine(date1,ti)
bench_cur = col.find({'last_update':{'$gte':Today}}).sort('last_update', -1).sort('time_taken',-1)
search_cur = []
if request.method == "POST":
if request.POST.get('searchmethod','') != '':
search_cur = col.find({'name':unicode(request.POST.get('searchmethod',''))}).sort('last_update', -1).sort('time_taken',-1)
else:
if request.POST.get('methodlist','') != "ALL":
print "sadfasfasdf",request.POST.get('methodlist','')
search_cur = col.find({'name':unicode(request.POST.get('methodlist',''))}).sort('last_update', -1).sort('time_taken',-1)
avg = 0
count = 0
last_name = ""
total = 0
loop = 0
new_list =[]
for i in bench_cur:
loop = loop + 1
if i['name'] not in listofmethods:
listofmethods.append(i['name'])
if last_name != "" :
if last_name != i['name']:
total = avg/count
count = 0
avg = 0
a = new_list.pop()
a.update({'avg':total})
new_list.append(a)
avg = float (i['time_taken']) +avg
count = count + 1
last_name = i['name']
new_list.append(i)
if new_list:
a = new_list.pop()
a.update({'avg':(avg/count)})
new_list.append(a)
bench_cur.rewind()
return render_to_response("reports.html",
{'bench_cur':new_list,
'listofmethods':listofmethods,
'search_cur':search_cur
},context_instance = RequestContext(request))
def month_view(request):
periodicview = request.POST.get('periodview','')
if periodicview == 'day':
timedelta1 = 0
if periodicview == 'week':
timedelta1 = 7
if periodicview == 'month':
timedelta1 = 30
if not periodicview:
timedelta1= 0
date1=datetime.date.today() - timedelta(timedelta1)
ti=time(0,0)
listofmethods = []
Today=datetime.datetime.combine(date1,ti)
bench_cur = col.aggregate([{'$match':{'last_update':{'$gte':Today}}}, {
'$group':
{
'_id': "$name",
'time_taken': { '$sum': 1 },
}
},{'$sort': { 'time_taken': -1 }}
]
)
#write a code to check to find the frequency of the most executed method
#primarily focus on the method getting maximum number of hits
return render_to_response("frequency_reports.html",
{'bench_cur':json.dumps(bench_cur['result'], cls=NodeJSONEncoder),
},context_instance = RequestContext(request))
|
agpl-3.0
|
[
504,
486,
2131,
1274,
63,
977,
70,
14,
977,
70,
14,
992,
492,
627,
199,
504,
1639,
14,
1014,
492,
6183,
199,
646,
2196,
199,
504,
1639,
14,
1160,
492,
22538,
199,
504,
1639,
14,
17469,
492,
3795,
63,
475,
63,
1310,
12,
3795,
199,
504,
2197,
492,
1434,
12,
521,
12,
7473,
199,
646,
2022,
199,
2344,
272,
710,
7758,
1083,
370,
664,
2797,
14,
199,
2344,
199,
697,
275,
664,
63,
4659,
342,
257,
199,
761,
275,
1592,
59,
18644,
14,
3627,
63,
354,
61,
523,
199,
318,
3622,
8,
1069,
304,
199,
1434,
17,
29,
2083,
14,
602,
14,
8136,
342,
9948,
3367,
29,
521,
8,
16,
12,
16,
9,
199,
769,
1618,
2474,
275,
942,
199,
377,
26920,
29,
2083,
14,
2083,
14,
13307,
8,
602,
17,
12,
280,
9,
199,
26456,
63,
895,
275,
1048,
14,
1623,
3252,
2019,
63,
873,
3010,
4,
19586,
356,
31982,
4863,
680,
3191,
360,
2019,
63,
873,
297,
446,
17,
680,
3191,
360,
521,
63,
28549,
297,
13,
17,
9,
523,
199,
2754,
63,
895,
275,
942,
199,
340,
1056,
14,
765,
508,
298,
4030,
582,
489,
340,
1056,
14,
4030,
14,
362,
360,
1733,
765,
20944,
1137,
8061,
881,
2754,
63,
895,
275,
1048,
14,
1623,
3252,
354,
356,
2975,
8,
1069,
14,
4030,
14,
362,
360,
1733,
765,
1673,
1333,
21385,
3191,
360,
2019,
63,
873,
297,
446,
17,
680,
3191,
360,
521,
63,
28549,
297,
13,
17,
9,
1779,
489,
587,
26,
267,
340,
1056,
14,
4030,
14,
362,
360,
765,
513,
20944,
1137,
298,
1761,
582,
881,
870,
298,
83,
24642,
29551,
18196,
401,
1069,
14,
4030,
14,
362,
360,
765,
513,
20944,
881,
2754,
63,
895,
275,
1048,
14,
1623,
3252,
354,
356,
2975,
8,
1069,
14,
4030,
14,
362,
360,
765,
513,
1673,
1333,
21385,
3191,
360,
2019,
63,
873,
297,
446,
17,
680,
3191,
360,
521,
63,
28549,
297,
13,
17,
9,
1598,
199,
12402,
275,
378,
9668,
199,
2338,
275,
378,
199,
2061,
63,
354,
275,
3087,
199,
3141,
275,
378,
199,
4438,
275,
378,
199,
892,
63,
513,
275,
8607,
3777,
199,
367,
284,
315,
26456,
63,
895,
26,
272,
4438,
275,
4438,
221,
435,
413,
5591,
340,
284,
459,
354,
418,
440,
315,
769,
1618,
2474,
26,
1779,
769,
1618,
2474,
14,
740,
8,
73,
459,
354,
1105,
272,
340,
2061,
63,
354,
1137,
3087,
520,
489,
340,
2061,
63,
354,
1137,
284,
459,
354,
2565,
268,
3141,
275,
12402,
15,
835,
268,
2338,
275,
378,
268,
12402,
275,
378,
268,
282,
275,
892,
63,
513,
14,
1935,
342,
268,
282,
14,
873,
3252,
8595,
356,
2923,
1552,
268,
892,
63,
513,
14,
740,
8,
65,
9,
272,
12402,
275,
2069,
334,
73,
459,
521,
63,
28549,
1105,
435,
8595,
272,
2338,
275,
2338,
435,
413,
272,
2061,
63,
354,
275,
284,
459,
354,
418,
272,
892,
63,
513,
14,
740,
8,
73,
9,
199,
340,
892,
63,
513,
26,
272,
282,
275,
892,
63,
513,
14,
1935,
342,
259,
272,
282,
14,
873,
3252,
8595,
356,
8,
8595,
15,
835,
11466,
272,
892,
63,
513,
14,
740,
8,
65,
9,
199,
26456,
63,
895,
14,
5257,
688,
342,
3698,
199,
372,
3795,
63,
475,
63,
1310,
480,
15629,
14,
1360,
401,
2574,
791,
16571,
63,
895,
356,
1222,
63,
513,
12,
1169,
283,
513,
1618,
2474,
356,
513,
1618,
2474,
12,
1169,
283,
1733,
63,
895,
356,
1733,
63,
895,
29157,
2574,
1660,
1100,
63,
842,
275,
22538,
8,
1069,
430,
221,
421,
199,
318,
5794,
63,
1345,
8,
1069,
304,
199,
18745,
1345,
275,
1056,
14,
4030,
14,
362,
360,
5191,
1345,
20944,
523,
199,
340,
18745,
1345,
508,
283,
2977,
356,
272,
6871,
17,
275,
378,
199,
340,
18745,
1345,
508,
283,
6419,
356,
272,
6871,
17,
275,
1520,
199,
340,
18745,
1345,
508,
283,
4482,
356,
272,
6871,
17,
275,
4233,
199,
340,
440,
18745,
1345,
26,
2043,
6871,
17,
29,
378,
259,
199,
1434,
17,
29,
2083,
14,
602,
14,
8136,
342,
446,
6871,
8,
7473,
17,
9,
9948,
3367,
29,
521,
8,
16,
12,
16,
9,
199,
769,
1618,
2474,
275,
942,
199,
377,
26920,
29,
2083,
14,
2083,
14,
13307,
8,
602,
17,
12,
280,
9,
523,
199,
26456,
63,
895,
275,
1048,
14,
7516,
779,
1445,
4,
1431,
3010,
2019,
63,
873,
3010,
4,
19586,
356,
31982,
4863,
1386,
469,
2126,
4505,
923,
356,
268,
469,
1779,
2513,
344,
356,
7880,
354,
401,
1779,
283,
521,
63,
28549,
356,
469,
4505,
1838,
356,
413,
1660,
268,
789,
881,
1362,
1660,
1445,
4,
3191,
356,
469,
283,
521,
63,
28549,
356,
446,
17,
3586,
2043,
1622,
272,
2043,
776,
3521,
1362,
327,
952,
282,
1233,
370,
1104,
370,
2342,
314,
9857,
402,
314,
4750,
7934,
1083,
1362,
327,
1359,
30468,
16470,
641,
314,
1083,
10232,
5696,
1329,
402,
19745,
199,
372,
3795,
63,
475,
63,
1310,
480,
11132,
63,
15629,
14,
1360,
401,
2574,
791,
16571,
63,
895,
356,
1001,
14,
4180,
8,
16571,
63,
895,
459,
1099,
995,
843,
29,
1716,
23069,
395,
2574,
1660,
1100,
63,
842,
275,
22538,
8,
1069,
430,
9948,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
486,
2131,
1274,
63,
977,
70,
14,
977,
70,
14,
992,
492,
627,
199,
504,
1639,
14,
1014,
492,
6183,
199,
646,
2196,
199,
504,
1639,
14,
1160,
492,
22538,
199,
504,
1639,
14,
17469,
492,
3795,
63,
475,
63,
1310,
12,
3795,
199,
504,
2197,
492,
1434,
12,
521,
12,
7473,
199,
646,
2022,
199,
2344,
272,
710,
7758,
1083,
370,
664,
2797,
14,
199,
2344,
199,
697,
275,
664,
63,
4659,
342,
257,
199,
761,
275,
1592,
59,
18644,
14,
3627,
63,
354,
61,
523,
199,
318,
3622,
8,
1069,
304,
199,
1434,
17,
29,
2083,
14,
602,
14,
8136,
342,
9948,
3367,
29,
521,
8,
16,
12,
16,
9,
199,
769,
1618,
2474,
275,
942,
199,
377,
26920,
29,
2083,
14,
2083,
14,
13307,
8,
602,
17,
12,
280,
9,
199,
26456,
63,
895,
275,
1048,
14,
1623,
3252,
2019,
63,
873,
3010,
4,
19586,
356,
31982,
4863,
680,
3191,
360,
2019,
63,
873,
297,
446,
17,
680,
3191,
360,
521,
63,
28549,
297,
13,
17,
9,
523,
199,
2754,
63,
895,
275,
942,
199,
340,
1056,
14,
765,
508,
298,
4030,
582,
489,
340,
1056,
14,
4030,
14,
362,
360,
1733,
765,
20944,
1137,
8061,
881,
2754,
63,
895,
275,
1048,
14,
1623,
3252,
354,
356,
2975,
8,
1069,
14,
4030,
14,
362,
360,
1733,
765,
1673,
1333,
21385,
3191,
360,
2019,
63,
873,
297,
446,
17,
680,
3191,
360,
521,
63,
28549,
297,
13,
17,
9,
1779,
489,
587,
26,
267,
340,
1056,
14,
4030,
14,
362,
360,
765,
513,
20944,
1137,
298,
1761,
582,
881,
870,
298,
83,
24642,
29551,
18196,
401,
1069,
14,
4030,
14,
362,
360,
765,
513,
20944,
881,
2754,
63,
895,
275,
1048,
14,
1623,
3252,
354,
356,
2975,
8,
1069,
14,
4030,
14,
362,
360,
765,
513,
1673,
1333,
21385,
3191,
360,
2019,
63,
873,
297,
446,
17,
680,
3191,
360,
521,
63,
28549,
297,
13,
17,
9,
1598,
199,
12402,
275,
378,
9668,
199,
2338,
275,
378,
199,
2061,
63,
354,
275,
3087,
199,
3141,
275,
378,
199,
4438,
275,
378,
199,
892,
63,
513,
275,
8607,
3777,
199,
367,
284,
315,
26456,
63,
895,
26,
272,
4438,
275,
4438,
221,
435,
413,
5591,
340,
284,
459,
354,
418,
440,
315,
769,
1618,
2474,
26,
1779,
769,
1618,
2474,
14,
740,
8,
73,
459,
354,
1105,
272,
340,
2061,
63,
354,
1137,
3087,
520,
489,
340,
2061,
63,
354,
1137,
284,
459,
354,
2565,
268,
3141,
275,
12402,
15,
835,
268,
2338,
275,
378,
268,
12402,
275,
378,
268,
282,
275,
892,
63,
513,
14,
1935,
342,
268,
282,
14,
873,
3252,
8595,
356,
2923,
1552,
268,
892,
63,
513,
14,
740,
8,
65,
9,
272,
12402,
275,
2069,
334,
73,
459,
521,
63,
28549,
1105,
435,
8595,
272,
2338,
275,
2338,
435,
413,
272,
2061,
63,
354,
275,
284,
459,
354,
418,
272,
892,
63,
513,
14,
740,
8,
73,
9,
199,
340,
892,
63,
513,
26,
272,
282,
275,
892,
63,
513,
14,
1935,
342,
259,
272,
282,
14,
873,
3252,
8595,
356,
8,
8595,
15,
835,
11466,
272,
892,
63,
513,
14,
740,
8,
65,
9,
199,
26456,
63,
895,
14,
5257,
688,
342,
3698,
199,
372,
3795,
63,
475,
63,
1310,
480,
15629,
14,
1360,
401,
2574,
791,
16571,
63,
895,
356,
1222,
63,
513,
12,
1169,
283,
513,
1618,
2474,
356,
513,
1618,
2474,
12,
1169,
283,
1733,
63,
895,
356,
1733,
63,
895,
29157,
2574,
1660,
1100,
63,
842,
275,
22538,
8,
1069,
430,
221,
421,
199,
318,
5794,
63,
1345,
8,
1069,
304,
199,
18745,
1345,
275,
1056,
14,
4030,
14,
362,
360,
5191,
1345,
20944,
523,
199,
340,
18745,
1345,
508,
283,
2977,
356,
272,
6871,
17,
275,
378,
199,
340,
18745,
1345,
508,
283,
6419,
356,
272,
6871,
17,
275,
1520,
199,
340,
18745,
1345,
508,
283,
4482,
356,
272,
6871,
17,
275,
4233,
199,
340,
440,
18745,
1345,
26,
2043,
6871,
17,
29,
378,
259,
199,
1434,
17,
29,
2083,
14,
602,
14,
8136,
342,
446,
6871,
8,
7473,
17,
9,
9948,
3367,
29,
521,
8,
16,
12,
16,
9,
199,
769,
1618,
2474,
275,
942,
199,
377,
26920,
29,
2083,
14,
2083,
14,
13307,
8,
602,
17,
12,
280,
9,
523,
199,
26456,
63,
895,
275,
1048,
14,
7516,
779,
1445,
4,
1431,
3010,
2019,
63,
873,
3010,
4,
19586,
356,
31982,
4863,
1386,
469,
2126,
4505,
923,
356,
268,
469,
1779,
2513,
344,
356,
7880,
354,
401,
1779,
283,
521,
63,
28549,
356,
469,
4505,
1838,
356,
413,
1660,
268,
789,
881,
1362,
1660,
1445,
4,
3191,
356,
469,
283,
521,
63,
28549,
356,
446,
17,
3586,
2043,
1622,
272,
2043,
776,
3521,
1362,
327,
952,
282,
1233,
370,
1104,
370,
2342,
314,
9857,
402,
314,
4750,
7934,
1083,
1362,
327,
1359,
30468,
16470,
641,
314,
1083,
10232,
5696,
1329,
402,
19745,
199,
372,
3795,
63,
475,
63,
1310,
480,
11132,
63,
15629,
14,
1360,
401,
2574,
791,
16571,
63,
895,
356,
1001,
14,
4180,
8,
16571,
63,
895,
459,
1099,
995,
843,
29,
1716,
23069,
395,
2574,
1660,
1100,
63,
842,
275,
22538,
8,
1069,
430,
9948,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nanolearningllc/edx-platform-cypress
|
common/djangoapps/track/shim.py
|
71
|
6434
|
"""Map new event context values to old top-level field values. Ensures events can be parsed by legacy parsers."""
import json
import logging
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import UsageKey
log = logging.getLogger(__name__)
CONTEXT_FIELDS_TO_INCLUDE = [
'username',
'session',
'ip',
'agent',
'host',
'referer',
'accept_language'
]
class LegacyFieldMappingProcessor(object):
"""Ensures all required fields are included in emitted events"""
def __call__(self, event):
context = event.get('context', {})
if 'context' in event:
for field in CONTEXT_FIELDS_TO_INCLUDE:
self.move_from_context(field, event)
remove_shim_context(event)
if 'data' in event:
if context.get('event_source', '') == 'browser' and isinstance(event['data'], dict):
event['event'] = json.dumps(event['data'])
else:
event['event'] = event['data']
del event['data']
else:
event['event'] = {}
if 'timestamp' in context:
event['time'] = context['timestamp']
del context['timestamp']
elif 'timestamp' in event:
event['time'] = event['timestamp']
if 'timestamp' in event:
del event['timestamp']
self.move_from_context('event_type', event, event.get('name', ''))
self.move_from_context('event_source', event, 'server')
self.move_from_context('page', event, None)
def move_from_context(self, field, event, default_value=''):
"""Move a field from the context to the top level of the event."""
context = event.get('context', {})
if field in context:
event[field] = context[field]
del context[field]
else:
event[field] = default_value
def remove_shim_context(event):
if 'context' in event:
context = event['context']
# These fields are present elsewhere in the event at this point
context_fields_to_remove = set(CONTEXT_FIELDS_TO_INCLUDE)
# This field is only used for Segment.io web analytics and does not concern researchers
context_fields_to_remove.add('client_id')
for field in context_fields_to_remove:
if field in context:
del context[field]
NAME_TO_EVENT_TYPE_MAP = {
'edx.video.played': 'play_video',
'edx.video.paused': 'pause_video',
'edx.video.stopped': 'stop_video',
'edx.video.loaded': 'load_video',
'edx.video.position.changed': 'seek_video',
'edx.video.seeked': 'seek_video',
'edx.video.transcript.shown': 'show_transcript',
'edx.video.transcript.hidden': 'hide_transcript',
}
class VideoEventProcessor(object):
"""
Converts new format video events into the legacy video event format.
Mobile devices cannot actually emit events that exactly match their counterparts emitted by the LMS javascript
video player. Instead of attempting to get them to do that, we instead insert a shim here that converts the events
they *can* easily emit and converts them into the legacy format.
TODO: Remove this shim and perform the conversion as part of some batch canonicalization process.
"""
def __call__(self, event):
name = event.get('name')
if not name:
return
if name not in NAME_TO_EVENT_TYPE_MAP:
return
# Convert edx.video.seeked to edx.video.position.changed because edx.video.seeked was not intended to actually
# ever be emitted.
if name == "edx.video.seeked":
event['name'] = "edx.video.position.changed"
event['event_type'] = NAME_TO_EVENT_TYPE_MAP[name]
if 'event' not in event:
return
payload = event['event']
if 'module_id' in payload:
module_id = payload['module_id']
try:
usage_key = UsageKey.from_string(module_id)
except InvalidKeyError:
log.warning('Unable to parse module_id "%s"', module_id, exc_info=True)
else:
payload['id'] = usage_key.html_id()
del payload['module_id']
if 'current_time' in payload:
payload['currentTime'] = payload.pop('current_time')
if 'context' in event:
context = event['context']
# Converts seek_type to seek and skip|slide to onSlideSeek|onSkipSeek
if 'seek_type' in payload:
seek_type = payload['seek_type']
if seek_type == 'slide':
payload['type'] = "onSlideSeek"
elif seek_type == 'skip':
payload['type'] = "onSkipSeek"
del payload['seek_type']
# For the iOS build that is returning a +30 for back skip 30
if (
context['application']['version'] == "1.0.02" and
context['application']['name'] == "edx.mobileapp.iOS"
):
if 'requested_skip_interval' in payload and 'type' in payload:
if (
payload['requested_skip_interval'] == 30 and
payload['type'] == "onSkipSeek"
):
payload['requested_skip_interval'] = -30
# For the Android build that isn't distinguishing between skip/seek
if 'requested_skip_interval' in payload:
if abs(payload['requested_skip_interval']) != 30:
if 'type' in payload:
payload['type'] = 'onSlideSeek'
if 'open_in_browser_url' in context:
page, _sep, _tail = context.pop('open_in_browser_url').rpartition('/')
event['page'] = page
event['event'] = json.dumps(payload)
class GoogleAnalyticsProcessor(object):
"""Adds course_id as label, and sets nonInteraction property"""
# documentation of fields here: https://segment.com/docs/integrations/google-analytics/
# this should *only* be used on events destined for segment.com and eventually google analytics
def __call__(self, event):
context = event.get('context', {})
course_id = context.get('course_id')
if course_id is not None:
event['label'] = course_id
event['nonInteraction'] = 1
|
agpl-3.0
|
[
624,
2956,
892,
1566,
1067,
1338,
370,
2269,
2746,
13,
1896,
901,
1338,
14,
29652,
4474,
883,
506,
4565,
701,
12139,
21295,
1041,
199,
199,
646,
2022,
199,
646,
2050,
199,
199,
504,
15058,
63,
1612,
492,
6378,
10230,
199,
504,
15058,
63,
1612,
14,
8268,
14,
1612,
492,
11028,
1197,
421,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
9059,
63,
12767,
63,
2566,
63,
18171,
275,
359,
272,
283,
2473,
297,
272,
283,
1730,
297,
272,
283,
711,
297,
272,
283,
4054,
297,
272,
283,
1102,
297,
272,
283,
20996,
297,
272,
283,
5694,
63,
3671,
7,
199,
61,
421,
199,
533,
26251,
792,
7674,
10438,
8,
785,
304,
272,
408,
37,
561,
1482,
1006,
1415,
1504,
787,
5120,
315,
19515,
4474,
624,
339,
347,
636,
1250,
721,
277,
12,
1566,
304,
267,
1067,
275,
1566,
14,
362,
360,
1100,
297,
5009,
267,
340,
283,
1100,
7,
315,
1566,
26,
288,
367,
901,
315,
1868,
3876,
63,
12767,
63,
2566,
63,
18171,
26,
355,
291,
14,
1185,
63,
504,
63,
1100,
8,
698,
12,
1566,
9,
288,
2813,
63,
28238,
63,
1100,
8,
1430,
9,
398,
340,
283,
576,
7,
315,
1566,
26,
288,
340,
1067,
14,
362,
360,
1430,
63,
1365,
297,
4074,
508,
283,
5750,
7,
436,
1228,
8,
1430,
459,
576,
995,
1211,
304,
355,
1566,
459,
1430,
418,
275,
2022,
14,
4180,
8,
1430,
459,
576,
1105,
288,
587,
26,
355,
1566,
459,
1430,
418,
275,
1566,
459,
576,
418,
288,
2150,
1566,
459,
576,
418,
267,
587,
26,
288,
1566,
459,
1430,
418,
275,
1052,
398,
340,
283,
3954,
7,
315,
1067,
26,
288,
1566,
459,
521,
418,
275,
1067,
459,
3954,
418,
288,
2150,
1067,
459,
3954,
418,
267,
916,
283,
3954,
7,
315,
1566,
26,
288,
1566,
459,
521,
418,
275,
1566,
459,
3954,
418,
398,
340,
283,
3954,
7,
315,
1566,
26,
288,
2150,
1566,
459,
3954,
418,
398,
291,
14,
1185,
63,
504,
63,
1100,
360,
1430,
63,
466,
297,
1566,
12,
1566,
14,
362,
360,
354,
297,
12381,
267,
291,
14,
1185,
63,
504,
63,
1100,
360,
1430,
63,
1365,
297,
1566,
12,
283,
1000,
358,
267,
291,
14,
1185,
63,
504,
63,
1100,
360,
1606,
297,
1566,
12,
488,
9,
339,
347,
4057,
63,
504,
63,
1100,
8,
277,
12,
901,
12,
1566,
12,
849,
63,
585,
9280,
267,
408,
10370,
282,
901,
687,
314,
1067,
370,
314,
2746,
2166,
402,
314,
1566,
1041,
267,
1067,
275,
1566,
14,
362,
360,
1100,
297,
5009,
267,
340,
901,
315,
1067,
26,
288,
1566,
59,
698,
61,
275,
1067,
59,
698,
61,
288,
2150,
1067,
59,
698,
61,
267,
587,
26,
288,
1566,
59,
698,
61,
275,
849,
63,
585,
421,
199,
318,
2813,
63,
28238,
63,
1100,
8,
1430,
304,
272,
340,
283,
1100,
7,
315,
1566,
26,
267,
1067,
275,
1566,
459,
1100,
418,
267,
327,
5723,
1504,
787,
3451,
25320,
315,
314,
1566,
737,
642,
2376,
267,
1067,
63,
955,
63,
475,
63,
2168,
275,
663,
8,
9059,
63,
12767,
63,
2566,
63,
18171,
9,
267,
327,
961,
901,
365,
1454,
1202,
367,
29858,
14,
2308,
3330,
30159,
436,
1630,
440,
406,
22082,
295,
1733,
1192,
267,
1067,
63,
955,
63,
475,
63,
2168,
14,
525,
360,
1258,
63,
344,
358,
267,
367,
901,
315,
1067,
63,
955,
63,
475,
63,
2168,
26,
288,
340,
901,
315,
1067,
26,
355,
2150,
1067,
59,
698,
61,
421,
199,
2339,
63,
2566,
63,
8193,
63,
2711,
63,
5443,
275,
469,
272,
283,
8268,
14,
3722,
14,
2802,
379,
356,
283,
2802,
63,
3722,
297,
272,
283,
8268,
14,
3722,
14,
22478,
356,
283,
11241,
63,
3722,
297,
272,
283,
8268,
14,
3722,
14,
14661,
356,
283,
2379,
63,
3722,
297,
272,
283,
8268,
14,
3722,
14,
4591,
356,
283,
912,
63,
3722,
297,
272,
283,
8268,
14,
3722,
14,
3124,
14,
2489,
356,
283,
5507,
63,
3722,
297,
272,
283,
8268,
14,
3722,
14,
5507,
379,
356,
283,
5507,
63,
3722,
297,
272,
283,
8268,
14,
3722,
14,
21656,
14,
24422,
356,
283,
2384,
63,
21656,
297,
272,
283,
8268,
14,
3722,
14,
21656,
14,
5642,
356,
283,
8191,
63,
21656,
297,
199,
93,
421,
199,
533,
15709,
2390,
10438,
8,
785,
304,
272,
408,
272,
19107,
892,
1475,
3991,
4474,
1901,
314,
12139,
3991,
1566,
1475,
14,
339,
29724,
7256,
3913,
5965,
8689,
4474,
626,
8840,
1336,
3932,
7055,
4181,
19515,
701,
314,
27540,
18910,
272,
3991,
7748,
14,
15345,
402,
19595,
370,
664,
3062,
370,
886,
626,
12,
781,
3140,
5518,
282,
25905,
2348,
626,
15373,
314,
4474,
272,
2985,
627,
2425,
10,
16174,
8689,
436,
15373,
3062,
1901,
314,
12139,
1475,
14,
339,
3254,
26,
5852,
642,
25905,
436,
5147,
314,
8603,
465,
1777,
402,
2005,
3522,
11358,
2072,
2112,
14,
339,
408,
339,
347,
636,
1250,
721,
277,
12,
1566,
304,
267,
536,
275,
1566,
14,
362,
360,
354,
358,
267,
340,
440,
536,
26,
288,
372,
398,
340,
536,
440,
315,
13637,
63,
2566,
63,
8193,
63,
2711,
63,
5443,
26,
288,
372,
398,
327,
7905,
22435,
14,
3722,
14,
5507,
379,
370,
22435,
14,
3722,
14,
3124,
14,
2489,
2952,
22435,
14,
3722,
14,
5507,
379,
1990,
440,
11619,
370,
5965,
267,
327,
14433,
506,
19515,
14,
267,
340,
536,
508,
298,
8268,
14,
3722,
14,
5507,
379,
582,
288,
1566,
459,
354,
418,
275,
298,
8268,
14,
3722,
14,
3124,
14,
2489,
2,
398,
1566,
459,
1430,
63,
466,
418,
275,
13637,
63,
2566,
63,
8193,
63,
2711,
63,
5443,
59,
354,
61,
398,
340,
283,
1430,
7,
440,
315,
1566,
26,
288,
372,
267,
4886,
275,
1566,
459,
1430,
418,
398,
340,
283,
578,
63,
344,
7,
315,
4886,
26,
288,
859,
63,
344,
275,
4886,
459,
578,
63,
344,
418,
288,
862,
26,
355,
4503,
63,
498,
275,
11028,
1197,
14,
504,
63,
875,
8,
578,
63,
344,
9,
288,
871,
6378,
10230,
26,
355,
943,
14,
3764,
360,
6005,
370,
2198,
859,
63,
344,
2071,
83,
6949,
859,
63,
344,
12,
3178,
63,
815,
29,
549,
9,
288,
587,
26,
355,
4886,
459,
344,
418,
275,
4503,
63,
498
] |
[
2956,
892,
1566,
1067,
1338,
370,
2269,
2746,
13,
1896,
901,
1338,
14,
29652,
4474,
883,
506,
4565,
701,
12139,
21295,
1041,
199,
199,
646,
2022,
199,
646,
2050,
199,
199,
504,
15058,
63,
1612,
492,
6378,
10230,
199,
504,
15058,
63,
1612,
14,
8268,
14,
1612,
492,
11028,
1197,
421,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
9059,
63,
12767,
63,
2566,
63,
18171,
275,
359,
272,
283,
2473,
297,
272,
283,
1730,
297,
272,
283,
711,
297,
272,
283,
4054,
297,
272,
283,
1102,
297,
272,
283,
20996,
297,
272,
283,
5694,
63,
3671,
7,
199,
61,
421,
199,
533,
26251,
792,
7674,
10438,
8,
785,
304,
272,
408,
37,
561,
1482,
1006,
1415,
1504,
787,
5120,
315,
19515,
4474,
624,
339,
347,
636,
1250,
721,
277,
12,
1566,
304,
267,
1067,
275,
1566,
14,
362,
360,
1100,
297,
5009,
267,
340,
283,
1100,
7,
315,
1566,
26,
288,
367,
901,
315,
1868,
3876,
63,
12767,
63,
2566,
63,
18171,
26,
355,
291,
14,
1185,
63,
504,
63,
1100,
8,
698,
12,
1566,
9,
288,
2813,
63,
28238,
63,
1100,
8,
1430,
9,
398,
340,
283,
576,
7,
315,
1566,
26,
288,
340,
1067,
14,
362,
360,
1430,
63,
1365,
297,
4074,
508,
283,
5750,
7,
436,
1228,
8,
1430,
459,
576,
995,
1211,
304,
355,
1566,
459,
1430,
418,
275,
2022,
14,
4180,
8,
1430,
459,
576,
1105,
288,
587,
26,
355,
1566,
459,
1430,
418,
275,
1566,
459,
576,
418,
288,
2150,
1566,
459,
576,
418,
267,
587,
26,
288,
1566,
459,
1430,
418,
275,
1052,
398,
340,
283,
3954,
7,
315,
1067,
26,
288,
1566,
459,
521,
418,
275,
1067,
459,
3954,
418,
288,
2150,
1067,
459,
3954,
418,
267,
916,
283,
3954,
7,
315,
1566,
26,
288,
1566,
459,
521,
418,
275,
1566,
459,
3954,
418,
398,
340,
283,
3954,
7,
315,
1566,
26,
288,
2150,
1566,
459,
3954,
418,
398,
291,
14,
1185,
63,
504,
63,
1100,
360,
1430,
63,
466,
297,
1566,
12,
1566,
14,
362,
360,
354,
297,
12381,
267,
291,
14,
1185,
63,
504,
63,
1100,
360,
1430,
63,
1365,
297,
1566,
12,
283,
1000,
358,
267,
291,
14,
1185,
63,
504,
63,
1100,
360,
1606,
297,
1566,
12,
488,
9,
339,
347,
4057,
63,
504,
63,
1100,
8,
277,
12,
901,
12,
1566,
12,
849,
63,
585,
9280,
267,
408,
10370,
282,
901,
687,
314,
1067,
370,
314,
2746,
2166,
402,
314,
1566,
1041,
267,
1067,
275,
1566,
14,
362,
360,
1100,
297,
5009,
267,
340,
901,
315,
1067,
26,
288,
1566,
59,
698,
61,
275,
1067,
59,
698,
61,
288,
2150,
1067,
59,
698,
61,
267,
587,
26,
288,
1566,
59,
698,
61,
275,
849,
63,
585,
421,
199,
318,
2813,
63,
28238,
63,
1100,
8,
1430,
304,
272,
340,
283,
1100,
7,
315,
1566,
26,
267,
1067,
275,
1566,
459,
1100,
418,
267,
327,
5723,
1504,
787,
3451,
25320,
315,
314,
1566,
737,
642,
2376,
267,
1067,
63,
955,
63,
475,
63,
2168,
275,
663,
8,
9059,
63,
12767,
63,
2566,
63,
18171,
9,
267,
327,
961,
901,
365,
1454,
1202,
367,
29858,
14,
2308,
3330,
30159,
436,
1630,
440,
406,
22082,
295,
1733,
1192,
267,
1067,
63,
955,
63,
475,
63,
2168,
14,
525,
360,
1258,
63,
344,
358,
267,
367,
901,
315,
1067,
63,
955,
63,
475,
63,
2168,
26,
288,
340,
901,
315,
1067,
26,
355,
2150,
1067,
59,
698,
61,
421,
199,
2339,
63,
2566,
63,
8193,
63,
2711,
63,
5443,
275,
469,
272,
283,
8268,
14,
3722,
14,
2802,
379,
356,
283,
2802,
63,
3722,
297,
272,
283,
8268,
14,
3722,
14,
22478,
356,
283,
11241,
63,
3722,
297,
272,
283,
8268,
14,
3722,
14,
14661,
356,
283,
2379,
63,
3722,
297,
272,
283,
8268,
14,
3722,
14,
4591,
356,
283,
912,
63,
3722,
297,
272,
283,
8268,
14,
3722,
14,
3124,
14,
2489,
356,
283,
5507,
63,
3722,
297,
272,
283,
8268,
14,
3722,
14,
5507,
379,
356,
283,
5507,
63,
3722,
297,
272,
283,
8268,
14,
3722,
14,
21656,
14,
24422,
356,
283,
2384,
63,
21656,
297,
272,
283,
8268,
14,
3722,
14,
21656,
14,
5642,
356,
283,
8191,
63,
21656,
297,
199,
93,
421,
199,
533,
15709,
2390,
10438,
8,
785,
304,
272,
408,
272,
19107,
892,
1475,
3991,
4474,
1901,
314,
12139,
3991,
1566,
1475,
14,
339,
29724,
7256,
3913,
5965,
8689,
4474,
626,
8840,
1336,
3932,
7055,
4181,
19515,
701,
314,
27540,
18910,
272,
3991,
7748,
14,
15345,
402,
19595,
370,
664,
3062,
370,
886,
626,
12,
781,
3140,
5518,
282,
25905,
2348,
626,
15373,
314,
4474,
272,
2985,
627,
2425,
10,
16174,
8689,
436,
15373,
3062,
1901,
314,
12139,
1475,
14,
339,
3254,
26,
5852,
642,
25905,
436,
5147,
314,
8603,
465,
1777,
402,
2005,
3522,
11358,
2072,
2112,
14,
339,
408,
339,
347,
636,
1250,
721,
277,
12,
1566,
304,
267,
536,
275,
1566,
14,
362,
360,
354,
358,
267,
340,
440,
536,
26,
288,
372,
398,
340,
536,
440,
315,
13637,
63,
2566,
63,
8193,
63,
2711,
63,
5443,
26,
288,
372,
398,
327,
7905,
22435,
14,
3722,
14,
5507,
379,
370,
22435,
14,
3722,
14,
3124,
14,
2489,
2952,
22435,
14,
3722,
14,
5507,
379,
1990,
440,
11619,
370,
5965,
267,
327,
14433,
506,
19515,
14,
267,
340,
536,
508,
298,
8268,
14,
3722,
14,
5507,
379,
582,
288,
1566,
459,
354,
418,
275,
298,
8268,
14,
3722,
14,
3124,
14,
2489,
2,
398,
1566,
459,
1430,
63,
466,
418,
275,
13637,
63,
2566,
63,
8193,
63,
2711,
63,
5443,
59,
354,
61,
398,
340,
283,
1430,
7,
440,
315,
1566,
26,
288,
372,
267,
4886,
275,
1566,
459,
1430,
418,
398,
340,
283,
578,
63,
344,
7,
315,
4886,
26,
288,
859,
63,
344,
275,
4886,
459,
578,
63,
344,
418,
288,
862,
26,
355,
4503,
63,
498,
275,
11028,
1197,
14,
504,
63,
875,
8,
578,
63,
344,
9,
288,
871,
6378,
10230,
26,
355,
943,
14,
3764,
360,
6005,
370,
2198,
859,
63,
344,
2071,
83,
6949,
859,
63,
344,
12,
3178,
63,
815,
29,
549,
9,
288,
587,
26,
355,
4886,
459,
344,
418,
275,
4503,
63,
498,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rspavel/spack
|
var/spack/repos/builtin/packages/py-thirdorder/package.py
|
5
|
1476
|
# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
from spack import *
class PyThirdorder(PythonPackage):
"""It helps ShengBTE users create FORCE_CONSTANTS_3RD files efficiently"""
homepage = "http://www.shengbte.org"
url = "http://www.shengbte.org/downloads/thirdorder-v1.1.1-8526f47.tar.bz2"
version('1.1.1-8526f47', '5e1cc8d6ffa7efdb7325c397ca236863ea8a9c5bed1c558acca68b140f89167e')
depends_on('py-numpy', type=('build', 'run'))
depends_on('py-scipy', type=('build', 'run'))
depends_on('spglib', type=('build', 'run'))
def patch(self):
setupfile = FileFilter('setup.py')
setupfile.filter('LIBRARY_DIRS = .*', 'LIBRARY_DIRS = ["%s"]'
% self.spec['spglib'].prefix.lib)
setupfile.filter('INCLUDE_DIRS = .*', 'INCLUDE_DIRS = ["%s"]'
% self.spec['spglib'].prefix.include)
sourcefile = FileFilter('thirdorder_core.c')
sourcefile.filter('#include "spglib.*"', '#include "spglib.h"')
@run_after('install')
def post_install(self):
mkdirp(self.prefix.bin)
install('thirdorder_espresso.py', self.prefix.bin)
install('thirdorder_vasp.py', self.prefix.bin)
install('thirdorder_castep.py', self.prefix.bin)
install('thirdorder_common.py', self.prefix.bin)
|
lgpl-2.1
|
[
3,
1898,
6171,
13,
14982,
7964,
29590,
491,
4380,
6878,
20548,
13863,
12,
20376,
436,
1163,
199,
3,
428,
1389,
7290,
23493,
14,
1666,
314,
2746,
13,
1896,
5877,
570,
367,
2436,
14,
199,
3,
199,
3,
6988,
19596,
13,
3761,
13,
7544,
26,
334,
28993,
13,
18,
14,
16,
1549,
10697,
9,
199,
199,
504,
308,
1389,
492,
627,
421,
199,
533,
1611,
28611,
1648,
8,
4718,
8599,
304,
272,
408,
7940,
22577,
5244,
7420,
34,
3727,
4390,
1218,
2381,
2089,
63,
25825,
51,
63,
19,
15543,
1584,
30427,
624,
339,
26586,
275,
298,
1014,
921,
1544,
14,
609,
287,
4908,
266,
14,
1308,
2,
272,
1166,
420,
275,
298,
1014,
921,
1544,
14,
609,
287,
4908,
266,
14,
1308,
15,
20373,
15,
11470,
1648,
13,
86,
17,
14,
17,
14,
17,
13,
2426,
1479,
70,
2417,
14,
5369,
14,
10582,
18,
2,
339,
1015,
360,
17,
14,
17,
14,
17,
13,
2426,
1479,
70,
2417,
297,
283,
21,
69,
17,
2055,
24,
68,
22,
556,
65,
23,
2829,
697,
23,
13288,
67,
13145,
696,
10008,
15887,
4489,
24,
65,
25,
67,
21,
6123,
17,
67,
17686,
645,
696,
2333,
66,
10037,
70,
1407,
10806,
69,
358,
339,
8350,
63,
265,
360,
647,
13,
4714,
297,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
647,
13,
14248,
297,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
681,
30816,
297,
730,
7782,
1506,
297,
283,
1065,
1333,
339,
347,
3371,
8,
277,
304,
267,
3272,
493,
275,
3814,
4131,
360,
2758,
14,
647,
358,
267,
3272,
493,
14,
1541,
360,
16983,
63,
14455,
275,
1275,
7693,
283,
16983,
63,
14455,
275,
28585,
83,
937,
7,
586,
450,
291,
14,
1650,
459,
681,
30816,
2278,
1861,
14,
773,
9,
267,
3272,
493,
14,
1541,
360,
18171,
63,
14455,
275,
1275,
7693,
283,
18171,
63,
14455,
275,
28585,
83,
937,
7,
586,
450,
291,
14,
1650,
459,
681,
30816,
2278,
1861,
14,
2613,
9,
398,
1350,
493,
275,
3814,
4131,
360,
11470,
1648,
63,
1018,
14,
67,
358,
267,
1350,
493,
14,
1541,
7863,
2613,
298,
681,
30816,
2795,
6949,
3943,
2613,
298,
681,
30816,
14,
72,
9008,
339,
768,
1065,
63,
4399,
360,
3174,
358,
272,
347,
2963,
63,
3174,
8,
277,
304,
267,
20366,
80,
8,
277,
14,
1861,
14,
1393,
9,
267,
3907,
360,
11470,
1648,
63,
397,
2915,
79,
14,
647,
297,
291,
14,
1861,
14,
1393,
9,
267,
3907,
360,
11470,
1648,
63,
4755,
80,
14,
647,
297,
291,
14,
1861,
14,
1393,
9,
267,
3907,
360,
11470,
1648,
63,
9765,
2852,
14,
647,
297,
291,
14,
1861,
14,
1393,
9,
267,
3907,
360,
11470,
1648,
63,
2330,
14,
647,
297,
291,
14,
1861,
14,
1393,
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
] |
[
1898,
6171,
13,
14982,
7964,
29590,
491,
4380,
6878,
20548,
13863,
12,
20376,
436,
1163,
199,
3,
428,
1389,
7290,
23493,
14,
1666,
314,
2746,
13,
1896,
5877,
570,
367,
2436,
14,
199,
3,
199,
3,
6988,
19596,
13,
3761,
13,
7544,
26,
334,
28993,
13,
18,
14,
16,
1549,
10697,
9,
199,
199,
504,
308,
1389,
492,
627,
421,
199,
533,
1611,
28611,
1648,
8,
4718,
8599,
304,
272,
408,
7940,
22577,
5244,
7420,
34,
3727,
4390,
1218,
2381,
2089,
63,
25825,
51,
63,
19,
15543,
1584,
30427,
624,
339,
26586,
275,
298,
1014,
921,
1544,
14,
609,
287,
4908,
266,
14,
1308,
2,
272,
1166,
420,
275,
298,
1014,
921,
1544,
14,
609,
287,
4908,
266,
14,
1308,
15,
20373,
15,
11470,
1648,
13,
86,
17,
14,
17,
14,
17,
13,
2426,
1479,
70,
2417,
14,
5369,
14,
10582,
18,
2,
339,
1015,
360,
17,
14,
17,
14,
17,
13,
2426,
1479,
70,
2417,
297,
283,
21,
69,
17,
2055,
24,
68,
22,
556,
65,
23,
2829,
697,
23,
13288,
67,
13145,
696,
10008,
15887,
4489,
24,
65,
25,
67,
21,
6123,
17,
67,
17686,
645,
696,
2333,
66,
10037,
70,
1407,
10806,
69,
358,
339,
8350,
63,
265,
360,
647,
13,
4714,
297,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
647,
13,
14248,
297,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
681,
30816,
297,
730,
7782,
1506,
297,
283,
1065,
1333,
339,
347,
3371,
8,
277,
304,
267,
3272,
493,
275,
3814,
4131,
360,
2758,
14,
647,
358,
267,
3272,
493,
14,
1541,
360,
16983,
63,
14455,
275,
1275,
7693,
283,
16983,
63,
14455,
275,
28585,
83,
937,
7,
586,
450,
291,
14,
1650,
459,
681,
30816,
2278,
1861,
14,
773,
9,
267,
3272,
493,
14,
1541,
360,
18171,
63,
14455,
275,
1275,
7693,
283,
18171,
63,
14455,
275,
28585,
83,
937,
7,
586,
450,
291,
14,
1650,
459,
681,
30816,
2278,
1861,
14,
2613,
9,
398,
1350,
493,
275,
3814,
4131,
360,
11470,
1648,
63,
1018,
14,
67,
358,
267,
1350,
493,
14,
1541,
7863,
2613,
298,
681,
30816,
2795,
6949,
3943,
2613,
298,
681,
30816,
14,
72,
9008,
339,
768,
1065,
63,
4399,
360,
3174,
358,
272,
347,
2963,
63,
3174,
8,
277,
304,
267,
20366,
80,
8,
277,
14,
1861,
14,
1393,
9,
267,
3907,
360,
11470,
1648,
63,
397,
2915,
79,
14,
647,
297,
291,
14,
1861,
14,
1393,
9,
267,
3907,
360,
11470,
1648,
63,
4755,
80,
14,
647,
297,
291,
14,
1861,
14,
1393,
9,
267,
3907,
360,
11470,
1648,
63,
9765,
2852,
14,
647,
297,
291,
14,
1861,
14,
1393,
9,
267,
3907,
360,
11470,
1648,
63,
2330,
14,
647,
297,
291,
14,
1861,
14,
1393,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
samdoshi/teletype
|
utils/docs.py
|
1
|
6073
|
#!/usr/bin/env python3
import sys
from pathlib import Path
import jinja2
import pypandoc
import pytoml as toml
from common import list_ops, list_mods, validate_toml, get_tt_version
if (sys.version_info.major, sys.version_info.minor) < (3, 6):
raise Exception("need Python 3.6 or later")
THIS_FILE = Path(__file__).resolve()
ROOT_DIR = THIS_FILE.parent.parent
TEMPLATE_DIR = ROOT_DIR / "utils" / "templates"
DOCS_DIR = ROOT_DIR / "docs"
OP_DOCS_DIR = DOCS_DIR / "ops"
FONTS_DIR = ROOT_DIR / "utils" / "fonts"
TT_VERSION = get_tt_version()
VERSION_STR = " ".join(["Teletype", TT_VERSION["tag"], TT_VERSION["hash"],
"Documentation"])
env = jinja2.Environment(
autoescape=False,
loader=jinja2.FileSystemLoader(str(TEMPLATE_DIR)),
trim_blocks=True,
lstrip_blocks=True,
cache_size=0,
auto_reload=True
)
# determines the order in which sections are displayed
OPS_SECTIONS = [
"variables",
"hardware",
"patterns",
"controlflow",
"maths",
"metronome",
"delay",
"stack",
"queue",
"turtle",
"grid",
"ansible",
"whitewhale",
"meadowphysics",
"earthsea",
"orca",
"justfriends",
"telex_i",
"telex_o",
"er301",
"fader",
"wslash",
"matrixarchate"
]
def deep_merge_dict(source, destination):
for key, value in source.items():
if isinstance(value, dict):
node = destination.setdefault(key, {})
deep_merge_dict(value, node)
else:
destination[key] = value
return destination
def common_md():
print(f"Pandoc version: {pypandoc.get_pandoc_version()}")
print(f"Using docs directory: {DOCS_DIR}")
print(f"Using ops docs directory: {OP_DOCS_DIR}")
print()
op_table_template = env.get_template("op_table.jinja2.md")
op_extended_template = env.get_template("op_extended.jinja2.md")
output = ""
output += Path(DOCS_DIR / "intro.md") \
.read_text().replace("VERSION", TT_VERSION["tag"][1:]) + "\n\n"
output += Path(DOCS_DIR / "whats_new.md").read_text() + "\n\n"
output += Path(DOCS_DIR / "quickstart.md").read_text() + "\n\n"
output += Path(DOCS_DIR / "keys.md").read_text() + "\n\n"
output += Path(DOCS_DIR / "ops.md").read_text() + "\n\n"
all_ops = set(list_ops()) | set(list_mods())
all_ops_dict = {}
ops_with_docs = set()
for section in OPS_SECTIONS:
md_file = Path(OP_DOCS_DIR, section + ".md")
toml_file = Path(OP_DOCS_DIR, section + ".toml")
output += "\\newpage\n"
if md_file.exists() and md_file.is_file():
print(f"Reading {md_file}")
output += md_file.read_text() + "\n\n"
output += "\n"
if toml_file.exists() and toml_file.is_file():
print(f"Reading {toml_file}")
extended = []
# n.b. Python 3.6 dicts maintain insertion order
ops = toml.loads(toml_file.read_text())
validate_toml(ops)
deep_merge_dict(ops, all_ops_dict)
for key in ops:
if key not in all_ops:
print(f" - WARNING: unknown {key}")
ops_with_docs.add(key)
if "aliases" in ops[key]:
ops_with_docs |= set(ops[key]["aliases"])
if "description" in ops[key]:
render = op_extended_template.render(name=key, **ops[key])
extended.append((key, render))
output += op_table_template.render(ops=ops.values())
output += "\n"
output += "\n".join([e[1] for e in extended]) + "\n\n"
output += Path(DOCS_DIR / "advanced.md").read_text() + "\n\n"
output += "\\appendix\n\n"
output += "# Alphabetical list of OPs and MODs\n\n"
sorted_ops = [kv[1] for kv in sorted(all_ops_dict.items())]
output += op_table_template.render(ops=sorted_ops)
output += "\n\n# Missing documentation\n\n"
missing_ops = all_ops - ops_with_docs
output += ", ".join([f"`{o}`" for o in sorted(missing_ops)]) + "\n\n"
output += Path(ROOT_DIR / "CHANGELOG.md").read_text() + "\n\n"
return output
def main():
if len(sys.argv) <= 1:
sys.exit("Please supply a filename")
input_format = "markdown"
output = common_md()
print()
for arg in sys.argv[1:]:
p = Path(arg).resolve()
print(f"Generating: {p}")
ext = p.suffix
if ext == ".md":
p.write_text(output)
elif ext == ".html":
output = "# " + VERSION_STR + "\n\n" + output
pypandoc.convert_text(
output,
format=input_format,
to="html5",
outputfile=str(p),
extra_args=["--standalone",
"--self-contained",
"--toc",
"--toc-depth=2",
"--css=" + str(TEMPLATE_DIR / "docs.css"),
"--template=" + str(TEMPLATE_DIR /
"template.html5")])
elif ext == ".pdf" or ext == ".tex":
latex_preamble = env.get_template("latex_preamble.jinja2.md")
latex = latex_preamble \
.render(title=VERSION_STR, fonts_dir=FONTS_DIR) + "\n\n"
latex += output
pandoc_version = int(pypandoc.get_pandoc_version()[0])
engine = ("--pdf-engine=xelatex"
if pandoc_version >= 2
else "--latex-engine=xelatex")
pypandoc.convert_text(
latex,
format=input_format,
to=ext[1:],
outputfile=str(p),
extra_args=["--standalone",
"--column=80",
"--toc",
"--toc-depth=2",
engine,
"--variable=papersize:A4"])
if __name__ == "__main__":
main()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
646,
984,
199,
504,
32212,
492,
6912,
199,
199,
646,
10321,
18,
199,
646,
1134,
80,
460,
679,
199,
646,
1134,
475,
757,
465,
370,
757,
199,
199,
504,
2863,
492,
769,
63,
1483,
12,
769,
63,
19709,
12,
4107,
63,
475,
757,
12,
664,
63,
6215,
63,
1023,
199,
199,
692,
334,
1274,
14,
1023,
63,
815,
14,
8452,
12,
984,
14,
1023,
63,
815,
14,
11067,
9,
665,
334,
19,
12,
1227,
304,
272,
746,
2186,
480,
9321,
2018,
650,
14,
22,
503,
2945,
531,
199,
199,
24571,
63,
3817,
275,
6912,
3460,
493,
28634,
6983,
342,
199,
5441,
63,
3022,
275,
5749,
63,
3817,
14,
1708,
14,
1708,
199,
7433,
63,
3022,
275,
16547,
63,
3022,
1182,
298,
1208,
2,
1182,
298,
5876,
2,
199,
30072,
63,
3022,
275,
16547,
63,
3022,
1182,
298,
4757,
2,
199,
1938,
63,
30072,
63,
3022,
275,
3506,
3298,
63,
3022,
1182,
298,
1483,
2,
199,
18398,
51,
63,
3022,
275,
16547,
63,
3022,
1182,
298,
1208,
2,
1182,
298,
19864,
2,
199,
1481,
63,
4612,
275,
664,
63,
6215,
63,
1023,
342,
199,
4612,
63,
3027,
275,
298,
3680,
904,
5234,
24944,
466,
401,
377,
52,
63,
4612,
905,
1450,
2255,
377,
52,
63,
4612,
905,
2227,
2255,
717,
298,
17763,
3135,
199,
199,
1813,
275,
10321,
18,
14,
8263,
8,
272,
19102,
29,
797,
12,
272,
5077,
29,
12264,
18,
14,
17521,
5455,
8,
495,
8,
7433,
63,
3022,
1826,
272,
11639,
63,
4166,
29,
549,
12,
272,
634,
1913,
63,
4166,
29,
549,
12,
272,
2581,
63,
890,
29,
16,
12,
272,
2599,
63,
9233,
29,
549,
199,
9,
199,
199,
3,
16756,
314,
1865,
315,
1314,
10189,
787,
9080,
199,
21665,
63,
899,
19560,
275,
359,
272,
298,
3669,
401,
272,
298,
16529,
401,
272,
298,
7435,
401,
272,
298,
31215,
276,
674,
401,
272,
298,
3442,
83,
401,
272,
298,
278,
454,
265,
1377,
401,
272,
298,
5814,
401,
272,
298,
2340,
401,
272,
298,
1825,
401,
272,
298,
25027,
401,
272,
298,
3825,
401,
272,
298,
4853,
401,
272,
298,
7510,
2191,
1895,
401,
272,
298,
278,
8369,
24724,
401,
272,
298,
2210,
273,
27590,
401,
272,
298,
269,
696,
401,
272,
298,
4764,
18024,
401,
272,
298,
266,
3113,
63,
73,
401,
272,
298,
266,
3113,
63,
79,
401,
272,
298,
281,
8507,
401,
272,
298,
667,
424,
401,
272,
298,
87,
7001,
401,
272,
298,
3642,
1047,
323,
2,
199,
61,
421,
199,
318,
13217,
63,
5628,
63,
807,
8,
1365,
12,
5724,
304,
272,
367,
790,
12,
574,
315,
1350,
14,
1744,
837,
267,
340,
1228,
8,
585,
12,
1211,
304,
288,
1031,
275,
5724,
14,
5486,
8,
498,
12,
5009,
288,
13217,
63,
5628,
63,
807,
8,
585,
12,
1031,
9,
267,
587,
26,
288,
5724,
59,
498,
61,
275,
574,
339,
372,
5724,
421,
199,
318,
2863,
63,
1064,
837,
272,
870,
8,
70,
2,
48,
460,
679,
1015,
26,
3698,
469,
647,
80,
460,
679,
14,
362,
63,
80,
460,
679,
63,
1023,
12737,
531,
272,
870,
8,
70,
2,
10369,
9149,
2082,
26,
258,
469,
30072,
63,
3022,
15412,
272,
870,
8,
70,
2,
10369,
4156,
9149,
2082,
26,
469,
1938,
63,
30072,
63,
3022,
15412,
272,
870,
342,
339,
1687,
63,
1224,
63,
1160,
275,
2589,
14,
362,
63,
1160,
480,
411,
63,
1224,
14,
12264,
18,
14,
1064,
531,
272,
1687,
63,
10525,
63,
1160,
275,
2589,
14,
362,
63,
1160,
480,
411,
63,
10525,
14,
12264,
18,
14,
1064,
531,
339,
1072,
275,
3087,
272,
1072,
847,
6912,
8,
30072,
63,
3022,
1182,
298,
18206,
14,
1064,
531,
971,
267,
1275,
739,
63,
505,
1252,
1814,
480,
4612,
401,
377,
52,
63,
4612,
905,
1450,
9210,
17,
5728,
435,
1867,
78,
60,
78,
2,
272,
1072,
847,
6912,
8,
30072,
63,
3022,
1182,
298,
2191,
1956,
63,
1222,
14,
1064,
3471,
739,
63,
505,
342,
435,
1867,
78,
60,
78,
2,
272,
1072,
847,
6912,
8,
30072,
63,
3022,
1182,
298,
28957,
14,
1064,
3471,
739,
63,
505,
342,
435,
1867,
78,
60,
78,
2,
272,
1072,
847,
6912,
8,
30072,
63,
3022,
1182,
298,
1612,
14,
1064,
3471,
739,
63,
505,
342,
435,
1867,
78,
60,
78,
2,
272,
1072,
847,
6912,
8,
30072,
63,
3022,
1182,
298,
1483,
14,
1064,
3471,
739,
63,
505,
342,
435,
1867,
78,
60,
78,
2,
339,
1006,
63,
1483,
275,
663,
8,
513,
63,
1483,
1012,
1204,
663,
8,
513,
63,
19709,
1012,
272,
1006,
63,
1483,
63,
807,
275,
1052,
339,
4156,
63,
1045,
63,
4757,
275,
663,
342,
339,
367,
3420,
315,
593,
5067,
63,
899,
19560,
26,
267,
6128,
63,
493,
275,
6912,
8,
1938,
63,
30072,
63,
3022,
12,
3420,
435,
3680,
1064,
531,
267,
370,
757,
63,
493,
275,
6912,
8,
1938,
63,
30072,
63,
3022,
12,
3420,
435,
3680,
475,
757,
531,
398,
1072,
847,
9926,
1222,
1606,
60,
78,
2,
398,
340,
6128,
63,
493,
14,
2444,
342,
436,
6128,
63,
493,
14,
374,
63,
493,
837,
288,
870,
8,
70,
2,
20568,
469,
1064,
63,
493,
15412,
288,
1072,
847,
6128,
63,
493,
14,
739,
63,
505,
342,
435,
1867,
78,
60,
78,
2,
288,
1072,
847,
1867,
78,
2,
398,
340,
370,
757,
63,
493,
14,
2444,
342,
436,
370,
757,
63,
493,
14,
374,
63,
493,
837,
288,
870,
8,
70,
2,
20568,
469,
475,
757,
63,
493,
15412,
288,
9243,
275,
942,
288,
327,
302,
14,
66,
14,
2018,
650,
14,
22,
10809,
11075,
22470,
1865,
288,
4156,
275,
370,
757,
14,
3640,
8,
475,
757,
63,
493,
14,
739,
63,
505,
1012,
288,
4107,
63,
475,
757,
8,
1483,
9,
288,
13217,
63,
5628,
63,
807,
8,
1483,
12,
1006,
63,
1483,
63,
807,
9,
288,
367,
790,
315,
4156,
26,
355,
340,
790,
440,
315,
1006,
63,
1483,
26,
490,
870,
8,
70,
2,
446,
14750,
26,
5809,
469,
498,
15412,
355,
4156,
63,
1045,
63,
4757,
14,
525,
8,
498,
9,
355,
340,
298,
8602,
2,
315,
4156,
59,
498,
2189,
490,
4156,
63,
1045,
63,
4757
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
646,
984,
199,
504,
32212,
492,
6912,
199,
199,
646,
10321,
18,
199,
646,
1134,
80,
460,
679,
199,
646,
1134,
475,
757,
465,
370,
757,
199,
199,
504,
2863,
492,
769,
63,
1483,
12,
769,
63,
19709,
12,
4107,
63,
475,
757,
12,
664,
63,
6215,
63,
1023,
199,
199,
692,
334,
1274,
14,
1023,
63,
815,
14,
8452,
12,
984,
14,
1023,
63,
815,
14,
11067,
9,
665,
334,
19,
12,
1227,
304,
272,
746,
2186,
480,
9321,
2018,
650,
14,
22,
503,
2945,
531,
199,
199,
24571,
63,
3817,
275,
6912,
3460,
493,
28634,
6983,
342,
199,
5441,
63,
3022,
275,
5749,
63,
3817,
14,
1708,
14,
1708,
199,
7433,
63,
3022,
275,
16547,
63,
3022,
1182,
298,
1208,
2,
1182,
298,
5876,
2,
199,
30072,
63,
3022,
275,
16547,
63,
3022,
1182,
298,
4757,
2,
199,
1938,
63,
30072,
63,
3022,
275,
3506,
3298,
63,
3022,
1182,
298,
1483,
2,
199,
18398,
51,
63,
3022,
275,
16547,
63,
3022,
1182,
298,
1208,
2,
1182,
298,
19864,
2,
199,
1481,
63,
4612,
275,
664,
63,
6215,
63,
1023,
342,
199,
4612,
63,
3027,
275,
298,
3680,
904,
5234,
24944,
466,
401,
377,
52,
63,
4612,
905,
1450,
2255,
377,
52,
63,
4612,
905,
2227,
2255,
717,
298,
17763,
3135,
199,
199,
1813,
275,
10321,
18,
14,
8263,
8,
272,
19102,
29,
797,
12,
272,
5077,
29,
12264,
18,
14,
17521,
5455,
8,
495,
8,
7433,
63,
3022,
1826,
272,
11639,
63,
4166,
29,
549,
12,
272,
634,
1913,
63,
4166,
29,
549,
12,
272,
2581,
63,
890,
29,
16,
12,
272,
2599,
63,
9233,
29,
549,
199,
9,
199,
199,
3,
16756,
314,
1865,
315,
1314,
10189,
787,
9080,
199,
21665,
63,
899,
19560,
275,
359,
272,
298,
3669,
401,
272,
298,
16529,
401,
272,
298,
7435,
401,
272,
298,
31215,
276,
674,
401,
272,
298,
3442,
83,
401,
272,
298,
278,
454,
265,
1377,
401,
272,
298,
5814,
401,
272,
298,
2340,
401,
272,
298,
1825,
401,
272,
298,
25027,
401,
272,
298,
3825,
401,
272,
298,
4853,
401,
272,
298,
7510,
2191,
1895,
401,
272,
298,
278,
8369,
24724,
401,
272,
298,
2210,
273,
27590,
401,
272,
298,
269,
696,
401,
272,
298,
4764,
18024,
401,
272,
298,
266,
3113,
63,
73,
401,
272,
298,
266,
3113,
63,
79,
401,
272,
298,
281,
8507,
401,
272,
298,
667,
424,
401,
272,
298,
87,
7001,
401,
272,
298,
3642,
1047,
323,
2,
199,
61,
421,
199,
318,
13217,
63,
5628,
63,
807,
8,
1365,
12,
5724,
304,
272,
367,
790,
12,
574,
315,
1350,
14,
1744,
837,
267,
340,
1228,
8,
585,
12,
1211,
304,
288,
1031,
275,
5724,
14,
5486,
8,
498,
12,
5009,
288,
13217,
63,
5628,
63,
807,
8,
585,
12,
1031,
9,
267,
587,
26,
288,
5724,
59,
498,
61,
275,
574,
339,
372,
5724,
421,
199,
318,
2863,
63,
1064,
837,
272,
870,
8,
70,
2,
48,
460,
679,
1015,
26,
3698,
469,
647,
80,
460,
679,
14,
362,
63,
80,
460,
679,
63,
1023,
12737,
531,
272,
870,
8,
70,
2,
10369,
9149,
2082,
26,
258,
469,
30072,
63,
3022,
15412,
272,
870,
8,
70,
2,
10369,
4156,
9149,
2082,
26,
469,
1938,
63,
30072,
63,
3022,
15412,
272,
870,
342,
339,
1687,
63,
1224,
63,
1160,
275,
2589,
14,
362,
63,
1160,
480,
411,
63,
1224,
14,
12264,
18,
14,
1064,
531,
272,
1687,
63,
10525,
63,
1160,
275,
2589,
14,
362,
63,
1160,
480,
411,
63,
10525,
14,
12264,
18,
14,
1064,
531,
339,
1072,
275,
3087,
272,
1072,
847,
6912,
8,
30072,
63,
3022,
1182,
298,
18206,
14,
1064,
531,
971,
267,
1275,
739,
63,
505,
1252,
1814,
480,
4612,
401,
377,
52,
63,
4612,
905,
1450,
9210,
17,
5728,
435,
1867,
78,
60,
78,
2,
272,
1072,
847,
6912,
8,
30072,
63,
3022,
1182,
298,
2191,
1956,
63,
1222,
14,
1064,
3471,
739,
63,
505,
342,
435,
1867,
78,
60,
78,
2,
272,
1072,
847,
6912,
8,
30072,
63,
3022,
1182,
298,
28957,
14,
1064,
3471,
739,
63,
505,
342,
435,
1867,
78,
60,
78,
2,
272,
1072,
847,
6912,
8,
30072,
63,
3022,
1182,
298,
1612,
14,
1064,
3471,
739,
63,
505,
342,
435,
1867,
78,
60,
78,
2,
272,
1072,
847,
6912,
8,
30072,
63,
3022,
1182,
298,
1483,
14,
1064,
3471,
739,
63,
505,
342,
435,
1867,
78,
60,
78,
2,
339,
1006,
63,
1483,
275,
663,
8,
513,
63,
1483,
1012,
1204,
663,
8,
513,
63,
19709,
1012,
272,
1006,
63,
1483,
63,
807,
275,
1052,
339,
4156,
63,
1045,
63,
4757,
275,
663,
342,
339,
367,
3420,
315,
593,
5067,
63,
899,
19560,
26,
267,
6128,
63,
493,
275,
6912,
8,
1938,
63,
30072,
63,
3022,
12,
3420,
435,
3680,
1064,
531,
267,
370,
757,
63,
493,
275,
6912,
8,
1938,
63,
30072,
63,
3022,
12,
3420,
435,
3680,
475,
757,
531,
398,
1072,
847,
9926,
1222,
1606,
60,
78,
2,
398,
340,
6128,
63,
493,
14,
2444,
342,
436,
6128,
63,
493,
14,
374,
63,
493,
837,
288,
870,
8,
70,
2,
20568,
469,
1064,
63,
493,
15412,
288,
1072,
847,
6128,
63,
493,
14,
739,
63,
505,
342,
435,
1867,
78,
60,
78,
2,
288,
1072,
847,
1867,
78,
2,
398,
340,
370,
757,
63,
493,
14,
2444,
342,
436,
370,
757,
63,
493,
14,
374,
63,
493,
837,
288,
870,
8,
70,
2,
20568,
469,
475,
757,
63,
493,
15412,
288,
9243,
275,
942,
288,
327,
302,
14,
66,
14,
2018,
650,
14,
22,
10809,
11075,
22470,
1865,
288,
4156,
275,
370,
757,
14,
3640,
8,
475,
757,
63,
493,
14,
739,
63,
505,
1012,
288,
4107,
63,
475,
757,
8,
1483,
9,
288,
13217,
63,
5628,
63,
807,
8,
1483,
12,
1006,
63,
1483,
63,
807,
9,
288,
367,
790,
315,
4156,
26,
355,
340,
790,
440,
315,
1006,
63,
1483,
26,
490,
870,
8,
70,
2,
446,
14750,
26,
5809,
469,
498,
15412,
355,
4156,
63,
1045,
63,
4757,
14,
525,
8,
498,
9,
355,
340,
298,
8602,
2,
315,
4156,
59,
498,
2189,
490,
4156,
63,
1045,
63,
4757,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ghandiosm/Test
|
addons/point_of_sale/report/pos_lines.py
|
44
|
1518
|
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import time
from openerp.osv import osv
from openerp.report import report_sxw
class pos_lines(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(pos_lines, self).__init__(cr, uid, name, context=context)
self.total = 0.0
self.localcontext.update({
'time': time,
'total_quantity': self.__total_quantity__,
'taxes':self.__taxes__,
})
def __total_quantity__(self, obj):
tot = 0
for line in obj.lines:
tot += line.qty
self.total = tot
return self.total
def __taxes__(self, obj):
self.cr.execute ( " Select acct.name from pos_order as po " \
" LEFT JOIN pos_order_line as pol ON po.id = pol.order_id " \
" LEFT JOIN product_product as pp ON pol.product_id = pp.id"
" LEFT JOIN product_taxes_rel as ptr ON pp.product_tmpl_id = ptr.prod_id " \
" LEFT JOIN account_tax as acct ON acct.id = ptr.tax_id " \
" WHERE pol.id = %s", (obj.id,))
res=self.cr.fetchone()[0]
return res
class report_pos_lines(osv.AbstractModel):
_name = 'report.point_of_sale.report_saleslines'
_inherit = 'report.abstract_report'
_template = 'point_of_sale.report_saleslines'
_wrapped_report_class = pos_lines
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
14320,
402,
28935,
14,
1666,
5113,
570,
367,
2615,
4248,
436,
32572,
2436,
14,
199,
199,
646,
900,
199,
504,
5166,
14,
4795,
492,
9506,
199,
504,
5166,
14,
3070,
492,
3622,
63,
20851,
421,
199,
533,
2086,
63,
1278,
8,
3070,
63,
20851,
14,
16300,
63,
1122,
304,
339,
347,
636,
826,
721,
277,
12,
2467,
12,
1747,
12,
536,
12,
1067,
304,
267,
1613,
8,
1712,
63,
1278,
12,
291,
2843,
826,
721,
1556,
12,
1747,
12,
536,
12,
1067,
29,
1100,
9,
267,
291,
14,
2923,
275,
378,
14,
16,
267,
291,
14,
17886,
14,
873,
2561,
288,
283,
521,
356,
900,
12,
288,
283,
2923,
63,
10577,
356,
291,
855,
2923,
63,
10577,
3108,
288,
283,
22272,
356,
277,
855,
22272,
3108,
398,
3828,
339,
347,
636,
2923,
63,
10577,
721,
277,
12,
1559,
304,
267,
12657,
275,
378,
267,
367,
1004,
315,
1559,
14,
1278,
26,
288,
12657,
847,
1004,
14,
5643,
267,
291,
14,
2923,
275,
12657,
267,
372,
291,
14,
2923,
339,
347,
636,
22272,
721,
277,
12,
1559,
304,
267,
291,
14,
1556,
14,
2526,
334,
298,
9496,
29468,
14,
354,
687,
2086,
63,
1648,
465,
1115,
298,
971,
2892,
298,
6578,
10593,
2086,
63,
1648,
63,
604,
465,
3708,
5258,
1115,
14,
344,
275,
3708,
14,
1648,
63,
344,
298,
971,
2892,
298,
6578,
10593,
3336,
63,
2558,
465,
11618,
5258,
3708,
14,
2558,
63,
344,
275,
11618,
14,
344,
2,
2892,
298,
6578,
10593,
3336,
63,
22272,
63,
3369,
465,
12448,
5258,
11618,
14,
2558,
63,
11510,
63,
344,
275,
12448,
14,
8788,
63,
344,
298,
971,
2892,
298,
6578,
10593,
2933,
63,
5530,
465,
29468,
5258,
29468,
14,
344,
275,
12448,
14,
5530,
63,
344,
298,
971,
2892,
298,
6038,
3708,
14,
344,
275,
450,
83,
401,
334,
1113,
14,
344,
4641,
267,
522,
29,
277,
14,
1556,
14,
11591,
3430,
16,
61,
267,
372,
522,
421,
199,
533,
3622,
63,
1712,
63,
1278,
8,
4795,
14,
8458,
1685,
304,
272,
485,
354,
275,
283,
3070,
14,
1403,
63,
1618,
63,
8515,
14,
3070,
63,
16175,
1278,
7,
272,
485,
6486,
275,
283,
3070,
14,
6198,
63,
3070,
7,
272,
485,
1160,
275,
283,
1403,
63,
1618,
63,
8515,
14,
3070,
63,
16175,
1278,
7,
272,
485,
9130,
63,
3070,
63,
533,
275,
2086,
63,
1278,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
14320,
402,
28935,
14,
1666,
5113,
570,
367,
2615,
4248,
436,
32572,
2436,
14,
199,
199,
646,
900,
199,
504,
5166,
14,
4795,
492,
9506,
199,
504,
5166,
14,
3070,
492,
3622,
63,
20851,
421,
199,
533,
2086,
63,
1278,
8,
3070,
63,
20851,
14,
16300,
63,
1122,
304,
339,
347,
636,
826,
721,
277,
12,
2467,
12,
1747,
12,
536,
12,
1067,
304,
267,
1613,
8,
1712,
63,
1278,
12,
291,
2843,
826,
721,
1556,
12,
1747,
12,
536,
12,
1067,
29,
1100,
9,
267,
291,
14,
2923,
275,
378,
14,
16,
267,
291,
14,
17886,
14,
873,
2561,
288,
283,
521,
356,
900,
12,
288,
283,
2923,
63,
10577,
356,
291,
855,
2923,
63,
10577,
3108,
288,
283,
22272,
356,
277,
855,
22272,
3108,
398,
3828,
339,
347,
636,
2923,
63,
10577,
721,
277,
12,
1559,
304,
267,
12657,
275,
378,
267,
367,
1004,
315,
1559,
14,
1278,
26,
288,
12657,
847,
1004,
14,
5643,
267,
291,
14,
2923,
275,
12657,
267,
372,
291,
14,
2923,
339,
347,
636,
22272,
721,
277,
12,
1559,
304,
267,
291,
14,
1556,
14,
2526,
334,
298,
9496,
29468,
14,
354,
687,
2086,
63,
1648,
465,
1115,
298,
971,
2892,
298,
6578,
10593,
2086,
63,
1648,
63,
604,
465,
3708,
5258,
1115,
14,
344,
275,
3708,
14,
1648,
63,
344,
298,
971,
2892,
298,
6578,
10593,
3336,
63,
2558,
465,
11618,
5258,
3708,
14,
2558,
63,
344,
275,
11618,
14,
344,
2,
2892,
298,
6578,
10593,
3336,
63,
22272,
63,
3369,
465,
12448,
5258,
11618,
14,
2558,
63,
11510,
63,
344,
275,
12448,
14,
8788,
63,
344,
298,
971,
2892,
298,
6578,
10593,
2933,
63,
5530,
465,
29468,
5258,
29468,
14,
344,
275,
12448,
14,
5530,
63,
344,
298,
971,
2892,
298,
6038,
3708,
14,
344,
275,
450,
83,
401,
334,
1113,
14,
344,
4641,
267,
522,
29,
277,
14,
1556,
14,
11591,
3430,
16,
61,
267,
372,
522,
421,
199,
533,
3622,
63,
1712,
63,
1278,
8,
4795,
14,
8458,
1685,
304,
272,
485,
354,
275,
283,
3070,
14,
1403,
63,
1618,
63,
8515,
14,
3070,
63,
16175,
1278,
7,
272,
485,
6486,
275,
283,
3070,
14,
6198,
63,
3070,
7,
272,
485,
1160,
275,
283,
1403,
63,
1618,
63,
8515,
14,
3070,
63,
16175,
1278,
7,
272,
485,
9130,
63,
3070,
63,
533,
275,
2086,
63,
1278,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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from coverage.version import __version__, __url__
from coverage.control import coverage, process_startup
from coverage.data import CoverageData
from coverage.cmdline import main, CoverageScript
from coverage.misc import CoverageException
# Module-level functions. The original API to this module was based on
# functions defined directly in the module, with a singleton of the coverage()
# class. That design hampered programmability, so the current api uses
# explicitly-created coverage objects. But for backward compatibility, here we
# define the top-level functions to create the singleton when they are first
# called.
# Singleton object for use with module-level functions. The singleton is
# created as needed when one of the module-level functions is called.
_the_coverage = None
def _singleton_method(name):
"""Return a function to the `name` method on a singleton `coverage` object.
The singleton object is created the first time one of these functions is
called.
"""
# Disable pylint msg W0612, because a bunch of variables look unused, but
# they're accessed via locals().
# pylint: disable=W0612
def wrapper(*args, **kwargs):
"""Singleton wrapper around a coverage method."""
global _the_coverage
if not _the_coverage:
_the_coverage = coverage(auto_data=True)
return getattr(_the_coverage, name)(*args, **kwargs)
import inspect
meth = getattr(coverage, name)
args, varargs, kw, defaults = inspect.getargspec(meth)
argspec = inspect.formatargspec(args[1:], varargs, kw, defaults)
docstring = meth.__doc__
wrapper.__doc__ = ("""\
A first-use-singleton wrapper around coverage.%(name)s.
This wrapper is provided for backward compatibility with legacy code.
New code should use coverage.%(name)s directly.
%(name)s%(argspec)s:
%(docstring)s
""" % locals()
)
return wrapper
# Define the module-level functions.
use_cache = _singleton_method('use_cache')
start = _singleton_method('start')
stop = _singleton_method('stop')
erase = _singleton_method('erase')
exclude = _singleton_method('exclude')
analysis = _singleton_method('analysis')
analysis2 = _singleton_method('analysis2')
report = _singleton_method('report')
annotate = _singleton_method('annotate')
# On Windows, we encode and decode deep enough that something goes wrong and
# the encodings.utf_8 module is loaded and then unloaded, I don't know why.
# Adding a reference here prevents it from being unloaded. Yuk.
import encodings.utf_8
# Because of the "from coverage.control import fooey" lines at the top of the
# file, there's an entry for coverage.coverage in sys.modules, mapped to None.
# This makes some inspection tools (like pydoc) unable to find the class
# coverage.coverage. So remove that entry.
import sys
try:
del sys.modules['coverage.coverage']
except KeyError:
pass
# COPYRIGHT AND LICENSE
#
# Copyright 2001 Gareth Rees. All rights reserved.
# Copyright 2004-2013 Ned Batchelder. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the
# distribution.
#
# 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
# HOLDERS AND 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.
|
bsd-3-clause
|
[
624,
3034,
11745,
18216,
367,
2018,
14,
199,
199,
46,
379,
17206,
352,
424,
199,
1014,
921,
7439,
2912,
352,
424,
14,
957,
15,
600,
15,
10828,
199,
199,
624,
199,
199,
504,
11745,
14,
1023,
492,
636,
1023,
3108,
636,
633,
363,
199,
199,
504,
11745,
14,
2785,
492,
11745,
12,
2112,
63,
16480,
199,
504,
11745,
14,
576,
492,
1849,
3652,
1451,
199,
504,
11745,
14,
15612,
492,
2446,
12,
1849,
3652,
5229,
199,
504,
11745,
14,
9923,
492,
1849,
3652,
1726,
199,
199,
3,
5673,
13,
1896,
3423,
14,
221,
710,
3379,
3261,
370,
642,
859,
1990,
4079,
641,
199,
3,
3423,
3247,
5370,
315,
314,
859,
12,
543,
282,
19768,
402,
314,
11745,
342,
199,
3,
1021,
14,
221,
10314,
12899,
394,
5282,
16179,
557,
7359,
3616,
12,
880,
314,
1453,
2986,
4440,
199,
3,
7662,
13,
3966,
11745,
2251,
14,
221,
11017,
367,
13388,
7163,
12,
2348,
781,
199,
3,
5627,
314,
2746,
13,
1896,
3423,
370,
1218,
314,
19768,
1380,
2985,
787,
1642,
199,
3,
2797,
14,
199,
199,
3,
13050,
1860,
909,
367,
675,
543,
859,
13,
1896,
3423,
14,
221,
710,
19768,
365,
199,
3,
2737,
465,
4346,
1380,
1373,
402,
314,
859,
13,
1896,
3423,
365,
2797,
14,
199,
63,
1589,
63,
10828,
275,
488,
199,
199,
318,
485,
24675,
63,
765,
8,
354,
304,
272,
408,
1767,
282,
805,
370,
314,
658,
354,
64,
1083,
641,
282,
19768,
658,
10828,
64,
909,
14,
339,
710,
19768,
909,
365,
2737,
314,
1642,
900,
1373,
402,
3520,
3423,
365,
272,
2797,
14,
339,
408,
272,
327,
17534,
4287,
1499,
644,
1690,
713,
12,
2952,
282,
22219,
402,
2860,
3648,
9563,
12,
1325,
272,
327,
2985,
3984,
13810,
4799,
9480,
1252,
272,
327,
4287,
26,
3507,
29,
55,
1690,
713,
339,
347,
4975,
2031,
589,
12,
1011,
958,
304,
267,
408,
28456,
4975,
6818,
282,
11745,
1083,
1041,
267,
2288,
485,
1589,
63,
10828,
267,
340,
440,
485,
1589,
63,
10828,
26,
288,
485,
1589,
63,
10828,
275,
11745,
8,
2495,
63,
576,
29,
549,
9,
267,
372,
2519,
1547,
1589,
63,
10828,
12,
536,
25967,
589,
12,
1011,
958,
9,
339,
492,
6485,
272,
12750,
275,
2519,
8,
10828,
12,
536,
9,
272,
1249,
12,
23377,
12,
4775,
12,
4243,
275,
6485,
14,
29836,
8,
5247,
9,
272,
26632,
275,
6485,
14,
908,
15644,
8,
589,
59,
17,
8429,
23377,
12,
4775,
12,
4243,
9,
272,
9214,
275,
12750,
855,
1301,
363,
272,
4975,
855,
1301,
363,
275,
334,
19659,
267,
437,
1642,
13,
1180,
13,
24675,
4975,
6818,
11745,
31706,
354,
9,
83,
14,
398,
961,
4975,
365,
2741,
367,
13388,
7163,
543,
12139,
1233,
14,
267,
7053,
1233,
1077,
675,
11745,
31706,
354,
9,
83,
5370,
14,
398,
2818,
354,
9,
83,
2840,
15644,
9,
83,
26,
398,
2818,
12485,
9,
83,
267,
408,
450,
9480,
342,
267,
776,
339,
372,
4975,
421,
199,
3,
13930,
314,
859,
13,
1896,
3423,
14,
199,
1180,
63,
1637,
275,
485,
24675,
63,
765,
360,
1180,
63,
1637,
358,
199,
928,
275,
258,
485,
24675,
63,
765,
360,
928,
358,
199,
2379,
275,
420,
485,
24675,
63,
765,
360,
2379,
358,
199,
22087,
275,
258,
485,
24675,
63,
765,
360,
22087,
358,
199,
5473,
275,
257,
485,
24675,
63,
765,
360,
5473,
358,
199,
10466,
275,
221,
485,
24675,
63,
765,
360,
10466,
358,
199,
10466,
18,
275,
485,
24675,
63,
765,
360,
10466,
18,
358,
199,
3070,
275,
259,
485,
24675,
63,
765,
360,
3070,
358,
199,
10898,
275,
221,
485,
24675,
63,
765,
360,
10898,
358,
421,
199,
3,
4068,
5417,
12,
781,
3752,
436,
4849,
13217,
8321,
626,
6020,
13538,
6835,
436,
199,
3,
314,
14134,
14,
1624,
63,
24,
859,
365,
6511,
436,
2066,
625,
4591,
12,
473,
2793,
1133,
5715,
10842,
14,
199,
3,
12934,
282,
3659,
2348,
21925,
652,
687,
3769,
625,
4591,
14,
221,
1488,
3210,
14,
199,
646,
14134,
14,
1624,
63,
24,
199,
199,
3,
13821,
402,
314,
298,
504,
11745,
14,
2785,
492,
3925,
14655,
2,
2385,
737,
314,
2746,
402,
314,
199,
3,
570,
12,
2337,
1159,
376,
2397,
367,
11745,
14,
10828,
315,
984,
14,
3112,
12,
9994,
370,
488,
14,
199,
3,
961,
7704,
2005,
5261,
10303,
7249,
334,
2930,
29164,
9,
17329,
370,
2342,
314,
1021,
199,
3,
11745,
14,
10828,
14,
221,
2002,
2813,
626,
2397,
14,
199,
646,
984,
199,
893,
26,
272,
2150,
984,
14,
3112,
459,
10828,
14,
10828,
418,
199,
2590,
4067,
26,
272,
986,
421,
199,
3,
5877,
2401,
5113,
199,
3,
199,
3,
1898,
12521,
598,
1530,
273,
799,
397,
14,
221,
2900,
4481,
4644,
14,
199,
3,
1898,
8353,
13,
6965,
653,
379,
17206,
352,
424,
14,
221,
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,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
259,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
259,
4084,
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,
8164,
2401,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
199,
3,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
199,
3,
5258,
1821,
9815,
1634,
5603,
12
] |
[
3034,
11745,
18216,
367,
2018,
14,
199,
199,
46,
379,
17206,
352,
424,
199,
1014,
921,
7439,
2912,
352,
424,
14,
957,
15,
600,
15,
10828,
199,
199,
624,
199,
199,
504,
11745,
14,
1023,
492,
636,
1023,
3108,
636,
633,
363,
199,
199,
504,
11745,
14,
2785,
492,
11745,
12,
2112,
63,
16480,
199,
504,
11745,
14,
576,
492,
1849,
3652,
1451,
199,
504,
11745,
14,
15612,
492,
2446,
12,
1849,
3652,
5229,
199,
504,
11745,
14,
9923,
492,
1849,
3652,
1726,
199,
199,
3,
5673,
13,
1896,
3423,
14,
221,
710,
3379,
3261,
370,
642,
859,
1990,
4079,
641,
199,
3,
3423,
3247,
5370,
315,
314,
859,
12,
543,
282,
19768,
402,
314,
11745,
342,
199,
3,
1021,
14,
221,
10314,
12899,
394,
5282,
16179,
557,
7359,
3616,
12,
880,
314,
1453,
2986,
4440,
199,
3,
7662,
13,
3966,
11745,
2251,
14,
221,
11017,
367,
13388,
7163,
12,
2348,
781,
199,
3,
5627,
314,
2746,
13,
1896,
3423,
370,
1218,
314,
19768,
1380,
2985,
787,
1642,
199,
3,
2797,
14,
199,
199,
3,
13050,
1860,
909,
367,
675,
543,
859,
13,
1896,
3423,
14,
221,
710,
19768,
365,
199,
3,
2737,
465,
4346,
1380,
1373,
402,
314,
859,
13,
1896,
3423,
365,
2797,
14,
199,
63,
1589,
63,
10828,
275,
488,
199,
199,
318,
485,
24675,
63,
765,
8,
354,
304,
272,
408,
1767,
282,
805,
370,
314,
658,
354,
64,
1083,
641,
282,
19768,
658,
10828,
64,
909,
14,
339,
710,
19768,
909,
365,
2737,
314,
1642,
900,
1373,
402,
3520,
3423,
365,
272,
2797,
14,
339,
408,
272,
327,
17534,
4287,
1499,
644,
1690,
713,
12,
2952,
282,
22219,
402,
2860,
3648,
9563,
12,
1325,
272,
327,
2985,
3984,
13810,
4799,
9480,
1252,
272,
327,
4287,
26,
3507,
29,
55,
1690,
713,
339,
347,
4975,
2031,
589,
12,
1011,
958,
304,
267,
408,
28456,
4975,
6818,
282,
11745,
1083,
1041,
267,
2288,
485,
1589,
63,
10828,
267,
340,
440,
485,
1589,
63,
10828,
26,
288,
485,
1589,
63,
10828,
275,
11745,
8,
2495,
63,
576,
29,
549,
9,
267,
372,
2519,
1547,
1589,
63,
10828,
12,
536,
25967,
589,
12,
1011,
958,
9,
339,
492,
6485,
272,
12750,
275,
2519,
8,
10828,
12,
536,
9,
272,
1249,
12,
23377,
12,
4775,
12,
4243,
275,
6485,
14,
29836,
8,
5247,
9,
272,
26632,
275,
6485,
14,
908,
15644,
8,
589,
59,
17,
8429,
23377,
12,
4775,
12,
4243,
9,
272,
9214,
275,
12750,
855,
1301,
363,
272,
4975,
855,
1301,
363,
275,
334,
19659,
267,
437,
1642,
13,
1180,
13,
24675,
4975,
6818,
11745,
31706,
354,
9,
83,
14,
398,
961,
4975,
365,
2741,
367,
13388,
7163,
543,
12139,
1233,
14,
267,
7053,
1233,
1077,
675,
11745,
31706,
354,
9,
83,
5370,
14,
398,
2818,
354,
9,
83,
2840,
15644,
9,
83,
26,
398,
2818,
12485,
9,
83,
267,
408,
450,
9480,
342,
267,
776,
339,
372,
4975,
421,
199,
3,
13930,
314,
859,
13,
1896,
3423,
14,
199,
1180,
63,
1637,
275,
485,
24675,
63,
765,
360,
1180,
63,
1637,
358,
199,
928,
275,
258,
485,
24675,
63,
765,
360,
928,
358,
199,
2379,
275,
420,
485,
24675,
63,
765,
360,
2379,
358,
199,
22087,
275,
258,
485,
24675,
63,
765,
360,
22087,
358,
199,
5473,
275,
257,
485,
24675,
63,
765,
360,
5473,
358,
199,
10466,
275,
221,
485,
24675,
63,
765,
360,
10466,
358,
199,
10466,
18,
275,
485,
24675,
63,
765,
360,
10466,
18,
358,
199,
3070,
275,
259,
485,
24675,
63,
765,
360,
3070,
358,
199,
10898,
275,
221,
485,
24675,
63,
765,
360,
10898,
358,
421,
199,
3,
4068,
5417,
12,
781,
3752,
436,
4849,
13217,
8321,
626,
6020,
13538,
6835,
436,
199,
3,
314,
14134,
14,
1624,
63,
24,
859,
365,
6511,
436,
2066,
625,
4591,
12,
473,
2793,
1133,
5715,
10842,
14,
199,
3,
12934,
282,
3659,
2348,
21925,
652,
687,
3769,
625,
4591,
14,
221,
1488,
3210,
14,
199,
646,
14134,
14,
1624,
63,
24,
199,
199,
3,
13821,
402,
314,
298,
504,
11745,
14,
2785,
492,
3925,
14655,
2,
2385,
737,
314,
2746,
402,
314,
199,
3,
570,
12,
2337,
1159,
376,
2397,
367,
11745,
14,
10828,
315,
984,
14,
3112,
12,
9994,
370,
488,
14,
199,
3,
961,
7704,
2005,
5261,
10303,
7249,
334,
2930,
29164,
9,
17329,
370,
2342,
314,
1021,
199,
3,
11745,
14,
10828,
14,
221,
2002,
2813,
626,
2397,
14,
199,
646,
984,
199,
893,
26,
272,
2150,
984,
14,
3112,
459,
10828,
14,
10828,
418,
199,
2590,
4067,
26,
272,
986,
421,
199,
3,
5877,
2401,
5113,
199,
3,
199,
3,
1898,
12521,
598,
1530,
273,
799,
397,
14,
221,
2900,
4481,
4644,
14,
199,
3,
1898,
8353,
13,
6965,
653,
379,
17206,
352,
424,
14,
221,
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,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
259,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
259,
4084,
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,
8164,
2401,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
199,
3,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
199,
3,
5258,
1821,
9815,
1634,
5603,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
mylokin/redisext
|
tests/test_expire.py
|
1
|
1260
|
from __future__ import absolute_import
import redisext.counter
import redisext.key
import redisext.serializer
from . import fixture
class ExpireCounter(redisext.counter.Counter, redisext.key.Expire):
EXPIRE = 60
CONNECTION = fixture.Connection
SERIALIZER = redisext.serializer.Numeric
class ExpireCounterTestCase(fixture.TestCase):
def setUp(self):
self.counter = ExpireCounter('key')
self.counter.incr()
self.counter.expire()
def test_expire(self):
self.assertTrue(60 >= self.counter.ttl() > 0)
def test_persist(self):
self.counter.persist()
self.assertEqual(self.counter.ttl(), -1)
class UnspecifiedExpireCounter(redisext.counter.Counter, redisext.key.Expire):
CONNECTION = fixture.Connection
SERIALIZER = redisext.serializer.Numeric
class UnspecifiedExpireCounterTestCase(fixture.TestCase):
def setUp(self):
self.counter = UnspecifiedExpireCounter('key')
def test_expire_unspecified(self):
self.counter.incr()
with self.assertRaises(ValueError):
self.counter.expire()
def test_expire_specified(self):
self.counter.incr()
self.counter.expire(60)
self.assertTrue(60 >= self.counter.ttl() > 0)
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
295,
328,
261,
400,
14,
5337,
199,
646,
295,
328,
261,
400,
14,
498,
199,
646,
295,
328,
261,
400,
14,
8349,
199,
199,
504,
1275,
492,
10949,
421,
199,
533,
1316,
1038,
264,
11348,
8,
264,
328,
261,
400,
14,
5337,
14,
11348,
12,
295,
328,
261,
400,
14,
498,
14,
14000,
264,
304,
272,
3651,
2252,
907,
275,
5212,
272,
11287,
275,
10949,
14,
3225,
272,
7017,
4938,
5357,
540,
275,
295,
328,
261,
400,
14,
8349,
14,
14687,
421,
199,
533,
1316,
1038,
264,
11348,
1746,
8,
5997,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
5337,
275,
1316,
1038,
264,
11348,
360,
498,
358,
267,
291,
14,
5337,
14,
19362,
342,
267,
291,
14,
5337,
14,
14691,
342,
339,
347,
511,
63,
14691,
8,
277,
304,
267,
291,
14,
1815,
8,
2259,
2356,
291,
14,
5337,
14,
12130,
342,
690,
378,
9,
339,
347,
511,
63,
23619,
8,
277,
304,
267,
291,
14,
5337,
14,
23619,
342,
267,
291,
14,
629,
8,
277,
14,
5337,
14,
12130,
1062,
446,
17,
9,
421,
199,
533,
15254,
28387,
14000,
264,
11348,
8,
264,
328,
261,
400,
14,
5337,
14,
11348,
12,
295,
328,
261,
400,
14,
498,
14,
14000,
264,
304,
272,
11287,
275,
10949,
14,
3225,
272,
7017,
4938,
5357,
540,
275,
295,
328,
261,
400,
14,
8349,
14,
14687,
421,
199,
533,
15254,
28387,
14000,
264,
11348,
1746,
8,
5997,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
5337,
275,
15254,
28387,
14000,
264,
11348,
360,
498,
358,
339,
347,
511,
63,
14691,
63,
324,
10085,
8,
277,
304,
267,
291,
14,
5337,
14,
19362,
342,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
291,
14,
5337,
14,
14691,
342,
339,
347,
511,
63,
14691,
63,
10085,
8,
277,
304,
267,
291,
14,
5337,
14,
19362,
342,
267,
291,
14,
5337,
14,
14691,
8,
2259,
9,
267,
291,
14,
1815,
8,
2259,
2356,
291,
14,
5337,
14,
12130,
342,
690,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
295,
328,
261,
400,
14,
5337,
199,
646,
295,
328,
261,
400,
14,
498,
199,
646,
295,
328,
261,
400,
14,
8349,
199,
199,
504,
1275,
492,
10949,
421,
199,
533,
1316,
1038,
264,
11348,
8,
264,
328,
261,
400,
14,
5337,
14,
11348,
12,
295,
328,
261,
400,
14,
498,
14,
14000,
264,
304,
272,
3651,
2252,
907,
275,
5212,
272,
11287,
275,
10949,
14,
3225,
272,
7017,
4938,
5357,
540,
275,
295,
328,
261,
400,
14,
8349,
14,
14687,
421,
199,
533,
1316,
1038,
264,
11348,
1746,
8,
5997,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
5337,
275,
1316,
1038,
264,
11348,
360,
498,
358,
267,
291,
14,
5337,
14,
19362,
342,
267,
291,
14,
5337,
14,
14691,
342,
339,
347,
511,
63,
14691,
8,
277,
304,
267,
291,
14,
1815,
8,
2259,
2356,
291,
14,
5337,
14,
12130,
342,
690,
378,
9,
339,
347,
511,
63,
23619,
8,
277,
304,
267,
291,
14,
5337,
14,
23619,
342,
267,
291,
14,
629,
8,
277,
14,
5337,
14,
12130,
1062,
446,
17,
9,
421,
199,
533,
15254,
28387,
14000,
264,
11348,
8,
264,
328,
261,
400,
14,
5337,
14,
11348,
12,
295,
328,
261,
400,
14,
498,
14,
14000,
264,
304,
272,
11287,
275,
10949,
14,
3225,
272,
7017,
4938,
5357,
540,
275,
295,
328,
261,
400,
14,
8349,
14,
14687,
421,
199,
533,
15254,
28387,
14000,
264,
11348,
1746,
8,
5997,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
5337,
275,
15254,
28387,
14000,
264,
11348,
360,
498,
358,
339,
347,
511,
63,
14691,
63,
324,
10085,
8,
277,
304,
267,
291,
14,
5337,
14,
19362,
342,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
291,
14,
5337,
14,
14691,
342,
339,
347,
511,
63,
14691,
63,
10085,
8,
277,
304,
267,
291,
14,
5337,
14,
19362,
342,
267,
291,
14,
5337,
14,
14691,
8,
2259,
9,
267,
291,
14,
1815,
8,
2259,
2356,
291,
14,
5337,
14,
12130,
342,
690,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
GetSomeBlocks/ServerStatus
|
resources/lib/IMDbPY/imdb/parser/http/bsouplxml/etree.py
|
143
|
2728
|
"""
parser.http.bsouplxml.etree module (imdb.parser.http package).
This module adapts the beautifulsoup interface to lxml.etree module.
Copyright 2008 H. Turgut Uyar <uyar@tekir.org>
2008 Davide Alberani <da@erlug.linux.it>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
import _bsoup as BeautifulSoup
from _bsoup import Tag as Element
import bsoupxpath
# Not directly used by IMDbPY, but do not remove: it's used by IMDbPYKit,
# for example.
def fromstring(xml_string):
"""Return a DOM representation of the string."""
# We try to not use BeautifulSoup.BeautifulStoneSoup.XML_ENTITIES,
# for convertEntities.
return BeautifulSoup.BeautifulStoneSoup(xml_string,
convertEntities=None).findChild(True)
def tostring(element, encoding=None, pretty_print=False):
"""Return a string or unicode representation of an element."""
if encoding is unicode:
encoding = None
# For BeautifulSoup 3.1
#encArgs = {'prettyPrint': pretty_print}
#if encoding is not None:
# encArgs['encoding'] = encoding
#return element.encode(**encArgs)
return element.__str__(encoding, pretty_print)
def setattribute(tag, name, value):
tag[name] = value
def xpath(node, expr):
"""Apply an xpath expression to a node. Return a list of nodes."""
#path = bsoupxpath.Path(expr)
path = bsoupxpath.get_path(expr)
return path.apply(node)
# XXX: monkey patching the beautifulsoup tag class
class _EverythingIsNestable(dict):
""""Fake that every tag is nestable."""
def get(self, key, *args, **kwds):
return []
BeautifulSoup.BeautifulStoneSoup.NESTABLE_TAGS = _EverythingIsNestable()
BeautifulSoup.Tag.tag = property(fget=lambda self: self.name)
BeautifulSoup.Tag.attrib = property(fget=lambda self: self)
BeautifulSoup.Tag.text = property(fget=lambda self: self.string)
BeautifulSoup.Tag.set = setattribute
BeautifulSoup.Tag.getparent = lambda self: self.parent
BeautifulSoup.Tag.drop_tree = BeautifulSoup.Tag.extract
BeautifulSoup.Tag.xpath = xpath
# TODO: setting the text attribute for tags
|
mit
|
[
624,
199,
2087,
14,
1014,
14,
66,
9317,
22899,
14,
9464,
859,
334,
17117,
14,
2087,
14,
1014,
2559,
680,
199,
199,
2765,
859,
1503,
439,
1086,
314,
506,
25146,
9317,
3217,
370,
14490,
14,
9464,
859,
14,
199,
199,
7384,
9079,
869,
14,
377,
17629,
337,
738,
89,
285,
665,
29514,
285,
32,
266,
75,
723,
14,
1308,
30,
881,
9079,
577,
65,
5624,
4580,
605,
26455,
665,
983,
32,
281,
32047,
14,
5135,
14,
390,
30,
199,
199,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
30216,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
624,
199,
199,
646,
485,
66,
9317,
465,
17132,
199,
504,
485,
66,
9317,
492,
8053,
465,
6566,
199,
199,
646,
330,
9317,
8006,
199,
199,
3,
2832,
5370,
1202,
701,
473,
5127,
66,
4521,
12,
1325,
886,
440,
2813,
26,
652,
1159,
1202,
701,
473,
5127,
66,
4521,
14591,
12,
199,
3,
367,
2893,
14,
199,
318,
687,
875,
8,
1652,
63,
875,
304,
272,
408,
1767,
282,
14316,
6025,
402,
314,
1059,
1041,
272,
327,
2136,
862,
370,
440,
675,
17132,
14,
30117,
933,
368,
12341,
14,
4317,
63,
1309,
19144,
12,
272,
327,
367,
3957,
24672,
14,
272,
372,
17132,
14,
30117,
933,
368,
12341,
8,
1652,
63,
875,
12,
717,
3957,
24672,
29,
403,
680,
1623,
3493,
8,
549,
9,
421,
199,
318,
370,
875,
8,
2108,
12,
2644,
29,
403,
12,
7268,
63,
1361,
29,
797,
304,
272,
408,
1767,
282,
1059,
503,
2649,
6025,
402,
376,
1819,
1041,
272,
340,
2644,
365,
2649,
26,
267,
2644,
275,
488,
272,
327,
2104,
17132,
650,
14,
17,
272,
327,
10945,
6213,
275,
791,
9118,
5375,
356,
7268,
63,
1361,
93,
272,
327,
692,
2644,
365,
440,
488,
26,
272,
327,
259,
12011,
6213,
459,
2991,
418,
275,
2644,
272,
327,
1107,
1819,
14,
2143,
3682,
10945,
6213,
9,
272,
372,
1819,
855,
495,
721,
2991,
12,
7268,
63,
1361,
9,
199,
199,
318,
663,
3215,
8,
1450,
12,
536,
12,
574,
304,
272,
1947,
59,
354,
61,
275,
574,
199,
199,
318,
14462,
8,
932,
12,
5348,
304,
272,
408,
16581,
376,
14462,
3965,
370,
282,
1031,
14,
1432,
282,
769,
402,
3380,
1041,
272,
327,
515,
275,
330,
9317,
8006,
14,
2042,
8,
3684,
9,
272,
931,
275,
330,
9317,
8006,
14,
362,
63,
515,
8,
3684,
9,
272,
372,
931,
14,
4998,
8,
932,
9,
421,
199,
3,
5787,
26,
14198,
3371,
316,
314,
506,
25146,
9317,
1947,
1021,
199,
533,
485,
24527,
2127,
1831,
46,
597,
461,
8,
807,
304,
272,
408,
2,
8249,
626,
4036,
1947,
365,
10715,
461,
1041,
272,
347,
664,
8,
277,
12,
790,
12,
627,
589,
12,
1011,
10340,
304,
267,
372,
942,
199,
199,
30117,
12341,
14,
30117,
933,
368,
12341,
14,
46,
1719,
2617,
63,
17626,
275,
485,
24527,
2127,
1831,
46,
597,
461,
342,
199,
30117,
12341,
14,
1931,
14,
1450,
275,
3324,
8,
27823,
29,
2734,
291,
26,
291,
14,
354,
9,
199,
30117,
12341,
14,
1931,
14,
6640,
275,
3324,
8,
27823,
29,
2734,
291,
26,
291,
9,
199,
30117,
12341,
14,
1931,
14,
505,
275,
3324,
8,
27823,
29,
2734,
291,
26,
291,
14,
875,
9,
199,
30117,
12341,
14,
1931,
14,
409,
275,
663,
3215,
199,
30117,
12341,
14,
1931,
14,
362,
1708,
275,
2400,
291,
26,
291,
14,
1708,
199,
30117,
12341,
14,
1931,
14,
4824,
63,
2350,
275,
17132,
14,
1931,
14,
5005,
199,
30117,
12341,
14,
1931,
14,
8006,
275,
14462,
199,
199,
3,
3254,
26,
4260,
314,
1318,
2225,
367,
3762,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2087,
14,
1014,
14,
66,
9317,
22899,
14,
9464,
859,
334,
17117,
14,
2087,
14,
1014,
2559,
680,
199,
199,
2765,
859,
1503,
439,
1086,
314,
506,
25146,
9317,
3217,
370,
14490,
14,
9464,
859,
14,
199,
199,
7384,
9079,
869,
14,
377,
17629,
337,
738,
89,
285,
665,
29514,
285,
32,
266,
75,
723,
14,
1308,
30,
881,
9079,
577,
65,
5624,
4580,
605,
26455,
665,
983,
32,
281,
32047,
14,
5135,
14,
390,
30,
199,
199,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
30216,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
624,
199,
199,
646,
485,
66,
9317,
465,
17132,
199,
504,
485,
66,
9317,
492,
8053,
465,
6566,
199,
199,
646,
330,
9317,
8006,
199,
199,
3,
2832,
5370,
1202,
701,
473,
5127,
66,
4521,
12,
1325,
886,
440,
2813,
26,
652,
1159,
1202,
701,
473,
5127,
66,
4521,
14591,
12,
199,
3,
367,
2893,
14,
199,
318,
687,
875,
8,
1652,
63,
875,
304,
272,
408,
1767,
282,
14316,
6025,
402,
314,
1059,
1041,
272,
327,
2136,
862,
370,
440,
675,
17132,
14,
30117,
933,
368,
12341,
14,
4317,
63,
1309,
19144,
12,
272,
327,
367,
3957,
24672,
14,
272,
372,
17132,
14,
30117,
933,
368,
12341,
8,
1652,
63,
875,
12,
717,
3957,
24672,
29,
403,
680,
1623,
3493,
8,
549,
9,
421,
199,
318,
370,
875,
8,
2108,
12,
2644,
29,
403,
12,
7268,
63,
1361,
29,
797,
304,
272,
408,
1767,
282,
1059,
503,
2649,
6025,
402,
376,
1819,
1041,
272,
340,
2644,
365,
2649,
26,
267,
2644,
275,
488,
272,
327,
2104,
17132,
650,
14,
17,
272,
327,
10945,
6213,
275,
791,
9118,
5375,
356,
7268,
63,
1361,
93,
272,
327,
692,
2644,
365,
440,
488,
26,
272,
327,
259,
12011,
6213,
459,
2991,
418,
275,
2644,
272,
327,
1107,
1819,
14,
2143,
3682,
10945,
6213,
9,
272,
372,
1819,
855,
495,
721,
2991,
12,
7268,
63,
1361,
9,
199,
199,
318,
663,
3215,
8,
1450,
12,
536,
12,
574,
304,
272,
1947,
59,
354,
61,
275,
574,
199,
199,
318,
14462,
8,
932,
12,
5348,
304,
272,
408,
16581,
376,
14462,
3965,
370,
282,
1031,
14,
1432,
282,
769,
402,
3380,
1041,
272,
327,
515,
275,
330,
9317,
8006,
14,
2042,
8,
3684,
9,
272,
931,
275,
330,
9317,
8006,
14,
362,
63,
515,
8,
3684,
9,
272,
372,
931,
14,
4998,
8,
932,
9,
421,
199,
3,
5787,
26,
14198,
3371,
316,
314,
506,
25146,
9317,
1947,
1021,
199,
533,
485,
24527,
2127,
1831,
46,
597,
461,
8,
807,
304,
272,
408,
2,
8249,
626,
4036,
1947,
365,
10715,
461,
1041,
272,
347,
664,
8,
277,
12,
790,
12,
627,
589,
12,
1011,
10340,
304,
267,
372,
942,
199,
199,
30117,
12341,
14,
30117,
933,
368,
12341,
14,
46,
1719,
2617,
63,
17626,
275,
485,
24527,
2127,
1831,
46,
597,
461,
342,
199,
30117,
12341,
14,
1931,
14,
1450,
275,
3324,
8,
27823,
29,
2734,
291,
26,
291,
14,
354,
9,
199,
30117,
12341,
14,
1931,
14,
6640,
275,
3324,
8,
27823,
29,
2734,
291,
26,
291,
9,
199,
30117,
12341,
14,
1931,
14,
505,
275,
3324,
8,
27823,
29,
2734,
291,
26,
291,
14,
875,
9,
199,
30117,
12341,
14,
1931,
14,
409,
275,
663,
3215,
199,
30117,
12341,
14,
1931,
14,
362,
1708,
275,
2400,
291,
26,
291,
14,
1708,
199,
30117,
12341,
14,
1931,
14,
4824,
63,
2350,
275,
17132,
14,
1931,
14,
5005,
199,
30117,
12341,
14,
1931,
14,
8006,
275,
14462,
199,
199,
3,
3254,
26,
4260,
314,
1318,
2225,
367,
3762,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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ine
# In[63]:
import os
import random
import json
import shutil
# In[37]:
colordir = os.listdir('/home/wcmckee/colortest/')
# In[42]:
alcolrz = []
# In[43]:
for cold in colordir:
#print cold
if '.json' in cold:
print cold
alcolrz.append(cold)
# In[47]:
alranza = random.choice(alcolrz)
# In[48]:
alranza
# In[71]:
checkexist = os.listdir('/home/wcmckee/colortest/assignedhosts/')
assignedh = []
# In[72]:
for chex in checkexist:
print chex
assignedh.append(chex)
#os.remove('/home/wcmckee/colortest/' + chex)
# In[73]:
colordir
# In[80]:
assignedh
# In[83]:
toremvz = set(colordir) & set(assignedh)
# In[88]:
tolidt = list(toremvz)
# In[91]:
for tolid in tolidt:
print tolid
os.remove('/home/wcmckee/colortest/' + tolid)
# In[ ]:
# In[ ]:
# In[89]:
tolidt
# In[50]:
opjsflz = open('/home/wcmckee/colortest/' + alranza, 'r')
# In[51]:
nerza = opjsflz.read()
# In[53]:
nerza
# In[55]:
neadict = json.loads(nerza)
# In[8]:
opipdy = open('/home/wcmckee/colortest/freeip.txt', 'r')
iprdy = opipdy.read()
# In[12]:
ipclean = iprdy.replace('\n', ', ')
# In[13]:
ipclean
# In[15]:
ipliszq = ipclean.split(',')
# In[23]:
#New hostname is zero on the list. Need to remove this now
newhos = ipliszq[0]
# In[24]:
newhos
# In[57]:
neadict.update({'ipaddress' : newhos})
# In[58]:
neadict
# In[60]:
convjsn = json.dumps(neadict)
# In[62]:
convjsn
convipdy = open('/home/wcmckee/colortest/' + alranza, 'w')
convipdy.write(convjsn)
convipdy.close()
# In[64]:
shutil.move('/home/wcmckee/colortest/' + alranza, '/home/wcmckee/colortest/assignedhosts/')
# In[ ]:
#shutil.move('/home/wcmckee/colortest/' + alranza, '/home/wcmckee/colortest/assignedhosts/')
# In[29]:
newlisav = ipliszq[1:]
# In[35]:
newlisav
newfre = open('/home/wcmckee/colortest/freeip.txt', 'w')
for lisaw in newlisav:
#print lispo
newfre.write(str(lisaw))
newfre.write('\n')
newfre.close()
# In[19]:
for ipzq in ipliszq:
print ipzq
# In[ ]:
|
mit
|
[
199,
3,
2803,
26,
2774,
13,
24,
199,
199,
3,
2884,
370,
5090,
6246,
436,
3384,
2287,
370,
6844,
199,
199,
3,
1010,
59,
2766,
2189,
199,
199,
646,
747,
199,
646,
2196,
199,
646,
2022,
199,
646,
5145,
421,
199,
3,
1010,
59,
1401,
2189,
199,
199,
2326,
694,
275,
747,
14,
7374,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
6217,
421,
199,
3,
1010,
59,
2260,
2189,
199,
199,
279,
761,
30841,
275,
942,
421,
199,
3,
1010,
59,
2824,
2189,
199,
199,
509,
1048,
68,
315,
3164,
694,
26,
272,
327,
1361,
1048,
68,
272,
340,
1987,
1001,
7,
315,
1048,
68,
26,
267,
870,
1048,
68,
267,
741,
761,
30841,
14,
740,
8,
761,
68,
9,
421,
199,
3,
1010,
59,
2417,
2189,
199,
199,
279,
1312,
8076,
275,
2196,
14,
5095,
8,
279,
761,
30841,
9,
421,
199,
3,
1010,
59,
2006,
2189,
199,
199,
279,
1312,
8076,
421,
199,
3,
1010,
59,
3172,
2189,
199,
199,
1074,
4494,
275,
747,
14,
7374,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
15,
12941,
5146,
6217,
199,
12941,
72,
275,
942,
421,
199,
3,
1010,
59,
2819,
2189,
199,
199,
509,
286,
4097,
315,
1104,
4494,
26,
272,
870,
286,
4097,
272,
7943,
72,
14,
740,
8,
335,
476,
9,
272,
327,
736,
14,
2168,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
4805,
435,
286,
4097,
9,
421,
199,
3,
1010,
59,
2898,
2189,
199,
199,
2326,
694,
421,
199,
3,
1010,
59,
1257,
2189,
199,
199,
12941,
72,
421,
199,
3,
1010,
59,
2658,
2189,
199,
199,
475,
264,
12393,
90,
275,
663,
8,
2326,
694,
9,
1253,
663,
8,
12941,
72,
9,
421,
199,
3,
1010,
59,
1299,
2189,
199,
199,
475,
317,
3583,
275,
769,
8,
475,
264,
12393,
90,
9,
421,
199,
3,
1010,
59,
3328,
2189,
199,
199,
509,
370,
7401,
315,
370,
317,
3583,
26,
272,
870,
370,
7401,
272,
747,
14,
2168,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
4805,
435,
370,
7401,
9,
421,
199,
3,
1010,
59,
16246,
6905,
199,
3,
1010,
59,
16246,
6905,
199,
3,
1010,
59,
1407,
2189,
199,
199,
475,
317,
3583,
421,
199,
3,
1010,
59,
1400,
2189,
199,
199,
411,
3596,
2327,
90,
275,
1551,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
4805,
435,
741,
1312,
8076,
12,
283,
82,
358,
421,
199,
3,
1010,
59,
2869,
2189,
199,
199,
1372,
8076,
275,
1687,
3596,
2327,
90,
14,
739,
342,
421,
199,
3,
1010,
59,
2481,
2189,
199,
199,
1372,
8076,
421,
199,
3,
1010,
59,
1229,
2189,
199,
199,
685,
65,
807,
275,
2022,
14,
3640,
8,
1372,
8076,
9,
421,
199,
3,
1010,
59,
24,
2189,
199,
199,
411,
711,
8161,
275,
1551,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
15,
4624,
711,
14,
2424,
297,
283,
82,
358,
199,
711,
6883,
89,
275,
1687,
711,
8161,
14,
739,
342,
421,
199,
3,
1010,
59,
713,
2189,
199,
199,
711,
3118,
275,
284,
2700,
8161,
14,
1814,
2258,
78,
297,
1656,
5320,
421,
199,
3,
1010,
59,
969,
2189,
199,
199,
711,
3118,
421,
199,
3,
1010,
59,
1046,
2189,
199,
199,
711,
317,
11803,
81,
275,
284,
2352,
1270,
14,
1294,
11917,
421,
199,
3,
1010,
59,
1789,
2189,
199,
199,
3,
4665,
6246,
365,
4697,
641,
314,
769,
14,
14012,
370,
2813,
642,
3063,
199,
199,
1222,
526,
83,
275,
3384,
317,
11803,
81,
59,
16,
61,
421,
199,
3,
1010,
59,
1194,
2189,
199,
199,
1222,
526,
83,
421,
199,
3,
1010,
59,
1641,
2189,
199,
199,
685,
65,
807,
14,
873,
3252,
21809,
7,
520,
892,
526,
83,
1552,
421,
199,
3,
1010,
59,
2010,
2189,
199,
199,
685,
65,
807,
421,
199,
3,
1010,
59,
2259,
2189,
199,
199,
5598,
3596,
78,
275,
2022,
14,
4180,
8,
685,
65,
807,
9,
421,
199,
3,
1010,
59,
2789,
2189,
199,
199,
5598,
3596,
78,
199,
388,
18607,
8161,
275,
1551,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
4805,
435,
741,
1312,
8076,
12,
283,
87,
358,
199,
388,
18607,
8161,
14,
952,
8,
5598,
3596,
78,
9,
199,
388,
18607,
8161,
14,
1600,
342,
421,
199,
3,
1010,
59,
772,
2189,
199,
199,
20938,
14,
1185,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
4805,
435,
741,
1312,
8076,
12,
1994,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
15,
12941,
5146,
6217,
421,
199,
3,
1010,
59,
16246,
199,
199,
3,
20938,
14,
1185,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
4805,
435,
741,
1312,
8076,
12,
1994,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
15,
12941,
5146,
6217,
421,
199,
3,
1010,
59,
1398,
2189,
199,
199,
1222,
14392,
1214,
275,
3384,
317,
11803,
81,
59,
17,
2938,
421,
199,
3,
1010,
59,
1276,
2189,
199,
199,
1222,
14392,
1214,
199,
199,
1222,
20153,
275,
1551,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
15,
4624,
711,
14,
2424,
297,
283,
87,
358,
199,
199,
509,
1212,
2231,
87,
315,
892,
14392,
1214,
26,
272,
327,
1361,
1212,
22522,
272,
892,
20153,
14,
952,
8,
495,
8,
317,
2231,
87,
430,
272,
892,
20153,
14,
952,
2258,
78,
358,
199,
199,
1222,
20153,
14,
1600,
342,
421,
199,
3,
1010,
59,
1167,
2189,
199,
199,
509,
3384,
90,
81,
315,
3384,
317,
11803,
81,
26,
272,
870,
3384,
90,
81,
421,
199,
3,
1010,
59,
16246,
6905,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3,
2803,
26,
2774,
13,
24,
199,
199,
3,
2884,
370,
5090,
6246,
436,
3384,
2287,
370,
6844,
199,
199,
3,
1010,
59,
2766,
2189,
199,
199,
646,
747,
199,
646,
2196,
199,
646,
2022,
199,
646,
5145,
421,
199,
3,
1010,
59,
1401,
2189,
199,
199,
2326,
694,
275,
747,
14,
7374,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
6217,
421,
199,
3,
1010,
59,
2260,
2189,
199,
199,
279,
761,
30841,
275,
942,
421,
199,
3,
1010,
59,
2824,
2189,
199,
199,
509,
1048,
68,
315,
3164,
694,
26,
272,
327,
1361,
1048,
68,
272,
340,
1987,
1001,
7,
315,
1048,
68,
26,
267,
870,
1048,
68,
267,
741,
761,
30841,
14,
740,
8,
761,
68,
9,
421,
199,
3,
1010,
59,
2417,
2189,
199,
199,
279,
1312,
8076,
275,
2196,
14,
5095,
8,
279,
761,
30841,
9,
421,
199,
3,
1010,
59,
2006,
2189,
199,
199,
279,
1312,
8076,
421,
199,
3,
1010,
59,
3172,
2189,
199,
199,
1074,
4494,
275,
747,
14,
7374,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
15,
12941,
5146,
6217,
199,
12941,
72,
275,
942,
421,
199,
3,
1010,
59,
2819,
2189,
199,
199,
509,
286,
4097,
315,
1104,
4494,
26,
272,
870,
286,
4097,
272,
7943,
72,
14,
740,
8,
335,
476,
9,
272,
327,
736,
14,
2168,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
4805,
435,
286,
4097,
9,
421,
199,
3,
1010,
59,
2898,
2189,
199,
199,
2326,
694,
421,
199,
3,
1010,
59,
1257,
2189,
199,
199,
12941,
72,
421,
199,
3,
1010,
59,
2658,
2189,
199,
199,
475,
264,
12393,
90,
275,
663,
8,
2326,
694,
9,
1253,
663,
8,
12941,
72,
9,
421,
199,
3,
1010,
59,
1299,
2189,
199,
199,
475,
317,
3583,
275,
769,
8,
475,
264,
12393,
90,
9,
421,
199,
3,
1010,
59,
3328,
2189,
199,
199,
509,
370,
7401,
315,
370,
317,
3583,
26,
272,
870,
370,
7401,
272,
747,
14,
2168,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
4805,
435,
370,
7401,
9,
421,
199,
3,
1010,
59,
16246,
6905,
199,
3,
1010,
59,
16246,
6905,
199,
3,
1010,
59,
1407,
2189,
199,
199,
475,
317,
3583,
421,
199,
3,
1010,
59,
1400,
2189,
199,
199,
411,
3596,
2327,
90,
275,
1551,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
4805,
435,
741,
1312,
8076,
12,
283,
82,
358,
421,
199,
3,
1010,
59,
2869,
2189,
199,
199,
1372,
8076,
275,
1687,
3596,
2327,
90,
14,
739,
342,
421,
199,
3,
1010,
59,
2481,
2189,
199,
199,
1372,
8076,
421,
199,
3,
1010,
59,
1229,
2189,
199,
199,
685,
65,
807,
275,
2022,
14,
3640,
8,
1372,
8076,
9,
421,
199,
3,
1010,
59,
24,
2189,
199,
199,
411,
711,
8161,
275,
1551,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
15,
4624,
711,
14,
2424,
297,
283,
82,
358,
199,
711,
6883,
89,
275,
1687,
711,
8161,
14,
739,
342,
421,
199,
3,
1010,
59,
713,
2189,
199,
199,
711,
3118,
275,
284,
2700,
8161,
14,
1814,
2258,
78,
297,
1656,
5320,
421,
199,
3,
1010,
59,
969,
2189,
199,
199,
711,
3118,
421,
199,
3,
1010,
59,
1046,
2189,
199,
199,
711,
317,
11803,
81,
275,
284,
2352,
1270,
14,
1294,
11917,
421,
199,
3,
1010,
59,
1789,
2189,
199,
199,
3,
4665,
6246,
365,
4697,
641,
314,
769,
14,
14012,
370,
2813,
642,
3063,
199,
199,
1222,
526,
83,
275,
3384,
317,
11803,
81,
59,
16,
61,
421,
199,
3,
1010,
59,
1194,
2189,
199,
199,
1222,
526,
83,
421,
199,
3,
1010,
59,
1641,
2189,
199,
199,
685,
65,
807,
14,
873,
3252,
21809,
7,
520,
892,
526,
83,
1552,
421,
199,
3,
1010,
59,
2010,
2189,
199,
199,
685,
65,
807,
421,
199,
3,
1010,
59,
2259,
2189,
199,
199,
5598,
3596,
78,
275,
2022,
14,
4180,
8,
685,
65,
807,
9,
421,
199,
3,
1010,
59,
2789,
2189,
199,
199,
5598,
3596,
78,
199,
388,
18607,
8161,
275,
1551,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
4805,
435,
741,
1312,
8076,
12,
283,
87,
358,
199,
388,
18607,
8161,
14,
952,
8,
5598,
3596,
78,
9,
199,
388,
18607,
8161,
14,
1600,
342,
421,
199,
3,
1010,
59,
772,
2189,
199,
199,
20938,
14,
1185,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
4805,
435,
741,
1312,
8076,
12,
1994,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
15,
12941,
5146,
6217,
421,
199,
3,
1010,
59,
16246,
199,
199,
3,
20938,
14,
1185,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
4805,
435,
741,
1312,
8076,
12,
1994,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
15,
12941,
5146,
6217,
421,
199,
3,
1010,
59,
1398,
2189,
199,
199,
1222,
14392,
1214,
275,
3384,
317,
11803,
81,
59,
17,
2938,
421,
199,
3,
1010,
59,
1276,
2189,
199,
199,
1222,
14392,
1214,
199,
199,
1222,
20153,
275,
1551,
2336,
4219,
15,
87,
4400,
346,
1024,
15,
2326,
396,
15,
4624,
711,
14,
2424,
297,
283,
87,
358,
199,
199,
509,
1212,
2231,
87,
315,
892,
14392,
1214,
26,
272,
327,
1361,
1212,
22522,
272,
892,
20153,
14,
952,
8,
495,
8,
317,
2231,
87,
430,
272,
892,
20153,
14,
952,
2258,
78,
358,
199,
199,
1222,
20153,
14,
1600,
342,
421,
199,
3,
1010,
59,
1167,
2189,
199,
199,
509,
3384,
90,
81,
315,
3384,
317,
11803,
81,
26,
272,
870,
3384,
90,
81,
421,
199,
3,
1010,
59,
16246,
6905,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Instanssi/Instanssi.org
|
Instanssi/screenshow/migrations/0003_auto_20210511_0020.py
|
1
|
1515
|
# Generated by Django 3.2.2 on 2021-05-10 21:20
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('screenshow', '0002_auto_20180711_2110'),
]
operations = [
migrations.AlterField(
model_name='ircmessage',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='message',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='npsong',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='playlistvideo',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='screenconfig',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='sponsor',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
]
|
mit
|
[
3,
17065,
701,
5634,
650,
14,
18,
14,
18,
641,
499,
15385,
13,
1717,
13,
709,
7829,
26,
1165,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
5410,
2384,
297,
283,
9425,
63,
2495,
63,
1797,
11369,
845,
63,
10639,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
5958,
1188,
297,
288,
536,
534,
344,
297,
288,
901,
29,
992,
14,
7279,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
659,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
1188,
297,
288,
536,
534,
344,
297,
288,
901,
29,
992,
14,
7279,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
659,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
1590,
19351,
297,
288,
536,
534,
344,
297,
288,
901,
29,
992,
14,
7279,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
659,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
10411,
3722,
297,
288,
536,
534,
344,
297,
288,
901,
29,
992,
14,
7279,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
659,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
5410,
888,
297,
288,
536,
534,
344,
297,
288,
901,
29,
992,
14,
7279,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
659,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
83,
29733,
297,
288,
536,
534,
344,
297,
288,
901,
29,
992,
14,
7279,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
659,
267,
2318,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
17065,
701,
5634,
650,
14,
18,
14,
18,
641,
499,
15385,
13,
1717,
13,
709,
7829,
26,
1165,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
5410,
2384,
297,
283,
9425,
63,
2495,
63,
1797,
11369,
845,
63,
10639,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
5958,
1188,
297,
288,
536,
534,
344,
297,
288,
901,
29,
992,
14,
7279,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
659,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
1188,
297,
288,
536,
534,
344,
297,
288,
901,
29,
992,
14,
7279,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
659,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
1590,
19351,
297,
288,
536,
534,
344,
297,
288,
901,
29,
992,
14,
7279,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
659,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
10411,
3722,
297,
288,
536,
534,
344,
297,
288,
901,
29,
992,
14,
7279,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
659,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
5410,
888,
297,
288,
536,
534,
344,
297,
288,
901,
29,
992,
14,
7279,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
659,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
83,
29733,
297,
288,
536,
534,
344,
297,
288,
901,
29,
992,
14,
7279,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
659,
267,
2318,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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verify traffic_dump functionality.
"""
# 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
Test.Summary = '''
Verify traffic_dump functionality.
'''
Test.SkipUnless(
Condition.PluginExists('traffic_dump.so'),
)
# Configure the origin server.
replay_file = "replay/traffic_dump.yaml"
server = Test.MakeVerifierServerProcess(
"server", replay_file,
ssl_cert="ssl/server_combined.pem", ca_cert="ssl/signer.pem")
# Define ATS and configure it.
ts = Test.MakeATSProcess("ts", enable_tls=True)
replay_dir = os.path.join(ts.RunDirectory, "ts", "log")
ts.addSSLfile("ssl/server.pem")
ts.addSSLfile("ssl/server.key")
ts.addSSLfile("ssl/signer.pem")
ts.Setup.Copy("ssl/signed-foo.pem")
ts.Setup.Copy("ssl/signed-foo.key")
ts.Disk.records_config.update({
'proxy.config.diags.debug.enabled': 1,
'proxy.config.diags.debug.tags': 'traffic_dump',
'proxy.config.http.insert_age_in_response': 0,
'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir),
'proxy.config.ssl.server.private_key.path': '{0}'.format(ts.Variables.SSLDir),
'proxy.config.url_remap.pristine_host_hdr': 1,
'proxy.config.ssl.CA.cert.filename': '{0}/signer.pem'.format(ts.Variables.SSLDir),
'proxy.config.exec_thread.autoconfig.scale': 1.0,
'proxy.config.http.host_sni_policy': 2,
'proxy.config.ssl.TLSv1_3': 0,
'proxy.config.ssl.client.verify.server.policy': 'PERMISSIVE',
})
ts.Disk.ssl_multicert_config.AddLine(
'dest_ip=* ssl_cert_name=server.pem ssl_key_name=server.key'
)
ts.Disk.remap_config.AddLine(
'map https://www.client_only_tls.com/ http://127.0.0.1:{0}'.format(server.Variables.http_port)
)
ts.Disk.remap_config.AddLine(
'map https://www.tls.com/ https://127.0.0.1:{0}'.format(server.Variables.https_port)
)
ts.Disk.remap_config.AddLine(
'map / http://127.0.0.1:{0}'.format(server.Variables.http_port)
)
# Configure traffic_dump.
ts.Disk.plugin_config.AddLine(
'traffic_dump.so --logdir {0} --sample 1 --limit 1000000000 '
'--sensitive-fields "cookie,set-cookie,x-request-1,x-request-2"'.format(replay_dir)
)
# Configure logging of transactions. This is helpful for the cache test below.
ts.Disk.logging_yaml.AddLines(
'''
logging:
formats:
- name: basic
format: "%<cluc>: Read result: %<crc>:%<crsc>:%<chm>, Write result: %<cwr>"
logs:
- filename: transactions
format: basic
'''.split('\n'))
# Set up trafficserver expectations.
ts.Disk.diags_log.Content = Testers.ContainsExpression(
"loading plugin.*traffic_dump.so",
"Verify the traffic_dump plugin got loaded.")
ts.Streams.stderr = Testers.ContainsExpression(
"Initialized with log directory: {0}".format(replay_dir),
"Verify traffic_dump initialized with the configured directory.")
ts.Streams.stderr += Testers.ContainsExpression(
"Initialized with sample pool size 1 bytes and disk limit 1000000000 bytes",
"Verify traffic_dump initialized with the configured disk limit.")
ts.Streams.stderr += Testers.ContainsExpression(
"Finish a session with log file of.*bytes",
"Verify traffic_dump sees the end of sessions and accounts for it.")
# Set up the json replay file expectations.
replay_file_session_1 = os.path.join(replay_dir, "127", "0000000000000000")
ts.Disk.File(replay_file_session_1, exists=True)
replay_file_session_2 = os.path.join(replay_dir, "127", "0000000000000001")
ts.Disk.File(replay_file_session_2, exists=True)
replay_file_session_3 = os.path.join(replay_dir, "127", "0000000000000002")
ts.Disk.File(replay_file_session_3, exists=True)
replay_file_session_4 = os.path.join(replay_dir, "127", "0000000000000003")
ts.Disk.File(replay_file_session_4, exists=True)
replay_file_session_5 = os.path.join(replay_dir, "127", "0000000000000004")
ts.Disk.File(replay_file_session_5, exists=True)
replay_file_session_6 = os.path.join(replay_dir, "127", "0000000000000005")
ts.Disk.File(replay_file_session_6, exists=True)
replay_file_session_7 = os.path.join(replay_dir, "127", "0000000000000006")
ts.Disk.File(replay_file_session_7, exists=True)
replay_file_session_8 = os.path.join(replay_dir, "127", "0000000000000007")
ts.Disk.File(replay_file_session_8, exists=True)
replay_file_session_9 = os.path.join(replay_dir, "127", "0000000000000008")
ts.Disk.File(replay_file_session_9, exists=True)
replay_file_session_10 = os.path.join(replay_dir, "127", "0000000000000009")
ts.Disk.File(replay_file_session_10, exists=True)
# Execute the first transaction. We limit the threads to 1 so that the sessions
# are run in serial.
tr = Test.AddTestRun("Run the test traffic.")
tr.AddVerifierClientProcess(
"client", replay_file, http_ports=[ts.Variables.port],
https_ports=[ts.Variables.ssl_port],
ssl_cert="ssl/server_combined.pem", ca_cert="ssl/signer.pem",
other_args='--thread-limit 1')
tr.Processes.Default.StartBefore(server)
tr.Processes.Default.StartBefore(ts)
tr.StillRunningAfter = server
tr.StillRunningAfter = ts
#
# Test 1: Verify the correct behavior of two transactions across two sessions.
#
# Verify the properties of the replay file for the first transaction.
tr = Test.AddTestRun("Verify the json content of the first session")
http_protocols = "tcp,ip"
verify_replay = "verify_replay.py"
sensitive_fields_arg = (
"--sensitive-fields cookie "
"--sensitive-fields set-cookie "
"--sensitive-fields x-request-1 "
"--sensitive-fields x-request-2 ")
tr.Setup.CopyAs(verify_replay, Test.RunDirectory)
tr.Processes.Default.Command = \
('python3 {0} {1} {2} {3} --client-http-version "1.1" '
'--client-protocols "{4}"'.format(
verify_replay,
os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'),
replay_file_session_1,
sensitive_fields_arg,
http_protocols))
tr.Processes.Default.ReturnCode = 0
tr.StillRunningAfter = server
tr.StillRunningAfter = ts
# Verify the properties of the replay file for the second transaction.
tr = Test.AddTestRun("Verify the json content of the second session")
tr.Setup.CopyAs(verify_replay, Test.RunDirectory)
tr.Processes.Default.Command = \
('python3 {0} {1} {2} {3} --client-http-version "1.1" '
'--request-target "/two"'.format(
verify_replay,
os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'),
replay_file_session_2,
sensitive_fields_arg))
tr.Processes.Default.ReturnCode = 0
tr.StillRunningAfter = server
tr.StillRunningAfter = ts
#
# Test 2: Verify the correct behavior of an explicit path in the request line.
#
# Verify recording of a request target with the host specified.
tr = Test.AddTestRun("Verify the replay file has the explicit target.")
tr.Setup.CopyAs(verify_replay, Test.RunDirectory)
tr.Processes.Default.Command = "python3 {0} {1} {2} {3} --request-target '{4}'".format(
verify_replay,
os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'),
replay_file_session_3,
sensitive_fields_arg,
"http://www.some.host.com/candy")
tr.Processes.Default.ReturnCode = 0
tr.StillRunningAfter = server
tr.StillRunningAfter = ts
#
# Test 3: Verify correct handling of a POST with body data.
#
tr = Test.AddTestRun("Verify the client-request size node for a request with a body.")
tr.Setup.CopyAs(verify_replay, Test.RunDirectory)
size_of_verify_replay_file = os.path.getsize(os.path.join(Test.TestDirectory, verify_replay))
expected_body_size = 12345
tr.Processes.Default.Command = \
"python3 {0} {1} {2} {3} --client-request-size {4}".format(
verify_replay,
os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'),
replay_file_session_4,
sensitive_fields_arg,
expected_body_size)
tr.Processes.Default.ReturnCode = 0
tr.StillRunningAfter = server
tr.StillRunningAfter = ts
#
# Test 4: Verify correct handling of a response produced out of the cache.
#
tr = Test.AddTestRun("Verify that the cached response's replay file looks appropriate.")
tr.Setup.CopyAs(verify_replay, Test.RunDirectory)
tr.Processes.Default.Command = 'python3 {0} {1} {2} --client-protocols "{3}"'.format(
verify_replay,
os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'),
replay_file_session_6,
http_protocols)
tr.Processes.Default.ReturnCode = 0
tr.StillRunningAfter = server
tr.StillRunningAfter = ts
#
# Test 5: Verify correct handling of two transactions in a session.
#
tr = Test.AddTestRun("Verify the dump file of two transactions in a session.")
tr.Setup.CopyAs(verify_replay, Test.RunDirectory)
tr.Processes.Default.Command = 'python3 {0} {1} {2} --client-protocols "{3}"'.format(
verify_replay,
os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'),
replay_file_session_7,
http_protocols)
tr.Processes.Default.ReturnCode = 0
tr.StillRunningAfter = server
tr.StillRunningAfter = ts
#
# Test 6: Verify correct protcol dumping of a TLS connection.
#
tr = Test.AddTestRun("Verify the client protocol stack of a TLS session.")
https_protocols = "tls,tcp,ip"
client_tls_features = "sni:www.tls.com,proxy-verify-mode:0,proxy-provided-cert:true"
tr.Setup.CopyAs(verify_replay, Test.RunDirectory)
tr.Processes.Default.Command = 'python3 {0} {1} {2} --client-protocols "{3}" --client-tls-features "{4}"'.format(
verify_replay,
os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'),
replay_file_session_8,
https_protocols,
client_tls_features)
tr.Processes.Default.ReturnCode = 0
tr.StillRunningAfter = server
tr.StillRunningAfter = ts
tr = Test.AddTestRun("Verify the server TLS protocol stack.")
https_server_stack = "http,tls,tcp,ip"
tr.Setup.CopyAs(verify_replay, Test.RunDirectory)
server_tls_features = 'proxy-provided-cert:false,sni:www.tls.com,proxy-verify-mode:1'
tr.Processes.Default.Command = 'python3 {0} {1} {2} --server-protocols "{3}" --server-tls-features "{4}"'.format(
verify_replay,
os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'),
replay_file_session_8,
https_server_stack,
server_tls_features)
tr.Processes.Default.ReturnCode = 0
tr.StillRunningAfter = server
tr.StillRunningAfter = ts
#
# Test 7: Verify correct protcol dumping of TLS and HTTP/2 connections.
#
tr = Test.AddTestRun("Verify the client HTTP/2 protocol stack.")
h2_protocols = "http,tls,tcp,ip"
tr.Setup.CopyAs(verify_replay, Test.RunDirectory)
tr.Processes.Default.Command = \
('python3 {0} {1} {2} --client-http-version "2" '
'--client-protocols "{3}" --client-tls-features "{4}"'.format(
verify_replay,
os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'),
replay_file_session_9,
h2_protocols,
client_tls_features))
tr.Processes.Default.ReturnCode = 0
tr.StillRunningAfter = server
tr.StillRunningAfter = ts
tr = Test.AddTestRun("Verify the server HTTP/2 protocol stack.")
tr.Setup.CopyAs(verify_replay, Test.RunDirectory)
tr.Processes.Default.Command = 'python3 {0} {1} {2} --server-protocols "{3}" --server-tls-features "{4}"'.format(
verify_replay,
os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'),
replay_file_session_9,
https_server_stack,
server_tls_features)
tr.Processes.Default.ReturnCode = 0
tr.StillRunningAfter = server
tr.StillRunningAfter = ts
#
# Test 8: Verify correct protcol dumping of client-side TLS and server-side HTTP.
#
tr = Test.AddTestRun("Verify the client TLS protocol stack.")
tr.Setup.CopyAs(verify_replay, Test.RunDirectory)
tr.Processes.Default.Command = 'python3 {0} {1} {2} --client-http-version "1.1" --client-protocols "{3}"'.format(
verify_replay,
os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'),
replay_file_session_10,
https_protocols)
tr.Processes.Default.ReturnCode = 0
tr.StillRunningAfter = server
tr.StillRunningAfter = ts
tr = Test.AddTestRun("Verify the server HTTP protocol stack.")
tr.Setup.CopyAs(verify_replay, Test.RunDirectory)
http_server_stack = "http,tcp,ip"
tr.Processes.Default.Command = 'python3 {0} {1} {2} --server-protocols "{3}"'.format(
verify_replay,
os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'),
replay_file_session_10,
http_server_stack)
tr.Processes.Default.ReturnCode = 0
tr.StillRunningAfter = server
tr.StillRunningAfter = ts
|
apache-2.0
|
[
624,
199,
7496,
15602,
63,
2724,
9330,
14,
199,
624,
199,
3,
221,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
221,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
221,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
221,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
221,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
221,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
221,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
199,
646,
747,
199,
774,
14,
10407,
275,
1449,
199,
7496,
15602,
63,
2724,
9330,
14,
199,
2344,
199,
199,
774,
14,
7738,
5524,
8,
272,
28401,
14,
5061,
7965,
360,
17297,
63,
2724,
14,
1152,
659,
199,
9,
199,
199,
3,
15453,
314,
6330,
1654,
14,
199,
19540,
63,
493,
275,
298,
19540,
15,
17297,
63,
2724,
14,
5963,
2,
199,
1000,
275,
1379,
14,
5483,
3673,
9893,
3120,
3498,
8,
272,
298,
1000,
401,
24331,
63,
493,
12,
272,
6149,
63,
4736,
628,
4266,
15,
1000,
63,
17583,
14,
13102,
401,
1704,
63,
4736,
628,
4266,
15,
25399,
14,
13102,
531,
421,
199,
3,
13930,
437,
9730,
436,
7908,
652,
14,
199,
1086,
275,
1379,
14,
5483,
619,
51,
3498,
480,
1086,
401,
4756,
63,
9945,
29,
549,
9,
199,
19540,
63,
694,
275,
747,
14,
515,
14,
904,
8,
1086,
14,
2540,
6231,
12,
298,
1086,
401,
298,
793,
531,
199,
199,
1086,
14,
525,
5413,
493,
480,
4266,
15,
1000,
14,
13102,
531,
199,
1086,
14,
525,
5413,
493,
480,
4266,
15,
1000,
14,
498,
531,
199,
1086,
14,
525,
5413,
493,
480,
4266,
15,
25399,
14,
13102,
531,
199,
199,
1086,
14,
8555,
14,
5116,
480,
4266,
15,
1737,
13,
1421,
14,
13102,
531,
199,
1086,
14,
8555,
14,
5116,
480,
4266,
15,
1737,
13,
1421,
14,
498,
531,
199,
199,
1086,
14,
10690,
14,
6502,
63,
888,
14,
873,
2561,
272,
283,
3280,
14,
888,
14,
2391,
458,
14,
1757,
14,
3827,
356,
413,
12,
272,
283,
3280,
14,
888,
14,
2391,
458,
14,
1757,
14,
2969,
356,
283,
17297,
63,
2724,
297,
272,
283,
3280,
14,
888,
14,
1014,
14,
3176,
63,
474,
63,
262,
63,
1310,
356,
378,
12,
339,
283,
3280,
14,
888,
14,
4266,
14,
1000,
14,
4736,
14,
515,
356,
5041,
16,
5285,
908,
8,
1086,
14,
11458,
14,
5413,
3567,
395,
272,
283,
3280,
14,
888,
14,
4266,
14,
1000,
14,
4239,
63,
498,
14,
515,
356,
5041,
16,
5285,
908,
8,
1086,
14,
11458,
14,
5413,
3567,
395,
272,
283,
3280,
14,
888,
14,
633,
63,
25340,
14,
1359,
270,
1132,
63,
1102,
63,
11244,
356,
413,
12,
272,
283,
3280,
14,
888,
14,
4266,
14,
3263,
14,
4736,
14,
1501,
356,
5041,
16,
5995,
25399,
14,
13102,
1370,
908,
8,
1086,
14,
11458,
14,
5413,
3567,
395,
272,
283,
3280,
14,
888,
14,
1628,
63,
2671,
14,
2495,
888,
14,
3467,
356,
413,
14,
16,
12,
272,
283,
3280,
14,
888,
14,
1014,
14,
1102,
63,
5167,
73,
63,
3185,
356,
499,
12,
272,
283,
3280,
14,
888,
14,
4266,
14,
10224,
86,
17,
63,
19,
356,
378,
12,
272,
283,
3280,
14,
888,
14,
4266,
14,
1258,
14,
4712,
14,
1000,
14,
3185,
356,
283,
4227,
9674,
2684,
2524,
297,
199,
1552,
199,
199,
1086,
14,
10690,
14,
4266,
63,
3703,
764,
15299,
63,
888,
14,
1123,
3049,
8,
272,
283,
2614,
63,
711,
29,
10,
6149,
63,
4736,
63,
354,
29,
1000,
14,
13102,
6149,
63,
498,
63,
354,
29,
1000,
14,
498,
7,
199,
9,
199,
199,
1086,
14,
10690,
14,
25340,
63,
888,
14,
1123,
3049,
8,
272,
283,
1130,
4178,
921,
1544,
14,
1258,
63,
2118,
63,
9945,
14,
957,
15,
1455,
921,
4195,
14,
16,
14,
16,
14,
17,
14534,
16,
5285,
908,
8,
1000,
14,
11458,
14,
1014,
63,
719,
9,
199,
9,
199,
1086,
14,
10690,
14,
25340,
63,
888,
14,
1123,
3049,
8,
272,
283,
1130,
4178,
921,
1544,
14,
9945,
14,
957,
15,
4178,
921,
4195,
14,
16,
14,
16,
14,
17,
14534,
16,
5285,
908,
8,
1000,
14,
11458,
14,
2859,
63,
719,
9,
199,
9,
199,
1086,
14,
10690,
14,
25340,
63,
888,
14,
1123,
3049,
8,
272,
283,
1130,
1182,
1455,
921,
4195,
14,
16,
14,
16,
14,
17,
14534,
16,
5285,
908,
8,
1000,
14,
11458,
14,
1014,
63,
719,
9,
199,
9,
199,
199,
3,
15453,
15602,
63,
2724,
14,
199,
1086,
14,
10690,
14,
2718,
63,
888,
14,
1123,
3049,
8,
272,
283,
17297,
63,
2724,
14,
1152,
1553,
22222,
469,
16,
93,
1553,
3271,
413,
1553,
3097,
413,
25464,
283,
272,
2850,
7361,
13,
955,
298,
5306,
12,
409,
13,
5306,
12,
88,
13,
1069,
13,
17,
12,
88,
13,
1069,
13,
18,
2,
1370,
908,
8,
19540,
63,
694,
9,
199,
9,
199,
3,
15453,
2050,
402,
15809,
14,
961,
365,
24606,
367,
314,
2581,
511,
5084,
14,
199,
1086,
14,
10690,
14,
4806,
63,
5963,
14,
1123,
9863,
8,
272,
1449,
199,
4806,
26,
523,
6752,
26,
272,
446,
536,
26,
5678,
489,
1475,
26,
2071,
28,
429,
947,
20020,
5574,
754,
26,
450,
28,
13258,
30,
2689,
28,
1556,
551,
30,
2689,
28,
335,
77,
6244,
6990,
754,
26,
450,
28,
15346,
82,
4335,
523,
9610,
26,
272,
446,
1788,
26,
15809,
489,
1475,
26,
5678,
199,
891,
1370,
1294,
2258,
78,
1333,
199,
199,
3,
2494,
1536,
15602
] |
[
199,
7496,
15602,
63,
2724,
9330,
14,
199,
624,
199,
3,
221,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
221,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
221,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
221,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
221,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
221,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
221,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
199,
646,
747,
199,
774,
14,
10407,
275,
1449,
199,
7496,
15602,
63,
2724,
9330,
14,
199,
2344,
199,
199,
774,
14,
7738,
5524,
8,
272,
28401,
14,
5061,
7965,
360,
17297,
63,
2724,
14,
1152,
659,
199,
9,
199,
199,
3,
15453,
314,
6330,
1654,
14,
199,
19540,
63,
493,
275,
298,
19540,
15,
17297,
63,
2724,
14,
5963,
2,
199,
1000,
275,
1379,
14,
5483,
3673,
9893,
3120,
3498,
8,
272,
298,
1000,
401,
24331,
63,
493,
12,
272,
6149,
63,
4736,
628,
4266,
15,
1000,
63,
17583,
14,
13102,
401,
1704,
63,
4736,
628,
4266,
15,
25399,
14,
13102,
531,
421,
199,
3,
13930,
437,
9730,
436,
7908,
652,
14,
199,
1086,
275,
1379,
14,
5483,
619,
51,
3498,
480,
1086,
401,
4756,
63,
9945,
29,
549,
9,
199,
19540,
63,
694,
275,
747,
14,
515,
14,
904,
8,
1086,
14,
2540,
6231,
12,
298,
1086,
401,
298,
793,
531,
199,
199,
1086,
14,
525,
5413,
493,
480,
4266,
15,
1000,
14,
13102,
531,
199,
1086,
14,
525,
5413,
493,
480,
4266,
15,
1000,
14,
498,
531,
199,
1086,
14,
525,
5413,
493,
480,
4266,
15,
25399,
14,
13102,
531,
199,
199,
1086,
14,
8555,
14,
5116,
480,
4266,
15,
1737,
13,
1421,
14,
13102,
531,
199,
1086,
14,
8555,
14,
5116,
480,
4266,
15,
1737,
13,
1421,
14,
498,
531,
199,
199,
1086,
14,
10690,
14,
6502,
63,
888,
14,
873,
2561,
272,
283,
3280,
14,
888,
14,
2391,
458,
14,
1757,
14,
3827,
356,
413,
12,
272,
283,
3280,
14,
888,
14,
2391,
458,
14,
1757,
14,
2969,
356,
283,
17297,
63,
2724,
297,
272,
283,
3280,
14,
888,
14,
1014,
14,
3176,
63,
474,
63,
262,
63,
1310,
356,
378,
12,
339,
283,
3280,
14,
888,
14,
4266,
14,
1000,
14,
4736,
14,
515,
356,
5041,
16,
5285,
908,
8,
1086,
14,
11458,
14,
5413,
3567,
395,
272,
283,
3280,
14,
888,
14,
4266,
14,
1000,
14,
4239,
63,
498,
14,
515,
356,
5041,
16,
5285,
908,
8,
1086,
14,
11458,
14,
5413,
3567,
395,
272,
283,
3280,
14,
888,
14,
633,
63,
25340,
14,
1359,
270,
1132,
63,
1102,
63,
11244,
356,
413,
12,
272,
283,
3280,
14,
888,
14,
4266,
14,
3263,
14,
4736,
14,
1501,
356,
5041,
16,
5995,
25399,
14,
13102,
1370,
908,
8,
1086,
14,
11458,
14,
5413,
3567,
395,
272,
283,
3280,
14,
888,
14,
1628,
63,
2671,
14,
2495,
888,
14,
3467,
356,
413,
14,
16,
12,
272,
283,
3280,
14,
888,
14,
1014,
14,
1102,
63,
5167,
73,
63,
3185,
356,
499,
12,
272,
283,
3280,
14,
888,
14,
4266,
14,
10224,
86,
17,
63,
19,
356,
378,
12,
272,
283,
3280,
14,
888,
14,
4266,
14,
1258,
14,
4712,
14,
1000,
14,
3185,
356,
283,
4227,
9674,
2684,
2524,
297,
199,
1552,
199,
199,
1086,
14,
10690,
14,
4266,
63,
3703,
764,
15299,
63,
888,
14,
1123,
3049,
8,
272,
283,
2614,
63,
711,
29,
10,
6149,
63,
4736,
63,
354,
29,
1000,
14,
13102,
6149,
63,
498,
63,
354,
29,
1000,
14,
498,
7,
199,
9,
199,
199,
1086,
14,
10690,
14,
25340,
63,
888,
14,
1123,
3049,
8,
272,
283,
1130,
4178,
921,
1544,
14,
1258,
63,
2118,
63,
9945,
14,
957,
15,
1455,
921,
4195,
14,
16,
14,
16,
14,
17,
14534,
16,
5285,
908,
8,
1000,
14,
11458,
14,
1014,
63,
719,
9,
199,
9,
199,
1086,
14,
10690,
14,
25340,
63,
888,
14,
1123,
3049,
8,
272,
283,
1130,
4178,
921,
1544,
14,
9945,
14,
957,
15,
4178,
921,
4195,
14,
16,
14,
16,
14,
17,
14534,
16,
5285,
908,
8,
1000,
14,
11458,
14,
2859,
63,
719,
9,
199,
9,
199,
1086,
14,
10690,
14,
25340,
63,
888,
14,
1123,
3049,
8,
272,
283,
1130,
1182,
1455,
921,
4195,
14,
16,
14,
16,
14,
17,
14534,
16,
5285,
908,
8,
1000,
14,
11458,
14,
1014,
63,
719,
9,
199,
9,
199,
199,
3,
15453,
15602,
63,
2724,
14,
199,
1086,
14,
10690,
14,
2718,
63,
888,
14,
1123,
3049,
8,
272,
283,
17297,
63,
2724,
14,
1152,
1553,
22222,
469,
16,
93,
1553,
3271,
413,
1553,
3097,
413,
25464,
283,
272,
2850,
7361,
13,
955,
298,
5306,
12,
409,
13,
5306,
12,
88,
13,
1069,
13,
17,
12,
88,
13,
1069,
13,
18,
2,
1370,
908,
8,
19540,
63,
694,
9,
199,
9,
199,
3,
15453,
2050,
402,
15809,
14,
961,
365,
24606,
367,
314,
2581,
511,
5084,
14,
199,
1086,
14,
10690,
14,
4806,
63,
5963,
14,
1123,
9863,
8,
272,
1449,
199,
4806,
26,
523,
6752,
26,
272,
446,
536,
26,
5678,
489,
1475,
26,
2071,
28,
429,
947,
20020,
5574,
754,
26,
450,
28,
13258,
30,
2689,
28,
1556,
551,
30,
2689,
28,
335,
77,
6244,
6990,
754,
26,
450,
28,
15346,
82,
4335,
523,
9610,
26,
272,
446,
1788,
26,
15809,
489,
1475,
26,
5678,
199,
891,
1370,
1294,
2258,
78,
1333,
199,
199,
3,
2494,
1536,
15602,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
chenc10/Spark-PAF
|
examples/src/main/python/ml/binarizer_example.py
|
3
|
1587
|
#
# 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 __future__ import print_function
from pyspark import SparkContext
from pyspark.sql import SQLContext
# $example on$
from pyspark.ml.feature import Binarizer
# $example off$
if __name__ == "__main__":
sc = SparkContext(appName="BinarizerExample")
sqlContext = SQLContext(sc)
# $example on$
continuousDataFrame = sqlContext.createDataFrame([
(0, 0.1),
(1, 0.8),
(2, 0.2)
], ["label", "feature"])
binarizer = Binarizer(threshold=0.5, inputCol="feature", outputCol="binarized_feature")
binarizedDataFrame = binarizer.transform(continuousDataFrame)
binarizedFeatures = binarizedDataFrame.select("binarized_feature")
for binarized_feature, in binarizedFeatures.collect():
print(binarized_feature)
# $example off$
sc.stop()
|
apache-2.0
|
[
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
15847,
492,
21769,
199,
504,
15847,
14,
3009,
492,
5385,
2998,
199,
3,
2672,
2694,
641,
4,
199,
504,
15847,
14,
757,
14,
4445,
492,
32613,
31008,
199,
3,
2672,
2694,
2331,
4,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
4061,
275,
21769,
8,
571,
985,
628,
13394,
31008,
9846,
531,
272,
3875,
2998,
275,
5385,
2998,
8,
551,
9,
339,
327,
2672,
2694,
641,
4,
272,
19922,
9205,
275,
3875,
2998,
14,
25482,
779,
267,
334,
16,
12,
378,
14,
17,
395,
267,
334,
17,
12,
378,
14,
24,
395,
267,
334,
18,
12,
378,
14,
18,
9,
272,
2156,
2097,
1302,
401,
298,
4445,
3135,
272,
2517,
31008,
275,
32613,
31008,
8,
7227,
29,
16,
14,
21,
12,
1324,
2001,
628,
4445,
401,
1072,
2001,
628,
1393,
285,
1759,
63,
4445,
531,
272,
2517,
285,
1759,
9205,
275,
2517,
31008,
14,
4711,
8,
23458,
9205,
9,
272,
2517,
285,
1759,
10807,
275,
2517,
285,
1759,
9205,
14,
2416,
480,
1393,
285,
1759,
63,
4445,
531,
272,
367,
2517,
285,
1759,
63,
4445,
12,
315,
2517,
285,
1759,
10807,
14,
7112,
837,
267,
870,
8,
1393,
285,
1759,
63,
4445,
9,
272,
327,
2672,
2694,
2331,
4,
339,
4061,
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
] |
[
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
15847,
492,
21769,
199,
504,
15847,
14,
3009,
492,
5385,
2998,
199,
3,
2672,
2694,
641,
4,
199,
504,
15847,
14,
757,
14,
4445,
492,
32613,
31008,
199,
3,
2672,
2694,
2331,
4,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
4061,
275,
21769,
8,
571,
985,
628,
13394,
31008,
9846,
531,
272,
3875,
2998,
275,
5385,
2998,
8,
551,
9,
339,
327,
2672,
2694,
641,
4,
272,
19922,
9205,
275,
3875,
2998,
14,
25482,
779,
267,
334,
16,
12,
378,
14,
17,
395,
267,
334,
17,
12,
378,
14,
24,
395,
267,
334,
18,
12,
378,
14,
18,
9,
272,
2156,
2097,
1302,
401,
298,
4445,
3135,
272,
2517,
31008,
275,
32613,
31008,
8,
7227,
29,
16,
14,
21,
12,
1324,
2001,
628,
4445,
401,
1072,
2001,
628,
1393,
285,
1759,
63,
4445,
531,
272,
2517,
285,
1759,
9205,
275,
2517,
31008,
14,
4711,
8,
23458,
9205,
9,
272,
2517,
285,
1759,
10807,
275,
2517,
285,
1759,
9205,
14,
2416,
480,
1393,
285,
1759,
63,
4445,
531,
272,
367,
2517,
285,
1759,
63,
4445,
12,
315,
2517,
285,
1759,
10807,
14,
7112,
837,
267,
870,
8,
1393,
285,
1759,
63,
4445,
9,
272,
327,
2672,
2694,
2331,
4,
339,
4061,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
diagramsoftware/odoo
|
openerp/report/render/html2html/html2html.py
|
443
|
4238
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.report.render.rml2pdf import utils
import copy
import base64
import cStringIO
import re
from reportlab.lib.utils import ImageReader
_regex = re.compile('\[\[(.+?)\]\]')
utils._regex = re.compile('\[\[\s*(.+?)\s*\]\]',re.DOTALL)
class html2html(object):
def __init__(self, html, localcontext):
self.localcontext = localcontext
self.etree = html
self._node = None
def render(self):
def process_text(node,new_node):
if new_node.tag in ['story','tr','section']:
new_node.attrib.clear()
for child in utils._child_get(node, self):
new_child = copy.deepcopy(child)
new_node.append(new_child)
if len(child):
for n in new_child:
new_child.text = utils._process_text(self, child.text)
new_child.tail = utils._process_text(self, child.tail)
new_child.remove(n)
process_text(child, new_child)
else:
if new_child.tag=='img' and new_child.get('name'):
if _regex.findall(new_child.get('name')) :
src = utils._process_text(self, new_child.get('name'))
if src :
new_child.set('src','data:image/gif;base64,%s'%src)
output = cStringIO.StringIO(base64.decodestring(src))
img = ImageReader(output)
(width,height) = img.getSize()
if not new_child.get('width'):
new_child.set('width',str(width))
if not new_child.get('height') :
new_child.set('height',str(height))
else :
new_child.getparent().remove(new_child)
new_child.text = utils._process_text(self, child.text)
new_child.tail = utils._process_text(self, child.tail)
self._node = copy.deepcopy(self.etree)
for n in self._node:
self._node.remove(n)
process_text(self.etree, self._node)
return self._node
def url_modify(self,root):
for n in root:
if (n.text.find('<a ')>=0 or n.text.find('<a')>=0) and n.text.find('href')>=0 and n.text.find('style')<=0 :
node = (n.tag=='span' and n.getparent().tag=='u') and n.getparent().getparent() or ((n.tag=='span') and n.getparent()) or n
style = node.get('color') and "style='color:%s; text-decoration: none;'"%node.get('color') or ''
if n.text.find('<a')>=0:
t = '<a '
else :
t = '<a '
href = n.text.split(t)[-1]
n.text = ' '.join([t,style,href])
self.url_modify(n)
return root
def parseString(node, localcontext = {}):
r = html2html(node, localcontext)
root = r.render()
root = r.url_modify(root)
return root
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
3070,
14,
3352,
14,
16300,
18,
5607,
492,
3778,
199,
646,
1331,
199,
646,
1300,
772,
199,
646,
15073,
199,
646,
295,
199,
504,
21773,
14,
773,
14,
1208,
492,
6047,
5929,
199,
199,
63,
3821,
275,
295,
14,
2014,
2258,
7023,
7528,
11198,
2862,
7272,
10374,
199,
1208,
423,
3821,
275,
295,
14,
2014,
2258,
7023,
7023,
83,
5830,
11198,
2862,
83,
7590,
7272,
4300,
264,
14,
16504,
9,
199,
533,
3517,
18,
1360,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
3517,
12,
2257,
1100,
304,
267,
291,
14,
17886,
275,
2257,
1100,
267,
291,
14,
9464,
275,
3517,
267,
291,
423,
932,
275,
488,
2378,
347,
3795,
8,
277,
304,
267,
347,
2112,
63,
505,
8,
932,
12,
1222,
63,
932,
304,
288,
340,
892,
63,
932,
14,
1450,
315,
788,
17372,
1673,
454,
1673,
2792,
2565,
355,
892,
63,
932,
14,
6640,
14,
3584,
342,
288,
367,
1982,
315,
3778,
423,
1739,
63,
362,
8,
932,
12,
291,
304,
355,
892,
63,
1739,
275,
1331,
14,
8293,
8,
1739,
9,
355,
892,
63,
932,
14,
740,
8,
1222,
63,
1739,
9,
355,
340,
822,
8,
1739,
304,
490,
367,
302,
315,
892,
63,
1739,
26,
717,
892,
63,
1739,
14,
505,
221,
275,
3778,
423,
1412,
63,
505,
8,
277,
12,
1982,
14,
505,
9,
717,
892,
63,
1739,
14,
1521,
221,
275,
3778,
423,
1412,
63,
505,
8,
277,
12,
1982,
14,
1521,
9,
717,
892,
63,
1739,
14,
2168,
8,
78,
9,
490,
2112,
63,
505,
8,
1739,
12,
892,
63,
1739,
9,
355,
587,
26,
490,
340,
892,
63,
1739,
14,
1450,
6803,
4060,
7,
436,
892,
63,
1739,
14,
362,
360,
354,
735,
717,
340,
485,
3821,
14,
6452,
8,
1222,
63,
1739,
14,
362,
360,
354,
1333,
520,
1169,
2928,
275,
221,
3778,
423,
1412,
63,
505,
8,
277,
12,
892,
63,
1739,
14,
362,
360,
354,
1333,
1169,
340,
2928,
520,
1816,
892,
63,
1739,
14,
409,
360,
2164,
1673,
576,
26,
1569,
15,
14513,
27,
1095,
772,
8719,
83,
5956,
2164,
9,
1816,
1072,
275,
15073,
14,
6424,
8,
1095,
772,
14,
2708,
875,
8,
2164,
430,
1816,
6050,
275,
6047,
5929,
8,
1199,
9,
1816,
334,
2063,
12,
3333,
9,
275,
6050,
14,
362,
2320,
342,
1816,
340,
440,
892,
63,
1739,
14,
362,
360,
2063,
735,
2511,
892,
63,
1739,
14,
409,
360,
2063,
297,
495,
8,
2063,
430,
1816,
340,
440,
892,
63,
1739,
14,
362,
360,
3333,
358,
520,
2511,
892,
63,
1739,
14,
409,
360,
3333,
297,
495,
8,
3333,
430,
1169,
587,
520,
1816,
892,
63,
1739,
14,
362,
1708,
1252,
2168,
8,
1222,
63,
1739,
9,
490,
892,
63,
1739,
14,
505,
221,
275,
3778,
423,
1412,
63,
505,
8,
277,
12,
1982,
14,
505,
9,
490,
892,
63,
1739,
14,
1521,
221,
275,
3778,
423,
1412,
63,
505,
8,
277,
12,
1982,
14,
1521,
9,
267,
291,
423,
932,
275,
1331,
14,
8293,
8,
277,
14,
9464,
9,
267,
367,
302,
315,
291,
423,
932,
26,
288,
291,
423,
932,
14,
2168,
8,
78,
9,
267,
2112,
63,
505,
8,
277,
14,
9464,
12,
291,
423,
932,
9,
267,
372,
291,
423,
932,
5493,
347,
1166,
63,
8951,
8,
277,
12,
1231,
304,
267,
367,
302,
315,
1738,
26,
288,
340,
334,
78,
14,
505,
14,
1623,
4827,
65,
5320,
8119,
16,
503,
302,
14,
505,
14,
1623,
20040,
4116,
27,
65,
358,
8119,
16,
9,
436,
302,
14,
505,
14,
1623,
360,
6399,
358,
8119,
16,
436,
302,
14,
505,
14,
1623,
360,
2487,
358,
12932,
16,
520,
355,
1031,
275,
334,
78,
14,
1450,
6803,
3751,
7,
436,
302,
14,
362,
1708,
1252,
1450,
6803,
85,
358,
436,
302,
14,
362,
1708,
1252,
362,
1708,
342,
503,
3666,
78,
14,
1450,
6803,
3751,
358,
436,
302,
14,
362,
1708,
1012,
503,
302,
355,
3449,
275,
1031,
14,
362,
360,
2326,
358,
436,
298,
2487,
534,
2326,
2689,
83,
27,
1318,
13,
6518,
425,
26,
7179,
27,
4065,
5,
932,
14,
362,
360,
2326,
358,
503,
2125,
355,
340,
302,
14,
505,
14,
1623,
20040,
4116,
27,
65,
358,
8119,
16,
26,
490,
307,
275,
7673,
4116,
27,
65,
283,
355,
587,
520,
490,
307,
275,
2650,
65,
283,
355,
4369,
275,
302,
14,
505,
14,
1294,
8,
84,
15786,
17,
61,
355,
302,
14,
505,
275,
283,
1987,
904,
779,
84,
12,
2487,
12,
6399,
566,
288,
291,
14,
633,
63,
8951,
8,
78,
9,
267,
372,
1738,
199,
199,
318,
2198,
1558,
8,
932,
12,
2257,
1100,
275,
1052,
304,
272,
519,
275,
3517,
18,
1360,
8,
932,
12,
2257,
1100,
9,
272,
1738,
275,
519,
14,
3352,
342,
272,
1738,
275,
519,
14,
633,
63,
8951,
8,
1231,
9,
272,
372,
1738,
421,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
3070,
14,
3352,
14,
16300,
18,
5607,
492,
3778,
199,
646,
1331,
199,
646,
1300,
772,
199,
646,
15073,
199,
646,
295,
199,
504,
21773,
14,
773,
14,
1208,
492,
6047,
5929,
199,
199,
63,
3821,
275,
295,
14,
2014,
2258,
7023,
7528,
11198,
2862,
7272,
10374,
199,
1208,
423,
3821,
275,
295,
14,
2014,
2258,
7023,
7023,
83,
5830,
11198,
2862,
83,
7590,
7272,
4300,
264,
14,
16504,
9,
199,
533,
3517,
18,
1360,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
3517,
12,
2257,
1100,
304,
267,
291,
14,
17886,
275,
2257,
1100,
267,
291,
14,
9464,
275,
3517,
267,
291,
423,
932,
275,
488,
2378,
347,
3795,
8,
277,
304,
267,
347,
2112,
63,
505,
8,
932,
12,
1222,
63,
932,
304,
288,
340,
892,
63,
932,
14,
1450,
315,
788,
17372,
1673,
454,
1673,
2792,
2565,
355,
892,
63,
932,
14,
6640,
14,
3584,
342,
288,
367,
1982,
315,
3778,
423,
1739,
63,
362,
8,
932,
12,
291,
304,
355,
892,
63,
1739,
275,
1331,
14,
8293,
8,
1739,
9,
355,
892,
63,
932,
14,
740,
8,
1222,
63,
1739,
9,
355,
340,
822,
8,
1739,
304,
490,
367,
302,
315,
892,
63,
1739,
26,
717,
892,
63,
1739,
14,
505,
221,
275,
3778,
423,
1412,
63,
505,
8,
277,
12,
1982,
14,
505,
9,
717,
892,
63,
1739,
14,
1521,
221,
275,
3778,
423,
1412,
63,
505,
8,
277,
12,
1982,
14,
1521,
9,
717,
892,
63,
1739,
14,
2168,
8,
78,
9,
490,
2112,
63,
505,
8,
1739,
12,
892,
63,
1739,
9,
355,
587,
26,
490,
340,
892,
63,
1739,
14,
1450,
6803,
4060,
7,
436,
892,
63,
1739,
14,
362,
360,
354,
735,
717,
340,
485,
3821,
14,
6452,
8,
1222,
63,
1739,
14,
362,
360,
354,
1333,
520,
1169,
2928,
275,
221,
3778,
423,
1412,
63,
505,
8,
277,
12,
892,
63,
1739,
14,
362,
360,
354,
1333,
1169,
340,
2928,
520,
1816,
892,
63,
1739,
14,
409,
360,
2164,
1673,
576,
26,
1569,
15,
14513,
27,
1095,
772,
8719,
83,
5956,
2164,
9,
1816,
1072,
275,
15073,
14,
6424,
8,
1095,
772,
14,
2708,
875,
8,
2164,
430,
1816,
6050,
275,
6047,
5929,
8,
1199,
9,
1816,
334,
2063,
12,
3333,
9,
275,
6050,
14,
362,
2320,
342,
1816,
340,
440,
892,
63,
1739,
14,
362,
360,
2063,
735,
2511,
892,
63,
1739,
14,
409,
360,
2063,
297,
495,
8,
2063,
430,
1816,
340,
440,
892,
63,
1739,
14,
362,
360,
3333,
358,
520,
2511,
892,
63,
1739,
14,
409,
360,
3333,
297,
495,
8,
3333,
430,
1169,
587,
520,
1816,
892,
63,
1739,
14,
362,
1708,
1252,
2168,
8,
1222,
63,
1739,
9,
490,
892,
63,
1739,
14,
505,
221,
275,
3778,
423,
1412,
63,
505,
8,
277,
12,
1982,
14,
505,
9,
490,
892,
63,
1739,
14,
1521,
221,
275,
3778,
423,
1412,
63,
505,
8,
277,
12,
1982,
14,
1521,
9,
267,
291,
423,
932,
275,
1331,
14,
8293,
8,
277,
14,
9464,
9,
267,
367,
302,
315,
291,
423,
932,
26,
288,
291,
423,
932,
14,
2168,
8,
78,
9,
267,
2112,
63,
505,
8,
277,
14,
9464,
12,
291,
423,
932,
9,
267,
372,
291,
423,
932,
5493,
347,
1166,
63,
8951,
8,
277,
12,
1231,
304,
267,
367,
302,
315,
1738,
26,
288,
340,
334,
78,
14,
505,
14,
1623,
4827,
65,
5320,
8119,
16,
503,
302,
14,
505,
14,
1623,
20040,
4116,
27,
65,
358,
8119,
16,
9,
436,
302,
14,
505,
14,
1623,
360,
6399,
358,
8119,
16,
436,
302,
14,
505,
14,
1623,
360,
2487,
358,
12932,
16,
520,
355,
1031,
275,
334,
78,
14,
1450,
6803,
3751,
7,
436,
302,
14,
362,
1708,
1252,
1450,
6803,
85,
358,
436,
302,
14,
362,
1708,
1252,
362,
1708,
342,
503,
3666,
78,
14,
1450,
6803,
3751,
358,
436,
302,
14,
362,
1708,
1012,
503,
302,
355,
3449,
275,
1031,
14,
362,
360,
2326,
358,
436,
298,
2487,
534,
2326,
2689,
83,
27,
1318,
13,
6518,
425,
26,
7179,
27,
4065,
5,
932,
14,
362,
360,
2326,
358,
503,
2125,
355,
340,
302,
14,
505,
14,
1623,
20040,
4116,
27,
65,
358,
8119,
16,
26,
490,
307,
275,
7673,
4116,
27,
65,
283,
355,
587,
520,
490,
307,
275,
2650,
65,
283,
355,
4369,
275,
302,
14,
505,
14,
1294,
8,
84,
15786,
17,
61,
355,
302,
14,
505,
275,
283,
1987,
904,
779,
84,
12,
2487,
12,
6399,
566,
288,
291,
14,
633,
63,
8951,
8,
78,
9,
267,
372,
1738,
199,
199,
318,
2198,
1558,
8,
932,
12,
2257,
1100,
275,
1052,
304,
272,
519,
275,
3517,
18,
1360,
8,
932,
12,
2257,
1100,
9,
272,
1738,
275,
519,
14,
3352,
342,
272,
1738,
275,
519,
14,
633,
63,
8951,
8,
1231,
9,
272,
372,
1738,
421,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tabalinas/jsgrid-django
|
clients/views.py
|
1
|
1522
|
from django.http import HttpResponse
from django.core import serializers
from django.shortcuts import render
from simple_rest import Resource
from .models import Client
def index(request):
return render(request, 'index.html')
class Clients(Resource):
def get(self, request):
clients = Client.objects.all() \
.filter(name__contains = request.GET.get('name')) \
.filter(address__contains = request.GET.get('address'));
return HttpResponse(self.to_json(clients), content_type = 'application/json', status = 200)
def post(self, request):
Client.objects.create(
name = request.POST.get("name"),
age = request.POST.get("age"),
address = request.POST.get("address"),
married = True if request.POST.get("married") == 'true' else False
)
return HttpResponse(status = 201)
def put(self, request, client_id):
client = Client.objects.get(pk = client_id)
client.name = request.PUT.get("name")
client.age = request.PUT.get("age")
client.address = request.PUT.get("address")
client.married = True if request.PUT.get("married") == 'true' else False
client.save()
return HttpResponse(status = 200)
def delete(self, request, client_id):
client = Client.objects.get(pk = client_id)
client.delete()
return HttpResponse(status = 200)
def to_json(self, objects):
return serializers.serialize('json', objects)
|
mit
|
[
504,
1639,
14,
1014,
492,
6183,
199,
504,
1639,
14,
1018,
492,
12506,
199,
504,
1639,
14,
17469,
492,
3795,
199,
199,
504,
3486,
63,
3911,
492,
7337,
199,
199,
504,
1275,
992,
492,
6810,
199,
199,
318,
1478,
8,
1069,
304,
272,
372,
3795,
8,
1069,
12,
283,
1080,
14,
1360,
358,
421,
199,
533,
6810,
83,
8,
4031,
304,
339,
347,
664,
8,
277,
12,
1056,
304,
267,
13431,
275,
6810,
14,
1462,
14,
452,
342,
971,
288,
1275,
1541,
8,
354,
363,
6134,
275,
1056,
14,
2970,
14,
362,
360,
354,
1333,
971,
288,
1275,
1541,
8,
1562,
363,
6134,
275,
1056,
14,
2970,
14,
362,
360,
1562,
1333,
27,
267,
372,
6183,
8,
277,
14,
475,
63,
1001,
8,
14555,
395,
1564,
63,
466,
275,
283,
3578,
15,
1001,
297,
2004,
275,
1926,
9,
339,
347,
2963,
8,
277,
12,
1056,
304,
267,
6810,
14,
1462,
14,
981,
8,
288,
536,
275,
1056,
14,
4030,
14,
362,
480,
354,
1288,
288,
11437,
275,
1056,
14,
4030,
14,
362,
480,
474,
1288,
288,
2287,
275,
1056,
14,
4030,
14,
362,
480,
1562,
1288,
288,
7557,
18906,
275,
221,
715,
340,
1056,
14,
4030,
14,
362,
480,
4584,
18906,
531,
508,
283,
2052,
7,
587,
756,
267,
776,
267,
372,
6183,
8,
1205,
275,
1784,
9,
339,
347,
5324,
8,
277,
12,
1056,
12,
1890,
63,
344,
304,
267,
1890,
275,
6810,
14,
1462,
14,
362,
8,
2051,
275,
1890,
63,
344,
9,
267,
1890,
14,
354,
275,
1056,
14,
4013,
14,
362,
480,
354,
531,
267,
1890,
14,
474,
275,
1056,
14,
4013,
14,
362,
480,
474,
531,
267,
1890,
14,
1562,
275,
1056,
14,
4013,
14,
362,
480,
1562,
531,
267,
1890,
14,
4584,
18906,
275,
715,
340,
1056,
14,
4013,
14,
362,
480,
4584,
18906,
531,
508,
283,
2052,
7,
587,
756,
267,
1890,
14,
2117,
342,
267,
372,
6183,
8,
1205,
275,
1926,
9,
339,
347,
3145,
8,
277,
12,
1056,
12,
1890,
63,
344,
304,
267,
1890,
275,
6810,
14,
1462,
14,
362,
8,
2051,
275,
1890,
63,
344,
9,
267,
1890,
14,
1807,
342,
267,
372,
6183,
8,
1205,
275,
1926,
9,
339,
347,
370,
63,
1001,
8,
277,
12,
2251,
304,
267,
372,
12506,
14,
3549,
360,
1001,
297,
2251,
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
] |
[
1639,
14,
1014,
492,
6183,
199,
504,
1639,
14,
1018,
492,
12506,
199,
504,
1639,
14,
17469,
492,
3795,
199,
199,
504,
3486,
63,
3911,
492,
7337,
199,
199,
504,
1275,
992,
492,
6810,
199,
199,
318,
1478,
8,
1069,
304,
272,
372,
3795,
8,
1069,
12,
283,
1080,
14,
1360,
358,
421,
199,
533,
6810,
83,
8,
4031,
304,
339,
347,
664,
8,
277,
12,
1056,
304,
267,
13431,
275,
6810,
14,
1462,
14,
452,
342,
971,
288,
1275,
1541,
8,
354,
363,
6134,
275,
1056,
14,
2970,
14,
362,
360,
354,
1333,
971,
288,
1275,
1541,
8,
1562,
363,
6134,
275,
1056,
14,
2970,
14,
362,
360,
1562,
1333,
27,
267,
372,
6183,
8,
277,
14,
475,
63,
1001,
8,
14555,
395,
1564,
63,
466,
275,
283,
3578,
15,
1001,
297,
2004,
275,
1926,
9,
339,
347,
2963,
8,
277,
12,
1056,
304,
267,
6810,
14,
1462,
14,
981,
8,
288,
536,
275,
1056,
14,
4030,
14,
362,
480,
354,
1288,
288,
11437,
275,
1056,
14,
4030,
14,
362,
480,
474,
1288,
288,
2287,
275,
1056,
14,
4030,
14,
362,
480,
1562,
1288,
288,
7557,
18906,
275,
221,
715,
340,
1056,
14,
4030,
14,
362,
480,
4584,
18906,
531,
508,
283,
2052,
7,
587,
756,
267,
776,
267,
372,
6183,
8,
1205,
275,
1784,
9,
339,
347,
5324,
8,
277,
12,
1056,
12,
1890,
63,
344,
304,
267,
1890,
275,
6810,
14,
1462,
14,
362,
8,
2051,
275,
1890,
63,
344,
9,
267,
1890,
14,
354,
275,
1056,
14,
4013,
14,
362,
480,
354,
531,
267,
1890,
14,
474,
275,
1056,
14,
4013,
14,
362,
480,
474,
531,
267,
1890,
14,
1562,
275,
1056,
14,
4013,
14,
362,
480,
1562,
531,
267,
1890,
14,
4584,
18906,
275,
715,
340,
1056,
14,
4013,
14,
362,
480,
4584,
18906,
531,
508,
283,
2052,
7,
587,
756,
267,
1890,
14,
2117,
342,
267,
372,
6183,
8,
1205,
275,
1926,
9,
339,
347,
3145,
8,
277,
12,
1056,
12,
1890,
63,
344,
304,
267,
1890,
275,
6810,
14,
1462,
14,
362,
8,
2051,
275,
1890,
63,
344,
9,
267,
1890,
14,
1807,
342,
267,
372,
6183,
8,
1205,
275,
1926,
9,
339,
347,
370,
63,
1001,
8,
277,
12,
2251,
304,
267,
372,
12506,
14,
3549,
360,
1001,
297,
2251,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
VishvajitP/Django-facebook
|
docs/docs_env/Lib/site-packages/pip-1.0-py2.5.egg/pip/basecommand.py
|
25
|
6939
|
"""Base Command class, and related routines"""
import os
import socket
import sys
import traceback
import time
from pip import commands
from pip.log import logger
from pip.baseparser import parser, ConfigOptionParser, UpdatingDefaultsHelpFormatter
from pip.download import urlopen
from pip.exceptions import BadCommand, InstallationError, UninstallationError
from pip.venv import restart_in_venv
from pip.backwardcompat import StringIO, urllib, urllib2, walk_packages
__all__ = ['command_dict', 'Command', 'load_all_commands',
'load_command', 'command_names']
command_dict = {}
# for backwards compatibiliy
get_proxy = urlopen.get_proxy
class Command(object):
name = None
usage = None
hidden = False
def __init__(self):
assert self.name
self.parser = ConfigOptionParser(
usage=self.usage,
prog='%s %s' % (sys.argv[0], self.name),
version=parser.version,
formatter=UpdatingDefaultsHelpFormatter(),
name=self.name)
for option in parser.option_list:
if not option.dest or option.dest == 'help':
# -h, --version, etc
continue
self.parser.add_option(option)
command_dict[self.name] = self
def merge_options(self, initial_options, options):
# Make sure we have all global options carried over
for attr in ['log', 'venv', 'proxy', 'venv_base', 'require_venv',
'respect_venv', 'log_explicit_levels', 'log_file',
'timeout', 'default_vcs', 'skip_requirements_regex',
'no_input']:
setattr(options, attr, getattr(initial_options, attr) or getattr(options, attr))
options.quiet += initial_options.quiet
options.verbose += initial_options.verbose
def setup_logging(self):
pass
def main(self, complete_args, args, initial_options):
options, args = self.parser.parse_args(args)
self.merge_options(initial_options, options)
level = 1 # Notify
level += options.verbose
level -= options.quiet
level = logger.level_for_integer(4-level)
complete_log = []
logger.consumers.extend(
[(level, sys.stdout),
(logger.DEBUG, complete_log.append)])
if options.log_explicit_levels:
logger.explicit_levels = True
self.setup_logging()
if options.require_venv and not options.venv:
# If a venv is required check if it can really be found
if not os.environ.get('VIRTUAL_ENV'):
logger.fatal('Could not find an activated virtualenv (required).')
sys.exit(3)
# Automatically install in currently activated venv if required
options.respect_venv = True
if args and args[-1] == '___VENV_RESTART___':
## FIXME: We don't do anything this this value yet:
args = args[:-2]
options.venv = None
else:
# If given the option to respect the activated environment
# check if no venv is given as a command line parameter
if options.respect_venv and os.environ.get('VIRTUAL_ENV'):
if options.venv and os.path.exists(options.venv):
# Make sure command line venv and environmental are the same
if (os.path.realpath(os.path.expanduser(options.venv)) !=
os.path.realpath(os.environ.get('VIRTUAL_ENV'))):
logger.fatal("Given virtualenv (%s) doesn't match "
"currently activated virtualenv (%s)."
% (options.venv, os.environ.get('VIRTUAL_ENV')))
sys.exit(3)
else:
options.venv = os.environ.get('VIRTUAL_ENV')
logger.info('Using already activated environment %s' % options.venv)
if options.venv:
logger.info('Running in environment %s' % options.venv)
site_packages=False
if options.site_packages:
site_packages=True
restart_in_venv(options.venv, options.venv_base, site_packages,
complete_args)
# restart_in_venv should actually never return, but for clarity...
return
## FIXME: not sure if this sure come before or after venv restart
if options.log:
log_fp = open_logfile(options.log, 'a')
logger.consumers.append((logger.DEBUG, log_fp))
else:
log_fp = None
socket.setdefaulttimeout(options.timeout or None)
urlopen.setup(proxystr=options.proxy, prompting=not options.no_input)
exit = 0
try:
self.run(options, args)
except (InstallationError, UninstallationError):
e = sys.exc_info()[1]
logger.fatal(str(e))
logger.info('Exception information:\n%s' % format_exc())
exit = 1
except BadCommand:
e = sys.exc_info()[1]
logger.fatal(str(e))
logger.info('Exception information:\n%s' % format_exc())
exit = 1
except:
logger.fatal('Exception:\n%s' % format_exc())
exit = 2
if log_fp is not None:
log_fp.close()
if exit:
log_fn = options.log_file
text = '\n'.join(complete_log)
logger.fatal('Storing complete log in %s' % log_fn)
log_fp = open_logfile(log_fn, 'w')
log_fp.write(text)
log_fp.close()
return exit
def format_exc(exc_info=None):
if exc_info is None:
exc_info = sys.exc_info()
out = StringIO()
traceback.print_exception(*exc_info, **dict(file=out))
return out.getvalue()
def open_logfile(filename, mode='a'):
"""Open the named log file in append mode.
If the file already exists, a separator will also be printed to
the file to separate past activity from current activity.
"""
filename = os.path.expanduser(filename)
filename = os.path.abspath(filename)
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
os.makedirs(dirname)
exists = os.path.exists(filename)
log_fp = open(filename, mode)
if exists:
log_fp.write('%s\n' % ('-'*60))
log_fp.write('%s run on %s\n' % (sys.argv[0], time.strftime('%c')))
return log_fp
def load_command(name):
full_name = 'pip.commands.%s' % name
if full_name in sys.modules:
return
try:
__import__(full_name)
except ImportError:
pass
def load_all_commands():
for name in command_names():
load_command(name)
def command_names():
names = set((pkg[1] for pkg in walk_packages(path=commands.__path__)))
return list(names)
|
bsd-3-clause
|
[
624,
1563,
5817,
1021,
12,
436,
4048,
14975,
624,
199,
199,
646,
747,
199,
646,
2838,
199,
646,
984,
199,
646,
5190,
199,
646,
900,
199,
199,
504,
7305,
492,
3718,
199,
504,
7305,
14,
793,
492,
2512,
199,
504,
7305,
14,
1095,
2087,
492,
1798,
12,
4094,
14553,
12,
4949,
9239,
16986,
22779,
199,
504,
7305,
14,
4249,
492,
18279,
199,
504,
7305,
14,
3924,
492,
8857,
3110,
12,
26866,
547,
12,
1910,
23048,
547,
199,
504,
7305,
14,
23195,
492,
11004,
63,
262,
63,
23195,
199,
504,
7305,
14,
15457,
5819,
492,
5228,
12,
4011,
12,
4011,
18,
12,
12778,
63,
5154,
199,
199,
363,
452,
363,
275,
788,
1531,
63,
807,
297,
283,
3110,
297,
283,
912,
63,
452,
63,
4405,
297,
1779,
283,
912,
63,
1531,
297,
283,
1531,
63,
1247,
418,
199,
199,
1531,
63,
807,
275,
1052,
199,
199,
3,
367,
8552,
1013,
2159,
66,
1638,
89,
199,
362,
63,
3280,
275,
18279,
14,
362,
63,
3280,
421,
199,
533,
5817,
8,
785,
304,
272,
536,
275,
488,
272,
4503,
275,
488,
272,
8752,
275,
756,
339,
347,
636,
826,
721,
277,
304,
267,
702,
291,
14,
354,
267,
291,
14,
2087,
275,
4094,
14553,
8,
288,
4503,
29,
277,
14,
3807,
12,
288,
13205,
9569,
83,
450,
83,
7,
450,
334,
1274,
14,
3020,
59,
16,
467,
291,
14,
354,
395,
288,
1015,
29,
2087,
14,
1023,
12,
288,
9698,
29,
24993,
16986,
22779,
1062,
288,
536,
29,
277,
14,
354,
9,
267,
367,
945,
315,
1798,
14,
1422,
63,
513,
26,
288,
340,
440,
945,
14,
2614,
503,
945,
14,
2614,
508,
283,
3437,
356,
355,
327,
446,
72,
12,
1553,
1023,
12,
5423,
355,
1980,
288,
291,
14,
2087,
14,
525,
63,
1422,
8,
1422,
9,
267,
1414,
63,
807,
59,
277,
14,
354,
61,
275,
291,
339,
347,
5389,
63,
1419,
8,
277,
12,
2536,
63,
1419,
12,
1511,
304,
267,
327,
4155,
3238,
781,
1172,
1006,
2288,
1511,
9590,
18906,
1806,
267,
367,
1921,
315,
788,
793,
297,
283,
23195,
297,
283,
3280,
297,
283,
23195,
63,
1095,
297,
283,
4365,
63,
23195,
297,
2151,
283,
27872,
63,
23195,
297,
283,
793,
63,
10306,
63,
11402,
297,
283,
793,
63,
493,
297,
2151,
283,
2593,
297,
283,
885,
63,
15525,
297,
283,
2759,
63,
7538,
63,
3821,
297,
2151,
283,
889,
63,
1210,
2565,
288,
5371,
8,
1419,
12,
1921,
12,
2519,
8,
2747,
63,
1419,
12,
1921,
9,
503,
2519,
8,
1419,
12,
1921,
430,
267,
1511,
14,
10243,
847,
2536,
63,
1419,
14,
10243,
267,
1511,
14,
3832,
847,
2536,
63,
1419,
14,
3832,
339,
347,
3272,
63,
4806,
8,
277,
304,
267,
986,
339,
347,
2446,
8,
277,
12,
4890,
63,
589,
12,
1249,
12,
2536,
63,
1419,
304,
267,
1511,
12,
1249,
275,
291,
14,
2087,
14,
1122,
63,
589,
8,
589,
9,
267,
291,
14,
5628,
63,
1419,
8,
2747,
63,
1419,
12,
1511,
9,
398,
2166,
275,
413,
327,
31949,
267,
2166,
847,
1511,
14,
3832,
267,
2166,
4862,
1511,
14,
10243,
267,
2166,
275,
2512,
14,
1896,
63,
509,
63,
4115,
8,
20,
13,
1896,
9,
267,
4890,
63,
793,
275,
942,
267,
2512,
14,
10235,
2393,
14,
2880,
8,
288,
3842,
1896,
12,
984,
14,
2703,
395,
1467,
334,
2921,
14,
5287,
12,
4890,
63,
793,
14,
740,
3948,
267,
340,
1511,
14,
793,
63,
10306,
63,
11402,
26,
288,
2512,
14,
10306,
63,
11402,
275,
715,
398,
291,
14,
2758,
63,
4806,
342,
398,
340,
1511,
14,
4365,
63,
23195,
436,
440,
1511,
14,
23195,
26,
288,
327,
982,
282,
373,
1813,
365,
1415,
1104,
340,
652,
883,
7710,
506,
1911,
288,
340,
440,
747,
14,
2314,
14,
362,
360,
25618,
63,
9984,
735,
355,
2512,
14,
16208,
360,
6531,
440,
2342,
376,
22225,
19128,
334,
2427,
28583,
355,
984,
14,
2224,
8,
19,
9,
288,
327,
9195,
17174,
3907,
315,
5544,
22225,
373,
1813,
340,
1415,
288,
1511,
14,
27872,
63,
23195,
275,
715,
398,
340,
1249,
436,
1249,
1988,
17,
61,
508,
2560,
63,
8253,
54,
63,
15740,
2294,
8989,
356,
288,
925,
7600,
26,
2136,
2793,
1133,
886,
7003,
642,
642,
574,
5966,
26,
288,
1249,
275,
1249,
4439,
18,
61,
288,
1511,
14,
23195,
275,
488,
267,
587,
26,
288,
327,
982,
1627,
314,
945,
370,
14021,
314,
22225,
3734,
288,
327,
1104,
340,
949,
373,
1813,
365,
1627,
465,
282,
1414,
1004,
2725,
288,
340,
1511,
14,
27872,
63,
23195,
436,
747,
14,
2314,
14,
362,
360,
25618,
63,
9984,
735,
355,
340,
1511,
14,
23195,
436,
747,
14,
515,
14,
2444,
8,
1419,
14,
23195,
304,
490,
327,
4155,
3238,
1414,
1004,
373,
1813,
436,
3734,
279,
787,
314,
2011,
490,
340,
334,
736,
14,
515,
14,
11091,
8,
736,
14,
515,
14,
12131,
8,
1419,
14,
23195,
430,
1137,
1169,
747,
14,
515,
14,
11091,
8,
736,
14,
2314,
14,
362,
360,
25618,
63,
9984,
1333,
304,
717,
2512,
14,
16208,
480,
13735,
19128,
4366,
83,
9,
3181,
1133,
1336,
298,
3660,
298,
19767,
22225,
19128,
4366,
83,
17617,
3660,
450,
334,
1419,
14,
23195,
12,
747,
14,
2314,
14,
362,
360,
25618,
63,
9984,
7058,
717,
984,
14,
2224,
8,
19,
9,
355,
587,
26,
490,
1511,
14,
23195,
275,
747,
14,
2314,
14,
362,
360,
25618,
63,
9984,
358,
490,
2512,
14,
815,
360,
10369,
2575,
22225,
3734,
450,
83,
7,
450,
1511,
14,
23195,
9,
267,
340,
1511,
14,
23195,
26,
288,
2512,
14,
815,
360,
9602,
315,
3734,
450,
83,
7,
450,
1511,
14,
23195,
9,
288,
4770,
63,
5154,
29,
797,
288,
340,
1511,
14,
2124,
63,
5154,
26,
355,
4770,
63,
5154,
29,
549,
288,
11004,
63,
262,
63,
23195,
8,
1419,
14,
23195,
12,
1511,
14,
23195,
63,
1095,
12,
4770,
63,
5154,
12,
1169,
4890,
63,
589,
9,
288,
327,
11004,
63,
262,
63,
23195,
1077,
5965,
7078,
372,
12,
1325,
367,
824,
7945,
1396,
288,
372,
398,
925,
7600,
26,
440,
3238,
340,
642,
3238,
11492,
2544,
503,
2410,
373,
1813,
11004,
267,
340,
1511,
14,
793,
26,
288,
943,
63,
3997,
275,
1551,
63,
12804,
8,
1419
] |
[
1563,
5817,
1021,
12,
436,
4048,
14975,
624,
199,
199,
646,
747,
199,
646,
2838,
199,
646,
984,
199,
646,
5190,
199,
646,
900,
199,
199,
504,
7305,
492,
3718,
199,
504,
7305,
14,
793,
492,
2512,
199,
504,
7305,
14,
1095,
2087,
492,
1798,
12,
4094,
14553,
12,
4949,
9239,
16986,
22779,
199,
504,
7305,
14,
4249,
492,
18279,
199,
504,
7305,
14,
3924,
492,
8857,
3110,
12,
26866,
547,
12,
1910,
23048,
547,
199,
504,
7305,
14,
23195,
492,
11004,
63,
262,
63,
23195,
199,
504,
7305,
14,
15457,
5819,
492,
5228,
12,
4011,
12,
4011,
18,
12,
12778,
63,
5154,
199,
199,
363,
452,
363,
275,
788,
1531,
63,
807,
297,
283,
3110,
297,
283,
912,
63,
452,
63,
4405,
297,
1779,
283,
912,
63,
1531,
297,
283,
1531,
63,
1247,
418,
199,
199,
1531,
63,
807,
275,
1052,
199,
199,
3,
367,
8552,
1013,
2159,
66,
1638,
89,
199,
362,
63,
3280,
275,
18279,
14,
362,
63,
3280,
421,
199,
533,
5817,
8,
785,
304,
272,
536,
275,
488,
272,
4503,
275,
488,
272,
8752,
275,
756,
339,
347,
636,
826,
721,
277,
304,
267,
702,
291,
14,
354,
267,
291,
14,
2087,
275,
4094,
14553,
8,
288,
4503,
29,
277,
14,
3807,
12,
288,
13205,
9569,
83,
450,
83,
7,
450,
334,
1274,
14,
3020,
59,
16,
467,
291,
14,
354,
395,
288,
1015,
29,
2087,
14,
1023,
12,
288,
9698,
29,
24993,
16986,
22779,
1062,
288,
536,
29,
277,
14,
354,
9,
267,
367,
945,
315,
1798,
14,
1422,
63,
513,
26,
288,
340,
440,
945,
14,
2614,
503,
945,
14,
2614,
508,
283,
3437,
356,
355,
327,
446,
72,
12,
1553,
1023,
12,
5423,
355,
1980,
288,
291,
14,
2087,
14,
525,
63,
1422,
8,
1422,
9,
267,
1414,
63,
807,
59,
277,
14,
354,
61,
275,
291,
339,
347,
5389,
63,
1419,
8,
277,
12,
2536,
63,
1419,
12,
1511,
304,
267,
327,
4155,
3238,
781,
1172,
1006,
2288,
1511,
9590,
18906,
1806,
267,
367,
1921,
315,
788,
793,
297,
283,
23195,
297,
283,
3280,
297,
283,
23195,
63,
1095,
297,
283,
4365,
63,
23195,
297,
2151,
283,
27872,
63,
23195,
297,
283,
793,
63,
10306,
63,
11402,
297,
283,
793,
63,
493,
297,
2151,
283,
2593,
297,
283,
885,
63,
15525,
297,
283,
2759,
63,
7538,
63,
3821,
297,
2151,
283,
889,
63,
1210,
2565,
288,
5371,
8,
1419,
12,
1921,
12,
2519,
8,
2747,
63,
1419,
12,
1921,
9,
503,
2519,
8,
1419,
12,
1921,
430,
267,
1511,
14,
10243,
847,
2536,
63,
1419,
14,
10243,
267,
1511,
14,
3832,
847,
2536,
63,
1419,
14,
3832,
339,
347,
3272,
63,
4806,
8,
277,
304,
267,
986,
339,
347,
2446,
8,
277,
12,
4890,
63,
589,
12,
1249,
12,
2536,
63,
1419,
304,
267,
1511,
12,
1249,
275,
291,
14,
2087,
14,
1122,
63,
589,
8,
589,
9,
267,
291,
14,
5628,
63,
1419,
8,
2747,
63,
1419,
12,
1511,
9,
398,
2166,
275,
413,
327,
31949,
267,
2166,
847,
1511,
14,
3832,
267,
2166,
4862,
1511,
14,
10243,
267,
2166,
275,
2512,
14,
1896,
63,
509,
63,
4115,
8,
20,
13,
1896,
9,
267,
4890,
63,
793,
275,
942,
267,
2512,
14,
10235,
2393,
14,
2880,
8,
288,
3842,
1896,
12,
984,
14,
2703,
395,
1467,
334,
2921,
14,
5287,
12,
4890,
63,
793,
14,
740,
3948,
267,
340,
1511,
14,
793,
63,
10306,
63,
11402,
26,
288,
2512,
14,
10306,
63,
11402,
275,
715,
398,
291,
14,
2758,
63,
4806,
342,
398,
340,
1511,
14,
4365,
63,
23195,
436,
440,
1511,
14,
23195,
26,
288,
327,
982,
282,
373,
1813,
365,
1415,
1104,
340,
652,
883,
7710,
506,
1911,
288,
340,
440,
747,
14,
2314,
14,
362,
360,
25618,
63,
9984,
735,
355,
2512,
14,
16208,
360,
6531,
440,
2342,
376,
22225,
19128,
334,
2427,
28583,
355,
984,
14,
2224,
8,
19,
9,
288,
327,
9195,
17174,
3907,
315,
5544,
22225,
373,
1813,
340,
1415,
288,
1511,
14,
27872,
63,
23195,
275,
715,
398,
340,
1249,
436,
1249,
1988,
17,
61,
508,
2560,
63,
8253,
54,
63,
15740,
2294,
8989,
356,
288,
925,
7600,
26,
2136,
2793,
1133,
886,
7003,
642,
642,
574,
5966,
26,
288,
1249,
275,
1249,
4439,
18,
61,
288,
1511,
14,
23195,
275,
488,
267,
587,
26,
288,
327,
982,
1627,
314,
945,
370,
14021,
314,
22225,
3734,
288,
327,
1104,
340,
949,
373,
1813,
365,
1627,
465,
282,
1414,
1004,
2725,
288,
340,
1511,
14,
27872,
63,
23195,
436,
747,
14,
2314,
14,
362,
360,
25618,
63,
9984,
735,
355,
340,
1511,
14,
23195,
436,
747,
14,
515,
14,
2444,
8,
1419,
14,
23195,
304,
490,
327,
4155,
3238,
1414,
1004,
373,
1813,
436,
3734,
279,
787,
314,
2011,
490,
340,
334,
736,
14,
515,
14,
11091,
8,
736,
14,
515,
14,
12131,
8,
1419,
14,
23195,
430,
1137,
1169,
747,
14,
515,
14,
11091,
8,
736,
14,
2314,
14,
362,
360,
25618,
63,
9984,
1333,
304,
717,
2512,
14,
16208,
480,
13735,
19128,
4366,
83,
9,
3181,
1133,
1336,
298,
3660,
298,
19767,
22225,
19128,
4366,
83,
17617,
3660,
450,
334,
1419,
14,
23195,
12,
747,
14,
2314,
14,
362,
360,
25618,
63,
9984,
7058,
717,
984,
14,
2224,
8,
19,
9,
355,
587,
26,
490,
1511,
14,
23195,
275,
747,
14,
2314,
14,
362,
360,
25618,
63,
9984,
358,
490,
2512,
14,
815,
360,
10369,
2575,
22225,
3734,
450,
83,
7,
450,
1511,
14,
23195,
9,
267,
340,
1511,
14,
23195,
26,
288,
2512,
14,
815,
360,
9602,
315,
3734,
450,
83,
7,
450,
1511,
14,
23195,
9,
288,
4770,
63,
5154,
29,
797,
288,
340,
1511,
14,
2124,
63,
5154,
26,
355,
4770,
63,
5154,
29,
549,
288,
11004,
63,
262,
63,
23195,
8,
1419,
14,
23195,
12,
1511,
14,
23195,
63,
1095,
12,
4770,
63,
5154,
12,
1169,
4890,
63,
589,
9,
288,
327,
11004,
63,
262,
63,
23195,
1077,
5965,
7078,
372,
12,
1325,
367,
824,
7945,
1396,
288,
372,
398,
925,
7600,
26,
440,
3238,
340,
642,
3238,
11492,
2544,
503,
2410,
373,
1813,
11004,
267,
340,
1511,
14,
793,
26,
288,
943,
63,
3997,
275,
1551,
63,
12804,
8,
1419,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
allenp/odoo
|
addons/website_blog/models/website_blog.py
|
3
|
12036
|
# -*- coding: utf-8 -*-
from datetime import datetime
import lxml
import random
from openerp import tools
from openerp import SUPERUSER_ID
from openerp.addons.website.models.website import slug
from openerp.osv import osv, fields
from openerp.tools.translate import _
class Blog(osv.Model):
_name = 'blog.blog'
_description = 'Blogs'
_inherit = ['mail.thread', 'website.seo.metadata']
_order = 'name'
_columns = {
'name': fields.char('Blog Name', required=True, translate=True),
'subtitle': fields.char('Blog Subtitle', translate=True),
}
def all_tags(self, cr, uid, ids, min_limit=1, context=None):
req = """
SELECT
p.blog_id, count(*), r.blog_tag_id
FROM
blog_post_blog_tag_rel r
join blog_post p on r.blog_post_id=p.id
WHERE
p.blog_id in %s
GROUP BY
p.blog_id,
r.blog_tag_id
ORDER BY
count(*) DESC
"""
cr.execute(req, [tuple(ids)])
tag_by_blog = {i: [] for i in ids}
for blog_id, freq, tag_id in cr.fetchall():
if freq >= min_limit:
tag_by_blog[blog_id].append(tag_id)
tag_obj = self.pool['blog.tag']
for blog_id in tag_by_blog:
tag_by_blog[blog_id] = tag_obj.browse(cr, uid, tag_by_blog[blog_id], context=context)
return tag_by_blog
class BlogTag(osv.Model):
_name = 'blog.tag'
_description = 'Blog Tag'
_inherit = ['website.seo.metadata']
_order = 'name'
_columns = {
'name': fields.char('Name', required=True),
'post_ids': fields.many2many(
'blog.post', string='Posts',
),
}
_sql_constraints = [
('name_uniq', 'unique (name)', "Tag name already exists !"),
]
class BlogPost(osv.Model):
_name = "blog.post"
_description = "Blog Post"
_inherit = ['mail.thread', 'website.seo.metadata', 'website.published.mixin']
_order = 'id DESC'
_mail_post_access = 'read'
def _website_url(self, cr, uid, ids, field_name, arg, context=None):
res = super(BlogPost, self)._website_url(cr, uid, ids, field_name, arg, context=context)
for blog_post in self.browse(cr, uid, ids, context=context):
res[blog_post.id] = "/blog/%s/post/%s" % (slug(blog_post.blog_id), slug(blog_post))
return res
def _compute_ranking(self, cr, uid, ids, name, arg, context=None):
res = {}
for blog_post in self.browse(cr, uid, ids, context=context):
age = datetime.now() - datetime.strptime(blog_post.create_date, tools.DEFAULT_SERVER_DATETIME_FORMAT)
res[blog_post.id] = blog_post.visits * (0.5+random.random()) / max(3, age.days)
return res
def _default_content(self, cr, uid, context=None):
return ''' <div class="container">
<section class="mt16 mb16">
<p class="o_default_snippet_text">''' + _("Start writing here...") + '''</p>
</section>
</div> '''
_columns = {
'name': fields.char('Title', required=True, translate=True),
'subtitle': fields.char('Sub Title', translate=True),
'author_id': fields.many2one('res.partner', 'Author'),
'cover_properties': fields.text('Cover Properties'),
'blog_id': fields.many2one(
'blog.blog', 'Blog',
required=True, ondelete='cascade',
),
'tag_ids': fields.many2many(
'blog.tag', string='Tags',
),
'content': fields.html('Content', translate=True, sanitize=False),
'website_message_ids': fields.one2many(
'mail.message', 'res_id',
domain=lambda self: [
'&', '&', ('model', '=', self._name), ('message_type', '=', 'comment'), ('path', '=', False)
],
string='Website Messages',
help="Website communication history",
),
# creation / update stuff
'create_date': fields.datetime(
'Created on',
select=True, readonly=True,
),
'create_uid': fields.many2one(
'res.users', 'Author',
select=True, readonly=True,
),
'write_date': fields.datetime(
'Last Modified on',
select=True, readonly=True,
),
'write_uid': fields.many2one(
'res.users', 'Last Contributor',
select=True, readonly=True,
),
'author_avatar': fields.related(
'author_id', 'image_small',
string="Avatar", type="binary"),
'visits': fields.integer('No of Views'),
'ranking': fields.function(_compute_ranking, string='Ranking', type='float'),
}
_defaults = {
'name': '',
'content': _default_content,
'cover_properties': '{"background-image": "none", "background-color": "oe_none", "opacity": "0.6", "resize_class": ""}',
'author_id': lambda self, cr, uid, ctx=None: self.pool['res.users'].browse(cr, uid, uid, context=ctx).partner_id.id,
}
def html_tag_nodes(self, html, attribute=None, tags=None, context=None):
""" Processing of html content to tag paragraphs and set them an unique
ID.
:return result: (html, mappin), where html is the updated html with ID
and mapping is a list of (old_ID, new_ID), where old_ID
is None is the paragraph is a new one. """
existing_attributes = []
mapping = []
if not html:
return html, mapping
if tags is None:
tags = ['p']
if attribute is None:
attribute = 'data-unique-id'
# form a tree
root = lxml.html.fragment_fromstring(html, create_parent='div')
if not len(root) and root.text is None and root.tail is None:
return html, mapping
# check all nodes, replace :
# - img src -> check URL
# - a href -> check URL
for node in root.iter():
if node.tag not in tags:
continue
ancestor_tags = [parent.tag for parent in node.iterancestors()]
old_attribute = node.get(attribute)
new_attribute = old_attribute
if not new_attribute or (old_attribute in existing_attributes):
if ancestor_tags:
ancestor_tags.pop()
counter = random.randint(10000, 99999)
ancestor_tags.append('counter_%s' % counter)
new_attribute = '/'.join(reversed(ancestor_tags))
node.set(attribute, new_attribute)
existing_attributes.append(new_attribute)
mapping.append((old_attribute, new_attribute))
html = lxml.html.tostring(root, pretty_print=False, method='html')
# this is ugly, but lxml/etree tostring want to put everything in a 'div' that breaks the editor -> remove that
if html.startswith('<div>') and html.endswith('</div>'):
html = html[5:-6]
return html, mapping
def _postproces_content(self, cr, uid, id, content=None, context=None):
if content is None:
content = self.browse(cr, uid, id, context=context).content
if content is False:
return content
content, mapping = self.html_tag_nodes(content, attribute='data-chatter-id', tags=['p'], context=context)
if id: # not creating
existing = [x[0] for x in mapping if x[0]]
msg_ids = self.pool['mail.message'].search(cr, SUPERUSER_ID, [
('res_id', '=', id),
('model', '=', self._name),
('path', 'not in', existing),
('path', '!=', False)
], context=context)
self.pool['mail.message'].unlink(cr, SUPERUSER_ID, msg_ids, context=context)
return content
def _check_for_publication(self, cr, uid, ids, vals, context=None):
if vals.get('website_published'):
base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url')
for post in self.browse(cr, uid, ids, context=context):
post.blog_id.message_post(
body='<p>%(post_publication)s <a href="%(base_url)s/blog/%(blog_slug)s/post/%(post_slug)s">%(post_link)s</a></p>' % {
'post_publication': _('A new post %s has been published on the %s blog.') % (post.name, post.blog_id.name),
'post_link': _('Click here to access the post.'),
'base_url': base_url,
'blog_slug': slug(post.blog_id),
'post_slug': slug(post),
},
subtype='website_blog.mt_blog_blog_published')
return True
return False
def create(self, cr, uid, vals, context=None):
if context is None:
context = {}
if 'content' in vals:
vals['content'] = self._postproces_content(cr, uid, None, vals['content'], context=context)
create_context = dict(context, mail_create_nolog=True)
post_id = super(BlogPost, self).create(cr, uid, vals, context=create_context)
self._check_for_publication(cr, uid, [post_id], vals, context=context)
return post_id
def write(self, cr, uid, ids, vals, context=None):
if isinstance(ids, (int, long)):
ids = [ids]
if 'content' in vals:
vals['content'] = self._postproces_content(cr, uid, ids[0], vals['content'], context=context)
result = super(BlogPost, self).write(cr, uid, ids, vals, context)
self._check_for_publication(cr, uid, ids, vals, context=context)
return result
def get_access_action(self, cr, uid, ids, context=None):
""" Override method that generated the link to access the document. Instead
of the classic form view, redirect to the post on the website directly """
post = self.browse(cr, uid, ids[0], context=context)
return {
'type': 'ir.actions.act_url',
'url': '/blog/%s/post/%s' % (post.blog_id.id, post.id),
'target': 'self',
'res_id': self.id,
}
def _notification_get_recipient_groups(self, cr, uid, ids, message, recipients, context=None):
""" Override to set the access button: everyone can see an access button
on their notification email. It will lead on the website view of the
post. """
res = super(BlogPost, self)._notification_get_recipient_groups(cr, uid, ids, message, recipients, context=context)
access_action = self._notification_link_helper('view', model=message.model, res_id=message.res_id)
for category, data in res.iteritems():
res[category]['button_access'] = {'url': access_action, 'title': _('View Blog Post')}
return res
class Website(osv.Model):
_inherit = "website"
def page_search_dependencies(self, cr, uid, view_id, context=None):
dep = super(Website, self).page_search_dependencies(cr, uid, view_id, context=context)
post_obj = self.pool.get('blog.post')
view = self.pool.get('ir.ui.view').browse(cr, uid, view_id, context=context)
name = view.key.replace("website.", "")
fullname = "website.%s" % name
dom = [
'|', ('content', 'ilike', '/page/%s' % name), ('content', 'ilike', '/page/%s' % fullname)
]
posts = post_obj.search(cr, uid, dom, context=context)
if posts:
page_key = _('Blog Post')
dep[page_key] = []
for p in post_obj.browse(cr, uid, posts, context=context):
dep[page_key].append({
'text': _('Blog Post <b>%s</b> seems to have a link to this page !' % p.name),
'link': p.website_url
})
return dep
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
2197,
492,
2197,
199,
646,
14490,
199,
646,
2196,
199,
199,
504,
5166,
492,
7249,
199,
504,
5166,
492,
12824,
63,
998,
199,
504,
5166,
14,
10788,
14,
7360,
14,
992,
14,
7360,
492,
8889,
199,
504,
5166,
14,
4795,
492,
9506,
12,
1504,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
421,
199,
533,
29775,
8,
4795,
14,
1685,
304,
272,
485,
354,
275,
283,
11486,
14,
11486,
7,
272,
485,
1802,
275,
283,
34,
7270,
7,
272,
485,
6486,
275,
788,
1198,
14,
2671,
297,
283,
7360,
14,
261,
79,
14,
2343,
418,
272,
485,
1648,
275,
283,
354,
7,
272,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
26081,
2812,
297,
1415,
29,
549,
12,
9028,
29,
549,
395,
267,
283,
14348,
356,
1504,
14,
1560,
360,
26081,
4804,
1213,
297,
9028,
29,
549,
395,
272,
789,
339,
347,
1006,
63,
2969,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1748,
63,
3097,
29,
17,
12,
1067,
29,
403,
304,
267,
2648,
275,
408,
288,
10468,
355,
299,
14,
11486,
63,
344,
12,
2338,
2031,
395,
519,
14,
11486,
63,
1450,
63,
344,
288,
4442,
355,
19936,
63,
1932,
63,
11486,
63,
1450,
63,
3369,
519,
490,
4263,
19936,
63,
1932,
299,
641,
519,
14,
11486,
63,
1932,
63,
344,
29,
80,
14,
344,
288,
6038,
355,
299,
14,
11486,
63,
344,
315,
450,
83,
288,
15443,
6515,
355,
299,
14,
11486,
63,
344,
12,
355,
519,
14,
11486,
63,
1450,
63,
344,
288,
16044,
6515,
355,
2338,
21565,
23915,
267,
408,
267,
2467,
14,
2526,
8,
2103,
12,
359,
2960,
8,
1580,
3948,
267,
1947,
63,
991,
63,
11486,
275,
469,
73,
26,
942,
367,
284,
315,
2762,
93,
267,
367,
19936,
63,
344,
12,
9220,
12,
1947,
63,
344,
315,
2467,
14,
10174,
837,
288,
340,
9220,
2356,
1748,
63,
3097,
26,
355,
1947,
63,
991,
63,
11486,
59,
11486,
63,
344,
1055,
740,
8,
1450,
63,
344,
9,
398,
1947,
63,
1113,
275,
291,
14,
2293,
459,
11486,
14,
1450,
418,
267,
367,
19936,
63,
344,
315,
1947,
63,
991,
63,
11486,
26,
288,
1947,
63,
991,
63,
11486,
59,
11486,
63,
344,
61,
275,
1947,
63,
1113,
14,
4570,
8,
1556,
12,
1747,
12,
1947,
63,
991,
63,
11486,
59,
11486,
63,
344,
467,
1067,
29,
1100,
9,
267,
372,
1947,
63,
991,
63,
11486,
421,
199,
533,
29775,
1931,
8,
4795,
14,
1685,
304,
272,
485,
354,
275,
283,
11486,
14,
1450,
7,
272,
485,
1802,
275,
283,
26081,
8053,
7,
272,
485,
6486,
275,
788,
7360,
14,
261,
79,
14,
2343,
418,
272,
485,
1648,
275,
283,
354,
7,
272,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
985,
297,
1415,
29,
549,
395,
267,
283,
1932,
63,
1580,
356,
1504,
14,
3479,
18,
3479,
8,
288,
283,
11486,
14,
1932,
297,
1059,
534,
6564,
83,
297,
267,
2318,
272,
789,
272,
485,
3009,
63,
9882,
275,
359,
288,
661,
354,
63,
22484,
297,
283,
3235,
334,
354,
3196,
298,
1931,
536,
2575,
3495,
8546,
1288,
272,
1622,
421,
199,
533,
29775,
6564,
8,
4795,
14,
1685,
304,
272,
485,
354,
275,
298,
11486,
14,
1932,
2,
272,
485,
1802,
275,
298,
26081,
7711,
2,
272,
485,
6486,
275,
788,
1198,
14,
2671,
297,
283,
7360,
14,
261,
79,
14,
2343,
297,
283,
7360,
14,
8987,
14,
20406,
418,
272,
485,
1648,
275,
283,
344,
23915,
7,
272,
485,
1198,
63,
1932,
63,
2732,
275,
283,
739,
7,
339,
347,
485,
7360,
63,
633,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
901,
63,
354,
12,
1680,
12,
1067,
29,
403,
304,
267,
522,
275,
1613,
8,
26081,
6564,
12,
291,
10445,
7360,
63,
633,
8,
1556,
12,
1747,
12,
2762,
12,
901,
63,
354,
12,
1680,
12,
1067,
29,
1100,
9,
267,
367,
19936,
63,
1932,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
522,
59,
11486,
63,
1932,
14,
344,
61,
275,
3286,
11486,
3149,
83,
15,
1932,
3149,
83,
2,
450,
334,
5464,
8,
11486,
63,
1932,
14,
11486,
63,
344,
395,
8889,
8,
11486,
63,
1932,
430,
267,
372,
522,
339,
347,
485,
3357,
63,
31950,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1680,
12,
1067,
29,
403,
304,
267,
522,
275,
1052,
267,
367,
19936,
63,
1932,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
11437,
275,
2197,
14,
2131,
342,
446,
2197,
14,
9866,
8,
11486,
63,
1932,
14,
981,
63,
602,
12,
7249,
14,
3472,
63,
6613,
63,
12488,
63,
4807,
9,
288,
522,
59,
11486,
63,
1932,
14,
344,
61,
275,
19936,
63,
1932,
14,
433,
30066,
627,
334,
16,
14,
21,
11,
2355,
14,
2355,
1012,
1182,
1390,
8,
19,
12,
11437,
14,
4899,
9,
267,
372,
522,
339,
347,
485,
885,
63,
1317,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
372,
1449,
221,
665,
3015,
1021,
628,
3600,
1743,
717,
665,
2792,
1021,
628,
2037,
975,
21187,
975,
1743,
1169,
665,
80,
1021,
628,
79,
63,
885,
63,
18547,
63,
505,
1743,
2344,
435,
3824,
3162,
3575,
2348,
12594,
435,
1449,
1108,
80,
30,
717,
3068,
2792,
30,
490,
3068,
3015,
30,
1449,
339,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
6888,
297,
1415,
29,
549,
12,
9028,
29,
549,
395,
267,
283,
14348,
356,
1504,
14,
1560,
360,
2610,
16881,
297,
9028,
29,
549,
395,
267,
283,
2502,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
3899,
297,
283,
5949,
659,
267,
283,
5899,
63,
3282,
356,
1504,
14,
505,
360,
31048,
19329,
659,
267,
283,
11486,
63,
344,
356,
1504,
14,
3479,
18,
368,
8,
288,
283,
11486,
14,
11486,
297,
283,
26081,
297,
288,
1415,
29,
549,
12,
16549,
534,
15377,
297,
267,
2318,
267,
283,
1450,
63,
1580,
356,
1504,
14,
3479,
18,
3479,
8,
288,
283,
11486,
14,
1450,
297,
1059,
534,
9440,
297,
267
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
2197,
492,
2197,
199,
646,
14490,
199,
646,
2196,
199,
199,
504,
5166,
492,
7249,
199,
504,
5166,
492,
12824,
63,
998,
199,
504,
5166,
14,
10788,
14,
7360,
14,
992,
14,
7360,
492,
8889,
199,
504,
5166,
14,
4795,
492,
9506,
12,
1504,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
421,
199,
533,
29775,
8,
4795,
14,
1685,
304,
272,
485,
354,
275,
283,
11486,
14,
11486,
7,
272,
485,
1802,
275,
283,
34,
7270,
7,
272,
485,
6486,
275,
788,
1198,
14,
2671,
297,
283,
7360,
14,
261,
79,
14,
2343,
418,
272,
485,
1648,
275,
283,
354,
7,
272,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
26081,
2812,
297,
1415,
29,
549,
12,
9028,
29,
549,
395,
267,
283,
14348,
356,
1504,
14,
1560,
360,
26081,
4804,
1213,
297,
9028,
29,
549,
395,
272,
789,
339,
347,
1006,
63,
2969,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1748,
63,
3097,
29,
17,
12,
1067,
29,
403,
304,
267,
2648,
275,
408,
288,
10468,
355,
299,
14,
11486,
63,
344,
12,
2338,
2031,
395,
519,
14,
11486,
63,
1450,
63,
344,
288,
4442,
355,
19936,
63,
1932,
63,
11486,
63,
1450,
63,
3369,
519,
490,
4263,
19936,
63,
1932,
299,
641,
519,
14,
11486,
63,
1932,
63,
344,
29,
80,
14,
344,
288,
6038,
355,
299,
14,
11486,
63,
344,
315,
450,
83,
288,
15443,
6515,
355,
299,
14,
11486,
63,
344,
12,
355,
519,
14,
11486,
63,
1450,
63,
344,
288,
16044,
6515,
355,
2338,
21565,
23915,
267,
408,
267,
2467,
14,
2526,
8,
2103,
12,
359,
2960,
8,
1580,
3948,
267,
1947,
63,
991,
63,
11486,
275,
469,
73,
26,
942,
367,
284,
315,
2762,
93,
267,
367,
19936,
63,
344,
12,
9220,
12,
1947,
63,
344,
315,
2467,
14,
10174,
837,
288,
340,
9220,
2356,
1748,
63,
3097,
26,
355,
1947,
63,
991,
63,
11486,
59,
11486,
63,
344,
1055,
740,
8,
1450,
63,
344,
9,
398,
1947,
63,
1113,
275,
291,
14,
2293,
459,
11486,
14,
1450,
418,
267,
367,
19936,
63,
344,
315,
1947,
63,
991,
63,
11486,
26,
288,
1947,
63,
991,
63,
11486,
59,
11486,
63,
344,
61,
275,
1947,
63,
1113,
14,
4570,
8,
1556,
12,
1747,
12,
1947,
63,
991,
63,
11486,
59,
11486,
63,
344,
467,
1067,
29,
1100,
9,
267,
372,
1947,
63,
991,
63,
11486,
421,
199,
533,
29775,
1931,
8,
4795,
14,
1685,
304,
272,
485,
354,
275,
283,
11486,
14,
1450,
7,
272,
485,
1802,
275,
283,
26081,
8053,
7,
272,
485,
6486,
275,
788,
7360,
14,
261,
79,
14,
2343,
418,
272,
485,
1648,
275,
283,
354,
7,
272,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
985,
297,
1415,
29,
549,
395,
267,
283,
1932,
63,
1580,
356,
1504,
14,
3479,
18,
3479,
8,
288,
283,
11486,
14,
1932,
297,
1059,
534,
6564,
83,
297,
267,
2318,
272,
789,
272,
485,
3009,
63,
9882,
275,
359,
288,
661,
354,
63,
22484,
297,
283,
3235,
334,
354,
3196,
298,
1931,
536,
2575,
3495,
8546,
1288,
272,
1622,
421,
199,
533,
29775,
6564,
8,
4795,
14,
1685,
304,
272,
485,
354,
275,
298,
11486,
14,
1932,
2,
272,
485,
1802,
275,
298,
26081,
7711,
2,
272,
485,
6486,
275,
788,
1198,
14,
2671,
297,
283,
7360,
14,
261,
79,
14,
2343,
297,
283,
7360,
14,
8987,
14,
20406,
418,
272,
485,
1648,
275,
283,
344,
23915,
7,
272,
485,
1198,
63,
1932,
63,
2732,
275,
283,
739,
7,
339,
347,
485,
7360,
63,
633,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
901,
63,
354,
12,
1680,
12,
1067,
29,
403,
304,
267,
522,
275,
1613,
8,
26081,
6564,
12,
291,
10445,
7360,
63,
633,
8,
1556,
12,
1747,
12,
2762,
12,
901,
63,
354,
12,
1680,
12,
1067,
29,
1100,
9,
267,
367,
19936,
63,
1932,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
522,
59,
11486,
63,
1932,
14,
344,
61,
275,
3286,
11486,
3149,
83,
15,
1932,
3149,
83,
2,
450,
334,
5464,
8,
11486,
63,
1932,
14,
11486,
63,
344,
395,
8889,
8,
11486,
63,
1932,
430,
267,
372,
522,
339,
347,
485,
3357,
63,
31950,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1680,
12,
1067,
29,
403,
304,
267,
522,
275,
1052,
267,
367,
19936,
63,
1932,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
11437,
275,
2197,
14,
2131,
342,
446,
2197,
14,
9866,
8,
11486,
63,
1932,
14,
981,
63,
602,
12,
7249,
14,
3472,
63,
6613,
63,
12488,
63,
4807,
9,
288,
522,
59,
11486,
63,
1932,
14,
344,
61,
275,
19936,
63,
1932,
14,
433,
30066,
627,
334,
16,
14,
21,
11,
2355,
14,
2355,
1012,
1182,
1390,
8,
19,
12,
11437,
14,
4899,
9,
267,
372,
522,
339,
347,
485,
885,
63,
1317,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
372,
1449,
221,
665,
3015,
1021,
628,
3600,
1743,
717,
665,
2792,
1021,
628,
2037,
975,
21187,
975,
1743,
1169,
665,
80,
1021,
628,
79,
63,
885,
63,
18547,
63,
505,
1743,
2344,
435,
3824,
3162,
3575,
2348,
12594,
435,
1449,
1108,
80,
30,
717,
3068,
2792,
30,
490,
3068,
3015,
30,
1449,
339,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
6888,
297,
1415,
29,
549,
12,
9028,
29,
549,
395,
267,
283,
14348,
356,
1504,
14,
1560,
360,
2610,
16881,
297,
9028,
29,
549,
395,
267,
283,
2502,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
3899,
297,
283,
5949,
659,
267,
283,
5899,
63,
3282,
356,
1504,
14,
505,
360,
31048,
19329,
659,
267,
283,
11486,
63,
344,
356,
1504,
14,
3479,
18,
368,
8,
288,
283,
11486,
14,
11486,
297,
283,
26081,
297,
288,
1415,
29,
549,
12,
16549,
534,
15377,
297,
267,
2318,
267,
283,
1450,
63,
1580,
356,
1504,
14,
3479,
18,
3479,
8,
288,
283,
11486,
14,
1450,
297,
1059,
534,
9440,
297,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
MiltosD/CEF-ELRC
|
lib/python2.7/site-packages/haystack/management/commands/update_index.py
|
3
|
11192
|
import datetime
import os
import warnings
from optparse import make_option
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.management.base import LabelCommand
from django.db import reset_queries
from django.utils.encoding import smart_str
from haystack import connections as haystack_connections
from haystack.constants import DEFAULT_ALIAS
from haystack.query import SearchQuerySet
DEFAULT_BATCH_SIZE = None
DEFAULT_AGE = None
APP = 'app'
MODEL = 'model'
def worker(bits):
# We need to reset the connections, otherwise the different processes
# will try to share the connection, which causes things to blow up.
from django.db import connections
for alias, info in connections.databases.items():
# We need to also tread lightly with SQLite, because blindly wiping
# out connections (via ``... = {}``) destroys in-memory DBs.
if not 'sqlite3' in info['ENGINE']:
try:
del(connections._connections[alias])
except KeyError:
pass
if bits[0] == 'do_update':
func, model, start, end, total, using, start_date, end_date, verbosity = bits
elif bits[0] == 'do_remove':
func, model, pks_seen, start, upper_bound, using, verbosity = bits
else:
return
unified_index = haystack_connections[using].get_unified_index()
index = unified_index.get_index(model)
backend = haystack_connections[using].get_backend()
if func == 'do_update':
qs = build_queryset(index, model, start_date=start_date, end_date=end_date, verbosity=verbosity)
do_update(backend, index, qs, start, end, total, verbosity=verbosity)
elif bits[0] == 'do_remove':
do_remove(backend, index, model, pks_seen, start, upper_bound, verbosity=verbosity)
def build_queryset(index, model, start_date=None, end_date=None, verbosity=1):
extra_lookup_kwargs = {}
updated_field = index.get_updated_field()
if start_date:
if updated_field:
extra_lookup_kwargs['%s__gte' % updated_field] = start_date
else:
if verbosity >= 2:
print "No updated date field found for '%s' - not restricting by age." % model.__name__
if end_date:
if updated_field:
extra_lookup_kwargs['%s__lte' % updated_field] = end_date
else:
if verbosity >= 2:
print "No updated date field found for '%s' - not restricting by age." % model.__name__
index_qs = None
if hasattr(index, 'get_queryset'):
warnings.warn("'SearchIndex.get_queryset' was deprecated in Haystack v2. Please rename the method 'index_queryset'.")
index_qs = index.get_queryset()
else:
index_qs = index.index_queryset()
if not hasattr(index_qs, 'filter'):
raise ImproperlyConfigured("The '%r' class must return a 'QuerySet' in the 'index_queryset' method." % index)
# `.select_related()` seems like a good idea here but can fail on
# nullable `ForeignKey` as well as what seems like other cases.
return index_qs.filter(**extra_lookup_kwargs).order_by(model._meta.pk.name)
def do_update(backend, index, qs, start, end, total, verbosity=1):
# Get a clone of the QuerySet so that the cache doesn't bloat up
# in memory. Useful when reindexing large amounts of data.
small_cache_qs = qs.all()
current_qs = small_cache_qs[start:end]
if verbosity >= 2:
if os.getpid() == os.getppid():
print " indexed %s - %d of %d." % (start+1, end, total)
else:
print " indexed %s - %d of %d (by %s)." % (start+1, end, total, os.getpid())
# FIXME: Get the right backend.
backend.update(index, current_qs)
# Clear out the DB connections queries because it bloats up RAM.
reset_queries()
def do_remove(backend, index, model, pks_seen, start, upper_bound, verbosity=1):
# Fetch a list of results.
# Can't do pk range, because id's are strings (thanks comments
# & UUIDs!).
stuff_in_the_index = SearchQuerySet().models(model)[start:upper_bound]
# Iterate over those results.
for result in stuff_in_the_index:
# Be careful not to hit the DB.
if not smart_str(result.pk) in pks_seen:
# The id is NOT in the small_cache_qs, issue a delete.
if verbosity >= 2:
print " removing %s." % result.pk
backend.remove(".".join([result.app_label, result.model_name, str(result.pk)]))
class Command(LabelCommand):
help = "Freshens the index for the given app(s)."
base_options = (
make_option('-a', '--age', action='store', dest='age',
default=DEFAULT_AGE, type='int',
help='Number of hours back to consider objects new.'
),
make_option('-s', '--start', action='store', dest='start_date',
default=None, type='string',
help='The start date for indexing within. Can be any dateutil-parsable string, recommended to be YYYY-MM-DDTHH:MM:SS.'
),
make_option('-e', '--end', action='store', dest='end_date',
default=None, type='string',
help='The end date for indexing within. Can be any dateutil-parsable string, recommended to be YYYY-MM-DDTHH:MM:SS.'
),
make_option('-b', '--batch-size', action='store', dest='batchsize',
default=None, type='int',
help='Number of items to index at once.'
),
make_option('-r', '--remove', action='store_true', dest='remove',
default=False, help='Remove objects from the index that are no longer present in the database.'
),
make_option("-u", "--using", action="store", type="string", dest="using", default=DEFAULT_ALIAS,
help='If provided, chooses a connection to work with.'
),
make_option('-k', '--workers', action='store', dest='workers',
default=0, type='int',
help='Allows for the use multiple workers to parallelize indexing. Requires multiprocessing.'
),
)
option_list = LabelCommand.option_list + base_options
def handle(self, *items, **options):
self.verbosity = int(options.get('verbosity', 1))
self.batchsize = options.get('batchsize', DEFAULT_BATCH_SIZE)
self.start_date = None
self.end_date = None
self.remove = options.get('remove', False)
self.using = options.get('using')
self.workers = int(options.get('workers', 0))
self.backend = haystack_connections[self.using].get_backend()
age = options.get('age', DEFAULT_AGE)
start_date = options.get('start_date')
end_date = options.get('end_date')
if age is not None:
self.start_date = datetime.datetime.now() - datetime.timedelta(hours=int(age))
if start_date is not None:
from dateutil.parser import parse as dateutil_parse
try:
self.start_date = dateutil_parse(start_date)
except ValueError:
pass
if end_date is not None:
from dateutil.parser import parse as dateutil_parse
try:
self.end_date = dateutil_parse(end_date)
except ValueError:
pass
if not items:
from django.db.models import get_app
# Do all, in an INSTALLED_APPS sorted order.
items = []
for app in settings.INSTALLED_APPS:
try:
app_label = app.split('.')[-1]
loaded_app = get_app(app_label)
items.append(app_label)
except:
# No models, no problem.
pass
return super(Command, self).handle(*items, **options)
def is_app_or_model(self, label):
label_bits = label.split('.')
if len(label_bits) == 1:
return APP
elif len(label_bits) == 2:
return MODEL
else:
raise ImproperlyConfigured("'%s' isn't recognized as an app (<app_label>) or model (<app_label>.<model_name>)." % label)
def get_models(self, label):
from django.db.models import get_app, get_models, get_model
app_or_model = self.is_app_or_model(label)
if app_or_model == APP:
app_mod = get_app(label)
return get_models(app_mod)
else:
app_label, model_name = label.split('.')
return [get_model(app_label, model_name)]
def handle_label(self, label, **options):
from haystack.exceptions import NotHandled
unified_index = haystack_connections[self.using].get_unified_index()
if self.workers > 0:
import multiprocessing
for model in self.get_models(label):
try:
index = unified_index.get_index(model)
except NotHandled:
if self.verbosity >= 2:
print "Skipping '%s' - no index." % model
continue
qs = build_queryset(index, model, start_date=self.start_date, end_date=self.end_date, verbosity=self.verbosity)
total = qs.count()
if self.verbosity >= 1:
print "Indexing %d %s." % (total, smart_str(model._meta.verbose_name_plural))
pks_seen = set([smart_str(pk) for pk in qs.values_list('pk', flat=True)])
batch_size = self.batchsize or self.backend.batch_size
if self.workers > 0:
ghetto_queue = []
for start in range(0, total, batch_size):
end = min(start + batch_size, total)
if self.workers == 0:
do_update(self.backend, index, qs, start, end, total, self.verbosity)
else:
ghetto_queue.append(('do_update', model, start, end, total, self.using, self.start_date, self.end_date, self.verbosity))
if self.workers > 0:
pool = multiprocessing.Pool(self.workers)
pool.map(worker, ghetto_queue)
if self.remove:
if self.start_date or self.end_date or total <= 0:
# They're using a reduced set, which may not incorporate
# all pks. Rebuild the list with everything.
qs = index.index_queryset().values_list('pk', flat=True)
pks_seen = set([smart_str(pk) for pk in qs])
total = len(pks_seen)
if self.workers > 0:
ghetto_queue = []
for start in range(0, total, batch_size):
upper_bound = start + batch_size
if self.workers == 0:
do_remove(self.backend, index, model, pks_seen, start, upper_bound)
else:
ghetto_queue.append(('do_remove', model, pks_seen, start, upper_bound, self.using, self.verbosity))
if self.workers > 0:
pool = multiprocessing.Pool(self.workers)
pool.map(worker, ghetto_queue)
|
bsd-3-clause
|
[
646,
2197,
199,
646,
747,
199,
646,
3598,
199,
504,
8691,
492,
1852,
63,
1422,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
10354,
3110,
199,
504,
1639,
14,
697,
492,
5305,
63,
10590,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
495,
199,
504,
394,
1187,
2340,
492,
6947,
465,
394,
1187,
2340,
63,
7995,
199,
504,
394,
1187,
2340,
14,
5559,
492,
6186,
63,
12644,
199,
504,
394,
1187,
2340,
14,
1131,
492,
8730,
13689,
421,
199,
3472,
63,
20813,
63,
4305,
275,
488,
199,
3472,
63,
2962,
275,
488,
199,
7121,
275,
283,
571,
7,
199,
11429,
275,
283,
1238,
7,
421,
199,
318,
7239,
8,
5609,
304,
272,
327,
2136,
1929,
370,
5305,
314,
6947,
12,
4257,
314,
3365,
10358,
272,
327,
911,
862,
370,
8663,
314,
1950,
12,
1314,
14486,
7645,
370,
28511,
1536,
14,
272,
687,
1639,
14,
697,
492,
6947,
339,
367,
5162,
12,
2256,
315,
6947,
14,
17439,
14,
1744,
837,
267,
327,
2136,
1929,
370,
2597,
307,
739,
10540,
590,
543,
19245,
12,
2952,
330,
24491,
590,
336,
711,
316,
267,
327,
734,
6947,
334,
12897,
1124,
1396,
275,
1052,
16580,
2053,
293,
588,
315,
13,
4844,
6249,
83,
14,
267,
340,
440,
283,
10659,
19,
7,
315,
2256,
459,
15956,
2565,
288,
862,
26,
355,
2150,
8,
7995,
423,
7995,
59,
3620,
566,
288,
871,
4067,
26,
355,
986,
339,
340,
5821,
59,
16,
61,
508,
283,
1117,
63,
873,
356,
267,
2562,
12,
1402,
12,
1343,
12,
1284,
12,
3141,
12,
1808,
12,
1343,
63,
602,
12,
1284,
63,
602,
12,
8661,
275,
5821,
272,
916,
5821,
59,
16,
61,
508,
283,
1117,
63,
2168,
356,
267,
2562,
12,
1402,
12,
3803,
83,
63,
8606,
12,
1343,
12,
7008,
63,
3556,
12,
1808,
12,
8661,
275,
5821,
272,
587,
26,
267,
372,
339,
25344,
63,
1080,
275,
394,
1187,
2340,
63,
7995,
59,
4941,
1055,
362,
63,
32180,
63,
1080,
342,
272,
1478,
275,
25344,
63,
1080,
14,
362,
63,
1080,
8,
1238,
9,
272,
4865,
275,
394,
1187,
2340,
63,
7995,
59,
4941,
1055,
362,
63,
4620,
342,
339,
340,
2562,
508,
283,
1117,
63,
873,
356,
267,
6377,
275,
1900,
63,
7924,
8,
1080,
12,
1402,
12,
1343,
63,
602,
29,
928,
63,
602,
12,
1284,
63,
602,
29,
500,
63,
602,
12,
8661,
29,
9833,
9,
267,
886,
63,
873,
8,
4620,
12,
1478,
12,
6377,
12,
1343,
12,
1284,
12,
3141,
12,
8661,
29,
9833,
9,
272,
916,
5821,
59,
16,
61,
508,
283,
1117,
63,
2168,
356,
267,
886,
63,
2168,
8,
4620,
12,
1478,
12,
1402,
12,
3803,
83,
63,
8606,
12,
1343,
12,
7008,
63,
3556,
12,
8661,
29,
9833,
9,
421,
199,
318,
1900,
63,
7924,
8,
1080,
12,
1402,
12,
1343,
63,
602,
29,
403,
12,
1284,
63,
602,
29,
403,
12,
8661,
29,
17,
304,
272,
2402,
63,
3892,
63,
958,
275,
1052,
272,
4588,
63,
698,
275,
1478,
14,
362,
63,
5334,
63,
698,
342,
339,
340,
1343,
63,
602,
26,
267,
340,
4588,
63,
698,
26,
288,
2402,
63,
3892,
63,
958,
13890,
83,
363,
19586,
7,
450,
4588,
63,
698,
61,
275,
1343,
63,
602,
267,
587,
26,
288,
340,
8661,
2356,
499,
26,
355,
870,
298,
1944,
4588,
1434,
901,
1911,
367,
1543,
83,
7,
446,
440,
18152,
316,
701,
11437,
2122,
450,
1402,
855,
354,
363,
339,
340,
1284,
63,
602,
26,
267,
340,
4588,
63,
698,
26,
288,
2402,
63,
3892,
63,
958,
13890,
83,
363,
20740,
7,
450,
4588,
63,
698,
61,
275,
1284,
63,
602,
267,
587,
26,
288,
340,
8661,
2356,
499,
26,
355,
870,
298,
1944,
4588,
1434,
901,
1911,
367,
1543,
83,
7,
446,
440,
18152,
316,
701,
11437,
2122,
450,
1402,
855,
354,
363,
339,
1478,
63,
6177,
275,
488,
339,
340,
2688,
8,
1080,
12,
283,
362,
63,
7924,
735,
267,
3598,
14,
4050,
15587,
5278,
2681,
14,
362,
63,
7924,
7,
1990,
5906,
315,
869,
1187,
2340,
373,
18,
14,
7754,
11441,
314,
1083,
283,
1080,
63,
7924,
29435,
267,
1478,
63,
6177,
275,
1478,
14,
362,
63,
7924,
342,
272,
587,
26,
267,
1478,
63,
6177,
275,
1478,
14,
1080,
63,
7924,
342,
339,
340,
440,
2688,
8,
1080,
63,
6177,
12,
283,
1541,
735,
267,
746,
11897,
480,
1918,
1543,
82,
7,
1021,
1471,
372,
282,
283,
13689,
7,
315,
314,
283,
1080,
63,
7924,
7,
1083,
2122,
450,
1478,
9,
339,
327,
19853,
2416,
63,
2407,
11995,
12237,
2839,
282,
6954,
16819,
2348,
1325,
883,
2449,
641,
272,
327,
7854,
658,
3190,
64,
465,
5521,
465,
4052,
12237,
2839,
1163,
5560,
14,
272,
372,
1478,
63,
6177,
14,
1541,
3682,
2911,
63,
3892,
63,
958,
680,
1648,
63,
991,
8,
1238,
423,
2024,
14,
2051,
14,
354,
9,
421,
199,
318,
886,
63,
873,
8,
4620,
12,
1478,
12,
6377,
12,
1343,
12,
1284,
12,
3141,
12,
8661,
29,
17,
304,
272,
327,
2372,
282,
7289,
402,
314,
18397,
880,
626,
314,
2581,
3181,
1133,
330,
1088,
1536,
272,
327,
315,
4402,
14,
18491,
1380,
295,
28703,
7031,
32247,
402,
666,
14,
272,
7425,
63,
1637,
63,
6177,
275,
6377,
14,
452,
342,
272,
1453,
63,
6177,
275,
7425,
63,
1637,
63,
6177,
59,
928,
26,
500,
61,
339,
340,
8661,
2356,
499,
26,
267,
340,
747,
14,
17829,
342,
508,
747,
14,
362,
802,
344,
837,
288,
870,
298,
221,
15235,
450,
83,
446,
450,
68,
402,
450,
68,
2122,
450,
334,
928,
11,
17,
12,
1284,
12,
3141,
9,
267,
587,
26,
288,
870,
298,
221,
15235,
450,
83,
446,
450,
68,
402,
450,
68,
334,
991,
450,
83,
17617,
450,
334,
928,
11,
17,
12,
1284,
12,
3141,
12,
747,
14,
17829,
1012,
339,
327,
7600,
26,
2372,
314,
2451,
4865,
14,
272,
4865,
14,
873,
8,
1080,
12,
1453,
63,
6177,
9,
339,
327,
14836,
734,
314,
6249,
6947,
9212,
2952,
652,
330,
1088,
83,
1536,
30207,
14,
272,
5305,
63,
10590,
342,
421,
199,
318,
886,
63,
2168,
8,
4620,
12
] |
[
2197,
199,
646,
747,
199,
646,
3598,
199,
504,
8691,
492,
1852,
63,
1422,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
10354,
3110,
199,
504,
1639,
14,
697,
492,
5305,
63,
10590,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
495,
199,
504,
394,
1187,
2340,
492,
6947,
465,
394,
1187,
2340,
63,
7995,
199,
504,
394,
1187,
2340,
14,
5559,
492,
6186,
63,
12644,
199,
504,
394,
1187,
2340,
14,
1131,
492,
8730,
13689,
421,
199,
3472,
63,
20813,
63,
4305,
275,
488,
199,
3472,
63,
2962,
275,
488,
199,
7121,
275,
283,
571,
7,
199,
11429,
275,
283,
1238,
7,
421,
199,
318,
7239,
8,
5609,
304,
272,
327,
2136,
1929,
370,
5305,
314,
6947,
12,
4257,
314,
3365,
10358,
272,
327,
911,
862,
370,
8663,
314,
1950,
12,
1314,
14486,
7645,
370,
28511,
1536,
14,
272,
687,
1639,
14,
697,
492,
6947,
339,
367,
5162,
12,
2256,
315,
6947,
14,
17439,
14,
1744,
837,
267,
327,
2136,
1929,
370,
2597,
307,
739,
10540,
590,
543,
19245,
12,
2952,
330,
24491,
590,
336,
711,
316,
267,
327,
734,
6947,
334,
12897,
1124,
1396,
275,
1052,
16580,
2053,
293,
588,
315,
13,
4844,
6249,
83,
14,
267,
340,
440,
283,
10659,
19,
7,
315,
2256,
459,
15956,
2565,
288,
862,
26,
355,
2150,
8,
7995,
423,
7995,
59,
3620,
566,
288,
871,
4067,
26,
355,
986,
339,
340,
5821,
59,
16,
61,
508,
283,
1117,
63,
873,
356,
267,
2562,
12,
1402,
12,
1343,
12,
1284,
12,
3141,
12,
1808,
12,
1343,
63,
602,
12,
1284,
63,
602,
12,
8661,
275,
5821,
272,
916,
5821,
59,
16,
61,
508,
283,
1117,
63,
2168,
356,
267,
2562,
12,
1402,
12,
3803,
83,
63,
8606,
12,
1343,
12,
7008,
63,
3556,
12,
1808,
12,
8661,
275,
5821,
272,
587,
26,
267,
372,
339,
25344,
63,
1080,
275,
394,
1187,
2340,
63,
7995,
59,
4941,
1055,
362,
63,
32180,
63,
1080,
342,
272,
1478,
275,
25344,
63,
1080,
14,
362,
63,
1080,
8,
1238,
9,
272,
4865,
275,
394,
1187,
2340,
63,
7995,
59,
4941,
1055,
362,
63,
4620,
342,
339,
340,
2562,
508,
283,
1117,
63,
873,
356,
267,
6377,
275,
1900,
63,
7924,
8,
1080,
12,
1402,
12,
1343,
63,
602,
29,
928,
63,
602,
12,
1284,
63,
602,
29,
500,
63,
602,
12,
8661,
29,
9833,
9,
267,
886,
63,
873,
8,
4620,
12,
1478,
12,
6377,
12,
1343,
12,
1284,
12,
3141,
12,
8661,
29,
9833,
9,
272,
916,
5821,
59,
16,
61,
508,
283,
1117,
63,
2168,
356,
267,
886,
63,
2168,
8,
4620,
12,
1478,
12,
1402,
12,
3803,
83,
63,
8606,
12,
1343,
12,
7008,
63,
3556,
12,
8661,
29,
9833,
9,
421,
199,
318,
1900,
63,
7924,
8,
1080,
12,
1402,
12,
1343,
63,
602,
29,
403,
12,
1284,
63,
602,
29,
403,
12,
8661,
29,
17,
304,
272,
2402,
63,
3892,
63,
958,
275,
1052,
272,
4588,
63,
698,
275,
1478,
14,
362,
63,
5334,
63,
698,
342,
339,
340,
1343,
63,
602,
26,
267,
340,
4588,
63,
698,
26,
288,
2402,
63,
3892,
63,
958,
13890,
83,
363,
19586,
7,
450,
4588,
63,
698,
61,
275,
1343,
63,
602,
267,
587,
26,
288,
340,
8661,
2356,
499,
26,
355,
870,
298,
1944,
4588,
1434,
901,
1911,
367,
1543,
83,
7,
446,
440,
18152,
316,
701,
11437,
2122,
450,
1402,
855,
354,
363,
339,
340,
1284,
63,
602,
26,
267,
340,
4588,
63,
698,
26,
288,
2402,
63,
3892,
63,
958,
13890,
83,
363,
20740,
7,
450,
4588,
63,
698,
61,
275,
1284,
63,
602,
267,
587,
26,
288,
340,
8661,
2356,
499,
26,
355,
870,
298,
1944,
4588,
1434,
901,
1911,
367,
1543,
83,
7,
446,
440,
18152,
316,
701,
11437,
2122,
450,
1402,
855,
354,
363,
339,
1478,
63,
6177,
275,
488,
339,
340,
2688,
8,
1080,
12,
283,
362,
63,
7924,
735,
267,
3598,
14,
4050,
15587,
5278,
2681,
14,
362,
63,
7924,
7,
1990,
5906,
315,
869,
1187,
2340,
373,
18,
14,
7754,
11441,
314,
1083,
283,
1080,
63,
7924,
29435,
267,
1478,
63,
6177,
275,
1478,
14,
362,
63,
7924,
342,
272,
587,
26,
267,
1478,
63,
6177,
275,
1478,
14,
1080,
63,
7924,
342,
339,
340,
440,
2688,
8,
1080,
63,
6177,
12,
283,
1541,
735,
267,
746,
11897,
480,
1918,
1543,
82,
7,
1021,
1471,
372,
282,
283,
13689,
7,
315,
314,
283,
1080,
63,
7924,
7,
1083,
2122,
450,
1478,
9,
339,
327,
19853,
2416,
63,
2407,
11995,
12237,
2839,
282,
6954,
16819,
2348,
1325,
883,
2449,
641,
272,
327,
7854,
658,
3190,
64,
465,
5521,
465,
4052,
12237,
2839,
1163,
5560,
14,
272,
372,
1478,
63,
6177,
14,
1541,
3682,
2911,
63,
3892,
63,
958,
680,
1648,
63,
991,
8,
1238,
423,
2024,
14,
2051,
14,
354,
9,
421,
199,
318,
886,
63,
873,
8,
4620,
12,
1478,
12,
6377,
12,
1343,
12,
1284,
12,
3141,
12,
8661,
29,
17,
304,
272,
327,
2372,
282,
7289,
402,
314,
18397,
880,
626,
314,
2581,
3181,
1133,
330,
1088,
1536,
272,
327,
315,
4402,
14,
18491,
1380,
295,
28703,
7031,
32247,
402,
666,
14,
272,
7425,
63,
1637,
63,
6177,
275,
6377,
14,
452,
342,
272,
1453,
63,
6177,
275,
7425,
63,
1637,
63,
6177,
59,
928,
26,
500,
61,
339,
340,
8661,
2356,
499,
26,
267,
340,
747,
14,
17829,
342,
508,
747,
14,
362,
802,
344,
837,
288,
870,
298,
221,
15235,
450,
83,
446,
450,
68,
402,
450,
68,
2122,
450,
334,
928,
11,
17,
12,
1284,
12,
3141,
9,
267,
587,
26,
288,
870,
298,
221,
15235,
450,
83,
446,
450,
68,
402,
450,
68,
334,
991,
450,
83,
17617,
450,
334,
928,
11,
17,
12,
1284,
12,
3141,
12,
747,
14,
17829,
1012,
339,
327,
7600,
26,
2372,
314,
2451,
4865,
14,
272,
4865,
14,
873,
8,
1080,
12,
1453,
63,
6177,
9,
339,
327,
14836,
734,
314,
6249,
6947,
9212,
2952,
652,
330,
1088,
83,
1536,
30207,
14,
272,
5305,
63,
10590,
342,
421,
199,
318,
886,
63,
2168,
8,
4620,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
qbuat/rootpy
|
rootpy/tree/tree.py
|
1
|
33528
|
# Copyright 2012 the rootpy developers
# distributed under the terms of the GNU General Public License
from __future__ import absolute_import
import sys
import re
import fnmatch
import uuid
import ROOT
from .. import log; log = log[__name__]
from .. import asrootpy, QROOT
from ..extern.ordereddict import OrderedDict
from ..context import set_directory, thread_specific_tmprootdir, do_nothing
from ..base import NamedObject
from ..decorators import snake_case_methods, method_file_check, method_file_cd
from ..plotting.base import Plottable
from ..plotting import Hist, Canvas
from ..memory.keepalive import keepalive
from .cut import Cut
from .treebuffer import TreeBuffer
from .treetypes import Scalar, Array, BaseChar
from .model import TreeModel
__all__ = [
'Tree',
'Ntuple',
]
class UserData(object):
pass
class BaseTree(NamedObject):
DRAW_PATTERN = re.compile(
'^(?P<branches>.+?)'
'(?P<redirect>\>\>[\+]?'
'(?P<name>[^\(]+)'
'(?P<binning>.+)?)?$')
def _post_init(self):
"""
The standard rootpy _post_init method that is used to initialize both
new Trees and Trees retrieved from a File.
"""
if not hasattr(self, '_buffer'):
# only set _buffer if model was not specified in the __init__
self._buffer = TreeBuffer()
self.read_branches_on_demand = False
self._branch_cache = {}
self._current_entry = 0
self._always_read = []
self.userdata = UserData()
self._inited = True
def always_read(self, branches):
"""
Always read these branches, even when in caching mode. Maybe you have
caching enabled and there are branches you want to be updated for each
entry even though you never access them directly. This is useful if you
are iterating over an input tree and writing to an output tree sharing
the same TreeBuffer and you want a direct copy of certain branches. If
you have caching enabled but these branches are not specified here and
never accessed then they will never be read from disk, so the values of
branches in memory will remain unchanged.
Parameters
----------
branches : list, tuple
these branches will always be read from disk for every GetEntry
"""
if type(branches) not in (list, tuple):
raise TypeError("branches must be a list or tuple")
self._always_read = branches
@classmethod
def branch_type(cls, branch):
"""
Return the string representation for the type of a branch
"""
typename = branch.GetClassName()
if not typename:
leaf = branch.GetListOfLeaves()[0]
typename = leaf.GetTypeName()
# check if leaf has multiple elements
length = leaf.GetLen()
if length > 1:
typename = '{0}[{1:d}]'.format(typename, length)
return typename
@classmethod
def branch_is_supported(cls, branch):
"""
Currently the branch must only have one leaf but the leaf may have one
or multiple elements
"""
return branch.GetNleaves() == 1
def create_buffer(self, ignore_unsupported=False):
"""
Create this tree's TreeBuffer
"""
bufferdict = OrderedDict()
for branch in self.iterbranches():
# only include activated branches
if not self.GetBranchStatus(branch.GetName()):
continue
if not BaseTree.branch_is_supported(branch):
log.warning(
"ignore unsupported branch `{0}`".format(branch.GetName()))
continue
bufferdict[branch.GetName()] = Tree.branch_type(branch)
self.set_buffer(TreeBuffer(
bufferdict,
ignore_unsupported=ignore_unsupported))
def create_branches(self, branches):
"""
Create branches from a TreeBuffer or dict mapping names to type names
Parameters
----------
branches : TreeBuffer or dict
"""
if not isinstance(branches, TreeBuffer):
branches = TreeBuffer(branches)
self.set_buffer(branches, create_branches=True)
def update_buffer(self, treebuffer, transfer_objects=False):
"""
Merge items from a TreeBuffer into this Tree's TreeBuffer
Parameters
----------
buffer : rootpy.tree.buffer.TreeBuffer
The TreeBuffer to merge into this Tree's buffer
transfer_objects : bool, optional (default=False)
If True then all objects and collections on the input buffer will
be transferred to this Tree's buffer.
"""
self._buffer.update(treebuffer)
if transfer_objects:
self._buffer.set_objects(treebuffer)
def set_buffer(self, treebuffer,
branches=None,
ignore_branches=None,
create_branches=False,
visible=True,
ignore_missing=False,
ignore_duplicates=False,
transfer_objects=False):
"""
Set the Tree buffer
Parameters
----------
treebuffer : rootpy.tree.buffer.TreeBuffer
a TreeBuffer
branches : list, optional (default=None)
only include these branches from the TreeBuffer
ignore_branches : list, optional (default=None)
ignore these branches from the TreeBuffer
create_branches : bool, optional (default=False)
If True then the branches in the TreeBuffer should be created.
Use this option if initializing the Tree. A ValueError is raised
if an attempt is made to create a branch with the same name as one
that already exists in the Tree. If False the addresses of existing
branches will be set to point at the addresses in this buffer.
visible : bool, optional (default=True)
If True then the branches will be added to the buffer and will be
accessible as attributes of the Tree.
ignore_missing : bool, optional (default=False)
If True then any branches in this buffer that do not exist in the
Tree will be ignored, otherwise a ValueError will be raised. This
option is only valid when ``create_branches`` is False.
ignore_duplicates : bool, optional (default=False)
If False then raise a ValueError if the tree already has a branch
with the same name as an entry in the buffer. If True then skip
branches that already exist. This option is only valid when
``create_branches`` is True.
transfer_objects : bool, optional (default=False)
If True, all tree objects and collections will be transferred from
the buffer into this Tree's buffer.
"""
# determine branches to keep while preserving branch order
if branches is None:
branches = treebuffer.keys()
if ignore_branches is not None:
branches = [b for b in branches if b not in ignore_branches]
if create_branches:
for name in branches:
value = treebuffer[name]
if self.has_branch(name):
if ignore_duplicates:
log.warning(
"Skipping entry in buffer with the same name "
"as an existing branch: `{0}`".format(name))
continue
raise ValueError(
"Attempting to create two branches "
"with the same name: `{0}`".format(name))
if isinstance(value, Scalar):
self.Branch(name, value,
'{0}/{1}'.format(
name, value.type))
elif isinstance(value, Array):
self.Branch(name, value,
'{0}[{2:d}]/{1}'.format(
name, value.type, len(value)))
else:
self.Branch(name, value)
else:
for name in branches:
value = treebuffer[name]
if self.has_branch(name):
self.SetBranchAddress(name, value)
elif not ignore_missing:
raise ValueError(
"Attempting to set address for "
"branch `{0}` which does not exist".format(name))
else:
log.warning(
"Skipping entry in buffer for which no "
"corresponding branch in the "
"tree exists: `{0}`".format(name))
if visible:
newbuffer = TreeBuffer()
for branch in branches:
if branch in treebuffer:
newbuffer[branch] = treebuffer[branch]
newbuffer.set_objects(treebuffer)
self.update_buffer(newbuffer, transfer_objects=transfer_objects)
def activate(self, branches, exclusive=False):
"""
Activate branches
Parameters
----------
branches : str or list
branch or list of branches to activate
exclusive : bool, optional (default=False)
if True deactivate the remaining branches
"""
if exclusive:
self.SetBranchStatus('*', 0)
if isinstance(branches, basestring):
branches = [branches]
for branch in branches:
if '*' in branch:
matched_branches = self.glob(branch)
for b in matched_branches:
self.SetBranchStatus(b, 1)
elif self.has_branch(branch):
self.SetBranchStatus(branch, 1)
def deactivate(self, branches, exclusive=False):
"""
Deactivate branches
Parameters
----------
branches : str or list
branch or list of branches to deactivate
exclusive : bool, optional (default=False)
if True activate the remaining branches
"""
if exclusive:
self.SetBranchStatus('*', 1)
if isinstance(branches, basestring):
branches = [branches]
for branch in branches:
if '*' in branch:
matched_branches = self.glob(branch)
for b in matched_branches:
self.SetBranchStatus(b, 0)
elif self.has_branch(branch):
self.SetBranchStatus(branch, 0)
@property
def branches(self):
"""
List of the branches
"""
return [branch for branch in self.GetListOfBranches()]
def iterbranches(self):
"""
Iterator over the branches
"""
for branch in self.GetListOfBranches():
yield branch
@property
def branchnames(self):
"""
List of branch names
"""
return [branch.GetName() for branch in self.GetListOfBranches()]
def iterbranchnames(self):
"""
Iterator over the branch names
"""
for branch in self.iterbranches():
yield branch.GetName()
def glob(self, patterns, exclude=None):
"""
Return a list of branch names that match ``pattern``.
Exclude all matched branch names which also match a pattern in
``exclude``. ``exclude`` may be a string or list of strings.
Parameters
----------
patterns: str or list
branches are matched against this pattern or list of patterns where
globbing is performed with '*'.
exclude : str or list, optional (default=None)
branches matching this pattern or list of patterns are excluded
even if they match a pattern in ``patterns``.
Returns
-------
matches : list
List of matching branch names
"""
if isinstance(patterns, basestring):
patterns = [patterns]
if isinstance(exclude, basestring):
exclude = [exclude]
matches = []
for pattern in patterns:
matches += fnmatch.filter(self.iterbranchnames(), pattern)
if exclude is not None:
for exclude_pattern in exclude:
matches = [match for match in matches
if not fnmatch.fnmatch(match, exclude_pattern)]
return matches
def __getitem__(self, item):
"""
Get an entry in the tree or a branch
Parameters
----------
item : str or int
if item is a str then return the value of the branch with that name
if item is an int then call GetEntry
"""
if isinstance(item, basestring):
return self._buffer[item]
self.GetEntry(item)
return self
def GetEntry(self, entry):
"""
Get an entry. Tree collections are reset
(see ``rootpy.tree.treeobject``)
Parameters
----------
entry : int
entry index
Returns
-------
ROOT.TTree.GetEntry : int
The number of bytes read
"""
if not (0 <= entry < self.GetEntries()):
raise IndexError("entry index out of range: {0:d}".format(entry))
self._buffer.reset_collections()
return super(BaseTree, self).GetEntry(entry)
def __iter__(self):
"""
Iterator over the entries in the Tree.
"""
if not self._buffer:
self.create_buffer()
if self.read_branches_on_demand:
self._buffer.set_tree(self)
# drop all branches from the cache
self.DropBranchFromCache('*')
for attr in self._always_read:
try:
branch = self._branch_cache[attr]
except KeyError: # one-time hit
branch = self.GetBranch(attr)
if not branch:
raise AttributeError(
"branch `{0}` specified in "
"`always_read` does not exist".format(attr))
self._branch_cache[attr] = branch
# add branches that we should always read to cache
self.AddBranchToCache(branch)
for i in xrange(self.GetEntries()):
# Only increment current entry.
# getattr on a branch will then GetEntry on only that branch
# see ``TreeBuffer.get_with_read_if_cached``.
self._current_entry = i
self.LoadTree(i)
for attr in self._always_read:
# Always read branched in ``self._always_read`` since
# these branches may never be getattr'd but the TreeBuffer
# should always be updated to reflect their current values.
# This is useful if you are iterating over an input tree
# and writing to an output tree that shares the same
# TreeBuffer but you don't getattr on all branches of the
# input tree in the logic that determines which entries
# to keep.
self._branch_cache[attr].GetEntry(i)
self._buffer._entry.set(i)
yield self._buffer
self._buffer.next_entry()
self._buffer.reset_collections()
else:
for i in xrange(self.GetEntries()):
# Read all activated branches (can be slow!).
super(BaseTree, self).GetEntry(i)
self._buffer._entry.set(i)
yield self._buffer
self._buffer.reset_collections()
def __setattr__(self, attr, value):
if '_inited' not in self.__dict__ or attr in self.__dict__:
return super(BaseTree, self).__setattr__(attr, value)
try:
return self._buffer.__setattr__(attr, value)
except AttributeError:
raise AttributeError(
"`{0}` instance has no attribute `{1}`".format(
self.__class__.__name__, attr))
def __getattr__(self, attr):
if '_inited' not in self.__dict__:
raise AttributeError(
"`{0}` instance has no attribute `{1}`".format(
self.__class__.__name__, attr))
try:
return getattr(self._buffer, attr)
except AttributeError:
raise AttributeError(
"`{0}` instance has no attribute `{1}`".format(
self.__class__.__name__, attr))
def __setitem__(self, item, value):
self._buffer[item] = value
def __len__(self):
"""
Same as GetEntries
"""
return self.GetEntries()
def __contains__(self, branch):
"""
Same as has_branch
"""
return self.has_branch(branch)
def has_branch(self, branch):
"""
Determine if this Tree contains a branch with the name ``branch``
Parameters
----------
branch : str
branch name
Returns
-------
has_branch : bool
True if this Tree contains a branch with the name ``branch`` or
False otherwise.
"""
return not not self.GetBranch(branch)
def csv(self, sep=',', branches=None,
include_labels=True, limit=None,
stream=None):
"""
Print csv representation of tree only including branches
of basic types (no objects, vectors, etc..)
Parameters
----------
sep : str, optional (default=',')
The delimiter used to separate columns
branches : list, optional (default=None)
Only include these branches in the CSV output. If None, then all
basic types will be included.
include_labels : bool, optional (default=True)
Include a first row of branch names labelling each column.
limit : int, optional (default=None)
Only include up to a maximum of ``limit`` rows in the CSV.
stream : file, (default=None)
Stream to write the CSV output on. By default the CSV will be
written to ``sys.stdout``.
"""
if stream is None:
stream = sys.stdout
if not self._buffer:
self.create_buffer(ignore_unsupported=True)
if branches is None:
branchdict = OrderedDict([
(name, self._buffer[name])
for name in self.iterbranchnames()
if isinstance(self._buffer[name], (Scalar, Array))])
else:
branchdict = OrderedDict()
for name in branches:
if not isinstance(self._buffer[name], (Scalar, Array)):
raise TypeError(
"selected branch `{0}` "
"is not a scalar or array type".format(name))
branchdict[name] = self._buffer[name]
if not branchdict:
raise RuntimeError(
"no branches selected or no "
"branches of scalar or array types exist")
if include_labels:
# expand array types to f[0],f[1],f[2],...
print >> stream, sep.join(
name if isinstance(value, (Scalar, BaseChar))
else sep.join('{0}[{1:d}]'.format(name, idx)
for idx in xrange(len(value)))
for name, value in branchdict.items())
# even though 'entry' is not used, enumerate or simply iterating over
# self is required to update the buffer with the new branch values at
# each tree entry.
for i, entry in enumerate(self):
print >> stream, sep.join(
str(v.value) if isinstance(v, (Scalar, BaseChar))
else sep.join(map(str, v))
for v in branchdict.values())
if limit is not None and i + 1 == limit:
break
def Scale(self, value):
"""
Scale the weight of the Tree by ``value``
Parameters
----------
value : int, float
Scale the Tree weight by this value
"""
self.SetWeight(self.GetWeight() * value)
def GetEntries(self, cut=None, weighted_cut=None, weighted=False):
"""
Get the number of (weighted) entries in the Tree
Parameters
----------
cut : str or rootpy.tree.cut.Cut, optional (default=None)
Only entries passing this cut will be included in the count
weighted_cut : str or rootpy.tree.cut.Cut, optional (default=None)
Apply a weighted selection and determine the weighted number of
entries.
weighted : bool, optional (default=False)
Multiply the number of (weighted) entries by the Tree weight.
"""
if weighted_cut:
hist = Hist(1, -1, 2)
branch = self.GetListOfBranches()[0].GetName()
weight = self.GetWeight()
self.SetWeight(1)
self.Draw('{0}=={1}>>{2}'.format(branch, branch, hist.GetName()),
weighted_cut * cut)
self.SetWeight(weight)
entries = hist.Integral()
elif cut:
entries = super(BaseTree, self).GetEntries(str(cut))
else:
entries = super(BaseTree, self).GetEntries()
if weighted:
entries *= self.GetWeight()
return entries
def GetMaximum(self, expression, cut=None):
"""
TODO: we need a better way of determining the maximum value of an
expression.
"""
if cut:
self.Draw(expression, cut, 'goff')
else:
self.Draw(expression, '', 'goff')
vals = self.GetV1()
n = self.GetSelectedRows()
vals = [vals[i] for i in xrange(min(n, 10000))]
return max(vals)
def GetMinimum(self, expression, cut=None):
"""
TODO: we need a better way of determining the minimum value of an
expression.
"""
if cut:
self.Draw(expression, cut, "goff")
else:
self.Draw(expression, "", "goff")
vals = self.GetV1()
n = self.GetSelectedRows()
vals = [vals[i] for i in xrange(min(n, 10000))]
return min(vals)
def CopyTree(self, selection, *args, **kwargs):
"""
Copy the tree while supporting a rootpy.tree.cut.Cut selection in
addition to a simple string.
"""
return super(BaseTree, self).CopyTree(str(selection), *args, **kwargs)
def reset_branch_values(self):
"""
Reset all values in the buffer to their default values
"""
self._buffer.reset()
@method_file_cd
def Write(self, *args, **kwargs):
super(BaseTree, self).Write(*args, **kwargs)
def Draw(self,
expression,
selection="",
options="",
hist=None,
create_hist=False,
**kwargs):
"""
Draw a TTree with a selection as usual, but return the created
histogram.
Parameters
----------
expression : str
The expression to draw. Multidimensional expressions are separated
by ":". rootpy reverses the expressions along each dimension so the
order matches the order of the elements identifying a location in
the resulting histogram. By default ROOT takes the expression "Y:X"
to mean Y versus X but we argue that this is counterintuitive and
that the order should be "X:Y" so that the expression along the
first dimension identifies the location along the first axis, etc.
selection : str or rootpy.tree.Cut, optional (default="")
The cut expression. Only entries satisfying this selection are
included in the filled histogram.
options : str, optional (default="")
Draw options passed to ROOT.TTree.Draw
hist : ROOT.TH1, optional (default=None)
The histogram to be filled. If not specified, rootpy will attempt
to find what ROOT created and return that.
create_hist : bool (default=False)
If True and `hist`` is not specified and a histogram name is not
specified in the draw expression, then override ROOT's
default behaviour and fill a new histogram. ROOT will otherwise add
points to a TGraph or TPolyMarker3D if not drawing in more than
two dimensions.
kwargs : dict, optional
Remaining keword arguments are used to set the style attributes of
the histogram.
Returns
-------
If ``hist`` is specified, None is returned. If ``hist`` is left
unspecified, an attempt is made to retrieve the generated histogram
which is then returned.
"""
# Check that we have a valid draw expression and pick out components
exprmatch = re.match(BaseTree.DRAW_PATTERN, expression)
if not exprmatch:
raise ValueError(
"not a valid draw expression: `{0}`".format(expression))
# Reverse variable order to match order in hist constructor
exprdict = exprmatch.groupdict()
fields = exprdict['branches'].split(':')
num_dimensions = len(fields)
expression = ':'.join(fields[:3][::-1] + fields[3:])
if exprdict['redirect'] is not None:
expression += exprdict['redirect']
if not isinstance(selection, Cut):
# Let Cut handle any extra processing (i.e. ternary operators)
selection = Cut(selection)
graphics = 'goff' not in options
if hist is not None:
if not isinstance(hist, ROOT.TH1):
raise TypeError("Cannot draw into a `{0}`".format(type(hist)))
# Check that the dimensionality of the expression and object match
if num_dimensions != hist.GetDimension():
raise TypeError(
"The dimensionality of the expression `{0}` ({1:d}) "
"does not match the dimensionality of a `{2}`".format(
expression, num_dimensions, hist.__class__.__name__))
# Handle graphics ourselves
if graphics:
if options:
options += ' '
options += 'goff'
if exprdict['name'] is None:
# Draw into histogram supplied by user
expression = '{0}>>+{1}'.format(expression, hist.GetName())
else:
if exprdict['name'] != hist.GetName():
# If the user specified a name to draw into then check that
# this is consistent with the specified object.
raise ValueError(
"The name specified in the draw "
"expression `{0}` does not match the "
"name of the specified object `{1}`".format(
exprdict['name'],
hist.GetName()))
# Check that binning is not specified
if exprdict['binning'] is not None:
raise ValueError(
"When specifying the object to draw into, do not "
"specify a binning in the draw expression")
else:
if create_hist and exprdict['name'] is None:
if num_dimensions > 4:
raise ValueError(
"Cannot create a histogram for expressions with "
"more than 4 dimensions")
newname = uuid.uuid4().hex
expression += '>>{0}'.format(newname)
exprdict['name'] = newname
pad = ROOT.gPad.func()
own_pad = False
if graphics and not pad:
# Create a new canvas if one doesn't exist yet
own_pad = True
pad = Canvas()
# Note: TTree.Draw() pollutes gDirectory, make a temporary one
with thread_specific_tmprootdir():
if hist is not None:
# If a custom histogram is specified (i.e, it's not being
# created root side), then temporarily put it into the
# temporary thread-specific directory.
context = set_directory(hist)
else:
context = do_nothing()
with context:
super(BaseTree, self).Draw(expression, selection, options)
if hist is None:
# Retrieve histogram made by TTree.Draw
if num_dimensions == 1 or exprdict['name'] is not None:
# a TH1
hist = asrootpy(self.GetHistogram(), warn=False)
elif num_dimensions == 2:
# a TGraph
hist = asrootpy(pad.GetPrimitive('Graph'), warn=False)
else:
# ROOT: For a three and four dimensional Draw the TPolyMarker3D
# is unnamed, and cannot be retrieved. Why, ROOT?
log.warning(
"Cannot retrieve the TPolyMarker3D for "
"3D and 4D expressions")
if graphics and own_pad:
# Since we cannot access the TPolyMarker3D we use self to
# keep the canvas alive
keepalive(self, pad)
if hist: # is not None
if isinstance(hist, Plottable):
hist.decorate(**kwargs)
# ROOT, don't try to delete this object! (See issue #277)
hist.SetBit(ROOT.kCanDelete, False)
if graphics:
if own_pad:
# The usual bug is that the histogram is garbage
# collected and we want the canvas to keep the
# histogram alive, but here the canvas has been
# created locally and we are returning the histogram,
# so we want the histogram to keep the canvas alive.
keepalive(hist, pad)
# Redraw the histogram since we may have specified style
# attributes in **kwargs
hist.Draw()
if graphics:
pad.Modified()
pad.Update()
return hist
def to_array(self, *args, **kwargs):
"""
Convert this tree into a NumPy structured array
"""
from root_numpy import tree2array
return tree2array(self, *args, **kwargs)
@snake_case_methods
class Tree(BaseTree, QROOT.TTree):
"""
Inherits from TTree so all regular TTree methods are available
but certain methods (i.e. Draw) have been overridden
to improve usage in Python.
Parameters
----------
name : str, optional (default=None)
The Tree name (a UUID if None)
title : str, optional (default=None)
The Tree title (empty string if None)
model : TreeModel, optional (default=None)
If specified then this TreeModel will be used to create the branches
"""
_ROOT = QROOT.TTree
@method_file_check
def __init__(self, name=None, title=None, model=None):
super(Tree, self).__init__(name=name, title=title)
self._buffer = TreeBuffer()
if model is not None:
if not issubclass(model, TreeModel):
raise TypeError("the model must subclass TreeModel")
self.set_buffer(model(), create_branches=True)
self._post_init()
def Fill(self, reset=False):
"""
Fill the Tree with the current values in the buffer
Parameters
----------
reset : bool, optional (default=False)
Reset the values in the buffer to their default values after
filling.
"""
super(Tree, self).Fill()
# reset all branches
if reset:
self._buffer.reset()
@snake_case_methods
class Ntuple(BaseTree, QROOT.TNtuple):
"""
Inherits from TNtuple so all regular TNtuple/TTree methods are available
but certain methods (i.e. Draw) have been overridden
to improve usage in Python.
Parameters
----------
varlist : list of str
A list of the field names
name : str, optional (default=None)
The Ntuple name (a UUID if None)
title : str, optional (default=None)
The Ntuple title (empty string if None)
bufsize : int, optional (default=32000)
Basket buffer size
"""
_ROOT = QROOT.TNtuple
@method_file_check
def __init__(self, varlist, name=None, title=None, bufsize=32000):
super(Ntuple, self).__init__(':'.join(varlist), bufsize,
name=name,
title=title)
self._post_init()
|
gpl-3.0
|
[
3,
1898,
6029,
314,
1738,
647,
19782,
199,
3,
1854,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
984,
199,
646,
295,
199,
646,
15951,
199,
646,
5377,
199,
199,
646,
16547,
199,
199,
504,
2508,
492,
943,
27,
943,
275,
943,
28894,
354,
22705,
199,
504,
2508,
492,
465,
1231,
647,
12,
1413,
5441,
199,
504,
2508,
18587,
14,
8235,
807,
492,
8773,
199,
504,
2508,
1100,
492,
663,
63,
3619,
12,
2462,
63,
6100,
63,
2791,
1231,
694,
12,
886,
63,
16323,
199,
504,
2508,
1095,
492,
16198,
1692,
199,
504,
2508,
11582,
492,
6895,
1728,
63,
2546,
63,
2474,
12,
1083,
63,
493,
63,
1074,
12,
1083,
63,
493,
63,
2866,
199,
504,
2508,
2798,
1337,
14,
1095,
492,
14794,
1224,
199,
504,
2508,
2798,
1337,
492,
869,
631,
12,
29349,
199,
504,
2508,
4844,
14,
28227,
492,
4215,
9631,
199,
504,
1275,
5919,
492,
445,
337,
199,
504,
1275,
2350,
2738,
492,
12178,
3299,
199,
504,
1275,
2350,
1313,
492,
24289,
12,
8725,
12,
3523,
1610,
199,
504,
1275,
1238,
492,
12178,
1685,
199,
199,
363,
452,
363,
275,
359,
272,
283,
3987,
297,
272,
283,
46,
2960,
297,
199,
61,
421,
199,
533,
2876,
1451,
8,
785,
304,
272,
986,
421,
199,
533,
3523,
3987,
8,
7989,
1692,
304,
339,
5239,
63,
10764,
275,
295,
14,
2014,
8,
267,
14452,
2229,
48,
28,
16896,
29587,
3171,
267,
17644,
48,
28,
4876,
3072,
3072,
24693,
11,
11843,
7,
267,
17644,
48,
28,
354,
13489,
24805,
29716,
267,
17644,
48,
28,
1393,
1835,
31411,
5547,
5547,
9988,
339,
347,
485,
1932,
63,
826,
8,
277,
304,
267,
408,
267,
710,
4465,
1738,
647,
485,
1932,
63,
826,
1083,
626,
365,
1202,
370,
8265,
3865,
267,
892,
377,
5710,
436,
377,
5710,
12396,
687,
282,
3814,
14,
267,
408,
267,
340,
440,
2688,
8,
277,
12,
2513,
2738,
735,
288,
327,
1454,
663,
485,
2738,
340,
1402,
1990,
440,
2013,
315,
314,
636,
826,
363,
288,
291,
423,
2738,
275,
12178,
3299,
342,
267,
291,
14,
739,
63,
16896,
63,
265,
63,
24152,
275,
756,
267,
291,
423,
4694,
63,
1637,
275,
1052,
267,
291,
423,
1818,
63,
2373,
275,
378,
267,
291,
423,
9223,
63,
739,
275,
942,
267,
291,
14,
751,
576,
275,
2876,
1451,
342,
267,
291,
423,
2730,
471,
275,
715,
339,
347,
3544,
63,
739,
8,
277,
12,
17347,
304,
267,
408,
267,
16763,
1586,
3520,
17347,
12,
2755,
1380,
315,
13627,
818,
14,
23038,
1265,
1172,
267,
13627,
5223,
436,
2337,
787,
17347,
1265,
2934,
370,
506,
4588,
367,
1924,
267,
2397,
2755,
10617,
1265,
7078,
2879,
3062,
5370,
14,
961,
365,
2997,
340,
1265,
267,
787,
25012,
1806,
376,
1324,
3123,
436,
3575,
370,
376,
1072,
3123,
26994,
267,
314,
2011,
12178,
3299,
436,
1265,
2934,
282,
4125,
1331,
402,
9842,
17347,
14,
982,
267,
1265,
1172,
13627,
5223,
1325,
3520,
17347,
787,
440,
2013,
2348,
436,
267,
7078,
13810,
2066,
2985,
911,
7078,
506,
1586,
687,
4543,
12,
880,
314,
1338,
402,
267,
17347,
315,
4402,
911,
5706,
14874,
14,
398,
3897,
267,
4143,
267,
17347,
520,
769,
12,
2008,
288,
3520,
17347,
911,
3544,
506,
1586,
687,
4543,
367,
4036,
2372,
3900,
267,
408,
267,
340,
730,
8,
16896,
9,
440,
315,
334,
513,
12,
2008,
304,
288,
746,
3146,
480,
16896,
1471,
506,
282,
769,
503,
2008,
531,
267,
291,
423,
9223,
63,
739,
275,
17347,
339,
768,
3744,
272,
347,
5246,
63,
466,
8,
1886,
12,
5246,
304,
267,
408,
267,
1432,
314,
1059,
6025,
367,
314,
730,
402,
282,
5246,
267,
408,
267,
19151,
275,
5246,
14,
1002,
23200,
342,
267,
340,
440,
19151,
26,
288,
11747,
275,
5246,
14,
1002,
30210,
2553,
7047,
3430,
16,
61,
288,
19151,
275,
11747,
14,
1002,
23059,
342,
288,
327,
1104,
340,
11747,
965,
3663,
4008,
288,
2582,
275,
11747,
14,
1002,
3166,
342,
288,
340,
2582,
690,
413,
26,
355,
19151,
275,
5041,
16,
22857,
91,
17,
26,
68,
11049,
1370,
908,
8,
18596,
12,
2582,
9,
267,
372,
19151,
339,
768,
3744,
272,
347,
5246,
63,
374,
63,
4946,
8,
1886,
12,
5246,
304,
267,
408,
267,
13550,
314,
5246,
1471,
1454,
1172,
1373,
11747,
1325,
314,
11747,
1443,
1172,
1373,
267,
503,
3663,
4008,
267,
408,
267,
372,
5246,
14,
13920,
16554,
342,
508,
413,
339,
347,
1218,
63,
2738,
8,
277,
12,
3686,
63,
15267,
29,
797,
304,
267,
408,
267,
2790,
642,
3123,
1159,
12178,
3299,
267,
408,
267,
3335,
807,
275,
8773,
342,
267,
367,
5246,
315,
291,
14,
1661,
16896,
837,
288,
327,
1454,
2387,
22225,
17347,
288,
340,
440,
291,
14,
1002,
12526,
3694,
8,
4694,
14,
21266,
5109,
355,
1980,
288,
340,
440,
3523,
3987,
14,
4694,
63,
374,
63,
4946,
8,
4694,
304,
355,
943,
14,
3764,
8,
490,
298,
4247,
16313,
5246,
658,
91,
16,
23485,
1674,
908,
8,
4694,
14,
21266,
4059,
355,
1980,
288,
3335,
807,
59,
4694,
14,
21266,
5106,
275,
12178,
14,
4694,
63,
466,
8,
4694,
9,
267,
291,
14,
409,
63,
2738,
8,
3987,
3299,
8,
288,
3335,
807,
12,
288,
3686,
63,
15267,
29,
4247,
63,
15267,
430,
339,
347,
1218,
63,
16896,
8,
277,
12,
17347,
304,
267,
408,
267,
2790,
17347,
687,
282,
12178,
3299,
503,
1211,
4412,
1561,
370,
730,
1561,
398,
3897,
267,
4143,
267,
17347,
520,
12178,
3299,
503,
1211,
267,
408,
267,
340,
440,
1228,
8,
16896,
12,
12178,
3299,
304,
288,
17347,
275,
12178,
3299,
8,
16896,
9,
267,
291,
14,
409,
63,
2738,
8,
16896,
12,
1218,
63,
16896,
29,
549,
9,
339,
347,
1678,
63,
2738,
8,
277,
12,
3123,
2738,
12,
9307,
63,
1462,
29,
797,
304,
267,
408,
267,
14076,
2974,
687,
282,
12178,
3299,
1901,
642,
12178,
1159,
12178,
3299,
398,
3897,
267,
4143,
267,
3335,
520,
1738,
647,
14,
2350,
14,
2738,
14,
3987,
3299,
288,
710,
12178,
3299,
370,
5389,
1901,
642,
12178,
1159,
3335,
398,
9307,
63,
1462,
520,
2155,
12,
2716,
334,
885,
29,
797,
9,
288,
982,
715,
2066,
1006,
2251,
436,
5055,
641,
314
] |
[
1898,
6029,
314,
1738,
647,
19782,
199,
3,
1854,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
984,
199,
646,
295,
199,
646,
15951,
199,
646,
5377,
199,
199,
646,
16547,
199,
199,
504,
2508,
492,
943,
27,
943,
275,
943,
28894,
354,
22705,
199,
504,
2508,
492,
465,
1231,
647,
12,
1413,
5441,
199,
504,
2508,
18587,
14,
8235,
807,
492,
8773,
199,
504,
2508,
1100,
492,
663,
63,
3619,
12,
2462,
63,
6100,
63,
2791,
1231,
694,
12,
886,
63,
16323,
199,
504,
2508,
1095,
492,
16198,
1692,
199,
504,
2508,
11582,
492,
6895,
1728,
63,
2546,
63,
2474,
12,
1083,
63,
493,
63,
1074,
12,
1083,
63,
493,
63,
2866,
199,
504,
2508,
2798,
1337,
14,
1095,
492,
14794,
1224,
199,
504,
2508,
2798,
1337,
492,
869,
631,
12,
29349,
199,
504,
2508,
4844,
14,
28227,
492,
4215,
9631,
199,
504,
1275,
5919,
492,
445,
337,
199,
504,
1275,
2350,
2738,
492,
12178,
3299,
199,
504,
1275,
2350,
1313,
492,
24289,
12,
8725,
12,
3523,
1610,
199,
504,
1275,
1238,
492,
12178,
1685,
199,
199,
363,
452,
363,
275,
359,
272,
283,
3987,
297,
272,
283,
46,
2960,
297,
199,
61,
421,
199,
533,
2876,
1451,
8,
785,
304,
272,
986,
421,
199,
533,
3523,
3987,
8,
7989,
1692,
304,
339,
5239,
63,
10764,
275,
295,
14,
2014,
8,
267,
14452,
2229,
48,
28,
16896,
29587,
3171,
267,
17644,
48,
28,
4876,
3072,
3072,
24693,
11,
11843,
7,
267,
17644,
48,
28,
354,
13489,
24805,
29716,
267,
17644,
48,
28,
1393,
1835,
31411,
5547,
5547,
9988,
339,
347,
485,
1932,
63,
826,
8,
277,
304,
267,
408,
267,
710,
4465,
1738,
647,
485,
1932,
63,
826,
1083,
626,
365,
1202,
370,
8265,
3865,
267,
892,
377,
5710,
436,
377,
5710,
12396,
687,
282,
3814,
14,
267,
408,
267,
340,
440,
2688,
8,
277,
12,
2513,
2738,
735,
288,
327,
1454,
663,
485,
2738,
340,
1402,
1990,
440,
2013,
315,
314,
636,
826,
363,
288,
291,
423,
2738,
275,
12178,
3299,
342,
267,
291,
14,
739,
63,
16896,
63,
265,
63,
24152,
275,
756,
267,
291,
423,
4694,
63,
1637,
275,
1052,
267,
291,
423,
1818,
63,
2373,
275,
378,
267,
291,
423,
9223,
63,
739,
275,
942,
267,
291,
14,
751,
576,
275,
2876,
1451,
342,
267,
291,
423,
2730,
471,
275,
715,
339,
347,
3544,
63,
739,
8,
277,
12,
17347,
304,
267,
408,
267,
16763,
1586,
3520,
17347,
12,
2755,
1380,
315,
13627,
818,
14,
23038,
1265,
1172,
267,
13627,
5223,
436,
2337,
787,
17347,
1265,
2934,
370,
506,
4588,
367,
1924,
267,
2397,
2755,
10617,
1265,
7078,
2879,
3062,
5370,
14,
961,
365,
2997,
340,
1265,
267,
787,
25012,
1806,
376,
1324,
3123,
436,
3575,
370,
376,
1072,
3123,
26994,
267,
314,
2011,
12178,
3299,
436,
1265,
2934,
282,
4125,
1331,
402,
9842,
17347,
14,
982,
267,
1265,
1172,
13627,
5223,
1325,
3520,
17347,
787,
440,
2013,
2348,
436,
267,
7078,
13810,
2066,
2985,
911,
7078,
506,
1586,
687,
4543,
12,
880,
314,
1338,
402,
267,
17347,
315,
4402,
911,
5706,
14874,
14,
398,
3897,
267,
4143,
267,
17347,
520,
769,
12,
2008,
288,
3520,
17347,
911,
3544,
506,
1586,
687,
4543,
367,
4036,
2372,
3900,
267,
408,
267,
340,
730,
8,
16896,
9,
440,
315,
334,
513,
12,
2008,
304,
288,
746,
3146,
480,
16896,
1471,
506,
282,
769,
503,
2008,
531,
267,
291,
423,
9223,
63,
739,
275,
17347,
339,
768,
3744,
272,
347,
5246,
63,
466,
8,
1886,
12,
5246,
304,
267,
408,
267,
1432,
314,
1059,
6025,
367,
314,
730,
402,
282,
5246,
267,
408,
267,
19151,
275,
5246,
14,
1002,
23200,
342,
267,
340,
440,
19151,
26,
288,
11747,
275,
5246,
14,
1002,
30210,
2553,
7047,
3430,
16,
61,
288,
19151,
275,
11747,
14,
1002,
23059,
342,
288,
327,
1104,
340,
11747,
965,
3663,
4008,
288,
2582,
275,
11747,
14,
1002,
3166,
342,
288,
340,
2582,
690,
413,
26,
355,
19151,
275,
5041,
16,
22857,
91,
17,
26,
68,
11049,
1370,
908,
8,
18596,
12,
2582,
9,
267,
372,
19151,
339,
768,
3744,
272,
347,
5246,
63,
374,
63,
4946,
8,
1886,
12,
5246,
304,
267,
408,
267,
13550,
314,
5246,
1471,
1454,
1172,
1373,
11747,
1325,
314,
11747,
1443,
1172,
1373,
267,
503,
3663,
4008,
267,
408,
267,
372,
5246,
14,
13920,
16554,
342,
508,
413,
339,
347,
1218,
63,
2738,
8,
277,
12,
3686,
63,
15267,
29,
797,
304,
267,
408,
267,
2790,
642,
3123,
1159,
12178,
3299,
267,
408,
267,
3335,
807,
275,
8773,
342,
267,
367,
5246,
315,
291,
14,
1661,
16896,
837,
288,
327,
1454,
2387,
22225,
17347,
288,
340,
440,
291,
14,
1002,
12526,
3694,
8,
4694,
14,
21266,
5109,
355,
1980,
288,
340,
440,
3523,
3987,
14,
4694,
63,
374,
63,
4946,
8,
4694,
304,
355,
943,
14,
3764,
8,
490,
298,
4247,
16313,
5246,
658,
91,
16,
23485,
1674,
908,
8,
4694,
14,
21266,
4059,
355,
1980,
288,
3335,
807,
59,
4694,
14,
21266,
5106,
275,
12178,
14,
4694,
63,
466,
8,
4694,
9,
267,
291,
14,
409,
63,
2738,
8,
3987,
3299,
8,
288,
3335,
807,
12,
288,
3686,
63,
15267,
29,
4247,
63,
15267,
430,
339,
347,
1218,
63,
16896,
8,
277,
12,
17347,
304,
267,
408,
267,
2790,
17347,
687,
282,
12178,
3299,
503,
1211,
4412,
1561,
370,
730,
1561,
398,
3897,
267,
4143,
267,
17347,
520,
12178,
3299,
503,
1211,
267,
408,
267,
340,
440,
1228,
8,
16896,
12,
12178,
3299,
304,
288,
17347,
275,
12178,
3299,
8,
16896,
9,
267,
291,
14,
409,
63,
2738,
8,
16896,
12,
1218,
63,
16896,
29,
549,
9,
339,
347,
1678,
63,
2738,
8,
277,
12,
3123,
2738,
12,
9307,
63,
1462,
29,
797,
304,
267,
408,
267,
14076,
2974,
687,
282,
12178,
3299,
1901,
642,
12178,
1159,
12178,
3299,
398,
3897,
267,
4143,
267,
3335,
520,
1738,
647,
14,
2350,
14,
2738,
14,
3987,
3299,
288,
710,
12178,
3299,
370,
5389,
1901,
642,
12178,
1159,
3335,
398,
9307,
63,
1462,
520,
2155,
12,
2716,
334,
885,
29,
797,
9,
288,
982,
715,
2066,
1006,
2251,
436,
5055,
641,
314,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
gimite/personfinder
|
app/vendors/unidecode/x05e.py
|
250
|
4668
|
data = (
'Za ', # 0x00
'Bi ', # 0x01
'Shi ', # 0x02
'Bu ', # 0x03
'Ding ', # 0x04
'Shuai ', # 0x05
'Fan ', # 0x06
'Nie ', # 0x07
'Shi ', # 0x08
'Fen ', # 0x09
'Pa ', # 0x0a
'Zhi ', # 0x0b
'Xi ', # 0x0c
'Hu ', # 0x0d
'Dan ', # 0x0e
'Wei ', # 0x0f
'Zhang ', # 0x10
'Tang ', # 0x11
'Dai ', # 0x12
'Ma ', # 0x13
'Pei ', # 0x14
'Pa ', # 0x15
'Tie ', # 0x16
'Fu ', # 0x17
'Lian ', # 0x18
'Zhi ', # 0x19
'Zhou ', # 0x1a
'Bo ', # 0x1b
'Zhi ', # 0x1c
'Di ', # 0x1d
'Mo ', # 0x1e
'Yi ', # 0x1f
'Yi ', # 0x20
'Ping ', # 0x21
'Qia ', # 0x22
'Juan ', # 0x23
'Ru ', # 0x24
'Shuai ', # 0x25
'Dai ', # 0x26
'Zheng ', # 0x27
'Shui ', # 0x28
'Qiao ', # 0x29
'Zhen ', # 0x2a
'Shi ', # 0x2b
'Qun ', # 0x2c
'Xi ', # 0x2d
'Bang ', # 0x2e
'Dai ', # 0x2f
'Gui ', # 0x30
'Chou ', # 0x31
'Ping ', # 0x32
'Zhang ', # 0x33
'Sha ', # 0x34
'Wan ', # 0x35
'Dai ', # 0x36
'Wei ', # 0x37
'Chang ', # 0x38
'Sha ', # 0x39
'Qi ', # 0x3a
'Ze ', # 0x3b
'Guo ', # 0x3c
'Mao ', # 0x3d
'Du ', # 0x3e
'Hou ', # 0x3f
'Zheng ', # 0x40
'Xu ', # 0x41
'Mi ', # 0x42
'Wei ', # 0x43
'Wo ', # 0x44
'Fu ', # 0x45
'Yi ', # 0x46
'Bang ', # 0x47
'Ping ', # 0x48
'Tazuna ', # 0x49
'Gong ', # 0x4a
'Pan ', # 0x4b
'Huang ', # 0x4c
'Dao ', # 0x4d
'Mi ', # 0x4e
'Jia ', # 0x4f
'Teng ', # 0x50
'Hui ', # 0x51
'Zhong ', # 0x52
'Shan ', # 0x53
'Man ', # 0x54
'Mu ', # 0x55
'Biao ', # 0x56
'Guo ', # 0x57
'Ze ', # 0x58
'Mu ', # 0x59
'Bang ', # 0x5a
'Zhang ', # 0x5b
'Jiong ', # 0x5c
'Chan ', # 0x5d
'Fu ', # 0x5e
'Zhi ', # 0x5f
'Hu ', # 0x60
'Fan ', # 0x61
'Chuang ', # 0x62
'Bi ', # 0x63
'Hei ', # 0x64
'[?] ', # 0x65
'Mi ', # 0x66
'Qiao ', # 0x67
'Chan ', # 0x68
'Fen ', # 0x69
'Meng ', # 0x6a
'Bang ', # 0x6b
'Chou ', # 0x6c
'Mie ', # 0x6d
'Chu ', # 0x6e
'Jie ', # 0x6f
'Xian ', # 0x70
'Lan ', # 0x71
'Gan ', # 0x72
'Ping ', # 0x73
'Nian ', # 0x74
'Qian ', # 0x75
'Bing ', # 0x76
'Bing ', # 0x77
'Xing ', # 0x78
'Gan ', # 0x79
'Yao ', # 0x7a
'Huan ', # 0x7b
'You ', # 0x7c
'You ', # 0x7d
'Ji ', # 0x7e
'Yan ', # 0x7f
'Pi ', # 0x80
'Ting ', # 0x81
'Ze ', # 0x82
'Guang ', # 0x83
'Zhuang ', # 0x84
'Mo ', # 0x85
'Qing ', # 0x86
'Bi ', # 0x87
'Qin ', # 0x88
'Dun ', # 0x89
'Chuang ', # 0x8a
'Gui ', # 0x8b
'Ya ', # 0x8c
'Bai ', # 0x8d
'Jie ', # 0x8e
'Xu ', # 0x8f
'Lu ', # 0x90
'Wu ', # 0x91
'[?] ', # 0x92
'Ku ', # 0x93
'Ying ', # 0x94
'Di ', # 0x95
'Pao ', # 0x96
'Dian ', # 0x97
'Ya ', # 0x98
'Miao ', # 0x99
'Geng ', # 0x9a
'Ci ', # 0x9b
'Fu ', # 0x9c
'Tong ', # 0x9d
'Pang ', # 0x9e
'Fei ', # 0x9f
'Xiang ', # 0xa0
'Yi ', # 0xa1
'Zhi ', # 0xa2
'Tiao ', # 0xa3
'Zhi ', # 0xa4
'Xiu ', # 0xa5
'Du ', # 0xa6
'Zuo ', # 0xa7
'Xiao ', # 0xa8
'Tu ', # 0xa9
'Gui ', # 0xaa
'Ku ', # 0xab
'Pang ', # 0xac
'Ting ', # 0xad
'You ', # 0xae
'Bu ', # 0xaf
'Ding ', # 0xb0
'Cheng ', # 0xb1
'Lai ', # 0xb2
'Bei ', # 0xb3
'Ji ', # 0xb4
'An ', # 0xb5
'Shu ', # 0xb6
'Kang ', # 0xb7
'Yong ', # 0xb8
'Tuo ', # 0xb9
'Song ', # 0xba
'Shu ', # 0xbb
'Qing ', # 0xbc
'Yu ', # 0xbd
'Yu ', # 0xbe
'Miao ', # 0xbf
'Sou ', # 0xc0
'Ce ', # 0xc1
'Xiang ', # 0xc2
'Fei ', # 0xc3
'Jiu ', # 0xc4
'He ', # 0xc5
'Hui ', # 0xc6
'Liu ', # 0xc7
'Sha ', # 0xc8
'Lian ', # 0xc9
'Lang ', # 0xca
'Sou ', # 0xcb
'Jian ', # 0xcc
'Pou ', # 0xcd
'Qing ', # 0xce
'Jiu ', # 0xcf
'Jiu ', # 0xd0
'Qin ', # 0xd1
'Ao ', # 0xd2
'Kuo ', # 0xd3
'Lou ', # 0xd4
'Yin ', # 0xd5
'Liao ', # 0xd6
'Dai ', # 0xd7
'Lu ', # 0xd8
'Yi ', # 0xd9
'Chu ', # 0xda
'Chan ', # 0xdb
'Tu ', # 0xdc
'Si ', # 0xdd
'Xin ', # 0xde
'Miao ', # 0xdf
'Chang ', # 0xe0
'Wu ', # 0xe1
'Fei ', # 0xe2
'Guang ', # 0xe3
'Koc ', # 0xe4
'Kuai ', # 0xe5
'Bi ', # 0xe6
'Qiang ', # 0xe7
'Xie ', # 0xe8
'Lin ', # 0xe9
'Lin ', # 0xea
'Liao ', # 0xeb
'Lu ', # 0xec
'[?] ', # 0xed
'Ying ', # 0xee
'Xian ', # 0xef
'Ting ', # 0xf0
'Yong ', # 0xf1
'Li ', # 0xf2
'Ting ', # 0xf3
'Yin ', # 0xf4
'Xun ', # 0xf5
'Yan ', # 0xf6
'Ting ', # 0xf7
'Di ', # 0xf8
'Po ', # 0xf9
'Jian ', # 0xfa
'Hui ', # 0xfb
'Nai ', # 0xfc
'Hui ', # 0xfd
'Gong ', # 0xfe
'Nian ', # 0xff
)
|
apache-2.0
|
[
576,
275,
334,
199,
7,
13163,
1656,
259,
327,
378,
88,
383,
199,
7,
17975,
1656,
259,
327,
378,
88,
614,
199,
7,
2662,
73,
1656,
259,
327,
378,
88,
996,
199,
7,
1713,
1656,
259,
327,
378,
88,
1644,
199,
7,
36,
316,
1656,
259,
327,
378,
88,
966,
199,
7,
2662,
1458,
73,
1656,
259,
327,
378,
88,
1717,
199,
7,
29745,
1656,
259,
327,
378,
88,
1690,
199,
7,
46,
1873,
1656,
259,
327,
378,
88,
1780,
199,
7,
2662,
73,
1656,
259,
327,
378,
88,
2036,
199,
7,
38,
287,
1656,
259,
327,
378,
88,
1643,
199,
7,
4232,
1656,
259,
327,
378,
88,
16,
65,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
16,
66,
199,
7,
14828,
1656,
259,
327,
378,
88,
16,
67,
199,
7,
25542,
1656,
259,
327,
378,
88,
16,
68,
199,
7,
29336,
1656,
259,
327,
378,
88,
16,
69,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
16,
70,
199,
7,
12674,
621,
1656,
259,
327,
378,
88,
709,
199,
7,
52,
621,
1656,
259,
327,
378,
88,
845,
199,
7,
36,
5789,
1656,
259,
327,
378,
88,
713,
199,
7,
11903,
1656,
259,
327,
378,
88,
969,
199,
7,
8070,
73,
1656,
259,
327,
378,
88,
1079,
199,
7,
4232,
1656,
259,
327,
378,
88,
1046,
199,
7,
52,
1873,
1656,
259,
327,
378,
88,
975,
199,
7,
19590,
1656,
259,
327,
378,
88,
1196,
199,
7,
44,
5653,
1656,
259,
327,
378,
88,
1085,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
1167,
199,
7,
58,
11586,
1656,
259,
327,
378,
88,
17,
65,
199,
7,
2208,
1656,
259,
327,
378,
88,
17,
66,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
17,
67,
199,
7,
1341,
1656,
259,
327,
378,
88,
17,
68,
199,
7,
3716,
1656,
259,
327,
378,
88,
17,
69,
199,
7,
21001,
1656,
259,
327,
378,
88,
17,
70,
199,
7,
21001,
1656,
259,
327,
378,
88,
1165,
199,
7,
22638,
1656,
259,
327,
378,
88,
2025,
199,
7,
49,
4674,
1656,
259,
327,
378,
88,
1081,
199,
7,
42,
7856,
1656,
259,
327,
378,
88,
1789,
199,
7,
50,
85,
1656,
259,
327,
378,
88,
1194,
199,
7,
2662,
1458,
73,
1656,
259,
327,
378,
88,
821,
199,
7,
36,
5789,
1656,
259,
327,
378,
88,
1479,
199,
7,
12674,
7420,
1656,
259,
327,
378,
88,
1465,
199,
7,
2662,
1907,
1656,
259,
327,
378,
88,
1651,
199,
7,
49,
18939,
1656,
259,
327,
378,
88,
1398,
199,
7,
12674,
287,
1656,
259,
327,
378,
88,
18,
65,
199,
7,
2662,
73,
1656,
259,
327,
378,
88,
18,
66,
199,
7,
49,
324,
1656,
259,
327,
378,
88,
18,
67,
199,
7,
14828,
1656,
259,
327,
378,
88,
18,
68,
199,
7,
34,
621,
1656,
259,
327,
378,
88,
18,
69,
199,
7,
36,
5789,
1656,
259,
327,
378,
88,
18,
70,
199,
7,
4324,
1656,
259,
327,
378,
88,
1216,
199,
7,
6209,
85,
1656,
259,
327,
378,
88,
2192,
199,
7,
22638,
1656,
259,
327,
378,
88,
708,
199,
7,
12674,
621,
1656,
259,
327,
378,
88,
1153,
199,
7,
23527,
1656,
259,
327,
378,
88,
1082,
199,
7,
55,
290,
1656,
259,
327,
378,
88,
1276,
199,
7,
36,
5789,
1656,
259,
327,
378,
88,
1344,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
1401,
199,
7,
1049,
621,
1656,
259,
327,
378,
88,
1703,
199,
7,
23527,
1656,
259,
327,
378,
88,
1355,
199,
7,
19910,
1656,
259,
327,
378,
88,
19,
65,
199,
7,
58,
69,
1656,
259,
327,
378,
88,
19,
66,
199,
7,
11548,
79,
1656,
259,
327,
378,
88,
19,
67,
199,
7,
45,
8035,
1656,
259,
327,
378,
88,
19,
68,
199,
7,
36,
85,
1656,
259,
327,
378,
88,
19,
69,
199,
7,
24386,
1656,
259,
327,
378,
88,
19,
70,
199,
7,
12674,
7420,
1656,
259,
327,
378,
88,
2167,
199,
7,
56,
85,
1656,
259,
327,
378,
88,
2953,
199,
7,
14738,
1656,
259,
327,
378,
88,
2260,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
2824,
199,
7,
26724,
1656,
259,
327,
378,
88,
1602,
199,
7,
19590,
1656,
259,
327,
378,
88,
2322,
199,
7,
21001,
1656,
259,
327,
378,
88,
2466,
199,
7,
34,
621,
1656,
259,
327,
378,
88,
2417,
199,
7,
22638,
1656,
259,
327,
378,
88,
2006,
199,
7,
52,
4651,
31627,
1656,
259,
327,
378,
88,
1887,
199,
7,
39,
951,
1656,
259,
327,
378,
88,
20,
65,
199,
7,
19266,
1656,
259,
327,
378,
88,
20,
66,
199,
7,
25542,
621,
1656,
259,
327,
378,
88,
20,
67,
199,
7,
27361,
1656,
259,
327,
378,
88,
20,
68,
199,
7,
14738,
1656,
259,
327,
378,
88,
20,
69,
199,
7,
42,
4674,
1656,
259,
327,
378,
88,
20,
70,
199,
7,
52,
7420,
1656,
259,
327,
378,
88,
1400,
199,
7,
40,
1907,
1656,
259,
327,
378,
88,
2869,
199,
7,
12674,
951,
1656,
259,
327,
378,
88,
2528,
199,
7,
2662,
290,
1656,
259,
327,
378,
88,
2481,
199,
7,
2395,
1656,
259,
327,
378,
88,
1477,
199,
7,
16215,
1656,
259,
327,
378,
88,
1229,
199,
7,
34,
18939,
1656,
259,
327,
378,
88,
1367,
199,
7,
11548,
79,
1656,
259,
327,
378,
88,
1641,
199,
7,
58,
69,
1656,
259,
327,
378,
88,
2010,
199,
7,
16215,
1656,
259,
327,
378,
88,
1427,
199,
7,
34,
621,
1656,
259,
327,
378,
88,
21,
65,
199,
7,
12674,
621,
1656,
259,
327,
378,
88,
21,
66,
199,
7,
16911,
951,
1656,
259,
327,
378,
88,
21,
67,
199,
7,
27039,
1656,
259,
327,
378,
88,
21,
68,
199,
7,
19590,
1656,
259,
327,
378,
88,
21,
69,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
21,
70,
199,
7,
25542,
1656,
259,
327,
378,
88,
2259,
199,
7,
29745,
1656,
259,
327,
378,
88,
2976,
199,
7,
1049,
85,
621,
1656,
259,
327,
378,
88,
2789,
199,
7,
17975,
1656,
259,
327,
378,
88,
2766,
199,
7,
1966,
73,
1656,
259,
327,
378,
88,
772,
199,
17892,
1656,
259,
327,
378,
88,
2182,
199,
7,
14738
] |
[
275,
334,
199,
7,
13163,
1656,
259,
327,
378,
88,
383,
199,
7,
17975,
1656,
259,
327,
378,
88,
614,
199,
7,
2662,
73,
1656,
259,
327,
378,
88,
996,
199,
7,
1713,
1656,
259,
327,
378,
88,
1644,
199,
7,
36,
316,
1656,
259,
327,
378,
88,
966,
199,
7,
2662,
1458,
73,
1656,
259,
327,
378,
88,
1717,
199,
7,
29745,
1656,
259,
327,
378,
88,
1690,
199,
7,
46,
1873,
1656,
259,
327,
378,
88,
1780,
199,
7,
2662,
73,
1656,
259,
327,
378,
88,
2036,
199,
7,
38,
287,
1656,
259,
327,
378,
88,
1643,
199,
7,
4232,
1656,
259,
327,
378,
88,
16,
65,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
16,
66,
199,
7,
14828,
1656,
259,
327,
378,
88,
16,
67,
199,
7,
25542,
1656,
259,
327,
378,
88,
16,
68,
199,
7,
29336,
1656,
259,
327,
378,
88,
16,
69,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
16,
70,
199,
7,
12674,
621,
1656,
259,
327,
378,
88,
709,
199,
7,
52,
621,
1656,
259,
327,
378,
88,
845,
199,
7,
36,
5789,
1656,
259,
327,
378,
88,
713,
199,
7,
11903,
1656,
259,
327,
378,
88,
969,
199,
7,
8070,
73,
1656,
259,
327,
378,
88,
1079,
199,
7,
4232,
1656,
259,
327,
378,
88,
1046,
199,
7,
52,
1873,
1656,
259,
327,
378,
88,
975,
199,
7,
19590,
1656,
259,
327,
378,
88,
1196,
199,
7,
44,
5653,
1656,
259,
327,
378,
88,
1085,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
1167,
199,
7,
58,
11586,
1656,
259,
327,
378,
88,
17,
65,
199,
7,
2208,
1656,
259,
327,
378,
88,
17,
66,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
17,
67,
199,
7,
1341,
1656,
259,
327,
378,
88,
17,
68,
199,
7,
3716,
1656,
259,
327,
378,
88,
17,
69,
199,
7,
21001,
1656,
259,
327,
378,
88,
17,
70,
199,
7,
21001,
1656,
259,
327,
378,
88,
1165,
199,
7,
22638,
1656,
259,
327,
378,
88,
2025,
199,
7,
49,
4674,
1656,
259,
327,
378,
88,
1081,
199,
7,
42,
7856,
1656,
259,
327,
378,
88,
1789,
199,
7,
50,
85,
1656,
259,
327,
378,
88,
1194,
199,
7,
2662,
1458,
73,
1656,
259,
327,
378,
88,
821,
199,
7,
36,
5789,
1656,
259,
327,
378,
88,
1479,
199,
7,
12674,
7420,
1656,
259,
327,
378,
88,
1465,
199,
7,
2662,
1907,
1656,
259,
327,
378,
88,
1651,
199,
7,
49,
18939,
1656,
259,
327,
378,
88,
1398,
199,
7,
12674,
287,
1656,
259,
327,
378,
88,
18,
65,
199,
7,
2662,
73,
1656,
259,
327,
378,
88,
18,
66,
199,
7,
49,
324,
1656,
259,
327,
378,
88,
18,
67,
199,
7,
14828,
1656,
259,
327,
378,
88,
18,
68,
199,
7,
34,
621,
1656,
259,
327,
378,
88,
18,
69,
199,
7,
36,
5789,
1656,
259,
327,
378,
88,
18,
70,
199,
7,
4324,
1656,
259,
327,
378,
88,
1216,
199,
7,
6209,
85,
1656,
259,
327,
378,
88,
2192,
199,
7,
22638,
1656,
259,
327,
378,
88,
708,
199,
7,
12674,
621,
1656,
259,
327,
378,
88,
1153,
199,
7,
23527,
1656,
259,
327,
378,
88,
1082,
199,
7,
55,
290,
1656,
259,
327,
378,
88,
1276,
199,
7,
36,
5789,
1656,
259,
327,
378,
88,
1344,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
1401,
199,
7,
1049,
621,
1656,
259,
327,
378,
88,
1703,
199,
7,
23527,
1656,
259,
327,
378,
88,
1355,
199,
7,
19910,
1656,
259,
327,
378,
88,
19,
65,
199,
7,
58,
69,
1656,
259,
327,
378,
88,
19,
66,
199,
7,
11548,
79,
1656,
259,
327,
378,
88,
19,
67,
199,
7,
45,
8035,
1656,
259,
327,
378,
88,
19,
68,
199,
7,
36,
85,
1656,
259,
327,
378,
88,
19,
69,
199,
7,
24386,
1656,
259,
327,
378,
88,
19,
70,
199,
7,
12674,
7420,
1656,
259,
327,
378,
88,
2167,
199,
7,
56,
85,
1656,
259,
327,
378,
88,
2953,
199,
7,
14738,
1656,
259,
327,
378,
88,
2260,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
2824,
199,
7,
26724,
1656,
259,
327,
378,
88,
1602,
199,
7,
19590,
1656,
259,
327,
378,
88,
2322,
199,
7,
21001,
1656,
259,
327,
378,
88,
2466,
199,
7,
34,
621,
1656,
259,
327,
378,
88,
2417,
199,
7,
22638,
1656,
259,
327,
378,
88,
2006,
199,
7,
52,
4651,
31627,
1656,
259,
327,
378,
88,
1887,
199,
7,
39,
951,
1656,
259,
327,
378,
88,
20,
65,
199,
7,
19266,
1656,
259,
327,
378,
88,
20,
66,
199,
7,
25542,
621,
1656,
259,
327,
378,
88,
20,
67,
199,
7,
27361,
1656,
259,
327,
378,
88,
20,
68,
199,
7,
14738,
1656,
259,
327,
378,
88,
20,
69,
199,
7,
42,
4674,
1656,
259,
327,
378,
88,
20,
70,
199,
7,
52,
7420,
1656,
259,
327,
378,
88,
1400,
199,
7,
40,
1907,
1656,
259,
327,
378,
88,
2869,
199,
7,
12674,
951,
1656,
259,
327,
378,
88,
2528,
199,
7,
2662,
290,
1656,
259,
327,
378,
88,
2481,
199,
7,
2395,
1656,
259,
327,
378,
88,
1477,
199,
7,
16215,
1656,
259,
327,
378,
88,
1229,
199,
7,
34,
18939,
1656,
259,
327,
378,
88,
1367,
199,
7,
11548,
79,
1656,
259,
327,
378,
88,
1641,
199,
7,
58,
69,
1656,
259,
327,
378,
88,
2010,
199,
7,
16215,
1656,
259,
327,
378,
88,
1427,
199,
7,
34,
621,
1656,
259,
327,
378,
88,
21,
65,
199,
7,
12674,
621,
1656,
259,
327,
378,
88,
21,
66,
199,
7,
16911,
951,
1656,
259,
327,
378,
88,
21,
67,
199,
7,
27039,
1656,
259,
327,
378,
88,
21,
68,
199,
7,
19590,
1656,
259,
327,
378,
88,
21,
69,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
21,
70,
199,
7,
25542,
1656,
259,
327,
378,
88,
2259,
199,
7,
29745,
1656,
259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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
] |
kernel-bz/ml
|
Lectures/CNN/cnn_adam_opt.py
|
2
|
4213
|
'''
A Convolutional Network implementation example using TensorFlow library.
This example is using the MNIST database of handwritten digits (http://yann.lecun.com/exdb/mnist/)
Author: Aymeric Damien
Project: https://github.com/aymericdamien/TensorFlow-Examples/
'''
# Import MINST data
import input_data
mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
import tensorflow as tf
# Parameters
learning_rate = 0.001
training_iters = 100000
batch_size = 128
display_step = 10
# Network Parameters
n_input = 784 # MNIST data input (img shape: 28*28)
n_classes = 10 # MNIST total classes (0-9 digits)
dropout = 0.75 # Dropout, probability to keep units
# tf Graph input
x = tf.placeholder(tf.float32, [None, n_input])
y = tf.placeholder(tf.float32, [None, n_classes])
keep_prob = tf.placeholder(tf.float32) #dropout (keep probability)
# Create model
def conv2d(img, w, b):
return tf.nn.relu(tf.nn.bias_add(tf.nn.conv2d(img, w, strides=[1, 1, 1, 1], padding='SAME'),b))
def max_pool(img, k):
return tf.nn.max_pool(img, ksize=[1, k, k, 1], strides=[1, k, k, 1], padding='SAME')
def conv_net(_X, _weights, _biases, _dropout):
# Reshape input picture
_X = tf.reshape(_X, shape=[-1, 28, 28, 1])
# Convolution Layer
conv1 = conv2d(_X, _weights['wc1'], _biases['bc1'])
# Max Pooling (down-sampling)
conv1 = max_pool(conv1, k=2)
# Apply Dropout
conv1 = tf.nn.dropout(conv1, _dropout)
# Convolution Layer
conv2 = conv2d(conv1, _weights['wc2'], _biases['bc2'])
# Max Pooling (down-sampling)
conv2 = max_pool(conv2, k=2)
# Apply Dropout
conv2 = tf.nn.dropout(conv2, _dropout)
# Fully connected layer
dense1 = tf.reshape(conv2, [-1, _weights['wd1'].get_shape().as_list()[0]]) # Reshape conv2 output to fit dense layer input
dense1 = tf.nn.relu(tf.add(tf.matmul(dense1, _weights['wd1']), _biases['bd1'])) # Relu activation
dense1 = tf.nn.dropout(dense1, _dropout) # Apply Dropout
# Output, class prediction
out = tf.add(tf.matmul(dense1, _weights['out']), _biases['out'])
return out
# Store layers weight & bias
weights = {
'wc1': tf.Variable(tf.random_normal([5, 5, 1, 32])), # 5x5 conv, 1 input, 32 outputs
'wc2': tf.Variable(tf.random_normal([5, 5, 32, 64])), # 5x5 conv, 32 inputs, 64 outputs
'wd1': tf.Variable(tf.random_normal([7*7*64, 1024])), # fully connected, 7*7*64 inputs, 1024 outputs
'out': tf.Variable(tf.random_normal([1024, n_classes])) # 1024 inputs, 10 outputs (class prediction)
}
biases = {
'bc1': tf.Variable(tf.random_normal([32])),
'bc2': tf.Variable(tf.random_normal([64])),
'bd1': tf.Variable(tf.random_normal([1024])),
'out': tf.Variable(tf.random_normal([n_classes]))
}
# Construct model
pred = conv_net(x, weights, biases, keep_prob)
# Define loss and optimizer
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(pred, y))
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)
# Evaluate model
correct_pred = tf.equal(tf.argmax(pred,1), tf.argmax(y,1))
accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))
# Initializing the variables
init = tf.initialize_all_variables()
# Launch the graph
with tf.Session() as sess:
sess.run(init)
step = 1
# Keep training until reach max iterations
while step * batch_size < training_iters:
batch_xs, batch_ys = mnist.train.next_batch(batch_size)
# Fit training using batch data
sess.run(optimizer, feed_dict={x: batch_xs, y: batch_ys, keep_prob: dropout})
if step % display_step == 0:
# Calculate batch accuracy
acc = sess.run(accuracy, feed_dict={x: batch_xs, y: batch_ys, keep_prob: 1.})
# Calculate batch loss
loss = sess.run(cost, feed_dict={x: batch_xs, y: batch_ys, keep_prob: 1.})
print "Iter " + str(step*batch_size) + ", Minibatch Loss= " + "{:.6f}".format(loss) + ", Training Accuracy= " + "{:.5f}".format(acc)
step += 1
print "Optimization Finished!"
# Calculate accuracy for 256 mnist test images
print "Testing Accuracy:", sess.run(accuracy, feed_dict={x: mnist.test.images[:256], y: mnist.test.labels[:256], keep_prob: 1.})
|
gpl-3.0
|
[
2344,
199,
33,
19140,
3347,
279,
7220,
4514,
2893,
1808,
9134,
3555,
14,
199,
2765,
2893,
365,
1808,
314,
603,
25392,
3050,
402,
4926,
8938,
7576,
334,
1014,
921,
89,
1189,
14,
10251,
324,
14,
957,
15,
476,
697,
15,
32164,
24793,
199,
199,
5949,
26,
437,
89,
278,
1567,
577,
13496,
287,
199,
4761,
26,
4178,
921,
5031,
14,
957,
15,
1187,
278,
1567,
68,
13496,
287,
15,
26998,
13,
22787,
15,
199,
2344,
199,
199,
3,
3161,
603,
7834,
666,
199,
646,
1324,
63,
576,
199,
32164,
275,
1324,
63,
576,
14,
739,
63,
576,
63,
2193,
4769,
2791,
15,
576,
10665,
1373,
63,
8885,
29,
549,
9,
199,
199,
646,
3228,
465,
2833,
199,
199,
3,
3897,
199,
10546,
63,
1866,
275,
378,
14,
4587,
199,
7588,
63,
15266,
275,
25761,
199,
2912,
63,
890,
275,
7960,
199,
2918,
63,
2926,
275,
1616,
199,
199,
3,
7220,
3897,
199,
78,
63,
1210,
275,
1520,
1349,
327,
603,
25392,
666,
1324,
334,
4060,
2215,
26,
7294,
10,
1651,
9,
199,
78,
63,
2888,
275,
1616,
327,
603,
25392,
3141,
3992,
334,
16,
13,
25,
7576,
9,
199,
17953,
275,
378,
14,
2194,
327,
18110,
548,
12,
12224,
370,
4215,
6204,
199,
199,
3,
2833,
11513,
1324,
199,
88,
275,
2833,
14,
6199,
8,
3249,
14,
1609,
708,
12,
359,
403,
12,
302,
63,
1210,
566,
199,
89,
275,
2833,
14,
6199,
8,
3249,
14,
1609,
708,
12,
359,
403,
12,
302,
63,
2888,
566,
199,
3250,
63,
6101,
275,
2833,
14,
6199,
8,
3249,
14,
1609,
708,
9,
327,
17953,
334,
3250,
12224,
9,
199,
199,
3,
2790,
1402,
199,
318,
8260,
18,
68,
8,
4060,
12,
336,
12,
330,
304,
272,
372,
2833,
14,
4411,
14,
12833,
8,
3249,
14,
4411,
14,
8160,
63,
525,
8,
3249,
14,
4411,
14,
5598,
18,
68,
8,
4060,
12,
336,
12,
11883,
1524,
17,
12,
413,
12,
413,
12,
413,
467,
6273,
534,
19935,
659,
66,
430,
199,
199,
318,
1390,
63,
2293,
8,
4060,
12,
1022,
304,
272,
372,
2833,
14,
4411,
14,
988,
63,
2293,
8,
4060,
12,
30180,
1524,
17,
12,
1022,
12,
1022,
12,
413,
467,
11883,
1524,
17,
12,
1022,
12,
1022,
12,
413,
467,
6273,
534,
19935,
358,
199,
199,
318,
8260,
63,
846,
1547,
56,
12,
485,
4916,
12,
485,
20948,
12,
485,
17953,
304,
272,
327,
3591,
15221,
1324,
24945,
272,
485,
56,
275,
2833,
14,
5217,
1547,
56,
12,
2215,
1524,
13,
17,
12,
7294,
12,
7294,
12,
413,
566,
339,
327,
19140,
3347,
11915,
272,
8260,
17,
275,
8260,
18,
68,
1547,
56,
12,
485,
4916,
459,
13683,
17,
995,
485,
20948,
459,
3776,
17,
1105,
272,
327,
8228,
15553,
316,
334,
2110,
13,
17376,
9,
272,
8260,
17,
275,
1390,
63,
2293,
8,
5598,
17,
12,
1022,
29,
18,
9,
272,
327,
14618,
18110,
548,
272,
8260,
17,
275,
2833,
14,
4411,
14,
17953,
8,
5598,
17,
12,
485,
17953,
9,
339,
327,
19140,
3347,
11915,
272,
8260,
18,
275,
8260,
18,
68,
8,
5598,
17,
12,
485,
4916,
459,
13683,
18,
995,
485,
20948,
459,
3776,
18,
1105,
272,
327,
8228,
15553,
316,
334,
2110,
13,
17376,
9,
272,
8260,
18,
275,
1390,
63,
2293,
8,
5598,
18,
12,
1022,
29,
18,
9,
272,
327,
14618,
18110,
548,
272,
8260,
18,
275,
2833,
14,
4411,
14,
17953,
8,
5598,
18,
12,
485,
17953,
9,
339,
327,
481,
8525,
8539,
4045,
272,
9363,
17,
275,
2833,
14,
5217,
8,
5598,
18,
12,
5243,
17,
12,
485,
4916,
459,
2989,
17,
2278,
362,
63,
1392,
1252,
305,
63,
513,
3430,
16,
3934,
327,
3591,
15221,
8260,
18,
1072,
370,
5542,
9363,
4045,
1324,
272,
9363,
17,
275,
2833,
14,
4411,
14,
12833,
8,
3249,
14,
525,
8,
3249,
14,
14465,
8,
7253,
17,
12,
485,
4916,
459,
2989,
17,
3815,
485,
20948,
459,
3691,
17,
5156,
327,
9781,
85,
10361,
272,
9363,
17,
275,
2833,
14,
4411,
14,
17953,
8,
7253,
17,
12,
485,
17953,
9,
327,
14618,
18110,
548,
339,
327,
7242,
12,
1021,
12044,
272,
734,
275,
2833,
14,
525,
8,
3249,
14,
14465,
8,
7253,
17,
12,
485,
4916,
459,
548,
3815,
485,
20948,
459,
548,
1105,
272,
372,
734,
199,
199,
3,
13874,
9393,
5401,
1253,
10671,
199,
4916,
275,
469,
272,
283,
13683,
17,
356,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
3302,
779,
21,
12,
959,
12,
413,
12,
4337,
12884,
327,
959,
88,
21,
8260,
12,
413,
1324,
12,
4337,
4704,
272,
283,
13683,
18,
356,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
3302,
779,
21,
12,
959,
12,
4337,
12,
5049,
12884,
327,
959,
88,
21,
8260,
12,
4337,
4153,
12,
5049,
4704,
272,
283,
2989,
17,
356,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
3302,
779,
23,
10,
23,
10,
772,
12,
6619,
12884,
327,
9999,
8539,
12,
1520,
10,
23,
10,
772,
4153,
12,
6619,
4704,
272,
283,
548,
356,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
3302,
779,
7727,
12,
302,
63,
2888,
2459,
327,
6619,
4153,
12,
1616,
4704,
334,
533,
12044,
9,
199,
93,
199,
199,
20948,
275,
469,
272,
283,
3776,
17,
356,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
3302,
779,
708,
12884,
272,
283,
3776,
18,
356,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
3302,
779,
772,
12884,
272,
283,
3691,
17,
356,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
3302,
779,
7727,
12884,
272,
283,
548,
356,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
3302,
779,
78,
63,
2888,
2459,
199,
93,
199,
199,
3,
9215,
1402,
199,
5991,
275,
8260,
63,
846,
8,
88,
12,
4931,
12,
23548,
12,
4215,
63,
6101,
9,
199,
199,
3,
13930,
5621,
436,
10736,
199,
6336,
275,
2833,
14,
5270,
63,
3670,
8,
3249,
14,
4411,
14,
16395,
63,
7925,
63,
10435,
63,
1045,
63,
10492,
8,
5991,
12,
612,
430,
199,
12290,
275,
2833,
14,
2834,
14,
32408,
13946,
8,
10546,
63,
1866,
29,
10546,
63,
1866,
680,
19333,
8,
6336,
9,
199,
199,
3,
27450,
1402,
199,
4525,
63,
5991,
275,
2833,
14,
1452,
8,
3249,
14,
16383,
8,
5991
] |
[
199,
33,
19140,
3347,
279,
7220,
4514,
2893,
1808,
9134,
3555,
14,
199,
2765,
2893,
365,
1808,
314,
603,
25392,
3050,
402,
4926,
8938,
7576,
334,
1014,
921,
89,
1189,
14,
10251,
324,
14,
957,
15,
476,
697,
15,
32164,
24793,
199,
199,
5949,
26,
437,
89,
278,
1567,
577,
13496,
287,
199,
4761,
26,
4178,
921,
5031,
14,
957,
15,
1187,
278,
1567,
68,
13496,
287,
15,
26998,
13,
22787,
15,
199,
2344,
199,
199,
3,
3161,
603,
7834,
666,
199,
646,
1324,
63,
576,
199,
32164,
275,
1324,
63,
576,
14,
739,
63,
576,
63,
2193,
4769,
2791,
15,
576,
10665,
1373,
63,
8885,
29,
549,
9,
199,
199,
646,
3228,
465,
2833,
199,
199,
3,
3897,
199,
10546,
63,
1866,
275,
378,
14,
4587,
199,
7588,
63,
15266,
275,
25761,
199,
2912,
63,
890,
275,
7960,
199,
2918,
63,
2926,
275,
1616,
199,
199,
3,
7220,
3897,
199,
78,
63,
1210,
275,
1520,
1349,
327,
603,
25392,
666,
1324,
334,
4060,
2215,
26,
7294,
10,
1651,
9,
199,
78,
63,
2888,
275,
1616,
327,
603,
25392,
3141,
3992,
334,
16,
13,
25,
7576,
9,
199,
17953,
275,
378,
14,
2194,
327,
18110,
548,
12,
12224,
370,
4215,
6204,
199,
199,
3,
2833,
11513,
1324,
199,
88,
275,
2833,
14,
6199,
8,
3249,
14,
1609,
708,
12,
359,
403,
12,
302,
63,
1210,
566,
199,
89,
275,
2833,
14,
6199,
8,
3249,
14,
1609,
708,
12,
359,
403,
12,
302,
63,
2888,
566,
199,
3250,
63,
6101,
275,
2833,
14,
6199,
8,
3249,
14,
1609,
708,
9,
327,
17953,
334,
3250,
12224,
9,
199,
199,
3,
2790,
1402,
199,
318,
8260,
18,
68,
8,
4060,
12,
336,
12,
330,
304,
272,
372,
2833,
14,
4411,
14,
12833,
8,
3249,
14,
4411,
14,
8160,
63,
525,
8,
3249,
14,
4411,
14,
5598,
18,
68,
8,
4060,
12,
336,
12,
11883,
1524,
17,
12,
413,
12,
413,
12,
413,
467,
6273,
534,
19935,
659,
66,
430,
199,
199,
318,
1390,
63,
2293,
8,
4060,
12,
1022,
304,
272,
372,
2833,
14,
4411,
14,
988,
63,
2293,
8,
4060,
12,
30180,
1524,
17,
12,
1022,
12,
1022,
12,
413,
467,
11883,
1524,
17,
12,
1022,
12,
1022,
12,
413,
467,
6273,
534,
19935,
358,
199,
199,
318,
8260,
63,
846,
1547,
56,
12,
485,
4916,
12,
485,
20948,
12,
485,
17953,
304,
272,
327,
3591,
15221,
1324,
24945,
272,
485,
56,
275,
2833,
14,
5217,
1547,
56,
12,
2215,
1524,
13,
17,
12,
7294,
12,
7294,
12,
413,
566,
339,
327,
19140,
3347,
11915,
272,
8260,
17,
275,
8260,
18,
68,
1547,
56,
12,
485,
4916,
459,
13683,
17,
995,
485,
20948,
459,
3776,
17,
1105,
272,
327,
8228,
15553,
316,
334,
2110,
13,
17376,
9,
272,
8260,
17,
275,
1390,
63,
2293,
8,
5598,
17,
12,
1022,
29,
18,
9,
272,
327,
14618,
18110,
548,
272,
8260,
17,
275,
2833,
14,
4411,
14,
17953,
8,
5598,
17,
12,
485,
17953,
9,
339,
327,
19140,
3347,
11915,
272,
8260,
18,
275,
8260,
18,
68,
8,
5598,
17,
12,
485,
4916,
459,
13683,
18,
995,
485,
20948,
459,
3776,
18,
1105,
272,
327,
8228,
15553,
316,
334,
2110,
13,
17376,
9,
272,
8260,
18,
275,
1390,
63,
2293,
8,
5598,
18,
12,
1022,
29,
18,
9,
272,
327,
14618,
18110,
548,
272,
8260,
18,
275,
2833,
14,
4411,
14,
17953,
8,
5598,
18,
12,
485,
17953,
9,
339,
327,
481,
8525,
8539,
4045,
272,
9363,
17,
275,
2833,
14,
5217,
8,
5598,
18,
12,
5243,
17,
12,
485,
4916,
459,
2989,
17,
2278,
362,
63,
1392,
1252,
305,
63,
513,
3430,
16,
3934,
327,
3591,
15221,
8260,
18,
1072,
370,
5542,
9363,
4045,
1324,
272,
9363,
17,
275,
2833,
14,
4411,
14,
12833,
8,
3249,
14,
525,
8,
3249,
14,
14465,
8,
7253,
17,
12,
485,
4916,
459,
2989,
17,
3815,
485,
20948,
459,
3691,
17,
5156,
327,
9781,
85,
10361,
272,
9363,
17,
275,
2833,
14,
4411,
14,
17953,
8,
7253,
17,
12,
485,
17953,
9,
327,
14618,
18110,
548,
339,
327,
7242,
12,
1021,
12044,
272,
734,
275,
2833,
14,
525,
8,
3249,
14,
14465,
8,
7253,
17,
12,
485,
4916,
459,
548,
3815,
485,
20948,
459,
548,
1105,
272,
372,
734,
199,
199,
3,
13874,
9393,
5401,
1253,
10671,
199,
4916,
275,
469,
272,
283,
13683,
17,
356,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
3302,
779,
21,
12,
959,
12,
413,
12,
4337,
12884,
327,
959,
88,
21,
8260,
12,
413,
1324,
12,
4337,
4704,
272,
283,
13683,
18,
356,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
3302,
779,
21,
12,
959,
12,
4337,
12,
5049,
12884,
327,
959,
88,
21,
8260,
12,
4337,
4153,
12,
5049,
4704,
272,
283,
2989,
17,
356,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
3302,
779,
23,
10,
23,
10,
772,
12,
6619,
12884,
327,
9999,
8539,
12,
1520,
10,
23,
10,
772,
4153,
12,
6619,
4704,
272,
283,
548,
356,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
3302,
779,
7727,
12,
302,
63,
2888,
2459,
327,
6619,
4153,
12,
1616,
4704,
334,
533,
12044,
9,
199,
93,
199,
199,
20948,
275,
469,
272,
283,
3776,
17,
356,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
3302,
779,
708,
12884,
272,
283,
3776,
18,
356,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
3302,
779,
772,
12884,
272,
283,
3691,
17,
356,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
3302,
779,
7727,
12884,
272,
283,
548,
356,
2833,
14,
2773,
8,
3249,
14,
2355,
63,
3302,
779,
78,
63,
2888,
2459,
199,
93,
199,
199,
3,
9215,
1402,
199,
5991,
275,
8260,
63,
846,
8,
88,
12,
4931,
12,
23548,
12,
4215,
63,
6101,
9,
199,
199,
3,
13930,
5621,
436,
10736,
199,
6336,
275,
2833,
14,
5270,
63,
3670,
8,
3249,
14,
4411,
14,
16395,
63,
7925,
63,
10435,
63,
1045,
63,
10492,
8,
5991,
12,
612,
430,
199,
12290,
275,
2833,
14,
2834,
14,
32408,
13946,
8,
10546,
63,
1866,
29,
10546,
63,
1866,
680,
19333,
8,
6336,
9,
199,
199,
3,
27450,
1402,
199,
4525,
63,
5991,
275,
2833,
14,
1452,
8,
3249,
14,
16383,
8,
5991,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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
|
import sys
import numpy as np
import numpy.ma as ma
from numpy.ma.testutils import *
from numpy.ma.mrecords import MaskedRecords
from numpy.lib.recfunctions import *
get_names = np.lib.recfunctions.get_names
get_names_flat = np.lib.recfunctions.get_names_flat
zip_descr = np.lib.recfunctions.zip_descr
class TestRecFunctions(TestCase):
"""
Misc tests
"""
#
def setUp(self):
x = np.array([1, 2, ])
y = np.array([10, 20, 30])
z = np.array([('A', 1.), ('B', 2.)],
dtype=[('A', '|S3'), ('B', float)])
w = np.array([(1, (2, 3.0)), (4, (5, 6.0))],
dtype=[('a', int), ('b', [('ba', float), ('bb', int)])])
self.data = (w, x, y, z)
def test_zip_descr(self):
"Test zip_descr"
(w, x, y, z) = self.data
# Std array
test = zip_descr((x, x), flatten=True)
assert_equal(test,
np.dtype([('', int), ('', int)]))
test = zip_descr((x, x), flatten=False)
assert_equal(test,
np.dtype([('', int), ('', int)]))
# Std & flexible-dtype
test = zip_descr((x, z), flatten=True)
assert_equal(test,
np.dtype([('', int), ('A', '|S3'), ('B', float)]))
test = zip_descr((x, z), flatten=False)
assert_equal(test,
np.dtype([('', int),
('', [('A', '|S3'), ('B', float)])]))
# Standard & nested dtype
test = zip_descr((x, w), flatten=True)
assert_equal(test,
np.dtype([('', int),
('a', int),
('ba', float), ('bb', int)]))
test = zip_descr((x, w), flatten=False)
assert_equal(test,
np.dtype([('', int),
('', [('a', int),
('b', [('ba', float), ('bb', int)])])]))
def test_drop_fields(self):
"Test drop_fields"
a = np.array([(1, (2, 3.0)), (4, (5, 6.0))],
dtype=[('a', int), ('b', [('ba', float), ('bb', int)])])
# A basic field
test = drop_fields(a, 'a')
control = np.array([((2, 3.0),), ((5, 6.0),)],
dtype=[('b', [('ba', float), ('bb', int)])])
assert_equal(test, control)
# Another basic field (but nesting two fields)
test = drop_fields(a, 'b')
control = np.array([(1,), (4,)], dtype=[('a', int)])
assert_equal(test, control)
# A nested sub-field
test = drop_fields(a, ['ba', ])
control = np.array([(1, (3.0,)), (4, (6.0,))],
dtype=[('a', int), ('b', [('bb', int)])])
assert_equal(test, control)
# All the nested sub-field from a field: zap that field
test = drop_fields(a, ['ba', 'bb'])
control = np.array([(1,), (4,)], dtype=[('a', int)])
assert_equal(test, control)
#
test = drop_fields(a, ['a', 'b'])
assert(test is None)
def test_rename_fields(self):
"Tests rename fields"
a = np.array([(1, (2, [3.0, 30.])), (4, (5, [6.0, 60.]))],
dtype=[('a', int),
('b', [('ba', float), ('bb', (float, 2))])])
test = rename_fields(a, {'a':'A', 'bb':'BB'})
newdtype = [('A', int), ('b', [('ba', float), ('BB', (float, 2))])]
control = a.view(newdtype)
assert_equal(test.dtype, newdtype)
assert_equal(test, control)
def test_get_names(self):
"Tests get_names"
ndtype = np.dtype([('A', '|S3'), ('B', float)])
test = get_names(ndtype)
assert_equal(test, ('A', 'B'))
#
ndtype = np.dtype([('a', int), ('b', [('ba', float), ('bb', int)])])
test = get_names(ndtype)
assert_equal(test, ('a', ('b', ('ba', 'bb'))))
def test_get_names_flat(self):
"Test get_names_flat"
ndtype = np.dtype([('A', '|S3'), ('B', float)])
test = get_names_flat(ndtype)
assert_equal(test, ('A', 'B'))
#
ndtype = np.dtype([('a', int), ('b', [('ba', float), ('bb', int)])])
test = get_names_flat(ndtype)
assert_equal(test, ('a', 'b', 'ba', 'bb'))
def test_get_fieldstructure(self):
"Test get_fieldstructure"
# No nested fields
ndtype = np.dtype([('A', '|S3'), ('B', float)])
test = get_fieldstructure(ndtype)
assert_equal(test, {'A':[], 'B':[]})
# One 1-nested field
ndtype = np.dtype([('A', int), ('B', [('BA', float), ('BB', '|S1')])])
test = get_fieldstructure(ndtype)
assert_equal(test, {'A': [], 'B': [], 'BA':['B', ], 'BB':['B']})
# One 2-nested fields
ndtype = np.dtype([('A', int),
('B', [('BA', int),
('BB', [('BBA', int), ('BBB', int)])])])
test = get_fieldstructure(ndtype)
control = {'A': [], 'B': [], 'BA': ['B'], 'BB': ['B'],
'BBA': ['B', 'BB'], 'BBB': ['B', 'BB']}
assert_equal(test, control)
def test_find_duplicates(self):
"Test find_duplicates"
a = ma.array([(2, (2., 'B')), (1, (2., 'B')), (2, (2., 'B')),
(1, (1., 'B')), (2, (2., 'B')), (2, (2., 'C'))],
mask=[(0, (0, 0)), (0, (0, 0)), (0, (0, 0)),
(0, (0, 0)), (1, (0, 0)), (0, (1, 0))],
dtype=[('A', int), ('B', [('BA', float), ('BB', '|S1')])])
#
test = find_duplicates(a, ignoremask=False, return_index=True)
control = [0, 2]
assert_equal(sorted(test[-1]), control)
assert_equal(test[0], a[test[-1]])
#
test = find_duplicates(a, key='A', return_index=True)
control = [0, 1, 2, 3, 5]
assert_equal(sorted(test[-1]), control)
assert_equal(test[0], a[test[-1]])
#
test = find_duplicates(a, key='B', return_index=True)
control = [0, 1, 2, 4]
assert_equal(sorted(test[-1]), control)
assert_equal(test[0], a[test[-1]])
#
test = find_duplicates(a, key='BA', return_index=True)
control = [0, 1, 2, 4]
assert_equal(sorted(test[-1]), control)
assert_equal(test[0], a[test[-1]])
#
test = find_duplicates(a, key='BB', return_index=True)
control = [0, 1, 2, 3, 4]
assert_equal(sorted(test[-1]), control)
assert_equal(test[0], a[test[-1]])
def test_find_duplicates_ignoremask(self):
"Test the ignoremask option of find_duplicates"
ndtype = [('a', int)]
a = ma.array([1, 1, 1, 2, 2, 3, 3],
mask=[0, 0, 1, 0, 0, 0, 1]).view(ndtype)
test = find_duplicates(a, ignoremask=True, return_index=True)
control = [0, 1, 3, 4]
assert_equal(sorted(test[-1]), control)
assert_equal(test[0], a[test[-1]])
#
test = find_duplicates(a, ignoremask=False, return_index=True)
control = [0, 1, 2, 3, 4, 6]
assert_equal(sorted(test[-1]), control)
assert_equal(test[0], a[test[-1]])
class TestRecursiveFillFields(TestCase):
"""
Test recursive_fill_fields.
"""
def test_simple_flexible(self):
"Test recursive_fill_fields on flexible-array"
a = np.array([(1, 10.), (2, 20.)], dtype=[('A', int), ('B', float)])
b = np.zeros((3,), dtype=a.dtype)
test = recursive_fill_fields(a, b)
control = np.array([(1, 10.), (2, 20.), (0, 0.)],
dtype=[('A', int), ('B', float)])
assert_equal(test, control)
#
def test_masked_flexible(self):
"Test recursive_fill_fields on masked flexible-array"
a = ma.array([(1, 10.), (2, 20.)], mask=[(0, 1), (1, 0)],
dtype=[('A', int), ('B', float)])
b = ma.zeros((3,), dtype=a.dtype)
test = recursive_fill_fields(a, b)
control = ma.array([(1, 10.), (2, 20.), (0, 0.)],
mask=[(0, 1), (1, 0), (0, 0)],
dtype=[('A', int), ('B', float)])
assert_equal(test, control)
#
class TestMergeArrays(TestCase):
"""
Test merge_arrays
"""
def setUp(self):
x = np.array([1, 2, ])
y = np.array([10, 20, 30])
z = np.array([('A', 1.), ('B', 2.)], dtype=[('A', '|S3'), ('B', float)])
w = np.array([(1, (2, 3.0)), (4, (5, 6.0))],
dtype=[('a', int), ('b', [('ba', float), ('bb', int)])])
self.data = (w, x, y, z)
#
def test_solo(self):
"Test merge_arrays on a single array."
(_, x, _, z) = self.data
#
test = merge_arrays(x)
control = np.array([(1,), (2,)], dtype=[('f0', int)])
assert_equal(test, control)
test = merge_arrays((x,))
assert_equal(test, control)
#
test = merge_arrays(z, flatten=False)
assert_equal(test, z)
test = merge_arrays(z, flatten=True)
assert_equal(test, z)
#
def test_solo_w_flatten(self):
"Test merge_arrays on a single array w & w/o flattening"
w = self.data[0]
test = merge_arrays(w, flatten=False)
assert_equal(test, w)
#
test = merge_arrays(w, flatten=True)
control = np.array([(1, 2, 3.0), (4, 5, 6.0)],
dtype=[('a', int), ('ba', float), ('bb', int)])
assert_equal(test, control)
#
def test_standard(self):
"Test standard & standard"
# Test merge arrays
(_, x, y, _) = self.data
test = merge_arrays((x, y), usemask=False)
control = np.array([(1, 10), (2, 20), (-1, 30)],
dtype=[('f0', int), ('f1', int)])
assert_equal(test, control)
#
test = merge_arrays((x, y), usemask=True)
control = ma.array([(1, 10), (2, 20), (-1, 30)],
mask=[(0, 0), (0, 0), (1, 0)],
dtype=[('f0', int), ('f1', int)])
assert_equal(test, control)
assert_equal(test.mask, control.mask)
#
def test_flatten(self):
"Test standard & flexible"
(_, x, _, z) = self.data
test = merge_arrays((x, z), flatten=True)
control = np.array([(1, 'A', 1.), (2, 'B', 2.)],
dtype=[('f0', int), ('A', '|S3'), ('B', float)])
assert_equal(test, control)
#
test = merge_arrays((x, z), flatten=False)
control = np.array([(1, ('A', 1.)), (2, ('B', 2.))],
dtype=[('f0', int),
('f1', [('A', '|S3'), ('B', float)])])
assert_equal(test, control)
#
def test_flatten_wflexible(self):
"Test flatten standard & nested"
(w, x, _, _) = self.data
test = merge_arrays((x, w), flatten=True)
control = np.array([(1, 1, 2, 3.0), (2, 4, 5, 6.0)],
dtype=[('f0', int),
('a', int), ('ba', float), ('bb', int)])
assert_equal(test, control)
#
test = merge_arrays((x, w), flatten=False)
controldtype = dtype = [('f0', int),
('f1', [('a', int),
('b', [('ba', float), ('bb', int)])])]
control = np.array([(1., (1, (2, 3.0))), (2, (4, (5, 6.0)))],
dtype=controldtype)
#
def test_wmasked_arrays(self):
"Test merge_arrays masked arrays"
(_, x, _, _) = self.data
mx = ma.array([1, 2, 3], mask=[1, 0, 0])
test = merge_arrays((x, mx), usemask=True)
control = ma.array([(1, 1), (2, 2), (-1, 3)],
mask=[(0, 1), (0, 0), (1, 0)],
dtype=[('f0', int), ('f1', int)])
assert_equal(test, control)
test = merge_arrays((x, mx), usemask=True, asrecarray=True)
assert_equal(test, control)
assert(isinstance(test, MaskedRecords))
#
def test_w_singlefield(self):
"Test single field"
test = merge_arrays((np.array([1, 2]).view([('a', int)]),
np.array([10., 20., 30.])),)
control = ma.array([(1, 10.), (2, 20.), (-1, 30.)],
mask=[(0, 0), (0, 0), (1, 0)],
dtype=[('a', int), ('f1', float)])
assert_equal(test, control)
#
def test_w_shorter_flex(self):
"Test merge_arrays w/ a shorter flexndarray."
z = self.data[-1]
test = merge_arrays((z, np.array([10, 20, 30]).view([('C', int)])))
control = np.array([('A', 1., 10), ('B', 2., 20), ('-1', -1, 20)],
dtype=[('A', '|S3'), ('B', float), ('C', int)])
#
def test_singlerecord(self):
(_, x, y, z) = self.data
test = merge_arrays((x[0], y[0], z[0]), usemask=False)
control = np.array([(1, 10, ('A', 1))],
dtype=[('f0', int),
('f1', int),
('f2', [('A', '|S3'), ('B', float)])])
assert_equal(test, control)
class TestAppendFields(TestCase):
"""
Test append_fields
"""
def setUp(self):
x = np.array([1, 2, ])
y = np.array([10, 20, 30])
z = np.array([('A', 1.), ('B', 2.)], dtype=[('A', '|S3'), ('B', float)])
w = np.array([(1, (2, 3.0)), (4, (5, 6.0))],
dtype=[('a', int), ('b', [('ba', float), ('bb', int)])])
self.data = (w, x, y, z)
#
def test_append_single(self):
"Test simple case"
(_, x, _, _) = self.data
test = append_fields(x, 'A', data=[10, 20, 30])
control = ma.array([(1, 10), (2, 20), (-1, 30)],
mask=[(0, 0), (0, 0), (1, 0)],
dtype=[('f0', int), ('A', int)],)
assert_equal(test, control)
#
def test_append_double(self):
"Test simple case"
(_, x, _, _) = self.data
test = append_fields(x, ('A', 'B'), data=[[10, 20, 30], [100, 200]])
control = ma.array([(1, 10, 100), (2, 20, 200), (-1, 30, -1)],
mask=[(0, 0, 0), (0, 0, 0), (1, 0, 1)],
dtype=[('f0', int), ('A', int), ('B', int)],)
assert_equal(test, control)
#
def test_append_on_flex(self):
"Test append_fields on flexible type arrays"
z = self.data[-1]
test = append_fields(z, 'C', data=[10, 20, 30])
control = ma.array([('A', 1., 10), ('B', 2., 20), (-1, -1., 30)],
mask=[(0, 0, 0), (0, 0, 0), (1, 1, 0)],
dtype=[('A', '|S3'), ('B', float), ('C', int)],)
assert_equal(test, control)
#
def test_append_on_nested(self):
"Test append_fields on nested fields"
w = self.data[0]
test = append_fields(w, 'C', data=[10, 20, 30])
control = ma.array([(1, (2, 3.0), 10),
(4, (5, 6.0), 20),
(-1, (-1, -1.), 30)],
mask=[(0, (0, 0), 0), (0, (0, 0), 0), (1, (1, 1), 0)],
dtype=[('a', int),
('b', [('ba', float), ('bb', int)]),
('C', int)],)
assert_equal(test, control)
class TestStackArrays(TestCase):
"""
Test stack_arrays
"""
def setUp(self):
x = np.array([1, 2, ])
y = np.array([10, 20, 30])
z = np.array([('A', 1.), ('B', 2.)], dtype=[('A', '|S3'), ('B', float)])
w = np.array([(1, (2, 3.0)), (4, (5, 6.0))],
dtype=[('a', int), ('b', [('ba', float), ('bb', int)])])
self.data = (w, x, y, z)
#
def test_solo(self):
"Test stack_arrays on single arrays"
(_, x, _, _) = self.data
test = stack_arrays((x,))
assert_equal(test, x)
self.assertTrue(test is x)
#
test = stack_arrays(x)
assert_equal(test, x)
self.assertTrue(test is x)
#
def test_unnamed_fields(self):
"Tests combinations of arrays w/o named fields"
(_, x, y, _) = self.data
#
test = stack_arrays((x, x), usemask=False)
control = np.array([1, 2, 1, 2])
assert_equal(test, control)
#
test = stack_arrays((x, y), usemask=False)
control = np.array([1, 2, 10, 20, 30])
assert_equal(test, control)
#
test = stack_arrays((y, x), usemask=False)
control = np.array([10, 20, 30, 1, 2])
assert_equal(test, control)
#
def test_unnamed_and_named_fields(self):
"Test combination of arrays w/ & w/o named fields"
(_, x, _, z) = self.data
#
test = stack_arrays((x, z))
control = ma.array([(1, -1, -1), (2, -1, -1),
(-1, 'A', 1), (-1, 'B', 2)],
mask=[(0, 1, 1), (0, 1, 1),
(1, 0, 0), (1, 0, 0)],
dtype=[('f0', int), ('A', '|S3'), ('B', float)])
assert_equal(test, control)
assert_equal(test.mask, control.mask)
#
test = stack_arrays((z, x))
control = ma.array([('A', 1, -1), ('B', 2, -1),
(-1, -1, 1), (-1, -1, 2), ],
mask=[(0, 0, 1), (0, 0, 1),
(1, 1, 0), (1, 1, 0)],
dtype=[('A', '|S3'), ('B', float), ('f2', int)])
assert_equal(test, control)
assert_equal(test.mask, control.mask)
#
test = stack_arrays((z, z, x))
control = ma.array([('A', 1, -1), ('B', 2, -1),
('A', 1, -1), ('B', 2, -1),
(-1, -1, 1), (-1, -1, 2), ],
mask=[(0, 0, 1), (0, 0, 1),
(0, 0, 1), (0, 0, 1),
(1, 1, 0), (1, 1, 0)],
dtype=[('A', '|S3'), ('B', float), ('f2', int)])
assert_equal(test, control)
#
def test_matching_named_fields(self):
"Test combination of arrays w/ matching field names"
(_, x, _, z) = self.data
zz = np.array([('a', 10., 100.), ('b', 20., 200.), ('c', 30., 300.)],
dtype=[('A', '|S3'), ('B', float), ('C', float)])
test = stack_arrays((z, zz))
control = ma.array([('A', 1, -1), ('B', 2, -1),
('a', 10., 100.), ('b', 20., 200.), ('c', 30., 300.)],
dtype=[('A', '|S3'), ('B', float), ('C', float)],
mask=[(0, 0, 1), (0, 0, 1),
(0, 0, 0), (0, 0, 0), (0, 0, 0)])
assert_equal(test, control)
assert_equal(test.mask, control.mask)
#
test = stack_arrays((z, zz, x))
ndtype = [('A', '|S3'), ('B', float), ('C', float), ('f3', int)]
control = ma.array([('A', 1, -1, -1), ('B', 2, -1, -1),
('a', 10., 100., -1), ('b', 20., 200., -1),
('c', 30., 300., -1),
(-1, -1, -1, 1), (-1, -1, -1, 2)],
dtype=ndtype,
mask=[(0, 0, 1, 1), (0, 0, 1, 1),
(0, 0, 0, 1), (0, 0, 0, 1), (0, 0, 0, 1),
(1, 1, 1, 0), (1, 1, 1, 0)])
assert_equal(test, control)
assert_equal(test.mask, control.mask)
def test_defaults(self):
"Test defaults: no exception raised if keys of defaults are not fields."
(_, _, _, z) = self.data
zz = np.array([('a', 10., 100.), ('b', 20., 200.), ('c', 30., 300.)],
dtype=[('A', '|S3'), ('B', float), ('C', float)])
defaults = {'A':'???', 'B':-999., 'C':-9999., 'D':-99999.}
test = stack_arrays((z, zz), defaults=defaults)
control = ma.array([('A', 1, -9999.), ('B', 2, -9999.),
('a', 10., 100.), ('b', 20., 200.), ('c', 30., 300.)],
dtype=[('A', '|S3'), ('B', float), ('C', float)],
mask=[(0, 0, 1), (0, 0, 1),
(0, 0, 0), (0, 0, 0), (0, 0, 0)])
assert_equal(test, control)
assert_equal(test.data, control.data)
assert_equal(test.mask, control.mask)
def test_autoconversion(self):
"Tests autoconversion"
adtype = [('A', int), ('B', bool), ('C', float)]
a = ma.array([(1, 2, 3)], mask=[(0, 1, 0)], dtype=adtype)
bdtype = [('A', int), ('B', float), ('C', float)]
b = ma.array([(4, 5, 6)], dtype=bdtype)
control = ma.array([(1, 2, 3), (4, 5, 6)], mask=[(0, 1, 0), (0, 0, 0)],
dtype=bdtype)
test = stack_arrays((a, b), autoconvert=True)
assert_equal(test, control)
assert_equal(test.mask, control.mask)
try:
test = stack_arrays((a, b), autoconvert=False)
except TypeError:
pass
else:
raise AssertionError
def test_checktitles(self):
"Test using titles in the field names"
adtype = [(('a', 'A'), int), (('b', 'B'), bool), (('c', 'C'), float)]
a = ma.array([(1, 2, 3)], mask=[(0, 1, 0)], dtype=adtype)
bdtype = [(('a', 'A'), int), (('b', 'B'), bool), (('c', 'C'), float)]
b = ma.array([(4, 5, 6)], dtype=bdtype)
test = stack_arrays((a, b))
control = ma.array([(1, 2, 3), (4, 5, 6)], mask=[(0, 1, 0), (0, 0, 0)],
dtype=bdtype)
assert_equal(test, control)
assert_equal(test.mask, control.mask)
class TestJoinBy(TestCase):
def setUp(self):
self.a = np.array(zip(np.arange(10), np.arange(50, 60),
np.arange(100, 110)),
dtype=[('a', int), ('b', int), ('c', int)])
self.b = np.array(zip(np.arange(5, 15), np.arange(65, 75),
np.arange(100, 110)),
dtype=[('a', int), ('b', int), ('d', int)])
#
def test_inner_join(self):
"Basic test of join_by"
a, b = self.a, self.b
#
test = join_by('a', a, b, jointype='inner')
control = np.array([(5, 55, 65, 105, 100), (6, 56, 66, 106, 101),
(7, 57, 67, 107, 102), (8, 58, 68, 108, 103),
(9, 59, 69, 109, 104)],
dtype=[('a', int), ('b1', int), ('b2', int),
('c', int), ('d', int)])
assert_equal(test, control)
def test_join(self):
a, b = self.a, self.b
#
test = join_by(('a', 'b'), a, b)
control = np.array([(5, 55, 105, 100), (6, 56, 106, 101),
(7, 57, 107, 102), (8, 58, 108, 103),
(9, 59, 109, 104)],
dtype=[('a', int), ('b', int),
('c', int), ('d', int)])
def test_outer_join(self):
a, b = self.a, self.b
#
test = join_by(('a', 'b'), a, b, 'outer')
control = ma.array([(0, 50, 100, -1), (1, 51, 101, -1),
(2, 52, 102, -1), (3, 53, 103, -1),
(4, 54, 104, -1), (5, 55, 105, -1),
(5, 65, -1, 100), (6, 56, 106, -1),
(6, 66, -1, 101), (7, 57, 107, -1),
(7, 67, -1, 102), (8, 58, 108, -1),
(8, 68, -1, 103), (9, 59, 109, -1),
(9, 69, -1, 104), (10, 70, -1, 105),
(11, 71, -1, 106), (12, 72, -1, 107),
(13, 73, -1, 108), (14, 74, -1, 109)],
mask=[(0, 0, 0, 1), (0, 0, 0, 1),
(0, 0, 0, 1), (0, 0, 0, 1),
(0, 0, 0, 1), (0, 0, 0, 1),
(0, 0, 1, 0), (0, 0, 0, 1),
(0, 0, 1, 0), (0, 0, 0, 1),
(0, 0, 1, 0), (0, 0, 0, 1),
(0, 0, 1, 0), (0, 0, 0, 1),
(0, 0, 1, 0), (0, 0, 1, 0),
(0, 0, 1, 0), (0, 0, 1, 0),
(0, 0, 1, 0), (0, 0, 1, 0)],
dtype=[('a', int), ('b', int),
('c', int), ('d', int)])
assert_equal(test, control)
def test_leftouter_join(self):
a, b = self.a, self.b
#
test = join_by(('a', 'b'), a, b, 'leftouter')
control = ma.array([(0, 50, 100, -1), (1, 51, 101, -1),
(2, 52, 102, -1), (3, 53, 103, -1),
(4, 54, 104, -1), (5, 55, 105, -1),
(6, 56, 106, -1), (7, 57, 107, -1),
(8, 58, 108, -1), (9, 59, 109, -1)],
mask=[(0, 0, 0, 1), (0, 0, 0, 1),
(0, 0, 0, 1), (0, 0, 0, 1),
(0, 0, 0, 1), (0, 0, 0, 1),
(0, 0, 0, 1), (0, 0, 0, 1),
(0, 0, 0, 1), (0, 0, 0, 1)],
dtype=[('a', int), ('b', int), ('c', int), ('d', int)])
if __name__ == '__main__':
run_module_suite()
|
apache-2.0
|
[
646,
984,
199,
199,
646,
2680,
465,
980,
199,
646,
2680,
14,
391,
465,
610,
199,
504,
2680,
14,
391,
14,
396,
1208,
492,
627,
199,
199,
504,
2680,
14,
391,
14,
77,
6502,
492,
17581,
379,
14941,
199,
199,
504,
2680,
14,
773,
14,
2761,
5777,
492,
627,
199,
362,
63,
1247,
275,
980,
14,
773,
14,
2761,
5777,
14,
362,
63,
1247,
199,
362,
63,
1247,
63,
7088,
275,
980,
14,
773,
14,
2761,
5777,
14,
362,
63,
1247,
63,
7088,
199,
3065,
63,
12113,
275,
980,
14,
773,
14,
2761,
5777,
14,
3065,
63,
12113,
199,
199,
533,
1379,
21561,
13967,
8,
1746,
304,
272,
408,
272,
603,
10840,
2295,
272,
408,
272,
327,
272,
347,
3613,
8,
277,
304,
267,
671,
275,
980,
14,
1144,
779,
17,
12,
499,
12,
4794,
267,
612,
275,
980,
14,
1144,
779,
709,
12,
3388,
12,
4233,
566,
267,
1315,
275,
980,
14,
1144,
8318,
33,
297,
413,
15631,
661,
34,
297,
499,
14,
4360,
2151,
2152,
11699,
33,
297,
11280,
51,
19,
659,
661,
34,
297,
2069,
3948,
267,
336,
275,
980,
14,
1144,
7694,
17,
12,
334,
18,
12,
650,
14,
16,
1826,
334,
20,
12,
334,
21,
12,
1227,
14,
16,
25106,
288,
2152,
11699,
65,
297,
1109,
395,
661,
66,
297,
4274,
2470,
297,
2069,
395,
661,
2501,
297,
1109,
3948,
566,
267,
291,
14,
576,
275,
334,
87,
12,
671,
12,
612,
12,
1315,
9,
2378,
347,
511,
63,
3065,
63,
12113,
8,
277,
304,
267,
298,
774,
3482,
63,
12113,
2,
267,
334,
87,
12,
671,
12,
612,
12,
1315,
9,
275,
291,
14,
576,
267,
327,
20992,
1625,
267,
511,
275,
3482,
63,
12113,
1332,
88,
12,
671,
395,
9378,
29,
549,
9,
267,
702,
63,
1452,
8,
396,
12,
2151,
980,
14,
2271,
8318,
297,
1109,
395,
13134,
1109,
19563,
267,
511,
275,
3482,
63,
12113,
1332,
88,
12,
671,
395,
9378,
29,
797,
9,
267,
702,
63,
1452,
8,
396,
12,
2151,
980,
14,
2271,
8318,
297,
1109,
395,
13134,
1109,
19563,
267,
327,
20992,
1253,
26841,
13,
2271,
4960,
511,
275,
3482,
63,
12113,
1332,
88,
12,
1315,
395,
9378,
29,
549,
9,
267,
702,
63,
1452,
8,
396,
12,
2151,
980,
14,
2271,
8318,
297,
1109,
395,
661,
33,
297,
11280,
51,
19,
659,
661,
34,
297,
2069,
19563,
267,
511,
275,
3482,
63,
12113,
1332,
88,
12,
1315,
395,
9378,
29,
797,
9,
267,
702,
63,
1452,
8,
396,
12,
2151,
980,
14,
2271,
8318,
297,
1109,
395,
3044,
13134,
4274,
33,
297,
11280,
51,
19,
659,
661,
34,
297,
2069,
3948,
2459,
267,
327,
9739,
1253,
6032,
2152,
4960,
511,
275,
3482,
63,
12113,
1332,
88,
12,
336,
395,
9378,
29,
549,
9,
267,
702,
63,
1452,
8,
396,
12,
2151,
980,
14,
2271,
8318,
297,
1109,
395,
3044,
661,
65,
297,
1109,
395,
3044,
661,
2470,
297,
2069,
395,
661,
2501,
297,
1109,
19563,
267,
511,
275,
3482,
63,
12113,
1332,
88,
12,
336,
395,
9378,
29,
797,
9,
267,
702,
63,
1452,
8,
396,
12,
2151,
980,
14,
2271,
8318,
297,
1109,
395,
3044,
13134,
4274,
65,
297,
1109,
395,
3660,
661,
66,
297,
4274,
2470,
297,
2069,
395,
661,
2501,
297,
1109,
3948,
566,
2459,
2378,
347,
511,
63,
4824,
63,
955,
8,
277,
304,
267,
298,
774,
5978,
63,
955,
2,
267,
282,
275,
980,
14,
1144,
7694,
17,
12,
334,
18,
12,
650,
14,
16,
1826,
334,
20,
12,
334,
21,
12,
1227,
14,
16,
25106,
2151,
2152,
11699,
65,
297,
1109,
395,
661,
66,
297,
4274,
2470,
297,
2069,
395,
661,
2501,
297,
1109,
3948,
566,
267,
327,
437,
5678,
901,
267,
511,
275,
5978,
63,
955,
8,
65,
12,
283,
65,
358,
267,
3304,
275,
980,
14,
1144,
779,
1332,
18,
12,
650,
14,
16,
30148,
3666,
21,
12,
1227,
14,
16,
395,
4360,
2151,
2152,
11699,
66,
297,
4274,
2470,
297,
2069,
395,
661,
2501,
297,
1109,
3948,
566,
267,
702,
63,
1452,
8,
396,
12,
3304,
9,
267,
327,
22604,
5678,
901,
334,
7911,
19500,
2877,
1504,
9,
267,
511,
275,
5978,
63,
955,
8,
65,
12,
283,
66,
358,
267,
3304,
275,
980,
14,
1144,
7694,
17,
4706,
334,
20,
32444,
2152,
11699,
65,
297,
1109,
3948,
267,
702,
63,
1452,
8,
396,
12,
3304,
9,
267,
327,
437,
6032,
1007,
13,
698,
267,
511,
275,
5978,
63,
955,
8,
65,
12,
788,
2470,
297,
4794,
267,
3304,
275,
980,
14,
1144,
7694,
17,
12,
334,
19,
14,
16,
16965,
334,
20,
12,
334,
22,
14,
16,
4641,
467,
2151,
2152,
11699,
65,
297,
1109,
395,
661,
66,
297,
4274,
2501,
297,
1109,
3948,
566,
267,
702,
63,
1452,
8,
396,
12,
3304,
9,
267,
327,
2900,
314,
6032,
1007,
13,
698,
687,
282,
901,
26,
1315,
439,
626,
901,
267,
511,
275,
5978,
63,
955,
8,
65,
12,
788,
2470,
297,
283,
2501,
1105,
267,
3304,
275,
980,
14,
1144,
7694,
17,
4706,
334,
20,
32444,
2152,
11699,
65,
297,
1109,
3948,
267,
702,
63,
1452,
8,
396,
12,
3304,
9,
267,
327,
267,
511,
275,
5978,
63,
955,
8,
65,
12,
788,
65,
297,
283,
66,
1105,
267,
702,
8,
396,
365,
488,
9,
2378,
347,
511,
63,
8165,
63,
955,
8,
277,
304,
267,
298,
2925,
11441,
1504,
2,
267,
282,
275,
980,
14,
1144,
7694,
17,
12,
334,
18,
12,
359,
19,
14,
16,
12,
4233,
14,
12884,
334,
20,
12,
334,
21,
12,
359,
22,
14,
16,
12,
5212,
14,
2459,
467,
2151,
2152,
11699,
65,
297,
1109,
395,
1169,
661,
66,
297,
4274,
2470,
297,
2069,
395,
661,
2501,
297,
334,
1609,
12,
499,
18229,
566,
267,
511,
275,
11441,
63,
955,
8,
65,
12,
791,
65,
5242,
33,
297,
283,
2501,
5242,
5342,
3071,
267,
892,
2271,
275,
4274,
33,
297,
1109,
395,
661,
66,
297,
4274,
2470,
297,
2069,
395,
661,
5342,
297,
334,
1609,
12,
499,
430,
12457,
267,
3304,
275,
282,
14,
1345,
8,
1222,
2271,
9,
267,
702,
63,
1452,
8,
396,
14,
2271,
12,
892,
2271,
9,
267,
702,
63,
1452,
8,
396,
12,
3304,
9,
2378,
347,
511
] |
[
984,
199,
199,
646,
2680,
465,
980,
199,
646,
2680,
14,
391,
465,
610,
199,
504,
2680,
14,
391,
14,
396,
1208,
492,
627,
199,
199,
504,
2680,
14,
391,
14,
77,
6502,
492,
17581,
379,
14941,
199,
199,
504,
2680,
14,
773,
14,
2761,
5777,
492,
627,
199,
362,
63,
1247,
275,
980,
14,
773,
14,
2761,
5777,
14,
362,
63,
1247,
199,
362,
63,
1247,
63,
7088,
275,
980,
14,
773,
14,
2761,
5777,
14,
362,
63,
1247,
63,
7088,
199,
3065,
63,
12113,
275,
980,
14,
773,
14,
2761,
5777,
14,
3065,
63,
12113,
199,
199,
533,
1379,
21561,
13967,
8,
1746,
304,
272,
408,
272,
603,
10840,
2295,
272,
408,
272,
327,
272,
347,
3613,
8,
277,
304,
267,
671,
275,
980,
14,
1144,
779,
17,
12,
499,
12,
4794,
267,
612,
275,
980,
14,
1144,
779,
709,
12,
3388,
12,
4233,
566,
267,
1315,
275,
980,
14,
1144,
8318,
33,
297,
413,
15631,
661,
34,
297,
499,
14,
4360,
2151,
2152,
11699,
33,
297,
11280,
51,
19,
659,
661,
34,
297,
2069,
3948,
267,
336,
275,
980,
14,
1144,
7694,
17,
12,
334,
18,
12,
650,
14,
16,
1826,
334,
20,
12,
334,
21,
12,
1227,
14,
16,
25106,
288,
2152,
11699,
65,
297,
1109,
395,
661,
66,
297,
4274,
2470,
297,
2069,
395,
661,
2501,
297,
1109,
3948,
566,
267,
291,
14,
576,
275,
334,
87,
12,
671,
12,
612,
12,
1315,
9,
2378,
347,
511,
63,
3065,
63,
12113,
8,
277,
304,
267,
298,
774,
3482,
63,
12113,
2,
267,
334,
87,
12,
671,
12,
612,
12,
1315,
9,
275,
291,
14,
576,
267,
327,
20992,
1625,
267,
511,
275,
3482,
63,
12113,
1332,
88,
12,
671,
395,
9378,
29,
549,
9,
267,
702,
63,
1452,
8,
396,
12,
2151,
980,
14,
2271,
8318,
297,
1109,
395,
13134,
1109,
19563,
267,
511,
275,
3482,
63,
12113,
1332,
88,
12,
671,
395,
9378,
29,
797,
9,
267,
702,
63,
1452,
8,
396,
12,
2151,
980,
14,
2271,
8318,
297,
1109,
395,
13134,
1109,
19563,
267,
327,
20992,
1253,
26841,
13,
2271,
4960,
511,
275,
3482,
63,
12113,
1332,
88,
12,
1315,
395,
9378,
29,
549,
9,
267,
702,
63,
1452,
8,
396,
12,
2151,
980,
14,
2271,
8318,
297,
1109,
395,
661,
33,
297,
11280,
51,
19,
659,
661,
34,
297,
2069,
19563,
267,
511,
275,
3482,
63,
12113,
1332,
88,
12,
1315,
395,
9378,
29,
797,
9,
267,
702,
63,
1452,
8,
396,
12,
2151,
980,
14,
2271,
8318,
297,
1109,
395,
3044,
13134,
4274,
33,
297,
11280,
51,
19,
659,
661,
34,
297,
2069,
3948,
2459,
267,
327,
9739,
1253,
6032,
2152,
4960,
511,
275,
3482,
63,
12113,
1332,
88,
12,
336,
395,
9378,
29,
549,
9,
267,
702,
63,
1452,
8,
396,
12,
2151,
980,
14,
2271,
8318,
297,
1109,
395,
3044,
661,
65,
297,
1109,
395,
3044,
661,
2470,
297,
2069,
395,
661,
2501,
297,
1109,
19563,
267,
511,
275,
3482,
63,
12113,
1332,
88,
12,
336,
395,
9378,
29,
797,
9,
267,
702,
63,
1452,
8,
396,
12,
2151,
980,
14,
2271,
8318,
297,
1109,
395,
3044,
13134,
4274,
65,
297,
1109,
395,
3660,
661,
66,
297,
4274,
2470,
297,
2069,
395,
661,
2501,
297,
1109,
3948,
566,
2459,
2378,
347,
511,
63,
4824,
63,
955,
8,
277,
304,
267,
298,
774,
5978,
63,
955,
2,
267,
282,
275,
980,
14,
1144,
7694,
17,
12,
334,
18,
12,
650,
14,
16,
1826,
334,
20,
12,
334,
21,
12,
1227,
14,
16,
25106,
2151,
2152,
11699,
65,
297,
1109,
395,
661,
66,
297,
4274,
2470,
297,
2069,
395,
661,
2501,
297,
1109,
3948,
566,
267,
327,
437,
5678,
901,
267,
511,
275,
5978,
63,
955,
8,
65,
12,
283,
65,
358,
267,
3304,
275,
980,
14,
1144,
779,
1332,
18,
12,
650,
14,
16,
30148,
3666,
21,
12,
1227,
14,
16,
395,
4360,
2151,
2152,
11699,
66,
297,
4274,
2470,
297,
2069,
395,
661,
2501,
297,
1109,
3948,
566,
267,
702,
63,
1452,
8,
396,
12,
3304,
9,
267,
327,
22604,
5678,
901,
334,
7911,
19500,
2877,
1504,
9,
267,
511,
275,
5978,
63,
955,
8,
65,
12,
283,
66,
358,
267,
3304,
275,
980,
14,
1144,
7694,
17,
4706,
334,
20,
32444,
2152,
11699,
65,
297,
1109,
3948,
267,
702,
63,
1452,
8,
396,
12,
3304,
9,
267,
327,
437,
6032,
1007,
13,
698,
267,
511,
275,
5978,
63,
955,
8,
65,
12,
788,
2470,
297,
4794,
267,
3304,
275,
980,
14,
1144,
7694,
17,
12,
334,
19,
14,
16,
16965,
334,
20,
12,
334,
22,
14,
16,
4641,
467,
2151,
2152,
11699,
65,
297,
1109,
395,
661,
66,
297,
4274,
2501,
297,
1109,
3948,
566,
267,
702,
63,
1452,
8,
396,
12,
3304,
9,
267,
327,
2900,
314,
6032,
1007,
13,
698,
687,
282,
901,
26,
1315,
439,
626,
901,
267,
511,
275,
5978,
63,
955,
8,
65,
12,
788,
2470,
297,
283,
2501,
1105,
267,
3304,
275,
980,
14,
1144,
7694,
17,
4706,
334,
20,
32444,
2152,
11699,
65,
297,
1109,
3948,
267,
702,
63,
1452,
8,
396,
12,
3304,
9,
267,
327,
267,
511,
275,
5978,
63,
955,
8,
65,
12,
788,
65,
297,
283,
66,
1105,
267,
702,
8,
396,
365,
488,
9,
2378,
347,
511,
63,
8165,
63,
955,
8,
277,
304,
267,
298,
2925,
11441,
1504,
2,
267,
282,
275,
980,
14,
1144,
7694,
17,
12,
334,
18,
12,
359,
19,
14,
16,
12,
4233,
14,
12884,
334,
20,
12,
334,
21,
12,
359,
22,
14,
16,
12,
5212,
14,
2459,
467,
2151,
2152,
11699,
65,
297,
1109,
395,
1169,
661,
66,
297,
4274,
2470,
297,
2069,
395,
661,
2501,
297,
334,
1609,
12,
499,
18229,
566,
267,
511,
275,
11441,
63,
955,
8,
65,
12,
791,
65,
5242,
33,
297,
283,
2501,
5242,
5342,
3071,
267,
892,
2271,
275,
4274,
33,
297,
1109,
395,
661,
66,
297,
4274,
2470,
297,
2069,
395,
661,
5342,
297,
334,
1609,
12,
499,
430,
12457,
267,
3304,
275,
282,
14,
1345,
8,
1222,
2271,
9,
267,
702,
63,
1452,
8,
396,
14,
2271,
12,
892,
2271,
9,
267,
702,
63,
1452,
8,
396,
12,
3304,
9,
2378,
347,
511,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
CapOM/ChromiumGStreamerBackend
|
tools/git/for-all-touched-files.py
|
68
|
4374
|
#!/usr/bin/env python
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Invokes the specified (quoted) command for all files modified
between the current git branch and the specified branch or commit.
The special token [[FILENAME]] (or whatever you choose using the -t
flag) is replaced with each of the filenames of new or modified files.
Deleted files are not included. Neither are untracked files.
Synopsis:
%prog [-b BRANCH] [-d] [-x EXTENSIONS|-c|-g] [-t TOKEN] QUOTED_COMMAND
Examples:
%prog -x gyp,gypi "tools/format_xml.py [[FILENAME]]"
%prog -c "tools/sort-headers.py [[FILENAME]]"
%prog -g "tools/sort_sources.py [[FILENAME]]"
%prog -t "~~BINGO~~" "echo I modified ~~BINGO~~"
"""
import optparse
import os
import subprocess
import sys
# List of C++-like source file extensions.
_CPP_EXTENSIONS = ('h', 'hh', 'hpp', 'c', 'cc', 'cpp', 'cxx', 'mm',)
# List of build file extensions.
_BUILD_EXTENSIONS = ('gyp', 'gypi', 'gn',)
def GitShell(args, ignore_return=False):
"""A shell invocation suitable for communicating with git. Returns
output as list of lines, raises exception on error.
"""
job = subprocess.Popen(args,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
(out, err) = job.communicate()
if job.returncode != 0 and not ignore_return:
print out
raise Exception("Error %d running command %s" % (
job.returncode, args))
return out.split('\n')
def FilenamesFromGit(branch_name, extensions):
"""Provides a list of all new and modified files listed by [git diff
branch_name] where branch_name can be blank to get a diff of the
workspace.
Excludes deleted files.
If extensions is not an empty list, include only files with one of
the extensions on the list.
"""
lines = GitShell('git diff --stat=600,500 %s' % branch_name)
filenames = []
for line in lines:
line = line.lstrip()
# Avoid summary line, and files that have been deleted (no plus).
if line.find('|') != -1 and line.find('+') != -1:
filename = line.split()[0]
if filename:
filename = filename.rstrip()
ext = filename.rsplit('.')[-1]
if not extensions or ext in extensions:
filenames.append(filename)
return filenames
def ForAllTouchedFiles(branch_name, extensions, token, command):
"""For each new or modified file output by [git diff branch_name],
run command with token replaced with the filename. If extensions is
not empty, do this only for files with one of the extensions in that
list.
"""
filenames = FilenamesFromGit(branch_name, extensions)
for filename in filenames:
os.system(command.replace(token, filename))
def main():
parser = optparse.OptionParser(usage=__doc__)
parser.add_option('-x', '--extensions', default='', dest='extensions',
help='Limits to files with given extensions '
'(comma-separated).')
parser.add_option('-c', '--cpp', default=False, action='store_true',
dest='cpp_only',
help='Runs your command only on C++-like source files.')
# -g stands for GYP and GN.
parser.add_option('-g', '--build', default=False, action='store_true',
dest='build_only',
help='Runs your command only on build files.')
parser.add_option('-t', '--token', default='[[FILENAME]]', dest='token',
help='Sets the token to be replaced for each file '
'in your command (default [[FILENAME]]).')
parser.add_option('-b', '--branch', default='origin/master', dest='branch',
help='Sets what to diff to (default origin/master). Set '
'to empty to diff workspace against HEAD.')
opts, args = parser.parse_args()
if not args:
parser.print_help()
sys.exit(1)
if opts.cpp_only and opts.build_only:
parser.error("--cpp and --build are mutually exclusive")
extensions = opts.extensions
if opts.cpp_only:
extensions = _CPP_EXTENSIONS
if opts.build_only:
extensions = _BUILD_EXTENSIONS
ForAllTouchedFiles(opts.branch, extensions, opts.token, args[0])
if __name__ == '__main__':
main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
7760,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
523,
30110,
22652,
314,
2013,
334,
9888,
9,
1414,
367,
1006,
1584,
6042,
523,
3382,
314,
1453,
6135,
5246,
436,
314,
2013,
5246,
503,
5532,
14,
819,
710,
4539,
1526,
3474,
15440,
2677,
334,
269,
15685,
1265,
11496,
1808,
314,
446,
84,
523,
3305,
9,
365,
8717,
543,
1924,
402,
314,
6203,
402,
892,
503,
6042,
1584,
14,
819,
1487,
3496,
1584,
787,
440,
5120,
14,
221,
11443,
787,
625,
22586,
1584,
14,
199,
199,
17746,
27573,
26,
523,
450,
6595,
5243,
66,
11713,
20139,
61,
5243,
68,
61,
5243,
88,
20203,
17427,
28447,
67,
28447,
71,
61,
5243,
84,
18243,
61,
11364,
1149,
63,
10761,
199,
199,
22787,
26,
523,
450,
6595,
446,
88,
4902,
12,
4312,
1038,
298,
2537,
15,
908,
63,
1652,
14,
647,
3474,
15440,
2677,
2,
523,
450,
6595,
446,
67,
298,
2537,
15,
3191,
13,
2139,
14,
647,
3474,
15440,
2677,
2,
523,
450,
6595,
446,
71,
298,
2537,
15,
3191,
63,
4553,
14,
647,
3474,
15440,
2677,
2,
523,
450,
6595,
446,
84,
298,
1714,
34,
1206,
47,
1714,
2,
298,
7878,
473,
6042,
221,
1714,
34,
1206,
47,
1714,
2,
199,
624,
199,
199,
646,
8691,
199,
646,
747,
199,
646,
3873,
199,
646,
984,
421,
199,
3,
3820,
402,
445,
4176,
13,
2930,
1350,
570,
5478,
14,
199,
63,
14533,
63,
18451,
275,
661,
72,
297,
283,
12156,
297,
283,
72,
802,
297,
283,
67,
297,
283,
2055,
297,
283,
5910,
297,
283,
9634,
297,
283,
596,
9538,
199,
3,
3820,
402,
1900,
570,
5478,
14,
199,
63,
8248,
63,
18451,
275,
661,
6179,
297,
283,
4312,
1038,
297,
283,
784,
9538,
421,
199,
318,
12579,
8529,
8,
589,
12,
3686,
63,
1107,
29,
797,
304,
523,
408,
33,
5218,
19569,
11233,
367,
13882,
1958,
543,
6135,
14,
1803,
523,
1072,
465,
769,
402,
2385,
12,
6534,
1919,
641,
1125,
14,
523,
408,
523,
3906,
275,
3873,
14,
7942,
8,
589,
12,
586,
5218,
29,
549,
12,
586,
3839,
29,
5781,
14,
6089,
12,
586,
4635,
29,
5781,
14,
13850,
9,
523,
334,
548,
12,
2329,
9,
275,
3906,
14,
10664,
342,
523,
340,
3906,
14,
9913,
1137,
378,
436,
440,
3686,
63,
1107,
26,
272,
870,
734,
272,
746,
2186,
480,
547,
450,
68,
3879,
1414,
450,
83,
2,
450,
334,
267,
3906,
14,
9913,
12,
1249,
430,
523,
372,
734,
14,
1294,
2258,
78,
358,
421,
199,
318,
3814,
1247,
2532,
14686,
8,
4694,
63,
354,
12,
5478,
304,
523,
408,
17473,
282,
769,
402,
1006,
892,
436,
6042,
1584,
10532,
701,
359,
3187,
3915,
523,
5246,
63,
354,
61,
2382,
5246,
63,
354,
883,
506,
4596,
370,
664,
282,
3915,
402,
314,
523,
14466,
14,
819,
28554,
83,
5463,
1584,
14,
819,
982,
5478,
365,
440,
376,
2701,
769,
12,
2387,
1454,
1584,
543,
1373,
402,
523,
314,
5478,
641,
314,
769,
14,
523,
408,
523,
2385,
275,
12579,
8529,
360,
3187,
3915,
1553,
3736,
29,
6683,
12,
5783,
450,
83,
7,
450,
5246,
63,
354,
9,
523,
6203,
275,
942,
523,
367,
1004,
315,
2385,
26,
272,
1004,
275,
1004,
14,
10124,
342,
272,
327,
19503,
6212,
1004,
12,
436,
1584,
626,
1172,
2757,
5463,
334,
889,
12254,
680,
272,
340,
1004,
14,
1623,
20137,
358,
1137,
446,
17,
436,
1004,
14,
1623,
360,
13854,
1137,
446,
17,
26,
489,
1788,
275,
1004,
14,
1294,
3430,
16,
61,
489,
340,
1788,
26,
267,
1788,
275,
1788,
14,
6735,
342,
267,
1599,
275,
1788,
14,
13490,
29084,
17,
61,
267,
340,
440,
5478,
503,
1599,
315,
5478,
26,
881,
6203,
14,
740,
8,
1501,
9,
523,
372,
6203,
421,
199,
318,
2104,
2422,
52,
810,
1809,
5535,
8,
4694,
63,
354,
12,
5478,
12,
1526,
12,
1414,
304,
523,
408,
1858,
1924,
892,
503,
6042,
570,
1072,
701,
359,
3187,
3915,
5246,
63,
354,
467,
523,
1255,
1414,
543,
1526,
8717,
543,
314,
1788,
14,
982,
5478,
365,
523,
440,
2701,
12,
886,
642,
1454,
367,
1584,
543,
1373,
402,
314,
5478,
315,
626,
523,
769,
14,
523,
408,
523,
6203,
275,
3814,
1247,
2532,
14686,
8,
4694,
63,
354,
12,
5478,
9,
523,
367,
1788,
315,
6203,
26,
272,
747,
14,
2253,
8,
1531,
14,
1814,
8,
1418,
12,
1788,
430,
421,
199,
318,
2446,
837,
523,
1798,
275,
8691,
14,
14553,
8,
3807,
18971,
1301,
3368,
523,
1798,
14,
525,
63,
1422,
3654,
88,
297,
2850,
5359,
297,
849,
4581,
2053,
534,
5359,
297,
490,
1720,
534,
24480,
370,
1584,
543,
1627,
5478,
283,
490,
8189,
13184,
13,
12794,
28583,
523,
1798,
14,
525,
63,
1422,
3654,
67,
297,
2850,
5910,
297,
849,
29,
797,
12,
1595,
534,
1617,
63,
2052,
297,
490,
2053,
534,
5910,
63,
2118,
297,
490,
1720,
534,
16291,
2195,
1414,
1454,
641,
445,
4176,
13,
2930,
1350,
1584,
2659,
523,
327,
446,
71,
410,
5915,
367,
25686,
436,
27650,
14,
523,
1798,
14,
525,
63,
1422,
3654,
71,
297,
2850,
1506,
297,
849,
29,
797,
12,
1595,
534,
1617,
63,
2052,
297,
490,
2053,
534,
1506,
63,
2118,
297,
490,
1720,
534,
16291,
2195,
1414,
1454,
641,
1900,
1584,
2659,
523,
1798,
14,
525,
63,
1422,
3654,
84,
297,
2850,
1418,
297,
849,
534,
9046,
15440,
2677,
297,
2053,
534,
1418,
297,
490,
1720,
534,
9899,
314,
1526,
370,
506,
8717,
367,
1924,
570,
283,
490,
283,
262,
2195,
1414,
334,
885,
3474,
15440,
3934,
2659,
523,
1798,
14,
525,
63,
1422,
3654,
66,
297,
2850,
4694,
297,
849,
534,
6493,
15,
4133,
297,
2053,
534,
4694,
297,
490,
1720,
534,
9899,
4052,
370,
3915,
370,
334,
885,
6330,
15,
4133,
680,
2494,
283,
490,
283,
475,
2701,
370,
3915,
14466,
6169,
13053,
2659,
523,
3999,
12,
1249,
275,
1798,
14,
1122,
63,
589,
342,
819,
340,
440,
1249,
26,
272,
1798,
14,
1361,
63,
3437,
342,
272,
984,
14,
2224,
8,
17,
9
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
7760,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
523,
30110,
22652,
314,
2013,
334,
9888,
9,
1414,
367,
1006,
1584,
6042,
523,
3382,
314,
1453,
6135,
5246,
436,
314,
2013,
5246,
503,
5532,
14,
819,
710,
4539,
1526,
3474,
15440,
2677,
334,
269,
15685,
1265,
11496,
1808,
314,
446,
84,
523,
3305,
9,
365,
8717,
543,
1924,
402,
314,
6203,
402,
892,
503,
6042,
1584,
14,
819,
1487,
3496,
1584,
787,
440,
5120,
14,
221,
11443,
787,
625,
22586,
1584,
14,
199,
199,
17746,
27573,
26,
523,
450,
6595,
5243,
66,
11713,
20139,
61,
5243,
68,
61,
5243,
88,
20203,
17427,
28447,
67,
28447,
71,
61,
5243,
84,
18243,
61,
11364,
1149,
63,
10761,
199,
199,
22787,
26,
523,
450,
6595,
446,
88,
4902,
12,
4312,
1038,
298,
2537,
15,
908,
63,
1652,
14,
647,
3474,
15440,
2677,
2,
523,
450,
6595,
446,
67,
298,
2537,
15,
3191,
13,
2139,
14,
647,
3474,
15440,
2677,
2,
523,
450,
6595,
446,
71,
298,
2537,
15,
3191,
63,
4553,
14,
647,
3474,
15440,
2677,
2,
523,
450,
6595,
446,
84,
298,
1714,
34,
1206,
47,
1714,
2,
298,
7878,
473,
6042,
221,
1714,
34,
1206,
47,
1714,
2,
199,
624,
199,
199,
646,
8691,
199,
646,
747,
199,
646,
3873,
199,
646,
984,
421,
199,
3,
3820,
402,
445,
4176,
13,
2930,
1350,
570,
5478,
14,
199,
63,
14533,
63,
18451,
275,
661,
72,
297,
283,
12156,
297,
283,
72,
802,
297,
283,
67,
297,
283,
2055,
297,
283,
5910,
297,
283,
9634,
297,
283,
596,
9538,
199,
3,
3820,
402,
1900,
570,
5478,
14,
199,
63,
8248,
63,
18451,
275,
661,
6179,
297,
283,
4312,
1038,
297,
283,
784,
9538,
421,
199,
318,
12579,
8529,
8,
589,
12,
3686,
63,
1107,
29,
797,
304,
523,
408,
33,
5218,
19569,
11233,
367,
13882,
1958,
543,
6135,
14,
1803,
523,
1072,
465,
769,
402,
2385,
12,
6534,
1919,
641,
1125,
14,
523,
408,
523,
3906,
275,
3873,
14,
7942,
8,
589,
12,
586,
5218,
29,
549,
12,
586,
3839,
29,
5781,
14,
6089,
12,
586,
4635,
29,
5781,
14,
13850,
9,
523,
334,
548,
12,
2329,
9,
275,
3906,
14,
10664,
342,
523,
340,
3906,
14,
9913,
1137,
378,
436,
440,
3686,
63,
1107,
26,
272,
870,
734,
272,
746,
2186,
480,
547,
450,
68,
3879,
1414,
450,
83,
2,
450,
334,
267,
3906,
14,
9913,
12,
1249,
430,
523,
372,
734,
14,
1294,
2258,
78,
358,
421,
199,
318,
3814,
1247,
2532,
14686,
8,
4694,
63,
354,
12,
5478,
304,
523,
408,
17473,
282,
769,
402,
1006,
892,
436,
6042,
1584,
10532,
701,
359,
3187,
3915,
523,
5246,
63,
354,
61,
2382,
5246,
63,
354,
883,
506,
4596,
370,
664,
282,
3915,
402,
314,
523,
14466,
14,
819,
28554,
83,
5463,
1584,
14,
819,
982,
5478,
365,
440,
376,
2701,
769,
12,
2387,
1454,
1584,
543,
1373,
402,
523,
314,
5478,
641,
314,
769,
14,
523,
408,
523,
2385,
275,
12579,
8529,
360,
3187,
3915,
1553,
3736,
29,
6683,
12,
5783,
450,
83,
7,
450,
5246,
63,
354,
9,
523,
6203,
275,
942,
523,
367,
1004,
315,
2385,
26,
272,
1004,
275,
1004,
14,
10124,
342,
272,
327,
19503,
6212,
1004,
12,
436,
1584,
626,
1172,
2757,
5463,
334,
889,
12254,
680,
272,
340,
1004,
14,
1623,
20137,
358,
1137,
446,
17,
436,
1004,
14,
1623,
360,
13854,
1137,
446,
17,
26,
489,
1788,
275,
1004,
14,
1294,
3430,
16,
61,
489,
340,
1788,
26,
267,
1788,
275,
1788,
14,
6735,
342,
267,
1599,
275,
1788,
14,
13490,
29084,
17,
61,
267,
340,
440,
5478,
503,
1599,
315,
5478,
26,
881,
6203,
14,
740,
8,
1501,
9,
523,
372,
6203,
421,
199,
318,
2104,
2422,
52,
810,
1809,
5535,
8,
4694,
63,
354,
12,
5478,
12,
1526,
12,
1414,
304,
523,
408,
1858,
1924,
892,
503,
6042,
570,
1072,
701,
359,
3187,
3915,
5246,
63,
354,
467,
523,
1255,
1414,
543,
1526,
8717,
543,
314,
1788,
14,
982,
5478,
365,
523,
440,
2701,
12,
886,
642,
1454,
367,
1584,
543,
1373,
402,
314,
5478,
315,
626,
523,
769,
14,
523,
408,
523,
6203,
275,
3814,
1247,
2532,
14686,
8,
4694,
63,
354,
12,
5478,
9,
523,
367,
1788,
315,
6203,
26,
272,
747,
14,
2253,
8,
1531,
14,
1814,
8,
1418,
12,
1788,
430,
421,
199,
318,
2446,
837,
523,
1798,
275,
8691,
14,
14553,
8,
3807,
18971,
1301,
3368,
523,
1798,
14,
525,
63,
1422,
3654,
88,
297,
2850,
5359,
297,
849,
4581,
2053,
534,
5359,
297,
490,
1720,
534,
24480,
370,
1584,
543,
1627,
5478,
283,
490,
8189,
13184,
13,
12794,
28583,
523,
1798,
14,
525,
63,
1422,
3654,
67,
297,
2850,
5910,
297,
849,
29,
797,
12,
1595,
534,
1617,
63,
2052,
297,
490,
2053,
534,
5910,
63,
2118,
297,
490,
1720,
534,
16291,
2195,
1414,
1454,
641,
445,
4176,
13,
2930,
1350,
1584,
2659,
523,
327,
446,
71,
410,
5915,
367,
25686,
436,
27650,
14,
523,
1798,
14,
525,
63,
1422,
3654,
71,
297,
2850,
1506,
297,
849,
29,
797,
12,
1595,
534,
1617,
63,
2052,
297,
490,
2053,
534,
1506,
63,
2118,
297,
490,
1720,
534,
16291,
2195,
1414,
1454,
641,
1900,
1584,
2659,
523,
1798,
14,
525,
63,
1422,
3654,
84,
297,
2850,
1418,
297,
849,
534,
9046,
15440,
2677,
297,
2053,
534,
1418,
297,
490,
1720,
534,
9899,
314,
1526,
370,
506,
8717,
367,
1924,
570,
283,
490,
283,
262,
2195,
1414,
334,
885,
3474,
15440,
3934,
2659,
523,
1798,
14,
525,
63,
1422,
3654,
66,
297,
2850,
4694,
297,
849,
534,
6493,
15,
4133,
297,
2053,
534,
4694,
297,
490,
1720,
534,
9899,
4052,
370,
3915,
370,
334,
885,
6330,
15,
4133,
680,
2494,
283,
490,
283,
475,
2701,
370,
3915,
14466,
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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
] |
Grirrane/odoo
|
addons/portal/mail_thread.py
|
390
|
2004
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013-TODAY OpenERP S.A (<http://www.openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import SUPERUSER_ID
from openerp.osv import osv
class mail_thread(osv.AbstractModel):
""" Update of mail_mail class, to add the signin URL to notifications. """
_inherit = 'mail.thread'
def _get_inbox_action_xml_id(self, cr, uid, context=None):
""" For a given message, return an action that either
- opens the form view of the related document if model, res_id, and
read access to the document
- opens the Inbox with a default search on the conversation if model,
res_id
- opens the Inbox with context propagated
"""
cur_user = self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context=context)
# if uid is a portal user -> action is different
if any(group.is_portal for group in cur_user.groups_id):
return ('portal', 'action_mail_inbox_feeds_portal')
else:
return super(mail_thread, self)._get_inbox_action_xml_id(cr, uid, context=context)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
6171,
13,
2566,
11655,
7653,
428,
14,
33,
8642,
1014,
921,
1544,
14,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
492,
12824,
63,
998,
199,
504,
5166,
14,
4795,
492,
9506,
421,
199,
533,
6016,
63,
2671,
8,
4795,
14,
8458,
1685,
304,
272,
408,
6162,
402,
6016,
63,
1198,
1021,
12,
370,
1050,
314,
2070,
262,
2851,
370,
13116,
14,
408,
272,
485,
6486,
275,
283,
1198,
14,
2671,
7,
339,
347,
485,
362,
63,
27515,
63,
1287,
63,
1652,
63,
344,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
408,
2104,
282,
1627,
1245,
12,
372,
376,
1595,
626,
1902,
288,
446,
30848,
314,
1824,
2455,
402,
314,
4048,
2213,
340,
1402,
12,
522,
63,
344,
12,
436,
1598,
1586,
2879,
370,
314,
2213,
288,
446,
30848,
314,
1010,
1977,
543,
282,
849,
2754,
641,
314,
3818,
20592,
340,
1402,
12,
1598,
522,
63,
344,
288,
446,
30848,
314,
1010,
1977,
543,
1067,
25350,
267,
408,
267,
1094,
63,
751,
275,
291,
14,
2293,
14,
362,
360,
470,
14,
3707,
1959,
4570,
8,
1556,
12,
12824,
63,
998,
12,
1747,
12,
1067,
29,
1100,
9,
267,
327,
340,
1747,
365,
282,
18428,
922,
1035,
1595,
365,
3365,
267,
340,
1263,
8,
923,
14,
374,
63,
8707,
367,
1572,
315,
1094,
63,
751,
14,
2634,
63,
344,
304,
288,
372,
661,
8707,
297,
283,
1287,
63,
1198,
63,
27515,
63,
11522,
63,
8707,
358,
267,
587,
26,
288,
372,
1613,
8,
1198,
63,
2671,
12,
291,
10445,
362,
63,
27515,
63,
1287,
63,
1652,
63,
344,
8,
1556,
12,
1747,
12,
1067,
29,
1100,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
6171,
13,
2566,
11655,
7653,
428,
14,
33,
8642,
1014,
921,
1544,
14,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
492,
12824,
63,
998,
199,
504,
5166,
14,
4795,
492,
9506,
421,
199,
533,
6016,
63,
2671,
8,
4795,
14,
8458,
1685,
304,
272,
408,
6162,
402,
6016,
63,
1198,
1021,
12,
370,
1050,
314,
2070,
262,
2851,
370,
13116,
14,
408,
272,
485,
6486,
275,
283,
1198,
14,
2671,
7,
339,
347,
485,
362,
63,
27515,
63,
1287,
63,
1652,
63,
344,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
408,
2104,
282,
1627,
1245,
12,
372,
376,
1595,
626,
1902,
288,
446,
30848,
314,
1824,
2455,
402,
314,
4048,
2213,
340,
1402,
12,
522,
63,
344,
12,
436,
1598,
1586,
2879,
370,
314,
2213,
288,
446,
30848,
314,
1010,
1977,
543,
282,
849,
2754,
641,
314,
3818,
20592,
340,
1402,
12,
1598,
522,
63,
344,
288,
446,
30848,
314,
1010,
1977,
543,
1067,
25350,
267,
408,
267,
1094,
63,
751,
275,
291,
14,
2293,
14,
362,
360,
470,
14,
3707,
1959,
4570,
8,
1556,
12,
12824,
63,
998,
12,
1747,
12,
1067,
29,
1100,
9,
267,
327,
340,
1747,
365,
282,
18428,
922,
1035,
1595,
365,
3365,
267,
340,
1263,
8,
923,
14,
374,
63,
8707,
367,
1572,
315,
1094,
63,
751,
14,
2634,
63,
344,
304,
288,
372,
661,
8707,
297,
283,
1287,
63,
1198,
63,
27515,
63,
11522,
63,
8707,
358,
267,
587,
26,
288,
372,
1613,
8,
1198,
63,
2671,
12,
291,
10445,
362,
63,
27515,
63,
1287,
63,
1652,
63,
344,
8,
1556,
12,
1747,
12,
1067,
29,
1100,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Jason-Zhao-Jie/MagicTower
|
Assets/Firebase/Editor/generate_xml_from_google_services_json.py
|
1
|
13865
|
#!/usr/bin/python
# Copyright 2016 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Stand-alone implementation of the Gradle Firebase plugin.
Converts the services json file to xml:
https://googleplex-android.googlesource.com/platform/tools/base/+/studio-master-dev/build-system/google-services/src/main/groovy/com/google/gms/googleservices
"""
__author__ = 'Wouter van Oortmerssen'
import argparse
import json
import os
import sys
from xml.etree import ElementTree
# Input filename if it isn't set.
DEFAULT_INPUT_FILENAME = 'app/google-services.json'
# Output filename if it isn't set.
DEFAULT_OUTPUT_FILENAME = 'res/values/googleservices.xml'
# Input filename for .plist files, if it isn't set.
DEFAULT_PLIST_INPUT_FILENAME = 'GoogleService-Info.plist'
# Output filename for .json files, if it isn't set.
DEFAULT_JSON_OUTPUT_FILENAME = 'google-services-desktop.json'
# Indicates a web client in the oauth_client list.
OAUTH_CLIENT_TYPE_WEB = 3
def read_xml_value(xml_node):
"""Utility method for reading values from the plist XML.
Args:
xml_node: An ElementTree node, that contains a value.
Returns:
The value of the node, or None, if it could not be read.
"""
if xml_node.tag == 'string':
return xml_node.text
elif xml_node.tag == 'integer':
return int(xml_node.text)
elif xml_node.tag == 'real':
return float(xml_node.text)
elif xml_node.tag == 'false':
return 0
elif xml_node.tag == 'true':
return 1
else:
# other types of input are ignored. (data, dates, arrays, etc.)
return None
def construct_plist_dictionary(xml_root):
"""Constructs a dictionary of values based on the contents of a plist file.
Args:
xml_root: An ElementTree node, that represents the root of the xml file
that is to be parsed. (Which should be a dictionary containing
key-value pairs of the properties that need to be extracted.)
Returns:
A dictionary, containing key-value pairs for all (supported) entries in the
node.
"""
xml_dict = xml_root.find('dict')
if xml_dict is None:
return None
plist_dict = {}
i = 0
while i < len(xml_dict):
if xml_dict[i].tag == 'key':
key = xml_dict[i].text
i += 1
if i < len(xml_dict):
value = read_xml_value(xml_dict[i])
if value is not None:
plist_dict[key] = value
i += 1
return plist_dict
def construct_google_services_json(xml_dict):
"""Constructs a google services json file from a dictionary.
Args:
xml_dict: A dictionary of all the key/value pairs that are needed for the
output json file.
Returns:
A string representing the output json file.
"""
try:
json_struct = {
'project_info': {
'project_number': xml_dict['GCM_SENDER_ID'],
'firebase_url': xml_dict['DATABASE_URL'],
'project_id': xml_dict['PROJECT_ID'],
'storage_bucket': xml_dict['STORAGE_BUCKET']
},
'client': [{
'client_info': {
'mobilesdk_app_id': xml_dict['GOOGLE_APP_ID'],
'android_client_info': {
'package_name': xml_dict['BUNDLE_ID']
}
},
'oauth_client': [{
'client_id': xml_dict['CLIENT_ID'],
}],
'api_key': [{
'current_key': xml_dict['API_KEY']
}],
'services': {
'analytics_service': {
'status': xml_dict['IS_ANALYTICS_ENABLED']
},
'appinvite_service': {
'status': xml_dict['IS_APPINVITE_ENABLED']
}
}
},],
'configuration_version':
'1'
}
return json.dumps(json_struct, indent=2)
except KeyError as e:
sys.stderr.write('Could not find key in plist file: [%s]\n' % (e.args[0]))
return None
def convert_plist_to_json(plist_string, input_filename):
"""Converts an input plist string into a .json file and saves it.
Args:
plist_string: The contents of the loaded plist file.
input_filename: The file name that the plist data was read from.
Returns:
the converted string, or None if there were errors.
"""
try:
root = ElementTree.fromstring(plist_string)
except ElementTree.ParseError:
sys.stderr.write('Error parsing file %s.\n'
'It does not appear to be valid XML.\n' % (input_filename))
return None
plist_dict = construct_plist_dictionary(root)
if plist_dict is None:
sys.stderr.write('In file %s, could not locate a top-level \'dict\' '
'element.\n'
'File format should be plist XML, with a top-level '
'dictionary containing project settings as key-value '
'pairs.\n' % (input_filename))
return None
json_string = construct_google_services_json(plist_dict)
return json_string
def gen_string(parent, name, text):
"""Generate one <string /> element and put into the list of keeps.
Args:
parent: The object that will hold the string.
name: The name to store the string under.
text: The text of the string.
"""
if text:
prev = parent.get('tools:keep', '')
if prev:
prev += ','
parent.set('tools:keep', prev + '@string/' + name)
child = ElementTree.SubElement(parent, 'string', {
'name': name,
'translatable': 'false'
})
child.text = text
def indent(elem, level=0):
"""Recurse through XML tree and add indentation.
Args:
elem: The element to recurse over
level: The current indentation level.
"""
i = '\n' + level*' '
if elem is not None:
if not elem.text or not elem.text.strip():
elem.text = i + ' '
if not elem.tail or not elem.tail.strip():
elem.tail = i
for elem in elem:
indent(elem, level+1)
if not elem.tail or not elem.tail.strip():
elem.tail = i
else:
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i
def main():
parser = argparse.ArgumentParser(
description=((
'Converts a Firebase %s into %s similar to the Gradle plugin, or '
'converts a Firebase %s into a %s suitible for use on desktop apps.' %
(DEFAULT_INPUT_FILENAME, DEFAULT_OUTPUT_FILENAME,
DEFAULT_PLIST_INPUT_FILENAME, DEFAULT_JSON_OUTPUT_FILENAME))))
parser.add_argument('-i', help='Override input file name',
metavar='FILE', required=False)
parser.add_argument('-o', help='Override destination file name',
metavar='FILE', required=False)
parser.add_argument('-p', help=('Package ID to select within the set of '
'packages in the input file. If this is '
'not specified, the first package in the '
'input file is selected.'))
parser.add_argument('-l', help=('List all package IDs referenced by the '
'input file. If this is specified, '
'the output file is not created.'),
action='store_true', default=False, required=False)
parser.add_argument('-f', help=('Print project fields from the input file '
'in the form \'name=value\\n\' for each '
'field. If this is specified, the output '
'is not created.'),
action='store_true', default=False, required=False)
parser.add_argument(
'--plist',
help=(
'Specifies a plist file to convert to a JSON configuration file. '
'If this is enabled, the script will expect a .plist file as input, '
'which it will convert into %s file. The output file is '
'*not* suitable for use with Firebase on Android.' %
(DEFAULT_JSON_OUTPUT_FILENAME)),
action='store_true',
default=False,
required=False)
args = parser.parse_args()
if args.plist:
input_filename = DEFAULT_PLIST_INPUT_FILENAME
output_filename = DEFAULT_JSON_OUTPUT_FILENAME
else:
input_filename = DEFAULT_INPUT_FILENAME
output_filename = DEFAULT_OUTPUT_FILENAME
if args.i:
input_filename = args.i
if args.o:
output_filename = args.o
with open(input_filename, 'r') as ifile:
file_string = ifile.read()
json_string = None
if args.plist:
json_string = convert_plist_to_json(file_string, input_filename)
if json_string is None:
return 1
jsobj = json.loads(json_string)
else:
jsobj = json.loads(file_string)
root = ElementTree.Element('resources')
root.set('xmlns:tools', 'http://schemas.android.com/tools')
project_info = jsobj.get('project_info')
if project_info:
gen_string(root, 'firebase_database_url', project_info.get('firebase_url'))
gen_string(root, 'gcm_defaultSenderId', project_info.get('project_number'))
gen_string(root, 'google_storage_bucket',
project_info.get('storage_bucket'))
gen_string(root, 'project_id', project_info.get('project_id'))
if args.f:
if not project_info:
sys.stderr.write('No project info found in %s.' % input_filename)
return 1
for field, value in project_info.iteritems():
sys.stdout.write('%s=%s\n' % (field, value))
return 0
packages = set()
client_list = jsobj.get('client')
if client_list:
# Search for the user specified package in the file.
selected_package_name = ''
selected_client = client_list[0]
find_package_name = args.p
for client in client_list:
package_name = client.get('client_info', {}).get(
'android_client_info', {}).get('package_name', '')
if not package_name:
package_name = client.get('oauth_client', {}).get(
'android_info', {}).get('package_name', '')
if package_name:
if not selected_package_name:
selected_package_name = package_name
selected_client = client
if package_name == find_package_name:
selected_package_name = package_name
selected_client = client
packages.add(package_name)
if args.p and selected_package_name != find_package_name:
sys.stderr.write('No packages found in %s which match the package '
'name %s\n'
'\n'
'Found the following:\n'
'%s\n' % (input_filename, find_package_name,
'\n'.join(packages)))
return 1
client_api_key = selected_client.get('api_key')
if client_api_key:
client_api_key0 = client_api_key[0]
gen_string(root, 'google_api_key', client_api_key0.get('current_key'))
gen_string(root, 'google_crash_reporting_api_key',
client_api_key0.get('current_key'))
client_info = selected_client.get('client_info')
if client_info:
gen_string(root, 'google_app_id', client_info.get('mobilesdk_app_id'))
oauth_client_list = selected_client.get('oauth_client')
if oauth_client_list:
for oauth_client in oauth_client_list:
client_type = oauth_client.get('client_type')
client_id = oauth_client.get('client_id')
if client_type and client_type == OAUTH_CLIENT_TYPE_WEB and client_id:
gen_string(root, 'default_web_client_id', client_id)
# Only include the first matching OAuth web client ID.
break
services = selected_client.get('services')
if services:
ads_service = services.get('ads_service')
if ads_service:
gen_string(root, 'test_banner_ad_unit_id',
ads_service.get('test_banner_ad_unit_id'))
gen_string(root, 'test_interstitial_ad_unit_id',
ads_service.get('test_interstitial_ad_unit_id'))
analytics_service = services.get('analytics_service')
if analytics_service:
analytics_property = analytics_service.get('analytics_property')
if analytics_property:
gen_string(root, 'ga_trackingId',
analytics_property.get('tracking_id'))
# enable this once we have an example if this service being present
# in the json data:
maps_service_enabled = False
if maps_service_enabled:
maps_service = services.get('maps_service')
if maps_service:
maps_api_key = maps_service.get('api_key')
if maps_api_key:
for k in range(0, len(maps_api_key)):
# generates potentially multiple of these keys, which is
# the same behavior as the java plugin.
gen_string(root, 'google_maps_key',
maps_api_key[k].get('maps_api_key'))
tree = ElementTree.ElementTree(root)
indent(root)
if args.l:
for package in packages:
if package:
sys.stdout.write(package + '\n')
else:
path = os.path.dirname(output_filename)
if path and not os.path.exists(path):
os.makedirs(path)
if not args.plist:
tree.write(output_filename, 'utf-8', True)
else:
with open(output_filename, 'w') as ofile:
ofile.write(json_string)
return 0
if __name__ == '__main__':
sys.exit(main())
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
7800,
4475,
20376,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
18736,
13,
10636,
4514,
402,
314,
10268,
3011,
15967,
1095,
3589,
14,
199,
199,
17729,
314,
8500,
2022,
570,
370,
2748,
26,
199,
2859,
921,
3098,
22198,
13,
6238,
14,
3098,
1365,
14,
957,
15,
3246,
15,
2537,
15,
1095,
15,
19616,
19806,
13,
4133,
13,
2374,
15,
1506,
13,
2253,
15,
3098,
13,
5950,
15,
2164,
15,
973,
15,
23260,
8822,
89,
15,
957,
15,
3098,
15,
71,
706,
15,
3098,
5950,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
55,
7837,
20744,
593,
361,
16465,
2464,
7,
199,
199,
646,
7534,
199,
646,
2022,
199,
646,
747,
199,
646,
984,
199,
504,
2748,
14,
9464,
492,
13139,
199,
199,
3,
6924,
1788,
340,
652,
5712,
1133,
663,
14,
199,
3472,
63,
7321,
63,
15440,
275,
283,
571,
15,
3098,
13,
5950,
14,
1001,
7,
199,
3,
7242,
1788,
340,
652,
5712,
1133,
663,
14,
199,
3472,
63,
8414,
63,
15440,
275,
283,
470,
15,
1459,
15,
3098,
5950,
14,
1652,
7,
199,
3,
6924,
1788,
367,
1275,
10265,
1584,
12,
340,
652,
5712,
1133,
663,
14,
199,
3472,
63,
48,
4924,
63,
7321,
63,
15440,
275,
283,
13266,
3167,
13,
2354,
14,
10265,
7,
199,
3,
7242,
1788,
367,
1275,
1001,
1584,
12,
340,
652,
5712,
1133,
663,
14,
199,
3472,
63,
6243,
63,
8414,
63,
15440,
275,
283,
3098,
13,
5950,
13,
14487,
14,
1001,
7,
199,
199,
3,
19334,
282,
3330,
1890,
315,
314,
9725,
63,
1258,
769,
14,
199,
24041,
63,
9901,
63,
2711,
63,
13166,
275,
650,
421,
199,
318,
1586,
63,
1652,
63,
585,
8,
1652,
63,
932,
304,
523,
408,
17505,
1083,
367,
7664,
1338,
687,
314,
14459,
4692,
14,
819,
3033,
26,
272,
2748,
63,
932,
26,
1626,
13139,
1031,
12,
626,
3509,
282,
574,
14,
819,
1803,
26,
272,
710,
574,
402,
314,
1031,
12,
503,
488,
12,
340,
652,
4293,
440,
506,
1586,
14,
523,
408,
523,
340,
2748,
63,
932,
14,
1450,
508,
283,
875,
356,
272,
372,
2748,
63,
932,
14,
505,
523,
916,
2748,
63,
932,
14,
1450,
508,
283,
4115,
356,
272,
372,
1109,
8,
1652,
63,
932,
14,
505,
9,
523,
916,
2748,
63,
932,
14,
1450,
508,
283,
3093,
356,
272,
372,
2069,
8,
1652,
63,
932,
14,
505,
9,
523,
916,
2748,
63,
932,
14,
1450,
508,
283,
3910,
356,
272,
372,
378,
523,
916,
2748,
63,
932,
14,
1450,
508,
283,
2052,
356,
272,
372,
413,
523,
587,
26,
272,
327,
1163,
2943,
402,
1324,
787,
5525,
14,
221,
334,
576,
12,
10831,
12,
6572,
12,
5423,
4959,
272,
372,
488,
421,
199,
318,
6982,
63,
10265,
63,
9086,
8,
1652,
63,
1231,
304,
523,
408,
27943,
282,
2600,
402,
1338,
4079,
641,
314,
4072,
402,
282,
14459,
570,
14,
819,
3033,
26,
272,
2748,
63,
1231,
26,
1626,
13139,
1031,
12,
626,
8469,
314,
1738,
402,
314,
2748,
570,
1598,
626,
365,
370,
506,
4565,
14,
221,
334,
31619,
1077,
506,
282,
2600,
3035,
1598,
790,
13,
585,
6342,
402,
314,
4382,
626,
1929,
370,
506,
12509,
4959,
819,
1803,
26,
272,
437,
2600,
12,
3035,
790,
13,
585,
6342,
367,
1006,
334,
4946,
9,
4811,
315,
314,
272,
1031,
14,
523,
408,
523,
2748,
63,
807,
275,
2748,
63,
1231,
14,
1623,
360,
807,
358,
819,
340,
2748,
63,
807,
365,
488,
26,
272,
372,
488,
819,
14459,
63,
807,
275,
1052,
523,
284,
275,
378,
523,
1830,
284,
665,
822,
8,
1652,
63,
807,
304,
272,
340,
2748,
63,
807,
59,
73,
1055,
1450,
508,
283,
498,
356,
489,
790,
275,
2748,
63,
807,
59,
73,
1055,
505,
489,
284,
847,
413,
489,
340,
284,
665,
822,
8,
1652,
63,
807,
304,
267,
574,
275,
1586,
63,
1652,
63,
585,
8,
1652,
63,
807,
59,
73,
566,
267,
340,
574,
365,
440,
488,
26,
881,
14459,
63,
807,
59,
498,
61,
275,
574,
272,
284,
847,
413,
819,
372,
14459,
63,
807,
421,
199,
318,
6982,
63,
3098,
63,
5950,
63,
1001,
8,
1652,
63,
807,
304,
523,
408,
27943,
282,
6233,
8500,
2022,
570,
687,
282,
2600,
14,
819,
3033,
26,
272,
2748,
63,
807,
26,
437,
2600,
402,
1006,
314,
790,
15,
585,
6342,
626,
787,
4346,
367,
314,
1598,
1072,
2022,
570,
14,
523,
1803,
26,
272,
437,
1059,
6144,
314,
1072,
2022,
570,
14,
523,
408,
523,
862,
26,
272,
2022,
63,
1820,
275,
469,
267,
283,
1715,
63,
815,
356,
469,
288,
283,
1715,
63,
1955,
356,
2748,
63,
807,
459,
29009,
63,
20469,
540,
63,
998,
995,
288,
283,
8935,
1095,
63,
633,
356,
2748,
63,
807,
459,
17873,
63,
2632,
995,
288,
283,
1715,
63,
344,
356,
2748,
63,
807,
459,
10797,
63,
998,
995,
288,
283,
3494,
63,
4623,
356,
2748,
63,
807,
459,
17467,
63,
20156,
418,
267,
1660,
267,
283,
1258,
356,
8910,
288,
283,
1258,
63,
815,
356,
469,
355,
283,
11375,
9277,
63,
571,
63,
344,
356,
2748,
63,
807,
459,
24243,
63,
7121,
63,
998,
995,
355,
283,
6238,
63,
1258,
63,
815,
356,
469,
490,
283,
2491,
63,
354,
356,
2748,
63,
807,
459,
32044,
906,
63,
998,
418,
355,
789,
288,
1660,
288,
283,
6126,
63,
1258,
356,
8910,
355,
283,
1258,
63,
344,
356,
2748,
63,
807,
459
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
7800,
4475,
20376,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
18736,
13,
10636,
4514,
402,
314,
10268,
3011,
15967,
1095,
3589,
14,
199,
199,
17729,
314,
8500,
2022,
570,
370,
2748,
26,
199,
2859,
921,
3098,
22198,
13,
6238,
14,
3098,
1365,
14,
957,
15,
3246,
15,
2537,
15,
1095,
15,
19616,
19806,
13,
4133,
13,
2374,
15,
1506,
13,
2253,
15,
3098,
13,
5950,
15,
2164,
15,
973,
15,
23260,
8822,
89,
15,
957,
15,
3098,
15,
71,
706,
15,
3098,
5950,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
55,
7837,
20744,
593,
361,
16465,
2464,
7,
199,
199,
646,
7534,
199,
646,
2022,
199,
646,
747,
199,
646,
984,
199,
504,
2748,
14,
9464,
492,
13139,
199,
199,
3,
6924,
1788,
340,
652,
5712,
1133,
663,
14,
199,
3472,
63,
7321,
63,
15440,
275,
283,
571,
15,
3098,
13,
5950,
14,
1001,
7,
199,
3,
7242,
1788,
340,
652,
5712,
1133,
663,
14,
199,
3472,
63,
8414,
63,
15440,
275,
283,
470,
15,
1459,
15,
3098,
5950,
14,
1652,
7,
199,
3,
6924,
1788,
367,
1275,
10265,
1584,
12,
340,
652,
5712,
1133,
663,
14,
199,
3472,
63,
48,
4924,
63,
7321,
63,
15440,
275,
283,
13266,
3167,
13,
2354,
14,
10265,
7,
199,
3,
7242,
1788,
367,
1275,
1001,
1584,
12,
340,
652,
5712,
1133,
663,
14,
199,
3472,
63,
6243,
63,
8414,
63,
15440,
275,
283,
3098,
13,
5950,
13,
14487,
14,
1001,
7,
199,
199,
3,
19334,
282,
3330,
1890,
315,
314,
9725,
63,
1258,
769,
14,
199,
24041,
63,
9901,
63,
2711,
63,
13166,
275,
650,
421,
199,
318,
1586,
63,
1652,
63,
585,
8,
1652,
63,
932,
304,
523,
408,
17505,
1083,
367,
7664,
1338,
687,
314,
14459,
4692,
14,
819,
3033,
26,
272,
2748,
63,
932,
26,
1626,
13139,
1031,
12,
626,
3509,
282,
574,
14,
819,
1803,
26,
272,
710,
574,
402,
314,
1031,
12,
503,
488,
12,
340,
652,
4293,
440,
506,
1586,
14,
523,
408,
523,
340,
2748,
63,
932,
14,
1450,
508,
283,
875,
356,
272,
372,
2748,
63,
932,
14,
505,
523,
916,
2748,
63,
932,
14,
1450,
508,
283,
4115,
356,
272,
372,
1109,
8,
1652,
63,
932,
14,
505,
9,
523,
916,
2748,
63,
932,
14,
1450,
508,
283,
3093,
356,
272,
372,
2069,
8,
1652,
63,
932,
14,
505,
9,
523,
916,
2748,
63,
932,
14,
1450,
508,
283,
3910,
356,
272,
372,
378,
523,
916,
2748,
63,
932,
14,
1450,
508,
283,
2052,
356,
272,
372,
413,
523,
587,
26,
272,
327,
1163,
2943,
402,
1324,
787,
5525,
14,
221,
334,
576,
12,
10831,
12,
6572,
12,
5423,
4959,
272,
372,
488,
421,
199,
318,
6982,
63,
10265,
63,
9086,
8,
1652,
63,
1231,
304,
523,
408,
27943,
282,
2600,
402,
1338,
4079,
641,
314,
4072,
402,
282,
14459,
570,
14,
819,
3033,
26,
272,
2748,
63,
1231,
26,
1626,
13139,
1031,
12,
626,
8469,
314,
1738,
402,
314,
2748,
570,
1598,
626,
365,
370,
506,
4565,
14,
221,
334,
31619,
1077,
506,
282,
2600,
3035,
1598,
790,
13,
585,
6342,
402,
314,
4382,
626,
1929,
370,
506,
12509,
4959,
819,
1803,
26,
272,
437,
2600,
12,
3035,
790,
13,
585,
6342,
367,
1006,
334,
4946,
9,
4811,
315,
314,
272,
1031,
14,
523,
408,
523,
2748,
63,
807,
275,
2748,
63,
1231,
14,
1623,
360,
807,
358,
819,
340,
2748,
63,
807,
365,
488,
26,
272,
372,
488,
819,
14459,
63,
807,
275,
1052,
523,
284,
275,
378,
523,
1830,
284,
665,
822,
8,
1652,
63,
807,
304,
272,
340,
2748,
63,
807,
59,
73,
1055,
1450,
508,
283,
498,
356,
489,
790,
275,
2748,
63,
807,
59,
73,
1055,
505,
489,
284,
847,
413,
489,
340,
284,
665,
822,
8,
1652,
63,
807,
304,
267,
574,
275,
1586,
63,
1652,
63,
585,
8,
1652,
63,
807,
59,
73,
566,
267,
340,
574,
365,
440,
488,
26,
881,
14459,
63,
807,
59,
498,
61,
275,
574,
272,
284,
847,
413,
819,
372,
14459,
63,
807,
421,
199,
318,
6982,
63,
3098,
63,
5950,
63,
1001,
8,
1652,
63,
807,
304,
523,
408,
27943,
282,
6233,
8500,
2022,
570,
687,
282,
2600,
14,
819,
3033,
26,
272,
2748,
63,
807,
26,
437,
2600,
402,
1006,
314,
790,
15,
585,
6342,
626,
787,
4346,
367,
314,
1598,
1072,
2022,
570,
14,
523,
1803,
26,
272,
437,
1059,
6144,
314,
1072,
2022,
570,
14,
523,
408,
523,
862,
26,
272,
2022,
63,
1820,
275,
469,
267,
283,
1715,
63,
815,
356,
469,
288,
283,
1715,
63,
1955,
356,
2748,
63,
807,
459,
29009,
63,
20469,
540,
63,
998,
995,
288,
283,
8935,
1095,
63,
633,
356,
2748,
63,
807,
459,
17873,
63,
2632,
995,
288,
283,
1715,
63,
344,
356,
2748,
63,
807,
459,
10797,
63,
998,
995,
288,
283,
3494,
63,
4623,
356,
2748,
63,
807,
459,
17467,
63,
20156,
418,
267,
1660,
267,
283,
1258,
356,
8910,
288,
283,
1258,
63,
815,
356,
469,
355,
283,
11375,
9277,
63,
571,
63,
344,
356,
2748,
63,
807,
459,
24243,
63,
7121,
63,
998,
995,
355,
283,
6238,
63,
1258,
63,
815,
356,
469,
490,
283,
2491,
63,
354,
356,
2748,
63,
807,
459,
32044,
906,
63,
998,
418,
355,
789,
288,
1660,
288,
283,
6126,
63,
1258,
356,
8910,
355,
283,
1258,
63,
344,
356,
2748,
63,
807,
459,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
leilihh/novaha
|
nova/virt/vmwareapi/imagecache.py
|
4
|
8346
|
# Copyright (c) 2014 VMware, 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.
"""
Image cache class
Images that are stored in the cache folder will be stored in a folder whose
name is the image ID. In the event that an image is discovered to be no longer
used then a timestamp will be added to the image folder.
The timestamp will be a folder - this is due to the fact that we can use the
VMware API's for creating and deleting of folders (it really simplifies
things). The timestamp will contain the time, on the compute node, when the
image was first seen to be unused.
At each aging iteration we check if the image can be aged.
This is done by comparing the current nova compute time to the time embedded
in the timestamp. If the time exceeds the configured aging time then
the parent folder, that is the image ID folder, will be deleted.
That effectivly ages the cached image.
If an image is used then the timestamps will be deleted.
When accessing a timestamp we make use of locking. This ensure that aging
will not delete an image during the spawn operiation. When spawning
the timestamp folder will be locked and the timestamps will be purged.
This will ensure that a image is not deleted during the spawn.
"""
from oslo.config import cfg
from nova.openstack.common.gettextutils import _
from nova.openstack.common import lockutils
from nova.openstack.common import log as logging
from nova.openstack.common import timeutils
from nova.virt import imagecache
from nova.virt.vmwareapi import ds_util
from nova.virt.vmwareapi import error_util
from nova.virt.vmwareapi import vim_util
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
CONF.import_opt('remove_unused_original_minimum_age_seconds',
'nova.virt.imagecache')
TIMESTAMP_PREFIX = 'ts-'
TIMESTAMP_FORMAT = '%Y-%m-%d-%H-%M-%S'
class ImageCacheManager(imagecache.ImageCacheManager):
def __init__(self, session, base_folder):
super(ImageCacheManager, self).__init__()
self._session = session
self._base_folder = base_folder
self._ds_browser = {}
def _folder_delete(self, path, dc_ref):
try:
ds_util.file_delete(self._session, path, dc_ref)
except (error_util.CannotDeleteFileException,
error_util.FileFaultException,
error_util.FileLockedException) as e:
# There may be more than one process or thread that tries
# to delete the file.
LOG.warning(_("Unable to delete %(file)s. Exception: %(ex)s"),
{'file': path, 'ex': e})
except error_util.FileNotFoundException:
LOG.debug(_("File not found: %s"), path)
def timestamp_folder_get(self, ds_path, image_id):
"""Returns the timestamp folder."""
return '%s/%s' % (ds_path, image_id)
def timestamp_cleanup(self, dc_ref, ds_browser,
ds_ref, ds_name, ds_path):
ts = self._get_timestamp(ds_browser, ds_path)
if ts:
ts_path = '%s/%s' % (ds_path, ts)
LOG.debug(_("Timestamp path %s exists. Deleting!"), ts_path)
# Image is used - no longer need timestamp folder
self._folder_delete(ts_path, dc_ref)
def _get_timestamp(self, ds_browser, ds_path):
files = ds_util.get_sub_folders(self._session, ds_browser, ds_path)
if files:
for file in files:
if file.startswith(TIMESTAMP_PREFIX):
return file
def _get_timestamp_filename(self):
return '%s%s' % (TIMESTAMP_PREFIX,
timeutils.strtime(fmt=TIMESTAMP_FORMAT))
def _get_datetime_from_filename(self, timestamp_filename):
ts = timestamp_filename.lstrip(TIMESTAMP_PREFIX)
return timeutils.parse_strtime(ts, fmt=TIMESTAMP_FORMAT)
def _get_ds_browser(self, ds_ref):
ds_browser = self._ds_browser.get(ds_ref.value)
if not ds_browser:
ds_browser = vim_util.get_dynamic_property(
self._session._get_vim(), ds_ref,
"Datastore", "browser")
self._ds_browser[ds_ref.value] = ds_browser
return ds_browser
def _list_datastore_images(self, ds_path, datastore):
"""Return a list of the images present in _base.
This method returns a dictionary with the following keys:
- unexplained_images
- originals
"""
ds_browser = self._get_ds_browser(datastore['ref'])
originals = ds_util.get_sub_folders(self._session, ds_browser,
ds_path)
return {'unexplained_images': [],
'originals': originals}
def _age_cached_images(self, context, datastore, dc_info,
ds_path):
"""Ages cached images."""
age_seconds = CONF.remove_unused_original_minimum_age_seconds
unused_images = self.originals - self.used_images
ds_browser = self._get_ds_browser(datastore['ref'])
for image in unused_images:
path = self.timestamp_folder_get(ds_path, image)
# Lock to ensure that the spawn will not try and access a image
# that is currently being deleted on the datastore.
with lockutils.lock(path, lock_file_prefix='nova-vmware-ts',
external=True):
ts = self._get_timestamp(ds_browser, path)
if not ts:
ts_path = '%s/%s' % (path,
self._get_timestamp_filename())
try:
ds_util.mkdir(self._session, ts_path, dc_info.ref)
except error_util.FileAlreadyExistsException:
LOG.debug(_("Timestamp already exists."))
LOG.info(_("Image %s is no longer used by this node. "
"Pending deletion!"), image)
else:
dt = self._get_datetime_from_filename(ts)
if timeutils.is_older_than(dt, age_seconds):
LOG.info(_("Image %s is no longer used. "
"Deleting!"), path)
# Image has aged - delete the image ID folder
self._folder_delete(path, dc_info.ref)
# If the image is used and the timestamp file exists then we delete
# the timestamp.
for image in self.used_images:
path = self.timestamp_folder_get(ds_path, image)
with lockutils.lock(path, lock_file_prefix='nova-vmware-ts',
external=True):
self.timestamp_cleanup(dc_info.ref, ds_browser,
datastore['ref'], datastore['name'],
path)
def update(self, context, instances, datastores_info):
"""The cache manager entry point.
This will invoke the cache manager. This will update the cache
according to the defined cache management scheme. The information
populated in the cached stats will be used for the cache management.
"""
# read running instances data
running = self._list_running_instances(context, instances)
self.used_images = set(running['used_images'].keys())
# perform the aging and image verification per datastore
for (datastore, dc_info) in datastores_info:
ds_path = ds_util.build_datastore_path(datastore['name'],
self._base_folder)
images = self._list_datastore_images(ds_path, datastore)
self.originals = images['originals']
self._age_cached_images(context, datastore, dc_info, ds_path)
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6927,
27391,
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,
199,
624,
199,
3491,
2581,
1021,
199,
199,
18882,
626,
787,
5489,
315,
314,
2581,
4922,
911,
506,
5489,
315,
282,
4922,
7447,
199,
354,
365,
314,
1834,
2870,
14,
1010,
314,
1566,
626,
376,
1834,
365,
24983,
370,
506,
949,
8088,
199,
2972,
2066,
282,
4913,
911,
506,
3483,
370,
314,
1834,
4922,
14,
199,
1918,
4913,
911,
506,
282,
4922,
446,
642,
365,
7037,
370,
314,
10572,
626,
781,
883,
675,
314,
199,
6849,
1068,
3261,
1159,
367,
6425,
436,
13794,
402,
16533,
334,
390,
7710,
17553,
5604,
199,
25970,
680,
710,
4913,
911,
1395,
314,
900,
12,
641,
314,
4526,
1031,
12,
1380,
314,
199,
1569,
1990,
1642,
6775,
370,
506,
9563,
14,
199,
1271,
1924,
282,
1540,
8494,
781,
1104,
340,
314,
1834,
883,
506,
282,
3046,
14,
199,
2765,
365,
4224,
701,
20234,
314,
1453,
5913,
4526,
900,
370,
314,
900,
12169,
199,
262,
314,
4913,
14,
982,
314,
900,
22338,
314,
7526,
282,
1540,
900,
2066,
199,
1589,
1676,
4922,
12,
626,
365,
314,
1834,
2870,
4922,
12,
911,
506,
5463,
14,
199,
17231,
10783,
825,
280,
86,
590,
282,
3389,
314,
6328,
1834,
14,
199,
3917,
376,
1834,
365,
1202,
2066,
314,
22496,
911,
506,
5463,
14,
199,
199,
11423,
18549,
282,
4913,
781,
1852,
675,
402,
27267,
14,
961,
4868,
626,
282,
1540,
199,
14117,
440,
3145,
376,
1834,
5309,
314,
15187,
1758,
73,
425,
14,
3979,
5844,
87,
1835,
199,
1589,
4913,
4922,
911,
506,
14233,
221,
436,
314,
22496,
911,
506,
5861,
3046,
14,
199,
2765,
911,
4868,
626,
282,
1834,
365,
440,
5463,
5309,
314,
15187,
14,
199,
624,
199,
199,
504,
11258,
14,
888,
492,
4810,
199,
199,
504,
5913,
14,
8512,
14,
2330,
14,
5152,
1208,
492,
485,
199,
504,
5913,
14,
8512,
14,
2330,
492,
4650,
1208,
199,
504,
5913,
14,
8512,
14,
2330,
492,
943,
465,
2050,
199,
504,
5913,
14,
8512,
14,
2330,
492,
23011,
199,
504,
5913,
14,
4549,
492,
1834,
1637,
199,
504,
5913,
14,
4549,
14,
18970,
1246,
492,
6364,
63,
1974,
199,
504,
5913,
14,
4549,
14,
18970,
1246,
492,
1125,
63,
1974,
199,
504,
5913,
14,
4549,
14,
18970,
1246,
492,
6695,
63,
1974,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
646,
63,
2992,
360,
2168,
63,
8618,
63,
5043,
63,
10700,
63,
474,
63,
4515,
297,
355,
283,
6765,
14,
4549,
14,
1569,
1637,
358,
199,
199,
20277,
63,
6351,
275,
283,
1086,
15668,
199,
20277,
63,
4807,
275,
1543,
57,
3295,
77,
3295,
68,
3295,
40,
3295,
45,
3295,
51,
7,
421,
199,
533,
6047,
4437,
2988,
8,
1569,
1637,
14,
3491,
4437,
2988,
304,
272,
347,
636,
826,
721,
277,
12,
2351,
12,
1300,
63,
3741,
304,
267,
1613,
8,
3491,
4437,
2988,
12,
291,
2843,
826,
4533,
267,
291,
423,
1730,
275,
2351,
267,
291,
423,
1095,
63,
3741,
275,
1300,
63,
3741,
267,
291,
423,
795,
63,
5750,
275,
1052,
339,
347,
485,
3741,
63,
1807,
8,
277,
12,
931,
12,
12326,
63,
1121,
304,
267,
862,
26,
288,
6364,
63,
1974,
14,
493,
63,
1807,
8,
277,
423,
1730,
12,
931,
12,
12326,
63,
1121,
9,
267,
871,
334,
705,
63,
1974,
14,
6612,
5392,
1173,
1726,
12,
355,
1125,
63,
1974,
14,
1173,
16665,
1726,
12,
355,
1125,
63,
1974,
14,
1173,
22408,
1726,
9,
465,
325,
26,
288,
327,
6006,
1443,
506,
1655,
2419,
1373,
2112,
503,
2462,
626,
11275,
288,
327,
370,
3145,
314,
570,
14,
288,
5051,
14,
3764,
6115,
6005,
370,
3145,
2818,
493,
9,
83,
14,
2186,
26,
2818,
476,
9,
83,
1288,
717,
791,
493,
356,
931,
12,
283,
476,
356,
325,
1552,
267,
871,
1125,
63,
1974,
14,
1173,
22646,
26,
288,
5051,
14,
1757,
6115,
1173,
440,
1911,
26,
450,
83,
1288,
931,
9,
339,
347,
4913,
63,
3741,
63,
362,
8,
277,
12,
6364,
63,
515,
12,
1834,
63,
344,
304,
267,
408,
3407,
314,
4913,
4922,
1041,
267,
372,
1543,
83,
3149,
83,
7,
450,
334,
795,
63,
515,
12,
1834,
63,
344,
9,
339,
347,
4913,
63,
7661,
8,
277,
12,
12326,
63,
1121,
12,
6364,
63,
5750,
12,
2079,
6364,
63,
1121,
12,
6364,
63,
354,
12,
6364,
63,
515,
304,
267,
6714,
275,
291,
423,
362,
63,
3954,
8,
795,
63,
5750,
12,
6364,
63,
515,
9,
267,
340,
6714,
26,
288,
6714,
63,
515,
275,
1543,
83,
3149,
83,
7,
450,
334,
795,
63,
515,
12,
6714,
9,
288,
5051,
14,
1757,
6115,
10239,
931,
450,
83,
3495,
14,
15920,
1,
1288,
6714,
63,
515,
9,
288,
327,
6047,
365,
1202,
446,
949,
8088,
1929,
4913,
4922,
288,
291,
423,
3741,
63,
1807,
8,
1086,
63,
515,
12,
12326,
63,
1121,
9,
339,
347,
485,
362,
63,
3954,
8,
277,
12,
6364,
63,
5750,
12,
6364,
63,
515,
304,
267,
1584,
275,
6364,
63,
1974,
14,
362,
63,
954,
63,
15171,
8,
277,
423,
1730,
12,
6364,
63,
5750,
12,
6364,
63,
515,
9,
267,
340,
1584,
26,
288,
367,
570,
315,
1584,
26,
355,
340,
570,
14,
2460,
8,
20277,
63,
6351,
304,
490,
372,
570,
339,
347,
485,
362,
63,
3954,
63,
1501,
8,
277,
304,
267
] |
[
1898,
334,
67,
9,
6927,
27391,
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,
199,
624,
199,
3491,
2581,
1021,
199,
199,
18882,
626,
787,
5489,
315,
314,
2581,
4922,
911,
506,
5489,
315,
282,
4922,
7447,
199,
354,
365,
314,
1834,
2870,
14,
1010,
314,
1566,
626,
376,
1834,
365,
24983,
370,
506,
949,
8088,
199,
2972,
2066,
282,
4913,
911,
506,
3483,
370,
314,
1834,
4922,
14,
199,
1918,
4913,
911,
506,
282,
4922,
446,
642,
365,
7037,
370,
314,
10572,
626,
781,
883,
675,
314,
199,
6849,
1068,
3261,
1159,
367,
6425,
436,
13794,
402,
16533,
334,
390,
7710,
17553,
5604,
199,
25970,
680,
710,
4913,
911,
1395,
314,
900,
12,
641,
314,
4526,
1031,
12,
1380,
314,
199,
1569,
1990,
1642,
6775,
370,
506,
9563,
14,
199,
1271,
1924,
282,
1540,
8494,
781,
1104,
340,
314,
1834,
883,
506,
282,
3046,
14,
199,
2765,
365,
4224,
701,
20234,
314,
1453,
5913,
4526,
900,
370,
314,
900,
12169,
199,
262,
314,
4913,
14,
982,
314,
900,
22338,
314,
7526,
282,
1540,
900,
2066,
199,
1589,
1676,
4922,
12,
626,
365,
314,
1834,
2870,
4922,
12,
911,
506,
5463,
14,
199,
17231,
10783,
825,
280,
86,
590,
282,
3389,
314,
6328,
1834,
14,
199,
3917,
376,
1834,
365,
1202,
2066,
314,
22496,
911,
506,
5463,
14,
199,
199,
11423,
18549,
282,
4913,
781,
1852,
675,
402,
27267,
14,
961,
4868,
626,
282,
1540,
199,
14117,
440,
3145,
376,
1834,
5309,
314,
15187,
1758,
73,
425,
14,
3979,
5844,
87,
1835,
199,
1589,
4913,
4922,
911,
506,
14233,
221,
436,
314,
22496,
911,
506,
5861,
3046,
14,
199,
2765,
911,
4868,
626,
282,
1834,
365,
440,
5463,
5309,
314,
15187,
14,
199,
624,
199,
199,
504,
11258,
14,
888,
492,
4810,
199,
199,
504,
5913,
14,
8512,
14,
2330,
14,
5152,
1208,
492,
485,
199,
504,
5913,
14,
8512,
14,
2330,
492,
4650,
1208,
199,
504,
5913,
14,
8512,
14,
2330,
492,
943,
465,
2050,
199,
504,
5913,
14,
8512,
14,
2330,
492,
23011,
199,
504,
5913,
14,
4549,
492,
1834,
1637,
199,
504,
5913,
14,
4549,
14,
18970,
1246,
492,
6364,
63,
1974,
199,
504,
5913,
14,
4549,
14,
18970,
1246,
492,
1125,
63,
1974,
199,
504,
5913,
14,
4549,
14,
18970,
1246,
492,
6695,
63,
1974,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
646,
63,
2992,
360,
2168,
63,
8618,
63,
5043,
63,
10700,
63,
474,
63,
4515,
297,
355,
283,
6765,
14,
4549,
14,
1569,
1637,
358,
199,
199,
20277,
63,
6351,
275,
283,
1086,
15668,
199,
20277,
63,
4807,
275,
1543,
57,
3295,
77,
3295,
68,
3295,
40,
3295,
45,
3295,
51,
7,
421,
199,
533,
6047,
4437,
2988,
8,
1569,
1637,
14,
3491,
4437,
2988,
304,
272,
347,
636,
826,
721,
277,
12,
2351,
12,
1300,
63,
3741,
304,
267,
1613,
8,
3491,
4437,
2988,
12,
291,
2843,
826,
4533,
267,
291,
423,
1730,
275,
2351,
267,
291,
423,
1095,
63,
3741,
275,
1300,
63,
3741,
267,
291,
423,
795,
63,
5750,
275,
1052,
339,
347,
485,
3741,
63,
1807,
8,
277,
12,
931,
12,
12326,
63,
1121,
304,
267,
862,
26,
288,
6364,
63,
1974,
14,
493,
63,
1807,
8,
277,
423,
1730,
12,
931,
12,
12326,
63,
1121,
9,
267,
871,
334,
705,
63,
1974,
14,
6612,
5392,
1173,
1726,
12,
355,
1125,
63,
1974,
14,
1173,
16665,
1726,
12,
355,
1125,
63,
1974,
14,
1173,
22408,
1726,
9,
465,
325,
26,
288,
327,
6006,
1443,
506,
1655,
2419,
1373,
2112,
503,
2462,
626,
11275,
288,
327,
370,
3145,
314,
570,
14,
288,
5051,
14,
3764,
6115,
6005,
370,
3145,
2818,
493,
9,
83,
14,
2186,
26,
2818,
476,
9,
83,
1288,
717,
791,
493,
356,
931,
12,
283,
476,
356,
325,
1552,
267,
871,
1125,
63,
1974,
14,
1173,
22646,
26,
288,
5051,
14,
1757,
6115,
1173,
440,
1911,
26,
450,
83,
1288,
931,
9,
339,
347,
4913,
63,
3741,
63,
362,
8,
277,
12,
6364,
63,
515,
12,
1834,
63,
344,
304,
267,
408,
3407,
314,
4913,
4922,
1041,
267,
372,
1543,
83,
3149,
83,
7,
450,
334,
795,
63,
515,
12,
1834,
63,
344,
9,
339,
347,
4913,
63,
7661,
8,
277,
12,
12326,
63,
1121,
12,
6364,
63,
5750,
12,
2079,
6364,
63,
1121,
12,
6364,
63,
354,
12,
6364,
63,
515,
304,
267,
6714,
275,
291,
423,
362,
63,
3954,
8,
795,
63,
5750,
12,
6364,
63,
515,
9,
267,
340,
6714,
26,
288,
6714,
63,
515,
275,
1543,
83,
3149,
83,
7,
450,
334,
795,
63,
515,
12,
6714,
9,
288,
5051,
14,
1757,
6115,
10239,
931,
450,
83,
3495,
14,
15920,
1,
1288,
6714,
63,
515,
9,
288,
327,
6047,
365,
1202,
446,
949,
8088,
1929,
4913,
4922,
288,
291,
423,
3741,
63,
1807,
8,
1086,
63,
515,
12,
12326,
63,
1121,
9,
339,
347,
485,
362,
63,
3954,
8,
277,
12,
6364,
63,
5750,
12,
6364,
63,
515,
304,
267,
1584,
275,
6364,
63,
1974,
14,
362,
63,
954,
63,
15171,
8,
277,
423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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
] |
abdellatifkarroum/odoo
|
addons/base_gengo/__openerp__.py
|
312
|
2117
|
# -*- 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': 'Automated Translations through Gengo API',
'version': '0.1',
'category': 'Tools',
'description': """
Automated Translations through Gengo API
========================================
This module will install passive scheduler job for automated translations
using the Gengo API. To activate it, you must
1) Configure your Gengo authentication parameters under `Settings > Companies > Gengo Parameters`
2) Launch the wizard under `Settings > Application Terms > Gengo: Manual Request of Translation` and follow the wizard.
This wizard will activate the CRON job and the Scheduler and will start the automatic translation via Gengo Services for all the terms where you requested it.
""",
'author': 'OpenERP SA',
'website': 'https://www.odoo.com',
'depends': ['base'],
'data': [
'gengo_sync_schedular_data.xml',
'ir_translation.xml',
'res_company_view.xml',
'wizard/base_gengo_translations_view.xml',
],
'demo': [],
'test': [],
'installable': True,
'auto_install': False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
91,
272,
283,
354,
356,
283,
23570,
23513,
6266,
6011,
4012,
18870,
1939,
3261,
297,
272,
283,
1023,
356,
283,
16,
14,
17,
297,
272,
283,
3710,
356,
283,
11654,
297,
272,
283,
1802,
356,
408,
199,
23570,
23513,
6266,
6011,
4012,
18870,
1939,
3261,
199,
2486,
763,
199,
199,
2765,
859,
911,
3907,
21010,
11899,
3906,
367,
6384,
23513,
15547,
221,
199,
4941,
314,
18870,
1939,
3261,
14,
4005,
15422,
652,
12,
1265,
1471,
199,
17,
9,
15453,
2195,
18870,
1939,
6299,
2633,
1334,
658,
5268,
690,
3599,
23461,
690,
18870,
1939,
3897,
64,
199,
18,
9,
23615,
314,
12262,
1334,
658,
5268,
690,
13515,
13861,
706,
690,
18870,
1939,
26,
30247,
4784,
402,
25224,
64,
436,
2035,
314,
12262,
14,
199,
199,
2765,
12262,
911,
15422,
314,
445,
12758,
3906,
436,
314,
32051,
436,
911,
1343,
314,
4834,
7761,
4799,
18870,
1939,
21813,
367,
1006,
314,
2895,
2382,
1265,
5839,
652,
14,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
297,
272,
283,
8912,
356,
788,
1095,
995,
272,
283,
576,
356,
359,
267,
283,
2268,
1939,
63,
5186,
63,
10487,
2238,
63,
576,
14,
1652,
297,
267,
283,
723,
63,
6893,
14,
1652,
297,
267,
283,
470,
63,
4627,
63,
1345,
14,
1652,
297,
267,
283,
9819,
15,
1095,
63,
2268,
1939,
63,
13982,
63,
1345,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
990,
272,
283,
396,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
91,
272,
283,
354,
356,
283,
23570,
23513,
6266,
6011,
4012,
18870,
1939,
3261,
297,
272,
283,
1023,
356,
283,
16,
14,
17,
297,
272,
283,
3710,
356,
283,
11654,
297,
272,
283,
1802,
356,
408,
199,
23570,
23513,
6266,
6011,
4012,
18870,
1939,
3261,
199,
2486,
763,
199,
199,
2765,
859,
911,
3907,
21010,
11899,
3906,
367,
6384,
23513,
15547,
221,
199,
4941,
314,
18870,
1939,
3261,
14,
4005,
15422,
652,
12,
1265,
1471,
199,
17,
9,
15453,
2195,
18870,
1939,
6299,
2633,
1334,
658,
5268,
690,
3599,
23461,
690,
18870,
1939,
3897,
64,
199,
18,
9,
23615,
314,
12262,
1334,
658,
5268,
690,
13515,
13861,
706,
690,
18870,
1939,
26,
30247,
4784,
402,
25224,
64,
436,
2035,
314,
12262,
14,
199,
199,
2765,
12262,
911,
15422,
314,
445,
12758,
3906,
436,
314,
32051,
436,
911,
1343,
314,
4834,
7761,
4799,
18870,
1939,
21813,
367,
1006,
314,
2895,
2382,
1265,
5839,
652,
14,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
297,
272,
283,
8912,
356,
788,
1095,
995,
272,
283,
576,
356,
359,
267,
283,
2268,
1939,
63,
5186,
63,
10487,
2238,
63,
576,
14,
1652,
297,
267,
283,
723,
63,
6893,
14,
1652,
297,
267,
283,
470,
63,
4627,
63,
1345,
14,
1652,
297,
267,
283,
9819,
15,
1095,
63,
2268,
1939,
63,
13982,
63,
1345,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
990,
272,
283,
396,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
vinay87/flyer
|
.buildozer/venv/lib/python2.7/site-packages/setuptools/command/build_ext.py
|
177
|
12442
|
from distutils.command.build_ext import build_ext as _du_build_ext
from distutils.file_util import copy_file
from distutils.ccompiler import new_compiler
from distutils.sysconfig import customize_compiler
from distutils.errors import DistutilsError
from distutils import log
import os
import sys
import itertools
from setuptools.extension import Library
try:
# Attempt to use Pyrex for building extensions, if available
from Pyrex.Distutils.build_ext import build_ext as _build_ext
except ImportError:
_build_ext = _du_build_ext
try:
# Python 2.7 or >=3.2
from sysconfig import _CONFIG_VARS
except ImportError:
from distutils.sysconfig import get_config_var
get_config_var("LDSHARED") # make sure _config_vars is initialized
del get_config_var
from distutils.sysconfig import _config_vars as _CONFIG_VARS
have_rtld = False
use_stubs = False
libtype = 'shared'
if sys.platform == "darwin":
use_stubs = True
elif os.name != 'nt':
try:
import dl
use_stubs = have_rtld = hasattr(dl, 'RTLD_NOW')
except ImportError:
pass
if_dl = lambda s: s if have_rtld else ''
class build_ext(_build_ext):
def run(self):
"""Build extensions in build directory, then copy if --inplace"""
old_inplace, self.inplace = self.inplace, 0
_build_ext.run(self)
self.inplace = old_inplace
if old_inplace:
self.copy_extensions_to_source()
def copy_extensions_to_source(self):
build_py = self.get_finalized_command('build_py')
for ext in self.extensions:
fullname = self.get_ext_fullname(ext.name)
filename = self.get_ext_filename(fullname)
modpath = fullname.split('.')
package = '.'.join(modpath[:-1])
package_dir = build_py.get_package_dir(package)
dest_filename = os.path.join(package_dir,
os.path.basename(filename))
src_filename = os.path.join(self.build_lib, filename)
# Always copy, even if source is older than destination, to ensure
# that the right extensions for the current Python/platform are
# used.
copy_file(
src_filename, dest_filename, verbose=self.verbose,
dry_run=self.dry_run
)
if ext._needs_stub:
self.write_stub(package_dir or os.curdir, ext, True)
if _build_ext is not _du_build_ext and not hasattr(_build_ext,
'pyrex_sources'):
# Workaround for problems using some Pyrex versions w/SWIG and/or 2.4
def swig_sources(self, sources, *otherargs):
# first do any Pyrex processing
sources = _build_ext.swig_sources(self, sources) or sources
# Then do any actual SWIG stuff on the remainder
return _du_build_ext.swig_sources(self, sources, *otherargs)
def get_ext_filename(self, fullname):
filename = _build_ext.get_ext_filename(self, fullname)
if fullname in self.ext_map:
ext = self.ext_map[fullname]
if isinstance(ext, Library):
fn, ext = os.path.splitext(filename)
return self.shlib_compiler.library_filename(fn, libtype)
elif use_stubs and ext._links_to_dynamic:
d, fn = os.path.split(filename)
return os.path.join(d, 'dl-' + fn)
return filename
def initialize_options(self):
_build_ext.initialize_options(self)
self.shlib_compiler = None
self.shlibs = []
self.ext_map = {}
def finalize_options(self):
_build_ext.finalize_options(self)
self.extensions = self.extensions or []
self.check_extensions_list(self.extensions)
self.shlibs = [ext for ext in self.extensions
if isinstance(ext, Library)]
if self.shlibs:
self.setup_shlib_compiler()
for ext in self.extensions:
ext._full_name = self.get_ext_fullname(ext.name)
for ext in self.extensions:
fullname = ext._full_name
self.ext_map[fullname] = ext
# distutils 3.1 will also ask for module names
# XXX what to do with conflicts?
self.ext_map[fullname.split('.')[-1]] = ext
ltd = self.shlibs and self.links_to_dynamic(ext) or False
ns = ltd and use_stubs and not isinstance(ext, Library)
ext._links_to_dynamic = ltd
ext._needs_stub = ns
filename = ext._file_name = self.get_ext_filename(fullname)
libdir = os.path.dirname(os.path.join(self.build_lib, filename))
if ltd and libdir not in ext.library_dirs:
ext.library_dirs.append(libdir)
if ltd and use_stubs and os.curdir not in ext.runtime_library_dirs:
ext.runtime_library_dirs.append(os.curdir)
def setup_shlib_compiler(self):
compiler = self.shlib_compiler = new_compiler(
compiler=self.compiler, dry_run=self.dry_run, force=self.force
)
if sys.platform == "darwin":
tmp = _CONFIG_VARS.copy()
try:
# XXX Help! I don't have any idea whether these are right...
_CONFIG_VARS['LDSHARED'] = (
"gcc -Wl,-x -dynamiclib -undefined dynamic_lookup")
_CONFIG_VARS['CCSHARED'] = " -dynamiclib"
_CONFIG_VARS['SO'] = ".dylib"
customize_compiler(compiler)
finally:
_CONFIG_VARS.clear()
_CONFIG_VARS.update(tmp)
else:
customize_compiler(compiler)
if self.include_dirs is not None:
compiler.set_include_dirs(self.include_dirs)
if self.define is not None:
# 'define' option is a list of (name,value) tuples
for (name, value) in self.define:
compiler.define_macro(name, value)
if self.undef is not None:
for macro in self.undef:
compiler.undefine_macro(macro)
if self.libraries is not None:
compiler.set_libraries(self.libraries)
if self.library_dirs is not None:
compiler.set_library_dirs(self.library_dirs)
if self.rpath is not None:
compiler.set_runtime_library_dirs(self.rpath)
if self.link_objects is not None:
compiler.set_link_objects(self.link_objects)
# hack so distutils' build_extension() builds a library instead
compiler.link_shared_object = link_shared_object.__get__(compiler)
def get_export_symbols(self, ext):
if isinstance(ext, Library):
return ext.export_symbols
return _build_ext.get_export_symbols(self, ext)
def build_extension(self, ext):
_compiler = self.compiler
try:
if isinstance(ext, Library):
self.compiler = self.shlib_compiler
_build_ext.build_extension(self, ext)
if ext._needs_stub:
cmd = self.get_finalized_command('build_py').build_lib
self.write_stub(cmd, ext)
finally:
self.compiler = _compiler
def links_to_dynamic(self, ext):
"""Return true if 'ext' links to a dynamic lib in the same package"""
# XXX this should check to ensure the lib is actually being built
# XXX as dynamic, and not just using a locally-found version or a
# XXX static-compiled version
libnames = dict.fromkeys([lib._full_name for lib in self.shlibs])
pkg = '.'.join(ext._full_name.split('.')[:-1] + [''])
return any(pkg + libname in libnames for libname in ext.libraries)
def get_outputs(self):
return _build_ext.get_outputs(self) + self.__get_stubs_outputs()
def __get_stubs_outputs(self):
# assemble the base name for each extension that needs a stub
ns_ext_bases = (
os.path.join(self.build_lib, *ext._full_name.split('.'))
for ext in self.extensions
if ext._needs_stub
)
# pair each base with the extension
pairs = itertools.product(ns_ext_bases, self.__get_output_extensions())
return list(base + fnext for base, fnext in pairs)
def __get_output_extensions(self):
yield '.py'
yield '.pyc'
if self.get_finalized_command('build_py').optimize:
yield '.pyo'
def write_stub(self, output_dir, ext, compile=False):
log.info("writing stub loader for %s to %s", ext._full_name,
output_dir)
stub_file = (os.path.join(output_dir, *ext._full_name.split('.')) +
'.py')
if compile and os.path.exists(stub_file):
raise DistutilsError(stub_file + " already exists! Please delete.")
if not self.dry_run:
f = open(stub_file, 'w')
f.write(
'\n'.join([
"def __bootstrap__():",
" global __bootstrap__, __file__, __loader__",
" import sys, os, pkg_resources, imp" + if_dl(", dl"),
" __file__ = pkg_resources.resource_filename"
"(__name__,%r)"
% os.path.basename(ext._file_name),
" del __bootstrap__",
" if '__loader__' in globals():",
" del __loader__",
if_dl(" old_flags = sys.getdlopenflags()"),
" old_dir = os.getcwd()",
" try:",
" os.chdir(os.path.dirname(__file__))",
if_dl(" sys.setdlopenflags(dl.RTLD_NOW)"),
" imp.load_dynamic(__name__,__file__)",
" finally:",
if_dl(" sys.setdlopenflags(old_flags)"),
" os.chdir(old_dir)",
"__bootstrap__()",
"" # terminal \n
])
)
f.close()
if compile:
from distutils.util import byte_compile
byte_compile([stub_file], optimize=0,
force=True, dry_run=self.dry_run)
optimize = self.get_finalized_command('install_lib').optimize
if optimize > 0:
byte_compile([stub_file], optimize=optimize,
force=True, dry_run=self.dry_run)
if os.path.exists(stub_file) and not self.dry_run:
os.unlink(stub_file)
if use_stubs or os.name == 'nt':
# Build shared libraries
#
def link_shared_object(
self, objects, output_libname, output_dir=None, libraries=None,
library_dirs=None, runtime_library_dirs=None, export_symbols=None,
debug=0, extra_preargs=None, extra_postargs=None, build_temp=None,
target_lang=None):
self.link(
self.SHARED_LIBRARY, objects, output_libname,
output_dir, libraries, library_dirs, runtime_library_dirs,
export_symbols, debug, extra_preargs, extra_postargs,
build_temp, target_lang
)
else:
# Build static libraries everywhere else
libtype = 'static'
def link_shared_object(
self, objects, output_libname, output_dir=None, libraries=None,
library_dirs=None, runtime_library_dirs=None, export_symbols=None,
debug=0, extra_preargs=None, extra_postargs=None, build_temp=None,
target_lang=None):
# XXX we need to either disallow these attrs on Library instances,
# or warn/abort here if set, or something...
# libraries=None, library_dirs=None, runtime_library_dirs=None,
# export_symbols=None, extra_preargs=None, extra_postargs=None,
# build_temp=None
assert output_dir is None # distutils build_ext doesn't pass this
output_dir, filename = os.path.split(output_libname)
basename, ext = os.path.splitext(filename)
if self.library_filename("x").startswith('lib'):
# strip 'lib' prefix; this is kludgy if some platform uses
# a different prefix
basename = basename[3:]
self.create_static_lib(
objects, basename, output_dir, debug, target_lang
)
|
gpl-2.0
|
[
504,
7065,
14,
1531,
14,
1506,
63,
832,
492,
1900,
63,
832,
465,
485,
2033,
63,
1506,
63,
832,
199,
504,
7065,
14,
493,
63,
1974,
492,
1331,
63,
493,
199,
504,
7065,
14,
67,
5772,
492,
892,
63,
5772,
199,
504,
7065,
14,
24030,
492,
17551,
63,
5772,
199,
504,
7065,
14,
2550,
492,
12577,
547,
199,
504,
7065,
492,
943,
199,
646,
747,
199,
646,
984,
199,
646,
7975,
199,
199,
504,
9116,
14,
3435,
492,
11243,
199,
199,
893,
26,
272,
327,
23115,
370,
675,
1611,
15063,
367,
10015,
5478,
12,
340,
2808,
272,
687,
1611,
15063,
14,
12012,
1208,
14,
1506,
63,
832,
492,
1900,
63,
832,
465,
485,
1506,
63,
832,
199,
2590,
3545,
26,
272,
485,
1506,
63,
832,
275,
485,
2033,
63,
1506,
63,
832,
199,
199,
893,
26,
272,
327,
2018,
499,
14,
23,
503,
2356,
19,
14,
18,
272,
687,
22381,
492,
485,
5569,
63,
21367,
199,
2590,
3545,
26,
272,
687,
7065,
14,
24030,
492,
664,
63,
888,
63,
1391,
339,
664,
63,
888,
63,
1391,
480,
44,
3177,
30958,
1149,
531,
221,
327,
1852,
3238,
485,
888,
63,
2936,
365,
10038,
272,
2150,
664,
63,
888,
63,
1391,
272,
687,
7065,
14,
24030,
492,
485,
888,
63,
2936,
465,
485,
5569,
63,
21367,
199,
199,
7804,
63,
2591,
1447,
275,
756,
199,
1180,
63,
8957,
275,
756,
199,
773,
466,
275,
283,
5555,
7,
199,
199,
692,
984,
14,
3246,
508,
298,
13245,
582,
272,
675,
63,
8957,
275,
715,
199,
4164,
747,
14,
354,
1137,
283,
343,
356,
272,
862,
26,
267,
492,
15396,
267,
675,
63,
8957,
275,
1172,
63,
2591,
1447,
275,
2688,
8,
5030,
12,
283,
11876,
6533,
63,
14283,
358,
272,
871,
3545,
26,
267,
986,
421,
199,
692,
63,
5030,
275,
2400,
308,
26,
308,
340,
1172,
63,
2591,
1447,
587,
2125,
421,
199,
533,
1900,
63,
832,
1547,
1506,
63,
832,
304,
272,
347,
1255,
8,
277,
304,
267,
408,
3425,
5478,
315,
1900,
2082,
12,
2066,
1331,
340,
1553,
15008,
624,
267,
2269,
63,
15008,
12,
291,
14,
15008,
275,
291,
14,
15008,
12,
378,
267,
485,
1506,
63,
832,
14,
1065,
8,
277,
9,
267,
291,
14,
15008,
275,
2269,
63,
15008,
267,
340,
2269,
63,
15008,
26,
288,
291,
14,
1574,
63,
5359,
63,
475,
63,
1365,
342,
339,
347,
1331,
63,
5359,
63,
475,
63,
1365,
8,
277,
304,
267,
1900,
63,
647,
275,
291,
14,
362,
63,
19231,
63,
1531,
360,
1506,
63,
647,
358,
267,
367,
1599,
315,
291,
14,
5359,
26,
288,
11064,
275,
291,
14,
362,
63,
832,
63,
9930,
8,
832,
14,
354,
9,
288,
1788,
275,
291,
14,
362,
63,
832,
63,
1501,
8,
9930,
9,
288,
3413,
515,
275,
11064,
14,
1294,
7563,
288,
2559,
275,
15671,
904,
8,
1494,
515,
4439,
17,
566,
288,
2559,
63,
694,
275,
1900,
63,
647,
14,
362,
63,
2491,
63,
694,
8,
2491,
9,
288,
2053,
63,
1501,
275,
747,
14,
515,
14,
904,
8,
2491,
63,
694,
12,
1460,
747,
14,
515,
14,
4846,
8,
1501,
430,
288,
2928,
63,
1501,
275,
747,
14,
515,
14,
904,
8,
277,
14,
1506,
63,
773,
12,
1788,
9,
953,
327,
16763,
1331,
12,
2755,
340,
1350,
365,
12731,
2419,
5724,
12,
370,
4868,
288,
327,
626,
314,
2451,
5478,
367,
314,
1453,
2018,
15,
3246,
787,
288,
327,
1202,
14,
288,
1331,
63,
493,
8,
355,
2928,
63,
1501,
12,
2053,
63,
1501,
12,
3376,
29,
277,
14,
3832,
12,
355,
9951,
63,
1065,
29,
277,
14,
10481,
63,
1065,
288,
776,
288,
340,
1599,
423,
10065,
63,
5811,
26,
355,
291,
14,
952,
63,
5811,
8,
2491,
63,
694,
503,
747,
14,
15594,
12,
1599,
12,
715,
9,
339,
340,
485,
1506,
63,
832,
365,
440,
485,
2033,
63,
1506,
63,
832,
436,
440,
2688,
1547,
1506,
63,
832,
12,
10940,
283,
647,
15063,
63,
4553,
735,
267,
327,
9361,
11659,
367,
8826,
1808,
2005,
1611,
15063,
5459,
336,
15,
8745,
1277,
436,
15,
269,
499,
14,
20,
267,
347,
30057,
63,
4553,
8,
277,
12,
5274,
12,
627,
1848,
589,
304,
288,
327,
1642,
886,
1263,
1611,
15063,
6661,
288,
5274,
275,
485,
1506,
63,
832,
14,
9676,
63,
4553,
8,
277,
12,
5274,
9,
503,
5274,
288,
327,
9442,
886,
1263,
3503,
26480,
8292,
641,
314,
15748,
288,
372,
485,
2033,
63,
1506,
63,
832,
14,
9676,
63,
4553,
8,
277,
12,
5274,
12,
627,
1848,
589,
9,
339,
347,
664,
63,
832,
63,
1501,
8,
277,
12,
11064,
304,
267,
1788,
275,
485,
1506,
63,
832,
14,
362,
63,
832,
63,
1501,
8,
277,
12,
11064,
9,
267,
340,
11064,
315,
291,
14,
832,
63,
1130,
26,
288,
1599,
275,
291,
14,
832,
63,
1130,
59,
9930,
61,
288,
340,
1228,
8,
832,
12,
11243,
304,
355,
4325,
12,
1599,
275,
747,
14,
515,
14,
7973,
8,
1501,
9,
355,
372,
291,
14,
609,
773,
63,
5772,
14,
4342,
63,
1501,
8,
2324,
12,
1973,
466,
9,
288,
916,
675,
63,
8957,
436,
1599,
423,
4614,
63,
475,
63,
7764,
26,
355,
366,
12,
4325,
275,
747,
14,
515,
14,
1294,
8,
1501,
9,
355,
372,
747,
14,
515,
14,
904,
8,
68,
12,
283,
5030,
15668,
435,
4325,
9,
267,
372,
1788,
339,
347,
8265,
63,
1419,
8,
277,
304,
267,
485,
1506,
63,
832,
14,
8489,
63,
1419,
8,
277,
9,
267,
291,
14,
609,
773,
63,
5772,
275,
488,
267,
291,
14,
609,
8450,
275,
942,
267,
291,
14,
832,
63,
1130,
275,
1052,
339,
347,
17284,
63,
1419,
8,
277,
304,
267,
485,
1506,
63,
832,
14,
14450,
63,
1419,
8,
277,
9,
267,
291,
14,
5359,
275,
291,
14,
5359,
503,
942,
267,
291,
14,
1074,
63,
5359,
63,
513,
8,
277,
14,
5359,
9,
267,
291,
14,
609,
8450,
275,
359,
832,
367,
1599,
315,
291,
14,
5359,
2432,
340,
1228,
8,
832,
12,
11243,
1874,
267,
340,
291,
14,
609,
8450,
26,
288,
291,
14,
2758,
63,
609,
773,
63,
5772,
342,
267,
367,
1599,
315,
291,
14,
5359,
26,
288,
1599,
423,
2861,
63,
354,
275,
291
] |
[
7065,
14,
1531,
14,
1506,
63,
832,
492,
1900,
63,
832,
465,
485,
2033,
63,
1506,
63,
832,
199,
504,
7065,
14,
493,
63,
1974,
492,
1331,
63,
493,
199,
504,
7065,
14,
67,
5772,
492,
892,
63,
5772,
199,
504,
7065,
14,
24030,
492,
17551,
63,
5772,
199,
504,
7065,
14,
2550,
492,
12577,
547,
199,
504,
7065,
492,
943,
199,
646,
747,
199,
646,
984,
199,
646,
7975,
199,
199,
504,
9116,
14,
3435,
492,
11243,
199,
199,
893,
26,
272,
327,
23115,
370,
675,
1611,
15063,
367,
10015,
5478,
12,
340,
2808,
272,
687,
1611,
15063,
14,
12012,
1208,
14,
1506,
63,
832,
492,
1900,
63,
832,
465,
485,
1506,
63,
832,
199,
2590,
3545,
26,
272,
485,
1506,
63,
832,
275,
485,
2033,
63,
1506,
63,
832,
199,
199,
893,
26,
272,
327,
2018,
499,
14,
23,
503,
2356,
19,
14,
18,
272,
687,
22381,
492,
485,
5569,
63,
21367,
199,
2590,
3545,
26,
272,
687,
7065,
14,
24030,
492,
664,
63,
888,
63,
1391,
339,
664,
63,
888,
63,
1391,
480,
44,
3177,
30958,
1149,
531,
221,
327,
1852,
3238,
485,
888,
63,
2936,
365,
10038,
272,
2150,
664,
63,
888,
63,
1391,
272,
687,
7065,
14,
24030,
492,
485,
888,
63,
2936,
465,
485,
5569,
63,
21367,
199,
199,
7804,
63,
2591,
1447,
275,
756,
199,
1180,
63,
8957,
275,
756,
199,
773,
466,
275,
283,
5555,
7,
199,
199,
692,
984,
14,
3246,
508,
298,
13245,
582,
272,
675,
63,
8957,
275,
715,
199,
4164,
747,
14,
354,
1137,
283,
343,
356,
272,
862,
26,
267,
492,
15396,
267,
675,
63,
8957,
275,
1172,
63,
2591,
1447,
275,
2688,
8,
5030,
12,
283,
11876,
6533,
63,
14283,
358,
272,
871,
3545,
26,
267,
986,
421,
199,
692,
63,
5030,
275,
2400,
308,
26,
308,
340,
1172,
63,
2591,
1447,
587,
2125,
421,
199,
533,
1900,
63,
832,
1547,
1506,
63,
832,
304,
272,
347,
1255,
8,
277,
304,
267,
408,
3425,
5478,
315,
1900,
2082,
12,
2066,
1331,
340,
1553,
15008,
624,
267,
2269,
63,
15008,
12,
291,
14,
15008,
275,
291,
14,
15008,
12,
378,
267,
485,
1506,
63,
832,
14,
1065,
8,
277,
9,
267,
291,
14,
15008,
275,
2269,
63,
15008,
267,
340,
2269,
63,
15008,
26,
288,
291,
14,
1574,
63,
5359,
63,
475,
63,
1365,
342,
339,
347,
1331,
63,
5359,
63,
475,
63,
1365,
8,
277,
304,
267,
1900,
63,
647,
275,
291,
14,
362,
63,
19231,
63,
1531,
360,
1506,
63,
647,
358,
267,
367,
1599,
315,
291,
14,
5359,
26,
288,
11064,
275,
291,
14,
362,
63,
832,
63,
9930,
8,
832,
14,
354,
9,
288,
1788,
275,
291,
14,
362,
63,
832,
63,
1501,
8,
9930,
9,
288,
3413,
515,
275,
11064,
14,
1294,
7563,
288,
2559,
275,
15671,
904,
8,
1494,
515,
4439,
17,
566,
288,
2559,
63,
694,
275,
1900,
63,
647,
14,
362,
63,
2491,
63,
694,
8,
2491,
9,
288,
2053,
63,
1501,
275,
747,
14,
515,
14,
904,
8,
2491,
63,
694,
12,
1460,
747,
14,
515,
14,
4846,
8,
1501,
430,
288,
2928,
63,
1501,
275,
747,
14,
515,
14,
904,
8,
277,
14,
1506,
63,
773,
12,
1788,
9,
953,
327,
16763,
1331,
12,
2755,
340,
1350,
365,
12731,
2419,
5724,
12,
370,
4868,
288,
327,
626,
314,
2451,
5478,
367,
314,
1453,
2018,
15,
3246,
787,
288,
327,
1202,
14,
288,
1331,
63,
493,
8,
355,
2928,
63,
1501,
12,
2053,
63,
1501,
12,
3376,
29,
277,
14,
3832,
12,
355,
9951,
63,
1065,
29,
277,
14,
10481,
63,
1065,
288,
776,
288,
340,
1599,
423,
10065,
63,
5811,
26,
355,
291,
14,
952,
63,
5811,
8,
2491,
63,
694,
503,
747,
14,
15594,
12,
1599,
12,
715,
9,
339,
340,
485,
1506,
63,
832,
365,
440,
485,
2033,
63,
1506,
63,
832,
436,
440,
2688,
1547,
1506,
63,
832,
12,
10940,
283,
647,
15063,
63,
4553,
735,
267,
327,
9361,
11659,
367,
8826,
1808,
2005,
1611,
15063,
5459,
336,
15,
8745,
1277,
436,
15,
269,
499,
14,
20,
267,
347,
30057,
63,
4553,
8,
277,
12,
5274,
12,
627,
1848,
589,
304,
288,
327,
1642,
886,
1263,
1611,
15063,
6661,
288,
5274,
275,
485,
1506,
63,
832,
14,
9676,
63,
4553,
8,
277,
12,
5274,
9,
503,
5274,
288,
327,
9442,
886,
1263,
3503,
26480,
8292,
641,
314,
15748,
288,
372,
485,
2033,
63,
1506,
63,
832,
14,
9676,
63,
4553,
8,
277,
12,
5274,
12,
627,
1848,
589,
9,
339,
347,
664,
63,
832,
63,
1501,
8,
277,
12,
11064,
304,
267,
1788,
275,
485,
1506,
63,
832,
14,
362,
63,
832,
63,
1501,
8,
277,
12,
11064,
9,
267,
340,
11064,
315,
291,
14,
832,
63,
1130,
26,
288,
1599,
275,
291,
14,
832,
63,
1130,
59,
9930,
61,
288,
340,
1228,
8,
832,
12,
11243,
304,
355,
4325,
12,
1599,
275,
747,
14,
515,
14,
7973,
8,
1501,
9,
355,
372,
291,
14,
609,
773,
63,
5772,
14,
4342,
63,
1501,
8,
2324,
12,
1973,
466,
9,
288,
916,
675,
63,
8957,
436,
1599,
423,
4614,
63,
475,
63,
7764,
26,
355,
366,
12,
4325,
275,
747,
14,
515,
14,
1294,
8,
1501,
9,
355,
372,
747,
14,
515,
14,
904,
8,
68,
12,
283,
5030,
15668,
435,
4325,
9,
267,
372,
1788,
339,
347,
8265,
63,
1419,
8,
277,
304,
267,
485,
1506,
63,
832,
14,
8489,
63,
1419,
8,
277,
9,
267,
291,
14,
609,
773,
63,
5772,
275,
488,
267,
291,
14,
609,
8450,
275,
942,
267,
291,
14,
832,
63,
1130,
275,
1052,
339,
347,
17284,
63,
1419,
8,
277,
304,
267,
485,
1506,
63,
832,
14,
14450,
63,
1419,
8,
277,
9,
267,
291,
14,
5359,
275,
291,
14,
5359,
503,
942,
267,
291,
14,
1074,
63,
5359,
63,
513,
8,
277,
14,
5359,
9,
267,
291,
14,
609,
8450,
275,
359,
832,
367,
1599,
315,
291,
14,
5359,
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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
] |
sealcode/gpandoc
|
ui/recipe_ui.py
|
1
|
3014
|
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'recipe.ui'
#
# Created by: PyQt5 UI code generator 5.7.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(355, 478)
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
self.verticalLayout.setObjectName("verticalLayout")
self.vertical_layout_1 = QtWidgets.QVBoxLayout()
self.vertical_layout_1.setObjectName("vertical_layout_1")
self.label_1 = QtWidgets.QLabel(Dialog)
self.label_1.setObjectName("label_1")
self.vertical_layout_1.addWidget(self.label_1)
self.combo_box_1 = QtWidgets.QComboBox(Dialog)
self.combo_box_1.setObjectName("combo_box_1")
self.vertical_layout_1.addWidget(self.combo_box_1)
self.verticalLayout.addLayout(self.vertical_layout_1)
self.vertical_layout_2 = QtWidgets.QVBoxLayout()
self.vertical_layout_2.setObjectName("vertical_layout_2")
self.scroll_1 = QtWidgets.QScrollArea(Dialog)
self.scroll_1.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.scroll_1.setWidgetResizable(True)
self.scroll_1.setObjectName("scroll_1")
self.content_1 = QtWidgets.QWidget()
self.content_1.setGeometry(QtCore.QRect(0, 0, 300, 378))
self.content_1.setMaximumSize(QtCore.QSize(300, 600))
self.content_1.setObjectName("content_1")
self.label_2 = QtWidgets.QLabel(self.content_1)
self.label_2.setGeometry(QtCore.QRect(8, 3, 301, 421))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label_2.sizePolicy().hasHeightForWidth())
self.label_2.setSizePolicy(sizePolicy)
self.label_2.setAlignment(QtCore.Qt.AlignCenter)
self.label_2.setObjectName("label_2")
self.scroll_1.setWidget(self.content_1)
self.vertical_layout_2.addWidget(self.scroll_1)
self.button_box_1 = QtWidgets.QDialogButtonBox(Dialog)
self.button_box_1.setOrientation(QtCore.Qt.Horizontal)
self.button_box_1.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.button_box_1.setObjectName("button_box_1")
self.vertical_layout_2.addWidget(self.button_box_1)
self.verticalLayout.addLayout(self.vertical_layout_2)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Wybór przepisu"))
self.label_1.setText(_translate("Dialog", "Lista przepisów:"))
self.label_2.setText(_translate("Dialog", "TextLabel"))
|
lgpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
8204,
4514,
4046,
687,
7664,
8574,
570,
283,
13191,
14,
1907,
7,
199,
3,
199,
3,
18208,
701,
26,
14084,
21,
14041,
1233,
4306,
959,
14,
23,
14,
17,
199,
3,
199,
3,
14750,
1,
2900,
4493,
6326,
315,
642,
570,
911,
506,
14669,
1,
199,
199,
504,
14084,
21,
492,
10565,
12,
5928,
12,
17113,
199,
199,
533,
32471,
63,
5619,
8,
785,
304,
272,
347,
3272,
18203,
8,
277,
12,
30631,
304,
267,
30631,
14,
10376,
480,
5619,
531,
267,
30631,
14,
8709,
8,
10156,
12,
841,
2277,
9,
267,
291,
14,
18656,
275,
17113,
14,
25527,
18536,
8,
5619,
9,
267,
291,
14,
18656,
14,
10376,
480,
18656,
531,
267,
291,
14,
7870,
63,
4209,
63,
17,
275,
17113,
14,
25527,
18536,
342,
267,
291,
14,
7870,
63,
4209,
63,
17,
14,
10376,
480,
7870,
63,
4209,
63,
17,
531,
267,
291,
14,
1302,
63,
17,
275,
17113,
14,
19890,
8,
5619,
9,
267,
291,
14,
1302,
63,
17,
14,
10376,
480,
1302,
63,
17,
531,
267,
291,
14,
7870,
63,
4209,
63,
17,
14,
9475,
8,
277,
14,
1302,
63,
17,
9,
267,
291,
14,
12650,
63,
1977,
63,
17,
275,
17113,
14,
49,
17491,
8,
5619,
9,
267,
291,
14,
12650,
63,
1977,
63,
17,
14,
10376,
480,
12650,
63,
1977,
63,
17,
531,
267,
291,
14,
7870,
63,
4209,
63,
17,
14,
9475,
8,
277,
14,
12650,
63,
1977,
63,
17,
9,
267,
291,
14,
18656,
14,
30571,
8,
277,
14,
7870,
63,
4209,
63,
17,
9,
267,
291,
14,
7870,
63,
4209,
63,
18,
275,
17113,
14,
25527,
18536,
342,
267,
291,
14,
7870,
63,
4209,
63,
18,
14,
10376,
480,
7870,
63,
4209,
63,
18,
531,
267,
291,
14,
6755,
63,
17,
275,
17113,
14,
49,
13127,
11043,
8,
5619,
9,
267,
291,
14,
6755,
63,
17,
14,
409,
19462,
13127,
5281,
4845,
8,
10901,
14,
4238,
14,
13127,
5281,
2439,
2885,
3314,
9,
267,
291,
14,
6755,
63,
17,
14,
409,
3339,
497,
5946,
461,
8,
549,
9,
267,
291,
14,
6755,
63,
17,
14,
10376,
480,
6755,
63,
17,
531,
267,
291,
14,
1317,
63,
17,
275,
17113,
14,
23894,
342,
267,
291,
14,
1317,
63,
17,
14,
25559,
8,
10901,
14,
30197,
8,
16,
12,
378,
12,
9601,
12,
650,
2277,
430,
267,
291,
14,
1317,
63,
17,
14,
409,
10915,
2320,
8,
10901,
14,
15531,
8,
5863,
12,
11624,
430,
267,
291,
14,
1317,
63,
17,
14,
10376,
480,
1317,
63,
17,
531,
267,
291,
14,
1302,
63,
18,
275,
17113,
14,
19890,
8,
277,
14,
1317,
63,
17,
9,
267,
291,
14,
1302,
63,
18,
14,
25559,
8,
10901,
14,
30197,
8,
24,
12,
650,
12,
19660,
12,
841,
2025,
430,
267,
22789,
275,
17113,
14,
19934,
8,
29081,
14,
19934,
14,
29373,
12,
17113,
14,
19934,
14,
29373,
9,
267,
22789,
14,
409,
19918,
21537,
8,
16,
9,
267,
22789,
14,
409,
19462,
21537,
8,
16,
9,
267,
22789,
14,
409,
8436,
1858,
6216,
8,
277,
14,
1302,
63,
18,
14,
890,
4845,
1252,
1989,
8436,
1858,
6216,
1012,
267,
291,
14,
1302,
63,
18,
14,
21735,
4845,
8,
890,
4845,
9,
267,
291,
14,
1302,
63,
18,
14,
409,
16613,
8,
10901,
14,
4238,
14,
9497,
13551,
9,
267,
291,
14,
1302,
63,
18,
14,
10376,
480,
1302,
63,
18,
531,
267,
291,
14,
6755,
63,
17,
14,
409,
3339,
8,
277,
14,
1317,
63,
17,
9,
267,
291,
14,
7870,
63,
4209,
63,
18,
14,
9475,
8,
277,
14,
6755,
63,
17,
9,
267,
291,
14,
3887,
63,
1977,
63,
17,
275,
17113,
14,
30983,
4259,
3532,
8,
5619,
9,
267,
291,
14,
3887,
63,
1977,
63,
17,
14,
409,
27536,
8,
10901,
14,
4238,
14,
19918,
9,
267,
291,
14,
3887,
63,
1977,
63,
17,
14,
409,
9232,
24021,
8,
29081,
14,
30983,
4259,
3532,
14,
9083,
92,
29081,
14,
30983,
4259,
3532,
14,
11622,
9,
267,
291,
14,
3887,
63,
1977,
63,
17,
14,
10376,
480,
3887,
63,
1977,
63,
17,
531,
267,
291,
14,
7870,
63,
4209,
63,
18,
14,
9475,
8,
277,
14,
3887,
63,
1977,
63,
17,
9,
267,
291,
14,
18656,
14,
30571,
8,
277,
14,
7870,
63,
4209,
63,
18,
9,
398,
291,
14,
264,
5275,
18203,
8,
5619,
9,
267,
10565,
14,
49,
3396,
1692,
14,
2242,
26492,
11190,
8,
5619,
9,
339,
347,
295,
5275,
18203,
8,
277,
12,
30631,
304,
267,
485,
5275,
275,
10565,
14,
49,
29263,
14,
5275,
267,
30631,
14,
30601,
1547,
5275,
480,
5619,
401,
298,
55,
28564,
11980,
82,
5448,
806,
80,
374,
85,
2237,
267,
291,
14,
1302,
63,
17,
14,
8341,
1547,
5275,
480,
5619,
401,
298,
1296,
65,
5448,
806,
80,
374,
11980,
87,
26,
2237,
267,
291,
14,
1302,
63,
18,
14,
8341,
1547,
5275,
480,
5619,
401,
298,
1872,
4314,
2237,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
8204,
4514,
4046,
687,
7664,
8574,
570,
283,
13191,
14,
1907,
7,
199,
3,
199,
3,
18208,
701,
26,
14084,
21,
14041,
1233,
4306,
959,
14,
23,
14,
17,
199,
3,
199,
3,
14750,
1,
2900,
4493,
6326,
315,
642,
570,
911,
506,
14669,
1,
199,
199,
504,
14084,
21,
492,
10565,
12,
5928,
12,
17113,
199,
199,
533,
32471,
63,
5619,
8,
785,
304,
272,
347,
3272,
18203,
8,
277,
12,
30631,
304,
267,
30631,
14,
10376,
480,
5619,
531,
267,
30631,
14,
8709,
8,
10156,
12,
841,
2277,
9,
267,
291,
14,
18656,
275,
17113,
14,
25527,
18536,
8,
5619,
9,
267,
291,
14,
18656,
14,
10376,
480,
18656,
531,
267,
291,
14,
7870,
63,
4209,
63,
17,
275,
17113,
14,
25527,
18536,
342,
267,
291,
14,
7870,
63,
4209,
63,
17,
14,
10376,
480,
7870,
63,
4209,
63,
17,
531,
267,
291,
14,
1302,
63,
17,
275,
17113,
14,
19890,
8,
5619,
9,
267,
291,
14,
1302,
63,
17,
14,
10376,
480,
1302,
63,
17,
531,
267,
291,
14,
7870,
63,
4209,
63,
17,
14,
9475,
8,
277,
14,
1302,
63,
17,
9,
267,
291,
14,
12650,
63,
1977,
63,
17,
275,
17113,
14,
49,
17491,
8,
5619,
9,
267,
291,
14,
12650,
63,
1977,
63,
17,
14,
10376,
480,
12650,
63,
1977,
63,
17,
531,
267,
291,
14,
7870,
63,
4209,
63,
17,
14,
9475,
8,
277,
14,
12650,
63,
1977,
63,
17,
9,
267,
291,
14,
18656,
14,
30571,
8,
277,
14,
7870,
63,
4209,
63,
17,
9,
267,
291,
14,
7870,
63,
4209,
63,
18,
275,
17113,
14,
25527,
18536,
342,
267,
291,
14,
7870,
63,
4209,
63,
18,
14,
10376,
480,
7870,
63,
4209,
63,
18,
531,
267,
291,
14,
6755,
63,
17,
275,
17113,
14,
49,
13127,
11043,
8,
5619,
9,
267,
291,
14,
6755,
63,
17,
14,
409,
19462,
13127,
5281,
4845,
8,
10901,
14,
4238,
14,
13127,
5281,
2439,
2885,
3314,
9,
267,
291,
14,
6755,
63,
17,
14,
409,
3339,
497,
5946,
461,
8,
549,
9,
267,
291,
14,
6755,
63,
17,
14,
10376,
480,
6755,
63,
17,
531,
267,
291,
14,
1317,
63,
17,
275,
17113,
14,
23894,
342,
267,
291,
14,
1317,
63,
17,
14,
25559,
8,
10901,
14,
30197,
8,
16,
12,
378,
12,
9601,
12,
650,
2277,
430,
267,
291,
14,
1317,
63,
17,
14,
409,
10915,
2320,
8,
10901,
14,
15531,
8,
5863,
12,
11624,
430,
267,
291,
14,
1317,
63,
17,
14,
10376,
480,
1317,
63,
17,
531,
267,
291,
14,
1302,
63,
18,
275,
17113,
14,
19890,
8,
277,
14,
1317,
63,
17,
9,
267,
291,
14,
1302,
63,
18,
14,
25559,
8,
10901,
14,
30197,
8,
24,
12,
650,
12,
19660,
12,
841,
2025,
430,
267,
22789,
275,
17113,
14,
19934,
8,
29081,
14,
19934,
14,
29373,
12,
17113,
14,
19934,
14,
29373,
9,
267,
22789,
14,
409,
19918,
21537,
8,
16,
9,
267,
22789,
14,
409,
19462,
21537,
8,
16,
9,
267,
22789,
14,
409,
8436,
1858,
6216,
8,
277,
14,
1302,
63,
18,
14,
890,
4845,
1252,
1989,
8436,
1858,
6216,
1012,
267,
291,
14,
1302,
63,
18,
14,
21735,
4845,
8,
890,
4845,
9,
267,
291,
14,
1302,
63,
18,
14,
409,
16613,
8,
10901,
14,
4238,
14,
9497,
13551,
9,
267,
291,
14,
1302,
63,
18,
14,
10376,
480,
1302,
63,
18,
531,
267,
291,
14,
6755,
63,
17,
14,
409,
3339,
8,
277,
14,
1317,
63,
17,
9,
267,
291,
14,
7870,
63,
4209,
63,
18,
14,
9475,
8,
277,
14,
6755,
63,
17,
9,
267,
291,
14,
3887,
63,
1977,
63,
17,
275,
17113,
14,
30983,
4259,
3532,
8,
5619,
9,
267,
291,
14,
3887,
63,
1977,
63,
17,
14,
409,
27536,
8,
10901,
14,
4238,
14,
19918,
9,
267,
291,
14,
3887,
63,
1977,
63,
17,
14,
409,
9232,
24021,
8,
29081,
14,
30983,
4259,
3532,
14,
9083,
92,
29081,
14,
30983,
4259,
3532,
14,
11622,
9,
267,
291,
14,
3887,
63,
1977,
63,
17,
14,
10376,
480,
3887,
63,
1977,
63,
17,
531,
267,
291,
14,
7870,
63,
4209,
63,
18,
14,
9475,
8,
277,
14,
3887,
63,
1977,
63,
17,
9,
267,
291,
14,
18656,
14,
30571,
8,
277,
14,
7870,
63,
4209,
63,
18,
9,
398,
291,
14,
264,
5275,
18203,
8,
5619,
9,
267,
10565,
14,
49,
3396,
1692,
14,
2242,
26492,
11190,
8,
5619,
9,
339,
347,
295,
5275,
18203,
8,
277,
12,
30631,
304,
267,
485,
5275,
275,
10565,
14,
49,
29263,
14,
5275,
267,
30631,
14,
30601,
1547,
5275,
480,
5619,
401,
298,
55,
28564,
11980,
82,
5448,
806,
80,
374,
85,
2237,
267,
291,
14,
1302,
63,
17,
14,
8341,
1547,
5275,
480,
5619,
401,
298,
1296,
65,
5448,
806,
80,
374,
11980,
87,
26,
2237,
267,
291,
14,
1302,
63,
18,
14,
8341,
1547,
5275,
480,
5619,
401,
298,
1872,
4314,
2237,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dominikl/openmicroscopy
|
components/tools/OmeroCpp/ext/gtest-1.7.0/test/gtest_throw_on_failure_test.py
|
2917
|
5766
|
#!/usr/bin/env python
#
# Copyright 2009, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Tests Google Test's throw-on-failure mode with exceptions disabled.
This script invokes gtest_throw_on_failure_test_ (a program written with
Google Test) with different environments and command line flags.
"""
__author__ = 'wan@google.com (Zhanyong Wan)'
import os
import gtest_test_utils
# Constants.
# The command line flag for enabling/disabling the throw-on-failure mode.
THROW_ON_FAILURE = 'gtest_throw_on_failure'
# Path to the gtest_throw_on_failure_test_ program, compiled with
# exceptions disabled.
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
'gtest_throw_on_failure_test_')
# Utilities.
def SetEnvVar(env_var, value):
"""Sets an environment variable to a given value; unsets it when the
given value is None.
"""
env_var = env_var.upper()
if value is not None:
os.environ[env_var] = value
elif env_var in os.environ:
del os.environ[env_var]
def Run(command):
"""Runs a command; returns True/False if its exit code is/isn't 0."""
print 'Running "%s". . .' % ' '.join(command)
p = gtest_test_utils.Subprocess(command)
return p.exited and p.exit_code == 0
# The tests. TODO(wan@google.com): refactor the class to share common
# logic with code in gtest_break_on_failure_unittest.py.
class ThrowOnFailureTest(gtest_test_utils.TestCase):
"""Tests the throw-on-failure mode."""
def RunAndVerify(self, env_var_value, flag_value, should_fail):
"""Runs gtest_throw_on_failure_test_ and verifies that it does
(or does not) exit with a non-zero code.
Args:
env_var_value: value of the GTEST_BREAK_ON_FAILURE environment
variable; None if the variable should be unset.
flag_value: value of the --gtest_break_on_failure flag;
None if the flag should not be present.
should_fail: True iff the program is expected to fail.
"""
SetEnvVar(THROW_ON_FAILURE, env_var_value)
if env_var_value is None:
env_var_value_msg = ' is not set'
else:
env_var_value_msg = '=' + env_var_value
if flag_value is None:
flag = ''
elif flag_value == '0':
flag = '--%s=0' % THROW_ON_FAILURE
else:
flag = '--%s' % THROW_ON_FAILURE
command = [EXE_PATH]
if flag:
command.append(flag)
if should_fail:
should_or_not = 'should'
else:
should_or_not = 'should not'
failed = not Run(command)
SetEnvVar(THROW_ON_FAILURE, None)
msg = ('when %s%s, an assertion failure in "%s" %s cause a non-zero '
'exit code.' %
(THROW_ON_FAILURE, env_var_value_msg, ' '.join(command),
should_or_not))
self.assert_(failed == should_fail, msg)
def testDefaultBehavior(self):
"""Tests the behavior of the default mode."""
self.RunAndVerify(env_var_value=None, flag_value=None, should_fail=False)
def testThrowOnFailureEnvVar(self):
"""Tests using the GTEST_THROW_ON_FAILURE environment variable."""
self.RunAndVerify(env_var_value='0',
flag_value=None,
should_fail=False)
self.RunAndVerify(env_var_value='1',
flag_value=None,
should_fail=True)
def testThrowOnFailureFlag(self):
"""Tests using the --gtest_throw_on_failure flag."""
self.RunAndVerify(env_var_value=None,
flag_value='0',
should_fail=False)
self.RunAndVerify(env_var_value=None,
flag_value='1',
should_fail=True)
def testThrowOnFailureFlagOverridesEnvVar(self):
"""Tests that --gtest_throw_on_failure overrides GTEST_THROW_ON_FAILURE."""
self.RunAndVerify(env_var_value='0',
flag_value='0',
should_fail=False)
self.RunAndVerify(env_var_value='0',
flag_value='1',
should_fail=True)
self.RunAndVerify(env_var_value='1',
flag_value='0',
should_fail=False)
self.RunAndVerify(env_var_value='1',
flag_value='1',
should_fail=True)
if __name__ == '__main__':
gtest_test_utils.Main()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8937,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
2925,
4475,
1379,
1159,
7978,
13,
265,
13,
5328,
818,
543,
4967,
6980,
14,
199,
199,
2765,
2884,
29761,
9088,
63,
11964,
63,
265,
63,
5328,
63,
396,
63,
334,
65,
2240,
5313,
543,
199,
13266,
1379,
9,
543,
3365,
22196,
436,
1414,
1004,
3285,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
20444,
32,
3098,
14,
957,
334,
12674,
1629,
951,
644,
290,
3171,
199,
199,
646,
747,
199,
646,
9088,
63,
396,
63,
1208,
421,
199,
3,
22296,
14,
199,
199,
3,
710,
1414,
1004,
3305,
367,
29310,
15,
2297,
14744,
314,
7978,
13,
265,
13,
5328,
818,
14,
199,
2080,
11415,
63,
615,
63,
13989,
275,
283,
8385,
63,
11964,
63,
265,
63,
5328,
7,
199,
199,
3,
6912,
370,
314,
9088,
63,
11964,
63,
265,
63,
5328,
63,
396,
63,
2240,
12,
10311,
543,
199,
3,
4967,
6980,
14,
199,
23017,
63,
3243,
275,
9088,
63,
396,
63,
1208,
14,
28967,
27602,
8,
272,
283,
8385,
63,
11964,
63,
265,
63,
5328,
63,
396,
15452,
421,
199,
3,
738,
17933,
14,
421,
199,
318,
30306,
8,
1813,
63,
1391,
12,
574,
304,
523,
408,
9899,
376,
3734,
1750,
370,
282,
1627,
574,
27,
625,
2193,
652,
1380,
314,
523,
1627,
574,
365,
488,
14,
523,
408,
819,
2589,
63,
1391,
275,
2589,
63,
1391,
14,
4142,
342,
523,
340,
574,
365,
440,
488,
26,
272,
747,
14,
2314,
59,
1813,
63,
1391,
61,
275,
574,
523,
916,
2589,
63,
1391,
315,
747,
14,
2314,
26,
272,
2150,
747,
14,
2314,
59,
1813,
63,
1391,
61,
421,
199,
318,
3378,
8,
1531,
304,
523,
408,
16291,
282,
1414,
27,
2529,
715,
15,
797,
340,
2399,
4458,
1233,
365,
15,
374,
78,
1133,
378,
1041,
819,
870,
283,
9602,
2071,
83,
1674,
1275,
1275,
7,
450,
283,
1987,
904,
8,
1531,
9,
523,
299,
275,
9088,
63,
396,
63,
1208,
14,
22299,
8,
1531,
9,
523,
372,
299,
14,
32290,
436,
299,
14,
2224,
63,
600,
508,
378,
421,
199,
3,
710,
2295,
14,
221,
3254,
8,
20444,
32,
3098,
14,
957,
304,
24200,
314,
1021,
370,
8663,
2863,
199,
3,
9661,
543,
1233,
315,
9088,
63,
4785,
63,
265,
63,
5328,
63,
2796,
14,
647,
14,
199,
533,
3868,
1143,
3314,
6782,
774,
8,
8385,
63,
396,
63,
1208,
14,
1746,
304,
523,
408,
2925,
314,
7978,
13,
265,
13,
5328,
818,
1041,
819,
347,
3378,
14222,
8,
277,
12,
2589,
63,
1391,
63,
585,
12,
3305,
63,
585,
12,
1077,
63,
1633,
304,
272,
408,
16291,
9088,
63,
11964,
63,
265,
63,
5328,
63,
396,
63,
436,
22694,
626,
652,
1630,
272,
334,
269,
1630,
440,
9,
4458,
543,
282,
2222,
13,
4262,
1233,
14,
339,
3033,
26,
489,
2589,
63,
1391,
63,
585,
26,
259,
574,
402,
314,
18652,
63,
14731,
63,
615,
63,
13989,
3734,
717,
1750,
27,
488,
340,
314,
1750,
1077,
506,
15376,
14,
489,
3305,
63,
585,
26,
755,
574,
402,
314,
1553,
8385,
63,
4785,
63,
265,
63,
5328,
3305,
27,
717,
488,
340,
314,
3305,
1077,
440,
506,
3451,
14,
489,
1077,
63,
1633,
26,
420,
715,
17963,
314,
2240,
365,
1420,
370,
2449,
14,
272,
408,
339,
30306,
8,
2080,
11415,
63,
615,
63,
13989,
12,
2589,
63,
1391,
63,
585,
9,
339,
340,
2589,
63,
1391,
63,
585,
365,
488,
26,
489,
2589,
63,
1391,
63,
585,
63,
1328,
275,
283,
365,
440,
663,
7,
272,
587,
26,
489,
2589,
63,
1391,
63,
585,
63,
1328,
275,
14051,
435,
2589,
63,
1391,
63,
585,
339,
340,
3305,
63,
585,
365,
488,
26,
489,
3305,
275,
2125,
272,
916,
3305,
63,
585,
508,
283,
16,
356,
489,
3305,
275,
2850,
5,
83,
29,
16,
7,
450,
4221,
11415,
63,
615,
63,
13989,
272,
587,
26,
489,
3305,
275,
2850,
5,
83,
7,
450,
4221,
11415,
63,
615,
63,
13989,
339,
1414,
275,
359,
23017,
63,
3243,
61,
272,
340,
3305,
26,
489,
1414,
14,
740,
8,
4173,
9,
339,
340,
1077,
63,
1633,
26,
489,
1077,
63,
269,
63,
1397,
275,
283,
5626,
7,
272,
587,
26,
489,
1077,
63,
269,
63,
1397,
275,
283,
5626,
440
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8937,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
2925,
4475,
1379,
1159,
7978,
13,
265,
13,
5328,
818,
543,
4967,
6980,
14,
199,
199,
2765,
2884,
29761,
9088,
63,
11964,
63,
265,
63,
5328,
63,
396,
63,
334,
65,
2240,
5313,
543,
199,
13266,
1379,
9,
543,
3365,
22196,
436,
1414,
1004,
3285,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
20444,
32,
3098,
14,
957,
334,
12674,
1629,
951,
644,
290,
3171,
199,
199,
646,
747,
199,
646,
9088,
63,
396,
63,
1208,
421,
199,
3,
22296,
14,
199,
199,
3,
710,
1414,
1004,
3305,
367,
29310,
15,
2297,
14744,
314,
7978,
13,
265,
13,
5328,
818,
14,
199,
2080,
11415,
63,
615,
63,
13989,
275,
283,
8385,
63,
11964,
63,
265,
63,
5328,
7,
199,
199,
3,
6912,
370,
314,
9088,
63,
11964,
63,
265,
63,
5328,
63,
396,
63,
2240,
12,
10311,
543,
199,
3,
4967,
6980,
14,
199,
23017,
63,
3243,
275,
9088,
63,
396,
63,
1208,
14,
28967,
27602,
8,
272,
283,
8385,
63,
11964,
63,
265,
63,
5328,
63,
396,
15452,
421,
199,
3,
738,
17933,
14,
421,
199,
318,
30306,
8,
1813,
63,
1391,
12,
574,
304,
523,
408,
9899,
376,
3734,
1750,
370,
282,
1627,
574,
27,
625,
2193,
652,
1380,
314,
523,
1627,
574,
365,
488,
14,
523,
408,
819,
2589,
63,
1391,
275,
2589,
63,
1391,
14,
4142,
342,
523,
340,
574,
365,
440,
488,
26,
272,
747,
14,
2314,
59,
1813,
63,
1391,
61,
275,
574,
523,
916,
2589,
63,
1391,
315,
747,
14,
2314,
26,
272,
2150,
747,
14,
2314,
59,
1813,
63,
1391,
61,
421,
199,
318,
3378,
8,
1531,
304,
523,
408,
16291,
282,
1414,
27,
2529,
715,
15,
797,
340,
2399,
4458,
1233,
365,
15,
374,
78,
1133,
378,
1041,
819,
870,
283,
9602,
2071,
83,
1674,
1275,
1275,
7,
450,
283,
1987,
904,
8,
1531,
9,
523,
299,
275,
9088,
63,
396,
63,
1208,
14,
22299,
8,
1531,
9,
523,
372,
299,
14,
32290,
436,
299,
14,
2224,
63,
600,
508,
378,
421,
199,
3,
710,
2295,
14,
221,
3254,
8,
20444,
32,
3098,
14,
957,
304,
24200,
314,
1021,
370,
8663,
2863,
199,
3,
9661,
543,
1233,
315,
9088,
63,
4785,
63,
265,
63,
5328,
63,
2796,
14,
647,
14,
199,
533,
3868,
1143,
3314,
6782,
774,
8,
8385,
63,
396,
63,
1208,
14,
1746,
304,
523,
408,
2925,
314,
7978,
13,
265,
13,
5328,
818,
1041,
819,
347,
3378,
14222,
8,
277,
12,
2589,
63,
1391,
63,
585,
12,
3305,
63,
585,
12,
1077,
63,
1633,
304,
272,
408,
16291,
9088,
63,
11964,
63,
265,
63,
5328,
63,
396,
63,
436,
22694,
626,
652,
1630,
272,
334,
269,
1630,
440,
9,
4458,
543,
282,
2222,
13,
4262,
1233,
14,
339,
3033,
26,
489,
2589,
63,
1391,
63,
585,
26,
259,
574,
402,
314,
18652,
63,
14731,
63,
615,
63,
13989,
3734,
717,
1750,
27,
488,
340,
314,
1750,
1077,
506,
15376,
14,
489,
3305,
63,
585,
26,
755,
574,
402,
314,
1553,
8385,
63,
4785,
63,
265,
63,
5328,
3305,
27,
717,
488,
340,
314,
3305,
1077,
440,
506,
3451,
14,
489,
1077,
63,
1633,
26,
420,
715,
17963,
314,
2240,
365,
1420,
370,
2449,
14,
272,
408,
339,
30306,
8,
2080,
11415,
63,
615,
63,
13989,
12,
2589,
63,
1391,
63,
585,
9,
339,
340,
2589,
63,
1391,
63,
585,
365,
488,
26,
489,
2589,
63,
1391,
63,
585,
63,
1328,
275,
283,
365,
440,
663,
7,
272,
587,
26,
489,
2589,
63,
1391,
63,
585,
63,
1328,
275,
14051,
435,
2589,
63,
1391,
63,
585,
339,
340,
3305,
63,
585,
365,
488,
26,
489,
3305,
275,
2125,
272,
916,
3305,
63,
585,
508,
283,
16,
356,
489,
3305,
275,
2850,
5,
83,
29,
16,
7,
450,
4221,
11415,
63,
615,
63,
13989,
272,
587,
26,
489,
3305,
275,
2850,
5,
83,
7,
450,
4221,
11415,
63,
615,
63,
13989,
339,
1414,
275,
359,
23017,
63,
3243,
61,
272,
340,
3305,
26,
489,
1414,
14,
740,
8,
4173,
9,
339,
340,
1077,
63,
1633,
26,
489,
1077,
63,
269,
63,
1397,
275,
283,
5626,
7,
272,
587,
26,
489,
1077,
63,
269,
63,
1397,
275,
283,
5626,
440,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
stevekuznetsov/ansible
|
lib/ansible/plugins/strategy/debug.py
|
22
|
5050
|
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import cmd
import pprint
import sys
from ansible.plugins.strategy.linear import StrategyModule as LinearStrategyModule
from ansible.compat.six.moves import reduce
try:
from __main__ import display
except ImportError:
from ansible.utils.display import Display
display = Display()
class NextAction(object):
""" The next action after an interpreter's exit. """
REDO = 1
CONTINUE = 2
EXIT = 3
def __init__(self, result=EXIT):
self.result = result
class StrategyModule(LinearStrategyModule):
def __init__(self, tqm):
self.curr_tqm = tqm
super(StrategyModule, self).__init__(tqm)
def _queue_task(self, host, task, task_vars, play_context):
self.curr_host = host
self.curr_task = task
self.curr_task_vars = task_vars
self.curr_play_context = play_context
super(StrategyModule, self)._queue_task(host, task, task_vars, play_context)
def _process_pending_results(self, iterator, one_pass=False, max_passes=None):
if not hasattr(self, "curr_host"):
return super(StrategyModule, self)._process_pending_results(iterator, one_pass, max_passes)
prev_host_state = iterator.get_host_state(self.curr_host)
results = super(StrategyModule, self)._process_pending_results(iterator, one_pass)
while self._need_debug(results):
next_action = NextAction()
dbg = Debugger(self, results, next_action)
dbg.cmdloop()
if next_action.result == NextAction.REDO:
# rollback host state
self.curr_tqm.clear_failed_hosts()
iterator._host_states[self.curr_host.name] = prev_host_state
if reduce(lambda total, res : res.is_failed() or total, results, False):
self._tqm._stats.failures[self.curr_host.name] -= 1
elif reduce(lambda total, res : res.is_unreachable() or total, results, False):
self._tqm._stats.dark[self.curr_host.name] -= 1
# redo
super(StrategyModule, self)._queue_task(self.curr_host, self.curr_task, self.curr_task_vars, self.curr_play_context)
results = super(StrategyModule, self)._process_pending_results(iterator, one_pass)
elif next_action.result == NextAction.CONTINUE:
break
elif next_action.result == NextAction.EXIT:
exit(1)
return results
def _need_debug(self, results):
return reduce(lambda total, res : res.is_failed() or res.is_unreachable() or total, results, False)
class Debugger(cmd.Cmd):
prompt = '(debug) ' # debugger
prompt_continuous = '> ' # multiple lines
def __init__(self, strategy_module, results, next_action):
# cmd.Cmd is old-style class
cmd.Cmd.__init__(self)
self.intro = "Debugger invoked"
self.scope = {}
self.scope['task'] = strategy_module.curr_task
self.scope['vars'] = strategy_module.curr_task_vars
self.scope['host'] = strategy_module.curr_host
self.scope['result'] = results[0]._result
self.scope['results'] = results # for debug of this debugger
self.next_action = next_action
def cmdloop(self):
try:
cmd.Cmd.cmdloop(self)
except KeyboardInterrupt:
pass
def do_EOF(self, args):
return self.do_quit(args)
def do_quit(self, args):
display.display('aborted')
self.next_action.result = NextAction.EXIT
return True
do_q = do_quit
def do_continue(self, args):
self.next_action.result = NextAction.CONTINUE
return True
do_c = do_continue
def do_redo(self, args):
self.next_action.result = NextAction.REDO
return True
do_r = do_redo
def evaluate(self, args):
try:
return eval(args, globals(), self.scope)
except:
t, v = sys.exc_info()[:2]
if isinstance(t, str):
exc_type_name = t
else:
exc_type_name = t.__name__
display.display('***%s:%s' % (exc_type_name, repr(v)))
raise
def do_p(self, args):
try:
result = self.evaluate(args)
display.display(pprint.pformat(result))
except:
pass
def execute(self, args):
try:
code = compile(args + '\n', '<stdin>', 'single')
exec(code, globals(), self.scope)
except:
t, v = sys.exc_info()[:2]
if isinstance(t, str):
exc_type_name = t
else:
exc_type_name = t.__name__
display.display('***%s:%s' % (exc_type_name, repr(v)))
raise
def default(self, line):
try:
self.execute(line)
display.display(pprint.pformat(result))
except:
pass
|
gpl-3.0
|
[
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,
2088,
199,
646,
10933,
199,
646,
984,
199,
199,
504,
3242,
14,
5265,
14,
8590,
14,
6676,
492,
8303,
5374,
2377,
465,
12489,
16199,
2377,
199,
504,
3242,
14,
5819,
14,
4174,
14,
4912,
492,
7114,
199,
199,
893,
26,
272,
687,
636,
973,
363,
492,
2929,
199,
2590,
3545,
26,
272,
687,
3242,
14,
1208,
14,
2918,
492,
12175,
272,
2929,
275,
12175,
342,
421,
199,
533,
16840,
3310,
8,
785,
304,
272,
408,
710,
2163,
1595,
2410,
376,
12693,
1159,
4458,
14,
408,
272,
23443,
47,
275,
413,
272,
7408,
568,
4187,
275,
499,
272,
3651,
649,
275,
650,
339,
347,
636,
826,
721,
277,
12,
754,
29,
17219,
304,
267,
291,
14,
1099,
275,
754,
421,
199,
533,
8303,
5374,
2377,
8,
10608,
16199,
2377,
304,
272,
347,
636,
826,
721,
277,
12,
307,
17976,
304,
267,
291,
14,
9808,
63,
24400,
275,
307,
17976,
267,
1613,
8,
16199,
2377,
12,
291,
2843,
826,
721,
24400,
9,
339,
347,
485,
1825,
63,
1765,
8,
277,
12,
1591,
12,
2120,
12,
2120,
63,
2936,
12,
5232,
63,
1100,
304,
267,
291,
14,
9808,
63,
1102,
275,
1591,
267,
291,
14,
9808,
63,
1765,
275,
2120,
267,
291,
14,
9808,
63,
1765,
63,
2936,
275,
2120,
63,
2936,
267,
291,
14,
9808,
63,
2802,
63,
1100,
275,
5232,
63,
1100,
398,
1613,
8,
16199,
2377,
12,
291,
10445,
1825,
63,
1765,
8,
1102,
12,
2120,
12,
2120,
63,
2936,
12,
5232,
63,
1100,
9,
339,
347,
485,
1412,
63,
6455,
63,
2604,
8,
277,
12,
6122,
12,
1373,
63,
1529,
29,
797,
12,
1390,
63,
16027,
29,
403,
304,
267,
340,
440,
2688,
8,
277,
12,
298,
9808,
63,
1102,
2349,
288,
372,
1613,
8,
16199,
2377,
12,
291,
10445,
1412,
63,
6455,
63,
2604,
8,
5778,
12,
1373,
63,
1529,
12,
1390,
63,
16027,
9,
398,
5071,
63,
1102,
63,
929,
275,
6122,
14,
362,
63,
1102,
63,
929,
8,
277,
14,
9808,
63,
1102,
9,
267,
2058,
275,
1613,
8,
16199,
2377,
12,
291,
10445,
1412,
63,
6455,
63,
2604,
8,
5778,
12,
1373,
63,
1529,
9,
398,
1830,
291,
423,
9321,
63,
1757,
8,
2604,
304,
288,
2163,
63,
1287,
275,
16840,
3310,
342,
288,
24465,
275,
14245,
836,
8,
277,
12,
2058,
12,
2163,
63,
1287,
9,
288,
24465,
14,
1760,
3813,
342,
953,
340,
2163,
63,
1287,
14,
1099,
508,
16840,
3310,
14,
907,
1649,
26,
355,
327,
16475,
1591,
1174,
355,
291,
14,
9808,
63,
24400,
14,
3584,
63,
4892,
63,
5146,
342,
355,
6122,
423,
1102,
63,
4981,
59,
277,
14,
9808,
63,
1102,
14,
354,
61,
275,
5071,
63,
1102,
63,
929,
355,
340,
7114,
8,
2734,
3141,
12,
522,
520,
522,
14,
374,
63,
4892,
342,
503,
3141,
12,
2058,
12,
756,
304,
490,
291,
423,
24400,
423,
3200,
14,
9968,
59,
277,
14,
9808,
63,
1102,
14,
354,
61,
4862,
413,
355,
916,
7114,
8,
2734,
3141,
12,
522,
520,
522,
14,
374,
63,
26522,
342,
503,
3141,
12,
2058,
12,
756,
304,
490,
291,
423,
24400,
423,
3200,
14,
13625,
59,
277,
14,
9808,
63,
1102,
14,
354,
61,
4862,
413,
2234,
327,
295,
1117,
355,
1613,
8,
16199,
2377,
12,
291,
10445,
1825,
63,
1765,
8,
277,
14,
9808,
63,
1102,
12,
291,
14,
9808,
63,
1765,
12,
291,
14,
9808,
63,
1765,
63,
2936,
12,
291,
14,
9808,
63,
2802,
63,
1100,
9,
355,
2058,
275,
1613,
8,
16199,
2377,
12,
291,
10445,
1412,
63,
6455,
63,
2604,
8,
5778,
12,
1373,
63,
1529,
9,
288,
916,
2163,
63,
1287,
14,
1099,
508,
16840,
3310,
14,
26663,
4187,
26,
355,
2059,
288,
916,
2163,
63,
1287,
14,
1099,
508,
16840,
3310,
14,
17219,
26,
355,
4458,
8,
17,
9,
398,
372,
2058,
339,
347,
485,
9321,
63,
1757,
8,
277,
12,
2058,
304,
267,
372,
7114,
8,
2734,
3141,
12,
522,
520,
522,
14,
374,
63,
4892,
342,
503,
522,
14,
374,
63,
26522,
342,
503,
3141,
12,
2058,
12,
756,
9,
421,
199,
533,
14245,
836,
8,
1760,
14,
7874,
304,
272,
8457,
275,
8189,
1757,
9,
283,
221,
327,
14958,
272,
8457,
63,
23458,
275,
12696,
283,
221,
327,
3663,
2385,
339,
347,
636,
826,
721,
277,
12,
10054,
63,
578,
12,
2058,
12,
2163,
63,
1287,
304,
267,
327,
2088,
14,
7874,
365,
2269,
13,
2487,
1021,
267,
2088,
14,
7874,
855,
826,
721,
277,
9,
398,
291,
14,
18206,
275,
298,
31521,
10302,
2,
267,
291,
14,
2645,
275,
1052,
267,
291,
14,
2645,
459,
1765,
418,
275,
10054,
63,
578,
14,
9808,
63,
1765,
267,
291,
14,
2645,
459,
2936,
418,
275,
10054,
63,
578,
14,
9808,
63,
1765,
63,
2936,
267,
291,
14,
2645,
459,
1102,
418,
275,
10054,
63,
578,
14,
9808,
63,
1102,
267,
291,
14,
2645,
459,
1099,
418,
275,
2058,
59,
16,
18289,
1099,
267,
291,
14,
2645,
459,
2604,
418,
275,
2058,
221,
327,
367,
3105,
402,
642,
14958,
267,
291,
14,
2184,
63,
1287,
275,
2163,
63,
1287,
339,
347,
2088,
3813,
8,
277,
304,
267,
862,
26,
288,
2088,
14,
7874,
14,
1760,
3813,
8,
277,
9,
267,
871,
13483,
26,
288,
986,
339,
347,
886,
63,
13178,
8,
277,
12,
1249,
304,
267,
372,
291,
14,
1117,
63,
10589,
8,
589,
9,
339,
347,
886,
63,
10589,
8,
277,
12,
1249,
304,
267,
2929,
14,
2918,
360,
371,
1376,
358,
267,
291,
14,
2184,
63,
1287,
14,
1099,
275,
16840,
3310,
14,
17219,
267,
372,
715,
339,
886,
63,
81,
275,
886,
63,
10589,
339,
347,
886,
63,
6958,
8,
277,
12,
1249,
304,
267,
291,
14,
2184,
63,
1287,
14,
1099,
275,
16840,
3310,
14,
26663,
4187,
267,
372,
715,
339,
886,
63,
67,
275,
886,
63,
6958,
339,
347,
886,
63,
30938,
8,
277,
12,
1249,
304,
267,
291,
14,
2184,
63,
1287,
14,
1099,
275,
16840,
3310,
14,
907,
1649,
267,
372,
715,
339,
886,
63,
82,
275,
886,
63,
30938,
339,
347,
9352,
8,
277,
12
] |
[
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,
2088,
199,
646,
10933,
199,
646,
984,
199,
199,
504,
3242,
14,
5265,
14,
8590,
14,
6676,
492,
8303,
5374,
2377,
465,
12489,
16199,
2377,
199,
504,
3242,
14,
5819,
14,
4174,
14,
4912,
492,
7114,
199,
199,
893,
26,
272,
687,
636,
973,
363,
492,
2929,
199,
2590,
3545,
26,
272,
687,
3242,
14,
1208,
14,
2918,
492,
12175,
272,
2929,
275,
12175,
342,
421,
199,
533,
16840,
3310,
8,
785,
304,
272,
408,
710,
2163,
1595,
2410,
376,
12693,
1159,
4458,
14,
408,
272,
23443,
47,
275,
413,
272,
7408,
568,
4187,
275,
499,
272,
3651,
649,
275,
650,
339,
347,
636,
826,
721,
277,
12,
754,
29,
17219,
304,
267,
291,
14,
1099,
275,
754,
421,
199,
533,
8303,
5374,
2377,
8,
10608,
16199,
2377,
304,
272,
347,
636,
826,
721,
277,
12,
307,
17976,
304,
267,
291,
14,
9808,
63,
24400,
275,
307,
17976,
267,
1613,
8,
16199,
2377,
12,
291,
2843,
826,
721,
24400,
9,
339,
347,
485,
1825,
63,
1765,
8,
277,
12,
1591,
12,
2120,
12,
2120,
63,
2936,
12,
5232,
63,
1100,
304,
267,
291,
14,
9808,
63,
1102,
275,
1591,
267,
291,
14,
9808,
63,
1765,
275,
2120,
267,
291,
14,
9808,
63,
1765,
63,
2936,
275,
2120,
63,
2936,
267,
291,
14,
9808,
63,
2802,
63,
1100,
275,
5232,
63,
1100,
398,
1613,
8,
16199,
2377,
12,
291,
10445,
1825,
63,
1765,
8,
1102,
12,
2120,
12,
2120,
63,
2936,
12,
5232,
63,
1100,
9,
339,
347,
485,
1412,
63,
6455,
63,
2604,
8,
277,
12,
6122,
12,
1373,
63,
1529,
29,
797,
12,
1390,
63,
16027,
29,
403,
304,
267,
340,
440,
2688,
8,
277,
12,
298,
9808,
63,
1102,
2349,
288,
372,
1613,
8,
16199,
2377,
12,
291,
10445,
1412,
63,
6455,
63,
2604,
8,
5778,
12,
1373,
63,
1529,
12,
1390,
63,
16027,
9,
398,
5071,
63,
1102,
63,
929,
275,
6122,
14,
362,
63,
1102,
63,
929,
8,
277,
14,
9808,
63,
1102,
9,
267,
2058,
275,
1613,
8,
16199,
2377,
12,
291,
10445,
1412,
63,
6455,
63,
2604,
8,
5778,
12,
1373,
63,
1529,
9,
398,
1830,
291,
423,
9321,
63,
1757,
8,
2604,
304,
288,
2163,
63,
1287,
275,
16840,
3310,
342,
288,
24465,
275,
14245,
836,
8,
277,
12,
2058,
12,
2163,
63,
1287,
9,
288,
24465,
14,
1760,
3813,
342,
953,
340,
2163,
63,
1287,
14,
1099,
508,
16840,
3310,
14,
907,
1649,
26,
355,
327,
16475,
1591,
1174,
355,
291,
14,
9808,
63,
24400,
14,
3584,
63,
4892,
63,
5146,
342,
355,
6122,
423,
1102,
63,
4981,
59,
277,
14,
9808,
63,
1102,
14,
354,
61,
275,
5071,
63,
1102,
63,
929,
355,
340,
7114,
8,
2734,
3141,
12,
522,
520,
522,
14,
374,
63,
4892,
342,
503,
3141,
12,
2058,
12,
756,
304,
490,
291,
423,
24400,
423,
3200,
14,
9968,
59,
277,
14,
9808,
63,
1102,
14,
354,
61,
4862,
413,
355,
916,
7114,
8,
2734,
3141,
12,
522,
520,
522,
14,
374,
63,
26522,
342,
503,
3141,
12,
2058,
12,
756,
304,
490,
291,
423,
24400,
423,
3200,
14,
13625,
59,
277,
14,
9808,
63,
1102,
14,
354,
61,
4862,
413,
2234,
327,
295,
1117,
355,
1613,
8,
16199,
2377,
12,
291,
10445,
1825,
63,
1765,
8,
277,
14,
9808,
63,
1102,
12,
291,
14,
9808,
63,
1765,
12,
291,
14,
9808,
63,
1765,
63,
2936,
12,
291,
14,
9808,
63,
2802,
63,
1100,
9,
355,
2058,
275,
1613,
8,
16199,
2377,
12,
291,
10445,
1412,
63,
6455,
63,
2604,
8,
5778,
12,
1373,
63,
1529,
9,
288,
916,
2163,
63,
1287,
14,
1099,
508,
16840,
3310,
14,
26663,
4187,
26,
355,
2059,
288,
916,
2163,
63,
1287,
14,
1099,
508,
16840,
3310,
14,
17219,
26,
355,
4458,
8,
17,
9,
398,
372,
2058,
339,
347,
485,
9321,
63,
1757,
8,
277,
12,
2058,
304,
267,
372,
7114,
8,
2734,
3141,
12,
522,
520,
522,
14,
374,
63,
4892,
342,
503,
522,
14,
374,
63,
26522,
342,
503,
3141,
12,
2058,
12,
756,
9,
421,
199,
533,
14245,
836,
8,
1760,
14,
7874,
304,
272,
8457,
275,
8189,
1757,
9,
283,
221,
327,
14958,
272,
8457,
63,
23458,
275,
12696,
283,
221,
327,
3663,
2385,
339,
347,
636,
826,
721,
277,
12,
10054,
63,
578,
12,
2058,
12,
2163,
63,
1287,
304,
267,
327,
2088,
14,
7874,
365,
2269,
13,
2487,
1021,
267,
2088,
14,
7874,
855,
826,
721,
277,
9,
398,
291,
14,
18206,
275,
298,
31521,
10302,
2,
267,
291,
14,
2645,
275,
1052,
267,
291,
14,
2645,
459,
1765,
418,
275,
10054,
63,
578,
14,
9808,
63,
1765,
267,
291,
14,
2645,
459,
2936,
418,
275,
10054,
63,
578,
14,
9808,
63,
1765,
63,
2936,
267,
291,
14,
2645,
459,
1102,
418,
275,
10054,
63,
578,
14,
9808,
63,
1102,
267,
291,
14,
2645,
459,
1099,
418,
275,
2058,
59,
16,
18289,
1099,
267,
291,
14,
2645,
459,
2604,
418,
275,
2058,
221,
327,
367,
3105,
402,
642,
14958,
267,
291,
14,
2184,
63,
1287,
275,
2163,
63,
1287,
339,
347,
2088,
3813,
8,
277,
304,
267,
862,
26,
288,
2088,
14,
7874,
14,
1760,
3813,
8,
277,
9,
267,
871,
13483,
26,
288,
986,
339,
347,
886,
63,
13178,
8,
277,
12,
1249,
304,
267,
372,
291,
14,
1117,
63,
10589,
8,
589,
9,
339,
347,
886,
63,
10589,
8,
277,
12,
1249,
304,
267,
2929,
14,
2918,
360,
371,
1376,
358,
267,
291,
14,
2184,
63,
1287,
14,
1099,
275,
16840,
3310,
14,
17219,
267,
372,
715,
339,
886,
63,
81,
275,
886,
63,
10589,
339,
347,
886,
63,
6958,
8,
277,
12,
1249,
304,
267,
291,
14,
2184,
63,
1287,
14,
1099,
275,
16840,
3310,
14,
26663,
4187,
267,
372,
715,
339,
886,
63,
67,
275,
886,
63,
6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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
] |
nik-hil/fastai
|
deeplearning2/rossman_exp.py
|
10
|
5451
|
train_ratio=0.9
use_dict=True
use_scaler=False
init_emb=False
split_contins=True
samp_size = 100000
#samp_size = 0
import math, keras, datetime, pandas as pd, numpy as np, keras.backend as K
import matplotlib.pyplot as plt, xgboost, operator, random, pickle, os
from sklearn_pandas import DataFrameMapper
from sklearn.preprocessing import LabelEncoder, Imputer, StandardScaler
from keras.models import Model
from keras.layers import merge, Input
from keras.layers.core import Dense, Activation, Reshape, Flatten, Dropout
from keras.layers.embeddings import Embedding
from keras.optimizers import Adam
from keras.layers.normalization import BatchNormalization
from keras.regularizers import l2
from keras import initializations
np.set_printoptions(4)
cfg = K.tf.ConfigProto()
cfg.gpu_options.allow_growth = True
K.set_session(K.tf.Session(config=cfg))
os.chdir('data/rossman')
cat_var_dict = {'Store': 50, 'DayOfWeek': 6, 'Year': 2, 'Month': 6,
'Day': 10, 'StateHoliday': 3, 'CompetitionMonthsOpen': 2,
'Promo2Weeks': 1, 'StoreType': 2, 'Assortment': 3, 'PromoInterval': 3,
'CompetitionOpenSinceYear': 4, 'Promo2SinceYear': 4, 'State': 6,
'Week': 2, 'Events': 4, 'Promo_fw': 1,
'Promo_bw': 1, 'StateHoliday_fw': 1,
'StateHoliday_bw': 1, 'SchoolHoliday_fw': 1,
'SchoolHoliday_bw': 1}
cats, contins= [o for n,o in np.load('vars.npz').items()]
y = np.load('deps.npz').items()[0][1]
if samp_size != 0:
np.random.seed(42)
idxs = sorted(np.random.choice(len(y), samp_size, replace=False))
cats= cats[idxs]
contins= contins[idxs]
y= y[idxs]
n=len(y)
train_size = int(n*train_ratio)
contins_trn_orig, contins_val_orig = contins[:train_size], contins[train_size:]
cats_trn, cats_val = cats[:train_size], cats[train_size:]
y_trn, y_val = y[:train_size], y[train_size:]
contin_map_fit = pickle.load(open('contin_maps.pickle', 'rb'))
cat_map_fit = pickle.load(open('cat_maps.pickle', 'rb'))
def cat_map_info(feat): return feat[0], len(feat[1].classes_)
co_enc = StandardScaler().fit(contins_trn_orig)
tf_contins_trn = co_enc.transform(contins_trn_orig)
tf_contins_val = co_enc.transform(contins_val_orig)
"""
def rmspe(y_pred, targ = y_valid_orig):
return math.sqrt(np.square((targ - y_pred)/targ).mean())
def log_max_inv(preds, mx = max_log_y): return np.exp(preds * mx)
def normalize_inv(preds): return preds * ystd + ymean
"""
def split_cols(arr): return np.hsplit(arr,arr.shape[1])
def emb_init(shape, name=None):
return initializations.uniform(shape, scale=0.6/shape[1], name=name)
def get_emb(feat):
name, c = cat_map_info(feat)
if use_dict:
c2 = cat_var_dict[name]
else:
c2 = (c+2)//3
if c2>50: c2=50
inp = Input((1,), dtype='int64', name=name+'_in')
if init_emb:
u = Flatten(name=name+'_flt')(Embedding(c, c2, input_length=1)(inp))
else:
u = Flatten(name=name+'_flt')(Embedding(c, c2, input_length=1, init=emb_init)(inp))
return inp,u
def get_contin(feat):
name = feat[0][0]
inp = Input((1,), name=name+'_in')
return inp, Dense(1, name=name+'_d')(inp)
def split_data():
if split_contins:
map_train = split_cols(cats_trn) + split_cols(contins_trn)
map_valid = split_cols(cats_val) + split_cols(contins_val)
else:
map_train = split_cols(cats_trn) + [contins_trn]
map_valid = split_cols(cats_val) + [contins_val]
return (map_train, map_valid)
def get_contin_one():
n_contin = contins_trn.shape[1]
contin_inp = Input((n_contin,), name='contin')
contin_out = BatchNormalization()(contin_inp)
return contin_inp, contin_out
def train(model, map_train, map_valid, bs=128, ne=10):
return model.fit(map_train, y_trn, batch_size=bs, nb_epoch=ne,
verbose=0, validation_data=(map_valid, y_val))
def get_model():
if split_contins:
conts = [get_contin(feat) for feat in contin_map_fit.features]
cont_out = [d for inp,d in conts]
cont_inp = [inp for inp,d in conts]
else:
contin_inp, contin_out = get_contin_one()
cont_out = [contin_out]
cont_inp = [contin_inp]
embs = [get_emb(feat) for feat in cat_map_fit.features]
x = merge([emb for inp,emb in embs] + cont_out, mode='concat')
x = Dropout(0.02)(x)
x = Dense(1000, activation='relu', init='uniform')(x)
x = Dense(500, activation='relu', init='uniform')(x)
x = Dense(1, activation='sigmoid')(x)
model = Model([inp for inp,emb in embs] + cont_inp, x)
model.compile('adam', 'mean_absolute_error')
#model.compile(Adam(), 'mse')
return model
for split_contins in [True, False]:
for use_dict in [True, False]:
for use_scaler in [True, False]:
for init_emb in [True, False]:
print ({'split_contins':split_contins, 'use_dict':use_dict,
'use_scaler':use_scaler, 'init_emb':init_emb})
if use_scaler:
contins_trn = tf_contins_trn
contins_val = tf_contins_val
else:
contins_trn = contins_trn_orig
contins_val = contins_val_orig
map_train, map_valid = split_data()
model = get_model()
hist = np.array(train(model, map_train, map_valid, 128, 10)
.history['val_loss'])
print(hist)
print(hist.min())
|
apache-2.0
|
[
2834,
63,
6884,
29,
16,
14,
25,
199,
1180,
63,
807,
29,
549,
199,
1180,
63,
11494,
29,
797,
199,
826,
63,
18847,
29,
797,
199,
1294,
63,
12875,
83,
29,
549,
199,
16557,
63,
890,
275,
25761,
199,
3,
16557,
63,
890,
275,
378,
199,
199,
646,
3473,
12,
11708,
12,
2197,
12,
10634,
465,
6454,
12,
2680,
465,
980,
12,
11708,
14,
4620,
465,
1804,
199,
646,
8027,
14,
13563,
465,
4488,
12,
671,
71,
15589,
12,
4182,
12,
2196,
12,
5927,
12,
747,
199,
504,
6357,
63,
15718,
492,
10071,
11880,
199,
504,
6357,
14,
21402,
492,
10354,
6679,
12,
8362,
2699,
12,
9739,
24274,
199,
504,
11708,
14,
992,
492,
5822,
199,
504,
11708,
14,
4359,
492,
5389,
12,
6924,
199,
504,
11708,
14,
4359,
14,
1018,
492,
20847,
12,
29441,
12,
3591,
15221,
12,
19005,
724,
12,
18110,
548,
199,
504,
11708,
14,
4359,
14,
32719,
492,
24297,
1098,
199,
504,
11708,
14,
6433,
6315,
492,
4431,
455,
199,
504,
11708,
14,
4359,
14,
22384,
492,
17206,
29169,
199,
504,
11708,
14,
7898,
6315,
492,
634,
18,
199,
504,
11708,
492,
2536,
12270,
199,
1590,
14,
409,
63,
1361,
1419,
8,
20,
9,
199,
199,
4128,
275,
1804,
14,
3249,
14,
2028,
8548,
342,
199,
4128,
14,
6477,
63,
1419,
14,
3306,
63,
22890,
273,
275,
715,
199,
43,
14,
409,
63,
1730,
8,
43,
14,
3249,
14,
4434,
8,
888,
29,
4128,
430,
199,
199,
736,
14,
8563,
360,
576,
15,
3685,
1237,
358,
199,
3385,
63,
1391,
63,
807,
275,
791,
5502,
356,
5238,
12,
283,
12631,
3466,
20995,
356,
1227,
12,
283,
15731,
356,
499,
12,
283,
14306,
356,
1227,
12,
272,
283,
12631,
356,
1616,
12,
283,
2223,
17810,
317,
2977,
356,
650,
12,
283,
2404,
69,
3348,
14306,
83,
4299,
356,
499,
12,
272,
283,
19250,
79,
18,
20995,
83,
356,
413,
12,
283,
5502,
804,
356,
499,
12,
283,
9824,
361,
434,
356,
650,
12,
283,
19250,
79,
8227,
356,
650,
12,
272,
283,
2404,
69,
3348,
4299,
24430,
15731,
356,
841,
12,
283,
19250,
79,
18,
24430,
15731,
356,
841,
12,
283,
2223,
356,
1227,
12,
272,
283,
20995,
356,
499,
12,
283,
11770,
356,
841,
12,
283,
19250,
79,
63,
8835,
356,
413,
12,
272,
283,
19250,
79,
63,
12415,
356,
413,
12,
283,
2223,
17810,
317,
2977,
63,
8835,
356,
413,
12,
272,
283,
2223,
17810,
317,
2977,
63,
12415,
356,
413,
12,
283,
51,
15089,
17810,
317,
2977,
63,
8835,
356,
413,
12,
272,
283,
51,
15089,
17810,
317,
2977,
63,
12415,
356,
413,
93,
199,
199,
25729,
12,
9832,
83,
29,
359,
79,
367,
302,
12,
79,
315,
980,
14,
912,
360,
2936,
14,
1590,
90,
1959,
1744,
5106,
199,
89,
275,
980,
14,
912,
360,
5846,
14,
1590,
90,
1959,
1744,
3430,
16,
1527,
17,
61,
199,
199,
692,
2937,
311,
63,
890,
1137,
378,
26,
272,
980,
14,
2355,
14,
5176,
8,
2260,
9,
272,
4280,
83,
275,
3355,
8,
1590,
14,
2355,
14,
5095,
8,
552,
8,
89,
395,
2937,
311,
63,
890,
12,
3350,
29,
797,
430,
272,
286,
1956,
29,
286,
1956,
59,
30015,
61,
272,
9832,
83,
29,
9832,
83,
59,
30015,
61,
272,
612,
29,
612,
59,
30015,
61,
199,
199,
78,
29,
552,
8,
89,
9,
199,
2834,
63,
890,
275,
1109,
8,
78,
10,
2834,
63,
6884,
9,
199,
199,
12875,
83,
63,
454,
78,
63,
2981,
12,
9832,
83,
63,
637,
63,
2981,
275,
9832,
83,
1491,
2834,
63,
890,
467,
9832,
83,
59,
2834,
63,
890,
2938,
199,
25729,
63,
454,
78,
12,
286,
1956,
63,
637,
275,
286,
1956,
1491,
2834,
63,
890,
467,
286,
1956,
59,
2834,
63,
890,
2938,
199,
89,
63,
454,
78,
12,
612,
63,
637,
275,
612,
1491,
2834,
63,
890,
467,
612,
59,
2834,
63,
890,
2938,
199,
199,
12875,
63,
1130,
63,
3269,
275,
5927,
14,
912,
8,
1490,
360,
12875,
63,
8919,
14,
8092,
297,
283,
4848,
1333,
199,
3385,
63,
1130,
63,
3269,
275,
5927,
14,
912,
8,
1490,
360,
3385,
63,
8919,
14,
8092,
297,
283,
4848,
1333,
199,
199,
318,
6230,
63,
1130,
63,
815,
8,
11873,
304,
372,
13953,
59,
16,
467,
822,
8,
11873,
59,
17,
1055,
2888,
4602,
199,
199,
331,
63,
10945,
275,
9739,
24274,
1252,
3269,
8,
12875,
83,
63,
454,
78,
63,
2981,
9,
199,
3249,
63,
12875,
83,
63,
454,
78,
275,
512,
63,
10945,
14,
4711,
8,
12875,
83,
63,
454,
78,
63,
2981,
9,
199,
3249,
63,
12875,
83,
63,
637,
275,
512,
63,
10945,
14,
4711,
8,
12875,
83,
63,
637,
63,
2981,
9,
421,
199,
624,
199,
318,
32205,
321,
8,
89,
63,
5991,
12,
26483,
275,
612,
63,
1078,
63,
2981,
304,
272,
372,
3473,
14,
5079,
8,
1590,
14,
9646,
1332,
29919,
446,
612,
63,
5991,
2447,
29919,
680,
3670,
1012,
199,
318,
943,
63,
988,
63,
5350,
8,
28296,
12,
8728,
275,
1390,
63,
793,
63,
89,
304,
372,
980,
14,
1474,
8,
28296,
627,
8728,
9,
199,
318,
7666,
63,
5350,
8,
28296,
304,
372,
24960,
627,
612,
1516,
435,
612,
3670,
199,
624,
421,
199,
318,
3715,
63,
4574,
8,
5250,
304,
372,
980,
14,
72,
1294,
8,
5250,
12,
5250,
14,
1392,
59,
17,
566,
421,
199,
318,
25316,
63,
826,
8,
1392,
12,
536,
29,
403,
304,
272,
372,
2536,
12270,
14,
8830,
8,
1392,
12,
4666,
29,
16,
14,
22,
15,
1392,
59,
17,
467,
536,
29,
354,
9,
421,
199,
318,
664,
63,
18847,
8,
11873,
304,
272,
536,
12,
286,
275,
6230,
63,
1130,
63,
815,
8,
11873,
9,
272,
340,
675,
63,
807,
26,
267,
286,
18,
275,
6230,
63,
1391,
63,
807,
59,
354,
61,
272,
587,
26,
267,
286,
18,
275,
334,
67,
11,
18,
28428,
19,
267,
340,
286,
18,
30,
1400,
26,
286,
18,
29,
1400,
272,
10702,
275,
6924,
1332,
17,
4706,
2152,
534,
442,
772,
297,
536,
29,
354,
28323,
262,
358,
272,
340,
4205,
63,
18847,
26,
267,
399,
275,
19005,
724,
8,
354,
29,
354,
28323,
26057,
7533,
27907,
8,
67,
12,
286,
18,
12
] |
[
63,
6884,
29,
16,
14,
25,
199,
1180,
63,
807,
29,
549,
199,
1180,
63,
11494,
29,
797,
199,
826,
63,
18847,
29,
797,
199,
1294,
63,
12875,
83,
29,
549,
199,
16557,
63,
890,
275,
25761,
199,
3,
16557,
63,
890,
275,
378,
199,
199,
646,
3473,
12,
11708,
12,
2197,
12,
10634,
465,
6454,
12,
2680,
465,
980,
12,
11708,
14,
4620,
465,
1804,
199,
646,
8027,
14,
13563,
465,
4488,
12,
671,
71,
15589,
12,
4182,
12,
2196,
12,
5927,
12,
747,
199,
504,
6357,
63,
15718,
492,
10071,
11880,
199,
504,
6357,
14,
21402,
492,
10354,
6679,
12,
8362,
2699,
12,
9739,
24274,
199,
504,
11708,
14,
992,
492,
5822,
199,
504,
11708,
14,
4359,
492,
5389,
12,
6924,
199,
504,
11708,
14,
4359,
14,
1018,
492,
20847,
12,
29441,
12,
3591,
15221,
12,
19005,
724,
12,
18110,
548,
199,
504,
11708,
14,
4359,
14,
32719,
492,
24297,
1098,
199,
504,
11708,
14,
6433,
6315,
492,
4431,
455,
199,
504,
11708,
14,
4359,
14,
22384,
492,
17206,
29169,
199,
504,
11708,
14,
7898,
6315,
492,
634,
18,
199,
504,
11708,
492,
2536,
12270,
199,
1590,
14,
409,
63,
1361,
1419,
8,
20,
9,
199,
199,
4128,
275,
1804,
14,
3249,
14,
2028,
8548,
342,
199,
4128,
14,
6477,
63,
1419,
14,
3306,
63,
22890,
273,
275,
715,
199,
43,
14,
409,
63,
1730,
8,
43,
14,
3249,
14,
4434,
8,
888,
29,
4128,
430,
199,
199,
736,
14,
8563,
360,
576,
15,
3685,
1237,
358,
199,
3385,
63,
1391,
63,
807,
275,
791,
5502,
356,
5238,
12,
283,
12631,
3466,
20995,
356,
1227,
12,
283,
15731,
356,
499,
12,
283,
14306,
356,
1227,
12,
272,
283,
12631,
356,
1616,
12,
283,
2223,
17810,
317,
2977,
356,
650,
12,
283,
2404,
69,
3348,
14306,
83,
4299,
356,
499,
12,
272,
283,
19250,
79,
18,
20995,
83,
356,
413,
12,
283,
5502,
804,
356,
499,
12,
283,
9824,
361,
434,
356,
650,
12,
283,
19250,
79,
8227,
356,
650,
12,
272,
283,
2404,
69,
3348,
4299,
24430,
15731,
356,
841,
12,
283,
19250,
79,
18,
24430,
15731,
356,
841,
12,
283,
2223,
356,
1227,
12,
272,
283,
20995,
356,
499,
12,
283,
11770,
356,
841,
12,
283,
19250,
79,
63,
8835,
356,
413,
12,
272,
283,
19250,
79,
63,
12415,
356,
413,
12,
283,
2223,
17810,
317,
2977,
63,
8835,
356,
413,
12,
272,
283,
2223,
17810,
317,
2977,
63,
12415,
356,
413,
12,
283,
51,
15089,
17810,
317,
2977,
63,
8835,
356,
413,
12,
272,
283,
51,
15089,
17810,
317,
2977,
63,
12415,
356,
413,
93,
199,
199,
25729,
12,
9832,
83,
29,
359,
79,
367,
302,
12,
79,
315,
980,
14,
912,
360,
2936,
14,
1590,
90,
1959,
1744,
5106,
199,
89,
275,
980,
14,
912,
360,
5846,
14,
1590,
90,
1959,
1744,
3430,
16,
1527,
17,
61,
199,
199,
692,
2937,
311,
63,
890,
1137,
378,
26,
272,
980,
14,
2355,
14,
5176,
8,
2260,
9,
272,
4280,
83,
275,
3355,
8,
1590,
14,
2355,
14,
5095,
8,
552,
8,
89,
395,
2937,
311,
63,
890,
12,
3350,
29,
797,
430,
272,
286,
1956,
29,
286,
1956,
59,
30015,
61,
272,
9832,
83,
29,
9832,
83,
59,
30015,
61,
272,
612,
29,
612,
59,
30015,
61,
199,
199,
78,
29,
552,
8,
89,
9,
199,
2834,
63,
890,
275,
1109,
8,
78,
10,
2834,
63,
6884,
9,
199,
199,
12875,
83,
63,
454,
78,
63,
2981,
12,
9832,
83,
63,
637,
63,
2981,
275,
9832,
83,
1491,
2834,
63,
890,
467,
9832,
83,
59,
2834,
63,
890,
2938,
199,
25729,
63,
454,
78,
12,
286,
1956,
63,
637,
275,
286,
1956,
1491,
2834,
63,
890,
467,
286,
1956,
59,
2834,
63,
890,
2938,
199,
89,
63,
454,
78,
12,
612,
63,
637,
275,
612,
1491,
2834,
63,
890,
467,
612,
59,
2834,
63,
890,
2938,
199,
199,
12875,
63,
1130,
63,
3269,
275,
5927,
14,
912,
8,
1490,
360,
12875,
63,
8919,
14,
8092,
297,
283,
4848,
1333,
199,
3385,
63,
1130,
63,
3269,
275,
5927,
14,
912,
8,
1490,
360,
3385,
63,
8919,
14,
8092,
297,
283,
4848,
1333,
199,
199,
318,
6230,
63,
1130,
63,
815,
8,
11873,
304,
372,
13953,
59,
16,
467,
822,
8,
11873,
59,
17,
1055,
2888,
4602,
199,
199,
331,
63,
10945,
275,
9739,
24274,
1252,
3269,
8,
12875,
83,
63,
454,
78,
63,
2981,
9,
199,
3249,
63,
12875,
83,
63,
454,
78,
275,
512,
63,
10945,
14,
4711,
8,
12875,
83,
63,
454,
78,
63,
2981,
9,
199,
3249,
63,
12875,
83,
63,
637,
275,
512,
63,
10945,
14,
4711,
8,
12875,
83,
63,
637,
63,
2981,
9,
421,
199,
624,
199,
318,
32205,
321,
8,
89,
63,
5991,
12,
26483,
275,
612,
63,
1078,
63,
2981,
304,
272,
372,
3473,
14,
5079,
8,
1590,
14,
9646,
1332,
29919,
446,
612,
63,
5991,
2447,
29919,
680,
3670,
1012,
199,
318,
943,
63,
988,
63,
5350,
8,
28296,
12,
8728,
275,
1390,
63,
793,
63,
89,
304,
372,
980,
14,
1474,
8,
28296,
627,
8728,
9,
199,
318,
7666,
63,
5350,
8,
28296,
304,
372,
24960,
627,
612,
1516,
435,
612,
3670,
199,
624,
421,
199,
318,
3715,
63,
4574,
8,
5250,
304,
372,
980,
14,
72,
1294,
8,
5250,
12,
5250,
14,
1392,
59,
17,
566,
421,
199,
318,
25316,
63,
826,
8,
1392,
12,
536,
29,
403,
304,
272,
372,
2536,
12270,
14,
8830,
8,
1392,
12,
4666,
29,
16,
14,
22,
15,
1392,
59,
17,
467,
536,
29,
354,
9,
421,
199,
318,
664,
63,
18847,
8,
11873,
304,
272,
536,
12,
286,
275,
6230,
63,
1130,
63,
815,
8,
11873,
9,
272,
340,
675,
63,
807,
26,
267,
286,
18,
275,
6230,
63,
1391,
63,
807,
59,
354,
61,
272,
587,
26,
267,
286,
18,
275,
334,
67,
11,
18,
28428,
19,
267,
340,
286,
18,
30,
1400,
26,
286,
18,
29,
1400,
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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
] |
kalid55/git-core
|
contrib/svn-fe/svnrdump_sim.py
|
328
|
2044
|
#!/usr/bin/python
"""
Simulates svnrdump by replaying an existing dump from a file, taking care
of the specified revision range.
To simulate incremental imports the environment variable SVNRMAX can be set
to the highest revision that should be available.
"""
import sys
import os
if sys.hexversion < 0x02040000:
# The limiter is the ValueError() calls. This may be too conservative
sys.stderr.write("svnrdump-sim.py: requires Python 2.4 or later.\n")
sys.exit(1)
def getrevlimit():
var = 'SVNRMAX'
if var in os.environ:
return os.environ[var]
return None
def writedump(url, lower, upper):
if url.startswith('sim://'):
filename = url[6:]
if filename[-1] == '/':
filename = filename[:-1] # remove terminating slash
else:
raise ValueError('sim:// url required')
f = open(filename, 'r')
state = 'header'
wroterev = False
while(True):
l = f.readline()
if l == '':
break
if state == 'header' and l.startswith('Revision-number: '):
state = 'prefix'
if state == 'prefix' and l == 'Revision-number: %s\n' % lower:
state = 'selection'
if not upper == 'HEAD' and state == 'selection' and \
l == 'Revision-number: %s\n' % upper:
break
if state == 'header' or state == 'selection':
if state == 'selection':
wroterev = True
sys.stdout.write(l)
return wroterev
if __name__ == "__main__":
if not (len(sys.argv) in (3, 4, 5)):
print("usage: %s dump URL -rLOWER:UPPER")
sys.exit(1)
if not sys.argv[1] == 'dump':
raise NotImplementedError('only "dump" is suppported.')
url = sys.argv[2]
r = ('0', 'HEAD')
if len(sys.argv) == 4 and sys.argv[3][0:2] == '-r':
r = sys.argv[3][2:].lstrip().split(':')
if not getrevlimit() is None:
r[1] = getrevlimit()
if writedump(url, r[0], r[1]):
ret = 0
else:
ret = 1
sys.exit(ret)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
624,
199,
7467,
15409,
11327,
82,
2724,
701,
24331,
316,
376,
3411,
5461,
687,
282,
570,
12,
16466,
10296,
199,
1618,
314,
2013,
6974,
1425,
14,
199,
1378,
20577,
16316,
8925,
314,
3734,
1750,
14056,
17774,
4283,
883,
506,
663,
199,
475,
314,
15356,
6974,
626,
1077,
506,
2808,
14,
199,
624,
199,
646,
984,
199,
646,
747,
199,
199,
692,
984,
14,
4097,
1023,
665,
378,
88,
996,
966,
993,
26,
272,
327,
710,
1212,
77,
1661,
365,
314,
1722,
342,
4882,
14,
961,
1443,
506,
4634,
406,
7297,
1905,
272,
984,
14,
3083,
14,
952,
480,
6836,
82,
2724,
13,
5206,
14,
647,
26,
5074,
2018,
499,
14,
20,
503,
2945,
3134,
78,
531,
272,
984,
14,
2224,
8,
17,
9,
421,
199,
318,
664,
4964,
3097,
837,
272,
2729,
275,
283,
4985,
17774,
4283,
7,
272,
340,
2729,
315,
747,
14,
2314,
26,
267,
372,
747,
14,
2314,
59,
1391,
61,
272,
372,
488,
421,
199,
318,
2211,
471,
1220,
8,
633,
12,
5117,
12,
7008,
304,
272,
340,
1166,
14,
2460,
360,
5206,
921,
735,
267,
1788,
275,
1166,
59,
22,
2938,
267,
340,
1788,
1988,
17,
61,
508,
20549,
288,
1788,
275,
1788,
4439,
17,
61,
221,
327,
2813,
5537,
1958,
14457,
272,
587,
26,
267,
746,
1722,
360,
5206,
921,
1166,
1415,
358,
272,
289,
275,
1551,
8,
1501,
12,
283,
82,
358,
272,
1174,
275,
283,
1291,
7,
272,
336,
22665,
4964,
275,
756,
272,
1830,
8,
549,
304,
267,
634,
275,
289,
14,
6407,
342,
267,
340,
634,
508,
8061,
288,
2059,
267,
340,
1174,
508,
283,
1291,
7,
436,
634,
14,
2460,
360,
12714,
13,
1955,
26,
18927,
288,
1174,
275,
283,
1861,
7,
267,
340,
1174,
508,
283,
1861,
7,
436,
634,
508,
283,
12714,
13,
1955,
26,
450,
83,
60,
78,
7,
450,
5117,
26,
288,
1174,
275,
283,
5592,
7,
267,
340,
440,
7008,
508,
283,
5211,
7,
436,
1174,
508,
283,
5592,
7,
436,
971,
355,
634,
508,
283,
12714,
13,
1955,
26,
450,
83,
60,
78,
7,
450,
7008,
26,
288,
2059,
398,
340,
1174,
508,
283,
1291,
7,
503,
1174,
508,
283,
5592,
356,
288,
340,
1174,
508,
283,
5592,
356,
355,
336,
22665,
4964,
275,
715,
288,
984,
14,
2703,
14,
952,
8,
76,
9,
272,
372,
336,
22665,
4964,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
340,
440,
334,
552,
8,
1274,
14,
3020,
9,
315,
334,
19,
12,
841,
12,
959,
2298,
267,
870,
480,
3807,
26,
450,
83,
5461,
2851,
446,
82,
5896,
540,
26,
2160,
4227,
531,
267,
984,
14,
2224,
8,
17,
9,
272,
340,
440,
984,
14,
3020,
59,
17,
61,
508,
283,
2724,
356,
267,
746,
4279,
360,
2118,
298,
2724,
2,
365,
1029,
802,
1376,
2659,
272,
1166,
275,
984,
14,
3020,
59,
18,
61,
272,
519,
275,
661,
16,
297,
283,
5211,
358,
272,
340,
822,
8,
1274,
14,
3020,
9,
508,
841,
436,
984,
14,
3020,
59,
19,
1527,
16,
26,
18,
61,
508,
2475,
82,
356,
267,
519,
275,
984,
14,
3020,
59,
19,
1527,
18,
11455,
10124,
1252,
1294,
11633,
272,
340,
440,
664,
4964,
3097,
342,
365,
488,
26,
267,
519,
59,
17,
61,
275,
664,
4964,
3097,
342,
272,
340,
2211,
471,
1220,
8,
633,
12,
519,
59,
16,
467,
519,
59,
17,
4682,
267,
2203,
275,
378,
272,
587,
26,
267,
2203,
275,
413,
272,
984,
14,
2224,
8,
3292,
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
] |
[
2647,
15,
1393,
15,
1548,
199,
624,
199,
7467,
15409,
11327,
82,
2724,
701,
24331,
316,
376,
3411,
5461,
687,
282,
570,
12,
16466,
10296,
199,
1618,
314,
2013,
6974,
1425,
14,
199,
1378,
20577,
16316,
8925,
314,
3734,
1750,
14056,
17774,
4283,
883,
506,
663,
199,
475,
314,
15356,
6974,
626,
1077,
506,
2808,
14,
199,
624,
199,
646,
984,
199,
646,
747,
199,
199,
692,
984,
14,
4097,
1023,
665,
378,
88,
996,
966,
993,
26,
272,
327,
710,
1212,
77,
1661,
365,
314,
1722,
342,
4882,
14,
961,
1443,
506,
4634,
406,
7297,
1905,
272,
984,
14,
3083,
14,
952,
480,
6836,
82,
2724,
13,
5206,
14,
647,
26,
5074,
2018,
499,
14,
20,
503,
2945,
3134,
78,
531,
272,
984,
14,
2224,
8,
17,
9,
421,
199,
318,
664,
4964,
3097,
837,
272,
2729,
275,
283,
4985,
17774,
4283,
7,
272,
340,
2729,
315,
747,
14,
2314,
26,
267,
372,
747,
14,
2314,
59,
1391,
61,
272,
372,
488,
421,
199,
318,
2211,
471,
1220,
8,
633,
12,
5117,
12,
7008,
304,
272,
340,
1166,
14,
2460,
360,
5206,
921,
735,
267,
1788,
275,
1166,
59,
22,
2938,
267,
340,
1788,
1988,
17,
61,
508,
20549,
288,
1788,
275,
1788,
4439,
17,
61,
221,
327,
2813,
5537,
1958,
14457,
272,
587,
26,
267,
746,
1722,
360,
5206,
921,
1166,
1415,
358,
272,
289,
275,
1551,
8,
1501,
12,
283,
82,
358,
272,
1174,
275,
283,
1291,
7,
272,
336,
22665,
4964,
275,
756,
272,
1830,
8,
549,
304,
267,
634,
275,
289,
14,
6407,
342,
267,
340,
634,
508,
8061,
288,
2059,
267,
340,
1174,
508,
283,
1291,
7,
436,
634,
14,
2460,
360,
12714,
13,
1955,
26,
18927,
288,
1174,
275,
283,
1861,
7,
267,
340,
1174,
508,
283,
1861,
7,
436,
634,
508,
283,
12714,
13,
1955,
26,
450,
83,
60,
78,
7,
450,
5117,
26,
288,
1174,
275,
283,
5592,
7,
267,
340,
440,
7008,
508,
283,
5211,
7,
436,
1174,
508,
283,
5592,
7,
436,
971,
355,
634,
508,
283,
12714,
13,
1955,
26,
450,
83,
60,
78,
7,
450,
7008,
26,
288,
2059,
398,
340,
1174,
508,
283,
1291,
7,
503,
1174,
508,
283,
5592,
356,
288,
340,
1174,
508,
283,
5592,
356,
355,
336,
22665,
4964,
275,
715,
288,
984,
14,
2703,
14,
952,
8,
76,
9,
272,
372,
336,
22665,
4964,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
340,
440,
334,
552,
8,
1274,
14,
3020,
9,
315,
334,
19,
12,
841,
12,
959,
2298,
267,
870,
480,
3807,
26,
450,
83,
5461,
2851,
446,
82,
5896,
540,
26,
2160,
4227,
531,
267,
984,
14,
2224,
8,
17,
9,
272,
340,
440,
984,
14,
3020,
59,
17,
61,
508,
283,
2724,
356,
267,
746,
4279,
360,
2118,
298,
2724,
2,
365,
1029,
802,
1376,
2659,
272,
1166,
275,
984,
14,
3020,
59,
18,
61,
272,
519,
275,
661,
16,
297,
283,
5211,
358,
272,
340,
822,
8,
1274,
14,
3020,
9,
508,
841,
436,
984,
14,
3020,
59,
19,
1527,
16,
26,
18,
61,
508,
2475,
82,
356,
267,
519,
275,
984,
14,
3020,
59,
19,
1527,
18,
11455,
10124,
1252,
1294,
11633,
272,
340,
440,
664,
4964,
3097,
342,
365,
488,
26,
267,
519,
59,
17,
61,
275,
664,
4964,
3097,
342,
272,
340,
2211,
471,
1220,
8,
633,
12,
519,
59,
16,
467,
519,
59,
17,
4682,
267,
2203,
275,
378,
272,
587,
26,
267,
2203,
275,
413,
272,
984,
14,
2224,
8,
3292,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tboyce021/home-assistant
|
tests/components/api/test_init.py
|
10
|
17472
|
"""The tests for the Home Assistant API component."""
# pylint: disable=protected-access
import json
from aiohttp import web
import pytest
import voluptuous as vol
from homeassistant import const
from homeassistant.bootstrap import DATA_LOGGING
import homeassistant.core as ha
from homeassistant.setup import async_setup_component
from tests.async_mock import patch
from tests.common import async_mock_service
@pytest.fixture
def mock_api_client(hass, hass_client):
"""Start the Home Assistant HTTP component and return admin API client."""
hass.loop.run_until_complete(async_setup_component(hass, "api", {}))
return hass.loop.run_until_complete(hass_client())
async def test_api_list_state_entities(hass, mock_api_client):
"""Test if the debug interface allows us to list state entities."""
hass.states.async_set("test.entity", "hello")
resp = await mock_api_client.get(const.URL_API_STATES)
assert resp.status == 200
json = await resp.json()
remote_data = [ha.State.from_dict(item) for item in json]
assert remote_data == hass.states.async_all()
async def test_api_get_state(hass, mock_api_client):
"""Test if the debug interface allows us to get a state."""
hass.states.async_set("hello.world", "nice", {"attr": 1})
resp = await mock_api_client.get("/api/states/hello.world")
assert resp.status == 200
json = await resp.json()
data = ha.State.from_dict(json)
state = hass.states.get("hello.world")
assert data.state == state.state
assert data.last_changed == state.last_changed
assert data.attributes == state.attributes
async def test_api_get_non_existing_state(hass, mock_api_client):
"""Test if the debug interface allows us to get a state."""
resp = await mock_api_client.get("/api/states/does_not_exist")
assert resp.status == const.HTTP_NOT_FOUND
async def test_api_state_change(hass, mock_api_client):
"""Test if we can change the state of an entity that exists."""
hass.states.async_set("test.test", "not_to_be_set")
await mock_api_client.post(
"/api/states/test.test", json={"state": "debug_state_change2"}
)
assert hass.states.get("test.test").state == "debug_state_change2"
# pylint: disable=invalid-name
async def test_api_state_change_of_non_existing_entity(hass, mock_api_client):
"""Test if changing a state of a non existing entity is possible."""
new_state = "debug_state_change"
resp = await mock_api_client.post(
"/api/states/test_entity.that_does_not_exist", json={"state": new_state}
)
assert resp.status == 201
assert hass.states.get("test_entity.that_does_not_exist").state == new_state
# pylint: disable=invalid-name
async def test_api_state_change_with_bad_data(hass, mock_api_client):
"""Test if API sends appropriate error if we omit state."""
resp = await mock_api_client.post(
"/api/states/test_entity.that_does_not_exist", json={}
)
assert resp.status == 400
# pylint: disable=invalid-name
async def test_api_state_change_to_zero_value(hass, mock_api_client):
"""Test if changing a state to a zero value is possible."""
resp = await mock_api_client.post(
"/api/states/test_entity.with_zero_state", json={"state": 0}
)
assert resp.status == 201
resp = await mock_api_client.post(
"/api/states/test_entity.with_zero_state", json={"state": 0.0}
)
assert resp.status == 200
# pylint: disable=invalid-name
async def test_api_state_change_push(hass, mock_api_client):
"""Test if we can push a change the state of an entity."""
hass.states.async_set("test.test", "not_to_be_set")
events = []
@ha.callback
def event_listener(event):
"""Track events."""
events.append(event)
hass.bus.async_listen(const.EVENT_STATE_CHANGED, event_listener)
await mock_api_client.post("/api/states/test.test", json={"state": "not_to_be_set"})
await hass.async_block_till_done()
assert len(events) == 0
await mock_api_client.post(
"/api/states/test.test", json={"state": "not_to_be_set", "force_update": True}
)
await hass.async_block_till_done()
assert len(events) == 1
# pylint: disable=invalid-name
async def test_api_fire_event_with_no_data(hass, mock_api_client):
"""Test if the API allows us to fire an event."""
test_value = []
@ha.callback
def listener(event):
"""Record that our event got called."""
test_value.append(1)
hass.bus.async_listen_once("test.event_no_data", listener)
await mock_api_client.post("/api/events/test.event_no_data")
await hass.async_block_till_done()
assert len(test_value) == 1
# pylint: disable=invalid-name
async def test_api_fire_event_with_data(hass, mock_api_client):
"""Test if the API allows us to fire an event."""
test_value = []
@ha.callback
def listener(event):
"""Record that our event got called.
Also test if our data came through.
"""
if "test" in event.data:
test_value.append(1)
hass.bus.async_listen_once("test_event_with_data", listener)
await mock_api_client.post("/api/events/test_event_with_data", json={"test": 1})
await hass.async_block_till_done()
assert len(test_value) == 1
# pylint: disable=invalid-name
async def test_api_fire_event_with_invalid_json(hass, mock_api_client):
"""Test if the API allows us to fire an event."""
test_value = []
@ha.callback
def listener(event):
"""Record that our event got called."""
test_value.append(1)
hass.bus.async_listen_once("test_event_bad_data", listener)
resp = await mock_api_client.post(
"/api/events/test_event_bad_data", data=json.dumps("not an object")
)
await hass.async_block_till_done()
assert resp.status == 400
assert len(test_value) == 0
# Try now with valid but unusable JSON
resp = await mock_api_client.post(
"/api/events/test_event_bad_data", data=json.dumps([1, 2, 3])
)
await hass.async_block_till_done()
assert resp.status == 400
assert len(test_value) == 0
async def test_api_get_config(hass, mock_api_client):
"""Test the return of the configuration."""
resp = await mock_api_client.get(const.URL_API_CONFIG)
result = await resp.json()
if "components" in result:
result["components"] = set(result["components"])
if "whitelist_external_dirs" in result:
result["whitelist_external_dirs"] = set(result["whitelist_external_dirs"])
if "allowlist_external_dirs" in result:
result["allowlist_external_dirs"] = set(result["allowlist_external_dirs"])
if "allowlist_external_urls" in result:
result["allowlist_external_urls"] = set(result["allowlist_external_urls"])
assert hass.config.as_dict() == result
async def test_api_get_components(hass, mock_api_client):
"""Test the return of the components."""
resp = await mock_api_client.get(const.URL_API_COMPONENTS)
result = await resp.json()
assert set(result) == hass.config.components
async def test_api_get_event_listeners(hass, mock_api_client):
"""Test if we can get the list of events being listened for."""
resp = await mock_api_client.get(const.URL_API_EVENTS)
data = await resp.json()
local = hass.bus.async_listeners()
for event in data:
assert local.pop(event["event"]) == event["listener_count"]
assert len(local) == 0
async def test_api_get_services(hass, mock_api_client):
"""Test if we can get a dict describing current services."""
resp = await mock_api_client.get(const.URL_API_SERVICES)
data = await resp.json()
local_services = hass.services.async_services()
for serv_domain in data:
local = local_services.pop(serv_domain["domain"])
assert serv_domain["services"] == local
async def test_api_call_service_no_data(hass, mock_api_client):
"""Test if the API allows us to call a service."""
test_value = []
@ha.callback
def listener(service_call):
"""Record that our service got called."""
test_value.append(1)
hass.services.async_register("test_domain", "test_service", listener)
await mock_api_client.post("/api/services/test_domain/test_service")
await hass.async_block_till_done()
assert len(test_value) == 1
async def test_api_call_service_with_data(hass, mock_api_client):
"""Test if the API allows us to call a service."""
test_value = []
@ha.callback
def listener(service_call):
"""Record that our service got called.
Also test if our data came through.
"""
if "test" in service_call.data:
test_value.append(1)
hass.services.async_register("test_domain", "test_service", listener)
await mock_api_client.post(
"/api/services/test_domain/test_service", json={"test": 1}
)
await hass.async_block_till_done()
assert len(test_value) == 1
async def test_api_template(hass, mock_api_client):
"""Test the template API."""
hass.states.async_set("sensor.temperature", 10)
resp = await mock_api_client.post(
const.URL_API_TEMPLATE,
json={"template": "{{ states.sensor.temperature.state }}"},
)
body = await resp.text()
assert body == "10"
async def test_api_template_error(hass, mock_api_client):
"""Test the template API."""
hass.states.async_set("sensor.temperature", 10)
resp = await mock_api_client.post(
const.URL_API_TEMPLATE, json={"template": "{{ states.sensor.temperature.state"}
)
assert resp.status == 400
async def test_stream(hass, mock_api_client):
"""Test the stream."""
listen_count = _listen_count(hass)
resp = await mock_api_client.get(const.URL_API_STREAM)
assert resp.status == 200
assert listen_count + 1 == _listen_count(hass)
hass.bus.async_fire("test_event")
data = await _stream_next_event(resp.content)
assert data["event_type"] == "test_event"
async def test_stream_with_restricted(hass, mock_api_client):
"""Test the stream with restrictions."""
listen_count = _listen_count(hass)
resp = await mock_api_client.get(
f"{const.URL_API_STREAM}?restrict=test_event1,test_event3"
)
assert resp.status == 200
assert listen_count + 1 == _listen_count(hass)
hass.bus.async_fire("test_event1")
data = await _stream_next_event(resp.content)
assert data["event_type"] == "test_event1"
hass.bus.async_fire("test_event2")
hass.bus.async_fire("test_event3")
data = await _stream_next_event(resp.content)
assert data["event_type"] == "test_event3"
async def _stream_next_event(stream):
"""Read the stream for next event while ignoring ping."""
while True:
last_new_line = False
data = b""
while True:
dat = await stream.read(1)
if dat == b"\n" and last_new_line:
break
data += dat
last_new_line = dat == b"\n"
conv = data.decode("utf-8").strip()[6:]
if conv != "ping":
break
return json.loads(conv)
def _listen_count(hass):
"""Return number of event listeners."""
return sum(hass.bus.async_listeners().values())
async def test_api_error_log(hass, aiohttp_client, hass_access_token, hass_admin_user):
"""Test if we can fetch the error log."""
hass.data[DATA_LOGGING] = "/some/path"
await async_setup_component(hass, "api", {})
client = await aiohttp_client(hass.http.app)
resp = await client.get(const.URL_API_ERROR_LOG)
# Verify auth required
assert resp.status == 401
with patch(
"aiohttp.web.FileResponse", return_value=web.Response(status=200, text="Hello")
) as mock_file:
resp = await client.get(
const.URL_API_ERROR_LOG,
headers={"Authorization": f"Bearer {hass_access_token}"},
)
assert len(mock_file.mock_calls) == 1
assert mock_file.mock_calls[0][1][0] == hass.data[DATA_LOGGING]
assert resp.status == 200
assert await resp.text() == "Hello"
# Verify we require admin user
hass_admin_user.groups = []
resp = await client.get(
const.URL_API_ERROR_LOG,
headers={"Authorization": f"Bearer {hass_access_token}"},
)
assert resp.status == 401
async def test_api_fire_event_context(hass, mock_api_client, hass_access_token):
"""Test if the API sets right context if we fire an event."""
test_value = []
@ha.callback
def listener(event):
"""Record that our event got called."""
test_value.append(event)
hass.bus.async_listen("test.event", listener)
await mock_api_client.post(
"/api/events/test.event",
headers={"authorization": f"Bearer {hass_access_token}"},
)
await hass.async_block_till_done()
refresh_token = await hass.auth.async_validate_access_token(hass_access_token)
assert len(test_value) == 1
assert test_value[0].context.user_id == refresh_token.user.id
async def test_api_call_service_context(hass, mock_api_client, hass_access_token):
"""Test if the API sets right context if we call a service."""
calls = async_mock_service(hass, "test_domain", "test_service")
await mock_api_client.post(
"/api/services/test_domain/test_service",
headers={"authorization": f"Bearer {hass_access_token}"},
)
await hass.async_block_till_done()
refresh_token = await hass.auth.async_validate_access_token(hass_access_token)
assert len(calls) == 1
assert calls[0].context.user_id == refresh_token.user.id
async def test_api_set_state_context(hass, mock_api_client, hass_access_token):
"""Test if the API sets right context if we set state."""
await mock_api_client.post(
"/api/states/light.kitchen",
json={"state": "on"},
headers={"authorization": f"Bearer {hass_access_token}"},
)
refresh_token = await hass.auth.async_validate_access_token(hass_access_token)
state = hass.states.get("light.kitchen")
assert state.context.user_id == refresh_token.user.id
async def test_event_stream_requires_admin(hass, mock_api_client, hass_admin_user):
"""Test user needs to be admin to access event stream."""
hass_admin_user.groups = []
resp = await mock_api_client.get("/api/stream")
assert resp.status == 401
async def test_states_view_filters(hass, mock_api_client, hass_admin_user):
"""Test filtering only visible states."""
hass_admin_user.mock_policy({"entities": {"entity_ids": {"test.entity": True}}})
hass.states.async_set("test.entity", "hello")
hass.states.async_set("test.not_visible_entity", "invisible")
resp = await mock_api_client.get(const.URL_API_STATES)
assert resp.status == 200
json = await resp.json()
assert len(json) == 1
assert json[0]["entity_id"] == "test.entity"
async def test_get_entity_state_read_perm(hass, mock_api_client, hass_admin_user):
"""Test getting a state requires read permission."""
hass_admin_user.mock_policy({})
resp = await mock_api_client.get("/api/states/light.test")
assert resp.status == 401
async def test_post_entity_state_admin(hass, mock_api_client, hass_admin_user):
"""Test updating state requires admin."""
hass_admin_user.groups = []
resp = await mock_api_client.post("/api/states/light.test")
assert resp.status == 401
async def test_delete_entity_state_admin(hass, mock_api_client, hass_admin_user):
"""Test deleting entity requires admin."""
hass_admin_user.groups = []
resp = await mock_api_client.delete("/api/states/light.test")
assert resp.status == 401
async def test_post_event_admin(hass, mock_api_client, hass_admin_user):
"""Test sending event requires admin."""
hass_admin_user.groups = []
resp = await mock_api_client.post("/api/events/state_changed")
assert resp.status == 401
async def test_rendering_template_admin(hass, mock_api_client, hass_admin_user):
"""Test rendering a template requires admin."""
hass_admin_user.groups = []
resp = await mock_api_client.post(const.URL_API_TEMPLATE)
assert resp.status == 401
async def test_rendering_template_legacy_user(
hass, mock_api_client, aiohttp_client, legacy_auth
):
"""Test rendering a template with legacy API password."""
hass.states.async_set("sensor.temperature", 10)
client = await aiohttp_client(hass.http.app)
resp = await client.post(
const.URL_API_TEMPLATE,
json={"template": "{{ states.sensor.temperature.state }}"},
)
assert resp.status == 401
async def test_api_call_service_not_found(hass, mock_api_client):
"""Test if the API fails 400 if unknown service."""
resp = await mock_api_client.post("/api/services/test_domain/test_service")
assert resp.status == 400
async def test_api_call_service_bad_data(hass, mock_api_client):
"""Test if the API fails 400 if unknown service."""
test_value = []
@ha.callback
def listener(service_call):
"""Record that our service got called."""
test_value.append(1)
hass.services.async_register(
"test_domain", "test_service", listener, schema=vol.Schema({"hello": str})
)
resp = await mock_api_client.post(
"/api/services/test_domain/test_service", json={"hello": 5}
)
assert resp.status == 400
|
apache-2.0
|
[
624,
1918,
2295,
367,
314,
14621,
3709,
18832,
3261,
3931,
1041,
199,
3,
4287,
26,
3507,
29,
6798,
13,
2732,
199,
646,
2022,
199,
199,
504,
30274,
492,
3330,
199,
646,
4613,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
492,
950,
199,
504,
8846,
14,
11146,
492,
7126,
63,
27896,
199,
646,
8846,
14,
1018,
465,
18251,
199,
504,
8846,
14,
2758,
492,
5316,
63,
2758,
63,
3173,
199,
199,
504,
2295,
14,
4146,
63,
1805,
492,
3371,
199,
504,
2295,
14,
2330,
492,
5316,
63,
1805,
63,
1364,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
1246,
63,
1258,
8,
5387,
12,
6298,
63,
1258,
304,
272,
408,
3162,
314,
14621,
3709,
18832,
3101,
3931,
436,
372,
4628,
3261,
1890,
1041,
272,
6298,
14,
3813,
14,
1065,
63,
8111,
63,
4883,
8,
4146,
63,
2758,
63,
3173,
8,
5387,
12,
298,
1246,
401,
17003,
272,
372,
6298,
14,
3813,
14,
1065,
63,
8111,
63,
4883,
8,
5387,
63,
1258,
1012,
421,
199,
4146,
347,
511,
63,
1246,
63,
513,
63,
929,
63,
8327,
8,
5387,
12,
1683,
63,
1246,
63,
1258,
304,
272,
408,
774,
340,
314,
3105,
3217,
6127,
2739,
370,
769,
1174,
9045,
1041,
272,
6298,
14,
4981,
14,
4146,
63,
409,
480,
396,
14,
4502,
401,
298,
5006,
531,
272,
3085,
275,
5517,
1683,
63,
1246,
63,
1258,
14,
362,
8,
1297,
14,
2632,
63,
3735,
63,
23162,
9,
272,
702,
3085,
14,
1205,
508,
1926,
272,
2022,
275,
5517,
3085,
14,
1001,
342,
339,
3982,
63,
576,
275,
359,
2411,
14,
2223,
14,
504,
63,
807,
8,
1053,
9,
367,
1242,
315,
2022,
61,
272,
702,
3982,
63,
576,
508,
6298,
14,
4981,
14,
4146,
63,
452,
342,
421,
199,
4146,
347,
511,
63,
1246,
63,
362,
63,
929,
8,
5387,
12,
1683,
63,
1246,
63,
1258,
304,
272,
408,
774,
340,
314,
3105,
3217,
6127,
2739,
370,
664,
282,
1174,
1041,
272,
6298,
14,
4981,
14,
4146,
63,
409,
480,
5006,
14,
7617,
401,
298,
22746,
401,
2420,
962,
582,
413,
1552,
272,
3085,
275,
5517,
1683,
63,
1246,
63,
1258,
14,
362,
4769,
1246,
15,
4981,
15,
5006,
14,
7617,
531,
272,
702,
3085,
14,
1205,
508,
1926,
272,
2022,
275,
5517,
3085,
14,
1001,
342,
339,
666,
275,
18251,
14,
2223,
14,
504,
63,
807,
8,
1001,
9,
339,
1174,
275,
6298,
14,
4981,
14,
362,
480,
5006,
14,
7617,
531,
339,
702,
666,
14,
929,
508,
1174,
14,
929,
272,
702,
666,
14,
2019,
63,
2489,
508,
1174,
14,
2019,
63,
2489,
272,
702,
666,
14,
2987,
508,
1174,
14,
2987,
421,
199,
4146,
347,
511,
63,
1246,
63,
362,
63,
2865,
63,
5952,
63,
929,
8,
5387,
12,
1683,
63,
1246,
63,
1258,
304,
272,
408,
774,
340,
314,
3105,
3217,
6127,
2739,
370,
664,
282,
1174,
1041,
272,
3085,
275,
5517,
1683,
63,
1246,
63,
1258,
14,
362,
4769,
1246,
15,
4981,
15,
9105,
63,
1397,
63,
4494,
531,
272,
702,
3085,
14,
1205,
508,
950,
14,
2856,
63,
4609,
63,
13945,
421,
199,
4146,
347,
511,
63,
1246,
63,
929,
63,
1461,
8,
5387,
12,
1683,
63,
1246,
63,
1258,
304,
272,
408,
774,
340,
781,
883,
1570,
314,
1174,
402,
376,
4642,
626,
3495,
1041,
272,
6298,
14,
4981,
14,
4146,
63,
409,
480,
396,
14,
396,
401,
298,
1397,
63,
475,
63,
1235,
63,
409,
531,
339,
5517,
1683,
63,
1246,
63,
1258,
14,
1932,
8,
267,
3286,
1246,
15,
4981,
15,
396,
14,
396,
401,
2022,
8871,
929,
582,
298,
1757,
63,
929,
63,
1461,
18,
3570,
272,
776,
339,
702,
6298,
14,
4981,
14,
362,
480,
396,
14,
396,
3471,
929,
508,
298,
1757,
63,
929,
63,
1461,
18,
2,
421,
199,
3,
4287,
26,
3507,
29,
3197,
13,
354,
199,
4146,
347,
511,
63,
1246,
63,
929,
63,
1461,
63,
1618,
63,
2865,
63,
5952,
63,
4502,
8,
5387,
12,
1683,
63,
1246,
63,
1258,
304,
272,
408,
774,
340,
13729,
282,
1174,
402,
282,
2222,
3411,
4642,
365,
3962,
1041,
272,
892,
63,
929,
275,
298,
1757,
63,
929,
63,
1461,
2,
339,
3085,
275,
5517,
1683,
63,
1246,
63,
1258,
14,
1932,
8,
267,
3286,
1246,
15,
4981,
15,
396,
63,
4502,
14,
9099,
63,
9105,
63,
1397,
63,
4494,
401,
2022,
8871,
929,
582,
892,
63,
929,
93,
272,
776,
339,
702,
3085,
14,
1205,
508,
1784,
339,
702,
6298,
14,
4981,
14,
362,
480,
396,
63,
4502,
14,
9099,
63,
9105,
63,
1397,
63,
4494,
3471,
929,
508,
892,
63,
929,
421,
199,
3,
4287,
26,
3507,
29,
3197,
13,
354,
199,
4146,
347,
511,
63,
1246,
63,
929,
63,
1461,
63,
1045,
63,
4087,
63,
576,
8,
5387,
12,
1683,
63,
1246,
63,
1258,
304,
272,
408,
774,
340,
3261,
16178,
5827,
1125,
340,
781,
19413,
1174,
1041,
272,
3085,
275,
5517,
1683,
63,
1246,
63,
1258,
14,
1932,
8,
267,
3286,
1246,
15,
4981,
15,
396,
63,
4502,
14,
9099,
63,
9105,
63,
1397,
63,
4494,
401,
2022,
7622,
272,
776,
339,
702,
3085,
14,
1205,
508,
8290,
421,
199,
3,
4287,
26,
3507,
29,
3197,
13,
354,
199,
4146,
347,
511,
63,
1246,
63,
929,
63,
1461,
63,
475,
63,
4262,
63,
585,
8,
5387,
12,
1683,
63,
1246,
63,
1258,
304,
272,
408,
774,
340,
13729,
282,
1174,
370,
282,
4697,
574,
365,
3962,
1041,
272,
3085,
275,
5517,
1683,
63,
1246,
63,
1258,
14,
1932,
8,
267,
3286,
1246,
15,
4981,
15,
396,
63,
4502,
14,
1045,
63,
4262,
63,
929,
401,
2022,
8871,
929,
582,
378,
93,
272,
776,
339,
702,
3085,
14,
1205,
508,
1784,
339,
3085,
275,
5517,
1683,
63,
1246,
63,
1258,
14,
1932,
8,
267,
3286,
1246,
15,
4981,
15,
396,
63,
4502,
14,
1045,
63,
4262,
63,
929,
401,
2022,
8871,
929,
582,
378,
14,
16,
93,
272,
776,
339,
702,
3085,
14,
1205,
508,
1926,
421,
199,
3,
4287,
26,
3507,
29,
3197,
13,
354,
199,
4146,
347,
511,
63,
1246,
63,
929,
63,
1461,
63,
5335,
8,
5387,
12,
1683,
63,
1246,
63,
1258,
304,
272,
408,
774,
340,
781,
883,
6675,
282,
1570,
314,
1174
] |
[
1918,
2295,
367,
314,
14621,
3709,
18832,
3261,
3931,
1041,
199,
3,
4287,
26,
3507,
29,
6798,
13,
2732,
199,
646,
2022,
199,
199,
504,
30274,
492,
3330,
199,
646,
4613,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
492,
950,
199,
504,
8846,
14,
11146,
492,
7126,
63,
27896,
199,
646,
8846,
14,
1018,
465,
18251,
199,
504,
8846,
14,
2758,
492,
5316,
63,
2758,
63,
3173,
199,
199,
504,
2295,
14,
4146,
63,
1805,
492,
3371,
199,
504,
2295,
14,
2330,
492,
5316,
63,
1805,
63,
1364,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
1246,
63,
1258,
8,
5387,
12,
6298,
63,
1258,
304,
272,
408,
3162,
314,
14621,
3709,
18832,
3101,
3931,
436,
372,
4628,
3261,
1890,
1041,
272,
6298,
14,
3813,
14,
1065,
63,
8111,
63,
4883,
8,
4146,
63,
2758,
63,
3173,
8,
5387,
12,
298,
1246,
401,
17003,
272,
372,
6298,
14,
3813,
14,
1065,
63,
8111,
63,
4883,
8,
5387,
63,
1258,
1012,
421,
199,
4146,
347,
511,
63,
1246,
63,
513,
63,
929,
63,
8327,
8,
5387,
12,
1683,
63,
1246,
63,
1258,
304,
272,
408,
774,
340,
314,
3105,
3217,
6127,
2739,
370,
769,
1174,
9045,
1041,
272,
6298,
14,
4981,
14,
4146,
63,
409,
480,
396,
14,
4502,
401,
298,
5006,
531,
272,
3085,
275,
5517,
1683,
63,
1246,
63,
1258,
14,
362,
8,
1297,
14,
2632,
63,
3735,
63,
23162,
9,
272,
702,
3085,
14,
1205,
508,
1926,
272,
2022,
275,
5517,
3085,
14,
1001,
342,
339,
3982,
63,
576,
275,
359,
2411,
14,
2223,
14,
504,
63,
807,
8,
1053,
9,
367,
1242,
315,
2022,
61,
272,
702,
3982,
63,
576,
508,
6298,
14,
4981,
14,
4146,
63,
452,
342,
421,
199,
4146,
347,
511,
63,
1246,
63,
362,
63,
929,
8,
5387,
12,
1683,
63,
1246,
63,
1258,
304,
272,
408,
774,
340,
314,
3105,
3217,
6127,
2739,
370,
664,
282,
1174,
1041,
272,
6298,
14,
4981,
14,
4146,
63,
409,
480,
5006,
14,
7617,
401,
298,
22746,
401,
2420,
962,
582,
413,
1552,
272,
3085,
275,
5517,
1683,
63,
1246,
63,
1258,
14,
362,
4769,
1246,
15,
4981,
15,
5006,
14,
7617,
531,
272,
702,
3085,
14,
1205,
508,
1926,
272,
2022,
275,
5517,
3085,
14,
1001,
342,
339,
666,
275,
18251,
14,
2223,
14,
504,
63,
807,
8,
1001,
9,
339,
1174,
275,
6298,
14,
4981,
14,
362,
480,
5006,
14,
7617,
531,
339,
702,
666,
14,
929,
508,
1174,
14,
929,
272,
702,
666,
14,
2019,
63,
2489,
508,
1174,
14,
2019,
63,
2489,
272,
702,
666,
14,
2987,
508,
1174,
14,
2987,
421,
199,
4146,
347,
511,
63,
1246,
63,
362,
63,
2865,
63,
5952,
63,
929,
8,
5387,
12,
1683,
63,
1246,
63,
1258,
304,
272,
408,
774,
340,
314,
3105,
3217,
6127,
2739,
370,
664,
282,
1174,
1041,
272,
3085,
275,
5517,
1683,
63,
1246,
63,
1258,
14,
362,
4769,
1246,
15,
4981,
15,
9105,
63,
1397,
63,
4494,
531,
272,
702,
3085,
14,
1205,
508,
950,
14,
2856,
63,
4609,
63,
13945,
421,
199,
4146,
347,
511,
63,
1246,
63,
929,
63,
1461,
8,
5387,
12,
1683,
63,
1246,
63,
1258,
304,
272,
408,
774,
340,
781,
883,
1570,
314,
1174,
402,
376,
4642,
626,
3495,
1041,
272,
6298,
14,
4981,
14,
4146,
63,
409,
480,
396,
14,
396,
401,
298,
1397,
63,
475,
63,
1235,
63,
409,
531,
339,
5517,
1683,
63,
1246,
63,
1258,
14,
1932,
8,
267,
3286,
1246,
15,
4981,
15,
396,
14,
396,
401,
2022,
8871,
929,
582,
298,
1757,
63,
929,
63,
1461,
18,
3570,
272,
776,
339,
702,
6298,
14,
4981,
14,
362,
480,
396,
14,
396,
3471,
929,
508,
298,
1757,
63,
929,
63,
1461,
18,
2,
421,
199,
3,
4287,
26,
3507,
29,
3197,
13,
354,
199,
4146,
347,
511,
63,
1246,
63,
929,
63,
1461,
63,
1618,
63,
2865,
63,
5952,
63,
4502,
8,
5387,
12,
1683,
63,
1246,
63,
1258,
304,
272,
408,
774,
340,
13729,
282,
1174,
402,
282,
2222,
3411,
4642,
365,
3962,
1041,
272,
892,
63,
929,
275,
298,
1757,
63,
929,
63,
1461,
2,
339,
3085,
275,
5517,
1683,
63,
1246,
63,
1258,
14,
1932,
8,
267,
3286,
1246,
15,
4981,
15,
396,
63,
4502,
14,
9099,
63,
9105,
63,
1397,
63,
4494,
401,
2022,
8871,
929,
582,
892,
63,
929,
93,
272,
776,
339,
702,
3085,
14,
1205,
508,
1784,
339,
702,
6298,
14,
4981,
14,
362,
480,
396,
63,
4502,
14,
9099,
63,
9105,
63,
1397,
63,
4494,
3471,
929,
508,
892,
63,
929,
421,
199,
3,
4287,
26,
3507,
29,
3197,
13,
354,
199,
4146,
347,
511,
63,
1246,
63,
929,
63,
1461,
63,
1045,
63,
4087,
63,
576,
8,
5387,
12,
1683,
63,
1246,
63,
1258,
304,
272,
408,
774,
340,
3261,
16178,
5827,
1125,
340,
781,
19413,
1174,
1041,
272,
3085,
275,
5517,
1683,
63,
1246,
63,
1258,
14,
1932,
8,
267,
3286,
1246,
15,
4981,
15,
396,
63,
4502,
14,
9099,
63,
9105,
63,
1397,
63,
4494,
401,
2022,
7622,
272,
776,
339,
702,
3085,
14,
1205,
508,
8290,
421,
199,
3,
4287,
26,
3507,
29,
3197,
13,
354,
199,
4146,
347,
511,
63,
1246,
63,
929,
63,
1461,
63,
475,
63,
4262,
63,
585,
8,
5387,
12,
1683,
63,
1246,
63,
1258,
304,
272,
408,
774,
340,
13729,
282,
1174,
370,
282,
4697,
574,
365,
3962,
1041,
272,
3085,
275,
5517,
1683,
63,
1246,
63,
1258,
14,
1932,
8,
267,
3286,
1246,
15,
4981,
15,
396,
63,
4502,
14,
1045,
63,
4262,
63,
929,
401,
2022,
8871,
929,
582,
378,
93,
272,
776,
339,
702,
3085,
14,
1205,
508,
1784,
339,
3085,
275,
5517,
1683,
63,
1246,
63,
1258,
14,
1932,
8,
267,
3286,
1246,
15,
4981,
15,
396,
63,
4502,
14,
1045,
63,
4262,
63,
929,
401,
2022,
8871,
929,
582,
378,
14,
16,
93,
272,
776,
339,
702,
3085,
14,
1205,
508,
1926,
421,
199,
3,
4287,
26,
3507,
29,
3197,
13,
354,
199,
4146,
347,
511,
63,
1246,
63,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Micronaet/micronaet-trip
|
account_trip_edi_c5/__openerp__.py
|
1
|
1740
|
###############################################################################
#
# Copyright (C) 2001-2014 Micronaet SRL (<http://www.micronaet.it>).
#
# 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': 'Account trip - EDI order import procedure for Company 5',
'version': '0.1',
'category': 'EDI',
'description': """
Import function for load EDI files
this is a model of importation for Company 5
This type of module are linked to edi.company for parametrize
function for importation.
Import procedure is in account_trip_edi
""",
'author': 'Micronaet S.r.l. - Nicola Riolini',
'website': 'http://www.micronaet.it',
'license': 'AGPL-3',
'depends': [
'base',
'account_trip_edi',
],
'init_xml': [],
'demo': [],
'data': [
'security/ir.model.access.csv',
'data/edi_company_importation.xml'
],
'active': False,
'installable': True,
'auto_install': False,
}
|
agpl-3.0
|
[
11490,
199,
3,
199,
3,
259,
1898,
334,
35,
9,
12521,
13,
7280,
603,
530,
2641,
65,
386,
428,
2431,
8642,
1014,
921,
1544,
14,
15003,
2641,
65,
386,
14,
390,
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,
3267,
199,
3,
259,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
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,
11490,
199,
199,
91,
272,
283,
354,
356,
283,
6009,
18038,
446,
662,
1914,
1865,
492,
17782,
367,
15878,
959,
297,
272,
283,
1023,
356,
283,
16,
14,
17,
297,
272,
283,
3710,
356,
283,
7458,
297,
272,
283,
1802,
356,
408,
267,
3161,
805,
367,
2248,
662,
1914,
1584,
267,
642,
365,
282,
1402,
402,
492,
425,
367,
15878,
959,
267,
961,
730,
402,
859,
787,
10632,
370,
7860,
14,
4627,
367,
18117,
599,
806,
267,
805,
367,
492,
425,
14,
267,
3161,
17782,
365,
315,
2933,
63,
7254,
63,
6297,
4960,
10327,
272,
283,
2502,
356,
283,
45,
530,
2641,
65,
386,
428,
14,
82,
14,
76,
14,
446,
653,
12802,
416,
820,
73,
393,
2730,
297,
272,
283,
7360,
356,
283,
1014,
921,
1544,
14,
15003,
2641,
65,
386,
14,
390,
297,
272,
283,
1682,
356,
283,
1254,
2749,
13,
19,
297,
272,
283,
8912,
356,
359,
267,
283,
1095,
297,
267,
283,
2048,
63,
7254,
63,
6297,
297,
267,
2156,
272,
283,
826,
63,
1652,
356,
990,
272,
283,
8768,
356,
990,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
576,
15,
6297,
63,
4627,
63,
646,
425,
14,
1652,
7,
267,
2156,
272,
283,
2682,
356,
756,
12,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
199,
3,
259,
1898,
334,
35,
9,
12521,
13,
7280,
603,
530,
2641,
65,
386,
428,
2431,
8642,
1014,
921,
1544,
14,
15003,
2641,
65,
386,
14,
390,
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,
3267,
199,
3,
259,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
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,
11490,
199,
199,
91,
272,
283,
354,
356,
283,
6009,
18038,
446,
662,
1914,
1865,
492,
17782,
367,
15878,
959,
297,
272,
283,
1023,
356,
283,
16,
14,
17,
297,
272,
283,
3710,
356,
283,
7458,
297,
272,
283,
1802,
356,
408,
267,
3161,
805,
367,
2248,
662,
1914,
1584,
267,
642,
365,
282,
1402,
402,
492,
425,
367,
15878,
959,
267,
961,
730,
402,
859,
787,
10632,
370,
7860,
14,
4627,
367,
18117,
599,
806,
267,
805,
367,
492,
425,
14,
267,
3161,
17782,
365,
315,
2933,
63,
7254,
63,
6297,
4960,
10327,
272,
283,
2502,
356,
283,
45,
530,
2641,
65,
386,
428,
14,
82,
14,
76,
14,
446,
653,
12802,
416,
820,
73,
393,
2730,
297,
272,
283,
7360,
356,
283,
1014,
921,
1544,
14,
15003,
2641,
65,
386,
14,
390,
297,
272,
283,
1682,
356,
283,
1254,
2749,
13,
19,
297,
272,
283,
8912,
356,
359,
267,
283,
1095,
297,
267,
283,
2048,
63,
7254,
63,
6297,
297,
267,
2156,
272,
283,
826,
63,
1652,
356,
990,
272,
283,
8768,
356,
990,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
576,
15,
6297,
63,
4627,
63,
646,
425,
14,
1652,
7,
267,
2156,
272,
283,
2682,
356,
756,
12,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dkodnik/Ant
|
openerp/tests/test_ir_sequence.py
|
38
|
8071
|
# -*- coding: utf-8 -*-
# Run with one of these commands:
# > OPENERP_ADDONS_PATH='../../addons/trunk' OPENERP_PORT=8069 \
# OPENERP_DATABASE=yy PYTHONPATH=. python tests/test_ir_sequence.py
# > OPENERP_ADDONS_PATH='../../addons/trunk' OPENERP_PORT=8069 \
# OPENERP_DATABASE=yy nosetests tests/test_ir_sequence.py
# > OPENERP_ADDONS_PATH='../../../addons/trunk' OPENERP_PORT=8069 \
# OPENERP_DATABASE=yy PYTHONPATH=../:. unit2 test_ir_sequence
# This assume an existing database.
import psycopg2
import psycopg2.errorcodes
import unittest2
import openerp
import common
DB = common.DB
ADMIN_USER_ID = common.ADMIN_USER_ID
def registry(model):
return openerp.modules.registry.RegistryManager.get(DB)[model]
def cursor():
return openerp.modules.registry.RegistryManager.get(DB).db.cursor()
def drop_sequence(code):
cr = cursor()
for model in ['ir.sequence', 'ir.sequence.type']:
s = registry(model)
ids = s.search(cr, ADMIN_USER_ID, [('code', '=', code)])
s.unlink(cr, ADMIN_USER_ID, ids)
cr.commit()
cr.close()
class test_ir_sequence_standard(unittest2.TestCase):
""" A few tests for a 'Standard' (i.e. PostgreSQL) sequence. """
def test_ir_sequence_create(self):
""" Try to create a sequence object. """
cr = cursor()
d = dict(code='test_sequence_type', name='Test sequence type')
c = registry('ir.sequence.type').create(cr, ADMIN_USER_ID, d, {})
assert c
d = dict(code='test_sequence_type', name='Test sequence')
c = registry('ir.sequence').create(cr, ADMIN_USER_ID, d, {})
assert c
cr.commit()
cr.close()
def test_ir_sequence_search(self):
""" Try a search. """
cr = cursor()
ids = registry('ir.sequence').search(cr, ADMIN_USER_ID, [], {})
assert ids
cr.commit()
cr.close()
def test_ir_sequence_draw(self):
""" Try to draw a number. """
cr = cursor()
n = registry('ir.sequence').next_by_code(cr, ADMIN_USER_ID, 'test_sequence_type', {})
assert n
cr.commit()
cr.close()
def test_ir_sequence_draw_twice(self):
""" Try to draw a number from two transactions. """
cr0 = cursor()
cr1 = cursor()
n0 = registry('ir.sequence').next_by_code(cr0, ADMIN_USER_ID, 'test_sequence_type', {})
assert n0
n1 = registry('ir.sequence').next_by_code(cr1, ADMIN_USER_ID, 'test_sequence_type', {})
assert n1
cr0.commit()
cr1.commit()
cr0.close()
cr1.close()
@classmethod
def tearDownClass(cls):
drop_sequence('test_sequence_type')
class test_ir_sequence_no_gap(unittest2.TestCase):
""" Copy of the previous tests for a 'No gap' sequence. """
def test_ir_sequence_create_no_gap(self):
""" Try to create a sequence object. """
cr = cursor()
d = dict(code='test_sequence_type_2', name='Test sequence type')
c = registry('ir.sequence.type').create(cr, ADMIN_USER_ID, d, {})
assert c
d = dict(code='test_sequence_type_2', name='Test sequence',
implementation='no_gap')
c = registry('ir.sequence').create(cr, ADMIN_USER_ID, d, {})
assert c
cr.commit()
cr.close()
def test_ir_sequence_draw_no_gap(self):
""" Try to draw a number. """
cr = cursor()
n = registry('ir.sequence').next_by_code(cr, ADMIN_USER_ID, 'test_sequence_type_2', {})
assert n
cr.commit()
cr.close()
def test_ir_sequence_draw_twice_no_gap(self):
""" Try to draw a number from two transactions.
This is expected to not work.
"""
cr0 = cursor()
cr1 = cursor()
cr1._default_log_exceptions = False # Prevent logging a traceback
with self.assertRaises(psycopg2.OperationalError) as e:
n0 = registry('ir.sequence').next_by_code(cr0, ADMIN_USER_ID, 'test_sequence_type_2', {})
assert n0
n1 = registry('ir.sequence').next_by_code(cr1, ADMIN_USER_ID, 'test_sequence_type_2', {})
self.assertEqual(e.exception.pgcode, psycopg2.errorcodes.LOCK_NOT_AVAILABLE, msg="postgresql returned an incorrect errcode")
cr0.close()
cr1.close()
@classmethod
def tearDownClass(cls):
drop_sequence('test_sequence_type_2')
class test_ir_sequence_change_implementation(unittest2.TestCase):
""" Create sequence objects and change their ``implementation`` field. """
def test_ir_sequence_1_create(self):
""" Try to create a sequence object. """
cr = cursor()
d = dict(code='test_sequence_type_3', name='Test sequence type')
c = registry('ir.sequence.type').create(cr, ADMIN_USER_ID, d, {})
assert c
d = dict(code='test_sequence_type_3', name='Test sequence')
c = registry('ir.sequence').create(cr, ADMIN_USER_ID, d, {})
assert c
d = dict(code='test_sequence_type_4', name='Test sequence type')
c = registry('ir.sequence.type').create(cr, ADMIN_USER_ID, d, {})
assert c
d = dict(code='test_sequence_type_4', name='Test sequence',
implementation='no_gap')
c = registry('ir.sequence').create(cr, ADMIN_USER_ID, d, {})
assert c
cr.commit()
cr.close()
def test_ir_sequence_2_write(self):
cr = cursor()
ids = registry('ir.sequence').search(cr, ADMIN_USER_ID,
[('code', 'in', ['test_sequence_type_3', 'test_sequence_type_4'])], {})
registry('ir.sequence').write(cr, ADMIN_USER_ID, ids,
{'implementation': 'standard'}, {})
registry('ir.sequence').write(cr, ADMIN_USER_ID, ids,
{'implementation': 'no_gap'}, {})
cr.commit()
cr.close()
def test_ir_sequence_3_unlink(self):
cr = cursor()
ids = registry('ir.sequence').search(cr, ADMIN_USER_ID,
[('code', 'in', ['test_sequence_type_3', 'test_sequence_type_4'])], {})
registry('ir.sequence').unlink(cr, ADMIN_USER_ID, ids, {})
cr.commit()
cr.close()
@classmethod
def tearDownClass(cls):
drop_sequence('test_sequence_type_3')
drop_sequence('test_sequence_type_4')
class test_ir_sequence_generate(unittest2.TestCase):
""" Create sequence objects and generate some values. """
def test_ir_sequence_create(self):
""" Try to create a sequence object. """
cr = cursor()
d = dict(code='test_sequence_type_5', name='Test sequence type')
c = registry('ir.sequence.type').create(cr, ADMIN_USER_ID, d, {})
assert c
d = dict(code='test_sequence_type_5', name='Test sequence')
c = registry('ir.sequence').create(cr, ADMIN_USER_ID, d, {})
assert c
cr.commit()
cr.close()
cr = cursor()
f = lambda *a: registry('ir.sequence').next_by_code(cr, ADMIN_USER_ID, 'test_sequence_type_5', {})
assert all(str(x) == f() for x in xrange(1,10))
cr.commit()
cr.close()
def test_ir_sequence_create_no_gap(self):
""" Try to create a sequence object. """
cr = cursor()
d = dict(code='test_sequence_type_6', name='Test sequence type')
c = registry('ir.sequence.type').create(cr, ADMIN_USER_ID, d, {})
assert c
d = dict(code='test_sequence_type_6', name='Test sequence')
c = registry('ir.sequence').create(cr, ADMIN_USER_ID, d, {})
assert c
cr.commit()
cr.close()
cr = cursor()
f = lambda *a: registry('ir.sequence').next_by_code(cr, ADMIN_USER_ID, 'test_sequence_type_6', {})
assert all(str(x) == f() for x in xrange(1,10))
cr.commit()
cr.close()
@classmethod
def tearDownClass(cls):
drop_sequence('test_sequence_type_5')
drop_sequence('test_sequence_type_6')
if __name__ == '__main__':
unittest2.main()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
3378,
543,
1373,
402,
3520,
3718,
26,
199,
3,
259,
690,
24164,
6758,
63,
9732,
23300,
63,
3243,
534,
9707,
10788,
15,
13409,
7,
24164,
6758,
63,
3657,
29,
1257,
1876,
971,
199,
3,
420,
24164,
6758,
63,
17873,
29,
7566,
31176,
15856,
2366,
2295,
15,
396,
63,
723,
63,
4041,
14,
647,
199,
3,
259,
690,
24164,
6758,
63,
9732,
23300,
63,
3243,
534,
9707,
10788,
15,
13409,
7,
24164,
6758,
63,
3657,
29,
1257,
1876,
971,
199,
3,
420,
24164,
6758,
63,
17873,
29,
7566,
11354,
2219,
2295,
15,
396,
63,
723,
63,
4041,
14,
647,
199,
3,
259,
690,
24164,
6758,
63,
9732,
23300,
63,
3243,
534,
29866,
10788,
15,
13409,
7,
24164,
6758,
63,
3657,
29,
1257,
1876,
971,
199,
3,
420,
24164,
6758,
63,
17873,
29,
7566,
31176,
29,
5093,
14010,
4137,
18,
511,
63,
723,
63,
4041,
199,
3,
961,
5534,
376,
3411,
3050,
14,
199,
646,
15492,
18,
199,
646,
15492,
18,
14,
705,
6021,
199,
646,
2882,
18,
199,
199,
646,
5166,
199,
646,
2863,
199,
199,
2846,
275,
2863,
14,
2846,
199,
14288,
63,
3791,
63,
998,
275,
2863,
14,
14288,
63,
3791,
63,
998,
199,
199,
318,
7086,
8,
1238,
304,
272,
372,
5166,
14,
3112,
14,
5189,
14,
10899,
2988,
14,
362,
8,
2846,
2788,
1238,
61,
199,
199,
318,
3920,
837,
272,
372,
5166,
14,
3112,
14,
5189,
14,
10899,
2988,
14,
362,
8,
2846,
680,
697,
14,
3937,
342,
421,
199,
318,
5978,
63,
4041,
8,
600,
304,
272,
2467,
275,
3920,
342,
272,
367,
1402,
315,
788,
723,
14,
4041,
297,
283,
723,
14,
4041,
14,
466,
2565,
267,
308,
275,
7086,
8,
1238,
9,
267,
2762,
275,
308,
14,
1733,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
4274,
600,
297,
6291,
1233,
3948,
267,
308,
14,
7162,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
2762,
9,
272,
2467,
14,
3543,
342,
272,
2467,
14,
1600,
342,
199,
199,
533,
511,
63,
723,
63,
4041,
63,
6807,
8,
2796,
18,
14,
1746,
304,
272,
408,
437,
9284,
2295,
367,
282,
283,
9232,
7,
334,
73,
14,
69,
14,
20175,
9,
3414,
14,
408,
339,
347,
511,
63,
723,
63,
4041,
63,
981,
8,
277,
304,
267,
408,
7649,
370,
1218,
282,
3414,
909,
14,
408,
267,
2467,
275,
3920,
342,
267,
366,
275,
1211,
8,
600,
534,
396,
63,
4041,
63,
466,
297,
536,
534,
774,
3414,
730,
358,
267,
286,
275,
7086,
360,
723,
14,
4041,
14,
466,
1959,
981,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
366,
12,
5009,
267,
702,
286,
267,
366,
275,
1211,
8,
600,
534,
396,
63,
4041,
63,
466,
297,
536,
534,
774,
3414,
358,
267,
286,
275,
7086,
360,
723,
14,
4041,
1959,
981,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
366,
12,
5009,
267,
702,
286,
267,
2467,
14,
3543,
342,
267,
2467,
14,
1600,
342,
339,
347,
511,
63,
723,
63,
4041,
63,
1733,
8,
277,
304,
267,
408,
7649,
282,
2754,
14,
408,
267,
2467,
275,
3920,
342,
267,
2762,
275,
7086,
360,
723,
14,
4041,
1959,
1733,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
990,
5009,
267,
702,
2762,
267,
2467,
14,
3543,
342,
267,
2467,
14,
1600,
342,
339,
347,
511,
63,
723,
63,
4041,
63,
5485,
8,
277,
304,
267,
408,
7649,
370,
5954,
282,
1329,
14,
408,
267,
2467,
275,
3920,
342,
267,
302,
275,
7086,
360,
723,
14,
4041,
1959,
2184,
63,
991,
63,
600,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
283,
396,
63,
4041,
63,
466,
297,
5009,
267,
702,
302,
267,
2467,
14,
3543,
342,
267,
2467,
14,
1600,
342,
339,
347,
511,
63,
723,
63,
4041,
63,
5485,
63,
8122,
1885,
8,
277,
304,
267,
408,
7649,
370,
5954,
282,
1329,
687,
2877,
15809,
14,
408,
267,
2467,
16,
275,
3920,
342,
267,
2467,
17,
275,
3920,
342,
267,
302,
16,
275,
7086,
360,
723,
14,
4041,
1959,
2184,
63,
991,
63,
600,
8,
1556,
16,
12,
29948,
63,
3791,
63,
998,
12,
283,
396,
63,
4041,
63,
466,
297,
5009,
267,
702,
302,
16,
267,
302,
17,
275,
7086,
360,
723,
14,
4041,
1959,
2184,
63,
991,
63,
600,
8,
1556,
17,
12,
29948,
63,
3791,
63,
998,
12,
283,
396,
63,
4041,
63,
466,
297,
5009,
267,
702,
302,
17,
267,
2467,
16,
14,
3543,
342,
267,
2467,
17,
14,
3543,
342,
267,
2467,
16,
14,
1600,
342,
267,
2467,
17,
14,
1600,
342,
339,
768,
3744,
272,
347,
24468,
8,
1886,
304,
267,
5978,
63,
4041,
360,
396,
63,
4041,
63,
466,
358,
199,
199,
533,
511,
63,
723,
63,
4041,
63,
889,
63,
15046,
8,
2796,
18,
14,
1746,
304,
272,
408,
11247,
402,
314,
4136,
2295,
367,
282,
283,
1944,
16301,
7,
3414,
14,
408,
339,
347,
511,
63,
723,
63,
4041,
63,
981,
63,
889,
63,
15046,
8,
277,
304,
267,
408,
7649,
370,
1218,
282,
3414,
909,
14,
408,
267,
2467,
275,
3920,
342,
267,
366,
275,
1211,
8,
600,
534,
396,
63,
4041,
63,
466,
63,
18,
297,
536,
534,
774,
3414,
730,
358,
267,
286,
275,
7086,
360,
723,
14,
4041,
14,
466,
1959,
981,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
366,
12,
5009,
267,
702,
286,
267,
366,
275,
1211,
8,
600,
534,
396,
63,
4041,
63,
466,
63,
18,
297,
536,
534,
774,
3414,
297,
288,
4514,
534,
889,
63,
15046,
358,
267,
286,
275,
7086,
360,
723,
14,
4041,
1959,
981,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
366,
12,
5009,
267,
702,
286,
267,
2467,
14,
3543,
342,
267,
2467,
14,
1600,
342,
339,
347,
511,
63,
723,
63,
4041,
63,
5485,
63,
889,
63,
15046,
8,
277,
304,
267,
408,
7649,
370,
5954,
282,
1329,
14,
408,
267,
2467,
275,
3920,
342,
267,
302,
275,
7086,
360,
723,
14,
4041,
1959,
2184,
63,
991,
63,
600,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
283,
396,
63,
4041,
63,
466,
63,
18,
297,
5009,
267,
702,
302,
267
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
3378,
543,
1373,
402,
3520,
3718,
26,
199,
3,
259,
690,
24164,
6758,
63,
9732,
23300,
63,
3243,
534,
9707,
10788,
15,
13409,
7,
24164,
6758,
63,
3657,
29,
1257,
1876,
971,
199,
3,
420,
24164,
6758,
63,
17873,
29,
7566,
31176,
15856,
2366,
2295,
15,
396,
63,
723,
63,
4041,
14,
647,
199,
3,
259,
690,
24164,
6758,
63,
9732,
23300,
63,
3243,
534,
9707,
10788,
15,
13409,
7,
24164,
6758,
63,
3657,
29,
1257,
1876,
971,
199,
3,
420,
24164,
6758,
63,
17873,
29,
7566,
11354,
2219,
2295,
15,
396,
63,
723,
63,
4041,
14,
647,
199,
3,
259,
690,
24164,
6758,
63,
9732,
23300,
63,
3243,
534,
29866,
10788,
15,
13409,
7,
24164,
6758,
63,
3657,
29,
1257,
1876,
971,
199,
3,
420,
24164,
6758,
63,
17873,
29,
7566,
31176,
29,
5093,
14010,
4137,
18,
511,
63,
723,
63,
4041,
199,
3,
961,
5534,
376,
3411,
3050,
14,
199,
646,
15492,
18,
199,
646,
15492,
18,
14,
705,
6021,
199,
646,
2882,
18,
199,
199,
646,
5166,
199,
646,
2863,
199,
199,
2846,
275,
2863,
14,
2846,
199,
14288,
63,
3791,
63,
998,
275,
2863,
14,
14288,
63,
3791,
63,
998,
199,
199,
318,
7086,
8,
1238,
304,
272,
372,
5166,
14,
3112,
14,
5189,
14,
10899,
2988,
14,
362,
8,
2846,
2788,
1238,
61,
199,
199,
318,
3920,
837,
272,
372,
5166,
14,
3112,
14,
5189,
14,
10899,
2988,
14,
362,
8,
2846,
680,
697,
14,
3937,
342,
421,
199,
318,
5978,
63,
4041,
8,
600,
304,
272,
2467,
275,
3920,
342,
272,
367,
1402,
315,
788,
723,
14,
4041,
297,
283,
723,
14,
4041,
14,
466,
2565,
267,
308,
275,
7086,
8,
1238,
9,
267,
2762,
275,
308,
14,
1733,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
4274,
600,
297,
6291,
1233,
3948,
267,
308,
14,
7162,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
2762,
9,
272,
2467,
14,
3543,
342,
272,
2467,
14,
1600,
342,
199,
199,
533,
511,
63,
723,
63,
4041,
63,
6807,
8,
2796,
18,
14,
1746,
304,
272,
408,
437,
9284,
2295,
367,
282,
283,
9232,
7,
334,
73,
14,
69,
14,
20175,
9,
3414,
14,
408,
339,
347,
511,
63,
723,
63,
4041,
63,
981,
8,
277,
304,
267,
408,
7649,
370,
1218,
282,
3414,
909,
14,
408,
267,
2467,
275,
3920,
342,
267,
366,
275,
1211,
8,
600,
534,
396,
63,
4041,
63,
466,
297,
536,
534,
774,
3414,
730,
358,
267,
286,
275,
7086,
360,
723,
14,
4041,
14,
466,
1959,
981,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
366,
12,
5009,
267,
702,
286,
267,
366,
275,
1211,
8,
600,
534,
396,
63,
4041,
63,
466,
297,
536,
534,
774,
3414,
358,
267,
286,
275,
7086,
360,
723,
14,
4041,
1959,
981,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
366,
12,
5009,
267,
702,
286,
267,
2467,
14,
3543,
342,
267,
2467,
14,
1600,
342,
339,
347,
511,
63,
723,
63,
4041,
63,
1733,
8,
277,
304,
267,
408,
7649,
282,
2754,
14,
408,
267,
2467,
275,
3920,
342,
267,
2762,
275,
7086,
360,
723,
14,
4041,
1959,
1733,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
990,
5009,
267,
702,
2762,
267,
2467,
14,
3543,
342,
267,
2467,
14,
1600,
342,
339,
347,
511,
63,
723,
63,
4041,
63,
5485,
8,
277,
304,
267,
408,
7649,
370,
5954,
282,
1329,
14,
408,
267,
2467,
275,
3920,
342,
267,
302,
275,
7086,
360,
723,
14,
4041,
1959,
2184,
63,
991,
63,
600,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
283,
396,
63,
4041,
63,
466,
297,
5009,
267,
702,
302,
267,
2467,
14,
3543,
342,
267,
2467,
14,
1600,
342,
339,
347,
511,
63,
723,
63,
4041,
63,
5485,
63,
8122,
1885,
8,
277,
304,
267,
408,
7649,
370,
5954,
282,
1329,
687,
2877,
15809,
14,
408,
267,
2467,
16,
275,
3920,
342,
267,
2467,
17,
275,
3920,
342,
267,
302,
16,
275,
7086,
360,
723,
14,
4041,
1959,
2184,
63,
991,
63,
600,
8,
1556,
16,
12,
29948,
63,
3791,
63,
998,
12,
283,
396,
63,
4041,
63,
466,
297,
5009,
267,
702,
302,
16,
267,
302,
17,
275,
7086,
360,
723,
14,
4041,
1959,
2184,
63,
991,
63,
600,
8,
1556,
17,
12,
29948,
63,
3791,
63,
998,
12,
283,
396,
63,
4041,
63,
466,
297,
5009,
267,
702,
302,
17,
267,
2467,
16,
14,
3543,
342,
267,
2467,
17,
14,
3543,
342,
267,
2467,
16,
14,
1600,
342,
267,
2467,
17,
14,
1600,
342,
339,
768,
3744,
272,
347,
24468,
8,
1886,
304,
267,
5978,
63,
4041,
360,
396,
63,
4041,
63,
466,
358,
199,
199,
533,
511,
63,
723,
63,
4041,
63,
889,
63,
15046,
8,
2796,
18,
14,
1746,
304,
272,
408,
11247,
402,
314,
4136,
2295,
367,
282,
283,
1944,
16301,
7,
3414,
14,
408,
339,
347,
511,
63,
723,
63,
4041,
63,
981,
63,
889,
63,
15046,
8,
277,
304,
267,
408,
7649,
370,
1218,
282,
3414,
909,
14,
408,
267,
2467,
275,
3920,
342,
267,
366,
275,
1211,
8,
600,
534,
396,
63,
4041,
63,
466,
63,
18,
297,
536,
534,
774,
3414,
730,
358,
267,
286,
275,
7086,
360,
723,
14,
4041,
14,
466,
1959,
981,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
366,
12,
5009,
267,
702,
286,
267,
366,
275,
1211,
8,
600,
534,
396,
63,
4041,
63,
466,
63,
18,
297,
536,
534,
774,
3414,
297,
288,
4514,
534,
889,
63,
15046,
358,
267,
286,
275,
7086,
360,
723,
14,
4041,
1959,
981,
8,
1556,
12,
29948,
63,
3791,
63,
998,
12,
366,
12,
5009,
267,
702,
286,
267,
2467,
14,
3543,
342,
267,
2467,
14,
1600,
342,
339,
347,
511,
63,
723,
63,
4041,
63,
5485,
63,
889,
63,
15046,
8,
277,
304,
267,
408,
7649,
370,
5954,
282,
1329,
14,
408,
267,
2467,
275,
3920,
342,
267,
302,
275,
7086,
360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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
] |
GinnyN/towerofdimensions-django
|
build/lib/django/contrib/localflavor/ro/forms.py
|
85
|
6762
|
# -*- coding: utf-8 -*-
"""
Romanian specific form helpers.
"""
from __future__ import absolute_import
from django.contrib.localflavor.ro.ro_counties import COUNTIES_CHOICES
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError, Field, RegexField, Select
from django.utils.translation import ugettext_lazy as _
class ROCIFField(RegexField):
"""
A Romanian fiscal identity code (CIF) field
For CIF validation algorithm see http://www.validari.ro/cui.html
"""
default_error_messages = {
'invalid': _("Enter a valid CIF."),
}
def __init__(self, max_length=10, min_length=2, *args, **kwargs):
super(ROCIFField, self).__init__(r'^(RO)?[0-9]{2,10}', max_length,
min_length, *args, **kwargs)
def clean(self, value):
"""
CIF validation
"""
value = super(ROCIFField, self).clean(value)
if value in EMPTY_VALUES:
return u''
# strip RO part
if value[0:2] == 'RO':
value = value[2:]
key = '753217532'[::-1]
value = value[::-1]
key_iter = iter(key)
checksum = 0
for digit in value[1:]:
checksum += int(digit) * int(key_iter.next())
checksum = checksum * 10 % 11
if checksum == 10:
checksum = 0
if checksum != int(value[0]):
raise ValidationError(self.error_messages['invalid'])
return value[::-1]
class ROCNPField(RegexField):
"""
A Romanian personal identity code (CNP) field
For CNP validation algorithm see http://www.validari.ro/cnp.html
"""
default_error_messages = {
'invalid': _("Enter a valid CNP."),
}
def __init__(self, max_length=13, min_length=13, *args, **kwargs):
super(ROCNPField, self).__init__(r'^[1-9][0-9]{12}', max_length,
min_length, *args, **kwargs)
def clean(self, value):
"""
CNP validations
"""
value = super(ROCNPField, self).clean(value)
if value in EMPTY_VALUES:
return u''
# check birthdate digits
import datetime
try:
datetime.date(int(value[1:3]),int(value[3:5]),int(value[5:7]))
except:
raise ValidationError(self.error_messages['invalid'])
# checksum
key = '279146358279'
checksum = 0
value_iter = iter(value)
for digit in key:
checksum += int(digit) * int(value_iter.next())
checksum %= 11
if checksum == 10:
checksum = 1
if checksum != int(value[12]):
raise ValidationError(self.error_messages['invalid'])
return value
class ROCountyField(Field):
"""
A form field that validates its input is a Romanian county name or
abbreviation. It normalizes the input to the standard vehicle registration
abbreviation for the given county
WARNING: This field will only accept names written with diacritics; consider
using ROCountySelect if this behavior is unnaceptable for you
Example:
Argeş => valid
Arges => invalid
"""
default_error_messages = {
'invalid': u'Enter a Romanian county code or name.',
}
def clean(self, value):
super(ROCountyField, self).clean(value)
if value in EMPTY_VALUES:
return u''
try:
value = value.strip().upper()
except AttributeError:
pass
# search for county code
for entry in COUNTIES_CHOICES:
if value in entry:
return value
# search for county name
normalized_CC = []
for entry in COUNTIES_CHOICES:
normalized_CC.append((entry[0],entry[1].upper()))
for entry in normalized_CC:
if entry[1] == value:
return entry[0]
raise ValidationError(self.error_messages['invalid'])
class ROCountySelect(Select):
"""
A Select widget that uses a list of Romanian counties (judete) as its
choices.
"""
def __init__(self, attrs=None):
super(ROCountySelect, self).__init__(attrs, choices=COUNTIES_CHOICES)
class ROIBANField(RegexField):
"""
Romanian International Bank Account Number (IBAN) field
For Romanian IBAN validation algorithm see http://validari.ro/iban.html
"""
default_error_messages = {
'invalid': _('Enter a valid IBAN in ROXX-XXXX-XXXX-XXXX-XXXX-XXXX format'),
}
def __init__(self, max_length=40, min_length=24, *args, **kwargs):
super(ROIBANField, self).__init__(r'^[0-9A-Za-z\-\s]{24,40}$',
max_length, min_length, *args, **kwargs)
def clean(self, value):
"""
Strips - and spaces, performs country code and checksum validation
"""
value = super(ROIBANField, self).clean(value)
if value in EMPTY_VALUES:
return u''
value = value.replace('-','')
value = value.replace(' ','')
value = value.upper()
if value[0:2] != 'RO':
raise ValidationError(self.error_messages['invalid'])
numeric_format = ''
for char in value[4:] + value[0:4]:
if char.isalpha():
numeric_format += str(ord(char) - 55)
else:
numeric_format += char
if int(numeric_format) % 97 != 1:
raise ValidationError(self.error_messages['invalid'])
return value
class ROPhoneNumberField(RegexField):
"""Romanian phone number field"""
default_error_messages = {
'invalid': _('Phone numbers must be in XXXX-XXXXXX format.'),
}
def __init__(self, max_length=20, min_length=10, *args, **kwargs):
super(ROPhoneNumberField, self).__init__(r'^[0-9\-\(\)\s]{10,20}$',
max_length, min_length, *args, **kwargs)
def clean(self, value):
"""
Strips -, (, ) and spaces. Checks the final length.
"""
value = super(ROPhoneNumberField, self).clean(value)
if value in EMPTY_VALUES:
return u''
value = value.replace('-','')
value = value.replace('(','')
value = value.replace(')','')
value = value.replace(' ','')
if len(value) != 10:
raise ValidationError(self.error_messages['invalid'])
return value
class ROPostalCodeField(RegexField):
"""Romanian postal code field."""
default_error_messages = {
'invalid': _('Enter a valid postal code in the format XXXXXX'),
}
def __init__(self, max_length=6, min_length=6, *args, **kwargs):
super(ROPostalCodeField, self).__init__(r'^[0-9][0-8][0-9]{4}$',
max_length, min_length, *args, **kwargs)
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
50,
21604,
5653,
2488,
1824,
10897,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
1639,
14,
2828,
14,
320,
696,
276,
4271,
14,
293,
14,
293,
63,
3094,
1417,
492,
24903,
2563,
63,
16236,
199,
504,
1639,
14,
1018,
14,
11346,
492,
16589,
63,
15514,
199,
504,
1639,
14,
3351,
492,
8505,
12,
5024,
12,
12939,
792,
12,
9496,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
421,
199,
533,
9769,
3553,
38,
792,
8,
5103,
792,
304,
272,
408,
272,
437,
820,
21604,
5653,
18672,
8503,
1233,
334,
3553,
38,
9,
901,
339,
2104,
445,
4656,
6411,
5563,
1937,
1455,
921,
1544,
14,
1078,
759,
14,
293,
15,
67,
1907,
14,
1360,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
3824,
8468,
282,
1686,
445,
4656,
7651,
272,
789,
339,
347,
636,
826,
721,
277,
12,
1390,
63,
1267,
29,
709,
12,
1748,
63,
1267,
29,
18,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
1092,
3553,
38,
792,
12,
291,
2843,
826,
721,
82,
31996,
1092,
5547,
59,
16,
13,
25,
8194,
18,
12,
709,
7293,
1390,
63,
1267,
12,
355,
1748,
63,
1267,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
408,
267,
445,
4656,
6411,
267,
408,
267,
574,
275,
1613,
8,
1092,
3553,
38,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
267,
327,
6202,
9769,
1777,
267,
340,
574,
59,
16,
26,
18,
61,
508,
283,
1092,
356,
288,
574,
275,
574,
59,
18,
2938,
267,
790,
275,
283,
2194,
708,
10848,
708,
3894,
21123,
17,
61,
267,
574,
275,
574,
14172,
17,
61,
267,
790,
63,
1661,
275,
2740,
8,
498,
9,
267,
9040,
275,
378,
267,
367,
10964,
315,
574,
59,
17,
10688,
288,
9040,
847,
1109,
8,
8573,
9,
627,
1109,
8,
498,
63,
1661,
14,
2184,
1012,
267,
9040,
275,
9040,
627,
1616,
450,
4119,
267,
340,
9040,
508,
1616,
26,
288,
9040,
275,
378,
267,
340,
9040,
1137,
1109,
8,
585,
59,
16,
4682,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
372,
574,
14172,
17,
61,
199,
199,
533,
9769,
12874,
48,
792,
8,
5103,
792,
304,
272,
408,
272,
437,
820,
21604,
5653,
25994,
8503,
1233,
334,
12874,
48,
9,
901,
339,
2104,
445,
14970,
6411,
5563,
1937,
1455,
921,
1544,
14,
1078,
759,
14,
293,
15,
67,
1590,
14,
1360,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
3824,
8468,
282,
1686,
445,
14970,
7651,
272,
789,
339,
347,
636,
826,
721,
277,
12,
1390,
63,
1267,
29,
969,
12,
1748,
63,
1267,
29,
969,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
1092,
12874,
48,
792,
12,
291,
2843,
826,
721,
82,
23811,
17,
13,
25,
1527,
16,
13,
25,
8194,
713,
7293,
1390,
63,
1267,
12,
288,
1748,
63,
1267,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
408,
267,
445,
14970,
1686,
1298,
267,
408,
267,
574,
275,
1613,
8,
1092,
12874,
48,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
267,
327,
1104,
21036,
602,
7576,
267,
492,
2197,
267,
862,
26,
288,
2197,
14,
602,
8,
442,
8,
585,
59,
17,
26,
19,
2522,
442,
8,
585,
59,
19,
26,
21,
2522,
442,
8,
585,
59,
21,
26,
23,
2459,
267,
871,
26,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
327,
9040,
267,
790,
275,
283,
12987,
11432,
14321,
12987,
7,
267,
9040,
275,
378,
267,
574,
63,
1661,
275,
2740,
8,
585,
9,
267,
367,
10964,
315,
790,
26,
288,
9040,
847,
1109,
8,
8573,
9,
627,
1109,
8,
585,
63,
1661,
14,
2184,
1012,
267,
9040,
450,
29,
4119,
267,
340,
9040,
508,
1616,
26,
288,
9040,
275,
413,
267,
340,
9040,
1137,
1109,
8,
585,
59,
713,
4682,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
372,
574,
199,
199,
533,
9769,
24532,
369,
792,
8,
792,
304,
272,
408,
272,
437,
1824,
901,
626,
29280,
2399,
1324,
365,
282,
820,
21604,
5653,
4529,
369,
536,
503,
272,
2236,
30369,
14,
2779,
3293,
6491,
314,
1324,
370,
314,
4465,
27616,
10991,
272,
2236,
30369,
367,
314,
1627,
4529,
369,
339,
14750,
26,
961,
901,
911,
1454,
4729,
1561,
5313,
543,
487,
645,
322,
7769,
27,
11201,
272,
1808,
9769,
24532,
369,
5446,
340,
642,
5953,
365,
625,
3540,
716,
461,
367,
1265,
272,
5679,
26,
267,
1952,
303,
130,
254,
9265,
1686,
267,
1952,
3389,
9265,
3866,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
399,
7,
8468,
282,
820,
21604,
5653,
4529,
369,
1233,
503,
536,
3130,
272,
789,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
1613,
8,
1092,
24532,
369,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
267,
862,
26,
288,
574,
275,
574,
14,
1913,
1252,
4142,
342,
267,
871,
4281,
26,
288,
986,
267,
327,
2754,
367,
4529,
369,
1233,
267,
367,
2397,
315,
24903,
2563,
63,
16236,
26,
288,
340,
574,
315,
2397,
26,
355,
372,
574,
267,
327,
2754,
367,
4529,
369,
536,
267,
9657,
63,
2571,
275,
942,
267,
367,
2397,
315,
24903,
2563,
63,
16236,
26,
288,
9657,
63,
2571,
14,
740,
1332,
2373,
59,
16,
467,
2373,
59,
17,
1055,
4142,
4059,
267,
367,
2397,
315,
9657,
63,
2571,
26,
288,
340,
2397,
59,
17,
61,
508,
574,
26,
355,
372,
2397,
59,
16,
61,
267,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
199,
199,
533,
9769,
24532,
369,
5446,
8,
5446,
304,
272,
408,
272,
437,
9496,
3938,
626,
4440,
282,
769,
402,
820,
21604,
5653,
4529,
1417,
334,
74,
3786,
266
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
50,
21604,
5653,
2488,
1824,
10897,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
1639,
14,
2828,
14,
320,
696,
276,
4271,
14,
293,
14,
293,
63,
3094,
1417,
492,
24903,
2563,
63,
16236,
199,
504,
1639,
14,
1018,
14,
11346,
492,
16589,
63,
15514,
199,
504,
1639,
14,
3351,
492,
8505,
12,
5024,
12,
12939,
792,
12,
9496,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
421,
199,
533,
9769,
3553,
38,
792,
8,
5103,
792,
304,
272,
408,
272,
437,
820,
21604,
5653,
18672,
8503,
1233,
334,
3553,
38,
9,
901,
339,
2104,
445,
4656,
6411,
5563,
1937,
1455,
921,
1544,
14,
1078,
759,
14,
293,
15,
67,
1907,
14,
1360,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
3824,
8468,
282,
1686,
445,
4656,
7651,
272,
789,
339,
347,
636,
826,
721,
277,
12,
1390,
63,
1267,
29,
709,
12,
1748,
63,
1267,
29,
18,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
1092,
3553,
38,
792,
12,
291,
2843,
826,
721,
82,
31996,
1092,
5547,
59,
16,
13,
25,
8194,
18,
12,
709,
7293,
1390,
63,
1267,
12,
355,
1748,
63,
1267,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
408,
267,
445,
4656,
6411,
267,
408,
267,
574,
275,
1613,
8,
1092,
3553,
38,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
267,
327,
6202,
9769,
1777,
267,
340,
574,
59,
16,
26,
18,
61,
508,
283,
1092,
356,
288,
574,
275,
574,
59,
18,
2938,
267,
790,
275,
283,
2194,
708,
10848,
708,
3894,
21123,
17,
61,
267,
574,
275,
574,
14172,
17,
61,
267,
790,
63,
1661,
275,
2740,
8,
498,
9,
267,
9040,
275,
378,
267,
367,
10964,
315,
574,
59,
17,
10688,
288,
9040,
847,
1109,
8,
8573,
9,
627,
1109,
8,
498,
63,
1661,
14,
2184,
1012,
267,
9040,
275,
9040,
627,
1616,
450,
4119,
267,
340,
9040,
508,
1616,
26,
288,
9040,
275,
378,
267,
340,
9040,
1137,
1109,
8,
585,
59,
16,
4682,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
372,
574,
14172,
17,
61,
199,
199,
533,
9769,
12874,
48,
792,
8,
5103,
792,
304,
272,
408,
272,
437,
820,
21604,
5653,
25994,
8503,
1233,
334,
12874,
48,
9,
901,
339,
2104,
445,
14970,
6411,
5563,
1937,
1455,
921,
1544,
14,
1078,
759,
14,
293,
15,
67,
1590,
14,
1360,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
3824,
8468,
282,
1686,
445,
14970,
7651,
272,
789,
339,
347,
636,
826,
721,
277,
12,
1390,
63,
1267,
29,
969,
12,
1748,
63,
1267,
29,
969,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
1092,
12874,
48,
792,
12,
291,
2843,
826,
721,
82,
23811,
17,
13,
25,
1527,
16,
13,
25,
8194,
713,
7293,
1390,
63,
1267,
12,
288,
1748,
63,
1267,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
408,
267,
445,
14970,
1686,
1298,
267,
408,
267,
574,
275,
1613,
8,
1092,
12874,
48,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
267,
327,
1104,
21036,
602,
7576,
267,
492,
2197,
267,
862,
26,
288,
2197,
14,
602,
8,
442,
8,
585,
59,
17,
26,
19,
2522,
442,
8,
585,
59,
19,
26,
21,
2522,
442,
8,
585,
59,
21,
26,
23,
2459,
267,
871,
26,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
327,
9040,
267,
790,
275,
283,
12987,
11432,
14321,
12987,
7,
267,
9040,
275,
378,
267,
574,
63,
1661,
275,
2740,
8,
585,
9,
267,
367,
10964,
315,
790,
26,
288,
9040,
847,
1109,
8,
8573,
9,
627,
1109,
8,
585,
63,
1661,
14,
2184,
1012,
267,
9040,
450,
29,
4119,
267,
340,
9040,
508,
1616,
26,
288,
9040,
275,
413,
267,
340,
9040,
1137,
1109,
8,
585,
59,
713,
4682,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
372,
574,
199,
199,
533,
9769,
24532,
369,
792,
8,
792,
304,
272,
408,
272,
437,
1824,
901,
626,
29280,
2399,
1324,
365,
282,
820,
21604,
5653,
4529,
369,
536,
503,
272,
2236,
30369,
14,
2779,
3293,
6491,
314,
1324,
370,
314,
4465,
27616,
10991,
272,
2236,
30369,
367,
314,
1627,
4529,
369,
339,
14750,
26,
961,
901,
911,
1454,
4729,
1561,
5313,
543,
487,
645,
322,
7769,
27,
11201,
272,
1808,
9769,
24532,
369,
5446,
340,
642,
5953,
365,
625,
3540,
716,
461,
367,
1265,
272,
5679,
26,
267,
1952,
303,
130,
254,
9265,
1686,
267,
1952,
3389,
9265,
3866,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
399,
7,
8468,
282,
820,
21604,
5653,
4529,
369,
1233,
503,
536,
3130,
272,
789,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
1613,
8,
1092,
24532,
369,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
267,
862,
26,
288,
574,
275,
574,
14,
1913,
1252,
4142,
342,
267,
871,
4281,
26,
288,
986,
267,
327,
2754,
367,
4529,
369,
1233,
267,
367,
2397,
315,
24903,
2563,
63,
16236,
26,
288,
340,
574,
315,
2397,
26,
355,
372,
574,
267,
327,
2754,
367,
4529,
369,
536,
267,
9657,
63,
2571,
275,
942,
267,
367,
2397,
315,
24903,
2563,
63,
16236,
26,
288,
9657,
63,
2571,
14,
740,
1332,
2373,
59,
16,
467,
2373,
59,
17,
1055,
4142,
4059,
267,
367,
2397,
315,
9657,
63,
2571,
26,
288,
340,
2397,
59,
17,
61,
508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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
] |
dougbeal/gyp
|
test/generator-output/gyptest-depth.py
|
232
|
1561
|
#!/usr/bin/env python
# Copyright 2014 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies building a project hierarchy created when the --generator-output=
and --depth= options is used to put the build configuration files in a separate
directory tree.
"""
import TestGyp
import os
# This is a regression test for the make generator only.
test = TestGyp.TestGyp(formats=['make'])
test.writable(test.workpath('src'), False)
toplevel_dir = os.path.basename(test.workpath())
test.run_gyp(os.path.join(toplevel_dir, 'src', 'prog1.gyp'),
'-Dset_symroot=1',
'--generator-output=gypfiles',
depth=toplevel_dir,
chdir='..')
test.writable(test.workpath('src/build'), True)
test.writable(test.workpath('src/subdir2/build'), True)
test.writable(test.workpath('src/subdir3/build'), True)
test.build('prog1.gyp', test.ALL, chdir='gypfiles')
chdir = 'gypfiles'
expect = """\
Hello from %s
Hello from inc.h
Hello from inc1/include1.h
Hello from inc2/include2.h
Hello from inc3/include3.h
Hello from subdir2/deeper/deeper.h
"""
if test.format == 'xcode':
chdir = 'src'
test.run_built_executable('prog1', chdir=chdir, stdout=expect % 'prog1.c')
if test.format == 'xcode':
chdir = 'src/subdir2'
test.run_built_executable('prog2', chdir=chdir, stdout=expect % 'prog2.c')
if test.format == 'xcode':
chdir = 'src/subdir3'
test.run_built_executable('prog3', chdir=chdir, stdout=expect % 'prog3.c')
test.pass_test()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6927,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
21168,
10015,
282,
2199,
14446,
2737,
1380,
314,
1553,
4679,
13,
1199,
29,
199,
460,
1553,
4631,
29,
1511,
365,
1202,
370,
5324,
314,
1900,
2897,
1584,
315,
282,
7396,
199,
3619,
3123,
14,
199,
624,
199,
199,
646,
25688,
199,
646,
747,
199,
199,
3,
961,
365,
282,
10864,
511,
367,
314,
1852,
4306,
1454,
14,
199,
396,
275,
25688,
14,
774,
13899,
8,
6321,
2968,
1875,
1105,
199,
199,
396,
14,
15053,
8,
396,
14,
800,
515,
360,
2164,
659,
756,
9,
199,
199,
13517,
63,
694,
275,
747,
14,
515,
14,
4846,
8,
396,
14,
800,
515,
1012,
199,
199,
396,
14,
1065,
63,
6179,
8,
736,
14,
515,
14,
904,
8,
13517,
63,
694,
12,
283,
2164,
297,
283,
6595,
17,
14,
6179,
659,
1467,
2475,
36,
409,
63,
3840,
1231,
29,
17,
297,
1467,
2850,
4679,
13,
1199,
29,
6179,
1725,
297,
1467,
5818,
29,
13517,
63,
694,
12,
1467,
13097,
534,
703,
358,
199,
199,
396,
14,
15053,
8,
396,
14,
800,
515,
360,
2164,
15,
1506,
659,
715,
9,
199,
396,
14,
15053,
8,
396,
14,
800,
515,
360,
2164,
15,
10622,
18,
15,
1506,
659,
715,
9,
199,
396,
14,
15053,
8,
396,
14,
800,
515,
360,
2164,
15,
10622,
19,
15,
1506,
659,
715,
9,
199,
199,
396,
14,
1506,
360,
6595,
17,
14,
6179,
297,
511,
14,
1761,
12,
13097,
534,
6179,
1725,
358,
199,
199,
8563,
275,
283,
6179,
1725,
7,
199,
199,
4921,
275,
9638,
199,
6257,
687,
450,
83,
199,
6257,
687,
12864,
14,
72,
199,
6257,
687,
12864,
17,
15,
2613,
17,
14,
72,
199,
6257,
687,
12864,
18,
15,
2613,
18,
14,
72,
199,
6257,
687,
12864,
19,
15,
2613,
19,
14,
72,
199,
6257,
687,
15488,
18,
15,
11192,
529,
15,
11192,
529,
14,
72,
199,
624,
199,
199,
692,
511,
14,
908,
508,
283,
8701,
356,
523,
13097,
275,
283,
2164,
7,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
6595,
17,
297,
13097,
29,
8563,
12,
3839,
29,
4921,
450,
283,
6595,
17,
14,
67,
358,
199,
199,
692,
511,
14,
908,
508,
283,
8701,
356,
523,
13097,
275,
283,
2164,
15,
10622,
18,
7,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
6595,
18,
297,
13097,
29,
8563,
12,
3839,
29,
4921,
450,
283,
6595,
18,
14,
67,
358,
199,
199,
692,
511,
14,
908,
508,
283,
8701,
356,
523,
13097,
275,
283,
2164,
15,
10622,
19,
7,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
6595,
19,
297,
13097,
29,
8563,
12,
3839,
29,
4921,
450,
283,
6595,
19,
14,
67,
358,
199,
199,
396,
14,
1529,
63,
396,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6927,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
21168,
10015,
282,
2199,
14446,
2737,
1380,
314,
1553,
4679,
13,
1199,
29,
199,
460,
1553,
4631,
29,
1511,
365,
1202,
370,
5324,
314,
1900,
2897,
1584,
315,
282,
7396,
199,
3619,
3123,
14,
199,
624,
199,
199,
646,
25688,
199,
646,
747,
199,
199,
3,
961,
365,
282,
10864,
511,
367,
314,
1852,
4306,
1454,
14,
199,
396,
275,
25688,
14,
774,
13899,
8,
6321,
2968,
1875,
1105,
199,
199,
396,
14,
15053,
8,
396,
14,
800,
515,
360,
2164,
659,
756,
9,
199,
199,
13517,
63,
694,
275,
747,
14,
515,
14,
4846,
8,
396,
14,
800,
515,
1012,
199,
199,
396,
14,
1065,
63,
6179,
8,
736,
14,
515,
14,
904,
8,
13517,
63,
694,
12,
283,
2164,
297,
283,
6595,
17,
14,
6179,
659,
1467,
2475,
36,
409,
63,
3840,
1231,
29,
17,
297,
1467,
2850,
4679,
13,
1199,
29,
6179,
1725,
297,
1467,
5818,
29,
13517,
63,
694,
12,
1467,
13097,
534,
703,
358,
199,
199,
396,
14,
15053,
8,
396,
14,
800,
515,
360,
2164,
15,
1506,
659,
715,
9,
199,
396,
14,
15053,
8,
396,
14,
800,
515,
360,
2164,
15,
10622,
18,
15,
1506,
659,
715,
9,
199,
396,
14,
15053,
8,
396,
14,
800,
515,
360,
2164,
15,
10622,
19,
15,
1506,
659,
715,
9,
199,
199,
396,
14,
1506,
360,
6595,
17,
14,
6179,
297,
511,
14,
1761,
12,
13097,
534,
6179,
1725,
358,
199,
199,
8563,
275,
283,
6179,
1725,
7,
199,
199,
4921,
275,
9638,
199,
6257,
687,
450,
83,
199,
6257,
687,
12864,
14,
72,
199,
6257,
687,
12864,
17,
15,
2613,
17,
14,
72,
199,
6257,
687,
12864,
18,
15,
2613,
18,
14,
72,
199,
6257,
687,
12864,
19,
15,
2613,
19,
14,
72,
199,
6257,
687,
15488,
18,
15,
11192,
529,
15,
11192,
529,
14,
72,
199,
624,
199,
199,
692,
511,
14,
908,
508,
283,
8701,
356,
523,
13097,
275,
283,
2164,
7,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
6595,
17,
297,
13097,
29,
8563,
12,
3839,
29,
4921,
450,
283,
6595,
17,
14,
67,
358,
199,
199,
692,
511,
14,
908,
508,
283,
8701,
356,
523,
13097,
275,
283,
2164,
15,
10622,
18,
7,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
6595,
18,
297,
13097,
29,
8563,
12,
3839,
29,
4921,
450,
283,
6595,
18,
14,
67,
358,
199,
199,
692,
511,
14,
908,
508,
283,
8701,
356,
523,
13097,
275,
283,
2164,
15,
10622,
19,
7,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
6595,
19,
297,
13097,
29,
8563,
12,
3839,
29,
4921,
450,
283,
6595,
19,
14,
67,
358,
199,
199,
396,
14,
1529,
63,
396,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
devops2014/djangosite
|
tests/select_related/tests.py
|
38
|
8821
|
from __future__ import unicode_literals
from django.core.exceptions import FieldError
from django.test import TestCase
from .models import (
Bookmark, Domain, Family, Genus, HybridSpecies, Kingdom, Klass, Order,
Phylum, Pizza, Species, TaggedItem,
)
class SelectRelatedTests(TestCase):
@classmethod
def create_tree(cls, stringtree):
"""
Helper to create a complete tree.
"""
names = stringtree.split()
models = [Domain, Kingdom, Phylum, Klass, Order, Family, Genus, Species]
assert len(names) == len(models), (names, models)
parent = None
for name, model in zip(names, models):
try:
obj = model.objects.get(name=name)
except model.DoesNotExist:
obj = model(name=name)
if parent:
setattr(obj, parent.__class__.__name__.lower(), parent)
obj.save()
parent = obj
@classmethod
def setUpTestData(cls):
cls.create_tree("Eukaryota Animalia Anthropoda Insecta Diptera Drosophilidae Drosophila melanogaster")
cls.create_tree("Eukaryota Animalia Chordata Mammalia Primates Hominidae Homo sapiens")
cls.create_tree("Eukaryota Plantae Magnoliophyta Magnoliopsida Fabales Fabaceae Pisum sativum")
cls.create_tree("Eukaryota Fungi Basidiomycota Homobasidiomycatae Agaricales Amanitacae Amanita muscaria")
def test_access_fks_without_select_related(self):
"""
Normally, accessing FKs doesn't fill in related objects
"""
with self.assertNumQueries(8):
fly = Species.objects.get(name="melanogaster")
domain = fly.genus.family.order.klass.phylum.kingdom.domain
self.assertEqual(domain.name, 'Eukaryota')
def test_access_fks_with_select_related(self):
"""
A select_related() call will fill in those related objects without any
extra queries
"""
with self.assertNumQueries(1):
person = Species.objects.select_related('genus__family__order__klass__phylum__kingdom__domain').get(name="sapiens")
domain = person.genus.family.order.klass.phylum.kingdom.domain
self.assertEqual(domain.name, 'Eukaryota')
def test_list_without_select_related(self):
"""
select_related() also of course applies to entire lists, not just
items. This test verifies the expected behavior without select_related.
"""
with self.assertNumQueries(9):
world = Species.objects.all()
families = [o.genus.family.name for o in world]
self.assertEqual(sorted(families), [
'Amanitacae',
'Drosophilidae',
'Fabaceae',
'Hominidae',
])
def test_list_with_select_related(self):
"""
select_related() also of course applies to entire lists, not just
items. This test verifies the expected behavior with select_related.
"""
with self.assertNumQueries(1):
world = Species.objects.all().select_related()
families = [o.genus.family.name for o in world]
self.assertEqual(sorted(families), [
'Amanitacae',
'Drosophilidae',
'Fabaceae',
'Hominidae',
])
def test_list_with_depth(self):
"""
Passing a relationship field lookup specifier to select_related() will
stop the descent at a particular level. This can be used on lists as
well.
"""
with self.assertNumQueries(5):
world = Species.objects.all().select_related('genus__family')
orders = [o.genus.family.order.name for o in world]
self.assertEqual(sorted(orders),
['Agaricales', 'Diptera', 'Fabales', 'Primates'])
def test_select_related_with_extra(self):
s = (Species.objects.all()
.select_related()
.extra(select={'a': 'select_related_species.id + 10'})[0])
self.assertEqual(s.id + 10, s.a)
def test_certain_fields(self):
"""
The optional fields passed to select_related() control which related
models we pull in. This allows for smaller queries.
In this case, we explicitly say to select the 'genus' and
'genus.family' models, leading to the same number of queries as before.
"""
with self.assertNumQueries(1):
world = Species.objects.select_related('genus__family')
families = [o.genus.family.name for o in world]
self.assertEqual(sorted(families),
['Amanitacae', 'Drosophilidae', 'Fabaceae', 'Hominidae'])
def test_more_certain_fields(self):
"""
In this case, we explicitly say to select the 'genus' and
'genus.family' models, leading to the same number of queries as before.
"""
with self.assertNumQueries(2):
world = Species.objects.filter(genus__name='Amanita')\
.select_related('genus__family')
orders = [o.genus.family.order.name for o in world]
self.assertEqual(orders, ['Agaricales'])
def test_single_related_field(self):
with self.assertNumQueries(1):
species = Species.objects.select_related('genus__name')
names = [s.genus.name for s in species]
self.assertEqual(sorted(names), ['Amanita', 'Drosophila', 'Homo', 'Pisum'])
def test_field_traversal(self):
with self.assertNumQueries(1):
s = (Species.objects.all()
.select_related('genus__family__order')
.order_by('id')[0:1].get().genus.family.order.name)
self.assertEqual(s, 'Diptera')
def test_depth_fields_fails(self):
self.assertRaises(
TypeError,
Species.objects.select_related,
'genus__family__order', depth=4
)
def test_none_clears_list(self):
queryset = Species.objects.select_related('genus').select_related(None)
self.assertEqual(queryset.query.select_related, False)
def test_chaining(self):
parent_1, parent_2 = Species.objects.all()[:2]
HybridSpecies.objects.create(name='hybrid', parent_1=parent_1, parent_2=parent_2)
queryset = HybridSpecies.objects.select_related('parent_1').select_related('parent_2')
with self.assertNumQueries(1):
obj = queryset[0]
self.assertEqual(obj.parent_1, parent_1)
self.assertEqual(obj.parent_2, parent_2)
class SelectRelatedValidationTests(TestCase):
"""
select_related() should thrown an error on fields that do not exist and
non-relational fields.
"""
non_relational_error = "Non-relational field given in select_related: '%s'. Choices are: %s"
invalid_error = "Invalid field name(s) given in select_related: '%s'. Choices are: %s"
def test_non_relational_field(self):
with self.assertRaisesMessage(FieldError, self.non_relational_error % ('name', 'genus')):
list(Species.objects.select_related('name__some_field'))
with self.assertRaisesMessage(FieldError, self.non_relational_error % ('name', 'genus')):
list(Species.objects.select_related('name'))
with self.assertRaisesMessage(FieldError, self.non_relational_error % ('name', '(none)')):
list(Domain.objects.select_related('name'))
def test_many_to_many_field(self):
with self.assertRaisesMessage(FieldError, self.invalid_error % ('toppings', '(none)')):
list(Pizza.objects.select_related('toppings'))
def test_reverse_relational_field(self):
with self.assertRaisesMessage(FieldError, self.invalid_error % ('child_1', 'genus')):
list(Species.objects.select_related('child_1'))
def test_invalid_field(self):
with self.assertRaisesMessage(FieldError, self.invalid_error % ('invalid_field', 'genus')):
list(Species.objects.select_related('invalid_field'))
with self.assertRaisesMessage(FieldError, self.invalid_error % ('related_invalid_field', 'family')):
list(Species.objects.select_related('genus__related_invalid_field'))
with self.assertRaisesMessage(FieldError, self.invalid_error % ('invalid_field', '(none)')):
list(Domain.objects.select_related('invalid_field'))
def test_generic_relations(self):
with self.assertRaisesMessage(FieldError, self.invalid_error % ('tags', '')):
list(Bookmark.objects.select_related('tags'))
with self.assertRaisesMessage(FieldError, self.invalid_error % ('content_object', 'content_type')):
list(TaggedItem.objects.select_related('content_object'))
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
27691,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
992,
492,
334,
272,
8944,
1657,
12,
14061,
12,
481,
4632,
12,
18870,
527,
12,
29591,
14601,
6154,
397,
12,
1804,
316,
4556,
12,
1804,
4297,
12,
9240,
12,
272,
24309,
25065,
12,
510,
30937,
12,
5367,
397,
12,
32121,
2081,
12,
199,
9,
421,
199,
533,
9496,
13885,
2925,
8,
1746,
304,
339,
768,
3744,
272,
347,
1218,
63,
2350,
8,
1886,
12,
1059,
2350,
304,
267,
408,
267,
11642,
370,
1218,
282,
4890,
3123,
14,
267,
408,
267,
1561,
275,
1059,
2350,
14,
1294,
342,
267,
1709,
275,
359,
7705,
12,
1804,
316,
4556,
12,
24309,
25065,
12,
1804,
4297,
12,
9240,
12,
481,
4632,
12,
18870,
527,
12,
5367,
397,
61,
267,
702,
822,
8,
1247,
9,
508,
822,
8,
992,
395,
334,
1247,
12,
1709,
9,
398,
1676,
275,
488,
267,
367,
536,
12,
1402,
315,
3482,
8,
1247,
12,
1709,
304,
288,
862,
26,
355,
1559,
275,
1402,
14,
1462,
14,
362,
8,
354,
29,
354,
9,
288,
871,
1402,
14,
7400,
26,
355,
1559,
275,
1402,
8,
354,
29,
354,
9,
288,
340,
1676,
26,
355,
5371,
8,
1113,
12,
1676,
855,
533,
4914,
354,
4343,
2325,
1062,
1676,
9,
288,
1559,
14,
2117,
342,
288,
1676,
275,
1559,
339,
768,
3744,
272,
347,
3613,
16550,
8,
1886,
304,
267,
843,
14,
981,
63,
2350,
480,
37,
3210,
695,
12041,
1626,
7265,
4674,
1626,
273,
2675,
364,
65,
1010,
8519,
65,
577,
711,
2967,
577,
4796,
24316,
1638,
9747,
577,
4796,
24316,
25330,
562,
1502,
974,
2311,
531,
267,
843,
14,
981,
63,
2350,
480,
37,
3210,
695,
12041,
1626,
7265,
4674,
2799,
269,
576,
603,
455,
2174,
4674,
8538,
77,
2335,
869,
676,
262,
344,
3624,
28673,
573,
308,
1246,
8764,
531,
267,
843,
14,
981,
63,
2350,
480,
37,
3210,
695,
12041,
32427,
502,
69,
603,
643,
889,
317,
411,
3577,
502,
603,
643,
889,
317,
411,
338,
983,
481,
371,
7098,
481,
371,
7984,
3624,
510,
374,
453,
308,
2159,
86,
453,
531,
267,
843,
14,
981,
63,
2350,
480,
37,
3210,
695,
12041,
481,
324,
6153,
699,
305,
9897,
676,
89,
331,
502,
28673,
573,
31917,
9897,
676,
29874,
419,
69,
21582,
285,
530,
7098,
437,
1237,
390,
645,
3624,
437,
1237,
21492,
333,
527,
67,
27957,
531,
339,
347,
511,
63,
2732,
63,
70,
6080,
63,
7395,
63,
2416,
63,
2407,
8,
277,
304,
267,
408,
267,
24573,
12,
18549,
18821,
83,
3181,
1133,
5554,
315,
4048,
2251,
267,
408,
267,
543,
291,
14,
16463,
8,
24,
304,
288,
23158,
275,
5367,
397,
14,
1462,
14,
362,
8,
354,
628,
278,
1502,
974,
2311,
531,
288,
2881,
275,
23158,
14,
2268,
527,
14,
6606,
14,
1648,
14,
11645,
14,
6581,
25065,
14,
17443,
4556,
14,
2261,
288,
291,
14,
629,
8,
2261,
14,
354,
12,
283,
37,
3210,
695,
12041,
358,
339,
347,
511,
63,
2732,
63,
70,
6080,
63,
1045,
63,
2416,
63,
2407,
8,
277,
304,
267,
408,
267,
437,
3504,
63,
2407,
342,
1240,
911,
5554,
315,
5204,
4048,
2251,
1928,
1263,
267,
2402,
9212,
267,
408,
267,
543,
291,
14,
16463,
8,
17,
304,
288,
4954,
275,
5367,
397,
14,
1462,
14,
2416,
63,
2407,
360,
2268,
527,
363,
6606,
363,
1648,
363,
11645,
363,
6581,
25065,
363,
17443,
4556,
363,
2261,
1959,
362,
8,
354,
628,
83,
1246,
8764,
531,
288,
2881,
275,
4954,
14,
2268,
527,
14,
6606,
14,
1648,
14,
11645,
14,
6581,
25065,
14,
17443,
4556,
14,
2261,
288,
291,
14,
629,
8,
2261,
14,
354,
12,
283,
37,
3210,
695,
12041,
358,
339,
347,
511,
63,
513,
63,
7395,
63,
2416,
63,
2407,
8,
277,
304,
267,
408,
267,
3504,
63,
2407,
342,
2597,
402,
2518,
12966,
370,
8039,
5548,
12,
440,
2951,
267,
2974,
14,
961,
511,
22694,
314,
1420,
5953,
1928,
3504,
63,
2407,
14,
267,
408,
267,
543,
291,
14,
16463,
8,
25,
304,
288,
6701,
275,
5367,
397,
14,
1462,
14,
452,
342,
288,
21450,
20111,
275,
359,
79,
14,
2268,
527,
14,
6606,
14,
354,
367,
312,
315,
6701,
61,
288,
291,
14,
629,
8,
5917,
8,
32337,
395,
359,
355,
283,
33,
1237,
390,
645,
3624,
297,
355,
283,
36,
4796,
24316,
1638,
9747,
297,
355,
283,
38,
371,
7984,
3624,
297,
355,
283,
40,
676,
262,
344,
3624,
297,
288,
4794,
339,
347,
511,
63,
513,
63,
1045,
63,
2416,
63,
2407,
8,
277,
304,
267,
408,
267,
3504,
63,
2407,
342,
2597,
402,
2518,
12966,
370,
8039,
5548,
12,
440,
2951,
267,
2974,
14,
961,
511,
22694,
314,
1420,
5953,
543,
3504,
63,
2407,
14,
267,
408,
267,
543,
291,
14,
16463,
8,
17,
304,
288,
6701,
275,
5367,
397,
14,
1462,
14,
452,
1252,
2416,
63,
2407,
342,
288,
21450,
20111,
275,
359,
79,
14,
2268,
527,
14,
6606,
14,
354,
367,
312,
315,
6701,
61,
288,
291,
14,
629,
8,
5917,
8,
32337,
395,
359,
355,
283,
33,
1237,
390,
645,
3624,
297,
355,
283,
36,
4796,
24316,
1638,
9747,
297,
355,
283,
38,
371,
7984,
3624,
297,
355,
283,
40,
676,
262,
344,
3624,
297,
288,
4794,
339,
347,
511,
63,
513,
63,
1045,
63,
4631,
8,
277,
304,
267,
408,
267,
31755,
282,
8931,
901,
4237,
16628,
370,
3504,
63,
2407,
342,
911,
267,
3631,
314,
31518,
737,
282,
6770,
2166,
14,
961,
883,
506,
1202,
641,
5548,
465,
267,
5521,
14,
267,
408,
267,
543,
291,
14,
16463,
8,
21,
304,
288,
6701,
275,
5367,
397,
14,
1462,
14,
452,
1252,
2416,
63,
2407,
360,
2268,
527,
363,
6606,
358,
288,
15460,
275,
359,
79,
14,
2268,
527,
14,
6606,
14,
1648,
14,
354,
367,
312,
315,
6701,
61,
288,
291,
14,
629,
8,
5917,
8,
14387,
395,
355,
788,
5676,
285,
530,
7098,
297,
283,
36,
711,
2967,
297,
283,
38,
371,
7098,
297,
283,
4562,
77,
2335,
1105,
339,
347,
511,
63,
2416,
63,
2407,
63,
1045,
63,
2911,
8,
277,
304,
267,
308,
275,
334,
6154,
397,
14,
1462
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
27691,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
992,
492,
334,
272,
8944,
1657,
12,
14061,
12,
481,
4632,
12,
18870,
527,
12,
29591,
14601,
6154,
397,
12,
1804,
316,
4556,
12,
1804,
4297,
12,
9240,
12,
272,
24309,
25065,
12,
510,
30937,
12,
5367,
397,
12,
32121,
2081,
12,
199,
9,
421,
199,
533,
9496,
13885,
2925,
8,
1746,
304,
339,
768,
3744,
272,
347,
1218,
63,
2350,
8,
1886,
12,
1059,
2350,
304,
267,
408,
267,
11642,
370,
1218,
282,
4890,
3123,
14,
267,
408,
267,
1561,
275,
1059,
2350,
14,
1294,
342,
267,
1709,
275,
359,
7705,
12,
1804,
316,
4556,
12,
24309,
25065,
12,
1804,
4297,
12,
9240,
12,
481,
4632,
12,
18870,
527,
12,
5367,
397,
61,
267,
702,
822,
8,
1247,
9,
508,
822,
8,
992,
395,
334,
1247,
12,
1709,
9,
398,
1676,
275,
488,
267,
367,
536,
12,
1402,
315,
3482,
8,
1247,
12,
1709,
304,
288,
862,
26,
355,
1559,
275,
1402,
14,
1462,
14,
362,
8,
354,
29,
354,
9,
288,
871,
1402,
14,
7400,
26,
355,
1559,
275,
1402,
8,
354,
29,
354,
9,
288,
340,
1676,
26,
355,
5371,
8,
1113,
12,
1676,
855,
533,
4914,
354,
4343,
2325,
1062,
1676,
9,
288,
1559,
14,
2117,
342,
288,
1676,
275,
1559,
339,
768,
3744,
272,
347,
3613,
16550,
8,
1886,
304,
267,
843,
14,
981,
63,
2350,
480,
37,
3210,
695,
12041,
1626,
7265,
4674,
1626,
273,
2675,
364,
65,
1010,
8519,
65,
577,
711,
2967,
577,
4796,
24316,
1638,
9747,
577,
4796,
24316,
25330,
562,
1502,
974,
2311,
531,
267,
843,
14,
981,
63,
2350,
480,
37,
3210,
695,
12041,
1626,
7265,
4674,
2799,
269,
576,
603,
455,
2174,
4674,
8538,
77,
2335,
869,
676,
262,
344,
3624,
28673,
573,
308,
1246,
8764,
531,
267,
843,
14,
981,
63,
2350,
480,
37,
3210,
695,
12041,
32427,
502,
69,
603,
643,
889,
317,
411,
3577,
502,
603,
643,
889,
317,
411,
338,
983,
481,
371,
7098,
481,
371,
7984,
3624,
510,
374,
453,
308,
2159,
86,
453,
531,
267,
843,
14,
981,
63,
2350,
480,
37,
3210,
695,
12041,
481,
324,
6153,
699,
305,
9897,
676,
89,
331,
502,
28673,
573,
31917,
9897,
676,
29874,
419,
69,
21582,
285,
530,
7098,
437,
1237,
390,
645,
3624,
437,
1237,
21492,
333,
527,
67,
27957,
531,
339,
347,
511,
63,
2732,
63,
70,
6080,
63,
7395,
63,
2416,
63,
2407,
8,
277,
304,
267,
408,
267,
24573,
12,
18549,
18821,
83,
3181,
1133,
5554,
315,
4048,
2251,
267,
408,
267,
543,
291,
14,
16463,
8,
24,
304,
288,
23158,
275,
5367,
397,
14,
1462,
14,
362,
8,
354,
628,
278,
1502,
974,
2311,
531,
288,
2881,
275,
23158,
14,
2268,
527,
14,
6606,
14,
1648,
14,
11645,
14,
6581,
25065,
14,
17443,
4556,
14,
2261,
288,
291,
14,
629,
8,
2261,
14,
354,
12,
283,
37,
3210,
695,
12041,
358,
339,
347,
511,
63,
2732,
63,
70,
6080,
63,
1045,
63,
2416,
63,
2407,
8,
277,
304,
267,
408,
267,
437,
3504,
63,
2407,
342,
1240,
911,
5554,
315,
5204,
4048,
2251,
1928,
1263,
267,
2402,
9212,
267,
408,
267,
543,
291,
14,
16463,
8,
17,
304,
288,
4954,
275,
5367,
397,
14,
1462,
14,
2416,
63,
2407,
360,
2268,
527,
363,
6606,
363,
1648,
363,
11645,
363,
6581,
25065,
363,
17443,
4556,
363,
2261,
1959,
362,
8,
354,
628,
83,
1246,
8764,
531,
288,
2881,
275,
4954,
14,
2268,
527,
14,
6606,
14,
1648,
14,
11645,
14,
6581,
25065,
14,
17443,
4556,
14,
2261,
288,
291,
14,
629,
8,
2261,
14,
354,
12,
283,
37,
3210,
695,
12041,
358,
339,
347,
511,
63,
513,
63,
7395,
63,
2416,
63,
2407,
8,
277,
304,
267,
408,
267,
3504,
63,
2407,
342,
2597,
402,
2518,
12966,
370,
8039,
5548,
12,
440,
2951,
267,
2974,
14,
961,
511,
22694,
314,
1420,
5953,
1928,
3504,
63,
2407,
14,
267,
408,
267,
543,
291,
14,
16463,
8,
25,
304,
288,
6701,
275,
5367,
397,
14,
1462,
14,
452,
342,
288,
21450,
20111,
275,
359,
79,
14,
2268,
527,
14,
6606,
14,
354,
367,
312,
315,
6701,
61,
288,
291,
14,
629,
8,
5917,
8,
32337,
395,
359,
355,
283,
33,
1237,
390,
645,
3624,
297,
355,
283,
36,
4796,
24316,
1638,
9747,
297,
355,
283,
38,
371,
7984,
3624,
297,
355,
283,
40,
676,
262,
344,
3624,
297,
288,
4794,
339,
347,
511,
63,
513,
63,
1045,
63,
2416,
63,
2407,
8,
277,
304,
267,
408,
267,
3504,
63,
2407,
342,
2597,
402,
2518,
12966,
370,
8039,
5548,
12,
440,
2951,
267,
2974,
14,
961,
511,
22694,
314,
1420,
5953,
543,
3504,
63,
2407,
14,
267,
408,
267,
543,
291,
14,
16463,
8,
17,
304,
288,
6701,
275,
5367,
397,
14,
1462,
14,
452,
1252,
2416,
63,
2407,
342,
288,
21450,
20111,
275,
359,
79,
14,
2268,
527,
14,
6606,
14,
354,
367,
312,
315,
6701,
61,
288,
291,
14,
629,
8,
5917,
8,
32337,
395,
359,
355,
283,
33,
1237,
390,
645,
3624,
297,
355,
283,
36,
4796,
24316,
1638,
9747,
297,
355,
283,
38,
371,
7984,
3624,
297,
355,
283,
40,
676,
262,
344,
3624,
297,
288,
4794,
339,
347,
511,
63,
513,
63,
1045,
63,
4631,
8,
277,
304,
267,
408,
267,
31755,
282,
8931,
901,
4237,
16628,
370,
3504,
63,
2407,
342,
911,
267,
3631,
314,
31518,
737,
282,
6770,
2166,
14,
961,
883,
506,
1202,
641,
5548,
465,
267,
5521,
14,
267,
408,
267,
543,
291,
14,
16463,
8,
21,
304,
288,
6701,
275,
5367,
397,
14,
1462,
14,
452,
1252,
2416,
63,
2407,
360,
2268,
527,
363,
6606,
358,
288,
15460,
275,
359,
79,
14,
2268,
527,
14,
6606,
14,
1648,
14,
354,
367,
312,
315,
6701,
61,
288,
291,
14,
629,
8,
5917,
8,
14387,
395,
355,
788,
5676,
285,
530,
7098,
297,
283,
36,
711,
2967,
297,
283,
38,
371,
7098,
297,
283,
4562,
77,
2335,
1105,
339,
347,
511,
63,
2416,
63,
2407,
63,
1045,
63,
2911,
8,
277,
304,
267,
308,
275,
334,
6154,
397,
14,
1462,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
lookout/dd-agent
|
checks.d/elastic.py
|
3
|
29804
|
# stdlib
from collections import defaultdict, namedtuple
import time
import urlparse
# 3p
import requests
# project
from checks import AgentCheck
from config import _is_affirmative
from util import headers
class NodeNotFound(Exception):
pass
ESInstanceConfig = namedtuple(
'ESInstanceConfig', [
'pshard_stats',
'cluster_stats',
'password',
'service_check_tags',
'tags',
'timeout',
'url',
'username',
'pending_task_stats',
])
class ESCheck(AgentCheck):
SERVICE_CHECK_CONNECT_NAME = 'elasticsearch.can_connect'
SERVICE_CHECK_CLUSTER_STATUS = 'elasticsearch.cluster_health'
DEFAULT_TIMEOUT = 5
# Clusterwise metrics, pre aggregated on ES, compatible with all ES versions
PRIMARY_SHARD_METRICS = {
"elasticsearch.primaries.docs.count": ("gauge", "_all.primaries.docs.count"),
"elasticsearch.primaries.docs.deleted": ("gauge", "_all.primaries.docs.deleted"),
"elasticsearch.primaries.store.size": ("gauge", "_all.primaries.store.size_in_bytes"),
"elasticsearch.primaries.indexing.index.total": ("gauge", "_all.primaries.indexing.index_total"),
"elasticsearch.primaries.indexing.index.time": ("gauge", "_all.primaries.indexing.index_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.primaries.indexing.index.current": ("gauge", "_all.primaries.indexing.index_current"),
"elasticsearch.primaries.indexing.delete.total": ("gauge", "_all.primaries.indexing.delete_total"),
"elasticsearch.primaries.indexing.delete.time": ("gauge", "_all.primaries.indexing.delete_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.primaries.indexing.delete.current": ("gauge", "_all.primaries.indexing.delete_current"),
"elasticsearch.primaries.get.total": ("gauge", "_all.primaries.get.total"),
"elasticsearch.primaries.get.time": ("gauge", "_all.primaries.get.time_in_millis", lambda v: float(v)/1000),
"elasticsearch.primaries.get.current": ("gauge", "_all.primaries.get.current"),
"elasticsearch.primaries.get.exists.total": ("gauge", "_all.primaries.get.exists_total"),
"elasticsearch.primaries.get.exists.time": ("gauge", "_all.primaries.get.exists_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.primaries.get.missing.total": ("gauge", "_all.primaries.get.missing_total"),
"elasticsearch.primaries.get.missing.time": ("gauge", "_all.primaries.get.missing_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.primaries.search.query.total": ("gauge", "_all.primaries.search.query_total"),
"elasticsearch.primaries.search.query.time": ("gauge", "_all.primaries.search.query_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.primaries.search.query.current": ("gauge", "_all.primaries.search.query_current"),
"elasticsearch.primaries.search.fetch.total": ("gauge", "_all.primaries.search.fetch_total"),
"elasticsearch.primaries.search.fetch.time": ("gauge", "_all.primaries.search.fetch_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.primaries.search.fetch.current": ("gauge", "_all.primaries.search.fetch_current")
}
PRIMARY_SHARD_METRICS_POST_1_0 = {
"elasticsearch.primaries.merges.current": ("gauge", "_all.primaries.merges.current"),
"elasticsearch.primaries.merges.current.docs": ("gauge", "_all.primaries.merges.current_docs"),
"elasticsearch.primaries.merges.current.size": ("gauge", "_all.primaries.merges.current_size_in_bytes"),
"elasticsearch.primaries.merges.total": ("gauge", "_all.primaries.merges.total"),
"elasticsearch.primaries.merges.total.time": ("gauge", "_all.primaries.merges.total_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.primaries.merges.total.docs": ("gauge", "_all.primaries.merges.total_docs"),
"elasticsearch.primaries.merges.total.size": ("gauge", "_all.primaries.merges.total_size_in_bytes"),
"elasticsearch.primaries.refresh.total": ("gauge", "_all.primaries.refresh.total"),
"elasticsearch.primaries.refresh.total.time": ("gauge", "_all.primaries.refresh.total_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.primaries.flush.total": ("gauge", "_all.primaries.flush.total"),
"elasticsearch.primaries.flush.total.time": ("gauge", "_all.primaries.flush.total_time_in_millis", lambda v: float(v)/1000)
}
STATS_METRICS = { # Metrics that are common to all Elasticsearch versions
"elasticsearch.docs.count": ("gauge", "indices.docs.count"),
"elasticsearch.docs.deleted": ("gauge", "indices.docs.deleted"),
"elasticsearch.store.size": ("gauge", "indices.store.size_in_bytes"),
"elasticsearch.indexing.index.total": ("gauge", "indices.indexing.index_total"),
"elasticsearch.indexing.index.time": ("gauge", "indices.indexing.index_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.indexing.index.current": ("gauge", "indices.indexing.index_current"),
"elasticsearch.indexing.delete.total": ("gauge", "indices.indexing.delete_total"),
"elasticsearch.indexing.delete.time": ("gauge", "indices.indexing.delete_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.indexing.delete.current": ("gauge", "indices.indexing.delete_current"),
"elasticsearch.get.total": ("gauge", "indices.get.total"),
"elasticsearch.get.time": ("gauge", "indices.get.time_in_millis", lambda v: float(v)/1000),
"elasticsearch.get.current": ("gauge", "indices.get.current"),
"elasticsearch.get.exists.total": ("gauge", "indices.get.exists_total"),
"elasticsearch.get.exists.time": ("gauge", "indices.get.exists_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.get.missing.total": ("gauge", "indices.get.missing_total"),
"elasticsearch.get.missing.time": ("gauge", "indices.get.missing_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.search.query.total": ("gauge", "indices.search.query_total"),
"elasticsearch.search.query.time": ("gauge", "indices.search.query_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.search.query.current": ("gauge", "indices.search.query_current"),
"elasticsearch.search.fetch.total": ("gauge", "indices.search.fetch_total"),
"elasticsearch.search.fetch.time": ("gauge", "indices.search.fetch_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.search.fetch.current": ("gauge", "indices.search.fetch_current"),
"elasticsearch.indices.segments.count": ("gauge", "indices.segments.count"),
"elasticsearch.indices.segments.memory_in_bytes": ("gauge", "indices.segments.memory_in_bytes"),
"elasticsearch.merges.current": ("gauge", "indices.merges.current"),
"elasticsearch.merges.current.docs": ("gauge", "indices.merges.current_docs"),
"elasticsearch.merges.current.size": ("gauge", "indices.merges.current_size_in_bytes"),
"elasticsearch.merges.total": ("gauge", "indices.merges.total"),
"elasticsearch.merges.total.time": ("gauge", "indices.merges.total_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.merges.total.docs": ("gauge", "indices.merges.total_docs"),
"elasticsearch.merges.total.size": ("gauge", "indices.merges.total_size_in_bytes"),
"elasticsearch.refresh.total": ("gauge", "indices.refresh.total"),
"elasticsearch.refresh.total.time": ("gauge", "indices.refresh.total_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.flush.total": ("gauge", "indices.flush.total"),
"elasticsearch.flush.total.time": ("gauge", "indices.flush.total_time_in_millis", lambda v: float(v)/1000),
"elasticsearch.process.open_fd": ("gauge", "process.open_file_descriptors"),
"elasticsearch.transport.rx_count": ("gauge", "transport.rx_count"),
"elasticsearch.transport.tx_count": ("gauge", "transport.tx_count"),
"elasticsearch.transport.rx_size": ("gauge", "transport.rx_size_in_bytes"),
"elasticsearch.transport.tx_size": ("gauge", "transport.tx_size_in_bytes"),
"elasticsearch.transport.server_open": ("gauge", "transport.server_open"),
"elasticsearch.thread_pool.bulk.active": ("gauge", "thread_pool.bulk.active"),
"elasticsearch.thread_pool.bulk.threads": ("gauge", "thread_pool.bulk.threads"),
"elasticsearch.thread_pool.bulk.queue": ("gauge", "thread_pool.bulk.queue"),
"elasticsearch.thread_pool.flush.active": ("gauge", "thread_pool.flush.active"),
"elasticsearch.thread_pool.flush.threads": ("gauge", "thread_pool.flush.threads"),
"elasticsearch.thread_pool.flush.queue": ("gauge", "thread_pool.flush.queue"),
"elasticsearch.thread_pool.generic.active": ("gauge", "thread_pool.generic.active"),
"elasticsearch.thread_pool.generic.threads": ("gauge", "thread_pool.generic.threads"),
"elasticsearch.thread_pool.generic.queue": ("gauge", "thread_pool.generic.queue"),
"elasticsearch.thread_pool.get.active": ("gauge", "thread_pool.get.active"),
"elasticsearch.thread_pool.get.threads": ("gauge", "thread_pool.get.threads"),
"elasticsearch.thread_pool.get.queue": ("gauge", "thread_pool.get.queue"),
"elasticsearch.thread_pool.index.active": ("gauge", "thread_pool.index.active"),
"elasticsearch.thread_pool.index.threads": ("gauge", "thread_pool.index.threads"),
"elasticsearch.thread_pool.index.queue": ("gauge", "thread_pool.index.queue"),
"elasticsearch.thread_pool.management.active": ("gauge", "thread_pool.management.active"),
"elasticsearch.thread_pool.management.threads": ("gauge", "thread_pool.management.threads"),
"elasticsearch.thread_pool.management.queue": ("gauge", "thread_pool.management.queue"),
"elasticsearch.thread_pool.merge.active": ("gauge", "thread_pool.merge.active"),
"elasticsearch.thread_pool.merge.threads": ("gauge", "thread_pool.merge.threads"),
"elasticsearch.thread_pool.merge.queue": ("gauge", "thread_pool.merge.queue"),
"elasticsearch.thread_pool.percolate.active": ("gauge", "thread_pool.percolate.active"),
"elasticsearch.thread_pool.percolate.threads": ("gauge", "thread_pool.percolate.threads"),
"elasticsearch.thread_pool.percolate.queue": ("gauge", "thread_pool.percolate.queue"),
"elasticsearch.thread_pool.refresh.active": ("gauge", "thread_pool.refresh.active"),
"elasticsearch.thread_pool.refresh.threads": ("gauge", "thread_pool.refresh.threads"),
"elasticsearch.thread_pool.refresh.queue": ("gauge", "thread_pool.refresh.queue"),
"elasticsearch.thread_pool.search.active": ("gauge", "thread_pool.search.active"),
"elasticsearch.thread_pool.search.threads": ("gauge", "thread_pool.search.threads"),
"elasticsearch.thread_pool.search.queue": ("gauge", "thread_pool.search.queue"),
"elasticsearch.thread_pool.snapshot.active": ("gauge", "thread_pool.snapshot.active"),
"elasticsearch.thread_pool.snapshot.threads": ("gauge", "thread_pool.snapshot.threads"),
"elasticsearch.thread_pool.snapshot.queue": ("gauge", "thread_pool.snapshot.queue"),
"elasticsearch.http.current_open": ("gauge", "http.current_open"),
"elasticsearch.http.total_opened": ("gauge", "http.total_opened"),
"jvm.mem.heap_committed": ("gauge", "jvm.mem.heap_committed_in_bytes"),
"jvm.mem.heap_used": ("gauge", "jvm.mem.heap_used_in_bytes"),
"jvm.mem.heap_in_use": ("gauge", "jvm.mem.heap_used_percent"),
"jvm.mem.heap_max": ("gauge", "jvm.mem.heap_max_in_bytes"),
"jvm.mem.non_heap_committed": ("gauge", "jvm.mem.non_heap_committed_in_bytes"),
"jvm.mem.non_heap_used": ("gauge", "jvm.mem.non_heap_used_in_bytes"),
"jvm.threads.count": ("gauge", "jvm.threads.count"),
"jvm.threads.peak_count": ("gauge", "jvm.threads.peak_count"),
"elasticsearch.fs.total.total_in_bytes": ("gauge", "fs.total.total_in_bytes"),
"elasticsearch.fs.total.free_in_bytes": ("gauge", "fs.total.free_in_bytes"),
"elasticsearch.fs.total.available_in_bytes": ("gauge", "fs.total.available_in_bytes"),
}
JVM_METRICS_POST_0_90_10 = {
"jvm.gc.collectors.young.count": ("gauge", "jvm.gc.collectors.young.collection_count"),
"jvm.gc.collectors.young.collection_time": ("gauge", "jvm.gc.collectors.young.collection_time_in_millis", lambda v: float(v)/1000),
"jvm.gc.collectors.old.count": ("gauge", "jvm.gc.collectors.old.collection_count"),
"jvm.gc.collectors.old.collection_time": ("gauge", "jvm.gc.collectors.old.collection_time_in_millis", lambda v: float(v)/1000)
}
JVM_METRICS_PRE_0_90_10 = {
"jvm.gc.concurrent_mark_sweep.count": ("gauge", "jvm.gc.collectors.ConcurrentMarkSweep.collection_count"),
"jvm.gc.concurrent_mark_sweep.collection_time": ("gauge", "jvm.gc.collectors.ConcurrentMarkSweep.collection_time_in_millis", lambda v: float(v)/1000),
"jvm.gc.par_new.count": ("gauge", "jvm.gc.collectors.ParNew.collection_count"),
"jvm.gc.par_new.collection_time": ("gauge", "jvm.gc.collectors.ParNew.collection_time_in_millis", lambda v: float(v)/1000),
"jvm.gc.collection_count": ("gauge", "jvm.gc.collection_count"),
"jvm.gc.collection_time": ("gauge", "jvm.gc.collection_time_in_millis", lambda v: float(v)/1000),
}
ADDITIONAL_METRICS_POST_0_90_5 = {
"elasticsearch.search.fetch.open_contexts": ("gauge", "indices.search.open_contexts"),
"elasticsearch.cache.filter.evictions": ("gauge", "indices.filter_cache.evictions"),
"elasticsearch.cache.filter.size": ("gauge", "indices.filter_cache.memory_size_in_bytes"),
"elasticsearch.id_cache.size": ("gauge", "indices.id_cache.memory_size_in_bytes"),
"elasticsearch.fielddata.size": ("gauge", "indices.fielddata.memory_size_in_bytes"),
"elasticsearch.fielddata.evictions": ("gauge", "indices.fielddata.evictions"),
}
ADDITIONAL_METRICS_PRE_0_90_5 = {
"elasticsearch.cache.field.evictions": ("gauge", "indices.cache.field_evictions"),
"elasticsearch.cache.field.size": ("gauge", "indices.cache.field_size_in_bytes"),
"elasticsearch.cache.filter.count": ("gauge", "indices.cache.filter_count"),
"elasticsearch.cache.filter.evictions": ("gauge", "indices.cache.filter_evictions"),
"elasticsearch.cache.filter.size": ("gauge", "indices.cache.filter_size_in_bytes"),
}
ADDITIONAL_METRICS_POST_1_0_0 = {
"elasticsearch.indices.translog.size_in_bytes": ("gauge", "indices.translog.size_in_bytes"),
"elasticsearch.indices.translog.operations": ("gauge", "indices.translog.operations"),
"elasticsearch.fs.total.disk_reads": ("rate", "fs.total.disk_reads"),
"elasticsearch.fs.total.disk_writes": ("rate", "fs.total.disk_writes"),
"elasticsearch.fs.total.disk_io_op": ("rate", "fs.total.disk_io_op"),
"elasticsearch.fs.total.disk_read_size_in_bytes": ("gauge", "fs.total.disk_read_size_in_bytes"),
"elasticsearch.fs.total.disk_write_size_in_bytes": ("gauge", "fs.total.disk_write_size_in_bytes"),
"elasticsearch.fs.total.disk_io_size_in_bytes": ("gauge", "fs.total.disk_io_size_in_bytes"),
}
ADDITIONAL_METRICS_POST_1_3_0 = {
"elasticsearch.indices.segments.index_writer_memory_in_bytes": ("gauge", "indices.segments.index_writer_memory_in_bytes"),
"elasticsearch.indices.segments.version_map_memory_in_bytes": ("gauge", "indices.segments.version_map_memory_in_bytes"),
}
ADDITIONAL_METRICS_POST_1_4_0 = {
"elasticsearch.indices.segments.index_writer_max_memory_in_bytes": ("gauge", "indices.segments.index_writer_max_memory_in_bytes"),
"elasticsearch.indices.segments.fixed_bit_set_memory_in_bytes": ("gauge", "indices.segments.fixed_bit_set_memory_in_bytes"),
}
CLUSTER_HEALTH_METRICS = {
"elasticsearch.number_of_nodes": ("gauge", "number_of_nodes"),
"elasticsearch.number_of_data_nodes": ("gauge", "number_of_data_nodes"),
"elasticsearch.active_primary_shards": ("gauge", "active_primary_shards"),
"elasticsearch.active_shards": ("gauge", "active_shards"),
"elasticsearch.relocating_shards": ("gauge", "relocating_shards"),
"elasticsearch.initializing_shards": ("gauge", "initializing_shards"),
"elasticsearch.unassigned_shards": ("gauge", "unassigned_shards"),
"elasticsearch.cluster_status": ("gauge", "status", lambda v: {"red": 0, "yellow": 1, "green": 2}.get(v, -1)),
}
CLUSTER_PENDING_TASKS = {
"elasticsearch.pending_tasks_total": ("gauge", "pending_task_total"),
"elasticsearch.pending_tasks_priority_high": ("gauge", "pending_tasks_priority_high"),
"elasticsearch.pending_tasks_priority_urgent": ("gauge", "pending_tasks_priority_urgent")
}
SOURCE_TYPE_NAME = 'elasticsearch'
def __init__(self, name, init_config, agentConfig, instances=None):
AgentCheck.__init__(self, name, init_config, agentConfig, instances)
# Host status needs to persist across all checks
self.cluster_status = {}
def get_instance_config(self, instance):
url = instance.get('url')
if url is None:
raise Exception("An url must be specified in the instance")
pshard_stats = _is_affirmative(instance.get('pshard_stats', False))
cluster_stats = _is_affirmative(instance.get('cluster_stats', False))
if 'is_external' in instance:
cluster_stats = _is_affirmative(instance.get('is_external', False))
pending_task_stats = _is_affirmative(instance.get('pending_task_stats', True))
# Support URLs that have a path in them from the config, for
# backwards-compatibility.
parsed = urlparse.urlparse(url)
if parsed[2] != "":
url = "%s://%s" % (parsed[0], parsed[1])
port = parsed.port
host = parsed.hostname
custom_tags = instance.get('tags', [])
service_check_tags = [
'host:%s' % host,
'port:%s' % port
]
service_check_tags.extend(custom_tags)
# Tag by URL so we can differentiate the metrics
# from multiple instances
tags = ['url:%s' % url]
tags.extend(custom_tags)
timeout = instance.get('timeout') or self.DEFAULT_TIMEOUT
config = ESInstanceConfig(
pshard_stats=pshard_stats,
cluster_stats=cluster_stats,
password=instance.get('password'),
service_check_tags=service_check_tags,
tags=tags,
timeout=timeout,
url=url,
username=instance.get('username'),
pending_task_stats=pending_task_stats
)
return config
def check(self, instance):
config = self.get_instance_config(instance)
# Check ES version for this instance and define parameters
# (URLs and metrics) accordingly
version = self._get_es_version(config)
health_url, nodes_url, stats_url, pshard_stats_url, pending_tasks_url, stats_metrics, \
pshard_stats_metrics = self._define_params(version, config.cluster_stats)
# Load clusterwise data
if config.pshard_stats:
pshard_stats_url = urlparse.urljoin(config.url, pshard_stats_url)
pshard_stats_data = self._get_data(pshard_stats_url, config)
self._process_pshard_stats_data(pshard_stats_data, config, pshard_stats_metrics)
# Load stats data.
stats_url = urlparse.urljoin(config.url, stats_url)
stats_data = self._get_data(stats_url, config)
self._process_stats_data(nodes_url, stats_data, stats_metrics, config)
# Load the health data.
health_url = urlparse.urljoin(config.url, health_url)
health_data = self._get_data(health_url, config)
self._process_health_data(health_data, config)
if config.pending_task_stats:
# Load the pending_tasks data.
pending_tasks_url = urlparse.urljoin(config.url, pending_tasks_url)
pending_tasks_data = self._get_data(pending_tasks_url, config)
self._process_pending_tasks_data(pending_tasks_data, config)
# If we're here we did not have any ES conn issues
self.service_check(
self.SERVICE_CHECK_CONNECT_NAME,
AgentCheck.OK,
tags=config.service_check_tags
)
def _get_es_version(self, config):
""" Get the running version of elasticsearch.
"""
try:
data = self._get_data(config.url, config, send_sc=False)
version = map(int, data['version']['number'].split('.')[0:3])
except Exception, e:
self.warning(
"Error while trying to get Elasticsearch version "
"from %s %s"
% (config.url, str(e))
)
version = [1, 0, 0]
self.service_metadata('version', version)
self.log.debug("Elasticsearch version is %s" % version)
return version
def _define_params(self, version, cluster_stats):
""" Define the set of URLs and METRICS to use depending on the
running ES version.
"""
pshard_stats_url = "/_stats"
if version >= [0, 90, 10]:
# ES versions 0.90.10 and above
health_url = "/_cluster/health?pretty=true"
nodes_url = "/_nodes?network=true"
pending_tasks_url = "/_cluster/pending_tasks?pretty=true"
# For "external" clusters, we want to collect from all nodes.
if cluster_stats:
stats_url = "/_nodes/stats?all=true"
else:
stats_url = "/_nodes/_local/stats?all=true"
additional_metrics = self.JVM_METRICS_POST_0_90_10
else:
health_url = "/_cluster/health?pretty=true"
nodes_url = "/_cluster/nodes?network=true"
pending_tasks_url = None
if cluster_stats:
stats_url = "/_cluster/nodes/stats?all=true"
else:
stats_url = "/_cluster/nodes/_local/stats?all=true"
additional_metrics = self.JVM_METRICS_PRE_0_90_10
stats_metrics = dict(self.STATS_METRICS)
stats_metrics.update(additional_metrics)
### Additional Stats metrics ###
if version >= [0, 90, 5]:
# ES versions 0.90.5 and above
additional_metrics = self.ADDITIONAL_METRICS_POST_0_90_5
else:
# ES version 0.90.4 and below
additional_metrics = self.ADDITIONAL_METRICS_PRE_0_90_5
stats_metrics.update(additional_metrics)
if version >= [1, 0, 0]:
stats_metrics.update(self.ADDITIONAL_METRICS_POST_1_0_0)
if version >= [1, 3, 0]:
stats_metrics.update(self.ADDITIONAL_METRICS_POST_1_3_0)
if version >= [1, 4, 0]:
# ES versions 1.4 and above
stats_metrics.update(self.ADDITIONAL_METRICS_POST_1_4_0)
# Version specific stats metrics about the primary shards
pshard_stats_metrics = dict(self.PRIMARY_SHARD_METRICS)
if version >= [1, 0, 0]:
additional_metrics = self.PRIMARY_SHARD_METRICS_POST_1_0
pshard_stats_metrics.update(additional_metrics)
return health_url, nodes_url, stats_url, pshard_stats_url, pending_tasks_url, \
stats_metrics, pshard_stats_metrics
def _get_data(self, url, config, send_sc=True):
""" Hit a given URL and return the parsed json
"""
# Load basic authentication configuration, if available.
if config.username and config.password:
auth = (config.username, config.password)
else:
auth = None
try:
resp = requests.get(
url,
timeout=config.timeout,
headers=headers(self.agentConfig),
auth=auth
)
resp.raise_for_status()
except Exception as e:
if send_sc:
self.service_check(
self.SERVICE_CHECK_CONNECT_NAME,
AgentCheck.CRITICAL,
message="Error {0} when hitting {1}".format(e, url),
tags=config.service_check_tags
)
raise
return resp.json()
def _process_pending_tasks_data(self, data, config):
p_tasks = defaultdict(int)
for task in data.get('tasks', []):
p_tasks[task.get('priority')] += 1
node_data = {
'pending_task_total': sum(p_tasks.values()),
'pending_tasks_priority_high': p_tasks['high'],
'pending_tasks_priority_urgent': p_tasks['urgent'],
}
for metric in self.CLUSTER_PENDING_TASKS:
# metric description
desc = self.CLUSTER_PENDING_TASKS[metric]
self._process_metric(node_data, metric, *desc, tags=config.tags)
def _process_stats_data(self, nodes_url, data, stats_metrics, config):
cluster_stats = config.cluster_stats
for node_name in data['nodes']:
node_data = data['nodes'][node_name]
# On newer version of ES it's "host" not "hostname"
node_hostname = node_data.get(
'hostname', node_data.get('host', None))
# Override the metric hostname if we're hitting an external cluster
metric_hostname = node_hostname if cluster_stats else None
for metric, desc in stats_metrics.iteritems():
self._process_metric(
node_data, metric, *desc, tags=config.tags,
hostname=metric_hostname)
def _process_pshard_stats_data(self, data, config, pshard_stats_metrics):
for metric, desc in pshard_stats_metrics.iteritems():
self._process_metric(data, metric, *desc, tags=config.tags)
def _process_metric(self, data, metric, xtype, path, xform=None,
tags=None, hostname=None):
"""data: dictionary containing all the stats
metric: datadog metric
path: corresponding path in data, flattened, e.g. thread_pool.bulk.queue
xfom: a lambda to apply to the numerical value
"""
value = data
# Traverse the nested dictionaries
for key in path.split('.'):
if value is not None:
value = value.get(key, None)
else:
break
if value is not None:
if xform:
value = xform(value)
if xtype == "gauge":
self.gauge(metric, value, tags=tags, hostname=hostname)
else:
self.rate(metric, value, tags=tags, hostname=hostname)
else:
self._metric_not_found(metric, path)
def _process_health_data(self, data, config):
if self.cluster_status.get(config.url) is None:
self.cluster_status[config.url] = data['status']
if data['status'] in ["yellow", "red"]:
event = self._create_event(data['status'], tags=config.tags)
self.event(event)
if data['status'] != self.cluster_status.get(config.url):
self.cluster_status[config.url] = data['status']
event = self._create_event(data['status'], tags=config.tags)
self.event(event)
for metric, desc in self.CLUSTER_HEALTH_METRICS.iteritems():
self._process_metric(data, metric, *desc, tags=config.tags)
# Process the service check
cluster_status = data['status']
if cluster_status == 'green':
status = AgentCheck.OK
data['tag'] = "OK"
elif cluster_status == 'yellow':
status = AgentCheck.WARNING
data['tag'] = "WARN"
else:
status = AgentCheck.CRITICAL
data['tag'] = "ALERT"
msg = "{tag} on cluster \"{cluster_name}\" "\
"| active_shards={active_shards} "\
"| initializing_shards={initializing_shards} "\
"| relocating_shards={relocating_shards} "\
"| unassigned_shards={unassigned_shards} "\
"| timed_out={timed_out}" \
.format(**data)
self.service_check(
self.SERVICE_CHECK_CLUSTER_STATUS,
status,
message=msg,
tags=config.service_check_tags
)
def _metric_not_found(self, metric, path):
self.log.debug("Metric not found: %s -> %s", path, metric)
def _create_event(self, status, tags=None):
hostname = self.hostname.decode('utf-8')
if status == "red":
alert_type = "error"
msg_title = "%s is %s" % (hostname, status)
elif status == "yellow":
alert_type = "warning"
msg_title = "%s is %s" % (hostname, status)
else:
# then it should be green
alert_type = "success"
msg_title = "%s recovered as %s" % (hostname, status)
msg = "ElasticSearch: %s just reported as %s" % (hostname, status)
return {
'timestamp': int(time.time()),
'event_type': 'elasticsearch',
'host': hostname,
'msg_text': msg,
'msg_title': msg_title,
'alert_type': alert_type,
'source_type_name': "elasticsearch",
'event_object': hostname,
'tags': tags
}
|
bsd-3-clause
|
[
3,
26678,
199,
504,
5055,
492,
10018,
12,
12863,
199,
646,
900,
199,
646,
7097,
199,
199,
3,
650,
80,
199,
646,
4145,
199,
199,
3,
2199,
199,
504,
5920,
492,
19866,
1799,
199,
504,
1101,
492,
485,
374,
63,
2756,
1795,
391,
857,
199,
504,
4884,
492,
2323,
421,
199,
533,
5013,
4667,
8,
1726,
304,
272,
986,
421,
199,
654,
3244,
2028,
275,
12863,
8,
272,
283,
654,
3244,
2028,
297,
359,
267,
283,
80,
10810,
63,
3200,
297,
267,
283,
4201,
63,
3200,
297,
267,
283,
2060,
297,
267,
283,
1364,
63,
1074,
63,
2969,
297,
267,
283,
2969,
297,
267,
283,
2593,
297,
267,
283,
633,
297,
267,
283,
2473,
297,
267,
283,
6455,
63,
1765,
63,
3200,
297,
272,
4794,
421,
199,
533,
10427,
1799,
8,
7788,
1799,
304,
272,
16655,
63,
8936,
63,
14657,
63,
2339,
275,
283,
25651,
14,
2425,
63,
2242,
7,
272,
16655,
63,
8936,
63,
26340,
63,
6305,
275,
283,
25651,
14,
4201,
63,
9665,
7,
339,
6186,
63,
8899,
275,
959,
339,
327,
16454,
2605,
7186,
12,
876,
26913,
641,
10427,
12,
9025,
543,
1006,
10427,
5459,
272,
19770,
63,
3234,
7816,
63,
30476,
275,
469,
267,
298,
25651,
14,
1359,
13190,
14,
4757,
14,
835,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
4757,
14,
835,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
4757,
14,
6062,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
4757,
14,
6062,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
1617,
14,
890,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
1617,
14,
890,
63,
262,
63,
2394,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
28703,
14,
1080,
14,
2923,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
28703,
14,
1080,
63,
2923,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
28703,
14,
1080,
14,
521,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
28703,
14,
1080,
63,
521,
63,
262,
63,
19579,
83,
401,
2400,
373,
26,
2069,
8,
86,
2447,
5279,
395,
267,
298,
25651,
14,
1359,
13190,
14,
28703,
14,
1080,
14,
1818,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
28703,
14,
1080,
63,
1818,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
28703,
14,
1807,
14,
2923,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
28703,
14,
1807,
63,
2923,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
28703,
14,
1807,
14,
521,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
28703,
14,
1807,
63,
521,
63,
262,
63,
19579,
83,
401,
2400,
373,
26,
2069,
8,
86,
2447,
5279,
395,
267,
298,
25651,
14,
1359,
13190,
14,
28703,
14,
1807,
14,
1818,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
28703,
14,
1807,
63,
1818,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
362,
14,
2923,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
362,
14,
2923,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
362,
14,
521,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
362,
14,
521,
63,
262,
63,
19579,
83,
401,
2400,
373,
26,
2069,
8,
86,
2447,
5279,
395,
267,
298,
25651,
14,
1359,
13190,
14,
362,
14,
1818,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
362,
14,
1818,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
362,
14,
2444,
14,
2923,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
362,
14,
2444,
63,
2923,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
362,
14,
2444,
14,
521,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
362,
14,
2444,
63,
521,
63,
262,
63,
19579,
83,
401,
2400,
373,
26,
2069,
8,
86,
2447,
5279,
395,
267,
298,
25651,
14,
1359,
13190,
14,
362,
14,
4752,
14,
2923,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
362,
14,
4752,
63,
2923,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
362,
14,
4752,
14,
521,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
362,
14,
4752,
63,
521,
63,
262,
63,
19579,
83,
401,
2400,
373,
26,
2069,
8,
86,
2447,
5279,
395,
267,
298,
25651,
14,
1359,
13190,
14,
1733,
14,
1131,
14,
2923,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
1733,
14,
1131,
63,
2923,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
1733,
14,
1131,
14,
521,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
1733,
14,
1131,
63,
521,
63,
262,
63,
19579,
83,
401,
2400,
373,
26,
2069,
8,
86,
2447,
5279,
395,
267,
298,
25651,
14,
1359,
13190,
14,
1733,
14,
1131,
14,
1818,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
1733,
14,
1131,
63,
1818,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
1733,
14,
3535,
14,
2923,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
1733,
14,
3535,
63,
2923,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
1733,
14,
3535,
14,
521,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
1733,
14,
3535,
63,
521,
63,
262,
63,
19579,
83,
401,
2400,
373,
26,
2069,
8,
86,
2447,
5279,
395,
267,
298,
25651,
14,
1359,
13190,
14,
1733,
14,
3535,
14,
1818,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
1733,
14,
3535,
63,
1818,
531,
272,
789,
339,
19770,
63,
3234,
7816,
63,
30476,
63,
4030,
63,
17,
63,
16,
275,
469,
267,
298,
25651,
14,
1359,
13190,
14,
2626,
3389,
14,
1818,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
2626,
3389,
14,
1818,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
2626,
3389,
14,
1818,
14,
4757,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
2626,
3389,
14,
1818,
63,
4757,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
2626,
3389,
14,
1818,
14,
890,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
2626,
3389,
14,
1818,
63,
890,
63,
262,
63,
2394,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
2626,
3389,
14,
2923,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
2626,
3389,
14,
2923,
1288
] |
[
26678,
199,
504,
5055,
492,
10018,
12,
12863,
199,
646,
900,
199,
646,
7097,
199,
199,
3,
650,
80,
199,
646,
4145,
199,
199,
3,
2199,
199,
504,
5920,
492,
19866,
1799,
199,
504,
1101,
492,
485,
374,
63,
2756,
1795,
391,
857,
199,
504,
4884,
492,
2323,
421,
199,
533,
5013,
4667,
8,
1726,
304,
272,
986,
421,
199,
654,
3244,
2028,
275,
12863,
8,
272,
283,
654,
3244,
2028,
297,
359,
267,
283,
80,
10810,
63,
3200,
297,
267,
283,
4201,
63,
3200,
297,
267,
283,
2060,
297,
267,
283,
1364,
63,
1074,
63,
2969,
297,
267,
283,
2969,
297,
267,
283,
2593,
297,
267,
283,
633,
297,
267,
283,
2473,
297,
267,
283,
6455,
63,
1765,
63,
3200,
297,
272,
4794,
421,
199,
533,
10427,
1799,
8,
7788,
1799,
304,
272,
16655,
63,
8936,
63,
14657,
63,
2339,
275,
283,
25651,
14,
2425,
63,
2242,
7,
272,
16655,
63,
8936,
63,
26340,
63,
6305,
275,
283,
25651,
14,
4201,
63,
9665,
7,
339,
6186,
63,
8899,
275,
959,
339,
327,
16454,
2605,
7186,
12,
876,
26913,
641,
10427,
12,
9025,
543,
1006,
10427,
5459,
272,
19770,
63,
3234,
7816,
63,
30476,
275,
469,
267,
298,
25651,
14,
1359,
13190,
14,
4757,
14,
835,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
4757,
14,
835,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
4757,
14,
6062,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
4757,
14,
6062,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
1617,
14,
890,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
1617,
14,
890,
63,
262,
63,
2394,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
28703,
14,
1080,
14,
2923,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
28703,
14,
1080,
63,
2923,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
28703,
14,
1080,
14,
521,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
28703,
14,
1080,
63,
521,
63,
262,
63,
19579,
83,
401,
2400,
373,
26,
2069,
8,
86,
2447,
5279,
395,
267,
298,
25651,
14,
1359,
13190,
14,
28703,
14,
1080,
14,
1818,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
28703,
14,
1080,
63,
1818,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
28703,
14,
1807,
14,
2923,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
28703,
14,
1807,
63,
2923,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
28703,
14,
1807,
14,
521,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
28703,
14,
1807,
63,
521,
63,
262,
63,
19579,
83,
401,
2400,
373,
26,
2069,
8,
86,
2447,
5279,
395,
267,
298,
25651,
14,
1359,
13190,
14,
28703,
14,
1807,
14,
1818,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
28703,
14,
1807,
63,
1818,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
362,
14,
2923,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
362,
14,
2923,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
362,
14,
521,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
362,
14,
521,
63,
262,
63,
19579,
83,
401,
2400,
373,
26,
2069,
8,
86,
2447,
5279,
395,
267,
298,
25651,
14,
1359,
13190,
14,
362,
14,
1818,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
362,
14,
1818,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
362,
14,
2444,
14,
2923,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
362,
14,
2444,
63,
2923,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
362,
14,
2444,
14,
521,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
362,
14,
2444,
63,
521,
63,
262,
63,
19579,
83,
401,
2400,
373,
26,
2069,
8,
86,
2447,
5279,
395,
267,
298,
25651,
14,
1359,
13190,
14,
362,
14,
4752,
14,
2923,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
362,
14,
4752,
63,
2923,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
362,
14,
4752,
14,
521,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
362,
14,
4752,
63,
521,
63,
262,
63,
19579,
83,
401,
2400,
373,
26,
2069,
8,
86,
2447,
5279,
395,
267,
298,
25651,
14,
1359,
13190,
14,
1733,
14,
1131,
14,
2923,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
1733,
14,
1131,
63,
2923,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
1733,
14,
1131,
14,
521,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
1733,
14,
1131,
63,
521,
63,
262,
63,
19579,
83,
401,
2400,
373,
26,
2069,
8,
86,
2447,
5279,
395,
267,
298,
25651,
14,
1359,
13190,
14,
1733,
14,
1131,
14,
1818,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
1733,
14,
1131,
63,
1818,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
1733,
14,
3535,
14,
2923,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
1733,
14,
3535,
63,
2923,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
1733,
14,
3535,
14,
521,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
1733,
14,
3535,
63,
521,
63,
262,
63,
19579,
83,
401,
2400,
373,
26,
2069,
8,
86,
2447,
5279,
395,
267,
298,
25651,
14,
1359,
13190,
14,
1733,
14,
3535,
14,
1818,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
1733,
14,
3535,
63,
1818,
531,
272,
789,
339,
19770,
63,
3234,
7816,
63,
30476,
63,
4030,
63,
17,
63,
16,
275,
469,
267,
298,
25651,
14,
1359,
13190,
14,
2626,
3389,
14,
1818,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
2626,
3389,
14,
1818,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
2626,
3389,
14,
1818,
14,
4757,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
2626,
3389,
14,
1818,
63,
4757,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
2626,
3389,
14,
1818,
14,
890,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
2626,
3389,
14,
1818,
63,
890,
63,
262,
63,
2394,
1288,
267,
298,
25651,
14,
1359,
13190,
14,
2626,
3389,
14,
2923,
582,
1689,
26775,
401,
2668,
452,
14,
1359,
13190,
14,
2626,
3389,
14,
2923,
1288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ezequielpereira/Time-Line
|
libs/wx/tools/Editra/src/updater.py
|
2
|
25278
|
###############################################################################
# Name: updater.py #
# Purpose: UI and services for checking update status and downloading updates #
# for Editra. #
# Author: Cody Precord <cprecord@editra.org> #
# Copyright: (c) 2008 Cody Precord <staff@editra.org> #
# License: wxWindows License #
###############################################################################
"""
Provides controls/services that are used in checking and downloading updates
for the editor if they are available. The main control exported by this module
is the L{UpdateProgress} bar it displays the progress of the network action and
provides a higher level interface into the L{UpdateService}.
@summary: Utilities and controls for updating Editra
"""
__author__ = "Cody Precord <cprecord@editra.org>"
__svnid__ = "$Id: updater.py 60249 2009-04-20 01:18:29Z CJP $"
__revision__ = "$Revision: 60249 $"
#--------------------------------------------------------------------------#
# Dependancies
import os
import sys
import stat
import re
import urllib2
import threading
import wx
import wx.lib.delayedresult as delayedresult
# Editra Libraries
import ed_glob
import ed_event
from profiler import CalcVersionValue, Profile_Get
import util
import ebmlib
#--------------------------------------------------------------------------#
# Globals
RE_VERSION = re.compile('<\s*span id\="VERSION"[^>]*>(.*?)<\s*/span\s*>')
RE_CURL = re.compile('<\s*a id\="CURRENT"\s*href=\"(.*?)\"[^>]*>.*?<\s*/a\s*>')
DL_VERSION = ed_glob.HOME_PAGE + "/version.php"
DL_REQUEST = ed_glob.HOME_PAGE + "/e_update.php?dist=%s"
DL_LIN = 'SRC' # This may need to change in future
DL_MAC = 'Macintosh'
DL_SRC = 'SRC'
DL_WIN = 'Windows'
ISBIN = hasattr(sys, 'frozen')
#_ = wx.GetTranslation
from gettext import gettext as _
#--------------------------------------------------------------------------#
class UpdateService(object):
"""Defines an updater service object for Editra"""
def __init__(self):
"""Initializes the Updater Object"""
object.__init__(self)
self._abort = False
self._progress = (0, 100)
def __GetUrlHandle(self, url):
"""Gets a file handle for the given url. The caller is responsible for
closing the handle.
@requires: network conection
@param url: url to get page from
@return: all text from the given url
"""
h_file = None
try:
if Profile_Get('USE_PROXY', default=False):
proxy_set = Profile_Get('PROXY_SETTINGS',
default=dict(uname='', url='',
port='80', passwd=''))
proxy = util.GetProxyOpener(proxy_set)
h_file = proxy.open(url)
else:
h_file = urllib2.urlopen(url)
finally:
return h_file
def Abort(self):
"""Cancel any pending or in progress actions.
@postcondition: any download actions will be aborted
"""
self._abort = True
def GetCurrFileURL(self):
"""Returns the url for the current version of the program
for the current operating system, by requesting the data from
project homepage.
@requires: active network connection
@return: url of latest available program version
"""
if wx.Platform == '__WXGTK__':
dist = DL_LIN
elif wx.Platform == '__WXMAC__' and ISBIN:
dist = DL_MAC
elif wx.Platform == '__WXMSW__' and ISBIN:
dist = DL_WIN
else:
dist = DL_SRC
url = self.GetPageText(DL_REQUEST % dist)
url = re.findall(RE_CURL, url)
if len(url):
url = url[0]
else:
url = wx.EmptyString
return url.strip()
def GetCurrFileName(self):
"""Returns the name of the file that is currently available for
download as a string.
@return: name of currently available file without url
"""
url = self.GetCurrFileURL()
return url.split(u'/')[-1]
def GetCurrentVersionStr(self):
"""Parses the project website front page for the most
recent version of the program.
@requires: network connection
@return: verision number of latest available program
"""
page = self.GetPageText(ed_glob.HOME_PAGE + "/version.php?check=True")
found = re.findall(RE_VERSION, page)
if len(found):
return found[0] # Should be the first/only match found
else:
util.Log("[updater][warn] UpdateService.GetCurrentVersionStr "
"Failed to get version info.")
return _("Unable to retrieve version info")
def GetFileSize(self, url):
"""Gets the size of a file by address
@param url: url to look up file on
@return: size of the file in bytes
"""
size = 0
try:
dl_file = self.__GetUrlHandle(url)
info = dl_file.info()
size = int(info['Content-Length'])
dl_file.close()
finally:
return size
def GetPageText(self, url):
"""Gets the text of a url
@requires: network conection
@param url: url to get page from
@return: all text from the given url
"""
text = u''
try:
h_file = self.__GetUrlHandle(url)
text = h_file.read()
h_file.close()
finally:
return text
def GetProgress(self):
"""Returns the current progress/total tuple
@return: tuple of progress data
"""
return self._progress
def GetUpdateFiles(self, dl_to=wx.GetHomeDir()):
"""Gets the requested version of the program from the website
if possible. It will download the current files for the host system to
location (dl_to). On success it returns True, otherwise it returns
false.
@keyword dl_to: where to download the file to
"""
# Check version to see if update is needed
# Dont allow update if files are current
verpat = re.compile('[0-9]+\.[0-9]+\.[0-9]+')
current = self.GetCurrentVersionStr()
if not re.match(verpat, current):
return False
if CalcVersionValue(ed_glob.VERSION) < CalcVersionValue(current):
dl_path = self.GetCurrFileURL()
dl_file = dl_path.split('/')[-1]
dl_to = ebmlib.GetUniqueName(dl_to, dl_file)
blk_sz = 4096
read = 0
try:
# Download the file in chunks so it can be aborted if need be
# inbetween reads.
webfile = self.__GetUrlHandle(dl_path)
fsize = int(webfile.info()['Content-Length'])
locfile = open(dl_to, 'wb')
while read < fsize and not self._abort:
locfile.write(webfile.read(blk_sz))
read += blk_sz
self.UpdaterHook(int(read/blk_sz), blk_sz, fsize)
locfile.close()
webfile.close()
finally:
self._abort = False
if os.path.exists(dl_to) and \
os.stat(dl_to)[stat.ST_SIZE] == fsize:
return True
else:
return False
else:
return False
def UpdaterHook(self, count, block_sz, total_sz):
"""Updates the progress tuple of (amount_done, total) on
each iterative call during the download.
@param count: number of blocks fetched
@param block_sz: size of download blocks
@param total_sz: total size of file to be downloaded
"""
done = count * block_sz
if done > total_sz:
done = total_sz
self._progress = (done, total_sz)
#-----------------------------------------------------------------------------#
class UpdateThread(threading.Thread):
"""Thread for checking for updates"""
def __init__(self, parent, jobId):
"""Create the thread object
@param parent: parent window to post event to after completion
@param jobId: job identification id will be set as event id on finish
"""
threading.Thread.__init__(self)
# Attributes
self.parent = parent
self.id = jobId
def run(self):
"""Run the update check job"""
service = UpdateService()
result = service.GetCurrentVersionStr()
if result.replace('.', '').isdigit():
isupdate = CalcVersionValue(result) > CalcVersionValue(ed_glob.VERSION)
else:
isupdate = False
evt = ed_event.NotificationEvent(ed_event.edEVT_NOTIFY,
self.id, (isupdate, result))
wx.CallAfter(wx.PostEvent, self.parent, evt)
#-----------------------------------------------------------------------------#
class UpdateProgress(wx.Gauge, UpdateService):
"""Creates a progress bar that is controlled by the UpdateService"""
ID_CHECKING = wx.NewId()
ID_DOWNLOADING = wx.NewId()
ID_TIMER = wx.NewId()
def __init__(self, parent, id_, range_=100,
style=wx.GA_HORIZONTAL | wx.GA_PROGRESSBAR):
"""Initiliazes the bar in a disabled state."""
wx.Gauge.__init__(self, parent, id_, range_, style=style)
UpdateService.__init__(self)
#---- Attributes ----#
self.LOG = wx.GetApp().GetLog()
self._checking = False
self._downloading = False
self._dl_result = False
self._mode = 0
self._status = _("Status Unknown")
self._timer = wx.Timer(self, id=self.ID_TIMER)
#---- Layout ----#
if wx.Platform == '__WXMAC__':
self.SetWindowVariant(wx.WINDOW_VARIANT_LARGE)
#---- Bind Events ----#
self.Bind(wx.EVT_TIMER, self.OnUpdate, id = self.ID_TIMER)
# Disable bar till caller is ready to use it
self.Disable()
def __del__(self):
"""Cleans up when the control is destroyed
@postcondition: if timer is running it is stopped before deletion
"""
if self._timer.IsRunning():
self.LOG("[updater][info]UpdateProgress: __del__, stopped timer")
self._timer.Stop()
def Abort(self):
"""Overides the UpdateService abort function
@postcondition: any download actions in the L{UpdateService} are aborted
"""
self.LOG("[updater][info] UpdateProgress: Download aborted")
UpdateService.Abort(self)
if self._timer.IsRunning():
self._timer.Stop()
def CheckForUpdates(self):
"""Checks for updates and activates the bar. In order to keep the
UI from freezing while checking for updates the actual work is carried
out on another thread. When the thread exits it will set the _checking
attribute to false and set the _status attribute (See GetStatus) to the
return value of the check function which is either a version string or
an appropriate error message.
@see: L{_UpdatesCheckThread}
"""
# Set bar to Checking mode so it knows to simulate update progress
self._mode = self.ID_CHECKING
self.SetValue(0)
self.Start(10)
self._checking = True
delayedresult.startWorker(self._ResultNotifier,
self._UpdatesCheckThread,
jobID=self.ID_CHECKING)
def DownloadUpdates(self, dl_loc=wx.EmptyString):
"""Downloads available updates and configures the bar.
Returns True if the update was successfull or False if
it was not. The updates will be downloaded to the
specified location or to the Users Desktop or Home
Folder if no location is specified.
@keyword dl_loc: location to download file to
"""
self.LOG("[updater][info] UpdateProgress: Download Starting...")
if dl_loc == wx.EmptyString:
dl_loc = self.GetDownloadLocation()
self._mode = self.ID_DOWNLOADING
self.SetValue(0)
self.Start(50) #XXX Try this for starters
self._downloading = True # Mark the work status as busy
delayedresult.startWorker(self._ResultNotifier, self._DownloadThread,
wargs=dl_loc, jobID=self.ID_DOWNLOADING)
def GetDownloadResult(self):
"""Returns the status of the last download action. Either
True for success or False for failure.
@return: whether last download was successfull or not
"""
return self._dl_result
def GetDownloadLocation(self):
"""Returns the path that the file will be downloaded to.
Currently will either return the users Desktop path or the
users home directory in the case that there is no deskop directory
@return: path to download file
"""
dl_loc = wx.GetHomeDir() + os.sep
if os.path.exists(dl_loc + u"Desktop"):
dl_loc = dl_loc + u"Desktop" + os.sep
return dl_loc
def GetMode(self):
"""Returns the current mode of operation or 0 if the bar
is currently inactive.
@return: mode of operation for the progres bar
"""
return self._mode
def GetStatus(self):
"""Returns the status attribute string
@return: status set by any update actions
"""
return self._status
def GetUpdatesAvailable(self):
"""Compares the status against the version of the running
program to see if updates are available. It is expected
that CheckForUpdates has been called prior to calling this
function. Returns True if Available and False otherwise.
@return: whether udpates are available or not
"""
if self._status[0].isdigit():
return CalcVersionValue(self._status) > CalcVersionValue(ed_glob.VERSION)
else:
return False
def IsDownloading(self):
"""Returns a bool stating whether there is a download
in progress or not.
@return: whether downloading is active or not
"""
return self._downloading
def OnUpdate(self, evt):
"""Timer Event Handler Updates the progress bar
on each cycle of the timer
@param evt: event that called this handler
"""
mode = self.GetMode()
progress = self.GetProgress()
prange = self.GetRange()
if mode == self.ID_CHECKING:
# Simulate updates
if progress[0] < prange:
self.UpdaterHook(progress[0] + 1, 1, 90)
progress = self.GetProgress()
if not self._checking and progress[0] >= prange:
self.Stop()
if mode == self.ID_DOWNLOADING:
if not self._downloading and progress[0] >= prange:
self.Stop()
# Update Range if need be
if prange != progress[1]:
self.SetRange(progress[1])
# Update Progress
if progress[0] < progress[1]:
self.SetValue(progress[0])
elif progress[0] == progress[1]:
self.Pulse()
else:
pass
def Start(self, msec=100):
"""Starts the progress bar and timer if not already active
@keyword msec: pulse time for clock in milliseconds
"""
if not self._timer.IsRunning():
self.LOG('[updater][info] UpdateProgress: Starting Timer')
self.Enable()
self._timer.Start(msec)
else:
pass
def Stop(self):
"""Stops the progress bar
@postcondition: progress bar is stopped
"""
if self._timer.IsRunning():
self.LOG('[updater][info] UpdateProgress: Stopping Clock')
self._timer.Stop()
self._mode = 0
else:
pass
self.SetValue(0)
self.Disable()
#--- Protected Member Functions ---#
def _DownloadThread(self, *args):
"""Processes the download and checks that the file has been downloaded
properly. Then returns either True if the download was succesfull or
False if it failed in some way.
@return: success status of download
"""
dl_ok = self.GetUpdateFiles("".join(args))
return dl_ok
def _ResultNotifier(self, delayedResult):
"""Recieves the return from the result of the worker thread and
notifies the interested party with the result.
@param delayedResult: value from worker thread
"""
jid = delayedResult.getJobID()
try:
self.LOG("[updater][info] UpdateProgress: Worker thread exited. ID = %d" % jid)
self._checking = self._downloading = False # Work has finished
except wx.PyDeadObjectError:
return
try:
if jid == self.ID_CHECKING:
mevt = ed_event.UpdateTextEvent(ed_event.edEVT_UPDATE_TEXT, \
self.ID_CHECKING)
wx.PostEvent(self.GetParent(), mevt)
elif jid == self.ID_DOWNLOADING:
result = delayedResult.get()
self._dl_result = result
else:
pass
except (OSError, IOError, UnicodeDecodeError), msg:
self.LOG("[updater][err] UpdateProgress: Error on thread exit")
self.LOG("[updater][err] UpdateProgress: error = %s" % str(msg))
def _UpdatesCheckThread(self):
"""Sets internal status value to the return value from calling
GetCurrentVersionStr. This function is called on a separate thread
in the CheckForUpdates function to allow the ui to update properly
while this function waits for the result from the network. Returns
True to the consumer if updates are available and false if they
are not or status is unknown.
@return: whether updates are available or not
"""
self.LOG("[updater][info] UpdateProgress: Checking for updates")
self._checking = True
ret = self.GetCurrentVersionStr()
self._status = ret
self.LOG("[updater][info] UpdateProgress: Check Finished: result = " + ret)
if ret[0].isdigit() and \
CalcVersionValue(ret) > CalcVersionValue(ed_glob.VERSION):
ret = True
else:
ret = False
return ret
#-----------------------------------------------------------------------------#
class DownloadDialog(wx.Frame):
"""Creates a standalone download window
@todo: Status bar is sometimes not wide enough to display all data.
"""
ID_PROGRESS_BAR = wx.NewId()
ID_TIMER = wx.NewId()
SB_DOWNLOADED = 0
SB_INFO = 1
def __init__(self, parent, id_, title,
style=wx.DEFAULT_DIALOG_STYLE | wx.MINIMIZE_BOX):
"""Creates a standalone window that is used for downloading
updates for the editor.
@param parent: Parent Window of the dialog
@param title: Title of dialog
"""
wx.Frame.__init__(self, parent, id_, title, style=style)
util.SetWindowIcon(self)
#---- Attributes/Objects ----#
self.LOG = wx.GetApp().GetLog()
panel = wx.Panel(self)
self._progress = UpdateProgress(panel, self.ID_PROGRESS_BAR)
fname = self._progress.GetCurrFileName()
floc = self._progress.GetDownloadLocation()
dl_file = wx.StaticText(panel, label=_("Downloading: %s") % fname)
dl_loc = wx.StaticText(panel, wx.ID_ANY,
_("Downloading To: %s") % floc)
self._cancel_bt = wx.Button(panel, wx.ID_CANCEL, _("Cancel"))
self._timer = wx.Timer(self, id=self.ID_TIMER)
self._proghist = list()
#---- Layout ----#
self.CreateStatusBar(2)
self._sizer = wx.GridBagSizer()
bmp = wx.ArtProvider.GetBitmap(str(ed_glob.ID_WEB), wx.ART_TOOLBAR)
mdc = wx.MemoryDC(bmp)
tmp_bmp = wx.Image(ed_glob.CONFIG['SYSPIX_DIR'] + u"editra.png",
wx.BITMAP_TYPE_PNG)
tmp_bmp.Rescale(20, 20, wx.IMAGE_QUALITY_HIGH)
mdc.DrawBitmap(tmp_bmp.ConvertToBitmap(), 11, 11)
mdc.SelectObject(wx.NullBitmap)
bmp = wx.StaticBitmap(panel, wx.ID_ANY, bmp)
self._sizer.AddMany([(bmp, (1, 1), (3, 2)),
(dl_file, (1, 4), (1, 4)),
(dl_loc, (2, 4), (1, 4)),
((15, 15), (3, 5), (1, 1))])
self._sizer.Add(self._progress, (4, 1), (1, 10), wx.EXPAND)
bsizer = wx.BoxSizer(wx.HORIZONTAL)
bsizer.AddStretchSpacer()
bsizer.Add(self._cancel_bt, 0, wx.ALIGN_CENTER_HORIZONTAL)
bsizer.AddStretchSpacer()
self._sizer.Add(bsizer, (6, 1), (1, 10), wx.EXPAND)
self._sizer.Add((5, 5), (7, 1))
self._sizer.Add((5, 5), (7, 11))
panel.SetSizer(self._sizer)
mwsz = wx.BoxSizer(wx.HORIZONTAL)
mwsz.Add(panel, 1, wx.EXPAND)
self.SetSizer(mwsz)
self.SetInitialSize()
self.SetStatusWidths([-1, 100])
self.SetStatusText(_("Downloading") + u"...", self.SB_INFO)
#---- Bind Events ----#
self.Bind(wx.EVT_BUTTON, self.OnButton)
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.Bind(wx.EVT_TIMER, self.OnUpdate, id=self.ID_TIMER)
def __del__(self):
"""Cleans up on exit
@postcondition: if timer was running it is stopped
"""
if self._timer.IsRunning():
self.LOG('[updater][info] DownloadDialog: __del__ Timer Stopped')
self._timer.Stop()
def CalcDownRate(self):
"""Calculates and returns the approximate download rate
in Kb/s
@return: current downlaod rate in Kb/s
@rtype: float
"""
dlist = list()
last = 0
for item in self._proghist:
val = item - last
dlist.append(val)
last = item
return round((float(sum(dlist) / len(self._proghist)) / 1024), 2)
def OnButton(self, evt):
"""Handles events that are generated when buttons are pushed.
@param evt: event that called this handler
"""
e_id = evt.GetId()
if e_id == wx.ID_CANCEL:
self.LOG("[updater][evt] DownloadDialog: Cancel pressed")
self._progress.Abort()
self._cancel_bt.Disable()
self.SetStatusText(_("Canceled"), self.SB_INFO)
else:
evt.Skip()
def OnClose(self, evt):
"""Handles the window closer event
@param evt: event that called this handler
"""
self.LOG("[updater][evt] DownloadDialog: Closing Download Dialog")
self._progress.Abort()
# Wait till thread has halted before exiting
while self._progress.IsDownloading():
wx.YieldIfNeeded()
wx.GetApp().UnRegisterWindow(repr(self))
evt.Skip()
def OnUpdate(self, evt):
"""Updates the status text on each pulse from the timer
@param evt: event that called this handler
"""
e_id = evt.GetId()
if e_id == self.ID_TIMER:
prog = self._progress.GetProgress()
self._proghist.append(prog[0])
speed = self.CalcDownRate()
if self._progress.IsDownloading():
self.SetStatusText(_("Rate: %.2f Kb/s") % speed,
self.SB_DOWNLOADED)
else:
self.LOG("[updater][evt] DownloadDialog:: Download finished")
self.SetStatusText(u'', self.SB_DOWNLOADED)
if self._progress.GetDownloadResult():
self.LOG("[updater][info] DownloadDialog: Download Successful")
self.SetStatusText(_("Finished"), self.SB_INFO)
else:
self.LOG("[updater][info] DownloadDialog: Download Failed")
self.SetStatusText(_("Failed"), self.SB_INFO)
self._progress.Enable()
self._progress.SetValue(self._progress.GetProgress()[0])
self._timer.Stop()
self._cancel_bt.Disable()
else:
evt.Skip()
def Show(self):
"""Shows the Dialog and starts downloading the updates
@postcondition: window is registered with mainloop and shown on screen
@todo: Allow setting of download location to be set when shown
"""
# Tell the main loop we are busy
wx.GetApp().RegisterWindow(repr(self), self, True)
self._timer.Start(1000) # One pulse every second
self._progress.DownloadUpdates()
wx.Frame.Show(self)
|
gpl-3.0
|
[
11490,
199,
3,
2812,
26,
1678,
82,
14,
647,
2476,
14960,
327,
199,
3,
23177,
4070,
26,
14041,
436,
8500,
367,
7907,
1678,
2004,
436,
25937,
7029,
327,
199,
3,
3515,
367,
662,
328,
1239,
14,
2476,
12788,
327,
199,
3,
6529,
26,
445,
1351,
510,
3059,
665,
67,
657,
1577,
32,
6297,
1239,
14,
1308,
30,
22456,
327,
199,
3,
1898,
26,
334,
67,
9,
9079,
445,
1351,
510,
3059,
665,
7018,
32,
6297,
1239,
14,
1308,
30,
12793,
327,
199,
3,
844,
26,
4818,
8647,
844,
2476,
8295,
327,
199,
11490,
199,
199,
624,
199,
17473,
13467,
15,
5950,
626,
787,
1202,
315,
7907,
436,
25937,
7029,
199,
509,
314,
8823,
340,
2985,
787,
2808,
14,
710,
2446,
3304,
16629,
701,
642,
859,
199,
374,
314,
491,
91,
4152,
11504,
93,
4681,
652,
17561,
314,
6696,
402,
314,
2784,
1595,
436,
199,
20121,
282,
10948,
2166,
3217,
1901,
314,
491,
91,
4152,
3167,
5565,
199,
199,
32,
4705,
26,
738,
17933,
436,
13467,
367,
12928,
662,
328,
1239,
199,
199,
624,
199,
199,
363,
2502,
363,
275,
298,
35,
1351,
510,
3059,
665,
67,
657,
1577,
32,
6297,
1239,
14,
1308,
4335,
199,
363,
6836,
344,
363,
275,
7880,
1304,
26,
1678,
82,
14,
647,
1227,
996,
1887,
8937,
13,
966,
13,
1165,
17163,
26,
1085,
26,
1398,
58,
445,
15819,
2672,
2,
199,
363,
5792,
363,
275,
7880,
12714,
26,
1227,
996,
1887,
2672,
2,
199,
199,
7656,
9460,
3,
199,
3,
1487,
6643,
290,
2578,
199,
646,
747,
199,
646,
984,
199,
646,
5672,
199,
646,
295,
199,
646,
4011,
18,
199,
646,
5796,
199,
646,
4818,
199,
646,
4818,
14,
773,
14,
21830,
1099,
465,
24725,
1099,
199,
199,
3,
662,
328,
1239,
31454,
199,
646,
3988,
63,
6463,
199,
646,
3988,
63,
1430,
199,
504,
23173,
492,
8256,
67,
3353,
1110,
12,
14386,
63,
1002,
199,
646,
4884,
199,
646,
325,
12648,
773,
199,
199,
7656,
9460,
3,
199,
3,
13641,
83,
199,
907,
63,
4612,
275,
295,
14,
2014,
4827,
60,
83,
10,
3751,
1305,
60,
628,
4612,
2,
28959,
13661,
6697,
21528,
60,
83,
15870,
3751,
60,
83,
10,
5971,
199,
907,
63,
35,
2632,
275,
295,
14,
2014,
4827,
60,
83,
10,
65,
1305,
60,
628,
14211,
3212,
83,
10,
6399,
8178,
17140,
2862,
2,
28959,
27124,
31873,
83,
15870,
65,
60,
83,
10,
5971,
199,
8045,
63,
4612,
275,
3988,
63,
6463,
14,
9524,
63,
12898,
435,
3286,
1023,
14,
8624,
2,
199,
8045,
63,
6780,
275,
3988,
63,
6463,
14,
9524,
63,
12898,
435,
3286,
69,
63,
873,
14,
8624,
31,
2686,
2458,
83,
2,
199,
8045,
63,
6143,
275,
283,
12447,
7,
3515,
327,
961,
1443,
1929,
370,
1570,
315,
6466,
199,
8045,
63,
9410,
275,
283,
3399,
9924,
609,
7,
199,
8045,
63,
12447,
275,
283,
12447,
7,
199,
8045,
63,
7941,
275,
283,
8647,
7,
199,
1311,
9431,
275,
2688,
8,
1274,
12,
283,
11202,
358,
199,
199,
20930,
275,
4818,
14,
1002,
18483,
199,
199,
504,
9796,
492,
9796,
465,
485,
199,
199,
7656,
9460,
3,
199,
199,
533,
6162,
3167,
8,
785,
304,
272,
408,
23891,
376,
1678,
82,
2435,
909,
367,
662,
328,
1239,
624,
272,
347,
636,
826,
721,
277,
304,
267,
408,
23489,
314,
6162,
82,
6935,
624,
267,
909,
855,
826,
721,
277,
9,
267,
291,
423,
13845,
275,
756,
267,
291,
423,
5734,
275,
334,
16,
12,
2948,
9,
339,
347,
636,
1002,
6417,
5940,
8,
277,
12,
1166,
304,
267,
408,
14426,
282,
570,
2429,
367,
314,
1627,
1166,
14,
710,
8025,
365,
17845,
367,
267,
11261,
314,
2429,
14,
267,
768,
6537,
26,
2784,
286,
368,
414,
267,
768,
635,
1166,
26,
1166,
370,
664,
2034,
687,
267,
768,
1107,
26,
1006,
1318,
687,
314,
1627,
1166,
398,
408,
267,
394,
63,
493,
275,
488,
267,
862,
26,
288,
340,
14386,
63,
1002,
360,
4701,
63,
20026,
297,
849,
29,
797,
304,
355,
4566,
63,
409,
275,
14386,
63,
1002,
360,
20026,
63,
13931,
297,
3147,
849,
29,
807,
8,
16040,
4581,
1166,
4581,
9349,
1844,
534,
1257,
297,
15081,
534,
1333,
2234,
4566,
275,
4884,
14,
1002,
4936,
29993,
8,
3280,
63,
409,
9,
355,
394,
63,
493,
275,
4566,
14,
1490,
8,
633,
9,
288,
587,
26,
355,
394,
63,
493,
275,
4011,
18,
14,
10890,
8,
633,
9,
398,
3753,
26,
288,
372,
394,
63,
493,
339,
347,
31455,
8,
277,
304,
267,
408,
9083,
1263,
9413,
503,
315,
6696,
5445,
14,
267,
768,
1932,
5394,
26,
1263,
5235,
5445,
911,
506,
26815,
398,
408,
267,
291,
423,
13845,
275,
715,
339,
347,
2372,
3864,
82,
1173,
2632,
8,
277,
304,
267,
408,
3407,
314,
1166,
367,
314,
1453,
1015,
402,
314,
2240,
267,
367,
314,
1453,
17406,
2656,
12,
701,
23502,
314,
666,
687,
267,
2199,
26586,
14,
267,
768,
6537,
26,
4702,
2784,
1950,
267,
768,
1107,
26,
1166,
402,
8839,
2808,
2240,
1015,
398,
408,
267,
340,
4818,
14,
10397,
508,
2560,
16783,
8391,
43,
3706,
288,
2917,
275,
577,
44,
63,
6143,
267,
916,
4818,
14,
10397,
508,
2560,
16783,
9410,
12217,
436,
2281,
9431,
26,
288,
2917,
275,
577,
44,
63,
9410,
267,
916,
4818,
14,
10397,
508,
2560,
16783,
3053,
55,
12217,
436,
2281,
9431,
26,
288,
2917,
275,
577,
44,
63,
7941,
267,
587,
26,
288,
2917,
275,
577,
44,
63,
12447,
398,
1166,
275,
291,
14,
1002,
3276,
1872,
8,
8045,
63,
6780,
450,
2917,
9,
267,
1166,
275,
295,
14,
6452,
8,
907,
63,
35,
2632,
12,
1166,
9,
267,
340,
822,
8,
633,
304,
288,
1166,
275,
1166,
59,
16,
61,
267,
587,
26,
288,
1166,
275,
4818,
14,
4699,
1558,
398,
372,
1166,
14,
1913,
342,
339,
347,
2372,
3864,
82,
7733,
8,
277,
304,
267,
408,
3407,
314,
536,
402,
314,
570,
626,
365,
5544,
2808,
367,
267,
5235,
465,
282,
1059,
14,
267,
768,
1107,
26,
536,
402,
5544,
2808,
570,
1928,
1166,
398,
408,
267,
1166,
275,
291,
14,
1002,
3864,
82,
1173,
2632,
342,
267,
372,
1166,
14,
1294,
8,
85,
7,
6217,
1988,
17,
61,
339,
347,
2372,
5639,
3353,
2848,
8
] |
[
199,
3,
2812,
26,
1678,
82,
14,
647,
2476,
14960,
327,
199,
3,
23177,
4070,
26,
14041,
436,
8500,
367,
7907,
1678,
2004,
436,
25937,
7029,
327,
199,
3,
3515,
367,
662,
328,
1239,
14,
2476,
12788,
327,
199,
3,
6529,
26,
445,
1351,
510,
3059,
665,
67,
657,
1577,
32,
6297,
1239,
14,
1308,
30,
22456,
327,
199,
3,
1898,
26,
334,
67,
9,
9079,
445,
1351,
510,
3059,
665,
7018,
32,
6297,
1239,
14,
1308,
30,
12793,
327,
199,
3,
844,
26,
4818,
8647,
844,
2476,
8295,
327,
199,
11490,
199,
199,
624,
199,
17473,
13467,
15,
5950,
626,
787,
1202,
315,
7907,
436,
25937,
7029,
199,
509,
314,
8823,
340,
2985,
787,
2808,
14,
710,
2446,
3304,
16629,
701,
642,
859,
199,
374,
314,
491,
91,
4152,
11504,
93,
4681,
652,
17561,
314,
6696,
402,
314,
2784,
1595,
436,
199,
20121,
282,
10948,
2166,
3217,
1901,
314,
491,
91,
4152,
3167,
5565,
199,
199,
32,
4705,
26,
738,
17933,
436,
13467,
367,
12928,
662,
328,
1239,
199,
199,
624,
199,
199,
363,
2502,
363,
275,
298,
35,
1351,
510,
3059,
665,
67,
657,
1577,
32,
6297,
1239,
14,
1308,
4335,
199,
363,
6836,
344,
363,
275,
7880,
1304,
26,
1678,
82,
14,
647,
1227,
996,
1887,
8937,
13,
966,
13,
1165,
17163,
26,
1085,
26,
1398,
58,
445,
15819,
2672,
2,
199,
363,
5792,
363,
275,
7880,
12714,
26,
1227,
996,
1887,
2672,
2,
199,
199,
7656,
9460,
3,
199,
3,
1487,
6643,
290,
2578,
199,
646,
747,
199,
646,
984,
199,
646,
5672,
199,
646,
295,
199,
646,
4011,
18,
199,
646,
5796,
199,
646,
4818,
199,
646,
4818,
14,
773,
14,
21830,
1099,
465,
24725,
1099,
199,
199,
3,
662,
328,
1239,
31454,
199,
646,
3988,
63,
6463,
199,
646,
3988,
63,
1430,
199,
504,
23173,
492,
8256,
67,
3353,
1110,
12,
14386,
63,
1002,
199,
646,
4884,
199,
646,
325,
12648,
773,
199,
199,
7656,
9460,
3,
199,
3,
13641,
83,
199,
907,
63,
4612,
275,
295,
14,
2014,
4827,
60,
83,
10,
3751,
1305,
60,
628,
4612,
2,
28959,
13661,
6697,
21528,
60,
83,
15870,
3751,
60,
83,
10,
5971,
199,
907,
63,
35,
2632,
275,
295,
14,
2014,
4827,
60,
83,
10,
65,
1305,
60,
628,
14211,
3212,
83,
10,
6399,
8178,
17140,
2862,
2,
28959,
27124,
31873,
83,
15870,
65,
60,
83,
10,
5971,
199,
8045,
63,
4612,
275,
3988,
63,
6463,
14,
9524,
63,
12898,
435,
3286,
1023,
14,
8624,
2,
199,
8045,
63,
6780,
275,
3988,
63,
6463,
14,
9524,
63,
12898,
435,
3286,
69,
63,
873,
14,
8624,
31,
2686,
2458,
83,
2,
199,
8045,
63,
6143,
275,
283,
12447,
7,
3515,
327,
961,
1443,
1929,
370,
1570,
315,
6466,
199,
8045,
63,
9410,
275,
283,
3399,
9924,
609,
7,
199,
8045,
63,
12447,
275,
283,
12447,
7,
199,
8045,
63,
7941,
275,
283,
8647,
7,
199,
1311,
9431,
275,
2688,
8,
1274,
12,
283,
11202,
358,
199,
199,
20930,
275,
4818,
14,
1002,
18483,
199,
199,
504,
9796,
492,
9796,
465,
485,
199,
199,
7656,
9460,
3,
199,
199,
533,
6162,
3167,
8,
785,
304,
272,
408,
23891,
376,
1678,
82,
2435,
909,
367,
662,
328,
1239,
624,
272,
347,
636,
826,
721,
277,
304,
267,
408,
23489,
314,
6162,
82,
6935,
624,
267,
909,
855,
826,
721,
277,
9,
267,
291,
423,
13845,
275,
756,
267,
291,
423,
5734,
275,
334,
16,
12,
2948,
9,
339,
347,
636,
1002,
6417,
5940,
8,
277,
12,
1166,
304,
267,
408,
14426,
282,
570,
2429,
367,
314,
1627,
1166,
14,
710,
8025,
365,
17845,
367,
267,
11261,
314,
2429,
14,
267,
768,
6537,
26,
2784,
286,
368,
414,
267,
768,
635,
1166,
26,
1166,
370,
664,
2034,
687,
267,
768,
1107,
26,
1006,
1318,
687,
314,
1627,
1166,
398,
408,
267,
394,
63,
493,
275,
488,
267,
862,
26,
288,
340,
14386,
63,
1002,
360,
4701,
63,
20026,
297,
849,
29,
797,
304,
355,
4566,
63,
409,
275,
14386,
63,
1002,
360,
20026,
63,
13931,
297,
3147,
849,
29,
807,
8,
16040,
4581,
1166,
4581,
9349,
1844,
534,
1257,
297,
15081,
534,
1333,
2234,
4566,
275,
4884,
14,
1002,
4936,
29993,
8,
3280,
63,
409,
9,
355,
394,
63,
493,
275,
4566,
14,
1490,
8,
633,
9,
288,
587,
26,
355,
394,
63,
493,
275,
4011,
18,
14,
10890,
8,
633,
9,
398,
3753,
26,
288,
372,
394,
63,
493,
339,
347,
31455,
8,
277,
304,
267,
408,
9083,
1263,
9413,
503,
315,
6696,
5445,
14,
267,
768,
1932,
5394,
26,
1263,
5235,
5445,
911,
506,
26815,
398,
408,
267,
291,
423,
13845,
275,
715,
339,
347,
2372,
3864,
82,
1173,
2632,
8,
277,
304,
267,
408,
3407,
314,
1166,
367,
314,
1453,
1015,
402,
314,
2240,
267,
367,
314,
1453,
17406,
2656,
12,
701,
23502,
314,
666,
687,
267,
2199,
26586,
14,
267,
768,
6537,
26,
4702,
2784,
1950,
267,
768,
1107,
26,
1166,
402,
8839,
2808,
2240,
1015,
398,
408,
267,
340,
4818,
14,
10397,
508,
2560,
16783,
8391,
43,
3706,
288,
2917,
275,
577,
44,
63,
6143,
267,
916,
4818,
14,
10397,
508,
2560,
16783,
9410,
12217,
436,
2281,
9431,
26,
288,
2917,
275,
577,
44,
63,
9410,
267,
916,
4818,
14,
10397,
508,
2560,
16783,
3053,
55,
12217,
436,
2281,
9431,
26,
288,
2917,
275,
577,
44,
63,
7941,
267,
587,
26,
288,
2917,
275,
577,
44,
63,
12447,
398,
1166,
275,
291,
14,
1002,
3276,
1872,
8,
8045,
63,
6780,
450,
2917,
9,
267,
1166,
275,
295,
14,
6452,
8,
907,
63,
35,
2632,
12,
1166,
9,
267,
340,
822,
8,
633,
304,
288,
1166,
275,
1166,
59,
16,
61,
267,
587,
26,
288,
1166,
275,
4818,
14,
4699,
1558,
398,
372,
1166,
14,
1913,
342,
339,
347,
2372,
3864,
82,
7733,
8,
277,
304,
267,
408,
3407,
314,
536,
402,
314,
570,
626,
365,
5544,
2808,
367,
267,
5235,
465,
282,
1059,
14,
267,
768,
1107,
26,
536,
402,
5544,
2808,
570,
1928,
1166,
398,
408,
267,
1166,
275,
291,
14,
1002,
3864,
82,
1173,
2632,
342,
267,
372,
1166,
14,
1294,
8,
85,
7,
6217,
1988,
17,
61,
339,
347,
2372,
5639,
3353,
2848,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
thomaskeck/root
|
interpreter/llvm/src/tools/clang/tools/scan-build-py/tests/unit/test_clang.py
|
22
|
1387
|
# -*- coding: utf-8 -*-
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
import libear
import libscanbuild.clang as sut
import unittest
import os.path
class GetClangArgumentsTest(unittest.TestCase):
def test_get_clang_arguments(self):
with libear.TemporaryDirectory() as tmpdir:
filename = os.path.join(tmpdir, 'test.c')
with open(filename, 'w') as handle:
handle.write('')
result = sut.get_arguments(
['clang', '-c', filename, '-DNDEBUG', '-Dvar="this is it"'],
tmpdir)
self.assertTrue('NDEBUG' in result)
self.assertTrue('var="this is it"' in result)
def test_get_clang_arguments_fails(self):
self.assertRaises(
Exception, sut.get_arguments,
['clang', '-###', '-fsyntax-only', '-x', 'c', 'notexist.c'], '.')
class GetCheckersTest(unittest.TestCase):
def test_get_checkers(self):
# this test is only to see is not crashing
result = sut.get_checkers('clang', [])
self.assertTrue(len(result))
def test_get_active_checkers(self):
# this test is only to see is not crashing
result = sut.get_active_checkers('clang', [])
self.assertTrue(len(result))
|
lgpl-2.1
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
9326,
710,
491,
28631,
27154,
1010,
21844,
6976,
199,
3,
199,
3,
961,
570,
365,
1854,
1334,
314,
15904,
402,
473,
76,
472,
79,
374,
3232,
5800,
199,
3,
844,
14,
1666,
5113,
14,
17715,
367,
2436,
14,
199,
199,
646,
1973,
2210,
199,
646,
1973,
6282,
1506,
14,
16066,
465,
308,
337,
199,
646,
2882,
199,
646,
747,
14,
515,
421,
199,
533,
2372,
1968,
621,
14517,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
362,
63,
16066,
63,
4958,
8,
277,
304,
267,
543,
1973,
2210,
14,
11360,
6231,
342,
465,
12885,
26,
288,
1788,
275,
747,
14,
515,
14,
904,
8,
8616,
12,
283,
396,
14,
67,
358,
288,
543,
1551,
8,
1501,
12,
283,
87,
358,
465,
2429,
26,
355,
2429,
14,
952,
8355,
953,
754,
275,
308,
337,
14,
362,
63,
4958,
8,
355,
788,
16066,
297,
2475,
67,
297,
1788,
12,
2475,
10872,
5287,
297,
2475,
36,
1391,
628,
3749,
365,
652,
2,
995,
355,
12885,
9,
953,
291,
14,
1815,
360,
46,
5287,
7,
315,
754,
9,
288,
291,
14,
1815,
360,
1391,
628,
3749,
365,
652,
4507,
315,
754,
9,
339,
347,
511,
63,
362,
63,
16066,
63,
4958,
63,
15762,
8,
277,
304,
267,
291,
14,
1855,
8,
288,
2186,
12,
308,
337,
14,
362,
63,
4958,
12,
288,
788,
16066,
297,
2475,
5680,
297,
2475,
70,
7093,
13,
2118,
297,
2475,
88,
297,
283,
67,
297,
283,
889,
3858,
631,
14,
67,
995,
20093,
421,
199,
533,
2372,
1799,
1192,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
362,
63,
32514,
8,
277,
304,
267,
327,
642,
511,
365,
1454,
370,
1937,
365,
440,
12420,
316,
267,
754,
275,
308,
337,
14,
362,
63,
32514,
360,
16066,
297,
3073,
267,
291,
14,
1815,
8,
552,
8,
1099,
430,
339,
347,
511,
63,
362,
63,
2682,
63,
32514,
8,
277,
304,
267,
327,
642,
511,
365,
1454,
370,
1937,
365,
440,
12420,
316,
267,
754,
275,
308,
337,
14,
362,
63,
2682,
63,
32514,
360,
16066,
297,
3073,
267,
291,
14,
1815,
8,
552,
8,
1099,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
9326,
710,
491,
28631,
27154,
1010,
21844,
6976,
199,
3,
199,
3,
961,
570,
365,
1854,
1334,
314,
15904,
402,
473,
76,
472,
79,
374,
3232,
5800,
199,
3,
844,
14,
1666,
5113,
14,
17715,
367,
2436,
14,
199,
199,
646,
1973,
2210,
199,
646,
1973,
6282,
1506,
14,
16066,
465,
308,
337,
199,
646,
2882,
199,
646,
747,
14,
515,
421,
199,
533,
2372,
1968,
621,
14517,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
362,
63,
16066,
63,
4958,
8,
277,
304,
267,
543,
1973,
2210,
14,
11360,
6231,
342,
465,
12885,
26,
288,
1788,
275,
747,
14,
515,
14,
904,
8,
8616,
12,
283,
396,
14,
67,
358,
288,
543,
1551,
8,
1501,
12,
283,
87,
358,
465,
2429,
26,
355,
2429,
14,
952,
8355,
953,
754,
275,
308,
337,
14,
362,
63,
4958,
8,
355,
788,
16066,
297,
2475,
67,
297,
1788,
12,
2475,
10872,
5287,
297,
2475,
36,
1391,
628,
3749,
365,
652,
2,
995,
355,
12885,
9,
953,
291,
14,
1815,
360,
46,
5287,
7,
315,
754,
9,
288,
291,
14,
1815,
360,
1391,
628,
3749,
365,
652,
4507,
315,
754,
9,
339,
347,
511,
63,
362,
63,
16066,
63,
4958,
63,
15762,
8,
277,
304,
267,
291,
14,
1855,
8,
288,
2186,
12,
308,
337,
14,
362,
63,
4958,
12,
288,
788,
16066,
297,
2475,
5680,
297,
2475,
70,
7093,
13,
2118,
297,
2475,
88,
297,
283,
67,
297,
283,
889,
3858,
631,
14,
67,
995,
20093,
421,
199,
533,
2372,
1799,
1192,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
362,
63,
32514,
8,
277,
304,
267,
327,
642,
511,
365,
1454,
370,
1937,
365,
440,
12420,
316,
267,
754,
275,
308,
337,
14,
362,
63,
32514,
360,
16066,
297,
3073,
267,
291,
14,
1815,
8,
552,
8,
1099,
430,
339,
347,
511,
63,
362,
63,
2682,
63,
32514,
8,
277,
304,
267,
327,
642,
511,
365,
1454,
370,
1937,
365,
440,
12420,
316,
267,
754,
275,
308,
337,
14,
362,
63,
2682,
63,
32514,
360,
16066,
297,
3073,
267,
291,
14,
1815,
8,
552,
8,
1099,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
SqueezeStudioAnimation/omtk
|
python/omtk/libs/libPymel.py
|
1
|
14241
|
import logging
import pymel.core as pymel
from maya import OpenMaya
#
# A PyNodeChain is a special pymel-related object that act exactly like a standard array.
# However it allow us to have more bells and whistles.
#
def is_valid_PyNode(val):
return (val and hasattr(val, 'exists') and val.exists()) if val else None
def distance_between_nodes(x, y):
"""
Return the distance between two pynodes.
"""
ax, ay, az = x.getTranslation(space="world")
bx, b, bz = y.getTranslation(space="world")
return ((ax - bx) ** 2 + (ay - b) ** 2 + (az - bz) ** 2) ** 0.5
def distance_between_vectors(a, b):
"""
http://darkvertex.com/wp/2010/06/05/python-distance-between-2-vectors/
"""
return ((a.x - b.x) ** 2 + (a.y - b.y) ** 2 + (a.z - b.z) ** 2) ** 0.5
def is_child_of(node, potential_parent):
while node:
if node == potential_parent:
return True
node = node.getParent()
return False
class PyNodeChain(list):
"""A container for manipulating lists of hosts"""
@property
def start(self):
return next(iter(self), None)
@property
def end(self):
return self[-1] if len(self) > 0 else None
@property
def chain(self):
return self
def duplicate(self):
# Hack - Convert self into list even if self is a list to prevent duplicate self parameter in pymel.duplicate
new_chain = pymel.duplicate(list(self), renameChildren=True, parentOnly=True)
return PyNodeChain(new_chain)
def setParent(self, new_parent, **kwargs):
for node in self:
if node != new_parent and node.getParent() != new_parent:
node.setParent(new_parent, **kwargs)
# todo: convert to property?
def length(self):
length = 0
for i in range(len(self) - 1):
head = self[i]
tail = self[i + 1]
length += distance_between_nodes(head, tail)
return length
# get the first pynode that have the attr
def __getattr__(self, key):
logging.warning("Searching unknow attribute {key} in {self}", key=key, self=self)
first_node = next((node for node in self.__dict__['_list'] if hasattr(node, key)), None)
if first_node is not None:
return getattr(first_node, key)
raise AttributeError
# set all the pynodes that have the attr
def __setattr__(self, key, value):
for node in self:
try:
setattr(node, key, value)
except Exception, e:
logging.error(str(e))
def duplicate_chain(chain):
new_chain = pymel.duplicate(chain, renameChildren=True, parentOnly=True)
return PyNodeChain(new_chain)
def get_num_parents(obj):
num_parents = -1
while obj is not None:
obj = obj.getParent()
num_parents += 1
return num_parents
def get_chains_from_objs(objs):
"""
Take an arbitraty collection of joints and sort them in hyerarchies represented by lists.
"""
chains = []
objs = sorted(objs, key=get_num_parents)
for obj in objs:
parent = obj.getParent()
if parent not in objs:
chains.append([obj])
else:
for chain in chains:
if parent in chain:
chain.append(obj)
return [PyNodeChain(chain) for chain in chains]
def iter_parents(obj):
while obj.getParent() is not None:
obj = obj.getParent()
yield obj
def get_parents(obj):
return list(iter_parents(obj))
'''
parents = []
while obj.getParent() is not None:
parent = obj.getParent()
parents.append(parent)
obj = parent
return parents
'''
def get_common_parents(objs):
"""
Return the first parent that all provided objects share.
:param objs: A list of pymel.PyNode instances.
:return: A pymel.PyNode instance.
"""
parent_sets = set()
for jnt in objs:
parent_set = set(get_parents(jnt))
if not parent_sets:
parent_sets = parent_set
else:
parent_sets &= parent_set
result = next(iter(reversed(sorted(parent_sets, key=get_num_parents))), None)
if result and result in objs:
result = result.getParent()
return result
class Tree(object):
__slots__ = ('val', 'children', 'parent')
def __init__(self, val):
self.val = val
self.children = []
self.parent = None
def append(self, tree):
self.children.append(tree)
tree.parent = self
def __repr__(self):
return '<Tree {0}>'.format(self.val)
def get_tree_from_objs(objs, sort=False):
"""
Sort all provided objects in a tree fashion.
Support missing objects between hierarchy.
Note that tree root value will always be None, representing the root node.
"""
dagpaths = sorted([obj.fullPath() for obj in objs])
root = Tree(None)
def dag_is_child_of(dag_parent, dag_child):
return dag_child.startswith(dag_parent + '|')
last_knot = root
for dagpath in dagpaths:
knot = Tree(dagpath)
# Resolve the new knot parent
p = last_knot
while not (p.val is None or dag_is_child_of(p.val, dagpath)):
p = p.parent
p.append(knot)
# Save the last knot, since we are iterating in alphabetical order,
# we can assume that the next knot parent can be found using this knot.
last_knot = knot
return root
#
# ls() reimplementations
#
def ls(*args, **kwargs):
return PyNodeChain(pymel.ls(*args, **kwargs))
# Wrapper for pymel.ls that return only objects without parents.
def ls_root(*args, **kwargs):
# TODO: Better finding of the root joint
return PyNodeChain(filter(lambda x: x.getParent() is None or type(x.getParent()) != pymel.nt.Joint,
iter(pymel.ls(*args, **kwargs))))
def ls_root_anms(pattern='anm*', **kwargs):
return ls_root(pattern, type='transform', **kwargs)
def ls_root_geos(pattern='geo*', **kwargs):
return ls_root(pattern, type='transform', **kwargs)
def ls_root_rigs(pattern='rig*', **kwargs):
return ls_root(pattern, type='transform', **kwargs)
def ls_root_jnts(pattern='jnt*', **kwargs):
return ls_root(pattern, type='transform', **kwargs)
#
# isinstance() reimplementation
#
# Class check for transform PyNodes
def isinstance_of_transform(obj, cls=pymel.nodetypes.Transform):
return isinstance(obj, cls)
# Class check for shape PyNodes
def isinstance_of_shape(obj, cls=pymel.nodetypes.Shape):
if isinstance(obj, pymel.nodetypes.Transform):
return any((shape for shape in obj.getShapes() if isinstance(shape, cls)))
elif isinstance(obj, pymel.nodetypes.Shape):
return isinstance(obj, cls)
def create_zero_grp(obj):
zero_grp = pymel.createNode('transform')
new_name = obj.name() + '_' + 'zero_grp'
zero_grp.rename(new_name)
# Note: Removed for performance
zero_grp.setMatrix(obj.getMatrix(worldSpace=True))
parent = obj.getParent()
if parent:
zero_grp.setParent(parent)
obj.setParent(zero_grp)
return zero_grp
def zero_out_objs(objs):
for o in objs:
create_zero_grp(o)
#
# pymel.datatypes extensions.
#
class Segment(object):
"""
In Maya there's no class to represent a segment.
This is the pymel.datatypes.Segment I've always wanted.
"""
def __init__(self, pos_s, pos_e):
self.pos_s = pos_s
self.pos_e = pos_e
# self.pos_s = numpy.array(pos_s.x, pos_s.y, pos_s.z)
# self.pos_e = numpy.array(pos_e.x, pos_e.y, pos_e.z)
def closest_point(self, p):
"""
http://stackoverflow.com/questions/3120357/get-closest-point-to-a-line
"""
a = self.pos_s
b = self.pos_e
a_to_p = p - a
a_to_b = b - a
ab_length = a_to_b.length()
ap_length = a_to_p.length()
a_to_p_norm = a_to_p.normal()
a_to_b_norm = a_to_b.normal()
atp_dot_atb = a_to_p_norm * (a_to_b_norm) # dot product
dist_norm = atp_dot_atb * ap_length / ab_length
return pymel.datatypes.Vector(
a.x + a_to_b.x * dist_norm,
a.y + a_to_b.y * dist_norm,
a.z + a_to_b.z * dist_norm
)
def closest_point_normalized_distance(self, p, epsilon=0.001):
"""
Same things as .closest_point but only return the distance relative from the length of a to b.
Available for optimisation purpose.
"""
a = self.pos_s
b = self.pos_e
a_to_p = p - a
a_to_b = b - a
ab_length = a_to_b.length()
ap_length = a_to_p.length()
a_to_p_norm = a_to_p.normal()
a_to_b_norm = a_to_b.normal()
atp_dot_atb = a_to_p_norm * a_to_b_norm
return (atp_dot_atb * ap_length / ab_length) if abs(ab_length) > epsilon else 0.0
class SegmentCollection(object):
def __init__(self, segments=None):
if segments is None:
segments = []
self.segments = segments
self.knots = [segment.pos_s for segment in self.segments]
self.knots.append(self.segments[-1].pos_e)
def closest_segment(self, pos):
bound_min = -0.000000000001 # Damn float imprecision
bound_max = 1.0000000000001 # Damn float imprecision
num_segments = len(self.segments)
for i, segment in enumerate(self.segments):
distance_normalized = segment.closest_point_normalized_distance(pos)
if bound_min <= distance_normalized <= bound_max:
return segment, distance_normalized
elif i == 0 and distance_normalized < bound_min: # Handle out-of-bound
return segment, 0.0
elif i == (num_segments - 1) and distance_normalized > bound_max: # Handle out-of-bound
return segment, 1.0
raise Exception("Can't resolve segment for {0}".format(pos))
def closest_segment_index(self, pos):
closest_segment, ratio = self.closest_segment(pos)
index = self.segments.index(closest_segment)
return index, ratio
def get_knot_weights(self, dropoff=1.0, normalize=True):
num_knots = len(self.knots)
knots_weights = []
for i, knot in enumerate(self.knots):
if i == 0:
weights = [0] * num_knots
weights[0] = 1.0
elif i == (num_knots - 1):
weights = [0] * num_knots
weights[-1] = 1.0
else:
weights = []
total_weight = 0.0
for j in range(num_knots):
distance = abs(j - i)
weight = max(0, 1.0 - (distance / dropoff))
total_weight += weight
weights.append(weight)
weights = [weight / total_weight for weight in weights]
knots_weights.append(weights)
return knots_weights
'''
def get_weights(self, pos, dropoff=1.0, normalize=True):
# Compute the 'SegmentCollection' relative ratio and return the weight for each knots.
closest_segment, relative_ratio = self.closest_segment(pos)
index = self.segments.index(closest_segment)
absolute_ratio = relative_ratio + index
weights = []
total_weights = 0.0
for segment_ratio in range(len(self.knots)):
#segment_ratio += 0.5 # center of the joint
#print segment_ratio, absolute_ratio
distance = abs(segment_ratio - absolute_ratio)
weight = max(0, 1.0-(distance/dropoff))
# Apply cubic interpolation for greater results.
#weight = interp_cubic(weight)
total_weights += weight
weights.append(weight)
if normalize:
weights = [weight / total_weights for weight in weights]
return weights
'''
@classmethod
def from_transforms(cls, objs):
segments = []
num_objs = len(objs)
for i in range(num_objs - 1):
obj_s = objs[i]
obj_e = objs[i + 1]
mfn_transform_s = obj_s.__apimfn__()
mfn_transform_e = obj_e.__apimfn__()
pos_s = OpenMaya.MVector(mfn_transform_s.getTranslation(OpenMaya.MSpace.kWorld))
pos_e = OpenMaya.MVector(mfn_transform_e.getTranslation(OpenMaya.MSpace.kWorld))
segment = Segment(pos_s, pos_e)
segments.append(segment)
return cls(segments)
@classmethod
def from_positions(cls, positions):
segments = []
num_positions = len(positions)
for i in range(num_positions - 1):
pos_s = positions[i]
pos_e = positions[i + 1]
segment = Segment(pos_s, pos_e)
segments.append(segment)
return cls(segments)
def get_rotation_from_matrix(tm):
"""
Bypass pymel bug
see https://github.com/LumaPictures/pymel/issues/355
"""
return pymel.datatypes.TransformationMatrix(tm).rotate
def makeIdentity_safe(obj, translate=False, rotate=False, scale=False, apply=False, **kwargs):
"""
Extended pymel.makeIdentity method that won't crash for idiotic reasons.
"""
from . import libAttr
affected_attrs = []
# Ensure the shape don't have any extra transformation.
if apply:
if translate:
libAttr.unlock_translation(obj)
affected_attrs.extend([
obj.translate, obj.translateX, obj.translateY, obj.translateZ
])
if rotate:
libAttr.unlock_rotation(obj)
affected_attrs.extend([
obj.rotate, obj.rotateX, obj.rotateY, obj.rotateZ
])
if scale:
libAttr.unlock_scale(obj)
affected_attrs.extend([
obj.scale, obj.scaleX, obj.scaleY, obj.scaleZ
])
# Make identify will faile if attributes are connected...
with libAttr.context_disconnected_attrs(affected_attrs, hold_inputs=True, hold_outputs=False):
pymel.makeIdentity(obj, apply=apply, translate=translate, rotate=rotate, scale=scale, **kwargs)
|
mit
|
[
646,
2050,
199,
199,
646,
1134,
26908,
14,
1018,
465,
1134,
26908,
199,
504,
1443,
65,
492,
3232,
15586,
65,
421,
199,
3,
199,
3,
437,
1611,
1716,
10720,
365,
282,
4539,
1134,
26908,
13,
2407,
909,
626,
2454,
8840,
2839,
282,
4465,
1625,
14,
199,
3,
9738,
652,
2040,
2739,
370,
1172,
1655,
330,
6840,
436,
704,
631,
2978,
14,
199,
3,
199,
199,
318,
365,
63,
1078,
63,
2713,
1716,
8,
637,
304,
272,
372,
334,
637,
436,
2688,
8,
637,
12,
283,
2444,
358,
436,
1139,
14,
2444,
1012,
340,
1139,
587,
488,
421,
199,
318,
6033,
63,
13007,
63,
2415,
8,
88,
12,
612,
304,
272,
408,
272,
1432,
314,
6033,
3382,
2877,
1134,
2415,
14,
272,
408,
272,
2185,
12,
282,
89,
12,
24978,
275,
671,
14,
362,
18483,
8,
2638,
628,
7617,
531,
272,
330,
88,
12,
330,
12,
15055,
275,
612,
14,
362,
18483,
8,
2638,
628,
7617,
531,
272,
372,
3666,
1219,
446,
330,
88,
9,
1011,
499,
435,
334,
1187,
446,
330,
9,
1011,
499,
435,
334,
4651,
446,
15055,
9,
1011,
499,
9,
1011,
378,
14,
21,
421,
199,
318,
6033,
63,
13007,
63,
12280,
8,
65,
12,
330,
304,
272,
408,
272,
1455,
921,
13625,
11417,
14,
957,
15,
14649,
15,
6542,
15,
1690,
15,
1717,
15,
1548,
13,
5590,
13,
13007,
13,
18,
13,
12280,
15,
272,
408,
272,
372,
3666,
65,
14,
88,
446,
330,
14,
88,
9,
1011,
499,
435,
334,
65,
14,
89,
446,
330,
14,
89,
9,
1011,
499,
435,
334,
65,
14,
90,
446,
330,
14,
90,
9,
1011,
499,
9,
1011,
378,
14,
21,
421,
199,
318,
365,
63,
1739,
63,
1618,
8,
932,
12,
12330,
63,
1708,
304,
272,
1830,
1031,
26,
267,
340,
1031,
508,
12330,
63,
1708,
26,
288,
372,
715,
267,
1031,
275,
1031,
14,
362,
6652,
342,
272,
372,
756,
421,
199,
533,
1611,
1716,
10720,
8,
513,
304,
272,
408,
33,
3970,
367,
13335,
20529,
5548,
402,
7057,
624,
339,
768,
1829,
272,
347,
1343,
8,
277,
304,
267,
372,
2163,
8,
1661,
8,
277,
395,
488,
9,
339,
768,
1829,
272,
347,
1284,
8,
277,
304,
267,
372,
291,
1988,
17,
61,
340,
822,
8,
277,
9,
690,
378,
587,
488,
339,
768,
1829,
272,
347,
6036,
8,
277,
304,
267,
372,
291,
339,
347,
9250,
8,
277,
304,
267,
327,
30802,
446,
7905,
291,
1901,
769,
2755,
340,
291,
365,
282,
769,
370,
7981,
9250,
291,
2725,
315,
1134,
26908,
14,
11081,
267,
892,
63,
4429,
275,
1134,
26908,
14,
11081,
8,
513,
8,
277,
395,
11441,
7139,
29,
549,
12,
1676,
5903,
29,
549,
9,
267,
372,
1611,
1716,
10720,
8,
1222,
63,
4429,
9,
339,
347,
663,
6652,
8,
277,
12,
892,
63,
1708,
12,
1011,
958,
304,
267,
367,
1031,
315,
291,
26,
288,
340,
1031,
1137,
892,
63,
1708,
436,
1031,
14,
362,
6652,
342,
1137,
892,
63,
1708,
26,
355,
1031,
14,
409,
6652,
8,
1222,
63,
1708,
12,
1011,
958,
9,
339,
327,
11386,
26,
3957,
370,
3324,
31,
272,
347,
2582,
8,
277,
304,
267,
2582,
275,
378,
267,
367,
284,
315,
1425,
8,
552,
8,
277,
9,
446,
413,
304,
288,
4854,
275,
291,
59,
73,
61,
288,
9483,
275,
291,
59,
73,
435,
413,
61,
288,
2582,
847,
6033,
63,
13007,
63,
2415,
8,
2993,
12,
9483,
9,
267,
372,
2582,
339,
327,
664,
314,
1642,
1134,
932,
626,
1172,
314,
1921,
272,
347,
636,
5675,
721,
277,
12,
790,
304,
267,
2050,
14,
3764,
480,
5278,
316,
625,
14996,
2225,
469,
498,
93,
315,
469,
277,
10750,
790,
29,
498,
12,
291,
29,
277,
9,
267,
1642,
63,
932,
275,
2163,
1332,
932,
367,
1031,
315,
291,
855,
807,
363,
8680,
513,
418,
340,
2688,
8,
932,
12,
790,
1826,
488,
9,
267,
340,
1642,
63,
932,
365,
440,
488,
26,
288,
372,
2519,
8,
2246,
63,
932,
12,
790,
9,
267,
746,
4281,
339,
327,
663,
1006,
314,
1134,
2415,
626,
1172,
314,
1921,
272,
347,
636,
10202,
721,
277,
12,
790,
12,
574,
304,
267,
367,
1031,
315,
291,
26,
288,
862,
26,
355,
5371,
8,
932,
12,
790,
12,
574,
9,
288,
871,
2186,
12,
325,
26,
355,
2050,
14,
705,
8,
495,
8,
69,
430,
421,
199,
318,
9250,
63,
4429,
8,
4429,
304,
272,
892,
63,
4429,
275,
1134,
26908,
14,
11081,
8,
4429,
12,
11441,
7139,
29,
549,
12,
1676,
5903,
29,
549,
9,
272,
372,
1611,
1716,
10720,
8,
1222,
63,
4429,
9,
421,
199,
318,
664,
63,
1507,
63,
8859,
8,
1113,
304,
272,
1967,
63,
8859,
275,
446,
17,
272,
1830,
1559,
365,
440,
488,
26,
267,
1559,
275,
1559,
14,
362,
6652,
342,
267,
1967,
63,
8859,
847,
413,
272,
372,
1967,
63,
8859,
421,
199,
318,
664,
63,
17419,
63,
504,
63,
8718,
8,
8718,
304,
272,
408,
272,
18146,
376,
601,
2075,
17565,
89,
3245,
402,
5225,
13141,
436,
4069,
3062,
315,
7188,
281,
1047,
1500,
11159,
701,
5548,
14,
272,
408,
272,
30640,
275,
942,
272,
13474,
275,
3355,
8,
8718,
12,
790,
29,
362,
63,
1507,
63,
8859,
9,
272,
367,
1559,
315,
13474,
26,
267,
1676,
275,
1559,
14,
362,
6652,
342,
267,
340,
1676,
440,
315,
13474,
26,
288,
30640,
14,
740,
779,
1113,
566,
267,
587,
26,
288,
367,
6036,
315,
30640,
26,
355,
340,
1676,
315,
6036,
26,
490,
6036,
14,
740,
8,
1113,
9,
272,
372,
359,
2713,
1716,
10720,
8,
4429,
9,
367,
6036,
315,
30640,
61,
421,
199,
318,
2740,
63,
8859,
8,
1113,
304,
272,
1830,
1559,
14,
362,
6652,
342,
365,
440,
488,
26,
267,
1559,
275,
1559,
14,
362,
6652,
342,
267,
1995,
1559,
421,
199,
318,
664,
63,
8859,
8,
1113,
304,
272,
372,
769,
8,
1661,
63,
8859,
8,
1113,
430,
272,
1449,
272,
8623,
275,
942,
272,
1830,
1559,
14,
362,
6652,
342,
365,
440,
488,
26,
267,
1676,
275,
1559,
14,
362,
6652,
342,
267,
8623,
14,
740,
8,
1708,
9,
267,
1559,
275,
1676,
272,
372,
8623,
272,
1449,
421,
199,
318,
664,
63,
2330,
63,
8859,
8,
8718
] |
[
2050,
199,
199,
646,
1134,
26908,
14,
1018,
465,
1134,
26908,
199,
504,
1443,
65,
492,
3232,
15586,
65,
421,
199,
3,
199,
3,
437,
1611,
1716,
10720,
365,
282,
4539,
1134,
26908,
13,
2407,
909,
626,
2454,
8840,
2839,
282,
4465,
1625,
14,
199,
3,
9738,
652,
2040,
2739,
370,
1172,
1655,
330,
6840,
436,
704,
631,
2978,
14,
199,
3,
199,
199,
318,
365,
63,
1078,
63,
2713,
1716,
8,
637,
304,
272,
372,
334,
637,
436,
2688,
8,
637,
12,
283,
2444,
358,
436,
1139,
14,
2444,
1012,
340,
1139,
587,
488,
421,
199,
318,
6033,
63,
13007,
63,
2415,
8,
88,
12,
612,
304,
272,
408,
272,
1432,
314,
6033,
3382,
2877,
1134,
2415,
14,
272,
408,
272,
2185,
12,
282,
89,
12,
24978,
275,
671,
14,
362,
18483,
8,
2638,
628,
7617,
531,
272,
330,
88,
12,
330,
12,
15055,
275,
612,
14,
362,
18483,
8,
2638,
628,
7617,
531,
272,
372,
3666,
1219,
446,
330,
88,
9,
1011,
499,
435,
334,
1187,
446,
330,
9,
1011,
499,
435,
334,
4651,
446,
15055,
9,
1011,
499,
9,
1011,
378,
14,
21,
421,
199,
318,
6033,
63,
13007,
63,
12280,
8,
65,
12,
330,
304,
272,
408,
272,
1455,
921,
13625,
11417,
14,
957,
15,
14649,
15,
6542,
15,
1690,
15,
1717,
15,
1548,
13,
5590,
13,
13007,
13,
18,
13,
12280,
15,
272,
408,
272,
372,
3666,
65,
14,
88,
446,
330,
14,
88,
9,
1011,
499,
435,
334,
65,
14,
89,
446,
330,
14,
89,
9,
1011,
499,
435,
334,
65,
14,
90,
446,
330,
14,
90,
9,
1011,
499,
9,
1011,
378,
14,
21,
421,
199,
318,
365,
63,
1739,
63,
1618,
8,
932,
12,
12330,
63,
1708,
304,
272,
1830,
1031,
26,
267,
340,
1031,
508,
12330,
63,
1708,
26,
288,
372,
715,
267,
1031,
275,
1031,
14,
362,
6652,
342,
272,
372,
756,
421,
199,
533,
1611,
1716,
10720,
8,
513,
304,
272,
408,
33,
3970,
367,
13335,
20529,
5548,
402,
7057,
624,
339,
768,
1829,
272,
347,
1343,
8,
277,
304,
267,
372,
2163,
8,
1661,
8,
277,
395,
488,
9,
339,
768,
1829,
272,
347,
1284,
8,
277,
304,
267,
372,
291,
1988,
17,
61,
340,
822,
8,
277,
9,
690,
378,
587,
488,
339,
768,
1829,
272,
347,
6036,
8,
277,
304,
267,
372,
291,
339,
347,
9250,
8,
277,
304,
267,
327,
30802,
446,
7905,
291,
1901,
769,
2755,
340,
291,
365,
282,
769,
370,
7981,
9250,
291,
2725,
315,
1134,
26908,
14,
11081,
267,
892,
63,
4429,
275,
1134,
26908,
14,
11081,
8,
513,
8,
277,
395,
11441,
7139,
29,
549,
12,
1676,
5903,
29,
549,
9,
267,
372,
1611,
1716,
10720,
8,
1222,
63,
4429,
9,
339,
347,
663,
6652,
8,
277,
12,
892,
63,
1708,
12,
1011,
958,
304,
267,
367,
1031,
315,
291,
26,
288,
340,
1031,
1137,
892,
63,
1708,
436,
1031,
14,
362,
6652,
342,
1137,
892,
63,
1708,
26,
355,
1031,
14,
409,
6652,
8,
1222,
63,
1708,
12,
1011,
958,
9,
339,
327,
11386,
26,
3957,
370,
3324,
31,
272,
347,
2582,
8,
277,
304,
267,
2582,
275,
378,
267,
367,
284,
315,
1425,
8,
552,
8,
277,
9,
446,
413,
304,
288,
4854,
275,
291,
59,
73,
61,
288,
9483,
275,
291,
59,
73,
435,
413,
61,
288,
2582,
847,
6033,
63,
13007,
63,
2415,
8,
2993,
12,
9483,
9,
267,
372,
2582,
339,
327,
664,
314,
1642,
1134,
932,
626,
1172,
314,
1921,
272,
347,
636,
5675,
721,
277,
12,
790,
304,
267,
2050,
14,
3764,
480,
5278,
316,
625,
14996,
2225,
469,
498,
93,
315,
469,
277,
10750,
790,
29,
498,
12,
291,
29,
277,
9,
267,
1642,
63,
932,
275,
2163,
1332,
932,
367,
1031,
315,
291,
855,
807,
363,
8680,
513,
418,
340,
2688,
8,
932,
12,
790,
1826,
488,
9,
267,
340,
1642,
63,
932,
365,
440,
488,
26,
288,
372,
2519,
8,
2246,
63,
932,
12,
790,
9,
267,
746,
4281,
339,
327,
663,
1006,
314,
1134,
2415,
626,
1172,
314,
1921,
272,
347,
636,
10202,
721,
277,
12,
790,
12,
574,
304,
267,
367,
1031,
315,
291,
26,
288,
862,
26,
355,
5371,
8,
932,
12,
790,
12,
574,
9,
288,
871,
2186,
12,
325,
26,
355,
2050,
14,
705,
8,
495,
8,
69,
430,
421,
199,
318,
9250,
63,
4429,
8,
4429,
304,
272,
892,
63,
4429,
275,
1134,
26908,
14,
11081,
8,
4429,
12,
11441,
7139,
29,
549,
12,
1676,
5903,
29,
549,
9,
272,
372,
1611,
1716,
10720,
8,
1222,
63,
4429,
9,
421,
199,
318,
664,
63,
1507,
63,
8859,
8,
1113,
304,
272,
1967,
63,
8859,
275,
446,
17,
272,
1830,
1559,
365,
440,
488,
26,
267,
1559,
275,
1559,
14,
362,
6652,
342,
267,
1967,
63,
8859,
847,
413,
272,
372,
1967,
63,
8859,
421,
199,
318,
664,
63,
17419,
63,
504,
63,
8718,
8,
8718,
304,
272,
408,
272,
18146,
376,
601,
2075,
17565,
89,
3245,
402,
5225,
13141,
436,
4069,
3062,
315,
7188,
281,
1047,
1500,
11159,
701,
5548,
14,
272,
408,
272,
30640,
275,
942,
272,
13474,
275,
3355,
8,
8718,
12,
790,
29,
362,
63,
1507,
63,
8859,
9,
272,
367,
1559,
315,
13474,
26,
267,
1676,
275,
1559,
14,
362,
6652,
342,
267,
340,
1676,
440,
315,
13474,
26,
288,
30640,
14,
740,
779,
1113,
566,
267,
587,
26,
288,
367,
6036,
315,
30640,
26,
355,
340,
1676,
315,
6036,
26,
490,
6036,
14,
740,
8,
1113,
9,
272,
372,
359,
2713,
1716,
10720,
8,
4429,
9,
367,
6036,
315,
30640,
61,
421,
199,
318,
2740,
63,
8859,
8,
1113,
304,
272,
1830,
1559,
14,
362,
6652,
342,
365,
440,
488,
26,
267,
1559,
275,
1559,
14,
362,
6652,
342,
267,
1995,
1559,
421,
199,
318,
664,
63,
8859,
8,
1113,
304,
272,
372,
769,
8,
1661,
63,
8859,
8,
1113,
430,
272,
1449,
272,
8623,
275,
942,
272,
1830,
1559,
14,
362,
6652,
342,
365,
440,
488,
26,
267,
1676,
275,
1559,
14,
362,
6652,
342,
267,
8623,
14,
740,
8,
1708,
9,
267,
1559,
275,
1676,
272,
372,
8623,
272,
1449,
421,
199,
318,
664,
63,
2330,
63,
8859,
8,
8718,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
microsoft/task_oriented_dialogue_as_dataflow_synthesis
|
src/dataflow/leaderboard/predict.py
|
1
|
2613
|
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
"""
Semantic Machines\N{TRADE MARK SIGN} software.
Creates the prediction files from onmt_translate output for the leaderboard.
"""
import argparse
from typing import List
import jsons
from more_itertools import chunked
from dataflow.core.dialogue import TurnId
from dataflow.core.io import save_jsonl_file
from dataflow.core.turn_prediction import TurnPrediction
def build_prediction_report_datum(
datum_id_line: str, src_line: str, nbest_lines: List[str],
) -> TurnPrediction:
datum_id = jsons.loads(datum_id_line.strip(), TurnId)
return TurnPrediction(
datum_id=datum_id,
user_utterance=src_line.strip(),
lispress=nbest_lines[0].strip(),
)
def create_onmt_prediction_report(
datum_id_jsonl: str, src_txt: str, ref_txt: str, nbest_txt: str, nbest: int,
):
prediction_report = [
build_prediction_report_datum(
datum_id_line=datum_id_line, src_line=src_line, nbest_lines=nbest_lines,
)
for datum_id_line, src_line, ref_line, nbest_lines in zip(
open(datum_id_jsonl),
open(src_txt),
open(ref_txt),
chunked(open(nbest_txt), nbest),
)
]
save_jsonl_file(prediction_report, "predictions.jsonl")
def main(
datum_id_jsonl: str, src_txt: str, ref_txt: str, nbest_txt: str, nbest: int,
) -> None:
"""Creates 1-best predictions and saves them to files."""
create_onmt_prediction_report(
datum_id_jsonl=datum_id_jsonl,
src_txt=src_txt,
ref_txt=ref_txt,
nbest_txt=nbest_txt,
nbest=nbest,
)
def add_arguments(argument_parser: argparse.ArgumentParser) -> None:
argument_parser.add_argument("--datum_id_jsonl", help="datum ID file")
argument_parser.add_argument("--src_txt", help="source sequence file")
argument_parser.add_argument("--ref_txt", help="target sequence reference file")
argument_parser.add_argument("--nbest_txt", help="onmt_translate output file")
argument_parser.add_argument("--nbest", type=int, help="number of hypos per datum")
if __name__ == "__main__":
cmdline_parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawTextHelpFormatter
)
add_arguments(cmdline_parser)
args = cmdline_parser.parse_args()
print("Semantic Machines\N{TRADE MARK SIGN} software.")
main(
datum_id_jsonl=args.datum_id_jsonl,
src_txt=args.src_txt,
ref_txt=args.ref_txt,
nbest_txt=args.nbest_txt,
nbest=args.nbest,
)
|
mit
|
[
3,
221,
1898,
334,
67,
9,
15332,
11098,
14,
199,
3,
221,
3909,
1334,
314,
10697,
4190,
14,
199,
624,
199,
1513,
23127,
30611,
3746,
60,
46,
91,
13954,
1093,
8132,
5056,
93,
2032,
14,
199,
199,
10607,
314,
12044,
1584,
687,
641,
2037,
63,
5275,
1072,
367,
314,
23092,
3576,
14,
199,
624,
199,
646,
7534,
199,
504,
14090,
492,
3820,
199,
199,
646,
2022,
83,
199,
504,
1655,
63,
17691,
492,
22180,
199,
199,
504,
666,
1659,
14,
1018,
14,
7196,
310,
492,
16147,
1304,
199,
504,
666,
1659,
14,
1018,
14,
2308,
492,
3354,
63,
1001,
76,
63,
493,
199,
504,
666,
1659,
14,
1018,
14,
353,
63,
14845,
492,
16147,
24261,
421,
199,
318,
1900,
63,
14845,
63,
3070,
63,
18945,
8,
272,
18908,
63,
344,
63,
604,
26,
620,
12,
2928,
63,
604,
26,
620,
12,
302,
7010,
63,
1278,
26,
3820,
59,
495,
467,
199,
9,
1035,
16147,
24261,
26,
272,
18908,
63,
344,
275,
2022,
83,
14,
3640,
8,
18945,
63,
344,
63,
604,
14,
1913,
1062,
16147,
1304,
9,
272,
372,
16147,
24261,
8,
267,
18908,
63,
344,
29,
18945,
63,
344,
12,
267,
922,
63,
18404,
554,
29,
2164,
63,
604,
14,
1913,
1062,
267,
1212,
83,
2915,
29,
4994,
597,
63,
1278,
59,
16,
1055,
1913,
1062,
272,
776,
421,
199,
318,
1218,
63,
265,
2037,
63,
14845,
63,
3070,
8,
272,
18908,
63,
344,
63,
1001,
76,
26,
620,
12,
2928,
63,
2424,
26,
620,
12,
2984,
63,
2424,
26,
620,
12,
302,
7010,
63,
2424,
26,
620,
12,
302,
7010,
26,
1109,
12,
199,
304,
272,
12044,
63,
3070,
275,
359,
267,
1900,
63,
14845,
63,
3070,
63,
18945,
8,
288,
18908,
63,
344,
63,
604,
29,
18945,
63,
344,
63,
604,
12,
2928,
63,
604,
29,
2164,
63,
604,
12,
302,
7010,
63,
1278,
29,
4994,
597,
63,
1278,
12,
267,
776,
267,
367,
18908,
63,
344,
63,
604,
12,
2928,
63,
604,
12,
2984,
63,
604,
12,
302,
7010,
63,
1278,
315,
3482,
8,
288,
1551,
8,
18945,
63,
344,
63,
1001,
76,
395,
288,
1551,
8,
2164,
63,
2424,
395,
288,
1551,
8,
1121,
63,
2424,
395,
288,
22180,
8,
1490,
8,
4994,
597,
63,
2424,
395,
302,
7010,
395,
267,
776,
272,
1622,
272,
3354,
63,
1001,
76,
63,
493,
8,
14845,
63,
3070,
12,
298,
9869,
14,
1001,
76,
531,
421,
199,
318,
2446,
8,
272,
18908,
63,
344,
63,
1001,
76,
26,
620,
12,
2928,
63,
2424,
26,
620,
12,
2984,
63,
2424,
26,
620,
12,
302,
7010,
63,
2424,
26,
620,
12,
302,
7010,
26,
1109,
12,
199,
9,
1035,
488,
26,
272,
408,
10607,
413,
13,
7010,
7914,
436,
23050,
3062,
370,
1584,
1041,
272,
1218,
63,
265,
2037,
63,
14845,
63,
3070,
8,
267,
18908,
63,
344,
63,
1001,
76,
29,
18945,
63,
344,
63,
1001,
76,
12,
267,
2928,
63,
2424,
29,
2164,
63,
2424,
12,
267,
2984,
63,
2424,
29,
1121,
63,
2424,
12,
267,
302,
7010,
63,
2424,
29,
4994,
597,
63,
2424,
12,
267,
302,
7010,
29,
4994,
597,
12,
272,
776,
421,
199,
318,
1050,
63,
4958,
8,
2094,
63,
2087,
26,
7534,
14,
10730,
9,
1035,
488,
26,
272,
1423,
63,
2087,
14,
525,
63,
2094,
6739,
18945,
63,
344,
63,
1001,
76,
401,
1720,
628,
18945,
2870,
570,
531,
272,
1423,
63,
2087,
14,
525,
63,
2094,
6739,
2164,
63,
2424,
401,
1720,
628,
1365,
3414,
570,
531,
272,
1423,
63,
2087,
14,
525,
63,
2094,
6739,
1121,
63,
2424,
401,
1720,
628,
1375,
3414,
3659,
570,
531,
272,
1423,
63,
2087,
14,
525,
63,
2094,
6739,
4994,
597,
63,
2424,
401,
1720,
628,
265,
2037,
63,
5275,
1072,
570,
531,
272,
1423,
63,
2087,
14,
525,
63,
2094,
6739,
4994,
597,
401,
730,
29,
442,
12,
1720,
628,
1955,
402,
7188,
1712,
1126,
18908,
531,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
21206,
63,
2087,
275,
7534,
14,
10730,
8,
267,
1369,
18971,
1301,
3108,
9698,
63,
533,
29,
18978,
14,
7963,
1872,
22779,
272,
776,
272,
1050,
63,
4958,
8,
15612,
63,
2087,
9,
272,
1249,
275,
21206,
63,
2087,
14,
1122,
63,
589,
342,
339,
870,
480,
1513,
23127,
30611,
3746,
60,
46,
91,
13954,
1093,
8132,
5056,
93,
2032,
2685,
272,
2446,
8,
267,
18908,
63,
344,
63,
1001,
76,
29,
589,
14,
18945,
63,
344,
63,
1001,
76,
12,
267,
2928,
63,
2424,
29,
589,
14,
2164,
63,
2424,
12,
267,
2984,
63,
2424,
29,
589,
14,
1121,
63,
2424,
12,
267,
302,
7010,
63,
2424,
29,
589,
14,
4994,
597,
63,
2424,
12,
267,
302,
7010,
29,
589,
14,
4994,
597,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
221,
1898,
334,
67,
9,
15332,
11098,
14,
199,
3,
221,
3909,
1334,
314,
10697,
4190,
14,
199,
624,
199,
1513,
23127,
30611,
3746,
60,
46,
91,
13954,
1093,
8132,
5056,
93,
2032,
14,
199,
199,
10607,
314,
12044,
1584,
687,
641,
2037,
63,
5275,
1072,
367,
314,
23092,
3576,
14,
199,
624,
199,
646,
7534,
199,
504,
14090,
492,
3820,
199,
199,
646,
2022,
83,
199,
504,
1655,
63,
17691,
492,
22180,
199,
199,
504,
666,
1659,
14,
1018,
14,
7196,
310,
492,
16147,
1304,
199,
504,
666,
1659,
14,
1018,
14,
2308,
492,
3354,
63,
1001,
76,
63,
493,
199,
504,
666,
1659,
14,
1018,
14,
353,
63,
14845,
492,
16147,
24261,
421,
199,
318,
1900,
63,
14845,
63,
3070,
63,
18945,
8,
272,
18908,
63,
344,
63,
604,
26,
620,
12,
2928,
63,
604,
26,
620,
12,
302,
7010,
63,
1278,
26,
3820,
59,
495,
467,
199,
9,
1035,
16147,
24261,
26,
272,
18908,
63,
344,
275,
2022,
83,
14,
3640,
8,
18945,
63,
344,
63,
604,
14,
1913,
1062,
16147,
1304,
9,
272,
372,
16147,
24261,
8,
267,
18908,
63,
344,
29,
18945,
63,
344,
12,
267,
922,
63,
18404,
554,
29,
2164,
63,
604,
14,
1913,
1062,
267,
1212,
83,
2915,
29,
4994,
597,
63,
1278,
59,
16,
1055,
1913,
1062,
272,
776,
421,
199,
318,
1218,
63,
265,
2037,
63,
14845,
63,
3070,
8,
272,
18908,
63,
344,
63,
1001,
76,
26,
620,
12,
2928,
63,
2424,
26,
620,
12,
2984,
63,
2424,
26,
620,
12,
302,
7010,
63,
2424,
26,
620,
12,
302,
7010,
26,
1109,
12,
199,
304,
272,
12044,
63,
3070,
275,
359,
267,
1900,
63,
14845,
63,
3070,
63,
18945,
8,
288,
18908,
63,
344,
63,
604,
29,
18945,
63,
344,
63,
604,
12,
2928,
63,
604,
29,
2164,
63,
604,
12,
302,
7010,
63,
1278,
29,
4994,
597,
63,
1278,
12,
267,
776,
267,
367,
18908,
63,
344,
63,
604,
12,
2928,
63,
604,
12,
2984,
63,
604,
12,
302,
7010,
63,
1278,
315,
3482,
8,
288,
1551,
8,
18945,
63,
344,
63,
1001,
76,
395,
288,
1551,
8,
2164,
63,
2424,
395,
288,
1551,
8,
1121,
63,
2424,
395,
288,
22180,
8,
1490,
8,
4994,
597,
63,
2424,
395,
302,
7010,
395,
267,
776,
272,
1622,
272,
3354,
63,
1001,
76,
63,
493,
8,
14845,
63,
3070,
12,
298,
9869,
14,
1001,
76,
531,
421,
199,
318,
2446,
8,
272,
18908,
63,
344,
63,
1001,
76,
26,
620,
12,
2928,
63,
2424,
26,
620,
12,
2984,
63,
2424,
26,
620,
12,
302,
7010,
63,
2424,
26,
620,
12,
302,
7010,
26,
1109,
12,
199,
9,
1035,
488,
26,
272,
408,
10607,
413,
13,
7010,
7914,
436,
23050,
3062,
370,
1584,
1041,
272,
1218,
63,
265,
2037,
63,
14845,
63,
3070,
8,
267,
18908,
63,
344,
63,
1001,
76,
29,
18945,
63,
344,
63,
1001,
76,
12,
267,
2928,
63,
2424,
29,
2164,
63,
2424,
12,
267,
2984,
63,
2424,
29,
1121,
63,
2424,
12,
267,
302,
7010,
63,
2424,
29,
4994,
597,
63,
2424,
12,
267,
302,
7010,
29,
4994,
597,
12,
272,
776,
421,
199,
318,
1050,
63,
4958,
8,
2094,
63,
2087,
26,
7534,
14,
10730,
9,
1035,
488,
26,
272,
1423,
63,
2087,
14,
525,
63,
2094,
6739,
18945,
63,
344,
63,
1001,
76,
401,
1720,
628,
18945,
2870,
570,
531,
272,
1423,
63,
2087,
14,
525,
63,
2094,
6739,
2164,
63,
2424,
401,
1720,
628,
1365,
3414,
570,
531,
272,
1423,
63,
2087,
14,
525,
63,
2094,
6739,
1121,
63,
2424,
401,
1720,
628,
1375,
3414,
3659,
570,
531,
272,
1423,
63,
2087,
14,
525,
63,
2094,
6739,
4994,
597,
63,
2424,
401,
1720,
628,
265,
2037,
63,
5275,
1072,
570,
531,
272,
1423,
63,
2087,
14,
525,
63,
2094,
6739,
4994,
597,
401,
730,
29,
442,
12,
1720,
628,
1955,
402,
7188,
1712,
1126,
18908,
531,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
21206,
63,
2087,
275,
7534,
14,
10730,
8,
267,
1369,
18971,
1301,
3108,
9698,
63,
533,
29,
18978,
14,
7963,
1872,
22779,
272,
776,
272,
1050,
63,
4958,
8,
15612,
63,
2087,
9,
272,
1249,
275,
21206,
63,
2087,
14,
1122,
63,
589,
342,
339,
870,
480,
1513,
23127,
30611,
3746,
60,
46,
91,
13954,
1093,
8132,
5056,
93,
2032,
2685,
272,
2446,
8,
267,
18908,
63,
344,
63,
1001,
76,
29,
589,
14,
18945,
63,
344,
63,
1001,
76,
12,
267,
2928,
63,
2424,
29,
589,
14,
2164,
63,
2424,
12,
267,
2984,
63,
2424,
29,
589,
14,
1121,
63,
2424,
12,
267,
302,
7010,
63,
2424,
29,
589,
14,
4994,
597,
63,
2424,
12,
267,
302,
7010,
29,
589,
14,
4994,
597,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
deathcap/Burger
|
solum/compat.py
|
2
|
6211
|
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""
Copyright (c) 2010-2011 Tyler Kennedy <tk@tkte.ch>
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.
"""
__all__ = [
"namedtuple"
]
from operator import itemgetter as _itemgetter
from keyword import iskeyword as _iskeyword
import sys as _sys
def namedtuple(typename, field_names, verbose=False, rename=False):
"""Returns a new subclass of tuple with named fields.
>>> Point = namedtuple('Point', 'x y')
>>> Point.__doc__ # docstring for the new class
'Point(x, y)'
>>> p = Point(11, y=22) # instantiate with positional args or keywords
>>> p[0] + p[1] # indexable like a plain tuple
33
>>> x, y = p # unpack like a regular tuple
>>> x, y
(11, 22)
>>> p.x + p.y # fields also accessable by name
33
>>> d = p._asdict() # convert to a dictionary
>>> d['x']
11
>>> Point(**d) # convert from a dictionary
Point(x=11, y=22)
>>> p._replace(x=100) # _replace() is like str.replace() but targets named fields
Point(x=100, y=22)
"""
# Parse and validate the field names. Validation serves two purposes,
# generating informative error messages and preventing template injection attacks.
if isinstance(field_names, basestring):
field_names = field_names.replace(',', ' ').split() # names separated by whitespace and/or commas
field_names = tuple(map(str, field_names))
if rename:
names = list(field_names)
seen = set()
for i, name in enumerate(names):
if (not min(c.isalnum() or c=='_' for c in name) or _iskeyword(name)
or not name or name[0].isdigit() or name.startswith('_')
or name in seen):
names[i] = '_%d' % i
seen.add(name)
field_names = tuple(names)
for name in (typename,) + field_names:
if not min(c.isalnum() or c=='_' for c in name):
raise ValueError('Type names and field names can only contain alphanumeric characters and underscores: %r' % name)
if _iskeyword(name):
raise ValueError('Type names and field names cannot be a keyword: %r' % name)
if name[0].isdigit():
raise ValueError('Type names and field names cannot start with a number: %r' % name)
seen_names = set()
for name in field_names:
if name.startswith('_') and not rename:
raise ValueError('Field names cannot start with an underscore: %r' % name)
if name in seen_names:
raise ValueError('Encountered duplicate field name: %r' % name)
seen_names.add(name)
# Create and fill-in the class template
numfields = len(field_names)
argtxt = repr(field_names).replace("'", "")[1:-1] # tuple repr without parens or quotes
reprtxt = ', '.join('%s=%%r' % name for name in field_names)
template = '''class %(typename)s(tuple):
'%(typename)s(%(argtxt)s)' \n
__slots__ = () \n
_fields = %(field_names)r \n
def __new__(_cls, %(argtxt)s):
return _tuple.__new__(_cls, (%(argtxt)s)) \n
@classmethod
def _make(cls, iterable, new=tuple.__new__, len=len):
'Make a new %(typename)s object from a sequence or iterable'
result = new(cls, iterable)
if len(result) != %(numfields)d:
raise TypeError('Expected %(numfields)d arguments, got %%d' %% len(result))
return result \n
def __repr__(self):
return '%(typename)s(%(reprtxt)s)' %% self \n
def _asdict(self):
'Return a new dict which maps field names to their values'
return dict(zip(self._fields, self)) \n
def _replace(_self, **kwds):
'Return a new %(typename)s object replacing specified fields with new values'
result = _self._make(map(kwds.pop, %(field_names)r, _self))
if kwds:
raise ValueError('Got unexpected field names: %%r' %% kwds.keys())
return result \n
def __getnewargs__(self):
return tuple(self) \n\n''' % locals()
for i, name in enumerate(field_names):
template += ' %s = _property(_itemgetter(%d))\n' % (name, i)
if verbose:
print template
# Execute the template string in a temporary namespace
namespace = dict(_itemgetter=_itemgetter, __name__='namedtuple_%s' % typename,
_property=property, _tuple=tuple)
try:
exec template in namespace
except SyntaxError, e:
raise SyntaxError(e.message + ':\n' + template)
result = namespace[typename]
# For pickling to work, the __module__ variable needs to be set to the frame
# where the named tuple is created. Bypass this step in enviroments where
# sys._getframe is not defined (Jython for example) or sys._getframe is not
# defined for arguments greater than 0 (IronPython).
try:
result.__module__ = _sys._getframe(1).f_globals.get('__name__', '__main__')
except (AttributeError, ValueError):
pass
return result
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
24,
1882,
199,
624,
199,
7384,
334,
67,
9,
7129,
13,
8128,
377,
89,
1435,
1804,
287,
7439,
89,
665,
2663,
32,
2663,
266,
14,
335,
30,
199,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
452,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
18061,
4141,
14,
199,
624,
199,
363,
452,
363,
275,
359,
272,
298,
18921,
2,
199,
61,
199,
199,
504,
4182,
492,
1242,
7416,
465,
485,
20832,
199,
504,
4252,
492,
365,
6691,
465,
485,
374,
6691,
199,
646,
984,
465,
485,
1274,
199,
199,
318,
12863,
8,
18596,
12,
901,
63,
1247,
12,
3376,
29,
797,
12,
11441,
29,
797,
304,
272,
408,
3407,
282,
892,
5516,
402,
2008,
543,
4310,
1504,
14,
339,
1306,
7584,
275,
12863,
360,
3428,
297,
283,
88,
612,
358,
272,
1306,
7584,
855,
1301,
363,
7861,
327,
9214,
367,
314,
892,
1021,
272,
283,
3428,
8,
88,
12,
612,
3171,
272,
1306,
299,
275,
7584,
8,
845,
12,
612,
29,
1081,
9,
3777,
327,
17321,
543,
11333,
1249,
503,
7681,
272,
1306,
299,
59,
16,
61,
435,
299,
59,
17,
61,
9326,
327,
1478,
461,
2839,
282,
8971,
2008,
272,
9404,
272,
1306,
671,
12,
612,
275,
299,
12788,
327,
7787,
2839,
282,
5578,
2008,
272,
1306,
671,
12,
612,
272,
334,
845,
12,
6928,
9,
272,
1306,
299,
14,
88,
435,
299,
14,
89,
9668,
327,
1504,
2597,
2879,
461,
701,
536,
272,
9404,
272,
1306,
366,
275,
299,
423,
305,
807,
342,
463,
327,
3957,
370,
282,
2600,
272,
1306,
366,
459,
88,
418,
272,
4119,
272,
1306,
7584,
3682,
68,
9,
10473,
327,
3957,
687,
282,
2600,
272,
7584,
8,
88,
29,
845,
12,
612,
29,
1081,
9,
272,
1306,
299,
423,
1814,
8,
88,
29,
1960,
9,
5185,
327,
485,
1814,
342,
365,
2839,
620,
14,
1814,
342,
1325,
4545,
4310,
1504,
272,
7584,
8,
88,
29,
1960,
12,
612,
29,
1081,
9,
339,
408,
339,
327,
6077,
436,
4107,
314,
901,
1561,
14,
221,
19381,
23739,
2877,
12901,
12,
272,
327,
12999,
315,
20889,
1125,
3788,
436,
7981,
316,
1978,
315,
8923,
28140,
14,
272,
340,
1228,
8,
698,
63,
1247,
12,
7116,
304,
267,
901,
63,
1247,
275,
901,
63,
1247,
14,
1814,
32718,
283,
27274,
1294,
342,
327,
1561,
11673,
701,
8139,
436,
15,
269,
24476,
272,
901,
63,
1247,
275,
2008,
8,
1130,
8,
495,
12,
901,
63,
1247,
430,
272,
340,
11441,
26,
267,
1561,
275,
769,
8,
698,
63,
1247,
9,
267,
6775,
275,
663,
342,
267,
367,
284,
12,
536,
315,
3874,
8,
1247,
304,
288,
340,
334,
1397,
1748,
8,
67,
14,
28235,
1507,
342,
503,
286,
6803,
8650,
367,
286,
315,
536,
9,
503,
485,
374,
6691,
8,
354,
9,
355,
503,
440,
536,
503,
536,
59,
16,
1055,
13896,
342,
503,
536,
14,
2460,
26341,
355,
503,
536,
315,
6775,
304,
490,
1561,
59,
73,
61,
275,
2513,
5,
68,
7,
450,
284,
288,
6775,
14,
525,
8,
354,
9,
267,
901,
63,
1247,
275,
2008,
8,
1247,
9,
272,
367,
536,
315,
334,
18596,
4258,
435,
901,
63,
1247,
26,
267,
340,
440,
1748,
8,
67,
14,
28235,
1507,
342,
503,
286,
6803,
8650,
367,
286,
315,
536,
304,
288,
746,
1722,
360,
804,
1561,
436,
901,
1561,
883,
1454,
1395,
27964,
4110,
436,
23998,
26,
450,
82,
7,
450,
536,
9,
267,
340,
485,
374,
6691,
8,
354,
304,
288,
746,
1722,
360,
804,
1561,
436,
901,
1561,
3913,
506,
282,
4252,
26,
450,
82,
7,
450,
536,
9,
267,
340,
536,
59,
16,
1055,
13896,
837,
288,
746,
1722,
360,
804,
1561,
436,
901,
1561,
3913,
1343,
543,
282,
1329,
26,
450,
82,
7,
450,
536,
9,
272,
6775,
63,
1247,
275,
663,
342,
272,
367,
536,
315,
901,
63,
1247,
26,
267,
340,
536,
14,
2460,
26341,
436,
440,
11441,
26,
288,
746,
1722,
360,
792,
1561,
3913,
1343,
543,
376,
18888,
26,
450,
82,
7,
450,
536,
9,
267,
340,
536,
315,
6775,
63,
1247,
26,
288,
746,
1722,
360,
1327,
12613,
9250,
901,
536,
26,
450,
82,
7,
450,
536,
9,
267,
6775,
63,
1247,
14,
525,
8,
354,
9,
339,
327,
2790,
436,
5554,
13,
262,
314,
1021,
1978,
272,
1967,
955,
275,
822,
8,
698,
63,
1247,
9,
272,
1680,
2424,
275,
4700,
8,
698,
63,
1247,
680,
1814,
27769,
6899,
59,
17,
6809,
17,
61,
257,
327,
2008,
4700,
1928,
32029,
503,
9344,
272,
4700,
2424,
275,
1656,
1987,
904,
3508,
83,
2458,
5,
82,
7,
450,
536,
367,
536,
315,
901,
63,
1247,
9,
272,
1978,
275,
1449,
533,
2818,
18596,
9,
83,
8,
2960,
304,
267,
9487,
18596,
9,
83,
12473,
1273,
2424,
9,
83,
3171,
971,
78,
267,
636,
7257,
363,
275,
6248,
971,
78,
267,
485,
955,
275,
2818,
698,
63,
1247,
9,
82,
971,
78,
267,
347,
636,
1222,
721,
63,
1886,
12,
2818,
1273,
2424
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
24,
1882,
199,
624,
199,
7384,
334,
67,
9,
7129,
13,
8128,
377,
89,
1435,
1804,
287,
7439,
89,
665,
2663,
32,
2663,
266,
14,
335,
30,
199,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
452,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
18061,
4141,
14,
199,
624,
199,
363,
452,
363,
275,
359,
272,
298,
18921,
2,
199,
61,
199,
199,
504,
4182,
492,
1242,
7416,
465,
485,
20832,
199,
504,
4252,
492,
365,
6691,
465,
485,
374,
6691,
199,
646,
984,
465,
485,
1274,
199,
199,
318,
12863,
8,
18596,
12,
901,
63,
1247,
12,
3376,
29,
797,
12,
11441,
29,
797,
304,
272,
408,
3407,
282,
892,
5516,
402,
2008,
543,
4310,
1504,
14,
339,
1306,
7584,
275,
12863,
360,
3428,
297,
283,
88,
612,
358,
272,
1306,
7584,
855,
1301,
363,
7861,
327,
9214,
367,
314,
892,
1021,
272,
283,
3428,
8,
88,
12,
612,
3171,
272,
1306,
299,
275,
7584,
8,
845,
12,
612,
29,
1081,
9,
3777,
327,
17321,
543,
11333,
1249,
503,
7681,
272,
1306,
299,
59,
16,
61,
435,
299,
59,
17,
61,
9326,
327,
1478,
461,
2839,
282,
8971,
2008,
272,
9404,
272,
1306,
671,
12,
612,
275,
299,
12788,
327,
7787,
2839,
282,
5578,
2008,
272,
1306,
671,
12,
612,
272,
334,
845,
12,
6928,
9,
272,
1306,
299,
14,
88,
435,
299,
14,
89,
9668,
327,
1504,
2597,
2879,
461,
701,
536,
272,
9404,
272,
1306,
366,
275,
299,
423,
305,
807,
342,
463,
327,
3957,
370,
282,
2600,
272,
1306,
366,
459,
88,
418,
272,
4119,
272,
1306,
7584,
3682,
68,
9,
10473,
327,
3957,
687,
282,
2600,
272,
7584,
8,
88,
29,
845,
12,
612,
29,
1081,
9,
272,
1306,
299,
423,
1814,
8,
88,
29,
1960,
9,
5185,
327,
485,
1814,
342,
365,
2839,
620,
14,
1814,
342,
1325,
4545,
4310,
1504,
272,
7584,
8,
88,
29,
1960,
12,
612,
29,
1081,
9,
339,
408,
339,
327,
6077,
436,
4107,
314,
901,
1561,
14,
221,
19381,
23739,
2877,
12901,
12,
272,
327,
12999,
315,
20889,
1125,
3788,
436,
7981,
316,
1978,
315,
8923,
28140,
14,
272,
340,
1228,
8,
698,
63,
1247,
12,
7116,
304,
267,
901,
63,
1247,
275,
901,
63,
1247,
14,
1814,
32718,
283,
27274,
1294,
342,
327,
1561,
11673,
701,
8139,
436,
15,
269,
24476,
272,
901,
63,
1247,
275,
2008,
8,
1130,
8,
495,
12,
901,
63,
1247,
430,
272,
340,
11441,
26,
267,
1561,
275,
769,
8,
698,
63,
1247,
9,
267,
6775,
275,
663,
342,
267,
367,
284,
12,
536,
315,
3874,
8,
1247,
304,
288,
340,
334,
1397,
1748,
8,
67,
14,
28235,
1507,
342,
503,
286,
6803,
8650,
367,
286,
315,
536,
9,
503,
485,
374,
6691,
8,
354,
9,
355,
503,
440,
536,
503,
536,
59,
16,
1055,
13896,
342,
503,
536,
14,
2460,
26341,
355,
503,
536,
315,
6775,
304,
490,
1561,
59,
73,
61,
275,
2513,
5,
68,
7,
450,
284,
288,
6775,
14,
525,
8,
354,
9,
267,
901,
63,
1247,
275,
2008,
8,
1247,
9,
272,
367,
536,
315,
334,
18596,
4258,
435,
901,
63,
1247,
26,
267,
340,
440,
1748,
8,
67,
14,
28235,
1507,
342,
503,
286,
6803,
8650,
367,
286,
315,
536,
304,
288,
746,
1722,
360,
804,
1561,
436,
901,
1561,
883,
1454,
1395,
27964,
4110,
436,
23998,
26,
450,
82,
7,
450,
536,
9,
267,
340,
485,
374,
6691,
8,
354,
304,
288,
746,
1722,
360,
804,
1561,
436,
901,
1561,
3913,
506,
282,
4252,
26,
450,
82,
7,
450,
536,
9,
267,
340,
536,
59,
16,
1055,
13896,
837,
288,
746,
1722,
360,
804,
1561,
436,
901,
1561,
3913,
1343,
543,
282,
1329,
26,
450,
82,
7,
450,
536,
9,
272,
6775,
63,
1247,
275,
663,
342,
272,
367,
536,
315,
901,
63,
1247,
26,
267,
340,
536,
14,
2460,
26341,
436,
440,
11441,
26,
288,
746,
1722,
360,
792,
1561,
3913,
1343,
543,
376,
18888,
26,
450,
82,
7,
450,
536,
9,
267,
340,
536,
315,
6775,
63,
1247,
26,
288,
746,
1722,
360,
1327,
12613,
9250,
901,
536,
26,
450,
82,
7,
450,
536,
9,
267,
6775,
63,
1247,
14,
525,
8,
354,
9,
339,
327,
2790,
436,
5554,
13,
262,
314,
1021,
1978,
272,
1967,
955,
275,
822,
8,
698,
63,
1247,
9,
272,
1680,
2424,
275,
4700,
8,
698,
63,
1247,
680,
1814,
27769,
6899,
59,
17,
6809,
17,
61,
257,
327,
2008,
4700,
1928,
32029,
503,
9344,
272,
4700,
2424,
275,
1656,
1987,
904,
3508,
83,
2458,
5,
82,
7,
450,
536,
367,
536,
315,
901,
63,
1247,
9,
272,
1978,
275,
1449,
533,
2818,
18596,
9,
83,
8,
2960,
304,
267,
9487,
18596,
9,
83,
12473,
1273,
2424,
9,
83,
3171,
971,
78,
267,
636,
7257,
363,
275,
6248,
971,
78,
267,
485,
955,
275,
2818,
698,
63,
1247,
9,
82,
971,
78,
267,
347,
636,
1222,
721,
63,
1886,
12,
2818,
1273,
2424,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nashgul/weechat
|
audacious_script/audacious.py
|
1
|
3067
|
# audacious now playing for weechat
# nashgul <m.alcocer1978@gmail.com>
# version 0.1
# white => "00", black => "01", darkblue => "02", darkgreen => "03", lightred => "04", darkred => "05", magenta => "06", orange => "07", yellow => "08", lightgreen => "09", cyan => "10", lightcyan => "11", lightblue => "12", lightmagenta => "13", gray => "14", lightgray => "15"
import weechat
import subprocess
weechat.register("audacious_np", "nashgul", "0.01", "GPL2", "now playing for audacious (usage: /audacious)", "", "")
name = 'audacious'
description = 'show now playing for audacious'
hook = weechat.hook_command(name, description, '', '', '', 'now_playing', '')
def get_info_array():
info_list = (['audtool current-song',
'audtool current-song-length',
'audtool current-song-output-length',
'audtool current-song-bitrate-kbps',
'audtool current-song-filename'])
results = []
for x in info_list:
temporal = subprocess.Popen(x, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
b = temporal.stdout.read().splitlines()
results.append(b[0])
return results
def now_playing(datos, channel, args):
colors = {
'white' : '00', 'black' : '01', 'darkblue' : '02', 'darkgreen' : '03',
'lightred' : '04', 'darkred' : '05', 'magenta' : '06', 'orange' : '07',
'yellow' : '08', 'lightgreen' : '09', 'cyan' : '10', 'lightcyan' : '11',
'lightblue' : '12', 'lightmagenta' : '13', 'gray' : '14', 'lightgray' : '15'
}
info_array = get_info_array()
message_color = "%s" % colors['darkblue']
message = u'\x03' + message_color + 'esta reproduciendo' + u'\x0f'
song_color = "%s" % colors['lightred']
song = u'\x03' + song_color + info_array[0] + u'\x0f'
song_filename_color = "%s" % colors['lightred']
song_filename = u'\x03' + song_filename_color + info_array[4] + u'\x0f'
brackets_color = "%s" % colors['yellow']
bracket_1 = u'\x03' + brackets_color + '[' + u'\x0f'
bracket_2 = u'\x03' + brackets_color + ']' + u'\x0f'
hyphen_color = "%s" % colors['yellow']
hyphen = u'\x03' + hyphen_color + ' - ' + u'\x0f'
at_color = "%s" % colors['yellow']
at_sym = u'\x03' + at_color + '@' + u'\x0f'
output_length_color = "%s" % colors['lightblue']
output_length = u'\x03' + output_length_color + info_array[2] + u'\x0f'
length = ''
if info_array[1] != '0:00':
length_color = "%s" % colors['lightblue']
length = u'\x03' + length_color + hyphen + ' ' + info_array[1] + ' ' + u'\x0f'
bitrate_color = "%s" % colors['lightmagenta']
bitrate = u'\x03' + bitrate_color + info_array[3] + ' kbps' + u'\x0f'
string = "%s %s %s%s %s %s" %(bracket_1, output_length, length, at_sym, bitrate, bracket_2)
source = ''
if song_filename.lower().startswith('http'):
source = song_filename
output_string = "%s: %s %s %s" %(message, source, song, string)
weechat.command(channel, "/me %s" % (output_string))
return weechat.WEECHAT_RC_OK
|
gpl-2.0
|
[
3,
282,
6727,
559,
1785,
3063,
25692,
367,
781,
69,
10289,
199,
3,
302,
1119,
71,
348,
665,
77,
14,
279,
331,
2247,
1167,
2277,
32,
6799,
14,
957,
30,
199,
3,
1015,
378,
14,
17,
199,
199,
3,
10424,
9265,
298,
383,
401,
12136,
9265,
298,
614,
401,
23531,
6304,
9265,
298,
996,
401,
23531,
7731,
9265,
298,
1644,
401,
10540,
581,
9265,
298,
966,
401,
23531,
581,
9265,
298,
1717,
401,
8127,
21335,
9265,
298,
1690,
401,
29713,
9265,
298,
1780,
401,
31194,
9265,
298,
2036,
401,
10540,
7731,
9265,
298,
1643,
401,
6325,
290,
9265,
298,
709,
401,
10540,
28291,
9265,
298,
845,
401,
10540,
6304,
9265,
298,
713,
401,
10540,
5615,
21335,
9265,
298,
969,
401,
21977,
9265,
298,
1079,
401,
10540,
12150,
9265,
298,
1046,
2,
199,
199,
646,
781,
69,
10289,
199,
646,
3873,
199,
199,
25515,
10289,
14,
2683,
480,
3844,
983,
559,
1785,
63,
1590,
401,
298,
78,
1119,
71,
348,
401,
298,
16,
14,
614,
401,
298,
12006,
18,
401,
298,
2131,
25692,
367,
282,
6727,
559,
1785,
334,
3807,
26,
1182,
3844,
983,
559,
1785,
4186,
4873,
6899,
199,
199,
354,
275,
283,
3844,
983,
559,
1785,
7,
199,
1802,
275,
283,
2384,
3063,
25692,
367,
282,
6727,
559,
1785,
7,
199,
3664,
275,
781,
69,
10289,
14,
3664,
63,
1531,
8,
354,
12,
1369,
12,
3260,
3260,
3260,
283,
2131,
63,
22224,
297,
4074,
199,
199,
318,
664,
63,
815,
63,
1144,
837,
272,
2256,
63,
513,
275,
21022,
32024,
3557,
1453,
13,
19351,
297,
267,
283,
32024,
3557,
1453,
13,
19351,
13,
1267,
297,
267,
283,
32024,
3557,
1453,
13,
19351,
13,
1199,
13,
1267,
297,
267,
283,
32024,
3557,
1453,
13,
19351,
13,
24484,
13,
7862,
1190,
297,
267,
283,
32024,
3557,
1453,
13,
19351,
13,
1501,
1105,
272,
2058,
275,
942,
272,
367,
671,
315,
2256,
63,
513,
26,
267,
16457,
279,
275,
3873,
14,
7942,
8,
88,
12,
5218,
29,
549,
12,
3839,
29,
5781,
14,
6089,
12,
4635,
29,
5781,
14,
13850,
9,
267,
330,
275,
16457,
279,
14,
2703,
14,
739,
1252,
7644,
342,
267,
2058,
14,
740,
8,
66,
59,
16,
566,
272,
372,
2058,
199,
199,
318,
3063,
63,
22224,
8,
4616,
736,
12,
3623,
12,
1249,
304,
272,
9229,
275,
469,
288,
283,
7510,
7,
520,
283,
383,
297,
283,
8399,
7,
520,
283,
614,
297,
283,
13625,
6304,
7,
520,
283,
996,
297,
283,
13625,
7731,
7,
520,
283,
1644,
297,
288,
283,
4040,
581,
7,
520,
283,
966,
297,
283,
13625,
581,
7,
520,
283,
1717,
297,
283,
5615,
21335,
7,
520,
283,
1690,
297,
283,
22683,
7,
520,
283,
1780,
297,
288,
283,
14514,
7,
520,
283,
2036,
297,
283,
4040,
7731,
7,
520,
283,
1643,
297,
283,
28291,
7,
520,
283,
709,
297,
283,
4040,
28291,
7,
520,
283,
845,
297,
288,
283,
4040,
6304,
7,
520,
283,
713,
297,
283,
4040,
5615,
21335,
7,
520,
283,
969,
297,
283,
12150,
7,
520,
283,
1079,
297,
283,
4040,
12150,
7,
520,
283,
1046,
7,
288,
789,
2286,
2256,
63,
1144,
275,
664,
63,
815,
63,
1144,
342,
272,
1245,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
13625,
6304,
418,
272,
1245,
275,
399,
1154,
88,
1644,
7,
435,
1245,
63,
2326,
435,
283,
597,
65,
295,
496,
2033,
559,
500,
79,
7,
435,
399,
1154,
88,
16,
70,
7,
272,
20178,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
4040,
581,
418,
272,
20178,
275,
399,
1154,
88,
1644,
7,
435,
20178,
63,
2326,
435,
2256,
63,
1144,
59,
16,
61,
435,
399,
1154,
88,
16,
70,
7,
272,
20178,
63,
1501,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
4040,
581,
418,
272,
20178,
63,
1501,
275,
399,
1154,
88,
1644,
7,
435,
20178,
63,
1501,
63,
2326,
435,
2256,
63,
1144,
59,
20,
61,
435,
399,
1154,
88,
16,
70,
7,
272,
21873,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
14514,
418,
272,
14540,
63,
17,
275,
399,
1154,
88,
1644,
7,
435,
21873,
63,
2326,
435,
22640,
435,
399,
1154,
88,
16,
70,
7,
5591,
14540,
63,
18,
275,
399,
1154,
88,
1644,
7,
435,
21873,
63,
2326,
435,
24840,
435,
399,
1154,
88,
16,
70,
7,
272,
7188,
17579,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
14514,
418,
272,
7188,
17579,
275,
399,
1154,
88,
1644,
7,
435,
7188,
17579,
63,
2326,
435,
283,
446,
283,
435,
399,
1154,
88,
16,
70,
7,
272,
737,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
14514,
418,
272,
737,
63,
3840,
275,
399,
1154,
88,
1644,
7,
435,
737,
63,
2326,
435,
22143,
435,
399,
1154,
88,
16,
70,
7,
272,
1072,
63,
1267,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
4040,
6304,
418,
272,
1072,
63,
1267,
275,
399,
1154,
88,
1644,
7,
435,
1072,
63,
1267,
63,
2326,
435,
2256,
63,
1144,
59,
18,
61,
435,
399,
1154,
88,
16,
70,
7,
272,
2582,
275,
2125,
272,
340,
2256,
63,
1144,
59,
17,
61,
1137,
283,
16,
26,
383,
356,
267,
2582,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
4040,
6304,
418,
267,
2582,
275,
399,
1154,
88,
1644,
7,
435,
2582,
63,
2326,
435,
7188,
17579,
435,
283,
283,
435,
2256,
63,
1144,
59,
17,
61,
435,
283,
283,
435,
399,
1154,
88,
16,
70,
7,
272,
4546,
1866,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
4040,
5615,
21335,
418,
272,
4546,
1866,
275,
399,
1154,
88,
1644,
7,
435,
4546,
1866,
63,
2326,
435,
2256,
63,
1144,
59,
19,
61,
435,
283,
19932,
1190,
7,
435,
399,
1154,
88,
16,
70,
7,
272,
1059,
275,
2071,
83,
450,
83,
450,
83,
5,
83,
450,
83,
450,
83,
2,
2818,
14594,
63,
17,
12,
1072,
63,
1267,
12,
2582,
12,
737,
63,
3840,
12,
4546,
1866,
12,
14540,
63,
18,
9,
272,
1350,
275,
2125,
272,
340,
20178,
63,
1501,
14,
2325,
1252,
2460,
360,
1014,
735,
267,
1350,
275,
20178,
63,
1501,
5591,
1072,
63,
875,
275,
2071,
83,
26,
450,
83,
450,
83,
450,
83,
2,
2818,
1188
] |
[
282,
6727,
559,
1785,
3063,
25692,
367,
781,
69,
10289,
199,
3,
302,
1119,
71,
348,
665,
77,
14,
279,
331,
2247,
1167,
2277,
32,
6799,
14,
957,
30,
199,
3,
1015,
378,
14,
17,
199,
199,
3,
10424,
9265,
298,
383,
401,
12136,
9265,
298,
614,
401,
23531,
6304,
9265,
298,
996,
401,
23531,
7731,
9265,
298,
1644,
401,
10540,
581,
9265,
298,
966,
401,
23531,
581,
9265,
298,
1717,
401,
8127,
21335,
9265,
298,
1690,
401,
29713,
9265,
298,
1780,
401,
31194,
9265,
298,
2036,
401,
10540,
7731,
9265,
298,
1643,
401,
6325,
290,
9265,
298,
709,
401,
10540,
28291,
9265,
298,
845,
401,
10540,
6304,
9265,
298,
713,
401,
10540,
5615,
21335,
9265,
298,
969,
401,
21977,
9265,
298,
1079,
401,
10540,
12150,
9265,
298,
1046,
2,
199,
199,
646,
781,
69,
10289,
199,
646,
3873,
199,
199,
25515,
10289,
14,
2683,
480,
3844,
983,
559,
1785,
63,
1590,
401,
298,
78,
1119,
71,
348,
401,
298,
16,
14,
614,
401,
298,
12006,
18,
401,
298,
2131,
25692,
367,
282,
6727,
559,
1785,
334,
3807,
26,
1182,
3844,
983,
559,
1785,
4186,
4873,
6899,
199,
199,
354,
275,
283,
3844,
983,
559,
1785,
7,
199,
1802,
275,
283,
2384,
3063,
25692,
367,
282,
6727,
559,
1785,
7,
199,
3664,
275,
781,
69,
10289,
14,
3664,
63,
1531,
8,
354,
12,
1369,
12,
3260,
3260,
3260,
283,
2131,
63,
22224,
297,
4074,
199,
199,
318,
664,
63,
815,
63,
1144,
837,
272,
2256,
63,
513,
275,
21022,
32024,
3557,
1453,
13,
19351,
297,
267,
283,
32024,
3557,
1453,
13,
19351,
13,
1267,
297,
267,
283,
32024,
3557,
1453,
13,
19351,
13,
1199,
13,
1267,
297,
267,
283,
32024,
3557,
1453,
13,
19351,
13,
24484,
13,
7862,
1190,
297,
267,
283,
32024,
3557,
1453,
13,
19351,
13,
1501,
1105,
272,
2058,
275,
942,
272,
367,
671,
315,
2256,
63,
513,
26,
267,
16457,
279,
275,
3873,
14,
7942,
8,
88,
12,
5218,
29,
549,
12,
3839,
29,
5781,
14,
6089,
12,
4635,
29,
5781,
14,
13850,
9,
267,
330,
275,
16457,
279,
14,
2703,
14,
739,
1252,
7644,
342,
267,
2058,
14,
740,
8,
66,
59,
16,
566,
272,
372,
2058,
199,
199,
318,
3063,
63,
22224,
8,
4616,
736,
12,
3623,
12,
1249,
304,
272,
9229,
275,
469,
288,
283,
7510,
7,
520,
283,
383,
297,
283,
8399,
7,
520,
283,
614,
297,
283,
13625,
6304,
7,
520,
283,
996,
297,
283,
13625,
7731,
7,
520,
283,
1644,
297,
288,
283,
4040,
581,
7,
520,
283,
966,
297,
283,
13625,
581,
7,
520,
283,
1717,
297,
283,
5615,
21335,
7,
520,
283,
1690,
297,
283,
22683,
7,
520,
283,
1780,
297,
288,
283,
14514,
7,
520,
283,
2036,
297,
283,
4040,
7731,
7,
520,
283,
1643,
297,
283,
28291,
7,
520,
283,
709,
297,
283,
4040,
28291,
7,
520,
283,
845,
297,
288,
283,
4040,
6304,
7,
520,
283,
713,
297,
283,
4040,
5615,
21335,
7,
520,
283,
969,
297,
283,
12150,
7,
520,
283,
1079,
297,
283,
4040,
12150,
7,
520,
283,
1046,
7,
288,
789,
2286,
2256,
63,
1144,
275,
664,
63,
815,
63,
1144,
342,
272,
1245,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
13625,
6304,
418,
272,
1245,
275,
399,
1154,
88,
1644,
7,
435,
1245,
63,
2326,
435,
283,
597,
65,
295,
496,
2033,
559,
500,
79,
7,
435,
399,
1154,
88,
16,
70,
7,
272,
20178,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
4040,
581,
418,
272,
20178,
275,
399,
1154,
88,
1644,
7,
435,
20178,
63,
2326,
435,
2256,
63,
1144,
59,
16,
61,
435,
399,
1154,
88,
16,
70,
7,
272,
20178,
63,
1501,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
4040,
581,
418,
272,
20178,
63,
1501,
275,
399,
1154,
88,
1644,
7,
435,
20178,
63,
1501,
63,
2326,
435,
2256,
63,
1144,
59,
20,
61,
435,
399,
1154,
88,
16,
70,
7,
272,
21873,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
14514,
418,
272,
14540,
63,
17,
275,
399,
1154,
88,
1644,
7,
435,
21873,
63,
2326,
435,
22640,
435,
399,
1154,
88,
16,
70,
7,
5591,
14540,
63,
18,
275,
399,
1154,
88,
1644,
7,
435,
21873,
63,
2326,
435,
24840,
435,
399,
1154,
88,
16,
70,
7,
272,
7188,
17579,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
14514,
418,
272,
7188,
17579,
275,
399,
1154,
88,
1644,
7,
435,
7188,
17579,
63,
2326,
435,
283,
446,
283,
435,
399,
1154,
88,
16,
70,
7,
272,
737,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
14514,
418,
272,
737,
63,
3840,
275,
399,
1154,
88,
1644,
7,
435,
737,
63,
2326,
435,
22143,
435,
399,
1154,
88,
16,
70,
7,
272,
1072,
63,
1267,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
4040,
6304,
418,
272,
1072,
63,
1267,
275,
399,
1154,
88,
1644,
7,
435,
1072,
63,
1267,
63,
2326,
435,
2256,
63,
1144,
59,
18,
61,
435,
399,
1154,
88,
16,
70,
7,
272,
2582,
275,
2125,
272,
340,
2256,
63,
1144,
59,
17,
61,
1137,
283,
16,
26,
383,
356,
267,
2582,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
4040,
6304,
418,
267,
2582,
275,
399,
1154,
88,
1644,
7,
435,
2582,
63,
2326,
435,
7188,
17579,
435,
283,
283,
435,
2256,
63,
1144,
59,
17,
61,
435,
283,
283,
435,
399,
1154,
88,
16,
70,
7,
272,
4546,
1866,
63,
2326,
275,
2071,
83,
2,
450,
9229,
459,
4040,
5615,
21335,
418,
272,
4546,
1866,
275,
399,
1154,
88,
1644,
7,
435,
4546,
1866,
63,
2326,
435,
2256,
63,
1144,
59,
19,
61,
435,
283,
19932,
1190,
7,
435,
399,
1154,
88,
16,
70,
7,
272,
1059,
275,
2071,
83,
450,
83,
450,
83,
5,
83,
450,
83,
450,
83,
2,
2818,
14594,
63,
17,
12,
1072,
63,
1267,
12,
2582,
12,
737,
63,
3840,
12,
4546,
1866,
12,
14540,
63,
18,
9,
272,
1350,
275,
2125,
272,
340,
20178,
63,
1501,
14,
2325,
1252,
2460,
360,
1014,
735,
267,
1350,
275,
20178,
63,
1501,
5591,
1072,
63,
875,
275,
2071,
83,
26,
450,
83,
450,
83,
450,
83,
2,
2818,
1188,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
gonboy/sl4a
|
python/src/Lib/plat-mac/icopen.py
|
73
|
2068
|
"""icopen patch
OVERVIEW
icopen patches MacOS Python to use the Internet Config file mappings to select
the type and creator for a file.
Version 1 released to the public domain 3 November 1999
by Oliver Steele (steele@cs.brandeis.edu).
DETAILS
This patch causes files created by Python's open(filename, 'w') command (and
by functions and scripts that call it) to set the type and creator of the file
to the type and creator associated with filename's extension (the
portion of the filename after the last period), according to Internet Config.
Thus, a script that creates a file foo.html will create one that opens in whatever
browser you've set to handle *.html files, and so on.
Python IDE uses its own algorithm to select the type and creator for saved
editor windows, so this patch won't effect their types.
As of System 8.6 at least, Internet Config is built into the system, and the
file mappings are accessed from the Advanced pane of the Internet control
panel. User Mode (in the Edit menu) needs to be set to Advanced in order to
access this pane.
INSTALLATION
Put this file in your Python path, and create a file named {Python}:sitecustomize.py
that contains:
import icopen
(If {Python}:sitecustomizer.py already exists, just add the 'import' line to it.)
The next time you launch PythonInterpreter or Python IDE, the patch will take
effect.
"""
from warnings import warnpy3k
warnpy3k("In 3.x, the icopen module is removed.", stacklevel=2)
import __builtin__
_builtin_open = globals().get('_builtin_open', __builtin__.open)
def _open_with_typer(*args):
file = _builtin_open(*args)
filename = args[0]
mode = 'r'
if args[1:]:
mode = args[1]
if mode[0] == 'w':
from ic import error, settypecreator
try:
settypecreator(filename)
except error:
pass
return file
__builtin__.open = _open_with_typer
"""
open('test.py')
_open_with_typer('test.py', 'w')
_open_with_typer('test.txt', 'w')
_open_with_typer('test.html', 'w')
_open_with_typer('test.foo', 'w')
"""
|
apache-2.0
|
[
624,
12802,
897,
3371,
199,
199,
14336,
12058,
199,
199,
12802,
897,
12385,
10444,
3100,
2018,
370,
675,
314,
22026,
4094,
570,
13546,
370,
3504,
199,
1589,
730,
436,
14875,
367,
282,
570,
14,
199,
199,
3353,
413,
14286,
370,
314,
4575,
2881,
650,
3091,
432,
976,
21300,
199,
991,
593,
317,
422,
17854,
8081,
334,
1597,
8081,
32,
1259,
14,
66,
1312,
271,
374,
14,
8654,
680,
199,
199,
25081,
51,
199,
199,
2765,
3371,
14486,
1584,
2737,
701,
2018,
1159,
1551,
8,
1501,
12,
283,
87,
358,
1414,
334,
460,
199,
991,
3423,
436,
10554,
626,
1240,
652,
9,
370,
663,
314,
730,
436,
14875,
402,
314,
570,
199,
475,
314,
730,
436,
14875,
4568,
543,
1788,
1159,
3329,
334,
1589,
199,
7314,
296,
402,
314,
1788,
2410,
314,
2061,
6247,
395,
7182,
370,
22026,
4094,
14,
199,
2719,
527,
12,
282,
2884,
626,
8491,
282,
570,
3925,
14,
1360,
911,
1218,
1373,
626,
30848,
315,
15685,
199,
5750,
1265,
9064,
663,
370,
2429,
23588,
1360,
1584,
12,
436,
880,
641,
14,
199,
199,
4718,
473,
1093,
4440,
2399,
5705,
5563,
370,
3504,
314,
730,
436,
14875,
367,
6290,
199,
7515,
10061,
12,
880,
642,
3371,
7859,
1133,
7763,
3932,
2943,
14,
199,
199,
2822,
402,
6187,
1695,
14,
22,
737,
5210,
12,
22026,
4094,
365,
6137,
1901,
314,
2656,
12,
436,
314,
199,
493,
13546,
787,
13810,
687,
314,
32445,
299,
5865,
402,
314,
22026,
3304,
199,
7885,
14,
221,
2876,
4900,
334,
262,
314,
16407,
6269,
9,
4839,
370,
506,
663,
370,
32445,
315,
1865,
370,
199,
2732,
642,
299,
5865,
14,
199,
199,
16811,
2594,
199,
199,
18989,
642,
570,
315,
2195,
2018,
931,
12,
436,
1218,
282,
570,
4310,
469,
4718,
9160,
2124,
26660,
14,
647,
199,
9099,
3509,
26,
267,
492,
284,
331,
897,
199,
199,
8,
3917,
469,
4718,
9160,
2124,
4229,
1793,
14,
647,
2575,
3495,
12,
2951,
1050,
314,
283,
646,
7,
1004,
370,
652,
4959,
199,
199,
1918,
2163,
900,
1265,
10623,
2018,
2620,
26499,
503,
2018,
473,
1093,
12,
314,
3371,
911,
5452,
199,
5881,
14,
199,
624,
199,
199,
504,
3598,
492,
7987,
647,
19,
75,
199,
4050,
647,
19,
75,
480,
607,
650,
14,
88,
12,
314,
284,
331,
897,
859,
365,
4829,
4765,
13232,
29,
18,
9,
199,
199,
646,
636,
5351,
363,
199,
199,
63,
5351,
63,
1490,
275,
7992,
1252,
362,
6412,
5351,
63,
1490,
297,
636,
5351,
4343,
1490,
9,
199,
199,
318,
485,
1490,
63,
1045,
63,
369,
529,
2031,
589,
304,
272,
570,
275,
485,
5351,
63,
1490,
2031,
589,
9,
272,
1788,
275,
1249,
59,
16,
61,
272,
818,
275,
283,
82,
7,
272,
340,
1249,
59,
17,
10688,
267,
818,
275,
1249,
59,
17,
61,
272,
340,
818,
59,
16,
61,
508,
283,
87,
356,
267,
687,
284,
67,
492,
1125,
12,
663,
466,
9986,
267,
862,
26,
288,
663,
466,
9986,
8,
1501,
9,
267,
871,
1125,
26,
288,
986,
272,
372,
570,
199,
199,
363,
5351,
4343,
1490,
275,
485,
1490,
63,
1045,
63,
369,
529,
199,
199,
624,
199,
1490,
360,
396,
14,
647,
358,
199,
63,
1490,
63,
1045,
63,
369,
529,
360,
396,
14,
647,
297,
283,
87,
358,
199,
63,
1490,
63,
1045,
63,
369,
529,
360,
396,
14,
2424,
297,
283,
87,
358,
199,
63,
1490,
63,
1045,
63,
369,
529,
360,
396,
14,
1360,
297,
283,
87,
358,
199,
63,
1490,
63,
1045,
63,
369,
529,
360,
396,
14,
1421,
297,
283,
87,
358,
199,
624,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
12802,
897,
3371,
199,
199,
14336,
12058,
199,
199,
12802,
897,
12385,
10444,
3100,
2018,
370,
675,
314,
22026,
4094,
570,
13546,
370,
3504,
199,
1589,
730,
436,
14875,
367,
282,
570,
14,
199,
199,
3353,
413,
14286,
370,
314,
4575,
2881,
650,
3091,
432,
976,
21300,
199,
991,
593,
317,
422,
17854,
8081,
334,
1597,
8081,
32,
1259,
14,
66,
1312,
271,
374,
14,
8654,
680,
199,
199,
25081,
51,
199,
199,
2765,
3371,
14486,
1584,
2737,
701,
2018,
1159,
1551,
8,
1501,
12,
283,
87,
358,
1414,
334,
460,
199,
991,
3423,
436,
10554,
626,
1240,
652,
9,
370,
663,
314,
730,
436,
14875,
402,
314,
570,
199,
475,
314,
730,
436,
14875,
4568,
543,
1788,
1159,
3329,
334,
1589,
199,
7314,
296,
402,
314,
1788,
2410,
314,
2061,
6247,
395,
7182,
370,
22026,
4094,
14,
199,
2719,
527,
12,
282,
2884,
626,
8491,
282,
570,
3925,
14,
1360,
911,
1218,
1373,
626,
30848,
315,
15685,
199,
5750,
1265,
9064,
663,
370,
2429,
23588,
1360,
1584,
12,
436,
880,
641,
14,
199,
199,
4718,
473,
1093,
4440,
2399,
5705,
5563,
370,
3504,
314,
730,
436,
14875,
367,
6290,
199,
7515,
10061,
12,
880,
642,
3371,
7859,
1133,
7763,
3932,
2943,
14,
199,
199,
2822,
402,
6187,
1695,
14,
22,
737,
5210,
12,
22026,
4094,
365,
6137,
1901,
314,
2656,
12,
436,
314,
199,
493,
13546,
787,
13810,
687,
314,
32445,
299,
5865,
402,
314,
22026,
3304,
199,
7885,
14,
221,
2876,
4900,
334,
262,
314,
16407,
6269,
9,
4839,
370,
506,
663,
370,
32445,
315,
1865,
370,
199,
2732,
642,
299,
5865,
14,
199,
199,
16811,
2594,
199,
199,
18989,
642,
570,
315,
2195,
2018,
931,
12,
436,
1218,
282,
570,
4310,
469,
4718,
9160,
2124,
26660,
14,
647,
199,
9099,
3509,
26,
267,
492,
284,
331,
897,
199,
199,
8,
3917,
469,
4718,
9160,
2124,
4229,
1793,
14,
647,
2575,
3495,
12,
2951,
1050,
314,
283,
646,
7,
1004,
370,
652,
4959,
199,
199,
1918,
2163,
900,
1265,
10623,
2018,
2620,
26499,
503,
2018,
473,
1093,
12,
314,
3371,
911,
5452,
199,
5881,
14,
199,
624,
199,
199,
504,
3598,
492,
7987,
647,
19,
75,
199,
4050,
647,
19,
75,
480,
607,
650,
14,
88,
12,
314,
284,
331,
897,
859,
365,
4829,
4765,
13232,
29,
18,
9,
199,
199,
646,
636,
5351,
363,
199,
199,
63,
5351,
63,
1490,
275,
7992,
1252,
362,
6412,
5351,
63,
1490,
297,
636,
5351,
4343,
1490,
9,
199,
199,
318,
485,
1490,
63,
1045,
63,
369,
529,
2031,
589,
304,
272,
570,
275,
485,
5351,
63,
1490,
2031,
589,
9,
272,
1788,
275,
1249,
59,
16,
61,
272,
818,
275,
283,
82,
7,
272,
340,
1249,
59,
17,
10688,
267,
818,
275,
1249,
59,
17,
61,
272,
340,
818,
59,
16,
61,
508,
283,
87,
356,
267,
687,
284,
67,
492,
1125,
12,
663,
466,
9986,
267,
862,
26,
288,
663,
466,
9986,
8,
1501,
9,
267,
871,
1125,
26,
288,
986,
272,
372,
570,
199,
199,
363,
5351,
4343,
1490,
275,
485,
1490,
63,
1045,
63,
369,
529,
199,
199,
624,
199,
1490,
360,
396,
14,
647,
358,
199,
63,
1490,
63,
1045,
63,
369,
529,
360,
396,
14,
647,
297,
283,
87,
358,
199,
63,
1490,
63,
1045,
63,
369,
529,
360,
396,
14,
2424,
297,
283,
87,
358,
199,
63,
1490,
63,
1045,
63,
369,
529,
360,
396,
14,
1360,
297,
283,
87,
358,
199,
63,
1490,
63,
1045,
63,
369,
529,
360,
396,
14,
1421,
297,
283,
87,
358,
199,
624,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mancoast/CPythonPyc_test
|
cpython/261_test_pprint.py
|
55
|
24560
|
import pprint
import test.test_support
import unittest
import test.test_set
try:
uni = unicode
except NameError:
def uni(x):
return x
# list, tuple and dict subclasses that do or don't overwrite __repr__
class list2(list):
pass
class list3(list):
def __repr__(self):
return list.__repr__(self)
class tuple2(tuple):
pass
class tuple3(tuple):
def __repr__(self):
return tuple.__repr__(self)
class dict2(dict):
pass
class dict3(dict):
def __repr__(self):
return dict.__repr__(self)
class QueryTestCase(unittest.TestCase):
def setUp(self):
self.a = range(100)
self.b = range(200)
self.a[-12] = self.b
def test_basic(self):
# Verify .isrecursive() and .isreadable() w/o recursion
verify = self.assert_
pp = pprint.PrettyPrinter()
for safe in (2, 2.0, 2j, "abc", [3], (2,2), {3: 3}, uni("yaddayadda"),
self.a, self.b):
# module-level convenience functions
verify(not pprint.isrecursive(safe),
"expected not isrecursive for %r" % (safe,))
verify(pprint.isreadable(safe),
"expected isreadable for %r" % (safe,))
# PrettyPrinter methods
verify(not pp.isrecursive(safe),
"expected not isrecursive for %r" % (safe,))
verify(pp.isreadable(safe),
"expected isreadable for %r" % (safe,))
def test_knotted(self):
# Verify .isrecursive() and .isreadable() w/ recursion
# Tie a knot.
self.b[67] = self.a
# Messy dict.
self.d = {}
self.d[0] = self.d[1] = self.d[2] = self.d
verify = self.assert_
pp = pprint.PrettyPrinter()
for icky in self.a, self.b, self.d, (self.d, self.d):
verify(pprint.isrecursive(icky), "expected isrecursive")
verify(not pprint.isreadable(icky), "expected not isreadable")
verify(pp.isrecursive(icky), "expected isrecursive")
verify(not pp.isreadable(icky), "expected not isreadable")
# Break the cycles.
self.d.clear()
del self.a[:]
del self.b[:]
for safe in self.a, self.b, self.d, (self.d, self.d):
# module-level convenience functions
verify(not pprint.isrecursive(safe),
"expected not isrecursive for %r" % (safe,))
verify(pprint.isreadable(safe),
"expected isreadable for %r" % (safe,))
# PrettyPrinter methods
verify(not pp.isrecursive(safe),
"expected not isrecursive for %r" % (safe,))
verify(pp.isreadable(safe),
"expected isreadable for %r" % (safe,))
def test_unreadable(self):
# Not recursive but not readable anyway
verify = self.assert_
pp = pprint.PrettyPrinter()
for unreadable in type(3), pprint, pprint.isrecursive:
# module-level convenience functions
verify(not pprint.isrecursive(unreadable),
"expected not isrecursive for %r" % (unreadable,))
verify(not pprint.isreadable(unreadable),
"expected not isreadable for %r" % (unreadable,))
# PrettyPrinter methods
verify(not pp.isrecursive(unreadable),
"expected not isrecursive for %r" % (unreadable,))
verify(not pp.isreadable(unreadable),
"expected not isreadable for %r" % (unreadable,))
def test_same_as_repr(self):
# Simple objects, small containers and classes that overwrite __repr__
# For those the result should be the same as repr().
# Ahem. The docs don't say anything about that -- this appears to
# be testing an implementation quirk. Starting in Python 2.5, it's
# not true for dicts: pprint always sorts dicts by key now; before,
# it sorted a dict display if and only if the display required
# multiple lines. For that reason, dicts with more than one element
# aren't tested here.
verify = self.assert_
for simple in (0, 0L, 0+0j, 0.0, "", uni(""),
(), tuple2(), tuple3(),
[], list2(), list3(),
{}, dict2(), dict3(),
verify, pprint,
-6, -6L, -6-6j, -1.5, "x", uni("x"), (3,), [3], {3: 6},
(1,2), [3,4], {5: 6, 7: 8},
tuple2((1,2)), tuple3((1,2)), tuple3(range(100)),
[3,4], list2([3,4]), list3([3,4]), list3(range(100)),
{5: 6, 7: 8}, dict2({5: 6}), dict3({5: 6}),
range(10, -11, -1)
):
native = repr(simple)
for function in "pformat", "saferepr":
f = getattr(pprint, function)
got = f(simple)
verify(native == got, "expected %s got %s from pprint.%s" %
(native, got, function))
def test_basic_line_wrap(self):
# verify basic line-wrapping operation
o = {'RPM_cal': 0,
'RPM_cal2': 48059,
'Speed_cal': 0,
'controldesk_runtime_us': 0,
'main_code_runtime_us': 0,
'read_io_runtime_us': 0,
'write_io_runtime_us': 43690}
exp = """\
{'RPM_cal': 0,
'RPM_cal2': 48059,
'Speed_cal': 0,
'controldesk_runtime_us': 0,
'main_code_runtime_us': 0,
'read_io_runtime_us': 0,
'write_io_runtime_us': 43690}"""
for type in [dict, dict2]:
self.assertEqual(pprint.pformat(type(o)), exp)
o = range(100)
exp = '[%s]' % ',\n '.join(map(str, o))
for type in [list, list2]:
self.assertEqual(pprint.pformat(type(o)), exp)
o = tuple(range(100))
exp = '(%s)' % ',\n '.join(map(str, o))
for type in [tuple, tuple2]:
self.assertEqual(pprint.pformat(type(o)), exp)
# indent parameter
o = range(100)
exp = '[ %s]' % ',\n '.join(map(str, o))
for type in [list, list2]:
self.assertEqual(pprint.pformat(type(o), indent=4), exp)
def test_nested_indentations(self):
o1 = list(range(10))
o2 = dict(first=1, second=2, third=3)
o = [o1, o2]
expected = """\
[ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
{ 'first': 1,
'second': 2,
'third': 3}]"""
self.assertEqual(pprint.pformat(o, indent=4, width=42), expected)
def test_sorted_dict(self):
# Starting in Python 2.5, pprint sorts dict displays by key regardless
# of how small the dictionary may be.
# Before the change, on 32-bit Windows pformat() gave order
# 'a', 'c', 'b' here, so this test failed.
d = {'a': 1, 'b': 1, 'c': 1}
self.assertEqual(pprint.pformat(d), "{'a': 1, 'b': 1, 'c': 1}")
self.assertEqual(pprint.pformat([d, d]),
"[{'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 1}]")
# The next one is kind of goofy. The sorted order depends on the
# alphabetic order of type names: "int" < "str" < "tuple". Before
# Python 2.5, this was in the test_same_as_repr() test. It's worth
# keeping around for now because it's one of few tests of pprint
# against a crazy mix of types.
self.assertEqual(pprint.pformat({"xy\tab\n": (3,), 5: [[]], (): {}}),
r"{5: [[]], 'xy\tab\n': (3,), (): {}}")
def test_subclassing(self):
o = {'names with spaces': 'should be presented using repr()',
'others.should.not.be': 'like.this'}
exp = """\
{'names with spaces': 'should be presented using repr()',
others.should.not.be: like.this}"""
self.assertEqual(DottedPrettyPrinter().pformat(o), exp)
def test_set_reprs(self):
self.assertEqual(pprint.pformat(set()), 'set()')
self.assertEqual(pprint.pformat(set(range(3))), 'set([0, 1, 2])')
self.assertEqual(pprint.pformat(frozenset()), 'frozenset()')
self.assertEqual(pprint.pformat(frozenset(range(3))), 'frozenset([0, 1, 2])')
cube_repr_tgt = """\
{frozenset([]): frozenset([frozenset([2]), frozenset([0]), frozenset([1])]),
frozenset([0]): frozenset([frozenset(),
frozenset([0, 2]),
frozenset([0, 1])]),
frozenset([1]): frozenset([frozenset(),
frozenset([1, 2]),
frozenset([0, 1])]),
frozenset([2]): frozenset([frozenset(),
frozenset([1, 2]),
frozenset([0, 2])]),
frozenset([1, 2]): frozenset([frozenset([2]),
frozenset([1]),
frozenset([0, 1, 2])]),
frozenset([0, 2]): frozenset([frozenset([2]),
frozenset([0]),
frozenset([0, 1, 2])]),
frozenset([0, 1]): frozenset([frozenset([0]),
frozenset([1]),
frozenset([0, 1, 2])]),
frozenset([0, 1, 2]): frozenset([frozenset([1, 2]),
frozenset([0, 2]),
frozenset([0, 1])])}"""
cube = test.test_set.cube(3)
self.assertEqual(pprint.pformat(cube), cube_repr_tgt)
cubo_repr_tgt = """\
{frozenset([frozenset([0, 2]), frozenset([0])]): frozenset([frozenset([frozenset([0,
2]),
frozenset([0,
1,
2])]),
frozenset([frozenset([0]),
frozenset([0,
1])]),
frozenset([frozenset(),
frozenset([0])]),
frozenset([frozenset([2]),
frozenset([0,
2])])]),
frozenset([frozenset([0, 1]), frozenset([1])]): frozenset([frozenset([frozenset([0,
1]),
frozenset([0,
1,
2])]),
frozenset([frozenset([0]),
frozenset([0,
1])]),
frozenset([frozenset([1]),
frozenset([1,
2])]),
frozenset([frozenset(),
frozenset([1])])]),
frozenset([frozenset([1, 2]), frozenset([1])]): frozenset([frozenset([frozenset([1,
2]),
frozenset([0,
1,
2])]),
frozenset([frozenset([2]),
frozenset([1,
2])]),
frozenset([frozenset(),
frozenset([1])]),
frozenset([frozenset([1]),
frozenset([0,
1])])]),
frozenset([frozenset([1, 2]), frozenset([2])]): frozenset([frozenset([frozenset([1,
2]),
frozenset([0,
1,
2])]),
frozenset([frozenset([1]),
frozenset([1,
2])]),
frozenset([frozenset([2]),
frozenset([0,
2])]),
frozenset([frozenset(),
frozenset([2])])]),
frozenset([frozenset([]), frozenset([0])]): frozenset([frozenset([frozenset([0]),
frozenset([0,
1])]),
frozenset([frozenset([0]),
frozenset([0,
2])]),
frozenset([frozenset(),
frozenset([1])]),
frozenset([frozenset(),
frozenset([2])])]),
frozenset([frozenset([]), frozenset([1])]): frozenset([frozenset([frozenset(),
frozenset([0])]),
frozenset([frozenset([1]),
frozenset([1,
2])]),
frozenset([frozenset(),
frozenset([2])]),
frozenset([frozenset([1]),
frozenset([0,
1])])]),
frozenset([frozenset([2]), frozenset([])]): frozenset([frozenset([frozenset([2]),
frozenset([1,
2])]),
frozenset([frozenset(),
frozenset([0])]),
frozenset([frozenset(),
frozenset([1])]),
frozenset([frozenset([2]),
frozenset([0,
2])])]),
frozenset([frozenset([0, 1, 2]), frozenset([0, 1])]): frozenset([frozenset([frozenset([1,
2]),
frozenset([0,
1,
2])]),
frozenset([frozenset([0,
2]),
frozenset([0,
1,
2])]),
frozenset([frozenset([0]),
frozenset([0,
1])]),
frozenset([frozenset([1]),
frozenset([0,
1])])]),
frozenset([frozenset([0]), frozenset([0, 1])]): frozenset([frozenset([frozenset(),
frozenset([0])]),
frozenset([frozenset([0,
1]),
frozenset([0,
1,
2])]),
frozenset([frozenset([0]),
frozenset([0,
2])]),
frozenset([frozenset([1]),
frozenset([0,
1])])]),
frozenset([frozenset([2]), frozenset([0, 2])]): frozenset([frozenset([frozenset([0,
2]),
frozenset([0,
1,
2])]),
frozenset([frozenset([2]),
frozenset([1,
2])]),
frozenset([frozenset([0]),
frozenset([0,
2])]),
frozenset([frozenset(),
frozenset([2])])]),
frozenset([frozenset([0, 1, 2]), frozenset([0, 2])]): frozenset([frozenset([frozenset([1,
2]),
frozenset([0,
1,
2])]),
frozenset([frozenset([0,
1]),
frozenset([0,
1,
2])]),
frozenset([frozenset([0]),
frozenset([0,
2])]),
frozenset([frozenset([2]),
frozenset([0,
2])])]),
frozenset([frozenset([1, 2]), frozenset([0, 1, 2])]): frozenset([frozenset([frozenset([0,
2]),
frozenset([0,
1,
2])]),
frozenset([frozenset([0,
1]),
frozenset([0,
1,
2])]),
frozenset([frozenset([2]),
frozenset([1,
2])]),
frozenset([frozenset([1]),
frozenset([1,
2])])])}"""
cubo = test.test_set.linegraph(cube)
self.assertEqual(pprint.pformat(cubo), cubo_repr_tgt)
def test_depth(self):
nested_tuple = (1, (2, (3, (4, (5, 6)))))
nested_dict = {1: {2: {3: {4: {5: {6: 6}}}}}}
nested_list = [1, [2, [3, [4, [5, [6, []]]]]]]
self.assertEqual(pprint.pformat(nested_tuple), repr(nested_tuple))
self.assertEqual(pprint.pformat(nested_dict), repr(nested_dict))
self.assertEqual(pprint.pformat(nested_list), repr(nested_list))
lv1_tuple = '(1, (...))'
lv1_dict = '{1: {...}}'
lv1_list = '[1, [...]]'
self.assertEqual(pprint.pformat(nested_tuple, depth=1), lv1_tuple)
self.assertEqual(pprint.pformat(nested_dict, depth=1), lv1_dict)
self.assertEqual(pprint.pformat(nested_list, depth=1), lv1_list)
class DottedPrettyPrinter(pprint.PrettyPrinter):
def format(self, object, context, maxlevels, level):
if isinstance(object, str):
if ' ' in object:
return repr(object), 1, 0
else:
return object, 0, 0
else:
return pprint.PrettyPrinter.format(
self, object, context, maxlevels, level)
def test_main():
test.test_support.run_unittest(QueryTestCase)
if __name__ == "__main__":
test_main()
|
gpl-3.0
|
[
646,
10933,
199,
646,
511,
14,
396,
63,
4058,
199,
646,
2882,
199,
646,
511,
14,
396,
63,
409,
199,
199,
893,
26,
272,
15439,
275,
2649,
199,
2590,
12746,
26,
272,
347,
15439,
8,
88,
304,
267,
372,
671,
199,
199,
3,
769,
12,
2008,
436,
1211,
9180,
626,
886,
503,
2793,
1133,
8970,
636,
2722,
363,
199,
533,
769,
18,
8,
513,
304,
272,
986,
199,
199,
533,
769,
19,
8,
513,
304,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
769,
855,
2722,
721,
277,
9,
199,
199,
533,
2008,
18,
8,
2960,
304,
272,
986,
199,
199,
533,
2008,
19,
8,
2960,
304,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
2008,
855,
2722,
721,
277,
9,
199,
199,
533,
1211,
18,
8,
807,
304,
272,
986,
199,
199,
533,
1211,
19,
8,
807,
304,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
1211,
855,
2722,
721,
277,
9,
199,
199,
533,
8133,
1746,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
65,
275,
1425,
8,
1960,
9,
267,
291,
14,
66,
275,
1425,
8,
1840,
9,
267,
291,
14,
65,
1988,
713,
61,
275,
291,
14,
66,
339,
347,
511,
63,
4316,
8,
277,
304,
267,
327,
7635,
1275,
374,
9931,
342,
436,
1275,
374,
11875,
342,
336,
15,
79,
16189,
267,
4911,
275,
291,
14,
479,
63,
267,
11618,
275,
10933,
14,
27153,
14131,
342,
267,
367,
5048,
315,
334,
18,
12,
499,
14,
16,
12,
499,
74,
12,
298,
3175,
401,
359,
19,
467,
334,
18,
12,
18,
395,
469,
19,
26,
650,
1386,
15439,
480,
89,
525,
1187,
525,
65,
1288,
2151,
291,
14,
65,
12,
291,
14,
66,
304,
288,
327,
859,
13,
1896,
16777,
3423,
288,
4911,
8,
1397,
10933,
14,
374,
9931,
8,
3489,
395,
673,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
4911,
8,
15380,
14,
374,
11875,
8,
3489,
395,
673,
298,
2062,
365,
11875,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
327,
31651,
14131,
3102,
288,
4911,
8,
1397,
11618,
14,
374,
9931,
8,
3489,
395,
673,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
4911,
8,
802,
14,
374,
11875,
8,
3489,
395,
673,
298,
2062,
365,
11875,
367,
450,
82,
2,
450,
334,
3489,
4641,
339,
347,
511,
63,
75,
1397,
471,
8,
277,
304,
267,
327,
7635,
1275,
374,
9931,
342,
436,
1275,
374,
11875,
342,
336,
15,
16189,
267,
327,
377,
1873,
282,
1022,
1397,
14,
267,
291,
14,
66,
59,
1822,
61,
275,
291,
14,
65,
267,
327,
3194,
385,
89,
1211,
14,
267,
291,
14,
68,
275,
1052,
267,
291,
14,
68,
59,
16,
61,
275,
291,
14,
68,
59,
17,
61,
275,
291,
14,
68,
59,
18,
61,
275,
291,
14,
68,
398,
4911,
275,
291,
14,
479,
63,
267,
11618,
275,
10933,
14,
27153,
14131,
342,
398,
367,
284,
346,
89,
315,
291,
14,
65,
12,
291,
14,
66,
12,
291,
14,
68,
12,
334,
277,
14,
68,
12,
291,
14,
68,
304,
288,
4911,
8,
15380,
14,
374,
9931,
8,
14022,
395,
298,
2062,
365,
9931,
531,
288,
4911,
8,
1397,
10933,
14,
374,
11875,
8,
14022,
395,
221,
298,
2062,
440,
365,
11875,
531,
288,
4911,
8,
802,
14,
374,
9931,
8,
14022,
395,
298,
2062,
365,
9931,
531,
288,
4911,
8,
1397,
11618,
14,
374,
11875,
8,
14022,
395,
221,
298,
2062,
440,
365,
11875,
531,
398,
327,
22535,
314,
19001,
14,
267,
291,
14,
68,
14,
3584,
342,
267,
2150,
291,
14,
65,
5873,
267,
2150,
291,
14,
66,
5873,
398,
367,
5048,
315,
291,
14,
65,
12,
291,
14,
66,
12,
291,
14,
68,
12,
334,
277,
14,
68,
12,
291,
14,
68,
304,
288,
327,
859,
13,
1896,
16777,
3423,
288,
4911,
8,
1397,
10933,
14,
374,
9931,
8,
3489,
395,
673,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
4911,
8,
15380,
14,
374,
11875,
8,
3489,
395,
673,
298,
2062,
365,
11875,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
327,
31651,
14131,
3102,
288,
4911,
8,
1397,
11618,
14,
374,
9931,
8,
3489,
395,
673,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
4911,
8,
802,
14,
374,
11875,
8,
3489,
395,
673,
298,
2062,
365,
11875,
367,
450,
82,
2,
450,
334,
3489,
4641,
339,
347,
511,
63,
324,
11875,
8,
277,
304,
267,
327,
2832,
9133,
1325,
440,
12701,
15988,
267,
4911,
275,
291,
14,
479,
63,
267,
11618,
275,
10933,
14,
27153,
14131,
342,
267,
367,
625,
11875,
315,
730,
8,
19,
395,
10933,
12,
10933,
14,
374,
9931,
26,
288,
327,
859,
13,
1896,
16777,
3423,
288,
4911,
8,
1397,
10933,
14,
374,
9931,
8,
324,
11875,
395,
673,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
324,
11875,
4641,
288,
4911,
8,
1397,
10933,
14,
374,
11875,
8,
324,
11875,
395,
673,
298,
2062,
440,
365,
11875,
367,
450,
82,
2,
450,
334,
324,
11875,
4641,
288,
327,
31651,
14131,
3102,
288,
4911,
8,
1397,
11618,
14,
374,
9931,
8,
324,
11875,
395,
673,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
324,
11875,
4641,
288,
4911,
8,
1397,
11618,
14,
374,
11875,
8,
324,
11875,
395,
673,
298,
2062,
440,
365,
11875,
367,
450,
82,
2,
450,
334,
324,
11875,
4641,
339,
347,
511,
63,
7191,
63,
305,
63,
2722,
8,
277,
304,
267,
327,
5870,
2251,
12,
7425,
15333,
436,
3992,
626,
8970,
636,
2722,
363,
267,
327,
2104,
5204,
314,
754,
1077,
506,
314,
2011,
465,
4700,
1252,
267,
327,
437,
27037,
14,
221,
710,
9149,
2793,
1133,
14722,
7003,
3595,
626,
1553,
642,
11337,
370,
267,
327,
506,
5343,
376,
4514,
2173,
723,
75,
14,
221,
24175,
315,
2018,
499,
14,
21,
12,
652,
1159,
267,
327,
440,
2549,
367,
10809,
26,
221,
10933,
3544,
30313,
10809,
701,
790,
3063,
27,
2544,
12,
267,
327,
652,
3355,
282,
1211,
2929,
340,
436,
1454,
340,
314,
2929,
1415,
267,
327,
3663,
2385
] |
[
10933,
199,
646,
511,
14,
396,
63,
4058,
199,
646,
2882,
199,
646,
511,
14,
396,
63,
409,
199,
199,
893,
26,
272,
15439,
275,
2649,
199,
2590,
12746,
26,
272,
347,
15439,
8,
88,
304,
267,
372,
671,
199,
199,
3,
769,
12,
2008,
436,
1211,
9180,
626,
886,
503,
2793,
1133,
8970,
636,
2722,
363,
199,
533,
769,
18,
8,
513,
304,
272,
986,
199,
199,
533,
769,
19,
8,
513,
304,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
769,
855,
2722,
721,
277,
9,
199,
199,
533,
2008,
18,
8,
2960,
304,
272,
986,
199,
199,
533,
2008,
19,
8,
2960,
304,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
2008,
855,
2722,
721,
277,
9,
199,
199,
533,
1211,
18,
8,
807,
304,
272,
986,
199,
199,
533,
1211,
19,
8,
807,
304,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
1211,
855,
2722,
721,
277,
9,
199,
199,
533,
8133,
1746,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
65,
275,
1425,
8,
1960,
9,
267,
291,
14,
66,
275,
1425,
8,
1840,
9,
267,
291,
14,
65,
1988,
713,
61,
275,
291,
14,
66,
339,
347,
511,
63,
4316,
8,
277,
304,
267,
327,
7635,
1275,
374,
9931,
342,
436,
1275,
374,
11875,
342,
336,
15,
79,
16189,
267,
4911,
275,
291,
14,
479,
63,
267,
11618,
275,
10933,
14,
27153,
14131,
342,
267,
367,
5048,
315,
334,
18,
12,
499,
14,
16,
12,
499,
74,
12,
298,
3175,
401,
359,
19,
467,
334,
18,
12,
18,
395,
469,
19,
26,
650,
1386,
15439,
480,
89,
525,
1187,
525,
65,
1288,
2151,
291,
14,
65,
12,
291,
14,
66,
304,
288,
327,
859,
13,
1896,
16777,
3423,
288,
4911,
8,
1397,
10933,
14,
374,
9931,
8,
3489,
395,
673,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
4911,
8,
15380,
14,
374,
11875,
8,
3489,
395,
673,
298,
2062,
365,
11875,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
327,
31651,
14131,
3102,
288,
4911,
8,
1397,
11618,
14,
374,
9931,
8,
3489,
395,
673,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
4911,
8,
802,
14,
374,
11875,
8,
3489,
395,
673,
298,
2062,
365,
11875,
367,
450,
82,
2,
450,
334,
3489,
4641,
339,
347,
511,
63,
75,
1397,
471,
8,
277,
304,
267,
327,
7635,
1275,
374,
9931,
342,
436,
1275,
374,
11875,
342,
336,
15,
16189,
267,
327,
377,
1873,
282,
1022,
1397,
14,
267,
291,
14,
66,
59,
1822,
61,
275,
291,
14,
65,
267,
327,
3194,
385,
89,
1211,
14,
267,
291,
14,
68,
275,
1052,
267,
291,
14,
68,
59,
16,
61,
275,
291,
14,
68,
59,
17,
61,
275,
291,
14,
68,
59,
18,
61,
275,
291,
14,
68,
398,
4911,
275,
291,
14,
479,
63,
267,
11618,
275,
10933,
14,
27153,
14131,
342,
398,
367,
284,
346,
89,
315,
291,
14,
65,
12,
291,
14,
66,
12,
291,
14,
68,
12,
334,
277,
14,
68,
12,
291,
14,
68,
304,
288,
4911,
8,
15380,
14,
374,
9931,
8,
14022,
395,
298,
2062,
365,
9931,
531,
288,
4911,
8,
1397,
10933,
14,
374,
11875,
8,
14022,
395,
221,
298,
2062,
440,
365,
11875,
531,
288,
4911,
8,
802,
14,
374,
9931,
8,
14022,
395,
298,
2062,
365,
9931,
531,
288,
4911,
8,
1397,
11618,
14,
374,
11875,
8,
14022,
395,
221,
298,
2062,
440,
365,
11875,
531,
398,
327,
22535,
314,
19001,
14,
267,
291,
14,
68,
14,
3584,
342,
267,
2150,
291,
14,
65,
5873,
267,
2150,
291,
14,
66,
5873,
398,
367,
5048,
315,
291,
14,
65,
12,
291,
14,
66,
12,
291,
14,
68,
12,
334,
277,
14,
68,
12,
291,
14,
68,
304,
288,
327,
859,
13,
1896,
16777,
3423,
288,
4911,
8,
1397,
10933,
14,
374,
9931,
8,
3489,
395,
673,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
4911,
8,
15380,
14,
374,
11875,
8,
3489,
395,
673,
298,
2062,
365,
11875,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
327,
31651,
14131,
3102,
288,
4911,
8,
1397,
11618,
14,
374,
9931,
8,
3489,
395,
673,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
4911,
8,
802,
14,
374,
11875,
8,
3489,
395,
673,
298,
2062,
365,
11875,
367,
450,
82,
2,
450,
334,
3489,
4641,
339,
347,
511,
63,
324,
11875,
8,
277,
304,
267,
327,
2832,
9133,
1325,
440,
12701,
15988,
267,
4911,
275,
291,
14,
479,
63,
267,
11618,
275,
10933,
14,
27153,
14131,
342,
267,
367,
625,
11875,
315,
730,
8,
19,
395,
10933,
12,
10933,
14,
374,
9931,
26,
288,
327,
859,
13,
1896,
16777,
3423,
288,
4911,
8,
1397,
10933,
14,
374,
9931,
8,
324,
11875,
395,
673,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
324,
11875,
4641,
288,
4911,
8,
1397,
10933,
14,
374,
11875,
8,
324,
11875,
395,
673,
298,
2062,
440,
365,
11875,
367,
450,
82,
2,
450,
334,
324,
11875,
4641,
288,
327,
31651,
14131,
3102,
288,
4911,
8,
1397,
11618,
14,
374,
9931,
8,
324,
11875,
395,
673,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
324,
11875,
4641,
288,
4911,
8,
1397,
11618,
14,
374,
11875,
8,
324,
11875,
395,
673,
298,
2062,
440,
365,
11875,
367,
450,
82,
2,
450,
334,
324,
11875,
4641,
339,
347,
511,
63,
7191,
63,
305,
63,
2722,
8,
277,
304,
267,
327,
5870,
2251,
12,
7425,
15333,
436,
3992,
626,
8970,
636,
2722,
363,
267,
327,
2104,
5204,
314,
754,
1077,
506,
314,
2011,
465,
4700,
1252,
267,
327,
437,
27037,
14,
221,
710,
9149,
2793,
1133,
14722,
7003,
3595,
626,
1553,
642,
11337,
370,
267,
327,
506,
5343,
376,
4514,
2173,
723,
75,
14,
221,
24175,
315,
2018,
499,
14,
21,
12,
652,
1159,
267,
327,
440,
2549,
367,
10809,
26,
221,
10933,
3544,
30313,
10809,
701,
790,
3063,
27,
2544,
12,
267,
327,
652,
3355,
282,
1211,
2929,
340,
436,
1454,
340,
314,
2929,
1415,
267,
327,
3663,
2385,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
theflofly/tensorflow
|
tensorflow/python/keras/utils/data_utils.py
|
4
|
23692
|
# Copyright 2018 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.
# ==============================================================================
# pylint: disable=g-import-not-at-top
"""Utilities for file download and caching."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from abc import abstractmethod
from contextlib import closing
import hashlib
import multiprocessing
from multiprocessing.pool import ThreadPool
import os
import random
import shutil
import sys
import tarfile
import threading
import time
import zipfile
import numpy as np
import six
from six.moves.urllib.error import HTTPError
from six.moves.urllib.error import URLError
from six.moves.urllib.request import urlopen
from tensorflow.python.keras.utils.generic_utils import Progbar
from tensorflow.python.util import tf_inspect
from tensorflow.python.util.tf_export import keras_export
try:
import queue
except ImportError:
import Queue as queue
if sys.version_info[0] == 2:
def urlretrieve(url, filename, reporthook=None, data=None):
"""Replacement for `urlretrive` for Python 2.
Under Python 2, `urlretrieve` relies on `FancyURLopener` from legacy
`urllib` module, known to have issues with proxy management.
Arguments:
url: url to retrieve.
filename: where to store the retrieved data locally.
reporthook: a hook function that will be called once
on establishment of the network connection and once
after each block read thereafter.
The hook will be passed three arguments;
a count of blocks transferred so far,
a block size in bytes, and the total size of the file.
data: `data` argument passed to `urlopen`.
"""
def chunk_read(response, chunk_size=8192, reporthook=None):
content_type = response.info().get('Content-Length')
total_size = -1
if content_type is not None:
total_size = int(content_type.strip())
count = 0
while True:
chunk = response.read(chunk_size)
count += 1
if reporthook is not None:
reporthook(count, chunk_size, total_size)
if chunk:
yield chunk
else:
break
response = urlopen(url, data)
with open(filename, 'wb') as fd:
for chunk in chunk_read(response, reporthook=reporthook):
fd.write(chunk)
else:
from six.moves.urllib.request import urlretrieve
def is_generator_or_sequence(x):
"""Check if `x` is a Keras generator type."""
return tf_inspect.isgenerator(x) or isinstance(x, Sequence)
def _extract_archive(file_path, path='.', archive_format='auto'):
"""Extracts an archive if it matches tar, tar.gz, tar.bz, or zip formats.
Arguments:
file_path: path to the archive file
path: path to extract the archive file
archive_format: Archive format to try for extracting the file.
Options are 'auto', 'tar', 'zip', and None.
'tar' includes tar, tar.gz, and tar.bz files.
The default 'auto' is ['tar', 'zip'].
None or an empty list will return no matches found.
Returns:
True if a match was found and an archive extraction was completed,
False otherwise.
"""
if archive_format is None:
return False
if archive_format == 'auto':
archive_format = ['tar', 'zip']
if isinstance(archive_format, six.string_types):
archive_format = [archive_format]
for archive_type in archive_format:
if archive_type == 'tar':
open_fn = tarfile.open
is_match_fn = tarfile.is_tarfile
if archive_type == 'zip':
open_fn = zipfile.ZipFile
is_match_fn = zipfile.is_zipfile
if is_match_fn(file_path):
with open_fn(file_path) as archive:
try:
archive.extractall(path)
except (tarfile.TarError, RuntimeError, KeyboardInterrupt):
if os.path.exists(path):
if os.path.isfile(path):
os.remove(path)
else:
shutil.rmtree(path)
raise
return True
return False
@keras_export('keras.utils.get_file')
def get_file(fname,
origin,
untar=False,
md5_hash=None,
file_hash=None,
cache_subdir='datasets',
hash_algorithm='auto',
extract=False,
archive_format='auto',
cache_dir=None):
"""Downloads a file from a URL if it not already in the cache.
By default the file at the url `origin` is downloaded to the
cache_dir `~/.keras`, placed in the cache_subdir `datasets`,
and given the filename `fname`. The final location of a file
`example.txt` would therefore be `~/.keras/datasets/example.txt`.
Files in tar, tar.gz, tar.bz, and zip formats can also be extracted.
Passing a hash will verify the file after download. The command line
programs `shasum` and `sha256sum` can compute the hash.
Arguments:
fname: Name of the file. If an absolute path `/path/to/file.txt` is
specified the file will be saved at that location.
origin: Original URL of the file.
untar: Deprecated in favor of 'extract'.
boolean, whether the file should be decompressed
md5_hash: Deprecated in favor of 'file_hash'.
md5 hash of the file for verification
file_hash: The expected hash string of the file after download.
The sha256 and md5 hash algorithms are both supported.
cache_subdir: Subdirectory under the Keras cache dir where the file is
saved. If an absolute path `/path/to/folder` is
specified the file will be saved at that location.
hash_algorithm: Select the hash algorithm to verify the file.
options are 'md5', 'sha256', and 'auto'.
The default 'auto' detects the hash algorithm in use.
extract: True tries extracting the file as an Archive, like tar or zip.
archive_format: Archive format to try for extracting the file.
Options are 'auto', 'tar', 'zip', and None.
'tar' includes tar, tar.gz, and tar.bz files.
The default 'auto' is ['tar', 'zip'].
None or an empty list will return no matches found.
cache_dir: Location to store cached files, when None it
defaults to the [Keras
Directory](/faq/#where-is-the-keras-configuration-filed-stored).
Returns:
Path to the downloaded file
"""
if cache_dir is None:
cache_dir = os.path.join(os.path.expanduser('~'), '.keras')
if md5_hash is not None and file_hash is None:
file_hash = md5_hash
hash_algorithm = 'md5'
datadir_base = os.path.expanduser(cache_dir)
if not os.access(datadir_base, os.W_OK):
datadir_base = os.path.join('/tmp', '.keras')
datadir = os.path.join(datadir_base, cache_subdir)
if not os.path.exists(datadir):
os.makedirs(datadir)
if untar:
untar_fpath = os.path.join(datadir, fname)
fpath = untar_fpath + '.tar.gz'
else:
fpath = os.path.join(datadir, fname)
download = False
if os.path.exists(fpath):
# File found; verify integrity if a hash was provided.
if file_hash is not None:
if not validate_file(fpath, file_hash, algorithm=hash_algorithm):
print('A local file was found, but it seems to be '
'incomplete or outdated because the ' + hash_algorithm +
' file hash does not match the original value of ' + file_hash +
' so we will re-download the data.')
download = True
else:
download = True
if download:
print('Downloading data from', origin)
class ProgressTracker(object):
# Maintain progbar for the lifetime of download.
# This design was chosen for Python 2.7 compatibility.
progbar = None
def dl_progress(count, block_size, total_size):
if ProgressTracker.progbar is None:
if total_size == -1:
total_size = None
ProgressTracker.progbar = Progbar(total_size)
else:
ProgressTracker.progbar.update(count * block_size)
error_msg = 'URL fetch failure on {}: {} -- {}'
try:
try:
urlretrieve(origin, fpath, dl_progress)
except HTTPError as e:
raise Exception(error_msg.format(origin, e.code, e.msg))
except URLError as e:
raise Exception(error_msg.format(origin, e.errno, e.reason))
except (Exception, KeyboardInterrupt) as e:
if os.path.exists(fpath):
os.remove(fpath)
raise
ProgressTracker.progbar = None
if untar:
if not os.path.exists(untar_fpath):
_extract_archive(fpath, datadir, archive_format='tar')
return untar_fpath
if extract:
_extract_archive(fpath, datadir, archive_format)
return fpath
def _hash_file(fpath, algorithm='sha256', chunk_size=65535):
"""Calculates a file sha256 or md5 hash.
Example:
```python
>>> from keras.data_utils import _hash_file
>>> _hash_file('/path/to/file.zip')
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
```
Arguments:
fpath: path to the file being validated
algorithm: hash algorithm, one of 'auto', 'sha256', or 'md5'.
The default 'auto' detects the hash algorithm in use.
chunk_size: Bytes to read at a time, important for large files.
Returns:
The file hash
"""
if (algorithm == 'sha256') or (algorithm == 'auto' and len(hash) == 64):
hasher = hashlib.sha256()
else:
hasher = hashlib.md5()
with open(fpath, 'rb') as fpath_file:
for chunk in iter(lambda: fpath_file.read(chunk_size), b''):
hasher.update(chunk)
return hasher.hexdigest()
def validate_file(fpath, file_hash, algorithm='auto', chunk_size=65535):
"""Validates a file against a sha256 or md5 hash.
Arguments:
fpath: path to the file being validated
file_hash: The expected hash string of the file.
The sha256 and md5 hash algorithms are both supported.
algorithm: Hash algorithm, one of 'auto', 'sha256', or 'md5'.
The default 'auto' detects the hash algorithm in use.
chunk_size: Bytes to read at a time, important for large files.
Returns:
Whether the file is valid
"""
if (algorithm == 'sha256') or (algorithm == 'auto' and len(file_hash) == 64):
hasher = 'sha256'
else:
hasher = 'md5'
if str(_hash_file(fpath, hasher, chunk_size)) == str(file_hash):
return True
else:
return False
@keras_export('keras.utils.Sequence')
class Sequence(object):
"""Base object for fitting to a sequence of data, such as a dataset.
Every `Sequence` must implement the `__getitem__` and the `__len__` methods.
If you want to modify your dataset between epochs you may implement
`on_epoch_end`.
The method `__getitem__` should return a complete batch.
Notes:
`Sequence` are a safer way to do multiprocessing. This structure guarantees
that the network will only train once
on each sample per epoch which is not the case with generators.
Examples:
```python
from skimage.io import imread
from skimage.transform import resize
import numpy as np
import math
# Here, `x_set` is list of path to the images
# and `y_set` are the associated classes.
class CIFAR10Sequence(Sequence):
def __init__(self, x_set, y_set, batch_size):
self.x, self.y = x_set, y_set
self.batch_size = batch_size
def __len__(self):
return math.ceil(len(self.x) / self.batch_size)
def __getitem__(self, idx):
batch_x = self.x[idx * self.batch_size:(idx + 1) *
self.batch_size]
batch_y = self.y[idx * self.batch_size:(idx + 1) *
self.batch_size]
return np.array([
resize(imread(file_name), (200, 200))
for file_name in batch_x]), np.array(batch_y)
```
"""
@abstractmethod
def __getitem__(self, index):
"""Gets batch at position `index`.
Arguments:
index: position of the batch in the Sequence.
Returns:
A batch
"""
raise NotImplementedError
@abstractmethod
def __len__(self):
"""Number of batch in the Sequence.
Returns:
The number of batches in the Sequence.
"""
raise NotImplementedError
def on_epoch_end(self):
"""Method called at the end of every epoch.
"""
pass
def __iter__(self):
"""Create a generator that iterate over the Sequence."""
for item in (self[i] for i in range(len(self))):
yield item
def iter_sequence_infinite(seq):
"""Iterates indefinitely over a Sequence.
Arguments:
seq: Sequence instance.
Yields:
Batches of data from the Sequence.
"""
while True:
for item in seq:
yield item
# Global variables to be shared across processes
_SHARED_SEQUENCES = {}
# We use a Value to provide unique id to different processes.
_SEQUENCE_COUNTER = None
def init_pool(seqs):
global _SHARED_SEQUENCES
_SHARED_SEQUENCES = seqs
def get_index(uid, i):
"""Get the value from the Sequence `uid` at index `i`.
To allow multiple Sequences to be used at the same time, we use `uid` to
get a specific one. A single Sequence would cause the validation to
overwrite the training Sequence.
Arguments:
uid: int, Sequence identifier
i: index
Returns:
The value at index `i`.
"""
return _SHARED_SEQUENCES[uid][i]
@keras_export('keras.utils.SequenceEnqueuer')
class SequenceEnqueuer(object):
"""Base class to enqueue inputs.
The task of an Enqueuer is to use parallelism to speed up preprocessing.
This is done with processes or threads.
Example:
```python
enqueuer = SequenceEnqueuer(...)
enqueuer.start()
datas = enqueuer.get()
for data in datas:
# Use the inputs; training, evaluating, predicting.
# ... stop sometime.
enqueuer.close()
```
The `enqueuer.get()` should be an infinite stream of datas.
"""
def __init__(self, sequence,
use_multiprocessing=False):
self.sequence = sequence
self.use_multiprocessing = use_multiprocessing
global _SEQUENCE_COUNTER
if _SEQUENCE_COUNTER is None:
try:
_SEQUENCE_COUNTER = multiprocessing.Value('i', 0)
except OSError:
# In this case the OS does not allow us to use
# multiprocessing. We resort to an int
# for enqueuer indexing.
_SEQUENCE_COUNTER = 0
if isinstance(_SEQUENCE_COUNTER, int):
self.uid = _SEQUENCE_COUNTER
_SEQUENCE_COUNTER += 1
else:
# Doing Multiprocessing.Value += x is not process-safe.
with _SEQUENCE_COUNTER.get_lock():
self.uid = _SEQUENCE_COUNTER.value
_SEQUENCE_COUNTER.value += 1
self.workers = 0
self.executor_fn = None
self.queue = None
self.run_thread = None
self.stop_signal = None
def is_running(self):
return self.stop_signal is not None and not self.stop_signal.is_set()
def start(self, workers=1, max_queue_size=10):
"""Starts the handler's workers.
Arguments:
workers: Number of workers.
max_queue_size: queue size
(when full, workers could block on `put()`)
"""
if self.use_multiprocessing:
self.executor_fn = self._get_executor_init(workers)
else:
# We do not need the init since it's threads.
self.executor_fn = lambda _: ThreadPool(workers)
self.workers = workers
self.queue = queue.Queue(max_queue_size)
self.stop_signal = threading.Event()
self.run_thread = threading.Thread(target=self._run)
self.run_thread.daemon = True
self.run_thread.start()
def _send_sequence(self):
"""Sends current Iterable to all workers."""
# For new processes that may spawn
_SHARED_SEQUENCES[self.uid] = self.sequence
def stop(self, timeout=None):
"""Stops running threads and wait for them to exit, if necessary.
Should be called by the same thread which called `start()`.
Arguments:
timeout: maximum time to wait on `thread.join()`
"""
self.stop_signal.set()
with self.queue.mutex:
self.queue.queue.clear()
self.queue.unfinished_tasks = 0
self.queue.not_full.notify()
self.run_thread.join(timeout)
_SHARED_SEQUENCES[self.uid] = None
@abstractmethod
def _run(self):
"""Submits request to the executor and queue the `Future` objects."""
raise NotImplementedError
@abstractmethod
def _get_executor_init(self, workers):
"""Gets the Pool initializer for multiprocessing.
Arguments:
workers: Number of workers.
Returns:
Function, a Function to initialize the pool
"""
raise NotImplementedError
@abstractmethod
def get(self):
"""Creates a generator to extract data from the queue.
Skip the data if it is `None`.
# Returns
Generator yielding tuples `(inputs, targets)`
or `(inputs, targets, sample_weights)`.
"""
raise NotImplementedError
@keras_export('keras.utils.OrderedEnqueuer')
class OrderedEnqueuer(SequenceEnqueuer):
"""Builds a Enqueuer from a Sequence.
Used in `fit_generator`, `evaluate_generator`, `predict_generator`.
Arguments:
sequence: A `tf.keras.utils.data_utils.Sequence` object.
use_multiprocessing: use multiprocessing if True, otherwise threading
shuffle: whether to shuffle the data at the beginning of each epoch
"""
def __init__(self, sequence, use_multiprocessing=False, shuffle=False):
super(OrderedEnqueuer, self).__init__(sequence, use_multiprocessing)
self.shuffle = shuffle
def _get_executor_init(self, workers):
"""Gets the Pool initializer for multiprocessing.
Arguments:
workers: Number of workers.
Returns:
Function, a Function to initialize the pool
"""
def pool_fn(seqs):
return multiprocessing.Pool(
workers, initializer=init_pool_generator, initargs=(seqs, None))
return pool_fn
def _wait_queue(self):
"""Wait for the queue to be empty."""
while True:
time.sleep(0.1)
if self.queue.unfinished_tasks == 0 or self.stop_signal.is_set():
return
def _run(self):
"""Submits request to the executor and queue the `Future` objects."""
sequence = list(range(len(self.sequence)))
self._send_sequence() # Share the initial sequence
while True:
if self.shuffle:
random.shuffle(sequence)
with closing(self.executor_fn(_SHARED_SEQUENCES)) as executor:
for i in sequence:
if self.stop_signal.is_set():
return
self.queue.put(
executor.apply_async(get_index, (self.uid, i)), block=True)
# Done with the current epoch, waiting for the final batches
self._wait_queue()
if self.stop_signal.is_set():
# We're done
return
# Call the internal on epoch end.
self.sequence.on_epoch_end()
self._send_sequence() # Update the pool
def get(self):
"""Creates a generator to extract data from the queue.
Skip the data if it is `None`.
Yields:
The next element in the queue, i.e. a tuple
`(inputs, targets)` or
`(inputs, targets, sample_weights)`.
"""
try:
while self.is_running():
inputs = self.queue.get(block=True).get()
self.queue.task_done()
if inputs is not None:
yield inputs
except Exception: # pylint: disable=broad-except
self.stop()
six.reraise(*sys.exc_info())
def init_pool_generator(gens, random_seed=None):
global _SHARED_SEQUENCES
_SHARED_SEQUENCES = gens
if random_seed is not None:
ident = multiprocessing.current_process().ident
np.random.seed(random_seed + ident)
def next_sample(uid):
"""Gets the next value from the generator `uid`.
To allow multiple generators to be used at the same time, we use `uid` to
get a specific one. A single generator would cause the validation to
overwrite the training generator.
Arguments:
uid: int, generator identifier
Returns:
The next value of generator `uid`.
"""
return six.next(_SHARED_SEQUENCES[uid])
@keras_export('keras.utils.GeneratorEnqueuer')
class GeneratorEnqueuer(SequenceEnqueuer):
"""Builds a queue out of a data generator.
The provided generator can be finite in which case the class will throw
a `StopIteration` exception.
Used in `fit_generator`, `evaluate_generator`, `predict_generator`.
Arguments:
generator: a generator function which yields data
use_multiprocessing: use multiprocessing if True, otherwise threading
wait_time: time to sleep in-between calls to `put()`
random_seed: Initial seed for workers,
will be incremented by one for each worker.
"""
def __init__(self, sequence,
use_multiprocessing=False,
random_seed=None):
super(GeneratorEnqueuer, self).__init__(sequence, use_multiprocessing)
self.random_seed = random_seed
def _get_executor_init(self, workers):
"""Gets the Pool initializer for multiprocessing.
Arguments:
workers: Number of works.
Returns:
A Function to initialize the pool
"""
def pool_fn(seqs):
return multiprocessing.Pool(workers,
initializer=init_pool_generator,
initargs=(seqs, self.random_seed))
return pool_fn
def _run(self):
"""Submits request to the executor and queue the `Future` objects."""
self._send_sequence() # Share the initial generator
with closing(self.executor_fn(_SHARED_SEQUENCES)) as executor:
while True:
if self.stop_signal.is_set():
return
self.queue.put(
executor.apply_async(next_sample, (self.uid,)), block=True)
def get(self):
"""Creates a generator to extract data from the queue.
Skip the data if it is `None`.
Yields:
The next element in the queue, i.e. a tuple
`(inputs, targets)` or
`(inputs, targets, sample_weights)`.
"""
try:
while self.is_running():
inputs = self.queue.get(block=True).get()
self.queue.task_done()
if inputs is not None:
yield inputs
except StopIteration:
# Special case for finite generators
last_ones = []
while self.queue.qsize() > 0:
last_ones.append(self.queue.get(block=True))
# Wait for them to complete
for f in last_ones:
f.wait()
# Keep the good ones
last_ones = [future.get() for future in last_ones if future.successful()]
for inputs in last_ones:
if inputs is not None:
yield inputs
except Exception as e: # pylint: disable=broad-except
self.stop()
if 'generator already executing' in str(e):
raise RuntimeError(
'Your generator is NOT thread-safe. '
'Keras requires a thread-safe generator when '
'`use_multiprocessing=False, workers > 1`. ')
six.reraise(*sys.exc_info())
|
apache-2.0
|
[
3,
1898,
14894,
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,
3,
4287,
26,
3507,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
199,
624,
22905,
367,
570,
5235,
436,
13627,
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,
13022,
492,
9006,
765,
199,
504,
15502,
492,
11261,
199,
646,
8337,
199,
646,
12866,
199,
504,
12866,
14,
2293,
492,
11086,
5453,
199,
646,
747,
199,
646,
2196,
199,
646,
5145,
199,
646,
984,
199,
646,
13608,
199,
646,
5796,
199,
646,
900,
199,
646,
10392,
199,
199,
646,
2680,
465,
980,
199,
646,
3816,
199,
504,
3816,
14,
4912,
14,
4078,
14,
705,
492,
15050,
199,
504,
3816,
14,
4912,
14,
4078,
14,
705,
492,
30794,
199,
504,
3816,
14,
4912,
14,
4078,
14,
1069,
492,
18279,
199,
199,
504,
3228,
14,
1548,
14,
8811,
14,
1208,
14,
6767,
63,
1208,
492,
2165,
71,
1700,
199,
504,
3228,
14,
1548,
14,
1974,
492,
2833,
63,
10955,
199,
504,
3228,
14,
1548,
14,
1974,
14,
3249,
63,
3790,
492,
11708,
63,
3790,
421,
199,
893,
26,
523,
492,
4126,
199,
2590,
3545,
26,
523,
492,
10703,
465,
4126,
421,
199,
692,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
26,
819,
347,
1166,
14270,
8,
633,
12,
1788,
12,
1833,
11297,
6992,
29,
403,
12,
666,
29,
403,
304,
272,
408,
29475,
367,
658,
633,
11235,
432,
64,
367,
2018,
499,
14,
339,
25010,
2018,
499,
12,
658,
633,
14270,
64,
25749,
641,
658,
38,
9844,
2632,
11637,
64,
687,
12139,
272,
658,
4078,
64,
859,
12,
6040,
370,
1172,
10876,
543,
4566,
10041,
14,
339,
7628,
26,
267,
1166,
26,
1166,
370,
8044,
14,
267,
1788,
26,
2382,
370,
3877,
314,
12396,
666,
17738,
14,
267,
1833,
11297,
6992,
26,
282,
5759,
805,
626,
911,
506,
2797,
5403,
288,
641,
16873,
434,
402,
314,
2784,
1950,
436,
5403,
288,
2410,
1924,
1853,
1586,
2337,
4399,
14,
288,
710,
5759,
911,
506,
3032,
7795,
2368,
27,
288,
282,
2338,
402,
5664,
1752,
5057,
880,
12474,
12,
288,
282,
1853,
1568,
315,
2783,
12,
436,
314,
3141,
1568,
402,
314,
570,
14,
267,
666,
26,
658,
576,
64,
1423,
3032,
370,
658,
10890,
2313,
272,
408,
339,
347,
3728,
63,
739,
8,
1310,
12,
3728,
63,
890,
29,
31526,
12,
1833,
11297,
6992,
29,
403,
304,
489,
1564,
63,
466,
275,
1177,
14,
815,
1252,
362,
360,
2714,
13,
4625,
358,
489,
3141,
63,
890,
275,
446,
17,
489,
340,
1564,
63,
466,
365,
440,
488,
26,
267,
3141,
63,
890,
275,
1109,
8,
1317,
63,
466,
14,
1913,
1012,
489,
2338,
275,
378,
489,
1830,
715,
26,
267,
3728,
275,
1177,
14,
739,
8,
4604,
63,
890,
9,
267,
2338,
847,
413,
267,
340,
1833,
11297,
6992,
365,
440,
488,
26,
881,
1833,
11297,
6992,
8,
835,
12,
3728,
63,
890,
12,
3141,
63,
890,
9,
267,
340,
3728,
26,
881,
1995,
3728,
267,
587,
26,
881,
2059,
339,
1177,
275,
18279,
8,
633,
12,
666,
9,
272,
543,
1551,
8,
1501,
12,
283,
6603,
358,
465,
6111,
26,
489,
367,
3728,
315,
3728,
63,
739,
8,
1310,
12,
1833,
11297,
6992,
29,
1155,
11297,
6992,
304,
267,
6111,
14,
952,
8,
4604,
9,
199,
2836,
26,
523,
687,
3816,
14,
4912,
14,
4078,
14,
1069,
492,
1166,
14270,
421,
199,
318,
365,
63,
4679,
63,
269,
63,
4041,
8,
88,
304,
523,
408,
1799,
340,
658,
88,
64,
365,
282,
1804,
30037,
4306,
730,
1041,
523,
372,
2833,
63,
10955,
14,
374,
4679,
8,
88,
9,
503,
1228,
8,
88,
12,
10975,
9,
421,
199,
318,
485,
5005,
63,
6404,
8,
493,
63,
515,
12,
931,
534,
3130,
6359,
63,
908,
534,
2495,
735,
523,
408,
12147,
83,
376,
6359,
340,
652,
4450,
5330,
12,
5330,
14,
6838,
12,
5330,
14,
10582,
12,
503,
3482,
6752,
14,
819,
7628,
26,
489,
570,
63,
515,
26,
931,
370,
314,
6359,
570,
489,
931,
26,
931,
370,
5536,
314,
6359,
570,
489,
6359,
63,
908,
26,
19521,
1912,
1475,
370,
862,
367,
30137,
314,
570,
14,
881,
8394,
787,
283,
2495,
297,
283,
5369,
297,
283,
3065,
297,
436,
488,
14,
881,
283,
5369,
7,
6952,
5330,
12,
5330,
14,
6838,
12,
436,
5330,
14,
10582,
1584,
14,
881,
710,
849,
283,
2495,
7,
365,
788,
5369,
297,
283,
3065,
2278,
881,
488,
503,
376,
2701,
769,
911,
372,
949,
4450,
1911,
14,
819,
1803,
26,
489,
715,
340,
282,
1336,
1990,
1911,
436,
376,
6359,
19967,
1990,
9709,
12,
489,
756,
4257,
14,
523,
408,
523,
340,
6359,
63,
908,
365,
488,
26,
272,
372,
756,
523,
340,
6359,
63,
908,
508,
283,
2495,
356,
272,
6359,
63,
908,
275,
788,
5369,
297,
283,
3065,
418,
523,
340,
1228,
8,
6404,
63,
908,
12,
3816,
14,
875,
63,
1313,
304,
272,
6359,
63,
908,
275,
359,
6404,
63,
908,
61,
819,
367,
6359,
63,
466,
315,
6359,
63,
908,
26,
272,
340,
6359,
63,
466,
508,
283,
5369,
356,
489,
1551,
63,
2324,
275,
13608,
14,
1490,
489,
365,
63,
1431,
63,
2324,
275,
13608,
14,
374,
63,
19862,
272,
340,
6359,
63,
466,
508,
283,
3065,
356,
489,
1551,
63,
2324,
275,
10392
] |
[
1898,
14894,
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,
3,
4287,
26,
3507,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
199,
624,
22905,
367,
570,
5235,
436,
13627,
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,
13022,
492,
9006,
765,
199,
504,
15502,
492,
11261,
199,
646,
8337,
199,
646,
12866,
199,
504,
12866,
14,
2293,
492,
11086,
5453,
199,
646,
747,
199,
646,
2196,
199,
646,
5145,
199,
646,
984,
199,
646,
13608,
199,
646,
5796,
199,
646,
900,
199,
646,
10392,
199,
199,
646,
2680,
465,
980,
199,
646,
3816,
199,
504,
3816,
14,
4912,
14,
4078,
14,
705,
492,
15050,
199,
504,
3816,
14,
4912,
14,
4078,
14,
705,
492,
30794,
199,
504,
3816,
14,
4912,
14,
4078,
14,
1069,
492,
18279,
199,
199,
504,
3228,
14,
1548,
14,
8811,
14,
1208,
14,
6767,
63,
1208,
492,
2165,
71,
1700,
199,
504,
3228,
14,
1548,
14,
1974,
492,
2833,
63,
10955,
199,
504,
3228,
14,
1548,
14,
1974,
14,
3249,
63,
3790,
492,
11708,
63,
3790,
421,
199,
893,
26,
523,
492,
4126,
199,
2590,
3545,
26,
523,
492,
10703,
465,
4126,
421,
199,
692,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
26,
819,
347,
1166,
14270,
8,
633,
12,
1788,
12,
1833,
11297,
6992,
29,
403,
12,
666,
29,
403,
304,
272,
408,
29475,
367,
658,
633,
11235,
432,
64,
367,
2018,
499,
14,
339,
25010,
2018,
499,
12,
658,
633,
14270,
64,
25749,
641,
658,
38,
9844,
2632,
11637,
64,
687,
12139,
272,
658,
4078,
64,
859,
12,
6040,
370,
1172,
10876,
543,
4566,
10041,
14,
339,
7628,
26,
267,
1166,
26,
1166,
370,
8044,
14,
267,
1788,
26,
2382,
370,
3877,
314,
12396,
666,
17738,
14,
267,
1833,
11297,
6992,
26,
282,
5759,
805,
626,
911,
506,
2797,
5403,
288,
641,
16873,
434,
402,
314,
2784,
1950,
436,
5403,
288,
2410,
1924,
1853,
1586,
2337,
4399,
14,
288,
710,
5759,
911,
506,
3032,
7795,
2368,
27,
288,
282,
2338,
402,
5664,
1752,
5057,
880,
12474,
12,
288,
282,
1853,
1568,
315,
2783,
12,
436,
314,
3141,
1568,
402,
314,
570,
14,
267,
666,
26,
658,
576,
64,
1423,
3032,
370,
658,
10890,
2313,
272,
408,
339,
347,
3728,
63,
739,
8,
1310,
12,
3728,
63,
890,
29,
31526,
12,
1833,
11297,
6992,
29,
403,
304,
489,
1564,
63,
466,
275,
1177,
14,
815,
1252,
362,
360,
2714,
13,
4625,
358,
489,
3141,
63,
890,
275,
446,
17,
489,
340,
1564,
63,
466,
365,
440,
488,
26,
267,
3141,
63,
890,
275,
1109,
8,
1317,
63,
466,
14,
1913,
1012,
489,
2338,
275,
378,
489,
1830,
715,
26,
267,
3728,
275,
1177,
14,
739,
8,
4604,
63,
890,
9,
267,
2338,
847,
413,
267,
340,
1833,
11297,
6992,
365,
440,
488,
26,
881,
1833,
11297,
6992,
8,
835,
12,
3728,
63,
890,
12,
3141,
63,
890,
9,
267,
340,
3728,
26,
881,
1995,
3728,
267,
587,
26,
881,
2059,
339,
1177,
275,
18279,
8,
633,
12,
666,
9,
272,
543,
1551,
8,
1501,
12,
283,
6603,
358,
465,
6111,
26,
489,
367,
3728,
315,
3728,
63,
739,
8,
1310,
12,
1833,
11297,
6992,
29,
1155,
11297,
6992,
304,
267,
6111,
14,
952,
8,
4604,
9,
199,
2836,
26,
523,
687,
3816,
14,
4912,
14,
4078,
14,
1069,
492,
1166,
14270,
421,
199,
318,
365,
63,
4679,
63,
269,
63,
4041,
8,
88,
304,
523,
408,
1799,
340,
658,
88,
64,
365,
282,
1804,
30037,
4306,
730,
1041,
523,
372,
2833,
63,
10955,
14,
374,
4679,
8,
88,
9,
503,
1228,
8,
88,
12,
10975,
9,
421,
199,
318,
485,
5005,
63,
6404,
8,
493,
63,
515,
12,
931,
534,
3130,
6359,
63,
908,
534,
2495,
735,
523,
408,
12147,
83,
376,
6359,
340,
652,
4450,
5330,
12,
5330,
14,
6838,
12,
5330,
14,
10582,
12,
503,
3482,
6752,
14,
819,
7628,
26,
489,
570,
63,
515,
26,
931,
370,
314,
6359,
570,
489,
931,
26,
931,
370,
5536,
314,
6359,
570,
489,
6359,
63,
908,
26,
19521,
1912,
1475,
370,
862,
367,
30137,
314,
570,
14,
881,
8394,
787,
283,
2495,
297,
283,
5369,
297,
283,
3065,
297,
436,
488,
14,
881,
283,
5369,
7,
6952,
5330,
12,
5330,
14,
6838,
12,
436,
5330,
14,
10582,
1584,
14,
881,
710,
849,
283,
2495,
7,
365,
788,
5369,
297,
283,
3065,
2278,
881,
488,
503,
376,
2701,
769,
911,
372,
949,
4450,
1911,
14,
819,
1803,
26,
489,
715,
340,
282,
1336,
1990,
1911,
436,
376,
6359,
19967,
1990,
9709,
12,
489,
756,
4257,
14,
523,
408,
523,
340,
6359,
63,
908,
365,
488,
26,
272,
372,
756,
523,
340,
6359,
63,
908,
508,
283,
2495,
356,
272,
6359,
63,
908,
275,
788,
5369,
297,
283,
3065,
418,
523,
340,
1228,
8,
6404,
63,
908,
12,
3816,
14,
875,
63,
1313,
304,
272,
6359,
63,
908,
275,
359,
6404,
63,
908,
61,
819,
367,
6359,
63,
466,
315,
6359,
63,
908,
26,
272,
340,
6359,
63,
466,
508,
283,
5369,
356,
489,
1551,
63,
2324,
275,
13608,
14,
1490,
489,
365,
63,
1431,
63,
2324,
275,
13608,
14,
374,
63,
19862,
272,
340,
6359,
63,
466,
508,
283,
3065,
356,
489,
1551,
63,
2324,
275,
10392,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
SerpentAI/SerpentAI
|
serpent/game_frame.py
|
1
|
5346
|
import skimage.color
import skimage.measure
import skimage.transform
import skimage.filters
import skimage.morphology
import numpy as np
import io
from PIL import Image
class GameFrameError(BaseException):
pass
class GameFrame:
def __init__(self, frame_data, frame_variants=None, timestamp=None, **kwargs):
if isinstance(frame_data, bytes):
self.frame_bytes = frame_data
self.frame_array = None
elif isinstance(frame_data, np.ndarray):
self.frame_bytes = None
self.frame_array = frame_data
self.frame_variants = frame_variants or dict()
self.timestamp = timestamp
self.offset_x = kwargs.get("offset_x") or 0
self.offset_y = kwargs.get("offset_y") or 0
self.resize_order = kwargs.get("resize_order") or 1
@property
def frame(self):
return self.frame_array if self.frame_array is not None else self.frame_bytes
@property
def half_resolution_frame(self):
""" A quarter-sized version of the frame (half-width, half-height)"""
if "half" not in self.frame_variants:
self.frame_variants["half"] = self._to_half_resolution()
return self.frame_variants["half"]
@property
def quarter_resolution_frame(self):
""" A sixteenth-sized version of the frame (quarter-width, quarter-height)"""
if "quarter" not in self.frame_variants:
self.frame_variants["quarter"] = self._to_quarter_resolution()
return self.frame_variants["quarter"]
@property
def eighth_resolution_frame(self):
""" A 1/32-sized version of the frame (eighth-width, eighth-height)"""
if "eighth" not in self.frame_variants:
self.frame_variants["eighth"] = self._to_eighth_resolution()
return self.frame_variants["eighth"]
@property
def eighth_resolution_grayscale_frame(self):
""" A 1/32-sized, grayscale version of the frame (eighth-width, eighth-height)"""
if "eighth_grayscale" not in self.frame_variants:
self.frame_variants["eighth_grayscale"] = self._to_eighth_grayscale_resolution()
return self.frame_variants["eighth_grayscale"]
@property
def grayscale_frame(self):
""" A full-size grayscale version of the frame"""
if "grayscale" not in self.frame_variants:
self.frame_variants["grayscale"] = self._to_grayscale()
return self.frame_variants["grayscale"]
@property
def ssim_frame(self):
""" A 100x100 grayscale frame to be used for SSIM"""
if "ssim" not in self.frame_variants:
self.frame_variants["ssim"] = self._to_ssim()
return self.frame_variants["ssim"]
@property
def top_color(self):
height, width, channels = self.eighth_resolution_frame.shape
values, counts = np.unique(self.eighth_resolution_frame.reshape(width * height, channels), axis=0, return_counts=True)
return [int(i) for i in values[np.argsort(counts)[::-1][0]]]
def compare_ssim(self, previous_game_frame):
return skimage.measure.compare_ssim(previous_game_frame.ssim_frame, self.ssim_frame)
def difference(self, previous_game_frame):
current = skimage.filters.gaussian(self.grayscale_frame, 8)
previous = skimage.filters.gaussian(previous_game_frame.grayscale_frame, 8)
return current - previous
def to_pil(self):
return Image.fromarray(self.frame)
def to_png_bytes(self):
pil_frame = Image.fromarray(skimage.util.img_as_ubyte(self.frame))
if len(self.frame.shape) == 3:
pil_frame = pil_frame.convert("RGB")
png_frame = io.BytesIO()
pil_frame.save(png_frame, format="PNG", compress_level=3)
png_frame.seek(0)
return png_frame.read()
# TODO: Refactor Fraction of Resolution Frames...
def _to_half_resolution(self):
shape = (
self.frame_array.shape[0] // 2,
self.frame_array.shape[1] // 2
)
return np.array(skimage.transform.resize(self.frame_array, shape, mode="reflect", order=self.resize_order) * 255, dtype="uint8")
def _to_quarter_resolution(self):
shape = (
self.frame_array.shape[0] // 4,
self.frame_array.shape[1] // 4
)
return np.array(skimage.transform.resize(self.frame_array, shape, mode="reflect", order=self.resize_order) * 255, dtype="uint8")
def _to_eighth_resolution(self):
shape = (
self.frame_array.shape[0] // 8,
self.frame_array.shape[1] // 8
)
return np.array(skimage.transform.resize(self.frame_array, shape, mode="reflect", order=self.resize_order) * 255, dtype="uint8")
def _to_eighth_grayscale_resolution(self):
shape = (
self.frame_array.shape[0] // 8,
self.frame_array.shape[1] // 8
)
return np.array(skimage.transform.resize(self.grayscale_frame, shape, mode="reflect", order=self.resize_order) * 255, dtype="uint8")
def _to_grayscale(self):
return np.array(skimage.color.rgb2gray(self.frame_array) * 255, dtype="uint8")
def _to_ssim(self):
grayscale = self.grayscale_frame
return skimage.transform.resize(grayscale, (100, 100), mode="reflect", order=0)
|
mit
|
[
646,
2386,
1569,
14,
2326,
199,
646,
2386,
1569,
14,
9580,
199,
646,
2386,
1569,
14,
4711,
199,
646,
2386,
1569,
14,
4273,
199,
646,
2386,
1569,
14,
12416,
21936,
4956,
199,
199,
646,
2680,
465,
980,
199,
199,
646,
5890,
199,
199,
504,
14937,
492,
6047,
421,
199,
533,
25132,
3160,
547,
8,
29900,
304,
272,
986,
421,
199,
533,
25132,
3160,
26,
339,
347,
636,
826,
721,
277,
12,
2787,
63,
576,
12,
2787,
63,
15680,
29,
403,
12,
4913,
29,
403,
12,
1011,
958,
304,
267,
340,
1228,
8,
1943,
63,
576,
12,
2783,
304,
288,
291,
14,
1943,
63,
2394,
275,
2787,
63,
576,
288,
291,
14,
1943,
63,
1144,
275,
488,
267,
916,
1228,
8,
1943,
63,
576,
12,
980,
14,
8237,
304,
288,
291,
14,
1943,
63,
2394,
275,
488,
288,
291,
14,
1943,
63,
1144,
275,
2787,
63,
576,
398,
291,
14,
1943,
63,
15680,
275,
2787,
63,
15680,
503,
1211,
342,
398,
291,
14,
3954,
275,
4913,
398,
291,
14,
2743,
63,
88,
275,
2074,
14,
362,
480,
2743,
63,
88,
531,
503,
378,
267,
291,
14,
2743,
63,
89,
275,
2074,
14,
362,
480,
2743,
63,
89,
531,
503,
378,
398,
291,
14,
8709,
63,
1648,
275,
2074,
14,
362,
480,
8709,
63,
1648,
531,
503,
413,
339,
768,
1829,
272,
347,
2787,
8,
277,
304,
267,
372,
291,
14,
1943,
63,
1144,
340,
291,
14,
1943,
63,
1144,
365,
440,
488,
587,
291,
14,
1943,
63,
2394,
339,
768,
1829,
272,
347,
12995,
63,
12588,
63,
1943,
8,
277,
304,
267,
408,
437,
2173,
16972,
13,
15308,
1015,
402,
314,
2787,
334,
10220,
13,
2063,
12,
12995,
13,
3333,
9471,
398,
340,
298,
10220,
2,
440,
315,
291,
14,
1943,
63,
15680,
26,
288,
291,
14,
1943,
63,
15680,
905,
10220,
937,
275,
291,
423,
475,
63,
10220,
63,
12588,
342,
398,
372,
291,
14,
1943,
63,
15680,
905,
10220,
937,
339,
768,
1829,
272,
347,
2173,
16972,
63,
12588,
63,
1943,
8,
277,
304,
267,
408,
437,
3816,
25076,
273,
13,
15308,
1015,
402,
314,
2787,
334,
25985,
13,
2063,
12,
2173,
16972,
13,
3333,
9471,
398,
340,
298,
25985,
2,
440,
315,
291,
14,
1943,
63,
15680,
26,
288,
291,
14,
1943,
63,
15680,
905,
25985,
937,
275,
291,
423,
475,
63,
25985,
63,
12588,
342,
398,
372,
291,
14,
1943,
63,
15680,
905,
25985,
937,
339,
768,
1829,
272,
347,
325,
2056,
273,
63,
12588,
63,
1943,
8,
277,
304,
267,
408,
437,
413,
15,
708,
13,
15308,
1015,
402,
314,
2787,
334,
69,
2056,
273,
13,
2063,
12,
325,
2056,
273,
13,
3333,
9471,
398,
340,
298,
69,
2056,
273,
2,
440,
315,
291,
14,
1943,
63,
15680,
26,
288,
291,
14,
1943,
63,
15680,
905,
69,
2056,
273,
937,
275,
291,
423,
475,
63,
69,
2056,
273,
63,
12588,
342,
398,
372,
291,
14,
1943,
63,
15680,
905,
69,
2056,
273,
937,
339,
768,
1829,
272,
347,
325,
2056,
273,
63,
12588,
63,
12150,
3467,
63,
1943,
8,
277,
304,
267,
408,
437,
413,
15,
708,
13,
15308,
12,
21977,
3467,
1015,
402,
314,
2787,
334,
69,
2056,
273,
13,
2063,
12,
325,
2056,
273,
13,
3333,
9471,
398,
340,
298,
69,
2056,
273,
63,
12150,
3467,
2,
440,
315,
291,
14,
1943,
63,
15680,
26,
288,
291,
14,
1943,
63,
15680,
905,
69,
2056,
273,
63,
12150,
3467,
937,
275,
291,
423,
475,
63,
69,
2056,
273,
63,
12150,
3467,
63,
12588,
342,
398,
372,
291,
14,
1943,
63,
15680,
905,
69,
2056,
273,
63,
12150,
3467,
937,
339,
768,
1829,
272,
347,
21977,
3467,
63,
1943,
8,
277,
304,
267,
408,
437,
2615,
13,
890,
21977,
3467,
1015,
402,
314,
2787,
624,
398,
340,
298,
12150,
3467,
2,
440,
315,
291,
14,
1943,
63,
15680,
26,
288,
291,
14,
1943,
63,
15680,
905,
12150,
3467,
937,
275,
291,
423,
475,
63,
12150,
3467,
342,
398,
372,
291,
14,
1943,
63,
15680,
905,
12150,
3467,
937,
339,
768,
1829,
272,
347,
308,
5206,
63,
1943,
8,
277,
304,
267,
408,
437,
2948,
88,
1960,
21977,
3467,
2787,
370,
506,
1202,
367,
428,
16590,
624,
398,
340,
298,
83,
5206,
2,
440,
315,
291,
14,
1943,
63,
15680,
26,
288,
291,
14,
1943,
63,
15680,
905,
83,
5206,
937,
275,
291,
423,
475,
63,
83,
5206,
342,
398,
372,
291,
14,
1943,
63,
15680,
905,
83,
5206,
937,
339,
768,
1829,
272,
347,
2746,
63,
2326,
8,
277,
304,
267,
4569,
12,
3462,
12,
9245,
275,
291,
14,
69,
2056,
273,
63,
12588,
63,
1943,
14,
1392,
267,
1338,
12,
8242,
275,
980,
14,
3235,
8,
277,
14,
69,
2056,
273,
63,
12588,
63,
1943,
14,
5217,
8,
2063,
627,
4569,
12,
9245,
395,
3114,
29,
16,
12,
372,
63,
6851,
29,
549,
9,
398,
372,
359,
442,
8,
73,
9,
367,
284,
315,
1338,
59,
1590,
14,
20188,
8,
6851,
2788,
21123,
17,
1527,
16,
20737,
339,
347,
6540,
63,
83,
5206,
8,
277,
12,
4136,
63,
5097,
63,
1943,
304,
267,
372,
2386,
1569,
14,
9580,
14,
5785,
63,
83,
5206,
8,
6352,
63,
5097,
63,
1943,
14,
83,
5206,
63,
1943,
12,
291,
14,
83,
5206,
63,
1943,
9,
339,
347,
8865,
8,
277,
12,
4136,
63,
5097,
63,
1943,
304,
267,
1453,
275,
2386,
1569,
14,
4273,
14,
22911,
8,
277,
14,
12150,
3467,
63,
1943,
12,
1695,
9,
267,
4136,
275,
2386,
1569,
14,
4273,
14,
22911,
8,
6352,
63,
5097,
63,
1943,
14,
12150,
3467,
63,
1943,
12,
1695,
9,
398,
372,
1453,
446,
4136,
339,
347,
370,
63,
80,
382,
8,
277,
304,
267,
372,
6047,
14,
504,
1144,
8,
277,
14,
1943,
9,
339,
347,
370,
63,
4524,
63,
2394,
8,
277,
304,
267,
299,
382,
63,
1943,
275,
6047,
14,
504,
1144,
8,
1339,
1569,
14,
1974,
14,
4060,
63,
305,
63,
20790,
8,
277,
14,
1943,
430,
398,
340,
822,
8,
277,
14,
1943,
14,
1392,
9,
508,
650,
26,
288,
299,
382,
63,
1943,
275,
299,
382,
63,
1943,
14,
3916,
480,
12067,
531,
398,
25296,
63,
1943,
275,
5890,
14,
15466,
342,
398,
299,
382,
63,
1943
] |
[
2386,
1569,
14,
2326,
199,
646,
2386,
1569,
14,
9580,
199,
646,
2386,
1569,
14,
4711,
199,
646,
2386,
1569,
14,
4273,
199,
646,
2386,
1569,
14,
12416,
21936,
4956,
199,
199,
646,
2680,
465,
980,
199,
199,
646,
5890,
199,
199,
504,
14937,
492,
6047,
421,
199,
533,
25132,
3160,
547,
8,
29900,
304,
272,
986,
421,
199,
533,
25132,
3160,
26,
339,
347,
636,
826,
721,
277,
12,
2787,
63,
576,
12,
2787,
63,
15680,
29,
403,
12,
4913,
29,
403,
12,
1011,
958,
304,
267,
340,
1228,
8,
1943,
63,
576,
12,
2783,
304,
288,
291,
14,
1943,
63,
2394,
275,
2787,
63,
576,
288,
291,
14,
1943,
63,
1144,
275,
488,
267,
916,
1228,
8,
1943,
63,
576,
12,
980,
14,
8237,
304,
288,
291,
14,
1943,
63,
2394,
275,
488,
288,
291,
14,
1943,
63,
1144,
275,
2787,
63,
576,
398,
291,
14,
1943,
63,
15680,
275,
2787,
63,
15680,
503,
1211,
342,
398,
291,
14,
3954,
275,
4913,
398,
291,
14,
2743,
63,
88,
275,
2074,
14,
362,
480,
2743,
63,
88,
531,
503,
378,
267,
291,
14,
2743,
63,
89,
275,
2074,
14,
362,
480,
2743,
63,
89,
531,
503,
378,
398,
291,
14,
8709,
63,
1648,
275,
2074,
14,
362,
480,
8709,
63,
1648,
531,
503,
413,
339,
768,
1829,
272,
347,
2787,
8,
277,
304,
267,
372,
291,
14,
1943,
63,
1144,
340,
291,
14,
1943,
63,
1144,
365,
440,
488,
587,
291,
14,
1943,
63,
2394,
339,
768,
1829,
272,
347,
12995,
63,
12588,
63,
1943,
8,
277,
304,
267,
408,
437,
2173,
16972,
13,
15308,
1015,
402,
314,
2787,
334,
10220,
13,
2063,
12,
12995,
13,
3333,
9471,
398,
340,
298,
10220,
2,
440,
315,
291,
14,
1943,
63,
15680,
26,
288,
291,
14,
1943,
63,
15680,
905,
10220,
937,
275,
291,
423,
475,
63,
10220,
63,
12588,
342,
398,
372,
291,
14,
1943,
63,
15680,
905,
10220,
937,
339,
768,
1829,
272,
347,
2173,
16972,
63,
12588,
63,
1943,
8,
277,
304,
267,
408,
437,
3816,
25076,
273,
13,
15308,
1015,
402,
314,
2787,
334,
25985,
13,
2063,
12,
2173,
16972,
13,
3333,
9471,
398,
340,
298,
25985,
2,
440,
315,
291,
14,
1943,
63,
15680,
26,
288,
291,
14,
1943,
63,
15680,
905,
25985,
937,
275,
291,
423,
475,
63,
25985,
63,
12588,
342,
398,
372,
291,
14,
1943,
63,
15680,
905,
25985,
937,
339,
768,
1829,
272,
347,
325,
2056,
273,
63,
12588,
63,
1943,
8,
277,
304,
267,
408,
437,
413,
15,
708,
13,
15308,
1015,
402,
314,
2787,
334,
69,
2056,
273,
13,
2063,
12,
325,
2056,
273,
13,
3333,
9471,
398,
340,
298,
69,
2056,
273,
2,
440,
315,
291,
14,
1943,
63,
15680,
26,
288,
291,
14,
1943,
63,
15680,
905,
69,
2056,
273,
937,
275,
291,
423,
475,
63,
69,
2056,
273,
63,
12588,
342,
398,
372,
291,
14,
1943,
63,
15680,
905,
69,
2056,
273,
937,
339,
768,
1829,
272,
347,
325,
2056,
273,
63,
12588,
63,
12150,
3467,
63,
1943,
8,
277,
304,
267,
408,
437,
413,
15,
708,
13,
15308,
12,
21977,
3467,
1015,
402,
314,
2787,
334,
69,
2056,
273,
13,
2063,
12,
325,
2056,
273,
13,
3333,
9471,
398,
340,
298,
69,
2056,
273,
63,
12150,
3467,
2,
440,
315,
291,
14,
1943,
63,
15680,
26,
288,
291,
14,
1943,
63,
15680,
905,
69,
2056,
273,
63,
12150,
3467,
937,
275,
291,
423,
475,
63,
69,
2056,
273,
63,
12150,
3467,
63,
12588,
342,
398,
372,
291,
14,
1943,
63,
15680,
905,
69,
2056,
273,
63,
12150,
3467,
937,
339,
768,
1829,
272,
347,
21977,
3467,
63,
1943,
8,
277,
304,
267,
408,
437,
2615,
13,
890,
21977,
3467,
1015,
402,
314,
2787,
624,
398,
340,
298,
12150,
3467,
2,
440,
315,
291,
14,
1943,
63,
15680,
26,
288,
291,
14,
1943,
63,
15680,
905,
12150,
3467,
937,
275,
291,
423,
475,
63,
12150,
3467,
342,
398,
372,
291,
14,
1943,
63,
15680,
905,
12150,
3467,
937,
339,
768,
1829,
272,
347,
308,
5206,
63,
1943,
8,
277,
304,
267,
408,
437,
2948,
88,
1960,
21977,
3467,
2787,
370,
506,
1202,
367,
428,
16590,
624,
398,
340,
298,
83,
5206,
2,
440,
315,
291,
14,
1943,
63,
15680,
26,
288,
291,
14,
1943,
63,
15680,
905,
83,
5206,
937,
275,
291,
423,
475,
63,
83,
5206,
342,
398,
372,
291,
14,
1943,
63,
15680,
905,
83,
5206,
937,
339,
768,
1829,
272,
347,
2746,
63,
2326,
8,
277,
304,
267,
4569,
12,
3462,
12,
9245,
275,
291,
14,
69,
2056,
273,
63,
12588,
63,
1943,
14,
1392,
267,
1338,
12,
8242,
275,
980,
14,
3235,
8,
277,
14,
69,
2056,
273,
63,
12588,
63,
1943,
14,
5217,
8,
2063,
627,
4569,
12,
9245,
395,
3114,
29,
16,
12,
372,
63,
6851,
29,
549,
9,
398,
372,
359,
442,
8,
73,
9,
367,
284,
315,
1338,
59,
1590,
14,
20188,
8,
6851,
2788,
21123,
17,
1527,
16,
20737,
339,
347,
6540,
63,
83,
5206,
8,
277,
12,
4136,
63,
5097,
63,
1943,
304,
267,
372,
2386,
1569,
14,
9580,
14,
5785,
63,
83,
5206,
8,
6352,
63,
5097,
63,
1943,
14,
83,
5206,
63,
1943,
12,
291,
14,
83,
5206,
63,
1943,
9,
339,
347,
8865,
8,
277,
12,
4136,
63,
5097,
63,
1943,
304,
267,
1453,
275,
2386,
1569,
14,
4273,
14,
22911,
8,
277,
14,
12150,
3467,
63,
1943,
12,
1695,
9,
267,
4136,
275,
2386,
1569,
14,
4273,
14,
22911,
8,
6352,
63,
5097,
63,
1943,
14,
12150,
3467,
63,
1943,
12,
1695,
9,
398,
372,
1453,
446,
4136,
339,
347,
370,
63,
80,
382,
8,
277,
304,
267,
372,
6047,
14,
504,
1144,
8,
277,
14,
1943,
9,
339,
347,
370,
63,
4524,
63,
2394,
8,
277,
304,
267,
299,
382,
63,
1943,
275,
6047,
14,
504,
1144,
8,
1339,
1569,
14,
1974,
14,
4060,
63,
305,
63,
20790,
8,
277,
14,
1943,
430,
398,
340,
822,
8,
277,
14,
1943,
14,
1392,
9,
508,
650,
26,
288,
299,
382,
63,
1943,
275,
299,
382,
63,
1943,
14,
3916,
480,
12067,
531,
398,
25296,
63,
1943,
275,
5890,
14,
15466,
342,
398,
299,
382,
63,
1943,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
cognitiveclass/edx-platform
|
common/djangoapps/embargo/tests/test_forms.py
|
132
|
4829
|
# -*- coding: utf-8 -*-
"""
Unit tests for embargo app admin forms.
"""
from django.test import TestCase
from opaque_keys.edx.locator import CourseLocator
# Explicitly import the cache from ConfigurationModel so we can reset it after each test
from config_models.models import cache
from embargo.models import IPFilter
from embargo.forms import RestrictedCourseForm, IPFilterForm
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
class RestrictedCourseFormTest(ModuleStoreTestCase):
"""Test the course form properly validates course IDs"""
def test_save_valid_data(self):
course = CourseFactory.create()
data = {
'course_key': unicode(course.id),
'enroll_msg_key': 'default',
'access_msg_key': 'default'
}
form = RestrictedCourseForm(data=data)
self.assertTrue(form.is_valid())
def test_invalid_course_key(self):
# Invalid format for the course key
form = RestrictedCourseForm(data={'course_key': 'not/valid'})
self._assert_course_field_error(form)
def test_course_not_found(self):
course_key = CourseLocator(org='test', course='test', run='test')
form = RestrictedCourseForm(data={'course_key': course_key})
self._assert_course_field_error(form)
def _assert_course_field_error(self, form):
# Validation shouldn't work
self.assertFalse(form.is_valid())
msg = 'COURSE NOT FOUND'
self.assertIn(msg, form._errors['course_key'][0]) # pylint: disable=protected-access
with self.assertRaisesRegexp(ValueError, "The RestrictedCourse could not be created because the data didn't validate."):
form.save()
class IPFilterFormTest(TestCase):
"""Test form for adding [black|white]list IP addresses"""
def tearDown(self):
super(IPFilterFormTest, self).tearDown()
# Explicitly clear ConfigurationModel's cache so tests have a clear cache
# and don't interfere with each other
cache.clear()
def test_add_valid_ips(self):
# test adding valid ip addresses
# should be able to do both ipv4 and ipv6
# spacing should not matter
form_data = {
'whitelist': '127.0.0.1, 2003:dead:beef:4dad:23:46:bb:101, 1.1.0.1/32, 1.0.0.0/24',
'blacklist': ' 18.244.1.5 , 2002:c0a8:101::42, 18.36.22.1, 1.0.0.0/16'
}
form = IPFilterForm(data=form_data)
self.assertTrue(form.is_valid())
form.save()
whitelist = IPFilter.current().whitelist_ips
blacklist = IPFilter.current().blacklist_ips
for addr in '127.0.0.1, 2003:dead:beef:4dad:23:46:bb:101'.split(','):
self.assertIn(addr.strip(), whitelist)
for addr in '18.244.1.5, 2002:c0a8:101::42, 18.36.22.1'.split(','):
self.assertIn(addr.strip(), blacklist)
# Network tests
# ips not in whitelist network
for addr in ['1.1.0.2', '1.0.1.0']:
self.assertNotIn(addr.strip(), whitelist)
# ips in whitelist network
for addr in ['1.1.0.1', '1.0.0.100']:
self.assertIn(addr.strip(), whitelist)
# ips not in blacklist network
for addr in ['2.0.0.0', '1.1.0.0']:
self.assertNotIn(addr.strip(), blacklist)
# ips in blacklist network
for addr in ['1.0.100.0', '1.0.0.10']:
self.assertIn(addr.strip(), blacklist)
# Test clearing by adding an empty list is OK too
form_data = {
'whitelist': '',
'blacklist': ''
}
form = IPFilterForm(data=form_data)
self.assertTrue(form.is_valid())
form.save()
self.assertTrue(len(IPFilter.current().whitelist) == 0)
self.assertTrue(len(IPFilter.current().blacklist) == 0)
def test_add_invalid_ips(self):
# test adding invalid ip addresses
form_data = {
'whitelist': '.0.0.1, :dead:beef:::, 1.0.0.0/55',
'blacklist': ' 18.244.* , 999999:c0a8:101::42, 1.0.0.0/'
}
form = IPFilterForm(data=form_data)
self.assertFalse(form.is_valid())
wmsg = "Invalid IP Address(es): [u'.0.0.1', u':dead:beef:::', u'1.0.0.0/55'] Please fix the error(s) and try again."
self.assertEquals(wmsg, form._errors['whitelist'][0]) # pylint: disable=protected-access
bmsg = "Invalid IP Address(es): [u'18.244.*', u'999999:c0a8:101::42', u'1.0.0.0/'] Please fix the error(s) and try again."
self.assertEquals(bmsg, form._errors['blacklist'][0]) # pylint: disable=protected-access
with self.assertRaisesRegexp(ValueError, "The IPFilter could not be created because the data didn't validate."):
form.save()
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
5072,
2295,
367,
25316,
16308,
1145,
4628,
4513,
14,
199,
624,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
15058,
63,
1612,
14,
8268,
14,
6354,
492,
31480,
199,
199,
3,
23872,
590,
492,
314,
2581,
687,
11595,
1685,
880,
781,
883,
5305,
652,
2410,
1924,
511,
199,
504,
1101,
63,
992,
14,
992,
492,
2581,
199,
504,
25316,
16308,
14,
992,
492,
3531,
4131,
199,
504,
25316,
16308,
14,
3351,
492,
32491,
1522,
6979,
2821,
12,
3531,
4131,
2821,
199,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
17996,
1746,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
421,
199,
533,
32491,
1522,
6979,
2821,
774,
8,
27863,
304,
272,
408,
774,
314,
2518,
1824,
7684,
29280,
2518,
11449,
624,
339,
347,
511,
63,
2117,
63,
1078,
63,
576,
8,
277,
304,
267,
2518,
275,
17862,
14,
981,
342,
267,
666,
275,
469,
288,
283,
1972,
63,
498,
356,
2649,
8,
1972,
14,
344,
395,
288,
283,
14695,
63,
1328,
63,
498,
356,
283,
885,
297,
288,
283,
2732,
63,
1328,
63,
498,
356,
283,
885,
7,
267,
789,
267,
1824,
275,
32491,
1522,
6979,
2821,
8,
576,
29,
576,
9,
267,
291,
14,
1815,
8,
964,
14,
374,
63,
1078,
1012,
339,
347,
511,
63,
3197,
63,
1972,
63,
498,
8,
277,
304,
267,
327,
6378,
1475,
367,
314,
2518,
790,
267,
1824,
275,
32491,
1522,
6979,
2821,
8,
576,
3713,
1972,
63,
498,
356,
283,
1397,
15,
1078,
3071,
267,
291,
423,
479,
63,
1972,
63,
698,
63,
705,
8,
964,
9,
339,
347,
511,
63,
1972,
63,
1397,
63,
4214,
8,
277,
304,
267,
2518,
63,
498,
275,
31480,
8,
1308,
534,
396,
297,
2518,
534,
396,
297,
1255,
534,
396,
358,
267,
1824,
275,
32491,
1522,
6979,
2821,
8,
576,
3713,
1972,
63,
498,
356,
2518,
63,
498,
1552,
267,
291,
423,
479,
63,
1972,
63,
698,
63,
705,
8,
964,
9,
339,
347,
485,
479,
63,
1972,
63,
698,
63,
705,
8,
277,
12,
1824,
304,
267,
327,
19381,
9296,
1133,
1736,
267,
291,
14,
3334,
8,
964,
14,
374,
63,
1078,
1012,
398,
1499,
275,
283,
15552,
2845,
481,
47,
6131,
7,
267,
291,
14,
4080,
8,
1328,
12,
1824,
423,
2550,
459,
1972,
63,
498,
3488,
16,
566,
221,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
398,
543,
291,
14,
10835,
8,
3393,
12,
298,
1918,
32491,
1522,
6979,
4293,
440,
506,
2737,
2952,
314,
666,
9980,
1133,
4107,
30946,
288,
1824,
14,
2117,
342,
421,
199,
533,
3531,
4131,
2821,
774,
8,
1746,
304,
272,
408,
774,
1824,
367,
7791,
359,
8399,
92,
7510,
61,
513,
3531,
7149,
624,
339,
347,
6766,
8,
277,
304,
267,
1613,
8,
1772,
4131,
2821,
774,
12,
291,
680,
12336,
342,
267,
327,
23872,
590,
5436,
11595,
1685,
1159,
2581,
880,
2295,
1172,
282,
5436,
2581,
267,
327,
436,
2793,
1133,
1640,
771,
264,
543,
1924,
1163,
267,
2581,
14,
3584,
342,
339,
347,
511,
63,
525,
63,
1078,
63,
6142,
8,
277,
304,
267,
327,
511,
7791,
1686,
3384,
7149,
267,
327,
1077,
506,
7688,
370,
886,
3865,
3278,
20,
436,
3278,
22,
267,
327,
19621,
1077,
440,
17247,
267,
1824,
63,
576,
275,
469,
288,
283,
14189,
356,
283,
4195,
14,
16,
14,
16,
14,
17,
12,
13004,
26,
10957,
26,
19446,
70,
26,
20,
25805,
26,
1789,
26,
2466,
26,
2501,
26,
4893,
12,
413,
14,
17,
14,
16,
14,
17,
15,
708,
12,
413,
14,
16,
14,
16,
14,
16,
15,
1194,
297,
288,
283,
22126,
356,
283,
221,
6155,
14,
11603,
14,
17,
14,
21,
221,
2360,
221,
14790,
26,
67,
16,
65,
24,
26,
4893,
447,
2260,
12,
6155,
14,
1344,
14,
1081,
14,
17,
12,
413,
14,
16,
14,
16,
14,
16,
15,
975,
7,
267,
789,
267,
1824,
275,
3531,
4131,
2821,
8,
576,
29,
964,
63,
576,
9,
267,
291,
14,
1815,
8,
964,
14,
374,
63,
1078,
1012,
267,
1824,
14,
2117,
342,
267,
22671,
275,
3531,
4131,
14,
1818,
1252,
14189,
63,
6142,
267,
23180,
275,
3531,
4131,
14,
1818,
1252,
22126,
63,
6142,
267,
367,
5552,
315,
283,
4195,
14,
16,
14,
16,
14,
17,
12,
13004,
26,
10957,
26,
19446,
70,
26,
20,
25805,
26,
1789,
26,
2466,
26,
2501,
26,
4893,
1370,
1294,
25908,
288,
291,
14,
4080,
8,
2697,
14,
1913,
1062,
22671,
9,
267,
367,
5552,
315,
283,
1085,
14,
11603,
14,
17,
14,
21,
12,
14790,
26,
67,
16,
65,
24,
26,
4893,
447,
2260,
12,
6155,
14,
1344,
14,
1081,
14,
17,
1370,
1294,
25908,
288,
291,
14,
4080,
8,
2697,
14,
1913,
1062,
23180,
9,
398,
327,
7220,
2295,
267,
327,
15017,
440,
315,
22671,
2784,
267,
367,
5552,
315,
788,
17,
14,
17,
14,
16,
14,
18,
297,
283,
17,
14,
16,
14,
17,
14,
16,
2565,
288,
291,
14,
8795,
8,
2697,
14,
1913,
1062,
22671,
9,
267,
327,
15017,
315,
22671,
2784,
267,
367,
5552,
315,
788,
17,
14,
17,
14,
16,
14,
17,
297,
283,
17,
14,
16,
14,
16,
14,
1960,
2565,
288,
291,
14,
4080,
8,
2697,
14,
1913,
1062,
22671,
9,
267,
327,
15017,
440,
315,
23180,
2784,
267,
367,
5552,
315,
788,
18,
14,
16,
14,
16,
14,
16,
297,
283,
17,
14,
17,
14,
16,
14,
16,
2565,
288,
291,
14,
8795,
8,
2697,
14,
1913,
1062,
23180,
9,
267,
327,
15017,
315,
23180,
2784,
267,
367,
5552,
315,
788,
17,
14,
16,
14,
1960,
14,
16,
297,
283,
17,
14,
16,
14,
16,
14,
709,
2565,
288,
291,
14,
4080,
8,
2697,
14,
1913,
1062,
23180,
9,
398,
327,
1379,
5436,
316,
701,
7791,
376,
2701,
769,
365,
9949,
4634,
267,
1824,
63,
576,
275,
469,
288,
283,
14189,
356,
3260,
288,
283,
22126,
356,
2125,
267,
789,
267,
1824,
275,
3531,
4131,
2821,
8,
576,
29,
964,
63,
576,
9,
267,
291,
14,
1815,
8,
964,
14,
374,
63,
1078,
1012,
267,
1824,
14,
2117,
342,
267,
291,
14,
1815,
8,
552,
8,
1772,
4131,
14,
1818
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
5072,
2295,
367,
25316,
16308,
1145,
4628,
4513,
14,
199,
624,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
15058,
63,
1612,
14,
8268,
14,
6354,
492,
31480,
199,
199,
3,
23872,
590,
492,
314,
2581,
687,
11595,
1685,
880,
781,
883,
5305,
652,
2410,
1924,
511,
199,
504,
1101,
63,
992,
14,
992,
492,
2581,
199,
504,
25316,
16308,
14,
992,
492,
3531,
4131,
199,
504,
25316,
16308,
14,
3351,
492,
32491,
1522,
6979,
2821,
12,
3531,
4131,
2821,
199,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
17996,
1746,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
421,
199,
533,
32491,
1522,
6979,
2821,
774,
8,
27863,
304,
272,
408,
774,
314,
2518,
1824,
7684,
29280,
2518,
11449,
624,
339,
347,
511,
63,
2117,
63,
1078,
63,
576,
8,
277,
304,
267,
2518,
275,
17862,
14,
981,
342,
267,
666,
275,
469,
288,
283,
1972,
63,
498,
356,
2649,
8,
1972,
14,
344,
395,
288,
283,
14695,
63,
1328,
63,
498,
356,
283,
885,
297,
288,
283,
2732,
63,
1328,
63,
498,
356,
283,
885,
7,
267,
789,
267,
1824,
275,
32491,
1522,
6979,
2821,
8,
576,
29,
576,
9,
267,
291,
14,
1815,
8,
964,
14,
374,
63,
1078,
1012,
339,
347,
511,
63,
3197,
63,
1972,
63,
498,
8,
277,
304,
267,
327,
6378,
1475,
367,
314,
2518,
790,
267,
1824,
275,
32491,
1522,
6979,
2821,
8,
576,
3713,
1972,
63,
498,
356,
283,
1397,
15,
1078,
3071,
267,
291,
423,
479,
63,
1972,
63,
698,
63,
705,
8,
964,
9,
339,
347,
511,
63,
1972,
63,
1397,
63,
4214,
8,
277,
304,
267,
2518,
63,
498,
275,
31480,
8,
1308,
534,
396,
297,
2518,
534,
396,
297,
1255,
534,
396,
358,
267,
1824,
275,
32491,
1522,
6979,
2821,
8,
576,
3713,
1972,
63,
498,
356,
2518,
63,
498,
1552,
267,
291,
423,
479,
63,
1972,
63,
698,
63,
705,
8,
964,
9,
339,
347,
485,
479,
63,
1972,
63,
698,
63,
705,
8,
277,
12,
1824,
304,
267,
327,
19381,
9296,
1133,
1736,
267,
291,
14,
3334,
8,
964,
14,
374,
63,
1078,
1012,
398,
1499,
275,
283,
15552,
2845,
481,
47,
6131,
7,
267,
291,
14,
4080,
8,
1328,
12,
1824,
423,
2550,
459,
1972,
63,
498,
3488,
16,
566,
221,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
398,
543,
291,
14,
10835,
8,
3393,
12,
298,
1918,
32491,
1522,
6979,
4293,
440,
506,
2737,
2952,
314,
666,
9980,
1133,
4107,
30946,
288,
1824,
14,
2117,
342,
421,
199,
533,
3531,
4131,
2821,
774,
8,
1746,
304,
272,
408,
774,
1824,
367,
7791,
359,
8399,
92,
7510,
61,
513,
3531,
7149,
624,
339,
347,
6766,
8,
277,
304,
267,
1613,
8,
1772,
4131,
2821,
774,
12,
291,
680,
12336,
342,
267,
327,
23872,
590,
5436,
11595,
1685,
1159,
2581,
880,
2295,
1172,
282,
5436,
2581,
267,
327,
436,
2793,
1133,
1640,
771,
264,
543,
1924,
1163,
267,
2581,
14,
3584,
342,
339,
347,
511,
63,
525,
63,
1078,
63,
6142,
8,
277,
304,
267,
327,
511,
7791,
1686,
3384,
7149,
267,
327,
1077,
506,
7688,
370,
886,
3865,
3278,
20,
436,
3278,
22,
267,
327,
19621,
1077,
440,
17247,
267,
1824,
63,
576,
275,
469,
288,
283,
14189,
356,
283,
4195,
14,
16,
14,
16,
14,
17,
12,
13004,
26,
10957,
26,
19446,
70,
26,
20,
25805,
26,
1789,
26,
2466,
26,
2501,
26,
4893,
12,
413,
14,
17,
14,
16,
14,
17,
15,
708,
12,
413,
14,
16,
14,
16,
14,
16,
15,
1194,
297,
288,
283,
22126,
356,
283,
221,
6155,
14,
11603,
14,
17,
14,
21,
221,
2360,
221,
14790,
26,
67,
16,
65,
24,
26,
4893,
447,
2260,
12,
6155,
14,
1344,
14,
1081,
14,
17,
12,
413,
14,
16,
14,
16,
14,
16,
15,
975,
7,
267,
789,
267,
1824,
275,
3531,
4131,
2821,
8,
576,
29,
964,
63,
576,
9,
267,
291,
14,
1815,
8,
964,
14,
374,
63,
1078,
1012,
267,
1824,
14,
2117,
342,
267,
22671,
275,
3531,
4131,
14,
1818,
1252,
14189,
63,
6142,
267,
23180,
275,
3531,
4131,
14,
1818,
1252,
22126,
63,
6142,
267,
367,
5552,
315,
283,
4195,
14,
16,
14,
16,
14,
17,
12,
13004,
26,
10957,
26,
19446,
70,
26,
20,
25805,
26,
1789,
26,
2466,
26,
2501,
26,
4893,
1370,
1294,
25908,
288,
291,
14,
4080,
8,
2697,
14,
1913,
1062,
22671,
9,
267,
367,
5552,
315,
283,
1085,
14,
11603,
14,
17,
14,
21,
12,
14790,
26,
67,
16,
65,
24,
26,
4893,
447,
2260,
12,
6155,
14,
1344,
14,
1081,
14,
17,
1370,
1294,
25908,
288,
291,
14,
4080,
8,
2697,
14,
1913,
1062,
23180,
9,
398,
327,
7220,
2295,
267,
327,
15017,
440,
315,
22671,
2784,
267,
367,
5552,
315,
788,
17,
14,
17,
14,
16,
14,
18,
297,
283,
17,
14,
16,
14,
17,
14,
16,
2565,
288,
291,
14,
8795,
8,
2697,
14,
1913,
1062,
22671,
9,
267,
327,
15017,
315,
22671,
2784,
267,
367,
5552,
315,
788,
17,
14,
17,
14,
16,
14,
17,
297,
283,
17,
14,
16,
14,
16,
14,
1960,
2565,
288,
291,
14,
4080,
8,
2697,
14,
1913,
1062,
22671,
9,
267,
327,
15017,
440,
315,
23180,
2784,
267,
367,
5552,
315,
788,
18,
14,
16,
14,
16,
14,
16,
297,
283,
17,
14,
17,
14,
16,
14,
16,
2565,
288,
291,
14,
8795,
8,
2697,
14,
1913,
1062,
23180,
9,
267,
327,
15017,
315,
23180,
2784,
267,
367,
5552,
315,
788,
17,
14,
16,
14,
1960,
14,
16,
297,
283,
17,
14,
16,
14,
16,
14,
709,
2565,
288,
291,
14,
4080,
8,
2697,
14,
1913,
1062,
23180,
9,
398,
327,
1379,
5436,
316,
701,
7791,
376,
2701,
769,
365,
9949,
4634,
267,
1824,
63,
576,
275,
469,
288,
283,
14189,
356,
3260,
288,
283,
22126,
356,
2125,
267,
789,
267,
1824,
275,
3531,
4131,
2821,
8,
576,
29,
964,
63,
576,
9,
267,
291,
14,
1815,
8,
964,
14,
374,
63,
1078,
1012,
267,
1824,
14,
2117,
342,
267,
291,
14,
1815,
8,
552,
8,
1772,
4131,
14,
1818,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Nikoala/CouchPotatoServer
|
libs/pyutil/hashexpand.py
|
106
|
2890
|
# Copyright (c) 2002-2012 Zooko Wilcox-O'Hearn
# This file is part of pyutil; see README.rst for licensing terms.
import warnings
"""
Cryptographically strong pseudo-random number generator based on SHA256.
"""
class SHA256Expander:
"""
Provide a cryptographically strong pseudo-random number generator based on
SHA256. Hopefully this means that no attacker will be able to predict any
bit of output that he hasn't seen, given that he doesn't know anything about
the seed and given that he can see as many bits of output as he desires
except for the bit that he is trying to predict. Further it is hoped that
an attacker will not even be able to determine whether a given stream of
random bytes was generated by this PRNG or by flipping a coin repeatedly.
The safety of this technique has not been verified by a Real Cryptographer.
... but it is similar to the PRNG in FIPS-186...
The seed and counter are encoded in DJB's netstring format so that I
don't have to think about the possibility of ambiguity.
Note: I've since learned more about the theory of secure hash functions
and the above is a strong assumption about a secure hash function. Use
of this class should be considered deprecated and you should use a more
well-analyzed KDF (such as the nascent standard HKDF) or stream cipher or
whatever it is that you need.
"""
def __init__(self, seed=None):
warnings.warn("deprecated", DeprecationWarning)
if seed is not None:
self.seed(seed)
def seed(self, seed):
import hashlib
self.starth = hashlib.sha256('24:pyutil hash expansion v2,10:algorithm:,6:SHA256,6:value:,')
seedlen = len(seed)
seedlenstr = str(seedlen)
self.starth.update(seedlenstr)
self.starth.update(':')
self.starth.update(seed)
self.starth.update(',')
self.avail = ""
self.counter = 0
def get(self, bytes):
bytesleft = bytes
res = []
while bytesleft > 0:
if len(self.avail) == 0:
h = self.starth.copy()
counterstr = str(self.counter)
counterstrlen = len(counterstr)
counterstrlenstr = str(counterstrlen)
h.update(counterstrlenstr)
h.update(':')
h.update(counterstr)
h.update(',')
self.avail = h.digest()
self.counter += 1
numb = min(len(self.avail), bytesleft)
(chunk, self.avail,) = (self.avail[:numb], self.avail[numb:],)
res.append(chunk)
bytesleft = bytesleft - numb
resstr = ''.join(res)
assert len(resstr) == bytes
return resstr
def sha256expand(inpstr, expbytes):
return SHA256Expander(inpstr).get(expbytes)
|
gpl-3.0
|
[
3,
221,
1898,
334,
67,
9,
14790,
13,
7409,
3107,
6992,
79,
644,
382,
331,
88,
13,
47,
7,
1966,
1060,
199,
3,
221,
961,
570,
365,
1777,
402,
1134,
1974,
27,
1937,
27781,
14,
8332,
367,
32572,
2895,
14,
199,
199,
646,
3598,
199,
199,
624,
199,
17134,
25537,
16925,
15984,
13,
2355,
1329,
4306,
4079,
641,
12002,
3912,
14,
199,
624,
199,
199,
533,
12002,
3912,
4527,
11438,
26,
272,
408,
272,
22896,
282,
13230,
25537,
16925,
15984,
13,
2355,
1329,
4306,
4079,
641,
272,
12002,
3912,
14,
221,
869,
13458,
5836,
642,
4910,
626,
949,
23326,
281,
911,
506,
7688,
370,
12610,
1263,
272,
4546,
402,
1072,
626,
946,
18699,
1133,
6775,
12,
1627,
626,
946,
3181,
1133,
5715,
7003,
3595,
272,
314,
6347,
436,
1627,
626,
946,
883,
1937,
465,
5002,
5821,
402,
1072,
465,
946,
477,
338,
470,
272,
871,
367,
314,
4546,
626,
946,
365,
9936,
370,
12610,
14,
221,
28876,
652,
365,
2636,
1915,
626,
272,
376,
23326,
281,
911,
440,
2755,
506,
7688,
370,
6705,
3775,
282,
1627,
2547,
402,
272,
2196,
2783,
1990,
4046,
701,
642,
12218,
12259,
503,
701,
289,
317,
3637,
282,
21914,
27714,
14,
272,
710,
30261,
402,
642,
32414,
965,
440,
2757,
16317,
701,
282,
14849,
18855,
2180,
281,
14,
272,
2263,
1325,
652,
365,
8545,
370,
314,
12218,
12259,
315,
481,
12346,
13,
11656,
1396,
339,
710,
6347,
436,
7055,
787,
5737,
315,
577,
42,
34,
1159,
1851,
875,
1475,
880,
626,
473,
272,
2793,
1133,
1172,
370,
13516,
3595,
314,
31077,
402,
16353,
528,
24180,
14,
2286,
3390,
26,
473,
9064,
3967,
12537,
379,
1655,
3595,
314,
30629,
402,
11153,
2631,
3423,
272,
436,
314,
3432,
365,
282,
16925,
30075,
3595,
282,
11153,
2631,
805,
14,
221,
3645,
272,
402,
642,
1021,
1077,
506,
8652,
5906,
436,
1265,
1077,
675,
282,
1655,
272,
5521,
13,
4797,
7068,
1804,
3888,
334,
10180,
465,
314,
302,
305,
2946,
4465,
869,
43,
3888,
9,
503,
2547,
10830,
503,
272,
15685,
652,
365,
626,
1265,
1929,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
6347,
29,
403,
304,
267,
3598,
14,
4050,
480,
6667,
401,
13413,
9,
267,
340,
6347,
365,
440,
488,
26,
288,
291,
14,
5176,
8,
5176,
9,
339,
347,
6347,
8,
277,
12,
6347,
304,
267,
492,
8337,
267,
291,
14,
7848,
273,
275,
8337,
14,
4835,
3912,
360,
1194,
26,
647,
1974,
2631,
14819,
373,
18,
12,
709,
26,
8833,
11941,
22,
26,
8461,
3912,
12,
22,
26,
585,
11941,
358,
267,
6347,
552,
275,
822,
8,
5176,
9,
267,
6347,
552,
495,
275,
620,
8,
5176,
552,
9,
267,
291,
14,
7848,
273,
14,
873,
8,
5176,
552,
495,
9,
267,
291,
14,
7848,
273,
14,
873,
11633,
267,
291,
14,
7848,
273,
14,
873,
8,
5176,
9,
267,
291,
14,
7848,
273,
14,
873,
11917,
398,
291,
14,
18961,
275,
3087,
267,
291,
14,
5337,
275,
378,
339,
347,
664,
8,
277,
12,
2783,
304,
267,
2783,
3039,
275,
2783,
398,
522,
275,
942,
398,
1830,
2783,
3039,
690,
378,
26,
288,
340,
822,
8,
277,
14,
18961,
9,
508,
378,
26,
355,
394,
275,
291,
14,
7848,
273,
14,
1574,
342,
355,
7055,
495,
275,
620,
8,
277,
14,
5337,
9,
355,
7055,
495,
552,
275,
822,
8,
5337,
495,
9,
355,
7055,
495,
552,
495,
275,
620,
8,
5337,
495,
552,
9,
355,
394,
14,
873,
8,
5337,
495,
552,
495,
9,
355,
394,
14,
873,
11633,
355,
394,
14,
873,
8,
5337,
495,
9,
355,
394,
14,
873,
11917,
355,
291,
14,
18961,
275,
394,
14,
5671,
342,
355,
291,
14,
5337,
847,
413,
953,
1967,
66,
275,
1748,
8,
552,
8,
277,
14,
18961,
395,
2783,
3039,
9,
953,
334,
4604,
12,
291,
14,
18961,
4258,
275,
334,
277,
14,
18961,
1491,
1507,
66,
467,
291,
14,
18961,
59,
1507,
66,
8429,
9,
953,
522,
14,
740,
8,
4604,
9,
7846,
2783,
3039,
275,
2783,
3039,
446,
1967,
66,
398,
522,
495,
275,
6522,
904,
8,
470,
9,
267,
702,
822,
8,
470,
495,
9,
508,
2783,
398,
372,
522,
495,
199,
199,
318,
7793,
3912,
4441,
8,
11416,
495,
12,
1437,
2394,
304,
272,
372,
12002,
3912,
4527,
11438,
8,
11416,
495,
680,
362,
8,
1474,
2394,
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
] |
[
221,
1898,
334,
67,
9,
14790,
13,
7409,
3107,
6992,
79,
644,
382,
331,
88,
13,
47,
7,
1966,
1060,
199,
3,
221,
961,
570,
365,
1777,
402,
1134,
1974,
27,
1937,
27781,
14,
8332,
367,
32572,
2895,
14,
199,
199,
646,
3598,
199,
199,
624,
199,
17134,
25537,
16925,
15984,
13,
2355,
1329,
4306,
4079,
641,
12002,
3912,
14,
199,
624,
199,
199,
533,
12002,
3912,
4527,
11438,
26,
272,
408,
272,
22896,
282,
13230,
25537,
16925,
15984,
13,
2355,
1329,
4306,
4079,
641,
272,
12002,
3912,
14,
221,
869,
13458,
5836,
642,
4910,
626,
949,
23326,
281,
911,
506,
7688,
370,
12610,
1263,
272,
4546,
402,
1072,
626,
946,
18699,
1133,
6775,
12,
1627,
626,
946,
3181,
1133,
5715,
7003,
3595,
272,
314,
6347,
436,
1627,
626,
946,
883,
1937,
465,
5002,
5821,
402,
1072,
465,
946,
477,
338,
470,
272,
871,
367,
314,
4546,
626,
946,
365,
9936,
370,
12610,
14,
221,
28876,
652,
365,
2636,
1915,
626,
272,
376,
23326,
281,
911,
440,
2755,
506,
7688,
370,
6705,
3775,
282,
1627,
2547,
402,
272,
2196,
2783,
1990,
4046,
701,
642,
12218,
12259,
503,
701,
289,
317,
3637,
282,
21914,
27714,
14,
272,
710,
30261,
402,
642,
32414,
965,
440,
2757,
16317,
701,
282,
14849,
18855,
2180,
281,
14,
272,
2263,
1325,
652,
365,
8545,
370,
314,
12218,
12259,
315,
481,
12346,
13,
11656,
1396,
339,
710,
6347,
436,
7055,
787,
5737,
315,
577,
42,
34,
1159,
1851,
875,
1475,
880,
626,
473,
272,
2793,
1133,
1172,
370,
13516,
3595,
314,
31077,
402,
16353,
528,
24180,
14,
2286,
3390,
26,
473,
9064,
3967,
12537,
379,
1655,
3595,
314,
30629,
402,
11153,
2631,
3423,
272,
436,
314,
3432,
365,
282,
16925,
30075,
3595,
282,
11153,
2631,
805,
14,
221,
3645,
272,
402,
642,
1021,
1077,
506,
8652,
5906,
436,
1265,
1077,
675,
282,
1655,
272,
5521,
13,
4797,
7068,
1804,
3888,
334,
10180,
465,
314,
302,
305,
2946,
4465,
869,
43,
3888,
9,
503,
2547,
10830,
503,
272,
15685,
652,
365,
626,
1265,
1929,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
6347,
29,
403,
304,
267,
3598,
14,
4050,
480,
6667,
401,
13413,
9,
267,
340,
6347,
365,
440,
488,
26,
288,
291,
14,
5176,
8,
5176,
9,
339,
347,
6347,
8,
277,
12,
6347,
304,
267,
492,
8337,
267,
291,
14,
7848,
273,
275,
8337,
14,
4835,
3912,
360,
1194,
26,
647,
1974,
2631,
14819,
373,
18,
12,
709,
26,
8833,
11941,
22,
26,
8461,
3912,
12,
22,
26,
585,
11941,
358,
267,
6347,
552,
275,
822,
8,
5176,
9,
267,
6347,
552,
495,
275,
620,
8,
5176,
552,
9,
267,
291,
14,
7848,
273,
14,
873,
8,
5176,
552,
495,
9,
267,
291,
14,
7848,
273,
14,
873,
11633,
267,
291,
14,
7848,
273,
14,
873,
8,
5176,
9,
267,
291,
14,
7848,
273,
14,
873,
11917,
398,
291,
14,
18961,
275,
3087,
267,
291,
14,
5337,
275,
378,
339,
347,
664,
8,
277,
12,
2783,
304,
267,
2783,
3039,
275,
2783,
398,
522,
275,
942,
398,
1830,
2783,
3039,
690,
378,
26,
288,
340,
822,
8,
277,
14,
18961,
9,
508,
378,
26,
355,
394,
275,
291,
14,
7848,
273,
14,
1574,
342,
355,
7055,
495,
275,
620,
8,
277,
14,
5337,
9,
355,
7055,
495,
552,
275,
822,
8,
5337,
495,
9,
355,
7055,
495,
552,
495,
275,
620,
8,
5337,
495,
552,
9,
355,
394,
14,
873,
8,
5337,
495,
552,
495,
9,
355,
394,
14,
873,
11633,
355,
394,
14,
873,
8,
5337,
495,
9,
355,
394,
14,
873,
11917,
355,
291,
14,
18961,
275,
394,
14,
5671,
342,
355,
291,
14,
5337,
847,
413,
953,
1967,
66,
275,
1748,
8,
552,
8,
277,
14,
18961,
395,
2783,
3039,
9,
953,
334,
4604,
12,
291,
14,
18961,
4258,
275,
334,
277,
14,
18961,
1491,
1507,
66,
467,
291,
14,
18961,
59,
1507,
66,
8429,
9,
953,
522,
14,
740,
8,
4604,
9,
7846,
2783,
3039,
275,
2783,
3039,
446,
1967,
66,
398,
522,
495,
275,
6522,
904,
8,
470,
9,
267,
702,
822,
8,
470,
495,
9,
508,
2783,
398,
372,
522,
495,
199,
199,
318,
7793,
3912,
4441,
8,
11416,
495,
12,
1437,
2394,
304,
272,
372,
12002,
3912,
4527,
11438,
8,
11416,
495,
680,
362,
8,
1474,
2394,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mdeejay/android_kernel_dlxub1
|
tools/perf/scripts/python/futex-contention.py
|
11261
|
1486
|
# futex contention
# (c) 2010, Arnaldo Carvalho de Melo <acme@redhat.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Translation of:
#
# http://sourceware.org/systemtap/wiki/WSFutexContention
#
# to perf python scripting.
#
# Measures futex contention
import os, sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from Util import *
process_names = {}
thread_thislock = {}
thread_blocktime = {}
lock_waits = {} # long-lived stats on (tid,lock) blockage elapsed time
process_names = {} # long-lived pid-to-execname mapping
def syscalls__sys_enter_futex(event, ctxt, cpu, s, ns, tid, comm,
nr, uaddr, op, val, utime, uaddr2, val3):
cmd = op & FUTEX_CMD_MASK
if cmd != FUTEX_WAIT:
return # we don't care about originators of WAKE events
process_names[tid] = comm
thread_thislock[tid] = uaddr
thread_blocktime[tid] = nsecs(s, ns)
def syscalls__sys_exit_futex(event, ctxt, cpu, s, ns, tid, comm,
nr, ret):
if thread_blocktime.has_key(tid):
elapsed = nsecs(s, ns) - thread_blocktime[tid]
add_stats(lock_waits, (tid, thread_thislock[tid]), elapsed)
del thread_blocktime[tid]
del thread_thislock[tid]
def trace_begin():
print "Press control+C to stop and show the summary"
def trace_end():
for (tid, lock) in lock_waits:
min, max, avg, count = lock_waits[tid, lock]
print "%s[%d] lock %x contended %d times, %d avg ns" % \
(process_names[tid], tid, lock, count, avg)
|
gpl-2.0
|
[
3,
289,
18173,
406,
9553,
199,
3,
334,
67,
9,
7129,
12,
1952,
78,
279,
1117,
14243,
637,
526,
477,
3194,
320,
665,
18107,
32,
17164,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
25224,
402,
26,
199,
3,
199,
3,
1455,
921,
1365,
1068,
14,
1308,
15,
2253,
16609,
15,
6797,
15,
5035,
38,
18173,
714,
9553,
199,
3,
199,
3,
370,
8582,
2366,
2884,
316,
14,
199,
3,
199,
3,
3194,
305,
1482,
289,
18173,
406,
9553,
199,
199,
646,
747,
12,
984,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
1994,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
504,
21248,
492,
627,
199,
199,
1412,
63,
1247,
275,
1052,
199,
2671,
63,
3749,
831,
275,
1052,
199,
2671,
63,
1457,
521,
275,
1052,
199,
199,
831,
63,
758,
1405,
275,
1052,
327,
1846,
13,
317,
1354,
5020,
641,
334,
5700,
12,
831,
9,
1853,
474,
14439,
900,
199,
1412,
63,
1247,
275,
1052,
327,
1846,
13,
317,
1354,
4422,
13,
475,
13,
1628,
354,
4412,
199,
199,
318,
19473,
363,
1274,
63,
4200,
63,
70,
18173,
8,
1430,
12,
11216,
12,
5033,
12,
308,
12,
700,
12,
11559,
12,
1923,
12,
1585,
420,
14762,
12,
399,
2697,
12,
1687,
12,
1139,
12,
399,
521,
12,
399,
2697,
18,
12,
1139,
19,
304,
199,
198,
1760,
275,
1687,
1253,
481,
934,
1438,
63,
9744,
63,
12880,
199,
198,
692,
2088,
1137,
481,
934,
1438,
63,
12458,
26,
507,
198,
1107,
327,
781,
2793,
1133,
10296,
3595,
6330,
2750,
402,
644,
22339,
4474,
421,
198,
1412,
63,
1247,
59,
5700,
61,
275,
1923,
199,
198,
2671,
63,
3749,
831,
59,
5700,
61,
275,
399,
2697,
199,
198,
2671,
63,
1457,
521,
59,
5700,
61,
275,
13781,
8,
83,
12,
700,
9,
199,
199,
318,
19473,
363,
1274,
63,
2224,
63,
70,
18173,
8,
1430,
12,
11216,
12,
5033,
12,
308,
12,
700,
12,
11559,
12,
1923,
12,
1585,
258,
14762,
12,
2203,
304,
199,
198,
692,
2462,
63,
1457,
521,
14,
1989,
63,
498,
8,
5700,
304,
507,
198,
16691,
275,
13781,
8,
83,
12,
700,
9,
446,
2462,
63,
1457,
521,
59,
5700,
61,
507,
198,
525,
63,
3200,
8,
831,
63,
758,
1405,
12,
334,
5700,
12,
2462,
63,
3749,
831,
59,
5700,
2522,
14439,
9,
507,
198,
2264,
2462,
63,
1457,
521,
59,
5700,
61,
507,
198,
2264,
2462,
63,
3749,
831,
59,
5700,
61,
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,
509,
334,
5700,
12,
4650,
9,
315,
4650,
63,
758,
1405,
26,
507,
198,
827,
12,
1390,
12,
12402,
12,
2338,
275,
4650,
63,
758,
1405,
59,
5700,
12,
4650,
61,
507,
198,
1361,
2071,
83,
9722,
68,
61,
4650,
450,
88,
406,
6943,
450,
68,
5431,
12,
450,
68,
12402,
700,
2,
450,
971,
686,
420,
334,
1412,
63,
1247,
59,
5700,
467,
11559,
12,
4650,
12,
2338,
12,
12402,
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
] |
[
289,
18173,
406,
9553,
199,
3,
334,
67,
9,
7129,
12,
1952,
78,
279,
1117,
14243,
637,
526,
477,
3194,
320,
665,
18107,
32,
17164,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
25224,
402,
26,
199,
3,
199,
3,
1455,
921,
1365,
1068,
14,
1308,
15,
2253,
16609,
15,
6797,
15,
5035,
38,
18173,
714,
9553,
199,
3,
199,
3,
370,
8582,
2366,
2884,
316,
14,
199,
3,
199,
3,
3194,
305,
1482,
289,
18173,
406,
9553,
199,
199,
646,
747,
12,
984,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
1994,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
504,
21248,
492,
627,
199,
199,
1412,
63,
1247,
275,
1052,
199,
2671,
63,
3749,
831,
275,
1052,
199,
2671,
63,
1457,
521,
275,
1052,
199,
199,
831,
63,
758,
1405,
275,
1052,
327,
1846,
13,
317,
1354,
5020,
641,
334,
5700,
12,
831,
9,
1853,
474,
14439,
900,
199,
1412,
63,
1247,
275,
1052,
327,
1846,
13,
317,
1354,
4422,
13,
475,
13,
1628,
354,
4412,
199,
199,
318,
19473,
363,
1274,
63,
4200,
63,
70,
18173,
8,
1430,
12,
11216,
12,
5033,
12,
308,
12,
700,
12,
11559,
12,
1923,
12,
1585,
420,
14762,
12,
399,
2697,
12,
1687,
12,
1139,
12,
399,
521,
12,
399,
2697,
18,
12,
1139,
19,
304,
199,
198,
1760,
275,
1687,
1253,
481,
934,
1438,
63,
9744,
63,
12880,
199,
198,
692,
2088,
1137,
481,
934,
1438,
63,
12458,
26,
507,
198,
1107,
327,
781,
2793,
1133,
10296,
3595,
6330,
2750,
402,
644,
22339,
4474,
421,
198,
1412,
63,
1247,
59,
5700,
61,
275,
1923,
199,
198,
2671,
63,
3749,
831,
59,
5700,
61,
275,
399,
2697,
199,
198,
2671,
63,
1457,
521,
59,
5700,
61,
275,
13781,
8,
83,
12,
700,
9,
199,
199,
318,
19473,
363,
1274,
63,
2224,
63,
70,
18173,
8,
1430,
12,
11216,
12,
5033,
12,
308,
12,
700,
12,
11559,
12,
1923,
12,
1585,
258,
14762,
12,
2203,
304,
199,
198,
692,
2462,
63,
1457,
521,
14,
1989,
63,
498,
8,
5700,
304,
507,
198,
16691,
275,
13781,
8,
83,
12,
700,
9,
446,
2462,
63,
1457,
521,
59,
5700,
61,
507,
198,
525,
63,
3200,
8,
831,
63,
758,
1405,
12,
334,
5700,
12,
2462,
63,
3749,
831,
59,
5700,
2522,
14439,
9,
507,
198,
2264,
2462,
63,
1457,
521,
59,
5700,
61,
507,
198,
2264,
2462,
63,
3749,
831,
59,
5700,
61,
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,
509,
334,
5700,
12,
4650,
9,
315,
4650,
63,
758,
1405,
26,
507,
198,
827,
12,
1390,
12,
12402,
12,
2338,
275,
4650,
63,
758,
1405,
59,
5700,
12,
4650,
61,
507,
198,
1361,
2071,
83,
9722,
68,
61,
4650,
450,
88,
406,
6943,
450,
68,
5431,
12,
450,
68,
12402,
700,
2,
450,
971,
686,
420,
334,
1412,
63,
1247,
59,
5700,
467,
11559,
12,
4650,
12,
2338,
12,
12402,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
andreslechuga/arte_mexicano_antiguo
|
felipegerard/code/luigi/itm/build/lib/itm/ShowLDA.py
|
4
|
5168
|
# coding=utf-8
#DESPUES DE PREDICTLDA
#ANTES DE TrainLSI
import luigi
import os
import re
import pickle
import json
from pprint import pprint
from lda import TrainLDA, PredictLDA
class ShowLDA(luigi.Task):
"""Necesita PredictLDA y
TrainLDA """
#variables de ShowLDA
res_dir = luigi.Parameter()
#variables de LDA
topic_range = luigi.Parameter(default='30,31,1') #numero de topicos
by_chunks = luigi.BoolParameter(default=False)
chunk_size = luigi.IntParameter(default=100)
update_e = luigi.IntParameter(default = 0)
n_passes = luigi.IntParameter(default=10) #numero de pasadas al corpus
#variables de corpus
pdf_dir = luigi.Parameter()
txt_dir = luigi.Parameter()
#jpg_dir = luigi.Parameter()
#image_meta_dir = luigi.Parameter()
model_dir = luigi.Parameter()
meta_dir = luigi.Parameter(default='meta')
meta_file = luigi.Parameter(default='librosAgregados.txt')
lang_file = luigi.Parameter(default='idiomas.txt') # Solo para tener el registro
clean_level = luigi.Parameter(default='stopwords')
languages = luigi.Parameter()
max_word_length = luigi.IntParameter(default=6)
min_docs_per_lang = luigi.IntParameter(default=1)
def requires(self):
return {
'lda':TrainLDA(topic_range=self.topic_range,
by_chunks=self.by_chunks,
chunk_size=self.chunk_size,
update_e=self.update_e,
n_passes=self.n_passes,
pdf_dir=self.pdf_dir,
txt_dir=self.txt_dir,
#jpg_dir = self.jpg_dir,
#image_meta_dir = self.image_meta_dir,
model_dir=self.model_dir,
meta_dir=self.meta_dir,
meta_file=self.meta_file,
lang_file=self.lang_file,
clean_level=self.clean_level,
languages=self.languages,
max_word_length=self.max_word_length,
min_docs_per_lang=self.min_docs_per_lang),
'corp_LDA':PredictLDA(res_dir=self.res_dir,
topic_range=self.topic_range,
by_chunks=self.by_chunks,
chunk_size=self.chunk_size,
update_e=self.update_e,
n_passes=self.n_passes,
pdf_dir=self.pdf_dir,
txt_dir=self.txt_dir,
#jpg_dir = self.jpg_dir,
#image_meta_dir = self.image_meta_dir,
model_dir=self.model_dir,
meta_dir=self.meta_dir,
meta_file=self.meta_file,
lang_file=self.lang_file,
clean_level=self.clean_level,
languages=self.languages,
max_word_length=self.max_word_length,
min_docs_per_lang=self.min_docs_per_lang)
}
################################CHECAR OUTPUT#################
def output(self):
topic_range = self.topic_range.split(',')
topic_range = [int(i) for i in topic_range]
topic_range = range(topic_range[0],topic_range[1],topic_range[2])
if self.clean_level in ('raw','clean','stopwords'):
kind = self.clean_level
else:
kind = 'stopwords'
return {
'langs':
{
idioma:
{
n_topics:
luigi.LocalTarget(os.path.join(self.res_dir, 'lda_results_%s_%s_%d.json' % (kind, idioma, n_topics)))
for n_topics in topic_range
}
for idioma in self.input()['corp_LDA']['langs'].iterkeys()
},
'files':self.input()['corp_LDA']['files']
}
def run(self):
if self.clean_level in ('raw','clean','stopwords'):
kind = self.clean_level
else:
kind = 'stopwords'
if not os.path.exists(self.res_dir):
print 'Creando carpeta para resultados...'
os.mkdir(self.res_dir)
for idioma, modelos in self.input()['lda']['langs'].iteritems(): # <<-- n_topics aqui en realidad es un dict con {ntopics:target}. Le cambie el nombre a modelos
print '======= paso 1 ========='
# corp_path1 = self.input()['corp_LDA']['langs'][idioma][n_topics]["doc_topics"].path # <<-- Por eso esto no funciona
# corp_path2 = self.input()['corp_LDA']['langs'][idioma][n_topics]["topics"].path # <<-- Ni esto
print '------------------------------'
print 'vamos por buen camino'
for n_topics, target in modelos.iteritems(): # <<-- No habias definido modelos, pero ahora ya esta y adentro de modelos esta ntopics y target
print idioma
# print modelos.keys()
#corp_path1 = self.input()['corp_LDA']['langs'][idioma][n_topics]["doc_topics"].path
#corp_path2 = self.input()['corp_LDA']['langs'][idioma][n_topics]["topics"].path
with self.input()['corp_LDA']['langs'][idioma][n_topics]["doc_topics"].open('r') as f:
topic_results = pickle.load(f)
with self.input()['corp_LDA']['langs'][idioma][n_topics]["topics"].open('r') as r:
topics = pickle.load(r)
high_topics = [max(x, key=lambda y: y[1]) for x in topic_results]
files = [i.replace('.txt', '') for i in os.listdir(os.path.join(self.txt_dir,kind,idioma))]
res = {
i:{
'formula':topic,
'tags':re.sub(' \+ [\.0-9]+\*', ', ', re.sub('[\.0-9]+\*', '', topic, count=1)),
'documents':[]
}
for i, topic in enumerate(topics)
}
for num_doc,(num_topic, s) in enumerate(high_topics):
res[num_topic]['documents'].append({
'name':files[num_doc],
'topic_similarity':s
})
pprint(res)
with self.output()['langs'][idioma][n_topics].open('w') as f:
json.dump(res, f)
|
agpl-3.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
4448,
6903,
654,
3265,
510,
7387,
6196,
6533,
33,
199,
3,
1441,
654,
3265,
16732,
44,
2684,
199,
646,
19485,
199,
646,
747,
199,
646,
295,
199,
646,
5927,
199,
646,
2022,
199,
504,
10933,
492,
10933,
199,
199,
504,
634,
983,
492,
16732,
6533,
33,
12,
5543,
807,
6533,
33,
199,
199,
533,
12968,
6533,
33,
8,
26795,
14,
4476,
304,
199,
198,
624,
4698,
301,
338,
502,
5543,
807,
6533,
33,
612,
9948,
198,
18591,
6533,
33,
408,
199,
198,
3,
3669,
477,
12968,
6533,
33,
199,
198,
470,
63,
694,
275,
19485,
14,
4720,
342,
421,
198,
3,
3669,
477,
491,
8980,
199,
198,
5746,
63,
1842,
275,
19485,
14,
4720,
8,
885,
534,
1216,
12,
2192,
12,
17,
358,
327,
10563,
293,
477,
370,
1038,
5197,
199,
198,
991,
63,
10660,
275,
19485,
14,
10349,
4720,
8,
885,
29,
797,
9,
199,
198,
4604,
63,
890,
275,
19485,
14,
3241,
4720,
8,
885,
29,
1960,
9,
199,
198,
873,
63,
69,
275,
19485,
14,
3241,
4720,
8,
885,
275,
378,
9,
199,
198,
78,
63,
16027,
275,
19485,
14,
3241,
4720,
8,
885,
29,
709,
9,
327,
10563,
293,
477,
19099,
350,
305,
741,
16831,
421,
198,
3,
3669,
477,
16831,
199,
198,
5607,
63,
694,
275,
19485,
14,
4720,
342,
199,
198,
2424,
63,
694,
275,
19485,
14,
4720,
342,
199,
198,
3,
8476,
63,
694,
275,
19485,
14,
4720,
342,
199,
198,
3,
1569,
63,
2024,
63,
694,
275,
19485,
14,
4720,
342,
199,
198,
1238,
63,
694,
275,
19485,
14,
4720,
342,
199,
198,
2024,
63,
694,
275,
19485,
14,
4720,
8,
885,
534,
2024,
358,
199,
198,
2024,
63,
493,
275,
19485,
14,
4720,
8,
885,
534,
773,
4796,
33,
3939,
20257,
14,
2424,
358,
199,
198,
4159,
63,
493,
275,
19485,
14,
4720,
8,
885,
534,
9897,
676,
305,
14,
2424,
358,
327,
2002,
320,
12665,
16685,
281,
579,
25483,
293,
199,
198,
3118,
63,
1896,
275,
19485,
14,
4720,
8,
885,
534,
2379,
3148,
358,
199,
198,
13209,
275,
19485,
14,
4720,
342,
199,
198,
988,
63,
1027,
63,
1267,
275,
19485,
14,
3241,
4720,
8,
885,
29,
22,
9,
199,
198,
827,
63,
4757,
63,
529,
63,
4159,
275,
19485,
14,
3241,
4720,
8,
885,
29,
17,
9,
4388,
198,
318,
5074,
8,
277,
304,
507,
198,
1107,
469,
686,
198,
7,
76,
983,
356,
18591,
6533,
33,
8,
5746,
63,
1842,
29,
277,
14,
5746,
63,
1842,
12,
5264,
198,
991,
63,
10660,
29,
277,
14,
991,
63,
10660,
12,
5264,
198,
4604,
63,
890,
29,
277,
14,
4604,
63,
890,
12,
5264,
198,
873,
63,
69,
29,
277,
14,
873,
63,
69,
12,
5264,
198,
78,
63,
16027,
29,
277,
14,
78,
63,
16027,
12,
5264,
198,
5607,
63,
694,
29,
277,
14,
5607,
63,
694,
12,
5264,
198,
2424,
63,
694,
29,
277,
14,
2424,
63,
694,
12,
5264,
198,
3,
8476,
63,
694,
275,
291,
14,
8476,
63,
694,
12,
5264,
198,
3,
1569,
63,
2024,
63,
694,
275,
291,
14,
1569,
63,
2024,
63,
694,
12,
5264,
198,
1238,
63,
694,
29,
277,
14,
1238,
63,
694,
12,
5264,
198,
2024,
63,
694,
29,
277,
14,
2024,
63,
694,
12,
5264,
198,
2024,
63,
493,
29,
277,
14,
2024,
63,
493,
12,
5264,
198,
4159,
63,
493,
29,
277,
14,
4159,
63,
493,
12,
5264,
198,
3118,
63,
1896,
29,
277,
14,
3118,
63,
1896,
12,
5264,
198,
13209,
29,
277,
14,
13209,
12,
5264,
198,
988,
63,
1027,
63,
1267,
29,
277,
14,
988,
63,
1027,
63,
1267,
12,
5264,
198,
827,
63,
4757,
63,
529,
63,
4159,
29,
277,
14,
827,
63,
4757,
63,
529,
63,
4159,
395,
6319,
198,
7,
989,
80,
63,
6533,
33,
356,
28240,
6533,
33,
8,
470,
63,
694,
29,
277,
14,
470,
63,
694,
12,
5264,
198,
5746,
63,
1842,
29,
277,
14,
5746,
63,
1842,
12,
5264,
198,
991,
63,
10660,
29,
277,
14,
991,
63,
10660,
12,
5264,
198,
4604,
63,
890,
29,
277,
14,
4604,
63,
890,
12,
5264,
198,
873,
63,
69,
29,
277,
14,
873,
63,
69,
12,
5264,
198,
78,
63,
16027,
29,
277,
14,
78,
63,
16027,
12,
221,
5264,
198,
5607,
63,
694,
29,
277,
14,
5607,
63,
694,
12,
5264,
198,
2424,
63,
694,
29,
277,
14,
2424,
63,
694,
12,
5264,
198,
3,
8476,
63,
694,
275,
291,
14,
8476,
63,
694,
12,
5264,
198,
3,
1569,
63,
2024,
63,
694,
275,
291,
14,
1569,
63,
2024,
63,
694,
12,
5264,
198,
1238,
63,
694,
29,
277,
14,
1238,
63,
694,
12,
5264,
198,
2024,
63,
694,
29,
277,
14,
2024,
63,
694,
12,
5264,
198,
2024,
63,
493,
29,
277,
14,
2024,
63,
493,
12,
5264,
198,
4159,
63,
493,
29,
277,
14,
4159,
63,
493,
12,
5264,
198,
3118,
63,
1896,
29,
277,
14,
3118,
63,
1896,
12,
5264,
198,
13209,
29,
277,
14,
13209,
12,
5264,
198,
988,
63,
1027,
63,
1267,
29,
277,
14,
988,
63,
1027,
63,
1267,
12,
5264,
198,
827,
63,
4757,
63,
529,
63,
4159,
29,
277,
14,
827,
63,
4757,
63,
529,
63,
4159,
9,
4671,
198,
93,
421,
199,
1371,
1244,
4220,
689,
18746,
749,
3,
199,
198,
318,
1072,
8,
277,
304,
507,
198,
5746,
63,
1842,
275,
291,
14,
5746,
63,
1842,
14,
1294,
11917,
507,
198,
5746,
63,
1842,
275,
359,
442,
8,
73,
9,
367,
284,
315,
7482,
63,
1842,
61,
507,
198,
5746,
63,
1842,
275,
1425,
8,
5746,
63,
1842,
59,
16,
467,
5746,
63,
1842,
59,
17,
467,
5746,
63,
1842,
59,
18,
566,
507,
198,
692,
291,
14,
3118,
63,
1896,
315,
661,
1773,
1673,
3118,
1673,
2379,
3148,
735,
686,
198,
5091,
275,
291,
14,
3118,
63,
1896,
507,
198,
2836,
26,
686,
198,
5091,
275,
283,
2379,
3148,
7,
9068,
198,
1107,
469,
1871,
198,
7,
28182,
356,
1871,
198,
91,
4671,
198,
73,
3006,
391,
26,
4671,
198,
91,
5264,
198,
78,
63,
11299,
26,
11674,
22680,
19485,
14,
5339,
4277,
8,
736,
14,
515,
14,
904,
8,
277,
14,
470
] |
[
2803,
29,
1624,
13,
24,
199,
3,
4448,
6903,
654,
3265,
510,
7387,
6196,
6533,
33,
199,
3,
1441,
654,
3265,
16732,
44,
2684,
199,
646,
19485,
199,
646,
747,
199,
646,
295,
199,
646,
5927,
199,
646,
2022,
199,
504,
10933,
492,
10933,
199,
199,
504,
634,
983,
492,
16732,
6533,
33,
12,
5543,
807,
6533,
33,
199,
199,
533,
12968,
6533,
33,
8,
26795,
14,
4476,
304,
199,
198,
624,
4698,
301,
338,
502,
5543,
807,
6533,
33,
612,
9948,
198,
18591,
6533,
33,
408,
199,
198,
3,
3669,
477,
12968,
6533,
33,
199,
198,
470,
63,
694,
275,
19485,
14,
4720,
342,
421,
198,
3,
3669,
477,
491,
8980,
199,
198,
5746,
63,
1842,
275,
19485,
14,
4720,
8,
885,
534,
1216,
12,
2192,
12,
17,
358,
327,
10563,
293,
477,
370,
1038,
5197,
199,
198,
991,
63,
10660,
275,
19485,
14,
10349,
4720,
8,
885,
29,
797,
9,
199,
198,
4604,
63,
890,
275,
19485,
14,
3241,
4720,
8,
885,
29,
1960,
9,
199,
198,
873,
63,
69,
275,
19485,
14,
3241,
4720,
8,
885,
275,
378,
9,
199,
198,
78,
63,
16027,
275,
19485,
14,
3241,
4720,
8,
885,
29,
709,
9,
327,
10563,
293,
477,
19099,
350,
305,
741,
16831,
421,
198,
3,
3669,
477,
16831,
199,
198,
5607,
63,
694,
275,
19485,
14,
4720,
342,
199,
198,
2424,
63,
694,
275,
19485,
14,
4720,
342,
199,
198,
3,
8476,
63,
694,
275,
19485,
14,
4720,
342,
199,
198,
3,
1569,
63,
2024,
63,
694,
275,
19485,
14,
4720,
342,
199,
198,
1238,
63,
694,
275,
19485,
14,
4720,
342,
199,
198,
2024,
63,
694,
275,
19485,
14,
4720,
8,
885,
534,
2024,
358,
199,
198,
2024,
63,
493,
275,
19485,
14,
4720,
8,
885,
534,
773,
4796,
33,
3939,
20257,
14,
2424,
358,
199,
198,
4159,
63,
493,
275,
19485,
14,
4720,
8,
885,
534,
9897,
676,
305,
14,
2424,
358,
327,
2002,
320,
12665,
16685,
281,
579,
25483,
293,
199,
198,
3118,
63,
1896,
275,
19485,
14,
4720,
8,
885,
534,
2379,
3148,
358,
199,
198,
13209,
275,
19485,
14,
4720,
342,
199,
198,
988,
63,
1027,
63,
1267,
275,
19485,
14,
3241,
4720,
8,
885,
29,
22,
9,
199,
198,
827,
63,
4757,
63,
529,
63,
4159,
275,
19485,
14,
3241,
4720,
8,
885,
29,
17,
9,
4388,
198,
318,
5074,
8,
277,
304,
507,
198,
1107,
469,
686,
198,
7,
76,
983,
356,
18591,
6533,
33,
8,
5746,
63,
1842,
29,
277,
14,
5746,
63,
1842,
12,
5264,
198,
991,
63,
10660,
29,
277,
14,
991,
63,
10660,
12,
5264,
198,
4604,
63,
890,
29,
277,
14,
4604,
63,
890,
12,
5264,
198,
873,
63,
69,
29,
277,
14,
873,
63,
69,
12,
5264,
198,
78,
63,
16027,
29,
277,
14,
78,
63,
16027,
12,
5264,
198,
5607,
63,
694,
29,
277,
14,
5607,
63,
694,
12,
5264,
198,
2424,
63,
694,
29,
277,
14,
2424,
63,
694,
12,
5264,
198,
3,
8476,
63,
694,
275,
291,
14,
8476,
63,
694,
12,
5264,
198,
3,
1569,
63,
2024,
63,
694,
275,
291,
14,
1569,
63,
2024,
63,
694,
12,
5264,
198,
1238,
63,
694,
29,
277,
14,
1238,
63,
694,
12,
5264,
198,
2024,
63,
694,
29,
277,
14,
2024,
63,
694,
12,
5264,
198,
2024,
63,
493,
29,
277,
14,
2024,
63,
493,
12,
5264,
198,
4159,
63,
493,
29,
277,
14,
4159,
63,
493,
12,
5264,
198,
3118,
63,
1896,
29,
277,
14,
3118,
63,
1896,
12,
5264,
198,
13209,
29,
277,
14,
13209,
12,
5264,
198,
988,
63,
1027,
63,
1267,
29,
277,
14,
988,
63,
1027,
63,
1267,
12,
5264,
198,
827,
63,
4757,
63,
529,
63,
4159,
29,
277,
14,
827,
63,
4757,
63,
529,
63,
4159,
395,
6319,
198,
7,
989,
80,
63,
6533,
33,
356,
28240,
6533,
33,
8,
470,
63,
694,
29,
277,
14,
470,
63,
694,
12,
5264,
198,
5746,
63,
1842,
29,
277,
14,
5746,
63,
1842,
12,
5264,
198,
991,
63,
10660,
29,
277,
14,
991,
63,
10660,
12,
5264,
198,
4604,
63,
890,
29,
277,
14,
4604,
63,
890,
12,
5264,
198,
873,
63,
69,
29,
277,
14,
873,
63,
69,
12,
5264,
198,
78,
63,
16027,
29,
277,
14,
78,
63,
16027,
12,
221,
5264,
198,
5607,
63,
694,
29,
277,
14,
5607,
63,
694,
12,
5264,
198,
2424,
63,
694,
29,
277,
14,
2424,
63,
694,
12,
5264,
198,
3,
8476,
63,
694,
275,
291,
14,
8476,
63,
694,
12,
5264,
198,
3,
1569,
63,
2024,
63,
694,
275,
291,
14,
1569,
63,
2024,
63,
694,
12,
5264,
198,
1238,
63,
694,
29,
277,
14,
1238,
63,
694,
12,
5264,
198,
2024,
63,
694,
29,
277,
14,
2024,
63,
694,
12,
5264,
198,
2024,
63,
493,
29,
277,
14,
2024,
63,
493,
12,
5264,
198,
4159,
63,
493,
29,
277,
14,
4159,
63,
493,
12,
5264,
198,
3118,
63,
1896,
29,
277,
14,
3118,
63,
1896,
12,
5264,
198,
13209,
29,
277,
14,
13209,
12,
5264,
198,
988,
63,
1027,
63,
1267,
29,
277,
14,
988,
63,
1027,
63,
1267,
12,
5264,
198,
827,
63,
4757,
63,
529,
63,
4159,
29,
277,
14,
827,
63,
4757,
63,
529,
63,
4159,
9,
4671,
198,
93,
421,
199,
1371,
1244,
4220,
689,
18746,
749,
3,
199,
198,
318,
1072,
8,
277,
304,
507,
198,
5746,
63,
1842,
275,
291,
14,
5746,
63,
1842,
14,
1294,
11917,
507,
198,
5746,
63,
1842,
275,
359,
442,
8,
73,
9,
367,
284,
315,
7482,
63,
1842,
61,
507,
198,
5746,
63,
1842,
275,
1425,
8,
5746,
63,
1842,
59,
16,
467,
5746,
63,
1842,
59,
17,
467,
5746,
63,
1842,
59,
18,
566,
507,
198,
692,
291,
14,
3118,
63,
1896,
315,
661,
1773,
1673,
3118,
1673,
2379,
3148,
735,
686,
198,
5091,
275,
291,
14,
3118,
63,
1896,
507,
198,
2836,
26,
686,
198,
5091,
275,
283,
2379,
3148,
7,
9068,
198,
1107,
469,
1871,
198,
7,
28182,
356,
1871,
198,
91,
4671,
198,
73,
3006,
391,
26,
4671,
198,
91,
5264,
198,
78,
63,
11299,
26,
11674,
22680,
19485,
14,
5339,
4277,
8,
736,
14,
515,
14,
904,
8,
277,
14,
470,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ryfeus/lambda-packs
|
Selenium_PhantomJS/source/requests/packages/urllib3/util/url.py
|
713
|
5879
|
from __future__ import absolute_import
from collections import namedtuple
from ..exceptions import LocationParseError
url_attrs = ['scheme', 'auth', 'host', 'port', 'path', 'query', 'fragment']
class Url(namedtuple('Url', url_attrs)):
"""
Datastructure for representing an HTTP URL. Used as a return value for
:func:`parse_url`.
"""
slots = ()
def __new__(cls, scheme=None, auth=None, host=None, port=None, path=None,
query=None, fragment=None):
if path and not path.startswith('/'):
path = '/' + path
return super(Url, cls).__new__(cls, scheme, auth, host, port, path,
query, fragment)
@property
def hostname(self):
"""For backwards-compatibility with urlparse. We're nice like that."""
return self.host
@property
def request_uri(self):
"""Absolute path including the query string."""
uri = self.path or '/'
if self.query is not None:
uri += '?' + self.query
return uri
@property
def netloc(self):
"""Network location including host and port"""
if self.port:
return '%s:%d' % (self.host, self.port)
return self.host
@property
def url(self):
"""
Convert self into a url
This function should more or less round-trip with :func:`.parse_url`. The
returned url may not be exactly the same as the url inputted to
:func:`.parse_url`, but it should be equivalent by the RFC (e.g., urls
with a blank port will have : removed).
Example: ::
>>> U = parse_url('http://google.com/mail/')
>>> U.url
'http://google.com/mail/'
>>> Url('http', 'username:password', 'host.com', 80,
... '/path', 'query', 'fragment').url
'http://username:password@host.com:80/path?query#fragment'
"""
scheme, auth, host, port, path, query, fragment = self
url = ''
# We use "is not None" we want things to happen with empty strings (or 0 port)
if scheme is not None:
url += scheme + '://'
if auth is not None:
url += auth + '@'
if host is not None:
url += host
if port is not None:
url += ':' + str(port)
if path is not None:
url += path
if query is not None:
url += '?' + query
if fragment is not None:
url += '#' + fragment
return url
def __str__(self):
return self.url
def split_first(s, delims):
"""
Given a string and an iterable of delimiters, split on the first found
delimiter. Return two split parts and the matched delimiter.
If not found, then the first part is the full input string.
Example::
>>> split_first('foo/bar?baz', '?/=')
('foo', 'bar?baz', '/')
>>> split_first('foo/bar?baz', '123')
('foo/bar?baz', '', None)
Scales linearly with number of delims. Not ideal for large number of delims.
"""
min_idx = None
min_delim = None
for d in delims:
idx = s.find(d)
if idx < 0:
continue
if min_idx is None or idx < min_idx:
min_idx = idx
min_delim = d
if min_idx is None or min_idx < 0:
return s, '', None
return s[:min_idx], s[min_idx + 1:], min_delim
def parse_url(url):
"""
Given a url, return a parsed :class:`.Url` namedtuple. Best-effort is
performed to parse incomplete urls. Fields not provided will be None.
Partly backwards-compatible with :mod:`urlparse`.
Example::
>>> parse_url('http://google.com/mail/')
Url(scheme='http', host='google.com', port=None, path='/mail/', ...)
>>> parse_url('google.com:80')
Url(scheme=None, host='google.com', port=80, path=None, ...)
>>> parse_url('/foo?bar')
Url(scheme=None, host=None, port=None, path='/foo', query='bar', ...)
"""
# While this code has overlap with stdlib's urlparse, it is much
# simplified for our needs and less annoying.
# Additionally, this implementations does silly things to be optimal
# on CPython.
if not url:
# Empty
return Url()
scheme = None
auth = None
host = None
port = None
path = None
fragment = None
query = None
# Scheme
if '://' in url:
scheme, url = url.split('://', 1)
# Find the earliest Authority Terminator
# (http://tools.ietf.org/html/rfc3986#section-3.2)
url, path_, delim = split_first(url, ['/', '?', '#'])
if delim:
# Reassemble the path
path = delim + path_
# Auth
if '@' in url:
# Last '@' denotes end of auth part
auth, url = url.rsplit('@', 1)
# IPv6
if url and url[0] == '[':
host, url = url.split(']', 1)
host += ']'
# Port
if ':' in url:
_host, port = url.split(':', 1)
if not host:
host = _host
if port:
# If given, ports must be integers.
if not port.isdigit():
raise LocationParseError(url)
port = int(port)
else:
# Blank ports are cool, too. (rfc3986#section-3.2.3)
port = None
elif not host and url:
host = url
if not path:
return Url(scheme, auth, host, port, path, query, fragment)
# Fragment
if '#' in path:
path, fragment = path.split('#', 1)
# Query
if '?' in path:
path, query = path.split('?', 1)
return Url(scheme, auth, host, port, path, query, fragment)
def get_host(url):
"""
Deprecated. Use :func:`.parse_url` instead.
"""
p = parse_url(url)
return p.scheme or 'http', p.hostname, p.port
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
5055,
492,
12863,
199,
199,
504,
2508,
3924,
492,
12625,
9123,
421,
199,
633,
63,
3288,
275,
788,
5512,
297,
283,
1178,
297,
283,
1102,
297,
283,
719,
297,
283,
515,
297,
283,
1131,
297,
283,
7677,
418,
421,
199,
533,
20503,
8,
18921,
360,
6417,
297,
1166,
63,
3288,
2298,
272,
408,
272,
3918,
6976,
367,
6144,
376,
3101,
2851,
14,
8051,
465,
282,
372,
574,
367,
272,
520,
1532,
1705,
1122,
63,
633,
2313,
272,
408,
272,
14319,
275,
6248,
339,
347,
636,
1222,
721,
1886,
12,
5687,
29,
403,
12,
1790,
29,
403,
12,
1591,
29,
403,
12,
1844,
29,
403,
12,
931,
29,
403,
12,
355,
1827,
29,
403,
12,
7956,
29,
403,
304,
267,
340,
931,
436,
440,
931,
14,
2460,
18265,
288,
931,
275,
7324,
435,
931,
267,
372,
1613,
8,
6417,
12,
843,
2843,
1222,
721,
1886,
12,
5687,
12,
1790,
12,
1591,
12,
1844,
12,
931,
12,
4318,
1827,
12,
7956,
9,
339,
768,
1829,
272,
347,
6246,
8,
277,
304,
267,
408,
1858,
8552,
13,
15390,
543,
7097,
14,
2136,
3984,
14213,
2839,
626,
1041,
267,
372,
291,
14,
1102,
339,
768,
1829,
272,
347,
1056,
63,
2302,
8,
277,
304,
267,
408,
24677,
931,
5893,
314,
1827,
1059,
1041,
267,
5108,
275,
291,
14,
515,
503,
7324,
398,
340,
291,
14,
1131,
365,
440,
488,
26,
288,
5108,
847,
15539,
435,
291,
14,
1131,
398,
372,
5108,
339,
768,
1829,
272,
347,
10154,
8,
277,
304,
267,
408,
4491,
2909,
5893,
1591,
436,
1844,
624,
267,
340,
291,
14,
719,
26,
288,
372,
1543,
83,
2689,
68,
7,
450,
334,
277,
14,
1102,
12,
291,
14,
719,
9,
267,
372,
291,
14,
1102,
339,
768,
1829,
272,
347,
1166,
8,
277,
304,
267,
408,
267,
7905,
291,
1901,
282,
1166,
398,
961,
805,
1077,
1655,
503,
6656,
6168,
13,
7254,
543,
520,
1532,
5026,
1122,
63,
633,
2313,
710,
267,
2138,
1166,
1443,
440,
506,
8840,
314,
2011,
465,
314,
1166,
1324,
471,
370,
267,
520,
1532,
5026,
1122,
63,
633,
3559,
1325,
652,
1077,
506,
7353,
701,
314,
7329,
334,
69,
14,
71,
2020,
8187,
267,
543,
282,
4596,
1844,
911,
1172,
520,
4829,
680,
398,
5679,
26,
3800,
953,
1306,
738,
275,
2198,
63,
633,
360,
1014,
921,
3098,
14,
957,
15,
1198,
6217,
288,
1306,
738,
14,
633,
288,
283,
1014,
921,
3098,
14,
957,
15,
1198,
4805,
288,
1306,
20503,
360,
1014,
297,
283,
2473,
26,
2060,
297,
283,
1102,
14,
957,
297,
5939,
12,
288,
2263,
1994,
515,
297,
283,
1131,
297,
283,
7677,
1959,
633,
288,
283,
1014,
921,
2473,
26,
2060,
32,
1102,
14,
957,
26,
1257,
15,
515,
31,
1131,
3,
7677,
7,
267,
408,
267,
5687,
12,
1790,
12,
1591,
12,
1844,
12,
931,
12,
1827,
12,
7956,
275,
291,
267,
1166,
275,
2125,
398,
327,
2136,
675,
298,
374,
440,
488,
2,
781,
2934,
7645,
370,
5992,
543,
2701,
3326,
334,
269,
378,
1844,
9,
267,
340,
5687,
365,
440,
488,
26,
288,
1166,
847,
5687,
435,
283,
22399,
267,
340,
1790,
365,
440,
488,
26,
288,
1166,
847,
1790,
435,
22143,
267,
340,
1591,
365,
440,
488,
26,
288,
1166,
847,
1591,
267,
340,
1844,
365,
440,
488,
26,
288,
1166,
847,
10871,
435,
620,
8,
719,
9,
267,
340,
931,
365,
440,
488,
26,
288,
1166,
847,
931,
267,
340,
1827,
365,
440,
488,
26,
288,
1166,
847,
15539,
435,
1827,
267,
340,
7956,
365,
440,
488,
26,
288,
1166,
847,
19619,
435,
7956,
398,
372,
1166,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
633,
421,
199,
318,
3715,
63,
2246,
8,
83,
12,
9122,
706,
304,
272,
408,
272,
9138,
282,
1059,
436,
376,
6076,
402,
26968,
12,
3715,
641,
314,
1642,
1911,
272,
11172,
14,
1432,
2877,
3715,
4184,
436,
314,
7838,
11172,
14,
339,
982,
440,
1911,
12,
2066,
314,
1642,
1777,
365,
314,
2615,
1324,
1059,
14,
339,
5679,
447,
398,
1306,
3715,
63,
2246,
360,
1421,
15,
1700,
31,
6185,
297,
8720,
15,
14619,
267,
661,
1421,
297,
283,
1700,
31,
6185,
297,
15107,
267,
1306,
3715,
63,
2246,
360,
1421,
15,
1700,
31,
6185,
297,
283,
4288,
358,
267,
661,
1421,
15,
1700,
31,
6185,
297,
3260,
488,
9,
339,
22869,
83,
7798,
590,
543,
1329,
402,
9122,
706,
14,
2832,
28264,
367,
7031,
1329,
402,
9122,
706,
14,
272,
408,
272,
1748,
63,
2996,
275,
488,
272,
1748,
63,
15966,
275,
488,
272,
367,
366,
315,
9122,
706,
26,
267,
4280,
275,
308,
14,
1623,
8,
68,
9,
267,
340,
4280,
665,
378,
26,
288,
1980,
398,
340,
1748,
63,
2996,
365,
488,
503,
4280,
665,
1748,
63,
2996,
26,
288,
1748,
63,
2996,
275,
4280,
288,
1748,
63,
15966,
275,
366,
339,
340,
1748,
63,
2996,
365,
488,
503,
1748,
63,
2996,
665,
378,
26,
267,
372,
308,
12,
3260,
488,
339,
372,
308,
1491,
827,
63,
2996,
467,
308,
59,
827,
63,
2996,
435,
413,
8429,
1748,
63,
15966,
421,
199,
318,
2198,
63,
633,
8,
633,
304,
272,
408,
272,
9138,
282,
1166,
12,
372,
282,
4565,
520,
533,
5026,
6417,
64,
12863,
14,
699,
597,
13,
26088,
365,
272,
10585,
370,
2198,
17110,
8187,
14,
16424,
440,
2741,
911,
506,
488,
14,
339,
14320,
590,
8552,
13,
6490,
543,
520,
1494,
1705,
10290,
2313,
339,
5679,
447,
398,
1306,
2198,
63,
633,
360,
1014,
921,
3098,
14,
957,
15,
1198,
6217,
267,
20503,
8,
5512,
534,
1014,
297,
1591,
534,
3098,
14,
957,
297,
1844,
29,
403,
12,
931,
8805,
1198,
3678,
19172,
267,
1306,
2198,
63,
633,
360,
3098,
14,
957,
26,
1257,
358,
267,
20503,
8,
5512,
29,
403,
12,
1591,
534,
3098,
14,
957,
297,
1844,
29,
1257,
12,
931,
29,
403,
12,
19172,
267,
1306,
2198,
63,
633,
2336,
1421,
31,
1700,
358,
267,
20503,
8,
5512,
29,
403,
12,
1591,
29,
403,
12,
1844,
29,
403,
12,
931,
8805,
1421,
297,
1827,
534,
1700,
297,
19172,
272,
408,
339,
327,
22117,
642,
1233,
965,
15145,
543,
26678,
1159,
7097,
12,
652,
365
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
5055,
492,
12863,
199,
199,
504,
2508,
3924,
492,
12625,
9123,
421,
199,
633,
63,
3288,
275,
788,
5512,
297,
283,
1178,
297,
283,
1102,
297,
283,
719,
297,
283,
515,
297,
283,
1131,
297,
283,
7677,
418,
421,
199,
533,
20503,
8,
18921,
360,
6417,
297,
1166,
63,
3288,
2298,
272,
408,
272,
3918,
6976,
367,
6144,
376,
3101,
2851,
14,
8051,
465,
282,
372,
574,
367,
272,
520,
1532,
1705,
1122,
63,
633,
2313,
272,
408,
272,
14319,
275,
6248,
339,
347,
636,
1222,
721,
1886,
12,
5687,
29,
403,
12,
1790,
29,
403,
12,
1591,
29,
403,
12,
1844,
29,
403,
12,
931,
29,
403,
12,
355,
1827,
29,
403,
12,
7956,
29,
403,
304,
267,
340,
931,
436,
440,
931,
14,
2460,
18265,
288,
931,
275,
7324,
435,
931,
267,
372,
1613,
8,
6417,
12,
843,
2843,
1222,
721,
1886,
12,
5687,
12,
1790,
12,
1591,
12,
1844,
12,
931,
12,
4318,
1827,
12,
7956,
9,
339,
768,
1829,
272,
347,
6246,
8,
277,
304,
267,
408,
1858,
8552,
13,
15390,
543,
7097,
14,
2136,
3984,
14213,
2839,
626,
1041,
267,
372,
291,
14,
1102,
339,
768,
1829,
272,
347,
1056,
63,
2302,
8,
277,
304,
267,
408,
24677,
931,
5893,
314,
1827,
1059,
1041,
267,
5108,
275,
291,
14,
515,
503,
7324,
398,
340,
291,
14,
1131,
365,
440,
488,
26,
288,
5108,
847,
15539,
435,
291,
14,
1131,
398,
372,
5108,
339,
768,
1829,
272,
347,
10154,
8,
277,
304,
267,
408,
4491,
2909,
5893,
1591,
436,
1844,
624,
267,
340,
291,
14,
719,
26,
288,
372,
1543,
83,
2689,
68,
7,
450,
334,
277,
14,
1102,
12,
291,
14,
719,
9,
267,
372,
291,
14,
1102,
339,
768,
1829,
272,
347,
1166,
8,
277,
304,
267,
408,
267,
7905,
291,
1901,
282,
1166,
398,
961,
805,
1077,
1655,
503,
6656,
6168,
13,
7254,
543,
520,
1532,
5026,
1122,
63,
633,
2313,
710,
267,
2138,
1166,
1443,
440,
506,
8840,
314,
2011,
465,
314,
1166,
1324,
471,
370,
267,
520,
1532,
5026,
1122,
63,
633,
3559,
1325,
652,
1077,
506,
7353,
701,
314,
7329,
334,
69,
14,
71,
2020,
8187,
267,
543,
282,
4596,
1844,
911,
1172,
520,
4829,
680,
398,
5679,
26,
3800,
953,
1306,
738,
275,
2198,
63,
633,
360,
1014,
921,
3098,
14,
957,
15,
1198,
6217,
288,
1306,
738,
14,
633,
288,
283,
1014,
921,
3098,
14,
957,
15,
1198,
4805,
288,
1306,
20503,
360,
1014,
297,
283,
2473,
26,
2060,
297,
283,
1102,
14,
957,
297,
5939,
12,
288,
2263,
1994,
515,
297,
283,
1131,
297,
283,
7677,
1959,
633,
288,
283,
1014,
921,
2473,
26,
2060,
32,
1102,
14,
957,
26,
1257,
15,
515,
31,
1131,
3,
7677,
7,
267,
408,
267,
5687,
12,
1790,
12,
1591,
12,
1844,
12,
931,
12,
1827,
12,
7956,
275,
291,
267,
1166,
275,
2125,
398,
327,
2136,
675,
298,
374,
440,
488,
2,
781,
2934,
7645,
370,
5992,
543,
2701,
3326,
334,
269,
378,
1844,
9,
267,
340,
5687,
365,
440,
488,
26,
288,
1166,
847,
5687,
435,
283,
22399,
267,
340,
1790,
365,
440,
488,
26,
288,
1166,
847,
1790,
435,
22143,
267,
340,
1591,
365,
440,
488,
26,
288,
1166,
847,
1591,
267,
340,
1844,
365,
440,
488,
26,
288,
1166,
847,
10871,
435,
620,
8,
719,
9,
267,
340,
931,
365,
440,
488,
26,
288,
1166,
847,
931,
267,
340,
1827,
365,
440,
488,
26,
288,
1166,
847,
15539,
435,
1827,
267,
340,
7956,
365,
440,
488,
26,
288,
1166,
847,
19619,
435,
7956,
398,
372,
1166,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
633,
421,
199,
318,
3715,
63,
2246,
8,
83,
12,
9122,
706,
304,
272,
408,
272,
9138,
282,
1059,
436,
376,
6076,
402,
26968,
12,
3715,
641,
314,
1642,
1911,
272,
11172,
14,
1432,
2877,
3715,
4184,
436,
314,
7838,
11172,
14,
339,
982,
440,
1911,
12,
2066,
314,
1642,
1777,
365,
314,
2615,
1324,
1059,
14,
339,
5679,
447,
398,
1306,
3715,
63,
2246,
360,
1421,
15,
1700,
31,
6185,
297,
8720,
15,
14619,
267,
661,
1421,
297,
283,
1700,
31,
6185,
297,
15107,
267,
1306,
3715,
63,
2246,
360,
1421,
15,
1700,
31,
6185,
297,
283,
4288,
358,
267,
661,
1421,
15,
1700,
31,
6185,
297,
3260,
488,
9,
339,
22869,
83,
7798,
590,
543,
1329,
402,
9122,
706,
14,
2832,
28264,
367,
7031,
1329,
402,
9122,
706,
14,
272,
408,
272,
1748,
63,
2996,
275,
488,
272,
1748,
63,
15966,
275,
488,
272,
367,
366,
315,
9122,
706,
26,
267,
4280,
275,
308,
14,
1623,
8,
68,
9,
267,
340,
4280,
665,
378,
26,
288,
1980,
398,
340,
1748,
63,
2996,
365,
488,
503,
4280,
665,
1748,
63,
2996,
26,
288,
1748,
63,
2996,
275,
4280,
288,
1748,
63,
15966,
275,
366,
339,
340,
1748,
63,
2996,
365,
488,
503,
1748,
63,
2996,
665,
378,
26,
267,
372,
308,
12,
3260,
488,
339,
372,
308,
1491,
827,
63,
2996,
467,
308,
59,
827,
63,
2996,
435,
413,
8429,
1748,
63,
15966,
421,
199,
318,
2198,
63,
633,
8,
633,
304,
272,
408,
272,
9138,
282,
1166,
12,
372,
282,
4565,
520,
533,
5026,
6417,
64,
12863,
14,
699,
597,
13,
26088,
365,
272,
10585,
370,
2198,
17110,
8187,
14,
16424,
440,
2741,
911,
506,
488,
14,
339,
14320,
590,
8552,
13,
6490,
543,
520,
1494,
1705,
10290,
2313,
339,
5679,
447,
398,
1306,
2198,
63,
633,
360,
1014,
921,
3098,
14,
957,
15,
1198,
6217,
267,
20503,
8,
5512,
534,
1014,
297,
1591,
534,
3098,
14,
957,
297,
1844,
29,
403,
12,
931,
8805,
1198,
3678,
19172,
267,
1306,
2198,
63,
633,
360,
3098,
14,
957,
26,
1257,
358,
267,
20503,
8,
5512,
29,
403,
12,
1591,
534,
3098,
14,
957,
297,
1844,
29,
1257,
12,
931,
29,
403,
12,
19172,
267,
1306,
2198,
63,
633,
2336,
1421,
31,
1700,
358,
267,
20503,
8,
5512,
29,
403,
12,
1591,
29,
403,
12,
1844,
29,
403,
12,
931,
8805,
1421,
297,
1827,
534,
1700,
297,
19172,
272,
408,
339,
327,
22117,
642,
1233,
965,
15145,
543,
26678,
1159,
7097,
12,
652,
365,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
proffalken/cobbler
|
koan/text_wrap.py
|
21
|
13867
|
"""Text wrapping and filling.
(note: repackaged in koan because it's not present in RHEL3)
"""
# Copyright (C) 1999-2001 Gregory P. Ward.
# Copyright (C) 2002, 2003 Python Software Foundation.
# Written by Greg Ward <gward@python.net>
__revision__ = "$Id: textwrap.py,v 1.32.8.2 2004/05/13 01:48:15 gward Exp $"
import string, re
# Do the right thing with boolean values for all known Python versions
# (so this module can be copied to projects that don't depend on Python
# 2.3, e.g. Optik and Docutils).
try:
True, False
except NameError:
(True, False) = (1, 0)
__all__ = ['TextWrapper', 'wrap', 'fill']
# Hardcode the recognized whitespace characters to the US-ASCII
# whitespace characters. The main reason for doing this is that in
# ISO-8859-1, 0xa0 is non-breaking whitespace, so in certain locales
# that character winds up in string.whitespace. Respecting
# string.whitespace in those cases would 1) make textwrap treat 0xa0 the
# same as any other whitespace char, which is clearly wrong (it's a
# *non-breaking* space), 2) possibly cause problems with Unicode,
# since 0xa0 is not in range(128).
_whitespace = '\t\n\x0b\x0c\r '
class TextWrapper:
"""
Object for wrapping/filling text. The public interface consists of
the wrap() and fill() methods; the other methods are just there for
subclasses to override in order to tweak the default behaviour.
If you want to completely replace the main wrapping algorithm,
you'll probably have to override _wrap_chunks().
Several instance attributes control various aspects of wrapping:
width (default: 70)
the maximum width of wrapped lines (unless break_long_words
is false)
initial_indent (default: "")
string that will be prepended to the first line of wrapped
output. Counts towards the line's width.
subsequent_indent (default: "")
string that will be prepended to all lines save the first
of wrapped output; also counts towards each line's width.
expand_tabs (default: true)
Expand tabs in input text to spaces before further processing.
Each tab will become 1 .. 8 spaces, depending on its position in
its line. If false, each tab is treated as a single character.
replace_whitespace (default: true)
Replace all whitespace characters in the input text by spaces
after tab expansion. Note that if expand_tabs is false and
replace_whitespace is true, every tab will be converted to a
single space!
fix_sentence_endings (default: false)
Ensure that sentence-ending punctuation is always followed
by two spaces. Off by default because the algorithm is
(unavoidably) imperfect.
break_long_words (default: true)
Break words longer than 'width'. If false, those words will not
be broken, and some lines might be longer than 'width'.
"""
whitespace_trans = string.maketrans(_whitespace, ' ' * len(_whitespace))
unicode_whitespace_trans = {}
uspace = ord(u' ')
for x in map(ord, _whitespace):
unicode_whitespace_trans[x] = uspace
# This funky little regex is just the trick for splitting
# text up into word-wrappable chunks. E.g.
# "Hello there -- you goof-ball, use the -b option!"
# splits into
# Hello/ /there/ /--/ /you/ /goof-/ball,/ /use/ /the/ /-b/ /option!
# (after stripping out empty strings).
wordsep_re = re.compile(r'(\s+|' # any whitespace
r'-*\w{2,}-(?=\w{2,})|' # hyphenated words
r'(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))') # em-dash
# XXX will there be a locale-or-charset-aware version of
# string.lowercase in 2.3?
sentence_end_re = re.compile(r'[%s]' # lowercase letter
r'[\.\!\?]' # sentence-ending punct.
r'[\"\']?' # optional end-of-quote
% string.lowercase)
def __init__(self,
width=70,
initial_indent="",
subsequent_indent="",
expand_tabs=True,
replace_whitespace=True,
fix_sentence_endings=False,
break_long_words=True):
self.width = width
self.initial_indent = initial_indent
self.subsequent_indent = subsequent_indent
self.expand_tabs = expand_tabs
self.replace_whitespace = replace_whitespace
self.fix_sentence_endings = fix_sentence_endings
self.break_long_words = break_long_words
# -- Private methods -----------------------------------------------
# (possibly useful for subclasses to override)
def _munge_whitespace(self, text):
"""_munge_whitespace(text : string) -> string
Munge whitespace in text: expand tabs and convert all other
whitespace characters to spaces. Eg. " foo\tbar\n\nbaz"
becomes " foo bar baz".
"""
if self.expand_tabs:
text = text.expandtabs()
if self.replace_whitespace:
if isinstance(text, str):
text = text.translate(self.whitespace_trans)
elif isinstance(text, unicode):
text = text.translate(self.unicode_whitespace_trans)
return text
def _split(self, text):
"""_split(text : string) -> [string]
Split the text to wrap into indivisible chunks. Chunks are
not quite the same as words; see wrap_chunks() for full
details. As an example, the text
Look, goof-ball -- use the -b option!
breaks into the following chunks:
'Look,', ' ', 'goof-', 'ball', ' ', '--', ' ',
'use', ' ', 'the', ' ', '-b', ' ', 'option!'
"""
chunks = self.wordsep_re.split(text)
chunks = filter(None, chunks)
return chunks
def _fix_sentence_endings(self, chunks):
"""_fix_sentence_endings(chunks : [string])
Correct for sentence endings buried in 'chunks'. Eg. when the
original text contains "... foo.\nBar ...", munge_whitespace()
and split() will convert that to [..., "foo.", " ", "Bar", ...]
which has one too few spaces; this method simply changes the one
space to two.
"""
i = 0
pat = self.sentence_end_re
while i < len(chunks)-1:
if chunks[i+1] == " " and pat.search(chunks[i]):
chunks[i+1] = " "
i += 2
else:
i += 1
def _handle_long_word(self, chunks, cur_line, cur_len, width):
"""_handle_long_word(chunks : [string],
cur_line : [string],
cur_len : int, width : int)
Handle a chunk of text (most likely a word, not whitespace) that
is too long to fit in any line.
"""
space_left = max(width - cur_len, 1)
# If we're allowed to break long words, then do so: put as much
# of the next chunk onto the current line as will fit.
if self.break_long_words:
cur_line.append(chunks[0][0:space_left])
chunks[0] = chunks[0][space_left:]
# Otherwise, we have to preserve the long word intact. Only add
# it to the current line if there's nothing already there --
# that minimizes how much we violate the width constraint.
elif not cur_line:
cur_line.append(chunks.pop(0))
# If we're not allowed to break long words, and there's already
# text on the current line, do nothing. Next time through the
# main loop of _wrap_chunks(), we'll wind up here again, but
# cur_len will be zero, so the next line will be entirely
# devoted to the long word that we can't handle right now.
def _wrap_chunks(self, chunks):
"""_wrap_chunks(chunks : [string]) -> [string]
Wrap a sequence of text chunks and return a list of lines of
length 'self.width' or less. (If 'break_long_words' is false,
some lines may be longer than this.) Chunks correspond roughly
to words and the whitespace between them: each chunk is
indivisible (modulo 'break_long_words'), but a line break can
come between any two chunks. Chunks should not have internal
whitespace; ie. a chunk is either all whitespace or a "word".
Whitespace chunks will be removed from the beginning and end of
lines, but apart from that whitespace is preserved.
"""
lines = []
if self.width <= 0:
raise ValueError("invalid width %r (must be > 0)" % self.width)
while chunks:
# Start the list of chunks that will make up the current line.
# cur_len is just the length of all the chunks in cur_line.
cur_line = []
cur_len = 0
# Figure out which static string will prefix this line.
if lines:
indent = self.subsequent_indent
else:
indent = self.initial_indent
# Maximum width for this line.
width = self.width - len(indent)
# First chunk on line is whitespace -- drop it, unless this
# is the very beginning of the text (ie. no lines started yet).
if chunks[0].strip() == '' and lines:
del chunks[0]
while chunks:
l = len(chunks[0])
# Can at least squeeze this chunk onto the current line.
if cur_len + l <= width:
cur_line.append(chunks.pop(0))
cur_len += l
# Nope, this line is full.
else:
break
# The current line is full, and the next chunk is too big to
# fit on *any* line (not just this one).
if chunks and len(chunks[0]) > width:
self._handle_long_word(chunks, cur_line, cur_len, width)
# If the last chunk on this line is all whitespace, drop it.
if cur_line and cur_line[-1].strip() == '':
del cur_line[-1]
# Convert current line back to a string and store it in list
# of all lines (return value).
if cur_line:
lines.append(indent + ''.join(cur_line))
return lines
# -- Public interface ----------------------------------------------
def wrap(self, text):
"""wrap(text : string) -> [string]
Reformat the single paragraph in 'text' so it fits in lines of
no more than 'self.width' columns, and return a list of wrapped
lines. Tabs in 'text' are expanded with string.expandtabs(),
and all other whitespace characters (including newline) are
converted to space.
"""
text = self._munge_whitespace(text)
indent = self.initial_indent
chunks = self._split(text)
if self.fix_sentence_endings:
self._fix_sentence_endings(chunks)
return self._wrap_chunks(chunks)
def fill(self, text):
"""fill(text : string) -> string
Reformat the single paragraph in 'text' to fit in lines of no
more than 'self.width' columns, and return a new string
containing the entire wrapped paragraph.
"""
return "\n".join(self.wrap(text))
# -- Convenience interface ---------------------------------------------
def wrap(text, width=70, **kwargs):
"""Wrap a single paragraph of text, returning a list of wrapped lines.
Reformat the single paragraph in 'text' so it fits in lines of no
more than 'width' columns, and return a list of wrapped lines. By
default, tabs in 'text' are expanded with string.expandtabs(), and
all other whitespace characters (including newline) are converted to
space. See TextWrapper class for available keyword args to customize
wrapping behaviour.
"""
w = TextWrapper(width=width, **kwargs)
return w.wrap(text)
def fill(text, width=70, **kwargs):
"""Fill a single paragraph of text, returning a new string.
Reformat the single paragraph in 'text' to fit in lines of no more
than 'width' columns, and return a new string containing the entire
wrapped paragraph. As with wrap(), tabs are expanded and other
whitespace characters converted to space. See TextWrapper class for
available keyword args to customize wrapping behaviour.
"""
w = TextWrapper(width=width, **kwargs)
return w.fill(text)
# -- Loosely related functionality -------------------------------------
def dedent(text):
"""dedent(text : string) -> string
Remove any whitespace than can be uniformly removed from the left
of every line in `text`.
This can be used e.g. to make triple-quoted strings line up with
the left edge of screen/whatever, while still presenting it in the
source code in indented form.
For example:
def test():
# end first line with \ to avoid the empty line!
s = '''\
hello
world
'''
print repr(s) # prints ' hello\n world\n '
print repr(dedent(s)) # prints 'hello\n world\n'
"""
lines = text.expandtabs().split('\n')
margin = None
for line in lines:
content = line.lstrip()
if not content:
continue
indent = len(line) - len(content)
if margin is None:
margin = indent
else:
margin = min(margin, indent)
if margin is not None and margin > 0:
for i in range(len(lines)):
lines[i] = lines[i][margin:]
return '\n'.join(lines)
|
gpl-2.0
|
[
624,
1872,
19696,
436,
32499,
14,
199,
8,
4610,
26,
295,
2491,
68,
315,
20817,
290,
2952,
652,
1159,
440,
3451,
315,
820,
24771,
19,
9,
199,
624,
199,
199,
3,
1898,
334,
35,
9,
21300,
13,
8339,
29096,
1089,
510,
14,
644,
1005,
14,
199,
3,
1898,
334,
35,
9,
14790,
12,
13004,
2018,
2290,
2752,
14,
199,
3,
27694,
701,
29096,
644,
1005,
665,
71,
3079,
32,
1548,
14,
846,
30,
199,
199,
363,
5792,
363,
275,
7880,
1304,
26,
13390,
14,
647,
12,
86,
413,
14,
708,
14,
24,
14,
18,
8353,
15,
1717,
15,
969,
17163,
26,
2006,
26,
1046,
486,
3079,
7910,
2672,
2,
199,
199,
646,
1059,
12,
295,
199,
199,
3,
4226,
314,
2451,
8377,
543,
5046,
1338,
367,
1006,
6040,
2018,
5459,
199,
3,
334,
1152,
642,
859,
883,
506,
8876,
370,
11336,
626,
2793,
1133,
11687,
641,
2018,
199,
3,
499,
14,
19,
12,
325,
14,
71,
14,
9319,
30298,
436,
5454,
1208,
680,
199,
893,
26,
272,
715,
12,
756,
199,
2590,
12746,
26,
272,
334,
549,
12,
756,
9,
275,
334,
17,
12,
378,
9,
199,
199,
363,
452,
363,
275,
788,
1872,
4590,
297,
283,
3823,
297,
283,
4498,
418,
199,
199,
3,
22825,
600,
314,
18054,
8139,
4110,
370,
314,
19635,
13,
12292,
199,
3,
8139,
4110,
14,
221,
710,
2446,
4499,
367,
9689,
642,
365,
626,
315,
199,
3,
9055,
13,
4830,
13,
17,
12,
378,
1800,
16,
365,
2222,
13,
4785,
316,
8139,
12,
880,
315,
9842,
24847,
199,
3,
626,
4528,
15417,
83,
1536,
315,
1059,
14,
8506,
14,
221,
3591,
1764,
316,
199,
3,
1059,
14,
8506,
315,
5204,
5560,
3955,
413,
9,
1852,
13390,
14312,
378,
1800,
16,
314,
199,
3,
2011,
465,
1263,
1163,
8139,
1495,
12,
1314,
365,
5436,
590,
6835,
334,
390,
1159,
282,
199,
3,
627,
2865,
13,
4785,
316,
10,
4601,
395,
499,
9,
12570,
7675,
8826,
543,
6140,
12,
199,
3,
3967,
378,
1800,
16,
365,
440,
315,
1425,
8,
3933,
680,
199,
63,
8506,
275,
1557,
84,
60,
78,
60,
88,
16,
66,
60,
88,
16,
67,
60,
82,
283,
199,
199,
533,
4516,
4590,
26,
272,
408,
272,
6935,
367,
19696,
15,
4498,
316,
1318,
14,
221,
710,
4575,
3217,
18581,
402,
272,
314,
4816,
342,
436,
5554,
342,
3102,
27,
314,
1163,
3102,
787,
2951,
2337,
367,
272,
9180,
370,
4278,
315,
1865,
370,
32464,
314,
849,
13942,
14,
272,
982,
1265,
2934,
370,
14793,
3350,
314,
2446,
19696,
5563,
12,
272,
1265,
7171,
8646,
1172,
370,
4278,
485,
3823,
63,
10660,
1252,
339,
3240,
422,
279,
1256,
3004,
3304,
7750,
17435,
83,
402,
19696,
26,
489,
3462,
334,
885,
26,
10045,
9,
267,
314,
5696,
3462,
402,
8072,
2385,
334,
18447,
2059,
63,
2809,
63,
3148,
267,
365,
3055,
9,
489,
2536,
63,
3724,
334,
885,
26,
6899,
267,
1059,
626,
911,
506,
20247,
370,
314,
1642,
1004,
402,
8072,
267,
1072,
14,
221,
14826,
83,
28354,
314,
1004,
1159,
3462,
14,
489,
13372,
63,
3724,
334,
885,
26,
6899,
267,
1059,
626,
911,
506,
20247,
370,
1006,
2385,
3354,
314,
1642,
267,
402,
8072,
1072,
27,
2597,
8242,
28354,
1924,
1004,
1159,
3462,
14,
489,
6544,
63,
8741,
334,
885,
26,
2549,
9,
267,
18890,
12187,
315,
1324,
1318,
370,
7883,
2544,
9848,
6661,
14,
267,
7048,
5174,
911,
8649,
413,
2508,
1695,
7883,
12,
10298,
641,
2399,
3421,
315,
267,
2399,
1004,
14,
221,
982,
3055,
12,
1924,
5174,
365,
10184,
465,
282,
2849,
4528,
14,
489,
3350,
63,
8506,
334,
885,
26,
2549,
9,
267,
14402,
1006,
8139,
4110,
315,
314,
1324,
1318,
701,
7883,
267,
2410,
5174,
14819,
14,
221,
3390,
626,
340,
6544,
63,
8741,
365,
3055,
436,
267,
3350,
63,
8506,
365,
2549,
12,
4036,
5174,
911,
506,
6702,
370,
282,
267,
2849,
4601,
1,
489,
5325,
63,
17727,
63,
500,
780,
334,
885,
26,
3055,
9,
267,
7523,
626,
14537,
13,
3219,
22929,
365,
3544,
9437,
267,
701,
2877,
7883,
14,
221,
28856,
701,
849,
2952,
314,
5563,
365,
267,
334,
324,
27403,
6665,
9,
1742,
31740,
449,
14,
489,
2059,
63,
2809,
63,
3148,
334,
885,
26,
2549,
9,
267,
22535,
5932,
8088,
2419,
283,
2063,
1370,
221,
982,
3055,
12,
5204,
5932,
911,
440,
267,
506,
10529,
12,
436,
2005,
2385,
5594,
506,
8088,
2419,
283,
2063,
1370,
272,
408,
339,
8139,
63,
1515,
275,
1059,
14,
22191,
31552,
1547,
8506,
12,
283,
283,
627,
822,
1547,
8506,
430,
339,
2649,
63,
8506,
63,
1515,
275,
1052,
272,
399,
2638,
275,
6206,
8,
85,
7,
5320,
272,
367,
671,
315,
2341,
8,
2181,
12,
485,
8506,
304,
267,
2649,
63,
8506,
63,
1515,
59,
88,
61,
275,
399,
2638,
339,
327,
961,
289,
1778,
89,
12050,
5163,
365,
2951,
314,
20907,
367,
26518,
272,
327,
1318,
1536,
1901,
4349,
13,
87,
345,
802,
461,
8291,
14,
221,
662,
14,
71,
14,
272,
327,
257,
298,
6257,
2337,
1553,
1265,
486,
1534,
70,
13,
8571,
12,
675,
314,
446,
66,
945,
9539,
272,
327,
19115,
1901,
272,
327,
257,
23833,
15,
1182,
16990,
15,
1182,
306,
15,
1182,
13297,
15,
1182,
29546,
70,
13,
15,
8571,
12,
15,
1182,
1180,
15,
1182,
1589,
15,
1182,
13,
66,
15,
1182,
1422,
1,
272,
327,
334,
4399,
4024,
3637,
734,
2701,
3326,
680,
272,
4349,
4127,
63,
264,
275,
295,
14,
2014,
8,
82,
13445,
83,
11,
5227,
8295,
327,
1263,
8139,
1169,
519,
12418,
7590,
87,
91,
18,
12,
17063,
2229,
9529,
87,
91,
18,
12,
1552,
5227,
257,
327,
7188,
17579,
972,
5932,
1169,
519,
10120,
28,
32296,
87,
60,
12525,
3212,
1154,
28103,
3134,
4202,
31,
566,
24185,
18,
28209,
2229,
9529,
87,
28435,
257,
327,
18564,
13,
6760,
339,
327,
5787,
911,
2337,
506,
282,
5867,
13,
269,
13,
6043,
13,
14600,
1015,
402,
272,
327,
1059,
14,
21636,
315,
499,
14,
19,
31,
272,
14537,
63,
500,
63,
264,
275,
295,
14,
2014,
8,
82,
3894,
5,
83,
6616,
4519,
327,
12141,
8082,
639,
519,
22123,
3134,
12525,
31,
6616,
3515,
327,
14537,
13,
3219,
299,
4638,
14,
639,
519,
3894,
13356,
418,
14069,
3698
] |
[
1872,
19696,
436,
32499,
14,
199,
8,
4610,
26,
295,
2491,
68,
315,
20817,
290,
2952,
652,
1159,
440,
3451,
315,
820,
24771,
19,
9,
199,
624,
199,
199,
3,
1898,
334,
35,
9,
21300,
13,
8339,
29096,
1089,
510,
14,
644,
1005,
14,
199,
3,
1898,
334,
35,
9,
14790,
12,
13004,
2018,
2290,
2752,
14,
199,
3,
27694,
701,
29096,
644,
1005,
665,
71,
3079,
32,
1548,
14,
846,
30,
199,
199,
363,
5792,
363,
275,
7880,
1304,
26,
13390,
14,
647,
12,
86,
413,
14,
708,
14,
24,
14,
18,
8353,
15,
1717,
15,
969,
17163,
26,
2006,
26,
1046,
486,
3079,
7910,
2672,
2,
199,
199,
646,
1059,
12,
295,
199,
199,
3,
4226,
314,
2451,
8377,
543,
5046,
1338,
367,
1006,
6040,
2018,
5459,
199,
3,
334,
1152,
642,
859,
883,
506,
8876,
370,
11336,
626,
2793,
1133,
11687,
641,
2018,
199,
3,
499,
14,
19,
12,
325,
14,
71,
14,
9319,
30298,
436,
5454,
1208,
680,
199,
893,
26,
272,
715,
12,
756,
199,
2590,
12746,
26,
272,
334,
549,
12,
756,
9,
275,
334,
17,
12,
378,
9,
199,
199,
363,
452,
363,
275,
788,
1872,
4590,
297,
283,
3823,
297,
283,
4498,
418,
199,
199,
3,
22825,
600,
314,
18054,
8139,
4110,
370,
314,
19635,
13,
12292,
199,
3,
8139,
4110,
14,
221,
710,
2446,
4499,
367,
9689,
642,
365,
626,
315,
199,
3,
9055,
13,
4830,
13,
17,
12,
378,
1800,
16,
365,
2222,
13,
4785,
316,
8139,
12,
880,
315,
9842,
24847,
199,
3,
626,
4528,
15417,
83,
1536,
315,
1059,
14,
8506,
14,
221,
3591,
1764,
316,
199,
3,
1059,
14,
8506,
315,
5204,
5560,
3955,
413,
9,
1852,
13390,
14312,
378,
1800,
16,
314,
199,
3,
2011,
465,
1263,
1163,
8139,
1495,
12,
1314,
365,
5436,
590,
6835,
334,
390,
1159,
282,
199,
3,
627,
2865,
13,
4785,
316,
10,
4601,
395,
499,
9,
12570,
7675,
8826,
543,
6140,
12,
199,
3,
3967,
378,
1800,
16,
365,
440,
315,
1425,
8,
3933,
680,
199,
63,
8506,
275,
1557,
84,
60,
78,
60,
88,
16,
66,
60,
88,
16,
67,
60,
82,
283,
199,
199,
533,
4516,
4590,
26,
272,
408,
272,
6935,
367,
19696,
15,
4498,
316,
1318,
14,
221,
710,
4575,
3217,
18581,
402,
272,
314,
4816,
342,
436,
5554,
342,
3102,
27,
314,
1163,
3102,
787,
2951,
2337,
367,
272,
9180,
370,
4278,
315,
1865,
370,
32464,
314,
849,
13942,
14,
272,
982,
1265,
2934,
370,
14793,
3350,
314,
2446,
19696,
5563,
12,
272,
1265,
7171,
8646,
1172,
370,
4278,
485,
3823,
63,
10660,
1252,
339,
3240,
422,
279,
1256,
3004,
3304,
7750,
17435,
83,
402,
19696,
26,
489,
3462,
334,
885,
26,
10045,
9,
267,
314,
5696,
3462,
402,
8072,
2385,
334,
18447,
2059,
63,
2809,
63,
3148,
267,
365,
3055,
9,
489,
2536,
63,
3724,
334,
885,
26,
6899,
267,
1059,
626,
911,
506,
20247,
370,
314,
1642,
1004,
402,
8072,
267,
1072,
14,
221,
14826,
83,
28354,
314,
1004,
1159,
3462,
14,
489,
13372,
63,
3724,
334,
885,
26,
6899,
267,
1059,
626,
911,
506,
20247,
370,
1006,
2385,
3354,
314,
1642,
267,
402,
8072,
1072,
27,
2597,
8242,
28354,
1924,
1004,
1159,
3462,
14,
489,
6544,
63,
8741,
334,
885,
26,
2549,
9,
267,
18890,
12187,
315,
1324,
1318,
370,
7883,
2544,
9848,
6661,
14,
267,
7048,
5174,
911,
8649,
413,
2508,
1695,
7883,
12,
10298,
641,
2399,
3421,
315,
267,
2399,
1004,
14,
221,
982,
3055,
12,
1924,
5174,
365,
10184,
465,
282,
2849,
4528,
14,
489,
3350,
63,
8506,
334,
885,
26,
2549,
9,
267,
14402,
1006,
8139,
4110,
315,
314,
1324,
1318,
701,
7883,
267,
2410,
5174,
14819,
14,
221,
3390,
626,
340,
6544,
63,
8741,
365,
3055,
436,
267,
3350,
63,
8506,
365,
2549,
12,
4036,
5174,
911,
506,
6702,
370,
282,
267,
2849,
4601,
1,
489,
5325,
63,
17727,
63,
500,
780,
334,
885,
26,
3055,
9,
267,
7523,
626,
14537,
13,
3219,
22929,
365,
3544,
9437,
267,
701,
2877,
7883,
14,
221,
28856,
701,
849,
2952,
314,
5563,
365,
267,
334,
324,
27403,
6665,
9,
1742,
31740,
449,
14,
489,
2059,
63,
2809,
63,
3148,
334,
885,
26,
2549,
9,
267,
22535,
5932,
8088,
2419,
283,
2063,
1370,
221,
982,
3055,
12,
5204,
5932,
911,
440,
267,
506,
10529,
12,
436,
2005,
2385,
5594,
506,
8088,
2419,
283,
2063,
1370,
272,
408,
339,
8139,
63,
1515,
275,
1059,
14,
22191,
31552,
1547,
8506,
12,
283,
283,
627,
822,
1547,
8506,
430,
339,
2649,
63,
8506,
63,
1515,
275,
1052,
272,
399,
2638,
275,
6206,
8,
85,
7,
5320,
272,
367,
671,
315,
2341,
8,
2181,
12,
485,
8506,
304,
267,
2649,
63,
8506,
63,
1515,
59,
88,
61,
275,
399,
2638,
339,
327,
961,
289,
1778,
89,
12050,
5163,
365,
2951,
314,
20907,
367,
26518,
272,
327,
1318,
1536,
1901,
4349,
13,
87,
345,
802,
461,
8291,
14,
221,
662,
14,
71,
14,
272,
327,
257,
298,
6257,
2337,
1553,
1265,
486,
1534,
70,
13,
8571,
12,
675,
314,
446,
66,
945,
9539,
272,
327,
19115,
1901,
272,
327,
257,
23833,
15,
1182,
16990,
15,
1182,
306,
15,
1182,
13297,
15,
1182,
29546,
70,
13,
15,
8571,
12,
15,
1182,
1180,
15,
1182,
1589,
15,
1182,
13,
66,
15,
1182,
1422,
1,
272,
327,
334,
4399,
4024,
3637,
734,
2701,
3326,
680,
272,
4349,
4127,
63,
264,
275,
295,
14,
2014,
8,
82,
13445,
83,
11,
5227,
8295,
327,
1263,
8139,
1169,
519,
12418,
7590,
87,
91,
18,
12,
17063,
2229,
9529,
87,
91,
18,
12,
1552,
5227,
257,
327,
7188,
17579,
972,
5932,
1169,
519,
10120,
28,
32296,
87,
60,
12525,
3212,
1154,
28103,
3134,
4202,
31,
566,
24185,
18,
28209,
2229,
9529,
87,
28435,
257,
327,
18564,
13,
6760,
339,
327,
5787,
911,
2337,
506,
282,
5867,
13,
269,
13,
6043,
13,
14600,
1015,
402,
272,
327,
1059,
14,
21636,
315,
499,
14,
19,
31,
272,
14537,
63,
500,
63,
264,
275,
295,
14,
2014,
8,
82,
3894,
5,
83,
6616,
4519,
327,
12141,
8082,
639,
519,
22123,
3134,
12525,
31,
6616,
3515,
327,
14537,
13,
3219,
299,
4638,
14,
639,
519,
3894,
13356,
418,
14069,
3698,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
newswangerd/ansible
|
lib/ansible/utils/collection_loader/_collection_config.py
|
18
|
2945
|
# (c) 2019 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.module_utils.common.text.converters import to_text
from ansible.module_utils.six import with_metaclass
class _EventSource:
def __init__(self):
self._handlers = set()
def __iadd__(self, handler):
if not callable(handler):
raise ValueError('handler must be callable')
self._handlers.add(handler)
return self
def __isub__(self, handler):
try:
self._handlers.remove(handler)
except KeyError:
pass
return self
def _on_exception(self, handler, exc, *args, **kwargs):
# if we return True, we want the caller to re-raise
return True
def fire(self, *args, **kwargs):
for h in self._handlers:
try:
h(*args, **kwargs)
except Exception as ex:
if self._on_exception(h, ex, *args, **kwargs):
raise
class _AnsibleCollectionConfig(type):
def __init__(cls, meta, name, bases):
cls._collection_finder = None
cls._default_collection = None
cls._on_collection_load = _EventSource()
@property
def collection_finder(cls):
return cls._collection_finder
@collection_finder.setter
def collection_finder(cls, value):
if cls._collection_finder:
raise ValueError('an AnsibleCollectionFinder has already been configured')
cls._collection_finder = value
@property
def collection_paths(cls):
cls._require_finder()
return [to_text(p) for p in cls._collection_finder._n_collection_paths]
@property
def default_collection(cls):
return cls._default_collection
@default_collection.setter
def default_collection(cls, value):
cls._default_collection = value
@property
def on_collection_load(cls):
return cls._on_collection_load
@on_collection_load.setter
def on_collection_load(cls, value):
if value is not cls._on_collection_load:
raise ValueError('on_collection_load is not directly settable (use +=)')
@property
def playbook_paths(cls):
cls._require_finder()
return [to_text(p) for p in cls._collection_finder._n_playbook_paths]
@playbook_paths.setter
def playbook_paths(cls, value):
cls._require_finder()
cls._collection_finder.set_playbook_paths(value)
def _require_finder(cls):
if not cls._collection_finder:
raise NotImplementedError('an AnsibleCollectionFinder has not been installed in this process')
# concrete class of our metaclass type that defines the class properties we want
class AnsibleCollectionConfig(with_metaclass(_AnsibleCollectionConfig)):
pass
|
gpl-3.0
|
[
3,
334,
67,
9,
20312,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
2330,
14,
505,
14,
17911,
492,
370,
63,
505,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
543,
63,
6577,
421,
199,
533,
485,
2390,
2980,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
5586,
275,
663,
342,
339,
347,
636,
28788,
721,
277,
12,
3016,
304,
267,
340,
440,
4550,
8,
2232,
304,
288,
746,
1722,
360,
2232,
1471,
506,
4550,
358,
267,
291,
423,
5586,
14,
525,
8,
2232,
9,
267,
372,
291,
339,
347,
636,
374,
456,
721,
277,
12,
3016,
304,
267,
862,
26,
288,
291,
423,
5586,
14,
2168,
8,
2232,
9,
267,
871,
4067,
26,
288,
986,
398,
372,
291,
339,
347,
485,
265,
63,
1971,
8,
277,
12,
3016,
12,
3178,
12,
627,
589,
12,
1011,
958,
304,
267,
327,
340,
781,
372,
715,
12,
781,
2934,
314,
8025,
370,
295,
13,
3730,
267,
372,
715,
339,
347,
8344,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
367,
394,
315,
291,
423,
5586,
26,
288,
862,
26,
355,
394,
2031,
589,
12,
1011,
958,
9,
288,
871,
2186,
465,
444,
26,
355,
340,
291,
423,
265,
63,
1971,
8,
72,
12,
444,
12,
627,
589,
12,
1011,
958,
304,
490,
746,
421,
199,
533,
485,
10047,
7768,
2028,
8,
466,
304,
272,
347,
636,
826,
721,
1886,
12,
3404,
12,
536,
12,
9768,
304,
267,
843,
423,
3627,
63,
11681,
275,
488,
267,
843,
423,
885,
63,
3627,
275,
488,
267,
843,
423,
265,
63,
3627,
63,
912,
275,
485,
2390,
2980,
342,
339,
768,
1829,
272,
347,
3245,
63,
11681,
8,
1886,
304,
267,
372,
843,
423,
3627,
63,
11681,
339,
768,
3627,
63,
11681,
14,
8345,
272,
347,
3245,
63,
11681,
8,
1886,
12,
574,
304,
267,
340,
843,
423,
3627,
63,
11681,
26,
288,
746,
1722,
360,
290,
2622,
7768,
11791,
965,
2575,
2757,
7526,
358,
398,
843,
423,
3627,
63,
11681,
275,
574,
339,
768,
1829,
272,
347,
3245,
63,
3771,
8,
1886,
304,
267,
843,
423,
4365,
63,
11681,
342,
267,
372,
359,
475,
63,
505,
8,
80,
9,
367,
299,
315,
843,
423,
3627,
63,
11681,
423,
78,
63,
3627,
63,
3771,
61,
339,
768,
1829,
272,
347,
849,
63,
3627,
8,
1886,
304,
267,
372,
843,
423,
885,
63,
3627,
339,
768,
885,
63,
3627,
14,
8345,
272,
347,
849,
63,
3627,
8,
1886,
12,
574,
304,
398,
843,
423,
885,
63,
3627,
275,
574,
339,
768,
1829,
272,
347,
641,
63,
3627,
63,
912,
8,
1886,
304,
267,
372,
843,
423,
265,
63,
3627,
63,
912,
339,
768,
265,
63,
3627,
63,
912,
14,
8345,
272,
347,
641,
63,
3627,
63,
912,
8,
1886,
12,
574,
304,
267,
340,
574,
365,
440,
843,
423,
265,
63,
3627,
63,
912,
26,
288,
746,
1722,
360,
265,
63,
3627,
63,
912,
365,
440,
5370,
663,
1224,
334,
1180,
847,
5942,
339,
768,
1829,
272,
347,
15695,
63,
3771,
8,
1886,
304,
267,
843,
423,
4365,
63,
11681,
342,
267,
372,
359,
475,
63,
505,
8,
80,
9,
367,
299,
315,
843,
423,
3627,
63,
11681,
423,
78,
63,
14205,
63,
3771,
61,
339,
768,
14205,
63,
3771,
14,
8345,
272,
347,
15695,
63,
3771,
8,
1886,
12,
574,
304,
267,
843,
423,
4365,
63,
11681,
342,
267,
843,
423,
3627,
63,
11681,
14,
409,
63,
14205,
63,
3771,
8,
585,
9,
339,
347,
485,
4365,
63,
11681,
8,
1886,
304,
267,
340,
440,
843,
423,
3627,
63,
11681,
26,
288,
746,
4279,
360,
290,
2622,
7768,
11791,
965,
440,
2757,
4903,
315,
642,
2112,
358,
421,
199,
3,
13801,
1021,
402,
4154,
17074,
730,
626,
7890,
314,
1021,
4382,
781,
2934,
199,
533,
2622,
7768,
2028,
8,
1045,
63,
6577,
1547,
10047,
7768,
2028,
2298,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
334,
67,
9,
20312,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
2330,
14,
505,
14,
17911,
492,
370,
63,
505,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
543,
63,
6577,
421,
199,
533,
485,
2390,
2980,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
5586,
275,
663,
342,
339,
347,
636,
28788,
721,
277,
12,
3016,
304,
267,
340,
440,
4550,
8,
2232,
304,
288,
746,
1722,
360,
2232,
1471,
506,
4550,
358,
267,
291,
423,
5586,
14,
525,
8,
2232,
9,
267,
372,
291,
339,
347,
636,
374,
456,
721,
277,
12,
3016,
304,
267,
862,
26,
288,
291,
423,
5586,
14,
2168,
8,
2232,
9,
267,
871,
4067,
26,
288,
986,
398,
372,
291,
339,
347,
485,
265,
63,
1971,
8,
277,
12,
3016,
12,
3178,
12,
627,
589,
12,
1011,
958,
304,
267,
327,
340,
781,
372,
715,
12,
781,
2934,
314,
8025,
370,
295,
13,
3730,
267,
372,
715,
339,
347,
8344,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
367,
394,
315,
291,
423,
5586,
26,
288,
862,
26,
355,
394,
2031,
589,
12,
1011,
958,
9,
288,
871,
2186,
465,
444,
26,
355,
340,
291,
423,
265,
63,
1971,
8,
72,
12,
444,
12,
627,
589,
12,
1011,
958,
304,
490,
746,
421,
199,
533,
485,
10047,
7768,
2028,
8,
466,
304,
272,
347,
636,
826,
721,
1886,
12,
3404,
12,
536,
12,
9768,
304,
267,
843,
423,
3627,
63,
11681,
275,
488,
267,
843,
423,
885,
63,
3627,
275,
488,
267,
843,
423,
265,
63,
3627,
63,
912,
275,
485,
2390,
2980,
342,
339,
768,
1829,
272,
347,
3245,
63,
11681,
8,
1886,
304,
267,
372,
843,
423,
3627,
63,
11681,
339,
768,
3627,
63,
11681,
14,
8345,
272,
347,
3245,
63,
11681,
8,
1886,
12,
574,
304,
267,
340,
843,
423,
3627,
63,
11681,
26,
288,
746,
1722,
360,
290,
2622,
7768,
11791,
965,
2575,
2757,
7526,
358,
398,
843,
423,
3627,
63,
11681,
275,
574,
339,
768,
1829,
272,
347,
3245,
63,
3771,
8,
1886,
304,
267,
843,
423,
4365,
63,
11681,
342,
267,
372,
359,
475,
63,
505,
8,
80,
9,
367,
299,
315,
843,
423,
3627,
63,
11681,
423,
78,
63,
3627,
63,
3771,
61,
339,
768,
1829,
272,
347,
849,
63,
3627,
8,
1886,
304,
267,
372,
843,
423,
885,
63,
3627,
339,
768,
885,
63,
3627,
14,
8345,
272,
347,
849,
63,
3627,
8,
1886,
12,
574,
304,
398,
843,
423,
885,
63,
3627,
275,
574,
339,
768,
1829,
272,
347,
641,
63,
3627,
63,
912,
8,
1886,
304,
267,
372,
843,
423,
265,
63,
3627,
63,
912,
339,
768,
265,
63,
3627,
63,
912,
14,
8345,
272,
347,
641,
63,
3627,
63,
912,
8,
1886,
12,
574,
304,
267,
340,
574,
365,
440,
843,
423,
265,
63,
3627,
63,
912,
26,
288,
746,
1722,
360,
265,
63,
3627,
63,
912,
365,
440,
5370,
663,
1224,
334,
1180,
847,
5942,
339,
768,
1829,
272,
347,
15695,
63,
3771,
8,
1886,
304,
267,
843,
423,
4365,
63,
11681,
342,
267,
372,
359,
475,
63,
505,
8,
80,
9,
367,
299,
315,
843,
423,
3627,
63,
11681,
423,
78,
63,
14205,
63,
3771,
61,
339,
768,
14205,
63,
3771,
14,
8345,
272,
347,
15695,
63,
3771,
8,
1886,
12,
574,
304,
267,
843,
423,
4365,
63,
11681,
342,
267,
843,
423,
3627,
63,
11681,
14,
409,
63,
14205,
63,
3771,
8,
585,
9,
339,
347,
485,
4365,
63,
11681,
8,
1886,
304,
267,
340,
440,
843,
423,
3627,
63,
11681,
26,
288,
746,
4279,
360,
290,
2622,
7768,
11791,
965,
440,
2757,
4903,
315,
642,
2112,
358,
421,
199,
3,
13801,
1021,
402,
4154,
17074,
730,
626,
7890,
314,
1021,
4382,
781,
2934,
199,
533,
2622,
7768,
2028,
8,
1045,
63,
6577,
1547,
10047,
7768,
2028,
2298,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rajul/Pydev
|
plugins/org.python.pydev.jython/Lib/encodings/mac_cyrillic.py
|
593
|
13710
|
""" Python Character Mapping Codec mac_cyrillic generated from 'MAPPINGS/VENDORS/APPLE/CYRILLIC.TXT' with gencodec.py.
"""#"
import codecs
### Codec APIs
class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
return codecs.charmap_encode(input,errors,encoding_table)
def decode(self,input,errors='strict'):
return codecs.charmap_decode(input,errors,decoding_table)
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
class IncrementalDecoder(codecs.IncrementalDecoder):
def decode(self, input, final=False):
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='mac-cyrillic',
encode=Codec().encode,
decode=Codec().decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
### Decoding Table
decoding_table = (
u'\x00' # 0x00 -> CONTROL CHARACTER
u'\x01' # 0x01 -> CONTROL CHARACTER
u'\x02' # 0x02 -> CONTROL CHARACTER
u'\x03' # 0x03 -> CONTROL CHARACTER
u'\x04' # 0x04 -> CONTROL CHARACTER
u'\x05' # 0x05 -> CONTROL CHARACTER
u'\x06' # 0x06 -> CONTROL CHARACTER
u'\x07' # 0x07 -> CONTROL CHARACTER
u'\x08' # 0x08 -> CONTROL CHARACTER
u'\t' # 0x09 -> CONTROL CHARACTER
u'\n' # 0x0A -> CONTROL CHARACTER
u'\x0b' # 0x0B -> CONTROL CHARACTER
u'\x0c' # 0x0C -> CONTROL CHARACTER
u'\r' # 0x0D -> CONTROL CHARACTER
u'\x0e' # 0x0E -> CONTROL CHARACTER
u'\x0f' # 0x0F -> CONTROL CHARACTER
u'\x10' # 0x10 -> CONTROL CHARACTER
u'\x11' # 0x11 -> CONTROL CHARACTER
u'\x12' # 0x12 -> CONTROL CHARACTER
u'\x13' # 0x13 -> CONTROL CHARACTER
u'\x14' # 0x14 -> CONTROL CHARACTER
u'\x15' # 0x15 -> CONTROL CHARACTER
u'\x16' # 0x16 -> CONTROL CHARACTER
u'\x17' # 0x17 -> CONTROL CHARACTER
u'\x18' # 0x18 -> CONTROL CHARACTER
u'\x19' # 0x19 -> CONTROL CHARACTER
u'\x1a' # 0x1A -> CONTROL CHARACTER
u'\x1b' # 0x1B -> CONTROL CHARACTER
u'\x1c' # 0x1C -> CONTROL CHARACTER
u'\x1d' # 0x1D -> CONTROL CHARACTER
u'\x1e' # 0x1E -> CONTROL CHARACTER
u'\x1f' # 0x1F -> CONTROL CHARACTER
u' ' # 0x20 -> SPACE
u'!' # 0x21 -> EXCLAMATION MARK
u'"' # 0x22 -> QUOTATION MARK
u'#' # 0x23 -> NUMBER SIGN
u'$' # 0x24 -> DOLLAR SIGN
u'%' # 0x25 -> PERCENT SIGN
u'&' # 0x26 -> AMPERSAND
u"'" # 0x27 -> APOSTROPHE
u'(' # 0x28 -> LEFT PARENTHESIS
u')' # 0x29 -> RIGHT PARENTHESIS
u'*' # 0x2A -> ASTERISK
u'+' # 0x2B -> PLUS SIGN
u',' # 0x2C -> COMMA
u'-' # 0x2D -> HYPHEN-MINUS
u'.' # 0x2E -> FULL STOP
u'/' # 0x2F -> SOLIDUS
u'0' # 0x30 -> DIGIT ZERO
u'1' # 0x31 -> DIGIT ONE
u'2' # 0x32 -> DIGIT TWO
u'3' # 0x33 -> DIGIT THREE
u'4' # 0x34 -> DIGIT FOUR
u'5' # 0x35 -> DIGIT FIVE
u'6' # 0x36 -> DIGIT SIX
u'7' # 0x37 -> DIGIT SEVEN
u'8' # 0x38 -> DIGIT EIGHT
u'9' # 0x39 -> DIGIT NINE
u':' # 0x3A -> COLON
u';' # 0x3B -> SEMICOLON
u'<' # 0x3C -> LESS-THAN SIGN
u'=' # 0x3D -> EQUALS SIGN
u'>' # 0x3E -> GREATER-THAN SIGN
u'?' # 0x3F -> QUESTION MARK
u'@' # 0x40 -> COMMERCIAL AT
u'A' # 0x41 -> LATIN CAPITAL LETTER A
u'B' # 0x42 -> LATIN CAPITAL LETTER B
u'C' # 0x43 -> LATIN CAPITAL LETTER C
u'D' # 0x44 -> LATIN CAPITAL LETTER D
u'E' # 0x45 -> LATIN CAPITAL LETTER E
u'F' # 0x46 -> LATIN CAPITAL LETTER F
u'G' # 0x47 -> LATIN CAPITAL LETTER G
u'H' # 0x48 -> LATIN CAPITAL LETTER H
u'I' # 0x49 -> LATIN CAPITAL LETTER I
u'J' # 0x4A -> LATIN CAPITAL LETTER J
u'K' # 0x4B -> LATIN CAPITAL LETTER K
u'L' # 0x4C -> LATIN CAPITAL LETTER L
u'M' # 0x4D -> LATIN CAPITAL LETTER M
u'N' # 0x4E -> LATIN CAPITAL LETTER N
u'O' # 0x4F -> LATIN CAPITAL LETTER O
u'P' # 0x50 -> LATIN CAPITAL LETTER P
u'Q' # 0x51 -> LATIN CAPITAL LETTER Q
u'R' # 0x52 -> LATIN CAPITAL LETTER R
u'S' # 0x53 -> LATIN CAPITAL LETTER S
u'T' # 0x54 -> LATIN CAPITAL LETTER T
u'U' # 0x55 -> LATIN CAPITAL LETTER U
u'V' # 0x56 -> LATIN CAPITAL LETTER V
u'W' # 0x57 -> LATIN CAPITAL LETTER W
u'X' # 0x58 -> LATIN CAPITAL LETTER X
u'Y' # 0x59 -> LATIN CAPITAL LETTER Y
u'Z' # 0x5A -> LATIN CAPITAL LETTER Z
u'[' # 0x5B -> LEFT SQUARE BRACKET
u'\\' # 0x5C -> REVERSE SOLIDUS
u']' # 0x5D -> RIGHT SQUARE BRACKET
u'^' # 0x5E -> CIRCUMFLEX ACCENT
u'_' # 0x5F -> LOW LINE
u'`' # 0x60 -> GRAVE ACCENT
u'a' # 0x61 -> LATIN SMALL LETTER A
u'b' # 0x62 -> LATIN SMALL LETTER B
u'c' # 0x63 -> LATIN SMALL LETTER C
u'd' # 0x64 -> LATIN SMALL LETTER D
u'e' # 0x65 -> LATIN SMALL LETTER E
u'f' # 0x66 -> LATIN SMALL LETTER F
u'g' # 0x67 -> LATIN SMALL LETTER G
u'h' # 0x68 -> LATIN SMALL LETTER H
u'i' # 0x69 -> LATIN SMALL LETTER I
u'j' # 0x6A -> LATIN SMALL LETTER J
u'k' # 0x6B -> LATIN SMALL LETTER K
u'l' # 0x6C -> LATIN SMALL LETTER L
u'm' # 0x6D -> LATIN SMALL LETTER M
u'n' # 0x6E -> LATIN SMALL LETTER N
u'o' # 0x6F -> LATIN SMALL LETTER O
u'p' # 0x70 -> LATIN SMALL LETTER P
u'q' # 0x71 -> LATIN SMALL LETTER Q
u'r' # 0x72 -> LATIN SMALL LETTER R
u's' # 0x73 -> LATIN SMALL LETTER S
u't' # 0x74 -> LATIN SMALL LETTER T
u'u' # 0x75 -> LATIN SMALL LETTER U
u'v' # 0x76 -> LATIN SMALL LETTER V
u'w' # 0x77 -> LATIN SMALL LETTER W
u'x' # 0x78 -> LATIN SMALL LETTER X
u'y' # 0x79 -> LATIN SMALL LETTER Y
u'z' # 0x7A -> LATIN SMALL LETTER Z
u'{' # 0x7B -> LEFT CURLY BRACKET
u'|' # 0x7C -> VERTICAL LINE
u'}' # 0x7D -> RIGHT CURLY BRACKET
u'~' # 0x7E -> TILDE
u'\x7f' # 0x7F -> CONTROL CHARACTER
u'\u0410' # 0x80 -> CYRILLIC CAPITAL LETTER A
u'\u0411' # 0x81 -> CYRILLIC CAPITAL LETTER BE
u'\u0412' # 0x82 -> CYRILLIC CAPITAL LETTER VE
u'\u0413' # 0x83 -> CYRILLIC CAPITAL LETTER GHE
u'\u0414' # 0x84 -> CYRILLIC CAPITAL LETTER DE
u'\u0415' # 0x85 -> CYRILLIC CAPITAL LETTER IE
u'\u0416' # 0x86 -> CYRILLIC CAPITAL LETTER ZHE
u'\u0417' # 0x87 -> CYRILLIC CAPITAL LETTER ZE
u'\u0418' # 0x88 -> CYRILLIC CAPITAL LETTER I
u'\u0419' # 0x89 -> CYRILLIC CAPITAL LETTER SHORT I
u'\u041a' # 0x8A -> CYRILLIC CAPITAL LETTER KA
u'\u041b' # 0x8B -> CYRILLIC CAPITAL LETTER EL
u'\u041c' # 0x8C -> CYRILLIC CAPITAL LETTER EM
u'\u041d' # 0x8D -> CYRILLIC CAPITAL LETTER EN
u'\u041e' # 0x8E -> CYRILLIC CAPITAL LETTER O
u'\u041f' # 0x8F -> CYRILLIC CAPITAL LETTER PE
u'\u0420' # 0x90 -> CYRILLIC CAPITAL LETTER ER
u'\u0421' # 0x91 -> CYRILLIC CAPITAL LETTER ES
u'\u0422' # 0x92 -> CYRILLIC CAPITAL LETTER TE
u'\u0423' # 0x93 -> CYRILLIC CAPITAL LETTER U
u'\u0424' # 0x94 -> CYRILLIC CAPITAL LETTER EF
u'\u0425' # 0x95 -> CYRILLIC CAPITAL LETTER HA
u'\u0426' # 0x96 -> CYRILLIC CAPITAL LETTER TSE
u'\u0427' # 0x97 -> CYRILLIC CAPITAL LETTER CHE
u'\u0428' # 0x98 -> CYRILLIC CAPITAL LETTER SHA
u'\u0429' # 0x99 -> CYRILLIC CAPITAL LETTER SHCHA
u'\u042a' # 0x9A -> CYRILLIC CAPITAL LETTER HARD SIGN
u'\u042b' # 0x9B -> CYRILLIC CAPITAL LETTER YERU
u'\u042c' # 0x9C -> CYRILLIC CAPITAL LETTER SOFT SIGN
u'\u042d' # 0x9D -> CYRILLIC CAPITAL LETTER E
u'\u042e' # 0x9E -> CYRILLIC CAPITAL LETTER YU
u'\u042f' # 0x9F -> CYRILLIC CAPITAL LETTER YA
u'\u2020' # 0xA0 -> DAGGER
u'\xb0' # 0xA1 -> DEGREE SIGN
u'\u0490' # 0xA2 -> CYRILLIC CAPITAL LETTER GHE WITH UPTURN
u'\xa3' # 0xA3 -> POUND SIGN
u'\xa7' # 0xA4 -> SECTION SIGN
u'\u2022' # 0xA5 -> BULLET
u'\xb6' # 0xA6 -> PILCROW SIGN
u'\u0406' # 0xA7 -> CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I
u'\xae' # 0xA8 -> REGISTERED SIGN
u'\xa9' # 0xA9 -> COPYRIGHT SIGN
u'\u2122' # 0xAA -> TRADE MARK SIGN
u'\u0402' # 0xAB -> CYRILLIC CAPITAL LETTER DJE
u'\u0452' # 0xAC -> CYRILLIC SMALL LETTER DJE
u'\u2260' # 0xAD -> NOT EQUAL TO
u'\u0403' # 0xAE -> CYRILLIC CAPITAL LETTER GJE
u'\u0453' # 0xAF -> CYRILLIC SMALL LETTER GJE
u'\u221e' # 0xB0 -> INFINITY
u'\xb1' # 0xB1 -> PLUS-MINUS SIGN
u'\u2264' # 0xB2 -> LESS-THAN OR EQUAL TO
u'\u2265' # 0xB3 -> GREATER-THAN OR EQUAL TO
u'\u0456' # 0xB4 -> CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I
u'\xb5' # 0xB5 -> MICRO SIGN
u'\u0491' # 0xB6 -> CYRILLIC SMALL LETTER GHE WITH UPTURN
u'\u0408' # 0xB7 -> CYRILLIC CAPITAL LETTER JE
u'\u0404' # 0xB8 -> CYRILLIC CAPITAL LETTER UKRAINIAN IE
u'\u0454' # 0xB9 -> CYRILLIC SMALL LETTER UKRAINIAN IE
u'\u0407' # 0xBA -> CYRILLIC CAPITAL LETTER YI
u'\u0457' # 0xBB -> CYRILLIC SMALL LETTER YI
u'\u0409' # 0xBC -> CYRILLIC CAPITAL LETTER LJE
u'\u0459' # 0xBD -> CYRILLIC SMALL LETTER LJE
u'\u040a' # 0xBE -> CYRILLIC CAPITAL LETTER NJE
u'\u045a' # 0xBF -> CYRILLIC SMALL LETTER NJE
u'\u0458' # 0xC0 -> CYRILLIC SMALL LETTER JE
u'\u0405' # 0xC1 -> CYRILLIC CAPITAL LETTER DZE
u'\xac' # 0xC2 -> NOT SIGN
u'\u221a' # 0xC3 -> SQUARE ROOT
u'\u0192' # 0xC4 -> LATIN SMALL LETTER F WITH HOOK
u'\u2248' # 0xC5 -> ALMOST EQUAL TO
u'\u2206' # 0xC6 -> INCREMENT
u'\xab' # 0xC7 -> LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
u'\xbb' # 0xC8 -> RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
u'\u2026' # 0xC9 -> HORIZONTAL ELLIPSIS
u'\xa0' # 0xCA -> NO-BREAK SPACE
u'\u040b' # 0xCB -> CYRILLIC CAPITAL LETTER TSHE
u'\u045b' # 0xCC -> CYRILLIC SMALL LETTER TSHE
u'\u040c' # 0xCD -> CYRILLIC CAPITAL LETTER KJE
u'\u045c' # 0xCE -> CYRILLIC SMALL LETTER KJE
u'\u0455' # 0xCF -> CYRILLIC SMALL LETTER DZE
u'\u2013' # 0xD0 -> EN DASH
u'\u2014' # 0xD1 -> EM DASH
u'\u201c' # 0xD2 -> LEFT DOUBLE QUOTATION MARK
u'\u201d' # 0xD3 -> RIGHT DOUBLE QUOTATION MARK
u'\u2018' # 0xD4 -> LEFT SINGLE QUOTATION MARK
u'\u2019' # 0xD5 -> RIGHT SINGLE QUOTATION MARK
u'\xf7' # 0xD6 -> DIVISION SIGN
u'\u201e' # 0xD7 -> DOUBLE LOW-9 QUOTATION MARK
u'\u040e' # 0xD8 -> CYRILLIC CAPITAL LETTER SHORT U
u'\u045e' # 0xD9 -> CYRILLIC SMALL LETTER SHORT U
u'\u040f' # 0xDA -> CYRILLIC CAPITAL LETTER DZHE
u'\u045f' # 0xDB -> CYRILLIC SMALL LETTER DZHE
u'\u2116' # 0xDC -> NUMERO SIGN
u'\u0401' # 0xDD -> CYRILLIC CAPITAL LETTER IO
u'\u0451' # 0xDE -> CYRILLIC SMALL LETTER IO
u'\u044f' # 0xDF -> CYRILLIC SMALL LETTER YA
u'\u0430' # 0xE0 -> CYRILLIC SMALL LETTER A
u'\u0431' # 0xE1 -> CYRILLIC SMALL LETTER BE
u'\u0432' # 0xE2 -> CYRILLIC SMALL LETTER VE
u'\u0433' # 0xE3 -> CYRILLIC SMALL LETTER GHE
u'\u0434' # 0xE4 -> CYRILLIC SMALL LETTER DE
u'\u0435' # 0xE5 -> CYRILLIC SMALL LETTER IE
u'\u0436' # 0xE6 -> CYRILLIC SMALL LETTER ZHE
u'\u0437' # 0xE7 -> CYRILLIC SMALL LETTER ZE
u'\u0438' # 0xE8 -> CYRILLIC SMALL LETTER I
u'\u0439' # 0xE9 -> CYRILLIC SMALL LETTER SHORT I
u'\u043a' # 0xEA -> CYRILLIC SMALL LETTER KA
u'\u043b' # 0xEB -> CYRILLIC SMALL LETTER EL
u'\u043c' # 0xEC -> CYRILLIC SMALL LETTER EM
u'\u043d' # 0xED -> CYRILLIC SMALL LETTER EN
u'\u043e' # 0xEE -> CYRILLIC SMALL LETTER O
u'\u043f' # 0xEF -> CYRILLIC SMALL LETTER PE
u'\u0440' # 0xF0 -> CYRILLIC SMALL LETTER ER
u'\u0441' # 0xF1 -> CYRILLIC SMALL LETTER ES
u'\u0442' # 0xF2 -> CYRILLIC SMALL LETTER TE
u'\u0443' # 0xF3 -> CYRILLIC SMALL LETTER U
u'\u0444' # 0xF4 -> CYRILLIC SMALL LETTER EF
u'\u0445' # 0xF5 -> CYRILLIC SMALL LETTER HA
u'\u0446' # 0xF6 -> CYRILLIC SMALL LETTER TSE
u'\u0447' # 0xF7 -> CYRILLIC SMALL LETTER CHE
u'\u0448' # 0xF8 -> CYRILLIC SMALL LETTER SHA
u'\u0449' # 0xF9 -> CYRILLIC SMALL LETTER SHCHA
u'\u044a' # 0xFA -> CYRILLIC SMALL LETTER HARD SIGN
u'\u044b' # 0xFB -> CYRILLIC SMALL LETTER YERU
u'\u044c' # 0xFC -> CYRILLIC SMALL LETTER SOFT SIGN
u'\u044d' # 0xFD -> CYRILLIC SMALL LETTER E
u'\u044e' # 0xFE -> CYRILLIC SMALL LETTER YU
u'\u20ac' # 0xFF -> EURO SIGN
)
### Encoding table
encoding_table=codecs.charmap_build(decoding_table)
|
epl-1.0
|
[
624,
2018,
17660,
12340,
13732,
4497,
63,
17405,
4046,
687,
283,
32362,
15,
27839,
4149,
15,
31683,
15,
35,
6191,
14,
17715,
7,
543,
486,
2143,
67,
14,
647,
14,
199,
199,
624,
23662,
199,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1224,
9,
339,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1224,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1224,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1224,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
3088,
13,
17405,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
421,
199,
5680,
27368,
6957,
199,
199,
12796,
63,
1224,
275,
334,
272,
399,
1154,
88,
383,
7,
258,
327,
221,
378,
88,
383,
1035,
8098,
9502,
272,
399,
1154,
88,
614,
7,
258,
327,
221,
378,
88,
614,
1035,
8098,
9502,
272,
399,
1154,
88,
996,
7,
258,
327,
221,
378,
88,
996,
1035,
8098,
9502,
272,
399,
1154,
88,
1644,
7,
258,
327,
221,
378,
88,
1644,
1035,
8098,
9502,
272,
399,
1154,
88,
966,
7,
258,
327,
221,
378,
88,
966,
1035,
8098,
9502,
272,
399,
1154,
88,
1717,
7,
258,
327,
221,
378,
88,
1717,
1035,
8098,
9502,
272,
399,
1154,
88,
1690,
7,
258,
327,
221,
378,
88,
1690,
1035,
8098,
9502,
272,
399,
1154,
88,
1780,
7,
258,
327,
221,
378,
88,
1780,
1035,
8098,
9502,
272,
399,
1154,
88,
2036,
7,
258,
327,
221,
378,
88,
2036,
1035,
8098,
9502,
272,
399,
1154,
84,
7,
755,
327,
221,
378,
88,
1643,
1035,
8098,
9502,
272,
399,
1154,
78,
7,
755,
327,
221,
378,
88,
16,
33,
1035,
8098,
9502,
272,
399,
1154,
88,
16,
66,
7,
258,
327,
221,
378,
88,
16,
34,
1035,
8098,
9502,
272,
399,
1154,
88,
16,
67,
7,
258,
327,
221,
378,
88,
16,
35,
1035,
8098,
9502,
272,
399,
1154,
82,
7,
755,
327,
221,
378,
88,
16,
36,
1035,
8098,
9502,
272,
399,
1154,
88,
16,
69,
7,
258,
327,
221,
378,
88,
16,
37,
1035,
8098,
9502,
272,
399,
1154,
88,
16,
70,
7,
258,
327,
221,
378,
88,
16,
38,
1035,
8098,
9502,
272,
399,
1154,
88,
709,
7,
258,
327,
221,
378,
88,
709,
1035,
8098,
9502,
272,
399,
1154,
88,
845,
7,
258,
327,
221,
378,
88,
845,
1035,
8098,
9502,
272,
399,
1154,
88,
713,
7,
258,
327,
221,
378,
88,
713,
1035,
8098,
9502,
272,
399,
1154,
88,
969,
7,
258,
327,
221,
378,
88,
969,
1035,
8098,
9502,
272,
399,
1154,
88,
1079,
7,
258,
327,
221,
378,
88,
1079,
1035,
8098,
9502,
272,
399,
1154,
88,
1046,
7,
258,
327,
221,
378,
88,
1046,
1035,
8098,
9502,
272,
399,
1154,
88,
975,
7,
258,
327,
221,
378,
88,
975,
1035,
8098,
9502,
272,
399,
1154,
88,
1196,
7,
258,
327,
221,
378,
88,
1196,
1035,
8098,
9502,
272,
399,
1154,
88,
1085,
7,
258,
327,
221,
378,
88,
1085,
1035,
8098,
9502,
272,
399,
1154,
88,
1167,
7,
258,
327,
221,
378,
88,
1167,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
65,
7,
258,
327,
221,
378,
88,
17,
33,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
66,
7,
258,
327,
221,
378,
88,
17,
34,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
67,
7,
258,
327,
221,
378,
88,
17,
35,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
68,
7,
258,
327,
221,
378,
88,
17,
36,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
69,
7,
258,
327,
221,
378,
88,
17,
37,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
70,
7,
258,
327,
221,
378,
88,
17,
38,
1035,
8098,
9502,
272,
399,
7,
283,
263,
327,
221,
378,
88,
1165,
1035,
16796,
272,
399,
7,
11213,
263,
327,
221,
378,
88,
2025,
1035,
24232,
8132,
272,
399,
30385,
263,
327,
221,
378,
88,
1081,
1035,
11830,
8132,
272,
399,
11525,
7,
263,
327,
221,
378,
88,
1789,
1035,
18122,
5056,
272,
399,
7,
12913,
263,
327,
221,
378,
88,
1194,
1035,
30857,
5056,
272,
399,
5956,
7,
263,
327,
221,
378,
88,
821,
1035,
26684,
5056,
272,
399,
21840,
7,
263,
327,
221,
378,
88,
1479,
1035,
30602,
272,
399,
2,
4065,
263,
327,
221,
378,
88,
1465,
1035,
30876,
272,
399,
7,
360,
263,
327,
221,
378,
88,
1651,
1035,
6578,
20570,
272,
399,
358,
7,
263,
327,
221,
378,
88,
1398,
1035,
7052,
20570,
272,
399,
7,
10223,
263,
327,
221,
378,
88,
18,
33,
1035,
29725,
272,
399,
30269,
263,
327,
221,
378,
88,
18,
34,
1035,
18807,
5056,
272,
399,
1673,
263,
327,
221,
378,
88,
18,
35,
1035,
22849,
272,
399,
12418,
7,
263,
327,
221,
378,
88,
18,
36,
1035,
22553,
13,
18004,
272,
399,
30484,
263,
327,
221,
378,
88,
18,
37,
1035,
18530,
22348,
272,
399,
29957,
263,
327,
221,
378,
88,
18,
38,
1035,
20585,
272,
399,
7,
16,
7,
263,
327,
221,
378,
88,
1216,
1035,
7298,
20348,
272,
399,
7,
17,
7,
263,
327,
221,
378,
88,
2192,
1035,
7298,
13051,
272,
399,
7,
18,
7
] |
[
2018,
17660,
12340,
13732,
4497,
63,
17405,
4046,
687,
283,
32362,
15,
27839,
4149,
15,
31683,
15,
35,
6191,
14,
17715,
7,
543,
486,
2143,
67,
14,
647,
14,
199,
199,
624,
23662,
199,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1224,
9,
339,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1224,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1224,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1224,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
3088,
13,
17405,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
421,
199,
5680,
27368,
6957,
199,
199,
12796,
63,
1224,
275,
334,
272,
399,
1154,
88,
383,
7,
258,
327,
221,
378,
88,
383,
1035,
8098,
9502,
272,
399,
1154,
88,
614,
7,
258,
327,
221,
378,
88,
614,
1035,
8098,
9502,
272,
399,
1154,
88,
996,
7,
258,
327,
221,
378,
88,
996,
1035,
8098,
9502,
272,
399,
1154,
88,
1644,
7,
258,
327,
221,
378,
88,
1644,
1035,
8098,
9502,
272,
399,
1154,
88,
966,
7,
258,
327,
221,
378,
88,
966,
1035,
8098,
9502,
272,
399,
1154,
88,
1717,
7,
258,
327,
221,
378,
88,
1717,
1035,
8098,
9502,
272,
399,
1154,
88,
1690,
7,
258,
327,
221,
378,
88,
1690,
1035,
8098,
9502,
272,
399,
1154,
88,
1780,
7,
258,
327,
221,
378,
88,
1780,
1035,
8098,
9502,
272,
399,
1154,
88,
2036,
7,
258,
327,
221,
378,
88,
2036,
1035,
8098,
9502,
272,
399,
1154,
84,
7,
755,
327,
221,
378,
88,
1643,
1035,
8098,
9502,
272,
399,
1154,
78,
7,
755,
327,
221,
378,
88,
16,
33,
1035,
8098,
9502,
272,
399,
1154,
88,
16,
66,
7,
258,
327,
221,
378,
88,
16,
34,
1035,
8098,
9502,
272,
399,
1154,
88,
16,
67,
7,
258,
327,
221,
378,
88,
16,
35,
1035,
8098,
9502,
272,
399,
1154,
82,
7,
755,
327,
221,
378,
88,
16,
36,
1035,
8098,
9502,
272,
399,
1154,
88,
16,
69,
7,
258,
327,
221,
378,
88,
16,
37,
1035,
8098,
9502,
272,
399,
1154,
88,
16,
70,
7,
258,
327,
221,
378,
88,
16,
38,
1035,
8098,
9502,
272,
399,
1154,
88,
709,
7,
258,
327,
221,
378,
88,
709,
1035,
8098,
9502,
272,
399,
1154,
88,
845,
7,
258,
327,
221,
378,
88,
845,
1035,
8098,
9502,
272,
399,
1154,
88,
713,
7,
258,
327,
221,
378,
88,
713,
1035,
8098,
9502,
272,
399,
1154,
88,
969,
7,
258,
327,
221,
378,
88,
969,
1035,
8098,
9502,
272,
399,
1154,
88,
1079,
7,
258,
327,
221,
378,
88,
1079,
1035,
8098,
9502,
272,
399,
1154,
88,
1046,
7,
258,
327,
221,
378,
88,
1046,
1035,
8098,
9502,
272,
399,
1154,
88,
975,
7,
258,
327,
221,
378,
88,
975,
1035,
8098,
9502,
272,
399,
1154,
88,
1196,
7,
258,
327,
221,
378,
88,
1196,
1035,
8098,
9502,
272,
399,
1154,
88,
1085,
7,
258,
327,
221,
378,
88,
1085,
1035,
8098,
9502,
272,
399,
1154,
88,
1167,
7,
258,
327,
221,
378,
88,
1167,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
65,
7,
258,
327,
221,
378,
88,
17,
33,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
66,
7,
258,
327,
221,
378,
88,
17,
34,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
67,
7,
258,
327,
221,
378,
88,
17,
35,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
68,
7,
258,
327,
221,
378,
88,
17,
36,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
69,
7,
258,
327,
221,
378,
88,
17,
37,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
70,
7,
258,
327,
221,
378,
88,
17,
38,
1035,
8098,
9502,
272,
399,
7,
283,
263,
327,
221,
378,
88,
1165,
1035,
16796,
272,
399,
7,
11213,
263,
327,
221,
378,
88,
2025,
1035,
24232,
8132,
272,
399,
30385,
263,
327,
221,
378,
88,
1081,
1035,
11830,
8132,
272,
399,
11525,
7,
263,
327,
221,
378,
88,
1789,
1035,
18122,
5056,
272,
399,
7,
12913,
263,
327,
221,
378,
88,
1194,
1035,
30857,
5056,
272,
399,
5956,
7,
263,
327,
221,
378,
88,
821,
1035,
26684,
5056,
272,
399,
21840,
7,
263,
327,
221,
378,
88,
1479,
1035,
30602,
272,
399,
2,
4065,
263,
327,
221,
378,
88,
1465,
1035,
30876,
272,
399,
7,
360,
263,
327,
221,
378,
88,
1651,
1035,
6578,
20570,
272,
399,
358,
7,
263,
327,
221,
378,
88,
1398,
1035,
7052,
20570,
272,
399,
7,
10223,
263,
327,
221,
378,
88,
18,
33,
1035,
29725,
272,
399,
30269,
263,
327,
221,
378,
88,
18,
34,
1035,
18807,
5056,
272,
399,
1673,
263,
327,
221,
378,
88,
18,
35,
1035,
22849,
272,
399,
12418,
7,
263,
327,
221,
378,
88,
18,
36,
1035,
22553,
13,
18004,
272,
399,
30484,
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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
] |
cestella/incubator-metron
|
metron-deployment/packaging/ambari/elasticsearch-mpack/src/main/resources/common-services/ELASTICSEARCH/5.6.2/package/scripts/service_check.py
|
8
|
4846
|
#!/usr/bin/env python
"""
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 __future__ import print_function
import subprocess
import sys
import re
from resource_management.core.resources.system import Execute
from resource_management.libraries.script import Script
from resource_management.core.logger import Logger
class ServiceCheck(Script):
def service_check(self, env):
import params
env.set_params(params)
Logger.info("Running Elasticsearch service check")
port = self.get_port_from_range(params.http_port)
self.check_cluster_health(params.hostname, port)
self.index_document(params.hostname, port)
Logger.info("Elasticsearch service check successful")
exit(0)
def index_document(self, host, port, doc='{"name": "Ambari Service Check"}', index="ambari_service_check"):
"""
Tests the health of Elasticsearch by indexing a document.
:param host: The name of a host running Elasticsearch.
:param port: The Elasticsearch HTTP port.
:param doc: The test document to put.
:param index: The name of the test index.
"""
# put a document into a new index
Execute("curl -XPUT 'http://%s:%s/%s/test/1' -d '%s'" % (host, port, index, doc), logoutput=True)
# retrieve the document... use subprocess because we actually need the results here.
cmd_retrieve = "curl -XGET 'http://%s:%s/%s/test/1'" % (host, port, index)
proc = subprocess.Popen(cmd_retrieve, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
(stdout, stderr) = proc.communicate()
response_retrieve = stdout
Logger.info("Retrieval response is: %s" % response_retrieve)
expected_retrieve = '{"_index":"%s","_type":"test","_id":"1","_version":1,"found":true,"_source":%s}' \
% (index, doc)
# delete the test index
cmd_delete = "curl -XDELETE 'http://%s:%s/%s'" % (host, port, index)
proc = subprocess.Popen(cmd_delete, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
(stdout, stderr) = proc.communicate()
response_delete = stdout
Logger.info("Delete index response is: %s" % response_retrieve)
expected_delete = '{"acknowledged":true}'
if (expected_retrieve == response_retrieve) and (expected_delete == response_delete):
Logger.info("Successfully indexed document in Elasticsearch")
else:
Logger.info("Unable to retrieve document from Elasticsearch")
sys.exit(1)
def check_cluster_health(self, host, port, status="green", timeout="120s"):
"""
Checks Elasticsearch cluster health. Will wait for a given health
state to be reached.
:param host: The name of a host running Elasticsearch.
:param port: The Elasticsearch HTTP port.
:param status: The expected cluster health state. By default, green.
:param timeout: How long to wait for the cluster. By default, 120 seconds.
"""
Logger.info("Checking cluster health")
cmd = "curl -sS -XGET 'http://{0}:{1}/_cluster/health?wait_for_status={2}&timeout={3}' | grep '\"status\":\"{2}\"'"
Execute(cmd.format(host, port, status, timeout), logoutput=True, tries=5, try_sleep=10)
def get_port_from_range(self, port_range, delimiter="-", default="9200"):
"""
Elasticsearch is configured with a range of ports to bind to, such as
9200-9300. This function identifies a single port within the given range.
:param port_range: A range of ports that Elasticsearch binds to.
:param delimiter: The port range delimiter, by default "-".
:param default: If no port can be identified in the port_range, the default is returned.
:return A single port within the given range.
"""
port = default
if delimiter in port_range:
ports = port_range.split(delimiter)
if len(ports) > 0:
port = ports[0]
return port
if __name__ == "__main__":
ServiceCheck().execute()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
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,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
3873,
199,
646,
984,
199,
646,
295,
199,
199,
504,
2073,
63,
8110,
14,
1018,
14,
4435,
14,
2253,
492,
17009,
199,
504,
2073,
63,
8110,
14,
10159,
14,
1579,
492,
14914,
199,
504,
2073,
63,
8110,
14,
1018,
14,
2921,
492,
15996,
199,
199,
533,
7591,
1799,
8,
5229,
304,
339,
347,
2435,
63,
1074,
8,
277,
12,
2589,
304,
267,
492,
1862,
267,
2589,
14,
409,
63,
1162,
8,
1162,
9,
267,
15996,
14,
815,
480,
9602,
19509,
1733,
2435,
1104,
531,
398,
1844,
275,
291,
14,
362,
63,
719,
63,
504,
63,
1842,
8,
1162,
14,
1014,
63,
719,
9,
267,
291,
14,
1074,
63,
4201,
63,
9665,
8,
1162,
14,
4269,
12,
1844,
9,
267,
291,
14,
1080,
63,
3554,
8,
1162,
14,
4269,
12,
1844,
9,
398,
15996,
14,
815,
480,
27822,
1733,
2435,
1104,
9512,
531,
267,
4458,
8,
16,
9,
339,
347,
1478,
63,
3554,
8,
277,
12,
1591,
12,
1844,
12,
1382,
534,
6641,
354,
582,
298,
29209,
759,
7591,
2670,
3570,
297,
1478,
628,
11020,
759,
63,
1364,
63,
1074,
2349,
267,
408,
267,
6496,
314,
13822,
402,
19509,
1733,
701,
16356,
282,
2213,
14,
398,
520,
635,
1591,
26,
710,
536,
402,
282,
1591,
3879,
19509,
1733,
14,
267,
520,
635,
1844,
26,
710,
19509,
1733,
3101,
1844,
14,
267,
520,
635,
1382,
26,
710,
511,
2213,
370,
5324,
14,
267,
520,
635,
1478,
26,
710,
536,
402,
314,
511,
1478,
14,
267,
408,
267,
327,
5324,
282,
2213,
1901,
282,
892,
1478,
267,
17009,
480,
17096,
446,
56,
4013,
283,
1014,
13827,
83,
2689,
83,
3149,
83,
15,
396,
15,
17,
7,
446,
68,
1543,
83,
4065,
450,
334,
1102,
12,
1844,
12,
1478,
12,
1382,
395,
943,
1199,
29,
549,
9,
398,
327,
8044,
314,
2213,
1396,
221,
675,
3873,
2952,
781,
5965,
1929,
314,
2058,
2348,
14,
267,
2088,
63,
14270,
275,
298,
17096,
446,
56,
2970,
283,
1014,
13827,
83,
2689,
83,
3149,
83,
15,
396,
15,
17,
4065,
450,
334,
1102,
12,
1844,
12,
1478,
9,
267,
6499,
275,
3873,
14,
7942,
8,
1760,
63,
14270,
12,
3839,
29,
5781,
14,
6089,
12,
4635,
29,
5781,
14,
6089,
12,
5218,
29,
549,
9,
267,
334,
2703,
12,
4635,
9,
275,
6499,
14,
10664,
342,
267,
1177,
63,
14270,
275,
3839,
267,
15996,
14,
815,
480,
6816,
322,
2579,
1177,
365,
26,
450,
83,
2,
450,
1177,
63,
14270,
9,
267,
1420,
63,
14270,
275,
17137,
63,
1080,
5122,
5,
83,
2266,
63,
466,
5122,
396,
2266,
63,
344,
5122,
17,
2266,
63,
1023,
582,
17,
4589,
4214,
582,
2052,
4589,
63,
1365,
582,
5,
83,
6834,
971,
288,
450,
334,
1080,
12,
1382,
9,
398,
327,
3145,
314,
511,
1478,
267,
2088,
63,
1807,
275,
298,
17096,
446,
56,
7014,
283,
1014,
13827,
83,
2689,
83,
3149,
83,
4065,
450,
334,
1102,
12,
1844,
12,
1478,
9,
267,
6499,
275,
3873,
14,
7942,
8,
1760,
63,
1807,
12,
3839,
29,
5781,
14,
6089,
12,
4635,
29,
5781,
14,
6089,
12,
5218,
29,
549,
9,
267,
334,
2703,
12,
4635,
9,
275,
6499,
14,
10664,
342,
267,
1177,
63,
1807,
275,
3839,
267,
15996,
14,
815,
480,
5392,
1478,
1177,
365,
26,
450,
83,
2,
450,
1177,
63,
14270,
9,
267,
1420,
63,
1807,
275,
17137,
564,
28609,
3046,
582,
2052,
6834,
398,
340,
334,
2062,
63,
14270,
508,
1177,
63,
14270,
9,
436,
334,
2062,
63,
1807,
508,
1177,
63,
1807,
304,
288,
15996,
14,
815,
480,
25001,
15235,
2213,
315,
19509,
1733,
531,
267,
587,
26,
288,
15996,
14,
815,
480,
6005,
370,
8044,
2213,
687,
19509,
1733,
531,
288,
984,
14,
2224,
8,
17,
9,
339,
347,
1104,
63,
4201,
63,
9665,
8,
277,
12,
1591,
12,
1844,
12,
2004,
628,
7731,
401,
2653,
628,
6708,
83,
2349,
267,
408,
267,
13813,
19509,
1733,
4350,
13822,
14,
221,
12823,
3618,
367,
282,
1627,
13822,
267,
1174,
370,
506,
13075,
14,
398,
520,
635,
1591,
26,
710,
536,
402,
282,
1591,
3879,
19509,
1733,
14,
267,
520,
635,
1844,
26,
710,
19509,
1733,
3101,
1844,
14,
267,
520,
635,
2004,
26,
710,
1420,
4350,
13822,
1174,
14,
221,
4885,
849,
12,
12431,
14,
267,
520,
635,
2653,
26,
7494,
1846,
370,
3618,
367,
314,
4350,
14,
221,
4885,
849,
12,
13960,
4696,
14,
267,
408,
267,
15996,
14,
815,
480,
14740,
4350,
13822,
531,
398,
2088,
275,
298,
17096,
446,
83,
51,
446,
56,
2970,
283,
1014,
20193,
16,
16495,
17,
5995,
63,
4201,
15,
9665,
31,
2573,
63,
509,
63,
1205,
3126,
18,
93,
6,
2593,
3126,
19,
6834,
1204,
20595,
1557,
2,
1205,
19354,
4451,
91,
18,
93,
4451,
4065,
267,
17009,
8,
1760,
14,
908,
8,
1102,
12,
1844,
12,
2004,
12,
2653,
395,
943,
1199,
29,
549,
12,
11275,
29,
21,
12,
862,
63,
4532,
29,
709,
9,
339,
347,
664,
63,
719,
63,
504,
63,
1842,
8,
277,
12,
1844,
63,
1842,
12,
11172,
27295,
401,
849,
628,
25,
1840,
2349,
267,
408,
267,
19509
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
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,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
3873,
199,
646,
984,
199,
646,
295,
199,
199,
504,
2073,
63,
8110,
14,
1018,
14,
4435,
14,
2253,
492,
17009,
199,
504,
2073,
63,
8110,
14,
10159,
14,
1579,
492,
14914,
199,
504,
2073,
63,
8110,
14,
1018,
14,
2921,
492,
15996,
199,
199,
533,
7591,
1799,
8,
5229,
304,
339,
347,
2435,
63,
1074,
8,
277,
12,
2589,
304,
267,
492,
1862,
267,
2589,
14,
409,
63,
1162,
8,
1162,
9,
267,
15996,
14,
815,
480,
9602,
19509,
1733,
2435,
1104,
531,
398,
1844,
275,
291,
14,
362,
63,
719,
63,
504,
63,
1842,
8,
1162,
14,
1014,
63,
719,
9,
267,
291,
14,
1074,
63,
4201,
63,
9665,
8,
1162,
14,
4269,
12,
1844,
9,
267,
291,
14,
1080,
63,
3554,
8,
1162,
14,
4269,
12,
1844,
9,
398,
15996,
14,
815,
480,
27822,
1733,
2435,
1104,
9512,
531,
267,
4458,
8,
16,
9,
339,
347,
1478,
63,
3554,
8,
277,
12,
1591,
12,
1844,
12,
1382,
534,
6641,
354,
582,
298,
29209,
759,
7591,
2670,
3570,
297,
1478,
628,
11020,
759,
63,
1364,
63,
1074,
2349,
267,
408,
267,
6496,
314,
13822,
402,
19509,
1733,
701,
16356,
282,
2213,
14,
398,
520,
635,
1591,
26,
710,
536,
402,
282,
1591,
3879,
19509,
1733,
14,
267,
520,
635,
1844,
26,
710,
19509,
1733,
3101,
1844,
14,
267,
520,
635,
1382,
26,
710,
511,
2213,
370,
5324,
14,
267,
520,
635,
1478,
26,
710,
536,
402,
314,
511,
1478,
14,
267,
408,
267,
327,
5324,
282,
2213,
1901,
282,
892,
1478,
267,
17009,
480,
17096,
446,
56,
4013,
283,
1014,
13827,
83,
2689,
83,
3149,
83,
15,
396,
15,
17,
7,
446,
68,
1543,
83,
4065,
450,
334,
1102,
12,
1844,
12,
1478,
12,
1382,
395,
943,
1199,
29,
549,
9,
398,
327,
8044,
314,
2213,
1396,
221,
675,
3873,
2952,
781,
5965,
1929,
314,
2058,
2348,
14,
267,
2088,
63,
14270,
275,
298,
17096,
446,
56,
2970,
283,
1014,
13827,
83,
2689,
83,
3149,
83,
15,
396,
15,
17,
4065,
450,
334,
1102,
12,
1844,
12,
1478,
9,
267,
6499,
275,
3873,
14,
7942,
8,
1760,
63,
14270,
12,
3839,
29,
5781,
14,
6089,
12,
4635,
29,
5781,
14,
6089,
12,
5218,
29,
549,
9,
267,
334,
2703,
12,
4635,
9,
275,
6499,
14,
10664,
342,
267,
1177,
63,
14270,
275,
3839,
267,
15996,
14,
815,
480,
6816,
322,
2579,
1177,
365,
26,
450,
83,
2,
450,
1177,
63,
14270,
9,
267,
1420,
63,
14270,
275,
17137,
63,
1080,
5122,
5,
83,
2266,
63,
466,
5122,
396,
2266,
63,
344,
5122,
17,
2266,
63,
1023,
582,
17,
4589,
4214,
582,
2052,
4589,
63,
1365,
582,
5,
83,
6834,
971,
288,
450,
334,
1080,
12,
1382,
9,
398,
327,
3145,
314,
511,
1478,
267,
2088,
63,
1807,
275,
298,
17096,
446,
56,
7014,
283,
1014,
13827,
83,
2689,
83,
3149,
83,
4065,
450,
334,
1102,
12,
1844,
12,
1478,
9,
267,
6499,
275,
3873,
14,
7942,
8,
1760,
63,
1807,
12,
3839,
29,
5781,
14,
6089,
12,
4635,
29,
5781,
14,
6089,
12,
5218,
29,
549,
9,
267,
334,
2703,
12,
4635,
9,
275,
6499,
14,
10664,
342,
267,
1177,
63,
1807,
275,
3839,
267,
15996,
14,
815,
480,
5392,
1478,
1177,
365,
26,
450,
83,
2,
450,
1177,
63,
14270,
9,
267,
1420,
63,
1807,
275,
17137,
564,
28609,
3046,
582,
2052,
6834,
398,
340,
334,
2062,
63,
14270,
508,
1177,
63,
14270,
9,
436,
334,
2062,
63,
1807,
508,
1177,
63,
1807,
304,
288,
15996,
14,
815,
480,
25001,
15235,
2213,
315,
19509,
1733,
531,
267,
587,
26,
288,
15996,
14,
815,
480,
6005,
370,
8044,
2213,
687,
19509,
1733,
531,
288,
984,
14,
2224,
8,
17,
9,
339,
347,
1104,
63,
4201,
63,
9665,
8,
277,
12,
1591,
12,
1844,
12,
2004,
628,
7731,
401,
2653,
628,
6708,
83,
2349,
267,
408,
267,
13813,
19509,
1733,
4350,
13822,
14,
221,
12823,
3618,
367,
282,
1627,
13822,
267,
1174,
370,
506,
13075,
14,
398,
520,
635,
1591,
26,
710,
536,
402,
282,
1591,
3879,
19509,
1733,
14,
267,
520,
635,
1844,
26,
710,
19509,
1733,
3101,
1844,
14,
267,
520,
635,
2004,
26,
710,
1420,
4350,
13822,
1174,
14,
221,
4885,
849,
12,
12431,
14,
267,
520,
635,
2653,
26,
7494,
1846,
370,
3618,
367,
314,
4350,
14,
221,
4885,
849,
12,
13960,
4696,
14,
267,
408,
267,
15996,
14,
815,
480,
14740,
4350,
13822,
531,
398,
2088,
275,
298,
17096,
446,
83,
51,
446,
56,
2970,
283,
1014,
20193,
16,
16495,
17,
5995,
63,
4201,
15,
9665,
31,
2573,
63,
509,
63,
1205,
3126,
18,
93,
6,
2593,
3126,
19,
6834,
1204,
20595,
1557,
2,
1205,
19354,
4451,
91,
18,
93,
4451,
4065,
267,
17009,
8,
1760,
14,
908,
8,
1102,
12,
1844,
12,
2004,
12,
2653,
395,
943,
1199,
29,
549,
12,
11275,
29,
21,
12,
862,
63,
4532,
29,
709,
9,
339,
347,
664,
63,
719,
63,
504,
63,
1842,
8,
277,
12,
1844,
63,
1842,
12,
11172,
27295,
401,
849,
628,
25,
1840,
2349,
267,
408,
267,
19509,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dexterx17/nodoSocket
|
clients/Python-2.7.6/Demo/turtle/tdemo_paint.py
|
6
|
1125
|
#!/usr/bin/env python
""" turtle-example-suite:
tdemo_paint.py
A simple eventdriven paint program
- use left mouse button to move turtle
- middle mouse button to change color
- right mouse button do turn filling on/off
-------------------------------------------
Play around by clicking into the canvas
using all three mouse buttons.
-------------------------------------------
To exit press STOP button
-------------------------------------------
"""
from turtle import *
def switchupdown(x=0, y=0):
if pen()["pendown"]:
end_fill()
up()
else:
down()
begin_fill()
def changecolor(x=0, y=0):
global colors
colors = colors[1:]+colors[:1]
color(colors[0])
def main():
global colors
shape("circle")
resizemode("user")
shapesize(.5)
width(3)
colors=["red", "green", "blue", "yellow"]
color(colors[0])
switchupdown()
onscreenclick(goto,1)
onscreenclick(changecolor,2)
onscreenclick(switchupdown,3)
return "EVENTLOOP"
if __name__ == "__main__":
msg = main()
print msg
mainloop()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
755,
11946,
13,
2694,
13,
5768,
26,
953,
307,
8768,
63,
17486,
14,
647,
199,
199,
33,
3486,
221,
1566,
17824,
1856,
32055,
2240,
199,
199,
13,
675,
3602,
12817,
5528,
370,
4057,
11946,
199,
13,
12180,
12817,
5528,
370,
1570,
3164,
199,
13,
2451,
12817,
5528,
886,
7485,
32499,
641,
15,
1997,
199,
11016,
13715,
199,
16527,
6818,
701,
8968,
316,
1901,
314,
10218,
199,
1808,
1006,
7795,
12817,
15766,
14,
199,
11016,
13715,
881,
4005,
4458,
15105,
22348,
5528,
199,
11016,
13715,
199,
624,
199,
504,
11946,
492,
627,
199,
199,
318,
6258,
384,
2110,
8,
88,
29,
16,
12,
612,
29,
16,
304,
272,
340,
12374,
22957,
6643,
944,
6229,
267,
1284,
63,
4498,
342,
267,
1536,
342,
272,
587,
26,
267,
3224,
342,
267,
5386,
63,
4498,
342,
199,
199,
318,
1570,
2326,
8,
88,
29,
16,
12,
612,
29,
16,
304,
272,
2288,
9229,
272,
9229,
275,
9229,
59,
17,
26,
2807,
7120,
1491,
17,
61,
272,
3164,
8,
7120,
59,
16,
566,
199,
199,
318,
2446,
837,
272,
2288,
9229,
272,
2215,
480,
11001,
531,
272,
15210,
632,
480,
751,
531,
272,
2215,
890,
13417,
21,
9,
272,
3462,
8,
19,
9,
272,
9229,
6270,
581,
401,
298,
7731,
401,
298,
6304,
401,
298,
14514,
937,
272,
3164,
8,
7120,
59,
16,
566,
272,
6258,
384,
2110,
342,
272,
641,
5410,
4891,
8,
14867,
12,
17,
9,
272,
641,
5410,
4891,
8,
1461,
2326,
12,
18,
9,
272,
641,
5410,
4891,
8,
5656,
384,
2110,
12,
19,
9,
272,
372,
298,
8193,
26573,
2,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1499,
275,
2446,
342,
272,
870,
1499,
272,
2446,
3813,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
755,
11946,
13,
2694,
13,
5768,
26,
953,
307,
8768,
63,
17486,
14,
647,
199,
199,
33,
3486,
221,
1566,
17824,
1856,
32055,
2240,
199,
199,
13,
675,
3602,
12817,
5528,
370,
4057,
11946,
199,
13,
12180,
12817,
5528,
370,
1570,
3164,
199,
13,
2451,
12817,
5528,
886,
7485,
32499,
641,
15,
1997,
199,
11016,
13715,
199,
16527,
6818,
701,
8968,
316,
1901,
314,
10218,
199,
1808,
1006,
7795,
12817,
15766,
14,
199,
11016,
13715,
881,
4005,
4458,
15105,
22348,
5528,
199,
11016,
13715,
199,
624,
199,
504,
11946,
492,
627,
199,
199,
318,
6258,
384,
2110,
8,
88,
29,
16,
12,
612,
29,
16,
304,
272,
340,
12374,
22957,
6643,
944,
6229,
267,
1284,
63,
4498,
342,
267,
1536,
342,
272,
587,
26,
267,
3224,
342,
267,
5386,
63,
4498,
342,
199,
199,
318,
1570,
2326,
8,
88,
29,
16,
12,
612,
29,
16,
304,
272,
2288,
9229,
272,
9229,
275,
9229,
59,
17,
26,
2807,
7120,
1491,
17,
61,
272,
3164,
8,
7120,
59,
16,
566,
199,
199,
318,
2446,
837,
272,
2288,
9229,
272,
2215,
480,
11001,
531,
272,
15210,
632,
480,
751,
531,
272,
2215,
890,
13417,
21,
9,
272,
3462,
8,
19,
9,
272,
9229,
6270,
581,
401,
298,
7731,
401,
298,
6304,
401,
298,
14514,
937,
272,
3164,
8,
7120,
59,
16,
566,
272,
6258,
384,
2110,
342,
272,
641,
5410,
4891,
8,
14867,
12,
17,
9,
272,
641,
5410,
4891,
8,
1461,
2326,
12,
18,
9,
272,
641,
5410,
4891,
8,
5656,
384,
2110,
12,
19,
9,
272,
372,
298,
8193,
26573,
2,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1499,
275,
2446,
342,
272,
870,
1499,
272,
2446,
3813,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
adiIspas/Machine-Learning_A-Z
|
Machine Learning A-Z/Part 7 - Natural Language Processing/Section 36 - Natural Language Processing/natural_language_processing.py
|
3
|
1452
|
# Natural Language Processing
# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Importing the dataset
dataset = pd.read_csv('Restaurant_Reviews.tsv', delimiter = '\t', quoting = 3)
# Cleaning the texts
import re
import nltk
nltk.download('stopwords')
from nltk.corpus import stopwords
from nltk.stem.porter import PorterStemmer
corpus = []
for i in range(0, 1000):
review = re.sub('[^a-zA-Z]', ' ', dataset['Review'][i])
review = review.lower()
review = review.split()
ps = PorterStemmer()
review = [ps.stem(word) for word in review if not word in set(stopwords.words('english'))]
review = ' '.join(review)
corpus.append(review)
# Creating the Bag of Words model
from sklearn.feature_extraction.text import CountVectorizer
cv = CountVectorizer(max_features = 1500)
X = cv.fit_transform(corpus).toarray()
y = dataset.iloc[:, 1].values
# Splitting the dataset into the Training set and Test set
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.20, random_state = 0)
# Fitting Naive Bayes to the Training set
from sklearn.naive_bayes import GaussianNB
classifier = GaussianNB()
classifier.fit(X_train, y_train)
# Predicting the Test set results
y_pred = classifier.predict(X_test)
# Making the Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
|
mit
|
[
3,
653,
292,
4889,
8466,
20157,
199,
199,
3,
3161,
316,
314,
8363,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
10634,
465,
6454,
199,
199,
3,
3161,
316,
314,
4789,
199,
5214,
275,
6454,
14,
739,
63,
4737,
360,
32075,
63,
497,
4196,
14,
29362,
297,
11172,
275,
1557,
84,
297,
18593,
275,
650,
9,
199,
199,
3,
12762,
316,
314,
24857,
199,
646,
295,
199,
646,
24706,
199,
7530,
2663,
14,
4249,
360,
2379,
3148,
358,
199,
504,
24706,
14,
16780,
492,
3631,
3148,
199,
504,
24706,
14,
18446,
14,
80,
3968,
492,
510,
3968,
51,
563,
2626,
199,
16780,
275,
942,
199,
509,
284,
315,
1425,
8,
16,
12,
5198,
304,
272,
11248,
275,
295,
14,
954,
360,
4735,
65,
13,
6353,
13,
58,
4300,
283,
1656,
4789,
459,
21000,
3488,
73,
566,
272,
11248,
275,
11248,
14,
2325,
342,
272,
11248,
275,
11248,
14,
1294,
342,
272,
7347,
275,
510,
3968,
51,
563,
2626,
342,
272,
11248,
275,
359,
1190,
14,
18446,
8,
1027,
9,
367,
4349,
315,
11248,
340,
440,
4349,
315,
663,
8,
2379,
3148,
14,
3148,
360,
17872,
27738,
272,
11248,
275,
283,
1987,
904,
8,
8578,
9,
272,
16831,
14,
740,
8,
8578,
9,
199,
199,
3,
20507,
314,
699,
643,
402,
644,
5630,
1402,
199,
504,
6357,
14,
4445,
63,
24020,
14,
505,
492,
14826,
26165,
199,
5107,
275,
14826,
26165,
8,
988,
63,
3179,
275,
24970,
9,
199,
56,
275,
6277,
14,
3269,
63,
4711,
8,
16780,
680,
18993,
342,
199,
89,
275,
4789,
14,
21104,
3981,
413,
1055,
1459,
199,
199,
3,
11740,
1337,
314,
4789,
1901,
314,
22859,
663,
436,
1379,
663,
199,
504,
6357,
14,
7925,
63,
6136,
492,
3560,
63,
396,
63,
1294,
199,
56,
63,
2834,
12,
1323,
63,
396,
12,
612,
63,
2834,
12,
612,
63,
396,
275,
3560,
63,
396,
63,
1294,
8,
56,
12,
612,
12,
511,
63,
890,
275,
378,
14,
1165,
12,
2196,
63,
929,
275,
378,
9,
199,
199,
3,
25971,
1337,
11290,
1912,
29434,
397,
370,
314,
22859,
663,
199,
504,
6357,
14,
21578,
63,
19558,
397,
492,
17131,
16170,
199,
14720,
275,
17131,
16170,
342,
199,
14720,
14,
3269,
8,
56,
63,
2834,
12,
612,
63,
2834,
9,
199,
199,
3,
5543,
807,
316,
314,
1379,
663,
2058,
199,
89,
63,
5991,
275,
12429,
14,
6892,
8,
56,
63,
396,
9,
199,
199,
3,
32269,
314,
32539,
12444,
8449,
199,
504,
6357,
14,
6759,
492,
26314,
63,
3642,
199,
4400,
275,
26314,
63,
3642,
8,
89,
63,
396,
12,
612,
63,
5991,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
653,
292,
4889,
8466,
20157,
199,
199,
3,
3161,
316,
314,
8363,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
10634,
465,
6454,
199,
199,
3,
3161,
316,
314,
4789,
199,
5214,
275,
6454,
14,
739,
63,
4737,
360,
32075,
63,
497,
4196,
14,
29362,
297,
11172,
275,
1557,
84,
297,
18593,
275,
650,
9,
199,
199,
3,
12762,
316,
314,
24857,
199,
646,
295,
199,
646,
24706,
199,
7530,
2663,
14,
4249,
360,
2379,
3148,
358,
199,
504,
24706,
14,
16780,
492,
3631,
3148,
199,
504,
24706,
14,
18446,
14,
80,
3968,
492,
510,
3968,
51,
563,
2626,
199,
16780,
275,
942,
199,
509,
284,
315,
1425,
8,
16,
12,
5198,
304,
272,
11248,
275,
295,
14,
954,
360,
4735,
65,
13,
6353,
13,
58,
4300,
283,
1656,
4789,
459,
21000,
3488,
73,
566,
272,
11248,
275,
11248,
14,
2325,
342,
272,
11248,
275,
11248,
14,
1294,
342,
272,
7347,
275,
510,
3968,
51,
563,
2626,
342,
272,
11248,
275,
359,
1190,
14,
18446,
8,
1027,
9,
367,
4349,
315,
11248,
340,
440,
4349,
315,
663,
8,
2379,
3148,
14,
3148,
360,
17872,
27738,
272,
11248,
275,
283,
1987,
904,
8,
8578,
9,
272,
16831,
14,
740,
8,
8578,
9,
199,
199,
3,
20507,
314,
699,
643,
402,
644,
5630,
1402,
199,
504,
6357,
14,
4445,
63,
24020,
14,
505,
492,
14826,
26165,
199,
5107,
275,
14826,
26165,
8,
988,
63,
3179,
275,
24970,
9,
199,
56,
275,
6277,
14,
3269,
63,
4711,
8,
16780,
680,
18993,
342,
199,
89,
275,
4789,
14,
21104,
3981,
413,
1055,
1459,
199,
199,
3,
11740,
1337,
314,
4789,
1901,
314,
22859,
663,
436,
1379,
663,
199,
504,
6357,
14,
7925,
63,
6136,
492,
3560,
63,
396,
63,
1294,
199,
56,
63,
2834,
12,
1323,
63,
396,
12,
612,
63,
2834,
12,
612,
63,
396,
275,
3560,
63,
396,
63,
1294,
8,
56,
12,
612,
12,
511,
63,
890,
275,
378,
14,
1165,
12,
2196,
63,
929,
275,
378,
9,
199,
199,
3,
25971,
1337,
11290,
1912,
29434,
397,
370,
314,
22859,
663,
199,
504,
6357,
14,
21578,
63,
19558,
397,
492,
17131,
16170,
199,
14720,
275,
17131,
16170,
342,
199,
14720,
14,
3269,
8,
56,
63,
2834,
12,
612,
63,
2834,
9,
199,
199,
3,
5543,
807,
316,
314,
1379,
663,
2058,
199,
89,
63,
5991,
275,
12429,
14,
6892,
8,
56,
63,
396,
9,
199,
199,
3,
32269,
314,
32539,
12444,
8449,
199,
504,
6357,
14,
6759,
492,
26314,
63,
3642,
199,
4400,
275,
26314,
63,
3642,
8,
89,
63,
396,
12,
612,
63,
5991,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
YangChihWei/w16b_test
|
static/Brython3.1.3-20150514-095342/Lib/tarfile.py
|
728
|
88474
|
#!/usr/bin/env python3
#-------------------------------------------------------------------
# tarfile.py
#-------------------------------------------------------------------
# Copyright (C) 2002 Lars Gustaebel <lars@gustaebel.de>
# All rights reserved.
#
# 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.
#
"""Read from and write to tar format archives.
"""
version = "0.9.0"
__author__ = "Lars Gust\u00e4bel (lars@gustaebel.de)"
__date__ = "$Date: 2011-02-25 17:42:01 +0200 (Fri, 25 Feb 2011) $"
__cvsid__ = "$Id: tarfile.py 88586 2011-02-25 15:42:01Z marc-andre.lemburg $"
__credits__ = "Gustavo Niemeyer, Niels Gust\u00e4bel, Richard Townsend."
#---------
# Imports
#---------
import sys
import os
import io
import shutil
import stat
import time
import struct
import copy
import re
try:
import grp, pwd
except ImportError:
grp = pwd = None
# os.symlink on Windows prior to 6.0 raises NotImplementedError
symlink_exception = (AttributeError, NotImplementedError)
try:
# WindowsError (1314) will be raised if the caller does not hold the
# SeCreateSymbolicLinkPrivilege privilege
symlink_exception += (WindowsError,)
except NameError:
pass
# from tarfile import *
__all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError"]
from builtins import open as _open # Since 'open' is TarFile.open
#---------------------------------------------------------
# tar constants
#---------------------------------------------------------
NUL = b"\0" # the null character
BLOCKSIZE = 512 # length of processing blocks
RECORDSIZE = BLOCKSIZE * 20 # length of records
GNU_MAGIC = b"ustar \0" # magic gnu tar string
POSIX_MAGIC = b"ustar\x0000" # magic posix tar string
LENGTH_NAME = 100 # maximum length of a filename
LENGTH_LINK = 100 # maximum length of a linkname
LENGTH_PREFIX = 155 # maximum length of the prefix field
REGTYPE = b"0" # regular file
AREGTYPE = b"\0" # regular file
LNKTYPE = b"1" # link (inside tarfile)
SYMTYPE = b"2" # symbolic link
CHRTYPE = b"3" # character special device
BLKTYPE = b"4" # block special device
DIRTYPE = b"5" # directory
FIFOTYPE = b"6" # fifo special device
CONTTYPE = b"7" # contiguous file
GNUTYPE_LONGNAME = b"L" # GNU tar longname
GNUTYPE_LONGLINK = b"K" # GNU tar longlink
GNUTYPE_SPARSE = b"S" # GNU tar sparse file
XHDTYPE = b"x" # POSIX.1-2001 extended header
XGLTYPE = b"g" # POSIX.1-2001 global header
SOLARIS_XHDTYPE = b"X" # Solaris extended header
USTAR_FORMAT = 0 # POSIX.1-1988 (ustar) format
GNU_FORMAT = 1 # GNU tar format
PAX_FORMAT = 2 # POSIX.1-2001 (pax) format
DEFAULT_FORMAT = GNU_FORMAT
#---------------------------------------------------------
# tarfile constants
#---------------------------------------------------------
# File types that tarfile supports:
SUPPORTED_TYPES = (REGTYPE, AREGTYPE, LNKTYPE,
SYMTYPE, DIRTYPE, FIFOTYPE,
CONTTYPE, CHRTYPE, BLKTYPE,
GNUTYPE_LONGNAME, GNUTYPE_LONGLINK,
GNUTYPE_SPARSE)
# File types that will be treated as a regular file.
REGULAR_TYPES = (REGTYPE, AREGTYPE,
CONTTYPE, GNUTYPE_SPARSE)
# File types that are part of the GNU tar format.
GNU_TYPES = (GNUTYPE_LONGNAME, GNUTYPE_LONGLINK,
GNUTYPE_SPARSE)
# Fields from a pax header that override a TarInfo attribute.
PAX_FIELDS = ("path", "linkpath", "size", "mtime",
"uid", "gid", "uname", "gname")
# Fields from a pax header that are affected by hdrcharset.
PAX_NAME_FIELDS = {"path", "linkpath", "uname", "gname"}
# Fields in a pax header that are numbers, all other fields
# are treated as strings.
PAX_NUMBER_FIELDS = {
"atime": float,
"ctime": float,
"mtime": float,
"uid": int,
"gid": int,
"size": int
}
#---------------------------------------------------------
# Bits used in the mode field, values in octal.
#---------------------------------------------------------
S_IFLNK = 0o120000 # symbolic link
S_IFREG = 0o100000 # regular file
S_IFBLK = 0o060000 # block device
S_IFDIR = 0o040000 # directory
S_IFCHR = 0o020000 # character device
S_IFIFO = 0o010000 # fifo
TSUID = 0o4000 # set UID on execution
TSGID = 0o2000 # set GID on execution
TSVTX = 0o1000 # reserved
TUREAD = 0o400 # read by owner
TUWRITE = 0o200 # write by owner
TUEXEC = 0o100 # execute/search by owner
TGREAD = 0o040 # read by group
TGWRITE = 0o020 # write by group
TGEXEC = 0o010 # execute/search by group
TOREAD = 0o004 # read by other
TOWRITE = 0o002 # write by other
TOEXEC = 0o001 # execute/search by other
#---------------------------------------------------------
# initialization
#---------------------------------------------------------
if os.name in ("nt", "ce"):
ENCODING = "utf-8"
else:
ENCODING = sys.getfilesystemencoding()
#---------------------------------------------------------
# Some useful functions
#---------------------------------------------------------
def stn(s, length, encoding, errors):
"""Convert a string to a null-terminated bytes object.
"""
s = s.encode(encoding, errors)
return s[:length] + (length - len(s)) * NUL
def nts(s, encoding, errors):
"""Convert a null-terminated bytes object to a string.
"""
p = s.find(b"\0")
if p != -1:
s = s[:p]
return s.decode(encoding, errors)
def nti(s):
"""Convert a number field to a python number.
"""
# There are two possible encodings for a number field, see
# itn() below.
if s[0] in (0o200, 0o377):
n = 0
for i in range(len(s) - 1):
n <<= 8
n += s[i + 1]
if s[0] == 0o377:
n = -(256 ** (len(s) - 1) - n)
else:
try:
n = int(nts(s, "ascii", "strict") or "0", 8)
except ValueError:
raise InvalidHeaderError("invalid header")
return n
def itn(n, digits=8, format=DEFAULT_FORMAT):
"""Convert a python number to a number field.
"""
# POSIX 1003.1-1988 requires numbers to be encoded as a string of
# octal digits followed by a null-byte, this allows values up to
# (8**(digits-1))-1. GNU tar allows storing numbers greater than
# that if necessary. A leading 0o200 or 0o377 byte indicate this
# particular encoding, the following digits-1 bytes are a big-endian
# base-256 representation. This allows values up to (256**(digits-1))-1.
# A 0o200 byte indicates a positive number, a 0o377 byte a negative
# number.
if 0 <= n < 8 ** (digits - 1):
s = bytes("%0*o" % (digits - 1, n), "ascii") + NUL
elif format == GNU_FORMAT and -256 ** (digits - 1) <= n < 256 ** (digits - 1):
if n >= 0:
s = bytearray([0o200])
else:
s = bytearray([0o377])
n = 256 ** digits + n
for i in range(digits - 1):
s.insert(1, n & 0o377)
n >>= 8
else:
raise ValueError("overflow in number field")
return s
def calc_chksums(buf):
"""Calculate the checksum for a member's header by summing up all
characters except for the chksum field which is treated as if
it was filled with spaces. According to the GNU tar sources,
some tars (Sun and NeXT) calculate chksum with signed char,
which will be different if there are chars in the buffer with
the high bit set. So we calculate two checksums, unsigned and
signed.
"""
unsigned_chksum = 256 + sum(struct.unpack_from("148B8x356B", buf))
signed_chksum = 256 + sum(struct.unpack_from("148b8x356b", buf))
return unsigned_chksum, signed_chksum
def copyfileobj(src, dst, length=None):
"""Copy length bytes from fileobj src to fileobj dst.
If length is None, copy the entire content.
"""
if length == 0:
return
if length is None:
shutil.copyfileobj(src, dst)
return
BUFSIZE = 16 * 1024
blocks, remainder = divmod(length, BUFSIZE)
for b in range(blocks):
buf = src.read(BUFSIZE)
if len(buf) < BUFSIZE:
raise IOError("end of file reached")
dst.write(buf)
if remainder != 0:
buf = src.read(remainder)
if len(buf) < remainder:
raise IOError("end of file reached")
dst.write(buf)
return
def filemode(mode):
"""Deprecated in this location; use stat.filemode."""
import warnings
warnings.warn("deprecated in favor of stat.filemode",
DeprecationWarning, 2)
return stat.filemode(mode)
class TarError(Exception):
"""Base exception."""
pass
class ExtractError(TarError):
"""General exception for extract errors."""
pass
class ReadError(TarError):
"""Exception for unreadable tar archives."""
pass
class CompressionError(TarError):
"""Exception for unavailable compression methods."""
pass
class StreamError(TarError):
"""Exception for unsupported operations on stream-like TarFiles."""
pass
class HeaderError(TarError):
"""Base exception for header errors."""
pass
class EmptyHeaderError(HeaderError):
"""Exception for empty headers."""
pass
class TruncatedHeaderError(HeaderError):
"""Exception for truncated headers."""
pass
class EOFHeaderError(HeaderError):
"""Exception for end of file headers."""
pass
class InvalidHeaderError(HeaderError):
"""Exception for invalid headers."""
pass
class SubsequentHeaderError(HeaderError):
"""Exception for missing and invalid extended headers."""
pass
#---------------------------
# internal stream interface
#---------------------------
class _LowLevelFile:
"""Low-level file object. Supports reading and writing.
It is used instead of a regular file object for streaming
access.
"""
def __init__(self, name, mode):
mode = {
"r": os.O_RDONLY,
"w": os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
}[mode]
if hasattr(os, "O_BINARY"):
mode |= os.O_BINARY
self.fd = os.open(name, mode, 0o666)
def close(self):
os.close(self.fd)
def read(self, size):
return os.read(self.fd, size)
def write(self, s):
os.write(self.fd, s)
class _Stream:
"""Class that serves as an adapter between TarFile and
a stream-like object. The stream-like object only
needs to have a read() or write() method and is accessed
blockwise. Use of gzip or bzip2 compression is possible.
A stream-like object could be for example: sys.stdin,
sys.stdout, a socket, a tape device etc.
_Stream is intended to be used only internally.
"""
def __init__(self, name, mode, comptype, fileobj, bufsize):
"""Construct a _Stream object.
"""
self._extfileobj = True
if fileobj is None:
fileobj = _LowLevelFile(name, mode)
self._extfileobj = False
if comptype == '*':
# Enable transparent compression detection for the
# stream interface
fileobj = _StreamProxy(fileobj)
comptype = fileobj.getcomptype()
self.name = name or ""
self.mode = mode
self.comptype = comptype
self.fileobj = fileobj
self.bufsize = bufsize
self.buf = b""
self.pos = 0
self.closed = False
try:
if comptype == "gz":
try:
import zlib
except ImportError:
raise CompressionError("zlib module is not available")
self.zlib = zlib
self.crc = zlib.crc32(b"")
if mode == "r":
self._init_read_gz()
self.exception = zlib.error
else:
self._init_write_gz()
elif comptype == "bz2":
try:
import bz2
except ImportError:
raise CompressionError("bz2 module is not available")
if mode == "r":
self.dbuf = b""
self.cmp = bz2.BZ2Decompressor()
self.exception = IOError
else:
self.cmp = bz2.BZ2Compressor()
elif comptype == "xz":
try:
import lzma
except ImportError:
raise CompressionError("lzma module is not available")
if mode == "r":
self.dbuf = b""
self.cmp = lzma.LZMADecompressor()
self.exception = lzma.LZMAError
else:
self.cmp = lzma.LZMACompressor()
elif comptype != "tar":
raise CompressionError("unknown compression type %r" % comptype)
except:
if not self._extfileobj:
self.fileobj.close()
self.closed = True
raise
def __del__(self):
if hasattr(self, "closed") and not self.closed:
self.close()
def _init_write_gz(self):
"""Initialize for writing with gzip compression.
"""
self.cmp = self.zlib.compressobj(9, self.zlib.DEFLATED,
-self.zlib.MAX_WBITS,
self.zlib.DEF_MEM_LEVEL,
0)
timestamp = struct.pack("<L", int(time.time()))
self.__write(b"\037\213\010\010" + timestamp + b"\002\377")
if self.name.endswith(".gz"):
self.name = self.name[:-3]
# RFC1952 says we must use ISO-8859-1 for the FNAME field.
self.__write(self.name.encode("iso-8859-1", "replace") + NUL)
def write(self, s):
"""Write string s to the stream.
"""
if self.comptype == "gz":
self.crc = self.zlib.crc32(s, self.crc)
self.pos += len(s)
if self.comptype != "tar":
s = self.cmp.compress(s)
self.__write(s)
def __write(self, s):
"""Write string s to the stream if a whole new block
is ready to be written.
"""
self.buf += s
while len(self.buf) > self.bufsize:
self.fileobj.write(self.buf[:self.bufsize])
self.buf = self.buf[self.bufsize:]
def close(self):
"""Close the _Stream object. No operation should be
done on it afterwards.
"""
if self.closed:
return
if self.mode == "w" and self.comptype != "tar":
self.buf += self.cmp.flush()
if self.mode == "w" and self.buf:
self.fileobj.write(self.buf)
self.buf = b""
if self.comptype == "gz":
# The native zlib crc is an unsigned 32-bit integer, but
# the Python wrapper implicitly casts that to a signed C
# long. So, on a 32-bit box self.crc may "look negative",
# while the same crc on a 64-bit box may "look positive".
# To avoid irksome warnings from the `struct` module, force
# it to look positive on all boxes.
self.fileobj.write(struct.pack("<L", self.crc & 0xffffffff))
self.fileobj.write(struct.pack("<L", self.pos & 0xffffFFFF))
if not self._extfileobj:
self.fileobj.close()
self.closed = True
def _init_read_gz(self):
"""Initialize for reading a gzip compressed fileobj.
"""
self.cmp = self.zlib.decompressobj(-self.zlib.MAX_WBITS)
self.dbuf = b""
# taken from gzip.GzipFile with some alterations
if self.__read(2) != b"\037\213":
raise ReadError("not a gzip file")
if self.__read(1) != b"\010":
raise CompressionError("unsupported compression method")
flag = ord(self.__read(1))
self.__read(6)
if flag & 4:
xlen = ord(self.__read(1)) + 256 * ord(self.__read(1))
self.read(xlen)
if flag & 8:
while True:
s = self.__read(1)
if not s or s == NUL:
break
if flag & 16:
while True:
s = self.__read(1)
if not s or s == NUL:
break
if flag & 2:
self.__read(2)
def tell(self):
"""Return the stream's file pointer position.
"""
return self.pos
def seek(self, pos=0):
"""Set the stream's file pointer to pos. Negative seeking
is forbidden.
"""
if pos - self.pos >= 0:
blocks, remainder = divmod(pos - self.pos, self.bufsize)
for i in range(blocks):
self.read(self.bufsize)
self.read(remainder)
else:
raise StreamError("seeking backwards is not allowed")
return self.pos
def read(self, size=None):
"""Return the next size number of bytes from the stream.
If size is not defined, return all bytes of the stream
up to EOF.
"""
if size is None:
t = []
while True:
buf = self._read(self.bufsize)
if not buf:
break
t.append(buf)
buf = "".join(t)
else:
buf = self._read(size)
self.pos += len(buf)
return buf
def _read(self, size):
"""Return size bytes from the stream.
"""
if self.comptype == "tar":
return self.__read(size)
c = len(self.dbuf)
while c < size:
buf = self.__read(self.bufsize)
if not buf:
break
try:
buf = self.cmp.decompress(buf)
except self.exception:
raise ReadError("invalid compressed data")
self.dbuf += buf
c += len(buf)
buf = self.dbuf[:size]
self.dbuf = self.dbuf[size:]
return buf
def __read(self, size):
"""Return size bytes from stream. If internal buffer is empty,
read another block from the stream.
"""
c = len(self.buf)
while c < size:
buf = self.fileobj.read(self.bufsize)
if not buf:
break
self.buf += buf
c += len(buf)
buf = self.buf[:size]
self.buf = self.buf[size:]
return buf
# class _Stream
class _StreamProxy(object):
"""Small proxy class that enables transparent compression
detection for the Stream interface (mode 'r|*').
"""
def __init__(self, fileobj):
self.fileobj = fileobj
self.buf = self.fileobj.read(BLOCKSIZE)
def read(self, size):
self.read = self.fileobj.read
return self.buf
def getcomptype(self):
if self.buf.startswith(b"\x1f\x8b\x08"):
return "gz"
elif self.buf[0:3] == b"BZh" and self.buf[4:10] == b"1AY&SY":
return "bz2"
elif self.buf.startswith((b"\x5d\x00\x00\x80", b"\xfd7zXZ")):
return "xz"
else:
return "tar"
def close(self):
self.fileobj.close()
# class StreamProxy
#------------------------
# Extraction file object
#------------------------
class _FileInFile(object):
"""A thin wrapper around an existing file object that
provides a part of its data as an individual file
object.
"""
def __init__(self, fileobj, offset, size, blockinfo=None):
self.fileobj = fileobj
self.offset = offset
self.size = size
self.position = 0
self.name = getattr(fileobj, "name", None)
self.closed = False
if blockinfo is None:
blockinfo = [(0, size)]
# Construct a map with data and zero blocks.
self.map_index = 0
self.map = []
lastpos = 0
realpos = self.offset
for offset, size in blockinfo:
if offset > lastpos:
self.map.append((False, lastpos, offset, None))
self.map.append((True, offset, offset + size, realpos))
realpos += size
lastpos = offset + size
if lastpos < self.size:
self.map.append((False, lastpos, self.size, None))
def flush(self):
pass
def readable(self):
return True
def writable(self):
return False
def seekable(self):
return self.fileobj.seekable()
def tell(self):
"""Return the current file position.
"""
return self.position
def seek(self, position, whence=io.SEEK_SET):
"""Seek to a position in the file.
"""
if whence == io.SEEK_SET:
self.position = min(max(position, 0), self.size)
elif whence == io.SEEK_CUR:
if position < 0:
self.position = max(self.position + position, 0)
else:
self.position = min(self.position + position, self.size)
elif whence == io.SEEK_END:
self.position = max(min(self.size + position, self.size), 0)
else:
raise ValueError("Invalid argument")
return self.position
def read(self, size=None):
"""Read data from the file.
"""
if size is None:
size = self.size - self.position
else:
size = min(size, self.size - self.position)
buf = b""
while size > 0:
while True:
data, start, stop, offset = self.map[self.map_index]
if start <= self.position < stop:
break
else:
self.map_index += 1
if self.map_index == len(self.map):
self.map_index = 0
length = min(size, stop - self.position)
if data:
self.fileobj.seek(offset + (self.position - start))
buf += self.fileobj.read(length)
else:
buf += NUL * length
size -= length
self.position += length
return buf
def readinto(self, b):
buf = self.read(len(b))
b[:len(buf)] = buf
return len(buf)
def close(self):
self.closed = True
#class _FileInFile
class ExFileObject(io.BufferedReader):
def __init__(self, tarfile, tarinfo):
fileobj = _FileInFile(tarfile.fileobj, tarinfo.offset_data,
tarinfo.size, tarinfo.sparse)
super().__init__(fileobj)
#class ExFileObject
#------------------
# Exported Classes
#------------------
class TarInfo(object):
"""Informational class which holds the details about an
archive member given by a tar header block.
TarInfo objects are returned by TarFile.getmember(),
TarFile.getmembers() and TarFile.gettarinfo() and are
usually created internally.
"""
__slots__ = ("name", "mode", "uid", "gid", "size", "mtime",
"chksum", "type", "linkname", "uname", "gname",
"devmajor", "devminor",
"offset", "offset_data", "pax_headers", "sparse",
"tarfile", "_sparse_structs", "_link_target")
def __init__(self, name=""):
"""Construct a TarInfo object. name is the optional name
of the member.
"""
self.name = name # member name
self.mode = 0o644 # file permissions
self.uid = 0 # user id
self.gid = 0 # group id
self.size = 0 # file size
self.mtime = 0 # modification time
self.chksum = 0 # header checksum
self.type = REGTYPE # member type
self.linkname = "" # link name
self.uname = "" # user name
self.gname = "" # group name
self.devmajor = 0 # device major number
self.devminor = 0 # device minor number
self.offset = 0 # the tar header starts here
self.offset_data = 0 # the file's data starts here
self.sparse = None # sparse member information
self.pax_headers = {} # pax header information
# In pax headers the "name" and "linkname" field are called
# "path" and "linkpath".
def _getpath(self):
return self.name
def _setpath(self, name):
self.name = name
path = property(_getpath, _setpath)
def _getlinkpath(self):
return self.linkname
def _setlinkpath(self, linkname):
self.linkname = linkname
linkpath = property(_getlinkpath, _setlinkpath)
def __repr__(self):
return "<%s %r at %#x>" % (self.__class__.__name__,self.name,id(self))
def get_info(self):
"""Return the TarInfo's attributes as a dictionary.
"""
info = {
"name": self.name,
"mode": self.mode & 0o7777,
"uid": self.uid,
"gid": self.gid,
"size": self.size,
"mtime": self.mtime,
"chksum": self.chksum,
"type": self.type,
"linkname": self.linkname,
"uname": self.uname,
"gname": self.gname,
"devmajor": self.devmajor,
"devminor": self.devminor
}
if info["type"] == DIRTYPE and not info["name"].endswith("/"):
info["name"] += "/"
return info
def tobuf(self, format=DEFAULT_FORMAT, encoding=ENCODING, errors="surrogateescape"):
"""Return a tar header as a string of 512 byte blocks.
"""
info = self.get_info()
if format == USTAR_FORMAT:
return self.create_ustar_header(info, encoding, errors)
elif format == GNU_FORMAT:
return self.create_gnu_header(info, encoding, errors)
elif format == PAX_FORMAT:
return self.create_pax_header(info, encoding)
else:
raise ValueError("invalid format")
def create_ustar_header(self, info, encoding, errors):
"""Return the object as a ustar header block.
"""
info["magic"] = POSIX_MAGIC
if len(info["linkname"]) > LENGTH_LINK:
raise ValueError("linkname is too long")
if len(info["name"]) > LENGTH_NAME:
info["prefix"], info["name"] = self._posix_split_name(info["name"])
return self._create_header(info, USTAR_FORMAT, encoding, errors)
def create_gnu_header(self, info, encoding, errors):
"""Return the object as a GNU header block sequence.
"""
info["magic"] = GNU_MAGIC
buf = b""
if len(info["linkname"]) > LENGTH_LINK:
buf += self._create_gnu_long_header(info["linkname"], GNUTYPE_LONGLINK, encoding, errors)
if len(info["name"]) > LENGTH_NAME:
buf += self._create_gnu_long_header(info["name"], GNUTYPE_LONGNAME, encoding, errors)
return buf + self._create_header(info, GNU_FORMAT, encoding, errors)
def create_pax_header(self, info, encoding):
"""Return the object as a ustar header block. If it cannot be
represented this way, prepend a pax extended header sequence
with supplement information.
"""
info["magic"] = POSIX_MAGIC
pax_headers = self.pax_headers.copy()
# Test string fields for values that exceed the field length or cannot
# be represented in ASCII encoding.
for name, hname, length in (
("name", "path", LENGTH_NAME), ("linkname", "linkpath", LENGTH_LINK),
("uname", "uname", 32), ("gname", "gname", 32)):
if hname in pax_headers:
# The pax header has priority.
continue
# Try to encode the string as ASCII.
try:
info[name].encode("ascii", "strict")
except UnicodeEncodeError:
pax_headers[hname] = info[name]
continue
if len(info[name]) > length:
pax_headers[hname] = info[name]
# Test number fields for values that exceed the field limit or values
# that like to be stored as float.
for name, digits in (("uid", 8), ("gid", 8), ("size", 12), ("mtime", 12)):
if name in pax_headers:
# The pax header has priority. Avoid overflow.
info[name] = 0
continue
val = info[name]
if not 0 <= val < 8 ** (digits - 1) or isinstance(val, float):
pax_headers[name] = str(val)
info[name] = 0
# Create a pax extended header if necessary.
if pax_headers:
buf = self._create_pax_generic_header(pax_headers, XHDTYPE, encoding)
else:
buf = b""
return buf + self._create_header(info, USTAR_FORMAT, "ascii", "replace")
@classmethod
def create_pax_global_header(cls, pax_headers):
"""Return the object as a pax global header block sequence.
"""
return cls._create_pax_generic_header(pax_headers, XGLTYPE, "utf-8")
def _posix_split_name(self, name):
"""Split a name longer than 100 chars into a prefix
and a name part.
"""
prefix = name[:LENGTH_PREFIX + 1]
while prefix and prefix[-1] != "/":
prefix = prefix[:-1]
name = name[len(prefix):]
prefix = prefix[:-1]
if not prefix or len(name) > LENGTH_NAME:
raise ValueError("name is too long")
return prefix, name
@staticmethod
def _create_header(info, format, encoding, errors):
"""Return a header block. info is a dictionary with file
information, format must be one of the *_FORMAT constants.
"""
parts = [
stn(info.get("name", ""), 100, encoding, errors),
itn(info.get("mode", 0) & 0o7777, 8, format),
itn(info.get("uid", 0), 8, format),
itn(info.get("gid", 0), 8, format),
itn(info.get("size", 0), 12, format),
itn(info.get("mtime", 0), 12, format),
b" ", # checksum field
info.get("type", REGTYPE),
stn(info.get("linkname", ""), 100, encoding, errors),
info.get("magic", POSIX_MAGIC),
stn(info.get("uname", ""), 32, encoding, errors),
stn(info.get("gname", ""), 32, encoding, errors),
itn(info.get("devmajor", 0), 8, format),
itn(info.get("devminor", 0), 8, format),
stn(info.get("prefix", ""), 155, encoding, errors)
]
buf = struct.pack("%ds" % BLOCKSIZE, b"".join(parts))
chksum = calc_chksums(buf[-BLOCKSIZE:])[0]
buf = buf[:-364] + bytes("%06o\0" % chksum, "ascii") + buf[-357:]
return buf
@staticmethod
def _create_payload(payload):
"""Return the string payload filled with zero bytes
up to the next 512 byte border.
"""
blocks, remainder = divmod(len(payload), BLOCKSIZE)
if remainder > 0:
payload += (BLOCKSIZE - remainder) * NUL
return payload
@classmethod
def _create_gnu_long_header(cls, name, type, encoding, errors):
"""Return a GNUTYPE_LONGNAME or GNUTYPE_LONGLINK sequence
for name.
"""
name = name.encode(encoding, errors) + NUL
info = {}
info["name"] = "././@LongLink"
info["type"] = type
info["size"] = len(name)
info["magic"] = GNU_MAGIC
# create extended header + name blocks.
return cls._create_header(info, USTAR_FORMAT, encoding, errors) + \
cls._create_payload(name)
@classmethod
def _create_pax_generic_header(cls, pax_headers, type, encoding):
"""Return a POSIX.1-2008 extended or global header sequence
that contains a list of keyword, value pairs. The values
must be strings.
"""
# Check if one of the fields contains surrogate characters and thereby
# forces hdrcharset=BINARY, see _proc_pax() for more information.
binary = False
for keyword, value in pax_headers.items():
try:
value.encode("utf-8", "strict")
except UnicodeEncodeError:
binary = True
break
records = b""
if binary:
# Put the hdrcharset field at the beginning of the header.
records += b"21 hdrcharset=BINARY\n"
for keyword, value in pax_headers.items():
keyword = keyword.encode("utf-8")
if binary:
# Try to restore the original byte representation of `value'.
# Needless to say, that the encoding must match the string.
value = value.encode(encoding, "surrogateescape")
else:
value = value.encode("utf-8")
l = len(keyword) + len(value) + 3 # ' ' + '=' + '\n'
n = p = 0
while True:
n = l + len(str(p))
if n == p:
break
p = n
records += bytes(str(p), "ascii") + b" " + keyword + b"=" + value + b"\n"
# We use a hardcoded "././@PaxHeader" name like star does
# instead of the one that POSIX recommends.
info = {}
info["name"] = "././@PaxHeader"
info["type"] = type
info["size"] = len(records)
info["magic"] = POSIX_MAGIC
# Create pax header + record blocks.
return cls._create_header(info, USTAR_FORMAT, "ascii", "replace") + \
cls._create_payload(records)
@classmethod
def frombuf(cls, buf, encoding, errors):
"""Construct a TarInfo object from a 512 byte bytes object.
"""
if len(buf) == 0:
raise EmptyHeaderError("empty header")
if len(buf) != BLOCKSIZE:
raise TruncatedHeaderError("truncated header")
if buf.count(NUL) == BLOCKSIZE:
raise EOFHeaderError("end of file header")
chksum = nti(buf[148:156])
if chksum not in calc_chksums(buf):
raise InvalidHeaderError("bad checksum")
obj = cls()
obj.name = nts(buf[0:100], encoding, errors)
obj.mode = nti(buf[100:108])
obj.uid = nti(buf[108:116])
obj.gid = nti(buf[116:124])
obj.size = nti(buf[124:136])
obj.mtime = nti(buf[136:148])
obj.chksum = chksum
obj.type = buf[156:157]
obj.linkname = nts(buf[157:257], encoding, errors)
obj.uname = nts(buf[265:297], encoding, errors)
obj.gname = nts(buf[297:329], encoding, errors)
obj.devmajor = nti(buf[329:337])
obj.devminor = nti(buf[337:345])
prefix = nts(buf[345:500], encoding, errors)
# Old V7 tar format represents a directory as a regular
# file with a trailing slash.
if obj.type == AREGTYPE and obj.name.endswith("/"):
obj.type = DIRTYPE
# The old GNU sparse format occupies some of the unused
# space in the buffer for up to 4 sparse structures.
# Save the them for later processing in _proc_sparse().
if obj.type == GNUTYPE_SPARSE:
pos = 386
structs = []
for i in range(4):
try:
offset = nti(buf[pos:pos + 12])
numbytes = nti(buf[pos + 12:pos + 24])
except ValueError:
break
structs.append((offset, numbytes))
pos += 24
isextended = bool(buf[482])
origsize = nti(buf[483:495])
obj._sparse_structs = (structs, isextended, origsize)
# Remove redundant slashes from directories.
if obj.isdir():
obj.name = obj.name.rstrip("/")
# Reconstruct a ustar longname.
if prefix and obj.type not in GNU_TYPES:
obj.name = prefix + "/" + obj.name
return obj
@classmethod
def fromtarfile(cls, tarfile):
"""Return the next TarInfo object from TarFile object
tarfile.
"""
buf = tarfile.fileobj.read(BLOCKSIZE)
obj = cls.frombuf(buf, tarfile.encoding, tarfile.errors)
obj.offset = tarfile.fileobj.tell() - BLOCKSIZE
return obj._proc_member(tarfile)
#--------------------------------------------------------------------------
# The following are methods that are called depending on the type of a
# member. The entry point is _proc_member() which can be overridden in a
# subclass to add custom _proc_*() methods. A _proc_*() method MUST
# implement the following
# operations:
# 1. Set self.offset_data to the position where the data blocks begin,
# if there is data that follows.
# 2. Set tarfile.offset to the position where the next member's header will
# begin.
# 3. Return self or another valid TarInfo object.
def _proc_member(self, tarfile):
"""Choose the right processing method depending on
the type and call it.
"""
if self.type in (GNUTYPE_LONGNAME, GNUTYPE_LONGLINK):
return self._proc_gnulong(tarfile)
elif self.type == GNUTYPE_SPARSE:
return self._proc_sparse(tarfile)
elif self.type in (XHDTYPE, XGLTYPE, SOLARIS_XHDTYPE):
return self._proc_pax(tarfile)
else:
return self._proc_builtin(tarfile)
def _proc_builtin(self, tarfile):
"""Process a builtin type or an unknown type which
will be treated as a regular file.
"""
self.offset_data = tarfile.fileobj.tell()
offset = self.offset_data
if self.isreg() or self.type not in SUPPORTED_TYPES:
# Skip the following data blocks.
offset += self._block(self.size)
tarfile.offset = offset
# Patch the TarInfo object with saved global
# header information.
self._apply_pax_info(tarfile.pax_headers, tarfile.encoding, tarfile.errors)
return self
def _proc_gnulong(self, tarfile):
"""Process the blocks that hold a GNU longname
or longlink member.
"""
buf = tarfile.fileobj.read(self._block(self.size))
# Fetch the next header and process it.
try:
next = self.fromtarfile(tarfile)
except HeaderError:
raise SubsequentHeaderError("missing or bad subsequent header")
# Patch the TarInfo object from the next header with
# the longname information.
next.offset = self.offset
if self.type == GNUTYPE_LONGNAME:
next.name = nts(buf, tarfile.encoding, tarfile.errors)
elif self.type == GNUTYPE_LONGLINK:
next.linkname = nts(buf, tarfile.encoding, tarfile.errors)
return next
def _proc_sparse(self, tarfile):
"""Process a GNU sparse header plus extra headers.
"""
# We already collected some sparse structures in frombuf().
structs, isextended, origsize = self._sparse_structs
del self._sparse_structs
# Collect sparse structures from extended header blocks.
while isextended:
buf = tarfile.fileobj.read(BLOCKSIZE)
pos = 0
for i in range(21):
try:
offset = nti(buf[pos:pos + 12])
numbytes = nti(buf[pos + 12:pos + 24])
except ValueError:
break
if offset and numbytes:
structs.append((offset, numbytes))
pos += 24
isextended = bool(buf[504])
self.sparse = structs
self.offset_data = tarfile.fileobj.tell()
tarfile.offset = self.offset_data + self._block(self.size)
self.size = origsize
return self
def _proc_pax(self, tarfile):
"""Process an extended or global header as described in
POSIX.1-2008.
"""
# Read the header information.
buf = tarfile.fileobj.read(self._block(self.size))
# A pax header stores supplemental information for either
# the following file (extended) or all following files
# (global).
if self.type == XGLTYPE:
pax_headers = tarfile.pax_headers
else:
pax_headers = tarfile.pax_headers.copy()
# Check if the pax header contains a hdrcharset field. This tells us
# the encoding of the path, linkpath, uname and gname fields. Normally,
# these fields are UTF-8 encoded but since POSIX.1-2008 tar
# implementations are allowed to store them as raw binary strings if
# the translation to UTF-8 fails.
match = re.search(br"\d+ hdrcharset=([^\n]+)\n", buf)
if match is not None:
pax_headers["hdrcharset"] = match.group(1).decode("utf-8")
# For the time being, we don't care about anything other than "BINARY".
# The only other value that is currently allowed by the standard is
# "ISO-IR 10646 2000 UTF-8" in other words UTF-8.
hdrcharset = pax_headers.get("hdrcharset")
if hdrcharset == "BINARY":
encoding = tarfile.encoding
else:
encoding = "utf-8"
# Parse pax header information. A record looks like that:
# "%d %s=%s\n" % (length, keyword, value). length is the size
# of the complete record including the length field itself and
# the newline. keyword and value are both UTF-8 encoded strings.
regex = re.compile(br"(\d+) ([^=]+)=")
pos = 0
while True:
match = regex.match(buf, pos)
if not match:
break
length, keyword = match.groups()
length = int(length)
value = buf[match.end(2) + 1:match.start(1) + length - 1]
# Normally, we could just use "utf-8" as the encoding and "strict"
# as the error handler, but we better not take the risk. For
# example, GNU tar <= 1.23 is known to store filenames it cannot
# translate to UTF-8 as raw strings (unfortunately without a
# hdrcharset=BINARY header).
# We first try the strict standard encoding, and if that fails we
# fall back on the user's encoding and error handler.
keyword = self._decode_pax_field(keyword, "utf-8", "utf-8",
tarfile.errors)
if keyword in PAX_NAME_FIELDS:
value = self._decode_pax_field(value, encoding, tarfile.encoding,
tarfile.errors)
else:
value = self._decode_pax_field(value, "utf-8", "utf-8",
tarfile.errors)
pax_headers[keyword] = value
pos += length
# Fetch the next header.
try:
next = self.fromtarfile(tarfile)
except HeaderError:
raise SubsequentHeaderError("missing or bad subsequent header")
# Process GNU sparse information.
if "GNU.sparse.map" in pax_headers:
# GNU extended sparse format version 0.1.
self._proc_gnusparse_01(next, pax_headers)
elif "GNU.sparse.size" in pax_headers:
# GNU extended sparse format version 0.0.
self._proc_gnusparse_00(next, pax_headers, buf)
elif pax_headers.get("GNU.sparse.major") == "1" and pax_headers.get("GNU.sparse.minor") == "0":
# GNU extended sparse format version 1.0.
self._proc_gnusparse_10(next, pax_headers, tarfile)
if self.type in (XHDTYPE, SOLARIS_XHDTYPE):
# Patch the TarInfo object with the extended header info.
next._apply_pax_info(pax_headers, tarfile.encoding, tarfile.errors)
next.offset = self.offset
if "size" in pax_headers:
# If the extended header replaces the size field,
# we need to recalculate the offset where the next
# header starts.
offset = next.offset_data
if next.isreg() or next.type not in SUPPORTED_TYPES:
offset += next._block(next.size)
tarfile.offset = offset
return next
def _proc_gnusparse_00(self, next, pax_headers, buf):
"""Process a GNU tar extended sparse header, version 0.0.
"""
offsets = []
for match in re.finditer(br"\d+ GNU.sparse.offset=(\d+)\n", buf):
offsets.append(int(match.group(1)))
numbytes = []
for match in re.finditer(br"\d+ GNU.sparse.numbytes=(\d+)\n", buf):
numbytes.append(int(match.group(1)))
next.sparse = list(zip(offsets, numbytes))
def _proc_gnusparse_01(self, next, pax_headers):
"""Process a GNU tar extended sparse header, version 0.1.
"""
sparse = [int(x) for x in pax_headers["GNU.sparse.map"].split(",")]
next.sparse = list(zip(sparse[::2], sparse[1::2]))
def _proc_gnusparse_10(self, next, pax_headers, tarfile):
"""Process a GNU tar extended sparse header, version 1.0.
"""
fields = None
sparse = []
buf = tarfile.fileobj.read(BLOCKSIZE)
fields, buf = buf.split(b"\n", 1)
fields = int(fields)
while len(sparse) < fields * 2:
if b"\n" not in buf:
buf += tarfile.fileobj.read(BLOCKSIZE)
number, buf = buf.split(b"\n", 1)
sparse.append(int(number))
next.offset_data = tarfile.fileobj.tell()
next.sparse = list(zip(sparse[::2], sparse[1::2]))
def _apply_pax_info(self, pax_headers, encoding, errors):
"""Replace fields with supplemental information from a previous
pax extended or global header.
"""
for keyword, value in pax_headers.items():
if keyword == "GNU.sparse.name":
setattr(self, "path", value)
elif keyword == "GNU.sparse.size":
setattr(self, "size", int(value))
elif keyword == "GNU.sparse.realsize":
setattr(self, "size", int(value))
elif keyword in PAX_FIELDS:
if keyword in PAX_NUMBER_FIELDS:
try:
value = PAX_NUMBER_FIELDS[keyword](value)
except ValueError:
value = 0
if keyword == "path":
value = value.rstrip("/")
setattr(self, keyword, value)
self.pax_headers = pax_headers.copy()
def _decode_pax_field(self, value, encoding, fallback_encoding, fallback_errors):
"""Decode a single field from a pax record.
"""
try:
return value.decode(encoding, "strict")
except UnicodeDecodeError:
return value.decode(fallback_encoding, fallback_errors)
def _block(self, count):
"""Round up a byte count by BLOCKSIZE and return it,
e.g. _block(834) => 1024.
"""
blocks, remainder = divmod(count, BLOCKSIZE)
if remainder:
blocks += 1
return blocks * BLOCKSIZE
def isreg(self):
return self.type in REGULAR_TYPES
def isfile(self):
return self.isreg()
def isdir(self):
return self.type == DIRTYPE
def issym(self):
return self.type == SYMTYPE
def islnk(self):
return self.type == LNKTYPE
def ischr(self):
return self.type == CHRTYPE
def isblk(self):
return self.type == BLKTYPE
def isfifo(self):
return self.type == FIFOTYPE
def issparse(self):
return self.sparse is not None
def isdev(self):
return self.type in (CHRTYPE, BLKTYPE, FIFOTYPE)
# class TarInfo
class TarFile(object):
"""The TarFile Class provides an interface to tar archives.
"""
debug = 0 # May be set from 0 (no msgs) to 3 (all msgs)
dereference = False # If true, add content of linked file to the
# tar file, else the link.
ignore_zeros = False # If true, skips empty or invalid blocks and
# continues processing.
errorlevel = 1 # If 0, fatal errors only appear in debug
# messages (if debug >= 0). If > 0, errors
# are passed to the caller as exceptions.
format = DEFAULT_FORMAT # The format to use when creating an archive.
encoding = ENCODING # Encoding for 8-bit character strings.
errors = None # Error handler for unicode conversion.
tarinfo = TarInfo # The default TarInfo class to use.
fileobject = ExFileObject # The file-object for extractfile().
def __init__(self, name=None, mode="r", fileobj=None, format=None,
tarinfo=None, dereference=None, ignore_zeros=None, encoding=None,
errors="surrogateescape", pax_headers=None, debug=None, errorlevel=None):
"""Open an (uncompressed) tar archive `name'. `mode' is either 'r' to
read from an existing archive, 'a' to append data to an existing
file or 'w' to create a new file overwriting an existing one. `mode'
defaults to 'r'.
If `fileobj' is given, it is used for reading or writing data. If it
can be determined, `mode' is overridden by `fileobj's mode.
`fileobj' is not closed, when TarFile is closed.
"""
if len(mode) > 1 or mode not in "raw":
raise ValueError("mode must be 'r', 'a' or 'w'")
self.mode = mode
self._mode = {"r": "rb", "a": "r+b", "w": "wb"}[mode]
if not fileobj:
if self.mode == "a" and not os.path.exists(name):
# Create nonexistent files in append mode.
self.mode = "w"
self._mode = "wb"
fileobj = bltn_open(name, self._mode)
self._extfileobj = False
else:
if name is None and hasattr(fileobj, "name"):
name = fileobj.name
if hasattr(fileobj, "mode"):
self._mode = fileobj.mode
self._extfileobj = True
self.name = os.path.abspath(name) if name else None
self.fileobj = fileobj
# Init attributes.
if format is not None:
self.format = format
if tarinfo is not None:
self.tarinfo = tarinfo
if dereference is not None:
self.dereference = dereference
if ignore_zeros is not None:
self.ignore_zeros = ignore_zeros
if encoding is not None:
self.encoding = encoding
self.errors = errors
if pax_headers is not None and self.format == PAX_FORMAT:
self.pax_headers = pax_headers
else:
self.pax_headers = {}
if debug is not None:
self.debug = debug
if errorlevel is not None:
self.errorlevel = errorlevel
# Init datastructures.
self.closed = False
self.members = [] # list of members as TarInfo objects
self._loaded = False # flag if all members have been read
self.offset = self.fileobj.tell()
# current position in the archive file
self.inodes = {} # dictionary caching the inodes of
# archive members already added
try:
if self.mode == "r":
self.firstmember = None
self.firstmember = self.next()
if self.mode == "a":
# Move to the end of the archive,
# before the first empty block.
while True:
self.fileobj.seek(self.offset)
try:
tarinfo = self.tarinfo.fromtarfile(self)
self.members.append(tarinfo)
except EOFHeaderError:
self.fileobj.seek(self.offset)
break
except HeaderError as e:
raise ReadError(str(e))
if self.mode in "aw":
self._loaded = True
if self.pax_headers:
buf = self.tarinfo.create_pax_global_header(self.pax_headers.copy())
self.fileobj.write(buf)
self.offset += len(buf)
except:
if not self._extfileobj:
self.fileobj.close()
self.closed = True
raise
#--------------------------------------------------------------------------
# Below are the classmethods which act as alternate constructors to the
# TarFile class. The open() method is the only one that is needed for
# public use; it is the "super"-constructor and is able to select an
# adequate "sub"-constructor for a particular compression using the mapping
# from OPEN_METH.
#
# This concept allows one to subclass TarFile without losing the comfort of
# the super-constructor. A sub-constructor is registered and made available
# by adding it to the mapping in OPEN_METH.
@classmethod
def open(cls, name=None, mode="r", fileobj=None, bufsize=RECORDSIZE, **kwargs):
"""Open a tar archive for reading, writing or appending. Return
an appropriate TarFile class.
mode:
'r' or 'r:*' open for reading with transparent compression
'r:' open for reading exclusively uncompressed
'r:gz' open for reading with gzip compression
'r:bz2' open for reading with bzip2 compression
'r:xz' open for reading with lzma compression
'a' or 'a:' open for appending, creating the file if necessary
'w' or 'w:' open for writing without compression
'w:gz' open for writing with gzip compression
'w:bz2' open for writing with bzip2 compression
'w:xz' open for writing with lzma compression
'r|*' open a stream of tar blocks with transparent compression
'r|' open an uncompressed stream of tar blocks for reading
'r|gz' open a gzip compressed stream of tar blocks
'r|bz2' open a bzip2 compressed stream of tar blocks
'r|xz' open an lzma compressed stream of tar blocks
'w|' open an uncompressed stream for writing
'w|gz' open a gzip compressed stream for writing
'w|bz2' open a bzip2 compressed stream for writing
'w|xz' open an lzma compressed stream for writing
"""
if not name and not fileobj:
raise ValueError("nothing to open")
if mode in ("r", "r:*"):
# Find out which *open() is appropriate for opening the file.
for comptype in cls.OPEN_METH:
func = getattr(cls, cls.OPEN_METH[comptype])
if fileobj is not None:
saved_pos = fileobj.tell()
try:
return func(name, "r", fileobj, **kwargs)
except (ReadError, CompressionError) as e:
if fileobj is not None:
fileobj.seek(saved_pos)
continue
raise ReadError("file could not be opened successfully")
elif ":" in mode:
filemode, comptype = mode.split(":", 1)
filemode = filemode or "r"
comptype = comptype or "tar"
# Select the *open() function according to
# given compression.
if comptype in cls.OPEN_METH:
func = getattr(cls, cls.OPEN_METH[comptype])
else:
raise CompressionError("unknown compression type %r" % comptype)
return func(name, filemode, fileobj, **kwargs)
elif "|" in mode:
filemode, comptype = mode.split("|", 1)
filemode = filemode or "r"
comptype = comptype or "tar"
if filemode not in "rw":
raise ValueError("mode must be 'r' or 'w'")
stream = _Stream(name, filemode, comptype, fileobj, bufsize)
try:
t = cls(name, filemode, stream, **kwargs)
except:
stream.close()
raise
t._extfileobj = False
return t
elif mode in "aw":
return cls.taropen(name, mode, fileobj, **kwargs)
raise ValueError("undiscernible mode")
@classmethod
def taropen(cls, name, mode="r", fileobj=None, **kwargs):
"""Open uncompressed tar archive name for reading or writing.
"""
if len(mode) > 1 or mode not in "raw":
raise ValueError("mode must be 'r', 'a' or 'w'")
return cls(name, mode, fileobj, **kwargs)
@classmethod
def gzopen(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs):
"""Open gzip compressed tar archive name for reading or writing.
Appending is not allowed.
"""
if len(mode) > 1 or mode not in "rw":
raise ValueError("mode must be 'r' or 'w'")
try:
import gzip
gzip.GzipFile
except (ImportError, AttributeError):
raise CompressionError("gzip module is not available")
extfileobj = fileobj is not None
try:
fileobj = gzip.GzipFile(name, mode + "b", compresslevel, fileobj)
t = cls.taropen(name, mode, fileobj, **kwargs)
except IOError:
if not extfileobj and fileobj is not None:
fileobj.close()
if fileobj is None:
raise
raise ReadError("not a gzip file")
except:
if not extfileobj and fileobj is not None:
fileobj.close()
raise
t._extfileobj = extfileobj
return t
@classmethod
def bz2open(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs):
"""Open bzip2 compressed tar archive name for reading or writing.
Appending is not allowed.
"""
if len(mode) > 1 or mode not in "rw":
raise ValueError("mode must be 'r' or 'w'.")
try:
import bz2
except ImportError:
raise CompressionError("bz2 module is not available")
fileobj = bz2.BZ2File(fileobj or name, mode,
compresslevel=compresslevel)
try:
t = cls.taropen(name, mode, fileobj, **kwargs)
except (IOError, EOFError):
fileobj.close()
raise ReadError("not a bzip2 file")
t._extfileobj = False
return t
@classmethod
def xzopen(cls, name, mode="r", fileobj=None, preset=None, **kwargs):
"""Open lzma compressed tar archive name for reading or writing.
Appending is not allowed.
"""
if mode not in ("r", "w"):
raise ValueError("mode must be 'r' or 'w'")
try:
import lzma
except ImportError:
raise CompressionError("lzma module is not available")
fileobj = lzma.LZMAFile(fileobj or name, mode, preset=preset)
try:
t = cls.taropen(name, mode, fileobj, **kwargs)
except (lzma.LZMAError, EOFError):
fileobj.close()
raise ReadError("not an lzma file")
t._extfileobj = False
return t
# All *open() methods are registered here.
OPEN_METH = {
"tar": "taropen", # uncompressed tar
"gz": "gzopen", # gzip compressed tar
"bz2": "bz2open", # bzip2 compressed tar
"xz": "xzopen" # lzma compressed tar
}
#--------------------------------------------------------------------------
# The public methods which TarFile provides:
def close(self):
"""Close the TarFile. In write-mode, two finishing zero blocks are
appended to the archive.
"""
if self.closed:
return
if self.mode in "aw":
self.fileobj.write(NUL * (BLOCKSIZE * 2))
self.offset += (BLOCKSIZE * 2)
# fill up the end with zero-blocks
# (like option -b20 for tar does)
blocks, remainder = divmod(self.offset, RECORDSIZE)
if remainder > 0:
self.fileobj.write(NUL * (RECORDSIZE - remainder))
if not self._extfileobj:
self.fileobj.close()
self.closed = True
def getmember(self, name):
"""Return a TarInfo object for member `name'. If `name' can not be
found in the archive, KeyError is raised. If a member occurs more
than once in the archive, its last occurrence is assumed to be the
most up-to-date version.
"""
tarinfo = self._getmember(name)
if tarinfo is None:
raise KeyError("filename %r not found" % name)
return tarinfo
def getmembers(self):
"""Return the members of the archive as a list of TarInfo objects. The
list has the same order as the members in the archive.
"""
self._check()
if not self._loaded: # if we want to obtain a list of
self._load() # all members, we first have to
# scan the whole archive.
return self.members
def getnames(self):
"""Return the members of the archive as a list of their names. It has
the same order as the list returned by getmembers().
"""
return [tarinfo.name for tarinfo in self.getmembers()]
def gettarinfo(self, name=None, arcname=None, fileobj=None):
"""Create a TarInfo object for either the file `name' or the file
object `fileobj' (using os.fstat on its file descriptor). You can
modify some of the TarInfo's attributes before you add it using
addfile(). If given, `arcname' specifies an alternative name for the
file in the archive.
"""
self._check("aw")
# When fileobj is given, replace name by
# fileobj's real name.
if fileobj is not None:
name = fileobj.name
# Building the name of the member in the archive.
# Backward slashes are converted to forward slashes,
# Absolute paths are turned to relative paths.
if arcname is None:
arcname = name
drv, arcname = os.path.splitdrive(arcname)
arcname = arcname.replace(os.sep, "/")
arcname = arcname.lstrip("/")
# Now, fill the TarInfo object with
# information specific for the file.
tarinfo = self.tarinfo()
tarinfo.tarfile = self
# Use os.stat or os.lstat, depending on platform
# and if symlinks shall be resolved.
if fileobj is None:
if hasattr(os, "lstat") and not self.dereference:
statres = os.lstat(name)
else:
statres = os.stat(name)
else:
statres = os.fstat(fileobj.fileno())
linkname = ""
stmd = statres.st_mode
if stat.S_ISREG(stmd):
inode = (statres.st_ino, statres.st_dev)
if not self.dereference and statres.st_nlink > 1 and \
inode in self.inodes and arcname != self.inodes[inode]:
# Is it a hardlink to an already
# archived file?
type = LNKTYPE
linkname = self.inodes[inode]
else:
# The inode is added only if its valid.
# For win32 it is always 0.
type = REGTYPE
if inode[0]:
self.inodes[inode] = arcname
elif stat.S_ISDIR(stmd):
type = DIRTYPE
elif stat.S_ISFIFO(stmd):
type = FIFOTYPE
elif stat.S_ISLNK(stmd):
type = SYMTYPE
linkname = os.readlink(name)
elif stat.S_ISCHR(stmd):
type = CHRTYPE
elif stat.S_ISBLK(stmd):
type = BLKTYPE
else:
return None
# Fill the TarInfo object with all
# information we can get.
tarinfo.name = arcname
tarinfo.mode = stmd
tarinfo.uid = statres.st_uid
tarinfo.gid = statres.st_gid
if type == REGTYPE:
tarinfo.size = statres.st_size
else:
tarinfo.size = 0
tarinfo.mtime = statres.st_mtime
tarinfo.type = type
tarinfo.linkname = linkname
if pwd:
try:
tarinfo.uname = pwd.getpwuid(tarinfo.uid)[0]
except KeyError:
pass
if grp:
try:
tarinfo.gname = grp.getgrgid(tarinfo.gid)[0]
except KeyError:
pass
if type in (CHRTYPE, BLKTYPE):
if hasattr(os, "major") and hasattr(os, "minor"):
tarinfo.devmajor = os.major(statres.st_rdev)
tarinfo.devminor = os.minor(statres.st_rdev)
return tarinfo
def list(self, verbose=True):
"""Print a table of contents to sys.stdout. If `verbose' is False, only
the names of the members are printed. If it is True, an `ls -l'-like
output is produced.
"""
self._check()
for tarinfo in self:
if verbose:
print(stat.filemode(tarinfo.mode), end=' ')
print("%s/%s" % (tarinfo.uname or tarinfo.uid,
tarinfo.gname or tarinfo.gid), end=' ')
if tarinfo.ischr() or tarinfo.isblk():
print("%10s" % ("%d,%d" \
% (tarinfo.devmajor, tarinfo.devminor)), end=' ')
else:
print("%10d" % tarinfo.size, end=' ')
print("%d-%02d-%02d %02d:%02d:%02d" \
% time.localtime(tarinfo.mtime)[:6], end=' ')
print(tarinfo.name + ("/" if tarinfo.isdir() else ""), end=' ')
if verbose:
if tarinfo.issym():
print("->", tarinfo.linkname, end=' ')
if tarinfo.islnk():
print("link to", tarinfo.linkname, end=' ')
print()
def add(self, name, arcname=None, recursive=True, exclude=None, *, filter=None):
"""Add the file `name' to the archive. `name' may be any type of file
(directory, fifo, symbolic link, etc.). If given, `arcname'
specifies an alternative name for the file in the archive.
Directories are added recursively by default. This can be avoided by
setting `recursive' to False. `exclude' is a function that should
return True for each filename to be excluded. `filter' is a function
that expects a TarInfo object argument and returns the changed
TarInfo object, if it returns None the TarInfo object will be
excluded from the archive.
"""
self._check("aw")
if arcname is None:
arcname = name
# Exclude pathnames.
if exclude is not None:
import warnings
warnings.warn("use the filter argument instead",
DeprecationWarning, 2)
if exclude(name):
self._dbg(2, "tarfile: Excluded %r" % name)
return
# Skip if somebody tries to archive the archive...
if self.name is not None and os.path.abspath(name) == self.name:
self._dbg(2, "tarfile: Skipped %r" % name)
return
self._dbg(1, name)
# Create a TarInfo object from the file.
tarinfo = self.gettarinfo(name, arcname)
if tarinfo is None:
self._dbg(1, "tarfile: Unsupported type %r" % name)
return
# Change or exclude the TarInfo object.
if filter is not None:
tarinfo = filter(tarinfo)
if tarinfo is None:
self._dbg(2, "tarfile: Excluded %r" % name)
return
# Append the tar header and data to the archive.
if tarinfo.isreg():
with bltn_open(name, "rb") as f:
self.addfile(tarinfo, f)
elif tarinfo.isdir():
self.addfile(tarinfo)
if recursive:
for f in os.listdir(name):
self.add(os.path.join(name, f), os.path.join(arcname, f),
recursive, exclude, filter=filter)
else:
self.addfile(tarinfo)
def addfile(self, tarinfo, fileobj=None):
"""Add the TarInfo object `tarinfo' to the archive. If `fileobj' is
given, tarinfo.size bytes are read from it and added to the archive.
You can create TarInfo objects using gettarinfo().
On Windows platforms, `fileobj' should always be opened with mode
'rb' to avoid irritation about the file size.
"""
self._check("aw")
tarinfo = copy.copy(tarinfo)
buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
self.fileobj.write(buf)
self.offset += len(buf)
# If there's data to follow, append it.
if fileobj is not None:
copyfileobj(fileobj, self.fileobj, tarinfo.size)
blocks, remainder = divmod(tarinfo.size, BLOCKSIZE)
if remainder > 0:
self.fileobj.write(NUL * (BLOCKSIZE - remainder))
blocks += 1
self.offset += blocks * BLOCKSIZE
self.members.append(tarinfo)
def extractall(self, path=".", members=None):
"""Extract all members from the archive to the current working
directory and set owner, modification time and permissions on
directories afterwards. `path' specifies a different directory
to extract to. `members' is optional and must be a subset of the
list returned by getmembers().
"""
directories = []
if members is None:
members = self
for tarinfo in members:
if tarinfo.isdir():
# Extract directories with a safe mode.
directories.append(tarinfo)
tarinfo = copy.copy(tarinfo)
tarinfo.mode = 0o700
# Do not set_attrs directories, as we will do that further down
self.extract(tarinfo, path, set_attrs=not tarinfo.isdir())
# Reverse sort directories.
directories.sort(key=lambda a: a.name)
directories.reverse()
# Set correct owner, mtime and filemode on directories.
for tarinfo in directories:
dirpath = os.path.join(path, tarinfo.name)
try:
self.chown(tarinfo, dirpath)
self.utime(tarinfo, dirpath)
self.chmod(tarinfo, dirpath)
except ExtractError as e:
if self.errorlevel > 1:
raise
else:
self._dbg(1, "tarfile: %s" % e)
def extract(self, member, path="", set_attrs=True):
"""Extract a member from the archive to the current working directory,
using its full name. Its file information is extracted as accurately
as possible. `member' may be a filename or a TarInfo object. You can
specify a different directory using `path'. File attributes (owner,
mtime, mode) are set unless `set_attrs' is False.
"""
self._check("r")
if isinstance(member, str):
tarinfo = self.getmember(member)
else:
tarinfo = member
# Prepare the link target for makelink().
if tarinfo.islnk():
tarinfo._link_target = os.path.join(path, tarinfo.linkname)
try:
self._extract_member(tarinfo, os.path.join(path, tarinfo.name),
set_attrs=set_attrs)
except EnvironmentError as e:
if self.errorlevel > 0:
raise
else:
if e.filename is None:
self._dbg(1, "tarfile: %s" % e.strerror)
else:
self._dbg(1, "tarfile: %s %r" % (e.strerror, e.filename))
except ExtractError as e:
if self.errorlevel > 1:
raise
else:
self._dbg(1, "tarfile: %s" % e)
def extractfile(self, member):
"""Extract a member from the archive as a file object. `member' may be
a filename or a TarInfo object. If `member' is a regular file or a
link, an io.BufferedReader object is returned. Otherwise, None is
returned.
"""
self._check("r")
if isinstance(member, str):
tarinfo = self.getmember(member)
else:
tarinfo = member
if tarinfo.isreg() or tarinfo.type not in SUPPORTED_TYPES:
# Members with unknown types are treated as regular files.
return self.fileobject(self, tarinfo)
elif tarinfo.islnk() or tarinfo.issym():
if isinstance(self.fileobj, _Stream):
# A small but ugly workaround for the case that someone tries
# to extract a (sym)link as a file-object from a non-seekable
# stream of tar blocks.
raise StreamError("cannot extract (sym)link as file object")
else:
# A (sym)link's file object is its target's file object.
return self.extractfile(self._find_link_target(tarinfo))
else:
# If there's no data associated with the member (directory, chrdev,
# blkdev, etc.), return None instead of a file object.
return None
def _extract_member(self, tarinfo, targetpath, set_attrs=True):
"""Extract the TarInfo object tarinfo to a physical
file called targetpath.
"""
# Fetch the TarInfo object for the given name
# and build the destination pathname, replacing
# forward slashes to platform specific separators.
targetpath = targetpath.rstrip("/")
targetpath = targetpath.replace("/", os.sep)
# Create all upper directories.
upperdirs = os.path.dirname(targetpath)
if upperdirs and not os.path.exists(upperdirs):
# Create directories that are not part of the archive with
# default permissions.
os.makedirs(upperdirs)
if tarinfo.islnk() or tarinfo.issym():
self._dbg(1, "%s -> %s" % (tarinfo.name, tarinfo.linkname))
else:
self._dbg(1, tarinfo.name)
if tarinfo.isreg():
self.makefile(tarinfo, targetpath)
elif tarinfo.isdir():
self.makedir(tarinfo, targetpath)
elif tarinfo.isfifo():
self.makefifo(tarinfo, targetpath)
elif tarinfo.ischr() or tarinfo.isblk():
self.makedev(tarinfo, targetpath)
elif tarinfo.islnk() or tarinfo.issym():
self.makelink(tarinfo, targetpath)
elif tarinfo.type not in SUPPORTED_TYPES:
self.makeunknown(tarinfo, targetpath)
else:
self.makefile(tarinfo, targetpath)
if set_attrs:
self.chown(tarinfo, targetpath)
if not tarinfo.issym():
self.chmod(tarinfo, targetpath)
self.utime(tarinfo, targetpath)
#--------------------------------------------------------------------------
# Below are the different file methods. They are called via
# _extract_member() when extract() is called. They can be replaced in a
# subclass to implement other functionality.
def makedir(self, tarinfo, targetpath):
"""Make a directory called targetpath.
"""
try:
# Use a safe mode for the directory, the real mode is set
# later in _extract_member().
os.mkdir(targetpath, 0o700)
except FileExistsError:
pass
def makefile(self, tarinfo, targetpath):
"""Make a file called targetpath.
"""
source = self.fileobj
source.seek(tarinfo.offset_data)
with bltn_open(targetpath, "wb") as target:
if tarinfo.sparse is not None:
for offset, size in tarinfo.sparse:
target.seek(offset)
copyfileobj(source, target, size)
else:
copyfileobj(source, target, tarinfo.size)
target.seek(tarinfo.size)
target.truncate()
def makeunknown(self, tarinfo, targetpath):
"""Make a file from a TarInfo object with an unknown type
at targetpath.
"""
self.makefile(tarinfo, targetpath)
self._dbg(1, "tarfile: Unknown file type %r, " \
"extracted as regular file." % tarinfo.type)
def makefifo(self, tarinfo, targetpath):
"""Make a fifo called targetpath.
"""
if hasattr(os, "mkfifo"):
os.mkfifo(targetpath)
else:
raise ExtractError("fifo not supported by system")
def makedev(self, tarinfo, targetpath):
"""Make a character or block device called targetpath.
"""
if not hasattr(os, "mknod") or not hasattr(os, "makedev"):
raise ExtractError("special devices not supported by system")
mode = tarinfo.mode
if tarinfo.isblk():
mode |= stat.S_IFBLK
else:
mode |= stat.S_IFCHR
os.mknod(targetpath, mode,
os.makedev(tarinfo.devmajor, tarinfo.devminor))
def makelink(self, tarinfo, targetpath):
"""Make a (symbolic) link called targetpath. If it cannot be created
(platform limitation), we try to make a copy of the referenced file
instead of a link.
"""
try:
# For systems that support symbolic and hard links.
if tarinfo.issym():
os.symlink(tarinfo.linkname, targetpath)
else:
# See extract().
if os.path.exists(tarinfo._link_target):
os.link(tarinfo._link_target, targetpath)
else:
self._extract_member(self._find_link_target(tarinfo),
targetpath)
except symlink_exception:
try:
self._extract_member(self._find_link_target(tarinfo),
targetpath)
except KeyError:
raise ExtractError("unable to resolve link inside archive")
def chown(self, tarinfo, targetpath):
"""Set owner of targetpath according to tarinfo.
"""
if pwd and hasattr(os, "geteuid") and os.geteuid() == 0:
# We have to be root to do so.
try:
g = grp.getgrnam(tarinfo.gname)[2]
except KeyError:
g = tarinfo.gid
try:
u = pwd.getpwnam(tarinfo.uname)[2]
except KeyError:
u = tarinfo.uid
try:
if tarinfo.issym() and hasattr(os, "lchown"):
os.lchown(targetpath, u, g)
else:
if sys.platform != "os2emx":
os.chown(targetpath, u, g)
except EnvironmentError as e:
raise ExtractError("could not change owner")
def chmod(self, tarinfo, targetpath):
"""Set file permissions of targetpath according to tarinfo.
"""
if hasattr(os, 'chmod'):
try:
os.chmod(targetpath, tarinfo.mode)
except EnvironmentError as e:
raise ExtractError("could not change mode")
def utime(self, tarinfo, targetpath):
"""Set modification time of targetpath according to tarinfo.
"""
if not hasattr(os, 'utime'):
return
try:
os.utime(targetpath, (tarinfo.mtime, tarinfo.mtime))
except EnvironmentError as e:
raise ExtractError("could not change modification time")
#--------------------------------------------------------------------------
def next(self):
"""Return the next member of the archive as a TarInfo object, when
TarFile is opened for reading. Return None if there is no more
available.
"""
self._check("ra")
if self.firstmember is not None:
m = self.firstmember
self.firstmember = None
return m
# Read the next block.
self.fileobj.seek(self.offset)
tarinfo = None
while True:
try:
tarinfo = self.tarinfo.fromtarfile(self)
except EOFHeaderError as e:
if self.ignore_zeros:
self._dbg(2, "0x%X: %s" % (self.offset, e))
self.offset += BLOCKSIZE
continue
except InvalidHeaderError as e:
if self.ignore_zeros:
self._dbg(2, "0x%X: %s" % (self.offset, e))
self.offset += BLOCKSIZE
continue
elif self.offset == 0:
raise ReadError(str(e))
except EmptyHeaderError:
if self.offset == 0:
raise ReadError("empty file")
except TruncatedHeaderError as e:
if self.offset == 0:
raise ReadError(str(e))
except SubsequentHeaderError as e:
raise ReadError(str(e))
break
if tarinfo is not None:
self.members.append(tarinfo)
else:
self._loaded = True
return tarinfo
#--------------------------------------------------------------------------
# Little helper methods:
def _getmember(self, name, tarinfo=None, normalize=False):
"""Find an archive member by name from bottom to top.
If tarinfo is given, it is used as the starting point.
"""
# Ensure that all members have been loaded.
members = self.getmembers()
# Limit the member search list up to tarinfo.
if tarinfo is not None:
members = members[:members.index(tarinfo)]
if normalize:
name = os.path.normpath(name)
for member in reversed(members):
if normalize:
member_name = os.path.normpath(member.name)
else:
member_name = member.name
if name == member_name:
return member
def _load(self):
"""Read through the entire archive file and look for readable
members.
"""
while True:
tarinfo = self.next()
if tarinfo is None:
break
self._loaded = True
def _check(self, mode=None):
"""Check if TarFile is still open, and if the operation's mode
corresponds to TarFile's mode.
"""
if self.closed:
raise IOError("%s is closed" % self.__class__.__name__)
if mode is not None and self.mode not in mode:
raise IOError("bad operation for mode %r" % self.mode)
def _find_link_target(self, tarinfo):
"""Find the target member of a symlink or hardlink member in the
archive.
"""
if tarinfo.issym():
# Always search the entire archive.
linkname = "/".join(filter(None, (os.path.dirname(tarinfo.name), tarinfo.linkname)))
limit = None
else:
# Search the archive before the link, because a hard link is
# just a reference to an already archived file.
linkname = tarinfo.linkname
limit = tarinfo
member = self._getmember(linkname, tarinfo=limit, normalize=True)
if member is None:
raise KeyError("linkname %r not found" % linkname)
return member
def __iter__(self):
"""Provide an iterator object.
"""
if self._loaded:
return iter(self.members)
else:
return TarIter(self)
def _dbg(self, level, msg):
"""Write debugging output to sys.stderr.
"""
if level <= self.debug:
print(msg, file=sys.stderr)
def __enter__(self):
self._check()
return self
def __exit__(self, type, value, traceback):
if type is None:
self.close()
else:
# An exception occurred. We must not call close() because
# it would try to write end-of-archive blocks and padding.
if not self._extfileobj:
self.fileobj.close()
self.closed = True
# class TarFile
class TarIter:
"""Iterator Class.
for tarinfo in TarFile(...):
suite...
"""
def __init__(self, tarfile):
"""Construct a TarIter object.
"""
self.tarfile = tarfile
self.index = 0
def __iter__(self):
"""Return iterator object.
"""
return self
def __next__(self):
"""Return the next item using TarFile's next() method.
When all members have been read, set TarFile as _loaded.
"""
# Fix for SF #1100429: Under rare circumstances it can
# happen that getmembers() is called during iteration,
# which will cause TarIter to stop prematurely.
if self.index == 0 and self.tarfile.firstmember is not None:
tarinfo = self.tarfile.next()
elif self.index < len(self.tarfile.members):
tarinfo = self.tarfile.members[self.index]
elif not self.tarfile._loaded:
tarinfo = self.tarfile.next()
if not tarinfo:
self.tarfile._loaded = True
raise StopIteration
else:
raise StopIteration
self.index += 1
return tarinfo
#--------------------
# exported functions
#--------------------
def is_tarfile(name):
"""Return True if name points to a tar archive that we
are able to handle, else return False.
"""
try:
t = open(name)
t.close()
return True
except TarError:
return False
bltn_open = open
open = TarFile.open
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
7656,
2595,
199,
3,
13608,
14,
647,
199,
7656,
2595,
199,
3,
1898,
334,
35,
9,
14790,
491,
4291,
598,
833,
65,
2871,
352,
665,
31590,
32,
71,
833,
65,
2871,
352,
14,
271,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
8779,
221,
365,
221,
11882,
10009,
12,
221,
2867,
221,
402,
11204,
12,
221,
370,
221,
1263,
4954,
199,
3,
12408,
282,
221,
1331,
402,
221,
642,
2032,
221,
436,
4568,
3794,
199,
3,
1584,
221,
334,
1589,
221,
298,
10337,
1288,
221,
370,
257,
7962,
221,
315,
221,
314,
221,
2290,
257,
1928,
199,
3,
10588,
12,
221,
5893,
221,
1928,
12305,
221,
314,
221,
4481,
370,
221,
675,
12,
199,
3,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
221,
402,
221,
314,
221,
2290,
12,
221,
436,
370,
221,
11291,
221,
12103,
221,
370,
221,
12676,
314,
199,
3,
2290,
221,
365,
221,
13985,
221,
370,
221,
886,
221,
880,
12,
221,
5420,
221,
370,
221,
314,
221,
2569,
199,
3,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
221,
4245,
436,
642,
221,
4983,
4245,
10989,
221,
506,
199,
3,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
221,
2281,
401,
2428,
3408,
1634,
1821,
221,
3826,
12,
199,
3,
7168,
1549,
5292,
12,
6931,
221,
5400,
2845,
5471,
2296,
221,
2334,
2990,
199,
3,
1634,
221,
3169,
12,
221,
3092,
257,
2381,
221,
437,
221,
3115,
257,
3104,
221,
2401,
199,
3,
13229,
14,
221,
1621,
221,
4825,
221,
6461,
7000,
221,
2334,
221,
10610,
221,
1549,
5877,
199,
3,
8164,
221,
6262,
7024,
221,
2381,
1821,
221,
13140,
12,
6736,
221,
1549,
5010,
221,
5603,
12,
199,
3,
7061,
221,
1621,
1261,
221,
9612,
1634,
221,
7066,
12,
7056,
221,
1549,
7334,
12,
221,
7043,
199,
3,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
199,
3,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
624,
3284,
687,
436,
2218,
370,
5330,
1475,
25993,
14,
199,
624,
199,
199,
1023,
258,
275,
298,
16,
14,
25,
14,
16,
2,
199,
363,
2502,
363,
221,
275,
298,
44,
4291,
598,
833,
60,
85,
383,
69,
20,
20621,
334,
31590,
32,
71,
833,
65,
2871,
352,
14,
271,
2924,
199,
363,
602,
363,
259,
275,
7880,
2506,
26,
7760,
13,
996,
13,
821,
5557,
26,
2260,
26,
614,
435,
24215,
334,
22533,
12,
5661,
21141,
7760,
9,
2672,
2,
199,
363,
5107,
4148,
363,
257,
275,
7880,
1304,
26,
13608,
14,
647,
10523,
26888,
7760,
13,
996,
13,
821,
4114,
26,
2260,
26,
614,
58,
7557,
67,
13,
28547,
14,
274,
32649,
2672,
2,
199,
363,
22461,
363,
275,
298,
39,
833,
1214,
79,
653,
1873,
278,
23009,
12,
653,
14769,
83,
598,
833,
60,
85,
383,
69,
20,
20621,
12,
30846,
1005,
377,
944,
2254,
2122,
199,
199,
3,
9960,
199,
3,
24339,
199,
3,
9960,
199,
646,
984,
199,
646,
747,
199,
646,
5890,
199,
646,
5145,
199,
646,
5672,
199,
646,
900,
199,
646,
2702,
199,
646,
1331,
199,
646,
295,
199,
199,
893,
26,
272,
492,
18598,
12,
14374,
199,
2590,
3545,
26,
272,
18598,
275,
14374,
275,
488,
199,
199,
3,
747,
14,
13380,
641,
5417,
6791,
370,
1227,
14,
16,
6534,
4279,
199,
13380,
63,
1971,
275,
334,
10227,
12,
4279,
9,
199,
893,
26,
272,
327,
23950,
334,
969,
1079,
9,
911,
506,
4915,
340,
314,
8025,
1630,
440,
10266,
314,
272,
327,
3240,
2499,
16594,
9670,
3834,
30447,
1979,
17228,
272,
15296,
63,
1971,
847,
334,
8647,
547,
4258,
199,
2590,
12746,
26,
272,
986,
199,
199,
3,
687,
13608,
492,
627,
199,
363,
452,
363,
275,
2097,
24818,
1173,
401,
298,
24818,
2354,
401,
298,
374,
63,
19862,
401,
298,
24818,
547,
937,
199,
199,
504,
12963,
492,
1551,
465,
485,
1490,
327,
9336,
283,
1490,
7,
365,
30227,
14,
1490,
199,
199,
17807,
9960,
199,
3,
5330,
5262,
199,
17807,
9960,
199,
46,
1293,
275,
330,
3212,
16,
2,
9326,
327,
314,
2973,
4528,
199,
8475,
4305,
275,
10574,
463,
327,
2582,
402,
6661,
5664,
199,
15060,
4305,
275,
8068,
4305,
627,
3388,
258,
327,
2582,
402,
5767,
199,
17732,
63,
19973,
275,
330,
2,
833,
285,
221,
971,
16,
2,
263,
327,
10628,
486,
4850,
5330,
1059,
199,
16399,
63,
19973,
275,
330,
2,
833,
285,
60,
88,
993,
2,
259,
327,
10628,
10694,
5330,
1059,
199,
199,
9127,
63,
2339,
275,
2948,
5185,
327,
5696,
2582,
402,
282,
1788,
199,
9127,
63,
7916,
275,
2948,
5185,
327,
5696,
2582,
402,
282,
2142,
354,
199,
9127,
63,
6351,
275,
29710,
3777,
327,
5696,
2582,
402,
314,
2403,
901,
199,
199,
5616,
2711,
275,
330,
2,
16,
2,
8295,
327,
5578,
570,
199,
689,
4680,
2711,
275,
330,
3212,
16,
2,
4483,
327,
5578,
570,
199,
44,
22780,
2711,
275,
330,
2,
17,
2,
8295,
327,
2142,
334,
17183,
13608,
9,
199,
30637,
2711,
275,
330,
2,
18,
2,
8295,
327,
13673,
2142,
199,
1244,
50,
2711,
275,
330,
2,
19,
2,
8295,
327,
4528,
4539,
2243,
199,
7847,
43,
2711,
275,
330,
2,
20,
2,
8295,
327,
1853,
4539,
2243,
199,
3022,
2711,
275,
330,
2,
21,
2,
8295,
327,
2082,
199,
1976,
38,
1387,
4948,
275,
330,
2,
22,
2,
463,
327,
5883,
545,
4539,
2243,
199,
1864,
1481,
4948,
275,
330,
2,
23,
2,
463,
327,
26611,
570,
199,
199,
15306,
934,
4948,
63,
12375,
2339,
275,
330,
2,
44,
2,
260,
327,
1664,
5330,
1846,
354,
199,
15306,
934,
4948,
63,
44,
615,
2226,
12394,
275,
330,
2,
43,
2,
260,
327,
1664,
5330,
1846,
1073,
199,
15306,
934,
4948,
63,
51,
23354,
275,
330,
2,
51,
2,
3698,
327,
1664,
5330,
5178,
570,
199,
199,
56,
14903,
2711,
275,
330,
2,
88,
2,
8295,
327,
18169,
14,
17,
13,
8339,
9243,
1406,
199,
56,
2226,
2711,
275,
330,
2,
71,
2,
8295,
327,
18169,
14,
17,
13,
8339,
2288
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
7656,
2595,
199,
3,
13608,
14,
647,
199,
7656,
2595,
199,
3,
1898,
334,
35,
9,
14790,
491,
4291,
598,
833,
65,
2871,
352,
665,
31590,
32,
71,
833,
65,
2871,
352,
14,
271,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
8779,
221,
365,
221,
11882,
10009,
12,
221,
2867,
221,
402,
11204,
12,
221,
370,
221,
1263,
4954,
199,
3,
12408,
282,
221,
1331,
402,
221,
642,
2032,
221,
436,
4568,
3794,
199,
3,
1584,
221,
334,
1589,
221,
298,
10337,
1288,
221,
370,
257,
7962,
221,
315,
221,
314,
221,
2290,
257,
1928,
199,
3,
10588,
12,
221,
5893,
221,
1928,
12305,
221,
314,
221,
4481,
370,
221,
675,
12,
199,
3,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
221,
402,
221,
314,
221,
2290,
12,
221,
436,
370,
221,
11291,
221,
12103,
221,
370,
221,
12676,
314,
199,
3,
2290,
221,
365,
221,
13985,
221,
370,
221,
886,
221,
880,
12,
221,
5420,
221,
370,
221,
314,
221,
2569,
199,
3,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
221,
4245,
436,
642,
221,
4983,
4245,
10989,
221,
506,
199,
3,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
221,
2281,
401,
2428,
3408,
1634,
1821,
221,
3826,
12,
199,
3,
7168,
1549,
5292,
12,
6931,
221,
5400,
2845,
5471,
2296,
221,
2334,
2990,
199,
3,
1634,
221,
3169,
12,
221,
3092,
257,
2381,
221,
437,
221,
3115,
257,
3104,
221,
2401,
199,
3,
13229,
14,
221,
1621,
221,
4825,
221,
6461,
7000,
221,
2334,
221,
10610,
221,
1549,
5877,
199,
3,
8164,
221,
6262,
7024,
221,
2381,
1821,
221,
13140,
12,
6736,
221,
1549,
5010,
221,
5603,
12,
199,
3,
7061,
221,
1621,
1261,
221,
9612,
1634,
221,
7066,
12,
7056,
221,
1549,
7334,
12,
221,
7043,
199,
3,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
199,
3,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
624,
3284,
687,
436,
2218,
370,
5330,
1475,
25993,
14,
199,
624,
199,
199,
1023,
258,
275,
298,
16,
14,
25,
14,
16,
2,
199,
363,
2502,
363,
221,
275,
298,
44,
4291,
598,
833,
60,
85,
383,
69,
20,
20621,
334,
31590,
32,
71,
833,
65,
2871,
352,
14,
271,
2924,
199,
363,
602,
363,
259,
275,
7880,
2506,
26,
7760,
13,
996,
13,
821,
5557,
26,
2260,
26,
614,
435,
24215,
334,
22533,
12,
5661,
21141,
7760,
9,
2672,
2,
199,
363,
5107,
4148,
363,
257,
275,
7880,
1304,
26,
13608,
14,
647,
10523,
26888,
7760,
13,
996,
13,
821,
4114,
26,
2260,
26,
614,
58,
7557,
67,
13,
28547,
14,
274,
32649,
2672,
2,
199,
363,
22461,
363,
275,
298,
39,
833,
1214,
79,
653,
1873,
278,
23009,
12,
653,
14769,
83,
598,
833,
60,
85,
383,
69,
20,
20621,
12,
30846,
1005,
377,
944,
2254,
2122,
199,
199,
3,
9960,
199,
3,
24339,
199,
3,
9960,
199,
646,
984,
199,
646,
747,
199,
646,
5890,
199,
646,
5145,
199,
646,
5672,
199,
646,
900,
199,
646,
2702,
199,
646,
1331,
199,
646,
295,
199,
199,
893,
26,
272,
492,
18598,
12,
14374,
199,
2590,
3545,
26,
272,
18598,
275,
14374,
275,
488,
199,
199,
3,
747,
14,
13380,
641,
5417,
6791,
370,
1227,
14,
16,
6534,
4279,
199,
13380,
63,
1971,
275,
334,
10227,
12,
4279,
9,
199,
893,
26,
272,
327,
23950,
334,
969,
1079,
9,
911,
506,
4915,
340,
314,
8025,
1630,
440,
10266,
314,
272,
327,
3240,
2499,
16594,
9670,
3834,
30447,
1979,
17228,
272,
15296,
63,
1971,
847,
334,
8647,
547,
4258,
199,
2590,
12746,
26,
272,
986,
199,
199,
3,
687,
13608,
492,
627,
199,
363,
452,
363,
275,
2097,
24818,
1173,
401,
298,
24818,
2354,
401,
298,
374,
63,
19862,
401,
298,
24818,
547,
937,
199,
199,
504,
12963,
492,
1551,
465,
485,
1490,
327,
9336,
283,
1490,
7,
365,
30227,
14,
1490,
199,
199,
17807,
9960,
199,
3,
5330,
5262,
199,
17807,
9960,
199,
46,
1293,
275,
330,
3212,
16,
2,
9326,
327,
314,
2973,
4528,
199,
8475,
4305,
275,
10574,
463,
327,
2582,
402,
6661,
5664,
199,
15060,
4305,
275,
8068,
4305,
627,
3388,
258,
327,
2582,
402,
5767,
199,
17732,
63,
19973,
275,
330,
2,
833,
285,
221,
971,
16,
2,
263,
327,
10628,
486,
4850,
5330,
1059,
199,
16399,
63,
19973,
275,
330,
2,
833,
285,
60,
88,
993,
2,
259,
327,
10628,
10694,
5330,
1059,
199,
199,
9127,
63,
2339,
275,
2948,
5185,
327,
5696,
2582,
402,
282,
1788,
199,
9127,
63,
7916,
275,
2948,
5185,
327,
5696,
2582,
402,
282,
2142,
354,
199,
9127,
63,
6351,
275,
29710,
3777,
327,
5696,
2582,
402,
314,
2403,
901,
199,
199,
5616,
2711,
275,
330,
2,
16,
2,
8295,
327,
5578,
570,
199,
689,
4680,
2711,
275,
330,
3212,
16,
2,
4483,
327,
5578,
570,
199,
44,
22780,
2711,
275,
330,
2,
17,
2,
8295,
327,
2142,
334,
17183,
13608,
9,
199,
30637,
2711,
275,
330,
2,
18,
2,
8295,
327,
13673,
2142,
199,
1244,
50,
2711,
275,
330,
2,
19,
2,
8295,
327,
4528,
4539,
2243,
199,
7847,
43,
2711,
275,
330,
2,
20,
2,
8295,
327,
1853,
4539,
2243,
199,
3022,
2711,
275,
330,
2,
21,
2,
8295,
327,
2082,
199,
1976,
38,
1387,
4948,
275,
330,
2,
22,
2,
463,
327,
5883,
545,
4539,
2243,
199,
1864,
1481,
4948,
275,
330,
2,
23,
2,
463,
327,
26611,
570,
199,
199,
15306,
934,
4948,
63,
12375,
2339,
275,
330,
2,
44,
2,
260,
327,
1664,
5330,
1846,
354,
199,
15306,
934,
4948,
63,
44,
615,
2226,
12394,
275,
330,
2,
43,
2,
260,
327,
1664,
5330,
1846,
1073,
199,
15306,
934,
4948,
63,
51,
23354,
275,
330,
2,
51,
2,
3698,
327,
1664,
5330,
5178,
570,
199,
199,
56,
14903,
2711,
275,
330,
2,
88,
2,
8295,
327,
18169,
14,
17,
13,
8339,
9243,
1406,
199,
56,
2226,
2711,
275,
330,
2,
71,
2,
8295,
327,
18169,
14,
17,
13,
8339,
2288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
40223236/40223236-50
|
static/Brython3.1.1-20150328-091302/Lib/unittest/runner.py
|
637
|
7485
|
"""Running tests"""
import sys
import time
import warnings
from . import result
from .signals import registerResult
__unittest = True
class _WritelnDecorator(object):
"""Used to decorate file-like objects with a handy 'writeln' method"""
def __init__(self,stream):
self.stream = stream
def __getattr__(self, attr):
if attr in ('stream', '__getstate__'):
raise AttributeError(attr)
return getattr(self.stream,attr)
def writeln(self, arg=None):
if arg:
self.write(arg)
self.write('\n') # text-mode streams translate to \r\n if needed
class TextTestResult(result.TestResult):
"""A test result class that can print formatted text results to a stream.
Used by TextTestRunner.
"""
separator1 = '=' * 70
separator2 = '-' * 70
def __init__(self, stream, descriptions, verbosity):
super(TextTestResult, self).__init__(stream, descriptions, verbosity)
self.stream = stream
self.showAll = verbosity > 1
self.dots = verbosity == 1
self.descriptions = descriptions
def getDescription(self, test):
doc_first_line = test.shortDescription()
if self.descriptions and doc_first_line:
return '\n'.join((str(test), doc_first_line))
else:
return str(test)
def startTest(self, test):
super(TextTestResult, self).startTest(test)
if self.showAll:
self.stream.write(self.getDescription(test))
self.stream.write(" ... ")
self.stream.flush()
def addSuccess(self, test):
super(TextTestResult, self).addSuccess(test)
if self.showAll:
self.stream.writeln("ok")
elif self.dots:
self.stream.write('.')
self.stream.flush()
def addError(self, test, err):
super(TextTestResult, self).addError(test, err)
if self.showAll:
self.stream.writeln("ERROR")
elif self.dots:
self.stream.write('E')
self.stream.flush()
def addFailure(self, test, err):
super(TextTestResult, self).addFailure(test, err)
if self.showAll:
self.stream.writeln("FAIL")
elif self.dots:
self.stream.write('F')
self.stream.flush()
def addSkip(self, test, reason):
super(TextTestResult, self).addSkip(test, reason)
if self.showAll:
self.stream.writeln("skipped {0!r}".format(reason))
elif self.dots:
self.stream.write("s")
self.stream.flush()
def addExpectedFailure(self, test, err):
super(TextTestResult, self).addExpectedFailure(test, err)
if self.showAll:
self.stream.writeln("expected failure")
elif self.dots:
self.stream.write("x")
self.stream.flush()
def addUnexpectedSuccess(self, test):
super(TextTestResult, self).addUnexpectedSuccess(test)
if self.showAll:
self.stream.writeln("unexpected success")
elif self.dots:
self.stream.write("u")
self.stream.flush()
def printErrors(self):
if self.dots or self.showAll:
self.stream.writeln()
self.printErrorList('ERROR', self.errors)
self.printErrorList('FAIL', self.failures)
def printErrorList(self, flavour, errors):
for test, err in errors:
self.stream.writeln(self.separator1)
self.stream.writeln("%s: %s" % (flavour,self.getDescription(test)))
self.stream.writeln(self.separator2)
self.stream.writeln("%s" % err)
class TextTestRunner(object):
"""A test runner class that displays results in textual form.
It prints out the names of tests as they are run, errors as they
occur, and a summary of the results at the end of the test run.
"""
resultclass = TextTestResult
def __init__(self, stream=None, descriptions=True, verbosity=1,
failfast=False, buffer=False, resultclass=None, warnings=None):
if stream is None:
stream = sys.stderr
self.stream = _WritelnDecorator(stream)
self.descriptions = descriptions
self.verbosity = verbosity
self.failfast = failfast
self.buffer = buffer
self.warnings = warnings
if resultclass is not None:
self.resultclass = resultclass
def _makeResult(self):
return self.resultclass(self.stream, self.descriptions, self.verbosity)
def run(self, test):
"Run the given test case or test suite."
result = self._makeResult()
registerResult(result)
result.failfast = self.failfast
result.buffer = self.buffer
with warnings.catch_warnings():
if self.warnings:
# if self.warnings is set, use it to filter all the warnings
warnings.simplefilter(self.warnings)
# if the filter is 'default' or 'always', special-case the
# warnings from the deprecated unittest methods to show them
# no more than once per module, because they can be fairly
# noisy. The -Wd and -Wa flags can be used to bypass this
# only when self.warnings is None.
if self.warnings in ['default', 'always']:
warnings.filterwarnings('module',
category=DeprecationWarning,
message='Please use assert\w+ instead.')
startTime = time.time()
startTestRun = getattr(result, 'startTestRun', None)
if startTestRun is not None:
startTestRun()
try:
test(result)
finally:
stopTestRun = getattr(result, 'stopTestRun', None)
if stopTestRun is not None:
stopTestRun()
stopTime = time.time()
timeTaken = stopTime - startTime
result.printErrors()
if hasattr(result, 'separator2'):
self.stream.writeln(result.separator2)
run = result.testsRun
self.stream.writeln("Ran %d test%s in %.3fs" %
(run, run != 1 and "s" or "", timeTaken))
self.stream.writeln()
expectedFails = unexpectedSuccesses = skipped = 0
try:
results = map(len, (result.expectedFailures,
result.unexpectedSuccesses,
result.skipped))
except AttributeError:
pass
else:
expectedFails, unexpectedSuccesses, skipped = results
infos = []
if not result.wasSuccessful():
self.stream.write("FAILED")
failed, errored = len(result.failures), len(result.errors)
if failed:
infos.append("failures=%d" % failed)
if errored:
infos.append("errors=%d" % errored)
else:
self.stream.write("OK")
if skipped:
infos.append("skipped=%d" % skipped)
if expectedFails:
infos.append("expected failures=%d" % expectedFails)
if unexpectedSuccesses:
infos.append("unexpected successes=%d" % unexpectedSuccesses)
if infos:
self.stream.writeln(" (%s)" % (", ".join(infos),))
else:
self.stream.write("\n")
return result
|
gpl-3.0
|
[
624,
9602,
2295,
624,
199,
199,
646,
984,
199,
646,
900,
199,
646,
3598,
199,
199,
504,
1275,
492,
754,
199,
504,
1275,
10458,
492,
2274,
2889,
199,
199,
363,
2796,
275,
715,
421,
199,
533,
485,
3534,
6066,
14946,
8,
785,
304,
272,
408,
9167,
370,
24774,
570,
13,
2930,
2251,
543,
282,
4926,
89,
283,
21768,
7,
1083,
624,
272,
347,
636,
826,
721,
277,
12,
1745,
304,
267,
291,
14,
1745,
275,
2547,
339,
347,
636,
5675,
721,
277,
12,
1921,
304,
267,
340,
1921,
315,
661,
1745,
297,
2560,
16011,
12168,
288,
746,
4281,
8,
962,
9,
267,
372,
2519,
8,
277,
14,
1745,
12,
962,
9,
339,
347,
2218,
6066,
8,
277,
12,
1680,
29,
403,
304,
267,
340,
1680,
26,
288,
291,
14,
952,
8,
1273,
9,
267,
291,
14,
952,
2258,
78,
358,
327,
1318,
13,
632,
13788,
9028,
370,
971,
82,
60,
78,
340,
4346,
421,
199,
533,
4516,
13120,
8,
1099,
14,
13120,
304,
272,
408,
33,
511,
754,
1021,
626,
883,
870,
7871,
1318,
2058,
370,
282,
2547,
14,
339,
8051,
701,
4516,
13649,
14,
272,
408,
272,
9432,
17,
275,
14051,
627,
10045,
272,
9432,
18,
275,
10791,
627,
10045,
339,
347,
636,
826,
721,
277,
12,
2547,
12,
18714,
12,
8661,
304,
267,
1613,
8,
1872,
13120,
12,
291,
2843,
826,
721,
1745,
12,
18714,
12,
8661,
9,
267,
291,
14,
1745,
275,
2547,
267,
291,
14,
2384,
2422,
275,
8661,
690,
413,
267,
291,
14,
25310,
275,
8661,
508,
413,
267,
291,
14,
21713,
275,
18714,
339,
347,
664,
5831,
8,
277,
12,
511,
304,
267,
1382,
63,
2246,
63,
604,
275,
511,
14,
3612,
5831,
342,
267,
340,
291,
14,
21713,
436,
1382,
63,
2246,
63,
604,
26,
288,
372,
1557,
78,
1370,
904,
1332,
495,
8,
396,
395,
1382,
63,
2246,
63,
604,
430,
267,
587,
26,
288,
372,
620,
8,
396,
9,
339,
347,
1343,
774,
8,
277,
12,
511,
304,
267,
1613,
8,
1872,
13120,
12,
291,
680,
29344,
8,
396,
9,
267,
340,
291,
14,
2384,
2422,
26,
288,
291,
14,
1745,
14,
952,
8,
277,
14,
362,
5831,
8,
396,
430,
288,
291,
14,
1745,
14,
952,
480,
2263,
6099,
288,
291,
14,
1745,
14,
4939,
342,
339,
347,
1050,
8300,
8,
277,
12,
511,
304,
267,
1613,
8,
1872,
13120,
12,
291,
680,
525,
8300,
8,
396,
9,
267,
340,
291,
14,
2384,
2422,
26,
288,
291,
14,
1745,
14,
21768,
480,
745,
531,
267,
916,
291,
14,
25310,
26,
288,
291,
14,
1745,
14,
952,
7563,
288,
291,
14,
1745,
14,
4939,
342,
339,
347,
1050,
547,
8,
277,
12,
511,
12,
2329,
304,
267,
1613,
8,
1872,
13120,
12,
291,
680,
30787,
8,
396,
12,
2329,
9,
267,
340,
291,
14,
2384,
2422,
26,
288,
291,
14,
1745,
14,
21768,
480,
3170,
531,
267,
916,
291,
14,
25310,
26,
288,
291,
14,
1745,
14,
952,
360,
37,
358,
288,
291,
14,
1745,
14,
4939,
342,
339,
347,
1050,
6782,
8,
277,
12,
511,
12,
2329,
304,
267,
1613,
8,
1872,
13120,
12,
291,
680,
525,
6782,
8,
396,
12,
2329,
9,
267,
340,
291,
14,
2384,
2422,
26,
288,
291,
14,
1745,
14,
21768,
480,
8784,
531,
267,
916,
291,
14,
25310,
26,
288,
291,
14,
1745,
14,
952,
360,
38,
358,
288,
291,
14,
1745,
14,
4939,
342,
339,
347,
1050,
7738,
8,
277,
12,
511,
12,
4499,
304,
267,
1613,
8,
1872,
13120,
12,
291,
680,
525,
7738,
8,
396,
12,
4499,
9,
267,
340,
291,
14,
2384,
2422,
26,
288,
291,
14,
1745,
14,
21768,
480,
11962,
469,
16,
1,
82,
5469,
908,
8,
5764,
430,
267,
916,
291,
14,
25310,
26,
288,
291,
14,
1745,
14,
952,
480,
83,
531,
288,
291,
14,
1745,
14,
4939,
342,
339,
347,
1050,
6964,
6782,
8,
277,
12,
511,
12,
2329,
304,
267,
1613,
8,
1872,
13120,
12,
291,
680,
525,
6964,
6782,
8,
396,
12,
2329,
9,
267,
340,
291,
14,
2384,
2422,
26,
288,
291,
14,
1745,
14,
21768,
480,
2062,
5988,
531,
267,
916,
291,
14,
25310,
26,
288,
291,
14,
1745,
14,
952,
480,
88,
531,
288,
291,
14,
1745,
14,
4939,
342,
339,
347,
1050,
8708,
8300,
8,
277,
12,
511,
304,
267,
1613,
8,
1872,
13120,
12,
291,
680,
525,
8708,
8300,
8,
396,
9,
267,
340,
291,
14,
2384,
2422,
26,
288,
291,
14,
1745,
14,
21768,
480,
8953,
3182,
531,
267,
916,
291,
14,
25310,
26,
288,
291,
14,
1745,
14,
952,
480,
85,
531,
288,
291,
14,
1745,
14,
4939,
342,
339,
347,
870,
9298,
8,
277,
304,
267,
340,
291,
14,
25310,
503,
291,
14,
2384,
2422,
26,
288,
291,
14,
1745,
14,
21768,
342,
267,
291,
14,
1361,
547,
1296,
360,
3170,
297,
291,
14,
2550,
9,
267,
291,
14,
1361,
547,
1296,
360,
8784,
297,
291,
14,
9968,
9,
339,
347,
870,
547,
1296,
8,
277,
12,
289,
3783,
567,
12,
2552,
304,
267,
367,
511,
12,
2329,
315,
2552,
26,
288,
291,
14,
1745,
14,
21768,
8,
277,
14,
9896,
17,
9,
288,
291,
14,
1745,
14,
21768,
3647,
83,
26,
450,
83,
2,
450,
334,
70,
3783,
567,
12,
277,
14,
362,
5831,
8,
396,
1724,
288,
291,
14,
1745,
14,
21768,
8,
277,
14,
9896,
18,
9,
288,
291,
14,
1745,
14,
21768,
3647,
83,
2,
450,
2329,
9,
421,
199,
533,
4516,
13649,
8,
785,
304,
272,
408,
33,
511,
7876,
1021,
626,
17561,
2058,
315,
25884,
1824,
14,
339,
2779,
14767,
734,
314,
1561,
402,
2295,
465,
2985,
787,
1255,
12,
2552,
465,
2985,
272,
4781,
12,
436,
282,
6212,
402,
314,
2058,
737,
314,
1284,
402,
314,
511,
1255,
14,
272,
408,
272,
754,
533,
275,
4516,
13120,
339,
347,
636,
826,
721,
277,
12,
2547,
29,
403,
12,
18714,
29,
549,
12,
8661,
29,
17,
12,
326,
1433,
20803,
29,
797,
12,
3335,
29,
797,
12,
754,
533,
29,
403,
12,
3598,
29,
403,
304,
267,
340,
2547,
365,
488,
26,
288,
2547,
275,
984,
14,
3083,
267,
291,
14,
1745,
275,
485,
3534,
6066,
14946,
8,
1745,
9,
267,
291,
14
] |
[
9602,
2295,
624,
199,
199,
646,
984,
199,
646,
900,
199,
646,
3598,
199,
199,
504,
1275,
492,
754,
199,
504,
1275,
10458,
492,
2274,
2889,
199,
199,
363,
2796,
275,
715,
421,
199,
533,
485,
3534,
6066,
14946,
8,
785,
304,
272,
408,
9167,
370,
24774,
570,
13,
2930,
2251,
543,
282,
4926,
89,
283,
21768,
7,
1083,
624,
272,
347,
636,
826,
721,
277,
12,
1745,
304,
267,
291,
14,
1745,
275,
2547,
339,
347,
636,
5675,
721,
277,
12,
1921,
304,
267,
340,
1921,
315,
661,
1745,
297,
2560,
16011,
12168,
288,
746,
4281,
8,
962,
9,
267,
372,
2519,
8,
277,
14,
1745,
12,
962,
9,
339,
347,
2218,
6066,
8,
277,
12,
1680,
29,
403,
304,
267,
340,
1680,
26,
288,
291,
14,
952,
8,
1273,
9,
267,
291,
14,
952,
2258,
78,
358,
327,
1318,
13,
632,
13788,
9028,
370,
971,
82,
60,
78,
340,
4346,
421,
199,
533,
4516,
13120,
8,
1099,
14,
13120,
304,
272,
408,
33,
511,
754,
1021,
626,
883,
870,
7871,
1318,
2058,
370,
282,
2547,
14,
339,
8051,
701,
4516,
13649,
14,
272,
408,
272,
9432,
17,
275,
14051,
627,
10045,
272,
9432,
18,
275,
10791,
627,
10045,
339,
347,
636,
826,
721,
277,
12,
2547,
12,
18714,
12,
8661,
304,
267,
1613,
8,
1872,
13120,
12,
291,
2843,
826,
721,
1745,
12,
18714,
12,
8661,
9,
267,
291,
14,
1745,
275,
2547,
267,
291,
14,
2384,
2422,
275,
8661,
690,
413,
267,
291,
14,
25310,
275,
8661,
508,
413,
267,
291,
14,
21713,
275,
18714,
339,
347,
664,
5831,
8,
277,
12,
511,
304,
267,
1382,
63,
2246,
63,
604,
275,
511,
14,
3612,
5831,
342,
267,
340,
291,
14,
21713,
436,
1382,
63,
2246,
63,
604,
26,
288,
372,
1557,
78,
1370,
904,
1332,
495,
8,
396,
395,
1382,
63,
2246,
63,
604,
430,
267,
587,
26,
288,
372,
620,
8,
396,
9,
339,
347,
1343,
774,
8,
277,
12,
511,
304,
267,
1613,
8,
1872,
13120,
12,
291,
680,
29344,
8,
396,
9,
267,
340,
291,
14,
2384,
2422,
26,
288,
291,
14,
1745,
14,
952,
8,
277,
14,
362,
5831,
8,
396,
430,
288,
291,
14,
1745,
14,
952,
480,
2263,
6099,
288,
291,
14,
1745,
14,
4939,
342,
339,
347,
1050,
8300,
8,
277,
12,
511,
304,
267,
1613,
8,
1872,
13120,
12,
291,
680,
525,
8300,
8,
396,
9,
267,
340,
291,
14,
2384,
2422,
26,
288,
291,
14,
1745,
14,
21768,
480,
745,
531,
267,
916,
291,
14,
25310,
26,
288,
291,
14,
1745,
14,
952,
7563,
288,
291,
14,
1745,
14,
4939,
342,
339,
347,
1050,
547,
8,
277,
12,
511,
12,
2329,
304,
267,
1613,
8,
1872,
13120,
12,
291,
680,
30787,
8,
396,
12,
2329,
9,
267,
340,
291,
14,
2384,
2422,
26,
288,
291,
14,
1745,
14,
21768,
480,
3170,
531,
267,
916,
291,
14,
25310,
26,
288,
291,
14,
1745,
14,
952,
360,
37,
358,
288,
291,
14,
1745,
14,
4939,
342,
339,
347,
1050,
6782,
8,
277,
12,
511,
12,
2329,
304,
267,
1613,
8,
1872,
13120,
12,
291,
680,
525,
6782,
8,
396,
12,
2329,
9,
267,
340,
291,
14,
2384,
2422,
26,
288,
291,
14,
1745,
14,
21768,
480,
8784,
531,
267,
916,
291,
14,
25310,
26,
288,
291,
14,
1745,
14,
952,
360,
38,
358,
288,
291,
14,
1745,
14,
4939,
342,
339,
347,
1050,
7738,
8,
277,
12,
511,
12,
4499,
304,
267,
1613,
8,
1872,
13120,
12,
291,
680,
525,
7738,
8,
396,
12,
4499,
9,
267,
340,
291,
14,
2384,
2422,
26,
288,
291,
14,
1745,
14,
21768,
480,
11962,
469,
16,
1,
82,
5469,
908,
8,
5764,
430,
267,
916,
291,
14,
25310,
26,
288,
291,
14,
1745,
14,
952,
480,
83,
531,
288,
291,
14,
1745,
14,
4939,
342,
339,
347,
1050,
6964,
6782,
8,
277,
12,
511,
12,
2329,
304,
267,
1613,
8,
1872,
13120,
12,
291,
680,
525,
6964,
6782,
8,
396,
12,
2329,
9,
267,
340,
291,
14,
2384,
2422,
26,
288,
291,
14,
1745,
14,
21768,
480,
2062,
5988,
531,
267,
916,
291,
14,
25310,
26,
288,
291,
14,
1745,
14,
952,
480,
88,
531,
288,
291,
14,
1745,
14,
4939,
342,
339,
347,
1050,
8708,
8300,
8,
277,
12,
511,
304,
267,
1613,
8,
1872,
13120,
12,
291,
680,
525,
8708,
8300,
8,
396,
9,
267,
340,
291,
14,
2384,
2422,
26,
288,
291,
14,
1745,
14,
21768,
480,
8953,
3182,
531,
267,
916,
291,
14,
25310,
26,
288,
291,
14,
1745,
14,
952,
480,
85,
531,
288,
291,
14,
1745,
14,
4939,
342,
339,
347,
870,
9298,
8,
277,
304,
267,
340,
291,
14,
25310,
503,
291,
14,
2384,
2422,
26,
288,
291,
14,
1745,
14,
21768,
342,
267,
291,
14,
1361,
547,
1296,
360,
3170,
297,
291,
14,
2550,
9,
267,
291,
14,
1361,
547,
1296,
360,
8784,
297,
291,
14,
9968,
9,
339,
347,
870,
547,
1296,
8,
277,
12,
289,
3783,
567,
12,
2552,
304,
267,
367,
511,
12,
2329,
315,
2552,
26,
288,
291,
14,
1745,
14,
21768,
8,
277,
14,
9896,
17,
9,
288,
291,
14,
1745,
14,
21768,
3647,
83,
26,
450,
83,
2,
450,
334,
70,
3783,
567,
12,
277,
14,
362,
5831,
8,
396,
1724,
288,
291,
14,
1745,
14,
21768,
8,
277,
14,
9896,
18,
9,
288,
291,
14,
1745,
14,
21768,
3647,
83,
2,
450,
2329,
9,
421,
199,
533,
4516,
13649,
8,
785,
304,
272,
408,
33,
511,
7876,
1021,
626,
17561,
2058,
315,
25884,
1824,
14,
339,
2779,
14767,
734,
314,
1561,
402,
2295,
465,
2985,
787,
1255,
12,
2552,
465,
2985,
272,
4781,
12,
436,
282,
6212,
402,
314,
2058,
737,
314,
1284,
402,
314,
511,
1255,
14,
272,
408,
272,
754,
533,
275,
4516,
13120,
339,
347,
636,
826,
721,
277,
12,
2547,
29,
403,
12,
18714,
29,
549,
12,
8661,
29,
17,
12,
326,
1433,
20803,
29,
797,
12,
3335,
29,
797,
12,
754,
533,
29,
403,
12,
3598,
29,
403,
304,
267,
340,
2547,
365,
488,
26,
288,
2547,
275,
984,
14,
3083,
267,
291,
14,
1745,
275,
485,
3534,
6066,
14946,
8,
1745,
9,
267,
291,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
CodingCat/mxnet
|
example/image-classification/symbols/inception-resnet-v2.py
|
23
|
6943
|
# 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.
"""
Contains the definition of the Inception Resnet V2 architecture.
As described in http://arxiv.org/abs/1602.07261.
Inception-v4, Inception-ResNet and the Impact of Residual Connections
on Learning
Christian Szegedy, Sergey Ioffe, Vincent Vanhoucke, Alex Alemi
"""
import mxnet as mx
def ConvFactory(data, num_filter, kernel, stride=(1, 1), pad=(0, 0), act_type="relu", mirror_attr={}, with_act=True):
conv = mx.symbol.Convolution(
data=data, num_filter=num_filter, kernel=kernel, stride=stride, pad=pad)
bn = mx.symbol.BatchNorm(data=conv)
if with_act:
act = mx.symbol.Activation(
data=bn, act_type=act_type, attr=mirror_attr)
return act
else:
return bn
def block35(net, input_num_channels, scale=1.0, with_act=True, act_type='relu', mirror_attr={}):
tower_conv = ConvFactory(net, 32, (1, 1))
tower_conv1_0 = ConvFactory(net, 32, (1, 1))
tower_conv1_1 = ConvFactory(tower_conv1_0, 32, (3, 3), pad=(1, 1))
tower_conv2_0 = ConvFactory(net, 32, (1, 1))
tower_conv2_1 = ConvFactory(tower_conv2_0, 48, (3, 3), pad=(1, 1))
tower_conv2_2 = ConvFactory(tower_conv2_1, 64, (3, 3), pad=(1, 1))
tower_mixed = mx.symbol.Concat(*[tower_conv, tower_conv1_1, tower_conv2_2])
tower_out = ConvFactory(
tower_mixed, input_num_channels, (1, 1), with_act=False)
net = net + scale * tower_out
if with_act:
act = mx.symbol.Activation(
data=net, act_type=act_type, attr=mirror_attr)
return act
else:
return net
def block17(net, input_num_channels, scale=1.0, with_act=True, act_type='relu', mirror_attr={}):
tower_conv = ConvFactory(net, 192, (1, 1))
tower_conv1_0 = ConvFactory(net, 129, (1, 1))
tower_conv1_1 = ConvFactory(tower_conv1_0, 160, (1, 7), pad=(1, 2))
tower_conv1_2 = ConvFactory(tower_conv1_1, 192, (7, 1), pad=(2, 1))
tower_mixed = mx.symbol.Concat(*[tower_conv, tower_conv1_2])
tower_out = ConvFactory(
tower_mixed, input_num_channels, (1, 1), with_act=False)
net = net + scale * tower_out
if with_act:
act = mx.symbol.Activation(
data=net, act_type=act_type, attr=mirror_attr)
return act
else:
return net
def block8(net, input_num_channels, scale=1.0, with_act=True, act_type='relu', mirror_attr={}):
tower_conv = ConvFactory(net, 192, (1, 1))
tower_conv1_0 = ConvFactory(net, 192, (1, 1))
tower_conv1_1 = ConvFactory(tower_conv1_0, 224, (1, 3), pad=(0, 1))
tower_conv1_2 = ConvFactory(tower_conv1_1, 256, (3, 1), pad=(1, 0))
tower_mixed = mx.symbol.Concat(*[tower_conv, tower_conv1_2])
tower_out = ConvFactory(
tower_mixed, input_num_channels, (1, 1), with_act=False)
net = net + scale * tower_out
if with_act:
act = mx.symbol.Activation(
data=net, act_type=act_type, attr=mirror_attr)
return act
else:
return net
def repeat(inputs, repetitions, layer, *args, **kwargs):
outputs = inputs
for i in range(repetitions):
outputs = layer(outputs, *args, **kwargs)
return outputs
def get_symbol(num_classes=1000, **kwargs):
data = mx.symbol.Variable(name='data')
conv1a_3_3 = ConvFactory(data=data, num_filter=32,
kernel=(3, 3), stride=(2, 2))
conv2a_3_3 = ConvFactory(conv1a_3_3, 32, (3, 3))
conv2b_3_3 = ConvFactory(conv2a_3_3, 64, (3, 3), pad=(1, 1))
maxpool3a_3_3 = mx.symbol.Pooling(
data=conv2b_3_3, kernel=(3, 3), stride=(2, 2), pool_type='max')
conv3b_1_1 = ConvFactory(maxpool3a_3_3, 80, (1, 1))
conv4a_3_3 = ConvFactory(conv3b_1_1, 192, (3, 3))
maxpool5a_3_3 = mx.symbol.Pooling(
data=conv4a_3_3, kernel=(3, 3), stride=(2, 2), pool_type='max')
tower_conv = ConvFactory(maxpool5a_3_3, 96, (1, 1))
tower_conv1_0 = ConvFactory(maxpool5a_3_3, 48, (1, 1))
tower_conv1_1 = ConvFactory(tower_conv1_0, 64, (5, 5), pad=(2, 2))
tower_conv2_0 = ConvFactory(maxpool5a_3_3, 64, (1, 1))
tower_conv2_1 = ConvFactory(tower_conv2_0, 96, (3, 3), pad=(1, 1))
tower_conv2_2 = ConvFactory(tower_conv2_1, 96, (3, 3), pad=(1, 1))
tower_pool3_0 = mx.symbol.Pooling(data=maxpool5a_3_3, kernel=(
3, 3), stride=(1, 1), pad=(1, 1), pool_type='avg')
tower_conv3_1 = ConvFactory(tower_pool3_0, 64, (1, 1))
tower_5b_out = mx.symbol.Concat(
*[tower_conv, tower_conv1_1, tower_conv2_2, tower_conv3_1])
net = repeat(tower_5b_out, 10, block35, scale=0.17, input_num_channels=320)
tower_conv = ConvFactory(net, 384, (3, 3), stride=(2, 2))
tower_conv1_0 = ConvFactory(net, 256, (1, 1))
tower_conv1_1 = ConvFactory(tower_conv1_0, 256, (3, 3), pad=(1, 1))
tower_conv1_2 = ConvFactory(tower_conv1_1, 384, (3, 3), stride=(2, 2))
tower_pool = mx.symbol.Pooling(net, kernel=(
3, 3), stride=(2, 2), pool_type='max')
net = mx.symbol.Concat(*[tower_conv, tower_conv1_2, tower_pool])
net = repeat(net, 20, block17, scale=0.1, input_num_channels=1088)
tower_conv = ConvFactory(net, 256, (1, 1))
tower_conv0_1 = ConvFactory(tower_conv, 384, (3, 3), stride=(2, 2))
tower_conv1 = ConvFactory(net, 256, (1, 1))
tower_conv1_1 = ConvFactory(tower_conv1, 288, (3, 3), stride=(2, 2))
tower_conv2 = ConvFactory(net, 256, (1, 1))
tower_conv2_1 = ConvFactory(tower_conv2, 288, (3, 3), pad=(1, 1))
tower_conv2_2 = ConvFactory(tower_conv2_1, 320, (3, 3), stride=(2, 2))
tower_pool = mx.symbol.Pooling(net, kernel=(
3, 3), stride=(2, 2), pool_type='max')
net = mx.symbol.Concat(
*[tower_conv0_1, tower_conv1_1, tower_conv2_2, tower_pool])
net = repeat(net, 9, block8, scale=0.2, input_num_channels=2080)
net = block8(net, with_act=False, input_num_channels=2080)
net = ConvFactory(net, 1536, (1, 1))
net = mx.symbol.Pooling(net, kernel=(
1, 1), global_pool=True, stride=(2, 2), pool_type='avg')
net = mx.symbol.Flatten(net)
net = mx.symbol.Dropout(data=net, p=0.2)
net = mx.symbol.FullyConnected(data=net, num_hidden=num_classes)
softmax = mx.symbol.SoftmaxOutput(data=net, name='softmax')
return softmax
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
624,
199,
6906,
314,
5492,
402,
314,
1010,
814,
3591,
846,
812,
18,
15931,
14,
199,
2822,
11736,
315,
1455,
921,
27290,
14,
1308,
15,
2101,
15,
975,
996,
14,
1780,
15128,
14,
199,
607,
814,
13,
86,
20,
12,
1010,
814,
13,
1322,
2480,
436,
314,
8362,
2442,
402,
799,
10969,
8113,
83,
199,
265,
29127,
199,
1049,
18824,
5653,
428,
806,
3046,
89,
12,
3739,
303,
89,
473,
1997,
69,
12,
28882,
2946,
812,
290,
526,
10112,
69,
12,
22986,
6832,
2664,
199,
624,
199,
646,
8728,
846,
465,
8728,
421,
199,
318,
19140,
2927,
8,
576,
12,
1967,
63,
1541,
12,
5114,
12,
7345,
2687,
17,
12,
413,
395,
6567,
2687,
16,
12,
378,
395,
2454,
63,
466,
628,
12833,
401,
15216,
63,
962,
10324,
543,
63,
2442,
29,
549,
304,
272,
8260,
275,
8728,
14,
5155,
14,
27394,
8,
267,
666,
29,
576,
12,
1967,
63,
1541,
29,
1507,
63,
1541,
12,
5114,
29,
4989,
12,
7345,
29,
12318,
12,
6567,
29,
6226,
9,
272,
21847,
275,
8728,
14,
5155,
14,
32672,
8,
576,
29,
5598,
9,
272,
340,
543,
63,
2442,
26,
267,
2454,
275,
8728,
14,
5155,
14,
19535,
8,
288,
666,
29,
10472,
12,
2454,
63,
466,
29,
2442,
63,
466,
12,
1921,
29,
12324,
63,
962,
9,
267,
372,
2454,
272,
587,
26,
267,
372,
21847,
421,
199,
318,
1853,
1276,
8,
846,
12,
1324,
63,
1507,
63,
6324,
12,
4666,
29,
17,
14,
16,
12,
543,
63,
2442,
29,
549,
12,
2454,
63,
466,
534,
12833,
297,
15216,
63,
962,
16420,
272,
18915,
63,
5598,
275,
19140,
2927,
8,
846,
12,
4337,
12,
334,
17,
12,
413,
430,
272,
18915,
63,
5598,
17,
63,
16,
275,
19140,
2927,
8,
846,
12,
4337,
12,
334,
17,
12,
413,
430,
272,
18915,
63,
5598,
17,
63,
17,
275,
19140,
2927,
8,
21651,
63,
5598,
17,
63,
16,
12,
4337,
12,
334,
19,
12,
650,
395,
6567,
2687,
17,
12,
413,
430,
272,
18915,
63,
5598,
18,
63,
16,
275,
19140,
2927,
8,
846,
12,
4337,
12,
334,
17,
12,
413,
430,
272,
18915,
63,
5598,
18,
63,
17,
275,
19140,
2927,
8,
21651,
63,
5598,
18,
63,
16,
12,
9615,
12,
334,
19,
12,
650,
395,
6567,
2687,
17,
12,
413,
430,
272,
18915,
63,
5598,
18,
63,
18,
275,
19140,
2927,
8,
21651,
63,
5598,
18,
63,
17,
12,
5049,
12,
334,
19,
12,
650,
395,
6567,
2687,
17,
12,
413,
430,
272,
18915,
63,
10455,
275,
8728,
14,
5155,
14,
25536,
23151,
21651,
63,
5598,
12,
18915,
63,
5598,
17,
63,
17,
12,
18915,
63,
5598,
18,
63,
18,
566,
272,
18915,
63,
548,
275,
19140,
2927,
8,
267,
18915,
63,
10455,
12,
1324,
63,
1507,
63,
6324,
12,
334,
17,
12,
413,
395,
543,
63,
2442,
29,
797,
9,
339,
1851,
275,
1851,
435,
4666,
627,
18915,
63,
548,
272,
340,
543,
63,
2442,
26,
267,
2454,
275,
8728,
14,
5155,
14,
19535,
8,
288,
666,
29,
846,
12,
2454,
63,
466,
29,
2442,
63,
466,
12,
1921,
29,
12324,
63,
962,
9,
267,
372,
2454,
272,
587,
26,
267,
372,
1851,
421,
199,
318,
1853,
1196,
8,
846,
12,
1324,
63,
1507,
63,
6324,
12,
4666,
29,
17,
14,
16,
12,
543,
63,
2442,
29,
549,
12,
2454,
63,
466,
534,
12833,
297,
15216,
63,
962,
16420,
272,
18915,
63,
5598,
275,
19140,
2927,
8,
846,
12,
13567,
12,
334,
17,
12,
413,
430,
272,
18915,
63,
5598,
17,
63,
16,
275,
19140,
2927,
8,
846,
12,
25454,
12,
334,
17,
12,
413,
430,
272,
18915,
63,
5598,
17,
63,
17,
275,
19140,
2927,
8,
21651,
63,
5598,
17,
63,
16,
12,
21235,
12,
334,
17,
12,
1520,
395,
6567,
2687,
17,
12,
499,
430,
272,
18915,
63,
5598,
17,
63,
18,
275,
19140,
2927,
8,
21651,
63,
5598,
17,
63,
17,
12,
13567,
12,
334,
23,
12,
413,
395,
6567,
2687,
18,
12,
413,
430,
272,
18915,
63,
10455,
275,
8728,
14,
5155,
14,
25536,
23151,
21651,
63,
5598,
12,
18915,
63,
5598,
17,
63,
18,
566,
272,
18915,
63,
548,
275,
19140,
2927,
8,
267,
18915,
63,
10455,
12,
1324,
63,
1507,
63,
6324,
12,
334,
17,
12,
413,
395,
543,
63,
2442,
29,
797,
9,
272,
1851,
275,
1851,
435,
4666,
627,
18915,
63,
548,
272,
340,
543,
63,
2442,
26,
267,
2454,
275,
8728,
14,
5155,
14,
19535,
8,
288,
666,
29,
846,
12,
2454,
63,
466,
29,
2442,
63,
466,
12,
1921,
29,
12324,
63,
962,
9,
267,
372,
2454,
272,
587,
26,
267,
372,
1851,
421,
199,
318,
1853,
24,
8,
846,
12,
1324,
63,
1507,
63,
6324,
12,
4666,
29,
17,
14,
16,
12,
543,
63,
2442,
29,
549,
12,
2454,
63,
466,
534,
12833,
297,
15216,
63,
962,
16420,
272,
18915,
63,
5598,
275,
19140,
2927,
8,
846,
12,
13567,
12,
334,
17,
12,
413,
430,
272,
18915,
63,
5598,
17,
63,
16,
275,
19140,
2927,
8,
846,
12,
13567,
12,
334,
17,
12,
413,
430,
272,
18915,
63,
5598,
17,
63,
17
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
624,
199,
6906,
314,
5492,
402,
314,
1010,
814,
3591,
846,
812,
18,
15931,
14,
199,
2822,
11736,
315,
1455,
921,
27290,
14,
1308,
15,
2101,
15,
975,
996,
14,
1780,
15128,
14,
199,
607,
814,
13,
86,
20,
12,
1010,
814,
13,
1322,
2480,
436,
314,
8362,
2442,
402,
799,
10969,
8113,
83,
199,
265,
29127,
199,
1049,
18824,
5653,
428,
806,
3046,
89,
12,
3739,
303,
89,
473,
1997,
69,
12,
28882,
2946,
812,
290,
526,
10112,
69,
12,
22986,
6832,
2664,
199,
624,
199,
646,
8728,
846,
465,
8728,
421,
199,
318,
19140,
2927,
8,
576,
12,
1967,
63,
1541,
12,
5114,
12,
7345,
2687,
17,
12,
413,
395,
6567,
2687,
16,
12,
378,
395,
2454,
63,
466,
628,
12833,
401,
15216,
63,
962,
10324,
543,
63,
2442,
29,
549,
304,
272,
8260,
275,
8728,
14,
5155,
14,
27394,
8,
267,
666,
29,
576,
12,
1967,
63,
1541,
29,
1507,
63,
1541,
12,
5114,
29,
4989,
12,
7345,
29,
12318,
12,
6567,
29,
6226,
9,
272,
21847,
275,
8728,
14,
5155,
14,
32672,
8,
576,
29,
5598,
9,
272,
340,
543,
63,
2442,
26,
267,
2454,
275,
8728,
14,
5155,
14,
19535,
8,
288,
666,
29,
10472,
12,
2454,
63,
466,
29,
2442,
63,
466,
12,
1921,
29,
12324,
63,
962,
9,
267,
372,
2454,
272,
587,
26,
267,
372,
21847,
421,
199,
318,
1853,
1276,
8,
846,
12,
1324,
63,
1507,
63,
6324,
12,
4666,
29,
17,
14,
16,
12,
543,
63,
2442,
29,
549,
12,
2454,
63,
466,
534,
12833,
297,
15216,
63,
962,
16420,
272,
18915,
63,
5598,
275,
19140,
2927,
8,
846,
12,
4337,
12,
334,
17,
12,
413,
430,
272,
18915,
63,
5598,
17,
63,
16,
275,
19140,
2927,
8,
846,
12,
4337,
12,
334,
17,
12,
413,
430,
272,
18915,
63,
5598,
17,
63,
17,
275,
19140,
2927,
8,
21651,
63,
5598,
17,
63,
16,
12,
4337,
12,
334,
19,
12,
650,
395,
6567,
2687,
17,
12,
413,
430,
272,
18915,
63,
5598,
18,
63,
16,
275,
19140,
2927,
8,
846,
12,
4337,
12,
334,
17,
12,
413,
430,
272,
18915,
63,
5598,
18,
63,
17,
275,
19140,
2927,
8,
21651,
63,
5598,
18,
63,
16,
12,
9615,
12,
334,
19,
12,
650,
395,
6567,
2687,
17,
12,
413,
430,
272,
18915,
63,
5598,
18,
63,
18,
275,
19140,
2927,
8,
21651,
63,
5598,
18,
63,
17,
12,
5049,
12,
334,
19,
12,
650,
395,
6567,
2687,
17,
12,
413,
430,
272,
18915,
63,
10455,
275,
8728,
14,
5155,
14,
25536,
23151,
21651,
63,
5598,
12,
18915,
63,
5598,
17,
63,
17,
12,
18915,
63,
5598,
18,
63,
18,
566,
272,
18915,
63,
548,
275,
19140,
2927,
8,
267,
18915,
63,
10455,
12,
1324,
63,
1507,
63,
6324,
12,
334,
17,
12,
413,
395,
543,
63,
2442,
29,
797,
9,
339,
1851,
275,
1851,
435,
4666,
627,
18915,
63,
548,
272,
340,
543,
63,
2442,
26,
267,
2454,
275,
8728,
14,
5155,
14,
19535,
8,
288,
666,
29,
846,
12,
2454,
63,
466,
29,
2442,
63,
466,
12,
1921,
29,
12324,
63,
962,
9,
267,
372,
2454,
272,
587,
26,
267,
372,
1851,
421,
199,
318,
1853,
1196,
8,
846,
12,
1324,
63,
1507,
63,
6324,
12,
4666,
29,
17,
14,
16,
12,
543,
63,
2442,
29,
549,
12,
2454,
63,
466,
534,
12833,
297,
15216,
63,
962,
16420,
272,
18915,
63,
5598,
275,
19140,
2927,
8,
846,
12,
13567,
12,
334,
17,
12,
413,
430,
272,
18915,
63,
5598,
17,
63,
16,
275,
19140,
2927,
8,
846,
12,
25454,
12,
334,
17,
12,
413,
430,
272,
18915,
63,
5598,
17,
63,
17,
275,
19140,
2927,
8,
21651,
63,
5598,
17,
63,
16,
12,
21235,
12,
334,
17,
12,
1520,
395,
6567,
2687,
17,
12,
499,
430,
272,
18915,
63,
5598,
17,
63,
18,
275,
19140,
2927,
8,
21651,
63,
5598,
17,
63,
17,
12,
13567,
12,
334,
23,
12,
413,
395,
6567,
2687,
18,
12,
413,
430,
272,
18915,
63,
10455,
275,
8728,
14,
5155,
14,
25536,
23151,
21651,
63,
5598,
12,
18915,
63,
5598,
17,
63,
18,
566,
272,
18915,
63,
548,
275,
19140,
2927,
8,
267,
18915,
63,
10455,
12,
1324,
63,
1507,
63,
6324,
12,
334,
17,
12,
413,
395,
543,
63,
2442,
29,
797,
9,
272,
1851,
275,
1851,
435,
4666,
627,
18915,
63,
548,
272,
340,
543,
63,
2442,
26,
267,
2454,
275,
8728,
14,
5155,
14,
19535,
8,
288,
666,
29,
846,
12,
2454,
63,
466,
29,
2442,
63,
466,
12,
1921,
29,
12324,
63,
962,
9,
267,
372,
2454,
272,
587,
26,
267,
372,
1851,
421,
199,
318,
1853,
24,
8,
846,
12,
1324,
63,
1507,
63,
6324,
12,
4666,
29,
17,
14,
16,
12,
543,
63,
2442,
29,
549,
12,
2454,
63,
466,
534,
12833,
297,
15216,
63,
962,
16420,
272,
18915,
63,
5598,
275,
19140,
2927,
8,
846,
12,
13567,
12,
334,
17,
12,
413,
430,
272,
18915,
63,
5598,
17,
63,
16,
275,
19140,
2927,
8,
846,
12,
13567,
12,
334,
17,
12,
413,
430,
272,
18915,
63,
5598,
17,
63,
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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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
] |
goldsborough/.emacs
|
.emacs.d/.python-environments/default/lib/python3.5/token.py
|
63
|
3075
|
"""Token constants (from "token.h")."""
__all__ = ['tok_name', 'ISTERMINAL', 'ISNONTERMINAL', 'ISEOF']
# This file is automatically generated; please don't muck it up!
#
# To update the symbols in this file, 'cd' to the top directory of
# the python source tree after building the interpreter and run:
#
# ./python Lib/token.py
#--start constants--
ENDMARKER = 0
NAME = 1
NUMBER = 2
STRING = 3
NEWLINE = 4
INDENT = 5
DEDENT = 6
LPAR = 7
RPAR = 8
LSQB = 9
RSQB = 10
COLON = 11
COMMA = 12
SEMI = 13
PLUS = 14
MINUS = 15
STAR = 16
SLASH = 17
VBAR = 18
AMPER = 19
LESS = 20
GREATER = 21
EQUAL = 22
DOT = 23
PERCENT = 24
LBRACE = 25
RBRACE = 26
EQEQUAL = 27
NOTEQUAL = 28
LESSEQUAL = 29
GREATEREQUAL = 30
TILDE = 31
CIRCUMFLEX = 32
LEFTSHIFT = 33
RIGHTSHIFT = 34
DOUBLESTAR = 35
PLUSEQUAL = 36
MINEQUAL = 37
STAREQUAL = 38
SLASHEQUAL = 39
PERCENTEQUAL = 40
AMPEREQUAL = 41
VBAREQUAL = 42
CIRCUMFLEXEQUAL = 43
LEFTSHIFTEQUAL = 44
RIGHTSHIFTEQUAL = 45
DOUBLESTAREQUAL = 46
DOUBLESLASH = 47
DOUBLESLASHEQUAL = 48
AT = 49
ATEQUAL = 50
RARROW = 51
ELLIPSIS = 52
OP = 53
AWAIT = 54
ASYNC = 55
ERRORTOKEN = 56
N_TOKENS = 57
NT_OFFSET = 256
#--end constants--
tok_name = {value: name
for name, value in globals().items()
if isinstance(value, int) and not name.startswith('_')}
__all__.extend(tok_name.values())
def ISTERMINAL(x):
return x < NT_OFFSET
def ISNONTERMINAL(x):
return x >= NT_OFFSET
def ISEOF(x):
return x == ENDMARKER
def _main():
import re
import sys
args = sys.argv[1:]
inFileName = args and args[0] or "Include/token.h"
outFileName = "Lib/token.py"
if len(args) > 1:
outFileName = args[1]
try:
fp = open(inFileName)
except OSError as err:
sys.stdout.write("I/O error: %s\n" % str(err))
sys.exit(1)
with fp:
lines = fp.read().split("\n")
prog = re.compile(
"#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)",
re.IGNORECASE)
tokens = {}
for line in lines:
match = prog.match(line)
if match:
name, val = match.group(1, 2)
val = int(val)
tokens[val] = name # reverse so we can sort them...
keys = sorted(tokens.keys())
# load the output skeleton from the target:
try:
fp = open(outFileName)
except OSError as err:
sys.stderr.write("I/O error: %s\n" % str(err))
sys.exit(2)
with fp:
format = fp.read().split("\n")
try:
start = format.index("#--start constants--") + 1
end = format.index("#--end constants--")
except ValueError:
sys.stderr.write("target does not contain format markers")
sys.exit(3)
lines = []
for val in keys:
lines.append("%s = %d" % (tokens[val], val))
format[start:end] = lines
try:
fp = open(outFileName, 'w')
except OSError as err:
sys.stderr.write("I/O error: %s\n" % str(err))
sys.exit(4)
with fp:
fp.write("\n".join(format))
if __name__ == "__main__":
_main()
|
mit
|
[
624,
3264,
5262,
334,
504,
298,
1418,
14,
72,
531,
1041,
199,
199,
363,
452,
363,
275,
788,
9305,
63,
354,
297,
283,
19027,
4896,
748,
297,
283,
1311,
13887,
28376,
748,
297,
283,
4971,
3359,
418,
199,
199,
3,
221,
961,
570,
365,
5847,
4046,
27,
8749,
2793,
1133,
8504,
346,
652,
1536,
1,
199,
3,
199,
3,
221,
4005,
1678,
314,
6698,
315,
642,
570,
12,
283,
2866,
7,
370,
314,
2746,
2082,
402,
199,
3,
221,
314,
2366,
1350,
3123,
2410,
10015,
314,
12693,
436,
1255,
26,
199,
3,
199,
3,
259,
16605,
1548,
8003,
15,
1418,
14,
647,
199,
199,
3,
306,
928,
5262,
306,
199,
3902,
18997,
275,
378,
199,
2339,
275,
413,
199,
9190,
275,
499,
199,
5353,
275,
650,
199,
28758,
275,
841,
199,
29080,
275,
959,
199,
8280,
1309,
275,
1227,
199,
44,
4014,
275,
1520,
199,
50,
4014,
275,
1695,
199,
5296,
31893,
275,
1749,
199,
15062,
31893,
275,
1616,
199,
3978,
615,
275,
4119,
199,
11265,
2054,
275,
3144,
199,
899,
10709,
275,
4944,
199,
27280,
275,
4329,
199,
18004,
275,
4114,
199,
30302,
275,
3193,
199,
27192,
275,
5557,
199,
54,
13895,
275,
6155,
199,
1156,
4227,
275,
5851,
199,
30928,
275,
3388,
199,
39,
21780,
275,
7829,
199,
16352,
275,
6928,
199,
13203,
275,
6546,
199,
4227,
17349,
275,
5504,
199,
44,
29246,
275,
5661,
199,
50,
29246,
275,
7875,
199,
17420,
16352,
275,
8087,
199,
4609,
16352,
275,
7294,
199,
11344,
7326,
748,
275,
7349,
199,
39,
21780,
16352,
275,
4233,
199,
52,
13922,
275,
7105,
199,
3553,
50,
9976,
275,
4337,
199,
9894,
18013,
275,
9404,
199,
12811,
18013,
275,
8177,
199,
1649,
2533,
44,
1719,
689,
275,
8685,
199,
2749,
4701,
9283,
275,
8780,
199,
45,
3565,
9283,
275,
6877,
199,
840,
8693,
9283,
275,
10448,
199,
4929,
1179,
1645,
9283,
275,
10551,
199,
4227,
17349,
16352,
275,
6335,
199,
1156,
4227,
16352,
275,
13385,
199,
27966,
8693,
9283,
275,
5685,
199,
3553,
50,
9976,
16352,
275,
11851,
199,
9894,
18013,
16352,
275,
10868,
199,
12811,
18013,
16352,
275,
10416,
199,
1649,
2533,
44,
1719,
8693,
9283,
275,
12426,
199,
1649,
2533,
11344,
44,
8100,
275,
10954,
199,
1649,
2533,
11344,
44,
1179,
1645,
9283,
275,
9615,
199,
619,
275,
12260,
199,
1951,
9283,
275,
5238,
199,
50,
689,
11415,
275,
8026,
199,
21677,
275,
14589,
199,
1938,
275,
13564,
199,
33,
12458,
275,
13470,
199,
26222,
6389,
275,
12766,
199,
3170,
8803,
275,
12001,
199,
46,
63,
8803,
51,
275,
12699,
199,
12460,
63,
14839,
275,
7633,
199,
3,
306,
500,
5262,
306,
199,
199,
9305,
63,
354,
275,
469,
585,
26,
536,
288,
367,
536,
12,
574,
315,
7992,
1252,
1744,
342,
288,
340,
1228,
8,
585,
12,
1109,
9,
436,
440,
536,
14,
2460,
6412,
21004,
199,
363,
452,
4343,
2880,
8,
9305,
63,
354,
14,
1459,
1012,
199,
199,
318,
473,
14471,
4896,
748,
8,
88,
304,
272,
372,
671,
665,
23350,
63,
14839,
199,
199,
318,
2281,
13887,
28376,
748,
8,
88,
304,
272,
372,
671,
2356,
23350,
63,
14839,
199,
199,
318,
473,
899,
3359,
8,
88,
304,
272,
372,
671,
508,
7729,
18997,
421,
199,
318,
485,
973,
837,
272,
492,
295,
272,
492,
984,
272,
1249,
275,
984,
14,
3020,
59,
17,
2938,
272,
315,
7733,
275,
1249,
436,
1249,
59,
16,
61,
503,
298,
7826,
15,
1418,
14,
72,
2,
272,
734,
7733,
275,
298,
4728,
15,
1418,
14,
647,
2,
272,
340,
822,
8,
589,
9,
690,
413,
26,
267,
734,
7733,
275,
1249,
59,
17,
61,
272,
862,
26,
267,
4090,
275,
1551,
8,
262,
7733,
9,
272,
871,
6440,
465,
2329,
26,
267,
984,
14,
2703,
14,
952,
480,
41,
15,
47,
1125,
26,
450,
83,
60,
78,
2,
450,
620,
8,
1508,
430,
267,
984,
14,
2224,
8,
17,
9,
272,
543,
4090,
26,
267,
2385,
275,
4090,
14,
739,
1252,
1294,
4582,
78,
531,
272,
13205,
275,
295,
14,
2014,
8,
267,
5426,
4640,
59,
971,
84,
1527,
971,
84,
3672,
779,
33,
13,
58,
16,
13,
25,
1527,
33,
13,
58,
16,
13,
25,
15555,
2788,
971,
84,
1527,
971,
84,
3672,
779,
16,
13,
25,
1527,
16,
13,
25,
3672,
4186,
267,
295,
14,
15434,
9,
272,
4645,
275,
1052,
272,
367,
1004,
315,
2385,
26,
267,
1336,
275,
13205,
14,
1431,
8,
604,
9,
267,
340,
1336,
26,
288,
536,
12,
1139,
275,
1336,
14,
923,
8,
17,
12,
499,
9,
288,
1139,
275,
1109,
8,
637,
9,
288,
4645,
59,
637,
61,
275,
536,
3515,
327,
3837,
880,
781,
883,
4069,
3062,
1396,
272,
2883,
275,
3355,
8,
4504,
14,
1612,
1012,
272,
327,
2248,
314,
1072,
30537,
687,
314,
1347,
26,
272,
862,
26,
267,
4090,
275,
1551,
8,
548,
7733,
9,
272,
871,
6440,
465,
2329,
26,
267,
984,
14,
3083,
14,
952,
480,
41,
15,
47,
1125,
26,
450,
83,
60,
78,
2,
450,
620,
8,
1508,
430,
267,
984,
14,
2224,
8,
18,
9,
272,
543,
4090,
26,
267,
1475,
275,
4090,
14,
739,
1252,
1294,
4582,
78,
531,
272,
862,
26,
267,
1343,
275,
1475,
14,
1080,
10064,
306,
928,
5262,
306,
531,
435,
413,
267,
1284,
275,
1475,
14,
1080,
10064,
306,
500,
5262,
306,
531,
272,
871,
1722,
26,
267,
984,
14,
3083,
14,
952,
480,
1375,
1630,
440,
1395,
1475,
14327,
531,
267,
984,
14,
2224,
8,
19,
9,
272,
2385,
275,
942,
272,
367,
1139,
315,
2883,
26,
267,
2385,
14,
740,
3647,
83,
275,
450,
68,
2,
450,
334,
4504,
59,
637,
467,
1139,
430,
272,
1475,
59,
928,
26,
500,
61,
275,
2385,
272,
862,
26,
267,
4090,
275,
1551,
8,
548,
7733,
12,
283,
87,
358,
272,
871,
6440,
465,
2329,
26,
267,
984,
14,
3083,
14,
952,
480,
41,
15,
47,
1125,
26,
450,
83,
60,
78,
2,
450,
620,
8,
1508,
430,
267,
984,
14,
2224,
8,
20,
9,
272,
543,
4090,
26,
267,
4090,
14,
952,
4582,
78,
1674,
904,
8,
908,
430,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
485,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3264,
5262,
334,
504,
298,
1418,
14,
72,
531,
1041,
199,
199,
363,
452,
363,
275,
788,
9305,
63,
354,
297,
283,
19027,
4896,
748,
297,
283,
1311,
13887,
28376,
748,
297,
283,
4971,
3359,
418,
199,
199,
3,
221,
961,
570,
365,
5847,
4046,
27,
8749,
2793,
1133,
8504,
346,
652,
1536,
1,
199,
3,
199,
3,
221,
4005,
1678,
314,
6698,
315,
642,
570,
12,
283,
2866,
7,
370,
314,
2746,
2082,
402,
199,
3,
221,
314,
2366,
1350,
3123,
2410,
10015,
314,
12693,
436,
1255,
26,
199,
3,
199,
3,
259,
16605,
1548,
8003,
15,
1418,
14,
647,
199,
199,
3,
306,
928,
5262,
306,
199,
3902,
18997,
275,
378,
199,
2339,
275,
413,
199,
9190,
275,
499,
199,
5353,
275,
650,
199,
28758,
275,
841,
199,
29080,
275,
959,
199,
8280,
1309,
275,
1227,
199,
44,
4014,
275,
1520,
199,
50,
4014,
275,
1695,
199,
5296,
31893,
275,
1749,
199,
15062,
31893,
275,
1616,
199,
3978,
615,
275,
4119,
199,
11265,
2054,
275,
3144,
199,
899,
10709,
275,
4944,
199,
27280,
275,
4329,
199,
18004,
275,
4114,
199,
30302,
275,
3193,
199,
27192,
275,
5557,
199,
54,
13895,
275,
6155,
199,
1156,
4227,
275,
5851,
199,
30928,
275,
3388,
199,
39,
21780,
275,
7829,
199,
16352,
275,
6928,
199,
13203,
275,
6546,
199,
4227,
17349,
275,
5504,
199,
44,
29246,
275,
5661,
199,
50,
29246,
275,
7875,
199,
17420,
16352,
275,
8087,
199,
4609,
16352,
275,
7294,
199,
11344,
7326,
748,
275,
7349,
199,
39,
21780,
16352,
275,
4233,
199,
52,
13922,
275,
7105,
199,
3553,
50,
9976,
275,
4337,
199,
9894,
18013,
275,
9404,
199,
12811,
18013,
275,
8177,
199,
1649,
2533,
44,
1719,
689,
275,
8685,
199,
2749,
4701,
9283,
275,
8780,
199,
45,
3565,
9283,
275,
6877,
199,
840,
8693,
9283,
275,
10448,
199,
4929,
1179,
1645,
9283,
275,
10551,
199,
4227,
17349,
16352,
275,
6335,
199,
1156,
4227,
16352,
275,
13385,
199,
27966,
8693,
9283,
275,
5685,
199,
3553,
50,
9976,
16352,
275,
11851,
199,
9894,
18013,
16352,
275,
10868,
199,
12811,
18013,
16352,
275,
10416,
199,
1649,
2533,
44,
1719,
8693,
9283,
275,
12426,
199,
1649,
2533,
11344,
44,
8100,
275,
10954,
199,
1649,
2533,
11344,
44,
1179,
1645,
9283,
275,
9615,
199,
619,
275,
12260,
199,
1951,
9283,
275,
5238,
199,
50,
689,
11415,
275,
8026,
199,
21677,
275,
14589,
199,
1938,
275,
13564,
199,
33,
12458,
275,
13470,
199,
26222,
6389,
275,
12766,
199,
3170,
8803,
275,
12001,
199,
46,
63,
8803,
51,
275,
12699,
199,
12460,
63,
14839,
275,
7633,
199,
3,
306,
500,
5262,
306,
199,
199,
9305,
63,
354,
275,
469,
585,
26,
536,
288,
367,
536,
12,
574,
315,
7992,
1252,
1744,
342,
288,
340,
1228,
8,
585,
12,
1109,
9,
436,
440,
536,
14,
2460,
6412,
21004,
199,
363,
452,
4343,
2880,
8,
9305,
63,
354,
14,
1459,
1012,
199,
199,
318,
473,
14471,
4896,
748,
8,
88,
304,
272,
372,
671,
665,
23350,
63,
14839,
199,
199,
318,
2281,
13887,
28376,
748,
8,
88,
304,
272,
372,
671,
2356,
23350,
63,
14839,
199,
199,
318,
473,
899,
3359,
8,
88,
304,
272,
372,
671,
508,
7729,
18997,
421,
199,
318,
485,
973,
837,
272,
492,
295,
272,
492,
984,
272,
1249,
275,
984,
14,
3020,
59,
17,
2938,
272,
315,
7733,
275,
1249,
436,
1249,
59,
16,
61,
503,
298,
7826,
15,
1418,
14,
72,
2,
272,
734,
7733,
275,
298,
4728,
15,
1418,
14,
647,
2,
272,
340,
822,
8,
589,
9,
690,
413,
26,
267,
734,
7733,
275,
1249,
59,
17,
61,
272,
862,
26,
267,
4090,
275,
1551,
8,
262,
7733,
9,
272,
871,
6440,
465,
2329,
26,
267,
984,
14,
2703,
14,
952,
480,
41,
15,
47,
1125,
26,
450,
83,
60,
78,
2,
450,
620,
8,
1508,
430,
267,
984,
14,
2224,
8,
17,
9,
272,
543,
4090,
26,
267,
2385,
275,
4090,
14,
739,
1252,
1294,
4582,
78,
531,
272,
13205,
275,
295,
14,
2014,
8,
267,
5426,
4640,
59,
971,
84,
1527,
971,
84,
3672,
779,
33,
13,
58,
16,
13,
25,
1527,
33,
13,
58,
16,
13,
25,
15555,
2788,
971,
84,
1527,
971,
84,
3672,
779,
16,
13,
25,
1527,
16,
13,
25,
3672,
4186,
267,
295,
14,
15434,
9,
272,
4645,
275,
1052,
272,
367,
1004,
315,
2385,
26,
267,
1336,
275,
13205,
14,
1431,
8,
604,
9,
267,
340,
1336,
26,
288,
536,
12,
1139,
275,
1336,
14,
923,
8,
17,
12,
499,
9,
288,
1139,
275,
1109,
8,
637,
9,
288,
4645,
59,
637,
61,
275,
536,
3515,
327,
3837,
880,
781,
883,
4069,
3062,
1396,
272,
2883,
275,
3355,
8,
4504,
14,
1612,
1012,
272,
327,
2248,
314,
1072,
30537,
687,
314,
1347,
26,
272,
862,
26,
267,
4090,
275,
1551,
8,
548,
7733,
9,
272,
871,
6440,
465,
2329,
26,
267,
984,
14,
3083,
14,
952,
480,
41,
15,
47,
1125,
26,
450,
83,
60,
78,
2,
450,
620,
8,
1508,
430,
267,
984,
14,
2224,
8,
18,
9,
272,
543,
4090,
26,
267,
1475,
275,
4090,
14,
739,
1252,
1294,
4582,
78,
531,
272,
862,
26,
267,
1343,
275,
1475,
14,
1080,
10064,
306,
928,
5262,
306,
531,
435,
413,
267,
1284,
275,
1475,
14,
1080,
10064,
306,
500,
5262,
306,
531,
272,
871,
1722,
26,
267,
984,
14,
3083,
14,
952,
480,
1375,
1630,
440,
1395,
1475,
14327,
531,
267,
984,
14,
2224,
8,
19,
9,
272,
2385,
275,
942,
272,
367,
1139,
315,
2883,
26,
267,
2385,
14,
740,
3647,
83,
275,
450,
68,
2,
450,
334,
4504,
59,
637,
467,
1139,
430,
272,
1475,
59,
928,
26,
500,
61,
275,
2385,
272,
862,
26,
267,
4090,
275,
1551,
8,
548,
7733,
12,
283,
87,
358,
272,
871,
6440,
465,
2329,
26,
267,
984,
14,
3083,
14,
952,
480,
41,
15,
47,
1125,
26,
450,
83,
60,
78,
2,
450,
620,
8,
1508,
430,
267,
984,
14,
2224,
8,
20,
9,
272,
543,
4090,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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0
] |
ojengwa/oh-mainline
|
vendor/packages/docutils/test/test_parsers/test_rst/test_directives/test_parsed_literals.py
|
18
|
1708
|
#! /usr/bin/env python
# $Id: test_parsed_literals.py 7072 2011-07-06 15:52:30Z milde $
# Author: Lea Wiemann <LeWiemann@gmail.com>
# Copyright: This module has been placed in the public domain.
"""
Tests for the body.py 'parsed-literal' directive.
"""
from __init__ import DocutilsTestSupport
def suite():
s = DocutilsTestSupport.ParserTestSuite()
s.generateTests(totest)
return s
totest = {}
totest['parsed_literals'] = [
["""\
.. parsed-literal::
This is a parsed literal block.
It may contain *inline markup
spanning lines.*
""",
"""\
<document source="test data">
<literal_block xml:space="preserve">
This is a parsed literal block.
It may contain \n\
<emphasis>
inline markup
spanning lines.
"""],
["""\
.. parsed-literal::
:class: myliteral
:name: example: parsed
This is a parsed literal block with options.
""",
"""\
<document source="test data">
<literal_block classes="myliteral" ids="example-parsed" names="example:\ parsed" xml:space="preserve">
This is a parsed literal block with options.
"""],
["""\
.. parsed-literal:: content may start on same line
""",
"""\
<document source="test data">
<literal_block xml:space="preserve">
content may start on same line
"""],
["""\
.. parsed-literal::
""",
"""\
<document source="test data">
<system_message level="3" line="1" source="test data" type="ERROR">
<paragraph>
Content block expected for the "parsed-literal" directive; none found.
<literal_block xml:space="preserve">
.. parsed-literal::
"""],
]
if __name__ == '__main__':
import unittest
unittest.main(defaultTest='suite')
|
agpl-3.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
2672,
1304,
26,
511,
63,
6751,
63,
5955,
14,
647,
1520,
20281,
7760,
13,
1780,
13,
1690,
4114,
26,
2528,
26,
1216,
58,
333,
24446,
2672,
199,
3,
6529,
26,
491,
4489,
644,
1873,
20059,
665,
2553,
55,
1873,
20059,
32,
6799,
14,
957,
30,
199,
3,
1898,
26,
961,
859,
965,
2757,
15090,
315,
314,
4575,
2881,
14,
199,
199,
624,
199,
2925,
367,
314,
2396,
14,
647,
283,
6751,
13,
8939,
7,
13613,
14,
199,
624,
199,
199,
504,
636,
826,
363,
492,
5454,
1208,
774,
11532,
199,
199,
318,
5241,
837,
272,
308,
275,
5454,
1208,
774,
11532,
14,
2842,
10591,
342,
272,
308,
14,
4208,
2925,
8,
475,
396,
9,
272,
372,
308,
199,
199,
475,
396,
275,
1052,
199,
199,
475,
396,
459,
6751,
63,
5955,
418,
275,
359,
199,
59,
19659,
199,
703,
4565,
13,
8939,
447,
8410,
961,
365,
282,
4565,
8785,
1853,
14,
2043,
2779,
1443,
1395,
627,
6460,
9189,
2043,
2249,
11495,
2385,
2795,
199,
7208,
199,
19659,
199,
28,
3554,
1350,
628,
396,
666,
1743,
272,
665,
8939,
63,
1457,
2748,
26,
2638,
628,
17053,
1743,
267,
961,
365,
282,
4565,
8785,
1853,
14,
267,
2779,
1443,
1395,
971,
78,
60,
267,
665,
28907,
30,
288,
8308,
9189,
288,
2249,
11495,
2385,
14,
199,
624,
467,
199,
59,
19659,
199,
703,
4565,
13,
8939,
447,
523,
520,
533,
26,
3002,
8939,
523,
520,
354,
26,
2893,
26,
4565,
8410,
961,
365,
282,
4565,
8785,
1853,
543,
1511,
14,
199,
7208,
199,
19659,
199,
28,
3554,
1350,
628,
396,
666,
1743,
272,
665,
8939,
63,
1457,
3992,
628,
1662,
8939,
2,
2762,
628,
2694,
13,
6751,
2,
1561,
628,
2694,
3427,
4565,
2,
2748,
26,
2638,
628,
17053,
1743,
268,
961,
365,
282,
4565,
8785,
1853,
543,
1511,
14,
199,
624,
467,
199,
59,
19659,
199,
703,
4565,
13,
8939,
447,
1564,
1443,
1343,
641,
2011,
1004,
199,
7208,
199,
19659,
199,
28,
3554,
1350,
628,
396,
666,
1743,
272,
665,
8939,
63,
1457,
2748,
26,
2638,
628,
17053,
1743,
267,
1564,
1443,
1343,
641,
2011,
1004,
199,
624,
467,
199,
59,
19659,
199,
703,
4565,
13,
8939,
447,
199,
7208,
199,
19659,
199,
28,
3554,
1350,
628,
396,
666,
1743,
272,
665,
2253,
63,
1188,
2166,
628,
19,
2,
1004,
628,
17,
2,
1350,
628,
396,
666,
2,
730,
628,
3170,
1743,
267,
665,
12400,
30,
288,
6646,
1853,
1420,
367,
314,
298,
6751,
13,
8939,
2,
13613,
27,
7179,
1911,
14,
267,
665,
8939,
63,
1457,
2748,
26,
2638,
628,
17053,
1743,
288,
2508,
4565,
13,
8939,
447,
199,
624,
467,
199,
61,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
2882,
272,
2882,
14,
973,
8,
885,
774,
534,
5768,
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
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
2672,
1304,
26,
511,
63,
6751,
63,
5955,
14,
647,
1520,
20281,
7760,
13,
1780,
13,
1690,
4114,
26,
2528,
26,
1216,
58,
333,
24446,
2672,
199,
3,
6529,
26,
491,
4489,
644,
1873,
20059,
665,
2553,
55,
1873,
20059,
32,
6799,
14,
957,
30,
199,
3,
1898,
26,
961,
859,
965,
2757,
15090,
315,
314,
4575,
2881,
14,
199,
199,
624,
199,
2925,
367,
314,
2396,
14,
647,
283,
6751,
13,
8939,
7,
13613,
14,
199,
624,
199,
199,
504,
636,
826,
363,
492,
5454,
1208,
774,
11532,
199,
199,
318,
5241,
837,
272,
308,
275,
5454,
1208,
774,
11532,
14,
2842,
10591,
342,
272,
308,
14,
4208,
2925,
8,
475,
396,
9,
272,
372,
308,
199,
199,
475,
396,
275,
1052,
199,
199,
475,
396,
459,
6751,
63,
5955,
418,
275,
359,
199,
59,
19659,
199,
703,
4565,
13,
8939,
447,
8410,
961,
365,
282,
4565,
8785,
1853,
14,
2043,
2779,
1443,
1395,
627,
6460,
9189,
2043,
2249,
11495,
2385,
2795,
199,
7208,
199,
19659,
199,
28,
3554,
1350,
628,
396,
666,
1743,
272,
665,
8939,
63,
1457,
2748,
26,
2638,
628,
17053,
1743,
267,
961,
365,
282,
4565,
8785,
1853,
14,
267,
2779,
1443,
1395,
971,
78,
60,
267,
665,
28907,
30,
288,
8308,
9189,
288,
2249,
11495,
2385,
14,
199,
624,
467,
199,
59,
19659,
199,
703,
4565,
13,
8939,
447,
523,
520,
533,
26,
3002,
8939,
523,
520,
354,
26,
2893,
26,
4565,
8410,
961,
365,
282,
4565,
8785,
1853,
543,
1511,
14,
199,
7208,
199,
19659,
199,
28,
3554,
1350,
628,
396,
666,
1743,
272,
665,
8939,
63,
1457,
3992,
628,
1662,
8939,
2,
2762,
628,
2694,
13,
6751,
2,
1561,
628,
2694,
3427,
4565,
2,
2748,
26,
2638,
628,
17053,
1743,
268,
961,
365,
282,
4565,
8785,
1853,
543,
1511,
14,
199,
624,
467,
199,
59,
19659,
199,
703,
4565,
13,
8939,
447,
1564,
1443,
1343,
641,
2011,
1004,
199,
7208,
199,
19659,
199,
28,
3554,
1350,
628,
396,
666,
1743,
272,
665,
8939,
63,
1457,
2748,
26,
2638,
628,
17053,
1743,
267,
1564,
1443,
1343,
641,
2011,
1004,
199,
624,
467,
199,
59,
19659,
199,
703,
4565,
13,
8939,
447,
199,
7208,
199,
19659,
199,
28,
3554,
1350,
628,
396,
666,
1743,
272,
665,
2253,
63,
1188,
2166,
628,
19,
2,
1004,
628,
17,
2,
1350,
628,
396,
666,
2,
730,
628,
3170,
1743,
267,
665,
12400,
30,
288,
6646,
1853,
1420,
367,
314,
298,
6751,
13,
8939,
2,
13613,
27,
7179,
1911,
14,
267,
665,
8939,
63,
1457,
2748,
26,
2638,
628,
17053,
1743,
288,
2508,
4565,
13,
8939,
447,
199,
624,
467,
199,
61,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
2882,
272,
2882,
14,
973,
8,
885,
774,
534,
5768,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
AloneRoad/Inforlearn
|
django/contrib/gis/tests/test_geoforms.py
|
74
|
2653
|
import unittest
from django.forms import ValidationError
from django.contrib.gis import forms
from django.contrib.gis.geos import GEOSGeometry
class GeometryFieldTest(unittest.TestCase):
def test00_init(self):
"Testing GeometryField initialization with defaults."
fld = forms.GeometryField()
for bad_default in ('blah', 3, 'FoO', None, 0):
self.assertRaises(ValidationError, fld.clean, bad_default)
def test01_srid(self):
"Testing GeometryField with a SRID set."
# Input that doesn't specify the SRID is assumed to be in the SRID
# of the input field.
fld = forms.GeometryField(srid=4326)
geom = fld.clean('POINT(5 23)')
self.assertEqual(4326, geom.srid)
# Making the field in a different SRID from that of the geometry, and
# asserting it transforms.
fld = forms.GeometryField(srid=32140)
tol = 0.0000001
xform_geom = GEOSGeometry('POINT (951640.547328465 4219369.26171664)', srid=32140)
# The cleaned geometry should be transformed to 32140.
cleaned_geom = fld.clean('SRID=4326;POINT (-95.363151 29.763374)')
self.failUnless(xform_geom.equals_exact(cleaned_geom, tol))
def test02_null(self):
"Testing GeometryField's handling of null (None) geometries."
# Form fields, by default, are required (`required=True`)
fld = forms.GeometryField()
self.assertRaises(forms.ValidationError, fld.clean, None)
# Still not allowed if `null=False`.
fld = forms.GeometryField(required=False, null=False)
self.assertRaises(forms.ValidationError, fld.clean, None)
# This will clean None as a geometry (See #10660).
fld = forms.GeometryField(required=False)
self.assertEqual(None, fld.clean(None))
def test03_geom_type(self):
"Testing GeometryField's handling of different geometry types."
# By default, all geometry types are allowed.
fld = forms.GeometryField()
for wkt in ('POINT(5 23)', 'MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))', 'LINESTRING(0 0, 1 1)'):
self.assertEqual(GEOSGeometry(wkt), fld.clean(wkt))
pnt_fld = forms.GeometryField(geom_type='POINT')
self.assertEqual(GEOSGeometry('POINT(5 23)'), pnt_fld.clean('POINT(5 23)'))
self.assertRaises(forms.ValidationError, pnt_fld.clean, 'LINESTRING(0 0, 1 1)')
def suite():
s = unittest.TestSuite()
s.addTest(unittest.makeSuite(GeometryFieldTest))
return s
def run(verbosity=2):
unittest.TextTestRunner(verbosity=verbosity).run(suite())
if __name__=="__main__":
run()
|
apache-2.0
|
[
646,
2882,
199,
199,
504,
1639,
14,
3351,
492,
8505,
199,
504,
1639,
14,
2828,
14,
5668,
492,
4513,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
492,
21479,
199,
199,
533,
30490,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
383,
63,
826,
8,
277,
304,
267,
298,
9029,
30490,
11097,
543,
4243,
2122,
267,
22928,
275,
4513,
14,
6831,
792,
342,
267,
367,
4875,
63,
885,
315,
661,
12702,
297,
650,
12,
283,
15563,
47,
297,
488,
12,
378,
304,
288,
291,
14,
1855,
8,
8172,
12,
22928,
14,
3118,
12,
4875,
63,
885,
9,
339,
347,
511,
614,
63,
10498,
8,
277,
304,
267,
298,
9029,
30490,
543,
282,
22425,
663,
2122,
267,
327,
6924,
626,
3181,
1133,
4165,
314,
22425,
365,
10826,
370,
506,
315,
314,
22425,
267,
327,
402,
314,
1324,
901,
14,
267,
22928,
275,
4513,
14,
6831,
792,
8,
10498,
29,
17948,
9,
267,
9671,
275,
22928,
14,
3118,
360,
7217,
8,
21,
6546,
5942,
267,
291,
14,
629,
8,
17948,
12,
9671,
14,
10498,
9,
267,
327,
32269,
314,
901,
315,
282,
3365,
22425,
687,
626,
402,
314,
3400,
12,
436,
267,
327,
702,
316,
652,
18501,
14,
267,
22928,
275,
4513,
14,
6831,
792,
8,
10498,
29,
708,
10037,
9,
267,
9561,
275,
378,
14,
3273,
17,
267,
671,
964,
63,
6481,
275,
21479,
360,
7217,
334,
2720,
8982,
16,
14,
16710,
708,
1349,
2182,
5685,
1167,
11939,
14,
1479,
1196,
975,
772,
3196,
15627,
29,
708,
10037,
9,
267,
327,
710,
12364,
3400,
1077,
506,
14834,
370,
4337,
10037,
14,
267,
12364,
63,
6481,
275,
22928,
14,
3118,
360,
5943,
998,
29,
17948,
27,
7217,
5868,
2720,
14,
1344,
9927,
17,
7349,
14,
2114,
1153,
1342,
5942,
267,
291,
14,
7589,
8,
24226,
63,
6481,
14,
11332,
63,
7327,
8,
8275,
63,
6481,
12,
9561,
430,
339,
347,
511,
996,
63,
2307,
8,
277,
304,
267,
298,
9029,
30490,
1159,
7252,
402,
2973,
334,
403,
9,
24883,
2122,
267,
327,
8204,
1504,
12,
701,
849,
12,
787,
1415,
13493,
2427,
29,
549,
10522,
267,
22928,
275,
4513,
14,
6831,
792,
342,
267,
291,
14,
1855,
8,
3351,
14,
8172,
12,
22928,
14,
3118,
12,
488,
9,
398,
327,
428,
12587,
440,
4370,
340,
658,
2307,
29,
797,
2313,
267,
22928,
275,
4513,
14,
6831,
792,
8,
2427,
29,
797,
12,
2973,
29,
797,
9,
267,
291,
14,
1855,
8,
3351,
14,
8172,
12,
22928,
14,
3118,
12,
488,
9,
398,
327,
961,
911,
3633,
488,
465,
282,
3400,
334,
9295,
327,
709,
15268,
680,
267,
22928,
275,
4513,
14,
6831,
792,
8,
2427,
29,
797,
9,
267,
291,
14,
629,
8,
403,
12,
22928,
14,
3118,
8,
403,
430,
339,
347,
511,
1644,
63,
6481,
63,
466,
8,
277,
304,
267,
298,
9029,
30490,
1159,
7252,
402,
3365,
3400,
2943,
2122,
267,
327,
4885,
849,
12,
1006,
3400,
2943,
787,
4370,
14,
267,
22928,
275,
4513,
14,
6831,
792,
342,
267,
367,
21992,
315,
661,
7217,
8,
21,
6546,
3196,
283,
21389,
23602,
12925,
16,
378,
12,
378,
413,
12,
413,
413,
12,
413,
378,
12,
378,
378,
1724,
297,
283,
6143,
29780,
8,
16,
378,
12,
413,
413,
9,
735,
288,
291,
14,
629,
8,
14151,
6831,
8,
11412,
395,
22928,
14,
3118,
8,
11412,
430,
398,
19948,
63,
17511,
275,
4513,
14,
6831,
792,
8,
6481,
63,
466,
534,
7217,
358,
267,
291,
14,
629,
8,
14151,
6831,
360,
7217,
8,
21,
6546,
11218,
19948,
63,
17511,
14,
3118,
360,
7217,
8,
21,
6546,
9,
1333,
267,
291,
14,
1855,
8,
3351,
14,
8172,
12,
19948,
63,
17511,
14,
3118,
12,
283,
6143,
29780,
8,
16,
378,
12,
413,
413,
5942,
199,
199,
318,
5241,
837,
272,
308,
275,
2882,
14,
10591,
342,
272,
308,
14,
15714,
8,
2796,
14,
18275,
8,
6831,
792,
774,
430,
272,
372,
308,
199,
199,
318,
1255,
8,
9833,
29,
18,
304,
272,
2882,
14,
24285,
8,
9833,
29,
9833,
680,
1065,
8,
5768,
1012,
199,
199,
692,
636,
354,
363,
11800,
363,
973,
5727,
272,
1255,
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
] |
[
2882,
199,
199,
504,
1639,
14,
3351,
492,
8505,
199,
504,
1639,
14,
2828,
14,
5668,
492,
4513,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
492,
21479,
199,
199,
533,
30490,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
383,
63,
826,
8,
277,
304,
267,
298,
9029,
30490,
11097,
543,
4243,
2122,
267,
22928,
275,
4513,
14,
6831,
792,
342,
267,
367,
4875,
63,
885,
315,
661,
12702,
297,
650,
12,
283,
15563,
47,
297,
488,
12,
378,
304,
288,
291,
14,
1855,
8,
8172,
12,
22928,
14,
3118,
12,
4875,
63,
885,
9,
339,
347,
511,
614,
63,
10498,
8,
277,
304,
267,
298,
9029,
30490,
543,
282,
22425,
663,
2122,
267,
327,
6924,
626,
3181,
1133,
4165,
314,
22425,
365,
10826,
370,
506,
315,
314,
22425,
267,
327,
402,
314,
1324,
901,
14,
267,
22928,
275,
4513,
14,
6831,
792,
8,
10498,
29,
17948,
9,
267,
9671,
275,
22928,
14,
3118,
360,
7217,
8,
21,
6546,
5942,
267,
291,
14,
629,
8,
17948,
12,
9671,
14,
10498,
9,
267,
327,
32269,
314,
901,
315,
282,
3365,
22425,
687,
626,
402,
314,
3400,
12,
436,
267,
327,
702,
316,
652,
18501,
14,
267,
22928,
275,
4513,
14,
6831,
792,
8,
10498,
29,
708,
10037,
9,
267,
9561,
275,
378,
14,
3273,
17,
267,
671,
964,
63,
6481,
275,
21479,
360,
7217,
334,
2720,
8982,
16,
14,
16710,
708,
1349,
2182,
5685,
1167,
11939,
14,
1479,
1196,
975,
772,
3196,
15627,
29,
708,
10037,
9,
267,
327,
710,
12364,
3400,
1077,
506,
14834,
370,
4337,
10037,
14,
267,
12364,
63,
6481,
275,
22928,
14,
3118,
360,
5943,
998,
29,
17948,
27,
7217,
5868,
2720,
14,
1344,
9927,
17,
7349,
14,
2114,
1153,
1342,
5942,
267,
291,
14,
7589,
8,
24226,
63,
6481,
14,
11332,
63,
7327,
8,
8275,
63,
6481,
12,
9561,
430,
339,
347,
511,
996,
63,
2307,
8,
277,
304,
267,
298,
9029,
30490,
1159,
7252,
402,
2973,
334,
403,
9,
24883,
2122,
267,
327,
8204,
1504,
12,
701,
849,
12,
787,
1415,
13493,
2427,
29,
549,
10522,
267,
22928,
275,
4513,
14,
6831,
792,
342,
267,
291,
14,
1855,
8,
3351,
14,
8172,
12,
22928,
14,
3118,
12,
488,
9,
398,
327,
428,
12587,
440,
4370,
340,
658,
2307,
29,
797,
2313,
267,
22928,
275,
4513,
14,
6831,
792,
8,
2427,
29,
797,
12,
2973,
29,
797,
9,
267,
291,
14,
1855,
8,
3351,
14,
8172,
12,
22928,
14,
3118,
12,
488,
9,
398,
327,
961,
911,
3633,
488,
465,
282,
3400,
334,
9295,
327,
709,
15268,
680,
267,
22928,
275,
4513,
14,
6831,
792,
8,
2427,
29,
797,
9,
267,
291,
14,
629,
8,
403,
12,
22928,
14,
3118,
8,
403,
430,
339,
347,
511,
1644,
63,
6481,
63,
466,
8,
277,
304,
267,
298,
9029,
30490,
1159,
7252,
402,
3365,
3400,
2943,
2122,
267,
327,
4885,
849,
12,
1006,
3400,
2943,
787,
4370,
14,
267,
22928,
275,
4513,
14,
6831,
792,
342,
267,
367,
21992,
315,
661,
7217,
8,
21,
6546,
3196,
283,
21389,
23602,
12925,
16,
378,
12,
378,
413,
12,
413,
413,
12,
413,
378,
12,
378,
378,
1724,
297,
283,
6143,
29780,
8,
16,
378,
12,
413,
413,
9,
735,
288,
291,
14,
629,
8,
14151,
6831,
8,
11412,
395,
22928,
14,
3118,
8,
11412,
430,
398,
19948,
63,
17511,
275,
4513,
14,
6831,
792,
8,
6481,
63,
466,
534,
7217,
358,
267,
291,
14,
629,
8,
14151,
6831,
360,
7217,
8,
21,
6546,
11218,
19948,
63,
17511,
14,
3118,
360,
7217,
8,
21,
6546,
9,
1333,
267,
291,
14,
1855,
8,
3351,
14,
8172,
12,
19948,
63,
17511,
14,
3118,
12,
283,
6143,
29780,
8,
16,
378,
12,
413,
413,
5942,
199,
199,
318,
5241,
837,
272,
308,
275,
2882,
14,
10591,
342,
272,
308,
14,
15714,
8,
2796,
14,
18275,
8,
6831,
792,
774,
430,
272,
372,
308,
199,
199,
318,
1255,
8,
9833,
29,
18,
304,
272,
2882,
14,
24285,
8,
9833,
29,
9833,
680,
1065,
8,
5768,
1012,
199,
199,
692,
636,
354,
363,
11800,
363,
973,
5727,
272,
1255,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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